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) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.Algebra.Algebra.Operations
import Mathlib.Data.Fintype.Lattice
import Mathlib.RingTheory.Coprime.Lemmas
#align_import ring_theory.ideal.operations from "leanprover-community/mathlib"@"e7f0ddbf65bd7181a85edb74b64bdc35ba4bdc74"
/-!
# More operations on modules and ideals
-/
assert_not_exists Basis -- See `RingTheory.Ideal.Basis`
assert_not_exists Submodule.hasQuotient -- See `RingTheory.Ideal.QuotientOperations`
universe u v w x
open Pointwise
namespace Submodule
variable {R : Type u} {M : Type v} {M' F G : Type*}
section CommSemiring
variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid M'] [Module R M']
open Pointwise
instance hasSMul' : SMul (Ideal R) (Submodule R M) :=
⟨Submodule.map₂ (LinearMap.lsmul R M)⟩
#align submodule.has_smul' Submodule.hasSMul'
/-- This duplicates the global `smul_eq_mul`, but doesn't have to unfold anywhere near as much to
apply. -/
protected theorem _root_.Ideal.smul_eq_mul (I J : Ideal R) : I • J = I * J :=
rfl
#align ideal.smul_eq_mul Ideal.smul_eq_mul
variable (R M) in
/-- `Module.annihilator R M` is the ideal of all elements `r : R` such that `r • M = 0`. -/
def _root_.Module.annihilator : Ideal R := LinearMap.ker (LinearMap.lsmul R M)
theorem _root_.Module.mem_annihilator {r} : r ∈ Module.annihilator R M ↔ ∀ m : M, r • m = 0 :=
⟨fun h ↦ (congr($h ·)), (LinearMap.ext ·)⟩
theorem _root_.LinearMap.annihilator_le_of_injective (f : M →ₗ[R] M') (hf : Function.Injective f) :
Module.annihilator R M' ≤ Module.annihilator R M := fun x h ↦ by
rw [Module.mem_annihilator] at h ⊢; exact fun m ↦ hf (by rw [map_smul, h, f.map_zero])
theorem _root_.LinearMap.annihilator_le_of_surjective (f : M →ₗ[R] M')
(hf : Function.Surjective f) : Module.annihilator R M ≤ Module.annihilator R M' := fun x h ↦ by
rw [Module.mem_annihilator] at h ⊢
intro m; obtain ⟨m, rfl⟩ := hf m
rw [← map_smul, h, f.map_zero]
theorem _root_.LinearEquiv.annihilator_eq (e : M ≃ₗ[R] M') :
Module.annihilator R M = Module.annihilator R M' :=
(e.annihilator_le_of_surjective e.surjective).antisymm (e.annihilator_le_of_injective e.injective)
/-- `N.annihilator` is the ideal of all elements `r : R` such that `r • N = 0`. -/
abbrev annihilator (N : Submodule R M) : Ideal R :=
Module.annihilator R N
#align submodule.annihilator Submodule.annihilator
theorem annihilator_top : (⊤ : Submodule R M).annihilator = Module.annihilator R M :=
topEquiv.annihilator_eq
variable {I J : Ideal R} {N P : Submodule R M}
theorem mem_annihilator {r} : r ∈ N.annihilator ↔ ∀ n ∈ N, r • n = (0 : M) := by
simp_rw [annihilator, Module.mem_annihilator, Subtype.forall, Subtype.ext_iff]; rfl
#align submodule.mem_annihilator Submodule.mem_annihilator
theorem mem_annihilator' {r} : r ∈ N.annihilator ↔ N ≤ comap (r • (LinearMap.id : M →ₗ[R] M)) ⊥ :=
mem_annihilator.trans ⟨fun H n hn => (mem_bot R).2 <| H n hn, fun H _ hn => (mem_bot R).1 <| H hn⟩
#align submodule.mem_annihilator' Submodule.mem_annihilator'
theorem mem_annihilator_span (s : Set M) (r : R) :
r ∈ (Submodule.span R s).annihilator ↔ ∀ n : s, r • (n : M) = 0 := by
rw [Submodule.mem_annihilator]
constructor
· intro h n
exact h _ (Submodule.subset_span n.prop)
· intro h n hn
refine Submodule.span_induction hn ?_ ?_ ?_ ?_
· intro x hx
exact h ⟨x, hx⟩
· exact smul_zero _
· intro x y hx hy
rw [smul_add, hx, hy, zero_add]
· intro a x hx
rw [smul_comm, hx, smul_zero]
#align submodule.mem_annihilator_span Submodule.mem_annihilator_span
theorem mem_annihilator_span_singleton (g : M) (r : R) :
r ∈ (Submodule.span R ({g} : Set M)).annihilator ↔ r • g = 0 := by simp [mem_annihilator_span]
#align submodule.mem_annihilator_span_singleton Submodule.mem_annihilator_span_singleton
theorem annihilator_bot : (⊥ : Submodule R M).annihilator = ⊤ :=
(Ideal.eq_top_iff_one _).2 <| mem_annihilator'.2 bot_le
#align submodule.annihilator_bot Submodule.annihilator_bot
theorem annihilator_eq_top_iff : N.annihilator = ⊤ ↔ N = ⊥ :=
⟨fun H =>
eq_bot_iff.2 fun (n : M) hn =>
(mem_bot R).2 <| one_smul R n ▸ mem_annihilator.1 ((Ideal.eq_top_iff_one _).1 H) n hn,
fun H => H.symm ▸ annihilator_bot⟩
#align submodule.annihilator_eq_top_iff Submodule.annihilator_eq_top_iff
theorem annihilator_mono (h : N ≤ P) : P.annihilator ≤ N.annihilator := fun _ hrp =>
mem_annihilator.2 fun n hn => mem_annihilator.1 hrp n <| h hn
#align submodule.annihilator_mono Submodule.annihilator_mono
theorem annihilator_iSup (ι : Sort w) (f : ι → Submodule R M) :
annihilator (⨆ i, f i) = ⨅ i, annihilator (f i) :=
le_antisymm (le_iInf fun _ => annihilator_mono <| le_iSup _ _) fun _ H =>
mem_annihilator'.2 <|
iSup_le fun i =>
have := (mem_iInf _).1 H i
mem_annihilator'.1 this
#align submodule.annihilator_supr Submodule.annihilator_iSup
theorem smul_mem_smul {r} {n} (hr : r ∈ I) (hn : n ∈ N) : r • n ∈ I • N :=
apply_mem_map₂ _ hr hn
#align submodule.smul_mem_smul Submodule.smul_mem_smul
theorem smul_le {P : Submodule R M} : I • N ≤ P ↔ ∀ r ∈ I, ∀ n ∈ N, r • n ∈ P :=
map₂_le
#align submodule.smul_le Submodule.smul_le
@[simp, norm_cast]
lemma coe_set_smul : (I : Set R) • N = I • N :=
Submodule.set_smul_eq_of_le _ _ _
(fun _ _ hr hx => smul_mem_smul hr hx)
(smul_le.mpr fun _ hr _ hx => mem_set_smul_of_mem_mem hr hx)
@[elab_as_elim]
theorem smul_induction_on {p : M → Prop} {x} (H : x ∈ I • N) (smul : ∀ r ∈ I, ∀ n ∈ N, p (r • n))
(add : ∀ x y, p x → p y → p (x + y)) : p x := by
have H0 : p 0 := by simpa only [zero_smul] using smul 0 I.zero_mem 0 N.zero_mem
refine Submodule.iSup_induction (x := x) _ H ?_ H0 add
rintro ⟨i, hi⟩ m ⟨j, hj, hj'⟩
rw [← hj']
exact smul _ hi _ hj
#align submodule.smul_induction_on Submodule.smul_induction_on
/-- Dependent version of `Submodule.smul_induction_on`. -/
@[elab_as_elim]
theorem smul_induction_on' {x : M} (hx : x ∈ I • N) {p : ∀ x, x ∈ I • N → Prop}
(smul : ∀ (r : R) (hr : r ∈ I) (n : M) (hn : n ∈ N), p (r • n) (smul_mem_smul hr hn))
(add : ∀ x hx y hy, p x hx → p y hy → p (x + y) (Submodule.add_mem _ ‹_› ‹_›)) : p x hx := by
refine Exists.elim ?_ fun (h : x ∈ I • N) (H : p x h) => H
exact
smul_induction_on hx (fun a ha x hx => ⟨_, smul _ ha _ hx⟩) fun x y ⟨_, hx⟩ ⟨_, hy⟩ =>
⟨_, add _ _ _ _ hx hy⟩
#align submodule.smul_induction_on' Submodule.smul_induction_on'
theorem mem_smul_span_singleton {I : Ideal R} {m : M} {x : M} :
x ∈ I • span R ({m} : Set M) ↔ ∃ y ∈ I, y • m = x :=
⟨fun hx =>
smul_induction_on hx
(fun r hri n hnm =>
let ⟨s, hs⟩ := mem_span_singleton.1 hnm
⟨r * s, I.mul_mem_right _ hri, hs ▸ mul_smul r s m⟩)
fun m1 m2 ⟨y1, hyi1, hy1⟩ ⟨y2, hyi2, hy2⟩ =>
⟨y1 + y2, I.add_mem hyi1 hyi2, by rw [add_smul, hy1, hy2]⟩,
fun ⟨y, hyi, hy⟩ => hy ▸ smul_mem_smul hyi (subset_span <| Set.mem_singleton m)⟩
#align submodule.mem_smul_span_singleton Submodule.mem_smul_span_singleton
theorem smul_le_right : I • N ≤ N :=
smul_le.2 fun r _ _ => N.smul_mem r
#align submodule.smul_le_right Submodule.smul_le_right
theorem smul_mono (hij : I ≤ J) (hnp : N ≤ P) : I • N ≤ J • P :=
map₂_le_map₂ hij hnp
#align submodule.smul_mono Submodule.smul_mono
theorem smul_mono_left (h : I ≤ J) : I • N ≤ J • N :=
map₂_le_map₂_left h
#align submodule.smul_mono_left Submodule.smul_mono_left
instance : CovariantClass (Ideal R) (Submodule R M) HSMul.hSMul LE.le :=
⟨fun _ _ => map₂_le_map₂_right⟩
@[deprecated smul_mono_right (since := "2024-03-31")]
protected theorem smul_mono_right (h : N ≤ P) : I • N ≤ I • P :=
_root_.smul_mono_right I h
#align submodule.smul_mono_right Submodule.smul_mono_right
theorem map_le_smul_top (I : Ideal R) (f : R →ₗ[R] M) :
Submodule.map f I ≤ I • (⊤ : Submodule R M) := by
rintro _ ⟨y, hy, rfl⟩
rw [← mul_one y, ← smul_eq_mul, f.map_smul]
exact smul_mem_smul hy mem_top
#align submodule.map_le_smul_top Submodule.map_le_smul_top
@[simp]
theorem annihilator_smul (N : Submodule R M) : annihilator N • N = ⊥ :=
eq_bot_iff.2 (smul_le.2 fun _ => mem_annihilator.1)
#align submodule.annihilator_smul Submodule.annihilator_smul
@[simp]
theorem annihilator_mul (I : Ideal R) : annihilator I * I = ⊥ :=
annihilator_smul I
#align submodule.annihilator_mul Submodule.annihilator_mul
@[simp]
theorem mul_annihilator (I : Ideal R) : I * annihilator I = ⊥ := by rw [mul_comm, annihilator_mul]
#align submodule.mul_annihilator Submodule.mul_annihilator
variable (I J N P)
@[simp]
theorem smul_bot : I • (⊥ : Submodule R M) = ⊥ :=
map₂_bot_right _ _
#align submodule.smul_bot Submodule.smul_bot
@[simp]
theorem bot_smul : (⊥ : Ideal R) • N = ⊥ :=
map₂_bot_left _ _
#align submodule.bot_smul Submodule.bot_smul
@[simp]
theorem top_smul : (⊤ : Ideal R) • N = N :=
le_antisymm smul_le_right fun r hri => one_smul R r ▸ smul_mem_smul mem_top hri
#align submodule.top_smul Submodule.top_smul
theorem smul_sup : I • (N ⊔ P) = I • N ⊔ I • P :=
map₂_sup_right _ _ _ _
#align submodule.smul_sup Submodule.smul_sup
theorem sup_smul : (I ⊔ J) • N = I • N ⊔ J • N :=
map₂_sup_left _ _ _ _
#align submodule.sup_smul Submodule.sup_smul
protected theorem smul_assoc : (I • J) • N = I • J • N :=
le_antisymm
(smul_le.2 fun _ hrsij t htn =>
smul_induction_on hrsij
(fun r hr s hs =>
(@smul_eq_mul R _ r s).symm ▸ smul_smul r s t ▸ smul_mem_smul hr (smul_mem_smul hs htn))
fun x y => (add_smul x y t).symm ▸ Submodule.add_mem _)
(smul_le.2 fun r hr _ hsn =>
suffices J • N ≤ Submodule.comap (r • (LinearMap.id : M →ₗ[R] M)) ((I • J) • N) from this hsn
smul_le.2 fun s hs n hn =>
show r • s • n ∈ (I • J) • N from mul_smul r s n ▸ smul_mem_smul (smul_mem_smul hr hs) hn)
#align submodule.smul_assoc Submodule.smul_assoc
@[deprecated smul_inf_le (since := "2024-03-31")]
protected theorem smul_inf_le (M₁ M₂ : Submodule R M) :
I • (M₁ ⊓ M₂) ≤ I • M₁ ⊓ I • M₂ := smul_inf_le _ _ _
#align submodule.smul_inf_le Submodule.smul_inf_le
theorem smul_iSup {ι : Sort*} {I : Ideal R} {t : ι → Submodule R M} : I • iSup t = ⨆ i, I • t i :=
map₂_iSup_right _ _ _
#align submodule.smul_supr Submodule.smul_iSup
@[deprecated smul_iInf_le (since := "2024-03-31")]
protected theorem smul_iInf_le {ι : Sort*} {I : Ideal R} {t : ι → Submodule R M} :
I • iInf t ≤ ⨅ i, I • t i :=
smul_iInf_le
#align submodule.smul_infi_le Submodule.smul_iInf_le
variable (S : Set R) (T : Set M)
theorem span_smul_span : Ideal.span S • span R T = span R (⋃ (s ∈ S) (t ∈ T), {s • t}) :=
(map₂_span_span _ _ _ _).trans <| congr_arg _ <| Set.image2_eq_iUnion _ _ _
#align submodule.span_smul_span Submodule.span_smul_span
theorem ideal_span_singleton_smul (r : R) (N : Submodule R M) :
(Ideal.span {r} : Ideal R) • N = r • N := by
have : span R (⋃ (t : M) (_ : t ∈ N), {r • t}) = r • N := by
convert span_eq (r • N)
exact (Set.image_eq_iUnion _ (N : Set M)).symm
conv_lhs => rw [← span_eq N, span_smul_span]
simpa
#align submodule.ideal_span_singleton_smul Submodule.ideal_span_singleton_smul
theorem mem_of_span_top_of_smul_mem (M' : Submodule R M) (s : Set R) (hs : Ideal.span s = ⊤) (x : M)
(H : ∀ r : s, (r : R) • x ∈ M') : x ∈ M' := by
suffices (⊤ : Ideal R) • span R ({x} : Set M) ≤ M' by
rw [top_smul] at this
exact this (subset_span (Set.mem_singleton x))
rw [← hs, span_smul_span, span_le]
simpa using H
#align submodule.mem_of_span_top_of_smul_mem Submodule.mem_of_span_top_of_smul_mem
/-- Given `s`, a generating set of `R`, to check that an `x : M` falls in a
submodule `M'` of `x`, we only need to show that `r ^ n • x ∈ M'` for some `n` for each `r : s`. -/
theorem mem_of_span_eq_top_of_smul_pow_mem (M' : Submodule R M) (s : Set R) (hs : Ideal.span s = ⊤)
(x : M) (H : ∀ r : s, ∃ n : ℕ, ((r : R) ^ n : R) • x ∈ M') : x ∈ M' := by
obtain ⟨s', hs₁, hs₂⟩ := (Ideal.span_eq_top_iff_finite _).mp hs
replace H : ∀ r : s', ∃ n : ℕ, ((r : R) ^ n : R) • x ∈ M' := fun r => H ⟨_, hs₁ r.2⟩
choose n₁ n₂ using H
let N := s'.attach.sup n₁
have hs' := Ideal.span_pow_eq_top (s' : Set R) hs₂ N
apply M'.mem_of_span_top_of_smul_mem _ hs'
rintro ⟨_, r, hr, rfl⟩
convert M'.smul_mem (r ^ (N - n₁ ⟨r, hr⟩)) (n₂ ⟨r, hr⟩) using 1
simp only [Subtype.coe_mk, smul_smul, ← pow_add]
rw [tsub_add_cancel_of_le (Finset.le_sup (s'.mem_attach _) : n₁ ⟨r, hr⟩ ≤ N)]
#align submodule.mem_of_span_eq_top_of_smul_pow_mem Submodule.mem_of_span_eq_top_of_smul_pow_mem
variable {M' : Type w} [AddCommMonoid M'] [Module R M']
@[simp]
theorem map_smul'' (f : M →ₗ[R] M') : (I • N).map f = I • N.map f :=
le_antisymm
(map_le_iff_le_comap.2 <|
smul_le.2 fun r hr n hn =>
show f (r • n) ∈ I • N.map f from
(f.map_smul r n).symm ▸ smul_mem_smul hr (mem_map_of_mem hn)) <|
smul_le.2 fun r hr _ hn =>
let ⟨p, hp, hfp⟩ := mem_map.1 hn
hfp ▸ f.map_smul r p ▸ mem_map_of_mem (smul_mem_smul hr hp)
#align submodule.map_smul'' Submodule.map_smul''
open Pointwise in
@[simp]
theorem map_pointwise_smul (r : R) (N : Submodule R M) (f : M →ₗ[R] M') :
(r • N).map f = r • N.map f := by
simp_rw [← ideal_span_singleton_smul, map_smul'']
variable {I}
theorem mem_smul_span {s : Set M} {x : M} :
x ∈ I • Submodule.span R s ↔ x ∈ Submodule.span R (⋃ (a ∈ I) (b ∈ s), ({a • b} : Set M)) := by
rw [← I.span_eq, Submodule.span_smul_span, I.span_eq]
rfl
#align submodule.mem_smul_span Submodule.mem_smul_span
variable (I)
/-- If `x` is an `I`-multiple of the submodule spanned by `f '' s`,
then we can write `x` as an `I`-linear combination of the elements of `f '' s`. -/
theorem mem_ideal_smul_span_iff_exists_sum {ι : Type*} (f : ι → M) (x : M) :
x ∈ I • span R (Set.range f) ↔
∃ (a : ι →₀ R) (_ : ∀ i, a i ∈ I), (a.sum fun i c => c • f i) = x := by
constructor; swap
· rintro ⟨a, ha, rfl⟩
exact Submodule.sum_mem _ fun c _ => smul_mem_smul (ha c) <| subset_span <| Set.mem_range_self _
refine fun hx => span_induction (mem_smul_span.mp hx) ?_ ?_ ?_ ?_
· simp only [Set.mem_iUnion, Set.mem_range, Set.mem_singleton_iff]
rintro x ⟨y, hy, x, ⟨i, rfl⟩, rfl⟩
refine ⟨Finsupp.single i y, fun j => ?_, ?_⟩
· letI := Classical.decEq ι
rw [Finsupp.single_apply]
split_ifs
· assumption
· exact I.zero_mem
refine @Finsupp.sum_single_index ι R M _ _ i _ (fun i y => y • f i) ?_
simp
· exact ⟨0, fun _ => I.zero_mem, Finsupp.sum_zero_index⟩
· rintro x y ⟨ax, hax, rfl⟩ ⟨ay, hay, rfl⟩
refine ⟨ax + ay, fun i => I.add_mem (hax i) (hay i), Finsupp.sum_add_index' ?_ ?_⟩ <;>
intros <;> simp only [zero_smul, add_smul]
· rintro c x ⟨a, ha, rfl⟩
refine ⟨c • a, fun i => I.mul_mem_left c (ha i), ?_⟩
rw [Finsupp.sum_smul_index, Finsupp.smul_sum] <;> intros <;> simp only [zero_smul, mul_smul]
#align submodule.mem_ideal_smul_span_iff_exists_sum Submodule.mem_ideal_smul_span_iff_exists_sum
theorem mem_ideal_smul_span_iff_exists_sum' {ι : Type*} (s : Set ι) (f : ι → M) (x : M) :
x ∈ I • span R (f '' s) ↔
∃ (a : s →₀ R) (_ : ∀ i, a i ∈ I), (a.sum fun i c => c • f i) = x := by
rw [← Submodule.mem_ideal_smul_span_iff_exists_sum, ← Set.image_eq_range]
#align submodule.mem_ideal_smul_span_iff_exists_sum' Submodule.mem_ideal_smul_span_iff_exists_sum'
theorem mem_smul_top_iff (N : Submodule R M) (x : N) :
x ∈ I • (⊤ : Submodule R N) ↔ (x : M) ∈ I • N := by
change _ ↔ N.subtype x ∈ I • N
have : Submodule.map N.subtype (I • ⊤) = I • N := by
rw [Submodule.map_smul'', Submodule.map_top, Submodule.range_subtype]
rw [← this]
exact (Function.Injective.mem_set_image N.injective_subtype).symm
#align submodule.mem_smul_top_iff Submodule.mem_smul_top_iff
@[simp]
theorem smul_comap_le_comap_smul (f : M →ₗ[R] M') (S : Submodule R M') (I : Ideal R) :
I • S.comap f ≤ (I • S).comap f := by
refine Submodule.smul_le.mpr fun r hr x hx => ?_
rw [Submodule.mem_comap] at hx ⊢
rw [f.map_smul]
exact Submodule.smul_mem_smul hr hx
#align submodule.smul_comap_le_comap_smul Submodule.smul_comap_le_comap_smul
end CommSemiring
end Submodule
namespace Ideal
section Add
variable {R : Type u} [Semiring R]
@[simp]
theorem add_eq_sup {I J : Ideal R} : I + J = I ⊔ J :=
rfl
#align ideal.add_eq_sup Ideal.add_eq_sup
@[simp]
theorem zero_eq_bot : (0 : Ideal R) = ⊥ :=
rfl
#align ideal.zero_eq_bot Ideal.zero_eq_bot
@[simp]
theorem sum_eq_sup {ι : Type*} (s : Finset ι) (f : ι → Ideal R) : s.sum f = s.sup f :=
rfl
#align ideal.sum_eq_sup Ideal.sum_eq_sup
end Add
section MulAndRadical
variable {R : Type u} {ι : Type*} [CommSemiring R]
variable {I J K L : Ideal R}
instance : Mul (Ideal R) :=
⟨(· • ·)⟩
@[simp]
theorem one_eq_top : (1 : Ideal R) = ⊤ := by erw [Submodule.one_eq_range, LinearMap.range_id]
#align ideal.one_eq_top Ideal.one_eq_top
theorem add_eq_one_iff : I + J = 1 ↔ ∃ i ∈ I, ∃ j ∈ J, i + j = 1 := by
rw [one_eq_top, eq_top_iff_one, add_eq_sup, Submodule.mem_sup]
theorem mul_mem_mul {r s} (hr : r ∈ I) (hs : s ∈ J) : r * s ∈ I * J :=
Submodule.smul_mem_smul hr hs
#align ideal.mul_mem_mul Ideal.mul_mem_mul
theorem mul_mem_mul_rev {r s} (hr : r ∈ I) (hs : s ∈ J) : s * r ∈ I * J :=
mul_comm r s ▸ mul_mem_mul hr hs
#align ideal.mul_mem_mul_rev Ideal.mul_mem_mul_rev
theorem pow_mem_pow {x : R} (hx : x ∈ I) (n : ℕ) : x ^ n ∈ I ^ n :=
Submodule.pow_mem_pow _ hx _
#align ideal.pow_mem_pow Ideal.pow_mem_pow
theorem prod_mem_prod {ι : Type*} {s : Finset ι} {I : ι → Ideal R} {x : ι → R} :
(∀ i ∈ s, x i ∈ I i) → (∏ i ∈ s, x i) ∈ ∏ i ∈ s, I i := by
classical
refine Finset.induction_on s ?_ ?_
· intro
rw [Finset.prod_empty, Finset.prod_empty, one_eq_top]
exact Submodule.mem_top
· intro a s ha IH h
rw [Finset.prod_insert ha, Finset.prod_insert ha]
exact
mul_mem_mul (h a <| Finset.mem_insert_self a s)
(IH fun i hi => h i <| Finset.mem_insert_of_mem hi)
#align ideal.prod_mem_prod Ideal.prod_mem_prod
theorem mul_le : I * J ≤ K ↔ ∀ r ∈ I, ∀ s ∈ J, r * s ∈ K :=
Submodule.smul_le
#align ideal.mul_le Ideal.mul_le
theorem mul_le_left : I * J ≤ J :=
Ideal.mul_le.2 fun _ _ _ => J.mul_mem_left _
#align ideal.mul_le_left Ideal.mul_le_left
theorem mul_le_right : I * J ≤ I :=
Ideal.mul_le.2 fun _ hr _ _ => I.mul_mem_right _ hr
#align ideal.mul_le_right Ideal.mul_le_right
@[simp]
theorem sup_mul_right_self : I ⊔ I * J = I :=
sup_eq_left.2 Ideal.mul_le_right
#align ideal.sup_mul_right_self Ideal.sup_mul_right_self
@[simp]
theorem sup_mul_left_self : I ⊔ J * I = I :=
sup_eq_left.2 Ideal.mul_le_left
#align ideal.sup_mul_left_self Ideal.sup_mul_left_self
@[simp]
theorem mul_right_self_sup : I * J ⊔ I = I :=
sup_eq_right.2 Ideal.mul_le_right
#align ideal.mul_right_self_sup Ideal.mul_right_self_sup
@[simp]
theorem mul_left_self_sup : J * I ⊔ I = I :=
sup_eq_right.2 Ideal.mul_le_left
#align ideal.mul_left_self_sup Ideal.mul_left_self_sup
variable (I J K)
protected theorem mul_comm : I * J = J * I :=
le_antisymm (mul_le.2 fun _ hrI _ hsJ => mul_mem_mul_rev hsJ hrI)
(mul_le.2 fun _ hrJ _ hsI => mul_mem_mul_rev hsI hrJ)
#align ideal.mul_comm Ideal.mul_comm
protected theorem mul_assoc : I * J * K = I * (J * K) :=
Submodule.smul_assoc I J K
#align ideal.mul_assoc Ideal.mul_assoc
theorem span_mul_span (S T : Set R) : span S * span T = span (⋃ (s ∈ S) (t ∈ T), {s * t}) :=
Submodule.span_smul_span S T
#align ideal.span_mul_span Ideal.span_mul_span
variable {I J K}
theorem span_mul_span' (S T : Set R) : span S * span T = span (S * T) := by
unfold span
rw [Submodule.span_mul_span]
#align ideal.span_mul_span' Ideal.span_mul_span'
theorem span_singleton_mul_span_singleton (r s : R) :
span {r} * span {s} = (span {r * s} : Ideal R) := by
unfold span
rw [Submodule.span_mul_span, Set.singleton_mul_singleton]
#align ideal.span_singleton_mul_span_singleton Ideal.span_singleton_mul_span_singleton
theorem span_singleton_pow (s : R) (n : ℕ) : span {s} ^ n = (span {s ^ n} : Ideal R) := by
induction' n with n ih; · simp [Set.singleton_one]
simp only [pow_succ, ih, span_singleton_mul_span_singleton]
#align ideal.span_singleton_pow Ideal.span_singleton_pow
theorem mem_mul_span_singleton {x y : R} {I : Ideal R} : x ∈ I * span {y} ↔ ∃ z ∈ I, z * y = x :=
Submodule.mem_smul_span_singleton
#align ideal.mem_mul_span_singleton Ideal.mem_mul_span_singleton
theorem mem_span_singleton_mul {x y : R} {I : Ideal R} : x ∈ span {y} * I ↔ ∃ z ∈ I, y * z = x := by
simp only [mul_comm, mem_mul_span_singleton]
#align ideal.mem_span_singleton_mul Ideal.mem_span_singleton_mul
theorem le_span_singleton_mul_iff {x : R} {I J : Ideal R} :
I ≤ span {x} * J ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI :=
show (∀ {zI} (_ : zI ∈ I), zI ∈ span {x} * J) ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI by
simp only [mem_span_singleton_mul]
#align ideal.le_span_singleton_mul_iff Ideal.le_span_singleton_mul_iff
theorem span_singleton_mul_le_iff {x : R} {I J : Ideal R} :
span {x} * I ≤ J ↔ ∀ z ∈ I, x * z ∈ J := by
simp only [mul_le, mem_span_singleton_mul, mem_span_singleton]
constructor
· intro h zI hzI
exact h x (dvd_refl x) zI hzI
· rintro h _ ⟨z, rfl⟩ zI hzI
rw [mul_comm x z, mul_assoc]
exact J.mul_mem_left _ (h zI hzI)
#align ideal.span_singleton_mul_le_iff Ideal.span_singleton_mul_le_iff
theorem span_singleton_mul_le_span_singleton_mul {x y : R} {I J : Ideal R} :
span {x} * I ≤ span {y} * J ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zI = y * zJ := by
simp only [span_singleton_mul_le_iff, mem_span_singleton_mul, eq_comm]
#align ideal.span_singleton_mul_le_span_singleton_mul Ideal.span_singleton_mul_le_span_singleton_mul
theorem span_singleton_mul_right_mono [IsDomain R] {x : R} (hx : x ≠ 0) :
span {x} * I ≤ span {x} * J ↔ I ≤ J := by
simp_rw [span_singleton_mul_le_span_singleton_mul, mul_right_inj' hx,
exists_eq_right', SetLike.le_def]
#align ideal.span_singleton_mul_right_mono Ideal.span_singleton_mul_right_mono
theorem span_singleton_mul_left_mono [IsDomain R] {x : R} (hx : x ≠ 0) :
I * span {x} ≤ J * span {x} ↔ I ≤ J := by
simpa only [mul_comm I, mul_comm J] using span_singleton_mul_right_mono hx
#align ideal.span_singleton_mul_left_mono Ideal.span_singleton_mul_left_mono
theorem span_singleton_mul_right_inj [IsDomain R] {x : R} (hx : x ≠ 0) :
span {x} * I = span {x} * J ↔ I = J := by
simp only [le_antisymm_iff, span_singleton_mul_right_mono hx]
#align ideal.span_singleton_mul_right_inj Ideal.span_singleton_mul_right_inj
theorem span_singleton_mul_left_inj [IsDomain R] {x : R} (hx : x ≠ 0) :
I * span {x} = J * span {x} ↔ I = J := by
simp only [le_antisymm_iff, span_singleton_mul_left_mono hx]
#align ideal.span_singleton_mul_left_inj Ideal.span_singleton_mul_left_inj
theorem span_singleton_mul_right_injective [IsDomain R] {x : R} (hx : x ≠ 0) :
Function.Injective ((span {x} : Ideal R) * ·) := fun _ _ =>
(span_singleton_mul_right_inj hx).mp
#align ideal.span_singleton_mul_right_injective Ideal.span_singleton_mul_right_injective
theorem span_singleton_mul_left_injective [IsDomain R] {x : R} (hx : x ≠ 0) :
Function.Injective fun I : Ideal R => I * span {x} := fun _ _ =>
(span_singleton_mul_left_inj hx).mp
#align ideal.span_singleton_mul_left_injective Ideal.span_singleton_mul_left_injective
theorem eq_span_singleton_mul {x : R} (I J : Ideal R) :
I = span {x} * J ↔ (∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI) ∧ ∀ z ∈ J, x * z ∈ I := by
simp only [le_antisymm_iff, le_span_singleton_mul_iff, span_singleton_mul_le_iff]
#align ideal.eq_span_singleton_mul Ideal.eq_span_singleton_mul
theorem span_singleton_mul_eq_span_singleton_mul {x y : R} (I J : Ideal R) :
span {x} * I = span {y} * J ↔
(∀ zI ∈ I, ∃ zJ ∈ J, x * zI = y * zJ) ∧ ∀ zJ ∈ J, ∃ zI ∈ I, x * zI = y * zJ := by
simp only [le_antisymm_iff, span_singleton_mul_le_span_singleton_mul, eq_comm]
#align ideal.span_singleton_mul_eq_span_singleton_mul Ideal.span_singleton_mul_eq_span_singleton_mul
theorem prod_span {ι : Type*} (s : Finset ι) (I : ι → Set R) :
(∏ i ∈ s, Ideal.span (I i)) = Ideal.span (∏ i ∈ s, I i) :=
Submodule.prod_span s I
#align ideal.prod_span Ideal.prod_span
theorem prod_span_singleton {ι : Type*} (s : Finset ι) (I : ι → R) :
(∏ i ∈ s, Ideal.span ({I i} : Set R)) = Ideal.span {∏ i ∈ s, I i} :=
Submodule.prod_span_singleton s I
#align ideal.prod_span_singleton Ideal.prod_span_singleton
@[simp]
theorem multiset_prod_span_singleton (m : Multiset R) :
(m.map fun x => Ideal.span {x}).prod = Ideal.span ({Multiset.prod m} : Set R) :=
Multiset.induction_on m (by simp) fun a m ih => by
simp only [Multiset.map_cons, Multiset.prod_cons, ih, ← Ideal.span_singleton_mul_span_singleton]
#align ideal.multiset_prod_span_singleton Ideal.multiset_prod_span_singleton
theorem finset_inf_span_singleton {ι : Type*} (s : Finset ι) (I : ι → R)
(hI : Set.Pairwise (↑s) (IsCoprime on I)) :
(s.inf fun i => Ideal.span ({I i} : Set R)) = Ideal.span {∏ i ∈ s, I i} := by
ext x
simp only [Submodule.mem_finset_inf, Ideal.mem_span_singleton]
exact ⟨Finset.prod_dvd_of_coprime hI, fun h i hi => (Finset.dvd_prod_of_mem _ hi).trans h⟩
#align ideal.finset_inf_span_singleton Ideal.finset_inf_span_singleton
theorem iInf_span_singleton {ι : Type*} [Fintype ι] {I : ι → R}
(hI : ∀ (i j) (_ : i ≠ j), IsCoprime (I i) (I j)) :
⨅ i, span ({I i} : Set R) = span {∏ i, I i} := by
rw [← Finset.inf_univ_eq_iInf, finset_inf_span_singleton]
rwa [Finset.coe_univ, Set.pairwise_univ]
#align ideal.infi_span_singleton Ideal.iInf_span_singleton
theorem iInf_span_singleton_natCast {R : Type*} [CommRing R] {ι : Type*} [Fintype ι]
{I : ι → ℕ} (hI : Pairwise fun i j => (I i).Coprime (I j)) :
⨅ (i : ι), span {(I i : R)} = span {((∏ i : ι, I i : ℕ) : R)} := by
rw [iInf_span_singleton, Nat.cast_prod]
exact fun i j h ↦ (hI h).cast
theorem sup_eq_top_iff_isCoprime {R : Type*} [CommSemiring R] (x y : R) :
span ({x} : Set R) ⊔ span {y} = ⊤ ↔ IsCoprime x y := by
rw [eq_top_iff_one, Submodule.mem_sup]
constructor
· rintro ⟨u, hu, v, hv, h1⟩
rw [mem_span_singleton'] at hu hv
rw [← hu.choose_spec, ← hv.choose_spec] at h1
exact ⟨_, _, h1⟩
· exact fun ⟨u, v, h1⟩ =>
⟨_, mem_span_singleton'.mpr ⟨_, rfl⟩, _, mem_span_singleton'.mpr ⟨_, rfl⟩, h1⟩
#align ideal.sup_eq_top_iff_is_coprime Ideal.sup_eq_top_iff_isCoprime
theorem mul_le_inf : I * J ≤ I ⊓ J :=
mul_le.2 fun r hri s hsj => ⟨I.mul_mem_right s hri, J.mul_mem_left r hsj⟩
#align ideal.mul_le_inf Ideal.mul_le_inf
theorem multiset_prod_le_inf {s : Multiset (Ideal R)} : s.prod ≤ s.inf := by
classical
refine s.induction_on ?_ ?_
· rw [Multiset.inf_zero]
exact le_top
intro a s ih
rw [Multiset.prod_cons, Multiset.inf_cons]
exact le_trans mul_le_inf (inf_le_inf le_rfl ih)
#align ideal.multiset_prod_le_inf Ideal.multiset_prod_le_inf
theorem prod_le_inf {s : Finset ι} {f : ι → Ideal R} : s.prod f ≤ s.inf f :=
multiset_prod_le_inf
#align ideal.prod_le_inf Ideal.prod_le_inf
theorem mul_eq_inf_of_coprime (h : I ⊔ J = ⊤) : I * J = I ⊓ J :=
le_antisymm mul_le_inf fun r ⟨hri, hrj⟩ =>
let ⟨s, hsi, t, htj, hst⟩ := Submodule.mem_sup.1 ((eq_top_iff_one _).1 h)
mul_one r ▸
hst ▸
(mul_add r s t).symm ▸ Ideal.add_mem (I * J) (mul_mem_mul_rev hsi hrj) (mul_mem_mul hri htj)
#align ideal.mul_eq_inf_of_coprime Ideal.mul_eq_inf_of_coprime
theorem sup_mul_eq_of_coprime_left (h : I ⊔ J = ⊤) : I ⊔ J * K = I ⊔ K :=
le_antisymm (sup_le_sup_left mul_le_left _) fun i hi => by
rw [eq_top_iff_one] at h; rw [Submodule.mem_sup] at h hi ⊢
obtain ⟨i1, hi1, j, hj, h⟩ := h; obtain ⟨i', hi', k, hk, hi⟩ := hi
refine ⟨_, add_mem hi' (mul_mem_right k _ hi1), _, mul_mem_mul hj hk, ?_⟩
rw [add_assoc, ← add_mul, h, one_mul, hi]
#align ideal.sup_mul_eq_of_coprime_left Ideal.sup_mul_eq_of_coprime_left
theorem sup_mul_eq_of_coprime_right (h : I ⊔ K = ⊤) : I ⊔ J * K = I ⊔ J := by
rw [mul_comm]
exact sup_mul_eq_of_coprime_left h
#align ideal.sup_mul_eq_of_coprime_right Ideal.sup_mul_eq_of_coprime_right
theorem mul_sup_eq_of_coprime_left (h : I ⊔ J = ⊤) : I * K ⊔ J = K ⊔ J := by
rw [sup_comm] at h
rw [sup_comm, sup_mul_eq_of_coprime_left h, sup_comm]
#align ideal.mul_sup_eq_of_coprime_left Ideal.mul_sup_eq_of_coprime_left
theorem mul_sup_eq_of_coprime_right (h : K ⊔ J = ⊤) : I * K ⊔ J = I ⊔ J := by
rw [sup_comm] at h
rw [sup_comm, sup_mul_eq_of_coprime_right h, sup_comm]
#align ideal.mul_sup_eq_of_coprime_right Ideal.mul_sup_eq_of_coprime_right
theorem sup_prod_eq_top {s : Finset ι} {J : ι → Ideal R} (h : ∀ i, i ∈ s → I ⊔ J i = ⊤) :
(I ⊔ ∏ i ∈ s, J i) = ⊤ :=
Finset.prod_induction _ (fun J => I ⊔ J = ⊤)
(fun J K hJ hK => (sup_mul_eq_of_coprime_left hJ).trans hK)
(by simp_rw [one_eq_top, sup_top_eq]) h
#align ideal.sup_prod_eq_top Ideal.sup_prod_eq_top
theorem sup_iInf_eq_top {s : Finset ι} {J : ι → Ideal R} (h : ∀ i, i ∈ s → I ⊔ J i = ⊤) :
(I ⊔ ⨅ i ∈ s, J i) = ⊤ :=
eq_top_iff.mpr <|
le_of_eq_of_le (sup_prod_eq_top h).symm <|
sup_le_sup_left (le_of_le_of_eq prod_le_inf <| Finset.inf_eq_iInf _ _) _
#align ideal.sup_infi_eq_top Ideal.sup_iInf_eq_top
theorem prod_sup_eq_top {s : Finset ι} {J : ι → Ideal R} (h : ∀ i, i ∈ s → J i ⊔ I = ⊤) :
(∏ i ∈ s, J i) ⊔ I = ⊤ := by rw [sup_comm, sup_prod_eq_top]; intro i hi; rw [sup_comm, h i hi]
#align ideal.prod_sup_eq_top Ideal.prod_sup_eq_top
theorem iInf_sup_eq_top {s : Finset ι} {J : ι → Ideal R} (h : ∀ i, i ∈ s → J i ⊔ I = ⊤) :
(⨅ i ∈ s, J i) ⊔ I = ⊤ := by rw [sup_comm, sup_iInf_eq_top]; intro i hi; rw [sup_comm, h i hi]
#align ideal.infi_sup_eq_top Ideal.iInf_sup_eq_top
theorem sup_pow_eq_top {n : ℕ} (h : I ⊔ J = ⊤) : I ⊔ J ^ n = ⊤ := by
rw [← Finset.card_range n, ← Finset.prod_const]
exact sup_prod_eq_top fun _ _ => h
#align ideal.sup_pow_eq_top Ideal.sup_pow_eq_top
theorem pow_sup_eq_top {n : ℕ} (h : I ⊔ J = ⊤) : I ^ n ⊔ J = ⊤ := by
rw [← Finset.card_range n, ← Finset.prod_const]
exact prod_sup_eq_top fun _ _ => h
#align ideal.pow_sup_eq_top Ideal.pow_sup_eq_top
theorem pow_sup_pow_eq_top {m n : ℕ} (h : I ⊔ J = ⊤) : I ^ m ⊔ J ^ n = ⊤ :=
sup_pow_eq_top (pow_sup_eq_top h)
#align ideal.pow_sup_pow_eq_top Ideal.pow_sup_pow_eq_top
variable (I)
-- @[simp] -- Porting note (#10618): simp can prove this
theorem mul_bot : I * ⊥ = ⊥ := by simp
#align ideal.mul_bot Ideal.mul_bot
-- @[simp] -- Porting note (#10618): simp can prove thisrove this
theorem bot_mul : ⊥ * I = ⊥ := by simp
#align ideal.bot_mul Ideal.bot_mul
@[simp]
theorem mul_top : I * ⊤ = I :=
Ideal.mul_comm ⊤ I ▸ Submodule.top_smul I
#align ideal.mul_top Ideal.mul_top
@[simp]
theorem top_mul : ⊤ * I = I :=
Submodule.top_smul I
#align ideal.top_mul Ideal.top_mul
variable {I}
theorem mul_mono (hik : I ≤ K) (hjl : J ≤ L) : I * J ≤ K * L :=
Submodule.smul_mono hik hjl
#align ideal.mul_mono Ideal.mul_mono
theorem mul_mono_left (h : I ≤ J) : I * K ≤ J * K :=
Submodule.smul_mono_left h
#align ideal.mul_mono_left Ideal.mul_mono_left
theorem mul_mono_right (h : J ≤ K) : I * J ≤ I * K :=
smul_mono_right _ h
#align ideal.mul_mono_right Ideal.mul_mono_right
variable (I J K)
theorem mul_sup : I * (J ⊔ K) = I * J ⊔ I * K :=
Submodule.smul_sup I J K
#align ideal.mul_sup Ideal.mul_sup
theorem sup_mul : (I ⊔ J) * K = I * K ⊔ J * K :=
Submodule.sup_smul I J K
#align ideal.sup_mul Ideal.sup_mul
variable {I J K}
theorem pow_le_pow_right {m n : ℕ} (h : m ≤ n) : I ^ n ≤ I ^ m := by
cases' Nat.exists_eq_add_of_le h with k hk
rw [hk, pow_add]
exact le_trans mul_le_inf inf_le_left
#align ideal.pow_le_pow_right Ideal.pow_le_pow_right
theorem pow_le_self {n : ℕ} (hn : n ≠ 0) : I ^ n ≤ I :=
calc
I ^ n ≤ I ^ 1 := pow_le_pow_right (Nat.pos_of_ne_zero hn)
_ = I := pow_one _
#align ideal.pow_le_self Ideal.pow_le_self
theorem pow_right_mono {I J : Ideal R} (e : I ≤ J) (n : ℕ) : I ^ n ≤ J ^ n := by
induction' n with _ hn
· rw [pow_zero, pow_zero]
· rw [pow_succ, pow_succ]
exact Ideal.mul_mono hn e
#align ideal.pow_right_mono Ideal.pow_right_mono
@[simp]
theorem mul_eq_bot {R : Type*} [CommSemiring R] [NoZeroDivisors R] {I J : Ideal R} :
I * J = ⊥ ↔ I = ⊥ ∨ J = ⊥ :=
⟨fun hij =>
or_iff_not_imp_left.mpr fun I_ne_bot =>
J.eq_bot_iff.mpr fun j hj =>
let ⟨i, hi, ne0⟩ := I.ne_bot_iff.mp I_ne_bot
Or.resolve_left (mul_eq_zero.mp ((I * J).eq_bot_iff.mp hij _ (mul_mem_mul hi hj))) ne0,
fun h => by cases' h with h h <;> rw [← Ideal.mul_bot, h, Ideal.mul_comm]⟩
#align ideal.mul_eq_bot Ideal.mul_eq_bot
instance {R : Type*} [CommSemiring R] [NoZeroDivisors R] : NoZeroDivisors (Ideal R) where
eq_zero_or_eq_zero_of_mul_eq_zero := mul_eq_bot.1
instance {R : Type*} [CommSemiring R] {S : Type*} [CommRing S] [Algebra R S]
[NoZeroSMulDivisors R S] {I : Ideal S} : NoZeroSMulDivisors R I :=
Submodule.noZeroSMulDivisors (Submodule.restrictScalars R I)
/-- A product of ideals in an integral domain is zero if and only if one of the terms is zero. -/
@[simp]
lemma multiset_prod_eq_bot {R : Type*} [CommRing R] [IsDomain R] {s : Multiset (Ideal R)} :
s.prod = ⊥ ↔ ⊥ ∈ s :=
Multiset.prod_eq_zero_iff
/-- A product of ideals in an integral domain is zero if and only if one of the terms is zero. -/
@[deprecated multiset_prod_eq_bot (since := "2023-12-26")]
theorem prod_eq_bot {R : Type*} [CommRing R] [IsDomain R] {s : Multiset (Ideal R)} :
s.prod = ⊥ ↔ ∃ I ∈ s, I = ⊥ := by
simp
#align ideal.prod_eq_bot Ideal.prod_eq_bot
theorem span_pair_mul_span_pair (w x y z : R) :
(span {w, x} : Ideal R) * span {y, z} = span {w * y, w * z, x * y, x * z} := by
simp_rw [span_insert, sup_mul, mul_sup, span_singleton_mul_span_singleton, sup_assoc]
#align ideal.span_pair_mul_span_pair Ideal.span_pair_mul_span_pair
theorem isCoprime_iff_codisjoint : IsCoprime I J ↔ Codisjoint I J := by
rw [IsCoprime, codisjoint_iff]
constructor
· rintro ⟨x, y, hxy⟩
rw [eq_top_iff_one]
apply (show x * I + y * J ≤ I ⊔ J from
sup_le (mul_le_left.trans le_sup_left) (mul_le_left.trans le_sup_right))
rw [hxy]
simp only [one_eq_top, Submodule.mem_top]
· intro h
refine ⟨1, 1, ?_⟩
simpa only [one_eq_top, top_mul, Submodule.add_eq_sup]
theorem isCoprime_iff_add : IsCoprime I J ↔ I + J = 1 := by
rw [isCoprime_iff_codisjoint, codisjoint_iff, add_eq_sup, one_eq_top]
theorem isCoprime_iff_exists : IsCoprime I J ↔ ∃ i ∈ I, ∃ j ∈ J, i + j = 1 := by
rw [← add_eq_one_iff, isCoprime_iff_add]
theorem isCoprime_iff_sup_eq : IsCoprime I J ↔ I ⊔ J = ⊤ := by
rw [isCoprime_iff_codisjoint, codisjoint_iff]
open List in
theorem isCoprime_tfae : TFAE [IsCoprime I J, Codisjoint I J, I + J = 1,
∃ i ∈ I, ∃ j ∈ J, i + j = 1, I ⊔ J = ⊤] := by
rw [← isCoprime_iff_codisjoint, ← isCoprime_iff_add, ← isCoprime_iff_exists,
← isCoprime_iff_sup_eq]
simp
theorem _root_.IsCoprime.codisjoint (h : IsCoprime I J) : Codisjoint I J :=
isCoprime_iff_codisjoint.mp h
theorem _root_.IsCoprime.add_eq (h : IsCoprime I J) : I + J = 1 := isCoprime_iff_add.mp h
theorem _root_.IsCoprime.exists (h : IsCoprime I J) : ∃ i ∈ I, ∃ j ∈ J, i + j = 1 :=
isCoprime_iff_exists.mp h
theorem _root_.IsCoprime.sup_eq (h : IsCoprime I J) : I ⊔ J = ⊤ := isCoprime_iff_sup_eq.mp h
theorem inf_eq_mul_of_isCoprime (coprime : IsCoprime I J) : I ⊓ J = I * J :=
(Ideal.mul_eq_inf_of_coprime coprime.sup_eq).symm
#align ideal.inf_eq_mul_of_coprime Ideal.inf_eq_mul_of_isCoprime
@[deprecated (since := "2024-05-28")]
alias inf_eq_mul_of_coprime := inf_eq_mul_of_isCoprime
theorem isCoprime_span_singleton_iff (x y : R) :
IsCoprime (span <| singleton x) (span <| singleton y) ↔ IsCoprime x y := by
simp_rw [isCoprime_iff_codisjoint, codisjoint_iff, eq_top_iff_one, mem_span_singleton_sup,
mem_span_singleton]
constructor
· rintro ⟨a, _, ⟨b, rfl⟩, e⟩; exact ⟨a, b, mul_comm b y ▸ e⟩
· rintro ⟨a, b, e⟩; exact ⟨a, _, ⟨b, rfl⟩, mul_comm y b ▸ e⟩
| Mathlib/RingTheory/Ideal/Operations.lean | 885 | 899 | theorem isCoprime_biInf {J : ι → Ideal R} {s : Finset ι}
(hf : ∀ j ∈ s, IsCoprime I (J j)) : IsCoprime I (⨅ j ∈ s, J j) := by |
classical
simp_rw [isCoprime_iff_add] at *
induction s using Finset.induction with
| empty =>
simp
| @insert i s _ hs =>
rw [Finset.iInf_insert, inf_comm, one_eq_top, eq_top_iff, ← one_eq_top]
set K := ⨅ j ∈ s, J j
calc
1 = I + K := (hs fun j hj ↦ hf j (Finset.mem_insert_of_mem hj)).symm
_ = I + K*(I + J i) := by rw [hf i (Finset.mem_insert_self i s), mul_one]
_ = (1+K)*I + K*J i := by ring
_ ≤ I + K ⊓ J i := add_le_add mul_le_left mul_le_inf
|
/-
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.Data.Finset.Sort
import Mathlib.Data.Fin.VecNotation
import Mathlib.Data.Sign
import Mathlib.LinearAlgebra.AffineSpace.Combination
import Mathlib.LinearAlgebra.AffineSpace.AffineEquiv
import Mathlib.LinearAlgebra.Basis.VectorSpace
#align_import linear_algebra.affine_space.independent from "leanprover-community/mathlib"@"2de9c37fa71dde2f1c6feff19876dd6a7b1519f0"
/-!
# Affine independence
This file defines affinely independent families of points.
## Main definitions
* `AffineIndependent` defines affinely independent families of points
as those where no nontrivial weighted subtraction is `0`. This is
proved equivalent to two other formulations: linear independence of
the results of subtracting a base point in the family from the other
points in the family, or any equal affine combinations having the
same weights. A bundled type `Simplex` is provided for finite
affinely independent families of points, with an abbreviation
`Triangle` for the case of three points.
## References
* https://en.wikipedia.org/wiki/Affine_space
-/
noncomputable section
open Finset Function
open scoped Affine
section AffineIndependent
variable (k : Type*) {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V]
variable [AffineSpace V P] {ι : Type*}
/-- An indexed family is said to be affinely independent if no
nontrivial weighted subtractions (where the sum of weights is 0) are
0. -/
def AffineIndependent (p : ι → P) : Prop :=
∀ (s : Finset ι) (w : ι → k),
∑ i ∈ s, w i = 0 → s.weightedVSub p w = (0 : V) → ∀ i ∈ s, w i = 0
#align affine_independent AffineIndependent
/-- The definition of `AffineIndependent`. -/
theorem affineIndependent_def (p : ι → P) :
AffineIndependent k p ↔
∀ (s : Finset ι) (w : ι → k),
∑ i ∈ s, w i = 0 → s.weightedVSub p w = (0 : V) → ∀ i ∈ s, w i = 0 :=
Iff.rfl
#align affine_independent_def affineIndependent_def
/-- A family with at most one point is affinely independent. -/
theorem affineIndependent_of_subsingleton [Subsingleton ι] (p : ι → P) : AffineIndependent k p :=
fun _ _ h _ i hi => Fintype.eq_of_subsingleton_of_sum_eq h i hi
#align affine_independent_of_subsingleton affineIndependent_of_subsingleton
/-- A family indexed by a `Fintype` is affinely independent if and
only if no nontrivial weighted subtractions over `Finset.univ` (where
the sum of the weights is 0) are 0. -/
theorem affineIndependent_iff_of_fintype [Fintype ι] (p : ι → P) :
AffineIndependent k p ↔
∀ w : ι → k, ∑ i, w i = 0 → Finset.univ.weightedVSub p w = (0 : V) → ∀ i, w i = 0 := by
constructor
· exact fun h w hw hs i => h Finset.univ w hw hs i (Finset.mem_univ _)
· intro h s w hw hs i hi
rw [Finset.weightedVSub_indicator_subset _ _ (Finset.subset_univ s)] at hs
rw [← Finset.sum_indicator_subset _ (Finset.subset_univ s)] at hw
replace h := h ((↑s : Set ι).indicator w) hw hs i
simpa [hi] using h
#align affine_independent_iff_of_fintype affineIndependent_iff_of_fintype
/-- A family is affinely independent if and only if the differences
from a base point in that family are linearly independent. -/
theorem affineIndependent_iff_linearIndependent_vsub (p : ι → P) (i1 : ι) :
AffineIndependent k p ↔ LinearIndependent k fun i : { x // x ≠ i1 } => (p i -ᵥ p i1 : V) := by
classical
constructor
· intro h
rw [linearIndependent_iff']
intro s g hg i hi
set f : ι → k := fun x => if hx : x = i1 then -∑ y ∈ s, g y else g ⟨x, hx⟩ with hfdef
let s2 : Finset ι := insert i1 (s.map (Embedding.subtype _))
have hfg : ∀ x : { x // x ≠ i1 }, g x = f x := by
intro x
rw [hfdef]
dsimp only
erw [dif_neg x.property, Subtype.coe_eta]
rw [hfg]
have hf : ∑ ι ∈ s2, f ι = 0 := by
rw [Finset.sum_insert
(Finset.not_mem_map_subtype_of_not_property s (Classical.not_not.2 rfl)),
Finset.sum_subtype_map_embedding fun x _ => (hfg x).symm]
rw [hfdef]
dsimp only
rw [dif_pos rfl]
exact neg_add_self _
have hs2 : s2.weightedVSub p f = (0 : V) := by
set f2 : ι → V := fun x => f x • (p x -ᵥ p i1) with hf2def
set g2 : { x // x ≠ i1 } → V := fun x => g x • (p x -ᵥ p i1)
have hf2g2 : ∀ x : { x // x ≠ i1 }, f2 x = g2 x := by
simp only [g2, hf2def]
refine fun x => ?_
rw [hfg]
rw [Finset.weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero s2 f p hf (p i1),
Finset.weightedVSubOfPoint_insert, Finset.weightedVSubOfPoint_apply,
Finset.sum_subtype_map_embedding fun x _ => hf2g2 x]
exact hg
exact h s2 f hf hs2 i (Finset.mem_insert_of_mem (Finset.mem_map.2 ⟨i, hi, rfl⟩))
· intro h
rw [linearIndependent_iff'] at h
intro s w hw hs i hi
rw [Finset.weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero s w p hw (p i1), ←
s.weightedVSubOfPoint_erase w p i1, Finset.weightedVSubOfPoint_apply] at hs
let f : ι → V := fun i => w i • (p i -ᵥ p i1)
have hs2 : (∑ i ∈ (s.erase i1).subtype fun i => i ≠ i1, f i) = 0 := by
rw [← hs]
convert Finset.sum_subtype_of_mem f fun x => Finset.ne_of_mem_erase
have h2 := h ((s.erase i1).subtype fun i => i ≠ i1) (fun x => w x) hs2
simp_rw [Finset.mem_subtype] at h2
have h2b : ∀ i ∈ s, i ≠ i1 → w i = 0 := fun i his hi =>
h2 ⟨i, hi⟩ (Finset.mem_erase_of_ne_of_mem hi his)
exact Finset.eq_zero_of_sum_eq_zero hw h2b i hi
#align affine_independent_iff_linear_independent_vsub affineIndependent_iff_linearIndependent_vsub
/-- A set is affinely independent if and only if the differences from
a base point in that set are linearly independent. -/
theorem affineIndependent_set_iff_linearIndependent_vsub {s : Set P} {p₁ : P} (hp₁ : p₁ ∈ s) :
AffineIndependent k (fun p => p : s → P) ↔
LinearIndependent k (fun v => v : (fun p => (p -ᵥ p₁ : V)) '' (s \ {p₁}) → V) := by
rw [affineIndependent_iff_linearIndependent_vsub k (fun p => p : s → P) ⟨p₁, hp₁⟩]
constructor
· intro h
have hv : ∀ v : (fun p => (p -ᵥ p₁ : V)) '' (s \ {p₁}), (v : V) +ᵥ p₁ ∈ s \ {p₁} := fun v =>
(vsub_left_injective p₁).mem_set_image.1 ((vadd_vsub (v : V) p₁).symm ▸ v.property)
let f : (fun p : P => (p -ᵥ p₁ : V)) '' (s \ {p₁}) → { x : s // x ≠ ⟨p₁, hp₁⟩ } := fun x =>
⟨⟨(x : V) +ᵥ p₁, Set.mem_of_mem_diff (hv x)⟩, fun hx =>
Set.not_mem_of_mem_diff (hv x) (Subtype.ext_iff.1 hx)⟩
convert h.comp f fun x1 x2 hx =>
Subtype.ext (vadd_right_cancel p₁ (Subtype.ext_iff.1 (Subtype.ext_iff.1 hx)))
ext v
exact (vadd_vsub (v : V) p₁).symm
· intro h
let f : { x : s // x ≠ ⟨p₁, hp₁⟩ } → (fun p : P => (p -ᵥ p₁ : V)) '' (s \ {p₁}) := fun x =>
⟨((x : s) : P) -ᵥ p₁, ⟨x, ⟨⟨(x : s).property, fun hx => x.property (Subtype.ext hx)⟩, rfl⟩⟩⟩
convert h.comp f fun x1 x2 hx =>
Subtype.ext (Subtype.ext (vsub_left_cancel (Subtype.ext_iff.1 hx)))
#align affine_independent_set_iff_linear_independent_vsub affineIndependent_set_iff_linearIndependent_vsub
/-- A set of nonzero vectors is linearly independent if and only if,
given a point `p₁`, the vectors added to `p₁` and `p₁` itself are
affinely independent. -/
theorem linearIndependent_set_iff_affineIndependent_vadd_union_singleton {s : Set V}
(hs : ∀ v ∈ s, v ≠ (0 : V)) (p₁ : P) : LinearIndependent k (fun v => v : s → V) ↔
AffineIndependent k (fun p => p : ({p₁} ∪ (fun v => v +ᵥ p₁) '' s : Set P) → P) := by
rw [affineIndependent_set_iff_linearIndependent_vsub k
(Set.mem_union_left _ (Set.mem_singleton p₁))]
have h : (fun p => (p -ᵥ p₁ : V)) '' (({p₁} ∪ (fun v => v +ᵥ p₁) '' s) \ {p₁}) = s := by
simp_rw [Set.union_diff_left, Set.image_diff (vsub_left_injective p₁), Set.image_image,
Set.image_singleton, vsub_self, vadd_vsub, Set.image_id']
exact Set.diff_singleton_eq_self fun h => hs 0 h rfl
rw [h]
#align linear_independent_set_iff_affine_independent_vadd_union_singleton linearIndependent_set_iff_affineIndependent_vadd_union_singleton
/-- A family is affinely independent if and only if any affine
combinations (with sum of weights 1) that evaluate to the same point
have equal `Set.indicator`. -/
theorem affineIndependent_iff_indicator_eq_of_affineCombination_eq (p : ι → P) :
AffineIndependent k p ↔
∀ (s1 s2 : Finset ι) (w1 w2 : ι → k),
∑ i ∈ s1, w1 i = 1 →
∑ i ∈ s2, w2 i = 1 →
s1.affineCombination k p w1 = s2.affineCombination k p w2 →
Set.indicator (↑s1) w1 = Set.indicator (↑s2) w2 := by
classical
constructor
· intro ha s1 s2 w1 w2 hw1 hw2 heq
ext i
by_cases hi : i ∈ s1 ∪ s2
· rw [← sub_eq_zero]
rw [← Finset.sum_indicator_subset w1 (s1.subset_union_left (s₂:=s2))] at hw1
rw [← Finset.sum_indicator_subset w2 (s1.subset_union_right)] at hw2
have hws : (∑ i ∈ s1 ∪ s2, (Set.indicator (↑s1) w1 - Set.indicator (↑s2) w2) i) = 0 := by
simp [hw1, hw2]
rw [Finset.affineCombination_indicator_subset w1 p (s1.subset_union_left (s₂:=s2)),
Finset.affineCombination_indicator_subset w2 p s1.subset_union_right,
← @vsub_eq_zero_iff_eq V, Finset.affineCombination_vsub] at heq
exact ha (s1 ∪ s2) (Set.indicator (↑s1) w1 - Set.indicator (↑s2) w2) hws heq i hi
· rw [← Finset.mem_coe, Finset.coe_union] at hi
have h₁ : Set.indicator (↑s1) w1 i = 0 := by
simp only [Set.indicator, Finset.mem_coe, ite_eq_right_iff]
intro h
by_contra
exact (mt (@Set.mem_union_left _ i ↑s1 ↑s2) hi) h
have h₂ : Set.indicator (↑s2) w2 i = 0 := by
simp only [Set.indicator, Finset.mem_coe, ite_eq_right_iff]
intro h
by_contra
exact (mt (@Set.mem_union_right _ i ↑s2 ↑s1) hi) h
simp [h₁, h₂]
· intro ha s w hw hs i0 hi0
let w1 : ι → k := Function.update (Function.const ι 0) i0 1
have hw1 : ∑ i ∈ s, w1 i = 1 := by
rw [Finset.sum_update_of_mem hi0]
simp only [Finset.sum_const_zero, add_zero, const_apply]
have hw1s : s.affineCombination k p w1 = p i0 :=
s.affineCombination_of_eq_one_of_eq_zero w1 p hi0 (Function.update_same _ _ _)
fun _ _ hne => Function.update_noteq hne _ _
let w2 := w + w1
have hw2 : ∑ i ∈ s, w2 i = 1 := by
simp_all only [w2, Pi.add_apply, Finset.sum_add_distrib, zero_add]
have hw2s : s.affineCombination k p w2 = p i0 := by
simp_all only [w2, ← Finset.weightedVSub_vadd_affineCombination, zero_vadd]
replace ha := ha s s w2 w1 hw2 hw1 (hw1s.symm ▸ hw2s)
have hws : w2 i0 - w1 i0 = 0 := by
rw [← Finset.mem_coe] at hi0
rw [← Set.indicator_of_mem hi0 w2, ← Set.indicator_of_mem hi0 w1, ha, sub_self]
simpa [w2] using hws
#align affine_independent_iff_indicator_eq_of_affine_combination_eq affineIndependent_iff_indicator_eq_of_affineCombination_eq
/-- A finite family is affinely independent if and only if any affine
combinations (with sum of weights 1) that evaluate to the same point are equal. -/
theorem affineIndependent_iff_eq_of_fintype_affineCombination_eq [Fintype ι] (p : ι → P) :
AffineIndependent k p ↔ ∀ w1 w2 : ι → k, ∑ i, w1 i = 1 → ∑ i, w2 i = 1 →
Finset.univ.affineCombination k p w1 = Finset.univ.affineCombination k p w2 → w1 = w2 := by
rw [affineIndependent_iff_indicator_eq_of_affineCombination_eq]
constructor
· intro h w1 w2 hw1 hw2 hweq
simpa only [Set.indicator_univ, Finset.coe_univ] using h _ _ w1 w2 hw1 hw2 hweq
· intro h s1 s2 w1 w2 hw1 hw2 hweq
have hw1' : (∑ i, (s1 : Set ι).indicator w1 i) = 1 := by
rwa [Finset.sum_indicator_subset _ (Finset.subset_univ s1)]
have hw2' : (∑ i, (s2 : Set ι).indicator w2 i) = 1 := by
rwa [Finset.sum_indicator_subset _ (Finset.subset_univ s2)]
rw [Finset.affineCombination_indicator_subset w1 p (Finset.subset_univ s1),
Finset.affineCombination_indicator_subset w2 p (Finset.subset_univ s2)] at hweq
exact h _ _ hw1' hw2' hweq
#align affine_independent_iff_eq_of_fintype_affine_combination_eq affineIndependent_iff_eq_of_fintype_affineCombination_eq
variable {k}
/-- If we single out one member of an affine-independent family of points and affinely transport
all others along the line joining them to this member, the resulting new family of points is affine-
independent.
This is the affine version of `LinearIndependent.units_smul`. -/
theorem AffineIndependent.units_lineMap {p : ι → P} (hp : AffineIndependent k p) (j : ι)
(w : ι → Units k) : AffineIndependent k fun i => AffineMap.lineMap (p j) (p i) (w i : k) := by
rw [affineIndependent_iff_linearIndependent_vsub k _ j] at hp ⊢
simp only [AffineMap.lineMap_vsub_left, AffineMap.coe_const, AffineMap.lineMap_same, const_apply]
exact hp.units_smul fun i => w i
#align affine_independent.units_line_map AffineIndependent.units_lineMap
theorem AffineIndependent.indicator_eq_of_affineCombination_eq {p : ι → P}
(ha : AffineIndependent k p) (s₁ s₂ : Finset ι) (w₁ w₂ : ι → k) (hw₁ : ∑ i ∈ s₁, w₁ i = 1)
(hw₂ : ∑ i ∈ s₂, w₂ i = 1) (h : s₁.affineCombination k p w₁ = s₂.affineCombination k p w₂) :
Set.indicator (↑s₁) w₁ = Set.indicator (↑s₂) w₂ :=
(affineIndependent_iff_indicator_eq_of_affineCombination_eq k p).1 ha s₁ s₂ w₁ w₂ hw₁ hw₂ h
#align affine_independent.indicator_eq_of_affine_combination_eq AffineIndependent.indicator_eq_of_affineCombination_eq
/-- An affinely independent family is injective, if the underlying
ring is nontrivial. -/
protected theorem AffineIndependent.injective [Nontrivial k] {p : ι → P}
(ha : AffineIndependent k p) : Function.Injective p := by
intro i j hij
rw [affineIndependent_iff_linearIndependent_vsub _ _ j] at ha
by_contra hij'
refine ha.ne_zero ⟨i, hij'⟩ (vsub_eq_zero_iff_eq.mpr ?_)
simp_all only [ne_eq]
#align affine_independent.injective AffineIndependent.injective
/-- If a family is affinely independent, so is any subfamily given by
composition of an embedding into index type with the original
family. -/
theorem AffineIndependent.comp_embedding {ι2 : Type*} (f : ι2 ↪ ι) {p : ι → P}
(ha : AffineIndependent k p) : AffineIndependent k (p ∘ f) := by
classical
intro fs w hw hs i0 hi0
let fs' := fs.map f
let w' i := if h : ∃ i2, f i2 = i then w h.choose else 0
have hw' : ∀ i2 : ι2, w' (f i2) = w i2 := by
intro i2
have h : ∃ i : ι2, f i = f i2 := ⟨i2, rfl⟩
have hs : h.choose = i2 := f.injective h.choose_spec
simp_rw [w', dif_pos h, hs]
have hw's : ∑ i ∈ fs', w' i = 0 := by
rw [← hw, Finset.sum_map]
simp [hw']
have hs' : fs'.weightedVSub p w' = (0 : V) := by
rw [← hs, Finset.weightedVSub_map]
congr with i
simp_all only [comp_apply, EmbeddingLike.apply_eq_iff_eq, exists_eq, dite_true]
rw [← ha fs' w' hw's hs' (f i0) ((Finset.mem_map' _).2 hi0), hw']
#align affine_independent.comp_embedding AffineIndependent.comp_embedding
/-- If a family is affinely independent, so is any subfamily indexed
by a subtype of the index type. -/
protected theorem AffineIndependent.subtype {p : ι → P} (ha : AffineIndependent k p) (s : Set ι) :
AffineIndependent k fun i : s => p i :=
ha.comp_embedding (Embedding.subtype _)
#align affine_independent.subtype AffineIndependent.subtype
/-- If an indexed family of points is affinely independent, so is the
corresponding set of points. -/
protected theorem AffineIndependent.range {p : ι → P} (ha : AffineIndependent k p) :
AffineIndependent k (fun x => x : Set.range p → P) := by
let f : Set.range p → ι := fun x => x.property.choose
have hf : ∀ x, p (f x) = x := fun x => x.property.choose_spec
let fe : Set.range p ↪ ι := ⟨f, fun x₁ x₂ he => Subtype.ext (hf x₁ ▸ hf x₂ ▸ he ▸ rfl)⟩
convert ha.comp_embedding fe
ext
simp [fe, hf]
#align affine_independent.range AffineIndependent.range
theorem affineIndependent_equiv {ι' : Type*} (e : ι ≃ ι') {p : ι' → P} :
AffineIndependent k (p ∘ e) ↔ AffineIndependent k p := by
refine ⟨?_, AffineIndependent.comp_embedding e.toEmbedding⟩
intro h
have : p = p ∘ e ∘ e.symm.toEmbedding := by
ext
simp
rw [this]
exact h.comp_embedding e.symm.toEmbedding
#align affine_independent_equiv affineIndependent_equiv
/-- If a set of points is affinely independent, so is any subset. -/
protected theorem AffineIndependent.mono {s t : Set P}
(ha : AffineIndependent k (fun x => x : t → P)) (hs : s ⊆ t) :
AffineIndependent k (fun x => x : s → P) :=
ha.comp_embedding (s.embeddingOfSubset t hs)
#align affine_independent.mono AffineIndependent.mono
/-- If the range of an injective indexed family of points is affinely
independent, so is that family. -/
theorem AffineIndependent.of_set_of_injective {p : ι → P}
(ha : AffineIndependent k (fun x => x : Set.range p → P)) (hi : Function.Injective p) :
AffineIndependent k p :=
ha.comp_embedding
(⟨fun i => ⟨p i, Set.mem_range_self _⟩, fun _ _ h => hi (Subtype.mk_eq_mk.1 h)⟩ :
ι ↪ Set.range p)
#align affine_independent.of_set_of_injective AffineIndependent.of_set_of_injective
section Composition
variable {V₂ P₂ : Type*} [AddCommGroup V₂] [Module k V₂] [AffineSpace V₂ P₂]
/-- If the image of a family of points in affine space under an affine transformation is affine-
independent, then the original family of points is also affine-independent. -/
theorem AffineIndependent.of_comp {p : ι → P} (f : P →ᵃ[k] P₂) (hai : AffineIndependent k (f ∘ p)) :
AffineIndependent k p := by
cases' isEmpty_or_nonempty ι with h h;
· haveI := h
apply affineIndependent_of_subsingleton
obtain ⟨i⟩ := h
rw [affineIndependent_iff_linearIndependent_vsub k p i]
simp_rw [affineIndependent_iff_linearIndependent_vsub k (f ∘ p) i, Function.comp_apply, ←
f.linearMap_vsub] at hai
exact LinearIndependent.of_comp f.linear hai
#align affine_independent.of_comp AffineIndependent.of_comp
/-- The image of a family of points in affine space, under an injective affine transformation, is
affine-independent. -/
theorem AffineIndependent.map' {p : ι → P} (hai : AffineIndependent k p) (f : P →ᵃ[k] P₂)
(hf : Function.Injective f) : AffineIndependent k (f ∘ p) := by
cases' isEmpty_or_nonempty ι with h h
· haveI := h
apply affineIndependent_of_subsingleton
obtain ⟨i⟩ := h
rw [affineIndependent_iff_linearIndependent_vsub k p i] at hai
simp_rw [affineIndependent_iff_linearIndependent_vsub k (f ∘ p) i, Function.comp_apply, ←
f.linearMap_vsub]
have hf' : LinearMap.ker f.linear = ⊥ := by rwa [LinearMap.ker_eq_bot, f.linear_injective_iff]
exact LinearIndependent.map' hai f.linear hf'
#align affine_independent.map' AffineIndependent.map'
/-- Injective affine maps preserve affine independence. -/
theorem AffineMap.affineIndependent_iff {p : ι → P} (f : P →ᵃ[k] P₂) (hf : Function.Injective f) :
AffineIndependent k (f ∘ p) ↔ AffineIndependent k p :=
⟨AffineIndependent.of_comp f, fun hai => AffineIndependent.map' hai f hf⟩
#align affine_map.affine_independent_iff AffineMap.affineIndependent_iff
/-- Affine equivalences preserve affine independence of families of points. -/
theorem AffineEquiv.affineIndependent_iff {p : ι → P} (e : P ≃ᵃ[k] P₂) :
AffineIndependent k (e ∘ p) ↔ AffineIndependent k p :=
e.toAffineMap.affineIndependent_iff e.toEquiv.injective
#align affine_equiv.affine_independent_iff AffineEquiv.affineIndependent_iff
/-- Affine equivalences preserve affine independence of subsets. -/
theorem AffineEquiv.affineIndependent_set_of_eq_iff {s : Set P} (e : P ≃ᵃ[k] P₂) :
AffineIndependent k ((↑) : e '' s → P₂) ↔ AffineIndependent k ((↑) : s → P) := by
have : e ∘ ((↑) : s → P) = ((↑) : e '' s → P₂) ∘ (e : P ≃ P₂).image s := rfl
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [← e.affineIndependent_iff, this, affineIndependent_equiv]
#align affine_equiv.affine_independent_set_of_eq_iff AffineEquiv.affineIndependent_set_of_eq_iff
end Composition
/-- If a family is affinely independent, and the spans of points
indexed by two subsets of the index type have a point in common, those
subsets of the index type have an element in common, if the underlying
ring is nontrivial. -/
theorem AffineIndependent.exists_mem_inter_of_exists_mem_inter_affineSpan [Nontrivial k] {p : ι → P}
(ha : AffineIndependent k p) {s1 s2 : Set ι} {p0 : P} (hp0s1 : p0 ∈ affineSpan k (p '' s1))
(hp0s2 : p0 ∈ affineSpan k (p '' s2)) : ∃ i : ι, i ∈ s1 ∩ s2 := by
rw [Set.image_eq_range] at hp0s1 hp0s2
rw [mem_affineSpan_iff_eq_affineCombination, ←
Finset.eq_affineCombination_subset_iff_eq_affineCombination_subtype] at hp0s1 hp0s2
rcases hp0s1 with ⟨fs1, hfs1, w1, hw1, hp0s1⟩
rcases hp0s2 with ⟨fs2, hfs2, w2, hw2, hp0s2⟩
rw [affineIndependent_iff_indicator_eq_of_affineCombination_eq] at ha
replace ha := ha fs1 fs2 w1 w2 hw1 hw2 (hp0s1 ▸ hp0s2)
have hnz : ∑ i ∈ fs1, w1 i ≠ 0 := hw1.symm ▸ one_ne_zero
rcases Finset.exists_ne_zero_of_sum_ne_zero hnz with ⟨i, hifs1, hinz⟩
simp_rw [← Set.indicator_of_mem (Finset.mem_coe.2 hifs1) w1, ha] at hinz
use i, hfs1 hifs1
exact hfs2 (Set.mem_of_indicator_ne_zero hinz)
#align affine_independent.exists_mem_inter_of_exists_mem_inter_affine_span AffineIndependent.exists_mem_inter_of_exists_mem_inter_affineSpan
/-- If a family is affinely independent, the spans of points indexed
by disjoint subsets of the index type are disjoint, if the underlying
ring is nontrivial. -/
theorem AffineIndependent.affineSpan_disjoint_of_disjoint [Nontrivial k] {p : ι → P}
(ha : AffineIndependent k p) {s1 s2 : Set ι} (hd : Disjoint s1 s2) :
Disjoint (affineSpan k (p '' s1) : Set P) (affineSpan k (p '' s2)) := by
refine Set.disjoint_left.2 fun p0 hp0s1 hp0s2 => ?_
cases' ha.exists_mem_inter_of_exists_mem_inter_affineSpan hp0s1 hp0s2 with i hi
exact Set.disjoint_iff.1 hd hi
#align affine_independent.affine_span_disjoint_of_disjoint AffineIndependent.affineSpan_disjoint_of_disjoint
/-- If a family is affinely independent, a point in the family is in
the span of some of the points given by a subset of the index type if
and only if that point's index is in the subset, if the underlying
ring is nontrivial. -/
@[simp]
protected theorem AffineIndependent.mem_affineSpan_iff [Nontrivial k] {p : ι → P}
(ha : AffineIndependent k p) (i : ι) (s : Set ι) : p i ∈ affineSpan k (p '' s) ↔ i ∈ s := by
constructor
· intro hs
have h :=
AffineIndependent.exists_mem_inter_of_exists_mem_inter_affineSpan ha hs
(mem_affineSpan k (Set.mem_image_of_mem _ (Set.mem_singleton _)))
rwa [← Set.nonempty_def, Set.inter_singleton_nonempty] at h
· exact fun h => mem_affineSpan k (Set.mem_image_of_mem p h)
#align affine_independent.mem_affine_span_iff AffineIndependent.mem_affineSpan_iff
/-- If a family is affinely independent, a point in the family is not
in the affine span of the other points, if the underlying ring is
nontrivial. -/
theorem AffineIndependent.not_mem_affineSpan_diff [Nontrivial k] {p : ι → P}
(ha : AffineIndependent k p) (i : ι) (s : Set ι) : p i ∉ affineSpan k (p '' (s \ {i})) := by
simp [ha]
#align affine_independent.not_mem_affine_span_diff AffineIndependent.not_mem_affineSpan_diff
theorem exists_nontrivial_relation_sum_zero_of_not_affine_ind {t : Finset V}
(h : ¬AffineIndependent k ((↑) : t → V)) :
∃ f : V → k, ∑ e ∈ t, f e • e = 0 ∧ ∑ e ∈ t, f e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by
classical
rw [affineIndependent_iff_of_fintype] at h
simp only [exists_prop, not_forall] at h
obtain ⟨w, hw, hwt, i, hi⟩ := h
simp only [Finset.weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero _ w ((↑) : t → V) hw 0,
vsub_eq_sub, Finset.weightedVSubOfPoint_apply, sub_zero] at hwt
let f : ∀ x : V, x ∈ t → k := fun x hx => w ⟨x, hx⟩
refine ⟨fun x => if hx : x ∈ t then f x hx else (0 : k), ?_, ?_, by use i; simp [hi]⟩
on_goal 1 =>
suffices (∑ e ∈ t, dite (e ∈ t) (fun hx => f e hx • e) fun _ => 0) = 0 by
convert this
rename V => x
by_cases hx : x ∈ t <;> simp [hx]
all_goals
simp only [Finset.sum_dite_of_true fun _ h => h, Finset.mk_coe, hwt, hw]
#align exists_nontrivial_relation_sum_zero_of_not_affine_ind exists_nontrivial_relation_sum_zero_of_not_affine_ind
variable {s : Finset ι} {w w₁ w₂ : ι → k} {p : ι → V}
/-- Viewing a module as an affine space modelled on itself, we can characterise affine independence
in terms of linear combinations. -/
theorem affineIndependent_iff {ι} {p : ι → V} :
AffineIndependent k p ↔
∀ (s : Finset ι) (w : ι → k), s.sum w = 0 → ∑ e ∈ s, w e • p e = 0 → ∀ e ∈ s, w e = 0 :=
forall₃_congr fun s w hw => by simp [s.weightedVSub_eq_linear_combination hw]
#align affine_independent_iff affineIndependent_iff
lemma AffineIndependent.eq_zero_of_sum_eq_zero (hp : AffineIndependent k p)
(hw₀ : ∑ i ∈ s, w i = 0) (hw₁ : ∑ i ∈ s, w i • p i = 0) : ∀ i ∈ s, w i = 0 :=
affineIndependent_iff.1 hp _ _ hw₀ hw₁
lemma AffineIndependent.eq_of_sum_eq_sum (hp : AffineIndependent k p)
(hw : ∑ i ∈ s, w₁ i = ∑ i ∈ s, w₂ i) (hwp : ∑ i ∈ s, w₁ i • p i = ∑ i ∈ s, w₂ i • p i) :
∀ i ∈ s, w₁ i = w₂ i := by
refine fun i hi ↦ sub_eq_zero.1 (hp.eq_zero_of_sum_eq_zero (w := w₁ - w₂) ?_ ?_ _ hi) <;>
simpa [sub_mul, sub_smul, sub_eq_zero]
lemma AffineIndependent.eq_zero_of_sum_eq_zero_subtype {s : Finset V}
(hp : AffineIndependent k ((↑) : s → V)) {w : V → k} (hw₀ : ∑ x ∈ s, w x = 0)
(hw₁ : ∑ x ∈ s, w x • x = 0) : ∀ x ∈ s, w x = 0 := by
rw [← sum_attach] at hw₀ hw₁
exact fun x hx ↦ hp.eq_zero_of_sum_eq_zero hw₀ hw₁ ⟨x, hx⟩ (mem_univ _)
lemma AffineIndependent.eq_of_sum_eq_sum_subtype {s : Finset V}
(hp : AffineIndependent k ((↑) : s → V)) {w₁ w₂ : V → k} (hw : ∑ i ∈ s, w₁ i = ∑ i ∈ s, w₂ i)
(hwp : ∑ i ∈ s, w₁ i • i = ∑ i ∈ s, w₂ i • i) : ∀ i ∈ s, w₁ i = w₂ i := by
refine fun i hi => sub_eq_zero.1 (hp.eq_zero_of_sum_eq_zero_subtype (w := w₁ - w₂) ?_ ?_ _ hi) <;>
simpa [sub_mul, sub_smul, sub_eq_zero]
/-- Given an affinely independent family of points, a weighted subtraction lies in the
`vectorSpan` of two points given as affine combinations if and only if it is a weighted
subtraction with weights a multiple of the difference between the weights of the two points. -/
theorem weightedVSub_mem_vectorSpan_pair {p : ι → P} (h : AffineIndependent k p) {w w₁ w₂ : ι → k}
{s : Finset ι} (hw : ∑ i ∈ s, w i = 0) (hw₁ : ∑ i ∈ s, w₁ i = 1)
(hw₂ : ∑ i ∈ s, w₂ i = 1) :
s.weightedVSub p w ∈
vectorSpan k ({s.affineCombination k p w₁, s.affineCombination k p w₂} : Set P) ↔
∃ r : k, ∀ i ∈ s, w i = r * (w₁ i - w₂ i) := by
rw [mem_vectorSpan_pair]
refine ⟨fun h => ?_, fun h => ?_⟩
· rcases h with ⟨r, hr⟩
refine ⟨r, fun i hi => ?_⟩
rw [s.affineCombination_vsub, ← s.weightedVSub_const_smul, ← sub_eq_zero, ← map_sub] at hr
have hw' : (∑ j ∈ s, (r • (w₁ - w₂) - w) j) = 0 := by
simp_rw [Pi.sub_apply, Pi.smul_apply, Pi.sub_apply, smul_sub, Finset.sum_sub_distrib, ←
Finset.smul_sum, hw, hw₁, hw₂, sub_self]
have hr' := h s _ hw' hr i hi
rw [eq_comm, ← sub_eq_zero, ← smul_eq_mul]
exact hr'
· rcases h with ⟨r, hr⟩
refine ⟨r, ?_⟩
let w' i := r * (w₁ i - w₂ i)
change ∀ i ∈ s, w i = w' i at hr
rw [s.weightedVSub_congr hr fun _ _ => rfl, s.affineCombination_vsub, ←
s.weightedVSub_const_smul]
congr
#align weighted_vsub_mem_vector_span_pair weightedVSub_mem_vectorSpan_pair
/-- Given an affinely independent family of points, an affine combination lies in the
span of two points given as affine combinations if and only if it is an affine combination
with weights those of one point plus a multiple of the difference between the weights of the
two points. -/
theorem affineCombination_mem_affineSpan_pair {p : ι → P} (h : AffineIndependent k p)
{w w₁ w₂ : ι → k} {s : Finset ι} (_ : ∑ i ∈ s, w i = 1) (hw₁ : ∑ i ∈ s, w₁ i = 1)
(hw₂ : ∑ i ∈ s, w₂ i = 1) :
s.affineCombination k p w ∈ line[k, s.affineCombination k p w₁, s.affineCombination k p w₂] ↔
∃ r : k, ∀ i ∈ s, w i = r * (w₂ i - w₁ i) + w₁ i := by
rw [← vsub_vadd (s.affineCombination k p w) (s.affineCombination k p w₁),
AffineSubspace.vadd_mem_iff_mem_direction _ (left_mem_affineSpan_pair _ _ _),
direction_affineSpan, s.affineCombination_vsub, Set.pair_comm,
weightedVSub_mem_vectorSpan_pair h _ hw₂ hw₁]
· simp only [Pi.sub_apply, sub_eq_iff_eq_add]
· simp_all only [Pi.sub_apply, Finset.sum_sub_distrib, sub_self]
#align affine_combination_mem_affine_span_pair affineCombination_mem_affineSpan_pair
end AffineIndependent
section DivisionRing
variable {k : Type*} {V : Type*} {P : Type*} [DivisionRing k] [AddCommGroup V] [Module k V]
variable [AffineSpace V P] {ι : Type*}
/-- An affinely independent set of points can be extended to such a
set that spans the whole space. -/
theorem exists_subset_affineIndependent_affineSpan_eq_top {s : Set P}
(h : AffineIndependent k (fun p => p : s → P)) :
∃ t : Set P, s ⊆ t ∧ AffineIndependent k (fun p => p : t → P) ∧ affineSpan k t = ⊤ := by
rcases s.eq_empty_or_nonempty with (rfl | ⟨p₁, hp₁⟩)
· have p₁ : P := AddTorsor.nonempty.some
let hsv := Basis.ofVectorSpace k V
have hsvi := hsv.linearIndependent
have hsvt := hsv.span_eq
rw [Basis.coe_ofVectorSpace] at hsvi hsvt
have h0 : ∀ v : V, v ∈ Basis.ofVectorSpaceIndex k V → v ≠ 0 := by
intro v hv
simpa [hsv] using hsv.ne_zero ⟨v, hv⟩
rw [linearIndependent_set_iff_affineIndependent_vadd_union_singleton k h0 p₁] at hsvi
exact
⟨{p₁} ∪ (fun v => v +ᵥ p₁) '' _, Set.empty_subset _, hsvi,
affineSpan_singleton_union_vadd_eq_top_of_span_eq_top p₁ hsvt⟩
· rw [affineIndependent_set_iff_linearIndependent_vsub k hp₁] at h
let bsv := Basis.extend h
have hsvi := bsv.linearIndependent
have hsvt := bsv.span_eq
rw [Basis.coe_extend] at hsvi hsvt
have hsv := h.subset_extend (Set.subset_univ _)
have h0 : ∀ v : V, v ∈ h.extend (Set.subset_univ _) → v ≠ 0 := by
intro v hv
simpa [bsv] using bsv.ne_zero ⟨v, hv⟩
rw [linearIndependent_set_iff_affineIndependent_vadd_union_singleton k h0 p₁] at hsvi
refine ⟨{p₁} ∪ (fun v => v +ᵥ p₁) '' h.extend (Set.subset_univ _), ?_, ?_⟩
· refine Set.Subset.trans ?_ (Set.union_subset_union_right _ (Set.image_subset _ hsv))
simp [Set.image_image]
· use hsvi
exact affineSpan_singleton_union_vadd_eq_top_of_span_eq_top p₁ hsvt
#align exists_subset_affine_independent_affine_span_eq_top exists_subset_affineIndependent_affineSpan_eq_top
variable (k V)
theorem exists_affineIndependent (s : Set P) :
∃ t ⊆ s, affineSpan k t = affineSpan k s ∧ AffineIndependent k ((↑) : t → P) := by
rcases s.eq_empty_or_nonempty with (rfl | ⟨p, hp⟩)
· exact ⟨∅, Set.empty_subset ∅, rfl, affineIndependent_of_subsingleton k _⟩
obtain ⟨b, hb₁, hb₂, hb₃⟩ := exists_linearIndependent k ((Equiv.vaddConst p).symm '' s)
have hb₀ : ∀ v : V, v ∈ b → v ≠ 0 := fun v hv => hb₃.ne_zero (⟨v, hv⟩ : b)
rw [linearIndependent_set_iff_affineIndependent_vadd_union_singleton k hb₀ p] at hb₃
refine ⟨{p} ∪ Equiv.vaddConst p '' b, ?_, ?_, hb₃⟩
· apply Set.union_subset (Set.singleton_subset_iff.mpr hp)
rwa [← (Equiv.vaddConst p).subset_symm_image b s]
· rw [Equiv.coe_vaddConst_symm, ← vectorSpan_eq_span_vsub_set_right k hp] at hb₂
apply AffineSubspace.ext_of_direction_eq
· have : Submodule.span k b = Submodule.span k (insert 0 b) := by simp
simp only [direction_affineSpan, ← hb₂, Equiv.coe_vaddConst, Set.singleton_union,
vectorSpan_eq_span_vsub_set_right k (Set.mem_insert p _), this]
congr
change (Equiv.vaddConst p).symm '' insert p (Equiv.vaddConst p '' b) = _
rw [Set.image_insert_eq, ← Set.image_comp]
simp
· use p
simp only [Equiv.coe_vaddConst, Set.singleton_union, Set.mem_inter_iff, coe_affineSpan]
exact ⟨mem_spanPoints k _ _ (Set.mem_insert p _), mem_spanPoints k _ _ hp⟩
#align exists_affine_independent exists_affineIndependent
variable {V}
/-- Two different points are affinely independent. -/
theorem affineIndependent_of_ne {p₁ p₂ : P} (h : p₁ ≠ p₂) : AffineIndependent k ![p₁, p₂] := by
rw [affineIndependent_iff_linearIndependent_vsub k ![p₁, p₂] 0]
let i₁ : { x // x ≠ (0 : Fin 2) } := ⟨1, by norm_num⟩
have he' : ∀ i, i = i₁ := by
rintro ⟨i, hi⟩
ext
fin_cases i
· simp at hi
· simp only [Fin.val_one]
haveI : Unique { x // x ≠ (0 : Fin 2) } := ⟨⟨i₁⟩, he'⟩
apply linearIndependent_unique
rw [he' default]
simpa using h.symm
#align affine_independent_of_ne affineIndependent_of_ne
variable {k}
/-- If all but one point of a family are affinely independent, and that point does not lie in
the affine span of that family, the family is affinely independent. -/
theorem AffineIndependent.affineIndependent_of_not_mem_span {p : ι → P} {i : ι}
(ha : AffineIndependent k fun x : { y // y ≠ i } => p x)
(hi : p i ∉ affineSpan k (p '' { x | x ≠ i })) : AffineIndependent k p := by
classical
intro s w hw hs
let s' : Finset { y // y ≠ i } := s.subtype (· ≠ i)
let p' : { y // y ≠ i } → P := fun x => p x
by_cases his : i ∈ s ∧ w i ≠ 0
· refine False.elim (hi ?_)
let wm : ι → k := -(w i)⁻¹ • w
have hms : s.weightedVSub p wm = (0 : V) := by simp [wm, hs]
have hwm : ∑ i ∈ s, wm i = 0 := by simp [wm, ← Finset.mul_sum, hw]
have hwmi : wm i = -1 := by simp [wm, his.2]
let w' : { y // y ≠ i } → k := fun x => wm x
have hw' : ∑ x ∈ s', w' x = 1 := by
simp_rw [w', s', Finset.sum_subtype_eq_sum_filter]
rw [← s.sum_filter_add_sum_filter_not (· ≠ i)] at hwm
simp_rw [Classical.not_not] at hwm
-- Porting note: this `erw` used to be part of the `simp_rw`
erw [Finset.filter_eq'] at hwm
simp_rw [if_pos his.1, Finset.sum_singleton, hwmi, ← sub_eq_add_neg, sub_eq_zero] at hwm
exact hwm
rw [← s.affineCombination_eq_of_weightedVSub_eq_zero_of_eq_neg_one hms his.1 hwmi, ←
(Subtype.range_coe : _ = { x | x ≠ i }), ← Set.range_comp, ←
s.affineCombination_subtype_eq_filter]
exact affineCombination_mem_affineSpan hw' p'
· rw [not_and_or, Classical.not_not] at his
let w' : { y // y ≠ i } → k := fun x => w x
have hw' : ∑ x ∈ s', w' x = 0 := by
simp_rw [w', s', Finset.sum_subtype_eq_sum_filter]
rw [Finset.sum_filter_of_ne, hw]
rintro x hxs hwx rfl
exact hwx (his.neg_resolve_left hxs)
have hs' : s'.weightedVSub p' w' = (0 : V) := by
simp_rw [w', s', p', Finset.weightedVSub_subtype_eq_filter]
rw [Finset.weightedVSub_filter_of_ne, hs]
rintro x hxs hwx rfl
exact hwx (his.neg_resolve_left hxs)
intro j hj
by_cases hji : j = i
· rw [hji] at hj
exact hji.symm ▸ his.neg_resolve_left hj
· exact ha s' w' hw' hs' ⟨j, hji⟩ (Finset.mem_subtype.2 hj)
#align affine_independent.affine_independent_of_not_mem_span AffineIndependent.affineIndependent_of_not_mem_span
/-- If distinct points `p₁` and `p₂` lie in `s` but `p₃` does not, the three points are affinely
independent. -/
theorem affineIndependent_of_ne_of_mem_of_mem_of_not_mem {s : AffineSubspace k P} {p₁ p₂ p₃ : P}
(hp₁p₂ : p₁ ≠ p₂) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (hp₃ : p₃ ∉ s) :
AffineIndependent k ![p₁, p₂, p₃] := by
have ha : AffineIndependent k fun x : { x : Fin 3 // x ≠ 2 } => ![p₁, p₂, p₃] x := by
rw [← affineIndependent_equiv (finSuccAboveEquiv (2 : Fin 3)).toEquiv]
convert affineIndependent_of_ne k hp₁p₂
ext x
fin_cases x <;> rfl
refine ha.affineIndependent_of_not_mem_span ?_
intro h
refine hp₃ ((AffineSubspace.le_def' _ s).1 ?_ p₃ h)
simp_rw [affineSpan_le, Set.image_subset_iff, Set.subset_def, Set.mem_preimage]
intro x
fin_cases x <;> simp (config := {decide := true}) [hp₁, hp₂]
#align affine_independent_of_ne_of_mem_of_mem_of_not_mem affineIndependent_of_ne_of_mem_of_mem_of_not_mem
/-- If distinct points `p₁` and `p₃` lie in `s` but `p₂` does not, the three points are affinely
independent. -/
theorem affineIndependent_of_ne_of_mem_of_not_mem_of_mem {s : AffineSubspace k P} {p₁ p₂ p₃ : P}
(hp₁p₃ : p₁ ≠ p₃) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∉ s) (hp₃ : p₃ ∈ s) :
AffineIndependent k ![p₁, p₂, p₃] := by
rw [← affineIndependent_equiv (Equiv.swap (1 : Fin 3) 2)]
convert affineIndependent_of_ne_of_mem_of_mem_of_not_mem hp₁p₃ hp₁ hp₃ hp₂ using 1
ext x
fin_cases x <;> rfl
#align affine_independent_of_ne_of_mem_of_not_mem_of_mem affineIndependent_of_ne_of_mem_of_not_mem_of_mem
/-- If distinct points `p₂` and `p₃` lie in `s` but `p₁` does not, the three points are affinely
independent. -/
theorem affineIndependent_of_ne_of_not_mem_of_mem_of_mem {s : AffineSubspace k P} {p₁ p₂ p₃ : P}
(hp₂p₃ : p₂ ≠ p₃) (hp₁ : p₁ ∉ s) (hp₂ : p₂ ∈ s) (hp₃ : p₃ ∈ s) :
AffineIndependent k ![p₁, p₂, p₃] := by
rw [← affineIndependent_equiv (Equiv.swap (0 : Fin 3) 2)]
convert affineIndependent_of_ne_of_mem_of_mem_of_not_mem hp₂p₃.symm hp₃ hp₂ hp₁ using 1
ext x
fin_cases x <;> rfl
#align affine_independent_of_ne_of_not_mem_of_mem_of_mem affineIndependent_of_ne_of_not_mem_of_mem_of_mem
end DivisionRing
section Ordered
variable {k : Type*} {V : Type*} {P : Type*} [LinearOrderedRing k] [AddCommGroup V]
variable [Module k V] [AffineSpace V P] {ι : Type*}
attribute [local instance] LinearOrderedRing.decidableLT
/-- Given an affinely independent family of points, suppose that an affine combination lies in
the span of two points given as affine combinations, and suppose that, for two indices, the
coefficients in the first point in the span are zero and those in the second point in the span
have the same sign. Then the coefficients in the combination lying in the span have the same
sign. -/
theorem sign_eq_of_affineCombination_mem_affineSpan_pair {p : ι → P} (h : AffineIndependent k p)
{w w₁ w₂ : ι → k} {s : Finset ι} (hw : ∑ i ∈ s, w i = 1) (hw₁ : ∑ i ∈ s, w₁ i = 1)
(hw₂ : ∑ i ∈ s, w₂ i = 1)
(hs :
s.affineCombination k p w ∈ line[k, s.affineCombination k p w₁, s.affineCombination k p w₂])
{i j : ι} (hi : i ∈ s) (hj : j ∈ s) (hi0 : w₁ i = 0) (hj0 : w₁ j = 0)
(hij : SignType.sign (w₂ i) = SignType.sign (w₂ j)) :
SignType.sign (w i) = SignType.sign (w j) := by
rw [affineCombination_mem_affineSpan_pair h hw hw₁ hw₂] at hs
rcases hs with ⟨r, hr⟩
rw [hr i hi, hr j hj, hi0, hj0, add_zero, add_zero, sub_zero, sub_zero, sign_mul, sign_mul, hij]
#align sign_eq_of_affine_combination_mem_affine_span_pair sign_eq_of_affineCombination_mem_affineSpan_pair
/-- Given an affinely independent family of points, suppose that an affine combination lies in
the span of one point of that family and a combination of another two points of that family given
by `lineMap` with coefficient between 0 and 1. Then the coefficients of those two points in the
combination lying in the span have the same sign. -/
theorem sign_eq_of_affineCombination_mem_affineSpan_single_lineMap {p : ι → P}
(h : AffineIndependent k p) {w : ι → k} {s : Finset ι} (hw : ∑ i ∈ s, w i = 1) {i₁ i₂ i₃ : ι}
(h₁ : i₁ ∈ s) (h₂ : i₂ ∈ s) (h₃ : i₃ ∈ s) (h₁₂ : i₁ ≠ i₂) (h₁₃ : i₁ ≠ i₃) (h₂₃ : i₂ ≠ i₃)
{c : k} (hc0 : 0 < c) (hc1 : c < 1)
(hs : s.affineCombination k p w ∈ line[k, p i₁, AffineMap.lineMap (p i₂) (p i₃) c]) :
SignType.sign (w i₂) = SignType.sign (w i₃) := by
classical
rw [← s.affineCombination_affineCombinationSingleWeights k p h₁, ←
s.affineCombination_affineCombinationLineMapWeights p h₂ h₃ c] at hs
refine
sign_eq_of_affineCombination_mem_affineSpan_pair h hw
(s.sum_affineCombinationSingleWeights k h₁)
(s.sum_affineCombinationLineMapWeights h₂ h₃ c) hs h₂ h₃
(Finset.affineCombinationSingleWeights_apply_of_ne k h₁₂.symm)
(Finset.affineCombinationSingleWeights_apply_of_ne k h₁₃.symm) ?_
rw [Finset.affineCombinationLineMapWeights_apply_left h₂₃,
Finset.affineCombinationLineMapWeights_apply_right h₂₃]
simp_all only [sub_pos, sign_pos]
#align sign_eq_of_affine_combination_mem_affine_span_single_line_map sign_eq_of_affineCombination_mem_affineSpan_single_lineMap
end Ordered
namespace Affine
variable (k : Type*) {V : Type*} (P : Type*) [Ring k] [AddCommGroup V] [Module k V]
variable [AffineSpace V P]
/-- A `Simplex k P n` is a collection of `n + 1` affinely
independent points. -/
structure Simplex (n : ℕ) where
points : Fin (n + 1) → P
independent : AffineIndependent k points
#align affine.simplex Affine.Simplex
/-- A `Triangle k P` is a collection of three affinely independent points. -/
abbrev Triangle :=
Simplex k P 2
#align affine.triangle Affine.Triangle
namespace Simplex
variable {P}
/-- Construct a 0-simplex from a point. -/
def mkOfPoint (p : P) : Simplex k P 0 :=
have : Subsingleton (Fin (1 + 0)) := by rw [add_zero]; infer_instance
⟨fun _ => p, affineIndependent_of_subsingleton k _⟩
#align affine.simplex.mk_of_point Affine.Simplex.mkOfPoint
/-- The point in a simplex constructed with `mkOfPoint`. -/
@[simp]
theorem mkOfPoint_points (p : P) (i : Fin 1) : (mkOfPoint k p).points i = p :=
rfl
#align affine.simplex.mk_of_point_points Affine.Simplex.mkOfPoint_points
instance [Inhabited P] : Inhabited (Simplex k P 0) :=
⟨mkOfPoint k default⟩
instance nonempty : Nonempty (Simplex k P 0) :=
⟨mkOfPoint k <| AddTorsor.nonempty.some⟩
#align affine.simplex.nonempty Affine.Simplex.nonempty
variable {k}
/-- Two simplices are equal if they have the same points. -/
@[ext]
theorem ext {n : ℕ} {s1 s2 : Simplex k P n} (h : ∀ i, s1.points i = s2.points i) : s1 = s2 := by
cases s1
cases s2
congr with i
exact h i
#align affine.simplex.ext Affine.Simplex.ext
/-- Two simplices are equal if and only if they have the same points. -/
theorem ext_iff {n : ℕ} (s1 s2 : Simplex k P n) : s1 = s2 ↔ ∀ i, s1.points i = s2.points i :=
⟨fun h _ => h ▸ rfl, ext⟩
#align affine.simplex.ext_iff Affine.Simplex.ext_iff
/-- A face of a simplex is a simplex with the given subset of
points. -/
def face {n : ℕ} (s : Simplex k P n) {fs : Finset (Fin (n + 1))} {m : ℕ} (h : fs.card = m + 1) :
Simplex k P m :=
⟨s.points ∘ fs.orderEmbOfFin h, s.independent.comp_embedding (fs.orderEmbOfFin h).toEmbedding⟩
#align affine.simplex.face Affine.Simplex.face
/-- The points of a face of a simplex are given by `mono_of_fin`. -/
theorem face_points {n : ℕ} (s : Simplex k P n) {fs : Finset (Fin (n + 1))} {m : ℕ}
(h : fs.card = m + 1) (i : Fin (m + 1)) :
(s.face h).points i = s.points (fs.orderEmbOfFin h i) :=
rfl
#align affine.simplex.face_points Affine.Simplex.face_points
/-- The points of a face of a simplex are given by `mono_of_fin`. -/
theorem face_points' {n : ℕ} (s : Simplex k P n) {fs : Finset (Fin (n + 1))} {m : ℕ}
(h : fs.card = m + 1) : (s.face h).points = s.points ∘ fs.orderEmbOfFin h :=
rfl
#align affine.simplex.face_points' Affine.Simplex.face_points'
/-- A single-point face equals the 0-simplex constructed with
`mkOfPoint`. -/
@[simp]
theorem face_eq_mkOfPoint {n : ℕ} (s : Simplex k P n) (i : Fin (n + 1)) :
s.face (Finset.card_singleton i) = mkOfPoint k (s.points i) := by
ext
simp only [Affine.Simplex.mkOfPoint_points, Affine.Simplex.face_points]
-- Porting note: `simp` can't use the next lemma
rw [Finset.orderEmbOfFin_singleton]
#align affine.simplex.face_eq_mk_of_point Affine.Simplex.face_eq_mkOfPoint
/-- The set of points of a face. -/
@[simp]
theorem range_face_points {n : ℕ} (s : Simplex k P n) {fs : Finset (Fin (n + 1))} {m : ℕ}
(h : fs.card = m + 1) : Set.range (s.face h).points = s.points '' ↑fs := by
rw [face_points', Set.range_comp, Finset.range_orderEmbOfFin]
#align affine.simplex.range_face_points Affine.Simplex.range_face_points
/-- Remap a simplex along an `Equiv` of index types. -/
@[simps]
def reindex {m n : ℕ} (s : Simplex k P m) (e : Fin (m + 1) ≃ Fin (n + 1)) : Simplex k P n :=
⟨s.points ∘ e.symm, (affineIndependent_equiv e.symm).2 s.independent⟩
#align affine.simplex.reindex Affine.Simplex.reindex
/-- Reindexing by `Equiv.refl` yields the original simplex. -/
@[simp]
theorem reindex_refl {n : ℕ} (s : Simplex k P n) : s.reindex (Equiv.refl (Fin (n + 1))) = s :=
ext fun _ => rfl
#align affine.simplex.reindex_refl Affine.Simplex.reindex_refl
/-- Reindexing by the composition of two equivalences is the same as reindexing twice. -/
@[simp]
theorem reindex_trans {n₁ n₂ n₃ : ℕ} (e₁₂ : Fin (n₁ + 1) ≃ Fin (n₂ + 1))
(e₂₃ : Fin (n₂ + 1) ≃ Fin (n₃ + 1)) (s : Simplex k P n₁) :
s.reindex (e₁₂.trans e₂₃) = (s.reindex e₁₂).reindex e₂₃ :=
rfl
#align affine.simplex.reindex_trans Affine.Simplex.reindex_trans
/-- Reindexing by an equivalence and its inverse yields the original simplex. -/
@[simp]
theorem reindex_reindex_symm {m n : ℕ} (s : Simplex k P m) (e : Fin (m + 1) ≃ Fin (n + 1)) :
(s.reindex e).reindex e.symm = s := by rw [← reindex_trans, Equiv.self_trans_symm, reindex_refl]
#align affine.simplex.reindex_reindex_symm Affine.Simplex.reindex_reindex_symm
/-- Reindexing by the inverse of an equivalence and that equivalence yields the original simplex. -/
@[simp]
| Mathlib/LinearAlgebra/AffineSpace/Independent.lean | 913 | 914 | theorem reindex_symm_reindex {m n : ℕ} (s : Simplex k P m) (e : Fin (n + 1) ≃ Fin (m + 1)) :
(s.reindex e.symm).reindex e = s := by | rw [← reindex_trans, Equiv.symm_trans_self, reindex_refl]
|
/-
Copyright (c) 2021 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth
-/
import Mathlib.Analysis.MeanInequalities
import Mathlib.Analysis.MeanInequalitiesPow
import Mathlib.Analysis.SpecialFunctions.Pow.Continuity
import Mathlib.Data.Set.Image
import Mathlib.Topology.Algebra.Order.LiminfLimsup
#align_import analysis.normed_space.lp_space from "leanprover-community/mathlib"@"de83b43717abe353f425855fcf0cedf9ea0fe8a4"
/-!
# ℓp space
This file describes properties of elements `f` of a pi-type `∀ i, E i` with finite "norm",
defined for `p : ℝ≥0∞` as the size of the support of `f` if `p=0`, `(∑' a, ‖f a‖^p) ^ (1/p)` for
`0 < p < ∞` and `⨆ a, ‖f a‖` for `p=∞`.
The Prop-valued `Memℓp f p` states that a function `f : ∀ i, E i` has finite norm according
to the above definition; that is, `f` has finite support if `p = 0`, `Summable (fun a ↦ ‖f a‖^p)` if
`0 < p < ∞`, and `BddAbove (norm '' (Set.range f))` if `p = ∞`.
The space `lp E p` is the subtype of elements of `∀ i : α, E i` which satisfy `Memℓp f p`. For
`1 ≤ p`, the "norm" is genuinely a norm and `lp` is a complete metric space.
## Main definitions
* `Memℓp f p` : property that the function `f` satisfies, as appropriate, `f` finitely supported
if `p = 0`, `Summable (fun a ↦ ‖f a‖^p)` if `0 < p < ∞`, and `BddAbove (norm '' (Set.range f))` if
`p = ∞`.
* `lp E p` : elements of `∀ i : α, E i` such that `Memℓp f p`. Defined as an `AddSubgroup` of
a type synonym `PreLp` for `∀ i : α, E i`, and equipped with a `NormedAddCommGroup` structure.
Under appropriate conditions, this is also equipped with the instances `lp.normedSpace`,
`lp.completeSpace`. For `p=∞`, there is also `lp.inftyNormedRing`,
`lp.inftyNormedAlgebra`, `lp.inftyStarRing` and `lp.inftyCstarRing`.
## Main results
* `Memℓp.of_exponent_ge`: For `q ≤ p`, a function which is `Memℓp` for `q` is also `Memℓp` for `p`.
* `lp.memℓp_of_tendsto`, `lp.norm_le_of_tendsto`: A pointwise limit of functions in `lp`, all with
`lp` norm `≤ C`, is itself in `lp` and has `lp` norm `≤ C`.
* `lp.tsum_mul_le_mul_norm`: basic form of Hölder's inequality
## Implementation
Since `lp` is defined as an `AddSubgroup`, dot notation does not work. Use `lp.norm_neg f` to
say that `‖-f‖ = ‖f‖`, instead of the non-working `f.norm_neg`.
## TODO
* More versions of Hölder's inequality (for example: the case `p = 1`, `q = ∞`; a version for normed
rings which has `‖∑' i, f i * g i‖` rather than `∑' i, ‖f i‖ * g i‖` on the RHS; a version for
three exponents satisfying `1 / r = 1 / p + 1 / q`)
-/
noncomputable section
open scoped NNReal ENNReal Function
variable {α : Type*} {E : α → Type*} {p q : ℝ≥0∞} [∀ i, NormedAddCommGroup (E i)]
/-!
### `Memℓp` predicate
-/
/-- The property that `f : ∀ i : α, E i`
* is finitely supported, if `p = 0`, or
* admits an upper bound for `Set.range (fun i ↦ ‖f i‖)`, if `p = ∞`, or
* has the series `∑' i, ‖f i‖ ^ p` be summable, if `0 < p < ∞`. -/
def Memℓp (f : ∀ i, E i) (p : ℝ≥0∞) : Prop :=
if p = 0 then Set.Finite { i | f i ≠ 0 }
else if p = ∞ then BddAbove (Set.range fun i => ‖f i‖)
else Summable fun i => ‖f i‖ ^ p.toReal
#align mem_ℓp Memℓp
theorem memℓp_zero_iff {f : ∀ i, E i} : Memℓp f 0 ↔ Set.Finite { i | f i ≠ 0 } := by
dsimp [Memℓp]
rw [if_pos rfl]
#align mem_ℓp_zero_iff memℓp_zero_iff
theorem memℓp_zero {f : ∀ i, E i} (hf : Set.Finite { i | f i ≠ 0 }) : Memℓp f 0 :=
memℓp_zero_iff.2 hf
#align mem_ℓp_zero memℓp_zero
theorem memℓp_infty_iff {f : ∀ i, E i} : Memℓp f ∞ ↔ BddAbove (Set.range fun i => ‖f i‖) := by
dsimp [Memℓp]
rw [if_neg ENNReal.top_ne_zero, if_pos rfl]
#align mem_ℓp_infty_iff memℓp_infty_iff
theorem memℓp_infty {f : ∀ i, E i} (hf : BddAbove (Set.range fun i => ‖f i‖)) : Memℓp f ∞ :=
memℓp_infty_iff.2 hf
#align mem_ℓp_infty memℓp_infty
theorem memℓp_gen_iff (hp : 0 < p.toReal) {f : ∀ i, E i} :
Memℓp f p ↔ Summable fun i => ‖f i‖ ^ p.toReal := by
rw [ENNReal.toReal_pos_iff] at hp
dsimp [Memℓp]
rw [if_neg hp.1.ne', if_neg hp.2.ne]
#align mem_ℓp_gen_iff memℓp_gen_iff
theorem memℓp_gen {f : ∀ i, E i} (hf : Summable fun i => ‖f i‖ ^ p.toReal) : Memℓp f p := by
rcases p.trichotomy with (rfl | rfl | hp)
· apply memℓp_zero
have H : Summable fun _ : α => (1 : ℝ) := by simpa using hf
exact (Set.Finite.of_summable_const (by norm_num) H).subset (Set.subset_univ _)
· apply memℓp_infty
have H : Summable fun _ : α => (1 : ℝ) := by simpa using hf
simpa using ((Set.Finite.of_summable_const (by norm_num) H).image fun i => ‖f i‖).bddAbove
exact (memℓp_gen_iff hp).2 hf
#align mem_ℓp_gen memℓp_gen
theorem memℓp_gen' {C : ℝ} {f : ∀ i, E i} (hf : ∀ s : Finset α, ∑ i ∈ s, ‖f i‖ ^ p.toReal ≤ C) :
Memℓp f p := by
apply memℓp_gen
use ⨆ s : Finset α, ∑ i ∈ s, ‖f i‖ ^ p.toReal
apply hasSum_of_isLUB_of_nonneg
· intro b
exact Real.rpow_nonneg (norm_nonneg _) _
apply isLUB_ciSup
use C
rintro - ⟨s, rfl⟩
exact hf s
#align mem_ℓp_gen' memℓp_gen'
theorem zero_memℓp : Memℓp (0 : ∀ i, E i) p := by
rcases p.trichotomy with (rfl | rfl | hp)
· apply memℓp_zero
simp
· apply memℓp_infty
simp only [norm_zero, Pi.zero_apply]
exact bddAbove_singleton.mono Set.range_const_subset
· apply memℓp_gen
simp [Real.zero_rpow hp.ne', summable_zero]
#align zero_mem_ℓp zero_memℓp
theorem zero_mem_ℓp' : Memℓp (fun i : α => (0 : E i)) p :=
zero_memℓp
#align zero_mem_ℓp' zero_mem_ℓp'
namespace Memℓp
theorem finite_dsupport {f : ∀ i, E i} (hf : Memℓp f 0) : Set.Finite { i | f i ≠ 0 } :=
memℓp_zero_iff.1 hf
#align mem_ℓp.finite_dsupport Memℓp.finite_dsupport
theorem bddAbove {f : ∀ i, E i} (hf : Memℓp f ∞) : BddAbove (Set.range fun i => ‖f i‖) :=
memℓp_infty_iff.1 hf
#align mem_ℓp.bdd_above Memℓp.bddAbove
theorem summable (hp : 0 < p.toReal) {f : ∀ i, E i} (hf : Memℓp f p) :
Summable fun i => ‖f i‖ ^ p.toReal :=
(memℓp_gen_iff hp).1 hf
#align mem_ℓp.summable Memℓp.summable
theorem neg {f : ∀ i, E i} (hf : Memℓp f p) : Memℓp (-f) p := by
rcases p.trichotomy with (rfl | rfl | hp)
· apply memℓp_zero
simp [hf.finite_dsupport]
· apply memℓp_infty
simpa using hf.bddAbove
· apply memℓp_gen
simpa using hf.summable hp
#align mem_ℓp.neg Memℓp.neg
@[simp]
theorem neg_iff {f : ∀ i, E i} : Memℓp (-f) p ↔ Memℓp f p :=
⟨fun h => neg_neg f ▸ h.neg, Memℓp.neg⟩
#align mem_ℓp.neg_iff Memℓp.neg_iff
theorem of_exponent_ge {p q : ℝ≥0∞} {f : ∀ i, E i} (hfq : Memℓp f q) (hpq : q ≤ p) : Memℓp f p := by
rcases ENNReal.trichotomy₂ hpq with
(⟨rfl, rfl⟩ | ⟨rfl, rfl⟩ | ⟨rfl, hp⟩ | ⟨rfl, rfl⟩ | ⟨hq, rfl⟩ | ⟨hq, _, hpq'⟩)
· exact hfq
· apply memℓp_infty
obtain ⟨C, hC⟩ := (hfq.finite_dsupport.image fun i => ‖f i‖).bddAbove
use max 0 C
rintro x ⟨i, rfl⟩
by_cases hi : f i = 0
· simp [hi]
· exact (hC ⟨i, hi, rfl⟩).trans (le_max_right _ _)
· apply memℓp_gen
have : ∀ i ∉ hfq.finite_dsupport.toFinset, ‖f i‖ ^ p.toReal = 0 := by
intro i hi
have : f i = 0 := by simpa using hi
simp [this, Real.zero_rpow hp.ne']
exact summable_of_ne_finset_zero this
· exact hfq
· apply memℓp_infty
obtain ⟨A, hA⟩ := (hfq.summable hq).tendsto_cofinite_zero.bddAbove_range_of_cofinite
use A ^ q.toReal⁻¹
rintro x ⟨i, rfl⟩
have : 0 ≤ ‖f i‖ ^ q.toReal := by positivity
simpa [← Real.rpow_mul, mul_inv_cancel hq.ne'] using
Real.rpow_le_rpow this (hA ⟨i, rfl⟩) (inv_nonneg.mpr hq.le)
· apply memℓp_gen
have hf' := hfq.summable hq
refine .of_norm_bounded_eventually _ hf' (@Set.Finite.subset _ { i | 1 ≤ ‖f i‖ } ?_ _ ?_)
· have H : { x : α | 1 ≤ ‖f x‖ ^ q.toReal }.Finite := by
simpa using eventually_lt_of_tendsto_lt (by norm_num) hf'.tendsto_cofinite_zero
exact H.subset fun i hi => Real.one_le_rpow hi hq.le
· show ∀ i, ¬|‖f i‖ ^ p.toReal| ≤ ‖f i‖ ^ q.toReal → 1 ≤ ‖f i‖
intro i hi
have : 0 ≤ ‖f i‖ ^ p.toReal := Real.rpow_nonneg (norm_nonneg _) p.toReal
simp only [abs_of_nonneg, this] at hi
contrapose! hi
exact Real.rpow_le_rpow_of_exponent_ge' (norm_nonneg _) hi.le hq.le hpq'
#align mem_ℓp.of_exponent_ge Memℓp.of_exponent_ge
theorem add {f g : ∀ i, E i} (hf : Memℓp f p) (hg : Memℓp g p) : Memℓp (f + g) p := by
rcases p.trichotomy with (rfl | rfl | hp)
· apply memℓp_zero
refine (hf.finite_dsupport.union hg.finite_dsupport).subset fun i => ?_
simp only [Pi.add_apply, Ne, Set.mem_union, Set.mem_setOf_eq]
contrapose!
rintro ⟨hf', hg'⟩
simp [hf', hg']
· apply memℓp_infty
obtain ⟨A, hA⟩ := hf.bddAbove
obtain ⟨B, hB⟩ := hg.bddAbove
refine ⟨A + B, ?_⟩
rintro a ⟨i, rfl⟩
exact le_trans (norm_add_le _ _) (add_le_add (hA ⟨i, rfl⟩) (hB ⟨i, rfl⟩))
apply memℓp_gen
let C : ℝ := if p.toReal < 1 then 1 else (2 : ℝ) ^ (p.toReal - 1)
refine .of_nonneg_of_le ?_ (fun i => ?_) (((hf.summable hp).add (hg.summable hp)).mul_left C)
· intro; positivity
· refine (Real.rpow_le_rpow (norm_nonneg _) (norm_add_le _ _) hp.le).trans ?_
dsimp only [C]
split_ifs with h
· simpa using NNReal.coe_le_coe.2 (NNReal.rpow_add_le_add_rpow ‖f i‖₊ ‖g i‖₊ hp.le h.le)
· let F : Fin 2 → ℝ≥0 := ![‖f i‖₊, ‖g i‖₊]
simp only [not_lt] at h
simpa [Fin.sum_univ_succ] using
Real.rpow_sum_le_const_mul_sum_rpow_of_nonneg Finset.univ h fun i _ => (F i).coe_nonneg
#align mem_ℓp.add Memℓp.add
theorem sub {f g : ∀ i, E i} (hf : Memℓp f p) (hg : Memℓp g p) : Memℓp (f - g) p := by
rw [sub_eq_add_neg]; exact hf.add hg.neg
#align mem_ℓp.sub Memℓp.sub
theorem finset_sum {ι} (s : Finset ι) {f : ι → ∀ i, E i} (hf : ∀ i ∈ s, Memℓp (f i) p) :
Memℓp (fun a => ∑ i ∈ s, f i a) p := by
haveI : DecidableEq ι := Classical.decEq _
revert hf
refine Finset.induction_on s ?_ ?_
· simp only [zero_mem_ℓp', Finset.sum_empty, imp_true_iff]
· intro i s his ih hf
simp only [his, Finset.sum_insert, not_false_iff]
exact (hf i (s.mem_insert_self i)).add (ih fun j hj => hf j (Finset.mem_insert_of_mem hj))
#align mem_ℓp.finset_sum Memℓp.finset_sum
section BoundedSMul
variable {𝕜 : Type*} [NormedRing 𝕜] [∀ i, Module 𝕜 (E i)] [∀ i, BoundedSMul 𝕜 (E i)]
theorem const_smul {f : ∀ i, E i} (hf : Memℓp f p) (c : 𝕜) : Memℓp (c • f) p := by
rcases p.trichotomy with (rfl | rfl | hp)
· apply memℓp_zero
refine hf.finite_dsupport.subset fun i => (?_ : ¬c • f i = 0 → ¬f i = 0)
exact not_imp_not.mpr fun hf' => hf'.symm ▸ smul_zero c
· obtain ⟨A, hA⟩ := hf.bddAbove
refine memℓp_infty ⟨‖c‖ * A, ?_⟩
rintro a ⟨i, rfl⟩
dsimp only [Pi.smul_apply]
refine (norm_smul_le _ _).trans ?_
gcongr
exact hA ⟨i, rfl⟩
· apply memℓp_gen
dsimp only [Pi.smul_apply]
have := (hf.summable hp).mul_left (↑(‖c‖₊ ^ p.toReal) : ℝ)
simp_rw [← coe_nnnorm, ← NNReal.coe_rpow, ← NNReal.coe_mul, NNReal.summable_coe,
← NNReal.mul_rpow] at this ⊢
refine NNReal.summable_of_le ?_ this
intro i
gcongr
apply nnnorm_smul_le
#align mem_ℓp.const_smul Memℓp.const_smul
theorem const_mul {f : α → 𝕜} (hf : Memℓp f p) (c : 𝕜) : Memℓp (fun x => c * f x) p :=
@Memℓp.const_smul α (fun _ => 𝕜) _ _ 𝕜 _ _ (fun i => by infer_instance) _ hf c
#align mem_ℓp.const_mul Memℓp.const_mul
end BoundedSMul
end Memℓp
/-!
### lp space
The space of elements of `∀ i, E i` satisfying the predicate `Memℓp`.
-/
/-- We define `PreLp E` to be a type synonym for `∀ i, E i` which, importantly, does not inherit
the `pi` topology on `∀ i, E i` (otherwise this topology would descend to `lp E p` and conflict
with the normed group topology we will later equip it with.)
We choose to deal with this issue by making a type synonym for `∀ i, E i` rather than for the `lp`
subgroup itself, because this allows all the spaces `lp E p` (for varying `p`) to be subgroups of
the same ambient group, which permits lemma statements like `lp.monotone` (below). -/
@[nolint unusedArguments]
def PreLp (E : α → Type*) [∀ i, NormedAddCommGroup (E i)] : Type _ :=
∀ i, E i --deriving AddCommGroup
#align pre_lp PreLp
instance : AddCommGroup (PreLp E) := by unfold PreLp; infer_instance
instance PreLp.unique [IsEmpty α] : Unique (PreLp E) :=
Pi.uniqueOfIsEmpty E
#align pre_lp.unique PreLp.unique
/-- lp space -/
def lp (E : α → Type*) [∀ i, NormedAddCommGroup (E i)] (p : ℝ≥0∞) : AddSubgroup (PreLp E) where
carrier := { f | Memℓp f p }
zero_mem' := zero_memℓp
add_mem' := Memℓp.add
neg_mem' := Memℓp.neg
#align lp lp
@[inherit_doc] scoped[lp] notation "ℓ^∞(" ι ", " E ")" => lp (fun i : ι => E) ∞
@[inherit_doc] scoped[lp] notation "ℓ^∞(" ι ")" => lp (fun i : ι => ℝ) ∞
namespace lp
-- Porting note: was `Coe`
instance : CoeOut (lp E p) (∀ i, E i) :=
⟨Subtype.val (α := ∀ i, E i)⟩ -- Porting note: Originally `coeSubtype`
instance coeFun : CoeFun (lp E p) fun _ => ∀ i, E i :=
⟨fun f => (f : ∀ i, E i)⟩
@[ext]
theorem ext {f g : lp E p} (h : (f : ∀ i, E i) = g) : f = g :=
Subtype.ext h
#align lp.ext lp.ext
protected theorem ext_iff {f g : lp E p} : f = g ↔ (f : ∀ i, E i) = g :=
Subtype.ext_iff
#align lp.ext_iff lp.ext_iff
theorem eq_zero' [IsEmpty α] (f : lp E p) : f = 0 :=
Subsingleton.elim f 0
#align lp.eq_zero' lp.eq_zero'
protected theorem monotone {p q : ℝ≥0∞} (hpq : q ≤ p) : lp E q ≤ lp E p :=
fun _ hf => Memℓp.of_exponent_ge hf hpq
#align lp.monotone lp.monotone
protected theorem memℓp (f : lp E p) : Memℓp f p :=
f.prop
#align lp.mem_ℓp lp.memℓp
variable (E p)
@[simp]
theorem coeFn_zero : ⇑(0 : lp E p) = 0 :=
rfl
#align lp.coe_fn_zero lp.coeFn_zero
variable {E p}
@[simp]
theorem coeFn_neg (f : lp E p) : ⇑(-f) = -f :=
rfl
#align lp.coe_fn_neg lp.coeFn_neg
@[simp]
theorem coeFn_add (f g : lp E p) : ⇑(f + g) = f + g :=
rfl
#align lp.coe_fn_add lp.coeFn_add
-- porting note (#10618): removed `@[simp]` because `simp` can prove this
theorem coeFn_sum {ι : Type*} (f : ι → lp E p) (s : Finset ι) :
⇑(∑ i ∈ s, f i) = ∑ i ∈ s, ⇑(f i) := by
simp
#align lp.coe_fn_sum lp.coeFn_sum
@[simp]
theorem coeFn_sub (f g : lp E p) : ⇑(f - g) = f - g :=
rfl
#align lp.coe_fn_sub lp.coeFn_sub
instance : Norm (lp E p) where
norm f :=
if hp : p = 0 then by
subst hp
exact ((lp.memℓp f).finite_dsupport.toFinset.card : ℝ)
else if p = ∞ then ⨆ i, ‖f i‖ else (∑' i, ‖f i‖ ^ p.toReal) ^ (1 / p.toReal)
theorem norm_eq_card_dsupport (f : lp E 0) : ‖f‖ = (lp.memℓp f).finite_dsupport.toFinset.card :=
dif_pos rfl
#align lp.norm_eq_card_dsupport lp.norm_eq_card_dsupport
| Mathlib/Analysis/NormedSpace/lpSpace.lean | 399 | 401 | theorem norm_eq_ciSup (f : lp E ∞) : ‖f‖ = ⨆ i, ‖f i‖ := by |
dsimp [norm]
rw [dif_neg ENNReal.top_ne_zero, if_pos rfl]
|
/-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.SpecialFunctions.Gaussian.GaussianIntegral
#align_import analysis.special_functions.gamma.bohr_mollerup from "leanprover-community/mathlib"@"a3209ddf94136d36e5e5c624b10b2a347cc9d090"
/-! # Convexity properties of the Gamma function
In this file, we prove that `Gamma` and `log ∘ Gamma` are convex functions on the positive real
line. We then prove the Bohr-Mollerup theorem, which characterises `Gamma` as the *unique*
positive-real-valued, log-convex function on the positive reals satisfying `f (x + 1) = x f x` and
`f 1 = 1`.
The proof of the Bohr-Mollerup theorem is bound up with the proof of (a weak form of) the Euler
limit formula, `Real.BohrMollerup.tendsto_logGammaSeq`, stating that for positive
real `x` the sequence `x * log n + log n! - ∑ (m : ℕ) ∈ Finset.range (n + 1), log (x + m)`
tends to `log Γ(x)` as `n → ∞`. We prove that any function satisfying the hypotheses of the
Bohr-Mollerup theorem must agree with the limit in the Euler limit formula, so there is at most one
such function; then we show that `Γ` satisfies these conditions.
Since most of the auxiliary lemmas for the Bohr-Mollerup theorem are of no relevance outside the
context of this proof, we place them in a separate namespace `Real.BohrMollerup` to avoid clutter.
(This includes the logarithmic form of the Euler limit formula, since later we will prove a more
general form of the Euler limit formula valid for any real or complex `x`; see
`Real.Gamma_seq_tendsto_Gamma` and `Complex.Gamma_seq_tendsto_Gamma` in the file
`Mathlib/Analysis/SpecialFunctions/Gamma/Beta.lean`.)
As an application of the Bohr-Mollerup theorem we prove the Legendre doubling formula for the
Gamma function for real positive `s` (which will be upgraded to a proof for all complex `s` in a
later file).
TODO: This argument can be extended to prove the general `k`-multiplication formula (at least up
to a constant, and it should be possible to deduce the value of this constant using Stirling's
formula).
-/
set_option linter.uppercaseLean3 false
noncomputable section
open Filter Set MeasureTheory
open scoped Nat ENNReal Topology Real
section Convexity
-- Porting note: move the following lemmas to `Analysis.Convex.Function`
variable {𝕜 E β : Type*} {s : Set E} {f g : E → β} [OrderedSemiring 𝕜] [SMul 𝕜 E] [AddCommMonoid E]
[OrderedAddCommMonoid β]
theorem ConvexOn.congr [SMul 𝕜 β] (hf : ConvexOn 𝕜 s f) (hfg : EqOn f g s) : ConvexOn 𝕜 s g :=
⟨hf.1, fun x hx y hy a b ha hb hab => by
simpa only [← hfg hx, ← hfg hy, ← hfg (hf.1 hx hy ha hb hab)] using hf.2 hx hy ha hb hab⟩
#align convex_on.congr ConvexOn.congr
theorem ConcaveOn.congr [SMul 𝕜 β] (hf : ConcaveOn 𝕜 s f) (hfg : EqOn f g s) : ConcaveOn 𝕜 s g :=
⟨hf.1, fun x hx y hy a b ha hb hab => by
simpa only [← hfg hx, ← hfg hy, ← hfg (hf.1 hx hy ha hb hab)] using hf.2 hx hy ha hb hab⟩
#align concave_on.congr ConcaveOn.congr
theorem StrictConvexOn.congr [SMul 𝕜 β] (hf : StrictConvexOn 𝕜 s f) (hfg : EqOn f g s) :
StrictConvexOn 𝕜 s g :=
⟨hf.1, fun x hx y hy hxy a b ha hb hab => by
simpa only [← hfg hx, ← hfg hy, ← hfg (hf.1 hx hy ha.le hb.le hab)] using
hf.2 hx hy hxy ha hb hab⟩
#align strict_convex_on.congr StrictConvexOn.congr
theorem StrictConcaveOn.congr [SMul 𝕜 β] (hf : StrictConcaveOn 𝕜 s f) (hfg : EqOn f g s) :
StrictConcaveOn 𝕜 s g :=
⟨hf.1, fun x hx y hy hxy a b ha hb hab => by
simpa only [← hfg hx, ← hfg hy, ← hfg (hf.1 hx hy ha.le hb.le hab)] using
hf.2 hx hy hxy ha hb hab⟩
#align strict_concave_on.congr StrictConcaveOn.congr
theorem ConvexOn.add_const [Module 𝕜 β] (hf : ConvexOn 𝕜 s f) (b : β) :
ConvexOn 𝕜 s (f + fun _ => b) :=
hf.add (convexOn_const _ hf.1)
#align convex_on.add_const ConvexOn.add_const
theorem ConcaveOn.add_const [Module 𝕜 β] (hf : ConcaveOn 𝕜 s f) (b : β) :
ConcaveOn 𝕜 s (f + fun _ => b) :=
hf.add (concaveOn_const _ hf.1)
#align concave_on.add_const ConcaveOn.add_const
theorem StrictConvexOn.add_const {γ : Type*} {f : E → γ} [OrderedCancelAddCommMonoid γ]
[Module 𝕜 γ] (hf : StrictConvexOn 𝕜 s f) (b : γ) : StrictConvexOn 𝕜 s (f + fun _ => b) :=
hf.add_convexOn (convexOn_const _ hf.1)
#align strict_convex_on.add_const StrictConvexOn.add_const
theorem StrictConcaveOn.add_const {γ : Type*} {f : E → γ} [OrderedCancelAddCommMonoid γ]
[Module 𝕜 γ] (hf : StrictConcaveOn 𝕜 s f) (b : γ) : StrictConcaveOn 𝕜 s (f + fun _ => b) :=
hf.add_concaveOn (concaveOn_const _ hf.1)
#align strict_concave_on.add_const StrictConcaveOn.add_const
end Convexity
namespace Real
section Convexity
/-- Log-convexity of the Gamma function on the positive reals (stated in multiplicative form),
proved using the Hölder inequality applied to Euler's integral. -/
theorem Gamma_mul_add_mul_le_rpow_Gamma_mul_rpow_Gamma {s t a b : ℝ} (hs : 0 < s) (ht : 0 < t)
(ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) :
Gamma (a * s + b * t) ≤ Gamma s ^ a * Gamma t ^ b := by
-- We will apply Hölder's inequality, for the conjugate exponents `p = 1 / a`
-- and `q = 1 / b`, to the functions `f a s` and `f b t`, where `f` is as follows:
let f : ℝ → ℝ → ℝ → ℝ := fun c u x => exp (-c * x) * x ^ (c * (u - 1))
have e : IsConjExponent (1 / a) (1 / b) := Real.isConjExponent_one_div ha hb hab
have hab' : b = 1 - a := by linarith
have hst : 0 < a * s + b * t := add_pos (mul_pos ha hs) (mul_pos hb ht)
-- some properties of f:
have posf : ∀ c u x : ℝ, x ∈ Ioi (0 : ℝ) → 0 ≤ f c u x := fun c u x hx =>
mul_nonneg (exp_pos _).le (rpow_pos_of_pos hx _).le
have posf' : ∀ c u : ℝ, ∀ᵐ x : ℝ ∂volume.restrict (Ioi 0), 0 ≤ f c u x := fun c u =>
(ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ (posf c u))
have fpow :
∀ {c x : ℝ} (_ : 0 < c) (u : ℝ) (_ : 0 < x), exp (-x) * x ^ (u - 1) = f c u x ^ (1 / c) := by
intro c x hc u hx
dsimp only [f]
rw [mul_rpow (exp_pos _).le ((rpow_nonneg hx.le) _), ← exp_mul, ← rpow_mul hx.le]
congr 2 <;> field_simp [hc.ne']; ring
-- show `f c u` is in `ℒp` for `p = 1/c`:
have f_mem_Lp :
∀ {c u : ℝ} (hc : 0 < c) (hu : 0 < u),
Memℒp (f c u) (ENNReal.ofReal (1 / c)) (volume.restrict (Ioi 0)) := by
intro c u hc hu
have A : ENNReal.ofReal (1 / c) ≠ 0 := by
rwa [Ne, ENNReal.ofReal_eq_zero, not_le, one_div_pos]
have B : ENNReal.ofReal (1 / c) ≠ ∞ := ENNReal.ofReal_ne_top
rw [← memℒp_norm_rpow_iff _ A B, ENNReal.toReal_ofReal (one_div_nonneg.mpr hc.le),
ENNReal.div_self A B, memℒp_one_iff_integrable]
· apply Integrable.congr (GammaIntegral_convergent hu)
refine eventuallyEq_of_mem (self_mem_ae_restrict measurableSet_Ioi) fun x hx => ?_
dsimp only
rw [fpow hc u hx]
congr 1
exact (norm_of_nonneg (posf _ _ x hx)).symm
· refine ContinuousOn.aestronglyMeasurable ?_ measurableSet_Ioi
refine (Continuous.continuousOn ?_).mul (ContinuousAt.continuousOn fun x hx => ?_)
· exact continuous_exp.comp (continuous_const.mul continuous_id')
· exact continuousAt_rpow_const _ _ (Or.inl (mem_Ioi.mp hx).ne')
-- now apply Hölder:
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst]
convert
MeasureTheory.integral_mul_le_Lp_mul_Lq_of_nonneg e (posf' a s) (posf' b t) (f_mem_Lp ha hs)
(f_mem_Lp hb ht) using
1
· refine setIntegral_congr measurableSet_Ioi fun x hx => ?_
dsimp only
have A : exp (-x) = exp (-a * x) * exp (-b * x) := by
rw [← exp_add, ← add_mul, ← neg_add, hab, neg_one_mul]
have B : x ^ (a * s + b * t - 1) = x ^ (a * (s - 1)) * x ^ (b * (t - 1)) := by
rw [← rpow_add hx, hab']; congr 1; ring
rw [A, B]
ring
· rw [one_div_one_div, one_div_one_div]
congr 2 <;> exact setIntegral_congr measurableSet_Ioi fun x hx => fpow (by assumption) _ hx
#align real.Gamma_mul_add_mul_le_rpow_Gamma_mul_rpow_Gamma Real.Gamma_mul_add_mul_le_rpow_Gamma_mul_rpow_Gamma
theorem convexOn_log_Gamma : ConvexOn ℝ (Ioi 0) (log ∘ Gamma) := by
refine convexOn_iff_forall_pos.mpr ⟨convex_Ioi _, fun x hx y hy a b ha hb hab => ?_⟩
have : b = 1 - a := by linarith
subst this
simp_rw [Function.comp_apply, smul_eq_mul]
simp only [mem_Ioi] at hx hy
rw [← log_rpow, ← log_rpow, ← log_mul]
· gcongr
exact Gamma_mul_add_mul_le_rpow_Gamma_mul_rpow_Gamma hx hy ha hb hab
all_goals positivity
#align real.convex_on_log_Gamma Real.convexOn_log_Gamma
theorem convexOn_Gamma : ConvexOn ℝ (Ioi 0) Gamma := by
refine
((convexOn_exp.subset (subset_univ _) ?_).comp convexOn_log_Gamma
(exp_monotone.monotoneOn _)).congr
fun x hx => exp_log (Gamma_pos_of_pos hx)
rw [convex_iff_isPreconnected]
refine isPreconnected_Ioi.image _ fun x hx => ContinuousAt.continuousWithinAt ?_
refine (differentiableAt_Gamma fun m => ?_).continuousAt.log (Gamma_pos_of_pos hx).ne'
exact (neg_lt_iff_pos_add.mpr (add_pos_of_pos_of_nonneg (mem_Ioi.mp hx) (Nat.cast_nonneg m))).ne'
#align real.convex_on_Gamma Real.convexOn_Gamma
end Convexity
section BohrMollerup
namespace BohrMollerup
/-- The function `n ↦ x log n + log n! - (log x + ... + log (x + n))`, which we will show tends to
`log (Gamma x)` as `n → ∞`. -/
def logGammaSeq (x : ℝ) (n : ℕ) : ℝ :=
x * log n + log n ! - ∑ m ∈ Finset.range (n + 1), log (x + m)
#align real.bohr_mollerup.log_gamma_seq Real.BohrMollerup.logGammaSeq
variable {f : ℝ → ℝ} {x : ℝ} {n : ℕ}
theorem f_nat_eq (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hn : n ≠ 0) :
f n = f 1 + log (n - 1)! := by
refine Nat.le_induction (by simp) (fun m hm IH => ?_) n (Nat.one_le_iff_ne_zero.2 hn)
have A : 0 < (m : ℝ) := Nat.cast_pos.2 hm
simp only [hf_feq A, Nat.cast_add, Nat.cast_one, Nat.add_succ_sub_one, add_zero]
rw [IH, add_assoc, ← log_mul (Nat.cast_ne_zero.mpr (Nat.factorial_ne_zero _)) A.ne', ←
Nat.cast_mul]
conv_rhs => rw [← Nat.succ_pred_eq_of_pos hm, Nat.factorial_succ, mul_comm]
congr
exact (Nat.succ_pred_eq_of_pos hm).symm
#align real.bohr_mollerup.f_nat_eq Real.BohrMollerup.f_nat_eq
theorem f_add_nat_eq (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hx : 0 < x) (n : ℕ) :
f (x + n) = f x + ∑ m ∈ Finset.range n, log (x + m) := by
induction' n with n hn
· simp
· have : x + n.succ = x + n + 1 := by push_cast; ring
rw [this, hf_feq, hn]
· rw [Finset.range_succ, Finset.sum_insert Finset.not_mem_range_self]
abel
· linarith [(Nat.cast_nonneg n : 0 ≤ (n : ℝ))]
#align real.bohr_mollerup.f_add_nat_eq Real.BohrMollerup.f_add_nat_eq
/-- Linear upper bound for `f (x + n)` on unit interval -/
theorem f_add_nat_le (hf_conv : ConvexOn ℝ (Ioi 0) f)
(hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hn : n ≠ 0) (hx : 0 < x) (hx' : x ≤ 1) :
f (n + x) ≤ f n + x * log n := by
have hn' : 0 < (n : ℝ) := Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)
have : f n + x * log n = (1 - x) * f n + x * f (n + 1) := by rw [hf_feq hn']; ring
rw [this, (by ring : (n : ℝ) + x = (1 - x) * n + x * (n + 1))]
simpa only [smul_eq_mul] using
hf_conv.2 hn' (by linarith : 0 < (n + 1 : ℝ)) (by linarith : 0 ≤ 1 - x) hx.le (by linarith)
#align real.bohr_mollerup.f_add_nat_le Real.BohrMollerup.f_add_nat_le
/-- Linear lower bound for `f (x + n)` on unit interval -/
theorem f_add_nat_ge (hf_conv : ConvexOn ℝ (Ioi 0) f)
(hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hn : 2 ≤ n) (hx : 0 < x) :
f n + x * log (n - 1) ≤ f (n + x) := by
have npos : 0 < (n : ℝ) - 1 := by rw [← Nat.cast_one, sub_pos, Nat.cast_lt]; linarith
have c :=
(convexOn_iff_slope_mono_adjacent.mp <| hf_conv).2 npos (by linarith : 0 < (n : ℝ) + x)
(by linarith : (n : ℝ) - 1 < (n : ℝ)) (by linarith)
rw [add_sub_cancel_left, sub_sub_cancel, div_one] at c
have : f (↑n - 1) = f n - log (↑n - 1) := by
-- Porting note: was
-- nth_rw_rhs 1 [(by ring : (n : ℝ) = ↑n - 1 + 1)]
-- rw [hf_feq npos, add_sub_cancel]
rw [eq_sub_iff_add_eq, ← hf_feq npos, sub_add_cancel]
rwa [this, le_div_iff hx, sub_sub_cancel, le_sub_iff_add_le, mul_comm _ x, add_comm] at c
#align real.bohr_mollerup.f_add_nat_ge Real.BohrMollerup.f_add_nat_ge
theorem logGammaSeq_add_one (x : ℝ) (n : ℕ) :
logGammaSeq (x + 1) n = logGammaSeq x (n + 1) + log x - (x + 1) * (log (n + 1) - log n) := by
dsimp only [Nat.factorial_succ, logGammaSeq]
conv_rhs => rw [Finset.sum_range_succ', Nat.cast_zero, add_zero]
rw [Nat.cast_mul, log_mul]; rotate_left
· rw [Nat.cast_ne_zero]; exact Nat.succ_ne_zero n
· rw [Nat.cast_ne_zero]; exact Nat.factorial_ne_zero n
have :
∑ m ∈ Finset.range (n + 1), log (x + 1 + ↑m) =
∑ k ∈ Finset.range (n + 1), log (x + ↑(k + 1)) := by
congr! 2 with m
push_cast
abel
rw [← this, Nat.cast_add_one n]
ring
#align real.bohr_mollerup.log_gamma_seq_add_one Real.BohrMollerup.logGammaSeq_add_one
theorem le_logGammaSeq (hf_conv : ConvexOn ℝ (Ioi 0) f)
(hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hx : 0 < x) (hx' : x ≤ 1) (n : ℕ) :
f x ≤ f 1 + x * log (n + 1) - x * log n + logGammaSeq x n := by
rw [logGammaSeq, ← add_sub_assoc, le_sub_iff_add_le, ← f_add_nat_eq (@hf_feq) hx, add_comm x]
refine (f_add_nat_le hf_conv (@hf_feq) (Nat.add_one_ne_zero n) hx hx').trans (le_of_eq ?_)
rw [f_nat_eq @hf_feq (by linarith : n + 1 ≠ 0), Nat.add_sub_cancel, Nat.cast_add_one]
ring
#align real.bohr_mollerup.le_log_gamma_seq Real.BohrMollerup.le_logGammaSeq
theorem ge_logGammaSeq (hf_conv : ConvexOn ℝ (Ioi 0) f)
(hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hx : 0 < x) (hn : n ≠ 0) :
f 1 + logGammaSeq x n ≤ f x := by
dsimp [logGammaSeq]
rw [← add_sub_assoc, sub_le_iff_le_add, ← f_add_nat_eq (@hf_feq) hx, add_comm x _]
refine le_trans (le_of_eq ?_) (f_add_nat_ge hf_conv @hf_feq ?_ hx)
· rw [f_nat_eq @hf_feq, Nat.add_sub_cancel, Nat.cast_add_one, add_sub_cancel_right]
· ring
· exact Nat.succ_ne_zero _
· omega
#align real.bohr_mollerup.ge_log_gamma_seq Real.BohrMollerup.ge_logGammaSeq
theorem tendsto_logGammaSeq_of_le_one (hf_conv : ConvexOn ℝ (Ioi 0) f)
(hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hx : 0 < x) (hx' : x ≤ 1) :
Tendsto (logGammaSeq x) atTop (𝓝 <| f x - f 1) := by
refine tendsto_of_tendsto_of_tendsto_of_le_of_le' (f := logGammaSeq x)
(g := fun n ↦ f x - f 1 - x * (log (n + 1) - log n)) ?_ tendsto_const_nhds ?_ ?_
· have : f x - f 1 = f x - f 1 - x * 0 := by ring
nth_rw 2 [this]
exact Tendsto.sub tendsto_const_nhds (tendsto_log_nat_add_one_sub_log.const_mul _)
· filter_upwards with n
rw [sub_le_iff_le_add', sub_le_iff_le_add']
convert le_logGammaSeq hf_conv (@hf_feq) hx hx' n using 1
ring
· show ∀ᶠ n : ℕ in atTop, logGammaSeq x n ≤ f x - f 1
filter_upwards [eventually_ne_atTop 0] with n hn using
le_sub_iff_add_le'.mpr (ge_logGammaSeq hf_conv hf_feq hx hn)
#align real.bohr_mollerup.tendsto_log_gamma_seq_of_le_one Real.BohrMollerup.tendsto_logGammaSeq_of_le_one
| Mathlib/Analysis/SpecialFunctions/Gamma/BohrMollerup.lean | 307 | 355 | theorem tendsto_logGammaSeq (hf_conv : ConvexOn ℝ (Ioi 0) f)
(hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hx : 0 < x) :
Tendsto (logGammaSeq x) atTop (𝓝 <| f x - f 1) := by |
suffices ∀ m : ℕ, ↑m < x → x ≤ m + 1 → Tendsto (logGammaSeq x) atTop (𝓝 <| f x - f 1) by
refine this ⌈x - 1⌉₊ ?_ ?_
· rcases lt_or_le x 1 with ⟨⟩
· rwa [Nat.ceil_eq_zero.mpr (by linarith : x - 1 ≤ 0), Nat.cast_zero]
· convert Nat.ceil_lt_add_one (by linarith : 0 ≤ x - 1)
abel
· rw [← sub_le_iff_le_add]; exact Nat.le_ceil _
intro m
induction' m with m hm generalizing x
· rw [Nat.cast_zero, zero_add]
exact fun _ hx' => tendsto_logGammaSeq_of_le_one hf_conv (@hf_feq) hx hx'
· intro hy hy'
rw [Nat.cast_succ, ← sub_le_iff_le_add] at hy'
rw [Nat.cast_succ, ← lt_sub_iff_add_lt] at hy
specialize hm ((Nat.cast_nonneg _).trans_lt hy) hy hy'
-- now massage gauss_product n (x - 1) into gauss_product (n - 1) x
have :
∀ᶠ n : ℕ in atTop,
logGammaSeq (x - 1) n =
logGammaSeq x (n - 1) + x * (log (↑(n - 1) + 1) - log ↑(n - 1)) - log (x - 1) := by
refine Eventually.mp (eventually_ge_atTop 1) (eventually_of_forall fun n hn => ?_)
have := logGammaSeq_add_one (x - 1) (n - 1)
rw [sub_add_cancel, Nat.sub_add_cancel hn] at this
rw [this]
ring
replace hm :=
((Tendsto.congr' this hm).add (tendsto_const_nhds : Tendsto (fun _ => log (x - 1)) _ _)).comp
(tendsto_add_atTop_nat 1)
have :
((fun x_1 : ℕ =>
(fun n : ℕ =>
logGammaSeq x (n - 1) + x * (log (↑(n - 1) + 1) - log ↑(n - 1)) - log (x - 1))
x_1 +
(fun b : ℕ => log (x - 1)) x_1) ∘
fun a : ℕ => a + 1) =
fun n => logGammaSeq x n + x * (log (↑n + 1) - log ↑n) := by
ext1 n
dsimp only [Function.comp_apply]
rw [sub_add_cancel, Nat.add_sub_cancel]
rw [this] at hm
convert hm.sub (tendsto_log_nat_add_one_sub_log.const_mul x) using 2
· ring
· have := hf_feq ((Nat.cast_nonneg m).trans_lt hy)
rw [sub_add_cancel] at this
rw [this]
ring
|
/-
Copyright (c) 2022 Moritz Firsching. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Firsching, Fabian Kruse, Nikolas Kuhn
-/
import Mathlib.Analysis.PSeries
import Mathlib.Data.Real.Pi.Wallis
import Mathlib.Tactic.AdaptationNote
#align_import analysis.special_functions.stirling from "leanprover-community/mathlib"@"2c1d8ca2812b64f88992a5294ea3dba144755cd1"
/-!
# Stirling's formula
This file proves Stirling's formula for the factorial.
It states that $n!$ grows asymptotically like $\sqrt{2\pi n}(\frac{n}{e})^n$.
## Proof outline
The proof follows: <https://proofwiki.org/wiki/Stirling%27s_Formula>.
We proceed in two parts.
**Part 1**: We consider the sequence $a_n$ of fractions $\frac{n!}{\sqrt{2n}(\frac{n}{e})^n}$
and prove that this sequence converges to a real, positive number $a$. For this the two main
ingredients are
- taking the logarithm of the sequence and
- using the series expansion of $\log(1 + x)$.
**Part 2**: We use the fact that the series defined in part 1 converges against a real number $a$
and prove that $a = \sqrt{\pi}$. Here the main ingredient is the convergence of Wallis' product
formula for `π`.
-/
open scoped Topology Real Nat Asymptotics
open Finset Filter Nat Real
namespace Stirling
/-!
### Part 1
https://proofwiki.org/wiki/Stirling%27s_Formula#Part_1
-/
/-- Define `stirlingSeq n` as $\frac{n!}{\sqrt{2n}(\frac{n}{e})^n}$.
Stirling's formula states that this sequence has limit $\sqrt(π)$.
-/
noncomputable def stirlingSeq (n : ℕ) : ℝ :=
n ! / (√(2 * n : ℝ) * (n / exp 1) ^ n)
#align stirling.stirling_seq Stirling.stirlingSeq
@[simp]
theorem stirlingSeq_zero : stirlingSeq 0 = 0 := by
rw [stirlingSeq, cast_zero, mul_zero, Real.sqrt_zero, zero_mul, div_zero]
#align stirling.stirling_seq_zero Stirling.stirlingSeq_zero
@[simp]
theorem stirlingSeq_one : stirlingSeq 1 = exp 1 / √2 := by
rw [stirlingSeq, pow_one, factorial_one, cast_one, mul_one, mul_one_div, one_div_div]
#align stirling.stirling_seq_one Stirling.stirlingSeq_one
theorem log_stirlingSeq_formula (n : ℕ) :
log (stirlingSeq n) = Real.log n ! - 1 / 2 * Real.log (2 * n) - n * log (n / exp 1) := by
cases n
· simp
· rw [stirlingSeq, log_div, log_mul, sqrt_eq_rpow, log_rpow, Real.log_pow, tsub_tsub]
<;> positivity
-- Porting note: generalized from `n.succ` to `n`
#align stirling.log_stirling_seq_formula Stirling.log_stirlingSeq_formulaₓ
/-- The sequence `log (stirlingSeq (m + 1)) - log (stirlingSeq (m + 2))` has the series expansion
`∑ 1 / (2 * (k + 1) + 1) * (1 / 2 * (m + 1) + 1)^(2 * (k + 1))`
-/
| Mathlib/Analysis/SpecialFunctions/Stirling.lean | 77 | 93 | theorem log_stirlingSeq_diff_hasSum (m : ℕ) :
HasSum (fun k : ℕ => (1 : ℝ) / (2 * ↑(k + 1) + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ ↑(k + 1))
(log (stirlingSeq (m + 1)) - log (stirlingSeq (m + 2))) := by |
let f (k : ℕ) := (1 : ℝ) / (2 * k + 1) * ((1 / (2 * ↑(m + 1) + 1)) ^ 2) ^ k
change HasSum (fun k => f (k + 1)) _
rw [hasSum_nat_add_iff]
convert (hasSum_log_one_add_inv m.cast_add_one_pos).mul_left ((↑(m + 1) : ℝ) + 1 / 2) using 1
· ext k
dsimp only [f]
rw [← pow_mul, pow_add]
push_cast
field_simp
ring
· have h : ∀ x ≠ (0 : ℝ), 1 + x⁻¹ = (x + 1) / x := fun x hx ↦ by field_simp [hx]
simp (disch := positivity) only [log_stirlingSeq_formula, log_div, log_mul, log_exp,
factorial_succ, cast_mul, cast_succ, cast_zero, range_one, sum_singleton, h]
ring
|
/-
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.Topology.Separation
import Mathlib.Topology.UniformSpace.Basic
import Mathlib.Topology.UniformSpace.Cauchy
#align_import topology.uniform_space.uniform_convergence from "leanprover-community/mathlib"@"2705404e701abc6b3127da906f40bae062a169c9"
/-!
# Uniform convergence
A sequence of functions `Fₙ` (with values in a metric space) converges uniformly on a set `s` to a
function `f` if, for all `ε > 0`, for all large enough `n`, one has for all `y ∈ s` the inequality
`dist (f y, Fₙ y) < ε`. Under uniform convergence, many properties of the `Fₙ` pass to the limit,
most notably continuity. We prove this in the file, defining the notion of uniform convergence
in the more general setting of uniform spaces, and with respect to an arbitrary indexing set
endowed with a filter (instead of just `ℕ` with `atTop`).
## Main results
Let `α` be a topological space, `β` a uniform space, `Fₙ` and `f` be functions from `α` to `β`
(where the index `n` belongs to an indexing type `ι` endowed with a filter `p`).
* `TendstoUniformlyOn F f p s`: the fact that `Fₙ` converges uniformly to `f` on `s`. This means
that, for any entourage `u` of the diagonal, for large enough `n` (with respect to `p`), one has
`(f y, Fₙ y) ∈ u` for all `y ∈ s`.
* `TendstoUniformly F f p`: same notion with `s = univ`.
* `TendstoUniformlyOn.continuousOn`: a uniform limit on a set of functions which are continuous
on this set is itself continuous on this set.
* `TendstoUniformly.continuous`: a uniform limit of continuous functions is continuous.
* `TendstoUniformlyOn.tendsto_comp`: If `Fₙ` tends uniformly to `f` on a set `s`, and `gₙ` tends
to `x` within `s`, then `Fₙ gₙ` tends to `f x` if `f` is continuous at `x` within `s`.
* `TendstoUniformly.tendsto_comp`: If `Fₙ` tends uniformly to `f`, and `gₙ` tends to `x`, then
`Fₙ gₙ` tends to `f x`.
We also define notions where the convergence is locally uniform, called
`TendstoLocallyUniformlyOn F f p s` and `TendstoLocallyUniformly F f p`. The previous theorems
all have corresponding versions under locally uniform convergence.
Finally, we introduce the notion of a uniform Cauchy sequence, which is to uniform
convergence what a Cauchy sequence is to the usual notion of convergence.
## Implementation notes
We derive most of our initial results from an auxiliary definition `TendstoUniformlyOnFilter`.
This definition in and of itself can sometimes be useful, e.g., when studying the local behavior
of the `Fₙ` near a point, which would typically look like `TendstoUniformlyOnFilter F f p (𝓝 x)`.
Still, while this may be the "correct" definition (see
`tendstoUniformlyOn_iff_tendstoUniformlyOnFilter`), it is somewhat unwieldy to work with in
practice. Thus, we provide the more traditional definition in `TendstoUniformlyOn`.
Most results hold under weaker assumptions of locally uniform approximation. In a first section,
we prove the results under these weaker assumptions. Then, we derive the results on uniform
convergence from them.
## Tags
Uniform limit, uniform convergence, tends uniformly to
-/
noncomputable section
open Topology Uniformity Filter Set
universe u v w x
variable {α : Type u} {β : Type v} {γ : Type w} {ι : Type x} [UniformSpace β]
variable {F : ι → α → β} {f : α → β} {s s' : Set α} {x : α} {p : Filter ι} {p' : Filter α}
{g : ι → α}
/-!
### Different notions of uniform convergence
We define uniform convergence and locally uniform convergence, on a set or in the whole space.
-/
/-- A sequence of functions `Fₙ` converges uniformly on a filter `p'` to a limiting function `f`
with respect to the filter `p` if, for any entourage of the diagonal `u`, one has
`p ×ˢ p'`-eventually `(f x, Fₙ x) ∈ u`. -/
def TendstoUniformlyOnFilter (F : ι → α → β) (f : α → β) (p : Filter ι) (p' : Filter α) :=
∀ u ∈ 𝓤 β, ∀ᶠ n : ι × α in p ×ˢ p', (f n.snd, F n.fst n.snd) ∈ u
#align tendsto_uniformly_on_filter TendstoUniformlyOnFilter
/--
A sequence of functions `Fₙ` converges uniformly on a filter `p'` to a limiting function `f` w.r.t.
filter `p` iff the function `(n, x) ↦ (f x, Fₙ x)` converges along `p ×ˢ p'` to the uniformity.
In other words: one knows nothing about the behavior of `x` in this limit besides it being in `p'`.
-/
theorem tendstoUniformlyOnFilter_iff_tendsto :
TendstoUniformlyOnFilter F f p p' ↔
Tendsto (fun q : ι × α => (f q.2, F q.1 q.2)) (p ×ˢ p') (𝓤 β) :=
Iff.rfl
#align tendsto_uniformly_on_filter_iff_tendsto tendstoUniformlyOnFilter_iff_tendsto
/-- A sequence of functions `Fₙ` converges uniformly on a set `s` to a limiting function `f` with
respect to the filter `p` if, for any entourage of the diagonal `u`, one has `p`-eventually
`(f x, Fₙ x) ∈ u` for all `x ∈ s`. -/
def TendstoUniformlyOn (F : ι → α → β) (f : α → β) (p : Filter ι) (s : Set α) :=
∀ u ∈ 𝓤 β, ∀ᶠ n in p, ∀ x : α, x ∈ s → (f x, F n x) ∈ u
#align tendsto_uniformly_on TendstoUniformlyOn
theorem tendstoUniformlyOn_iff_tendstoUniformlyOnFilter :
TendstoUniformlyOn F f p s ↔ TendstoUniformlyOnFilter F f p (𝓟 s) := by
simp only [TendstoUniformlyOn, TendstoUniformlyOnFilter]
apply forall₂_congr
simp_rw [eventually_prod_principal_iff]
simp
#align tendsto_uniformly_on_iff_tendsto_uniformly_on_filter tendstoUniformlyOn_iff_tendstoUniformlyOnFilter
alias ⟨TendstoUniformlyOn.tendstoUniformlyOnFilter, TendstoUniformlyOnFilter.tendstoUniformlyOn⟩ :=
tendstoUniformlyOn_iff_tendstoUniformlyOnFilter
#align tendsto_uniformly_on.tendsto_uniformly_on_filter TendstoUniformlyOn.tendstoUniformlyOnFilter
#align tendsto_uniformly_on_filter.tendsto_uniformly_on TendstoUniformlyOnFilter.tendstoUniformlyOn
/-- A sequence of functions `Fₙ` converges uniformly on a set `s` to a limiting function `f` w.r.t.
filter `p` iff the function `(n, x) ↦ (f x, Fₙ x)` converges along `p ×ˢ 𝓟 s` to the uniformity.
In other words: one knows nothing about the behavior of `x` in this limit besides it being in `s`.
-/
theorem tendstoUniformlyOn_iff_tendsto {F : ι → α → β} {f : α → β} {p : Filter ι} {s : Set α} :
TendstoUniformlyOn F f p s ↔
Tendsto (fun q : ι × α => (f q.2, F q.1 q.2)) (p ×ˢ 𝓟 s) (𝓤 β) := by
simp [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter, tendstoUniformlyOnFilter_iff_tendsto]
#align tendsto_uniformly_on_iff_tendsto tendstoUniformlyOn_iff_tendsto
/-- A sequence of functions `Fₙ` converges uniformly to a limiting function `f` with respect to a
filter `p` if, for any entourage of the diagonal `u`, one has `p`-eventually
`(f x, Fₙ x) ∈ u` for all `x`. -/
def TendstoUniformly (F : ι → α → β) (f : α → β) (p : Filter ι) :=
∀ u ∈ 𝓤 β, ∀ᶠ n in p, ∀ x : α, (f x, F n x) ∈ u
#align tendsto_uniformly TendstoUniformly
-- Porting note: moved from below
theorem tendstoUniformlyOn_univ : TendstoUniformlyOn F f p univ ↔ TendstoUniformly F f p := by
simp [TendstoUniformlyOn, TendstoUniformly]
#align tendsto_uniformly_on_univ tendstoUniformlyOn_univ
theorem tendstoUniformly_iff_tendstoUniformlyOnFilter :
TendstoUniformly F f p ↔ TendstoUniformlyOnFilter F f p ⊤ := by
rw [← tendstoUniformlyOn_univ, tendstoUniformlyOn_iff_tendstoUniformlyOnFilter, principal_univ]
#align tendsto_uniformly_iff_tendsto_uniformly_on_filter tendstoUniformly_iff_tendstoUniformlyOnFilter
theorem TendstoUniformly.tendstoUniformlyOnFilter (h : TendstoUniformly F f p) :
TendstoUniformlyOnFilter F f p ⊤ := by rwa [← tendstoUniformly_iff_tendstoUniformlyOnFilter]
#align tendsto_uniformly.tendsto_uniformly_on_filter TendstoUniformly.tendstoUniformlyOnFilter
theorem tendstoUniformlyOn_iff_tendstoUniformly_comp_coe :
TendstoUniformlyOn F f p s ↔ TendstoUniformly (fun i (x : s) => F i x) (f ∘ (↑)) p :=
forall₂_congr fun u _ => by simp
#align tendsto_uniformly_on_iff_tendsto_uniformly_comp_coe tendstoUniformlyOn_iff_tendstoUniformly_comp_coe
/-- A sequence of functions `Fₙ` converges uniformly to a limiting function `f` w.r.t.
filter `p` iff the function `(n, x) ↦ (f x, Fₙ x)` converges along `p ×ˢ ⊤` to the uniformity.
In other words: one knows nothing about the behavior of `x` in this limit.
-/
theorem tendstoUniformly_iff_tendsto {F : ι → α → β} {f : α → β} {p : Filter ι} :
TendstoUniformly F f p ↔ Tendsto (fun q : ι × α => (f q.2, F q.1 q.2)) (p ×ˢ ⊤) (𝓤 β) := by
simp [tendstoUniformly_iff_tendstoUniformlyOnFilter, tendstoUniformlyOnFilter_iff_tendsto]
#align tendsto_uniformly_iff_tendsto tendstoUniformly_iff_tendsto
/-- Uniform converence implies pointwise convergence. -/
theorem TendstoUniformlyOnFilter.tendsto_at (h : TendstoUniformlyOnFilter F f p p')
(hx : 𝓟 {x} ≤ p') : Tendsto (fun n => F n x) p <| 𝓝 (f x) := by
refine Uniform.tendsto_nhds_right.mpr fun u hu => mem_map.mpr ?_
filter_upwards [(h u hu).curry]
intro i h
simpa using h.filter_mono hx
#align tendsto_uniformly_on_filter.tendsto_at TendstoUniformlyOnFilter.tendsto_at
/-- Uniform converence implies pointwise convergence. -/
theorem TendstoUniformlyOn.tendsto_at (h : TendstoUniformlyOn F f p s) {x : α} (hx : x ∈ s) :
Tendsto (fun n => F n x) p <| 𝓝 (f x) :=
h.tendstoUniformlyOnFilter.tendsto_at
(le_principal_iff.mpr <| mem_principal.mpr <| singleton_subset_iff.mpr <| hx)
#align tendsto_uniformly_on.tendsto_at TendstoUniformlyOn.tendsto_at
/-- Uniform converence implies pointwise convergence. -/
theorem TendstoUniformly.tendsto_at (h : TendstoUniformly F f p) (x : α) :
Tendsto (fun n => F n x) p <| 𝓝 (f x) :=
h.tendstoUniformlyOnFilter.tendsto_at le_top
#align tendsto_uniformly.tendsto_at TendstoUniformly.tendsto_at
-- Porting note: tendstoUniformlyOn_univ moved up
theorem TendstoUniformlyOnFilter.mono_left {p'' : Filter ι} (h : TendstoUniformlyOnFilter F f p p')
(hp : p'' ≤ p) : TendstoUniformlyOnFilter F f p'' p' := fun u hu =>
(h u hu).filter_mono (p'.prod_mono_left hp)
#align tendsto_uniformly_on_filter.mono_left TendstoUniformlyOnFilter.mono_left
theorem TendstoUniformlyOnFilter.mono_right {p'' : Filter α} (h : TendstoUniformlyOnFilter F f p p')
(hp : p'' ≤ p') : TendstoUniformlyOnFilter F f p p'' := fun u hu =>
(h u hu).filter_mono (p.prod_mono_right hp)
#align tendsto_uniformly_on_filter.mono_right TendstoUniformlyOnFilter.mono_right
theorem TendstoUniformlyOn.mono {s' : Set α} (h : TendstoUniformlyOn F f p s) (h' : s' ⊆ s) :
TendstoUniformlyOn F f p s' :=
tendstoUniformlyOn_iff_tendstoUniformlyOnFilter.mpr
(h.tendstoUniformlyOnFilter.mono_right (le_principal_iff.mpr <| mem_principal.mpr h'))
#align tendsto_uniformly_on.mono TendstoUniformlyOn.mono
theorem TendstoUniformlyOnFilter.congr {F' : ι → α → β} (hf : TendstoUniformlyOnFilter F f p p')
(hff' : ∀ᶠ n : ι × α in p ×ˢ p', F n.fst n.snd = F' n.fst n.snd) :
TendstoUniformlyOnFilter F' f p p' := by
refine fun u hu => ((hf u hu).and hff').mono fun n h => ?_
rw [← h.right]
exact h.left
#align tendsto_uniformly_on_filter.congr TendstoUniformlyOnFilter.congr
theorem TendstoUniformlyOn.congr {F' : ι → α → β} (hf : TendstoUniformlyOn F f p s)
(hff' : ∀ᶠ n in p, Set.EqOn (F n) (F' n) s) : TendstoUniformlyOn F' f p s := by
rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter] at hf ⊢
refine hf.congr ?_
rw [eventually_iff] at hff' ⊢
simp only [Set.EqOn] at hff'
simp only [mem_prod_principal, hff', mem_setOf_eq]
#align tendsto_uniformly_on.congr TendstoUniformlyOn.congr
theorem TendstoUniformlyOn.congr_right {g : α → β} (hf : TendstoUniformlyOn F f p s)
(hfg : EqOn f g s) : TendstoUniformlyOn F g p s := fun u hu => by
filter_upwards [hf u hu] with i hi a ha using hfg ha ▸ hi a ha
#align tendsto_uniformly_on.congr_right TendstoUniformlyOn.congr_right
protected theorem TendstoUniformly.tendstoUniformlyOn (h : TendstoUniformly F f p) :
TendstoUniformlyOn F f p s :=
(tendstoUniformlyOn_univ.2 h).mono (subset_univ s)
#align tendsto_uniformly.tendsto_uniformly_on TendstoUniformly.tendstoUniformlyOn
/-- Composing on the right by a function preserves uniform convergence on a filter -/
theorem TendstoUniformlyOnFilter.comp (h : TendstoUniformlyOnFilter F f p p') (g : γ → α) :
TendstoUniformlyOnFilter (fun n => F n ∘ g) (f ∘ g) p (p'.comap g) := by
rw [tendstoUniformlyOnFilter_iff_tendsto] at h ⊢
exact h.comp (tendsto_id.prod_map tendsto_comap)
#align tendsto_uniformly_on_filter.comp TendstoUniformlyOnFilter.comp
/-- Composing on the right by a function preserves uniform convergence on a set -/
theorem TendstoUniformlyOn.comp (h : TendstoUniformlyOn F f p s) (g : γ → α) :
TendstoUniformlyOn (fun n => F n ∘ g) (f ∘ g) p (g ⁻¹' s) := by
rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter] at h ⊢
simpa [TendstoUniformlyOn, comap_principal] using TendstoUniformlyOnFilter.comp h g
#align tendsto_uniformly_on.comp TendstoUniformlyOn.comp
/-- Composing on the right by a function preserves uniform convergence -/
theorem TendstoUniformly.comp (h : TendstoUniformly F f p) (g : γ → α) :
TendstoUniformly (fun n => F n ∘ g) (f ∘ g) p := by
rw [tendstoUniformly_iff_tendstoUniformlyOnFilter] at h ⊢
simpa [principal_univ, comap_principal] using h.comp g
#align tendsto_uniformly.comp TendstoUniformly.comp
/-- Composing on the left by a uniformly continuous function preserves
uniform convergence on a filter -/
theorem UniformContinuous.comp_tendstoUniformlyOnFilter [UniformSpace γ] {g : β → γ}
(hg : UniformContinuous g) (h : TendstoUniformlyOnFilter F f p p') :
TendstoUniformlyOnFilter (fun i => g ∘ F i) (g ∘ f) p p' := fun _u hu => h _ (hg hu)
#align uniform_continuous.comp_tendsto_uniformly_on_filter UniformContinuous.comp_tendstoUniformlyOnFilter
/-- Composing on the left by a uniformly continuous function preserves
uniform convergence on a set -/
theorem UniformContinuous.comp_tendstoUniformlyOn [UniformSpace γ] {g : β → γ}
(hg : UniformContinuous g) (h : TendstoUniformlyOn F f p s) :
TendstoUniformlyOn (fun i => g ∘ F i) (g ∘ f) p s := fun _u hu => h _ (hg hu)
#align uniform_continuous.comp_tendsto_uniformly_on UniformContinuous.comp_tendstoUniformlyOn
/-- Composing on the left by a uniformly continuous function preserves uniform convergence -/
theorem UniformContinuous.comp_tendstoUniformly [UniformSpace γ] {g : β → γ}
(hg : UniformContinuous g) (h : TendstoUniformly F f p) :
TendstoUniformly (fun i => g ∘ F i) (g ∘ f) p := fun _u hu => h _ (hg hu)
#align uniform_continuous.comp_tendsto_uniformly UniformContinuous.comp_tendstoUniformly
theorem TendstoUniformlyOnFilter.prod_map {ι' α' β' : Type*} [UniformSpace β'] {F' : ι' → α' → β'}
{f' : α' → β'} {q : Filter ι'} {q' : Filter α'} (h : TendstoUniformlyOnFilter F f p p')
(h' : TendstoUniformlyOnFilter F' f' q q') :
TendstoUniformlyOnFilter (fun i : ι × ι' => Prod.map (F i.1) (F' i.2)) (Prod.map f f')
(p ×ˢ q) (p' ×ˢ q') := by
rw [tendstoUniformlyOnFilter_iff_tendsto] at h h' ⊢
rw [uniformity_prod_eq_comap_prod, tendsto_comap_iff, ← map_swap4_prod, tendsto_map'_iff]
convert h.prod_map h' -- seems to be faster than `exact` here
#align tendsto_uniformly_on_filter.prod_map TendstoUniformlyOnFilter.prod_map
theorem TendstoUniformlyOn.prod_map {ι' α' β' : Type*} [UniformSpace β'] {F' : ι' → α' → β'}
{f' : α' → β'} {p' : Filter ι'} {s' : Set α'} (h : TendstoUniformlyOn F f p s)
(h' : TendstoUniformlyOn F' f' p' s') :
TendstoUniformlyOn (fun i : ι × ι' => Prod.map (F i.1) (F' i.2)) (Prod.map f f') (p ×ˢ p')
(s ×ˢ s') := by
rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter] at h h' ⊢
simpa only [prod_principal_principal] using h.prod_map h'
#align tendsto_uniformly_on.prod_map TendstoUniformlyOn.prod_map
theorem TendstoUniformly.prod_map {ι' α' β' : Type*} [UniformSpace β'] {F' : ι' → α' → β'}
{f' : α' → β'} {p' : Filter ι'} (h : TendstoUniformly F f p) (h' : TendstoUniformly F' f' p') :
TendstoUniformly (fun i : ι × ι' => Prod.map (F i.1) (F' i.2)) (Prod.map f f') (p ×ˢ p') := by
rw [← tendstoUniformlyOn_univ, ← univ_prod_univ] at *
exact h.prod_map h'
#align tendsto_uniformly.prod_map TendstoUniformly.prod_map
theorem TendstoUniformlyOnFilter.prod {ι' β' : Type*} [UniformSpace β'] {F' : ι' → α → β'}
{f' : α → β'} {q : Filter ι'} (h : TendstoUniformlyOnFilter F f p p')
(h' : TendstoUniformlyOnFilter F' f' q p') :
TendstoUniformlyOnFilter (fun (i : ι × ι') a => (F i.1 a, F' i.2 a)) (fun a => (f a, f' a))
(p ×ˢ q) p' :=
fun u hu => ((h.prod_map h') u hu).diag_of_prod_right
#align tendsto_uniformly_on_filter.prod TendstoUniformlyOnFilter.prod
theorem TendstoUniformlyOn.prod {ι' β' : Type*} [UniformSpace β'] {F' : ι' → α → β'} {f' : α → β'}
{p' : Filter ι'} (h : TendstoUniformlyOn F f p s) (h' : TendstoUniformlyOn F' f' p' s) :
TendstoUniformlyOn (fun (i : ι × ι') a => (F i.1 a, F' i.2 a)) (fun a => (f a, f' a))
(p.prod p') s :=
(congr_arg _ s.inter_self).mp ((h.prod_map h').comp fun a => (a, a))
#align tendsto_uniformly_on.prod TendstoUniformlyOn.prod
theorem TendstoUniformly.prod {ι' β' : Type*} [UniformSpace β'] {F' : ι' → α → β'} {f' : α → β'}
{p' : Filter ι'} (h : TendstoUniformly F f p) (h' : TendstoUniformly F' f' p') :
TendstoUniformly (fun (i : ι × ι') a => (F i.1 a, F' i.2 a)) (fun a => (f a, f' a))
(p ×ˢ p') :=
(h.prod_map h').comp fun a => (a, a)
#align tendsto_uniformly.prod TendstoUniformly.prod
/-- Uniform convergence on a filter `p'` to a constant function is equivalent to convergence in
`p ×ˢ p'`. -/
theorem tendsto_prod_filter_iff {c : β} :
Tendsto (↿F) (p ×ˢ p') (𝓝 c) ↔ TendstoUniformlyOnFilter F (fun _ => c) p p' := by
simp_rw [nhds_eq_comap_uniformity, tendsto_comap_iff]
rfl
#align tendsto_prod_filter_iff tendsto_prod_filter_iff
/-- Uniform convergence on a set `s` to a constant function is equivalent to convergence in
`p ×ˢ 𝓟 s`. -/
theorem tendsto_prod_principal_iff {c : β} :
Tendsto (↿F) (p ×ˢ 𝓟 s) (𝓝 c) ↔ TendstoUniformlyOn F (fun _ => c) p s := by
rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter]
exact tendsto_prod_filter_iff
#align tendsto_prod_principal_iff tendsto_prod_principal_iff
/-- Uniform convergence to a constant function is equivalent to convergence in `p ×ˢ ⊤`. -/
theorem tendsto_prod_top_iff {c : β} :
Tendsto (↿F) (p ×ˢ ⊤) (𝓝 c) ↔ TendstoUniformly F (fun _ => c) p := by
rw [tendstoUniformly_iff_tendstoUniformlyOnFilter]
exact tendsto_prod_filter_iff
#align tendsto_prod_top_iff tendsto_prod_top_iff
/-- Uniform convergence on the empty set is vacuously true -/
theorem tendstoUniformlyOn_empty : TendstoUniformlyOn F f p ∅ := fun u _ => by simp
#align tendsto_uniformly_on_empty tendstoUniformlyOn_empty
/-- Uniform convergence on a singleton is equivalent to regular convergence -/
theorem tendstoUniformlyOn_singleton_iff_tendsto :
TendstoUniformlyOn F f p {x} ↔ Tendsto (fun n : ι => F n x) p (𝓝 (f x)) := by
simp_rw [tendstoUniformlyOn_iff_tendsto, Uniform.tendsto_nhds_right, tendsto_def]
exact forall₂_congr fun u _ => by simp [mem_prod_principal, preimage]
#align tendsto_uniformly_on_singleton_iff_tendsto tendstoUniformlyOn_singleton_iff_tendsto
/-- If a sequence `g` converges to some `b`, then the sequence of constant functions
`fun n ↦ fun a ↦ g n` converges to the constant function `fun a ↦ b` on any set `s` -/
theorem Filter.Tendsto.tendstoUniformlyOnFilter_const {g : ι → β} {b : β} (hg : Tendsto g p (𝓝 b))
(p' : Filter α) :
TendstoUniformlyOnFilter (fun n : ι => fun _ : α => g n) (fun _ : α => b) p p' := by
simpa only [nhds_eq_comap_uniformity, tendsto_comap_iff] using hg.comp (tendsto_fst (g := p'))
#align filter.tendsto.tendsto_uniformly_on_filter_const Filter.Tendsto.tendstoUniformlyOnFilter_const
/-- If a sequence `g` converges to some `b`, then the sequence of constant functions
`fun n ↦ fun a ↦ g n` converges to the constant function `fun a ↦ b` on any set `s` -/
theorem Filter.Tendsto.tendstoUniformlyOn_const {g : ι → β} {b : β} (hg : Tendsto g p (𝓝 b))
(s : Set α) : TendstoUniformlyOn (fun n : ι => fun _ : α => g n) (fun _ : α => b) p s :=
tendstoUniformlyOn_iff_tendstoUniformlyOnFilter.mpr (hg.tendstoUniformlyOnFilter_const (𝓟 s))
#align filter.tendsto.tendsto_uniformly_on_const Filter.Tendsto.tendstoUniformlyOn_const
-- Porting note (#10756): new lemma
theorem UniformContinuousOn.tendstoUniformlyOn [UniformSpace α] [UniformSpace γ] {x : α} {U : Set α}
{V : Set β} {F : α → β → γ} (hF : UniformContinuousOn (↿F) (U ×ˢ V)) (hU : x ∈ U) :
TendstoUniformlyOn F (F x) (𝓝[U] x) V := by
set φ := fun q : α × β => ((x, q.2), q)
rw [tendstoUniformlyOn_iff_tendsto]
change Tendsto (Prod.map (↿F) ↿F ∘ φ) (𝓝[U] x ×ˢ 𝓟 V) (𝓤 γ)
simp only [nhdsWithin, SProd.sprod, Filter.prod, comap_inf, inf_assoc, comap_principal,
inf_principal]
refine hF.comp (Tendsto.inf ?_ <| tendsto_principal_principal.2 fun x hx => ⟨⟨hU, hx.2⟩, hx⟩)
simp only [uniformity_prod_eq_comap_prod, tendsto_comap_iff, (· ∘ ·),
nhds_eq_comap_uniformity, comap_comap]
exact tendsto_comap.prod_mk (tendsto_diag_uniformity _ _)
theorem UniformContinuousOn.tendstoUniformly [UniformSpace α] [UniformSpace γ] {x : α} {U : Set α}
(hU : U ∈ 𝓝 x) {F : α → β → γ} (hF : UniformContinuousOn (↿F) (U ×ˢ (univ : Set β))) :
TendstoUniformly F (F x) (𝓝 x) := by
simpa only [tendstoUniformlyOn_univ, nhdsWithin_eq_nhds.2 hU]
using hF.tendstoUniformlyOn (mem_of_mem_nhds hU)
#align uniform_continuous_on.tendsto_uniformly UniformContinuousOn.tendstoUniformly
theorem UniformContinuous₂.tendstoUniformly [UniformSpace α] [UniformSpace γ] {f : α → β → γ}
(h : UniformContinuous₂ f) {x : α} : TendstoUniformly f (f x) (𝓝 x) :=
UniformContinuousOn.tendstoUniformly univ_mem <| by rwa [univ_prod_univ, uniformContinuousOn_univ]
#align uniform_continuous₂.tendsto_uniformly UniformContinuous₂.tendstoUniformly
/-- A sequence is uniformly Cauchy if eventually all of its pairwise differences are
uniformly bounded -/
def UniformCauchySeqOnFilter (F : ι → α → β) (p : Filter ι) (p' : Filter α) : Prop :=
∀ u ∈ 𝓤 β, ∀ᶠ m : (ι × ι) × α in (p ×ˢ p) ×ˢ p', (F m.fst.fst m.snd, F m.fst.snd m.snd) ∈ u
#align uniform_cauchy_seq_on_filter UniformCauchySeqOnFilter
/-- A sequence is uniformly Cauchy if eventually all of its pairwise differences are
uniformly bounded -/
def UniformCauchySeqOn (F : ι → α → β) (p : Filter ι) (s : Set α) : Prop :=
∀ u ∈ 𝓤 β, ∀ᶠ m : ι × ι in p ×ˢ p, ∀ x : α, x ∈ s → (F m.fst x, F m.snd x) ∈ u
#align uniform_cauchy_seq_on UniformCauchySeqOn
theorem uniformCauchySeqOn_iff_uniformCauchySeqOnFilter :
UniformCauchySeqOn F p s ↔ UniformCauchySeqOnFilter F p (𝓟 s) := by
simp only [UniformCauchySeqOn, UniformCauchySeqOnFilter]
refine forall₂_congr fun u hu => ?_
rw [eventually_prod_principal_iff]
#align uniform_cauchy_seq_on_iff_uniform_cauchy_seq_on_filter uniformCauchySeqOn_iff_uniformCauchySeqOnFilter
theorem UniformCauchySeqOn.uniformCauchySeqOnFilter (hF : UniformCauchySeqOn F p s) :
UniformCauchySeqOnFilter F p (𝓟 s) := by rwa [← uniformCauchySeqOn_iff_uniformCauchySeqOnFilter]
#align uniform_cauchy_seq_on.uniform_cauchy_seq_on_filter UniformCauchySeqOn.uniformCauchySeqOnFilter
/-- A sequence that converges uniformly is also uniformly Cauchy -/
theorem TendstoUniformlyOnFilter.uniformCauchySeqOnFilter (hF : TendstoUniformlyOnFilter F f p p') :
UniformCauchySeqOnFilter F p p' := by
intro u hu
rcases comp_symm_of_uniformity hu with ⟨t, ht, htsymm, htmem⟩
have := tendsto_swap4_prod.eventually ((hF t ht).prod_mk (hF t ht))
apply this.diag_of_prod_right.mono
simp only [and_imp, Prod.forall]
intro n1 n2 x hl hr
exact Set.mem_of_mem_of_subset (prod_mk_mem_compRel (htsymm hl) hr) htmem
#align tendsto_uniformly_on_filter.uniform_cauchy_seq_on_filter TendstoUniformlyOnFilter.uniformCauchySeqOnFilter
/-- A sequence that converges uniformly is also uniformly Cauchy -/
theorem TendstoUniformlyOn.uniformCauchySeqOn (hF : TendstoUniformlyOn F f p s) :
UniformCauchySeqOn F p s :=
uniformCauchySeqOn_iff_uniformCauchySeqOnFilter.mpr
hF.tendstoUniformlyOnFilter.uniformCauchySeqOnFilter
#align tendsto_uniformly_on.uniform_cauchy_seq_on TendstoUniformlyOn.uniformCauchySeqOn
/-- A uniformly Cauchy sequence converges uniformly to its limit -/
theorem UniformCauchySeqOnFilter.tendstoUniformlyOnFilter_of_tendsto [NeBot p]
(hF : UniformCauchySeqOnFilter F p p')
(hF' : ∀ᶠ x : α in p', Tendsto (fun n => F n x) p (𝓝 (f x))) :
TendstoUniformlyOnFilter F f p p' := by
-- Proof idea: |f_n(x) - f(x)| ≤ |f_n(x) - f_m(x)| + |f_m(x) - f(x)|. We choose `n`
-- so that |f_n(x) - f_m(x)| is uniformly small across `s` whenever `m ≥ n`. Then for
-- a fixed `x`, we choose `m` sufficiently large such that |f_m(x) - f(x)| is small.
intro u hu
rcases comp_symm_of_uniformity hu with ⟨t, ht, htsymm, htmem⟩
-- We will choose n, x, and m simultaneously. n and x come from hF. m comes from hF'
-- But we need to promote hF' to the full product filter to use it
have hmc : ∀ᶠ x in (p ×ˢ p) ×ˢ p', Tendsto (fun n : ι => F n x.snd) p (𝓝 (f x.snd)) := by
rw [eventually_prod_iff]
exact ⟨fun _ => True, by simp, _, hF', by simp⟩
-- To apply filter operations we'll need to do some order manipulation
rw [Filter.eventually_swap_iff]
have := tendsto_prodAssoc.eventually (tendsto_prod_swap.eventually ((hF t ht).and hmc))
apply this.curry.mono
simp only [Equiv.prodAssoc_apply, eventually_and, eventually_const, Prod.snd_swap, Prod.fst_swap,
and_imp, Prod.forall]
-- Complete the proof
intro x n hx hm'
refine Set.mem_of_mem_of_subset (mem_compRel.mpr ?_) htmem
rw [Uniform.tendsto_nhds_right] at hm'
have := hx.and (hm' ht)
obtain ⟨m, hm⟩ := this.exists
exact ⟨F m x, ⟨hm.2, htsymm hm.1⟩⟩
#align uniform_cauchy_seq_on_filter.tendsto_uniformly_on_filter_of_tendsto UniformCauchySeqOnFilter.tendstoUniformlyOnFilter_of_tendsto
/-- A uniformly Cauchy sequence converges uniformly to its limit -/
theorem UniformCauchySeqOn.tendstoUniformlyOn_of_tendsto [NeBot p] (hF : UniformCauchySeqOn F p s)
(hF' : ∀ x : α, x ∈ s → Tendsto (fun n => F n x) p (𝓝 (f x))) : TendstoUniformlyOn F f p s :=
tendstoUniformlyOn_iff_tendstoUniformlyOnFilter.mpr
(hF.uniformCauchySeqOnFilter.tendstoUniformlyOnFilter_of_tendsto hF')
#align uniform_cauchy_seq_on.tendsto_uniformly_on_of_tendsto UniformCauchySeqOn.tendstoUniformlyOn_of_tendsto
theorem UniformCauchySeqOnFilter.mono_left {p'' : Filter ι} (hf : UniformCauchySeqOnFilter F p p')
(hp : p'' ≤ p) : UniformCauchySeqOnFilter F p'' p' := by
intro u hu
have := (hf u hu).filter_mono (p'.prod_mono_left (Filter.prod_mono hp hp))
exact this.mono (by simp)
#align uniform_cauchy_seq_on_filter.mono_left UniformCauchySeqOnFilter.mono_left
theorem UniformCauchySeqOnFilter.mono_right {p'' : Filter α} (hf : UniformCauchySeqOnFilter F p p')
(hp : p'' ≤ p') : UniformCauchySeqOnFilter F p p'' := fun u hu =>
have := (hf u hu).filter_mono ((p ×ˢ p).prod_mono_right hp)
this.mono (by simp)
#align uniform_cauchy_seq_on_filter.mono_right UniformCauchySeqOnFilter.mono_right
theorem UniformCauchySeqOn.mono {s' : Set α} (hf : UniformCauchySeqOn F p s) (hss' : s' ⊆ s) :
UniformCauchySeqOn F p s' := by
rw [uniformCauchySeqOn_iff_uniformCauchySeqOnFilter] at hf ⊢
exact hf.mono_right (le_principal_iff.mpr <| mem_principal.mpr hss')
#align uniform_cauchy_seq_on.mono UniformCauchySeqOn.mono
/-- Composing on the right by a function preserves uniform Cauchy sequences -/
theorem UniformCauchySeqOnFilter.comp {γ : Type*} (hf : UniformCauchySeqOnFilter F p p')
(g : γ → α) : UniformCauchySeqOnFilter (fun n => F n ∘ g) p (p'.comap g) := fun u hu => by
obtain ⟨pa, hpa, pb, hpb, hpapb⟩ := eventually_prod_iff.mp (hf u hu)
rw [eventually_prod_iff]
refine ⟨pa, hpa, pb ∘ g, ?_, fun hx _ hy => hpapb hx hy⟩
exact eventually_comap.mpr (hpb.mono fun x hx y hy => by simp only [hx, hy, Function.comp_apply])
#align uniform_cauchy_seq_on_filter.comp UniformCauchySeqOnFilter.comp
/-- Composing on the right by a function preserves uniform Cauchy sequences -/
theorem UniformCauchySeqOn.comp {γ : Type*} (hf : UniformCauchySeqOn F p s) (g : γ → α) :
UniformCauchySeqOn (fun n => F n ∘ g) p (g ⁻¹' s) := by
rw [uniformCauchySeqOn_iff_uniformCauchySeqOnFilter] at hf ⊢
simpa only [UniformCauchySeqOn, comap_principal] using hf.comp g
#align uniform_cauchy_seq_on.comp UniformCauchySeqOn.comp
/-- Composing on the left by a uniformly continuous function preserves
uniform Cauchy sequences -/
theorem UniformContinuous.comp_uniformCauchySeqOn [UniformSpace γ] {g : β → γ}
(hg : UniformContinuous g) (hf : UniformCauchySeqOn F p s) :
UniformCauchySeqOn (fun n => g ∘ F n) p s := fun _u hu => hf _ (hg hu)
#align uniform_continuous.comp_uniform_cauchy_seq_on UniformContinuous.comp_uniformCauchySeqOn
theorem UniformCauchySeqOn.prod_map {ι' α' β' : Type*} [UniformSpace β'] {F' : ι' → α' → β'}
{p' : Filter ι'} {s' : Set α'} (h : UniformCauchySeqOn F p s)
(h' : UniformCauchySeqOn F' p' s') :
UniformCauchySeqOn (fun i : ι × ι' => Prod.map (F i.1) (F' i.2)) (p ×ˢ p') (s ×ˢ s') := by
intro u hu
rw [uniformity_prod_eq_prod, mem_map, mem_prod_iff] at hu
obtain ⟨v, hv, w, hw, hvw⟩ := hu
simp_rw [mem_prod, Prod.map_apply, and_imp, Prod.forall]
rw [← Set.image_subset_iff] at hvw
apply (tendsto_swap4_prod.eventually ((h v hv).prod_mk (h' w hw))).mono
intro x hx a b ha hb
exact hvw ⟨_, mk_mem_prod (hx.1 a ha) (hx.2 b hb), rfl⟩
#align uniform_cauchy_seq_on.prod_map UniformCauchySeqOn.prod_map
theorem UniformCauchySeqOn.prod {ι' β' : Type*} [UniformSpace β'] {F' : ι' → α → β'}
{p' : Filter ι'} (h : UniformCauchySeqOn F p s) (h' : UniformCauchySeqOn F' p' s) :
UniformCauchySeqOn (fun (i : ι × ι') a => (F i.fst a, F' i.snd a)) (p ×ˢ p') s :=
(congr_arg _ s.inter_self).mp ((h.prod_map h').comp fun a => (a, a))
#align uniform_cauchy_seq_on.prod UniformCauchySeqOn.prod
theorem UniformCauchySeqOn.prod' {β' : Type*} [UniformSpace β'] {F' : ι → α → β'}
(h : UniformCauchySeqOn F p s) (h' : UniformCauchySeqOn F' p s) :
UniformCauchySeqOn (fun (i : ι) a => (F i a, F' i a)) p s := fun u hu =>
have hh : Tendsto (fun x : ι => (x, x)) p (p ×ˢ p) := tendsto_diag
(hh.prod_map hh).eventually ((h.prod h') u hu)
#align uniform_cauchy_seq_on.prod' UniformCauchySeqOn.prod'
/-- If a sequence of functions is uniformly Cauchy on a set, then the values at each point form
a Cauchy sequence. -/
theorem UniformCauchySeqOn.cauchy_map [hp : NeBot p] (hf : UniformCauchySeqOn F p s) (hx : x ∈ s) :
Cauchy (map (fun i => F i x) p) := by
simp only [cauchy_map_iff, hp, true_and_iff]
intro u hu
rw [mem_map]
filter_upwards [hf u hu] with p hp using hp x hx
#align uniform_cauchy_seq_on.cauchy_map UniformCauchySeqOn.cauchy_map
/-- If a sequence of functions is uniformly Cauchy on a set, then the values at each point form
a Cauchy sequence. See `UniformCauchSeqOn.cauchy_map` for the non-`atTop` case. -/
theorem UniformCauchySeqOn.cauchySeq [Nonempty ι] [SemilatticeSup ι]
(hf : UniformCauchySeqOn F atTop s) (hx : x ∈ s) :
CauchySeq fun i ↦ F i x :=
hf.cauchy_map (hp := atTop_neBot) hx
section SeqTendsto
theorem tendstoUniformlyOn_of_seq_tendstoUniformlyOn {l : Filter ι} [l.IsCountablyGenerated]
(h : ∀ u : ℕ → ι, Tendsto u atTop l → TendstoUniformlyOn (fun n => F (u n)) f atTop s) :
TendstoUniformlyOn F f l s := by
rw [tendstoUniformlyOn_iff_tendsto, tendsto_iff_seq_tendsto]
intro u hu
rw [tendsto_prod_iff'] at hu
specialize h (fun n => (u n).fst) hu.1
rw [tendstoUniformlyOn_iff_tendsto] at h
exact h.comp (tendsto_id.prod_mk hu.2)
#align tendsto_uniformly_on_of_seq_tendsto_uniformly_on tendstoUniformlyOn_of_seq_tendstoUniformlyOn
theorem TendstoUniformlyOn.seq_tendstoUniformlyOn {l : Filter ι} (h : TendstoUniformlyOn F f l s)
(u : ℕ → ι) (hu : Tendsto u atTop l) : TendstoUniformlyOn (fun n => F (u n)) f atTop s := by
rw [tendstoUniformlyOn_iff_tendsto] at h ⊢
exact h.comp ((hu.comp tendsto_fst).prod_mk tendsto_snd)
#align tendsto_uniformly_on.seq_tendsto_uniformly_on TendstoUniformlyOn.seq_tendstoUniformlyOn
theorem tendstoUniformlyOn_iff_seq_tendstoUniformlyOn {l : Filter ι} [l.IsCountablyGenerated] :
TendstoUniformlyOn F f l s ↔
∀ u : ℕ → ι, Tendsto u atTop l → TendstoUniformlyOn (fun n => F (u n)) f atTop s :=
⟨TendstoUniformlyOn.seq_tendstoUniformlyOn, tendstoUniformlyOn_of_seq_tendstoUniformlyOn⟩
#align tendsto_uniformly_on_iff_seq_tendsto_uniformly_on tendstoUniformlyOn_iff_seq_tendstoUniformlyOn
theorem tendstoUniformly_iff_seq_tendstoUniformly {l : Filter ι} [l.IsCountablyGenerated] :
TendstoUniformly F f l ↔
∀ u : ℕ → ι, Tendsto u atTop l → TendstoUniformly (fun n => F (u n)) f atTop := by
simp_rw [← tendstoUniformlyOn_univ]
exact tendstoUniformlyOn_iff_seq_tendstoUniformlyOn
#align tendsto_uniformly_iff_seq_tendsto_uniformly tendstoUniformly_iff_seq_tendstoUniformly
end SeqTendsto
variable [TopologicalSpace α]
/-- A sequence of functions `Fₙ` converges locally uniformly on a set `s` to a limiting function
`f` with respect to a filter `p` if, for any entourage of the diagonal `u`, for any `x ∈ s`, one
has `p`-eventually `(f y, Fₙ y) ∈ u` for all `y` in a neighborhood of `x` in `s`. -/
def TendstoLocallyUniformlyOn (F : ι → α → β) (f : α → β) (p : Filter ι) (s : Set α) :=
∀ u ∈ 𝓤 β, ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, ∀ᶠ n in p, ∀ y ∈ t, (f y, F n y) ∈ u
#align tendsto_locally_uniformly_on TendstoLocallyUniformlyOn
/-- A sequence of functions `Fₙ` converges locally uniformly to a limiting function `f` with respect
to a filter `p` if, for any entourage of the diagonal `u`, for any `x`, one has `p`-eventually
`(f y, Fₙ y) ∈ u` for all `y` in a neighborhood of `x`. -/
def TendstoLocallyUniformly (F : ι → α → β) (f : α → β) (p : Filter ι) :=
∀ u ∈ 𝓤 β, ∀ x : α, ∃ t ∈ 𝓝 x, ∀ᶠ n in p, ∀ y ∈ t, (f y, F n y) ∈ u
#align tendsto_locally_uniformly TendstoLocallyUniformly
theorem tendstoLocallyUniformlyOn_univ :
TendstoLocallyUniformlyOn F f p univ ↔ TendstoLocallyUniformly F f p := by
simp [TendstoLocallyUniformlyOn, TendstoLocallyUniformly, nhdsWithin_univ]
#align tendsto_locally_uniformly_on_univ tendstoLocallyUniformlyOn_univ
-- Porting note (#10756): new lemma
theorem tendstoLocallyUniformlyOn_iff_forall_tendsto :
TendstoLocallyUniformlyOn F f p s ↔
∀ x ∈ s, Tendsto (fun y : ι × α => (f y.2, F y.1 y.2)) (p ×ˢ 𝓝[s] x) (𝓤 β) :=
forall₂_swap.trans <| forall₄_congr fun _ _ _ _ => by
rw [mem_map, mem_prod_iff_right]; rfl
nonrec theorem IsOpen.tendstoLocallyUniformlyOn_iff_forall_tendsto (hs : IsOpen s) :
TendstoLocallyUniformlyOn F f p s ↔
∀ x ∈ s, Tendsto (fun y : ι × α => (f y.2, F y.1 y.2)) (p ×ˢ 𝓝 x) (𝓤 β) :=
tendstoLocallyUniformlyOn_iff_forall_tendsto.trans <| forall₂_congr fun x hx => by
rw [hs.nhdsWithin_eq hx]
theorem tendstoLocallyUniformly_iff_forall_tendsto :
TendstoLocallyUniformly F f p ↔
∀ x, Tendsto (fun y : ι × α => (f y.2, F y.1 y.2)) (p ×ˢ 𝓝 x) (𝓤 β) := by
simp [← tendstoLocallyUniformlyOn_univ, isOpen_univ.tendstoLocallyUniformlyOn_iff_forall_tendsto]
#align tendsto_locally_uniformly_iff_forall_tendsto tendstoLocallyUniformly_iff_forall_tendsto
theorem tendstoLocallyUniformlyOn_iff_tendstoLocallyUniformly_comp_coe :
TendstoLocallyUniformlyOn F f p s ↔
TendstoLocallyUniformly (fun i (x : s) => F i x) (f ∘ (↑)) p := by
simp only [tendstoLocallyUniformly_iff_forall_tendsto, Subtype.forall', tendsto_map'_iff,
tendstoLocallyUniformlyOn_iff_forall_tendsto, ← map_nhds_subtype_val, prod_map_right]; rfl
#align tendsto_locally_uniformly_on_iff_tendsto_locally_uniformly_comp_coe tendstoLocallyUniformlyOn_iff_tendstoLocallyUniformly_comp_coe
protected theorem TendstoUniformlyOn.tendstoLocallyUniformlyOn (h : TendstoUniformlyOn F f p s) :
TendstoLocallyUniformlyOn F f p s := fun u hu x _ =>
⟨s, self_mem_nhdsWithin, by simpa using h u hu⟩
#align tendsto_uniformly_on.tendsto_locally_uniformly_on TendstoUniformlyOn.tendstoLocallyUniformlyOn
protected theorem TendstoUniformly.tendstoLocallyUniformly (h : TendstoUniformly F f p) :
TendstoLocallyUniformly F f p := fun u hu x => ⟨univ, univ_mem, by simpa using h u hu⟩
#align tendsto_uniformly.tendsto_locally_uniformly TendstoUniformly.tendstoLocallyUniformly
theorem TendstoLocallyUniformlyOn.mono (h : TendstoLocallyUniformlyOn F f p s) (h' : s' ⊆ s) :
TendstoLocallyUniformlyOn F f p s' := by
intro u hu x hx
rcases h u hu x (h' hx) with ⟨t, ht, H⟩
exact ⟨t, nhdsWithin_mono x h' ht, H.mono fun n => id⟩
#align tendsto_locally_uniformly_on.mono TendstoLocallyUniformlyOn.mono
-- Porting note: generalized from `Type` to `Sort`
theorem tendstoLocallyUniformlyOn_iUnion {ι' : Sort*} {S : ι' → Set α} (hS : ∀ i, IsOpen (S i))
(h : ∀ i, TendstoLocallyUniformlyOn F f p (S i)) :
TendstoLocallyUniformlyOn F f p (⋃ i, S i) :=
(isOpen_iUnion hS).tendstoLocallyUniformlyOn_iff_forall_tendsto.2 fun _x hx =>
let ⟨i, hi⟩ := mem_iUnion.1 hx
(hS i).tendstoLocallyUniformlyOn_iff_forall_tendsto.1 (h i) _ hi
#align tendsto_locally_uniformly_on_Union tendstoLocallyUniformlyOn_iUnion
theorem tendstoLocallyUniformlyOn_biUnion {s : Set γ} {S : γ → Set α} (hS : ∀ i ∈ s, IsOpen (S i))
(h : ∀ i ∈ s, TendstoLocallyUniformlyOn F f p (S i)) :
TendstoLocallyUniformlyOn F f p (⋃ i ∈ s, S i) :=
tendstoLocallyUniformlyOn_iUnion (fun i => isOpen_iUnion (hS i)) fun i =>
tendstoLocallyUniformlyOn_iUnion (hS i) (h i)
#align tendsto_locally_uniformly_on_bUnion tendstoLocallyUniformlyOn_biUnion
theorem tendstoLocallyUniformlyOn_sUnion (S : Set (Set α)) (hS : ∀ s ∈ S, IsOpen s)
(h : ∀ s ∈ S, TendstoLocallyUniformlyOn F f p s) : TendstoLocallyUniformlyOn F f p (⋃₀ S) := by
rw [sUnion_eq_biUnion]
exact tendstoLocallyUniformlyOn_biUnion hS h
#align tendsto_locally_uniformly_on_sUnion tendstoLocallyUniformlyOn_sUnion
theorem TendstoLocallyUniformlyOn.union {s₁ s₂ : Set α} (hs₁ : IsOpen s₁) (hs₂ : IsOpen s₂)
(h₁ : TendstoLocallyUniformlyOn F f p s₁) (h₂ : TendstoLocallyUniformlyOn F f p s₂) :
TendstoLocallyUniformlyOn F f p (s₁ ∪ s₂) := by
rw [← sUnion_pair]
refine tendstoLocallyUniformlyOn_sUnion _ ?_ ?_ <;> simp [*]
#align tendsto_locally_uniformly_on.union TendstoLocallyUniformlyOn.union
-- Porting note: tendstoLocallyUniformlyOn_univ moved up
protected theorem TendstoLocallyUniformly.tendstoLocallyUniformlyOn
(h : TendstoLocallyUniformly F f p) : TendstoLocallyUniformlyOn F f p s :=
(tendstoLocallyUniformlyOn_univ.mpr h).mono (subset_univ _)
#align tendsto_locally_uniformly.tendsto_locally_uniformly_on TendstoLocallyUniformly.tendstoLocallyUniformlyOn
/-- On a compact space, locally uniform convergence is just uniform convergence. -/
| Mathlib/Topology/UniformSpace/UniformConvergence.lean | 695 | 706 | theorem tendstoLocallyUniformly_iff_tendstoUniformly_of_compactSpace [CompactSpace α] :
TendstoLocallyUniformly F f p ↔ TendstoUniformly F f p := by |
refine ⟨fun h V hV => ?_, TendstoUniformly.tendstoLocallyUniformly⟩
choose U hU using h V hV
obtain ⟨t, ht⟩ := isCompact_univ.elim_nhds_subcover' (fun k _ => U k) fun k _ => (hU k).1
replace hU := fun x : t => (hU x).2
rw [← eventually_all] at hU
refine hU.mono fun i hi x => ?_
specialize ht (mem_univ x)
simp only [exists_prop, mem_iUnion, SetCoe.exists, exists_and_right, Subtype.coe_mk] at ht
obtain ⟨y, ⟨hy₁, hy₂⟩, hy₃⟩ := ht
exact hi ⟨⟨y, hy₁⟩, hy₂⟩ x hy₃
|
/-
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.Eval
#align_import data.polynomial.degree.lemmas from "leanprover-community/mathlib"@"728baa2f54e6062c5879a3e397ac6bac323e506f"
/-!
# Theory of degrees of polynomials
Some of the main results include
- `natDegree_comp_le` : The degree of the composition is at most the product of degrees
-/
noncomputable section
open Polynomial
open Finsupp Finset
namespace Polynomial
universe u v w
variable {R : Type u} {S : Type v} {ι : Type w} {a b : R} {m n : ℕ}
section Semiring
variable [Semiring R] {p q r : R[X]}
section Degree
theorem natDegree_comp_le : natDegree (p.comp q) ≤ natDegree p * natDegree q :=
letI := Classical.decEq R
if h0 : p.comp q = 0 then by rw [h0, natDegree_zero]; exact Nat.zero_le _
else
WithBot.coe_le_coe.1 <|
calc
↑(natDegree (p.comp q)) = degree (p.comp q) := (degree_eq_natDegree h0).symm
_ = _ := congr_arg degree comp_eq_sum_left
_ ≤ _ := degree_sum_le _ _
_ ≤ _ :=
Finset.sup_le fun n hn =>
calc
degree (C (coeff p n) * q ^ n) ≤ degree (C (coeff p n)) + degree (q ^ n) :=
degree_mul_le _ _
_ ≤ natDegree (C (coeff p n)) + n • degree q :=
(add_le_add degree_le_natDegree (degree_pow_le _ _))
_ ≤ natDegree (C (coeff p n)) + n • ↑(natDegree q) :=
(add_le_add_left (nsmul_le_nsmul_right (@degree_le_natDegree _ _ q) n) _)
_ = (n * natDegree q : ℕ) := by
rw [natDegree_C, Nat.cast_zero, zero_add, nsmul_eq_mul];
simp
_ ≤ (natDegree p * natDegree q : ℕ) :=
WithBot.coe_le_coe.2 <|
mul_le_mul_of_nonneg_right (le_natDegree_of_ne_zero (mem_support_iff.1 hn))
(Nat.zero_le _)
#align polynomial.nat_degree_comp_le Polynomial.natDegree_comp_le
theorem degree_pos_of_root {p : R[X]} (hp : p ≠ 0) (h : IsRoot p a) : 0 < degree p :=
lt_of_not_ge fun hlt => by
have := eq_C_of_degree_le_zero hlt
rw [IsRoot, this, eval_C] at h
simp only [h, RingHom.map_zero] at this
exact hp this
#align polynomial.degree_pos_of_root Polynomial.degree_pos_of_root
theorem natDegree_le_iff_coeff_eq_zero : p.natDegree ≤ n ↔ ∀ N : ℕ, n < N → p.coeff N = 0 := by
simp_rw [natDegree_le_iff_degree_le, degree_le_iff_coeff_zero, Nat.cast_lt]
#align polynomial.nat_degree_le_iff_coeff_eq_zero Polynomial.natDegree_le_iff_coeff_eq_zero
theorem natDegree_add_le_iff_left {n : ℕ} (p q : R[X]) (qn : q.natDegree ≤ n) :
(p + q).natDegree ≤ n ↔ p.natDegree ≤ n := by
refine ⟨fun h => ?_, fun h => natDegree_add_le_of_degree_le h qn⟩
refine natDegree_le_iff_coeff_eq_zero.mpr fun m hm => ?_
convert natDegree_le_iff_coeff_eq_zero.mp h m hm using 1
rw [coeff_add, natDegree_le_iff_coeff_eq_zero.mp qn _ hm, add_zero]
#align polynomial.nat_degree_add_le_iff_left Polynomial.natDegree_add_le_iff_left
theorem natDegree_add_le_iff_right {n : ℕ} (p q : R[X]) (pn : p.natDegree ≤ n) :
(p + q).natDegree ≤ n ↔ q.natDegree ≤ n := by
rw [add_comm]
exact natDegree_add_le_iff_left _ _ pn
#align polynomial.nat_degree_add_le_iff_right Polynomial.natDegree_add_le_iff_right
theorem natDegree_C_mul_le (a : R) (f : R[X]) : (C a * f).natDegree ≤ f.natDegree :=
calc
(C a * f).natDegree ≤ (C a).natDegree + f.natDegree := natDegree_mul_le
_ = 0 + f.natDegree := by rw [natDegree_C a]
_ = f.natDegree := zero_add _
set_option linter.uppercaseLean3 false in
#align polynomial.nat_degree_C_mul_le Polynomial.natDegree_C_mul_le
theorem natDegree_mul_C_le (f : R[X]) (a : R) : (f * C a).natDegree ≤ f.natDegree :=
calc
(f * C a).natDegree ≤ f.natDegree + (C a).natDegree := natDegree_mul_le
_ = f.natDegree + 0 := by rw [natDegree_C a]
_ = f.natDegree := add_zero _
set_option linter.uppercaseLean3 false in
#align polynomial.nat_degree_mul_C_le Polynomial.natDegree_mul_C_le
theorem eq_natDegree_of_le_mem_support (pn : p.natDegree ≤ n) (ns : n ∈ p.support) :
p.natDegree = n :=
le_antisymm pn (le_natDegree_of_mem_supp _ ns)
#align polynomial.eq_nat_degree_of_le_mem_support Polynomial.eq_natDegree_of_le_mem_support
theorem natDegree_C_mul_eq_of_mul_eq_one {ai : R} (au : ai * a = 1) :
(C a * p).natDegree = p.natDegree :=
le_antisymm (natDegree_C_mul_le a p)
(calc
p.natDegree = (1 * p).natDegree := by nth_rw 1 [← one_mul p]
_ = (C ai * (C a * p)).natDegree := by rw [← C_1, ← au, RingHom.map_mul, ← mul_assoc]
_ ≤ (C a * p).natDegree := natDegree_C_mul_le ai (C a * p))
set_option linter.uppercaseLean3 false in
#align polynomial.nat_degree_C_mul_eq_of_mul_eq_one Polynomial.natDegree_C_mul_eq_of_mul_eq_one
theorem natDegree_mul_C_eq_of_mul_eq_one {ai : R} (au : a * ai = 1) :
(p * C a).natDegree = p.natDegree :=
le_antisymm (natDegree_mul_C_le p a)
(calc
p.natDegree = (p * 1).natDegree := by nth_rw 1 [← mul_one p]
_ = (p * C a * C ai).natDegree := by rw [← C_1, ← au, RingHom.map_mul, ← mul_assoc]
_ ≤ (p * C a).natDegree := natDegree_mul_C_le (p * C a) ai)
set_option linter.uppercaseLean3 false in
#align polynomial.nat_degree_mul_C_eq_of_mul_eq_one Polynomial.natDegree_mul_C_eq_of_mul_eq_one
/-- Although not explicitly stated, the assumptions of lemma `nat_degree_mul_C_eq_of_mul_ne_zero`
force the polynomial `p` to be non-zero, via `p.leading_coeff ≠ 0`.
-/
theorem natDegree_mul_C_eq_of_mul_ne_zero (h : p.leadingCoeff * a ≠ 0) :
(p * C a).natDegree = p.natDegree := by
refine eq_natDegree_of_le_mem_support (natDegree_mul_C_le p a) ?_
refine mem_support_iff.mpr ?_
rwa [coeff_mul_C]
set_option linter.uppercaseLean3 false in
#align polynomial.nat_degree_mul_C_eq_of_mul_ne_zero Polynomial.natDegree_mul_C_eq_of_mul_ne_zero
/-- Although not explicitly stated, the assumptions of lemma `nat_degree_C_mul_eq_of_mul_ne_zero`
force the polynomial `p` to be non-zero, via `p.leading_coeff ≠ 0`.
-/
theorem natDegree_C_mul_eq_of_mul_ne_zero (h : a * p.leadingCoeff ≠ 0) :
(C a * p).natDegree = p.natDegree := by
refine eq_natDegree_of_le_mem_support (natDegree_C_mul_le a p) ?_
refine mem_support_iff.mpr ?_
rwa [coeff_C_mul]
set_option linter.uppercaseLean3 false in
#align polynomial.nat_degree_C_mul_eq_of_mul_ne_zero Polynomial.natDegree_C_mul_eq_of_mul_ne_zero
theorem natDegree_add_coeff_mul (f g : R[X]) :
(f * g).coeff (f.natDegree + g.natDegree) = f.coeff f.natDegree * g.coeff g.natDegree := by
simp only [coeff_natDegree, coeff_mul_degree_add_degree]
#align polynomial.nat_degree_add_coeff_mul Polynomial.natDegree_add_coeff_mul
theorem natDegree_lt_coeff_mul (h : p.natDegree + q.natDegree < m + n) :
(p * q).coeff (m + n) = 0 :=
coeff_eq_zero_of_natDegree_lt (natDegree_mul_le.trans_lt h)
#align polynomial.nat_degree_lt_coeff_mul Polynomial.natDegree_lt_coeff_mul
theorem coeff_mul_of_natDegree_le (pm : p.natDegree ≤ m) (qn : q.natDegree ≤ n) :
(p * q).coeff (m + n) = p.coeff m * q.coeff n := by
simp_rw [← Polynomial.toFinsupp_apply, toFinsupp_mul]
refine AddMonoidAlgebra.apply_add_of_supDegree_le ?_ Function.injective_id ?_ ?_
· simp
· rwa [supDegree_eq_natDegree, id_eq]
· rwa [supDegree_eq_natDegree, id_eq]
#align polynomial.coeff_mul_of_nat_degree_le Polynomial.coeff_mul_of_natDegree_le
theorem coeff_pow_of_natDegree_le (pn : p.natDegree ≤ n) :
(p ^ m).coeff (m * n) = p.coeff n ^ m := by
induction' m with m hm
· simp
· rw [pow_succ, pow_succ, ← hm, Nat.succ_mul, coeff_mul_of_natDegree_le _ pn]
refine natDegree_pow_le.trans (le_trans ?_ (le_refl _))
exact mul_le_mul_of_nonneg_left pn m.zero_le
#align polynomial.coeff_pow_of_nat_degree_le Polynomial.coeff_pow_of_natDegree_le
theorem coeff_pow_eq_ite_of_natDegree_le_of_le {o : ℕ}
(pn : natDegree p ≤ n) (mno : m * n ≤ o) :
coeff (p ^ m) o = if o = m * n then (coeff p n) ^ m else 0 := by
rcases eq_or_ne o (m * n) with rfl | h
· simpa only [ite_true] using coeff_pow_of_natDegree_le pn
· simpa only [h, ite_false] using coeff_eq_zero_of_natDegree_lt <|
lt_of_le_of_lt (natDegree_pow_le_of_le m pn) (lt_of_le_of_ne mno h.symm)
theorem coeff_add_eq_left_of_lt (qn : q.natDegree < n) : (p + q).coeff n = p.coeff n :=
(coeff_add _ _ _).trans <|
(congr_arg _ <| coeff_eq_zero_of_natDegree_lt <| qn).trans <| add_zero _
#align polynomial.coeff_add_eq_left_of_lt Polynomial.coeff_add_eq_left_of_lt
theorem coeff_add_eq_right_of_lt (pn : p.natDegree < n) : (p + q).coeff n = q.coeff n := by
rw [add_comm]
exact coeff_add_eq_left_of_lt pn
#align polynomial.coeff_add_eq_right_of_lt Polynomial.coeff_add_eq_right_of_lt
theorem degree_sum_eq_of_disjoint (f : S → R[X]) (s : Finset S)
(h : Set.Pairwise { i | i ∈ s ∧ f i ≠ 0 } (Ne on degree ∘ f)) :
degree (s.sum f) = s.sup fun i => degree (f i) := by
classical
induction' s using Finset.induction_on with x s hx IH
· simp
· simp only [hx, Finset.sum_insert, not_false_iff, Finset.sup_insert]
specialize IH (h.mono fun _ => by simp (config := { contextual := true }))
rcases lt_trichotomy (degree (f x)) (degree (s.sum f)) with (H | H | H)
· rw [← IH, sup_eq_right.mpr H.le, degree_add_eq_right_of_degree_lt H]
· rcases s.eq_empty_or_nonempty with (rfl | hs)
· simp
obtain ⟨y, hy, hy'⟩ := Finset.exists_mem_eq_sup s hs fun i => degree (f i)
rw [IH, hy'] at H
by_cases hx0 : f x = 0
· simp [hx0, IH]
have hy0 : f y ≠ 0 := by
contrapose! H
simpa [H, degree_eq_bot] using hx0
refine absurd H (h ?_ ?_ fun H => hx ?_)
· simp [hx0]
· simp [hy, hy0]
· exact H.symm ▸ hy
· rw [← IH, sup_eq_left.mpr H.le, degree_add_eq_left_of_degree_lt H]
#align polynomial.degree_sum_eq_of_disjoint Polynomial.degree_sum_eq_of_disjoint
theorem natDegree_sum_eq_of_disjoint (f : S → R[X]) (s : Finset S)
(h : Set.Pairwise { i | i ∈ s ∧ f i ≠ 0 } (Ne on natDegree ∘ f)) :
natDegree (s.sum f) = s.sup fun i => natDegree (f i) := by
by_cases H : ∃ x ∈ s, f x ≠ 0
· obtain ⟨x, hx, hx'⟩ := H
have hs : s.Nonempty := ⟨x, hx⟩
refine natDegree_eq_of_degree_eq_some ?_
rw [degree_sum_eq_of_disjoint]
· rw [← Finset.sup'_eq_sup hs, ← Finset.sup'_eq_sup hs,
Nat.cast_withBot, Finset.coe_sup' hs, ←
Finset.sup'_eq_sup hs]
refine le_antisymm ?_ ?_
· rw [Finset.sup'_le_iff]
intro b hb
by_cases hb' : f b = 0
· simpa [hb'] using hs
rw [degree_eq_natDegree hb', Nat.cast_withBot]
exact Finset.le_sup' (fun i : S => (natDegree (f i) : WithBot ℕ)) hb
· rw [Finset.sup'_le_iff]
intro b hb
simp only [Finset.le_sup'_iff, exists_prop, Function.comp_apply]
by_cases hb' : f b = 0
· refine ⟨x, hx, ?_⟩
contrapose! hx'
simpa [← Nat.cast_withBot, hb', degree_eq_bot] using hx'
exact ⟨b, hb, (degree_eq_natDegree hb').ge⟩
· exact h.imp fun x y hxy hxy' => hxy (natDegree_eq_of_degree_eq hxy')
· push_neg at H
rw [Finset.sum_eq_zero H, natDegree_zero, eq_comm, show 0 = ⊥ from rfl, Finset.sup_eq_bot_iff]
intro x hx
simp [H x hx]
#align polynomial.nat_degree_sum_eq_of_disjoint Polynomial.natDegree_sum_eq_of_disjoint
set_option linter.deprecated false in
theorem natDegree_bit0 (a : R[X]) : (bit0 a).natDegree ≤ a.natDegree :=
(natDegree_add_le _ _).trans (max_self _).le
#align polynomial.nat_degree_bit0 Polynomial.natDegree_bit0
set_option linter.deprecated false in
theorem natDegree_bit1 (a : R[X]) : (bit1 a).natDegree ≤ a.natDegree :=
(natDegree_add_le _ _).trans (by simp [natDegree_bit0])
#align polynomial.nat_degree_bit1 Polynomial.natDegree_bit1
variable [Semiring S]
theorem natDegree_pos_of_eval₂_root {p : R[X]} (hp : p ≠ 0) (f : R →+* S) {z : S}
(hz : eval₂ f z p = 0) (inj : ∀ x : R, f x = 0 → x = 0) : 0 < natDegree p :=
lt_of_not_ge fun hlt => by
have A : p = C (p.coeff 0) := eq_C_of_natDegree_le_zero hlt
rw [A, eval₂_C] at hz
simp only [inj (p.coeff 0) hz, RingHom.map_zero] at A
exact hp A
#align polynomial.nat_degree_pos_of_eval₂_root Polynomial.natDegree_pos_of_eval₂_root
theorem degree_pos_of_eval₂_root {p : R[X]} (hp : p ≠ 0) (f : R →+* S) {z : S}
(hz : eval₂ f z p = 0) (inj : ∀ x : R, f x = 0 → x = 0) : 0 < degree p :=
natDegree_pos_iff_degree_pos.mp (natDegree_pos_of_eval₂_root hp f hz inj)
#align polynomial.degree_pos_of_eval₂_root Polynomial.degree_pos_of_eval₂_root
@[simp]
theorem coe_lt_degree {p : R[X]} {n : ℕ} : (n : WithBot ℕ) < degree p ↔ n < natDegree p := by
by_cases h : p = 0
· simp [h]
simp [degree_eq_natDegree h, Nat.cast_lt]
#align polynomial.coe_lt_degree Polynomial.coe_lt_degree
@[simp]
theorem degree_map_eq_iff {f : R →+* S} {p : Polynomial R} :
degree (map f p) = degree p ↔ f (leadingCoeff p) ≠ 0 ∨ p = 0 := by
rcases eq_or_ne p 0 with h|h
· simp [h]
simp only [h, or_false]
refine ⟨fun h2 ↦ ?_, degree_map_eq_of_leadingCoeff_ne_zero f⟩
have h3 : natDegree (map f p) = natDegree p := by simp_rw [natDegree, h2]
have h4 : map f p ≠ 0 := by
rwa [ne_eq, ← degree_eq_bot, h2, degree_eq_bot]
rwa [← coeff_natDegree, ← coeff_map, ← h3, coeff_natDegree, ne_eq, leadingCoeff_eq_zero]
@[simp]
theorem natDegree_map_eq_iff {f : R →+* S} {p : Polynomial R} :
natDegree (map f p) = natDegree p ↔ f (p.leadingCoeff) ≠ 0 ∨ natDegree p = 0 := by
rcases eq_or_ne (natDegree p) 0 with h|h
· simp_rw [h, ne_eq, or_true, iff_true, ← Nat.le_zero, ← h, natDegree_map_le f p]
have h2 : p ≠ 0 := by rintro rfl; simp at h
have h3 : degree p ≠ (0 : ℕ) := degree_ne_of_natDegree_ne h
simp_rw [h, or_false, natDegree, WithBot.unbot'_eq_unbot'_iff, degree_map_eq_iff]
simp [h, h2, h3] -- simp doesn't rewrite in the hypothesis for some reason
tauto
theorem natDegree_pos_of_nextCoeff_ne_zero (h : p.nextCoeff ≠ 0) : 0 < p.natDegree := by
rw [nextCoeff] at h
by_cases hpz : p.natDegree = 0
· simp_all only [ne_eq, zero_le, ite_true, not_true_eq_false]
· apply Nat.zero_lt_of_ne_zero hpz
end Degree
end Semiring
section Ring
variable [Ring R] {p q : R[X]}
theorem natDegree_sub : (p - q).natDegree = (q - p).natDegree := by rw [← natDegree_neg, neg_sub]
#align polynomial.nat_degree_sub Polynomial.natDegree_sub
theorem natDegree_sub_le_iff_left (qn : q.natDegree ≤ n) :
(p - q).natDegree ≤ n ↔ p.natDegree ≤ n := by
rw [← natDegree_neg] at qn
rw [sub_eq_add_neg, natDegree_add_le_iff_left _ _ qn]
#align polynomial.nat_degree_sub_le_iff_left Polynomial.natDegree_sub_le_iff_left
theorem natDegree_sub_le_iff_right (pn : p.natDegree ≤ n) :
(p - q).natDegree ≤ n ↔ q.natDegree ≤ n := by rwa [natDegree_sub, natDegree_sub_le_iff_left]
#align polynomial.nat_degree_sub_le_iff_right Polynomial.natDegree_sub_le_iff_right
theorem coeff_sub_eq_left_of_lt (dg : q.natDegree < n) : (p - q).coeff n = p.coeff n := by
rw [← natDegree_neg] at dg
rw [sub_eq_add_neg, coeff_add_eq_left_of_lt dg]
#align polynomial.coeff_sub_eq_left_of_lt Polynomial.coeff_sub_eq_left_of_lt
theorem coeff_sub_eq_neg_right_of_lt (df : p.natDegree < n) : (p - q).coeff n = -q.coeff n := by
rwa [sub_eq_add_neg, coeff_add_eq_right_of_lt, coeff_neg]
#align polynomial.coeff_sub_eq_neg_right_of_lt Polynomial.coeff_sub_eq_neg_right_of_lt
end Ring
section NoZeroDivisors
variable [Semiring R] [NoZeroDivisors R] {p q : R[X]} {a : R}
theorem degree_mul_C (a0 : a ≠ 0) : (p * C a).degree = p.degree := by
rw [degree_mul, degree_C a0, add_zero]
set_option linter.uppercaseLean3 false in
#align polynomial.degree_mul_C Polynomial.degree_mul_C
theorem degree_C_mul (a0 : a ≠ 0) : (C a * p).degree = p.degree := by
rw [degree_mul, degree_C a0, zero_add]
set_option linter.uppercaseLean3 false in
#align polynomial.degree_C_mul Polynomial.degree_C_mul
theorem natDegree_mul_C (a0 : a ≠ 0) : (p * C a).natDegree = p.natDegree := by
simp only [natDegree, degree_mul_C a0]
set_option linter.uppercaseLean3 false in
#align polynomial.natDegree_mul_C Polynomial.natDegree_mul_C
theorem natDegree_C_mul (a0 : a ≠ 0) : (C a * p).natDegree = p.natDegree := by
simp only [natDegree, degree_C_mul a0]
set_option linter.uppercaseLean3 false in
#align polynomial.nat_degree_C_mul Polynomial.natDegree_C_mul
@[simp]
lemma nextCoeff_C_mul_X_add_C (ha : a ≠ 0) (c : R) : nextCoeff (C a * X + C c) = c := by
rw [nextCoeff_of_natDegree_pos] <;> simp [ha]
lemma natDegree_eq_one : p.natDegree = 1 ↔ ∃ a ≠ 0, ∃ b, C a * X + C b = p := by
refine ⟨fun hp ↦ ⟨p.coeff 1, fun h ↦ ?_, p.coeff 0, ?_⟩, ?_⟩
· rw [← hp, coeff_natDegree, leadingCoeff_eq_zero] at h
aesop
· ext n
obtain _ | _ | n := n
· simp
· simp
· simp only [coeff_add, coeff_mul_X, coeff_C_succ, add_zero]
rw [coeff_eq_zero_of_natDegree_lt]
simp [hp]
· rintro ⟨a, ha, b, rfl⟩
simp [ha]
| Mathlib/Algebra/Polynomial/Degree/Lemmas.lean | 394 | 402 | theorem natDegree_comp : natDegree (p.comp q) = natDegree p * natDegree q := by |
by_cases q0 : q.natDegree = 0
· rw [degree_le_zero_iff.mp (natDegree_eq_zero_iff_degree_le_zero.mp q0), comp_C, natDegree_C,
natDegree_C, mul_zero]
· by_cases p0 : p = 0
· simp only [p0, zero_comp, natDegree_zero, zero_mul]
refine le_antisymm natDegree_comp_le (le_natDegree_of_ne_zero ?_)
simp only [coeff_comp_degree_mul_degree q0, p0, mul_eq_zero, leadingCoeff_eq_zero, or_self_iff,
ne_zero_of_natDegree_gt (Nat.pos_of_ne_zero q0), pow_ne_zero, Ne, not_false_iff]
|
/-
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, Yury Kudryashov
-/
import Mathlib.Analysis.Calculus.FormalMultilinearSeries
import Mathlib.Analysis.SpecificLimits.Normed
import Mathlib.Logic.Equiv.Fin
import Mathlib.Topology.Algebra.InfiniteSum.Module
#align_import analysis.analytic.basic from "leanprover-community/mathlib"@"32253a1a1071173b33dc7d6a218cf722c6feb514"
/-!
# Analytic functions
A function is analytic in one dimension around `0` if it can be written as a converging power series
`Σ pₙ zⁿ`. This definition can be extended to any dimension (even in infinite dimension) by
requiring that `pₙ` is a continuous `n`-multilinear map. In general, `pₙ` is not unique (in two
dimensions, taking `p₂ (x, y) (x', y') = x y'` or `y x'` gives the same map when applied to a
vector `(x, y) (x, y)`). A way to guarantee uniqueness is to take a symmetric `pₙ`, but this is not
always possible in nonzero characteristic (in characteristic 2, the previous example has no
symmetric representative). Therefore, we do not insist on symmetry or uniqueness in the definition,
and we only require the existence of a converging series.
The general framework is important to say that the exponential map on bounded operators on a Banach
space is analytic, as well as the inverse on invertible operators.
## Main definitions
Let `p` be a formal multilinear series from `E` to `F`, i.e., `p n` is a multilinear map on `E^n`
for `n : ℕ`.
* `p.radius`: the largest `r : ℝ≥0∞` such that `‖p n‖ * r^n` grows subexponentially.
* `p.le_radius_of_bound`, `p.le_radius_of_bound_nnreal`, `p.le_radius_of_isBigO`: if `‖p n‖ * r ^ n`
is bounded above, then `r ≤ p.radius`;
* `p.isLittleO_of_lt_radius`, `p.norm_mul_pow_le_mul_pow_of_lt_radius`,
`p.isLittleO_one_of_lt_radius`,
`p.norm_mul_pow_le_of_lt_radius`, `p.nnnorm_mul_pow_le_of_lt_radius`: if `r < p.radius`, then
`‖p n‖ * r ^ n` tends to zero exponentially;
* `p.lt_radius_of_isBigO`: if `r ≠ 0` and `‖p n‖ * r ^ n = O(a ^ n)` for some `-1 < a < 1`, then
`r < p.radius`;
* `p.partialSum n x`: the sum `∑_{i = 0}^{n-1} pᵢ xⁱ`.
* `p.sum x`: the sum `∑'_{i = 0}^{∞} pᵢ xⁱ`.
Additionally, let `f` be a function from `E` to `F`.
* `HasFPowerSeriesOnBall f p x r`: on the ball of center `x` with radius `r`,
`f (x + y) = ∑'_n pₙ yⁿ`.
* `HasFPowerSeriesAt f p x`: on some ball of center `x` with positive radius, holds
`HasFPowerSeriesOnBall f p x r`.
* `AnalyticAt 𝕜 f x`: there exists a power series `p` such that holds `HasFPowerSeriesAt f p x`.
* `AnalyticOn 𝕜 f s`: the function `f` is analytic at every point of `s`.
We develop the basic properties of these notions, notably:
* If a function admits a power series, it is continuous (see
`HasFPowerSeriesOnBall.continuousOn` and `HasFPowerSeriesAt.continuousAt` and
`AnalyticAt.continuousAt`).
* In a complete space, the sum of a formal power series with positive radius is well defined on the
disk of convergence, see `FormalMultilinearSeries.hasFPowerSeriesOnBall`.
* If a function admits a power series in a ball, then it is analytic at any point `y` of this ball,
and the power series there can be expressed in terms of the initial power series `p` as
`p.changeOrigin y`. See `HasFPowerSeriesOnBall.changeOrigin`. It follows in particular that
the set of points at which a given function is analytic is open, see `isOpen_analyticAt`.
## Implementation details
We only introduce the radius of convergence of a power series, as `p.radius`.
For a power series in finitely many dimensions, there is a finer (directional, coordinate-dependent)
notion, describing the polydisk of convergence. This notion is more specific, and not necessary to
build the general theory. We do not define it here.
-/
noncomputable section
variable {𝕜 E F G : Type*}
open scoped Classical
open Topology NNReal Filter ENNReal
open Set Filter Asymptotics
namespace FormalMultilinearSeries
variable [Ring 𝕜] [AddCommGroup E] [AddCommGroup F] [Module 𝕜 E] [Module 𝕜 F]
variable [TopologicalSpace E] [TopologicalSpace F]
variable [TopologicalAddGroup E] [TopologicalAddGroup F]
variable [ContinuousConstSMul 𝕜 E] [ContinuousConstSMul 𝕜 F]
/-- Given a formal multilinear series `p` and a vector `x`, then `p.sum x` is the sum `Σ pₙ xⁿ`. A
priori, it only behaves well when `‖x‖ < p.radius`. -/
protected def sum (p : FormalMultilinearSeries 𝕜 E F) (x : E) : F :=
∑' n : ℕ, p n fun _ => x
#align formal_multilinear_series.sum FormalMultilinearSeries.sum
/-- Given a formal multilinear series `p` and a vector `x`, then `p.partialSum n x` is the sum
`Σ pₖ xᵏ` for `k ∈ {0,..., n-1}`. -/
def partialSum (p : FormalMultilinearSeries 𝕜 E F) (n : ℕ) (x : E) : F :=
∑ k ∈ Finset.range n, p k fun _ : Fin k => x
#align formal_multilinear_series.partial_sum FormalMultilinearSeries.partialSum
/-- The partial sums of a formal multilinear series are continuous. -/
theorem partialSum_continuous (p : FormalMultilinearSeries 𝕜 E F) (n : ℕ) :
Continuous (p.partialSum n) := by
unfold partialSum -- Porting note: added
continuity
#align formal_multilinear_series.partial_sum_continuous FormalMultilinearSeries.partialSum_continuous
end FormalMultilinearSeries
/-! ### The radius of a formal multilinear series -/
variable [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F]
[NormedSpace 𝕜 F] [NormedAddCommGroup G] [NormedSpace 𝕜 G]
namespace FormalMultilinearSeries
variable (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0}
/-- The radius of a formal multilinear series is the largest `r` such that the sum `Σ ‖pₙ‖ ‖y‖ⁿ`
converges for all `‖y‖ < r`. This implies that `Σ pₙ yⁿ` converges for all `‖y‖ < r`, but these
definitions are *not* equivalent in general. -/
def radius (p : FormalMultilinearSeries 𝕜 E F) : ℝ≥0∞ :=
⨆ (r : ℝ≥0) (C : ℝ) (_ : ∀ n, ‖p n‖ * (r : ℝ) ^ n ≤ C), (r : ℝ≥0∞)
#align formal_multilinear_series.radius FormalMultilinearSeries.radius
/-- If `‖pₙ‖ rⁿ` is bounded in `n`, then the radius of `p` is at least `r`. -/
theorem le_radius_of_bound (C : ℝ) {r : ℝ≥0} (h : ∀ n : ℕ, ‖p n‖ * (r : ℝ) ^ n ≤ C) :
(r : ℝ≥0∞) ≤ p.radius :=
le_iSup_of_le r <| le_iSup_of_le C <| le_iSup (fun _ => (r : ℝ≥0∞)) h
#align formal_multilinear_series.le_radius_of_bound FormalMultilinearSeries.le_radius_of_bound
/-- If `‖pₙ‖ rⁿ` is bounded in `n`, then the radius of `p` is at least `r`. -/
theorem le_radius_of_bound_nnreal (C : ℝ≥0) {r : ℝ≥0} (h : ∀ n : ℕ, ‖p n‖₊ * r ^ n ≤ C) :
(r : ℝ≥0∞) ≤ p.radius :=
p.le_radius_of_bound C fun n => mod_cast h n
#align formal_multilinear_series.le_radius_of_bound_nnreal FormalMultilinearSeries.le_radius_of_bound_nnreal
/-- If `‖pₙ‖ rⁿ = O(1)`, as `n → ∞`, then the radius of `p` is at least `r`. -/
theorem le_radius_of_isBigO (h : (fun n => ‖p n‖ * (r : ℝ) ^ n) =O[atTop] fun _ => (1 : ℝ)) :
↑r ≤ p.radius :=
Exists.elim (isBigO_one_nat_atTop_iff.1 h) fun C hC =>
p.le_radius_of_bound C fun n => (le_abs_self _).trans (hC n)
set_option linter.uppercaseLean3 false in
#align formal_multilinear_series.le_radius_of_is_O FormalMultilinearSeries.le_radius_of_isBigO
theorem le_radius_of_eventually_le (C) (h : ∀ᶠ n in atTop, ‖p n‖ * (r : ℝ) ^ n ≤ C) :
↑r ≤ p.radius :=
p.le_radius_of_isBigO <| IsBigO.of_bound C <| h.mono fun n hn => by simpa
#align formal_multilinear_series.le_radius_of_eventually_le FormalMultilinearSeries.le_radius_of_eventually_le
theorem le_radius_of_summable_nnnorm (h : Summable fun n => ‖p n‖₊ * r ^ n) : ↑r ≤ p.radius :=
p.le_radius_of_bound_nnreal (∑' n, ‖p n‖₊ * r ^ n) fun _ => le_tsum' h _
#align formal_multilinear_series.le_radius_of_summable_nnnorm FormalMultilinearSeries.le_radius_of_summable_nnnorm
theorem le_radius_of_summable (h : Summable fun n => ‖p n‖ * (r : ℝ) ^ n) : ↑r ≤ p.radius :=
p.le_radius_of_summable_nnnorm <| by
simp only [← coe_nnnorm] at h
exact mod_cast h
#align formal_multilinear_series.le_radius_of_summable FormalMultilinearSeries.le_radius_of_summable
theorem radius_eq_top_of_forall_nnreal_isBigO
(h : ∀ r : ℝ≥0, (fun n => ‖p n‖ * (r : ℝ) ^ n) =O[atTop] fun _ => (1 : ℝ)) : p.radius = ∞ :=
ENNReal.eq_top_of_forall_nnreal_le fun r => p.le_radius_of_isBigO (h r)
set_option linter.uppercaseLean3 false in
#align formal_multilinear_series.radius_eq_top_of_forall_nnreal_is_O FormalMultilinearSeries.radius_eq_top_of_forall_nnreal_isBigO
theorem radius_eq_top_of_eventually_eq_zero (h : ∀ᶠ n in atTop, p n = 0) : p.radius = ∞ :=
p.radius_eq_top_of_forall_nnreal_isBigO fun r =>
(isBigO_zero _ _).congr' (h.mono fun n hn => by simp [hn]) EventuallyEq.rfl
#align formal_multilinear_series.radius_eq_top_of_eventually_eq_zero FormalMultilinearSeries.radius_eq_top_of_eventually_eq_zero
theorem radius_eq_top_of_forall_image_add_eq_zero (n : ℕ) (hn : ∀ m, p (m + n) = 0) :
p.radius = ∞ :=
p.radius_eq_top_of_eventually_eq_zero <|
mem_atTop_sets.2 ⟨n, fun _ hk => tsub_add_cancel_of_le hk ▸ hn _⟩
#align formal_multilinear_series.radius_eq_top_of_forall_image_add_eq_zero FormalMultilinearSeries.radius_eq_top_of_forall_image_add_eq_zero
@[simp]
theorem constFormalMultilinearSeries_radius {v : F} :
(constFormalMultilinearSeries 𝕜 E v).radius = ⊤ :=
(constFormalMultilinearSeries 𝕜 E v).radius_eq_top_of_forall_image_add_eq_zero 1
(by simp [constFormalMultilinearSeries])
#align formal_multilinear_series.const_formal_multilinear_series_radius FormalMultilinearSeries.constFormalMultilinearSeries_radius
/-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` tends to zero exponentially:
for some `0 < a < 1`, `‖p n‖ rⁿ = o(aⁿ)`. -/
theorem isLittleO_of_lt_radius (h : ↑r < p.radius) :
∃ a ∈ Ioo (0 : ℝ) 1, (fun n => ‖p n‖ * (r : ℝ) ^ n) =o[atTop] (a ^ ·) := by
have := (TFAE_exists_lt_isLittleO_pow (fun n => ‖p n‖ * (r : ℝ) ^ n) 1).out 1 4
rw [this]
-- Porting note: was
-- rw [(TFAE_exists_lt_isLittleO_pow (fun n => ‖p n‖ * (r : ℝ) ^ n) 1).out 1 4]
simp only [radius, lt_iSup_iff] at h
rcases h with ⟨t, C, hC, rt⟩
rw [ENNReal.coe_lt_coe, ← NNReal.coe_lt_coe] at rt
have : 0 < (t : ℝ) := r.coe_nonneg.trans_lt rt
rw [← div_lt_one this] at rt
refine ⟨_, rt, C, Or.inr zero_lt_one, fun n => ?_⟩
calc
|‖p n‖ * (r : ℝ) ^ n| = ‖p n‖ * (t : ℝ) ^ n * (r / t : ℝ) ^ n := by
field_simp [mul_right_comm, abs_mul]
_ ≤ C * (r / t : ℝ) ^ n := by gcongr; apply hC
#align formal_multilinear_series.is_o_of_lt_radius FormalMultilinearSeries.isLittleO_of_lt_radius
/-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ = o(1)`. -/
theorem isLittleO_one_of_lt_radius (h : ↑r < p.radius) :
(fun n => ‖p n‖ * (r : ℝ) ^ n) =o[atTop] (fun _ => 1 : ℕ → ℝ) :=
let ⟨_, ha, hp⟩ := p.isLittleO_of_lt_radius h
hp.trans <| (isLittleO_pow_pow_of_lt_left ha.1.le ha.2).congr (fun _ => rfl) one_pow
#align formal_multilinear_series.is_o_one_of_lt_radius FormalMultilinearSeries.isLittleO_one_of_lt_radius
/-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` tends to zero exponentially:
for some `0 < a < 1` and `C > 0`, `‖p n‖ * r ^ n ≤ C * a ^ n`. -/
theorem norm_mul_pow_le_mul_pow_of_lt_radius (h : ↑r < p.radius) :
∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ n, ‖p n‖ * (r : ℝ) ^ n ≤ C * a ^ n := by
-- Porting note: moved out of `rcases`
have := ((TFAE_exists_lt_isLittleO_pow (fun n => ‖p n‖ * (r : ℝ) ^ n) 1).out 1 5).mp
(p.isLittleO_of_lt_radius h)
rcases this with ⟨a, ha, C, hC, H⟩
exact ⟨a, ha, C, hC, fun n => (le_abs_self _).trans (H n)⟩
#align formal_multilinear_series.norm_mul_pow_le_mul_pow_of_lt_radius FormalMultilinearSeries.norm_mul_pow_le_mul_pow_of_lt_radius
/-- If `r ≠ 0` and `‖pₙ‖ rⁿ = O(aⁿ)` for some `-1 < a < 1`, then `r < p.radius`. -/
theorem lt_radius_of_isBigO (h₀ : r ≠ 0) {a : ℝ} (ha : a ∈ Ioo (-1 : ℝ) 1)
(hp : (fun n => ‖p n‖ * (r : ℝ) ^ n) =O[atTop] (a ^ ·)) : ↑r < p.radius := by
-- Porting note: moved out of `rcases`
have := ((TFAE_exists_lt_isLittleO_pow (fun n => ‖p n‖ * (r : ℝ) ^ n) 1).out 2 5)
rcases this.mp ⟨a, ha, hp⟩ with ⟨a, ha, C, hC, hp⟩
rw [← pos_iff_ne_zero, ← NNReal.coe_pos] at h₀
lift a to ℝ≥0 using ha.1.le
have : (r : ℝ) < r / a := by
simpa only [div_one] using (div_lt_div_left h₀ zero_lt_one ha.1).2 ha.2
norm_cast at this
rw [← ENNReal.coe_lt_coe] at this
refine this.trans_le (p.le_radius_of_bound C fun n => ?_)
rw [NNReal.coe_div, div_pow, ← mul_div_assoc, div_le_iff (pow_pos ha.1 n)]
exact (le_abs_self _).trans (hp n)
set_option linter.uppercaseLean3 false in
#align formal_multilinear_series.lt_radius_of_is_O FormalMultilinearSeries.lt_radius_of_isBigO
/-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` is bounded. -/
theorem norm_mul_pow_le_of_lt_radius (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0}
(h : (r : ℝ≥0∞) < p.radius) : ∃ C > 0, ∀ n, ‖p n‖ * (r : ℝ) ^ n ≤ C :=
let ⟨_, ha, C, hC, h⟩ := p.norm_mul_pow_le_mul_pow_of_lt_radius h
⟨C, hC, fun n => (h n).trans <| mul_le_of_le_one_right hC.lt.le (pow_le_one _ ha.1.le ha.2.le)⟩
#align formal_multilinear_series.norm_mul_pow_le_of_lt_radius FormalMultilinearSeries.norm_mul_pow_le_of_lt_radius
/-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` is bounded. -/
theorem norm_le_div_pow_of_pos_of_lt_radius (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0}
(h0 : 0 < r) (h : (r : ℝ≥0∞) < p.radius) : ∃ C > 0, ∀ n, ‖p n‖ ≤ C / (r : ℝ) ^ n :=
let ⟨C, hC, hp⟩ := p.norm_mul_pow_le_of_lt_radius h
⟨C, hC, fun n => Iff.mpr (le_div_iff (pow_pos h0 _)) (hp n)⟩
#align formal_multilinear_series.norm_le_div_pow_of_pos_of_lt_radius FormalMultilinearSeries.norm_le_div_pow_of_pos_of_lt_radius
/-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` is bounded. -/
theorem nnnorm_mul_pow_le_of_lt_radius (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0}
(h : (r : ℝ≥0∞) < p.radius) : ∃ C > 0, ∀ n, ‖p n‖₊ * r ^ n ≤ C :=
let ⟨C, hC, hp⟩ := p.norm_mul_pow_le_of_lt_radius h
⟨⟨C, hC.lt.le⟩, hC, mod_cast hp⟩
#align formal_multilinear_series.nnnorm_mul_pow_le_of_lt_radius FormalMultilinearSeries.nnnorm_mul_pow_le_of_lt_radius
theorem le_radius_of_tendsto (p : FormalMultilinearSeries 𝕜 E F) {l : ℝ}
(h : Tendsto (fun n => ‖p n‖ * (r : ℝ) ^ n) atTop (𝓝 l)) : ↑r ≤ p.radius :=
p.le_radius_of_isBigO (h.isBigO_one _)
#align formal_multilinear_series.le_radius_of_tendsto FormalMultilinearSeries.le_radius_of_tendsto
theorem le_radius_of_summable_norm (p : FormalMultilinearSeries 𝕜 E F)
(hs : Summable fun n => ‖p n‖ * (r : ℝ) ^ n) : ↑r ≤ p.radius :=
p.le_radius_of_tendsto hs.tendsto_atTop_zero
#align formal_multilinear_series.le_radius_of_summable_norm FormalMultilinearSeries.le_radius_of_summable_norm
theorem not_summable_norm_of_radius_lt_nnnorm (p : FormalMultilinearSeries 𝕜 E F) {x : E}
(h : p.radius < ‖x‖₊) : ¬Summable fun n => ‖p n‖ * ‖x‖ ^ n :=
fun hs => not_le_of_lt h (p.le_radius_of_summable_norm hs)
#align formal_multilinear_series.not_summable_norm_of_radius_lt_nnnorm FormalMultilinearSeries.not_summable_norm_of_radius_lt_nnnorm
theorem summable_norm_mul_pow (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0} (h : ↑r < p.radius) :
Summable fun n : ℕ => ‖p n‖ * (r : ℝ) ^ n := by
obtain ⟨a, ha : a ∈ Ioo (0 : ℝ) 1, C, - : 0 < C, hp⟩ := p.norm_mul_pow_le_mul_pow_of_lt_radius h
exact .of_nonneg_of_le (fun n => mul_nonneg (norm_nonneg _) (pow_nonneg r.coe_nonneg _))
hp ((summable_geometric_of_lt_one ha.1.le ha.2).mul_left _)
#align formal_multilinear_series.summable_norm_mul_pow FormalMultilinearSeries.summable_norm_mul_pow
theorem summable_norm_apply (p : FormalMultilinearSeries 𝕜 E F) {x : E}
(hx : x ∈ EMetric.ball (0 : E) p.radius) : Summable fun n : ℕ => ‖p n fun _ => x‖ := by
rw [mem_emetric_ball_zero_iff] at hx
refine .of_nonneg_of_le
(fun _ ↦ norm_nonneg _) (fun n ↦ ((p n).le_opNorm _).trans_eq ?_) (p.summable_norm_mul_pow hx)
simp
#align formal_multilinear_series.summable_norm_apply FormalMultilinearSeries.summable_norm_apply
theorem summable_nnnorm_mul_pow (p : FormalMultilinearSeries 𝕜 E F) {r : ℝ≥0} (h : ↑r < p.radius) :
Summable fun n : ℕ => ‖p n‖₊ * r ^ n := by
rw [← NNReal.summable_coe]
push_cast
exact p.summable_norm_mul_pow h
#align formal_multilinear_series.summable_nnnorm_mul_pow FormalMultilinearSeries.summable_nnnorm_mul_pow
protected theorem summable [CompleteSpace F] (p : FormalMultilinearSeries 𝕜 E F) {x : E}
(hx : x ∈ EMetric.ball (0 : E) p.radius) : Summable fun n : ℕ => p n fun _ => x :=
(p.summable_norm_apply hx).of_norm
#align formal_multilinear_series.summable FormalMultilinearSeries.summable
theorem radius_eq_top_of_summable_norm (p : FormalMultilinearSeries 𝕜 E F)
(hs : ∀ r : ℝ≥0, Summable fun n => ‖p n‖ * (r : ℝ) ^ n) : p.radius = ∞ :=
ENNReal.eq_top_of_forall_nnreal_le fun r => p.le_radius_of_summable_norm (hs r)
#align formal_multilinear_series.radius_eq_top_of_summable_norm FormalMultilinearSeries.radius_eq_top_of_summable_norm
theorem radius_eq_top_iff_summable_norm (p : FormalMultilinearSeries 𝕜 E F) :
p.radius = ∞ ↔ ∀ r : ℝ≥0, Summable fun n => ‖p n‖ * (r : ℝ) ^ n := by
constructor
· intro h r
obtain ⟨a, ha : a ∈ Ioo (0 : ℝ) 1, C, - : 0 < C, hp⟩ := p.norm_mul_pow_le_mul_pow_of_lt_radius
(show (r : ℝ≥0∞) < p.radius from h.symm ▸ ENNReal.coe_lt_top)
refine .of_norm_bounded
(fun n ↦ (C : ℝ) * a ^ n) ((summable_geometric_of_lt_one ha.1.le ha.2).mul_left _) fun n ↦ ?_
specialize hp n
rwa [Real.norm_of_nonneg (mul_nonneg (norm_nonneg _) (pow_nonneg r.coe_nonneg n))]
· exact p.radius_eq_top_of_summable_norm
#align formal_multilinear_series.radius_eq_top_iff_summable_norm FormalMultilinearSeries.radius_eq_top_iff_summable_norm
/-- If the radius of `p` is positive, then `‖pₙ‖` grows at most geometrically. -/
theorem le_mul_pow_of_radius_pos (p : FormalMultilinearSeries 𝕜 E F) (h : 0 < p.radius) :
∃ (C r : _) (hC : 0 < C) (_ : 0 < r), ∀ n, ‖p n‖ ≤ C * r ^ n := by
rcases ENNReal.lt_iff_exists_nnreal_btwn.1 h with ⟨r, r0, rlt⟩
have rpos : 0 < (r : ℝ) := by simp [ENNReal.coe_pos.1 r0]
rcases norm_le_div_pow_of_pos_of_lt_radius p rpos rlt with ⟨C, Cpos, hCp⟩
refine ⟨C, r⁻¹, Cpos, by simp only [inv_pos, rpos], fun n => ?_⟩
-- Porting note: was `convert`
rw [inv_pow, ← div_eq_mul_inv]
exact hCp n
#align formal_multilinear_series.le_mul_pow_of_radius_pos FormalMultilinearSeries.le_mul_pow_of_radius_pos
/-- The radius of the sum of two formal series is at least the minimum of their two radii. -/
theorem min_radius_le_radius_add (p q : FormalMultilinearSeries 𝕜 E F) :
min p.radius q.radius ≤ (p + q).radius := by
refine ENNReal.le_of_forall_nnreal_lt fun r hr => ?_
rw [lt_min_iff] at hr
have := ((p.isLittleO_one_of_lt_radius hr.1).add (q.isLittleO_one_of_lt_radius hr.2)).isBigO
refine (p + q).le_radius_of_isBigO ((isBigO_of_le _ fun n => ?_).trans this)
rw [← add_mul, norm_mul, norm_mul, norm_norm]
exact mul_le_mul_of_nonneg_right ((norm_add_le _ _).trans (le_abs_self _)) (norm_nonneg _)
#align formal_multilinear_series.min_radius_le_radius_add FormalMultilinearSeries.min_radius_le_radius_add
@[simp]
theorem radius_neg (p : FormalMultilinearSeries 𝕜 E F) : (-p).radius = p.radius := by
simp only [radius, neg_apply, norm_neg]
#align formal_multilinear_series.radius_neg FormalMultilinearSeries.radius_neg
protected theorem hasSum [CompleteSpace F] (p : FormalMultilinearSeries 𝕜 E F) {x : E}
(hx : x ∈ EMetric.ball (0 : E) p.radius) : HasSum (fun n : ℕ => p n fun _ => x) (p.sum x) :=
(p.summable hx).hasSum
#align formal_multilinear_series.has_sum FormalMultilinearSeries.hasSum
theorem radius_le_radius_continuousLinearMap_comp (p : FormalMultilinearSeries 𝕜 E F)
(f : F →L[𝕜] G) : p.radius ≤ (f.compFormalMultilinearSeries p).radius := by
refine ENNReal.le_of_forall_nnreal_lt fun r hr => ?_
apply le_radius_of_isBigO
apply (IsBigO.trans_isLittleO _ (p.isLittleO_one_of_lt_radius hr)).isBigO
refine IsBigO.mul (@IsBigOWith.isBigO _ _ _ _ _ ‖f‖ _ _ _ ?_) (isBigO_refl _ _)
refine IsBigOWith.of_bound (eventually_of_forall fun n => ?_)
simpa only [norm_norm] using f.norm_compContinuousMultilinearMap_le (p n)
#align formal_multilinear_series.radius_le_radius_continuous_linear_map_comp FormalMultilinearSeries.radius_le_radius_continuousLinearMap_comp
end FormalMultilinearSeries
/-! ### Expanding a function as a power series -/
section
variable {f g : E → F} {p pf pg : FormalMultilinearSeries 𝕜 E F} {x : E} {r r' : ℝ≥0∞}
/-- Given a function `f : E → F` and a formal multilinear series `p`, we say that `f` has `p` as
a power series on the ball of radius `r > 0` around `x` if `f (x + y) = ∑' pₙ yⁿ` for all `‖y‖ < r`.
-/
structure HasFPowerSeriesOnBall (f : E → F) (p : FormalMultilinearSeries 𝕜 E F) (x : E) (r : ℝ≥0∞) :
Prop where
r_le : r ≤ p.radius
r_pos : 0 < r
hasSum :
∀ {y}, y ∈ EMetric.ball (0 : E) r → HasSum (fun n : ℕ => p n fun _ : Fin n => y) (f (x + y))
#align has_fpower_series_on_ball HasFPowerSeriesOnBall
/-- Given a function `f : E → F` and a formal multilinear series `p`, we say that `f` has `p` as
a power series around `x` if `f (x + y) = ∑' pₙ yⁿ` for all `y` in a neighborhood of `0`. -/
def HasFPowerSeriesAt (f : E → F) (p : FormalMultilinearSeries 𝕜 E F) (x : E) :=
∃ r, HasFPowerSeriesOnBall f p x r
#align has_fpower_series_at HasFPowerSeriesAt
variable (𝕜)
/-- Given a function `f : E → F`, we say that `f` is analytic at `x` if it admits a convergent power
series expansion around `x`. -/
def AnalyticAt (f : E → F) (x : E) :=
∃ p : FormalMultilinearSeries 𝕜 E F, HasFPowerSeriesAt f p x
#align analytic_at AnalyticAt
/-- Given a function `f : E → F`, we say that `f` is analytic on a set `s` if it is analytic around
every point of `s`. -/
def AnalyticOn (f : E → F) (s : Set E) :=
∀ x, x ∈ s → AnalyticAt 𝕜 f x
#align analytic_on AnalyticOn
variable {𝕜}
theorem HasFPowerSeriesOnBall.hasFPowerSeriesAt (hf : HasFPowerSeriesOnBall f p x r) :
HasFPowerSeriesAt f p x :=
⟨r, hf⟩
#align has_fpower_series_on_ball.has_fpower_series_at HasFPowerSeriesOnBall.hasFPowerSeriesAt
theorem HasFPowerSeriesAt.analyticAt (hf : HasFPowerSeriesAt f p x) : AnalyticAt 𝕜 f x :=
⟨p, hf⟩
#align has_fpower_series_at.analytic_at HasFPowerSeriesAt.analyticAt
theorem HasFPowerSeriesOnBall.analyticAt (hf : HasFPowerSeriesOnBall f p x r) : AnalyticAt 𝕜 f x :=
hf.hasFPowerSeriesAt.analyticAt
#align has_fpower_series_on_ball.analytic_at HasFPowerSeriesOnBall.analyticAt
theorem HasFPowerSeriesOnBall.congr (hf : HasFPowerSeriesOnBall f p x r)
(hg : EqOn f g (EMetric.ball x r)) : HasFPowerSeriesOnBall g p x r :=
{ r_le := hf.r_le
r_pos := hf.r_pos
hasSum := fun {y} hy => by
convert hf.hasSum hy using 1
apply hg.symm
simpa [edist_eq_coe_nnnorm_sub] using hy }
#align has_fpower_series_on_ball.congr HasFPowerSeriesOnBall.congr
/-- If a function `f` has a power series `p` around `x`, then the function `z ↦ f (z - y)` has the
same power series around `x + y`. -/
theorem HasFPowerSeriesOnBall.comp_sub (hf : HasFPowerSeriesOnBall f p x r) (y : E) :
HasFPowerSeriesOnBall (fun z => f (z - y)) p (x + y) r :=
{ r_le := hf.r_le
r_pos := hf.r_pos
hasSum := fun {z} hz => by
convert hf.hasSum hz using 2
abel }
#align has_fpower_series_on_ball.comp_sub HasFPowerSeriesOnBall.comp_sub
theorem HasFPowerSeriesOnBall.hasSum_sub (hf : HasFPowerSeriesOnBall f p x r) {y : E}
(hy : y ∈ EMetric.ball x r) : HasSum (fun n : ℕ => p n fun _ => y - x) (f y) := by
have : y - x ∈ EMetric.ball (0 : E) r := by simpa [edist_eq_coe_nnnorm_sub] using hy
simpa only [add_sub_cancel] using hf.hasSum this
#align has_fpower_series_on_ball.has_sum_sub HasFPowerSeriesOnBall.hasSum_sub
theorem HasFPowerSeriesOnBall.radius_pos (hf : HasFPowerSeriesOnBall f p x r) : 0 < p.radius :=
lt_of_lt_of_le hf.r_pos hf.r_le
#align has_fpower_series_on_ball.radius_pos HasFPowerSeriesOnBall.radius_pos
theorem HasFPowerSeriesAt.radius_pos (hf : HasFPowerSeriesAt f p x) : 0 < p.radius :=
let ⟨_, hr⟩ := hf
hr.radius_pos
#align has_fpower_series_at.radius_pos HasFPowerSeriesAt.radius_pos
theorem HasFPowerSeriesOnBall.mono (hf : HasFPowerSeriesOnBall f p x r) (r'_pos : 0 < r')
(hr : r' ≤ r) : HasFPowerSeriesOnBall f p x r' :=
⟨le_trans hr hf.1, r'_pos, fun hy => hf.hasSum (EMetric.ball_subset_ball hr hy)⟩
#align has_fpower_series_on_ball.mono HasFPowerSeriesOnBall.mono
theorem HasFPowerSeriesAt.congr (hf : HasFPowerSeriesAt f p x) (hg : f =ᶠ[𝓝 x] g) :
HasFPowerSeriesAt g p x := by
rcases hf with ⟨r₁, h₁⟩
rcases EMetric.mem_nhds_iff.mp hg with ⟨r₂, h₂pos, h₂⟩
exact ⟨min r₁ r₂,
(h₁.mono (lt_min h₁.r_pos h₂pos) inf_le_left).congr
fun y hy => h₂ (EMetric.ball_subset_ball inf_le_right hy)⟩
#align has_fpower_series_at.congr HasFPowerSeriesAt.congr
protected theorem HasFPowerSeriesAt.eventually (hf : HasFPowerSeriesAt f p x) :
∀ᶠ r : ℝ≥0∞ in 𝓝[>] 0, HasFPowerSeriesOnBall f p x r :=
let ⟨_, hr⟩ := hf
mem_of_superset (Ioo_mem_nhdsWithin_Ioi (left_mem_Ico.2 hr.r_pos)) fun _ hr' =>
hr.mono hr'.1 hr'.2.le
#align has_fpower_series_at.eventually HasFPowerSeriesAt.eventually
theorem HasFPowerSeriesOnBall.eventually_hasSum (hf : HasFPowerSeriesOnBall f p x r) :
∀ᶠ y in 𝓝 0, HasSum (fun n : ℕ => p n fun _ : Fin n => y) (f (x + y)) := by
filter_upwards [EMetric.ball_mem_nhds (0 : E) hf.r_pos] using fun _ => hf.hasSum
#align has_fpower_series_on_ball.eventually_has_sum HasFPowerSeriesOnBall.eventually_hasSum
theorem HasFPowerSeriesAt.eventually_hasSum (hf : HasFPowerSeriesAt f p x) :
∀ᶠ y in 𝓝 0, HasSum (fun n : ℕ => p n fun _ : Fin n => y) (f (x + y)) :=
let ⟨_, hr⟩ := hf
hr.eventually_hasSum
#align has_fpower_series_at.eventually_has_sum HasFPowerSeriesAt.eventually_hasSum
theorem HasFPowerSeriesOnBall.eventually_hasSum_sub (hf : HasFPowerSeriesOnBall f p x r) :
∀ᶠ y in 𝓝 x, HasSum (fun n : ℕ => p n fun _ : Fin n => y - x) (f y) := by
filter_upwards [EMetric.ball_mem_nhds x hf.r_pos] with y using hf.hasSum_sub
#align has_fpower_series_on_ball.eventually_has_sum_sub HasFPowerSeriesOnBall.eventually_hasSum_sub
theorem HasFPowerSeriesAt.eventually_hasSum_sub (hf : HasFPowerSeriesAt f p x) :
∀ᶠ y in 𝓝 x, HasSum (fun n : ℕ => p n fun _ : Fin n => y - x) (f y) :=
let ⟨_, hr⟩ := hf
hr.eventually_hasSum_sub
#align has_fpower_series_at.eventually_has_sum_sub HasFPowerSeriesAt.eventually_hasSum_sub
theorem HasFPowerSeriesOnBall.eventually_eq_zero
(hf : HasFPowerSeriesOnBall f (0 : FormalMultilinearSeries 𝕜 E F) x r) :
∀ᶠ z in 𝓝 x, f z = 0 := by
filter_upwards [hf.eventually_hasSum_sub] with z hz using hz.unique hasSum_zero
#align has_fpower_series_on_ball.eventually_eq_zero HasFPowerSeriesOnBall.eventually_eq_zero
theorem HasFPowerSeriesAt.eventually_eq_zero
(hf : HasFPowerSeriesAt f (0 : FormalMultilinearSeries 𝕜 E F) x) : ∀ᶠ z in 𝓝 x, f z = 0 :=
let ⟨_, hr⟩ := hf
hr.eventually_eq_zero
#align has_fpower_series_at.eventually_eq_zero HasFPowerSeriesAt.eventually_eq_zero
theorem hasFPowerSeriesOnBall_const {c : F} {e : E} :
HasFPowerSeriesOnBall (fun _ => c) (constFormalMultilinearSeries 𝕜 E c) e ⊤ := by
refine ⟨by simp, WithTop.zero_lt_top, fun _ => hasSum_single 0 fun n hn => ?_⟩
simp [constFormalMultilinearSeries_apply hn]
#align has_fpower_series_on_ball_const hasFPowerSeriesOnBall_const
theorem hasFPowerSeriesAt_const {c : F} {e : E} :
HasFPowerSeriesAt (fun _ => c) (constFormalMultilinearSeries 𝕜 E c) e :=
⟨⊤, hasFPowerSeriesOnBall_const⟩
#align has_fpower_series_at_const hasFPowerSeriesAt_const
theorem analyticAt_const {v : F} : AnalyticAt 𝕜 (fun _ => v) x :=
⟨constFormalMultilinearSeries 𝕜 E v, hasFPowerSeriesAt_const⟩
#align analytic_at_const analyticAt_const
theorem analyticOn_const {v : F} {s : Set E} : AnalyticOn 𝕜 (fun _ => v) s :=
fun _ _ => analyticAt_const
#align analytic_on_const analyticOn_const
theorem HasFPowerSeriesOnBall.add (hf : HasFPowerSeriesOnBall f pf x r)
(hg : HasFPowerSeriesOnBall g pg x r) : HasFPowerSeriesOnBall (f + g) (pf + pg) x r :=
{ r_le := le_trans (le_min_iff.2 ⟨hf.r_le, hg.r_le⟩) (pf.min_radius_le_radius_add pg)
r_pos := hf.r_pos
hasSum := fun hy => (hf.hasSum hy).add (hg.hasSum hy) }
#align has_fpower_series_on_ball.add HasFPowerSeriesOnBall.add
theorem HasFPowerSeriesAt.add (hf : HasFPowerSeriesAt f pf x) (hg : HasFPowerSeriesAt g pg x) :
HasFPowerSeriesAt (f + g) (pf + pg) x := by
rcases (hf.eventually.and hg.eventually).exists with ⟨r, hr⟩
exact ⟨r, hr.1.add hr.2⟩
#align has_fpower_series_at.add HasFPowerSeriesAt.add
theorem AnalyticAt.congr (hf : AnalyticAt 𝕜 f x) (hg : f =ᶠ[𝓝 x] g) : AnalyticAt 𝕜 g x :=
let ⟨_, hpf⟩ := hf
(hpf.congr hg).analyticAt
theorem analyticAt_congr (h : f =ᶠ[𝓝 x] g) : AnalyticAt 𝕜 f x ↔ AnalyticAt 𝕜 g x :=
⟨fun hf ↦ hf.congr h, fun hg ↦ hg.congr h.symm⟩
theorem AnalyticAt.add (hf : AnalyticAt 𝕜 f x) (hg : AnalyticAt 𝕜 g x) : AnalyticAt 𝕜 (f + g) x :=
let ⟨_, hpf⟩ := hf
let ⟨_, hqf⟩ := hg
(hpf.add hqf).analyticAt
#align analytic_at.add AnalyticAt.add
theorem HasFPowerSeriesOnBall.neg (hf : HasFPowerSeriesOnBall f pf x r) :
HasFPowerSeriesOnBall (-f) (-pf) x r :=
{ r_le := by
rw [pf.radius_neg]
exact hf.r_le
r_pos := hf.r_pos
hasSum := fun hy => (hf.hasSum hy).neg }
#align has_fpower_series_on_ball.neg HasFPowerSeriesOnBall.neg
theorem HasFPowerSeriesAt.neg (hf : HasFPowerSeriesAt f pf x) : HasFPowerSeriesAt (-f) (-pf) x :=
let ⟨_, hrf⟩ := hf
hrf.neg.hasFPowerSeriesAt
#align has_fpower_series_at.neg HasFPowerSeriesAt.neg
theorem AnalyticAt.neg (hf : AnalyticAt 𝕜 f x) : AnalyticAt 𝕜 (-f) x :=
let ⟨_, hpf⟩ := hf
hpf.neg.analyticAt
#align analytic_at.neg AnalyticAt.neg
theorem HasFPowerSeriesOnBall.sub (hf : HasFPowerSeriesOnBall f pf x r)
(hg : HasFPowerSeriesOnBall g pg x r) : HasFPowerSeriesOnBall (f - g) (pf - pg) x r := by
simpa only [sub_eq_add_neg] using hf.add hg.neg
#align has_fpower_series_on_ball.sub HasFPowerSeriesOnBall.sub
theorem HasFPowerSeriesAt.sub (hf : HasFPowerSeriesAt f pf x) (hg : HasFPowerSeriesAt g pg x) :
HasFPowerSeriesAt (f - g) (pf - pg) x := by
simpa only [sub_eq_add_neg] using hf.add hg.neg
#align has_fpower_series_at.sub HasFPowerSeriesAt.sub
theorem AnalyticAt.sub (hf : AnalyticAt 𝕜 f x) (hg : AnalyticAt 𝕜 g x) :
AnalyticAt 𝕜 (f - g) x := by
simpa only [sub_eq_add_neg] using hf.add hg.neg
#align analytic_at.sub AnalyticAt.sub
theorem AnalyticOn.mono {s t : Set E} (hf : AnalyticOn 𝕜 f t) (hst : s ⊆ t) : AnalyticOn 𝕜 f s :=
fun z hz => hf z (hst hz)
#align analytic_on.mono AnalyticOn.mono
theorem AnalyticOn.congr' {s : Set E} (hf : AnalyticOn 𝕜 f s) (hg : f =ᶠ[𝓝ˢ s] g) :
AnalyticOn 𝕜 g s :=
fun z hz => (hf z hz).congr (mem_nhdsSet_iff_forall.mp hg z hz)
theorem analyticOn_congr' {s : Set E} (h : f =ᶠ[𝓝ˢ s] g) : AnalyticOn 𝕜 f s ↔ AnalyticOn 𝕜 g s :=
⟨fun hf => hf.congr' h, fun hg => hg.congr' h.symm⟩
theorem AnalyticOn.congr {s : Set E} (hs : IsOpen s) (hf : AnalyticOn 𝕜 f s) (hg : s.EqOn f g) :
AnalyticOn 𝕜 g s :=
hf.congr' <| mem_nhdsSet_iff_forall.mpr
(fun _ hz => eventuallyEq_iff_exists_mem.mpr ⟨s, hs.mem_nhds hz, hg⟩)
theorem analyticOn_congr {s : Set E} (hs : IsOpen s) (h : s.EqOn f g) : AnalyticOn 𝕜 f s ↔
AnalyticOn 𝕜 g s := ⟨fun hf => hf.congr hs h, fun hg => hg.congr hs h.symm⟩
theorem AnalyticOn.add {s : Set E} (hf : AnalyticOn 𝕜 f s) (hg : AnalyticOn 𝕜 g s) :
AnalyticOn 𝕜 (f + g) s :=
fun z hz => (hf z hz).add (hg z hz)
#align analytic_on.add AnalyticOn.add
theorem AnalyticOn.sub {s : Set E} (hf : AnalyticOn 𝕜 f s) (hg : AnalyticOn 𝕜 g s) :
AnalyticOn 𝕜 (f - g) s :=
fun z hz => (hf z hz).sub (hg z hz)
#align analytic_on.sub AnalyticOn.sub
theorem HasFPowerSeriesOnBall.coeff_zero (hf : HasFPowerSeriesOnBall f pf x r) (v : Fin 0 → E) :
pf 0 v = f x := by
have v_eq : v = fun i => 0 := Subsingleton.elim _ _
have zero_mem : (0 : E) ∈ EMetric.ball (0 : E) r := by simp [hf.r_pos]
have : ∀ i, i ≠ 0 → (pf i fun j => 0) = 0 := by
intro i hi
have : 0 < i := pos_iff_ne_zero.2 hi
exact ContinuousMultilinearMap.map_coord_zero _ (⟨0, this⟩ : Fin i) rfl
have A := (hf.hasSum zero_mem).unique (hasSum_single _ this)
simpa [v_eq] using A.symm
#align has_fpower_series_on_ball.coeff_zero HasFPowerSeriesOnBall.coeff_zero
theorem HasFPowerSeriesAt.coeff_zero (hf : HasFPowerSeriesAt f pf x) (v : Fin 0 → E) :
pf 0 v = f x :=
let ⟨_, hrf⟩ := hf
hrf.coeff_zero v
#align has_fpower_series_at.coeff_zero HasFPowerSeriesAt.coeff_zero
/-- If a function `f` has a power series `p` on a ball and `g` is linear, then `g ∘ f` has the
power series `g ∘ p` on the same ball. -/
theorem ContinuousLinearMap.comp_hasFPowerSeriesOnBall (g : F →L[𝕜] G)
(h : HasFPowerSeriesOnBall f p x r) :
HasFPowerSeriesOnBall (g ∘ f) (g.compFormalMultilinearSeries p) x r :=
{ r_le := h.r_le.trans (p.radius_le_radius_continuousLinearMap_comp _)
r_pos := h.r_pos
hasSum := fun hy => by
simpa only [ContinuousLinearMap.compFormalMultilinearSeries_apply,
ContinuousLinearMap.compContinuousMultilinearMap_coe, Function.comp_apply] using
g.hasSum (h.hasSum hy) }
#align continuous_linear_map.comp_has_fpower_series_on_ball ContinuousLinearMap.comp_hasFPowerSeriesOnBall
/-- If a function `f` is analytic on a set `s` and `g` is linear, then `g ∘ f` is analytic
on `s`. -/
theorem ContinuousLinearMap.comp_analyticOn {s : Set E} (g : F →L[𝕜] G) (h : AnalyticOn 𝕜 f s) :
AnalyticOn 𝕜 (g ∘ f) s := by
rintro x hx
rcases h x hx with ⟨p, r, hp⟩
exact ⟨g.compFormalMultilinearSeries p, r, g.comp_hasFPowerSeriesOnBall hp⟩
#align continuous_linear_map.comp_analytic_on ContinuousLinearMap.comp_analyticOn
/-- If a function admits a power series expansion, then it is exponentially close to the partial
sums of this power series on strict subdisks of the disk of convergence.
This version provides an upper estimate that decreases both in `‖y‖` and `n`. See also
`HasFPowerSeriesOnBall.uniform_geometric_approx` for a weaker version. -/
theorem HasFPowerSeriesOnBall.uniform_geometric_approx' {r' : ℝ≥0}
(hf : HasFPowerSeriesOnBall f p x r) (h : (r' : ℝ≥0∞) < r) :
∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ y ∈ Metric.ball (0 : E) r', ∀ n,
‖f (x + y) - p.partialSum n y‖ ≤ C * (a * (‖y‖ / r')) ^ n := by
obtain ⟨a, ha, C, hC, hp⟩ : ∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ n, ‖p n‖ * (r' : ℝ) ^ n ≤ C * a ^ n :=
p.norm_mul_pow_le_mul_pow_of_lt_radius (h.trans_le hf.r_le)
refine ⟨a, ha, C / (1 - a), div_pos hC (sub_pos.2 ha.2), fun y hy n => ?_⟩
have yr' : ‖y‖ < r' := by
rw [ball_zero_eq] at hy
exact hy
have hr'0 : 0 < (r' : ℝ) := (norm_nonneg _).trans_lt yr'
have : y ∈ EMetric.ball (0 : E) r := by
refine mem_emetric_ball_zero_iff.2 (lt_trans ?_ h)
exact mod_cast yr'
rw [norm_sub_rev, ← mul_div_right_comm]
have ya : a * (‖y‖ / ↑r') ≤ a :=
mul_le_of_le_one_right ha.1.le (div_le_one_of_le yr'.le r'.coe_nonneg)
suffices ‖p.partialSum n y - f (x + y)‖ ≤ C * (a * (‖y‖ / r')) ^ n / (1 - a * (‖y‖ / r')) by
refine this.trans ?_
have : 0 < a := ha.1
gcongr
apply_rules [sub_pos.2, ha.2]
apply norm_sub_le_of_geometric_bound_of_hasSum (ya.trans_lt ha.2) _ (hf.hasSum this)
intro n
calc
‖(p n) fun _ : Fin n => y‖
_ ≤ ‖p n‖ * ∏ _i : Fin n, ‖y‖ := ContinuousMultilinearMap.le_opNorm _ _
_ = ‖p n‖ * (r' : ℝ) ^ n * (‖y‖ / r') ^ n := by field_simp [mul_right_comm]
_ ≤ C * a ^ n * (‖y‖ / r') ^ n := by gcongr ?_ * _; apply hp
_ ≤ C * (a * (‖y‖ / r')) ^ n := by rw [mul_pow, mul_assoc]
#align has_fpower_series_on_ball.uniform_geometric_approx' HasFPowerSeriesOnBall.uniform_geometric_approx'
/-- If a function admits a power series expansion, then it is exponentially close to the partial
sums of this power series on strict subdisks of the disk of convergence. -/
theorem HasFPowerSeriesOnBall.uniform_geometric_approx {r' : ℝ≥0}
(hf : HasFPowerSeriesOnBall f p x r) (h : (r' : ℝ≥0∞) < r) :
∃ a ∈ Ioo (0 : ℝ) 1,
∃ C > 0, ∀ y ∈ Metric.ball (0 : E) r', ∀ n, ‖f (x + y) - p.partialSum n y‖ ≤ C * a ^ n := by
obtain ⟨a, ha, C, hC, hp⟩ : ∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ y ∈ Metric.ball (0 : E) r', ∀ n,
‖f (x + y) - p.partialSum n y‖ ≤ C * (a * (‖y‖ / r')) ^ n :=
hf.uniform_geometric_approx' h
refine ⟨a, ha, C, hC, fun y hy n => (hp y hy n).trans ?_⟩
have yr' : ‖y‖ < r' := by rwa [ball_zero_eq] at hy
have := ha.1.le -- needed to discharge a side goal on the next line
gcongr
exact mul_le_of_le_one_right ha.1.le (div_le_one_of_le yr'.le r'.coe_nonneg)
#align has_fpower_series_on_ball.uniform_geometric_approx HasFPowerSeriesOnBall.uniform_geometric_approx
/-- Taylor formula for an analytic function, `IsBigO` version. -/
theorem HasFPowerSeriesAt.isBigO_sub_partialSum_pow (hf : HasFPowerSeriesAt f p x) (n : ℕ) :
(fun y : E => f (x + y) - p.partialSum n y) =O[𝓝 0] fun y => ‖y‖ ^ n := by
rcases hf with ⟨r, hf⟩
rcases ENNReal.lt_iff_exists_nnreal_btwn.1 hf.r_pos with ⟨r', r'0, h⟩
obtain ⟨a, -, C, -, hp⟩ : ∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ y ∈ Metric.ball (0 : E) r', ∀ n,
‖f (x + y) - p.partialSum n y‖ ≤ C * (a * (‖y‖ / r')) ^ n :=
hf.uniform_geometric_approx' h
refine isBigO_iff.2 ⟨C * (a / r') ^ n, ?_⟩
replace r'0 : 0 < (r' : ℝ) := mod_cast r'0
filter_upwards [Metric.ball_mem_nhds (0 : E) r'0] with y hy
simpa [mul_pow, mul_div_assoc, mul_assoc, div_mul_eq_mul_div] using hp y hy n
set_option linter.uppercaseLean3 false in
#align has_fpower_series_at.is_O_sub_partial_sum_pow HasFPowerSeriesAt.isBigO_sub_partialSum_pow
/-- If `f` has formal power series `∑ n, pₙ` on a ball of radius `r`, then for `y, z` in any smaller
ball, the norm of the difference `f y - f z - p 1 (fun _ ↦ y - z)` is bounded above by
`C * (max ‖y - x‖ ‖z - x‖) * ‖y - z‖`. This lemma formulates this property using `IsBigO` and
`Filter.principal` on `E × E`. -/
theorem HasFPowerSeriesOnBall.isBigO_image_sub_image_sub_deriv_principal
(hf : HasFPowerSeriesOnBall f p x r) (hr : r' < r) :
(fun y : E × E => f y.1 - f y.2 - p 1 fun _ => y.1 - y.2) =O[𝓟 (EMetric.ball (x, x) r')]
fun y => ‖y - (x, x)‖ * ‖y.1 - y.2‖ := by
lift r' to ℝ≥0 using ne_top_of_lt hr
rcases (zero_le r').eq_or_lt with (rfl | hr'0)
· simp only [isBigO_bot, EMetric.ball_zero, principal_empty, ENNReal.coe_zero]
obtain ⟨a, ha, C, hC : 0 < C, hp⟩ :
∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ n : ℕ, ‖p n‖ * (r' : ℝ) ^ n ≤ C * a ^ n :=
p.norm_mul_pow_le_mul_pow_of_lt_radius (hr.trans_le hf.r_le)
simp only [← le_div_iff (pow_pos (NNReal.coe_pos.2 hr'0) _)] at hp
set L : E × E → ℝ := fun y =>
C * (a / r') ^ 2 * (‖y - (x, x)‖ * ‖y.1 - y.2‖) * (a / (1 - a) ^ 2 + 2 / (1 - a))
have hL : ∀ y ∈ EMetric.ball (x, x) r', ‖f y.1 - f y.2 - p 1 fun _ => y.1 - y.2‖ ≤ L y := by
intro y hy'
have hy : y ∈ EMetric.ball x r ×ˢ EMetric.ball x r := by
rw [EMetric.ball_prod_same]
exact EMetric.ball_subset_ball hr.le hy'
set A : ℕ → F := fun n => (p n fun _ => y.1 - x) - p n fun _ => y.2 - x
have hA : HasSum (fun n => A (n + 2)) (f y.1 - f y.2 - p 1 fun _ => y.1 - y.2) := by
convert (hasSum_nat_add_iff' 2).2 ((hf.hasSum_sub hy.1).sub (hf.hasSum_sub hy.2)) using 1
rw [Finset.sum_range_succ, Finset.sum_range_one, hf.coeff_zero, hf.coeff_zero, sub_self,
zero_add, ← Subsingleton.pi_single_eq (0 : Fin 1) (y.1 - x), Pi.single,
← Subsingleton.pi_single_eq (0 : Fin 1) (y.2 - x), Pi.single, ← (p 1).map_sub, ← Pi.single,
Subsingleton.pi_single_eq, sub_sub_sub_cancel_right]
rw [EMetric.mem_ball, edist_eq_coe_nnnorm_sub, ENNReal.coe_lt_coe] at hy'
set B : ℕ → ℝ := fun n => C * (a / r') ^ 2 * (‖y - (x, x)‖ * ‖y.1 - y.2‖) * ((n + 2) * a ^ n)
have hAB : ∀ n, ‖A (n + 2)‖ ≤ B n := fun n =>
calc
‖A (n + 2)‖ ≤ ‖p (n + 2)‖ * ↑(n + 2) * ‖y - (x, x)‖ ^ (n + 1) * ‖y.1 - y.2‖ := by
-- Porting note: `pi_norm_const` was `pi_norm_const (_ : E)`
simpa only [Fintype.card_fin, pi_norm_const, Prod.norm_def, Pi.sub_def,
Prod.fst_sub, Prod.snd_sub, sub_sub_sub_cancel_right] using
(p <| n + 2).norm_image_sub_le (fun _ => y.1 - x) fun _ => y.2 - x
_ = ‖p (n + 2)‖ * ‖y - (x, x)‖ ^ n * (↑(n + 2) * ‖y - (x, x)‖ * ‖y.1 - y.2‖) := by
rw [pow_succ ‖y - (x, x)‖]
ring
-- Porting note: the two `↑` in `↑r'` are new, without them, Lean fails to synthesize
-- instances `HDiv ℝ ℝ≥0 ?m` or `HMul ℝ ℝ≥0 ?m`
_ ≤ C * a ^ (n + 2) / ↑r' ^ (n + 2)
* ↑r' ^ n * (↑(n + 2) * ‖y - (x, x)‖ * ‖y.1 - y.2‖) := by
have : 0 < a := ha.1
gcongr
· apply hp
· apply hy'.le
_ = B n := by
field_simp [B, pow_succ]
simp only [mul_assoc, mul_comm, mul_left_comm]
have hBL : HasSum B (L y) := by
apply HasSum.mul_left
simp only [add_mul]
have : ‖a‖ < 1 := by simp only [Real.norm_eq_abs, abs_of_pos ha.1, ha.2]
rw [div_eq_mul_inv, div_eq_mul_inv]
exact (hasSum_coe_mul_geometric_of_norm_lt_one this).add -- Porting note: was `convert`!
((hasSum_geometric_of_norm_lt_one this).mul_left 2)
exact hA.norm_le_of_bounded hBL hAB
suffices L =O[𝓟 (EMetric.ball (x, x) r')] fun y => ‖y - (x, x)‖ * ‖y.1 - y.2‖ by
refine (IsBigO.of_bound 1 (eventually_principal.2 fun y hy => ?_)).trans this
rw [one_mul]
exact (hL y hy).trans (le_abs_self _)
simp_rw [L, mul_right_comm _ (_ * _)]
exact (isBigO_refl _ _).const_mul_left _
set_option linter.uppercaseLean3 false in
#align has_fpower_series_on_ball.is_O_image_sub_image_sub_deriv_principal HasFPowerSeriesOnBall.isBigO_image_sub_image_sub_deriv_principal
/-- If `f` has formal power series `∑ n, pₙ` on a ball of radius `r`, then for `y, z` in any smaller
ball, the norm of the difference `f y - f z - p 1 (fun _ ↦ y - z)` is bounded above by
`C * (max ‖y - x‖ ‖z - x‖) * ‖y - z‖`. -/
theorem HasFPowerSeriesOnBall.image_sub_sub_deriv_le (hf : HasFPowerSeriesOnBall f p x r)
(hr : r' < r) :
∃ C, ∀ᵉ (y ∈ EMetric.ball x r') (z ∈ EMetric.ball x r'),
‖f y - f z - p 1 fun _ => y - z‖ ≤ C * max ‖y - x‖ ‖z - x‖ * ‖y - z‖ := by
simpa only [isBigO_principal, mul_assoc, norm_mul, norm_norm, Prod.forall, EMetric.mem_ball,
Prod.edist_eq, max_lt_iff, and_imp, @forall_swap (_ < _) E] using
hf.isBigO_image_sub_image_sub_deriv_principal hr
#align has_fpower_series_on_ball.image_sub_sub_deriv_le HasFPowerSeriesOnBall.image_sub_sub_deriv_le
/-- If `f` has formal power series `∑ n, pₙ` at `x`, then
`f y - f z - p 1 (fun _ ↦ y - z) = O(‖(y, z) - (x, x)‖ * ‖y - z‖)` as `(y, z) → (x, x)`.
In particular, `f` is strictly differentiable at `x`. -/
theorem HasFPowerSeriesAt.isBigO_image_sub_norm_mul_norm_sub (hf : HasFPowerSeriesAt f p x) :
(fun y : E × E => f y.1 - f y.2 - p 1 fun _ => y.1 - y.2) =O[𝓝 (x, x)] fun y =>
‖y - (x, x)‖ * ‖y.1 - y.2‖ := by
rcases hf with ⟨r, hf⟩
rcases ENNReal.lt_iff_exists_nnreal_btwn.1 hf.r_pos with ⟨r', r'0, h⟩
refine (hf.isBigO_image_sub_image_sub_deriv_principal h).mono ?_
exact le_principal_iff.2 (EMetric.ball_mem_nhds _ r'0)
set_option linter.uppercaseLean3 false in
#align has_fpower_series_at.is_O_image_sub_norm_mul_norm_sub HasFPowerSeriesAt.isBigO_image_sub_norm_mul_norm_sub
/-- If a function admits a power series expansion at `x`, then it is the uniform limit of the
partial sums of this power series on strict subdisks of the disk of convergence, i.e., `f (x + y)`
is the uniform limit of `p.partialSum n y` there. -/
theorem HasFPowerSeriesOnBall.tendstoUniformlyOn {r' : ℝ≥0} (hf : HasFPowerSeriesOnBall f p x r)
(h : (r' : ℝ≥0∞) < r) :
TendstoUniformlyOn (fun n y => p.partialSum n y) (fun y => f (x + y)) atTop
(Metric.ball (0 : E) r') := by
obtain ⟨a, ha, C, -, hp⟩ : ∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ y ∈ Metric.ball (0 : E) r', ∀ n,
‖f (x + y) - p.partialSum n y‖ ≤ C * a ^ n := hf.uniform_geometric_approx h
refine Metric.tendstoUniformlyOn_iff.2 fun ε εpos => ?_
have L : Tendsto (fun n => (C : ℝ) * a ^ n) atTop (𝓝 ((C : ℝ) * 0)) :=
tendsto_const_nhds.mul (tendsto_pow_atTop_nhds_zero_of_lt_one ha.1.le ha.2)
rw [mul_zero] at L
refine (L.eventually (gt_mem_nhds εpos)).mono fun n hn y hy => ?_
rw [dist_eq_norm]
exact (hp y hy n).trans_lt hn
#align has_fpower_series_on_ball.tendsto_uniformly_on HasFPowerSeriesOnBall.tendstoUniformlyOn
/-- If a function admits a power series expansion at `x`, then it is the locally uniform limit of
the partial sums of this power series on the disk of convergence, i.e., `f (x + y)`
is the locally uniform limit of `p.partialSum n y` there. -/
theorem HasFPowerSeriesOnBall.tendstoLocallyUniformlyOn (hf : HasFPowerSeriesOnBall f p x r) :
TendstoLocallyUniformlyOn (fun n y => p.partialSum n y) (fun y => f (x + y)) atTop
(EMetric.ball (0 : E) r) := by
intro u hu x hx
rcases ENNReal.lt_iff_exists_nnreal_btwn.1 hx with ⟨r', xr', hr'⟩
have : EMetric.ball (0 : E) r' ∈ 𝓝 x := IsOpen.mem_nhds EMetric.isOpen_ball xr'
refine ⟨EMetric.ball (0 : E) r', mem_nhdsWithin_of_mem_nhds this, ?_⟩
simpa [Metric.emetric_ball_nnreal] using hf.tendstoUniformlyOn hr' u hu
#align has_fpower_series_on_ball.tendsto_locally_uniformly_on HasFPowerSeriesOnBall.tendstoLocallyUniformlyOn
/-- If a function admits a power series expansion at `x`, then it is the uniform limit of the
partial sums of this power series on strict subdisks of the disk of convergence, i.e., `f y`
is the uniform limit of `p.partialSum n (y - x)` there. -/
theorem HasFPowerSeriesOnBall.tendstoUniformlyOn' {r' : ℝ≥0} (hf : HasFPowerSeriesOnBall f p x r)
(h : (r' : ℝ≥0∞) < r) :
TendstoUniformlyOn (fun n y => p.partialSum n (y - x)) f atTop (Metric.ball (x : E) r') := by
convert (hf.tendstoUniformlyOn h).comp fun y => y - x using 1
· simp [(· ∘ ·)]
· ext z
simp [dist_eq_norm]
#align has_fpower_series_on_ball.tendsto_uniformly_on' HasFPowerSeriesOnBall.tendstoUniformlyOn'
/-- If a function admits a power series expansion at `x`, then it is the locally uniform limit of
the partial sums of this power series on the disk of convergence, i.e., `f y`
is the locally uniform limit of `p.partialSum n (y - x)` there. -/
theorem HasFPowerSeriesOnBall.tendstoLocallyUniformlyOn' (hf : HasFPowerSeriesOnBall f p x r) :
TendstoLocallyUniformlyOn (fun n y => p.partialSum n (y - x)) f atTop
(EMetric.ball (x : E) r) := by
have A : ContinuousOn (fun y : E => y - x) (EMetric.ball (x : E) r) :=
(continuous_id.sub continuous_const).continuousOn
convert hf.tendstoLocallyUniformlyOn.comp (fun y : E => y - x) _ A using 1
· ext z
simp
· intro z
simp [edist_eq_coe_nnnorm, edist_eq_coe_nnnorm_sub]
#align has_fpower_series_on_ball.tendsto_locally_uniformly_on' HasFPowerSeriesOnBall.tendstoLocallyUniformlyOn'
/-- If a function admits a power series expansion on a disk, then it is continuous there. -/
protected theorem HasFPowerSeriesOnBall.continuousOn (hf : HasFPowerSeriesOnBall f p x r) :
ContinuousOn f (EMetric.ball x r) :=
hf.tendstoLocallyUniformlyOn'.continuousOn <|
eventually_of_forall fun n =>
((p.partialSum_continuous n).comp (continuous_id.sub continuous_const)).continuousOn
#align has_fpower_series_on_ball.continuous_on HasFPowerSeriesOnBall.continuousOn
protected theorem HasFPowerSeriesAt.continuousAt (hf : HasFPowerSeriesAt f p x) :
ContinuousAt f x :=
let ⟨_, hr⟩ := hf
hr.continuousOn.continuousAt (EMetric.ball_mem_nhds x hr.r_pos)
#align has_fpower_series_at.continuous_at HasFPowerSeriesAt.continuousAt
protected theorem AnalyticAt.continuousAt (hf : AnalyticAt 𝕜 f x) : ContinuousAt f x :=
let ⟨_, hp⟩ := hf
hp.continuousAt
#align analytic_at.continuous_at AnalyticAt.continuousAt
protected theorem AnalyticOn.continuousOn {s : Set E} (hf : AnalyticOn 𝕜 f s) : ContinuousOn f s :=
fun x hx => (hf x hx).continuousAt.continuousWithinAt
#align analytic_on.continuous_on AnalyticOn.continuousOn
/-- Analytic everywhere implies continuous -/
theorem AnalyticOn.continuous {f : E → F} (fa : AnalyticOn 𝕜 f univ) : Continuous f := by
rw [continuous_iff_continuousOn_univ]; exact fa.continuousOn
/-- In a complete space, the sum of a converging power series `p` admits `p` as a power series.
This is not totally obvious as we need to check the convergence of the series. -/
protected theorem FormalMultilinearSeries.hasFPowerSeriesOnBall [CompleteSpace F]
(p : FormalMultilinearSeries 𝕜 E F) (h : 0 < p.radius) :
HasFPowerSeriesOnBall p.sum p 0 p.radius :=
{ r_le := le_rfl
r_pos := h
hasSum := fun hy => by
rw [zero_add]
exact p.hasSum hy }
#align formal_multilinear_series.has_fpower_series_on_ball FormalMultilinearSeries.hasFPowerSeriesOnBall
theorem HasFPowerSeriesOnBall.sum (h : HasFPowerSeriesOnBall f p x r) {y : E}
(hy : y ∈ EMetric.ball (0 : E) r) : f (x + y) = p.sum y :=
(h.hasSum hy).tsum_eq.symm
#align has_fpower_series_on_ball.sum HasFPowerSeriesOnBall.sum
/-- The sum of a converging power series is continuous in its disk of convergence. -/
protected theorem FormalMultilinearSeries.continuousOn [CompleteSpace F] :
ContinuousOn p.sum (EMetric.ball 0 p.radius) := by
rcases (zero_le p.radius).eq_or_lt with h | h
· simp [← h, continuousOn_empty]
· exact (p.hasFPowerSeriesOnBall h).continuousOn
#align formal_multilinear_series.continuous_on FormalMultilinearSeries.continuousOn
end
/-!
### Uniqueness of power series
If a function `f : E → F` has two representations as power series at a point `x : E`, corresponding
to formal multilinear series `p₁` and `p₂`, then these representations agree term-by-term. That is,
for any `n : ℕ` and `y : E`, `p₁ n (fun i ↦ y) = p₂ n (fun i ↦ y)`. In the one-dimensional case,
when `f : 𝕜 → E`, the continuous multilinear maps `p₁ n` and `p₂ n` are given by
`ContinuousMultilinearMap.mkPiRing`, and hence are determined completely by the value of
`p₁ n (fun i ↦ 1)`, so `p₁ = p₂`. Consequently, the radius of convergence for one series can be
transferred to the other.
-/
section Uniqueness
open ContinuousMultilinearMap
theorem Asymptotics.IsBigO.continuousMultilinearMap_apply_eq_zero {n : ℕ} {p : E[×n]→L[𝕜] F}
(h : (fun y => p fun _ => y) =O[𝓝 0] fun y => ‖y‖ ^ (n + 1)) (y : E) : (p fun _ => y) = 0 := by
obtain ⟨c, c_pos, hc⟩ := h.exists_pos
obtain ⟨t, ht, t_open, z_mem⟩ := eventually_nhds_iff.mp (isBigOWith_iff.mp hc)
obtain ⟨δ, δ_pos, δε⟩ := (Metric.isOpen_iff.mp t_open) 0 z_mem
clear h hc z_mem
cases' n with n
· exact norm_eq_zero.mp (by
-- Porting note: the symmetric difference of the `simpa only` sets:
-- added `Nat.zero_eq, zero_add, pow_one`
-- removed `zero_pow, Ne.def, Nat.one_ne_zero, not_false_iff`
simpa only [Nat.zero_eq, fin0_apply_norm, norm_eq_zero, norm_zero, zero_add, pow_one,
mul_zero, norm_le_zero_iff] using ht 0 (δε (Metric.mem_ball_self δ_pos)))
· refine Or.elim (Classical.em (y = 0))
(fun hy => by simpa only [hy] using p.map_zero) fun hy => ?_
replace hy := norm_pos_iff.mpr hy
refine norm_eq_zero.mp (le_antisymm (le_of_forall_pos_le_add fun ε ε_pos => ?_) (norm_nonneg _))
have h₀ := _root_.mul_pos c_pos (pow_pos hy (n.succ + 1))
obtain ⟨k, k_pos, k_norm⟩ := NormedField.exists_norm_lt 𝕜
(lt_min (mul_pos δ_pos (inv_pos.mpr hy)) (mul_pos ε_pos (inv_pos.mpr h₀)))
have h₁ : ‖k • y‖ < δ := by
rw [norm_smul]
exact inv_mul_cancel_right₀ hy.ne.symm δ ▸
mul_lt_mul_of_pos_right (lt_of_lt_of_le k_norm (min_le_left _ _)) hy
have h₂ :=
calc
‖p fun _ => k • y‖ ≤ c * ‖k • y‖ ^ (n.succ + 1) := by
-- Porting note: now Lean wants `_root_.`
simpa only [norm_pow, _root_.norm_norm] using ht (k • y) (δε (mem_ball_zero_iff.mpr h₁))
--simpa only [norm_pow, norm_norm] using ht (k • y) (δε (mem_ball_zero_iff.mpr h₁))
_ = ‖k‖ ^ n.succ * (‖k‖ * (c * ‖y‖ ^ (n.succ + 1))) := by
-- Porting note: added `Nat.succ_eq_add_one` since otherwise `ring` does not conclude.
simp only [norm_smul, mul_pow, Nat.succ_eq_add_one]
-- Porting note: removed `rw [pow_succ]`, since it now becomes superfluous.
ring
have h₃ : ‖k‖ * (c * ‖y‖ ^ (n.succ + 1)) < ε :=
inv_mul_cancel_right₀ h₀.ne.symm ε ▸
mul_lt_mul_of_pos_right (lt_of_lt_of_le k_norm (min_le_right _ _)) h₀
calc
‖p fun _ => y‖ = ‖k⁻¹ ^ n.succ‖ * ‖p fun _ => k • y‖ := by
simpa only [inv_smul_smul₀ (norm_pos_iff.mp k_pos), norm_smul, Finset.prod_const,
Finset.card_fin] using
congr_arg norm (p.map_smul_univ (fun _ : Fin n.succ => k⁻¹) fun _ : Fin n.succ => k • y)
_ ≤ ‖k⁻¹ ^ n.succ‖ * (‖k‖ ^ n.succ * (‖k‖ * (c * ‖y‖ ^ (n.succ + 1)))) := by gcongr
_ = ‖(k⁻¹ * k) ^ n.succ‖ * (‖k‖ * (c * ‖y‖ ^ (n.succ + 1))) := by
rw [← mul_assoc]
simp [norm_mul, mul_pow]
_ ≤ 0 + ε := by
rw [inv_mul_cancel (norm_pos_iff.mp k_pos)]
simpa using h₃.le
set_option linter.uppercaseLean3 false in
#align asymptotics.is_O.continuous_multilinear_map_apply_eq_zero Asymptotics.IsBigO.continuousMultilinearMap_apply_eq_zero
/-- If a formal multilinear series `p` represents the zero function at `x : E`, then the
terms `p n (fun i ↦ y)` appearing in the sum are zero for any `n : ℕ`, `y : E`. -/
theorem HasFPowerSeriesAt.apply_eq_zero {p : FormalMultilinearSeries 𝕜 E F} {x : E}
(h : HasFPowerSeriesAt 0 p x) (n : ℕ) : ∀ y : E, (p n fun _ => y) = 0 := by
refine Nat.strong_induction_on n fun k hk => ?_
have psum_eq : p.partialSum (k + 1) = fun y => p k fun _ => y := by
funext z
refine Finset.sum_eq_single _ (fun b hb hnb => ?_) fun hn => ?_
· have := Finset.mem_range_succ_iff.mp hb
simp only [hk b (this.lt_of_ne hnb), Pi.zero_apply]
· exact False.elim (hn (Finset.mem_range.mpr (lt_add_one k)))
replace h := h.isBigO_sub_partialSum_pow k.succ
simp only [psum_eq, zero_sub, Pi.zero_apply, Asymptotics.isBigO_neg_left] at h
exact h.continuousMultilinearMap_apply_eq_zero
#align has_fpower_series_at.apply_eq_zero HasFPowerSeriesAt.apply_eq_zero
/-- A one-dimensional formal multilinear series representing the zero function is zero. -/
theorem HasFPowerSeriesAt.eq_zero {p : FormalMultilinearSeries 𝕜 𝕜 E} {x : 𝕜}
(h : HasFPowerSeriesAt 0 p x) : p = 0 := by
-- Porting note: `funext; ext` was `ext (n x)`
funext n
ext x
rw [← mkPiRing_apply_one_eq_self (p n)]
simp [h.apply_eq_zero n 1]
#align has_fpower_series_at.eq_zero HasFPowerSeriesAt.eq_zero
/-- One-dimensional formal multilinear series representing the same function are equal. -/
theorem HasFPowerSeriesAt.eq_formalMultilinearSeries {p₁ p₂ : FormalMultilinearSeries 𝕜 𝕜 E}
{f : 𝕜 → E} {x : 𝕜} (h₁ : HasFPowerSeriesAt f p₁ x) (h₂ : HasFPowerSeriesAt f p₂ x) : p₁ = p₂ :=
sub_eq_zero.mp (HasFPowerSeriesAt.eq_zero (by simpa only [sub_self] using h₁.sub h₂))
#align has_fpower_series_at.eq_formal_multilinear_series HasFPowerSeriesAt.eq_formalMultilinearSeries
theorem HasFPowerSeriesAt.eq_formalMultilinearSeries_of_eventually
{p q : FormalMultilinearSeries 𝕜 𝕜 E} {f g : 𝕜 → E} {x : 𝕜} (hp : HasFPowerSeriesAt f p x)
(hq : HasFPowerSeriesAt g q x) (heq : ∀ᶠ z in 𝓝 x, f z = g z) : p = q :=
(hp.congr heq).eq_formalMultilinearSeries hq
#align has_fpower_series_at.eq_formal_multilinear_series_of_eventually HasFPowerSeriesAt.eq_formalMultilinearSeries_of_eventually
/-- A one-dimensional formal multilinear series representing a locally zero function is zero. -/
theorem HasFPowerSeriesAt.eq_zero_of_eventually {p : FormalMultilinearSeries 𝕜 𝕜 E} {f : 𝕜 → E}
{x : 𝕜} (hp : HasFPowerSeriesAt f p x) (hf : f =ᶠ[𝓝 x] 0) : p = 0 :=
(hp.congr hf).eq_zero
#align has_fpower_series_at.eq_zero_of_eventually HasFPowerSeriesAt.eq_zero_of_eventually
/-- If a function `f : 𝕜 → E` has two power series representations at `x`, then the given radii in
which convergence is guaranteed may be interchanged. This can be useful when the formal multilinear
series in one representation has a particularly nice form, but the other has a larger radius. -/
theorem HasFPowerSeriesOnBall.exchange_radius {p₁ p₂ : FormalMultilinearSeries 𝕜 𝕜 E} {f : 𝕜 → E}
{r₁ r₂ : ℝ≥0∞} {x : 𝕜} (h₁ : HasFPowerSeriesOnBall f p₁ x r₁)
(h₂ : HasFPowerSeriesOnBall f p₂ x r₂) : HasFPowerSeriesOnBall f p₁ x r₂ :=
h₂.hasFPowerSeriesAt.eq_formalMultilinearSeries h₁.hasFPowerSeriesAt ▸ h₂
#align has_fpower_series_on_ball.exchange_radius HasFPowerSeriesOnBall.exchange_radius
/-- If a function `f : 𝕜 → E` has power series representation `p` on a ball of some radius and for
each positive radius it has some power series representation, then `p` converges to `f` on the whole
`𝕜`. -/
theorem HasFPowerSeriesOnBall.r_eq_top_of_exists {f : 𝕜 → E} {r : ℝ≥0∞} {x : 𝕜}
{p : FormalMultilinearSeries 𝕜 𝕜 E} (h : HasFPowerSeriesOnBall f p x r)
(h' : ∀ (r' : ℝ≥0) (_ : 0 < r'), ∃ p' : FormalMultilinearSeries 𝕜 𝕜 E,
HasFPowerSeriesOnBall f p' x r') :
HasFPowerSeriesOnBall f p x ∞ :=
{ r_le := ENNReal.le_of_forall_pos_nnreal_lt fun r hr _ =>
let ⟨_, hp'⟩ := h' r hr
(h.exchange_radius hp').r_le
r_pos := ENNReal.coe_lt_top
hasSum := fun {y} _ =>
let ⟨r', hr'⟩ := exists_gt ‖y‖₊
let ⟨_, hp'⟩ := h' r' hr'.ne_bot.bot_lt
(h.exchange_radius hp').hasSum <| mem_emetric_ball_zero_iff.mpr (ENNReal.coe_lt_coe.2 hr') }
#align has_fpower_series_on_ball.r_eq_top_of_exists HasFPowerSeriesOnBall.r_eq_top_of_exists
end Uniqueness
/-!
### Changing origin in a power series
If a function is analytic in a disk `D(x, R)`, then it is analytic in any disk contained in that
one. Indeed, one can write
$$
f (x + y + z) = \sum_{n} p_n (y + z)^n = \sum_{n, k} \binom{n}{k} p_n y^{n-k} z^k
= \sum_{k} \Bigl(\sum_{n} \binom{n}{k} p_n y^{n-k}\Bigr) z^k.
$$
The corresponding power series has thus a `k`-th coefficient equal to
$\sum_{n} \binom{n}{k} p_n y^{n-k}$. In the general case where `pₙ` is a multilinear map, this has
to be interpreted suitably: instead of having a binomial coefficient, one should sum over all
possible subsets `s` of `Fin n` of cardinality `k`, and attribute `z` to the indices in `s` and
`y` to the indices outside of `s`.
In this paragraph, we implement this. The new power series is called `p.changeOrigin y`. Then, we
check its convergence and the fact that its sum coincides with the original sum. The outcome of this
discussion is that the set of points where a function is analytic is open.
-/
namespace FormalMultilinearSeries
section
variable (p : FormalMultilinearSeries 𝕜 E F) {x y : E} {r R : ℝ≥0}
/-- A term of `FormalMultilinearSeries.changeOriginSeries`.
Given a formal multilinear series `p` and a point `x` in its ball of convergence,
`p.changeOrigin x` is a formal multilinear series such that
`p.sum (x+y) = (p.changeOrigin x).sum y` when this makes sense. Each term of `p.changeOrigin x`
is itself an analytic function of `x` given by the series `p.changeOriginSeries`. Each term in
`changeOriginSeries` is the sum of `changeOriginSeriesTerm`'s over all `s` of cardinality `l`.
The definition is such that `p.changeOriginSeriesTerm k l s hs (fun _ ↦ x) (fun _ ↦ y) =
p (k + l) (s.piecewise (fun _ ↦ x) (fun _ ↦ y))`
-/
def changeOriginSeriesTerm (k l : ℕ) (s : Finset (Fin (k + l))) (hs : s.card = l) :
E[×l]→L[𝕜] E[×k]→L[𝕜] F := by
let a := ContinuousMultilinearMap.curryFinFinset 𝕜 E F hs
(by erw [Finset.card_compl, Fintype.card_fin, hs, add_tsub_cancel_right])
exact a (p (k + l))
#align formal_multilinear_series.change_origin_series_term FormalMultilinearSeries.changeOriginSeriesTerm
theorem changeOriginSeriesTerm_apply (k l : ℕ) (s : Finset (Fin (k + l))) (hs : s.card = l)
(x y : E) :
(p.changeOriginSeriesTerm k l s hs (fun _ => x) fun _ => y) =
p (k + l) (s.piecewise (fun _ => x) fun _ => y) :=
ContinuousMultilinearMap.curryFinFinset_apply_const _ _ _ _ _
#align formal_multilinear_series.change_origin_series_term_apply FormalMultilinearSeries.changeOriginSeriesTerm_apply
@[simp]
theorem norm_changeOriginSeriesTerm (k l : ℕ) (s : Finset (Fin (k + l))) (hs : s.card = l) :
‖p.changeOriginSeriesTerm k l s hs‖ = ‖p (k + l)‖ := by
simp only [changeOriginSeriesTerm, LinearIsometryEquiv.norm_map]
#align formal_multilinear_series.norm_change_origin_series_term FormalMultilinearSeries.norm_changeOriginSeriesTerm
@[simp]
theorem nnnorm_changeOriginSeriesTerm (k l : ℕ) (s : Finset (Fin (k + l))) (hs : s.card = l) :
‖p.changeOriginSeriesTerm k l s hs‖₊ = ‖p (k + l)‖₊ := by
simp only [changeOriginSeriesTerm, LinearIsometryEquiv.nnnorm_map]
#align formal_multilinear_series.nnnorm_change_origin_series_term FormalMultilinearSeries.nnnorm_changeOriginSeriesTerm
theorem nnnorm_changeOriginSeriesTerm_apply_le (k l : ℕ) (s : Finset (Fin (k + l)))
(hs : s.card = l) (x y : E) :
‖p.changeOriginSeriesTerm k l s hs (fun _ => x) fun _ => y‖₊ ≤
‖p (k + l)‖₊ * ‖x‖₊ ^ l * ‖y‖₊ ^ k := by
rw [← p.nnnorm_changeOriginSeriesTerm k l s hs, ← Fin.prod_const, ← Fin.prod_const]
apply ContinuousMultilinearMap.le_of_opNNNorm_le
apply ContinuousMultilinearMap.le_opNNNorm
#align formal_multilinear_series.nnnorm_change_origin_series_term_apply_le FormalMultilinearSeries.nnnorm_changeOriginSeriesTerm_apply_le
/-- The power series for `f.changeOrigin k`.
Given a formal multilinear series `p` and a point `x` in its ball of convergence,
`p.changeOrigin x` is a formal multilinear series such that
`p.sum (x+y) = (p.changeOrigin x).sum y` when this makes sense. Its `k`-th term is the sum of
the series `p.changeOriginSeries k`. -/
def changeOriginSeries (k : ℕ) : FormalMultilinearSeries 𝕜 E (E[×k]→L[𝕜] F) := fun l =>
∑ s : { s : Finset (Fin (k + l)) // Finset.card s = l }, p.changeOriginSeriesTerm k l s s.2
#align formal_multilinear_series.change_origin_series FormalMultilinearSeries.changeOriginSeries
theorem nnnorm_changeOriginSeries_le_tsum (k l : ℕ) :
‖p.changeOriginSeries k l‖₊ ≤
∑' _ : { s : Finset (Fin (k + l)) // s.card = l }, ‖p (k + l)‖₊ :=
(nnnorm_sum_le _ (fun t => changeOriginSeriesTerm p k l (Subtype.val t) t.prop)).trans_eq <| by
simp_rw [tsum_fintype, nnnorm_changeOriginSeriesTerm (p := p) (k := k) (l := l)]
#align formal_multilinear_series.nnnorm_change_origin_series_le_tsum FormalMultilinearSeries.nnnorm_changeOriginSeries_le_tsum
| Mathlib/Analysis/Analytic/Basic.lean | 1,164 | 1,168 | theorem nnnorm_changeOriginSeries_apply_le_tsum (k l : ℕ) (x : E) :
‖p.changeOriginSeries k l fun _ => x‖₊ ≤
∑' _ : { s : Finset (Fin (k + l)) // s.card = l }, ‖p (k + l)‖₊ * ‖x‖₊ ^ l := by |
rw [NNReal.tsum_mul_right, ← Fin.prod_const]
exact (p.changeOriginSeries k l).le_of_opNNNorm_le _ (p.nnnorm_changeOriginSeries_le_tsum _ _)
|
/-
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
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
theorem absNorm_ne_zero_of_nonZeroDivisors (I : (Ideal S)⁰) : Ideal.absNorm (I : Ideal S) ≠ 0 :=
Ideal.absNorm_eq_zero_iff.not.mpr <| nonZeroDivisors.coe_ne_zero _
theorem irreducible_of_irreducible_absNorm {I : Ideal S} (hI : Irreducible (Ideal.absNorm I)) :
Irreducible I :=
irreducible_iff.mpr
⟨fun h =>
hI.not_unit (by simpa only [Ideal.isUnit_iff, Nat.isUnit_iff, absNorm_eq_one_iff] using h),
by
rintro a b rfl
simpa only [Ideal.isUnit_iff, Nat.isUnit_iff, absNorm_eq_one_iff] using
hI.isUnit_or_isUnit (_root_.map_mul absNorm a b)⟩
#align ideal.irreducible_of_irreducible_abs_norm Ideal.irreducible_of_irreducible_absNorm
theorem isPrime_of_irreducible_absNorm {I : Ideal S} (hI : Irreducible (Ideal.absNorm I)) :
I.IsPrime :=
isPrime_of_prime
(UniqueFactorizationMonoid.irreducible_iff_prime.mp (irreducible_of_irreducible_absNorm hI))
#align ideal.is_prime_of_irreducible_abs_norm Ideal.isPrime_of_irreducible_absNorm
theorem prime_of_irreducible_absNorm_span {a : S} (ha : a ≠ 0)
(hI : Irreducible (Ideal.absNorm (Ideal.span ({a} : Set S)))) : Prime a :=
(Ideal.span_singleton_prime ha).mp (isPrime_of_irreducible_absNorm hI)
#align ideal.prime_of_irreducible_abs_norm_span Ideal.prime_of_irreducible_absNorm_span
| Mathlib/RingTheory/Ideal/Norm.lean | 436 | 438 | theorem absNorm_mem (I : Ideal S) : ↑(Ideal.absNorm I) ∈ I := by |
rw [absNorm_apply, cardQuot, ← Ideal.Quotient.eq_zero_iff_mem, map_natCast,
Quotient.index_eq_zero]
|
/-
Copyright (c) 2019 Calle Sönne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Calle Sönne
-/
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic
import Mathlib.Analysis.Normed.Group.AddCircle
import Mathlib.Algebra.CharZero.Quotient
import Mathlib.Topology.Instances.Sign
#align_import analysis.special_functions.trigonometric.angle from "leanprover-community/mathlib"@"213b0cff7bc5ab6696ee07cceec80829ce42efec"
/-!
# The type of angles
In this file we define `Real.Angle` to be the quotient group `ℝ/2πℤ` and prove a few simple lemmas
about trigonometric functions and angles.
-/
open Real
noncomputable section
namespace Real
-- Porting note: can't derive `NormedAddCommGroup, Inhabited`
/-- The type of angles -/
def Angle : Type :=
AddCircle (2 * π)
#align real.angle Real.Angle
namespace Angle
-- Porting note (#10754): added due to missing instances due to no deriving
instance : NormedAddCommGroup Angle :=
inferInstanceAs (NormedAddCommGroup (AddCircle (2 * π)))
-- Porting note (#10754): added due to missing instances due to no deriving
instance : Inhabited Angle :=
inferInstanceAs (Inhabited (AddCircle (2 * π)))
-- Porting note (#10754): added due to missing instances due to no deriving
-- also, without this, a plain `QuotientAddGroup.mk`
-- causes coerced terms to be of type `ℝ ⧸ AddSubgroup.zmultiples (2 * π)`
/-- The canonical map from `ℝ` to the quotient `Angle`. -/
@[coe]
protected def coe (r : ℝ) : Angle := QuotientAddGroup.mk r
instance : Coe ℝ Angle := ⟨Angle.coe⟩
instance : CircularOrder Real.Angle :=
QuotientAddGroup.circularOrder (hp' := ⟨by norm_num [pi_pos]⟩)
@[continuity]
theorem continuous_coe : Continuous ((↑) : ℝ → Angle) :=
continuous_quotient_mk'
#align real.angle.continuous_coe Real.Angle.continuous_coe
/-- Coercion `ℝ → Angle` as an additive homomorphism. -/
def coeHom : ℝ →+ Angle :=
QuotientAddGroup.mk' _
#align real.angle.coe_hom Real.Angle.coeHom
@[simp]
theorem coe_coeHom : (coeHom : ℝ → Angle) = ((↑) : ℝ → Angle) :=
rfl
#align real.angle.coe_coe_hom Real.Angle.coe_coeHom
/-- An induction principle to deduce results for `Angle` from those for `ℝ`, used with
`induction θ using Real.Angle.induction_on`. -/
@[elab_as_elim]
protected theorem induction_on {p : Angle → Prop} (θ : Angle) (h : ∀ x : ℝ, p x) : p θ :=
Quotient.inductionOn' θ h
#align real.angle.induction_on Real.Angle.induction_on
@[simp]
theorem coe_zero : ↑(0 : ℝ) = (0 : Angle) :=
rfl
#align real.angle.coe_zero Real.Angle.coe_zero
@[simp]
theorem coe_add (x y : ℝ) : ↑(x + y : ℝ) = (↑x + ↑y : Angle) :=
rfl
#align real.angle.coe_add Real.Angle.coe_add
@[simp]
theorem coe_neg (x : ℝ) : ↑(-x : ℝ) = -(↑x : Angle) :=
rfl
#align real.angle.coe_neg Real.Angle.coe_neg
@[simp]
theorem coe_sub (x y : ℝ) : ↑(x - y : ℝ) = (↑x - ↑y : Angle) :=
rfl
#align real.angle.coe_sub Real.Angle.coe_sub
theorem coe_nsmul (n : ℕ) (x : ℝ) : ↑(n • x : ℝ) = n • (↑x : Angle) :=
rfl
#align real.angle.coe_nsmul Real.Angle.coe_nsmul
theorem coe_zsmul (z : ℤ) (x : ℝ) : ↑(z • x : ℝ) = z • (↑x : Angle) :=
rfl
#align real.angle.coe_zsmul Real.Angle.coe_zsmul
@[simp, norm_cast]
theorem natCast_mul_eq_nsmul (x : ℝ) (n : ℕ) : ↑((n : ℝ) * x) = n • (↑x : Angle) := by
simpa only [nsmul_eq_mul] using coeHom.map_nsmul x n
#align real.angle.coe_nat_mul_eq_nsmul Real.Angle.natCast_mul_eq_nsmul
@[simp, norm_cast]
theorem intCast_mul_eq_zsmul (x : ℝ) (n : ℤ) : ↑((n : ℝ) * x : ℝ) = n • (↑x : Angle) := by
simpa only [zsmul_eq_mul] using coeHom.map_zsmul x n
#align real.angle.coe_int_mul_eq_zsmul Real.Angle.intCast_mul_eq_zsmul
@[deprecated (since := "2024-05-25")] alias coe_nat_mul_eq_nsmul := natCast_mul_eq_nsmul
@[deprecated (since := "2024-05-25")] alias coe_int_mul_eq_zsmul := intCast_mul_eq_zsmul
theorem angle_eq_iff_two_pi_dvd_sub {ψ θ : ℝ} : (θ : Angle) = ψ ↔ ∃ k : ℤ, θ - ψ = 2 * π * k := by
simp only [QuotientAddGroup.eq, AddSubgroup.zmultiples_eq_closure,
AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm]
-- Porting note: added `rw`, `simp [Angle.coe, QuotientAddGroup.eq]` doesn't fire otherwise
rw [Angle.coe, Angle.coe, QuotientAddGroup.eq]
simp only [AddSubgroup.zmultiples_eq_closure,
AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm]
#align real.angle.angle_eq_iff_two_pi_dvd_sub Real.Angle.angle_eq_iff_two_pi_dvd_sub
@[simp]
theorem coe_two_pi : ↑(2 * π : ℝ) = (0 : Angle) :=
angle_eq_iff_two_pi_dvd_sub.2 ⟨1, by rw [sub_zero, Int.cast_one, mul_one]⟩
#align real.angle.coe_two_pi Real.Angle.coe_two_pi
@[simp]
theorem neg_coe_pi : -(π : Angle) = π := by
rw [← coe_neg, angle_eq_iff_two_pi_dvd_sub]
use -1
simp [two_mul, sub_eq_add_neg]
#align real.angle.neg_coe_pi Real.Angle.neg_coe_pi
@[simp]
theorem two_nsmul_coe_div_two (θ : ℝ) : (2 : ℕ) • (↑(θ / 2) : Angle) = θ := by
rw [← coe_nsmul, two_nsmul, add_halves]
#align real.angle.two_nsmul_coe_div_two Real.Angle.two_nsmul_coe_div_two
@[simp]
theorem two_zsmul_coe_div_two (θ : ℝ) : (2 : ℤ) • (↑(θ / 2) : Angle) = θ := by
rw [← coe_zsmul, two_zsmul, add_halves]
#align real.angle.two_zsmul_coe_div_two Real.Angle.two_zsmul_coe_div_two
-- Porting note (#10618): @[simp] can prove it
theorem two_nsmul_neg_pi_div_two : (2 : ℕ) • (↑(-π / 2) : Angle) = π := by
rw [two_nsmul_coe_div_two, coe_neg, neg_coe_pi]
#align real.angle.two_nsmul_neg_pi_div_two Real.Angle.two_nsmul_neg_pi_div_two
-- Porting note (#10618): @[simp] can prove it
theorem two_zsmul_neg_pi_div_two : (2 : ℤ) • (↑(-π / 2) : Angle) = π := by
rw [two_zsmul, ← two_nsmul, two_nsmul_neg_pi_div_two]
#align real.angle.two_zsmul_neg_pi_div_two Real.Angle.two_zsmul_neg_pi_div_two
theorem sub_coe_pi_eq_add_coe_pi (θ : Angle) : θ - π = θ + π := by
rw [sub_eq_add_neg, neg_coe_pi]
#align real.angle.sub_coe_pi_eq_add_coe_pi Real.Angle.sub_coe_pi_eq_add_coe_pi
@[simp]
theorem two_nsmul_coe_pi : (2 : ℕ) • (π : Angle) = 0 := by simp [← natCast_mul_eq_nsmul]
#align real.angle.two_nsmul_coe_pi Real.Angle.two_nsmul_coe_pi
@[simp]
theorem two_zsmul_coe_pi : (2 : ℤ) • (π : Angle) = 0 := by simp [← intCast_mul_eq_zsmul]
#align real.angle.two_zsmul_coe_pi Real.Angle.two_zsmul_coe_pi
@[simp]
theorem coe_pi_add_coe_pi : (π : Real.Angle) + π = 0 := by rw [← two_nsmul, two_nsmul_coe_pi]
#align real.angle.coe_pi_add_coe_pi Real.Angle.coe_pi_add_coe_pi
theorem zsmul_eq_iff {ψ θ : Angle} {z : ℤ} (hz : z ≠ 0) :
z • ψ = z • θ ↔ ∃ k : Fin z.natAbs, ψ = θ + (k : ℕ) • (2 * π / z : ℝ) :=
QuotientAddGroup.zmultiples_zsmul_eq_zsmul_iff hz
#align real.angle.zsmul_eq_iff Real.Angle.zsmul_eq_iff
theorem nsmul_eq_iff {ψ θ : Angle} {n : ℕ} (hz : n ≠ 0) :
n • ψ = n • θ ↔ ∃ k : Fin n, ψ = θ + (k : ℕ) • (2 * π / n : ℝ) :=
QuotientAddGroup.zmultiples_nsmul_eq_nsmul_iff hz
#align real.angle.nsmul_eq_iff Real.Angle.nsmul_eq_iff
theorem two_zsmul_eq_iff {ψ θ : Angle} : (2 : ℤ) • ψ = (2 : ℤ) • θ ↔ ψ = θ ∨ ψ = θ + ↑π := by
-- Porting note: no `Int.natAbs_bit0` anymore
have : Int.natAbs 2 = 2 := rfl
rw [zsmul_eq_iff two_ne_zero, this, Fin.exists_fin_two, Fin.val_zero,
Fin.val_one, zero_smul, add_zero, one_smul, Int.cast_two,
mul_div_cancel_left₀ (_ : ℝ) two_ne_zero]
#align real.angle.two_zsmul_eq_iff Real.Angle.two_zsmul_eq_iff
theorem two_nsmul_eq_iff {ψ θ : Angle} : (2 : ℕ) • ψ = (2 : ℕ) • θ ↔ ψ = θ ∨ ψ = θ + ↑π := by
simp_rw [← natCast_zsmul, Nat.cast_ofNat, two_zsmul_eq_iff]
#align real.angle.two_nsmul_eq_iff Real.Angle.two_nsmul_eq_iff
theorem two_nsmul_eq_zero_iff {θ : Angle} : (2 : ℕ) • θ = 0 ↔ θ = 0 ∨ θ = π := by
convert two_nsmul_eq_iff <;> simp
#align real.angle.two_nsmul_eq_zero_iff Real.Angle.two_nsmul_eq_zero_iff
theorem two_nsmul_ne_zero_iff {θ : Angle} : (2 : ℕ) • θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by
rw [← not_or, ← two_nsmul_eq_zero_iff]
#align real.angle.two_nsmul_ne_zero_iff Real.Angle.two_nsmul_ne_zero_iff
theorem two_zsmul_eq_zero_iff {θ : Angle} : (2 : ℤ) • θ = 0 ↔ θ = 0 ∨ θ = π := by
simp_rw [two_zsmul, ← two_nsmul, two_nsmul_eq_zero_iff]
#align real.angle.two_zsmul_eq_zero_iff Real.Angle.two_zsmul_eq_zero_iff
theorem two_zsmul_ne_zero_iff {θ : Angle} : (2 : ℤ) • θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by
rw [← not_or, ← two_zsmul_eq_zero_iff]
#align real.angle.two_zsmul_ne_zero_iff Real.Angle.two_zsmul_ne_zero_iff
theorem eq_neg_self_iff {θ : Angle} : θ = -θ ↔ θ = 0 ∨ θ = π := by
rw [← add_eq_zero_iff_eq_neg, ← two_nsmul, two_nsmul_eq_zero_iff]
#align real.angle.eq_neg_self_iff Real.Angle.eq_neg_self_iff
theorem ne_neg_self_iff {θ : Angle} : θ ≠ -θ ↔ θ ≠ 0 ∧ θ ≠ π := by
rw [← not_or, ← eq_neg_self_iff.not]
#align real.angle.ne_neg_self_iff Real.Angle.ne_neg_self_iff
theorem neg_eq_self_iff {θ : Angle} : -θ = θ ↔ θ = 0 ∨ θ = π := by rw [eq_comm, eq_neg_self_iff]
#align real.angle.neg_eq_self_iff Real.Angle.neg_eq_self_iff
theorem neg_ne_self_iff {θ : Angle} : -θ ≠ θ ↔ θ ≠ 0 ∧ θ ≠ π := by
rw [← not_or, ← neg_eq_self_iff.not]
#align real.angle.neg_ne_self_iff Real.Angle.neg_ne_self_iff
theorem two_nsmul_eq_pi_iff {θ : Angle} : (2 : ℕ) • θ = π ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by
have h : (π : Angle) = ((2 : ℕ) • (π / 2 : ℝ) :) := by rw [two_nsmul, add_halves]
nth_rw 1 [h]
rw [coe_nsmul, two_nsmul_eq_iff]
-- Porting note: `congr` didn't simplify the goal of iff of `Or`s
convert Iff.rfl
rw [add_comm, ← coe_add, ← sub_eq_zero, ← coe_sub, neg_div, ← neg_sub, sub_neg_eq_add, add_assoc,
add_halves, ← two_mul, coe_neg, coe_two_pi, neg_zero]
#align real.angle.two_nsmul_eq_pi_iff Real.Angle.two_nsmul_eq_pi_iff
theorem two_zsmul_eq_pi_iff {θ : Angle} : (2 : ℤ) • θ = π ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by
rw [two_zsmul, ← two_nsmul, two_nsmul_eq_pi_iff]
#align real.angle.two_zsmul_eq_pi_iff Real.Angle.two_zsmul_eq_pi_iff
theorem cos_eq_iff_coe_eq_or_eq_neg {θ ψ : ℝ} :
cos θ = cos ψ ↔ (θ : Angle) = ψ ∨ (θ : Angle) = -ψ := by
constructor
· intro Hcos
rw [← sub_eq_zero, cos_sub_cos, mul_eq_zero, mul_eq_zero, neg_eq_zero,
eq_false (two_ne_zero' ℝ), false_or_iff, sin_eq_zero_iff, sin_eq_zero_iff] at Hcos
rcases Hcos with (⟨n, hn⟩ | ⟨n, hn⟩)
· right
rw [eq_div_iff_mul_eq (two_ne_zero' ℝ), ← sub_eq_iff_eq_add] at hn
rw [← hn, coe_sub, eq_neg_iff_add_eq_zero, sub_add_cancel, mul_assoc, intCast_mul_eq_zsmul,
mul_comm, coe_two_pi, zsmul_zero]
· left
rw [eq_div_iff_mul_eq (two_ne_zero' ℝ), eq_sub_iff_add_eq] at hn
rw [← hn, coe_add, mul_assoc, intCast_mul_eq_zsmul, mul_comm, coe_two_pi, zsmul_zero,
zero_add]
· rw [angle_eq_iff_two_pi_dvd_sub, ← coe_neg, angle_eq_iff_two_pi_dvd_sub]
rintro (⟨k, H⟩ | ⟨k, H⟩)
· rw [← sub_eq_zero, cos_sub_cos, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ),
mul_comm π _, sin_int_mul_pi, mul_zero]
rw [← sub_eq_zero, cos_sub_cos, ← sub_neg_eq_add, H, mul_assoc 2 π k,
mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero,
zero_mul]
#align real.angle.cos_eq_iff_coe_eq_or_eq_neg Real.Angle.cos_eq_iff_coe_eq_or_eq_neg
theorem sin_eq_iff_coe_eq_or_add_eq_pi {θ ψ : ℝ} :
sin θ = sin ψ ↔ (θ : Angle) = ψ ∨ (θ : Angle) + ψ = π := by
constructor
· intro Hsin
rw [← cos_pi_div_two_sub, ← cos_pi_div_two_sub] at Hsin
cases' cos_eq_iff_coe_eq_or_eq_neg.mp Hsin with h h
· left
rw [coe_sub, coe_sub] at h
exact sub_right_inj.1 h
right
rw [coe_sub, coe_sub, eq_neg_iff_add_eq_zero, add_sub, sub_add_eq_add_sub, ← coe_add,
add_halves, sub_sub, sub_eq_zero] at h
exact h.symm
· rw [angle_eq_iff_two_pi_dvd_sub, ← eq_sub_iff_add_eq, ← coe_sub, angle_eq_iff_two_pi_dvd_sub]
rintro (⟨k, H⟩ | ⟨k, H⟩)
· rw [← sub_eq_zero, sin_sub_sin, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ),
mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul]
have H' : θ + ψ = 2 * k * π + π := by
rwa [← sub_add, sub_add_eq_add_sub, sub_eq_iff_eq_add, mul_assoc, mul_comm π _, ←
mul_assoc] at H
rw [← sub_eq_zero, sin_sub_sin, H', add_div, mul_assoc 2 _ π,
mul_div_cancel_left₀ _ (two_ne_zero' ℝ), cos_add_pi_div_two, sin_int_mul_pi, neg_zero,
mul_zero]
#align real.angle.sin_eq_iff_coe_eq_or_add_eq_pi Real.Angle.sin_eq_iff_coe_eq_or_add_eq_pi
theorem cos_sin_inj {θ ψ : ℝ} (Hcos : cos θ = cos ψ) (Hsin : sin θ = sin ψ) : (θ : Angle) = ψ := by
cases' cos_eq_iff_coe_eq_or_eq_neg.mp Hcos with hc hc; · exact hc
cases' sin_eq_iff_coe_eq_or_add_eq_pi.mp Hsin with hs hs; · exact hs
rw [eq_neg_iff_add_eq_zero, hs] at hc
obtain ⟨n, hn⟩ : ∃ n, n • _ = _ := QuotientAddGroup.leftRel_apply.mp (Quotient.exact' hc)
rw [← neg_one_mul, add_zero, ← sub_eq_zero, zsmul_eq_mul, ← mul_assoc, ← sub_mul, mul_eq_zero,
eq_false (ne_of_gt pi_pos), or_false_iff, sub_neg_eq_add, ← Int.cast_zero, ← Int.cast_one,
← Int.cast_ofNat, ← Int.cast_mul, ← Int.cast_add, Int.cast_inj] at hn
have : (n * 2 + 1) % (2 : ℤ) = 0 % (2 : ℤ) := congr_arg (· % (2 : ℤ)) hn
rw [add_comm, Int.add_mul_emod_self] at this
exact absurd this one_ne_zero
#align real.angle.cos_sin_inj Real.Angle.cos_sin_inj
/-- The sine of a `Real.Angle`. -/
def sin (θ : Angle) : ℝ :=
sin_periodic.lift θ
#align real.angle.sin Real.Angle.sin
@[simp]
theorem sin_coe (x : ℝ) : sin (x : Angle) = Real.sin x :=
rfl
#align real.angle.sin_coe Real.Angle.sin_coe
@[continuity]
theorem continuous_sin : Continuous sin :=
Real.continuous_sin.quotient_liftOn' _
#align real.angle.continuous_sin Real.Angle.continuous_sin
/-- The cosine of a `Real.Angle`. -/
def cos (θ : Angle) : ℝ :=
cos_periodic.lift θ
#align real.angle.cos Real.Angle.cos
@[simp]
theorem cos_coe (x : ℝ) : cos (x : Angle) = Real.cos x :=
rfl
#align real.angle.cos_coe Real.Angle.cos_coe
@[continuity]
theorem continuous_cos : Continuous cos :=
Real.continuous_cos.quotient_liftOn' _
#align real.angle.continuous_cos Real.Angle.continuous_cos
theorem cos_eq_real_cos_iff_eq_or_eq_neg {θ : Angle} {ψ : ℝ} :
cos θ = Real.cos ψ ↔ θ = ψ ∨ θ = -ψ := by
induction θ using Real.Angle.induction_on
exact cos_eq_iff_coe_eq_or_eq_neg
#align real.angle.cos_eq_real_cos_iff_eq_or_eq_neg Real.Angle.cos_eq_real_cos_iff_eq_or_eq_neg
theorem cos_eq_iff_eq_or_eq_neg {θ ψ : Angle} : cos θ = cos ψ ↔ θ = ψ ∨ θ = -ψ := by
induction ψ using Real.Angle.induction_on
exact cos_eq_real_cos_iff_eq_or_eq_neg
#align real.angle.cos_eq_iff_eq_or_eq_neg Real.Angle.cos_eq_iff_eq_or_eq_neg
theorem sin_eq_real_sin_iff_eq_or_add_eq_pi {θ : Angle} {ψ : ℝ} :
sin θ = Real.sin ψ ↔ θ = ψ ∨ θ + ψ = π := by
induction θ using Real.Angle.induction_on
exact sin_eq_iff_coe_eq_or_add_eq_pi
#align real.angle.sin_eq_real_sin_iff_eq_or_add_eq_pi Real.Angle.sin_eq_real_sin_iff_eq_or_add_eq_pi
theorem sin_eq_iff_eq_or_add_eq_pi {θ ψ : Angle} : sin θ = sin ψ ↔ θ = ψ ∨ θ + ψ = π := by
induction ψ using Real.Angle.induction_on
exact sin_eq_real_sin_iff_eq_or_add_eq_pi
#align real.angle.sin_eq_iff_eq_or_add_eq_pi Real.Angle.sin_eq_iff_eq_or_add_eq_pi
@[simp]
theorem sin_zero : sin (0 : Angle) = 0 := by rw [← coe_zero, sin_coe, Real.sin_zero]
#align real.angle.sin_zero Real.Angle.sin_zero
-- Porting note (#10618): @[simp] can prove it
theorem sin_coe_pi : sin (π : Angle) = 0 := by rw [sin_coe, Real.sin_pi]
#align real.angle.sin_coe_pi Real.Angle.sin_coe_pi
theorem sin_eq_zero_iff {θ : Angle} : sin θ = 0 ↔ θ = 0 ∨ θ = π := by
nth_rw 1 [← sin_zero]
rw [sin_eq_iff_eq_or_add_eq_pi]
simp
#align real.angle.sin_eq_zero_iff Real.Angle.sin_eq_zero_iff
theorem sin_ne_zero_iff {θ : Angle} : sin θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by
rw [← not_or, ← sin_eq_zero_iff]
#align real.angle.sin_ne_zero_iff Real.Angle.sin_ne_zero_iff
@[simp]
theorem sin_neg (θ : Angle) : sin (-θ) = -sin θ := by
induction θ using Real.Angle.induction_on
exact Real.sin_neg _
#align real.angle.sin_neg Real.Angle.sin_neg
theorem sin_antiperiodic : Function.Antiperiodic sin (π : Angle) := by
intro θ
induction θ using Real.Angle.induction_on
exact Real.sin_antiperiodic _
#align real.angle.sin_antiperiodic Real.Angle.sin_antiperiodic
@[simp]
theorem sin_add_pi (θ : Angle) : sin (θ + π) = -sin θ :=
sin_antiperiodic θ
#align real.angle.sin_add_pi Real.Angle.sin_add_pi
@[simp]
theorem sin_sub_pi (θ : Angle) : sin (θ - π) = -sin θ :=
sin_antiperiodic.sub_eq θ
#align real.angle.sin_sub_pi Real.Angle.sin_sub_pi
@[simp]
theorem cos_zero : cos (0 : Angle) = 1 := by rw [← coe_zero, cos_coe, Real.cos_zero]
#align real.angle.cos_zero Real.Angle.cos_zero
-- Porting note (#10618): @[simp] can prove it
theorem cos_coe_pi : cos (π : Angle) = -1 := by rw [cos_coe, Real.cos_pi]
#align real.angle.cos_coe_pi Real.Angle.cos_coe_pi
@[simp]
theorem cos_neg (θ : Angle) : cos (-θ) = cos θ := by
induction θ using Real.Angle.induction_on
exact Real.cos_neg _
#align real.angle.cos_neg Real.Angle.cos_neg
theorem cos_antiperiodic : Function.Antiperiodic cos (π : Angle) := by
intro θ
induction θ using Real.Angle.induction_on
exact Real.cos_antiperiodic _
#align real.angle.cos_antiperiodic Real.Angle.cos_antiperiodic
@[simp]
theorem cos_add_pi (θ : Angle) : cos (θ + π) = -cos θ :=
cos_antiperiodic θ
#align real.angle.cos_add_pi Real.Angle.cos_add_pi
@[simp]
theorem cos_sub_pi (θ : Angle) : cos (θ - π) = -cos θ :=
cos_antiperiodic.sub_eq θ
#align real.angle.cos_sub_pi Real.Angle.cos_sub_pi
theorem cos_eq_zero_iff {θ : Angle} : cos θ = 0 ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by
rw [← cos_pi_div_two, ← cos_coe, cos_eq_iff_eq_or_eq_neg, ← coe_neg, ← neg_div]
#align real.angle.cos_eq_zero_iff Real.Angle.cos_eq_zero_iff
theorem sin_add (θ₁ θ₂ : Real.Angle) : sin (θ₁ + θ₂) = sin θ₁ * cos θ₂ + cos θ₁ * sin θ₂ := by
induction θ₁ using Real.Angle.induction_on
induction θ₂ using Real.Angle.induction_on
exact Real.sin_add _ _
#align real.angle.sin_add Real.Angle.sin_add
theorem cos_add (θ₁ θ₂ : Real.Angle) : cos (θ₁ + θ₂) = cos θ₁ * cos θ₂ - sin θ₁ * sin θ₂ := by
induction θ₂ using Real.Angle.induction_on
induction θ₁ using Real.Angle.induction_on
exact Real.cos_add _ _
#align real.angle.cos_add Real.Angle.cos_add
@[simp]
theorem cos_sq_add_sin_sq (θ : Real.Angle) : cos θ ^ 2 + sin θ ^ 2 = 1 := by
induction θ using Real.Angle.induction_on
exact Real.cos_sq_add_sin_sq _
#align real.angle.cos_sq_add_sin_sq Real.Angle.cos_sq_add_sin_sq
theorem sin_add_pi_div_two (θ : Angle) : sin (θ + ↑(π / 2)) = cos θ := by
induction θ using Real.Angle.induction_on
exact Real.sin_add_pi_div_two _
#align real.angle.sin_add_pi_div_two Real.Angle.sin_add_pi_div_two
theorem sin_sub_pi_div_two (θ : Angle) : sin (θ - ↑(π / 2)) = -cos θ := by
induction θ using Real.Angle.induction_on
exact Real.sin_sub_pi_div_two _
#align real.angle.sin_sub_pi_div_two Real.Angle.sin_sub_pi_div_two
theorem sin_pi_div_two_sub (θ : Angle) : sin (↑(π / 2) - θ) = cos θ := by
induction θ using Real.Angle.induction_on
exact Real.sin_pi_div_two_sub _
#align real.angle.sin_pi_div_two_sub Real.Angle.sin_pi_div_two_sub
| Mathlib/Analysis/SpecialFunctions/Trigonometric/Angle.lean | 464 | 466 | theorem cos_add_pi_div_two (θ : Angle) : cos (θ + ↑(π / 2)) = -sin θ := by |
induction θ using Real.Angle.induction_on
exact Real.cos_add_pi_div_two _
|
/-
Copyright (c) 2022 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.CliffordAlgebra.Fold
import Mathlib.LinearAlgebra.ExteriorAlgebra.Basic
#align_import linear_algebra.exterior_algebra.of_alternating from "leanprover-community/mathlib"@"ce11c3c2a285bbe6937e26d9792fda4e51f3fe1a"
/-!
# Extending an alternating map to the exterior algebra
## Main definitions
* `ExteriorAlgebra.liftAlternating`: construct a linear map out of the exterior algebra
given alternating maps (corresponding to maps out of the exterior powers).
* `ExteriorAlgebra.liftAlternatingEquiv`: the above as a linear equivalence
## Main results
* `ExteriorAlgebra.lhom_ext`: linear maps from the exterior algebra agree if they agree on the
exterior powers.
-/
variable {R M N N' : Type*}
variable [CommRing R] [AddCommGroup M] [AddCommGroup N] [AddCommGroup N']
variable [Module R M] [Module R N] [Module R N']
-- This instance can't be found where it's needed if we don't remind lean that it exists.
instance AlternatingMap.instModuleAddCommGroup {ι : Type*} :
Module R (M [⋀^ι]→ₗ[R] N) := by
infer_instance
#align alternating_map.module_add_comm_group AlternatingMap.instModuleAddCommGroup
namespace ExteriorAlgebra
open CliffordAlgebra hiding ι
/-- Build a map out of the exterior algebra given a collection of alternating maps acting on each
exterior power -/
def liftAlternating : (∀ i, M [⋀^Fin i]→ₗ[R] N) →ₗ[R] ExteriorAlgebra R M →ₗ[R] N := by
suffices
(∀ i, M [⋀^Fin i]→ₗ[R] N) →ₗ[R]
ExteriorAlgebra R M →ₗ[R] ∀ i, M [⋀^Fin i]→ₗ[R] N by
refine LinearMap.compr₂ this ?_
refine (LinearEquiv.toLinearMap ?_).comp (LinearMap.proj 0)
exact AlternatingMap.constLinearEquivOfIsEmpty.symm
refine CliffordAlgebra.foldl _ ?_ ?_
· refine
LinearMap.mk₂ R (fun m f i => (f i.succ).curryLeft m) (fun m₁ m₂ f => ?_) (fun c m f => ?_)
(fun m f₁ f₂ => ?_) fun c m f => ?_
all_goals
ext i : 1
simp only [map_smul, map_add, Pi.add_apply, Pi.smul_apply, AlternatingMap.curryLeft_add,
AlternatingMap.curryLeft_smul, map_add, map_smul, LinearMap.add_apply, LinearMap.smul_apply]
· -- when applied twice with the same `m`, this recursive step produces 0
intro m x
dsimp only [LinearMap.mk₂_apply, QuadraticForm.coeFn_zero, Pi.zero_apply]
simp_rw [zero_smul]
ext i : 1
exact AlternatingMap.curryLeft_same _ _
#align exterior_algebra.lift_alternating ExteriorAlgebra.liftAlternating
@[simp]
theorem liftAlternating_ι (f : ∀ i, M [⋀^Fin i]→ₗ[R] N) (m : M) :
liftAlternating (R := R) (M := M) (N := N) f (ι R m) = f 1 ![m] := by
dsimp [liftAlternating]
rw [foldl_ι, LinearMap.mk₂_apply, AlternatingMap.curryLeft_apply_apply]
congr
-- Porting note: In Lean 3, `congr` could use the `[Subsingleton (Fin 0 → M)]` instance to finish
-- the proof. Here, the instance can be synthesized but `congr` does not use it so the following
-- line is provided.
rw [Matrix.zero_empty]
#align exterior_algebra.lift_alternating_ι ExteriorAlgebra.liftAlternating_ι
theorem liftAlternating_ι_mul (f : ∀ i, M [⋀^Fin i]→ₗ[R] N) (m : M)
(x : ExteriorAlgebra R M) :
liftAlternating (R := R) (M := M) (N := N) f (ι R m * x) =
liftAlternating (R := R) (M := M) (N := N) (fun i => (f i.succ).curryLeft m) x := by
dsimp [liftAlternating]
rw [foldl_mul, foldl_ι]
rfl
#align exterior_algebra.lift_alternating_ι_mul ExteriorAlgebra.liftAlternating_ι_mul
@[simp]
theorem liftAlternating_one (f : ∀ i, M [⋀^Fin i]→ₗ[R] N) :
liftAlternating (R := R) (M := M) (N := N) f (1 : ExteriorAlgebra R M) = f 0 0 := by
dsimp [liftAlternating]
rw [foldl_one]
#align exterior_algebra.lift_alternating_one ExteriorAlgebra.liftAlternating_one
@[simp]
theorem liftAlternating_algebraMap (f : ∀ i, M [⋀^Fin i]→ₗ[R] N) (r : R) :
liftAlternating (R := R) (M := M) (N := N) f (algebraMap _ (ExteriorAlgebra R M) r) =
r • f 0 0 := by
rw [Algebra.algebraMap_eq_smul_one, map_smul, liftAlternating_one]
#align exterior_algebra.lift_alternating_algebra_map ExteriorAlgebra.liftAlternating_algebraMap
@[simp]
theorem liftAlternating_apply_ιMulti {n : ℕ} (f : ∀ i, M [⋀^Fin i]→ₗ[R] N)
(v : Fin n → M) : liftAlternating (R := R) (M := M) (N := N) f (ιMulti R n v) = f n v := by
rw [ιMulti_apply]
-- Porting note: `v` is generalized automatically so it was removed from the next line
induction' n with n ih generalizing f
· -- Porting note: Lean does not automatically synthesize the instance
-- `[Subsingleton (Fin 0 → M)]` which is needed for `Subsingleton.elim 0 v` on line 114.
letI : Subsingleton (Fin 0 → M) := by infer_instance
rw [List.ofFn_zero, List.prod_nil, liftAlternating_one, Subsingleton.elim 0 v]
· rw [List.ofFn_succ, List.prod_cons, liftAlternating_ι_mul, ih,
AlternatingMap.curryLeft_apply_apply]
congr
exact Matrix.cons_head_tail _
#align exterior_algebra.lift_alternating_apply_ι_multi ExteriorAlgebra.liftAlternating_apply_ιMulti
@[simp]
theorem liftAlternating_comp_ιMulti {n : ℕ} (f : ∀ i, M [⋀^Fin i]→ₗ[R] N) :
(liftAlternating (R := R) (M := M) (N := N) f).compAlternatingMap (ιMulti R n) = f n :=
AlternatingMap.ext <| liftAlternating_apply_ιMulti f
#align exterior_algebra.lift_alternating_comp_ι_multi ExteriorAlgebra.liftAlternating_comp_ιMulti
@[simp]
| Mathlib/LinearAlgebra/ExteriorAlgebra/OfAlternating.lean | 125 | 135 | theorem liftAlternating_comp (g : N →ₗ[R] N') (f : ∀ i, M [⋀^Fin i]→ₗ[R] N) :
(liftAlternating (R := R) (M := M) (N := N') fun i => g.compAlternatingMap (f i)) =
g ∘ₗ liftAlternating (R := R) (M := M) (N := N) f := by |
ext v
rw [LinearMap.comp_apply]
induction' v using CliffordAlgebra.left_induction with r x y hx hy x m hx generalizing f
· rw [liftAlternating_algebraMap, liftAlternating_algebraMap, map_smul,
LinearMap.compAlternatingMap_apply]
· rw [map_add, map_add, map_add, hx, hy]
· rw [liftAlternating_ι_mul, liftAlternating_ι_mul, ← hx]
simp_rw [AlternatingMap.curryLeft_compAlternatingMap]
|
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.Algebra.Group.Subgroup.Basic
import Mathlib.Data.Fintype.Basic
import Mathlib.Data.List.Sublists
import Mathlib.Data.List.InsertNth
#align_import group_theory.free_group from "leanprover-community/mathlib"@"f93c11933efbc3c2f0299e47b8ff83e9b539cbf6"
/-!
# Free groups
This file defines free groups over a type. Furthermore, it is shown that the free group construction
is an instance of a monad. For the result that `FreeGroup` is the left adjoint to the forgetful
functor from groups to types, see `Algebra/Category/Group/Adjunctions`.
## Main definitions
* `FreeGroup`/`FreeAddGroup`: the free group (resp. free additive group) associated to a type
`α` defined as the words over `a : α × Bool` modulo the relation `a * x * x⁻¹ * b = a * b`.
* `FreeGroup.mk`/`FreeAddGroup.mk`: the canonical quotient map `List (α × Bool) → FreeGroup α`.
* `FreeGroup.of`/`FreeAddGroup.of`: the canonical injection `α → FreeGroup α`.
* `FreeGroup.lift f`/`FreeAddGroup.lift`: the canonical group homomorphism `FreeGroup α →* G`
given a group `G` and a function `f : α → G`.
## Main statements
* `FreeGroup.Red.church_rosser`/`FreeAddGroup.Red.church_rosser`: The Church-Rosser theorem for word
reduction (also known as Newman's diamond lemma).
* `FreeGroup.freeGroupUnitEquivInt`: The free group over the one-point type
is isomorphic to the integers.
* The free group construction is an instance of a monad.
## Implementation details
First we introduce the one step reduction relation `FreeGroup.Red.Step`:
`w * x * x⁻¹ * v ~> w * v`, its reflexive transitive closure `FreeGroup.Red.trans`
and prove that its join is an equivalence relation. Then we introduce `FreeGroup α` as a quotient
over `FreeGroup.Red.Step`.
For the additive version we introduce the same relation under a different name so that we can
distinguish the quotient types more easily.
## Tags
free group, Newman's diamond lemma, Church-Rosser theorem
-/
open Relation
universe u v w
variable {α : Type u}
attribute [local simp] List.append_eq_has_append
-- Porting note: to_additive.map_namespace is not supported yet
-- worked around it by putting a few extra manual mappings (but not too many all in all)
-- run_cmd to_additive.map_namespace `FreeGroup `FreeAddGroup
/-- Reduction step for the additive free group relation: `w + x + (-x) + v ~> w + v` -/
inductive FreeAddGroup.Red.Step : List (α × Bool) → List (α × Bool) → Prop
| not {L₁ L₂ x b} : FreeAddGroup.Red.Step (L₁ ++ (x, b) :: (x, not b) :: L₂) (L₁ ++ L₂)
#align free_add_group.red.step FreeAddGroup.Red.Step
attribute [simp] FreeAddGroup.Red.Step.not
/-- Reduction step for the multiplicative free group relation: `w * x * x⁻¹ * v ~> w * v` -/
@[to_additive FreeAddGroup.Red.Step]
inductive FreeGroup.Red.Step : List (α × Bool) → List (α × Bool) → Prop
| not {L₁ L₂ x b} : FreeGroup.Red.Step (L₁ ++ (x, b) :: (x, not b) :: L₂) (L₁ ++ L₂)
#align free_group.red.step FreeGroup.Red.Step
attribute [simp] FreeGroup.Red.Step.not
namespace FreeGroup
variable {L L₁ L₂ L₃ L₄ : List (α × Bool)}
/-- Reflexive-transitive closure of `Red.Step` -/
@[to_additive FreeAddGroup.Red "Reflexive-transitive closure of `Red.Step`"]
def Red : List (α × Bool) → List (α × Bool) → Prop :=
ReflTransGen Red.Step
#align free_group.red FreeGroup.Red
#align free_add_group.red FreeAddGroup.Red
@[to_additive (attr := refl)]
theorem Red.refl : Red L L :=
ReflTransGen.refl
#align free_group.red.refl FreeGroup.Red.refl
#align free_add_group.red.refl FreeAddGroup.Red.refl
@[to_additive (attr := trans)]
theorem Red.trans : Red L₁ L₂ → Red L₂ L₃ → Red L₁ L₃ :=
ReflTransGen.trans
#align free_group.red.trans FreeGroup.Red.trans
#align free_add_group.red.trans FreeAddGroup.Red.trans
namespace Red
/-- Predicate asserting that the word `w₁` can be reduced to `w₂` in one step, i.e. there are words
`w₃ w₄` and letter `x` such that `w₁ = w₃xx⁻¹w₄` and `w₂ = w₃w₄` -/
@[to_additive "Predicate asserting that the word `w₁` can be reduced to `w₂` in one step, i.e. there
are words `w₃ w₄` and letter `x` such that `w₁ = w₃ + x + (-x) + w₄` and `w₂ = w₃w₄`"]
theorem Step.length : ∀ {L₁ L₂ : List (α × Bool)}, Step L₁ L₂ → L₂.length + 2 = L₁.length
| _, _, @Red.Step.not _ L1 L2 x b => by rw [List.length_append, List.length_append]; rfl
#align free_group.red.step.length FreeGroup.Red.Step.length
#align free_add_group.red.step.length FreeAddGroup.Red.Step.length
@[to_additive (attr := simp)]
theorem Step.not_rev {x b} : Step (L₁ ++ (x, !b) :: (x, b) :: L₂) (L₁ ++ L₂) := by
cases b <;> exact Step.not
#align free_group.red.step.bnot_rev FreeGroup.Red.Step.not_rev
#align free_add_group.red.step.bnot_rev FreeAddGroup.Red.Step.not_rev
@[to_additive (attr := simp)]
theorem Step.cons_not {x b} : Red.Step ((x, b) :: (x, !b) :: L) L :=
@Step.not _ [] _ _ _
#align free_group.red.step.cons_bnot FreeGroup.Red.Step.cons_not
#align free_add_group.red.step.cons_bnot FreeAddGroup.Red.Step.cons_not
@[to_additive (attr := simp)]
theorem Step.cons_not_rev {x b} : Red.Step ((x, !b) :: (x, b) :: L) L :=
@Red.Step.not_rev _ [] _ _ _
#align free_group.red.step.cons_bnot_rev FreeGroup.Red.Step.cons_not_rev
#align free_add_group.red.step.cons_bnot_rev FreeAddGroup.Red.Step.cons_not_rev
@[to_additive]
theorem Step.append_left : ∀ {L₁ L₂ L₃ : List (α × Bool)}, Step L₂ L₃ → Step (L₁ ++ L₂) (L₁ ++ L₃)
| _, _, _, Red.Step.not => by rw [← List.append_assoc, ← List.append_assoc]; constructor
#align free_group.red.step.append_left FreeGroup.Red.Step.append_left
#align free_add_group.red.step.append_left FreeAddGroup.Red.Step.append_left
@[to_additive]
theorem Step.cons {x} (H : Red.Step L₁ L₂) : Red.Step (x :: L₁) (x :: L₂) :=
@Step.append_left _ [x] _ _ H
#align free_group.red.step.cons FreeGroup.Red.Step.cons
#align free_add_group.red.step.cons FreeAddGroup.Red.Step.cons
@[to_additive]
theorem Step.append_right : ∀ {L₁ L₂ L₃ : List (α × Bool)}, Step L₁ L₂ → Step (L₁ ++ L₃) (L₂ ++ L₃)
| _, _, _, Red.Step.not => by simp
#align free_group.red.step.append_right FreeGroup.Red.Step.append_right
#align free_add_group.red.step.append_right FreeAddGroup.Red.Step.append_right
@[to_additive]
theorem not_step_nil : ¬Step [] L := by
generalize h' : [] = L'
intro h
cases' h with L₁ L₂
simp [List.nil_eq_append] at h'
#align free_group.red.not_step_nil FreeGroup.Red.not_step_nil
#align free_add_group.red.not_step_nil FreeAddGroup.Red.not_step_nil
@[to_additive]
theorem Step.cons_left_iff {a : α} {b : Bool} :
Step ((a, b) :: L₁) L₂ ↔ (∃ L, Step L₁ L ∧ L₂ = (a, b) :: L) ∨ L₁ = (a, ! b) :: L₂ := by
constructor
· generalize hL : ((a, b) :: L₁ : List _) = L
rintro @⟨_ | ⟨p, s'⟩, e, a', b'⟩
· simp at hL
simp [*]
· simp at hL
rcases hL with ⟨rfl, rfl⟩
refine Or.inl ⟨s' ++ e, Step.not, ?_⟩
simp
· rintro (⟨L, h, rfl⟩ | rfl)
· exact Step.cons h
· exact Step.cons_not
#align free_group.red.step.cons_left_iff FreeGroup.Red.Step.cons_left_iff
#align free_add_group.red.step.cons_left_iff FreeAddGroup.Red.Step.cons_left_iff
@[to_additive]
theorem not_step_singleton : ∀ {p : α × Bool}, ¬Step [p] L
| (a, b) => by simp [Step.cons_left_iff, not_step_nil]
#align free_group.red.not_step_singleton FreeGroup.Red.not_step_singleton
#align free_add_group.red.not_step_singleton FreeAddGroup.Red.not_step_singleton
@[to_additive]
theorem Step.cons_cons_iff : ∀ {p : α × Bool}, Step (p :: L₁) (p :: L₂) ↔ Step L₁ L₂ := by
simp (config := { contextual := true }) [Step.cons_left_iff, iff_def, or_imp]
#align free_group.red.step.cons_cons_iff FreeGroup.Red.Step.cons_cons_iff
#align free_add_group.red.step.cons_cons_iff FreeAddGroup.Red.Step.cons_cons_iff
@[to_additive]
theorem Step.append_left_iff : ∀ L, Step (L ++ L₁) (L ++ L₂) ↔ Step L₁ L₂
| [] => by simp
| p :: l => by simp [Step.append_left_iff l, Step.cons_cons_iff]
#align free_group.red.step.append_left_iff FreeGroup.Red.Step.append_left_iff
#align free_add_group.red.step.append_left_iff FreeAddGroup.Red.Step.append_left_iff
@[to_additive]
theorem Step.diamond_aux :
∀ {L₁ L₂ L₃ L₄ : List (α × Bool)} {x1 b1 x2 b2},
L₁ ++ (x1, b1) :: (x1, !b1) :: L₂ = L₃ ++ (x2, b2) :: (x2, !b2) :: L₄ →
L₁ ++ L₂ = L₃ ++ L₄ ∨ ∃ L₅, Red.Step (L₁ ++ L₂) L₅ ∧ Red.Step (L₃ ++ L₄) L₅
| [], _, [], _, _, _, _, _, H => by injections; subst_vars; simp
| [], _, [(x3, b3)], _, _, _, _, _, H => by injections; subst_vars; simp
| [(x3, b3)], _, [], _, _, _, _, _, H => by injections; subst_vars; simp
| [], _, (x3, b3) :: (x4, b4) :: tl, _, _, _, _, _, H => by
injections; subst_vars; simp; right; exact ⟨_, Red.Step.not, Red.Step.cons_not⟩
| (x3, b3) :: (x4, b4) :: tl, _, [], _, _, _, _, _, H => by
injections; subst_vars; simp; right; exact ⟨_, Red.Step.cons_not, Red.Step.not⟩
| (x3, b3) :: tl, _, (x4, b4) :: tl2, _, _, _, _, _, H =>
let ⟨H1, H2⟩ := List.cons.inj H
match Step.diamond_aux H2 with
| Or.inl H3 => Or.inl <| by simp [H1, H3]
| Or.inr ⟨L₅, H3, H4⟩ => Or.inr ⟨_, Step.cons H3, by simpa [H1] using Step.cons H4⟩
#align free_group.red.step.diamond_aux FreeGroup.Red.Step.diamond_aux
#align free_add_group.red.step.diamond_aux FreeAddGroup.Red.Step.diamond_aux
@[to_additive]
theorem Step.diamond :
∀ {L₁ L₂ L₃ L₄ : List (α × Bool)},
Red.Step L₁ L₃ → Red.Step L₂ L₄ → L₁ = L₂ → L₃ = L₄ ∨ ∃ L₅, Red.Step L₃ L₅ ∧ Red.Step L₄ L₅
| _, _, _, _, Red.Step.not, Red.Step.not, H => Step.diamond_aux H
#align free_group.red.step.diamond FreeGroup.Red.Step.diamond
#align free_add_group.red.step.diamond FreeAddGroup.Red.Step.diamond
@[to_additive]
theorem Step.to_red : Step L₁ L₂ → Red L₁ L₂ :=
ReflTransGen.single
#align free_group.red.step.to_red FreeGroup.Red.Step.to_red
#align free_add_group.red.step.to_red FreeAddGroup.Red.Step.to_red
/-- **Church-Rosser theorem** for word reduction: If `w1 w2 w3` are words such that `w1` reduces
to `w2` and `w3` respectively, then there is a word `w4` such that `w2` and `w3` reduce to `w4`
respectively. This is also known as Newman's diamond lemma. -/
@[to_additive
"**Church-Rosser theorem** for word reduction: If `w1 w2 w3` are words such that `w1` reduces
to `w2` and `w3` respectively, then there is a word `w4` such that `w2` and `w3` reduce to `w4`
respectively. This is also known as Newman's diamond lemma."]
theorem church_rosser : Red L₁ L₂ → Red L₁ L₃ → Join Red L₂ L₃ :=
Relation.church_rosser fun a b c hab hac =>
match b, c, Red.Step.diamond hab hac rfl with
| b, _, Or.inl rfl => ⟨b, by rfl, by rfl⟩
| b, c, Or.inr ⟨d, hbd, hcd⟩ => ⟨d, ReflGen.single hbd, hcd.to_red⟩
#align free_group.red.church_rosser FreeGroup.Red.church_rosser
#align free_add_group.red.church_rosser FreeAddGroup.Red.church_rosser
@[to_additive]
theorem cons_cons {p} : Red L₁ L₂ → Red (p :: L₁) (p :: L₂) :=
ReflTransGen.lift (List.cons p) fun _ _ => Step.cons
#align free_group.red.cons_cons FreeGroup.Red.cons_cons
#align free_add_group.red.cons_cons FreeAddGroup.Red.cons_cons
@[to_additive]
theorem cons_cons_iff (p) : Red (p :: L₁) (p :: L₂) ↔ Red L₁ L₂ :=
Iff.intro
(by
generalize eq₁ : (p :: L₁ : List _) = LL₁
generalize eq₂ : (p :: L₂ : List _) = LL₂
intro h
induction' h using Relation.ReflTransGen.head_induction_on
with L₁ L₂ h₁₂ h ih
generalizing L₁ L₂
· subst_vars
cases eq₂
constructor
· subst_vars
cases' p with a b
rw [Step.cons_left_iff] at h₁₂
rcases h₁₂ with (⟨L, h₁₂, rfl⟩ | rfl)
· exact (ih rfl rfl).head h₁₂
· exact (cons_cons h).tail Step.cons_not_rev)
cons_cons
#align free_group.red.cons_cons_iff FreeGroup.Red.cons_cons_iff
#align free_add_group.red.cons_cons_iff FreeAddGroup.Red.cons_cons_iff
@[to_additive]
theorem append_append_left_iff : ∀ L, Red (L ++ L₁) (L ++ L₂) ↔ Red L₁ L₂
| [] => Iff.rfl
| p :: L => by simp [append_append_left_iff L, cons_cons_iff]
#align free_group.red.append_append_left_iff FreeGroup.Red.append_append_left_iff
#align free_add_group.red.append_append_left_iff FreeAddGroup.Red.append_append_left_iff
@[to_additive]
theorem append_append (h₁ : Red L₁ L₃) (h₂ : Red L₂ L₄) : Red (L₁ ++ L₂) (L₃ ++ L₄) :=
(h₁.lift (fun L => L ++ L₂) fun _ _ => Step.append_right).trans ((append_append_left_iff _).2 h₂)
#align free_group.red.append_append FreeGroup.Red.append_append
#align free_add_group.red.append_append FreeAddGroup.Red.append_append
@[to_additive]
theorem to_append_iff : Red L (L₁ ++ L₂) ↔ ∃ L₃ L₄, L = L₃ ++ L₄ ∧ Red L₃ L₁ ∧ Red L₄ L₂ :=
Iff.intro
(by
generalize eq : L₁ ++ L₂ = L₁₂
intro h
induction' h with L' L₁₂ hLL' h ih generalizing L₁ L₂
· exact ⟨_, _, eq.symm, by rfl, by rfl⟩
· cases' h with s e a b
rcases List.append_eq_append_iff.1 eq with (⟨s', rfl, rfl⟩ | ⟨e', rfl, rfl⟩)
· have : L₁ ++ (s' ++ (a, b) :: (a, not b) :: e) = L₁ ++ s' ++ (a, b) :: (a, not b) :: e :=
by simp
rcases ih this with ⟨w₁, w₂, rfl, h₁, h₂⟩
exact ⟨w₁, w₂, rfl, h₁, h₂.tail Step.not⟩
· have : s ++ (a, b) :: (a, not b) :: e' ++ L₂ = s ++ (a, b) :: (a, not b) :: (e' ++ L₂) :=
by simp
rcases ih this with ⟨w₁, w₂, rfl, h₁, h₂⟩
exact ⟨w₁, w₂, rfl, h₁.tail Step.not, h₂⟩)
fun ⟨L₃, L₄, Eq, h₃, h₄⟩ => Eq.symm ▸ append_append h₃ h₄
#align free_group.red.to_append_iff FreeGroup.Red.to_append_iff
#align free_add_group.red.to_append_iff FreeAddGroup.Red.to_append_iff
/-- The empty word `[]` only reduces to itself. -/
@[to_additive "The empty word `[]` only reduces to itself."]
theorem nil_iff : Red [] L ↔ L = [] :=
reflTransGen_iff_eq fun _ => Red.not_step_nil
#align free_group.red.nil_iff FreeGroup.Red.nil_iff
#align free_add_group.red.nil_iff FreeAddGroup.Red.nil_iff
/-- A letter only reduces to itself. -/
@[to_additive "A letter only reduces to itself."]
theorem singleton_iff {x} : Red [x] L₁ ↔ L₁ = [x] :=
reflTransGen_iff_eq fun _ => not_step_singleton
#align free_group.red.singleton_iff FreeGroup.Red.singleton_iff
#align free_add_group.red.singleton_iff FreeAddGroup.Red.singleton_iff
/-- If `x` is a letter and `w` is a word such that `xw` reduces to the empty word, then `w` reduces
to `x⁻¹` -/
@[to_additive
"If `x` is a letter and `w` is a word such that `x + w` reduces to the empty word, then `w`
reduces to `-x`."]
theorem cons_nil_iff_singleton {x b} : Red ((x, b) :: L) [] ↔ Red L [(x, not b)] :=
Iff.intro
(fun h => by
have h₁ : Red ((x, not b) :: (x, b) :: L) [(x, not b)] := cons_cons h
have h₂ : Red ((x, not b) :: (x, b) :: L) L := ReflTransGen.single Step.cons_not_rev
let ⟨L', h₁, h₂⟩ := church_rosser h₁ h₂
rw [singleton_iff] at h₁
subst L'
assumption)
fun h => (cons_cons h).tail Step.cons_not
#align free_group.red.cons_nil_iff_singleton FreeGroup.Red.cons_nil_iff_singleton
#align free_add_group.red.cons_nil_iff_singleton FreeAddGroup.Red.cons_nil_iff_singleton
@[to_additive]
theorem red_iff_irreducible {x1 b1 x2 b2} (h : (x1, b1) ≠ (x2, b2)) :
Red [(x1, !b1), (x2, b2)] L ↔ L = [(x1, !b1), (x2, b2)] := by
apply reflTransGen_iff_eq
generalize eq : [(x1, not b1), (x2, b2)] = L'
intro L h'
cases h'
simp [List.cons_eq_append, List.nil_eq_append] at eq
rcases eq with ⟨rfl, ⟨rfl, rfl⟩, ⟨rfl, rfl⟩, rfl⟩
simp at h
#align free_group.red.red_iff_irreducible FreeGroup.Red.red_iff_irreducible
#align free_add_group.red.red_iff_irreducible FreeAddGroup.Red.red_iff_irreducible
/-- If `x` and `y` are distinct letters and `w₁ w₂` are words such that `xw₁` reduces to `yw₂`, then
`w₁` reduces to `x⁻¹yw₂`. -/
@[to_additive "If `x` and `y` are distinct letters and `w₁ w₂` are words such that `x + w₁` reduces
to `y + w₂`, then `w₁` reduces to `-x + y + w₂`."]
theorem inv_of_red_of_ne {x1 b1 x2 b2} (H1 : (x1, b1) ≠ (x2, b2))
(H2 : Red ((x1, b1) :: L₁) ((x2, b2) :: L₂)) : Red L₁ ((x1, not b1) :: (x2, b2) :: L₂) := by
have : Red ((x1, b1) :: L₁) ([(x2, b2)] ++ L₂) := H2
rcases to_append_iff.1 this with ⟨_ | ⟨p, L₃⟩, L₄, eq, h₁, h₂⟩
· simp [nil_iff] at h₁
· cases eq
show Red (L₃ ++ L₄) ([(x1, not b1), (x2, b2)] ++ L₂)
apply append_append _ h₂
have h₁ : Red ((x1, not b1) :: (x1, b1) :: L₃) [(x1, not b1), (x2, b2)] := cons_cons h₁
have h₂ : Red ((x1, not b1) :: (x1, b1) :: L₃) L₃ := Step.cons_not_rev.to_red
rcases church_rosser h₁ h₂ with ⟨L', h₁, h₂⟩
rw [red_iff_irreducible H1] at h₁
rwa [h₁] at h₂
#align free_group.red.inv_of_red_of_ne FreeGroup.Red.inv_of_red_of_ne
#align free_add_group.red.neg_of_red_of_ne FreeAddGroup.Red.neg_of_red_of_ne
open List -- for <+ notation
@[to_additive]
theorem Step.sublist (H : Red.Step L₁ L₂) : Sublist L₂ L₁ := by
cases H; simp; constructor; constructor; rfl
#align free_group.red.step.sublist FreeGroup.Red.Step.sublist
#align free_add_group.red.step.sublist FreeAddGroup.Red.Step.sublist
/-- If `w₁ w₂` are words such that `w₁` reduces to `w₂`, then `w₂` is a sublist of `w₁`. -/
@[to_additive "If `w₁ w₂` are words such that `w₁` reduces to `w₂`, then `w₂` is a sublist of
`w₁`."]
protected theorem sublist : Red L₁ L₂ → L₂ <+ L₁ :=
@reflTransGen_of_transitive_reflexive
_ (fun a b => b <+ a) _ _ _
(fun l => List.Sublist.refl l)
(fun _a _b _c hab hbc => List.Sublist.trans hbc hab)
(fun _ _ => Red.Step.sublist)
#align free_group.red.sublist FreeGroup.Red.sublist
#align free_add_group.red.sublist FreeAddGroup.Red.sublist
@[to_additive]
theorem length_le (h : Red L₁ L₂) : L₂.length ≤ L₁.length :=
h.sublist.length_le
#align free_group.red.length_le FreeGroup.Red.length_le
#align free_add_group.red.length_le FreeAddGroup.Red.length_le
@[to_additive]
theorem sizeof_of_step : ∀ {L₁ L₂ : List (α × Bool)},
Step L₁ L₂ → sizeOf L₂ < sizeOf L₁
| _, _, @Step.not _ L1 L2 x b => by
induction L1 with
| nil =>
-- dsimp [sizeOf]
dsimp
simp only [Bool.sizeOf_eq_one]
have H :
1 + (1 + 1) + (1 + (1 + 1) + sizeOf L2) =
sizeOf L2 + (1 + ((1 + 1) + (1 + 1) + 1)) := by
ac_rfl
rw [H]
apply Nat.lt_add_of_pos_right
apply Nat.lt_add_right
apply Nat.zero_lt_one
| cons hd tl ih =>
dsimp
exact Nat.add_lt_add_left ih _
#align free_group.red.sizeof_of_step FreeGroup.Red.sizeof_of_step
#align free_add_group.red.sizeof_of_step FreeAddGroup.Red.sizeof_of_step
@[to_additive]
theorem length (h : Red L₁ L₂) : ∃ n, L₁.length = L₂.length + 2 * n := by
induction' h with L₂ L₃ _h₁₂ h₂₃ ih
· exact ⟨0, rfl⟩
· rcases ih with ⟨n, eq⟩
exists 1 + n
simp [Nat.mul_add, eq, (Step.length h₂₃).symm, add_assoc]
#align free_group.red.length FreeGroup.Red.length
#align free_add_group.red.length FreeAddGroup.Red.length
@[to_additive]
theorem antisymm (h₁₂ : Red L₁ L₂) (h₂₁ : Red L₂ L₁) : L₁ = L₂ :=
h₂₁.sublist.antisymm h₁₂.sublist
#align free_group.red.antisymm FreeGroup.Red.antisymm
#align free_add_group.red.antisymm FreeAddGroup.Red.antisymm
end Red
@[to_additive FreeAddGroup.equivalence_join_red]
theorem equivalence_join_red : Equivalence (Join (@Red α)) :=
equivalence_join_reflTransGen fun a b c hab hac =>
match b, c, Red.Step.diamond hab hac rfl with
| b, _, Or.inl rfl => ⟨b, by rfl, by rfl⟩
| b, c, Or.inr ⟨d, hbd, hcd⟩ => ⟨d, ReflGen.single hbd, ReflTransGen.single hcd⟩
#align free_group.equivalence_join_red FreeGroup.equivalence_join_red
#align free_add_group.equivalence_join_red FreeAddGroup.equivalence_join_red
@[to_additive FreeAddGroup.join_red_of_step]
theorem join_red_of_step (h : Red.Step L₁ L₂) : Join Red L₁ L₂ :=
join_of_single reflexive_reflTransGen h.to_red
#align free_group.join_red_of_step FreeGroup.join_red_of_step
#align free_add_group.join_red_of_step FreeAddGroup.join_red_of_step
@[to_additive FreeAddGroup.eqvGen_step_iff_join_red]
theorem eqvGen_step_iff_join_red : EqvGen Red.Step L₁ L₂ ↔ Join Red L₁ L₂ :=
Iff.intro
(fun h =>
have : EqvGen (Join Red) L₁ L₂ := h.mono fun _ _ => join_red_of_step
equivalence_join_red.eqvGen_iff.1 this)
(join_of_equivalence (EqvGen.is_equivalence _) fun _ _ =>
reflTransGen_of_equivalence (EqvGen.is_equivalence _) EqvGen.rel)
#align free_group.eqv_gen_step_iff_join_red FreeGroup.eqvGen_step_iff_join_red
#align free_add_group.eqv_gen_step_iff_join_red FreeAddGroup.eqvGen_step_iff_join_red
end FreeGroup
/-- The free group over a type, i.e. the words formed by the elements of the type and their formal
inverses, quotient by one step reduction. -/
@[to_additive "The free additive group over a type, i.e. the words formed by the elements of the
type and their formal inverses, quotient by one step reduction."]
def FreeGroup (α : Type u) : Type u :=
Quot <| @FreeGroup.Red.Step α
#align free_group FreeGroup
#align free_add_group FreeAddGroup
namespace FreeGroup
variable {L L₁ L₂ L₃ L₄ : List (α × Bool)}
/-- The canonical map from `List (α × Bool)` to the free group on `α`. -/
@[to_additive "The canonical map from `list (α × bool)` to the free additive group on `α`."]
def mk (L : List (α × Bool)) : FreeGroup α :=
Quot.mk Red.Step L
#align free_group.mk FreeGroup.mk
#align free_add_group.mk FreeAddGroup.mk
@[to_additive (attr := simp)]
theorem quot_mk_eq_mk : Quot.mk Red.Step L = mk L :=
rfl
#align free_group.quot_mk_eq_mk FreeGroup.quot_mk_eq_mk
#align free_add_group.quot_mk_eq_mk FreeAddGroup.quot_mk_eq_mk
@[to_additive (attr := simp)]
theorem quot_lift_mk (β : Type v) (f : List (α × Bool) → β)
(H : ∀ L₁ L₂, Red.Step L₁ L₂ → f L₁ = f L₂) : Quot.lift f H (mk L) = f L :=
rfl
#align free_group.quot_lift_mk FreeGroup.quot_lift_mk
#align free_add_group.quot_lift_mk FreeAddGroup.quot_lift_mk
@[to_additive (attr := simp)]
theorem quot_liftOn_mk (β : Type v) (f : List (α × Bool) → β)
(H : ∀ L₁ L₂, Red.Step L₁ L₂ → f L₁ = f L₂) : Quot.liftOn (mk L) f H = f L :=
rfl
#align free_group.quot_lift_on_mk FreeGroup.quot_liftOn_mk
#align free_add_group.quot_lift_on_mk FreeAddGroup.quot_liftOn_mk
@[to_additive (attr := simp)]
theorem quot_map_mk (β : Type v) (f : List (α × Bool) → List (β × Bool))
(H : (Red.Step ⇒ Red.Step) f f) : Quot.map f H (mk L) = mk (f L) :=
rfl
#align free_group.quot_map_mk FreeGroup.quot_map_mk
#align free_add_group.quot_map_mk FreeAddGroup.quot_map_mk
@[to_additive]
instance : One (FreeGroup α) :=
⟨mk []⟩
@[to_additive]
theorem one_eq_mk : (1 : FreeGroup α) = mk [] :=
rfl
#align free_group.one_eq_mk FreeGroup.one_eq_mk
#align free_add_group.zero_eq_mk FreeAddGroup.zero_eq_mk
@[to_additive]
instance : Inhabited (FreeGroup α) :=
⟨1⟩
@[to_additive]
instance [IsEmpty α] : Unique (FreeGroup α) := by unfold FreeGroup; infer_instance
@[to_additive]
instance : Mul (FreeGroup α) :=
⟨fun x y =>
Quot.liftOn x
(fun L₁ =>
Quot.liftOn y (fun L₂ => mk <| L₁ ++ L₂) fun _L₂ _L₃ H =>
Quot.sound <| Red.Step.append_left H)
fun _L₁ _L₂ H => Quot.inductionOn y fun _L₃ => Quot.sound <| Red.Step.append_right H⟩
@[to_additive (attr := simp)]
theorem mul_mk : mk L₁ * mk L₂ = mk (L₁ ++ L₂) :=
rfl
#align free_group.mul_mk FreeGroup.mul_mk
#align free_add_group.add_mk FreeAddGroup.add_mk
/-- Transform a word representing a free group element into a word representing its inverse. -/
@[to_additive "Transform a word representing a free group element into a word representing its
negative."]
def invRev (w : List (α × Bool)) : List (α × Bool) :=
(List.map (fun g : α × Bool => (g.1, not g.2)) w).reverse
#align free_group.inv_rev FreeGroup.invRev
#align free_add_group.neg_rev FreeAddGroup.negRev
@[to_additive (attr := simp)]
theorem invRev_length : (invRev L₁).length = L₁.length := by simp [invRev]
#align free_group.inv_rev_length FreeGroup.invRev_length
#align free_add_group.neg_rev_length FreeAddGroup.negRev_length
@[to_additive (attr := simp)]
theorem invRev_invRev : invRev (invRev L₁) = L₁ := by
simp [invRev, List.map_reverse, (· ∘ ·)]
#align free_group.inv_rev_inv_rev FreeGroup.invRev_invRev
#align free_add_group.neg_rev_neg_rev FreeAddGroup.negRev_negRev
@[to_additive (attr := simp)]
theorem invRev_empty : invRev ([] : List (α × Bool)) = [] :=
rfl
#align free_group.inv_rev_empty FreeGroup.invRev_empty
#align free_add_group.neg_rev_empty FreeAddGroup.negRev_empty
@[to_additive]
theorem invRev_involutive : Function.Involutive (@invRev α) := fun _ => invRev_invRev
#align free_group.inv_rev_involutive FreeGroup.invRev_involutive
#align free_add_group.neg_rev_involutive FreeAddGroup.negRev_involutive
@[to_additive]
theorem invRev_injective : Function.Injective (@invRev α) :=
invRev_involutive.injective
#align free_group.inv_rev_injective FreeGroup.invRev_injective
#align free_add_group.neg_rev_injective FreeAddGroup.negRev_injective
@[to_additive]
theorem invRev_surjective : Function.Surjective (@invRev α) :=
invRev_involutive.surjective
#align free_group.inv_rev_surjective FreeGroup.invRev_surjective
#align free_add_group.neg_rev_surjective FreeAddGroup.negRev_surjective
@[to_additive]
theorem invRev_bijective : Function.Bijective (@invRev α) :=
invRev_involutive.bijective
#align free_group.inv_rev_bijective FreeGroup.invRev_bijective
#align free_add_group.neg_rev_bijective FreeAddGroup.negRev_bijective
@[to_additive]
instance : Inv (FreeGroup α) :=
⟨Quot.map invRev
(by
intro a b h
cases h
simp [invRev])⟩
@[to_additive (attr := simp)]
theorem inv_mk : (mk L)⁻¹ = mk (invRev L) :=
rfl
#align free_group.inv_mk FreeGroup.inv_mk
#align free_add_group.neg_mk FreeAddGroup.neg_mk
@[to_additive]
theorem Red.Step.invRev {L₁ L₂ : List (α × Bool)} (h : Red.Step L₁ L₂) :
Red.Step (FreeGroup.invRev L₁) (FreeGroup.invRev L₂) := by
cases' h with a b x y
simp [FreeGroup.invRev]
#align free_group.red.step.inv_rev FreeGroup.Red.Step.invRev
#align free_add_group.red.step.neg_rev FreeAddGroup.Red.Step.negRev
@[to_additive]
theorem Red.invRev {L₁ L₂ : List (α × Bool)} (h : Red L₁ L₂) : Red (invRev L₁) (invRev L₂) :=
Relation.ReflTransGen.lift _ (fun _a _b => Red.Step.invRev) h
#align free_group.red.inv_rev FreeGroup.Red.invRev
#align free_add_group.red.neg_rev FreeAddGroup.Red.negRev
@[to_additive (attr := simp)]
theorem Red.step_invRev_iff :
Red.Step (FreeGroup.invRev L₁) (FreeGroup.invRev L₂) ↔ Red.Step L₁ L₂ :=
⟨fun h => by simpa only [invRev_invRev] using h.invRev, fun h => h.invRev⟩
#align free_group.red.step_inv_rev_iff FreeGroup.Red.step_invRev_iff
#align free_add_group.red.step_neg_rev_iff FreeAddGroup.Red.step_negRev_iff
@[to_additive (attr := simp)]
theorem red_invRev_iff : Red (invRev L₁) (invRev L₂) ↔ Red L₁ L₂ :=
⟨fun h => by simpa only [invRev_invRev] using h.invRev, fun h => h.invRev⟩
#align free_group.red_inv_rev_iff FreeGroup.red_invRev_iff
#align free_add_group.red_neg_rev_iff FreeAddGroup.red_negRev_iff
@[to_additive]
instance : Group (FreeGroup α) where
mul := (· * ·)
one := 1
inv := Inv.inv
mul_assoc := by rintro ⟨L₁⟩ ⟨L₂⟩ ⟨L₃⟩; simp
one_mul := by rintro ⟨L⟩; rfl
mul_one := by rintro ⟨L⟩; simp [one_eq_mk]
mul_left_inv := by
rintro ⟨L⟩
exact
List.recOn L rfl fun ⟨x, b⟩ tl ih =>
Eq.trans (Quot.sound <| by simp [invRev, one_eq_mk]) ih
/-- `of` is the canonical injection from the type to the free group over that type by sending each
element to the equivalence class of the letter that is the element. -/
@[to_additive "`of` is the canonical injection from the type to the free group over that type
by sending each element to the equivalence class of the letter that is the element."]
def of (x : α) : FreeGroup α :=
mk [(x, true)]
#align free_group.of FreeGroup.of
#align free_add_group.of FreeAddGroup.of
@[to_additive]
theorem Red.exact : mk L₁ = mk L₂ ↔ Join Red L₁ L₂ :=
calc
mk L₁ = mk L₂ ↔ EqvGen Red.Step L₁ L₂ := Iff.intro (Quot.exact _) Quot.EqvGen_sound
_ ↔ Join Red L₁ L₂ := eqvGen_step_iff_join_red
#align free_group.red.exact FreeGroup.Red.exact
#align free_add_group.red.exact FreeAddGroup.Red.exact
/-- The canonical map from the type to the free group is an injection. -/
@[to_additive "The canonical map from the type to the additive free group is an injection."]
theorem of_injective : Function.Injective (@of α) := fun _ _ H => by
let ⟨L₁, hx, hy⟩ := Red.exact.1 H
simp [Red.singleton_iff] at hx hy; aesop
#align free_group.of_injective FreeGroup.of_injective
#align free_add_group.of_injective FreeAddGroup.of_injective
section lift
variable {β : Type v} [Group β] (f : α → β) {x y : FreeGroup α}
/-- Given `f : α → β` with `β` a group, the canonical map `List (α × Bool) → β` -/
@[to_additive "Given `f : α → β` with `β` an additive group, the canonical map
`list (α × bool) → β`"]
def Lift.aux : List (α × Bool) → β := fun L =>
List.prod <| L.map fun x => cond x.2 (f x.1) (f x.1)⁻¹
#align free_group.lift.aux FreeGroup.Lift.aux
#align free_add_group.lift.aux FreeAddGroup.Lift.aux
@[to_additive]
theorem Red.Step.lift {f : α → β} (H : Red.Step L₁ L₂) : Lift.aux f L₁ = Lift.aux f L₂ := by
cases' H with _ _ _ b; cases b <;> simp [Lift.aux]
#align free_group.red.step.lift FreeGroup.Red.Step.lift
#align free_add_group.red.step.lift FreeAddGroup.Red.Step.lift
/-- If `β` is a group, then any function from `α` to `β` extends uniquely to a group homomorphism
from the free group over `α` to `β` -/
@[to_additive (attr := simps symm_apply)
"If `β` is an additive group, then any function from `α` to `β` extends uniquely to an
additive group homomorphism from the free additive group over `α` to `β`"]
def lift : (α → β) ≃ (FreeGroup α →* β) where
toFun f :=
MonoidHom.mk' (Quot.lift (Lift.aux f) fun L₁ L₂ => Red.Step.lift) <| by
rintro ⟨L₁⟩ ⟨L₂⟩; simp [Lift.aux]
invFun g := g ∘ of
left_inv f := one_mul _
right_inv g :=
MonoidHom.ext <| by
rintro ⟨L⟩
exact List.recOn L
(g.map_one.symm)
(by
rintro ⟨x, _ | _⟩ t (ih : _ = g (mk t))
· show _ = g ((of x)⁻¹ * mk t)
simpa [Lift.aux] using ih
· show _ = g (of x * mk t)
simpa [Lift.aux] using ih)
#align free_group.lift FreeGroup.lift
#align free_add_group.lift FreeAddGroup.lift
#align free_group.lift_symm_apply FreeGroup.lift_symm_apply
#align free_add_group.lift_symm_apply FreeAddGroup.lift_symm_apply
variable {f}
@[to_additive (attr := simp)]
theorem lift.mk : lift f (mk L) = List.prod (L.map fun x => cond x.2 (f x.1) (f x.1)⁻¹) :=
rfl
#align free_group.lift.mk FreeGroup.lift.mk
#align free_add_group.lift.mk FreeAddGroup.lift.mk
@[to_additive (attr := simp)]
theorem lift.of {x} : lift f (of x) = f x :=
one_mul _
#align free_group.lift.of FreeGroup.lift.of
#align free_add_group.lift.of FreeAddGroup.lift.of
@[to_additive]
theorem lift.unique (g : FreeGroup α →* β) (hg : ∀ x, g (FreeGroup.of x) = f x) {x} :
g x = FreeGroup.lift f x :=
DFunLike.congr_fun (lift.symm_apply_eq.mp (funext hg : g ∘ FreeGroup.of = f)) x
#align free_group.lift.unique FreeGroup.lift.unique
#align free_add_group.lift.unique FreeAddGroup.lift.unique
/-- Two homomorphisms out of a free group are equal if they are equal on generators.
See note [partially-applied ext lemmas]. -/
@[to_additive (attr := ext) "Two homomorphisms out of a free additive group are equal if they are
equal on generators. See note [partially-applied ext lemmas]."]
theorem ext_hom {G : Type*} [Group G] (f g : FreeGroup α →* G) (h : ∀ a, f (of a) = g (of a)) :
f = g :=
lift.symm.injective <| funext h
#align free_group.ext_hom FreeGroup.ext_hom
#align free_add_group.ext_hom FreeAddGroup.ext_hom
@[to_additive]
theorem lift_of_eq_id (α) : lift of = MonoidHom.id (FreeGroup α) :=
lift.apply_symm_apply (MonoidHom.id _)
@[to_additive]
theorem lift.of_eq (x : FreeGroup α) : lift FreeGroup.of x = x :=
DFunLike.congr_fun (lift_of_eq_id α) x
#align free_group.lift.of_eq FreeGroup.lift.of_eq
#align free_add_group.lift.of_eq FreeAddGroup.lift.of_eq
@[to_additive]
theorem lift.range_le {s : Subgroup β} (H : Set.range f ⊆ s) : (lift f).range ≤ s := by
rintro _ ⟨⟨L⟩, rfl⟩;
exact
List.recOn L s.one_mem fun ⟨x, b⟩ tl ih =>
Bool.recOn b (by simp at ih ⊢; exact s.mul_mem (s.inv_mem <| H ⟨x, rfl⟩) ih)
(by simp at ih ⊢; exact s.mul_mem (H ⟨x, rfl⟩) ih)
#align free_group.lift.range_le FreeGroup.lift.range_le
#align free_add_group.lift.range_le FreeAddGroup.lift.range_le
@[to_additive]
theorem lift.range_eq_closure : (lift f).range = Subgroup.closure (Set.range f) := by
apply le_antisymm (lift.range_le Subgroup.subset_closure)
rw [Subgroup.closure_le]
rintro _ ⟨a, rfl⟩
exact ⟨FreeGroup.of a, by simp only [lift.of]⟩
#align free_group.lift.range_eq_closure FreeGroup.lift.range_eq_closure
#align free_add_group.lift.range_eq_closure FreeAddGroup.lift.range_eq_closure
/-- The generators of `FreeGroup α` generate `FreeGroup α`. That is, the subgroup closure of the
set of generators equals `⊤`. -/
@[to_additive (attr := simp)]
theorem closure_range_of (α) :
Subgroup.closure (Set.range (FreeGroup.of : α → FreeGroup α)) = ⊤ := by
rw [← lift.range_eq_closure, lift_of_eq_id]
exact MonoidHom.range_top_of_surjective _ Function.surjective_id
end lift
section Map
variable {β : Type v} (f : α → β) {x y : FreeGroup α}
/-- Any function from `α` to `β` extends uniquely to a group homomorphism from the free group over
`α` to the free group over `β`. -/
@[to_additive "Any function from `α` to `β` extends uniquely to an additive group homomorphism from
the additive free group over `α` to the additive free group over `β`."]
def map : FreeGroup α →* FreeGroup β :=
MonoidHom.mk'
(Quot.map (List.map fun x => (f x.1, x.2)) fun L₁ L₂ H => by cases H; simp)
(by rintro ⟨L₁⟩ ⟨L₂⟩; simp)
#align free_group.map FreeGroup.map
#align free_add_group.map FreeAddGroup.map
variable {f}
@[to_additive (attr := simp)]
theorem map.mk : map f (mk L) = mk (L.map fun x => (f x.1, x.2)) :=
rfl
#align free_group.map.mk FreeGroup.map.mk
#align free_add_group.map.mk FreeAddGroup.map.mk
@[to_additive (attr := simp)]
theorem map.id (x : FreeGroup α) : map id x = x := by rcases x with ⟨L⟩; simp [List.map_id']
#align free_group.map.id FreeGroup.map.id
#align free_add_group.map.id FreeAddGroup.map.id
@[to_additive (attr := simp)]
theorem map.id' (x : FreeGroup α) : map (fun z => z) x = x :=
map.id x
#align free_group.map.id' FreeGroup.map.id'
#align free_add_group.map.id' FreeAddGroup.map.id'
@[to_additive]
theorem map.comp {γ : Type w} (f : α → β) (g : β → γ) (x) :
map g (map f x) = map (g ∘ f) x := by
rcases x with ⟨L⟩; simp [(· ∘ ·)]
#align free_group.map.comp FreeGroup.map.comp
#align free_add_group.map.comp FreeAddGroup.map.comp
@[to_additive (attr := simp)]
theorem map.of {x} : map f (of x) = of (f x) :=
rfl
#align free_group.map.of FreeGroup.map.of
#align free_add_group.map.of FreeAddGroup.map.of
@[to_additive]
theorem map.unique (g : FreeGroup α →* FreeGroup β)
(hg : ∀ x, g (FreeGroup.of x) = FreeGroup.of (f x)) :
∀ {x}, g x = map f x := by
rintro ⟨L⟩
exact List.recOn L g.map_one fun ⟨x, b⟩ t (ih : g (FreeGroup.mk t) = map f (FreeGroup.mk t)) =>
Bool.recOn b
(show g ((FreeGroup.of x)⁻¹ * FreeGroup.mk t) =
FreeGroup.map f ((FreeGroup.of x)⁻¹ * FreeGroup.mk t) by
simp [g.map_mul, g.map_inv, hg, ih])
(show g (FreeGroup.of x * FreeGroup.mk t) =
FreeGroup.map f (FreeGroup.of x * FreeGroup.mk t) by simp [g.map_mul, hg, ih])
#align free_group.map.unique FreeGroup.map.unique
#align free_add_group.map.unique FreeAddGroup.map.unique
@[to_additive]
theorem map_eq_lift : map f x = lift (of ∘ f) x :=
Eq.symm <| map.unique _ fun x => by simp
#align free_group.map_eq_lift FreeGroup.map_eq_lift
#align free_add_group.map_eq_lift FreeAddGroup.map_eq_lift
/-- Equivalent types give rise to multiplicatively equivalent free groups.
The converse can be found in `GroupTheory.FreeAbelianGroupFinsupp`,
as `Equiv.of_freeGroupEquiv`
-/
@[to_additive (attr := simps apply)
"Equivalent types give rise to additively equivalent additive free groups."]
def freeGroupCongr {α β} (e : α ≃ β) : FreeGroup α ≃* FreeGroup β where
toFun := map e
invFun := map e.symm
left_inv x := by simp [Function.comp, map.comp]
right_inv x := by simp [Function.comp, map.comp]
map_mul' := MonoidHom.map_mul _
#align free_group.free_group_congr FreeGroup.freeGroupCongr
#align free_add_group.free_add_group_congr FreeAddGroup.freeAddGroupCongr
#align free_group.free_group_congr_apply FreeGroup.freeGroupCongr_apply
#align free_add_group.free_add_group_congr_apply FreeAddGroup.freeAddGroupCongr_apply
@[to_additive (attr := simp)]
theorem freeGroupCongr_refl : freeGroupCongr (Equiv.refl α) = MulEquiv.refl _ :=
MulEquiv.ext map.id
#align free_group.free_group_congr_refl FreeGroup.freeGroupCongr_refl
#align free_add_group.free_add_group_congr_refl FreeAddGroup.freeAddGroupCongr_refl
@[to_additive (attr := simp)]
theorem freeGroupCongr_symm {α β} (e : α ≃ β) : (freeGroupCongr e).symm = freeGroupCongr e.symm :=
rfl
#align free_group.free_group_congr_symm FreeGroup.freeGroupCongr_symm
#align free_add_group.free_add_group_congr_symm FreeAddGroup.freeAddGroupCongr_symm
@[to_additive]
theorem freeGroupCongr_trans {α β γ} (e : α ≃ β) (f : β ≃ γ) :
(freeGroupCongr e).trans (freeGroupCongr f) = freeGroupCongr (e.trans f) :=
MulEquiv.ext <| map.comp _ _
#align free_group.free_group_congr_trans FreeGroup.freeGroupCongr_trans
#align free_add_group.free_add_group_congr_trans FreeAddGroup.freeAddGroupCongr_trans
end Map
section Prod
variable [Group α] (x y : FreeGroup α)
/-- If `α` is a group, then any function from `α` to `α` extends uniquely to a homomorphism from the
free group over `α` to `α`. This is the multiplicative version of `FreeGroup.sum`. -/
@[to_additive "If `α` is an additive group, then any function from `α` to `α` extends uniquely to an
additive homomorphism from the additive free group over `α` to `α`."]
def prod : FreeGroup α →* α :=
lift id
#align free_group.prod FreeGroup.prod
#align free_add_group.sum FreeAddGroup.sum
variable {x y}
@[to_additive (attr := simp)]
theorem prod_mk : prod (mk L) = List.prod (L.map fun x => cond x.2 x.1 x.1⁻¹) :=
rfl
#align free_group.prod_mk FreeGroup.prod_mk
#align free_add_group.sum_mk FreeAddGroup.sum_mk
@[to_additive (attr := simp)]
theorem prod.of {x : α} : prod (of x) = x :=
lift.of
#align free_group.prod.of FreeGroup.prod.of
#align free_add_group.sum.of FreeAddGroup.sum.of
@[to_additive]
theorem prod.unique (g : FreeGroup α →* α) (hg : ∀ x, g (FreeGroup.of x) = x) {x} : g x = prod x :=
lift.unique g hg
#align free_group.prod.unique FreeGroup.prod.unique
#align free_add_group.sum.unique FreeAddGroup.sum.unique
end Prod
@[to_additive]
theorem lift_eq_prod_map {β : Type v} [Group β] {f : α → β} {x} : lift f x = prod (map f x) := by
rw [← lift.unique (prod.comp (map f))]
· rfl
· simp
#align free_group.lift_eq_prod_map FreeGroup.lift_eq_prod_map
#align free_add_group.lift_eq_sum_map FreeAddGroup.lift_eq_sum_map
section Sum
variable [AddGroup α] (x y : FreeGroup α)
/-- If `α` is a group, then any function from `α` to `α` extends uniquely to a homomorphism from the
free group over `α` to `α`. This is the additive version of `Prod`. -/
def sum : α :=
@prod (Multiplicative _) _ x
#align free_group.sum FreeGroup.sum
variable {x y}
@[simp]
theorem sum_mk : sum (mk L) = List.sum (L.map fun x => cond x.2 x.1 (-x.1)) :=
rfl
#align free_group.sum_mk FreeGroup.sum_mk
@[simp]
theorem sum.of {x : α} : sum (of x) = x :=
@prod.of _ (_) _
#align free_group.sum.of FreeGroup.sum.of
-- note: there are no bundled homs with different notation in the domain and codomain, so we copy
-- these manually
@[simp]
theorem sum.map_mul : sum (x * y) = sum x + sum y :=
(@prod (Multiplicative _) _).map_mul _ _
#align free_group.sum.map_mul FreeGroup.sum.map_mul
@[simp]
theorem sum.map_one : sum (1 : FreeGroup α) = 0 :=
(@prod (Multiplicative _) _).map_one
#align free_group.sum.map_one FreeGroup.sum.map_one
@[simp]
theorem sum.map_inv : sum x⁻¹ = -sum x :=
(prod : FreeGroup (Multiplicative α) →* Multiplicative α).map_inv _
#align free_group.sum.map_inv FreeGroup.sum.map_inv
end Sum
/-- The bijection between the free group on the empty type, and a type with one element. -/
@[to_additive "The bijection between the additive free group on the empty type, and a type with one
element."]
def freeGroupEmptyEquivUnit : FreeGroup Empty ≃ Unit where
toFun _ := ()
invFun _ := 1
left_inv := by rintro ⟨_ | ⟨⟨⟨⟩, _⟩, _⟩⟩; rfl
right_inv := fun ⟨⟩ => rfl
#align free_group.free_group_empty_equiv_unit FreeGroup.freeGroupEmptyEquivUnit
#align free_add_group.free_add_group_empty_equiv_add_unit FreeAddGroup.freeAddGroupEmptyEquivAddUnit
/-- The bijection between the free group on a singleton, and the integers. -/
def freeGroupUnitEquivInt : FreeGroup Unit ≃ ℤ where
toFun x := sum (by
revert x
change (FreeGroup Unit →* FreeGroup ℤ)
apply map fun _ => (1 : ℤ))
invFun x := of () ^ x
left_inv := by
rintro ⟨L⟩
simp only [quot_mk_eq_mk, map.mk, sum_mk, List.map_map]
exact List.recOn L
(by rfl)
(fun ⟨⟨⟩, b⟩ tl ih => by
cases b <;> simp [zpow_add] at ih ⊢ <;> rw [ih] <;> rfl)
right_inv x :=
Int.induction_on x (by simp)
(fun i ih => by
simp only [zpow_natCast, map_pow, map.of] at ih
simp [zpow_add, ih])
(fun i ih => by
simp only [zpow_neg, zpow_natCast, map_inv, map_pow, map.of, sum.map_inv, neg_inj] at ih
simp [zpow_add, ih, sub_eq_add_neg])
#align free_group.free_group_unit_equiv_int FreeGroup.freeGroupUnitEquivInt
section Category
variable {β : Type u}
@[to_additive]
instance : Monad FreeGroup.{u} where
pure {_α} := of
map {_α} {_β} {f} := map f
bind {_α} {_β} {x} {f} := lift f x
@[to_additive (attr := elab_as_elim)]
protected theorem induction_on {C : FreeGroup α → Prop} (z : FreeGroup α) (C1 : C 1)
(Cp : ∀ x, C <| pure x) (Ci : ∀ x, C (pure x) → C (pure x)⁻¹)
(Cm : ∀ x y, C x → C y → C (x * y)) : C z :=
Quot.inductionOn z fun L =>
List.recOn L C1 fun ⟨x, b⟩ _tl ih => Bool.recOn b (Cm _ _ (Ci _ <| Cp x) ih) (Cm _ _ (Cp x) ih)
#align free_group.induction_on FreeGroup.induction_on
#align free_add_group.induction_on FreeAddGroup.induction_on
-- porting note (#10618): simp can prove this: by simp only [@map_pure]
@[to_additive]
theorem map_pure (f : α → β) (x : α) : f <$> (pure x : FreeGroup α) = pure (f x) :=
map.of
#align free_group.map_pure FreeGroup.map_pure
#align free_add_group.map_pure FreeAddGroup.map_pure
@[to_additive (attr := simp)]
theorem map_one (f : α → β) : f <$> (1 : FreeGroup α) = 1 :=
(map f).map_one
#align free_group.map_one FreeGroup.map_one
#align free_add_group.map_zero FreeAddGroup.map_zero
@[to_additive (attr := simp)]
theorem map_mul (f : α → β) (x y : FreeGroup α) : f <$> (x * y) = f <$> x * f <$> y :=
(map f).map_mul x y
#align free_group.map_mul FreeGroup.map_mul
#align free_add_group.map_add FreeAddGroup.map_add
@[to_additive (attr := simp)]
theorem map_inv (f : α → β) (x : FreeGroup α) : f <$> x⁻¹ = (f <$> x)⁻¹ :=
(map f).map_inv x
#align free_group.map_inv FreeGroup.map_inv
#align free_add_group.map_neg FreeAddGroup.map_neg
-- porting note (#10618): simp can prove this: by simp only [@pure_bind]
@[to_additive]
theorem pure_bind (f : α → FreeGroup β) (x) : pure x >>= f = f x :=
lift.of
#align free_group.pure_bind FreeGroup.pure_bind
#align free_add_group.pure_bind FreeAddGroup.pure_bind
@[to_additive (attr := simp)]
theorem one_bind (f : α → FreeGroup β) : 1 >>= f = 1 :=
(lift f).map_one
#align free_group.one_bind FreeGroup.one_bind
#align free_add_group.zero_bind FreeAddGroup.zero_bind
@[to_additive (attr := simp)]
theorem mul_bind (f : α → FreeGroup β) (x y : FreeGroup α) : x * y >>= f = (x >>= f) * (y >>= f) :=
(lift f).map_mul _ _
#align free_group.mul_bind FreeGroup.mul_bind
#align free_add_group.add_bind FreeAddGroup.add_bind
@[to_additive (attr := simp)]
theorem inv_bind (f : α → FreeGroup β) (x : FreeGroup α) : x⁻¹ >>= f = (x >>= f)⁻¹ :=
(lift f).map_inv _
#align free_group.inv_bind FreeGroup.inv_bind
#align free_add_group.neg_bind FreeAddGroup.neg_bind
@[to_additive]
instance : LawfulMonad FreeGroup.{u} := LawfulMonad.mk'
(id_map := fun x =>
FreeGroup.induction_on x (map_one id) (fun x => map_pure id x) (fun x ih => by rw [map_inv, ih])
fun x y ihx ihy => by rw [map_mul, ihx, ihy])
(pure_bind := fun x f => pure_bind f x)
(bind_assoc := fun x =>
FreeGroup.induction_on x
(by intros; iterate 3 rw [one_bind])
(fun x => by intros; iterate 2 rw [pure_bind])
(fun x ih => by intros; (iterate 3 rw [inv_bind]); rw [ih])
(fun x y ihx ihy => by intros; (iterate 3 rw [mul_bind]); rw [ihx, ihy]))
(bind_pure_comp := fun f x =>
FreeGroup.induction_on x (by rw [one_bind, map_one]) (fun x => by rw [pure_bind, map_pure])
(fun x ih => by rw [inv_bind, map_inv, ih]) fun x y ihx ihy => by
rw [mul_bind, map_mul, ihx, ihy])
end Category
section Reduce
variable [DecidableEq α]
/-- The maximal reduction of a word. It is computable
iff `α` has decidable equality. -/
@[to_additive "The maximal reduction of a word. It is computable iff `α` has decidable equality."]
def reduce : (L : List (α × Bool)) -> List (α × Bool) :=
List.rec [] fun hd1 _tl1 ih =>
List.casesOn ih [hd1] fun hd2 tl2 =>
if hd1.1 = hd2.1 ∧ hd1.2 = not hd2.2 then tl2 else hd1 :: hd2 :: tl2
#align free_group.reduce FreeGroup.reduce
#align free_add_group.reduce FreeAddGroup.reduce
@[to_additive (attr := simp)]
theorem reduce.cons (x) :
reduce (x :: L) =
List.casesOn (reduce L) [x] fun hd tl =>
if x.1 = hd.1 ∧ x.2 = not hd.2 then tl else x :: hd :: tl :=
rfl
#align free_group.reduce.cons FreeGroup.reduce.cons
#align free_add_group.reduce.cons FreeAddGroup.reduce.cons
/-- The first theorem that characterises the function `reduce`: a word reduces to its maximal
reduction. -/
@[to_additive "The first theorem that characterises the function `reduce`: a word reduces to its
maximal reduction."]
theorem reduce.red : Red L (reduce L) := by
induction L with
| nil => constructor
| cons hd1 tl1 ih =>
dsimp
revert ih
generalize htl : reduce tl1 = TL
intro ih
cases TL with
| nil => exact Red.cons_cons ih
| cons hd2 tl2 =>
dsimp only
split_ifs with h
· cases hd1
cases hd2
cases h
dsimp at *
subst_vars
apply Red.trans (Red.cons_cons ih)
exact Red.Step.cons_not_rev.to_red
· exact Red.cons_cons ih
#align free_group.reduce.red FreeGroup.reduce.red
#align free_add_group.reduce.red FreeAddGroup.reduce.red
@[to_additive]
theorem reduce.not {p : Prop} :
∀ {L₁ L₂ L₃ : List (α × Bool)} {x b}, reduce L₁ = L₂ ++ (x, b) :: (x, !b) :: L₃ → p
| [], L2, L3, _, _ => fun h => by cases L2 <;> injections
| (x, b) :: L1, L2, L3, x', b' => by
dsimp
cases r : reduce L1 with
| nil =>
dsimp; intro h
exfalso
have := congr_arg List.length h
simp? [List.length] at this says
simp only [List.length, zero_add, List.length_append] at this
rw [add_comm, add_assoc, add_assoc, add_comm, <-add_assoc] at this
omega
| cons hd tail =>
cases' hd with y c
dsimp only
split_ifs with h <;> intro H
· rw [H] at r
exact @reduce.not _ L1 ((y, c) :: L2) L3 x' b' r
rcases L2 with (_ | ⟨a, L2⟩)
· injections; subst_vars
simp at h
· refine @reduce.not _ L1 L2 L3 x' b' ?_
injection H with _ H
rw [r, H]; rfl
#align free_group.reduce.not FreeGroup.reduce.not
#align free_add_group.reduce.not FreeAddGroup.reduce.not
/-- The second theorem that characterises the function `reduce`: the maximal reduction of a word
only reduces to itself. -/
@[to_additive "The second theorem that characterises the function `reduce`: the maximal reduction of
a word only reduces to itself."]
theorem reduce.min (H : Red (reduce L₁) L₂) : reduce L₁ = L₂ := by
induction' H with L1 L' L2 H1 H2 ih
· rfl
· cases' H1 with L4 L5 x b
exact reduce.not H2
#align free_group.reduce.min FreeGroup.reduce.min
#align free_add_group.reduce.min FreeAddGroup.reduce.min
/-- `reduce` is idempotent, i.e. the maximal reduction of the maximal reduction of a word is the
maximal reduction of the word. -/
@[to_additive (attr := simp) "`reduce` is idempotent, i.e. the maximal reduction of the maximal
reduction of a word is the maximal reduction of the word."]
theorem reduce.idem : reduce (reduce L) = reduce L :=
Eq.symm <| reduce.min reduce.red
#align free_group.reduce.idem FreeGroup.reduce.idem
#align free_add_group.reduce.idem FreeAddGroup.reduce.idem
@[to_additive]
theorem reduce.Step.eq (H : Red.Step L₁ L₂) : reduce L₁ = reduce L₂ :=
let ⟨_L₃, HR13, HR23⟩ := Red.church_rosser reduce.red (reduce.red.head H)
(reduce.min HR13).trans (reduce.min HR23).symm
#align free_group.reduce.step.eq FreeGroup.reduce.Step.eq
#align free_add_group.reduce.step.eq FreeAddGroup.reduce.Step.eq
/-- If a word reduces to another word, then they have a common maximal reduction. -/
@[to_additive "If a word reduces to another word, then they have a common maximal reduction."]
theorem reduce.eq_of_red (H : Red L₁ L₂) : reduce L₁ = reduce L₂ :=
let ⟨_L₃, HR13, HR23⟩ := Red.church_rosser reduce.red (Red.trans H reduce.red)
(reduce.min HR13).trans (reduce.min HR23).symm
#align free_group.reduce.eq_of_red FreeGroup.reduce.eq_of_red
#align free_add_group.reduce.eq_of_red FreeAddGroup.reduce.eq_of_red
alias red.reduce_eq := reduce.eq_of_red
#align free_group.red.reduce_eq FreeGroup.red.reduce_eq
alias freeAddGroup.red.reduce_eq := FreeAddGroup.reduce.eq_of_red
#align free_group.free_add_group.red.reduce_eq FreeGroup.freeAddGroup.red.reduce_eq
@[to_additive]
theorem Red.reduce_right (h : Red L₁ L₂) : Red L₁ (reduce L₂) :=
reduce.eq_of_red h ▸ reduce.red
#align free_group.red.reduce_right FreeGroup.Red.reduce_right
#align free_add_group.red.reduce_right FreeAddGroup.Red.reduce_right
@[to_additive]
theorem Red.reduce_left (h : Red L₁ L₂) : Red L₂ (reduce L₁) :=
(reduce.eq_of_red h).symm ▸ reduce.red
#align free_group.red.reduce_left FreeGroup.Red.reduce_left
#align free_add_group.red.reduce_left FreeAddGroup.Red.reduce_left
/-- If two words correspond to the same element in the free group, then they
have a common maximal reduction. This is the proof that the function that sends
an element of the free group to its maximal reduction is well-defined. -/
@[to_additive "If two words correspond to the same element in the additive free group, then they
have a common maximal reduction. This is the proof that the function that sends an element of the
free group to its maximal reduction is well-defined."]
theorem reduce.sound (H : mk L₁ = mk L₂) : reduce L₁ = reduce L₂ :=
let ⟨_L₃, H13, H23⟩ := Red.exact.1 H
(reduce.eq_of_red H13).trans (reduce.eq_of_red H23).symm
#align free_group.reduce.sound FreeGroup.reduce.sound
#align free_add_group.reduce.sound FreeAddGroup.reduce.sound
/-- If two words have a common maximal reduction, then they correspond to the same element in the
free group. -/
@[to_additive "If two words have a common maximal reduction, then they correspond to the same
element in the additive free group."]
theorem reduce.exact (H : reduce L₁ = reduce L₂) : mk L₁ = mk L₂ :=
Red.exact.2 ⟨reduce L₂, H ▸ reduce.red, reduce.red⟩
#align free_group.reduce.exact FreeGroup.reduce.exact
#align free_add_group.reduce.exact FreeAddGroup.reduce.exact
/-- A word and its maximal reduction correspond to the same element of the free group. -/
@[to_additive "A word and its maximal reduction correspond to the same element of the additive free
group."]
theorem reduce.self : mk (reduce L) = mk L :=
reduce.exact reduce.idem
#align free_group.reduce.self FreeGroup.reduce.self
#align free_add_group.reduce.self FreeAddGroup.reduce.self
/-- If words `w₁ w₂` are such that `w₁` reduces to `w₂`, then `w₂` reduces to the maximal reduction
of `w₁`. -/
@[to_additive "If words `w₁ w₂` are such that `w₁` reduces to `w₂`, then `w₂` reduces to the maximal
reduction of `w₁`."]
theorem reduce.rev (H : Red L₁ L₂) : Red L₂ (reduce L₁) :=
(reduce.eq_of_red H).symm ▸ reduce.red
#align free_group.reduce.rev FreeGroup.reduce.rev
#align free_add_group.reduce.rev FreeAddGroup.reduce.rev
/-- The function that sends an element of the free group to its maximal reduction. -/
@[to_additive "The function that sends an element of the additive free group to its maximal
reduction."]
def toWord : FreeGroup α → List (α × Bool) :=
Quot.lift reduce fun _L₁ _L₂ H => reduce.Step.eq H
#align free_group.to_word FreeGroup.toWord
#align free_add_group.to_word FreeAddGroup.toWord
@[to_additive]
theorem mk_toWord : ∀ {x : FreeGroup α}, mk (toWord x) = x := by rintro ⟨L⟩; exact reduce.self
#align free_group.mk_to_word FreeGroup.mk_toWord
#align free_add_group.mk_to_word FreeAddGroup.mk_toWord
@[to_additive]
theorem toWord_injective : Function.Injective (toWord : FreeGroup α → List (α × Bool)) := by
rintro ⟨L₁⟩ ⟨L₂⟩; exact reduce.exact
#align free_group.to_word_injective FreeGroup.toWord_injective
#align free_add_group.to_word_injective FreeAddGroup.toWord_injective
@[to_additive (attr := simp)]
theorem toWord_inj {x y : FreeGroup α} : toWord x = toWord y ↔ x = y :=
toWord_injective.eq_iff
#align free_group.to_word_inj FreeGroup.toWord_inj
#align free_add_group.to_word_inj FreeAddGroup.toWord_inj
@[to_additive (attr := simp)]
theorem toWord_mk : (mk L₁).toWord = reduce L₁ :=
rfl
#align free_group.to_word_mk FreeGroup.toWord_mk
#align free_add_group.to_word_mk FreeAddGroup.toWord_mk
@[to_additive (attr := simp)]
theorem reduce_toWord : ∀ x : FreeGroup α, reduce (toWord x) = toWord x := by
rintro ⟨L⟩
exact reduce.idem
#align free_group.reduce_to_word FreeGroup.reduce_toWord
#align free_add_group.reduce_to_word FreeAddGroup.reduce_toWord
@[to_additive (attr := simp)]
theorem toWord_one : (1 : FreeGroup α).toWord = [] :=
rfl
#align free_group.to_word_one FreeGroup.toWord_one
#align free_add_group.to_word_zero FreeAddGroup.toWord_zero
@[to_additive (attr := simp)]
theorem toWord_eq_nil_iff {x : FreeGroup α} : x.toWord = [] ↔ x = 1 :=
toWord_injective.eq_iff' toWord_one
#align free_group.to_word_eq_nil_iff FreeGroup.toWord_eq_nil_iff
#align free_add_group.to_word_eq_nil_iff FreeAddGroup.toWord_eq_nil_iff
@[to_additive]
theorem reduce_invRev {w : List (α × Bool)} : reduce (invRev w) = invRev (reduce w) := by
apply reduce.min
rw [← red_invRev_iff, invRev_invRev]
apply Red.reduce_left
have : Red (invRev (invRev w)) (invRev (reduce (invRev w))) := reduce.red.invRev
rwa [invRev_invRev] at this
#align free_group.reduce_inv_rev FreeGroup.reduce_invRev
#align free_add_group.reduce_neg_rev FreeAddGroup.reduce_negRev
@[to_additive]
theorem toWord_inv {x : FreeGroup α} : x⁻¹.toWord = invRev x.toWord := by
rcases x with ⟨L⟩
rw [quot_mk_eq_mk, inv_mk, toWord_mk, toWord_mk, reduce_invRev]
#align free_group.to_word_inv FreeGroup.toWord_inv
#align free_add_group.to_word_neg FreeAddGroup.toWord_neg
/-- **Constructive Church-Rosser theorem** (compare `church_rosser`). -/
@[to_additive "**Constructive Church-Rosser theorem** (compare `church_rosser`)."]
def reduce.churchRosser (H12 : Red L₁ L₂) (H13 : Red L₁ L₃) : { L₄ // Red L₂ L₄ ∧ Red L₃ L₄ } :=
⟨reduce L₁, reduce.rev H12, reduce.rev H13⟩
#align free_group.reduce.church_rosser FreeGroup.reduce.churchRosser
#align free_add_group.reduce.church_rosser FreeAddGroup.reduce.churchRosser
@[to_additive]
instance : DecidableEq (FreeGroup α) :=
toWord_injective.decidableEq
-- TODO @[to_additive] doesn't succeed, possibly due to a bug
instance Red.decidableRel : DecidableRel (@Red α)
| [], [] => isTrue Red.refl
| [], _hd2 :: _tl2 => isFalse fun H => List.noConfusion (Red.nil_iff.1 H)
| (x, b) :: tl, [] =>
match Red.decidableRel tl [(x, not b)] with
| isTrue H => isTrue <| Red.trans (Red.cons_cons H) <| (@Red.Step.not _ [] [] _ _).to_red
| isFalse H => isFalse fun H2 => H <| Red.cons_nil_iff_singleton.1 H2
| (x1, b1) :: tl1, (x2, b2) :: tl2 =>
if h : (x1, b1) = (x2, b2) then
match Red.decidableRel tl1 tl2 with
| isTrue H => isTrue <| h ▸ Red.cons_cons H
| isFalse H => isFalse fun H2 => H <| (Red.cons_cons_iff _).1 <| h.symm ▸ H2
else
match Red.decidableRel tl1 ((x1, ! b1) :: (x2, b2) :: tl2) with
| isTrue H => isTrue <| (Red.cons_cons H).tail Red.Step.cons_not
| isFalse H => isFalse fun H2 => H <| Red.inv_of_red_of_ne h H2
#align free_group.red.decidable_rel FreeGroup.Red.decidableRel
/-- A list containing every word that `w₁` reduces to. -/
def Red.enum (L₁ : List (α × Bool)) : List (List (α × Bool)) :=
List.filter (Red L₁) (List.sublists L₁)
#align free_group.red.enum FreeGroup.Red.enum
theorem Red.enum.sound (H : L₂ ∈ List.filter (Red L₁) (List.sublists L₁)) : Red L₁ L₂ :=
of_decide_eq_true (@List.of_mem_filter _ _ L₂ _ H)
#align free_group.red.enum.sound FreeGroup.Red.enum.sound
theorem Red.enum.complete (H : Red L₁ L₂) : L₂ ∈ Red.enum L₁ :=
List.mem_filter_of_mem (List.mem_sublists.2 <| Red.sublist H) (decide_eq_true H)
#align free_group.red.enum.complete FreeGroup.Red.enum.complete
instance : Fintype { L₂ // Red L₁ L₂ } :=
Fintype.subtype (List.toFinset <| Red.enum L₁) fun _L₂ =>
⟨fun H => Red.enum.sound <| List.mem_toFinset.1 H, fun H =>
List.mem_toFinset.2 <| Red.enum.complete H⟩
end Reduce
section Metric
variable [DecidableEq α]
/-- The length of reduced words provides a norm on a free group. -/
@[to_additive "The length of reduced words provides a norm on an additive free group."]
def norm (x : FreeGroup α) : ℕ :=
x.toWord.length
#align free_group.norm FreeGroup.norm
#align free_add_group.norm FreeAddGroup.norm
@[to_additive (attr := simp)]
| Mathlib/GroupTheory/FreeGroup/Basic.lean | 1,410 | 1,411 | theorem norm_inv_eq {x : FreeGroup α} : norm x⁻¹ = norm x := by |
simp only [norm, toWord_inv, invRev_length]
|
/-
Copyright (c) 2020 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Adam Topaz, Eric Wieser
-/
import Mathlib.Algebra.Algebra.Subalgebra.Basic
import Mathlib.Algebra.Algebra.Tower
import Mathlib.Algebra.MonoidAlgebra.NoZeroDivisors
import Mathlib.RingTheory.Adjoin.Basic
#align_import algebra.free_algebra from "leanprover-community/mathlib"@"6623e6af705e97002a9054c1c05a980180276fc1"
/-!
# Free Algebras
Given a commutative semiring `R`, and a type `X`, we construct the free unital, associative
`R`-algebra on `X`.
## Notation
1. `FreeAlgebra R X` is the free algebra itself. It is endowed with an `R`-algebra structure.
2. `FreeAlgebra.ι R` is the function `X → FreeAlgebra R X`.
3. Given a function `f : X → A` to an R-algebra `A`, `lift R f` is the lift of `f` to an
`R`-algebra morphism `FreeAlgebra R X → A`.
## Theorems
1. `ι_comp_lift` states that the composition `(lift R f) ∘ (ι R)` is identical to `f`.
2. `lift_unique` states that whenever an R-algebra morphism `g : FreeAlgebra R X → A` is
given whose composition with `ι R` is `f`, then one has `g = lift R f`.
3. `hom_ext` is a variant of `lift_unique` in the form of an extensionality theorem.
4. `lift_comp_ι` is a combination of `ι_comp_lift` and `lift_unique`. It states that the lift
of the composition of an algebra morphism with `ι` is the algebra morphism itself.
5. `equivMonoidAlgebraFreeMonoid : FreeAlgebra R X ≃ₐ[R] MonoidAlgebra R (FreeMonoid X)`
6. An inductive principle `induction`.
## Implementation details
We construct the free algebra on `X` as a quotient of an inductive type `FreeAlgebra.Pre` by an
inductively defined relation `FreeAlgebra.Rel`. Explicitly, the construction involves three steps:
1. We construct an inductive type `FreeAlgebra.Pre R X`, the terms of which should be thought
of as representatives for the elements of `FreeAlgebra R X`.
It is the free type with maps from `R` and `X`, and with two binary operations `add` and `mul`.
2. We construct an inductive relation `FreeAlgebra.Rel R X` on `FreeAlgebra.Pre R X`.
This is the smallest relation for which the quotient is an `R`-algebra where addition resp.
multiplication are induced by `add` resp. `mul` from 1., and for which the map from `R` is the
structure map for the algebra.
3. The free algebra `FreeAlgebra R X` is the quotient of `FreeAlgebra.Pre R X` by
the relation `FreeAlgebra.Rel R X`.
-/
variable (R : Type*) [CommSemiring R]
variable (X : Type*)
namespace FreeAlgebra
/-- This inductive type is used to express representatives of the free algebra.
-/
inductive Pre
| of : X → Pre
| ofScalar : R → Pre
| add : Pre → Pre → Pre
| mul : Pre → Pre → Pre
#align free_algebra.pre FreeAlgebra.Pre
namespace Pre
instance : Inhabited (Pre R X) := ⟨ofScalar 0⟩
-- Note: These instances are only used to simplify the notation.
/-- Coercion from `X` to `Pre R X`. Note: Used for notation only. -/
def hasCoeGenerator : Coe X (Pre R X) := ⟨of⟩
#align free_algebra.pre.has_coe_generator FreeAlgebra.Pre.hasCoeGenerator
/-- Coercion from `R` to `Pre R X`. Note: Used for notation only. -/
def hasCoeSemiring : Coe R (Pre R X) := ⟨ofScalar⟩
#align free_algebra.pre.has_coe_semiring FreeAlgebra.Pre.hasCoeSemiring
/-- Multiplication in `Pre R X` defined as `Pre.mul`. Note: Used for notation only. -/
def hasMul : Mul (Pre R X) := ⟨mul⟩
#align free_algebra.pre.has_mul FreeAlgebra.Pre.hasMul
/-- Addition in `Pre R X` defined as `Pre.add`. Note: Used for notation only. -/
def hasAdd : Add (Pre R X) := ⟨add⟩
#align free_algebra.pre.has_add FreeAlgebra.Pre.hasAdd
/-- Zero in `Pre R X` defined as the image of `0` from `R`. Note: Used for notation only. -/
def hasZero : Zero (Pre R X) := ⟨ofScalar 0⟩
#align free_algebra.pre.has_zero FreeAlgebra.Pre.hasZero
/-- One in `Pre R X` defined as the image of `1` from `R`. Note: Used for notation only. -/
def hasOne : One (Pre R X) := ⟨ofScalar 1⟩
#align free_algebra.pre.has_one FreeAlgebra.Pre.hasOne
/-- Scalar multiplication defined as multiplication by the image of elements from `R`.
Note: Used for notation only.
-/
def hasSMul : SMul R (Pre R X) := ⟨fun r m ↦ mul (ofScalar r) m⟩
#align free_algebra.pre.has_smul FreeAlgebra.Pre.hasSMul
end Pre
attribute [local instance] Pre.hasCoeGenerator Pre.hasCoeSemiring Pre.hasMul Pre.hasAdd
Pre.hasZero Pre.hasOne Pre.hasSMul
/-- Given a function from `X` to an `R`-algebra `A`, `lift_fun` provides a lift of `f` to a function
from `Pre R X` to `A`. This is mainly used in the construction of `FreeAlgebra.lift`.
-/
-- Porting note: recOn was replaced to preserve computability, see lean4#2049
def liftFun {A : Type*} [Semiring A] [Algebra R A] (f : X → A) :
Pre R X → A
| .of t => f t
| .add a b => liftFun f a + liftFun f b
| .mul a b => liftFun f a * liftFun f b
| .ofScalar c => algebraMap _ _ c
#align free_algebra.lift_fun FreeAlgebra.liftFun
/-- An inductively defined relation on `Pre R X` used to force the initial algebra structure on
the associated quotient.
-/
inductive Rel : Pre R X → Pre R X → Prop
-- force `ofScalar` to be a central semiring morphism
| add_scalar {r s : R} : Rel (↑(r + s)) (↑r + ↑s)
| mul_scalar {r s : R} : Rel (↑(r * s)) (↑r * ↑s)
| central_scalar {r : R} {a : Pre R X} : Rel (r * a) (a * r)
-- commutative additive semigroup
| add_assoc {a b c : Pre R X} : Rel (a + b + c) (a + (b + c))
| add_comm {a b : Pre R X} : Rel (a + b) (b + a)
| zero_add {a : Pre R X} : Rel (0 + a) a
-- multiplicative monoid
| mul_assoc {a b c : Pre R X} : Rel (a * b * c) (a * (b * c))
| one_mul {a : Pre R X} : Rel (1 * a) a
| mul_one {a : Pre R X} : Rel (a * 1) a
-- distributivity
| left_distrib {a b c : Pre R X} : Rel (a * (b + c)) (a * b + a * c)
| right_distrib {a b c : Pre R X} :
Rel ((a + b) * c) (a * c + b * c)
-- other relations needed for semiring
| zero_mul {a : Pre R X} : Rel (0 * a) 0
| mul_zero {a : Pre R X} : Rel (a * 0) 0
-- compatibility
| add_compat_left {a b c : Pre R X} : Rel a b → Rel (a + c) (b + c)
| add_compat_right {a b c : Pre R X} : Rel a b → Rel (c + a) (c + b)
| mul_compat_left {a b c : Pre R X} : Rel a b → Rel (a * c) (b * c)
| mul_compat_right {a b c : Pre R X} : Rel a b → Rel (c * a) (c * b)
#align free_algebra.rel FreeAlgebra.Rel
end FreeAlgebra
/-- The free algebra for the type `X` over the commutative semiring `R`.
-/
def FreeAlgebra :=
Quot (FreeAlgebra.Rel R X)
#align free_algebra FreeAlgebra
namespace FreeAlgebra
attribute [local instance] Pre.hasCoeGenerator Pre.hasCoeSemiring Pre.hasMul Pre.hasAdd
Pre.hasZero Pre.hasOne Pre.hasSMul
/-! Define the basic operations-/
instance instSMul {A} [CommSemiring A] [Algebra R A] : SMul R (FreeAlgebra A X) where
smul r := Quot.map (HMul.hMul (algebraMap R A r : Pre A X)) fun _ _ ↦ Rel.mul_compat_right
instance instZero : Zero (FreeAlgebra R X) where zero := Quot.mk _ 0
instance instOne : One (FreeAlgebra R X) where one := Quot.mk _ 1
instance instAdd : Add (FreeAlgebra R X) where
add := Quot.map₂ HAdd.hAdd (fun _ _ _ ↦ Rel.add_compat_right) fun _ _ _ ↦ Rel.add_compat_left
instance instMul : Mul (FreeAlgebra R X) where
mul := Quot.map₂ HMul.hMul (fun _ _ _ ↦ Rel.mul_compat_right) fun _ _ _ ↦ Rel.mul_compat_left
-- `Quot.mk` is an implementation detail of `FreeAlgebra`, so this lemma is private
private theorem mk_mul (x y : Pre R X) :
Quot.mk (Rel R X) (x * y) = (HMul.hMul (self := instHMul (α := FreeAlgebra R X))
(Quot.mk (Rel R X) x) (Quot.mk (Rel R X) y)) :=
rfl
/-! Build the semiring structure. We do this one piece at a time as this is convenient for proving
the `nsmul` fields. -/
instance instMonoidWithZero : MonoidWithZero (FreeAlgebra R X) where
mul_assoc := by
rintro ⟨⟩ ⟨⟩ ⟨⟩
exact Quot.sound Rel.mul_assoc
one := Quot.mk _ 1
one_mul := by
rintro ⟨⟩
exact Quot.sound Rel.one_mul
mul_one := by
rintro ⟨⟩
exact Quot.sound Rel.mul_one
zero_mul := by
rintro ⟨⟩
exact Quot.sound Rel.zero_mul
mul_zero := by
rintro ⟨⟩
exact Quot.sound Rel.mul_zero
instance instDistrib : Distrib (FreeAlgebra R X) where
left_distrib := by
rintro ⟨⟩ ⟨⟩ ⟨⟩
exact Quot.sound Rel.left_distrib
right_distrib := by
rintro ⟨⟩ ⟨⟩ ⟨⟩
exact Quot.sound Rel.right_distrib
instance instAddCommMonoid : AddCommMonoid (FreeAlgebra R X) where
add_assoc := by
rintro ⟨⟩ ⟨⟩ ⟨⟩
exact Quot.sound Rel.add_assoc
zero_add := by
rintro ⟨⟩
exact Quot.sound Rel.zero_add
add_zero := by
rintro ⟨⟩
change Quot.mk _ _ = _
rw [Quot.sound Rel.add_comm, Quot.sound Rel.zero_add]
add_comm := by
rintro ⟨⟩ ⟨⟩
exact Quot.sound Rel.add_comm
nsmul := (· • ·)
nsmul_zero := by
rintro ⟨⟩
change Quot.mk _ (_ * _) = _
rw [map_zero]
exact Quot.sound Rel.zero_mul
nsmul_succ n := by
rintro ⟨a⟩
dsimp only [HSMul.hSMul, instSMul, Quot.map]
rw [map_add, map_one, mk_mul, mk_mul, ← add_one_mul (_ : FreeAlgebra R X)]
congr 1
exact Quot.sound Rel.add_scalar
instance : Semiring (FreeAlgebra R X) where
__ := instMonoidWithZero R X
__ := instAddCommMonoid R X
__ := instDistrib R X
natCast n := Quot.mk _ (n : R)
natCast_zero := by simp; rfl
natCast_succ n := by simp; exact Quot.sound Rel.add_scalar
instance : Inhabited (FreeAlgebra R X) :=
⟨0⟩
instance instAlgebra {A} [CommSemiring A] [Algebra R A] : Algebra R (FreeAlgebra A X) where
toRingHom := ({
toFun := fun r => Quot.mk _ r
map_one' := rfl
map_mul' := fun _ _ => Quot.sound Rel.mul_scalar
map_zero' := rfl
map_add' := fun _ _ => Quot.sound Rel.add_scalar } : A →+* FreeAlgebra A X).comp
(algebraMap R A)
commutes' _ := by
rintro ⟨⟩
exact Quot.sound Rel.central_scalar
smul_def' _ _ := rfl
-- verify there is no diamond at `default` transparency but we will need
-- `reducible_and_instances` which currently fails #10906
variable (S : Type) [CommSemiring S] in
example : (algebraNat : Algebra ℕ (FreeAlgebra S X)) = instAlgebra _ _ := rfl
instance {R S A} [CommSemiring R] [CommSemiring S] [CommSemiring A]
[SMul R S] [Algebra R A] [Algebra S A] [IsScalarTower R S A] :
IsScalarTower R S (FreeAlgebra A X) where
smul_assoc r s x := by
change algebraMap S A (r • s) • x = algebraMap R A _ • (algebraMap S A _ • x)
rw [← smul_assoc]
congr
simp only [Algebra.algebraMap_eq_smul_one, smul_eq_mul]
rw [smul_assoc, ← smul_one_mul]
instance {R S A} [CommSemiring R] [CommSemiring S] [CommSemiring A] [Algebra R A] [Algebra S A] :
SMulCommClass R S (FreeAlgebra A X) where
smul_comm r s x := smul_comm (algebraMap R A r) (algebraMap S A s) x
instance {S : Type*} [CommRing S] : Ring (FreeAlgebra S X) :=
Algebra.semiringToRing S
-- verify there is no diamond but we will need
-- `reducible_and_instances` which currently fails #10906
variable (S : Type) [CommRing S] in
example : (algebraInt _ : Algebra ℤ (FreeAlgebra S X)) = instAlgebra _ _ := rfl
variable {X}
/-- The canonical function `X → FreeAlgebra R X`.
-/
irreducible_def ι : X → FreeAlgebra R X := fun m ↦ Quot.mk _ m
#align free_algebra.ι FreeAlgebra.ι
@[simp]
theorem quot_mk_eq_ι (m : X) : Quot.mk (FreeAlgebra.Rel R X) m = ι R m := by rw [ι_def]
#align free_algebra.quot_mk_eq_ι FreeAlgebra.quot_mk_eq_ι
variable {A : Type*} [Semiring A] [Algebra R A]
/-- Internal definition used to define `lift` -/
private def liftAux (f : X → A) : FreeAlgebra R X →ₐ[R] A where
toFun a :=
Quot.liftOn a (liftFun _ _ f) fun a b h ↦ by
induction' h
· exact (algebraMap R A).map_add _ _
· exact (algebraMap R A).map_mul _ _
· apply Algebra.commutes
· change _ + _ + _ = _ + (_ + _)
rw [add_assoc]
· change _ + _ = _ + _
rw [add_comm]
· change algebraMap _ _ _ + liftFun R X f _ = liftFun R X f _
simp
· change _ * _ * _ = _ * (_ * _)
rw [mul_assoc]
· change algebraMap _ _ _ * liftFun R X f _ = liftFun R X f _
simp
· change liftFun R X f _ * algebraMap _ _ _ = liftFun R X f _
simp
· change _ * (_ + _) = _ * _ + _ * _
rw [left_distrib]
· change (_ + _) * _ = _ * _ + _ * _
rw [right_distrib]
· change algebraMap _ _ _ * _ = algebraMap _ _ _
simp
· change _ * algebraMap _ _ _ = algebraMap _ _ _
simp
repeat
change liftFun R X f _ + liftFun R X f _ = _
simp only [*]
rfl
repeat
change liftFun R X f _ * liftFun R X f _ = _
simp only [*]
rfl
map_one' := by
change algebraMap _ _ _ = _
simp
map_mul' := by
rintro ⟨⟩ ⟨⟩
rfl
map_zero' := by
dsimp
change algebraMap _ _ _ = _
simp
map_add' := by
rintro ⟨⟩ ⟨⟩
rfl
commutes' := by tauto
-- Porting note: removed #align declaration since it is a private lemma
/-- Given a function `f : X → A` where `A` is an `R`-algebra, `lift R f` is the unique lift
of `f` to a morphism of `R`-algebras `FreeAlgebra R X → A`.
-/
@[irreducible]
def lift : (X → A) ≃ (FreeAlgebra R X →ₐ[R] A) :=
{ toFun := liftAux R
invFun := fun F ↦ F ∘ ι R
left_inv := fun f ↦ by
ext
simp only [Function.comp_apply, ι_def]
rfl
right_inv := fun F ↦ by
ext t
rcases t with ⟨x⟩
induction x with
| of =>
change ((F : FreeAlgebra R X → A) ∘ ι R) _ = _
simp only [Function.comp_apply, ι_def]
| ofScalar x =>
change algebraMap _ _ x = F (algebraMap _ _ x)
rw [AlgHom.commutes F _]
| add a b ha hb =>
-- Porting note: it is necessary to declare fa and fb explicitly otherwise Lean refuses
-- to consider `Quot.mk (Rel R X) ·` as element of FreeAlgebra R X
let fa : FreeAlgebra R X := Quot.mk (Rel R X) a
let fb : FreeAlgebra R X := Quot.mk (Rel R X) b
change liftAux R (F ∘ ι R) (fa + fb) = F (fa + fb)
rw [AlgHom.map_add, AlgHom.map_add, ha, hb]
| mul a b ha hb =>
let fa : FreeAlgebra R X := Quot.mk (Rel R X) a
let fb : FreeAlgebra R X := Quot.mk (Rel R X) b
change liftAux R (F ∘ ι R) (fa * fb) = F (fa * fb)
rw [AlgHom.map_mul, AlgHom.map_mul, ha, hb] }
#align free_algebra.lift FreeAlgebra.lift
@[simp]
theorem liftAux_eq (f : X → A) : liftAux R f = lift R f := by
rw [lift]
rfl
#align free_algebra.lift_aux_eq FreeAlgebra.liftAux_eq
@[simp]
theorem lift_symm_apply (F : FreeAlgebra R X →ₐ[R] A) : (lift R).symm F = F ∘ ι R := by
rw [lift]
rfl
#align free_algebra.lift_symm_apply FreeAlgebra.lift_symm_apply
variable {R}
@[simp]
theorem ι_comp_lift (f : X → A) : (lift R f : FreeAlgebra R X → A) ∘ ι R = f := by
ext
rw [Function.comp_apply, ι_def, lift]
rfl
#align free_algebra.ι_comp_lift FreeAlgebra.ι_comp_lift
@[simp]
| Mathlib/Algebra/FreeAlgebra.lean | 417 | 419 | theorem lift_ι_apply (f : X → A) (x) : lift R f (ι R x) = f x := by |
rw [ι_def, lift]
rfl
|
/-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, E. W. Ayers
-/
import Mathlib.CategoryTheory.Comma.Over
import Mathlib.CategoryTheory.Limits.Shapes.Pullbacks
import Mathlib.CategoryTheory.Yoneda
import Mathlib.Data.Set.Lattice
import Mathlib.Order.CompleteLattice
#align_import category_theory.sites.sieves from "leanprover-community/mathlib"@"239d882c4fb58361ee8b3b39fb2091320edef10a"
/-!
# Theory of sieves
- For an object `X` of a category `C`, a `Sieve X` is a set of morphisms to `X`
which is closed under left-composition.
- The complete lattice structure on sieves is given, as well as the Galois insertion
given by downward-closing.
- A `Sieve X` (functorially) induces a presheaf on `C` together with a monomorphism to
the yoneda embedding of `X`.
## Tags
sieve, pullback
-/
universe v₁ v₂ v₃ u₁ u₂ u₃
namespace CategoryTheory
open Category Limits
variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] (F : C ⥤ D)
variable {X Y Z : C} (f : Y ⟶ X)
/-- A set of arrows all with codomain `X`. -/
def Presieve (X : C) :=
∀ ⦃Y⦄, Set (Y ⟶ X)-- deriving CompleteLattice
#align category_theory.presieve CategoryTheory.Presieve
instance : CompleteLattice (Presieve X) := by
dsimp [Presieve]
infer_instance
namespace Presieve
noncomputable instance : Inhabited (Presieve X) :=
⟨⊤⟩
/-- The full subcategory of the over category `C/X` consisting of arrows which belong to a
presieve on `X`. -/
abbrev category {X : C} (P : Presieve X) :=
FullSubcategory fun f : Over X => P f.hom
/-- Construct an object of `P.category`. -/
abbrev categoryMk {X : C} (P : Presieve X) {Y : C} (f : Y ⟶ X) (hf : P f) : P.category :=
⟨Over.mk f, hf⟩
/-- Given a sieve `S` on `X : C`, its associated diagram `S.diagram` is defined to be
the natural functor from the full subcategory of the over category `C/X` consisting
of arrows in `S` to `C`. -/
abbrev diagram (S : Presieve X) : S.category ⥤ C :=
fullSubcategoryInclusion _ ⋙ Over.forget X
#align category_theory.presieve.diagram CategoryTheory.Presieve.diagram
/-- Given a sieve `S` on `X : C`, its associated cocone `S.cocone` is defined to be
the natural cocone over the diagram defined above with cocone point `X`. -/
abbrev cocone (S : Presieve X) : Cocone S.diagram :=
(Over.forgetCocone X).whisker (fullSubcategoryInclusion _)
#align category_theory.presieve.cocone CategoryTheory.Presieve.cocone
/-- Given a set of arrows `S` all with codomain `X`, and a set of arrows with codomain `Y` for each
`f : Y ⟶ X` in `S`, produce a set of arrows with codomain `X`:
`{ g ≫ f | (f : Y ⟶ X) ∈ S, (g : Z ⟶ Y) ∈ R f }`.
-/
def bind (S : Presieve X) (R : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → Presieve Y) : Presieve X := fun Z h =>
∃ (Y : C) (g : Z ⟶ Y) (f : Y ⟶ X) (H : S f), R H g ∧ g ≫ f = h
#align category_theory.presieve.bind CategoryTheory.Presieve.bind
@[simp]
theorem bind_comp {S : Presieve X} {R : ∀ ⦃Y : C⦄ ⦃f : Y ⟶ X⦄, S f → Presieve Y} {g : Z ⟶ Y}
(h₁ : S f) (h₂ : R h₁ g) : bind S R (g ≫ f) :=
⟨_, _, _, h₁, h₂, rfl⟩
#align category_theory.presieve.bind_comp CategoryTheory.Presieve.bind_comp
-- Porting note: it seems the definition of `Presieve` must be unfolded in order to define
-- this inductive type, it was thus renamed `singleton'`
-- Note we can't make this into `HasSingleton` because of the out-param.
/-- The singleton presieve. -/
inductive singleton' : ⦃Y : C⦄ → (Y ⟶ X) → Prop
| mk : singleton' f
/-- The singleton presieve. -/
def singleton : Presieve X := singleton' f
lemma singleton.mk {f : Y ⟶ X} : singleton f f := singleton'.mk
#align category_theory.presieve.singleton CategoryTheory.Presieve.singleton
@[simp]
theorem singleton_eq_iff_domain (f g : Y ⟶ X) : singleton f g ↔ f = g := by
constructor
· rintro ⟨a, rfl⟩
rfl
· rintro rfl
apply singleton.mk
#align category_theory.presieve.singleton_eq_iff_domain CategoryTheory.Presieve.singleton_eq_iff_domain
theorem singleton_self : singleton f f :=
singleton.mk
#align category_theory.presieve.singleton_self CategoryTheory.Presieve.singleton_self
/-- Pullback a set of arrows with given codomain along a fixed map, by taking the pullback in the
category.
This is not the same as the arrow set of `Sieve.pullback`, but there is a relation between them
in `pullbackArrows_comm`.
-/
inductive pullbackArrows [HasPullbacks C] (R : Presieve X) : Presieve Y
| mk (Z : C) (h : Z ⟶ X) : R h → pullbackArrows _ (pullback.snd : pullback h f ⟶ Y)
#align category_theory.presieve.pullback_arrows CategoryTheory.Presieve.pullbackArrows
theorem pullback_singleton [HasPullbacks C] (g : Z ⟶ X) :
pullbackArrows f (singleton g) = singleton (pullback.snd : pullback g f ⟶ _) := by
funext W
ext h
constructor
· rintro ⟨W, _, _, _⟩
exact singleton.mk
· rintro ⟨_⟩
exact pullbackArrows.mk Z g singleton.mk
#align category_theory.presieve.pullback_singleton CategoryTheory.Presieve.pullback_singleton
/-- Construct the presieve given by the family of arrows indexed by `ι`. -/
inductive ofArrows {ι : Type*} (Y : ι → C) (f : ∀ i, Y i ⟶ X) : Presieve X
| mk (i : ι) : ofArrows _ _ (f i)
#align category_theory.presieve.of_arrows CategoryTheory.Presieve.ofArrows
theorem ofArrows_pUnit : (ofArrows _ fun _ : PUnit => f) = singleton f := by
funext Y
ext g
constructor
· rintro ⟨_⟩
apply singleton.mk
· rintro ⟨_⟩
exact ofArrows.mk PUnit.unit
#align category_theory.presieve.of_arrows_punit CategoryTheory.Presieve.ofArrows_pUnit
theorem ofArrows_pullback [HasPullbacks C] {ι : Type*} (Z : ι → C) (g : ∀ i : ι, Z i ⟶ X) :
(ofArrows (fun i => pullback (g i) f) fun i => pullback.snd) =
pullbackArrows f (ofArrows Z g) := by
funext T
ext h
constructor
· rintro ⟨hk⟩
exact pullbackArrows.mk _ _ (ofArrows.mk hk)
· rintro ⟨W, k, hk₁⟩
cases' hk₁ with i hi
apply ofArrows.mk
#align category_theory.presieve.of_arrows_pullback CategoryTheory.Presieve.ofArrows_pullback
theorem ofArrows_bind {ι : Type*} (Z : ι → C) (g : ∀ i : ι, Z i ⟶ X)
(j : ∀ ⦃Y⦄ (f : Y ⟶ X), ofArrows Z g f → Type*) (W : ∀ ⦃Y⦄ (f : Y ⟶ X) (H), j f H → C)
(k : ∀ ⦃Y⦄ (f : Y ⟶ X) (H i), W f H i ⟶ Y) :
((ofArrows Z g).bind fun Y f H => ofArrows (W f H) (k f H)) =
ofArrows (fun i : Σi, j _ (ofArrows.mk i) => W (g i.1) _ i.2) fun ij =>
k (g ij.1) _ ij.2 ≫ g ij.1 := by
funext Y
ext f
constructor
· rintro ⟨_, _, _, ⟨i⟩, ⟨i'⟩, rfl⟩
exact ofArrows.mk (Sigma.mk _ _)
· rintro ⟨i⟩
exact bind_comp _ (ofArrows.mk _) (ofArrows.mk _)
#align category_theory.presieve.of_arrows_bind CategoryTheory.Presieve.ofArrows_bind
theorem ofArrows_surj {ι : Type*} {Y : ι → C} (f : ∀ i, Y i ⟶ X) {Z : C} (g : Z ⟶ X)
(hg : ofArrows Y f g) : ∃ (i : ι) (h : Y i = Z),
g = eqToHom h.symm ≫ f i := by
cases' hg with i
exact ⟨i, rfl, by simp only [eqToHom_refl, id_comp]⟩
/-- Given a presieve on `F(X)`, we can define a presieve on `X` by taking the preimage via `F`. -/
def functorPullback (R : Presieve (F.obj X)) : Presieve X := fun _ f => R (F.map f)
#align category_theory.presieve.functor_pullback CategoryTheory.Presieve.functorPullback
@[simp]
theorem functorPullback_mem (R : Presieve (F.obj X)) {Y} (f : Y ⟶ X) :
R.functorPullback F f ↔ R (F.map f) :=
Iff.rfl
#align category_theory.presieve.functor_pullback_mem CategoryTheory.Presieve.functorPullback_mem
@[simp]
theorem functorPullback_id (R : Presieve X) : R.functorPullback (𝟭 _) = R :=
rfl
#align category_theory.presieve.functor_pullback_id CategoryTheory.Presieve.functorPullback_id
/-- Given a presieve `R` on `X`, the predicate `R.hasPullbacks` means that for all arrows `f` and
`g` in `R`, the pullback of `f` and `g` exists. -/
class hasPullbacks (R : Presieve X) : Prop where
/-- For all arrows `f` and `g` in `R`, the pullback of `f` and `g` exists. -/
has_pullbacks : ∀ {Y Z} {f : Y ⟶ X} (_ : R f) {g : Z ⟶ X} (_ : R g), HasPullback f g
instance (R : Presieve X) [HasPullbacks C] : R.hasPullbacks := ⟨fun _ _ ↦ inferInstance⟩
instance {α : Type v₂} {X : α → C} {B : C} (π : (a : α) → X a ⟶ B)
[(Presieve.ofArrows X π).hasPullbacks] (a b : α) : HasPullback (π a) (π b) :=
Presieve.hasPullbacks.has_pullbacks (Presieve.ofArrows.mk _) (Presieve.ofArrows.mk _)
section FunctorPushforward
variable {E : Type u₃} [Category.{v₃} E] (G : D ⥤ E)
/-- Given a presieve on `X`, we can define a presieve on `F(X)` (which is actually a sieve)
by taking the sieve generated by the image via `F`.
-/
def functorPushforward (S : Presieve X) : Presieve (F.obj X) := fun Y f =>
∃ (Z : C) (g : Z ⟶ X) (h : Y ⟶ F.obj Z), S g ∧ f = h ≫ F.map g
#align category_theory.presieve.functor_pushforward CategoryTheory.Presieve.functorPushforward
-- Porting note: removed @[nolint hasNonemptyInstance]
/-- An auxiliary definition in order to fix the choice of the preimages between various definitions.
-/
structure FunctorPushforwardStructure (S : Presieve X) {Y} (f : Y ⟶ F.obj X) where
/-- an object in the source category -/
preobj : C
/-- a map in the source category which has to be in the presieve -/
premap : preobj ⟶ X
/-- the morphism which appear in the factorisation -/
lift : Y ⟶ F.obj preobj
/-- the condition that `premap` is in the presieve -/
cover : S premap
/-- the factorisation of the morphism -/
fac : f = lift ≫ F.map premap
#align category_theory.presieve.functor_pushforward_structure CategoryTheory.Presieve.FunctorPushforwardStructure
/-- The fixed choice of a preimage. -/
noncomputable def getFunctorPushforwardStructure {F : C ⥤ D} {S : Presieve X} {Y : D}
{f : Y ⟶ F.obj X} (h : S.functorPushforward F f) : FunctorPushforwardStructure F S f := by
choose Z f' g h₁ h using h
exact ⟨Z, f', g, h₁, h⟩
#align category_theory.presieve.get_functor_pushforward_structure CategoryTheory.Presieve.getFunctorPushforwardStructure
theorem functorPushforward_comp (R : Presieve X) :
R.functorPushforward (F ⋙ G) = (R.functorPushforward F).functorPushforward G := by
funext x
ext f
constructor
· rintro ⟨X, f₁, g₁, h₁, rfl⟩
exact ⟨F.obj X, F.map f₁, g₁, ⟨X, f₁, 𝟙 _, h₁, by simp⟩, rfl⟩
· rintro ⟨X, f₁, g₁, ⟨X', f₂, g₂, h₁, rfl⟩, rfl⟩
exact ⟨X', f₂, g₁ ≫ G.map g₂, h₁, by simp⟩
#align category_theory.presieve.functor_pushforward_comp CategoryTheory.Presieve.functorPushforward_comp
theorem image_mem_functorPushforward (R : Presieve X) {f : Y ⟶ X} (h : R f) :
R.functorPushforward F (F.map f) :=
⟨Y, f, 𝟙 _, h, by simp⟩
#align category_theory.presieve.image_mem_functor_pushforward CategoryTheory.Presieve.image_mem_functorPushforward
end FunctorPushforward
end Presieve
/--
For an object `X` of a category `C`, a `Sieve X` is a set of morphisms to `X` which is closed under
left-composition.
-/
structure Sieve {C : Type u₁} [Category.{v₁} C] (X : C) where
/-- the underlying presieve -/
arrows : Presieve X
/-- stability by precomposition -/
downward_closed : ∀ {Y Z f} (_ : arrows f) (g : Z ⟶ Y), arrows (g ≫ f)
#align category_theory.sieve CategoryTheory.Sieve
namespace Sieve
instance : CoeFun (Sieve X) fun _ => Presieve X :=
⟨Sieve.arrows⟩
initialize_simps_projections Sieve (arrows → apply)
variable {S R : Sieve X}
attribute [simp] downward_closed
theorem arrows_ext : ∀ {R S : Sieve X}, R.arrows = S.arrows → R = S := by
rintro ⟨_, _⟩ ⟨_, _⟩ rfl
rfl
#align category_theory.sieve.arrows_ext CategoryTheory.Sieve.arrows_ext
@[ext]
protected theorem ext {R S : Sieve X} (h : ∀ ⦃Y⦄ (f : Y ⟶ X), R f ↔ S f) : R = S :=
arrows_ext <| funext fun _ => funext fun f => propext <| h f
#align category_theory.sieve.ext CategoryTheory.Sieve.ext
protected theorem ext_iff {R S : Sieve X} : R = S ↔ ∀ ⦃Y⦄ (f : Y ⟶ X), R f ↔ S f :=
⟨fun h _ _ => h ▸ Iff.rfl, Sieve.ext⟩
#align category_theory.sieve.ext_iff CategoryTheory.Sieve.ext_iff
open Lattice
/-- The supremum of a collection of sieves: the union of them all. -/
protected def sup (𝒮 : Set (Sieve X)) : Sieve X where
arrows Y := { f | ∃ S ∈ 𝒮, Sieve.arrows S f }
downward_closed {_ _ f} hf _ := by
obtain ⟨S, hS, hf⟩ := hf
exact ⟨S, hS, S.downward_closed hf _⟩
#align category_theory.sieve.Sup CategoryTheory.Sieve.sup
/-- The infimum of a collection of sieves: the intersection of them all. -/
protected def inf (𝒮 : Set (Sieve X)) : Sieve X where
arrows _ := { f | ∀ S ∈ 𝒮, Sieve.arrows S f }
downward_closed {_ _ _} hf g S H := S.downward_closed (hf S H) g
#align category_theory.sieve.Inf CategoryTheory.Sieve.inf
/-- The union of two sieves is a sieve. -/
protected def union (S R : Sieve X) : Sieve X where
arrows Y f := S f ∨ R f
downward_closed := by rintro _ _ _ (h | h) g <;> simp [h]
#align category_theory.sieve.union CategoryTheory.Sieve.union
/-- The intersection of two sieves is a sieve. -/
protected def inter (S R : Sieve X) : Sieve X where
arrows Y f := S f ∧ R f
downward_closed := by
rintro _ _ _ ⟨h₁, h₂⟩ g
simp [h₁, h₂]
#align category_theory.sieve.inter CategoryTheory.Sieve.inter
/-- Sieves on an object `X` form a complete lattice.
We generate this directly rather than using the galois insertion for nicer definitional properties.
-/
instance : CompleteLattice (Sieve X) where
le S R := ∀ ⦃Y⦄ (f : Y ⟶ X), S f → R f
le_refl S f q := id
le_trans S₁ S₂ S₃ S₁₂ S₂₃ Y f h := S₂₃ _ (S₁₂ _ h)
le_antisymm S R p q := Sieve.ext fun Y f => ⟨p _, q _⟩
top :=
{ arrows := fun _ => Set.univ
downward_closed := fun _ _ => ⟨⟩ }
bot :=
{ arrows := fun _ => ∅
downward_closed := False.elim }
sup := Sieve.union
inf := Sieve.inter
sSup := Sieve.sup
sInf := Sieve.inf
le_sSup 𝒮 S hS Y f hf := ⟨S, hS, hf⟩
sSup_le := fun s a ha Y f ⟨b, hb, hf⟩ => (ha b hb) _ hf
sInf_le _ _ hS _ _ h := h _ hS
le_sInf _ _ hS _ _ hf _ hR := hS _ hR _ hf
le_sup_left _ _ _ _ := Or.inl
le_sup_right _ _ _ _ := Or.inr
sup_le _ _ _ h₁ h₂ _ f := by--ℰ S hS Y f := by
rintro (hf | hf)
· exact h₁ _ hf
· exact h₂ _ hf
inf_le_left _ _ _ _ := And.left
inf_le_right _ _ _ _ := And.right
le_inf _ _ _ p q _ _ z := ⟨p _ z, q _ z⟩
le_top _ _ _ _ := trivial
bot_le _ _ _ := False.elim
/-- The maximal sieve always exists. -/
instance sieveInhabited : Inhabited (Sieve X) :=
⟨⊤⟩
#align category_theory.sieve.sieve_inhabited CategoryTheory.Sieve.sieveInhabited
@[simp]
theorem sInf_apply {Ss : Set (Sieve X)} {Y} (f : Y ⟶ X) :
sInf Ss f ↔ ∀ (S : Sieve X) (_ : S ∈ Ss), S f :=
Iff.rfl
#align category_theory.sieve.Inf_apply CategoryTheory.Sieve.sInf_apply
@[simp]
theorem sSup_apply {Ss : Set (Sieve X)} {Y} (f : Y ⟶ X) :
sSup Ss f ↔ ∃ (S : Sieve X) (_ : S ∈ Ss), S f := by
simp [sSup, Sieve.sup, setOf]
#align category_theory.sieve.Sup_apply CategoryTheory.Sieve.sSup_apply
@[simp]
theorem inter_apply {R S : Sieve X} {Y} (f : Y ⟶ X) : (R ⊓ S) f ↔ R f ∧ S f :=
Iff.rfl
#align category_theory.sieve.inter_apply CategoryTheory.Sieve.inter_apply
@[simp]
theorem union_apply {R S : Sieve X} {Y} (f : Y ⟶ X) : (R ⊔ S) f ↔ R f ∨ S f :=
Iff.rfl
#align category_theory.sieve.union_apply CategoryTheory.Sieve.union_apply
@[simp]
theorem top_apply (f : Y ⟶ X) : (⊤ : Sieve X) f :=
trivial
#align category_theory.sieve.top_apply CategoryTheory.Sieve.top_apply
/-- Generate the smallest sieve containing the given set of arrows. -/
@[simps]
def generate (R : Presieve X) : Sieve X where
arrows Z f := ∃ (Y : _) (h : Z ⟶ Y) (g : Y ⟶ X), R g ∧ h ≫ g = f
downward_closed := by
rintro Y Z _ ⟨W, g, f, hf, rfl⟩ h
exact ⟨_, h ≫ g, _, hf, by simp⟩
#align category_theory.sieve.generate CategoryTheory.Sieve.generate
/-- Given a presieve on `X`, and a sieve on each domain of an arrow in the presieve, we can bind to
produce a sieve on `X`.
-/
@[simps]
def bind (S : Presieve X) (R : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → Sieve Y) : Sieve X where
arrows := S.bind fun Y f h => R h
downward_closed := by
rintro Y Z f ⟨W, f, h, hh, hf, rfl⟩ g
exact ⟨_, g ≫ f, _, hh, by simp [hf]⟩
#align category_theory.sieve.bind CategoryTheory.Sieve.bind
open Order Lattice
theorem sets_iff_generate (R : Presieve X) (S : Sieve X) : generate R ≤ S ↔ R ≤ S :=
⟨fun H Y g hg => H _ ⟨_, 𝟙 _, _, hg, id_comp _⟩, fun ss Y f => by
rintro ⟨Z, f, g, hg, rfl⟩
exact S.downward_closed (ss Z hg) f⟩
#align category_theory.sieve.sets_iff_generate CategoryTheory.Sieve.sets_iff_generate
/-- Show that there is a galois insertion (generate, set_over). -/
def giGenerate : GaloisInsertion (generate : Presieve X → Sieve X) arrows where
gc := sets_iff_generate
choice 𝒢 _ := generate 𝒢
choice_eq _ _ := rfl
le_l_u _ _ _ hf := ⟨_, 𝟙 _, _, hf, id_comp _⟩
#align category_theory.sieve.gi_generate CategoryTheory.Sieve.giGenerate
theorem le_generate (R : Presieve X) : R ≤ generate R :=
giGenerate.gc.le_u_l R
#align category_theory.sieve.le_generate CategoryTheory.Sieve.le_generate
@[simp]
theorem generate_sieve (S : Sieve X) : generate S = S :=
giGenerate.l_u_eq S
#align category_theory.sieve.generate_sieve CategoryTheory.Sieve.generate_sieve
/-- If the identity arrow is in a sieve, the sieve is maximal. -/
theorem id_mem_iff_eq_top : S (𝟙 X) ↔ S = ⊤ :=
⟨fun h => top_unique fun Y f _ => by simpa using downward_closed _ h f, fun h => h.symm ▸ trivial⟩
#align category_theory.sieve.id_mem_iff_eq_top CategoryTheory.Sieve.id_mem_iff_eq_top
/-- If an arrow set contains a split epi, it generates the maximal sieve. -/
theorem generate_of_contains_isSplitEpi {R : Presieve X} (f : Y ⟶ X) [IsSplitEpi f] (hf : R f) :
generate R = ⊤ := by
rw [← id_mem_iff_eq_top]
exact ⟨_, section_ f, f, hf, by simp⟩
#align category_theory.sieve.generate_of_contains_is_split_epi CategoryTheory.Sieve.generate_of_contains_isSplitEpi
@[simp]
theorem generate_of_singleton_isSplitEpi (f : Y ⟶ X) [IsSplitEpi f] :
generate (Presieve.singleton f) = ⊤ :=
generate_of_contains_isSplitEpi f (Presieve.singleton_self _)
#align category_theory.sieve.generate_of_singleton_is_split_epi CategoryTheory.Sieve.generate_of_singleton_isSplitEpi
@[simp]
theorem generate_top : generate (⊤ : Presieve X) = ⊤ :=
generate_of_contains_isSplitEpi (𝟙 _) ⟨⟩
#align category_theory.sieve.generate_top CategoryTheory.Sieve.generate_top
/-- The sieve of `X` generated by family of morphisms `Y i ⟶ X`. -/
abbrev ofArrows {I : Type*} {X : C} (Y : I → C) (f : ∀ i, Y i ⟶ X) :
Sieve X :=
generate (Presieve.ofArrows Y f)
lemma ofArrows_mk {I : Type*} {X : C} (Y : I → C) (f : ∀ i, Y i ⟶ X) (i : I) :
ofArrows Y f (f i) :=
⟨_, 𝟙 _, _, ⟨i⟩, by simp⟩
lemma mem_ofArrows_iff {I : Type*} {X : C} (Y : I → C) (f : ∀ i, Y i ⟶ X)
{W : C} (g : W ⟶ X) :
ofArrows Y f g ↔ ∃ (i : I) (a : W ⟶ Y i), g = a ≫ f i := by
constructor
· rintro ⟨T, a, b, ⟨i⟩, rfl⟩
exact ⟨i, a, rfl⟩
· rintro ⟨i, a, rfl⟩
apply downward_closed _ (ofArrows_mk Y f i)
/-- The sieve of `X : C` that is generated by a family of objects `Y : I → C`:
it consists of morphisms to `X` which factor through at least one of the `Y i`. -/
def ofObjects {I : Type*} (Y : I → C) (X : C) : Sieve X where
arrows Z _ := ∃ (i : I), Nonempty (Z ⟶ Y i)
downward_closed := by
rintro Z₁ Z₂ p ⟨i, ⟨f⟩⟩ g
exact ⟨i, ⟨g ≫ f⟩⟩
lemma mem_ofObjects_iff {I : Type*} (Y : I → C) {Z X : C} (g : Z ⟶ X) :
ofObjects Y X g ↔ ∃ (i : I), Nonempty (Z ⟶ Y i) := by rfl
lemma ofArrows_le_ofObjects
{I : Type*} (Y : I → C) {X : C} (f : ∀ i, Y i ⟶ X) :
Sieve.ofArrows Y f ≤ Sieve.ofObjects Y X := by
intro W g hg
rw [mem_ofArrows_iff] at hg
obtain ⟨i, a, rfl⟩ := hg
exact ⟨i, ⟨a⟩⟩
lemma ofArrows_eq_ofObjects {X : C} (hX : IsTerminal X)
{I : Type*} (Y : I → C) (f : ∀ i, Y i ⟶ X) :
ofArrows Y f = ofObjects Y X := by
refine le_antisymm (ofArrows_le_ofObjects Y f) (fun W g => ?_)
rw [mem_ofArrows_iff, mem_ofObjects_iff]
rintro ⟨i, ⟨h⟩⟩
exact ⟨i, h, hX.hom_ext _ _⟩
/-- Given a morphism `h : Y ⟶ X`, send a sieve S on X to a sieve on Y
as the inverse image of S with `_ ≫ h`.
That is, `Sieve.pullback S h := (≫ h) '⁻¹ S`. -/
@[simps]
def pullback (h : Y ⟶ X) (S : Sieve X) : Sieve Y where
arrows Y sl := S (sl ≫ h)
downward_closed g := by simp [g]
#align category_theory.sieve.pullback CategoryTheory.Sieve.pullback
@[simp]
theorem pullback_id : S.pullback (𝟙 _) = S := by simp [Sieve.ext_iff]
#align category_theory.sieve.pullback_id CategoryTheory.Sieve.pullback_id
@[simp]
theorem pullback_top {f : Y ⟶ X} : (⊤ : Sieve X).pullback f = ⊤ :=
top_unique fun _ _ => id
#align category_theory.sieve.pullback_top CategoryTheory.Sieve.pullback_top
theorem pullback_comp {f : Y ⟶ X} {g : Z ⟶ Y} (S : Sieve X) :
S.pullback (g ≫ f) = (S.pullback f).pullback g := by simp [Sieve.ext_iff]
#align category_theory.sieve.pullback_comp CategoryTheory.Sieve.pullback_comp
@[simp]
theorem pullback_inter {f : Y ⟶ X} (S R : Sieve X) :
(S ⊓ R).pullback f = S.pullback f ⊓ R.pullback f := by simp [Sieve.ext_iff]
#align category_theory.sieve.pullback_inter CategoryTheory.Sieve.pullback_inter
theorem pullback_eq_top_iff_mem (f : Y ⟶ X) : S f ↔ S.pullback f = ⊤ := by
rw [← id_mem_iff_eq_top, pullback_apply, id_comp]
#align category_theory.sieve.pullback_eq_top_iff_mem CategoryTheory.Sieve.pullback_eq_top_iff_mem
theorem pullback_eq_top_of_mem (S : Sieve X) {f : Y ⟶ X} : S f → S.pullback f = ⊤ :=
(pullback_eq_top_iff_mem f).1
#align category_theory.sieve.pullback_eq_top_of_mem CategoryTheory.Sieve.pullback_eq_top_of_mem
lemma pullback_ofObjects_eq_top
{I : Type*} (Y : I → C) {X : C} {i : I} (g : X ⟶ Y i) :
ofObjects Y X = ⊤ := by
ext Z h
simp only [top_apply, iff_true]
rw [mem_ofObjects_iff ]
exact ⟨i, ⟨h ≫ g⟩⟩
/-- Push a sieve `R` on `Y` forward along an arrow `f : Y ⟶ X`: `gf : Z ⟶ X` is in the sieve if `gf`
factors through some `g : Z ⟶ Y` which is in `R`.
-/
@[simps]
def pushforward (f : Y ⟶ X) (R : Sieve Y) : Sieve X where
arrows Z gf := ∃ g, g ≫ f = gf ∧ R g
downward_closed := fun ⟨j, k, z⟩ h => ⟨h ≫ j, by simp [k], by simp [z]⟩
#align category_theory.sieve.pushforward CategoryTheory.Sieve.pushforward
theorem pushforward_apply_comp {R : Sieve Y} {Z : C} {g : Z ⟶ Y} (hg : R g) (f : Y ⟶ X) :
R.pushforward f (g ≫ f) :=
⟨g, rfl, hg⟩
#align category_theory.sieve.pushforward_apply_comp CategoryTheory.Sieve.pushforward_apply_comp
theorem pushforward_comp {f : Y ⟶ X} {g : Z ⟶ Y} (R : Sieve Z) :
R.pushforward (g ≫ f) = (R.pushforward g).pushforward f :=
Sieve.ext fun W h =>
⟨fun ⟨f₁, hq, hf₁⟩ => ⟨f₁ ≫ g, by simpa, f₁, rfl, hf₁⟩, fun ⟨y, hy, z, hR, hz⟩ =>
⟨z, by rw [← Category.assoc, hR]; tauto⟩⟩
#align category_theory.sieve.pushforward_comp CategoryTheory.Sieve.pushforward_comp
theorem galoisConnection (f : Y ⟶ X) : GaloisConnection (Sieve.pushforward f) (Sieve.pullback f) :=
fun _ _ => ⟨fun hR _ g hg => hR _ ⟨g, rfl, hg⟩, fun hS _ _ ⟨h, hg, hh⟩ => hg ▸ hS h hh⟩
#align category_theory.sieve.galois_connection CategoryTheory.Sieve.galoisConnection
theorem pullback_monotone (f : Y ⟶ X) : Monotone (Sieve.pullback f) :=
(galoisConnection f).monotone_u
#align category_theory.sieve.pullback_monotone CategoryTheory.Sieve.pullback_monotone
theorem pushforward_monotone (f : Y ⟶ X) : Monotone (Sieve.pushforward f) :=
(galoisConnection f).monotone_l
#align category_theory.sieve.pushforward_monotone CategoryTheory.Sieve.pushforward_monotone
theorem le_pushforward_pullback (f : Y ⟶ X) (R : Sieve Y) : R ≤ (R.pushforward f).pullback f :=
(galoisConnection f).le_u_l _
#align category_theory.sieve.le_pushforward_pullback CategoryTheory.Sieve.le_pushforward_pullback
theorem pullback_pushforward_le (f : Y ⟶ X) (R : Sieve X) : (R.pullback f).pushforward f ≤ R :=
(galoisConnection f).l_u_le _
#align category_theory.sieve.pullback_pushforward_le CategoryTheory.Sieve.pullback_pushforward_le
theorem pushforward_union {f : Y ⟶ X} (S R : Sieve Y) :
(S ⊔ R).pushforward f = S.pushforward f ⊔ R.pushforward f :=
(galoisConnection f).l_sup
#align category_theory.sieve.pushforward_union CategoryTheory.Sieve.pushforward_union
theorem pushforward_le_bind_of_mem (S : Presieve X) (R : ∀ ⦃Y : C⦄ ⦃f : Y ⟶ X⦄, S f → Sieve Y)
(f : Y ⟶ X) (h : S f) : (R h).pushforward f ≤ bind S R := by
rintro Z _ ⟨g, rfl, hg⟩
exact ⟨_, g, f, h, hg, rfl⟩
#align category_theory.sieve.pushforward_le_bind_of_mem CategoryTheory.Sieve.pushforward_le_bind_of_mem
theorem le_pullback_bind (S : Presieve X) (R : ∀ ⦃Y : C⦄ ⦃f : Y ⟶ X⦄, S f → Sieve Y) (f : Y ⟶ X)
(h : S f) : R h ≤ (bind S R).pullback f := by
rw [← galoisConnection f]
apply pushforward_le_bind_of_mem
#align category_theory.sieve.le_pullback_bind CategoryTheory.Sieve.le_pullback_bind
/-- If `f` is a monomorphism, the pushforward-pullback adjunction on sieves is coreflective. -/
def galoisCoinsertionOfMono (f : Y ⟶ X) [Mono f] :
GaloisCoinsertion (Sieve.pushforward f) (Sieve.pullback f) := by
apply (galoisConnection f).toGaloisCoinsertion
rintro S Z g ⟨g₁, hf, hg₁⟩
rw [cancel_mono f] at hf
rwa [← hf]
#align category_theory.sieve.galois_coinsertion_of_mono CategoryTheory.Sieve.galoisCoinsertionOfMono
/-- If `f` is a split epi, the pushforward-pullback adjunction on sieves is reflective. -/
def galoisInsertionOfIsSplitEpi (f : Y ⟶ X) [IsSplitEpi f] :
GaloisInsertion (Sieve.pushforward f) (Sieve.pullback f) := by
apply (galoisConnection f).toGaloisInsertion
intro S Z g hg
exact ⟨g ≫ section_ f, by simpa⟩
#align category_theory.sieve.galois_insertion_of_is_split_epi CategoryTheory.Sieve.galoisInsertionOfIsSplitEpi
theorem pullbackArrows_comm [HasPullbacks C] {X Y : C} (f : Y ⟶ X) (R : Presieve X) :
Sieve.generate (R.pullbackArrows f) = (Sieve.generate R).pullback f := by
ext W g
constructor
· rintro ⟨_, h, k, hk, rfl⟩
cases' hk with W g hg
change (Sieve.generate R).pullback f (h ≫ pullback.snd)
rw [Sieve.pullback_apply, assoc, ← pullback.condition, ← assoc]
exact Sieve.downward_closed _ (by exact Sieve.le_generate R W hg) (h ≫ pullback.fst)
· rintro ⟨W, h, k, hk, comm⟩
exact ⟨_, _, _, Presieve.pullbackArrows.mk _ _ hk, pullback.lift_snd _ _ comm⟩
#align category_theory.sieve.pullback_arrows_comm CategoryTheory.Sieve.pullbackArrows_comm
section Functor
variable {E : Type u₃} [Category.{v₃} E] (G : D ⥤ E)
/--
If `R` is a sieve, then the `CategoryTheory.Presieve.functorPullback` of `R` is actually a sieve.
-/
@[simps]
def functorPullback (R : Sieve (F.obj X)) : Sieve X where
arrows := Presieve.functorPullback F R
downward_closed := by
intro _ _ f hf g
unfold Presieve.functorPullback
rw [F.map_comp]
exact R.downward_closed hf (F.map g)
#align category_theory.sieve.functor_pullback CategoryTheory.Sieve.functorPullback
@[simp]
theorem functorPullback_arrows (R : Sieve (F.obj X)) :
(R.functorPullback F).arrows = R.arrows.functorPullback F :=
rfl
#align category_theory.sieve.functor_pullback_arrows CategoryTheory.Sieve.functorPullback_arrows
@[simp]
theorem functorPullback_id (R : Sieve X) : R.functorPullback (𝟭 _) = R := by
ext
rfl
#align category_theory.sieve.functor_pullback_id CategoryTheory.Sieve.functorPullback_id
theorem functorPullback_comp (R : Sieve ((F ⋙ G).obj X)) :
R.functorPullback (F ⋙ G) = (R.functorPullback G).functorPullback F := by
ext
rfl
#align category_theory.sieve.functor_pullback_comp CategoryTheory.Sieve.functorPullback_comp
theorem functorPushforward_extend_eq {R : Presieve X} :
(generate R).arrows.functorPushforward F = R.functorPushforward F := by
funext Y
ext f
constructor
· rintro ⟨X', g, f', ⟨X'', g', f'', h₁, rfl⟩, rfl⟩
exact ⟨X'', f'', f' ≫ F.map g', h₁, by simp⟩
· rintro ⟨X', g, f', h₁, h₂⟩
exact ⟨X', g, f', le_generate R _ h₁, h₂⟩
#align category_theory.sieve.functor_pushforward_extend_eq CategoryTheory.Sieve.functorPushforward_extend_eq
/-- The sieve generated by the image of `R` under `F`. -/
@[simps]
def functorPushforward (R : Sieve X) : Sieve (F.obj X) where
arrows := R.arrows.functorPushforward F
downward_closed := by
intro _ _ f h g
obtain ⟨X, α, β, hα, rfl⟩ := h
exact ⟨X, α, g ≫ β, hα, by simp⟩
#align category_theory.sieve.functor_pushforward CategoryTheory.Sieve.functorPushforward
@[simp]
theorem functorPushforward_id (R : Sieve X) : R.functorPushforward (𝟭 _) = R := by
ext X f
constructor
· intro hf
obtain ⟨X, g, h, hg, rfl⟩ := hf
exact R.downward_closed hg h
· intro hf
exact ⟨X, f, 𝟙 _, hf, by simp⟩
#align category_theory.sieve.functor_pushforward_id CategoryTheory.Sieve.functorPushforward_id
| Mathlib/CategoryTheory/Sites/Sieves.lean | 710 | 713 | theorem functorPushforward_comp (R : Sieve X) :
R.functorPushforward (F ⋙ G) = (R.functorPushforward F).functorPushforward G := by |
ext
simp [R.arrows.functorPushforward_comp F G]
|
/-
Copyright (c) 2020 Johan Commelin, Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Robert Y. Lewis
-/
import Mathlib.Algebra.MvPolynomial.Rename
import Mathlib.Algebra.MvPolynomial.Variables
#align_import data.mv_polynomial.monad from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4"
/-!
# Monad operations on `MvPolynomial`
This file defines two monadic operations on `MvPolynomial`. Given `p : MvPolynomial σ R`,
* `MvPolynomial.bind₁` and `MvPolynomial.join₁` operate on the variable type `σ`.
* `MvPolynomial.bind₂` and `MvPolynomial.join₂` operate on the coefficient type `R`.
- `MvPolynomial.bind₁ f φ` with `f : σ → MvPolynomial τ R` and `φ : MvPolynomial σ R`,
is the polynomial `φ(f 1, ..., f i, ...) : MvPolynomial τ R`.
- `MvPolynomial.join₁ φ` with `φ : MvPolynomial (MvPolynomial σ R) R` collapses `φ` to
a `MvPolynomial σ R`, by evaluating `φ` under the map `X f ↦ f` for `f : MvPolynomial σ R`.
In other words, if you have a polynomial `φ` in a set of variables indexed by a polynomial ring,
you evaluate the polynomial in these indexing polynomials.
- `MvPolynomial.bind₂ f φ` with `f : R →+* MvPolynomial σ S` and `φ : MvPolynomial σ R`
is the `MvPolynomial σ S` obtained from `φ` by mapping the coefficients of `φ` through `f`
and considering the resulting polynomial as polynomial expression in `MvPolynomial σ R`.
- `MvPolynomial.join₂ φ` with `φ : MvPolynomial σ (MvPolynomial σ R)` collapses `φ` to
a `MvPolynomial σ R`, by considering `φ` as polynomial expression in `MvPolynomial σ R`.
These operations themselves have algebraic structure: `MvPolynomial.bind₁`
and `MvPolynomial.join₁` are algebra homs and
`MvPolynomial.bind₂` and `MvPolynomial.join₂` are ring homs.
They interact in convenient ways with `MvPolynomial.rename`, `MvPolynomial.map`,
`MvPolynomial.vars`, and other polynomial operations.
Indeed, `MvPolynomial.rename` is the "map" operation for the (`bind₁`, `join₁`) pair,
whereas `MvPolynomial.map` is the "map" operation for the other pair.
## Implementation notes
We add a `LawfulMonad` instance for the (`bind₁`, `join₁`) pair.
The second pair cannot be instantiated as a `Monad`,
since it is not a monad in `Type` but in `CommRingCat` (or rather `CommSemiRingCat`).
-/
noncomputable section
namespace MvPolynomial
open Finsupp
variable {σ : Type*} {τ : Type*}
variable {R S T : Type*} [CommSemiring R] [CommSemiring S] [CommSemiring T]
/--
`bind₁` is the "left hand side" bind operation on `MvPolynomial`, operating on the variable type.
Given a polynomial `p : MvPolynomial σ R` and a map `f : σ → MvPolynomial τ R` taking variables
in `p` to polynomials in the variable type `τ`, `bind₁ f p` replaces each variable in `p` with
its value under `f`, producing a new polynomial in `τ`. The coefficient type remains the same.
This operation is an algebra hom.
-/
def bind₁ (f : σ → MvPolynomial τ R) : MvPolynomial σ R →ₐ[R] MvPolynomial τ R :=
aeval f
#align mv_polynomial.bind₁ MvPolynomial.bind₁
/-- `bind₂` is the "right hand side" bind operation on `MvPolynomial`,
operating on the coefficient type.
Given a polynomial `p : MvPolynomial σ R` and
a map `f : R → MvPolynomial σ S` taking coefficients in `p` to polynomials over a new ring `S`,
`bind₂ f p` replaces each coefficient in `p` with its value under `f`,
producing a new polynomial over `S`.
The variable type remains the same. This operation is a ring hom.
-/
def bind₂ (f : R →+* MvPolynomial σ S) : MvPolynomial σ R →+* MvPolynomial σ S :=
eval₂Hom f X
#align mv_polynomial.bind₂ MvPolynomial.bind₂
/--
`join₁` is the monadic join operation corresponding to `MvPolynomial.bind₁`. Given a polynomial `p`
with coefficients in `R` whose variables are polynomials in `σ` with coefficients in `R`,
`join₁ p` collapses `p` to a polynomial with variables in `σ` and coefficients in `R`.
This operation is an algebra hom.
-/
def join₁ : MvPolynomial (MvPolynomial σ R) R →ₐ[R] MvPolynomial σ R :=
aeval id
#align mv_polynomial.join₁ MvPolynomial.join₁
/--
`join₂` is the monadic join operation corresponding to `MvPolynomial.bind₂`. Given a polynomial `p`
with variables in `σ` whose coefficients are polynomials in `σ` with coefficients in `R`,
`join₂ p` collapses `p` to a polynomial with variables in `σ` and coefficients in `R`.
This operation is a ring hom.
-/
def join₂ : MvPolynomial σ (MvPolynomial σ R) →+* MvPolynomial σ R :=
eval₂Hom (RingHom.id _) X
#align mv_polynomial.join₂ MvPolynomial.join₂
@[simp]
theorem aeval_eq_bind₁ (f : σ → MvPolynomial τ R) : aeval f = bind₁ f :=
rfl
#align mv_polynomial.aeval_eq_bind₁ MvPolynomial.aeval_eq_bind₁
@[simp]
theorem eval₂Hom_C_eq_bind₁ (f : σ → MvPolynomial τ R) : eval₂Hom C f = bind₁ f :=
rfl
set_option linter.uppercaseLean3 false in
#align mv_polynomial.eval₂_hom_C_eq_bind₁ MvPolynomial.eval₂Hom_C_eq_bind₁
@[simp]
theorem eval₂Hom_eq_bind₂ (f : R →+* MvPolynomial σ S) : eval₂Hom f X = bind₂ f :=
rfl
#align mv_polynomial.eval₂_hom_eq_bind₂ MvPolynomial.eval₂Hom_eq_bind₂
section
variable (σ R)
@[simp]
theorem aeval_id_eq_join₁ : aeval id = @join₁ σ R _ :=
rfl
#align mv_polynomial.aeval_id_eq_join₁ MvPolynomial.aeval_id_eq_join₁
theorem eval₂Hom_C_id_eq_join₁ (φ : MvPolynomial (MvPolynomial σ R) R) :
eval₂Hom C id φ = join₁ φ :=
rfl
set_option linter.uppercaseLean3 false in
#align mv_polynomial.eval₂_hom_C_id_eq_join₁ MvPolynomial.eval₂Hom_C_id_eq_join₁
@[simp]
theorem eval₂Hom_id_X_eq_join₂ : eval₂Hom (RingHom.id _) X = @join₂ σ R _ :=
rfl
set_option linter.uppercaseLean3 false in
#align mv_polynomial.eval₂_hom_id_X_eq_join₂ MvPolynomial.eval₂Hom_id_X_eq_join₂
end
-- In this file, we don't want to use these simp lemmas,
-- because we first need to show how these new definitions interact
-- and the proofs fall back on unfolding the definitions and call simp afterwards
attribute [-simp]
aeval_eq_bind₁ eval₂Hom_C_eq_bind₁ eval₂Hom_eq_bind₂ aeval_id_eq_join₁ eval₂Hom_id_X_eq_join₂
@[simp]
theorem bind₁_X_right (f : σ → MvPolynomial τ R) (i : σ) : bind₁ f (X i) = f i :=
aeval_X f i
set_option linter.uppercaseLean3 false in
#align mv_polynomial.bind₁_X_right MvPolynomial.bind₁_X_right
@[simp]
theorem bind₂_X_right (f : R →+* MvPolynomial σ S) (i : σ) : bind₂ f (X i) = X i :=
eval₂Hom_X' f X i
set_option linter.uppercaseLean3 false in
#align mv_polynomial.bind₂_X_right MvPolynomial.bind₂_X_right
@[simp]
theorem bind₁_X_left : bind₁ (X : σ → MvPolynomial σ R) = AlgHom.id R _ := by
ext1 i
simp
set_option linter.uppercaseLean3 false in
#align mv_polynomial.bind₁_X_left MvPolynomial.bind₁_X_left
variable (f : σ → MvPolynomial τ R)
theorem bind₁_C_right (f : σ → MvPolynomial τ R) (x) : bind₁ f (C x) = C x := algHom_C _ _
set_option linter.uppercaseLean3 false in
#align mv_polynomial.bind₁_C_right MvPolynomial.bind₁_C_right
@[simp]
theorem bind₂_C_right (f : R →+* MvPolynomial σ S) (r : R) : bind₂ f (C r) = f r :=
eval₂Hom_C f X r
set_option linter.uppercaseLean3 false in
#align mv_polynomial.bind₂_C_right MvPolynomial.bind₂_C_right
@[simp]
theorem bind₂_C_left : bind₂ (C : R →+* MvPolynomial σ R) = RingHom.id _ := by ext : 2 <;> simp
set_option linter.uppercaseLean3 false in
#align mv_polynomial.bind₂_C_left MvPolynomial.bind₂_C_left
@[simp]
theorem bind₂_comp_C (f : R →+* MvPolynomial σ S) : (bind₂ f).comp C = f :=
RingHom.ext <| bind₂_C_right _
set_option linter.uppercaseLean3 false in
#align mv_polynomial.bind₂_comp_C MvPolynomial.bind₂_comp_C
@[simp]
theorem join₂_map (f : R →+* MvPolynomial σ S) (φ : MvPolynomial σ R) :
join₂ (map f φ) = bind₂ f φ := by simp only [join₂, bind₂, eval₂Hom_map_hom, RingHom.id_comp]
#align mv_polynomial.join₂_map MvPolynomial.join₂_map
@[simp]
theorem join₂_comp_map (f : R →+* MvPolynomial σ S) : join₂.comp (map f) = bind₂ f :=
RingHom.ext <| join₂_map _
#align mv_polynomial.join₂_comp_map MvPolynomial.join₂_comp_map
theorem aeval_id_rename (f : σ → MvPolynomial τ R) (p : MvPolynomial σ R) :
aeval id (rename f p) = aeval f p := by rw [aeval_rename, Function.id_comp]
#align mv_polynomial.aeval_id_rename MvPolynomial.aeval_id_rename
@[simp]
theorem join₁_rename (f : σ → MvPolynomial τ R) (φ : MvPolynomial σ R) :
join₁ (rename f φ) = bind₁ f φ :=
aeval_id_rename _ _
#align mv_polynomial.join₁_rename MvPolynomial.join₁_rename
@[simp]
theorem bind₁_id : bind₁ (@id (MvPolynomial σ R)) = join₁ :=
rfl
#align mv_polynomial.bind₁_id MvPolynomial.bind₁_id
@[simp]
theorem bind₂_id : bind₂ (RingHom.id (MvPolynomial σ R)) = join₂ :=
rfl
#align mv_polynomial.bind₂_id MvPolynomial.bind₂_id
theorem bind₁_bind₁ {υ : Type*} (f : σ → MvPolynomial τ R) (g : τ → MvPolynomial υ R)
(φ : MvPolynomial σ R) : (bind₁ g) (bind₁ f φ) = bind₁ (fun i => bind₁ g (f i)) φ := by
simp [bind₁, ← comp_aeval]
#align mv_polynomial.bind₁_bind₁ MvPolynomial.bind₁_bind₁
theorem bind₁_comp_bind₁ {υ : Type*} (f : σ → MvPolynomial τ R) (g : τ → MvPolynomial υ R) :
(bind₁ g).comp (bind₁ f) = bind₁ fun i => bind₁ g (f i) := by
ext1
apply bind₁_bind₁
#align mv_polynomial.bind₁_comp_bind₁ MvPolynomial.bind₁_comp_bind₁
theorem bind₂_comp_bind₂ (f : R →+* MvPolynomial σ S) (g : S →+* MvPolynomial σ T) :
(bind₂ g).comp (bind₂ f) = bind₂ ((bind₂ g).comp f) := by ext : 2 <;> simp
#align mv_polynomial.bind₂_comp_bind₂ MvPolynomial.bind₂_comp_bind₂
theorem bind₂_bind₂ (f : R →+* MvPolynomial σ S) (g : S →+* MvPolynomial σ T)
(φ : MvPolynomial σ R) : (bind₂ g) (bind₂ f φ) = bind₂ ((bind₂ g).comp f) φ :=
RingHom.congr_fun (bind₂_comp_bind₂ f g) φ
#align mv_polynomial.bind₂_bind₂ MvPolynomial.bind₂_bind₂
theorem rename_comp_bind₁ {υ : Type*} (f : σ → MvPolynomial τ R) (g : τ → υ) :
(rename g).comp (bind₁ f) = bind₁ fun i => rename g <| f i := by
ext1 i
simp
#align mv_polynomial.rename_comp_bind₁ MvPolynomial.rename_comp_bind₁
theorem rename_bind₁ {υ : Type*} (f : σ → MvPolynomial τ R) (g : τ → υ) (φ : MvPolynomial σ R) :
rename g (bind₁ f φ) = bind₁ (fun i => rename g <| f i) φ :=
AlgHom.congr_fun (rename_comp_bind₁ f g) φ
#align mv_polynomial.rename_bind₁ MvPolynomial.rename_bind₁
theorem map_bind₂ (f : R →+* MvPolynomial σ S) (g : S →+* T) (φ : MvPolynomial σ R) :
map g (bind₂ f φ) = bind₂ ((map g).comp f) φ := by
simp only [bind₂, eval₂_comp_right, coe_eval₂Hom, eval₂_map]
congr 1 with : 1
simp only [Function.comp_apply, map_X]
#align mv_polynomial.map_bind₂ MvPolynomial.map_bind₂
theorem bind₁_comp_rename {υ : Type*} (f : τ → MvPolynomial υ R) (g : σ → τ) :
(bind₁ f).comp (rename g) = bind₁ (f ∘ g) := by
ext1 i
simp
#align mv_polynomial.bind₁_comp_rename MvPolynomial.bind₁_comp_rename
theorem bind₁_rename {υ : Type*} (f : τ → MvPolynomial υ R) (g : σ → τ) (φ : MvPolynomial σ R) :
bind₁ f (rename g φ) = bind₁ (f ∘ g) φ :=
AlgHom.congr_fun (bind₁_comp_rename f g) φ
#align mv_polynomial.bind₁_rename MvPolynomial.bind₁_rename
theorem bind₂_map (f : S →+* MvPolynomial σ T) (g : R →+* S) (φ : MvPolynomial σ R) :
bind₂ f (map g φ) = bind₂ (f.comp g) φ := by simp [bind₂]
#align mv_polynomial.bind₂_map MvPolynomial.bind₂_map
@[simp]
theorem map_comp_C (f : R →+* S) : (map f).comp (C : R →+* MvPolynomial σ R) = C.comp f := by
ext1
apply map_C
set_option linter.uppercaseLean3 false in
#align mv_polynomial.map_comp_C MvPolynomial.map_comp_C
-- mixing the two monad structures
theorem hom_bind₁ (f : MvPolynomial τ R →+* S) (g : σ → MvPolynomial τ R) (φ : MvPolynomial σ R) :
f (bind₁ g φ) = eval₂Hom (f.comp C) (fun i => f (g i)) φ := by
rw [bind₁, map_aeval, algebraMap_eq]
#align mv_polynomial.hom_bind₁ MvPolynomial.hom_bind₁
theorem map_bind₁ (f : R →+* S) (g : σ → MvPolynomial τ R) (φ : MvPolynomial σ R) :
map f (bind₁ g φ) = bind₁ (fun i : σ => (map f) (g i)) (map f φ) := by
rw [hom_bind₁, map_comp_C, ← eval₂Hom_map_hom]
rfl
#align mv_polynomial.map_bind₁ MvPolynomial.map_bind₁
@[simp]
theorem eval₂Hom_comp_C (f : R →+* S) (g : σ → S) : (eval₂Hom f g).comp C = f := by
ext1 r
exact eval₂_C f g r
set_option linter.uppercaseLean3 false in
#align mv_polynomial.eval₂_hom_comp_C MvPolynomial.eval₂Hom_comp_C
theorem eval₂Hom_bind₁ (f : R →+* S) (g : τ → S) (h : σ → MvPolynomial τ R) (φ : MvPolynomial σ R) :
eval₂Hom f g (bind₁ h φ) = eval₂Hom f (fun i => eval₂Hom f g (h i)) φ := by
rw [hom_bind₁, eval₂Hom_comp_C]
#align mv_polynomial.eval₂_hom_bind₁ MvPolynomial.eval₂Hom_bind₁
theorem aeval_bind₁ [Algebra R S] (f : τ → S) (g : σ → MvPolynomial τ R) (φ : MvPolynomial σ R) :
aeval f (bind₁ g φ) = aeval (fun i => aeval f (g i)) φ :=
eval₂Hom_bind₁ _ _ _ _
#align mv_polynomial.aeval_bind₁ MvPolynomial.aeval_bind₁
theorem aeval_comp_bind₁ [Algebra R S] (f : τ → S) (g : σ → MvPolynomial τ R) :
(aeval f).comp (bind₁ g) = aeval fun i => aeval f (g i) := by
ext1
apply aeval_bind₁
#align mv_polynomial.aeval_comp_bind₁ MvPolynomial.aeval_comp_bind₁
| Mathlib/Algebra/MvPolynomial/Monad.lean | 314 | 315 | theorem eval₂Hom_comp_bind₂ (f : S →+* T) (g : σ → T) (h : R →+* MvPolynomial σ S) :
(eval₂Hom f g).comp (bind₂ h) = eval₂Hom ((eval₂Hom f g).comp h) g := by | ext : 2 <;> simp
|
/-
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.Data.Matrix.Basic
import Mathlib.Data.PEquiv
#align_import data.matrix.pequiv from "leanprover-community/mathlib"@"3e068ece210655b7b9a9477c3aff38a492400aa1"
/-!
# partial equivalences for matrices
Using partial equivalences to represent matrices.
This file introduces the function `PEquiv.toMatrix`, which returns a matrix containing ones and
zeros. For any partial equivalence `f`, `f.toMatrix i j = 1 ↔ f i = some j`.
The following important properties of this function are proved
`toMatrix_trans : (f.trans g).toMatrix = f.toMatrix * g.toMatrix`
`toMatrix_symm : f.symm.toMatrix = f.toMatrixᵀ`
`toMatrix_refl : (PEquiv.refl n).toMatrix = 1`
`toMatrix_bot : ⊥.toMatrix = 0`
This theory gives the matrix representation of projection linear maps, and their right inverses.
For example, the matrix `(single (0 : Fin 1) (i : Fin n)).toMatrix` corresponds to the ith
projection map from R^n to R.
Any injective function `Fin m → Fin n` gives rise to a `PEquiv`, whose matrix is the projection
map from R^m → R^n represented by the same function. The transpose of this matrix is the right
inverse of this map, sending anything not in the image to zero.
## notations
This file uses `ᵀ` for `Matrix.transpose`.
-/
namespace PEquiv
open Matrix
universe u v
variable {k l m n : Type*}
variable {α : Type v}
open Matrix
/-- `toMatrix` returns a matrix containing ones and zeros. `f.toMatrix i j` is `1` if
`f i = some j` and `0` otherwise -/
def toMatrix [DecidableEq n] [Zero α] [One α] (f : m ≃. n) : Matrix m n α :=
of fun i j => if j ∈ f i then (1 : α) else 0
#align pequiv.to_matrix PEquiv.toMatrix
-- TODO: set as an equation lemma for `toMatrix`, see mathlib4#3024
@[simp]
theorem toMatrix_apply [DecidableEq n] [Zero α] [One α] (f : m ≃. n) (i j) :
toMatrix f i j = if j ∈ f i then (1 : α) else 0 :=
rfl
#align pequiv.to_matrix_apply PEquiv.toMatrix_apply
theorem mul_matrix_apply [Fintype m] [DecidableEq m] [Semiring α] (f : l ≃. m) (M : Matrix m n α)
(i j) : (f.toMatrix * M :) i j = Option.casesOn (f i) 0 fun fi => M fi j := by
dsimp [toMatrix, Matrix.mul_apply]
cases' h : f i with fi
· simp [h]
· rw [Finset.sum_eq_single fi] <;> simp (config := { contextual := true }) [h, eq_comm]
#align pequiv.mul_matrix_apply PEquiv.mul_matrix_apply
theorem toMatrix_symm [DecidableEq m] [DecidableEq n] [Zero α] [One α] (f : m ≃. n) :
(f.symm.toMatrix : Matrix n m α) = f.toMatrixᵀ := by
ext
simp only [transpose, mem_iff_mem f, toMatrix_apply]
congr
#align pequiv.to_matrix_symm PEquiv.toMatrix_symm
@[simp]
theorem toMatrix_refl [DecidableEq n] [Zero α] [One α] :
((PEquiv.refl n).toMatrix : Matrix n n α) = 1 := by
ext
simp [toMatrix_apply, one_apply]
#align pequiv.to_matrix_refl PEquiv.toMatrix_refl
theorem matrix_mul_apply [Fintype m] [Semiring α] [DecidableEq n] (M : Matrix l m α) (f : m ≃. n)
(i j) : (M * f.toMatrix :) i j = Option.casesOn (f.symm j) 0 fun fj => M i fj := by
dsimp [toMatrix, Matrix.mul_apply]
cases' h : f.symm j with fj
· simp [h, ← f.eq_some_iff]
· rw [Finset.sum_eq_single fj]
· simp [h, ← f.eq_some_iff]
· rintro b - n
simp [h, ← f.eq_some_iff, n.symm]
· simp
#align pequiv.matrix_mul_apply PEquiv.matrix_mul_apply
| Mathlib/Data/Matrix/PEquiv.lean | 96 | 99 | theorem toPEquiv_mul_matrix [Fintype m] [DecidableEq m] [Semiring α] (f : m ≃ m)
(M : Matrix m n α) : f.toPEquiv.toMatrix * M = M.submatrix f id := by |
ext i j
rw [mul_matrix_apply, Equiv.toPEquiv_apply, submatrix_apply, id]
|
/-
Copyright (c) 2024 Mitchell Lee. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mitchell Lee
-/
import Mathlib.Data.ZMod.Basic
import Mathlib.GroupTheory.Coxeter.Basic
/-!
# The length function, reduced words, and descents
Throughout this file, `B` is a type and `M : CoxeterMatrix B` is a Coxeter matrix.
`cs : CoxeterSystem M W` is a Coxeter system; that is, `W` is a group, and `cs` holds the data
of a group isomorphism `W ≃* M.group`, where `M.group` refers to the quotient of the free group on
`B` by the Coxeter relations given by the matrix `M`. See `Mathlib/GroupTheory/Coxeter/Basic.lean`
for more details.
Given any element $w \in W$, its *length* (`CoxeterSystem.length`), denoted $\ell(w)$, is the
minimum number $\ell$ such that $w$ can be written as a product of a sequence of $\ell$ simple
reflections:
$$w = s_{i_1} \cdots s_{i_\ell}.$$
We prove for all $w_1, w_2 \in W$ that $\ell (w_1 w_2) \leq \ell (w_1) + \ell (w_2)$
and that $\ell (w_1 w_2)$ has the same parity as $\ell (w_1) + \ell (w_2)$.
We define a *reduced word* (`CoxeterSystem.IsReduced`) for an element $w \in W$ to be a way of
writing $w$ as a product of exactly $\ell(w)$ simple reflections. Every element of $W$ has a reduced
word.
We say that $i \in B$ is a *left descent* (`CoxeterSystem.IsLeftDescent`) of $w \in W$ if
$\ell(s_i w) < \ell(w)$. We show that if $i$ is a left descent of $w$, then
$\ell(s_i w) + 1 = \ell(w)$. On the other hand, if $i$ is not a left descent of $w$, then
$\ell(s_i w) = \ell(w) + 1$. We similarly define right descents (`CoxeterSystem.IsRightDescent`) and
prove analogous results.
## Main definitions
* `cs.length`
* `cs.IsReduced`
* `cs.IsLeftDescent`
* `cs.IsRightDescent`
## References
* [A. Björner and F. Brenti, *Combinatorics of Coxeter Groups*](bjorner2005)
-/
namespace CoxeterSystem
open List Matrix Function Classical
variable {B : Type*}
variable {W : Type*} [Group W]
variable {M : CoxeterMatrix B} (cs : CoxeterSystem M W)
local prefix:100 "s" => cs.simple
local prefix:100 "π" => cs.wordProd
/-! ### Length -/
private theorem exists_word_with_prod (w : W) : ∃ n ω, ω.length = n ∧ π ω = w := by
rcases cs.wordProd_surjective w with ⟨ω, rfl⟩
use ω.length, ω
/-- The length of `w`; i.e., the minimum number of simple reflections that
must be multiplied to form `w`. -/
noncomputable def length (w : W) : ℕ := Nat.find (cs.exists_word_with_prod w)
local prefix:100 "ℓ" => cs.length
theorem exists_reduced_word (w : W) : ∃ ω, ω.length = ℓ w ∧ w = π ω := by
have := Nat.find_spec (cs.exists_word_with_prod w)
tauto
theorem length_wordProd_le (ω : List B) : ℓ (π ω) ≤ ω.length :=
Nat.find_min' (cs.exists_word_with_prod (π ω)) ⟨ω, by tauto⟩
@[simp] theorem length_one : ℓ (1 : W) = 0 := Nat.eq_zero_of_le_zero (cs.length_wordProd_le [])
@[simp]
theorem length_eq_zero_iff {w : W} : ℓ w = 0 ↔ w = 1 := by
constructor
· intro h
rcases cs.exists_reduced_word w with ⟨ω, hω, rfl⟩
have : ω = [] := eq_nil_of_length_eq_zero (hω.trans h)
rw [this, wordProd_nil]
· rintro rfl
exact cs.length_one
@[simp]
| Mathlib/GroupTheory/Coxeter/Length.lean | 91 | 98 | theorem length_inv (w : W) : ℓ (w⁻¹) = ℓ w := by |
apply Nat.le_antisymm
· rcases cs.exists_reduced_word w with ⟨ω, hω, rfl⟩
have := cs.length_wordProd_le (List.reverse ω)
rwa [wordProd_reverse, length_reverse, hω] at this
· rcases cs.exists_reduced_word w⁻¹ with ⟨ω, hω, h'ω⟩
have := cs.length_wordProd_le (List.reverse ω)
rwa [wordProd_reverse, length_reverse, ← h'ω, hω, inv_inv] at this
|
/-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne
-/
import Mathlib.MeasureTheory.Integral.SetToL1
#align_import measure_theory.integral.bochner from "leanprover-community/mathlib"@"48fb5b5280e7c81672afc9524185ae994553ebf4"
/-!
# Bochner integral
The Bochner integral extends the definition of the Lebesgue integral to functions that map from a
measure space into a Banach space (complete normed vector space). It is constructed here by
extending the integral on simple functions.
## Main definitions
The Bochner integral is defined through the extension process described in the file `SetToL1`,
which follows these steps:
1. Define the integral of the indicator of a set. This is `weightedSMul μ s x = (μ s).toReal * x`.
`weightedSMul μ` is shown to be linear in the value `x` and `DominatedFinMeasAdditive`
(defined in the file `SetToL1`) with respect to the set `s`.
2. Define the integral on simple functions of the type `SimpleFunc α E` (notation : `α →ₛ E`)
where `E` is a real normed space. (See `SimpleFunc.integral` for details.)
3. Transfer this definition to define the integral on `L1.simpleFunc α E` (notation :
`α →₁ₛ[μ] E`), see `L1.simpleFunc.integral`. Show that this integral is a continuous linear
map from `α →₁ₛ[μ] E` to `E`.
4. Define the Bochner integral on L1 functions by extending the integral on integrable simple
functions `α →₁ₛ[μ] E` using `ContinuousLinearMap.extend` and the fact that the embedding of
`α →₁ₛ[μ] E` into `α →₁[μ] E` is dense.
5. Define the Bochner integral on functions as the Bochner integral of its equivalence class in L1
space, if it is in L1, and 0 otherwise.
The result of that construction is `∫ a, f a ∂μ`, which is definitionally equal to
`setToFun (dominatedFinMeasAdditive_weightedSMul μ) f`. Some basic properties of the integral
(like linearity) are particular cases of the properties of `setToFun` (which are described in the
file `SetToL1`).
## Main statements
1. Basic properties of the Bochner integral on functions of type `α → E`, where `α` is a measure
space and `E` is a real normed space.
* `integral_zero` : `∫ 0 ∂μ = 0`
* `integral_add` : `∫ x, f x + g x ∂μ = ∫ x, f ∂μ + ∫ x, g x ∂μ`
* `integral_neg` : `∫ x, - f x ∂μ = - ∫ x, f x ∂μ`
* `integral_sub` : `∫ x, f x - g x ∂μ = ∫ x, f x ∂μ - ∫ x, g x ∂μ`
* `integral_smul` : `∫ x, r • f x ∂μ = r • ∫ x, f x ∂μ`
* `integral_congr_ae` : `f =ᵐ[μ] g → ∫ x, f x ∂μ = ∫ x, g x ∂μ`
* `norm_integral_le_integral_norm` : `‖∫ x, f x ∂μ‖ ≤ ∫ x, ‖f x‖ ∂μ`
2. Basic properties of the Bochner integral on functions of type `α → ℝ`, where `α` is a measure
space.
* `integral_nonneg_of_ae` : `0 ≤ᵐ[μ] f → 0 ≤ ∫ x, f x ∂μ`
* `integral_nonpos_of_ae` : `f ≤ᵐ[μ] 0 → ∫ x, f x ∂μ ≤ 0`
* `integral_mono_ae` : `f ≤ᵐ[μ] g → ∫ x, f x ∂μ ≤ ∫ x, g x ∂μ`
* `integral_nonneg` : `0 ≤ f → 0 ≤ ∫ x, f x ∂μ`
* `integral_nonpos` : `f ≤ 0 → ∫ x, f x ∂μ ≤ 0`
* `integral_mono` : `f ≤ᵐ[μ] g → ∫ x, f x ∂μ ≤ ∫ x, g x ∂μ`
3. Propositions connecting the Bochner integral with the integral on `ℝ≥0∞`-valued functions,
which is called `lintegral` and has the notation `∫⁻`.
* `integral_eq_lintegral_pos_part_sub_lintegral_neg_part` :
`∫ x, f x ∂μ = ∫⁻ x, f⁺ x ∂μ - ∫⁻ x, f⁻ x ∂μ`,
where `f⁺` is the positive part of `f` and `f⁻` is the negative part of `f`.
* `integral_eq_lintegral_of_nonneg_ae` : `0 ≤ᵐ[μ] f → ∫ x, f x ∂μ = ∫⁻ x, f x ∂μ`
4. (In the file `DominatedConvergence`)
`tendsto_integral_of_dominated_convergence` : the Lebesgue dominated convergence theorem
5. (In the file `SetIntegral`) integration commutes with continuous linear maps.
* `ContinuousLinearMap.integral_comp_comm`
* `LinearIsometry.integral_comp_comm`
## Notes
Some tips on how to prove a proposition if the API for the Bochner integral is not enough so that
you need to unfold the definition of the Bochner integral and go back to simple functions.
One method is to use the theorem `Integrable.induction` in the file `SimpleFuncDenseLp` (or one
of the related results, like `Lp.induction` for functions in `Lp`), which allows you to prove
something for an arbitrary integrable function.
Another method is using the following steps.
See `integral_eq_lintegral_pos_part_sub_lintegral_neg_part` for a complicated example, which proves
that `∫ f = ∫⁻ f⁺ - ∫⁻ f⁻`, with the first integral sign being the Bochner integral of a real-valued
function `f : α → ℝ`, and second and third integral sign being the integral on `ℝ≥0∞`-valued
functions (called `lintegral`). The proof of `integral_eq_lintegral_pos_part_sub_lintegral_neg_part`
is scattered in sections with the name `posPart`.
Here are the usual steps of proving that a property `p`, say `∫ f = ∫⁻ f⁺ - ∫⁻ f⁻`, holds for all
functions :
1. First go to the `L¹` space.
For example, if you see `ENNReal.toReal (∫⁻ a, ENNReal.ofReal <| ‖f a‖)`, that is the norm of
`f` in `L¹` space. Rewrite using `L1.norm_of_fun_eq_lintegral_norm`.
2. Show that the set `{f ∈ L¹ | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻}` is closed in `L¹` using `isClosed_eq`.
3. Show that the property holds for all simple functions `s` in `L¹` space.
Typically, you need to convert various notions to their `SimpleFunc` counterpart, using lemmas
like `L1.integral_coe_eq_integral`.
4. Since simple functions are dense in `L¹`,
```
univ = closure {s simple}
= closure {s simple | ∫ s = ∫⁻ s⁺ - ∫⁻ s⁻} : the property holds for all simple functions
⊆ closure {f | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻}
= {f | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻} : closure of a closed set is itself
```
Use `isClosed_property` or `DenseRange.induction_on` for this argument.
## Notations
* `α →ₛ E` : simple functions (defined in `MeasureTheory/Integration`)
* `α →₁[μ] E` : functions in L1 space, i.e., equivalence classes of integrable functions (defined in
`MeasureTheory/LpSpace`)
* `α →₁ₛ[μ] E` : simple functions in L1 space, i.e., equivalence classes of integrable simple
functions (defined in `MeasureTheory/SimpleFuncDense`)
* `∫ a, f a ∂μ` : integral of `f` with respect to a measure `μ`
* `∫ a, f a` : integral of `f` with respect to `volume`, the default measure on the ambient type
We also define notations for integral on a set, which are described in the file
`MeasureTheory/SetIntegral`.
Note : `ₛ` is typed using `\_s`. Sometimes it shows as a box if the font is missing.
## Tags
Bochner integral, simple function, function space, Lebesgue dominated convergence theorem
-/
assert_not_exists Differentiable
noncomputable section
open scoped Topology NNReal ENNReal MeasureTheory
open Set Filter TopologicalSpace ENNReal EMetric
namespace MeasureTheory
variable {α E F 𝕜 : Type*}
section WeightedSMul
open ContinuousLinearMap
variable [NormedAddCommGroup F] [NormedSpace ℝ F] {m : MeasurableSpace α} {μ : Measure α}
/-- Given a set `s`, return the continuous linear map `fun x => (μ s).toReal • x`. The extension
of that set function through `setToL1` gives the Bochner integral of L1 functions. -/
def weightedSMul {_ : MeasurableSpace α} (μ : Measure α) (s : Set α) : F →L[ℝ] F :=
(μ s).toReal • ContinuousLinearMap.id ℝ F
#align measure_theory.weighted_smul MeasureTheory.weightedSMul
theorem weightedSMul_apply {m : MeasurableSpace α} (μ : Measure α) (s : Set α) (x : F) :
weightedSMul μ s x = (μ s).toReal • x := by simp [weightedSMul]
#align measure_theory.weighted_smul_apply MeasureTheory.weightedSMul_apply
@[simp]
theorem weightedSMul_zero_measure {m : MeasurableSpace α} :
weightedSMul (0 : Measure α) = (0 : Set α → F →L[ℝ] F) := by ext1; simp [weightedSMul]
#align measure_theory.weighted_smul_zero_measure MeasureTheory.weightedSMul_zero_measure
@[simp]
theorem weightedSMul_empty {m : MeasurableSpace α} (μ : Measure α) :
weightedSMul μ ∅ = (0 : F →L[ℝ] F) := by ext1 x; rw [weightedSMul_apply]; simp
#align measure_theory.weighted_smul_empty MeasureTheory.weightedSMul_empty
theorem weightedSMul_add_measure {m : MeasurableSpace α} (μ ν : Measure α) {s : Set α}
(hμs : μ s ≠ ∞) (hνs : ν s ≠ ∞) :
(weightedSMul (μ + ν) s : F →L[ℝ] F) = weightedSMul μ s + weightedSMul ν s := by
ext1 x
push_cast
simp_rw [Pi.add_apply, weightedSMul_apply]
push_cast
rw [Pi.add_apply, ENNReal.toReal_add hμs hνs, add_smul]
#align measure_theory.weighted_smul_add_measure MeasureTheory.weightedSMul_add_measure
theorem weightedSMul_smul_measure {m : MeasurableSpace α} (μ : Measure α) (c : ℝ≥0∞) {s : Set α} :
(weightedSMul (c • μ) s : F →L[ℝ] F) = c.toReal • weightedSMul μ s := by
ext1 x
push_cast
simp_rw [Pi.smul_apply, weightedSMul_apply]
push_cast
simp_rw [Pi.smul_apply, smul_eq_mul, toReal_mul, smul_smul]
#align measure_theory.weighted_smul_smul_measure MeasureTheory.weightedSMul_smul_measure
theorem weightedSMul_congr (s t : Set α) (hst : μ s = μ t) :
(weightedSMul μ s : F →L[ℝ] F) = weightedSMul μ t := by
ext1 x; simp_rw [weightedSMul_apply]; congr 2
#align measure_theory.weighted_smul_congr MeasureTheory.weightedSMul_congr
theorem weightedSMul_null {s : Set α} (h_zero : μ s = 0) : (weightedSMul μ s : F →L[ℝ] F) = 0 := by
ext1 x; rw [weightedSMul_apply, h_zero]; simp
#align measure_theory.weighted_smul_null MeasureTheory.weightedSMul_null
theorem weightedSMul_union' (s t : Set α) (ht : MeasurableSet t) (hs_finite : μ s ≠ ∞)
(ht_finite : μ t ≠ ∞) (h_inter : s ∩ t = ∅) :
(weightedSMul μ (s ∪ t) : F →L[ℝ] F) = weightedSMul μ s + weightedSMul μ t := by
ext1 x
simp_rw [add_apply, weightedSMul_apply,
measure_union (Set.disjoint_iff_inter_eq_empty.mpr h_inter) ht,
ENNReal.toReal_add hs_finite ht_finite, add_smul]
#align measure_theory.weighted_smul_union' MeasureTheory.weightedSMul_union'
@[nolint unusedArguments]
theorem weightedSMul_union (s t : Set α) (_hs : MeasurableSet s) (ht : MeasurableSet t)
(hs_finite : μ s ≠ ∞) (ht_finite : μ t ≠ ∞) (h_inter : s ∩ t = ∅) :
(weightedSMul μ (s ∪ t) : F →L[ℝ] F) = weightedSMul μ s + weightedSMul μ t :=
weightedSMul_union' s t ht hs_finite ht_finite h_inter
#align measure_theory.weighted_smul_union MeasureTheory.weightedSMul_union
theorem weightedSMul_smul [NormedField 𝕜] [NormedSpace 𝕜 F] [SMulCommClass ℝ 𝕜 F] (c : 𝕜)
(s : Set α) (x : F) : weightedSMul μ s (c • x) = c • weightedSMul μ s x := by
simp_rw [weightedSMul_apply, smul_comm]
#align measure_theory.weighted_smul_smul MeasureTheory.weightedSMul_smul
theorem norm_weightedSMul_le (s : Set α) : ‖(weightedSMul μ s : F →L[ℝ] F)‖ ≤ (μ s).toReal :=
calc
‖(weightedSMul μ s : F →L[ℝ] F)‖ = ‖(μ s).toReal‖ * ‖ContinuousLinearMap.id ℝ F‖ :=
norm_smul (μ s).toReal (ContinuousLinearMap.id ℝ F)
_ ≤ ‖(μ s).toReal‖ :=
((mul_le_mul_of_nonneg_left norm_id_le (norm_nonneg _)).trans (mul_one _).le)
_ = abs (μ s).toReal := Real.norm_eq_abs _
_ = (μ s).toReal := abs_eq_self.mpr ENNReal.toReal_nonneg
#align measure_theory.norm_weighted_smul_le MeasureTheory.norm_weightedSMul_le
theorem dominatedFinMeasAdditive_weightedSMul {_ : MeasurableSpace α} (μ : Measure α) :
DominatedFinMeasAdditive μ (weightedSMul μ : Set α → F →L[ℝ] F) 1 :=
⟨weightedSMul_union, fun s _ _ => (norm_weightedSMul_le s).trans (one_mul _).symm.le⟩
#align measure_theory.dominated_fin_meas_additive_weighted_smul MeasureTheory.dominatedFinMeasAdditive_weightedSMul
theorem weightedSMul_nonneg (s : Set α) (x : ℝ) (hx : 0 ≤ x) : 0 ≤ weightedSMul μ s x := by
simp only [weightedSMul, Algebra.id.smul_eq_mul, coe_smul', _root_.id, coe_id', Pi.smul_apply]
exact mul_nonneg toReal_nonneg hx
#align measure_theory.weighted_smul_nonneg MeasureTheory.weightedSMul_nonneg
end WeightedSMul
local infixr:25 " →ₛ " => SimpleFunc
namespace SimpleFunc
section PosPart
variable [LinearOrder E] [Zero E] [MeasurableSpace α]
/-- Positive part of a simple function. -/
def posPart (f : α →ₛ E) : α →ₛ E :=
f.map fun b => max b 0
#align measure_theory.simple_func.pos_part MeasureTheory.SimpleFunc.posPart
/-- Negative part of a simple function. -/
def negPart [Neg E] (f : α →ₛ E) : α →ₛ E :=
posPart (-f)
#align measure_theory.simple_func.neg_part MeasureTheory.SimpleFunc.negPart
theorem posPart_map_norm (f : α →ₛ ℝ) : (posPart f).map norm = posPart f := by
ext; rw [map_apply, Real.norm_eq_abs, abs_of_nonneg]; exact le_max_right _ _
#align measure_theory.simple_func.pos_part_map_norm MeasureTheory.SimpleFunc.posPart_map_norm
theorem negPart_map_norm (f : α →ₛ ℝ) : (negPart f).map norm = negPart f := by
rw [negPart]; exact posPart_map_norm _
#align measure_theory.simple_func.neg_part_map_norm MeasureTheory.SimpleFunc.negPart_map_norm
theorem posPart_sub_negPart (f : α →ₛ ℝ) : f.posPart - f.negPart = f := by
simp only [posPart, negPart]
ext a
rw [coe_sub]
exact max_zero_sub_eq_self (f a)
#align measure_theory.simple_func.pos_part_sub_neg_part MeasureTheory.SimpleFunc.posPart_sub_negPart
end PosPart
section Integral
/-!
### The Bochner integral of simple functions
Define the Bochner integral of simple functions of the type `α →ₛ β` where `β` is a normed group,
and prove basic property of this integral.
-/
open Finset
variable [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedSpace ℝ F] {p : ℝ≥0∞} {G F' : Type*}
[NormedAddCommGroup G] [NormedAddCommGroup F'] [NormedSpace ℝ F'] {m : MeasurableSpace α}
{μ : Measure α}
/-- Bochner integral of simple functions whose codomain is a real `NormedSpace`.
This is equal to `∑ x ∈ f.range, (μ (f ⁻¹' {x})).toReal • x` (see `integral_eq`). -/
def integral {_ : MeasurableSpace α} (μ : Measure α) (f : α →ₛ F) : F :=
f.setToSimpleFunc (weightedSMul μ)
#align measure_theory.simple_func.integral MeasureTheory.SimpleFunc.integral
theorem integral_def {_ : MeasurableSpace α} (μ : Measure α) (f : α →ₛ F) :
f.integral μ = f.setToSimpleFunc (weightedSMul μ) := rfl
#align measure_theory.simple_func.integral_def MeasureTheory.SimpleFunc.integral_def
theorem integral_eq {m : MeasurableSpace α} (μ : Measure α) (f : α →ₛ F) :
f.integral μ = ∑ x ∈ f.range, (μ (f ⁻¹' {x})).toReal • x := by
simp [integral, setToSimpleFunc, weightedSMul_apply]
#align measure_theory.simple_func.integral_eq MeasureTheory.SimpleFunc.integral_eq
theorem integral_eq_sum_filter [DecidablePred fun x : F => x ≠ 0] {m : MeasurableSpace α}
(f : α →ₛ F) (μ : Measure α) :
f.integral μ = ∑ x ∈ f.range.filter fun x => x ≠ 0, (μ (f ⁻¹' {x})).toReal • x := by
rw [integral_def, setToSimpleFunc_eq_sum_filter]; simp_rw [weightedSMul_apply]; congr
#align measure_theory.simple_func.integral_eq_sum_filter MeasureTheory.SimpleFunc.integral_eq_sum_filter
/-- The Bochner integral is equal to a sum over any set that includes `f.range` (except `0`). -/
theorem integral_eq_sum_of_subset [DecidablePred fun x : F => x ≠ 0] {f : α →ₛ F} {s : Finset F}
(hs : (f.range.filter fun x => x ≠ 0) ⊆ s) :
f.integral μ = ∑ x ∈ s, (μ (f ⁻¹' {x})).toReal • x := by
rw [SimpleFunc.integral_eq_sum_filter, Finset.sum_subset hs]
rintro x - hx; rw [Finset.mem_filter, not_and_or, Ne, Classical.not_not] at hx
-- Porting note: reordered for clarity
rcases hx.symm with (rfl | hx)
· simp
rw [SimpleFunc.mem_range] at hx
-- Porting note: added
simp only [Set.mem_range, not_exists] at hx
rw [preimage_eq_empty] <;> simp [Set.disjoint_singleton_left, hx]
#align measure_theory.simple_func.integral_eq_sum_of_subset MeasureTheory.SimpleFunc.integral_eq_sum_of_subset
@[simp]
theorem integral_const {m : MeasurableSpace α} (μ : Measure α) (y : F) :
(const α y).integral μ = (μ univ).toReal • y := by
classical
calc
(const α y).integral μ = ∑ z ∈ {y}, (μ (const α y ⁻¹' {z})).toReal • z :=
integral_eq_sum_of_subset <| (filter_subset _ _).trans (range_const_subset _ _)
_ = (μ univ).toReal • y := by simp [Set.preimage] -- Porting note: added `Set.preimage`
#align measure_theory.simple_func.integral_const MeasureTheory.SimpleFunc.integral_const
@[simp]
theorem integral_piecewise_zero {m : MeasurableSpace α} (f : α →ₛ F) (μ : Measure α) {s : Set α}
(hs : MeasurableSet s) : (piecewise s hs f 0).integral μ = f.integral (μ.restrict s) := by
classical
refine (integral_eq_sum_of_subset ?_).trans
((sum_congr rfl fun y hy => ?_).trans (integral_eq_sum_filter _ _).symm)
· intro y hy
simp only [mem_filter, mem_range, coe_piecewise, coe_zero, piecewise_eq_indicator,
mem_range_indicator] at *
rcases hy with ⟨⟨rfl, -⟩ | ⟨x, -, rfl⟩, h₀⟩
exacts [(h₀ rfl).elim, ⟨Set.mem_range_self _, h₀⟩]
· dsimp
rw [Set.piecewise_eq_indicator, indicator_preimage_of_not_mem,
Measure.restrict_apply (f.measurableSet_preimage _)]
exact fun h₀ => (mem_filter.1 hy).2 (Eq.symm h₀)
#align measure_theory.simple_func.integral_piecewise_zero MeasureTheory.SimpleFunc.integral_piecewise_zero
/-- Calculate the integral of `g ∘ f : α →ₛ F`, where `f` is an integrable function from `α` to `E`
and `g` is a function from `E` to `F`. We require `g 0 = 0` so that `g ∘ f` is integrable. -/
theorem map_integral (f : α →ₛ E) (g : E → F) (hf : Integrable f μ) (hg : g 0 = 0) :
(f.map g).integral μ = ∑ x ∈ f.range, ENNReal.toReal (μ (f ⁻¹' {x})) • g x :=
map_setToSimpleFunc _ weightedSMul_union hf hg
#align measure_theory.simple_func.map_integral MeasureTheory.SimpleFunc.map_integral
/-- `SimpleFunc.integral` and `SimpleFunc.lintegral` agree when the integrand has type
`α →ₛ ℝ≥0∞`. But since `ℝ≥0∞` is not a `NormedSpace`, we need some form of coercion.
See `integral_eq_lintegral` for a simpler version. -/
theorem integral_eq_lintegral' {f : α →ₛ E} {g : E → ℝ≥0∞} (hf : Integrable f μ) (hg0 : g 0 = 0)
(ht : ∀ b, g b ≠ ∞) :
(f.map (ENNReal.toReal ∘ g)).integral μ = ENNReal.toReal (∫⁻ a, g (f a) ∂μ) := by
have hf' : f.FinMeasSupp μ := integrable_iff_finMeasSupp.1 hf
simp only [← map_apply g f, lintegral_eq_lintegral]
rw [map_integral f _ hf, map_lintegral, ENNReal.toReal_sum]
· refine Finset.sum_congr rfl fun b _ => ?_
-- Porting note: added `Function.comp_apply`
rw [smul_eq_mul, toReal_mul, mul_comm, Function.comp_apply]
· rintro a -
by_cases a0 : a = 0
· rw [a0, hg0, zero_mul]; exact WithTop.zero_ne_top
· apply mul_ne_top (ht a) (hf'.meas_preimage_singleton_ne_zero a0).ne
· simp [hg0]
#align measure_theory.simple_func.integral_eq_lintegral' MeasureTheory.SimpleFunc.integral_eq_lintegral'
variable [NormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace ℝ E] [SMulCommClass ℝ 𝕜 E]
theorem integral_congr {f g : α →ₛ E} (hf : Integrable f μ) (h : f =ᵐ[μ] g) :
f.integral μ = g.integral μ :=
setToSimpleFunc_congr (weightedSMul μ) (fun _ _ => weightedSMul_null) weightedSMul_union hf h
#align measure_theory.simple_func.integral_congr MeasureTheory.SimpleFunc.integral_congr
/-- `SimpleFunc.bintegral` and `SimpleFunc.integral` agree when the integrand has type
`α →ₛ ℝ≥0∞`. But since `ℝ≥0∞` is not a `NormedSpace`, we need some form of coercion. -/
theorem integral_eq_lintegral {f : α →ₛ ℝ} (hf : Integrable f μ) (h_pos : 0 ≤ᵐ[μ] f) :
f.integral μ = ENNReal.toReal (∫⁻ a, ENNReal.ofReal (f a) ∂μ) := by
have : f =ᵐ[μ] f.map (ENNReal.toReal ∘ ENNReal.ofReal) :=
h_pos.mono fun a h => (ENNReal.toReal_ofReal h).symm
rw [← integral_eq_lintegral' hf]
exacts [integral_congr hf this, ENNReal.ofReal_zero, fun b => ENNReal.ofReal_ne_top]
#align measure_theory.simple_func.integral_eq_lintegral MeasureTheory.SimpleFunc.integral_eq_lintegral
theorem integral_add {f g : α →ₛ E} (hf : Integrable f μ) (hg : Integrable g μ) :
integral μ (f + g) = integral μ f + integral μ g :=
setToSimpleFunc_add _ weightedSMul_union hf hg
#align measure_theory.simple_func.integral_add MeasureTheory.SimpleFunc.integral_add
theorem integral_neg {f : α →ₛ E} (hf : Integrable f μ) : integral μ (-f) = -integral μ f :=
setToSimpleFunc_neg _ weightedSMul_union hf
#align measure_theory.simple_func.integral_neg MeasureTheory.SimpleFunc.integral_neg
theorem integral_sub {f g : α →ₛ E} (hf : Integrable f μ) (hg : Integrable g μ) :
integral μ (f - g) = integral μ f - integral μ g :=
setToSimpleFunc_sub _ weightedSMul_union hf hg
#align measure_theory.simple_func.integral_sub MeasureTheory.SimpleFunc.integral_sub
theorem integral_smul (c : 𝕜) {f : α →ₛ E} (hf : Integrable f μ) :
integral μ (c • f) = c • integral μ f :=
setToSimpleFunc_smul _ weightedSMul_union weightedSMul_smul c hf
#align measure_theory.simple_func.integral_smul MeasureTheory.SimpleFunc.integral_smul
theorem norm_setToSimpleFunc_le_integral_norm (T : Set α → E →L[ℝ] F) {C : ℝ}
(hT_norm : ∀ s, MeasurableSet s → μ s < ∞ → ‖T s‖ ≤ C * (μ s).toReal) {f : α →ₛ E}
(hf : Integrable f μ) : ‖f.setToSimpleFunc T‖ ≤ C * (f.map norm).integral μ :=
calc
‖f.setToSimpleFunc T‖ ≤ C * ∑ x ∈ f.range, ENNReal.toReal (μ (f ⁻¹' {x})) * ‖x‖ :=
norm_setToSimpleFunc_le_sum_mul_norm_of_integrable T hT_norm f hf
_ = C * (f.map norm).integral μ := by
rw [map_integral f norm hf norm_zero]; simp_rw [smul_eq_mul]
#align measure_theory.simple_func.norm_set_to_simple_func_le_integral_norm MeasureTheory.SimpleFunc.norm_setToSimpleFunc_le_integral_norm
theorem norm_integral_le_integral_norm (f : α →ₛ E) (hf : Integrable f μ) :
‖f.integral μ‖ ≤ (f.map norm).integral μ := by
refine (norm_setToSimpleFunc_le_integral_norm _ (fun s _ _ => ?_) hf).trans (one_mul _).le
exact (norm_weightedSMul_le s).trans (one_mul _).symm.le
#align measure_theory.simple_func.norm_integral_le_integral_norm MeasureTheory.SimpleFunc.norm_integral_le_integral_norm
theorem integral_add_measure {ν} (f : α →ₛ E) (hf : Integrable f (μ + ν)) :
f.integral (μ + ν) = f.integral μ + f.integral ν := by
simp_rw [integral_def]
refine setToSimpleFunc_add_left'
(weightedSMul μ) (weightedSMul ν) (weightedSMul (μ + ν)) (fun s _ hμνs => ?_) hf
rw [lt_top_iff_ne_top, Measure.coe_add, Pi.add_apply, ENNReal.add_ne_top] at hμνs
rw [weightedSMul_add_measure _ _ hμνs.1 hμνs.2]
#align measure_theory.simple_func.integral_add_measure MeasureTheory.SimpleFunc.integral_add_measure
end Integral
end SimpleFunc
namespace L1
set_option linter.uppercaseLean3 false -- `L1`
open AEEqFun Lp.simpleFunc Lp
variable [NormedAddCommGroup E] [NormedAddCommGroup F] {m : MeasurableSpace α} {μ : Measure α}
namespace SimpleFunc
theorem norm_eq_integral (f : α →₁ₛ[μ] E) : ‖f‖ = ((toSimpleFunc f).map norm).integral μ := by
rw [norm_eq_sum_mul f, (toSimpleFunc f).map_integral norm (SimpleFunc.integrable f) norm_zero]
simp_rw [smul_eq_mul]
#align measure_theory.L1.simple_func.norm_eq_integral MeasureTheory.L1.SimpleFunc.norm_eq_integral
section PosPart
/-- Positive part of a simple function in L1 space. -/
nonrec def posPart (f : α →₁ₛ[μ] ℝ) : α →₁ₛ[μ] ℝ :=
⟨Lp.posPart (f : α →₁[μ] ℝ), by
rcases f with ⟨f, s, hsf⟩
use s.posPart
simp only [Subtype.coe_mk, Lp.coe_posPart, ← hsf, AEEqFun.posPart_mk,
SimpleFunc.coe_map, mk_eq_mk]
-- Porting note: added
simp [SimpleFunc.posPart, Function.comp, EventuallyEq.rfl] ⟩
#align measure_theory.L1.simple_func.pos_part MeasureTheory.L1.SimpleFunc.posPart
/-- Negative part of a simple function in L1 space. -/
def negPart (f : α →₁ₛ[μ] ℝ) : α →₁ₛ[μ] ℝ :=
posPart (-f)
#align measure_theory.L1.simple_func.neg_part MeasureTheory.L1.SimpleFunc.negPart
@[norm_cast]
theorem coe_posPart (f : α →₁ₛ[μ] ℝ) : (posPart f : α →₁[μ] ℝ) = Lp.posPart (f : α →₁[μ] ℝ) := rfl
#align measure_theory.L1.simple_func.coe_pos_part MeasureTheory.L1.SimpleFunc.coe_posPart
@[norm_cast]
theorem coe_negPart (f : α →₁ₛ[μ] ℝ) : (negPart f : α →₁[μ] ℝ) = Lp.negPart (f : α →₁[μ] ℝ) := rfl
#align measure_theory.L1.simple_func.coe_neg_part MeasureTheory.L1.SimpleFunc.coe_negPart
end PosPart
section SimpleFuncIntegral
/-!
### The Bochner integral of `L1`
Define the Bochner integral on `α →₁ₛ[μ] E` by extension from the simple functions `α →₁ₛ[μ] E`,
and prove basic properties of this integral. -/
variable [NormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace ℝ E] [SMulCommClass ℝ 𝕜 E] {F' : Type*}
[NormedAddCommGroup F'] [NormedSpace ℝ F']
attribute [local instance] simpleFunc.normedSpace
/-- The Bochner integral over simple functions in L1 space. -/
def integral (f : α →₁ₛ[μ] E) : E :=
(toSimpleFunc f).integral μ
#align measure_theory.L1.simple_func.integral MeasureTheory.L1.SimpleFunc.integral
theorem integral_eq_integral (f : α →₁ₛ[μ] E) : integral f = (toSimpleFunc f).integral μ := rfl
#align measure_theory.L1.simple_func.integral_eq_integral MeasureTheory.L1.SimpleFunc.integral_eq_integral
nonrec theorem integral_eq_lintegral {f : α →₁ₛ[μ] ℝ} (h_pos : 0 ≤ᵐ[μ] toSimpleFunc f) :
integral f = ENNReal.toReal (∫⁻ a, ENNReal.ofReal ((toSimpleFunc f) a) ∂μ) := by
rw [integral, SimpleFunc.integral_eq_lintegral (SimpleFunc.integrable f) h_pos]
#align measure_theory.L1.simple_func.integral_eq_lintegral MeasureTheory.L1.SimpleFunc.integral_eq_lintegral
theorem integral_eq_setToL1S (f : α →₁ₛ[μ] E) : integral f = setToL1S (weightedSMul μ) f := rfl
#align measure_theory.L1.simple_func.integral_eq_set_to_L1s MeasureTheory.L1.SimpleFunc.integral_eq_setToL1S
nonrec theorem integral_congr {f g : α →₁ₛ[μ] E} (h : toSimpleFunc f =ᵐ[μ] toSimpleFunc g) :
integral f = integral g :=
SimpleFunc.integral_congr (SimpleFunc.integrable f) h
#align measure_theory.L1.simple_func.integral_congr MeasureTheory.L1.SimpleFunc.integral_congr
theorem integral_add (f g : α →₁ₛ[μ] E) : integral (f + g) = integral f + integral g :=
setToL1S_add _ (fun _ _ => weightedSMul_null) weightedSMul_union _ _
#align measure_theory.L1.simple_func.integral_add MeasureTheory.L1.SimpleFunc.integral_add
theorem integral_smul (c : 𝕜) (f : α →₁ₛ[μ] E) : integral (c • f) = c • integral f :=
setToL1S_smul _ (fun _ _ => weightedSMul_null) weightedSMul_union weightedSMul_smul c f
#align measure_theory.L1.simple_func.integral_smul MeasureTheory.L1.SimpleFunc.integral_smul
theorem norm_integral_le_norm (f : α →₁ₛ[μ] E) : ‖integral f‖ ≤ ‖f‖ := by
rw [integral, norm_eq_integral]
exact (toSimpleFunc f).norm_integral_le_integral_norm (SimpleFunc.integrable f)
#align measure_theory.L1.simple_func.norm_integral_le_norm MeasureTheory.L1.SimpleFunc.norm_integral_le_norm
variable {E' : Type*} [NormedAddCommGroup E'] [NormedSpace ℝ E'] [NormedSpace 𝕜 E']
variable (α E μ 𝕜)
/-- The Bochner integral over simple functions in L1 space as a continuous linear map. -/
def integralCLM' : (α →₁ₛ[μ] E) →L[𝕜] E :=
LinearMap.mkContinuous ⟨⟨integral, integral_add⟩, integral_smul⟩ 1 fun f =>
le_trans (norm_integral_le_norm _) <| by rw [one_mul]
#align measure_theory.L1.simple_func.integral_clm' MeasureTheory.L1.SimpleFunc.integralCLM'
/-- The Bochner integral over simple functions in L1 space as a continuous linear map over ℝ. -/
def integralCLM : (α →₁ₛ[μ] E) →L[ℝ] E :=
integralCLM' α E ℝ μ
#align measure_theory.L1.simple_func.integral_clm MeasureTheory.L1.SimpleFunc.integralCLM
variable {α E μ 𝕜}
local notation "Integral" => integralCLM α E μ
open ContinuousLinearMap
theorem norm_Integral_le_one : ‖Integral‖ ≤ 1 :=
-- Porting note: Old proof was `LinearMap.mkContinuous_norm_le _ zero_le_one _`
LinearMap.mkContinuous_norm_le _ zero_le_one (fun f => by
rw [one_mul]
exact norm_integral_le_norm f)
#align measure_theory.L1.simple_func.norm_Integral_le_one MeasureTheory.L1.SimpleFunc.norm_Integral_le_one
section PosPart
theorem posPart_toSimpleFunc (f : α →₁ₛ[μ] ℝ) :
toSimpleFunc (posPart f) =ᵐ[μ] (toSimpleFunc f).posPart := by
have eq : ∀ a, (toSimpleFunc f).posPart a = max ((toSimpleFunc f) a) 0 := fun a => rfl
have ae_eq : ∀ᵐ a ∂μ, toSimpleFunc (posPart f) a = max ((toSimpleFunc f) a) 0 := by
filter_upwards [toSimpleFunc_eq_toFun (posPart f), Lp.coeFn_posPart (f : α →₁[μ] ℝ),
toSimpleFunc_eq_toFun f] with _ _ h₂ h₃
convert h₂ using 1
-- Porting note: added
rw [h₃]
refine ae_eq.mono fun a h => ?_
rw [h, eq]
#align measure_theory.L1.simple_func.pos_part_to_simple_func MeasureTheory.L1.SimpleFunc.posPart_toSimpleFunc
theorem negPart_toSimpleFunc (f : α →₁ₛ[μ] ℝ) :
toSimpleFunc (negPart f) =ᵐ[μ] (toSimpleFunc f).negPart := by
rw [SimpleFunc.negPart, MeasureTheory.SimpleFunc.negPart]
filter_upwards [posPart_toSimpleFunc (-f), neg_toSimpleFunc f]
intro a h₁ h₂
rw [h₁]
show max _ _ = max _ _
rw [h₂]
rfl
#align measure_theory.L1.simple_func.neg_part_to_simple_func MeasureTheory.L1.SimpleFunc.negPart_toSimpleFunc
theorem integral_eq_norm_posPart_sub (f : α →₁ₛ[μ] ℝ) : integral f = ‖posPart f‖ - ‖negPart f‖ := by
-- Convert things in `L¹` to their `SimpleFunc` counterpart
have ae_eq₁ : (toSimpleFunc f).posPart =ᵐ[μ] (toSimpleFunc (posPart f)).map norm := by
filter_upwards [posPart_toSimpleFunc f] with _ h
rw [SimpleFunc.map_apply, h]
conv_lhs => rw [← SimpleFunc.posPart_map_norm, SimpleFunc.map_apply]
-- Convert things in `L¹` to their `SimpleFunc` counterpart
have ae_eq₂ : (toSimpleFunc f).negPart =ᵐ[μ] (toSimpleFunc (negPart f)).map norm := by
filter_upwards [negPart_toSimpleFunc f] with _ h
rw [SimpleFunc.map_apply, h]
conv_lhs => rw [← SimpleFunc.negPart_map_norm, SimpleFunc.map_apply]
rw [integral, norm_eq_integral, norm_eq_integral, ← SimpleFunc.integral_sub]
· show (toSimpleFunc f).integral μ =
((toSimpleFunc (posPart f)).map norm - (toSimpleFunc (negPart f)).map norm).integral μ
apply MeasureTheory.SimpleFunc.integral_congr (SimpleFunc.integrable f)
filter_upwards [ae_eq₁, ae_eq₂] with _ h₁ h₂
show _ = _ - _
rw [← h₁, ← h₂]
have := (toSimpleFunc f).posPart_sub_negPart
conv_lhs => rw [← this]
rfl
· exact (SimpleFunc.integrable f).pos_part.congr ae_eq₁
· exact (SimpleFunc.integrable f).neg_part.congr ae_eq₂
#align measure_theory.L1.simple_func.integral_eq_norm_pos_part_sub MeasureTheory.L1.SimpleFunc.integral_eq_norm_posPart_sub
end PosPart
end SimpleFuncIntegral
end SimpleFunc
open SimpleFunc
local notation "Integral" => @integralCLM α E _ _ _ _ _ μ _
variable [NormedSpace ℝ E] [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E] [SMulCommClass ℝ 𝕜 E]
[NormedSpace ℝ F] [CompleteSpace E]
section IntegrationInL1
attribute [local instance] simpleFunc.normedSpace
open ContinuousLinearMap
variable (𝕜)
/-- The Bochner integral in L1 space as a continuous linear map. -/
nonrec def integralCLM' : (α →₁[μ] E) →L[𝕜] E :=
(integralCLM' α E 𝕜 μ).extend (coeToLp α E 𝕜) (simpleFunc.denseRange one_ne_top)
simpleFunc.uniformInducing
#align measure_theory.L1.integral_clm' MeasureTheory.L1.integralCLM'
variable {𝕜}
/-- The Bochner integral in L1 space as a continuous linear map over ℝ. -/
def integralCLM : (α →₁[μ] E) →L[ℝ] E :=
integralCLM' ℝ
#align measure_theory.L1.integral_clm MeasureTheory.L1.integralCLM
-- Porting note: added `(E := E)` in several places below.
/-- The Bochner integral in L1 space -/
irreducible_def integral (f : α →₁[μ] E) : E :=
integralCLM (E := E) f
#align measure_theory.L1.integral MeasureTheory.L1.integral
theorem integral_eq (f : α →₁[μ] E) : integral f = integralCLM (E := E) f := by
simp only [integral]
#align measure_theory.L1.integral_eq MeasureTheory.L1.integral_eq
theorem integral_eq_setToL1 (f : α →₁[μ] E) :
integral f = setToL1 (E := E) (dominatedFinMeasAdditive_weightedSMul μ) f := by
simp only [integral]; rfl
#align measure_theory.L1.integral_eq_set_to_L1 MeasureTheory.L1.integral_eq_setToL1
@[norm_cast]
| Mathlib/MeasureTheory/Integral/Bochner.lean | 679 | 682 | theorem SimpleFunc.integral_L1_eq_integral (f : α →₁ₛ[μ] E) :
L1.integral (f : α →₁[μ] E) = SimpleFunc.integral f := by |
simp only [integral, L1.integral]
exact setToL1_eq_setToL1SCLM (dominatedFinMeasAdditive_weightedSMul μ) f
|
/-
Copyright (c) 2021 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying
-/
import Mathlib.MeasureTheory.Measure.Sub
import Mathlib.MeasureTheory.Decomposition.SignedHahn
import Mathlib.MeasureTheory.Function.AEEqOfIntegral
#align_import measure_theory.decomposition.lebesgue from "leanprover-community/mathlib"@"b2ff9a3d7a15fd5b0f060b135421d6a89a999c2f"
/-!
# Lebesgue decomposition
This file proves the Lebesgue decomposition theorem. The Lebesgue decomposition theorem states that,
given two σ-finite measures `μ` and `ν`, there exists a σ-finite measure `ξ` and a measurable
function `f` such that `μ = ξ + fν` and `ξ` is mutually singular with respect to `ν`.
The Lebesgue decomposition provides the Radon-Nikodym theorem readily.
## Main definitions
* `MeasureTheory.Measure.HaveLebesgueDecomposition` : A pair of measures `μ` and `ν` is said
to `HaveLebesgueDecomposition` if there exist a measure `ξ` and a measurable function `f`,
such that `ξ` is mutually singular with respect to `ν` and `μ = ξ + ν.withDensity f`
* `MeasureTheory.Measure.singularPart` : If a pair of measures `HaveLebesgueDecomposition`,
then `singularPart` chooses the measure from `HaveLebesgueDecomposition`, otherwise it
returns the zero measure.
* `MeasureTheory.Measure.rnDeriv`: If a pair of measures
`HaveLebesgueDecomposition`, then `rnDeriv` chooses the measurable function from
`HaveLebesgueDecomposition`, otherwise it returns the zero function.
## Main results
* `MeasureTheory.Measure.haveLebesgueDecomposition_of_sigmaFinite` :
the Lebesgue decomposition theorem.
* `MeasureTheory.Measure.eq_singularPart` : Given measures `μ` and `ν`, if `s` is a measure
mutually singular to `ν` and `f` is a measurable function such that `μ = s + fν`, then
`s = μ.singularPart ν`.
* `MeasureTheory.Measure.eq_rnDeriv` : Given measures `μ` and `ν`, if `s` is a
measure mutually singular to `ν` and `f` is a measurable function such that `μ = s + fν`,
then `f = μ.rnDeriv ν`.
## Tags
Lebesgue decomposition theorem
-/
open scoped MeasureTheory NNReal ENNReal
open Set
namespace MeasureTheory
namespace Measure
variable {α β : Type*} {m : MeasurableSpace α} {μ ν : Measure α}
/-- A pair of measures `μ` and `ν` is said to `HaveLebesgueDecomposition` if there exists a
measure `ξ` and a measurable function `f`, such that `ξ` is mutually singular with respect to
`ν` and `μ = ξ + ν.withDensity f`. -/
class HaveLebesgueDecomposition (μ ν : Measure α) : Prop where
lebesgue_decomposition :
∃ p : Measure α × (α → ℝ≥0∞), Measurable p.2 ∧ p.1 ⟂ₘ ν ∧ μ = p.1 + ν.withDensity p.2
#align measure_theory.measure.have_lebesgue_decomposition MeasureTheory.Measure.HaveLebesgueDecomposition
#align measure_theory.measure.have_lebesgue_decomposition.lebesgue_decomposition MeasureTheory.Measure.HaveLebesgueDecomposition.lebesgue_decomposition
open Classical in
/-- If a pair of measures `HaveLebesgueDecomposition`, then `singularPart` chooses the
measure from `HaveLebesgueDecomposition`, otherwise it returns the zero measure. For sigma-finite
measures, `μ = μ.singularPart ν + ν.withDensity (μ.rnDeriv ν)`. -/
noncomputable irreducible_def singularPart (μ ν : Measure α) : Measure α :=
if h : HaveLebesgueDecomposition μ ν then (Classical.choose h.lebesgue_decomposition).1 else 0
#align measure_theory.measure.singular_part MeasureTheory.Measure.singularPart
open Classical in
/-- If a pair of measures `HaveLebesgueDecomposition`, then `rnDeriv` chooses the
measurable function from `HaveLebesgueDecomposition`, otherwise it returns the zero function.
For sigma-finite measures, `μ = μ.singularPart ν + ν.withDensity (μ.rnDeriv ν)`. -/
noncomputable irreducible_def rnDeriv (μ ν : Measure α) : α → ℝ≥0∞ :=
if h : HaveLebesgueDecomposition μ ν then (Classical.choose h.lebesgue_decomposition).2 else 0
#align measure_theory.measure.rn_deriv MeasureTheory.Measure.rnDeriv
section ByDefinition
theorem haveLebesgueDecomposition_spec (μ ν : Measure α) [h : HaveLebesgueDecomposition μ ν] :
Measurable (μ.rnDeriv ν) ∧
μ.singularPart ν ⟂ₘ ν ∧ μ = μ.singularPart ν + ν.withDensity (μ.rnDeriv ν) := by
rw [singularPart, rnDeriv, dif_pos h, dif_pos h]
exact Classical.choose_spec h.lebesgue_decomposition
#align measure_theory.measure.have_lebesgue_decomposition_spec MeasureTheory.Measure.haveLebesgueDecomposition_spec
lemma rnDeriv_of_not_haveLebesgueDecomposition (h : ¬ HaveLebesgueDecomposition μ ν) :
μ.rnDeriv ν = 0 := by
rw [rnDeriv, dif_neg h]
lemma singularPart_of_not_haveLebesgueDecomposition (h : ¬ HaveLebesgueDecomposition μ ν) :
μ.singularPart ν = 0 := by
rw [singularPart, dif_neg h]
@[measurability]
theorem measurable_rnDeriv (μ ν : Measure α) : Measurable <| μ.rnDeriv ν := by
by_cases h : HaveLebesgueDecomposition μ ν
· exact (haveLebesgueDecomposition_spec μ ν).1
· rw [rnDeriv_of_not_haveLebesgueDecomposition h]
exact measurable_zero
#align measure_theory.measure.measurable_rn_deriv MeasureTheory.Measure.measurable_rnDeriv
theorem mutuallySingular_singularPart (μ ν : Measure α) : μ.singularPart ν ⟂ₘ ν := by
by_cases h : HaveLebesgueDecomposition μ ν
· exact (haveLebesgueDecomposition_spec μ ν).2.1
· rw [singularPart_of_not_haveLebesgueDecomposition h]
exact MutuallySingular.zero_left
#align measure_theory.measure.mutually_singular_singular_part MeasureTheory.Measure.mutuallySingular_singularPart
theorem haveLebesgueDecomposition_add (μ ν : Measure α) [HaveLebesgueDecomposition μ ν] :
μ = μ.singularPart ν + ν.withDensity (μ.rnDeriv ν) :=
(haveLebesgueDecomposition_spec μ ν).2.2
#align measure_theory.measure.have_lebesgue_decomposition_add MeasureTheory.Measure.haveLebesgueDecomposition_add
lemma singularPart_add_rnDeriv (μ ν : Measure α) [HaveLebesgueDecomposition μ ν] :
μ.singularPart ν + ν.withDensity (μ.rnDeriv ν) = μ := (haveLebesgueDecomposition_add μ ν).symm
lemma rnDeriv_add_singularPart (μ ν : Measure α) [HaveLebesgueDecomposition μ ν] :
ν.withDensity (μ.rnDeriv ν) + μ.singularPart ν = μ := by rw [add_comm, singularPart_add_rnDeriv]
end ByDefinition
section HaveLebesgueDecomposition
instance instHaveLebesgueDecompositionZeroLeft : HaveLebesgueDecomposition 0 ν where
lebesgue_decomposition := ⟨⟨0, 0⟩, measurable_zero, MutuallySingular.zero_left, by simp⟩
instance instHaveLebesgueDecompositionZeroRight : HaveLebesgueDecomposition μ 0 where
lebesgue_decomposition := ⟨⟨μ, 0⟩, measurable_zero, MutuallySingular.zero_right, by simp⟩
instance instHaveLebesgueDecompositionSelf : HaveLebesgueDecomposition μ μ where
lebesgue_decomposition := ⟨⟨0, 1⟩, measurable_const, MutuallySingular.zero_left, by simp⟩
instance haveLebesgueDecompositionSMul' (μ ν : Measure α) [HaveLebesgueDecomposition μ ν]
(r : ℝ≥0∞) : (r • μ).HaveLebesgueDecomposition ν where
lebesgue_decomposition := by
obtain ⟨hmeas, hsing, hadd⟩ := haveLebesgueDecomposition_spec μ ν
refine ⟨⟨r • μ.singularPart ν, r • μ.rnDeriv ν⟩, hmeas.const_smul _, hsing.smul _, ?_⟩
simp only [ENNReal.smul_def]
rw [withDensity_smul _ hmeas, ← smul_add, ← hadd]
instance haveLebesgueDecompositionSMul (μ ν : Measure α) [HaveLebesgueDecomposition μ ν]
(r : ℝ≥0) : (r • μ).HaveLebesgueDecomposition ν := by
rw [ENNReal.smul_def]; infer_instance
#align measure_theory.measure.have_lebesgue_decomposition_smul MeasureTheory.Measure.haveLebesgueDecompositionSMul
instance haveLebesgueDecompositionSMulRight (μ ν : Measure α) [HaveLebesgueDecomposition μ ν]
(r : ℝ≥0) :
μ.HaveLebesgueDecomposition (r • ν) where
lebesgue_decomposition := by
obtain ⟨hmeas, hsing, hadd⟩ := haveLebesgueDecomposition_spec μ ν
by_cases hr : r = 0
· exact ⟨⟨μ, 0⟩, measurable_const, by simp [hr], by simp⟩
refine ⟨⟨μ.singularPart ν, r⁻¹ • μ.rnDeriv ν⟩, hmeas.const_smul _,
hsing.mono_ac AbsolutelyContinuous.rfl smul_absolutelyContinuous, ?_⟩
have : r⁻¹ • rnDeriv μ ν = ((r⁻¹ : ℝ≥0) : ℝ≥0∞) • rnDeriv μ ν := by simp [ENNReal.smul_def]
rw [this, withDensity_smul _ hmeas, ENNReal.smul_def r, withDensity_smul_measure,
← smul_assoc, smul_eq_mul, ENNReal.coe_inv hr, ENNReal.inv_mul_cancel, one_smul]
· exact hadd
· simp [hr]
· exact ENNReal.coe_ne_top
theorem haveLebesgueDecomposition_withDensity (μ : Measure α) {f : α → ℝ≥0∞} (hf : Measurable f) :
(μ.withDensity f).HaveLebesgueDecomposition μ := ⟨⟨⟨0, f⟩, hf, .zero_left, (zero_add _).symm⟩⟩
instance haveLebesgueDecompositionRnDeriv (μ ν : Measure α) :
HaveLebesgueDecomposition (ν.withDensity (μ.rnDeriv ν)) ν :=
haveLebesgueDecomposition_withDensity ν (measurable_rnDeriv _ _)
instance instHaveLebesgueDecompositionSingularPart :
HaveLebesgueDecomposition (μ.singularPart ν) ν :=
⟨⟨μ.singularPart ν, 0⟩, measurable_zero, mutuallySingular_singularPart μ ν, by simp⟩
end HaveLebesgueDecomposition
theorem singularPart_le (μ ν : Measure α) : μ.singularPart ν ≤ μ := by
by_cases hl : HaveLebesgueDecomposition μ ν
· conv_rhs => rw [haveLebesgueDecomposition_add μ ν]
exact Measure.le_add_right le_rfl
· rw [singularPart, dif_neg hl]
exact Measure.zero_le μ
#align measure_theory.measure.singular_part_le MeasureTheory.Measure.singularPart_le
theorem withDensity_rnDeriv_le (μ ν : Measure α) : ν.withDensity (μ.rnDeriv ν) ≤ μ := by
by_cases hl : HaveLebesgueDecomposition μ ν
· conv_rhs => rw [haveLebesgueDecomposition_add μ ν]
exact Measure.le_add_left le_rfl
· rw [rnDeriv, dif_neg hl, withDensity_zero]
exact Measure.zero_le μ
#align measure_theory.measure.with_density_rn_deriv_le MeasureTheory.Measure.withDensity_rnDeriv_le
lemma _root_.AEMeasurable.singularPart {β : Type*} {_ : MeasurableSpace β} {f : α → β}
(hf : AEMeasurable f μ) (ν : Measure α) :
AEMeasurable f (μ.singularPart ν) :=
AEMeasurable.mono_measure hf (Measure.singularPart_le _ _)
lemma _root_.AEMeasurable.withDensity_rnDeriv {β : Type*} {_ : MeasurableSpace β} {f : α → β}
(hf : AEMeasurable f μ) (ν : Measure α) :
AEMeasurable f (ν.withDensity (μ.rnDeriv ν)) :=
AEMeasurable.mono_measure hf (Measure.withDensity_rnDeriv_le _ _)
lemma MutuallySingular.singularPart (h : μ ⟂ₘ ν) (ν' : Measure α) :
μ.singularPart ν' ⟂ₘ ν :=
h.mono (singularPart_le μ ν') le_rfl
lemma absolutelyContinuous_withDensity_rnDeriv [HaveLebesgueDecomposition ν μ] (hμν : μ ≪ ν) :
μ ≪ μ.withDensity (ν.rnDeriv μ) := by
rw [haveLebesgueDecomposition_add ν μ] at hμν
refine AbsolutelyContinuous.mk (fun s _ hνs ↦ ?_)
obtain ⟨t, _, ht1, ht2⟩ := mutuallySingular_singularPart ν μ
rw [← inter_union_compl s]
refine le_antisymm ((measure_union_le (s ∩ t) (s ∩ tᶜ)).trans ?_) (zero_le _)
simp only [nonpos_iff_eq_zero, add_eq_zero]
constructor
· refine hμν ?_
simp only [coe_add, Pi.add_apply, add_eq_zero]
constructor
· exact measure_mono_null Set.inter_subset_right ht1
· exact measure_mono_null Set.inter_subset_left hνs
· exact measure_mono_null Set.inter_subset_right ht2
lemma singularPart_eq_zero_of_ac (h : μ ≪ ν) : μ.singularPart ν = 0 := by
rw [← MutuallySingular.self_iff]
exact MutuallySingular.mono_ac (mutuallySingular_singularPart _ _)
AbsolutelyContinuous.rfl ((absolutelyContinuous_of_le (singularPart_le _ _)).trans h)
@[simp]
theorem singularPart_zero (ν : Measure α) : (0 : Measure α).singularPart ν = 0 :=
singularPart_eq_zero_of_ac (AbsolutelyContinuous.zero _)
#align measure_theory.measure.singular_part_zero MeasureTheory.Measure.singularPart_zero
@[simp]
lemma singularPart_zero_right (μ : Measure α) : μ.singularPart 0 = μ := by
conv_rhs => rw [haveLebesgueDecomposition_add μ 0]
simp
lemma singularPart_eq_zero (μ ν : Measure α) [μ.HaveLebesgueDecomposition ν] :
μ.singularPart ν = 0 ↔ μ ≪ ν := by
have h_dec := haveLebesgueDecomposition_add μ ν
refine ⟨fun h ↦ ?_, singularPart_eq_zero_of_ac⟩
rw [h, zero_add] at h_dec
rw [h_dec]
exact withDensity_absolutelyContinuous ν _
@[simp]
lemma withDensity_rnDeriv_eq_zero (μ ν : Measure α) [μ.HaveLebesgueDecomposition ν] :
ν.withDensity (μ.rnDeriv ν) = 0 ↔ μ ⟂ₘ ν := by
have h_dec := haveLebesgueDecomposition_add μ ν
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· rw [h, add_zero] at h_dec
rw [h_dec]
exact mutuallySingular_singularPart μ ν
· rw [← MutuallySingular.self_iff]
rw [h_dec, MutuallySingular.add_left_iff] at h
refine MutuallySingular.mono_ac h.2 AbsolutelyContinuous.rfl ?_
exact withDensity_absolutelyContinuous _ _
@[simp]
lemma rnDeriv_eq_zero (μ ν : Measure α) [μ.HaveLebesgueDecomposition ν] :
μ.rnDeriv ν =ᵐ[ν] 0 ↔ μ ⟂ₘ ν := by
rw [← withDensity_rnDeriv_eq_zero, withDensity_eq_zero_iff (measurable_rnDeriv _ _).aemeasurable]
lemma rnDeriv_zero (ν : Measure α) : (0 : Measure α).rnDeriv ν =ᵐ[ν] 0 := by
rw [rnDeriv_eq_zero]
exact MutuallySingular.zero_left
lemma MutuallySingular.rnDeriv_ae_eq_zero (hμν : μ ⟂ₘ ν) :
μ.rnDeriv ν =ᵐ[ν] 0 := by
by_cases h : μ.HaveLebesgueDecomposition ν
· rw [rnDeriv_eq_zero]
exact hμν
· rw [rnDeriv_of_not_haveLebesgueDecomposition h]
@[simp]
theorem singularPart_withDensity (ν : Measure α) (f : α → ℝ≥0∞) :
(ν.withDensity f).singularPart ν = 0 :=
singularPart_eq_zero_of_ac (withDensity_absolutelyContinuous _ _)
#align measure_theory.measure.singular_part_with_density MeasureTheory.Measure.singularPart_withDensity
lemma rnDeriv_singularPart (μ ν : Measure α) :
(μ.singularPart ν).rnDeriv ν =ᵐ[ν] 0 := by
rw [rnDeriv_eq_zero]
exact mutuallySingular_singularPart μ ν
@[simp]
lemma singularPart_self (μ : Measure α) : μ.singularPart μ = 0 :=
singularPart_eq_zero_of_ac Measure.AbsolutelyContinuous.rfl
lemma rnDeriv_self (μ : Measure α) [SigmaFinite μ] : μ.rnDeriv μ =ᵐ[μ] fun _ ↦ 1 := by
have h := rnDeriv_add_singularPart μ μ
rw [singularPart_self, add_zero] at h
have h_one : μ = μ.withDensity 1 := by simp
conv_rhs at h => rw [h_one]
rwa [withDensity_eq_iff_of_sigmaFinite (measurable_rnDeriv _ _).aemeasurable] at h
exact aemeasurable_const
lemma singularPart_eq_self [μ.HaveLebesgueDecomposition ν] : μ.singularPart ν = μ ↔ μ ⟂ₘ ν := by
have h_dec := haveLebesgueDecomposition_add μ ν
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· rw [← h]
exact mutuallySingular_singularPart _ _
· conv_rhs => rw [h_dec]
rw [(withDensity_rnDeriv_eq_zero _ _).mpr h, add_zero]
@[simp]
lemma singularPart_singularPart (μ ν : Measure α) :
(μ.singularPart ν).singularPart ν = μ.singularPart ν := by
rw [Measure.singularPart_eq_self]
exact Measure.mutuallySingular_singularPart _ _
instance singularPart.instIsFiniteMeasure [IsFiniteMeasure μ] :
IsFiniteMeasure (μ.singularPart ν) :=
isFiniteMeasure_of_le μ <| singularPart_le μ ν
#align measure_theory.measure.singular_part.measure_theory.is_finite_measure MeasureTheory.Measure.singularPart.instIsFiniteMeasure
instance singularPart.instSigmaFinite [SigmaFinite μ] : SigmaFinite (μ.singularPart ν) :=
sigmaFinite_of_le μ <| singularPart_le μ ν
#align measure_theory.measure.singular_part.measure_theory.sigma_finite MeasureTheory.Measure.singularPart.instSigmaFinite
instance singularPart.instIsLocallyFiniteMeasure [TopologicalSpace α] [IsLocallyFiniteMeasure μ] :
IsLocallyFiniteMeasure (μ.singularPart ν) :=
isLocallyFiniteMeasure_of_le <| singularPart_le μ ν
#align measure_theory.measure.singular_part.measure_theory.is_locally_finite_measure MeasureTheory.Measure.singularPart.instIsLocallyFiniteMeasure
instance withDensity.instIsFiniteMeasure [IsFiniteMeasure μ] :
IsFiniteMeasure (ν.withDensity <| μ.rnDeriv ν) :=
isFiniteMeasure_of_le μ <| withDensity_rnDeriv_le μ ν
#align measure_theory.measure.with_density.measure_theory.is_finite_measure MeasureTheory.Measure.withDensity.instIsFiniteMeasure
instance withDensity.instSigmaFinite [SigmaFinite μ] :
SigmaFinite (ν.withDensity <| μ.rnDeriv ν) :=
sigmaFinite_of_le μ <| withDensity_rnDeriv_le μ ν
#align measure_theory.measure.with_density.measure_theory.sigma_finite MeasureTheory.Measure.withDensity.instSigmaFinite
instance withDensity.instIsLocallyFiniteMeasure [TopologicalSpace α] [IsLocallyFiniteMeasure μ] :
IsLocallyFiniteMeasure (ν.withDensity <| μ.rnDeriv ν) :=
isLocallyFiniteMeasure_of_le <| withDensity_rnDeriv_le μ ν
#align measure_theory.measure.with_density.measure_theory.is_locally_finite_measure MeasureTheory.Measure.withDensity.instIsLocallyFiniteMeasure
section RNDerivFinite
theorem lintegral_rnDeriv_lt_top_of_measure_ne_top (ν : Measure α) {s : Set α} (hs : μ s ≠ ∞) :
∫⁻ x in s, μ.rnDeriv ν x ∂ν < ∞ := by
by_cases hl : HaveLebesgueDecomposition μ ν
· suffices (∫⁻ x in toMeasurable μ s, μ.rnDeriv ν x ∂ν) < ∞ from
lt_of_le_of_lt (lintegral_mono_set (subset_toMeasurable _ _)) this
rw [← withDensity_apply _ (measurableSet_toMeasurable _ _)]
calc
_ ≤ (singularPart μ ν) (toMeasurable μ s) + _ := le_add_self
_ = μ s := by rw [← Measure.add_apply, ← haveLebesgueDecomposition_add, measure_toMeasurable]
_ < ⊤ := hs.lt_top
· simp only [Measure.rnDeriv, dif_neg hl, Pi.zero_apply, lintegral_zero, ENNReal.zero_lt_top]
#align measure_theory.measure.lintegral_rn_deriv_lt_top_of_measure_ne_top MeasureTheory.Measure.lintegral_rnDeriv_lt_top_of_measure_ne_top
theorem lintegral_rnDeriv_lt_top (μ ν : Measure α) [IsFiniteMeasure μ] :
∫⁻ x, μ.rnDeriv ν x ∂ν < ∞ := by
rw [← set_lintegral_univ]
exact lintegral_rnDeriv_lt_top_of_measure_ne_top _ (measure_lt_top _ _).ne
#align measure_theory.measure.lintegral_rn_deriv_lt_top MeasureTheory.Measure.lintegral_rnDeriv_lt_top
lemma integrable_toReal_rnDeriv [IsFiniteMeasure μ] :
Integrable (fun x ↦ (μ.rnDeriv ν x).toReal) ν :=
integrable_toReal_of_lintegral_ne_top (Measure.measurable_rnDeriv _ _).aemeasurable
(Measure.lintegral_rnDeriv_lt_top _ _).ne
/-- The Radon-Nikodym derivative of a sigma-finite measure `μ` with respect to another
measure `ν` is `ν`-almost everywhere finite. -/
theorem rnDeriv_lt_top (μ ν : Measure α) [SigmaFinite μ] : ∀ᵐ x ∂ν, μ.rnDeriv ν x < ∞ := by
suffices ∀ n, ∀ᵐ x ∂ν, x ∈ spanningSets μ n → μ.rnDeriv ν x < ∞ by
filter_upwards [ae_all_iff.2 this] with _ hx using hx _ (mem_spanningSetsIndex _ _)
intro n
rw [← ae_restrict_iff' (measurable_spanningSets _ _)]
apply ae_lt_top (measurable_rnDeriv _ _)
refine (lintegral_rnDeriv_lt_top_of_measure_ne_top _ ?_).ne
exact (measure_spanningSets_lt_top _ _).ne
#align measure_theory.measure.rn_deriv_lt_top MeasureTheory.Measure.rnDeriv_lt_top
lemma rnDeriv_ne_top (μ ν : Measure α) [SigmaFinite μ] : ∀ᵐ x ∂ν, μ.rnDeriv ν x ≠ ∞ := by
filter_upwards [Measure.rnDeriv_lt_top μ ν] with x hx using hx.ne
end RNDerivFinite
/-- Given measures `μ` and `ν`, if `s` is a measure mutually singular to `ν` and `f` is a
measurable function such that `μ = s + fν`, then `s = μ.singularPart μ`.
This theorem provides the uniqueness of the `singularPart` in the Lebesgue decomposition theorem,
while `MeasureTheory.Measure.eq_rnDeriv` provides the uniqueness of the
`rnDeriv`. -/
theorem eq_singularPart {s : Measure α} {f : α → ℝ≥0∞} (hf : Measurable f) (hs : s ⟂ₘ ν)
(hadd : μ = s + ν.withDensity f) : s = μ.singularPart ν := by
have : HaveLebesgueDecomposition μ ν := ⟨⟨⟨s, f⟩, hf, hs, hadd⟩⟩
obtain ⟨hmeas, hsing, hadd'⟩ := haveLebesgueDecomposition_spec μ ν
obtain ⟨⟨S, hS₁, hS₂, hS₃⟩, ⟨T, hT₁, hT₂, hT₃⟩⟩ := hs, hsing
rw [hadd'] at hadd
have hνinter : ν (S ∩ T)ᶜ = 0 := by
rw [compl_inter]
refine nonpos_iff_eq_zero.1 (le_trans (measure_union_le _ _) ?_)
rw [hT₃, hS₃, add_zero]
have heq : s.restrict (S ∩ T)ᶜ = (μ.singularPart ν).restrict (S ∩ T)ᶜ := by
ext1 A hA
have hf : ν.withDensity f (A ∩ (S ∩ T)ᶜ) = 0 := by
refine withDensity_absolutelyContinuous ν _ ?_
rw [← nonpos_iff_eq_zero]
exact hνinter ▸ measure_mono inter_subset_right
have hrn : ν.withDensity (μ.rnDeriv ν) (A ∩ (S ∩ T)ᶜ) = 0 := by
refine withDensity_absolutelyContinuous ν _ ?_
rw [← nonpos_iff_eq_zero]
exact hνinter ▸ measure_mono inter_subset_right
rw [restrict_apply hA, restrict_apply hA, ← add_zero (s (A ∩ (S ∩ T)ᶜ)), ← hf, ← add_apply, ←
hadd, add_apply, hrn, add_zero]
have heq' : ∀ A : Set α, MeasurableSet A → s A = s.restrict (S ∩ T)ᶜ A := by
intro A hA
have hsinter : s (A ∩ (S ∩ T)) = 0 := by
rw [← nonpos_iff_eq_zero]
exact hS₂ ▸ measure_mono (inter_subset_right.trans inter_subset_left)
rw [restrict_apply hA, ← diff_eq, AEDisjoint.measure_diff_left hsinter]
ext1 A hA
have hμinter : μ.singularPart ν (A ∩ (S ∩ T)) = 0 := by
rw [← nonpos_iff_eq_zero]
exact hT₂ ▸ measure_mono (inter_subset_right.trans inter_subset_right)
rw [heq' A hA, heq, restrict_apply hA, ← diff_eq, AEDisjoint.measure_diff_left hμinter]
#align measure_theory.measure.eq_singular_part MeasureTheory.Measure.eq_singularPart
theorem singularPart_smul (μ ν : Measure α) (r : ℝ≥0) :
(r • μ).singularPart ν = r • μ.singularPart ν := by
by_cases hr : r = 0
· rw [hr, zero_smul, zero_smul, singularPart_zero]
by_cases hl : HaveLebesgueDecomposition μ ν
· refine (eq_singularPart ((measurable_rnDeriv μ ν).const_smul (r : ℝ≥0∞))
(MutuallySingular.smul r (mutuallySingular_singularPart _ _)) ?_).symm
rw [withDensity_smul _ (measurable_rnDeriv _ _), ← smul_add,
← haveLebesgueDecomposition_add μ ν, ENNReal.smul_def]
· rw [singularPart, singularPart, dif_neg hl, dif_neg, smul_zero]
refine fun hl' ↦ hl ?_
rw [← inv_smul_smul₀ hr μ]
infer_instance
#align measure_theory.measure.singular_part_smul MeasureTheory.Measure.singularPart_smul
theorem singularPart_smul_right (μ ν : Measure α) (r : ℝ≥0) (hr : r ≠ 0) :
μ.singularPart (r • ν) = μ.singularPart ν := by
by_cases hl : HaveLebesgueDecomposition μ ν
· refine (eq_singularPart ((measurable_rnDeriv μ ν).const_smul r⁻¹) ?_ ?_).symm
· exact (mutuallySingular_singularPart μ ν).mono_ac AbsolutelyContinuous.rfl
smul_absolutelyContinuous
· rw [ENNReal.smul_def r, withDensity_smul_measure, ← withDensity_smul]
swap; · exact (measurable_rnDeriv _ _).const_smul _
convert haveLebesgueDecomposition_add μ ν
ext x
simp only [Pi.smul_apply]
rw [← ENNReal.smul_def, smul_inv_smul₀ hr]
· rw [singularPart, singularPart, dif_neg hl, dif_neg]
refine fun hl' ↦ hl ?_
rw [← inv_smul_smul₀ hr ν]
infer_instance
theorem singularPart_add (μ₁ μ₂ ν : Measure α) [HaveLebesgueDecomposition μ₁ ν]
[HaveLebesgueDecomposition μ₂ ν] :
(μ₁ + μ₂).singularPart ν = μ₁.singularPart ν + μ₂.singularPart ν := by
refine (eq_singularPart ((measurable_rnDeriv μ₁ ν).add (measurable_rnDeriv μ₂ ν))
((mutuallySingular_singularPart _ _).add_left (mutuallySingular_singularPart _ _)) ?_).symm
erw [withDensity_add_left (measurable_rnDeriv μ₁ ν)]
conv_rhs => rw [add_assoc, add_comm (μ₂.singularPart ν), ← add_assoc, ← add_assoc]
rw [← haveLebesgueDecomposition_add μ₁ ν, add_assoc, add_comm (ν.withDensity (μ₂.rnDeriv ν)),
← haveLebesgueDecomposition_add μ₂ ν]
#align measure_theory.measure.singular_part_add MeasureTheory.Measure.singularPart_add
lemma singularPart_restrict (μ ν : Measure α) [HaveLebesgueDecomposition μ ν]
{s : Set α} (hs : MeasurableSet s) :
(μ.restrict s).singularPart ν = (μ.singularPart ν).restrict s := by
refine (Measure.eq_singularPart (f := s.indicator (μ.rnDeriv ν)) ?_ ?_ ?_).symm
· exact (μ.measurable_rnDeriv ν).indicator hs
· exact (Measure.mutuallySingular_singularPart μ ν).restrict s
· ext t
rw [withDensity_indicator hs, ← restrict_withDensity hs, ← Measure.restrict_add,
← μ.haveLebesgueDecomposition_add ν]
/-- Given measures `μ` and `ν`, if `s` is a measure mutually singular to `ν` and `f` is a
measurable function such that `μ = s + fν`, then `f = μ.rnDeriv ν`.
This theorem provides the uniqueness of the `rnDeriv` in the Lebesgue decomposition
theorem, while `MeasureTheory.Measure.eq_singularPart` provides the uniqueness of the
`singularPart`. Here, the uniqueness is given in terms of the measures, while the uniqueness in
terms of the functions is given in `eq_rnDeriv`. -/
theorem eq_withDensity_rnDeriv {s : Measure α} {f : α → ℝ≥0∞} (hf : Measurable f) (hs : s ⟂ₘ ν)
(hadd : μ = s + ν.withDensity f) : ν.withDensity f = ν.withDensity (μ.rnDeriv ν) := by
have : HaveLebesgueDecomposition μ ν := ⟨⟨⟨s, f⟩, hf, hs, hadd⟩⟩
obtain ⟨hmeas, hsing, hadd'⟩ := haveLebesgueDecomposition_spec μ ν
obtain ⟨⟨S, hS₁, hS₂, hS₃⟩, ⟨T, hT₁, hT₂, hT₃⟩⟩ := hs, hsing
rw [hadd'] at hadd
have hνinter : ν (S ∩ T)ᶜ = 0 := by
rw [compl_inter]
refine nonpos_iff_eq_zero.1 (le_trans (measure_union_le _ _) ?_)
rw [hT₃, hS₃, add_zero]
have heq :
(ν.withDensity f).restrict (S ∩ T) = (ν.withDensity (μ.rnDeriv ν)).restrict (S ∩ T) := by
ext1 A hA
have hs : s (A ∩ (S ∩ T)) = 0 := by
rw [← nonpos_iff_eq_zero]
exact hS₂ ▸ measure_mono (inter_subset_right.trans inter_subset_left)
have hsing : μ.singularPart ν (A ∩ (S ∩ T)) = 0 := by
rw [← nonpos_iff_eq_zero]
exact hT₂ ▸ measure_mono (inter_subset_right.trans inter_subset_right)
rw [restrict_apply hA, restrict_apply hA, ← add_zero (ν.withDensity f (A ∩ (S ∩ T))), ← hs, ←
add_apply, add_comm, ← hadd, add_apply, hsing, zero_add]
have heq' :
∀ A : Set α, MeasurableSet A → ν.withDensity f A = (ν.withDensity f).restrict (S ∩ T) A := by
intro A hA
have hνfinter : ν.withDensity f (A ∩ (S ∩ T)ᶜ) = 0 := by
rw [← nonpos_iff_eq_zero]
exact withDensity_absolutelyContinuous ν f hνinter ▸ measure_mono inter_subset_right
rw [restrict_apply hA, ← add_zero (ν.withDensity f (A ∩ (S ∩ T))), ← hνfinter, ← diff_eq,
measure_inter_add_diff _ (hS₁.inter hT₁)]
ext1 A hA
have hνrn : ν.withDensity (μ.rnDeriv ν) (A ∩ (S ∩ T)ᶜ) = 0 := by
rw [← nonpos_iff_eq_zero]
exact
withDensity_absolutelyContinuous ν (μ.rnDeriv ν) hνinter ▸
measure_mono inter_subset_right
rw [heq' A hA, heq, ← add_zero ((ν.withDensity (μ.rnDeriv ν)).restrict (S ∩ T) A), ← hνrn,
restrict_apply hA, ← diff_eq, measure_inter_add_diff _ (hS₁.inter hT₁)]
#align measure_theory.measure.eq_with_density_rn_deriv MeasureTheory.Measure.eq_withDensity_rnDeriv
theorem eq_withDensity_rnDeriv₀ {s : Measure α} {f : α → ℝ≥0∞}
(hf : AEMeasurable f ν) (hs : s ⟂ₘ ν) (hadd : μ = s + ν.withDensity f) :
ν.withDensity f = ν.withDensity (μ.rnDeriv ν) := by
rw [withDensity_congr_ae hf.ae_eq_mk] at hadd ⊢
exact eq_withDensity_rnDeriv hf.measurable_mk hs hadd
theorem eq_rnDeriv₀ [SigmaFinite ν] {s : Measure α} {f : α → ℝ≥0∞}
(hf : AEMeasurable f ν) (hs : s ⟂ₘ ν) (hadd : μ = s + ν.withDensity f) :
f =ᵐ[ν] μ.rnDeriv ν :=
(withDensity_eq_iff_of_sigmaFinite hf (measurable_rnDeriv _ _).aemeasurable).mp
(eq_withDensity_rnDeriv₀ hf hs hadd)
/-- Given measures `μ` and `ν`, if `s` is a measure mutually singular to `ν` and `f` is a
measurable function such that `μ = s + fν`, then `f = μ.rnDeriv ν`.
This theorem provides the uniqueness of the `rnDeriv` in the Lebesgue decomposition
theorem, while `MeasureTheory.Measure.eq_singularPart` provides the uniqueness of the
`singularPart`. Here, the uniqueness is given in terms of the functions, while the uniqueness in
terms of the functions is given in `eq_withDensity_rnDeriv`. -/
theorem eq_rnDeriv [SigmaFinite ν] {s : Measure α} {f : α → ℝ≥0∞} (hf : Measurable f) (hs : s ⟂ₘ ν)
(hadd : μ = s + ν.withDensity f) : f =ᵐ[ν] μ.rnDeriv ν :=
eq_rnDeriv₀ hf.aemeasurable hs hadd
#align measure_theory.measure.eq_rn_deriv MeasureTheory.Measure.eq_rnDeriv
/-- The Radon-Nikodym derivative of `f ν` with respect to `ν` is `f`. -/
theorem rnDeriv_withDensity₀ (ν : Measure α) [SigmaFinite ν] {f : α → ℝ≥0∞}
(hf : AEMeasurable f ν) :
(ν.withDensity f).rnDeriv ν =ᵐ[ν] f :=
have : ν.withDensity f = 0 + ν.withDensity f := by rw [zero_add]
(eq_rnDeriv₀ hf MutuallySingular.zero_left this).symm
/-- The Radon-Nikodym derivative of `f ν` with respect to `ν` is `f`. -/
theorem rnDeriv_withDensity (ν : Measure α) [SigmaFinite ν] {f : α → ℝ≥0∞} (hf : Measurable f) :
(ν.withDensity f).rnDeriv ν =ᵐ[ν] f :=
rnDeriv_withDensity₀ ν hf.aemeasurable
#align measure_theory.measure.rn_deriv_with_density MeasureTheory.Measure.rnDeriv_withDensity
lemma rnDeriv_restrict (μ ν : Measure α) [HaveLebesgueDecomposition μ ν] [SigmaFinite ν]
{s : Set α} (hs : MeasurableSet s) :
(μ.restrict s).rnDeriv ν =ᵐ[ν] s.indicator (μ.rnDeriv ν) := by
refine (eq_rnDeriv (s := (μ.restrict s).singularPart ν)
((measurable_rnDeriv _ _).indicator hs) (mutuallySingular_singularPart _ _) ?_).symm
rw [singularPart_restrict _ _ hs, withDensity_indicator hs, ← restrict_withDensity hs,
← Measure.restrict_add, ← μ.haveLebesgueDecomposition_add ν]
/-- The Radon-Nikodym derivative of the restriction of a measure to a measurable set is the
indicator function of this set. -/
theorem rnDeriv_restrict_self (ν : Measure α) [SigmaFinite ν] {s : Set α} (hs : MeasurableSet s) :
(ν.restrict s).rnDeriv ν =ᵐ[ν] s.indicator 1 := by
rw [← withDensity_indicator_one hs]
exact rnDeriv_withDensity _ (measurable_one.indicator hs)
#align measure_theory.measure.rn_deriv_restrict MeasureTheory.Measure.rnDeriv_restrict_self
/-- Radon-Nikodym derivative of the scalar multiple of a measure.
See also `rnDeriv_smul_left'`, which requires sigma-finite `ν` and `μ`. -/
theorem rnDeriv_smul_left (ν μ : Measure α) [IsFiniteMeasure ν]
[ν.HaveLebesgueDecomposition μ] (r : ℝ≥0) :
(r • ν).rnDeriv μ =ᵐ[μ] r • ν.rnDeriv μ := by
rw [← withDensity_eq_iff]
· simp_rw [ENNReal.smul_def]
rw [withDensity_smul _ (measurable_rnDeriv _ _)]
suffices (r • ν).singularPart μ + withDensity μ (rnDeriv (r • ν) μ)
= (r • ν).singularPart μ + r • withDensity μ (rnDeriv ν μ) by
rwa [Measure.add_right_inj] at this
rw [← (r • ν).haveLebesgueDecomposition_add μ, singularPart_smul, ← smul_add,
← ν.haveLebesgueDecomposition_add μ]
· exact (measurable_rnDeriv _ _).aemeasurable
· exact (measurable_rnDeriv _ _).aemeasurable.const_smul _
· exact (lintegral_rnDeriv_lt_top (r • ν) μ).ne
/-- Radon-Nikodym derivative of the scalar multiple of a measure.
See also `rnDeriv_smul_left_of_ne_top'`, which requires sigma-finite `ν` and `μ`. -/
theorem rnDeriv_smul_left_of_ne_top (ν μ : Measure α) [IsFiniteMeasure ν]
[ν.HaveLebesgueDecomposition μ] {r : ℝ≥0∞} (hr : r ≠ ∞) :
(r • ν).rnDeriv μ =ᵐ[μ] r • ν.rnDeriv μ := by
have h : (r.toNNReal • ν).rnDeriv μ =ᵐ[μ] r.toNNReal • ν.rnDeriv μ :=
rnDeriv_smul_left ν μ r.toNNReal
simpa [ENNReal.smul_def, ENNReal.coe_toNNReal hr] using h
/-- Radon-Nikodym derivative with respect to the scalar multiple of a measure.
See also `rnDeriv_smul_right'`, which requires sigma-finite `ν` and `μ`. -/
theorem rnDeriv_smul_right (ν μ : Measure α) [IsFiniteMeasure ν]
[ν.HaveLebesgueDecomposition μ] {r : ℝ≥0} (hr : r ≠ 0) :
ν.rnDeriv (r • μ) =ᵐ[μ] r⁻¹ • ν.rnDeriv μ := by
refine (absolutelyContinuous_smul <| ENNReal.coe_ne_zero.2 hr).ae_le
(?_ : ν.rnDeriv (r • μ) =ᵐ[r • μ] r⁻¹ • ν.rnDeriv μ)
rw [← withDensity_eq_iff]
rotate_left
· exact (measurable_rnDeriv _ _).aemeasurable
· exact (measurable_rnDeriv _ _).aemeasurable.const_smul _
· exact (lintegral_rnDeriv_lt_top ν _).ne
· simp_rw [ENNReal.smul_def]
rw [withDensity_smul _ (measurable_rnDeriv _ _)]
suffices ν.singularPart (r • μ) + withDensity (r • μ) (rnDeriv ν (r • μ))
= ν.singularPart (r • μ) + r⁻¹ • withDensity (r • μ) (rnDeriv ν μ) by
rwa [add_right_inj] at this
rw [← ν.haveLebesgueDecomposition_add (r • μ), singularPart_smul_right _ _ _ hr,
ENNReal.smul_def r, withDensity_smul_measure, ← ENNReal.smul_def, ← smul_assoc,
smul_eq_mul, inv_mul_cancel hr, one_smul]
exact ν.haveLebesgueDecomposition_add μ
/-- Radon-Nikodym derivative with respect to the scalar multiple of a measure.
See also `rnDeriv_smul_right_of_ne_top'`, which requires sigma-finite `ν` and `μ`. -/
theorem rnDeriv_smul_right_of_ne_top (ν μ : Measure α) [IsFiniteMeasure ν]
[ν.HaveLebesgueDecomposition μ] {r : ℝ≥0∞} (hr : r ≠ 0) (hr_ne_top : r ≠ ∞) :
ν.rnDeriv (r • μ) =ᵐ[μ] r⁻¹ • ν.rnDeriv μ := by
have h : ν.rnDeriv (r.toNNReal • μ) =ᵐ[μ] r.toNNReal⁻¹ • ν.rnDeriv μ := by
refine rnDeriv_smul_right ν μ ?_
rw [ne_eq, ENNReal.toNNReal_eq_zero_iff]
simp [hr, hr_ne_top]
have : (r.toNNReal)⁻¹ • rnDeriv ν μ = r⁻¹ • rnDeriv ν μ := by
ext x
simp only [Pi.smul_apply, ENNReal.smul_def, ne_eq, smul_eq_mul]
rw [ENNReal.coe_inv, ENNReal.coe_toNNReal hr_ne_top]
rw [ne_eq, ENNReal.toNNReal_eq_zero_iff]
simp [hr, hr_ne_top]
simp_rw [this, ENNReal.smul_def, ENNReal.coe_toNNReal hr_ne_top] at h
exact h
/-- Radon-Nikodym derivative of a sum of two measures.
See also `rnDeriv_add'`, which requires sigma-finite `ν₁`, `ν₂` and `μ`. -/
lemma rnDeriv_add (ν₁ ν₂ μ : Measure α) [IsFiniteMeasure ν₁] [IsFiniteMeasure ν₂]
[ν₁.HaveLebesgueDecomposition μ] [ν₂.HaveLebesgueDecomposition μ]
[(ν₁ + ν₂).HaveLebesgueDecomposition μ] :
(ν₁ + ν₂).rnDeriv μ =ᵐ[μ] ν₁.rnDeriv μ + ν₂.rnDeriv μ := by
rw [← withDensity_eq_iff]
· suffices (ν₁ + ν₂).singularPart μ + μ.withDensity ((ν₁ + ν₂).rnDeriv μ)
= (ν₁ + ν₂).singularPart μ + μ.withDensity (ν₁.rnDeriv μ + ν₂.rnDeriv μ) by
rwa [add_right_inj] at this
rw [← (ν₁ + ν₂).haveLebesgueDecomposition_add μ, singularPart_add,
withDensity_add_left (measurable_rnDeriv _ _), add_assoc,
add_comm (ν₂.singularPart μ), add_assoc, add_comm _ (ν₂.singularPart μ),
← ν₂.haveLebesgueDecomposition_add μ, ← add_assoc, ← ν₁.haveLebesgueDecomposition_add μ]
· exact (measurable_rnDeriv _ _).aemeasurable
· exact ((measurable_rnDeriv _ _).add (measurable_rnDeriv _ _)).aemeasurable
· exact (lintegral_rnDeriv_lt_top (ν₁ + ν₂) μ).ne
open VectorMeasure SignedMeasure
/-- If two finite measures `μ` and `ν` are not mutually singular, there exists some `ε > 0` and
a measurable set `E`, such that `ν(E) > 0` and `E` is positive with respect to `μ - εν`.
This lemma is useful for the Lebesgue decomposition theorem. -/
theorem exists_positive_of_not_mutuallySingular (μ ν : Measure α) [IsFiniteMeasure μ]
[IsFiniteMeasure ν] (h : ¬μ ⟂ₘ ν) :
∃ ε : ℝ≥0, 0 < ε ∧
∃ E : Set α,
MeasurableSet E ∧ 0 < ν E ∧ 0 ≤[E] μ.toSignedMeasure - (ε • ν).toSignedMeasure := by
-- for all `n : ℕ`, obtain the Hahn decomposition for `μ - (1 / n) ν`
have :
∀ n : ℕ, ∃ i : Set α,
MeasurableSet i ∧
0 ≤[i] μ.toSignedMeasure - ((1 / (n + 1) : ℝ≥0) • ν).toSignedMeasure ∧
μ.toSignedMeasure - ((1 / (n + 1) : ℝ≥0) • ν).toSignedMeasure ≤[iᶜ] 0 := by
intro; exact exists_compl_positive_negative _
choose f hf₁ hf₂ hf₃ using this
-- set `A` to be the intersection of all the negative parts of obtained Hahn decompositions
-- and we show that `μ A = 0`
let A := ⋂ n, (f n)ᶜ
have hAmeas : MeasurableSet A := MeasurableSet.iInter fun n ↦ (hf₁ n).compl
have hA₂ : ∀ n : ℕ, μ.toSignedMeasure - ((1 / (n + 1) : ℝ≥0) • ν).toSignedMeasure ≤[A] 0 := by
intro n; exact restrict_le_restrict_subset _ _ (hf₁ n).compl (hf₃ n) (iInter_subset _ _)
have hA₃ : ∀ n : ℕ, μ A ≤ (1 / (n + 1) : ℝ≥0) * ν A := by
intro n
have := nonpos_of_restrict_le_zero _ (hA₂ n)
rwa [toSignedMeasure_sub_apply hAmeas, sub_nonpos, ENNReal.toReal_le_toReal] at this
exacts [measure_ne_top _ _, measure_ne_top _ _]
have hμ : μ A = 0 := by
lift μ A to ℝ≥0 using measure_ne_top _ _ with μA
lift ν A to ℝ≥0 using measure_ne_top _ _ with νA
rw [ENNReal.coe_eq_zero]
by_cases hb : 0 < νA
· suffices ∀ b, 0 < b → μA ≤ b by
by_contra h
have h' := this (μA / 2) (half_pos (zero_lt_iff.2 h))
rw [← @Classical.not_not (μA ≤ μA / 2)] at h'
exact h' (not_le.2 (NNReal.half_lt_self h))
intro c hc
have : ∃ n : ℕ, 1 / (n + 1 : ℝ) < c * (νA : ℝ)⁻¹ := by
refine exists_nat_one_div_lt ?_
positivity
rcases this with ⟨n, hn⟩
have hb₁ : (0 : ℝ) < (νA : ℝ)⁻¹ := by rw [_root_.inv_pos]; exact hb
have h' : 1 / (↑n + 1) * νA < c := by
rw [← NNReal.coe_lt_coe, ← mul_lt_mul_right hb₁, NNReal.coe_mul, mul_assoc, ←
NNReal.coe_inv, ← NNReal.coe_mul, _root_.mul_inv_cancel, ← NNReal.coe_mul, mul_one,
NNReal.coe_inv]
· exact hn
· exact hb.ne'
refine le_trans ?_ h'.le
rw [← ENNReal.coe_le_coe, ENNReal.coe_mul]
exact hA₃ n
· rw [not_lt, le_zero_iff] at hb
specialize hA₃ 0
simp? [hb] at hA₃ says
simp only [CharP.cast_eq_zero, zero_add, ne_eq, one_ne_zero, not_false_eq_true, div_self,
ENNReal.coe_one, hb, ENNReal.coe_zero, mul_zero, nonpos_iff_eq_zero,
ENNReal.coe_eq_zero] at hA₃
assumption
-- since `μ` and `ν` are not mutually singular, `μ A = 0` implies `ν Aᶜ > 0`
rw [MutuallySingular] at h; push_neg at h
have := h _ hAmeas hμ
simp_rw [A, compl_iInter, compl_compl] at this
-- as `Aᶜ = ⋃ n, f n`, `ν Aᶜ > 0` implies there exists some `n` such that `ν (f n) > 0`
obtain ⟨n, hn⟩ := exists_measure_pos_of_not_measure_iUnion_null this
-- thus, choosing `f n` as the set `E` suffices
exact ⟨1 / (n + 1), by simp, f n, hf₁ n, hn, hf₂ n⟩
#align measure_theory.measure.exists_positive_of_not_mutually_singular MeasureTheory.Measure.exists_positive_of_not_mutuallySingular
namespace LebesgueDecomposition
/-- Given two measures `μ` and `ν`, `measurableLE μ ν` is the set of measurable
functions `f`, such that, for all measurable sets `A`, `∫⁻ x in A, f x ∂μ ≤ ν A`.
This is useful for the Lebesgue decomposition theorem. -/
def measurableLE (μ ν : Measure α) : Set (α → ℝ≥0∞) :=
{f | Measurable f ∧ ∀ (A : Set α), MeasurableSet A → (∫⁻ x in A, f x ∂μ) ≤ ν A}
#align measure_theory.measure.lebesgue_decomposition.measurable_le MeasureTheory.Measure.LebesgueDecomposition.measurableLE
theorem zero_mem_measurableLE : (0 : α → ℝ≥0∞) ∈ measurableLE μ ν :=
⟨measurable_zero, fun A _ ↦ by simp⟩
#align measure_theory.measure.lebesgue_decomposition.zero_mem_measurable_le MeasureTheory.Measure.LebesgueDecomposition.zero_mem_measurableLE
theorem sup_mem_measurableLE {f g : α → ℝ≥0∞} (hf : f ∈ measurableLE μ ν)
(hg : g ∈ measurableLE μ ν) : (fun a ↦ f a ⊔ g a) ∈ measurableLE μ ν := by
simp_rw [ENNReal.sup_eq_max]
refine ⟨Measurable.max hf.1 hg.1, fun A hA ↦ ?_⟩
have h₁ := hA.inter (measurableSet_le hf.1 hg.1)
have h₂ := hA.inter (measurableSet_lt hg.1 hf.1)
rw [set_lintegral_max hf.1 hg.1]
refine (add_le_add (hg.2 _ h₁) (hf.2 _ h₂)).trans_eq ?_
simp only [← not_le, ← compl_setOf, ← diff_eq]
exact measure_inter_add_diff _ (measurableSet_le hf.1 hg.1)
#align measure_theory.measure.lebesgue_decomposition.sup_mem_measurable_le MeasureTheory.Measure.LebesgueDecomposition.sup_mem_measurableLE
theorem iSup_succ_eq_sup {α} (f : ℕ → α → ℝ≥0∞) (m : ℕ) (a : α) :
⨆ (k : ℕ) (_ : k ≤ m + 1), f k a = f m.succ a ⊔ ⨆ (k : ℕ) (_ : k ≤ m), f k a := by
set c := ⨆ (k : ℕ) (_ : k ≤ m + 1), f k a with hc
set d := f m.succ a ⊔ ⨆ (k : ℕ) (_ : k ≤ m), f k a with hd
rw [le_antisymm_iff, hc, hd]
constructor
· refine iSup₂_le fun n hn ↦ ?_
rcases Nat.of_le_succ hn with (h | h)
· exact le_sup_of_le_right (le_iSup₂ (f := fun k (_ : k ≤ m) ↦ f k a) n h)
· exact h ▸ le_sup_left
· refine sup_le ?_ (biSup_mono fun n hn ↦ hn.trans m.le_succ)
exact @le_iSup₂ ℝ≥0∞ ℕ (fun i ↦ i ≤ m + 1) _ _ (m + 1) le_rfl
#align measure_theory.measure.lebesgue_decomposition.supr_succ_eq_sup MeasureTheory.Measure.LebesgueDecomposition.iSup_succ_eq_sup
theorem iSup_mem_measurableLE (f : ℕ → α → ℝ≥0∞) (hf : ∀ n, f n ∈ measurableLE μ ν) (n : ℕ) :
(fun x ↦ ⨆ (k) (_ : k ≤ n), f k x) ∈ measurableLE μ ν := by
induction' n with m hm
· constructor
· simp [(hf 0).1]
· intro A hA; simp [(hf 0).2 A hA]
· have :
(fun a : α ↦ ⨆ (k : ℕ) (_ : k ≤ m + 1), f k a) = fun a ↦
f m.succ a ⊔ ⨆ (k : ℕ) (_ : k ≤ m), f k a :=
funext fun _ ↦ iSup_succ_eq_sup _ _ _
refine ⟨measurable_iSup fun n ↦ Measurable.iSup_Prop _ (hf n).1, fun A hA ↦ ?_⟩
rw [this]; exact (sup_mem_measurableLE (hf m.succ) hm).2 A hA
#align measure_theory.measure.lebesgue_decomposition.supr_mem_measurable_le MeasureTheory.Measure.LebesgueDecomposition.iSup_mem_measurableLE
theorem iSup_mem_measurableLE' (f : ℕ → α → ℝ≥0∞) (hf : ∀ n, f n ∈ measurableLE μ ν) (n : ℕ) :
(⨆ (k) (_ : k ≤ n), f k) ∈ measurableLE μ ν := by
convert iSup_mem_measurableLE f hf n
simp
#align measure_theory.measure.lebesgue_decomposition.supr_mem_measurable_le' MeasureTheory.Measure.LebesgueDecomposition.iSup_mem_measurableLE'
section SuprLemmas
--TODO: these statements should be moved elsewhere
theorem iSup_monotone {α : Type*} (f : ℕ → α → ℝ≥0∞) :
Monotone fun n x ↦ ⨆ (k) (_ : k ≤ n), f k x :=
fun _ _ hnm _ ↦ biSup_mono fun _ ↦ ge_trans hnm
#align measure_theory.measure.lebesgue_decomposition.supr_monotone MeasureTheory.Measure.LebesgueDecomposition.iSup_monotone
theorem iSup_monotone' {α : Type*} (f : ℕ → α → ℝ≥0∞) (x : α) :
Monotone fun n ↦ ⨆ (k) (_ : k ≤ n), f k x := fun _ _ hnm ↦ iSup_monotone f hnm x
#align measure_theory.measure.lebesgue_decomposition.supr_monotone' MeasureTheory.Measure.LebesgueDecomposition.iSup_monotone'
theorem iSup_le_le {α : Type*} (f : ℕ → α → ℝ≥0∞) (n k : ℕ) (hk : k ≤ n) :
f k ≤ fun x ↦ ⨆ (k) (_ : k ≤ n), f k x :=
fun x ↦ le_iSup₂ (f := fun k (_ : k ≤ n) ↦ f k x) k hk
#align measure_theory.measure.lebesgue_decomposition.supr_le_le MeasureTheory.Measure.LebesgueDecomposition.iSup_le_le
end SuprLemmas
/-- `measurableLEEval μ ν` is the set of `∫⁻ x, f x ∂μ` for all `f ∈ measurableLE μ ν`. -/
def measurableLEEval (μ ν : Measure α) : Set ℝ≥0∞ :=
(fun f : α → ℝ≥0∞ ↦ ∫⁻ x, f x ∂μ) '' measurableLE μ ν
#align measure_theory.measure.lebesgue_decomposition.measurable_le_eval MeasureTheory.Measure.LebesgueDecomposition.measurableLEEval
end LebesgueDecomposition
open LebesgueDecomposition
/-- Any pair of finite measures `μ` and `ν`, `HaveLebesgueDecomposition`. That is to say,
there exist a measure `ξ` and a measurable function `f`, such that `ξ` is mutually singular
with respect to `ν` and `μ = ξ + ν.withDensity f`.
This is not an instance since this is also shown for the more general σ-finite measures with
`MeasureTheory.Measure.haveLebesgueDecomposition_of_sigmaFinite`. -/
| Mathlib/MeasureTheory/Decomposition/Lebesgue.lean | 833 | 931 | theorem haveLebesgueDecomposition_of_finiteMeasure [IsFiniteMeasure μ] [IsFiniteMeasure ν] :
HaveLebesgueDecomposition μ ν :=
⟨by
have h := @exists_seq_tendsto_sSup _ _ _ _ _ (measurableLEEval ν μ)
⟨0, 0, zero_mem_measurableLE, by simp⟩ (OrderTop.bddAbove _)
choose g _ hg₂ f hf₁ hf₂ using h
-- we set `ξ` to be the supremum of an increasing sequence of functions obtained from above
set ξ := ⨆ (n) (k) (_ : k ≤ n), f k with hξ
-- we see that `ξ` has the largest integral among all functions in `measurableLE`
have hξ₁ : sSup (measurableLEEval ν μ) = ∫⁻ a, ξ a ∂ν := by |
have :=
@lintegral_tendsto_of_tendsto_of_monotone _ _ ν (fun n ↦ ⨆ (k) (_ : k ≤ n), f k)
(⨆ (n) (k) (_ : k ≤ n), f k) ?_ ?_ ?_
· refine tendsto_nhds_unique ?_ this
refine tendsto_of_tendsto_of_tendsto_of_le_of_le hg₂ tendsto_const_nhds ?_ ?_
· intro n; rw [← hf₂ n]
apply lintegral_mono
simp only [iSup_apply, iSup_le_le f n n le_rfl]
· intro n
exact le_sSup ⟨⨆ (k : ℕ) (_ : k ≤ n), f k, iSup_mem_measurableLE' _ hf₁ _, rfl⟩
· intro n
refine Measurable.aemeasurable ?_
convert (iSup_mem_measurableLE _ hf₁ n).1
simp
· refine Filter.eventually_of_forall fun a ↦ ?_
simp [iSup_monotone' f _]
· refine Filter.eventually_of_forall fun a ↦ ?_
simp [tendsto_atTop_iSup (iSup_monotone' f a)]
have hξm : Measurable ξ := by
convert measurable_iSup fun n ↦ (iSup_mem_measurableLE _ hf₁ n).1
simp [hξ]
-- `ξ` is the `f` in the theorem statement and we set `μ₁` to be `μ - ν.withDensity ξ`
-- since we need `μ₁ + ν.withDensity ξ = μ`
set μ₁ := μ - ν.withDensity ξ with hμ₁
have hle : ν.withDensity ξ ≤ μ := by
refine le_iff.2 fun B hB ↦ ?_
rw [hξ, withDensity_apply _ hB]
simp_rw [iSup_apply]
rw [lintegral_iSup (fun i ↦ (iSup_mem_measurableLE _ hf₁ i).1) (iSup_monotone _)]
exact iSup_le fun i ↦ (iSup_mem_measurableLE _ hf₁ i).2 B hB
have : IsFiniteMeasure (ν.withDensity ξ) := by
refine isFiniteMeasure_withDensity ?_
have hle' := hle univ
rw [withDensity_apply _ MeasurableSet.univ, Measure.restrict_univ] at hle'
exact ne_top_of_le_ne_top (measure_ne_top _ _) hle'
refine ⟨⟨μ₁, ξ⟩, hξm, ?_, ?_⟩
· by_contra h
-- if they are not mutually singular, then from `exists_positive_of_not_mutuallySingular`,
-- there exists some `ε > 0` and a measurable set `E`, such that `μ(E) > 0` and `E` is
-- positive with respect to `ν - εμ`
obtain ⟨ε, hε₁, E, hE₁, hE₂, hE₃⟩ := exists_positive_of_not_mutuallySingular μ₁ ν h
simp_rw [hμ₁] at hE₃
have hξle : ∀ A, MeasurableSet A → (∫⁻ a in A, ξ a ∂ν) ≤ μ A := by
intro A hA; rw [hξ]
simp_rw [iSup_apply]
rw [lintegral_iSup (fun n ↦ (iSup_mem_measurableLE _ hf₁ n).1) (iSup_monotone _)]
exact iSup_le fun n ↦ (iSup_mem_measurableLE _ hf₁ n).2 A hA
-- since `E` is positive, we have `∫⁻ a in A ∩ E, ε + ξ a ∂ν ≤ μ (A ∩ E)` for all `A`
have hε₂ : ∀ A : Set α, MeasurableSet A → (∫⁻ a in A ∩ E, ε + ξ a ∂ν) ≤ μ (A ∩ E) := by
intro A hA
have := subset_le_of_restrict_le_restrict _ _ hE₁ hE₃ A.inter_subset_right
rwa [zero_apply, toSignedMeasure_sub_apply (hA.inter hE₁),
Measure.sub_apply (hA.inter hE₁) hle,
ENNReal.toReal_sub_of_le _ (measure_ne_top _ _), sub_nonneg, le_sub_iff_add_le,
← ENNReal.toReal_add, ENNReal.toReal_le_toReal, Measure.coe_smul, Pi.smul_apply,
withDensity_apply _ (hA.inter hE₁), show ε • ν (A ∩ E) = (ε : ℝ≥0∞) * ν (A ∩ E) by rfl,
← set_lintegral_const, ← lintegral_add_left measurable_const] at this
· rw [Ne, ENNReal.add_eq_top, not_or]
exact ⟨measure_ne_top _ _, measure_ne_top _ _⟩
· exact measure_ne_top _ _
· exact measure_ne_top _ _
· exact measure_ne_top _ _
· rw [withDensity_apply _ (hA.inter hE₁)]
exact hξle (A ∩ E) (hA.inter hE₁)
-- from this, we can show `ξ + ε * E.indicator` is a function in `measurableLE` with
-- integral greater than `ξ`
have hξε : (ξ + E.indicator fun _ ↦ (ε : ℝ≥0∞)) ∈ measurableLE ν μ := by
refine ⟨Measurable.add hξm (Measurable.indicator measurable_const hE₁), fun A hA ↦ ?_⟩
have :
(∫⁻ a in A, (ξ + E.indicator fun _ ↦ (ε : ℝ≥0∞)) a ∂ν) =
(∫⁻ a in A ∩ E, ε + ξ a ∂ν) + ∫⁻ a in A \ E, ξ a ∂ν := by
simp only [lintegral_add_left measurable_const, lintegral_add_left hξm,
set_lintegral_const, add_assoc, lintegral_inter_add_diff _ _ hE₁, Pi.add_apply,
lintegral_indicator _ hE₁, restrict_apply hE₁]
rw [inter_comm, add_comm]
rw [this, ← measure_inter_add_diff A hE₁]
exact add_le_add (hε₂ A hA) (hξle (A \ E) (hA.diff hE₁))
have : (∫⁻ a, ξ a + E.indicator (fun _ ↦ (ε : ℝ≥0∞)) a ∂ν) ≤ sSup (measurableLEEval ν μ) :=
le_sSup ⟨ξ + E.indicator fun _ ↦ (ε : ℝ≥0∞), hξε, rfl⟩
-- but this contradicts the maximality of `∫⁻ x, ξ x ∂ν`
refine not_lt.2 this ?_
rw [hξ₁, lintegral_add_left hξm, lintegral_indicator _ hE₁, set_lintegral_const]
refine ENNReal.lt_add_right ?_ (ENNReal.mul_pos_iff.2 ⟨ENNReal.coe_pos.2 hε₁, hE₂⟩).ne'
have := measure_ne_top (ν.withDensity ξ) univ
rwa [withDensity_apply _ MeasurableSet.univ, Measure.restrict_univ] at this
-- since `ν.withDensity ξ ≤ μ`, it is clear that `μ = μ₁ + ν.withDensity ξ`
· rw [hμ₁]; ext1 A hA
rw [Measure.coe_add, Pi.add_apply, Measure.sub_apply hA hle, add_comm,
add_tsub_cancel_of_le (hle A)]⟩
|
/-
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Floris van Doorn
-/
import Mathlib.Geometry.Manifold.ChartedSpace
#align_import geometry.manifold.local_invariant_properties from "leanprover-community/mathlib"@"431589bce478b2229eba14b14a283250428217db"
/-!
# Local properties invariant under a groupoid
We study properties of a triple `(g, s, x)` where `g` is a function between two spaces `H` and `H'`,
`s` is a subset of `H` and `x` is a point of `H`. Our goal is to register how such a property
should behave to make sense in charted spaces modelled on `H` and `H'`.
The main examples we have in mind are the properties "`g` is differentiable at `x` within `s`", or
"`g` is smooth at `x` within `s`". We want to develop general results that, when applied in these
specific situations, say that the notion of smooth function in a manifold behaves well under
restriction, intersection, is local, and so on.
## Main definitions
* `LocalInvariantProp G G' P` says that a property `P` of a triple `(g, s, x)` is local, and
invariant under composition by elements of the groupoids `G` and `G'` of `H` and `H'`
respectively.
* `ChartedSpace.LiftPropWithinAt` (resp. `LiftPropAt`, `LiftPropOn` and `LiftProp`):
given a property `P` of `(g, s, x)` where `g : H → H'`, define the corresponding property
for functions `M → M'` where `M` and `M'` are charted spaces modelled respectively on `H` and
`H'`. We define these properties within a set at a point, or at a point, or on a set, or in the
whole space. This lifting process (obtained by restricting to suitable chart domains) can always
be done, but it only behaves well under locality and invariance assumptions.
Given `hG : LocalInvariantProp G G' P`, we deduce many properties of the lifted property on the
charted spaces. For instance, `hG.liftPropWithinAt_inter` says that `P g s x` is equivalent to
`P g (s ∩ t) x` whenever `t` is a neighborhood of `x`.
## Implementation notes
We do not use dot notation for properties of the lifted property. For instance, we have
`hG.liftPropWithinAt_congr` saying that if `LiftPropWithinAt P g s x` holds, and `g` and `g'`
coincide on `s`, then `LiftPropWithinAt P g' s x` holds. We can't call it
`LiftPropWithinAt.congr` as it is in the namespace associated to `LocalInvariantProp`, not
in the one for `LiftPropWithinAt`.
-/
noncomputable section
open scoped Classical
open Manifold Topology
open Set Filter TopologicalSpace
variable {H M H' M' X : Type*}
variable [TopologicalSpace H] [TopologicalSpace M] [ChartedSpace H M]
variable [TopologicalSpace H'] [TopologicalSpace M'] [ChartedSpace H' M']
variable [TopologicalSpace X]
namespace StructureGroupoid
variable (G : StructureGroupoid H) (G' : StructureGroupoid H')
/-- Structure recording good behavior of a property of a triple `(f, s, x)` where `f` is a function,
`s` a set and `x` a point. Good behavior here means locality and invariance under given groupoids
(both in the source and in the target). Given such a good behavior, the lift of this property
to charted spaces admitting these groupoids will inherit the good behavior. -/
structure LocalInvariantProp (P : (H → H') → Set H → H → Prop) : Prop where
is_local : ∀ {s x u} {f : H → H'}, IsOpen u → x ∈ u → (P f s x ↔ P f (s ∩ u) x)
right_invariance' : ∀ {s x f} {e : PartialHomeomorph H H},
e ∈ G → x ∈ e.source → P f s x → P (f ∘ e.symm) (e.symm ⁻¹' s) (e x)
congr_of_forall : ∀ {s x} {f g : H → H'}, (∀ y ∈ s, f y = g y) → f x = g x → P f s x → P g s x
left_invariance' : ∀ {s x f} {e' : PartialHomeomorph H' H'},
e' ∈ G' → s ⊆ f ⁻¹' e'.source → f x ∈ e'.source → P f s x → P (e' ∘ f) s x
#align structure_groupoid.local_invariant_prop StructureGroupoid.LocalInvariantProp
variable {G G'} {P : (H → H') → Set H → H → Prop} {s t u : Set H} {x : H}
variable (hG : G.LocalInvariantProp G' P)
namespace LocalInvariantProp
theorem congr_set {s t : Set H} {x : H} {f : H → H'} (hu : s =ᶠ[𝓝 x] t) : P f s x ↔ P f t x := by
obtain ⟨o, host, ho, hxo⟩ := mem_nhds_iff.mp hu.mem_iff
simp_rw [subset_def, mem_setOf, ← and_congr_left_iff, ← mem_inter_iff, ← Set.ext_iff] at host
rw [hG.is_local ho hxo, host, ← hG.is_local ho hxo]
#align structure_groupoid.local_invariant_prop.congr_set StructureGroupoid.LocalInvariantProp.congr_set
theorem is_local_nhds {s u : Set H} {x : H} {f : H → H'} (hu : u ∈ 𝓝[s] x) :
P f s x ↔ P f (s ∩ u) x :=
hG.congr_set <| mem_nhdsWithin_iff_eventuallyEq.mp hu
#align structure_groupoid.local_invariant_prop.is_local_nhds StructureGroupoid.LocalInvariantProp.is_local_nhds
theorem congr_iff_nhdsWithin {s : Set H} {x : H} {f g : H → H'} (h1 : f =ᶠ[𝓝[s] x] g)
(h2 : f x = g x) : P f s x ↔ P g s x := by
simp_rw [hG.is_local_nhds h1]
exact ⟨hG.congr_of_forall (fun y hy ↦ hy.2) h2, hG.congr_of_forall (fun y hy ↦ hy.2.symm) h2.symm⟩
#align structure_groupoid.local_invariant_prop.congr_iff_nhds_within StructureGroupoid.LocalInvariantProp.congr_iff_nhdsWithin
theorem congr_nhdsWithin {s : Set H} {x : H} {f g : H → H'} (h1 : f =ᶠ[𝓝[s] x] g) (h2 : f x = g x)
(hP : P f s x) : P g s x :=
(hG.congr_iff_nhdsWithin h1 h2).mp hP
#align structure_groupoid.local_invariant_prop.congr_nhds_within StructureGroupoid.LocalInvariantProp.congr_nhdsWithin
theorem congr_nhdsWithin' {s : Set H} {x : H} {f g : H → H'} (h1 : f =ᶠ[𝓝[s] x] g) (h2 : f x = g x)
(hP : P g s x) : P f s x :=
(hG.congr_iff_nhdsWithin h1 h2).mpr hP
#align structure_groupoid.local_invariant_prop.congr_nhds_within' StructureGroupoid.LocalInvariantProp.congr_nhdsWithin'
theorem congr_iff {s : Set H} {x : H} {f g : H → H'} (h : f =ᶠ[𝓝 x] g) : P f s x ↔ P g s x :=
hG.congr_iff_nhdsWithin (mem_nhdsWithin_of_mem_nhds h) (mem_of_mem_nhds h : _)
#align structure_groupoid.local_invariant_prop.congr_iff StructureGroupoid.LocalInvariantProp.congr_iff
theorem congr {s : Set H} {x : H} {f g : H → H'} (h : f =ᶠ[𝓝 x] g) (hP : P f s x) : P g s x :=
(hG.congr_iff h).mp hP
#align structure_groupoid.local_invariant_prop.congr StructureGroupoid.LocalInvariantProp.congr
theorem congr' {s : Set H} {x : H} {f g : H → H'} (h : f =ᶠ[𝓝 x] g) (hP : P g s x) : P f s x :=
hG.congr h.symm hP
#align structure_groupoid.local_invariant_prop.congr' StructureGroupoid.LocalInvariantProp.congr'
theorem left_invariance {s : Set H} {x : H} {f : H → H'} {e' : PartialHomeomorph H' H'}
(he' : e' ∈ G') (hfs : ContinuousWithinAt f s x) (hxe' : f x ∈ e'.source) :
P (e' ∘ f) s x ↔ P f s x := by
have h2f := hfs.preimage_mem_nhdsWithin (e'.open_source.mem_nhds hxe')
have h3f :=
((e'.continuousAt hxe').comp_continuousWithinAt hfs).preimage_mem_nhdsWithin <|
e'.symm.open_source.mem_nhds <| e'.mapsTo hxe'
constructor
· intro h
rw [hG.is_local_nhds h3f] at h
have h2 := hG.left_invariance' (G'.symm he') inter_subset_right (e'.mapsTo hxe') h
rw [← hG.is_local_nhds h3f] at h2
refine hG.congr_nhdsWithin ?_ (e'.left_inv hxe') h2
exact eventually_of_mem h2f fun x' ↦ e'.left_inv
· simp_rw [hG.is_local_nhds h2f]
exact hG.left_invariance' he' inter_subset_right hxe'
#align structure_groupoid.local_invariant_prop.left_invariance StructureGroupoid.LocalInvariantProp.left_invariance
theorem right_invariance {s : Set H} {x : H} {f : H → H'} {e : PartialHomeomorph H H} (he : e ∈ G)
(hxe : x ∈ e.source) : P (f ∘ e.symm) (e.symm ⁻¹' s) (e x) ↔ P f s x := by
refine ⟨fun h ↦ ?_, hG.right_invariance' he hxe⟩
have := hG.right_invariance' (G.symm he) (e.mapsTo hxe) h
rw [e.symm_symm, e.left_inv hxe] at this
refine hG.congr ?_ ((hG.congr_set ?_).mp this)
· refine eventually_of_mem (e.open_source.mem_nhds hxe) fun x' hx' ↦ ?_
simp_rw [Function.comp_apply, e.left_inv hx']
· rw [eventuallyEq_set]
refine eventually_of_mem (e.open_source.mem_nhds hxe) fun x' hx' ↦ ?_
simp_rw [mem_preimage, e.left_inv hx']
#align structure_groupoid.local_invariant_prop.right_invariance StructureGroupoid.LocalInvariantProp.right_invariance
end LocalInvariantProp
end StructureGroupoid
namespace ChartedSpace
/-- Given a property of germs of functions and sets in the model space, then one defines
a corresponding property in a charted space, by requiring that it holds at the preferred chart at
this point. (When the property is local and invariant, it will in fact hold using any chart, see
`liftPropWithinAt_indep_chart`). We require continuity in the lifted property, as otherwise one
single chart might fail to capture the behavior of the function.
-/
@[mk_iff liftPropWithinAt_iff']
structure LiftPropWithinAt (P : (H → H') → Set H → H → Prop) (f : M → M') (s : Set M) (x : M) :
Prop where
continuousWithinAt : ContinuousWithinAt f s x
prop : P (chartAt H' (f x) ∘ f ∘ (chartAt H x).symm) ((chartAt H x).symm ⁻¹' s) (chartAt H x x)
#align charted_space.lift_prop_within_at ChartedSpace.LiftPropWithinAt
/-- Given a property of germs of functions and sets in the model space, then one defines
a corresponding property of functions on sets in a charted space, by requiring that it holds
around each point of the set, in the preferred charts. -/
def LiftPropOn (P : (H → H') → Set H → H → Prop) (f : M → M') (s : Set M) :=
∀ x ∈ s, LiftPropWithinAt P f s x
#align charted_space.lift_prop_on ChartedSpace.LiftPropOn
/-- Given a property of germs of functions and sets in the model space, then one defines
a corresponding property of a function at a point in a charted space, by requiring that it holds
in the preferred chart. -/
def LiftPropAt (P : (H → H') → Set H → H → Prop) (f : M → M') (x : M) :=
LiftPropWithinAt P f univ x
#align charted_space.lift_prop_at ChartedSpace.LiftPropAt
theorem liftPropAt_iff {P : (H → H') → Set H → H → Prop} {f : M → M'} {x : M} :
LiftPropAt P f x ↔
ContinuousAt f x ∧ P (chartAt H' (f x) ∘ f ∘ (chartAt H x).symm) univ (chartAt H x x) := by
rw [LiftPropAt, liftPropWithinAt_iff', continuousWithinAt_univ, preimage_univ]
#align charted_space.lift_prop_at_iff ChartedSpace.liftPropAt_iff
/-- Given a property of germs of functions and sets in the model space, then one defines
a corresponding property of a function in a charted space, by requiring that it holds
in the preferred chart around every point. -/
def LiftProp (P : (H → H') → Set H → H → Prop) (f : M → M') :=
∀ x, LiftPropAt P f x
#align charted_space.lift_prop ChartedSpace.LiftProp
theorem liftProp_iff {P : (H → H') → Set H → H → Prop} {f : M → M'} :
LiftProp P f ↔
Continuous f ∧ ∀ x, P (chartAt H' (f x) ∘ f ∘ (chartAt H x).symm) univ (chartAt H x x) := by
simp_rw [LiftProp, liftPropAt_iff, forall_and, continuous_iff_continuousAt]
#align charted_space.lift_prop_iff ChartedSpace.liftProp_iff
end ChartedSpace
open ChartedSpace
namespace StructureGroupoid
variable {G : StructureGroupoid H} {G' : StructureGroupoid H'} {e e' : PartialHomeomorph M H}
{f f' : PartialHomeomorph M' H'} {P : (H → H') → Set H → H → Prop} {g g' : M → M'} {s t : Set M}
{x : M} {Q : (H → H) → Set H → H → Prop}
theorem liftPropWithinAt_univ : LiftPropWithinAt P g univ x ↔ LiftPropAt P g x := Iff.rfl
#align structure_groupoid.lift_prop_within_at_univ StructureGroupoid.liftPropWithinAt_univ
theorem liftPropOn_univ : LiftPropOn P g univ ↔ LiftProp P g := by
simp [LiftPropOn, LiftProp, LiftPropAt]
#align structure_groupoid.lift_prop_on_univ StructureGroupoid.liftPropOn_univ
theorem liftPropWithinAt_self {f : H → H'} {s : Set H} {x : H} :
LiftPropWithinAt P f s x ↔ ContinuousWithinAt f s x ∧ P f s x :=
liftPropWithinAt_iff' ..
#align structure_groupoid.lift_prop_within_at_self StructureGroupoid.liftPropWithinAt_self
theorem liftPropWithinAt_self_source {f : H → M'} {s : Set H} {x : H} :
LiftPropWithinAt P f s x ↔ ContinuousWithinAt f s x ∧ P (chartAt H' (f x) ∘ f) s x :=
liftPropWithinAt_iff' ..
#align structure_groupoid.lift_prop_within_at_self_source StructureGroupoid.liftPropWithinAt_self_source
theorem liftPropWithinAt_self_target {f : M → H'} :
LiftPropWithinAt P f s x ↔ ContinuousWithinAt f s x ∧
P (f ∘ (chartAt H x).symm) ((chartAt H x).symm ⁻¹' s) (chartAt H x x) :=
liftPropWithinAt_iff' ..
#align structure_groupoid.lift_prop_within_at_self_target StructureGroupoid.liftPropWithinAt_self_target
namespace LocalInvariantProp
variable (hG : G.LocalInvariantProp G' P)
/-- `LiftPropWithinAt P f s x` is equivalent to a definition where we restrict the set we are
considering to the domain of the charts at `x` and `f x`. -/
theorem liftPropWithinAt_iff {f : M → M'} :
LiftPropWithinAt P f s x ↔
ContinuousWithinAt f s x ∧
P (chartAt H' (f x) ∘ f ∘ (chartAt H x).symm)
((chartAt H x).target ∩ (chartAt H x).symm ⁻¹' (s ∩ f ⁻¹' (chartAt H' (f x)).source))
(chartAt H x x) := by
rw [liftPropWithinAt_iff']
refine and_congr_right fun hf ↦ hG.congr_set ?_
exact PartialHomeomorph.preimage_eventuallyEq_target_inter_preimage_inter hf
(mem_chart_source H x) (chart_source_mem_nhds H' (f x))
#align structure_groupoid.local_invariant_prop.lift_prop_within_at_iff StructureGroupoid.LocalInvariantProp.liftPropWithinAt_iff
theorem liftPropWithinAt_indep_chart_source_aux (g : M → H') (he : e ∈ G.maximalAtlas M)
(xe : x ∈ e.source) (he' : e' ∈ G.maximalAtlas M) (xe' : x ∈ e'.source) :
P (g ∘ e.symm) (e.symm ⁻¹' s) (e x) ↔ P (g ∘ e'.symm) (e'.symm ⁻¹' s) (e' x) := by
rw [← hG.right_invariance (compatible_of_mem_maximalAtlas he he')]
swap; · simp only [xe, xe', mfld_simps]
simp_rw [PartialHomeomorph.trans_apply, e.left_inv xe]
rw [hG.congr_iff]
· refine hG.congr_set ?_
refine (eventually_of_mem ?_ fun y (hy : y ∈ e'.symm ⁻¹' e.source) ↦ ?_).set_eq
· refine (e'.symm.continuousAt <| e'.mapsTo xe').preimage_mem_nhds (e.open_source.mem_nhds ?_)
simp_rw [e'.left_inv xe', xe]
simp_rw [mem_preimage, PartialHomeomorph.coe_trans_symm, PartialHomeomorph.symm_symm,
Function.comp_apply, e.left_inv hy]
· refine ((e'.eventually_nhds' _ xe').mpr <| e.eventually_left_inverse xe).mono fun y hy ↦ ?_
simp only [mfld_simps]
rw [hy]
#align structure_groupoid.local_invariant_prop.lift_prop_within_at_indep_chart_source_aux StructureGroupoid.LocalInvariantProp.liftPropWithinAt_indep_chart_source_aux
theorem liftPropWithinAt_indep_chart_target_aux2 (g : H → M') {x : H} {s : Set H}
(hf : f ∈ G'.maximalAtlas M') (xf : g x ∈ f.source) (hf' : f' ∈ G'.maximalAtlas M')
(xf' : g x ∈ f'.source) (hgs : ContinuousWithinAt g s x) : P (f ∘ g) s x ↔ P (f' ∘ g) s x := by
have hcont : ContinuousWithinAt (f ∘ g) s x := (f.continuousAt xf).comp_continuousWithinAt hgs
rw [← hG.left_invariance (compatible_of_mem_maximalAtlas hf hf') hcont
(by simp only [xf, xf', mfld_simps])]
refine hG.congr_iff_nhdsWithin ?_ (by simp only [xf, mfld_simps])
exact (hgs.eventually <| f.eventually_left_inverse xf).mono fun y ↦ congr_arg f'
#align structure_groupoid.local_invariant_prop.lift_prop_within_at_indep_chart_target_aux2 StructureGroupoid.LocalInvariantProp.liftPropWithinAt_indep_chart_target_aux2
theorem liftPropWithinAt_indep_chart_target_aux {g : X → M'} {e : PartialHomeomorph X H} {x : X}
{s : Set X} (xe : x ∈ e.source) (hf : f ∈ G'.maximalAtlas M') (xf : g x ∈ f.source)
(hf' : f' ∈ G'.maximalAtlas M') (xf' : g x ∈ f'.source) (hgs : ContinuousWithinAt g s x) :
P (f ∘ g ∘ e.symm) (e.symm ⁻¹' s) (e x) ↔ P (f' ∘ g ∘ e.symm) (e.symm ⁻¹' s) (e x) := by
rw [← e.left_inv xe] at xf xf' hgs
refine hG.liftPropWithinAt_indep_chart_target_aux2 (g ∘ e.symm) hf xf hf' xf' ?_
exact hgs.comp (e.symm.continuousAt <| e.mapsTo xe).continuousWithinAt Subset.rfl
#align structure_groupoid.local_invariant_prop.lift_prop_within_at_indep_chart_target_aux StructureGroupoid.LocalInvariantProp.liftPropWithinAt_indep_chart_target_aux
/-- If a property of a germ of function `g` on a pointed set `(s, x)` is invariant under the
structure groupoid (by composition in the source space and in the target space), then
expressing it in charted spaces does not depend on the element of the maximal atlas one uses
both in the source and in the target manifolds, provided they are defined around `x` and `g x`
respectively, and provided `g` is continuous within `s` at `x` (otherwise, the local behavior
of `g` at `x` can not be captured with a chart in the target). -/
theorem liftPropWithinAt_indep_chart_aux (he : e ∈ G.maximalAtlas M) (xe : x ∈ e.source)
(he' : e' ∈ G.maximalAtlas M) (xe' : x ∈ e'.source) (hf : f ∈ G'.maximalAtlas M')
(xf : g x ∈ f.source) (hf' : f' ∈ G'.maximalAtlas M') (xf' : g x ∈ f'.source)
(hgs : ContinuousWithinAt g s x) :
P (f ∘ g ∘ e.symm) (e.symm ⁻¹' s) (e x) ↔ P (f' ∘ g ∘ e'.symm) (e'.symm ⁻¹' s) (e' x) := by
rw [← Function.comp.assoc, hG.liftPropWithinAt_indep_chart_source_aux (f ∘ g) he xe he' xe',
Function.comp.assoc, hG.liftPropWithinAt_indep_chart_target_aux xe' hf xf hf' xf' hgs]
#align structure_groupoid.local_invariant_prop.lift_prop_within_at_indep_chart_aux StructureGroupoid.LocalInvariantProp.liftPropWithinAt_indep_chart_aux
theorem liftPropWithinAt_indep_chart [HasGroupoid M G] [HasGroupoid M' G']
(he : e ∈ G.maximalAtlas M) (xe : x ∈ e.source) (hf : f ∈ G'.maximalAtlas M')
(xf : g x ∈ f.source) :
LiftPropWithinAt P g s x ↔
ContinuousWithinAt g s x ∧ P (f ∘ g ∘ e.symm) (e.symm ⁻¹' s) (e x) := by
simp only [liftPropWithinAt_iff']
exact and_congr_right <|
hG.liftPropWithinAt_indep_chart_aux (chart_mem_maximalAtlas _ _) (mem_chart_source _ _) he xe
(chart_mem_maximalAtlas _ _) (mem_chart_source _ _) hf xf
#align structure_groupoid.local_invariant_prop.lift_prop_within_at_indep_chart StructureGroupoid.LocalInvariantProp.liftPropWithinAt_indep_chart
/-- A version of `liftPropWithinAt_indep_chart`, only for the source. -/
theorem liftPropWithinAt_indep_chart_source [HasGroupoid M G] (he : e ∈ G.maximalAtlas M)
(xe : x ∈ e.source) :
LiftPropWithinAt P g s x ↔ LiftPropWithinAt P (g ∘ e.symm) (e.symm ⁻¹' s) (e x) := by
rw [liftPropWithinAt_self_source, liftPropWithinAt_iff',
e.symm.continuousWithinAt_iff_continuousWithinAt_comp_right xe, e.symm_symm]
refine and_congr Iff.rfl ?_
rw [Function.comp_apply, e.left_inv xe, ← Function.comp.assoc,
hG.liftPropWithinAt_indep_chart_source_aux (chartAt _ (g x) ∘ g) (chart_mem_maximalAtlas G x)
(mem_chart_source _ x) he xe, Function.comp.assoc]
#align structure_groupoid.local_invariant_prop.lift_prop_within_at_indep_chart_source StructureGroupoid.LocalInvariantProp.liftPropWithinAt_indep_chart_source
/-- A version of `liftPropWithinAt_indep_chart`, only for the target. -/
theorem liftPropWithinAt_indep_chart_target [HasGroupoid M' G'] (hf : f ∈ G'.maximalAtlas M')
(xf : g x ∈ f.source) :
LiftPropWithinAt P g s x ↔ ContinuousWithinAt g s x ∧ LiftPropWithinAt P (f ∘ g) s x := by
rw [liftPropWithinAt_self_target, liftPropWithinAt_iff', and_congr_right_iff]
intro hg
simp_rw [(f.continuousAt xf).comp_continuousWithinAt hg, true_and_iff]
exact hG.liftPropWithinAt_indep_chart_target_aux (mem_chart_source _ _)
(chart_mem_maximalAtlas _ _) (mem_chart_source _ _) hf xf hg
#align structure_groupoid.local_invariant_prop.lift_prop_within_at_indep_chart_target StructureGroupoid.LocalInvariantProp.liftPropWithinAt_indep_chart_target
/-- A version of `liftPropWithinAt_indep_chart`, that uses `LiftPropWithinAt` on both sides. -/
theorem liftPropWithinAt_indep_chart' [HasGroupoid M G] [HasGroupoid M' G']
(he : e ∈ G.maximalAtlas M) (xe : x ∈ e.source) (hf : f ∈ G'.maximalAtlas M')
(xf : g x ∈ f.source) :
LiftPropWithinAt P g s x ↔
ContinuousWithinAt g s x ∧ LiftPropWithinAt P (f ∘ g ∘ e.symm) (e.symm ⁻¹' s) (e x) := by
rw [hG.liftPropWithinAt_indep_chart he xe hf xf, liftPropWithinAt_self, and_left_comm,
Iff.comm, and_iff_right_iff_imp]
intro h
have h1 := (e.symm.continuousWithinAt_iff_continuousWithinAt_comp_right xe).mp h.1
have : ContinuousAt f ((g ∘ e.symm) (e x)) := by
simp_rw [Function.comp, e.left_inv xe, f.continuousAt xf]
exact this.comp_continuousWithinAt h1
#align structure_groupoid.local_invariant_prop.lift_prop_within_at_indep_chart' StructureGroupoid.LocalInvariantProp.liftPropWithinAt_indep_chart'
theorem liftPropOn_indep_chart [HasGroupoid M G] [HasGroupoid M' G'] (he : e ∈ G.maximalAtlas M)
(hf : f ∈ G'.maximalAtlas M') (h : LiftPropOn P g s) {y : H}
(hy : y ∈ e.target ∩ e.symm ⁻¹' (s ∩ g ⁻¹' f.source)) :
P (f ∘ g ∘ e.symm) (e.symm ⁻¹' s) y := by
convert ((hG.liftPropWithinAt_indep_chart he (e.symm_mapsTo hy.1) hf hy.2.2).1 (h _ hy.2.1)).2
rw [e.right_inv hy.1]
#align structure_groupoid.local_invariant_prop.lift_prop_on_indep_chart StructureGroupoid.LocalInvariantProp.liftPropOn_indep_chart
theorem liftPropWithinAt_inter' (ht : t ∈ 𝓝[s] x) :
LiftPropWithinAt P g (s ∩ t) x ↔ LiftPropWithinAt P g s x := by
rw [liftPropWithinAt_iff', liftPropWithinAt_iff', continuousWithinAt_inter' ht, hG.congr_set]
simp_rw [eventuallyEq_set, mem_preimage,
(chartAt _ x).eventually_nhds' (fun x ↦ x ∈ s ∩ t ↔ x ∈ s) (mem_chart_source _ x)]
exact (mem_nhdsWithin_iff_eventuallyEq.mp ht).symm.mem_iff
#align structure_groupoid.local_invariant_prop.lift_prop_within_at_inter' StructureGroupoid.LocalInvariantProp.liftPropWithinAt_inter'
theorem liftPropWithinAt_inter (ht : t ∈ 𝓝 x) :
LiftPropWithinAt P g (s ∩ t) x ↔ LiftPropWithinAt P g s x :=
hG.liftPropWithinAt_inter' (mem_nhdsWithin_of_mem_nhds ht)
#align structure_groupoid.local_invariant_prop.lift_prop_within_at_inter StructureGroupoid.LocalInvariantProp.liftPropWithinAt_inter
theorem liftPropAt_of_liftPropWithinAt (h : LiftPropWithinAt P g s x) (hs : s ∈ 𝓝 x) :
LiftPropAt P g x := by
rwa [← univ_inter s, hG.liftPropWithinAt_inter hs] at h
#align structure_groupoid.local_invariant_prop.lift_prop_at_of_lift_prop_within_at StructureGroupoid.LocalInvariantProp.liftPropAt_of_liftPropWithinAt
theorem liftPropWithinAt_of_liftPropAt_of_mem_nhds (h : LiftPropAt P g x) (hs : s ∈ 𝓝 x) :
LiftPropWithinAt P g s x := by
rwa [← univ_inter s, hG.liftPropWithinAt_inter hs]
#align structure_groupoid.local_invariant_prop.lift_prop_within_at_of_lift_prop_at_of_mem_nhds StructureGroupoid.LocalInvariantProp.liftPropWithinAt_of_liftPropAt_of_mem_nhds
theorem liftPropOn_of_locally_liftPropOn
(h : ∀ x ∈ s, ∃ u, IsOpen u ∧ x ∈ u ∧ LiftPropOn P g (s ∩ u)) : LiftPropOn P g s := by
intro x hx
rcases h x hx with ⟨u, u_open, xu, hu⟩
have := hu x ⟨hx, xu⟩
rwa [hG.liftPropWithinAt_inter] at this
exact u_open.mem_nhds xu
#align structure_groupoid.local_invariant_prop.lift_prop_on_of_locally_lift_prop_on StructureGroupoid.LocalInvariantProp.liftPropOn_of_locally_liftPropOn
| Mathlib/Geometry/Manifold/LocalInvariantProperties.lean | 396 | 400 | theorem liftProp_of_locally_liftPropOn (h : ∀ x, ∃ u, IsOpen u ∧ x ∈ u ∧ LiftPropOn P g u) :
LiftProp P g := by |
rw [← liftPropOn_univ]
refine hG.liftPropOn_of_locally_liftPropOn fun x _ ↦ ?_
simp [h x]
|
/-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Analysis.Convex.Between
import Mathlib.Analysis.Convex.Normed
import Mathlib.Analysis.Normed.Group.AddTorsor
#align_import analysis.convex.side from "leanprover-community/mathlib"@"a63928c34ec358b5edcda2bf7513c50052a5230f"
/-!
# Sides of affine subspaces
This file defines notions of two points being on the same or opposite sides of an affine subspace.
## Main definitions
* `s.WSameSide x y`: The points `x` and `y` are weakly on the same side of the affine
subspace `s`.
* `s.SSameSide x y`: The points `x` and `y` are strictly on the same side of the affine
subspace `s`.
* `s.WOppSide x y`: The points `x` and `y` are weakly on opposite sides of the affine
subspace `s`.
* `s.SOppSide x y`: The points `x` and `y` are strictly on opposite sides of the affine
subspace `s`.
-/
variable {R V V' P P' : Type*}
open AffineEquiv AffineMap
namespace AffineSubspace
section StrictOrderedCommRing
variable [StrictOrderedCommRing R] [AddCommGroup V] [Module R V] [AddTorsor V P]
variable [AddCommGroup V'] [Module R V'] [AddTorsor V' P']
/-- The points `x` and `y` are weakly on the same side of `s`. -/
def WSameSide (s : AffineSubspace R P) (x y : P) : Prop :=
∃ᵉ (p₁ ∈ s) (p₂ ∈ s), SameRay R (x -ᵥ p₁) (y -ᵥ p₂)
#align affine_subspace.w_same_side AffineSubspace.WSameSide
/-- The points `x` and `y` are strictly on the same side of `s`. -/
def SSameSide (s : AffineSubspace R P) (x y : P) : Prop :=
s.WSameSide x y ∧ x ∉ s ∧ y ∉ s
#align affine_subspace.s_same_side AffineSubspace.SSameSide
/-- The points `x` and `y` are weakly on opposite sides of `s`. -/
def WOppSide (s : AffineSubspace R P) (x y : P) : Prop :=
∃ᵉ (p₁ ∈ s) (p₂ ∈ s), SameRay R (x -ᵥ p₁) (p₂ -ᵥ y)
#align affine_subspace.w_opp_side AffineSubspace.WOppSide
/-- The points `x` and `y` are strictly on opposite sides of `s`. -/
def SOppSide (s : AffineSubspace R P) (x y : P) : Prop :=
s.WOppSide x y ∧ x ∉ s ∧ y ∉ s
#align affine_subspace.s_opp_side AffineSubspace.SOppSide
theorem WSameSide.map {s : AffineSubspace R P} {x y : P} (h : s.WSameSide x y) (f : P →ᵃ[R] P') :
(s.map f).WSameSide (f x) (f y) := by
rcases h with ⟨p₁, hp₁, p₂, hp₂, h⟩
refine ⟨f p₁, mem_map_of_mem f hp₁, f p₂, mem_map_of_mem f hp₂, ?_⟩
simp_rw [← linearMap_vsub]
exact h.map f.linear
#align affine_subspace.w_same_side.map AffineSubspace.WSameSide.map
theorem _root_.Function.Injective.wSameSide_map_iff {s : AffineSubspace R P} {x y : P}
{f : P →ᵃ[R] P'} (hf : Function.Injective f) :
(s.map f).WSameSide (f x) (f y) ↔ s.WSameSide x y := by
refine ⟨fun h => ?_, fun h => h.map _⟩
rcases h with ⟨fp₁, hfp₁, fp₂, hfp₂, h⟩
rw [mem_map] at hfp₁ hfp₂
rcases hfp₁ with ⟨p₁, hp₁, rfl⟩
rcases hfp₂ with ⟨p₂, hp₂, rfl⟩
refine ⟨p₁, hp₁, p₂, hp₂, ?_⟩
simp_rw [← linearMap_vsub, (f.linear_injective_iff.2 hf).sameRay_map_iff] at h
exact h
#align function.injective.w_same_side_map_iff Function.Injective.wSameSide_map_iff
theorem _root_.Function.Injective.sSameSide_map_iff {s : AffineSubspace R P} {x y : P}
{f : P →ᵃ[R] P'} (hf : Function.Injective f) :
(s.map f).SSameSide (f x) (f y) ↔ s.SSameSide x y := by
simp_rw [SSameSide, hf.wSameSide_map_iff, mem_map_iff_mem_of_injective hf]
#align function.injective.s_same_side_map_iff Function.Injective.sSameSide_map_iff
@[simp]
theorem _root_.AffineEquiv.wSameSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') :
(s.map ↑f).WSameSide (f x) (f y) ↔ s.WSameSide x y :=
(show Function.Injective f.toAffineMap from f.injective).wSameSide_map_iff
#align affine_equiv.w_same_side_map_iff AffineEquiv.wSameSide_map_iff
@[simp]
theorem _root_.AffineEquiv.sSameSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᵃ[R] P') :
(s.map ↑f).SSameSide (f x) (f y) ↔ s.SSameSide x y :=
(show Function.Injective f.toAffineMap from f.injective).sSameSide_map_iff
#align affine_equiv.s_same_side_map_iff AffineEquiv.sSameSide_map_iff
theorem WOppSide.map {s : AffineSubspace R P} {x y : P} (h : s.WOppSide x y) (f : P →ᵃ[R] P') :
(s.map f).WOppSide (f x) (f y) := by
rcases h with ⟨p₁, hp₁, p₂, hp₂, h⟩
refine ⟨f p₁, mem_map_of_mem f hp₁, f p₂, mem_map_of_mem f hp₂, ?_⟩
simp_rw [← linearMap_vsub]
exact h.map f.linear
#align affine_subspace.w_opp_side.map AffineSubspace.WOppSide.map
| Mathlib/Analysis/Convex/Side.lean | 109 | 119 | theorem _root_.Function.Injective.wOppSide_map_iff {s : AffineSubspace R P} {x y : P}
{f : P →ᵃ[R] P'} (hf : Function.Injective f) :
(s.map f).WOppSide (f x) (f y) ↔ s.WOppSide x y := by |
refine ⟨fun h => ?_, fun h => h.map _⟩
rcases h with ⟨fp₁, hfp₁, fp₂, hfp₂, h⟩
rw [mem_map] at hfp₁ hfp₂
rcases hfp₁ with ⟨p₁, hp₁, rfl⟩
rcases hfp₂ with ⟨p₂, hp₂, rfl⟩
refine ⟨p₁, hp₁, p₂, hp₂, ?_⟩
simp_rw [← linearMap_vsub, (f.linear_injective_iff.2 hf).sameRay_map_iff] at h
exact h
|
/-
Copyright (c) 2018 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
-/
import Mathlib.Control.Functor
import Mathlib.Tactic.Common
#align_import control.bifunctor from "leanprover-community/mathlib"@"dc1525fb3ef6eb4348fb1749c302d8abc303d34a"
/-!
# Functors with two arguments
This file defines bifunctors.
A bifunctor is a function `F : Type* → Type* → Type*` along with a bimap which turns `F α β`into
`F α' β'` given two functions `α → α'` and `β → β'`. It further
* respects the identity: `bimap id id = id`
* composes in the obvious way: `(bimap f' g') ∘ (bimap f g) = bimap (f' ∘ f) (g' ∘ g)`
## Main declarations
* `Bifunctor`: A typeclass for the bare bimap of a bifunctor.
* `LawfulBifunctor`: A typeclass asserting this bimap respects the bifunctor laws.
-/
universe u₀ u₁ u₂ v₀ v₁ v₂
open Function
/-- Lawless bifunctor. This typeclass only holds the data for the bimap. -/
class Bifunctor (F : Type u₀ → Type u₁ → Type u₂) where
bimap : ∀ {α α' β β'}, (α → α') → (β → β') → F α β → F α' β'
#align bifunctor Bifunctor
export Bifunctor (bimap)
/-- Bifunctor. This typeclass asserts that a lawless `Bifunctor` is lawful. -/
class LawfulBifunctor (F : Type u₀ → Type u₁ → Type u₂) [Bifunctor F] : Prop where
id_bimap : ∀ {α β} (x : F α β), bimap id id x = x
bimap_bimap :
∀ {α₀ α₁ α₂ β₀ β₁ β₂} (f : α₀ → α₁) (f' : α₁ → α₂) (g : β₀ → β₁) (g' : β₁ → β₂) (x : F α₀ β₀),
bimap f' g' (bimap f g x) = bimap (f' ∘ f) (g' ∘ g) x
#align is_lawful_bifunctor LawfulBifunctor
export LawfulBifunctor (id_bimap bimap_bimap)
attribute [higher_order bimap_id_id] id_bimap
#align is_lawful_bifunctor.bimap_id_id LawfulBifunctor.bimap_id_id
attribute [higher_order bimap_comp_bimap] bimap_bimap
#align is_lawful_bifunctor.bimap_comp_bimap LawfulBifunctor.bimap_comp_bimap
export LawfulBifunctor (bimap_id_id bimap_comp_bimap)
variable {F : Type u₀ → Type u₁ → Type u₂} [Bifunctor F]
namespace Bifunctor
/-- Left map of a bifunctor. -/
abbrev fst {α α' β} (f : α → α') : F α β → F α' β :=
bimap f id
#align bifunctor.fst Bifunctor.fst
/-- Right map of a bifunctor. -/
abbrev snd {α β β'} (f : β → β') : F α β → F α β' :=
bimap id f
#align bifunctor.snd Bifunctor.snd
variable [LawfulBifunctor F]
@[higher_order fst_id]
theorem id_fst : ∀ {α β} (x : F α β), fst id x = x :=
@id_bimap _ _ _
#align bifunctor.id_fst Bifunctor.id_fst
#align bifunctor.fst_id Bifunctor.fst_id
@[higher_order snd_id]
theorem id_snd : ∀ {α β} (x : F α β), snd id x = x :=
@id_bimap _ _ _
#align bifunctor.id_snd Bifunctor.id_snd
#align bifunctor.snd_id Bifunctor.snd_id
@[higher_order fst_comp_fst]
| Mathlib/Control/Bifunctor.lean | 86 | 87 | theorem comp_fst {α₀ α₁ α₂ β} (f : α₀ → α₁) (f' : α₁ → α₂) (x : F α₀ β) :
fst f' (fst f x) = fst (f' ∘ f) x := by | simp [fst, bimap_bimap]
|
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Algebra.MvPolynomial.Rename
#align_import data.mv_polynomial.comap from "leanprover-community/mathlib"@"aba31c938d3243cc671be7091b28a1e0814647ee"
/-!
# `comap` operation on `MvPolynomial`
This file defines the `comap` function on `MvPolynomial`.
`MvPolynomial.comap` is a low-tech example of a map of "algebraic varieties," modulo the fact that
`mathlib` does not yet define varieties.
## Notation
As in other polynomial files, we typically use the notation:
+ `σ : Type*` (indexing the variables)
+ `R : Type*` `[CommSemiring R]` (the coefficients)
-/
namespace MvPolynomial
variable {σ : Type*} {τ : Type*} {υ : Type*} {R : Type*} [CommSemiring R]
/-- Given an algebra hom `f : MvPolynomial σ R →ₐ[R] MvPolynomial τ R`
and a variable evaluation `v : τ → R`,
`comap f v` produces a variable evaluation `σ → R`.
-/
noncomputable def comap (f : MvPolynomial σ R →ₐ[R] MvPolynomial τ R) : (τ → R) → σ → R :=
fun x i => aeval x (f (X i))
#align mv_polynomial.comap MvPolynomial.comap
@[simp]
theorem comap_apply (f : MvPolynomial σ R →ₐ[R] MvPolynomial τ R) (x : τ → R) (i : σ) :
comap f x i = aeval x (f (X i)) :=
rfl
#align mv_polynomial.comap_apply MvPolynomial.comap_apply
@[simp]
| Mathlib/Algebra/MvPolynomial/Comap.lean | 48 | 50 | theorem comap_id_apply (x : σ → R) : comap (AlgHom.id R (MvPolynomial σ R)) x = x := by |
funext i
simp only [comap, AlgHom.id_apply, id, aeval_X]
|
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Eric Wieser
-/
import Mathlib.Algebra.Quaternion
import Mathlib.Analysis.InnerProductSpace.Basic
import Mathlib.Analysis.InnerProductSpace.PiL2
import Mathlib.Topology.Algebra.Algebra
#align_import analysis.quaternion from "leanprover-community/mathlib"@"07992a1d1f7a4176c6d3f160209608be4e198566"
/-!
# Quaternions as a normed algebra
In this file we define the following structures on the space `ℍ := ℍ[ℝ]` of quaternions:
* inner product space;
* normed ring;
* normed space over `ℝ`.
We show that the norm on `ℍ[ℝ]` agrees with the euclidean norm of its components.
## Notation
The following notation is available with `open Quaternion` or `open scoped Quaternion`:
* `ℍ` : quaternions
## Tags
quaternion, normed ring, normed space, normed algebra
-/
@[inherit_doc] scoped[Quaternion] notation "ℍ" => Quaternion ℝ
open scoped RealInnerProductSpace
namespace Quaternion
instance : Inner ℝ ℍ :=
⟨fun a b => (a * star b).re⟩
theorem inner_self (a : ℍ) : ⟪a, a⟫ = normSq a :=
rfl
#align quaternion.inner_self Quaternion.inner_self
theorem inner_def (a b : ℍ) : ⟪a, b⟫ = (a * star b).re :=
rfl
#align quaternion.inner_def Quaternion.inner_def
noncomputable instance : NormedAddCommGroup ℍ :=
@InnerProductSpace.Core.toNormedAddCommGroup ℝ ℍ _ _ _
{ toInner := inferInstance
conj_symm := fun x y => by simp [inner_def, mul_comm]
nonneg_re := fun x => normSq_nonneg
definite := fun x => normSq_eq_zero.1
add_left := fun x y z => by simp only [inner_def, add_mul, add_re]
smul_left := fun x y r => by simp [inner_def] }
noncomputable instance : InnerProductSpace ℝ ℍ :=
InnerProductSpace.ofCore _
| Mathlib/Analysis/Quaternion.lean | 65 | 66 | theorem normSq_eq_norm_mul_self (a : ℍ) : normSq a = ‖a‖ * ‖a‖ := by |
rw [← inner_self, real_inner_self_eq_norm_mul_norm]
|
/-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Logic.Basic
import Mathlib.Tactic.Positivity.Basic
#align_import algebra.order.hom.basic from "leanprover-community/mathlib"@"28aa996fc6fb4317f0083c4e6daf79878d81be33"
/-!
# Algebraic order homomorphism classes
This file defines hom classes for common properties at the intersection of order theory and algebra.
## Typeclasses
Basic typeclasses
* `NonnegHomClass`: Homs are nonnegative: `∀ f a, 0 ≤ f a`
* `SubadditiveHomClass`: Homs are subadditive: `∀ f a b, f (a + b) ≤ f a + f b`
* `SubmultiplicativeHomClass`: Homs are submultiplicative: `∀ f a b, f (a * b) ≤ f a * f b`
* `MulLEAddHomClass`: `∀ f a b, f (a * b) ≤ f a + f b`
* `NonarchimedeanHomClass`: `∀ a b, f (a + b) ≤ max (f a) (f b)`
Group norms
* `AddGroupSeminormClass`: Homs are nonnegative, subadditive, even and preserve zero.
* `GroupSeminormClass`: Homs are nonnegative, respect `f (a * b) ≤ f a + f b`, `f a⁻¹ = f a` and
preserve zero.
* `AddGroupNormClass`: Homs are seminorms such that `f x = 0 → x = 0` for all `x`.
* `GroupNormClass`: Homs are seminorms such that `f x = 0 → x = 1` for all `x`.
Ring norms
* `RingSeminormClass`: Homs are submultiplicative group norms.
* `RingNormClass`: Homs are ring seminorms that are also additive group norms.
* `MulRingSeminormClass`: Homs are ring seminorms that are multiplicative.
* `MulRingNormClass`: Homs are ring norms that are multiplicative.
## Notes
Typeclasses for seminorms are defined here while types of seminorms are defined in
`Analysis.Normed.Group.Seminorm` and `Analysis.Normed.Ring.Seminorm` because absolute values are
multiplicative ring norms but outside of this use we only consider real-valued seminorms.
## TODO
Finitary versions of the current lemmas.
-/
library_note "out-param inheritance"/--
Diamond inheritance cannot depend on `outParam`s in the following circumstances:
* there are three classes `Top`, `Middle`, `Bottom`
* all of these classes have a parameter `(α : outParam _)`
* all of these classes have an instance parameter `[Root α]` that depends on this `outParam`
* the `Root` class has two child classes: `Left` and `Right`, these are siblings in the hierarchy
* the instance `Bottom.toMiddle` takes a `[Left α]` parameter
* the instance `Middle.toTop` takes a `[Right α]` parameter
* there is a `Leaf` class that inherits from both `Left` and `Right`.
In that case, given instances `Bottom α` and `Leaf α`, Lean cannot synthesize a `Top α` instance,
even though the hypotheses of the instances `Bottom.toMiddle` and `Middle.toTop` are satisfied.
There are two workarounds:
* You could replace the bundled inheritance implemented by the instance `Middle.toTop` with
unbundled inheritance implemented by adding a `[Top α]` parameter to the `Middle` class. This is
the preferred option since it is also more compatible with Lean 4, at the cost of being more work
to implement and more verbose to use.
* You could weaken the `Bottom.toMiddle` instance by making it depend on a subclass of
`Middle.toTop`'s parameter, in this example replacing `[Left α]` with `[Leaf α]`.
-/
open Function
variable {ι F α β γ δ : Type*}
/-! ### Basics -/
/-- `NonnegHomClass F α β` states that `F` is a type of nonnegative morphisms. -/
class NonnegHomClass (F α β : Type*) [Zero β] [LE β] [FunLike F α β] : Prop where
/-- the image of any element is non negative. -/
apply_nonneg (f : F) : ∀ a, 0 ≤ f a
#align nonneg_hom_class NonnegHomClass
/-- `SubadditiveHomClass F α β` states that `F` is a type of subadditive morphisms. -/
class SubadditiveHomClass (F α β : Type*) [Add α] [Add β] [LE β] [FunLike F α β] : Prop where
/-- the image of a sum is less or equal than the sum of the images. -/
map_add_le_add (f : F) : ∀ a b, f (a + b) ≤ f a + f b
#align subadditive_hom_class SubadditiveHomClass
/-- `SubmultiplicativeHomClass F α β` states that `F` is a type of submultiplicative morphisms. -/
@[to_additive SubadditiveHomClass]
class SubmultiplicativeHomClass (F α β : Type*) [Mul α] [Mul β] [LE β] [FunLike F α β] : Prop where
/-- the image of a product is less or equal than the product of the images. -/
map_mul_le_mul (f : F) : ∀ a b, f (a * b) ≤ f a * f b
#align submultiplicative_hom_class SubmultiplicativeHomClass
/-- `MulLEAddHomClass F α β` states that `F` is a type of subadditive morphisms. -/
@[to_additive SubadditiveHomClass]
class MulLEAddHomClass (F α β : Type*) [Mul α] [Add β] [LE β] [FunLike F α β] : Prop where
/-- the image of a product is less or equal than the sum of the images. -/
map_mul_le_add (f : F) : ∀ a b, f (a * b) ≤ f a + f b
#align mul_le_add_hom_class MulLEAddHomClass
/-- `NonarchimedeanHomClass F α β` states that `F` is a type of non-archimedean morphisms. -/
class NonarchimedeanHomClass (F α β : Type*) [Add α] [LinearOrder β] [FunLike F α β] : Prop where
/-- the image of a sum is less or equal than the maximum of the images. -/
map_add_le_max (f : F) : ∀ a b, f (a + b) ≤ max (f a) (f b)
#align nonarchimedean_hom_class NonarchimedeanHomClass
export NonnegHomClass (apply_nonneg)
export SubadditiveHomClass (map_add_le_add)
export SubmultiplicativeHomClass (map_mul_le_mul)
export MulLEAddHomClass (map_mul_le_add)
export NonarchimedeanHomClass (map_add_le_max)
attribute [simp] apply_nonneg
variable [FunLike F α β]
@[to_additive]
theorem le_map_mul_map_div [Group α] [CommSemigroup β] [LE β] [SubmultiplicativeHomClass F α β]
(f : F) (a b : α) : f a ≤ f b * f (a / b) := by
simpa only [mul_comm, div_mul_cancel] using map_mul_le_mul f (a / b) b
#align le_map_mul_map_div le_map_mul_map_div
#align le_map_add_map_sub le_map_add_map_sub
@[to_additive existing]
theorem le_map_add_map_div [Group α] [AddCommSemigroup β] [LE β] [MulLEAddHomClass F α β] (f : F)
(a b : α) : f a ≤ f b + f (a / b) := by
simpa only [add_comm, div_mul_cancel] using map_mul_le_add f (a / b) b
#align le_map_add_map_div le_map_add_map_div
-- #align le_map_add_map_sub le_map_add_map_sub
-- Porting note (#11215): TODO: `to_additive` clashes
@[to_additive]
| Mathlib/Algebra/Order/Hom/Basic.lean | 139 | 141 | theorem le_map_div_mul_map_div [Group α] [CommSemigroup β] [LE β] [SubmultiplicativeHomClass F α β]
(f : F) (a b c : α) : f (a / c) ≤ f (a / b) * f (b / c) := by |
simpa only [div_mul_div_cancel'] using map_mul_le_mul f (a / b) (b / c)
|
/-
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, Alexander Bentkamp
-/
import Mathlib.Algebra.BigOperators.Finsupp
import Mathlib.Algebra.BigOperators.Finprod
import Mathlib.Data.Fintype.BigOperators
import Mathlib.LinearAlgebra.Finsupp
import Mathlib.LinearAlgebra.LinearIndependent
import Mathlib.SetTheory.Cardinal.Cofinality
#align_import linear_algebra.basis from "leanprover-community/mathlib"@"13bce9a6b6c44f6b4c91ac1c1d2a816e2533d395"
/-!
# Bases
This file defines bases in a module or vector space.
It is inspired by Isabelle/HOL's linear algebra, and hence indirectly by HOL Light.
## Main definitions
All definitions are given for families of vectors, i.e. `v : ι → M` where `M` is the module or
vector space and `ι : Type*` is an arbitrary indexing type.
* `Basis ι R M` is the type of `ι`-indexed `R`-bases for a module `M`,
represented by a linear equiv `M ≃ₗ[R] ι →₀ R`.
* the basis vectors of a basis `b : Basis ι R M` are available as `b i`, where `i : ι`
* `Basis.repr` is the isomorphism sending `x : M` to its coordinates `Basis.repr x : ι →₀ R`.
The converse, turning this isomorphism into a basis, is called `Basis.ofRepr`.
* If `ι` is finite, there is a variant of `repr` called `Basis.equivFun b : M ≃ₗ[R] ι → R`
(saving you from having to work with `Finsupp`). The converse, turning this isomorphism into
a basis, is called `Basis.ofEquivFun`.
* `Basis.constr b R f` constructs a linear map `M₁ →ₗ[R] M₂` given the values `f : ι → M₂` at the
basis elements `⇑b : ι → M₁`.
* `Basis.reindex` uses an equiv to map a basis to a different indexing set.
* `Basis.map` uses a linear equiv to map a basis to a different module.
## Main statements
* `Basis.mk`: a linear independent set of vectors spanning the whole module determines a basis
* `Basis.ext` states that two linear maps are equal if they coincide on a basis.
Similar results are available for linear equivs (if they coincide on the basis vectors),
elements (if their coordinates coincide) and the functions `b.repr` and `⇑b`.
## Implementation notes
We use families instead of sets because it allows us to say that two identical vectors are linearly
dependent. For bases, this is useful as well because we can easily derive ordered bases by using an
ordered index type `ι`.
## Tags
basis, bases
-/
noncomputable section
universe u
open Function Set Submodule
variable {ι : Type*} {ι' : Type*} {R : Type*} {R₂ : Type*} {K : Type*}
variable {M : Type*} {M' M'' : Type*} {V : Type u} {V' : Type*}
section Module
variable [Semiring R]
variable [AddCommMonoid M] [Module R M] [AddCommMonoid M'] [Module R M']
section
variable (ι R M)
/-- A `Basis ι R M` for a module `M` is the type of `ι`-indexed `R`-bases of `M`.
The basis vectors are available as `DFunLike.coe (b : Basis ι R M) : ι → M`.
To turn a linear independent family of vectors spanning `M` into a basis, use `Basis.mk`.
They are internally represented as linear equivs `M ≃ₗ[R] (ι →₀ R)`,
available as `Basis.repr`.
-/
structure Basis where
/-- `Basis.ofRepr` constructs a basis given an assignment of coordinates to each vector. -/
ofRepr ::
/-- `repr` is the linear equivalence sending a vector `x` to its coordinates:
the `c`s such that `x = ∑ i, c i`. -/
repr : M ≃ₗ[R] ι →₀ R
#align basis Basis
#align basis.repr Basis.repr
#align basis.of_repr Basis.ofRepr
end
instance uniqueBasis [Subsingleton R] : Unique (Basis ι R M) :=
⟨⟨⟨default⟩⟩, fun ⟨b⟩ => by rw [Subsingleton.elim b]⟩
#align unique_basis uniqueBasis
namespace Basis
instance : Inhabited (Basis ι R (ι →₀ R)) :=
⟨.ofRepr (LinearEquiv.refl _ _)⟩
variable (b b₁ : Basis ι R M) (i : ι) (c : R) (x : M)
section repr
theorem repr_injective : Injective (repr : Basis ι R M → M ≃ₗ[R] ι →₀ R) := fun f g h => by
cases f; cases g; congr
#align basis.repr_injective Basis.repr_injective
/-- `b i` is the `i`th basis vector. -/
instance instFunLike : FunLike (Basis ι R M) ι M where
coe b i := b.repr.symm (Finsupp.single i 1)
coe_injective' f g h := repr_injective <| LinearEquiv.symm_bijective.injective <|
LinearEquiv.toLinearMap_injective <| by ext; exact congr_fun h _
#align basis.fun_like Basis.instFunLike
@[simp]
theorem coe_ofRepr (e : M ≃ₗ[R] ι →₀ R) : ⇑(ofRepr e) = fun i => e.symm (Finsupp.single i 1) :=
rfl
#align basis.coe_of_repr Basis.coe_ofRepr
protected theorem injective [Nontrivial R] : Injective b :=
b.repr.symm.injective.comp fun _ _ => (Finsupp.single_left_inj (one_ne_zero : (1 : R) ≠ 0)).mp
#align basis.injective Basis.injective
theorem repr_symm_single_one : b.repr.symm (Finsupp.single i 1) = b i :=
rfl
#align basis.repr_symm_single_one Basis.repr_symm_single_one
theorem repr_symm_single : b.repr.symm (Finsupp.single i c) = c • b i :=
calc
b.repr.symm (Finsupp.single i c) = b.repr.symm (c • Finsupp.single i (1 : R)) := by
{ rw [Finsupp.smul_single', mul_one] }
_ = c • b i := by rw [LinearEquiv.map_smul, repr_symm_single_one]
#align basis.repr_symm_single Basis.repr_symm_single
@[simp]
theorem repr_self : b.repr (b i) = Finsupp.single i 1 :=
LinearEquiv.apply_symm_apply _ _
#align basis.repr_self Basis.repr_self
theorem repr_self_apply (j) [Decidable (i = j)] : b.repr (b i) j = if i = j then 1 else 0 := by
rw [repr_self, Finsupp.single_apply]
#align basis.repr_self_apply Basis.repr_self_apply
@[simp]
theorem repr_symm_apply (v) : b.repr.symm v = Finsupp.total ι M R b v :=
calc
b.repr.symm v = b.repr.symm (v.sum Finsupp.single) := by simp
_ = v.sum fun i vi => b.repr.symm (Finsupp.single i vi) := map_finsupp_sum ..
_ = Finsupp.total ι M R b v := by simp only [repr_symm_single, Finsupp.total_apply]
#align basis.repr_symm_apply Basis.repr_symm_apply
@[simp]
theorem coe_repr_symm : ↑b.repr.symm = Finsupp.total ι M R b :=
LinearMap.ext fun v => b.repr_symm_apply v
#align basis.coe_repr_symm Basis.coe_repr_symm
@[simp]
theorem repr_total (v) : b.repr (Finsupp.total _ _ _ b v) = v := by
rw [← b.coe_repr_symm]
exact b.repr.apply_symm_apply v
#align basis.repr_total Basis.repr_total
@[simp]
theorem total_repr : Finsupp.total _ _ _ b (b.repr x) = x := by
rw [← b.coe_repr_symm]
exact b.repr.symm_apply_apply x
#align basis.total_repr Basis.total_repr
theorem repr_range : LinearMap.range (b.repr : M →ₗ[R] ι →₀ R) = Finsupp.supported R R univ := by
rw [LinearEquiv.range, Finsupp.supported_univ]
#align basis.repr_range Basis.repr_range
theorem mem_span_repr_support (m : M) : m ∈ span R (b '' (b.repr m).support) :=
(Finsupp.mem_span_image_iff_total _).2 ⟨b.repr m, by simp [Finsupp.mem_supported_support]⟩
#align basis.mem_span_repr_support Basis.mem_span_repr_support
theorem repr_support_subset_of_mem_span (s : Set ι) {m : M}
(hm : m ∈ span R (b '' s)) : ↑(b.repr m).support ⊆ s := by
rcases (Finsupp.mem_span_image_iff_total _).1 hm with ⟨l, hl, rfl⟩
rwa [repr_total, ← Finsupp.mem_supported R l]
#align basis.repr_support_subset_of_mem_span Basis.repr_support_subset_of_mem_span
theorem mem_span_image {m : M} {s : Set ι} : m ∈ span R (b '' s) ↔ ↑(b.repr m).support ⊆ s :=
⟨repr_support_subset_of_mem_span _ _, fun h ↦
span_mono (image_subset _ h) (mem_span_repr_support b _)⟩
@[simp]
theorem self_mem_span_image [Nontrivial R] {i : ι} {s : Set ι} :
b i ∈ span R (b '' s) ↔ i ∈ s := by
simp [mem_span_image, Finsupp.support_single_ne_zero]
end repr
section Coord
/-- `b.coord i` is the linear function giving the `i`'th coordinate of a vector
with respect to the basis `b`.
`b.coord i` is an element of the dual space. In particular, for
finite-dimensional spaces it is the `ι`th basis vector of the dual space.
-/
@[simps!]
def coord : M →ₗ[R] R :=
Finsupp.lapply i ∘ₗ ↑b.repr
#align basis.coord Basis.coord
theorem forall_coord_eq_zero_iff {x : M} : (∀ i, b.coord i x = 0) ↔ x = 0 :=
Iff.trans (by simp only [b.coord_apply, DFunLike.ext_iff, Finsupp.zero_apply])
b.repr.map_eq_zero_iff
#align basis.forall_coord_eq_zero_iff Basis.forall_coord_eq_zero_iff
/-- The sum of the coordinates of an element `m : M` with respect to a basis. -/
noncomputable def sumCoords : M →ₗ[R] R :=
(Finsupp.lsum ℕ fun _ => LinearMap.id) ∘ₗ (b.repr : M →ₗ[R] ι →₀ R)
#align basis.sum_coords Basis.sumCoords
@[simp]
theorem coe_sumCoords : (b.sumCoords : M → R) = fun m => (b.repr m).sum fun _ => id :=
rfl
#align basis.coe_sum_coords Basis.coe_sumCoords
theorem coe_sumCoords_eq_finsum : (b.sumCoords : M → R) = fun m => ∑ᶠ i, b.coord i m := by
ext m
simp only [Basis.sumCoords, Basis.coord, Finsupp.lapply_apply, LinearMap.id_coe,
LinearEquiv.coe_coe, Function.comp_apply, Finsupp.coe_lsum, LinearMap.coe_comp,
finsum_eq_sum _ (b.repr m).finite_support, Finsupp.sum, Finset.finite_toSet_toFinset, id,
Finsupp.fun_support_eq]
#align basis.coe_sum_coords_eq_finsum Basis.coe_sumCoords_eq_finsum
@[simp high]
theorem coe_sumCoords_of_fintype [Fintype ι] : (b.sumCoords : M → R) = ∑ i, b.coord i := by
ext m
-- Porting note: - `eq_self_iff_true`
-- + `comp_apply` `LinearMap.coeFn_sum`
simp only [sumCoords, Finsupp.sum_fintype, LinearMap.id_coe, LinearEquiv.coe_coe, coord_apply,
id, Fintype.sum_apply, imp_true_iff, Finsupp.coe_lsum, LinearMap.coe_comp, comp_apply,
LinearMap.coeFn_sum]
#align basis.coe_sum_coords_of_fintype Basis.coe_sumCoords_of_fintype
@[simp]
theorem sumCoords_self_apply : b.sumCoords (b i) = 1 := by
simp only [Basis.sumCoords, LinearMap.id_coe, LinearEquiv.coe_coe, id, Basis.repr_self,
Function.comp_apply, Finsupp.coe_lsum, LinearMap.coe_comp, Finsupp.sum_single_index]
#align basis.sum_coords_self_apply Basis.sumCoords_self_apply
theorem dvd_coord_smul (i : ι) (m : M) (r : R) : r ∣ b.coord i (r • m) :=
⟨b.coord i m, by simp⟩
#align basis.dvd_coord_smul Basis.dvd_coord_smul
theorem coord_repr_symm (b : Basis ι R M) (i : ι) (f : ι →₀ R) :
b.coord i (b.repr.symm f) = f i := by
simp only [repr_symm_apply, coord_apply, repr_total]
#align basis.coord_repr_symm Basis.coord_repr_symm
end Coord
section Ext
variable {R₁ : Type*} [Semiring R₁] {σ : R →+* R₁} {σ' : R₁ →+* R}
variable [RingHomInvPair σ σ'] [RingHomInvPair σ' σ]
variable {M₁ : Type*} [AddCommMonoid M₁] [Module R₁ M₁]
/-- Two linear maps are equal if they are equal on basis vectors. -/
theorem ext {f₁ f₂ : M →ₛₗ[σ] M₁} (h : ∀ i, f₁ (b i) = f₂ (b i)) : f₁ = f₂ := by
ext x
rw [← b.total_repr x, Finsupp.total_apply, Finsupp.sum]
simp only [map_sum, LinearMap.map_smulₛₗ, h]
#align basis.ext Basis.ext
/-- Two linear equivs are equal if they are equal on basis vectors. -/
theorem ext' {f₁ f₂ : M ≃ₛₗ[σ] M₁} (h : ∀ i, f₁ (b i) = f₂ (b i)) : f₁ = f₂ := by
ext x
rw [← b.total_repr x, Finsupp.total_apply, Finsupp.sum]
simp only [map_sum, LinearEquiv.map_smulₛₗ, h]
#align basis.ext' Basis.ext'
/-- Two elements are equal iff their coordinates are equal. -/
theorem ext_elem_iff {x y : M} : x = y ↔ ∀ i, b.repr x i = b.repr y i := by
simp only [← DFunLike.ext_iff, EmbeddingLike.apply_eq_iff_eq]
#align basis.ext_elem_iff Basis.ext_elem_iff
alias ⟨_, _root_.Basis.ext_elem⟩ := ext_elem_iff
#align basis.ext_elem Basis.ext_elem
theorem repr_eq_iff {b : Basis ι R M} {f : M →ₗ[R] ι →₀ R} :
↑b.repr = f ↔ ∀ i, f (b i) = Finsupp.single i 1 :=
⟨fun h i => h ▸ b.repr_self i, fun h => b.ext fun i => (b.repr_self i).trans (h i).symm⟩
#align basis.repr_eq_iff Basis.repr_eq_iff
theorem repr_eq_iff' {b : Basis ι R M} {f : M ≃ₗ[R] ι →₀ R} :
b.repr = f ↔ ∀ i, f (b i) = Finsupp.single i 1 :=
⟨fun h i => h ▸ b.repr_self i, fun h => b.ext' fun i => (b.repr_self i).trans (h i).symm⟩
#align basis.repr_eq_iff' Basis.repr_eq_iff'
theorem apply_eq_iff {b : Basis ι R M} {x : M} {i : ι} : b i = x ↔ b.repr x = Finsupp.single i 1 :=
⟨fun h => h ▸ b.repr_self i, fun h => b.repr.injective ((b.repr_self i).trans h.symm)⟩
#align basis.apply_eq_iff Basis.apply_eq_iff
/-- An unbundled version of `repr_eq_iff` -/
theorem repr_apply_eq (f : M → ι → R) (hadd : ∀ x y, f (x + y) = f x + f y)
(hsmul : ∀ (c : R) (x : M), f (c • x) = c • f x) (f_eq : ∀ i, f (b i) = Finsupp.single i 1)
(x : M) (i : ι) : b.repr x i = f x i := by
let f_i : M →ₗ[R] R :=
{ toFun := fun x => f x i
-- Porting note(#12129): additional beta reduction needed
map_add' := fun _ _ => by beta_reduce; rw [hadd, Pi.add_apply]
map_smul' := fun _ _ => by simp [hsmul, Pi.smul_apply] }
have : Finsupp.lapply i ∘ₗ ↑b.repr = f_i := by
refine b.ext fun j => ?_
show b.repr (b j) i = f (b j) i
rw [b.repr_self, f_eq]
calc
b.repr x i = f_i x := by
{ rw [← this]
rfl }
_ = f x i := rfl
#align basis.repr_apply_eq Basis.repr_apply_eq
/-- Two bases are equal if they assign the same coordinates. -/
theorem eq_ofRepr_eq_repr {b₁ b₂ : Basis ι R M} (h : ∀ x i, b₁.repr x i = b₂.repr x i) : b₁ = b₂ :=
repr_injective <| by ext; apply h
#align basis.eq_of_repr_eq_repr Basis.eq_ofRepr_eq_repr
/-- Two bases are equal if their basis vectors are the same. -/
@[ext]
theorem eq_of_apply_eq {b₁ b₂ : Basis ι R M} : (∀ i, b₁ i = b₂ i) → b₁ = b₂ :=
DFunLike.ext _ _
#align basis.eq_of_apply_eq Basis.eq_of_apply_eq
end Ext
section Map
variable (f : M ≃ₗ[R] M')
/-- Apply the linear equivalence `f` to the basis vectors. -/
@[simps]
protected def map : Basis ι R M' :=
ofRepr (f.symm.trans b.repr)
#align basis.map Basis.map
@[simp]
theorem map_apply (i) : b.map f i = f (b i) :=
rfl
#align basis.map_apply Basis.map_apply
theorem coe_map : (b.map f : ι → M') = f ∘ b :=
rfl
end Map
section MapCoeffs
variable {R' : Type*} [Semiring R'] [Module R' M] (f : R ≃+* R')
(h : ∀ (c) (x : M), f c • x = c • x)
attribute [local instance] SMul.comp.isScalarTower
/-- If `R` and `R'` are isomorphic rings that act identically on a module `M`,
then a basis for `M` as `R`-module is also a basis for `M` as `R'`-module.
See also `Basis.algebraMapCoeffs` for the case where `f` is equal to `algebraMap`.
-/
@[simps (config := { simpRhs := true })]
def mapCoeffs : Basis ι R' M := by
letI : Module R' R := Module.compHom R (↑f.symm : R' →+* R)
haveI : IsScalarTower R' R M :=
{ smul_assoc := fun x y z => by
-- Porting note: `dsimp [(· • ·)]` is unavailable because
-- `HSMul.hsmul` becomes `SMul.smul`.
change (f.symm x * y) • z = x • (y • z)
rw [mul_smul, ← h, f.apply_symm_apply] }
exact ofRepr <| (b.repr.restrictScalars R').trans <|
Finsupp.mapRange.linearEquiv (Module.compHom.toLinearEquiv f.symm).symm
#align basis.map_coeffs Basis.mapCoeffs
theorem mapCoeffs_apply (i : ι) : b.mapCoeffs f h i = b i :=
apply_eq_iff.mpr <| by
-- Porting note: in Lean 3, these were automatically inferred from the definition of
-- `mapCoeffs`.
letI : Module R' R := Module.compHom R (↑f.symm : R' →+* R)
haveI : IsScalarTower R' R M :=
{ smul_assoc := fun x y z => by
-- Porting note: `dsimp [(· • ·)]` is unavailable because
-- `HSMul.hsmul` becomes `SMul.smul`.
change (f.symm x * y) • z = x • (y • z)
rw [mul_smul, ← h, f.apply_symm_apply] }
simp
#align basis.map_coeffs_apply Basis.mapCoeffs_apply
@[simp]
theorem coe_mapCoeffs : (b.mapCoeffs f h : ι → M) = b :=
funext <| b.mapCoeffs_apply f h
#align basis.coe_map_coeffs Basis.coe_mapCoeffs
end MapCoeffs
section Reindex
variable (b' : Basis ι' R M')
variable (e : ι ≃ ι')
/-- `b.reindex (e : ι ≃ ι')` is a basis indexed by `ι'` -/
def reindex : Basis ι' R M :=
.ofRepr (b.repr.trans (Finsupp.domLCongr e))
#align basis.reindex Basis.reindex
theorem reindex_apply (i' : ι') : b.reindex e i' = b (e.symm i') :=
show (b.repr.trans (Finsupp.domLCongr e)).symm (Finsupp.single i' 1) =
b.repr.symm (Finsupp.single (e.symm i') 1)
by rw [LinearEquiv.symm_trans_apply, Finsupp.domLCongr_symm, Finsupp.domLCongr_single]
#align basis.reindex_apply Basis.reindex_apply
@[simp]
theorem coe_reindex : (b.reindex e : ι' → M) = b ∘ e.symm :=
funext (b.reindex_apply e)
#align basis.coe_reindex Basis.coe_reindex
theorem repr_reindex_apply (i' : ι') : (b.reindex e).repr x i' = b.repr x (e.symm i') :=
show (Finsupp.domLCongr e : _ ≃ₗ[R] _) (b.repr x) i' = _ by simp
#align basis.repr_reindex_apply Basis.repr_reindex_apply
@[simp]
theorem repr_reindex : (b.reindex e).repr x = (b.repr x).mapDomain e :=
DFunLike.ext _ _ <| by simp [repr_reindex_apply]
#align basis.repr_reindex Basis.repr_reindex
@[simp]
theorem reindex_refl : b.reindex (Equiv.refl ι) = b :=
eq_of_apply_eq fun i => by simp
#align basis.reindex_refl Basis.reindex_refl
/-- `simp` can prove this as `Basis.coe_reindex` + `EquivLike.range_comp` -/
theorem range_reindex : Set.range (b.reindex e) = Set.range b := by
simp [coe_reindex, range_comp]
#align basis.range_reindex Basis.range_reindex
@[simp]
theorem sumCoords_reindex : (b.reindex e).sumCoords = b.sumCoords := by
ext x
simp only [coe_sumCoords, repr_reindex]
exact Finsupp.sum_mapDomain_index (fun _ => rfl) fun _ _ _ => rfl
#align basis.sum_coords_reindex Basis.sumCoords_reindex
/-- `b.reindex_range` is a basis indexed by `range b`, the basis vectors themselves. -/
def reindexRange : Basis (range b) R M :=
haveI := Classical.dec (Nontrivial R)
if h : Nontrivial R then
letI := h
b.reindex (Equiv.ofInjective b (Basis.injective b))
else
letI : Subsingleton R := not_nontrivial_iff_subsingleton.mp h
.ofRepr (Module.subsingletonEquiv R M (range b))
#align basis.reindex_range Basis.reindexRange
theorem reindexRange_self (i : ι) (h := Set.mem_range_self i) : b.reindexRange ⟨b i, h⟩ = b i := by
by_cases htr : Nontrivial R
· letI := htr
simp [htr, reindexRange, reindex_apply, Equiv.apply_ofInjective_symm b.injective,
Subtype.coe_mk]
· letI : Subsingleton R := not_nontrivial_iff_subsingleton.mp htr
letI := Module.subsingleton R M
simp [reindexRange, eq_iff_true_of_subsingleton]
#align basis.reindex_range_self Basis.reindexRange_self
theorem reindexRange_repr_self (i : ι) :
b.reindexRange.repr (b i) = Finsupp.single ⟨b i, mem_range_self i⟩ 1 :=
calc
b.reindexRange.repr (b i) = b.reindexRange.repr (b.reindexRange ⟨b i, mem_range_self i⟩) :=
congr_arg _ (b.reindexRange_self _ _).symm
_ = Finsupp.single ⟨b i, mem_range_self i⟩ 1 := b.reindexRange.repr_self _
#align basis.reindex_range_repr_self Basis.reindexRange_repr_self
@[simp]
theorem reindexRange_apply (x : range b) : b.reindexRange x = x := by
rcases x with ⟨bi, ⟨i, rfl⟩⟩
exact b.reindexRange_self i
#align basis.reindex_range_apply Basis.reindexRange_apply
theorem reindexRange_repr' (x : M) {bi : M} {i : ι} (h : b i = bi) :
b.reindexRange.repr x ⟨bi, ⟨i, h⟩⟩ = b.repr x i := by
nontriviality
subst h
apply (b.repr_apply_eq (fun x i => b.reindexRange.repr x ⟨b i, _⟩) _ _ _ x i).symm
· intro x y
ext i
simp only [Pi.add_apply, LinearEquiv.map_add, Finsupp.coe_add]
· intro c x
ext i
simp only [Pi.smul_apply, LinearEquiv.map_smul, Finsupp.coe_smul]
· intro i
ext j
simp only [reindexRange_repr_self]
apply Finsupp.single_apply_left (f := fun i => (⟨b i, _⟩ : Set.range b))
exact fun i j h => b.injective (Subtype.mk.inj h)
#align basis.reindex_range_repr' Basis.reindexRange_repr'
@[simp]
theorem reindexRange_repr (x : M) (i : ι) (h := Set.mem_range_self i) :
b.reindexRange.repr x ⟨b i, h⟩ = b.repr x i :=
b.reindexRange_repr' _ rfl
#align basis.reindex_range_repr Basis.reindexRange_repr
section Fintype
variable [Fintype ι] [DecidableEq M]
/-- `b.reindexFinsetRange` is a basis indexed by `Finset.univ.image b`,
the finite set of basis vectors themselves. -/
def reindexFinsetRange : Basis (Finset.univ.image b) R M :=
b.reindexRange.reindex ((Equiv.refl M).subtypeEquiv (by simp))
#align basis.reindex_finset_range Basis.reindexFinsetRange
theorem reindexFinsetRange_self (i : ι) (h := Finset.mem_image_of_mem b (Finset.mem_univ i)) :
b.reindexFinsetRange ⟨b i, h⟩ = b i := by
rw [reindexFinsetRange, reindex_apply, reindexRange_apply]
rfl
#align basis.reindex_finset_range_self Basis.reindexFinsetRange_self
@[simp]
theorem reindexFinsetRange_apply (x : Finset.univ.image b) : b.reindexFinsetRange x = x := by
rcases x with ⟨bi, hbi⟩
rcases Finset.mem_image.mp hbi with ⟨i, -, rfl⟩
exact b.reindexFinsetRange_self i
#align basis.reindex_finset_range_apply Basis.reindexFinsetRange_apply
theorem reindexFinsetRange_repr_self (i : ι) :
b.reindexFinsetRange.repr (b i) =
Finsupp.single ⟨b i, Finset.mem_image_of_mem b (Finset.mem_univ i)⟩ 1 := by
ext ⟨bi, hbi⟩
rw [reindexFinsetRange, repr_reindex, Finsupp.mapDomain_equiv_apply, reindexRange_repr_self]
-- Porting note: replaced a `convert; refl` with `simp`
simp [Finsupp.single_apply]
#align basis.reindex_finset_range_repr_self Basis.reindexFinsetRange_repr_self
@[simp]
theorem reindexFinsetRange_repr (x : M) (i : ι)
(h := Finset.mem_image_of_mem b (Finset.mem_univ i)) :
b.reindexFinsetRange.repr x ⟨b i, h⟩ = b.repr x i := by simp [reindexFinsetRange]
#align basis.reindex_finset_range_repr Basis.reindexFinsetRange_repr
end Fintype
end Reindex
protected theorem linearIndependent : LinearIndependent R b :=
linearIndependent_iff.mpr fun l hl =>
calc
l = b.repr (Finsupp.total _ _ _ b l) := (b.repr_total l).symm
_ = 0 := by rw [hl, LinearEquiv.map_zero]
#align basis.linear_independent Basis.linearIndependent
protected theorem ne_zero [Nontrivial R] (i) : b i ≠ 0 :=
b.linearIndependent.ne_zero i
#align basis.ne_zero Basis.ne_zero
protected theorem mem_span (x : M) : x ∈ span R (range b) :=
span_mono (image_subset_range _ _) (mem_span_repr_support b x)
#align basis.mem_span Basis.mem_span
@[simp]
protected theorem span_eq : span R (range b) = ⊤ :=
eq_top_iff.mpr fun x _ => b.mem_span x
#align basis.span_eq Basis.span_eq
theorem index_nonempty (b : Basis ι R M) [Nontrivial M] : Nonempty ι := by
obtain ⟨x, y, ne⟩ : ∃ x y : M, x ≠ y := Nontrivial.exists_pair_ne
obtain ⟨i, _⟩ := not_forall.mp (mt b.ext_elem_iff.2 ne)
exact ⟨i⟩
#align basis.index_nonempty Basis.index_nonempty
/-- If the submodule `P` has a basis, `x ∈ P` iff it is a linear combination of basis vectors. -/
theorem mem_submodule_iff {P : Submodule R M} (b : Basis ι R P) {x : M} :
x ∈ P ↔ ∃ c : ι →₀ R, x = Finsupp.sum c fun i x => x • (b i : M) := by
conv_lhs =>
rw [← P.range_subtype, ← Submodule.map_top, ← b.span_eq, Submodule.map_span, ← Set.range_comp,
← Finsupp.range_total]
simp [@eq_comm _ x, Function.comp, Finsupp.total_apply]
#align basis.mem_submodule_iff Basis.mem_submodule_iff
section Constr
variable (S : Type*) [Semiring S] [Module S M']
variable [SMulCommClass R S M']
/-- Construct a linear map given the value at the basis, called `Basis.constr b S f` where `b` is
a basis, `f` is the value of the linear map over the elements of the basis, and `S` is an
extra semiring (typically `S = R` or `S = ℕ`).
This definition is parameterized over an extra `Semiring S`,
such that `SMulCommClass R S M'` holds.
If `R` is commutative, you can set `S := R`; if `R` is not commutative,
you can recover an `AddEquiv` by setting `S := ℕ`.
See library note [bundled maps over different rings].
-/
def constr : (ι → M') ≃ₗ[S] M →ₗ[R] M' where
toFun f := (Finsupp.total M' M' R id).comp <| Finsupp.lmapDomain R R f ∘ₗ ↑b.repr
invFun f i := f (b i)
left_inv f := by
ext
simp
right_inv f := by
refine b.ext fun i => ?_
simp
map_add' f g := by
refine b.ext fun i => ?_
simp
map_smul' c f := by
refine b.ext fun i => ?_
simp
#align basis.constr Basis.constr
theorem constr_def (f : ι → M') :
constr (M' := M') b S f = Finsupp.total M' M' R id ∘ₗ Finsupp.lmapDomain R R f ∘ₗ ↑b.repr :=
rfl
#align basis.constr_def Basis.constr_def
theorem constr_apply (f : ι → M') (x : M) :
constr (M' := M') b S f x = (b.repr x).sum fun b a => a • f b := by
simp only [constr_def, LinearMap.comp_apply, Finsupp.lmapDomain_apply, Finsupp.total_apply]
rw [Finsupp.sum_mapDomain_index] <;> simp [add_smul]
#align basis.constr_apply Basis.constr_apply
@[simp]
| Mathlib/LinearAlgebra/Basis.lean | 634 | 635 | theorem constr_basis (f : ι → M') (i : ι) : (constr (M' := M') b S f : M → M') (b i) = f i := by |
simp [Basis.constr_apply, b.repr_self]
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Angle
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Inverse
#align_import analysis.special_functions.complex.arg from "leanprover-community/mathlib"@"2c1d8ca2812b64f88992a5294ea3dba144755cd1"
/-!
# The argument of a complex number.
We define `arg : ℂ → ℝ`, returning a real number in the range (-π, π],
such that for `x ≠ 0`, `sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`,
while `arg 0` defaults to `0`
-/
open Filter Metric Set
open scoped ComplexConjugate Real Topology
namespace Complex
variable {a x z : ℂ}
/-- `arg` returns values in the range (-π, π], such that for `x ≠ 0`,
`sin (arg x) = x.im / x.abs` and `cos (arg x) = x.re / x.abs`,
`arg 0` defaults to `0` -/
noncomputable def arg (x : ℂ) : ℝ :=
if 0 ≤ x.re then Real.arcsin (x.im / abs x)
else if 0 ≤ x.im then Real.arcsin ((-x).im / abs x) + π else Real.arcsin ((-x).im / abs x) - π
#align complex.arg Complex.arg
theorem sin_arg (x : ℂ) : Real.sin (arg x) = x.im / abs x := by
unfold arg; split_ifs <;>
simp [sub_eq_add_neg, arg,
Real.sin_arcsin (abs_le.1 (abs_im_div_abs_le_one x)).1 (abs_le.1 (abs_im_div_abs_le_one x)).2,
Real.sin_add, neg_div, Real.arcsin_neg, Real.sin_neg]
#align complex.sin_arg Complex.sin_arg
theorem cos_arg {x : ℂ} (hx : x ≠ 0) : Real.cos (arg x) = x.re / abs x := by
rw [arg]
split_ifs with h₁ h₂
· rw [Real.cos_arcsin]
field_simp [Real.sqrt_sq, (abs.pos hx).le, *]
· rw [Real.cos_add_pi, Real.cos_arcsin]
field_simp [Real.sqrt_div (sq_nonneg _), Real.sqrt_sq_eq_abs,
_root_.abs_of_neg (not_le.1 h₁), *]
· rw [Real.cos_sub_pi, Real.cos_arcsin]
field_simp [Real.sqrt_div (sq_nonneg _), Real.sqrt_sq_eq_abs,
_root_.abs_of_neg (not_le.1 h₁), *]
#align complex.cos_arg Complex.cos_arg
@[simp]
theorem abs_mul_exp_arg_mul_I (x : ℂ) : ↑(abs x) * exp (arg x * I) = x := by
rcases eq_or_ne x 0 with (rfl | hx)
· simp
· have : abs x ≠ 0 := abs.ne_zero hx
apply Complex.ext <;> field_simp [sin_arg, cos_arg hx, this, mul_comm (abs x)]
set_option linter.uppercaseLean3 false in
#align complex.abs_mul_exp_arg_mul_I Complex.abs_mul_exp_arg_mul_I
@[simp]
| Mathlib/Analysis/SpecialFunctions/Complex/Arg.lean | 63 | 64 | theorem abs_mul_cos_add_sin_mul_I (x : ℂ) : (abs x * (cos (arg x) + sin (arg x) * I) : ℂ) = x := by |
rw [← exp_mul_I, abs_mul_exp_arg_mul_I]
|
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
-/
import Mathlib.LinearAlgebra.FiniteDimensional
import Mathlib.LinearAlgebra.GeneralLinearGroup
import Mathlib.LinearAlgebra.Matrix.Reindex
import Mathlib.Tactic.FieldSimp
import Mathlib.LinearAlgebra.Matrix.NonsingularInverse
import Mathlib.LinearAlgebra.Matrix.Basis
#align_import linear_algebra.determinant from "leanprover-community/mathlib"@"0c1d80f5a86b36c1db32e021e8d19ae7809d5b79"
/-!
# Determinant of families of vectors
This file defines the determinant of an endomorphism, and of a family of vectors
with respect to some basis. For the determinant of a matrix, see the file
`LinearAlgebra.Matrix.Determinant`.
## Main definitions
In the list below, and in all this file, `R` is a commutative ring (semiring
is sometimes enough), `M` and its variations are `R`-modules, `ι`, `κ`, `n` and `m` are finite
types used for indexing.
* `Basis.det`: the determinant of a family of vectors with respect to a basis,
as a multilinear map
* `LinearMap.det`: the determinant of an endomorphism `f : End R M` as a
multiplicative homomorphism (if `M` does not have a finite `R`-basis, the
result is `1` instead)
* `LinearEquiv.det`: the determinant of an isomorphism `f : M ≃ₗ[R] M` as a
multiplicative homomorphism (if `M` does not have a finite `R`-basis, the
result is `1` instead)
## Tags
basis, det, determinant
-/
noncomputable section
open Matrix LinearMap Submodule Set Function
universe u v w
variable {R : Type*} [CommRing R]
variable {M : Type*} [AddCommGroup M] [Module R M]
variable {M' : Type*} [AddCommGroup M'] [Module R M']
variable {ι : Type*} [DecidableEq ι] [Fintype ι]
variable (e : Basis ι R M)
section Conjugate
variable {A : Type*} [CommRing A]
variable {m n : Type*}
/-- If `R^m` and `R^n` are linearly equivalent, then `m` and `n` are also equivalent. -/
def equivOfPiLEquivPi {R : Type*} [Finite m] [Finite n] [CommRing R] [Nontrivial R]
(e : (m → R) ≃ₗ[R] n → R) : m ≃ n :=
Basis.indexEquiv (Basis.ofEquivFun e.symm) (Pi.basisFun _ _)
#align equiv_of_pi_lequiv_pi equivOfPiLEquivPi
namespace Matrix
variable [Fintype m] [Fintype n]
/-- If `M` and `M'` are each other's inverse matrices, they are square matrices up to
equivalence of types. -/
def indexEquivOfInv [Nontrivial A] [DecidableEq m] [DecidableEq n] {M : Matrix m n A}
{M' : Matrix n m A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : m ≃ n :=
equivOfPiLEquivPi (toLin'OfInv hMM' hM'M)
#align matrix.index_equiv_of_inv Matrix.indexEquivOfInv
theorem det_comm [DecidableEq n] (M N : Matrix n n A) : det (M * N) = det (N * M) := by
rw [det_mul, det_mul, mul_comm]
#align matrix.det_comm Matrix.det_comm
/-- If there exists a two-sided inverse `M'` for `M` (indexed differently),
then `det (N * M) = det (M * N)`. -/
theorem det_comm' [DecidableEq m] [DecidableEq n] {M : Matrix n m A} {N : Matrix m n A}
{M' : Matrix m n A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : det (M * N) = det (N * M) := by
nontriviality A
-- Although `m` and `n` are different a priori, we will show they have the same cardinality.
-- This turns the problem into one for square matrices, which is easy.
let e := indexEquivOfInv hMM' hM'M
rw [← det_submatrix_equiv_self e, ← submatrix_mul_equiv _ _ _ (Equiv.refl n) _, det_comm,
submatrix_mul_equiv, Equiv.coe_refl, submatrix_id_id]
#align matrix.det_comm' Matrix.det_comm'
/-- If `M'` is a two-sided inverse for `M` (indexed differently), `det (M * N * M') = det N`.
See `Matrix.det_conj` and `Matrix.det_conj'` for the case when `M' = M⁻¹` or vice versa. -/
theorem det_conj_of_mul_eq_one [DecidableEq m] [DecidableEq n] {M : Matrix m n A}
{M' : Matrix n m A} {N : Matrix n n A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) :
det (M * N * M') = det N := by
rw [← det_comm' hM'M hMM', ← Matrix.mul_assoc, hM'M, Matrix.one_mul]
#align matrix.det_conj_of_mul_eq_one Matrix.det_conj_of_mul_eq_one
end Matrix
end Conjugate
namespace LinearMap
/-! ### Determinant of a linear map -/
variable {A : Type*} [CommRing A] [Module A M]
variable {κ : Type*} [Fintype κ]
/-- The determinant of `LinearMap.toMatrix` does not depend on the choice of basis. -/
theorem det_toMatrix_eq_det_toMatrix [DecidableEq κ] (b : Basis ι A M) (c : Basis κ A M)
(f : M →ₗ[A] M) : det (LinearMap.toMatrix b b f) = det (LinearMap.toMatrix c c f) := by
rw [← linearMap_toMatrix_mul_basis_toMatrix c b c, ← basis_toMatrix_mul_linearMap_toMatrix b c b,
Matrix.det_conj_of_mul_eq_one] <;>
rw [Basis.toMatrix_mul_toMatrix, Basis.toMatrix_self]
#align linear_map.det_to_matrix_eq_det_to_matrix LinearMap.det_toMatrix_eq_det_toMatrix
/-- The determinant of an endomorphism given a basis.
See `LinearMap.det` for a version that populates the basis non-computably.
Although the `Trunc (Basis ι A M)` parameter makes it slightly more convenient to switch bases,
there is no good way to generalize over universe parameters, so we can't fully state in `detAux`'s
type that it does not depend on the choice of basis. Instead you can use the `detAux_def''` lemma,
or avoid mentioning a basis at all using `LinearMap.det`.
-/
irreducible_def detAux : Trunc (Basis ι A M) → (M →ₗ[A] M) →* A :=
Trunc.lift
(fun b : Basis ι A M => detMonoidHom.comp (toMatrixAlgEquiv b : (M →ₗ[A] M) →* Matrix ι ι A))
fun b c => MonoidHom.ext <| det_toMatrix_eq_det_toMatrix b c
#align linear_map.det_aux LinearMap.detAux
/-- Unfold lemma for `detAux`.
See also `detAux_def''` which allows you to vary the basis.
-/
theorem detAux_def' (b : Basis ι A M) (f : M →ₗ[A] M) :
LinearMap.detAux (Trunc.mk b) f = Matrix.det (LinearMap.toMatrix b b f) := by
rw [detAux]
rfl
#align linear_map.det_aux_def LinearMap.detAux_def'
theorem detAux_def'' {ι' : Type*} [Fintype ι'] [DecidableEq ι'] (tb : Trunc <| Basis ι A M)
(b' : Basis ι' A M) (f : M →ₗ[A] M) :
LinearMap.detAux tb f = Matrix.det (LinearMap.toMatrix b' b' f) := by
induction tb using Trunc.induction_on with
| h b => rw [detAux_def', det_toMatrix_eq_det_toMatrix b b']
#align linear_map.det_aux_def' LinearMap.detAux_def''
@[simp]
theorem detAux_id (b : Trunc <| Basis ι A M) : LinearMap.detAux b LinearMap.id = 1 :=
(LinearMap.detAux b).map_one
#align linear_map.det_aux_id LinearMap.detAux_id
@[simp]
theorem detAux_comp (b : Trunc <| Basis ι A M) (f g : M →ₗ[A] M) :
LinearMap.detAux b (f.comp g) = LinearMap.detAux b f * LinearMap.detAux b g :=
(LinearMap.detAux b).map_mul f g
#align linear_map.det_aux_comp LinearMap.detAux_comp
section
open scoped Classical in
-- Discourage the elaborator from unfolding `det` and producing a huge term by marking it
-- as irreducible.
/-- The determinant of an endomorphism independent of basis.
If there is no finite basis on `M`, the result is `1` instead.
-/
protected irreducible_def det : (M →ₗ[A] M) →* A :=
if H : ∃ s : Finset M, Nonempty (Basis s A M) then LinearMap.detAux (Trunc.mk H.choose_spec.some)
else 1
#align linear_map.det LinearMap.det
open scoped Classical in
theorem coe_det [DecidableEq M] :
⇑(LinearMap.det : (M →ₗ[A] M) →* A) =
if H : ∃ s : Finset M, Nonempty (Basis s A M) then
LinearMap.detAux (Trunc.mk H.choose_spec.some)
else 1 := by
ext
rw [LinearMap.det_def]
split_ifs
· congr -- use the correct `DecidableEq` instance
rfl
#align linear_map.coe_det LinearMap.coe_det
end
-- Auxiliary lemma, the `simp` normal form goes in the other direction
-- (using `LinearMap.det_toMatrix`)
theorem det_eq_det_toMatrix_of_finset [DecidableEq M] {s : Finset M} (b : Basis s A M)
(f : M →ₗ[A] M) : LinearMap.det f = Matrix.det (LinearMap.toMatrix b b f) := by
have : ∃ s : Finset M, Nonempty (Basis s A M) := ⟨s, ⟨b⟩⟩
rw [LinearMap.coe_det, dif_pos, detAux_def'' _ b] <;> assumption
#align linear_map.det_eq_det_to_matrix_of_finset LinearMap.det_eq_det_toMatrix_of_finset
@[simp]
theorem det_toMatrix (b : Basis ι A M) (f : M →ₗ[A] M) :
Matrix.det (toMatrix b b f) = LinearMap.det f := by
haveI := Classical.decEq M
rw [det_eq_det_toMatrix_of_finset b.reindexFinsetRange]
-- Porting note: moved out of `rw` due to error
-- typeclass instance problem is stuck, it is often due to metavariables `DecidableEq ?m.628881`
apply det_toMatrix_eq_det_toMatrix b
#align linear_map.det_to_matrix LinearMap.det_toMatrix
@[simp]
theorem det_toMatrix' {ι : Type*} [Fintype ι] [DecidableEq ι] (f : (ι → A) →ₗ[A] ι → A) :
Matrix.det (LinearMap.toMatrix' f) = LinearMap.det f := by simp [← toMatrix_eq_toMatrix']
#align linear_map.det_to_matrix' LinearMap.det_toMatrix'
@[simp]
theorem det_toLin (b : Basis ι R M) (f : Matrix ι ι R) :
LinearMap.det (Matrix.toLin b b f) = f.det := by
rw [← LinearMap.det_toMatrix b, LinearMap.toMatrix_toLin]
#align linear_map.det_to_lin LinearMap.det_toLin
@[simp]
theorem det_toLin' (f : Matrix ι ι R) : LinearMap.det (Matrix.toLin' f) = Matrix.det f := by
simp only [← toLin_eq_toLin', det_toLin]
#align linear_map.det_to_lin' LinearMap.det_toLin'
/-- To show `P (LinearMap.det f)` it suffices to consider `P (Matrix.det (toMatrix _ _ f))` and
`P 1`. -/
-- @[elab_as_elim] -- Porting note: This attr can't be applied.
theorem det_cases [DecidableEq M] {P : A → Prop} (f : M →ₗ[A] M)
(hb : ∀ (s : Finset M) (b : Basis s A M), P (Matrix.det (toMatrix b b f))) (h1 : P 1) :
P (LinearMap.det f) := by
rw [LinearMap.det_def]
split_ifs with h
· convert hb _ h.choose_spec.some
-- Porting note: was `apply det_aux_def'`
convert detAux_def'' (Trunc.mk h.choose_spec.some) h.choose_spec.some f
· exact h1
#align linear_map.det_cases LinearMap.det_cases
@[simp]
theorem det_comp (f g : M →ₗ[A] M) :
LinearMap.det (f.comp g) = LinearMap.det f * LinearMap.det g :=
LinearMap.det.map_mul f g
#align linear_map.det_comp LinearMap.det_comp
@[simp]
theorem det_id : LinearMap.det (LinearMap.id : M →ₗ[A] M) = 1 :=
LinearMap.det.map_one
#align linear_map.det_id LinearMap.det_id
/-- Multiplying a map by a scalar `c` multiplies its determinant by `c ^ dim M`. -/
@[simp]
theorem det_smul {𝕜 : Type*} [Field 𝕜] {M : Type*} [AddCommGroup M] [Module 𝕜 M] (c : 𝕜)
(f : M →ₗ[𝕜] M) :
LinearMap.det (c • f) = c ^ FiniteDimensional.finrank 𝕜 M * LinearMap.det f := by
by_cases H : ∃ s : Finset M, Nonempty (Basis s 𝕜 M)
· have : FiniteDimensional 𝕜 M := by
rcases H with ⟨s, ⟨hs⟩⟩
exact FiniteDimensional.of_fintype_basis hs
simp only [← det_toMatrix (FiniteDimensional.finBasis 𝕜 M), LinearEquiv.map_smul,
Fintype.card_fin, Matrix.det_smul]
· classical
have : FiniteDimensional.finrank 𝕜 M = 0 := finrank_eq_zero_of_not_exists_basis H
simp [coe_det, H, this]
#align linear_map.det_smul LinearMap.det_smul
theorem det_zero' {ι : Type*} [Finite ι] [Nonempty ι] (b : Basis ι A M) :
LinearMap.det (0 : M →ₗ[A] M) = 0 := by
haveI := Classical.decEq ι
cases nonempty_fintype ι
rwa [← det_toMatrix b, LinearEquiv.map_zero, det_zero]
#align linear_map.det_zero' LinearMap.det_zero'
/-- In a finite-dimensional vector space, the zero map has determinant `1` in dimension `0`,
and `0` otherwise. We give a formula that also works in infinite dimension, where we define
the determinant to be `1`. -/
@[simp]
theorem det_zero {𝕜 : Type*} [Field 𝕜] {M : Type*} [AddCommGroup M] [Module 𝕜 M] :
LinearMap.det (0 : M →ₗ[𝕜] M) = (0 : 𝕜) ^ FiniteDimensional.finrank 𝕜 M := by
simp only [← zero_smul 𝕜 (1 : M →ₗ[𝕜] M), det_smul, mul_one, MonoidHom.map_one]
#align linear_map.det_zero LinearMap.det_zero
theorem det_eq_one_of_subsingleton [Subsingleton M] (f : M →ₗ[R] M) :
LinearMap.det (f : M →ₗ[R] M) = 1 := by
have b : Basis (Fin 0) R M := Basis.empty M
rw [← f.det_toMatrix b]
exact Matrix.det_isEmpty
#align linear_map.det_eq_one_of_subsingleton LinearMap.det_eq_one_of_subsingleton
theorem det_eq_one_of_finrank_eq_zero {𝕜 : Type*} [Field 𝕜] {M : Type*} [AddCommGroup M]
[Module 𝕜 M] (h : FiniteDimensional.finrank 𝕜 M = 0) (f : M →ₗ[𝕜] M) :
LinearMap.det (f : M →ₗ[𝕜] M) = 1 := by
classical
refine @LinearMap.det_cases M _ 𝕜 _ _ _ (fun t => t = 1) f ?_ rfl
intro s b
have : IsEmpty s := by
rw [← Fintype.card_eq_zero_iff]
exact (FiniteDimensional.finrank_eq_card_basis b).symm.trans h
exact Matrix.det_isEmpty
#align linear_map.det_eq_one_of_finrank_eq_zero LinearMap.det_eq_one_of_finrank_eq_zero
/-- Conjugating a linear map by a linear equiv does not change its determinant. -/
@[simp]
theorem det_conj {N : Type*} [AddCommGroup N] [Module A N] (f : M →ₗ[A] M) (e : M ≃ₗ[A] N) :
LinearMap.det ((e : M →ₗ[A] N) ∘ₗ f ∘ₗ (e.symm : N →ₗ[A] M)) = LinearMap.det f := by
classical
by_cases H : ∃ s : Finset M, Nonempty (Basis s A M)
· rcases H with ⟨s, ⟨b⟩⟩
rw [← det_toMatrix b f, ← det_toMatrix (b.map e), toMatrix_comp (b.map e) b (b.map e),
toMatrix_comp (b.map e) b b, ← Matrix.mul_assoc, Matrix.det_conj_of_mul_eq_one]
· rw [← toMatrix_comp, LinearEquiv.comp_coe, e.symm_trans_self, LinearEquiv.refl_toLinearMap,
toMatrix_id]
· rw [← toMatrix_comp, LinearEquiv.comp_coe, e.self_trans_symm, LinearEquiv.refl_toLinearMap,
toMatrix_id]
· have H' : ¬∃ t : Finset N, Nonempty (Basis t A N) := by
contrapose! H
rcases H with ⟨s, ⟨b⟩⟩
exact ⟨_, ⟨(b.map e.symm).reindexFinsetRange⟩⟩
simp only [coe_det, H, H', MonoidHom.one_apply, dif_neg, not_false_eq_true]
#align linear_map.det_conj LinearMap.det_conj
/-- If a linear map is invertible, so is its determinant. -/
theorem isUnit_det {A : Type*} [CommRing A] [Module A M] (f : M →ₗ[A] M) (hf : IsUnit f) :
IsUnit (LinearMap.det f) := by
obtain ⟨g, hg⟩ : ∃ g, f.comp g = 1 := hf.exists_right_inv
have : LinearMap.det f * LinearMap.det g = 1 := by
simp only [← LinearMap.det_comp, hg, MonoidHom.map_one]
exact isUnit_of_mul_eq_one _ _ this
#align linear_map.is_unit_det LinearMap.isUnit_det
/-- If a linear map has determinant different from `1`, then the space is finite-dimensional. -/
theorem finiteDimensional_of_det_ne_one {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] (f : M →ₗ[𝕜] M)
(hf : LinearMap.det f ≠ 1) : FiniteDimensional 𝕜 M := by
by_cases H : ∃ s : Finset M, Nonempty (Basis s 𝕜 M)
· rcases H with ⟨s, ⟨hs⟩⟩
exact FiniteDimensional.of_fintype_basis hs
· classical simp [LinearMap.coe_det, H] at hf
#align linear_map.finite_dimensional_of_det_ne_one LinearMap.finiteDimensional_of_det_ne_one
/-- If the determinant of a map vanishes, then the map is not onto. -/
theorem range_lt_top_of_det_eq_zero {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] {f : M →ₗ[𝕜] M}
(hf : LinearMap.det f = 0) : LinearMap.range f < ⊤ := by
have : FiniteDimensional 𝕜 M := by simp [f.finiteDimensional_of_det_ne_one, hf]
contrapose hf
simp only [lt_top_iff_ne_top, Classical.not_not, ← isUnit_iff_range_eq_top] at hf
exact isUnit_iff_ne_zero.1 (f.isUnit_det hf)
#align linear_map.range_lt_top_of_det_eq_zero LinearMap.range_lt_top_of_det_eq_zero
/-- If the determinant of a map vanishes, then the map is not injective. -/
theorem bot_lt_ker_of_det_eq_zero {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] {f : M →ₗ[𝕜] M}
(hf : LinearMap.det f = 0) : ⊥ < LinearMap.ker f := by
have : FiniteDimensional 𝕜 M := by simp [f.finiteDimensional_of_det_ne_one, hf]
contrapose hf
simp only [bot_lt_iff_ne_bot, Classical.not_not, ← isUnit_iff_ker_eq_bot] at hf
exact isUnit_iff_ne_zero.1 (f.isUnit_det hf)
#align linear_map.bot_lt_ker_of_det_eq_zero LinearMap.bot_lt_ker_of_det_eq_zero
end LinearMap
namespace LinearEquiv
/-- On a `LinearEquiv`, the domain of `LinearMap.det` can be promoted to `Rˣ`. -/
protected def det : (M ≃ₗ[R] M) →* Rˣ :=
(Units.map (LinearMap.det : (M →ₗ[R] M) →* R)).comp
(LinearMap.GeneralLinearGroup.generalLinearEquiv R M).symm.toMonoidHom
#align linear_equiv.det LinearEquiv.det
@[simp]
theorem coe_det (f : M ≃ₗ[R] M) : ↑(LinearEquiv.det f) = LinearMap.det (f : M →ₗ[R] M) :=
rfl
#align linear_equiv.coe_det LinearEquiv.coe_det
@[simp]
theorem coe_inv_det (f : M ≃ₗ[R] M) : ↑(LinearEquiv.det f)⁻¹ = LinearMap.det (f.symm : M →ₗ[R] M) :=
rfl
#align linear_equiv.coe_inv_det LinearEquiv.coe_inv_det
@[simp]
theorem det_refl : LinearEquiv.det (LinearEquiv.refl R M) = 1 :=
Units.ext <| LinearMap.det_id
#align linear_equiv.det_refl LinearEquiv.det_refl
@[simp]
theorem det_trans (f g : M ≃ₗ[R] M) :
LinearEquiv.det (f.trans g) = LinearEquiv.det g * LinearEquiv.det f :=
map_mul _ g f
#align linear_equiv.det_trans LinearEquiv.det_trans
@[simp, nolint simpNF]
theorem det_symm (f : M ≃ₗ[R] M) : LinearEquiv.det f.symm = LinearEquiv.det f⁻¹ :=
map_inv _ f
#align linear_equiv.det_symm LinearEquiv.det_symm
/-- Conjugating a linear equiv by a linear equiv does not change its determinant. -/
@[simp]
theorem det_conj (f : M ≃ₗ[R] M) (e : M ≃ₗ[R] M') :
LinearEquiv.det ((e.symm.trans f).trans e) = LinearEquiv.det f := by
rw [← Units.eq_iff, coe_det, coe_det, ← comp_coe, ← comp_coe, LinearMap.det_conj]
#align linear_equiv.det_conj LinearEquiv.det_conj
attribute [irreducible] LinearEquiv.det
end LinearEquiv
/-- The determinants of a `LinearEquiv` and its inverse multiply to 1. -/
@[simp]
theorem LinearEquiv.det_mul_det_symm {A : Type*} [CommRing A] [Module A M] (f : M ≃ₗ[A] M) :
LinearMap.det (f : M →ₗ[A] M) * LinearMap.det (f.symm : M →ₗ[A] M) = 1 := by
simp [← LinearMap.det_comp]
#align linear_equiv.det_mul_det_symm LinearEquiv.det_mul_det_symm
/-- The determinants of a `LinearEquiv` and its inverse multiply to 1. -/
@[simp]
theorem LinearEquiv.det_symm_mul_det {A : Type*} [CommRing A] [Module A M] (f : M ≃ₗ[A] M) :
LinearMap.det (f.symm : M →ₗ[A] M) * LinearMap.det (f : M →ₗ[A] M) = 1 := by
simp [← LinearMap.det_comp]
#align linear_equiv.det_symm_mul_det LinearEquiv.det_symm_mul_det
-- Cannot be stated using `LinearMap.det` because `f` is not an endomorphism.
theorem LinearEquiv.isUnit_det (f : M ≃ₗ[R] M') (v : Basis ι R M) (v' : Basis ι R M') :
IsUnit (LinearMap.toMatrix v v' f).det := by
apply isUnit_det_of_left_inverse
simpa using (LinearMap.toMatrix_comp v v' v f.symm f).symm
#align linear_equiv.is_unit_det LinearEquiv.isUnit_det
/-- Specialization of `LinearEquiv.isUnit_det` -/
theorem LinearEquiv.isUnit_det' {A : Type*} [CommRing A] [Module A M] (f : M ≃ₗ[A] M) :
IsUnit (LinearMap.det (f : M →ₗ[A] M)) :=
isUnit_of_mul_eq_one _ _ f.det_mul_det_symm
#align linear_equiv.is_unit_det' LinearEquiv.isUnit_det'
/-- The determinant of `f.symm` is the inverse of that of `f` when `f` is a linear equiv. -/
theorem LinearEquiv.det_coe_symm {𝕜 : Type*} [Field 𝕜] [Module 𝕜 M] (f : M ≃ₗ[𝕜] M) :
LinearMap.det (f.symm : M →ₗ[𝕜] M) = (LinearMap.det (f : M →ₗ[𝕜] M))⁻¹ := by
field_simp [IsUnit.ne_zero f.isUnit_det']
#align linear_equiv.det_coe_symm LinearEquiv.det_coe_symm
/-- Builds a linear equivalence from a linear map whose determinant in some bases is a unit. -/
@[simps]
def LinearEquiv.ofIsUnitDet {f : M →ₗ[R] M'} {v : Basis ι R M} {v' : Basis ι R M'}
(h : IsUnit (LinearMap.toMatrix v v' f).det) : M ≃ₗ[R] M' where
toFun := f
map_add' := f.map_add
map_smul' := f.map_smul
invFun := toLin v' v (toMatrix v v' f)⁻¹
left_inv x :=
calc toLin v' v (toMatrix v v' f)⁻¹ (f x)
_ = toLin v v ((toMatrix v v' f)⁻¹ * toMatrix v v' f) x := by
rw [toLin_mul v v' v, toLin_toMatrix, LinearMap.comp_apply]
_ = x := by simp [h]
right_inv x :=
calc f (toLin v' v (toMatrix v v' f)⁻¹ x)
_ = toLin v' v' (toMatrix v v' f * (toMatrix v v' f)⁻¹) x := by
rw [toLin_mul v' v v', LinearMap.comp_apply, toLin_toMatrix v v']
_ = x := by simp [h]
#align linear_equiv.of_is_unit_det LinearEquiv.ofIsUnitDet
@[simp]
theorem LinearEquiv.coe_ofIsUnitDet {f : M →ₗ[R] M'} {v : Basis ι R M} {v' : Basis ι R M'}
(h : IsUnit (LinearMap.toMatrix v v' f).det) :
(LinearEquiv.ofIsUnitDet h : M →ₗ[R] M') = f := by
ext x
rfl
#align linear_equiv.coe_of_is_unit_det LinearEquiv.coe_ofIsUnitDet
/-- Builds a linear equivalence from a linear map on a finite-dimensional vector space whose
determinant is nonzero. -/
abbrev LinearMap.equivOfDetNeZero {𝕜 : Type*} [Field 𝕜] {M : Type*} [AddCommGroup M] [Module 𝕜 M]
[FiniteDimensional 𝕜 M] (f : M →ₗ[𝕜] M) (hf : LinearMap.det f ≠ 0) : M ≃ₗ[𝕜] M :=
have : IsUnit (LinearMap.toMatrix (FiniteDimensional.finBasis 𝕜 M)
(FiniteDimensional.finBasis 𝕜 M) f).det := by
rw [LinearMap.det_toMatrix]
exact isUnit_iff_ne_zero.2 hf
LinearEquiv.ofIsUnitDet this
#align linear_map.equiv_of_det_ne_zero LinearMap.equivOfDetNeZero
theorem LinearMap.associated_det_of_eq_comp (e : M ≃ₗ[R] M) (f f' : M →ₗ[R] M)
(h : ∀ x, f x = f' (e x)) : Associated (LinearMap.det f) (LinearMap.det f') := by
suffices Associated (LinearMap.det (f' ∘ₗ ↑e)) (LinearMap.det f') by
convert this using 2
ext x
exact h x
rw [← mul_one (LinearMap.det f'), LinearMap.det_comp]
exact Associated.mul_left _ (associated_one_iff_isUnit.mpr e.isUnit_det')
#align linear_map.associated_det_of_eq_comp LinearMap.associated_det_of_eq_comp
theorem LinearMap.associated_det_comp_equiv {N : Type*} [AddCommGroup N] [Module R N]
(f : N →ₗ[R] M) (e e' : M ≃ₗ[R] N) :
Associated (LinearMap.det (f ∘ₗ ↑e)) (LinearMap.det (f ∘ₗ ↑e')) := by
refine LinearMap.associated_det_of_eq_comp (e.trans e'.symm) _ _ ?_
intro x
simp only [LinearMap.comp_apply, LinearEquiv.coe_coe, LinearEquiv.trans_apply,
LinearEquiv.apply_symm_apply]
#align linear_map.associated_det_comp_equiv LinearMap.associated_det_comp_equiv
/-- The determinant of a family of vectors with respect to some basis, as an alternating
multilinear map. -/
nonrec def Basis.det : M [⋀^ι]→ₗ[R] R where
toFun v := det (e.toMatrix v)
map_add' := by
intro inst v i x y
cases Subsingleton.elim inst ‹_›
simp only [e.toMatrix_update, LinearEquiv.map_add, Finsupp.coe_add]
-- Porting note: was `exact det_update_column_add _ _ _ _`
convert det_updateColumn_add (e.toMatrix v) i (e.repr x) (e.repr y)
map_smul' := by
intro inst u i c x
cases Subsingleton.elim inst ‹_›
simp only [e.toMatrix_update, Algebra.id.smul_eq_mul, LinearEquiv.map_smul]
-- Porting note: was `apply det_update_column_smul`
convert det_updateColumn_smul (e.toMatrix u) i c (e.repr x)
map_eq_zero_of_eq' := by
intro v i j h hij
-- Porting note: added
simp only
rw [← Function.update_eq_self i v, h, ← det_transpose, e.toMatrix_update, ← updateRow_transpose,
← e.toMatrix_transpose_apply]
apply det_zero_of_row_eq hij
rw [updateRow_ne hij.symm, updateRow_self]
#align basis.det Basis.det
theorem Basis.det_apply (v : ι → M) : e.det v = Matrix.det (e.toMatrix v) :=
rfl
#align basis.det_apply Basis.det_apply
theorem Basis.det_self : e.det e = 1 := by simp [e.det_apply]
#align basis.det_self Basis.det_self
@[simp]
theorem Basis.det_isEmpty [IsEmpty ι] : e.det = AlternatingMap.constOfIsEmpty R M ι 1 := by
ext v
exact Matrix.det_isEmpty
#align basis.det_is_empty Basis.det_isEmpty
/-- `Basis.det` is not the zero map. -/
theorem Basis.det_ne_zero [Nontrivial R] : e.det ≠ 0 := fun h => by simpa [h] using e.det_self
#align basis.det_ne_zero Basis.det_ne_zero
theorem is_basis_iff_det {v : ι → M} :
LinearIndependent R v ∧ span R (Set.range v) = ⊤ ↔ IsUnit (e.det v) := by
constructor
· rintro ⟨hli, hspan⟩
set v' := Basis.mk hli hspan.ge
rw [e.det_apply]
convert LinearEquiv.isUnit_det (LinearEquiv.refl R M) v' e using 2
ext i j
simp [v']
· intro h
rw [Basis.det_apply, Basis.toMatrix_eq_toMatrix_constr] at h
set v' := Basis.map e (LinearEquiv.ofIsUnitDet h) with v'_def
have : ⇑v' = v := by
ext i
rw [v'_def, Basis.map_apply, LinearEquiv.ofIsUnitDet_apply, e.constr_basis]
rw [← this]
exact ⟨v'.linearIndependent, v'.span_eq⟩
#align is_basis_iff_det is_basis_iff_det
theorem Basis.isUnit_det (e' : Basis ι R M) : IsUnit (e.det e') :=
(is_basis_iff_det e).mp ⟨e'.linearIndependent, e'.span_eq⟩
#align basis.is_unit_det Basis.isUnit_det
/-- Any alternating map to `R` where `ι` has the cardinality of a basis equals the determinant
map with respect to that basis, multiplied by the value of that alternating map on that basis. -/
theorem AlternatingMap.eq_smul_basis_det (f : M [⋀^ι]→ₗ[R] R) : f = f e • e.det := by
refine Basis.ext_alternating e fun i h => ?_
let σ : Equiv.Perm ι := Equiv.ofBijective i (Finite.injective_iff_bijective.1 h)
change f (e ∘ σ) = (f e • e.det) (e ∘ σ)
simp [AlternatingMap.map_perm, Basis.det_self]
#align alternating_map.eq_smul_basis_det AlternatingMap.eq_smul_basis_det
@[simp]
theorem AlternatingMap.map_basis_eq_zero_iff {ι : Type*} [Finite ι] (e : Basis ι R M)
(f : M [⋀^ι]→ₗ[R] R) : f e = 0 ↔ f = 0 :=
⟨fun h => by
cases nonempty_fintype ι
letI := Classical.decEq ι
simpa [h] using f.eq_smul_basis_det e,
fun h => h.symm ▸ AlternatingMap.zero_apply _⟩
#align alternating_map.map_basis_eq_zero_iff AlternatingMap.map_basis_eq_zero_iff
theorem AlternatingMap.map_basis_ne_zero_iff {ι : Type*} [Finite ι] (e : Basis ι R M)
(f : M [⋀^ι]→ₗ[R] R) : f e ≠ 0 ↔ f ≠ 0 :=
not_congr <| f.map_basis_eq_zero_iff e
#align alternating_map.map_basis_ne_zero_iff AlternatingMap.map_basis_ne_zero_iff
variable {A : Type*} [CommRing A] [Module A M]
@[simp]
theorem Basis.det_comp (e : Basis ι A M) (f : M →ₗ[A] M) (v : ι → M) :
e.det (f ∘ v) = (LinearMap.det f) * e.det v := by
rw [Basis.det_apply, Basis.det_apply, ← f.det_toMatrix e, ← Matrix.det_mul,
e.toMatrix_eq_toMatrix_constr (f ∘ v), e.toMatrix_eq_toMatrix_constr v, ← toMatrix_comp,
e.constr_comp]
#align basis.det_comp Basis.det_comp
@[simp]
theorem Basis.det_comp_basis [Module A M'] (b : Basis ι A M) (b' : Basis ι A M') (f : M →ₗ[A] M') :
b'.det (f ∘ b) = LinearMap.det (f ∘ₗ (b'.equiv b (Equiv.refl ι) : M' →ₗ[A] M)) := by
rw [Basis.det_apply, ← LinearMap.det_toMatrix b', LinearMap.toMatrix_comp _ b, Matrix.det_mul,
LinearMap.toMatrix_basis_equiv, Matrix.det_one, mul_one]
congr 1; ext i j
rw [Basis.toMatrix_apply, LinearMap.toMatrix_apply, Function.comp_apply]
#align basis.det_comp_basis Basis.det_comp_basis
theorem Basis.det_reindex {ι' : Type*} [Fintype ι'] [DecidableEq ι'] (b : Basis ι R M) (v : ι' → M)
(e : ι ≃ ι') : (b.reindex e).det v = b.det (v ∘ e) := by
rw [Basis.det_apply, Basis.toMatrix_reindex', det_reindexAlgEquiv, Basis.det_apply]
#align basis.det_reindex Basis.det_reindex
theorem Basis.det_reindex' {ι' : Type*} [Fintype ι'] [DecidableEq ι'] (b : Basis ι R M)
(e : ι ≃ ι') : (b.reindex e).det = b.det.domDomCongr e :=
AlternatingMap.ext fun _ => Basis.det_reindex _ _ _
#align basis.det_reindex' Basis.det_reindex'
| Mathlib/LinearAlgebra/Determinant.lean | 619 | 621 | theorem Basis.det_reindex_symm {ι' : Type*} [Fintype ι'] [DecidableEq ι'] (b : Basis ι R M)
(v : ι → M) (e : ι' ≃ ι) : (b.reindex e.symm).det (v ∘ e) = b.det v := by |
rw [Basis.det_reindex, Function.comp.assoc, e.self_comp_symm, Function.comp_id]
|
/-
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]
| Mathlib/SetTheory/Cardinal/Basic.lean | 1,142 | 1,145 | 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]
|
/-
Copyright (c) 2019 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Lu-Ming Zhang
-/
import Mathlib.Data.Matrix.Invertible
import Mathlib.LinearAlgebra.Matrix.Adjugate
import Mathlib.LinearAlgebra.FiniteDimensional
#align_import linear_algebra.matrix.nonsingular_inverse from "leanprover-community/mathlib"@"722b3b152ddd5e0cf21c0a29787c76596cb6b422"
/-!
# Nonsingular inverses
In this file, we define an inverse for square matrices of invertible determinant.
For matrices that are not square or not of full rank, there is a more general notion of
pseudoinverses which we do not consider here.
The definition of inverse used in this file is the adjugate divided by the determinant.
We show that dividing the adjugate by `det A` (if possible), giving a matrix `A⁻¹` (`nonsing_inv`),
will result in a multiplicative inverse to `A`.
Note that there are at least three different inverses in mathlib:
* `A⁻¹` (`Inv.inv`): alone, this satisfies no properties, although it is usually used in
conjunction with `Group` or `GroupWithZero`. On matrices, this is defined to be zero when no
inverse exists.
* `⅟A` (`invOf`): this is only available in the presence of `[Invertible A]`, which guarantees an
inverse exists.
* `Ring.inverse A`: this is defined on any `MonoidWithZero`, and just like `⁻¹` on matrices, is
defined to be zero when no inverse exists.
We start by working with `Invertible`, and show the main results:
* `Matrix.invertibleOfDetInvertible`
* `Matrix.detInvertibleOfInvertible`
* `Matrix.isUnit_iff_isUnit_det`
* `Matrix.mul_eq_one_comm`
After this we define `Matrix.inv` and show it matches `⅟A` and `Ring.inverse A`.
The rest of the results in the file are then about `A⁻¹`
## References
* https://en.wikipedia.org/wiki/Cramer's_rule#Finding_inverse_matrix
## Tags
matrix inverse, cramer, cramer's rule, adjugate
-/
namespace Matrix
universe u u' v
variable {l : Type*} {m : Type u} {n : Type u'} {α : Type v}
open Matrix Equiv Equiv.Perm Finset
/-! ### Matrices are `Invertible` iff their determinants are -/
section Invertible
variable [Fintype n] [DecidableEq n] [CommRing α]
variable (A : Matrix n n α) (B : Matrix n n α)
/-- If `A.det` has a constructive inverse, produce one for `A`. -/
def invertibleOfDetInvertible [Invertible A.det] : Invertible A where
invOf := ⅟ A.det • A.adjugate
mul_invOf_self := by
rw [mul_smul_comm, mul_adjugate, smul_smul, invOf_mul_self, one_smul]
invOf_mul_self := by
rw [smul_mul_assoc, adjugate_mul, smul_smul, invOf_mul_self, one_smul]
#align matrix.invertible_of_det_invertible Matrix.invertibleOfDetInvertible
theorem invOf_eq [Invertible A.det] [Invertible A] : ⅟ A = ⅟ A.det • A.adjugate := by
letI := invertibleOfDetInvertible A
convert (rfl : ⅟ A = _)
#align matrix.inv_of_eq Matrix.invOf_eq
/-- `A.det` is invertible if `A` has a left inverse. -/
def detInvertibleOfLeftInverse (h : B * A = 1) : Invertible A.det where
invOf := B.det
mul_invOf_self := by rw [mul_comm, ← det_mul, h, det_one]
invOf_mul_self := by rw [← det_mul, h, det_one]
#align matrix.det_invertible_of_left_inverse Matrix.detInvertibleOfLeftInverse
/-- `A.det` is invertible if `A` has a right inverse. -/
def detInvertibleOfRightInverse (h : A * B = 1) : Invertible A.det where
invOf := B.det
mul_invOf_self := by rw [← det_mul, h, det_one]
invOf_mul_self := by rw [mul_comm, ← det_mul, h, det_one]
#align matrix.det_invertible_of_right_inverse Matrix.detInvertibleOfRightInverse
/-- If `A` has a constructive inverse, produce one for `A.det`. -/
def detInvertibleOfInvertible [Invertible A] : Invertible A.det :=
detInvertibleOfLeftInverse A (⅟ A) (invOf_mul_self _)
#align matrix.det_invertible_of_invertible Matrix.detInvertibleOfInvertible
theorem det_invOf [Invertible A] [Invertible A.det] : (⅟ A).det = ⅟ A.det := by
letI := detInvertibleOfInvertible A
convert (rfl : _ = ⅟ A.det)
#align matrix.det_inv_of Matrix.det_invOf
/-- Together `Matrix.detInvertibleOfInvertible` and `Matrix.invertibleOfDetInvertible` form an
equivalence, although both sides of the equiv are subsingleton anyway. -/
@[simps]
def invertibleEquivDetInvertible : Invertible A ≃ Invertible A.det where
toFun := @detInvertibleOfInvertible _ _ _ _ _ A
invFun := @invertibleOfDetInvertible _ _ _ _ _ A
left_inv _ := Subsingleton.elim _ _
right_inv _ := Subsingleton.elim _ _
#align matrix.invertible_equiv_det_invertible Matrix.invertibleEquivDetInvertible
variable {A B}
theorem mul_eq_one_comm : A * B = 1 ↔ B * A = 1 :=
suffices ∀ A B : Matrix n n α, A * B = 1 → B * A = 1 from ⟨this A B, this B A⟩
fun A B h => by
letI : Invertible B.det := detInvertibleOfLeftInverse _ _ h
letI : Invertible B := invertibleOfDetInvertible B
calc
B * A = B * A * (B * ⅟ B) := by rw [mul_invOf_self, Matrix.mul_one]
_ = B * (A * B * ⅟ B) := by simp only [Matrix.mul_assoc]
_ = B * ⅟ B := by rw [h, Matrix.one_mul]
_ = 1 := mul_invOf_self B
#align matrix.mul_eq_one_comm Matrix.mul_eq_one_comm
variable (A B)
/-- We can construct an instance of invertible A if A has a left inverse. -/
def invertibleOfLeftInverse (h : B * A = 1) : Invertible A :=
⟨B, h, mul_eq_one_comm.mp h⟩
#align matrix.invertible_of_left_inverse Matrix.invertibleOfLeftInverse
/-- We can construct an instance of invertible A if A has a right inverse. -/
def invertibleOfRightInverse (h : A * B = 1) : Invertible A :=
⟨B, mul_eq_one_comm.mp h, h⟩
#align matrix.invertible_of_right_inverse Matrix.invertibleOfRightInverse
/-- Given a proof that `A.det` has a constructive inverse, lift `A` to `(Matrix n n α)ˣ`-/
def unitOfDetInvertible [Invertible A.det] : (Matrix n n α)ˣ :=
@unitOfInvertible _ _ A (invertibleOfDetInvertible A)
#align matrix.unit_of_det_invertible Matrix.unitOfDetInvertible
/-- When lowered to a prop, `Matrix.invertibleEquivDetInvertible` forms an `iff`. -/
theorem isUnit_iff_isUnit_det : IsUnit A ↔ IsUnit A.det := by
simp only [← nonempty_invertible_iff_isUnit, (invertibleEquivDetInvertible A).nonempty_congr]
#align matrix.is_unit_iff_is_unit_det Matrix.isUnit_iff_isUnit_det
@[simp]
theorem isUnits_det_units (A : (Matrix n n α)ˣ) : IsUnit (A : Matrix n n α).det :=
isUnit_iff_isUnit_det _ |>.mp A.isUnit
/-! #### Variants of the statements above with `IsUnit`-/
theorem isUnit_det_of_invertible [Invertible A] : IsUnit A.det :=
@isUnit_of_invertible _ _ _ (detInvertibleOfInvertible A)
#align matrix.is_unit_det_of_invertible Matrix.isUnit_det_of_invertible
variable {A B}
theorem isUnit_of_left_inverse (h : B * A = 1) : IsUnit A :=
⟨⟨A, B, mul_eq_one_comm.mp h, h⟩, rfl⟩
#align matrix.is_unit_of_left_inverse Matrix.isUnit_of_left_inverse
theorem exists_left_inverse_iff_isUnit : (∃ B, B * A = 1) ↔ IsUnit A :=
⟨fun ⟨_, h⟩ ↦ isUnit_of_left_inverse h, fun h ↦ have := h.invertible; ⟨⅟A, invOf_mul_self' A⟩⟩
theorem isUnit_of_right_inverse (h : A * B = 1) : IsUnit A :=
⟨⟨A, B, h, mul_eq_one_comm.mp h⟩, rfl⟩
#align matrix.is_unit_of_right_inverse Matrix.isUnit_of_right_inverse
theorem exists_right_inverse_iff_isUnit : (∃ B, A * B = 1) ↔ IsUnit A :=
⟨fun ⟨_, h⟩ ↦ isUnit_of_right_inverse h, fun h ↦ have := h.invertible; ⟨⅟A, mul_invOf_self' A⟩⟩
theorem isUnit_det_of_left_inverse (h : B * A = 1) : IsUnit A.det :=
@isUnit_of_invertible _ _ _ (detInvertibleOfLeftInverse _ _ h)
#align matrix.is_unit_det_of_left_inverse Matrix.isUnit_det_of_left_inverse
theorem isUnit_det_of_right_inverse (h : A * B = 1) : IsUnit A.det :=
@isUnit_of_invertible _ _ _ (detInvertibleOfRightInverse _ _ h)
#align matrix.is_unit_det_of_right_inverse Matrix.isUnit_det_of_right_inverse
theorem det_ne_zero_of_left_inverse [Nontrivial α] (h : B * A = 1) : A.det ≠ 0 :=
(isUnit_det_of_left_inverse h).ne_zero
#align matrix.det_ne_zero_of_left_inverse Matrix.det_ne_zero_of_left_inverse
theorem det_ne_zero_of_right_inverse [Nontrivial α] (h : A * B = 1) : A.det ≠ 0 :=
(isUnit_det_of_right_inverse h).ne_zero
#align matrix.det_ne_zero_of_right_inverse Matrix.det_ne_zero_of_right_inverse
end Invertible
section Inv
variable [Fintype n] [DecidableEq n] [CommRing α]
variable (A : Matrix n n α) (B : Matrix n n α)
theorem isUnit_det_transpose (h : IsUnit A.det) : IsUnit Aᵀ.det := by
rw [det_transpose]
exact h
#align matrix.is_unit_det_transpose Matrix.isUnit_det_transpose
/-! ### A noncomputable `Inv` instance -/
/-- The inverse of a square matrix, when it is invertible (and zero otherwise). -/
noncomputable instance inv : Inv (Matrix n n α) :=
⟨fun A => Ring.inverse A.det • A.adjugate⟩
theorem inv_def (A : Matrix n n α) : A⁻¹ = Ring.inverse A.det • A.adjugate :=
rfl
#align matrix.inv_def Matrix.inv_def
theorem nonsing_inv_apply_not_isUnit (h : ¬IsUnit A.det) : A⁻¹ = 0 := by
rw [inv_def, Ring.inverse_non_unit _ h, zero_smul]
#align matrix.nonsing_inv_apply_not_is_unit Matrix.nonsing_inv_apply_not_isUnit
theorem nonsing_inv_apply (h : IsUnit A.det) : A⁻¹ = (↑h.unit⁻¹ : α) • A.adjugate := by
rw [inv_def, ← Ring.inverse_unit h.unit, IsUnit.unit_spec]
#align matrix.nonsing_inv_apply Matrix.nonsing_inv_apply
/-- The nonsingular inverse is the same as `invOf` when `A` is invertible. -/
@[simp]
theorem invOf_eq_nonsing_inv [Invertible A] : ⅟ A = A⁻¹ := by
letI := detInvertibleOfInvertible A
rw [inv_def, Ring.inverse_invertible, invOf_eq]
#align matrix.inv_of_eq_nonsing_inv Matrix.invOf_eq_nonsing_inv
/-- Coercing the result of `Units.instInv` is the same as coercing first and applying the
nonsingular inverse. -/
@[simp, norm_cast]
theorem coe_units_inv (A : (Matrix n n α)ˣ) : ↑A⁻¹ = (A⁻¹ : Matrix n n α) := by
letI := A.invertible
rw [← invOf_eq_nonsing_inv, invOf_units]
#align matrix.coe_units_inv Matrix.coe_units_inv
/-- The nonsingular inverse is the same as the general `Ring.inverse`. -/
theorem nonsing_inv_eq_ring_inverse : A⁻¹ = Ring.inverse A := by
by_cases h_det : IsUnit A.det
· cases (A.isUnit_iff_isUnit_det.mpr h_det).nonempty_invertible
rw [← invOf_eq_nonsing_inv, Ring.inverse_invertible]
· have h := mt A.isUnit_iff_isUnit_det.mp h_det
rw [Ring.inverse_non_unit _ h, nonsing_inv_apply_not_isUnit A h_det]
#align matrix.nonsing_inv_eq_ring_inverse Matrix.nonsing_inv_eq_ring_inverse
theorem transpose_nonsing_inv : A⁻¹ᵀ = Aᵀ⁻¹ := by
rw [inv_def, inv_def, transpose_smul, det_transpose, adjugate_transpose]
#align matrix.transpose_nonsing_inv Matrix.transpose_nonsing_inv
theorem conjTranspose_nonsing_inv [StarRing α] : A⁻¹ᴴ = Aᴴ⁻¹ := by
rw [inv_def, inv_def, conjTranspose_smul, det_conjTranspose, adjugate_conjTranspose,
Ring.inverse_star]
#align matrix.conj_transpose_nonsing_inv Matrix.conjTranspose_nonsing_inv
/-- The `nonsing_inv` of `A` is a right inverse. -/
@[simp]
theorem mul_nonsing_inv (h : IsUnit A.det) : A * A⁻¹ = 1 := by
cases (A.isUnit_iff_isUnit_det.mpr h).nonempty_invertible
rw [← invOf_eq_nonsing_inv, mul_invOf_self]
#align matrix.mul_nonsing_inv Matrix.mul_nonsing_inv
/-- The `nonsing_inv` of `A` is a left inverse. -/
@[simp]
theorem nonsing_inv_mul (h : IsUnit A.det) : A⁻¹ * A = 1 := by
cases (A.isUnit_iff_isUnit_det.mpr h).nonempty_invertible
rw [← invOf_eq_nonsing_inv, invOf_mul_self]
#align matrix.nonsing_inv_mul Matrix.nonsing_inv_mul
instance [Invertible A] : Invertible A⁻¹ := by
rw [← invOf_eq_nonsing_inv]
infer_instance
@[simp]
theorem inv_inv_of_invertible [Invertible A] : A⁻¹⁻¹ = A := by
simp only [← invOf_eq_nonsing_inv, invOf_invOf]
#align matrix.inv_inv_of_invertible Matrix.inv_inv_of_invertible
@[simp]
theorem mul_nonsing_inv_cancel_right (B : Matrix m n α) (h : IsUnit A.det) : B * A * A⁻¹ = B := by
simp [Matrix.mul_assoc, mul_nonsing_inv A h]
#align matrix.mul_nonsing_inv_cancel_right Matrix.mul_nonsing_inv_cancel_right
@[simp]
theorem mul_nonsing_inv_cancel_left (B : Matrix n m α) (h : IsUnit A.det) : A * (A⁻¹ * B) = B := by
simp [← Matrix.mul_assoc, mul_nonsing_inv A h]
#align matrix.mul_nonsing_inv_cancel_left Matrix.mul_nonsing_inv_cancel_left
@[simp]
theorem nonsing_inv_mul_cancel_right (B : Matrix m n α) (h : IsUnit A.det) : B * A⁻¹ * A = B := by
simp [Matrix.mul_assoc, nonsing_inv_mul A h]
#align matrix.nonsing_inv_mul_cancel_right Matrix.nonsing_inv_mul_cancel_right
@[simp]
theorem nonsing_inv_mul_cancel_left (B : Matrix n m α) (h : IsUnit A.det) : A⁻¹ * (A * B) = B := by
simp [← Matrix.mul_assoc, nonsing_inv_mul A h]
#align matrix.nonsing_inv_mul_cancel_left Matrix.nonsing_inv_mul_cancel_left
@[simp]
theorem mul_inv_of_invertible [Invertible A] : A * A⁻¹ = 1 :=
mul_nonsing_inv A (isUnit_det_of_invertible A)
#align matrix.mul_inv_of_invertible Matrix.mul_inv_of_invertible
@[simp]
theorem inv_mul_of_invertible [Invertible A] : A⁻¹ * A = 1 :=
nonsing_inv_mul A (isUnit_det_of_invertible A)
#align matrix.inv_mul_of_invertible Matrix.inv_mul_of_invertible
@[simp]
theorem mul_inv_cancel_right_of_invertible (B : Matrix m n α) [Invertible A] : B * A * A⁻¹ = B :=
mul_nonsing_inv_cancel_right A B (isUnit_det_of_invertible A)
#align matrix.mul_inv_cancel_right_of_invertible Matrix.mul_inv_cancel_right_of_invertible
@[simp]
theorem mul_inv_cancel_left_of_invertible (B : Matrix n m α) [Invertible A] : A * (A⁻¹ * B) = B :=
mul_nonsing_inv_cancel_left A B (isUnit_det_of_invertible A)
#align matrix.mul_inv_cancel_left_of_invertible Matrix.mul_inv_cancel_left_of_invertible
@[simp]
theorem inv_mul_cancel_right_of_invertible (B : Matrix m n α) [Invertible A] : B * A⁻¹ * A = B :=
nonsing_inv_mul_cancel_right A B (isUnit_det_of_invertible A)
#align matrix.inv_mul_cancel_right_of_invertible Matrix.inv_mul_cancel_right_of_invertible
@[simp]
theorem inv_mul_cancel_left_of_invertible (B : Matrix n m α) [Invertible A] : A⁻¹ * (A * B) = B :=
nonsing_inv_mul_cancel_left A B (isUnit_det_of_invertible A)
#align matrix.inv_mul_cancel_left_of_invertible Matrix.inv_mul_cancel_left_of_invertible
theorem inv_mul_eq_iff_eq_mul_of_invertible (A B C : Matrix n n α) [Invertible A] :
A⁻¹ * B = C ↔ B = A * C :=
⟨fun h => by rw [← h, mul_inv_cancel_left_of_invertible],
fun h => by rw [h, inv_mul_cancel_left_of_invertible]⟩
#align matrix.inv_mul_eq_iff_eq_mul_of_invertible Matrix.inv_mul_eq_iff_eq_mul_of_invertible
theorem mul_inv_eq_iff_eq_mul_of_invertible (A B C : Matrix n n α) [Invertible A] :
B * A⁻¹ = C ↔ B = C * A :=
⟨fun h => by rw [← h, inv_mul_cancel_right_of_invertible],
fun h => by rw [h, mul_inv_cancel_right_of_invertible]⟩
#align matrix.mul_inv_eq_iff_eq_mul_of_invertible Matrix.mul_inv_eq_iff_eq_mul_of_invertible
lemma mul_right_injective_of_invertible [Invertible A] :
Function.Injective (fun (x : Matrix n m α) => A * x) :=
fun _ _ h => by simpa only [inv_mul_cancel_left_of_invertible] using congr_arg (A⁻¹ * ·) h
lemma mul_left_injective_of_invertible [Invertible A] :
Function.Injective (fun (x : Matrix m n α) => x * A) :=
fun a x hax => by simpa only [mul_inv_cancel_right_of_invertible] using congr_arg (· * A⁻¹) hax
lemma mul_right_inj_of_invertible [Invertible A] {x y : Matrix n m α} : A * x = A * y ↔ x = y :=
(mul_right_injective_of_invertible A).eq_iff
lemma mul_left_inj_of_invertible [Invertible A] {x y : Matrix m n α} : x * A = y * A ↔ x = y :=
(mul_left_injective_of_invertible A).eq_iff
end Inv
section InjectiveMul
variable [Fintype n] [Fintype m] [DecidableEq m] [CommRing α]
variable [Fintype l] [DecidableEq l]
lemma mul_left_injective_of_inv (A : Matrix m n α) (B : Matrix n m α) (h : A * B = 1) :
Function.Injective (fun x : Matrix l m α => x * A) := fun _ _ g => by
simpa only [Matrix.mul_assoc, Matrix.mul_one, h] using congr_arg (· * B) g
lemma mul_right_injective_of_inv (A : Matrix m n α) (B : Matrix n m α) (h : A * B = 1) :
Function.Injective (fun x : Matrix m l α => B * x) :=
fun _ _ g => by simpa only [← Matrix.mul_assoc, Matrix.one_mul, h] using congr_arg (A * ·) g
end InjectiveMul
section vecMul
variable [DecidableEq m] [DecidableEq n]
section Semiring
variable {R : Type*} [Semiring R]
theorem vecMul_surjective_iff_exists_left_inverse [Fintype m] [Finite n] {A : Matrix m n R} :
Function.Surjective A.vecMul ↔ ∃ B : Matrix n m R, B * A = 1 := by
cases nonempty_fintype n
refine ⟨fun h ↦ ?_, fun ⟨B, hBA⟩ y ↦ ⟨y ᵥ* B, by simp [hBA]⟩⟩
choose rows hrows using (h <| Pi.single · 1)
refine ⟨Matrix.of rows, Matrix.ext fun i j => ?_⟩
rw [mul_apply_eq_vecMul, one_eq_pi_single, ← hrows]
rfl
theorem mulVec_surjective_iff_exists_right_inverse [Finite m] [Fintype n] {A : Matrix m n R} :
Function.Surjective A.mulVec ↔ ∃ B : Matrix n m R, A * B = 1 := by
cases nonempty_fintype m
refine ⟨fun h ↦ ?_, fun ⟨B, hBA⟩ y ↦ ⟨B *ᵥ y, by simp [hBA]⟩⟩
choose cols hcols using (h <| Pi.single · 1)
refine ⟨(Matrix.of cols)ᵀ, Matrix.ext fun i j ↦ ?_⟩
rw [one_eq_pi_single, Pi.single_comm, ← hcols j]
rfl
end Semiring
variable {R K : Type*} [CommRing R] [Field K] [Fintype m]
theorem vecMul_surjective_iff_isUnit {A : Matrix m m R} :
Function.Surjective A.vecMul ↔ IsUnit A := by
rw [vecMul_surjective_iff_exists_left_inverse, exists_left_inverse_iff_isUnit]
theorem mulVec_surjective_iff_isUnit {A : Matrix m m R} :
Function.Surjective A.mulVec ↔ IsUnit A := by
rw [mulVec_surjective_iff_exists_right_inverse, exists_right_inverse_iff_isUnit]
theorem vecMul_injective_iff_isUnit {A : Matrix m m K} :
Function.Injective A.vecMul ↔ IsUnit A := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· rw [← vecMul_surjective_iff_isUnit]
exact LinearMap.surjective_of_injective (f := A.vecMulLinear) h
change Function.Injective A.vecMulLinear
rw [← LinearMap.ker_eq_bot, LinearMap.ker_eq_bot']
intro c hc
replace h := h.invertible
simpa using congr_arg A⁻¹.vecMulLinear hc
theorem mulVec_injective_iff_isUnit {A : Matrix m m K} :
Function.Injective A.mulVec ↔ IsUnit A := by
rw [← isUnit_transpose, ← vecMul_injective_iff_isUnit]
simp_rw [vecMul_transpose]
theorem linearIndependent_rows_iff_isUnit {A : Matrix m m K} :
LinearIndependent K (fun i ↦ A i) ↔ IsUnit A := by
rw [← transpose_transpose A, ← mulVec_injective_iff, ← coe_mulVecLin, mulVecLin_transpose,
transpose_transpose, ← vecMul_injective_iff_isUnit, coe_vecMulLinear]
theorem linearIndependent_cols_iff_isUnit {A : Matrix m m K} :
LinearIndependent K (fun i ↦ Aᵀ i) ↔ IsUnit A := by
rw [← transpose_transpose A, isUnit_transpose, linearIndependent_rows_iff_isUnit,
transpose_transpose]
theorem vecMul_surjective_of_invertible (A : Matrix m m R) [Invertible A] :
Function.Surjective A.vecMul :=
vecMul_surjective_iff_isUnit.2 <| isUnit_of_invertible A
theorem mulVec_surjective_of_invertible (A : Matrix m m R) [Invertible A] :
Function.Surjective A.mulVec :=
mulVec_surjective_iff_isUnit.2 <| isUnit_of_invertible A
theorem vecMul_injective_of_invertible (A : Matrix m m K) [Invertible A] :
Function.Injective A.vecMul :=
vecMul_injective_iff_isUnit.2 <| isUnit_of_invertible A
theorem mulVec_injective_of_invertible (A : Matrix m m K) [Invertible A] :
Function.Injective A.mulVec :=
mulVec_injective_iff_isUnit.2 <| isUnit_of_invertible A
theorem linearIndependent_rows_of_invertible (A : Matrix m m K) [Invertible A] :
LinearIndependent K (fun i ↦ A i) :=
linearIndependent_rows_iff_isUnit.2 <| isUnit_of_invertible A
theorem linearIndependent_cols_of_invertible (A : Matrix m m K) [Invertible A] :
LinearIndependent K (fun i ↦ Aᵀ i) :=
linearIndependent_cols_iff_isUnit.2 <| isUnit_of_invertible A
end vecMul
variable [Fintype n] [DecidableEq n] [CommRing α]
variable (A : Matrix n n α) (B : Matrix n n α)
theorem nonsing_inv_cancel_or_zero : A⁻¹ * A = 1 ∧ A * A⁻¹ = 1 ∨ A⁻¹ = 0 := by
by_cases h : IsUnit A.det
· exact Or.inl ⟨nonsing_inv_mul _ h, mul_nonsing_inv _ h⟩
· exact Or.inr (nonsing_inv_apply_not_isUnit _ h)
#align matrix.nonsing_inv_cancel_or_zero Matrix.nonsing_inv_cancel_or_zero
theorem det_nonsing_inv_mul_det (h : IsUnit A.det) : A⁻¹.det * A.det = 1 := by
rw [← det_mul, A.nonsing_inv_mul h, det_one]
#align matrix.det_nonsing_inv_mul_det Matrix.det_nonsing_inv_mul_det
@[simp]
theorem det_nonsing_inv : A⁻¹.det = Ring.inverse A.det := by
by_cases h : IsUnit A.det
· cases h.nonempty_invertible
letI := invertibleOfDetInvertible A
rw [Ring.inverse_invertible, ← invOf_eq_nonsing_inv, det_invOf]
cases isEmpty_or_nonempty n
· rw [det_isEmpty, det_isEmpty, Ring.inverse_one]
· rw [Ring.inverse_non_unit _ h, nonsing_inv_apply_not_isUnit _ h, det_zero ‹_›]
#align matrix.det_nonsing_inv Matrix.det_nonsing_inv
theorem isUnit_nonsing_inv_det (h : IsUnit A.det) : IsUnit A⁻¹.det :=
isUnit_of_mul_eq_one _ _ (A.det_nonsing_inv_mul_det h)
#align matrix.is_unit_nonsing_inv_det Matrix.isUnit_nonsing_inv_det
@[simp]
theorem nonsing_inv_nonsing_inv (h : IsUnit A.det) : A⁻¹⁻¹ = A :=
calc
A⁻¹⁻¹ = 1 * A⁻¹⁻¹ := by rw [Matrix.one_mul]
_ = A * A⁻¹ * A⁻¹⁻¹ := by rw [A.mul_nonsing_inv h]
_ = A := by
rw [Matrix.mul_assoc, A⁻¹.mul_nonsing_inv (A.isUnit_nonsing_inv_det h), Matrix.mul_one]
#align matrix.nonsing_inv_nonsing_inv Matrix.nonsing_inv_nonsing_inv
theorem isUnit_nonsing_inv_det_iff {A : Matrix n n α} : IsUnit A⁻¹.det ↔ IsUnit A.det := by
rw [Matrix.det_nonsing_inv, isUnit_ring_inverse]
#align matrix.is_unit_nonsing_inv_det_iff Matrix.isUnit_nonsing_inv_det_iff
-- `IsUnit.invertible` lifts the proposition `IsUnit A` to a constructive inverse of `A`.
/-- A version of `Matrix.invertibleOfDetInvertible` with the inverse defeq to `A⁻¹` that is
therefore noncomputable. -/
noncomputable def invertibleOfIsUnitDet (h : IsUnit A.det) : Invertible A :=
⟨A⁻¹, nonsing_inv_mul A h, mul_nonsing_inv A h⟩
#align matrix.invertible_of_is_unit_det Matrix.invertibleOfIsUnitDet
/-- A version of `Matrix.unitOfDetInvertible` with the inverse defeq to `A⁻¹` that is therefore
noncomputable. -/
noncomputable def nonsingInvUnit (h : IsUnit A.det) : (Matrix n n α)ˣ :=
@unitOfInvertible _ _ _ (invertibleOfIsUnitDet A h)
#align matrix.nonsing_inv_unit Matrix.nonsingInvUnit
theorem unitOfDetInvertible_eq_nonsingInvUnit [Invertible A.det] :
unitOfDetInvertible A = nonsingInvUnit A (isUnit_of_invertible _) := by
ext
rfl
#align matrix.unit_of_det_invertible_eq_nonsing_inv_unit Matrix.unitOfDetInvertible_eq_nonsingInvUnit
variable {A} {B}
/-- If matrix A is left invertible, then its inverse equals its left inverse. -/
theorem inv_eq_left_inv (h : B * A = 1) : A⁻¹ = B :=
letI := invertibleOfLeftInverse _ _ h
invOf_eq_nonsing_inv A ▸ invOf_eq_left_inv h
#align matrix.inv_eq_left_inv Matrix.inv_eq_left_inv
/-- If matrix A is right invertible, then its inverse equals its right inverse. -/
theorem inv_eq_right_inv (h : A * B = 1) : A⁻¹ = B :=
inv_eq_left_inv (mul_eq_one_comm.2 h)
#align matrix.inv_eq_right_inv Matrix.inv_eq_right_inv
section InvEqInv
variable {C : Matrix n n α}
/-- The left inverse of matrix A is unique when existing. -/
theorem left_inv_eq_left_inv (h : B * A = 1) (g : C * A = 1) : B = C := by
rw [← inv_eq_left_inv h, ← inv_eq_left_inv g]
#align matrix.left_inv_eq_left_inv Matrix.left_inv_eq_left_inv
/-- The right inverse of matrix A is unique when existing. -/
theorem right_inv_eq_right_inv (h : A * B = 1) (g : A * C = 1) : B = C := by
rw [← inv_eq_right_inv h, ← inv_eq_right_inv g]
#align matrix.right_inv_eq_right_inv Matrix.right_inv_eq_right_inv
/-- The right inverse of matrix A equals the left inverse of A when they exist. -/
theorem right_inv_eq_left_inv (h : A * B = 1) (g : C * A = 1) : B = C := by
rw [← inv_eq_right_inv h, ← inv_eq_left_inv g]
#align matrix.right_inv_eq_left_inv Matrix.right_inv_eq_left_inv
theorem inv_inj (h : A⁻¹ = B⁻¹) (h' : IsUnit A.det) : A = B := by
refine left_inv_eq_left_inv (mul_nonsing_inv _ h') ?_
rw [h]
refine mul_nonsing_inv _ ?_
rwa [← isUnit_nonsing_inv_det_iff, ← h, isUnit_nonsing_inv_det_iff]
#align matrix.inv_inj Matrix.inv_inj
end InvEqInv
variable (A)
@[simp]
| Mathlib/LinearAlgebra/Matrix/NonsingularInverse.lean | 572 | 582 | theorem inv_zero : (0 : Matrix n n α)⁻¹ = 0 := by |
cases' subsingleton_or_nontrivial α with ht ht
· simp [eq_iff_true_of_subsingleton]
rcases (Fintype.card n).zero_le.eq_or_lt with hc | hc
· rw [eq_comm, Fintype.card_eq_zero_iff] at hc
haveI := hc
ext i
exact (IsEmpty.false i).elim
· have hn : Nonempty n := Fintype.card_pos_iff.mp hc
refine nonsing_inv_apply_not_isUnit _ ?_
simp [hn]
|
/-
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.GroupPower.IterateHom
import Mathlib.Algebra.Polynomial.Eval
import Mathlib.GroupTheory.GroupAction.Ring
#align_import data.polynomial.derivative from "leanprover-community/mathlib"@"bbeb185db4ccee8ed07dc48449414ebfa39cb821"
/-!
# The derivative map on polynomials
## Main definitions
* `Polynomial.derivative`: The formal derivative of polynomials, expressed as a linear map.
-/
noncomputable section
open Finset
open Polynomial
namespace Polynomial
universe u v w y z
variable {R : Type u} {S : Type v} {T : Type w} {ι : Type y} {A : Type z} {a b : R} {n : ℕ}
section Derivative
section Semiring
variable [Semiring R]
/-- `derivative p` is the formal derivative of the polynomial `p` -/
def derivative : R[X] →ₗ[R] R[X] where
toFun p := p.sum fun n a => C (a * n) * X ^ (n - 1)
map_add' p q := by
dsimp only
rw [sum_add_index] <;>
simp only [add_mul, forall_const, RingHom.map_add, eq_self_iff_true, zero_mul,
RingHom.map_zero]
map_smul' a p := by
dsimp; rw [sum_smul_index] <;>
simp only [mul_sum, ← C_mul', mul_assoc, coeff_C_mul, RingHom.map_mul, forall_const, zero_mul,
RingHom.map_zero, sum]
#align polynomial.derivative Polynomial.derivative
theorem derivative_apply (p : R[X]) : derivative p = p.sum fun n a => C (a * n) * X ^ (n - 1) :=
rfl
#align polynomial.derivative_apply Polynomial.derivative_apply
theorem coeff_derivative (p : R[X]) (n : ℕ) :
coeff (derivative p) n = coeff p (n + 1) * (n + 1) := by
rw [derivative_apply]
simp only [coeff_X_pow, coeff_sum, coeff_C_mul]
rw [sum, Finset.sum_eq_single (n + 1)]
· simp only [Nat.add_succ_sub_one, add_zero, mul_one, if_true, eq_self_iff_true]; norm_cast
· intro b
cases b
· intros
rw [Nat.cast_zero, mul_zero, zero_mul]
· intro _ H
rw [Nat.add_one_sub_one, if_neg (mt (congr_arg Nat.succ) H.symm), mul_zero]
· rw [if_pos (add_tsub_cancel_right n 1).symm, mul_one, Nat.cast_add, Nat.cast_one,
mem_support_iff]
intro h
push_neg at h
simp [h]
#align polynomial.coeff_derivative Polynomial.coeff_derivative
-- Porting note (#10618): removed `simp`: `simp` can prove it.
theorem derivative_zero : derivative (0 : R[X]) = 0 :=
derivative.map_zero
#align polynomial.derivative_zero Polynomial.derivative_zero
theorem iterate_derivative_zero {k : ℕ} : derivative^[k] (0 : R[X]) = 0 :=
iterate_map_zero derivative k
#align polynomial.iterate_derivative_zero Polynomial.iterate_derivative_zero
@[simp]
theorem derivative_monomial (a : R) (n : ℕ) :
derivative (monomial n a) = monomial (n - 1) (a * n) := by
rw [derivative_apply, sum_monomial_index, C_mul_X_pow_eq_monomial]
simp
#align polynomial.derivative_monomial Polynomial.derivative_monomial
theorem derivative_C_mul_X (a : R) : derivative (C a * X) = C a := by
simp [C_mul_X_eq_monomial, derivative_monomial, Nat.cast_one, mul_one]
set_option linter.uppercaseLean3 false in
#align polynomial.derivative_C_mul_X Polynomial.derivative_C_mul_X
theorem derivative_C_mul_X_pow (a : R) (n : ℕ) :
derivative (C a * X ^ n) = C (a * n) * X ^ (n - 1) := by
rw [C_mul_X_pow_eq_monomial, C_mul_X_pow_eq_monomial, derivative_monomial]
set_option linter.uppercaseLean3 false in
#align polynomial.derivative_C_mul_X_pow Polynomial.derivative_C_mul_X_pow
theorem derivative_C_mul_X_sq (a : R) : derivative (C a * X ^ 2) = C (a * 2) * X := by
rw [derivative_C_mul_X_pow, Nat.cast_two, pow_one]
set_option linter.uppercaseLean3 false in
#align polynomial.derivative_C_mul_X_sq Polynomial.derivative_C_mul_X_sq
@[simp]
theorem derivative_X_pow (n : ℕ) : derivative (X ^ n : R[X]) = C (n : R) * X ^ (n - 1) := by
convert derivative_C_mul_X_pow (1 : R) n <;> simp
set_option linter.uppercaseLean3 false in
#align polynomial.derivative_X_pow Polynomial.derivative_X_pow
-- Porting note (#10618): removed `simp`: `simp` can prove it.
theorem derivative_X_sq : derivative (X ^ 2 : R[X]) = C 2 * X := by
rw [derivative_X_pow, Nat.cast_two, pow_one]
set_option linter.uppercaseLean3 false in
#align polynomial.derivative_X_sq Polynomial.derivative_X_sq
@[simp]
theorem derivative_C {a : R} : derivative (C a) = 0 := by simp [derivative_apply]
set_option linter.uppercaseLean3 false in
#align polynomial.derivative_C Polynomial.derivative_C
theorem derivative_of_natDegree_zero {p : R[X]} (hp : p.natDegree = 0) : derivative p = 0 := by
rw [eq_C_of_natDegree_eq_zero hp, derivative_C]
#align polynomial.derivative_of_nat_degree_zero Polynomial.derivative_of_natDegree_zero
@[simp]
theorem derivative_X : derivative (X : R[X]) = 1 :=
(derivative_monomial _ _).trans <| by simp
set_option linter.uppercaseLean3 false in
#align polynomial.derivative_X Polynomial.derivative_X
@[simp]
theorem derivative_one : derivative (1 : R[X]) = 0 :=
derivative_C
#align polynomial.derivative_one Polynomial.derivative_one
#noalign polynomial.derivative_bit0
#noalign polynomial.derivative_bit1
-- Porting note (#10618): removed `simp`: `simp` can prove it.
theorem derivative_add {f g : R[X]} : derivative (f + g) = derivative f + derivative g :=
derivative.map_add f g
#align polynomial.derivative_add Polynomial.derivative_add
-- Porting note (#10618): removed `simp`: `simp` can prove it.
theorem derivative_X_add_C (c : R) : derivative (X + C c) = 1 := by
rw [derivative_add, derivative_X, derivative_C, add_zero]
set_option linter.uppercaseLean3 false in
#align polynomial.derivative_X_add_C Polynomial.derivative_X_add_C
-- Porting note (#10618): removed `simp`: `simp` can prove it.
theorem derivative_sum {s : Finset ι} {f : ι → R[X]} :
derivative (∑ b ∈ s, f b) = ∑ b ∈ s, derivative (f b) :=
map_sum ..
#align polynomial.derivative_sum Polynomial.derivative_sum
-- Porting note (#10618): removed `simp`: `simp` can prove it.
theorem derivative_smul {S : Type*} [Monoid S] [DistribMulAction S R] [IsScalarTower S R R] (s : S)
(p : R[X]) : derivative (s • p) = s • derivative p :=
derivative.map_smul_of_tower s p
#align polynomial.derivative_smul Polynomial.derivative_smul
@[simp]
theorem iterate_derivative_smul {S : Type*} [Monoid S] [DistribMulAction S R] [IsScalarTower S R R]
(s : S) (p : R[X]) (k : ℕ) : derivative^[k] (s • p) = s • derivative^[k] p := by
induction' k with k ih generalizing p
· simp
· simp [ih]
#align polynomial.iterate_derivative_smul Polynomial.iterate_derivative_smul
@[simp]
| Mathlib/Algebra/Polynomial/Derivative.lean | 175 | 177 | theorem iterate_derivative_C_mul (a : R) (p : R[X]) (k : ℕ) :
derivative^[k] (C a * p) = C a * derivative^[k] p := by |
simp_rw [← smul_eq_C_mul, iterate_derivative_smul]
|
/-
Copyright (c) 2022 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.AlgebraicTopology.DoldKan.FunctorGamma
import Mathlib.AlgebraicTopology.DoldKan.SplitSimplicialObject
import Mathlib.CategoryTheory.Idempotents.HomologicalComplex
#align_import algebraic_topology.dold_kan.gamma_comp_n from "leanprover-community/mathlib"@"32a7e535287f9c73f2e4d2aef306a39190f0b504"
/-! The counit isomorphism of the Dold-Kan equivalence
The purpose of this file is to construct natural isomorphisms
`N₁Γ₀ : Γ₀ ⋙ N₁ ≅ toKaroubi (ChainComplex C ℕ)`
and `N₂Γ₂ : Γ₂ ⋙ N₂ ≅ 𝟭 (Karoubi (ChainComplex C ℕ))`.
(See `Equivalence.lean` for the general strategy of proof of the Dold-Kan equivalence.)
-/
noncomputable section
open CategoryTheory CategoryTheory.Category CategoryTheory.Limits
CategoryTheory.Idempotents Opposite SimplicialObject Simplicial
namespace AlgebraicTopology
namespace DoldKan
variable {C : Type*} [Category C] [Preadditive C] [HasFiniteCoproducts C]
/-- The isomorphism `(Γ₀.splitting K).nondegComplex ≅ K` for all `K : ChainComplex C ℕ`. -/
@[simps!]
def Γ₀NondegComplexIso (K : ChainComplex C ℕ) : (Γ₀.splitting K).nondegComplex ≅ K :=
HomologicalComplex.Hom.isoOfComponents (fun n => Iso.refl _)
(by
rintro _ n (rfl : n + 1 = _)
dsimp
simp only [id_comp, comp_id, AlternatingFaceMapComplex.obj_d_eq, Preadditive.sum_comp,
Preadditive.comp_sum]
rw [Fintype.sum_eq_single (0 : Fin (n + 2))]
· simp only [Fin.val_zero, pow_zero, one_zsmul]
erw [Γ₀.Obj.mapMono_on_summand_id_assoc, Γ₀.Obj.Termwise.mapMono_δ₀,
Splitting.cofan_inj_πSummand_eq_id, comp_id]
· intro i hi
dsimp
simp only [Preadditive.zsmul_comp, Preadditive.comp_zsmul, assoc]
erw [Γ₀.Obj.mapMono_on_summand_id_assoc, Γ₀.Obj.Termwise.mapMono_eq_zero, zero_comp,
zsmul_zero]
· intro h
replace h := congr_arg SimplexCategory.len h
change n + 1 = n at h
omega
· simpa only [Isδ₀.iff] using hi)
#align algebraic_topology.dold_kan.Γ₀_nondeg_complex_iso AlgebraicTopology.DoldKan.Γ₀NondegComplexIso
/-- The natural isomorphism `(Γ₀.splitting K).nondegComplex ≅ K` for `K : ChainComplex C ℕ`. -/
def Γ₀'CompNondegComplexFunctor : Γ₀' ⋙ Split.nondegComplexFunctor ≅ 𝟭 (ChainComplex C ℕ) :=
NatIso.ofComponents Γ₀NondegComplexIso
#align algebraic_topology.dold_kan.Γ₀'_comp_nondeg_complex_functor AlgebraicTopology.DoldKan.Γ₀'CompNondegComplexFunctor
/-- The natural isomorphism `Γ₀ ⋙ N₁ ≅ toKaroubi (ChainComplex C ℕ)`. -/
def N₁Γ₀ : Γ₀ ⋙ N₁ ≅ toKaroubi (ChainComplex C ℕ) :=
calc
Γ₀ ⋙ N₁ ≅ Γ₀' ⋙ Split.forget C ⋙ N₁ := Functor.associator _ _ _
_ ≅ Γ₀' ⋙ Split.nondegComplexFunctor ⋙ toKaroubi _ :=
(isoWhiskerLeft Γ₀' Split.toKaroubiNondegComplexFunctorIsoN₁.symm)
_ ≅ (Γ₀' ⋙ Split.nondegComplexFunctor) ⋙ toKaroubi _ := (Functor.associator _ _ _).symm
_ ≅ 𝟭 _ ⋙ toKaroubi (ChainComplex C ℕ) := isoWhiskerRight Γ₀'CompNondegComplexFunctor _
_ ≅ toKaroubi (ChainComplex C ℕ) := Functor.leftUnitor _
set_option linter.uppercaseLean3 false in
#align algebraic_topology.dold_kan.N₁Γ₀ AlgebraicTopology.DoldKan.N₁Γ₀
theorem N₁Γ₀_app (K : ChainComplex C ℕ) :
N₁Γ₀.app K = (Γ₀.splitting K).toKaroubiNondegComplexIsoN₁.symm ≪≫
(toKaroubi _).mapIso (Γ₀NondegComplexIso K) := by
ext1
dsimp [N₁Γ₀]
erw [id_comp, comp_id, comp_id]
rfl
set_option linter.uppercaseLean3 false in
#align algebraic_topology.dold_kan.N₁Γ₀_app AlgebraicTopology.DoldKan.N₁Γ₀_app
theorem N₁Γ₀_hom_app (K : ChainComplex C ℕ) :
N₁Γ₀.hom.app K = (Γ₀.splitting K).toKaroubiNondegComplexIsoN₁.inv ≫
(toKaroubi _).map (Γ₀NondegComplexIso K).hom := by
change (N₁Γ₀.app K).hom = _
simp only [N₁Γ₀_app]
rfl
set_option linter.uppercaseLean3 false in
#align algebraic_topology.dold_kan.N₁Γ₀_hom_app AlgebraicTopology.DoldKan.N₁Γ₀_hom_app
theorem N₁Γ₀_inv_app (K : ChainComplex C ℕ) :
N₁Γ₀.inv.app K = (toKaroubi _).map (Γ₀NondegComplexIso K).inv ≫
(Γ₀.splitting K).toKaroubiNondegComplexIsoN₁.hom := by
change (N₁Γ₀.app K).inv = _
simp only [N₁Γ₀_app]
rfl
set_option linter.uppercaseLean3 false in
#align algebraic_topology.dold_kan.N₁Γ₀_inv_app AlgebraicTopology.DoldKan.N₁Γ₀_inv_app
@[simp]
theorem N₁Γ₀_hom_app_f_f (K : ChainComplex C ℕ) (n : ℕ) :
(N₁Γ₀.hom.app K).f.f n = (Γ₀.splitting K).toKaroubiNondegComplexIsoN₁.inv.f.f n := by
rw [N₁Γ₀_hom_app]
apply comp_id
set_option linter.uppercaseLean3 false in
#align algebraic_topology.dold_kan.N₁Γ₀_hom_app_f_f AlgebraicTopology.DoldKan.N₁Γ₀_hom_app_f_f
@[simp]
| Mathlib/AlgebraicTopology/DoldKan/GammaCompN.lean | 113 | 116 | theorem N₁Γ₀_inv_app_f_f (K : ChainComplex C ℕ) (n : ℕ) :
(N₁Γ₀.inv.app K).f.f n = (Γ₀.splitting K).toKaroubiNondegComplexIsoN₁.hom.f.f n := by |
rw [N₁Γ₀_inv_app]
apply id_comp
|
/-
Copyright (c) 2022 Anand Rao, Rémi Bottinelli. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anand Rao, Rémi Bottinelli
-/
import Mathlib.CategoryTheory.CofilteredSystem
import Mathlib.Combinatorics.SimpleGraph.Connectivity
import Mathlib.Data.Finite.Set
#align_import combinatorics.simple_graph.ends.defs from "leanprover-community/mathlib"@"b99e2d58a5e6861833fa8de11e51a81144258db4"
/-!
# Ends
This file contains a definition of the ends of a simple graph, as sections of the inverse system
assigning, to each finite set of vertices, the connected components of its complement.
-/
universe u
variable {V : Type u} (G : SimpleGraph V) (K L L' M : Set V)
namespace SimpleGraph
/-- The components outside a given set of vertices `K` -/
abbrev ComponentCompl :=
(G.induce Kᶜ).ConnectedComponent
#align simple_graph.component_compl SimpleGraph.ComponentCompl
variable {G} {K L M}
/-- The connected component of `v` in `G.induce Kᶜ`. -/
abbrev componentComplMk (G : SimpleGraph V) {v : V} (vK : v ∉ K) : G.ComponentCompl K :=
connectedComponentMk (G.induce Kᶜ) ⟨v, vK⟩
#align simple_graph.component_compl_mk SimpleGraph.componentComplMk
/-- The set of vertices of `G` making up the connected component `C` -/
def ComponentCompl.supp (C : G.ComponentCompl K) : Set V :=
{ v : V | ∃ h : v ∉ K, G.componentComplMk h = C }
#align simple_graph.component_compl.supp SimpleGraph.ComponentCompl.supp
@[ext]
| Mathlib/Combinatorics/SimpleGraph/Ends/Defs.lean | 44 | 49 | theorem ComponentCompl.supp_injective :
Function.Injective (ComponentCompl.supp : G.ComponentCompl K → Set V) := by |
refine ConnectedComponent.ind₂ ?_
rintro ⟨v, hv⟩ ⟨w, hw⟩ h
simp only [Set.ext_iff, ConnectedComponent.eq, Set.mem_setOf_eq, ComponentCompl.supp] at h ⊢
exact ((h v).mp ⟨hv, Reachable.refl _⟩).choose_spec
|
/-
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]
| Mathlib/Algebra/CharZero/Lemmas.lean | 88 | 89 | 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]
|
/-
Copyright (c) 2020 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts
import Mathlib.CategoryTheory.Limits.Shapes.Kernels
import Mathlib.CategoryTheory.Limits.Shapes.NormalMono.Equalizers
import Mathlib.CategoryTheory.Abelian.Images
import Mathlib.CategoryTheory.Preadditive.Basic
#align_import category_theory.abelian.non_preadditive from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3"
/-!
# Every NonPreadditiveAbelian category is preadditive
In mathlib, we define an abelian category as a preadditive category with a zero object,
kernels and cokernels, products and coproducts and in which every monomorphism and epimorphism is
normal.
While virtually every interesting abelian category has a natural preadditive structure (which is why
it is included in the definition), preadditivity is not actually needed: Every category that has
all of the other properties appearing in the definition of an abelian category admits a preadditive
structure. This is the construction we carry out in this file.
The proof proceeds in roughly five steps:
1. Prove some results (for example that all equalizers exist) that would be trivial if we already
had the preadditive structure but are a bit of work without it.
2. Develop images and coimages to show that every monomorphism is the kernel of its cokernel.
The results of the first two steps are also useful for the "normal" development of abelian
categories, and will be used there.
3. For every object `A`, define a "subtraction" morphism `σ : A ⨯ A ⟶ A` and use it to define
subtraction on morphisms as `f - g := prod.lift f g ≫ σ`.
4. Prove a small number of identities about this subtraction from the definition of `σ`.
5. From these identities, prove a large number of other identities that imply that defining
`f + g := f - (0 - g)` indeed gives an abelian group structure on morphisms such that composition
is bilinear.
The construction is non-trivial and it is quite remarkable that this abelian group structure can
be constructed purely from the existence of a few limits and colimits. Even more remarkably,
since abelian categories admit exactly one preadditive structure (see
`subsingletonPreadditiveOfHasBinaryBiproducts`), the construction manages to exactly
reconstruct any natural preadditive structure the category may have.
## References
* [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2]
-/
noncomputable section
open CategoryTheory
open CategoryTheory.Limits
namespace CategoryTheory
section
universe v u
variable (C : Type u) [Category.{v} C]
/-- We call a category `NonPreadditiveAbelian` if it has a zero object, kernels, cokernels, binary
products and coproducts, and every monomorphism and every epimorphism is normal. -/
class NonPreadditiveAbelian extends HasZeroMorphisms C, NormalMonoCategory C,
NormalEpiCategory C where
[has_zero_object : HasZeroObject C]
[has_kernels : HasKernels C]
[has_cokernels : HasCokernels C]
[has_finite_products : HasFiniteProducts C]
[has_finite_coproducts : HasFiniteCoproducts C]
#align category_theory.non_preadditive_abelian CategoryTheory.NonPreadditiveAbelian
attribute [instance] NonPreadditiveAbelian.has_zero_object
attribute [instance] NonPreadditiveAbelian.has_kernels
attribute [instance] NonPreadditiveAbelian.has_cokernels
attribute [instance] NonPreadditiveAbelian.has_finite_products
attribute [instance] NonPreadditiveAbelian.has_finite_coproducts
end
end CategoryTheory
open CategoryTheory
universe v u
variable {C : Type u} [Category.{v} C] [NonPreadditiveAbelian C]
namespace CategoryTheory.NonPreadditiveAbelian
section Factor
variable {P Q : C} (f : P ⟶ Q)
/-- The map `p : P ⟶ image f` is an epimorphism -/
instance : Epi (Abelian.factorThruImage f) :=
let I := Abelian.image f
let p := Abelian.factorThruImage f
let i := kernel.ι (cokernel.π f)
-- It will suffice to consider some g : I ⟶ R such that p ≫ g = 0 and show that g = 0.
NormalMonoCategory.epi_of_zero_cancel
_ fun R (g : I ⟶ R) (hpg : p ≫ g = 0) => by
-- Since C is abelian, u := ker g ≫ i is the kernel of some morphism h.
let u := kernel.ι g ≫ i
haveI : Mono u := mono_comp _ _
haveI hu := normalMonoOfMono u
let h := hu.g
-- By hypothesis, p factors through the kernel of g via some t.
obtain ⟨t, ht⟩ := kernel.lift' g p hpg
have fh : f ≫ h = 0 :=
calc
f ≫ h = (p ≫ i) ≫ h := (Abelian.image.fac f).symm ▸ rfl
_ = ((t ≫ kernel.ι g) ≫ i) ≫ h := ht ▸ rfl
_ = t ≫ u ≫ h := by simp only [u, Category.assoc]
_ = t ≫ 0 := hu.w ▸ rfl
_ = 0 := HasZeroMorphisms.comp_zero _ _
-- h factors through the cokernel of f via some l.
obtain ⟨l, hl⟩ := cokernel.desc' f h fh
have hih : i ≫ h = 0 :=
calc
i ≫ h = i ≫ cokernel.π f ≫ l := hl ▸ rfl
_ = 0 ≫ l := by rw [← Category.assoc, kernel.condition]
_ = 0 := zero_comp
-- i factors through u = ker h via some s.
obtain ⟨s, hs⟩ := NormalMono.lift' u i hih
have hs' : (s ≫ kernel.ι g) ≫ i = 𝟙 I ≫ i := by rw [Category.assoc, hs, Category.id_comp]
haveI : Epi (kernel.ι g) := epi_of_epi_fac ((cancel_mono _).1 hs')
-- ker g is an epimorphism, but ker g ≫ g = 0 = ker g ≫ 0, so g = 0 as required.
exact zero_of_epi_comp _ (kernel.condition g)
instance isIso_factorThruImage [Mono f] : IsIso (Abelian.factorThruImage f) :=
isIso_of_mono_of_epi <| Abelian.factorThruImage f
#align category_theory.non_preadditive_abelian.is_iso_factor_thru_image CategoryTheory.NonPreadditiveAbelian.isIso_factorThruImage
/-- The canonical morphism `i : coimage f ⟶ Q` is a monomorphism -/
instance : Mono (Abelian.factorThruCoimage f) :=
let I := Abelian.coimage f
let i := Abelian.factorThruCoimage f
let p := cokernel.π (kernel.ι f)
NormalEpiCategory.mono_of_cancel_zero _ fun R (g : R ⟶ I) (hgi : g ≫ i = 0) => by
-- Since C is abelian, u := p ≫ coker g is the cokernel of some morphism h.
let u := p ≫ cokernel.π g
haveI : Epi u := epi_comp _ _
haveI hu := normalEpiOfEpi u
let h := hu.g
-- By hypothesis, i factors through the cokernel of g via some t.
obtain ⟨t, ht⟩ := cokernel.desc' g i hgi
have hf : h ≫ f = 0 :=
calc
h ≫ f = h ≫ p ≫ i := (Abelian.coimage.fac f).symm ▸ rfl
_ = h ≫ p ≫ cokernel.π g ≫ t := ht ▸ rfl
_ = h ≫ u ≫ t := by simp only [u, Category.assoc]
_ = 0 ≫ t := by rw [← Category.assoc, hu.w]
_ = 0 := zero_comp
-- h factors through the kernel of f via some l.
obtain ⟨l, hl⟩ := kernel.lift' f h hf
have hhp : h ≫ p = 0 :=
calc
h ≫ p = (l ≫ kernel.ι f) ≫ p := hl ▸ rfl
_ = l ≫ 0 := by rw [Category.assoc, cokernel.condition]
_ = 0 := comp_zero
-- p factors through u = coker h via some s.
obtain ⟨s, hs⟩ := NormalEpi.desc' u p hhp
have hs' : p ≫ cokernel.π g ≫ s = p ≫ 𝟙 I := by rw [← Category.assoc, hs, Category.comp_id]
haveI : Mono (cokernel.π g) := mono_of_mono_fac ((cancel_epi _).1 hs')
-- coker g is a monomorphism, but g ≫ coker g = 0 = 0 ≫ coker g, so g = 0 as required.
exact zero_of_comp_mono _ (cokernel.condition g)
instance isIso_factorThruCoimage [Epi f] : IsIso (Abelian.factorThruCoimage f) :=
isIso_of_mono_of_epi _
#align category_theory.non_preadditive_abelian.is_iso_factor_thru_coimage CategoryTheory.NonPreadditiveAbelian.isIso_factorThruCoimage
end Factor
section CokernelOfKernel
variable {X Y : C} {f : X ⟶ Y}
/-- In a `NonPreadditiveAbelian` category, an epi is the cokernel of its kernel. More precisely:
If `f` is an epimorphism and `s` is some limit kernel cone on `f`, then `f` is a cokernel
of `Fork.ι s`. -/
def epiIsCokernelOfKernel [Epi f] (s : Fork f 0) (h : IsLimit s) :
IsColimit (CokernelCofork.ofπ f (KernelFork.condition s)) :=
IsCokernel.cokernelIso _ _
(cokernel.ofIsoComp _ _ (Limits.IsLimit.conePointUniqueUpToIso (limit.isLimit _) h)
(ConeMorphism.w (Limits.IsLimit.uniqueUpToIso (limit.isLimit _) h).hom _))
(asIso <| Abelian.factorThruCoimage f) (Abelian.coimage.fac f)
#align category_theory.non_preadditive_abelian.epi_is_cokernel_of_kernel CategoryTheory.NonPreadditiveAbelian.epiIsCokernelOfKernel
/-- In a `NonPreadditiveAbelian` category, a mono is the kernel of its cokernel. More precisely:
If `f` is a monomorphism and `s` is some colimit cokernel cocone on `f`, then `f` is a kernel
of `Cofork.π s`. -/
def monoIsKernelOfCokernel [Mono f] (s : Cofork f 0) (h : IsColimit s) :
IsLimit (KernelFork.ofι f (CokernelCofork.condition s)) :=
IsKernel.isoKernel _ _
(kernel.ofCompIso _ _ (Limits.IsColimit.coconePointUniqueUpToIso h (colimit.isColimit _))
(CoconeMorphism.w (Limits.IsColimit.uniqueUpToIso h <| colimit.isColimit _).hom _))
(asIso <| Abelian.factorThruImage f) (Abelian.image.fac f)
#align category_theory.non_preadditive_abelian.mono_is_kernel_of_cokernel CategoryTheory.NonPreadditiveAbelian.monoIsKernelOfCokernel
end CokernelOfKernel
section
/-- The composite `A ⟶ A ⨯ A ⟶ cokernel (Δ A)`, where the first map is `(𝟙 A, 0)` and the second map
is the canonical projection into the cokernel. -/
abbrev r (A : C) : A ⟶ cokernel (diag A) :=
prod.lift (𝟙 A) 0 ≫ cokernel.π (diag A)
#align category_theory.non_preadditive_abelian.r CategoryTheory.NonPreadditiveAbelian.r
instance mono_Δ {A : C} : Mono (diag A) :=
mono_of_mono_fac <| prod.lift_fst _ _
#align category_theory.non_preadditive_abelian.mono_Δ CategoryTheory.NonPreadditiveAbelian.mono_Δ
instance mono_r {A : C} : Mono (r A) := by
let hl : IsLimit (KernelFork.ofι (diag A) (cokernel.condition (diag A))) :=
monoIsKernelOfCokernel _ (colimit.isColimit _)
apply NormalEpiCategory.mono_of_cancel_zero
intro Z x hx
have hxx : (x ≫ prod.lift (𝟙 A) (0 : A ⟶ A)) ≫ cokernel.π (diag A) = 0 := by
rw [Category.assoc, hx]
obtain ⟨y, hy⟩ := KernelFork.IsLimit.lift' hl _ hxx
rw [KernelFork.ι_ofι] at hy
have hyy : y = 0 := by
erw [← Category.comp_id y, ← Limits.prod.lift_snd (𝟙 A) (𝟙 A), ← Category.assoc, hy,
Category.assoc, prod.lift_snd, HasZeroMorphisms.comp_zero]
haveI : Mono (prod.lift (𝟙 A) (0 : A ⟶ A)) := mono_of_mono_fac (prod.lift_fst _ _)
apply (cancel_mono (prod.lift (𝟙 A) (0 : A ⟶ A))).1
rw [← hy, hyy, zero_comp, zero_comp]
#align category_theory.non_preadditive_abelian.mono_r CategoryTheory.NonPreadditiveAbelian.mono_r
instance epi_r {A : C} : Epi (r A) := by
have hlp : prod.lift (𝟙 A) (0 : A ⟶ A) ≫ Limits.prod.snd = 0 := prod.lift_snd _ _
let hp1 : IsLimit (KernelFork.ofι (prod.lift (𝟙 A) (0 : A ⟶ A)) hlp) := by
refine Fork.IsLimit.mk _ (fun s => Fork.ι s ≫ Limits.prod.fst) ?_ ?_
· intro s
apply prod.hom_ext <;> simp
· intro s m h
haveI : Mono (prod.lift (𝟙 A) (0 : A ⟶ A)) := mono_of_mono_fac (prod.lift_fst _ _)
apply (cancel_mono (prod.lift (𝟙 A) (0 : A ⟶ A))).1
convert h
apply prod.hom_ext <;> simp
let hp2 : IsColimit (CokernelCofork.ofπ (Limits.prod.snd : A ⨯ A ⟶ A) hlp) :=
epiIsCokernelOfKernel _ hp1
apply NormalMonoCategory.epi_of_zero_cancel
intro Z z hz
have h : prod.lift (𝟙 A) (0 : A ⟶ A) ≫ cokernel.π (diag A) ≫ z = 0 := by rw [← Category.assoc, hz]
obtain ⟨t, ht⟩ := CokernelCofork.IsColimit.desc' hp2 _ h
rw [CokernelCofork.π_ofπ] at ht
have htt : t = 0 := by
rw [← Category.id_comp t]
change 𝟙 A ≫ t = 0
rw [← Limits.prod.lift_snd (𝟙 A) (𝟙 A), Category.assoc, ht, ← Category.assoc,
cokernel.condition, zero_comp]
apply (cancel_epi (cokernel.π (diag A))).1
rw [← ht, htt, comp_zero, comp_zero]
#align category_theory.non_preadditive_abelian.epi_r CategoryTheory.NonPreadditiveAbelian.epi_r
instance isIso_r {A : C} : IsIso (r A) :=
isIso_of_mono_of_epi _
#align category_theory.non_preadditive_abelian.is_iso_r CategoryTheory.NonPreadditiveAbelian.isIso_r
/-- The composite `A ⨯ A ⟶ cokernel (diag A) ⟶ A` given by the natural projection into the cokernel
followed by the inverse of `r`. In the category of modules, using the normal kernels and
cokernels, this map is equal to the map `(a, b) ↦ a - b`, hence the name `σ` for
"subtraction". -/
abbrev σ {A : C} : A ⨯ A ⟶ A :=
cokernel.π (diag A) ≫ inv (r A)
#align category_theory.non_preadditive_abelian.σ CategoryTheory.NonPreadditiveAbelian.σ
end
-- Porting note (#10618): simp can prove these
@[reassoc]
theorem diag_σ {X : C} : diag X ≫ σ = 0 := by rw [cokernel.condition_assoc, zero_comp]
#align category_theory.non_preadditive_abelian.diag_σ CategoryTheory.NonPreadditiveAbelian.diag_σ
@[reassoc (attr := simp)]
theorem lift_σ {X : C} : prod.lift (𝟙 X) 0 ≫ σ = 𝟙 X := by rw [← Category.assoc, IsIso.hom_inv_id]
#align category_theory.non_preadditive_abelian.lift_σ CategoryTheory.NonPreadditiveAbelian.lift_σ
@[reassoc]
theorem lift_map {X Y : C} (f : X ⟶ Y) :
prod.lift (𝟙 X) 0 ≫ Limits.prod.map f f = f ≫ prod.lift (𝟙 Y) 0 := by simp
#align category_theory.non_preadditive_abelian.lift_map CategoryTheory.NonPreadditiveAbelian.lift_map
/-- σ is a cokernel of Δ X. -/
def isColimitσ {X : C} : IsColimit (CokernelCofork.ofπ (σ : X ⨯ X ⟶ X) diag_σ) :=
cokernel.cokernelIso _ σ (asIso (r X)).symm (by rw [Iso.symm_hom, asIso_inv])
#align category_theory.non_preadditive_abelian.is_colimit_σ CategoryTheory.NonPreadditiveAbelian.isColimitσ
/-- This is the key identity satisfied by `σ`. -/
theorem σ_comp {X Y : C} (f : X ⟶ Y) : σ ≫ f = Limits.prod.map f f ≫ σ := by
obtain ⟨g, hg⟩ :=
CokernelCofork.IsColimit.desc' isColimitσ (Limits.prod.map f f ≫ σ) (by
rw [prod.diag_map_assoc, diag_σ, comp_zero])
suffices hfg : f = g by rw [← hg, Cofork.π_ofπ, hfg]
calc
f = f ≫ prod.lift (𝟙 Y) 0 ≫ σ := by rw [lift_σ, Category.comp_id]
_ = prod.lift (𝟙 X) 0 ≫ Limits.prod.map f f ≫ σ := by rw [lift_map_assoc]
_ = prod.lift (𝟙 X) 0 ≫ σ ≫ g := by rw [← hg, CokernelCofork.π_ofπ]
_ = g := by rw [← Category.assoc, lift_σ, Category.id_comp]
#align category_theory.non_preadditive_abelian.σ_comp CategoryTheory.NonPreadditiveAbelian.σ_comp
section
-- We write `f - g` for `prod.lift f g ≫ σ`.
/-- Subtraction of morphisms in a `NonPreadditiveAbelian` category. -/
def hasSub {X Y : C} : Sub (X ⟶ Y) :=
⟨fun f g => prod.lift f g ≫ σ⟩
#align category_theory.non_preadditive_abelian.has_sub CategoryTheory.NonPreadditiveAbelian.hasSub
attribute [local instance] hasSub
-- We write `-f` for `0 - f`.
/-- Negation of morphisms in a `NonPreadditiveAbelian` category. -/
def hasNeg {X Y : C} : Neg (X ⟶ Y) where
neg := fun f => 0 - f
#align category_theory.non_preadditive_abelian.has_neg CategoryTheory.NonPreadditiveAbelian.hasNeg
attribute [local instance] hasNeg
-- We write `f + g` for `f - (-g)`.
/-- Addition of morphisms in a `NonPreadditiveAbelian` category. -/
def hasAdd {X Y : C} : Add (X ⟶ Y) :=
⟨fun f g => f - -g⟩
#align category_theory.non_preadditive_abelian.has_add CategoryTheory.NonPreadditiveAbelian.hasAdd
attribute [local instance] hasAdd
theorem sub_def {X Y : C} (a b : X ⟶ Y) : a - b = prod.lift a b ≫ σ := rfl
#align category_theory.non_preadditive_abelian.sub_def CategoryTheory.NonPreadditiveAbelian.sub_def
theorem add_def {X Y : C} (a b : X ⟶ Y) : a + b = a - -b := rfl
#align category_theory.non_preadditive_abelian.add_def CategoryTheory.NonPreadditiveAbelian.add_def
theorem neg_def {X Y : C} (a : X ⟶ Y) : -a = 0 - a := rfl
#align category_theory.non_preadditive_abelian.neg_def CategoryTheory.NonPreadditiveAbelian.neg_def
theorem sub_zero {X Y : C} (a : X ⟶ Y) : a - 0 = a := by
rw [sub_def]
conv_lhs =>
congr; congr; rw [← Category.comp_id a]
case a.g => rw [show 0 = a ≫ (0 : Y ⟶ Y) by simp]
rw [← prod.comp_lift, Category.assoc, lift_σ, Category.comp_id]
#align category_theory.non_preadditive_abelian.sub_zero CategoryTheory.NonPreadditiveAbelian.sub_zero
| Mathlib/CategoryTheory/Abelian/NonPreadditive.lean | 358 | 359 | theorem sub_self {X Y : C} (a : X ⟶ Y) : a - a = 0 := by |
rw [sub_def, ← Category.comp_id a, ← prod.comp_lift, Category.assoc, diag_σ, comp_zero]
|
/-
Copyright (c) 2023 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import Mathlib.Probability.Kernel.MeasurableIntegral
#align_import probability.kernel.composition from "leanprover-community/mathlib"@"3b92d54a05ee592aa2c6181a4e76b1bb7cc45d0b"
/-!
# Product and composition of kernels
We define
* the composition-product `κ ⊗ₖ η` of two s-finite kernels `κ : kernel α β` and
`η : kernel (α × β) γ`, a kernel from `α` to `β × γ`.
* the map and comap of a kernel along a measurable function.
* the composition `η ∘ₖ κ` of kernels `κ : kernel α β` and `η : kernel β γ`, kernel from `α` to
`γ`.
* the product `κ ×ₖ η` of s-finite kernels `κ : kernel α β` and `η : kernel α γ`,
a kernel from `α` to `β × γ`.
A note on names:
The composition-product `kernel α β → kernel (α × β) γ → kernel α (β × γ)` is named composition in
[kallenberg2021] and product on the wikipedia article on transition kernels.
Most papers studying categories of kernels call composition the map we call composition. We adopt
that convention because it fits better with the use of the name `comp` elsewhere in mathlib.
## Main definitions
Kernels built from other kernels:
* `compProd (κ : kernel α β) (η : kernel (α × β) γ) : kernel α (β × γ)`: composition-product of 2
s-finite kernels. We define a notation `κ ⊗ₖ η = compProd κ η`.
`∫⁻ bc, f bc ∂((κ ⊗ₖ η) a) = ∫⁻ b, ∫⁻ c, f (b, c) ∂(η (a, b)) ∂(κ a)`
* `map (κ : kernel α β) (f : β → γ) (hf : Measurable f) : kernel α γ`
`∫⁻ c, g c ∂(map κ f hf a) = ∫⁻ b, g (f b) ∂(κ a)`
* `comap (κ : kernel α β) (f : γ → α) (hf : Measurable f) : kernel γ β`
`∫⁻ b, g b ∂(comap κ f hf c) = ∫⁻ b, g b ∂(κ (f c))`
* `comp (η : kernel β γ) (κ : kernel α β) : kernel α γ`: composition of 2 kernels.
We define a notation `η ∘ₖ κ = comp η κ`.
`∫⁻ c, g c ∂((η ∘ₖ κ) a) = ∫⁻ b, ∫⁻ c, g c ∂(η b) ∂(κ a)`
* `prod (κ : kernel α β) (η : kernel α γ) : kernel α (β × γ)`: product of 2 s-finite kernels.
`∫⁻ bc, f bc ∂((κ ×ₖ η) a) = ∫⁻ b, ∫⁻ c, f (b, c) ∂(η a) ∂(κ a)`
## Main statements
* `lintegral_compProd`, `lintegral_map`, `lintegral_comap`, `lintegral_comp`, `lintegral_prod`:
Lebesgue integral of a function against a composition-product/map/comap/composition/product of
kernels.
* Instances of the form `<class>.<operation>` where class is one of `IsMarkovKernel`,
`IsFiniteKernel`, `IsSFiniteKernel` and operation is one of `compProd`, `map`, `comap`,
`comp`, `prod`. These instances state that the three classes are stable by the various operations.
## Notations
* `κ ⊗ₖ η = ProbabilityTheory.kernel.compProd κ η`
* `η ∘ₖ κ = ProbabilityTheory.kernel.comp η κ`
* `κ ×ₖ η = ProbabilityTheory.kernel.prod κ η`
-/
open MeasureTheory
open scoped ENNReal
namespace ProbabilityTheory
namespace kernel
variable {α β ι : Type*} {mα : MeasurableSpace α} {mβ : MeasurableSpace β}
section CompositionProduct
/-!
### Composition-Product of kernels
We define a kernel composition-product
`compProd : kernel α β → kernel (α × β) γ → kernel α (β × γ)`.
-/
variable {γ : Type*} {mγ : MeasurableSpace γ} {s : Set (β × γ)}
/-- Auxiliary function for the definition of the composition-product of two kernels.
For all `a : α`, `compProdFun κ η a` is a countably additive function with value zero on the empty
set, and the composition-product of kernels is defined in `kernel.compProd` through
`Measure.ofMeasurable`. -/
noncomputable def compProdFun (κ : kernel α β) (η : kernel (α × β) γ) (a : α) (s : Set (β × γ)) :
ℝ≥0∞ :=
∫⁻ b, η (a, b) {c | (b, c) ∈ s} ∂κ a
#align probability_theory.kernel.comp_prod_fun ProbabilityTheory.kernel.compProdFun
theorem compProdFun_empty (κ : kernel α β) (η : kernel (α × β) γ) (a : α) :
compProdFun κ η a ∅ = 0 := by
simp only [compProdFun, Set.mem_empty_iff_false, Set.setOf_false, measure_empty,
MeasureTheory.lintegral_const, zero_mul]
#align probability_theory.kernel.comp_prod_fun_empty ProbabilityTheory.kernel.compProdFun_empty
theorem compProdFun_iUnion (κ : kernel α β) (η : kernel (α × β) γ) [IsSFiniteKernel η] (a : α)
(f : ℕ → Set (β × γ)) (hf_meas : ∀ i, MeasurableSet (f i))
(hf_disj : Pairwise (Disjoint on f)) :
compProdFun κ η a (⋃ i, f i) = ∑' i, compProdFun κ η a (f i) := by
have h_Union :
(fun b => η (a, b) {c : γ | (b, c) ∈ ⋃ i, f i}) = fun b =>
η (a, b) (⋃ i, {c : γ | (b, c) ∈ f i}) := by
ext1 b
congr with c
simp only [Set.mem_iUnion, Set.iSup_eq_iUnion, Set.mem_setOf_eq]
rw [compProdFun, h_Union]
have h_tsum :
(fun b => η (a, b) (⋃ i, {c : γ | (b, c) ∈ f i})) = fun b =>
∑' i, η (a, b) {c : γ | (b, c) ∈ f i} := by
ext1 b
rw [measure_iUnion]
· intro i j hij s hsi hsj c hcs
have hbci : {(b, c)} ⊆ f i := by rw [Set.singleton_subset_iff]; exact hsi hcs
have hbcj : {(b, c)} ⊆ f j := by rw [Set.singleton_subset_iff]; exact hsj hcs
simpa only [Set.bot_eq_empty, Set.le_eq_subset, Set.singleton_subset_iff,
Set.mem_empty_iff_false] using hf_disj hij hbci hbcj
· -- Porting note: behavior of `@` changed relative to lean 3, was
-- exact fun i => (@measurable_prod_mk_left β γ _ _ b) _ (hf_meas i)
exact fun i => (@measurable_prod_mk_left β γ _ _ b) (hf_meas i)
rw [h_tsum, lintegral_tsum]
· rfl
· intro i
have hm : MeasurableSet {p : (α × β) × γ | (p.1.2, p.2) ∈ f i} :=
measurable_fst.snd.prod_mk measurable_snd (hf_meas i)
exact ((measurable_kernel_prod_mk_left hm).comp measurable_prod_mk_left).aemeasurable
#align probability_theory.kernel.comp_prod_fun_Union ProbabilityTheory.kernel.compProdFun_iUnion
theorem compProdFun_tsum_right (κ : kernel α β) (η : kernel (α × β) γ) [IsSFiniteKernel η] (a : α)
(hs : MeasurableSet s) : compProdFun κ η a s = ∑' n, compProdFun κ (seq η n) a s := by
simp_rw [compProdFun, (measure_sum_seq η _).symm]
have :
∫⁻ b, Measure.sum (fun n => seq η n (a, b)) {c : γ | (b, c) ∈ s} ∂κ a =
∫⁻ b, ∑' n, seq η n (a, b) {c : γ | (b, c) ∈ s} ∂κ a := by
congr
ext1 b
rw [Measure.sum_apply]
exact measurable_prod_mk_left hs
rw [this, lintegral_tsum]
exact fun n => ((measurable_kernel_prod_mk_left (κ := (seq η n))
((measurable_fst.snd.prod_mk measurable_snd) hs)).comp measurable_prod_mk_left).aemeasurable
#align probability_theory.kernel.comp_prod_fun_tsum_right ProbabilityTheory.kernel.compProdFun_tsum_right
theorem compProdFun_tsum_left (κ : kernel α β) (η : kernel (α × β) γ) [IsSFiniteKernel κ] (a : α)
(s : Set (β × γ)) : compProdFun κ η a s = ∑' n, compProdFun (seq κ n) η a s := by
simp_rw [compProdFun, (measure_sum_seq κ _).symm, lintegral_sum_measure]
#align probability_theory.kernel.comp_prod_fun_tsum_left ProbabilityTheory.kernel.compProdFun_tsum_left
theorem compProdFun_eq_tsum (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ)
[IsSFiniteKernel η] (a : α) (hs : MeasurableSet s) :
compProdFun κ η a s = ∑' (n) (m), compProdFun (seq κ n) (seq η m) a s := by
simp_rw [compProdFun_tsum_left κ η a s, compProdFun_tsum_right _ η a hs]
#align probability_theory.kernel.comp_prod_fun_eq_tsum ProbabilityTheory.kernel.compProdFun_eq_tsum
/-- Auxiliary lemma for `measurable_compProdFun`. -/
theorem measurable_compProdFun_of_finite (κ : kernel α β) [IsFiniteKernel κ] (η : kernel (α × β) γ)
[IsFiniteKernel η] (hs : MeasurableSet s) : Measurable fun a => compProdFun κ η a s := by
simp only [compProdFun]
have h_meas : Measurable (Function.uncurry fun a b => η (a, b) {c : γ | (b, c) ∈ s}) := by
have :
(Function.uncurry fun a b => η (a, b) {c : γ | (b, c) ∈ s}) = fun p =>
η p {c : γ | (p.2, c) ∈ s} := by
ext1 p
rw [Function.uncurry_apply_pair]
rw [this]
exact measurable_kernel_prod_mk_left (measurable_fst.snd.prod_mk measurable_snd hs)
exact h_meas.lintegral_kernel_prod_right
#align probability_theory.kernel.measurable_comp_prod_fun_of_finite ProbabilityTheory.kernel.measurable_compProdFun_of_finite
| Mathlib/Probability/Kernel/Composition.lean | 172 | 185 | theorem measurable_compProdFun (κ : kernel α β) [IsSFiniteKernel κ] (η : kernel (α × β) γ)
[IsSFiniteKernel η] (hs : MeasurableSet s) : Measurable fun a => compProdFun κ η a s := by |
simp_rw [compProdFun_tsum_right κ η _ hs]
refine Measurable.ennreal_tsum fun n => ?_
simp only [compProdFun]
have h_meas : Measurable (Function.uncurry fun a b => seq η n (a, b) {c : γ | (b, c) ∈ s}) := by
have :
(Function.uncurry fun a b => seq η n (a, b) {c : γ | (b, c) ∈ s}) = fun p =>
seq η n p {c : γ | (p.2, c) ∈ s} := by
ext1 p
rw [Function.uncurry_apply_pair]
rw [this]
exact measurable_kernel_prod_mk_left (measurable_fst.snd.prod_mk measurable_snd hs)
exact h_meas.lintegral_kernel_prod_right
|
/-
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.Logic.Equiv.PartialEquiv
import Mathlib.Topology.Sets.Opens
#align_import topology.local_homeomorph from "leanprover-community/mathlib"@"431589bce478b2229eba14b14a283250428217db"
/-!
# Partial homeomorphisms
This file defines homeomorphisms between open subsets of topological spaces. An element `e` of
`PartialHomeomorph X Y` is an extension of `PartialEquiv X Y`, i.e., it is a pair of functions
`e.toFun` and `e.invFun`, inverse of each other on the sets `e.source` and `e.target`.
Additionally, we require that these sets are open, and that the functions are continuous on them.
Equivalently, they are homeomorphisms there.
As in equivs, we register a coercion to functions, and we use `e x` and `e.symm x` throughout
instead of `e.toFun x` and `e.invFun x`.
## Main definitions
* `Homeomorph.toPartialHomeomorph`: associating a partial homeomorphism to a homeomorphism, with
`source = target = Set.univ`;
* `PartialHomeomorph.symm`: the inverse of a partial homeomorphism
* `PartialHomeomorph.trans`: the composition of two partial homeomorphisms
* `PartialHomeomorph.refl`: the identity partial homeomorphism
* `PartialHomeomorph.ofSet`: the identity on a set `s`
* `PartialHomeomorph.EqOnSource`: equivalence relation describing the "right" notion of equality
for partial homeomorphisms
## Implementation notes
Most statements are copied from their `PartialEquiv` versions, although some care is required
especially when restricting to subsets, as these should be open subsets.
For design notes, see `PartialEquiv.lean`.
### Local coding conventions
If a lemma deals with the intersection of a set with either source or target of a `PartialEquiv`,
then it should use `e.source ∩ s` or `e.target ∩ t`, not `s ∩ e.source` or `t ∩ e.target`.
-/
open Function Set Filter Topology
variable {X X' : Type*} {Y Y' : Type*} {Z Z' : Type*}
[TopologicalSpace X] [TopologicalSpace X'] [TopologicalSpace Y] [TopologicalSpace Y']
[TopologicalSpace Z] [TopologicalSpace Z']
/-- Partial homeomorphisms, defined on open subsets of the space -/
-- Porting note(#5171): this linter isn't ported yet. @[nolint has_nonempty_instance]
structure PartialHomeomorph (X : Type*) (Y : Type*) [TopologicalSpace X]
[TopologicalSpace Y] extends PartialEquiv X Y where
open_source : IsOpen source
open_target : IsOpen target
continuousOn_toFun : ContinuousOn toFun source
continuousOn_invFun : ContinuousOn invFun target
#align local_homeomorph PartialHomeomorph
namespace PartialHomeomorph
variable (e : PartialHomeomorph X Y)
/-! Basic properties; inverse (symm instance) -/
section Basic
/-- Coercion of a partial homeomorphisms to a function. We don't use `e.toFun` because it is
actually `e.toPartialEquiv.toFun`, so `simp` will apply lemmas about `toPartialEquiv`.
While we may want to switch to this behavior later, doing it mid-port will break a lot of proofs. -/
@[coe] def toFun' : X → Y := e.toFun
/-- Coercion of a `PartialHomeomorph` to function.
Note that a `PartialHomeomorph` is not `DFunLike`. -/
instance : CoeFun (PartialHomeomorph X Y) fun _ => X → Y :=
⟨fun e => e.toFun'⟩
/-- The inverse of a partial homeomorphism -/
@[symm]
protected def symm : PartialHomeomorph Y X where
toPartialEquiv := e.toPartialEquiv.symm
open_source := e.open_target
open_target := e.open_source
continuousOn_toFun := e.continuousOn_invFun
continuousOn_invFun := e.continuousOn_toFun
#align local_homeomorph.symm PartialHomeomorph.symm
/-- See Note [custom simps projection]. We need to specify this projection explicitly in this case,
because it is a composition of multiple projections. -/
def Simps.apply (e : PartialHomeomorph X Y) : X → Y := e
#align local_homeomorph.simps.apply PartialHomeomorph.Simps.apply
/-- See Note [custom simps projection] -/
def Simps.symm_apply (e : PartialHomeomorph X Y) : Y → X := e.symm
#align local_homeomorph.simps.symm_apply PartialHomeomorph.Simps.symm_apply
initialize_simps_projections PartialHomeomorph (toFun → apply, invFun → symm_apply)
protected theorem continuousOn : ContinuousOn e e.source :=
e.continuousOn_toFun
#align local_homeomorph.continuous_on PartialHomeomorph.continuousOn
theorem continuousOn_symm : ContinuousOn e.symm e.target :=
e.continuousOn_invFun
#align local_homeomorph.continuous_on_symm PartialHomeomorph.continuousOn_symm
@[simp, mfld_simps]
theorem mk_coe (e : PartialEquiv X Y) (a b c d) : (PartialHomeomorph.mk e a b c d : X → Y) = e :=
rfl
#align local_homeomorph.mk_coe PartialHomeomorph.mk_coe
@[simp, mfld_simps]
theorem mk_coe_symm (e : PartialEquiv X Y) (a b c d) :
((PartialHomeomorph.mk e a b c d).symm : Y → X) = e.symm :=
rfl
#align local_homeomorph.mk_coe_symm PartialHomeomorph.mk_coe_symm
theorem toPartialEquiv_injective :
Injective (toPartialEquiv : PartialHomeomorph X Y → PartialEquiv X Y)
| ⟨_, _, _, _, _⟩, ⟨_, _, _, _, _⟩, rfl => rfl
#align local_homeomorph.to_local_equiv_injective PartialHomeomorph.toPartialEquiv_injective
/- Register a few simp lemmas to make sure that `simp` puts the application of a local
homeomorphism in its normal form, i.e., in terms of its coercion to a function. -/
@[simp, mfld_simps]
theorem toFun_eq_coe (e : PartialHomeomorph X Y) : e.toFun = e :=
rfl
#align local_homeomorph.to_fun_eq_coe PartialHomeomorph.toFun_eq_coe
@[simp, mfld_simps]
theorem invFun_eq_coe (e : PartialHomeomorph X Y) : e.invFun = e.symm :=
rfl
#align local_homeomorph.inv_fun_eq_coe PartialHomeomorph.invFun_eq_coe
@[simp, mfld_simps]
theorem coe_coe : (e.toPartialEquiv : X → Y) = e :=
rfl
#align local_homeomorph.coe_coe PartialHomeomorph.coe_coe
@[simp, mfld_simps]
theorem coe_coe_symm : (e.toPartialEquiv.symm : Y → X) = e.symm :=
rfl
#align local_homeomorph.coe_coe_symm PartialHomeomorph.coe_coe_symm
@[simp, mfld_simps]
theorem map_source {x : X} (h : x ∈ e.source) : e x ∈ e.target :=
e.map_source' h
#align local_homeomorph.map_source PartialHomeomorph.map_source
/-- Variant of `map_source`, stated for images of subsets of `source`. -/
lemma map_source'' : e '' e.source ⊆ e.target :=
fun _ ⟨_, hx, hex⟩ ↦ mem_of_eq_of_mem (id hex.symm) (e.map_source' hx)
@[simp, mfld_simps]
theorem map_target {x : Y} (h : x ∈ e.target) : e.symm x ∈ e.source :=
e.map_target' h
#align local_homeomorph.map_target PartialHomeomorph.map_target
@[simp, mfld_simps]
theorem left_inv {x : X} (h : x ∈ e.source) : e.symm (e x) = x :=
e.left_inv' h
#align local_homeomorph.left_inv PartialHomeomorph.left_inv
@[simp, mfld_simps]
theorem right_inv {x : Y} (h : x ∈ e.target) : e (e.symm x) = x :=
e.right_inv' h
#align local_homeomorph.right_inv PartialHomeomorph.right_inv
theorem eq_symm_apply {x : X} {y : Y} (hx : x ∈ e.source) (hy : y ∈ e.target) :
x = e.symm y ↔ e x = y :=
e.toPartialEquiv.eq_symm_apply hx hy
#align local_homeomorph.eq_symm_apply PartialHomeomorph.eq_symm_apply
protected theorem mapsTo : MapsTo e e.source e.target := fun _ => e.map_source
#align local_homeomorph.maps_to PartialHomeomorph.mapsTo
protected theorem symm_mapsTo : MapsTo e.symm e.target e.source :=
e.symm.mapsTo
#align local_homeomorph.symm_maps_to PartialHomeomorph.symm_mapsTo
protected theorem leftInvOn : LeftInvOn e.symm e e.source := fun _ => e.left_inv
#align local_homeomorph.left_inv_on PartialHomeomorph.leftInvOn
protected theorem rightInvOn : RightInvOn e.symm e e.target := fun _ => e.right_inv
#align local_homeomorph.right_inv_on PartialHomeomorph.rightInvOn
protected theorem invOn : InvOn e.symm e e.source e.target :=
⟨e.leftInvOn, e.rightInvOn⟩
#align local_homeomorph.inv_on PartialHomeomorph.invOn
protected theorem injOn : InjOn e e.source :=
e.leftInvOn.injOn
#align local_homeomorph.inj_on PartialHomeomorph.injOn
protected theorem bijOn : BijOn e e.source e.target :=
e.invOn.bijOn e.mapsTo e.symm_mapsTo
#align local_homeomorph.bij_on PartialHomeomorph.bijOn
protected theorem surjOn : SurjOn e e.source e.target :=
e.bijOn.surjOn
#align local_homeomorph.surj_on PartialHomeomorph.surjOn
end Basic
/-- Interpret a `Homeomorph` as a `PartialHomeomorph` by restricting it
to an open set `s` in the domain and to `t` in the codomain. -/
@[simps! (config := .asFn) apply symm_apply toPartialEquiv,
simps! (config := .lemmasOnly) source target]
def _root_.Homeomorph.toPartialHomeomorphOfImageEq (e : X ≃ₜ Y) (s : Set X) (hs : IsOpen s)
(t : Set Y) (h : e '' s = t) : PartialHomeomorph X Y where
toPartialEquiv := e.toPartialEquivOfImageEq s t h
open_source := hs
open_target := by simpa [← h]
continuousOn_toFun := e.continuous.continuousOn
continuousOn_invFun := e.symm.continuous.continuousOn
/-- A homeomorphism induces a partial homeomorphism on the whole space -/
@[simps! (config := mfld_cfg)]
def _root_.Homeomorph.toPartialHomeomorph (e : X ≃ₜ Y) : PartialHomeomorph X Y :=
e.toPartialHomeomorphOfImageEq univ isOpen_univ univ <| by rw [image_univ, e.surjective.range_eq]
#align homeomorph.to_local_homeomorph Homeomorph.toPartialHomeomorph
/-- Replace `toPartialEquiv` field to provide better definitional equalities. -/
def replaceEquiv (e : PartialHomeomorph X Y) (e' : PartialEquiv X Y) (h : e.toPartialEquiv = e') :
PartialHomeomorph X Y where
toPartialEquiv := e'
open_source := h ▸ e.open_source
open_target := h ▸ e.open_target
continuousOn_toFun := h ▸ e.continuousOn_toFun
continuousOn_invFun := h ▸ e.continuousOn_invFun
#align local_homeomorph.replace_equiv PartialHomeomorph.replaceEquiv
theorem replaceEquiv_eq_self (e' : PartialEquiv X Y)
(h : e.toPartialEquiv = e') : e.replaceEquiv e' h = e := by
cases e
subst e'
rfl
#align local_homeomorph.replace_equiv_eq_self PartialHomeomorph.replaceEquiv_eq_self
theorem source_preimage_target : e.source ⊆ e ⁻¹' e.target :=
e.mapsTo
#align local_homeomorph.source_preimage_target PartialHomeomorph.source_preimage_target
@[deprecated toPartialEquiv_injective (since := "2023-02-18")]
theorem eq_of_partialEquiv_eq {e e' : PartialHomeomorph X Y}
(h : e.toPartialEquiv = e'.toPartialEquiv) : e = e' :=
toPartialEquiv_injective h
#align local_homeomorph.eq_of_local_equiv_eq PartialHomeomorph.eq_of_partialEquiv_eq
theorem eventually_left_inverse {x} (hx : x ∈ e.source) :
∀ᶠ y in 𝓝 x, e.symm (e y) = y :=
(e.open_source.eventually_mem hx).mono e.left_inv'
#align local_homeomorph.eventually_left_inverse PartialHomeomorph.eventually_left_inverse
theorem eventually_left_inverse' {x} (hx : x ∈ e.target) :
∀ᶠ y in 𝓝 (e.symm x), e.symm (e y) = y :=
e.eventually_left_inverse (e.map_target hx)
#align local_homeomorph.eventually_left_inverse' PartialHomeomorph.eventually_left_inverse'
theorem eventually_right_inverse {x} (hx : x ∈ e.target) :
∀ᶠ y in 𝓝 x, e (e.symm y) = y :=
(e.open_target.eventually_mem hx).mono e.right_inv'
#align local_homeomorph.eventually_right_inverse PartialHomeomorph.eventually_right_inverse
theorem eventually_right_inverse' {x} (hx : x ∈ e.source) :
∀ᶠ y in 𝓝 (e x), e (e.symm y) = y :=
e.eventually_right_inverse (e.map_source hx)
#align local_homeomorph.eventually_right_inverse' PartialHomeomorph.eventually_right_inverse'
theorem eventually_ne_nhdsWithin {x} (hx : x ∈ e.source) :
∀ᶠ x' in 𝓝[≠] x, e x' ≠ e x :=
eventually_nhdsWithin_iff.2 <|
(e.eventually_left_inverse hx).mono fun x' hx' =>
mt fun h => by rw [mem_singleton_iff, ← e.left_inv hx, ← h, hx']
#align local_homeomorph.eventually_ne_nhds_within PartialHomeomorph.eventually_ne_nhdsWithin
theorem nhdsWithin_source_inter {x} (hx : x ∈ e.source) (s : Set X) : 𝓝[e.source ∩ s] x = 𝓝[s] x :=
nhdsWithin_inter_of_mem (mem_nhdsWithin_of_mem_nhds <| IsOpen.mem_nhds e.open_source hx)
#align local_homeomorph.nhds_within_source_inter PartialHomeomorph.nhdsWithin_source_inter
theorem nhdsWithin_target_inter {x} (hx : x ∈ e.target) (s : Set Y) : 𝓝[e.target ∩ s] x = 𝓝[s] x :=
e.symm.nhdsWithin_source_inter hx s
#align local_homeomorph.nhds_within_target_inter PartialHomeomorph.nhdsWithin_target_inter
theorem image_eq_target_inter_inv_preimage {s : Set X} (h : s ⊆ e.source) :
e '' s = e.target ∩ e.symm ⁻¹' s :=
e.toPartialEquiv.image_eq_target_inter_inv_preimage h
#align local_homeomorph.image_eq_target_inter_inv_preimage PartialHomeomorph.image_eq_target_inter_inv_preimage
theorem image_source_inter_eq' (s : Set X) : e '' (e.source ∩ s) = e.target ∩ e.symm ⁻¹' s :=
e.toPartialEquiv.image_source_inter_eq' s
#align local_homeomorph.image_source_inter_eq' PartialHomeomorph.image_source_inter_eq'
theorem image_source_inter_eq (s : Set X) :
e '' (e.source ∩ s) = e.target ∩ e.symm ⁻¹' (e.source ∩ s) :=
e.toPartialEquiv.image_source_inter_eq s
#align local_homeomorph.image_source_inter_eq PartialHomeomorph.image_source_inter_eq
theorem symm_image_eq_source_inter_preimage {s : Set Y} (h : s ⊆ e.target) :
e.symm '' s = e.source ∩ e ⁻¹' s :=
e.symm.image_eq_target_inter_inv_preimage h
#align local_homeomorph.symm_image_eq_source_inter_preimage PartialHomeomorph.symm_image_eq_source_inter_preimage
theorem symm_image_target_inter_eq (s : Set Y) :
e.symm '' (e.target ∩ s) = e.source ∩ e ⁻¹' (e.target ∩ s) :=
e.symm.image_source_inter_eq _
#align local_homeomorph.symm_image_target_inter_eq PartialHomeomorph.symm_image_target_inter_eq
theorem source_inter_preimage_inv_preimage (s : Set X) :
e.source ∩ e ⁻¹' (e.symm ⁻¹' s) = e.source ∩ s :=
e.toPartialEquiv.source_inter_preimage_inv_preimage s
#align local_homeomorph.source_inter_preimage_inv_preimage PartialHomeomorph.source_inter_preimage_inv_preimage
theorem target_inter_inv_preimage_preimage (s : Set Y) :
e.target ∩ e.symm ⁻¹' (e ⁻¹' s) = e.target ∩ s :=
e.symm.source_inter_preimage_inv_preimage _
#align local_homeomorph.target_inter_inv_preimage_preimage PartialHomeomorph.target_inter_inv_preimage_preimage
theorem source_inter_preimage_target_inter (s : Set Y) :
e.source ∩ e ⁻¹' (e.target ∩ s) = e.source ∩ e ⁻¹' s :=
e.toPartialEquiv.source_inter_preimage_target_inter s
#align local_homeomorph.source_inter_preimage_target_inter PartialHomeomorph.source_inter_preimage_target_inter
theorem image_source_eq_target : e '' e.source = e.target :=
e.toPartialEquiv.image_source_eq_target
#align local_homeomorph.image_source_eq_target PartialHomeomorph.image_source_eq_target
theorem symm_image_target_eq_source : e.symm '' e.target = e.source :=
e.symm.image_source_eq_target
#align local_homeomorph.symm_image_target_eq_source PartialHomeomorph.symm_image_target_eq_source
/-- Two partial homeomorphisms are equal when they have equal `toFun`, `invFun` and `source`.
It is not sufficient to have equal `toFun` and `source`, as this only determines `invFun` on
the target. This would only be true for a weaker notion of equality, arguably the right one,
called `EqOnSource`. -/
@[ext]
protected theorem ext (e' : PartialHomeomorph X Y) (h : ∀ x, e x = e' x)
(hinv : ∀ x, e.symm x = e'.symm x) (hs : e.source = e'.source) : e = e' :=
toPartialEquiv_injective (PartialEquiv.ext h hinv hs)
#align local_homeomorph.ext PartialHomeomorph.ext
protected theorem ext_iff {e e' : PartialHomeomorph X Y} :
e = e' ↔ (∀ x, e x = e' x) ∧ (∀ x, e.symm x = e'.symm x) ∧ e.source = e'.source :=
⟨by
rintro rfl
exact ⟨fun x => rfl, fun x => rfl, rfl⟩, fun h => e.ext e' h.1 h.2.1 h.2.2⟩
#align local_homeomorph.ext_iff PartialHomeomorph.ext_iff
@[simp, mfld_simps]
theorem symm_toPartialEquiv : e.symm.toPartialEquiv = e.toPartialEquiv.symm :=
rfl
#align local_homeomorph.symm_to_local_equiv PartialHomeomorph.symm_toPartialEquiv
-- The following lemmas are already simp via `PartialEquiv`
theorem symm_source : e.symm.source = e.target :=
rfl
#align local_homeomorph.symm_source PartialHomeomorph.symm_source
theorem symm_target : e.symm.target = e.source :=
rfl
#align local_homeomorph.symm_target PartialHomeomorph.symm_target
@[simp, mfld_simps] theorem symm_symm : e.symm.symm = e := rfl
#align local_homeomorph.symm_symm PartialHomeomorph.symm_symm
theorem symm_bijective : Function.Bijective
(PartialHomeomorph.symm : PartialHomeomorph X Y → PartialHomeomorph Y X) :=
Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩
/-- A partial homeomorphism is continuous at any point of its source -/
protected theorem continuousAt {x : X} (h : x ∈ e.source) : ContinuousAt e x :=
(e.continuousOn x h).continuousAt (e.open_source.mem_nhds h)
#align local_homeomorph.continuous_at PartialHomeomorph.continuousAt
/-- A partial homeomorphism inverse is continuous at any point of its target -/
theorem continuousAt_symm {x : Y} (h : x ∈ e.target) : ContinuousAt e.symm x :=
e.symm.continuousAt h
#align local_homeomorph.continuous_at_symm PartialHomeomorph.continuousAt_symm
theorem tendsto_symm {x} (hx : x ∈ e.source) : Tendsto e.symm (𝓝 (e x)) (𝓝 x) := by
simpa only [ContinuousAt, e.left_inv hx] using e.continuousAt_symm (e.map_source hx)
#align local_homeomorph.tendsto_symm PartialHomeomorph.tendsto_symm
theorem map_nhds_eq {x} (hx : x ∈ e.source) : map e (𝓝 x) = 𝓝 (e x) :=
le_antisymm (e.continuousAt hx) <|
le_map_of_right_inverse (e.eventually_right_inverse' hx) (e.tendsto_symm hx)
#align local_homeomorph.map_nhds_eq PartialHomeomorph.map_nhds_eq
theorem symm_map_nhds_eq {x} (hx : x ∈ e.source) : map e.symm (𝓝 (e x)) = 𝓝 x :=
(e.symm.map_nhds_eq <| e.map_source hx).trans <| by rw [e.left_inv hx]
#align local_homeomorph.symm_map_nhds_eq PartialHomeomorph.symm_map_nhds_eq
theorem image_mem_nhds {x} (hx : x ∈ e.source) {s : Set X} (hs : s ∈ 𝓝 x) : e '' s ∈ 𝓝 (e x) :=
e.map_nhds_eq hx ▸ Filter.image_mem_map hs
#align local_homeomorph.image_mem_nhds PartialHomeomorph.image_mem_nhds
theorem map_nhdsWithin_eq {x} (hx : x ∈ e.source) (s : Set X) :
map e (𝓝[s] x) = 𝓝[e '' (e.source ∩ s)] e x :=
calc
map e (𝓝[s] x) = map e (𝓝[e.source ∩ s] x) :=
congr_arg (map e) (e.nhdsWithin_source_inter hx _).symm
_ = 𝓝[e '' (e.source ∩ s)] e x :=
(e.leftInvOn.mono inter_subset_left).map_nhdsWithin_eq (e.left_inv hx)
(e.continuousAt_symm (e.map_source hx)).continuousWithinAt
(e.continuousAt hx).continuousWithinAt
#align local_homeomorph.map_nhds_within_eq PartialHomeomorph.map_nhdsWithin_eq
theorem map_nhdsWithin_preimage_eq {x} (hx : x ∈ e.source) (s : Set Y) :
map e (𝓝[e ⁻¹' s] x) = 𝓝[s] e x := by
rw [e.map_nhdsWithin_eq hx, e.image_source_inter_eq', e.target_inter_inv_preimage_preimage,
e.nhdsWithin_target_inter (e.map_source hx)]
#align local_homeomorph.map_nhds_within_preimage_eq PartialHomeomorph.map_nhdsWithin_preimage_eq
theorem eventually_nhds {x : X} (p : Y → Prop) (hx : x ∈ e.source) :
(∀ᶠ y in 𝓝 (e x), p y) ↔ ∀ᶠ x in 𝓝 x, p (e x) :=
Iff.trans (by rw [e.map_nhds_eq hx]) eventually_map
#align local_homeomorph.eventually_nhds PartialHomeomorph.eventually_nhds
theorem eventually_nhds' {x : X} (p : X → Prop) (hx : x ∈ e.source) :
(∀ᶠ y in 𝓝 (e x), p (e.symm y)) ↔ ∀ᶠ x in 𝓝 x, p x := by
rw [e.eventually_nhds _ hx]
refine eventually_congr ((e.eventually_left_inverse hx).mono fun y hy => ?_)
rw [hy]
#align local_homeomorph.eventually_nhds' PartialHomeomorph.eventually_nhds'
theorem eventually_nhdsWithin {x : X} (p : Y → Prop) {s : Set X}
(hx : x ∈ e.source) : (∀ᶠ y in 𝓝[e.symm ⁻¹' s] e x, p y) ↔ ∀ᶠ x in 𝓝[s] x, p (e x) := by
refine Iff.trans ?_ eventually_map
rw [e.map_nhdsWithin_eq hx, e.image_source_inter_eq', e.nhdsWithin_target_inter (e.mapsTo hx)]
#align local_homeomorph.eventually_nhds_within PartialHomeomorph.eventually_nhdsWithin
theorem eventually_nhdsWithin' {x : X} (p : X → Prop) {s : Set X}
(hx : x ∈ e.source) : (∀ᶠ y in 𝓝[e.symm ⁻¹' s] e x, p (e.symm y)) ↔ ∀ᶠ x in 𝓝[s] x, p x := by
rw [e.eventually_nhdsWithin _ hx]
refine eventually_congr <|
(eventually_nhdsWithin_of_eventually_nhds <| e.eventually_left_inverse hx).mono fun y hy => ?_
rw [hy]
#align local_homeomorph.eventually_nhds_within' PartialHomeomorph.eventually_nhdsWithin'
/-- This lemma is useful in the manifold library in the case that `e` is a chart. It states that
locally around `e x` the set `e.symm ⁻¹' s` is the same as the set intersected with the target
of `e` and some other neighborhood of `f x` (which will be the source of a chart on `Z`). -/
theorem preimage_eventuallyEq_target_inter_preimage_inter {e : PartialHomeomorph X Y} {s : Set X}
{t : Set Z} {x : X} {f : X → Z} (hf : ContinuousWithinAt f s x) (hxe : x ∈ e.source)
(ht : t ∈ 𝓝 (f x)) :
e.symm ⁻¹' s =ᶠ[𝓝 (e x)] (e.target ∩ e.symm ⁻¹' (s ∩ f ⁻¹' t) : Set Y) := by
rw [eventuallyEq_set, e.eventually_nhds _ hxe]
filter_upwards [e.open_source.mem_nhds hxe,
mem_nhdsWithin_iff_eventually.mp (hf.preimage_mem_nhdsWithin ht)]
intro y hy hyu
simp_rw [mem_inter_iff, mem_preimage, mem_inter_iff, e.mapsTo hy, true_and_iff, iff_self_and,
e.left_inv hy, iff_true_intro hyu]
#align local_homeomorph.preimage_eventually_eq_target_inter_preimage_inter PartialHomeomorph.preimage_eventuallyEq_target_inter_preimage_inter
theorem isOpen_inter_preimage {s : Set Y} (hs : IsOpen s) : IsOpen (e.source ∩ e ⁻¹' s) :=
e.continuousOn.isOpen_inter_preimage e.open_source hs
#align local_homeomorph.preimage_open_of_open PartialHomeomorph.isOpen_inter_preimage
theorem isOpen_inter_preimage_symm {s : Set X} (hs : IsOpen s) : IsOpen (e.target ∩ e.symm ⁻¹' s) :=
e.symm.continuousOn.isOpen_inter_preimage e.open_target hs
#align local_homeomorph.preimage_open_of_open_symm PartialHomeomorph.isOpen_inter_preimage_symm
/-- A partial homeomorphism is an open map on its source:
the image of an open subset of the source is open. -/
lemma isOpen_image_of_subset_source {s : Set X} (hs : IsOpen s) (hse : s ⊆ e.source) :
IsOpen (e '' s) := by
rw [(image_eq_target_inter_inv_preimage (e := e) hse)]
exact e.continuousOn_invFun.isOpen_inter_preimage e.open_target hs
#align local_homeomorph.image_open_of_open PartialHomeomorph.isOpen_image_of_subset_source
/-- The image of the restriction of an open set to the source is open. -/
theorem isOpen_image_source_inter {s : Set X} (hs : IsOpen s) :
IsOpen (e '' (e.source ∩ s)) :=
e.isOpen_image_of_subset_source (e.open_source.inter hs) inter_subset_left
#align local_homeomorph.image_open_of_open' PartialHomeomorph.isOpen_image_source_inter
/-- The inverse of a partial homeomorphism `e` is an open map on `e.target`. -/
lemma isOpen_image_symm_of_subset_target {t : Set Y} (ht : IsOpen t) (hte : t ⊆ e.target) :
IsOpen (e.symm '' t) :=
isOpen_image_of_subset_source e.symm ht (e.symm_source ▸ hte)
lemma isOpen_symm_image_iff_of_subset_target {t : Set Y} (hs : t ⊆ e.target) :
IsOpen (e.symm '' t) ↔ IsOpen t := by
refine ⟨fun h ↦ ?_, fun h ↦ e.symm.isOpen_image_of_subset_source h hs⟩
have hs' : e.symm '' t ⊆ e.source := by
rw [e.symm_image_eq_source_inter_preimage hs]
apply Set.inter_subset_left
rw [← e.image_symm_image_of_subset_target hs]
exact e.isOpen_image_of_subset_source h hs'
theorem isOpen_image_iff_of_subset_source {s : Set X} (hs : s ⊆ e.source) :
IsOpen (e '' s) ↔ IsOpen s := by
rw [← e.symm.isOpen_symm_image_iff_of_subset_target hs, e.symm_symm]
section IsImage
/-!
### `PartialHomeomorph.IsImage` relation
We say that `t : Set Y` is an image of `s : Set X` under a partial homeomorphism `e` if any of the
following equivalent conditions hold:
* `e '' (e.source ∩ s) = e.target ∩ t`;
* `e.source ∩ e ⁻¹ t = e.source ∩ s`;
* `∀ x ∈ e.source, e x ∈ t ↔ x ∈ s` (this one is used in the definition).
This definition is a restatement of `PartialEquiv.IsImage` for partial homeomorphisms.
In this section we transfer API about `PartialEquiv.IsImage` to partial homeomorphisms and
add a few `PartialHomeomorph`-specific lemmas like `PartialHomeomorph.IsImage.closure`.
-/
/-- We say that `t : Set Y` is an image of `s : Set X` under a partial homeomorphism `e`
if any of the following equivalent conditions hold:
* `e '' (e.source ∩ s) = e.target ∩ t`;
* `e.source ∩ e ⁻¹ t = e.source ∩ s`;
* `∀ x ∈ e.source, e x ∈ t ↔ x ∈ s` (this one is used in the definition).
-/
def IsImage (s : Set X) (t : Set Y) : Prop :=
∀ ⦃x⦄, x ∈ e.source → (e x ∈ t ↔ x ∈ s)
#align local_homeomorph.is_image PartialHomeomorph.IsImage
namespace IsImage
variable {e} {s : Set X} {t : Set Y} {x : X} {y : Y}
theorem toPartialEquiv (h : e.IsImage s t) : e.toPartialEquiv.IsImage s t :=
h
#align local_homeomorph.is_image.to_local_equiv PartialHomeomorph.IsImage.toPartialEquiv
theorem apply_mem_iff (h : e.IsImage s t) (hx : x ∈ e.source) : e x ∈ t ↔ x ∈ s :=
h hx
#align local_homeomorph.is_image.apply_mem_iff PartialHomeomorph.IsImage.apply_mem_iff
protected theorem symm (h : e.IsImage s t) : e.symm.IsImage t s :=
h.toPartialEquiv.symm
#align local_homeomorph.is_image.symm PartialHomeomorph.IsImage.symm
theorem symm_apply_mem_iff (h : e.IsImage s t) (hy : y ∈ e.target) : e.symm y ∈ s ↔ y ∈ t :=
h.symm hy
#align local_homeomorph.is_image.symm_apply_mem_iff PartialHomeomorph.IsImage.symm_apply_mem_iff
@[simp]
theorem symm_iff : e.symm.IsImage t s ↔ e.IsImage s t :=
⟨fun h => h.symm, fun h => h.symm⟩
#align local_homeomorph.is_image.symm_iff PartialHomeomorph.IsImage.symm_iff
protected theorem mapsTo (h : e.IsImage s t) : MapsTo e (e.source ∩ s) (e.target ∩ t) :=
h.toPartialEquiv.mapsTo
#align local_homeomorph.is_image.maps_to PartialHomeomorph.IsImage.mapsTo
theorem symm_mapsTo (h : e.IsImage s t) : MapsTo e.symm (e.target ∩ t) (e.source ∩ s) :=
h.symm.mapsTo
#align local_homeomorph.is_image.symm_maps_to PartialHomeomorph.IsImage.symm_mapsTo
theorem image_eq (h : e.IsImage s t) : e '' (e.source ∩ s) = e.target ∩ t :=
h.toPartialEquiv.image_eq
#align local_homeomorph.is_image.image_eq PartialHomeomorph.IsImage.image_eq
theorem symm_image_eq (h : e.IsImage s t) : e.symm '' (e.target ∩ t) = e.source ∩ s :=
h.symm.image_eq
#align local_homeomorph.is_image.symm_image_eq PartialHomeomorph.IsImage.symm_image_eq
theorem iff_preimage_eq : e.IsImage s t ↔ e.source ∩ e ⁻¹' t = e.source ∩ s :=
PartialEquiv.IsImage.iff_preimage_eq
#align local_homeomorph.is_image.iff_preimage_eq PartialHomeomorph.IsImage.iff_preimage_eq
alias ⟨preimage_eq, of_preimage_eq⟩ := iff_preimage_eq
#align local_homeomorph.is_image.preimage_eq PartialHomeomorph.IsImage.preimage_eq
#align local_homeomorph.is_image.of_preimage_eq PartialHomeomorph.IsImage.of_preimage_eq
theorem iff_symm_preimage_eq : e.IsImage s t ↔ e.target ∩ e.symm ⁻¹' s = e.target ∩ t :=
symm_iff.symm.trans iff_preimage_eq
#align local_homeomorph.is_image.iff_symm_preimage_eq PartialHomeomorph.IsImage.iff_symm_preimage_eq
alias ⟨symm_preimage_eq, of_symm_preimage_eq⟩ := iff_symm_preimage_eq
#align local_homeomorph.is_image.symm_preimage_eq PartialHomeomorph.IsImage.symm_preimage_eq
#align local_homeomorph.is_image.of_symm_preimage_eq PartialHomeomorph.IsImage.of_symm_preimage_eq
theorem iff_symm_preimage_eq' :
e.IsImage s t ↔ e.target ∩ e.symm ⁻¹' (e.source ∩ s) = e.target ∩ t := by
rw [iff_symm_preimage_eq, ← image_source_inter_eq, ← image_source_inter_eq']
#align local_homeomorph.is_image.iff_symm_preimage_eq' PartialHomeomorph.IsImage.iff_symm_preimage_eq'
alias ⟨symm_preimage_eq', of_symm_preimage_eq'⟩ := iff_symm_preimage_eq'
#align local_homeomorph.is_image.symm_preimage_eq' PartialHomeomorph.IsImage.symm_preimage_eq'
#align local_homeomorph.is_image.of_symm_preimage_eq' PartialHomeomorph.IsImage.of_symm_preimage_eq'
theorem iff_preimage_eq' : e.IsImage s t ↔ e.source ∩ e ⁻¹' (e.target ∩ t) = e.source ∩ s :=
symm_iff.symm.trans iff_symm_preimage_eq'
#align local_homeomorph.is_image.iff_preimage_eq' PartialHomeomorph.IsImage.iff_preimage_eq'
alias ⟨preimage_eq', of_preimage_eq'⟩ := iff_preimage_eq'
#align local_homeomorph.is_image.preimage_eq' PartialHomeomorph.IsImage.preimage_eq'
#align local_homeomorph.is_image.of_preimage_eq' PartialHomeomorph.IsImage.of_preimage_eq'
theorem of_image_eq (h : e '' (e.source ∩ s) = e.target ∩ t) : e.IsImage s t :=
PartialEquiv.IsImage.of_image_eq h
#align local_homeomorph.is_image.of_image_eq PartialHomeomorph.IsImage.of_image_eq
theorem of_symm_image_eq (h : e.symm '' (e.target ∩ t) = e.source ∩ s) : e.IsImage s t :=
PartialEquiv.IsImage.of_symm_image_eq h
#align local_homeomorph.is_image.of_symm_image_eq PartialHomeomorph.IsImage.of_symm_image_eq
protected theorem compl (h : e.IsImage s t) : e.IsImage sᶜ tᶜ := fun _ hx => (h hx).not
#align local_homeomorph.is_image.compl PartialHomeomorph.IsImage.compl
protected theorem inter {s' t'} (h : e.IsImage s t) (h' : e.IsImage s' t') :
e.IsImage (s ∩ s') (t ∩ t') := fun _ hx => (h hx).and (h' hx)
#align local_homeomorph.is_image.inter PartialHomeomorph.IsImage.inter
protected theorem union {s' t'} (h : e.IsImage s t) (h' : e.IsImage s' t') :
e.IsImage (s ∪ s') (t ∪ t') := fun _ hx => (h hx).or (h' hx)
#align local_homeomorph.is_image.union PartialHomeomorph.IsImage.union
protected theorem diff {s' t'} (h : e.IsImage s t) (h' : e.IsImage s' t') :
e.IsImage (s \ s') (t \ t') :=
h.inter h'.compl
#align local_homeomorph.is_image.diff PartialHomeomorph.IsImage.diff
theorem leftInvOn_piecewise {e' : PartialHomeomorph X Y} [∀ i, Decidable (i ∈ s)]
[∀ i, Decidable (i ∈ t)] (h : e.IsImage s t) (h' : e'.IsImage s t) :
LeftInvOn (t.piecewise e.symm e'.symm) (s.piecewise e e') (s.ite e.source e'.source) :=
h.toPartialEquiv.leftInvOn_piecewise h'
#align local_homeomorph.is_image.left_inv_on_piecewise PartialHomeomorph.IsImage.leftInvOn_piecewise
theorem inter_eq_of_inter_eq_of_eqOn {e' : PartialHomeomorph X Y} (h : e.IsImage s t)
(h' : e'.IsImage s t) (hs : e.source ∩ s = e'.source ∩ s) (Heq : EqOn e e' (e.source ∩ s)) :
e.target ∩ t = e'.target ∩ t :=
h.toPartialEquiv.inter_eq_of_inter_eq_of_eqOn h' hs Heq
#align local_homeomorph.is_image.inter_eq_of_inter_eq_of_eq_on PartialHomeomorph.IsImage.inter_eq_of_inter_eq_of_eqOn
theorem symm_eqOn_of_inter_eq_of_eqOn {e' : PartialHomeomorph X Y} (h : e.IsImage s t)
(hs : e.source ∩ s = e'.source ∩ s) (Heq : EqOn e e' (e.source ∩ s)) :
EqOn e.symm e'.symm (e.target ∩ t) :=
h.toPartialEquiv.symm_eq_on_of_inter_eq_of_eqOn hs Heq
#align local_homeomorph.is_image.symm_eq_on_of_inter_eq_of_eq_on PartialHomeomorph.IsImage.symm_eqOn_of_inter_eq_of_eqOn
theorem map_nhdsWithin_eq (h : e.IsImage s t) (hx : x ∈ e.source) : map e (𝓝[s] x) = 𝓝[t] e x := by
rw [e.map_nhdsWithin_eq hx, h.image_eq, e.nhdsWithin_target_inter (e.map_source hx)]
#align local_homeomorph.is_image.map_nhds_within_eq PartialHomeomorph.IsImage.map_nhdsWithin_eq
protected theorem closure (h : e.IsImage s t) : e.IsImage (closure s) (closure t) := fun x hx => by
simp only [mem_closure_iff_nhdsWithin_neBot, ← h.map_nhdsWithin_eq hx, map_neBot_iff]
#align local_homeomorph.is_image.closure PartialHomeomorph.IsImage.closure
protected theorem interior (h : e.IsImage s t) : e.IsImage (interior s) (interior t) := by
simpa only [closure_compl, compl_compl] using h.compl.closure.compl
#align local_homeomorph.is_image.interior PartialHomeomorph.IsImage.interior
protected theorem frontier (h : e.IsImage s t) : e.IsImage (frontier s) (frontier t) :=
h.closure.diff h.interior
#align local_homeomorph.is_image.frontier PartialHomeomorph.IsImage.frontier
theorem isOpen_iff (h : e.IsImage s t) : IsOpen (e.source ∩ s) ↔ IsOpen (e.target ∩ t) :=
⟨fun hs => h.symm_preimage_eq' ▸ e.symm.isOpen_inter_preimage hs, fun hs =>
h.preimage_eq' ▸ e.isOpen_inter_preimage hs⟩
#align local_homeomorph.is_image.is_open_iff PartialHomeomorph.IsImage.isOpen_iff
/-- Restrict a `PartialHomeomorph` to a pair of corresponding open sets. -/
@[simps toPartialEquiv]
def restr (h : e.IsImage s t) (hs : IsOpen (e.source ∩ s)) : PartialHomeomorph X Y where
toPartialEquiv := h.toPartialEquiv.restr
open_source := hs
open_target := h.isOpen_iff.1 hs
continuousOn_toFun := e.continuousOn.mono inter_subset_left
continuousOn_invFun := e.symm.continuousOn.mono inter_subset_left
#align local_homeomorph.is_image.restr PartialHomeomorph.IsImage.restr
end IsImage
theorem isImage_source_target : e.IsImage e.source e.target :=
e.toPartialEquiv.isImage_source_target
#align local_homeomorph.is_image_source_target PartialHomeomorph.isImage_source_target
theorem isImage_source_target_of_disjoint (e' : PartialHomeomorph X Y)
(hs : Disjoint e.source e'.source) (ht : Disjoint e.target e'.target) :
e.IsImage e'.source e'.target :=
e.toPartialEquiv.isImage_source_target_of_disjoint e'.toPartialEquiv hs ht
#align local_homeomorph.is_image_source_target_of_disjoint PartialHomeomorph.isImage_source_target_of_disjoint
/-- Preimage of interior or interior of preimage coincide for partial homeomorphisms,
when restricted to the source. -/
theorem preimage_interior (s : Set Y) :
e.source ∩ e ⁻¹' interior s = e.source ∩ interior (e ⁻¹' s) :=
(IsImage.of_preimage_eq rfl).interior.preimage_eq
#align local_homeomorph.preimage_interior PartialHomeomorph.preimage_interior
theorem preimage_closure (s : Set Y) : e.source ∩ e ⁻¹' closure s = e.source ∩ closure (e ⁻¹' s) :=
(IsImage.of_preimage_eq rfl).closure.preimage_eq
#align local_homeomorph.preimage_closure PartialHomeomorph.preimage_closure
theorem preimage_frontier (s : Set Y) :
e.source ∩ e ⁻¹' frontier s = e.source ∩ frontier (e ⁻¹' s) :=
(IsImage.of_preimage_eq rfl).frontier.preimage_eq
#align local_homeomorph.preimage_frontier PartialHomeomorph.preimage_frontier
end IsImage
/-- A `PartialEquiv` with continuous open forward map and open source is a `PartialHomeomorph`. -/
def ofContinuousOpenRestrict (e : PartialEquiv X Y) (hc : ContinuousOn e e.source)
(ho : IsOpenMap (e.source.restrict e)) (hs : IsOpen e.source) : PartialHomeomorph X Y where
toPartialEquiv := e
open_source := hs
open_target := by simpa only [range_restrict, e.image_source_eq_target] using ho.isOpen_range
continuousOn_toFun := hc
continuousOn_invFun := e.image_source_eq_target ▸ ho.continuousOn_image_of_leftInvOn e.leftInvOn
#align local_homeomorph.of_continuous_open_restrict PartialHomeomorph.ofContinuousOpenRestrict
/-- A `PartialEquiv` with continuous open forward map and open source is a `PartialHomeomorph`. -/
def ofContinuousOpen (e : PartialEquiv X Y) (hc : ContinuousOn e e.source) (ho : IsOpenMap e)
(hs : IsOpen e.source) : PartialHomeomorph X Y :=
ofContinuousOpenRestrict e hc (ho.restrict hs) hs
#align local_homeomorph.of_continuous_open PartialHomeomorph.ofContinuousOpen
/-- Restricting a partial homeomorphism `e` to `e.source ∩ s` when `s` is open.
This is sometimes hard to use because of the openness assumption, but it has the advantage that
when it can be used then its `PartialEquiv` is defeq to `PartialEquiv.restr`. -/
protected def restrOpen (s : Set X) (hs : IsOpen s) : PartialHomeomorph X Y :=
(@IsImage.of_symm_preimage_eq X Y _ _ e s (e.symm ⁻¹' s) rfl).restr
(IsOpen.inter e.open_source hs)
#align local_homeomorph.restr_open PartialHomeomorph.restrOpen
@[simp, mfld_simps]
theorem restrOpen_toPartialEquiv (s : Set X) (hs : IsOpen s) :
(e.restrOpen s hs).toPartialEquiv = e.toPartialEquiv.restr s :=
rfl
#align local_homeomorph.restr_open_to_local_equiv PartialHomeomorph.restrOpen_toPartialEquiv
-- Already simp via `PartialEquiv`
theorem restrOpen_source (s : Set X) (hs : IsOpen s) : (e.restrOpen s hs).source = e.source ∩ s :=
rfl
#align local_homeomorph.restr_open_source PartialHomeomorph.restrOpen_source
/-- Restricting a partial homeomorphism `e` to `e.source ∩ interior s`. We use the interior to make
sure that the restriction is well defined whatever the set s, since partial homeomorphisms are by
definition defined on open sets. In applications where `s` is open, this coincides with the
restriction of partial equivalences -/
@[simps! (config := mfld_cfg) apply symm_apply, simps! (config := .lemmasOnly) source target]
protected def restr (s : Set X) : PartialHomeomorph X Y :=
e.restrOpen (interior s) isOpen_interior
#align local_homeomorph.restr PartialHomeomorph.restr
@[simp, mfld_simps]
theorem restr_toPartialEquiv (s : Set X) :
(e.restr s).toPartialEquiv = e.toPartialEquiv.restr (interior s) :=
rfl
#align local_homeomorph.restr_to_local_equiv PartialHomeomorph.restr_toPartialEquiv
theorem restr_source' (s : Set X) (hs : IsOpen s) : (e.restr s).source = e.source ∩ s := by
rw [e.restr_source, hs.interior_eq]
#align local_homeomorph.restr_source' PartialHomeomorph.restr_source'
theorem restr_toPartialEquiv' (s : Set X) (hs : IsOpen s) :
(e.restr s).toPartialEquiv = e.toPartialEquiv.restr s := by
rw [e.restr_toPartialEquiv, hs.interior_eq]
#align local_homeomorph.restr_to_local_equiv' PartialHomeomorph.restr_toPartialEquiv'
theorem restr_eq_of_source_subset {e : PartialHomeomorph X Y} {s : Set X} (h : e.source ⊆ s) :
e.restr s = e :=
toPartialEquiv_injective <| PartialEquiv.restr_eq_of_source_subset <|
interior_maximal h e.open_source
#align local_homeomorph.restr_eq_of_source_subset PartialHomeomorph.restr_eq_of_source_subset
@[simp, mfld_simps]
theorem restr_univ {e : PartialHomeomorph X Y} : e.restr univ = e :=
restr_eq_of_source_subset (subset_univ _)
#align local_homeomorph.restr_univ PartialHomeomorph.restr_univ
theorem restr_source_inter (s : Set X) : e.restr (e.source ∩ s) = e.restr s := by
refine PartialHomeomorph.ext _ _ (fun x => rfl) (fun x => rfl) ?_
simp [e.open_source.interior_eq, ← inter_assoc]
#align local_homeomorph.restr_source_inter PartialHomeomorph.restr_source_inter
/-- The identity on the whole space as a partial homeomorphism. -/
@[simps! (config := mfld_cfg) apply, simps! (config := .lemmasOnly) source target]
protected def refl (X : Type*) [TopologicalSpace X] : PartialHomeomorph X X :=
(Homeomorph.refl X).toPartialHomeomorph
#align local_homeomorph.refl PartialHomeomorph.refl
@[simp, mfld_simps]
theorem refl_partialEquiv : (PartialHomeomorph.refl X).toPartialEquiv = PartialEquiv.refl X :=
rfl
#align local_homeomorph.refl_local_equiv PartialHomeomorph.refl_partialEquiv
@[simp, mfld_simps]
theorem refl_symm : (PartialHomeomorph.refl X).symm = PartialHomeomorph.refl X :=
rfl
#align local_homeomorph.refl_symm PartialHomeomorph.refl_symm
/-! ofSet: the identity on a set `s` -/
section ofSet
variable {s : Set X} (hs : IsOpen s)
/-- The identity partial equivalence on a set `s` -/
@[simps! (config := mfld_cfg) apply, simps! (config := .lemmasOnly) source target]
def ofSet (s : Set X) (hs : IsOpen s) : PartialHomeomorph X X where
toPartialEquiv := PartialEquiv.ofSet s
open_source := hs
open_target := hs
continuousOn_toFun := continuous_id.continuousOn
continuousOn_invFun := continuous_id.continuousOn
#align local_homeomorph.of_set PartialHomeomorph.ofSet
@[simp, mfld_simps]
theorem ofSet_toPartialEquiv : (ofSet s hs).toPartialEquiv = PartialEquiv.ofSet s :=
rfl
#align local_homeomorph.of_set_to_local_equiv PartialHomeomorph.ofSet_toPartialEquiv
@[simp, mfld_simps]
theorem ofSet_symm : (ofSet s hs).symm = ofSet s hs :=
rfl
#align local_homeomorph.of_set_symm PartialHomeomorph.ofSet_symm
@[simp, mfld_simps]
theorem ofSet_univ_eq_refl : ofSet univ isOpen_univ = PartialHomeomorph.refl X := by ext <;> simp
#align local_homeomorph.of_set_univ_eq_refl PartialHomeomorph.ofSet_univ_eq_refl
end ofSet
/-! `trans`: composition of two partial homeomorphisms -/
section trans
variable (e' : PartialHomeomorph Y Z)
/-- Composition of two partial homeomorphisms when the target of the first and the source of
the second coincide. -/
@[simps! apply symm_apply toPartialEquiv, simps! (config := .lemmasOnly) source target]
protected def trans' (h : e.target = e'.source) : PartialHomeomorph X Z where
toPartialEquiv := PartialEquiv.trans' e.toPartialEquiv e'.toPartialEquiv h
open_source := e.open_source
open_target := e'.open_target
continuousOn_toFun := e'.continuousOn.comp e.continuousOn <| h ▸ e.mapsTo
continuousOn_invFun := e.continuousOn_symm.comp e'.continuousOn_symm <| h.symm ▸ e'.symm_mapsTo
#align local_homeomorph.trans' PartialHomeomorph.trans'
/-- Composing two partial homeomorphisms, by restricting to the maximal domain where their
composition is well defined. -/
@[trans]
protected def trans : PartialHomeomorph X Z :=
PartialHomeomorph.trans' (e.symm.restrOpen e'.source e'.open_source).symm
(e'.restrOpen e.target e.open_target) (by simp [inter_comm])
#align local_homeomorph.trans PartialHomeomorph.trans
@[simp, mfld_simps]
theorem trans_toPartialEquiv :
(e.trans e').toPartialEquiv = e.toPartialEquiv.trans e'.toPartialEquiv :=
rfl
#align local_homeomorph.trans_to_local_equiv PartialHomeomorph.trans_toPartialEquiv
@[simp, mfld_simps]
theorem coe_trans : (e.trans e' : X → Z) = e' ∘ e :=
rfl
#align local_homeomorph.coe_trans PartialHomeomorph.coe_trans
@[simp, mfld_simps]
theorem coe_trans_symm : ((e.trans e').symm : Z → X) = e.symm ∘ e'.symm :=
rfl
#align local_homeomorph.coe_trans_symm PartialHomeomorph.coe_trans_symm
theorem trans_apply {x : X} : (e.trans e') x = e' (e x) :=
rfl
#align local_homeomorph.trans_apply PartialHomeomorph.trans_apply
theorem trans_symm_eq_symm_trans_symm : (e.trans e').symm = e'.symm.trans e.symm := rfl
#align local_homeomorph.trans_symm_eq_symm_trans_symm PartialHomeomorph.trans_symm_eq_symm_trans_symm
/- This could be considered as a simp lemma, but there are many situations where it makes something
simple into something more complicated. -/
theorem trans_source : (e.trans e').source = e.source ∩ e ⁻¹' e'.source :=
PartialEquiv.trans_source e.toPartialEquiv e'.toPartialEquiv
#align local_homeomorph.trans_source PartialHomeomorph.trans_source
theorem trans_source' : (e.trans e').source = e.source ∩ e ⁻¹' (e.target ∩ e'.source) :=
PartialEquiv.trans_source' e.toPartialEquiv e'.toPartialEquiv
#align local_homeomorph.trans_source' PartialHomeomorph.trans_source'
theorem trans_source'' : (e.trans e').source = e.symm '' (e.target ∩ e'.source) :=
PartialEquiv.trans_source'' e.toPartialEquiv e'.toPartialEquiv
#align local_homeomorph.trans_source'' PartialHomeomorph.trans_source''
theorem image_trans_source : e '' (e.trans e').source = e.target ∩ e'.source :=
PartialEquiv.image_trans_source e.toPartialEquiv e'.toPartialEquiv
#align local_homeomorph.image_trans_source PartialHomeomorph.image_trans_source
theorem trans_target : (e.trans e').target = e'.target ∩ e'.symm ⁻¹' e.target :=
rfl
#align local_homeomorph.trans_target PartialHomeomorph.trans_target
theorem trans_target' : (e.trans e').target = e'.target ∩ e'.symm ⁻¹' (e'.source ∩ e.target) :=
trans_source' e'.symm e.symm
#align local_homeomorph.trans_target' PartialHomeomorph.trans_target'
theorem trans_target'' : (e.trans e').target = e' '' (e'.source ∩ e.target) :=
trans_source'' e'.symm e.symm
#align local_homeomorph.trans_target'' PartialHomeomorph.trans_target''
theorem inv_image_trans_target : e'.symm '' (e.trans e').target = e'.source ∩ e.target :=
image_trans_source e'.symm e.symm
#align local_homeomorph.inv_image_trans_target PartialHomeomorph.inv_image_trans_target
theorem trans_assoc (e'' : PartialHomeomorph Z Z') :
(e.trans e').trans e'' = e.trans (e'.trans e'') :=
toPartialEquiv_injective <| e.1.trans_assoc _ _
#align local_homeomorph.trans_assoc PartialHomeomorph.trans_assoc
@[simp, mfld_simps]
theorem trans_refl : e.trans (PartialHomeomorph.refl Y) = e :=
toPartialEquiv_injective e.1.trans_refl
#align local_homeomorph.trans_refl PartialHomeomorph.trans_refl
@[simp, mfld_simps]
theorem refl_trans : (PartialHomeomorph.refl X).trans e = e :=
toPartialEquiv_injective e.1.refl_trans
#align local_homeomorph.refl_trans PartialHomeomorph.refl_trans
theorem trans_ofSet {s : Set Y} (hs : IsOpen s) : e.trans (ofSet s hs) = e.restr (e ⁻¹' s) :=
PartialHomeomorph.ext _ _ (fun _ => rfl) (fun _ => rfl) <| by
rw [trans_source, restr_source, ofSet_source, ← preimage_interior, hs.interior_eq]
#align local_homeomorph.trans_of_set PartialHomeomorph.trans_ofSet
theorem trans_of_set' {s : Set Y} (hs : IsOpen s) :
e.trans (ofSet s hs) = e.restr (e.source ∩ e ⁻¹' s) := by rw [trans_ofSet, restr_source_inter]
#align local_homeomorph.trans_of_set' PartialHomeomorph.trans_of_set'
theorem ofSet_trans {s : Set X} (hs : IsOpen s) : (ofSet s hs).trans e = e.restr s :=
PartialHomeomorph.ext _ _ (fun x => rfl) (fun x => rfl) <| by simp [hs.interior_eq, inter_comm]
#align local_homeomorph.of_set_trans PartialHomeomorph.ofSet_trans
theorem ofSet_trans' {s : Set X} (hs : IsOpen s) :
(ofSet s hs).trans e = e.restr (e.source ∩ s) := by
rw [ofSet_trans, restr_source_inter]
#align local_homeomorph.of_set_trans' PartialHomeomorph.ofSet_trans'
@[simp, mfld_simps]
theorem ofSet_trans_ofSet {s : Set X} (hs : IsOpen s) {s' : Set X} (hs' : IsOpen s') :
(ofSet s hs).trans (ofSet s' hs') = ofSet (s ∩ s') (IsOpen.inter hs hs') := by
rw [(ofSet s hs).trans_ofSet hs']
ext <;> simp [hs'.interior_eq]
#align local_homeomorph.of_set_trans_of_set PartialHomeomorph.ofSet_trans_ofSet
theorem restr_trans (s : Set X) : (e.restr s).trans e' = (e.trans e').restr s :=
toPartialEquiv_injective <|
PartialEquiv.restr_trans e.toPartialEquiv e'.toPartialEquiv (interior s)
#align local_homeomorph.restr_trans PartialHomeomorph.restr_trans
end trans
/-! `EqOnSource`: equivalence on their source -/
section EqOnSource
/-- `EqOnSource e e'` means that `e` and `e'` have the same source, and coincide there. They
should really be considered the same partial equivalence. -/
def EqOnSource (e e' : PartialHomeomorph X Y) : Prop :=
e.source = e'.source ∧ EqOn e e' e.source
#align local_homeomorph.eq_on_source PartialHomeomorph.EqOnSource
theorem eqOnSource_iff (e e' : PartialHomeomorph X Y) :
EqOnSource e e' ↔ PartialEquiv.EqOnSource e.toPartialEquiv e'.toPartialEquiv :=
Iff.rfl
#align local_homeomorph.eq_on_source_iff PartialHomeomorph.eqOnSource_iff
/-- `EqOnSource` is an equivalence relation. -/
instance eqOnSourceSetoid : Setoid (PartialHomeomorph X Y) :=
{ PartialEquiv.eqOnSourceSetoid.comap toPartialEquiv with r := EqOnSource }
theorem eqOnSource_refl : e ≈ e := Setoid.refl _
#align local_homeomorph.eq_on_source_refl PartialHomeomorph.eqOnSource_refl
/-- If two partial homeomorphisms are equivalent, so are their inverses. -/
theorem EqOnSource.symm' {e e' : PartialHomeomorph X Y} (h : e ≈ e') : e.symm ≈ e'.symm :=
PartialEquiv.EqOnSource.symm' h
#align local_homeomorph.eq_on_source.symm' PartialHomeomorph.EqOnSource.symm'
/-- Two equivalent partial homeomorphisms have the same source. -/
theorem EqOnSource.source_eq {e e' : PartialHomeomorph X Y} (h : e ≈ e') : e.source = e'.source :=
h.1
#align local_homeomorph.eq_on_source.source_eq PartialHomeomorph.EqOnSource.source_eq
/-- Two equivalent partial homeomorphisms have the same target. -/
theorem EqOnSource.target_eq {e e' : PartialHomeomorph X Y} (h : e ≈ e') : e.target = e'.target :=
h.symm'.1
#align local_homeomorph.eq_on_source.target_eq PartialHomeomorph.EqOnSource.target_eq
/-- Two equivalent partial homeomorphisms have coinciding `toFun` on the source -/
theorem EqOnSource.eqOn {e e' : PartialHomeomorph X Y} (h : e ≈ e') : EqOn e e' e.source :=
h.2
#align local_homeomorph.eq_on_source.eq_on PartialHomeomorph.EqOnSource.eqOn
/-- Two equivalent partial homeomorphisms have coinciding `invFun` on the target -/
theorem EqOnSource.symm_eqOn_target {e e' : PartialHomeomorph X Y} (h : e ≈ e') :
EqOn e.symm e'.symm e.target :=
h.symm'.2
#align local_homeomorph.eq_on_source.symm_eq_on_target PartialHomeomorph.EqOnSource.symm_eqOn_target
/-- Composition of partial homeomorphisms respects equivalence. -/
theorem EqOnSource.trans' {e e' : PartialHomeomorph X Y} {f f' : PartialHomeomorph Y Z}
(he : e ≈ e') (hf : f ≈ f') : e.trans f ≈ e'.trans f' :=
PartialEquiv.EqOnSource.trans' he hf
#align local_homeomorph.eq_on_source.trans' PartialHomeomorph.EqOnSource.trans'
/-- Restriction of partial homeomorphisms respects equivalence -/
theorem EqOnSource.restr {e e' : PartialHomeomorph X Y} (he : e ≈ e') (s : Set X) :
e.restr s ≈ e'.restr s :=
PartialEquiv.EqOnSource.restr he _
#align local_homeomorph.eq_on_source.restr PartialHomeomorph.EqOnSource.restr
/-- Two equivalent partial homeomorphisms are equal when the source and target are `univ`. -/
theorem Set.EqOn.restr_eqOn_source {e e' : PartialHomeomorph X Y}
(h : EqOn e e' (e.source ∩ e'.source)) : e.restr e'.source ≈ e'.restr e.source := by
constructor
· rw [e'.restr_source' _ e.open_source]
rw [e.restr_source' _ e'.open_source]
exact Set.inter_comm _ _
· rw [e.restr_source' _ e'.open_source]
refine (EqOn.trans ?_ h).trans ?_ <;> simp only [mfld_simps, eqOn_refl]
#align local_homeomorph.set.eq_on.restr_eq_on_source PartialHomeomorph.Set.EqOn.restr_eqOn_source
/-- Composition of a partial homeomorphism and its inverse is equivalent to the restriction of the
identity to the source -/
theorem self_trans_symm : e.trans e.symm ≈ PartialHomeomorph.ofSet e.source e.open_source :=
PartialEquiv.self_trans_symm _
#align local_homeomorph.self_trans_symm PartialHomeomorph.self_trans_symm
theorem symm_trans_self : e.symm.trans e ≈ PartialHomeomorph.ofSet e.target e.open_target :=
e.symm.self_trans_symm
#align local_homeomorph.symm_trans_self PartialHomeomorph.symm_trans_self
theorem eq_of_eqOnSource_univ {e e' : PartialHomeomorph X Y} (h : e ≈ e') (s : e.source = univ)
(t : e.target = univ) : e = e' :=
toPartialEquiv_injective <| PartialEquiv.eq_of_eqOnSource_univ _ _ h s t
#align local_homeomorph.eq_of_eq_on_source_univ PartialHomeomorph.eq_of_eqOnSource_univ
end EqOnSource
/-! product of two partial homeomorphisms -/
section Prod
/-- The product of two partial homeomorphisms, as a partial homeomorphism on the product space. -/
@[simps! (config := mfld_cfg) toPartialEquiv apply,
simps! (config := .lemmasOnly) source target symm_apply]
def prod (eX : PartialHomeomorph X X') (eY : PartialHomeomorph Y Y') :
PartialHomeomorph (X × Y) (X' × Y') where
open_source := eX.open_source.prod eY.open_source
open_target := eX.open_target.prod eY.open_target
continuousOn_toFun := eX.continuousOn.prod_map eY.continuousOn
continuousOn_invFun := eX.continuousOn_symm.prod_map eY.continuousOn_symm
toPartialEquiv := eX.toPartialEquiv.prod eY.toPartialEquiv
#align local_homeomorph.prod PartialHomeomorph.prod
@[simp, mfld_simps]
theorem prod_symm (eX : PartialHomeomorph X X') (eY : PartialHomeomorph Y Y') :
(eX.prod eY).symm = eX.symm.prod eY.symm :=
rfl
#align local_homeomorph.prod_symm PartialHomeomorph.prod_symm
@[simp]
theorem refl_prod_refl :
(PartialHomeomorph.refl X).prod (PartialHomeomorph.refl Y) = PartialHomeomorph.refl (X × Y) :=
PartialHomeomorph.ext _ _ (fun _ => rfl) (fun _ => rfl) univ_prod_univ
#align local_homeomorph.refl_prod_refl PartialHomeomorph.refl_prod_refl
@[simp, mfld_simps]
theorem prod_trans (e : PartialHomeomorph X Y) (f : PartialHomeomorph Y Z)
(e' : PartialHomeomorph X' Y') (f' : PartialHomeomorph Y' Z') :
(e.prod e').trans (f.prod f') = (e.trans f).prod (e'.trans f') :=
toPartialEquiv_injective <| e.1.prod_trans ..
#align local_homeomorph.prod_trans PartialHomeomorph.prod_trans
theorem prod_eq_prod_of_nonempty {eX eX' : PartialHomeomorph X X'} {eY eY' : PartialHomeomorph Y Y'}
(h : (eX.prod eY).source.Nonempty) : eX.prod eY = eX'.prod eY' ↔ eX = eX' ∧ eY = eY' := by
obtain ⟨⟨x, y⟩, -⟩ := id h
haveI : Nonempty X := ⟨x⟩
haveI : Nonempty X' := ⟨eX x⟩
haveI : Nonempty Y := ⟨y⟩
haveI : Nonempty Y' := ⟨eY y⟩
simp_rw [PartialHomeomorph.ext_iff, prod_apply, prod_symm_apply, prod_source, Prod.ext_iff,
Set.prod_eq_prod_iff_of_nonempty h, forall_and, Prod.forall, forall_const,
and_assoc, and_left_comm]
#align local_homeomorph.prod_eq_prod_of_nonempty PartialHomeomorph.prod_eq_prod_of_nonempty
theorem prod_eq_prod_of_nonempty'
{eX eX' : PartialHomeomorph X X'} {eY eY' : PartialHomeomorph Y Y'}
(h : (eX'.prod eY').source.Nonempty) : eX.prod eY = eX'.prod eY' ↔ eX = eX' ∧ eY = eY' := by
rw [eq_comm, prod_eq_prod_of_nonempty h, eq_comm, @eq_comm _ eY']
#align local_homeomorph.prod_eq_prod_of_nonempty' PartialHomeomorph.prod_eq_prod_of_nonempty'
end Prod
/-! finite product of partial homeomorphisms -/
section Pi
variable {ι : Type*} [Finite ι] {X Y : ι → Type*} [∀ i, TopologicalSpace (X i)]
[∀ i, TopologicalSpace (Y i)] (ei : ∀ i, PartialHomeomorph (X i) (Y i))
/-- The product of a finite family of `PartialHomeomorph`s. -/
@[simps toPartialEquiv]
def pi : PartialHomeomorph (∀ i, X i) (∀ i, Y i) where
toPartialEquiv := PartialEquiv.pi fun i => (ei i).toPartialEquiv
open_source := isOpen_set_pi finite_univ fun i _ => (ei i).open_source
open_target := isOpen_set_pi finite_univ fun i _ => (ei i).open_target
continuousOn_toFun := continuousOn_pi.2 fun i =>
(ei i).continuousOn.comp (continuous_apply _).continuousOn fun _f hf => hf i trivial
continuousOn_invFun := continuousOn_pi.2 fun i =>
(ei i).continuousOn_symm.comp (continuous_apply _).continuousOn fun _f hf => hf i trivial
#align local_homeomorph.pi PartialHomeomorph.pi
end Pi
/-! combining two partial homeomorphisms using `Set.piecewise` -/
section Piecewise
/-- Combine two `PartialHomeomorph`s using `Set.piecewise`. The source of the new
`PartialHomeomorph` is `s.ite e.source e'.source = e.source ∩ s ∪ e'.source \ s`, and similarly for
target. The function sends `e.source ∩ s` to `e.target ∩ t` using `e` and
`e'.source \ s` to `e'.target \ t` using `e'`, and similarly for the inverse function.
To ensure the maps `toFun` and `invFun` are inverse of each other on the new `source` and `target`,
the definition assumes that the sets `s` and `t` are related both by `e.is_image` and `e'.is_image`.
To ensure that the new maps are continuous on `source`/`target`, it also assumes that `e.source` and
`e'.source` meet `frontier s` on the same set and `e x = e' x` on this intersection. -/
@[simps! (config := .asFn) toPartialEquiv apply]
def piecewise (e e' : PartialHomeomorph X Y) (s : Set X) (t : Set Y) [∀ x, Decidable (x ∈ s)]
[∀ y, Decidable (y ∈ t)] (H : e.IsImage s t) (H' : e'.IsImage s t)
(Hs : e.source ∩ frontier s = e'.source ∩ frontier s)
(Heq : EqOn e e' (e.source ∩ frontier s)) : PartialHomeomorph X Y where
toPartialEquiv := e.toPartialEquiv.piecewise e'.toPartialEquiv s t H H'
open_source := e.open_source.ite e'.open_source Hs
open_target :=
e.open_target.ite e'.open_target <| H.frontier.inter_eq_of_inter_eq_of_eqOn H'.frontier Hs Heq
continuousOn_toFun := continuousOn_piecewise_ite e.continuousOn e'.continuousOn Hs Heq
continuousOn_invFun :=
continuousOn_piecewise_ite e.continuousOn_symm e'.continuousOn_symm
(H.frontier.inter_eq_of_inter_eq_of_eqOn H'.frontier Hs Heq)
(H.frontier.symm_eqOn_of_inter_eq_of_eqOn Hs Heq)
#align local_homeomorph.piecewise PartialHomeomorph.piecewise
@[simp]
theorem symm_piecewise (e e' : PartialHomeomorph X Y) {s : Set X} {t : Set Y}
[∀ x, Decidable (x ∈ s)] [∀ y, Decidable (y ∈ t)] (H : e.IsImage s t) (H' : e'.IsImage s t)
(Hs : e.source ∩ frontier s = e'.source ∩ frontier s)
(Heq : EqOn e e' (e.source ∩ frontier s)) :
(e.piecewise e' s t H H' Hs Heq).symm =
e.symm.piecewise e'.symm t s H.symm H'.symm
(H.frontier.inter_eq_of_inter_eq_of_eqOn H'.frontier Hs Heq)
(H.frontier.symm_eqOn_of_inter_eq_of_eqOn Hs Heq) :=
rfl
#align local_homeomorph.symm_piecewise PartialHomeomorph.symm_piecewise
/-- Combine two `PartialHomeomorph`s with disjoint sources and disjoint targets. We reuse
`PartialHomeomorph.piecewise` then override `toPartialEquiv` to `PartialEquiv.disjointUnion`.
This way we have better definitional equalities for `source` and `target`. -/
def disjointUnion (e e' : PartialHomeomorph X Y) [∀ x, Decidable (x ∈ e.source)]
[∀ y, Decidable (y ∈ e.target)] (Hs : Disjoint e.source e'.source)
(Ht : Disjoint e.target e'.target) : PartialHomeomorph X Y :=
(e.piecewise e' e.source e.target e.isImage_source_target
(e'.isImage_source_target_of_disjoint e Hs.symm Ht.symm)
(by rw [e.open_source.inter_frontier_eq, (Hs.symm.frontier_right e'.open_source).inter_eq])
(by
rw [e.open_source.inter_frontier_eq]
exact eqOn_empty _ _)).replaceEquiv
(e.toPartialEquiv.disjointUnion e'.toPartialEquiv Hs Ht)
(PartialEquiv.disjointUnion_eq_piecewise _ _ _ _).symm
#align local_homeomorph.disjoint_union PartialHomeomorph.disjointUnion
end Piecewise
section Continuity
/-- Continuity within a set at a point can be read under right composition with a local
homeomorphism, if the point is in its target -/
theorem continuousWithinAt_iff_continuousWithinAt_comp_right {f : Y → Z} {s : Set Y} {x : Y}
(h : x ∈ e.target) :
ContinuousWithinAt f s x ↔ ContinuousWithinAt (f ∘ e) (e ⁻¹' s) (e.symm x) := by
simp_rw [ContinuousWithinAt, ← @tendsto_map'_iff _ _ _ _ e,
e.map_nhdsWithin_preimage_eq (e.map_target h), (· ∘ ·), e.right_inv h]
#align local_homeomorph.continuous_within_at_iff_continuous_within_at_comp_right PartialHomeomorph.continuousWithinAt_iff_continuousWithinAt_comp_right
/-- Continuity at a point can be read under right composition with a partial homeomorphism, if the
point is in its target -/
theorem continuousAt_iff_continuousAt_comp_right {f : Y → Z} {x : Y} (h : x ∈ e.target) :
ContinuousAt f x ↔ ContinuousAt (f ∘ e) (e.symm x) := by
rw [← continuousWithinAt_univ, e.continuousWithinAt_iff_continuousWithinAt_comp_right h,
preimage_univ, continuousWithinAt_univ]
#align local_homeomorph.continuous_at_iff_continuous_at_comp_right PartialHomeomorph.continuousAt_iff_continuousAt_comp_right
/-- A function is continuous on a set if and only if its composition with a partial homeomorphism
on the right is continuous on the corresponding set. -/
theorem continuousOn_iff_continuousOn_comp_right {f : Y → Z} {s : Set Y} (h : s ⊆ e.target) :
ContinuousOn f s ↔ ContinuousOn (f ∘ e) (e.source ∩ e ⁻¹' s) := by
simp only [← e.symm_image_eq_source_inter_preimage h, ContinuousOn, forall_mem_image]
refine forall₂_congr fun x hx => ?_
rw [e.continuousWithinAt_iff_continuousWithinAt_comp_right (h hx),
e.symm_image_eq_source_inter_preimage h, inter_comm, continuousWithinAt_inter]
exact IsOpen.mem_nhds e.open_source (e.map_target (h hx))
#align local_homeomorph.continuous_on_iff_continuous_on_comp_right PartialHomeomorph.continuousOn_iff_continuousOn_comp_right
/-- Continuity within a set at a point can be read under left composition with a local
homeomorphism if a neighborhood of the initial point is sent to the source of the local
homeomorphism-/
theorem continuousWithinAt_iff_continuousWithinAt_comp_left {f : Z → X} {s : Set Z} {x : Z}
(hx : f x ∈ e.source) (h : f ⁻¹' e.source ∈ 𝓝[s] x) :
ContinuousWithinAt f s x ↔ ContinuousWithinAt (e ∘ f) s x := by
refine ⟨(e.continuousAt hx).comp_continuousWithinAt, fun fe_cont => ?_⟩
rw [← continuousWithinAt_inter' h] at fe_cont ⊢
have : ContinuousWithinAt (e.symm ∘ e ∘ f) (s ∩ f ⁻¹' e.source) x :=
haveI : ContinuousWithinAt e.symm univ (e (f x)) :=
(e.continuousAt_symm (e.map_source hx)).continuousWithinAt
ContinuousWithinAt.comp this fe_cont (subset_univ _)
exact this.congr (fun y hy => by simp [e.left_inv hy.2]) (by simp [e.left_inv hx])
#align local_homeomorph.continuous_within_at_iff_continuous_within_at_comp_left PartialHomeomorph.continuousWithinAt_iff_continuousWithinAt_comp_left
/-- Continuity at a point can be read under left composition with a partial homeomorphism if a
neighborhood of the initial point is sent to the source of the partial homeomorphism-/
theorem continuousAt_iff_continuousAt_comp_left {f : Z → X} {x : Z} (h : f ⁻¹' e.source ∈ 𝓝 x) :
ContinuousAt f x ↔ ContinuousAt (e ∘ f) x := by
have hx : f x ∈ e.source := (mem_of_mem_nhds h : _)
have h' : f ⁻¹' e.source ∈ 𝓝[univ] x := by rwa [nhdsWithin_univ]
rw [← continuousWithinAt_univ, ← continuousWithinAt_univ,
e.continuousWithinAt_iff_continuousWithinAt_comp_left hx h']
#align local_homeomorph.continuous_at_iff_continuous_at_comp_left PartialHomeomorph.continuousAt_iff_continuousAt_comp_left
/-- A function is continuous on a set if and only if its composition with a partial homeomorphism
on the left is continuous on the corresponding set. -/
theorem continuousOn_iff_continuousOn_comp_left {f : Z → X} {s : Set Z} (h : s ⊆ f ⁻¹' e.source) :
ContinuousOn f s ↔ ContinuousOn (e ∘ f) s :=
forall₂_congr fun _x hx =>
e.continuousWithinAt_iff_continuousWithinAt_comp_left (h hx)
(mem_of_superset self_mem_nhdsWithin h)
#align local_homeomorph.continuous_on_iff_continuous_on_comp_left PartialHomeomorph.continuousOn_iff_continuousOn_comp_left
/-- A function is continuous if and only if its composition with a partial homeomorphism
on the left is continuous and its image is contained in the source. -/
theorem continuous_iff_continuous_comp_left {f : Z → X} (h : f ⁻¹' e.source = univ) :
Continuous f ↔ Continuous (e ∘ f) := by
simp only [continuous_iff_continuousOn_univ]
exact e.continuousOn_iff_continuousOn_comp_left (Eq.symm h).subset
#align local_homeomorph.continuous_iff_continuous_comp_left PartialHomeomorph.continuous_iff_continuous_comp_left
end Continuity
/-- The homeomorphism obtained by restricting a `PartialHomeomorph` to a subset of the source. -/
@[simps]
def homeomorphOfImageSubsetSource {s : Set X} {t : Set Y} (hs : s ⊆ e.source) (ht : e '' s = t) :
s ≃ₜ t :=
have h₁ : MapsTo e s t := mapsTo'.2 ht.subset
have h₂ : t ⊆ e.target := ht ▸ e.image_source_eq_target ▸ image_subset e hs
have h₃ : MapsTo e.symm t s := ht ▸ forall_mem_image.2 fun _x hx =>
(e.left_inv (hs hx)).symm ▸ hx
{ toFun := MapsTo.restrict e s t h₁
invFun := MapsTo.restrict e.symm t s h₃
left_inv := fun a => Subtype.ext (e.left_inv (hs a.2))
right_inv := fun b => Subtype.eq <| e.right_inv (h₂ b.2)
continuous_toFun := (e.continuousOn.mono hs).restrict_mapsTo h₁
continuous_invFun := (e.continuousOn_symm.mono h₂).restrict_mapsTo h₃ }
#align local_homeomorph.homeomorph_of_image_subset_source PartialHomeomorph.homeomorphOfImageSubsetSource
/-- A partial homeomorphism defines a homeomorphism between its source and target. -/
@[simps!] -- Porting note: new `simps`
def toHomeomorphSourceTarget : e.source ≃ₜ e.target :=
e.homeomorphOfImageSubsetSource subset_rfl e.image_source_eq_target
#align local_homeomorph.to_homeomorph_source_target PartialHomeomorph.toHomeomorphSourceTarget
theorem secondCountableTopology_source [SecondCountableTopology Y] :
SecondCountableTopology e.source :=
e.toHomeomorphSourceTarget.secondCountableTopology
#align local_homeomorph.second_countable_topology_source PartialHomeomorph.secondCountableTopology_source
theorem nhds_eq_comap_inf_principal {x} (hx : x ∈ e.source) :
𝓝 x = comap e (𝓝 (e x)) ⊓ 𝓟 e.source := by
lift x to e.source using hx
rw [← e.open_source.nhdsWithin_eq x.2, ← map_nhds_subtype_val, ← map_comap_setCoe_val,
e.toHomeomorphSourceTarget.nhds_eq_comap, nhds_subtype_eq_comap]
simp only [(· ∘ ·), toHomeomorphSourceTarget_apply_coe, comap_comap]
/-- If a partial homeomorphism has source and target equal to univ, then it induces a homeomorphism
between the whole spaces, expressed in this definition. -/
@[simps (config := mfld_cfg) apply symm_apply]
-- Porting note (#11215): TODO: add a `PartialEquiv` version
def toHomeomorphOfSourceEqUnivTargetEqUniv (h : e.source = (univ : Set X)) (h' : e.target = univ) :
X ≃ₜ Y where
toFun := e
invFun := e.symm
left_inv x :=
e.left_inv <| by
rw [h]
exact mem_univ _
right_inv x :=
e.right_inv <| by
rw [h']
exact mem_univ _
continuous_toFun := by
simpa only [continuous_iff_continuousOn_univ, h] using e.continuousOn
continuous_invFun := by
simpa only [continuous_iff_continuousOn_univ, h'] using e.continuousOn_symm
#align local_homeomorph.to_homeomorph_of_source_eq_univ_target_eq_univ PartialHomeomorph.toHomeomorphOfSourceEqUnivTargetEqUniv
theorem openEmbedding_restrict : OpenEmbedding (e.source.restrict e) := by
refine openEmbedding_of_continuous_injective_open (e.continuousOn.comp_continuous
continuous_subtype_val Subtype.prop) e.injOn.injective fun V hV ↦ ?_
rw [Set.restrict_eq, Set.image_comp]
exact e.isOpen_image_of_subset_source (e.open_source.isOpenMap_subtype_val V hV)
fun _ ⟨x, _, h⟩ ↦ h ▸ x.2
/-- A partial homeomorphism whose source is all of `X` defines an open embedding of `X` into `Y`.
The converse is also true; see `OpenEmbedding.toPartialHomeomorph`. -/
theorem to_openEmbedding (h : e.source = Set.univ) : OpenEmbedding e :=
e.openEmbedding_restrict.comp
((Homeomorph.setCongr h).trans <| Homeomorph.Set.univ X).symm.openEmbedding
#align local_homeomorph.to_open_embedding PartialHomeomorph.to_openEmbedding
end PartialHomeomorph
namespace Homeomorph
variable (e : X ≃ₜ Y) (e' : Y ≃ₜ Z)
/- Register as simp lemmas that the fields of a partial homeomorphism built from a homeomorphism
correspond to the fields of the original homeomorphism. -/
@[simp, mfld_simps]
theorem refl_toPartialHomeomorph :
(Homeomorph.refl X).toPartialHomeomorph = PartialHomeomorph.refl X :=
rfl
#align homeomorph.refl_to_local_homeomorph Homeomorph.refl_toPartialHomeomorph
@[simp, mfld_simps]
theorem symm_toPartialHomeomorph : e.symm.toPartialHomeomorph = e.toPartialHomeomorph.symm :=
rfl
#align homeomorph.symm_to_local_homeomorph Homeomorph.symm_toPartialHomeomorph
@[simp, mfld_simps]
theorem trans_toPartialHomeomorph :
(e.trans e').toPartialHomeomorph = e.toPartialHomeomorph.trans e'.toPartialHomeomorph :=
PartialHomeomorph.toPartialEquiv_injective <| Equiv.trans_toPartialEquiv _ _
#align homeomorph.trans_to_local_homeomorph Homeomorph.trans_toPartialHomeomorph
/-- Precompose a partial homeomorphism with a homeomorphism.
We modify the source and target to have better definitional behavior. -/
@[simps! (config := .asFn)]
def transPartialHomeomorph (e : X ≃ₜ Y) (f' : PartialHomeomorph Y Z) : PartialHomeomorph X Z where
toPartialEquiv := e.toEquiv.transPartialEquiv f'.toPartialEquiv
open_source := f'.open_source.preimage e.continuous
open_target := f'.open_target
continuousOn_toFun := f'.continuousOn.comp e.continuous.continuousOn fun _ => id
continuousOn_invFun := e.symm.continuous.comp_continuousOn f'.symm.continuousOn
#align homeomorph.trans_local_homeomorph Homeomorph.transPartialHomeomorph
theorem transPartialHomeomorph_eq_trans (e : X ≃ₜ Y) (f' : PartialHomeomorph Y Z) :
e.transPartialHomeomorph f' = e.toPartialHomeomorph.trans f' :=
PartialHomeomorph.toPartialEquiv_injective <| Equiv.transPartialEquiv_eq_trans _ _
#align homeomorph.trans_local_homeomorph_eq_trans Homeomorph.transPartialHomeomorph_eq_trans
@[simp, mfld_simps]
theorem transPartialHomeomorph_trans (e : X ≃ₜ Y) (f : PartialHomeomorph Y Z)
(f' : PartialHomeomorph Z Z') :
(e.transPartialHomeomorph f).trans f' = e.transPartialHomeomorph (f.trans f') := by
simp only [transPartialHomeomorph_eq_trans, PartialHomeomorph.trans_assoc]
@[simp, mfld_simps]
| Mathlib/Topology/PartialHomeomorph.lean | 1,362 | 1,366 | theorem trans_transPartialHomeomorph (e : X ≃ₜ Y) (e' : Y ≃ₜ Z) (f'' : PartialHomeomorph Z Z') :
(e.trans e').transPartialHomeomorph f'' =
e.transPartialHomeomorph (e'.transPartialHomeomorph f'') := by |
simp only [transPartialHomeomorph_eq_trans, PartialHomeomorph.trans_assoc,
trans_toPartialHomeomorph]
|
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Data.Fintype.Order
import Mathlib.Data.Set.Finite
import Mathlib.Order.Category.FinPartOrd
import Mathlib.Order.Category.LinOrd
import Mathlib.CategoryTheory.Limits.Shapes.Images
import Mathlib.CategoryTheory.Limits.Shapes.RegularMono
import Mathlib.Data.Set.Subsingleton
#align_import order.category.NonemptyFinLinOrd from "leanprover-community/mathlib"@"fa4a805d16a9cd9c96e0f8edeb57dc5a07af1a19"
/-!
# Nonempty finite linear orders
This defines `NonemptyFinLinOrd`, the category of nonempty finite linear
orders with monotone maps. This is the index category for simplicial objects.
Note: `NonemptyFinLinOrd` is *not* a subcategory of `FinBddDistLat` because its morphisms do not
preserve `⊥` and `⊤`.
-/
universe u v
open CategoryTheory CategoryTheory.Limits
/-- A typeclass for nonempty finite linear orders. -/
class NonemptyFiniteLinearOrder (α : Type*) extends Fintype α, LinearOrder α where
Nonempty : Nonempty α := by infer_instance
#align nonempty_fin_lin_ord NonemptyFiniteLinearOrder
attribute [instance] NonemptyFiniteLinearOrder.Nonempty
instance (priority := 100) NonemptyFiniteLinearOrder.toBoundedOrder (α : Type*)
[NonemptyFiniteLinearOrder α] : BoundedOrder α :=
Fintype.toBoundedOrder α
#align nonempty_fin_lin_ord.to_bounded_order NonemptyFiniteLinearOrder.toBoundedOrder
instance PUnit.nonemptyFiniteLinearOrder : NonemptyFiniteLinearOrder PUnit where
#align punit.nonempty_fin_lin_ord PUnit.nonemptyFiniteLinearOrder
instance Fin.nonemptyFiniteLinearOrder (n : ℕ) : NonemptyFiniteLinearOrder (Fin (n + 1)) where
#align fin.nonempty_fin_lin_ord Fin.nonemptyFiniteLinearOrder
instance ULift.nonemptyFiniteLinearOrder (α : Type u) [NonemptyFiniteLinearOrder α] :
NonemptyFiniteLinearOrder (ULift.{v} α) :=
{ LinearOrder.lift' Equiv.ulift (Equiv.injective _) with }
#align ulift.nonempty_fin_lin_ord ULift.nonemptyFiniteLinearOrder
instance (α : Type*) [NonemptyFiniteLinearOrder α] : NonemptyFiniteLinearOrder αᵒᵈ :=
{ OrderDual.fintype α with }
/-- The category of nonempty finite linear orders. -/
def NonemptyFinLinOrd :=
Bundled NonemptyFiniteLinearOrder
set_option linter.uppercaseLean3 false in
#align NonemptyFinLinOrd NonemptyFinLinOrd
namespace NonemptyFinLinOrd
instance : BundledHom.ParentProjection @NonemptyFiniteLinearOrder.toLinearOrder :=
⟨⟩
deriving instance LargeCategory for NonemptyFinLinOrd
-- Porting note: probably see https://github.com/leanprover-community/mathlib4/issues/5020
instance : ConcreteCategory NonemptyFinLinOrd :=
BundledHom.concreteCategory _
instance : CoeSort NonemptyFinLinOrd Type* :=
Bundled.coeSort
/-- Construct a bundled `NonemptyFinLinOrd` from the underlying type and typeclass. -/
def of (α : Type*) [NonemptyFiniteLinearOrder α] : NonemptyFinLinOrd :=
Bundled.of α
set_option linter.uppercaseLean3 false in
#align NonemptyFinLinOrd.of NonemptyFinLinOrd.of
@[simp]
theorem coe_of (α : Type*) [NonemptyFiniteLinearOrder α] : ↥(of α) = α :=
rfl
set_option linter.uppercaseLean3 false in
#align NonemptyFinLinOrd.coe_of NonemptyFinLinOrd.coe_of
instance : Inhabited NonemptyFinLinOrd :=
⟨of PUnit⟩
instance (α : NonemptyFinLinOrd) : NonemptyFiniteLinearOrder α :=
α.str
instance hasForgetToLinOrd : HasForget₂ NonemptyFinLinOrd LinOrd :=
BundledHom.forget₂ _ _
set_option linter.uppercaseLean3 false in
#align NonemptyFinLinOrd.has_forget_to_LinOrd NonemptyFinLinOrd.hasForgetToLinOrd
instance hasForgetToFinPartOrd : HasForget₂ NonemptyFinLinOrd FinPartOrd where
forget₂ :=
{ obj := fun X => FinPartOrd.of X
map := @fun X Y => id }
set_option linter.uppercaseLean3 false in
#align NonemptyFinLinOrd.has_forget_to_FinPartOrd NonemptyFinLinOrd.hasForgetToFinPartOrd
/-- Constructs an equivalence between nonempty finite linear orders from an order isomorphism
between them. -/
@[simps]
def Iso.mk {α β : NonemptyFinLinOrd.{u}} (e : α ≃o β) : α ≅ β where
hom := (e : OrderHom _ _)
inv := (e.symm : OrderHom _ _)
hom_inv_id := by
ext x
exact e.symm_apply_apply x
inv_hom_id := by
ext x
exact e.apply_symm_apply x
set_option linter.uppercaseLean3 false in
#align NonemptyFinLinOrd.iso.mk NonemptyFinLinOrd.Iso.mk
/-- `OrderDual` as a functor. -/
@[simps]
def dual : NonemptyFinLinOrd ⥤ NonemptyFinLinOrd where
obj X := of Xᵒᵈ
map := OrderHom.dual
set_option linter.uppercaseLean3 false in
#align NonemptyFinLinOrd.dual NonemptyFinLinOrd.dual
/-- The equivalence between `NonemptyFinLinOrd` and itself induced by `OrderDual` both ways. -/
@[simps functor inverse]
def dualEquiv : NonemptyFinLinOrd ≌ NonemptyFinLinOrd where
functor := dual
inverse := dual
unitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X
counitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X
set_option linter.uppercaseLean3 false in
#align NonemptyFinLinOrd.dual_equiv NonemptyFinLinOrd.dualEquiv
instance {A B : NonemptyFinLinOrd.{u}} : FunLike (A ⟶ B) A B where
coe f := ⇑(show OrderHom A B from f)
coe_injective' _ _ h := by
ext x
exact congr_fun h x
-- porting note (#10670): this instance was not necessary in mathlib
instance {A B : NonemptyFinLinOrd.{u}} : OrderHomClass (A ⟶ B) A B where
map_rel f _ _ h := f.monotone h
| Mathlib/Order/Category/NonemptyFinLinOrd.lean | 150 | 163 | theorem mono_iff_injective {A B : NonemptyFinLinOrd.{u}} (f : A ⟶ B) :
Mono f ↔ Function.Injective f := by |
refine ⟨?_, ConcreteCategory.mono_of_injective f⟩
intro
intro a₁ a₂ h
let X := NonemptyFinLinOrd.of (ULift (Fin 1))
let g₁ : X ⟶ A := ⟨fun _ => a₁, fun _ _ _ => by rfl⟩
let g₂ : X ⟶ A := ⟨fun _ => a₂, fun _ _ _ => by rfl⟩
change g₁ (ULift.up (0 : Fin 1)) = g₂ (ULift.up (0 : Fin 1))
have eq : g₁ ≫ f = g₂ ≫ f := by
ext
exact h
rw [cancel_mono] at eq
rw [eq]
|
/-
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
| Mathlib/Data/List/Basic.lean | 2,083 | 2,099 | 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
|
/-
Copyright (c) 2021 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.Data.SetLike.Basic
import Mathlib.Data.Finset.Preimage
import Mathlib.ModelTheory.Semantics
#align_import model_theory.definability from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a"
/-!
# Definable Sets
This file defines what it means for a set over a first-order structure to be definable.
## Main Definitions
* `Set.Definable` is defined so that `A.Definable L s` indicates that the
set `s` of a finite cartesian power of `M` is definable with parameters in `A`.
* `Set.Definable₁` is defined so that `A.Definable₁ L s` indicates that
`(s : Set M)` is definable with parameters in `A`.
* `Set.Definable₂` is defined so that `A.Definable₂ L s` indicates that
`(s : Set (M × M))` is definable with parameters in `A`.
* A `FirstOrder.Language.DefinableSet` is defined so that `L.DefinableSet A α` is the boolean
algebra of subsets of `α → M` defined by formulas with parameters in `A`.
## Main Results
* `L.DefinableSet A α` forms a `BooleanAlgebra`
* `Set.Definable.image_comp` shows that definability is closed under projections in finite
dimensions.
-/
universe u v w u₁
namespace Set
variable {M : Type w} (A : Set M) (L : FirstOrder.Language.{u, v}) [L.Structure M]
open FirstOrder FirstOrder.Language FirstOrder.Language.Structure
variable {α : Type u₁} {β : Type*}
/-- A subset of a finite Cartesian product of a structure is definable over a set `A` when
membership in the set is given by a first-order formula with parameters from `A`. -/
def Definable (s : Set (α → M)) : Prop :=
∃ φ : L[[A]].Formula α, s = setOf φ.Realize
#align set.definable Set.Definable
variable {L} {A} {B : Set M} {s : Set (α → M)}
theorem Definable.map_expansion {L' : FirstOrder.Language} [L'.Structure M] (h : A.Definable L s)
(φ : L →ᴸ L') [φ.IsExpansionOn M] : A.Definable L' s := by
obtain ⟨ψ, rfl⟩ := h
refine ⟨(φ.addConstants A).onFormula ψ, ?_⟩
ext x
simp only [mem_setOf_eq, LHom.realize_onFormula]
#align set.definable.map_expansion Set.Definable.map_expansion
theorem definable_iff_exists_formula_sum :
A.Definable L s ↔ ∃ φ : L.Formula (A ⊕ α), s = {v | φ.Realize (Sum.elim (↑) v)} := by
rw [Definable, Equiv.exists_congr_left (BoundedFormula.constantsVarsEquiv)]
refine exists_congr (fun φ => iff_iff_eq.2 (congr_arg (s = ·) ?_))
ext
simp only [Formula.Realize, BoundedFormula.constantsVarsEquiv, constantsOn, mk₂_Relations,
BoundedFormula.mapTermRelEquiv_symm_apply, mem_setOf_eq]
refine BoundedFormula.realize_mapTermRel_id ?_ (fun _ _ _ => rfl)
intros
simp only [Term.constantsVarsEquivLeft_symm_apply, Term.realize_varsToConstants,
coe_con, Term.realize_relabel]
congr
ext a
rcases a with (_ | _) | _ <;> rfl
theorem empty_definable_iff :
(∅ : Set M).Definable L s ↔ ∃ φ : L.Formula α, s = setOf φ.Realize := by
rw [Definable, Equiv.exists_congr_left (LEquiv.addEmptyConstants L (∅ : Set M)).onFormula]
simp [-constantsOn]
#align set.empty_definable_iff Set.empty_definable_iff
theorem definable_iff_empty_definable_with_params :
A.Definable L s ↔ (∅ : Set M).Definable (L[[A]]) s :=
empty_definable_iff.symm
#align set.definable_iff_empty_definable_with_params Set.definable_iff_empty_definable_with_params
theorem Definable.mono (hAs : A.Definable L s) (hAB : A ⊆ B) : B.Definable L s := by
rw [definable_iff_empty_definable_with_params] at *
exact hAs.map_expansion (L.lhomWithConstantsMap (Set.inclusion hAB))
#align set.definable.mono Set.Definable.mono
@[simp]
theorem definable_empty : A.Definable L (∅ : Set (α → M)) :=
⟨⊥, by
ext
simp⟩
#align set.definable_empty Set.definable_empty
@[simp]
theorem definable_univ : A.Definable L (univ : Set (α → M)) :=
⟨⊤, by
ext
simp⟩
#align set.definable_univ Set.definable_univ
@[simp]
theorem Definable.inter {f g : Set (α → M)} (hf : A.Definable L f) (hg : A.Definable L g) :
A.Definable L (f ∩ g) := by
rcases hf with ⟨φ, rfl⟩
rcases hg with ⟨θ, rfl⟩
refine ⟨φ ⊓ θ, ?_⟩
ext
simp
#align set.definable.inter Set.Definable.inter
@[simp]
theorem Definable.union {f g : Set (α → M)} (hf : A.Definable L f) (hg : A.Definable L g) :
A.Definable L (f ∪ g) := by
rcases hf with ⟨φ, hφ⟩
rcases hg with ⟨θ, hθ⟩
refine ⟨φ ⊔ θ, ?_⟩
ext
rw [hφ, hθ, mem_setOf_eq, Formula.realize_sup, mem_union, mem_setOf_eq, mem_setOf_eq]
#align set.definable.union Set.Definable.union
theorem definable_finset_inf {ι : Type*} {f : ι → Set (α → M)} (hf : ∀ i, A.Definable L (f i))
(s : Finset ι) : A.Definable L (s.inf f) := by
classical
refine Finset.induction definable_univ (fun i s _ h => ?_) s
rw [Finset.inf_insert]
exact (hf i).inter h
#align set.definable_finset_inf Set.definable_finset_inf
theorem definable_finset_sup {ι : Type*} {f : ι → Set (α → M)} (hf : ∀ i, A.Definable L (f i))
(s : Finset ι) : A.Definable L (s.sup f) := by
classical
refine Finset.induction definable_empty (fun i s _ h => ?_) s
rw [Finset.sup_insert]
exact (hf i).union h
#align set.definable_finset_sup Set.definable_finset_sup
theorem definable_finset_biInter {ι : Type*} {f : ι → Set (α → M)}
(hf : ∀ i, A.Definable L (f i)) (s : Finset ι) : A.Definable L (⋂ i ∈ s, f i) := by
rw [← Finset.inf_set_eq_iInter]
exact definable_finset_inf hf s
#align set.definable_finset_bInter Set.definable_finset_biInter
theorem definable_finset_biUnion {ι : Type*} {f : ι → Set (α → M)}
(hf : ∀ i, A.Definable L (f i)) (s : Finset ι) : A.Definable L (⋃ i ∈ s, f i) := by
rw [← Finset.sup_set_eq_biUnion]
exact definable_finset_sup hf s
#align set.definable_finset_bUnion Set.definable_finset_biUnion
@[simp]
theorem Definable.compl {s : Set (α → M)} (hf : A.Definable L s) : A.Definable L sᶜ := by
rcases hf with ⟨φ, hφ⟩
refine ⟨φ.not, ?_⟩
ext v
rw [hφ, compl_setOf, mem_setOf, mem_setOf, Formula.realize_not]
#align set.definable.compl Set.Definable.compl
@[simp]
theorem Definable.sdiff {s t : Set (α → M)} (hs : A.Definable L s) (ht : A.Definable L t) :
A.Definable L (s \ t) :=
hs.inter ht.compl
#align set.definable.sdiff Set.Definable.sdiff
theorem Definable.preimage_comp (f : α → β) {s : Set (α → M)} (h : A.Definable L s) :
A.Definable L ((fun g : β → M => g ∘ f) ⁻¹' s) := by
obtain ⟨φ, rfl⟩ := h
refine ⟨φ.relabel f, ?_⟩
ext
simp only [Set.preimage_setOf_eq, mem_setOf_eq, Formula.realize_relabel]
#align set.definable.preimage_comp Set.Definable.preimage_comp
theorem Definable.image_comp_equiv {s : Set (β → M)} (h : A.Definable L s) (f : α ≃ β) :
A.Definable L ((fun g : β → M => g ∘ f) '' s) := by
refine (congr rfl ?_).mp (h.preimage_comp f.symm)
rw [image_eq_preimage_of_inverse]
· intro i
ext b
simp only [Function.comp_apply, Equiv.apply_symm_apply]
· intro i
ext a
simp
#align set.definable.image_comp_equiv Set.Definable.image_comp_equiv
theorem definable_iff_finitely_definable :
A.Definable L s ↔ ∃ (A0 : Finset M), (A0 : Set M) ⊆ A ∧
(A0 : Set M).Definable L s := by
letI := Classical.decEq M
letI := Classical.decEq α
constructor
· simp only [definable_iff_exists_formula_sum]
rintro ⟨φ, rfl⟩
let A0 := (φ.freeVarFinset.preimage Sum.inl
(Function.Injective.injOn Sum.inl_injective)).image Subtype.val
have hA0 : (A0 : Set M) ⊆ A := by simp [A0]
refine ⟨A0, hA0, (φ.restrictFreeVar
(Set.inclusion (Set.Subset.refl _))).relabel ?_, ?_⟩
· rintro ⟨a | a, ha⟩
· exact Sum.inl (Sum.inl ⟨a, by simpa [A0] using ha⟩)
· exact Sum.inl (Sum.inr a)
· ext v
simp only [Formula.Realize, BoundedFormula.realize_relabel,
Set.mem_setOf_eq]
apply Iff.symm
convert BoundedFormula.realize_restrictFreeVar _
ext a
rcases a with ⟨_ | _, _⟩ <;> simp
· rintro ⟨A0, hA0, hd⟩
exact Definable.mono hd hA0
/-- This lemma is only intended as a helper for `Definable.image_comp`. -/
theorem Definable.image_comp_sum_inl_fin (m : ℕ) {s : Set (Sum α (Fin m) → M)}
(h : A.Definable L s) : A.Definable L ((fun g : Sum α (Fin m) → M => g ∘ Sum.inl) '' s) := by
obtain ⟨φ, rfl⟩ := h
refine ⟨(BoundedFormula.relabel id φ).exs, ?_⟩
ext x
simp only [Set.mem_image, mem_setOf_eq, BoundedFormula.realize_exs,
BoundedFormula.realize_relabel, Function.comp_id, Fin.castAdd_zero, Fin.cast_refl]
constructor
· rintro ⟨y, hy, rfl⟩
exact
⟨y ∘ Sum.inr, (congr (congr rfl (Sum.elim_comp_inl_inr y).symm) (funext finZeroElim)).mp hy⟩
· rintro ⟨y, hy⟩
exact ⟨Sum.elim x y, (congr rfl (funext finZeroElim)).mp hy, Sum.elim_comp_inl _ _⟩
#align set.definable.image_comp_sum_inl_fin Set.Definable.image_comp_sum_inl_fin
/-- Shows that definability is closed under finite projections. -/
| Mathlib/ModelTheory/Definability.lean | 230 | 242 | theorem Definable.image_comp_embedding {s : Set (β → M)} (h : A.Definable L s) (f : α ↪ β)
[Finite β] : A.Definable L ((fun g : β → M => g ∘ f) '' s) := by |
classical
cases nonempty_fintype β
refine
(congr rfl (ext fun x => ?_)).mp
(((h.image_comp_equiv (Equiv.Set.sumCompl (range f))).image_comp_equiv
(Equiv.sumCongr (Equiv.ofInjective f f.injective)
(Fintype.equivFin (↥(range f)ᶜ)).symm)).image_comp_sum_inl_fin
_)
simp only [mem_preimage, mem_image, exists_exists_and_eq_and]
refine exists_congr fun y => and_congr_right fun _ => Eq.congr_left (funext fun a => ?_)
simp
|
/-
Copyright (c) 2022 Yuyang Zhao. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yuyang Zhao
-/
import Mathlib.Algebra.Algebra.Tower
import Mathlib.Algebra.MvPolynomial.Basic
#align_import ring_theory.mv_polynomial.tower from "leanprover-community/mathlib"@"bb168510ef455e9280a152e7f31673cabd3d7496"
/-!
# Algebra towers for multivariate polynomial
This file proves some basic results about the algebra tower structure for the type
`MvPolynomial σ R`.
This structure itself is provided elsewhere as `MvPolynomial.isScalarTower`
When you update this file, you can also try to make a corresponding update in
`RingTheory.Polynomial.Tower`.
-/
variable (R A B : Type*) {σ : Type*}
namespace MvPolynomial
section Semiring
variable [CommSemiring R] [CommSemiring A] [CommSemiring B]
variable [Algebra R A] [Algebra A B] [Algebra R B]
variable [IsScalarTower R A B]
variable {R B}
theorem aeval_map_algebraMap (x : σ → B) (p : MvPolynomial σ R) :
aeval x (map (algebraMap R A) p) = aeval x p := by
rw [aeval_def, aeval_def, eval₂_map, IsScalarTower.algebraMap_eq R A B]
#align mv_polynomial.aeval_map_algebra_map MvPolynomial.aeval_map_algebraMap
end Semiring
section CommSemiring
variable [CommSemiring R] [CommSemiring A] [CommSemiring B]
variable [Algebra R A] [Algebra A B] [Algebra R B] [IsScalarTower R A B]
variable {R A}
| Mathlib/RingTheory/MvPolynomial/Tower.lean | 48 | 53 | theorem aeval_algebraMap_apply (x : σ → A) (p : MvPolynomial σ R) :
aeval (algebraMap A B ∘ x) p = algebraMap A B (MvPolynomial.aeval x p) := by |
rw [aeval_def, aeval_def, ← coe_eval₂Hom, ← coe_eval₂Hom, map_eval₂Hom, ←
IsScalarTower.algebraMap_eq]
-- Porting note: added
simp only [Function.comp]
|
/-
Copyright (c) 2020 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca
-/
import Mathlib.Algebra.NeZero
import Mathlib.Algebra.Polynomial.BigOperators
import Mathlib.Algebra.Polynomial.Lifts
import Mathlib.Algebra.Polynomial.Splits
import Mathlib.RingTheory.RootsOfUnity.Complex
import Mathlib.NumberTheory.ArithmeticFunction
import Mathlib.RingTheory.RootsOfUnity.Basic
import Mathlib.FieldTheory.RatFunc.AsPolynomial
#align_import ring_theory.polynomial.cyclotomic.basic from "leanprover-community/mathlib"@"7fdeecc0d03cd40f7a165e6cf00a4d2286db599f"
/-!
# Cyclotomic polynomials.
For `n : ℕ` and an integral domain `R`, we define a modified version of the `n`-th cyclotomic
polynomial with coefficients in `R`, denoted `cyclotomic' n R`, as `∏ (X - μ)`, where `μ` varies
over the primitive `n`th roots of unity. If there is a primitive `n`th root of unity in `R` then
this the standard definition. We then define the standard cyclotomic polynomial `cyclotomic n R`
with coefficients in any ring `R`.
## Main definition
* `cyclotomic n R` : the `n`-th cyclotomic polynomial with coefficients in `R`.
## Main results
* `Polynomial.degree_cyclotomic` : The degree of `cyclotomic n` is `totient n`.
* `Polynomial.prod_cyclotomic_eq_X_pow_sub_one` : `X ^ n - 1 = ∏ (cyclotomic i)`, where `i`
divides `n`.
* `Polynomial.cyclotomic_eq_prod_X_pow_sub_one_pow_moebius` : The Möbius inversion formula for
`cyclotomic n R` over an abstract fraction field for `R[X]`.
## Implementation details
Our definition of `cyclotomic' n R` makes sense in any integral domain `R`, but the interesting
results hold if there is a primitive `n`-th root of unity in `R`. In particular, our definition is
not the standard one unless there is a primitive `n`th root of unity in `R`. For example,
`cyclotomic' 3 ℤ = 1`, since there are no primitive cube roots of unity in `ℤ`. The main example is
`R = ℂ`, we decided to work in general since the difficulties are essentially the same.
To get the standard cyclotomic polynomials, we use `unique_int_coeff_of_cycl`, with `R = ℂ`,
to get a polynomial with integer coefficients and then we map it to `R[X]`, for any ring `R`.
-/
open scoped Polynomial
noncomputable section
universe u
namespace Polynomial
section Cyclotomic'
section IsDomain
variable {R : Type*} [CommRing R] [IsDomain R]
/-- The modified `n`-th cyclotomic polynomial with coefficients in `R`, it is the usual cyclotomic
polynomial if there is a primitive `n`-th root of unity in `R`. -/
def cyclotomic' (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] : R[X] :=
∏ μ ∈ primitiveRoots n R, (X - C μ)
#align polynomial.cyclotomic' Polynomial.cyclotomic'
/-- The zeroth modified cyclotomic polyomial is `1`. -/
@[simp]
theorem cyclotomic'_zero (R : Type*) [CommRing R] [IsDomain R] : cyclotomic' 0 R = 1 := by
simp only [cyclotomic', Finset.prod_empty, primitiveRoots_zero]
#align polynomial.cyclotomic'_zero Polynomial.cyclotomic'_zero
/-- The first modified cyclotomic polyomial is `X - 1`. -/
@[simp]
theorem cyclotomic'_one (R : Type*) [CommRing R] [IsDomain R] : cyclotomic' 1 R = X - 1 := by
simp only [cyclotomic', Finset.prod_singleton, RingHom.map_one,
IsPrimitiveRoot.primitiveRoots_one]
#align polynomial.cyclotomic'_one Polynomial.cyclotomic'_one
/-- The second modified cyclotomic polyomial is `X + 1` if the characteristic of `R` is not `2`. -/
@[simp]
theorem cyclotomic'_two (R : Type*) [CommRing R] [IsDomain R] (p : ℕ) [CharP R p] (hp : p ≠ 2) :
cyclotomic' 2 R = X + 1 := by
rw [cyclotomic']
have prim_root_two : primitiveRoots 2 R = {(-1 : R)} := by
simp only [Finset.eq_singleton_iff_unique_mem, mem_primitiveRoots two_pos]
exact ⟨IsPrimitiveRoot.neg_one p hp, fun x => IsPrimitiveRoot.eq_neg_one_of_two_right⟩
simp only [prim_root_two, Finset.prod_singleton, RingHom.map_neg, RingHom.map_one, sub_neg_eq_add]
#align polynomial.cyclotomic'_two Polynomial.cyclotomic'_two
/-- `cyclotomic' n R` is monic. -/
theorem cyclotomic'.monic (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] :
(cyclotomic' n R).Monic :=
monic_prod_of_monic _ _ fun _ _ => monic_X_sub_C _
#align polynomial.cyclotomic'.monic Polynomial.cyclotomic'.monic
/-- `cyclotomic' n R` is different from `0`. -/
theorem cyclotomic'_ne_zero (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] : cyclotomic' n R ≠ 0 :=
(cyclotomic'.monic n R).ne_zero
#align polynomial.cyclotomic'_ne_zero Polynomial.cyclotomic'_ne_zero
/-- The natural degree of `cyclotomic' n R` is `totient n` if there is a primitive root of
unity in `R`. -/
theorem natDegree_cyclotomic' {ζ : R} {n : ℕ} (h : IsPrimitiveRoot ζ n) :
(cyclotomic' n R).natDegree = Nat.totient n := by
rw [cyclotomic']
rw [natDegree_prod (primitiveRoots n R) fun z : R => X - C z]
· simp only [IsPrimitiveRoot.card_primitiveRoots h, mul_one, natDegree_X_sub_C, Nat.cast_id,
Finset.sum_const, nsmul_eq_mul]
intro z _
exact X_sub_C_ne_zero z
#align polynomial.nat_degree_cyclotomic' Polynomial.natDegree_cyclotomic'
/-- The degree of `cyclotomic' n R` is `totient n` if there is a primitive root of unity in `R`. -/
theorem degree_cyclotomic' {ζ : R} {n : ℕ} (h : IsPrimitiveRoot ζ n) :
(cyclotomic' n R).degree = Nat.totient n := by
simp only [degree_eq_natDegree (cyclotomic'_ne_zero n R), natDegree_cyclotomic' h]
#align polynomial.degree_cyclotomic' Polynomial.degree_cyclotomic'
/-- The roots of `cyclotomic' n R` are the primitive `n`-th roots of unity. -/
theorem roots_of_cyclotomic (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] :
(cyclotomic' n R).roots = (primitiveRoots n R).val := by
rw [cyclotomic']; exact roots_prod_X_sub_C (primitiveRoots n R)
#align polynomial.roots_of_cyclotomic Polynomial.roots_of_cyclotomic
/-- If there is a primitive `n`th root of unity in `K`, then `X ^ n - 1 = ∏ (X - μ)`, where `μ`
varies over the `n`-th roots of unity. -/
theorem X_pow_sub_one_eq_prod {ζ : R} {n : ℕ} (hpos : 0 < n) (h : IsPrimitiveRoot ζ n) :
X ^ n - 1 = ∏ ζ ∈ nthRootsFinset n R, (X - C ζ) := by
classical
rw [nthRootsFinset, ← Multiset.toFinset_eq (IsPrimitiveRoot.nthRoots_one_nodup h)]
simp only [Finset.prod_mk, RingHom.map_one]
rw [nthRoots]
have hmonic : (X ^ n - C (1 : R)).Monic := monic_X_pow_sub_C (1 : R) (ne_of_lt hpos).symm
symm
apply prod_multiset_X_sub_C_of_monic_of_roots_card_eq hmonic
rw [@natDegree_X_pow_sub_C R _ _ n 1, ← nthRoots]
exact IsPrimitiveRoot.card_nthRoots_one h
set_option linter.uppercaseLean3 false in
#align polynomial.X_pow_sub_one_eq_prod Polynomial.X_pow_sub_one_eq_prod
end IsDomain
section Field
variable {K : Type*} [Field K]
/-- `cyclotomic' n K` splits. -/
theorem cyclotomic'_splits (n : ℕ) : Splits (RingHom.id K) (cyclotomic' n K) := by
apply splits_prod (RingHom.id K)
intro z _
simp only [splits_X_sub_C (RingHom.id K)]
#align polynomial.cyclotomic'_splits Polynomial.cyclotomic'_splits
/-- If there is a primitive `n`-th root of unity in `K`, then `X ^ n - 1` splits. -/
theorem X_pow_sub_one_splits {ζ : K} {n : ℕ} (h : IsPrimitiveRoot ζ n) :
Splits (RingHom.id K) (X ^ n - C (1 : K)) := by
rw [splits_iff_card_roots, ← nthRoots, IsPrimitiveRoot.card_nthRoots_one h, natDegree_X_pow_sub_C]
set_option linter.uppercaseLean3 false in
#align polynomial.X_pow_sub_one_splits Polynomial.X_pow_sub_one_splits
/-- If there is a primitive `n`-th root of unity in `K`, then
`∏ i ∈ Nat.divisors n, cyclotomic' i K = X ^ n - 1`. -/
| Mathlib/RingTheory/Polynomial/Cyclotomic/Basic.lean | 167 | 174 | theorem prod_cyclotomic'_eq_X_pow_sub_one {K : Type*} [CommRing K] [IsDomain K] {ζ : K} {n : ℕ}
(hpos : 0 < n) (h : IsPrimitiveRoot ζ n) :
∏ i ∈ Nat.divisors n, cyclotomic' i K = X ^ n - 1 := by |
classical
have hd : (n.divisors : Set ℕ).PairwiseDisjoint fun k => primitiveRoots k K :=
fun x _ y _ hne => IsPrimitiveRoot.disjoint hne
simp only [X_pow_sub_one_eq_prod hpos h, cyclotomic', ← Finset.prod_biUnion hd,
h.nthRoots_one_eq_biUnion_primitiveRoots]
|
/-
Copyright (c) 2020 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import Mathlib.Algebra.Polynomial.Degree.TrailingDegree
import Mathlib.Algebra.Polynomial.EraseLead
import Mathlib.Algebra.Polynomial.Eval
#align_import data.polynomial.reverse from "leanprover-community/mathlib"@"44de64f183393284a16016dfb2a48ac97382f2bd"
/-!
# Reverse of a univariate polynomial
The main definition is `reverse`. Applying `reverse` to a polynomial `f : R[X]` produces
the polynomial with a reversed list of coefficients, equivalent to `X^f.natDegree * f(1/X)`.
The main result is that `reverse (f * g) = reverse f * reverse g`, provided the leading
coefficients of `f` and `g` do not multiply to zero.
-/
namespace Polynomial
open Polynomial Finsupp Finset
open Polynomial
section Semiring
variable {R : Type*} [Semiring R] {f : R[X]}
/-- If `i ≤ N`, then `revAtFun N i` returns `N - i`, otherwise it returns `i`.
This is the map used by the embedding `revAt`.
-/
def revAtFun (N i : ℕ) : ℕ :=
ite (i ≤ N) (N - i) i
#align polynomial.rev_at_fun Polynomial.revAtFun
theorem revAtFun_invol {N i : ℕ} : revAtFun N (revAtFun N i) = i := by
unfold revAtFun
split_ifs with h j
· exact tsub_tsub_cancel_of_le h
· exfalso
apply j
exact Nat.sub_le N i
· rfl
#align polynomial.rev_at_fun_invol Polynomial.revAtFun_invol
theorem revAtFun_inj {N : ℕ} : Function.Injective (revAtFun N) := by
intro a b hab
rw [← @revAtFun_invol N a, hab, revAtFun_invol]
#align polynomial.rev_at_fun_inj Polynomial.revAtFun_inj
/-- If `i ≤ N`, then `revAt N i` returns `N - i`, otherwise it returns `i`.
Essentially, this embedding is only used for `i ≤ N`.
The advantage of `revAt N i` over `N - i` is that `revAt` is an involution.
-/
def revAt (N : ℕ) : Function.Embedding ℕ ℕ where
toFun i := ite (i ≤ N) (N - i) i
inj' := revAtFun_inj
#align polynomial.rev_at Polynomial.revAt
/-- We prefer to use the bundled `revAt` over unbundled `revAtFun`. -/
@[simp]
theorem revAtFun_eq (N i : ℕ) : revAtFun N i = revAt N i :=
rfl
#align polynomial.rev_at_fun_eq Polynomial.revAtFun_eq
@[simp]
theorem revAt_invol {N i : ℕ} : (revAt N) (revAt N i) = i :=
revAtFun_invol
#align polynomial.rev_at_invol Polynomial.revAt_invol
@[simp]
theorem revAt_le {N i : ℕ} (H : i ≤ N) : revAt N i = N - i :=
if_pos H
#align polynomial.rev_at_le Polynomial.revAt_le
lemma revAt_eq_self_of_lt {N i : ℕ} (h : N < i) : revAt N i = i := by simp [revAt, Nat.not_le.mpr h]
| Mathlib/Algebra/Polynomial/Reverse.lean | 82 | 88 | theorem revAt_add {N O n o : ℕ} (hn : n ≤ N) (ho : o ≤ O) :
revAt (N + O) (n + o) = revAt N n + revAt O o := by |
rcases Nat.le.dest hn with ⟨n', rfl⟩
rcases Nat.le.dest ho with ⟨o', rfl⟩
repeat' rw [revAt_le (le_add_right rfl.le)]
rw [add_assoc, add_left_comm n' o, ← add_assoc, revAt_le (le_add_right rfl.le)]
repeat' rw [add_tsub_cancel_left]
|
/-
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.Data.Real.Basic
import Mathlib.Combinatorics.Pigeonhole
import Mathlib.Algebra.Order.EuclideanAbsoluteValue
#align_import number_theory.class_number.admissible_absolute_value from "leanprover-community/mathlib"@"f7fc89d5d5ff1db2d1242c7bb0e9062ce47ef47c"
/-!
# Admissible absolute values
This file defines a structure `AbsoluteValue.IsAdmissible` which we use to show the class number
of the ring of integers of a global field is finite.
## Main definitions
* `AbsoluteValue.IsAdmissible abv` states the absolute value `abv : R → ℤ`
respects the Euclidean domain structure on `R`, and that a large enough set
of elements of `R^n` contains a pair of elements whose remainders are
pointwise close together.
## Main results
* `AbsoluteValue.absIsAdmissible` shows the "standard" absolute value on `ℤ`,
mapping negative `x` to `-x`, is admissible.
* `Polynomial.cardPowDegreeIsAdmissible` shows `cardPowDegree`,
mapping `p : Polynomial 𝔽_q` to `q ^ degree p`, is admissible
-/
local infixl:50 " ≺ " => EuclideanDomain.r
namespace AbsoluteValue
variable {R : Type*} [EuclideanDomain R]
variable (abv : AbsoluteValue R ℤ)
/-- An absolute value `R → ℤ` is admissible if it respects the Euclidean domain
structure and a large enough set of elements in `R^n` will contain a pair of
elements whose remainders are pointwise close together. -/
structure IsAdmissible extends IsEuclidean abv where
protected card : ℝ → ℕ
/-- For all `ε > 0` and finite families `A`, we can partition the remainders of `A` mod `b`
into `abv.card ε` sets, such that all elements in each part of remainders are close together. -/
exists_partition' :
∀ (n : ℕ) {ε : ℝ} (_ : 0 < ε) {b : R} (_ : b ≠ 0) (A : Fin n → R),
∃ t : Fin n → Fin (card ε), ∀ i₀ i₁, t i₀ = t i₁ → (abv (A i₁ % b - A i₀ % b) : ℝ) < abv b • ε
#align absolute_value.is_admissible AbsoluteValue.IsAdmissible
-- Porting note: no docstrings for IsAdmissible
attribute [nolint docBlame] IsAdmissible.card
namespace IsAdmissible
variable {abv}
/-- For all `ε > 0` and finite families `A`, we can partition the remainders of `A` mod `b`
into `abv.card ε` sets, such that all elements in each part of remainders are close together. -/
theorem exists_partition {ι : Type*} [Finite ι] {ε : ℝ} (hε : 0 < ε) {b : R} (hb : b ≠ 0)
(A : ι → R) (h : abv.IsAdmissible) : ∃ t : ι → Fin (h.card ε),
∀ i₀ i₁, t i₀ = t i₁ → (abv (A i₁ % b - A i₀ % b) : ℝ) < abv b • ε := by
rcases Finite.exists_equiv_fin ι with ⟨n, ⟨e⟩⟩
obtain ⟨t, ht⟩ := h.exists_partition' n hε hb (A ∘ e.symm)
refine ⟨t ∘ e, fun i₀ i₁ h ↦ ?_⟩
convert (config := {transparency := .default})
ht (e i₀) (e i₁) h <;> simp only [e.symm_apply_apply]
#align absolute_value.is_admissible.exists_partition AbsoluteValue.IsAdmissible.exists_partition
/-- Any large enough family of vectors in `R^n` has a pair of elements
whose remainders are close together, pointwise. -/
theorem exists_approx_aux (n : ℕ) (h : abv.IsAdmissible) :
∀ {ε : ℝ} (_hε : 0 < ε) {b : R} (_hb : b ≠ 0) (A : Fin (h.card ε ^ n).succ → Fin n → R),
∃ i₀ i₁, i₀ ≠ i₁ ∧ ∀ k, (abv (A i₁ k % b - A i₀ k % b) : ℝ) < abv b • ε := by
haveI := Classical.decEq R
induction' n with n ih
· intro ε _hε b _hb A
refine ⟨0, 1, ?_, ?_⟩
· simp
rintro ⟨i, ⟨⟩⟩
intro ε hε b hb A
let M := h.card ε
-- By the "nicer" pigeonhole principle, we can find a collection `s`
-- of more than `M^n` remainders where the first components lie close together:
obtain ⟨s, s_inj, hs⟩ :
∃ s : Fin (M ^ n).succ → Fin (M ^ n.succ).succ,
Function.Injective s ∧ ∀ i₀ i₁, (abv (A (s i₁) 0 % b - A (s i₀) 0 % b) : ℝ) < abv b • ε := by
-- We can partition the `A`s into `M` subsets where
-- the first components lie close together:
obtain ⟨t, ht⟩ :
∃ t : Fin (M ^ n.succ).succ → Fin M,
∀ i₀ i₁, t i₀ = t i₁ → (abv (A i₁ 0 % b - A i₀ 0 % b) : ℝ) < abv b • ε :=
h.exists_partition hε hb fun x ↦ A x 0
-- Since the `M` subsets contain more than `M * M^n` elements total,
-- there must be a subset that contains more than `M^n` elements.
obtain ⟨s, hs⟩ :=
Fintype.exists_lt_card_fiber_of_mul_lt_card (f := t)
(by simpa only [Fintype.card_fin, pow_succ'] using Nat.lt_succ_self (M ^ n.succ))
refine ⟨fun i ↦ (Finset.univ.filter fun x ↦ t x = s).toList.get <| i.castLE ?_, fun i j h ↦ ?_,
fun i₀ i₁ ↦ ht _ _ ?_⟩
· rwa [Finset.length_toList]
· simpa [(Finset.nodup_toList _).get_inj_iff] using h
· have : ∀ i, t ((Finset.univ.filter fun x ↦ t x = s).toList.get i) = s := fun i ↦
(Finset.mem_filter.mp (Finset.mem_toList.mp (List.get_mem _ i i.2))).2
simp [this]
-- Since `s` is large enough, there are two elements of `A ∘ s`
-- where the second components lie close together.
obtain ⟨k₀, k₁, hk, h⟩ := ih hε hb fun x ↦ Fin.tail (A (s x))
refine ⟨s k₀, s k₁, fun h ↦ hk (s_inj h), fun i ↦ Fin.cases ?_ (fun i ↦ ?_) i⟩
· exact hs k₀ k₁
· exact h i
#align absolute_value.is_admissible.exists_approx_aux AbsoluteValue.IsAdmissible.exists_approx_aux
/-- Any large enough family of vectors in `R^ι` has a pair of elements
whose remainders are close together, pointwise. -/
| Mathlib/NumberTheory/ClassNumber/AdmissibleAbsoluteValue.lean | 117 | 123 | theorem exists_approx {ι : Type*} [Fintype ι] {ε : ℝ} (hε : 0 < ε) {b : R} (hb : b ≠ 0)
(h : abv.IsAdmissible) (A : Fin (h.card ε ^ Fintype.card ι).succ → ι → R) :
∃ i₀ i₁, i₀ ≠ i₁ ∧ ∀ k, (abv (A i₁ k % b - A i₀ k % b) : ℝ) < abv b • ε := by |
let e := Fintype.equivFin ι
obtain ⟨i₀, i₁, ne, h⟩ := h.exists_approx_aux (Fintype.card ι) hε hb fun x y ↦ A x (e.symm y)
refine ⟨i₀, i₁, ne, fun k ↦ ?_⟩
convert h (e k) <;> simp only [e.symm_apply_apply]
|
/-
Copyright (c) 2019 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Sébastien Gouëzel, Yury Kudryashov
-/
import Mathlib.Analysis.Calculus.FDeriv.Basic
#align_import analysis.calculus.fderiv.restrict_scalars from "leanprover-community/mathlib"@"e3fb84046afd187b710170887195d50bada934ee"
/-!
# The derivative of the scalar restriction of a linear map
For detailed documentation of the Fréchet derivative,
see the module docstring of `Analysis/Calculus/FDeriv/Basic.lean`.
This file contains the usual formulas (and existence assertions) for the derivative of
the scalar restriction of a linear map.
-/
open Filter Asymptotics ContinuousLinearMap Set Metric
open scoped Classical
open Topology NNReal Filter Asymptotics ENNReal
noncomputable section
section RestrictScalars
/-!
### Restricting from `ℂ` to `ℝ`, or generally from `𝕜'` to `𝕜`
If a function is differentiable over `ℂ`, then it is differentiable over `ℝ`. In this paragraph,
we give variants of this statement, in the general situation where `ℂ` and `ℝ` are replaced
respectively by `𝕜'` and `𝕜` where `𝕜'` is a normed algebra over `𝕜`.
-/
variable (𝕜 : Type*) [NontriviallyNormedField 𝕜]
variable {𝕜' : Type*} [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜 𝕜']
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedSpace 𝕜' E]
variable [IsScalarTower 𝕜 𝕜' E]
variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] [NormedSpace 𝕜' F]
variable [IsScalarTower 𝕜 𝕜' F]
variable {f : E → F} {f' : E →L[𝕜'] F} {s : Set E} {x : E}
@[fun_prop]
theorem HasStrictFDerivAt.restrictScalars (h : HasStrictFDerivAt f f' x) :
HasStrictFDerivAt f (f'.restrictScalars 𝕜) x :=
h
#align has_strict_fderiv_at.restrict_scalars HasStrictFDerivAt.restrictScalars
theorem HasFDerivAtFilter.restrictScalars {L} (h : HasFDerivAtFilter f f' x L) :
HasFDerivAtFilter f (f'.restrictScalars 𝕜) x L :=
.of_isLittleO h.1
#align has_fderiv_at_filter.restrict_scalars HasFDerivAtFilter.restrictScalars
@[fun_prop]
theorem HasFDerivAt.restrictScalars (h : HasFDerivAt f f' x) :
HasFDerivAt f (f'.restrictScalars 𝕜) x :=
.of_isLittleO h.1
#align has_fderiv_at.restrict_scalars HasFDerivAt.restrictScalars
@[fun_prop]
theorem HasFDerivWithinAt.restrictScalars (h : HasFDerivWithinAt f f' s x) :
HasFDerivWithinAt f (f'.restrictScalars 𝕜) s x :=
.of_isLittleO h.1
#align has_fderiv_within_at.restrict_scalars HasFDerivWithinAt.restrictScalars
@[fun_prop]
theorem DifferentiableAt.restrictScalars (h : DifferentiableAt 𝕜' f x) : DifferentiableAt 𝕜 f x :=
(h.hasFDerivAt.restrictScalars 𝕜).differentiableAt
#align differentiable_at.restrict_scalars DifferentiableAt.restrictScalars
@[fun_prop]
theorem DifferentiableWithinAt.restrictScalars (h : DifferentiableWithinAt 𝕜' f s x) :
DifferentiableWithinAt 𝕜 f s x :=
(h.hasFDerivWithinAt.restrictScalars 𝕜).differentiableWithinAt
#align differentiable_within_at.restrict_scalars DifferentiableWithinAt.restrictScalars
@[fun_prop]
theorem DifferentiableOn.restrictScalars (h : DifferentiableOn 𝕜' f s) : DifferentiableOn 𝕜 f s :=
fun x hx => (h x hx).restrictScalars 𝕜
#align differentiable_on.restrict_scalars DifferentiableOn.restrictScalars
@[fun_prop]
theorem Differentiable.restrictScalars (h : Differentiable 𝕜' f) : Differentiable 𝕜 f := fun x =>
(h x).restrictScalars 𝕜
#align differentiable.restrict_scalars Differentiable.restrictScalars
@[fun_prop]
theorem HasFDerivWithinAt.of_restrictScalars {g' : E →L[𝕜] F} (h : HasFDerivWithinAt f g' s x)
(H : f'.restrictScalars 𝕜 = g') : HasFDerivWithinAt f f' s x := by
rw [← H] at h
exact .of_isLittleO h.1
#align has_fderiv_within_at_of_restrict_scalars HasFDerivWithinAt.of_restrictScalars
@[fun_prop]
| Mathlib/Analysis/Calculus/FDeriv/RestrictScalars.lean | 99 | 102 | theorem hasFDerivAt_of_restrictScalars {g' : E →L[𝕜] F} (h : HasFDerivAt f g' x)
(H : f'.restrictScalars 𝕜 = g') : HasFDerivAt f f' x := by |
rw [← H] at h
exact .of_isLittleO h.1
|
/-
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, Eric Wieser
-/
import Mathlib.LinearAlgebra.TensorProduct.Tower
import Mathlib.Algebra.DirectSum.Module
#align_import linear_algebra.direct_sum.tensor_product from "leanprover-community/mathlib"@"9b9d125b7be0930f564a68f1d73ace10cf46064d"
/-!
# Tensor products of direct sums
This file shows that taking `TensorProduct`s commutes with taking `DirectSum`s in both arguments.
## Main results
* `TensorProduct.directSum`
* `TensorProduct.directSumLeft`
* `TensorProduct.directSumRight`
-/
suppress_compilation
universe u v₁ v₂ w₁ w₁' w₂ w₂'
section Ring
namespace TensorProduct
open TensorProduct
open DirectSum
open LinearMap
attribute [local ext] TensorProduct.ext
variable (R : Type u) [CommSemiring R] (S) [Semiring S] [Algebra R S]
variable {ι₁ : Type v₁} {ι₂ : Type v₂}
variable [DecidableEq ι₁] [DecidableEq ι₂]
variable (M₁ : ι₁ → Type w₁) (M₁' : Type w₁') (M₂ : ι₂ → Type w₂) (M₂' : Type w₂')
variable [∀ i₁, AddCommMonoid (M₁ i₁)] [AddCommMonoid M₁']
variable [∀ i₂, AddCommMonoid (M₂ i₂)] [AddCommMonoid M₂']
variable [∀ i₁, Module R (M₁ i₁)] [Module R M₁'] [∀ i₂, Module R (M₂ i₂)] [Module R M₂']
variable [∀ i₁, Module S (M₁ i₁)] [∀ i₁, IsScalarTower R S (M₁ i₁)]
/-- The linear equivalence `(⨁ i₁, M₁ i₁) ⊗ (⨁ i₂, M₂ i₂) ≃ (⨁ i₁, ⨁ i₂, M₁ i₁ ⊗ M₂ i₂)`, i.e.
"tensor product distributes over direct sum". -/
protected def directSum :
((⨁ i₁, M₁ i₁) ⊗[R] ⨁ i₂, M₂ i₂) ≃ₗ[S] ⨁ i : ι₁ × ι₂, M₁ i.1 ⊗[R] M₂ i.2 := by
-- Porting note: entirely rewritten to allow unification to happen one step at a time
refine LinearEquiv.ofLinear (R := S) (R₂ := S) ?toFun ?invFun ?left ?right
· refine AlgebraTensorModule.lift ?_
refine DirectSum.toModule S _ _ fun i₁ => ?_
refine LinearMap.flip ?_
refine DirectSum.toModule R _ _ fun i₂ => LinearMap.flip <| ?_
refine AlgebraTensorModule.curry ?_
exact DirectSum.lof S (ι₁ × ι₂) (fun i => M₁ i.1 ⊗[R] M₂ i.2) (i₁, i₂)
· refine DirectSum.toModule S _ _ fun i => ?_
exact AlgebraTensorModule.map (DirectSum.lof S _ M₁ i.1) (DirectSum.lof R _ M₂ i.2)
· refine DirectSum.linearMap_ext S fun ⟨i₁, i₂⟩ => ?_
refine TensorProduct.AlgebraTensorModule.ext fun m₁ m₂ => ?_
-- Porting note: seems much nicer than the `repeat` lean 3 proof.
simp only [coe_comp, Function.comp_apply, toModule_lof, AlgebraTensorModule.map_tmul,
AlgebraTensorModule.lift_apply, lift.tmul, coe_restrictScalars, flip_apply,
AlgebraTensorModule.curry_apply, curry_apply, id_comp]
· -- `(_)` prevents typeclass search timing out on problems that can be solved immediately by
-- unification
apply TensorProduct.AlgebraTensorModule.curry_injective
refine DirectSum.linearMap_ext _ fun i₁ => ?_
refine LinearMap.ext fun x₁ => ?_
refine DirectSum.linearMap_ext _ fun i₂ => ?_
refine LinearMap.ext fun x₂ => ?_
-- Porting note: seems much nicer than the `repeat` lean 3 proof.
simp only [coe_comp, Function.comp_apply, AlgebraTensorModule.curry_apply, curry_apply,
coe_restrictScalars, AlgebraTensorModule.lift_apply, lift.tmul, toModule_lof, flip_apply,
AlgebraTensorModule.map_tmul, id_coe, id_eq]
/- was:
refine'
LinearEquiv.ofLinear
(lift <|
DirectSum.toModule R _ _ fun i₁ => LinearMap.flip <| DirectSum.toModule R _ _ fun i₂ =>
LinearMap.flip <| curry <|
DirectSum.lof R (ι₁ × ι₂) (fun i => M₁ i.1 ⊗[R] M₂ i.2) (i₁, i₂))
(DirectSum.toModule R _ _ fun i => map (DirectSum.lof R _ _ _) (DirectSum.lof R _ _ _)) _
_ <;>
[ext ⟨i₁, i₂⟩ x₁ x₂ : 4, ext i₁ i₂ x₁ x₂ : 5]
repeat'
first
|rw [compr₂_apply]|rw [comp_apply]|rw [id_apply]|rw [mk_apply]|rw [DirectSum.toModule_lof]
|rw [map_tmul]|rw [lift.tmul]|rw [flip_apply]|rw [curry_apply]
-/
/- alternative with explicit types:
refine'
LinearEquiv.ofLinear
(lift <|
DirectSum.toModule
(R := R) (M := M₁) (N := (⨁ i₂, M₂ i₂) →ₗ[R] ⨁ i : ι₁ × ι₂, M₁ i.1 ⊗[R] M₂ i.2)
(φ := fun i₁ => LinearMap.flip <|
DirectSum.toModule (R := R) (M := M₂) (N := ⨁ i : ι₁ × ι₂, M₁ i.1 ⊗[R] M₂ i.2)
(φ := fun i₂ => LinearMap.flip <| curry <|
DirectSum.lof R (ι₁ × ι₂) (fun i => M₁ i.1 ⊗[R] M₂ i.2) (i₁, i₂))))
(DirectSum.toModule
(R := R)
(M := fun i : ι₁ × ι₂ => M₁ i.1 ⊗[R] M₂ i.2)
(N := (⨁ i₁, M₁ i₁) ⊗[R] ⨁ i₂, M₂ i₂)
(φ := fun i : ι₁ × ι₂ => map (DirectSum.lof R _ M₁ i.1) (DirectSum.lof R _ M₂ i.2))) _
_ <;>
[ext ⟨i₁, i₂⟩ x₁ x₂ : 4, ext i₁ i₂ x₁ x₂ : 5]
repeat'
first
|rw [compr₂_apply]|rw [comp_apply]|rw [id_apply]|rw [mk_apply]|rw [DirectSum.toModule_lof]
|rw [map_tmul]|rw [lift.tmul]|rw [flip_apply]|rw [curry_apply]
-/
#align tensor_product.direct_sum TensorProduct.directSum
/-- Tensor products distribute over a direct sum on the left . -/
def directSumLeft : (⨁ i₁, M₁ i₁) ⊗[R] M₂' ≃ₗ[R] ⨁ i, M₁ i ⊗[R] M₂' :=
LinearEquiv.ofLinear
(lift <|
DirectSum.toModule R _ _ fun i =>
(mk R _ _).compr₂ <| DirectSum.lof R ι₁ (fun i => M₁ i ⊗[R] M₂') _)
(DirectSum.toModule R _ _ fun i => rTensor _ (DirectSum.lof R ι₁ _ _))
(DirectSum.linearMap_ext R fun i =>
TensorProduct.ext <|
LinearMap.ext₂ fun m₁ m₂ => by
dsimp only [comp_apply, compr₂_apply, id_apply, mk_apply]
simp_rw [DirectSum.toModule_lof, rTensor_tmul, lift.tmul, DirectSum.toModule_lof,
compr₂_apply, mk_apply])
(TensorProduct.ext <|
DirectSum.linearMap_ext R fun i =>
LinearMap.ext₂ fun m₁ m₂ => by
dsimp only [comp_apply, compr₂_apply, id_apply, mk_apply]
simp_rw [lift.tmul, DirectSum.toModule_lof, compr₂_apply,
mk_apply, DirectSum.toModule_lof, rTensor_tmul])
#align tensor_product.direct_sum_left TensorProduct.directSumLeft
/-- Tensor products distribute over a direct sum on the right. -/
def directSumRight : (M₁' ⊗[R] ⨁ i, M₂ i) ≃ₗ[R] ⨁ i, M₁' ⊗[R] M₂ i :=
TensorProduct.comm R _ _ ≪≫ₗ directSumLeft R M₂ M₁' ≪≫ₗ
DFinsupp.mapRange.linearEquiv fun _ => TensorProduct.comm R _ _
#align tensor_product.direct_sum_right TensorProduct.directSumRight
variable {M₁ M₁' M₂ M₂'}
@[simp]
| Mathlib/LinearAlgebra/DirectSum/TensorProduct.lean | 150 | 153 | theorem directSum_lof_tmul_lof (i₁ : ι₁) (m₁ : M₁ i₁) (i₂ : ι₂) (m₂ : M₂ i₂) :
TensorProduct.directSum R S M₁ M₂ (DirectSum.lof S ι₁ M₁ i₁ m₁ ⊗ₜ DirectSum.lof R ι₂ M₂ i₂ m₂) =
DirectSum.lof S (ι₁ × ι₂) (fun i => M₁ i.1 ⊗[R] M₂ i.2) (i₁, i₂) (m₁ ⊗ₜ m₂) := by |
simp [TensorProduct.directSum]
|
/-
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.Degree.Definitions
import Mathlib.Algebra.Polynomial.Induction
#align_import data.polynomial.eval from "leanprover-community/mathlib"@"728baa2f54e6062c5879a3e397ac6bac323e506f"
/-!
# Theory of univariate polynomials
The main defs here are `eval₂`, `eval`, and `map`.
We give several lemmas about their interaction with each other and with module operations.
-/
set_option linter.uppercaseLean3 false
noncomputable section
open Finset AddMonoidAlgebra
open Polynomial
namespace Polynomial
universe u v w y
variable {R : Type u} {S : Type v} {T : Type w} {ι : Type y} {a b : R} {m n : ℕ}
section Semiring
variable [Semiring R] {p q r : R[X]}
section
variable [Semiring S]
variable (f : R →+* S) (x : S)
/-- Evaluate a polynomial `p` given a ring hom `f` from the scalar ring
to the target and a value `x` for the variable in the target -/
irreducible_def eval₂ (p : R[X]) : S :=
p.sum fun e a => f a * x ^ e
#align polynomial.eval₂ Polynomial.eval₂
theorem eval₂_eq_sum {f : R →+* S} {x : S} : p.eval₂ f x = p.sum fun e a => f a * x ^ e := by
rw [eval₂_def]
#align polynomial.eval₂_eq_sum Polynomial.eval₂_eq_sum
theorem eval₂_congr {R S : Type*} [Semiring R] [Semiring S] {f g : R →+* S} {s t : S}
{φ ψ : R[X]} : f = g → s = t → φ = ψ → eval₂ f s φ = eval₂ g t ψ := by
rintro rfl rfl rfl; rfl
#align polynomial.eval₂_congr Polynomial.eval₂_congr
@[simp]
theorem eval₂_at_zero : p.eval₂ f 0 = f (coeff p 0) := by
simp (config := { contextual := true }) only [eval₂_eq_sum, zero_pow_eq, mul_ite, mul_zero,
mul_one, sum, Classical.not_not, mem_support_iff, sum_ite_eq', ite_eq_left_iff,
RingHom.map_zero, imp_true_iff, eq_self_iff_true]
#align polynomial.eval₂_at_zero Polynomial.eval₂_at_zero
@[simp]
theorem eval₂_zero : (0 : R[X]).eval₂ f x = 0 := by simp [eval₂_eq_sum]
#align polynomial.eval₂_zero Polynomial.eval₂_zero
@[simp]
theorem eval₂_C : (C a).eval₂ f x = f a := by simp [eval₂_eq_sum]
#align polynomial.eval₂_C Polynomial.eval₂_C
@[simp]
theorem eval₂_X : X.eval₂ f x = x := by simp [eval₂_eq_sum]
#align polynomial.eval₂_X Polynomial.eval₂_X
@[simp]
theorem eval₂_monomial {n : ℕ} {r : R} : (monomial n r).eval₂ f x = f r * x ^ n := by
simp [eval₂_eq_sum]
#align polynomial.eval₂_monomial Polynomial.eval₂_monomial
@[simp]
theorem eval₂_X_pow {n : ℕ} : (X ^ n).eval₂ f x = x ^ n := by
rw [X_pow_eq_monomial]
convert eval₂_monomial f x (n := n) (r := 1)
simp
#align polynomial.eval₂_X_pow Polynomial.eval₂_X_pow
@[simp]
theorem eval₂_add : (p + q).eval₂ f x = p.eval₂ f x + q.eval₂ f x := by
simp only [eval₂_eq_sum]
apply sum_add_index <;> simp [add_mul]
#align polynomial.eval₂_add Polynomial.eval₂_add
@[simp]
theorem eval₂_one : (1 : R[X]).eval₂ f x = 1 := by rw [← C_1, eval₂_C, f.map_one]
#align polynomial.eval₂_one Polynomial.eval₂_one
set_option linter.deprecated false in
@[simp]
theorem eval₂_bit0 : (bit0 p).eval₂ f x = bit0 (p.eval₂ f x) := by rw [bit0, eval₂_add, bit0]
#align polynomial.eval₂_bit0 Polynomial.eval₂_bit0
set_option linter.deprecated false in
@[simp]
theorem eval₂_bit1 : (bit1 p).eval₂ f x = bit1 (p.eval₂ f x) := by
rw [bit1, eval₂_add, eval₂_bit0, eval₂_one, bit1]
#align polynomial.eval₂_bit1 Polynomial.eval₂_bit1
@[simp]
theorem eval₂_smul (g : R →+* S) (p : R[X]) (x : S) {s : R} :
eval₂ g x (s • p) = g s * eval₂ g x p := by
have A : p.natDegree < p.natDegree.succ := Nat.lt_succ_self _
have B : (s • p).natDegree < p.natDegree.succ := (natDegree_smul_le _ _).trans_lt A
rw [eval₂_eq_sum, eval₂_eq_sum, sum_over_range' _ _ _ A, sum_over_range' _ _ _ B] <;>
simp [mul_sum, mul_assoc]
#align polynomial.eval₂_smul Polynomial.eval₂_smul
@[simp]
theorem eval₂_C_X : eval₂ C X p = p :=
Polynomial.induction_on' p (fun p q hp hq => by simp [hp, hq]) fun n x => by
rw [eval₂_monomial, ← smul_X_eq_monomial, C_mul']
#align polynomial.eval₂_C_X Polynomial.eval₂_C_X
/-- `eval₂AddMonoidHom (f : R →+* S) (x : S)` is the `AddMonoidHom` from
`R[X]` to `S` obtained by evaluating the pushforward of `p` along `f` at `x`. -/
@[simps]
def eval₂AddMonoidHom : R[X] →+ S where
toFun := eval₂ f x
map_zero' := eval₂_zero _ _
map_add' _ _ := eval₂_add _ _
#align polynomial.eval₂_add_monoid_hom Polynomial.eval₂AddMonoidHom
#align polynomial.eval₂_add_monoid_hom_apply Polynomial.eval₂AddMonoidHom_apply
@[simp]
theorem eval₂_natCast (n : ℕ) : (n : R[X]).eval₂ f x = n := by
induction' n with n ih
-- Porting note: `Nat.zero_eq` is required.
· simp only [eval₂_zero, Nat.cast_zero, Nat.zero_eq]
· rw [n.cast_succ, eval₂_add, ih, eval₂_one, n.cast_succ]
#align polynomial.eval₂_nat_cast Polynomial.eval₂_natCast
@[deprecated (since := "2024-04-17")]
alias eval₂_nat_cast := eval₂_natCast
-- See note [no_index around OfNat.ofNat]
@[simp]
lemma eval₂_ofNat {S : Type*} [Semiring S] (n : ℕ) [n.AtLeastTwo] (f : R →+* S) (a : S) :
(no_index (OfNat.ofNat n : R[X])).eval₂ f a = OfNat.ofNat n := by
simp [OfNat.ofNat]
variable [Semiring T]
theorem eval₂_sum (p : T[X]) (g : ℕ → T → R[X]) (x : S) :
(p.sum g).eval₂ f x = p.sum fun n a => (g n a).eval₂ f x := by
let T : R[X] →+ S :=
{ toFun := eval₂ f x
map_zero' := eval₂_zero _ _
map_add' := fun p q => eval₂_add _ _ }
have A : ∀ y, eval₂ f x y = T y := fun y => rfl
simp only [A]
rw [sum, map_sum, sum]
#align polynomial.eval₂_sum Polynomial.eval₂_sum
theorem eval₂_list_sum (l : List R[X]) (x : S) : eval₂ f x l.sum = (l.map (eval₂ f x)).sum :=
map_list_sum (eval₂AddMonoidHom f x) l
#align polynomial.eval₂_list_sum Polynomial.eval₂_list_sum
theorem eval₂_multiset_sum (s : Multiset R[X]) (x : S) :
eval₂ f x s.sum = (s.map (eval₂ f x)).sum :=
map_multiset_sum (eval₂AddMonoidHom f x) s
#align polynomial.eval₂_multiset_sum Polynomial.eval₂_multiset_sum
theorem eval₂_finset_sum (s : Finset ι) (g : ι → R[X]) (x : S) :
(∑ i ∈ s, g i).eval₂ f x = ∑ i ∈ s, (g i).eval₂ f x :=
map_sum (eval₂AddMonoidHom f x) _ _
#align polynomial.eval₂_finset_sum Polynomial.eval₂_finset_sum
theorem eval₂_ofFinsupp {f : R →+* S} {x : S} {p : R[ℕ]} :
eval₂ f x (⟨p⟩ : R[X]) = liftNC (↑f) (powersHom S x) p := by
simp only [eval₂_eq_sum, sum, toFinsupp_sum, support, coeff]
rfl
#align polynomial.eval₂_of_finsupp Polynomial.eval₂_ofFinsupp
theorem eval₂_mul_noncomm (hf : ∀ k, Commute (f <| q.coeff k) x) :
eval₂ f x (p * q) = eval₂ f x p * eval₂ f x q := by
rcases p with ⟨p⟩; rcases q with ⟨q⟩
simp only [coeff] at hf
simp only [← ofFinsupp_mul, eval₂_ofFinsupp]
exact liftNC_mul _ _ p q fun {k n} _hn => (hf k).pow_right n
#align polynomial.eval₂_mul_noncomm Polynomial.eval₂_mul_noncomm
@[simp]
theorem eval₂_mul_X : eval₂ f x (p * X) = eval₂ f x p * x := by
refine _root_.trans (eval₂_mul_noncomm _ _ fun k => ?_) (by rw [eval₂_X])
rcases em (k = 1) with (rfl | hk)
· simp
· simp [coeff_X_of_ne_one hk]
#align polynomial.eval₂_mul_X Polynomial.eval₂_mul_X
@[simp]
theorem eval₂_X_mul : eval₂ f x (X * p) = eval₂ f x p * x := by rw [X_mul, eval₂_mul_X]
#align polynomial.eval₂_X_mul Polynomial.eval₂_X_mul
theorem eval₂_mul_C' (h : Commute (f a) x) : eval₂ f x (p * C a) = eval₂ f x p * f a := by
rw [eval₂_mul_noncomm, eval₂_C]
intro k
by_cases hk : k = 0
· simp only [hk, h, coeff_C_zero, coeff_C_ne_zero]
· simp only [coeff_C_ne_zero hk, RingHom.map_zero, Commute.zero_left]
#align polynomial.eval₂_mul_C' Polynomial.eval₂_mul_C'
theorem eval₂_list_prod_noncomm (ps : List R[X])
(hf : ∀ p ∈ ps, ∀ (k), Commute (f <| coeff p k) x) :
eval₂ f x ps.prod = (ps.map (Polynomial.eval₂ f x)).prod := by
induction' ps using List.reverseRecOn with ps p ihp
· simp
· simp only [List.forall_mem_append, List.forall_mem_singleton] at hf
simp [eval₂_mul_noncomm _ _ hf.2, ihp hf.1]
#align polynomial.eval₂_list_prod_noncomm Polynomial.eval₂_list_prod_noncomm
/-- `eval₂` as a `RingHom` for noncommutative rings -/
@[simps]
def eval₂RingHom' (f : R →+* S) (x : S) (hf : ∀ a, Commute (f a) x) : R[X] →+* S where
toFun := eval₂ f x
map_add' _ _ := eval₂_add _ _
map_zero' := eval₂_zero _ _
map_mul' _p q := eval₂_mul_noncomm f x fun k => hf <| coeff q k
map_one' := eval₂_one _ _
#align polynomial.eval₂_ring_hom' Polynomial.eval₂RingHom'
end
/-!
We next prove that eval₂ is multiplicative
as long as target ring is commutative
(even if the source ring is not).
-/
section Eval₂
section
variable [Semiring S] (f : R →+* S) (x : S)
theorem eval₂_eq_sum_range :
p.eval₂ f x = ∑ i ∈ Finset.range (p.natDegree + 1), f (p.coeff i) * x ^ i :=
_root_.trans (congr_arg _ p.as_sum_range)
(_root_.trans (eval₂_finset_sum f _ _ x) (congr_arg _ (by simp)))
#align polynomial.eval₂_eq_sum_range Polynomial.eval₂_eq_sum_range
theorem eval₂_eq_sum_range' (f : R →+* S) {p : R[X]} {n : ℕ} (hn : p.natDegree < n) (x : S) :
eval₂ f x p = ∑ i ∈ Finset.range n, f (p.coeff i) * x ^ i := by
rw [eval₂_eq_sum, p.sum_over_range' _ _ hn]
intro i
rw [f.map_zero, zero_mul]
#align polynomial.eval₂_eq_sum_range' Polynomial.eval₂_eq_sum_range'
end
section
variable [CommSemiring S] (f : R →+* S) (x : S)
@[simp]
theorem eval₂_mul : (p * q).eval₂ f x = p.eval₂ f x * q.eval₂ f x :=
eval₂_mul_noncomm _ _ fun _k => Commute.all _ _
#align polynomial.eval₂_mul Polynomial.eval₂_mul
theorem eval₂_mul_eq_zero_of_left (q : R[X]) (hp : p.eval₂ f x = 0) : (p * q).eval₂ f x = 0 := by
rw [eval₂_mul f x]
exact mul_eq_zero_of_left hp (q.eval₂ f x)
#align polynomial.eval₂_mul_eq_zero_of_left Polynomial.eval₂_mul_eq_zero_of_left
theorem eval₂_mul_eq_zero_of_right (p : R[X]) (hq : q.eval₂ f x = 0) : (p * q).eval₂ f x = 0 := by
rw [eval₂_mul f x]
exact mul_eq_zero_of_right (p.eval₂ f x) hq
#align polynomial.eval₂_mul_eq_zero_of_right Polynomial.eval₂_mul_eq_zero_of_right
/-- `eval₂` as a `RingHom` -/
def eval₂RingHom (f : R →+* S) (x : S) : R[X] →+* S :=
{ eval₂AddMonoidHom f x with
map_one' := eval₂_one _ _
map_mul' := fun _ _ => eval₂_mul _ _ }
#align polynomial.eval₂_ring_hom Polynomial.eval₂RingHom
@[simp]
theorem coe_eval₂RingHom (f : R →+* S) (x) : ⇑(eval₂RingHom f x) = eval₂ f x :=
rfl
#align polynomial.coe_eval₂_ring_hom Polynomial.coe_eval₂RingHom
theorem eval₂_pow (n : ℕ) : (p ^ n).eval₂ f x = p.eval₂ f x ^ n :=
(eval₂RingHom _ _).map_pow _ _
#align polynomial.eval₂_pow Polynomial.eval₂_pow
theorem eval₂_dvd : p ∣ q → eval₂ f x p ∣ eval₂ f x q :=
(eval₂RingHom f x).map_dvd
#align polynomial.eval₂_dvd Polynomial.eval₂_dvd
theorem eval₂_eq_zero_of_dvd_of_eval₂_eq_zero (h : p ∣ q) (h0 : eval₂ f x p = 0) :
eval₂ f x q = 0 :=
zero_dvd_iff.mp (h0 ▸ eval₂_dvd f x h)
#align polynomial.eval₂_eq_zero_of_dvd_of_eval₂_eq_zero Polynomial.eval₂_eq_zero_of_dvd_of_eval₂_eq_zero
theorem eval₂_list_prod (l : List R[X]) (x : S) : eval₂ f x l.prod = (l.map (eval₂ f x)).prod :=
map_list_prod (eval₂RingHom f x) l
#align polynomial.eval₂_list_prod Polynomial.eval₂_list_prod
end
end Eval₂
section Eval
variable {x : R}
/-- `eval x p` is the evaluation of the polynomial `p` at `x` -/
def eval : R → R[X] → R :=
eval₂ (RingHom.id _)
#align polynomial.eval Polynomial.eval
theorem eval_eq_sum : p.eval x = p.sum fun e a => a * x ^ e := by
rw [eval, eval₂_eq_sum]
rfl
#align polynomial.eval_eq_sum Polynomial.eval_eq_sum
theorem eval_eq_sum_range {p : R[X]} (x : R) :
p.eval x = ∑ i ∈ Finset.range (p.natDegree + 1), p.coeff i * x ^ i := by
rw [eval_eq_sum, sum_over_range]; simp
#align polynomial.eval_eq_sum_range Polynomial.eval_eq_sum_range
theorem eval_eq_sum_range' {p : R[X]} {n : ℕ} (hn : p.natDegree < n) (x : R) :
p.eval x = ∑ i ∈ Finset.range n, p.coeff i * x ^ i := by
rw [eval_eq_sum, p.sum_over_range' _ _ hn]; simp
#align polynomial.eval_eq_sum_range' Polynomial.eval_eq_sum_range'
@[simp]
theorem eval₂_at_apply {S : Type*} [Semiring S] (f : R →+* S) (r : R) :
p.eval₂ f (f r) = f (p.eval r) := by
rw [eval₂_eq_sum, eval_eq_sum, sum, sum, map_sum f]
simp only [f.map_mul, f.map_pow]
#align polynomial.eval₂_at_apply Polynomial.eval₂_at_apply
@[simp]
theorem eval₂_at_one {S : Type*} [Semiring S] (f : R →+* S) : p.eval₂ f 1 = f (p.eval 1) := by
convert eval₂_at_apply (p := p) f 1
simp
#align polynomial.eval₂_at_one Polynomial.eval₂_at_one
@[simp]
theorem eval₂_at_natCast {S : Type*} [Semiring S] (f : R →+* S) (n : ℕ) :
p.eval₂ f n = f (p.eval n) := by
convert eval₂_at_apply (p := p) f n
simp
#align polynomial.eval₂_at_nat_cast Polynomial.eval₂_at_natCast
@[deprecated (since := "2024-04-17")]
alias eval₂_at_nat_cast := eval₂_at_natCast
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem eval₂_at_ofNat {S : Type*} [Semiring S] (f : R →+* S) (n : ℕ) [n.AtLeastTwo] :
p.eval₂ f (no_index (OfNat.ofNat n)) = f (p.eval (OfNat.ofNat n)) := by
simp [OfNat.ofNat]
@[simp]
theorem eval_C : (C a).eval x = a :=
eval₂_C _ _
#align polynomial.eval_C Polynomial.eval_C
@[simp]
theorem eval_natCast {n : ℕ} : (n : R[X]).eval x = n := by simp only [← C_eq_natCast, eval_C]
#align polynomial.eval_nat_cast Polynomial.eval_natCast
@[deprecated (since := "2024-04-17")]
alias eval_nat_cast := eval_natCast
-- See note [no_index around OfNat.ofNat]
@[simp]
lemma eval_ofNat (n : ℕ) [n.AtLeastTwo] (a : R) :
(no_index (OfNat.ofNat n : R[X])).eval a = OfNat.ofNat n := by
simp only [OfNat.ofNat, eval_natCast]
@[simp]
theorem eval_X : X.eval x = x :=
eval₂_X _ _
#align polynomial.eval_X Polynomial.eval_X
@[simp]
theorem eval_monomial {n a} : (monomial n a).eval x = a * x ^ n :=
eval₂_monomial _ _
#align polynomial.eval_monomial Polynomial.eval_monomial
@[simp]
theorem eval_zero : (0 : R[X]).eval x = 0 :=
eval₂_zero _ _
#align polynomial.eval_zero Polynomial.eval_zero
@[simp]
theorem eval_add : (p + q).eval x = p.eval x + q.eval x :=
eval₂_add _ _
#align polynomial.eval_add Polynomial.eval_add
@[simp]
theorem eval_one : (1 : R[X]).eval x = 1 :=
eval₂_one _ _
#align polynomial.eval_one Polynomial.eval_one
set_option linter.deprecated false in
@[simp]
theorem eval_bit0 : (bit0 p).eval x = bit0 (p.eval x) :=
eval₂_bit0 _ _
#align polynomial.eval_bit0 Polynomial.eval_bit0
set_option linter.deprecated false in
@[simp]
theorem eval_bit1 : (bit1 p).eval x = bit1 (p.eval x) :=
eval₂_bit1 _ _
#align polynomial.eval_bit1 Polynomial.eval_bit1
@[simp]
theorem eval_smul [Monoid S] [DistribMulAction S R] [IsScalarTower S R R] (s : S) (p : R[X])
(x : R) : (s • p).eval x = s • p.eval x := by
rw [← smul_one_smul R s p, eval, eval₂_smul, RingHom.id_apply, smul_one_mul]
#align polynomial.eval_smul Polynomial.eval_smul
@[simp]
theorem eval_C_mul : (C a * p).eval x = a * p.eval x := by
induction p using Polynomial.induction_on' with
| h_add p q ph qh =>
simp only [mul_add, eval_add, ph, qh]
| h_monomial n b =>
simp only [mul_assoc, C_mul_monomial, eval_monomial]
#align polynomial.eval_C_mul Polynomial.eval_C_mul
/-- A reformulation of the expansion of (1 + y)^d:
$$(d + 1) (1 + y)^d - (d + 1)y^d = \sum_{i = 0}^d {d + 1 \choose i} \cdot i \cdot y^{i - 1}.$$
-/
theorem eval_monomial_one_add_sub [CommRing S] (d : ℕ) (y : S) :
eval (1 + y) (monomial d (d + 1 : S)) - eval y (monomial d (d + 1 : S)) =
∑ x_1 ∈ range (d + 1), ↑((d + 1).choose x_1) * (↑x_1 * y ^ (x_1 - 1)) := by
have cast_succ : (d + 1 : S) = ((d.succ : ℕ) : S) := by simp only [Nat.cast_succ]
rw [cast_succ, eval_monomial, eval_monomial, add_comm, add_pow]
-- Porting note: `apply_congr` hadn't been ported yet, so `congr` & `ext` is used.
conv_lhs =>
congr
· congr
· skip
· congr
· skip
· ext
rw [one_pow, mul_one, mul_comm]
rw [sum_range_succ, mul_add, Nat.choose_self, Nat.cast_one, one_mul, add_sub_cancel_right,
mul_sum, sum_range_succ', Nat.cast_zero, zero_mul, mul_zero, add_zero]
refine sum_congr rfl fun y _hy => ?_
rw [← mul_assoc, ← mul_assoc, ← Nat.cast_mul, Nat.succ_mul_choose_eq, Nat.cast_mul,
Nat.add_sub_cancel]
#align polynomial.eval_monomial_one_add_sub Polynomial.eval_monomial_one_add_sub
/-- `Polynomial.eval` as linear map -/
@[simps]
def leval {R : Type*} [Semiring R] (r : R) : R[X] →ₗ[R] R where
toFun f := f.eval r
map_add' _f _g := eval_add
map_smul' c f := eval_smul c f r
#align polynomial.leval Polynomial.leval
#align polynomial.leval_apply Polynomial.leval_apply
@[simp]
theorem eval_natCast_mul {n : ℕ} : ((n : R[X]) * p).eval x = n * p.eval x := by
rw [← C_eq_natCast, eval_C_mul]
#align polynomial.eval_nat_cast_mul Polynomial.eval_natCast_mul
@[deprecated (since := "2024-04-17")]
alias eval_nat_cast_mul := eval_natCast_mul
@[simp]
| Mathlib/Algebra/Polynomial/Eval.lean | 478 | 484 | theorem eval_mul_X : (p * X).eval x = p.eval x * x := by |
induction p using Polynomial.induction_on' with
| h_add p q ph qh =>
simp only [add_mul, eval_add, ph, qh]
| h_monomial n a =>
simp only [← monomial_one_one_eq_X, monomial_mul_monomial, eval_monomial, mul_one, pow_succ,
mul_assoc]
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Kevin Buzzard, Yury Kudryashov, Frédéric Dupuis,
Heather Macbeth
-/
import Mathlib.Algebra.Module.Submodule.EqLocus
import Mathlib.Algebra.Module.Submodule.RestrictScalars
import Mathlib.Algebra.Ring.Idempotents
import Mathlib.Data.Set.Pointwise.SMul
import Mathlib.LinearAlgebra.Basic
import Mathlib.Order.CompactlyGenerated.Basic
import Mathlib.Order.OmegaCompletePartialOrder
#align_import linear_algebra.span from "leanprover-community/mathlib"@"10878f6bf1dab863445907ab23fbfcefcb5845d0"
/-!
# The span of a set of vectors, as a submodule
* `Submodule.span s` is defined to be the smallest submodule containing the set `s`.
## Notations
* We introduce the notation `R ∙ v` for the span of a singleton, `Submodule.span R {v}`. This is
`\span`, not the same as the scalar multiplication `•`/`\bub`.
-/
variable {R R₂ K M M₂ V S : Type*}
namespace Submodule
open Function Set
open Pointwise
section AddCommMonoid
variable [Semiring R] [AddCommMonoid M] [Module R M]
variable {x : M} (p p' : Submodule R M)
variable [Semiring R₂] {σ₁₂ : R →+* R₂}
variable [AddCommMonoid M₂] [Module R₂ M₂]
variable {F : Type*} [FunLike F M M₂] [SemilinearMapClass F σ₁₂ M M₂]
section
variable (R)
/-- The span of a set `s ⊆ M` is the smallest submodule of M that contains `s`. -/
def span (s : Set M) : Submodule R M :=
sInf { p | s ⊆ p }
#align submodule.span Submodule.span
variable {R}
-- Porting note: renamed field to `principal'` and added `principal` to fix explicit argument
/-- An `R`-submodule of `M` is principal if it is generated by one element. -/
@[mk_iff]
class IsPrincipal (S : Submodule R M) : Prop where
principal' : ∃ a, S = span R {a}
#align submodule.is_principal Submodule.IsPrincipal
theorem IsPrincipal.principal (S : Submodule R M) [S.IsPrincipal] :
∃ a, S = span R {a} :=
Submodule.IsPrincipal.principal'
#align submodule.is_principal.principal Submodule.IsPrincipal.principal
end
variable {s t : Set M}
theorem mem_span : x ∈ span R s ↔ ∀ p : Submodule R M, s ⊆ p → x ∈ p :=
mem_iInter₂
#align submodule.mem_span Submodule.mem_span
@[aesop safe 20 apply (rule_sets := [SetLike])]
theorem subset_span : s ⊆ span R s := fun _ h => mem_span.2 fun _ hp => hp h
#align submodule.subset_span Submodule.subset_span
theorem span_le {p} : span R s ≤ p ↔ s ⊆ p :=
⟨Subset.trans subset_span, fun ss _ h => mem_span.1 h _ ss⟩
#align submodule.span_le Submodule.span_le
theorem span_mono (h : s ⊆ t) : span R s ≤ span R t :=
span_le.2 <| Subset.trans h subset_span
#align submodule.span_mono Submodule.span_mono
theorem span_monotone : Monotone (span R : Set M → Submodule R M) := fun _ _ => span_mono
#align submodule.span_monotone Submodule.span_monotone
theorem span_eq_of_le (h₁ : s ⊆ p) (h₂ : p ≤ span R s) : span R s = p :=
le_antisymm (span_le.2 h₁) h₂
#align submodule.span_eq_of_le Submodule.span_eq_of_le
theorem span_eq : span R (p : Set M) = p :=
span_eq_of_le _ (Subset.refl _) subset_span
#align submodule.span_eq Submodule.span_eq
theorem span_eq_span (hs : s ⊆ span R t) (ht : t ⊆ span R s) : span R s = span R t :=
le_antisymm (span_le.2 hs) (span_le.2 ht)
#align submodule.span_eq_span Submodule.span_eq_span
/-- A version of `Submodule.span_eq` for subobjects closed under addition and scalar multiplication
and containing zero. In general, this should not be used directly, but can be used to quickly
generate proofs for specific types of subobjects. -/
lemma coe_span_eq_self [SetLike S M] [AddSubmonoidClass S M] [SMulMemClass S R M] (s : S) :
(span R (s : Set M) : Set M) = s := by
refine le_antisymm ?_ subset_span
let s' : Submodule R M :=
{ carrier := s
add_mem' := add_mem
zero_mem' := zero_mem _
smul_mem' := SMulMemClass.smul_mem }
exact span_le (p := s') |>.mpr le_rfl
/-- A version of `Submodule.span_eq` for when the span is by a smaller ring. -/
@[simp]
theorem span_coe_eq_restrictScalars [Semiring S] [SMul S R] [Module S M] [IsScalarTower S R M] :
span S (p : Set M) = p.restrictScalars S :=
span_eq (p.restrictScalars S)
#align submodule.span_coe_eq_restrict_scalars Submodule.span_coe_eq_restrictScalars
/-- A version of `Submodule.map_span_le` that does not require the `RingHomSurjective`
assumption. -/
theorem image_span_subset (f : F) (s : Set M) (N : Submodule R₂ M₂) :
f '' span R s ⊆ N ↔ ∀ m ∈ s, f m ∈ N := image_subset_iff.trans <| span_le (p := N.comap f)
theorem image_span_subset_span (f : F) (s : Set M) : f '' span R s ⊆ span R₂ (f '' s) :=
(image_span_subset f s _).2 fun x hx ↦ subset_span ⟨x, hx, rfl⟩
theorem map_span [RingHomSurjective σ₁₂] (f : F) (s : Set M) :
(span R s).map f = span R₂ (f '' s) :=
Eq.symm <| span_eq_of_le _ (Set.image_subset f subset_span) (image_span_subset_span f s)
#align submodule.map_span Submodule.map_span
alias _root_.LinearMap.map_span := Submodule.map_span
#align linear_map.map_span LinearMap.map_span
theorem map_span_le [RingHomSurjective σ₁₂] (f : F) (s : Set M) (N : Submodule R₂ M₂) :
map f (span R s) ≤ N ↔ ∀ m ∈ s, f m ∈ N := image_span_subset f s N
#align submodule.map_span_le Submodule.map_span_le
alias _root_.LinearMap.map_span_le := Submodule.map_span_le
#align linear_map.map_span_le LinearMap.map_span_le
@[simp]
theorem span_insert_zero : span R (insert (0 : M) s) = span R s := by
refine le_antisymm ?_ (Submodule.span_mono (Set.subset_insert 0 s))
rw [span_le, Set.insert_subset_iff]
exact ⟨by simp only [SetLike.mem_coe, Submodule.zero_mem], Submodule.subset_span⟩
#align submodule.span_insert_zero Submodule.span_insert_zero
-- See also `span_preimage_eq` below.
theorem span_preimage_le (f : F) (s : Set M₂) :
span R (f ⁻¹' s) ≤ (span R₂ s).comap f := by
rw [span_le, comap_coe]
exact preimage_mono subset_span
#align submodule.span_preimage_le Submodule.span_preimage_le
alias _root_.LinearMap.span_preimage_le := Submodule.span_preimage_le
#align linear_map.span_preimage_le LinearMap.span_preimage_le
theorem closure_subset_span {s : Set M} : (AddSubmonoid.closure s : Set M) ⊆ span R s :=
(@AddSubmonoid.closure_le _ _ _ (span R s).toAddSubmonoid).mpr subset_span
#align submodule.closure_subset_span Submodule.closure_subset_span
theorem closure_le_toAddSubmonoid_span {s : Set M} :
AddSubmonoid.closure s ≤ (span R s).toAddSubmonoid :=
closure_subset_span
#align submodule.closure_le_to_add_submonoid_span Submodule.closure_le_toAddSubmonoid_span
@[simp]
theorem span_closure {s : Set M} : span R (AddSubmonoid.closure s : Set M) = span R s :=
le_antisymm (span_le.mpr closure_subset_span) (span_mono AddSubmonoid.subset_closure)
#align submodule.span_closure Submodule.span_closure
/-- An induction principle for span membership. If `p` holds for 0 and all elements of `s`, and is
preserved under addition and scalar multiplication, then `p` holds for all elements of the span of
`s`. -/
@[elab_as_elim]
theorem span_induction {p : M → Prop} (h : x ∈ span R s) (mem : ∀ x ∈ s, p x) (zero : p 0)
(add : ∀ x y, p x → p y → p (x + y)) (smul : ∀ (a : R) (x), p x → p (a • x)) : p x :=
((@span_le (p := ⟨⟨⟨p, by intros x y; exact add x y⟩, zero⟩, smul⟩)) s).2 mem h
#align submodule.span_induction Submodule.span_induction
/-- An induction principle for span membership. This is a version of `Submodule.span_induction`
for binary predicates. -/
theorem span_induction₂ {p : M → M → Prop} {a b : M} (ha : a ∈ Submodule.span R s)
(hb : b ∈ Submodule.span R s) (mem_mem : ∀ x ∈ s, ∀ y ∈ s, p x y)
(zero_left : ∀ y, p 0 y) (zero_right : ∀ x, p x 0)
(add_left : ∀ x₁ x₂ y, p x₁ y → p x₂ y → p (x₁ + x₂) y)
(add_right : ∀ x y₁ y₂, p x y₁ → p x y₂ → p x (y₁ + y₂))
(smul_left : ∀ (r : R) x y, p x y → p (r • x) y)
(smul_right : ∀ (r : R) x y, p x y → p x (r • y)) : p a b :=
Submodule.span_induction ha
(fun x hx => Submodule.span_induction hb (mem_mem x hx) (zero_right x) (add_right x) fun r =>
smul_right r x)
(zero_left b) (fun x₁ x₂ => add_left x₁ x₂ b) fun r x => smul_left r x b
/-- A dependent version of `Submodule.span_induction`. -/
@[elab_as_elim]
theorem span_induction' {p : ∀ x, x ∈ span R s → Prop}
(mem : ∀ (x) (h : x ∈ s), p x (subset_span h))
(zero : p 0 (Submodule.zero_mem _))
(add : ∀ x hx y hy, p x hx → p y hy → p (x + y) (Submodule.add_mem _ ‹_› ‹_›))
(smul : ∀ (a : R) (x hx), p x hx → p (a • x) (Submodule.smul_mem _ _ ‹_›)) {x}
(hx : x ∈ span R s) : p x hx := by
refine Exists.elim ?_ fun (hx : x ∈ span R s) (hc : p x hx) => hc
refine
span_induction hx (fun m hm => ⟨subset_span hm, mem m hm⟩) ⟨zero_mem _, zero⟩
(fun x y hx hy =>
Exists.elim hx fun hx' hx =>
Exists.elim hy fun hy' hy => ⟨add_mem hx' hy', add _ _ _ _ hx hy⟩)
fun r x hx => Exists.elim hx fun hx' hx => ⟨smul_mem _ _ hx', smul r _ _ hx⟩
#align submodule.span_induction' Submodule.span_induction'
open AddSubmonoid in
theorem span_eq_closure {s : Set M} : (span R s).toAddSubmonoid = closure (@univ R • s) := by
refine le_antisymm
(fun x hx ↦ span_induction hx (fun x hx ↦ subset_closure ⟨1, trivial, x, hx, one_smul R x⟩)
(zero_mem _) (fun _ _ ↦ add_mem) fun r m hm ↦ closure_induction hm ?_ ?_ fun _ _ h h' ↦ ?_)
(closure_le.2 ?_)
· rintro _ ⟨r, -, m, hm, rfl⟩; exact smul_mem _ _ (subset_span hm)
· rintro _ ⟨r', -, m, hm, rfl⟩; exact subset_closure ⟨r * r', trivial, m, hm, mul_smul r r' m⟩
· rw [smul_zero]; apply zero_mem
· rw [smul_add]; exact add_mem h h'
/-- A variant of `span_induction` that combines `∀ x ∈ s, p x` and `∀ r x, p x → p (r • x)`
into a single condition `∀ r, ∀ x ∈ s, p (r • x)`, which can be easier to verify. -/
@[elab_as_elim]
theorem closure_induction {p : M → Prop} (h : x ∈ span R s) (zero : p 0)
(add : ∀ x y, p x → p y → p (x + y)) (smul_mem : ∀ r : R, ∀ x ∈ s, p (r • x)) : p x := by
rw [← mem_toAddSubmonoid, span_eq_closure] at h
refine AddSubmonoid.closure_induction h ?_ zero add
rintro _ ⟨r, -, m, hm, rfl⟩
exact smul_mem r m hm
/-- A dependent version of `Submodule.closure_induction`. -/
@[elab_as_elim]
theorem closure_induction' {p : ∀ x, x ∈ span R s → Prop}
(zero : p 0 (Submodule.zero_mem _))
(add : ∀ x hx y hy, p x hx → p y hy → p (x + y) (Submodule.add_mem _ ‹_› ‹_›))
(smul_mem : ∀ (r x) (h : x ∈ s), p (r • x) (Submodule.smul_mem _ _ <| subset_span h)) {x}
(hx : x ∈ span R s) : p x hx := by
refine Exists.elim ?_ fun (hx : x ∈ span R s) (hc : p x hx) ↦ hc
refine closure_induction hx ⟨zero_mem _, zero⟩
(fun x y hx hy ↦ Exists.elim hx fun hx' hx ↦
Exists.elim hy fun hy' hy ↦ ⟨add_mem hx' hy', add _ _ _ _ hx hy⟩)
fun r x hx ↦ ⟨Submodule.smul_mem _ _ (subset_span hx), smul_mem r x hx⟩
@[simp]
theorem span_span_coe_preimage : span R (((↑) : span R s → M) ⁻¹' s) = ⊤ :=
eq_top_iff.2 fun x ↦ Subtype.recOn x fun x hx _ ↦ by
refine span_induction' (p := fun x hx ↦ (⟨x, hx⟩ : span R s) ∈ span R (Subtype.val ⁻¹' s))
(fun x' hx' ↦ subset_span hx') ?_ (fun x _ y _ ↦ ?_) (fun r x _ ↦ ?_) hx
· exact zero_mem _
· exact add_mem
· exact smul_mem _ _
#align submodule.span_span_coe_preimage Submodule.span_span_coe_preimage
@[simp]
lemma span_setOf_mem_eq_top :
span R {x : span R s | (x : M) ∈ s} = ⊤ :=
span_span_coe_preimage
theorem span_nat_eq_addSubmonoid_closure (s : Set M) :
(span ℕ s).toAddSubmonoid = AddSubmonoid.closure s := by
refine Eq.symm (AddSubmonoid.closure_eq_of_le subset_span ?_)
apply (OrderIso.to_galoisConnection (AddSubmonoid.toNatSubmodule (M := M)).symm).l_le
(a := span ℕ s) (b := AddSubmonoid.closure s)
rw [span_le]
exact AddSubmonoid.subset_closure
#align submodule.span_nat_eq_add_submonoid_closure Submodule.span_nat_eq_addSubmonoid_closure
@[simp]
theorem span_nat_eq (s : AddSubmonoid M) : (span ℕ (s : Set M)).toAddSubmonoid = s := by
rw [span_nat_eq_addSubmonoid_closure, s.closure_eq]
#align submodule.span_nat_eq Submodule.span_nat_eq
theorem span_int_eq_addSubgroup_closure {M : Type*} [AddCommGroup M] (s : Set M) :
(span ℤ s).toAddSubgroup = AddSubgroup.closure s :=
Eq.symm <|
AddSubgroup.closure_eq_of_le _ subset_span fun x hx =>
span_induction hx (fun x hx => AddSubgroup.subset_closure hx) (AddSubgroup.zero_mem _)
(fun _ _ => AddSubgroup.add_mem _) fun _ _ _ => AddSubgroup.zsmul_mem _ ‹_› _
#align submodule.span_int_eq_add_subgroup_closure Submodule.span_int_eq_addSubgroup_closure
@[simp]
theorem span_int_eq {M : Type*} [AddCommGroup M] (s : AddSubgroup M) :
(span ℤ (s : Set M)).toAddSubgroup = s := by rw [span_int_eq_addSubgroup_closure, s.closure_eq]
#align submodule.span_int_eq Submodule.span_int_eq
section
variable (R M)
/-- `span` forms a Galois insertion with the coercion from submodule to set. -/
protected def gi : GaloisInsertion (@span R M _ _ _) (↑) where
choice s _ := span R s
gc _ _ := span_le
le_l_u _ := subset_span
choice_eq _ _ := rfl
#align submodule.gi Submodule.gi
end
@[simp]
theorem span_empty : span R (∅ : Set M) = ⊥ :=
(Submodule.gi R M).gc.l_bot
#align submodule.span_empty Submodule.span_empty
@[simp]
theorem span_univ : span R (univ : Set M) = ⊤ :=
eq_top_iff.2 <| SetLike.le_def.2 <| subset_span
#align submodule.span_univ Submodule.span_univ
theorem span_union (s t : Set M) : span R (s ∪ t) = span R s ⊔ span R t :=
(Submodule.gi R M).gc.l_sup
#align submodule.span_union Submodule.span_union
theorem span_iUnion {ι} (s : ι → Set M) : span R (⋃ i, s i) = ⨆ i, span R (s i) :=
(Submodule.gi R M).gc.l_iSup
#align submodule.span_Union Submodule.span_iUnion
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
/- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/
theorem span_iUnion₂ {ι} {κ : ι → Sort*} (s : ∀ i, κ i → Set M) :
span R (⋃ (i) (j), s i j) = ⨆ (i) (j), span R (s i j) :=
(Submodule.gi R M).gc.l_iSup₂
#align submodule.span_Union₂ Submodule.span_iUnion₂
theorem span_attach_biUnion [DecidableEq M] {α : Type*} (s : Finset α) (f : s → Finset M) :
span R (s.attach.biUnion f : Set M) = ⨆ x, span R (f x) := by simp [span_iUnion]
#align submodule.span_attach_bUnion Submodule.span_attach_biUnion
theorem sup_span : p ⊔ span R s = span R (p ∪ s) := by rw [Submodule.span_union, p.span_eq]
#align submodule.sup_span Submodule.sup_span
theorem span_sup : span R s ⊔ p = span R (s ∪ p) := by rw [Submodule.span_union, p.span_eq]
#align submodule.span_sup Submodule.span_sup
notation:1000
/- Note that the character `∙` U+2219 used below is different from the scalar multiplication
character `•` U+2022. -/
R " ∙ " x => span R (singleton x)
theorem span_eq_iSup_of_singleton_spans (s : Set M) : span R s = ⨆ x ∈ s, R ∙ x := by
simp only [← span_iUnion, Set.biUnion_of_singleton s]
#align submodule.span_eq_supr_of_singleton_spans Submodule.span_eq_iSup_of_singleton_spans
theorem span_range_eq_iSup {ι : Sort*} {v : ι → M} : span R (range v) = ⨆ i, R ∙ v i := by
rw [span_eq_iSup_of_singleton_spans, iSup_range]
#align submodule.span_range_eq_supr Submodule.span_range_eq_iSup
theorem span_smul_le (s : Set M) (r : R) : span R (r • s) ≤ span R s := by
rw [span_le]
rintro _ ⟨x, hx, rfl⟩
exact smul_mem (span R s) r (subset_span hx)
#align submodule.span_smul_le Submodule.span_smul_le
theorem subset_span_trans {U V W : Set M} (hUV : U ⊆ Submodule.span R V)
(hVW : V ⊆ Submodule.span R W) : U ⊆ Submodule.span R W :=
(Submodule.gi R M).gc.le_u_l_trans hUV hVW
#align submodule.subset_span_trans Submodule.subset_span_trans
/-- See `Submodule.span_smul_eq` (in `RingTheory.Ideal.Operations`) for
`span R (r • s) = r • span R s` that holds for arbitrary `r` in a `CommSemiring`. -/
theorem span_smul_eq_of_isUnit (s : Set M) (r : R) (hr : IsUnit r) : span R (r • s) = span R s := by
apply le_antisymm
· apply span_smul_le
· convert span_smul_le (r • s) ((hr.unit⁻¹ : _) : R)
rw [smul_smul]
erw [hr.unit.inv_val]
rw [one_smul]
#align submodule.span_smul_eq_of_is_unit Submodule.span_smul_eq_of_isUnit
@[simp]
theorem coe_iSup_of_directed {ι} [Nonempty ι] (S : ι → Submodule R M)
(H : Directed (· ≤ ·) S) : ((iSup S: Submodule R M) : Set M) = ⋃ i, S i :=
let s : Submodule R M :=
{ __ := AddSubmonoid.copy _ _ (AddSubmonoid.coe_iSup_of_directed H).symm
smul_mem' := fun r _ hx ↦ have ⟨i, hi⟩ := Set.mem_iUnion.mp hx
Set.mem_iUnion.mpr ⟨i, (S i).smul_mem' r hi⟩ }
have : iSup S = s := le_antisymm
(iSup_le fun i ↦ le_iSup (fun i ↦ (S i : Set M)) i) (Set.iUnion_subset fun _ ↦ le_iSup S _)
this.symm ▸ rfl
#align submodule.coe_supr_of_directed Submodule.coe_iSup_of_directed
@[simp]
theorem mem_iSup_of_directed {ι} [Nonempty ι] (S : ι → Submodule R M) (H : Directed (· ≤ ·) S) {x} :
x ∈ iSup S ↔ ∃ i, x ∈ S i := by
rw [← SetLike.mem_coe, coe_iSup_of_directed S H, mem_iUnion]
rfl
#align submodule.mem_supr_of_directed Submodule.mem_iSup_of_directed
theorem mem_sSup_of_directed {s : Set (Submodule R M)} {z} (hs : s.Nonempty)
(hdir : DirectedOn (· ≤ ·) s) : z ∈ sSup s ↔ ∃ y ∈ s, z ∈ y := by
have : Nonempty s := hs.to_subtype
simp only [sSup_eq_iSup', mem_iSup_of_directed _ hdir.directed_val, SetCoe.exists, Subtype.coe_mk,
exists_prop]
#align submodule.mem_Sup_of_directed Submodule.mem_sSup_of_directed
@[norm_cast, simp]
theorem coe_iSup_of_chain (a : ℕ →o Submodule R M) : (↑(⨆ k, a k) : Set M) = ⋃ k, (a k : Set M) :=
coe_iSup_of_directed a a.monotone.directed_le
#align submodule.coe_supr_of_chain Submodule.coe_iSup_of_chain
/-- We can regard `coe_iSup_of_chain` as the statement that `(↑) : (Submodule R M) → Set M` is
Scott continuous for the ω-complete partial order induced by the complete lattice structures. -/
theorem coe_scott_continuous :
OmegaCompletePartialOrder.Continuous' ((↑) : Submodule R M → Set M) :=
⟨SetLike.coe_mono, coe_iSup_of_chain⟩
#align submodule.coe_scott_continuous Submodule.coe_scott_continuous
@[simp]
theorem mem_iSup_of_chain (a : ℕ →o Submodule R M) (m : M) : (m ∈ ⨆ k, a k) ↔ ∃ k, m ∈ a k :=
mem_iSup_of_directed a a.monotone.directed_le
#align submodule.mem_supr_of_chain Submodule.mem_iSup_of_chain
section
variable {p p'}
theorem mem_sup : x ∈ p ⊔ p' ↔ ∃ y ∈ p, ∃ z ∈ p', y + z = x :=
⟨fun h => by
rw [← span_eq p, ← span_eq p', ← span_union] at h
refine span_induction h ?_ ?_ ?_ ?_
· rintro y (h | h)
· exact ⟨y, h, 0, by simp, by simp⟩
· exact ⟨0, by simp, y, h, by simp⟩
· exact ⟨0, by simp, 0, by simp⟩
· rintro _ _ ⟨y₁, hy₁, z₁, hz₁, rfl⟩ ⟨y₂, hy₂, z₂, hz₂, rfl⟩
exact ⟨_, add_mem hy₁ hy₂, _, add_mem hz₁ hz₂, by
rw [add_assoc, add_assoc, ← add_assoc y₂, ← add_assoc z₁, add_comm y₂]⟩
· rintro a _ ⟨y, hy, z, hz, rfl⟩
exact ⟨_, smul_mem _ a hy, _, smul_mem _ a hz, by simp [smul_add]⟩, by
rintro ⟨y, hy, z, hz, rfl⟩
exact add_mem ((le_sup_left : p ≤ p ⊔ p') hy) ((le_sup_right : p' ≤ p ⊔ p') hz)⟩
#align submodule.mem_sup Submodule.mem_sup
theorem mem_sup' : x ∈ p ⊔ p' ↔ ∃ (y : p) (z : p'), (y : M) + z = x :=
mem_sup.trans <| by simp only [Subtype.exists, exists_prop]
#align submodule.mem_sup' Submodule.mem_sup'
lemma exists_add_eq_of_codisjoint (h : Codisjoint p p') (x : M) :
∃ y ∈ p, ∃ z ∈ p', y + z = x := by
suffices x ∈ p ⊔ p' by exact Submodule.mem_sup.mp this
simpa only [h.eq_top] using Submodule.mem_top
variable (p p')
theorem coe_sup : ↑(p ⊔ p') = (p + p' : Set M) := by
ext
rw [SetLike.mem_coe, mem_sup, Set.mem_add]
simp
#align submodule.coe_sup Submodule.coe_sup
theorem sup_toAddSubmonoid : (p ⊔ p').toAddSubmonoid = p.toAddSubmonoid ⊔ p'.toAddSubmonoid := by
ext x
rw [mem_toAddSubmonoid, mem_sup, AddSubmonoid.mem_sup]
rfl
#align submodule.sup_to_add_submonoid Submodule.sup_toAddSubmonoid
| Mathlib/LinearAlgebra/Span.lean | 464 | 468 | theorem sup_toAddSubgroup {R M : Type*} [Ring R] [AddCommGroup M] [Module R M]
(p p' : Submodule R M) : (p ⊔ p').toAddSubgroup = p.toAddSubgroup ⊔ p'.toAddSubgroup := by |
ext x
rw [mem_toAddSubgroup, mem_sup, AddSubgroup.mem_sup]
rfl
|
/-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Julian Kuelshammer
-/
import Mathlib.Algebra.CharP.Defs
import Mathlib.Algebra.GroupPower.IterateHom
import Mathlib.Algebra.GroupWithZero.Divisibility
import Mathlib.Data.Int.ModEq
import Mathlib.Data.Set.Pointwise.Basic
import Mathlib.Dynamics.PeriodicPts
import Mathlib.GroupTheory.Index
import Mathlib.Order.Interval.Finset.Nat
import Mathlib.Order.Interval.Set.Infinite
#align_import group_theory.order_of_element from "leanprover-community/mathlib"@"d07245fd37786daa997af4f1a73a49fa3b748408"
/-!
# Order of an element
This file defines the order of an element of a finite group. For a finite group `G` the order of
`x ∈ G` is the minimal `n ≥ 1` such that `x ^ n = 1`.
## Main definitions
* `IsOfFinOrder` is a predicate on an element `x` of a monoid `G` saying that `x` is of finite
order.
* `IsOfFinAddOrder` is the additive analogue of `IsOfFinOrder`.
* `orderOf x` defines the order of an element `x` of a monoid `G`, by convention its value is `0`
if `x` has infinite order.
* `addOrderOf` is the additive analogue of `orderOf`.
## Tags
order of an element
-/
open Function Fintype Nat Pointwise Subgroup Submonoid
variable {G H A α β : Type*}
section Monoid
variable [Monoid G] {a b x y : G} {n m : ℕ}
section IsOfFinOrder
-- Porting note(#12129): additional beta reduction needed
@[to_additive]
theorem isPeriodicPt_mul_iff_pow_eq_one (x : G) : IsPeriodicPt (x * ·) n 1 ↔ x ^ n = 1 := by
rw [IsPeriodicPt, IsFixedPt, mul_left_iterate]; beta_reduce; rw [mul_one]
#align is_periodic_pt_mul_iff_pow_eq_one isPeriodicPt_mul_iff_pow_eq_one
#align is_periodic_pt_add_iff_nsmul_eq_zero isPeriodicPt_add_iff_nsmul_eq_zero
/-- `IsOfFinOrder` is a predicate on an element `x` of a monoid to be of finite order, i.e. there
exists `n ≥ 1` such that `x ^ n = 1`. -/
@[to_additive "`IsOfFinAddOrder` is a predicate on an element `a` of an
additive monoid to be of finite order, i.e. there exists `n ≥ 1` such that `n • a = 0`."]
def IsOfFinOrder (x : G) : Prop :=
(1 : G) ∈ periodicPts (x * ·)
#align is_of_fin_order IsOfFinOrder
#align is_of_fin_add_order IsOfFinAddOrder
theorem isOfFinAddOrder_ofMul_iff : IsOfFinAddOrder (Additive.ofMul x) ↔ IsOfFinOrder x :=
Iff.rfl
#align is_of_fin_add_order_of_mul_iff isOfFinAddOrder_ofMul_iff
theorem isOfFinOrder_ofAdd_iff {α : Type*} [AddMonoid α] {x : α} :
IsOfFinOrder (Multiplicative.ofAdd x) ↔ IsOfFinAddOrder x := Iff.rfl
#align is_of_fin_order_of_add_iff isOfFinOrder_ofAdd_iff
@[to_additive]
theorem isOfFinOrder_iff_pow_eq_one : IsOfFinOrder x ↔ ∃ n, 0 < n ∧ x ^ n = 1 := by
simp [IsOfFinOrder, mem_periodicPts, isPeriodicPt_mul_iff_pow_eq_one]
#align is_of_fin_order_iff_pow_eq_one isOfFinOrder_iff_pow_eq_one
#align is_of_fin_add_order_iff_nsmul_eq_zero isOfFinAddOrder_iff_nsmul_eq_zero
@[to_additive] alias ⟨IsOfFinOrder.exists_pow_eq_one, _⟩ := isOfFinOrder_iff_pow_eq_one
@[to_additive]
lemma isOfFinOrder_iff_zpow_eq_one {G} [Group G] {x : G} :
IsOfFinOrder x ↔ ∃ (n : ℤ), n ≠ 0 ∧ x ^ n = 1 := by
rw [isOfFinOrder_iff_pow_eq_one]
refine ⟨fun ⟨n, hn, hn'⟩ ↦ ⟨n, Int.natCast_ne_zero_iff_pos.mpr hn, zpow_natCast x n ▸ hn'⟩,
fun ⟨n, hn, hn'⟩ ↦ ⟨n.natAbs, Int.natAbs_pos.mpr hn, ?_⟩⟩
cases' (Int.natAbs_eq_iff (a := n)).mp rfl with h h
· rwa [h, zpow_natCast] at hn'
· rwa [h, zpow_neg, inv_eq_one, zpow_natCast] at hn'
/-- See also `injective_pow_iff_not_isOfFinOrder`. -/
@[to_additive "See also `injective_nsmul_iff_not_isOfFinAddOrder`."]
theorem not_isOfFinOrder_of_injective_pow {x : G} (h : Injective fun n : ℕ => x ^ n) :
¬IsOfFinOrder x := by
simp_rw [isOfFinOrder_iff_pow_eq_one, not_exists, not_and]
intro n hn_pos hnx
rw [← pow_zero x] at hnx
rw [h hnx] at hn_pos
exact irrefl 0 hn_pos
#align not_is_of_fin_order_of_injective_pow not_isOfFinOrder_of_injective_pow
#align not_is_of_fin_add_order_of_injective_nsmul not_isOfFinAddOrder_of_injective_nsmul
lemma IsOfFinOrder.pow {n : ℕ} : IsOfFinOrder a → IsOfFinOrder (a ^ n) := by
simp_rw [isOfFinOrder_iff_pow_eq_one]
rintro ⟨m, hm, ha⟩
exact ⟨m, hm, by simp [pow_right_comm _ n, ha]⟩
/-- Elements of finite order are of finite order in submonoids. -/
@[to_additive "Elements of finite order are of finite order in submonoids."]
theorem Submonoid.isOfFinOrder_coe {H : Submonoid G} {x : H} :
IsOfFinOrder (x : G) ↔ IsOfFinOrder x := by
rw [isOfFinOrder_iff_pow_eq_one, isOfFinOrder_iff_pow_eq_one]
norm_cast
#align is_of_fin_order_iff_coe Submonoid.isOfFinOrder_coe
#align is_of_fin_add_order_iff_coe AddSubmonoid.isOfFinAddOrder_coe
/-- The image of an element of finite order has finite order. -/
@[to_additive "The image of an element of finite additive order has finite additive order."]
theorem MonoidHom.isOfFinOrder [Monoid H] (f : G →* H) {x : G} (h : IsOfFinOrder x) :
IsOfFinOrder <| f x :=
isOfFinOrder_iff_pow_eq_one.mpr <| by
obtain ⟨n, npos, hn⟩ := h.exists_pow_eq_one
exact ⟨n, npos, by rw [← f.map_pow, hn, f.map_one]⟩
#align monoid_hom.is_of_fin_order MonoidHom.isOfFinOrder
#align add_monoid_hom.is_of_fin_order AddMonoidHom.isOfFinAddOrder
/-- If a direct product has finite order then so does each component. -/
@[to_additive "If a direct product has finite additive order then so does each component."]
theorem IsOfFinOrder.apply {η : Type*} {Gs : η → Type*} [∀ i, Monoid (Gs i)] {x : ∀ i, Gs i}
(h : IsOfFinOrder x) : ∀ i, IsOfFinOrder (x i) := by
obtain ⟨n, npos, hn⟩ := h.exists_pow_eq_one
exact fun _ => isOfFinOrder_iff_pow_eq_one.mpr ⟨n, npos, (congr_fun hn.symm _).symm⟩
#align is_of_fin_order.apply IsOfFinOrder.apply
#align is_of_fin_add_order.apply IsOfFinAddOrder.apply
/-- 1 is of finite order in any monoid. -/
@[to_additive "0 is of finite order in any additive monoid."]
theorem isOfFinOrder_one : IsOfFinOrder (1 : G) :=
isOfFinOrder_iff_pow_eq_one.mpr ⟨1, Nat.one_pos, one_pow 1⟩
#align is_of_fin_order_one isOfFinOrder_one
#align is_of_fin_order_zero isOfFinAddOrder_zero
/-- The submonoid generated by an element is a group if that element has finite order. -/
@[to_additive "The additive submonoid generated by an element is
an additive group if that element has finite order."]
noncomputable abbrev IsOfFinOrder.groupPowers (hx : IsOfFinOrder x) :
Group (Submonoid.powers x) := by
obtain ⟨hpos, hx⟩ := hx.exists_pow_eq_one.choose_spec
exact Submonoid.groupPowers hpos hx
end IsOfFinOrder
/-- `orderOf x` is the order of the element `x`, i.e. the `n ≥ 1`, s.t. `x ^ n = 1` if it exists.
Otherwise, i.e. if `x` is of infinite order, then `orderOf x` is `0` by convention. -/
@[to_additive
"`addOrderOf a` is the order of the element `a`, i.e. the `n ≥ 1`, s.t. `n • a = 0` if it
exists. Otherwise, i.e. if `a` is of infinite order, then `addOrderOf a` is `0` by convention."]
noncomputable def orderOf (x : G) : ℕ :=
minimalPeriod (x * ·) 1
#align order_of orderOf
#align add_order_of addOrderOf
@[simp]
theorem addOrderOf_ofMul_eq_orderOf (x : G) : addOrderOf (Additive.ofMul x) = orderOf x :=
rfl
#align add_order_of_of_mul_eq_order_of addOrderOf_ofMul_eq_orderOf
@[simp]
lemma orderOf_ofAdd_eq_addOrderOf {α : Type*} [AddMonoid α] (a : α) :
orderOf (Multiplicative.ofAdd a) = addOrderOf a := rfl
#align order_of_of_add_eq_add_order_of orderOf_ofAdd_eq_addOrderOf
@[to_additive]
protected lemma IsOfFinOrder.orderOf_pos (h : IsOfFinOrder x) : 0 < orderOf x :=
minimalPeriod_pos_of_mem_periodicPts h
#align order_of_pos' IsOfFinOrder.orderOf_pos
#align add_order_of_pos' IsOfFinAddOrder.addOrderOf_pos
@[to_additive addOrderOf_nsmul_eq_zero]
theorem pow_orderOf_eq_one (x : G) : x ^ orderOf x = 1 := by
convert Eq.trans _ (isPeriodicPt_minimalPeriod (x * ·) 1)
-- Porting note(#12129): additional beta reduction needed in the middle of the rewrite
rw [orderOf, mul_left_iterate]; beta_reduce; rw [mul_one]
#align pow_order_of_eq_one pow_orderOf_eq_one
#align add_order_of_nsmul_eq_zero addOrderOf_nsmul_eq_zero
@[to_additive]
theorem orderOf_eq_zero (h : ¬IsOfFinOrder x) : orderOf x = 0 := by
rwa [orderOf, minimalPeriod, dif_neg]
#align order_of_eq_zero orderOf_eq_zero
#align add_order_of_eq_zero addOrderOf_eq_zero
@[to_additive]
theorem orderOf_eq_zero_iff : orderOf x = 0 ↔ ¬IsOfFinOrder x :=
⟨fun h H ↦ H.orderOf_pos.ne' h, orderOf_eq_zero⟩
#align order_of_eq_zero_iff orderOf_eq_zero_iff
#align add_order_of_eq_zero_iff addOrderOf_eq_zero_iff
@[to_additive]
theorem orderOf_eq_zero_iff' : orderOf x = 0 ↔ ∀ n : ℕ, 0 < n → x ^ n ≠ 1 := by
simp_rw [orderOf_eq_zero_iff, isOfFinOrder_iff_pow_eq_one, not_exists, not_and]
#align order_of_eq_zero_iff' orderOf_eq_zero_iff'
#align add_order_of_eq_zero_iff' addOrderOf_eq_zero_iff'
@[to_additive]
theorem orderOf_eq_iff {n} (h : 0 < n) :
orderOf x = n ↔ x ^ n = 1 ∧ ∀ m, m < n → 0 < m → x ^ m ≠ 1 := by
simp_rw [Ne, ← isPeriodicPt_mul_iff_pow_eq_one, orderOf, minimalPeriod]
split_ifs with h1
· classical
rw [find_eq_iff]
simp only [h, true_and]
push_neg
rfl
· rw [iff_false_left h.ne]
rintro ⟨h', -⟩
exact h1 ⟨n, h, h'⟩
#align order_of_eq_iff orderOf_eq_iff
#align add_order_of_eq_iff addOrderOf_eq_iff
/-- A group element has finite order iff its order is positive. -/
@[to_additive
"A group element has finite additive order iff its order is positive."]
theorem orderOf_pos_iff : 0 < orderOf x ↔ IsOfFinOrder x := by
rw [iff_not_comm.mp orderOf_eq_zero_iff, pos_iff_ne_zero]
#align order_of_pos_iff orderOf_pos_iff
#align add_order_of_pos_iff addOrderOf_pos_iff
@[to_additive]
theorem IsOfFinOrder.mono [Monoid β] {y : β} (hx : IsOfFinOrder x) (h : orderOf y ∣ orderOf x) :
IsOfFinOrder y := by rw [← orderOf_pos_iff] at hx ⊢; exact Nat.pos_of_dvd_of_pos h hx
#align is_of_fin_order.mono IsOfFinOrder.mono
#align is_of_fin_add_order.mono IsOfFinAddOrder.mono
@[to_additive]
theorem pow_ne_one_of_lt_orderOf' (n0 : n ≠ 0) (h : n < orderOf x) : x ^ n ≠ 1 := fun j =>
not_isPeriodicPt_of_pos_of_lt_minimalPeriod n0 h ((isPeriodicPt_mul_iff_pow_eq_one x).mpr j)
#align pow_ne_one_of_lt_order_of' pow_ne_one_of_lt_orderOf'
#align nsmul_ne_zero_of_lt_add_order_of' nsmul_ne_zero_of_lt_addOrderOf'
@[to_additive]
theorem orderOf_le_of_pow_eq_one (hn : 0 < n) (h : x ^ n = 1) : orderOf x ≤ n :=
IsPeriodicPt.minimalPeriod_le hn (by rwa [isPeriodicPt_mul_iff_pow_eq_one])
#align order_of_le_of_pow_eq_one orderOf_le_of_pow_eq_one
#align add_order_of_le_of_nsmul_eq_zero addOrderOf_le_of_nsmul_eq_zero
@[to_additive (attr := simp)]
theorem orderOf_one : orderOf (1 : G) = 1 := by
rw [orderOf, ← minimalPeriod_id (x := (1:G)), ← one_mul_eq_id]
#align order_of_one orderOf_one
#align order_of_zero addOrderOf_zero
@[to_additive (attr := simp) AddMonoid.addOrderOf_eq_one_iff]
theorem orderOf_eq_one_iff : orderOf x = 1 ↔ x = 1 := by
rw [orderOf, minimalPeriod_eq_one_iff_isFixedPt, IsFixedPt, mul_one]
#align order_of_eq_one_iff orderOf_eq_one_iff
#align add_monoid.order_of_eq_one_iff AddMonoid.addOrderOf_eq_one_iff
@[to_additive (attr := simp) mod_addOrderOf_nsmul]
lemma pow_mod_orderOf (x : G) (n : ℕ) : x ^ (n % orderOf x) = x ^ n :=
calc
x ^ (n % orderOf x) = x ^ (n % orderOf x + orderOf x * (n / orderOf x)) := by
simp [pow_add, pow_mul, pow_orderOf_eq_one]
_ = x ^ n := by rw [Nat.mod_add_div]
#align pow_eq_mod_order_of pow_mod_orderOf
#align nsmul_eq_mod_add_order_of mod_addOrderOf_nsmul
@[to_additive]
theorem orderOf_dvd_of_pow_eq_one (h : x ^ n = 1) : orderOf x ∣ n :=
IsPeriodicPt.minimalPeriod_dvd ((isPeriodicPt_mul_iff_pow_eq_one _).mpr h)
#align order_of_dvd_of_pow_eq_one orderOf_dvd_of_pow_eq_one
#align add_order_of_dvd_of_nsmul_eq_zero addOrderOf_dvd_of_nsmul_eq_zero
@[to_additive]
theorem orderOf_dvd_iff_pow_eq_one {n : ℕ} : orderOf x ∣ n ↔ x ^ n = 1 :=
⟨fun h => by rw [← pow_mod_orderOf, Nat.mod_eq_zero_of_dvd h, _root_.pow_zero],
orderOf_dvd_of_pow_eq_one⟩
#align order_of_dvd_iff_pow_eq_one orderOf_dvd_iff_pow_eq_one
#align add_order_of_dvd_iff_nsmul_eq_zero addOrderOf_dvd_iff_nsmul_eq_zero
@[to_additive addOrderOf_smul_dvd]
theorem orderOf_pow_dvd (n : ℕ) : orderOf (x ^ n) ∣ orderOf x := by
rw [orderOf_dvd_iff_pow_eq_one, pow_right_comm, pow_orderOf_eq_one, one_pow]
#align order_of_pow_dvd orderOf_pow_dvd
#align add_order_of_smul_dvd addOrderOf_smul_dvd
@[to_additive]
lemma pow_injOn_Iio_orderOf : (Set.Iio <| orderOf x).InjOn (x ^ ·) := by
simpa only [mul_left_iterate, mul_one]
using iterate_injOn_Iio_minimalPeriod (f := (x * ·)) (x := 1)
#align pow_injective_of_lt_order_of pow_injOn_Iio_orderOf
#align nsmul_injective_of_lt_add_order_of nsmul_injOn_Iio_addOrderOf
@[to_additive]
protected lemma IsOfFinOrder.mem_powers_iff_mem_range_orderOf [DecidableEq G]
(hx : IsOfFinOrder x) :
y ∈ Submonoid.powers x ↔ y ∈ (Finset.range (orderOf x)).image (x ^ ·) :=
Finset.mem_range_iff_mem_finset_range_of_mod_eq' hx.orderOf_pos <| pow_mod_orderOf _
#align mem_powers_iff_mem_range_order_of' IsOfFinOrder.mem_powers_iff_mem_range_orderOf
#align mem_multiples_iff_mem_range_add_order_of' IsOfFinAddOrder.mem_multiples_iff_mem_range_addOrderOf
@[to_additive]
protected lemma IsOfFinOrder.powers_eq_image_range_orderOf [DecidableEq G] (hx : IsOfFinOrder x) :
(Submonoid.powers x : Set G) = (Finset.range (orderOf x)).image (x ^ ·) :=
Set.ext fun _ ↦ hx.mem_powers_iff_mem_range_orderOf
@[deprecated (since := "2024-02-21")]
alias IsOfFinAddOrder.powers_eq_image_range_orderOf :=
IsOfFinAddOrder.multiples_eq_image_range_addOrderOf
@[to_additive]
theorem pow_eq_one_iff_modEq : x ^ n = 1 ↔ n ≡ 0 [MOD orderOf x] := by
rw [modEq_zero_iff_dvd, orderOf_dvd_iff_pow_eq_one]
#align pow_eq_one_iff_modeq pow_eq_one_iff_modEq
#align nsmul_eq_zero_iff_modeq nsmul_eq_zero_iff_modEq
@[to_additive]
theorem orderOf_map_dvd {H : Type*} [Monoid H] (ψ : G →* H) (x : G) :
orderOf (ψ x) ∣ orderOf x := by
apply orderOf_dvd_of_pow_eq_one
rw [← map_pow, pow_orderOf_eq_one]
apply map_one
#align order_of_map_dvd orderOf_map_dvd
#align add_order_of_map_dvd addOrderOf_map_dvd
@[to_additive]
theorem exists_pow_eq_self_of_coprime (h : n.Coprime (orderOf x)) : ∃ m : ℕ, (x ^ n) ^ m = x := by
by_cases h0 : orderOf x = 0
· rw [h0, coprime_zero_right] at h
exact ⟨1, by rw [h, pow_one, pow_one]⟩
by_cases h1 : orderOf x = 1
· exact ⟨0, by rw [orderOf_eq_one_iff.mp h1, one_pow, one_pow]⟩
obtain ⟨m, h⟩ := exists_mul_emod_eq_one_of_coprime h (one_lt_iff_ne_zero_and_ne_one.mpr ⟨h0, h1⟩)
exact ⟨m, by rw [← pow_mul, ← pow_mod_orderOf, h, pow_one]⟩
#align exists_pow_eq_self_of_coprime exists_pow_eq_self_of_coprime
#align exists_nsmul_eq_self_of_coprime exists_nsmul_eq_self_of_coprime
/-- If `x^n = 1`, but `x^(n/p) ≠ 1` for all prime factors `p` of `n`,
then `x` has order `n` in `G`. -/
@[to_additive addOrderOf_eq_of_nsmul_and_div_prime_nsmul "If `n * x = 0`, but `n/p * x ≠ 0` for
all prime factors `p` of `n`, then `x` has order `n` in `G`."]
theorem orderOf_eq_of_pow_and_pow_div_prime (hn : 0 < n) (hx : x ^ n = 1)
(hd : ∀ p : ℕ, p.Prime → p ∣ n → x ^ (n / p) ≠ 1) : orderOf x = n := by
-- Let `a` be `n/(orderOf x)`, and show `a = 1`
cases' exists_eq_mul_right_of_dvd (orderOf_dvd_of_pow_eq_one hx) with a ha
suffices a = 1 by simp [this, ha]
-- Assume `a` is not one...
by_contra h
have a_min_fac_dvd_p_sub_one : a.minFac ∣ n := by
obtain ⟨b, hb⟩ : ∃ b : ℕ, a = b * a.minFac := exists_eq_mul_left_of_dvd a.minFac_dvd
rw [hb, ← mul_assoc] at ha
exact Dvd.intro_left (orderOf x * b) ha.symm
-- Use the minimum prime factor of `a` as `p`.
refine hd a.minFac (Nat.minFac_prime h) a_min_fac_dvd_p_sub_one ?_
rw [← orderOf_dvd_iff_pow_eq_one, Nat.dvd_div_iff a_min_fac_dvd_p_sub_one, ha, mul_comm,
Nat.mul_dvd_mul_iff_left (IsOfFinOrder.orderOf_pos _)]
· exact Nat.minFac_dvd a
· rw [isOfFinOrder_iff_pow_eq_one]
exact Exists.intro n (id ⟨hn, hx⟩)
#align order_of_eq_of_pow_and_pow_div_prime orderOf_eq_of_pow_and_pow_div_prime
#align add_order_of_eq_of_nsmul_and_div_prime_nsmul addOrderOf_eq_of_nsmul_and_div_prime_nsmul
@[to_additive]
theorem orderOf_eq_orderOf_iff {H : Type*} [Monoid H] {y : H} :
orderOf x = orderOf y ↔ ∀ n : ℕ, x ^ n = 1 ↔ y ^ n = 1 := by
simp_rw [← isPeriodicPt_mul_iff_pow_eq_one, ← minimalPeriod_eq_minimalPeriod_iff, orderOf]
#align order_of_eq_order_of_iff orderOf_eq_orderOf_iff
#align add_order_of_eq_add_order_of_iff addOrderOf_eq_addOrderOf_iff
/-- An injective homomorphism of monoids preserves orders of elements. -/
@[to_additive "An injective homomorphism of additive monoids preserves orders of elements."]
theorem orderOf_injective {H : Type*} [Monoid H] (f : G →* H) (hf : Function.Injective f) (x : G) :
orderOf (f x) = orderOf x := by
simp_rw [orderOf_eq_orderOf_iff, ← f.map_pow, ← f.map_one, hf.eq_iff, forall_const]
#align order_of_injective orderOf_injective
#align add_order_of_injective addOrderOf_injective
/-- A multiplicative equivalence preserves orders of elements. -/
@[to_additive (attr := simp) "An additive equivalence preserves orders of elements."]
lemma MulEquiv.orderOf_eq {H : Type*} [Monoid H] (e : G ≃* H) (x : G) :
orderOf (e x) = orderOf x :=
orderOf_injective e e.injective x
@[to_additive]
theorem Function.Injective.isOfFinOrder_iff [Monoid H] {f : G →* H} (hf : Injective f) :
IsOfFinOrder (f x) ↔ IsOfFinOrder x := by
rw [← orderOf_pos_iff, orderOf_injective f hf x, ← orderOf_pos_iff]
@[to_additive (attr := norm_cast, simp)]
theorem orderOf_submonoid {H : Submonoid G} (y : H) : orderOf (y : G) = orderOf y :=
orderOf_injective H.subtype Subtype.coe_injective y
#align order_of_submonoid orderOf_submonoid
#align order_of_add_submonoid addOrderOf_addSubmonoid
@[to_additive]
theorem orderOf_units {y : Gˣ} : orderOf (y : G) = orderOf y :=
orderOf_injective (Units.coeHom G) Units.ext y
#align order_of_units orderOf_units
#align order_of_add_units addOrderOf_addUnits
/-- If the order of `x` is finite, then `x` is a unit with inverse `x ^ (orderOf x - 1)`. -/
@[simps]
noncomputable
def IsOfFinOrder.unit {M} [Monoid M] {x : M} (hx : IsOfFinOrder x) : Mˣ :=
⟨x, x ^ (orderOf x - 1),
by rw [← _root_.pow_succ', tsub_add_cancel_of_le (by exact hx.orderOf_pos), pow_orderOf_eq_one],
by rw [← _root_.pow_succ, tsub_add_cancel_of_le (by exact hx.orderOf_pos), pow_orderOf_eq_one]⟩
lemma IsOfFinOrder.isUnit {M} [Monoid M] {x : M} (hx : IsOfFinOrder x) : IsUnit x := ⟨hx.unit, rfl⟩
variable (x)
@[to_additive]
theorem orderOf_pow' (h : n ≠ 0) : orderOf (x ^ n) = orderOf x / gcd (orderOf x) n := by
unfold orderOf
rw [← minimalPeriod_iterate_eq_div_gcd h, mul_left_iterate]
#align order_of_pow' orderOf_pow'
#align add_order_of_nsmul' addOrderOf_nsmul'
@[to_additive]
lemma orderOf_pow_of_dvd {x : G} {n : ℕ} (hn : n ≠ 0) (dvd : n ∣ orderOf x) :
orderOf (x ^ n) = orderOf x / n := by rw [orderOf_pow' _ hn, Nat.gcd_eq_right dvd]
@[to_additive]
lemma orderOf_pow_orderOf_div {x : G} {n : ℕ} (hx : orderOf x ≠ 0) (hn : n ∣ orderOf x) :
orderOf (x ^ (orderOf x / n)) = n := by
rw [orderOf_pow_of_dvd _ (Nat.div_dvd_of_dvd hn), Nat.div_div_self hn hx]
rw [← Nat.div_mul_cancel hn] at hx; exact left_ne_zero_of_mul hx
variable (n)
@[to_additive]
protected lemma IsOfFinOrder.orderOf_pow (h : IsOfFinOrder x) :
orderOf (x ^ n) = orderOf x / gcd (orderOf x) n := by
unfold orderOf
rw [← minimalPeriod_iterate_eq_div_gcd' h, mul_left_iterate]
#align order_of_pow'' IsOfFinOrder.orderOf_pow
#align add_order_of_nsmul'' IsOfFinAddOrder.addOrderOf_nsmul
@[to_additive]
lemma Nat.Coprime.orderOf_pow (h : (orderOf y).Coprime m) : orderOf (y ^ m) = orderOf y := by
by_cases hg : IsOfFinOrder y
· rw [hg.orderOf_pow y m , h.gcd_eq_one, Nat.div_one]
· rw [m.coprime_zero_left.1 (orderOf_eq_zero hg ▸ h), pow_one]
#align order_of_pow_coprime Nat.Coprime.orderOf_pow
#align add_order_of_nsmul_coprime Nat.Coprime.addOrderOf_nsmul
@[to_additive]
lemma IsOfFinOrder.natCard_powers_le_orderOf (ha : IsOfFinOrder a) :
Nat.card (powers a : Set G) ≤ orderOf a := by
classical
simpa [ha.powers_eq_image_range_orderOf, Finset.card_range, Nat.Iio_eq_range]
using Finset.card_image_le (s := Finset.range (orderOf a))
@[to_additive]
lemma IsOfFinOrder.finite_powers (ha : IsOfFinOrder a) : (powers a : Set G).Finite := by
classical rw [ha.powers_eq_image_range_orderOf]; exact Finset.finite_toSet _
namespace Commute
variable {x} (h : Commute x y)
@[to_additive]
theorem orderOf_mul_dvd_lcm : orderOf (x * y) ∣ Nat.lcm (orderOf x) (orderOf y) := by
rw [orderOf, ← comp_mul_left]
exact Function.Commute.minimalPeriod_of_comp_dvd_lcm h.function_commute_mul_left
#align commute.order_of_mul_dvd_lcm Commute.orderOf_mul_dvd_lcm
#align add_commute.order_of_add_dvd_lcm AddCommute.addOrderOf_add_dvd_lcm
@[to_additive]
theorem orderOf_dvd_lcm_mul : orderOf y ∣ Nat.lcm (orderOf x) (orderOf (x * y)) := by
by_cases h0 : orderOf x = 0
· rw [h0, lcm_zero_left]
apply dvd_zero
conv_lhs =>
rw [← one_mul y, ← pow_orderOf_eq_one x, ← succ_pred_eq_of_pos (Nat.pos_of_ne_zero h0),
_root_.pow_succ, mul_assoc]
exact
(((Commute.refl x).mul_right h).pow_left _).orderOf_mul_dvd_lcm.trans
(lcm_dvd_iff.2 ⟨(orderOf_pow_dvd _).trans (dvd_lcm_left _ _), dvd_lcm_right _ _⟩)
#align commute.order_of_dvd_lcm_mul Commute.orderOf_dvd_lcm_mul
#align add_commute.order_of_dvd_lcm_add AddCommute.addOrderOf_dvd_lcm_add
@[to_additive addOrderOf_add_dvd_mul_addOrderOf]
theorem orderOf_mul_dvd_mul_orderOf : orderOf (x * y) ∣ orderOf x * orderOf y :=
dvd_trans h.orderOf_mul_dvd_lcm (lcm_dvd_mul _ _)
#align commute.order_of_mul_dvd_mul_order_of Commute.orderOf_mul_dvd_mul_orderOf
#align add_commute.add_order_of_add_dvd_mul_add_order_of AddCommute.addOrderOf_add_dvd_mul_addOrderOf
@[to_additive addOrderOf_add_eq_mul_addOrderOf_of_coprime]
theorem orderOf_mul_eq_mul_orderOf_of_coprime (hco : (orderOf x).Coprime (orderOf y)) :
orderOf (x * y) = orderOf x * orderOf y := by
rw [orderOf, ← comp_mul_left]
exact h.function_commute_mul_left.minimalPeriod_of_comp_eq_mul_of_coprime hco
#align commute.order_of_mul_eq_mul_order_of_of_coprime Commute.orderOf_mul_eq_mul_orderOf_of_coprime
#align add_commute.add_order_of_add_eq_mul_add_order_of_of_coprime AddCommute.addOrderOf_add_eq_mul_addOrderOf_of_coprime
/-- Commuting elements of finite order are closed under multiplication. -/
@[to_additive "Commuting elements of finite additive order are closed under addition."]
theorem isOfFinOrder_mul (hx : IsOfFinOrder x) (hy : IsOfFinOrder y) : IsOfFinOrder (x * y) :=
orderOf_pos_iff.mp <|
pos_of_dvd_of_pos h.orderOf_mul_dvd_mul_orderOf <| mul_pos hx.orderOf_pos hy.orderOf_pos
#align commute.is_of_fin_order_mul Commute.isOfFinOrder_mul
#align add_commute.is_of_fin_order_add AddCommute.isOfFinAddOrder_add
/-- If each prime factor of `orderOf x` has higher multiplicity in `orderOf y`, and `x` commutes
with `y`, then `x * y` has the same order as `y`. -/
@[to_additive addOrderOf_add_eq_right_of_forall_prime_mul_dvd
"If each prime factor of
`addOrderOf x` has higher multiplicity in `addOrderOf y`, and `x` commutes with `y`,
then `x + y` has the same order as `y`."]
theorem orderOf_mul_eq_right_of_forall_prime_mul_dvd (hy : IsOfFinOrder y)
(hdvd : ∀ p : ℕ, p.Prime → p ∣ orderOf x → p * orderOf x ∣ orderOf y) :
orderOf (x * y) = orderOf y := by
have hoy := hy.orderOf_pos
have hxy := dvd_of_forall_prime_mul_dvd hdvd
apply orderOf_eq_of_pow_and_pow_div_prime hoy <;> simp only [Ne, ← orderOf_dvd_iff_pow_eq_one]
· exact h.orderOf_mul_dvd_lcm.trans (lcm_dvd hxy dvd_rfl)
refine fun p hp hpy hd => hp.ne_one ?_
rw [← Nat.dvd_one, ← mul_dvd_mul_iff_right hoy.ne', one_mul, ← dvd_div_iff hpy]
refine (orderOf_dvd_lcm_mul h).trans (lcm_dvd ((dvd_div_iff hpy).2 ?_) hd)
by_cases h : p ∣ orderOf x
exacts [hdvd p hp h, (hp.coprime_iff_not_dvd.2 h).mul_dvd_of_dvd_of_dvd hpy hxy]
#align commute.order_of_mul_eq_right_of_forall_prime_mul_dvd Commute.orderOf_mul_eq_right_of_forall_prime_mul_dvd
#align add_commute.add_order_of_add_eq_right_of_forall_prime_mul_dvd AddCommute.addOrderOf_add_eq_right_of_forall_prime_mul_dvd
end Commute
section PPrime
variable {x n} {p : ℕ} [hp : Fact p.Prime]
@[to_additive]
theorem orderOf_eq_prime (hg : x ^ p = 1) (hg1 : x ≠ 1) : orderOf x = p :=
minimalPeriod_eq_prime ((isPeriodicPt_mul_iff_pow_eq_one _).mpr hg)
(by rwa [IsFixedPt, mul_one])
#align order_of_eq_prime orderOf_eq_prime
#align add_order_of_eq_prime addOrderOf_eq_prime
@[to_additive addOrderOf_eq_prime_pow]
theorem orderOf_eq_prime_pow (hnot : ¬x ^ p ^ n = 1) (hfin : x ^ p ^ (n + 1) = 1) :
orderOf x = p ^ (n + 1) := by
apply minimalPeriod_eq_prime_pow <;> rwa [isPeriodicPt_mul_iff_pow_eq_one]
#align order_of_eq_prime_pow orderOf_eq_prime_pow
#align add_order_of_eq_prime_pow addOrderOf_eq_prime_pow
@[to_additive exists_addOrderOf_eq_prime_pow_iff]
theorem exists_orderOf_eq_prime_pow_iff :
(∃ k : ℕ, orderOf x = p ^ k) ↔ ∃ m : ℕ, x ^ (p : ℕ) ^ m = 1 :=
⟨fun ⟨k, hk⟩ => ⟨k, by rw [← hk, pow_orderOf_eq_one]⟩, fun ⟨_, hm⟩ => by
obtain ⟨k, _, hk⟩ := (Nat.dvd_prime_pow hp.elim).mp (orderOf_dvd_of_pow_eq_one hm)
exact ⟨k, hk⟩⟩
#align exists_order_of_eq_prime_pow_iff exists_orderOf_eq_prime_pow_iff
#align exists_add_order_of_eq_prime_pow_iff exists_addOrderOf_eq_prime_pow_iff
end PPrime
end Monoid
section CancelMonoid
variable [LeftCancelMonoid G] {x y : G} {a : G} {m n : ℕ}
@[to_additive]
theorem pow_eq_pow_iff_modEq : x ^ n = x ^ m ↔ n ≡ m [MOD orderOf x] := by
wlog hmn : m ≤ n generalizing m n
· rw [eq_comm, ModEq.comm, this (le_of_not_le hmn)]
obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le hmn
rw [← mul_one (x ^ m), pow_add, mul_left_cancel_iff, pow_eq_one_iff_modEq]
exact ⟨fun h => Nat.ModEq.add_left _ h, fun h => Nat.ModEq.add_left_cancel' _ h⟩
#align pow_eq_pow_iff_modeq pow_eq_pow_iff_modEq
#align nsmul_eq_nsmul_iff_modeq nsmul_eq_nsmul_iff_modEq
@[to_additive (attr := simp)]
lemma injective_pow_iff_not_isOfFinOrder : Injective (fun n : ℕ ↦ x ^ n) ↔ ¬IsOfFinOrder x := by
refine ⟨fun h => not_isOfFinOrder_of_injective_pow h, fun h n m hnm => ?_⟩
rwa [pow_eq_pow_iff_modEq, orderOf_eq_zero_iff.mpr h, modEq_zero_iff] at hnm
#align injective_pow_iff_not_is_of_fin_order injective_pow_iff_not_isOfFinOrder
#align injective_nsmul_iff_not_is_of_fin_add_order injective_nsmul_iff_not_isOfFinAddOrder
@[to_additive]
lemma pow_inj_mod {n m : ℕ} : x ^ n = x ^ m ↔ n % orderOf x = m % orderOf x := pow_eq_pow_iff_modEq
#align pow_inj_mod pow_inj_mod
#align nsmul_inj_mod nsmul_inj_mod
@[to_additive]
theorem pow_inj_iff_of_orderOf_eq_zero (h : orderOf x = 0) {n m : ℕ} : x ^ n = x ^ m ↔ n = m := by
rw [pow_eq_pow_iff_modEq, h, modEq_zero_iff]
#align pow_inj_iff_of_order_of_eq_zero pow_inj_iff_of_orderOf_eq_zero
#align nsmul_inj_iff_of_add_order_of_eq_zero nsmul_inj_iff_of_addOrderOf_eq_zero
@[to_additive]
theorem infinite_not_isOfFinOrder {x : G} (h : ¬IsOfFinOrder x) :
{ y : G | ¬IsOfFinOrder y }.Infinite := by
let s := { n | 0 < n }.image fun n : ℕ => x ^ n
have hs : s ⊆ { y : G | ¬IsOfFinOrder y } := by
rintro - ⟨n, hn : 0 < n, rfl⟩ (contra : IsOfFinOrder (x ^ n))
apply h
rw [isOfFinOrder_iff_pow_eq_one] at contra ⊢
obtain ⟨m, hm, hm'⟩ := contra
exact ⟨n * m, mul_pos hn hm, by rwa [pow_mul]⟩
suffices s.Infinite by exact this.mono hs
contrapose! h
have : ¬Injective fun n : ℕ => x ^ n := by
have := Set.not_injOn_infinite_finite_image (Set.Ioi_infinite 0) (Set.not_infinite.mp h)
contrapose! this
exact Set.injOn_of_injective this
rwa [injective_pow_iff_not_isOfFinOrder, Classical.not_not] at this
#align infinite_not_is_of_fin_order infinite_not_isOfFinOrder
#align infinite_not_is_of_fin_add_order infinite_not_isOfFinAddOrder
@[to_additive (attr := simp)]
lemma finite_powers : (powers a : Set G).Finite ↔ IsOfFinOrder a := by
refine ⟨fun h ↦ ?_, IsOfFinOrder.finite_powers⟩
obtain ⟨m, n, hmn, ha⟩ := h.exists_lt_map_eq_of_forall_mem (f := fun n : ℕ ↦ a ^ n)
(fun n ↦ by simp [mem_powers_iff])
refine isOfFinOrder_iff_pow_eq_one.2 ⟨n - m, tsub_pos_iff_lt.2 hmn, ?_⟩
rw [← mul_left_cancel_iff (a := a ^ m), ← pow_add, add_tsub_cancel_of_le hmn.le, ha, mul_one]
@[to_additive (attr := simp)]
lemma infinite_powers : (powers a : Set G).Infinite ↔ ¬ IsOfFinOrder a := finite_powers.not
/-- The equivalence between `Fin (orderOf x)` and `Submonoid.powers x`, sending `i` to `x ^ i`."-/
@[to_additive "The equivalence between `Fin (addOrderOf a)` and
`AddSubmonoid.multiples a`, sending `i` to `i • a`."]
noncomputable def finEquivPowers (x : G) (hx : IsOfFinOrder x) : Fin (orderOf x) ≃ powers x :=
Equiv.ofBijective (fun n ↦ ⟨x ^ (n : ℕ), ⟨n, rfl⟩⟩) ⟨fun ⟨_, h₁⟩ ⟨_, h₂⟩ ij ↦
Fin.ext (pow_injOn_Iio_orderOf h₁ h₂ (Subtype.mk_eq_mk.1 ij)), fun ⟨_, i, rfl⟩ ↦
⟨⟨i % orderOf x, mod_lt _ hx.orderOf_pos⟩, Subtype.eq <| pow_mod_orderOf _ _⟩⟩
#align fin_equiv_powers finEquivPowers
#align fin_equiv_multiples finEquivMultiples
-- This lemma has always been bad, but the linter only noticed after leanprover/lean4#2644.
@[to_additive (attr := simp, nolint simpNF)]
lemma finEquivPowers_apply (x : G) (hx) {n : Fin (orderOf x)} :
finEquivPowers x hx n = ⟨x ^ (n : ℕ), n, rfl⟩ := rfl
#align fin_equiv_powers_apply finEquivPowers_apply
#align fin_equiv_multiples_apply finEquivMultiples_apply
-- This lemma has always been bad, but the linter only noticed after leanprover/lean4#2644.
@[to_additive (attr := simp, nolint simpNF)]
lemma finEquivPowers_symm_apply (x : G) (hx) (n : ℕ) {hn : ∃ m : ℕ, x ^ m = x ^ n} :
(finEquivPowers x hx).symm ⟨x ^ n, hn⟩ = ⟨n % orderOf x, Nat.mod_lt _ hx.orderOf_pos⟩ := by
rw [Equiv.symm_apply_eq, finEquivPowers_apply, Subtype.mk_eq_mk, ← pow_mod_orderOf, Fin.val_mk]
#align fin_equiv_powers_symm_apply finEquivPowers_symm_apply
#align fin_equiv_multiples_symm_apply finEquivMultiples_symm_apply
/-- See also `orderOf_eq_card_powers`. -/
@[to_additive "See also `addOrder_eq_card_multiples`."]
lemma Nat.card_submonoidPowers : Nat.card (powers a) = orderOf a := by
classical
by_cases ha : IsOfFinOrder a
· exact (Nat.card_congr (finEquivPowers _ ha).symm).trans <| by simp
· have := (infinite_powers.2 ha).to_subtype
rw [orderOf_eq_zero ha, Nat.card_eq_zero_of_infinite]
end CancelMonoid
section Group
variable [Group G] {x y : G} {i : ℤ}
/-- Inverses of elements of finite order have finite order. -/
@[to_additive (attr := simp) "Inverses of elements of finite additive order
have finite additive order."]
theorem isOfFinOrder_inv_iff {x : G} : IsOfFinOrder x⁻¹ ↔ IsOfFinOrder x := by
simp [isOfFinOrder_iff_pow_eq_one]
#align is_of_fin_order_inv_iff isOfFinOrder_inv_iff
#align is_of_fin_order_neg_iff isOfFinAddOrder_neg_iff
@[to_additive] alias ⟨IsOfFinOrder.of_inv, IsOfFinOrder.inv⟩ := isOfFinOrder_inv_iff
#align is_of_fin_order.inv IsOfFinOrder.inv
#align is_of_fin_add_order.neg IsOfFinAddOrder.neg
@[to_additive]
theorem orderOf_dvd_iff_zpow_eq_one : (orderOf x : ℤ) ∣ i ↔ x ^ i = 1 := by
rcases Int.eq_nat_or_neg i with ⟨i, rfl | rfl⟩
· rw [Int.natCast_dvd_natCast, orderOf_dvd_iff_pow_eq_one, zpow_natCast]
· rw [dvd_neg, Int.natCast_dvd_natCast, zpow_neg, inv_eq_one, zpow_natCast,
orderOf_dvd_iff_pow_eq_one]
#align order_of_dvd_iff_zpow_eq_one orderOf_dvd_iff_zpow_eq_one
#align add_order_of_dvd_iff_zsmul_eq_zero addOrderOf_dvd_iff_zsmul_eq_zero
@[to_additive (attr := simp)]
theorem orderOf_inv (x : G) : orderOf x⁻¹ = orderOf x := by simp [orderOf_eq_orderOf_iff]
#align order_of_inv orderOf_inv
#align order_of_neg addOrderOf_neg
namespace Subgroup
variable {H : Subgroup G}
@[to_additive (attr := norm_cast)] -- Porting note (#10618): simp can prove this (so removed simp)
lemma orderOf_coe (a : H) : orderOf (a : G) = orderOf a :=
orderOf_injective H.subtype Subtype.coe_injective _
#align order_of_subgroup Subgroup.orderOf_coe
#align order_of_add_subgroup AddSubgroup.addOrderOf_coe
@[to_additive (attr := simp)]
lemma orderOf_mk (a : G) (ha) : orderOf (⟨a, ha⟩ : H) = orderOf a := (orderOf_coe _).symm
end Subgroup
@[to_additive mod_addOrderOf_zsmul]
lemma zpow_mod_orderOf (x : G) (z : ℤ) : x ^ (z % (orderOf x : ℤ)) = x ^ z :=
calc
x ^ (z % (orderOf x : ℤ)) = x ^ (z % orderOf x + orderOf x * (z / orderOf x) : ℤ) := by
simp [zpow_add, zpow_mul, pow_orderOf_eq_one]
_ = x ^ z := by rw [Int.emod_add_ediv]
#align zpow_eq_mod_order_of zpow_mod_orderOf
#align zsmul_eq_mod_add_order_of mod_addOrderOf_zsmul
@[to_additive (attr := simp) zsmul_smul_addOrderOf]
theorem zpow_pow_orderOf : (x ^ i) ^ orderOf x = 1 := by
by_cases h : IsOfFinOrder x
· rw [← zpow_natCast, ← zpow_mul, mul_comm, zpow_mul, zpow_natCast, pow_orderOf_eq_one, one_zpow]
· rw [orderOf_eq_zero h, _root_.pow_zero]
#align zpow_pow_order_of zpow_pow_orderOf
#align zsmul_smul_order_of zsmul_smul_addOrderOf
@[to_additive]
theorem IsOfFinOrder.zpow (h : IsOfFinOrder x) {i : ℤ} : IsOfFinOrder (x ^ i) :=
isOfFinOrder_iff_pow_eq_one.mpr ⟨orderOf x, h.orderOf_pos, zpow_pow_orderOf⟩
#align is_of_fin_order.zpow IsOfFinOrder.zpow
#align is_of_fin_add_order.zsmul IsOfFinAddOrder.zsmul
@[to_additive]
theorem IsOfFinOrder.of_mem_zpowers (h : IsOfFinOrder x) (h' : y ∈ Subgroup.zpowers x) :
IsOfFinOrder y := by
obtain ⟨k, rfl⟩ := Subgroup.mem_zpowers_iff.mp h'
exact h.zpow
#align is_of_fin_order.of_mem_zpowers IsOfFinOrder.of_mem_zpowers
#align is_of_fin_add_order.of_mem_zmultiples IsOfFinAddOrder.of_mem_zmultiples
@[to_additive]
theorem orderOf_dvd_of_mem_zpowers (h : y ∈ Subgroup.zpowers x) : orderOf y ∣ orderOf x := by
obtain ⟨k, rfl⟩ := Subgroup.mem_zpowers_iff.mp h
rw [orderOf_dvd_iff_pow_eq_one]
exact zpow_pow_orderOf
#align order_of_dvd_of_mem_zpowers orderOf_dvd_of_mem_zpowers
#align add_order_of_dvd_of_mem_zmultiples addOrderOf_dvd_of_mem_zmultiples
theorem smul_eq_self_of_mem_zpowers {α : Type*} [MulAction G α] (hx : x ∈ Subgroup.zpowers y)
{a : α} (hs : y • a = a) : x • a = a := by
obtain ⟨k, rfl⟩ := Subgroup.mem_zpowers_iff.mp hx
rw [← MulAction.toPerm_apply, ← MulAction.toPermHom_apply, MonoidHom.map_zpow _ y k,
MulAction.toPermHom_apply]
exact Function.IsFixedPt.perm_zpow (by exact hs) k -- Porting note: help elab'n with `by exact`
#align smul_eq_self_of_mem_zpowers smul_eq_self_of_mem_zpowers
theorem vadd_eq_self_of_mem_zmultiples {α G : Type*} [AddGroup G] [AddAction G α] {x y : G}
(hx : x ∈ AddSubgroup.zmultiples y) {a : α} (hs : y +ᵥ a = a) : x +ᵥ a = a :=
@smul_eq_self_of_mem_zpowers (Multiplicative G) _ _ _ α _ hx a hs
#align vadd_eq_self_of_mem_zmultiples vadd_eq_self_of_mem_zmultiples
attribute [to_additive existing] smul_eq_self_of_mem_zpowers
@[to_additive]
lemma IsOfFinOrder.mem_powers_iff_mem_zpowers (hx : IsOfFinOrder x) :
y ∈ powers x ↔ y ∈ zpowers x :=
⟨fun ⟨n, hn⟩ ↦ ⟨n, by simp_all⟩, fun ⟨i, hi⟩ ↦ ⟨(i % orderOf x).natAbs, by
dsimp only
rwa [← zpow_natCast, Int.natAbs_of_nonneg <| Int.emod_nonneg _ <|
Int.natCast_ne_zero_iff_pos.2 <| hx.orderOf_pos, zpow_mod_orderOf]⟩⟩
@[to_additive]
lemma IsOfFinOrder.powers_eq_zpowers (hx : IsOfFinOrder x) : (powers x : Set G) = zpowers x :=
Set.ext fun _ ↦ hx.mem_powers_iff_mem_zpowers
@[to_additive]
lemma IsOfFinOrder.mem_zpowers_iff_mem_range_orderOf [DecidableEq G] (hx : IsOfFinOrder x) :
y ∈ zpowers x ↔ y ∈ (Finset.range (orderOf x)).image (x ^ ·) :=
hx.mem_powers_iff_mem_zpowers.symm.trans hx.mem_powers_iff_mem_range_orderOf
/-- The equivalence between `Fin (orderOf x)` and `Subgroup.zpowers x`, sending `i` to `x ^ i`. -/
@[to_additive "The equivalence between `Fin (addOrderOf a)` and
`Subgroup.zmultiples a`, sending `i` to `i • a`."]
noncomputable def finEquivZPowers (x : G) (hx : IsOfFinOrder x) :
Fin (orderOf x) ≃ (zpowers x : Set G) :=
(finEquivPowers x hx).trans <| Equiv.Set.ofEq hx.powers_eq_zpowers
#align fin_equiv_zpowers finEquivZPowers
#align fin_equiv_zmultiples finEquivZMultiples
-- This lemma has always been bad, but the linter only noticed after leaprover/lean4#2644.
@[to_additive (attr := simp, nolint simpNF)]
lemma finEquivZPowers_apply (hx) {n : Fin (orderOf x)} :
finEquivZPowers x hx n = ⟨x ^ (n : ℕ), n, zpow_natCast x n⟩ := rfl
#align fin_equiv_zpowers_apply finEquivZPowers_apply
#align fin_equiv_zmultiples_apply finEquivZMultiples_apply
-- This lemma has always been bad, but the linter only noticed after leanprover/lean4#2644.
@[to_additive (attr := simp, nolint simpNF)]
lemma finEquivZPowers_symm_apply (x : G) (hx) (n : ℕ) :
(finEquivZPowers x hx).symm ⟨x ^ n, ⟨n, by simp⟩⟩ =
⟨n % orderOf x, Nat.mod_lt _ hx.orderOf_pos⟩ := by
rw [finEquivZPowers, Equiv.symm_trans_apply]; exact finEquivPowers_symm_apply x _ n
#align fin_equiv_zpowers_symm_apply finEquivZPowers_symm_apply
#align fin_equiv_zmultiples_symm_apply finEquivZMultiples_symm_apply
end Group
section CommMonoid
variable [CommMonoid G] {x y : G}
/-- Elements of finite order are closed under multiplication. -/
@[to_additive "Elements of finite additive order are closed under addition."]
theorem IsOfFinOrder.mul (hx : IsOfFinOrder x) (hy : IsOfFinOrder y) : IsOfFinOrder (x * y) :=
(Commute.all x y).isOfFinOrder_mul hx hy
#align is_of_fin_order.mul IsOfFinOrder.mul
#align is_of_fin_add_order.add IsOfFinAddOrder.add
end CommMonoid
section FiniteMonoid
variable [Monoid G] {x : G} {n : ℕ}
@[to_additive]
theorem sum_card_orderOf_eq_card_pow_eq_one [Fintype G] [DecidableEq G] (hn : n ≠ 0) :
(∑ m ∈ (Finset.range n.succ).filter (· ∣ n),
(Finset.univ.filter fun x : G => orderOf x = m).card) =
(Finset.univ.filter fun x : G => x ^ n = 1).card :=
calc
(∑ m ∈ (Finset.range n.succ).filter (· ∣ n),
(Finset.univ.filter fun x : G => orderOf x = m).card) = _ :=
(Finset.card_biUnion
(by
intros
apply Finset.disjoint_filter.2
rintro _ _ rfl; assumption)).symm
_ = _ :=
congr_arg Finset.card
(Finset.ext
(by
intro x
suffices orderOf x ≤ n ∧ orderOf x ∣ n ↔ x ^ n = 1 by simpa [Nat.lt_succ_iff]
exact
⟨fun h => by
let ⟨m, hm⟩ := h.2
rw [hm, pow_mul, pow_orderOf_eq_one, one_pow], fun h =>
⟨orderOf_le_of_pow_eq_one hn.bot_lt h, orderOf_dvd_of_pow_eq_one h⟩⟩))
#align sum_card_order_of_eq_card_pow_eq_one sum_card_orderOf_eq_card_pow_eq_one
#align sum_card_add_order_of_eq_card_nsmul_eq_zero sum_card_addOrderOf_eq_card_nsmul_eq_zero
@[to_additive]
theorem orderOf_le_card_univ [Fintype G] : orderOf x ≤ Fintype.card G :=
Finset.le_card_of_inj_on_range (x ^ ·) (fun _ _ ↦ Finset.mem_univ _) pow_injOn_Iio_orderOf
#align order_of_le_card_univ orderOf_le_card_univ
#align add_order_of_le_card_univ addOrderOf_le_card_univ
end FiniteMonoid
section FiniteCancelMonoid
variable [LeftCancelMonoid G]
-- TODO: Of course everything also works for `RightCancelMonoid`.
section Finite
variable [Finite G] {x y : G} {n : ℕ}
-- TODO: Use this to show that a finite left cancellative monoid is a group.
@[to_additive]
lemma isOfFinOrder_of_finite (x : G) : IsOfFinOrder x := by
by_contra h; exact infinite_not_isOfFinOrder h <| Set.toFinite _
#align exists_pow_eq_one isOfFinOrder_of_finite
#align exists_nsmul_eq_zero isOfFinAddOrder_of_finite
/-- This is the same as `IsOfFinOrder.orderOf_pos` but with one fewer explicit assumption since this
is automatic in case of a finite cancellative monoid. -/
@[to_additive "This is the same as `IsOfFinAddOrder.addOrderOf_pos` but with one fewer explicit
assumption since this is automatic in case of a finite cancellative additive monoid."]
lemma orderOf_pos (x : G) : 0 < orderOf x := (isOfFinOrder_of_finite x).orderOf_pos
#align order_of_pos orderOf_pos
#align add_order_of_pos addOrderOf_pos
/-- This is the same as `orderOf_pow'` and `orderOf_pow''` but with one assumption less which is
automatic in the case of a finite cancellative monoid. -/
@[to_additive "This is the same as `addOrderOf_nsmul'` and
`addOrderOf_nsmul` but with one assumption less which is automatic in the case of a
finite cancellative additive monoid."]
theorem orderOf_pow (x : G) : orderOf (x ^ n) = orderOf x / gcd (orderOf x) n :=
(isOfFinOrder_of_finite _).orderOf_pow _
#align order_of_pow orderOf_pow
#align add_order_of_nsmul addOrderOf_nsmul
@[to_additive]
theorem mem_powers_iff_mem_range_orderOf [DecidableEq G] :
y ∈ powers x ↔ y ∈ (Finset.range (orderOf x)).image (x ^ ·) :=
Finset.mem_range_iff_mem_finset_range_of_mod_eq' (orderOf_pos x) <| pow_mod_orderOf _
#align mem_powers_iff_mem_range_order_of mem_powers_iff_mem_range_orderOf
#align mem_multiples_iff_mem_range_add_order_of mem_multiples_iff_mem_range_addOrderOf
/-- The equivalence between `Submonoid.powers` of two elements `x, y` of the same order, mapping
`x ^ i` to `y ^ i`. -/
@[to_additive
"The equivalence between `Submonoid.multiples` of two elements `a, b` of the same additive order,
mapping `i • a` to `i • b`."]
noncomputable def powersEquivPowers (h : orderOf x = orderOf y) : powers x ≃ powers y :=
(finEquivPowers x <| isOfFinOrder_of_finite _).symm.trans <|
(finCongr h).trans <| finEquivPowers y <| isOfFinOrder_of_finite _
#align powers_equiv_powers powersEquivPowers
#align multiples_equiv_multiples multiplesEquivMultiples
-- Porting note: the simpNF linter complains that simp can change the LHS to something
-- that looks the same as the current LHS even with `pp.explicit`
@[to_additive (attr := simp, nolint simpNF)]
theorem powersEquivPowers_apply (h : orderOf x = orderOf y) (n : ℕ) :
powersEquivPowers h ⟨x ^ n, n, rfl⟩ = ⟨y ^ n, n, rfl⟩ := by
rw [powersEquivPowers, Equiv.trans_apply, Equiv.trans_apply, finEquivPowers_symm_apply, ←
Equiv.eq_symm_apply, finEquivPowers_symm_apply]
simp [h]
#align powers_equiv_powers_apply powersEquivPowers_apply
#align multiples_equiv_multiples_apply multiplesEquivMultiples_apply
end Finite
variable [Fintype G] {x : G}
@[to_additive]
lemma orderOf_eq_card_powers : orderOf x = Fintype.card (powers x : Set G) :=
(Fintype.card_fin (orderOf x)).symm.trans <|
Fintype.card_eq.2 ⟨finEquivPowers x <| isOfFinOrder_of_finite _⟩
#align order_eq_card_powers orderOf_eq_card_powers
#align add_order_of_eq_card_multiples addOrderOf_eq_card_multiples
end FiniteCancelMonoid
section FiniteGroup
variable [Group G]
section Finite
variable [Finite G] {x y : G}
@[to_additive]
theorem exists_zpow_eq_one (x : G) : ∃ (i : ℤ) (_ : i ≠ 0), x ^ (i : ℤ) = 1 := by
obtain ⟨w, hw1, hw2⟩ := isOfFinOrder_of_finite x
refine ⟨w, Int.natCast_ne_zero.mpr (_root_.ne_of_gt hw1), ?_⟩
rw [zpow_natCast]
exact (isPeriodicPt_mul_iff_pow_eq_one _).mp hw2
#align exists_zpow_eq_one exists_zpow_eq_one
#align exists_zsmul_eq_zero exists_zsmul_eq_zero
@[to_additive]
lemma mem_powers_iff_mem_zpowers : y ∈ powers x ↔ y ∈ zpowers x :=
(isOfFinOrder_of_finite _).mem_powers_iff_mem_zpowers
#align mem_powers_iff_mem_zpowers mem_powers_iff_mem_zpowers
#align mem_multiples_iff_mem_zmultiples mem_multiples_iff_mem_zmultiples
@[to_additive]
lemma powers_eq_zpowers (x : G) : (powers x : Set G) = zpowers x :=
(isOfFinOrder_of_finite _).powers_eq_zpowers
#align powers_eq_zpowers powers_eq_zpowers
#align multiples_eq_zmultiples multiples_eq_zmultiples
@[to_additive]
lemma mem_zpowers_iff_mem_range_orderOf [DecidableEq G] :
y ∈ zpowers x ↔ y ∈ (Finset.range (orderOf x)).image (x ^ ·) :=
(isOfFinOrder_of_finite _).mem_zpowers_iff_mem_range_orderOf
#align mem_zpowers_iff_mem_range_order_of mem_zpowers_iff_mem_range_orderOf
#align mem_zmultiples_iff_mem_range_add_order_of mem_zmultiples_iff_mem_range_addOrderOf
@[to_additive]
theorem zpow_eq_one_iff_modEq {n : ℤ} : x ^ n = 1 ↔ n ≡ 0 [ZMOD orderOf x] := by
rw [Int.modEq_zero_iff_dvd, orderOf_dvd_iff_zpow_eq_one]
#align zpow_eq_one_iff_modeq zpow_eq_one_iff_modEq
#align zsmul_eq_zero_iff_modeq zsmul_eq_zero_iff_modEq
@[to_additive]
theorem zpow_eq_zpow_iff_modEq {m n : ℤ} : x ^ m = x ^ n ↔ m ≡ n [ZMOD orderOf x] := by
rw [← mul_inv_eq_one, ← zpow_sub, zpow_eq_one_iff_modEq, Int.modEq_iff_dvd, Int.modEq_iff_dvd,
zero_sub, neg_sub]
#align zpow_eq_zpow_iff_modeq zpow_eq_zpow_iff_modEq
#align zsmul_eq_zsmul_iff_modeq zsmul_eq_zsmul_iff_modEq
@[to_additive (attr := simp)]
theorem injective_zpow_iff_not_isOfFinOrder : (Injective fun n : ℤ => x ^ n) ↔ ¬IsOfFinOrder x := by
refine ⟨?_, fun h n m hnm => ?_⟩
· simp_rw [isOfFinOrder_iff_pow_eq_one]
rintro h ⟨n, hn, hx⟩
exact Nat.cast_ne_zero.2 hn.ne' (h <| by simpa using hx)
rwa [zpow_eq_zpow_iff_modEq, orderOf_eq_zero_iff.2 h, Nat.cast_zero, Int.modEq_zero_iff] at hnm
#align injective_zpow_iff_not_is_of_fin_order injective_zpow_iff_not_isOfFinOrder
#align injective_zsmul_iff_not_is_of_fin_order injective_zsmul_iff_not_isOfFinAddOrder
/-- The equivalence between `Subgroup.zpowers` of two elements `x, y` of the same order, mapping
`x ^ i` to `y ^ i`. -/
@[to_additive
"The equivalence between `Subgroup.zmultiples` of two elements `a, b` of the same additive order,
mapping `i • a` to `i • b`."]
noncomputable def zpowersEquivZPowers (h : orderOf x = orderOf y) :
(Subgroup.zpowers x : Set G) ≃ (Subgroup.zpowers y : Set G) :=
(finEquivZPowers x <| isOfFinOrder_of_finite _).symm.trans <| (finCongr h).trans <|
finEquivZPowers y <| isOfFinOrder_of_finite _
#align zpowers_equiv_zpowers zpowersEquivZPowers
#align zmultiples_equiv_zmultiples zmultiplesEquivZMultiples
-- Porting note: the simpNF linter complains that simp can change the LHS to something
-- that looks the same as the current LHS even with `pp.explicit`
@[to_additive (attr := simp, nolint simpNF) zmultiples_equiv_zmultiples_apply]
theorem zpowersEquivZPowers_apply (h : orderOf x = orderOf y) (n : ℕ) :
zpowersEquivZPowers h ⟨x ^ n, n, zpow_natCast x n⟩ = ⟨y ^ n, n, zpow_natCast y n⟩ := by
rw [zpowersEquivZPowers, Equiv.trans_apply, Equiv.trans_apply, finEquivZPowers_symm_apply, ←
Equiv.eq_symm_apply, finEquivZPowers_symm_apply]
simp [h]
#align zpowers_equiv_zpowers_apply zpowersEquivZPowers_apply
#align zmultiples_equiv_zmultiples_apply zmultiples_equiv_zmultiples_apply
end Finite
variable [Fintype G] {x : G} {n : ℕ}
/-- See also `Nat.card_addSubgroupZPowers`. -/
@[to_additive "See also `Nat.card_subgroup`."]
theorem Fintype.card_zpowers : Fintype.card (zpowers x) = orderOf x :=
(Fintype.card_eq.2 ⟨finEquivZPowers x <| isOfFinOrder_of_finite _⟩).symm.trans <|
Fintype.card_fin (orderOf x)
#align order_eq_card_zpowers Fintype.card_zpowers
#align add_order_eq_card_zmultiples Fintype.card_zmultiples
@[to_additive]
theorem card_zpowers_le (a : G) {k : ℕ} (k_pos : k ≠ 0)
(ha : a ^ k = 1) : Fintype.card (Subgroup.zpowers a) ≤ k := by
rw [Fintype.card_zpowers]
apply orderOf_le_of_pow_eq_one k_pos.bot_lt ha
open QuotientGroup
@[to_additive]
theorem orderOf_dvd_card : orderOf x ∣ Fintype.card G := by
classical
have ft_prod : Fintype ((G ⧸ zpowers x) × zpowers x) :=
Fintype.ofEquiv G groupEquivQuotientProdSubgroup
have ft_s : Fintype (zpowers x) := @Fintype.prodRight _ _ _ ft_prod _
have ft_cosets : Fintype (G ⧸ zpowers x) :=
@Fintype.prodLeft _ _ _ ft_prod ⟨⟨1, (zpowers x).one_mem⟩⟩
have eq₁ : Fintype.card G = @Fintype.card _ ft_cosets * @Fintype.card _ ft_s :=
calc
Fintype.card G = @Fintype.card _ ft_prod :=
@Fintype.card_congr _ _ _ ft_prod groupEquivQuotientProdSubgroup
_ = @Fintype.card _ (@instFintypeProd _ _ ft_cosets ft_s) :=
congr_arg (@Fintype.card _) <| Subsingleton.elim _ _
_ = @Fintype.card _ ft_cosets * @Fintype.card _ ft_s :=
@Fintype.card_prod _ _ ft_cosets ft_s
have eq₂ : orderOf x = @Fintype.card _ ft_s :=
calc
orderOf x = _ := Fintype.card_zpowers.symm
_ = _ := congr_arg (@Fintype.card _) <| Subsingleton.elim _ _
exact Dvd.intro (@Fintype.card (G ⧸ Subgroup.zpowers x) ft_cosets) (by rw [eq₁, eq₂, mul_comm])
#align order_of_dvd_card_univ orderOf_dvd_card
#align add_order_of_dvd_card_univ addOrderOf_dvd_card
@[to_additive]
theorem orderOf_dvd_natCard {G : Type*} [Group G] (x : G) : orderOf x ∣ Nat.card G := by
cases' fintypeOrInfinite G with h h
· simp only [Nat.card_eq_fintype_card, orderOf_dvd_card]
· simp only [card_eq_zero_of_infinite, dvd_zero]
#align order_of_dvd_nat_card orderOf_dvd_natCard
#align add_order_of_dvd_nat_card addOrderOf_dvd_natCard
@[to_additive]
nonrec lemma Subgroup.orderOf_dvd_natCard (s : Subgroup G) (hx : x ∈ s) :
orderOf x ∣ Nat.card s := by simpa using orderOf_dvd_natCard (⟨x, hx⟩ : s)
@[to_additive]
lemma Subgroup.orderOf_le_card (s : Subgroup G) (hs : (s : Set G).Finite) (hx : x ∈ s) :
orderOf x ≤ Nat.card s :=
le_of_dvd (Nat.card_pos_iff.2 <| ⟨s.coe_nonempty.to_subtype, hs.to_subtype⟩) <|
s.orderOf_dvd_natCard hx
@[to_additive]
lemma Submonoid.orderOf_le_card (s : Submonoid G) (hs : (s : Set G).Finite) (hx : x ∈ s) :
orderOf x ≤ Nat.card s := by
rw [← Nat.card_submonoidPowers]; exact Nat.card_mono hs <| powers_le.2 hx
@[to_additive (attr := simp) card_nsmul_eq_zero']
theorem pow_card_eq_one' {G : Type*} [Group G] {x : G} : x ^ Nat.card G = 1 :=
orderOf_dvd_iff_pow_eq_one.mp <| orderOf_dvd_natCard _
#align pow_card_eq_one' pow_card_eq_one'
#align card_nsmul_eq_zero' card_nsmul_eq_zero'
@[to_additive (attr := simp) card_nsmul_eq_zero]
| Mathlib/GroupTheory/OrderOfElement.lean | 1,077 | 1,078 | theorem pow_card_eq_one : x ^ Fintype.card G = 1 := by |
rw [← Nat.card_eq_fintype_card, pow_card_eq_one']
|
/-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Analysis.BoxIntegral.Partition.Additive
import Mathlib.MeasureTheory.Measure.Lebesgue.Basic
#align_import analysis.box_integral.partition.measure from "leanprover-community/mathlib"@"fd5edc43dc4f10b85abfe544b88f82cf13c5f844"
/-!
# Box-additive functions defined by measures
In this file we prove a few simple facts about rectangular boxes, partitions, and measures:
- given a box `I : Box ι`, its coercion to `Set (ι → ℝ)` and `I.Icc` are measurable sets;
- if `μ` is a locally finite measure, then `(I : Set (ι → ℝ))` and `I.Icc` have finite measure;
- if `μ` is a locally finite measure, then `fun J ↦ (μ J).toReal` is a box additive function.
For the last statement, we both prove it as a proposition and define a bundled
`BoxIntegral.BoxAdditiveMap` function.
## Tags
rectangular box, measure
-/
open Set
noncomputable section
open scoped ENNReal Classical BoxIntegral
variable {ι : Type*}
namespace BoxIntegral
open MeasureTheory
namespace Box
variable (I : Box ι)
theorem measure_Icc_lt_top (μ : Measure (ι → ℝ)) [IsLocallyFiniteMeasure μ] : μ (Box.Icc I) < ∞ :=
show μ (Icc I.lower I.upper) < ∞ from I.isCompact_Icc.measure_lt_top
#align box_integral.box.measure_Icc_lt_top BoxIntegral.Box.measure_Icc_lt_top
theorem measure_coe_lt_top (μ : Measure (ι → ℝ)) [IsLocallyFiniteMeasure μ] : μ I < ∞ :=
(measure_mono <| coe_subset_Icc).trans_lt (I.measure_Icc_lt_top μ)
#align box_integral.box.measure_coe_lt_top BoxIntegral.Box.measure_coe_lt_top
section Countable
variable [Countable ι]
theorem measurableSet_coe : MeasurableSet (I : Set (ι → ℝ)) := by
rw [coe_eq_pi]
exact MeasurableSet.univ_pi fun i => measurableSet_Ioc
#align box_integral.box.measurable_set_coe BoxIntegral.Box.measurableSet_coe
theorem measurableSet_Icc : MeasurableSet (Box.Icc I) :=
_root_.measurableSet_Icc
#align box_integral.box.measurable_set_Icc BoxIntegral.Box.measurableSet_Icc
theorem measurableSet_Ioo : MeasurableSet (Box.Ioo I) :=
MeasurableSet.univ_pi fun _ => _root_.measurableSet_Ioo
#align box_integral.box.measurable_set_Ioo BoxIntegral.Box.measurableSet_Ioo
end Countable
variable [Fintype ι]
| Mathlib/Analysis/BoxIntegral/Partition/Measure.lean | 74 | 76 | theorem coe_ae_eq_Icc : (I : Set (ι → ℝ)) =ᵐ[volume] Box.Icc I := by |
rw [coe_eq_pi]
exact Measure.univ_pi_Ioc_ae_eq_Icc
|
/-
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.Algebra.CharP.Invertible
import Mathlib.Algebra.Order.Invertible
import Mathlib.Algebra.Order.Module.OrderedSMul
import Mathlib.Algebra.Order.Group.Instances
import Mathlib.LinearAlgebra.AffineSpace.Slope
import Mathlib.LinearAlgebra.AffineSpace.Midpoint
import Mathlib.Tactic.FieldSimp
#align_import linear_algebra.affine_space.ordered from "leanprover-community/mathlib"@"78261225eb5cedc61c5c74ecb44e5b385d13b733"
/-!
# Ordered modules as affine spaces
In this file we prove some theorems about `slope` and `lineMap` in the case when the module `E`
acting on the codomain `PE` of a function is an ordered module over its domain `k`. We also prove
inequalities that can be used to link convexity of a function on an interval to monotonicity of the
slope, see section docstring below for details.
## Implementation notes
We do not introduce the notion of ordered affine spaces (yet?). Instead, we prove various theorems
for an ordered module interpreted as an affine space.
## Tags
affine space, ordered module, slope
-/
open AffineMap
variable {k E PE : Type*}
/-!
### Monotonicity of `lineMap`
In this section we prove that `lineMap a b r` is monotone (strictly or not) in its arguments if
other arguments belong to specific domains.
-/
section OrderedRing
variable [OrderedRing k] [OrderedAddCommGroup E] [Module k E] [OrderedSMul k E]
variable {a a' b b' : E} {r r' : k}
theorem lineMap_mono_left (ha : a ≤ a') (hr : r ≤ 1) : lineMap a b r ≤ lineMap a' b r := by
simp only [lineMap_apply_module]
exact add_le_add_right (smul_le_smul_of_nonneg_left ha (sub_nonneg.2 hr)) _
#align line_map_mono_left lineMap_mono_left
| Mathlib/LinearAlgebra/AffineSpace/Ordered.lean | 57 | 59 | theorem lineMap_strict_mono_left (ha : a < a') (hr : r < 1) : lineMap a b r < lineMap a' b r := by |
simp only [lineMap_apply_module]
exact add_lt_add_right (smul_lt_smul_of_pos_left ha (sub_pos.2 hr)) _
|
/-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Analysis.Convex.Side
import Mathlib.Geometry.Euclidean.Angle.Oriented.Rotation
import Mathlib.Geometry.Euclidean.Angle.Unoriented.Affine
#align_import geometry.euclidean.angle.oriented.affine from "leanprover-community/mathlib"@"46b633fd842bef9469441c0209906f6dddd2b4f5"
/-!
# Oriented angles.
This file defines oriented angles in Euclidean affine spaces.
## Main definitions
* `EuclideanGeometry.oangle`, with notation `∡`, is the oriented angle determined by three
points.
-/
noncomputable section
open FiniteDimensional Complex
open scoped Affine EuclideanGeometry Real RealInnerProductSpace ComplexConjugate
namespace EuclideanGeometry
variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P]
[NormedAddTorsor V P] [hd2 : Fact (finrank ℝ V = 2)] [Module.Oriented ℝ V (Fin 2)]
/-- A fixed choice of positive orientation of Euclidean space `ℝ²` -/
abbrev o := @Module.Oriented.positiveOrientation
/-- The oriented angle at `p₂` between the line segments to `p₁` and `p₃`, modulo `2 * π`. If
either of those points equals `p₂`, this is 0. See `EuclideanGeometry.angle` for the
corresponding unoriented angle definition. -/
def oangle (p₁ p₂ p₃ : P) : Real.Angle :=
o.oangle (p₁ -ᵥ p₂) (p₃ -ᵥ p₂)
#align euclidean_geometry.oangle EuclideanGeometry.oangle
@[inherit_doc] scoped notation "∡" => EuclideanGeometry.oangle
/-- Oriented angles are continuous when neither end point equals the middle point. -/
theorem continuousAt_oangle {x : P × P × P} (hx12 : x.1 ≠ x.2.1) (hx32 : x.2.2 ≠ x.2.1) :
ContinuousAt (fun y : P × P × P => ∡ y.1 y.2.1 y.2.2) x := by
let f : P × P × P → V × V := fun y => (y.1 -ᵥ y.2.1, y.2.2 -ᵥ y.2.1)
have hf1 : (f x).1 ≠ 0 := by simp [hx12]
have hf2 : (f x).2 ≠ 0 := by simp [hx32]
exact (o.continuousAt_oangle hf1 hf2).comp ((continuous_fst.vsub continuous_snd.fst).prod_mk
(continuous_snd.snd.vsub continuous_snd.fst)).continuousAt
#align euclidean_geometry.continuous_at_oangle EuclideanGeometry.continuousAt_oangle
/-- The angle ∡AAB at a point. -/
@[simp]
theorem oangle_self_left (p₁ p₂ : P) : ∡ p₁ p₁ p₂ = 0 := by simp [oangle]
#align euclidean_geometry.oangle_self_left EuclideanGeometry.oangle_self_left
/-- The angle ∡ABB at a point. -/
@[simp]
theorem oangle_self_right (p₁ p₂ : P) : ∡ p₁ p₂ p₂ = 0 := by simp [oangle]
#align euclidean_geometry.oangle_self_right EuclideanGeometry.oangle_self_right
/-- The angle ∡ABA at a point. -/
@[simp]
theorem oangle_self_left_right (p₁ p₂ : P) : ∡ p₁ p₂ p₁ = 0 :=
o.oangle_self _
#align euclidean_geometry.oangle_self_left_right EuclideanGeometry.oangle_self_left_right
/-- If the angle between three points is nonzero, the first two points are not equal. -/
theorem left_ne_of_oangle_ne_zero {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ ≠ 0) : p₁ ≠ p₂ := by
rw [← @vsub_ne_zero V]; exact o.left_ne_zero_of_oangle_ne_zero h
#align euclidean_geometry.left_ne_of_oangle_ne_zero EuclideanGeometry.left_ne_of_oangle_ne_zero
/-- If the angle between three points is nonzero, the last two points are not equal. -/
theorem right_ne_of_oangle_ne_zero {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ ≠ 0) : p₃ ≠ p₂ := by
rw [← @vsub_ne_zero V]; exact o.right_ne_zero_of_oangle_ne_zero h
#align euclidean_geometry.right_ne_of_oangle_ne_zero EuclideanGeometry.right_ne_of_oangle_ne_zero
/-- If the angle between three points is nonzero, the first and third points are not equal. -/
theorem left_ne_right_of_oangle_ne_zero {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ ≠ 0) : p₁ ≠ p₃ := by
rw [← (vsub_left_injective p₂).ne_iff]; exact o.ne_of_oangle_ne_zero h
#align euclidean_geometry.left_ne_right_of_oangle_ne_zero EuclideanGeometry.left_ne_right_of_oangle_ne_zero
/-- If the angle between three points is `π`, the first two points are not equal. -/
theorem left_ne_of_oangle_eq_pi {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = π) : p₁ ≠ p₂ :=
left_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : ∡ p₁ p₂ p₃ ≠ 0)
#align euclidean_geometry.left_ne_of_oangle_eq_pi EuclideanGeometry.left_ne_of_oangle_eq_pi
/-- If the angle between three points is `π`, the last two points are not equal. -/
theorem right_ne_of_oangle_eq_pi {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = π) : p₃ ≠ p₂ :=
right_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : ∡ p₁ p₂ p₃ ≠ 0)
#align euclidean_geometry.right_ne_of_oangle_eq_pi EuclideanGeometry.right_ne_of_oangle_eq_pi
/-- If the angle between three points is `π`, the first and third points are not equal. -/
theorem left_ne_right_of_oangle_eq_pi {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = π) : p₁ ≠ p₃ :=
left_ne_right_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : ∡ p₁ p₂ p₃ ≠ 0)
#align euclidean_geometry.left_ne_right_of_oangle_eq_pi EuclideanGeometry.left_ne_right_of_oangle_eq_pi
/-- If the angle between three points is `π / 2`, the first two points are not equal. -/
theorem left_ne_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (π / 2 : ℝ)) : p₁ ≠ p₂ :=
left_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0)
#align euclidean_geometry.left_ne_of_oangle_eq_pi_div_two EuclideanGeometry.left_ne_of_oangle_eq_pi_div_two
/-- If the angle between three points is `π / 2`, the last two points are not equal. -/
theorem right_ne_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (π / 2 : ℝ)) : p₃ ≠ p₂ :=
right_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0)
#align euclidean_geometry.right_ne_of_oangle_eq_pi_div_two EuclideanGeometry.right_ne_of_oangle_eq_pi_div_two
/-- If the angle between three points is `π / 2`, the first and third points are not equal. -/
theorem left_ne_right_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (π / 2 : ℝ)) :
p₁ ≠ p₃ :=
left_ne_right_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0)
#align euclidean_geometry.left_ne_right_of_oangle_eq_pi_div_two EuclideanGeometry.left_ne_right_of_oangle_eq_pi_div_two
/-- If the angle between three points is `-π / 2`, the first two points are not equal. -/
theorem left_ne_of_oangle_eq_neg_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (-π / 2 : ℝ)) :
p₁ ≠ p₂ :=
left_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0)
#align euclidean_geometry.left_ne_of_oangle_eq_neg_pi_div_two EuclideanGeometry.left_ne_of_oangle_eq_neg_pi_div_two
/-- If the angle between three points is `-π / 2`, the last two points are not equal. -/
theorem right_ne_of_oangle_eq_neg_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (-π / 2 : ℝ)) :
p₃ ≠ p₂ :=
right_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0)
#align euclidean_geometry.right_ne_of_oangle_eq_neg_pi_div_two EuclideanGeometry.right_ne_of_oangle_eq_neg_pi_div_two
/-- If the angle between three points is `-π / 2`, the first and third points are not equal. -/
theorem left_ne_right_of_oangle_eq_neg_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (-π / 2 : ℝ)) :
p₁ ≠ p₃ :=
left_ne_right_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0)
#align euclidean_geometry.left_ne_right_of_oangle_eq_neg_pi_div_two EuclideanGeometry.left_ne_right_of_oangle_eq_neg_pi_div_two
/-- If the sign of the angle between three points is nonzero, the first two points are not
equal. -/
theorem left_ne_of_oangle_sign_ne_zero {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign ≠ 0) : p₁ ≠ p₂ :=
left_ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1
#align euclidean_geometry.left_ne_of_oangle_sign_ne_zero EuclideanGeometry.left_ne_of_oangle_sign_ne_zero
/-- If the sign of the angle between three points is nonzero, the last two points are not
equal. -/
theorem right_ne_of_oangle_sign_ne_zero {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign ≠ 0) : p₃ ≠ p₂ :=
right_ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1
#align euclidean_geometry.right_ne_of_oangle_sign_ne_zero EuclideanGeometry.right_ne_of_oangle_sign_ne_zero
/-- If the sign of the angle between three points is nonzero, the first and third points are not
equal. -/
theorem left_ne_right_of_oangle_sign_ne_zero {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign ≠ 0) : p₁ ≠ p₃ :=
left_ne_right_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1
#align euclidean_geometry.left_ne_right_of_oangle_sign_ne_zero EuclideanGeometry.left_ne_right_of_oangle_sign_ne_zero
/-- If the sign of the angle between three points is positive, the first two points are not
equal. -/
theorem left_ne_of_oangle_sign_eq_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = 1) : p₁ ≠ p₂ :=
left_ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0)
#align euclidean_geometry.left_ne_of_oangle_sign_eq_one EuclideanGeometry.left_ne_of_oangle_sign_eq_one
/-- If the sign of the angle between three points is positive, the last two points are not
equal. -/
theorem right_ne_of_oangle_sign_eq_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = 1) : p₃ ≠ p₂ :=
right_ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0)
#align euclidean_geometry.right_ne_of_oangle_sign_eq_one EuclideanGeometry.right_ne_of_oangle_sign_eq_one
/-- If the sign of the angle between three points is positive, the first and third points are not
equal. -/
theorem left_ne_right_of_oangle_sign_eq_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = 1) : p₁ ≠ p₃ :=
left_ne_right_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0)
#align euclidean_geometry.left_ne_right_of_oangle_sign_eq_one EuclideanGeometry.left_ne_right_of_oangle_sign_eq_one
/-- If the sign of the angle between three points is negative, the first two points are not
equal. -/
theorem left_ne_of_oangle_sign_eq_neg_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = -1) : p₁ ≠ p₂ :=
left_ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0)
#align euclidean_geometry.left_ne_of_oangle_sign_eq_neg_one EuclideanGeometry.left_ne_of_oangle_sign_eq_neg_one
/-- If the sign of the angle between three points is negative, the last two points are not equal.
-/
theorem right_ne_of_oangle_sign_eq_neg_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = -1) : p₃ ≠ p₂ :=
right_ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0)
#align euclidean_geometry.right_ne_of_oangle_sign_eq_neg_one EuclideanGeometry.right_ne_of_oangle_sign_eq_neg_one
/-- If the sign of the angle between three points is negative, the first and third points are not
equal. -/
theorem left_ne_right_of_oangle_sign_eq_neg_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = -1) :
p₁ ≠ p₃ :=
left_ne_right_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0)
#align euclidean_geometry.left_ne_right_of_oangle_sign_eq_neg_one EuclideanGeometry.left_ne_right_of_oangle_sign_eq_neg_one
/-- Reversing the order of the points passed to `oangle` negates the angle. -/
theorem oangle_rev (p₁ p₂ p₃ : P) : ∡ p₃ p₂ p₁ = -∡ p₁ p₂ p₃ :=
o.oangle_rev _ _
#align euclidean_geometry.oangle_rev EuclideanGeometry.oangle_rev
/-- Adding an angle to that with the order of the points reversed results in 0. -/
@[simp]
theorem oangle_add_oangle_rev (p₁ p₂ p₃ : P) : ∡ p₁ p₂ p₃ + ∡ p₃ p₂ p₁ = 0 :=
o.oangle_add_oangle_rev _ _
#align euclidean_geometry.oangle_add_oangle_rev EuclideanGeometry.oangle_add_oangle_rev
/-- An oriented angle is zero if and only if the angle with the order of the points reversed is
zero. -/
theorem oangle_eq_zero_iff_oangle_rev_eq_zero {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ = 0 ↔ ∡ p₃ p₂ p₁ = 0 :=
o.oangle_eq_zero_iff_oangle_rev_eq_zero
#align euclidean_geometry.oangle_eq_zero_iff_oangle_rev_eq_zero EuclideanGeometry.oangle_eq_zero_iff_oangle_rev_eq_zero
/-- An oriented angle is `π` if and only if the angle with the order of the points reversed is
`π`. -/
theorem oangle_eq_pi_iff_oangle_rev_eq_pi {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ = π ↔ ∡ p₃ p₂ p₁ = π :=
o.oangle_eq_pi_iff_oangle_rev_eq_pi
#align euclidean_geometry.oangle_eq_pi_iff_oangle_rev_eq_pi EuclideanGeometry.oangle_eq_pi_iff_oangle_rev_eq_pi
/-- An oriented angle is not zero or `π` if and only if the three points are affinely
independent. -/
theorem oangle_ne_zero_and_ne_pi_iff_affineIndependent {p₁ p₂ p₃ : P} :
∡ p₁ p₂ p₃ ≠ 0 ∧ ∡ p₁ p₂ p₃ ≠ π ↔ AffineIndependent ℝ ![p₁, p₂, p₃] := by
rw [oangle, o.oangle_ne_zero_and_ne_pi_iff_linearIndependent,
affineIndependent_iff_linearIndependent_vsub ℝ _ (1 : Fin 3), ←
linearIndependent_equiv (finSuccAboveEquiv (1 : Fin 3)).toEquiv]
convert Iff.rfl
ext i
fin_cases i <;> rfl
#align euclidean_geometry.oangle_ne_zero_and_ne_pi_iff_affine_independent EuclideanGeometry.oangle_ne_zero_and_ne_pi_iff_affineIndependent
/-- An oriented angle is zero or `π` if and only if the three points are collinear. -/
theorem oangle_eq_zero_or_eq_pi_iff_collinear {p₁ p₂ p₃ : P} :
∡ p₁ p₂ p₃ = 0 ∨ ∡ p₁ p₂ p₃ = π ↔ Collinear ℝ ({p₁, p₂, p₃} : Set P) := by
rw [← not_iff_not, not_or, oangle_ne_zero_and_ne_pi_iff_affineIndependent,
affineIndependent_iff_not_collinear_set]
#align euclidean_geometry.oangle_eq_zero_or_eq_pi_iff_collinear EuclideanGeometry.oangle_eq_zero_or_eq_pi_iff_collinear
/-- An oriented angle has a sign zero if and only if the three points are collinear. -/
theorem oangle_sign_eq_zero_iff_collinear {p₁ p₂ p₃ : P} :
(∡ p₁ p₂ p₃).sign = 0 ↔ Collinear ℝ ({p₁, p₂, p₃} : Set P) := by
rw [Real.Angle.sign_eq_zero_iff, oangle_eq_zero_or_eq_pi_iff_collinear]
/-- If twice the oriented angles between two triples of points are equal, one triple is affinely
independent if and only if the other is. -/
theorem affineIndependent_iff_of_two_zsmul_oangle_eq {p₁ p₂ p₃ p₄ p₅ p₆ : P}
(h : (2 : ℤ) • ∡ p₁ p₂ p₃ = (2 : ℤ) • ∡ p₄ p₅ p₆) :
AffineIndependent ℝ ![p₁, p₂, p₃] ↔ AffineIndependent ℝ ![p₄, p₅, p₆] := by
simp_rw [← oangle_ne_zero_and_ne_pi_iff_affineIndependent, ← Real.Angle.two_zsmul_ne_zero_iff, h]
#align euclidean_geometry.affine_independent_iff_of_two_zsmul_oangle_eq EuclideanGeometry.affineIndependent_iff_of_two_zsmul_oangle_eq
/-- If twice the oriented angles between two triples of points are equal, one triple is collinear
if and only if the other is. -/
theorem collinear_iff_of_two_zsmul_oangle_eq {p₁ p₂ p₃ p₄ p₅ p₆ : P}
(h : (2 : ℤ) • ∡ p₁ p₂ p₃ = (2 : ℤ) • ∡ p₄ p₅ p₆) :
Collinear ℝ ({p₁, p₂, p₃} : Set P) ↔ Collinear ℝ ({p₄, p₅, p₆} : Set P) := by
simp_rw [← oangle_eq_zero_or_eq_pi_iff_collinear, ← Real.Angle.two_zsmul_eq_zero_iff, h]
#align euclidean_geometry.collinear_iff_of_two_zsmul_oangle_eq EuclideanGeometry.collinear_iff_of_two_zsmul_oangle_eq
/-- If corresponding pairs of points in two angles have the same vector span, twice those angles
are equal. -/
theorem two_zsmul_oangle_of_vectorSpan_eq {p₁ p₂ p₃ p₄ p₅ p₆ : P}
(h₁₂₄₅ : vectorSpan ℝ ({p₁, p₂} : Set P) = vectorSpan ℝ ({p₄, p₅} : Set P))
(h₃₂₆₅ : vectorSpan ℝ ({p₃, p₂} : Set P) = vectorSpan ℝ ({p₆, p₅} : Set P)) :
(2 : ℤ) • ∡ p₁ p₂ p₃ = (2 : ℤ) • ∡ p₄ p₅ p₆ := by
simp_rw [vectorSpan_pair] at h₁₂₄₅ h₃₂₆₅
exact o.two_zsmul_oangle_of_span_eq_of_span_eq h₁₂₄₅ h₃₂₆₅
#align euclidean_geometry.two_zsmul_oangle_of_vector_span_eq EuclideanGeometry.two_zsmul_oangle_of_vectorSpan_eq
/-- If the lines determined by corresponding pairs of points in two angles are parallel, twice
those angles are equal. -/
theorem two_zsmul_oangle_of_parallel {p₁ p₂ p₃ p₄ p₅ p₆ : P}
(h₁₂₄₅ : line[ℝ, p₁, p₂] ∥ line[ℝ, p₄, p₅]) (h₃₂₆₅ : line[ℝ, p₃, p₂] ∥ line[ℝ, p₆, p₅]) :
(2 : ℤ) • ∡ p₁ p₂ p₃ = (2 : ℤ) • ∡ p₄ p₅ p₆ := by
rw [AffineSubspace.affineSpan_pair_parallel_iff_vectorSpan_eq] at h₁₂₄₅ h₃₂₆₅
exact two_zsmul_oangle_of_vectorSpan_eq h₁₂₄₅ h₃₂₆₅
#align euclidean_geometry.two_zsmul_oangle_of_parallel EuclideanGeometry.two_zsmul_oangle_of_parallel
/-- Given three points not equal to `p`, the angle between the first and the second at `p` plus
the angle between the second and the third equals the angle between the first and the third. -/
@[simp]
theorem oangle_add {p p₁ p₂ p₃ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) (hp₃ : p₃ ≠ p) :
∡ p₁ p p₂ + ∡ p₂ p p₃ = ∡ p₁ p p₃ :=
o.oangle_add (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) (vsub_ne_zero.2 hp₃)
#align euclidean_geometry.oangle_add EuclideanGeometry.oangle_add
/-- Given three points not equal to `p`, the angle between the second and the third at `p` plus
the angle between the first and the second equals the angle between the first and the third. -/
@[simp]
theorem oangle_add_swap {p p₁ p₂ p₃ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) (hp₃ : p₃ ≠ p) :
∡ p₂ p p₃ + ∡ p₁ p p₂ = ∡ p₁ p p₃ :=
o.oangle_add_swap (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) (vsub_ne_zero.2 hp₃)
#align euclidean_geometry.oangle_add_swap EuclideanGeometry.oangle_add_swap
/-- Given three points not equal to `p`, the angle between the first and the third at `p` minus
the angle between the first and the second equals the angle between the second and the third. -/
@[simp]
theorem oangle_sub_left {p p₁ p₂ p₃ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) (hp₃ : p₃ ≠ p) :
∡ p₁ p p₃ - ∡ p₁ p p₂ = ∡ p₂ p p₃ :=
o.oangle_sub_left (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) (vsub_ne_zero.2 hp₃)
#align euclidean_geometry.oangle_sub_left EuclideanGeometry.oangle_sub_left
/-- Given three points not equal to `p`, the angle between the first and the third at `p` minus
the angle between the second and the third equals the angle between the first and the second. -/
@[simp]
theorem oangle_sub_right {p p₁ p₂ p₃ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) (hp₃ : p₃ ≠ p) :
∡ p₁ p p₃ - ∡ p₂ p p₃ = ∡ p₁ p p₂ :=
o.oangle_sub_right (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) (vsub_ne_zero.2 hp₃)
#align euclidean_geometry.oangle_sub_right EuclideanGeometry.oangle_sub_right
/-- Given three points not equal to `p`, adding the angles between them at `p` in cyclic order
results in 0. -/
@[simp]
theorem oangle_add_cyc3 {p p₁ p₂ p₃ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) (hp₃ : p₃ ≠ p) :
∡ p₁ p p₂ + ∡ p₂ p p₃ + ∡ p₃ p p₁ = 0 :=
o.oangle_add_cyc3 (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) (vsub_ne_zero.2 hp₃)
#align euclidean_geometry.oangle_add_cyc3 EuclideanGeometry.oangle_add_cyc3
/-- Pons asinorum, oriented angle-at-point form. -/
theorem oangle_eq_oangle_of_dist_eq {p₁ p₂ p₃ : P} (h : dist p₁ p₂ = dist p₁ p₃) :
∡ p₁ p₂ p₃ = ∡ p₂ p₃ p₁ := by
simp_rw [dist_eq_norm_vsub V] at h
rw [oangle, oangle, ← vsub_sub_vsub_cancel_left p₃ p₂ p₁, ← vsub_sub_vsub_cancel_left p₂ p₃ p₁,
o.oangle_sub_eq_oangle_sub_rev_of_norm_eq h]
#align euclidean_geometry.oangle_eq_oangle_of_dist_eq EuclideanGeometry.oangle_eq_oangle_of_dist_eq
/-- The angle at the apex of an isosceles triangle is `π` minus twice a base angle, oriented
angle-at-point form. -/
theorem oangle_eq_pi_sub_two_zsmul_oangle_of_dist_eq {p₁ p₂ p₃ : P} (hn : p₂ ≠ p₃)
(h : dist p₁ p₂ = dist p₁ p₃) : ∡ p₃ p₁ p₂ = π - (2 : ℤ) • ∡ p₁ p₂ p₃ := by
simp_rw [dist_eq_norm_vsub V] at h
rw [oangle, oangle]
convert o.oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq _ h using 1
· rw [← neg_vsub_eq_vsub_rev p₁ p₃, ← neg_vsub_eq_vsub_rev p₁ p₂, o.oangle_neg_neg]
· rw [← o.oangle_sub_eq_oangle_sub_rev_of_norm_eq h]; simp
· simpa using hn
#align euclidean_geometry.oangle_eq_pi_sub_two_zsmul_oangle_of_dist_eq EuclideanGeometry.oangle_eq_pi_sub_two_zsmul_oangle_of_dist_eq
/-- A base angle of an isosceles triangle is acute, oriented angle-at-point form. -/
theorem abs_oangle_right_toReal_lt_pi_div_two_of_dist_eq {p₁ p₂ p₃ : P}
(h : dist p₁ p₂ = dist p₁ p₃) : |(∡ p₁ p₂ p₃).toReal| < π / 2 := by
simp_rw [dist_eq_norm_vsub V] at h
rw [oangle, ← vsub_sub_vsub_cancel_left p₃ p₂ p₁]
exact o.abs_oangle_sub_right_toReal_lt_pi_div_two h
#align euclidean_geometry.abs_oangle_right_to_real_lt_pi_div_two_of_dist_eq EuclideanGeometry.abs_oangle_right_toReal_lt_pi_div_two_of_dist_eq
/-- A base angle of an isosceles triangle is acute, oriented angle-at-point form. -/
theorem abs_oangle_left_toReal_lt_pi_div_two_of_dist_eq {p₁ p₂ p₃ : P}
(h : dist p₁ p₂ = dist p₁ p₃) : |(∡ p₂ p₃ p₁).toReal| < π / 2 :=
oangle_eq_oangle_of_dist_eq h ▸ abs_oangle_right_toReal_lt_pi_div_two_of_dist_eq h
#align euclidean_geometry.abs_oangle_left_to_real_lt_pi_div_two_of_dist_eq EuclideanGeometry.abs_oangle_left_toReal_lt_pi_div_two_of_dist_eq
/-- The cosine of the oriented angle at `p` between two points not equal to `p` equals that of the
unoriented angle. -/
theorem cos_oangle_eq_cos_angle {p p₁ p₂ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) :
Real.Angle.cos (∡ p₁ p p₂) = Real.cos (∠ p₁ p p₂) :=
o.cos_oangle_eq_cos_angle (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂)
#align euclidean_geometry.cos_oangle_eq_cos_angle EuclideanGeometry.cos_oangle_eq_cos_angle
/-- The oriented angle at `p` between two points not equal to `p` is plus or minus the unoriented
angle. -/
theorem oangle_eq_angle_or_eq_neg_angle {p p₁ p₂ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) :
∡ p₁ p p₂ = ∠ p₁ p p₂ ∨ ∡ p₁ p p₂ = -∠ p₁ p p₂ :=
o.oangle_eq_angle_or_eq_neg_angle (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂)
#align euclidean_geometry.oangle_eq_angle_or_eq_neg_angle EuclideanGeometry.oangle_eq_angle_or_eq_neg_angle
/-- The unoriented angle at `p` between two points not equal to `p` is the absolute value of the
oriented angle. -/
theorem angle_eq_abs_oangle_toReal {p p₁ p₂ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) :
∠ p₁ p p₂ = |(∡ p₁ p p₂).toReal| :=
o.angle_eq_abs_oangle_toReal (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂)
#align euclidean_geometry.angle_eq_abs_oangle_to_real EuclideanGeometry.angle_eq_abs_oangle_toReal
/-- If the sign of the oriented angle at `p` between two points is zero, either one of the points
equals `p` or the unoriented angle is 0 or π. -/
theorem eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero {p p₁ p₂ : P}
(h : (∡ p₁ p p₂).sign = 0) : p₁ = p ∨ p₂ = p ∨ ∠ p₁ p p₂ = 0 ∨ ∠ p₁ p p₂ = π := by
convert o.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero h <;> simp
#align euclidean_geometry.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero EuclideanGeometry.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero
/-- If two unoriented angles are equal, and the signs of the corresponding oriented angles are
equal, then the oriented angles are equal (even in degenerate cases). -/
theorem oangle_eq_of_angle_eq_of_sign_eq {p₁ p₂ p₃ p₄ p₅ p₆ : P} (h : ∠ p₁ p₂ p₃ = ∠ p₄ p₅ p₆)
(hs : (∡ p₁ p₂ p₃).sign = (∡ p₄ p₅ p₆).sign) : ∡ p₁ p₂ p₃ = ∡ p₄ p₅ p₆ :=
o.oangle_eq_of_angle_eq_of_sign_eq h hs
#align euclidean_geometry.oangle_eq_of_angle_eq_of_sign_eq EuclideanGeometry.oangle_eq_of_angle_eq_of_sign_eq
/-- If the signs of two nondegenerate oriented angles between points are equal, the oriented
angles are equal if and only if the unoriented angles are equal. -/
theorem angle_eq_iff_oangle_eq_of_sign_eq {p₁ p₂ p₃ p₄ p₅ p₆ : P} (hp₁ : p₁ ≠ p₂) (hp₃ : p₃ ≠ p₂)
(hp₄ : p₄ ≠ p₅) (hp₆ : p₆ ≠ p₅) (hs : (∡ p₁ p₂ p₃).sign = (∡ p₄ p₅ p₆).sign) :
∠ p₁ p₂ p₃ = ∠ p₄ p₅ p₆ ↔ ∡ p₁ p₂ p₃ = ∡ p₄ p₅ p₆ :=
o.angle_eq_iff_oangle_eq_of_sign_eq (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₃) (vsub_ne_zero.2 hp₄)
(vsub_ne_zero.2 hp₆) hs
#align euclidean_geometry.angle_eq_iff_oangle_eq_of_sign_eq EuclideanGeometry.angle_eq_iff_oangle_eq_of_sign_eq
/-- The oriented angle between three points equals the unoriented angle if the sign is
positive. -/
theorem oangle_eq_angle_of_sign_eq_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = 1) :
∡ p₁ p₂ p₃ = ∠ p₁ p₂ p₃ :=
o.oangle_eq_angle_of_sign_eq_one h
#align euclidean_geometry.oangle_eq_angle_of_sign_eq_one EuclideanGeometry.oangle_eq_angle_of_sign_eq_one
/-- The oriented angle between three points equals minus the unoriented angle if the sign is
negative. -/
theorem oangle_eq_neg_angle_of_sign_eq_neg_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = -1) :
∡ p₁ p₂ p₃ = -∠ p₁ p₂ p₃ :=
o.oangle_eq_neg_angle_of_sign_eq_neg_one h
#align euclidean_geometry.oangle_eq_neg_angle_of_sign_eq_neg_one EuclideanGeometry.oangle_eq_neg_angle_of_sign_eq_neg_one
/-- The unoriented angle at `p` between two points not equal to `p` is zero if and only if the
unoriented angle is zero. -/
theorem oangle_eq_zero_iff_angle_eq_zero {p p₁ p₂ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) :
∡ p₁ p p₂ = 0 ↔ ∠ p₁ p p₂ = 0 :=
o.oangle_eq_zero_iff_angle_eq_zero (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂)
#align euclidean_geometry.oangle_eq_zero_iff_angle_eq_zero EuclideanGeometry.oangle_eq_zero_iff_angle_eq_zero
/-- The oriented angle between three points is `π` if and only if the unoriented angle is `π`. -/
theorem oangle_eq_pi_iff_angle_eq_pi {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ = π ↔ ∠ p₁ p₂ p₃ = π :=
o.oangle_eq_pi_iff_angle_eq_pi
#align euclidean_geometry.oangle_eq_pi_iff_angle_eq_pi EuclideanGeometry.oangle_eq_pi_iff_angle_eq_pi
/-- If the oriented angle between three points is `π / 2`, so is the unoriented angle. -/
theorem angle_eq_pi_div_two_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) :
∠ p₁ p₂ p₃ = π / 2 := by
rw [angle, ← InnerProductGeometry.inner_eq_zero_iff_angle_eq_pi_div_two]
exact o.inner_eq_zero_of_oangle_eq_pi_div_two h
#align euclidean_geometry.angle_eq_pi_div_two_of_oangle_eq_pi_div_two EuclideanGeometry.angle_eq_pi_div_two_of_oangle_eq_pi_div_two
/-- If the oriented angle between three points is `π / 2`, so is the unoriented angle
(reversed). -/
theorem angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) :
∠ p₃ p₂ p₁ = π / 2 := by
rw [angle_comm]
exact angle_eq_pi_div_two_of_oangle_eq_pi_div_two h
#align euclidean_geometry.angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two EuclideanGeometry.angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two
/-- If the oriented angle between three points is `-π / 2`, the unoriented angle is `π / 2`. -/
theorem angle_eq_pi_div_two_of_oangle_eq_neg_pi_div_two {p₁ p₂ p₃ : P}
(h : ∡ p₁ p₂ p₃ = ↑(-π / 2)) : ∠ p₁ p₂ p₃ = π / 2 := by
rw [angle, ← InnerProductGeometry.inner_eq_zero_iff_angle_eq_pi_div_two]
exact o.inner_eq_zero_of_oangle_eq_neg_pi_div_two h
#align euclidean_geometry.angle_eq_pi_div_two_of_oangle_eq_neg_pi_div_two EuclideanGeometry.angle_eq_pi_div_two_of_oangle_eq_neg_pi_div_two
/-- If the oriented angle between three points is `-π / 2`, the unoriented angle (reversed) is
`π / 2`. -/
theorem angle_rev_eq_pi_div_two_of_oangle_eq_neg_pi_div_two {p₁ p₂ p₃ : P}
(h : ∡ p₁ p₂ p₃ = ↑(-π / 2)) : ∠ p₃ p₂ p₁ = π / 2 := by
rw [angle_comm]
exact angle_eq_pi_div_two_of_oangle_eq_neg_pi_div_two h
#align euclidean_geometry.angle_rev_eq_pi_div_two_of_oangle_eq_neg_pi_div_two EuclideanGeometry.angle_rev_eq_pi_div_two_of_oangle_eq_neg_pi_div_two
/-- Swapping the first and second points in an oriented angle negates the sign of that angle. -/
theorem oangle_swap₁₂_sign (p₁ p₂ p₃ : P) : -(∡ p₁ p₂ p₃).sign = (∡ p₂ p₁ p₃).sign := by
rw [eq_comm, oangle, oangle, ← o.oangle_neg_neg, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev, ←
vsub_sub_vsub_cancel_left p₁ p₃ p₂, ← neg_vsub_eq_vsub_rev p₃ p₂, sub_eq_add_neg,
neg_vsub_eq_vsub_rev p₂ p₁, add_comm, ← @neg_one_smul ℝ]
nth_rw 2 [← one_smul ℝ (p₁ -ᵥ p₂)]
rw [o.oangle_sign_smul_add_smul_right]
simp
#align euclidean_geometry.oangle_swap₁₂_sign EuclideanGeometry.oangle_swap₁₂_sign
/-- Swapping the first and third points in an oriented angle negates the sign of that angle. -/
theorem oangle_swap₁₃_sign (p₁ p₂ p₃ : P) : -(∡ p₁ p₂ p₃).sign = (∡ p₃ p₂ p₁).sign := by
rw [oangle_rev, Real.Angle.sign_neg, neg_neg]
#align euclidean_geometry.oangle_swap₁₃_sign EuclideanGeometry.oangle_swap₁₃_sign
/-- Swapping the second and third points in an oriented angle negates the sign of that angle. -/
| Mathlib/Geometry/Euclidean/Angle/Oriented/Affine.lean | 465 | 466 | theorem oangle_swap₂₃_sign (p₁ p₂ p₃ : P) : -(∡ p₁ p₂ p₃).sign = (∡ p₁ p₃ p₂).sign := by |
rw [oangle_swap₁₃_sign, ← oangle_swap₁₂_sign, oangle_swap₁₃_sign]
|
/-
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.Algebra.MvPolynomial.Equiv
import Mathlib.Algebra.MvPolynomial.Supported
import Mathlib.LinearAlgebra.LinearIndependent
import Mathlib.RingTheory.Adjoin.Basic
import Mathlib.RingTheory.Algebraic
import Mathlib.RingTheory.MvPolynomial.Basic
#align_import ring_theory.algebraic_independent from "leanprover-community/mathlib"@"949dc57e616a621462062668c9f39e4e17b64b69"
/-!
# Algebraic Independence
This file defines algebraic independence of a family of element of an `R` algebra.
## Main definitions
* `AlgebraicIndependent` - `AlgebraicIndependent R x` states the family of elements `x`
is algebraically independent over `R`, meaning that the canonical map out of the multivariable
polynomial ring is injective.
* `AlgebraicIndependent.repr` - The canonical map from the subalgebra generated by an
algebraic independent family into the polynomial ring.
## References
* [Stacks: Transcendence](https://stacks.math.columbia.edu/tag/030D)
## TODO
Define the transcendence degree and show it is independent of the choice of a
transcendence basis.
## Tags
transcendence basis, transcendence degree, transcendence
-/
noncomputable section
open Function Set Subalgebra MvPolynomial Algebra
open scoped Classical
universe x u v w
variable {ι : Type*} {ι' : Type*} (R : Type*) {K : Type*}
variable {A : Type*} {A' A'' : Type*} {V : Type u} {V' : Type*}
variable (x : ι → A)
variable [CommRing R] [CommRing A] [CommRing A'] [CommRing A'']
variable [Algebra R A] [Algebra R A'] [Algebra R A'']
variable {a b : R}
/-- `AlgebraicIndependent R x` states the family of elements `x`
is algebraically independent over `R`, meaning that the canonical
map out of the multivariable polynomial ring is injective. -/
def AlgebraicIndependent : Prop :=
Injective (MvPolynomial.aeval x : MvPolynomial ι R →ₐ[R] A)
#align algebraic_independent AlgebraicIndependent
variable {R} {x}
theorem algebraicIndependent_iff_ker_eq_bot :
AlgebraicIndependent R x ↔
RingHom.ker (MvPolynomial.aeval x : MvPolynomial ι R →ₐ[R] A).toRingHom = ⊥ :=
RingHom.injective_iff_ker_eq_bot _
#align algebraic_independent_iff_ker_eq_bot algebraicIndependent_iff_ker_eq_bot
theorem algebraicIndependent_iff :
AlgebraicIndependent R x ↔
∀ p : MvPolynomial ι R, MvPolynomial.aeval (x : ι → A) p = 0 → p = 0 :=
injective_iff_map_eq_zero _
#align algebraic_independent_iff algebraicIndependent_iff
theorem AlgebraicIndependent.eq_zero_of_aeval_eq_zero (h : AlgebraicIndependent R x) :
∀ p : MvPolynomial ι R, MvPolynomial.aeval (x : ι → A) p = 0 → p = 0 :=
algebraicIndependent_iff.1 h
#align algebraic_independent.eq_zero_of_aeval_eq_zero AlgebraicIndependent.eq_zero_of_aeval_eq_zero
theorem algebraicIndependent_iff_injective_aeval :
AlgebraicIndependent R x ↔ Injective (MvPolynomial.aeval x : MvPolynomial ι R →ₐ[R] A) :=
Iff.rfl
#align algebraic_independent_iff_injective_aeval algebraicIndependent_iff_injective_aeval
@[simp]
theorem algebraicIndependent_empty_type_iff [IsEmpty ι] :
AlgebraicIndependent R x ↔ Injective (algebraMap R A) := by
have : aeval x = (Algebra.ofId R A).comp (@isEmptyAlgEquiv R ι _ _).toAlgHom := by
ext i
exact IsEmpty.elim' ‹IsEmpty ι› i
rw [AlgebraicIndependent, this, ← Injective.of_comp_iff' _ (@isEmptyAlgEquiv R ι _ _).bijective]
rfl
#align algebraic_independent_empty_type_iff algebraicIndependent_empty_type_iff
namespace AlgebraicIndependent
variable (hx : AlgebraicIndependent R x)
theorem algebraMap_injective : Injective (algebraMap R A) := by
simpa [Function.comp] using
(Injective.of_comp_iff (algebraicIndependent_iff_injective_aeval.1 hx) MvPolynomial.C).2
(MvPolynomial.C_injective _ _)
#align algebraic_independent.algebra_map_injective AlgebraicIndependent.algebraMap_injective
theorem linearIndependent : LinearIndependent R x := by
rw [linearIndependent_iff_injective_total]
have : Finsupp.total ι A R x =
(MvPolynomial.aeval x).toLinearMap.comp (Finsupp.total ι _ R X) := by
ext
simp
rw [this]
refine hx.comp ?_
rw [← linearIndependent_iff_injective_total]
exact linearIndependent_X _ _
#align algebraic_independent.linear_independent AlgebraicIndependent.linearIndependent
protected theorem injective [Nontrivial R] : Injective x :=
hx.linearIndependent.injective
#align algebraic_independent.injective AlgebraicIndependent.injective
theorem ne_zero [Nontrivial R] (i : ι) : x i ≠ 0 :=
hx.linearIndependent.ne_zero i
#align algebraic_independent.ne_zero AlgebraicIndependent.ne_zero
theorem comp (f : ι' → ι) (hf : Function.Injective f) : AlgebraicIndependent R (x ∘ f) := by
intro p q
simpa [aeval_rename, (rename_injective f hf).eq_iff] using @hx (rename f p) (rename f q)
#align algebraic_independent.comp AlgebraicIndependent.comp
theorem coe_range : AlgebraicIndependent R ((↑) : range x → A) := by
simpa using hx.comp _ (rangeSplitting_injective x)
#align algebraic_independent.coe_range AlgebraicIndependent.coe_range
theorem map {f : A →ₐ[R] A'} (hf_inj : Set.InjOn f (adjoin R (range x))) :
AlgebraicIndependent R (f ∘ x) := by
have : aeval (f ∘ x) = f.comp (aeval x) := by ext; simp
have h : ∀ p : MvPolynomial ι R, aeval x p ∈ (@aeval R _ _ _ _ _ ((↑) : range x → A)).range := by
intro p
rw [AlgHom.mem_range]
refine ⟨MvPolynomial.rename (codRestrict x (range x) mem_range_self) p, ?_⟩
simp [Function.comp, aeval_rename]
intro x y hxy
rw [this] at hxy
rw [adjoin_eq_range] at hf_inj
exact hx (hf_inj (h x) (h y) hxy)
#align algebraic_independent.map AlgebraicIndependent.map
theorem map' {f : A →ₐ[R] A'} (hf_inj : Injective f) : AlgebraicIndependent R (f ∘ x) :=
hx.map hf_inj.injOn
#align algebraic_independent.map' AlgebraicIndependent.map'
theorem of_comp (f : A →ₐ[R] A') (hfv : AlgebraicIndependent R (f ∘ x)) :
AlgebraicIndependent R x := by
have : aeval (f ∘ x) = f.comp (aeval x) := by ext; simp
rw [AlgebraicIndependent, this, AlgHom.coe_comp] at hfv
exact hfv.of_comp
#align algebraic_independent.of_comp AlgebraicIndependent.of_comp
end AlgebraicIndependent
open AlgebraicIndependent
theorem AlgHom.algebraicIndependent_iff (f : A →ₐ[R] A') (hf : Injective f) :
AlgebraicIndependent R (f ∘ x) ↔ AlgebraicIndependent R x :=
⟨fun h => h.of_comp f, fun h => h.map hf.injOn⟩
#align alg_hom.algebraic_independent_iff AlgHom.algebraicIndependent_iff
@[nontriviality]
theorem algebraicIndependent_of_subsingleton [Subsingleton R] : AlgebraicIndependent R x :=
algebraicIndependent_iff.2 fun _ _ => Subsingleton.elim _ _
#align algebraic_independent_of_subsingleton algebraicIndependent_of_subsingleton
theorem algebraicIndependent_equiv (e : ι ≃ ι') {f : ι' → A} :
AlgebraicIndependent R (f ∘ e) ↔ AlgebraicIndependent R f :=
⟨fun h => Function.comp_id f ▸ e.self_comp_symm ▸ h.comp _ e.symm.injective,
fun h => h.comp _ e.injective⟩
#align algebraic_independent_equiv algebraicIndependent_equiv
theorem algebraicIndependent_equiv' (e : ι ≃ ι') {f : ι' → A} {g : ι → A} (h : f ∘ e = g) :
AlgebraicIndependent R g ↔ AlgebraicIndependent R f :=
h ▸ algebraicIndependent_equiv e
#align algebraic_independent_equiv' algebraicIndependent_equiv'
theorem algebraicIndependent_subtype_range {ι} {f : ι → A} (hf : Injective f) :
AlgebraicIndependent R ((↑) : range f → A) ↔ AlgebraicIndependent R f :=
Iff.symm <| algebraicIndependent_equiv' (Equiv.ofInjective f hf) rfl
#align algebraic_independent_subtype_range algebraicIndependent_subtype_range
alias ⟨AlgebraicIndependent.of_subtype_range, _⟩ := algebraicIndependent_subtype_range
#align algebraic_independent.of_subtype_range AlgebraicIndependent.of_subtype_range
theorem algebraicIndependent_image {ι} {s : Set ι} {f : ι → A} (hf : Set.InjOn f s) :
(AlgebraicIndependent R fun x : s => f x) ↔ AlgebraicIndependent R fun x : f '' s => (x : A) :=
algebraicIndependent_equiv' (Equiv.Set.imageOfInjOn _ _ hf) rfl
#align algebraic_independent_image algebraicIndependent_image
theorem algebraicIndependent_adjoin (hs : AlgebraicIndependent R x) :
@AlgebraicIndependent ι R (adjoin R (range x))
(fun i : ι => ⟨x i, subset_adjoin (mem_range_self i)⟩) _ _ _ :=
AlgebraicIndependent.of_comp (adjoin R (range x)).val hs
#align algebraic_independent_adjoin algebraicIndependent_adjoin
/-- A set of algebraically independent elements in an algebra `A` over a ring `K` is also
algebraically independent over a subring `R` of `K`. -/
theorem AlgebraicIndependent.restrictScalars {K : Type*} [CommRing K] [Algebra R K] [Algebra K A]
[IsScalarTower R K A] (hinj : Function.Injective (algebraMap R K))
(ai : AlgebraicIndependent K x) : AlgebraicIndependent R x := by
have : (aeval x : MvPolynomial ι K →ₐ[K] A).toRingHom.comp (MvPolynomial.map (algebraMap R K)) =
(aeval x : MvPolynomial ι R →ₐ[R] A).toRingHom := by
ext <;> simp [algebraMap_eq_smul_one]
show Injective (aeval x).toRingHom
rw [← this, RingHom.coe_comp]
exact Injective.comp ai (MvPolynomial.map_injective _ hinj)
#align algebraic_independent.restrict_scalars AlgebraicIndependent.restrictScalars
/-- Every finite subset of an algebraically independent set is algebraically independent. -/
theorem algebraicIndependent_finset_map_embedding_subtype (s : Set A)
(li : AlgebraicIndependent R ((↑) : s → A)) (t : Finset s) :
AlgebraicIndependent R ((↑) : Finset.map (Embedding.subtype s) t → A) := by
let f : t.map (Embedding.subtype s) → s := fun x =>
⟨x.1, by
obtain ⟨x, h⟩ := x
rw [Finset.mem_map] at h
obtain ⟨a, _, rfl⟩ := h
simp only [Subtype.coe_prop, Embedding.coe_subtype]⟩
convert AlgebraicIndependent.comp li f _
rintro ⟨x, hx⟩ ⟨y, hy⟩
rw [Finset.mem_map] at hx hy
obtain ⟨a, _, rfl⟩ := hx
obtain ⟨b, _, rfl⟩ := hy
simp only [f, imp_self, Subtype.mk_eq_mk]
#align algebraic_independent_finset_map_embedding_subtype algebraicIndependent_finset_map_embedding_subtype
/-- If every finite set of algebraically independent element has cardinality at most `n`,
then the same is true for arbitrary sets of algebraically independent elements. -/
theorem algebraicIndependent_bounded_of_finset_algebraicIndependent_bounded {n : ℕ}
(H : ∀ s : Finset A, (AlgebraicIndependent R fun i : s => (i : A)) → s.card ≤ n) :
∀ s : Set A, AlgebraicIndependent R ((↑) : s → A) → Cardinal.mk s ≤ n := by
intro s li
apply Cardinal.card_le_of
intro t
rw [← Finset.card_map (Embedding.subtype s)]
apply H
apply algebraicIndependent_finset_map_embedding_subtype _ li
#align algebraic_independent_bounded_of_finset_algebraic_independent_bounded algebraicIndependent_bounded_of_finset_algebraicIndependent_bounded
section Subtype
theorem AlgebraicIndependent.restrict_of_comp_subtype {s : Set ι}
(hs : AlgebraicIndependent R (x ∘ (↑) : s → A)) : AlgebraicIndependent R (s.restrict x) :=
hs
#align algebraic_independent.restrict_of_comp_subtype AlgebraicIndependent.restrict_of_comp_subtype
variable (R A)
theorem algebraicIndependent_empty_iff :
AlgebraicIndependent R ((↑) : (∅ : Set A) → A) ↔ Injective (algebraMap R A) := by simp
#align algebraic_independent_empty_iff algebraicIndependent_empty_iff
variable {R A}
theorem AlgebraicIndependent.mono {t s : Set A} (h : t ⊆ s)
(hx : AlgebraicIndependent R ((↑) : s → A)) : AlgebraicIndependent R ((↑) : t → A) := by
simpa [Function.comp] using hx.comp (inclusion h) (inclusion_injective h)
#align algebraic_independent.mono AlgebraicIndependent.mono
end Subtype
theorem AlgebraicIndependent.to_subtype_range {ι} {f : ι → A} (hf : AlgebraicIndependent R f) :
AlgebraicIndependent R ((↑) : range f → A) := by
nontriviality R
rwa [algebraicIndependent_subtype_range hf.injective]
#align algebraic_independent.to_subtype_range AlgebraicIndependent.to_subtype_range
theorem AlgebraicIndependent.to_subtype_range' {ι} {f : ι → A} (hf : AlgebraicIndependent R f) {t}
(ht : range f = t) : AlgebraicIndependent R ((↑) : t → A) :=
ht ▸ hf.to_subtype_range
#align algebraic_independent.to_subtype_range' AlgebraicIndependent.to_subtype_range'
theorem algebraicIndependent_comp_subtype {s : Set ι} :
AlgebraicIndependent R (x ∘ (↑) : s → A) ↔
∀ p ∈ MvPolynomial.supported R s, aeval x p = 0 → p = 0 := by
have : (aeval (x ∘ (↑) : s → A) : _ →ₐ[R] _) = (aeval x).comp (rename (↑)) := by ext; simp
have : ∀ p : MvPolynomial s R, rename ((↑) : s → ι) p = 0 ↔ p = 0 :=
(injective_iff_map_eq_zero' (rename ((↑) : s → ι) : MvPolynomial s R →ₐ[R] _).toRingHom).1
(rename_injective _ Subtype.val_injective)
simp [algebraicIndependent_iff, supported_eq_range_rename, *]
#align algebraic_independent_comp_subtype algebraicIndependent_comp_subtype
theorem algebraicIndependent_subtype {s : Set A} :
AlgebraicIndependent R ((↑) : s → A) ↔
∀ p : MvPolynomial A R, p ∈ MvPolynomial.supported R s → aeval id p = 0 → p = 0 := by
apply @algebraicIndependent_comp_subtype _ _ _ id
#align algebraic_independent_subtype algebraicIndependent_subtype
theorem algebraicIndependent_of_finite (s : Set A)
(H : ∀ t ⊆ s, t.Finite → AlgebraicIndependent R ((↑) : t → A)) :
AlgebraicIndependent R ((↑) : s → A) :=
algebraicIndependent_subtype.2 fun p hp =>
algebraicIndependent_subtype.1 (H _ (mem_supported.1 hp) (Finset.finite_toSet _)) _ (by simp)
#align algebraic_independent_of_finite algebraicIndependent_of_finite
theorem AlgebraicIndependent.image_of_comp {ι ι'} (s : Set ι) (f : ι → ι') (g : ι' → A)
(hs : AlgebraicIndependent R fun x : s => g (f x)) :
AlgebraicIndependent R fun x : f '' s => g x := by
nontriviality R
have : InjOn f s := injOn_iff_injective.2 hs.injective.of_comp
exact (algebraicIndependent_equiv' (Equiv.Set.imageOfInjOn f s this) rfl).1 hs
#align algebraic_independent.image_of_comp AlgebraicIndependent.image_of_comp
| Mathlib/RingTheory/AlgebraicIndependent.lean | 315 | 318 | theorem AlgebraicIndependent.image {ι} {s : Set ι} {f : ι → A}
(hs : AlgebraicIndependent R fun x : s => f x) :
AlgebraicIndependent R fun x : f '' s => (x : A) := by |
convert AlgebraicIndependent.image_of_comp s f id hs
|
/-
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.Algebra.Category.GroupCat.Abelian
import Mathlib.CategoryTheory.Limits.Shapes.Images
#align_import algebra.category.Group.images from "leanprover-community/mathlib"@"70fd9563a21e7b963887c9360bd29b2393e6225a"
/-!
# The category of commutative additive groups has images.
Note that we don't need to register any of the constructions here as instances, because we get them
from the fact that `AddCommGroupCat` is an abelian category.
-/
open CategoryTheory
open CategoryTheory.Limits
universe u
namespace AddCommGroupCat
set_option linter.uppercaseLean3 false
-- Note that because `injective_of_mono` is currently only proved in `Type 0`,
-- we restrict to the lowest universe here for now.
variable {G H : AddCommGroupCat.{0}} (f : G ⟶ H)
attribute [local ext] Subtype.ext_val
section
-- implementation details of `IsImage` for `AddCommGroupCat`; use the API, not these
/-- the image of a morphism in `AddCommGroupCat` is just the bundling of `AddMonoidHom.range f` -/
def image : AddCommGroupCat :=
AddCommGroupCat.of (AddMonoidHom.range f)
#align AddCommGroup.image AddCommGroupCat.image
/-- the inclusion of `image f` into the target -/
def image.ι : image f ⟶ H :=
f.range.subtype
#align AddCommGroup.image.ι AddCommGroupCat.image.ι
instance : Mono (image.ι f) :=
ConcreteCategory.mono_of_injective (image.ι f) Subtype.val_injective
/-- the corestriction map to the image -/
def factorThruImage : G ⟶ image f :=
f.rangeRestrict
#align AddCommGroup.factor_thru_image AddCommGroupCat.factorThruImage
theorem image.fac : factorThruImage f ≫ image.ι f = f := by
ext
rfl
#align AddCommGroup.image.fac AddCommGroupCat.image.fac
attribute [local simp] image.fac
variable {f}
/-- the universal property for the image factorisation -/
noncomputable def image.lift (F' : MonoFactorisation f) : image f ⟶ F'.I where
toFun := (fun x => F'.e (Classical.indefiniteDescription _ x.2).1 : image f → F'.I)
map_zero' := by
haveI := F'.m_mono
apply injective_of_mono F'.m
change (F'.e ≫ F'.m) _ = _
rw [F'.fac, AddMonoidHom.map_zero]
exact (Classical.indefiniteDescription (fun y => f y = 0) _).2
map_add' := by
intro x y
haveI := F'.m_mono
apply injective_of_mono F'.m
rw [AddMonoidHom.map_add]
change (F'.e ≫ F'.m) _ = (F'.e ≫ F'.m) _ + (F'.e ≫ F'.m) _
rw [F'.fac]
rw [(Classical.indefiniteDescription (fun z => f z = _) _).2]
rw [(Classical.indefiniteDescription (fun z => f z = _) _).2]
rw [(Classical.indefiniteDescription (fun z => f z = _) _).2]
rfl
#align AddCommGroup.image.lift AddCommGroupCat.image.lift
| Mathlib/Algebra/Category/GroupCat/Images.lean | 87 | 91 | theorem image.lift_fac (F' : MonoFactorisation f) : image.lift F' ≫ F'.m = image.ι f := by |
ext x
change (F'.e ≫ F'.m) _ = _
rw [F'.fac, (Classical.indefiniteDescription _ x.2).2]
rfl
|
/-
Copyright (c) 2021 Stuart Presnell. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Stuart Presnell
-/
import Mathlib.Data.Finsupp.Multiset
import Mathlib.Data.Nat.GCD.BigOperators
import Mathlib.Data.Nat.PrimeFin
import Mathlib.NumberTheory.Padics.PadicVal
import Mathlib.Order.Interval.Finset.Nat
#align_import data.nat.factorization.basic from "leanprover-community/mathlib"@"f694c7dead66f5d4c80f446c796a5aad14707f0e"
/-!
# Prime factorizations
`n.factorization` is the finitely supported function `ℕ →₀ ℕ`
mapping each prime factor of `n` to its multiplicity in `n`. For example, since 2000 = 2^4 * 5^3,
* `factorization 2000 2` is 4
* `factorization 2000 5` is 3
* `factorization 2000 k` is 0 for all other `k : ℕ`.
## TODO
* As discussed in this Zulip thread:
https://leanprover.zulipchat.com/#narrow/stream/217875/topic/Multiplicity.20in.20the.20naturals
We have lots of disparate ways of talking about the multiplicity of a prime
in a natural number, including `factors.count`, `padicValNat`, `multiplicity`,
and the material in `Data/PNat/Factors`. Move some of this material to this file,
prove results about the relationships between these definitions,
and (where appropriate) choose a uniform canonical way of expressing these ideas.
* Moreover, the results here should be generalised to an arbitrary unique factorization monoid
with a normalization function, and then deduplicated. The basics of this have been started in
`RingTheory/UniqueFactorizationDomain`.
* Extend the inductions to any `NormalizationMonoid` with unique factorization.
-/
-- Workaround for lean4#2038
attribute [-instance] instBEqNat
open Nat Finset List Finsupp
namespace Nat
variable {a b m n p : ℕ}
/-- `n.factorization` is the finitely supported function `ℕ →₀ ℕ`
mapping each prime factor of `n` to its multiplicity in `n`. -/
def factorization (n : ℕ) : ℕ →₀ ℕ where
support := n.primeFactors
toFun p := if p.Prime then padicValNat p n else 0
mem_support_toFun := by simp [not_or]; aesop
#align nat.factorization Nat.factorization
/-- The support of `n.factorization` is exactly `n.primeFactors`. -/
@[simp] lemma support_factorization (n : ℕ) : (factorization n).support = n.primeFactors := rfl
theorem factorization_def (n : ℕ) {p : ℕ} (pp : p.Prime) : n.factorization p = padicValNat p n := by
simpa [factorization] using absurd pp
#align nat.factorization_def Nat.factorization_def
/-- We can write both `n.factorization p` and `n.factors.count p` to represent the power
of `p` in the factorization of `n`: we declare the former to be the simp-normal form. -/
@[simp]
theorem factors_count_eq {n p : ℕ} : n.factors.count p = n.factorization p := by
rcases n.eq_zero_or_pos with (rfl | hn0)
· simp [factorization, count]
if pp : p.Prime then ?_ else
rw [count_eq_zero_of_not_mem (mt prime_of_mem_factors pp)]
simp [factorization, pp]
simp only [factorization_def _ pp]
apply _root_.le_antisymm
· rw [le_padicValNat_iff_replicate_subperm_factors pp hn0.ne']
exact List.le_count_iff_replicate_sublist.mp le_rfl |>.subperm
· rw [← lt_add_one_iff, lt_iff_not_ge, ge_iff_le,
le_padicValNat_iff_replicate_subperm_factors pp hn0.ne']
intro h
have := h.count_le p
simp at this
#align nat.factors_count_eq Nat.factors_count_eq
theorem factorization_eq_factors_multiset (n : ℕ) :
n.factorization = Multiset.toFinsupp (n.factors : Multiset ℕ) := by
ext p
simp
#align nat.factorization_eq_factors_multiset Nat.factorization_eq_factors_multiset
theorem multiplicity_eq_factorization {n p : ℕ} (pp : p.Prime) (hn : n ≠ 0) :
multiplicity p n = n.factorization p := by
simp [factorization, pp, padicValNat_def' pp.ne_one hn.bot_lt]
#align nat.multiplicity_eq_factorization Nat.multiplicity_eq_factorization
/-! ### Basic facts about factorization -/
@[simp]
theorem factorization_prod_pow_eq_self {n : ℕ} (hn : n ≠ 0) : n.factorization.prod (· ^ ·) = n := by
rw [factorization_eq_factors_multiset n]
simp only [← prod_toMultiset, factorization, Multiset.prod_coe, Multiset.toFinsupp_toMultiset]
exact prod_factors hn
#align nat.factorization_prod_pow_eq_self Nat.factorization_prod_pow_eq_self
theorem eq_of_factorization_eq {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0)
(h : ∀ p : ℕ, a.factorization p = b.factorization p) : a = b :=
eq_of_perm_factors ha hb (by simpa only [List.perm_iff_count, factors_count_eq] using h)
#align nat.eq_of_factorization_eq Nat.eq_of_factorization_eq
/-- Every nonzero natural number has a unique prime factorization -/
theorem factorization_inj : Set.InjOn factorization { x : ℕ | x ≠ 0 } := fun a ha b hb h =>
eq_of_factorization_eq ha hb fun p => by simp [h]
#align nat.factorization_inj Nat.factorization_inj
@[simp]
theorem factorization_zero : factorization 0 = 0 := by ext; simp [factorization]
#align nat.factorization_zero Nat.factorization_zero
@[simp]
theorem factorization_one : factorization 1 = 0 := by ext; simp [factorization]
#align nat.factorization_one Nat.factorization_one
#noalign nat.support_factorization
#align nat.factor_iff_mem_factorization Nat.mem_primeFactors_iff_mem_factors
#align nat.prime_of_mem_factorization Nat.prime_of_mem_primeFactors
#align nat.pos_of_mem_factorization Nat.pos_of_mem_primeFactors
#align nat.le_of_mem_factorization Nat.le_of_mem_primeFactors
/-! ## Lemmas characterising when `n.factorization p = 0` -/
theorem factorization_eq_zero_iff (n p : ℕ) :
n.factorization p = 0 ↔ ¬p.Prime ∨ ¬p ∣ n ∨ n = 0 := by
simp_rw [← not_mem_support_iff, support_factorization, mem_primeFactors, not_and_or, not_ne_iff]
#align nat.factorization_eq_zero_iff Nat.factorization_eq_zero_iff
@[simp]
theorem factorization_eq_zero_of_non_prime (n : ℕ) {p : ℕ} (hp : ¬p.Prime) :
n.factorization p = 0 := by simp [factorization_eq_zero_iff, hp]
#align nat.factorization_eq_zero_of_non_prime Nat.factorization_eq_zero_of_non_prime
theorem factorization_eq_zero_of_not_dvd {n p : ℕ} (h : ¬p ∣ n) : n.factorization p = 0 := by
simp [factorization_eq_zero_iff, h]
#align nat.factorization_eq_zero_of_not_dvd Nat.factorization_eq_zero_of_not_dvd
theorem factorization_eq_zero_of_lt {n p : ℕ} (h : n < p) : n.factorization p = 0 :=
Finsupp.not_mem_support_iff.mp (mt le_of_mem_primeFactors (not_le_of_lt h))
#align nat.factorization_eq_zero_of_lt Nat.factorization_eq_zero_of_lt
@[simp]
theorem factorization_zero_right (n : ℕ) : n.factorization 0 = 0 :=
factorization_eq_zero_of_non_prime _ not_prime_zero
#align nat.factorization_zero_right Nat.factorization_zero_right
@[simp]
theorem factorization_one_right (n : ℕ) : n.factorization 1 = 0 :=
factorization_eq_zero_of_non_prime _ not_prime_one
#align nat.factorization_one_right Nat.factorization_one_right
theorem dvd_of_factorization_pos {n p : ℕ} (hn : n.factorization p ≠ 0) : p ∣ n :=
dvd_of_mem_factors <| mem_primeFactors_iff_mem_factors.1 <| mem_support_iff.2 hn
#align nat.dvd_of_factorization_pos Nat.dvd_of_factorization_pos
theorem Prime.factorization_pos_of_dvd {n p : ℕ} (hp : p.Prime) (hn : n ≠ 0) (h : p ∣ n) :
0 < n.factorization p := by
rwa [← factors_count_eq, count_pos_iff_mem, mem_factors_iff_dvd hn hp]
#align nat.prime.factorization_pos_of_dvd Nat.Prime.factorization_pos_of_dvd
theorem factorization_eq_zero_of_remainder {p r : ℕ} (i : ℕ) (hr : ¬p ∣ r) :
(p * i + r).factorization p = 0 := by
apply factorization_eq_zero_of_not_dvd
rwa [← Nat.dvd_add_iff_right (Dvd.intro i rfl)]
#align nat.factorization_eq_zero_of_remainder Nat.factorization_eq_zero_of_remainder
theorem factorization_eq_zero_iff_remainder {p r : ℕ} (i : ℕ) (pp : p.Prime) (hr0 : r ≠ 0) :
¬p ∣ r ↔ (p * i + r).factorization p = 0 := by
refine ⟨factorization_eq_zero_of_remainder i, fun h => ?_⟩
rw [factorization_eq_zero_iff] at h
contrapose! h
refine ⟨pp, ?_, ?_⟩
· rwa [← Nat.dvd_add_iff_right (dvd_mul_right p i)]
· contrapose! hr0
exact (add_eq_zero_iff.mp hr0).2
#align nat.factorization_eq_zero_iff_remainder Nat.factorization_eq_zero_iff_remainder
/-- The only numbers with empty prime factorization are `0` and `1` -/
theorem factorization_eq_zero_iff' (n : ℕ) : n.factorization = 0 ↔ n = 0 ∨ n = 1 := by
rw [factorization_eq_factors_multiset n]
simp [factorization, AddEquiv.map_eq_zero_iff, Multiset.coe_eq_zero]
#align nat.factorization_eq_zero_iff' Nat.factorization_eq_zero_iff'
/-! ## Lemmas about factorizations of products and powers -/
/-- For nonzero `a` and `b`, the power of `p` in `a * b` is the sum of the powers in `a` and `b` -/
@[simp]
theorem factorization_mul {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) :
(a * b).factorization = a.factorization + b.factorization := by
ext p
simp only [add_apply, ← factors_count_eq, perm_iff_count.mp (perm_factors_mul ha hb) p,
count_append]
#align nat.factorization_mul Nat.factorization_mul
#align nat.factorization_mul_support Nat.primeFactors_mul
/-- A product over `n.factorization` can be written as a product over `n.primeFactors`; -/
lemma prod_factorization_eq_prod_primeFactors {β : Type*} [CommMonoid β] (f : ℕ → ℕ → β) :
n.factorization.prod f = ∏ p ∈ n.primeFactors, f p (n.factorization p) := rfl
#align nat.prod_factorization_eq_prod_factors Nat.prod_factorization_eq_prod_primeFactors
/-- A product over `n.primeFactors` can be written as a product over `n.factorization`; -/
lemma prod_primeFactors_prod_factorization {β : Type*} [CommMonoid β] (f : ℕ → β) :
∏ p ∈ n.primeFactors, f p = n.factorization.prod (fun p _ ↦ f p) := rfl
/-- For any `p : ℕ` and any function `g : α → ℕ` that's non-zero on `S : Finset α`,
the power of `p` in `S.prod g` equals the sum over `x ∈ S` of the powers of `p` in `g x`.
Generalises `factorization_mul`, which is the special case where `S.card = 2` and `g = id`. -/
theorem factorization_prod {α : Type*} {S : Finset α} {g : α → ℕ} (hS : ∀ x ∈ S, g x ≠ 0) :
(S.prod g).factorization = S.sum fun x => (g x).factorization := by
classical
ext p
refine Finset.induction_on' S ?_ ?_
· simp
· intro x T hxS hTS hxT IH
have hT : T.prod g ≠ 0 := prod_ne_zero_iff.mpr fun x hx => hS x (hTS hx)
simp [prod_insert hxT, sum_insert hxT, ← IH, factorization_mul (hS x hxS) hT]
#align nat.factorization_prod Nat.factorization_prod
/-- For any `p`, the power of `p` in `n^k` is `k` times the power in `n` -/
@[simp]
theorem factorization_pow (n k : ℕ) : factorization (n ^ k) = k • n.factorization := by
induction' k with k ih; · simp
rcases eq_or_ne n 0 with (rfl | hn)
· simp
rw [Nat.pow_succ, mul_comm, factorization_mul hn (pow_ne_zero _ hn), ih,
add_smul, one_smul, add_comm]
#align nat.factorization_pow Nat.factorization_pow
/-! ## Lemmas about factorizations of primes and prime powers -/
/-- The only prime factor of prime `p` is `p` itself, with multiplicity `1` -/
@[simp]
protected theorem Prime.factorization {p : ℕ} (hp : Prime p) : p.factorization = single p 1 := by
ext q
rw [← factors_count_eq, factors_prime hp, single_apply, count_singleton', if_congr eq_comm] <;>
rfl
#align nat.prime.factorization Nat.Prime.factorization
/-- The multiplicity of prime `p` in `p` is `1` -/
@[simp]
theorem Prime.factorization_self {p : ℕ} (hp : Prime p) : p.factorization p = 1 := by simp [hp]
#align nat.prime.factorization_self Nat.Prime.factorization_self
/-- For prime `p` the only prime factor of `p^k` is `p` with multiplicity `k` -/
theorem Prime.factorization_pow {p k : ℕ} (hp : Prime p) : (p ^ k).factorization = single p k := by
simp [hp]
#align nat.prime.factorization_pow Nat.Prime.factorization_pow
/-- If the factorization of `n` contains just one number `p` then `n` is a power of `p` -/
theorem eq_pow_of_factorization_eq_single {n p k : ℕ} (hn : n ≠ 0)
(h : n.factorization = Finsupp.single p k) : n = p ^ k := by
-- Porting note: explicitly added `Finsupp.prod_single_index`
rw [← Nat.factorization_prod_pow_eq_self hn, h, Finsupp.prod_single_index]
simp
#align nat.eq_pow_of_factorization_eq_single Nat.eq_pow_of_factorization_eq_single
/-- The only prime factor of prime `p` is `p` itself. -/
theorem Prime.eq_of_factorization_pos {p q : ℕ} (hp : Prime p) (h : p.factorization q ≠ 0) :
p = q := by simpa [hp.factorization, single_apply] using h
#align nat.prime.eq_of_factorization_pos Nat.Prime.eq_of_factorization_pos
/-! ### Equivalence between `ℕ+` and `ℕ →₀ ℕ` with support in the primes. -/
/-- Any Finsupp `f : ℕ →₀ ℕ` whose support is in the primes is equal to the factorization of
the product `∏ (a : ℕ) ∈ f.support, a ^ f a`. -/
| Mathlib/Data/Nat/Factorization/Basic.lean | 279 | 287 | theorem prod_pow_factorization_eq_self {f : ℕ →₀ ℕ} (hf : ∀ p : ℕ, p ∈ f.support → Prime p) :
(f.prod (· ^ ·)).factorization = f := by |
have h : ∀ x : ℕ, x ∈ f.support → x ^ f x ≠ 0 := fun p hp =>
pow_ne_zero _ (Prime.ne_zero (hf p hp))
simp only [Finsupp.prod, factorization_prod h]
conv =>
rhs
rw [(sum_single f).symm]
exact sum_congr rfl fun p hp => Prime.factorization_pow (hf p hp)
|
/-
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.Topology.ContinuousOn
import Mathlib.Order.Filter.SmallSets
#align_import topology.locally_finite from "leanprover-community/mathlib"@"55d771df074d0dd020139ee1cd4b95521422df9f"
/-!
### Locally finite families of sets
We say that a family of sets in a topological space is *locally finite* if at every point `x : X`,
there is a neighborhood of `x` which meets only finitely many sets in the family.
In this file we give the definition and prove basic properties of locally finite families of sets.
-/
-- locally finite family [General Topology (Bourbaki, 1995)]
open Set Function Filter Topology
variable {ι ι' α X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] {f g : ι → Set X}
/-- A family of sets in `Set X` is locally finite if at every point `x : X`,
there is a neighborhood of `x` which meets only finitely many sets in the family. -/
def LocallyFinite (f : ι → Set X) :=
∀ x : X, ∃ t ∈ 𝓝 x, { i | (f i ∩ t).Nonempty }.Finite
#align locally_finite LocallyFinite
theorem locallyFinite_of_finite [Finite ι] (f : ι → Set X) : LocallyFinite f := fun _ =>
⟨univ, univ_mem, toFinite _⟩
#align locally_finite_of_finite locallyFinite_of_finite
namespace LocallyFinite
theorem point_finite (hf : LocallyFinite f) (x : X) : { b | x ∈ f b }.Finite :=
let ⟨_t, hxt, ht⟩ := hf x
ht.subset fun _b hb => ⟨x, hb, mem_of_mem_nhds hxt⟩
#align locally_finite.point_finite LocallyFinite.point_finite
protected theorem subset (hf : LocallyFinite f) (hg : ∀ i, g i ⊆ f i) : LocallyFinite g := fun a =>
let ⟨t, ht₁, ht₂⟩ := hf a
⟨t, ht₁, ht₂.subset fun i hi => hi.mono <| inter_subset_inter (hg i) Subset.rfl⟩
#align locally_finite.subset LocallyFinite.subset
theorem comp_injOn {g : ι' → ι} (hf : LocallyFinite f) (hg : InjOn g { i | (f (g i)).Nonempty }) :
LocallyFinite (f ∘ g) := fun x => by
let ⟨t, htx, htf⟩ := hf x
refine ⟨t, htx, htf.preimage <| ?_⟩
exact hg.mono fun i (hi : Set.Nonempty _) => hi.left
#align locally_finite.comp_inj_on LocallyFinite.comp_injOn
theorem comp_injective {g : ι' → ι} (hf : LocallyFinite f) (hg : Injective g) :
LocallyFinite (f ∘ g) :=
hf.comp_injOn hg.injOn
#align locally_finite.comp_injective LocallyFinite.comp_injective
theorem _root_.locallyFinite_iff_smallSets :
LocallyFinite f ↔ ∀ x, ∀ᶠ s in (𝓝 x).smallSets, { i | (f i ∩ s).Nonempty }.Finite :=
forall_congr' fun _ => Iff.symm <|
eventually_smallSets' fun _s _t hst ht =>
ht.subset fun _i hi => hi.mono <| inter_subset_inter_right _ hst
#align locally_finite_iff_small_sets locallyFinite_iff_smallSets
protected theorem eventually_smallSets (hf : LocallyFinite f) (x : X) :
∀ᶠ s in (𝓝 x).smallSets, { i | (f i ∩ s).Nonempty }.Finite :=
locallyFinite_iff_smallSets.mp hf x
#align locally_finite.eventually_small_sets LocallyFinite.eventually_smallSets
theorem exists_mem_basis {ι' : Sort*} (hf : LocallyFinite f) {p : ι' → Prop} {s : ι' → Set X}
{x : X} (hb : (𝓝 x).HasBasis p s) : ∃ i, p i ∧ { j | (f j ∩ s i).Nonempty }.Finite :=
let ⟨i, hpi, hi⟩ := hb.smallSets.eventually_iff.mp (hf.eventually_smallSets x)
⟨i, hpi, hi Subset.rfl⟩
#align locally_finite.exists_mem_basis LocallyFinite.exists_mem_basis
protected theorem nhdsWithin_iUnion (hf : LocallyFinite f) (a : X) :
𝓝[⋃ i, f i] a = ⨆ i, 𝓝[f i] a := by
rcases hf a with ⟨U, haU, hfin⟩
refine le_antisymm ?_ (Monotone.le_map_iSup fun _ _ ↦ nhdsWithin_mono _)
calc
𝓝[⋃ i, f i] a = 𝓝[⋃ i, f i ∩ U] a := by
rw [← iUnion_inter, ← nhdsWithin_inter_of_mem' (nhdsWithin_le_nhds haU)]
_ = 𝓝[⋃ i ∈ {j | (f j ∩ U).Nonempty}, (f i ∩ U)] a := by
simp only [mem_setOf_eq, iUnion_nonempty_self]
_ = ⨆ i ∈ {j | (f j ∩ U).Nonempty}, 𝓝[f i ∩ U] a := nhdsWithin_biUnion hfin _ _
_ ≤ ⨆ i, 𝓝[f i ∩ U] a := iSup₂_le_iSup _ _
_ ≤ ⨆ i, 𝓝[f i] a := iSup_mono fun i ↦ nhdsWithin_mono _ inter_subset_left
#align locally_finite.nhds_within_Union LocallyFinite.nhdsWithin_iUnion
theorem continuousOn_iUnion' {g : X → Y} (hf : LocallyFinite f)
(hc : ∀ i x, x ∈ closure (f i) → ContinuousWithinAt g (f i) x) :
ContinuousOn g (⋃ i, f i) := by
rintro x -
rw [ContinuousWithinAt, hf.nhdsWithin_iUnion, tendsto_iSup]
intro i
by_cases hx : x ∈ closure (f i)
· exact hc i _ hx
· rw [mem_closure_iff_nhdsWithin_neBot, not_neBot] at hx
rw [hx]
exact tendsto_bot
#align locally_finite.continuous_on_Union' LocallyFinite.continuousOn_iUnion'
theorem continuousOn_iUnion {g : X → Y} (hf : LocallyFinite f) (h_cl : ∀ i, IsClosed (f i))
(h_cont : ∀ i, ContinuousOn g (f i)) : ContinuousOn g (⋃ i, f i) :=
hf.continuousOn_iUnion' fun i x hx ↦ h_cont i x <| (h_cl i).closure_subset hx
#align locally_finite.continuous_on_Union LocallyFinite.continuousOn_iUnion
protected theorem continuous' {g : X → Y} (hf : LocallyFinite f) (h_cov : ⋃ i, f i = univ)
(hc : ∀ i x, x ∈ closure (f i) → ContinuousWithinAt g (f i) x) :
Continuous g :=
continuous_iff_continuousOn_univ.2 <| h_cov ▸ hf.continuousOn_iUnion' hc
#align locally_finite.continuous' LocallyFinite.continuous'
protected theorem continuous {g : X → Y} (hf : LocallyFinite f) (h_cov : ⋃ i, f i = univ)
(h_cl : ∀ i, IsClosed (f i)) (h_cont : ∀ i, ContinuousOn g (f i)) :
Continuous g :=
continuous_iff_continuousOn_univ.2 <| h_cov ▸ hf.continuousOn_iUnion h_cl h_cont
#align locally_finite.continuous LocallyFinite.continuous
protected theorem closure (hf : LocallyFinite f) : LocallyFinite fun i => closure (f i) := by
intro x
rcases hf x with ⟨s, hsx, hsf⟩
refine ⟨interior s, interior_mem_nhds.2 hsx, hsf.subset fun i hi => ?_⟩
exact (hi.mono isOpen_interior.closure_inter).of_closure.mono
(inter_subset_inter_right _ interior_subset)
#align locally_finite.closure LocallyFinite.closure
theorem closure_iUnion (h : LocallyFinite f) : closure (⋃ i, f i) = ⋃ i, closure (f i) := by
ext x
simp only [mem_closure_iff_nhdsWithin_neBot, h.nhdsWithin_iUnion, iSup_neBot, mem_iUnion]
#align locally_finite.closure_Union LocallyFinite.closure_iUnion
theorem isClosed_iUnion (hf : LocallyFinite f) (hc : ∀ i, IsClosed (f i)) :
IsClosed (⋃ i, f i) := by
simp only [← closure_eq_iff_isClosed, hf.closure_iUnion, (hc _).closure_eq]
#align locally_finite.is_closed_Union LocallyFinite.isClosed_iUnion
/-- If `f : β → Set α` is a locally finite family of closed sets, then for any `x : α`, the
intersection of the complements to `f i`, `x ∉ f i`, is a neighbourhood of `x`. -/
theorem iInter_compl_mem_nhds (hf : LocallyFinite f) (hc : ∀ i, IsClosed (f i)) (x : X) :
(⋂ (i) (_ : x ∉ f i), (f i)ᶜ) ∈ 𝓝 x := by
refine IsOpen.mem_nhds ?_ (mem_iInter₂.2 fun i => id)
suffices IsClosed (⋃ i : { i // x ∉ f i }, f i) by
rwa [← isOpen_compl_iff, compl_iUnion, iInter_subtype] at this
exact (hf.comp_injective Subtype.val_injective).isClosed_iUnion fun i => hc _
#align locally_finite.Inter_compl_mem_nhds LocallyFinite.iInter_compl_mem_nhds
/-- Let `f : ℕ → Π a, β a` be a sequence of (dependent) functions on a topological space. Suppose
that the family of sets `s n = {x | f (n + 1) x ≠ f n x}` is locally finite. Then there exists a
function `F : Π a, β a` such that for any `x`, we have `f n x = F x` on the product of an infinite
interval `[N, +∞)` and a neighbourhood of `x`.
We formulate the conclusion in terms of the product of filter `Filter.atTop` and `𝓝 x`. -/
| Mathlib/Topology/LocallyFinite.lean | 155 | 170 | theorem exists_forall_eventually_eq_prod {π : X → Sort*} {f : ℕ → ∀ x : X, π x}
(hf : LocallyFinite fun n => { x | f (n + 1) x ≠ f n x }) :
∃ F : ∀ x : X, π x, ∀ x, ∀ᶠ p : ℕ × X in atTop ×ˢ 𝓝 x, f p.1 p.2 = F p.2 := by |
choose U hUx hU using hf
choose N hN using fun x => (hU x).bddAbove
replace hN : ∀ (x), ∀ n > N x, ∀ y ∈ U x, f (n + 1) y = f n y :=
fun x n hn y hy => by_contra fun hne => hn.lt.not_le <| hN x ⟨y, hne, hy⟩
replace hN : ∀ (x), ∀ n ≥ N x + 1, ∀ y ∈ U x, f n y = f (N x + 1) y :=
fun x n hn y hy => Nat.le_induction rfl (fun k hle => (hN x _ hle _ hy).trans) n hn
refine ⟨fun x => f (N x + 1) x, fun x => ?_⟩
filter_upwards [Filter.prod_mem_prod (eventually_gt_atTop (N x)) (hUx x)]
rintro ⟨n, y⟩ ⟨hn : N x < n, hy : y ∈ U x⟩
calc
f n y = f (N x + 1) y := hN _ _ hn _ hy
_ = f (max (N x + 1) (N y + 1)) y := (hN _ _ (le_max_left _ _) _ hy).symm
_ = f (N y + 1) y := hN _ _ (le_max_right _ _) _ (mem_of_mem_nhds <| hUx y)
|
/-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.Data.Set.Lattice
import Mathlib.Order.ModularLattice
import Mathlib.Order.WellFounded
import Mathlib.Tactic.Nontriviality
#align_import order.atoms from "leanprover-community/mathlib"@"422e70f7ce183d2900c586a8cda8381e788a0c62"
/-!
# Atoms, Coatoms, and Simple Lattices
This module defines atoms, which are minimal non-`⊥` elements in bounded lattices, simple lattices,
which are lattices with only two elements, and related ideas.
## Main definitions
### Atoms and Coatoms
* `IsAtom a` indicates that the only element below `a` is `⊥`.
* `IsCoatom a` indicates that the only element above `a` is `⊤`.
### Atomic and Atomistic Lattices
* `IsAtomic` indicates that every element other than `⊥` is above an atom.
* `IsCoatomic` indicates that every element other than `⊤` is below a coatom.
* `IsAtomistic` indicates that every element is the `sSup` of a set of atoms.
* `IsCoatomistic` indicates that every element is the `sInf` of a set of coatoms.
### Simple Lattices
* `IsSimpleOrder` indicates that an order has only two unique elements, `⊥` and `⊤`.
* `IsSimpleOrder.boundedOrder`
* `IsSimpleOrder.distribLattice`
* Given an instance of `IsSimpleOrder`, we provide the following definitions. These are not
made global instances as they contain data :
* `IsSimpleOrder.booleanAlgebra`
* `IsSimpleOrder.completeLattice`
* `IsSimpleOrder.completeBooleanAlgebra`
## Main results
* `isAtom_dual_iff_isCoatom` and `isCoatom_dual_iff_isAtom` express the (definitional) duality
of `IsAtom` and `IsCoatom`.
* `isSimpleOrder_iff_isAtom_top` and `isSimpleOrder_iff_isCoatom_bot` express the
connection between atoms, coatoms, and simple lattices
* `IsCompl.isAtom_iff_isCoatom` and `IsCompl.isCoatom_if_isAtom`: In a modular
bounded lattice, a complement of an atom is a coatom and vice versa.
* `isAtomic_iff_isCoatomic`: A modular complemented lattice is atomic iff it is coatomic.
-/
set_option autoImplicit true
variable {α β : Type*}
section Atoms
section IsAtom
section Preorder
variable [Preorder α] [OrderBot α] {a b x : α}
/-- An atom of an `OrderBot` is an element with no other element between it and `⊥`,
which is not `⊥`. -/
def IsAtom (a : α) : Prop :=
a ≠ ⊥ ∧ ∀ b, b < a → b = ⊥
#align is_atom IsAtom
theorem IsAtom.Iic (ha : IsAtom a) (hax : a ≤ x) : IsAtom (⟨a, hax⟩ : Set.Iic x) :=
⟨fun con => ha.1 (Subtype.mk_eq_mk.1 con), fun ⟨b, _⟩ hba => Subtype.mk_eq_mk.2 (ha.2 b hba)⟩
#align is_atom.Iic IsAtom.Iic
theorem IsAtom.of_isAtom_coe_Iic {a : Set.Iic x} (ha : IsAtom a) : IsAtom (a : α) :=
⟨fun con => ha.1 (Subtype.ext con), fun b hba =>
Subtype.mk_eq_mk.1 (ha.2 ⟨b, hba.le.trans a.prop⟩ hba)⟩
#align is_atom.of_is_atom_coe_Iic IsAtom.of_isAtom_coe_Iic
theorem isAtom_iff_le_of_ge : IsAtom a ↔ a ≠ ⊥ ∧ ∀ b ≠ ⊥, b ≤ a → a ≤ b :=
and_congr Iff.rfl <|
forall_congr' fun b => by
simp only [Ne, @not_imp_comm (b = ⊥), Classical.not_imp, lt_iff_le_not_le]
#align is_atom_iff isAtom_iff_le_of_ge
end Preorder
section PartialOrder
variable [PartialOrder α] [OrderBot α] {a b x : α}
theorem IsAtom.lt_iff (h : IsAtom a) : x < a ↔ x = ⊥ :=
⟨h.2 x, fun hx => hx.symm ▸ h.1.bot_lt⟩
#align is_atom.lt_iff IsAtom.lt_iff
theorem IsAtom.le_iff (h : IsAtom a) : x ≤ a ↔ x = ⊥ ∨ x = a := by rw [le_iff_lt_or_eq, h.lt_iff]
#align is_atom.le_iff IsAtom.le_iff
lemma IsAtom.le_iff_eq (ha : IsAtom a) (hb : b ≠ ⊥) : b ≤ a ↔ b = a :=
ha.le_iff.trans <| or_iff_right hb
theorem IsAtom.Iic_eq (h : IsAtom a) : Set.Iic a = {⊥, a} :=
Set.ext fun _ => h.le_iff
#align is_atom.Iic_eq IsAtom.Iic_eq
@[simp]
theorem bot_covBy_iff : ⊥ ⋖ a ↔ IsAtom a := by
simp only [CovBy, bot_lt_iff_ne_bot, IsAtom, not_imp_not]
#align bot_covby_iff bot_covBy_iff
alias ⟨CovBy.is_atom, IsAtom.bot_covBy⟩ := bot_covBy_iff
#align covby.is_atom CovBy.is_atom
#align is_atom.bot_covby IsAtom.bot_covBy
end PartialOrder
theorem atom_le_iSup [Order.Frame α] (ha : IsAtom a) {f : ι → α} :
a ≤ iSup f ↔ ∃ i, a ≤ f i := by
refine ⟨?_, fun ⟨i, hi⟩ => le_trans hi (le_iSup _ _)⟩
show (a ≤ ⨆ i, f i) → _
refine fun h => of_not_not fun ha' => ?_
push_neg at ha'
have ha'' : Disjoint a (⨆ i, f i) :=
disjoint_iSup_iff.2 fun i => fun x hxa hxf => le_bot_iff.2 <| of_not_not fun hx =>
have hxa : x < a := (le_iff_eq_or_lt.1 hxa).resolve_left (by rintro rfl; exact ha' _ hxf)
hx (ha.2 _ hxa)
obtain rfl := le_bot_iff.1 (ha'' le_rfl h)
exact ha.1 rfl
end IsAtom
section IsCoatom
section Preorder
variable [Preorder α]
/-- A coatom of an `OrderTop` is an element with no other element between it and `⊤`,
which is not `⊤`. -/
def IsCoatom [OrderTop α] (a : α) : Prop :=
a ≠ ⊤ ∧ ∀ b, a < b → b = ⊤
#align is_coatom IsCoatom
@[simp]
theorem isCoatom_dual_iff_isAtom [OrderBot α] {a : α} :
IsCoatom (OrderDual.toDual a) ↔ IsAtom a :=
Iff.rfl
#align is_coatom_dual_iff_is_atom isCoatom_dual_iff_isAtom
@[simp]
theorem isAtom_dual_iff_isCoatom [OrderTop α] {a : α} :
IsAtom (OrderDual.toDual a) ↔ IsCoatom a :=
Iff.rfl
#align is_atom_dual_iff_is_coatom isAtom_dual_iff_isCoatom
alias ⟨_, IsAtom.dual⟩ := isCoatom_dual_iff_isAtom
#align is_atom.dual IsAtom.dual
alias ⟨_, IsCoatom.dual⟩ := isAtom_dual_iff_isCoatom
#align is_coatom.dual IsCoatom.dual
variable [OrderTop α] {a x : α}
theorem IsCoatom.Ici (ha : IsCoatom a) (hax : x ≤ a) : IsCoatom (⟨a, hax⟩ : Set.Ici x) :=
ha.dual.Iic hax
#align is_coatom.Ici IsCoatom.Ici
theorem IsCoatom.of_isCoatom_coe_Ici {a : Set.Ici x} (ha : IsCoatom a) : IsCoatom (a : α) :=
@IsAtom.of_isAtom_coe_Iic αᵒᵈ _ _ x a ha
#align is_coatom.of_is_coatom_coe_Ici IsCoatom.of_isCoatom_coe_Ici
theorem isCoatom_iff_ge_of_le : IsCoatom a ↔ a ≠ ⊤ ∧ ∀ b ≠ ⊤, a ≤ b → b ≤ a :=
isAtom_iff_le_of_ge (α := αᵒᵈ)
#align is_coatom_iff isCoatom_iff_ge_of_le
end Preorder
section PartialOrder
variable [PartialOrder α] [OrderTop α] {a b x : α}
theorem IsCoatom.lt_iff (h : IsCoatom a) : a < x ↔ x = ⊤ :=
h.dual.lt_iff
#align is_coatom.lt_iff IsCoatom.lt_iff
theorem IsCoatom.le_iff (h : IsCoatom a) : a ≤ x ↔ x = ⊤ ∨ x = a :=
h.dual.le_iff
#align is_coatom.le_iff IsCoatom.le_iff
lemma IsCoatom.le_iff_eq (ha : IsCoatom a) (hb : b ≠ ⊤) : a ≤ b ↔ b = a := ha.dual.le_iff_eq hb
theorem IsCoatom.Ici_eq (h : IsCoatom a) : Set.Ici a = {⊤, a} :=
h.dual.Iic_eq
#align is_coatom.Ici_eq IsCoatom.Ici_eq
@[simp]
theorem covBy_top_iff : a ⋖ ⊤ ↔ IsCoatom a :=
toDual_covBy_toDual_iff.symm.trans bot_covBy_iff
#align covby_top_iff covBy_top_iff
alias ⟨CovBy.isCoatom, IsCoatom.covBy_top⟩ := covBy_top_iff
#align covby.is_coatom CovBy.isCoatom
#align is_coatom.covby_top IsCoatom.covBy_top
end PartialOrder
theorem iInf_le_coatom [Order.Coframe α] (ha : IsCoatom a) {f : ι → α} :
iInf f ≤ a ↔ ∃ i, f i ≤ a :=
atom_le_iSup (α := αᵒᵈ) ha
end IsCoatom
section PartialOrder
variable [PartialOrder α] {a b : α}
@[simp]
theorem Set.Ici.isAtom_iff {b : Set.Ici a} : IsAtom b ↔ a ⋖ b := by
rw [← bot_covBy_iff]
refine (Set.OrdConnected.apply_covBy_apply_iff (OrderEmbedding.subtype fun c => a ≤ c) ?_).symm
simpa only [OrderEmbedding.subtype_apply, Subtype.range_coe_subtype] using Set.ordConnected_Ici
#align set.Ici.is_atom_iff Set.Ici.isAtom_iff
@[simp]
theorem Set.Iic.isCoatom_iff {a : Set.Iic b} : IsCoatom a ↔ ↑a ⋖ b := by
rw [← covBy_top_iff]
refine (Set.OrdConnected.apply_covBy_apply_iff (OrderEmbedding.subtype fun c => c ≤ b) ?_).symm
simpa only [OrderEmbedding.subtype_apply, Subtype.range_coe_subtype] using Set.ordConnected_Iic
#align set.Iic.is_coatom_iff Set.Iic.isCoatom_iff
theorem covBy_iff_atom_Ici (h : a ≤ b) : a ⋖ b ↔ IsAtom (⟨b, h⟩ : Set.Ici a) := by simp
#align covby_iff_atom_Ici covBy_iff_atom_Ici
theorem covBy_iff_coatom_Iic (h : a ≤ b) : a ⋖ b ↔ IsCoatom (⟨a, h⟩ : Set.Iic b) := by simp
#align covby_iff_coatom_Iic covBy_iff_coatom_Iic
end PartialOrder
section Pairwise
theorem IsAtom.inf_eq_bot_of_ne [SemilatticeInf α] [OrderBot α] {a b : α} (ha : IsAtom a)
(hb : IsAtom b) (hab : a ≠ b) : a ⊓ b = ⊥ :=
hab.not_le_or_not_le.elim (ha.lt_iff.1 ∘ inf_lt_left.2) (hb.lt_iff.1 ∘ inf_lt_right.2)
#align is_atom.inf_eq_bot_of_ne IsAtom.inf_eq_bot_of_ne
theorem IsAtom.disjoint_of_ne [SemilatticeInf α] [OrderBot α] {a b : α} (ha : IsAtom a)
(hb : IsAtom b) (hab : a ≠ b) : Disjoint a b :=
disjoint_iff.mpr (IsAtom.inf_eq_bot_of_ne ha hb hab)
#align is_atom.disjoint_of_ne IsAtom.disjoint_of_ne
theorem IsCoatom.sup_eq_top_of_ne [SemilatticeSup α] [OrderTop α] {a b : α} (ha : IsCoatom a)
(hb : IsCoatom b) (hab : a ≠ b) : a ⊔ b = ⊤ :=
ha.dual.inf_eq_bot_of_ne hb.dual hab
#align is_coatom.sup_eq_top_of_ne IsCoatom.sup_eq_top_of_ne
end Pairwise
end Atoms
section Atomic
variable [PartialOrder α] (α)
/-- A lattice is atomic iff every element other than `⊥` has an atom below it. -/
@[mk_iff]
class IsAtomic [OrderBot α] : Prop where
/-- Every element other than `⊥` has an atom below it. -/
eq_bot_or_exists_atom_le : ∀ b : α, b = ⊥ ∨ ∃ a : α, IsAtom a ∧ a ≤ b
#align is_atomic IsAtomic
#align is_atomic_iff isAtomic_iff
/-- A lattice is coatomic iff every element other than `⊤` has a coatom above it. -/
@[mk_iff]
class IsCoatomic [OrderTop α] : Prop where
/-- Every element other than `⊤` has an atom above it. -/
eq_top_or_exists_le_coatom : ∀ b : α, b = ⊤ ∨ ∃ a : α, IsCoatom a ∧ b ≤ a
#align is_coatomic IsCoatomic
#align is_coatomic_iff isCoatomic_iff
export IsAtomic (eq_bot_or_exists_atom_le)
export IsCoatomic (eq_top_or_exists_le_coatom)
lemma IsAtomic.exists_atom [OrderBot α] [Nontrivial α] [IsAtomic α] : ∃ a : α, IsAtom a :=
have ⟨b, hb⟩ := exists_ne (⊥ : α)
have ⟨a, ha⟩ := (eq_bot_or_exists_atom_le b).resolve_left hb
⟨a, ha.1⟩
lemma IsCoatomic.exists_coatom [OrderTop α] [Nontrivial α] [IsCoatomic α] : ∃ a : α, IsCoatom a :=
have ⟨b, hb⟩ := exists_ne (⊤ : α)
have ⟨a, ha⟩ := (eq_top_or_exists_le_coatom b).resolve_left hb
⟨a, ha.1⟩
variable {α}
@[simp]
theorem isCoatomic_dual_iff_isAtomic [OrderBot α] : IsCoatomic αᵒᵈ ↔ IsAtomic α :=
⟨fun h => ⟨fun b => by apply h.eq_top_or_exists_le_coatom⟩, fun h =>
⟨fun b => by apply h.eq_bot_or_exists_atom_le⟩⟩
#align is_coatomic_dual_iff_is_atomic isCoatomic_dual_iff_isAtomic
@[simp]
theorem isAtomic_dual_iff_isCoatomic [OrderTop α] : IsAtomic αᵒᵈ ↔ IsCoatomic α :=
⟨fun h => ⟨fun b => by apply h.eq_bot_or_exists_atom_le⟩, fun h =>
⟨fun b => by apply h.eq_top_or_exists_le_coatom⟩⟩
#align is_atomic_dual_iff_is_coatomic isAtomic_dual_iff_isCoatomic
namespace IsAtomic
variable [OrderBot α] [IsAtomic α]
instance _root_.OrderDual.instIsCoatomic : IsCoatomic αᵒᵈ :=
isCoatomic_dual_iff_isAtomic.2 ‹IsAtomic α›
#align is_atomic.is_coatomic_dual OrderDual.instIsCoatomic
instance Set.Iic.isAtomic {x : α} : IsAtomic (Set.Iic x) :=
⟨fun ⟨y, hy⟩ =>
(eq_bot_or_exists_atom_le y).imp Subtype.mk_eq_mk.2 fun ⟨a, ha, hay⟩ =>
⟨⟨a, hay.trans hy⟩, ha.Iic (hay.trans hy), hay⟩⟩
#align is_atomic.set.Iic.is_atomic IsAtomic.Set.Iic.isAtomic
end IsAtomic
namespace IsCoatomic
variable [OrderTop α] [IsCoatomic α]
instance _root_.OrderDual.instIsAtomic : IsAtomic αᵒᵈ :=
isAtomic_dual_iff_isCoatomic.2 ‹IsCoatomic α›
#align is_coatomic.is_coatomic OrderDual.instIsAtomic
instance Set.Ici.isCoatomic {x : α} : IsCoatomic (Set.Ici x) :=
⟨fun ⟨y, hy⟩ =>
(eq_top_or_exists_le_coatom y).imp Subtype.mk_eq_mk.2 fun ⟨a, ha, hay⟩ =>
⟨⟨a, le_trans hy hay⟩, ha.Ici (le_trans hy hay), hay⟩⟩
#align is_coatomic.set.Ici.is_coatomic IsCoatomic.Set.Ici.isCoatomic
end IsCoatomic
theorem isAtomic_iff_forall_isAtomic_Iic [OrderBot α] :
IsAtomic α ↔ ∀ x : α, IsAtomic (Set.Iic x) :=
⟨@IsAtomic.Set.Iic.isAtomic _ _ _, fun h =>
⟨fun x =>
((@eq_bot_or_exists_atom_le _ _ _ (h x)) (⊤ : Set.Iic x)).imp Subtype.mk_eq_mk.1
(Exists.imp' (↑) fun ⟨_, _⟩ => And.imp_left IsAtom.of_isAtom_coe_Iic)⟩⟩
#align is_atomic_iff_forall_is_atomic_Iic isAtomic_iff_forall_isAtomic_Iic
theorem isCoatomic_iff_forall_isCoatomic_Ici [OrderTop α] :
IsCoatomic α ↔ ∀ x : α, IsCoatomic (Set.Ici x) :=
isAtomic_dual_iff_isCoatomic.symm.trans <|
isAtomic_iff_forall_isAtomic_Iic.trans <|
forall_congr' fun _ => isCoatomic_dual_iff_isAtomic.symm.trans Iff.rfl
#align is_coatomic_iff_forall_is_coatomic_Ici isCoatomic_iff_forall_isCoatomic_Ici
section WellFounded
theorem isAtomic_of_orderBot_wellFounded_lt [OrderBot α]
(h : WellFounded ((· < ·) : α → α → Prop)) : IsAtomic α :=
⟨fun a =>
or_iff_not_imp_left.2 fun ha =>
let ⟨b, hb, hm⟩ := h.has_min { b | b ≠ ⊥ ∧ b ≤ a } ⟨a, ha, le_rfl⟩
⟨b, ⟨hb.1, fun c => not_imp_not.1 fun hc hl => hm c ⟨hc, hl.le.trans hb.2⟩ hl⟩, hb.2⟩⟩
#align is_atomic_of_order_bot_well_founded_lt isAtomic_of_orderBot_wellFounded_lt
theorem isCoatomic_of_orderTop_gt_wellFounded [OrderTop α]
(h : WellFounded ((· > ·) : α → α → Prop)) : IsCoatomic α :=
isAtomic_dual_iff_isCoatomic.1 (@isAtomic_of_orderBot_wellFounded_lt αᵒᵈ _ _ h)
#align is_coatomic_of_order_top_gt_well_founded isCoatomic_of_orderTop_gt_wellFounded
end WellFounded
namespace BooleanAlgebra
theorem le_iff_atom_le_imp {α} [BooleanAlgebra α] [IsAtomic α] {x y : α} :
x ≤ y ↔ ∀ a, IsAtom a → a ≤ x → a ≤ y := by
refine ⟨fun h a _ => (le_trans · h), fun h => ?_⟩
have : x ⊓ yᶜ = ⊥ := of_not_not fun hbot =>
have ⟨a, ha, hle⟩ := (eq_bot_or_exists_atom_le _).resolve_left hbot
have ⟨hx, hy'⟩ := le_inf_iff.1 hle
have hy := h a ha hx
have : a ≤ y ⊓ yᶜ := le_inf_iff.2 ⟨hy, hy'⟩
ha.1 (by simpa using this)
exact (eq_compl_iff_isCompl.1 (by simp)).inf_right_eq_bot_iff.1 this
theorem eq_iff_atom_le_iff {α} [BooleanAlgebra α] [IsAtomic α] {x y : α} :
x = y ↔ ∀ a, IsAtom a → (a ≤ x ↔ a ≤ y) := by
refine ⟨fun h => h ▸ by simp, fun h => ?_⟩
exact le_antisymm (le_iff_atom_le_imp.2 fun a ha hx => (h a ha).1 hx)
(le_iff_atom_le_imp.2 fun a ha hy => (h a ha).2 hy)
end BooleanAlgebra
namespace CompleteBooleanAlgebra
-- See note [reducible non-instances]
abbrev toCompleteAtomicBooleanAlgebra {α} [CompleteBooleanAlgebra α] [IsAtomic α] :
CompleteAtomicBooleanAlgebra α where
__ := ‹CompleteBooleanAlgebra α›
iInf_iSup_eq f := BooleanAlgebra.eq_iff_atom_le_iff.2 fun a ha => by
simp only [le_iInf_iff, atom_le_iSup ha]
rw [Classical.skolem]
end CompleteBooleanAlgebra
end Atomic
section Atomistic
variable (α) [CompleteLattice α]
/-- A lattice is atomistic iff every element is a `sSup` of a set of atoms. -/
class IsAtomistic : Prop where
/-- Every element is a `sSup` of a set of atoms. -/
eq_sSup_atoms : ∀ b : α, ∃ s : Set α, b = sSup s ∧ ∀ a, a ∈ s → IsAtom a
#align is_atomistic IsAtomistic
#align is_atomistic.eq_Sup_atoms IsAtomistic.eq_sSup_atoms
/-- A lattice is coatomistic iff every element is an `sInf` of a set of coatoms. -/
class IsCoatomistic : Prop where
/-- Every element is a `sInf` of a set of coatoms. -/
eq_sInf_coatoms : ∀ b : α, ∃ s : Set α, b = sInf s ∧ ∀ a, a ∈ s → IsCoatom a
#align is_coatomistic IsCoatomistic
#align is_coatomistic.eq_Inf_coatoms IsCoatomistic.eq_sInf_coatoms
export IsAtomistic (eq_sSup_atoms)
export IsCoatomistic (eq_sInf_coatoms)
variable {α}
@[simp]
theorem isCoatomistic_dual_iff_isAtomistic : IsCoatomistic αᵒᵈ ↔ IsAtomistic α :=
⟨fun h => ⟨fun b => by apply h.eq_sInf_coatoms⟩, fun h => ⟨fun b => by apply h.eq_sSup_atoms⟩⟩
#align is_coatomistic_dual_iff_is_atomistic isCoatomistic_dual_iff_isAtomistic
@[simp]
theorem isAtomistic_dual_iff_isCoatomistic : IsAtomistic αᵒᵈ ↔ IsCoatomistic α :=
⟨fun h => ⟨fun b => by apply h.eq_sSup_atoms⟩, fun h => ⟨fun b => by apply h.eq_sInf_coatoms⟩⟩
#align is_atomistic_dual_iff_is_coatomistic isAtomistic_dual_iff_isCoatomistic
namespace IsAtomistic
instance _root_.OrderDual.instIsCoatomistic [h : IsAtomistic α] : IsCoatomistic αᵒᵈ :=
isCoatomistic_dual_iff_isAtomistic.2 h
#align is_atomistic.is_coatomistic_dual OrderDual.instIsCoatomistic
variable [IsAtomistic α]
instance (priority := 100) : IsAtomic α :=
⟨fun b => by
rcases eq_sSup_atoms b with ⟨s, rfl, hs⟩
rcases s.eq_empty_or_nonempty with h | h
· simp [h]
· exact Or.intro_right _ ⟨h.some, hs _ h.choose_spec, le_sSup h.choose_spec⟩⟩
end IsAtomistic
section IsAtomistic
variable [IsAtomistic α]
@[simp]
theorem sSup_atoms_le_eq (b : α) : sSup { a : α | IsAtom a ∧ a ≤ b } = b := by
rcases eq_sSup_atoms b with ⟨s, rfl, hs⟩
exact le_antisymm (sSup_le fun _ => And.right) (sSup_le_sSup fun a ha => ⟨hs a ha, le_sSup ha⟩)
#align Sup_atoms_le_eq sSup_atoms_le_eq
@[simp]
theorem sSup_atoms_eq_top : sSup { a : α | IsAtom a } = ⊤ := by
refine Eq.trans (congr rfl (Set.ext fun x => ?_)) (sSup_atoms_le_eq ⊤)
exact (and_iff_left le_top).symm
#align Sup_atoms_eq_top sSup_atoms_eq_top
theorem le_iff_atom_le_imp {a b : α} : a ≤ b ↔ ∀ c : α, IsAtom c → c ≤ a → c ≤ b :=
⟨fun ab c _ ca => le_trans ca ab, fun h => by
rw [← sSup_atoms_le_eq a, ← sSup_atoms_le_eq b]
exact sSup_le_sSup fun c hc => ⟨hc.1, h c hc.1 hc.2⟩⟩
#align le_iff_atom_le_imp le_iff_atom_le_imp
theorem eq_iff_atom_le_iff {a b : α} : a = b ↔ ∀ c, IsAtom c → (c ≤ a ↔ c ≤ b) := by
refine ⟨fun h => h ▸ by simp, fun h => ?_⟩
exact le_antisymm (le_iff_atom_le_imp.2 fun a ha hx => (h a ha).1 hx)
(le_iff_atom_le_imp.2 fun a ha hy => (h a ha).2 hy)
end IsAtomistic
namespace IsCoatomistic
instance _root_.OrderDual.instIsAtomistic [h : IsCoatomistic α] : IsAtomistic αᵒᵈ :=
isAtomistic_dual_iff_isCoatomistic.2 h
#align is_coatomistic.is_atomistic_dual OrderDual.instIsAtomistic
variable [IsCoatomistic α]
instance (priority := 100) : IsCoatomic α :=
⟨fun b => by
rcases eq_sInf_coatoms b with ⟨s, rfl, hs⟩
rcases s.eq_empty_or_nonempty with h | h
· simp [h]
· exact Or.intro_right _ ⟨h.some, hs _ h.choose_spec, sInf_le h.choose_spec⟩⟩
end IsCoatomistic
namespace CompleteAtomicBooleanAlgebra
instance {α} [CompleteAtomicBooleanAlgebra α] : IsAtomistic α where
eq_sSup_atoms b := by
inhabit α
refine ⟨{ a | IsAtom a ∧ a ≤ b }, ?_, fun a ha => ha.1⟩
refine le_antisymm ?_ (sSup_le fun c hc => hc.2)
have : (⨅ c : α, ⨆ x, b ⊓ cond x c (cᶜ)) = b := by simp [iSup_bool_eq, iInf_const]
rw [← this]; clear this
simp_rw [iInf_iSup_eq, iSup_le_iff]; intro g
if h : (⨅ a, b ⊓ cond (g a) a (aᶜ)) = ⊥ then simp [h] else
refine le_sSup ⟨⟨h, fun c hc => ?_⟩, le_trans (by rfl) (le_iSup _ g)⟩; clear h
have := lt_of_lt_of_le hc (le_trans (iInf_le _ c) inf_le_right)
revert this
nontriviality α
cases g c <;> simp
instance {α} [CompleteAtomicBooleanAlgebra α] : IsCoatomistic α :=
isAtomistic_dual_iff_isCoatomistic.1 inferInstance
end CompleteAtomicBooleanAlgebra
end Atomistic
/-- An order is simple iff it has exactly two elements, `⊥` and `⊤`. -/
class IsSimpleOrder (α : Type*) [LE α] [BoundedOrder α] extends Nontrivial α : Prop where
/-- Every element is either `⊥` or `⊤` -/
eq_bot_or_eq_top : ∀ a : α, a = ⊥ ∨ a = ⊤
#align is_simple_order IsSimpleOrder
export IsSimpleOrder (eq_bot_or_eq_top)
theorem isSimpleOrder_iff_isSimpleOrder_orderDual [LE α] [BoundedOrder α] :
IsSimpleOrder α ↔ IsSimpleOrder αᵒᵈ := by
constructor <;> intro i <;> haveI := i
· exact
{ exists_pair_ne := @exists_pair_ne α _
eq_bot_or_eq_top := fun a => Or.symm (eq_bot_or_eq_top (OrderDual.ofDual a) : _ ∨ _) }
· exact
{ exists_pair_ne := @exists_pair_ne αᵒᵈ _
eq_bot_or_eq_top := fun a => Or.symm (eq_bot_or_eq_top (OrderDual.toDual a)) }
#align is_simple_order_iff_is_simple_order_order_dual isSimpleOrder_iff_isSimpleOrder_orderDual
theorem IsSimpleOrder.bot_ne_top [LE α] [BoundedOrder α] [IsSimpleOrder α] : (⊥ : α) ≠ (⊤ : α) := by
obtain ⟨a, b, h⟩ := exists_pair_ne α
rcases eq_bot_or_eq_top a with (rfl | rfl) <;> rcases eq_bot_or_eq_top b with (rfl | rfl) <;>
first |simpa|simpa using h.symm
#align is_simple_order.bot_ne_top IsSimpleOrder.bot_ne_top
section IsSimpleOrder
variable [PartialOrder α] [BoundedOrder α] [IsSimpleOrder α]
instance OrderDual.instIsSimpleOrder {α} [LE α] [BoundedOrder α] [IsSimpleOrder α] :
IsSimpleOrder αᵒᵈ := isSimpleOrder_iff_isSimpleOrder_orderDual.1 (by infer_instance)
/-- A simple `BoundedOrder` induces a preorder. This is not an instance to prevent loops. -/
protected def IsSimpleOrder.preorder {α} [LE α] [BoundedOrder α] [IsSimpleOrder α] :
Preorder α where
le := (· ≤ ·)
le_refl a := by rcases eq_bot_or_eq_top a with (rfl | rfl) <;> simp
le_trans a b c := by
rcases eq_bot_or_eq_top a with (rfl | rfl)
· simp
· rcases eq_bot_or_eq_top b with (rfl | rfl)
· rcases eq_bot_or_eq_top c with (rfl | rfl) <;> simp
· simp
#align is_simple_order.preorder IsSimpleOrder.preorder
/-- A simple partial ordered `BoundedOrder` induces a linear order.
This is not an instance to prevent loops. -/
protected def IsSimpleOrder.linearOrder [DecidableEq α] : LinearOrder α :=
{ (inferInstance : PartialOrder α) with
le_total := fun a b => by rcases eq_bot_or_eq_top a with (rfl | rfl) <;> simp
decidableLE := fun a b =>
if ha : a = ⊥ then isTrue (ha.le.trans bot_le)
else
if hb : b = ⊤ then isTrue (le_top.trans hb.ge)
else
isFalse fun H =>
hb (top_unique (le_trans (top_le_iff.mpr (Or.resolve_left
(eq_bot_or_eq_top a) ha)) H)) }
#align is_simple_order.linear_order IsSimpleOrder.linearOrder
@[simp]
theorem isAtom_top : IsAtom (⊤ : α) :=
⟨top_ne_bot, fun a ha => Or.resolve_right (eq_bot_or_eq_top a) (ne_of_lt ha)⟩
#align is_atom_top isAtom_top
@[simp]
theorem isCoatom_bot : IsCoatom (⊥ : α) :=
isAtom_dual_iff_isCoatom.1 isAtom_top
#align is_coatom_bot isCoatom_bot
theorem bot_covBy_top : (⊥ : α) ⋖ ⊤ :=
isAtom_top.bot_covBy
#align bot_covby_top bot_covBy_top
end IsSimpleOrder
namespace IsSimpleOrder
section Preorder
variable [Preorder α] [BoundedOrder α] [IsSimpleOrder α] {a b : α} (h : a < b)
theorem eq_bot_of_lt : a = ⊥ :=
(IsSimpleOrder.eq_bot_or_eq_top _).resolve_right h.ne_top
#align is_simple_order.eq_bot_of_lt IsSimpleOrder.eq_bot_of_lt
theorem eq_top_of_lt : b = ⊤ :=
(IsSimpleOrder.eq_bot_or_eq_top _).resolve_left h.ne_bot
#align is_simple_order.eq_top_of_lt IsSimpleOrder.eq_top_of_lt
alias _root_.LT.lt.eq_bot := eq_bot_of_lt
alias _root_.LT.lt.eq_top := eq_top_of_lt
@[deprecated (since := "2024-05-29")] alias LT.lt.eq_bot := _root_.LT.lt.eq_bot
@[deprecated (since := "2024-05-29")] alias LT.lt.eq_top := _root_.LT.lt.eq_top
end Preorder
section BoundedOrder
variable [Lattice α] [BoundedOrder α] [IsSimpleOrder α]
/-- A simple partial ordered `BoundedOrder` induces a lattice.
This is not an instance to prevent loops -/
protected def lattice {α} [DecidableEq α] [PartialOrder α] [BoundedOrder α] [IsSimpleOrder α] :
Lattice α :=
@LinearOrder.toLattice α IsSimpleOrder.linearOrder
#align is_simple_order.lattice IsSimpleOrder.lattice
/-- A lattice that is a `BoundedOrder` is a distributive lattice.
This is not an instance to prevent loops -/
protected def distribLattice : DistribLattice α :=
{ (inferInstance : Lattice α) with
le_sup_inf := fun x y z => by rcases eq_bot_or_eq_top x with (rfl | rfl) <;> simp }
#align is_simple_order.distrib_lattice IsSimpleOrder.distribLattice
-- see Note [lower instance priority]
instance (priority := 100) : IsAtomic α :=
⟨fun b => (eq_bot_or_eq_top b).imp_right fun h => ⟨⊤, ⟨isAtom_top, ge_of_eq h⟩⟩⟩
-- see Note [lower instance priority]
instance (priority := 100) : IsCoatomic α :=
isAtomic_dual_iff_isCoatomic.1 (by infer_instance)
end BoundedOrder
-- It is important that in this section `IsSimpleOrder` is the last type-class argument.
section DecidableEq
variable [DecidableEq α] [PartialOrder α] [BoundedOrder α] [IsSimpleOrder α]
/-- Every simple lattice is isomorphic to `Bool`, regardless of order. -/
@[simps]
def equivBool {α} [DecidableEq α] [LE α] [BoundedOrder α] [IsSimpleOrder α] : α ≃ Bool where
toFun x := x = ⊤
invFun x := x.casesOn ⊥ ⊤
left_inv x := by rcases eq_bot_or_eq_top x with (rfl | rfl) <;> simp [bot_ne_top]
right_inv x := by cases x <;> simp [bot_ne_top]
#align is_simple_order.equiv_bool IsSimpleOrder.equivBool
#align is_simple_order.equiv_bool_symm_apply IsSimpleOrder.equivBool_symm_apply
#align is_simple_order.equiv_bool_apply IsSimpleOrder.equivBool_apply
/-- Every simple lattice over a partial order is order-isomorphic to `Bool`. -/
def orderIsoBool : α ≃o Bool :=
{ equivBool with
map_rel_iff' := @fun a b => by
rcases eq_bot_or_eq_top a with (rfl | rfl)
· simp [bot_ne_top]
· rcases eq_bot_or_eq_top b with (rfl | rfl)
· simp [bot_ne_top.symm, bot_ne_top, Bool.false_lt_true]
· simp [bot_ne_top] }
#align is_simple_order.order_iso_bool IsSimpleOrder.orderIsoBool
/-- A simple `BoundedOrder` is also a `BooleanAlgebra`. -/
protected def booleanAlgebra {α} [DecidableEq α] [Lattice α] [BoundedOrder α] [IsSimpleOrder α] :
BooleanAlgebra α :=
{ inferInstanceAs (BoundedOrder α), IsSimpleOrder.distribLattice with
compl := fun x => if x = ⊥ then ⊤ else ⊥
sdiff := fun x y => if x = ⊤ ∧ y = ⊥ then ⊤ else ⊥
sdiff_eq := fun x y => by
rcases eq_bot_or_eq_top x with (rfl | rfl) <;> simp [bot_ne_top, SDiff.sdiff, compl]
inf_compl_le_bot := fun x => by
rcases eq_bot_or_eq_top x with (rfl | rfl)
· simp
· simp
top_le_sup_compl := fun x => by rcases eq_bot_or_eq_top x with (rfl | rfl) <;> simp }
#align is_simple_order.boolean_algebra IsSimpleOrder.booleanAlgebra
end DecidableEq
variable [Lattice α] [BoundedOrder α] [IsSimpleOrder α]
open scoped Classical
/-- A simple `BoundedOrder` is also complete. -/
protected noncomputable def completeLattice : CompleteLattice α :=
{ (inferInstance : Lattice α),
(inferInstance : BoundedOrder α) with
sSup := fun s => if ⊤ ∈ s then ⊤ else ⊥
sInf := fun s => if ⊥ ∈ s then ⊥ else ⊤
le_sSup := fun s x h => by
rcases eq_bot_or_eq_top x with (rfl | rfl)
· exact bot_le
· dsimp; rw [if_pos h]
sSup_le := fun s x h => by
rcases eq_bot_or_eq_top x with (rfl | rfl)
· dsimp; rw [if_neg]
intro con
exact bot_ne_top (eq_top_iff.2 (h ⊤ con))
· exact le_top
sInf_le := fun s x h => by
rcases eq_bot_or_eq_top x with (rfl | rfl)
· dsimp; rw [if_pos h]
· exact le_top
le_sInf := fun s x h => by
rcases eq_bot_or_eq_top x with (rfl | rfl)
· exact bot_le
· dsimp; rw [if_neg]
intro con
exact top_ne_bot (eq_bot_iff.2 (h ⊥ con)) }
#align is_simple_order.complete_lattice IsSimpleOrder.completeLattice
/-- A simple `BoundedOrder` is also a `CompleteBooleanAlgebra`. -/
protected noncomputable def completeBooleanAlgebra : CompleteBooleanAlgebra α :=
{ __ := IsSimpleOrder.completeLattice
__ := IsSimpleOrder.booleanAlgebra
iInf_sup_le_sup_sInf := fun x s => by
rcases eq_bot_or_eq_top x with (rfl | rfl)
· simp [bot_sup_eq, ← sInf_eq_iInf]
· simp only [top_le_iff, top_sup_eq, iInf_top, le_sInf_iff, le_refl]
inf_sSup_le_iSup_inf := fun x s => by
rcases eq_bot_or_eq_top x with (rfl | rfl)
· simp only [le_bot_iff, sSup_eq_bot, bot_inf_eq, iSup_bot, le_refl]
· simp only [top_inf_eq, ← sSup_eq_iSup]
exact le_rfl }
#align is_simple_order.complete_boolean_algebra IsSimpleOrder.completeBooleanAlgebra
instance : ComplementedLattice α :=
letI := IsSimpleOrder.completeBooleanAlgebra (α := α); inferInstance
end IsSimpleOrder
namespace IsSimpleOrder
variable [CompleteLattice α] [IsSimpleOrder α]
--set_option default_priority 100
-- Porting note: not supported, done for each instance individually
instance (priority := 100) : IsAtomistic α :=
⟨fun b =>
(eq_bot_or_eq_top b).elim
(fun h => ⟨∅, ⟨h.trans sSup_empty.symm, fun _ ha => False.elim (Set.not_mem_empty _ ha)⟩⟩)
fun h =>
⟨{⊤}, h.trans sSup_singleton.symm, fun _ ha =>
(Set.mem_singleton_iff.1 ha).symm ▸ isAtom_top⟩⟩
instance : IsCoatomistic α :=
isAtomistic_dual_iff_isCoatomistic.1 (by infer_instance)
end IsSimpleOrder
theorem isSimpleOrder_iff_isAtom_top [PartialOrder α] [BoundedOrder α] :
IsSimpleOrder α ↔ IsAtom (⊤ : α) :=
⟨fun h => @isAtom_top _ _ _ h, fun h =>
{ exists_pair_ne := ⟨⊤, ⊥, h.1⟩
eq_bot_or_eq_top := fun a => ((eq_or_lt_of_le le_top).imp_right (h.2 a)).symm }⟩
#align is_simple_order_iff_is_atom_top isSimpleOrder_iff_isAtom_top
theorem isSimpleOrder_iff_isCoatom_bot [PartialOrder α] [BoundedOrder α] :
IsSimpleOrder α ↔ IsCoatom (⊥ : α) :=
isSimpleOrder_iff_isSimpleOrder_orderDual.trans isSimpleOrder_iff_isAtom_top
#align is_simple_order_iff_is_coatom_bot isSimpleOrder_iff_isCoatom_bot
namespace Set
theorem isSimpleOrder_Iic_iff_isAtom [PartialOrder α] [OrderBot α] {a : α} :
IsSimpleOrder (Iic a) ↔ IsAtom a :=
isSimpleOrder_iff_isAtom_top.trans <|
and_congr (not_congr Subtype.mk_eq_mk)
⟨fun h b ab => Subtype.mk_eq_mk.1 (h ⟨b, le_of_lt ab⟩ ab), fun h ⟨b, _⟩ hbotb =>
Subtype.mk_eq_mk.2 (h b (Subtype.mk_lt_mk.1 hbotb))⟩
#align set.is_simple_order_Iic_iff_is_atom Set.isSimpleOrder_Iic_iff_isAtom
theorem isSimpleOrder_Ici_iff_isCoatom [PartialOrder α] [OrderTop α] {a : α} :
IsSimpleOrder (Ici a) ↔ IsCoatom a :=
isSimpleOrder_iff_isCoatom_bot.trans <|
and_congr (not_congr Subtype.mk_eq_mk)
⟨fun h b ab => Subtype.mk_eq_mk.1 (h ⟨b, le_of_lt ab⟩ ab), fun h ⟨b, _⟩ hbotb =>
Subtype.mk_eq_mk.2 (h b (Subtype.mk_lt_mk.1 hbotb))⟩
#align set.is_simple_order_Ici_iff_is_coatom Set.isSimpleOrder_Ici_iff_isCoatom
end Set
namespace OrderEmbedding
variable [PartialOrder α] [PartialOrder β]
theorem isAtom_of_map_bot_of_image [OrderBot α] [OrderBot β] (f : β ↪o α) (hbot : f ⊥ = ⊥) {b : β}
(hb : IsAtom (f b)) : IsAtom b := by
simp only [← bot_covBy_iff] at hb ⊢
exact CovBy.of_image f (hbot.symm ▸ hb)
#align order_embedding.is_atom_of_map_bot_of_image OrderEmbedding.isAtom_of_map_bot_of_image
theorem isCoatom_of_map_top_of_image [OrderTop α] [OrderTop β] (f : β ↪o α) (htop : f ⊤ = ⊤)
{b : β} (hb : IsCoatom (f b)) : IsCoatom b :=
f.dual.isAtom_of_map_bot_of_image htop hb
#align order_embedding.is_coatom_of_map_top_of_image OrderEmbedding.isCoatom_of_map_top_of_image
end OrderEmbedding
namespace GaloisInsertion
variable [PartialOrder α] [PartialOrder β]
theorem isAtom_of_u_bot [OrderBot α] [OrderBot β] {l : α → β} {u : β → α}
(gi : GaloisInsertion l u) (hbot : u ⊥ = ⊥) {b : β} (hb : IsAtom (u b)) : IsAtom b :=
OrderEmbedding.isAtom_of_map_bot_of_image
⟨⟨u, gi.u_injective⟩, @GaloisInsertion.u_le_u_iff _ _ _ _ _ _ gi⟩ hbot hb
#align galois_insertion.is_atom_of_u_bot GaloisInsertion.isAtom_of_u_bot
theorem isAtom_iff [OrderBot α] [IsAtomic α] [OrderBot β] {l : α → β} {u : β → α}
(gi : GaloisInsertion l u) (hbot : u ⊥ = ⊥) (h_atom : ∀ a, IsAtom a → u (l a) = a) (a : α) :
IsAtom (l a) ↔ IsAtom a := by
refine ⟨fun hla => ?_, fun ha => gi.isAtom_of_u_bot hbot ((h_atom a ha).symm ▸ ha)⟩
obtain ⟨a', ha', hab'⟩ :=
(eq_bot_or_exists_atom_le (u (l a))).resolve_left (hbot ▸ fun h => hla.1 (gi.u_injective h))
have :=
(hla.le_iff.mp <| (gi.l_u_eq (l a) ▸ gi.gc.monotone_l hab' : l a' ≤ l a)).resolve_left fun h =>
ha'.1 (hbot ▸ h_atom a' ha' ▸ congr_arg u h)
have haa' : a = a' :=
(ha'.le_iff.mp <|
(gi.gc.le_u_l a).trans_eq (h_atom a' ha' ▸ congr_arg u this.symm)).resolve_left
(mt (congr_arg l) (gi.gc.l_bot.symm ▸ hla.1))
exact haa'.symm ▸ ha'
#align galois_insertion.is_atom_iff GaloisInsertion.isAtom_iff
theorem isAtom_iff' [OrderBot α] [IsAtomic α] [OrderBot β] {l : α → β} {u : β → α}
(gi : GaloisInsertion l u) (hbot : u ⊥ = ⊥) (h_atom : ∀ a, IsAtom a → u (l a) = a) (b : β) :
IsAtom (u b) ↔ IsAtom b := by rw [← gi.isAtom_iff hbot h_atom, gi.l_u_eq]
#align galois_insertion.is_atom_iff' GaloisInsertion.isAtom_iff'
theorem isCoatom_of_image [OrderTop α] [OrderTop β] {l : α → β} {u : β → α}
(gi : GaloisInsertion l u) {b : β} (hb : IsCoatom (u b)) : IsCoatom b :=
OrderEmbedding.isCoatom_of_map_top_of_image
⟨⟨u, gi.u_injective⟩, @GaloisInsertion.u_le_u_iff _ _ _ _ _ _ gi⟩ gi.gc.u_top hb
#align galois_insertion.is_coatom_of_image GaloisInsertion.isCoatom_of_image
theorem isCoatom_iff [OrderTop α] [IsCoatomic α] [OrderTop β] {l : α → β} {u : β → α}
(gi : GaloisInsertion l u) (h_coatom : ∀ a : α, IsCoatom a → u (l a) = a) (b : β) :
IsCoatom (u b) ↔ IsCoatom b := by
refine ⟨fun hb => gi.isCoatom_of_image hb, fun hb => ?_⟩
obtain ⟨a, ha, hab⟩ :=
(eq_top_or_exists_le_coatom (u b)).resolve_left fun h =>
hb.1 <| (gi.gc.u_top ▸ gi.l_u_eq ⊤ : l ⊤ = ⊤) ▸ gi.l_u_eq b ▸ congr_arg l h
have : l a = b :=
(hb.le_iff.mp (gi.l_u_eq b ▸ gi.gc.monotone_l hab : b ≤ l a)).resolve_left fun hla =>
ha.1 (gi.gc.u_top ▸ h_coatom a ha ▸ congr_arg u hla)
exact this ▸ (h_coatom a ha).symm ▸ ha
#align galois_insertion.is_coatom_iff GaloisInsertion.isCoatom_iff
end GaloisInsertion
namespace GaloisCoinsertion
variable [PartialOrder α] [PartialOrder β]
theorem isCoatom_of_l_top [OrderTop α] [OrderTop β] {l : α → β} {u : β → α}
(gi : GaloisCoinsertion l u) (hbot : l ⊤ = ⊤) {a : α} (hb : IsCoatom (l a)) : IsCoatom a :=
gi.dual.isAtom_of_u_bot hbot hb.dual
#align galois_coinsertion.is_coatom_of_l_top GaloisCoinsertion.isCoatom_of_l_top
theorem isCoatom_iff [OrderTop α] [OrderTop β] [IsCoatomic β] {l : α → β} {u : β → α}
(gi : GaloisCoinsertion l u) (htop : l ⊤ = ⊤) (h_coatom : ∀ b, IsCoatom b → l (u b) = b)
(b : β) : IsCoatom (u b) ↔ IsCoatom b :=
gi.dual.isAtom_iff htop h_coatom b
#align galois_coinsertion.is_coatom_iff GaloisCoinsertion.isCoatom_iff
theorem isCoatom_iff' [OrderTop α] [OrderTop β] [IsCoatomic β] {l : α → β} {u : β → α}
(gi : GaloisCoinsertion l u) (htop : l ⊤ = ⊤) (h_coatom : ∀ b, IsCoatom b → l (u b) = b)
(a : α) : IsCoatom (l a) ↔ IsCoatom a :=
gi.dual.isAtom_iff' htop h_coatom a
#align galois_coinsertion.is_coatom_iff' GaloisCoinsertion.isCoatom_iff'
theorem isAtom_of_image [OrderBot α] [OrderBot β] {l : α → β} {u : β → α}
(gi : GaloisCoinsertion l u) {a : α} (hb : IsAtom (l a)) : IsAtom a :=
gi.dual.isCoatom_of_image hb.dual
#align galois_coinsertion.is_atom_of_image GaloisCoinsertion.isAtom_of_image
theorem isAtom_iff [OrderBot α] [OrderBot β] [IsAtomic β] {l : α → β} {u : β → α}
(gi : GaloisCoinsertion l u) (h_atom : ∀ b, IsAtom b → l (u b) = b) (a : α) :
IsAtom (l a) ↔ IsAtom a :=
gi.dual.isCoatom_iff h_atom a
#align galois_coinsertion.is_atom_iff GaloisCoinsertion.isAtom_iff
end GaloisCoinsertion
namespace OrderIso
variable [PartialOrder α] [PartialOrder β]
@[simp]
theorem isAtom_iff [OrderBot α] [OrderBot β] (f : α ≃o β) (a : α) : IsAtom (f a) ↔ IsAtom a :=
⟨f.toGaloisCoinsertion.isAtom_of_image, fun ha =>
f.toGaloisInsertion.isAtom_of_u_bot (map_bot f.symm) <| (f.symm_apply_apply a).symm ▸ ha⟩
#align order_iso.is_atom_iff OrderIso.isAtom_iff
@[simp]
theorem isCoatom_iff [OrderTop α] [OrderTop β] (f : α ≃o β) (a : α) :
IsCoatom (f a) ↔ IsCoatom a :=
f.dual.isAtom_iff a
#align order_iso.is_coatom_iff OrderIso.isCoatom_iff
theorem isSimpleOrder_iff [BoundedOrder α] [BoundedOrder β] (f : α ≃o β) :
IsSimpleOrder α ↔ IsSimpleOrder β := by
rw [isSimpleOrder_iff_isAtom_top, isSimpleOrder_iff_isAtom_top, ← f.isAtom_iff ⊤,
f.map_top]
#align order_iso.is_simple_order_iff OrderIso.isSimpleOrder_iff
theorem isSimpleOrder [BoundedOrder α] [BoundedOrder β] [h : IsSimpleOrder β] (f : α ≃o β) :
IsSimpleOrder α :=
f.isSimpleOrder_iff.mpr h
#align order_iso.is_simple_order OrderIso.isSimpleOrder
protected theorem isAtomic_iff [OrderBot α] [OrderBot β] (f : α ≃o β) :
IsAtomic α ↔ IsAtomic β := by
simp only [isAtomic_iff, f.surjective.forall, f.surjective.exists, ← map_bot f, f.eq_iff_eq,
f.le_iff_le, f.isAtom_iff]
#align order_iso.is_atomic_iff OrderIso.isAtomic_iff
protected theorem isCoatomic_iff [OrderTop α] [OrderTop β] (f : α ≃o β) :
IsCoatomic α ↔ IsCoatomic β := by
simp only [← isAtomic_dual_iff_isCoatomic, f.dual.isAtomic_iff]
#align order_iso.is_coatomic_iff OrderIso.isCoatomic_iff
end OrderIso
section IsModularLattice
variable [Lattice α] [BoundedOrder α] [IsModularLattice α]
namespace IsCompl
variable {a b : α} (hc : IsCompl a b)
theorem isAtom_iff_isCoatom : IsAtom a ↔ IsCoatom b :=
Set.isSimpleOrder_Iic_iff_isAtom.symm.trans <|
hc.IicOrderIsoIci.isSimpleOrder_iff.trans Set.isSimpleOrder_Ici_iff_isCoatom
#align is_compl.is_atom_iff_is_coatom IsCompl.isAtom_iff_isCoatom
theorem isCoatom_iff_isAtom : IsCoatom a ↔ IsAtom b :=
hc.symm.isAtom_iff_isCoatom.symm
#align is_compl.is_coatom_iff_is_atom IsCompl.isCoatom_iff_isAtom
end IsCompl
variable [ComplementedLattice α]
theorem isCoatomic_of_isAtomic_of_complementedLattice_of_isModular [IsAtomic α] :
IsCoatomic α :=
⟨fun x => by
rcases exists_isCompl x with ⟨y, xy⟩
apply (eq_bot_or_exists_atom_le y).imp _ _
· rintro rfl
exact eq_top_of_isCompl_bot xy
· rintro ⟨a, ha, ay⟩
rcases exists_isCompl (xy.symm.IicOrderIsoIci ⟨a, ay⟩) with ⟨⟨b, xb⟩, hb⟩
refine ⟨↑(⟨b, xb⟩ : Set.Ici x), IsCoatom.of_isCoatom_coe_Ici ?_, xb⟩
rw [← hb.isAtom_iff_isCoatom, OrderIso.isAtom_iff]
apply ha.Iic⟩
#align is_coatomic_of_is_atomic_of_complemented_lattice_of_is_modular isCoatomic_of_isAtomic_of_complementedLattice_of_isModular
theorem isAtomic_of_isCoatomic_of_complementedLattice_of_isModular [IsCoatomic α] :
IsAtomic α :=
isCoatomic_dual_iff_isAtomic.1 isCoatomic_of_isAtomic_of_complementedLattice_of_isModular
#align is_atomic_of_is_coatomic_of_complemented_lattice_of_is_modular isAtomic_of_isCoatomic_of_complementedLattice_of_isModular
theorem isAtomic_iff_isCoatomic : IsAtomic α ↔ IsCoatomic α :=
⟨fun h => @isCoatomic_of_isAtomic_of_complementedLattice_of_isModular _ _ _ _ _ h, fun h =>
@isAtomic_of_isCoatomic_of_complementedLattice_of_isModular _ _ _ _ _ h⟩
#align is_atomic_iff_is_coatomic isAtomic_iff_isCoatomic
end IsModularLattice
namespace «Prop»
@[simp] theorem isAtom_iff {p : Prop} : IsAtom p ↔ p := by
simp [IsAtom, show ⊥ = False from rfl, fun q r : Prop => show q < r ↔ _ ∧ _ from .rfl]
@[simp] theorem isCoatom_iff {p : Prop} : IsCoatom p ↔ ¬ p := by
simp [IsCoatom, show ⊤ = True from rfl, fun q r : Prop => show q < r ↔ _ ∧ _ from .rfl]; tauto
instance : IsSimpleOrder Prop where
eq_bot_or_eq_top p := by simp [em']
end «Prop»
namespace Pi
variable {π : ι → Type u}
protected theorem eq_bot_iff [∀ i, Bot (π i)] {f : ∀ i, π i} : f = ⊥ ↔ ∀ i, f i = ⊥ :=
⟨(· ▸ by simp), fun h => funext fun i => by simp [h]⟩
| Mathlib/Order/Atoms.lean | 1,011 | 1,038 | theorem isAtom_iff {f : ∀ i, π i} [∀ i, PartialOrder (π i)] [∀ i, OrderBot (π i)] :
IsAtom f ↔ ∃ i, IsAtom (f i) ∧ ∀ j, j ≠ i → f j = ⊥ := by |
classical
constructor
case mpr =>
rintro ⟨i, ⟨hfi, hlt⟩, hbot⟩
refine ⟨fun h => hfi ((Pi.eq_bot_iff.1 h) _), fun g hgf => Pi.eq_bot_iff.2 fun j => ?_⟩
have ⟨hgf, k, hgfk⟩ := Pi.lt_def.1 hgf
obtain rfl : i = k := of_not_not fun hki => by rw [hbot _ (Ne.symm hki)] at hgfk; simp at hgfk
if hij : j = i then subst hij; refine hlt _ hgfk else
exact eq_bot_iff.2 <| le_trans (hgf _) (eq_bot_iff.1 (hbot _ hij))
case mp =>
rintro ⟨hbot, h⟩
have ⟨i, hbot⟩ : ∃ i, f i ≠ ⊥ := by rw [ne_eq, Pi.eq_bot_iff, not_forall] at hbot; exact hbot
refine ⟨i, ⟨hbot, ?c⟩, ?d⟩
case c =>
intro b hb
have := h (Function.update ⊥ i b)
simp only [lt_def, le_def, ge_iff_le, Pi.eq_bot_iff, and_imp, forall_exists_index] at this
simpa using this
(fun j => by by_cases h : j = i; { subst h; simpa using le_of_lt hb }; simp [h])
i (by simpa using hb) i
case d =>
intro j hj
have := h (Function.update ⊥ j (f j))
simp only [lt_def, le_def, ge_iff_le, Pi.eq_bot_iff, and_imp, forall_exists_index] at this
simpa using this (fun k => by by_cases h : k = j; { subst h; simp }; simp [h]) i
(by rwa [Function.update_noteq (Ne.symm hj), bot_apply, bot_lt_iff_ne_bot]) j
|
/-
Copyright (c) 2018 Mario Carneiro, Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Kevin Buzzard
-/
import Mathlib.Order.Filter.EventuallyConst
import Mathlib.Order.PartialSups
import Mathlib.Algebra.Module.Submodule.IterateMapComap
import Mathlib.RingTheory.OrzechProperty
import Mathlib.RingTheory.Nilpotent.Lemmas
#align_import ring_theory.noetherian from "leanprover-community/mathlib"@"210657c4ea4a4a7b234392f70a3a2a83346dfa90"
/-!
# Noetherian rings and modules
The following are equivalent for a module M over a ring R:
1. Every increasing chain of submodules M₁ ⊆ M₂ ⊆ M₃ ⊆ ⋯ eventually stabilises.
2. Every submodule is finitely generated.
A module satisfying these equivalent conditions is said to be a *Noetherian* R-module.
A ring is a *Noetherian ring* if it is Noetherian as a module over itself.
(Note that we do not assume yet that our rings are commutative,
so perhaps this should be called "left Noetherian".
To avoid cumbersome names once we specialize to the commutative case,
we don't make this explicit in the declaration names.)
## Main definitions
Let `R` be a ring and let `M` and `P` be `R`-modules. Let `N` be an `R`-submodule of `M`.
* `IsNoetherian R M` is the proposition that `M` is a Noetherian `R`-module. It is a class,
implemented as the predicate that all `R`-submodules of `M` are finitely generated.
## Main statements
* `isNoetherian_iff_wellFounded` is the theorem that an R-module M is Noetherian iff
`>` is well-founded on `Submodule R M`.
Note that the Hilbert basis theorem, that if a commutative ring R is Noetherian then so is R[X],
is proved in `RingTheory.Polynomial`.
## References
* [M. F. Atiyah and I. G. Macdonald, *Introduction to commutative algebra*][atiyah-macdonald]
* [samuel1967]
## Tags
Noetherian, noetherian, Noetherian ring, Noetherian module, noetherian ring, noetherian module
-/
open Set Filter Pointwise
/-- `IsNoetherian R M` is the proposition that `M` is a Noetherian `R`-module,
implemented as the predicate that all `R`-submodules of `M` are finitely generated.
-/
-- Porting note: should this be renamed to `Noetherian`?
class IsNoetherian (R M) [Semiring R] [AddCommMonoid M] [Module R M] : Prop where
noetherian : ∀ s : Submodule R M, s.FG
#align is_noetherian IsNoetherian
attribute [inherit_doc IsNoetherian] IsNoetherian.noetherian
section
variable {R : Type*} {M : Type*} {P : Type*}
variable [Semiring R] [AddCommMonoid M] [AddCommMonoid P]
variable [Module R M] [Module R P]
open IsNoetherian
/-- An R-module is Noetherian iff all its submodules are finitely-generated. -/
theorem isNoetherian_def : IsNoetherian R M ↔ ∀ s : Submodule R M, s.FG :=
⟨fun h => h.noetherian, IsNoetherian.mk⟩
#align is_noetherian_def isNoetherian_def
theorem isNoetherian_submodule {N : Submodule R M} :
IsNoetherian R N ↔ ∀ s : Submodule R M, s ≤ N → s.FG := by
refine ⟨fun ⟨hn⟩ => fun s hs =>
have : s ≤ LinearMap.range N.subtype := N.range_subtype.symm ▸ hs
Submodule.map_comap_eq_self this ▸ (hn _).map _,
fun h => ⟨fun s => ?_⟩⟩
have f := (Submodule.equivMapOfInjective N.subtype Subtype.val_injective s).symm
have h₁ := h (s.map N.subtype) (Submodule.map_subtype_le N s)
have h₂ : (⊤ : Submodule R (s.map N.subtype)).map f = ⊤ := by simp
have h₃ := ((Submodule.fg_top _).2 h₁).map (↑f : _ →ₗ[R] s)
exact (Submodule.fg_top _).1 (h₂ ▸ h₃)
#align is_noetherian_submodule isNoetherian_submodule
theorem isNoetherian_submodule_left {N : Submodule R M} :
IsNoetherian R N ↔ ∀ s : Submodule R M, (N ⊓ s).FG :=
isNoetherian_submodule.trans ⟨fun H _ => H _ inf_le_left, fun H _ hs => inf_of_le_right hs ▸ H _⟩
#align is_noetherian_submodule_left isNoetherian_submodule_left
theorem isNoetherian_submodule_right {N : Submodule R M} :
IsNoetherian R N ↔ ∀ s : Submodule R M, (s ⊓ N).FG :=
isNoetherian_submodule.trans ⟨fun H _ => H _ inf_le_right, fun H _ hs => inf_of_le_left hs ▸ H _⟩
#align is_noetherian_submodule_right isNoetherian_submodule_right
instance isNoetherian_submodule' [IsNoetherian R M] (N : Submodule R M) : IsNoetherian R N :=
isNoetherian_submodule.2 fun _ _ => IsNoetherian.noetherian _
#align is_noetherian_submodule' isNoetherian_submodule'
theorem isNoetherian_of_le {s t : Submodule R M} [ht : IsNoetherian R t] (h : s ≤ t) :
IsNoetherian R s :=
isNoetherian_submodule.mpr fun _ hs' => isNoetherian_submodule.mp ht _ (le_trans hs' h)
#align is_noetherian_of_le isNoetherian_of_le
variable (M)
theorem isNoetherian_of_surjective (f : M →ₗ[R] P) (hf : LinearMap.range f = ⊤) [IsNoetherian R M] :
IsNoetherian R P :=
⟨fun s =>
have : (s.comap f).map f = s := Submodule.map_comap_eq_self <| hf.symm ▸ le_top
this ▸ (noetherian _).map _⟩
#align is_noetherian_of_surjective isNoetherian_of_surjective
variable {M}
instance isNoetherian_quotient {R} [Ring R] {M} [AddCommGroup M] [Module R M]
(N : Submodule R M) [IsNoetherian R M] : IsNoetherian R (M ⧸ N) :=
isNoetherian_of_surjective _ _ (LinearMap.range_eq_top.mpr N.mkQ_surjective)
#align submodule.quotient.is_noetherian isNoetherian_quotient
@[deprecated (since := "2024-04-27"), nolint defLemma]
alias Submodule.Quotient.isNoetherian := isNoetherian_quotient
theorem isNoetherian_of_linearEquiv (f : M ≃ₗ[R] P) [IsNoetherian R M] : IsNoetherian R P :=
isNoetherian_of_surjective _ f.toLinearMap f.range
#align is_noetherian_of_linear_equiv isNoetherian_of_linearEquiv
theorem isNoetherian_top_iff : IsNoetherian R (⊤ : Submodule R M) ↔ IsNoetherian R M := by
constructor <;> intro h
· exact isNoetherian_of_linearEquiv (LinearEquiv.ofTop (⊤ : Submodule R M) rfl)
· exact isNoetherian_of_linearEquiv (LinearEquiv.ofTop (⊤ : Submodule R M) rfl).symm
#align is_noetherian_top_iff isNoetherian_top_iff
theorem isNoetherian_of_injective [IsNoetherian R P] (f : M →ₗ[R] P) (hf : Function.Injective f) :
IsNoetherian R M :=
isNoetherian_of_linearEquiv (LinearEquiv.ofInjective f hf).symm
#align is_noetherian_of_injective isNoetherian_of_injective
theorem fg_of_injective [IsNoetherian R P] {N : Submodule R M} (f : M →ₗ[R] P)
(hf : Function.Injective f) : N.FG :=
haveI := isNoetherian_of_injective f hf
IsNoetherian.noetherian N
#align fg_of_injective fg_of_injective
end
namespace Module
variable {R M N : Type*}
variable [Semiring R] [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N]
variable (R M)
-- see Note [lower instance priority]
instance (priority := 100) IsNoetherian.finite [IsNoetherian R M] : Finite R M :=
⟨IsNoetherian.noetherian ⊤⟩
#align module.is_noetherian.finite Module.IsNoetherian.finite
instance {R₁ S : Type*} [CommSemiring R₁] [Semiring S] [Algebra R₁ S]
[IsNoetherian R₁ S] (I : Ideal S) : Finite R₁ I :=
IsNoetherian.finite R₁ ((I : Submodule S S).restrictScalars R₁)
variable {R M}
theorem Finite.of_injective [IsNoetherian R N] (f : M →ₗ[R] N) (hf : Function.Injective f) :
Finite R M :=
⟨fg_of_injective f hf⟩
#align module.finite.of_injective Module.Finite.of_injective
end Module
section
variable {R : Type*} {M : Type*} {P : Type*}
variable [Ring R] [AddCommGroup M] [AddCommGroup P]
variable [Module R M] [Module R P]
open IsNoetherian
theorem isNoetherian_of_ker_bot [IsNoetherian R P] (f : M →ₗ[R] P) (hf : LinearMap.ker f = ⊥) :
IsNoetherian R M :=
isNoetherian_of_linearEquiv (LinearEquiv.ofInjective f <| LinearMap.ker_eq_bot.mp hf).symm
#align is_noetherian_of_ker_bot isNoetherian_of_ker_bot
theorem fg_of_ker_bot [IsNoetherian R P] {N : Submodule R M} (f : M →ₗ[R] P)
(hf : LinearMap.ker f = ⊥) : N.FG :=
haveI := isNoetherian_of_ker_bot f hf
IsNoetherian.noetherian N
#align fg_of_ker_bot fg_of_ker_bot
instance isNoetherian_prod [IsNoetherian R M] [IsNoetherian R P] : IsNoetherian R (M × P) :=
⟨fun s =>
Submodule.fg_of_fg_map_of_fg_inf_ker (LinearMap.snd R M P) (noetherian _) <|
have : s ⊓ LinearMap.ker (LinearMap.snd R M P) ≤ LinearMap.range (LinearMap.inl R M P) :=
fun x ⟨_, hx2⟩ => ⟨x.1, Prod.ext rfl <| Eq.symm <| LinearMap.mem_ker.1 hx2⟩
Submodule.map_comap_eq_self this ▸ (noetherian _).map _⟩
#align is_noetherian_prod isNoetherian_prod
instance isNoetherian_pi {R ι : Type*} {M : ι → Type*}
[Ring R] [∀ i, AddCommGroup (M i)] [∀ i, Module R (M i)] [Finite ι]
[∀ i, IsNoetherian R (M i)] : IsNoetherian R (∀ i, M i) := by
cases nonempty_fintype ι
haveI := Classical.decEq ι
suffices on_finset : ∀ s : Finset ι, IsNoetherian R (∀ i : s, M i) by
let coe_e := Equiv.subtypeUnivEquiv <| @Finset.mem_univ ι _
letI : IsNoetherian R (∀ i : Finset.univ, M (coe_e i)) := on_finset Finset.univ
exact isNoetherian_of_linearEquiv (LinearEquiv.piCongrLeft R M coe_e)
intro s
induction' s using Finset.induction with a s has ih
· exact ⟨fun s => by
have : s = ⊥ := by simp only [eq_iff_true_of_subsingleton]
rw [this]
apply Submodule.fg_bot⟩
refine
@isNoetherian_of_linearEquiv R (M a × ((i : s) → M i)) _ _ _ _ _ _ ?_ <|
@isNoetherian_prod R (M a) _ _ _ _ _ _ _ ih
refine
{ toFun := fun f i =>
(Finset.mem_insert.1 i.2).by_cases
(fun h : i.1 = a => show M i.1 from Eq.recOn h.symm f.1)
(fun h : i.1 ∈ s => show M i.1 from f.2 ⟨i.1, h⟩),
invFun := fun f =>
(f ⟨a, Finset.mem_insert_self _ _⟩, fun i => f ⟨i.1, Finset.mem_insert_of_mem i.2⟩),
map_add' := ?_,
map_smul' := ?_
left_inv := ?_,
right_inv := ?_ }
· intro f g
ext i
unfold Or.by_cases
cases' i with i hi
rcases Finset.mem_insert.1 hi with (rfl | h)
· change _ = _ + _
simp only [dif_pos]
rfl
· change _ = _ + _
have : ¬i = a := by
rintro rfl
exact has h
simp only [dif_neg this, dif_pos h]
rfl
· intro c f
ext i
unfold Or.by_cases
cases' i with i hi
rcases Finset.mem_insert.1 hi with (rfl | h)
· dsimp
simp only [dif_pos]
· dsimp
have : ¬i = a := by
rintro rfl
exact has h
simp only [dif_neg this, dif_pos h]
· intro f
apply Prod.ext
· simp only [Or.by_cases, dif_pos]
· ext ⟨i, his⟩
have : ¬i = a := by
rintro rfl
exact has his
simp only [Or.by_cases, this, not_false_iff, dif_neg]
· intro f
ext ⟨i, hi⟩
rcases Finset.mem_insert.1 hi with (rfl | h)
· simp only [Or.by_cases, dif_pos]
· have : ¬i = a := by
rintro rfl
exact has h
simp only [Or.by_cases, dif_neg this, dif_pos h]
#align is_noetherian_pi isNoetherian_pi
/-- A version of `isNoetherian_pi` for non-dependent functions. We need this instance because
sometimes Lean fails to apply the dependent version in non-dependent settings (e.g., it fails to
prove that `ι → ℝ` is finite dimensional over `ℝ`). -/
instance isNoetherian_pi' {R ι M : Type*} [Ring R] [AddCommGroup M] [Module R M] [Finite ι]
[IsNoetherian R M] : IsNoetherian R (ι → M) :=
isNoetherian_pi
#align is_noetherian_pi' isNoetherian_pi'
end
section CommRing
variable (R M N : Type*) [CommRing R] [AddCommGroup M] [AddCommGroup N] [Module R M] [Module R N]
[IsNoetherian R M] [Module.Finite R N]
instance isNoetherian_linearMap_pi {ι : Type*} [Finite ι] : IsNoetherian R ((ι → R) →ₗ[R] M) :=
let _i : Fintype ι := Fintype.ofFinite ι; isNoetherian_of_linearEquiv (Module.piEquiv ι R M)
instance isNoetherian_linearMap : IsNoetherian R (N →ₗ[R] M) := by
obtain ⟨n, f, hf⟩ := Module.Finite.exists_fin' R N
let g : (N →ₗ[R] M) →ₗ[R] (Fin n → R) →ₗ[R] M := (LinearMap.llcomp R (Fin n → R) N M).flip f
exact isNoetherian_of_injective g hf.injective_linearMapComp_right
end CommRing
open IsNoetherian Submodule Function
section
universe w
variable {R M P : Type*} {N : Type w} [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N]
[Module R N] [AddCommMonoid P] [Module R P]
theorem isNoetherian_iff_wellFounded :
IsNoetherian R M ↔ WellFounded ((· > ·) : Submodule R M → Submodule R M → Prop) := by
have := (CompleteLattice.wellFounded_characterisations <| Submodule R M).out 0 3
-- Porting note: inlining this makes rw complain about it being a metavariable
rw [this]
exact
⟨fun ⟨h⟩ => fun k => (fg_iff_compact k).mp (h k), fun h =>
⟨fun k => (fg_iff_compact k).mpr (h k)⟩⟩
#align is_noetherian_iff_well_founded isNoetherian_iff_wellFounded
theorem isNoetherian_iff_fg_wellFounded :
IsNoetherian R M ↔
WellFounded
((· > ·) : { N : Submodule R M // N.FG } → { N : Submodule R M // N.FG } → Prop) := by
let α := { N : Submodule R M // N.FG }
constructor
· intro H
let f : α ↪o Submodule R M := OrderEmbedding.subtype _
exact OrderEmbedding.wellFounded f.dual (isNoetherian_iff_wellFounded.mp H)
· intro H
constructor
intro N
obtain ⟨⟨N₀, h₁⟩, e : N₀ ≤ N, h₂⟩ :=
WellFounded.has_min H { N' : α | N'.1 ≤ N } ⟨⟨⊥, Submodule.fg_bot⟩, @bot_le _ _ _ N⟩
convert h₁
refine (e.antisymm ?_).symm
by_contra h₃
obtain ⟨x, hx₁ : x ∈ N, hx₂ : x ∉ N₀⟩ := Set.not_subset.mp h₃
apply hx₂
rw [eq_of_le_of_not_lt (le_sup_right : N₀ ≤ _) (h₂
⟨_, Submodule.FG.sup ⟨{x}, by rw [Finset.coe_singleton]⟩ h₁⟩ <|
sup_le ((Submodule.span_singleton_le_iff_mem _ _).mpr hx₁) e)]
exact (le_sup_left : (R ∙ x) ≤ _) (Submodule.mem_span_singleton_self _)
#align is_noetherian_iff_fg_well_founded isNoetherian_iff_fg_wellFounded
variable (R M)
theorem wellFounded_submodule_gt (R M) [Semiring R] [AddCommMonoid M] [Module R M] :
∀ [IsNoetherian R M], WellFounded ((· > ·) : Submodule R M → Submodule R M → Prop) :=
isNoetherian_iff_wellFounded.mp ‹_›
#align well_founded_submodule_gt wellFounded_submodule_gt
variable {R M}
/-- A module is Noetherian iff every nonempty set of submodules has a maximal submodule among them.
-/
theorem set_has_maximal_iff_noetherian :
(∀ a : Set <| Submodule R M, a.Nonempty → ∃ M' ∈ a, ∀ I ∈ a, ¬M' < I) ↔ IsNoetherian R M := by
rw [isNoetherian_iff_wellFounded, WellFounded.wellFounded_iff_has_min]
#align set_has_maximal_iff_noetherian set_has_maximal_iff_noetherian
/-- A module is Noetherian iff every increasing chain of submodules stabilizes. -/
theorem monotone_stabilizes_iff_noetherian :
(∀ f : ℕ →o Submodule R M, ∃ n, ∀ m, n ≤ m → f n = f m) ↔ IsNoetherian R M := by
rw [isNoetherian_iff_wellFounded, WellFounded.monotone_chain_condition]
#align monotone_stabilizes_iff_noetherian monotone_stabilizes_iff_noetherian
theorem eventuallyConst_of_isNoetherian [IsNoetherian R M] (f : ℕ →o Submodule R M) :
atTop.EventuallyConst f := by
simp_rw [eventuallyConst_atTop, eq_comm]
exact (monotone_stabilizes_iff_noetherian.mpr inferInstance) f
/-- If `∀ I > J, P I` implies `P J`, then `P` holds for all submodules. -/
theorem IsNoetherian.induction [IsNoetherian R M] {P : Submodule R M → Prop}
(hgt : ∀ I, (∀ J > I, P J) → P I) (I : Submodule R M) : P I :=
WellFounded.recursion (wellFounded_submodule_gt R M) I hgt
#align is_noetherian.induction IsNoetherian.induction
end
section
universe w
variable {R M P : Type*} {N : Type w} [Ring R] [AddCommGroup M] [Module R M] [AddCommGroup N]
[Module R N] [AddCommGroup P] [Module R P] [IsNoetherian R M]
lemma Submodule.finite_ne_bot_of_independent {ι : Type*} {N : ι → Submodule R M}
(h : CompleteLattice.Independent N) :
Set.Finite {i | N i ≠ ⊥} :=
CompleteLattice.WellFounded.finite_ne_bot_of_independent
(isNoetherian_iff_wellFounded.mp inferInstance) h
/-- A linearly-independent family of vectors in a module over a non-trivial ring must be finite if
the module is Noetherian. -/
theorem LinearIndependent.finite_of_isNoetherian [Nontrivial R] {ι} {v : ι → M}
(hv : LinearIndependent R v) : Finite ι := by
have hwf := isNoetherian_iff_wellFounded.mp (by infer_instance : IsNoetherian R M)
refine CompleteLattice.WellFounded.finite_of_independent hwf hv.independent_span_singleton
fun i contra => ?_
apply hv.ne_zero i
have : v i ∈ R ∙ v i := Submodule.mem_span_singleton_self (v i)
rwa [contra, Submodule.mem_bot] at this
#align linear_independent.finite_of_is_noetherian LinearIndependent.finite_of_isNoetherian
theorem LinearIndependent.set_finite_of_isNoetherian [Nontrivial R] {s : Set M}
(hi : LinearIndependent R ((↑) : s → M)) : s.Finite :=
@Set.toFinite _ _ hi.finite_of_isNoetherian
#align linear_independent.set_finite_of_is_noetherian LinearIndependent.set_finite_of_isNoetherian
@[deprecated]
alias finite_of_linearIndependent := LinearIndependent.set_finite_of_isNoetherian
#align finite_of_linear_independent LinearIndependent.set_finite_of_isNoetherian
/-- If the first and final modules in an exact sequence are Noetherian,
then the middle module is also Noetherian. -/
theorem isNoetherian_of_range_eq_ker [IsNoetherian R P]
(f : M →ₗ[R] N) (g : N →ₗ[R] P) (h : LinearMap.range f = LinearMap.ker g) :
IsNoetherian R N :=
isNoetherian_iff_wellFounded.2 <|
wellFounded_gt_exact_sequence
(wellFounded_submodule_gt R _) (wellFounded_submodule_gt R _)
(LinearMap.range f)
(Submodule.map (f.ker.liftQ f <| le_rfl))
(Submodule.comap (f.ker.liftQ f <| le_rfl))
(Submodule.comap g.rangeRestrict) (Submodule.map g.rangeRestrict)
(Submodule.gciMapComap <| LinearMap.ker_eq_bot.mp <|
Submodule.ker_liftQ_eq_bot _ _ _ (le_refl _))
(Submodule.giMapComap g.surjective_rangeRestrict)
(by simp [Submodule.map_comap_eq, inf_comm, Submodule.range_liftQ])
(by simp [Submodule.comap_map_eq, h])
#align is_noetherian_of_range_eq_ker isNoetherian_of_range_eq_ker
/-- For an endomorphism of a Noetherian module, any sufficiently large iterate has disjoint kernel
and range. -/
theorem LinearMap.eventually_disjoint_ker_pow_range_pow (f : M →ₗ[R] M) :
∀ᶠ n in atTop, Disjoint (LinearMap.ker (f ^ n)) (LinearMap.range (f ^ n)) := by
obtain ⟨n, hn : ∀ m, n ≤ m → LinearMap.ker (f ^ n) = LinearMap.ker (f ^ m)⟩ :=
monotone_stabilizes_iff_noetherian.mpr inferInstance f.iterateKer
refine eventually_atTop.mpr ⟨n, fun m hm ↦ disjoint_iff.mpr ?_⟩
rw [← hn _ hm, Submodule.eq_bot_iff]
rintro - ⟨hx, ⟨x, rfl⟩⟩
apply LinearMap.pow_map_zero_of_le hm
replace hx : x ∈ LinearMap.ker (f ^ (n + m)) := by
simpa [f.pow_apply n, f.pow_apply m, ← f.pow_apply (n + m), ← iterate_add_apply] using hx
rwa [← hn _ (n.le_add_right m)] at hx
#align is_noetherian.exists_endomorphism_iterate_ker_inf_range_eq_bot LinearMap.eventually_disjoint_ker_pow_range_pow
lemma LinearMap.eventually_iSup_ker_pow_eq (f : M →ₗ[R] M) :
∀ᶠ n in atTop, ⨆ m, LinearMap.ker (f ^ m) = LinearMap.ker (f ^ n) := by
obtain ⟨n, hn : ∀ m, n ≤ m → ker (f ^ n) = ker (f ^ m)⟩ :=
monotone_stabilizes_iff_noetherian.mpr inferInstance f.iterateKer
refine eventually_atTop.mpr ⟨n, fun m hm ↦ ?_⟩
refine le_antisymm (iSup_le fun l ↦ ?_) (le_iSup (fun i ↦ LinearMap.ker (f ^ i)) m)
rcases le_or_lt m l with h | h
· rw [← hn _ (hm.trans h), hn _ hm]
· exact f.iterateKer.monotone h.le
/-- **Orzech's theorem** for Noetherian module: if `R` is a ring (not necessarily commutative),
`M` and `N` are `R`-modules, `M` is Noetherian, `i : N →ₗ[R] M` is injective,
`f : N →ₗ[R] M` is surjective, then `f` is also injective. The proof here is adapted from
Djoković's paper *Epimorphisms of modules which must be isomorphisms* [djokovic1973],
utilizing `LinearMap.iterateMapComap`.
See also Orzech's original paper: *Onto endomorphisms are isomorphisms* [orzech1971]. -/
| Mathlib/RingTheory/Noetherian.lean | 467 | 473 | theorem IsNoetherian.injective_of_surjective_of_injective (i f : N →ₗ[R] M)
(hi : Injective i) (hf : Surjective f) : Injective f := by |
haveI := isNoetherian_of_injective i hi
obtain ⟨n, H⟩ := monotone_stabilizes_iff_noetherian.2 ‹_›
⟨_, monotone_nat_of_le_succ <| f.iterateMapComap_le_succ i ⊥ (by simp)⟩
exact LinearMap.ker_eq_bot.1 <| bot_unique <|
f.ker_le_of_iterateMapComap_eq_succ i ⊥ n (H _ (Nat.le_succ _)) hf hi
|
/-
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.Topology.Algebra.Module.WeakDual
import Mathlib.MeasureTheory.Integral.BoundedContinuousFunction
import Mathlib.MeasureTheory.Measure.HasOuterApproxClosed
#align_import measure_theory.measure.finite_measure from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982"
/-!
# Finite measures
This file defines the type of finite measures on a given measurable space. When the underlying
space has a topology and the measurable space structure (sigma algebra) is finer than the Borel
sigma algebra, then the type of finite measures is equipped with the topology of weak convergence
of measures. The topology of weak convergence is the coarsest topology w.r.t. which
for every bounded continuous `ℝ≥0`-valued function `f`, the integration of `f` against the
measure is continuous.
## Main definitions
The main definitions are
* `MeasureTheory.FiniteMeasure Ω`: The type of finite measures on `Ω` with the topology of weak
convergence of measures.
* `MeasureTheory.FiniteMeasure.toWeakDualBCNN : FiniteMeasure Ω → (WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0))`:
Interpret a finite measure as a continuous linear functional on the space of
bounded continuous nonnegative functions on `Ω`. This is used for the definition of the
topology of weak convergence.
* `MeasureTheory.FiniteMeasure.map`: The push-forward `f* μ` of a finite measure `μ` on `Ω`
along a measurable function `f : Ω → Ω'`.
* `MeasureTheory.FiniteMeasure.mapCLM`: The push-forward along a given continuous `f : Ω → Ω'`
as a continuous linear map `f* : FiniteMeasure Ω →L[ℝ≥0] FiniteMeasure Ω'`.
## Main results
* Finite measures `μ` on `Ω` give rise to continuous linear functionals on the space of
bounded continuous nonnegative functions on `Ω` via integration:
`MeasureTheory.FiniteMeasure.toWeakDualBCNN : FiniteMeasure Ω → (WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0))`
* `MeasureTheory.FiniteMeasure.tendsto_iff_forall_integral_tendsto`: Convergence of finite
measures is characterized by the convergence of integrals of all bounded continuous functions.
This shows that the chosen definition of topology coincides with the common textbook definition
of weak convergence of measures. A similar characterization by the convergence of integrals (in
the `MeasureTheory.lintegral` sense) of all bounded continuous nonnegative functions is
`MeasureTheory.FiniteMeasure.tendsto_iff_forall_lintegral_tendsto`.
* `MeasureTheory.FiniteMeasure.continuous_map`: For a continuous function `f : Ω → Ω'`, the
push-forward of finite measures `f* : FiniteMeasure Ω → FiniteMeasure Ω'` is continuous.
* `MeasureTheory.FiniteMeasure.t2Space`: The topology of weak convergence of finite Borel measures
is Hausdorff on spaces where indicators of closed sets have continuous decreasing approximating
sequences (in particular on any pseudo-metrizable spaces).
## Implementation notes
The topology of weak convergence of finite Borel measures is defined using a mapping from
`MeasureTheory.FiniteMeasure Ω` to `WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0)`, inheriting the topology from the
latter.
The implementation of `MeasureTheory.FiniteMeasure Ω` and is directly as a subtype of
`MeasureTheory.Measure Ω`, and the coercion to a function is the composition `ENNReal.toNNReal`
and the coercion to function of `MeasureTheory.Measure Ω`. Another alternative would have been to
use a bijection with `MeasureTheory.VectorMeasure Ω ℝ≥0` as an intermediate step. Some
considerations:
* Potential advantages of using the `NNReal`-valued vector measure alternative:
* The coercion to function would avoid need to compose with `ENNReal.toNNReal`, the
`NNReal`-valued API could be more directly available.
* Potential drawbacks of the vector measure alternative:
* The coercion to function would lose monotonicity, as non-measurable sets would be defined to
have measure 0.
* No integration theory directly. E.g., the topology definition requires
`MeasureTheory.lintegral` w.r.t. a coercion to `MeasureTheory.Measure Ω` in any case.
## References
* [Billingsley, *Convergence of probability measures*][billingsley1999]
## Tags
weak convergence of measures, finite measure
-/
noncomputable section
open MeasureTheory
open Set
open Filter
open BoundedContinuousFunction
open scoped Topology ENNReal NNReal BoundedContinuousFunction
namespace MeasureTheory
namespace FiniteMeasure
section FiniteMeasure
/-! ### Finite measures
In this section we define the `Type` of `MeasureTheory.FiniteMeasure Ω`, when `Ω` is a measurable
space. Finite measures on `Ω` are a module over `ℝ≥0`.
If `Ω` is moreover a topological space and the sigma algebra on `Ω` is finer than the Borel sigma
algebra (i.e. `[OpensMeasurableSpace Ω]`), then `MeasureTheory.FiniteMeasure Ω` is equipped with
the topology of weak convergence of measures. This is implemented by defining a pairing of finite
measures `μ` on `Ω` with continuous bounded nonnegative functions `f : Ω →ᵇ ℝ≥0` via integration,
and using the associated weak topology (essentially the weak-star topology on the dual of
`Ω →ᵇ ℝ≥0`).
-/
variable {Ω : Type*} [MeasurableSpace Ω]
/-- Finite measures are defined as the subtype of measures that have the property of being finite
measures (i.e., their total mass is finite). -/
def _root_.MeasureTheory.FiniteMeasure (Ω : Type*) [MeasurableSpace Ω] : Type _ :=
{ μ : Measure Ω // IsFiniteMeasure μ }
#align measure_theory.finite_measure MeasureTheory.FiniteMeasure
-- 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.FiniteMeasure Ω` to `MeasureTheory.Measure Ω`. -/
@[coe]
def toMeasure : FiniteMeasure Ω → Measure Ω := Subtype.val
/-- A finite measure can be interpreted as a measure. -/
instance instCoe : Coe (FiniteMeasure Ω) (MeasureTheory.Measure Ω) where
coe := toMeasure
instance isFiniteMeasure (μ : FiniteMeasure Ω) : IsFiniteMeasure (μ : Measure Ω) :=
μ.prop
#align measure_theory.finite_measure.is_finite_measure MeasureTheory.FiniteMeasure.isFiniteMeasure
@[simp]
theorem val_eq_toMeasure (ν : FiniteMeasure Ω) : ν.val = (ν : Measure Ω) :=
rfl
#align measure_theory.finite_measure.val_eq_to_measure MeasureTheory.FiniteMeasure.val_eq_toMeasure
theorem toMeasure_injective : Function.Injective ((↑) : FiniteMeasure Ω → Measure Ω) :=
Subtype.coe_injective
#align measure_theory.finite_measure.coe_injective MeasureTheory.FiniteMeasure.toMeasure_injective
instance instFunLike : FunLike (FiniteMeasure Ω) (Set Ω) ℝ≥0 where
coe μ s := ((μ : Measure Ω) s).toNNReal
coe_injective' μ ν h := toMeasure_injective $ Measure.ext fun s _ ↦ by
simpa [ENNReal.toNNReal_eq_toNNReal_iff, measure_ne_top] using congr_fun h s
lemma coeFn_def (μ : FiniteMeasure Ω) : μ = fun s ↦ ((μ : Measure Ω) s).toNNReal := rfl
#align measure_theory.finite_measure.coe_fn_eq_to_nnreal_coe_fn_to_measure MeasureTheory.FiniteMeasure.coeFn_def
lemma coeFn_mk (μ : Measure Ω) (hμ) :
DFunLike.coe (F := FiniteMeasure Ω) ⟨μ, hμ⟩ = fun s ↦ (μ s).toNNReal := rfl
@[simp, norm_cast]
lemma mk_apply (μ : Measure Ω) (hμ) (s : Set Ω) :
DFunLike.coe (F := FiniteMeasure Ω) ⟨μ, hμ⟩ s = (μ s).toNNReal := rfl
@[simp]
theorem ennreal_coeFn_eq_coeFn_toMeasure (ν : FiniteMeasure Ω) (s : Set Ω) :
(ν s : ℝ≥0∞) = (ν : Measure Ω) s :=
ENNReal.coe_toNNReal (measure_lt_top (↑ν) s).ne
#align measure_theory.finite_measure.ennreal_coe_fn_eq_coe_fn_to_measure MeasureTheory.FiniteMeasure.ennreal_coeFn_eq_coeFn_toMeasure
theorem apply_mono (μ : FiniteMeasure Ω) {s₁ s₂ : Set Ω} (h : s₁ ⊆ s₂) : μ s₁ ≤ μ s₂ := by
change ((μ : Measure Ω) s₁).toNNReal ≤ ((μ : Measure Ω) s₂).toNNReal
have key : (μ : Measure Ω) s₁ ≤ (μ : Measure Ω) s₂ := (μ : Measure Ω).mono h
apply (ENNReal.toNNReal_le_toNNReal (measure_ne_top _ s₁) (measure_ne_top _ s₂)).mpr key
#align measure_theory.finite_measure.apply_mono MeasureTheory.FiniteMeasure.apply_mono
/-- The (total) mass of a finite measure `μ` is `μ univ`, i.e., the cast to `NNReal` of
`(μ : measure Ω) univ`. -/
def mass (μ : FiniteMeasure Ω) : ℝ≥0 :=
μ univ
#align measure_theory.finite_measure.mass MeasureTheory.FiniteMeasure.mass
@[simp] theorem apply_le_mass (μ : FiniteMeasure Ω) (s : Set Ω) : μ s ≤ μ.mass := by
simpa using apply_mono μ (subset_univ s)
@[simp]
theorem ennreal_mass {μ : FiniteMeasure Ω} : (μ.mass : ℝ≥0∞) = (μ : Measure Ω) univ :=
ennreal_coeFn_eq_coeFn_toMeasure μ Set.univ
#align measure_theory.finite_measure.ennreal_mass MeasureTheory.FiniteMeasure.ennreal_mass
instance instZero : Zero (FiniteMeasure Ω) where zero := ⟨0, MeasureTheory.isFiniteMeasureZero⟩
#align measure_theory.finite_measure.has_zero MeasureTheory.FiniteMeasure.instZero
@[simp, norm_cast] lemma coeFn_zero : ⇑(0 : FiniteMeasure Ω) = 0 := rfl
#align measure_theory.finite_measure.coe_fn_zero MeasureTheory.FiniteMeasure.coeFn_zero
@[simp]
theorem zero_mass : (0 : FiniteMeasure Ω).mass = 0 :=
rfl
#align measure_theory.finite_measure.zero.mass MeasureTheory.FiniteMeasure.zero_mass
@[simp]
theorem mass_zero_iff (μ : FiniteMeasure Ω) : μ.mass = 0 ↔ μ = 0 := by
refine ⟨fun μ_mass => ?_, fun hμ => by simp only [hμ, zero_mass]⟩
apply toMeasure_injective
apply Measure.measure_univ_eq_zero.mp
rwa [← ennreal_mass, ENNReal.coe_eq_zero]
#align measure_theory.finite_measure.mass_zero_iff MeasureTheory.FiniteMeasure.mass_zero_iff
theorem mass_nonzero_iff (μ : FiniteMeasure Ω) : μ.mass ≠ 0 ↔ μ ≠ 0 := by
rw [not_iff_not]
exact FiniteMeasure.mass_zero_iff μ
#align measure_theory.finite_measure.mass_nonzero_iff MeasureTheory.FiniteMeasure.mass_nonzero_iff
@[ext]
theorem eq_of_forall_toMeasure_apply_eq (μ ν : FiniteMeasure Ω)
(h : ∀ s : Set Ω, MeasurableSet s → (μ : Measure Ω) s = (ν : Measure Ω) s) : μ = ν := by
apply Subtype.ext
ext1 s s_mble
exact h s s_mble
#align measure_theory.finite_measure.eq_of_forall_measure_apply_eq MeasureTheory.FiniteMeasure.eq_of_forall_toMeasure_apply_eq
theorem eq_of_forall_apply_eq (μ ν : FiniteMeasure Ω)
(h : ∀ s : Set Ω, MeasurableSet s → μ s = ν s) : μ = ν := by
ext1 s s_mble
simpa [ennreal_coeFn_eq_coeFn_toMeasure] using congr_arg ((↑) : ℝ≥0 → ℝ≥0∞) (h s s_mble)
#align measure_theory.finite_measure.eq_of_forall_apply_eq MeasureTheory.FiniteMeasure.eq_of_forall_apply_eq
instance instInhabited : Inhabited (FiniteMeasure Ω) :=
⟨0⟩
instance instAdd : Add (FiniteMeasure Ω) where add μ ν := ⟨μ + ν, MeasureTheory.isFiniteMeasureAdd⟩
variable {R : Type*} [SMul R ℝ≥0] [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0 ℝ≥0∞]
[IsScalarTower R ℝ≥0∞ ℝ≥0∞]
instance instSMul : SMul R (FiniteMeasure Ω) where
smul (c : R) μ := ⟨c • (μ : Measure Ω), MeasureTheory.isFiniteMeasureSMulOfNNRealTower⟩
@[simp, norm_cast]
theorem toMeasure_zero : ((↑) : FiniteMeasure Ω → Measure Ω) 0 = 0 :=
rfl
#align measure_theory.finite_measure.coe_zero MeasureTheory.FiniteMeasure.toMeasure_zero
-- Porting note: with `simp` here the `coeFn` lemmas below fall prey to `simpNF`: the LHS simplifies
@[norm_cast]
theorem toMeasure_add (μ ν : FiniteMeasure Ω) : ↑(μ + ν) = (↑μ + ↑ν : Measure Ω) :=
rfl
#align measure_theory.finite_measure.coe_add MeasureTheory.FiniteMeasure.toMeasure_add
@[simp, norm_cast]
theorem toMeasure_smul (c : R) (μ : FiniteMeasure Ω) : ↑(c • μ) = c • (μ : Measure Ω) :=
rfl
#align measure_theory.finite_measure.coe_smul MeasureTheory.FiniteMeasure.toMeasure_smul
@[simp, norm_cast]
theorem coeFn_add (μ ν : FiniteMeasure Ω) : (⇑(μ + ν) : Set Ω → ℝ≥0) = (⇑μ + ⇑ν : Set Ω → ℝ≥0) := by
funext
simp only [Pi.add_apply, ← ENNReal.coe_inj, ne_eq, ennreal_coeFn_eq_coeFn_toMeasure,
ENNReal.coe_add]
norm_cast
#align measure_theory.finite_measure.coe_fn_add MeasureTheory.FiniteMeasure.coeFn_add
@[simp, norm_cast]
theorem coeFn_smul [IsScalarTower R ℝ≥0 ℝ≥0] (c : R) (μ : FiniteMeasure Ω) :
(⇑(c • μ) : Set Ω → ℝ≥0) = c • (⇑μ : Set Ω → ℝ≥0) := by
funext; simp [← ENNReal.coe_inj, ENNReal.coe_smul]
#align measure_theory.finite_measure.coe_fn_smul MeasureTheory.FiniteMeasure.coeFn_smul
instance instAddCommMonoid : AddCommMonoid (FiniteMeasure Ω) :=
toMeasure_injective.addCommMonoid (↑) toMeasure_zero toMeasure_add fun _ _ => toMeasure_smul _ _
/-- Coercion is an `AddMonoidHom`. -/
@[simps]
def toMeasureAddMonoidHom : FiniteMeasure Ω →+ Measure Ω where
toFun := (↑)
map_zero' := toMeasure_zero
map_add' := toMeasure_add
#align measure_theory.finite_measure.coe_add_monoid_hom MeasureTheory.FiniteMeasure.toMeasureAddMonoidHom
instance {Ω : Type*} [MeasurableSpace Ω] : Module ℝ≥0 (FiniteMeasure Ω) :=
Function.Injective.module _ toMeasureAddMonoidHom toMeasure_injective toMeasure_smul
@[simp]
theorem smul_apply [IsScalarTower R ℝ≥0 ℝ≥0] (c : R) (μ : FiniteMeasure Ω) (s : Set Ω) :
(c • μ) s = c • μ s := by
rw [coeFn_smul, Pi.smul_apply]
#align measure_theory.finite_measure.coe_fn_smul_apply MeasureTheory.FiniteMeasure.smul_apply
/-- Restrict a finite measure μ to a set A. -/
def restrict (μ : FiniteMeasure Ω) (A : Set Ω) : FiniteMeasure Ω where
val := (μ : Measure Ω).restrict A
property := MeasureTheory.isFiniteMeasureRestrict (μ : Measure Ω) A
#align measure_theory.finite_measure.restrict MeasureTheory.FiniteMeasure.restrict
theorem restrict_measure_eq (μ : FiniteMeasure Ω) (A : Set Ω) :
(μ.restrict A : Measure Ω) = (μ : Measure Ω).restrict A :=
rfl
#align measure_theory.finite_measure.restrict_measure_eq MeasureTheory.FiniteMeasure.restrict_measure_eq
theorem restrict_apply_measure (μ : FiniteMeasure Ω) (A : Set Ω) {s : Set Ω}
(s_mble : MeasurableSet s) : (μ.restrict A : Measure Ω) s = (μ : Measure Ω) (s ∩ A) :=
Measure.restrict_apply s_mble
#align measure_theory.finite_measure.restrict_apply_measure MeasureTheory.FiniteMeasure.restrict_apply_measure
theorem restrict_apply (μ : FiniteMeasure Ω) (A : Set Ω) {s : Set Ω} (s_mble : MeasurableSet s) :
(μ.restrict A) s = μ (s ∩ A) := by
apply congr_arg ENNReal.toNNReal
exact Measure.restrict_apply s_mble
#align measure_theory.finite_measure.restrict_apply MeasureTheory.FiniteMeasure.restrict_apply
theorem restrict_mass (μ : FiniteMeasure Ω) (A : Set Ω) : (μ.restrict A).mass = μ A := by
simp only [mass, restrict_apply μ A MeasurableSet.univ, univ_inter]
#align measure_theory.finite_measure.restrict_mass MeasureTheory.FiniteMeasure.restrict_mass
theorem restrict_eq_zero_iff (μ : FiniteMeasure Ω) (A : Set Ω) : μ.restrict A = 0 ↔ μ A = 0 := by
rw [← mass_zero_iff, restrict_mass]
#align measure_theory.finite_measure.restrict_eq_zero_iff MeasureTheory.FiniteMeasure.restrict_eq_zero_iff
theorem restrict_nonzero_iff (μ : FiniteMeasure Ω) (A : Set Ω) : μ.restrict A ≠ 0 ↔ μ A ≠ 0 := by
rw [← mass_nonzero_iff, restrict_mass]
#align measure_theory.finite_measure.restrict_nonzero_iff MeasureTheory.FiniteMeasure.restrict_nonzero_iff
variable [TopologicalSpace Ω]
/-- Two finite Borel measures are equal if the integrals of all bounded continuous functions with
respect to both agree. -/
theorem ext_of_forall_lintegral_eq [HasOuterApproxClosed Ω] [BorelSpace Ω]
{μ ν : FiniteMeasure Ω} (h : ∀ (f : Ω →ᵇ ℝ≥0), ∫⁻ x, f x ∂μ = ∫⁻ x, f x ∂ν) :
μ = ν := by
apply Subtype.ext
change (μ : Measure Ω) = (ν : Measure Ω)
exact ext_of_forall_lintegral_eq_of_IsFiniteMeasure h
/-- The pairing of a finite (Borel) measure `μ` with a nonnegative bounded continuous
function is obtained by (Lebesgue) integrating the (test) function against the measure.
This is `MeasureTheory.FiniteMeasure.testAgainstNN`. -/
def testAgainstNN (μ : FiniteMeasure Ω) (f : Ω →ᵇ ℝ≥0) : ℝ≥0 :=
(∫⁻ ω, f ω ∂(μ : Measure Ω)).toNNReal
#align measure_theory.finite_measure.test_against_nn MeasureTheory.FiniteMeasure.testAgainstNN
@[simp]
theorem testAgainstNN_coe_eq {μ : FiniteMeasure Ω} {f : Ω →ᵇ ℝ≥0} :
(μ.testAgainstNN f : ℝ≥0∞) = ∫⁻ ω, f ω ∂(μ : Measure Ω) :=
ENNReal.coe_toNNReal (f.lintegral_lt_top_of_nnreal _).ne
#align measure_theory.finite_measure.test_against_nn_coe_eq MeasureTheory.FiniteMeasure.testAgainstNN_coe_eq
theorem testAgainstNN_const (μ : FiniteMeasure Ω) (c : ℝ≥0) :
μ.testAgainstNN (BoundedContinuousFunction.const Ω c) = c * μ.mass := by
simp [← ENNReal.coe_inj]
#align measure_theory.finite_measure.test_against_nn_const MeasureTheory.FiniteMeasure.testAgainstNN_const
theorem testAgainstNN_mono (μ : FiniteMeasure Ω) {f g : Ω →ᵇ ℝ≥0} (f_le_g : (f : Ω → ℝ≥0) ≤ g) :
μ.testAgainstNN f ≤ μ.testAgainstNN g := by
simp only [← ENNReal.coe_le_coe, testAgainstNN_coe_eq]
gcongr
apply f_le_g
#align measure_theory.finite_measure.test_against_nn_mono MeasureTheory.FiniteMeasure.testAgainstNN_mono
@[simp]
theorem testAgainstNN_zero (μ : FiniteMeasure Ω) : μ.testAgainstNN 0 = 0 := by
simpa only [zero_mul] using μ.testAgainstNN_const 0
#align measure_theory.finite_measure.test_against_nn_zero MeasureTheory.FiniteMeasure.testAgainstNN_zero
@[simp]
theorem testAgainstNN_one (μ : FiniteMeasure Ω) : μ.testAgainstNN 1 = μ.mass := by
simp only [testAgainstNN, coe_one, Pi.one_apply, ENNReal.coe_one, lintegral_one]
rfl
#align measure_theory.finite_measure.test_against_nn_one MeasureTheory.FiniteMeasure.testAgainstNN_one
@[simp]
theorem zero_testAgainstNN_apply (f : Ω →ᵇ ℝ≥0) : (0 : FiniteMeasure Ω).testAgainstNN f = 0 := by
simp only [testAgainstNN, toMeasure_zero, lintegral_zero_measure, ENNReal.zero_toNNReal]
#align measure_theory.finite_measure.zero.test_against_nn_apply MeasureTheory.FiniteMeasure.zero_testAgainstNN_apply
theorem zero_testAgainstNN : (0 : FiniteMeasure Ω).testAgainstNN = 0 := by
funext;
simp only [zero_testAgainstNN_apply, Pi.zero_apply]
#align measure_theory.finite_measure.zero.test_against_nn MeasureTheory.FiniteMeasure.zero_testAgainstNN
@[simp]
theorem smul_testAgainstNN_apply (c : ℝ≥0) (μ : FiniteMeasure Ω) (f : Ω →ᵇ ℝ≥0) :
(c • μ).testAgainstNN f = c • μ.testAgainstNN f := by
simp only [testAgainstNN, toMeasure_smul, smul_eq_mul, ← ENNReal.smul_toNNReal, ENNReal.smul_def,
lintegral_smul_measure]
#align measure_theory.finite_measure.smul_test_against_nn_apply MeasureTheory.FiniteMeasure.smul_testAgainstNN_apply
section weak_convergence
variable [OpensMeasurableSpace Ω]
theorem testAgainstNN_add (μ : FiniteMeasure Ω) (f₁ f₂ : Ω →ᵇ ℝ≥0) :
μ.testAgainstNN (f₁ + f₂) = μ.testAgainstNN f₁ + μ.testAgainstNN f₂ := by
simp only [← ENNReal.coe_inj, BoundedContinuousFunction.coe_add, ENNReal.coe_add, Pi.add_apply,
testAgainstNN_coe_eq]
exact lintegral_add_left (BoundedContinuousFunction.measurable_coe_ennreal_comp _) _
#align measure_theory.finite_measure.test_against_nn_add MeasureTheory.FiniteMeasure.testAgainstNN_add
theorem testAgainstNN_smul [IsScalarTower R ℝ≥0 ℝ≥0] [PseudoMetricSpace R] [Zero R]
[BoundedSMul R ℝ≥0] (μ : FiniteMeasure Ω) (c : R) (f : Ω →ᵇ ℝ≥0) :
μ.testAgainstNN (c • f) = c • μ.testAgainstNN f := by
simp only [← ENNReal.coe_inj, BoundedContinuousFunction.coe_smul, testAgainstNN_coe_eq,
ENNReal.coe_smul]
simp_rw [← smul_one_smul ℝ≥0∞ c (f _ : ℝ≥0∞), ← smul_one_smul ℝ≥0∞ c (lintegral _ _ : ℝ≥0∞),
smul_eq_mul]
exact
@lintegral_const_mul _ _ (μ : Measure Ω) (c • (1 : ℝ≥0∞)) _ f.measurable_coe_ennreal_comp
#align measure_theory.finite_measure.test_against_nn_smul MeasureTheory.FiniteMeasure.testAgainstNN_smul
theorem testAgainstNN_lipschitz_estimate (μ : FiniteMeasure Ω) (f g : Ω →ᵇ ℝ≥0) :
μ.testAgainstNN f ≤ μ.testAgainstNN g + nndist f g * μ.mass := by
simp only [← μ.testAgainstNN_const (nndist f g), ← testAgainstNN_add, ← ENNReal.coe_le_coe,
BoundedContinuousFunction.coe_add, const_apply, ENNReal.coe_add, Pi.add_apply,
coe_nnreal_ennreal_nndist, testAgainstNN_coe_eq]
apply lintegral_mono
have le_dist : ∀ ω, dist (f ω) (g ω) ≤ nndist f g := BoundedContinuousFunction.dist_coe_le_dist
intro ω
have le' : f ω ≤ g ω + nndist f g := by
apply (NNReal.le_add_nndist (f ω) (g ω)).trans
rw [add_le_add_iff_left]
exact dist_le_coe.mp (le_dist ω)
have le : (f ω : ℝ≥0∞) ≤ (g ω : ℝ≥0∞) + nndist f g := by
rw [← ENNReal.coe_add];
exact ENNReal.coe_mono le'
rwa [coe_nnreal_ennreal_nndist] at le
#align measure_theory.finite_measure.test_against_nn_lipschitz_estimate MeasureTheory.FiniteMeasure.testAgainstNN_lipschitz_estimate
theorem testAgainstNN_lipschitz (μ : FiniteMeasure Ω) :
LipschitzWith μ.mass fun f : Ω →ᵇ ℝ≥0 => μ.testAgainstNN f := by
rw [lipschitzWith_iff_dist_le_mul]
intro f₁ f₂
suffices abs (μ.testAgainstNN f₁ - μ.testAgainstNN f₂ : ℝ) ≤ μ.mass * dist f₁ f₂ by
rwa [NNReal.dist_eq]
apply abs_le.mpr
constructor
· have key' := μ.testAgainstNN_lipschitz_estimate f₂ f₁
rw [mul_comm] at key'
suffices ↑(μ.testAgainstNN f₂) ≤ ↑(μ.testAgainstNN f₁) + ↑μ.mass * dist f₁ f₂ by linarith
have key := NNReal.coe_mono key'
rwa [NNReal.coe_add, NNReal.coe_mul, nndist_comm] at key
· have key' := μ.testAgainstNN_lipschitz_estimate f₁ f₂
rw [mul_comm] at key'
suffices ↑(μ.testAgainstNN f₁) ≤ ↑(μ.testAgainstNN f₂) + ↑μ.mass * dist f₁ f₂ by linarith
have key := NNReal.coe_mono key'
rwa [NNReal.coe_add, NNReal.coe_mul] at key
#align measure_theory.finite_measure.test_against_nn_lipschitz MeasureTheory.FiniteMeasure.testAgainstNN_lipschitz
/-- Finite measures yield elements of the `WeakDual` of bounded continuous nonnegative
functions via `MeasureTheory.FiniteMeasure.testAgainstNN`, i.e., integration. -/
def toWeakDualBCNN (μ : FiniteMeasure Ω) : WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0) where
toFun f := μ.testAgainstNN f
map_add' := testAgainstNN_add μ
map_smul' := testAgainstNN_smul μ
cont := μ.testAgainstNN_lipschitz.continuous
#align measure_theory.finite_measure.to_weak_dual_bcnn MeasureTheory.FiniteMeasure.toWeakDualBCNN
@[simp]
theorem coe_toWeakDualBCNN (μ : FiniteMeasure Ω) : ⇑μ.toWeakDualBCNN = μ.testAgainstNN :=
rfl
#align measure_theory.finite_measure.coe_to_weak_dual_bcnn MeasureTheory.FiniteMeasure.coe_toWeakDualBCNN
@[simp]
theorem toWeakDualBCNN_apply (μ : FiniteMeasure Ω) (f : Ω →ᵇ ℝ≥0) :
μ.toWeakDualBCNN f = (∫⁻ x, f x ∂(μ : Measure Ω)).toNNReal :=
rfl
#align measure_theory.finite_measure.to_weak_dual_bcnn_apply MeasureTheory.FiniteMeasure.toWeakDualBCNN_apply
/-- The topology of weak convergence on `MeasureTheory.FiniteMeasure Ω` is inherited (induced)
from the weak-* topology on `WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0)` via the function
`MeasureTheory.FiniteMeasure.toWeakDualBCNN`. -/
instance instTopologicalSpace : TopologicalSpace (FiniteMeasure Ω) :=
TopologicalSpace.induced toWeakDualBCNN inferInstance
theorem toWeakDualBCNN_continuous : Continuous (@toWeakDualBCNN Ω _ _ _) :=
continuous_induced_dom
#align measure_theory.finite_measure.to_weak_dual_bcnn_continuous MeasureTheory.FiniteMeasure.toWeakDualBCNN_continuous
/-- Integration of (nonnegative bounded continuous) test functions against finite Borel measures
depends continuously on the measure. -/
theorem continuous_testAgainstNN_eval (f : Ω →ᵇ ℝ≥0) :
Continuous fun μ : FiniteMeasure Ω => μ.testAgainstNN f := by
show Continuous ((fun φ : WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0) => φ f) ∘ toWeakDualBCNN)
refine Continuous.comp ?_ (toWeakDualBCNN_continuous (Ω := Ω))
exact WeakBilin.eval_continuous (𝕜 := ℝ≥0) (E := (Ω →ᵇ ℝ≥0) →L[ℝ≥0] ℝ≥0) _ _
/- porting note: without explicitly providing `𝕜` and `E` TC synthesis times
out trying to find `Module ℝ≥0 ((Ω →ᵇ ℝ≥0) →L[ℝ≥0] ℝ≥0)`, but it can find it with enough time:
`set_option synthInstance.maxHeartbeats 47000` was sufficient. -/
#align measure_theory.finite_measure.continuous_test_against_nn_eval MeasureTheory.FiniteMeasure.continuous_testAgainstNN_eval
/-- The total mass of a finite measure depends continuously on the measure. -/
theorem continuous_mass : Continuous fun μ : FiniteMeasure Ω => μ.mass := by
simp_rw [← testAgainstNN_one]; exact continuous_testAgainstNN_eval 1
#align measure_theory.finite_measure.continuous_mass MeasureTheory.FiniteMeasure.continuous_mass
/-- Convergence of finite measures implies the convergence of their total masses. -/
theorem _root_.Filter.Tendsto.mass {γ : Type*} {F : Filter γ} {μs : γ → FiniteMeasure Ω}
{μ : FiniteMeasure Ω} (h : Tendsto μs F (𝓝 μ)) : Tendsto (fun i => (μs i).mass) F (𝓝 μ.mass) :=
(continuous_mass.tendsto μ).comp h
#align filter.tendsto.mass Filter.Tendsto.mass
theorem tendsto_iff_weak_star_tendsto {γ : Type*} {F : Filter γ} {μs : γ → FiniteMeasure Ω}
{μ : FiniteMeasure Ω} :
Tendsto μs F (𝓝 μ) ↔ Tendsto (fun i => (μs i).toWeakDualBCNN) F (𝓝 μ.toWeakDualBCNN) :=
Inducing.tendsto_nhds_iff ⟨rfl⟩
#align measure_theory.finite_measure.tendsto_iff_weak_star_tendsto MeasureTheory.FiniteMeasure.tendsto_iff_weak_star_tendsto
theorem tendsto_iff_forall_toWeakDualBCNN_tendsto {γ : Type*} {F : Filter γ}
{μs : γ → FiniteMeasure Ω} {μ : FiniteMeasure Ω} :
Tendsto μs F (𝓝 μ) ↔
∀ f : Ω →ᵇ ℝ≥0, Tendsto (fun i => (μs i).toWeakDualBCNN f) F (𝓝 (μ.toWeakDualBCNN f)) := by
rw [tendsto_iff_weak_star_tendsto, tendsto_iff_forall_eval_tendsto_topDualPairing]; rfl
#align measure_theory.finite_measure.tendsto_iff_forall_to_weak_dual_bcnn_tendsto MeasureTheory.FiniteMeasure.tendsto_iff_forall_toWeakDualBCNN_tendsto
theorem tendsto_iff_forall_testAgainstNN_tendsto {γ : Type*} {F : Filter γ}
{μs : γ → FiniteMeasure Ω} {μ : FiniteMeasure Ω} :
Tendsto μs F (𝓝 μ) ↔
∀ f : Ω →ᵇ ℝ≥0, Tendsto (fun i => (μs i).testAgainstNN f) F (𝓝 (μ.testAgainstNN f)) := by
rw [FiniteMeasure.tendsto_iff_forall_toWeakDualBCNN_tendsto]; rfl
#align measure_theory.finite_measure.tendsto_iff_forall_test_against_nn_tendsto MeasureTheory.FiniteMeasure.tendsto_iff_forall_testAgainstNN_tendsto
/-- If the total masses of finite measures tend to zero, then the measures tend to
zero. This formulation concerns the associated functionals on bounded continuous
nonnegative test functions. See `MeasureTheory.FiniteMeasure.tendsto_zero_of_tendsto_zero_mass` for
a formulation stating the weak convergence of measures. -/
theorem tendsto_zero_testAgainstNN_of_tendsto_zero_mass {γ : Type*} {F : Filter γ}
{μs : γ → FiniteMeasure Ω} (mass_lim : Tendsto (fun i => (μs i).mass) F (𝓝 0)) (f : Ω →ᵇ ℝ≥0) :
Tendsto (fun i => (μs i).testAgainstNN f) F (𝓝 0) := by
apply tendsto_iff_dist_tendsto_zero.mpr
have obs := fun i => (μs i).testAgainstNN_lipschitz_estimate f 0
simp_rw [testAgainstNN_zero, zero_add] at obs
simp_rw [show ∀ i, dist ((μs i).testAgainstNN f) 0 = (μs i).testAgainstNN f by
simp only [dist_nndist, NNReal.nndist_zero_eq_val', eq_self_iff_true, imp_true_iff]]
refine squeeze_zero (fun i => NNReal.coe_nonneg _) obs ?_
have lim_pair : Tendsto (fun i => (⟨nndist f 0, (μs i).mass⟩ : ℝ × ℝ)) F (𝓝 ⟨nndist f 0, 0⟩) := by
refine (Prod.tendsto_iff _ _).mpr ⟨tendsto_const_nhds, ?_⟩
exact (NNReal.continuous_coe.tendsto 0).comp mass_lim
have key := tendsto_mul.comp lim_pair
rwa [mul_zero] at key
#align measure_theory.finite_measure.tendsto_zero_test_against_nn_of_tendsto_zero_mass MeasureTheory.FiniteMeasure.tendsto_zero_testAgainstNN_of_tendsto_zero_mass
/-- If the total masses of finite measures tend to zero, then the measures tend to zero. -/
theorem tendsto_zero_of_tendsto_zero_mass {γ : Type*} {F : Filter γ} {μs : γ → FiniteMeasure Ω}
(mass_lim : Tendsto (fun i => (μs i).mass) F (𝓝 0)) : Tendsto μs F (𝓝 0) := by
rw [tendsto_iff_forall_testAgainstNN_tendsto]
intro f
convert tendsto_zero_testAgainstNN_of_tendsto_zero_mass mass_lim f
rw [zero_testAgainstNN_apply]
#align measure_theory.finite_measure.tendsto_zero_of_tendsto_zero_mass MeasureTheory.FiniteMeasure.tendsto_zero_of_tendsto_zero_mass
/-- A characterization of weak convergence in terms of integrals of bounded continuous
nonnegative functions. -/
theorem tendsto_iff_forall_lintegral_tendsto {γ : Type*} {F : Filter γ} {μs : γ → FiniteMeasure Ω}
{μ : FiniteMeasure Ω} :
Tendsto μs F (𝓝 μ) ↔
∀ f : Ω →ᵇ ℝ≥0,
Tendsto (fun i => ∫⁻ x, f x ∂(μs i : Measure Ω)) F (𝓝 (∫⁻ x, f x ∂(μ : Measure Ω))) := by
rw [tendsto_iff_forall_toWeakDualBCNN_tendsto]
simp_rw [toWeakDualBCNN_apply _ _, ← testAgainstNN_coe_eq, ENNReal.tendsto_coe,
ENNReal.toNNReal_coe]
#align measure_theory.finite_measure.tendsto_iff_forall_lintegral_tendsto MeasureTheory.FiniteMeasure.tendsto_iff_forall_lintegral_tendsto
end weak_convergence -- section
section Hausdorff
variable [HasOuterApproxClosed Ω] [BorelSpace Ω]
open Function
/-- The mapping `toWeakDualBCNN` from finite Borel measures to the weak dual of `Ω →ᵇ ℝ≥0` is
injective, if in the underlying space `Ω`, indicator functions of closed sets have decreasing
approximations by sequences of continuous functions (in particular if `Ω` is pseudometrizable). -/
lemma injective_toWeakDualBCNN :
Injective (toWeakDualBCNN : FiniteMeasure Ω → WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0)) := by
intro μ ν hμν
apply ext_of_forall_lintegral_eq
intro f
have key := congr_fun (congrArg DFunLike.coe hμν) f
apply (ENNReal.toNNReal_eq_toNNReal_iff' ?_ ?_).mp key
· exact (lintegral_lt_top_of_nnreal μ f).ne
· exact (lintegral_lt_top_of_nnreal ν f).ne
variable (Ω)
lemma embedding_toWeakDualBCNN :
Embedding (toWeakDualBCNN : FiniteMeasure Ω → WeakDual ℝ≥0 (Ω →ᵇ ℝ≥0)) where
induced := rfl
inj := injective_toWeakDualBCNN
/-- On topological spaces where indicators of closed sets have decreasing approximating sequences of
continuous functions (`HasOuterApproxClosed`), the topology of weak convergence of finite Borel
measures is Hausdorff (`T2Space`). -/
instance t2Space : T2Space (FiniteMeasure Ω) :=
Embedding.t2Space (embedding_toWeakDualBCNN Ω)
end Hausdorff -- section
end FiniteMeasure
-- section
section FiniteMeasureBoundedConvergence
/-! ### Bounded convergence results for finite measures
This section is about bounded convergence theorems for finite measures.
-/
variable {Ω : Type*} [MeasurableSpace Ω] [TopologicalSpace Ω] [OpensMeasurableSpace Ω]
/-- A bounded convergence theorem for a finite measure:
If a sequence of bounded continuous non-negative functions are uniformly bounded by a constant
and tend pointwise to a limit, then their integrals (`MeasureTheory.lintegral`) against the finite
measure tend to the integral of the limit.
A related result with more general assumptions is
`MeasureTheory.tendsto_lintegral_nn_filter_of_le_const`.
-/
theorem tendsto_lintegral_nn_of_le_const (μ : FiniteMeasure Ω) {fs : ℕ → Ω →ᵇ ℝ≥0} {c : ℝ≥0}
(fs_le_const : ∀ n ω, fs n ω ≤ c) {f : Ω → ℝ≥0}
(fs_lim : ∀ ω, Tendsto (fun n => fs n ω) atTop (𝓝 (f ω))) :
Tendsto (fun n => ∫⁻ ω, fs n ω ∂(μ : Measure Ω)) atTop (𝓝 (∫⁻ ω, f ω ∂(μ : Measure Ω))) :=
tendsto_lintegral_nn_filter_of_le_const μ
(eventually_of_forall fun n => eventually_of_forall (fs_le_const n))
(eventually_of_forall fs_lim)
#align measure_theory.finite_measure.tendsto_lintegral_nn_of_le_const MeasureTheory.FiniteMeasure.tendsto_lintegral_nn_of_le_const
/-- A bounded convergence theorem for a finite measure:
If bounded continuous non-negative functions are uniformly bounded by a constant and tend to a
limit, then their integrals against the finite measure tend to the integral of the limit.
This formulation assumes:
* the functions tend to a limit along a countably generated filter;
* the limit is in the almost everywhere sense;
* boundedness holds almost everywhere;
* integration is the pairing against non-negative continuous test functions
(`MeasureTheory.FiniteMeasure.testAgainstNN`).
A related result using `MeasureTheory.lintegral` for integration is
`MeasureTheory.FiniteMeasure.tendsto_lintegral_nn_filter_of_le_const`.
-/
theorem tendsto_testAgainstNN_filter_of_le_const {ι : Type*} {L : Filter ι}
[L.IsCountablyGenerated] {μ : FiniteMeasure Ω} {fs : ι → Ω →ᵇ ℝ≥0} {c : ℝ≥0}
(fs_le_const : ∀ᶠ i in L, ∀ᵐ ω : Ω ∂(μ : Measure Ω), fs i ω ≤ c) {f : Ω →ᵇ ℝ≥0}
(fs_lim : ∀ᵐ ω : Ω ∂(μ : Measure Ω), Tendsto (fun i => fs i ω) L (𝓝 (f ω))) :
Tendsto (fun i => μ.testAgainstNN (fs i)) L (𝓝 (μ.testAgainstNN f)) := by
apply (ENNReal.tendsto_toNNReal (f.lintegral_lt_top_of_nnreal (μ : Measure Ω)).ne).comp
exact tendsto_lintegral_nn_filter_of_le_const μ fs_le_const fs_lim
#align measure_theory.finite_measure.tendsto_test_against_nn_filter_of_le_const MeasureTheory.FiniteMeasure.tendsto_testAgainstNN_filter_of_le_const
/-- A bounded convergence theorem for a finite measure:
If a sequence of bounded continuous non-negative functions are uniformly bounded by a constant and
tend pointwise to a limit, then their integrals (`MeasureTheory.FiniteMeasure.testAgainstNN`)
against the finite measure tend to the integral of the limit.
Related results:
* `MeasureTheory.FiniteMeasure.tendsto_testAgainstNN_filter_of_le_const`:
more general assumptions
* `MeasureTheory.FiniteMeasure.tendsto_lintegral_nn_of_le_const`:
using `MeasureTheory.lintegral` for integration.
-/
theorem tendsto_testAgainstNN_of_le_const {μ : FiniteMeasure Ω} {fs : ℕ → Ω →ᵇ ℝ≥0} {c : ℝ≥0}
(fs_le_const : ∀ n ω, fs n ω ≤ c) {f : Ω →ᵇ ℝ≥0}
(fs_lim : ∀ ω, Tendsto (fun n => fs n ω) atTop (𝓝 (f ω))) :
Tendsto (fun n => μ.testAgainstNN (fs n)) atTop (𝓝 (μ.testAgainstNN f)) :=
tendsto_testAgainstNN_filter_of_le_const
(eventually_of_forall fun n => eventually_of_forall (fs_le_const n))
(eventually_of_forall fs_lim)
#align measure_theory.finite_measure.tendsto_test_against_nn_of_le_const MeasureTheory.FiniteMeasure.tendsto_testAgainstNN_of_le_const
end FiniteMeasureBoundedConvergence
-- section
section FiniteMeasureConvergenceByBoundedContinuousFunctions
/-! ### Weak convergence of finite measures with bounded continuous real-valued functions
In this section we characterize the weak convergence of finite measures by the usual (defining)
condition that the integrals of all bounded continuous real-valued functions converge.
-/
variable {Ω : Type*} [MeasurableSpace Ω] [TopologicalSpace Ω] [OpensMeasurableSpace Ω]
| Mathlib/MeasureTheory/Measure/FiniteMeasure.lean | 681 | 706 | theorem tendsto_of_forall_integral_tendsto {γ : Type*} {F : Filter γ} {μs : γ → FiniteMeasure Ω}
{μ : FiniteMeasure Ω}
(h :
∀ f : Ω →ᵇ ℝ,
Tendsto (fun i => ∫ x, f x ∂(μs i : Measure Ω)) F (𝓝 (∫ x, f x ∂(μ : Measure Ω)))) :
Tendsto μs F (𝓝 μ) := by |
apply (@tendsto_iff_forall_lintegral_tendsto Ω _ _ _ γ F μs μ).mpr
intro f
have key :=
@ENNReal.tendsto_toReal_iff _ F _
(fun i => (f.lintegral_lt_top_of_nnreal (μs i)).ne) _ (f.lintegral_lt_top_of_nnreal μ).ne
simp only [ENNReal.ofReal_coe_nnreal] at key
apply key.mp
have lip : LipschitzWith 1 ((↑) : ℝ≥0 → ℝ) := isometry_subtype_coe.lipschitz
set f₀ := BoundedContinuousFunction.comp _ lip f with _def_f₀
have f₀_eq : ⇑f₀ = ((↑) : ℝ≥0 → ℝ) ∘ ⇑f := rfl
have f₀_nn : 0 ≤ ⇑f₀ := fun _ => by
simp only [f₀_eq, Pi.zero_apply, Function.comp_apply, NNReal.zero_le_coe]
have f₀_ae_nn : 0 ≤ᵐ[(μ : Measure Ω)] ⇑f₀ := eventually_of_forall f₀_nn
have f₀_ae_nns : ∀ i, 0 ≤ᵐ[(μs i : Measure Ω)] ⇑f₀ := fun i => eventually_of_forall f₀_nn
have aux :=
integral_eq_lintegral_of_nonneg_ae f₀_ae_nn f₀.continuous.measurable.aestronglyMeasurable
have auxs := fun i =>
integral_eq_lintegral_of_nonneg_ae (f₀_ae_nns i) f₀.continuous.measurable.aestronglyMeasurable
simp_rw [f₀_eq, Function.comp_apply, ENNReal.ofReal_coe_nnreal] at aux auxs
simpa only [← aux, ← auxs] using h f₀
|
/-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Yaël Dillies
-/
import Mathlib.LinearAlgebra.Ray
import Mathlib.Analysis.NormedSpace.Real
#align_import analysis.normed_space.ray from "leanprover-community/mathlib"@"92ca63f0fb391a9ca5f22d2409a6080e786d99f7"
/-!
# Rays in a real normed vector space
In this file we prove some lemmas about the `SameRay` predicate in case of a real normed space. In
this case, for two vectors `x y` in the same ray, the norm of their sum is equal to the sum of their
norms and `‖y‖ • x = ‖x‖ • y`.
-/
open Real
variable {E : Type*} [SeminormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*}
[NormedAddCommGroup F] [NormedSpace ℝ F]
namespace SameRay
variable {x y : E}
/-- If `x` and `y` are on the same ray, then the triangle inequality becomes the equality: the norm
of `x + y` is the sum of the norms of `x` and `y`. The converse is true for a strictly convex
space. -/
theorem norm_add (h : SameRay ℝ x y) : ‖x + y‖ = ‖x‖ + ‖y‖ := by
rcases h.exists_eq_smul with ⟨u, a, b, ha, hb, -, rfl, rfl⟩
rw [← add_smul, norm_smul_of_nonneg (add_nonneg ha hb), norm_smul_of_nonneg ha,
norm_smul_of_nonneg hb, add_mul]
#align same_ray.norm_add SameRay.norm_add
theorem norm_sub (h : SameRay ℝ x y) : ‖x - y‖ = |‖x‖ - ‖y‖| := by
rcases h.exists_eq_smul with ⟨u, a, b, ha, hb, -, rfl, rfl⟩
wlog hab : b ≤ a generalizing a b with H
· rw [SameRay.sameRay_comm] at h
rw [norm_sub_rev, abs_sub_comm]
exact H b a hb ha h (le_of_not_le hab)
rw [← sub_nonneg] at hab
rw [← sub_smul, norm_smul_of_nonneg hab, norm_smul_of_nonneg ha, norm_smul_of_nonneg hb, ←
sub_mul, abs_of_nonneg (mul_nonneg hab (norm_nonneg _))]
#align same_ray.norm_sub SameRay.norm_sub
theorem norm_smul_eq (h : SameRay ℝ x y) : ‖x‖ • y = ‖y‖ • x := by
rcases h.exists_eq_smul with ⟨u, a, b, ha, hb, -, rfl, rfl⟩
simp only [norm_smul_of_nonneg, *, mul_smul]
rw [smul_comm, smul_comm b, smul_comm a b u]
#align same_ray.norm_smul_eq SameRay.norm_smul_eq
end SameRay
variable {x y : F}
| Mathlib/Analysis/NormedSpace/Ray.lean | 59 | 65 | theorem norm_injOn_ray_left (hx : x ≠ 0) : { y | SameRay ℝ x y }.InjOn norm := by |
rintro y hy z hz h
rcases hy.exists_nonneg_left hx with ⟨r, hr, rfl⟩
rcases hz.exists_nonneg_left hx with ⟨s, hs, rfl⟩
rw [norm_smul, norm_smul, mul_left_inj' (norm_ne_zero_iff.2 hx), norm_of_nonneg hr,
norm_of_nonneg hs] at h
rw [h]
|
/-
Copyright (c) 2021 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth
-/
import Mathlib.Algebra.CharP.Invertible
import Mathlib.Analysis.NormedSpace.LinearIsometry
import Mathlib.Analysis.Normed.Group.AddTorsor
import Mathlib.Analysis.NormedSpace.Basic
import Mathlib.LinearAlgebra.AffineSpace.Restrict
import Mathlib.Tactic.FailIfNoProgress
#align_import analysis.normed_space.affine_isometry from "leanprover-community/mathlib"@"f0c8bf9245297a541f468be517f1bde6195105e9"
/-!
# Affine isometries
In this file we define `AffineIsometry 𝕜 P P₂` to be an affine isometric embedding of normed
add-torsors `P` into `P₂` over normed `𝕜`-spaces and `AffineIsometryEquiv` to be an affine
isometric equivalence between `P` and `P₂`.
We also prove basic lemmas and provide convenience constructors. The choice of these lemmas and
constructors is closely modelled on those for the `LinearIsometry` and `AffineMap` theories.
Since many elementary properties don't require `‖x‖ = 0 → x = 0` we initially set up the theory for
`SeminormedAddCommGroup` and specialize to `NormedAddCommGroup` only when needed.
## Notation
We introduce the notation `P →ᵃⁱ[𝕜] P₂` for `AffineIsometry 𝕜 P P₂`, and `P ≃ᵃⁱ[𝕜] P₂` for
`AffineIsometryEquiv 𝕜 P P₂`. In contrast with the notation `→ₗᵢ` for linear isometries, `≃ᵢ`
for isometric equivalences, etc., the "i" here is a superscript. This is for aesthetic reasons to
match the superscript "a" (note that in mathlib `→ᵃ` is an affine map, since `→ₐ` has been taken by
algebra-homomorphisms.)
-/
open Function Set
variable (𝕜 : Type*) {V V₁ V₁' V₂ V₃ V₄ : Type*} {P₁ P₁' : Type*} (P P₂ : Type*) {P₃ P₄ : Type*}
[NormedField 𝕜]
[SeminormedAddCommGroup V] [NormedSpace 𝕜 V] [PseudoMetricSpace P] [NormedAddTorsor V P]
[SeminormedAddCommGroup V₁] [NormedSpace 𝕜 V₁] [PseudoMetricSpace P₁] [NormedAddTorsor V₁ P₁]
[SeminormedAddCommGroup V₁'] [NormedSpace 𝕜 V₁'] [MetricSpace P₁'] [NormedAddTorsor V₁' P₁']
[SeminormedAddCommGroup V₂] [NormedSpace 𝕜 V₂] [PseudoMetricSpace P₂] [NormedAddTorsor V₂ P₂]
[SeminormedAddCommGroup V₃] [NormedSpace 𝕜 V₃] [PseudoMetricSpace P₃] [NormedAddTorsor V₃ P₃]
[SeminormedAddCommGroup V₄] [NormedSpace 𝕜 V₄] [PseudoMetricSpace P₄] [NormedAddTorsor V₄ P₄]
/-- A `𝕜`-affine isometric embedding of one normed add-torsor over a normed `𝕜`-space into
another. -/
structure AffineIsometry extends P →ᵃ[𝕜] P₂ where
norm_map : ∀ x : V, ‖linear x‖ = ‖x‖
#align affine_isometry AffineIsometry
variable {𝕜 P P₂}
@[inherit_doc]
notation:25 -- `→ᵃᵢ` would be more consistent with the linear isometry notation, but it is uglier
P " →ᵃⁱ[" 𝕜:25 "] " P₂:0 => AffineIsometry 𝕜 P P₂
namespace AffineIsometry
variable (f : P →ᵃⁱ[𝕜] P₂)
/-- The underlying linear map of an affine isometry is in fact a linear isometry. -/
protected def linearIsometry : V →ₗᵢ[𝕜] V₂ :=
{ f.linear with norm_map' := f.norm_map }
#align affine_isometry.linear_isometry AffineIsometry.linearIsometry
@[simp]
theorem linear_eq_linearIsometry : f.linear = f.linearIsometry.toLinearMap := by
ext
rfl
#align affine_isometry.linear_eq_linear_isometry AffineIsometry.linear_eq_linearIsometry
instance : FunLike (P →ᵃⁱ[𝕜] P₂) P P₂ :=
{ coe := fun f => f.toFun,
coe_injective' := fun f g => by cases f; cases g; simp }
@[simp]
theorem coe_toAffineMap : ⇑f.toAffineMap = f := by
rfl
#align affine_isometry.coe_to_affine_map AffineIsometry.coe_toAffineMap
theorem toAffineMap_injective : Injective (toAffineMap : (P →ᵃⁱ[𝕜] P₂) → P →ᵃ[𝕜] P₂) := by
rintro ⟨f, _⟩ ⟨g, _⟩ rfl
rfl
#align affine_isometry.to_affine_map_injective AffineIsometry.toAffineMap_injective
theorem coeFn_injective : @Injective (P →ᵃⁱ[𝕜] P₂) (P → P₂) (↑) :=
AffineMap.coeFn_injective.comp toAffineMap_injective
#align affine_isometry.coe_fn_injective AffineIsometry.coeFn_injective
@[ext]
theorem ext {f g : P →ᵃⁱ[𝕜] P₂} (h : ∀ x, f x = g x) : f = g :=
coeFn_injective <| funext h
#align affine_isometry.ext AffineIsometry.ext
end AffineIsometry
namespace LinearIsometry
variable (f : V →ₗᵢ[𝕜] V₂)
/-- Reinterpret a linear isometry as an affine isometry. -/
def toAffineIsometry : V →ᵃⁱ[𝕜] V₂ :=
{ f.toLinearMap.toAffineMap with norm_map := f.norm_map }
#align linear_isometry.to_affine_isometry LinearIsometry.toAffineIsometry
@[simp]
theorem coe_toAffineIsometry : ⇑(f.toAffineIsometry : V →ᵃⁱ[𝕜] V₂) = f :=
rfl
#align linear_isometry.coe_to_affine_isometry LinearIsometry.coe_toAffineIsometry
@[simp]
theorem toAffineIsometry_linearIsometry : f.toAffineIsometry.linearIsometry = f := by
ext
rfl
#align linear_isometry.to_affine_isometry_linear_isometry LinearIsometry.toAffineIsometry_linearIsometry
-- somewhat arbitrary choice of simp direction
@[simp]
theorem toAffineIsometry_toAffineMap : f.toAffineIsometry.toAffineMap = f.toLinearMap.toAffineMap :=
rfl
#align linear_isometry.to_affine_isometry_to_affine_map LinearIsometry.toAffineIsometry_toAffineMap
end LinearIsometry
namespace AffineIsometry
variable (f : P →ᵃⁱ[𝕜] P₂) (f₁ : P₁' →ᵃⁱ[𝕜] P₂)
@[simp]
theorem map_vadd (p : P) (v : V) : f (v +ᵥ p) = f.linearIsometry v +ᵥ f p :=
f.toAffineMap.map_vadd p v
#align affine_isometry.map_vadd AffineIsometry.map_vadd
@[simp]
theorem map_vsub (p1 p2 : P) : f.linearIsometry (p1 -ᵥ p2) = f p1 -ᵥ f p2 :=
f.toAffineMap.linearMap_vsub p1 p2
#align affine_isometry.map_vsub AffineIsometry.map_vsub
@[simp]
theorem dist_map (x y : P) : dist (f x) (f y) = dist x y := by
rw [dist_eq_norm_vsub V₂, dist_eq_norm_vsub V, ← map_vsub, f.linearIsometry.norm_map]
#align affine_isometry.dist_map AffineIsometry.dist_map
@[simp]
theorem nndist_map (x y : P) : nndist (f x) (f y) = nndist x y := by simp [nndist_dist]
#align affine_isometry.nndist_map AffineIsometry.nndist_map
@[simp]
| Mathlib/Analysis/NormedSpace/AffineIsometry.lean | 154 | 154 | theorem edist_map (x y : P) : edist (f x) (f y) = edist x y := by | simp [edist_dist]
|
/-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Jens Wagemaker
-/
import Mathlib.Algebra.Group.Even
import Mathlib.Algebra.GroupWithZero.Divisibility
import Mathlib.Algebra.GroupWithZero.Hom
import Mathlib.Algebra.Group.Commute.Units
import Mathlib.Algebra.Group.Units.Hom
import Mathlib.Algebra.Order.Monoid.Canonical.Defs
import Mathlib.Algebra.Ring.Units
#align_import algebra.associated from "leanprover-community/mathlib"@"2f3994e1b117b1e1da49bcfb67334f33460c3ce4"
/-!
# Associated, prime, and irreducible elements.
In this file we define the predicate `Prime p`
saying that an element of a commutative monoid with zero is prime.
Namely, `Prime p` means that `p` isn't zero, it isn't a unit,
and `p ∣ a * b → p ∣ a ∨ p ∣ b` for all `a`, `b`;
In decomposition monoids (e.g., `ℕ`, `ℤ`), this predicate is equivalent to `Irreducible`,
however this is not true in general.
We also define an equivalence relation `Associated`
saying that two elements of a monoid differ by a multiplication by a unit.
Then we show that the quotient type `Associates` is a monoid
and prove basic properties of this quotient.
-/
variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
section Prime
variable [CommMonoidWithZero α]
/-- An element `p` of a commutative monoid with zero (e.g., a ring) is called *prime*,
if it's not zero, not a unit, and `p ∣ a * b → p ∣ a ∨ p ∣ b` for all `a`, `b`. -/
def Prime (p : α) : Prop :=
p ≠ 0 ∧ ¬IsUnit p ∧ ∀ a b, p ∣ a * b → p ∣ a ∨ p ∣ b
#align prime Prime
namespace Prime
variable {p : α} (hp : Prime p)
theorem ne_zero : p ≠ 0 :=
hp.1
#align prime.ne_zero Prime.ne_zero
theorem not_unit : ¬IsUnit p :=
hp.2.1
#align prime.not_unit Prime.not_unit
theorem not_dvd_one : ¬p ∣ 1 :=
mt (isUnit_of_dvd_one ·) hp.not_unit
#align prime.not_dvd_one Prime.not_dvd_one
theorem ne_one : p ≠ 1 := fun h => hp.2.1 (h.symm ▸ isUnit_one)
#align prime.ne_one Prime.ne_one
theorem dvd_or_dvd (hp : Prime p) {a b : α} (h : p ∣ a * b) : p ∣ a ∨ p ∣ b :=
hp.2.2 a b h
#align prime.dvd_or_dvd Prime.dvd_or_dvd
theorem dvd_mul {a b : α} : p ∣ a * b ↔ p ∣ a ∨ p ∣ b :=
⟨hp.dvd_or_dvd, (Or.elim · (dvd_mul_of_dvd_left · _) (dvd_mul_of_dvd_right · _))⟩
theorem isPrimal (hp : Prime p) : IsPrimal p := fun _a _b dvd ↦ (hp.dvd_or_dvd dvd).elim
(fun h ↦ ⟨p, 1, h, one_dvd _, (mul_one p).symm⟩) fun h ↦ ⟨1, p, one_dvd _, h, (one_mul p).symm⟩
theorem not_dvd_mul {a b : α} (ha : ¬ p ∣ a) (hb : ¬ p ∣ b) : ¬ p ∣ a * b :=
hp.dvd_mul.not.mpr <| not_or.mpr ⟨ha, hb⟩
theorem dvd_of_dvd_pow (hp : Prime p) {a : α} {n : ℕ} (h : p ∣ a ^ n) : p ∣ a := by
induction' n with n ih
· rw [pow_zero] at h
have := isUnit_of_dvd_one h
have := not_unit hp
contradiction
rw [pow_succ'] at h
cases' dvd_or_dvd hp h with dvd_a dvd_pow
· assumption
exact ih dvd_pow
#align prime.dvd_of_dvd_pow Prime.dvd_of_dvd_pow
theorem dvd_pow_iff_dvd {a : α} {n : ℕ} (hn : n ≠ 0) : p ∣ a ^ n ↔ p ∣ a :=
⟨hp.dvd_of_dvd_pow, (dvd_pow · hn)⟩
end Prime
@[simp]
theorem not_prime_zero : ¬Prime (0 : α) := fun h => h.ne_zero rfl
#align not_prime_zero not_prime_zero
@[simp]
theorem not_prime_one : ¬Prime (1 : α) := fun h => h.not_unit isUnit_one
#align not_prime_one not_prime_one
section Map
variable [CommMonoidWithZero β] {F : Type*} {G : Type*} [FunLike F α β]
variable [MonoidWithZeroHomClass F α β] [FunLike G β α] [MulHomClass G β α]
variable (f : F) (g : G) {p : α}
theorem comap_prime (hinv : ∀ a, g (f a : β) = a) (hp : Prime (f p)) : Prime p :=
⟨fun h => hp.1 <| by simp [h], fun h => hp.2.1 <| h.map f, fun a b h => by
refine
(hp.2.2 (f a) (f b) <| by
convert map_dvd f h
simp).imp
?_ ?_ <;>
· intro h
convert ← map_dvd g h <;> apply hinv⟩
#align comap_prime comap_prime
theorem MulEquiv.prime_iff (e : α ≃* β) : Prime p ↔ Prime (e p) :=
⟨fun h => (comap_prime e.symm e fun a => by simp) <| (e.symm_apply_apply p).substr h,
comap_prime e e.symm fun a => by simp⟩
#align mul_equiv.prime_iff MulEquiv.prime_iff
end Map
end Prime
theorem Prime.left_dvd_or_dvd_right_of_dvd_mul [CancelCommMonoidWithZero α] {p : α} (hp : Prime p)
{a b : α} : a ∣ p * b → p ∣ a ∨ a ∣ b := by
rintro ⟨c, hc⟩
rcases hp.2.2 a c (hc ▸ dvd_mul_right _ _) with (h | ⟨x, rfl⟩)
· exact Or.inl h
· rw [mul_left_comm, mul_right_inj' hp.ne_zero] at hc
exact Or.inr (hc.symm ▸ dvd_mul_right _ _)
#align prime.left_dvd_or_dvd_right_of_dvd_mul Prime.left_dvd_or_dvd_right_of_dvd_mul
theorem Prime.pow_dvd_of_dvd_mul_left [CancelCommMonoidWithZero α] {p a b : α} (hp : Prime p)
(n : ℕ) (h : ¬p ∣ a) (h' : p ^ n ∣ a * b) : p ^ n ∣ b := by
induction' n with n ih
· rw [pow_zero]
exact one_dvd b
· obtain ⟨c, rfl⟩ := ih (dvd_trans (pow_dvd_pow p n.le_succ) h')
rw [pow_succ]
apply mul_dvd_mul_left _ ((hp.dvd_or_dvd _).resolve_left h)
rwa [← mul_dvd_mul_iff_left (pow_ne_zero n hp.ne_zero), ← pow_succ, mul_left_comm]
#align prime.pow_dvd_of_dvd_mul_left Prime.pow_dvd_of_dvd_mul_left
theorem Prime.pow_dvd_of_dvd_mul_right [CancelCommMonoidWithZero α] {p a b : α} (hp : Prime p)
(n : ℕ) (h : ¬p ∣ b) (h' : p ^ n ∣ a * b) : p ^ n ∣ a := by
rw [mul_comm] at h'
exact hp.pow_dvd_of_dvd_mul_left n h h'
#align prime.pow_dvd_of_dvd_mul_right Prime.pow_dvd_of_dvd_mul_right
theorem Prime.dvd_of_pow_dvd_pow_mul_pow_of_square_not_dvd [CancelCommMonoidWithZero α] {p a b : α}
{n : ℕ} (hp : Prime p) (hpow : p ^ n.succ ∣ a ^ n.succ * b ^ n) (hb : ¬p ^ 2 ∣ b) : p ∣ a := by
-- Suppose `p ∣ b`, write `b = p * x` and `hy : a ^ n.succ * b ^ n = p ^ n.succ * y`.
cases' hp.dvd_or_dvd ((dvd_pow_self p (Nat.succ_ne_zero n)).trans hpow) with H hbdiv
· exact hp.dvd_of_dvd_pow H
obtain ⟨x, rfl⟩ := hp.dvd_of_dvd_pow hbdiv
obtain ⟨y, hy⟩ := hpow
-- Then we can divide out a common factor of `p ^ n` from the equation `hy`.
have : a ^ n.succ * x ^ n = p * y := by
refine mul_left_cancel₀ (pow_ne_zero n hp.ne_zero) ?_
rw [← mul_assoc _ p, ← pow_succ, ← hy, mul_pow, ← mul_assoc (a ^ n.succ), mul_comm _ (p ^ n),
mul_assoc]
-- So `p ∣ a` (and we're done) or `p ∣ x`, which can't be the case since it implies `p^2 ∣ b`.
refine hp.dvd_of_dvd_pow ((hp.dvd_or_dvd ⟨_, this⟩).resolve_right fun hdvdx => hb ?_)
obtain ⟨z, rfl⟩ := hp.dvd_of_dvd_pow hdvdx
rw [pow_two, ← mul_assoc]
exact dvd_mul_right _ _
#align prime.dvd_of_pow_dvd_pow_mul_pow_of_square_not_dvd Prime.dvd_of_pow_dvd_pow_mul_pow_of_square_not_dvd
theorem prime_pow_succ_dvd_mul {α : Type*} [CancelCommMonoidWithZero α] {p x y : α} (h : Prime p)
{i : ℕ} (hxy : p ^ (i + 1) ∣ x * y) : p ^ (i + 1) ∣ x ∨ p ∣ y := by
rw [or_iff_not_imp_right]
intro hy
induction' i with i ih generalizing x
· rw [pow_one] at hxy ⊢
exact (h.dvd_or_dvd hxy).resolve_right hy
rw [pow_succ'] at hxy ⊢
obtain ⟨x', rfl⟩ := (h.dvd_or_dvd (dvd_of_mul_right_dvd hxy)).resolve_right hy
rw [mul_assoc] at hxy
exact mul_dvd_mul_left p (ih ((mul_dvd_mul_iff_left h.ne_zero).mp hxy))
#align prime_pow_succ_dvd_mul prime_pow_succ_dvd_mul
/-- `Irreducible p` states that `p` is non-unit and only factors into units.
We explicitly avoid stating that `p` is non-zero, this would require a semiring. Assuming only a
monoid allows us to reuse irreducible for associated elements.
-/
structure Irreducible [Monoid α] (p : α) : Prop where
/-- `p` is not a unit -/
not_unit : ¬IsUnit p
/-- if `p` factors then one factor is a unit -/
isUnit_or_isUnit' : ∀ a b, p = a * b → IsUnit a ∨ IsUnit b
#align irreducible Irreducible
namespace Irreducible
theorem not_dvd_one [CommMonoid α] {p : α} (hp : Irreducible p) : ¬p ∣ 1 :=
mt (isUnit_of_dvd_one ·) hp.not_unit
#align irreducible.not_dvd_one Irreducible.not_dvd_one
theorem isUnit_or_isUnit [Monoid α] {p : α} (hp : Irreducible p) {a b : α} (h : p = a * b) :
IsUnit a ∨ IsUnit b :=
hp.isUnit_or_isUnit' a b h
#align irreducible.is_unit_or_is_unit Irreducible.isUnit_or_isUnit
end Irreducible
theorem irreducible_iff [Monoid α] {p : α} :
Irreducible p ↔ ¬IsUnit p ∧ ∀ a b, p = a * b → IsUnit a ∨ IsUnit b :=
⟨fun h => ⟨h.1, h.2⟩, fun h => ⟨h.1, h.2⟩⟩
#align irreducible_iff irreducible_iff
@[simp]
theorem not_irreducible_one [Monoid α] : ¬Irreducible (1 : α) := by simp [irreducible_iff]
#align not_irreducible_one not_irreducible_one
theorem Irreducible.ne_one [Monoid α] : ∀ {p : α}, Irreducible p → p ≠ 1
| _, hp, rfl => not_irreducible_one hp
#align irreducible.ne_one Irreducible.ne_one
@[simp]
theorem not_irreducible_zero [MonoidWithZero α] : ¬Irreducible (0 : α)
| ⟨hn0, h⟩ =>
have : IsUnit (0 : α) ∨ IsUnit (0 : α) := h 0 0 (mul_zero 0).symm
this.elim hn0 hn0
#align not_irreducible_zero not_irreducible_zero
theorem Irreducible.ne_zero [MonoidWithZero α] : ∀ {p : α}, Irreducible p → p ≠ 0
| _, hp, rfl => not_irreducible_zero hp
#align irreducible.ne_zero Irreducible.ne_zero
theorem of_irreducible_mul {α} [Monoid α] {x y : α} : Irreducible (x * y) → IsUnit x ∨ IsUnit y
| ⟨_, h⟩ => h _ _ rfl
#align of_irreducible_mul of_irreducible_mul
theorem not_irreducible_pow {α} [Monoid α] {x : α} {n : ℕ} (hn : n ≠ 1) :
¬ Irreducible (x ^ n) := by
cases n with
| zero => simp
| succ n =>
intro ⟨h₁, h₂⟩
have := h₂ _ _ (pow_succ _ _)
rw [isUnit_pow_iff (Nat.succ_ne_succ.mp hn), or_self] at this
exact h₁ (this.pow _)
#noalign of_irreducible_pow
theorem irreducible_or_factor {α} [Monoid α] (x : α) (h : ¬IsUnit x) :
Irreducible x ∨ ∃ a b, ¬IsUnit a ∧ ¬IsUnit b ∧ a * b = x := by
haveI := Classical.dec
refine or_iff_not_imp_right.2 fun H => ?_
simp? [h, irreducible_iff] at H ⊢ says
simp only [exists_and_left, not_exists, not_and, irreducible_iff, h, not_false_eq_true,
true_and] at H ⊢
refine fun a b h => by_contradiction fun o => ?_
simp? [not_or] at o says simp only [not_or] at o
exact H _ o.1 _ o.2 h.symm
#align irreducible_or_factor irreducible_or_factor
/-- If `p` and `q` are irreducible, then `p ∣ q` implies `q ∣ p`. -/
theorem Irreducible.dvd_symm [Monoid α] {p q : α} (hp : Irreducible p) (hq : Irreducible q) :
p ∣ q → q ∣ p := by
rintro ⟨q', rfl⟩
rw [IsUnit.mul_right_dvd (Or.resolve_left (of_irreducible_mul hq) hp.not_unit)]
#align irreducible.dvd_symm Irreducible.dvd_symm
theorem Irreducible.dvd_comm [Monoid α] {p q : α} (hp : Irreducible p) (hq : Irreducible q) :
p ∣ q ↔ q ∣ p :=
⟨hp.dvd_symm hq, hq.dvd_symm hp⟩
#align irreducible.dvd_comm Irreducible.dvd_comm
section
variable [Monoid α]
theorem irreducible_units_mul (a : αˣ) (b : α) : Irreducible (↑a * b) ↔ Irreducible b := by
simp only [irreducible_iff, Units.isUnit_units_mul, and_congr_right_iff]
refine fun _ => ⟨fun h A B HAB => ?_, fun h A B HAB => ?_⟩
· rw [← a.isUnit_units_mul]
apply h
rw [mul_assoc, ← HAB]
· rw [← a⁻¹.isUnit_units_mul]
apply h
rw [mul_assoc, ← HAB, Units.inv_mul_cancel_left]
#align irreducible_units_mul irreducible_units_mul
theorem irreducible_isUnit_mul {a b : α} (h : IsUnit a) : Irreducible (a * b) ↔ Irreducible b :=
let ⟨a, ha⟩ := h
ha ▸ irreducible_units_mul a b
#align irreducible_is_unit_mul irreducible_isUnit_mul
theorem irreducible_mul_units (a : αˣ) (b : α) : Irreducible (b * ↑a) ↔ Irreducible b := by
simp only [irreducible_iff, Units.isUnit_mul_units, and_congr_right_iff]
refine fun _ => ⟨fun h A B HAB => ?_, fun h A B HAB => ?_⟩
· rw [← Units.isUnit_mul_units B a]
apply h
rw [← mul_assoc, ← HAB]
· rw [← Units.isUnit_mul_units B a⁻¹]
apply h
rw [← mul_assoc, ← HAB, Units.mul_inv_cancel_right]
#align irreducible_mul_units irreducible_mul_units
theorem irreducible_mul_isUnit {a b : α} (h : IsUnit a) : Irreducible (b * a) ↔ Irreducible b :=
let ⟨a, ha⟩ := h
ha ▸ irreducible_mul_units a b
#align irreducible_mul_is_unit irreducible_mul_isUnit
theorem irreducible_mul_iff {a b : α} :
Irreducible (a * b) ↔ Irreducible a ∧ IsUnit b ∨ Irreducible b ∧ IsUnit a := by
constructor
· refine fun h => Or.imp (fun h' => ⟨?_, h'⟩) (fun h' => ⟨?_, h'⟩) (h.isUnit_or_isUnit rfl).symm
· rwa [irreducible_mul_isUnit h'] at h
· rwa [irreducible_isUnit_mul h'] at h
· rintro (⟨ha, hb⟩ | ⟨hb, ha⟩)
· rwa [irreducible_mul_isUnit hb]
· rwa [irreducible_isUnit_mul ha]
#align irreducible_mul_iff irreducible_mul_iff
end
section CommMonoid
variable [CommMonoid α] {a : α}
theorem Irreducible.not_square (ha : Irreducible a) : ¬IsSquare a := by
rw [isSquare_iff_exists_sq]
rintro ⟨b, rfl⟩
exact not_irreducible_pow (by decide) ha
#align irreducible.not_square Irreducible.not_square
theorem IsSquare.not_irreducible (ha : IsSquare a) : ¬Irreducible a := fun h => h.not_square ha
#align is_square.not_irreducible IsSquare.not_irreducible
end CommMonoid
section CommMonoidWithZero
variable [CommMonoidWithZero α]
theorem Irreducible.prime_of_isPrimal {a : α}
(irr : Irreducible a) (primal : IsPrimal a) : Prime a :=
⟨irr.ne_zero, irr.not_unit, fun a b dvd ↦ by
obtain ⟨d₁, d₂, h₁, h₂, rfl⟩ := primal dvd
exact (of_irreducible_mul irr).symm.imp (·.mul_right_dvd.mpr h₁) (·.mul_left_dvd.mpr h₂)⟩
theorem Irreducible.prime [DecompositionMonoid α] {a : α} (irr : Irreducible a) : Prime a :=
irr.prime_of_isPrimal (DecompositionMonoid.primal a)
end CommMonoidWithZero
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α] {a p : α}
protected theorem Prime.irreducible (hp : Prime p) : Irreducible p :=
⟨hp.not_unit, fun a b ↦ by
rintro rfl
exact (hp.dvd_or_dvd dvd_rfl).symm.imp
(isUnit_of_dvd_one <| (mul_dvd_mul_iff_right <| right_ne_zero_of_mul hp.ne_zero).mp <|
dvd_mul_of_dvd_right · _)
(isUnit_of_dvd_one <| (mul_dvd_mul_iff_left <| left_ne_zero_of_mul hp.ne_zero).mp <|
dvd_mul_of_dvd_left · _)⟩
#align prime.irreducible Prime.irreducible
theorem irreducible_iff_prime [DecompositionMonoid α] {a : α} : Irreducible a ↔ Prime a :=
⟨Irreducible.prime, Prime.irreducible⟩
theorem succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul (hp : Prime p) {a b : α} {k l : ℕ} :
p ^ k ∣ a → p ^ l ∣ b → p ^ (k + l + 1) ∣ a * b → p ^ (k + 1) ∣ a ∨ p ^ (l + 1) ∣ b :=
fun ⟨x, hx⟩ ⟨y, hy⟩ ⟨z, hz⟩ =>
have h : p ^ (k + l) * (x * y) = p ^ (k + l) * (p * z) := by
simpa [mul_comm, pow_add, hx, hy, mul_assoc, mul_left_comm] using hz
have hp0 : p ^ (k + l) ≠ 0 := pow_ne_zero _ hp.ne_zero
have hpd : p ∣ x * y := ⟨z, by rwa [mul_right_inj' hp0] at h⟩
(hp.dvd_or_dvd hpd).elim
(fun ⟨d, hd⟩ => Or.inl ⟨d, by simp [*, pow_succ, mul_comm, mul_left_comm, mul_assoc]⟩)
fun ⟨d, hd⟩ => Or.inr ⟨d, by simp [*, pow_succ, mul_comm, mul_left_comm, mul_assoc]⟩
#align succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul
theorem Prime.not_square (hp : Prime p) : ¬IsSquare p :=
hp.irreducible.not_square
#align prime.not_square Prime.not_square
theorem IsSquare.not_prime (ha : IsSquare a) : ¬Prime a := fun h => h.not_square ha
#align is_square.not_prime IsSquare.not_prime
theorem not_prime_pow {n : ℕ} (hn : n ≠ 1) : ¬Prime (a ^ n) := fun hp =>
not_irreducible_pow hn hp.irreducible
#align pow_not_prime not_prime_pow
end CancelCommMonoidWithZero
/-- Two elements of a `Monoid` are `Associated` if one of them is another one
multiplied by a unit on the right. -/
def Associated [Monoid α] (x y : α) : Prop :=
∃ u : αˣ, x * u = y
#align associated Associated
/-- Notation for two elements of a monoid are associated, i.e.
if one of them is another one multiplied by a unit on the right. -/
local infixl:50 " ~ᵤ " => Associated
namespace Associated
@[refl]
protected theorem refl [Monoid α] (x : α) : x ~ᵤ x :=
⟨1, by simp⟩
#align associated.refl Associated.refl
protected theorem rfl [Monoid α] {x : α} : x ~ᵤ x :=
.refl x
instance [Monoid α] : IsRefl α Associated :=
⟨Associated.refl⟩
@[symm]
protected theorem symm [Monoid α] : ∀ {x y : α}, x ~ᵤ y → y ~ᵤ x
| x, _, ⟨u, rfl⟩ => ⟨u⁻¹, by rw [mul_assoc, Units.mul_inv, mul_one]⟩
#align associated.symm Associated.symm
instance [Monoid α] : IsSymm α Associated :=
⟨fun _ _ => Associated.symm⟩
protected theorem comm [Monoid α] {x y : α} : x ~ᵤ y ↔ y ~ᵤ x :=
⟨Associated.symm, Associated.symm⟩
#align associated.comm Associated.comm
@[trans]
protected theorem trans [Monoid α] : ∀ {x y z : α}, x ~ᵤ y → y ~ᵤ z → x ~ᵤ z
| x, _, _, ⟨u, rfl⟩, ⟨v, rfl⟩ => ⟨u * v, by rw [Units.val_mul, mul_assoc]⟩
#align associated.trans Associated.trans
instance [Monoid α] : IsTrans α Associated :=
⟨fun _ _ _ => Associated.trans⟩
/-- The setoid of the relation `x ~ᵤ y` iff there is a unit `u` such that `x * u = y` -/
protected def setoid (α : Type*) [Monoid α] :
Setoid α where
r := Associated
iseqv := ⟨Associated.refl, Associated.symm, Associated.trans⟩
#align associated.setoid Associated.setoid
theorem map {M N : Type*} [Monoid M] [Monoid N] {F : Type*} [FunLike F M N] [MonoidHomClass F M N]
(f : F) {x y : M} (ha : Associated x y) : Associated (f x) (f y) := by
obtain ⟨u, ha⟩ := ha
exact ⟨Units.map f u, by rw [← ha, map_mul, Units.coe_map, MonoidHom.coe_coe]⟩
end Associated
attribute [local instance] Associated.setoid
theorem unit_associated_one [Monoid α] {u : αˣ} : (u : α) ~ᵤ 1 :=
⟨u⁻¹, Units.mul_inv u⟩
#align unit_associated_one unit_associated_one
@[simp]
theorem associated_one_iff_isUnit [Monoid α] {a : α} : (a : α) ~ᵤ 1 ↔ IsUnit a :=
Iff.intro
(fun h =>
let ⟨c, h⟩ := h.symm
h ▸ ⟨c, (one_mul _).symm⟩)
fun ⟨c, h⟩ => Associated.symm ⟨c, by simp [h]⟩
#align associated_one_iff_is_unit associated_one_iff_isUnit
@[simp]
theorem associated_zero_iff_eq_zero [MonoidWithZero α] (a : α) : a ~ᵤ 0 ↔ a = 0 :=
Iff.intro
(fun h => by
let ⟨u, h⟩ := h.symm
simpa using h.symm)
fun h => h ▸ Associated.refl a
#align associated_zero_iff_eq_zero associated_zero_iff_eq_zero
theorem associated_one_of_mul_eq_one [CommMonoid α] {a : α} (b : α) (hab : a * b = 1) : a ~ᵤ 1 :=
show (Units.mkOfMulEqOne a b hab : α) ~ᵤ 1 from unit_associated_one
#align associated_one_of_mul_eq_one associated_one_of_mul_eq_one
theorem associated_one_of_associated_mul_one [CommMonoid α] {a b : α} : a * b ~ᵤ 1 → a ~ᵤ 1
| ⟨u, h⟩ => associated_one_of_mul_eq_one (b * u) <| by simpa [mul_assoc] using h
#align associated_one_of_associated_mul_one associated_one_of_associated_mul_one
theorem associated_mul_unit_left {β : Type*} [Monoid β] (a u : β) (hu : IsUnit u) :
Associated (a * u) a :=
let ⟨u', hu⟩ := hu
⟨u'⁻¹, hu ▸ Units.mul_inv_cancel_right _ _⟩
#align associated_mul_unit_left associated_mul_unit_left
theorem associated_unit_mul_left {β : Type*} [CommMonoid β] (a u : β) (hu : IsUnit u) :
Associated (u * a) a := by
rw [mul_comm]
exact associated_mul_unit_left _ _ hu
#align associated_unit_mul_left associated_unit_mul_left
theorem associated_mul_unit_right {β : Type*} [Monoid β] (a u : β) (hu : IsUnit u) :
Associated a (a * u) :=
(associated_mul_unit_left a u hu).symm
#align associated_mul_unit_right associated_mul_unit_right
theorem associated_unit_mul_right {β : Type*} [CommMonoid β] (a u : β) (hu : IsUnit u) :
Associated a (u * a) :=
(associated_unit_mul_left a u hu).symm
#align associated_unit_mul_right associated_unit_mul_right
theorem associated_mul_isUnit_left_iff {β : Type*} [Monoid β] {a u b : β} (hu : IsUnit u) :
Associated (a * u) b ↔ Associated a b :=
⟨(associated_mul_unit_right _ _ hu).trans, (associated_mul_unit_left _ _ hu).trans⟩
#align associated_mul_is_unit_left_iff associated_mul_isUnit_left_iff
theorem associated_isUnit_mul_left_iff {β : Type*} [CommMonoid β] {u a b : β} (hu : IsUnit u) :
Associated (u * a) b ↔ Associated a b := by
rw [mul_comm]
exact associated_mul_isUnit_left_iff hu
#align associated_is_unit_mul_left_iff associated_isUnit_mul_left_iff
theorem associated_mul_isUnit_right_iff {β : Type*} [Monoid β] {a b u : β} (hu : IsUnit u) :
Associated a (b * u) ↔ Associated a b :=
Associated.comm.trans <| (associated_mul_isUnit_left_iff hu).trans Associated.comm
#align associated_mul_is_unit_right_iff associated_mul_isUnit_right_iff
theorem associated_isUnit_mul_right_iff {β : Type*} [CommMonoid β] {a u b : β} (hu : IsUnit u) :
Associated a (u * b) ↔ Associated a b :=
Associated.comm.trans <| (associated_isUnit_mul_left_iff hu).trans Associated.comm
#align associated_is_unit_mul_right_iff associated_isUnit_mul_right_iff
@[simp]
theorem associated_mul_unit_left_iff {β : Type*} [Monoid β] {a b : β} {u : Units β} :
Associated (a * u) b ↔ Associated a b :=
associated_mul_isUnit_left_iff u.isUnit
#align associated_mul_unit_left_iff associated_mul_unit_left_iff
@[simp]
theorem associated_unit_mul_left_iff {β : Type*} [CommMonoid β] {a b : β} {u : Units β} :
Associated (↑u * a) b ↔ Associated a b :=
associated_isUnit_mul_left_iff u.isUnit
#align associated_unit_mul_left_iff associated_unit_mul_left_iff
@[simp]
theorem associated_mul_unit_right_iff {β : Type*} [Monoid β] {a b : β} {u : Units β} :
Associated a (b * u) ↔ Associated a b :=
associated_mul_isUnit_right_iff u.isUnit
#align associated_mul_unit_right_iff associated_mul_unit_right_iff
@[simp]
theorem associated_unit_mul_right_iff {β : Type*} [CommMonoid β] {a b : β} {u : Units β} :
Associated a (↑u * b) ↔ Associated a b :=
associated_isUnit_mul_right_iff u.isUnit
#align associated_unit_mul_right_iff associated_unit_mul_right_iff
theorem Associated.mul_left [Monoid α] (a : α) {b c : α} (h : b ~ᵤ c) : a * b ~ᵤ a * c := by
obtain ⟨d, rfl⟩ := h; exact ⟨d, mul_assoc _ _ _⟩
#align associated.mul_left Associated.mul_left
theorem Associated.mul_right [CommMonoid α] {a b : α} (h : a ~ᵤ b) (c : α) : a * c ~ᵤ b * c := by
obtain ⟨d, rfl⟩ := h; exact ⟨d, mul_right_comm _ _ _⟩
#align associated.mul_right Associated.mul_right
theorem Associated.mul_mul [CommMonoid α] {a₁ a₂ b₁ b₂ : α}
(h₁ : a₁ ~ᵤ b₁) (h₂ : a₂ ~ᵤ b₂) : a₁ * a₂ ~ᵤ b₁ * b₂ := (h₁.mul_right _).trans (h₂.mul_left _)
#align associated.mul_mul Associated.mul_mul
theorem Associated.pow_pow [CommMonoid α] {a b : α} {n : ℕ} (h : a ~ᵤ b) : a ^ n ~ᵤ b ^ n := by
induction' n with n ih
· simp [Associated.refl]
convert h.mul_mul ih <;> rw [pow_succ']
#align associated.pow_pow Associated.pow_pow
protected theorem Associated.dvd [Monoid α] {a b : α} : a ~ᵤ b → a ∣ b := fun ⟨u, hu⟩ =>
⟨u, hu.symm⟩
#align associated.dvd Associated.dvd
protected theorem Associated.dvd' [Monoid α] {a b : α} (h : a ~ᵤ b) : b ∣ a :=
h.symm.dvd
protected theorem Associated.dvd_dvd [Monoid α] {a b : α} (h : a ~ᵤ b) : a ∣ b ∧ b ∣ a :=
⟨h.dvd, h.symm.dvd⟩
#align associated.dvd_dvd Associated.dvd_dvd
theorem associated_of_dvd_dvd [CancelMonoidWithZero α] {a b : α} (hab : a ∣ b) (hba : b ∣ a) :
a ~ᵤ b := by
rcases hab with ⟨c, rfl⟩
rcases hba with ⟨d, a_eq⟩
by_cases ha0 : a = 0
· simp_all
have hac0 : a * c ≠ 0 := by
intro con
rw [con, zero_mul] at a_eq
apply ha0 a_eq
have : a * (c * d) = a * 1 := by rw [← mul_assoc, ← a_eq, mul_one]
have hcd : c * d = 1 := mul_left_cancel₀ ha0 this
have : a * c * (d * c) = a * c * 1 := by rw [← mul_assoc, ← a_eq, mul_one]
have hdc : d * c = 1 := mul_left_cancel₀ hac0 this
exact ⟨⟨c, d, hcd, hdc⟩, rfl⟩
#align associated_of_dvd_dvd associated_of_dvd_dvd
theorem dvd_dvd_iff_associated [CancelMonoidWithZero α] {a b : α} : a ∣ b ∧ b ∣ a ↔ a ~ᵤ b :=
⟨fun ⟨h1, h2⟩ => associated_of_dvd_dvd h1 h2, Associated.dvd_dvd⟩
#align dvd_dvd_iff_associated dvd_dvd_iff_associated
instance [CancelMonoidWithZero α] [DecidableRel ((· ∣ ·) : α → α → Prop)] :
DecidableRel ((· ~ᵤ ·) : α → α → Prop) := fun _ _ => decidable_of_iff _ dvd_dvd_iff_associated
theorem Associated.dvd_iff_dvd_left [Monoid α] {a b c : α} (h : a ~ᵤ b) : a ∣ c ↔ b ∣ c :=
let ⟨_, hu⟩ := h
hu ▸ Units.mul_right_dvd.symm
#align associated.dvd_iff_dvd_left Associated.dvd_iff_dvd_left
theorem Associated.dvd_iff_dvd_right [Monoid α] {a b c : α} (h : b ~ᵤ c) : a ∣ b ↔ a ∣ c :=
let ⟨_, hu⟩ := h
hu ▸ Units.dvd_mul_right.symm
#align associated.dvd_iff_dvd_right Associated.dvd_iff_dvd_right
theorem Associated.eq_zero_iff [MonoidWithZero α] {a b : α} (h : a ~ᵤ b) : a = 0 ↔ b = 0 := by
obtain ⟨u, rfl⟩ := h
rw [← Units.eq_mul_inv_iff_mul_eq, zero_mul]
#align associated.eq_zero_iff Associated.eq_zero_iff
theorem Associated.ne_zero_iff [MonoidWithZero α] {a b : α} (h : a ~ᵤ b) : a ≠ 0 ↔ b ≠ 0 :=
not_congr h.eq_zero_iff
#align associated.ne_zero_iff Associated.ne_zero_iff
theorem Associated.neg_left [Monoid α] [HasDistribNeg α] {a b : α} (h : Associated a b) :
Associated (-a) b :=
let ⟨u, hu⟩ := h; ⟨-u, by simp [hu]⟩
theorem Associated.neg_right [Monoid α] [HasDistribNeg α] {a b : α} (h : Associated a b) :
Associated a (-b) :=
h.symm.neg_left.symm
theorem Associated.neg_neg [Monoid α] [HasDistribNeg α] {a b : α} (h : Associated a b) :
Associated (-a) (-b) :=
h.neg_left.neg_right
protected theorem Associated.prime [CommMonoidWithZero α] {p q : α} (h : p ~ᵤ q) (hp : Prime p) :
Prime q :=
⟨h.ne_zero_iff.1 hp.ne_zero,
let ⟨u, hu⟩ := h
⟨fun ⟨v, hv⟩ => hp.not_unit ⟨v * u⁻¹, by simp [hv, hu.symm]⟩,
hu ▸ by
simp only [IsUnit.mul_iff, Units.isUnit, and_true, IsUnit.mul_right_dvd]
intro a b
exact hp.dvd_or_dvd⟩⟩
#align associated.prime Associated.prime
theorem prime_mul_iff [CancelCommMonoidWithZero α] {x y : α} :
Prime (x * y) ↔ (Prime x ∧ IsUnit y) ∨ (IsUnit x ∧ Prime y) := by
refine ⟨fun h ↦ ?_, ?_⟩
· rcases of_irreducible_mul h.irreducible with hx | hy
· exact Or.inr ⟨hx, (associated_unit_mul_left y x hx).prime h⟩
· exact Or.inl ⟨(associated_mul_unit_left x y hy).prime h, hy⟩
· rintro (⟨hx, hy⟩ | ⟨hx, hy⟩)
· exact (associated_mul_unit_left x y hy).symm.prime hx
· exact (associated_unit_mul_right y x hx).prime hy
@[simp]
lemma prime_pow_iff [CancelCommMonoidWithZero α] {p : α} {n : ℕ} :
Prime (p ^ n) ↔ Prime p ∧ n = 1 := by
refine ⟨fun hp ↦ ?_, fun ⟨hp, hn⟩ ↦ by simpa [hn]⟩
suffices n = 1 by aesop
cases' n with n
· simp at hp
· rw [Nat.succ.injEq]
rw [pow_succ', prime_mul_iff] at hp
rcases hp with ⟨hp, hpn⟩ | ⟨hp, hpn⟩
· by_contra contra
rw [isUnit_pow_iff contra] at hpn
exact hp.not_unit hpn
· exfalso
exact hpn.not_unit (hp.pow n)
theorem Irreducible.dvd_iff [Monoid α] {x y : α} (hx : Irreducible x) :
y ∣ x ↔ IsUnit y ∨ Associated x y := by
constructor
· rintro ⟨z, hz⟩
obtain (h|h) := hx.isUnit_or_isUnit hz
· exact Or.inl h
· rw [hz]
exact Or.inr (associated_mul_unit_left _ _ h)
· rintro (hy|h)
· exact hy.dvd
· exact h.symm.dvd
theorem Irreducible.associated_of_dvd [Monoid α] {p q : α} (p_irr : Irreducible p)
(q_irr : Irreducible q) (dvd : p ∣ q) : Associated p q :=
((q_irr.dvd_iff.mp dvd).resolve_left p_irr.not_unit).symm
#align irreducible.associated_of_dvd Irreducible.associated_of_dvdₓ
theorem Irreducible.dvd_irreducible_iff_associated [Monoid α] {p q : α}
(pp : Irreducible p) (qp : Irreducible q) : p ∣ q ↔ Associated p q :=
⟨Irreducible.associated_of_dvd pp qp, Associated.dvd⟩
#align irreducible.dvd_irreducible_iff_associated Irreducible.dvd_irreducible_iff_associated
theorem Prime.associated_of_dvd [CancelCommMonoidWithZero α] {p q : α} (p_prime : Prime p)
(q_prime : Prime q) (dvd : p ∣ q) : Associated p q :=
p_prime.irreducible.associated_of_dvd q_prime.irreducible dvd
#align prime.associated_of_dvd Prime.associated_of_dvd
theorem Prime.dvd_prime_iff_associated [CancelCommMonoidWithZero α] {p q : α} (pp : Prime p)
(qp : Prime q) : p ∣ q ↔ Associated p q :=
pp.irreducible.dvd_irreducible_iff_associated qp.irreducible
#align prime.dvd_prime_iff_associated Prime.dvd_prime_iff_associated
theorem Associated.prime_iff [CommMonoidWithZero α] {p q : α} (h : p ~ᵤ q) : Prime p ↔ Prime q :=
⟨h.prime, h.symm.prime⟩
#align associated.prime_iff Associated.prime_iff
protected theorem Associated.isUnit [Monoid α] {a b : α} (h : a ~ᵤ b) : IsUnit a → IsUnit b :=
let ⟨u, hu⟩ := h
fun ⟨v, hv⟩ => ⟨v * u, by simp [hv, hu.symm]⟩
#align associated.is_unit Associated.isUnit
theorem Associated.isUnit_iff [Monoid α] {a b : α} (h : a ~ᵤ b) : IsUnit a ↔ IsUnit b :=
⟨h.isUnit, h.symm.isUnit⟩
#align associated.is_unit_iff Associated.isUnit_iff
theorem Irreducible.isUnit_iff_not_associated_of_dvd [Monoid α]
{x y : α} (hx : Irreducible x) (hy : y ∣ x) : IsUnit y ↔ ¬ Associated x y :=
⟨fun hy hxy => hx.1 (hxy.symm.isUnit hy), (hx.dvd_iff.mp hy).resolve_right⟩
protected theorem Associated.irreducible [Monoid α] {p q : α} (h : p ~ᵤ q) (hp : Irreducible p) :
Irreducible q :=
⟨mt h.symm.isUnit hp.1,
let ⟨u, hu⟩ := h
fun a b hab =>
have hpab : p = a * (b * (u⁻¹ : αˣ)) :=
calc
p = p * u * (u⁻¹ : αˣ) := by simp
_ = _ := by rw [hu]; simp [hab, mul_assoc]
(hp.isUnit_or_isUnit hpab).elim Or.inl fun ⟨v, hv⟩ => Or.inr ⟨v * u, by simp [hv]⟩⟩
#align associated.irreducible Associated.irreducible
protected theorem Associated.irreducible_iff [Monoid α] {p q : α} (h : p ~ᵤ q) :
Irreducible p ↔ Irreducible q :=
⟨h.irreducible, h.symm.irreducible⟩
#align associated.irreducible_iff Associated.irreducible_iff
theorem Associated.of_mul_left [CancelCommMonoidWithZero α] {a b c d : α} (h : a * b ~ᵤ c * d)
(h₁ : a ~ᵤ c) (ha : a ≠ 0) : b ~ᵤ d :=
let ⟨u, hu⟩ := h
let ⟨v, hv⟩ := Associated.symm h₁
⟨u * (v : αˣ),
mul_left_cancel₀ ha
(by
rw [← hv, mul_assoc c (v : α) d, mul_left_comm c, ← hu]
simp [hv.symm, mul_assoc, mul_comm, mul_left_comm])⟩
#align associated.of_mul_left Associated.of_mul_left
theorem Associated.of_mul_right [CancelCommMonoidWithZero α] {a b c d : α} :
a * b ~ᵤ c * d → b ~ᵤ d → b ≠ 0 → a ~ᵤ c := by
rw [mul_comm a, mul_comm c]; exact Associated.of_mul_left
#align associated.of_mul_right Associated.of_mul_right
theorem Associated.of_pow_associated_of_prime [CancelCommMonoidWithZero α] {p₁ p₂ : α} {k₁ k₂ : ℕ}
(hp₁ : Prime p₁) (hp₂ : Prime p₂) (hk₁ : 0 < k₁) (h : p₁ ^ k₁ ~ᵤ p₂ ^ k₂) : p₁ ~ᵤ p₂ := by
have : p₁ ∣ p₂ ^ k₂ := by
rw [← h.dvd_iff_dvd_right]
apply dvd_pow_self _ hk₁.ne'
rw [← hp₁.dvd_prime_iff_associated hp₂]
exact hp₁.dvd_of_dvd_pow this
#align associated.of_pow_associated_of_prime Associated.of_pow_associated_of_prime
theorem Associated.of_pow_associated_of_prime' [CancelCommMonoidWithZero α] {p₁ p₂ : α} {k₁ k₂ : ℕ}
(hp₁ : Prime p₁) (hp₂ : Prime p₂) (hk₂ : 0 < k₂) (h : p₁ ^ k₁ ~ᵤ p₂ ^ k₂) : p₁ ~ᵤ p₂ :=
(h.symm.of_pow_associated_of_prime hp₂ hp₁ hk₂).symm
#align associated.of_pow_associated_of_prime' Associated.of_pow_associated_of_prime'
/-- See also `Irreducible.coprime_iff_not_dvd`. -/
lemma Irreducible.isRelPrime_iff_not_dvd [Monoid α] {p n : α} (hp : Irreducible p) :
IsRelPrime p n ↔ ¬ p ∣ n := by
refine ⟨fun h contra ↦ hp.not_unit (h dvd_rfl contra), fun hpn d hdp hdn ↦ ?_⟩
contrapose! hpn
suffices Associated p d from this.dvd.trans hdn
exact (hp.dvd_iff.mp hdp).resolve_left hpn
lemma Irreducible.dvd_or_isRelPrime [Monoid α] {p n : α} (hp : Irreducible p) :
p ∣ n ∨ IsRelPrime p n := Classical.or_iff_not_imp_left.mpr hp.isRelPrime_iff_not_dvd.2
section UniqueUnits
variable [Monoid α] [Unique αˣ]
theorem associated_iff_eq {x y : α} : x ~ᵤ y ↔ x = y := by
constructor
· rintro ⟨c, rfl⟩
rw [units_eq_one c, Units.val_one, mul_one]
· rintro rfl
rfl
#align associated_iff_eq associated_iff_eq
theorem associated_eq_eq : (Associated : α → α → Prop) = Eq := by
ext
rw [associated_iff_eq]
#align associated_eq_eq associated_eq_eq
theorem prime_dvd_prime_iff_eq {M : Type*} [CancelCommMonoidWithZero M] [Unique Mˣ] {p q : M}
(pp : Prime p) (qp : Prime q) : p ∣ q ↔ p = q := by
rw [pp.dvd_prime_iff_associated qp, ← associated_eq_eq]
#align prime_dvd_prime_iff_eq prime_dvd_prime_iff_eq
end UniqueUnits
section UniqueUnits₀
variable {R : Type*} [CancelCommMonoidWithZero R] [Unique Rˣ] {p₁ p₂ : R} {k₁ k₂ : ℕ}
theorem eq_of_prime_pow_eq (hp₁ : Prime p₁) (hp₂ : Prime p₂) (hk₁ : 0 < k₁)
(h : p₁ ^ k₁ = p₂ ^ k₂) : p₁ = p₂ := by
rw [← associated_iff_eq] at h ⊢
apply h.of_pow_associated_of_prime hp₁ hp₂ hk₁
#align eq_of_prime_pow_eq eq_of_prime_pow_eq
theorem eq_of_prime_pow_eq' (hp₁ : Prime p₁) (hp₂ : Prime p₂) (hk₁ : 0 < k₂)
(h : p₁ ^ k₁ = p₂ ^ k₂) : p₁ = p₂ := by
rw [← associated_iff_eq] at h ⊢
apply h.of_pow_associated_of_prime' hp₁ hp₂ hk₁
#align eq_of_prime_pow_eq' eq_of_prime_pow_eq'
end UniqueUnits₀
/-- The quotient of a monoid by the `Associated` relation. Two elements `x` and `y`
are associated iff there is a unit `u` such that `x * u = y`. There is a natural
monoid structure on `Associates α`. -/
abbrev Associates (α : Type*) [Monoid α] : Type _ :=
Quotient (Associated.setoid α)
#align associates Associates
namespace Associates
open Associated
/-- The canonical quotient map from a monoid `α` into the `Associates` of `α` -/
protected abbrev mk {α : Type*} [Monoid α] (a : α) : Associates α :=
⟦a⟧
#align associates.mk Associates.mk
instance [Monoid α] : Inhabited (Associates α) :=
⟨⟦1⟧⟩
theorem mk_eq_mk_iff_associated [Monoid α] {a b : α} : Associates.mk a = Associates.mk b ↔ a ~ᵤ b :=
Iff.intro Quotient.exact Quot.sound
#align associates.mk_eq_mk_iff_associated Associates.mk_eq_mk_iff_associated
theorem quotient_mk_eq_mk [Monoid α] (a : α) : ⟦a⟧ = Associates.mk a :=
rfl
#align associates.quotient_mk_eq_mk Associates.quotient_mk_eq_mk
theorem quot_mk_eq_mk [Monoid α] (a : α) : Quot.mk Setoid.r a = Associates.mk a :=
rfl
#align associates.quot_mk_eq_mk Associates.quot_mk_eq_mk
@[simp]
theorem quot_out [Monoid α] (a : Associates α) : Associates.mk (Quot.out a) = a := by
rw [← quot_mk_eq_mk, Quot.out_eq]
#align associates.quot_out Associates.quot_outₓ
theorem mk_quot_out [Monoid α] (a : α) : Quot.out (Associates.mk a) ~ᵤ a := by
rw [← Associates.mk_eq_mk_iff_associated, Associates.quot_out]
theorem forall_associated [Monoid α] {p : Associates α → Prop} :
(∀ a, p a) ↔ ∀ a, p (Associates.mk a) :=
Iff.intro (fun h _ => h _) fun h a => Quotient.inductionOn a h
#align associates.forall_associated Associates.forall_associated
theorem mk_surjective [Monoid α] : Function.Surjective (@Associates.mk α _) :=
forall_associated.2 fun a => ⟨a, rfl⟩
#align associates.mk_surjective Associates.mk_surjective
instance [Monoid α] : One (Associates α) :=
⟨⟦1⟧⟩
@[simp]
theorem mk_one [Monoid α] : Associates.mk (1 : α) = 1 :=
rfl
#align associates.mk_one Associates.mk_one
theorem one_eq_mk_one [Monoid α] : (1 : Associates α) = Associates.mk 1 :=
rfl
#align associates.one_eq_mk_one Associates.one_eq_mk_one
@[simp]
theorem mk_eq_one [Monoid α] {a : α} : Associates.mk a = 1 ↔ IsUnit a := by
rw [← mk_one, mk_eq_mk_iff_associated, associated_one_iff_isUnit]
instance [Monoid α] : Bot (Associates α) :=
⟨1⟩
theorem bot_eq_one [Monoid α] : (⊥ : Associates α) = 1 :=
rfl
#align associates.bot_eq_one Associates.bot_eq_one
theorem exists_rep [Monoid α] (a : Associates α) : ∃ a0 : α, Associates.mk a0 = a :=
Quot.exists_rep a
#align associates.exists_rep Associates.exists_rep
instance [Monoid α] [Subsingleton α] :
Unique (Associates α) where
default := 1
uniq := forall_associated.2 fun _ ↦ mk_eq_one.2 <| isUnit_of_subsingleton _
theorem mk_injective [Monoid α] [Unique (Units α)] : Function.Injective (@Associates.mk α _) :=
fun _ _ h => associated_iff_eq.mp (Associates.mk_eq_mk_iff_associated.mp h)
#align associates.mk_injective Associates.mk_injective
section CommMonoid
variable [CommMonoid α]
instance instMul : Mul (Associates α) :=
⟨Quotient.map₂ (· * ·) fun _ _ h₁ _ _ h₂ ↦ h₁.mul_mul h₂⟩
theorem mk_mul_mk {x y : α} : Associates.mk x * Associates.mk y = Associates.mk (x * y) :=
rfl
#align associates.mk_mul_mk Associates.mk_mul_mk
instance instCommMonoid : CommMonoid (Associates α) where
one := 1
mul := (· * ·)
mul_one a' := Quotient.inductionOn a' fun a => show ⟦a * 1⟧ = ⟦a⟧ by simp
one_mul a' := Quotient.inductionOn a' fun a => show ⟦1 * a⟧ = ⟦a⟧ by simp
mul_assoc a' b' c' :=
Quotient.inductionOn₃ a' b' c' fun a b c =>
show ⟦a * b * c⟧ = ⟦a * (b * c)⟧ by rw [mul_assoc]
mul_comm a' b' :=
Quotient.inductionOn₂ a' b' fun a b => show ⟦a * b⟧ = ⟦b * a⟧ by rw [mul_comm]
instance instPreorder : Preorder (Associates α) where
le := Dvd.dvd
le_refl := dvd_refl
le_trans a b c := dvd_trans
/-- `Associates.mk` as a `MonoidHom`. -/
protected def mkMonoidHom : α →* Associates α where
toFun := Associates.mk
map_one' := mk_one
map_mul' _ _ := mk_mul_mk
#align associates.mk_monoid_hom Associates.mkMonoidHom
@[simp]
theorem mkMonoidHom_apply (a : α) : Associates.mkMonoidHom a = Associates.mk a :=
rfl
#align associates.mk_monoid_hom_apply Associates.mkMonoidHom_apply
theorem associated_map_mk {f : Associates α →* α} (hinv : Function.RightInverse f Associates.mk)
(a : α) : a ~ᵤ f (Associates.mk a) :=
Associates.mk_eq_mk_iff_associated.1 (hinv (Associates.mk a)).symm
#align associates.associated_map_mk Associates.associated_map_mk
theorem mk_pow (a : α) (n : ℕ) : Associates.mk (a ^ n) = Associates.mk a ^ n := by
induction n <;> simp [*, pow_succ, Associates.mk_mul_mk.symm]
#align associates.mk_pow Associates.mk_pow
theorem dvd_eq_le : ((· ∣ ·) : Associates α → Associates α → Prop) = (· ≤ ·) :=
rfl
#align associates.dvd_eq_le Associates.dvd_eq_le
theorem mul_eq_one_iff {x y : Associates α} : x * y = 1 ↔ x = 1 ∧ y = 1 :=
Iff.intro
(Quotient.inductionOn₂ x y fun a b h =>
have : a * b ~ᵤ 1 := Quotient.exact h
⟨Quotient.sound <| associated_one_of_associated_mul_one this,
Quotient.sound <| associated_one_of_associated_mul_one <| by rwa [mul_comm] at this⟩)
(by simp (config := { contextual := true }))
#align associates.mul_eq_one_iff Associates.mul_eq_one_iff
theorem units_eq_one (u : (Associates α)ˣ) : u = 1 :=
Units.ext (mul_eq_one_iff.1 u.val_inv).1
#align associates.units_eq_one Associates.units_eq_one
instance uniqueUnits : Unique (Associates α)ˣ where
default := 1
uniq := Associates.units_eq_one
#align associates.unique_units Associates.uniqueUnits
@[simp]
theorem coe_unit_eq_one (u : (Associates α)ˣ) : (u : Associates α) = 1 := by
simp [eq_iff_true_of_subsingleton]
#align associates.coe_unit_eq_one Associates.coe_unit_eq_one
theorem isUnit_iff_eq_one (a : Associates α) : IsUnit a ↔ a = 1 :=
Iff.intro (fun ⟨_, h⟩ => h ▸ coe_unit_eq_one _) fun h => h.symm ▸ isUnit_one
#align associates.is_unit_iff_eq_one Associates.isUnit_iff_eq_one
theorem isUnit_iff_eq_bot {a : Associates α} : IsUnit a ↔ a = ⊥ := by
rw [Associates.isUnit_iff_eq_one, bot_eq_one]
#align associates.is_unit_iff_eq_bot Associates.isUnit_iff_eq_bot
theorem isUnit_mk {a : α} : IsUnit (Associates.mk a) ↔ IsUnit a :=
calc
IsUnit (Associates.mk a) ↔ a ~ᵤ 1 := by
rw [isUnit_iff_eq_one, one_eq_mk_one, mk_eq_mk_iff_associated]
_ ↔ IsUnit a := associated_one_iff_isUnit
#align associates.is_unit_mk Associates.isUnit_mk
section Order
theorem mul_mono {a b c d : Associates α} (h₁ : a ≤ b) (h₂ : c ≤ d) : a * c ≤ b * d :=
let ⟨x, hx⟩ := h₁
let ⟨y, hy⟩ := h₂
⟨x * y, by simp [hx, hy, mul_comm, mul_assoc, mul_left_comm]⟩
#align associates.mul_mono Associates.mul_mono
theorem one_le {a : Associates α} : 1 ≤ a :=
Dvd.intro _ (one_mul a)
#align associates.one_le Associates.one_le
theorem le_mul_right {a b : Associates α} : a ≤ a * b :=
⟨b, rfl⟩
#align associates.le_mul_right Associates.le_mul_right
theorem le_mul_left {a b : Associates α} : a ≤ b * a := by rw [mul_comm]; exact le_mul_right
#align associates.le_mul_left Associates.le_mul_left
instance instOrderBot : OrderBot (Associates α) where
bot := 1
bot_le _ := one_le
end Order
@[simp]
theorem mk_dvd_mk {a b : α} : Associates.mk a ∣ Associates.mk b ↔ a ∣ b := by
simp only [dvd_def, mk_surjective.exists, mk_mul_mk, mk_eq_mk_iff_associated,
Associated.comm (x := b)]
constructor
· rintro ⟨x, u, rfl⟩
exact ⟨_, mul_assoc ..⟩
· rintro ⟨c, rfl⟩
use c
#align associates.mk_dvd_mk Associates.mk_dvd_mk
theorem dvd_of_mk_le_mk {a b : α} : Associates.mk a ≤ Associates.mk b → a ∣ b :=
mk_dvd_mk.mp
#align associates.dvd_of_mk_le_mk Associates.dvd_of_mk_le_mk
theorem mk_le_mk_of_dvd {a b : α} : a ∣ b → Associates.mk a ≤ Associates.mk b :=
mk_dvd_mk.mpr
#align associates.mk_le_mk_of_dvd Associates.mk_le_mk_of_dvd
theorem mk_le_mk_iff_dvd {a b : α} : Associates.mk a ≤ Associates.mk b ↔ a ∣ b := mk_dvd_mk
#align associates.mk_le_mk_iff_dvd_iff Associates.mk_le_mk_iff_dvd
@[deprecated (since := "2024-03-16")] alias mk_le_mk_iff_dvd_iff := mk_le_mk_iff_dvd
@[simp]
theorem isPrimal_mk {a : α} : IsPrimal (Associates.mk a) ↔ IsPrimal a := by
simp_rw [IsPrimal, forall_associated, mk_surjective.exists, mk_mul_mk, mk_dvd_mk]
constructor <;> intro h b c dvd <;> obtain ⟨a₁, a₂, h₁, h₂, eq⟩ := @h b c dvd
· obtain ⟨u, rfl⟩ := mk_eq_mk_iff_associated.mp eq.symm
exact ⟨a₁, a₂ * u, h₁, Units.mul_right_dvd.mpr h₂, mul_assoc _ _ _⟩
· exact ⟨a₁, a₂, h₁, h₂, congr_arg _ eq⟩
@[deprecated (since := "2024-03-16")] alias isPrimal_iff := isPrimal_mk
@[simp]
theorem decompositionMonoid_iff : DecompositionMonoid (Associates α) ↔ DecompositionMonoid α := by
simp_rw [_root_.decompositionMonoid_iff, forall_associated, isPrimal_mk]
instance instDecompositionMonoid [DecompositionMonoid α] : DecompositionMonoid (Associates α) :=
decompositionMonoid_iff.mpr ‹_›
@[simp]
theorem mk_isRelPrime_iff {a b : α} :
IsRelPrime (Associates.mk a) (Associates.mk b) ↔ IsRelPrime a b := by
simp_rw [IsRelPrime, forall_associated, mk_dvd_mk, isUnit_mk]
end CommMonoid
instance [Zero α] [Monoid α] : Zero (Associates α) :=
⟨⟦0⟧⟩
instance [Zero α] [Monoid α] : Top (Associates α) :=
⟨0⟩
@[simp] theorem mk_zero [Zero α] [Monoid α] : Associates.mk (0 : α) = 0 := rfl
section MonoidWithZero
variable [MonoidWithZero α]
@[simp]
theorem mk_eq_zero {a : α} : Associates.mk a = 0 ↔ a = 0 :=
⟨fun h => (associated_zero_iff_eq_zero a).1 <| Quotient.exact h, fun h => h.symm ▸ rfl⟩
#align associates.mk_eq_zero Associates.mk_eq_zero
@[simp]
theorem quot_out_zero : Quot.out (0 : Associates α) = 0 := by rw [← mk_eq_zero, quot_out]
theorem mk_ne_zero {a : α} : Associates.mk a ≠ 0 ↔ a ≠ 0 :=
not_congr mk_eq_zero
#align associates.mk_ne_zero Associates.mk_ne_zero
instance [Nontrivial α] : Nontrivial (Associates α) :=
⟨⟨1, 0, mk_ne_zero.2 one_ne_zero⟩⟩
theorem exists_non_zero_rep {a : Associates α} : a ≠ 0 → ∃ a0 : α, a0 ≠ 0 ∧ Associates.mk a0 = a :=
Quotient.inductionOn a fun b nz => ⟨b, mt (congr_arg Quotient.mk'') nz, rfl⟩
#align associates.exists_non_zero_rep Associates.exists_non_zero_rep
end MonoidWithZero
section CommMonoidWithZero
variable [CommMonoidWithZero α]
instance instCommMonoidWithZero : CommMonoidWithZero (Associates α) where
zero_mul := forall_associated.2 fun a ↦ by rw [← mk_zero, mk_mul_mk, zero_mul]
mul_zero := forall_associated.2 fun a ↦ by rw [← mk_zero, mk_mul_mk, mul_zero]
instance instOrderTop : OrderTop (Associates α) where
top := 0
le_top := dvd_zero
@[simp] protected theorem le_zero (a : Associates α) : a ≤ 0 := le_top
instance instBoundedOrder : BoundedOrder (Associates α) where
instance [DecidableRel ((· ∣ ·) : α → α → Prop)] :
DecidableRel ((· ∣ ·) : Associates α → Associates α → Prop) := fun a b =>
Quotient.recOnSubsingleton₂ a b fun _ _ => decidable_of_iff' _ mk_dvd_mk
theorem Prime.le_or_le {p : Associates α} (hp : Prime p) {a b : Associates α} (h : p ≤ a * b) :
p ≤ a ∨ p ≤ b :=
hp.2.2 a b h
#align associates.prime.le_or_le Associates.Prime.le_or_le
@[simp]
theorem prime_mk {p : α} : Prime (Associates.mk p) ↔ Prime p := by
rw [Prime, _root_.Prime, forall_associated]
simp only [forall_associated, mk_ne_zero, isUnit_mk, mk_mul_mk, mk_dvd_mk]
#align associates.prime_mk Associates.prime_mk
@[simp]
theorem irreducible_mk {a : α} : Irreducible (Associates.mk a) ↔ Irreducible a := by
simp only [irreducible_iff, isUnit_mk, forall_associated, isUnit_mk, mk_mul_mk,
mk_eq_mk_iff_associated, Associated.comm (x := a)]
apply Iff.rfl.and
constructor
· rintro h x y rfl
exact h _ _ <| .refl _
· rintro h x y ⟨u, rfl⟩
simpa using h x (y * u) (mul_assoc _ _ _)
#align associates.irreducible_mk Associates.irreducible_mk
@[simp]
theorem mk_dvdNotUnit_mk_iff {a b : α} :
DvdNotUnit (Associates.mk a) (Associates.mk b) ↔ DvdNotUnit a b := by
simp only [DvdNotUnit, mk_ne_zero, mk_surjective.exists, isUnit_mk, mk_mul_mk,
mk_eq_mk_iff_associated, Associated.comm (x := b)]
refine Iff.rfl.and ?_
constructor
· rintro ⟨x, hx, u, rfl⟩
refine ⟨x * u, ?_, mul_assoc ..⟩
simpa
· rintro ⟨x, ⟨hx, rfl⟩⟩
use x
#align associates.mk_dvd_not_unit_mk_iff Associates.mk_dvdNotUnit_mk_iff
theorem dvdNotUnit_of_lt {a b : Associates α} (hlt : a < b) : DvdNotUnit a b := by
constructor;
· rintro rfl
apply not_lt_of_le _ hlt
apply dvd_zero
rcases hlt with ⟨⟨x, rfl⟩, ndvd⟩
refine ⟨x, ?_, rfl⟩
contrapose! ndvd
rcases ndvd with ⟨u, rfl⟩
simp
#align associates.dvd_not_unit_of_lt Associates.dvdNotUnit_of_lt
theorem irreducible_iff_prime_iff :
(∀ a : α, Irreducible a ↔ Prime a) ↔ ∀ a : Associates α, Irreducible a ↔ Prime a := by
simp_rw [forall_associated, irreducible_mk, prime_mk]
#align associates.irreducible_iff_prime_iff Associates.irreducible_iff_prime_iff
end CommMonoidWithZero
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero α]
instance instPartialOrder : PartialOrder (Associates α) where
le_antisymm := mk_surjective.forall₂.2 fun _a _b hab hba => mk_eq_mk_iff_associated.2 <|
associated_of_dvd_dvd (dvd_of_mk_le_mk hab) (dvd_of_mk_le_mk hba)
instance instOrderedCommMonoid : OrderedCommMonoid (Associates α) where
mul_le_mul_left := fun a _ ⟨d, hd⟩ c => hd.symm ▸ mul_assoc c a d ▸ le_mul_right
instance instCancelCommMonoidWithZero : CancelCommMonoidWithZero (Associates α) :=
{ (by infer_instance : CommMonoidWithZero (Associates α)) with
mul_left_cancel_of_ne_zero := by
rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ ha h
rcases Quotient.exact' h with ⟨u, hu⟩
have hu : a * (b * ↑u) = a * c := by rwa [← mul_assoc]
exact Quotient.sound' ⟨u, mul_left_cancel₀ (mk_ne_zero.1 ha) hu⟩ }
theorem _root_.associates_irreducible_iff_prime [DecompositionMonoid α] {p : Associates α} :
Irreducible p ↔ Prime p := irreducible_iff_prime
instance : NoZeroDivisors (Associates α) := by infer_instance
theorem le_of_mul_le_mul_left (a b c : Associates α) (ha : a ≠ 0) : a * b ≤ a * c → b ≤ c
| ⟨d, hd⟩ => ⟨d, mul_left_cancel₀ ha <| by rwa [← mul_assoc]⟩
#align associates.le_of_mul_le_mul_left Associates.le_of_mul_le_mul_left
theorem one_or_eq_of_le_of_prime {p m : Associates α} (hp : Prime p) (hle : m ≤ p) :
m = 1 ∨ m = p := by
rcases mk_surjective p with ⟨p, rfl⟩
rcases mk_surjective m with ⟨m, rfl⟩
simpa [mk_eq_mk_iff_associated, Associated.comm, -Quotient.eq]
using (prime_mk.1 hp).irreducible.dvd_iff.mp (mk_le_mk_iff_dvd.1 hle)
#align associates.one_or_eq_of_le_of_prime Associates.one_or_eq_of_le_of_prime
instance : CanonicallyOrderedCommMonoid (Associates α) where
exists_mul_of_le := fun h => h
le_self_mul := fun _ b => ⟨b, rfl⟩
bot_le := fun _ => one_le
theorem dvdNotUnit_iff_lt {a b : Associates α} : DvdNotUnit a b ↔ a < b :=
dvd_and_not_dvd_iff.symm
#align associates.dvd_not_unit_iff_lt Associates.dvdNotUnit_iff_lt
theorem le_one_iff {p : Associates α} : p ≤ 1 ↔ p = 1 := by rw [← Associates.bot_eq_one, le_bot_iff]
#align associates.le_one_iff Associates.le_one_iff
end CancelCommMonoidWithZero
end Associates
section CommMonoidWithZero
theorem DvdNotUnit.isUnit_of_irreducible_right [CommMonoidWithZero α] {p q : α}
(h : DvdNotUnit p q) (hq : Irreducible q) : IsUnit p := by
obtain ⟨_, x, hx, hx'⟩ := h
exact Or.resolve_right ((irreducible_iff.1 hq).right p x hx') hx
#align dvd_not_unit.is_unit_of_irreducible_right DvdNotUnit.isUnit_of_irreducible_right
theorem not_irreducible_of_not_unit_dvdNotUnit [CommMonoidWithZero α] {p q : α} (hp : ¬IsUnit p)
(h : DvdNotUnit p q) : ¬Irreducible q :=
mt h.isUnit_of_irreducible_right hp
#align not_irreducible_of_not_unit_dvd_not_unit not_irreducible_of_not_unit_dvdNotUnit
| Mathlib/Algebra/Associated.lean | 1,243 | 1,245 | theorem DvdNotUnit.not_unit [CommMonoidWithZero α] {p q : α} (hp : DvdNotUnit p q) : ¬IsUnit q := by |
obtain ⟨-, x, hx, rfl⟩ := hp
exact fun hc => hx (isUnit_iff_dvd_one.mpr (dvd_of_mul_left_dvd (isUnit_iff_dvd_one.mp hc)))
|
/-
Copyright (c) 2023 Jz Pan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jz Pan
-/
import Mathlib.FieldTheory.SplittingField.Construction
import Mathlib.FieldTheory.IsAlgClosed.AlgebraicClosure
import Mathlib.FieldTheory.Separable
import Mathlib.FieldTheory.NormalClosure
import Mathlib.RingTheory.Polynomial.SeparableDegree
/-!
# Separable degree
This file contains basics about the separable degree of a field extension.
## Main definitions
- `Field.Emb F E`: the type of `F`-algebra homomorphisms from `E` to the algebraic closure of `E`
(the algebraic closure of `F` is usually used in the literature, but our definition has the
advantage that `Field.Emb F E` lies in the same universe as `E` rather than the maximum over `F`
and `E`). Usually denoted by $\operatorname{Emb}_F(E)$ in textbooks.
**Remark:** if `E / F` is not algebraic, then this definition makes no mathematical sense,
and if it is infinite, then its cardinality doesn't behave as expected (namely, not equal to the
field extension degree of `separableClosure F E / F`). For example, if $F = \mathbb{Q}$ and
$E = \mathbb{Q}( \mu_{p^\infty} )$, then $\operatorname{Emb}_F (E)$ is in bijection with
$\operatorname{Gal}(E/F)$, which is isomorphic to
$\mathbb{Z}_p^\times$, which is uncountable, while $[E:F]$ is countable.
**TODO:** prove or disprove that if `E / F` is algebraic and `Emb F E` is infinite, then
`Field.Emb F E` has cardinality `2 ^ Module.rank F (separableClosure F E)`.
- `Field.finSepDegree F E`: the (finite) separable degree $[E:F]_s$ of an algebraic extension
`E / F` of fields, defined to be the number of `F`-algebra homomorphisms from `E` to the algebraic
closure of `E`, as a natural number. It is zero if `Field.Emb F E` is not finite.
Note that if `E / F` is not algebraic, then this definition makes no mathematical sense.
**Remark:** the `Cardinal`-valued, potentially infinite separable degree `Field.sepDegree F E`
for a general algebraic extension `E / F` is defined to be the degree of `L / F`, where `L` is
the (relative) separable closure `separableClosure F E` of `F` in `E`, which is not defined in
this file yet. Later we will show that (`Field.finSepDegree_eq`), if `Field.Emb F E` is finite,
then these two definitions coincide.
- `Polynomial.natSepDegree`: the separable degree of a polynomial is a natural number,
defined to be the number of distinct roots of it over its splitting field.
## Main results
- `Field.embEquivOfEquiv`, `Field.finSepDegree_eq_of_equiv`:
a random bijection between `Field.Emb F E` and `Field.Emb F K` when `E` and `K` are isomorphic
as `F`-algebras. In particular, they have the same cardinality (so their
`Field.finSepDegree` are equal).
- `Field.embEquivOfAdjoinSplits`,
`Field.finSepDegree_eq_of_adjoin_splits`: a random bijection between `Field.Emb F E` and
`E →ₐ[F] K` if `E = F(S)` such that every element `s` of `S` is integral (= algebraic) over `F`
and whose minimal polynomial splits in `K`. In particular, they have the same cardinality.
- `Field.embEquivOfIsAlgClosed`,
`Field.finSepDegree_eq_of_isAlgClosed`: a random bijection between `Field.Emb F E` and
`E →ₐ[F] K` when `E / F` is algebraic and `K / F` is algebraically closed.
In particular, they have the same cardinality.
- `Field.embProdEmbOfIsAlgebraic`, `Field.finSepDegree_mul_finSepDegree_of_isAlgebraic`:
if `K / E / F` is a field extension tower, such that `K / E` is algebraic,
then there is a non-canonical bijection `Field.Emb F E × Field.Emb E K ≃ Field.Emb F K`.
In particular, the separable degrees satisfy the tower law: $[E:F]_s [K:E]_s = [K:F]_s$
(see also `FiniteDimensional.finrank_mul_finrank`).
- `Polynomial.natSepDegree_le_natDegree`: the separable degree of a polynomial is smaller than
its degree.
- `Polynomial.natSepDegree_eq_natDegree_iff`: the separable degree of a non-zero polynomial is
equal to its degree if and only if it is separable.
- `Polynomial.natSepDegree_eq_of_splits`: if a polynomial splits over `E`, then its separable degree
is equal to the number of distinct roots of it over `E`.
- `Polynomial.natSepDegree_eq_of_isAlgClosed`: the separable degree of a polynomial is equal to
the number of distinct roots of it over any algebraically closed field.
- `Polynomial.natSepDegree_expand`: if a field `F` is of exponential characteristic
`q`, then `Polynomial.expand F (q ^ n) f` and `f` have the same separable degree.
- `Polynomial.HasSeparableContraction.natSepDegree_eq`: if a polynomial has separable
contraction, then its separable degree is equal to its separable contraction degree.
- `Irreducible.natSepDegree_dvd_natDegree`: the separable degree of an irreducible
polynomial divides its degree.
- `IntermediateField.finSepDegree_adjoin_simple_eq_natSepDegree`: the separable degree of
`F⟮α⟯ / F` is equal to the separable degree of the minimal polynomial of `α` over `F`.
- `IntermediateField.finSepDegree_adjoin_simple_eq_finrank_iff`: if `α` is algebraic over `F`, then
the separable degree of `F⟮α⟯ / F` is equal to the degree of `F⟮α⟯ / F` if and only if `α` is a
separable element.
- `Field.finSepDegree_dvd_finrank`: the separable degree of any field extension `E / F` divides
the degree of `E / F`.
- `Field.finSepDegree_le_finrank`: the separable degree of a finite extension `E / F` is smaller
than the degree of `E / F`.
- `Field.finSepDegree_eq_finrank_iff`: if `E / F` is a finite extension, then its separable degree
is equal to its degree if and only if it is a separable extension.
- `IntermediateField.isSeparable_adjoin_simple_iff_separable`: `F⟮x⟯ / F` is a separable extension
if and only if `x` is a separable element.
- `IsSeparable.trans`: if `E / F` and `K / E` are both separable, then `K / F` is also separable.
## Tags
separable degree, degree, polynomial
-/
open scoped Classical Polynomial
open FiniteDimensional Polynomial IntermediateField Field
noncomputable section
universe u v w
variable (F : Type u) (E : Type v) [Field F] [Field E] [Algebra F E]
variable (K : Type w) [Field K] [Algebra F K]
namespace Field
/-- `Field.Emb F E` is the type of `F`-algebra homomorphisms from `E` to the algebraic closure
of `E`. -/
def Emb := E →ₐ[F] AlgebraicClosure E
/-- If `E / F` is an algebraic extension, then the (finite) separable degree of `E / F`
is the number of `F`-algebra homomorphisms from `E` to the algebraic closure of `E`,
as a natural number. It is defined to be zero if there are infinitely many of them.
Note that if `E / F` is not algebraic, then this definition makes no mathematical sense. -/
def finSepDegree : ℕ := Nat.card (Emb F E)
instance instInhabitedEmb : Inhabited (Emb F E) := ⟨IsScalarTower.toAlgHom F E _⟩
instance instNeZeroFinSepDegree [FiniteDimensional F E] : NeZero (finSepDegree F E) :=
⟨Nat.card_ne_zero.2 ⟨inferInstance, Fintype.finite <| minpoly.AlgHom.fintype _ _ _⟩⟩
/-- A random bijection between `Field.Emb F E` and `Field.Emb F K` when `E` and `K` are isomorphic
as `F`-algebras. -/
def embEquivOfEquiv (i : E ≃ₐ[F] K) :
Emb F E ≃ Emb F K := AlgEquiv.arrowCongr i <| AlgEquiv.symm <| by
let _ : Algebra E K := i.toAlgHom.toRingHom.toAlgebra
have : Algebra.IsAlgebraic E K := by
constructor
intro x
have h := isAlgebraic_algebraMap (R := E) (A := K) (i.symm.toAlgHom x)
rw [show ∀ y : E, (algebraMap E K) y = i.toAlgHom y from fun y ↦ rfl] at h
simpa only [AlgEquiv.toAlgHom_eq_coe, AlgHom.coe_coe, AlgEquiv.apply_symm_apply] using h
apply AlgEquiv.restrictScalars (R := F) (S := E)
exact IsAlgClosure.equivOfAlgebraic E K (AlgebraicClosure K) (AlgebraicClosure E)
/-- If `E` and `K` are isomorphic as `F`-algebras, then they have the same `Field.finSepDegree`
over `F`. -/
theorem finSepDegree_eq_of_equiv (i : E ≃ₐ[F] K) :
finSepDegree F E = finSepDegree F K := Nat.card_congr (embEquivOfEquiv F E K i)
@[simp]
theorem finSepDegree_self : finSepDegree F F = 1 := by
have : Cardinal.mk (Emb F F) = 1 := le_antisymm
(Cardinal.le_one_iff_subsingleton.2 AlgHom.subsingleton)
(Cardinal.one_le_iff_ne_zero.2 <| Cardinal.mk_ne_zero _)
rw [finSepDegree, Nat.card, this, Cardinal.one_toNat]
end Field
namespace IntermediateField
@[simp]
theorem finSepDegree_bot : finSepDegree F (⊥ : IntermediateField F E) = 1 := by
rw [finSepDegree_eq_of_equiv _ _ _ (botEquiv F E), finSepDegree_self]
section Tower
variable {F}
variable [Algebra E K] [IsScalarTower F E K]
@[simp]
theorem finSepDegree_bot' : finSepDegree F (⊥ : IntermediateField E K) = finSepDegree F E :=
finSepDegree_eq_of_equiv _ _ _ ((botEquiv E K).restrictScalars F)
@[simp]
theorem finSepDegree_top : finSepDegree F (⊤ : IntermediateField E K) = finSepDegree F K :=
finSepDegree_eq_of_equiv _ _ _ ((topEquiv (F := E) (E := K)).restrictScalars F)
end Tower
end IntermediateField
namespace Field
/-- A random bijection between `Field.Emb F E` and `E →ₐ[F] K` if `E = F(S)` such that every
element `s` of `S` is integral (= algebraic) over `F` and whose minimal polynomial splits in `K`.
Combined with `Field.instInhabitedEmb`, it can be viewed as a stronger version of
`IntermediateField.nonempty_algHom_of_adjoin_splits`. -/
def embEquivOfAdjoinSplits {S : Set E} (hS : adjoin F S = ⊤)
(hK : ∀ s ∈ S, IsIntegral F s ∧ Splits (algebraMap F K) (minpoly F s)) :
Emb F E ≃ (E →ₐ[F] K) :=
have : Algebra.IsAlgebraic F (⊤ : IntermediateField F E) :=
(hS ▸ isAlgebraic_adjoin (S := S) fun x hx ↦ (hK x hx).1)
have halg := (topEquiv (F := F) (E := E)).isAlgebraic
Classical.choice <| Function.Embedding.antisymm
(halg.algHomEmbeddingOfSplits (fun _ ↦ splits_of_mem_adjoin F (S := S) hK (hS ▸ mem_top)) _)
(halg.algHomEmbeddingOfSplits (fun _ ↦ IsAlgClosed.splits_codomain _) _)
/-- The `Field.finSepDegree F E` is equal to the cardinality of `E →ₐ[F] K`
if `E = F(S)` such that every element
`s` of `S` is integral (= algebraic) over `F` and whose minimal polynomial splits in `K`. -/
theorem finSepDegree_eq_of_adjoin_splits {S : Set E} (hS : adjoin F S = ⊤)
(hK : ∀ s ∈ S, IsIntegral F s ∧ Splits (algebraMap F K) (minpoly F s)) :
finSepDegree F E = Nat.card (E →ₐ[F] K) := Nat.card_congr (embEquivOfAdjoinSplits F E K hS hK)
/-- A random bijection between `Field.Emb F E` and `E →ₐ[F] K` when `E / F` is algebraic
and `K / F` is algebraically closed. -/
def embEquivOfIsAlgClosed [Algebra.IsAlgebraic F E] [IsAlgClosed K] :
Emb F E ≃ (E →ₐ[F] K) :=
embEquivOfAdjoinSplits F E K (adjoin_univ F E) fun s _ ↦
⟨Algebra.IsIntegral.isIntegral s, IsAlgClosed.splits_codomain _⟩
/-- The `Field.finSepDegree F E` is equal to the cardinality of `E →ₐ[F] K` as a natural number,
when `E / F` is algebraic and `K / F` is algebraically closed. -/
theorem finSepDegree_eq_of_isAlgClosed [Algebra.IsAlgebraic F E] [IsAlgClosed K] :
finSepDegree F E = Nat.card (E →ₐ[F] K) := Nat.card_congr (embEquivOfIsAlgClosed F E K)
/-- If `K / E / F` is a field extension tower, such that `K / E` is algebraic,
then there is a non-canonical bijection
`Field.Emb F E × Field.Emb E K ≃ Field.Emb F K`. A corollary of `algHomEquivSigma`. -/
def embProdEmbOfIsAlgebraic [Algebra E K] [IsScalarTower F E K] [Algebra.IsAlgebraic E K] :
Emb F E × Emb E K ≃ Emb F K :=
let e : ∀ f : E →ₐ[F] AlgebraicClosure K,
@AlgHom E K _ _ _ _ _ f.toRingHom.toAlgebra ≃ Emb E K := fun f ↦
(@embEquivOfIsAlgClosed E K _ _ _ _ _ f.toRingHom.toAlgebra).symm
(algHomEquivSigma (A := F) (B := E) (C := K) (D := AlgebraicClosure K) |>.trans
(Equiv.sigmaEquivProdOfEquiv e) |>.trans <| Equiv.prodCongrLeft <|
fun _ : Emb E K ↦ AlgEquiv.arrowCongr (@AlgEquiv.refl F E _ _ _) <|
(IsAlgClosure.equivOfAlgebraic E K (AlgebraicClosure K)
(AlgebraicClosure E)).restrictScalars F).symm
/-- If `K / E / F` is a field extension tower, such that `K / E` is algebraic, then their
separable degrees satisfy the tower law
$[E:F]_s [K:E]_s = [K:F]_s$. See also `FiniteDimensional.finrank_mul_finrank`. -/
theorem finSepDegree_mul_finSepDegree_of_isAlgebraic
[Algebra E K] [IsScalarTower F E K] [Algebra.IsAlgebraic E K] :
finSepDegree F E * finSepDegree E K = finSepDegree F K := by
simpa only [Nat.card_prod] using Nat.card_congr (embProdEmbOfIsAlgebraic F E K)
end Field
namespace Polynomial
variable {F E}
variable (f : F[X])
/-- The separable degree `Polynomial.natSepDegree` of a polynomial is a natural number,
defined to be the number of distinct roots of it over its splitting field.
This is similar to `Polynomial.natDegree` but not to `Polynomial.degree`, namely, the separable
degree of `0` is `0`, not negative infinity. -/
def natSepDegree : ℕ := (f.aroots f.SplittingField).toFinset.card
/-- The separable degree of a polynomial is smaller than its degree. -/
theorem natSepDegree_le_natDegree : f.natSepDegree ≤ f.natDegree := by
have := f.map (algebraMap F f.SplittingField) |>.card_roots'
rw [← aroots_def, natDegree_map] at this
exact (f.aroots f.SplittingField).toFinset_card_le.trans this
@[simp]
theorem natSepDegree_X_sub_C (x : F) : (X - C x).natSepDegree = 1 := by
simp only [natSepDegree, aroots_X_sub_C, Multiset.toFinset_singleton, Finset.card_singleton]
@[simp]
theorem natSepDegree_X : (X : F[X]).natSepDegree = 1 := by
simp only [natSepDegree, aroots_X, Multiset.toFinset_singleton, Finset.card_singleton]
/-- A constant polynomial has zero separable degree. -/
theorem natSepDegree_eq_zero (h : f.natDegree = 0) : f.natSepDegree = 0 := by
linarith only [natSepDegree_le_natDegree f, h]
@[simp]
theorem natSepDegree_C (x : F) : (C x).natSepDegree = 0 := natSepDegree_eq_zero _ (natDegree_C _)
@[simp]
theorem natSepDegree_zero : (0 : F[X]).natSepDegree = 0 := by
rw [← C_0, natSepDegree_C]
@[simp]
theorem natSepDegree_one : (1 : F[X]).natSepDegree = 0 := by
rw [← C_1, natSepDegree_C]
/-- A non-constant polynomial has non-zero separable degree. -/
theorem natSepDegree_ne_zero (h : f.natDegree ≠ 0) : f.natSepDegree ≠ 0 := by
rw [natSepDegree, ne_eq, Finset.card_eq_zero, ← ne_eq, ← Finset.nonempty_iff_ne_empty]
use rootOfSplits _ (SplittingField.splits f) (ne_of_apply_ne _ h)
rw [Multiset.mem_toFinset, mem_aroots]
exact ⟨ne_of_apply_ne _ h, map_rootOfSplits _ (SplittingField.splits f) (ne_of_apply_ne _ h)⟩
/-- A polynomial has zero separable degree if and only if it is constant. -/
theorem natSepDegree_eq_zero_iff : f.natSepDegree = 0 ↔ f.natDegree = 0 :=
⟨(natSepDegree_ne_zero f).mtr, natSepDegree_eq_zero f⟩
/-- A polynomial has non-zero separable degree if and only if it is non-constant. -/
theorem natSepDegree_ne_zero_iff : f.natSepDegree ≠ 0 ↔ f.natDegree ≠ 0 :=
Iff.not <| natSepDegree_eq_zero_iff f
/-- The separable degree of a non-zero polynomial is equal to its degree if and only if
it is separable. -/
theorem natSepDegree_eq_natDegree_iff (hf : f ≠ 0) :
f.natSepDegree = f.natDegree ↔ f.Separable := by
simp_rw [← card_rootSet_eq_natDegree_iff_of_splits hf (SplittingField.splits f),
rootSet_def, Finset.coe_sort_coe, Fintype.card_coe]
rfl
/-- If a polynomial is separable, then its separable degree is equal to its degree. -/
theorem natSepDegree_eq_natDegree_of_separable (h : f.Separable) :
f.natSepDegree = f.natDegree := (natSepDegree_eq_natDegree_iff f h.ne_zero).2 h
variable {f} in
/-- Same as `Polynomial.natSepDegree_eq_natDegree_of_separable`, but enables the use of
dot notation. -/
theorem Separable.natSepDegree_eq_natDegree (h : f.Separable) :
f.natSepDegree = f.natDegree := natSepDegree_eq_natDegree_of_separable f h
/-- If a polynomial splits over `E`, then its separable degree is equal to
the number of distinct roots of it over `E`. -/
theorem natSepDegree_eq_of_splits (h : f.Splits (algebraMap F E)) :
f.natSepDegree = (f.aroots E).toFinset.card := by
rw [aroots, ← (SplittingField.lift f h).comp_algebraMap, ← map_map,
roots_map _ ((splits_id_iff_splits _).mpr <| SplittingField.splits f),
Multiset.toFinset_map, Finset.card_image_of_injective _ (RingHom.injective _), natSepDegree]
variable (E) in
/-- The separable degree of a polynomial is equal to
the number of distinct roots of it over any algebraically closed field. -/
theorem natSepDegree_eq_of_isAlgClosed [IsAlgClosed E] :
f.natSepDegree = (f.aroots E).toFinset.card :=
natSepDegree_eq_of_splits f (IsAlgClosed.splits_codomain f)
variable (E) in
theorem natSepDegree_map : (f.map (algebraMap F E)).natSepDegree = f.natSepDegree := by
simp_rw [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure E), aroots_def, map_map,
← IsScalarTower.algebraMap_eq]
@[simp]
| Mathlib/FieldTheory/SeparableDegree.lean | 352 | 354 | theorem natSepDegree_C_mul {x : F} (hx : x ≠ 0) :
(C x * f).natSepDegree = f.natSepDegree := by |
simp only [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_C_mul _ hx]
|
/-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Geometry.Euclidean.Angle.Oriented.Affine
import Mathlib.Geometry.Euclidean.Angle.Unoriented.RightAngle
#align_import geometry.euclidean.angle.oriented.right_angle from "leanprover-community/mathlib"@"46b633fd842bef9469441c0209906f6dddd2b4f5"
/-!
# Oriented angles in right-angled triangles.
This file proves basic geometrical results about distances and oriented angles in (possibly
degenerate) right-angled triangles in real inner product spaces and Euclidean affine spaces.
-/
noncomputable section
open scoped EuclideanGeometry
open scoped Real
open scoped RealInnerProductSpace
namespace Orientation
open FiniteDimensional
variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V]
variable [hd2 : Fact (finrank ℝ V = 2)] (o : Orientation ℝ V (Fin 2))
/-- An angle in a right-angled triangle expressed using `arccos`. -/
theorem oangle_add_right_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle x (x + y) = Real.arccos (‖x‖ / ‖x + y‖) := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs,
InnerProductGeometry.angle_add_eq_arccos_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)]
#align orientation.oangle_add_right_eq_arccos_of_oangle_eq_pi_div_two Orientation.oangle_add_right_eq_arccos_of_oangle_eq_pi_div_two
/-- An angle in a right-angled triangle expressed using `arccos`. -/
theorem oangle_add_left_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle (x + y) y = Real.arccos (‖y‖ / ‖x + y‖) := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).oangle_add_right_eq_arccos_of_oangle_eq_pi_div_two h
#align orientation.oangle_add_left_eq_arccos_of_oangle_eq_pi_div_two Orientation.oangle_add_left_eq_arccos_of_oangle_eq_pi_div_two
/-- An angle in a right-angled triangle expressed using `arcsin`. -/
theorem oangle_add_right_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle x (x + y) = Real.arcsin (‖y‖ / ‖x + y‖) := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs,
InnerProductGeometry.angle_add_eq_arcsin_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))]
#align orientation.oangle_add_right_eq_arcsin_of_oangle_eq_pi_div_two Orientation.oangle_add_right_eq_arcsin_of_oangle_eq_pi_div_two
/-- An angle in a right-angled triangle expressed using `arcsin`. -/
theorem oangle_add_left_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle (x + y) y = Real.arcsin (‖x‖ / ‖x + y‖) := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).oangle_add_right_eq_arcsin_of_oangle_eq_pi_div_two h
#align orientation.oangle_add_left_eq_arcsin_of_oangle_eq_pi_div_two Orientation.oangle_add_left_eq_arcsin_of_oangle_eq_pi_div_two
/-- An angle in a right-angled triangle expressed using `arctan`. -/
theorem oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle x (x + y) = Real.arctan (‖y‖ / ‖x‖) := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs,
InnerProductGeometry.angle_add_eq_arctan_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h) (o.left_ne_zero_of_oangle_eq_pi_div_two h)]
#align orientation.oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two Orientation.oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two
/-- An angle in a right-angled triangle expressed using `arctan`. -/
theorem oangle_add_left_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
o.oangle (x + y) y = Real.arctan (‖x‖ / ‖y‖) := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two h
#align orientation.oangle_add_left_eq_arctan_of_oangle_eq_pi_div_two Orientation.oangle_add_left_eq_arctan_of_oangle_eq_pi_div_two
/-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/
theorem cos_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.cos (o.oangle x (x + y)) = ‖x‖ / ‖x + y‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe,
InnerProductGeometry.cos_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)]
#align orientation.cos_oangle_add_right_of_oangle_eq_pi_div_two Orientation.cos_oangle_add_right_of_oangle_eq_pi_div_two
/-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/
theorem cos_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.cos (o.oangle (x + y) y) = ‖y‖ / ‖x + y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).cos_oangle_add_right_of_oangle_eq_pi_div_two h
#align orientation.cos_oangle_add_left_of_oangle_eq_pi_div_two Orientation.cos_oangle_add_left_of_oangle_eq_pi_div_two
/-- The sine of an angle in a right-angled triangle as a ratio of sides. -/
theorem sin_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.sin (o.oangle x (x + y)) = ‖y‖ / ‖x + y‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe,
InnerProductGeometry.sin_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)
(Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))]
#align orientation.sin_oangle_add_right_of_oangle_eq_pi_div_two Orientation.sin_oangle_add_right_of_oangle_eq_pi_div_two
/-- The sine of an angle in a right-angled triangle as a ratio of sides. -/
theorem sin_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.sin (o.oangle (x + y) y) = ‖x‖ / ‖x + y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).sin_oangle_add_right_of_oangle_eq_pi_div_two h
#align orientation.sin_oangle_add_left_of_oangle_eq_pi_div_two Orientation.sin_oangle_add_left_of_oangle_eq_pi_div_two
/-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/
theorem tan_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.tan (o.oangle x (x + y)) = ‖y‖ / ‖x‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe,
InnerProductGeometry.tan_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)]
#align orientation.tan_oangle_add_right_of_oangle_eq_pi_div_two Orientation.tan_oangle_add_right_of_oangle_eq_pi_div_two
/-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/
theorem tan_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) :
Real.Angle.tan (o.oangle (x + y) y) = ‖x‖ / ‖y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).tan_oangle_add_right_of_oangle_eq_pi_div_two h
#align orientation.tan_oangle_add_left_of_oangle_eq_pi_div_two Orientation.tan_oangle_add_left_of_oangle_eq_pi_div_two
/-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
adjacent side. -/
theorem cos_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle x (x + y)) * ‖x + y‖ = ‖x‖ := by
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe,
InnerProductGeometry.cos_angle_add_mul_norm_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two h)]
#align orientation.cos_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two Orientation.cos_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two
/-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
adjacent side. -/
theorem cos_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle (x + y) y) * ‖x + y‖ = ‖y‖ := by
rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢
rw [add_comm]
exact (-o).cos_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two h
#align orientation.cos_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two Orientation.cos_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two
/-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the
opposite side. -/
| Mathlib/Geometry/Euclidean/Angle/Oriented/RightAngle.lean | 164 | 170 | theorem sin_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two {x y : V}
(h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle x (x + y)) * ‖x + y‖ = ‖y‖ := by |
have hs : (o.oangle x (x + y)).sign = 1 := by
rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two]
rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe,
InnerProductGeometry.sin_angle_add_mul_norm_of_inner_eq_zero
(o.inner_eq_zero_of_oangle_eq_pi_div_two 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.Order.Interval.Set.OrdConnectedComponent
import Mathlib.Topology.Order.Basic
#align_import topology.algebra.order.t5 from "leanprover-community/mathlib"@"4c19a16e4b705bf135cf9a80ac18fcc99c438514"
/-!
# Linear order is a completely normal Hausdorff topological space
In this file we prove that a linear order with order topology is a completely normal Hausdorff
topological space.
-/
open Filter Set Function OrderDual Topology Interval
variable {X : Type*} [LinearOrder X] [TopologicalSpace X] [OrderTopology X] {a b c : X}
{s t : Set X}
namespace Set
@[simp]
| Mathlib/Topology/Order/T5.lean | 27 | 30 | theorem ordConnectedComponent_mem_nhds : ordConnectedComponent s a ∈ 𝓝 a ↔ s ∈ 𝓝 a := by |
refine ⟨fun h => mem_of_superset h ordConnectedComponent_subset, fun h => ?_⟩
rcases exists_Icc_mem_subset_of_mem_nhds h with ⟨b, c, ha, ha', hs⟩
exact mem_of_superset ha' (subset_ordConnectedComponent ha hs)
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Floris van Doorn, Violeta Hernández Palacios
-/
import Mathlib.SetTheory.Ordinal.Basic
import Mathlib.Data.Nat.SuccPred
#align_import set_theory.ordinal.arithmetic from "leanprover-community/mathlib"@"31b269b60935483943542d547a6dd83a66b37dc7"
/-!
# Ordinal arithmetic
Ordinals have an addition (corresponding to disjoint union) that turns them into an additive
monoid, and a multiplication (corresponding to the lexicographic order on the product) that turns
them into a monoid. One can also define correspondingly a subtraction, a division, a successor
function, a power function and a logarithm function.
We also define limit ordinals and prove the basic induction principle on ordinals separating
successor ordinals and limit ordinals, in `limitRecOn`.
## Main definitions and results
* `o₁ + o₂` is the order on the disjoint union of `o₁` and `o₂` obtained by declaring that
every element of `o₁` is smaller than every element of `o₂`.
* `o₁ - o₂` is the unique ordinal `o` such that `o₂ + o = o₁`, when `o₂ ≤ o₁`.
* `o₁ * o₂` is the lexicographic order on `o₂ × o₁`.
* `o₁ / o₂` is the ordinal `o` such that `o₁ = o₂ * o + o'` with `o' < o₂`. We also define the
divisibility predicate, and a modulo operation.
* `Order.succ o = o + 1` is the successor of `o`.
* `pred o` if the predecessor of `o`. If `o` is not a successor, we set `pred o = o`.
We discuss the properties of casts of natural numbers of and of `ω` with respect to these
operations.
Some properties of the operations are also used to discuss general tools on ordinals:
* `IsLimit o`: an ordinal is a limit ordinal if it is neither `0` nor a successor.
* `limitRecOn` is the main induction principle of ordinals: if one can prove a property by
induction at successor ordinals and at limit ordinals, then it holds for all ordinals.
* `IsNormal`: a function `f : Ordinal → Ordinal` satisfies `IsNormal` if it is strictly increasing
and order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for
`a < o`.
* `enumOrd`: enumerates an unbounded set of ordinals by the ordinals themselves.
* `sup`, `lsub`: the supremum / least strict upper bound of an indexed family of ordinals in
`Type u`, as an ordinal in `Type u`.
* `bsup`, `blsub`: the supremum / least strict upper bound of a set of ordinals indexed by ordinals
less than a given ordinal `o`.
Various other basic arithmetic results are given in `Principal.lean` instead.
-/
assert_not_exists Field
assert_not_exists Module
noncomputable section
open Function Cardinal Set Equiv Order
open scoped Classical
open Cardinal Ordinal
universe u v w
namespace Ordinal
variable {α : Type*} {β : Type*} {γ : Type*} {r : α → α → Prop} {s : β → β → Prop}
{t : γ → γ → Prop}
/-! ### Further properties of addition on ordinals -/
@[simp]
theorem lift_add (a b : Ordinal.{v}) : lift.{u} (a + b) = lift.{u} a + lift.{u} b :=
Quotient.inductionOn₂ a b fun ⟨_α, _r, _⟩ ⟨_β, _s, _⟩ =>
Quotient.sound
⟨(RelIso.preimage Equiv.ulift _).trans
(RelIso.sumLexCongr (RelIso.preimage Equiv.ulift _) (RelIso.preimage Equiv.ulift _)).symm⟩
#align ordinal.lift_add Ordinal.lift_add
@[simp]
theorem lift_succ (a : Ordinal.{v}) : lift.{u} (succ a) = succ (lift.{u} a) := by
rw [← add_one_eq_succ, lift_add, lift_one]
rfl
#align ordinal.lift_succ Ordinal.lift_succ
instance add_contravariantClass_le : ContravariantClass Ordinal.{u} Ordinal.{u} (· + ·) (· ≤ ·) :=
⟨fun a b c =>
inductionOn a fun α r hr =>
inductionOn b fun β₁ s₁ hs₁ =>
inductionOn c fun β₂ s₂ hs₂ ⟨f⟩ =>
⟨have fl : ∀ a, f (Sum.inl a) = Sum.inl a := fun a => by
simpa only [InitialSeg.trans_apply, InitialSeg.leAdd_apply] using
@InitialSeg.eq _ _ _ _ _
((InitialSeg.leAdd r s₁).trans f) (InitialSeg.leAdd r s₂) a
have : ∀ b, { b' // f (Sum.inr b) = Sum.inr b' } := by
intro b; cases e : f (Sum.inr b)
· rw [← fl] at e
have := f.inj' e
contradiction
· exact ⟨_, rfl⟩
let g (b) := (this b).1
have fr : ∀ b, f (Sum.inr b) = Sum.inr (g b) := fun b => (this b).2
⟨⟨⟨g, fun x y h => by
injection f.inj' (by rw [fr, fr, h] : f (Sum.inr x) = f (Sum.inr y))⟩,
@fun a b => by
-- Porting note:
-- `relEmbedding.coe_fn_to_embedding` & `initial_seg.coe_fn_to_rel_embedding`
-- → `InitialSeg.coe_coe_fn`
simpa only [Sum.lex_inr_inr, fr, InitialSeg.coe_coe_fn, Embedding.coeFn_mk] using
@RelEmbedding.map_rel_iff _ _ _ _ f.toRelEmbedding (Sum.inr a) (Sum.inr b)⟩,
fun a b H => by
rcases f.init (by rw [fr] <;> exact Sum.lex_inr_inr.2 H) with ⟨a' | a', h⟩
· rw [fl] at h
cases h
· rw [fr] at h
exact ⟨a', Sum.inr.inj h⟩⟩⟩⟩
#align ordinal.add_contravariant_class_le Ordinal.add_contravariantClass_le
theorem add_left_cancel (a) {b c : Ordinal} : a + b = a + c ↔ b = c := by
simp only [le_antisymm_iff, add_le_add_iff_left]
#align ordinal.add_left_cancel Ordinal.add_left_cancel
private theorem add_lt_add_iff_left' (a) {b c : Ordinal} : a + b < a + c ↔ b < c := by
rw [← not_le, ← not_le, add_le_add_iff_left]
instance add_covariantClass_lt : CovariantClass Ordinal.{u} Ordinal.{u} (· + ·) (· < ·) :=
⟨fun a _b _c => (add_lt_add_iff_left' a).2⟩
#align ordinal.add_covariant_class_lt Ordinal.add_covariantClass_lt
instance add_contravariantClass_lt : ContravariantClass Ordinal.{u} Ordinal.{u} (· + ·) (· < ·) :=
⟨fun a _b _c => (add_lt_add_iff_left' a).1⟩
#align ordinal.add_contravariant_class_lt Ordinal.add_contravariantClass_lt
instance add_swap_contravariantClass_lt :
ContravariantClass Ordinal.{u} Ordinal.{u} (swap (· + ·)) (· < ·) :=
⟨fun _a _b _c => lt_imp_lt_of_le_imp_le fun h => add_le_add_right h _⟩
#align ordinal.add_swap_contravariant_class_lt Ordinal.add_swap_contravariantClass_lt
theorem add_le_add_iff_right {a b : Ordinal} : ∀ n : ℕ, a + n ≤ b + n ↔ a ≤ b
| 0 => by simp
| n + 1 => by
simp only [natCast_succ, add_succ, add_succ, succ_le_succ_iff, add_le_add_iff_right]
#align ordinal.add_le_add_iff_right Ordinal.add_le_add_iff_right
theorem add_right_cancel {a b : Ordinal} (n : ℕ) : a + n = b + n ↔ a = b := by
simp only [le_antisymm_iff, add_le_add_iff_right]
#align ordinal.add_right_cancel Ordinal.add_right_cancel
theorem add_eq_zero_iff {a b : Ordinal} : a + b = 0 ↔ a = 0 ∧ b = 0 :=
inductionOn a fun α r _ =>
inductionOn b fun β s _ => by
simp_rw [← type_sum_lex, type_eq_zero_iff_isEmpty]
exact isEmpty_sum
#align ordinal.add_eq_zero_iff Ordinal.add_eq_zero_iff
theorem left_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : a = 0 :=
(add_eq_zero_iff.1 h).1
#align ordinal.left_eq_zero_of_add_eq_zero Ordinal.left_eq_zero_of_add_eq_zero
theorem right_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : b = 0 :=
(add_eq_zero_iff.1 h).2
#align ordinal.right_eq_zero_of_add_eq_zero Ordinal.right_eq_zero_of_add_eq_zero
/-! ### The predecessor of an ordinal -/
/-- The ordinal predecessor of `o` is `o'` if `o = succ o'`,
and `o` otherwise. -/
def pred (o : Ordinal) : Ordinal :=
if h : ∃ a, o = succ a then Classical.choose h else o
#align ordinal.pred Ordinal.pred
@[simp]
theorem pred_succ (o) : pred (succ o) = o := by
have h : ∃ a, succ o = succ a := ⟨_, rfl⟩;
simpa only [pred, dif_pos h] using (succ_injective <| Classical.choose_spec h).symm
#align ordinal.pred_succ Ordinal.pred_succ
theorem pred_le_self (o) : pred o ≤ o :=
if h : ∃ a, o = succ a then by
let ⟨a, e⟩ := h
rw [e, pred_succ]; exact le_succ a
else by rw [pred, dif_neg h]
#align ordinal.pred_le_self Ordinal.pred_le_self
theorem pred_eq_iff_not_succ {o} : pred o = o ↔ ¬∃ a, o = succ a :=
⟨fun e ⟨a, e'⟩ => by rw [e', pred_succ] at e; exact (lt_succ a).ne e, fun h => dif_neg h⟩
#align ordinal.pred_eq_iff_not_succ Ordinal.pred_eq_iff_not_succ
theorem pred_eq_iff_not_succ' {o} : pred o = o ↔ ∀ a, o ≠ succ a := by
simpa using pred_eq_iff_not_succ
#align ordinal.pred_eq_iff_not_succ' Ordinal.pred_eq_iff_not_succ'
theorem pred_lt_iff_is_succ {o} : pred o < o ↔ ∃ a, o = succ a :=
Iff.trans (by simp only [le_antisymm_iff, pred_le_self, true_and_iff, not_le])
(iff_not_comm.1 pred_eq_iff_not_succ).symm
#align ordinal.pred_lt_iff_is_succ Ordinal.pred_lt_iff_is_succ
@[simp]
theorem pred_zero : pred 0 = 0 :=
pred_eq_iff_not_succ'.2 fun a => (succ_ne_zero a).symm
#align ordinal.pred_zero Ordinal.pred_zero
theorem succ_pred_iff_is_succ {o} : succ (pred o) = o ↔ ∃ a, o = succ a :=
⟨fun e => ⟨_, e.symm⟩, fun ⟨a, e⟩ => by simp only [e, pred_succ]⟩
#align ordinal.succ_pred_iff_is_succ Ordinal.succ_pred_iff_is_succ
theorem succ_lt_of_not_succ {o b : Ordinal} (h : ¬∃ a, o = succ a) : succ b < o ↔ b < o :=
⟨(lt_succ b).trans, fun l => lt_of_le_of_ne (succ_le_of_lt l) fun e => h ⟨_, e.symm⟩⟩
#align ordinal.succ_lt_of_not_succ Ordinal.succ_lt_of_not_succ
theorem lt_pred {a b} : a < pred b ↔ succ a < b :=
if h : ∃ a, b = succ a then by
let ⟨c, e⟩ := h
rw [e, pred_succ, succ_lt_succ_iff]
else by simp only [pred, dif_neg h, succ_lt_of_not_succ h]
#align ordinal.lt_pred Ordinal.lt_pred
theorem pred_le {a b} : pred a ≤ b ↔ a ≤ succ b :=
le_iff_le_iff_lt_iff_lt.2 lt_pred
#align ordinal.pred_le Ordinal.pred_le
@[simp]
theorem lift_is_succ {o : Ordinal.{v}} : (∃ a, lift.{u} o = succ a) ↔ ∃ a, o = succ a :=
⟨fun ⟨a, h⟩ =>
let ⟨b, e⟩ := lift_down <| show a ≤ lift.{u} o from le_of_lt <| h.symm ▸ lt_succ a
⟨b, lift_inj.1 <| by rw [h, ← e, lift_succ]⟩,
fun ⟨a, h⟩ => ⟨lift.{u} a, by simp only [h, lift_succ]⟩⟩
#align ordinal.lift_is_succ Ordinal.lift_is_succ
@[simp]
theorem lift_pred (o : Ordinal.{v}) : lift.{u} (pred o) = pred (lift.{u} o) :=
if h : ∃ a, o = succ a then by cases' h with a e; simp only [e, pred_succ, lift_succ]
else by rw [pred_eq_iff_not_succ.2 h, pred_eq_iff_not_succ.2 (mt lift_is_succ.1 h)]
#align ordinal.lift_pred Ordinal.lift_pred
/-! ### Limit ordinals -/
/-- A limit ordinal is an ordinal which is not zero and not a successor. -/
def IsLimit (o : Ordinal) : Prop :=
o ≠ 0 ∧ ∀ a < o, succ a < o
#align ordinal.is_limit Ordinal.IsLimit
theorem IsLimit.isSuccLimit {o} (h : IsLimit o) : IsSuccLimit o := isSuccLimit_iff_succ_lt.mpr h.2
theorem IsLimit.succ_lt {o a : Ordinal} (h : IsLimit o) : a < o → succ a < o :=
h.2 a
#align ordinal.is_limit.succ_lt Ordinal.IsLimit.succ_lt
theorem isSuccLimit_zero : IsSuccLimit (0 : Ordinal) := isSuccLimit_bot
theorem not_zero_isLimit : ¬IsLimit 0
| ⟨h, _⟩ => h rfl
#align ordinal.not_zero_is_limit Ordinal.not_zero_isLimit
theorem not_succ_isLimit (o) : ¬IsLimit (succ o)
| ⟨_, h⟩ => lt_irrefl _ (h _ (lt_succ o))
#align ordinal.not_succ_is_limit Ordinal.not_succ_isLimit
theorem not_succ_of_isLimit {o} (h : IsLimit o) : ¬∃ a, o = succ a
| ⟨a, e⟩ => not_succ_isLimit a (e ▸ h)
#align ordinal.not_succ_of_is_limit Ordinal.not_succ_of_isLimit
theorem succ_lt_of_isLimit {o a : Ordinal} (h : IsLimit o) : succ a < o ↔ a < o :=
⟨(lt_succ a).trans, h.2 _⟩
#align ordinal.succ_lt_of_is_limit Ordinal.succ_lt_of_isLimit
theorem le_succ_of_isLimit {o} (h : IsLimit o) {a} : o ≤ succ a ↔ o ≤ a :=
le_iff_le_iff_lt_iff_lt.2 <| succ_lt_of_isLimit h
#align ordinal.le_succ_of_is_limit Ordinal.le_succ_of_isLimit
theorem limit_le {o} (h : IsLimit o) {a} : o ≤ a ↔ ∀ x < o, x ≤ a :=
⟨fun h _x l => l.le.trans h, fun H =>
(le_succ_of_isLimit h).1 <| le_of_not_lt fun hn => not_lt_of_le (H _ hn) (lt_succ a)⟩
#align ordinal.limit_le Ordinal.limit_le
theorem lt_limit {o} (h : IsLimit o) {a} : a < o ↔ ∃ x < o, a < x := by
-- Porting note: `bex_def` is required.
simpa only [not_forall₂, not_le, bex_def] using not_congr (@limit_le _ h a)
#align ordinal.lt_limit Ordinal.lt_limit
@[simp]
theorem lift_isLimit (o) : IsLimit (lift o) ↔ IsLimit o :=
and_congr (not_congr <| by simpa only [lift_zero] using @lift_inj o 0)
⟨fun H a h => lift_lt.1 <| by simpa only [lift_succ] using H _ (lift_lt.2 h), fun H a h => by
obtain ⟨a', rfl⟩ := lift_down h.le
rw [← lift_succ, lift_lt]
exact H a' (lift_lt.1 h)⟩
#align ordinal.lift_is_limit Ordinal.lift_isLimit
theorem IsLimit.pos {o : Ordinal} (h : IsLimit o) : 0 < o :=
lt_of_le_of_ne (Ordinal.zero_le _) h.1.symm
#align ordinal.is_limit.pos Ordinal.IsLimit.pos
theorem IsLimit.one_lt {o : Ordinal} (h : IsLimit o) : 1 < o := by
simpa only [succ_zero] using h.2 _ h.pos
#align ordinal.is_limit.one_lt Ordinal.IsLimit.one_lt
theorem IsLimit.nat_lt {o : Ordinal} (h : IsLimit o) : ∀ n : ℕ, (n : Ordinal) < o
| 0 => h.pos
| n + 1 => h.2 _ (IsLimit.nat_lt h n)
#align ordinal.is_limit.nat_lt Ordinal.IsLimit.nat_lt
theorem zero_or_succ_or_limit (o : Ordinal) : o = 0 ∨ (∃ a, o = succ a) ∨ IsLimit o :=
if o0 : o = 0 then Or.inl o0
else
if h : ∃ a, o = succ a then Or.inr (Or.inl h)
else Or.inr <| Or.inr ⟨o0, fun _a => (succ_lt_of_not_succ h).2⟩
#align ordinal.zero_or_succ_or_limit Ordinal.zero_or_succ_or_limit
/-- Main induction principle of ordinals: if one can prove a property by
induction at successor ordinals and at limit ordinals, then it holds for all ordinals. -/
@[elab_as_elim]
def limitRecOn {C : Ordinal → Sort*} (o : Ordinal) (H₁ : C 0) (H₂ : ∀ o, C o → C (succ o))
(H₃ : ∀ o, IsLimit o → (∀ o' < o, C o') → C o) : C o :=
SuccOrder.limitRecOn o (fun o _ ↦ H₂ o) fun o hl ↦
if h : o = 0 then fun _ ↦ h ▸ H₁ else H₃ o ⟨h, fun _ ↦ hl.succ_lt⟩
#align ordinal.limit_rec_on Ordinal.limitRecOn
@[simp]
theorem limitRecOn_zero {C} (H₁ H₂ H₃) : @limitRecOn C 0 H₁ H₂ H₃ = H₁ := by
rw [limitRecOn, SuccOrder.limitRecOn_limit _ _ isSuccLimit_zero, dif_pos rfl]
#align ordinal.limit_rec_on_zero Ordinal.limitRecOn_zero
@[simp]
theorem limitRecOn_succ {C} (o H₁ H₂ H₃) :
@limitRecOn C (succ o) H₁ H₂ H₃ = H₂ o (@limitRecOn C o H₁ H₂ H₃) := by
simp_rw [limitRecOn, SuccOrder.limitRecOn_succ _ _ (not_isMax _)]
#align ordinal.limit_rec_on_succ Ordinal.limitRecOn_succ
@[simp]
theorem limitRecOn_limit {C} (o H₁ H₂ H₃ h) :
@limitRecOn C o H₁ H₂ H₃ = H₃ o h fun x _h => @limitRecOn C x H₁ H₂ H₃ := by
simp_rw [limitRecOn, SuccOrder.limitRecOn_limit _ _ h.isSuccLimit, dif_neg h.1]
#align ordinal.limit_rec_on_limit Ordinal.limitRecOn_limit
instance orderTopOutSucc (o : Ordinal) : OrderTop (succ o).out.α :=
@OrderTop.mk _ _ (Top.mk _) le_enum_succ
#align ordinal.order_top_out_succ Ordinal.orderTopOutSucc
theorem enum_succ_eq_top {o : Ordinal} :
enum (· < ·) o
(by
rw [type_lt]
exact lt_succ o) =
(⊤ : (succ o).out.α) :=
rfl
#align ordinal.enum_succ_eq_top Ordinal.enum_succ_eq_top
theorem has_succ_of_type_succ_lt {α} {r : α → α → Prop} [wo : IsWellOrder α r]
(h : ∀ a < type r, succ a < type r) (x : α) : ∃ y, r x y := by
use enum r (succ (typein r x)) (h _ (typein_lt_type r x))
convert (enum_lt_enum (typein_lt_type r x)
(h _ (typein_lt_type r x))).mpr (lt_succ _); rw [enum_typein]
#align ordinal.has_succ_of_type_succ_lt Ordinal.has_succ_of_type_succ_lt
theorem out_no_max_of_succ_lt {o : Ordinal} (ho : ∀ a < o, succ a < o) : NoMaxOrder o.out.α :=
⟨has_succ_of_type_succ_lt (by rwa [type_lt])⟩
#align ordinal.out_no_max_of_succ_lt Ordinal.out_no_max_of_succ_lt
theorem bounded_singleton {r : α → α → Prop} [IsWellOrder α r] (hr : (type r).IsLimit) (x) :
Bounded r {x} := by
refine ⟨enum r (succ (typein r x)) (hr.2 _ (typein_lt_type r x)), ?_⟩
intro b hb
rw [mem_singleton_iff.1 hb]
nth_rw 1 [← enum_typein r x]
rw [@enum_lt_enum _ r]
apply lt_succ
#align ordinal.bounded_singleton Ordinal.bounded_singleton
-- Porting note: `· < ·` requires a type ascription for an `IsWellOrder` instance.
theorem type_subrel_lt (o : Ordinal.{u}) :
type (Subrel ((· < ·) : Ordinal → Ordinal → Prop) { o' : Ordinal | o' < o })
= Ordinal.lift.{u + 1} o := by
refine Quotient.inductionOn o ?_
rintro ⟨α, r, wo⟩; apply Quotient.sound
-- Porting note: `symm; refine' [term]` → `refine' [term].symm`
constructor; refine ((RelIso.preimage Equiv.ulift r).trans (enumIso r).symm).symm
#align ordinal.type_subrel_lt Ordinal.type_subrel_lt
theorem mk_initialSeg (o : Ordinal.{u}) :
#{ o' : Ordinal | o' < o } = Cardinal.lift.{u + 1} o.card := by
rw [lift_card, ← type_subrel_lt, card_type]
#align ordinal.mk_initial_seg Ordinal.mk_initialSeg
/-! ### Normal ordinal functions -/
/-- A normal ordinal function is a strictly increasing function which is
order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for
`a < o`. -/
def IsNormal (f : Ordinal → Ordinal) : Prop :=
(∀ o, f o < f (succ o)) ∧ ∀ o, IsLimit o → ∀ a, f o ≤ a ↔ ∀ b < o, f b ≤ a
#align ordinal.is_normal Ordinal.IsNormal
theorem IsNormal.limit_le {f} (H : IsNormal f) :
∀ {o}, IsLimit o → ∀ {a}, f o ≤ a ↔ ∀ b < o, f b ≤ a :=
@H.2
#align ordinal.is_normal.limit_le Ordinal.IsNormal.limit_le
theorem IsNormal.limit_lt {f} (H : IsNormal f) {o} (h : IsLimit o) {a} :
a < f o ↔ ∃ b < o, a < f b :=
not_iff_not.1 <| by simpa only [exists_prop, not_exists, not_and, not_lt] using H.2 _ h a
#align ordinal.is_normal.limit_lt Ordinal.IsNormal.limit_lt
theorem IsNormal.strictMono {f} (H : IsNormal f) : StrictMono f := fun a b =>
limitRecOn b (Not.elim (not_lt_of_le <| Ordinal.zero_le _))
(fun _b IH h =>
(lt_or_eq_of_le (le_of_lt_succ h)).elim (fun h => (IH h).trans (H.1 _)) fun e => e ▸ H.1 _)
fun _b l _IH h => lt_of_lt_of_le (H.1 a) ((H.2 _ l _).1 le_rfl _ (l.2 _ h))
#align ordinal.is_normal.strict_mono Ordinal.IsNormal.strictMono
theorem IsNormal.monotone {f} (H : IsNormal f) : Monotone f :=
H.strictMono.monotone
#align ordinal.is_normal.monotone Ordinal.IsNormal.monotone
theorem isNormal_iff_strictMono_limit (f : Ordinal → Ordinal) :
IsNormal f ↔ StrictMono f ∧ ∀ o, IsLimit o → ∀ a, (∀ b < o, f b ≤ a) → f o ≤ a :=
⟨fun hf => ⟨hf.strictMono, fun a ha c => (hf.2 a ha c).2⟩, fun ⟨hs, hl⟩ =>
⟨fun a => hs (lt_succ a), fun a ha c =>
⟨fun hac _b hba => ((hs hba).trans_le hac).le, hl a ha c⟩⟩⟩
#align ordinal.is_normal_iff_strict_mono_limit Ordinal.isNormal_iff_strictMono_limit
theorem IsNormal.lt_iff {f} (H : IsNormal f) {a b} : f a < f b ↔ a < b :=
StrictMono.lt_iff_lt <| H.strictMono
#align ordinal.is_normal.lt_iff Ordinal.IsNormal.lt_iff
theorem IsNormal.le_iff {f} (H : IsNormal f) {a b} : f a ≤ f b ↔ a ≤ b :=
le_iff_le_iff_lt_iff_lt.2 H.lt_iff
#align ordinal.is_normal.le_iff Ordinal.IsNormal.le_iff
theorem IsNormal.inj {f} (H : IsNormal f) {a b} : f a = f b ↔ a = b := by
simp only [le_antisymm_iff, H.le_iff]
#align ordinal.is_normal.inj Ordinal.IsNormal.inj
theorem IsNormal.self_le {f} (H : IsNormal f) (a) : a ≤ f a :=
lt_wf.self_le_of_strictMono H.strictMono a
#align ordinal.is_normal.self_le Ordinal.IsNormal.self_le
theorem IsNormal.le_set {f o} (H : IsNormal f) (p : Set Ordinal) (p0 : p.Nonempty) (b)
(H₂ : ∀ o, b ≤ o ↔ ∀ a ∈ p, a ≤ o) : f b ≤ o ↔ ∀ a ∈ p, f a ≤ o :=
⟨fun h a pa => (H.le_iff.2 ((H₂ _).1 le_rfl _ pa)).trans h, fun h => by
-- Porting note: `refine'` didn't work well so `induction` is used
induction b using limitRecOn with
| H₁ =>
cases' p0 with x px
have := Ordinal.le_zero.1 ((H₂ _).1 (Ordinal.zero_le _) _ px)
rw [this] at px
exact h _ px
| H₂ S _ =>
rcases not_forall₂.1 (mt (H₂ S).2 <| (lt_succ S).not_le) with ⟨a, h₁, h₂⟩
exact (H.le_iff.2 <| succ_le_of_lt <| not_le.1 h₂).trans (h _ h₁)
| H₃ S L _ =>
refine (H.2 _ L _).2 fun a h' => ?_
rcases not_forall₂.1 (mt (H₂ a).2 h'.not_le) with ⟨b, h₁, h₂⟩
exact (H.le_iff.2 <| (not_le.1 h₂).le).trans (h _ h₁)⟩
#align ordinal.is_normal.le_set Ordinal.IsNormal.le_set
theorem IsNormal.le_set' {f o} (H : IsNormal f) (p : Set α) (p0 : p.Nonempty) (g : α → Ordinal) (b)
(H₂ : ∀ o, b ≤ o ↔ ∀ a ∈ p, g a ≤ o) : f b ≤ o ↔ ∀ a ∈ p, f (g a) ≤ o := by
simpa [H₂] using H.le_set (g '' p) (p0.image g) b
#align ordinal.is_normal.le_set' Ordinal.IsNormal.le_set'
theorem IsNormal.refl : IsNormal id :=
⟨lt_succ, fun _o l _a => Ordinal.limit_le l⟩
#align ordinal.is_normal.refl Ordinal.IsNormal.refl
theorem IsNormal.trans {f g} (H₁ : IsNormal f) (H₂ : IsNormal g) : IsNormal (f ∘ g) :=
⟨fun _x => H₁.lt_iff.2 (H₂.1 _), fun o l _a =>
H₁.le_set' (· < o) ⟨0, l.pos⟩ g _ fun _c => H₂.2 _ l _⟩
#align ordinal.is_normal.trans Ordinal.IsNormal.trans
theorem IsNormal.isLimit {f} (H : IsNormal f) {o} (l : IsLimit o) : IsLimit (f o) :=
⟨ne_of_gt <| (Ordinal.zero_le _).trans_lt <| H.lt_iff.2 l.pos, fun _ h =>
let ⟨_b, h₁, h₂⟩ := (H.limit_lt l).1 h
(succ_le_of_lt h₂).trans_lt (H.lt_iff.2 h₁)⟩
#align ordinal.is_normal.is_limit Ordinal.IsNormal.isLimit
theorem IsNormal.le_iff_eq {f} (H : IsNormal f) {a} : f a ≤ a ↔ f a = a :=
(H.self_le a).le_iff_eq
#align ordinal.is_normal.le_iff_eq Ordinal.IsNormal.le_iff_eq
theorem add_le_of_limit {a b c : Ordinal} (h : IsLimit b) : a + b ≤ c ↔ ∀ b' < b, a + b' ≤ c :=
⟨fun h b' l => (add_le_add_left l.le _).trans h, fun H =>
le_of_not_lt <| by
-- Porting note: `induction` tactics are required because of the parser bug.
induction a using inductionOn with
| H α r =>
induction b using inductionOn with
| H β s =>
intro l
suffices ∀ x : β, Sum.Lex r s (Sum.inr x) (enum _ _ l) by
-- Porting note: `revert` & `intro` is required because `cases'` doesn't replace
-- `enum _ _ l` in `this`.
revert this; cases' enum _ _ l with x x <;> intro this
· cases this (enum s 0 h.pos)
· exact irrefl _ (this _)
intro x
rw [← typein_lt_typein (Sum.Lex r s), typein_enum]
have := H _ (h.2 _ (typein_lt_type s x))
rw [add_succ, succ_le_iff] at this
refine
(RelEmbedding.ofMonotone (fun a => ?_) fun a b => ?_).ordinal_type_le.trans_lt this
· rcases a with ⟨a | b, h⟩
· exact Sum.inl a
· exact Sum.inr ⟨b, by cases h; assumption⟩
· rcases a with ⟨a | a, h₁⟩ <;> rcases b with ⟨b | b, h₂⟩ <;> cases h₁ <;> cases h₂ <;>
rintro ⟨⟩ <;> constructor <;> assumption⟩
#align ordinal.add_le_of_limit Ordinal.add_le_of_limit
theorem add_isNormal (a : Ordinal) : IsNormal (a + ·) :=
⟨fun b => (add_lt_add_iff_left a).2 (lt_succ b), fun _b l _c => add_le_of_limit l⟩
#align ordinal.add_is_normal Ordinal.add_isNormal
theorem add_isLimit (a) {b} : IsLimit b → IsLimit (a + b) :=
(add_isNormal a).isLimit
#align ordinal.add_is_limit Ordinal.add_isLimit
alias IsLimit.add := add_isLimit
#align ordinal.is_limit.add Ordinal.IsLimit.add
/-! ### Subtraction on ordinals-/
/-- The set in the definition of subtraction is nonempty. -/
theorem sub_nonempty {a b : Ordinal} : { o | a ≤ b + o }.Nonempty :=
⟨a, le_add_left _ _⟩
#align ordinal.sub_nonempty Ordinal.sub_nonempty
/-- `a - b` is the unique ordinal satisfying `b + (a - b) = a` when `b ≤ a`. -/
instance sub : Sub Ordinal :=
⟨fun a b => sInf { o | a ≤ b + o }⟩
theorem le_add_sub (a b : Ordinal) : a ≤ b + (a - b) :=
csInf_mem sub_nonempty
#align ordinal.le_add_sub Ordinal.le_add_sub
theorem sub_le {a b c : Ordinal} : a - b ≤ c ↔ a ≤ b + c :=
⟨fun h => (le_add_sub a b).trans (add_le_add_left h _), fun h => csInf_le' h⟩
#align ordinal.sub_le Ordinal.sub_le
theorem lt_sub {a b c : Ordinal} : a < b - c ↔ c + a < b :=
lt_iff_lt_of_le_iff_le sub_le
#align ordinal.lt_sub Ordinal.lt_sub
theorem add_sub_cancel (a b : Ordinal) : a + b - a = b :=
le_antisymm (sub_le.2 <| le_rfl) ((add_le_add_iff_left a).1 <| le_add_sub _ _)
#align ordinal.add_sub_cancel Ordinal.add_sub_cancel
theorem sub_eq_of_add_eq {a b c : Ordinal} (h : a + b = c) : c - a = b :=
h ▸ add_sub_cancel _ _
#align ordinal.sub_eq_of_add_eq Ordinal.sub_eq_of_add_eq
theorem sub_le_self (a b : Ordinal) : a - b ≤ a :=
sub_le.2 <| le_add_left _ _
#align ordinal.sub_le_self Ordinal.sub_le_self
protected theorem add_sub_cancel_of_le {a b : Ordinal} (h : b ≤ a) : b + (a - b) = a :=
(le_add_sub a b).antisymm'
(by
rcases zero_or_succ_or_limit (a - b) with (e | ⟨c, e⟩ | l)
· simp only [e, add_zero, h]
· rw [e, add_succ, succ_le_iff, ← lt_sub, e]
exact lt_succ c
· exact (add_le_of_limit l).2 fun c l => (lt_sub.1 l).le)
#align ordinal.add_sub_cancel_of_le Ordinal.add_sub_cancel_of_le
theorem le_sub_of_le {a b c : Ordinal} (h : b ≤ a) : c ≤ a - b ↔ b + c ≤ a := by
rw [← add_le_add_iff_left b, Ordinal.add_sub_cancel_of_le h]
#align ordinal.le_sub_of_le Ordinal.le_sub_of_le
theorem sub_lt_of_le {a b c : Ordinal} (h : b ≤ a) : a - b < c ↔ a < b + c :=
lt_iff_lt_of_le_iff_le (le_sub_of_le h)
#align ordinal.sub_lt_of_le Ordinal.sub_lt_of_le
instance existsAddOfLE : ExistsAddOfLE Ordinal :=
⟨fun h => ⟨_, (Ordinal.add_sub_cancel_of_le h).symm⟩⟩
@[simp]
theorem sub_zero (a : Ordinal) : a - 0 = a := by simpa only [zero_add] using add_sub_cancel 0 a
#align ordinal.sub_zero Ordinal.sub_zero
@[simp]
theorem zero_sub (a : Ordinal) : 0 - a = 0 := by rw [← Ordinal.le_zero]; apply sub_le_self
#align ordinal.zero_sub Ordinal.zero_sub
@[simp]
theorem sub_self (a : Ordinal) : a - a = 0 := by simpa only [add_zero] using add_sub_cancel a 0
#align ordinal.sub_self Ordinal.sub_self
protected theorem sub_eq_zero_iff_le {a b : Ordinal} : a - b = 0 ↔ a ≤ b :=
⟨fun h => by simpa only [h, add_zero] using le_add_sub a b, fun h => by
rwa [← Ordinal.le_zero, sub_le, add_zero]⟩
#align ordinal.sub_eq_zero_iff_le Ordinal.sub_eq_zero_iff_le
theorem sub_sub (a b c : Ordinal) : a - b - c = a - (b + c) :=
eq_of_forall_ge_iff fun d => by rw [sub_le, sub_le, sub_le, add_assoc]
#align ordinal.sub_sub Ordinal.sub_sub
@[simp]
theorem add_sub_add_cancel (a b c : Ordinal) : a + b - (a + c) = b - c := by
rw [← sub_sub, add_sub_cancel]
#align ordinal.add_sub_add_cancel Ordinal.add_sub_add_cancel
theorem sub_isLimit {a b} (l : IsLimit a) (h : b < a) : IsLimit (a - b) :=
⟨ne_of_gt <| lt_sub.2 <| by rwa [add_zero], fun c h => by
rw [lt_sub, add_succ]; exact l.2 _ (lt_sub.1 h)⟩
#align ordinal.sub_is_limit Ordinal.sub_isLimit
-- @[simp] -- Porting note (#10618): simp can prove this
theorem one_add_omega : 1 + ω = ω := by
refine le_antisymm ?_ (le_add_left _ _)
rw [omega, ← lift_one.{_, 0}, ← lift_add, lift_le, ← type_unit, ← type_sum_lex]
refine ⟨RelEmbedding.collapse (RelEmbedding.ofMonotone ?_ ?_)⟩
· apply Sum.rec
· exact fun _ => 0
· exact Nat.succ
· intro a b
cases a <;> cases b <;> intro H <;> cases' H with _ _ H _ _ H <;>
[exact H.elim; exact Nat.succ_pos _; exact Nat.succ_lt_succ H]
#align ordinal.one_add_omega Ordinal.one_add_omega
@[simp]
theorem one_add_of_omega_le {o} (h : ω ≤ o) : 1 + o = o := by
rw [← Ordinal.add_sub_cancel_of_le h, ← add_assoc, one_add_omega]
#align ordinal.one_add_of_omega_le Ordinal.one_add_of_omega_le
/-! ### Multiplication of ordinals-/
/-- The multiplication of ordinals `o₁` and `o₂` is the (well founded) lexicographic order on
`o₂ × o₁`. -/
instance monoid : Monoid Ordinal.{u} where
mul a b :=
Quotient.liftOn₂ a b
(fun ⟨α, r, wo⟩ ⟨β, s, wo'⟩ => ⟦⟨β × α, Prod.Lex s r, inferInstance⟩⟧ :
WellOrder → WellOrder → Ordinal)
fun ⟨α₁, r₁, o₁⟩ ⟨α₂, r₂, o₂⟩ ⟨β₁, s₁, p₁⟩ ⟨β₂, s₂, p₂⟩ ⟨f⟩ ⟨g⟩ =>
Quot.sound ⟨RelIso.prodLexCongr g f⟩
one := 1
mul_assoc a b c :=
Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ =>
Eq.symm <|
Quotient.sound
⟨⟨prodAssoc _ _ _, @fun a b => by
rcases a with ⟨⟨a₁, a₂⟩, a₃⟩
rcases b with ⟨⟨b₁, b₂⟩, b₃⟩
simp [Prod.lex_def, and_or_left, or_assoc, and_assoc]⟩⟩
mul_one a :=
inductionOn a fun α r _ =>
Quotient.sound
⟨⟨punitProd _, @fun a b => by
rcases a with ⟨⟨⟨⟩⟩, a⟩; rcases b with ⟨⟨⟨⟩⟩, b⟩
simp only [Prod.lex_def, EmptyRelation, false_or_iff]
simp only [eq_self_iff_true, true_and_iff]
rfl⟩⟩
one_mul a :=
inductionOn a fun α r _ =>
Quotient.sound
⟨⟨prodPUnit _, @fun a b => by
rcases a with ⟨a, ⟨⟨⟩⟩⟩; rcases b with ⟨b, ⟨⟨⟩⟩⟩
simp only [Prod.lex_def, EmptyRelation, and_false_iff, or_false_iff]
rfl⟩⟩
@[simp]
theorem type_prod_lex {α β : Type u} (r : α → α → Prop) (s : β → β → Prop) [IsWellOrder α r]
[IsWellOrder β s] : type (Prod.Lex s r) = type r * type s :=
rfl
#align ordinal.type_prod_lex Ordinal.type_prod_lex
private theorem mul_eq_zero' {a b : Ordinal} : a * b = 0 ↔ a = 0 ∨ b = 0 :=
inductionOn a fun α _ _ =>
inductionOn b fun β _ _ => by
simp_rw [← type_prod_lex, type_eq_zero_iff_isEmpty]
rw [or_comm]
exact isEmpty_prod
instance monoidWithZero : MonoidWithZero Ordinal :=
{ Ordinal.monoid with
zero := 0
mul_zero := fun _a => mul_eq_zero'.2 <| Or.inr rfl
zero_mul := fun _a => mul_eq_zero'.2 <| Or.inl rfl }
instance noZeroDivisors : NoZeroDivisors Ordinal :=
⟨fun {_ _} => mul_eq_zero'.1⟩
@[simp]
theorem lift_mul (a b : Ordinal.{v}) : lift.{u} (a * b) = lift.{u} a * lift.{u} b :=
Quotient.inductionOn₂ a b fun ⟨_α, _r, _⟩ ⟨_β, _s, _⟩ =>
Quotient.sound
⟨(RelIso.preimage Equiv.ulift _).trans
(RelIso.prodLexCongr (RelIso.preimage Equiv.ulift _)
(RelIso.preimage Equiv.ulift _)).symm⟩
#align ordinal.lift_mul Ordinal.lift_mul
@[simp]
theorem card_mul (a b) : card (a * b) = card a * card b :=
Quotient.inductionOn₂ a b fun ⟨α, _r, _⟩ ⟨β, _s, _⟩ => mul_comm #β #α
#align ordinal.card_mul Ordinal.card_mul
instance leftDistribClass : LeftDistribClass Ordinal.{u} :=
⟨fun a b c =>
Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ =>
Quotient.sound
⟨⟨sumProdDistrib _ _ _, by
rintro ⟨a₁ | a₁, a₂⟩ ⟨b₁ | b₁, b₂⟩ <;>
simp only [Prod.lex_def, Sum.lex_inl_inl, Sum.Lex.sep, Sum.lex_inr_inl,
Sum.lex_inr_inr, sumProdDistrib_apply_left, sumProdDistrib_apply_right] <;>
-- Porting note: `Sum.inr.inj_iff` is required.
simp only [Sum.inl.inj_iff, Sum.inr.inj_iff,
true_or_iff, false_and_iff, false_or_iff]⟩⟩⟩
theorem mul_succ (a b : Ordinal) : a * succ b = a * b + a :=
mul_add_one a b
#align ordinal.mul_succ Ordinal.mul_succ
instance mul_covariantClass_le : CovariantClass Ordinal.{u} Ordinal.{u} (· * ·) (· ≤ ·) :=
⟨fun c a b =>
Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ ⟨f⟩ => by
refine
(RelEmbedding.ofMonotone (fun a : α × γ => (f a.1, a.2)) fun a b h => ?_).ordinal_type_le
cases' h with a₁ b₁ a₂ b₂ h' a b₁ b₂ h'
· exact Prod.Lex.left _ _ (f.toRelEmbedding.map_rel_iff.2 h')
· exact Prod.Lex.right _ h'⟩
#align ordinal.mul_covariant_class_le Ordinal.mul_covariantClass_le
instance mul_swap_covariantClass_le :
CovariantClass Ordinal.{u} Ordinal.{u} (swap (· * ·)) (· ≤ ·) :=
⟨fun c a b =>
Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ ⟨f⟩ => by
refine
(RelEmbedding.ofMonotone (fun a : γ × α => (a.1, f a.2)) fun a b h => ?_).ordinal_type_le
cases' h with a₁ b₁ a₂ b₂ h' a b₁ b₂ h'
· exact Prod.Lex.left _ _ h'
· exact Prod.Lex.right _ (f.toRelEmbedding.map_rel_iff.2 h')⟩
#align ordinal.mul_swap_covariant_class_le Ordinal.mul_swap_covariantClass_le
theorem le_mul_left (a : Ordinal) {b : Ordinal} (hb : 0 < b) : a ≤ a * b := by
convert mul_le_mul_left' (one_le_iff_pos.2 hb) a
rw [mul_one a]
#align ordinal.le_mul_left Ordinal.le_mul_left
theorem le_mul_right (a : Ordinal) {b : Ordinal} (hb : 0 < b) : a ≤ b * a := by
convert mul_le_mul_right' (one_le_iff_pos.2 hb) a
rw [one_mul a]
#align ordinal.le_mul_right Ordinal.le_mul_right
private theorem mul_le_of_limit_aux {α β r s} [IsWellOrder α r] [IsWellOrder β s] {c}
(h : IsLimit (type s)) (H : ∀ b' < type s, type r * b' ≤ c) (l : c < type r * type s) :
False := by
suffices ∀ a b, Prod.Lex s r (b, a) (enum _ _ l) by
cases' enum _ _ l with b a
exact irrefl _ (this _ _)
intro a b
rw [← typein_lt_typein (Prod.Lex s r), typein_enum]
have := H _ (h.2 _ (typein_lt_type s b))
rw [mul_succ] at this
have := ((add_lt_add_iff_left _).2 (typein_lt_type _ a)).trans_le this
refine (RelEmbedding.ofMonotone (fun a => ?_) fun a b => ?_).ordinal_type_le.trans_lt this
· rcases a with ⟨⟨b', a'⟩, h⟩
by_cases e : b = b'
· refine Sum.inr ⟨a', ?_⟩
subst e
cases' h with _ _ _ _ h _ _ _ h
· exact (irrefl _ h).elim
· exact h
· refine Sum.inl (⟨b', ?_⟩, a')
cases' h with _ _ _ _ h _ _ _ h
· exact h
· exact (e rfl).elim
· rcases a with ⟨⟨b₁, a₁⟩, h₁⟩
rcases b with ⟨⟨b₂, a₂⟩, h₂⟩
intro h
by_cases e₁ : b = b₁ <;> by_cases e₂ : b = b₂
· substs b₁ b₂
simpa only [subrel_val, Prod.lex_def, @irrefl _ s _ b, true_and_iff, false_or_iff,
eq_self_iff_true, dif_pos, Sum.lex_inr_inr] using h
· subst b₁
simp only [subrel_val, Prod.lex_def, e₂, Prod.lex_def, dif_pos, subrel_val, eq_self_iff_true,
or_false_iff, dif_neg, not_false_iff, Sum.lex_inr_inl, false_and_iff] at h ⊢
cases' h₂ with _ _ _ _ h₂_h h₂_h <;> [exact asymm h h₂_h; exact e₂ rfl]
-- Porting note: `cc` hadn't ported yet.
· simp [e₂, dif_neg e₁, show b₂ ≠ b₁ from e₂ ▸ e₁]
· simpa only [dif_neg e₁, dif_neg e₂, Prod.lex_def, subrel_val, Subtype.mk_eq_mk,
Sum.lex_inl_inl] using h
theorem mul_le_of_limit {a b c : Ordinal} (h : IsLimit b) : a * b ≤ c ↔ ∀ b' < b, a * b' ≤ c :=
⟨fun h b' l => (mul_le_mul_left' l.le _).trans h, fun H =>
-- Porting note: `induction` tactics are required because of the parser bug.
le_of_not_lt <| by
induction a using inductionOn with
| H α r =>
induction b using inductionOn with
| H β s =>
exact mul_le_of_limit_aux h H⟩
#align ordinal.mul_le_of_limit Ordinal.mul_le_of_limit
theorem mul_isNormal {a : Ordinal} (h : 0 < a) : IsNormal (a * ·) :=
-- Porting note(#12129): additional beta reduction needed
⟨fun b => by
beta_reduce
rw [mul_succ]
simpa only [add_zero] using (add_lt_add_iff_left (a * b)).2 h,
fun b l c => mul_le_of_limit l⟩
#align ordinal.mul_is_normal Ordinal.mul_isNormal
theorem lt_mul_of_limit {a b c : Ordinal} (h : IsLimit c) : a < b * c ↔ ∃ c' < c, a < b * c' := by
-- Porting note: `bex_def` is required.
simpa only [not_forall₂, not_le, bex_def] using not_congr (@mul_le_of_limit b c a h)
#align ordinal.lt_mul_of_limit Ordinal.lt_mul_of_limit
theorem mul_lt_mul_iff_left {a b c : Ordinal} (a0 : 0 < a) : a * b < a * c ↔ b < c :=
(mul_isNormal a0).lt_iff
#align ordinal.mul_lt_mul_iff_left Ordinal.mul_lt_mul_iff_left
theorem mul_le_mul_iff_left {a b c : Ordinal} (a0 : 0 < a) : a * b ≤ a * c ↔ b ≤ c :=
(mul_isNormal a0).le_iff
#align ordinal.mul_le_mul_iff_left Ordinal.mul_le_mul_iff_left
theorem mul_lt_mul_of_pos_left {a b c : Ordinal} (h : a < b) (c0 : 0 < c) : c * a < c * b :=
(mul_lt_mul_iff_left c0).2 h
#align ordinal.mul_lt_mul_of_pos_left Ordinal.mul_lt_mul_of_pos_left
theorem mul_pos {a b : Ordinal} (h₁ : 0 < a) (h₂ : 0 < b) : 0 < a * b := by
simpa only [mul_zero] using mul_lt_mul_of_pos_left h₂ h₁
#align ordinal.mul_pos Ordinal.mul_pos
theorem mul_ne_zero {a b : Ordinal} : a ≠ 0 → b ≠ 0 → a * b ≠ 0 := by
simpa only [Ordinal.pos_iff_ne_zero] using mul_pos
#align ordinal.mul_ne_zero Ordinal.mul_ne_zero
theorem le_of_mul_le_mul_left {a b c : Ordinal} (h : c * a ≤ c * b) (h0 : 0 < c) : a ≤ b :=
le_imp_le_of_lt_imp_lt (fun h' => mul_lt_mul_of_pos_left h' h0) h
#align ordinal.le_of_mul_le_mul_left Ordinal.le_of_mul_le_mul_left
theorem mul_right_inj {a b c : Ordinal} (a0 : 0 < a) : a * b = a * c ↔ b = c :=
(mul_isNormal a0).inj
#align ordinal.mul_right_inj Ordinal.mul_right_inj
theorem mul_isLimit {a b : Ordinal} (a0 : 0 < a) : IsLimit b → IsLimit (a * b) :=
(mul_isNormal a0).isLimit
#align ordinal.mul_is_limit Ordinal.mul_isLimit
theorem mul_isLimit_left {a b : Ordinal} (l : IsLimit a) (b0 : 0 < b) : IsLimit (a * b) := by
rcases zero_or_succ_or_limit b with (rfl | ⟨b, rfl⟩ | lb)
· exact b0.false.elim
· rw [mul_succ]
exact add_isLimit _ l
· exact mul_isLimit l.pos lb
#align ordinal.mul_is_limit_left Ordinal.mul_isLimit_left
theorem smul_eq_mul : ∀ (n : ℕ) (a : Ordinal), n • a = a * n
| 0, a => by rw [zero_nsmul, Nat.cast_zero, mul_zero]
| n + 1, a => by rw [succ_nsmul, Nat.cast_add, mul_add, Nat.cast_one, mul_one, smul_eq_mul n]
#align ordinal.smul_eq_mul Ordinal.smul_eq_mul
/-! ### Division on ordinals -/
/-- The set in the definition of division is nonempty. -/
theorem div_nonempty {a b : Ordinal} (h : b ≠ 0) : { o | a < b * succ o }.Nonempty :=
⟨a, (succ_le_iff (a := a) (b := b * succ a)).1 <| by
simpa only [succ_zero, one_mul] using
mul_le_mul_right' (succ_le_of_lt (Ordinal.pos_iff_ne_zero.2 h)) (succ a)⟩
#align ordinal.div_nonempty Ordinal.div_nonempty
/-- `a / b` is the unique ordinal `o` satisfying `a = b * o + o'` with `o' < b`. -/
instance div : Div Ordinal :=
⟨fun a b => if _h : b = 0 then 0 else sInf { o | a < b * succ o }⟩
@[simp]
theorem div_zero (a : Ordinal) : a / 0 = 0 :=
dif_pos rfl
#align ordinal.div_zero Ordinal.div_zero
theorem div_def (a) {b : Ordinal} (h : b ≠ 0) : a / b = sInf { o | a < b * succ o } :=
dif_neg h
#align ordinal.div_def Ordinal.div_def
theorem lt_mul_succ_div (a) {b : Ordinal} (h : b ≠ 0) : a < b * succ (a / b) := by
rw [div_def a h]; exact csInf_mem (div_nonempty h)
#align ordinal.lt_mul_succ_div Ordinal.lt_mul_succ_div
theorem lt_mul_div_add (a) {b : Ordinal} (h : b ≠ 0) : a < b * (a / b) + b := by
simpa only [mul_succ] using lt_mul_succ_div a h
#align ordinal.lt_mul_div_add Ordinal.lt_mul_div_add
theorem div_le {a b c : Ordinal} (b0 : b ≠ 0) : a / b ≤ c ↔ a < b * succ c :=
⟨fun h => (lt_mul_succ_div a b0).trans_le (mul_le_mul_left' (succ_le_succ_iff.2 h) _), fun h => by
rw [div_def a b0]; exact csInf_le' h⟩
#align ordinal.div_le Ordinal.div_le
theorem lt_div {a b c : Ordinal} (h : c ≠ 0) : a < b / c ↔ c * succ a ≤ b := by
rw [← not_le, div_le h, not_lt]
#align ordinal.lt_div Ordinal.lt_div
theorem div_pos {b c : Ordinal} (h : c ≠ 0) : 0 < b / c ↔ c ≤ b := by simp [lt_div h]
#align ordinal.div_pos Ordinal.div_pos
theorem le_div {a b c : Ordinal} (c0 : c ≠ 0) : a ≤ b / c ↔ c * a ≤ b := by
induction a using limitRecOn with
| H₁ => simp only [mul_zero, Ordinal.zero_le]
| H₂ _ _ => rw [succ_le_iff, lt_div c0]
| H₃ _ h₁ h₂ =>
revert h₁ h₂
simp (config := { contextual := true }) only [mul_le_of_limit, limit_le, iff_self_iff,
forall_true_iff]
#align ordinal.le_div Ordinal.le_div
theorem div_lt {a b c : Ordinal} (b0 : b ≠ 0) : a / b < c ↔ a < b * c :=
lt_iff_lt_of_le_iff_le <| le_div b0
#align ordinal.div_lt Ordinal.div_lt
theorem div_le_of_le_mul {a b c : Ordinal} (h : a ≤ b * c) : a / b ≤ c :=
if b0 : b = 0 then by simp only [b0, div_zero, Ordinal.zero_le]
else
(div_le b0).2 <| h.trans_lt <| mul_lt_mul_of_pos_left (lt_succ c) (Ordinal.pos_iff_ne_zero.2 b0)
#align ordinal.div_le_of_le_mul Ordinal.div_le_of_le_mul
theorem mul_lt_of_lt_div {a b c : Ordinal} : a < b / c → c * a < b :=
lt_imp_lt_of_le_imp_le div_le_of_le_mul
#align ordinal.mul_lt_of_lt_div Ordinal.mul_lt_of_lt_div
@[simp]
theorem zero_div (a : Ordinal) : 0 / a = 0 :=
Ordinal.le_zero.1 <| div_le_of_le_mul <| Ordinal.zero_le _
#align ordinal.zero_div Ordinal.zero_div
theorem mul_div_le (a b : Ordinal) : b * (a / b) ≤ a :=
if b0 : b = 0 then by simp only [b0, zero_mul, Ordinal.zero_le] else (le_div b0).1 le_rfl
#align ordinal.mul_div_le Ordinal.mul_div_le
theorem mul_add_div (a) {b : Ordinal} (b0 : b ≠ 0) (c) : (b * a + c) / b = a + c / b := by
apply le_antisymm
· apply (div_le b0).2
rw [mul_succ, mul_add, add_assoc, add_lt_add_iff_left]
apply lt_mul_div_add _ b0
· rw [le_div b0, mul_add, add_le_add_iff_left]
apply mul_div_le
#align ordinal.mul_add_div Ordinal.mul_add_div
theorem div_eq_zero_of_lt {a b : Ordinal} (h : a < b) : a / b = 0 := by
rw [← Ordinal.le_zero, div_le <| Ordinal.pos_iff_ne_zero.1 <| (Ordinal.zero_le _).trans_lt h]
simpa only [succ_zero, mul_one] using h
#align ordinal.div_eq_zero_of_lt Ordinal.div_eq_zero_of_lt
@[simp]
theorem mul_div_cancel (a) {b : Ordinal} (b0 : b ≠ 0) : b * a / b = a := by
simpa only [add_zero, zero_div] using mul_add_div a b0 0
#align ordinal.mul_div_cancel Ordinal.mul_div_cancel
@[simp]
theorem div_one (a : Ordinal) : a / 1 = a := by
simpa only [one_mul] using mul_div_cancel a Ordinal.one_ne_zero
#align ordinal.div_one Ordinal.div_one
@[simp]
theorem div_self {a : Ordinal} (h : a ≠ 0) : a / a = 1 := by
simpa only [mul_one] using mul_div_cancel 1 h
#align ordinal.div_self Ordinal.div_self
theorem mul_sub (a b c : Ordinal) : a * (b - c) = a * b - a * c :=
if a0 : a = 0 then by simp only [a0, zero_mul, sub_self]
else
eq_of_forall_ge_iff fun d => by rw [sub_le, ← le_div a0, sub_le, ← le_div a0, mul_add_div _ a0]
#align ordinal.mul_sub Ordinal.mul_sub
theorem isLimit_add_iff {a b} : IsLimit (a + b) ↔ IsLimit b ∨ b = 0 ∧ IsLimit a := by
constructor <;> intro h
· by_cases h' : b = 0
· rw [h', add_zero] at h
right
exact ⟨h', h⟩
left
rw [← add_sub_cancel a b]
apply sub_isLimit h
suffices a + 0 < a + b by simpa only [add_zero] using this
rwa [add_lt_add_iff_left, Ordinal.pos_iff_ne_zero]
rcases h with (h | ⟨rfl, h⟩)
· exact add_isLimit a h
· simpa only [add_zero]
#align ordinal.is_limit_add_iff Ordinal.isLimit_add_iff
theorem dvd_add_iff : ∀ {a b c : Ordinal}, a ∣ b → (a ∣ b + c ↔ a ∣ c)
| a, _, c, ⟨b, rfl⟩ =>
⟨fun ⟨d, e⟩ => ⟨d - b, by rw [mul_sub, ← e, add_sub_cancel]⟩, fun ⟨d, e⟩ => by
rw [e, ← mul_add]
apply dvd_mul_right⟩
#align ordinal.dvd_add_iff Ordinal.dvd_add_iff
theorem div_mul_cancel : ∀ {a b : Ordinal}, a ≠ 0 → a ∣ b → a * (b / a) = b
| a, _, a0, ⟨b, rfl⟩ => by rw [mul_div_cancel _ a0]
#align ordinal.div_mul_cancel Ordinal.div_mul_cancel
theorem le_of_dvd : ∀ {a b : Ordinal}, b ≠ 0 → a ∣ b → a ≤ b
-- Porting note: `⟨b, rfl⟩ => by` → `⟨b, e⟩ => by subst e`
| a, _, b0, ⟨b, e⟩ => by
subst e
-- Porting note: `Ne` is required.
simpa only [mul_one] using
mul_le_mul_left'
(one_le_iff_ne_zero.2 fun h : b = 0 => by
simp only [h, mul_zero, Ne, not_true_eq_false] at b0) a
#align ordinal.le_of_dvd Ordinal.le_of_dvd
theorem dvd_antisymm {a b : Ordinal} (h₁ : a ∣ b) (h₂ : b ∣ a) : a = b :=
if a0 : a = 0 then by subst a; exact (eq_zero_of_zero_dvd h₁).symm
else
if b0 : b = 0 then by subst b; exact eq_zero_of_zero_dvd h₂
else (le_of_dvd b0 h₁).antisymm (le_of_dvd a0 h₂)
#align ordinal.dvd_antisymm Ordinal.dvd_antisymm
instance isAntisymm : IsAntisymm Ordinal (· ∣ ·) :=
⟨@dvd_antisymm⟩
/-- `a % b` is the unique ordinal `o'` satisfying
`a = b * o + o'` with `o' < b`. -/
instance mod : Mod Ordinal :=
⟨fun a b => a - b * (a / b)⟩
theorem mod_def (a b : Ordinal) : a % b = a - b * (a / b) :=
rfl
#align ordinal.mod_def Ordinal.mod_def
theorem mod_le (a b : Ordinal) : a % b ≤ a :=
sub_le_self a _
#align ordinal.mod_le Ordinal.mod_le
@[simp]
theorem mod_zero (a : Ordinal) : a % 0 = a := by simp only [mod_def, div_zero, zero_mul, sub_zero]
#align ordinal.mod_zero Ordinal.mod_zero
theorem mod_eq_of_lt {a b : Ordinal} (h : a < b) : a % b = a := by
simp only [mod_def, div_eq_zero_of_lt h, mul_zero, sub_zero]
#align ordinal.mod_eq_of_lt Ordinal.mod_eq_of_lt
@[simp]
theorem zero_mod (b : Ordinal) : 0 % b = 0 := by simp only [mod_def, zero_div, mul_zero, sub_self]
#align ordinal.zero_mod Ordinal.zero_mod
theorem div_add_mod (a b : Ordinal) : b * (a / b) + a % b = a :=
Ordinal.add_sub_cancel_of_le <| mul_div_le _ _
#align ordinal.div_add_mod Ordinal.div_add_mod
theorem mod_lt (a) {b : Ordinal} (h : b ≠ 0) : a % b < b :=
(add_lt_add_iff_left (b * (a / b))).1 <| by rw [div_add_mod]; exact lt_mul_div_add a h
#align ordinal.mod_lt Ordinal.mod_lt
@[simp]
theorem mod_self (a : Ordinal) : a % a = 0 :=
if a0 : a = 0 then by simp only [a0, zero_mod]
else by simp only [mod_def, div_self a0, mul_one, sub_self]
#align ordinal.mod_self Ordinal.mod_self
@[simp]
theorem mod_one (a : Ordinal) : a % 1 = 0 := by simp only [mod_def, div_one, one_mul, sub_self]
#align ordinal.mod_one Ordinal.mod_one
theorem dvd_of_mod_eq_zero {a b : Ordinal} (H : a % b = 0) : b ∣ a :=
⟨a / b, by simpa [H] using (div_add_mod a b).symm⟩
#align ordinal.dvd_of_mod_eq_zero Ordinal.dvd_of_mod_eq_zero
theorem mod_eq_zero_of_dvd {a b : Ordinal} (H : b ∣ a) : a % b = 0 := by
rcases H with ⟨c, rfl⟩
rcases eq_or_ne b 0 with (rfl | hb)
· simp
· simp [mod_def, hb]
#align ordinal.mod_eq_zero_of_dvd Ordinal.mod_eq_zero_of_dvd
theorem dvd_iff_mod_eq_zero {a b : Ordinal} : b ∣ a ↔ a % b = 0 :=
⟨mod_eq_zero_of_dvd, dvd_of_mod_eq_zero⟩
#align ordinal.dvd_iff_mod_eq_zero Ordinal.dvd_iff_mod_eq_zero
@[simp]
theorem mul_add_mod_self (x y z : Ordinal) : (x * y + z) % x = z % x := by
rcases eq_or_ne x 0 with rfl | hx
· simp
· rwa [mod_def, mul_add_div, mul_add, ← sub_sub, add_sub_cancel, mod_def]
#align ordinal.mul_add_mod_self Ordinal.mul_add_mod_self
@[simp]
theorem mul_mod (x y : Ordinal) : x * y % x = 0 := by
simpa using mul_add_mod_self x y 0
#align ordinal.mul_mod Ordinal.mul_mod
theorem mod_mod_of_dvd (a : Ordinal) {b c : Ordinal} (h : c ∣ b) : a % b % c = a % c := by
nth_rw 2 [← div_add_mod a b]
rcases h with ⟨d, rfl⟩
rw [mul_assoc, mul_add_mod_self]
#align ordinal.mod_mod_of_dvd Ordinal.mod_mod_of_dvd
@[simp]
theorem mod_mod (a b : Ordinal) : a % b % b = a % b :=
mod_mod_of_dvd a dvd_rfl
#align ordinal.mod_mod Ordinal.mod_mod
/-! ### Families of ordinals
There are two kinds of indexed families that naturally arise when dealing with ordinals: those
indexed by some type in the appropriate universe, and those indexed by ordinals less than another.
The following API allows one to convert from one kind of family to the other.
In many cases, this makes it easy to prove claims about one kind of family via the corresponding
claim on the other. -/
/-- Converts a family indexed by a `Type u` to one indexed by an `Ordinal.{u}` using a specified
well-ordering. -/
def bfamilyOfFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → α) :
∀ a < type r, α := fun a ha => f (enum r a ha)
#align ordinal.bfamily_of_family' Ordinal.bfamilyOfFamily'
/-- Converts a family indexed by a `Type u` to one indexed by an `Ordinal.{u}` using a well-ordering
given by the axiom of choice. -/
def bfamilyOfFamily {ι : Type u} : (ι → α) → ∀ a < type (@WellOrderingRel ι), α :=
bfamilyOfFamily' WellOrderingRel
#align ordinal.bfamily_of_family Ordinal.bfamilyOfFamily
/-- Converts a family indexed by an `Ordinal.{u}` to one indexed by a `Type u` using a specified
well-ordering. -/
def familyOfBFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o} (ho : type r = o)
(f : ∀ a < o, α) : ι → α := fun i =>
f (typein r i)
(by
rw [← ho]
exact typein_lt_type r i)
#align ordinal.family_of_bfamily' Ordinal.familyOfBFamily'
/-- Converts a family indexed by an `Ordinal.{u}` to one indexed by a `Type u` using a well-ordering
given by the axiom of choice. -/
def familyOfBFamily (o : Ordinal) (f : ∀ a < o, α) : o.out.α → α :=
familyOfBFamily' (· < ·) (type_lt o) f
#align ordinal.family_of_bfamily Ordinal.familyOfBFamily
@[simp]
theorem bfamilyOfFamily'_typein {ι} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → α) (i) :
bfamilyOfFamily' r f (typein r i) (typein_lt_type r i) = f i := by
simp only [bfamilyOfFamily', enum_typein]
#align ordinal.bfamily_of_family'_typein Ordinal.bfamilyOfFamily'_typein
@[simp]
theorem bfamilyOfFamily_typein {ι} (f : ι → α) (i) :
bfamilyOfFamily f (typein _ i) (typein_lt_type _ i) = f i :=
bfamilyOfFamily'_typein _ f i
#align ordinal.bfamily_of_family_typein Ordinal.bfamilyOfFamily_typein
@[simp, nolint simpNF] -- Porting note (#10959): simp cannot prove this
theorem familyOfBFamily'_enum {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o}
(ho : type r = o) (f : ∀ a < o, α) (i hi) :
familyOfBFamily' r ho f (enum r i (by rwa [ho])) = f i hi := by
simp only [familyOfBFamily', typein_enum]
#align ordinal.family_of_bfamily'_enum Ordinal.familyOfBFamily'_enum
@[simp, nolint simpNF] -- Porting note (#10959): simp cannot prove this
theorem familyOfBFamily_enum (o : Ordinal) (f : ∀ a < o, α) (i hi) :
familyOfBFamily o f
(enum (· < ·) i
(by
convert hi
exact type_lt _)) =
f i hi :=
familyOfBFamily'_enum _ (type_lt o) f _ _
#align ordinal.family_of_bfamily_enum Ordinal.familyOfBFamily_enum
/-- The range of a family indexed by ordinals. -/
def brange (o : Ordinal) (f : ∀ a < o, α) : Set α :=
{ a | ∃ i hi, f i hi = a }
#align ordinal.brange Ordinal.brange
theorem mem_brange {o : Ordinal} {f : ∀ a < o, α} {a} : a ∈ brange o f ↔ ∃ i hi, f i hi = a :=
Iff.rfl
#align ordinal.mem_brange Ordinal.mem_brange
theorem mem_brange_self {o} (f : ∀ a < o, α) (i hi) : f i hi ∈ brange o f :=
⟨i, hi, rfl⟩
#align ordinal.mem_brange_self Ordinal.mem_brange_self
@[simp]
theorem range_familyOfBFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o}
(ho : type r = o) (f : ∀ a < o, α) : range (familyOfBFamily' r ho f) = brange o f := by
refine Set.ext fun a => ⟨?_, ?_⟩
· rintro ⟨b, rfl⟩
apply mem_brange_self
· rintro ⟨i, hi, rfl⟩
exact ⟨_, familyOfBFamily'_enum _ _ _ _ _⟩
#align ordinal.range_family_of_bfamily' Ordinal.range_familyOfBFamily'
@[simp]
theorem range_familyOfBFamily {o} (f : ∀ a < o, α) : range (familyOfBFamily o f) = brange o f :=
range_familyOfBFamily' _ _ f
#align ordinal.range_family_of_bfamily Ordinal.range_familyOfBFamily
@[simp]
theorem brange_bfamilyOfFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → α) :
brange _ (bfamilyOfFamily' r f) = range f := by
refine Set.ext fun a => ⟨?_, ?_⟩
· rintro ⟨i, hi, rfl⟩
apply mem_range_self
· rintro ⟨b, rfl⟩
exact ⟨_, _, bfamilyOfFamily'_typein _ _ _⟩
#align ordinal.brange_bfamily_of_family' Ordinal.brange_bfamilyOfFamily'
@[simp]
theorem brange_bfamilyOfFamily {ι : Type u} (f : ι → α) : brange _ (bfamilyOfFamily f) = range f :=
brange_bfamilyOfFamily' _ _
#align ordinal.brange_bfamily_of_family Ordinal.brange_bfamilyOfFamily
@[simp]
theorem brange_const {o : Ordinal} (ho : o ≠ 0) {c : α} : (brange o fun _ _ => c) = {c} := by
rw [← range_familyOfBFamily]
exact @Set.range_const _ o.out.α (out_nonempty_iff_ne_zero.2 ho) c
#align ordinal.brange_const Ordinal.brange_const
theorem comp_bfamilyOfFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → α)
(g : α → β) : (fun i hi => g (bfamilyOfFamily' r f i hi)) = bfamilyOfFamily' r (g ∘ f) :=
rfl
#align ordinal.comp_bfamily_of_family' Ordinal.comp_bfamilyOfFamily'
theorem comp_bfamilyOfFamily {ι : Type u} (f : ι → α) (g : α → β) :
(fun i hi => g (bfamilyOfFamily f i hi)) = bfamilyOfFamily (g ∘ f) :=
rfl
#align ordinal.comp_bfamily_of_family Ordinal.comp_bfamilyOfFamily
theorem comp_familyOfBFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o}
(ho : type r = o) (f : ∀ a < o, α) (g : α → β) :
g ∘ familyOfBFamily' r ho f = familyOfBFamily' r ho fun i hi => g (f i hi) :=
rfl
#align ordinal.comp_family_of_bfamily' Ordinal.comp_familyOfBFamily'
theorem comp_familyOfBFamily {o} (f : ∀ a < o, α) (g : α → β) :
g ∘ familyOfBFamily o f = familyOfBFamily o fun i hi => g (f i hi) :=
rfl
#align ordinal.comp_family_of_bfamily Ordinal.comp_familyOfBFamily
/-! ### Supremum of a family of ordinals -/
-- Porting note: Universes should be specified in `sup`s.
/-- The supremum of a family of ordinals -/
def sup {ι : Type u} (f : ι → Ordinal.{max u v}) : Ordinal.{max u v} :=
iSup f
#align ordinal.sup Ordinal.sup
@[simp]
theorem sSup_eq_sup {ι : Type u} (f : ι → Ordinal.{max u v}) : sSup (Set.range f) = sup.{_, v} f :=
rfl
#align ordinal.Sup_eq_sup Ordinal.sSup_eq_sup
/-- The range of an indexed ordinal function, whose outputs live in a higher universe than the
inputs, is always bounded above. See `Ordinal.lsub` for an explicit bound. -/
theorem bddAbove_range {ι : Type u} (f : ι → Ordinal.{max u v}) : BddAbove (Set.range f) :=
⟨(iSup (succ ∘ card ∘ f)).ord, by
rintro a ⟨i, rfl⟩
exact le_of_lt (Cardinal.lt_ord.2 ((lt_succ _).trans_le
(le_ciSup (Cardinal.bddAbove_range.{_, v} _) _)))⟩
#align ordinal.bdd_above_range Ordinal.bddAbove_range
theorem le_sup {ι : Type u} (f : ι → Ordinal.{max u v}) : ∀ i, f i ≤ sup.{_, v} f := fun i =>
le_csSup (bddAbove_range.{_, v} f) (mem_range_self i)
#align ordinal.le_sup Ordinal.le_sup
theorem sup_le_iff {ι : Type u} {f : ι → Ordinal.{max u v}} {a} : sup.{_, v} f ≤ a ↔ ∀ i, f i ≤ a :=
(csSup_le_iff' (bddAbove_range.{_, v} f)).trans (by simp)
#align ordinal.sup_le_iff Ordinal.sup_le_iff
theorem sup_le {ι : Type u} {f : ι → Ordinal.{max u v}} {a} : (∀ i, f i ≤ a) → sup.{_, v} f ≤ a :=
sup_le_iff.2
#align ordinal.sup_le Ordinal.sup_le
theorem lt_sup {ι : Type u} {f : ι → Ordinal.{max u v}} {a} : a < sup.{_, v} f ↔ ∃ i, a < f i := by
simpa only [not_forall, not_le] using not_congr (@sup_le_iff.{_, v} _ f a)
#align ordinal.lt_sup Ordinal.lt_sup
theorem ne_sup_iff_lt_sup {ι : Type u} {f : ι → Ordinal.{max u v}} :
(∀ i, f i ≠ sup.{_, v} f) ↔ ∀ i, f i < sup.{_, v} f :=
⟨fun hf _ => lt_of_le_of_ne (le_sup _ _) (hf _), fun hf _ => ne_of_lt (hf _)⟩
#align ordinal.ne_sup_iff_lt_sup Ordinal.ne_sup_iff_lt_sup
theorem sup_not_succ_of_ne_sup {ι : Type u} {f : ι → Ordinal.{max u v}}
(hf : ∀ i, f i ≠ sup.{_, v} f) {a} (hao : a < sup.{_, v} f) : succ a < sup.{_, v} f := by
by_contra! hoa
exact
hao.not_le (sup_le fun i => le_of_lt_succ <| (lt_of_le_of_ne (le_sup _ _) (hf i)).trans_le hoa)
#align ordinal.sup_not_succ_of_ne_sup Ordinal.sup_not_succ_of_ne_sup
@[simp]
theorem sup_eq_zero_iff {ι : Type u} {f : ι → Ordinal.{max u v}} :
sup.{_, v} f = 0 ↔ ∀ i, f i = 0 := by
refine
⟨fun h i => ?_, fun h =>
le_antisymm (sup_le fun i => Ordinal.le_zero.2 (h i)) (Ordinal.zero_le _)⟩
rw [← Ordinal.le_zero, ← h]
exact le_sup f i
#align ordinal.sup_eq_zero_iff Ordinal.sup_eq_zero_iff
theorem IsNormal.sup {f : Ordinal.{max u v} → Ordinal.{max u w}} (H : IsNormal f) {ι : Type u}
(g : ι → Ordinal.{max u v}) [Nonempty ι] : f (sup.{_, v} g) = sup.{_, w} (f ∘ g) :=
eq_of_forall_ge_iff fun a => by
rw [sup_le_iff]; simp only [comp]; rw [H.le_set' Set.univ Set.univ_nonempty g] <;>
simp [sup_le_iff]
#align ordinal.is_normal.sup Ordinal.IsNormal.sup
@[simp]
theorem sup_empty {ι} [IsEmpty ι] (f : ι → Ordinal) : sup f = 0 :=
ciSup_of_empty f
#align ordinal.sup_empty Ordinal.sup_empty
@[simp]
theorem sup_const {ι} [_hι : Nonempty ι] (o : Ordinal) : (sup fun _ : ι => o) = o :=
ciSup_const
#align ordinal.sup_const Ordinal.sup_const
@[simp]
theorem sup_unique {ι} [Unique ι] (f : ι → Ordinal) : sup f = f default :=
ciSup_unique
#align ordinal.sup_unique Ordinal.sup_unique
theorem sup_le_of_range_subset {ι ι'} {f : ι → Ordinal} {g : ι' → Ordinal}
(h : Set.range f ⊆ Set.range g) : sup.{u, max v w} f ≤ sup.{v, max u w} g :=
sup_le fun i =>
match h (mem_range_self i) with
| ⟨_j, hj⟩ => hj ▸ le_sup _ _
#align ordinal.sup_le_of_range_subset Ordinal.sup_le_of_range_subset
theorem sup_eq_of_range_eq {ι ι'} {f : ι → Ordinal} {g : ι' → Ordinal}
(h : Set.range f = Set.range g) : sup.{u, max v w} f = sup.{v, max u w} g :=
(sup_le_of_range_subset.{u, v, w} h.le).antisymm (sup_le_of_range_subset.{v, u, w} h.ge)
#align ordinal.sup_eq_of_range_eq Ordinal.sup_eq_of_range_eq
@[simp]
| Mathlib/SetTheory/Ordinal/Arithmetic.lean | 1,332 | 1,342 | theorem sup_sum {α : Type u} {β : Type v} (f : Sum α β → Ordinal) :
sup.{max u v, w} f =
max (sup.{u, max v w} fun a => f (Sum.inl a)) (sup.{v, max u w} fun b => f (Sum.inr b)) := by |
apply (sup_le_iff.2 _).antisymm (max_le_iff.2 ⟨_, _⟩)
· rintro (i | i)
· exact le_max_of_le_left (le_sup _ i)
· exact le_max_of_le_right (le_sup _ i)
all_goals
apply sup_le_of_range_subset.{_, max u v, w}
rintro i ⟨a, rfl⟩
apply mem_range_self
|
/-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
-/
import Mathlib.Data.List.OfFn
import Mathlib.Data.List.Nodup
import Mathlib.Data.List.Infix
#align_import data.list.sort from "leanprover-community/mathlib"@"f694c7dead66f5d4c80f446c796a5aad14707f0e"
/-!
# Sorting algorithms on lists
In this file we define `List.Sorted r l` to be an alias for `List.Pairwise r l`.
This alias is preferred in the case that `r` is a `<` or `≤`-like relation.
Then we define two sorting algorithms:
`List.insertionSort` and `List.mergeSort`, and prove their correctness.
-/
open List.Perm
universe u
namespace List
/-!
### The predicate `List.Sorted`
-/
section Sorted
variable {α : Type u} {r : α → α → Prop} {a : α} {l : List α}
/-- `Sorted r l` is the same as `List.Pairwise r l`, preferred in the case that `r`
is a `<` or `≤`-like relation (transitive and antisymmetric or asymmetric) -/
def Sorted :=
@Pairwise
#align list.sorted List.Sorted
instance decidableSorted [DecidableRel r] (l : List α) : Decidable (Sorted r l) :=
List.instDecidablePairwise _
#align list.decidable_sorted List.decidableSorted
protected theorem Sorted.le_of_lt [Preorder α] {l : List α} (h : l.Sorted (· < ·)) :
l.Sorted (· ≤ ·) :=
h.imp le_of_lt
protected theorem Sorted.lt_of_le [PartialOrder α] {l : List α} (h₁ : l.Sorted (· ≤ ·))
(h₂ : l.Nodup) : l.Sorted (· < ·) :=
h₁.imp₂ (fun _ _ => lt_of_le_of_ne) h₂
protected theorem Sorted.ge_of_gt [Preorder α] {l : List α} (h : l.Sorted (· > ·)) :
l.Sorted (· ≥ ·) :=
h.imp le_of_lt
protected theorem Sorted.gt_of_ge [PartialOrder α] {l : List α} (h₁ : l.Sorted (· ≥ ·))
(h₂ : l.Nodup) : l.Sorted (· > ·) :=
h₁.imp₂ (fun _ _ => lt_of_le_of_ne) <| by simp_rw [ne_comm]; exact h₂
@[simp]
theorem sorted_nil : Sorted r [] :=
Pairwise.nil
#align list.sorted_nil List.sorted_nil
theorem Sorted.of_cons : Sorted r (a :: l) → Sorted r l :=
Pairwise.of_cons
#align list.sorted.of_cons List.Sorted.of_cons
theorem Sorted.tail {r : α → α → Prop} {l : List α} (h : Sorted r l) : Sorted r l.tail :=
Pairwise.tail h
#align list.sorted.tail List.Sorted.tail
theorem rel_of_sorted_cons {a : α} {l : List α} : Sorted r (a :: l) → ∀ b ∈ l, r a b :=
rel_of_pairwise_cons
#align list.rel_of_sorted_cons List.rel_of_sorted_cons
theorem Sorted.head!_le [Inhabited α] [Preorder α] {a : α} {l : List α} (h : Sorted (· < ·) l)
(ha : a ∈ l) : l.head! ≤ a := by
rw [← List.cons_head!_tail (List.ne_nil_of_mem ha)] at h ha
cases ha
· exact le_rfl
· exact le_of_lt (rel_of_sorted_cons h a (by assumption))
theorem Sorted.le_head! [Inhabited α] [Preorder α] {a : α} {l : List α} (h : Sorted (· > ·) l)
(ha : a ∈ l) : a ≤ l.head! := by
rw [← List.cons_head!_tail (List.ne_nil_of_mem ha)] at h ha
cases ha
· exact le_rfl
· exact le_of_lt (rel_of_sorted_cons h a (by assumption))
@[simp]
theorem sorted_cons {a : α} {l : List α} : Sorted r (a :: l) ↔ (∀ b ∈ l, r a b) ∧ Sorted r l :=
pairwise_cons
#align list.sorted_cons List.sorted_cons
protected theorem Sorted.nodup {r : α → α → Prop} [IsIrrefl α r] {l : List α} (h : Sorted r l) :
Nodup l :=
Pairwise.nodup h
#align list.sorted.nodup List.Sorted.nodup
theorem eq_of_perm_of_sorted [IsAntisymm α r] {l₁ l₂ : List α} (hp : l₁ ~ l₂) (hs₁ : Sorted r l₁)
(hs₂ : Sorted r l₂) : l₁ = l₂ := by
induction' hs₁ with a l₁ h₁ hs₁ IH generalizing l₂
· exact hp.nil_eq
· have : a ∈ l₂ := hp.subset (mem_cons_self _ _)
rcases append_of_mem this with ⟨u₂, v₂, rfl⟩
have hp' := (perm_cons a).1 (hp.trans perm_middle)
obtain rfl := IH hp' (hs₂.sublist <| by simp)
change a :: u₂ ++ v₂ = u₂ ++ ([a] ++ v₂)
rw [← append_assoc]
congr
have : ∀ x ∈ u₂, x = a := fun x m =>
antisymm ((pairwise_append.1 hs₂).2.2 _ m a (mem_cons_self _ _)) (h₁ _ (by simp [m]))
rw [(@eq_replicate _ a (length u₂ + 1) (a :: u₂)).2,
(@eq_replicate _ a (length u₂ + 1) (u₂ ++ [a])).2] <;>
constructor <;>
simp [iff_true_intro this, or_comm]
#align list.eq_of_perm_of_sorted List.eq_of_perm_of_sorted
theorem sublist_of_subperm_of_sorted [IsAntisymm α r] {l₁ l₂ : List α} (hp : l₁ <+~ l₂)
(hs₁ : l₁.Sorted r) (hs₂ : l₂.Sorted r) : l₁ <+ l₂ := by
let ⟨_, h, h'⟩ := hp
rwa [← eq_of_perm_of_sorted h (hs₂.sublist h') hs₁]
#align list.sublist_of_subperm_of_sorted List.sublist_of_subperm_of_sorted
@[simp 1100] -- Porting note: higher priority for linter
theorem sorted_singleton (a : α) : Sorted r [a] :=
pairwise_singleton _ _
#align list.sorted_singleton List.sorted_singleton
theorem Sorted.rel_get_of_lt {l : List α} (h : l.Sorted r) {a b : Fin l.length} (hab : a < b) :
r (l.get a) (l.get b) :=
List.pairwise_iff_get.1 h _ _ hab
set_option linter.deprecated false in
@[deprecated Sorted.rel_get_of_lt (since := "2024-05-08")]
theorem Sorted.rel_nthLe_of_lt {l : List α} (h : l.Sorted r) {a b : ℕ} (ha : a < l.length)
(hb : b < l.length) (hab : a < b) : r (l.nthLe a ha) (l.nthLe b hb) :=
List.pairwise_iff_get.1 h ⟨a, ha⟩ ⟨b, hb⟩ hab
#align list.sorted.rel_nth_le_of_lt List.Sorted.rel_nthLe_of_lt
theorem Sorted.rel_get_of_le [IsRefl α r] {l : List α} (h : l.Sorted r) {a b : Fin l.length}
(hab : a ≤ b) : r (l.get a) (l.get b) := by
rcases hab.eq_or_lt with (rfl | hlt)
exacts [refl _, h.rel_get_of_lt hlt]
set_option linter.deprecated false in
@[deprecated Sorted.rel_get_of_le (since := "2024-05-08")]
theorem Sorted.rel_nthLe_of_le [IsRefl α r] {l : List α} (h : l.Sorted r) {a b : ℕ}
(ha : a < l.length) (hb : b < l.length) (hab : a ≤ b) : r (l.nthLe a ha) (l.nthLe b hb) :=
h.rel_get_of_le hab
#align list.sorted.rel_nth_le_of_le List.Sorted.rel_nthLe_of_le
theorem Sorted.rel_of_mem_take_of_mem_drop {l : List α} (h : List.Sorted r l) {k : ℕ} {x y : α}
(hx : x ∈ List.take k l) (hy : y ∈ List.drop k l) : r x y := by
obtain ⟨⟨iy, hiy⟩, rfl⟩ := get_of_mem hy
obtain ⟨⟨ix, hix⟩, rfl⟩ := get_of_mem hx
rw [get_take', get_drop']
rw [length_take] at hix
exact h.rel_get_of_lt (Nat.lt_add_right _ (lt_min_iff.mp hix).left)
#align list.sorted.rel_of_mem_take_of_mem_drop List.Sorted.rel_of_mem_take_of_mem_drop
end Sorted
section Monotone
variable {n : ℕ} {α : Type u} [Preorder α] {f : Fin n → α}
theorem sorted_ofFn_iff {r : α → α → Prop} : (ofFn f).Sorted r ↔ ((· < ·) ⇒ r) f f := by
simp_rw [Sorted, pairwise_iff_get, get_ofFn, Relator.LiftFun]
exact Iff.symm (Fin.rightInverse_cast _).surjective.forall₂
/-- The list `List.ofFn f` is strictly sorted with respect to `(· ≤ ·)` if and only if `f` is
strictly monotone. -/
@[simp] theorem sorted_lt_ofFn_iff : (ofFn f).Sorted (· < ·) ↔ StrictMono f := sorted_ofFn_iff
/-- The list `List.ofFn f` is sorted with respect to `(· ≤ ·)` if and only if `f` is monotone. -/
@[simp] theorem sorted_le_ofFn_iff : (ofFn f).Sorted (· ≤ ·) ↔ Monotone f :=
sorted_ofFn_iff.trans monotone_iff_forall_lt.symm
/-- A tuple is monotone if and only if the list obtained from it is sorted. -/
@[deprecated sorted_le_ofFn_iff (since := "2023-01-10")]
theorem monotone_iff_ofFn_sorted : Monotone f ↔ (ofFn f).Sorted (· ≤ ·) := sorted_le_ofFn_iff.symm
#align list.monotone_iff_of_fn_sorted List.monotone_iff_ofFn_sorted
/-- The list obtained from a monotone tuple is sorted. -/
alias ⟨_, _root_.Monotone.ofFn_sorted⟩ := sorted_le_ofFn_iff
#align list.monotone.of_fn_sorted Monotone.ofFn_sorted
end Monotone
section sort
variable {α : Type u} (r : α → α → Prop) [DecidableRel r]
local infixl:50 " ≼ " => r
/-! ### Insertion sort -/
section InsertionSort
/-- `orderedInsert a l` inserts `a` into `l` at such that
`orderedInsert a l` is sorted if `l` is. -/
@[simp]
def orderedInsert (a : α) : List α → List α
| [] => [a]
| b :: l => if a ≼ b then a :: b :: l else b :: orderedInsert a l
#align list.ordered_insert List.orderedInsert
/-- `insertionSort l` returns `l` sorted using the insertion sort algorithm. -/
@[simp]
def insertionSort : List α → List α
| [] => []
| b :: l => orderedInsert r b (insertionSort l)
#align list.insertion_sort List.insertionSort
@[simp]
theorem orderedInsert_nil (a : α) : [].orderedInsert r a = [a] :=
rfl
#align list.ordered_insert_nil List.orderedInsert_nil
theorem orderedInsert_length : ∀ (L : List α) (a : α), (L.orderedInsert r a).length = L.length + 1
| [], a => rfl
| hd :: tl, a => by
dsimp [orderedInsert]
split_ifs <;> simp [orderedInsert_length tl]
#align list.ordered_insert_length List.orderedInsert_length
/-- An alternative definition of `orderedInsert` using `takeWhile` and `dropWhile`. -/
theorem orderedInsert_eq_take_drop (a : α) :
∀ l : List α,
l.orderedInsert r a = (l.takeWhile fun b => ¬a ≼ b) ++ a :: l.dropWhile fun b => ¬a ≼ b
| [] => rfl
| b :: l => by
dsimp only [orderedInsert]
split_ifs with h <;> simp [takeWhile, dropWhile, *, orderedInsert_eq_take_drop a l]
#align list.ordered_insert_eq_take_drop List.orderedInsert_eq_take_drop
theorem insertionSort_cons_eq_take_drop (a : α) (l : List α) :
insertionSort r (a :: l) =
((insertionSort r l).takeWhile fun b => ¬a ≼ b) ++
a :: (insertionSort r l).dropWhile fun b => ¬a ≼ b :=
orderedInsert_eq_take_drop r a _
#align list.insertion_sort_cons_eq_take_drop List.insertionSort_cons_eq_take_drop
@[simp]
theorem mem_orderedInsert {a b : α} {l : List α} :
a ∈ orderedInsert r b l ↔ a = b ∨ a ∈ l :=
match l with
| [] => by simp [orderedInsert]
| x :: xs => by
rw [orderedInsert]
split_ifs
· simp [orderedInsert]
· rw [mem_cons, mem_cons, mem_orderedInsert, or_left_comm]
section Correctness
open Perm
theorem perm_orderedInsert (a) : ∀ l : List α, orderedInsert r a l ~ a :: l
| [] => Perm.refl _
| b :: l => by
by_cases h : a ≼ b
· simp [orderedInsert, h]
· simpa [orderedInsert, h] using ((perm_orderedInsert a l).cons _).trans (Perm.swap _ _ _)
#align list.perm_ordered_insert List.perm_orderedInsert
theorem orderedInsert_count [DecidableEq α] (L : List α) (a b : α) :
count a (L.orderedInsert r b) = count a L + if a = b then 1 else 0 := by
rw [(L.perm_orderedInsert r b).count_eq, count_cons]
#align list.ordered_insert_count List.orderedInsert_count
theorem perm_insertionSort : ∀ l : List α, insertionSort r l ~ l
| [] => Perm.nil
| b :: l => by
simpa [insertionSort] using (perm_orderedInsert _ _ _).trans ((perm_insertionSort l).cons b)
#align list.perm_insertion_sort List.perm_insertionSort
variable {r}
/-- If `l` is already `List.Sorted` with respect to `r`, then `insertionSort` does not change
it. -/
theorem Sorted.insertionSort_eq : ∀ {l : List α}, Sorted r l → insertionSort r l = l
| [], _ => rfl
| [a], _ => rfl
| a :: b :: l, h => by
rw [insertionSort, Sorted.insertionSort_eq, orderedInsert, if_pos]
exacts [rel_of_sorted_cons h _ (mem_cons_self _ _), h.tail]
#align list.sorted.insertion_sort_eq List.Sorted.insertionSort_eq
/-- For a reflexive relation, insert then erasing is the identity. -/
theorem erase_orderedInsert [DecidableEq α] [IsRefl α r] (x : α) (xs : List α) :
(xs.orderedInsert r x).erase x = xs := by
rw [orderedInsert_eq_take_drop, erase_append_right, List.erase_cons_head,
takeWhile_append_dropWhile]
intro h
replace h := mem_takeWhile_imp h
simp [refl x] at h
/-- Inserting then erasing an element that is absent is the identity. -/
theorem erase_orderedInsert_of_not_mem [DecidableEq α]
{x : α} {xs : List α} (hx : x ∉ xs) :
(xs.orderedInsert r x).erase x = xs := by
rw [orderedInsert_eq_take_drop, erase_append_right, List.erase_cons_head,
takeWhile_append_dropWhile]
exact mt ((takeWhile_prefix _).sublist.subset ·) hx
/-- For an antisymmetric relation, erasing then inserting is the identity. -/
| Mathlib/Data/List/Sort.lean | 314 | 331 | theorem orderedInsert_erase [DecidableEq α] [IsAntisymm α r] (x : α) (xs : List α) (hx : x ∈ xs)
(hxs : Sorted r xs) :
(xs.erase x).orderedInsert r x = xs := by |
induction xs generalizing x with
| nil => cases hx
| cons y ys ih =>
rw [sorted_cons] at hxs
obtain rfl | hxy := Decidable.eq_or_ne x y
· rw [erase_cons_head]
cases ys with
| nil => rfl
| cons z zs =>
rw [orderedInsert, if_pos (hxs.1 _ (.head zs))]
· rw [mem_cons] at hx
replace hx := hx.resolve_left hxy
rw [erase_cons_tail _ (not_beq_of_ne hxy.symm), orderedInsert, ih _ hx hxs.2, if_neg]
refine mt (fun hrxy => ?_) hxy
exact antisymm hrxy (hxs.1 _ hx)
|
/-
Copyright (c) 2019 Rohan Mitta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rohan Mitta, Kevin Buzzard, Alistair Tucker, Johannes Hölzl, Yury Kudryashov
-/
import Mathlib.Analysis.SpecificLimits.Basic
import Mathlib.Data.Setoid.Basic
import Mathlib.Dynamics.FixedPoints.Topology
import Mathlib.Topology.MetricSpace.Lipschitz
#align_import topology.metric_space.contracting from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982"
/-!
# Contracting maps
A Lipschitz continuous self-map with Lipschitz constant `K < 1` is called a *contracting map*.
In this file we prove the Banach fixed point theorem, some explicit estimates on the rate
of convergence, and some properties of the map sending a contracting map to its fixed point.
## Main definitions
* `ContractingWith K f` : a Lipschitz continuous self-map with `K < 1`;
* `efixedPoint` : given a contracting map `f` on a complete emetric space and a point `x`
such that `edist x (f x) ≠ ∞`, `efixedPoint f hf x hx` is the unique fixed point of `f`
in `EMetric.ball x ∞`;
* `fixedPoint` : the unique fixed point of a contracting map on a complete nonempty metric space.
## Tags
contracting map, fixed point, Banach fixed point theorem
-/
open scoped Classical
open NNReal Topology ENNReal Filter Function
variable {α : Type*}
/-- A map is said to be `ContractingWith K`, if `K < 1` and `f` is `LipschitzWith K`. -/
def ContractingWith [EMetricSpace α] (K : ℝ≥0) (f : α → α) :=
K < 1 ∧ LipschitzWith K f
#align contracting_with ContractingWith
namespace ContractingWith
variable [EMetricSpace α] [cs : CompleteSpace α] {K : ℝ≥0} {f : α → α}
open EMetric Set
theorem toLipschitzWith (hf : ContractingWith K f) : LipschitzWith K f := hf.2
#align contracting_with.to_lipschitz_with ContractingWith.toLipschitzWith
theorem one_sub_K_pos' (hf : ContractingWith K f) : (0 : ℝ≥0∞) < 1 - K := by simp [hf.1]
set_option linter.uppercaseLean3 false in
#align contracting_with.one_sub_K_pos' ContractingWith.one_sub_K_pos'
theorem one_sub_K_ne_zero (hf : ContractingWith K f) : (1 : ℝ≥0∞) - K ≠ 0 :=
ne_of_gt hf.one_sub_K_pos'
set_option linter.uppercaseLean3 false in
#align contracting_with.one_sub_K_ne_zero ContractingWith.one_sub_K_ne_zero
theorem one_sub_K_ne_top : (1 : ℝ≥0∞) - K ≠ ∞ := by
norm_cast
exact ENNReal.coe_ne_top
set_option linter.uppercaseLean3 false in
#align contracting_with.one_sub_K_ne_top ContractingWith.one_sub_K_ne_top
theorem edist_inequality (hf : ContractingWith K f) {x y} (h : edist x y ≠ ∞) :
edist x y ≤ (edist x (f x) + edist y (f y)) / (1 - K) :=
suffices edist x y ≤ edist x (f x) + edist y (f y) + K * edist x y by
rwa [ENNReal.le_div_iff_mul_le (Or.inl hf.one_sub_K_ne_zero) (Or.inl one_sub_K_ne_top),
mul_comm, ENNReal.sub_mul fun _ _ ↦ h, one_mul, tsub_le_iff_right]
calc
edist x y ≤ edist x (f x) + edist (f x) (f y) + edist (f y) y := edist_triangle4 _ _ _ _
_ = edist x (f x) + edist y (f y) + edist (f x) (f y) := by rw [edist_comm y, add_right_comm]
_ ≤ edist x (f x) + edist y (f y) + K * edist x y := add_le_add le_rfl (hf.2 _ _)
#align contracting_with.edist_inequality ContractingWith.edist_inequality
theorem edist_le_of_fixedPoint (hf : ContractingWith K f) {x y} (h : edist x y ≠ ∞)
(hy : IsFixedPt f y) : edist x y ≤ edist x (f x) / (1 - K) := by
simpa only [hy.eq, edist_self, add_zero] using hf.edist_inequality h
#align contracting_with.edist_le_of_fixed_point ContractingWith.edist_le_of_fixedPoint
theorem eq_or_edist_eq_top_of_fixedPoints (hf : ContractingWith K f) {x y} (hx : IsFixedPt f x)
(hy : IsFixedPt f y) : x = y ∨ edist x y = ∞ := by
refine or_iff_not_imp_right.2 fun h ↦ edist_le_zero.1 ?_
simpa only [hx.eq, edist_self, add_zero, ENNReal.zero_div] using hf.edist_le_of_fixedPoint h hy
#align contracting_with.eq_or_edist_eq_top_of_fixed_points ContractingWith.eq_or_edist_eq_top_of_fixedPoints
/-- If a map `f` is `ContractingWith K`, and `s` is a forward-invariant set, then
restriction of `f` to `s` is `ContractingWith K` as well. -/
theorem restrict (hf : ContractingWith K f) {s : Set α} (hs : MapsTo f s s) :
ContractingWith K (hs.restrict f s s) :=
⟨hf.1, fun x y ↦ hf.2 x y⟩
#align contracting_with.restrict ContractingWith.restrict
/-- Banach fixed-point theorem, contraction mapping theorem, `EMetricSpace` version.
A contracting map on a complete metric space has a fixed point.
We include more conclusions in this theorem to avoid proving them again later.
The main API for this theorem are the functions `efixedPoint` and `fixedPoint`,
and lemmas about these functions. -/
theorem exists_fixedPoint (hf : ContractingWith K f) (x : α) (hx : edist x (f x) ≠ ∞) :
∃ y, IsFixedPt f y ∧ Tendsto (fun n ↦ f^[n] x) atTop (𝓝 y) ∧
∀ n : ℕ, edist (f^[n] x) y ≤ edist x (f x) * (K : ℝ≥0∞) ^ n / (1 - K) :=
have : CauchySeq fun n ↦ f^[n] x :=
cauchySeq_of_edist_le_geometric K (edist x (f x)) (ENNReal.coe_lt_one_iff.2 hf.1) hx
(hf.toLipschitzWith.edist_iterate_succ_le_geometric x)
let ⟨y, hy⟩ := cauchySeq_tendsto_of_complete this
⟨y, isFixedPt_of_tendsto_iterate hy hf.2.continuous.continuousAt, hy,
edist_le_of_edist_le_geometric_of_tendsto K (edist x (f x))
(hf.toLipschitzWith.edist_iterate_succ_le_geometric x) hy⟩
#align contracting_with.exists_fixed_point ContractingWith.exists_fixedPoint
variable (f)
-- avoid `efixedPoint _` in pretty printer
/-- Let `x` be a point of a complete emetric space. Suppose that `f` is a contracting map,
and `edist x (f x) ≠ ∞`. Then `efixedPoint` is the unique fixed point of `f`
in `EMetric.ball x ∞`. -/
noncomputable def efixedPoint (hf : ContractingWith K f) (x : α) (hx : edist x (f x) ≠ ∞) : α :=
Classical.choose <| hf.exists_fixedPoint x hx
#align contracting_with.efixed_point ContractingWith.efixedPoint
variable {f}
theorem efixedPoint_isFixedPt (hf : ContractingWith K f) {x : α} (hx : edist x (f x) ≠ ∞) :
IsFixedPt f (efixedPoint f hf x hx) :=
(Classical.choose_spec <| hf.exists_fixedPoint x hx).1
#align contracting_with.efixed_point_is_fixed_pt ContractingWith.efixedPoint_isFixedPt
theorem tendsto_iterate_efixedPoint (hf : ContractingWith K f) {x : α} (hx : edist x (f x) ≠ ∞) :
Tendsto (fun n ↦ f^[n] x) atTop (𝓝 <| efixedPoint f hf x hx) :=
(Classical.choose_spec <| hf.exists_fixedPoint x hx).2.1
#align contracting_with.tendsto_iterate_efixed_point ContractingWith.tendsto_iterate_efixedPoint
theorem apriori_edist_iterate_efixedPoint_le (hf : ContractingWith K f) {x : α}
(hx : edist x (f x) ≠ ∞) (n : ℕ) :
edist (f^[n] x) (efixedPoint f hf x hx) ≤ edist x (f x) * (K : ℝ≥0∞) ^ n / (1 - K) :=
(Classical.choose_spec <| hf.exists_fixedPoint x hx).2.2 n
#align contracting_with.apriori_edist_iterate_efixed_point_le ContractingWith.apriori_edist_iterate_efixedPoint_le
theorem edist_efixedPoint_le (hf : ContractingWith K f) {x : α} (hx : edist x (f x) ≠ ∞) :
edist x (efixedPoint f hf x hx) ≤ edist x (f x) / (1 - K) := by
convert hf.apriori_edist_iterate_efixedPoint_le hx 0
simp only [pow_zero, mul_one]
#align contracting_with.edist_efixed_point_le ContractingWith.edist_efixedPoint_le
theorem edist_efixedPoint_lt_top (hf : ContractingWith K f) {x : α} (hx : edist x (f x) ≠ ∞) :
edist x (efixedPoint f hf x hx) < ∞ :=
(hf.edist_efixedPoint_le hx).trans_lt
(ENNReal.mul_lt_top hx <| ENNReal.inv_ne_top.2 hf.one_sub_K_ne_zero)
#align contracting_with.edist_efixed_point_lt_top ContractingWith.edist_efixedPoint_lt_top
theorem efixedPoint_eq_of_edist_lt_top (hf : ContractingWith K f) {x : α} (hx : edist x (f x) ≠ ∞)
{y : α} (hy : edist y (f y) ≠ ∞) (h : edist x y ≠ ∞) :
efixedPoint f hf x hx = efixedPoint f hf y hy := by
refine (hf.eq_or_edist_eq_top_of_fixedPoints ?_ ?_).elim id fun h' ↦ False.elim (ne_of_lt ?_ h')
<;> try apply efixedPoint_isFixedPt
change edistLtTopSetoid.Rel _ _
trans x
· apply Setoid.symm' -- Porting note: Originally `symm`
exact hf.edist_efixedPoint_lt_top hx
trans y
exacts [lt_top_iff_ne_top.2 h, hf.edist_efixedPoint_lt_top hy]
#align contracting_with.efixed_point_eq_of_edist_lt_top ContractingWith.efixedPoint_eq_of_edist_lt_top
/-- Banach fixed-point theorem for maps contracting on a complete subset. -/
theorem exists_fixedPoint' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s)
(hf : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) :
∃ y ∈ s, IsFixedPt f y ∧ Tendsto (fun n ↦ f^[n] x) atTop (𝓝 y) ∧
∀ n : ℕ, edist (f^[n] x) y ≤ edist x (f x) * (K : ℝ≥0∞) ^ n / (1 - K) := by
haveI := hsc.completeSpace_coe
rcases hf.exists_fixedPoint ⟨x, hxs⟩ hx with ⟨y, hfy, h_tendsto, hle⟩
refine ⟨y, y.2, Subtype.ext_iff_val.1 hfy, ?_, fun n ↦ ?_⟩
· convert (continuous_subtype_val.tendsto _).comp h_tendsto
simp only [(· ∘ ·), MapsTo.iterate_restrict, MapsTo.val_restrict_apply]
· convert hle n
rw [MapsTo.iterate_restrict]
rfl
#align contracting_with.exists_fixed_point' ContractingWith.exists_fixedPoint'
variable (f)
-- avoid `efixedPoint _` in pretty printer
/-- Let `s` be a complete forward-invariant set of a self-map `f`. If `f` contracts on `s`
and `x ∈ s` satisfies `edist x (f x) ≠ ∞`, then `efixedPoint'` is the unique fixed point
of the restriction of `f` to `s ∩ EMetric.ball x ∞`. -/
noncomputable def efixedPoint' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s)
(hf : ContractingWith K <| hsf.restrict f s s) (x : α) (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) :
α :=
Classical.choose <| hf.exists_fixedPoint' hsc hsf hxs hx
#align contracting_with.efixed_point' ContractingWith.efixedPoint'
variable {f}
theorem efixedPoint_mem' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s)
(hf : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) :
efixedPoint' f hsc hsf hf x hxs hx ∈ s :=
(Classical.choose_spec <| hf.exists_fixedPoint' hsc hsf hxs hx).1
#align contracting_with.efixed_point_mem' ContractingWith.efixedPoint_mem'
theorem efixedPoint_isFixedPt' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s)
(hf : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) :
IsFixedPt f (efixedPoint' f hsc hsf hf x hxs hx) :=
(Classical.choose_spec <| hf.exists_fixedPoint' hsc hsf hxs hx).2.1
#align contracting_with.efixed_point_is_fixed_pt' ContractingWith.efixedPoint_isFixedPt'
theorem tendsto_iterate_efixedPoint' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s)
(hf : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) :
Tendsto (fun n ↦ f^[n] x) atTop (𝓝 <| efixedPoint' f hsc hsf hf x hxs hx) :=
(Classical.choose_spec <| hf.exists_fixedPoint' hsc hsf hxs hx).2.2.1
#align contracting_with.tendsto_iterate_efixed_point' ContractingWith.tendsto_iterate_efixedPoint'
theorem apriori_edist_iterate_efixedPoint_le' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s)
(hf : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞)
(n : ℕ) :
edist (f^[n] x) (efixedPoint' f hsc hsf hf x hxs hx) ≤
edist x (f x) * (K : ℝ≥0∞) ^ n / (1 - K) :=
(Classical.choose_spec <| hf.exists_fixedPoint' hsc hsf hxs hx).2.2.2 n
#align contracting_with.apriori_edist_iterate_efixed_point_le' ContractingWith.apriori_edist_iterate_efixedPoint_le'
theorem edist_efixedPoint_le' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s)
(hf : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) :
edist x (efixedPoint' f hsc hsf hf x hxs hx) ≤ edist x (f x) / (1 - K) := by
convert hf.apriori_edist_iterate_efixedPoint_le' hsc hsf hxs hx 0
rw [pow_zero, mul_one]
#align contracting_with.edist_efixed_point_le' ContractingWith.edist_efixedPoint_le'
theorem edist_efixedPoint_lt_top' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s)
(hf : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) :
edist x (efixedPoint' f hsc hsf hf x hxs hx) < ∞ :=
(hf.edist_efixedPoint_le' hsc hsf hxs hx).trans_lt
(ENNReal.mul_lt_top hx <| ENNReal.inv_ne_top.2 hf.one_sub_K_ne_zero)
#align contracting_with.edist_efixed_point_lt_top' ContractingWith.edist_efixedPoint_lt_top'
/-- If a globally contracting map `f` has two complete forward-invariant sets `s`, `t`,
and `x ∈ s` is at a finite distance from `y ∈ t`, then the `efixedPoint'` constructed by `x`
is the same as the `efixedPoint'` constructed by `y`.
This lemma takes additional arguments stating that `f` contracts on `s` and `t` because this way
it can be used to prove the desired equality with non-trivial proofs of these facts. -/
| Mathlib/Topology/MetricSpace/Contracting.lean | 243 | 257 | theorem efixedPoint_eq_of_edist_lt_top' (hf : ContractingWith K f) {s : Set α} (hsc : IsComplete s)
(hsf : MapsTo f s s) (hfs : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s)
(hx : edist x (f x) ≠ ∞) {t : Set α} (htc : IsComplete t) (htf : MapsTo f t t)
(hft : ContractingWith K <| htf.restrict f t t) {y : α} (hyt : y ∈ t) (hy : edist y (f y) ≠ ∞)
(hxy : edist x y ≠ ∞) :
efixedPoint' f hsc hsf hfs x hxs hx = efixedPoint' f htc htf hft y hyt hy := by |
refine (hf.eq_or_edist_eq_top_of_fixedPoints ?_ ?_).elim id fun h' ↦ False.elim (ne_of_lt ?_ h')
<;> try apply efixedPoint_isFixedPt'
change edistLtTopSetoid.Rel _ _
trans x
· apply Setoid.symm' -- Porting note: Originally `symm`
apply edist_efixedPoint_lt_top'
trans y
· exact lt_top_iff_ne_top.2 hxy
· apply edist_efixedPoint_lt_top'
|
/-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.Algebra.BigOperators.Ring
import Mathlib.Algebra.Module.BigOperators
import Mathlib.NumberTheory.Divisors
import Mathlib.Data.Nat.Squarefree
import Mathlib.Data.Nat.GCD.BigOperators
import Mathlib.Data.Nat.Factorization.Basic
import Mathlib.Tactic.ArithMult
#align_import number_theory.arithmetic_function from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3"
/-!
# Arithmetic Functions and Dirichlet Convolution
This file defines arithmetic functions, which are functions from `ℕ` to a specified type that map 0
to 0. In the literature, they are often instead defined as functions from `ℕ+`. These arithmetic
functions are endowed with a multiplication, given by Dirichlet convolution, and pointwise addition,
to form the Dirichlet ring.
## Main Definitions
* `ArithmeticFunction R` consists of functions `f : ℕ → R` such that `f 0 = 0`.
* An arithmetic function `f` `IsMultiplicative` when `x.coprime y → f (x * y) = f x * f y`.
* The pointwise operations `pmul` and `ppow` differ from the multiplication
and power instances on `ArithmeticFunction R`, which use Dirichlet multiplication.
* `ζ` is the arithmetic function such that `ζ x = 1` for `0 < x`.
* `σ k` is the arithmetic function such that `σ k x = ∑ y ∈ divisors x, y ^ k` for `0 < x`.
* `pow k` is the arithmetic function such that `pow k x = x ^ k` for `0 < x`.
* `id` is the identity arithmetic function on `ℕ`.
* `ω n` is the number of distinct prime factors of `n`.
* `Ω n` is the number of prime factors of `n` counted with multiplicity.
* `μ` is the Möbius function (spelled `moebius` in code).
## Main Results
* Several forms of Möbius inversion:
* `sum_eq_iff_sum_mul_moebius_eq` for functions to a `CommRing`
* `sum_eq_iff_sum_smul_moebius_eq` for functions to an `AddCommGroup`
* `prod_eq_iff_prod_pow_moebius_eq` for functions to a `CommGroup`
* `prod_eq_iff_prod_pow_moebius_eq_of_nonzero` for functions to a `CommGroupWithZero`
* And variants that apply when the equalities only hold on a set `S : Set ℕ` such that
`m ∣ n → n ∈ S → m ∈ S`:
* `sum_eq_iff_sum_mul_moebius_eq_on` for functions to a `CommRing`
* `sum_eq_iff_sum_smul_moebius_eq_on` for functions to an `AddCommGroup`
* `prod_eq_iff_prod_pow_moebius_eq_on` for functions to a `CommGroup`
* `prod_eq_iff_prod_pow_moebius_eq_on_of_nonzero` for functions to a `CommGroupWithZero`
## Notation
All notation is localized in the namespace `ArithmeticFunction`.
The arithmetic functions `ζ`, `σ`, `ω`, `Ω` and `μ` have Greek letter names.
In addition, there are separate locales `ArithmeticFunction.zeta` for `ζ`,
`ArithmeticFunction.sigma` for `σ`, `ArithmeticFunction.omega` for `ω`,
`ArithmeticFunction.Omega` for `Ω`, and `ArithmeticFunction.Moebius` for `μ`,
to allow for selective access to these notations.
The arithmetic function $$n \mapsto \prod_{p \mid n} f(p)$$ is given custom notation
`∏ᵖ p ∣ n, f p` when applied to `n`.
## Tags
arithmetic functions, dirichlet convolution, divisors
-/
open Finset
open Nat
variable (R : Type*)
/-- An arithmetic function is a function from `ℕ` that maps 0 to 0. In the literature, they are
often instead defined as functions from `ℕ+`. Multiplication on `ArithmeticFunctions` is by
Dirichlet convolution. -/
def ArithmeticFunction [Zero R] :=
ZeroHom ℕ R
#align nat.arithmetic_function ArithmeticFunction
instance ArithmeticFunction.zero [Zero R] : Zero (ArithmeticFunction R) :=
inferInstanceAs (Zero (ZeroHom ℕ R))
instance [Zero R] : Inhabited (ArithmeticFunction R) := inferInstanceAs (Inhabited (ZeroHom ℕ R))
variable {R}
namespace ArithmeticFunction
section Zero
variable [Zero R]
-- porting note: used to be `CoeFun`
instance : FunLike (ArithmeticFunction R) ℕ R :=
inferInstanceAs (FunLike (ZeroHom ℕ R) ℕ R)
@[simp]
theorem toFun_eq (f : ArithmeticFunction R) : f.toFun = f := rfl
#align nat.arithmetic_function.to_fun_eq ArithmeticFunction.toFun_eq
@[simp]
theorem coe_mk (f : ℕ → R) (hf) : @DFunLike.coe (ArithmeticFunction R) _ _ _
(ZeroHom.mk f hf) = f := rfl
@[simp]
theorem map_zero {f : ArithmeticFunction R} : f 0 = 0 :=
ZeroHom.map_zero' f
#align nat.arithmetic_function.map_zero ArithmeticFunction.map_zero
theorem coe_inj {f g : ArithmeticFunction R} : (f : ℕ → R) = g ↔ f = g :=
DFunLike.coe_fn_eq
#align nat.arithmetic_function.coe_inj ArithmeticFunction.coe_inj
@[simp]
theorem zero_apply {x : ℕ} : (0 : ArithmeticFunction R) x = 0 :=
ZeroHom.zero_apply x
#align nat.arithmetic_function.zero_apply ArithmeticFunction.zero_apply
@[ext]
theorem ext ⦃f g : ArithmeticFunction R⦄ (h : ∀ x, f x = g x) : f = g :=
ZeroHom.ext h
#align nat.arithmetic_function.ext ArithmeticFunction.ext
theorem ext_iff {f g : ArithmeticFunction R} : f = g ↔ ∀ x, f x = g x :=
DFunLike.ext_iff
#align nat.arithmetic_function.ext_iff ArithmeticFunction.ext_iff
section One
variable [One R]
instance one : One (ArithmeticFunction R) :=
⟨⟨fun x => ite (x = 1) 1 0, rfl⟩⟩
theorem one_apply {x : ℕ} : (1 : ArithmeticFunction R) x = ite (x = 1) 1 0 :=
rfl
#align nat.arithmetic_function.one_apply ArithmeticFunction.one_apply
@[simp]
theorem one_one : (1 : ArithmeticFunction R) 1 = 1 :=
rfl
#align nat.arithmetic_function.one_one ArithmeticFunction.one_one
@[simp]
theorem one_apply_ne {x : ℕ} (h : x ≠ 1) : (1 : ArithmeticFunction R) x = 0 :=
if_neg h
#align nat.arithmetic_function.one_apply_ne ArithmeticFunction.one_apply_ne
end One
end Zero
/-- Coerce an arithmetic function with values in `ℕ` to one with values in `R`. We cannot inline
this in `natCoe` because it gets unfolded too much. -/
@[coe] -- Porting note: added `coe` tag.
def natToArithmeticFunction [AddMonoidWithOne R] :
(ArithmeticFunction ℕ) → (ArithmeticFunction R) :=
fun f => ⟨fun n => ↑(f n), by simp⟩
instance natCoe [AddMonoidWithOne R] : Coe (ArithmeticFunction ℕ) (ArithmeticFunction R) :=
⟨natToArithmeticFunction⟩
#align nat.arithmetic_function.nat_coe ArithmeticFunction.natCoe
@[simp]
theorem natCoe_nat (f : ArithmeticFunction ℕ) : natToArithmeticFunction f = f :=
ext fun _ => cast_id _
#align nat.arithmetic_function.nat_coe_nat ArithmeticFunction.natCoe_nat
@[simp]
theorem natCoe_apply [AddMonoidWithOne R] {f : ArithmeticFunction ℕ} {x : ℕ} :
(f : ArithmeticFunction R) x = f x :=
rfl
#align nat.arithmetic_function.nat_coe_apply ArithmeticFunction.natCoe_apply
/-- Coerce an arithmetic function with values in `ℤ` to one with values in `R`. We cannot inline
this in `intCoe` because it gets unfolded too much. -/
@[coe]
def ofInt [AddGroupWithOne R] :
(ArithmeticFunction ℤ) → (ArithmeticFunction R) :=
fun f => ⟨fun n => ↑(f n), by simp⟩
instance intCoe [AddGroupWithOne R] : Coe (ArithmeticFunction ℤ) (ArithmeticFunction R) :=
⟨ofInt⟩
#align nat.arithmetic_function.int_coe ArithmeticFunction.intCoe
@[simp]
theorem intCoe_int (f : ArithmeticFunction ℤ) : ofInt f = f :=
ext fun _ => Int.cast_id
#align nat.arithmetic_function.int_coe_int ArithmeticFunction.intCoe_int
@[simp]
theorem intCoe_apply [AddGroupWithOne R] {f : ArithmeticFunction ℤ} {x : ℕ} :
(f : ArithmeticFunction R) x = f x := rfl
#align nat.arithmetic_function.int_coe_apply ArithmeticFunction.intCoe_apply
@[simp]
theorem coe_coe [AddGroupWithOne R] {f : ArithmeticFunction ℕ} :
((f : ArithmeticFunction ℤ) : ArithmeticFunction R) = (f : ArithmeticFunction R) := by
ext
simp
#align nat.arithmetic_function.coe_coe ArithmeticFunction.coe_coe
@[simp]
theorem natCoe_one [AddMonoidWithOne R] :
((1 : ArithmeticFunction ℕ) : ArithmeticFunction R) = 1 := by
ext n
simp [one_apply]
#align nat.arithmetic_function.nat_coe_one ArithmeticFunction.natCoe_one
@[simp]
theorem intCoe_one [AddGroupWithOne R] : ((1 : ArithmeticFunction ℤ) :
ArithmeticFunction R) = 1 := by
ext n
simp [one_apply]
#align nat.arithmetic_function.int_coe_one ArithmeticFunction.intCoe_one
section AddMonoid
variable [AddMonoid R]
instance add : Add (ArithmeticFunction R) :=
⟨fun f g => ⟨fun n => f n + g n, by simp⟩⟩
@[simp]
theorem add_apply {f g : ArithmeticFunction R} {n : ℕ} : (f + g) n = f n + g n :=
rfl
#align nat.arithmetic_function.add_apply ArithmeticFunction.add_apply
instance instAddMonoid : AddMonoid (ArithmeticFunction R) :=
{ ArithmeticFunction.zero R,
ArithmeticFunction.add with
add_assoc := fun _ _ _ => ext fun _ => add_assoc _ _ _
zero_add := fun _ => ext fun _ => zero_add _
add_zero := fun _ => ext fun _ => add_zero _
nsmul := nsmulRec }
#align nat.arithmetic_function.add_monoid ArithmeticFunction.instAddMonoid
end AddMonoid
instance instAddMonoidWithOne [AddMonoidWithOne R] : AddMonoidWithOne (ArithmeticFunction R) :=
{ ArithmeticFunction.instAddMonoid,
ArithmeticFunction.one with
natCast := fun n => ⟨fun x => if x = 1 then (n : R) else 0, by simp⟩
natCast_zero := by ext; simp
natCast_succ := fun n => by ext x; by_cases h : x = 1 <;> simp [h] }
#align nat.arithmetic_function.add_monoid_with_one ArithmeticFunction.instAddMonoidWithOne
instance instAddCommMonoid [AddCommMonoid R] : AddCommMonoid (ArithmeticFunction R) :=
{ ArithmeticFunction.instAddMonoid with add_comm := fun _ _ => ext fun _ => add_comm _ _ }
instance [NegZeroClass R] : Neg (ArithmeticFunction R) where
neg f := ⟨fun n => -f n, by simp⟩
instance [AddGroup R] : AddGroup (ArithmeticFunction R) :=
{ ArithmeticFunction.instAddMonoid with
add_left_neg := fun _ => ext fun _ => add_left_neg _
zsmul := zsmulRec }
instance [AddCommGroup R] : AddCommGroup (ArithmeticFunction R) :=
{ show AddGroup (ArithmeticFunction R) by infer_instance with
add_comm := fun _ _ ↦ add_comm _ _ }
section SMul
variable {M : Type*} [Zero R] [AddCommMonoid M] [SMul R M]
/-- The Dirichlet convolution of two arithmetic functions `f` and `g` is another arithmetic function
such that `(f * g) n` is the sum of `f x * g y` over all `(x,y)` such that `x * y = n`. -/
instance : SMul (ArithmeticFunction R) (ArithmeticFunction M) :=
⟨fun f g => ⟨fun n => ∑ x ∈ divisorsAntidiagonal n, f x.fst • g x.snd, by simp⟩⟩
@[simp]
theorem smul_apply {f : ArithmeticFunction R} {g : ArithmeticFunction M} {n : ℕ} :
(f • g) n = ∑ x ∈ divisorsAntidiagonal n, f x.fst • g x.snd :=
rfl
#align nat.arithmetic_function.smul_apply ArithmeticFunction.smul_apply
end SMul
/-- The Dirichlet convolution of two arithmetic functions `f` and `g` is another arithmetic function
such that `(f * g) n` is the sum of `f x * g y` over all `(x,y)` such that `x * y = n`. -/
instance [Semiring R] : Mul (ArithmeticFunction R) :=
⟨(· • ·)⟩
@[simp]
theorem mul_apply [Semiring R] {f g : ArithmeticFunction R} {n : ℕ} :
(f * g) n = ∑ x ∈ divisorsAntidiagonal n, f x.fst * g x.snd :=
rfl
#align nat.arithmetic_function.mul_apply ArithmeticFunction.mul_apply
theorem mul_apply_one [Semiring R] {f g : ArithmeticFunction R} : (f * g) 1 = f 1 * g 1 := by simp
#align nat.arithmetic_function.mul_apply_one ArithmeticFunction.mul_apply_one
@[simp, norm_cast]
theorem natCoe_mul [Semiring R] {f g : ArithmeticFunction ℕ} :
(↑(f * g) : ArithmeticFunction R) = f * g := by
ext n
simp
#align nat.arithmetic_function.nat_coe_mul ArithmeticFunction.natCoe_mul
@[simp, norm_cast]
theorem intCoe_mul [Ring R] {f g : ArithmeticFunction ℤ} :
(↑(f * g) : ArithmeticFunction R) = ↑f * g := by
ext n
simp
#align nat.arithmetic_function.int_coe_mul ArithmeticFunction.intCoe_mul
section Module
variable {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M]
theorem mul_smul' (f g : ArithmeticFunction R) (h : ArithmeticFunction M) :
(f * g) • h = f • g • h := by
ext n
simp only [mul_apply, smul_apply, sum_smul, mul_smul, smul_sum, Finset.sum_sigma']
apply Finset.sum_nbij' (fun ⟨⟨_i, j⟩, ⟨k, l⟩⟩ ↦ ⟨(k, l * j), (l, j)⟩)
(fun ⟨⟨i, _j⟩, ⟨k, l⟩⟩ ↦ ⟨(i * k, l), (i, k)⟩) <;> aesop (add simp mul_assoc)
#align nat.arithmetic_function.mul_smul' ArithmeticFunction.mul_smul'
theorem one_smul' (b : ArithmeticFunction M) : (1 : ArithmeticFunction R) • b = b := by
ext x
rw [smul_apply]
by_cases x0 : x = 0
· simp [x0]
have h : {(1, x)} ⊆ divisorsAntidiagonal x := by simp [x0]
rw [← sum_subset h]
· simp
intro y ymem ynmem
have y1ne : y.fst ≠ 1 := by
intro con
simp only [Con, mem_divisorsAntidiagonal, one_mul, Ne] at ymem
simp only [mem_singleton, Prod.ext_iff] at ynmem
-- Porting note: `tauto` worked from here.
cases y
subst con
simp only [true_and, one_mul, x0, not_false_eq_true, and_true] at ynmem ymem
tauto
simp [y1ne]
#align nat.arithmetic_function.one_smul' ArithmeticFunction.one_smul'
end Module
section Semiring
variable [Semiring R]
instance instMonoid : Monoid (ArithmeticFunction R) :=
{ one := One.one
mul := Mul.mul
one_mul := one_smul'
mul_one := fun f => by
ext x
rw [mul_apply]
by_cases x0 : x = 0
· simp [x0]
have h : {(x, 1)} ⊆ divisorsAntidiagonal x := by simp [x0]
rw [← sum_subset h]
· simp
intro y ymem ynmem
have y2ne : y.snd ≠ 1 := by
intro con
cases y; subst con -- Porting note: added
simp only [Con, mem_divisorsAntidiagonal, mul_one, Ne] at ymem
simp only [mem_singleton, Prod.ext_iff] at ynmem
tauto
simp [y2ne]
mul_assoc := mul_smul' }
#align nat.arithmetic_function.monoid ArithmeticFunction.instMonoid
instance instSemiring : Semiring (ArithmeticFunction R) :=
-- Porting note: I reorganized this instance
{ ArithmeticFunction.instAddMonoidWithOne,
ArithmeticFunction.instMonoid,
ArithmeticFunction.instAddCommMonoid with
zero_mul := fun f => by
ext
simp only [mul_apply, zero_mul, sum_const_zero, zero_apply]
mul_zero := fun f => by
ext
simp only [mul_apply, sum_const_zero, mul_zero, zero_apply]
left_distrib := fun a b c => by
ext
simp only [← sum_add_distrib, mul_add, mul_apply, add_apply]
right_distrib := fun a b c => by
ext
simp only [← sum_add_distrib, add_mul, mul_apply, add_apply] }
#align nat.arithmetic_function.semiring ArithmeticFunction.instSemiring
end Semiring
instance [CommSemiring R] : CommSemiring (ArithmeticFunction R) :=
{ ArithmeticFunction.instSemiring with
mul_comm := fun f g => by
ext
rw [mul_apply, ← map_swap_divisorsAntidiagonal, sum_map]
simp [mul_comm] }
instance [CommRing R] : CommRing (ArithmeticFunction R) :=
{ ArithmeticFunction.instSemiring with
add_left_neg := add_left_neg
mul_comm := mul_comm
zsmul := (· • ·) }
instance {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] :
Module (ArithmeticFunction R) (ArithmeticFunction M) where
one_smul := one_smul'
mul_smul := mul_smul'
smul_add r x y := by
ext
simp only [sum_add_distrib, smul_add, smul_apply, add_apply]
smul_zero r := by
ext
simp only [smul_apply, sum_const_zero, smul_zero, zero_apply]
add_smul r s x := by
ext
simp only [add_smul, sum_add_distrib, smul_apply, add_apply]
zero_smul r := by
ext
simp only [smul_apply, sum_const_zero, zero_smul, zero_apply]
section Zeta
/-- `ζ 0 = 0`, otherwise `ζ x = 1`. The Dirichlet Series is the Riemann `ζ`. -/
def zeta : ArithmeticFunction ℕ :=
⟨fun x => ite (x = 0) 0 1, rfl⟩
#align nat.arithmetic_function.zeta ArithmeticFunction.zeta
@[inherit_doc]
scoped[ArithmeticFunction] notation "ζ" => ArithmeticFunction.zeta
@[inherit_doc]
scoped[ArithmeticFunction.zeta] notation "ζ" => ArithmeticFunction.zeta
@[simp]
theorem zeta_apply {x : ℕ} : ζ x = if x = 0 then 0 else 1 :=
rfl
#align nat.arithmetic_function.zeta_apply ArithmeticFunction.zeta_apply
theorem zeta_apply_ne {x : ℕ} (h : x ≠ 0) : ζ x = 1 :=
if_neg h
#align nat.arithmetic_function.zeta_apply_ne ArithmeticFunction.zeta_apply_ne
-- Porting note: removed `@[simp]`, LHS not in normal form
theorem coe_zeta_smul_apply {M} [Semiring R] [AddCommMonoid M] [Module R M]
{f : ArithmeticFunction M} {x : ℕ} :
((↑ζ : ArithmeticFunction R) • f) x = ∑ i ∈ divisors x, f i := by
rw [smul_apply]
trans ∑ i ∈ divisorsAntidiagonal x, f i.snd
· refine sum_congr rfl fun i hi => ?_
rcases mem_divisorsAntidiagonal.1 hi with ⟨rfl, h⟩
rw [natCoe_apply, zeta_apply_ne (left_ne_zero_of_mul h), cast_one, one_smul]
· rw [← map_div_left_divisors, sum_map, Function.Embedding.coeFn_mk]
#align nat.arithmetic_function.coe_zeta_smul_apply ArithmeticFunction.coe_zeta_smul_apply
-- Porting note: removed `@[simp]` to make the linter happy.
theorem coe_zeta_mul_apply [Semiring R] {f : ArithmeticFunction R} {x : ℕ} :
(↑ζ * f) x = ∑ i ∈ divisors x, f i :=
coe_zeta_smul_apply
#align nat.arithmetic_function.coe_zeta_mul_apply ArithmeticFunction.coe_zeta_mul_apply
-- Porting note: removed `@[simp]` to make the linter happy.
theorem coe_mul_zeta_apply [Semiring R] {f : ArithmeticFunction R} {x : ℕ} :
(f * ζ) x = ∑ i ∈ divisors x, f i := by
rw [mul_apply]
trans ∑ i ∈ divisorsAntidiagonal x, f i.1
· refine sum_congr rfl fun i hi => ?_
rcases mem_divisorsAntidiagonal.1 hi with ⟨rfl, h⟩
rw [natCoe_apply, zeta_apply_ne (right_ne_zero_of_mul h), cast_one, mul_one]
· rw [← map_div_right_divisors, sum_map, Function.Embedding.coeFn_mk]
#align nat.arithmetic_function.coe_mul_zeta_apply ArithmeticFunction.coe_mul_zeta_apply
theorem zeta_mul_apply {f : ArithmeticFunction ℕ} {x : ℕ} : (ζ * f) x = ∑ i ∈ divisors x, f i :=
coe_zeta_mul_apply
-- Porting note: was `by rw [← nat_coe_nat ζ, coe_zeta_mul_apply]`. Is this `theorem` obsolete?
#align nat.arithmetic_function.zeta_mul_apply ArithmeticFunction.zeta_mul_apply
theorem mul_zeta_apply {f : ArithmeticFunction ℕ} {x : ℕ} : (f * ζ) x = ∑ i ∈ divisors x, f i :=
coe_mul_zeta_apply
-- Porting note: was `by rw [← natCoe_nat ζ, coe_mul_zeta_apply]`. Is this `theorem` obsolete=
#align nat.arithmetic_function.mul_zeta_apply ArithmeticFunction.mul_zeta_apply
end Zeta
open ArithmeticFunction
section Pmul
/-- This is the pointwise product of `ArithmeticFunction`s. -/
def pmul [MulZeroClass R] (f g : ArithmeticFunction R) : ArithmeticFunction R :=
⟨fun x => f x * g x, by simp⟩
#align nat.arithmetic_function.pmul ArithmeticFunction.pmul
@[simp]
theorem pmul_apply [MulZeroClass R] {f g : ArithmeticFunction R} {x : ℕ} : f.pmul g x = f x * g x :=
rfl
#align nat.arithmetic_function.pmul_apply ArithmeticFunction.pmul_apply
theorem pmul_comm [CommMonoidWithZero R] (f g : ArithmeticFunction R) : f.pmul g = g.pmul f := by
ext
simp [mul_comm]
#align nat.arithmetic_function.pmul_comm ArithmeticFunction.pmul_comm
lemma pmul_assoc [CommMonoidWithZero R] (f₁ f₂ f₃ : ArithmeticFunction R) :
pmul (pmul f₁ f₂) f₃ = pmul f₁ (pmul f₂ f₃) := by
ext
simp only [pmul_apply, mul_assoc]
section NonAssocSemiring
variable [NonAssocSemiring R]
@[simp]
theorem pmul_zeta (f : ArithmeticFunction R) : f.pmul ↑ζ = f := by
ext x
cases x <;> simp [Nat.succ_ne_zero]
#align nat.arithmetic_function.pmul_zeta ArithmeticFunction.pmul_zeta
@[simp]
theorem zeta_pmul (f : ArithmeticFunction R) : (ζ : ArithmeticFunction R).pmul f = f := by
ext x
cases x <;> simp [Nat.succ_ne_zero]
#align nat.arithmetic_function.zeta_pmul ArithmeticFunction.zeta_pmul
end NonAssocSemiring
variable [Semiring R]
/-- This is the pointwise power of `ArithmeticFunction`s. -/
def ppow (f : ArithmeticFunction R) (k : ℕ) : ArithmeticFunction R :=
if h0 : k = 0 then ζ else ⟨fun x ↦ f x ^ k, by simp_rw [map_zero, zero_pow h0]⟩
#align nat.arithmetic_function.ppow ArithmeticFunction.ppow
@[simp]
theorem ppow_zero {f : ArithmeticFunction R} : f.ppow 0 = ζ := by rw [ppow, dif_pos rfl]
#align nat.arithmetic_function.ppow_zero ArithmeticFunction.ppow_zero
@[simp]
theorem ppow_apply {f : ArithmeticFunction R} {k x : ℕ} (kpos : 0 < k) : f.ppow k x = f x ^ k := by
rw [ppow, dif_neg (Nat.ne_of_gt kpos)]
rfl
#align nat.arithmetic_function.ppow_apply ArithmeticFunction.ppow_apply
theorem ppow_succ' {f : ArithmeticFunction R} {k : ℕ} : f.ppow (k + 1) = f.pmul (f.ppow k) := by
ext x
rw [ppow_apply (Nat.succ_pos k), _root_.pow_succ']
induction k <;> simp
#align nat.arithmetic_function.ppow_succ ArithmeticFunction.ppow_succ'
theorem ppow_succ {f : ArithmeticFunction R} {k : ℕ} {kpos : 0 < k} :
f.ppow (k + 1) = (f.ppow k).pmul f := by
ext x
rw [ppow_apply (Nat.succ_pos k), _root_.pow_succ]
induction k <;> simp
#align nat.arithmetic_function.ppow_succ' ArithmeticFunction.ppow_succ
end Pmul
section Pdiv
/-- This is the pointwise division of `ArithmeticFunction`s. -/
def pdiv [GroupWithZero R] (f g : ArithmeticFunction R) : ArithmeticFunction R :=
⟨fun n => f n / g n, by simp only [map_zero, ne_eq, not_true, div_zero]⟩
@[simp]
theorem pdiv_apply [GroupWithZero R] (f g : ArithmeticFunction R) (n : ℕ) :
pdiv f g n = f n / g n := rfl
/-- This result only holds for `DivisionSemiring`s instead of `GroupWithZero`s because zeta takes
values in ℕ, and hence the coercion requires an `AddMonoidWithOne`. TODO: Generalise zeta -/
@[simp]
theorem pdiv_zeta [DivisionSemiring R] (f : ArithmeticFunction R) :
pdiv f zeta = f := by
ext n
cases n <;> simp [succ_ne_zero]
end Pdiv
section ProdPrimeFactors
/-- The map $n \mapsto \prod_{p \mid n} f(p)$ as an arithmetic function -/
def prodPrimeFactors [CommMonoidWithZero R] (f : ℕ → R) : ArithmeticFunction R where
toFun d := if d = 0 then 0 else ∏ p ∈ d.primeFactors, f p
map_zero' := if_pos rfl
open Batteries.ExtendedBinder
/-- `∏ᵖ p ∣ n, f p` is custom notation for `prodPrimeFactors f n` -/
scoped syntax (name := bigproddvd) "∏ᵖ " extBinder " ∣ " term ", " term:67 : term
scoped macro_rules (kind := bigproddvd)
| `(∏ᵖ $x:ident ∣ $n, $r) => `(prodPrimeFactors (fun $x ↦ $r) $n)
@[simp]
theorem prodPrimeFactors_apply [CommMonoidWithZero R] {f: ℕ → R} {n : ℕ} (hn : n ≠ 0) :
∏ᵖ p ∣ n, f p = ∏ p ∈ n.primeFactors, f p :=
if_neg hn
end ProdPrimeFactors
/-- Multiplicative functions -/
def IsMultiplicative [MonoidWithZero R] (f : ArithmeticFunction R) : Prop :=
f 1 = 1 ∧ ∀ {m n : ℕ}, m.Coprime n → f (m * n) = f m * f n
#align nat.arithmetic_function.is_multiplicative ArithmeticFunction.IsMultiplicative
namespace IsMultiplicative
section MonoidWithZero
variable [MonoidWithZero R]
@[simp, arith_mult]
theorem map_one {f : ArithmeticFunction R} (h : f.IsMultiplicative) : f 1 = 1 :=
h.1
#align nat.arithmetic_function.is_multiplicative.map_one ArithmeticFunction.IsMultiplicative.map_one
@[simp]
theorem map_mul_of_coprime {f : ArithmeticFunction R} (hf : f.IsMultiplicative) {m n : ℕ}
(h : m.Coprime n) : f (m * n) = f m * f n :=
hf.2 h
#align nat.arithmetic_function.is_multiplicative.map_mul_of_coprime ArithmeticFunction.IsMultiplicative.map_mul_of_coprime
end MonoidWithZero
theorem map_prod {ι : Type*} [CommMonoidWithZero R] (g : ι → ℕ) {f : ArithmeticFunction R}
(hf : f.IsMultiplicative) (s : Finset ι) (hs : (s : Set ι).Pairwise (Coprime on g)) :
f (∏ i ∈ s, g i) = ∏ i ∈ s, f (g i) := by
classical
induction' s using Finset.induction_on with a s has ih hs
· simp [hf]
rw [coe_insert, Set.pairwise_insert_of_symmetric (Coprime.symmetric.comap g)] at hs
rw [prod_insert has, prod_insert has, hf.map_mul_of_coprime, ih hs.1]
exact .prod_right fun i hi => hs.2 _ hi (hi.ne_of_not_mem has).symm
#align nat.arithmetic_function.is_multiplicative.map_prod ArithmeticFunction.IsMultiplicative.map_prod
theorem map_prod_of_prime [CommSemiring R] {f : ArithmeticFunction R}
(h_mult : ArithmeticFunction.IsMultiplicative f)
(t : Finset ℕ) (ht : ∀ p ∈ t, p.Prime) :
f (∏ a ∈ t, a) = ∏ a ∈ t, f a :=
map_prod _ h_mult t fun x hx y hy hxy => (coprime_primes (ht x hx) (ht y hy)).mpr hxy
theorem map_prod_of_subset_primeFactors [CommSemiring R] {f : ArithmeticFunction R}
(h_mult : ArithmeticFunction.IsMultiplicative f) (l : ℕ)
(t : Finset ℕ) (ht : t ⊆ l.primeFactors) :
f (∏ a ∈ t, a) = ∏ a ∈ t, f a :=
map_prod_of_prime h_mult t fun _ a => prime_of_mem_primeFactors (ht a)
@[arith_mult]
theorem natCast {f : ArithmeticFunction ℕ} [Semiring R] (h : f.IsMultiplicative) :
IsMultiplicative (f : ArithmeticFunction R) :=
-- Porting note: was `by simp [cop, h]`
⟨by simp [h], fun {m n} cop => by simp [h.2 cop]⟩
#align nat.arithmetic_function.is_multiplicative.nat_cast ArithmeticFunction.IsMultiplicative.natCast
@[deprecated (since := "2024-04-17")]
alias nat_cast := natCast
@[arith_mult]
theorem intCast {f : ArithmeticFunction ℤ} [Ring R] (h : f.IsMultiplicative) :
IsMultiplicative (f : ArithmeticFunction R) :=
-- Porting note: was `by simp [cop, h]`
⟨by simp [h], fun {m n} cop => by simp [h.2 cop]⟩
#align nat.arithmetic_function.is_multiplicative.int_cast ArithmeticFunction.IsMultiplicative.intCast
@[deprecated (since := "2024-04-17")]
alias int_cast := intCast
@[arith_mult]
theorem mul [CommSemiring R] {f g : ArithmeticFunction R} (hf : f.IsMultiplicative)
(hg : g.IsMultiplicative) : IsMultiplicative (f * g) := by
refine ⟨by simp [hf.1, hg.1], ?_⟩
simp only [mul_apply]
intro m n cop
rw [sum_mul_sum, ← sum_product']
symm
apply sum_nbij fun ((i, j), k, l) ↦ (i * k, j * l)
· rintro ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ h
simp only [mem_divisorsAntidiagonal, Ne, mem_product] at h
rcases h with ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩
simp only [mem_divisorsAntidiagonal, Nat.mul_eq_zero, Ne]
constructor
· ring
rw [Nat.mul_eq_zero] at *
apply not_or_of_not ha hb
· simp only [Set.InjOn, mem_coe, mem_divisorsAntidiagonal, Ne, mem_product, Prod.mk.inj_iff]
rintro ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩ ⟨⟨c1, c2⟩, ⟨d1, d2⟩⟩ hcd h
simp only [Prod.mk.inj_iff] at h
ext <;> dsimp only
· trans Nat.gcd (a1 * a2) (a1 * b1)
· rw [Nat.gcd_mul_left, cop.coprime_mul_left.coprime_mul_right_right.gcd_eq_one, mul_one]
· rw [← hcd.1.1, ← hcd.2.1] at cop
rw [← hcd.1.1, h.1, Nat.gcd_mul_left,
cop.coprime_mul_left.coprime_mul_right_right.gcd_eq_one, mul_one]
· trans Nat.gcd (a1 * a2) (a2 * b2)
· rw [mul_comm, Nat.gcd_mul_left, cop.coprime_mul_right.coprime_mul_left_right.gcd_eq_one,
mul_one]
· rw [← hcd.1.1, ← hcd.2.1] at cop
rw [← hcd.1.1, h.2, mul_comm, Nat.gcd_mul_left,
cop.coprime_mul_right.coprime_mul_left_right.gcd_eq_one, mul_one]
· trans Nat.gcd (b1 * b2) (a1 * b1)
· rw [mul_comm, Nat.gcd_mul_right,
cop.coprime_mul_right.coprime_mul_left_right.symm.gcd_eq_one, one_mul]
· rw [← hcd.1.1, ← hcd.2.1] at cop
rw [← hcd.2.1, h.1, mul_comm c1 d1, Nat.gcd_mul_left,
cop.coprime_mul_right.coprime_mul_left_right.symm.gcd_eq_one, mul_one]
· trans Nat.gcd (b1 * b2) (a2 * b2)
· rw [Nat.gcd_mul_right, cop.coprime_mul_left.coprime_mul_right_right.symm.gcd_eq_one,
one_mul]
· rw [← hcd.1.1, ← hcd.2.1] at cop
rw [← hcd.2.1, h.2, Nat.gcd_mul_right,
cop.coprime_mul_left.coprime_mul_right_right.symm.gcd_eq_one, one_mul]
· simp only [Set.SurjOn, Set.subset_def, mem_coe, mem_divisorsAntidiagonal, Ne, mem_product,
Set.mem_image, exists_prop, Prod.mk.inj_iff]
rintro ⟨b1, b2⟩ h
dsimp at h
use ((b1.gcd m, b2.gcd m), (b1.gcd n, b2.gcd n))
rw [← cop.gcd_mul _, ← cop.gcd_mul _, ← h.1, Nat.gcd_mul_gcd_of_coprime_of_mul_eq_mul cop h.1,
Nat.gcd_mul_gcd_of_coprime_of_mul_eq_mul cop.symm _]
· rw [Nat.mul_eq_zero, not_or] at h
simp [h.2.1, h.2.2]
rw [mul_comm n m, h.1]
· simp only [mem_divisorsAntidiagonal, Ne, mem_product]
rintro ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩
dsimp only
rw [hf.map_mul_of_coprime cop.coprime_mul_right.coprime_mul_right_right,
hg.map_mul_of_coprime cop.coprime_mul_left.coprime_mul_left_right]
ring
#align nat.arithmetic_function.is_multiplicative.mul ArithmeticFunction.IsMultiplicative.mul
@[arith_mult]
theorem pmul [CommSemiring R] {f g : ArithmeticFunction R} (hf : f.IsMultiplicative)
(hg : g.IsMultiplicative) : IsMultiplicative (f.pmul g) :=
⟨by simp [hf, hg], fun {m n} cop => by
simp only [pmul_apply, hf.map_mul_of_coprime cop, hg.map_mul_of_coprime cop]
ring⟩
#align nat.arithmetic_function.is_multiplicative.pmul ArithmeticFunction.IsMultiplicative.pmul
@[arith_mult]
theorem pdiv [CommGroupWithZero R] {f g : ArithmeticFunction R} (hf : IsMultiplicative f)
(hg : IsMultiplicative g) : IsMultiplicative (pdiv f g) :=
⟨ by simp [hf, hg], fun {m n} cop => by
simp only [pdiv_apply, map_mul_of_coprime hf cop, map_mul_of_coprime hg cop,
div_eq_mul_inv, mul_inv]
apply mul_mul_mul_comm ⟩
/-- For any multiplicative function `f` and any `n > 0`,
we can evaluate `f n` by evaluating `f` at `p ^ k` over the factorization of `n` -/
nonrec -- Porting note: added
theorem multiplicative_factorization [CommMonoidWithZero R] (f : ArithmeticFunction R)
(hf : f.IsMultiplicative) {n : ℕ} (hn : n ≠ 0) :
f n = n.factorization.prod fun p k => f (p ^ k) :=
multiplicative_factorization f (fun _ _ => hf.2) hf.1 hn
#align nat.arithmetic_function.is_multiplicative.multiplicative_factorization ArithmeticFunction.IsMultiplicative.multiplicative_factorization
/-- A recapitulation of the definition of multiplicative that is simpler for proofs -/
theorem iff_ne_zero [MonoidWithZero R] {f : ArithmeticFunction R} :
IsMultiplicative f ↔
f 1 = 1 ∧ ∀ {m n : ℕ}, m ≠ 0 → n ≠ 0 → m.Coprime n → f (m * n) = f m * f n := by
refine and_congr_right' (forall₂_congr fun m n => ⟨fun h _ _ => h, fun h hmn => ?_⟩)
rcases eq_or_ne m 0 with (rfl | hm)
· simp
rcases eq_or_ne n 0 with (rfl | hn)
· simp
exact h hm hn hmn
#align nat.arithmetic_function.is_multiplicative.iff_ne_zero ArithmeticFunction.IsMultiplicative.iff_ne_zero
/-- Two multiplicative functions `f` and `g` are equal if and only if
they agree on prime powers -/
theorem eq_iff_eq_on_prime_powers [CommMonoidWithZero R] (f : ArithmeticFunction R)
(hf : f.IsMultiplicative) (g : ArithmeticFunction R) (hg : g.IsMultiplicative) :
f = g ↔ ∀ p i : ℕ, Nat.Prime p → f (p ^ i) = g (p ^ i) := by
constructor
· intro h p i _
rw [h]
intro h
ext n
by_cases hn : n = 0
· rw [hn, ArithmeticFunction.map_zero, ArithmeticFunction.map_zero]
rw [multiplicative_factorization f hf hn, multiplicative_factorization g hg hn]
exact Finset.prod_congr rfl fun p hp ↦ h p _ (Nat.prime_of_mem_primeFactors hp)
#align nat.arithmetic_function.is_multiplicative.eq_iff_eq_on_prime_powers ArithmeticFunction.IsMultiplicative.eq_iff_eq_on_prime_powers
@[arith_mult]
theorem prodPrimeFactors [CommMonoidWithZero R] (f : ℕ → R) :
IsMultiplicative (prodPrimeFactors f) := by
rw [iff_ne_zero]
simp only [ne_eq, one_ne_zero, not_false_eq_true, prodPrimeFactors_apply, primeFactors_one,
prod_empty, true_and]
intro x y hx hy hxy
have hxy₀ : x * y ≠ 0 := mul_ne_zero hx hy
rw [prodPrimeFactors_apply hxy₀, prodPrimeFactors_apply hx, prodPrimeFactors_apply hy,
Nat.primeFactors_mul hx hy, ← Finset.prod_union hxy.disjoint_primeFactors]
theorem prodPrimeFactors_add_of_squarefree [CommSemiring R] {f g : ArithmeticFunction R}
(hf : IsMultiplicative f) (hg : IsMultiplicative g) {n : ℕ} (hn : Squarefree n) :
∏ᵖ p ∣ n, (f + g) p = (f * g) n := by
rw [prodPrimeFactors_apply hn.ne_zero]
simp_rw [add_apply (f:=f) (g:=g)]
rw [Finset.prod_add, mul_apply, sum_divisorsAntidiagonal (f · * g ·),
← divisors_filter_squarefree_of_squarefree hn, sum_divisors_filter_squarefree hn.ne_zero,
factors_eq]
apply Finset.sum_congr rfl
intro t ht
rw [t.prod_val, Function.id_def,
← prod_primeFactors_sdiff_of_squarefree hn (Finset.mem_powerset.mp ht),
hf.map_prod_of_subset_primeFactors n t (Finset.mem_powerset.mp ht),
← hg.map_prod_of_subset_primeFactors n (_ \ t) Finset.sdiff_subset]
theorem lcm_apply_mul_gcd_apply [CommMonoidWithZero R] {f : ArithmeticFunction R}
(hf : f.IsMultiplicative) {x y : ℕ} :
f (x.lcm y) * f (x.gcd y) = f x * f y := by
by_cases hx : x = 0
· simp only [hx, f.map_zero, zero_mul, Nat.lcm_zero_left, Nat.gcd_zero_left]
by_cases hy : y = 0
· simp only [hy, f.map_zero, mul_zero, Nat.lcm_zero_right, Nat.gcd_zero_right, zero_mul]
have hgcd_ne_zero : x.gcd y ≠ 0 := gcd_ne_zero_left hx
have hlcm_ne_zero : x.lcm y ≠ 0 := lcm_ne_zero hx hy
have hfi_zero : ∀ {i}, f (i ^ 0) = 1 := by
intro i; rw [Nat.pow_zero, hf.1]
iterate 4 rw [hf.multiplicative_factorization f (by assumption),
Finsupp.prod_of_support_subset _ _ _ (fun _ _ => hfi_zero)
(s := (x.primeFactors ⊔ y.primeFactors))]
· rw [← Finset.prod_mul_distrib, ← Finset.prod_mul_distrib]
apply Finset.prod_congr rfl
intro p _
rcases Nat.le_or_le (x.factorization p) (y.factorization p) with h | h <;>
simp only [factorization_lcm hx hy, ge_iff_le, Finsupp.sup_apply, h, sup_of_le_right,
sup_of_le_left, inf_of_le_right, Nat.factorization_gcd hx hy, Finsupp.inf_apply,
inf_of_le_left, mul_comm]
· apply Finset.subset_union_right
· apply Finset.subset_union_left
· rw [factorization_gcd hx hy, Finsupp.support_inf, Finset.sup_eq_union]
apply Finset.inter_subset_union
· simp [factorization_lcm hx hy]
end IsMultiplicative
section SpecialFunctions
/-- The identity on `ℕ` as an `ArithmeticFunction`. -/
nonrec -- Porting note (#11445): added
def id : ArithmeticFunction ℕ :=
⟨id, rfl⟩
#align nat.arithmetic_function.id ArithmeticFunction.id
@[simp]
theorem id_apply {x : ℕ} : id x = x :=
rfl
#align nat.arithmetic_function.id_apply ArithmeticFunction.id_apply
/-- `pow k n = n ^ k`, except `pow 0 0 = 0`. -/
def pow (k : ℕ) : ArithmeticFunction ℕ :=
id.ppow k
#align nat.arithmetic_function.pow ArithmeticFunction.pow
@[simp]
theorem pow_apply {k n : ℕ} : pow k n = if k = 0 ∧ n = 0 then 0 else n ^ k := by
cases k
· simp [pow]
rename_i k -- Porting note: added
simp [pow, k.succ_pos.ne']
#align nat.arithmetic_function.pow_apply ArithmeticFunction.pow_apply
theorem pow_zero_eq_zeta : pow 0 = ζ := by
ext n
simp
#align nat.arithmetic_function.pow_zero_eq_zeta ArithmeticFunction.pow_zero_eq_zeta
/-- `σ k n` is the sum of the `k`th powers of the divisors of `n` -/
def sigma (k : ℕ) : ArithmeticFunction ℕ :=
⟨fun n => ∑ d ∈ divisors n, d ^ k, by simp⟩
#align nat.arithmetic_function.sigma ArithmeticFunction.sigma
@[inherit_doc]
scoped[ArithmeticFunction] notation "σ" => ArithmeticFunction.sigma
@[inherit_doc]
scoped[ArithmeticFunction.sigma] notation "σ" => ArithmeticFunction.sigma
theorem sigma_apply {k n : ℕ} : σ k n = ∑ d ∈ divisors n, d ^ k :=
rfl
#align nat.arithmetic_function.sigma_apply ArithmeticFunction.sigma_apply
theorem sigma_one_apply (n : ℕ) : σ 1 n = ∑ d ∈ divisors n, d := by simp [sigma_apply]
#align nat.arithmetic_function.sigma_one_apply ArithmeticFunction.sigma_one_apply
theorem sigma_zero_apply (n : ℕ) : σ 0 n = (divisors n).card := by simp [sigma_apply]
#align nat.arithmetic_function.sigma_zero_apply ArithmeticFunction.sigma_zero_apply
theorem sigma_zero_apply_prime_pow {p i : ℕ} (hp : p.Prime) : σ 0 (p ^ i) = i + 1 := by
rw [sigma_zero_apply, divisors_prime_pow hp, card_map, card_range]
#align nat.arithmetic_function.sigma_zero_apply_prime_pow ArithmeticFunction.sigma_zero_apply_prime_pow
theorem zeta_mul_pow_eq_sigma {k : ℕ} : ζ * pow k = σ k := by
ext
rw [sigma, zeta_mul_apply]
apply sum_congr rfl
intro x hx
rw [pow_apply, if_neg (not_and_of_not_right _ _)]
contrapose! hx
simp [hx]
#align nat.arithmetic_function.zeta_mul_pow_eq_sigma ArithmeticFunction.zeta_mul_pow_eq_sigma
@[arith_mult]
theorem isMultiplicative_one [MonoidWithZero R] : IsMultiplicative (1 : ArithmeticFunction R) :=
IsMultiplicative.iff_ne_zero.2
⟨by simp, by
intro m n hm _hn hmn
rcases eq_or_ne m 1 with (rfl | hm')
· simp
rw [one_apply_ne, one_apply_ne hm', zero_mul]
rw [Ne, mul_eq_one, not_and_or]
exact Or.inl hm'⟩
#align nat.arithmetic_function.is_multiplicative_one ArithmeticFunction.isMultiplicative_one
@[arith_mult]
theorem isMultiplicative_zeta : IsMultiplicative ζ :=
IsMultiplicative.iff_ne_zero.2 ⟨by simp, by simp (config := { contextual := true })⟩
#align nat.arithmetic_function.is_multiplicative_zeta ArithmeticFunction.isMultiplicative_zeta
@[arith_mult]
theorem isMultiplicative_id : IsMultiplicative ArithmeticFunction.id :=
⟨rfl, fun {_ _} _ => rfl⟩
#align nat.arithmetic_function.is_multiplicative_id ArithmeticFunction.isMultiplicative_id
@[arith_mult]
theorem IsMultiplicative.ppow [CommSemiring R] {f : ArithmeticFunction R} (hf : f.IsMultiplicative)
{k : ℕ} : IsMultiplicative (f.ppow k) := by
induction' k with k hi
· exact isMultiplicative_zeta.natCast
· rw [ppow_succ']
apply hf.pmul hi
#align nat.arithmetic_function.is_multiplicative.ppow ArithmeticFunction.IsMultiplicative.ppow
@[arith_mult]
theorem isMultiplicative_pow {k : ℕ} : IsMultiplicative (pow k) :=
isMultiplicative_id.ppow
#align nat.arithmetic_function.is_multiplicative_pow ArithmeticFunction.isMultiplicative_pow
@[arith_mult]
theorem isMultiplicative_sigma {k : ℕ} : IsMultiplicative (σ k) := by
rw [← zeta_mul_pow_eq_sigma]
apply isMultiplicative_zeta.mul isMultiplicative_pow
#align nat.arithmetic_function.is_multiplicative_sigma ArithmeticFunction.isMultiplicative_sigma
/-- `Ω n` is the number of prime factors of `n`. -/
def cardFactors : ArithmeticFunction ℕ :=
⟨fun n => n.factors.length, by simp⟩
#align nat.arithmetic_function.card_factors ArithmeticFunction.cardFactors
@[inherit_doc]
scoped[ArithmeticFunction] notation "Ω" => ArithmeticFunction.cardFactors
@[inherit_doc]
scoped[ArithmeticFunction.Omega] notation "Ω" => ArithmeticFunction.cardFactors
theorem cardFactors_apply {n : ℕ} : Ω n = n.factors.length :=
rfl
#align nat.arithmetic_function.card_factors_apply ArithmeticFunction.cardFactors_apply
lemma cardFactors_zero : Ω 0 = 0 := by simp
@[simp] theorem cardFactors_one : Ω 1 = 0 := by simp [cardFactors_apply]
#align nat.arithmetic_function.card_factors_one ArithmeticFunction.cardFactors_one
@[simp]
theorem cardFactors_eq_one_iff_prime {n : ℕ} : Ω n = 1 ↔ n.Prime := by
refine ⟨fun h => ?_, fun h => List.length_eq_one.2 ⟨n, factors_prime h⟩⟩
cases' n with n
· simp at h
rcases List.length_eq_one.1 h with ⟨x, hx⟩
rw [← prod_factors n.add_one_ne_zero, hx, List.prod_singleton]
apply prime_of_mem_factors
rw [hx, List.mem_singleton]
#align nat.arithmetic_function.card_factors_eq_one_iff_prime ArithmeticFunction.cardFactors_eq_one_iff_prime
theorem cardFactors_mul {m n : ℕ} (m0 : m ≠ 0) (n0 : n ≠ 0) : Ω (m * n) = Ω m + Ω n := by
rw [cardFactors_apply, cardFactors_apply, cardFactors_apply, ← Multiset.coe_card, ← factors_eq,
UniqueFactorizationMonoid.normalizedFactors_mul m0 n0, factors_eq, factors_eq,
Multiset.card_add, Multiset.coe_card, Multiset.coe_card]
#align nat.arithmetic_function.card_factors_mul ArithmeticFunction.cardFactors_mul
theorem cardFactors_multiset_prod {s : Multiset ℕ} (h0 : s.prod ≠ 0) :
Ω s.prod = (Multiset.map Ω s).sum := by
induction s using Multiset.induction_on with
| empty => simp
| cons ih => simp_all [cardFactors_mul, not_or]
#align nat.arithmetic_function.card_factors_multiset_prod ArithmeticFunction.cardFactors_multiset_prod
@[simp]
theorem cardFactors_apply_prime {p : ℕ} (hp : p.Prime) : Ω p = 1 :=
cardFactors_eq_one_iff_prime.2 hp
#align nat.arithmetic_function.card_factors_apply_prime ArithmeticFunction.cardFactors_apply_prime
@[simp]
theorem cardFactors_apply_prime_pow {p k : ℕ} (hp : p.Prime) : Ω (p ^ k) = k := by
rw [cardFactors_apply, hp.factors_pow, List.length_replicate]
#align nat.arithmetic_function.card_factors_apply_prime_pow ArithmeticFunction.cardFactors_apply_prime_pow
/-- `ω n` is the number of distinct prime factors of `n`. -/
def cardDistinctFactors : ArithmeticFunction ℕ :=
⟨fun n => n.factors.dedup.length, by simp⟩
#align nat.arithmetic_function.card_distinct_factors ArithmeticFunction.cardDistinctFactors
@[inherit_doc]
scoped[ArithmeticFunction] notation "ω" => ArithmeticFunction.cardDistinctFactors
@[inherit_doc]
scoped[ArithmeticFunction.omega] notation "ω" => ArithmeticFunction.cardDistinctFactors
theorem cardDistinctFactors_zero : ω 0 = 0 := by simp
#align nat.arithmetic_function.card_distinct_factors_zero ArithmeticFunction.cardDistinctFactors_zero
@[simp]
theorem cardDistinctFactors_one : ω 1 = 0 := by simp [cardDistinctFactors]
#align nat.arithmetic_function.card_distinct_factors_one ArithmeticFunction.cardDistinctFactors_one
theorem cardDistinctFactors_apply {n : ℕ} : ω n = n.factors.dedup.length :=
rfl
#align nat.arithmetic_function.card_distinct_factors_apply ArithmeticFunction.cardDistinctFactors_apply
theorem cardDistinctFactors_eq_cardFactors_iff_squarefree {n : ℕ} (h0 : n ≠ 0) :
ω n = Ω n ↔ Squarefree n := by
rw [squarefree_iff_nodup_factors h0, cardDistinctFactors_apply]
constructor <;> intro h
· rw [← n.factors.dedup_sublist.eq_of_length h]
apply List.nodup_dedup
· rw [h.dedup]
rfl
#align nat.arithmetic_function.card_distinct_factors_eq_card_factors_iff_squarefree ArithmeticFunction.cardDistinctFactors_eq_cardFactors_iff_squarefree
@[simp]
theorem cardDistinctFactors_apply_prime_pow {p k : ℕ} (hp : p.Prime) (hk : k ≠ 0) :
ω (p ^ k) = 1 := by
rw [cardDistinctFactors_apply, hp.factors_pow, List.replicate_dedup hk, List.length_singleton]
#align nat.arithmetic_function.card_distinct_factors_apply_prime_pow ArithmeticFunction.cardDistinctFactors_apply_prime_pow
@[simp]
theorem cardDistinctFactors_apply_prime {p : ℕ} (hp : p.Prime) : ω p = 1 := by
rw [← pow_one p, cardDistinctFactors_apply_prime_pow hp one_ne_zero]
#align nat.arithmetic_function.card_distinct_factors_apply_prime ArithmeticFunction.cardDistinctFactors_apply_prime
/-- `μ` is the Möbius function. If `n` is squarefree with an even number of distinct prime factors,
`μ n = 1`. If `n` is squarefree with an odd number of distinct prime factors, `μ n = -1`.
If `n` is not squarefree, `μ n = 0`. -/
def moebius : ArithmeticFunction ℤ :=
⟨fun n => if Squarefree n then (-1) ^ cardFactors n else 0, by simp⟩
#align nat.arithmetic_function.moebius ArithmeticFunction.moebius
@[inherit_doc]
scoped[ArithmeticFunction] notation "μ" => ArithmeticFunction.moebius
@[inherit_doc]
scoped[ArithmeticFunction.Moebius] notation "μ" => ArithmeticFunction.moebius
@[simp]
theorem moebius_apply_of_squarefree {n : ℕ} (h : Squarefree n) : μ n = (-1) ^ cardFactors n :=
if_pos h
#align nat.arithmetic_function.moebius_apply_of_squarefree ArithmeticFunction.moebius_apply_of_squarefree
@[simp]
theorem moebius_eq_zero_of_not_squarefree {n : ℕ} (h : ¬Squarefree n) : μ n = 0 :=
if_neg h
#align nat.arithmetic_function.moebius_eq_zero_of_not_squarefree ArithmeticFunction.moebius_eq_zero_of_not_squarefree
theorem moebius_apply_one : μ 1 = 1 := by simp
#align nat.arithmetic_function.moebius_apply_one ArithmeticFunction.moebius_apply_one
theorem moebius_ne_zero_iff_squarefree {n : ℕ} : μ n ≠ 0 ↔ Squarefree n := by
constructor <;> intro h
· contrapose! h
simp [h]
· simp [h, pow_ne_zero]
#align nat.arithmetic_function.moebius_ne_zero_iff_squarefree ArithmeticFunction.moebius_ne_zero_iff_squarefree
theorem moebius_eq_or (n : ℕ) : μ n = 0 ∨ μ n = 1 ∨ μ n = -1 := by
simp only [moebius, coe_mk]
split_ifs
· right
exact neg_one_pow_eq_or ..
· left
rfl
theorem moebius_ne_zero_iff_eq_or {n : ℕ} : μ n ≠ 0 ↔ μ n = 1 ∨ μ n = -1 := by
have := moebius_eq_or n
aesop
#align nat.arithmetic_function.moebius_ne_zero_iff_eq_or ArithmeticFunction.moebius_ne_zero_iff_eq_or
theorem moebius_sq_eq_one_of_squarefree {l : ℕ} (hl : Squarefree l) : μ l ^ 2 = 1 := by
rw [moebius_apply_of_squarefree hl, ← pow_mul, mul_comm, pow_mul, neg_one_sq, one_pow]
theorem abs_moebius_eq_one_of_squarefree {l : ℕ} (hl : Squarefree l) : |μ l| = 1 := by
simp only [moebius_apply_of_squarefree hl, abs_pow, abs_neg, abs_one, one_pow]
theorem moebius_sq {n : ℕ} :
μ n ^ 2 = if Squarefree n then 1 else 0 := by
split_ifs with h
· exact moebius_sq_eq_one_of_squarefree h
· simp only [pow_eq_zero_iff, moebius_eq_zero_of_not_squarefree h,
zero_pow (show 2 ≠ 0 by norm_num)]
theorem abs_moebius {n : ℕ} :
|μ n| = if Squarefree n then 1 else 0 := by
split_ifs with h
· exact abs_moebius_eq_one_of_squarefree h
· simp only [moebius_eq_zero_of_not_squarefree h, abs_zero]
theorem abs_moebius_le_one {n : ℕ} : |μ n| ≤ 1 := by
rw [abs_moebius, apply_ite (· ≤ 1)]
simp
theorem moebius_apply_prime {p : ℕ} (hp : p.Prime) : μ p = -1 := by
rw [moebius_apply_of_squarefree hp.squarefree, cardFactors_apply_prime hp, pow_one]
#align nat.arithmetic_function.moebius_apply_prime ArithmeticFunction.moebius_apply_prime
theorem moebius_apply_prime_pow {p k : ℕ} (hp : p.Prime) (hk : k ≠ 0) :
μ (p ^ k) = if k = 1 then -1 else 0 := by
split_ifs with h
· rw [h, pow_one, moebius_apply_prime hp]
rw [moebius_eq_zero_of_not_squarefree]
rw [squarefree_pow_iff hp.ne_one hk, not_and_or]
exact Or.inr h
#align nat.arithmetic_function.moebius_apply_prime_pow ArithmeticFunction.moebius_apply_prime_pow
theorem moebius_apply_isPrimePow_not_prime {n : ℕ} (hn : IsPrimePow n) (hn' : ¬n.Prime) :
μ n = 0 := by
obtain ⟨p, k, hp, hk, rfl⟩ := (isPrimePow_nat_iff _).1 hn
rw [moebius_apply_prime_pow hp hk.ne', if_neg]
rintro rfl
exact hn' (by simpa)
#align nat.arithmetic_function.moebius_apply_is_prime_pow_not_prime ArithmeticFunction.moebius_apply_isPrimePow_not_prime
@[arith_mult]
theorem isMultiplicative_moebius : IsMultiplicative μ := by
rw [IsMultiplicative.iff_ne_zero]
refine ⟨by simp, fun {n m} hn hm hnm => ?_⟩
simp only [moebius, ZeroHom.coe_mk, coe_mk, ZeroHom.toFun_eq_coe, Eq.ndrec, ZeroHom.coe_mk,
IsUnit.mul_iff, Nat.isUnit_iff, squarefree_mul hnm, ite_zero_mul_ite_zero,
cardFactors_mul hn hm, pow_add]
#align nat.arithmetic_function.is_multiplicative_moebius ArithmeticFunction.isMultiplicative_moebius
theorem IsMultiplicative.prodPrimeFactors_one_add_of_squarefree [CommSemiring R]
{f : ArithmeticFunction R} (h_mult : f.IsMultiplicative) {n : ℕ} (hn : Squarefree n) :
∏ p ∈ n.primeFactors, (1 + f p) = ∑ d ∈ n.divisors, f d := by
trans (∏ᵖ p ∣ n, ((ζ:ArithmeticFunction R) + f) p)
· simp_rw [prodPrimeFactors_apply hn.ne_zero, add_apply, natCoe_apply]
apply Finset.prod_congr rfl; intro p hp;
rw [zeta_apply_ne (prime_of_mem_factors <| List.mem_toFinset.mp hp).ne_zero, cast_one]
rw [isMultiplicative_zeta.natCast.prodPrimeFactors_add_of_squarefree h_mult hn,
coe_zeta_mul_apply]
theorem IsMultiplicative.prodPrimeFactors_one_sub_of_squarefree [CommRing R]
(f : ArithmeticFunction R) (hf : f.IsMultiplicative) {n : ℕ} (hn : Squarefree n) :
∏ p ∈ n.primeFactors, (1 - f p) = ∑ d ∈ n.divisors, μ d * f d := by
trans (∏ p ∈ n.primeFactors, (1 + (ArithmeticFunction.pmul (μ:ArithmeticFunction R) f) p))
· apply Finset.prod_congr rfl; intro p hp
rw [pmul_apply, intCoe_apply, ArithmeticFunction.moebius_apply_prime
(prime_of_mem_factors (List.mem_toFinset.mp hp))]
ring
· rw [(isMultiplicative_moebius.intCast.pmul hf).prodPrimeFactors_one_add_of_squarefree hn]
simp_rw [pmul_apply, intCoe_apply]
open UniqueFactorizationMonoid
@[simp]
theorem moebius_mul_coe_zeta : (μ * ζ : ArithmeticFunction ℤ) = 1 := by
ext n
refine recOnPosPrimePosCoprime ?_ ?_ ?_ ?_ n
· intro p n hp hn
rw [coe_mul_zeta_apply, sum_divisors_prime_pow hp, sum_range_succ']
simp_rw [Nat.pow_zero, moebius_apply_one,
moebius_apply_prime_pow hp (Nat.succ_ne_zero _), Nat.succ_inj', sum_ite_eq', mem_range,
if_pos hn, add_left_neg]
rw [one_apply_ne]
rw [Ne, pow_eq_one_iff]
· exact hp.ne_one
· exact hn.ne'
· rw [ZeroHom.map_zero, ZeroHom.map_zero]
· simp
· intro a b _ha _hb hab ha' hb'
rw [IsMultiplicative.map_mul_of_coprime _ hab, ha', hb',
IsMultiplicative.map_mul_of_coprime isMultiplicative_one hab]
exact isMultiplicative_moebius.mul isMultiplicative_zeta.natCast
#align nat.arithmetic_function.moebius_mul_coe_zeta ArithmeticFunction.moebius_mul_coe_zeta
@[simp]
theorem coe_zeta_mul_moebius : (ζ * μ : ArithmeticFunction ℤ) = 1 := by
rw [mul_comm, moebius_mul_coe_zeta]
#align nat.arithmetic_function.coe_zeta_mul_moebius ArithmeticFunction.coe_zeta_mul_moebius
@[simp]
theorem coe_moebius_mul_coe_zeta [Ring R] : (μ * ζ : ArithmeticFunction R) = 1 := by
rw [← coe_coe, ← intCoe_mul, moebius_mul_coe_zeta, intCoe_one]
#align nat.arithmetic_function.coe_moebius_mul_coe_zeta ArithmeticFunction.coe_moebius_mul_coe_zeta
@[simp]
theorem coe_zeta_mul_coe_moebius [Ring R] : (ζ * μ : ArithmeticFunction R) = 1 := by
rw [← coe_coe, ← intCoe_mul, coe_zeta_mul_moebius, intCoe_one]
#align nat.arithmetic_function.coe_zeta_mul_coe_moebius ArithmeticFunction.coe_zeta_mul_coe_moebius
section CommRing
variable [CommRing R]
instance : Invertible (ζ : ArithmeticFunction R) where
invOf := μ
invOf_mul_self := coe_moebius_mul_coe_zeta
mul_invOf_self := coe_zeta_mul_coe_moebius
/-- A unit in `ArithmeticFunction R` that evaluates to `ζ`, with inverse `μ`. -/
def zetaUnit : (ArithmeticFunction R)ˣ :=
⟨ζ, μ, coe_zeta_mul_coe_moebius, coe_moebius_mul_coe_zeta⟩
#align nat.arithmetic_function.zeta_unit ArithmeticFunction.zetaUnit
@[simp]
theorem coe_zetaUnit : ((zetaUnit : (ArithmeticFunction R)ˣ) : ArithmeticFunction R) = ζ :=
rfl
#align nat.arithmetic_function.coe_zeta_unit ArithmeticFunction.coe_zetaUnit
@[simp]
theorem inv_zetaUnit : ((zetaUnit⁻¹ : (ArithmeticFunction R)ˣ) : ArithmeticFunction R) = μ :=
rfl
#align nat.arithmetic_function.inv_zeta_unit ArithmeticFunction.inv_zetaUnit
end CommRing
/-- Möbius inversion for functions to an `AddCommGroup`. -/
theorem sum_eq_iff_sum_smul_moebius_eq [AddCommGroup R] {f g : ℕ → R} :
(∀ n > 0, ∑ i ∈ n.divisors, f i = g n) ↔
∀ n > 0, ∑ x ∈ n.divisorsAntidiagonal, μ x.fst • g x.snd = f n := by
let f' : ArithmeticFunction R := ⟨fun x => if x = 0 then 0 else f x, if_pos rfl⟩
let g' : ArithmeticFunction R := ⟨fun x => if x = 0 then 0 else g x, if_pos rfl⟩
trans (ζ : ArithmeticFunction ℤ) • f' = g'
· rw [ext_iff]
apply forall_congr'
intro n
cases n with
| zero => simp
| succ n =>
rw [coe_zeta_smul_apply]
simp only [n.succ_ne_zero, forall_prop_of_true, succ_pos', if_false, ZeroHom.coe_mk]
simp only [f', g', coe_mk, succ_ne_zero, ite_false]
rw [sum_congr rfl fun x hx => ?_]
rw [if_neg (Nat.pos_of_mem_divisors hx).ne']
trans μ • g' = f'
· constructor <;> intro h
· rw [← h, ← mul_smul, moebius_mul_coe_zeta, one_smul]
· rw [← h, ← mul_smul, coe_zeta_mul_moebius, one_smul]
· rw [ext_iff]
apply forall_congr'
intro n
cases n with
| zero => simp
| succ n =>
simp only [n.succ_ne_zero, forall_prop_of_true, succ_pos', smul_apply, if_false,
ZeroHom.coe_mk]
-- Porting note: added following `simp only`
simp only [f', g', Nat.isUnit_iff, coe_mk, ZeroHom.toFun_eq_coe, succ_ne_zero, ite_false]
rw [sum_congr rfl fun x hx => ?_]
rw [if_neg (Nat.pos_of_mem_divisors (snd_mem_divisors_of_mem_antidiagonal hx)).ne']
#align nat.arithmetic_function.sum_eq_iff_sum_smul_moebius_eq ArithmeticFunction.sum_eq_iff_sum_smul_moebius_eq
/-- Möbius inversion for functions to a `Ring`. -/
theorem sum_eq_iff_sum_mul_moebius_eq [Ring R] {f g : ℕ → R} :
(∀ n > 0, ∑ i ∈ n.divisors, f i = g n) ↔
∀ n > 0, ∑ x ∈ n.divisorsAntidiagonal, (μ x.fst : R) * g x.snd = f n := by
rw [sum_eq_iff_sum_smul_moebius_eq]
apply forall_congr'
refine fun a => imp_congr_right fun _ => (sum_congr rfl fun x _hx => ?_).congr_left
rw [zsmul_eq_mul]
#align nat.arithmetic_function.sum_eq_iff_sum_mul_moebius_eq ArithmeticFunction.sum_eq_iff_sum_mul_moebius_eq
/-- Möbius inversion for functions to a `CommGroup`. -/
theorem prod_eq_iff_prod_pow_moebius_eq [CommGroup R] {f g : ℕ → R} :
(∀ n > 0, ∏ i ∈ n.divisors, f i = g n) ↔
∀ n > 0, ∏ x ∈ n.divisorsAntidiagonal, g x.snd ^ μ x.fst = f n :=
@sum_eq_iff_sum_smul_moebius_eq (Additive R) _ _ _
#align nat.arithmetic_function.prod_eq_iff_prod_pow_moebius_eq ArithmeticFunction.prod_eq_iff_prod_pow_moebius_eq
/-- Möbius inversion for functions to a `CommGroupWithZero`. -/
theorem prod_eq_iff_prod_pow_moebius_eq_of_nonzero [CommGroupWithZero R] {f g : ℕ → R}
(hf : ∀ n : ℕ, 0 < n → f n ≠ 0) (hg : ∀ n : ℕ, 0 < n → g n ≠ 0) :
(∀ n > 0, ∏ i ∈ n.divisors, f i = g n) ↔
∀ n > 0, ∏ x ∈ n.divisorsAntidiagonal, g x.snd ^ μ x.fst = f n := by
refine
Iff.trans
(Iff.trans (forall_congr' fun n => ?_)
(@prod_eq_iff_prod_pow_moebius_eq Rˣ _
(fun n => if h : 0 < n then Units.mk0 (f n) (hf n h) else 1) fun n =>
if h : 0 < n then Units.mk0 (g n) (hg n h) else 1))
(forall_congr' fun n => ?_) <;>
refine imp_congr_right fun hn => ?_
· dsimp
rw [dif_pos hn, ← Units.eq_iff, ← Units.coeHom_apply, map_prod, Units.val_mk0,
prod_congr rfl _]
intro x hx
rw [dif_pos (Nat.pos_of_mem_divisors hx), Units.coeHom_apply, Units.val_mk0]
· dsimp
rw [dif_pos hn, ← Units.eq_iff, ← Units.coeHom_apply, map_prod, Units.val_mk0,
prod_congr rfl _]
intro x hx
rw [dif_pos (Nat.pos_of_mem_divisors (Nat.snd_mem_divisors_of_mem_antidiagonal hx)),
Units.coeHom_apply, Units.val_zpow_eq_zpow_val, Units.val_mk0]
#align nat.arithmetic_function.prod_eq_iff_prod_pow_moebius_eq_of_nonzero ArithmeticFunction.prod_eq_iff_prod_pow_moebius_eq_of_nonzero
/-- Möbius inversion for functions to an `AddCommGroup`, where the equalities only hold on a
well-behaved set. -/
theorem sum_eq_iff_sum_smul_moebius_eq_on [AddCommGroup R] {f g : ℕ → R}
(s : Set ℕ) (hs : ∀ m n, m ∣ n → n ∈ s → m ∈ s) :
(∀ n > 0, n ∈ s → (∑ i ∈ n.divisors, f i) = g n) ↔
∀ n > 0, n ∈ s → (∑ x ∈ n.divisorsAntidiagonal, μ x.fst • g x.snd) = f n := by
constructor
· intro h
let G := fun (n:ℕ) => (∑ i ∈ n.divisors, f i)
intro n hn hnP
suffices ∑ d ∈ n.divisors, μ (n/d) • G d = f n from by
rw [Nat.sum_divisorsAntidiagonal' (f := fun x y => μ x • g y), ← this, sum_congr rfl]
intro d hd
rw [← h d (Nat.pos_of_mem_divisors hd) <| hs d n (Nat.dvd_of_mem_divisors hd) hnP]
rw [← Nat.sum_divisorsAntidiagonal' (f := fun x y => μ x • G y)]
apply sum_eq_iff_sum_smul_moebius_eq.mp _ n hn
intro _ _; rfl
· intro h
let F := fun (n:ℕ) => ∑ x ∈ n.divisorsAntidiagonal, μ x.fst • g x.snd
intro n hn hnP
suffices ∑ d ∈ n.divisors, F d = g n from by
rw [← this, sum_congr rfl]
intro d hd
rw [← h d (Nat.pos_of_mem_divisors hd) <| hs d n (Nat.dvd_of_mem_divisors hd) hnP]
apply sum_eq_iff_sum_smul_moebius_eq.mpr _ n hn
intro _ _; rfl
theorem sum_eq_iff_sum_smul_moebius_eq_on' [AddCommGroup R] {f g : ℕ → R}
(s : Set ℕ) (hs : ∀ m n, m ∣ n → n ∈ s → m ∈ s) (hs₀ : 0 ∉ s) :
(∀ n ∈ s, (∑ i ∈ n.divisors, f i) = g n) ↔
∀ n ∈ s, (∑ x ∈ n.divisorsAntidiagonal, μ x.fst • g x.snd) = f n := by
have : ∀ P : ℕ → Prop, ((∀ n ∈ s, P n) ↔ (∀ n > 0, n ∈ s → P n)) := fun P ↦ by
refine forall_congr' (fun n ↦ ⟨fun h _ ↦ h, fun h hn ↦ h ?_ hn⟩)
contrapose! hs₀
simpa [nonpos_iff_eq_zero.mp hs₀] using hn
simpa only [this] using sum_eq_iff_sum_smul_moebius_eq_on s hs
/-- Möbius inversion for functions to a `Ring`, where the equalities only hold on a well-behaved
set. -/
| Mathlib/NumberTheory/ArithmeticFunction.lean | 1,349 | 1,358 | theorem sum_eq_iff_sum_mul_moebius_eq_on [Ring R] {f g : ℕ → R}
(s : Set ℕ) (hs : ∀ m n, m ∣ n → n ∈ s → m ∈ s) :
(∀ n > 0, n ∈ s → (∑ i ∈ n.divisors, f i) = g n) ↔
∀ n > 0, n ∈ s →
(∑ x ∈ n.divisorsAntidiagonal, (μ x.fst : R) * g x.snd) = f n := by |
rw [sum_eq_iff_sum_smul_moebius_eq_on s hs]
apply forall_congr'
intro a; refine imp_congr_right ?_
refine fun _ => imp_congr_right fun _ => (sum_congr rfl fun x _hx => ?_).congr_left
rw [zsmul_eq_mul]
|
/-
Copyright (c) 2023 Peter Nelson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Peter Nelson
-/
import Mathlib.SetTheory.Cardinal.Finite
#align_import data.set.ncard from "leanprover-community/mathlib"@"74c2af38a828107941029b03839882c5c6f87a04"
/-!
# Noncomputable Set Cardinality
We define the cardinality of set `s` as a term `Set.encard s : ℕ∞` and a term `Set.ncard s : ℕ`.
The latter takes the junk value of zero if `s` is infinite. Both functions are noncomputable, and
are defined in terms of `PartENat.card` (which takes a type as its argument); this file can be seen
as an API for the same function in the special case where the type is a coercion of a `Set`,
allowing for smoother interactions with the `Set` API.
`Set.encard` never takes junk values, so is more mathematically natural than `Set.ncard`, even
though it takes values in a less convenient type. It is probably the right choice in settings where
one is concerned with the cardinalities of sets that may or may not be infinite.
`Set.ncard` has a nicer codomain, but when using it, `Set.Finite` hypotheses are normally needed to
make sure its values are meaningful. More generally, `Set.ncard` is intended to be used over the
obvious alternative `Finset.card` when finiteness is 'propositional' rather than 'structural'.
When working with sets that are finite by virtue of their definition, then `Finset.card` probably
makes more sense. One setting where `Set.ncard` works nicely is in a type `α` with `[Finite α]`,
where every set is automatically finite. In this setting, we use default arguments and a simple
tactic so that finiteness goals are discharged automatically in `Set.ncard` theorems.
## Main Definitions
* `Set.encard s` is the cardinality of the set `s` as an extended natural number, with value `⊤` if
`s` is infinite.
* `Set.ncard s` is the cardinality of the set `s` as a natural number, provided `s` is Finite.
If `s` is Infinite, then `Set.ncard s = 0`.
* `toFinite_tac` is a tactic that tries to synthesize a `Set.Finite s` argument with
`Set.toFinite`. This will work for `s : Set α` where there is a `Finite α` instance.
## Implementation Notes
The theorems in this file are very similar to those in `Data.Finset.Card`, but with `Set` operations
instead of `Finset`. We first prove all the theorems for `Set.encard`, and then derive most of the
`Set.ncard` results as a consequence. Things are done this way to avoid reliance on the `Finset` API
for theorems about infinite sets, and to allow for a refactor that removes or modifies `Set.ncard`
in the future.
Nearly all the theorems for `Set.ncard` require finiteness of one or more of their arguments. We
provide this assumption with a default argument of the form `(hs : s.Finite := by toFinite_tac)`,
where `toFinite_tac` will find an `s.Finite` term in the cases where `s` is a set in a `Finite`
type.
Often, where there are two set arguments `s` and `t`, the finiteness of one follows from the other
in the context of the theorem, in which case we only include the ones that are needed, and derive
the other inside the proof. A few of the theorems, such as `ncard_union_le` do not require
finiteness arguments; they are true by coincidence due to junk values.
-/
namespace Set
variable {α β : Type*} {s t : Set α}
/-- The cardinality of a set as a term in `ℕ∞` -/
noncomputable def encard (s : Set α) : ℕ∞ := PartENat.withTopEquiv (PartENat.card s)
@[simp] theorem encard_univ_coe (s : Set α) : encard (univ : Set s) = encard s := by
rw [encard, encard, PartENat.card_congr (Equiv.Set.univ ↑s)]
theorem encard_univ (α : Type*) :
encard (univ : Set α) = PartENat.withTopEquiv (PartENat.card α) := by
rw [encard, PartENat.card_congr (Equiv.Set.univ α)]
theorem Finite.encard_eq_coe_toFinset_card (h : s.Finite) : s.encard = h.toFinset.card := by
have := h.fintype
rw [encard, PartENat.card_eq_coe_fintype_card,
PartENat.withTopEquiv_natCast, toFinite_toFinset, toFinset_card]
theorem encard_eq_coe_toFinset_card (s : Set α) [Fintype s] : encard s = s.toFinset.card := by
have h := toFinite s
rw [h.encard_eq_coe_toFinset_card, toFinite_toFinset]
theorem encard_coe_eq_coe_finsetCard (s : Finset α) : encard (s : Set α) = s.card := by
rw [Finite.encard_eq_coe_toFinset_card (Finset.finite_toSet s)]; simp
theorem Infinite.encard_eq {s : Set α} (h : s.Infinite) : s.encard = ⊤ := by
have := h.to_subtype
rw [encard, ← PartENat.withTopEquiv.symm.injective.eq_iff, Equiv.symm_apply_apply,
PartENat.withTopEquiv_symm_top, PartENat.card_eq_top_of_infinite]
@[simp] theorem encard_eq_zero : s.encard = 0 ↔ s = ∅ := by
rw [encard, ← PartENat.withTopEquiv.symm.injective.eq_iff, Equiv.symm_apply_apply,
PartENat.withTopEquiv_symm_zero, PartENat.card_eq_zero_iff_empty, isEmpty_subtype,
eq_empty_iff_forall_not_mem]
@[simp] theorem encard_empty : (∅ : Set α).encard = 0 := by
rw [encard_eq_zero]
theorem nonempty_of_encard_ne_zero (h : s.encard ≠ 0) : s.Nonempty := by
rwa [nonempty_iff_ne_empty, Ne, ← encard_eq_zero]
theorem encard_ne_zero : s.encard ≠ 0 ↔ s.Nonempty := by
rw [ne_eq, encard_eq_zero, nonempty_iff_ne_empty]
@[simp] theorem encard_pos : 0 < s.encard ↔ s.Nonempty := by
rw [pos_iff_ne_zero, encard_ne_zero]
@[simp] theorem encard_singleton (e : α) : ({e} : Set α).encard = 1 := by
rw [encard, ← PartENat.withTopEquiv.symm.injective.eq_iff, Equiv.symm_apply_apply,
PartENat.card_eq_coe_fintype_card, Fintype.card_ofSubsingleton, Nat.cast_one]; rfl
theorem encard_union_eq (h : Disjoint s t) : (s ∪ t).encard = s.encard + t.encard := by
classical
have e := (Equiv.Set.union (by rwa [subset_empty_iff, ← disjoint_iff_inter_eq_empty])).symm
simp [encard, ← PartENat.card_congr e, PartENat.card_sum, PartENat.withTopEquiv]
theorem encard_insert_of_not_mem {a : α} (has : a ∉ s) : (insert a s).encard = s.encard + 1 := by
rw [← union_singleton, encard_union_eq (by simpa), encard_singleton]
theorem Finite.encard_lt_top (h : s.Finite) : s.encard < ⊤ := by
refine h.induction_on (by simp) ?_
rintro a t hat _ ht'
rw [encard_insert_of_not_mem hat]
exact lt_tsub_iff_right.1 ht'
theorem Finite.encard_eq_coe (h : s.Finite) : s.encard = ENat.toNat s.encard :=
(ENat.coe_toNat h.encard_lt_top.ne).symm
theorem Finite.exists_encard_eq_coe (h : s.Finite) : ∃ (n : ℕ), s.encard = n :=
⟨_, h.encard_eq_coe⟩
@[simp] theorem encard_lt_top_iff : s.encard < ⊤ ↔ s.Finite :=
⟨fun h ↦ by_contra fun h' ↦ h.ne (Infinite.encard_eq h'), Finite.encard_lt_top⟩
@[simp] theorem encard_eq_top_iff : s.encard = ⊤ ↔ s.Infinite := by
rw [← not_iff_not, ← Ne, ← lt_top_iff_ne_top, encard_lt_top_iff, not_infinite]
theorem encard_ne_top_iff : s.encard ≠ ⊤ ↔ s.Finite := by
simp
theorem finite_of_encard_le_coe {k : ℕ} (h : s.encard ≤ k) : s.Finite := by
rw [← encard_lt_top_iff]; exact h.trans_lt (WithTop.coe_lt_top _)
theorem finite_of_encard_eq_coe {k : ℕ} (h : s.encard = k) : s.Finite :=
finite_of_encard_le_coe h.le
theorem encard_le_coe_iff {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ ∃ (n₀ : ℕ), s.encard = n₀ ∧ n₀ ≤ k :=
⟨fun h ↦ ⟨finite_of_encard_le_coe h, by rwa [ENat.le_coe_iff] at h⟩,
fun ⟨_,⟨n₀,hs, hle⟩⟩ ↦ by rwa [hs, Nat.cast_le]⟩
section Lattice
theorem encard_le_card (h : s ⊆ t) : s.encard ≤ t.encard := by
rw [← union_diff_cancel h, encard_union_eq disjoint_sdiff_right]; exact le_self_add
theorem encard_mono {α : Type*} : Monotone (encard : Set α → ℕ∞) :=
fun _ _ ↦ encard_le_card
theorem encard_diff_add_encard_of_subset (h : s ⊆ t) : (t \ s).encard + s.encard = t.encard := by
rw [← encard_union_eq disjoint_sdiff_left, diff_union_self, union_eq_self_of_subset_right h]
@[simp] theorem one_le_encard_iff_nonempty : 1 ≤ s.encard ↔ s.Nonempty := by
rw [nonempty_iff_ne_empty, Ne, ← encard_eq_zero, ENat.one_le_iff_ne_zero]
theorem encard_diff_add_encard_inter (s t : Set α) :
(s \ t).encard + (s ∩ t).encard = s.encard := by
rw [← encard_union_eq (disjoint_of_subset_right inter_subset_right disjoint_sdiff_left),
diff_union_inter]
theorem encard_union_add_encard_inter (s t : Set α) :
(s ∪ t).encard + (s ∩ t).encard = s.encard + t.encard := by
rw [← diff_union_self, encard_union_eq disjoint_sdiff_left, add_right_comm,
encard_diff_add_encard_inter]
theorem encard_eq_encard_iff_encard_diff_eq_encard_diff (h : (s ∩ t).Finite) :
s.encard = t.encard ↔ (s \ t).encard = (t \ s).encard := by
rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s,
WithTop.add_right_cancel_iff h.encard_lt_top.ne]
theorem encard_le_encard_iff_encard_diff_le_encard_diff (h : (s ∩ t).Finite) :
s.encard ≤ t.encard ↔ (s \ t).encard ≤ (t \ s).encard := by
rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s,
WithTop.add_le_add_iff_right h.encard_lt_top.ne]
theorem encard_lt_encard_iff_encard_diff_lt_encard_diff (h : (s ∩ t).Finite) :
s.encard < t.encard ↔ (s \ t).encard < (t \ s).encard := by
rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s,
WithTop.add_lt_add_iff_right h.encard_lt_top.ne]
theorem encard_union_le (s t : Set α) : (s ∪ t).encard ≤ s.encard + t.encard := by
rw [← encard_union_add_encard_inter]; exact le_self_add
theorem finite_iff_finite_of_encard_eq_encard (h : s.encard = t.encard) : s.Finite ↔ t.Finite := by
rw [← encard_lt_top_iff, ← encard_lt_top_iff, h]
theorem infinite_iff_infinite_of_encard_eq_encard (h : s.encard = t.encard) :
s.Infinite ↔ t.Infinite := by rw [← encard_eq_top_iff, h, encard_eq_top_iff]
theorem Finite.finite_of_encard_le {s : Set α} {t : Set β} (hs : s.Finite)
(h : t.encard ≤ s.encard) : t.Finite :=
encard_lt_top_iff.1 (h.trans_lt hs.encard_lt_top)
theorem Finite.eq_of_subset_of_encard_le (ht : t.Finite) (hst : s ⊆ t) (hts : t.encard ≤ s.encard) :
s = t := by
rw [← zero_add (a := encard s), ← encard_diff_add_encard_of_subset hst] at hts
have hdiff := WithTop.le_of_add_le_add_right (ht.subset hst).encard_lt_top.ne hts
rw [nonpos_iff_eq_zero, encard_eq_zero, diff_eq_empty] at hdiff
exact hst.antisymm hdiff
theorem Finite.eq_of_subset_of_encard_le' (hs : s.Finite) (hst : s ⊆ t)
(hts : t.encard ≤ s.encard) : s = t :=
(hs.finite_of_encard_le hts).eq_of_subset_of_encard_le hst hts
theorem Finite.encard_lt_encard (ht : t.Finite) (h : s ⊂ t) : s.encard < t.encard :=
(encard_mono h.subset).lt_of_ne (fun he ↦ h.ne (ht.eq_of_subset_of_encard_le h.subset he.symm.le))
theorem encard_strictMono [Finite α] : StrictMono (encard : Set α → ℕ∞) :=
fun _ _ h ↦ (toFinite _).encard_lt_encard h
theorem encard_diff_add_encard (s t : Set α) : (s \ t).encard + t.encard = (s ∪ t).encard := by
rw [← encard_union_eq disjoint_sdiff_left, diff_union_self]
theorem encard_le_encard_diff_add_encard (s t : Set α) : s.encard ≤ (s \ t).encard + t.encard :=
(encard_mono subset_union_left).trans_eq (encard_diff_add_encard _ _).symm
theorem tsub_encard_le_encard_diff (s t : Set α) : s.encard - t.encard ≤ (s \ t).encard := by
rw [tsub_le_iff_left, add_comm]; apply encard_le_encard_diff_add_encard
theorem encard_add_encard_compl (s : Set α) : s.encard + sᶜ.encard = (univ : Set α).encard := by
rw [← encard_union_eq disjoint_compl_right, union_compl_self]
end Lattice
section InsertErase
variable {a b : α}
theorem encard_insert_le (s : Set α) (x : α) : (insert x s).encard ≤ s.encard + 1 := by
rw [← union_singleton, ← encard_singleton x]; apply encard_union_le
theorem encard_singleton_inter (s : Set α) (x : α) : ({x} ∩ s).encard ≤ 1 := by
rw [← encard_singleton x]; exact encard_le_card inter_subset_left
theorem encard_diff_singleton_add_one (h : a ∈ s) :
(s \ {a}).encard + 1 = s.encard := by
rw [← encard_insert_of_not_mem (fun h ↦ h.2 rfl), insert_diff_singleton, insert_eq_of_mem h]
theorem encard_diff_singleton_of_mem (h : a ∈ s) :
(s \ {a}).encard = s.encard - 1 := by
rw [← encard_diff_singleton_add_one h, ← WithTop.add_right_cancel_iff WithTop.one_ne_top,
tsub_add_cancel_of_le (self_le_add_left _ _)]
theorem encard_tsub_one_le_encard_diff_singleton (s : Set α) (x : α) :
s.encard - 1 ≤ (s \ {x}).encard := by
rw [← encard_singleton x]; apply tsub_encard_le_encard_diff
theorem encard_exchange (ha : a ∉ s) (hb : b ∈ s) : (insert a (s \ {b})).encard = s.encard := by
rw [encard_insert_of_not_mem, encard_diff_singleton_add_one hb]
simp_all only [not_true, mem_diff, mem_singleton_iff, false_and, not_false_eq_true]
theorem encard_exchange' (ha : a ∉ s) (hb : b ∈ s) : (insert a s \ {b}).encard = s.encard := by
rw [← insert_diff_singleton_comm (by rintro rfl; exact ha hb), encard_exchange ha hb]
theorem encard_eq_add_one_iff {k : ℕ∞} :
s.encard = k + 1 ↔ (∃ a t, ¬a ∈ t ∧ insert a t = s ∧ t.encard = k) := by
refine ⟨fun h ↦ ?_, ?_⟩
· obtain ⟨a, ha⟩ := nonempty_of_encard_ne_zero (s := s) (by simp [h])
refine ⟨a, s \ {a}, fun h ↦ h.2 rfl, by rwa [insert_diff_singleton, insert_eq_of_mem], ?_⟩
rw [← WithTop.add_right_cancel_iff WithTop.one_ne_top, ← h,
encard_diff_singleton_add_one ha]
rintro ⟨a, t, h, rfl, rfl⟩
rw [encard_insert_of_not_mem h]
/-- Every set is either empty, infinite, or can have its `encard` reduced by a removal. Intended
for well-founded induction on the value of `encard`. -/
theorem eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt (s : Set α) :
s = ∅ ∨ s.encard = ⊤ ∨ ∃ a ∈ s, (s \ {a}).encard < s.encard := by
refine s.eq_empty_or_nonempty.elim Or.inl (Or.inr ∘ fun ⟨a,ha⟩ ↦
(s.finite_or_infinite.elim (fun hfin ↦ Or.inr ⟨a, ha, ?_⟩) (Or.inl ∘ Infinite.encard_eq)))
rw [← encard_diff_singleton_add_one ha]; nth_rw 1 [← add_zero (encard _)]
exact WithTop.add_lt_add_left (hfin.diff _).encard_lt_top.ne zero_lt_one
end InsertErase
section SmallSets
theorem encard_pair {x y : α} (hne : x ≠ y) : ({x, y} : Set α).encard = 2 := by
rw [encard_insert_of_not_mem (by simpa), ← one_add_one_eq_two,
WithTop.add_right_cancel_iff WithTop.one_ne_top, encard_singleton]
theorem encard_eq_one : s.encard = 1 ↔ ∃ x, s = {x} := by
refine ⟨fun h ↦ ?_, fun ⟨x, hx⟩ ↦ by rw [hx, encard_singleton]⟩
obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp)
exact ⟨x, ((finite_singleton x).eq_of_subset_of_encard_le' (by simpa) (by simp [h])).symm⟩
theorem encard_le_one_iff_eq : s.encard ≤ 1 ↔ s = ∅ ∨ ∃ x, s = {x} := by
rw [le_iff_lt_or_eq, lt_iff_not_le, ENat.one_le_iff_ne_zero, not_not, encard_eq_zero,
encard_eq_one]
theorem encard_le_one_iff : s.encard ≤ 1 ↔ ∀ a b, a ∈ s → b ∈ s → a = b := by
rw [encard_le_one_iff_eq, or_iff_not_imp_left, ← Ne, ← nonempty_iff_ne_empty]
refine ⟨fun h a b has hbs ↦ ?_,
fun h ⟨x, hx⟩ ↦ ⟨x, ((singleton_subset_iff.2 hx).antisymm' (fun y hy ↦ h _ _ hy hx))⟩⟩
obtain ⟨x, rfl⟩ := h ⟨_, has⟩
rw [(has : a = x), (hbs : b = x)]
theorem one_lt_encard_iff : 1 < s.encard ↔ ∃ a b, a ∈ s ∧ b ∈ s ∧ a ≠ b := by
rw [← not_iff_not, not_exists, not_lt, encard_le_one_iff]; aesop
theorem exists_ne_of_one_lt_encard (h : 1 < s.encard) (a : α) : ∃ b ∈ s, b ≠ a := by
by_contra! h'
obtain ⟨b, b', hb, hb', hne⟩ := one_lt_encard_iff.1 h
apply hne
rw [h' b hb, h' b' hb']
| Mathlib/Data/Set/Card.lean | 315 | 322 | theorem encard_eq_two : s.encard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by |
refine ⟨fun h ↦ ?_, fun ⟨x, y, hne, hs⟩ ↦ by rw [hs, encard_pair hne]⟩
obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp)
rw [← insert_eq_of_mem hx, ← insert_diff_singleton, encard_insert_of_not_mem (fun h ↦ h.2 rfl),
← one_add_one_eq_two, WithTop.add_right_cancel_iff (WithTop.one_ne_top), encard_eq_one] at h
obtain ⟨y, h⟩ := h
refine ⟨x, y, by rintro rfl; exact (h.symm.subset rfl).2 rfl, ?_⟩
rw [← h, insert_diff_singleton, insert_eq_of_mem hx]
|
/-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Jakob von Raumer
-/
import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts
import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts
import Mathlib.CategoryTheory.Limits.Shapes.Kernels
#align_import category_theory.limits.shapes.biproducts from "leanprover-community/mathlib"@"ac3ae212f394f508df43e37aa093722fa9b65d31"
/-!
# Biproducts and binary biproducts
We introduce the notion of (finite) biproducts and binary biproducts.
These are slightly unusual relative to the other shapes in the library,
as they are simultaneously limits and colimits.
(Zero objects are similar; they are "biterminal".)
For results about biproducts in preadditive categories see
`CategoryTheory.Preadditive.Biproducts`.
In a category with zero morphisms, we model the (binary) biproduct of `P Q : C`
using a `BinaryBicone`, which has a cone point `X`,
and morphisms `fst : X ⟶ P`, `snd : X ⟶ Q`, `inl : P ⟶ X` and `inr : X ⟶ Q`,
such that `inl ≫ fst = 𝟙 P`, `inl ≫ snd = 0`, `inr ≫ fst = 0`, and `inr ≫ snd = 𝟙 Q`.
Such a `BinaryBicone` is a biproduct if the cone is a limit cone, and the cocone is a colimit
cocone.
For biproducts indexed by a `Fintype J`, a `bicone` again consists of a cone point `X`
and morphisms `π j : X ⟶ F j` and `ι j : F j ⟶ X` for each `j`,
such that `ι j ≫ π j'` is the identity when `j = j'` and zero otherwise.
## Notation
As `⊕` is already taken for the sum of types, we introduce the notation `X ⊞ Y` for
a binary biproduct. We introduce `⨁ f` for the indexed biproduct.
## Implementation notes
Prior to leanprover-community/mathlib#14046,
`HasFiniteBiproducts` required a `DecidableEq` instance on the indexing type.
As this had no pay-off (everything about limits is non-constructive in mathlib),
and occasional cost
(constructing decidability instances appropriate for constructions involving the indexing type),
we made everything classical.
-/
noncomputable section
universe w w' v u
open CategoryTheory
open CategoryTheory.Functor
open scoped Classical
namespace CategoryTheory
namespace Limits
variable {J : Type w}
universe uC' uC uD' uD
variable {C : Type uC} [Category.{uC'} C] [HasZeroMorphisms C]
variable {D : Type uD} [Category.{uD'} D] [HasZeroMorphisms D]
/-- A `c : Bicone F` is:
* an object `c.pt` and
* morphisms `π j : pt ⟶ F j` and `ι j : F j ⟶ pt` for each `j`,
* such that `ι j ≫ π j'` is the identity when `j = j'` and zero otherwise.
-/
-- @[nolint has_nonempty_instance] Porting note (#5171): removed
structure Bicone (F : J → C) where
pt : C
π : ∀ j, pt ⟶ F j
ι : ∀ j, F j ⟶ pt
ι_π : ∀ j j', ι j ≫ π j' =
if h : j = j' then eqToHom (congrArg F h) else 0 := by aesop
#align category_theory.limits.bicone CategoryTheory.Limits.Bicone
set_option linter.uppercaseLean3 false in
#align category_theory.limits.bicone_X CategoryTheory.Limits.Bicone.pt
attribute [inherit_doc Bicone] Bicone.pt Bicone.π Bicone.ι Bicone.ι_π
@[reassoc (attr := simp)]
theorem bicone_ι_π_self {F : J → C} (B : Bicone F) (j : J) : B.ι j ≫ B.π j = 𝟙 (F j) := by
simpa using B.ι_π j j
#align category_theory.limits.bicone_ι_π_self CategoryTheory.Limits.bicone_ι_π_self
@[reassoc (attr := simp)]
theorem bicone_ι_π_ne {F : J → C} (B : Bicone F) {j j' : J} (h : j ≠ j') : B.ι j ≫ B.π j' = 0 := by
simpa [h] using B.ι_π j j'
#align category_theory.limits.bicone_ι_π_ne CategoryTheory.Limits.bicone_ι_π_ne
variable {F : J → C}
/-- A bicone morphism between two bicones for the same diagram is a morphism of the bicone points
which commutes with the cone and cocone legs. -/
structure BiconeMorphism {F : J → C} (A B : Bicone F) where
/-- A morphism between the two vertex objects of the bicones -/
hom : A.pt ⟶ B.pt
/-- The triangle consisting of the two natural transformations and `hom` commutes -/
wπ : ∀ j : J, hom ≫ B.π j = A.π j := by aesop_cat
/-- The triangle consisting of the two natural transformations and `hom` commutes -/
wι : ∀ j : J, A.ι j ≫ hom = B.ι j := by aesop_cat
attribute [reassoc (attr := simp)] BiconeMorphism.wι
attribute [reassoc (attr := simp)] BiconeMorphism.wπ
/-- The category of bicones on a given diagram. -/
@[simps]
instance Bicone.category : Category (Bicone F) where
Hom A B := BiconeMorphism A B
comp f g := { hom := f.hom ≫ g.hom }
id B := { hom := 𝟙 B.pt }
-- Porting note: if we do not have `simps` automatically generate the lemma for simplifying
-- the `hom` field of a category, we need to write the `ext` lemma in terms of the categorical
-- morphism, rather than the underlying structure.
@[ext]
theorem BiconeMorphism.ext {c c' : Bicone F} (f g : c ⟶ c') (w : f.hom = g.hom) : f = g := by
cases f
cases g
congr
namespace Bicones
/-- To give an isomorphism between cocones, it suffices to give an
isomorphism between their vertices which commutes with the cocone
maps. -/
-- Porting note: `@[ext]` used to accept lemmas like this. Now we add an aesop rule
@[aesop apply safe (rule_sets := [CategoryTheory]), simps]
def ext {c c' : Bicone F} (φ : c.pt ≅ c'.pt)
(wι : ∀ j, c.ι j ≫ φ.hom = c'.ι j := by aesop_cat)
(wπ : ∀ j, φ.hom ≫ c'.π j = c.π j := by aesop_cat) : c ≅ c' where
hom := { hom := φ.hom }
inv :=
{ hom := φ.inv
wι := fun j => φ.comp_inv_eq.mpr (wι j).symm
wπ := fun j => φ.inv_comp_eq.mpr (wπ j).symm }
variable (F) in
/-- A functor `G : C ⥤ D` sends bicones over `F` to bicones over `G.obj ∘ F` functorially. -/
@[simps]
def functoriality (G : C ⥤ D) [Functor.PreservesZeroMorphisms G] :
Bicone F ⥤ Bicone (G.obj ∘ F) where
obj A :=
{ pt := G.obj A.pt
π := fun j => G.map (A.π j)
ι := fun j => G.map (A.ι j)
ι_π := fun i j => (Functor.map_comp _ _ _).symm.trans <| by
rw [A.ι_π]
aesop_cat }
map f :=
{ hom := G.map f.hom
wπ := fun j => by simp [-BiconeMorphism.wπ, ← f.wπ j]
wι := fun j => by simp [-BiconeMorphism.wι, ← f.wι j] }
variable (G : C ⥤ D)
instance functoriality_full [G.PreservesZeroMorphisms] [G.Full] [G.Faithful] :
(functoriality F G).Full where
map_surjective t :=
⟨{ hom := G.preimage t.hom
wι := fun j => G.map_injective (by simpa using t.wι j)
wπ := fun j => G.map_injective (by simpa using t.wπ j) }, by aesop_cat⟩
instance functoriality_faithful [G.PreservesZeroMorphisms] [G.Faithful] :
(functoriality F G).Faithful where
map_injective {_X} {_Y} f g h :=
BiconeMorphism.ext f g <| G.map_injective <| congr_arg BiconeMorphism.hom h
end Bicones
namespace Bicone
attribute [local aesop safe tactic (rule_sets := [CategoryTheory])]
CategoryTheory.Discrete.discreteCases
-- Porting note: would it be okay to use this more generally?
attribute [local aesop safe cases (rule_sets := [CategoryTheory])] Eq
/-- Extract the cone from a bicone. -/
def toConeFunctor : Bicone F ⥤ Cone (Discrete.functor F) where
obj B := { pt := B.pt, π := { app := fun j => B.π j.as } }
map {X Y} F := { hom := F.hom, w := fun _ => F.wπ _ }
/-- A shorthand for `toConeFunctor.obj` -/
abbrev toCone (B : Bicone F) : Cone (Discrete.functor F) := toConeFunctor.obj B
#align category_theory.limits.bicone.to_cone CategoryTheory.Limits.Bicone.toCone
-- TODO Consider changing this API to `toFan (B : Bicone F) : Fan F`.
@[simp]
theorem toCone_pt (B : Bicone F) : B.toCone.pt = B.pt := rfl
set_option linter.uppercaseLean3 false in
#align category_theory.limits.bicone.to_cone_X CategoryTheory.Limits.Bicone.toCone_pt
@[simp]
theorem toCone_π_app (B : Bicone F) (j : Discrete J) : B.toCone.π.app j = B.π j.as := rfl
#align category_theory.limits.bicone.to_cone_π_app CategoryTheory.Limits.Bicone.toCone_π_app
theorem toCone_π_app_mk (B : Bicone F) (j : J) : B.toCone.π.app ⟨j⟩ = B.π j := rfl
#align category_theory.limits.bicone.to_cone_π_app_mk CategoryTheory.Limits.Bicone.toCone_π_app_mk
@[simp]
theorem toCone_proj (B : Bicone F) (j : J) : Fan.proj B.toCone j = B.π j := rfl
/-- Extract the cocone from a bicone. -/
def toCoconeFunctor : Bicone F ⥤ Cocone (Discrete.functor F) where
obj B := { pt := B.pt, ι := { app := fun j => B.ι j.as } }
map {X Y} F := { hom := F.hom, w := fun _ => F.wι _ }
/-- A shorthand for `toCoconeFunctor.obj` -/
abbrev toCocone (B : Bicone F) : Cocone (Discrete.functor F) := toCoconeFunctor.obj B
#align category_theory.limits.bicone.to_cocone CategoryTheory.Limits.Bicone.toCocone
@[simp]
theorem toCocone_pt (B : Bicone F) : B.toCocone.pt = B.pt := rfl
set_option linter.uppercaseLean3 false in
#align category_theory.limits.bicone.to_cocone_X CategoryTheory.Limits.Bicone.toCocone_pt
@[simp]
theorem toCocone_ι_app (B : Bicone F) (j : Discrete J) : B.toCocone.ι.app j = B.ι j.as := rfl
#align category_theory.limits.bicone.to_cocone_ι_app CategoryTheory.Limits.Bicone.toCocone_ι_app
@[simp]
theorem toCocone_inj (B : Bicone F) (j : J) : Cofan.inj B.toCocone j = B.ι j := rfl
theorem toCocone_ι_app_mk (B : Bicone F) (j : J) : B.toCocone.ι.app ⟨j⟩ = B.ι j := rfl
#align category_theory.limits.bicone.to_cocone_ι_app_mk CategoryTheory.Limits.Bicone.toCocone_ι_app_mk
/-- We can turn any limit cone over a discrete collection of objects into a bicone. -/
@[simps]
def ofLimitCone {f : J → C} {t : Cone (Discrete.functor f)} (ht : IsLimit t) : Bicone f where
pt := t.pt
π j := t.π.app ⟨j⟩
ι j := ht.lift (Fan.mk _ fun j' => if h : j = j' then eqToHom (congr_arg f h) else 0)
ι_π j j' := by simp
#align category_theory.limits.bicone.of_limit_cone CategoryTheory.Limits.Bicone.ofLimitCone
theorem ι_of_isLimit {f : J → C} {t : Bicone f} (ht : IsLimit t.toCone) (j : J) :
t.ι j = ht.lift (Fan.mk _ fun j' => if h : j = j' then eqToHom (congr_arg f h) else 0) :=
ht.hom_ext fun j' => by
rw [ht.fac]
simp [t.ι_π]
#align category_theory.limits.bicone.ι_of_is_limit CategoryTheory.Limits.Bicone.ι_of_isLimit
/-- We can turn any colimit cocone over a discrete collection of objects into a bicone. -/
@[simps]
def ofColimitCocone {f : J → C} {t : Cocone (Discrete.functor f)} (ht : IsColimit t) :
Bicone f where
pt := t.pt
π j := ht.desc (Cofan.mk _ fun j' => if h : j' = j then eqToHom (congr_arg f h) else 0)
ι j := t.ι.app ⟨j⟩
ι_π j j' := by simp
#align category_theory.limits.bicone.of_colimit_cocone CategoryTheory.Limits.Bicone.ofColimitCocone
theorem π_of_isColimit {f : J → C} {t : Bicone f} (ht : IsColimit t.toCocone) (j : J) :
t.π j = ht.desc (Cofan.mk _ fun j' => if h : j' = j then eqToHom (congr_arg f h) else 0) :=
ht.hom_ext fun j' => by
rw [ht.fac]
simp [t.ι_π]
#align category_theory.limits.bicone.π_of_is_colimit CategoryTheory.Limits.Bicone.π_of_isColimit
/-- Structure witnessing that a bicone is both a limit cone and a colimit cocone. -/
-- @[nolint has_nonempty_instance] Porting note (#5171): removed
structure IsBilimit {F : J → C} (B : Bicone F) where
isLimit : IsLimit B.toCone
isColimit : IsColimit B.toCocone
#align category_theory.limits.bicone.is_bilimit CategoryTheory.Limits.Bicone.IsBilimit
#align category_theory.limits.bicone.is_bilimit.is_limit CategoryTheory.Limits.Bicone.IsBilimit.isLimit
#align category_theory.limits.bicone.is_bilimit.is_colimit CategoryTheory.Limits.Bicone.IsBilimit.isColimit
attribute [inherit_doc IsBilimit] IsBilimit.isLimit IsBilimit.isColimit
-- Porting note (#10618): simp can prove this, linter doesn't notice it is removed
attribute [-simp, nolint simpNF] IsBilimit.mk.injEq
attribute [local ext] Bicone.IsBilimit
instance subsingleton_isBilimit {f : J → C} {c : Bicone f} : Subsingleton c.IsBilimit :=
⟨fun _ _ => Bicone.IsBilimit.ext _ _ (Subsingleton.elim _ _) (Subsingleton.elim _ _)⟩
#align category_theory.limits.bicone.subsingleton_is_bilimit CategoryTheory.Limits.Bicone.subsingleton_isBilimit
section Whisker
variable {K : Type w'}
/-- Whisker a bicone with an equivalence between the indexing types. -/
@[simps]
def whisker {f : J → C} (c : Bicone f) (g : K ≃ J) : Bicone (f ∘ g) where
pt := c.pt
π k := c.π (g k)
ι k := c.ι (g k)
ι_π k k' := by
simp only [c.ι_π]
split_ifs with h h' h' <;> simp [Equiv.apply_eq_iff_eq g] at h h' <;> tauto
#align category_theory.limits.bicone.whisker CategoryTheory.Limits.Bicone.whisker
/-- Taking the cone of a whiskered bicone results in a cone isomorphic to one gained
by whiskering the cone and postcomposing with a suitable isomorphism. -/
def whiskerToCone {f : J → C} (c : Bicone f) (g : K ≃ J) :
(c.whisker g).toCone ≅
(Cones.postcompose (Discrete.functorComp f g).inv).obj
(c.toCone.whisker (Discrete.functor (Discrete.mk ∘ g))) :=
Cones.ext (Iso.refl _) (by aesop_cat)
#align category_theory.limits.bicone.whisker_to_cone CategoryTheory.Limits.Bicone.whiskerToCone
/-- Taking the cocone of a whiskered bicone results in a cone isomorphic to one gained
by whiskering the cocone and precomposing with a suitable isomorphism. -/
def whiskerToCocone {f : J → C} (c : Bicone f) (g : K ≃ J) :
(c.whisker g).toCocone ≅
(Cocones.precompose (Discrete.functorComp f g).hom).obj
(c.toCocone.whisker (Discrete.functor (Discrete.mk ∘ g))) :=
Cocones.ext (Iso.refl _) (by aesop_cat)
#align category_theory.limits.bicone.whisker_to_cocone CategoryTheory.Limits.Bicone.whiskerToCocone
/-- Whiskering a bicone with an equivalence between types preserves being a bilimit bicone. -/
def whiskerIsBilimitIff {f : J → C} (c : Bicone f) (g : K ≃ J) :
(c.whisker g).IsBilimit ≃ c.IsBilimit := by
refine equivOfSubsingletonOfSubsingleton (fun hc => ⟨?_, ?_⟩) fun hc => ⟨?_, ?_⟩
· let this := IsLimit.ofIsoLimit hc.isLimit (Bicone.whiskerToCone c g)
let this := (IsLimit.postcomposeHomEquiv (Discrete.functorComp f g).symm _) this
exact IsLimit.ofWhiskerEquivalence (Discrete.equivalence g) this
· let this := IsColimit.ofIsoColimit hc.isColimit (Bicone.whiskerToCocone c g)
let this := (IsColimit.precomposeHomEquiv (Discrete.functorComp f g) _) this
exact IsColimit.ofWhiskerEquivalence (Discrete.equivalence g) this
· apply IsLimit.ofIsoLimit _ (Bicone.whiskerToCone c g).symm
apply (IsLimit.postcomposeHomEquiv (Discrete.functorComp f g).symm _).symm _
exact IsLimit.whiskerEquivalence hc.isLimit (Discrete.equivalence g)
· apply IsColimit.ofIsoColimit _ (Bicone.whiskerToCocone c g).symm
apply (IsColimit.precomposeHomEquiv (Discrete.functorComp f g) _).symm _
exact IsColimit.whiskerEquivalence hc.isColimit (Discrete.equivalence g)
#align category_theory.limits.bicone.whisker_is_bilimit_iff CategoryTheory.Limits.Bicone.whiskerIsBilimitIff
end Whisker
end Bicone
/-- A bicone over `F : J → C`, which is both a limit cone and a colimit cocone.
-/
-- @[nolint has_nonempty_instance] -- Porting note(#5171): removed; linter not ported yet
structure LimitBicone (F : J → C) where
bicone : Bicone F
isBilimit : bicone.IsBilimit
#align category_theory.limits.limit_bicone CategoryTheory.Limits.LimitBicone
#align category_theory.limits.limit_bicone.is_bilimit CategoryTheory.Limits.LimitBicone.isBilimit
attribute [inherit_doc LimitBicone] LimitBicone.bicone LimitBicone.isBilimit
/-- `HasBiproduct F` expresses the mere existence of a bicone which is
simultaneously a limit and a colimit of the diagram `F`.
-/
class HasBiproduct (F : J → C) : Prop where mk' ::
exists_biproduct : Nonempty (LimitBicone F)
#align category_theory.limits.has_biproduct CategoryTheory.Limits.HasBiproduct
attribute [inherit_doc HasBiproduct] HasBiproduct.exists_biproduct
theorem HasBiproduct.mk {F : J → C} (d : LimitBicone F) : HasBiproduct F :=
⟨Nonempty.intro d⟩
#align category_theory.limits.has_biproduct.mk CategoryTheory.Limits.HasBiproduct.mk
/-- Use the axiom of choice to extract explicit `BiproductData F` from `HasBiproduct F`. -/
def getBiproductData (F : J → C) [HasBiproduct F] : LimitBicone F :=
Classical.choice HasBiproduct.exists_biproduct
#align category_theory.limits.get_biproduct_data CategoryTheory.Limits.getBiproductData
/-- A bicone for `F` which is both a limit cone and a colimit cocone. -/
def biproduct.bicone (F : J → C) [HasBiproduct F] : Bicone F :=
(getBiproductData F).bicone
#align category_theory.limits.biproduct.bicone CategoryTheory.Limits.biproduct.bicone
/-- `biproduct.bicone F` is a bilimit bicone. -/
def biproduct.isBilimit (F : J → C) [HasBiproduct F] : (biproduct.bicone F).IsBilimit :=
(getBiproductData F).isBilimit
#align category_theory.limits.biproduct.is_bilimit CategoryTheory.Limits.biproduct.isBilimit
/-- `biproduct.bicone F` is a limit cone. -/
def biproduct.isLimit (F : J → C) [HasBiproduct F] : IsLimit (biproduct.bicone F).toCone :=
(getBiproductData F).isBilimit.isLimit
#align category_theory.limits.biproduct.is_limit CategoryTheory.Limits.biproduct.isLimit
/-- `biproduct.bicone F` is a colimit cocone. -/
def biproduct.isColimit (F : J → C) [HasBiproduct F] : IsColimit (biproduct.bicone F).toCocone :=
(getBiproductData F).isBilimit.isColimit
#align category_theory.limits.biproduct.is_colimit CategoryTheory.Limits.biproduct.isColimit
instance (priority := 100) hasProduct_of_hasBiproduct [HasBiproduct F] : HasProduct F :=
HasLimit.mk
{ cone := (biproduct.bicone F).toCone
isLimit := biproduct.isLimit F }
#align category_theory.limits.has_product_of_has_biproduct CategoryTheory.Limits.hasProduct_of_hasBiproduct
instance (priority := 100) hasCoproduct_of_hasBiproduct [HasBiproduct F] : HasCoproduct F :=
HasColimit.mk
{ cocone := (biproduct.bicone F).toCocone
isColimit := biproduct.isColimit F }
#align category_theory.limits.has_coproduct_of_has_biproduct CategoryTheory.Limits.hasCoproduct_of_hasBiproduct
variable (J C)
/-- `C` has biproducts of shape `J` if we have
a limit and a colimit, with the same cone points,
of every function `F : J → C`.
-/
class HasBiproductsOfShape : Prop where
has_biproduct : ∀ F : J → C, HasBiproduct F
#align category_theory.limits.has_biproducts_of_shape CategoryTheory.Limits.HasBiproductsOfShape
attribute [instance 100] HasBiproductsOfShape.has_biproduct
/-- `HasFiniteBiproducts C` represents a choice of biproduct for every family of objects in `C`
indexed by a finite type. -/
class HasFiniteBiproducts : Prop where
out : ∀ n, HasBiproductsOfShape (Fin n) C
#align category_theory.limits.has_finite_biproducts CategoryTheory.Limits.HasFiniteBiproducts
attribute [inherit_doc HasFiniteBiproducts] HasFiniteBiproducts.out
variable {J}
theorem hasBiproductsOfShape_of_equiv {K : Type w'} [HasBiproductsOfShape K C] (e : J ≃ K) :
HasBiproductsOfShape J C :=
⟨fun F =>
let ⟨⟨h⟩⟩ := HasBiproductsOfShape.has_biproduct (F ∘ e.symm)
let ⟨c, hc⟩ := h
HasBiproduct.mk <| by
simpa only [(· ∘ ·), e.symm_apply_apply] using
LimitBicone.mk (c.whisker e) ((c.whiskerIsBilimitIff _).2 hc)⟩
#align category_theory.limits.has_biproducts_of_shape_of_equiv CategoryTheory.Limits.hasBiproductsOfShape_of_equiv
instance (priority := 100) hasBiproductsOfShape_finite [HasFiniteBiproducts C] [Finite J] :
HasBiproductsOfShape J C := by
rcases Finite.exists_equiv_fin J with ⟨n, ⟨e⟩⟩
haveI : HasBiproductsOfShape (Fin n) C := HasFiniteBiproducts.out n
exact hasBiproductsOfShape_of_equiv C e
#align category_theory.limits.has_biproducts_of_shape_finite CategoryTheory.Limits.hasBiproductsOfShape_finite
instance (priority := 100) hasFiniteProducts_of_hasFiniteBiproducts [HasFiniteBiproducts C] :
HasFiniteProducts C where
out _ := ⟨fun _ => hasLimitOfIso Discrete.natIsoFunctor.symm⟩
#align category_theory.limits.has_finite_products_of_has_finite_biproducts CategoryTheory.Limits.hasFiniteProducts_of_hasFiniteBiproducts
instance (priority := 100) hasFiniteCoproducts_of_hasFiniteBiproducts [HasFiniteBiproducts C] :
HasFiniteCoproducts C where
out _ := ⟨fun _ => hasColimitOfIso Discrete.natIsoFunctor⟩
#align category_theory.limits.has_finite_coproducts_of_has_finite_biproducts CategoryTheory.Limits.hasFiniteCoproducts_of_hasFiniteBiproducts
variable {C}
/-- The isomorphism between the specified limit and the specified colimit for
a functor with a bilimit.
-/
def biproductIso (F : J → C) [HasBiproduct F] : Limits.piObj F ≅ Limits.sigmaObj F :=
(IsLimit.conePointUniqueUpToIso (limit.isLimit _) (biproduct.isLimit F)).trans <|
IsColimit.coconePointUniqueUpToIso (biproduct.isColimit F) (colimit.isColimit _)
#align category_theory.limits.biproduct_iso CategoryTheory.Limits.biproductIso
end Limits
namespace Limits
variable {J : Type w} {K : Type*}
variable {C : Type u} [Category.{v} C] [HasZeroMorphisms C]
/-- `biproduct f` computes the biproduct of a family of elements `f`. (It is defined as an
abbreviation for `limit (Discrete.functor f)`, so for most facts about `biproduct f`, you will
just use general facts about limits and colimits.) -/
abbrev biproduct (f : J → C) [HasBiproduct f] : C :=
(biproduct.bicone f).pt
#align category_theory.limits.biproduct CategoryTheory.Limits.biproduct
@[inherit_doc biproduct]
notation "⨁ " f:20 => biproduct f
/-- The projection onto a summand of a biproduct. -/
abbrev biproduct.π (f : J → C) [HasBiproduct f] (b : J) : ⨁ f ⟶ f b :=
(biproduct.bicone f).π b
#align category_theory.limits.biproduct.π CategoryTheory.Limits.biproduct.π
@[simp]
theorem biproduct.bicone_π (f : J → C) [HasBiproduct f] (b : J) :
(biproduct.bicone f).π b = biproduct.π f b := rfl
#align category_theory.limits.biproduct.bicone_π CategoryTheory.Limits.biproduct.bicone_π
/-- The inclusion into a summand of a biproduct. -/
abbrev biproduct.ι (f : J → C) [HasBiproduct f] (b : J) : f b ⟶ ⨁ f :=
(biproduct.bicone f).ι b
#align category_theory.limits.biproduct.ι CategoryTheory.Limits.biproduct.ι
@[simp]
theorem biproduct.bicone_ι (f : J → C) [HasBiproduct f] (b : J) :
(biproduct.bicone f).ι b = biproduct.ι f b := rfl
#align category_theory.limits.biproduct.bicone_ι CategoryTheory.Limits.biproduct.bicone_ι
/-- Note that as this lemma has an `if` in the statement, we include a `DecidableEq` argument.
This means you may not be able to `simp` using this lemma unless you `open scoped Classical`. -/
@[reassoc]
theorem biproduct.ι_π [DecidableEq J] (f : J → C) [HasBiproduct f] (j j' : J) :
biproduct.ι f j ≫ biproduct.π f j' = if h : j = j' then eqToHom (congr_arg f h) else 0 := by
convert (biproduct.bicone f).ι_π j j'
#align category_theory.limits.biproduct.ι_π CategoryTheory.Limits.biproduct.ι_π
@[reassoc] -- Porting note: both versions proven by simp
theorem biproduct.ι_π_self (f : J → C) [HasBiproduct f] (j : J) :
biproduct.ι f j ≫ biproduct.π f j = 𝟙 _ := by simp [biproduct.ι_π]
#align category_theory.limits.biproduct.ι_π_self CategoryTheory.Limits.biproduct.ι_π_self
@[reassoc (attr := simp)]
theorem biproduct.ι_π_ne (f : J → C) [HasBiproduct f] {j j' : J} (h : j ≠ j') :
biproduct.ι f j ≫ biproduct.π f j' = 0 := by simp [biproduct.ι_π, h]
#align category_theory.limits.biproduct.ι_π_ne CategoryTheory.Limits.biproduct.ι_π_ne
-- The `simpNF` linter incorrectly identifies these as simp lemmas that could never apply.
-- https://github.com/leanprover-community/mathlib4/issues/5049
-- They are used by `simp` in `biproduct.whiskerEquiv` below.
@[reassoc (attr := simp, nolint simpNF)]
theorem biproduct.eqToHom_comp_ι (f : J → C) [HasBiproduct f] {j j' : J} (w : j = j') :
eqToHom (by simp [w]) ≫ biproduct.ι f j' = biproduct.ι f j := by
cases w
simp
-- The `simpNF` linter incorrectly identifies these as simp lemmas that could never apply.
-- https://github.com/leanprover-community/mathlib4/issues/5049
-- They are used by `simp` in `biproduct.whiskerEquiv` below.
@[reassoc (attr := simp, nolint simpNF)]
theorem biproduct.π_comp_eqToHom (f : J → C) [HasBiproduct f] {j j' : J} (w : j = j') :
biproduct.π f j ≫ eqToHom (by simp [w]) = biproduct.π f j' := by
cases w
simp
/-- Given a collection of maps into the summands, we obtain a map into the biproduct. -/
abbrev biproduct.lift {f : J → C} [HasBiproduct f] {P : C} (p : ∀ b, P ⟶ f b) : P ⟶ ⨁ f :=
(biproduct.isLimit f).lift (Fan.mk P p)
#align category_theory.limits.biproduct.lift CategoryTheory.Limits.biproduct.lift
/-- Given a collection of maps out of the summands, we obtain a map out of the biproduct. -/
abbrev biproduct.desc {f : J → C} [HasBiproduct f] {P : C} (p : ∀ b, f b ⟶ P) : ⨁ f ⟶ P :=
(biproduct.isColimit f).desc (Cofan.mk P p)
#align category_theory.limits.biproduct.desc CategoryTheory.Limits.biproduct.desc
@[reassoc (attr := simp)]
theorem biproduct.lift_π {f : J → C} [HasBiproduct f] {P : C} (p : ∀ b, P ⟶ f b) (j : J) :
biproduct.lift p ≫ biproduct.π f j = p j := (biproduct.isLimit f).fac _ ⟨j⟩
#align category_theory.limits.biproduct.lift_π CategoryTheory.Limits.biproduct.lift_π
@[reassoc (attr := simp)]
theorem biproduct.ι_desc {f : J → C} [HasBiproduct f] {P : C} (p : ∀ b, f b ⟶ P) (j : J) :
biproduct.ι f j ≫ biproduct.desc p = p j := (biproduct.isColimit f).fac _ ⟨j⟩
#align category_theory.limits.biproduct.ι_desc CategoryTheory.Limits.biproduct.ι_desc
/-- Given a collection of maps between corresponding summands of a pair of biproducts
indexed by the same type, we obtain a map between the biproducts. -/
abbrev biproduct.map {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ b, f b ⟶ g b) :
⨁ f ⟶ ⨁ g :=
IsLimit.map (biproduct.bicone f).toCone (biproduct.isLimit g)
(Discrete.natTrans (fun j => p j.as))
#align category_theory.limits.biproduct.map CategoryTheory.Limits.biproduct.map
/-- An alternative to `biproduct.map` constructed via colimits.
This construction only exists in order to show it is equal to `biproduct.map`. -/
abbrev biproduct.map' {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ b, f b ⟶ g b) :
⨁ f ⟶ ⨁ g :=
IsColimit.map (biproduct.isColimit f) (biproduct.bicone g).toCocone
(Discrete.natTrans fun j => p j.as)
#align category_theory.limits.biproduct.map' CategoryTheory.Limits.biproduct.map'
-- We put this at slightly higher priority than `biproduct.hom_ext'`,
-- to get the matrix indices in the "right" order.
@[ext 1001]
theorem biproduct.hom_ext {f : J → C} [HasBiproduct f] {Z : C} (g h : Z ⟶ ⨁ f)
(w : ∀ j, g ≫ biproduct.π f j = h ≫ biproduct.π f j) : g = h :=
(biproduct.isLimit f).hom_ext fun j => w j.as
#align category_theory.limits.biproduct.hom_ext CategoryTheory.Limits.biproduct.hom_ext
@[ext]
theorem biproduct.hom_ext' {f : J → C} [HasBiproduct f] {Z : C} (g h : ⨁ f ⟶ Z)
(w : ∀ j, biproduct.ι f j ≫ g = biproduct.ι f j ≫ h) : g = h :=
(biproduct.isColimit f).hom_ext fun j => w j.as
#align category_theory.limits.biproduct.hom_ext' CategoryTheory.Limits.biproduct.hom_ext'
/-- The canonical isomorphism between the chosen biproduct and the chosen product. -/
def biproduct.isoProduct (f : J → C) [HasBiproduct f] : ⨁ f ≅ ∏ᶜ f :=
IsLimit.conePointUniqueUpToIso (biproduct.isLimit f) (limit.isLimit _)
#align category_theory.limits.biproduct.iso_product CategoryTheory.Limits.biproduct.isoProduct
@[simp]
theorem biproduct.isoProduct_hom {f : J → C} [HasBiproduct f] :
(biproduct.isoProduct f).hom = Pi.lift (biproduct.π f) :=
limit.hom_ext fun j => by simp [biproduct.isoProduct]
#align category_theory.limits.biproduct.iso_product_hom CategoryTheory.Limits.biproduct.isoProduct_hom
@[simp]
theorem biproduct.isoProduct_inv {f : J → C} [HasBiproduct f] :
(biproduct.isoProduct f).inv = biproduct.lift (Pi.π f) :=
biproduct.hom_ext _ _ fun j => by simp [Iso.inv_comp_eq]
#align category_theory.limits.biproduct.iso_product_inv CategoryTheory.Limits.biproduct.isoProduct_inv
/-- The canonical isomorphism between the chosen biproduct and the chosen coproduct. -/
def biproduct.isoCoproduct (f : J → C) [HasBiproduct f] : ⨁ f ≅ ∐ f :=
IsColimit.coconePointUniqueUpToIso (biproduct.isColimit f) (colimit.isColimit _)
#align category_theory.limits.biproduct.iso_coproduct CategoryTheory.Limits.biproduct.isoCoproduct
@[simp]
theorem biproduct.isoCoproduct_inv {f : J → C} [HasBiproduct f] :
(biproduct.isoCoproduct f).inv = Sigma.desc (biproduct.ι f) :=
colimit.hom_ext fun j => by simp [biproduct.isoCoproduct]
#align category_theory.limits.biproduct.iso_coproduct_inv CategoryTheory.Limits.biproduct.isoCoproduct_inv
@[simp]
theorem biproduct.isoCoproduct_hom {f : J → C} [HasBiproduct f] :
(biproduct.isoCoproduct f).hom = biproduct.desc (Sigma.ι f) :=
biproduct.hom_ext' _ _ fun j => by simp [← Iso.eq_comp_inv]
#align category_theory.limits.biproduct.iso_coproduct_hom CategoryTheory.Limits.biproduct.isoCoproduct_hom
theorem biproduct.map_eq_map' {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ b, f b ⟶ g b) :
biproduct.map p = biproduct.map' p := by
ext
dsimp
simp only [Discrete.natTrans_app, Limits.IsColimit.ι_map_assoc, Limits.IsLimit.map_π,
Category.assoc, ← Bicone.toCone_π_app_mk, ← biproduct.bicone_π, ← Bicone.toCocone_ι_app_mk,
← biproduct.bicone_ι]
dsimp
rw [biproduct.ι_π_assoc, biproduct.ι_π]
split_ifs with h
· subst h; rw [eqToHom_refl, Category.id_comp]; erw [Category.comp_id]
· simp
#align category_theory.limits.biproduct.map_eq_map' CategoryTheory.Limits.biproduct.map_eq_map'
@[reassoc (attr := simp)]
theorem biproduct.map_π {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ j, f j ⟶ g j)
(j : J) : biproduct.map p ≫ biproduct.π g j = biproduct.π f j ≫ p j :=
Limits.IsLimit.map_π _ _ _ (Discrete.mk j)
#align category_theory.limits.biproduct.map_π CategoryTheory.Limits.biproduct.map_π
@[reassoc (attr := simp)]
theorem biproduct.ι_map {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ j, f j ⟶ g j)
(j : J) : biproduct.ι f j ≫ biproduct.map p = p j ≫ biproduct.ι g j := by
rw [biproduct.map_eq_map']
apply
Limits.IsColimit.ι_map (biproduct.isColimit f) (biproduct.bicone g).toCocone
(Discrete.natTrans fun j => p j.as) (Discrete.mk j)
#align category_theory.limits.biproduct.ι_map CategoryTheory.Limits.biproduct.ι_map
@[reassoc (attr := simp)]
theorem biproduct.map_desc {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ j, f j ⟶ g j)
{P : C} (k : ∀ j, g j ⟶ P) :
biproduct.map p ≫ biproduct.desc k = biproduct.desc fun j => p j ≫ k j := by
ext; simp
#align category_theory.limits.biproduct.map_desc CategoryTheory.Limits.biproduct.map_desc
@[reassoc (attr := simp)]
theorem biproduct.lift_map {f g : J → C} [HasBiproduct f] [HasBiproduct g] {P : C}
(k : ∀ j, P ⟶ f j) (p : ∀ j, f j ⟶ g j) :
biproduct.lift k ≫ biproduct.map p = biproduct.lift fun j => k j ≫ p j := by
ext; simp
#align category_theory.limits.biproduct.lift_map CategoryTheory.Limits.biproduct.lift_map
/-- Given a collection of isomorphisms between corresponding summands of a pair of biproducts
indexed by the same type, we obtain an isomorphism between the biproducts. -/
@[simps]
def biproduct.mapIso {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ b, f b ≅ g b) :
⨁ f ≅ ⨁ g where
hom := biproduct.map fun b => (p b).hom
inv := biproduct.map fun b => (p b).inv
#align category_theory.limits.biproduct.map_iso CategoryTheory.Limits.biproduct.mapIso
/-- Two biproducts which differ by an equivalence in the indexing type,
and up to isomorphism in the factors, are isomorphic.
Unfortunately there are two natural ways to define each direction of this isomorphism
(because it is true for both products and coproducts separately).
We give the alternative definitions as lemmas below.
-/
@[simps]
def biproduct.whiskerEquiv {f : J → C} {g : K → C} (e : J ≃ K) (w : ∀ j, g (e j) ≅ f j)
[HasBiproduct f] [HasBiproduct g] : ⨁ f ≅ ⨁ g where
hom := biproduct.desc fun j => (w j).inv ≫ biproduct.ι g (e j)
inv := biproduct.desc fun k => eqToHom (by simp) ≫ (w (e.symm k)).hom ≫ biproduct.ι f _
lemma biproduct.whiskerEquiv_hom_eq_lift {f : J → C} {g : K → C} (e : J ≃ K)
(w : ∀ j, g (e j) ≅ f j) [HasBiproduct f] [HasBiproduct g] :
(biproduct.whiskerEquiv e w).hom =
biproduct.lift fun k => biproduct.π f (e.symm k) ≫ (w _).inv ≫ eqToHom (by simp) := by
simp only [whiskerEquiv_hom]
ext k j
by_cases h : k = e j
· subst h
simp
· simp only [ι_desc_assoc, Category.assoc, ne_eq, lift_π]
rw [biproduct.ι_π_ne, biproduct.ι_π_ne_assoc]
· simp
· rintro rfl
simp at h
· exact Ne.symm h
lemma biproduct.whiskerEquiv_inv_eq_lift {f : J → C} {g : K → C} (e : J ≃ K)
(w : ∀ j, g (e j) ≅ f j) [HasBiproduct f] [HasBiproduct g] :
(biproduct.whiskerEquiv e w).inv =
biproduct.lift fun j => biproduct.π g (e j) ≫ (w j).hom := by
simp only [whiskerEquiv_inv]
ext j k
by_cases h : k = e j
· subst h
simp only [ι_desc_assoc, ← eqToHom_iso_hom_naturality_assoc w (e.symm_apply_apply j).symm,
Equiv.symm_apply_apply, eqToHom_comp_ι, Category.assoc, bicone_ι_π_self, Category.comp_id,
lift_π, bicone_ι_π_self_assoc]
· simp only [ι_desc_assoc, Category.assoc, ne_eq, lift_π]
rw [biproduct.ι_π_ne, biproduct.ι_π_ne_assoc]
· simp
· exact h
· rintro rfl
simp at h
instance {ι} (f : ι → Type*) (g : (i : ι) → (f i) → C)
[∀ i, HasBiproduct (g i)] [HasBiproduct fun i => ⨁ g i] :
HasBiproduct fun p : Σ i, f i => g p.1 p.2 where
exists_biproduct := Nonempty.intro
{ bicone :=
{ pt := ⨁ fun i => ⨁ g i
ι := fun X => biproduct.ι (g X.1) X.2 ≫ biproduct.ι (fun i => ⨁ g i) X.1
π := fun X => biproduct.π (fun i => ⨁ g i) X.1 ≫ biproduct.π (g X.1) X.2
ι_π := fun ⟨j, x⟩ ⟨j', y⟩ => by
split_ifs with h
· obtain ⟨rfl, rfl⟩ := h
simp
· simp only [Sigma.mk.inj_iff, not_and] at h
by_cases w : j = j'
· cases w
simp only [heq_eq_eq, forall_true_left] at h
simp [biproduct.ι_π_ne _ h]
· simp [biproduct.ι_π_ne_assoc _ w] }
isBilimit :=
{ isLimit := mkFanLimit _
(fun s => biproduct.lift fun b => biproduct.lift fun c => s.proj ⟨b, c⟩)
isColimit := mkCofanColimit _
(fun s => biproduct.desc fun b => biproduct.desc fun c => s.inj ⟨b, c⟩) } }
/-- An iterated biproduct is a biproduct over a sigma type. -/
@[simps]
def biproductBiproductIso {ι} (f : ι → Type*) (g : (i : ι) → (f i) → C)
[∀ i, HasBiproduct (g i)] [HasBiproduct fun i => ⨁ g i] :
(⨁ fun i => ⨁ g i) ≅ (⨁ fun p : Σ i, f i => g p.1 p.2) where
hom := biproduct.lift fun ⟨i, x⟩ => biproduct.π _ i ≫ biproduct.π _ x
inv := biproduct.lift fun i => biproduct.lift fun x => biproduct.π _ (⟨i, x⟩ : Σ i, f i)
section πKernel
section
variable (f : J → C) [HasBiproduct f]
variable (p : J → Prop) [HasBiproduct (Subtype.restrict p f)]
/-- The canonical morphism from the biproduct over a restricted index type to the biproduct of
the full index type. -/
def biproduct.fromSubtype : ⨁ Subtype.restrict p f ⟶ ⨁ f :=
biproduct.desc fun j => biproduct.ι _ j.val
#align category_theory.limits.biproduct.from_subtype CategoryTheory.Limits.biproduct.fromSubtype
/-- The canonical morphism from a biproduct to the biproduct over a restriction of its index
type. -/
def biproduct.toSubtype : ⨁ f ⟶ ⨁ Subtype.restrict p f :=
biproduct.lift fun _ => biproduct.π _ _
#align category_theory.limits.biproduct.to_subtype CategoryTheory.Limits.biproduct.toSubtype
@[reassoc (attr := simp)]
theorem biproduct.fromSubtype_π [DecidablePred p] (j : J) :
biproduct.fromSubtype f p ≫ biproduct.π f j =
if h : p j then biproduct.π (Subtype.restrict p f) ⟨j, h⟩ else 0 := by
ext i; dsimp
rw [biproduct.fromSubtype, biproduct.ι_desc_assoc, biproduct.ι_π]
by_cases h : p j
· rw [dif_pos h, biproduct.ι_π]
split_ifs with h₁ h₂ h₂
exacts [rfl, False.elim (h₂ (Subtype.ext h₁)), False.elim (h₁ (congr_arg Subtype.val h₂)), rfl]
· rw [dif_neg h, dif_neg (show (i : J) ≠ j from fun h₂ => h (h₂ ▸ i.2)), comp_zero]
#align category_theory.limits.biproduct.from_subtype_π CategoryTheory.Limits.biproduct.fromSubtype_π
theorem biproduct.fromSubtype_eq_lift [DecidablePred p] :
biproduct.fromSubtype f p =
biproduct.lift fun j => if h : p j then biproduct.π (Subtype.restrict p f) ⟨j, h⟩ else 0 :=
biproduct.hom_ext _ _ (by simp)
#align category_theory.limits.biproduct.from_subtype_eq_lift CategoryTheory.Limits.biproduct.fromSubtype_eq_lift
@[reassoc] -- Porting note: both version solved using simp
theorem biproduct.fromSubtype_π_subtype (j : Subtype p) :
biproduct.fromSubtype f p ≫ biproduct.π f j = biproduct.π (Subtype.restrict p f) j := by
ext
rw [biproduct.fromSubtype, biproduct.ι_desc_assoc, biproduct.ι_π, biproduct.ι_π]
split_ifs with h₁ h₂ h₂
exacts [rfl, False.elim (h₂ (Subtype.ext h₁)), False.elim (h₁ (congr_arg Subtype.val h₂)), rfl]
#align category_theory.limits.biproduct.from_subtype_π_subtype CategoryTheory.Limits.biproduct.fromSubtype_π_subtype
@[reassoc (attr := simp)]
theorem biproduct.toSubtype_π (j : Subtype p) :
biproduct.toSubtype f p ≫ biproduct.π (Subtype.restrict p f) j = biproduct.π f j :=
biproduct.lift_π _ _
#align category_theory.limits.biproduct.to_subtype_π CategoryTheory.Limits.biproduct.toSubtype_π
@[reassoc (attr := simp)]
theorem biproduct.ι_toSubtype [DecidablePred p] (j : J) :
biproduct.ι f j ≫ biproduct.toSubtype f p =
if h : p j then biproduct.ι (Subtype.restrict p f) ⟨j, h⟩ else 0 := by
ext i
rw [biproduct.toSubtype, Category.assoc, biproduct.lift_π, biproduct.ι_π]
by_cases h : p j
· rw [dif_pos h, biproduct.ι_π]
split_ifs with h₁ h₂ h₂
exacts [rfl, False.elim (h₂ (Subtype.ext h₁)), False.elim (h₁ (congr_arg Subtype.val h₂)), rfl]
· rw [dif_neg h, dif_neg (show j ≠ i from fun h₂ => h (h₂.symm ▸ i.2)), zero_comp]
#align category_theory.limits.biproduct.ι_to_subtype CategoryTheory.Limits.biproduct.ι_toSubtype
theorem biproduct.toSubtype_eq_desc [DecidablePred p] :
biproduct.toSubtype f p =
biproduct.desc fun j => if h : p j then biproduct.ι (Subtype.restrict p f) ⟨j, h⟩ else 0 :=
biproduct.hom_ext' _ _ (by simp)
#align category_theory.limits.biproduct.to_subtype_eq_desc CategoryTheory.Limits.biproduct.toSubtype_eq_desc
@[reassoc] -- Porting note (#10618): simp can prove both versions
theorem biproduct.ι_toSubtype_subtype (j : Subtype p) :
biproduct.ι f j ≫ biproduct.toSubtype f p = biproduct.ι (Subtype.restrict p f) j := by
ext
rw [biproduct.toSubtype, Category.assoc, biproduct.lift_π, biproduct.ι_π, biproduct.ι_π]
split_ifs with h₁ h₂ h₂
exacts [rfl, False.elim (h₂ (Subtype.ext h₁)), False.elim (h₁ (congr_arg Subtype.val h₂)), rfl]
#align category_theory.limits.biproduct.ι_to_subtype_subtype CategoryTheory.Limits.biproduct.ι_toSubtype_subtype
@[reassoc (attr := simp)]
theorem biproduct.ι_fromSubtype (j : Subtype p) :
biproduct.ι (Subtype.restrict p f) j ≫ biproduct.fromSubtype f p = biproduct.ι f j :=
biproduct.ι_desc _ _
#align category_theory.limits.biproduct.ι_from_subtype CategoryTheory.Limits.biproduct.ι_fromSubtype
@[reassoc (attr := simp)]
theorem biproduct.fromSubtype_toSubtype :
biproduct.fromSubtype f p ≫ biproduct.toSubtype f p = 𝟙 (⨁ Subtype.restrict p f) := by
refine biproduct.hom_ext _ _ fun j => ?_
rw [Category.assoc, biproduct.toSubtype_π, biproduct.fromSubtype_π_subtype, Category.id_comp]
#align category_theory.limits.biproduct.from_subtype_to_subtype CategoryTheory.Limits.biproduct.fromSubtype_toSubtype
@[reassoc (attr := simp)]
theorem biproduct.toSubtype_fromSubtype [DecidablePred p] :
biproduct.toSubtype f p ≫ biproduct.fromSubtype f p =
biproduct.map fun j => if p j then 𝟙 (f j) else 0 := by
ext1 i
by_cases h : p i
· simp [h]
· simp [h]
#align category_theory.limits.biproduct.to_subtype_from_subtype CategoryTheory.Limits.biproduct.toSubtype_fromSubtype
end
section
variable (f : J → C) (i : J) [HasBiproduct f] [HasBiproduct (Subtype.restrict (fun j => j ≠ i) f)]
/-- The kernel of `biproduct.π f i` is the inclusion from the biproduct which omits `i`
from the index set `J` into the biproduct over `J`. -/
def biproduct.isLimitFromSubtype :
IsLimit (KernelFork.ofι (biproduct.fromSubtype f fun j => j ≠ i) (by simp) :
KernelFork (biproduct.π f i)) :=
Fork.IsLimit.mk' _ fun s =>
⟨s.ι ≫ biproduct.toSubtype _ _, by
apply biproduct.hom_ext; intro j
rw [KernelFork.ι_ofι, Category.assoc, Category.assoc,
biproduct.toSubtype_fromSubtype_assoc, biproduct.map_π]
rcases Classical.em (i = j) with (rfl | h)
· rw [if_neg (Classical.not_not.2 rfl), comp_zero, comp_zero, KernelFork.condition]
· rw [if_pos (Ne.symm h), Category.comp_id], by
intro m hm
rw [← hm, KernelFork.ι_ofι, Category.assoc, biproduct.fromSubtype_toSubtype]
exact (Category.comp_id _).symm⟩
#align category_theory.limits.biproduct.is_limit_from_subtype CategoryTheory.Limits.biproduct.isLimitFromSubtype
instance : HasKernel (biproduct.π f i) :=
HasLimit.mk ⟨_, biproduct.isLimitFromSubtype f i⟩
/-- The kernel of `biproduct.π f i` is `⨁ Subtype.restrict {i}ᶜ f`. -/
@[simps!]
def kernelBiproductπIso : kernel (biproduct.π f i) ≅ ⨁ Subtype.restrict (fun j => j ≠ i) f :=
limit.isoLimitCone ⟨_, biproduct.isLimitFromSubtype f i⟩
#align category_theory.limits.kernel_biproduct_π_iso CategoryTheory.Limits.kernelBiproductπIso
/-- The cokernel of `biproduct.ι f i` is the projection from the biproduct over the index set `J`
onto the biproduct omitting `i`. -/
def biproduct.isColimitToSubtype :
IsColimit (CokernelCofork.ofπ (biproduct.toSubtype f fun j => j ≠ i) (by simp) :
CokernelCofork (biproduct.ι f i)) :=
Cofork.IsColimit.mk' _ fun s =>
⟨biproduct.fromSubtype _ _ ≫ s.π, by
apply biproduct.hom_ext'; intro j
rw [CokernelCofork.π_ofπ, biproduct.toSubtype_fromSubtype_assoc, biproduct.ι_map_assoc]
rcases Classical.em (i = j) with (rfl | h)
· rw [if_neg (Classical.not_not.2 rfl), zero_comp, CokernelCofork.condition]
· rw [if_pos (Ne.symm h), Category.id_comp], by
intro m hm
rw [← hm, CokernelCofork.π_ofπ, ← Category.assoc, biproduct.fromSubtype_toSubtype]
exact (Category.id_comp _).symm⟩
#align category_theory.limits.biproduct.is_colimit_to_subtype CategoryTheory.Limits.biproduct.isColimitToSubtype
instance : HasCokernel (biproduct.ι f i) :=
HasColimit.mk ⟨_, biproduct.isColimitToSubtype f i⟩
/-- The cokernel of `biproduct.ι f i` is `⨁ Subtype.restrict {i}ᶜ f`. -/
@[simps!]
def cokernelBiproductιIso : cokernel (biproduct.ι f i) ≅ ⨁ Subtype.restrict (fun j => j ≠ i) f :=
colimit.isoColimitCocone ⟨_, biproduct.isColimitToSubtype f i⟩
#align category_theory.limits.cokernel_biproduct_ι_iso CategoryTheory.Limits.cokernelBiproductιIso
end
section
open scoped Classical
-- Per leanprover-community/mathlib#15067, we only allow indexing in `Type 0` here.
variable {K : Type} [Finite K] [HasFiniteBiproducts C] (f : K → C)
/-- The limit cone exhibiting `⨁ Subtype.restrict pᶜ f` as the kernel of
`biproduct.toSubtype f p` -/
@[simps]
def kernelForkBiproductToSubtype (p : Set K) :
LimitCone (parallelPair (biproduct.toSubtype f p) 0) where
cone :=
KernelFork.ofι (biproduct.fromSubtype f pᶜ)
(by
ext j k
simp only [Category.assoc, biproduct.ι_fromSubtype_assoc, biproduct.ι_toSubtype_assoc,
comp_zero, zero_comp]
erw [dif_neg k.2]
simp only [zero_comp])
isLimit :=
KernelFork.IsLimit.ofι _ _ (fun {W} g _ => g ≫ biproduct.toSubtype f pᶜ)
(by
intro W' g' w
ext j
simp only [Category.assoc, biproduct.toSubtype_fromSubtype, Pi.compl_apply,
biproduct.map_π]
split_ifs with h
· simp
· replace w := w =≫ biproduct.π _ ⟨j, not_not.mp h⟩
simpa using w.symm)
(by aesop_cat)
#align category_theory.limits.kernel_fork_biproduct_to_subtype CategoryTheory.Limits.kernelForkBiproductToSubtype
instance (p : Set K) : HasKernel (biproduct.toSubtype f p) :=
HasLimit.mk (kernelForkBiproductToSubtype f p)
/-- The kernel of `biproduct.toSubtype f p` is `⨁ Subtype.restrict pᶜ f`. -/
@[simps!]
def kernelBiproductToSubtypeIso (p : Set K) :
kernel (biproduct.toSubtype f p) ≅ ⨁ Subtype.restrict pᶜ f :=
limit.isoLimitCone (kernelForkBiproductToSubtype f p)
#align category_theory.limits.kernel_biproduct_to_subtype_iso CategoryTheory.Limits.kernelBiproductToSubtypeIso
/-- The colimit cocone exhibiting `⨁ Subtype.restrict pᶜ f` as the cokernel of
`biproduct.fromSubtype f p` -/
@[simps]
def cokernelCoforkBiproductFromSubtype (p : Set K) :
ColimitCocone (parallelPair (biproduct.fromSubtype f p) 0) where
cocone :=
CokernelCofork.ofπ (biproduct.toSubtype f pᶜ)
(by
ext j k
simp only [Category.assoc, Pi.compl_apply, biproduct.ι_fromSubtype_assoc,
biproduct.ι_toSubtype_assoc, comp_zero, zero_comp]
rw [dif_neg]
· simp only [zero_comp]
· exact not_not.mpr k.2)
isColimit :=
CokernelCofork.IsColimit.ofπ _ _ (fun {W} g _ => biproduct.fromSubtype f pᶜ ≫ g)
(by
intro W g' w
ext j
simp only [biproduct.toSubtype_fromSubtype_assoc, Pi.compl_apply, biproduct.ι_map_assoc]
split_ifs with h
· simp
· replace w := biproduct.ι _ (⟨j, not_not.mp h⟩ : p) ≫= w
simpa using w.symm)
(by aesop_cat)
#align category_theory.limits.cokernel_cofork_biproduct_from_subtype CategoryTheory.Limits.cokernelCoforkBiproductFromSubtype
instance (p : Set K) : HasCokernel (biproduct.fromSubtype f p) :=
HasColimit.mk (cokernelCoforkBiproductFromSubtype f p)
/-- The cokernel of `biproduct.fromSubtype f p` is `⨁ Subtype.restrict pᶜ f`. -/
@[simps!]
def cokernelBiproductFromSubtypeIso (p : Set K) :
cokernel (biproduct.fromSubtype f p) ≅ ⨁ Subtype.restrict pᶜ f :=
colimit.isoColimitCocone (cokernelCoforkBiproductFromSubtype f p)
#align category_theory.limits.cokernel_biproduct_from_subtype_iso CategoryTheory.Limits.cokernelBiproductFromSubtypeIso
end
end πKernel
end Limits
namespace Limits
section FiniteBiproducts
variable {J : Type} [Finite J] {K : Type} [Finite K] {C : Type u} [Category.{v} C]
[HasZeroMorphisms C] [HasFiniteBiproducts C] {f : J → C} {g : K → C}
/-- Convert a (dependently typed) matrix to a morphism of biproducts.
-/
def biproduct.matrix (m : ∀ j k, f j ⟶ g k) : ⨁ f ⟶ ⨁ g :=
biproduct.desc fun j => biproduct.lift fun k => m j k
#align category_theory.limits.biproduct.matrix CategoryTheory.Limits.biproduct.matrix
@[reassoc (attr := simp)]
theorem biproduct.matrix_π (m : ∀ j k, f j ⟶ g k) (k : K) :
biproduct.matrix m ≫ biproduct.π g k = biproduct.desc fun j => m j k := by
ext
simp [biproduct.matrix]
#align category_theory.limits.biproduct.matrix_π CategoryTheory.Limits.biproduct.matrix_π
@[reassoc (attr := simp)]
theorem biproduct.ι_matrix (m : ∀ j k, f j ⟶ g k) (j : J) :
biproduct.ι f j ≫ biproduct.matrix m = biproduct.lift fun k => m j k := by
ext
simp [biproduct.matrix]
#align category_theory.limits.biproduct.ι_matrix CategoryTheory.Limits.biproduct.ι_matrix
/-- Extract the matrix components from a morphism of biproducts.
-/
def biproduct.components (m : ⨁ f ⟶ ⨁ g) (j : J) (k : K) : f j ⟶ g k :=
biproduct.ι f j ≫ m ≫ biproduct.π g k
#align category_theory.limits.biproduct.components CategoryTheory.Limits.biproduct.components
@[simp]
theorem biproduct.matrix_components (m : ∀ j k, f j ⟶ g k) (j : J) (k : K) :
biproduct.components (biproduct.matrix m) j k = m j k := by simp [biproduct.components]
#align category_theory.limits.biproduct.matrix_components CategoryTheory.Limits.biproduct.matrix_components
@[simp]
theorem biproduct.components_matrix (m : ⨁ f ⟶ ⨁ g) :
(biproduct.matrix fun j k => biproduct.components m j k) = m := by
ext
simp [biproduct.components]
#align category_theory.limits.biproduct.components_matrix CategoryTheory.Limits.biproduct.components_matrix
/-- Morphisms between direct sums are matrices. -/
@[simps]
def biproduct.matrixEquiv : (⨁ f ⟶ ⨁ g) ≃ ∀ j k, f j ⟶ g k where
toFun := biproduct.components
invFun := biproduct.matrix
left_inv := biproduct.components_matrix
right_inv m := by
ext
apply biproduct.matrix_components
#align category_theory.limits.biproduct.matrix_equiv CategoryTheory.Limits.biproduct.matrixEquiv
end FiniteBiproducts
universe uD uD'
variable {J : Type w}
variable {C : Type u} [Category.{v} C] [HasZeroMorphisms C]
variable {D : Type uD} [Category.{uD'} D] [HasZeroMorphisms D]
instance biproduct.ι_mono (f : J → C) [HasBiproduct f] (b : J) : IsSplitMono (biproduct.ι f b) :=
IsSplitMono.mk' { retraction := biproduct.desc <| Pi.single b _ }
#align category_theory.limits.biproduct.ι_mono CategoryTheory.Limits.biproduct.ι_mono
instance biproduct.π_epi (f : J → C) [HasBiproduct f] (b : J) : IsSplitEpi (biproduct.π f b) :=
IsSplitEpi.mk' { section_ := biproduct.lift <| Pi.single b _ }
#align category_theory.limits.biproduct.π_epi CategoryTheory.Limits.biproduct.π_epi
/-- Auxiliary lemma for `biproduct.uniqueUpToIso`. -/
theorem biproduct.conePointUniqueUpToIso_hom (f : J → C) [HasBiproduct f] {b : Bicone f}
(hb : b.IsBilimit) :
(hb.isLimit.conePointUniqueUpToIso (biproduct.isLimit _)).hom = biproduct.lift b.π :=
rfl
#align category_theory.limits.biproduct.cone_point_unique_up_to_iso_hom CategoryTheory.Limits.biproduct.conePointUniqueUpToIso_hom
/-- Auxiliary lemma for `biproduct.uniqueUpToIso`. -/
theorem biproduct.conePointUniqueUpToIso_inv (f : J → C) [HasBiproduct f] {b : Bicone f}
(hb : b.IsBilimit) :
(hb.isLimit.conePointUniqueUpToIso (biproduct.isLimit _)).inv = biproduct.desc b.ι := by
refine biproduct.hom_ext' _ _ fun j => hb.isLimit.hom_ext fun j' => ?_
rw [Category.assoc, IsLimit.conePointUniqueUpToIso_inv_comp, Bicone.toCone_π_app,
biproduct.bicone_π, biproduct.ι_desc, biproduct.ι_π, b.toCone_π_app, b.ι_π]
#align category_theory.limits.biproduct.cone_point_unique_up_to_iso_inv CategoryTheory.Limits.biproduct.conePointUniqueUpToIso_inv
/-- Biproducts are unique up to isomorphism. This already follows because bilimits are limits,
but in the case of biproducts we can give an isomorphism with particularly nice definitional
properties, namely that `biproduct.lift b.π` and `biproduct.desc b.ι` are inverses of each
other. -/
@[simps]
def biproduct.uniqueUpToIso (f : J → C) [HasBiproduct f] {b : Bicone f} (hb : b.IsBilimit) :
b.pt ≅ ⨁ f where
hom := biproduct.lift b.π
inv := biproduct.desc b.ι
hom_inv_id := by
rw [← biproduct.conePointUniqueUpToIso_hom f hb, ←
biproduct.conePointUniqueUpToIso_inv f hb, Iso.hom_inv_id]
inv_hom_id := by
rw [← biproduct.conePointUniqueUpToIso_hom f hb, ←
biproduct.conePointUniqueUpToIso_inv f hb, Iso.inv_hom_id]
#align category_theory.limits.biproduct.unique_up_to_iso CategoryTheory.Limits.biproduct.uniqueUpToIso
variable (C)
-- see Note [lower instance priority]
/-- A category with finite biproducts has a zero object. -/
instance (priority := 100) hasZeroObject_of_hasFiniteBiproducts [HasFiniteBiproducts C] :
HasZeroObject C := by
refine ⟨⟨biproduct Empty.elim, fun X => ⟨⟨⟨0⟩, ?_⟩⟩, fun X => ⟨⟨⟨0⟩, ?_⟩⟩⟩⟩
· intro a; apply biproduct.hom_ext'; simp
· intro a; apply biproduct.hom_ext; simp
#align category_theory.limits.has_zero_object_of_has_finite_biproducts CategoryTheory.Limits.hasZeroObject_of_hasFiniteBiproducts
section
variable {C} [Unique J] (f : J → C)
attribute [local simp] eq_iff_true_of_subsingleton in
/-- The limit bicone for the biproduct over an index type with exactly one term. -/
@[simps]
def limitBiconeOfUnique : LimitBicone f where
bicone :=
{ pt := f default
π := fun j => eqToHom (by congr; rw [← Unique.uniq] )
ι := fun j => eqToHom (by congr; rw [← Unique.uniq] ) }
isBilimit :=
{ isLimit := (limitConeOfUnique f).isLimit
isColimit := (colimitCoconeOfUnique f).isColimit }
#align category_theory.limits.limit_bicone_of_unique CategoryTheory.Limits.limitBiconeOfUnique
instance (priority := 100) hasBiproduct_unique : HasBiproduct f :=
HasBiproduct.mk (limitBiconeOfUnique f)
#align category_theory.limits.has_biproduct_unique CategoryTheory.Limits.hasBiproduct_unique
/-- A biproduct over an index type with exactly one term is just the object over that term. -/
@[simps!]
def biproductUniqueIso : ⨁ f ≅ f default :=
(biproduct.uniqueUpToIso _ (limitBiconeOfUnique f).isBilimit).symm
#align category_theory.limits.biproduct_unique_iso CategoryTheory.Limits.biproductUniqueIso
end
variable {C}
/-- A binary bicone for a pair of objects `P Q : C` consists of the cone point `X`,
maps from `X` to both `P` and `Q`, and maps from both `P` and `Q` to `X`,
so that `inl ≫ fst = 𝟙 P`, `inl ≫ snd = 0`, `inr ≫ fst = 0`, and `inr ≫ snd = 𝟙 Q`
-/
-- @[nolint has_nonempty_instance] Porting note (#5171): removed
structure BinaryBicone (P Q : C) where
pt : C
fst : pt ⟶ P
snd : pt ⟶ Q
inl : P ⟶ pt
inr : Q ⟶ pt
inl_fst : inl ≫ fst = 𝟙 P := by aesop
inl_snd : inl ≫ snd = 0 := by aesop
inr_fst : inr ≫ fst = 0 := by aesop
inr_snd : inr ≫ snd = 𝟙 Q := by aesop
#align category_theory.limits.binary_bicone CategoryTheory.Limits.BinaryBicone
#align category_theory.limits.binary_bicone.inl_fst' CategoryTheory.Limits.BinaryBicone.inl_fst
#align category_theory.limits.binary_bicone.inl_snd' CategoryTheory.Limits.BinaryBicone.inl_snd
#align category_theory.limits.binary_bicone.inr_fst' CategoryTheory.Limits.BinaryBicone.inr_fst
#align category_theory.limits.binary_bicone.inr_snd' CategoryTheory.Limits.BinaryBicone.inr_snd
attribute [inherit_doc BinaryBicone] BinaryBicone.pt BinaryBicone.fst BinaryBicone.snd
BinaryBicone.inl BinaryBicone.inr BinaryBicone.inl_fst BinaryBicone.inl_snd
BinaryBicone.inr_fst BinaryBicone.inr_snd
attribute [reassoc (attr := simp)]
BinaryBicone.inl_fst BinaryBicone.inl_snd BinaryBicone.inr_fst BinaryBicone.inr_snd
/-- A binary bicone morphism between two binary bicones for the same diagram is a morphism of the
binary bicone points which commutes with the cone and cocone legs. -/
structure BinaryBiconeMorphism {P Q : C} (A B : BinaryBicone P Q) where
/-- A morphism between the two vertex objects of the bicones -/
hom : A.pt ⟶ B.pt
/-- The triangle consisting of the two natural transformations and `hom` commutes -/
wfst : hom ≫ B.fst = A.fst := by aesop_cat
/-- The triangle consisting of the two natural transformations and `hom` commutes -/
wsnd : hom ≫ B.snd = A.snd := by aesop_cat
/-- The triangle consisting of the two natural transformations and `hom` commutes -/
winl : A.inl ≫ hom = B.inl := by aesop_cat
/-- The triangle consisting of the two natural transformations and `hom` commutes -/
winr : A.inr ≫ hom = B.inr := by aesop_cat
attribute [reassoc (attr := simp)] BinaryBiconeMorphism.wfst BinaryBiconeMorphism.wsnd
attribute [reassoc (attr := simp)] BinaryBiconeMorphism.winl BinaryBiconeMorphism.winr
/-- The category of binary bicones on a given diagram. -/
@[simps]
instance BinaryBicone.category {P Q : C} : Category (BinaryBicone P Q) where
Hom A B := BinaryBiconeMorphism A B
comp f g := { hom := f.hom ≫ g.hom }
id B := { hom := 𝟙 B.pt }
-- Porting note: if we do not have `simps` automatically generate the lemma for simplifying
-- the `hom` field of a category, we need to write the `ext` lemma in terms of the categorical
-- morphism, rather than the underlying structure.
@[ext]
theorem BinaryBiconeMorphism.ext {P Q : C} {c c' : BinaryBicone P Q}
(f g : c ⟶ c') (w : f.hom = g.hom) : f = g := by
cases f
cases g
congr
namespace BinaryBicones
/-- To give an isomorphism between cocones, it suffices to give an
isomorphism between their vertices which commutes with the cocone
maps. -/
-- Porting note: `@[ext]` used to accept lemmas like this. Now we add an aesop rule
@[aesop apply safe (rule_sets := [CategoryTheory]), simps]
def ext {P Q : C} {c c' : BinaryBicone P Q} (φ : c.pt ≅ c'.pt)
(winl : c.inl ≫ φ.hom = c'.inl := by aesop_cat)
(winr : c.inr ≫ φ.hom = c'.inr := by aesop_cat)
(wfst : φ.hom ≫ c'.fst = c.fst := by aesop_cat)
(wsnd : φ.hom ≫ c'.snd = c.snd := by aesop_cat) : c ≅ c' where
hom := { hom := φ.hom }
inv :=
{ hom := φ.inv
wfst := φ.inv_comp_eq.mpr wfst.symm
wsnd := φ.inv_comp_eq.mpr wsnd.symm
winl := φ.comp_inv_eq.mpr winl.symm
winr := φ.comp_inv_eq.mpr winr.symm }
variable (P Q : C) (F : C ⥤ D) [Functor.PreservesZeroMorphisms F]
/-- A functor `F : C ⥤ D` sends binary bicones for `P` and `Q`
to binary bicones for `G.obj P` and `G.obj Q` functorially. -/
@[simps]
def functoriality : BinaryBicone P Q ⥤ BinaryBicone (F.obj P) (F.obj Q) where
obj A :=
{ pt := F.obj A.pt
fst := F.map A.fst
snd := F.map A.snd
inl := F.map A.inl
inr := F.map A.inr
inl_fst := by rw [← F.map_comp, A.inl_fst, F.map_id]
inl_snd := by rw [← F.map_comp, A.inl_snd, F.map_zero]
inr_fst := by rw [← F.map_comp, A.inr_fst, F.map_zero]
inr_snd := by rw [← F.map_comp, A.inr_snd, F.map_id] }
map f :=
{ hom := F.map f.hom
wfst := by simp [-BinaryBiconeMorphism.wfst, ← f.wfst]
wsnd := by simp [-BinaryBiconeMorphism.wsnd, ← f.wsnd]
winl := by simp [-BinaryBiconeMorphism.winl, ← f.winl]
winr := by simp [-BinaryBiconeMorphism.winr, ← f.winr] }
instance functoriality_full [F.Full] [F.Faithful] : (functoriality P Q F).Full where
map_surjective t :=
⟨{ hom := F.preimage t.hom
winl := F.map_injective (by simpa using t.winl)
winr := F.map_injective (by simpa using t.winr)
wfst := F.map_injective (by simpa using t.wfst)
wsnd := F.map_injective (by simpa using t.wsnd) }, by aesop_cat⟩
instance functoriality_faithful [F.Faithful] : (functoriality P Q F).Faithful where
map_injective {_X} {_Y} f g h :=
BinaryBiconeMorphism.ext f g <| F.map_injective <| congr_arg BinaryBiconeMorphism.hom h
end BinaryBicones
namespace BinaryBicone
variable {P Q : C}
/-- Extract the cone from a binary bicone. -/
def toCone (c : BinaryBicone P Q) : Cone (pair P Q) :=
BinaryFan.mk c.fst c.snd
#align category_theory.limits.binary_bicone.to_cone CategoryTheory.Limits.BinaryBicone.toCone
@[simp]
theorem toCone_pt (c : BinaryBicone P Q) : c.toCone.pt = c.pt := rfl
set_option linter.uppercaseLean3 false in
#align category_theory.limits.binary_bicone.to_cone_X CategoryTheory.Limits.BinaryBicone.toCone_pt
@[simp]
theorem toCone_π_app_left (c : BinaryBicone P Q) : c.toCone.π.app ⟨WalkingPair.left⟩ = c.fst :=
rfl
#align category_theory.limits.binary_bicone.to_cone_π_app_left CategoryTheory.Limits.BinaryBicone.toCone_π_app_left
@[simp]
theorem toCone_π_app_right (c : BinaryBicone P Q) : c.toCone.π.app ⟨WalkingPair.right⟩ = c.snd :=
rfl
#align category_theory.limits.binary_bicone.to_cone_π_app_right CategoryTheory.Limits.BinaryBicone.toCone_π_app_right
@[simp]
theorem binary_fan_fst_toCone (c : BinaryBicone P Q) : BinaryFan.fst c.toCone = c.fst := rfl
#align category_theory.limits.binary_bicone.binary_fan_fst_to_cone CategoryTheory.Limits.BinaryBicone.binary_fan_fst_toCone
@[simp]
theorem binary_fan_snd_toCone (c : BinaryBicone P Q) : BinaryFan.snd c.toCone = c.snd := rfl
#align category_theory.limits.binary_bicone.binary_fan_snd_to_cone CategoryTheory.Limits.BinaryBicone.binary_fan_snd_toCone
/-- Extract the cocone from a binary bicone. -/
def toCocone (c : BinaryBicone P Q) : Cocone (pair P Q) := BinaryCofan.mk c.inl c.inr
#align category_theory.limits.binary_bicone.to_cocone CategoryTheory.Limits.BinaryBicone.toCocone
@[simp]
theorem toCocone_pt (c : BinaryBicone P Q) : c.toCocone.pt = c.pt := rfl
set_option linter.uppercaseLean3 false in
#align category_theory.limits.binary_bicone.to_cocone_X CategoryTheory.Limits.BinaryBicone.toCocone_pt
@[simp]
theorem toCocone_ι_app_left (c : BinaryBicone P Q) : c.toCocone.ι.app ⟨WalkingPair.left⟩ = c.inl :=
rfl
#align category_theory.limits.binary_bicone.to_cocone_ι_app_left CategoryTheory.Limits.BinaryBicone.toCocone_ι_app_left
@[simp]
theorem toCocone_ι_app_right (c : BinaryBicone P Q) :
c.toCocone.ι.app ⟨WalkingPair.right⟩ = c.inr := rfl
#align category_theory.limits.binary_bicone.to_cocone_ι_app_right CategoryTheory.Limits.BinaryBicone.toCocone_ι_app_right
@[simp]
theorem binary_cofan_inl_toCocone (c : BinaryBicone P Q) : BinaryCofan.inl c.toCocone = c.inl :=
rfl
#align category_theory.limits.binary_bicone.binary_cofan_inl_to_cocone CategoryTheory.Limits.BinaryBicone.binary_cofan_inl_toCocone
@[simp]
theorem binary_cofan_inr_toCocone (c : BinaryBicone P Q) : BinaryCofan.inr c.toCocone = c.inr :=
rfl
#align category_theory.limits.binary_bicone.binary_cofan_inr_to_cocone CategoryTheory.Limits.BinaryBicone.binary_cofan_inr_toCocone
instance (c : BinaryBicone P Q) : IsSplitMono c.inl :=
IsSplitMono.mk'
{ retraction := c.fst
id := c.inl_fst }
instance (c : BinaryBicone P Q) : IsSplitMono c.inr :=
IsSplitMono.mk'
{ retraction := c.snd
id := c.inr_snd }
instance (c : BinaryBicone P Q) : IsSplitEpi c.fst :=
IsSplitEpi.mk'
{ section_ := c.inl
id := c.inl_fst }
instance (c : BinaryBicone P Q) : IsSplitEpi c.snd :=
IsSplitEpi.mk'
{ section_ := c.inr
id := c.inr_snd }
/-- Convert a `BinaryBicone` into a `Bicone` over a pair. -/
@[simps]
def toBiconeFunctor {X Y : C} : BinaryBicone X Y ⥤ Bicone (pairFunction X Y) where
obj b :=
{ pt := b.pt
π := fun j => WalkingPair.casesOn j b.fst b.snd
ι := fun j => WalkingPair.casesOn j b.inl b.inr
ι_π := fun j j' => by
rcases j with ⟨⟩ <;> rcases j' with ⟨⟩ <;> simp }
map f := {
hom := f.hom
wπ := fun i => WalkingPair.casesOn i f.wfst f.wsnd
wι := fun i => WalkingPair.casesOn i f.winl f.winr }
/-- A shorthand for `toBiconeFunctor.obj` -/
abbrev toBicone {X Y : C} (b : BinaryBicone X Y) : Bicone (pairFunction X Y) :=
toBiconeFunctor.obj b
#align category_theory.limits.binary_bicone.to_bicone CategoryTheory.Limits.BinaryBicone.toBicone
/-- A binary bicone is a limit cone if and only if the corresponding bicone is a limit cone. -/
def toBiconeIsLimit {X Y : C} (b : BinaryBicone X Y) :
IsLimit b.toBicone.toCone ≃ IsLimit b.toCone :=
IsLimit.equivIsoLimit <|
Cones.ext (Iso.refl _) fun j => by
cases' j with as; cases as <;> simp
#align category_theory.limits.binary_bicone.to_bicone_is_limit CategoryTheory.Limits.BinaryBicone.toBiconeIsLimit
/-- A binary bicone is a colimit cocone if and only if the corresponding bicone is a colimit
cocone. -/
def toBiconeIsColimit {X Y : C} (b : BinaryBicone X Y) :
IsColimit b.toBicone.toCocone ≃ IsColimit b.toCocone :=
IsColimit.equivIsoColimit <|
Cocones.ext (Iso.refl _) fun j => by
cases' j with as; cases as <;> simp
#align category_theory.limits.binary_bicone.to_bicone_is_colimit CategoryTheory.Limits.BinaryBicone.toBiconeIsColimit
end BinaryBicone
namespace Bicone
/-- Convert a `Bicone` over a function on `WalkingPair` to a BinaryBicone. -/
@[simps]
def toBinaryBiconeFunctor {X Y : C} : Bicone (pairFunction X Y) ⥤ BinaryBicone X Y where
obj b :=
{ pt := b.pt
fst := b.π WalkingPair.left
snd := b.π WalkingPair.right
inl := b.ι WalkingPair.left
inr := b.ι WalkingPair.right
inl_fst := by simp [Bicone.ι_π]
inr_fst := by simp [Bicone.ι_π]
inl_snd := by simp [Bicone.ι_π]
inr_snd := by simp [Bicone.ι_π] }
map f :=
{ hom := f.hom }
/-- A shorthand for `toBinaryBiconeFunctor.obj` -/
abbrev toBinaryBicone {X Y : C} (b : Bicone (pairFunction X Y)) : BinaryBicone X Y :=
toBinaryBiconeFunctor.obj b
#align category_theory.limits.bicone.to_binary_bicone CategoryTheory.Limits.Bicone.toBinaryBicone
/-- A bicone over a pair is a limit cone if and only if the corresponding binary bicone is a limit
cone. -/
def toBinaryBiconeIsLimit {X Y : C} (b : Bicone (pairFunction X Y)) :
IsLimit b.toBinaryBicone.toCone ≃ IsLimit b.toCone :=
IsLimit.equivIsoLimit <| Cones.ext (Iso.refl _) fun j => by rcases j with ⟨⟨⟩⟩ <;> simp
#align category_theory.limits.bicone.to_binary_bicone_is_limit CategoryTheory.Limits.Bicone.toBinaryBiconeIsLimit
/-- A bicone over a pair is a colimit cocone if and only if the corresponding binary bicone is a
colimit cocone. -/
def toBinaryBiconeIsColimit {X Y : C} (b : Bicone (pairFunction X Y)) :
IsColimit b.toBinaryBicone.toCocone ≃ IsColimit b.toCocone :=
IsColimit.equivIsoColimit <| Cocones.ext (Iso.refl _) fun j => by rcases j with ⟨⟨⟩⟩ <;> simp
#align category_theory.limits.bicone.to_binary_bicone_is_colimit CategoryTheory.Limits.Bicone.toBinaryBiconeIsColimit
end Bicone
/-- Structure witnessing that a binary bicone is a limit cone and a limit cocone. -/
-- @[nolint has_nonempty_instance] Porting note (#5171): removed
structure BinaryBicone.IsBilimit {P Q : C} (b : BinaryBicone P Q) where
isLimit : IsLimit b.toCone
isColimit : IsColimit b.toCocone
#align category_theory.limits.binary_bicone.is_bilimit CategoryTheory.Limits.BinaryBicone.IsBilimit
#align category_theory.limits.binary_bicone.is_bilimit.is_limit CategoryTheory.Limits.BinaryBicone.IsBilimit.isLimit
#align category_theory.limits.binary_bicone.is_bilimit.is_colimit CategoryTheory.Limits.BinaryBicone.IsBilimit.isColimit
attribute [inherit_doc BinaryBicone.IsBilimit] BinaryBicone.IsBilimit.isLimit
BinaryBicone.IsBilimit.isColimit
/-- A binary bicone is a bilimit bicone if and only if the corresponding bicone is a bilimit. -/
def BinaryBicone.toBiconeIsBilimit {X Y : C} (b : BinaryBicone X Y) :
b.toBicone.IsBilimit ≃ b.IsBilimit where
toFun h := ⟨b.toBiconeIsLimit h.isLimit, b.toBiconeIsColimit h.isColimit⟩
invFun h := ⟨b.toBiconeIsLimit.symm h.isLimit, b.toBiconeIsColimit.symm h.isColimit⟩
left_inv := fun ⟨h, h'⟩ => by dsimp only; simp
right_inv := fun ⟨h, h'⟩ => by dsimp only; simp
#align category_theory.limits.binary_bicone.to_bicone_is_bilimit CategoryTheory.Limits.BinaryBicone.toBiconeIsBilimit
/-- A bicone over a pair is a bilimit bicone if and only if the corresponding binary bicone is a
bilimit. -/
def Bicone.toBinaryBiconeIsBilimit {X Y : C} (b : Bicone (pairFunction X Y)) :
b.toBinaryBicone.IsBilimit ≃ b.IsBilimit where
toFun h := ⟨b.toBinaryBiconeIsLimit h.isLimit, b.toBinaryBiconeIsColimit h.isColimit⟩
invFun h := ⟨b.toBinaryBiconeIsLimit.symm h.isLimit, b.toBinaryBiconeIsColimit.symm h.isColimit⟩
left_inv := fun ⟨h, h'⟩ => by dsimp only; simp
right_inv := fun ⟨h, h'⟩ => by dsimp only; simp
#align category_theory.limits.bicone.to_binary_bicone_is_bilimit CategoryTheory.Limits.Bicone.toBinaryBiconeIsBilimit
/-- A bicone over `P Q : C`, which is both a limit cone and a colimit cocone.
-/
-- @[nolint has_nonempty_instance] Porting note (#5171): removed
structure BinaryBiproductData (P Q : C) where
bicone : BinaryBicone P Q
isBilimit : bicone.IsBilimit
#align category_theory.limits.binary_biproduct_data CategoryTheory.Limits.BinaryBiproductData
#align category_theory.limits.binary_biproduct_data.is_bilimit CategoryTheory.Limits.BinaryBiproductData.isBilimit
attribute [inherit_doc BinaryBiproductData] BinaryBiproductData.bicone
BinaryBiproductData.isBilimit
/-- `HasBinaryBiproduct P Q` expresses the mere existence of a bicone which is
simultaneously a limit and a colimit of the diagram `pair P Q`.
-/
class HasBinaryBiproduct (P Q : C) : Prop where mk' ::
exists_binary_biproduct : Nonempty (BinaryBiproductData P Q)
#align category_theory.limits.has_binary_biproduct CategoryTheory.Limits.HasBinaryBiproduct
attribute [inherit_doc HasBinaryBiproduct] HasBinaryBiproduct.exists_binary_biproduct
theorem HasBinaryBiproduct.mk {P Q : C} (d : BinaryBiproductData P Q) : HasBinaryBiproduct P Q :=
⟨Nonempty.intro d⟩
#align category_theory.limits.has_binary_biproduct.mk CategoryTheory.Limits.HasBinaryBiproduct.mk
/--
Use the axiom of choice to extract explicit `BinaryBiproductData F` from `HasBinaryBiproduct F`.
-/
def getBinaryBiproductData (P Q : C) [HasBinaryBiproduct P Q] : BinaryBiproductData P Q :=
Classical.choice HasBinaryBiproduct.exists_binary_biproduct
#align category_theory.limits.get_binary_biproduct_data CategoryTheory.Limits.getBinaryBiproductData
/-- A bicone for `P Q` which is both a limit cone and a colimit cocone. -/
def BinaryBiproduct.bicone (P Q : C) [HasBinaryBiproduct P Q] : BinaryBicone P Q :=
(getBinaryBiproductData P Q).bicone
#align category_theory.limits.binary_biproduct.bicone CategoryTheory.Limits.BinaryBiproduct.bicone
/-- `BinaryBiproduct.bicone P Q` is a limit bicone. -/
def BinaryBiproduct.isBilimit (P Q : C) [HasBinaryBiproduct P Q] :
(BinaryBiproduct.bicone P Q).IsBilimit :=
(getBinaryBiproductData P Q).isBilimit
#align category_theory.limits.binary_biproduct.is_bilimit CategoryTheory.Limits.BinaryBiproduct.isBilimit
/-- `BinaryBiproduct.bicone P Q` is a limit cone. -/
def BinaryBiproduct.isLimit (P Q : C) [HasBinaryBiproduct P Q] :
IsLimit (BinaryBiproduct.bicone P Q).toCone :=
(getBinaryBiproductData P Q).isBilimit.isLimit
#align category_theory.limits.binary_biproduct.is_limit CategoryTheory.Limits.BinaryBiproduct.isLimit
/-- `BinaryBiproduct.bicone P Q` is a colimit cocone. -/
def BinaryBiproduct.isColimit (P Q : C) [HasBinaryBiproduct P Q] :
IsColimit (BinaryBiproduct.bicone P Q).toCocone :=
(getBinaryBiproductData P Q).isBilimit.isColimit
#align category_theory.limits.binary_biproduct.is_colimit CategoryTheory.Limits.BinaryBiproduct.isColimit
section
variable (C)
/-- `HasBinaryBiproducts C` represents the existence of a bicone which is
simultaneously a limit and a colimit of the diagram `pair P Q`, for every `P Q : C`.
-/
class HasBinaryBiproducts : Prop where
has_binary_biproduct : ∀ P Q : C, HasBinaryBiproduct P Q
#align category_theory.limits.has_binary_biproducts CategoryTheory.Limits.HasBinaryBiproducts
attribute [instance 100] HasBinaryBiproducts.has_binary_biproduct
/-- A category with finite biproducts has binary biproducts.
This is not an instance as typically in concrete categories there will be
an alternative construction with nicer definitional properties.
-/
theorem hasBinaryBiproducts_of_finite_biproducts [HasFiniteBiproducts C] : HasBinaryBiproducts C :=
{ has_binary_biproduct := fun P Q =>
HasBinaryBiproduct.mk
{ bicone := (biproduct.bicone (pairFunction P Q)).toBinaryBicone
isBilimit := (Bicone.toBinaryBiconeIsBilimit _).symm (biproduct.isBilimit _) } }
#align category_theory.limits.has_binary_biproducts_of_finite_biproducts CategoryTheory.Limits.hasBinaryBiproducts_of_finite_biproducts
end
variable {P Q : C}
instance HasBinaryBiproduct.hasLimit_pair [HasBinaryBiproduct P Q] : HasLimit (pair P Q) :=
HasLimit.mk ⟨_, BinaryBiproduct.isLimit P Q⟩
#align category_theory.limits.has_binary_biproduct.has_limit_pair CategoryTheory.Limits.HasBinaryBiproduct.hasLimit_pair
instance HasBinaryBiproduct.hasColimit_pair [HasBinaryBiproduct P Q] : HasColimit (pair P Q) :=
HasColimit.mk ⟨_, BinaryBiproduct.isColimit P Q⟩
#align category_theory.limits.has_binary_biproduct.has_colimit_pair CategoryTheory.Limits.HasBinaryBiproduct.hasColimit_pair
instance (priority := 100) hasBinaryProducts_of_hasBinaryBiproducts [HasBinaryBiproducts C] :
HasBinaryProducts C where
has_limit F := hasLimitOfIso (diagramIsoPair F).symm
#align category_theory.limits.has_binary_products_of_has_binary_biproducts CategoryTheory.Limits.hasBinaryProducts_of_hasBinaryBiproducts
instance (priority := 100) hasBinaryCoproducts_of_hasBinaryBiproducts [HasBinaryBiproducts C] :
HasBinaryCoproducts C where
has_colimit F := hasColimitOfIso (diagramIsoPair F)
#align category_theory.limits.has_binary_coproducts_of_has_binary_biproducts CategoryTheory.Limits.hasBinaryCoproducts_of_hasBinaryBiproducts
/-- The isomorphism between the specified binary product and the specified binary coproduct for
a pair for a binary biproduct.
-/
def biprodIso (X Y : C) [HasBinaryBiproduct X Y] : Limits.prod X Y ≅ Limits.coprod X Y :=
(IsLimit.conePointUniqueUpToIso (limit.isLimit _) (BinaryBiproduct.isLimit X Y)).trans <|
IsColimit.coconePointUniqueUpToIso (BinaryBiproduct.isColimit X Y) (colimit.isColimit _)
#align category_theory.limits.biprod_iso CategoryTheory.Limits.biprodIso
/-- An arbitrary choice of biproduct of a pair of objects. -/
abbrev biprod (X Y : C) [HasBinaryBiproduct X Y] :=
(BinaryBiproduct.bicone X Y).pt
#align category_theory.limits.biprod CategoryTheory.Limits.biprod
@[inherit_doc biprod]
notation:20 X " ⊞ " Y:20 => biprod X Y
/-- The projection onto the first summand of a binary biproduct. -/
abbrev biprod.fst {X Y : C} [HasBinaryBiproduct X Y] : X ⊞ Y ⟶ X :=
(BinaryBiproduct.bicone X Y).fst
#align category_theory.limits.biprod.fst CategoryTheory.Limits.biprod.fst
/-- The projection onto the second summand of a binary biproduct. -/
abbrev biprod.snd {X Y : C} [HasBinaryBiproduct X Y] : X ⊞ Y ⟶ Y :=
(BinaryBiproduct.bicone X Y).snd
#align category_theory.limits.biprod.snd CategoryTheory.Limits.biprod.snd
/-- The inclusion into the first summand of a binary biproduct. -/
abbrev biprod.inl {X Y : C} [HasBinaryBiproduct X Y] : X ⟶ X ⊞ Y :=
(BinaryBiproduct.bicone X Y).inl
#align category_theory.limits.biprod.inl CategoryTheory.Limits.biprod.inl
/-- The inclusion into the second summand of a binary biproduct. -/
abbrev biprod.inr {X Y : C} [HasBinaryBiproduct X Y] : Y ⟶ X ⊞ Y :=
(BinaryBiproduct.bicone X Y).inr
#align category_theory.limits.biprod.inr CategoryTheory.Limits.biprod.inr
section
variable {X Y : C} [HasBinaryBiproduct X Y]
@[simp]
theorem BinaryBiproduct.bicone_fst : (BinaryBiproduct.bicone X Y).fst = biprod.fst :=
rfl
#align category_theory.limits.binary_biproduct.bicone_fst CategoryTheory.Limits.BinaryBiproduct.bicone_fst
@[simp]
theorem BinaryBiproduct.bicone_snd : (BinaryBiproduct.bicone X Y).snd = biprod.snd :=
rfl
#align category_theory.limits.binary_biproduct.bicone_snd CategoryTheory.Limits.BinaryBiproduct.bicone_snd
@[simp]
theorem BinaryBiproduct.bicone_inl : (BinaryBiproduct.bicone X Y).inl = biprod.inl :=
rfl
#align category_theory.limits.binary_biproduct.bicone_inl CategoryTheory.Limits.BinaryBiproduct.bicone_inl
@[simp]
theorem BinaryBiproduct.bicone_inr : (BinaryBiproduct.bicone X Y).inr = biprod.inr :=
rfl
#align category_theory.limits.binary_biproduct.bicone_inr CategoryTheory.Limits.BinaryBiproduct.bicone_inr
end
@[reassoc] -- Porting note: simp can solve both versions
theorem biprod.inl_fst {X Y : C} [HasBinaryBiproduct X Y] :
(biprod.inl : X ⟶ X ⊞ Y) ≫ (biprod.fst : X ⊞ Y ⟶ X) = 𝟙 X :=
(BinaryBiproduct.bicone X Y).inl_fst
#align category_theory.limits.biprod.inl_fst CategoryTheory.Limits.biprod.inl_fst
@[reassoc] -- Porting note: simp can solve both versions
theorem biprod.inl_snd {X Y : C} [HasBinaryBiproduct X Y] :
(biprod.inl : X ⟶ X ⊞ Y) ≫ (biprod.snd : X ⊞ Y ⟶ Y) = 0 :=
(BinaryBiproduct.bicone X Y).inl_snd
#align category_theory.limits.biprod.inl_snd CategoryTheory.Limits.biprod.inl_snd
@[reassoc] -- Porting note: simp can solve both versions
theorem biprod.inr_fst {X Y : C} [HasBinaryBiproduct X Y] :
(biprod.inr : Y ⟶ X ⊞ Y) ≫ (biprod.fst : X ⊞ Y ⟶ X) = 0 :=
(BinaryBiproduct.bicone X Y).inr_fst
#align category_theory.limits.biprod.inr_fst CategoryTheory.Limits.biprod.inr_fst
@[reassoc] -- Porting note: simp can solve both versions
theorem biprod.inr_snd {X Y : C} [HasBinaryBiproduct X Y] :
(biprod.inr : Y ⟶ X ⊞ Y) ≫ (biprod.snd : X ⊞ Y ⟶ Y) = 𝟙 Y :=
(BinaryBiproduct.bicone X Y).inr_snd
#align category_theory.limits.biprod.inr_snd CategoryTheory.Limits.biprod.inr_snd
/-- Given a pair of maps into the summands of a binary biproduct,
we obtain a map into the binary biproduct. -/
abbrev biprod.lift {W X Y : C} [HasBinaryBiproduct X Y] (f : W ⟶ X) (g : W ⟶ Y) : W ⟶ X ⊞ Y :=
(BinaryBiproduct.isLimit X Y).lift (BinaryFan.mk f g)
#align category_theory.limits.biprod.lift CategoryTheory.Limits.biprod.lift
/-- Given a pair of maps out of the summands of a binary biproduct,
we obtain a map out of the binary biproduct. -/
abbrev biprod.desc {W X Y : C} [HasBinaryBiproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) : X ⊞ Y ⟶ W :=
(BinaryBiproduct.isColimit X Y).desc (BinaryCofan.mk f g)
#align category_theory.limits.biprod.desc CategoryTheory.Limits.biprod.desc
@[reassoc (attr := simp)]
theorem biprod.lift_fst {W X Y : C} [HasBinaryBiproduct X Y] (f : W ⟶ X) (g : W ⟶ Y) :
biprod.lift f g ≫ biprod.fst = f :=
(BinaryBiproduct.isLimit X Y).fac _ ⟨WalkingPair.left⟩
#align category_theory.limits.biprod.lift_fst CategoryTheory.Limits.biprod.lift_fst
@[reassoc (attr := simp)]
theorem biprod.lift_snd {W X Y : C} [HasBinaryBiproduct X Y] (f : W ⟶ X) (g : W ⟶ Y) :
biprod.lift f g ≫ biprod.snd = g :=
(BinaryBiproduct.isLimit X Y).fac _ ⟨WalkingPair.right⟩
#align category_theory.limits.biprod.lift_snd CategoryTheory.Limits.biprod.lift_snd
@[reassoc (attr := simp)]
theorem biprod.inl_desc {W X Y : C} [HasBinaryBiproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) :
biprod.inl ≫ biprod.desc f g = f :=
(BinaryBiproduct.isColimit X Y).fac _ ⟨WalkingPair.left⟩
#align category_theory.limits.biprod.inl_desc CategoryTheory.Limits.biprod.inl_desc
@[reassoc (attr := simp)]
theorem biprod.inr_desc {W X Y : C} [HasBinaryBiproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) :
biprod.inr ≫ biprod.desc f g = g :=
(BinaryBiproduct.isColimit X Y).fac _ ⟨WalkingPair.right⟩
#align category_theory.limits.biprod.inr_desc CategoryTheory.Limits.biprod.inr_desc
instance biprod.mono_lift_of_mono_left {W X Y : C} [HasBinaryBiproduct X Y] (f : W ⟶ X) (g : W ⟶ Y)
[Mono f] : Mono (biprod.lift f g) :=
mono_of_mono_fac <| biprod.lift_fst _ _
#align category_theory.limits.biprod.mono_lift_of_mono_left CategoryTheory.Limits.biprod.mono_lift_of_mono_left
instance biprod.mono_lift_of_mono_right {W X Y : C} [HasBinaryBiproduct X Y] (f : W ⟶ X) (g : W ⟶ Y)
[Mono g] : Mono (biprod.lift f g) :=
mono_of_mono_fac <| biprod.lift_snd _ _
#align category_theory.limits.biprod.mono_lift_of_mono_right CategoryTheory.Limits.biprod.mono_lift_of_mono_right
instance biprod.epi_desc_of_epi_left {W X Y : C} [HasBinaryBiproduct X Y] (f : X ⟶ W) (g : Y ⟶ W)
[Epi f] : Epi (biprod.desc f g) :=
epi_of_epi_fac <| biprod.inl_desc _ _
#align category_theory.limits.biprod.epi_desc_of_epi_left CategoryTheory.Limits.biprod.epi_desc_of_epi_left
instance biprod.epi_desc_of_epi_right {W X Y : C} [HasBinaryBiproduct X Y] (f : X ⟶ W) (g : Y ⟶ W)
[Epi g] : Epi (biprod.desc f g) :=
epi_of_epi_fac <| biprod.inr_desc _ _
#align category_theory.limits.biprod.epi_desc_of_epi_right CategoryTheory.Limits.biprod.epi_desc_of_epi_right
/-- Given a pair of maps between the summands of a pair of binary biproducts,
we obtain a map between the binary biproducts. -/
abbrev biprod.map {W X Y Z : C} [HasBinaryBiproduct W X] [HasBinaryBiproduct Y Z] (f : W ⟶ Y)
(g : X ⟶ Z) : W ⊞ X ⟶ Y ⊞ Z :=
IsLimit.map (BinaryBiproduct.bicone W X).toCone (BinaryBiproduct.isLimit Y Z)
(@mapPair _ _ (pair W X) (pair Y Z) f g)
#align category_theory.limits.biprod.map CategoryTheory.Limits.biprod.map
/-- An alternative to `biprod.map` constructed via colimits.
This construction only exists in order to show it is equal to `biprod.map`. -/
abbrev biprod.map' {W X Y Z : C} [HasBinaryBiproduct W X] [HasBinaryBiproduct Y Z] (f : W ⟶ Y)
(g : X ⟶ Z) : W ⊞ X ⟶ Y ⊞ Z :=
IsColimit.map (BinaryBiproduct.isColimit W X) (BinaryBiproduct.bicone Y Z).toCocone
(@mapPair _ _ (pair W X) (pair Y Z) f g)
#align category_theory.limits.biprod.map' CategoryTheory.Limits.biprod.map'
@[ext]
theorem biprod.hom_ext {X Y Z : C} [HasBinaryBiproduct X Y] (f g : Z ⟶ X ⊞ Y)
(h₀ : f ≫ biprod.fst = g ≫ biprod.fst) (h₁ : f ≫ biprod.snd = g ≫ biprod.snd) : f = g :=
BinaryFan.IsLimit.hom_ext (BinaryBiproduct.isLimit X Y) h₀ h₁
#align category_theory.limits.biprod.hom_ext CategoryTheory.Limits.biprod.hom_ext
@[ext]
theorem biprod.hom_ext' {X Y Z : C} [HasBinaryBiproduct X Y] (f g : X ⊞ Y ⟶ Z)
(h₀ : biprod.inl ≫ f = biprod.inl ≫ g) (h₁ : biprod.inr ≫ f = biprod.inr ≫ g) : f = g :=
BinaryCofan.IsColimit.hom_ext (BinaryBiproduct.isColimit X Y) h₀ h₁
#align category_theory.limits.biprod.hom_ext' CategoryTheory.Limits.biprod.hom_ext'
/-- The canonical isomorphism between the chosen biproduct and the chosen product. -/
def biprod.isoProd (X Y : C) [HasBinaryBiproduct X Y] : X ⊞ Y ≅ X ⨯ Y :=
IsLimit.conePointUniqueUpToIso (BinaryBiproduct.isLimit X Y) (limit.isLimit _)
#align category_theory.limits.biprod.iso_prod CategoryTheory.Limits.biprod.isoProd
@[simp]
theorem biprod.isoProd_hom {X Y : C} [HasBinaryBiproduct X Y] :
(biprod.isoProd X Y).hom = prod.lift biprod.fst biprod.snd := by
ext <;> simp [biprod.isoProd]
#align category_theory.limits.biprod.iso_prod_hom CategoryTheory.Limits.biprod.isoProd_hom
@[simp]
theorem biprod.isoProd_inv {X Y : C} [HasBinaryBiproduct X Y] :
(biprod.isoProd X Y).inv = biprod.lift prod.fst prod.snd := by
ext <;> simp [Iso.inv_comp_eq]
#align category_theory.limits.biprod.iso_prod_inv CategoryTheory.Limits.biprod.isoProd_inv
/-- The canonical isomorphism between the chosen biproduct and the chosen coproduct. -/
def biprod.isoCoprod (X Y : C) [HasBinaryBiproduct X Y] : X ⊞ Y ≅ X ⨿ Y :=
IsColimit.coconePointUniqueUpToIso (BinaryBiproduct.isColimit X Y) (colimit.isColimit _)
#align category_theory.limits.biprod.iso_coprod CategoryTheory.Limits.biprod.isoCoprod
@[simp]
theorem biprod.isoCoprod_inv {X Y : C} [HasBinaryBiproduct X Y] :
(biprod.isoCoprod X Y).inv = coprod.desc biprod.inl biprod.inr := by
ext <;> simp [biprod.isoCoprod]
#align category_theory.limits.biprod.iso_coprod_inv CategoryTheory.Limits.biprod.isoCoprod_inv
@[simp]
theorem biprod_isoCoprod_hom {X Y : C} [HasBinaryBiproduct X Y] :
(biprod.isoCoprod X Y).hom = biprod.desc coprod.inl coprod.inr := by
ext <;> simp [← Iso.eq_comp_inv]
#align category_theory.limits.biprod_iso_coprod_hom CategoryTheory.Limits.biprod_isoCoprod_hom
theorem biprod.map_eq_map' {W X Y Z : C} [HasBinaryBiproduct W X] [HasBinaryBiproduct Y Z]
(f : W ⟶ Y) (g : X ⟶ Z) : biprod.map f g = biprod.map' f g := by
ext
· simp only [mapPair_left, IsColimit.ι_map, IsLimit.map_π, biprod.inl_fst_assoc,
Category.assoc, ← BinaryBicone.toCone_π_app_left, ← BinaryBiproduct.bicone_fst, ←
BinaryBicone.toCocone_ι_app_left, ← BinaryBiproduct.bicone_inl];
dsimp; simp
· simp only [mapPair_left, IsColimit.ι_map, IsLimit.map_π, zero_comp, biprod.inl_snd_assoc,
Category.assoc, ← BinaryBicone.toCone_π_app_right, ← BinaryBiproduct.bicone_snd, ←
BinaryBicone.toCocone_ι_app_left, ← BinaryBiproduct.bicone_inl]
simp
· simp only [mapPair_right, biprod.inr_fst_assoc, IsColimit.ι_map, IsLimit.map_π, zero_comp,
Category.assoc, ← BinaryBicone.toCone_π_app_left, ← BinaryBiproduct.bicone_fst, ←
BinaryBicone.toCocone_ι_app_right, ← BinaryBiproduct.bicone_inr]
simp
· simp only [mapPair_right, IsColimit.ι_map, IsLimit.map_π, biprod.inr_snd_assoc,
Category.assoc, ← BinaryBicone.toCone_π_app_right, ← BinaryBiproduct.bicone_snd, ←
BinaryBicone.toCocone_ι_app_right, ← BinaryBiproduct.bicone_inr]
simp
#align category_theory.limits.biprod.map_eq_map' CategoryTheory.Limits.biprod.map_eq_map'
instance biprod.inl_mono {X Y : C} [HasBinaryBiproduct X Y] :
IsSplitMono (biprod.inl : X ⟶ X ⊞ Y) :=
IsSplitMono.mk' { retraction := biprod.fst }
#align category_theory.limits.biprod.inl_mono CategoryTheory.Limits.biprod.inl_mono
instance biprod.inr_mono {X Y : C} [HasBinaryBiproduct X Y] :
IsSplitMono (biprod.inr : Y ⟶ X ⊞ Y) :=
IsSplitMono.mk' { retraction := biprod.snd }
#align category_theory.limits.biprod.inr_mono CategoryTheory.Limits.biprod.inr_mono
instance biprod.fst_epi {X Y : C} [HasBinaryBiproduct X Y] : IsSplitEpi (biprod.fst : X ⊞ Y ⟶ X) :=
IsSplitEpi.mk' { section_ := biprod.inl }
#align category_theory.limits.biprod.fst_epi CategoryTheory.Limits.biprod.fst_epi
instance biprod.snd_epi {X Y : C} [HasBinaryBiproduct X Y] : IsSplitEpi (biprod.snd : X ⊞ Y ⟶ Y) :=
IsSplitEpi.mk' { section_ := biprod.inr }
#align category_theory.limits.biprod.snd_epi CategoryTheory.Limits.biprod.snd_epi
@[reassoc (attr := simp)]
theorem biprod.map_fst {W X Y Z : C} [HasBinaryBiproduct W X] [HasBinaryBiproduct Y Z] (f : W ⟶ Y)
(g : X ⟶ Z) : biprod.map f g ≫ biprod.fst = biprod.fst ≫ f :=
IsLimit.map_π _ _ _ (⟨WalkingPair.left⟩ : Discrete WalkingPair)
#align category_theory.limits.biprod.map_fst CategoryTheory.Limits.biprod.map_fst
@[reassoc (attr := simp)]
theorem biprod.map_snd {W X Y Z : C} [HasBinaryBiproduct W X] [HasBinaryBiproduct Y Z] (f : W ⟶ Y)
(g : X ⟶ Z) : biprod.map f g ≫ biprod.snd = biprod.snd ≫ g :=
IsLimit.map_π _ _ _ (⟨WalkingPair.right⟩ : Discrete WalkingPair)
#align category_theory.limits.biprod.map_snd CategoryTheory.Limits.biprod.map_snd
-- Because `biprod.map` is defined in terms of `lim` rather than `colim`,
-- we need to provide additional `simp` lemmas.
@[reassoc (attr := simp)]
theorem biprod.inl_map {W X Y Z : C} [HasBinaryBiproduct W X] [HasBinaryBiproduct Y Z] (f : W ⟶ Y)
(g : X ⟶ Z) : biprod.inl ≫ biprod.map f g = f ≫ biprod.inl := by
rw [biprod.map_eq_map']
exact IsColimit.ι_map (BinaryBiproduct.isColimit W X) _ _ ⟨WalkingPair.left⟩
#align category_theory.limits.biprod.inl_map CategoryTheory.Limits.biprod.inl_map
@[reassoc (attr := simp)]
theorem biprod.inr_map {W X Y Z : C} [HasBinaryBiproduct W X] [HasBinaryBiproduct Y Z] (f : W ⟶ Y)
(g : X ⟶ Z) : biprod.inr ≫ biprod.map f g = g ≫ biprod.inr := by
rw [biprod.map_eq_map']
exact IsColimit.ι_map (BinaryBiproduct.isColimit W X) _ _ ⟨WalkingPair.right⟩
#align category_theory.limits.biprod.inr_map CategoryTheory.Limits.biprod.inr_map
/-- Given a pair of isomorphisms between the summands of a pair of binary biproducts,
we obtain an isomorphism between the binary biproducts. -/
@[simps]
def biprod.mapIso {W X Y Z : C} [HasBinaryBiproduct W X] [HasBinaryBiproduct Y Z] (f : W ≅ Y)
(g : X ≅ Z) : W ⊞ X ≅ Y ⊞ Z where
hom := biprod.map f.hom g.hom
inv := biprod.map f.inv g.inv
#align category_theory.limits.biprod.map_iso CategoryTheory.Limits.biprod.mapIso
/-- Auxiliary lemma for `biprod.uniqueUpToIso`. -/
theorem biprod.conePointUniqueUpToIso_hom (X Y : C) [HasBinaryBiproduct X Y] {b : BinaryBicone X Y}
(hb : b.IsBilimit) :
(hb.isLimit.conePointUniqueUpToIso (BinaryBiproduct.isLimit _ _)).hom =
biprod.lift b.fst b.snd := rfl
#align category_theory.limits.biprod.cone_point_unique_up_to_iso_hom CategoryTheory.Limits.biprod.conePointUniqueUpToIso_hom
/-- Auxiliary lemma for `biprod.uniqueUpToIso`. -/
theorem biprod.conePointUniqueUpToIso_inv (X Y : C) [HasBinaryBiproduct X Y] {b : BinaryBicone X Y}
(hb : b.IsBilimit) :
(hb.isLimit.conePointUniqueUpToIso (BinaryBiproduct.isLimit _ _)).inv =
biprod.desc b.inl b.inr := by
refine biprod.hom_ext' _ _ (hb.isLimit.hom_ext fun j => ?_) (hb.isLimit.hom_ext fun j => ?_)
all_goals
simp only [Category.assoc, IsLimit.conePointUniqueUpToIso_inv_comp]
rcases j with ⟨⟨⟩⟩
all_goals simp
#align category_theory.limits.biprod.cone_point_unique_up_to_iso_inv CategoryTheory.Limits.biprod.conePointUniqueUpToIso_inv
/-- Binary biproducts are unique up to isomorphism. This already follows because bilimits are
limits, but in the case of biproducts we can give an isomorphism with particularly nice
definitional properties, namely that `biprod.lift b.fst b.snd` and `biprod.desc b.inl b.inr`
are inverses of each other. -/
@[simps]
def biprod.uniqueUpToIso (X Y : C) [HasBinaryBiproduct X Y] {b : BinaryBicone X Y}
(hb : b.IsBilimit) : b.pt ≅ X ⊞ Y where
hom := biprod.lift b.fst b.snd
inv := biprod.desc b.inl b.inr
hom_inv_id := by
rw [← biprod.conePointUniqueUpToIso_hom X Y hb, ←
biprod.conePointUniqueUpToIso_inv X Y hb, Iso.hom_inv_id]
inv_hom_id := by
rw [← biprod.conePointUniqueUpToIso_hom X Y hb, ←
biprod.conePointUniqueUpToIso_inv X Y hb, Iso.inv_hom_id]
#align category_theory.limits.biprod.unique_up_to_iso CategoryTheory.Limits.biprod.uniqueUpToIso
-- There are three further variations,
-- about `IsIso biprod.inr`, `IsIso biprod.fst` and `IsIso biprod.snd`,
-- but any one suffices to prove `indecomposable_of_simple`
-- and they are likely not separately useful.
theorem biprod.isIso_inl_iff_id_eq_fst_comp_inl (X Y : C) [HasBinaryBiproduct X Y] :
IsIso (biprod.inl : X ⟶ X ⊞ Y) ↔ 𝟙 (X ⊞ Y) = biprod.fst ≫ biprod.inl := by
constructor
· intro h
have := (cancel_epi (inv biprod.inl : X ⊞ Y ⟶ X)).2 <| @biprod.inl_fst _ _ _ X Y _
rw [IsIso.inv_hom_id_assoc, Category.comp_id] at this
rw [this, IsIso.inv_hom_id]
· intro h
exact ⟨⟨biprod.fst, biprod.inl_fst, h.symm⟩⟩
#align category_theory.limits.biprod.is_iso_inl_iff_id_eq_fst_comp_inl CategoryTheory.Limits.biprod.isIso_inl_iff_id_eq_fst_comp_inl
section BiprodKernel
section BinaryBicone
variable {X Y : C} (c : BinaryBicone X Y)
/-- A kernel fork for the kernel of `BinaryBicone.fst`. It consists of the morphism
`BinaryBicone.inr`. -/
def BinaryBicone.fstKernelFork : KernelFork c.fst :=
KernelFork.ofι c.inr c.inr_fst
#align category_theory.limits.binary_bicone.fst_kernel_fork CategoryTheory.Limits.BinaryBicone.fstKernelFork
@[simp]
theorem BinaryBicone.fstKernelFork_ι : (BinaryBicone.fstKernelFork c).ι = c.inr := rfl
#align category_theory.limits.binary_bicone.fst_kernel_fork_ι CategoryTheory.Limits.BinaryBicone.fstKernelFork_ι
/-- A kernel fork for the kernel of `BinaryBicone.snd`. It consists of the morphism
`BinaryBicone.inl`. -/
def BinaryBicone.sndKernelFork : KernelFork c.snd :=
KernelFork.ofι c.inl c.inl_snd
#align category_theory.limits.binary_bicone.snd_kernel_fork CategoryTheory.Limits.BinaryBicone.sndKernelFork
@[simp]
theorem BinaryBicone.sndKernelFork_ι : (BinaryBicone.sndKernelFork c).ι = c.inl := rfl
#align category_theory.limits.binary_bicone.snd_kernel_fork_ι CategoryTheory.Limits.BinaryBicone.sndKernelFork_ι
/-- A cokernel cofork for the cokernel of `BinaryBicone.inl`. It consists of the morphism
`BinaryBicone.snd`. -/
def BinaryBicone.inlCokernelCofork : CokernelCofork c.inl :=
CokernelCofork.ofπ c.snd c.inl_snd
#align category_theory.limits.binary_bicone.inl_cokernel_cofork CategoryTheory.Limits.BinaryBicone.inlCokernelCofork
@[simp]
theorem BinaryBicone.inlCokernelCofork_π : (BinaryBicone.inlCokernelCofork c).π = c.snd := rfl
#align category_theory.limits.binary_bicone.inl_cokernel_cofork_π CategoryTheory.Limits.BinaryBicone.inlCokernelCofork_π
/-- A cokernel cofork for the cokernel of `BinaryBicone.inr`. It consists of the morphism
`BinaryBicone.fst`. -/
def BinaryBicone.inrCokernelCofork : CokernelCofork c.inr :=
CokernelCofork.ofπ c.fst c.inr_fst
#align category_theory.limits.binary_bicone.inr_cokernel_cofork CategoryTheory.Limits.BinaryBicone.inrCokernelCofork
@[simp]
theorem BinaryBicone.inrCokernelCofork_π : (BinaryBicone.inrCokernelCofork c).π = c.fst := rfl
#align category_theory.limits.binary_bicone.inr_cokernel_cofork_π CategoryTheory.Limits.BinaryBicone.inrCokernelCofork_π
variable {c}
/-- The fork defined in `BinaryBicone.fstKernelFork` is indeed a kernel. -/
def BinaryBicone.isLimitFstKernelFork (i : IsLimit c.toCone) : IsLimit c.fstKernelFork :=
Fork.IsLimit.mk' _ fun s =>
⟨s.ι ≫ c.snd, by apply BinaryFan.IsLimit.hom_ext i <;> simp, fun hm => by simp [← hm]⟩
#align category_theory.limits.binary_bicone.is_limit_fst_kernel_fork CategoryTheory.Limits.BinaryBicone.isLimitFstKernelFork
/-- The fork defined in `BinaryBicone.sndKernelFork` is indeed a kernel. -/
def BinaryBicone.isLimitSndKernelFork (i : IsLimit c.toCone) : IsLimit c.sndKernelFork :=
Fork.IsLimit.mk' _ fun s =>
⟨s.ι ≫ c.fst, by apply BinaryFan.IsLimit.hom_ext i <;> simp, fun hm => by simp [← hm]⟩
#align category_theory.limits.binary_bicone.is_limit_snd_kernel_fork CategoryTheory.Limits.BinaryBicone.isLimitSndKernelFork
/-- The cofork defined in `BinaryBicone.inlCokernelCofork` is indeed a cokernel. -/
def BinaryBicone.isColimitInlCokernelCofork (i : IsColimit c.toCocone) :
IsColimit c.inlCokernelCofork :=
Cofork.IsColimit.mk' _ fun s =>
⟨c.inr ≫ s.π, by apply BinaryCofan.IsColimit.hom_ext i <;> simp, fun hm => by simp [← hm]⟩
#align category_theory.limits.binary_bicone.is_colimit_inl_cokernel_cofork CategoryTheory.Limits.BinaryBicone.isColimitInlCokernelCofork
/-- The cofork defined in `BinaryBicone.inrCokernelCofork` is indeed a cokernel. -/
def BinaryBicone.isColimitInrCokernelCofork (i : IsColimit c.toCocone) :
IsColimit c.inrCokernelCofork :=
Cofork.IsColimit.mk' _ fun s =>
⟨c.inl ≫ s.π, by apply BinaryCofan.IsColimit.hom_ext i <;> simp, fun hm => by simp [← hm]⟩
#align category_theory.limits.binary_bicone.is_colimit_inr_cokernel_cofork CategoryTheory.Limits.BinaryBicone.isColimitInrCokernelCofork
end BinaryBicone
section HasBinaryBiproduct
variable (X Y : C) [HasBinaryBiproduct X Y]
/-- A kernel fork for the kernel of `biprod.fst`. It consists of the
morphism `biprod.inr`. -/
def biprod.fstKernelFork : KernelFork (biprod.fst : X ⊞ Y ⟶ X) :=
BinaryBicone.fstKernelFork _
#align category_theory.limits.biprod.fst_kernel_fork CategoryTheory.Limits.biprod.fstKernelFork
@[simp]
theorem biprod.fstKernelFork_ι : Fork.ι (biprod.fstKernelFork X Y) = (biprod.inr : Y ⟶ X ⊞ Y) :=
rfl
#align category_theory.limits.biprod.fst_kernel_fork_ι CategoryTheory.Limits.biprod.fstKernelFork_ι
/-- The fork `biprod.fstKernelFork` is indeed a limit. -/
def biprod.isKernelFstKernelFork : IsLimit (biprod.fstKernelFork X Y) :=
BinaryBicone.isLimitFstKernelFork (BinaryBiproduct.isLimit _ _)
#align category_theory.limits.biprod.is_kernel_fst_kernel_fork CategoryTheory.Limits.biprod.isKernelFstKernelFork
/-- A kernel fork for the kernel of `biprod.snd`. It consists of the
morphism `biprod.inl`. -/
def biprod.sndKernelFork : KernelFork (biprod.snd : X ⊞ Y ⟶ Y) :=
BinaryBicone.sndKernelFork _
#align category_theory.limits.biprod.snd_kernel_fork CategoryTheory.Limits.biprod.sndKernelFork
@[simp]
theorem biprod.sndKernelFork_ι : Fork.ι (biprod.sndKernelFork X Y) = (biprod.inl : X ⟶ X ⊞ Y) :=
rfl
#align category_theory.limits.biprod.snd_kernel_fork_ι CategoryTheory.Limits.biprod.sndKernelFork_ι
/-- The fork `biprod.sndKernelFork` is indeed a limit. -/
def biprod.isKernelSndKernelFork : IsLimit (biprod.sndKernelFork X Y) :=
BinaryBicone.isLimitSndKernelFork (BinaryBiproduct.isLimit _ _)
#align category_theory.limits.biprod.is_kernel_snd_kernel_fork CategoryTheory.Limits.biprod.isKernelSndKernelFork
/-- A cokernel cofork for the cokernel of `biprod.inl`. It consists of the
morphism `biprod.snd`. -/
def biprod.inlCokernelCofork : CokernelCofork (biprod.inl : X ⟶ X ⊞ Y) :=
BinaryBicone.inlCokernelCofork _
#align category_theory.limits.biprod.inl_cokernel_cofork CategoryTheory.Limits.biprod.inlCokernelCofork
@[simp]
theorem biprod.inlCokernelCofork_π : Cofork.π (biprod.inlCokernelCofork X Y) = biprod.snd :=
rfl
#align category_theory.limits.biprod.inl_cokernel_cofork_π CategoryTheory.Limits.biprod.inlCokernelCofork_π
/-- The cofork `biprod.inlCokernelFork` is indeed a colimit. -/
def biprod.isCokernelInlCokernelFork : IsColimit (biprod.inlCokernelCofork X Y) :=
BinaryBicone.isColimitInlCokernelCofork (BinaryBiproduct.isColimit _ _)
#align category_theory.limits.biprod.is_cokernel_inl_cokernel_fork CategoryTheory.Limits.biprod.isCokernelInlCokernelFork
/-- A cokernel cofork for the cokernel of `biprod.inr`. It consists of the
morphism `biprod.fst`. -/
def biprod.inrCokernelCofork : CokernelCofork (biprod.inr : Y ⟶ X ⊞ Y) :=
BinaryBicone.inrCokernelCofork _
#align category_theory.limits.biprod.inr_cokernel_cofork CategoryTheory.Limits.biprod.inrCokernelCofork
@[simp]
theorem biprod.inrCokernelCofork_π : Cofork.π (biprod.inrCokernelCofork X Y) = biprod.fst :=
rfl
#align category_theory.limits.biprod.inr_cokernel_cofork_π CategoryTheory.Limits.biprod.inrCokernelCofork_π
/-- The cofork `biprod.inrCokernelFork` is indeed a colimit. -/
def biprod.isCokernelInrCokernelFork : IsColimit (biprod.inrCokernelCofork X Y) :=
BinaryBicone.isColimitInrCokernelCofork (BinaryBiproduct.isColimit _ _)
#align category_theory.limits.biprod.is_cokernel_inr_cokernel_fork CategoryTheory.Limits.biprod.isCokernelInrCokernelFork
end HasBinaryBiproduct
variable {X Y : C} [HasBinaryBiproduct X Y]
instance : HasKernel (biprod.fst : X ⊞ Y ⟶ X) :=
HasLimit.mk ⟨_, biprod.isKernelFstKernelFork X Y⟩
/-- The kernel of `biprod.fst : X ⊞ Y ⟶ X` is `Y`. -/
@[simps!]
def kernelBiprodFstIso : kernel (biprod.fst : X ⊞ Y ⟶ X) ≅ Y :=
limit.isoLimitCone ⟨_, biprod.isKernelFstKernelFork X Y⟩
#align category_theory.limits.kernel_biprod_fst_iso CategoryTheory.Limits.kernelBiprodFstIso
instance : HasKernel (biprod.snd : X ⊞ Y ⟶ Y) :=
HasLimit.mk ⟨_, biprod.isKernelSndKernelFork X Y⟩
/-- The kernel of `biprod.snd : X ⊞ Y ⟶ Y` is `X`. -/
@[simps!]
def kernelBiprodSndIso : kernel (biprod.snd : X ⊞ Y ⟶ Y) ≅ X :=
limit.isoLimitCone ⟨_, biprod.isKernelSndKernelFork X Y⟩
#align category_theory.limits.kernel_biprod_snd_iso CategoryTheory.Limits.kernelBiprodSndIso
instance : HasCokernel (biprod.inl : X ⟶ X ⊞ Y) :=
HasColimit.mk ⟨_, biprod.isCokernelInlCokernelFork X Y⟩
/-- The cokernel of `biprod.inl : X ⟶ X ⊞ Y` is `Y`. -/
@[simps!]
def cokernelBiprodInlIso : cokernel (biprod.inl : X ⟶ X ⊞ Y) ≅ Y :=
colimit.isoColimitCocone ⟨_, biprod.isCokernelInlCokernelFork X Y⟩
#align category_theory.limits.cokernel_biprod_inl_iso CategoryTheory.Limits.cokernelBiprodInlIso
instance : HasCokernel (biprod.inr : Y ⟶ X ⊞ Y) :=
HasColimit.mk ⟨_, biprod.isCokernelInrCokernelFork X Y⟩
/-- The cokernel of `biprod.inr : Y ⟶ X ⊞ Y` is `X`. -/
@[simps!]
def cokernelBiprodInrIso : cokernel (biprod.inr : Y ⟶ X ⊞ Y) ≅ X :=
colimit.isoColimitCocone ⟨_, biprod.isCokernelInrCokernelFork X Y⟩
#align category_theory.limits.cokernel_biprod_inr_iso CategoryTheory.Limits.cokernelBiprodInrIso
end BiprodKernel
section IsZero
/-- If `Y` is a zero object, `X ≅ X ⊞ Y` for any `X`. -/
@[simps!]
def isoBiprodZero {X Y : C} [HasBinaryBiproduct X Y] (hY : IsZero Y) : X ≅ X ⊞ Y where
hom := biprod.inl
inv := biprod.fst
inv_hom_id := by
apply CategoryTheory.Limits.biprod.hom_ext <;>
simp only [Category.assoc, biprod.inl_fst, Category.comp_id, Category.id_comp, biprod.inl_snd,
comp_zero]
apply hY.eq_of_tgt
#align category_theory.limits.iso_biprod_zero CategoryTheory.Limits.isoBiprodZero
/-- If `X` is a zero object, `Y ≅ X ⊞ Y` for any `Y`. -/
@[simps]
def isoZeroBiprod {X Y : C} [HasBinaryBiproduct X Y] (hY : IsZero X) : Y ≅ X ⊞ Y where
hom := biprod.inr
inv := biprod.snd
inv_hom_id := by
apply CategoryTheory.Limits.biprod.hom_ext <;>
simp only [Category.assoc, biprod.inr_snd, Category.comp_id, Category.id_comp, biprod.inr_fst,
comp_zero]
apply hY.eq_of_tgt
#align category_theory.limits.iso_zero_biprod CategoryTheory.Limits.isoZeroBiprod
@[simp]
lemma biprod_isZero_iff (A B : C) [HasBinaryBiproduct A B] :
IsZero (biprod A B) ↔ IsZero A ∧ IsZero B := by
constructor
· intro h
simp only [IsZero.iff_id_eq_zero] at h ⊢
simp only [show 𝟙 A = biprod.inl ≫ 𝟙 (A ⊞ B) ≫ biprod.fst by simp,
show 𝟙 B = biprod.inr ≫ 𝟙 (A ⊞ B) ≫ biprod.snd by simp, h, zero_comp, comp_zero,
and_self]
· rintro ⟨hA, hB⟩
rw [IsZero.iff_id_eq_zero]
apply biprod.hom_ext
· apply hA.eq_of_tgt
· apply hB.eq_of_tgt
end IsZero
section
variable [HasBinaryBiproducts C]
/-- The braiding isomorphism which swaps a binary biproduct. -/
@[simps]
def biprod.braiding (P Q : C) : P ⊞ Q ≅ Q ⊞ P where
hom := biprod.lift biprod.snd biprod.fst
inv := biprod.lift biprod.snd biprod.fst
#align category_theory.limits.biprod.braiding CategoryTheory.Limits.biprod.braiding
/-- An alternative formula for the braiding isomorphism which swaps a binary biproduct,
using the fact that the biproduct is a coproduct.
-/
@[simps]
def biprod.braiding' (P Q : C) : P ⊞ Q ≅ Q ⊞ P where
hom := biprod.desc biprod.inr biprod.inl
inv := biprod.desc biprod.inr biprod.inl
#align category_theory.limits.biprod.braiding' CategoryTheory.Limits.biprod.braiding'
theorem biprod.braiding'_eq_braiding {P Q : C} : biprod.braiding' P Q = biprod.braiding P Q := by
aesop_cat
#align category_theory.limits.biprod.braiding'_eq_braiding CategoryTheory.Limits.biprod.braiding'_eq_braiding
/-- The braiding isomorphism can be passed through a map by swapping the order. -/
@[reassoc]
theorem biprod.braid_natural {W X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ W) :
biprod.map f g ≫ (biprod.braiding _ _).hom = (biprod.braiding _ _).hom ≫ biprod.map g f := by
aesop_cat
#align category_theory.limits.biprod.braid_natural CategoryTheory.Limits.biprod.braid_natural
@[reassoc]
theorem biprod.braiding_map_braiding {W X Y Z : C} (f : W ⟶ Y) (g : X ⟶ Z) :
(biprod.braiding X W).hom ≫ biprod.map f g ≫ (biprod.braiding Y Z).hom = biprod.map g f := by
aesop_cat
#align category_theory.limits.biprod.braiding_map_braiding CategoryTheory.Limits.biprod.braiding_map_braiding
@[reassoc (attr := simp)]
| Mathlib/CategoryTheory/Limits/Shapes/Biproducts.lean | 2,158 | 2,160 | theorem biprod.symmetry' (P Q : C) :
biprod.lift biprod.snd biprod.fst ≫ biprod.lift biprod.snd biprod.fst = 𝟙 (P ⊞ Q) := by |
aesop_cat
|
/-
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.Init.Function
import Mathlib.Logic.Function.Basic
#align_import data.sigma.basic from "leanprover-community/mathlib"@"a148d797a1094ab554ad4183a4ad6f130358ef64"
/-!
# Sigma types
This file proves basic results about sigma types.
A sigma type is a dependent pair type. Like `α × β` but where the type of the second component
depends on the first component. More precisely, given `β : ι → Type*`, `Sigma β` is made of stuff
which is of type `β i` for some `i : ι`, so the sigma type is a disjoint union of types.
For example, the sum type `X ⊕ Y` can be emulated using a sigma type, by taking `ι` with
exactly two elements (see `Equiv.sumEquivSigmaBool`).
`Σ x, A x` is notation for `Sigma A` (note that this is `\Sigma`, not the sum operator `∑`).
`Σ x y z ..., A x y z ...` is notation for `Σ x, Σ y, Σ z, ..., A x y z ...`. Here we have
`α : Type*`, `β : α → Type*`, `γ : Π a : α, β a → Type*`, ...,
`A : Π (a : α) (b : β a) (c : γ a b) ..., Type*` with `x : α` `y : β x`, `z : γ x y`, ...
## Notes
The definition of `Sigma` takes values in `Type*`. This effectively forbids `Prop`- valued sigma
types. To that effect, we have `PSigma`, which takes value in `Sort*` and carries a more
complicated universe signature as a consequence.
-/
open Function
section Sigma
variable {α α₁ α₂ : Type*} {β : α → Type*} {β₁ : α₁ → Type*} {β₂ : α₂ → Type*}
namespace Sigma
instance instInhabitedSigma [Inhabited α] [Inhabited (β default)] : Inhabited (Sigma β) :=
⟨⟨default, default⟩⟩
instance instDecidableEqSigma [h₁ : DecidableEq α] [h₂ : ∀ a, DecidableEq (β a)] :
DecidableEq (Sigma β)
| ⟨a₁, b₁⟩, ⟨a₂, b₂⟩ =>
match a₁, b₁, a₂, b₂, h₁ a₁ a₂ with
| _, b₁, _, b₂, isTrue (Eq.refl _) =>
match b₁, b₂, h₂ _ b₁ b₂ with
| _, _, isTrue (Eq.refl _) => isTrue rfl
| _, _, isFalse n => isFalse fun h ↦ Sigma.noConfusion h fun _ e₂ ↦ n <| eq_of_heq e₂
| _, _, _, _, isFalse n => isFalse fun h ↦ Sigma.noConfusion h fun e₁ _ ↦ n e₁
-- sometimes the built-in injectivity support does not work
@[simp] -- @[nolint simpNF]
theorem mk.inj_iff {a₁ a₂ : α} {b₁ : β a₁} {b₂ : β a₂} :
Sigma.mk a₁ b₁ = ⟨a₂, b₂⟩ ↔ a₁ = a₂ ∧ HEq b₁ b₂ :=
⟨fun h ↦ by cases h; simp,
fun ⟨h₁, h₂⟩ ↦ by subst h₁; rw [eq_of_heq h₂]⟩
#align sigma.mk.inj_iff Sigma.mk.inj_iff
@[simp]
theorem eta : ∀ x : Σa, β a, Sigma.mk x.1 x.2 = x
| ⟨_, _⟩ => rfl
#align sigma.eta Sigma.eta
#align sigma.ext Sigma.ext
theorem ext_iff {x₀ x₁ : Sigma β} : x₀ = x₁ ↔ x₀.1 = x₁.1 ∧ HEq x₀.2 x₁.2 := by
cases x₀; cases x₁; exact Sigma.mk.inj_iff
#align sigma.ext_iff Sigma.ext_iff
/-- A version of `Iff.mp Sigma.ext_iff` for functions from a nonempty type to a sigma type. -/
theorem _root_.Function.eq_of_sigmaMk_comp {γ : Type*} [Nonempty γ]
{a b : α} {f : γ → β a} {g : γ → β b} (h : Sigma.mk a ∘ f = Sigma.mk b ∘ g) :
a = b ∧ HEq f g := by
rcases ‹Nonempty γ› with ⟨i⟩
obtain rfl : a = b := congr_arg Sigma.fst (congr_fun h i)
simpa [funext_iff] using h
/-- A specialized ext lemma for equality of sigma types over an indexed subtype. -/
@[ext]
theorem subtype_ext {β : Type*} {p : α → β → Prop} :
∀ {x₀ x₁ : Σa, Subtype (p a)}, x₀.fst = x₁.fst → (x₀.snd : β) = x₁.snd → x₀ = x₁
| ⟨_, _, _⟩, ⟨_, _, _⟩, rfl, rfl => rfl
#align sigma.subtype_ext Sigma.subtype_ext
theorem subtype_ext_iff {β : Type*} {p : α → β → Prop} {x₀ x₁ : Σa, Subtype (p a)} :
x₀ = x₁ ↔ x₀.fst = x₁.fst ∧ (x₀.snd : β) = x₁.snd :=
⟨fun h ↦ h ▸ ⟨rfl, rfl⟩, fun ⟨h₁, h₂⟩ ↦ subtype_ext h₁ h₂⟩
#align sigma.subtype_ext_iff Sigma.subtype_ext_iff
@[simp]
theorem «forall» {p : (Σa, β a) → Prop} : (∀ x, p x) ↔ ∀ a b, p ⟨a, b⟩ :=
⟨fun h a b ↦ h ⟨a, b⟩, fun h ⟨a, b⟩ ↦ h a b⟩
#align sigma.forall Sigma.forall
@[simp]
theorem «exists» {p : (Σa, β a) → Prop} : (∃ x, p x) ↔ ∃ a b, p ⟨a, b⟩ :=
⟨fun ⟨⟨a, b⟩, h⟩ ↦ ⟨a, b, h⟩, fun ⟨a, b, h⟩ ↦ ⟨⟨a, b⟩, h⟩⟩
#align sigma.exists Sigma.exists
lemma exists' {p : ∀ a, β a → Prop} : (∃ a b, p a b) ↔ ∃ x : Σ a, β a, p x.1 x.2 :=
(Sigma.exists (p := fun x ↦ p x.1 x.2)).symm
lemma forall' {p : ∀ a, β a → Prop} : (∀ a b, p a b) ↔ ∀ x : Σ a, β a, p x.1 x.2 :=
(Sigma.forall (p := fun x ↦ p x.1 x.2)).symm
theorem _root_.sigma_mk_injective {i : α} : Injective (@Sigma.mk α β i)
| _, _, rfl => rfl
#align sigma_mk_injective sigma_mk_injective
theorem fst_surjective [h : ∀ a, Nonempty (β a)] : Surjective (fst : (Σ a, β a) → α) := fun a ↦
let ⟨b⟩ := h a; ⟨⟨a, b⟩, rfl⟩
theorem fst_surjective_iff : Surjective (fst : (Σ a, β a) → α) ↔ ∀ a, Nonempty (β a) :=
⟨fun h a ↦ let ⟨x, hx⟩ := h a; hx ▸ ⟨x.2⟩, @fst_surjective _ _⟩
theorem fst_injective [h : ∀ a, Subsingleton (β a)] : Injective (fst : (Σ a, β a) → α) := by
rintro ⟨a₁, b₁⟩ ⟨a₂, b₂⟩ (rfl : a₁ = a₂)
exact congr_arg (mk a₁) <| Subsingleton.elim _ _
theorem fst_injective_iff : Injective (fst : (Σ a, β a) → α) ↔ ∀ a, Subsingleton (β a) :=
⟨fun h _ ↦ ⟨fun _ _ ↦ sigma_mk_injective <| h rfl⟩, @fst_injective _ _⟩
/-- Map the left and right components of a sigma -/
def map (f₁ : α₁ → α₂) (f₂ : ∀ a, β₁ a → β₂ (f₁ a)) (x : Sigma β₁) : Sigma β₂ :=
⟨f₁ x.1, f₂ x.1 x.2⟩
#align sigma.map Sigma.map
lemma map_mk (f₁ : α₁ → α₂) (f₂ : ∀ a, β₁ a → β₂ (f₁ a)) (x : α₁) (y : β₁ x) :
map f₁ f₂ ⟨x, y⟩ = ⟨f₁ x, f₂ x y⟩ := rfl
end Sigma
theorem Function.Injective.sigma_map {f₁ : α₁ → α₂} {f₂ : ∀ a, β₁ a → β₂ (f₁ a)}
(h₁ : Injective f₁) (h₂ : ∀ a, Injective (f₂ a)) : Injective (Sigma.map f₁ f₂)
| ⟨i, x⟩, ⟨j, y⟩, h => by
obtain rfl : i = j := h₁ (Sigma.mk.inj_iff.mp h).1
obtain rfl : x = y := h₂ i (sigma_mk_injective h)
rfl
#align function.injective.sigma_map Function.Injective.sigma_map
theorem Function.Injective.of_sigma_map {f₁ : α₁ → α₂} {f₂ : ∀ a, β₁ a → β₂ (f₁ a)}
(h : Injective (Sigma.map f₁ f₂)) (a : α₁) : Injective (f₂ a) := fun x y hxy ↦
sigma_mk_injective <| @h ⟨a, x⟩ ⟨a, y⟩ (Sigma.ext rfl (heq_of_eq hxy))
#align function.injective.of_sigma_map Function.Injective.of_sigma_map
theorem Function.Injective.sigma_map_iff {f₁ : α₁ → α₂} {f₂ : ∀ a, β₁ a → β₂ (f₁ a)}
(h₁ : Injective f₁) : Injective (Sigma.map f₁ f₂) ↔ ∀ a, Injective (f₂ a) :=
⟨fun h ↦ h.of_sigma_map, h₁.sigma_map⟩
#align function.injective.sigma_map_iff Function.Injective.sigma_map_iff
| Mathlib/Data/Sigma/Basic.lean | 154 | 157 | theorem Function.Surjective.sigma_map {f₁ : α₁ → α₂} {f₂ : ∀ a, β₁ a → β₂ (f₁ a)}
(h₁ : Surjective f₁) (h₂ : ∀ a, Surjective (f₂ a)) : Surjective (Sigma.map f₁ f₂) := by |
simp only [Surjective, Sigma.forall, h₁.forall]
exact fun i ↦ (h₂ _).forall.2 fun x ↦ ⟨⟨i, x⟩, rfl⟩
|
/-
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.CliffordAlgebra.Conjugation
import Mathlib.LinearAlgebra.TensorProduct.Opposite
import Mathlib.RingTheory.TensorProduct.Basic
/-!
# The base change of a clifford algebra
In this file we show the isomorphism
* `CliffordAlgebra.equivBaseChange A Q` :
`CliffordAlgebra (Q.baseChange A) ≃ₐ[A] (A ⊗[R] CliffordAlgebra Q)`
with forward direction `CliffordAlgebra.toBasechange A Q` and reverse direction
`CliffordAlgebra.ofBasechange A Q`.
This covers a more general case of the complexification of clifford algebras (as described in §2.2
of https://empg.maths.ed.ac.uk/Activities/Spin/Lecture2.pdf), where ℂ and ℝ are replaced by an
`R`-algebra `A` (where `2 : R` is invertible).
We show the additional results:
* `CliffordAlgebra.toBasechange_ι`: the effect of base-changing pure vectors.
* `CliffordAlgebra.ofBasechange_tmul_ι`: the effect of un-base-changing a tensor of a pure vectors.
* `CliffordAlgebra.toBasechange_involute`: the effect of base-changing an involution.
* `CliffordAlgebra.toBasechange_reverse`: the effect of base-changing a reversal.
-/
variable {R A V : Type*}
variable [CommRing R] [CommRing A] [AddCommGroup V]
variable [Algebra R A] [Module R V] [Module A V] [IsScalarTower R A V]
variable [Invertible (2 : R)]
open scoped TensorProduct
namespace CliffordAlgebra
variable (A)
/-- Auxiliary construction: note this is really just a heterobasic `CliffordAlgebra.map`. -/
-- `noncomputable` is a performance workaround for mathlib4#7103
noncomputable def ofBaseChangeAux (Q : QuadraticForm R V) :
CliffordAlgebra Q →ₐ[R] CliffordAlgebra (Q.baseChange A) :=
CliffordAlgebra.lift Q <| by
refine ⟨(ι (Q.baseChange A)).restrictScalars R ∘ₗ TensorProduct.mk R A V 1, fun v => ?_⟩
refine (CliffordAlgebra.ι_sq_scalar (Q.baseChange A) (1 ⊗ₜ v)).trans ?_
rw [QuadraticForm.baseChange_tmul, one_mul, ← Algebra.algebraMap_eq_smul_one,
← IsScalarTower.algebraMap_apply]
@[simp] theorem ofBaseChangeAux_ι (Q : QuadraticForm R V) (v : V) :
ofBaseChangeAux A Q (ι Q v) = ι (Q.baseChange A) (1 ⊗ₜ v) :=
CliffordAlgebra.lift_ι_apply _ _ v
/-- Convert from the base-changed clifford algebra to the clifford algebra over a base-changed
module. -/
-- `noncomputable` is a performance workaround for mathlib4#7103
noncomputable def ofBaseChange (Q : QuadraticForm R V) :
A ⊗[R] CliffordAlgebra Q →ₐ[A] CliffordAlgebra (Q.baseChange A) :=
Algebra.TensorProduct.lift (Algebra.ofId _ _) (ofBaseChangeAux A Q)
fun _a _x => Algebra.commutes _ _
@[simp] theorem ofBaseChange_tmul_ι (Q : QuadraticForm R V) (z : A) (v : V) :
ofBaseChange A Q (z ⊗ₜ ι Q v) = ι (Q.baseChange A) (z ⊗ₜ v) := by
show algebraMap _ _ z * ofBaseChangeAux A Q (ι Q v) = ι (Q.baseChange A) (z ⊗ₜ[R] v)
rw [ofBaseChangeAux_ι, ← Algebra.smul_def, ← map_smul, TensorProduct.smul_tmul', smul_eq_mul,
mul_one]
@[simp] theorem ofBaseChange_tmul_one (Q : QuadraticForm R V) (z : A) :
ofBaseChange A Q (z ⊗ₜ 1) = algebraMap _ _ z := by
show algebraMap _ _ z * ofBaseChangeAux A Q 1 = _
rw [map_one, mul_one]
/-- Convert from the clifford algebra over a base-changed module to the base-changed clifford
algebra. -/
-- `noncomputable` is a performance workaround for mathlib4#7103
noncomputable def toBaseChange (Q : QuadraticForm R V) :
CliffordAlgebra (Q.baseChange A) →ₐ[A] A ⊗[R] CliffordAlgebra Q :=
CliffordAlgebra.lift _ <| by
refine ⟨TensorProduct.AlgebraTensorModule.map (LinearMap.id : A →ₗ[A] A) (ι Q), ?_⟩
letI : Invertible (2 : A) := (Invertible.map (algebraMap R A) 2).copy 2 (map_ofNat _ _).symm
letI : Invertible (2 : A ⊗[R] CliffordAlgebra Q) :=
(Invertible.map (algebraMap R _) 2).copy 2 (map_ofNat _ _).symm
suffices hpure_tensor : ∀ v w, (1 * 1) ⊗ₜ[R] (ι Q v * ι Q w) + (1 * 1) ⊗ₜ[R] (ι Q w * ι Q v) =
QuadraticForm.polarBilin (Q.baseChange A) (1 ⊗ₜ[R] v) (1 ⊗ₜ[R] w) ⊗ₜ[R] 1 by
-- the crux is that by converting to a statement about linear maps instead of quadratic forms,
-- we then have access to all the partially-applied `ext` lemmas.
rw [CliffordAlgebra.forall_mul_self_eq_iff (isUnit_of_invertible _)]
refine TensorProduct.AlgebraTensorModule.curry_injective ?_
ext v w
exact hpure_tensor v w
intros v w
rw [← TensorProduct.tmul_add, CliffordAlgebra.ι_mul_ι_add_swap,
QuadraticForm.polarBilin_baseChange, LinearMap.BilinForm.baseChange_tmul, one_mul,
TensorProduct.smul_tmul, Algebra.algebraMap_eq_smul_one, QuadraticForm.polarBilin_apply_apply]
@[simp] theorem toBaseChange_ι (Q : QuadraticForm R V) (z : A) (v : V) :
toBaseChange A Q (ι (Q.baseChange A) (z ⊗ₜ v)) = z ⊗ₜ ι Q v :=
CliffordAlgebra.lift_ι_apply _ _ _
theorem toBaseChange_comp_involute (Q : QuadraticForm R V) :
(toBaseChange A Q).comp (involute : CliffordAlgebra (Q.baseChange A) →ₐ[A] _) =
(Algebra.TensorProduct.map (AlgHom.id _ _) involute).comp (toBaseChange A Q) := by
ext v
show toBaseChange A Q (involute (ι (Q.baseChange A) (1 ⊗ₜ[R] v)))
= (Algebra.TensorProduct.map (AlgHom.id _ _) involute :
A ⊗[R] CliffordAlgebra Q →ₐ[A] _)
(toBaseChange A Q (ι (Q.baseChange A) (1 ⊗ₜ[R] v)))
rw [toBaseChange_ι, involute_ι, map_neg (toBaseChange A Q), toBaseChange_ι,
Algebra.TensorProduct.map_tmul, AlgHom.id_apply, involute_ι, TensorProduct.tmul_neg]
/-- The involution acts only on the right of the tensor product. -/
theorem toBaseChange_involute (Q : QuadraticForm R V) (x : CliffordAlgebra (Q.baseChange A)) :
toBaseChange A Q (involute x) =
TensorProduct.map LinearMap.id (involute.toLinearMap) (toBaseChange A Q x) :=
DFunLike.congr_fun (toBaseChange_comp_involute A Q) x
open MulOpposite
/-- Auxiliary theorem used to prove `toBaseChange_reverse` without needing induction. -/
| Mathlib/LinearAlgebra/CliffordAlgebra/BaseChange.lean | 124 | 137 | theorem toBaseChange_comp_reverseOp (Q : QuadraticForm R V) :
(toBaseChange A Q).op.comp reverseOp =
((Algebra.TensorProduct.opAlgEquiv R A A (CliffordAlgebra Q)).toAlgHom.comp <|
(Algebra.TensorProduct.map
(AlgEquiv.toOpposite A A).toAlgHom (reverseOp (Q := Q))).comp
(toBaseChange A Q)) := by |
ext v
show op (toBaseChange A Q (reverse (ι (Q.baseChange A) (1 ⊗ₜ[R] v)))) =
Algebra.TensorProduct.opAlgEquiv R A A (CliffordAlgebra Q)
(Algebra.TensorProduct.map (AlgEquiv.toOpposite A A).toAlgHom (reverseOp (Q := Q))
(toBaseChange A Q (ι (Q.baseChange A) (1 ⊗ₜ[R] v))))
rw [toBaseChange_ι, reverse_ι, toBaseChange_ι, Algebra.TensorProduct.map_tmul,
Algebra.TensorProduct.opAlgEquiv_tmul, reverseOp_ι]
rfl
|
/-
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.SetTheory.Game.Basic
import Mathlib.Tactic.NthRewrite
#align_import set_theory.game.impartial from "leanprover-community/mathlib"@"2e0975f6a25dd3fbfb9e41556a77f075f6269748"
/-!
# Basic definitions about impartial (pre-)games
We will define an impartial game, one in which left and right can make exactly the same moves.
Our definition differs slightly by saying that the game is always equivalent to its negative,
no matter what moves are played. This allows for games such as poker-nim to be classified as
impartial.
-/
universe u
namespace SetTheory
open scoped PGame
namespace PGame
/-- The definition for an impartial game, defined using Conway induction. -/
def ImpartialAux : PGame → Prop
| G => (G ≈ -G) ∧ (∀ i, ImpartialAux (G.moveLeft i)) ∧ ∀ j, ImpartialAux (G.moveRight j)
termination_by G => G -- Porting note: Added `termination_by`
#align pgame.impartial_aux SetTheory.PGame.ImpartialAux
theorem impartialAux_def {G : PGame} :
G.ImpartialAux ↔
(G ≈ -G) ∧ (∀ i, ImpartialAux (G.moveLeft i)) ∧ ∀ j, ImpartialAux (G.moveRight j) := by
rw [ImpartialAux]
#align pgame.impartial_aux_def SetTheory.PGame.impartialAux_def
/-- A typeclass on impartial games. -/
class Impartial (G : PGame) : Prop where
out : ImpartialAux G
#align pgame.impartial SetTheory.PGame.Impartial
theorem impartial_iff_aux {G : PGame} : G.Impartial ↔ G.ImpartialAux :=
⟨fun h => h.1, fun h => ⟨h⟩⟩
#align pgame.impartial_iff_aux SetTheory.PGame.impartial_iff_aux
theorem impartial_def {G : PGame} :
G.Impartial ↔ (G ≈ -G) ∧ (∀ i, Impartial (G.moveLeft i)) ∧ ∀ j, Impartial (G.moveRight j) := by
simpa only [impartial_iff_aux] using impartialAux_def
#align pgame.impartial_def SetTheory.PGame.impartial_def
namespace Impartial
instance impartial_zero : Impartial 0 := by rw [impartial_def]; dsimp; simp
#align pgame.impartial.impartial_zero SetTheory.PGame.Impartial.impartial_zero
instance impartial_star : Impartial star := by
rw [impartial_def]; simpa using Impartial.impartial_zero
#align pgame.impartial.impartial_star SetTheory.PGame.Impartial.impartial_star
theorem neg_equiv_self (G : PGame) [h : G.Impartial] : G ≈ -G :=
(impartial_def.1 h).1
#align pgame.impartial.neg_equiv_self SetTheory.PGame.Impartial.neg_equiv_self
-- Porting note: Changed `-⟦G⟧` to `-(⟦G⟧ : Quotient setoid)`
@[simp]
theorem mk'_neg_equiv_self (G : PGame) [G.Impartial] : -(⟦G⟧ : Quotient setoid) = ⟦G⟧ :=
Quot.sound (Equiv.symm (neg_equiv_self G))
#align pgame.impartial.mk_neg_equiv_self SetTheory.PGame.Impartial.mk'_neg_equiv_self
instance moveLeft_impartial {G : PGame} [h : G.Impartial] (i : G.LeftMoves) :
(G.moveLeft i).Impartial :=
(impartial_def.1 h).2.1 i
#align pgame.impartial.move_left_impartial SetTheory.PGame.Impartial.moveLeft_impartial
instance moveRight_impartial {G : PGame} [h : G.Impartial] (j : G.RightMoves) :
(G.moveRight j).Impartial :=
(impartial_def.1 h).2.2 j
#align pgame.impartial.move_right_impartial SetTheory.PGame.Impartial.moveRight_impartial
theorem impartial_congr : ∀ {G H : PGame} (_ : G ≡r H) [G.Impartial], H.Impartial
| G, H => fun e => by
intro h
exact impartial_def.2
⟨Equiv.trans e.symm.equiv (Equiv.trans (neg_equiv_self G) (neg_equiv_neg_iff.2 e.equiv)),
fun i => impartial_congr (e.moveLeftSymm i), fun j => impartial_congr (e.moveRightSymm j)⟩
termination_by G H => (G, H)
#align pgame.impartial.impartial_congr SetTheory.PGame.Impartial.impartial_congr
instance impartial_add : ∀ (G H : PGame) [G.Impartial] [H.Impartial], (G + H).Impartial
| G, H, _, _ => by
rw [impartial_def]
refine ⟨Equiv.trans (add_congr (neg_equiv_self G) (neg_equiv_self _))
(Equiv.symm (negAddRelabelling _ _).equiv), fun k => ?_, fun k => ?_⟩
· apply leftMoves_add_cases k
all_goals
intro i; simp only [add_moveLeft_inl, add_moveLeft_inr]
apply impartial_add
· apply rightMoves_add_cases k
all_goals
intro i; simp only [add_moveRight_inl, add_moveRight_inr]
apply impartial_add
termination_by G H => (G, H)
#align pgame.impartial.impartial_add SetTheory.PGame.Impartial.impartial_add
instance impartial_neg : ∀ (G : PGame) [G.Impartial], (-G).Impartial
| G, _ => by
rw [impartial_def]
refine ⟨?_, fun i => ?_, fun i => ?_⟩
· rw [neg_neg]
exact Equiv.symm (neg_equiv_self G)
· rw [moveLeft_neg']
apply impartial_neg
· rw [moveRight_neg']
apply impartial_neg
termination_by G => G
#align pgame.impartial.impartial_neg SetTheory.PGame.Impartial.impartial_neg
variable (G : PGame) [Impartial G]
theorem nonpos : ¬0 < G := fun h => by
have h' := neg_lt_neg_iff.2 h
rw [neg_zero, lt_congr_left (Equiv.symm (neg_equiv_self G))] at h'
exact (h.trans h').false
#align pgame.impartial.nonpos SetTheory.PGame.Impartial.nonpos
theorem nonneg : ¬G < 0 := fun h => by
have h' := neg_lt_neg_iff.2 h
rw [neg_zero, lt_congr_right (Equiv.symm (neg_equiv_self G))] at h'
exact (h.trans h').false
#align pgame.impartial.nonneg SetTheory.PGame.Impartial.nonneg
/-- In an impartial game, either the first player always wins, or the second player always wins. -/
| Mathlib/SetTheory/Game/Impartial.lean | 137 | 142 | theorem equiv_or_fuzzy_zero : (G ≈ 0) ∨ G ‖ 0 := by |
rcases lt_or_equiv_or_gt_or_fuzzy G 0 with (h | h | h | h)
· exact ((nonneg G) h).elim
· exact Or.inl h
· exact ((nonpos G) h).elim
· exact Or.inr h
|
/-
Copyright (c) 2019 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Topology.Constructions
#align_import topology.continuous_on from "leanprover-community/mathlib"@"d4f691b9e5f94cfc64639973f3544c95f8d5d494"
/-!
# Neighborhoods and continuity relative to a subset
This file defines relative versions
* `nhdsWithin` of `nhds`
* `ContinuousOn` of `Continuous`
* `ContinuousWithinAt` of `ContinuousAt`
and proves their basic properties, including the relationships between
these restricted notions and the corresponding notions for the subtype
equipped with the subspace topology.
## Notation
* `𝓝 x`: the filter 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`.
-/
open Set Filter Function Topology Filter
variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
variable [TopologicalSpace α]
@[simp]
theorem nhds_bind_nhdsWithin {a : α} {s : Set α} : ((𝓝 a).bind fun x => 𝓝[s] x) = 𝓝[s] a :=
bind_inf_principal.trans <| congr_arg₂ _ nhds_bind_nhds rfl
#align nhds_bind_nhds_within nhds_bind_nhdsWithin
@[simp]
theorem eventually_nhds_nhdsWithin {a : α} {s : Set α} {p : α → Prop} :
(∀ᶠ y in 𝓝 a, ∀ᶠ x in 𝓝[s] y, p x) ↔ ∀ᶠ x in 𝓝[s] a, p x :=
Filter.ext_iff.1 nhds_bind_nhdsWithin { x | p x }
#align eventually_nhds_nhds_within eventually_nhds_nhdsWithin
theorem eventually_nhdsWithin_iff {a : α} {s : Set α} {p : α → Prop} :
(∀ᶠ x in 𝓝[s] a, p x) ↔ ∀ᶠ x in 𝓝 a, x ∈ s → p x :=
eventually_inf_principal
#align eventually_nhds_within_iff eventually_nhdsWithin_iff
theorem frequently_nhdsWithin_iff {z : α} {s : Set α} {p : α → Prop} :
(∃ᶠ x in 𝓝[s] z, p x) ↔ ∃ᶠ x in 𝓝 z, p x ∧ x ∈ s :=
frequently_inf_principal.trans <| by simp only [and_comm]
#align frequently_nhds_within_iff frequently_nhdsWithin_iff
theorem mem_closure_ne_iff_frequently_within {z : α} {s : Set α} :
z ∈ closure (s \ {z}) ↔ ∃ᶠ x in 𝓝[≠] z, x ∈ s := by
simp [mem_closure_iff_frequently, frequently_nhdsWithin_iff]
#align mem_closure_ne_iff_frequently_within mem_closure_ne_iff_frequently_within
@[simp]
theorem eventually_nhdsWithin_nhdsWithin {a : α} {s : Set α} {p : α → Prop} :
(∀ᶠ y in 𝓝[s] a, ∀ᶠ x in 𝓝[s] y, p x) ↔ ∀ᶠ x in 𝓝[s] a, p x := by
refine ⟨fun h => ?_, fun h => (eventually_nhds_nhdsWithin.2 h).filter_mono inf_le_left⟩
simp only [eventually_nhdsWithin_iff] at h ⊢
exact h.mono fun x hx hxs => (hx hxs).self_of_nhds hxs
#align eventually_nhds_within_nhds_within eventually_nhdsWithin_nhdsWithin
theorem nhdsWithin_eq (a : α) (s : Set α) :
𝓝[s] a = ⨅ t ∈ { t : Set α | a ∈ t ∧ IsOpen t }, 𝓟 (t ∩ s) :=
((nhds_basis_opens a).inf_principal s).eq_biInf
#align nhds_within_eq nhdsWithin_eq
theorem nhdsWithin_univ (a : α) : 𝓝[Set.univ] a = 𝓝 a := by
rw [nhdsWithin, principal_univ, inf_top_eq]
#align nhds_within_univ nhdsWithin_univ
theorem nhdsWithin_hasBasis {p : β → Prop} {s : β → Set α} {a : α} (h : (𝓝 a).HasBasis p s)
(t : Set α) : (𝓝[t] a).HasBasis p fun i => s i ∩ t :=
h.inf_principal t
#align nhds_within_has_basis nhdsWithin_hasBasis
theorem nhdsWithin_basis_open (a : α) (t : Set α) :
(𝓝[t] a).HasBasis (fun u => a ∈ u ∧ IsOpen u) fun u => u ∩ t :=
nhdsWithin_hasBasis (nhds_basis_opens a) t
#align nhds_within_basis_open nhdsWithin_basis_open
theorem mem_nhdsWithin {t : Set α} {a : α} {s : Set α} :
t ∈ 𝓝[s] a ↔ ∃ u, IsOpen u ∧ a ∈ u ∧ u ∩ s ⊆ t := by
simpa only [and_assoc, and_left_comm] using (nhdsWithin_basis_open a s).mem_iff
#align mem_nhds_within mem_nhdsWithin
theorem mem_nhdsWithin_iff_exists_mem_nhds_inter {t : Set α} {a : α} {s : Set α} :
t ∈ 𝓝[s] a ↔ ∃ u ∈ 𝓝 a, u ∩ s ⊆ t :=
(nhdsWithin_hasBasis (𝓝 a).basis_sets s).mem_iff
#align mem_nhds_within_iff_exists_mem_nhds_inter mem_nhdsWithin_iff_exists_mem_nhds_inter
theorem diff_mem_nhdsWithin_compl {x : α} {s : Set α} (hs : s ∈ 𝓝 x) (t : Set α) :
s \ t ∈ 𝓝[tᶜ] x :=
diff_mem_inf_principal_compl hs t
#align diff_mem_nhds_within_compl diff_mem_nhdsWithin_compl
theorem diff_mem_nhdsWithin_diff {x : α} {s t : Set α} (hs : s ∈ 𝓝[t] x) (t' : Set α) :
s \ t' ∈ 𝓝[t \ t'] x := by
rw [nhdsWithin, diff_eq, diff_eq, ← inf_principal, ← inf_assoc]
exact inter_mem_inf hs (mem_principal_self _)
#align diff_mem_nhds_within_diff diff_mem_nhdsWithin_diff
theorem nhds_of_nhdsWithin_of_nhds {s t : Set α} {a : α} (h1 : s ∈ 𝓝 a) (h2 : t ∈ 𝓝[s] a) :
t ∈ 𝓝 a := by
rcases mem_nhdsWithin_iff_exists_mem_nhds_inter.mp h2 with ⟨_, Hw, hw⟩
exact (𝓝 a).sets_of_superset ((𝓝 a).inter_sets Hw h1) hw
#align nhds_of_nhds_within_of_nhds nhds_of_nhdsWithin_of_nhds
theorem mem_nhdsWithin_iff_eventually {s t : Set α} {x : α} :
t ∈ 𝓝[s] x ↔ ∀ᶠ y in 𝓝 x, y ∈ s → y ∈ t :=
eventually_inf_principal
#align mem_nhds_within_iff_eventually mem_nhdsWithin_iff_eventually
theorem mem_nhdsWithin_iff_eventuallyEq {s t : Set α} {x : α} :
t ∈ 𝓝[s] x ↔ s =ᶠ[𝓝 x] (s ∩ t : Set α) := by
simp_rw [mem_nhdsWithin_iff_eventually, eventuallyEq_set, mem_inter_iff, iff_self_and]
#align mem_nhds_within_iff_eventually_eq mem_nhdsWithin_iff_eventuallyEq
theorem nhdsWithin_eq_iff_eventuallyEq {s t : Set α} {x : α} : 𝓝[s] x = 𝓝[t] x ↔ s =ᶠ[𝓝 x] t :=
set_eventuallyEq_iff_inf_principal.symm
#align nhds_within_eq_iff_eventually_eq nhdsWithin_eq_iff_eventuallyEq
theorem nhdsWithin_le_iff {s t : Set α} {x : α} : 𝓝[s] x ≤ 𝓝[t] x ↔ t ∈ 𝓝[s] x :=
set_eventuallyLE_iff_inf_principal_le.symm.trans set_eventuallyLE_iff_mem_inf_principal
#align nhds_within_le_iff nhdsWithin_le_iff
-- Porting note: golfed, dropped an unneeded assumption
theorem preimage_nhdsWithin_coinduced' {π : α → β} {s : Set β} {t : Set α} {a : α} (h : a ∈ t)
(hs : s ∈ @nhds β (.coinduced (fun x : t => π x) inferInstance) (π a)) :
π ⁻¹' s ∈ 𝓝[t] a := by
lift a to t using h
replace hs : (fun x : t => π x) ⁻¹' s ∈ 𝓝 a := preimage_nhds_coinduced hs
rwa [← map_nhds_subtype_val, mem_map]
#align preimage_nhds_within_coinduced' preimage_nhdsWithin_coinduced'ₓ
theorem mem_nhdsWithin_of_mem_nhds {s t : Set α} {a : α} (h : s ∈ 𝓝 a) : s ∈ 𝓝[t] a :=
mem_inf_of_left h
#align mem_nhds_within_of_mem_nhds mem_nhdsWithin_of_mem_nhds
theorem self_mem_nhdsWithin {a : α} {s : Set α} : s ∈ 𝓝[s] a :=
mem_inf_of_right (mem_principal_self s)
#align self_mem_nhds_within self_mem_nhdsWithin
theorem eventually_mem_nhdsWithin {a : α} {s : Set α} : ∀ᶠ x in 𝓝[s] a, x ∈ s :=
self_mem_nhdsWithin
#align eventually_mem_nhds_within eventually_mem_nhdsWithin
theorem inter_mem_nhdsWithin (s : Set α) {t : Set α} {a : α} (h : t ∈ 𝓝 a) : s ∩ t ∈ 𝓝[s] a :=
inter_mem self_mem_nhdsWithin (mem_inf_of_left h)
#align inter_mem_nhds_within inter_mem_nhdsWithin
theorem nhdsWithin_mono (a : α) {s t : Set α} (h : s ⊆ t) : 𝓝[s] a ≤ 𝓝[t] a :=
inf_le_inf_left _ (principal_mono.mpr h)
#align nhds_within_mono nhdsWithin_mono
theorem pure_le_nhdsWithin {a : α} {s : Set α} (ha : a ∈ s) : pure a ≤ 𝓝[s] a :=
le_inf (pure_le_nhds a) (le_principal_iff.2 ha)
#align pure_le_nhds_within pure_le_nhdsWithin
theorem mem_of_mem_nhdsWithin {a : α} {s t : Set α} (ha : a ∈ s) (ht : t ∈ 𝓝[s] a) : a ∈ t :=
pure_le_nhdsWithin ha ht
#align mem_of_mem_nhds_within mem_of_mem_nhdsWithin
theorem Filter.Eventually.self_of_nhdsWithin {p : α → Prop} {s : Set α} {x : α}
(h : ∀ᶠ y in 𝓝[s] x, p y) (hx : x ∈ s) : p x :=
mem_of_mem_nhdsWithin hx h
#align filter.eventually.self_of_nhds_within Filter.Eventually.self_of_nhdsWithin
theorem tendsto_const_nhdsWithin {l : Filter β} {s : Set α} {a : α} (ha : a ∈ s) :
Tendsto (fun _ : β => a) l (𝓝[s] a) :=
tendsto_const_pure.mono_right <| pure_le_nhdsWithin ha
#align tendsto_const_nhds_within tendsto_const_nhdsWithin
theorem nhdsWithin_restrict'' {a : α} (s : Set α) {t : Set α} (h : t ∈ 𝓝[s] a) :
𝓝[s] a = 𝓝[s ∩ t] a :=
le_antisymm (le_inf inf_le_left (le_principal_iff.mpr (inter_mem self_mem_nhdsWithin h)))
(inf_le_inf_left _ (principal_mono.mpr Set.inter_subset_left))
#align nhds_within_restrict'' nhdsWithin_restrict''
theorem nhdsWithin_restrict' {a : α} (s : Set α) {t : Set α} (h : t ∈ 𝓝 a) : 𝓝[s] a = 𝓝[s ∩ t] a :=
nhdsWithin_restrict'' s <| mem_inf_of_left h
#align nhds_within_restrict' nhdsWithin_restrict'
theorem nhdsWithin_restrict {a : α} (s : Set α) {t : Set α} (h₀ : a ∈ t) (h₁ : IsOpen t) :
𝓝[s] a = 𝓝[s ∩ t] a :=
nhdsWithin_restrict' s (IsOpen.mem_nhds h₁ h₀)
#align nhds_within_restrict nhdsWithin_restrict
theorem nhdsWithin_le_of_mem {a : α} {s t : Set α} (h : s ∈ 𝓝[t] a) : 𝓝[t] a ≤ 𝓝[s] a :=
nhdsWithin_le_iff.mpr h
#align nhds_within_le_of_mem nhdsWithin_le_of_mem
theorem nhdsWithin_le_nhds {a : α} {s : Set α} : 𝓝[s] a ≤ 𝓝 a := by
rw [← nhdsWithin_univ]
apply nhdsWithin_le_of_mem
exact univ_mem
#align nhds_within_le_nhds nhdsWithin_le_nhds
theorem nhdsWithin_eq_nhdsWithin' {a : α} {s t u : Set α} (hs : s ∈ 𝓝 a) (h₂ : t ∩ s = u ∩ s) :
𝓝[t] a = 𝓝[u] a := by rw [nhdsWithin_restrict' t hs, nhdsWithin_restrict' u hs, h₂]
#align nhds_within_eq_nhds_within' nhdsWithin_eq_nhdsWithin'
theorem nhdsWithin_eq_nhdsWithin {a : α} {s t u : Set α} (h₀ : a ∈ s) (h₁ : IsOpen s)
(h₂ : t ∩ s = u ∩ s) : 𝓝[t] a = 𝓝[u] a := by
rw [nhdsWithin_restrict t h₀ h₁, nhdsWithin_restrict u h₀ h₁, h₂]
#align nhds_within_eq_nhds_within nhdsWithin_eq_nhdsWithin
@[simp] theorem nhdsWithin_eq_nhds {a : α} {s : Set α} : 𝓝[s] a = 𝓝 a ↔ s ∈ 𝓝 a :=
inf_eq_left.trans le_principal_iff
#align nhds_within_eq_nhds nhdsWithin_eq_nhds
theorem IsOpen.nhdsWithin_eq {a : α} {s : Set α} (h : IsOpen s) (ha : a ∈ s) : 𝓝[s] a = 𝓝 a :=
nhdsWithin_eq_nhds.2 <| h.mem_nhds ha
#align is_open.nhds_within_eq IsOpen.nhdsWithin_eq
theorem preimage_nhds_within_coinduced {π : α → β} {s : Set β} {t : Set α} {a : α} (h : a ∈ t)
(ht : IsOpen t)
(hs : s ∈ @nhds β (.coinduced (fun x : t => π x) inferInstance) (π a)) :
π ⁻¹' s ∈ 𝓝 a := by
rw [← ht.nhdsWithin_eq h]
exact preimage_nhdsWithin_coinduced' h hs
#align preimage_nhds_within_coinduced preimage_nhds_within_coinduced
@[simp]
theorem nhdsWithin_empty (a : α) : 𝓝[∅] a = ⊥ := by rw [nhdsWithin, principal_empty, inf_bot_eq]
#align nhds_within_empty nhdsWithin_empty
theorem nhdsWithin_union (a : α) (s t : Set α) : 𝓝[s ∪ t] a = 𝓝[s] a ⊔ 𝓝[t] a := by
delta nhdsWithin
rw [← inf_sup_left, sup_principal]
#align nhds_within_union nhdsWithin_union
theorem nhdsWithin_biUnion {ι} {I : Set ι} (hI : I.Finite) (s : ι → Set α) (a : α) :
𝓝[⋃ i ∈ I, s i] a = ⨆ i ∈ I, 𝓝[s i] a :=
Set.Finite.induction_on hI (by simp) fun _ _ hT ↦ by
simp only [hT, nhdsWithin_union, iSup_insert, biUnion_insert]
#align nhds_within_bUnion nhdsWithin_biUnion
theorem nhdsWithin_sUnion {S : Set (Set α)} (hS : S.Finite) (a : α) :
𝓝[⋃₀ S] a = ⨆ s ∈ S, 𝓝[s] a := by
rw [sUnion_eq_biUnion, nhdsWithin_biUnion hS]
#align nhds_within_sUnion nhdsWithin_sUnion
theorem nhdsWithin_iUnion {ι} [Finite ι] (s : ι → Set α) (a : α) :
𝓝[⋃ i, s i] a = ⨆ i, 𝓝[s i] a := by
rw [← sUnion_range, nhdsWithin_sUnion (finite_range s), iSup_range]
#align nhds_within_Union nhdsWithin_iUnion
theorem nhdsWithin_inter (a : α) (s t : Set α) : 𝓝[s ∩ t] a = 𝓝[s] a ⊓ 𝓝[t] a := by
delta nhdsWithin
rw [inf_left_comm, inf_assoc, inf_principal, ← inf_assoc, inf_idem]
#align nhds_within_inter nhdsWithin_inter
theorem nhdsWithin_inter' (a : α) (s t : Set α) : 𝓝[s ∩ t] a = 𝓝[s] a ⊓ 𝓟 t := by
delta nhdsWithin
rw [← inf_principal, inf_assoc]
#align nhds_within_inter' nhdsWithin_inter'
theorem nhdsWithin_inter_of_mem {a : α} {s t : Set α} (h : s ∈ 𝓝[t] a) : 𝓝[s ∩ t] a = 𝓝[t] a := by
rw [nhdsWithin_inter, inf_eq_right]
exact nhdsWithin_le_of_mem h
#align nhds_within_inter_of_mem nhdsWithin_inter_of_mem
theorem nhdsWithin_inter_of_mem' {a : α} {s t : Set α} (h : t ∈ 𝓝[s] a) : 𝓝[s ∩ t] a = 𝓝[s] a := by
rw [inter_comm, nhdsWithin_inter_of_mem h]
#align nhds_within_inter_of_mem' nhdsWithin_inter_of_mem'
@[simp]
theorem nhdsWithin_singleton (a : α) : 𝓝[{a}] a = pure a := by
rw [nhdsWithin, principal_singleton, inf_eq_right.2 (pure_le_nhds a)]
#align nhds_within_singleton nhdsWithin_singleton
@[simp]
theorem nhdsWithin_insert (a : α) (s : Set α) : 𝓝[insert a s] a = pure a ⊔ 𝓝[s] a := by
rw [← singleton_union, nhdsWithin_union, nhdsWithin_singleton]
#align nhds_within_insert nhdsWithin_insert
theorem mem_nhdsWithin_insert {a : α} {s t : Set α} : t ∈ 𝓝[insert a s] a ↔ a ∈ t ∧ t ∈ 𝓝[s] a := by
simp
#align mem_nhds_within_insert mem_nhdsWithin_insert
theorem insert_mem_nhdsWithin_insert {a : α} {s t : Set α} (h : t ∈ 𝓝[s] a) :
insert a t ∈ 𝓝[insert a s] a := by simp [mem_of_superset h]
#align insert_mem_nhds_within_insert insert_mem_nhdsWithin_insert
theorem insert_mem_nhds_iff {a : α} {s : Set α} : insert a s ∈ 𝓝 a ↔ s ∈ 𝓝[≠] a := by
simp only [nhdsWithin, mem_inf_principal, mem_compl_iff, mem_singleton_iff, or_iff_not_imp_left,
insert_def]
#align insert_mem_nhds_iff insert_mem_nhds_iff
@[simp]
theorem nhdsWithin_compl_singleton_sup_pure (a : α) : 𝓝[≠] a ⊔ pure a = 𝓝 a := by
rw [← nhdsWithin_singleton, ← nhdsWithin_union, compl_union_self, nhdsWithin_univ]
#align nhds_within_compl_singleton_sup_pure nhdsWithin_compl_singleton_sup_pure
theorem nhdsWithin_prod {α : Type*} [TopologicalSpace α] {β : Type*} [TopologicalSpace β]
{s u : Set α} {t v : Set β} {a : α} {b : β} (hu : u ∈ 𝓝[s] a) (hv : v ∈ 𝓝[t] b) :
u ×ˢ v ∈ 𝓝[s ×ˢ t] (a, b) := by
rw [nhdsWithin_prod_eq]
exact prod_mem_prod hu hv
#align nhds_within_prod nhdsWithin_prod
theorem nhdsWithin_pi_eq' {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι}
(hI : I.Finite) (s : ∀ i, Set (α i)) (x : ∀ i, α i) :
𝓝[pi I s] x = ⨅ i, comap (fun x => x i) (𝓝 (x i) ⊓ ⨅ (_ : i ∈ I), 𝓟 (s i)) := by
simp only [nhdsWithin, nhds_pi, Filter.pi, comap_inf, comap_iInf, pi_def, comap_principal, ←
iInf_principal_finite hI, ← iInf_inf_eq]
#align nhds_within_pi_eq' nhdsWithin_pi_eq'
theorem nhdsWithin_pi_eq {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι}
(hI : I.Finite) (s : ∀ i, Set (α i)) (x : ∀ i, α i) :
𝓝[pi I s] x =
(⨅ i ∈ I, comap (fun x => x i) (𝓝[s i] x i)) ⊓
⨅ (i) (_ : i ∉ I), comap (fun x => x i) (𝓝 (x i)) := by
simp only [nhdsWithin, nhds_pi, Filter.pi, pi_def, ← iInf_principal_finite hI, comap_inf,
comap_principal, eval]
rw [iInf_split _ fun i => i ∈ I, inf_right_comm]
simp only [iInf_inf_eq]
#align nhds_within_pi_eq nhdsWithin_pi_eq
theorem nhdsWithin_pi_univ_eq {ι : Type*} {α : ι → Type*} [Finite ι] [∀ i, TopologicalSpace (α i)]
(s : ∀ i, Set (α i)) (x : ∀ i, α i) :
𝓝[pi univ s] x = ⨅ i, comap (fun x => x i) (𝓝[s i] x i) := by
simpa [nhdsWithin] using nhdsWithin_pi_eq finite_univ s x
#align nhds_within_pi_univ_eq nhdsWithin_pi_univ_eq
theorem nhdsWithin_pi_eq_bot {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι}
{s : ∀ i, Set (α i)} {x : ∀ i, α i} : 𝓝[pi I s] x = ⊥ ↔ ∃ i ∈ I, 𝓝[s i] x i = ⊥ := by
simp only [nhdsWithin, nhds_pi, pi_inf_principal_pi_eq_bot]
#align nhds_within_pi_eq_bot nhdsWithin_pi_eq_bot
theorem nhdsWithin_pi_neBot {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι}
{s : ∀ i, Set (α i)} {x : ∀ i, α i} : (𝓝[pi I s] x).NeBot ↔ ∀ i ∈ I, (𝓝[s i] x i).NeBot := by
simp [neBot_iff, nhdsWithin_pi_eq_bot]
#align nhds_within_pi_ne_bot nhdsWithin_pi_neBot
theorem Filter.Tendsto.piecewise_nhdsWithin {f g : α → β} {t : Set α} [∀ x, Decidable (x ∈ t)]
{a : α} {s : Set α} {l : Filter β} (h₀ : Tendsto f (𝓝[s ∩ t] a) l)
(h₁ : Tendsto g (𝓝[s ∩ tᶜ] a) l) : Tendsto (piecewise t f g) (𝓝[s] a) l := by
apply Tendsto.piecewise <;> rwa [← nhdsWithin_inter']
#align filter.tendsto.piecewise_nhds_within Filter.Tendsto.piecewise_nhdsWithin
theorem Filter.Tendsto.if_nhdsWithin {f g : α → β} {p : α → Prop} [DecidablePred p] {a : α}
{s : Set α} {l : Filter β} (h₀ : Tendsto f (𝓝[s ∩ { x | p x }] a) l)
(h₁ : Tendsto g (𝓝[s ∩ { x | ¬p x }] a) l) :
Tendsto (fun x => if p x then f x else g x) (𝓝[s] a) l :=
h₀.piecewise_nhdsWithin h₁
#align filter.tendsto.if_nhds_within Filter.Tendsto.if_nhdsWithin
theorem map_nhdsWithin (f : α → β) (a : α) (s : Set α) :
map f (𝓝[s] a) = ⨅ t ∈ { t : Set α | a ∈ t ∧ IsOpen t }, 𝓟 (f '' (t ∩ s)) :=
((nhdsWithin_basis_open a s).map f).eq_biInf
#align map_nhds_within map_nhdsWithin
theorem tendsto_nhdsWithin_mono_left {f : α → β} {a : α} {s t : Set α} {l : Filter β} (hst : s ⊆ t)
(h : Tendsto f (𝓝[t] a) l) : Tendsto f (𝓝[s] a) l :=
h.mono_left <| nhdsWithin_mono a hst
#align tendsto_nhds_within_mono_left tendsto_nhdsWithin_mono_left
theorem tendsto_nhdsWithin_mono_right {f : β → α} {l : Filter β} {a : α} {s t : Set α} (hst : s ⊆ t)
(h : Tendsto f l (𝓝[s] a)) : Tendsto f l (𝓝[t] a) :=
h.mono_right (nhdsWithin_mono a hst)
#align tendsto_nhds_within_mono_right tendsto_nhdsWithin_mono_right
theorem tendsto_nhdsWithin_of_tendsto_nhds {f : α → β} {a : α} {s : Set α} {l : Filter β}
(h : Tendsto f (𝓝 a) l) : Tendsto f (𝓝[s] a) l :=
h.mono_left inf_le_left
#align tendsto_nhds_within_of_tendsto_nhds tendsto_nhdsWithin_of_tendsto_nhds
theorem eventually_mem_of_tendsto_nhdsWithin {f : β → α} {a : α} {s : Set α} {l : Filter β}
(h : Tendsto f l (𝓝[s] a)) : ∀ᶠ i in l, f i ∈ s := by
simp_rw [nhdsWithin_eq, tendsto_iInf, mem_setOf_eq, tendsto_principal, mem_inter_iff,
eventually_and] at h
exact (h univ ⟨mem_univ a, isOpen_univ⟩).2
#align eventually_mem_of_tendsto_nhds_within eventually_mem_of_tendsto_nhdsWithin
theorem tendsto_nhds_of_tendsto_nhdsWithin {f : β → α} {a : α} {s : Set α} {l : Filter β}
(h : Tendsto f l (𝓝[s] a)) : Tendsto f l (𝓝 a) :=
h.mono_right nhdsWithin_le_nhds
#align tendsto_nhds_of_tendsto_nhds_within tendsto_nhds_of_tendsto_nhdsWithin
theorem nhdsWithin_neBot_of_mem {s : Set α} {x : α} (hx : x ∈ s) : NeBot (𝓝[s] x) :=
mem_closure_iff_nhdsWithin_neBot.1 <| subset_closure hx
#align nhds_within_ne_bot_of_mem nhdsWithin_neBot_of_mem
theorem IsClosed.mem_of_nhdsWithin_neBot {s : Set α} (hs : IsClosed s) {x : α}
(hx : NeBot <| 𝓝[s] x) : x ∈ s :=
hs.closure_eq ▸ mem_closure_iff_nhdsWithin_neBot.2 hx
#align is_closed.mem_of_nhds_within_ne_bot IsClosed.mem_of_nhdsWithin_neBot
theorem DenseRange.nhdsWithin_neBot {ι : Type*} {f : ι → α} (h : DenseRange f) (x : α) :
NeBot (𝓝[range f] x) :=
mem_closure_iff_clusterPt.1 (h x)
#align dense_range.nhds_within_ne_bot DenseRange.nhdsWithin_neBot
theorem mem_closure_pi {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι}
{s : ∀ i, Set (α i)} {x : ∀ i, α i} : x ∈ closure (pi I s) ↔ ∀ i ∈ I, x i ∈ closure (s i) := by
simp only [mem_closure_iff_nhdsWithin_neBot, nhdsWithin_pi_neBot]
#align mem_closure_pi mem_closure_pi
theorem closure_pi_set {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] (I : Set ι)
(s : ∀ i, Set (α i)) : closure (pi I s) = pi I fun i => closure (s i) :=
Set.ext fun _ => mem_closure_pi
#align closure_pi_set closure_pi_set
theorem dense_pi {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {s : ∀ i, Set (α i)}
(I : Set ι) (hs : ∀ i ∈ I, Dense (s i)) : Dense (pi I s) := by
simp only [dense_iff_closure_eq, closure_pi_set, pi_congr rfl fun i hi => (hs i hi).closure_eq,
pi_univ]
#align dense_pi dense_pi
theorem eventuallyEq_nhdsWithin_iff {f g : α → β} {s : Set α} {a : α} :
f =ᶠ[𝓝[s] a] g ↔ ∀ᶠ x in 𝓝 a, x ∈ s → f x = g x :=
mem_inf_principal
#align eventually_eq_nhds_within_iff eventuallyEq_nhdsWithin_iff
theorem eventuallyEq_nhdsWithin_of_eqOn {f g : α → β} {s : Set α} {a : α} (h : EqOn f g s) :
f =ᶠ[𝓝[s] a] g :=
mem_inf_of_right h
#align eventually_eq_nhds_within_of_eq_on eventuallyEq_nhdsWithin_of_eqOn
theorem Set.EqOn.eventuallyEq_nhdsWithin {f g : α → β} {s : Set α} {a : α} (h : EqOn f g s) :
f =ᶠ[𝓝[s] a] g :=
eventuallyEq_nhdsWithin_of_eqOn h
#align set.eq_on.eventually_eq_nhds_within Set.EqOn.eventuallyEq_nhdsWithin
theorem tendsto_nhdsWithin_congr {f g : α → β} {s : Set α} {a : α} {l : Filter β}
(hfg : ∀ x ∈ s, f x = g x) (hf : Tendsto f (𝓝[s] a) l) : Tendsto g (𝓝[s] a) l :=
(tendsto_congr' <| eventuallyEq_nhdsWithin_of_eqOn hfg).1 hf
#align tendsto_nhds_within_congr tendsto_nhdsWithin_congr
theorem eventually_nhdsWithin_of_forall {s : Set α} {a : α} {p : α → Prop} (h : ∀ x ∈ s, p x) :
∀ᶠ x in 𝓝[s] a, p x :=
mem_inf_of_right h
#align eventually_nhds_within_of_forall eventually_nhdsWithin_of_forall
theorem tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within {a : α} {l : Filter β} {s : Set α}
(f : β → α) (h1 : Tendsto f l (𝓝 a)) (h2 : ∀ᶠ x in l, f x ∈ s) : Tendsto f l (𝓝[s] a) :=
tendsto_inf.2 ⟨h1, tendsto_principal.2 h2⟩
#align tendsto_nhds_within_of_tendsto_nhds_of_eventually_within tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within
theorem tendsto_nhdsWithin_iff {a : α} {l : Filter β} {s : Set α} {f : β → α} :
Tendsto f l (𝓝[s] a) ↔ Tendsto f l (𝓝 a) ∧ ∀ᶠ n in l, f n ∈ s :=
⟨fun h => ⟨tendsto_nhds_of_tendsto_nhdsWithin h, eventually_mem_of_tendsto_nhdsWithin h⟩, fun h =>
tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ h.1 h.2⟩
#align tendsto_nhds_within_iff tendsto_nhdsWithin_iff
@[simp]
theorem tendsto_nhdsWithin_range {a : α} {l : Filter β} {f : β → α} :
Tendsto f l (𝓝[range f] a) ↔ Tendsto f l (𝓝 a) :=
⟨fun h => h.mono_right inf_le_left, fun h =>
tendsto_inf.2 ⟨h, tendsto_principal.2 <| eventually_of_forall mem_range_self⟩⟩
#align tendsto_nhds_within_range tendsto_nhdsWithin_range
theorem Filter.EventuallyEq.eq_of_nhdsWithin {s : Set α} {f g : α → β} {a : α} (h : f =ᶠ[𝓝[s] a] g)
(hmem : a ∈ s) : f a = g a :=
h.self_of_nhdsWithin hmem
#align filter.eventually_eq.eq_of_nhds_within Filter.EventuallyEq.eq_of_nhdsWithin
theorem eventually_nhdsWithin_of_eventually_nhds {α : Type*} [TopologicalSpace α] {s : Set α}
{a : α} {p : α → Prop} (h : ∀ᶠ x in 𝓝 a, p x) : ∀ᶠ x in 𝓝[s] a, p x :=
mem_nhdsWithin_of_mem_nhds h
#align eventually_nhds_within_of_eventually_nhds eventually_nhdsWithin_of_eventually_nhds
/-!
### `nhdsWithin` and subtypes
-/
theorem mem_nhdsWithin_subtype {s : Set α} {a : { x // x ∈ s }} {t u : Set { x // x ∈ s }} :
t ∈ 𝓝[u] a ↔ t ∈ comap ((↑) : s → α) (𝓝[(↑) '' u] a) := by
rw [nhdsWithin, nhds_subtype, principal_subtype, ← comap_inf, ← nhdsWithin]
#align mem_nhds_within_subtype mem_nhdsWithin_subtype
theorem nhdsWithin_subtype (s : Set α) (a : { x // x ∈ s }) (t : Set { x // x ∈ s }) :
𝓝[t] a = comap ((↑) : s → α) (𝓝[(↑) '' t] a) :=
Filter.ext fun _ => mem_nhdsWithin_subtype
#align nhds_within_subtype nhdsWithin_subtype
theorem nhdsWithin_eq_map_subtype_coe {s : Set α} {a : α} (h : a ∈ s) :
𝓝[s] a = map ((↑) : s → α) (𝓝 ⟨a, h⟩) :=
(map_nhds_subtype_val ⟨a, h⟩).symm
#align nhds_within_eq_map_subtype_coe nhdsWithin_eq_map_subtype_coe
theorem mem_nhds_subtype_iff_nhdsWithin {s : Set α} {a : s} {t : Set s} :
t ∈ 𝓝 a ↔ (↑) '' t ∈ 𝓝[s] (a : α) := by
rw [← map_nhds_subtype_val, image_mem_map_iff Subtype.val_injective]
#align mem_nhds_subtype_iff_nhds_within mem_nhds_subtype_iff_nhdsWithin
theorem preimage_coe_mem_nhds_subtype {s t : Set α} {a : s} : (↑) ⁻¹' t ∈ 𝓝 a ↔ t ∈ 𝓝[s] ↑a := by
rw [← map_nhds_subtype_val, mem_map]
#align preimage_coe_mem_nhds_subtype preimage_coe_mem_nhds_subtype
theorem eventually_nhds_subtype_iff (s : Set α) (a : s) (P : α → Prop) :
(∀ᶠ x : s in 𝓝 a, P x) ↔ ∀ᶠ x in 𝓝[s] a, P x :=
preimage_coe_mem_nhds_subtype
theorem frequently_nhds_subtype_iff (s : Set α) (a : s) (P : α → Prop) :
(∃ᶠ x : s in 𝓝 a, P x) ↔ ∃ᶠ x in 𝓝[s] a, P x :=
eventually_nhds_subtype_iff s a (¬ P ·) |>.not
theorem tendsto_nhdsWithin_iff_subtype {s : Set α} {a : α} (h : a ∈ s) (f : α → β) (l : Filter β) :
Tendsto f (𝓝[s] a) l ↔ Tendsto (s.restrict f) (𝓝 ⟨a, h⟩) l := by
rw [nhdsWithin_eq_map_subtype_coe h, tendsto_map'_iff]; rfl
#align tendsto_nhds_within_iff_subtype tendsto_nhdsWithin_iff_subtype
variable [TopologicalSpace β] [TopologicalSpace γ] [TopologicalSpace δ]
/-- If a function is continuous within `s` at `x`, then it tends to `f x` within `s` by definition.
We register this fact for use with the dot notation, especially to use `Filter.Tendsto.comp` as
`ContinuousWithinAt.comp` will have a different meaning. -/
theorem ContinuousWithinAt.tendsto {f : α → β} {s : Set α} {x : α} (h : ContinuousWithinAt f s x) :
Tendsto f (𝓝[s] x) (𝓝 (f x)) :=
h
#align continuous_within_at.tendsto ContinuousWithinAt.tendsto
theorem ContinuousOn.continuousWithinAt {f : α → β} {s : Set α} {x : α} (hf : ContinuousOn f s)
(hx : x ∈ s) : ContinuousWithinAt f s x :=
hf x hx
#align continuous_on.continuous_within_at ContinuousOn.continuousWithinAt
theorem continuousWithinAt_univ (f : α → β) (x : α) :
ContinuousWithinAt f Set.univ x ↔ ContinuousAt f x := by
rw [ContinuousAt, ContinuousWithinAt, nhdsWithin_univ]
#align continuous_within_at_univ continuousWithinAt_univ
| Mathlib/Topology/ContinuousOn.lean | 533 | 535 | theorem continuous_iff_continuousOn_univ {f : α → β} : Continuous f ↔ ContinuousOn f univ := by |
simp [continuous_iff_continuousAt, ContinuousOn, ContinuousAt, ContinuousWithinAt,
nhdsWithin_univ]
|
/-
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.Alter
import Batteries.Data.List.Lemmas
/-!
# Additional lemmas for Red-black trees
-/
namespace Batteries
namespace RBNode
open RBColor
attribute [simp] fold foldl foldr Any forM foldlM Ordered
@[simp] theorem min?_reverse (t : RBNode α) : t.reverse.min? = t.max? := by
unfold RBNode.max?; split <;> simp [RBNode.min?]
unfold RBNode.min?; rw [min?.match_1.eq_3]
· apply min?_reverse
· simpa [reverse_eq_iff]
@[simp] theorem max?_reverse (t : RBNode α) : t.reverse.max? = t.min? := by
rw [← min?_reverse, reverse_reverse]
@[simp] theorem mem_nil {x} : ¬x ∈ (.nil : RBNode α) := by simp [(·∈·), EMem]
@[simp] theorem mem_node {y c a x b} :
y ∈ (.node c a x b : RBNode α) ↔ y = x ∨ y ∈ a ∨ y ∈ b := by simp [(·∈·), EMem]
theorem All_def {t : RBNode α} : t.All p ↔ ∀ x ∈ t, p x := by
induction t <;> simp [or_imp, forall_and, *]
theorem Any_def {t : RBNode α} : t.Any p ↔ ∃ x ∈ t, p x := by
induction t <;> simp [or_and_right, exists_or, *]
theorem memP_def : MemP cut t ↔ ∃ x ∈ t, cut x = .eq := Any_def
theorem mem_def : Mem cmp x t ↔ ∃ y ∈ t, cmp x y = .eq := Any_def
theorem mem_congr [@TransCmp α cmp] {t : RBNode α} (h : cmp x y = .eq) :
Mem cmp x t ↔ Mem cmp y t := by simp [Mem, TransCmp.cmp_congr_left' h]
theorem isOrdered_iff' [@TransCmp α cmp] {t : RBNode α} :
isOrdered cmp t L R ↔
(∀ a ∈ L, t.All (cmpLT cmp a ·)) ∧
(∀ a ∈ R, t.All (cmpLT cmp · a)) ∧
(∀ a ∈ L, ∀ b ∈ R, cmpLT cmp a b) ∧
Ordered cmp t := by
induction t generalizing L R with
| nil =>
simp [isOrdered]; split <;> simp [cmpLT_iff]
next h => intro _ ha _ hb; cases h _ _ ha hb
| node _ l v r =>
simp [isOrdered, *]
exact ⟨
fun ⟨⟨Ll, lv, Lv, ol⟩, ⟨vr, rR, vR, or⟩⟩ => ⟨
fun _ h => ⟨Lv _ h, Ll _ h, (Lv _ h).trans_l vr⟩,
fun _ h => ⟨vR _ h, (vR _ h).trans_r lv, rR _ h⟩,
fun _ hL _ hR => (Lv _ hL).trans (vR _ hR),
lv, vr, ol, or⟩,
fun ⟨hL, hR, _, lv, vr, ol, or⟩ => ⟨
⟨fun _ h => (hL _ h).2.1, lv, fun _ h => (hL _ h).1, ol⟩,
⟨vr, fun _ h => (hR _ h).2.2, fun _ h => (hR _ h).1, or⟩⟩⟩
theorem isOrdered_iff [@TransCmp α cmp] {t : RBNode α} :
isOrdered cmp t ↔ Ordered cmp t := by simp [isOrdered_iff']
instance (cmp) [@TransCmp α cmp] (t) : Decidable (Ordered cmp t) := decidable_of_iff _ isOrdered_iff
/--
A cut is like a homomorphism of orderings: it is a monotonic predicate with respect to `cmp`,
but it can make things that are distinguished by `cmp` equal.
This is sufficient for `find?` to locate an element on which `cut` returns `.eq`,
but there may be other elements, not returned by `find?`, on which `cut` also returns `.eq`.
-/
class IsCut (cmp : α → α → Ordering) (cut : α → Ordering) : Prop where
/-- The set `{x | cut x = .lt}` is downward-closed. -/
le_lt_trans [TransCmp cmp] : cmp x y ≠ .gt → cut x = .lt → cut y = .lt
/-- The set `{x | cut x = .gt}` is upward-closed. -/
le_gt_trans [TransCmp cmp] : cmp x y ≠ .gt → cut y = .gt → cut x = .gt
theorem IsCut.lt_trans [IsCut cmp cut] [TransCmp cmp]
(H : cmp x y = .lt) : cut x = .lt → cut y = .lt :=
IsCut.le_lt_trans <| TransCmp.gt_asymm <| OrientedCmp.cmp_eq_gt.2 H
theorem IsCut.gt_trans [IsCut cmp cut] [TransCmp cmp]
(H : cmp x y = .lt) : cut y = .gt → cut x = .gt :=
IsCut.le_gt_trans <| TransCmp.gt_asymm <| OrientedCmp.cmp_eq_gt.2 H
theorem IsCut.congr [IsCut cmp cut] [TransCmp cmp] (H : cmp x y = .eq) : cut x = cut y := by
cases ey : cut y
· exact IsCut.le_lt_trans (fun h => nomatch H.symm.trans <| OrientedCmp.cmp_eq_gt.1 h) ey
· cases ex : cut x
· exact IsCut.le_lt_trans (fun h => nomatch H.symm.trans h) ex |>.symm.trans ey
· rfl
· refine IsCut.le_gt_trans (cmp := cmp) (fun h => ?_) ex |>.symm.trans ey
cases H.symm.trans <| OrientedCmp.cmp_eq_gt.1 h
· exact IsCut.le_gt_trans (fun h => nomatch H.symm.trans h) ey
instance (cmp cut) [@IsCut α cmp cut] : IsCut (flip cmp) (cut · |>.swap) where
le_lt_trans h₁ h₂ := by
have : TransCmp cmp := inferInstanceAs (TransCmp (flip (flip cmp)))
rw [IsCut.le_gt_trans (cmp := cmp) h₁ (Ordering.swap_inj.1 h₂)]; rfl
le_gt_trans h₁ h₂ := by
have : TransCmp cmp := inferInstanceAs (TransCmp (flip (flip cmp)))
rw [IsCut.le_lt_trans (cmp := cmp) h₁ (Ordering.swap_inj.1 h₂)]; rfl
/--
`IsStrictCut` upgrades the `IsCut` property to ensure that at most one element of the tree
can match the cut, and hence `find?` will return the unique such element if one exists.
-/
class IsStrictCut (cmp : α → α → Ordering) (cut : α → Ordering) extends IsCut cmp cut : Prop where
/-- If `cut = x`, then `cut` and `x` have compare the same with respect to other elements. -/
exact [TransCmp cmp] : cut x = .eq → cmp x y = cut y
/-- A "representable cut" is one generated by `cmp a` for some `a`. This is always a valid cut. -/
instance (cmp) (a : α) : IsStrictCut cmp (cmp a) where
le_lt_trans h₁ h₂ := TransCmp.lt_le_trans h₂ h₁
le_gt_trans h₁ := Decidable.not_imp_not.1 (TransCmp.le_trans · h₁)
exact h := (TransCmp.cmp_congr_left h).symm
instance (cmp cut) [@IsStrictCut α cmp cut] : IsStrictCut (flip cmp) (cut · |>.swap) where
exact h := by
have : TransCmp cmp := inferInstanceAs (TransCmp (flip (flip cmp)))
rw [← IsStrictCut.exact (cmp := cmp) (Ordering.swap_inj.1 h), OrientedCmp.symm]; rfl
section fold
theorem foldr_cons (t : RBNode α) (l) : t.foldr (·::·) l = t.toList ++ l := by
unfold toList
induction t generalizing l with
| nil => rfl
| node _ a _ b iha ihb => rw [foldr, foldr, iha, iha (_::_), ihb]; simp
@[simp] theorem toList_nil : (.nil : RBNode α).toList = [] := rfl
@[simp] theorem toList_node : (.node c a x b : RBNode α).toList = a.toList ++ x :: b.toList := by
rw [toList, foldr, foldr_cons]; rfl
@[simp] theorem toList_reverse (t : RBNode α) : t.reverse.toList = t.toList.reverse := by
induction t <;> simp [*]
@[simp] theorem mem_toList {t : RBNode α} : x ∈ t.toList ↔ x ∈ t := by
induction t <;> simp [*, or_left_comm]
@[simp] theorem mem_reverse {t : RBNode α} : a ∈ t.reverse ↔ a ∈ t := by rw [← mem_toList]; simp
theorem min?_eq_toList_head? {t : RBNode α} : t.min? = t.toList.head? := by
induction t with
| nil => rfl
| node _ l _ _ ih =>
cases l <;> simp [RBNode.min?, ih]
next ll _ _ => cases toList ll <;> rfl
theorem max?_eq_toList_getLast? {t : RBNode α} : t.max? = t.toList.getLast? := by
rw [← min?_reverse, min?_eq_toList_head?]; simp
theorem foldr_eq_foldr_toList {t : RBNode α} : t.foldr f init = t.toList.foldr f init := by
induction t generalizing init <;> simp [*]
theorem foldl_eq_foldl_toList {t : RBNode α} : t.foldl f init = t.toList.foldl f init := by
induction t generalizing init <;> simp [*]
theorem foldl_reverse {α β : Type _} {t : RBNode α} {f : β → α → β} {init : β} :
t.reverse.foldl f init = t.foldr (flip f) init := by
simp (config := {unfoldPartialApp := true})
[foldr_eq_foldr_toList, foldl_eq_foldl_toList, flip]
theorem foldr_reverse {α β : Type _} {t : RBNode α} {f : α → β → β} {init : β} :
t.reverse.foldr f init = t.foldl (flip f) init :=
foldl_reverse.symm.trans (by simp; rfl)
theorem forM_eq_forM_toList [Monad m] [LawfulMonad m] {t : RBNode α} :
t.forM (m := m) f = t.toList.forM f := by induction t <;> simp [*]
theorem foldlM_eq_foldlM_toList [Monad m] [LawfulMonad m] {t : RBNode α} :
t.foldlM (m := m) f init = t.toList.foldlM f init := by
induction t generalizing init <;> simp [*]
theorem forIn_visit_eq_bindList [Monad m] [LawfulMonad m] {t : RBNode α} :
forIn.visit (m := m) f t init = (ForInStep.yield init).bindList f t.toList := by
induction t generalizing init <;> simp [*, forIn.visit]
theorem forIn_eq_forIn_toList [Monad m] [LawfulMonad m] {t : RBNode α} :
forIn (m := m) t init f = forIn t.toList init f := by
conv => lhs; simp only [forIn, RBNode.forIn]
rw [List.forIn_eq_bindList, forIn_visit_eq_bindList]
end fold
namespace Stream
attribute [simp] foldl foldr
theorem foldr_cons (t : RBNode.Stream α) (l) : t.foldr (·::·) l = t.toList ++ l := by
unfold toList; apply Eq.symm; induction t <;> simp [*, foldr, RBNode.foldr_cons]
@[simp] theorem toList_nil : (.nil : RBNode.Stream α).toList = [] := rfl
@[simp] theorem toList_cons :
(.cons x r s : RBNode.Stream α).toList = x :: r.toList ++ s.toList := by
rw [toList, toList, foldr, RBNode.foldr_cons]; rfl
theorem foldr_eq_foldr_toList {s : RBNode.Stream α} : s.foldr f init = s.toList.foldr f init := by
induction s <;> simp [*, RBNode.foldr_eq_foldr_toList]
theorem foldl_eq_foldl_toList {t : RBNode.Stream α} : t.foldl f init = t.toList.foldl f init := by
induction t generalizing init <;> simp [*, RBNode.foldl_eq_foldl_toList]
theorem forIn_eq_forIn_toList [Monad m] [LawfulMonad m] {t : RBNode α} :
forIn (m := m) t init f = forIn t.toList init f := by
conv => lhs; simp only [forIn, RBNode.forIn]
rw [List.forIn_eq_bindList, forIn_visit_eq_bindList]
end Stream
theorem toStream_toList' {t : RBNode α} {s} : (t.toStream s).toList = t.toList ++ s.toList := by
induction t generalizing s <;> simp [*, toStream]
@[simp] theorem toStream_toList {t : RBNode α} : t.toStream.toList = t.toList := by
simp [toStream_toList']
| .lake/packages/batteries/Batteries/Data/RBMap/Lemmas.lean | 225 | 227 | theorem Stream.next?_toList {s : RBNode.Stream α} :
(s.next?.map fun (a, b) => (a, b.toList)) = s.toList.next? := by |
cases s <;> simp [next?, toStream_toList']
|
/-
Copyright (c) 2020 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Floris van Doorn, Yury Kudryashov
-/
import Mathlib.Algebra.Star.Order
import Mathlib.Topology.Instances.NNReal
import Mathlib.Topology.Order.MonotoneContinuity
#align_import data.real.sqrt from "leanprover-community/mathlib"@"31c24aa72e7b3e5ed97a8412470e904f82b81004"
/-!
# Square root of a real number
In this file we define
* `NNReal.sqrt` to be the square root of a nonnegative real number.
* `Real.sqrt` to be the square root of a real number, defined to be zero on negative numbers.
Then we prove some basic properties of these functions.
## Implementation notes
We define `NNReal.sqrt` as the noncomputable inverse to the function `x ↦ x * x`. We use general
theory of inverses of strictly monotone functions to prove that `NNReal.sqrt x` exists. As a side
effect, `NNReal.sqrt` is a bundled `OrderIso`, so for `NNReal` numbers we get continuity as well as
theorems like `NNReal.sqrt x ≤ y ↔ x ≤ y * y` for free.
Then we define `Real.sqrt x` to be `NNReal.sqrt (Real.toNNReal x)`.
## Tags
square root
-/
open Set Filter
open scoped Filter NNReal Topology
namespace NNReal
variable {x y : ℝ≥0}
/-- Square root of a nonnegative real number. -/
-- Porting note: was @[pp_nodot]
noncomputable def sqrt : ℝ≥0 ≃o ℝ≥0 :=
OrderIso.symm <| powOrderIso 2 two_ne_zero
#align nnreal.sqrt NNReal.sqrt
@[simp] lemma sq_sqrt (x : ℝ≥0) : sqrt x ^ 2 = x := sqrt.symm_apply_apply _
#align nnreal.sq_sqrt NNReal.sq_sqrt
@[simp] lemma sqrt_sq (x : ℝ≥0) : sqrt (x ^ 2) = x := sqrt.apply_symm_apply _
#align nnreal.sqrt_sq NNReal.sqrt_sq
@[simp] lemma mul_self_sqrt (x : ℝ≥0) : sqrt x * sqrt x = x := by rw [← sq, sq_sqrt]
#align nnreal.mul_self_sqrt NNReal.mul_self_sqrt
@[simp] lemma sqrt_mul_self (x : ℝ≥0) : sqrt (x * x) = x := by rw [← sq, sqrt_sq]
#align nnreal.sqrt_mul_self NNReal.sqrt_mul_self
lemma sqrt_le_sqrt : sqrt x ≤ sqrt y ↔ x ≤ y := sqrt.le_iff_le
#align nnreal.sqrt_le_sqrt_iff NNReal.sqrt_le_sqrt
lemma sqrt_lt_sqrt : sqrt x < sqrt y ↔ x < y := sqrt.lt_iff_lt
#align nnreal.sqrt_lt_sqrt_iff NNReal.sqrt_lt_sqrt
lemma sqrt_eq_iff_eq_sq : sqrt x = y ↔ x = y ^ 2 := sqrt.toEquiv.apply_eq_iff_eq_symm_apply
#align nnreal.sqrt_eq_iff_sq_eq NNReal.sqrt_eq_iff_eq_sq
lemma sqrt_le_iff_le_sq : sqrt x ≤ y ↔ x ≤ y ^ 2 := sqrt.to_galoisConnection _ _
#align nnreal.sqrt_le_iff NNReal.sqrt_le_iff_le_sq
lemma le_sqrt_iff_sq_le : x ≤ sqrt y ↔ x ^ 2 ≤ y := (sqrt.symm.to_galoisConnection _ _).symm
#align nnreal.le_sqrt_iff NNReal.le_sqrt_iff_sq_le
-- 2024-02-14
@[deprecated] alias sqrt_le_sqrt_iff := sqrt_le_sqrt
@[deprecated] alias sqrt_lt_sqrt_iff := sqrt_lt_sqrt
@[deprecated] alias sqrt_le_iff := sqrt_le_iff_le_sq
@[deprecated] alias le_sqrt_iff := le_sqrt_iff_sq_le
@[deprecated] alias sqrt_eq_iff_sq_eq := sqrt_eq_iff_eq_sq
@[simp] lemma sqrt_eq_zero : sqrt x = 0 ↔ x = 0 := by simp [sqrt_eq_iff_eq_sq]
#align nnreal.sqrt_eq_zero NNReal.sqrt_eq_zero
@[simp] lemma sqrt_eq_one : sqrt x = 1 ↔ x = 1 := by simp [sqrt_eq_iff_eq_sq]
@[simp] lemma sqrt_zero : sqrt 0 = 0 := by simp
#align nnreal.sqrt_zero NNReal.sqrt_zero
@[simp] lemma sqrt_one : sqrt 1 = 1 := by simp
#align nnreal.sqrt_one NNReal.sqrt_one
@[simp] lemma sqrt_le_one : sqrt x ≤ 1 ↔ x ≤ 1 := by rw [← sqrt_one, sqrt_le_sqrt, sqrt_one]
@[simp] lemma one_le_sqrt : 1 ≤ sqrt x ↔ 1 ≤ x := by rw [← sqrt_one, sqrt_le_sqrt, sqrt_one]
theorem sqrt_mul (x y : ℝ≥0) : sqrt (x * y) = sqrt x * sqrt y := by
rw [sqrt_eq_iff_eq_sq, mul_pow, sq_sqrt, sq_sqrt]
#align nnreal.sqrt_mul NNReal.sqrt_mul
/-- `NNReal.sqrt` as a `MonoidWithZeroHom`. -/
noncomputable def sqrtHom : ℝ≥0 →*₀ ℝ≥0 :=
⟨⟨sqrt, sqrt_zero⟩, sqrt_one, sqrt_mul⟩
#align nnreal.sqrt_hom NNReal.sqrtHom
theorem sqrt_inv (x : ℝ≥0) : sqrt x⁻¹ = (sqrt x)⁻¹ :=
map_inv₀ sqrtHom x
#align nnreal.sqrt_inv NNReal.sqrt_inv
theorem sqrt_div (x y : ℝ≥0) : sqrt (x / y) = sqrt x / sqrt y :=
map_div₀ sqrtHom x y
#align nnreal.sqrt_div NNReal.sqrt_div
@[continuity, fun_prop]
theorem continuous_sqrt : Continuous sqrt := sqrt.continuous
#align nnreal.continuous_sqrt NNReal.continuous_sqrt
@[simp] theorem sqrt_pos : 0 < sqrt x ↔ 0 < x := by simp [pos_iff_ne_zero]
alias ⟨_, sqrt_pos_of_pos⟩ := sqrt_pos
end NNReal
namespace Real
/-- The square root of a real number. This returns 0 for negative inputs.
This has notation `√x`. Note that `√x⁻¹` is parsed as `√(x⁻¹)`. -/
noncomputable def sqrt (x : ℝ) : ℝ :=
NNReal.sqrt (Real.toNNReal x)
#align real.sqrt Real.sqrt
-- TODO: replace this with a typeclass
@[inherit_doc]
prefix:max "√" => Real.sqrt
/- quotient.lift_on x
(λ f, mk ⟨sqrt_aux f, (sqrt_aux_converges f).fst⟩)
(λ f g e, begin
rcases sqrt_aux_converges f with ⟨hf, x, x0, xf, xs⟩,
rcases sqrt_aux_converges g with ⟨hg, y, y0, yg, ys⟩,
refine xs.trans (eq.trans _ ys.symm),
rw [← @mul_self_inj_of_nonneg ℝ _ x y x0 y0, xf, yg],
congr' 1, exact quotient.sound e
end)-/
variable {x y : ℝ}
@[simp, norm_cast]
theorem coe_sqrt {x : ℝ≥0} : (NNReal.sqrt x : ℝ) = √(x : ℝ) := by
rw [Real.sqrt, Real.toNNReal_coe]
#align real.coe_sqrt Real.coe_sqrt
@[continuity]
theorem continuous_sqrt : Continuous (√· : ℝ → ℝ) :=
NNReal.continuous_coe.comp <| NNReal.continuous_sqrt.comp continuous_real_toNNReal
#align real.continuous_sqrt Real.continuous_sqrt
theorem sqrt_eq_zero_of_nonpos (h : x ≤ 0) : sqrt x = 0 := by simp [sqrt, Real.toNNReal_eq_zero.2 h]
#align real.sqrt_eq_zero_of_nonpos Real.sqrt_eq_zero_of_nonpos
theorem sqrt_nonneg (x : ℝ) : 0 ≤ √x :=
NNReal.coe_nonneg _
#align real.sqrt_nonneg Real.sqrt_nonneg
@[simp]
theorem mul_self_sqrt (h : 0 ≤ x) : √x * √x = x := by
rw [Real.sqrt, ← NNReal.coe_mul, NNReal.mul_self_sqrt, Real.coe_toNNReal _ h]
#align real.mul_self_sqrt Real.mul_self_sqrt
@[simp]
theorem sqrt_mul_self (h : 0 ≤ x) : √(x * x) = x :=
(mul_self_inj_of_nonneg (sqrt_nonneg _) h).1 (mul_self_sqrt (mul_self_nonneg _))
#align real.sqrt_mul_self Real.sqrt_mul_self
theorem sqrt_eq_cases : √x = y ↔ y * y = x ∧ 0 ≤ y ∨ x < 0 ∧ y = 0 := by
constructor
· rintro rfl
rcases le_or_lt 0 x with hle | hlt
· exact Or.inl ⟨mul_self_sqrt hle, sqrt_nonneg x⟩
· exact Or.inr ⟨hlt, sqrt_eq_zero_of_nonpos hlt.le⟩
· rintro (⟨rfl, hy⟩ | ⟨hx, rfl⟩)
exacts [sqrt_mul_self hy, sqrt_eq_zero_of_nonpos hx.le]
#align real.sqrt_eq_cases Real.sqrt_eq_cases
theorem sqrt_eq_iff_mul_self_eq (hx : 0 ≤ x) (hy : 0 ≤ y) : √x = y ↔ y * y = x :=
⟨fun h => by rw [← h, mul_self_sqrt hx], fun h => by rw [← h, sqrt_mul_self hy]⟩
#align real.sqrt_eq_iff_mul_self_eq Real.sqrt_eq_iff_mul_self_eq
theorem sqrt_eq_iff_mul_self_eq_of_pos (h : 0 < y) : √x = y ↔ y * y = x := by
simp [sqrt_eq_cases, h.ne', h.le]
#align real.sqrt_eq_iff_mul_self_eq_of_pos Real.sqrt_eq_iff_mul_self_eq_of_pos
@[simp]
theorem sqrt_eq_one : √x = 1 ↔ x = 1 :=
calc
√x = 1 ↔ 1 * 1 = x := sqrt_eq_iff_mul_self_eq_of_pos zero_lt_one
_ ↔ x = 1 := by rw [eq_comm, mul_one]
#align real.sqrt_eq_one Real.sqrt_eq_one
@[simp]
theorem sq_sqrt (h : 0 ≤ x) : √x ^ 2 = x := by rw [sq, mul_self_sqrt h]
#align real.sq_sqrt Real.sq_sqrt
@[simp]
theorem sqrt_sq (h : 0 ≤ x) : √(x ^ 2) = x := by rw [sq, sqrt_mul_self h]
#align real.sqrt_sq Real.sqrt_sq
theorem sqrt_eq_iff_sq_eq (hx : 0 ≤ x) (hy : 0 ≤ y) : √x = y ↔ y ^ 2 = x := by
rw [sq, sqrt_eq_iff_mul_self_eq hx hy]
#align real.sqrt_eq_iff_sq_eq Real.sqrt_eq_iff_sq_eq
theorem sqrt_mul_self_eq_abs (x : ℝ) : √(x * x) = |x| := by
rw [← abs_mul_abs_self x, sqrt_mul_self (abs_nonneg _)]
#align real.sqrt_mul_self_eq_abs Real.sqrt_mul_self_eq_abs
theorem sqrt_sq_eq_abs (x : ℝ) : √(x ^ 2) = |x| := by rw [sq, sqrt_mul_self_eq_abs]
#align real.sqrt_sq_eq_abs Real.sqrt_sq_eq_abs
@[simp]
theorem sqrt_zero : √0 = 0 := by simp [Real.sqrt]
#align real.sqrt_zero Real.sqrt_zero
@[simp]
theorem sqrt_one : √1 = 1 := by simp [Real.sqrt]
#align real.sqrt_one Real.sqrt_one
@[simp]
theorem sqrt_le_sqrt_iff (hy : 0 ≤ y) : √x ≤ √y ↔ x ≤ y := by
rw [Real.sqrt, Real.sqrt, NNReal.coe_le_coe, NNReal.sqrt_le_sqrt, toNNReal_le_toNNReal_iff hy]
#align real.sqrt_le_sqrt_iff Real.sqrt_le_sqrt_iff
@[simp]
theorem sqrt_lt_sqrt_iff (hx : 0 ≤ x) : √x < √y ↔ x < y :=
lt_iff_lt_of_le_iff_le (sqrt_le_sqrt_iff hx)
#align real.sqrt_lt_sqrt_iff Real.sqrt_lt_sqrt_iff
theorem sqrt_lt_sqrt_iff_of_pos (hy : 0 < y) : √x < √y ↔ x < y := by
rw [Real.sqrt, Real.sqrt, NNReal.coe_lt_coe, NNReal.sqrt_lt_sqrt, toNNReal_lt_toNNReal_iff hy]
#align real.sqrt_lt_sqrt_iff_of_pos Real.sqrt_lt_sqrt_iff_of_pos
@[gcongr]
theorem sqrt_le_sqrt (h : x ≤ y) : √x ≤ √y := by
rw [Real.sqrt, Real.sqrt, NNReal.coe_le_coe, NNReal.sqrt_le_sqrt]
exact toNNReal_le_toNNReal h
#align real.sqrt_le_sqrt Real.sqrt_le_sqrt
@[gcongr]
theorem sqrt_lt_sqrt (hx : 0 ≤ x) (h : x < y) : √x < √y :=
(sqrt_lt_sqrt_iff hx).2 h
#align real.sqrt_lt_sqrt Real.sqrt_lt_sqrt
theorem sqrt_le_left (hy : 0 ≤ y) : √x ≤ y ↔ x ≤ y ^ 2 := by
rw [sqrt, ← Real.le_toNNReal_iff_coe_le hy, NNReal.sqrt_le_iff_le_sq, sq, ← Real.toNNReal_mul hy,
Real.toNNReal_le_toNNReal_iff (mul_self_nonneg y), sq]
#align real.sqrt_le_left Real.sqrt_le_left
theorem sqrt_le_iff : √x ≤ y ↔ 0 ≤ y ∧ x ≤ y ^ 2 := by
rw [← and_iff_right_of_imp fun h => (sqrt_nonneg x).trans h, and_congr_right_iff]
exact sqrt_le_left
#align real.sqrt_le_iff Real.sqrt_le_iff
theorem sqrt_lt (hx : 0 ≤ x) (hy : 0 ≤ y) : √x < y ↔ x < y ^ 2 := by
rw [← sqrt_lt_sqrt_iff hx, sqrt_sq hy]
#align real.sqrt_lt Real.sqrt_lt
theorem sqrt_lt' (hy : 0 < y) : √x < y ↔ x < y ^ 2 := by
rw [← sqrt_lt_sqrt_iff_of_pos (pow_pos hy _), sqrt_sq hy.le]
#align real.sqrt_lt' Real.sqrt_lt'
/-- Note: if you want to conclude `x ≤ √y`, then use `Real.le_sqrt_of_sq_le`.
If you have `x > 0`, consider using `Real.le_sqrt'` -/
theorem le_sqrt (hx : 0 ≤ x) (hy : 0 ≤ y) : x ≤ √y ↔ x ^ 2 ≤ y :=
le_iff_le_iff_lt_iff_lt.2 <| sqrt_lt hy hx
#align real.le_sqrt Real.le_sqrt
theorem le_sqrt' (hx : 0 < x) : x ≤ √y ↔ x ^ 2 ≤ y :=
le_iff_le_iff_lt_iff_lt.2 <| sqrt_lt' hx
#align real.le_sqrt' Real.le_sqrt'
theorem abs_le_sqrt (h : x ^ 2 ≤ y) : |x| ≤ √y := by
rw [← sqrt_sq_eq_abs]; exact sqrt_le_sqrt h
#align real.abs_le_sqrt Real.abs_le_sqrt
theorem sq_le (h : 0 ≤ y) : x ^ 2 ≤ y ↔ -√y ≤ x ∧ x ≤ √y := by
constructor
· simpa only [abs_le] using abs_le_sqrt
· rw [← abs_le, ← sq_abs]
exact (le_sqrt (abs_nonneg x) h).mp
#align real.sq_le Real.sq_le
theorem neg_sqrt_le_of_sq_le (h : x ^ 2 ≤ y) : -√y ≤ x :=
((sq_le ((sq_nonneg x).trans h)).mp h).1
#align real.neg_sqrt_le_of_sq_le Real.neg_sqrt_le_of_sq_le
theorem le_sqrt_of_sq_le (h : x ^ 2 ≤ y) : x ≤ √y :=
((sq_le ((sq_nonneg x).trans h)).mp h).2
#align real.le_sqrt_of_sq_le Real.le_sqrt_of_sq_le
@[simp]
theorem sqrt_inj (hx : 0 ≤ x) (hy : 0 ≤ y) : √x = √y ↔ x = y := by
simp [le_antisymm_iff, hx, hy]
#align real.sqrt_inj Real.sqrt_inj
@[simp]
theorem sqrt_eq_zero (h : 0 ≤ x) : √x = 0 ↔ x = 0 := by simpa using sqrt_inj h le_rfl
#align real.sqrt_eq_zero Real.sqrt_eq_zero
theorem sqrt_eq_zero' : √x = 0 ↔ x ≤ 0 := by
rw [sqrt, NNReal.coe_eq_zero, NNReal.sqrt_eq_zero, Real.toNNReal_eq_zero]
#align real.sqrt_eq_zero' Real.sqrt_eq_zero'
theorem sqrt_ne_zero (h : 0 ≤ x) : √x ≠ 0 ↔ x ≠ 0 := by rw [not_iff_not, sqrt_eq_zero h]
#align real.sqrt_ne_zero Real.sqrt_ne_zero
theorem sqrt_ne_zero' : √x ≠ 0 ↔ 0 < x := by rw [← not_le, not_iff_not, sqrt_eq_zero']
#align real.sqrt_ne_zero' Real.sqrt_ne_zero'
@[simp]
theorem sqrt_pos : 0 < √x ↔ 0 < x :=
lt_iff_lt_of_le_iff_le (Iff.trans (by simp [le_antisymm_iff, sqrt_nonneg]) sqrt_eq_zero')
#align real.sqrt_pos Real.sqrt_pos
alias ⟨_, sqrt_pos_of_pos⟩ := sqrt_pos
#align real.sqrt_pos_of_pos Real.sqrt_pos_of_pos
lemma sqrt_le_sqrt_iff' (hx : 0 < x) : √x ≤ √y ↔ x ≤ y := by
obtain hy | hy := le_total y 0
· exact iff_of_false ((sqrt_eq_zero_of_nonpos hy).trans_lt $ sqrt_pos.2 hx).not_le
(hy.trans_lt hx).not_le
· exact sqrt_le_sqrt_iff hy
@[simp] lemma one_le_sqrt : 1 ≤ √x ↔ 1 ≤ x := by
rw [← sqrt_one, sqrt_le_sqrt_iff' zero_lt_one, sqrt_one]
@[simp] lemma sqrt_le_one : √x ≤ 1 ↔ x ≤ 1 := by
rw [← sqrt_one, sqrt_le_sqrt_iff zero_le_one, sqrt_one]
end Real
namespace Mathlib.Meta.Positivity
open Lean Meta Qq Function
/-- Extension for the `positivity` tactic: a square root of a strictly positive nonnegative real is
positive. -/
@[positivity NNReal.sqrt _]
def evalNNRealSqrt : PositivityExt where eval {u α} _zα _pα e := do
match u, α, e with
| 0, ~q(NNReal), ~q(NNReal.sqrt $a) =>
let ra ← core q(inferInstance) q(inferInstance) a
assertInstancesCommute
match ra with
| .positive pa => pure (.positive q(NNReal.sqrt_pos_of_pos $pa))
| _ => failure -- this case is dealt with by generic nonnegativity of nnreals
| _, _, _ => throwError "not NNReal.sqrt"
/-- Extension for the `positivity` tactic: a square root is nonnegative, and is strictly positive if
its input is. -/
@[positivity √ _]
def evalSqrt : PositivityExt where eval {u α} _zα _pα e := do
match u, α, e with
| 0, ~q(ℝ), ~q(√$a) =>
let ra ← catchNone <| core q(inferInstance) q(inferInstance) a
assertInstancesCommute
match ra with
| .positive pa => pure (.positive q(Real.sqrt_pos_of_pos $pa))
| _ => pure (.nonnegative q(Real.sqrt_nonneg $a))
| _, _, _ => throwError "not Real.sqrt"
end Mathlib.Meta.Positivity
namespace Real
variable {x y : ℝ}
@[simp]
theorem sqrt_mul {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : √(x * y) = √x * √y := by
simp_rw [Real.sqrt, ← NNReal.coe_mul, NNReal.coe_inj, Real.toNNReal_mul hx, NNReal.sqrt_mul]
#align real.sqrt_mul Real.sqrt_mul
@[simp]
theorem sqrt_mul' (x) {y : ℝ} (hy : 0 ≤ y) : √(x * y) = √x * √y := by
rw [mul_comm, sqrt_mul hy, mul_comm]
#align real.sqrt_mul' Real.sqrt_mul'
@[simp]
theorem sqrt_inv (x : ℝ) : √x⁻¹ = (√x)⁻¹ := by
rw [Real.sqrt, Real.toNNReal_inv, NNReal.sqrt_inv, NNReal.coe_inv, Real.sqrt]
#align real.sqrt_inv Real.sqrt_inv
@[simp]
theorem sqrt_div {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : √(x / y) = √x / √y := by
rw [division_def, sqrt_mul hx, sqrt_inv, division_def]
#align real.sqrt_div Real.sqrt_div
@[simp]
theorem sqrt_div' (x) {y : ℝ} (hy : 0 ≤ y) : √(x / y) = √x / √y := by
rw [division_def, sqrt_mul' x (inv_nonneg.2 hy), sqrt_inv, division_def]
#align real.sqrt_div' Real.sqrt_div'
variable {x y : ℝ}
@[simp]
theorem div_sqrt : x / √x = √x := by
rcases le_or_lt x 0 with h | h
· rw [sqrt_eq_zero'.mpr h, div_zero]
· rw [div_eq_iff (sqrt_ne_zero'.mpr h), mul_self_sqrt h.le]
#align real.div_sqrt Real.div_sqrt
theorem sqrt_div_self' : √x / x = 1 / √x := by rw [← div_sqrt, one_div_div, div_sqrt]
#align real.sqrt_div_self' Real.sqrt_div_self'
theorem sqrt_div_self : √x / x = (√x)⁻¹ := by rw [sqrt_div_self', one_div]
#align real.sqrt_div_self Real.sqrt_div_self
theorem lt_sqrt (hx : 0 ≤ x) : x < √y ↔ x ^ 2 < y := by
rw [← sqrt_lt_sqrt_iff (sq_nonneg _), sqrt_sq hx]
#align real.lt_sqrt Real.lt_sqrt
theorem sq_lt : x ^ 2 < y ↔ -√y < x ∧ x < √y := by
rw [← abs_lt, ← sq_abs, lt_sqrt (abs_nonneg _)]
#align real.sq_lt Real.sq_lt
theorem neg_sqrt_lt_of_sq_lt (h : x ^ 2 < y) : -√y < x :=
(sq_lt.mp h).1
#align real.neg_sqrt_lt_of_sq_lt Real.neg_sqrt_lt_of_sq_lt
theorem lt_sqrt_of_sq_lt (h : x ^ 2 < y) : x < √y :=
(sq_lt.mp h).2
#align real.lt_sqrt_of_sq_lt Real.lt_sqrt_of_sq_lt
theorem lt_sq_of_sqrt_lt (h : √x < y) : x < y ^ 2 := by
have hy := x.sqrt_nonneg.trans_lt h
rwa [← sqrt_lt_sqrt_iff_of_pos (sq_pos_of_pos hy), sqrt_sq hy.le]
#align real.lt_sq_of_sqrt_lt Real.lt_sq_of_sqrt_lt
/-- The natural square root is at most the real square root -/
theorem nat_sqrt_le_real_sqrt {a : ℕ} : ↑(Nat.sqrt a) ≤ √(a : ℝ) := by
rw [Real.le_sqrt (Nat.cast_nonneg _) (Nat.cast_nonneg _)]
norm_cast
exact Nat.sqrt_le' a
#align real.nat_sqrt_le_real_sqrt Real.nat_sqrt_le_real_sqrt
/-- The real square root is less than the natural square root plus one -/
theorem real_sqrt_lt_nat_sqrt_succ {a : ℕ} : √(a : ℝ) < Nat.sqrt a + 1 := by
rw [sqrt_lt (by simp)] <;> norm_cast
· exact Nat.lt_succ_sqrt' a
· exact Nat.le_add_left 0 (Nat.sqrt a + 1)
/-- The real square root is at most the natural square root plus one -/
theorem real_sqrt_le_nat_sqrt_succ {a : ℕ} : √(a : ℝ) ≤ Nat.sqrt a + 1 :=
real_sqrt_lt_nat_sqrt_succ.le
#align real.real_sqrt_le_nat_sqrt_succ Real.real_sqrt_le_nat_sqrt_succ
/-- The floor of the real square root is the same as the natural square root. -/
@[simp]
theorem floor_real_sqrt_eq_nat_sqrt {a : ℕ} : ⌊√(a : ℝ)⌋ = Nat.sqrt a := by
rw [Int.floor_eq_iff]
exact ⟨nat_sqrt_le_real_sqrt, real_sqrt_lt_nat_sqrt_succ⟩
/-- The natural floor of the real square root is the same as the natural square root. -/
@[simp]
| Mathlib/Data/Real/Sqrt.lean | 463 | 465 | theorem nat_floor_real_sqrt_eq_nat_sqrt {a : ℕ} : ⌊√(a : ℝ)⌋₊ = Nat.sqrt a := by |
rw [Nat.floor_eq_iff (sqrt_nonneg a)]
exact ⟨nat_sqrt_le_real_sqrt, real_sqrt_lt_nat_sqrt_succ⟩
|
/-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
-/
import Mathlib.Data.Int.Bitwise
import Mathlib.Data.Int.Order.Lemmas
import Mathlib.Data.Set.Function
import Mathlib.Order.Interval.Set.Basic
#align_import data.int.lemmas from "leanprover-community/mathlib"@"09597669f02422ed388036273d8848119699c22f"
/-!
# Miscellaneous lemmas about the integers
This file contains lemmas about integers, which require further imports than
`Data.Int.Basic` or `Data.Int.Order`.
-/
open Nat
namespace Int
theorem le_natCast_sub (m n : ℕ) : (m - n : ℤ) ≤ ↑(m - n : ℕ) := by
by_cases h : m ≥ n
· exact le_of_eq (Int.ofNat_sub h).symm
· simp [le_of_not_ge h, ofNat_le]
#align int.le_coe_nat_sub Int.le_natCast_sub
/-! ### `succ` and `pred` -/
-- Porting note (#10618): simp can prove this @[simp]
theorem succ_natCast_pos (n : ℕ) : 0 < (n : ℤ) + 1 :=
lt_add_one_iff.mpr (by simp)
#align int.succ_coe_nat_pos Int.succ_natCast_pos
/-! ### `natAbs` -/
variable {a b : ℤ} {n : ℕ}
theorem natAbs_eq_iff_sq_eq {a b : ℤ} : a.natAbs = b.natAbs ↔ a ^ 2 = b ^ 2 := by
rw [sq, sq]
exact natAbs_eq_iff_mul_self_eq
#align int.nat_abs_eq_iff_sq_eq Int.natAbs_eq_iff_sq_eq
theorem natAbs_lt_iff_sq_lt {a b : ℤ} : a.natAbs < b.natAbs ↔ a ^ 2 < b ^ 2 := by
rw [sq, sq]
exact natAbs_lt_iff_mul_self_lt
#align int.nat_abs_lt_iff_sq_lt Int.natAbs_lt_iff_sq_lt
theorem natAbs_le_iff_sq_le {a b : ℤ} : a.natAbs ≤ b.natAbs ↔ a ^ 2 ≤ b ^ 2 := by
rw [sq, sq]
exact natAbs_le_iff_mul_self_le
#align int.nat_abs_le_iff_sq_le Int.natAbs_le_iff_sq_le
theorem natAbs_inj_of_nonneg_of_nonneg {a b : ℤ} (ha : 0 ≤ a) (hb : 0 ≤ b) :
natAbs a = natAbs b ↔ a = b := by rw [← sq_eq_sq ha hb, ← natAbs_eq_iff_sq_eq]
#align int.nat_abs_inj_of_nonneg_of_nonneg Int.natAbs_inj_of_nonneg_of_nonneg
theorem natAbs_inj_of_nonpos_of_nonpos {a b : ℤ} (ha : a ≤ 0) (hb : b ≤ 0) :
natAbs a = natAbs b ↔ a = b := by
simpa only [Int.natAbs_neg, neg_inj] using
natAbs_inj_of_nonneg_of_nonneg (neg_nonneg_of_nonpos ha) (neg_nonneg_of_nonpos hb)
#align int.nat_abs_inj_of_nonpos_of_nonpos Int.natAbs_inj_of_nonpos_of_nonpos
theorem natAbs_inj_of_nonneg_of_nonpos {a b : ℤ} (ha : 0 ≤ a) (hb : b ≤ 0) :
natAbs a = natAbs b ↔ a = -b := by
simpa only [Int.natAbs_neg] using natAbs_inj_of_nonneg_of_nonneg ha (neg_nonneg_of_nonpos hb)
#align int.nat_abs_inj_of_nonneg_of_nonpos Int.natAbs_inj_of_nonneg_of_nonpos
theorem natAbs_inj_of_nonpos_of_nonneg {a b : ℤ} (ha : a ≤ 0) (hb : 0 ≤ b) :
natAbs a = natAbs b ↔ -a = b := by
simpa only [Int.natAbs_neg] using natAbs_inj_of_nonneg_of_nonneg (neg_nonneg_of_nonpos ha) hb
#align int.nat_abs_inj_of_nonpos_of_nonneg Int.natAbs_inj_of_nonpos_of_nonneg
/-- A specialization of `abs_sub_le_of_nonneg_of_le` for working with the signed subtraction
of natural numbers. -/
| Mathlib/Data/Int/Lemmas.lean | 82 | 86 | theorem natAbs_coe_sub_coe_le_of_le {a b n : ℕ} (a_le_n : a ≤ n) (b_le_n : b ≤ n) :
natAbs (a - b : ℤ) ≤ n := by |
rw [← Nat.cast_le (α := ℤ), natCast_natAbs]
exact abs_sub_le_of_nonneg_of_le (ofNat_nonneg a) (ofNat_le.mpr a_le_n)
(ofNat_nonneg b) (ofNat_le.mpr b_le_n)
|
/-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Yaël Dillies
-/
import Mathlib.Order.Cover
import Mathlib.Order.Interval.Finset.Defs
#align_import data.finset.locally_finite from "leanprover-community/mathlib"@"442a83d738cb208d3600056c489be16900ba701d"
/-!
# Intervals as finsets
This file provides basic results about all the `Finset.Ixx`, which are defined in
`Order.Interval.Finset.Defs`.
In addition, it shows that in a locally finite order `≤` and `<` are the transitive closures of,
respectively, `⩿` and `⋖`, which then leads to a characterization of monotone and strictly
functions whose domain is a locally finite order. In particular, this file proves:
* `le_iff_transGen_wcovBy`: `≤` is the transitive closure of `⩿`
* `lt_iff_transGen_covBy`: `≤` is the transitive closure of `⩿`
* `monotone_iff_forall_wcovBy`: Characterization of monotone functions
* `strictMono_iff_forall_covBy`: Characterization of strictly monotone functions
## TODO
This file was originally only about `Finset.Ico a b` where `a b : ℕ`. No care has yet been taken to
generalize these lemmas properly and many lemmas about `Icc`, `Ioc`, `Ioo` are missing. In general,
what's to do is taking the lemmas in `Data.X.Intervals` and abstract away the concrete structure.
Complete the API. See
https://github.com/leanprover-community/mathlib/pull/14448#discussion_r906109235
for some ideas.
-/
assert_not_exists MonoidWithZero
assert_not_exists Finset.sum
open Function OrderDual
open FinsetInterval
variable {ι α : Type*}
namespace Finset
section Preorder
variable [Preorder α]
section LocallyFiniteOrder
variable [LocallyFiniteOrder α] {a a₁ a₂ b b₁ b₂ c x : α}
@[simp, aesop safe apply (rule_sets := [finsetNonempty])]
theorem nonempty_Icc : (Icc a b).Nonempty ↔ a ≤ b := by
rw [← coe_nonempty, coe_Icc, Set.nonempty_Icc]
#align finset.nonempty_Icc Finset.nonempty_Icc
@[simp, aesop safe apply (rule_sets := [finsetNonempty])]
theorem nonempty_Ico : (Ico a b).Nonempty ↔ a < b := by
rw [← coe_nonempty, coe_Ico, Set.nonempty_Ico]
#align finset.nonempty_Ico Finset.nonempty_Ico
@[simp, aesop safe apply (rule_sets := [finsetNonempty])]
theorem nonempty_Ioc : (Ioc a b).Nonempty ↔ a < b := by
rw [← coe_nonempty, coe_Ioc, Set.nonempty_Ioc]
#align finset.nonempty_Ioc Finset.nonempty_Ioc
-- TODO: This is nonsense. A locally finite order is never densely ordered
@[simp]
theorem nonempty_Ioo [DenselyOrdered α] : (Ioo a b).Nonempty ↔ a < b := by
rw [← coe_nonempty, coe_Ioo, Set.nonempty_Ioo]
#align finset.nonempty_Ioo Finset.nonempty_Ioo
@[simp]
theorem Icc_eq_empty_iff : Icc a b = ∅ ↔ ¬a ≤ b := by
rw [← coe_eq_empty, coe_Icc, Set.Icc_eq_empty_iff]
#align finset.Icc_eq_empty_iff Finset.Icc_eq_empty_iff
@[simp]
theorem Ico_eq_empty_iff : Ico a b = ∅ ↔ ¬a < b := by
rw [← coe_eq_empty, coe_Ico, Set.Ico_eq_empty_iff]
#align finset.Ico_eq_empty_iff Finset.Ico_eq_empty_iff
@[simp]
theorem Ioc_eq_empty_iff : Ioc a b = ∅ ↔ ¬a < b := by
rw [← coe_eq_empty, coe_Ioc, Set.Ioc_eq_empty_iff]
#align finset.Ioc_eq_empty_iff Finset.Ioc_eq_empty_iff
-- TODO: This is nonsense. A locally finite order is never densely ordered
@[simp]
theorem Ioo_eq_empty_iff [DenselyOrdered α] : Ioo a b = ∅ ↔ ¬a < b := by
rw [← coe_eq_empty, coe_Ioo, Set.Ioo_eq_empty_iff]
#align finset.Ioo_eq_empty_iff Finset.Ioo_eq_empty_iff
alias ⟨_, Icc_eq_empty⟩ := Icc_eq_empty_iff
#align finset.Icc_eq_empty Finset.Icc_eq_empty
alias ⟨_, Ico_eq_empty⟩ := Ico_eq_empty_iff
#align finset.Ico_eq_empty Finset.Ico_eq_empty
alias ⟨_, Ioc_eq_empty⟩ := Ioc_eq_empty_iff
#align finset.Ioc_eq_empty Finset.Ioc_eq_empty
@[simp]
theorem Ioo_eq_empty (h : ¬a < b) : Ioo a b = ∅ :=
eq_empty_iff_forall_not_mem.2 fun _ hx => h ((mem_Ioo.1 hx).1.trans (mem_Ioo.1 hx).2)
#align finset.Ioo_eq_empty Finset.Ioo_eq_empty
@[simp]
theorem Icc_eq_empty_of_lt (h : b < a) : Icc a b = ∅ :=
Icc_eq_empty h.not_le
#align finset.Icc_eq_empty_of_lt Finset.Icc_eq_empty_of_lt
@[simp]
theorem Ico_eq_empty_of_le (h : b ≤ a) : Ico a b = ∅ :=
Ico_eq_empty h.not_lt
#align finset.Ico_eq_empty_of_le Finset.Ico_eq_empty_of_le
@[simp]
theorem Ioc_eq_empty_of_le (h : b ≤ a) : Ioc a b = ∅ :=
Ioc_eq_empty h.not_lt
#align finset.Ioc_eq_empty_of_le Finset.Ioc_eq_empty_of_le
@[simp]
theorem Ioo_eq_empty_of_le (h : b ≤ a) : Ioo a b = ∅ :=
Ioo_eq_empty h.not_lt
#align finset.Ioo_eq_empty_of_le Finset.Ioo_eq_empty_of_le
-- porting note (#10618): simp can prove this
-- @[simp]
theorem left_mem_Icc : a ∈ Icc a b ↔ a ≤ b := by simp only [mem_Icc, true_and_iff, le_rfl]
#align finset.left_mem_Icc Finset.left_mem_Icc
-- porting note (#10618): simp can prove this
-- @[simp]
theorem left_mem_Ico : a ∈ Ico a b ↔ a < b := by simp only [mem_Ico, true_and_iff, le_refl]
#align finset.left_mem_Ico Finset.left_mem_Ico
-- porting note (#10618): simp can prove this
-- @[simp]
theorem right_mem_Icc : b ∈ Icc a b ↔ a ≤ b := by simp only [mem_Icc, and_true_iff, le_rfl]
#align finset.right_mem_Icc Finset.right_mem_Icc
-- porting note (#10618): simp can prove this
-- @[simp]
theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b := by simp only [mem_Ioc, and_true_iff, le_rfl]
#align finset.right_mem_Ioc Finset.right_mem_Ioc
-- porting note (#10618): simp can prove this
-- @[simp]
theorem left_not_mem_Ioc : a ∉ Ioc a b := fun h => lt_irrefl _ (mem_Ioc.1 h).1
#align finset.left_not_mem_Ioc Finset.left_not_mem_Ioc
-- porting note (#10618): simp can prove this
-- @[simp]
theorem left_not_mem_Ioo : a ∉ Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).1
#align finset.left_not_mem_Ioo Finset.left_not_mem_Ioo
-- porting note (#10618): simp can prove this
-- @[simp]
theorem right_not_mem_Ico : b ∉ Ico a b := fun h => lt_irrefl _ (mem_Ico.1 h).2
#align finset.right_not_mem_Ico Finset.right_not_mem_Ico
-- porting note (#10618): simp can prove this
-- @[simp]
theorem right_not_mem_Ioo : b ∉ Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).2
#align finset.right_not_mem_Ioo Finset.right_not_mem_Ioo
theorem Icc_subset_Icc (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊆ Icc a₂ b₂ := by
simpa [← coe_subset] using Set.Icc_subset_Icc ha hb
#align finset.Icc_subset_Icc Finset.Icc_subset_Icc
theorem Ico_subset_Ico (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ico a₁ b₁ ⊆ Ico a₂ b₂ := by
simpa [← coe_subset] using Set.Ico_subset_Ico ha hb
#align finset.Ico_subset_Ico Finset.Ico_subset_Ico
theorem Ioc_subset_Ioc (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ioc a₁ b₁ ⊆ Ioc a₂ b₂ := by
simpa [← coe_subset] using Set.Ioc_subset_Ioc ha hb
#align finset.Ioc_subset_Ioc Finset.Ioc_subset_Ioc
theorem Ioo_subset_Ioo (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ioo a₁ b₁ ⊆ Ioo a₂ b₂ := by
simpa [← coe_subset] using Set.Ioo_subset_Ioo ha hb
#align finset.Ioo_subset_Ioo Finset.Ioo_subset_Ioo
theorem Icc_subset_Icc_left (h : a₁ ≤ a₂) : Icc a₂ b ⊆ Icc a₁ b :=
Icc_subset_Icc h le_rfl
#align finset.Icc_subset_Icc_left Finset.Icc_subset_Icc_left
theorem Ico_subset_Ico_left (h : a₁ ≤ a₂) : Ico a₂ b ⊆ Ico a₁ b :=
Ico_subset_Ico h le_rfl
#align finset.Ico_subset_Ico_left Finset.Ico_subset_Ico_left
theorem Ioc_subset_Ioc_left (h : a₁ ≤ a₂) : Ioc a₂ b ⊆ Ioc a₁ b :=
Ioc_subset_Ioc h le_rfl
#align finset.Ioc_subset_Ioc_left Finset.Ioc_subset_Ioc_left
theorem Ioo_subset_Ioo_left (h : a₁ ≤ a₂) : Ioo a₂ b ⊆ Ioo a₁ b :=
Ioo_subset_Ioo h le_rfl
#align finset.Ioo_subset_Ioo_left Finset.Ioo_subset_Ioo_left
theorem Icc_subset_Icc_right (h : b₁ ≤ b₂) : Icc a b₁ ⊆ Icc a b₂ :=
Icc_subset_Icc le_rfl h
#align finset.Icc_subset_Icc_right Finset.Icc_subset_Icc_right
theorem Ico_subset_Ico_right (h : b₁ ≤ b₂) : Ico a b₁ ⊆ Ico a b₂ :=
Ico_subset_Ico le_rfl h
#align finset.Ico_subset_Ico_right Finset.Ico_subset_Ico_right
theorem Ioc_subset_Ioc_right (h : b₁ ≤ b₂) : Ioc a b₁ ⊆ Ioc a b₂ :=
Ioc_subset_Ioc le_rfl h
#align finset.Ioc_subset_Ioc_right Finset.Ioc_subset_Ioc_right
theorem Ioo_subset_Ioo_right (h : b₁ ≤ b₂) : Ioo a b₁ ⊆ Ioo a b₂ :=
Ioo_subset_Ioo le_rfl h
#align finset.Ioo_subset_Ioo_right Finset.Ioo_subset_Ioo_right
theorem Ico_subset_Ioo_left (h : a₁ < a₂) : Ico a₂ b ⊆ Ioo a₁ b := by
rw [← coe_subset, coe_Ico, coe_Ioo]
exact Set.Ico_subset_Ioo_left h
#align finset.Ico_subset_Ioo_left Finset.Ico_subset_Ioo_left
theorem Ioc_subset_Ioo_right (h : b₁ < b₂) : Ioc a b₁ ⊆ Ioo a b₂ := by
rw [← coe_subset, coe_Ioc, coe_Ioo]
exact Set.Ioc_subset_Ioo_right h
#align finset.Ioc_subset_Ioo_right Finset.Ioc_subset_Ioo_right
| Mathlib/Order/Interval/Finset/Basic.lean | 230 | 232 | theorem Icc_subset_Ico_right (h : b₁ < b₂) : Icc a b₁ ⊆ Ico a b₂ := by |
rw [← coe_subset, coe_Icc, coe_Ico]
exact Set.Icc_subset_Ico_right h
|
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
-/
import Mathlib.LinearAlgebra.FiniteDimensional
import Mathlib.LinearAlgebra.GeneralLinearGroup
import Mathlib.LinearAlgebra.Matrix.Reindex
import Mathlib.Tactic.FieldSimp
import Mathlib.LinearAlgebra.Matrix.NonsingularInverse
import Mathlib.LinearAlgebra.Matrix.Basis
#align_import linear_algebra.determinant from "leanprover-community/mathlib"@"0c1d80f5a86b36c1db32e021e8d19ae7809d5b79"
/-!
# Determinant of families of vectors
This file defines the determinant of an endomorphism, and of a family of vectors
with respect to some basis. For the determinant of a matrix, see the file
`LinearAlgebra.Matrix.Determinant`.
## Main definitions
In the list below, and in all this file, `R` is a commutative ring (semiring
is sometimes enough), `M` and its variations are `R`-modules, `ι`, `κ`, `n` and `m` are finite
types used for indexing.
* `Basis.det`: the determinant of a family of vectors with respect to a basis,
as a multilinear map
* `LinearMap.det`: the determinant of an endomorphism `f : End R M` as a
multiplicative homomorphism (if `M` does not have a finite `R`-basis, the
result is `1` instead)
* `LinearEquiv.det`: the determinant of an isomorphism `f : M ≃ₗ[R] M` as a
multiplicative homomorphism (if `M` does not have a finite `R`-basis, the
result is `1` instead)
## Tags
basis, det, determinant
-/
noncomputable section
open Matrix LinearMap Submodule Set Function
universe u v w
variable {R : Type*} [CommRing R]
variable {M : Type*} [AddCommGroup M] [Module R M]
variable {M' : Type*} [AddCommGroup M'] [Module R M']
variable {ι : Type*} [DecidableEq ι] [Fintype ι]
variable (e : Basis ι R M)
section Conjugate
variable {A : Type*} [CommRing A]
variable {m n : Type*}
/-- If `R^m` and `R^n` are linearly equivalent, then `m` and `n` are also equivalent. -/
def equivOfPiLEquivPi {R : Type*} [Finite m] [Finite n] [CommRing R] [Nontrivial R]
(e : (m → R) ≃ₗ[R] n → R) : m ≃ n :=
Basis.indexEquiv (Basis.ofEquivFun e.symm) (Pi.basisFun _ _)
#align equiv_of_pi_lequiv_pi equivOfPiLEquivPi
namespace Matrix
variable [Fintype m] [Fintype n]
/-- If `M` and `M'` are each other's inverse matrices, they are square matrices up to
equivalence of types. -/
def indexEquivOfInv [Nontrivial A] [DecidableEq m] [DecidableEq n] {M : Matrix m n A}
{M' : Matrix n m A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : m ≃ n :=
equivOfPiLEquivPi (toLin'OfInv hMM' hM'M)
#align matrix.index_equiv_of_inv Matrix.indexEquivOfInv
theorem det_comm [DecidableEq n] (M N : Matrix n n A) : det (M * N) = det (N * M) := by
rw [det_mul, det_mul, mul_comm]
#align matrix.det_comm Matrix.det_comm
/-- If there exists a two-sided inverse `M'` for `M` (indexed differently),
then `det (N * M) = det (M * N)`. -/
theorem det_comm' [DecidableEq m] [DecidableEq n] {M : Matrix n m A} {N : Matrix m n A}
{M' : Matrix m n A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : det (M * N) = det (N * M) := by
nontriviality A
-- Although `m` and `n` are different a priori, we will show they have the same cardinality.
-- This turns the problem into one for square matrices, which is easy.
let e := indexEquivOfInv hMM' hM'M
rw [← det_submatrix_equiv_self e, ← submatrix_mul_equiv _ _ _ (Equiv.refl n) _, det_comm,
submatrix_mul_equiv, Equiv.coe_refl, submatrix_id_id]
#align matrix.det_comm' Matrix.det_comm'
/-- If `M'` is a two-sided inverse for `M` (indexed differently), `det (M * N * M') = det N`.
See `Matrix.det_conj` and `Matrix.det_conj'` for the case when `M' = M⁻¹` or vice versa. -/
theorem det_conj_of_mul_eq_one [DecidableEq m] [DecidableEq n] {M : Matrix m n A}
{M' : Matrix n m A} {N : Matrix n n A} (hMM' : M * M' = 1) (hM'M : M' * M = 1) :
det (M * N * M') = det N := by
rw [← det_comm' hM'M hMM', ← Matrix.mul_assoc, hM'M, Matrix.one_mul]
#align matrix.det_conj_of_mul_eq_one Matrix.det_conj_of_mul_eq_one
end Matrix
end Conjugate
namespace LinearMap
/-! ### Determinant of a linear map -/
variable {A : Type*} [CommRing A] [Module A M]
variable {κ : Type*} [Fintype κ]
/-- The determinant of `LinearMap.toMatrix` does not depend on the choice of basis. -/
| Mathlib/LinearAlgebra/Determinant.lean | 115 | 119 | theorem det_toMatrix_eq_det_toMatrix [DecidableEq κ] (b : Basis ι A M) (c : Basis κ A M)
(f : M →ₗ[A] M) : det (LinearMap.toMatrix b b f) = det (LinearMap.toMatrix c c f) := by |
rw [← linearMap_toMatrix_mul_basis_toMatrix c b c, ← basis_toMatrix_mul_linearMap_toMatrix b c b,
Matrix.det_conj_of_mul_eq_one] <;>
rw [Basis.toMatrix_mul_toMatrix, Basis.toMatrix_self]
|
/-
Copyright (c) 2021 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Eric Rodriguez
-/
import Mathlib.GroupTheory.ClassEquation
import Mathlib.GroupTheory.GroupAction.ConjAct
import Mathlib.RingTheory.Polynomial.Cyclotomic.Eval
/-!
# Wedderburn's Little Theorem
This file proves Wedderburn's Little Theorem.
## Main Declarations
* `littleWedderburn`: a finite division ring is a field.
## Future work
A couple simple generalisations are possible:
* A finite ring is commutative iff all its nilpotents lie in the center.
[Chintala, Vineeth, *Sorry, the Nilpotents Are in the Center*][chintala2020]
* A ring is commutative if all its elements have finite order.
[Dolan, S. W., *A Proof of Jacobson's Theorem*][dolan1975]
When alternativity is added to Mathlib, one could formalise the Artin-Zorn theorem, which states
that any finite alternative division ring is in fact a field.
https://en.wikipedia.org/wiki/Artin%E2%80%93Zorn_theorem
If interested, generalisations to semifields could be explored. The theory of semi-vector spaces is
not clear, but assuming that such a theory could be found where every module considered in the
below proof is free, then the proof works nearly verbatim.
-/
open scoped Polynomial
open Fintype
/-! Everything in this namespace is internal to the proof of Wedderburn's little theorem. -/
namespace LittleWedderburn
variable (D : Type*) [DivisionRing D]
private def InductionHyp : Prop :=
∀ {R : Subring D}, R < ⊤ → ∀ ⦃x y⦄, x ∈ R → y ∈ R → x * y = y * x
namespace InductionHyp
open FiniteDimensional Polynomial
variable {D}
private def field (hD : InductionHyp D) {R : Subring D} (hR : R < ⊤)
[Fintype D] [DecidableEq D] [DecidablePred (· ∈ R)] :
Field R :=
{ show DivisionRing R from Fintype.divisionRingOfIsDomain R with
mul_comm := fun x y ↦ Subtype.ext <| hD hR x.2 y.2 }
set_option backward.synthInstance.canonInstances false in -- See https://github.com/leanprover-community/mathlib4/issues/12532
/-- We prove that if every subring of `D` is central, then so is `D`. -/
private theorem center_eq_top [Finite D] (hD : InductionHyp D) : Subring.center D = ⊤ := by
classical
cases nonempty_fintype D
set Z := Subring.center D
-- We proceed by contradiction; that is, we assume the center is strictly smaller than `D`.
by_contra! hZ
letI : Field Z := hD.field hZ.lt_top
set q := card Z with card_Z
have hq : 1 < q := by rw [card_Z]; exact one_lt_card
let n := finrank Z D
have card_D : card D = q ^ n := card_eq_pow_finrank
have h1qn : 1 ≤ q ^ n := by rw [← card_D]; exact card_pos
-- We go about this by looking at the class equation for `Dˣ`:
-- `q ^ n - 1 = q - 1 + ∑ x : conjugacy classes (D ∖ Dˣ), |x|`.
-- The next few lines gets the equation into basically this form over `ℤ`.
have key := Group.card_center_add_sum_card_noncenter_eq_card (Dˣ)
rw [card_congr (show _ ≃* Zˣ from Subgroup.centerUnitsEquivUnitsCenter D).toEquiv,
card_units, ← card_Z, card_units, card_D] at key
-- By properties of the cyclotomic function, we have that `Φₙ(q) ∣ q ^ n - 1`; however, when
-- `n ≠ 1`, then `¬Φₙ(q) | q - 1`; so if the sum over the conjugacy classes is divisible by
-- `Φₙ(q)`, then `n = 1`, and therefore the vector space is trivial, as desired.
let Φₙ := cyclotomic n ℤ
apply_fun (Nat.cast : ℕ → ℤ) at key
rw [Nat.cast_add, Nat.cast_sub h1qn, Nat.cast_sub hq.le, Nat.cast_one, Nat.cast_pow] at key
suffices Φₙ.eval ↑q ∣ ↑(∑ x ∈ (ConjClasses.noncenter Dˣ).toFinset, x.carrier.toFinset.card) by
have contra : Φₙ.eval _ ∣ _ := eval_dvd (cyclotomic.dvd_X_pow_sub_one n ℤ) (x := (q : ℤ))
rw [eval_sub, eval_pow, eval_X, eval_one, ← key, Int.dvd_add_left this] at contra
refine (Nat.le_of_dvd ?_ ?_).not_lt (sub_one_lt_natAbs_cyclotomic_eval (n := n) ?_ hq.ne')
· exact tsub_pos_of_lt hq
· convert Int.natAbs_dvd_natAbs.mpr contra
clear_value q
simp only [eq_comm, Int.natAbs_eq_iff, Nat.cast_sub hq.le, Nat.cast_one, neg_sub, true_or]
· by_contra! h
obtain ⟨x, hx⟩ := finrank_le_one_iff.mp h
refine not_le_of_lt hZ.lt_top (fun y _ ↦ Subring.mem_center_iff.mpr fun z ↦ ?_)
obtain ⟨r, rfl⟩ := hx y
obtain ⟨s, rfl⟩ := hx z
rw [smul_mul_smul, smul_mul_smul, mul_comm]
rw [Nat.cast_sum]
apply Finset.dvd_sum
rintro ⟨x⟩ hx
simp (config := {zeta := false}) only [ConjClasses.quot_mk_eq_mk, Set.mem_toFinset] at hx ⊢
set Zx := Subring.centralizer ({↑x} : Set D)
-- The key thing is then to note that for all conjugacy classes `x`, `|x|` is given by
-- `|Dˣ| / |Zxˣ|`, where `Zx` is the centralizer of `x`; but `Zx` is an algebra over `Z`, and
-- therefore `|Zxˣ| = q ^ d - 1`, where `d` is the dimension of `D` as a vector space over `Z`.
-- We therefore get that `|x| = (q ^ n - 1) / (q ^ d - 1)`, and as `d` is a strict divisor of `n`,
-- we do have that `Φₙ(q) | (q ^ n - 1) / (q ^ d - 1)`; extending this over the whole sum
-- gives us the desired contradiction..
rw [Set.toFinset_card, ConjClasses.card_carrier, ← card_congr
(show Zxˣ ≃* _ from unitsCentralizerEquiv _ x).toEquiv, card_units, card_D]
have hZx : Zx ≠ ⊤ := by
by_contra! hZx
refine (ConjClasses.mk_bijOn (Dˣ)).mapsTo (Set.subset_center_units ?_) hx
exact Subring.centralizer_eq_top_iff_subset.mp hZx <| Set.mem_singleton _
letI : Field Zx := hD.field hZx.lt_top
letI : Algebra Z Zx := (Subring.inclusion <| Subring.center_le_centralizer {(x : D)}).toAlgebra
let d := finrank Z Zx
have card_Zx : card Zx = q ^ d := card_eq_pow_finrank
have h1qd : 1 ≤ q ^ d := by rw [← card_Zx]; exact card_pos
haveI : IsScalarTower Z Zx D := ⟨fun x y z ↦ mul_assoc _ _ _⟩
rw [card_units, card_Zx, Int.natCast_div, Nat.cast_sub h1qd, Nat.cast_sub h1qn, Nat.cast_one,
Nat.cast_pow, Nat.cast_pow]
apply Int.dvd_div_of_mul_dvd
have aux : ∀ {k : ℕ}, ((X : ℤ[X]) ^ k - 1).eval ↑q = (q : ℤ) ^ k - 1 := by
simp only [eval_X, eval_one, eval_pow, eval_sub, eq_self_iff_true, forall_const]
rw [← aux, ← aux, ← eval_mul]
refine (evalRingHom ↑q).map_dvd (X_pow_sub_one_mul_cyclotomic_dvd_X_pow_sub_one_of_dvd ℤ ?_)
refine Nat.mem_properDivisors.mpr ⟨⟨_, (finrank_mul_finrank Z Zx D).symm⟩, ?_⟩
rw [← pow_lt_pow_iff_right hq, ← card_D, ← card_Zx]
obtain ⟨b, -, hb⟩ := SetLike.exists_of_lt hZx.lt_top
refine card_lt_of_injective_of_not_mem _ Subtype.val_injective (?_ : b ∉ _)
rintro ⟨b, rfl⟩
exact hb b.2
end InductionHyp
private theorem center_eq_top [Finite D] : Subring.center D = ⊤ := by
classical
cases nonempty_fintype D
induction' hn : Fintype.card D using Nat.strong_induction_on with n IH generalizing D
apply InductionHyp.center_eq_top
intro R hR x y hx hy
suffices (⟨y, hy⟩ : R) ∈ Subring.center R by
rw [Subring.mem_center_iff] at this
simpa using this ⟨x, hx⟩
let R_dr : DivisionRing R := Fintype.divisionRingOfIsDomain R
rw [IH (Fintype.card R) _ R inferInstance rfl]
· trivial
rw [← hn, ← Subring.card_top D]
exact Set.card_lt_card hR
end LittleWedderburn
open LittleWedderburn
/-- A finite division ring is a field. See `Finite.isDomain_to_isField` and
`Fintype.divisionRingOfIsDomain` for more general statements, but these create data, and therefore
may cause diamonds if used improperly. -/
instance (priority := 100) littleWedderburn (D : Type*) [DivisionRing D] [Finite D] : Field D :=
{ ‹DivisionRing D› with
mul_comm := fun x y ↦ by simp [Subring.mem_center_iff.mp ?_ x, center_eq_top D] }
alias Finite.divisionRing_to_field := littleWedderburn
/-- A finite domain is a field. See also `littleWedderburn` and `Fintype.divisionRingOfIsDomain`. -/
| Mathlib/RingTheory/LittleWedderburn.lean | 168 | 173 | theorem Finite.isDomain_to_isField (D : Type*) [Finite D] [Ring D] [IsDomain D] : IsField D := by |
classical
cases nonempty_fintype D
let _ := Fintype.divisionRingOfIsDomain D
let _ := littleWedderburn D
exact Field.toIsField D
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.MeasureTheory.OuterMeasure.Operations
import Mathlib.Analysis.SpecificLimits.Basic
/-!
# Outer measures from functions
Given an arbitrary function `m : Set α → ℝ≥0∞` that sends `∅` to `0` we can define an outer
measure on `α` that on `s` is defined to be the infimum of `∑ᵢ, m (sᵢ)` for all collections of sets
`sᵢ` that cover `s`. This is the unique maximal outer measure that is at most the given function.
Given an outer measure `m`, the Carathéodory-measurable sets are the sets `s` such that
for all sets `t` we have `m t = m (t ∩ s) + m (t \ s)`. This forms a measurable space.
## Main definitions and statements
* `OuterMeasure.boundedBy` is the greatest outer measure that is at most the given function.
If you know that the given function sends `∅` to `0`, then `OuterMeasure.ofFunction` is a
special case.
* `sInf_eq_boundedBy_sInfGen` is a characterization of the infimum of outer measures.
## References
* <https://en.wikipedia.org/wiki/Outer_measure>
* <https://en.wikipedia.org/wiki/Carath%C3%A9odory%27s_criterion>
## Tags
outer measure, Carathéodory-measurable, Carathéodory's criterion
-/
#align_import measure_theory.measure.outer_measure from "leanprover-community/mathlib"@"343e80208d29d2d15f8050b929aa50fe4ce71b55"
noncomputable section
open Set Function Filter
open scoped Classical NNReal Topology ENNReal
namespace MeasureTheory
namespace OuterMeasure
section OfFunction
-- Porting note: "set_option eqn_compiler.zeta true" removed
variable {α : Type*} (m : Set α → ℝ≥0∞) (m_empty : m ∅ = 0)
/-- Given any function `m` assigning measures to sets satisying `m ∅ = 0`, there is
a unique maximal outer measure `μ` satisfying `μ s ≤ m s` for all `s : Set α`. -/
protected def ofFunction : OuterMeasure α :=
let μ s := ⨅ (f : ℕ → Set α) (_ : s ⊆ ⋃ i, f i), ∑' i, m (f i)
{ measureOf := μ
empty :=
le_antisymm
((iInf_le_of_le fun _ => ∅) <| iInf_le_of_le (empty_subset _) <| by simp [m_empty])
(zero_le _)
mono := fun {s₁ s₂} hs => iInf_mono fun f => iInf_mono' fun hb => ⟨hs.trans hb, le_rfl⟩
iUnion_nat := fun s _ =>
ENNReal.le_of_forall_pos_le_add <| by
intro ε hε (hb : (∑' i, μ (s i)) < ∞)
rcases ENNReal.exists_pos_sum_of_countable (ENNReal.coe_pos.2 hε).ne' ℕ with ⟨ε', hε', hl⟩
refine le_trans ?_ (add_le_add_left (le_of_lt hl) _)
rw [← ENNReal.tsum_add]
choose f hf using
show ∀ i, ∃ f : ℕ → Set α, (s i ⊆ ⋃ i, f i) ∧ (∑' i, m (f i)) < μ (s i) + ε' i by
intro i
have : μ (s i) < μ (s i) + ε' i :=
ENNReal.lt_add_right (ne_top_of_le_ne_top hb.ne <| ENNReal.le_tsum _)
(by simpa using (hε' i).ne')
rcases iInf_lt_iff.mp this with ⟨t, ht⟩
exists t
contrapose! ht
exact le_iInf ht
refine le_trans ?_ (ENNReal.tsum_le_tsum fun i => le_of_lt (hf i).2)
rw [← ENNReal.tsum_prod, ← Nat.pairEquiv.symm.tsum_eq]
refine iInf_le_of_le _ (iInf_le _ ?_)
apply iUnion_subset
intro i
apply Subset.trans (hf i).1
apply iUnion_subset
simp only [Nat.pairEquiv_symm_apply]
rw [iUnion_unpair]
intro j
apply subset_iUnion₂ i }
#align measure_theory.outer_measure.of_function MeasureTheory.OuterMeasure.ofFunction
theorem ofFunction_apply (s : Set α) :
OuterMeasure.ofFunction m m_empty s = ⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, m (t n) :=
rfl
#align measure_theory.outer_measure.of_function_apply MeasureTheory.OuterMeasure.ofFunction_apply
variable {m m_empty}
theorem ofFunction_le (s : Set α) : OuterMeasure.ofFunction m m_empty s ≤ m s :=
let f : ℕ → Set α := fun i => Nat.casesOn i s fun _ => ∅
iInf_le_of_le f <|
iInf_le_of_le (subset_iUnion f 0) <|
le_of_eq <| tsum_eq_single 0 <| by
rintro (_ | i)
· simp
· simp [m_empty]
#align measure_theory.outer_measure.of_function_le MeasureTheory.OuterMeasure.ofFunction_le
theorem ofFunction_eq (s : Set α) (m_mono : ∀ ⦃t : Set α⦄, s ⊆ t → m s ≤ m t)
(m_subadd : ∀ s : ℕ → Set α, m (⋃ i, s i) ≤ ∑' i, m (s i)) :
OuterMeasure.ofFunction m m_empty s = m s :=
le_antisymm (ofFunction_le s) <|
le_iInf fun f => le_iInf fun hf => le_trans (m_mono hf) (m_subadd f)
#align measure_theory.outer_measure.of_function_eq MeasureTheory.OuterMeasure.ofFunction_eq
theorem le_ofFunction {μ : OuterMeasure α} :
μ ≤ OuterMeasure.ofFunction m m_empty ↔ ∀ s, μ s ≤ m s :=
⟨fun H s => le_trans (H s) (ofFunction_le s), fun H _ =>
le_iInf fun f =>
le_iInf fun hs =>
le_trans (μ.mono hs) <| le_trans (measure_iUnion_le f) <| ENNReal.tsum_le_tsum fun _ => H _⟩
#align measure_theory.outer_measure.le_of_function MeasureTheory.OuterMeasure.le_ofFunction
theorem isGreatest_ofFunction :
IsGreatest { μ : OuterMeasure α | ∀ s, μ s ≤ m s } (OuterMeasure.ofFunction m m_empty) :=
⟨fun _ => ofFunction_le _, fun _ => le_ofFunction.2⟩
#align measure_theory.outer_measure.is_greatest_of_function MeasureTheory.OuterMeasure.isGreatest_ofFunction
theorem ofFunction_eq_sSup : OuterMeasure.ofFunction m m_empty = sSup { μ | ∀ s, μ s ≤ m s } :=
(@isGreatest_ofFunction α m m_empty).isLUB.sSup_eq.symm
#align measure_theory.outer_measure.of_function_eq_Sup MeasureTheory.OuterMeasure.ofFunction_eq_sSup
/-- If `m u = ∞` for any set `u` that has nonempty intersection both with `s` and `t`, then
`μ (s ∪ t) = μ s + μ t`, where `μ = MeasureTheory.OuterMeasure.ofFunction m m_empty`.
E.g., if `α` is an (e)metric space and `m u = ∞` on any set of diameter `≥ r`, then this lemma
implies that `μ (s ∪ t) = μ s + μ t` on any two sets such that `r ≤ edist x y` for all `x ∈ s`
and `y ∈ t`. -/
theorem ofFunction_union_of_top_of_nonempty_inter {s t : Set α}
(h : ∀ u, (s ∩ u).Nonempty → (t ∩ u).Nonempty → m u = ∞) :
OuterMeasure.ofFunction m m_empty (s ∪ t) =
OuterMeasure.ofFunction m m_empty s + OuterMeasure.ofFunction m m_empty t := by
refine le_antisymm (measure_union_le _ _) (le_iInf₂ fun f hf ↦ ?_)
set μ := OuterMeasure.ofFunction m m_empty
rcases Classical.em (∃ i, (s ∩ f i).Nonempty ∧ (t ∩ f i).Nonempty) with (⟨i, hs, ht⟩ | he)
· calc
μ s + μ t ≤ ∞ := le_top
_ = m (f i) := (h (f i) hs ht).symm
_ ≤ ∑' i, m (f i) := ENNReal.le_tsum i
set I := fun s => { i : ℕ | (s ∩ f i).Nonempty }
have hd : Disjoint (I s) (I t) := disjoint_iff_inf_le.mpr fun i hi => he ⟨i, hi⟩
have hI : ∀ u ⊆ s ∪ t, μ u ≤ ∑' i : I u, μ (f i) := fun u hu =>
calc
μ u ≤ μ (⋃ i : I u, f i) :=
μ.mono fun x hx =>
let ⟨i, hi⟩ := mem_iUnion.1 (hf (hu hx))
mem_iUnion.2 ⟨⟨i, ⟨x, hx, hi⟩⟩, hi⟩
_ ≤ ∑' i : I u, μ (f i) := measure_iUnion_le _
calc
μ s + μ t ≤ (∑' i : I s, μ (f i)) + ∑' i : I t, μ (f i) :=
add_le_add (hI _ subset_union_left) (hI _ subset_union_right)
_ = ∑' i : ↑(I s ∪ I t), μ (f i) :=
(tsum_union_disjoint (f := fun i => μ (f i)) hd ENNReal.summable ENNReal.summable).symm
_ ≤ ∑' i, μ (f i) :=
(tsum_le_tsum_of_inj (↑) Subtype.coe_injective (fun _ _ => zero_le _) (fun _ => le_rfl)
ENNReal.summable ENNReal.summable)
_ ≤ ∑' i, m (f i) := ENNReal.tsum_le_tsum fun i => ofFunction_le _
#align measure_theory.outer_measure.of_function_union_of_top_of_nonempty_inter MeasureTheory.OuterMeasure.ofFunction_union_of_top_of_nonempty_inter
theorem comap_ofFunction {β} (f : β → α) (h : Monotone m ∨ Surjective f) :
comap f (OuterMeasure.ofFunction m m_empty) =
OuterMeasure.ofFunction (fun s => m (f '' s)) (by simp; simp [m_empty]) := by
refine le_antisymm (le_ofFunction.2 fun s => ?_) fun s => ?_
· rw [comap_apply]
apply ofFunction_le
· rw [comap_apply, ofFunction_apply, ofFunction_apply]
refine iInf_mono' fun t => ⟨fun k => f ⁻¹' t k, ?_⟩
refine iInf_mono' fun ht => ?_
rw [Set.image_subset_iff, preimage_iUnion] at ht
refine ⟨ht, ENNReal.tsum_le_tsum fun n => ?_⟩
cases' h with hl hr
exacts [hl (image_preimage_subset _ _), (congr_arg m (hr.image_preimage (t n))).le]
#align measure_theory.outer_measure.comap_of_function MeasureTheory.OuterMeasure.comap_ofFunction
theorem map_ofFunction_le {β} (f : α → β) :
map f (OuterMeasure.ofFunction m m_empty) ≤
OuterMeasure.ofFunction (fun s => m (f ⁻¹' s)) m_empty :=
le_ofFunction.2 fun s => by
rw [map_apply]
apply ofFunction_le
#align measure_theory.outer_measure.map_of_function_le MeasureTheory.OuterMeasure.map_ofFunction_le
theorem map_ofFunction {β} {f : α → β} (hf : Injective f) :
map f (OuterMeasure.ofFunction m m_empty) =
OuterMeasure.ofFunction (fun s => m (f ⁻¹' s)) m_empty := by
refine (map_ofFunction_le _).antisymm fun s => ?_
simp only [ofFunction_apply, map_apply, le_iInf_iff]
intro t ht
refine iInf_le_of_le (fun n => (range f)ᶜ ∪ f '' t n) (iInf_le_of_le ?_ ?_)
· rw [← union_iUnion, ← inter_subset, ← image_preimage_eq_inter_range, ← image_iUnion]
exact image_subset _ ht
· refine ENNReal.tsum_le_tsum fun n => le_of_eq ?_
simp [hf.preimage_image]
#align measure_theory.outer_measure.map_of_function MeasureTheory.OuterMeasure.map_ofFunction
-- TODO (kmill): change `m (t ∩ s)` to `m (s ∩ t)`
theorem restrict_ofFunction (s : Set α) (hm : Monotone m) :
restrict s (OuterMeasure.ofFunction m m_empty) =
OuterMeasure.ofFunction (fun t => m (t ∩ s)) (by simp; simp [m_empty]) := by
rw [restrict]
simp only [inter_comm _ s, LinearMap.comp_apply]
rw [comap_ofFunction _ (Or.inl hm)]
simp only [map_ofFunction Subtype.coe_injective, Subtype.image_preimage_coe]
#align measure_theory.outer_measure.restrict_of_function MeasureTheory.OuterMeasure.restrict_ofFunction
theorem smul_ofFunction {c : ℝ≥0∞} (hc : c ≠ ∞) : c • OuterMeasure.ofFunction m m_empty =
OuterMeasure.ofFunction (c • m) (by simp [m_empty]) := by
ext1 s
haveI : Nonempty { t : ℕ → Set α // s ⊆ ⋃ i, t i } := ⟨⟨fun _ => s, subset_iUnion (fun _ => s) 0⟩⟩
simp only [smul_apply, ofFunction_apply, ENNReal.tsum_mul_left, Pi.smul_apply, smul_eq_mul,
iInf_subtype']
rw [ENNReal.iInf_mul_left fun h => (hc h).elim]
#align measure_theory.outer_measure.smul_of_function MeasureTheory.OuterMeasure.smul_ofFunction
end OfFunction
section BoundedBy
variable {α : Type*} (m : Set α → ℝ≥0∞)
/-- Given any function `m` assigning measures to sets, there is a unique maximal outer measure `μ`
satisfying `μ s ≤ m s` for all `s : Set α`. This is the same as `OuterMeasure.ofFunction`,
except that it doesn't require `m ∅ = 0`. -/
def boundedBy : OuterMeasure α :=
OuterMeasure.ofFunction (fun s => ⨆ _ : s.Nonempty, m s) (by simp [Set.not_nonempty_empty])
#align measure_theory.outer_measure.bounded_by MeasureTheory.OuterMeasure.boundedBy
variable {m}
theorem boundedBy_le (s : Set α) : boundedBy m s ≤ m s :=
(ofFunction_le _).trans iSup_const_le
#align measure_theory.outer_measure.bounded_by_le MeasureTheory.OuterMeasure.boundedBy_le
theorem boundedBy_eq_ofFunction (m_empty : m ∅ = 0) (s : Set α) :
boundedBy m s = OuterMeasure.ofFunction m m_empty s := by
have : (fun s : Set α => ⨆ _ : s.Nonempty, m s) = m := by
ext1 t
rcases t.eq_empty_or_nonempty with h | h <;> simp [h, Set.not_nonempty_empty, m_empty]
simp [boundedBy, this]
#align measure_theory.outer_measure.bounded_by_eq_of_function MeasureTheory.OuterMeasure.boundedBy_eq_ofFunction
theorem boundedBy_apply (s : Set α) :
boundedBy m s = ⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t),
∑' n, ⨆ _ : (t n).Nonempty, m (t n) := by
simp [boundedBy, ofFunction_apply]
#align measure_theory.outer_measure.bounded_by_apply MeasureTheory.OuterMeasure.boundedBy_apply
theorem boundedBy_eq (s : Set α) (m_empty : m ∅ = 0) (m_mono : ∀ ⦃t : Set α⦄, s ⊆ t → m s ≤ m t)
(m_subadd : ∀ s : ℕ → Set α, m (⋃ i, s i) ≤ ∑' i, m (s i)) : boundedBy m s = m s := by
rw [boundedBy_eq_ofFunction m_empty, ofFunction_eq s m_mono m_subadd]
#align measure_theory.outer_measure.bounded_by_eq MeasureTheory.OuterMeasure.boundedBy_eq
@[simp]
theorem boundedBy_eq_self (m : OuterMeasure α) : boundedBy m = m :=
ext fun _ => boundedBy_eq _ measure_empty (fun _ ht => measure_mono ht) measure_iUnion_le
#align measure_theory.outer_measure.bounded_by_eq_self MeasureTheory.OuterMeasure.boundedBy_eq_self
theorem le_boundedBy {μ : OuterMeasure α} : μ ≤ boundedBy m ↔ ∀ s, μ s ≤ m s := by
rw [boundedBy , le_ofFunction, forall_congr']; intro s
rcases s.eq_empty_or_nonempty with h | h <;> simp [h, Set.not_nonempty_empty]
#align measure_theory.outer_measure.le_bounded_by MeasureTheory.OuterMeasure.le_boundedBy
theorem le_boundedBy' {μ : OuterMeasure α} :
μ ≤ boundedBy m ↔ ∀ s : Set α, s.Nonempty → μ s ≤ m s := by
rw [le_boundedBy, forall_congr']
intro s
rcases s.eq_empty_or_nonempty with h | h <;> simp [h]
#align measure_theory.outer_measure.le_bounded_by' MeasureTheory.OuterMeasure.le_boundedBy'
@[simp]
theorem boundedBy_top : boundedBy (⊤ : Set α → ℝ≥0∞) = ⊤ := by
rw [eq_top_iff, le_boundedBy']
intro s hs
rw [top_apply hs]
exact le_rfl
#align measure_theory.outer_measure.bounded_by_top MeasureTheory.OuterMeasure.boundedBy_top
@[simp]
theorem boundedBy_zero : boundedBy (0 : Set α → ℝ≥0∞) = 0 := by
rw [← coe_bot, eq_bot_iff]
apply boundedBy_le
#align measure_theory.outer_measure.bounded_by_zero MeasureTheory.OuterMeasure.boundedBy_zero
theorem smul_boundedBy {c : ℝ≥0∞} (hc : c ≠ ∞) : c • boundedBy m = boundedBy (c • m) := by
simp only [boundedBy , smul_ofFunction hc]
congr 1 with s : 1
rcases s.eq_empty_or_nonempty with (rfl | hs) <;> simp [*]
#align measure_theory.outer_measure.smul_bounded_by MeasureTheory.OuterMeasure.smul_boundedBy
theorem comap_boundedBy {β} (f : β → α)
(h : (Monotone fun s : { s : Set α // s.Nonempty } => m s) ∨ Surjective f) :
comap f (boundedBy m) = boundedBy fun s => m (f '' s) := by
refine (comap_ofFunction _ ?_).trans ?_
· refine h.imp (fun H s t hst => iSup_le fun hs => ?_) id
have ht : t.Nonempty := hs.mono hst
exact (@H ⟨s, hs⟩ ⟨t, ht⟩ hst).trans (le_iSup (fun _ : t.Nonempty => m t) ht)
· dsimp only [boundedBy]
congr with s : 1
rw [image_nonempty]
#align measure_theory.outer_measure.comap_bounded_by MeasureTheory.OuterMeasure.comap_boundedBy
/-- If `m u = ∞` for any set `u` that has nonempty intersection both with `s` and `t`, then
`μ (s ∪ t) = μ s + μ t`, where `μ = MeasureTheory.OuterMeasure.boundedBy m`.
E.g., if `α` is an (e)metric space and `m u = ∞` on any set of diameter `≥ r`, then this lemma
implies that `μ (s ∪ t) = μ s + μ t` on any two sets such that `r ≤ edist x y` for all `x ∈ s`
and `y ∈ t`. -/
theorem boundedBy_union_of_top_of_nonempty_inter {s t : Set α}
(h : ∀ u, (s ∩ u).Nonempty → (t ∩ u).Nonempty → m u = ∞) :
boundedBy m (s ∪ t) = boundedBy m s + boundedBy m t :=
ofFunction_union_of_top_of_nonempty_inter fun u hs ht =>
top_unique <| (h u hs ht).ge.trans <| le_iSup (fun _ => m u) (hs.mono inter_subset_right)
#align measure_theory.outer_measure.bounded_by_union_of_top_of_nonempty_inter MeasureTheory.OuterMeasure.boundedBy_union_of_top_of_nonempty_inter
end BoundedBy
section sInfGen
variable {α : Type*}
/-- Given a set of outer measures, we define a new function that on a set `s` is defined to be the
infimum of `μ(s)` for the outer measures `μ` in the collection. We ensure that this
function is defined to be `0` on `∅`, even if the collection of outer measures is empty.
The outer measure generated by this function is the infimum of the given outer measures. -/
def sInfGen (m : Set (OuterMeasure α)) (s : Set α) : ℝ≥0∞ :=
⨅ (μ : OuterMeasure α) (_ : μ ∈ m), μ s
#align measure_theory.outer_measure.Inf_gen MeasureTheory.OuterMeasure.sInfGen
theorem sInfGen_def (m : Set (OuterMeasure α)) (t : Set α) :
sInfGen m t = ⨅ (μ : OuterMeasure α) (_ : μ ∈ m), μ t :=
rfl
#align measure_theory.outer_measure.Inf_gen_def MeasureTheory.OuterMeasure.sInfGen_def
theorem sInf_eq_boundedBy_sInfGen (m : Set (OuterMeasure α)) :
sInf m = OuterMeasure.boundedBy (sInfGen m) := by
refine le_antisymm ?_ ?_
· refine le_boundedBy.2 fun s => le_iInf₂ fun μ hμ => ?_
apply sInf_le hμ
· refine le_sInf ?_
intro μ hμ t
exact le_trans (boundedBy_le t) (iInf₂_le μ hμ)
#align measure_theory.outer_measure.Inf_eq_bounded_by_Inf_gen MeasureTheory.OuterMeasure.sInf_eq_boundedBy_sInfGen
theorem iSup_sInfGen_nonempty {m : Set (OuterMeasure α)} (h : m.Nonempty) (t : Set α) :
⨆ _ : t.Nonempty, sInfGen m t = ⨅ (μ : OuterMeasure α) (_ : μ ∈ m), μ t := by
rcases t.eq_empty_or_nonempty with (rfl | ht)
· simp [biInf_const h]
· simp [ht, sInfGen_def]
#align measure_theory.outer_measure.supr_Inf_gen_nonempty MeasureTheory.OuterMeasure.iSup_sInfGen_nonempty
/-- The value of the Infimum of a nonempty set of outer measures on a set is not simply
the minimum value of a measure on that set: it is the infimum sum of measures of countable set of
sets that covers that set, where a different measure can be used for each set in the cover. -/
theorem sInf_apply {m : Set (OuterMeasure α)} {s : Set α} (h : m.Nonempty) :
sInf m s =
⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, ⨅ (μ : OuterMeasure α) (_ : μ ∈ m), μ (t n) := by
simp_rw [sInf_eq_boundedBy_sInfGen, boundedBy_apply, iSup_sInfGen_nonempty h]
#align measure_theory.outer_measure.Inf_apply MeasureTheory.OuterMeasure.sInf_apply
/-- The value of the Infimum of a set of outer measures on a nonempty set is not simply
the minimum value of a measure on that set: it is the infimum sum of measures of countable set of
sets that covers that set, where a different measure can be used for each set in the cover. -/
theorem sInf_apply' {m : Set (OuterMeasure α)} {s : Set α} (h : s.Nonempty) :
sInf m s =
⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, ⨅ (μ : OuterMeasure α) (_ : μ ∈ m), μ (t n) :=
m.eq_empty_or_nonempty.elim (fun hm => by simp [hm, h]) sInf_apply
#align measure_theory.outer_measure.Inf_apply' MeasureTheory.OuterMeasure.sInf_apply'
/-- The value of the Infimum of a nonempty family of outer measures on a set is not simply
the minimum value of a measure on that set: it is the infimum sum of measures of countable set of
sets that covers that set, where a different measure can be used for each set in the cover. -/
theorem iInf_apply {ι} [Nonempty ι] (m : ι → OuterMeasure α) (s : Set α) :
(⨅ i, m i) s = ⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, ⨅ i, m i (t n) := by
rw [iInf, sInf_apply (range_nonempty m)]
simp only [iInf_range]
#align measure_theory.outer_measure.infi_apply MeasureTheory.OuterMeasure.iInf_apply
/-- The value of the Infimum of a family of outer measures on a nonempty set is not simply
the minimum value of a measure on that set: it is the infimum sum of measures of countable set of
sets that covers that set, where a different measure can be used for each set in the cover. -/
theorem iInf_apply' {ι} (m : ι → OuterMeasure α) {s : Set α} (hs : s.Nonempty) :
(⨅ i, m i) s = ⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, ⨅ i, m i (t n) := by
rw [iInf, sInf_apply' hs]
simp only [iInf_range]
#align measure_theory.outer_measure.infi_apply' MeasureTheory.OuterMeasure.iInf_apply'
/-- The value of the Infimum of a nonempty family of outer measures on a set is not simply
the minimum value of a measure on that set: it is the infimum sum of measures of countable set of
sets that covers that set, where a different measure can be used for each set in the cover. -/
theorem biInf_apply {ι} {I : Set ι} (hI : I.Nonempty) (m : ι → OuterMeasure α) (s : Set α) :
(⨅ i ∈ I, m i) s = ⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, ⨅ i ∈ I, m i (t n) := by
haveI := hI.to_subtype
simp only [← iInf_subtype'', iInf_apply]
#align measure_theory.outer_measure.binfi_apply MeasureTheory.OuterMeasure.biInf_apply
/-- The value of the Infimum of a nonempty family of outer measures on a set is not simply
the minimum value of a measure on that set: it is the infimum sum of measures of countable set of
sets that covers that set, where a different measure can be used for each set in the cover. -/
theorem biInf_apply' {ι} (I : Set ι) (m : ι → OuterMeasure α) {s : Set α} (hs : s.Nonempty) :
(⨅ i ∈ I, m i) s = ⨅ (t : ℕ → Set α) (_ : s ⊆ iUnion t), ∑' n, ⨅ i ∈ I, m i (t n) := by
simp only [← iInf_subtype'', iInf_apply' _ hs]
#align measure_theory.outer_measure.binfi_apply' MeasureTheory.OuterMeasure.biInf_apply'
theorem map_iInf_le {ι β} (f : α → β) (m : ι → OuterMeasure α) :
map f (⨅ i, m i) ≤ ⨅ i, map f (m i) :=
(map_mono f).map_iInf_le
#align measure_theory.outer_measure.map_infi_le MeasureTheory.OuterMeasure.map_iInf_le
theorem comap_iInf {ι β} (f : α → β) (m : ι → OuterMeasure β) :
comap f (⨅ i, m i) = ⨅ i, comap f (m i) := by
refine ext_nonempty fun s hs => ?_
refine ((comap_mono f).map_iInf_le s).antisymm ?_
simp only [comap_apply, iInf_apply' _ hs, iInf_apply' _ (hs.image _), le_iInf_iff,
Set.image_subset_iff, preimage_iUnion]
refine fun t ht => iInf_le_of_le _ (iInf_le_of_le ht <| ENNReal.tsum_le_tsum fun k => ?_)
exact iInf_mono fun i => (m i).mono (image_preimage_subset _ _)
#align measure_theory.outer_measure.comap_infi MeasureTheory.OuterMeasure.comap_iInf
theorem map_iInf {ι β} {f : α → β} (hf : Injective f) (m : ι → OuterMeasure α) :
map f (⨅ i, m i) = restrict (range f) (⨅ i, map f (m i)) := by
refine Eq.trans ?_ (map_comap _ _)
simp only [comap_iInf, comap_map hf]
#align measure_theory.outer_measure.map_infi MeasureTheory.OuterMeasure.map_iInf
theorem map_iInf_comap {ι β} [Nonempty ι] {f : α → β} (m : ι → OuterMeasure β) :
map f (⨅ i, comap f (m i)) = ⨅ i, map f (comap f (m i)) := by
refine (map_iInf_le _ _).antisymm fun s => ?_
simp only [map_apply, comap_apply, iInf_apply, le_iInf_iff]
refine fun t ht => iInf_le_of_le (fun n => f '' t n ∪ (range f)ᶜ) (iInf_le_of_le ?_ ?_)
· rw [← iUnion_union, Set.union_comm, ← inter_subset, ← image_iUnion, ←
image_preimage_eq_inter_range]
exact image_subset _ ht
· refine ENNReal.tsum_le_tsum fun n => iInf_mono fun i => (m i).mono ?_
simp only [preimage_union, preimage_compl, preimage_range, compl_univ, union_empty,
image_subset_iff]
exact subset_refl _
#align measure_theory.outer_measure.map_infi_comap MeasureTheory.OuterMeasure.map_iInf_comap
| Mathlib/MeasureTheory/OuterMeasure/OfFunction.lean | 451 | 455 | theorem map_biInf_comap {ι β} {I : Set ι} (hI : I.Nonempty) {f : α → β} (m : ι → OuterMeasure β) :
map f (⨅ i ∈ I, comap f (m i)) = ⨅ i ∈ I, map f (comap f (m i)) := by |
haveI := hI.to_subtype
rw [← iInf_subtype'', ← iInf_subtype'']
exact map_iInf_comap _
|
/-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers, Heather Macbeth
-/
import Mathlib.Analysis.InnerProductSpace.TwoDim
import Mathlib.Geometry.Euclidean.Angle.Unoriented.Basic
#align_import geometry.euclidean.angle.oriented.basic from "leanprover-community/mathlib"@"f0c8bf9245297a541f468be517f1bde6195105e9"
/-!
# Oriented angles.
This file defines oriented angles in real inner product spaces.
## Main definitions
* `Orientation.oangle` is the oriented angle between two vectors with respect to an orientation.
## Implementation notes
The definitions here use the `Real.angle` type, angles modulo `2 * π`. For some purposes,
angles modulo `π` are more convenient, because results are true for such angles with less
configuration dependence. Results that are only equalities modulo `π` can be represented
modulo `2 * π` as equalities of `(2 : ℤ) • θ`.
## References
* Evan Chen, Euclidean Geometry in Mathematical Olympiads.
-/
noncomputable section
open FiniteDimensional Complex
open scoped Real RealInnerProductSpace ComplexConjugate
namespace Orientation
attribute [local instance] Complex.finrank_real_complex_fact
variable {V V' : Type*}
variable [NormedAddCommGroup V] [NormedAddCommGroup V']
variable [InnerProductSpace ℝ V] [InnerProductSpace ℝ V']
variable [Fact (finrank ℝ V = 2)] [Fact (finrank ℝ V' = 2)] (o : Orientation ℝ V (Fin 2))
local notation "ω" => o.areaForm
/-- The oriented angle from `x` to `y`, modulo `2 * π`. If either vector is 0, this is 0.
See `InnerProductGeometry.angle` for the corresponding unoriented angle definition. -/
def oangle (x y : V) : Real.Angle :=
Complex.arg (o.kahler x y)
#align orientation.oangle Orientation.oangle
/-- Oriented angles are continuous when the vectors involved are nonzero. -/
theorem continuousAt_oangle {x : V × V} (hx1 : x.1 ≠ 0) (hx2 : x.2 ≠ 0) :
ContinuousAt (fun y : V × V => o.oangle y.1 y.2) x := by
refine (Complex.continuousAt_arg_coe_angle ?_).comp ?_
· exact o.kahler_ne_zero hx1 hx2
exact ((continuous_ofReal.comp continuous_inner).add
((continuous_ofReal.comp o.areaForm'.continuous₂).mul continuous_const)).continuousAt
#align orientation.continuous_at_oangle Orientation.continuousAt_oangle
/-- If the first vector passed to `oangle` is 0, the result is 0. -/
@[simp]
theorem oangle_zero_left (x : V) : o.oangle 0 x = 0 := by simp [oangle]
#align orientation.oangle_zero_left Orientation.oangle_zero_left
/-- If the second vector passed to `oangle` is 0, the result is 0. -/
@[simp]
theorem oangle_zero_right (x : V) : o.oangle x 0 = 0 := by simp [oangle]
#align orientation.oangle_zero_right Orientation.oangle_zero_right
/-- If the two vectors passed to `oangle` are the same, the result is 0. -/
@[simp]
theorem oangle_self (x : V) : o.oangle x x = 0 := by
rw [oangle, kahler_apply_self, ← ofReal_pow]
convert QuotientAddGroup.mk_zero (AddSubgroup.zmultiples (2 * π))
apply arg_ofReal_of_nonneg
positivity
#align orientation.oangle_self Orientation.oangle_self
/-- If the angle between two vectors is nonzero, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : x ≠ 0 := by
rintro rfl; simp at h
#align orientation.left_ne_zero_of_oangle_ne_zero Orientation.left_ne_zero_of_oangle_ne_zero
/-- If the angle between two vectors is nonzero, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : y ≠ 0 := by
rintro rfl; simp at h
#align orientation.right_ne_zero_of_oangle_ne_zero Orientation.right_ne_zero_of_oangle_ne_zero
/-- If the angle between two vectors is nonzero, the vectors are not equal. -/
theorem ne_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : x ≠ y := by
rintro rfl; simp at h
#align orientation.ne_of_oangle_ne_zero Orientation.ne_of_oangle_ne_zero
/-- If the angle between two vectors is `π`, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : x ≠ 0 :=
o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0)
#align orientation.left_ne_zero_of_oangle_eq_pi Orientation.left_ne_zero_of_oangle_eq_pi
/-- If the angle between two vectors is `π`, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : y ≠ 0 :=
o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0)
#align orientation.right_ne_zero_of_oangle_eq_pi Orientation.right_ne_zero_of_oangle_eq_pi
/-- If the angle between two vectors is `π`, the vectors are not equal. -/
theorem ne_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : x ≠ y :=
o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0)
#align orientation.ne_of_oangle_eq_pi Orientation.ne_of_oangle_eq_pi
/-- If the angle between two vectors is `π / 2`, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : x ≠ 0 :=
o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0)
#align orientation.left_ne_zero_of_oangle_eq_pi_div_two Orientation.left_ne_zero_of_oangle_eq_pi_div_two
/-- If the angle between two vectors is `π / 2`, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : y ≠ 0 :=
o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0)
#align orientation.right_ne_zero_of_oangle_eq_pi_div_two Orientation.right_ne_zero_of_oangle_eq_pi_div_two
/-- If the angle between two vectors is `π / 2`, the vectors are not equal. -/
theorem ne_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : x ≠ y :=
o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0)
#align orientation.ne_of_oangle_eq_pi_div_two Orientation.ne_of_oangle_eq_pi_div_two
/-- If the angle between two vectors is `-π / 2`, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) :
x ≠ 0 :=
o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0)
#align orientation.left_ne_zero_of_oangle_eq_neg_pi_div_two Orientation.left_ne_zero_of_oangle_eq_neg_pi_div_two
/-- If the angle between two vectors is `-π / 2`, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) :
y ≠ 0 :=
o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0)
#align orientation.right_ne_zero_of_oangle_eq_neg_pi_div_two Orientation.right_ne_zero_of_oangle_eq_neg_pi_div_two
/-- If the angle between two vectors is `-π / 2`, the vectors are not equal. -/
theorem ne_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : x ≠ y :=
o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0)
#align orientation.ne_of_oangle_eq_neg_pi_div_two Orientation.ne_of_oangle_eq_neg_pi_div_two
/-- If the sign of the angle between two vectors is nonzero, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : x ≠ 0 :=
o.left_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1
#align orientation.left_ne_zero_of_oangle_sign_ne_zero Orientation.left_ne_zero_of_oangle_sign_ne_zero
/-- If the sign of the angle between two vectors is nonzero, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : y ≠ 0 :=
o.right_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1
#align orientation.right_ne_zero_of_oangle_sign_ne_zero Orientation.right_ne_zero_of_oangle_sign_ne_zero
/-- If the sign of the angle between two vectors is nonzero, the vectors are not equal. -/
theorem ne_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : x ≠ y :=
o.ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1
#align orientation.ne_of_oangle_sign_ne_zero Orientation.ne_of_oangle_sign_ne_zero
/-- If the sign of the angle between two vectors is positive, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x ≠ 0 :=
o.left_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0)
#align orientation.left_ne_zero_of_oangle_sign_eq_one Orientation.left_ne_zero_of_oangle_sign_eq_one
/-- If the sign of the angle between two vectors is positive, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : y ≠ 0 :=
o.right_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0)
#align orientation.right_ne_zero_of_oangle_sign_eq_one Orientation.right_ne_zero_of_oangle_sign_eq_one
/-- If the sign of the angle between two vectors is positive, the vectors are not equal. -/
theorem ne_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x ≠ y :=
o.ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0)
#align orientation.ne_of_oangle_sign_eq_one Orientation.ne_of_oangle_sign_eq_one
/-- If the sign of the angle between two vectors is negative, the first vector is nonzero. -/
theorem left_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x ≠ 0 :=
o.left_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0)
#align orientation.left_ne_zero_of_oangle_sign_eq_neg_one Orientation.left_ne_zero_of_oangle_sign_eq_neg_one
/-- If the sign of the angle between two vectors is negative, the second vector is nonzero. -/
theorem right_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : y ≠ 0 :=
o.right_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0)
#align orientation.right_ne_zero_of_oangle_sign_eq_neg_one Orientation.right_ne_zero_of_oangle_sign_eq_neg_one
/-- If the sign of the angle between two vectors is negative, the vectors are not equal. -/
theorem ne_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x ≠ y :=
o.ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0)
#align orientation.ne_of_oangle_sign_eq_neg_one Orientation.ne_of_oangle_sign_eq_neg_one
/-- Swapping the two vectors passed to `oangle` negates the angle. -/
theorem oangle_rev (x y : V) : o.oangle y x = -o.oangle x y := by
simp only [oangle, o.kahler_swap y x, Complex.arg_conj_coe_angle]
#align orientation.oangle_rev Orientation.oangle_rev
/-- Adding the angles between two vectors in each order results in 0. -/
@[simp]
theorem oangle_add_oangle_rev (x y : V) : o.oangle x y + o.oangle y x = 0 := by
simp [o.oangle_rev y x]
#align orientation.oangle_add_oangle_rev Orientation.oangle_add_oangle_rev
/-- Negating the first vector passed to `oangle` adds `π` to the angle. -/
theorem oangle_neg_left {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
o.oangle (-x) y = o.oangle x y + π := by
simp only [oangle, map_neg]
convert Complex.arg_neg_coe_angle _
exact o.kahler_ne_zero hx hy
#align orientation.oangle_neg_left Orientation.oangle_neg_left
/-- Negating the second vector passed to `oangle` adds `π` to the angle. -/
theorem oangle_neg_right {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
o.oangle x (-y) = o.oangle x y + π := by
simp only [oangle, map_neg]
convert Complex.arg_neg_coe_angle _
exact o.kahler_ne_zero hx hy
#align orientation.oangle_neg_right Orientation.oangle_neg_right
/-- Negating the first vector passed to `oangle` does not change twice the angle. -/
@[simp]
theorem two_zsmul_oangle_neg_left (x y : V) :
(2 : ℤ) • o.oangle (-x) y = (2 : ℤ) • o.oangle x y := by
by_cases hx : x = 0
· simp [hx]
· by_cases hy : y = 0
· simp [hy]
· simp [o.oangle_neg_left hx hy]
#align orientation.two_zsmul_oangle_neg_left Orientation.two_zsmul_oangle_neg_left
/-- Negating the second vector passed to `oangle` does not change twice the angle. -/
@[simp]
theorem two_zsmul_oangle_neg_right (x y : V) :
(2 : ℤ) • o.oangle x (-y) = (2 : ℤ) • o.oangle x y := by
by_cases hx : x = 0
· simp [hx]
· by_cases hy : y = 0
· simp [hy]
· simp [o.oangle_neg_right hx hy]
#align orientation.two_zsmul_oangle_neg_right Orientation.two_zsmul_oangle_neg_right
/-- Negating both vectors passed to `oangle` does not change the angle. -/
@[simp]
theorem oangle_neg_neg (x y : V) : o.oangle (-x) (-y) = o.oangle x y := by simp [oangle]
#align orientation.oangle_neg_neg Orientation.oangle_neg_neg
/-- Negating the first vector produces the same angle as negating the second vector. -/
theorem oangle_neg_left_eq_neg_right (x y : V) : o.oangle (-x) y = o.oangle x (-y) := by
rw [← neg_neg y, oangle_neg_neg, neg_neg]
#align orientation.oangle_neg_left_eq_neg_right Orientation.oangle_neg_left_eq_neg_right
/-- The angle between the negation of a nonzero vector and that vector is `π`. -/
@[simp]
theorem oangle_neg_self_left {x : V} (hx : x ≠ 0) : o.oangle (-x) x = π := by
simp [oangle_neg_left, hx]
#align orientation.oangle_neg_self_left Orientation.oangle_neg_self_left
/-- The angle between a nonzero vector and its negation is `π`. -/
@[simp]
theorem oangle_neg_self_right {x : V} (hx : x ≠ 0) : o.oangle x (-x) = π := by
simp [oangle_neg_right, hx]
#align orientation.oangle_neg_self_right Orientation.oangle_neg_self_right
/-- Twice the angle between the negation of a vector and that vector is 0. -/
-- @[simp] -- Porting note (#10618): simp can prove this
theorem two_zsmul_oangle_neg_self_left (x : V) : (2 : ℤ) • o.oangle (-x) x = 0 := by
by_cases hx : x = 0 <;> simp [hx]
#align orientation.two_zsmul_oangle_neg_self_left Orientation.two_zsmul_oangle_neg_self_left
/-- Twice the angle between a vector and its negation is 0. -/
-- @[simp] -- Porting note (#10618): simp can prove this
theorem two_zsmul_oangle_neg_self_right (x : V) : (2 : ℤ) • o.oangle x (-x) = 0 := by
by_cases hx : x = 0 <;> simp [hx]
#align orientation.two_zsmul_oangle_neg_self_right Orientation.two_zsmul_oangle_neg_self_right
/-- Adding the angles between two vectors in each order, with the first vector in each angle
negated, results in 0. -/
@[simp]
theorem oangle_add_oangle_rev_neg_left (x y : V) : o.oangle (-x) y + o.oangle (-y) x = 0 := by
rw [oangle_neg_left_eq_neg_right, oangle_rev, add_left_neg]
#align orientation.oangle_add_oangle_rev_neg_left Orientation.oangle_add_oangle_rev_neg_left
/-- Adding the angles between two vectors in each order, with the second vector in each angle
negated, results in 0. -/
@[simp]
theorem oangle_add_oangle_rev_neg_right (x y : V) : o.oangle x (-y) + o.oangle y (-x) = 0 := by
rw [o.oangle_rev (-x), oangle_neg_left_eq_neg_right, add_neg_self]
#align orientation.oangle_add_oangle_rev_neg_right Orientation.oangle_add_oangle_rev_neg_right
/-- Multiplying the first vector passed to `oangle` by a positive real does not change the
angle. -/
@[simp]
theorem oangle_smul_left_of_pos (x y : V) {r : ℝ} (hr : 0 < r) :
o.oangle (r • x) y = o.oangle x y := by simp [oangle, Complex.arg_real_mul _ hr]
#align orientation.oangle_smul_left_of_pos Orientation.oangle_smul_left_of_pos
/-- Multiplying the second vector passed to `oangle` by a positive real does not change the
angle. -/
@[simp]
theorem oangle_smul_right_of_pos (x y : V) {r : ℝ} (hr : 0 < r) :
o.oangle x (r • y) = o.oangle x y := by simp [oangle, Complex.arg_real_mul _ hr]
#align orientation.oangle_smul_right_of_pos Orientation.oangle_smul_right_of_pos
/-- Multiplying the first vector passed to `oangle` by a negative real produces the same angle
as negating that vector. -/
@[simp]
theorem oangle_smul_left_of_neg (x y : V) {r : ℝ} (hr : r < 0) :
o.oangle (r • x) y = o.oangle (-x) y := by
rw [← neg_neg r, neg_smul, ← smul_neg, o.oangle_smul_left_of_pos _ _ (neg_pos_of_neg hr)]
#align orientation.oangle_smul_left_of_neg Orientation.oangle_smul_left_of_neg
/-- Multiplying the second vector passed to `oangle` by a negative real produces the same angle
as negating that vector. -/
@[simp]
theorem oangle_smul_right_of_neg (x y : V) {r : ℝ} (hr : r < 0) :
o.oangle x (r • y) = o.oangle x (-y) := by
rw [← neg_neg r, neg_smul, ← smul_neg, o.oangle_smul_right_of_pos _ _ (neg_pos_of_neg hr)]
#align orientation.oangle_smul_right_of_neg Orientation.oangle_smul_right_of_neg
/-- The angle between a nonnegative multiple of a vector and that vector is 0. -/
@[simp]
theorem oangle_smul_left_self_of_nonneg (x : V) {r : ℝ} (hr : 0 ≤ r) : o.oangle (r • x) x = 0 := by
rcases hr.lt_or_eq with (h | h)
· simp [h]
· simp [h.symm]
#align orientation.oangle_smul_left_self_of_nonneg Orientation.oangle_smul_left_self_of_nonneg
/-- The angle between a vector and a nonnegative multiple of that vector is 0. -/
@[simp]
theorem oangle_smul_right_self_of_nonneg (x : V) {r : ℝ} (hr : 0 ≤ r) : o.oangle x (r • x) = 0 := by
rcases hr.lt_or_eq with (h | h)
· simp [h]
· simp [h.symm]
#align orientation.oangle_smul_right_self_of_nonneg Orientation.oangle_smul_right_self_of_nonneg
/-- The angle between two nonnegative multiples of the same vector is 0. -/
@[simp]
theorem oangle_smul_smul_self_of_nonneg (x : V) {r₁ r₂ : ℝ} (hr₁ : 0 ≤ r₁) (hr₂ : 0 ≤ r₂) :
o.oangle (r₁ • x) (r₂ • x) = 0 := by
rcases hr₁.lt_or_eq with (h | h)
· simp [h, hr₂]
· simp [h.symm]
#align orientation.oangle_smul_smul_self_of_nonneg Orientation.oangle_smul_smul_self_of_nonneg
/-- Multiplying the first vector passed to `oangle` by a nonzero real does not change twice the
angle. -/
@[simp]
theorem two_zsmul_oangle_smul_left_of_ne_zero (x y : V) {r : ℝ} (hr : r ≠ 0) :
(2 : ℤ) • o.oangle (r • x) y = (2 : ℤ) • o.oangle x y := by
rcases hr.lt_or_lt with (h | h) <;> simp [h]
#align orientation.two_zsmul_oangle_smul_left_of_ne_zero Orientation.two_zsmul_oangle_smul_left_of_ne_zero
/-- Multiplying the second vector passed to `oangle` by a nonzero real does not change twice the
angle. -/
@[simp]
theorem two_zsmul_oangle_smul_right_of_ne_zero (x y : V) {r : ℝ} (hr : r ≠ 0) :
(2 : ℤ) • o.oangle x (r • y) = (2 : ℤ) • o.oangle x y := by
rcases hr.lt_or_lt with (h | h) <;> simp [h]
#align orientation.two_zsmul_oangle_smul_right_of_ne_zero Orientation.two_zsmul_oangle_smul_right_of_ne_zero
/-- Twice the angle between a multiple of a vector and that vector is 0. -/
@[simp]
theorem two_zsmul_oangle_smul_left_self (x : V) {r : ℝ} : (2 : ℤ) • o.oangle (r • x) x = 0 := by
rcases lt_or_le r 0 with (h | h) <;> simp [h]
#align orientation.two_zsmul_oangle_smul_left_self Orientation.two_zsmul_oangle_smul_left_self
/-- Twice the angle between a vector and a multiple of that vector is 0. -/
@[simp]
theorem two_zsmul_oangle_smul_right_self (x : V) {r : ℝ} : (2 : ℤ) • o.oangle x (r • x) = 0 := by
rcases lt_or_le r 0 with (h | h) <;> simp [h]
#align orientation.two_zsmul_oangle_smul_right_self Orientation.two_zsmul_oangle_smul_right_self
/-- Twice the angle between two multiples of a vector is 0. -/
@[simp]
theorem two_zsmul_oangle_smul_smul_self (x : V) {r₁ r₂ : ℝ} :
(2 : ℤ) • o.oangle (r₁ • x) (r₂ • x) = 0 := by by_cases h : r₁ = 0 <;> simp [h]
#align orientation.two_zsmul_oangle_smul_smul_self Orientation.two_zsmul_oangle_smul_smul_self
/-- If the spans of two vectors are equal, twice angles with those vectors on the left are
equal. -/
theorem two_zsmul_oangle_left_of_span_eq {x y : V} (z : V) (h : (ℝ ∙ x) = ℝ ∙ y) :
(2 : ℤ) • o.oangle x z = (2 : ℤ) • o.oangle y z := by
rw [Submodule.span_singleton_eq_span_singleton] at h
rcases h with ⟨r, rfl⟩
exact (o.two_zsmul_oangle_smul_left_of_ne_zero _ _ (Units.ne_zero _)).symm
#align orientation.two_zsmul_oangle_left_of_span_eq Orientation.two_zsmul_oangle_left_of_span_eq
/-- If the spans of two vectors are equal, twice angles with those vectors on the right are
equal. -/
theorem two_zsmul_oangle_right_of_span_eq (x : V) {y z : V} (h : (ℝ ∙ y) = ℝ ∙ z) :
(2 : ℤ) • o.oangle x y = (2 : ℤ) • o.oangle x z := by
rw [Submodule.span_singleton_eq_span_singleton] at h
rcases h with ⟨r, rfl⟩
exact (o.two_zsmul_oangle_smul_right_of_ne_zero _ _ (Units.ne_zero _)).symm
#align orientation.two_zsmul_oangle_right_of_span_eq Orientation.two_zsmul_oangle_right_of_span_eq
/-- If the spans of two pairs of vectors are equal, twice angles between those vectors are
equal. -/
theorem two_zsmul_oangle_of_span_eq_of_span_eq {w x y z : V} (hwx : (ℝ ∙ w) = ℝ ∙ x)
(hyz : (ℝ ∙ y) = ℝ ∙ z) : (2 : ℤ) • o.oangle w y = (2 : ℤ) • o.oangle x z := by
rw [o.two_zsmul_oangle_left_of_span_eq y hwx, o.two_zsmul_oangle_right_of_span_eq x hyz]
#align orientation.two_zsmul_oangle_of_span_eq_of_span_eq Orientation.two_zsmul_oangle_of_span_eq_of_span_eq
/-- The oriented angle between two vectors is zero if and only if the angle with the vectors
swapped is zero. -/
theorem oangle_eq_zero_iff_oangle_rev_eq_zero {x y : V} : o.oangle x y = 0 ↔ o.oangle y x = 0 := by
rw [oangle_rev, neg_eq_zero]
#align orientation.oangle_eq_zero_iff_oangle_rev_eq_zero Orientation.oangle_eq_zero_iff_oangle_rev_eq_zero
/-- The oriented angle between two vectors is zero if and only if they are on the same ray. -/
theorem oangle_eq_zero_iff_sameRay {x y : V} : o.oangle x y = 0 ↔ SameRay ℝ x y := by
rw [oangle, kahler_apply_apply, Complex.arg_coe_angle_eq_iff_eq_toReal, Real.Angle.toReal_zero,
Complex.arg_eq_zero_iff]
simpa using o.nonneg_inner_and_areaForm_eq_zero_iff_sameRay x y
#align orientation.oangle_eq_zero_iff_same_ray Orientation.oangle_eq_zero_iff_sameRay
/-- The oriented angle between two vectors is `π` if and only if the angle with the vectors
swapped is `π`. -/
theorem oangle_eq_pi_iff_oangle_rev_eq_pi {x y : V} : o.oangle x y = π ↔ o.oangle y x = π := by
rw [oangle_rev, neg_eq_iff_eq_neg, Real.Angle.neg_coe_pi]
#align orientation.oangle_eq_pi_iff_oangle_rev_eq_pi Orientation.oangle_eq_pi_iff_oangle_rev_eq_pi
/-- The oriented angle between two vectors is `π` if and only they are nonzero and the first is
on the same ray as the negation of the second. -/
theorem oangle_eq_pi_iff_sameRay_neg {x y : V} :
o.oangle x y = π ↔ x ≠ 0 ∧ y ≠ 0 ∧ SameRay ℝ x (-y) := by
rw [← o.oangle_eq_zero_iff_sameRay]
constructor
· intro h
by_cases hx : x = 0; · simp [hx, Real.Angle.pi_ne_zero.symm] at h
by_cases hy : y = 0; · simp [hy, Real.Angle.pi_ne_zero.symm] at h
refine ⟨hx, hy, ?_⟩
rw [o.oangle_neg_right hx hy, h, Real.Angle.coe_pi_add_coe_pi]
· rintro ⟨hx, hy, h⟩
rwa [o.oangle_neg_right hx hy, ← Real.Angle.sub_coe_pi_eq_add_coe_pi, sub_eq_zero] at h
#align orientation.oangle_eq_pi_iff_same_ray_neg Orientation.oangle_eq_pi_iff_sameRay_neg
/-- The oriented angle between two vectors is zero or `π` if and only if those two vectors are
not linearly independent. -/
theorem oangle_eq_zero_or_eq_pi_iff_not_linearIndependent {x y : V} :
o.oangle x y = 0 ∨ o.oangle x y = π ↔ ¬LinearIndependent ℝ ![x, y] := by
rw [oangle_eq_zero_iff_sameRay, oangle_eq_pi_iff_sameRay_neg,
sameRay_or_ne_zero_and_sameRay_neg_iff_not_linearIndependent]
#align orientation.oangle_eq_zero_or_eq_pi_iff_not_linear_independent Orientation.oangle_eq_zero_or_eq_pi_iff_not_linearIndependent
/-- The oriented angle between two vectors is zero or `π` if and only if the first vector is zero
or the second is a multiple of the first. -/
theorem oangle_eq_zero_or_eq_pi_iff_right_eq_smul {x y : V} :
o.oangle x y = 0 ∨ o.oangle x y = π ↔ x = 0 ∨ ∃ r : ℝ, y = r • x := by
rw [oangle_eq_zero_iff_sameRay, oangle_eq_pi_iff_sameRay_neg]
refine ⟨fun h => ?_, fun h => ?_⟩
· rcases h with (h | ⟨-, -, h⟩)
· by_cases hx : x = 0; · simp [hx]
obtain ⟨r, -, rfl⟩ := h.exists_nonneg_left hx
exact Or.inr ⟨r, rfl⟩
· by_cases hx : x = 0; · simp [hx]
obtain ⟨r, -, hy⟩ := h.exists_nonneg_left hx
refine Or.inr ⟨-r, ?_⟩
simp [hy]
· rcases h with (rfl | ⟨r, rfl⟩); · simp
by_cases hx : x = 0; · simp [hx]
rcases lt_trichotomy r 0 with (hr | hr | hr)
· rw [← neg_smul]
exact Or.inr ⟨hx, smul_ne_zero hr.ne hx,
SameRay.sameRay_pos_smul_right x (Left.neg_pos_iff.2 hr)⟩
· simp [hr]
· exact Or.inl (SameRay.sameRay_pos_smul_right x hr)
#align orientation.oangle_eq_zero_or_eq_pi_iff_right_eq_smul Orientation.oangle_eq_zero_or_eq_pi_iff_right_eq_smul
/-- The oriented angle between two vectors is not zero or `π` if and only if those two vectors
are linearly independent. -/
theorem oangle_ne_zero_and_ne_pi_iff_linearIndependent {x y : V} :
o.oangle x y ≠ 0 ∧ o.oangle x y ≠ π ↔ LinearIndependent ℝ ![x, y] := by
rw [← not_or, ← not_iff_not, Classical.not_not,
oangle_eq_zero_or_eq_pi_iff_not_linearIndependent]
#align orientation.oangle_ne_zero_and_ne_pi_iff_linear_independent Orientation.oangle_ne_zero_and_ne_pi_iff_linearIndependent
/-- Two vectors are equal if and only if they have equal norms and zero angle between them. -/
theorem eq_iff_norm_eq_and_oangle_eq_zero (x y : V) : x = y ↔ ‖x‖ = ‖y‖ ∧ o.oangle x y = 0 := by
rw [oangle_eq_zero_iff_sameRay]
constructor
· rintro rfl
simp; rfl
· rcases eq_or_ne y 0 with (rfl | hy)
· simp
rintro ⟨h₁, h₂⟩
obtain ⟨r, hr, rfl⟩ := h₂.exists_nonneg_right hy
have : ‖y‖ ≠ 0 := by simpa using hy
obtain rfl : r = 1 := by
apply mul_right_cancel₀ this
simpa [norm_smul, _root_.abs_of_nonneg hr] using h₁
simp
#align orientation.eq_iff_norm_eq_and_oangle_eq_zero Orientation.eq_iff_norm_eq_and_oangle_eq_zero
/-- Two vectors with equal norms are equal if and only if they have zero angle between them. -/
theorem eq_iff_oangle_eq_zero_of_norm_eq {x y : V} (h : ‖x‖ = ‖y‖) : x = y ↔ o.oangle x y = 0 :=
⟨fun he => ((o.eq_iff_norm_eq_and_oangle_eq_zero x y).1 he).2, fun ha =>
(o.eq_iff_norm_eq_and_oangle_eq_zero x y).2 ⟨h, ha⟩⟩
#align orientation.eq_iff_oangle_eq_zero_of_norm_eq Orientation.eq_iff_oangle_eq_zero_of_norm_eq
/-- Two vectors with zero angle between them are equal if and only if they have equal norms. -/
theorem eq_iff_norm_eq_of_oangle_eq_zero {x y : V} (h : o.oangle x y = 0) : x = y ↔ ‖x‖ = ‖y‖ :=
⟨fun he => ((o.eq_iff_norm_eq_and_oangle_eq_zero x y).1 he).1, fun hn =>
(o.eq_iff_norm_eq_and_oangle_eq_zero x y).2 ⟨hn, h⟩⟩
#align orientation.eq_iff_norm_eq_of_oangle_eq_zero Orientation.eq_iff_norm_eq_of_oangle_eq_zero
/-- Given three nonzero vectors, the angle between the first and the second plus the angle
between the second and the third equals the angle between the first and the third. -/
@[simp]
theorem oangle_add {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) :
o.oangle x y + o.oangle y z = o.oangle x z := by
simp_rw [oangle]
rw [← Complex.arg_mul_coe_angle, o.kahler_mul y x z]
· congr 1
convert Complex.arg_real_mul _ (_ : 0 < ‖y‖ ^ 2) using 2
· norm_cast
· have : 0 < ‖y‖ := by simpa using hy
positivity
· exact o.kahler_ne_zero hx hy
· exact o.kahler_ne_zero hy hz
#align orientation.oangle_add Orientation.oangle_add
/-- Given three nonzero vectors, the angle between the second and the third plus the angle
between the first and the second equals the angle between the first and the third. -/
@[simp]
theorem oangle_add_swap {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) :
o.oangle y z + o.oangle x y = o.oangle x z := by rw [add_comm, o.oangle_add hx hy hz]
#align orientation.oangle_add_swap Orientation.oangle_add_swap
/-- Given three nonzero vectors, the angle between the first and the third minus the angle
between the first and the second equals the angle between the second and the third. -/
@[simp]
theorem oangle_sub_left {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) :
o.oangle x z - o.oangle x y = o.oangle y z := by
rw [sub_eq_iff_eq_add, o.oangle_add_swap hx hy hz]
#align orientation.oangle_sub_left Orientation.oangle_sub_left
/-- Given three nonzero vectors, the angle between the first and the third minus the angle
between the second and the third equals the angle between the first and the second. -/
@[simp]
theorem oangle_sub_right {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) :
o.oangle x z - o.oangle y z = o.oangle x y := by rw [sub_eq_iff_eq_add, o.oangle_add hx hy hz]
#align orientation.oangle_sub_right Orientation.oangle_sub_right
/-- Given three nonzero vectors, adding the angles between them in cyclic order results in 0. -/
@[simp]
theorem oangle_add_cyc3 {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) :
o.oangle x y + o.oangle y z + o.oangle z x = 0 := by simp [hx, hy, hz]
#align orientation.oangle_add_cyc3 Orientation.oangle_add_cyc3
/-- Given three nonzero vectors, adding the angles between them in cyclic order, with the first
vector in each angle negated, results in π. If the vectors add to 0, this is a version of the
sum of the angles of a triangle. -/
@[simp]
theorem oangle_add_cyc3_neg_left {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) :
o.oangle (-x) y + o.oangle (-y) z + o.oangle (-z) x = π := by
rw [o.oangle_neg_left hx hy, o.oangle_neg_left hy hz, o.oangle_neg_left hz hx,
show o.oangle x y + π + (o.oangle y z + π) + (o.oangle z x + π) =
o.oangle x y + o.oangle y z + o.oangle z x + (π + π + π : Real.Angle) by abel,
o.oangle_add_cyc3 hx hy hz, Real.Angle.coe_pi_add_coe_pi, zero_add, zero_add]
#align orientation.oangle_add_cyc3_neg_left Orientation.oangle_add_cyc3_neg_left
/-- Given three nonzero vectors, adding the angles between them in cyclic order, with the second
vector in each angle negated, results in π. If the vectors add to 0, this is a version of the
sum of the angles of a triangle. -/
@[simp]
theorem oangle_add_cyc3_neg_right {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) :
o.oangle x (-y) + o.oangle y (-z) + o.oangle z (-x) = π := by
simp_rw [← oangle_neg_left_eq_neg_right, o.oangle_add_cyc3_neg_left hx hy hz]
#align orientation.oangle_add_cyc3_neg_right Orientation.oangle_add_cyc3_neg_right
/-- Pons asinorum, oriented vector angle form. -/
theorem oangle_sub_eq_oangle_sub_rev_of_norm_eq {x y : V} (h : ‖x‖ = ‖y‖) :
o.oangle x (x - y) = o.oangle (y - x) y := by simp [oangle, h]
#align orientation.oangle_sub_eq_oangle_sub_rev_of_norm_eq Orientation.oangle_sub_eq_oangle_sub_rev_of_norm_eq
/-- The angle at the apex of an isosceles triangle is `π` minus twice a base angle, oriented
vector angle form. -/
theorem oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq {x y : V} (hn : x ≠ y) (h : ‖x‖ = ‖y‖) :
o.oangle y x = π - (2 : ℤ) • o.oangle (y - x) y := by
rw [two_zsmul]
nth_rw 1 [← o.oangle_sub_eq_oangle_sub_rev_of_norm_eq h]
rw [eq_sub_iff_add_eq, ← oangle_neg_neg, ← add_assoc]
have hy : y ≠ 0 := by
rintro rfl
rw [norm_zero, norm_eq_zero] at h
exact hn h
have hx : x ≠ 0 := norm_ne_zero_iff.1 (h.symm ▸ norm_ne_zero_iff.2 hy)
convert o.oangle_add_cyc3_neg_right (neg_ne_zero.2 hy) hx (sub_ne_zero_of_ne hn.symm) using 1
simp
#align orientation.oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq Orientation.oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq
/-- The angle between two vectors, with respect to an orientation given by `Orientation.map`
with a linear isometric equivalence, equals the angle between those two vectors, transformed by
the inverse of that equivalence, with respect to the original orientation. -/
@[simp]
theorem oangle_map (x y : V') (f : V ≃ₗᵢ[ℝ] V') :
(Orientation.map (Fin 2) f.toLinearEquiv o).oangle x y = o.oangle (f.symm x) (f.symm y) := by
simp [oangle, o.kahler_map]
#align orientation.oangle_map Orientation.oangle_map
@[simp]
protected theorem _root_.Complex.oangle (w z : ℂ) :
Complex.orientation.oangle w z = Complex.arg (conj w * z) := by simp [oangle]
#align complex.oangle Complex.oangle
/-- The oriented angle on an oriented real inner product space of dimension 2 can be evaluated in
terms of a complex-number representation of the space. -/
theorem oangle_map_complex (f : V ≃ₗᵢ[ℝ] ℂ)
(hf : Orientation.map (Fin 2) f.toLinearEquiv o = Complex.orientation) (x y : V) :
o.oangle x y = Complex.arg (conj (f x) * f y) := by
rw [← Complex.oangle, ← hf, o.oangle_map]
iterate 2 rw [LinearIsometryEquiv.symm_apply_apply]
#align orientation.oangle_map_complex Orientation.oangle_map_complex
/-- Negating the orientation negates the value of `oangle`. -/
theorem oangle_neg_orientation_eq_neg (x y : V) : (-o).oangle x y = -o.oangle x y := by
simp [oangle]
#align orientation.oangle_neg_orientation_eq_neg Orientation.oangle_neg_orientation_eq_neg
/-- The inner product of two vectors is the product of the norms and the cosine of the oriented
angle between the vectors. -/
theorem inner_eq_norm_mul_norm_mul_cos_oangle (x y : V) :
⟪x, y⟫ = ‖x‖ * ‖y‖ * Real.Angle.cos (o.oangle x y) := by
by_cases hx : x = 0; · simp [hx]
by_cases hy : y = 0; · simp [hy]
have : ‖x‖ ≠ 0 := by simpa using hx
have : ‖y‖ ≠ 0 := by simpa using hy
rw [oangle, Real.Angle.cos_coe, Complex.cos_arg, o.abs_kahler]
· simp only [kahler_apply_apply, real_smul, add_re, ofReal_re, mul_re, I_re, ofReal_im]
field_simp
· exact o.kahler_ne_zero hx hy
#align orientation.inner_eq_norm_mul_norm_mul_cos_oangle Orientation.inner_eq_norm_mul_norm_mul_cos_oangle
/-- The cosine of the oriented angle between two nonzero vectors is the inner product divided by
the product of the norms. -/
theorem cos_oangle_eq_inner_div_norm_mul_norm {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
Real.Angle.cos (o.oangle x y) = ⟪x, y⟫ / (‖x‖ * ‖y‖) := by
rw [o.inner_eq_norm_mul_norm_mul_cos_oangle]
field_simp [norm_ne_zero_iff.2 hx, norm_ne_zero_iff.2 hy]
#align orientation.cos_oangle_eq_inner_div_norm_mul_norm Orientation.cos_oangle_eq_inner_div_norm_mul_norm
/-- The cosine of the oriented angle between two nonzero vectors equals that of the unoriented
angle. -/
theorem cos_oangle_eq_cos_angle {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
Real.Angle.cos (o.oangle x y) = Real.cos (InnerProductGeometry.angle x y) := by
rw [o.cos_oangle_eq_inner_div_norm_mul_norm hx hy, InnerProductGeometry.cos_angle]
#align orientation.cos_oangle_eq_cos_angle Orientation.cos_oangle_eq_cos_angle
/-- The oriented angle between two nonzero vectors is plus or minus the unoriented angle. -/
theorem oangle_eq_angle_or_eq_neg_angle {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
o.oangle x y = InnerProductGeometry.angle x y ∨
o.oangle x y = -InnerProductGeometry.angle x y :=
Real.Angle.cos_eq_real_cos_iff_eq_or_eq_neg.1 <| o.cos_oangle_eq_cos_angle hx hy
#align orientation.oangle_eq_angle_or_eq_neg_angle Orientation.oangle_eq_angle_or_eq_neg_angle
/-- The unoriented angle between two nonzero vectors is the absolute value of the oriented angle,
converted to a real. -/
theorem angle_eq_abs_oangle_toReal {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
InnerProductGeometry.angle x y = |(o.oangle x y).toReal| := by
have h0 := InnerProductGeometry.angle_nonneg x y
have hpi := InnerProductGeometry.angle_le_pi x y
rcases o.oangle_eq_angle_or_eq_neg_angle hx hy with (h | h)
· rw [h, eq_comm, Real.Angle.abs_toReal_coe_eq_self_iff]
exact ⟨h0, hpi⟩
· rw [h, eq_comm, Real.Angle.abs_toReal_neg_coe_eq_self_iff]
exact ⟨h0, hpi⟩
#align orientation.angle_eq_abs_oangle_to_real Orientation.angle_eq_abs_oangle_toReal
/-- If the sign of the oriented angle between two vectors is zero, either one of the vectors is
zero or the unoriented angle is 0 or π. -/
theorem eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero {x y : V}
(h : (o.oangle x y).sign = 0) :
x = 0 ∨ y = 0 ∨ InnerProductGeometry.angle x y = 0 ∨ InnerProductGeometry.angle x y = π := by
by_cases hx : x = 0; · simp [hx]
by_cases hy : y = 0; · simp [hy]
rw [o.angle_eq_abs_oangle_toReal hx hy]
rw [Real.Angle.sign_eq_zero_iff] at h
rcases h with (h | h) <;> simp [h, Real.pi_pos.le]
#align orientation.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero Orientation.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero
/-- If two unoriented angles are equal, and the signs of the corresponding oriented angles are
equal, then the oriented angles are equal (even in degenerate cases). -/
theorem oangle_eq_of_angle_eq_of_sign_eq {w x y z : V}
(h : InnerProductGeometry.angle w x = InnerProductGeometry.angle y z)
(hs : (o.oangle w x).sign = (o.oangle y z).sign) : o.oangle w x = o.oangle y z := by
by_cases h0 : (w = 0 ∨ x = 0) ∨ y = 0 ∨ z = 0
· have hs' : (o.oangle w x).sign = 0 ∧ (o.oangle y z).sign = 0 := by
rcases h0 with ((rfl | rfl) | rfl | rfl)
· simpa using hs.symm
· simpa using hs.symm
· simpa using hs
· simpa using hs
rcases hs' with ⟨hswx, hsyz⟩
have h' : InnerProductGeometry.angle w x = π / 2 ∧ InnerProductGeometry.angle y z = π / 2 := by
rcases h0 with ((rfl | rfl) | rfl | rfl)
· simpa using h.symm
· simpa using h.symm
· simpa using h
· simpa using h
rcases h' with ⟨hwx, hyz⟩
have hpi : π / 2 ≠ π := by
intro hpi
rw [div_eq_iff, eq_comm, ← sub_eq_zero, mul_two, add_sub_cancel_right] at hpi
· exact Real.pi_pos.ne.symm hpi
· exact two_ne_zero
have h0wx : w = 0 ∨ x = 0 := by
have h0' := o.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero hswx
simpa [hwx, Real.pi_pos.ne.symm, hpi] using h0'
have h0yz : y = 0 ∨ z = 0 := by
have h0' := o.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero hsyz
simpa [hyz, Real.pi_pos.ne.symm, hpi] using h0'
rcases h0wx with (h0wx | h0wx) <;> rcases h0yz with (h0yz | h0yz) <;> simp [h0wx, h0yz]
· push_neg at h0
rw [Real.Angle.eq_iff_abs_toReal_eq_of_sign_eq hs]
rwa [o.angle_eq_abs_oangle_toReal h0.1.1 h0.1.2,
o.angle_eq_abs_oangle_toReal h0.2.1 h0.2.2] at h
#align orientation.oangle_eq_of_angle_eq_of_sign_eq Orientation.oangle_eq_of_angle_eq_of_sign_eq
/-- If the signs of two oriented angles between nonzero vectors are equal, the oriented angles are
equal if and only if the unoriented angles are equal. -/
theorem angle_eq_iff_oangle_eq_of_sign_eq {w x y z : V} (hw : w ≠ 0) (hx : x ≠ 0) (hy : y ≠ 0)
(hz : z ≠ 0) (hs : (o.oangle w x).sign = (o.oangle y z).sign) :
InnerProductGeometry.angle w x = InnerProductGeometry.angle y z ↔
o.oangle w x = o.oangle y z := by
refine ⟨fun h => o.oangle_eq_of_angle_eq_of_sign_eq h hs, fun h => ?_⟩
rw [o.angle_eq_abs_oangle_toReal hw hx, o.angle_eq_abs_oangle_toReal hy hz, h]
#align orientation.angle_eq_iff_oangle_eq_of_sign_eq Orientation.angle_eq_iff_oangle_eq_of_sign_eq
/-- The oriented angle between two vectors equals the unoriented angle if the sign is positive. -/
theorem oangle_eq_angle_of_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) :
o.oangle x y = InnerProductGeometry.angle x y := by
by_cases hx : x = 0; · exfalso; simp [hx] at h
by_cases hy : y = 0; · exfalso; simp [hy] at h
refine (o.oangle_eq_angle_or_eq_neg_angle hx hy).resolve_right ?_
intro hxy
rw [hxy, Real.Angle.sign_neg, neg_eq_iff_eq_neg, ← SignType.neg_iff, ← not_le] at h
exact h (Real.Angle.sign_coe_nonneg_of_nonneg_of_le_pi (InnerProductGeometry.angle_nonneg _ _)
(InnerProductGeometry.angle_le_pi _ _))
#align orientation.oangle_eq_angle_of_sign_eq_one Orientation.oangle_eq_angle_of_sign_eq_one
/-- The oriented angle between two vectors equals minus the unoriented angle if the sign is
negative. -/
theorem oangle_eq_neg_angle_of_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) :
o.oangle x y = -InnerProductGeometry.angle x y := by
by_cases hx : x = 0; · exfalso; simp [hx] at h
by_cases hy : y = 0; · exfalso; simp [hy] at h
refine (o.oangle_eq_angle_or_eq_neg_angle hx hy).resolve_left ?_
intro hxy
rw [hxy, ← SignType.neg_iff, ← not_le] at h
exact h (Real.Angle.sign_coe_nonneg_of_nonneg_of_le_pi (InnerProductGeometry.angle_nonneg _ _)
(InnerProductGeometry.angle_le_pi _ _))
#align orientation.oangle_eq_neg_angle_of_sign_eq_neg_one Orientation.oangle_eq_neg_angle_of_sign_eq_neg_one
/-- The oriented angle between two nonzero vectors is zero if and only if the unoriented angle
is zero. -/
theorem oangle_eq_zero_iff_angle_eq_zero {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
o.oangle x y = 0 ↔ InnerProductGeometry.angle x y = 0 := by
refine ⟨fun h => ?_, fun h => ?_⟩
· simpa [o.angle_eq_abs_oangle_toReal hx hy]
· have ha := o.oangle_eq_angle_or_eq_neg_angle hx hy
rw [h] at ha
simpa using ha
#align orientation.oangle_eq_zero_iff_angle_eq_zero Orientation.oangle_eq_zero_iff_angle_eq_zero
/-- The oriented angle between two vectors is `π` if and only if the unoriented angle is `π`. -/
theorem oangle_eq_pi_iff_angle_eq_pi {x y : V} :
o.oangle x y = π ↔ InnerProductGeometry.angle x y = π := by
by_cases hx : x = 0
· simp [hx, Real.Angle.pi_ne_zero.symm, div_eq_mul_inv, mul_right_eq_self₀, not_or,
Real.pi_ne_zero]
by_cases hy : y = 0
· simp [hy, Real.Angle.pi_ne_zero.symm, div_eq_mul_inv, mul_right_eq_self₀, not_or,
Real.pi_ne_zero]
refine ⟨fun h => ?_, fun h => ?_⟩
· rw [o.angle_eq_abs_oangle_toReal hx hy, h]
simp [Real.pi_pos.le]
· have ha := o.oangle_eq_angle_or_eq_neg_angle hx hy
rw [h] at ha
simpa using ha
#align orientation.oangle_eq_pi_iff_angle_eq_pi Orientation.oangle_eq_pi_iff_angle_eq_pi
/-- One of two vectors is zero or the oriented angle between them is plus or minus `π / 2` if
and only if the inner product of those vectors is zero. -/
theorem eq_zero_or_oangle_eq_iff_inner_eq_zero {x y : V} :
x = 0 ∨ y = 0 ∨ o.oangle x y = (π / 2 : ℝ) ∨ o.oangle x y = (-π / 2 : ℝ) ↔ ⟪x, y⟫ = 0 := by
by_cases hx : x = 0; · simp [hx]
by_cases hy : y = 0; · simp [hy]
rw [InnerProductGeometry.inner_eq_zero_iff_angle_eq_pi_div_two, or_iff_right hx, or_iff_right hy]
refine ⟨fun h => ?_, fun h => ?_⟩
· rwa [o.angle_eq_abs_oangle_toReal hx hy, Real.Angle.abs_toReal_eq_pi_div_two_iff]
· convert o.oangle_eq_angle_or_eq_neg_angle hx hy using 2 <;> rw [h]
simp only [neg_div, Real.Angle.coe_neg]
#align orientation.eq_zero_or_oangle_eq_iff_inner_eq_zero Orientation.eq_zero_or_oangle_eq_iff_inner_eq_zero
/-- If the oriented angle between two vectors is `π / 2`, the inner product of those vectors
is zero. -/
theorem inner_eq_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) :
⟪x, y⟫ = 0 :=
o.eq_zero_or_oangle_eq_iff_inner_eq_zero.1 <| Or.inr <| Or.inr <| Or.inl h
#align orientation.inner_eq_zero_of_oangle_eq_pi_div_two Orientation.inner_eq_zero_of_oangle_eq_pi_div_two
/-- If the oriented angle between two vectors is `π / 2`, the inner product of those vectors
(reversed) is zero. -/
theorem inner_rev_eq_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) :
⟪y, x⟫ = 0 := by rw [real_inner_comm, o.inner_eq_zero_of_oangle_eq_pi_div_two h]
#align orientation.inner_rev_eq_zero_of_oangle_eq_pi_div_two Orientation.inner_rev_eq_zero_of_oangle_eq_pi_div_two
/-- If the oriented angle between two vectors is `-π / 2`, the inner product of those vectors
is zero. -/
theorem inner_eq_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) :
⟪x, y⟫ = 0 :=
o.eq_zero_or_oangle_eq_iff_inner_eq_zero.1 <| Or.inr <| Or.inr <| Or.inr h
#align orientation.inner_eq_zero_of_oangle_eq_neg_pi_div_two Orientation.inner_eq_zero_of_oangle_eq_neg_pi_div_two
/-- If the oriented angle between two vectors is `-π / 2`, the inner product of those vectors
(reversed) is zero. -/
theorem inner_rev_eq_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) :
⟪y, x⟫ = 0 := by rw [real_inner_comm, o.inner_eq_zero_of_oangle_eq_neg_pi_div_two h]
#align orientation.inner_rev_eq_zero_of_oangle_eq_neg_pi_div_two Orientation.inner_rev_eq_zero_of_oangle_eq_neg_pi_div_two
/-- Negating the first vector passed to `oangle` negates the sign of the angle. -/
@[simp]
theorem oangle_sign_neg_left (x y : V) : (o.oangle (-x) y).sign = -(o.oangle x y).sign := by
by_cases hx : x = 0; · simp [hx]
by_cases hy : y = 0; · simp [hy]
rw [o.oangle_neg_left hx hy, Real.Angle.sign_add_pi]
#align orientation.oangle_sign_neg_left Orientation.oangle_sign_neg_left
/-- Negating the second vector passed to `oangle` negates the sign of the angle. -/
@[simp]
theorem oangle_sign_neg_right (x y : V) : (o.oangle x (-y)).sign = -(o.oangle x y).sign := by
by_cases hx : x = 0; · simp [hx]
by_cases hy : y = 0; · simp [hy]
rw [o.oangle_neg_right hx hy, Real.Angle.sign_add_pi]
#align orientation.oangle_sign_neg_right Orientation.oangle_sign_neg_right
/-- Multiplying the first vector passed to `oangle` by a real multiplies the sign of the angle by
the sign of the real. -/
@[simp]
theorem oangle_sign_smul_left (x y : V) (r : ℝ) :
(o.oangle (r • x) y).sign = SignType.sign r * (o.oangle x y).sign := by
rcases lt_trichotomy r 0 with (h | h | h) <;> simp [h]
#align orientation.oangle_sign_smul_left Orientation.oangle_sign_smul_left
/-- Multiplying the second vector passed to `oangle` by a real multiplies the sign of the angle by
the sign of the real. -/
@[simp]
theorem oangle_sign_smul_right (x y : V) (r : ℝ) :
(o.oangle x (r • y)).sign = SignType.sign r * (o.oangle x y).sign := by
rcases lt_trichotomy r 0 with (h | h | h) <;> simp [h]
#align orientation.oangle_sign_smul_right Orientation.oangle_sign_smul_right
/-- Auxiliary lemma for the proof of `oangle_sign_smul_add_right`; not intended to be used
outside of that proof. -/
theorem oangle_smul_add_right_eq_zero_or_eq_pi_iff {x y : V} (r : ℝ) :
o.oangle x (r • x + y) = 0 ∨ o.oangle x (r • x + y) = π ↔
o.oangle x y = 0 ∨ o.oangle x y = π := by
simp_rw [oangle_eq_zero_or_eq_pi_iff_not_linearIndependent, Fintype.not_linearIndependent_iff]
-- Porting note: at this point all occurences of the bound variable `i` are of type
-- `Fin (Nat.succ (Nat.succ 0))`, but `Fin.sum_univ_two` and `Fin.exists_fin_two` expect it to be
-- `Fin 2` instead. Hence all the `conv`s.
-- Was `simp_rw [Fin.sum_univ_two, Fin.exists_fin_two]`
conv_lhs => enter [1, g, 1, 1, 2, i]; tactic => change Fin 2 at i
conv_lhs => enter [1, g]; rw [Fin.sum_univ_two]
conv_rhs => enter [1, g, 1, 1, 2, i]; tactic => change Fin 2 at i
conv_rhs => enter [1, g]; rw [Fin.sum_univ_two]
conv_lhs => enter [1, g, 2, 1, i]; tactic => change Fin 2 at i
conv_lhs => enter [1, g]; rw [Fin.exists_fin_two]
conv_rhs => enter [1, g, 2, 1, i]; tactic => change Fin 2 at i
conv_rhs => enter [1, g]; rw [Fin.exists_fin_two]
refine ⟨fun h => ?_, fun h => ?_⟩
· rcases h with ⟨m, h, hm⟩
change m 0 • x + m 1 • (r • x + y) = 0 at h
refine ⟨![m 0 + m 1 * r, m 1], ?_⟩
change (m 0 + m 1 * r) • x + m 1 • y = 0 ∧ (m 0 + m 1 * r ≠ 0 ∨ m 1 ≠ 0)
rw [smul_add, smul_smul, ← add_assoc, ← add_smul] at h
refine ⟨h, not_and_or.1 fun h0 => ?_⟩
obtain ⟨h0, h1⟩ := h0
rw [h1] at h0 hm
rw [zero_mul, add_zero] at h0
simp [h0] at hm
· rcases h with ⟨m, h, hm⟩
change m 0 • x + m 1 • y = 0 at h
refine ⟨![m 0 - m 1 * r, m 1], ?_⟩
change (m 0 - m 1 * r) • x + m 1 • (r • x + y) = 0 ∧ (m 0 - m 1 * r ≠ 0 ∨ m 1 ≠ 0)
rw [sub_smul, smul_add, smul_smul, ← add_assoc, sub_add_cancel]
refine ⟨h, not_and_or.1 fun h0 => ?_⟩
obtain ⟨h0, h1⟩ := h0
rw [h1] at h0 hm
rw [zero_mul, sub_zero] at h0
simp [h0] at hm
#align orientation.oangle_smul_add_right_eq_zero_or_eq_pi_iff Orientation.oangle_smul_add_right_eq_zero_or_eq_pi_iff
/-- Adding a multiple of the first vector passed to `oangle` to the second vector does not change
the sign of the angle. -/
@[simp]
theorem oangle_sign_smul_add_right (x y : V) (r : ℝ) :
(o.oangle x (r • x + y)).sign = (o.oangle x y).sign := by
by_cases h : o.oangle x y = 0 ∨ o.oangle x y = π
· rwa [Real.Angle.sign_eq_zero_iff.2 h, Real.Angle.sign_eq_zero_iff,
oangle_smul_add_right_eq_zero_or_eq_pi_iff]
have h' : ∀ r' : ℝ, o.oangle x (r' • x + y) ≠ 0 ∧ o.oangle x (r' • x + y) ≠ π := by
intro r'
rwa [← o.oangle_smul_add_right_eq_zero_or_eq_pi_iff r', not_or] at h
let s : Set (V × V) := (fun r' : ℝ => (x, r' • x + y)) '' Set.univ
have hc : IsConnected s := isConnected_univ.image _ (continuous_const.prod_mk
((continuous_id.smul continuous_const).add continuous_const)).continuousOn
have hf : ContinuousOn (fun z : V × V => o.oangle z.1 z.2) s := by
refine ContinuousAt.continuousOn fun z hz => o.continuousAt_oangle ?_ ?_
all_goals
simp_rw [s, Set.mem_image] at hz
obtain ⟨r', -, rfl⟩ := hz
simp only [Prod.fst, Prod.snd]
intro hz
· simpa [hz] using (h' 0).1
· simpa [hz] using (h' r').1
have hs : ∀ z : V × V, z ∈ s → o.oangle z.1 z.2 ≠ 0 ∧ o.oangle z.1 z.2 ≠ π := by
intro z hz
simp_rw [s, Set.mem_image] at hz
obtain ⟨r', -, rfl⟩ := hz
exact h' r'
have hx : (x, y) ∈ s := by
convert Set.mem_image_of_mem (fun r' : ℝ => (x, r' • x + y)) (Set.mem_univ 0)
simp
have hy : (x, r • x + y) ∈ s := Set.mem_image_of_mem _ (Set.mem_univ _)
convert Real.Angle.sign_eq_of_continuousOn hc hf hs hx hy
#align orientation.oangle_sign_smul_add_right Orientation.oangle_sign_smul_add_right
/-- Adding a multiple of the second vector passed to `oangle` to the first vector does not change
the sign of the angle. -/
@[simp]
theorem oangle_sign_add_smul_left (x y : V) (r : ℝ) :
(o.oangle (x + r • y) y).sign = (o.oangle x y).sign := by
simp_rw [o.oangle_rev y, Real.Angle.sign_neg, add_comm x, oangle_sign_smul_add_right]
#align orientation.oangle_sign_add_smul_left Orientation.oangle_sign_add_smul_left
/-- Subtracting a multiple of the first vector passed to `oangle` from the second vector does
not change the sign of the angle. -/
@[simp]
theorem oangle_sign_sub_smul_right (x y : V) (r : ℝ) :
(o.oangle x (y - r • x)).sign = (o.oangle x y).sign := by
rw [sub_eq_add_neg, ← neg_smul, add_comm, oangle_sign_smul_add_right]
#align orientation.oangle_sign_sub_smul_right Orientation.oangle_sign_sub_smul_right
/-- Subtracting a multiple of the second vector passed to `oangle` from the first vector does
not change the sign of the angle. -/
@[simp]
theorem oangle_sign_sub_smul_left (x y : V) (r : ℝ) :
(o.oangle (x - r • y) y).sign = (o.oangle x y).sign := by
rw [sub_eq_add_neg, ← neg_smul, oangle_sign_add_smul_left]
#align orientation.oangle_sign_sub_smul_left Orientation.oangle_sign_sub_smul_left
/-- Adding the first vector passed to `oangle` to the second vector does not change the sign of
the angle. -/
@[simp]
theorem oangle_sign_add_right (x y : V) : (o.oangle x (x + y)).sign = (o.oangle x y).sign := by
rw [← o.oangle_sign_smul_add_right x y 1, one_smul]
#align orientation.oangle_sign_add_right Orientation.oangle_sign_add_right
/-- Adding the second vector passed to `oangle` to the first vector does not change the sign of
the angle. -/
@[simp]
theorem oangle_sign_add_left (x y : V) : (o.oangle (x + y) y).sign = (o.oangle x y).sign := by
rw [← o.oangle_sign_add_smul_left x y 1, one_smul]
#align orientation.oangle_sign_add_left Orientation.oangle_sign_add_left
/-- Subtracting the first vector passed to `oangle` from the second vector does not change the
sign of the angle. -/
@[simp]
theorem oangle_sign_sub_right (x y : V) : (o.oangle x (y - x)).sign = (o.oangle x y).sign := by
rw [← o.oangle_sign_sub_smul_right x y 1, one_smul]
#align orientation.oangle_sign_sub_right Orientation.oangle_sign_sub_right
/-- Subtracting the second vector passed to `oangle` from the first vector does not change the
sign of the angle. -/
@[simp]
theorem oangle_sign_sub_left (x y : V) : (o.oangle (x - y) y).sign = (o.oangle x y).sign := by
rw [← o.oangle_sign_sub_smul_left x y 1, one_smul]
#align orientation.oangle_sign_sub_left Orientation.oangle_sign_sub_left
/-- Subtracting the second vector passed to `oangle` from a multiple of the first vector negates
the sign of the angle. -/
@[simp]
theorem oangle_sign_smul_sub_right (x y : V) (r : ℝ) :
(o.oangle x (r • x - y)).sign = -(o.oangle x y).sign := by
rw [← oangle_sign_neg_right, sub_eq_add_neg, oangle_sign_smul_add_right]
#align orientation.oangle_sign_smul_sub_right Orientation.oangle_sign_smul_sub_right
/-- Subtracting the first vector passed to `oangle` from a multiple of the second vector negates
the sign of the angle. -/
@[simp]
theorem oangle_sign_smul_sub_left (x y : V) (r : ℝ) :
(o.oangle (r • y - x) y).sign = -(o.oangle x y).sign := by
rw [← oangle_sign_neg_left, sub_eq_neg_add, oangle_sign_add_smul_left]
#align orientation.oangle_sign_smul_sub_left Orientation.oangle_sign_smul_sub_left
/-- Subtracting the second vector passed to `oangle` from the first vector negates the sign of
the angle. -/
| Mathlib/Geometry/Euclidean/Angle/Oriented/Basic.lean | 999 | 1,001 | theorem oangle_sign_sub_right_eq_neg (x y : V) :
(o.oangle x (x - y)).sign = -(o.oangle x y).sign := by |
rw [← o.oangle_sign_smul_sub_right x y 1, one_smul]
|
/-
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
| Mathlib/CategoryTheory/Subobject/FactorThru.lean | 96 | 100 | 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⟩
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Jeremy Avigad, Yury Kudryashov
-/
import Mathlib.Order.Filter.AtTopBot
import Mathlib.Order.Filter.Pi
#align_import order.filter.cofinite from "leanprover-community/mathlib"@"8631e2d5ea77f6c13054d9151d82b83069680cb1"
/-!
# The cofinite filter
In this file we define
`Filter.cofinite`: the filter of sets with finite complement
and prove its basic properties. In particular, we prove that for `ℕ` it is equal to `Filter.atTop`.
## TODO
Define filters for other cardinalities of the complement.
-/
open Set Function
variable {ι α β : Type*} {l : Filter α}
namespace Filter
/-- The cofinite filter is the filter of subsets whose complements are finite. -/
def cofinite : Filter α :=
comk Set.Finite finite_empty (fun _t ht _s hsub ↦ ht.subset hsub) fun _ h _ ↦ h.union
#align filter.cofinite Filter.cofinite
@[simp]
theorem mem_cofinite {s : Set α} : s ∈ @cofinite α ↔ sᶜ.Finite :=
Iff.rfl
#align filter.mem_cofinite Filter.mem_cofinite
@[simp]
theorem eventually_cofinite {p : α → Prop} : (∀ᶠ x in cofinite, p x) ↔ { x | ¬p x }.Finite :=
Iff.rfl
#align filter.eventually_cofinite Filter.eventually_cofinite
theorem hasBasis_cofinite : HasBasis cofinite (fun s : Set α => s.Finite) compl :=
⟨fun s =>
⟨fun h => ⟨sᶜ, h, (compl_compl s).subset⟩, fun ⟨_t, htf, hts⟩ =>
htf.subset <| compl_subset_comm.2 hts⟩⟩
#align filter.has_basis_cofinite Filter.hasBasis_cofinite
instance cofinite_neBot [Infinite α] : NeBot (@cofinite α) :=
hasBasis_cofinite.neBot_iff.2 fun hs => hs.infinite_compl.nonempty
#align filter.cofinite_ne_bot Filter.cofinite_neBot
@[simp]
theorem cofinite_eq_bot_iff : @cofinite α = ⊥ ↔ Finite α := by
simp [← empty_mem_iff_bot, finite_univ_iff]
@[simp]
theorem cofinite_eq_bot [Finite α] : @cofinite α = ⊥ := cofinite_eq_bot_iff.2 ‹_›
theorem frequently_cofinite_iff_infinite {p : α → Prop} :
(∃ᶠ x in cofinite, p x) ↔ Set.Infinite { x | p x } := by
simp only [Filter.Frequently, eventually_cofinite, not_not, Set.Infinite]
#align filter.frequently_cofinite_iff_infinite Filter.frequently_cofinite_iff_infinite
lemma frequently_cofinite_mem_iff_infinite {s : Set α} : (∃ᶠ x in cofinite, x ∈ s) ↔ s.Infinite :=
frequently_cofinite_iff_infinite
alias ⟨_, _root_.Set.Infinite.frequently_cofinite⟩ := frequently_cofinite_mem_iff_infinite
@[simp]
lemma cofinite_inf_principal_neBot_iff {s : Set α} : (cofinite ⊓ 𝓟 s).NeBot ↔ s.Infinite :=
frequently_mem_iff_neBot.symm.trans frequently_cofinite_mem_iff_infinite
alias ⟨_, _root_.Set.Infinite.cofinite_inf_principal_neBot⟩ := cofinite_inf_principal_neBot_iff
theorem _root_.Set.Finite.compl_mem_cofinite {s : Set α} (hs : s.Finite) : sᶜ ∈ @cofinite α :=
mem_cofinite.2 <| (compl_compl s).symm ▸ hs
#align set.finite.compl_mem_cofinite Set.Finite.compl_mem_cofinite
theorem _root_.Set.Finite.eventually_cofinite_nmem {s : Set α} (hs : s.Finite) :
∀ᶠ x in cofinite, x ∉ s :=
hs.compl_mem_cofinite
#align set.finite.eventually_cofinite_nmem Set.Finite.eventually_cofinite_nmem
theorem _root_.Finset.eventually_cofinite_nmem (s : Finset α) : ∀ᶠ x in cofinite, x ∉ s :=
s.finite_toSet.eventually_cofinite_nmem
#align finset.eventually_cofinite_nmem Finset.eventually_cofinite_nmem
theorem _root_.Set.infinite_iff_frequently_cofinite {s : Set α} :
Set.Infinite s ↔ ∃ᶠ x in cofinite, x ∈ s :=
frequently_cofinite_iff_infinite.symm
#align set.infinite_iff_frequently_cofinite Set.infinite_iff_frequently_cofinite
theorem eventually_cofinite_ne (x : α) : ∀ᶠ a in cofinite, a ≠ x :=
(Set.finite_singleton x).eventually_cofinite_nmem
#align filter.eventually_cofinite_ne Filter.eventually_cofinite_ne
| Mathlib/Order/Filter/Cofinite.lean | 101 | 104 | theorem le_cofinite_iff_compl_singleton_mem : l ≤ cofinite ↔ ∀ x, {x}ᶜ ∈ l := by |
refine ⟨fun h x => h (finite_singleton x).compl_mem_cofinite, fun h s (hs : sᶜ.Finite) => ?_⟩
rw [← compl_compl s, ← biUnion_of_singleton sᶜ, compl_iUnion₂, Filter.biInter_mem hs]
exact fun x _ => h x
|
/-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Data.Finset.Lattice
import Mathlib.Order.Hom.Basic
import Mathlib.Data.Set.Finite
import Mathlib.Order.ConditionallyCompleteLattice.Basic
#align_import order.partial_sups from "leanprover-community/mathlib"@"d6fad0e5bf2d6f48da9175d25c3dc5706b3834ce"
/-!
# The monotone sequence of partial supremums of a sequence
We define `partialSups : (ℕ → α) → ℕ →o α` inductively. For `f : ℕ → α`, `partialSups f` is
the sequence `f 0`, `f 0 ⊔ f 1`, `f 0 ⊔ f 1 ⊔ f 2`, ... The point of this definition is that
* it doesn't need a `⨆`, as opposed to `⨆ (i ≤ n), f i` (which also means the wrong thing on
`ConditionallyCompleteLattice`s).
* it doesn't need a `⊥`, as opposed to `(Finset.range (n + 1)).sup f`.
* it avoids needing to prove that `Finset.range (n + 1)` is nonempty to use `Finset.sup'`.
Equivalence with those definitions is shown by `partialSups_eq_biSup`, `partialSups_eq_sup_range`,
and `partialSups_eq_sup'_range` respectively.
## Notes
One might dispute whether this sequence should start at `f 0` or `⊥`. We choose the former because :
* Starting at `⊥` requires... having a bottom element.
* `fun f n ↦ (Finset.range n).sup f` is already effectively the sequence starting at `⊥`.
* If we started at `⊥` we wouldn't have the Galois insertion. See `partialSups.gi`.
## TODO
One could generalize `partialSups` to any locally finite bot preorder domain, in place of `ℕ`.
Necessary for the TODO in the module docstring of `Order.disjointed`.
-/
variable {α : Type*}
section SemilatticeSup
variable [SemilatticeSup α]
/-- The monotone sequence whose value at `n` is the supremum of the `f m` where `m ≤ n`. -/
def partialSups (f : ℕ → α) : ℕ →o α :=
⟨@Nat.rec (fun _ => α) (f 0) fun (n : ℕ) (a : α) => a ⊔ f (n + 1),
monotone_nat_of_le_succ fun _ => le_sup_left⟩
#align partial_sups partialSups
@[simp]
theorem partialSups_zero (f : ℕ → α) : partialSups f 0 = f 0 :=
rfl
#align partial_sups_zero partialSups_zero
@[simp]
theorem partialSups_succ (f : ℕ → α) (n : ℕ) :
partialSups f (n + 1) = partialSups f n ⊔ f (n + 1) :=
rfl
#align partial_sups_succ partialSups_succ
lemma partialSups_iff_forall {f : ℕ → α} (p : α → Prop)
(hp : ∀ {a b}, p (a ⊔ b) ↔ p a ∧ p b) : ∀ {n : ℕ}, p (partialSups f n) ↔ ∀ k ≤ n, p (f k)
| 0 => by simp
| (n + 1) => by simp [hp, partialSups_iff_forall, ← Nat.lt_succ_iff, ← Nat.forall_lt_succ]
@[simp]
lemma partialSups_le_iff {f : ℕ → α} {n : ℕ} {a : α} : partialSups f n ≤ a ↔ ∀ k ≤ n, f k ≤ a :=
partialSups_iff_forall (· ≤ a) sup_le_iff
theorem le_partialSups_of_le (f : ℕ → α) {m n : ℕ} (h : m ≤ n) : f m ≤ partialSups f n :=
partialSups_le_iff.1 le_rfl m h
#align le_partial_sups_of_le le_partialSups_of_le
theorem le_partialSups (f : ℕ → α) : f ≤ partialSups f := fun _n => le_partialSups_of_le f le_rfl
#align le_partial_sups le_partialSups
theorem partialSups_le (f : ℕ → α) (n : ℕ) (a : α) (w : ∀ m, m ≤ n → f m ≤ a) :
partialSups f n ≤ a :=
partialSups_le_iff.2 w
#align partial_sups_le partialSups_le
@[simp]
lemma upperBounds_range_partialSups (f : ℕ → α) :
upperBounds (Set.range (partialSups f)) = upperBounds (Set.range f) := by
ext a
simp only [mem_upperBounds, Set.forall_mem_range, partialSups_le_iff]
exact ⟨fun h _ ↦ h _ _ le_rfl, fun h _ _ _ ↦ h _⟩
@[simp]
theorem bddAbove_range_partialSups {f : ℕ → α} :
BddAbove (Set.range (partialSups f)) ↔ BddAbove (Set.range f) :=
.of_eq <| congr_arg Set.Nonempty <| upperBounds_range_partialSups f
#align bdd_above_range_partial_sups bddAbove_range_partialSups
| Mathlib/Order/PartialSups.lean | 97 | 101 | theorem Monotone.partialSups_eq {f : ℕ → α} (hf : Monotone f) : (partialSups f : ℕ → α) = f := by |
ext n
induction' n with n ih
· rfl
· rw [partialSups_succ, ih, sup_eq_right.2 (hf (Nat.le_succ _))]
|
/-
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.MonoidAlgebra.Degree
import Mathlib.Algebra.Polynomial.Coeff
import Mathlib.Algebra.Polynomial.Monomial
import Mathlib.Data.Fintype.BigOperators
import Mathlib.Data.Nat.WithBot
import Mathlib.Data.Nat.Cast.WithTop
import Mathlib.Data.Nat.SuccPred
#align_import data.polynomial.degree.definitions from "leanprover-community/mathlib"@"808ea4ebfabeb599f21ec4ae87d6dc969597887f"
/-!
# Theory of univariate polynomials
The definitions include
`degree`, `Monic`, `leadingCoeff`
Results include
- `degree_mul` : The degree of the product is the sum of degrees
- `leadingCoeff_add_of_degree_eq` and `leadingCoeff_add_of_degree_lt` :
The leading_coefficient of a sum is determined by the leading coefficients and degrees
-/
-- Porting note: `Mathlib.Data.Nat.Cast.WithTop` should be imported for `Nat.cast_withBot`.
set_option linter.uppercaseLean3 false
noncomputable section
open Finsupp Finset
open Polynomial
namespace Polynomial
universe u v
variable {R : Type u} {S : Type v} {a b c d : R} {n m : ℕ}
section Semiring
variable [Semiring R] {p q r : R[X]}
/-- `degree p` is the degree of the polynomial `p`, i.e. the largest `X`-exponent in `p`.
`degree p = some n` when `p ≠ 0` and `n` is the highest power of `X` that appears in `p`, otherwise
`degree 0 = ⊥`. -/
def degree (p : R[X]) : WithBot ℕ :=
p.support.max
#align polynomial.degree Polynomial.degree
theorem supDegree_eq_degree (p : R[X]) : p.toFinsupp.supDegree WithBot.some = p.degree :=
max_eq_sup_coe
theorem degree_lt_wf : WellFounded fun p q : R[X] => degree p < degree q :=
InvImage.wf degree wellFounded_lt
#align polynomial.degree_lt_wf Polynomial.degree_lt_wf
instance : WellFoundedRelation R[X] :=
⟨_, degree_lt_wf⟩
/-- `natDegree p` forces `degree p` to ℕ, by defining `natDegree 0 = 0`. -/
def natDegree (p : R[X]) : ℕ :=
(degree p).unbot' 0
#align polynomial.nat_degree Polynomial.natDegree
/-- `leadingCoeff p` gives the coefficient of the highest power of `X` in `p`-/
def leadingCoeff (p : R[X]) : R :=
coeff p (natDegree p)
#align polynomial.leading_coeff Polynomial.leadingCoeff
/-- a polynomial is `Monic` if its leading coefficient is 1 -/
def Monic (p : R[X]) :=
leadingCoeff p = (1 : R)
#align polynomial.monic Polynomial.Monic
@[nontriviality]
theorem monic_of_subsingleton [Subsingleton R] (p : R[X]) : Monic p :=
Subsingleton.elim _ _
#align polynomial.monic_of_subsingleton Polynomial.monic_of_subsingleton
theorem Monic.def : Monic p ↔ leadingCoeff p = 1 :=
Iff.rfl
#align polynomial.monic.def Polynomial.Monic.def
instance Monic.decidable [DecidableEq R] : Decidable (Monic p) := by unfold Monic; infer_instance
#align polynomial.monic.decidable Polynomial.Monic.decidable
@[simp]
theorem Monic.leadingCoeff {p : R[X]} (hp : p.Monic) : leadingCoeff p = 1 :=
hp
#align polynomial.monic.leading_coeff Polynomial.Monic.leadingCoeff
theorem Monic.coeff_natDegree {p : R[X]} (hp : p.Monic) : p.coeff p.natDegree = 1 :=
hp
#align polynomial.monic.coeff_nat_degree Polynomial.Monic.coeff_natDegree
@[simp]
theorem degree_zero : degree (0 : R[X]) = ⊥ :=
rfl
#align polynomial.degree_zero Polynomial.degree_zero
@[simp]
theorem natDegree_zero : natDegree (0 : R[X]) = 0 :=
rfl
#align polynomial.nat_degree_zero Polynomial.natDegree_zero
@[simp]
theorem coeff_natDegree : coeff p (natDegree p) = leadingCoeff p :=
rfl
#align polynomial.coeff_nat_degree Polynomial.coeff_natDegree
@[simp]
theorem degree_eq_bot : degree p = ⊥ ↔ p = 0 :=
⟨fun h => support_eq_empty.1 (Finset.max_eq_bot.1 h), fun h => h.symm ▸ rfl⟩
#align polynomial.degree_eq_bot Polynomial.degree_eq_bot
@[nontriviality]
theorem degree_of_subsingleton [Subsingleton R] : degree p = ⊥ := by
rw [Subsingleton.elim p 0, degree_zero]
#align polynomial.degree_of_subsingleton Polynomial.degree_of_subsingleton
@[nontriviality]
theorem natDegree_of_subsingleton [Subsingleton R] : natDegree p = 0 := by
rw [Subsingleton.elim p 0, natDegree_zero]
#align polynomial.nat_degree_of_subsingleton Polynomial.natDegree_of_subsingleton
theorem degree_eq_natDegree (hp : p ≠ 0) : degree p = (natDegree p : WithBot ℕ) := by
let ⟨n, hn⟩ := not_forall.1 (mt Option.eq_none_iff_forall_not_mem.2 (mt degree_eq_bot.1 hp))
have hn : degree p = some n := Classical.not_not.1 hn
rw [natDegree, hn]; rfl
#align polynomial.degree_eq_nat_degree Polynomial.degree_eq_natDegree
theorem supDegree_eq_natDegree (p : R[X]) : p.toFinsupp.supDegree id = p.natDegree := by
obtain rfl|h := eq_or_ne p 0
· simp
apply WithBot.coe_injective
rw [← AddMonoidAlgebra.supDegree_withBot_some_comp, Function.comp_id, supDegree_eq_degree,
degree_eq_natDegree h, Nat.cast_withBot]
rwa [support_toFinsupp, nonempty_iff_ne_empty, Ne, support_eq_empty]
| Mathlib/Algebra/Polynomial/Degree/Definitions.lean | 146 | 147 | theorem degree_eq_iff_natDegree_eq {p : R[X]} {n : ℕ} (hp : p ≠ 0) :
p.degree = n ↔ p.natDegree = n := by | rw [degree_eq_natDegree hp]; exact WithBot.coe_eq_coe
|
/-
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∞}
| Mathlib/Topology/MetricSpace/Infsep.lean | 287 | 293 | 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
|
/-
Copyright (c) 2022 Yuyang Zhao. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yuyang Zhao
-/
import Batteries.Classes.Order
namespace Batteries.PairingHeapImp
/--
A `Heap` is the nodes of the pairing heap.
Each node have two pointers: `child` going to the first child of this node,
and `sibling` goes to the next sibling of this tree.
So it actually encodes a forest where each node has children
`node.child`, `node.child.sibling`, `node.child.sibling.sibling`, etc.
Each edge in this forest denotes a `le a b` relation that has been checked, so
the root is smaller than everything else under it.
-/
inductive Heap (α : Type u) where
/-- An empty forest, which has depth `0`. -/
| nil : Heap α
/-- A forest consists of a root `a`, a forest `child` elements greater than `a`,
and another forest `sibling`. -/
| node (a : α) (child sibling : Heap α) : Heap α
deriving Repr
/-- `O(n)`. The number of elements in the heap. -/
def Heap.size : Heap α → Nat
| .nil => 0
| .node _ c s => c.size + 1 + s.size
/-- A node containing a single element `a`. -/
def Heap.singleton (a : α) : Heap α := .node a .nil .nil
/-- `O(1)`. Is the heap empty? -/
def Heap.isEmpty : Heap α → Bool
| .nil => true
| _ => false
/-- `O(1)`. Merge two heaps. Ignore siblings. -/
@[specialize] def Heap.merge (le : α → α → Bool) : Heap α → Heap α → Heap α
| .nil, .nil => .nil
| .nil, .node a₂ c₂ _ => .node a₂ c₂ .nil
| .node a₁ c₁ _, .nil => .node a₁ c₁ .nil
| .node a₁ c₁ _, .node a₂ c₂ _ =>
if le a₁ a₂ then .node a₁ (.node a₂ c₂ c₁) .nil else .node a₂ (.node a₁ c₁ c₂) .nil
/-- Auxiliary for `Heap.deleteMin`: merge the forest in pairs. -/
@[specialize] def Heap.combine (le : α → α → Bool) : Heap α → Heap α
| h₁@(.node _ _ h₂@(.node _ _ s)) => merge le (merge le h₁ h₂) (s.combine le)
| h => h
/-- `O(1)`. Get the smallest element in the heap, including the passed in value `a`. -/
@[inline] def Heap.headD (a : α) : Heap α → α
| .nil => a
| .node a _ _ => a
/-- `O(1)`. Get the smallest element in the heap, if it has an element. -/
@[inline] def Heap.head? : Heap α → Option α
| .nil => none
| .node a _ _ => some a
/-- Amortized `O(log n)`. Find and remove the the minimum element from the heap. -/
@[inline] def Heap.deleteMin (le : α → α → Bool) : Heap α → Option (α × Heap α)
| .nil => none
| .node a c _ => (a, combine le c)
/-- Amortized `O(log n)`. Get the tail of the pairing heap after removing the minimum element. -/
@[inline] def Heap.tail? (le : α → α → Bool) (h : Heap α) : Option (Heap α) :=
deleteMin le h |>.map (·.snd)
/-- Amortized `O(log n)`. Remove the minimum element of the heap. -/
@[inline] def Heap.tail (le : α → α → Bool) (h : Heap α) : Heap α :=
tail? le h |>.getD .nil
/-- A predicate says there is no more than one tree. -/
inductive Heap.NoSibling : Heap α → Prop
/-- An empty heap is no more than one tree. -/
| nil : NoSibling .nil
/-- Or there is exactly one tree. -/
| node (a c) : NoSibling (.node a c .nil)
instance : Decidable (Heap.NoSibling s) :=
match s with
| .nil => isTrue .nil
| .node a c .nil => isTrue (.node a c)
| .node _ _ (.node _ _ _) => isFalse nofun
theorem Heap.noSibling_merge (le) (s₁ s₂ : Heap α) :
(s₁.merge le s₂).NoSibling := by
unfold merge
(split <;> try split) <;> constructor
theorem Heap.noSibling_combine (le) (s : Heap α) :
(s.combine le).NoSibling := by
unfold combine; split
· exact noSibling_merge _ _ _
· match s with
| nil | node _ _ nil => constructor
| node _ _ (node _ _ s) => rename_i h; exact (h _ _ _ _ _ rfl).elim
theorem Heap.noSibling_deleteMin {s : Heap α} (eq : s.deleteMin le = some (a, s')) :
s'.NoSibling := by
cases s with cases eq | node a c => exact noSibling_combine _ _
theorem Heap.noSibling_tail? {s : Heap α} : s.tail? le = some s' →
s'.NoSibling := by
simp only [Heap.tail?]; intro eq
match eq₂ : s.deleteMin le, eq with
| some (a, tl), rfl => exact noSibling_deleteMin eq₂
theorem Heap.noSibling_tail (le) (s : Heap α) : (s.tail le).NoSibling := by
simp only [Heap.tail]
match eq : s.tail? le with
| none => cases s with cases eq | nil => constructor
| some tl => exact Heap.noSibling_tail? eq
theorem Heap.size_merge_node (le) (a₁ : α) (c₁ s₁ : Heap α) (a₂ : α) (c₂ s₂ : Heap α) :
(merge le (.node a₁ c₁ s₁) (.node a₂ c₂ s₂)).size = c₁.size + c₂.size + 2 := by
unfold merge; dsimp; split <;> simp_arith [size]
theorem Heap.size_merge (le) {s₁ s₂ : Heap α} (h₁ : s₁.NoSibling) (h₂ : s₂.NoSibling) :
(merge le s₁ s₂).size = s₁.size + s₂.size := by
match h₁, h₂ with
| .nil, .nil | .nil, .node _ _ | .node _ _, .nil => simp [size]
| .node _ _, .node _ _ => unfold merge; dsimp; split <;> simp_arith [size]
theorem Heap.size_combine (le) (s : Heap α) :
(s.combine le).size = s.size := by
unfold combine; split
· rename_i a₁ c₁ a₂ c₂ s
rw [size_merge le (noSibling_merge _ _ _) (noSibling_combine _ _),
size_merge_node, size_combine le s]
simp_arith [size]
· rfl
theorem Heap.size_deleteMin {s : Heap α} (h : s.NoSibling) (eq : s.deleteMin le = some (a, s')) :
s.size = s'.size + 1 := by
cases h with cases eq | node a c => rw [size_combine, size, size]
theorem Heap.size_tail? {s : Heap α} (h : s.NoSibling) : s.tail? le = some s' →
s.size = s'.size + 1 := by
simp only [Heap.tail?]; intro eq
match eq₂ : s.deleteMin le, eq with
| some (a, tl), rfl => exact size_deleteMin h eq₂
theorem Heap.size_tail (le) {s : Heap α} (h : s.NoSibling) : (s.tail le).size = s.size - 1 := by
simp only [Heap.tail]
match eq : s.tail? le with
| none => cases s with cases eq | nil => rfl
| some tl => simp [Heap.size_tail? h eq]
theorem Heap.size_deleteMin_lt {s : Heap α} (eq : s.deleteMin le = some (a, s')) :
s'.size < s.size := by
cases s with cases eq | node a c => simp_arith [size_combine, size]
theorem Heap.size_tail?_lt {s : Heap α} : s.tail? le = some s' →
s'.size < s.size := by
simp only [Heap.tail?]; intro eq
match eq₂ : s.deleteMin le, eq with
| some (a, tl), rfl => exact size_deleteMin_lt eq₂
/--
`O(n log n)`. Monadic fold over the elements of a heap in increasing order,
by repeatedly pulling the minimum element out of the heap.
-/
@[specialize] def Heap.foldM [Monad m] (le : α → α → Bool) (s : Heap α)
(init : β) (f : β → α → m β) : m β :=
match eq : s.deleteMin le with
| none => pure init
| some (hd, tl) =>
have : tl.size < s.size := by simp_arith [Heap.size_deleteMin_lt eq]
do foldM le tl (← f init hd) f
termination_by s.size
/--
`O(n log n)`. Fold over the elements of a heap in increasing order,
by repeatedly pulling the minimum element out of the heap.
-/
@[inline] def Heap.fold (le : α → α → Bool) (s : Heap α) (init : β) (f : β → α → β) : β :=
Id.run <| s.foldM le init f
/-- `O(n log n)`. Convert the heap to an array in increasing order. -/
@[inline] def Heap.toArray (le : α → α → Bool) (s : Heap α) : Array α := fold le s #[] Array.push
/-- `O(n log n)`. Convert the heap to a list in increasing order. -/
@[inline] def Heap.toList (le : α → α → Bool) (s : Heap α) : List α := (s.toArray le).toList
/-- `O(n)`. Fold a monadic function over the tree structure to accumulate a value. -/
@[specialize] def Heap.foldTreeM [Monad m] (nil : β) (join : α → β → β → m β) : Heap α → m β
| .nil => pure nil
| .node a c s => do join a (← c.foldTreeM nil join) (← s.foldTreeM nil join)
/-- `O(n)`. Fold a function over the tree structure to accumulate a value. -/
@[inline] def Heap.foldTree (nil : β) (join : α → β → β → β) (s : Heap α) : β :=
Id.run <| s.foldTreeM nil join
/-- `O(n)`. Convert the heap to a list in arbitrary order. -/
def Heap.toListUnordered (s : Heap α) : List α :=
s.foldTree id (fun a c s l => a :: c (s l)) []
/-- `O(n)`. Convert the heap to an array in arbitrary order. -/
def Heap.toArrayUnordered (s : Heap α) : Array α :=
s.foldTree id (fun a c s r => s (c (r.push a))) #[]
/--
The well formedness predicate for a heap node.
It asserts that:
* If `a` is added at the top to make the forest into a tree, the resulting tree
is a `le`-min-heap (if `le` is well-behaved)
-/
def Heap.NodeWF (le : α → α → Bool) (a : α) : Heap α → Prop
| .nil => True
| .node b c s => (∀ [TotalBLE le], le a b) ∧ c.NodeWF le b ∧ s.NodeWF le a
/--
The well formedness predicate for a pairing heap.
It asserts that:
* There is no more than one tree.
* It is a `le`-min-heap (if `le` is well-behaved)
-/
inductive Heap.WF (le : α → α → Bool) : Heap α → Prop
/-- It is an empty heap. -/
| nil : WF le .nil
/-- There is exactly one tree and it is a `le`-min-heap. -/
| node (h : c.NodeWF le a) : WF le (.node a c .nil)
theorem Heap.WF.singleton : (Heap.singleton a).WF le := node trivial
theorem Heap.WF.merge_node (h₁ : NodeWF le a₁ c₁) (h₂ : NodeWF le a₂ c₂) :
(merge le (.node a₁ c₁ s₁) (.node a₂ c₂ s₂)).WF le := by
unfold merge; dsimp
split <;> rename_i h
· exact node ⟨fun [_] => h, h₂, h₁⟩
· exact node ⟨fun [_] => TotalBLE.total.resolve_left h, h₁, h₂⟩
theorem Heap.WF.merge (h₁ : s₁.WF le) (h₂ : s₂.WF le) :
(merge le s₁ s₂).WF le :=
match h₁, h₂ with
| .nil, .nil => nil
| .nil, .node h₂ => node h₂
| .node h₁, .nil => node h₁
| .node h₁, .node h₂ => merge_node h₁ h₂
theorem Heap.WF.combine (h : s.NodeWF le a) : (combine le s).WF le :=
match s with
| .nil => nil
| .node _b _c .nil => node h.2.1
| .node _b₁ _c₁ (.node _b₂ _c₂ _s) => merge (merge_node h.2.1 h.2.2.2.1) (combine h.2.2.2.2)
| .lake/packages/batteries/Batteries/Data/PairingHeap.lean | 252 | 254 | theorem Heap.WF.deleteMin {s : Heap α} (h : s.WF le)
(eq : s.deleteMin le = some (a, s')) : s'.WF le := by |
cases h with cases eq | node h => exact Heap.WF.combine h
|
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Wen Yang
-/
import Mathlib.LinearAlgebra.GeneralLinearGroup
import Mathlib.LinearAlgebra.Matrix.Adjugate
import Mathlib.LinearAlgebra.Matrix.Transvection
import Mathlib.RingTheory.RootsOfUnity.Basic
#align_import linear_algebra.matrix.special_linear_group from "leanprover-community/mathlib"@"f06058e64b7e8397234455038f3f8aec83aaba5a"
/-!
# The Special Linear group $SL(n, R)$
This file defines the elements of the Special Linear group `SpecialLinearGroup n R`, consisting
of all square `R`-matrices with determinant `1` on the fintype `n` by `n`. In addition, we define
the group structure on `SpecialLinearGroup n R` and the embedding into the general linear group
`GeneralLinearGroup R (n → R)`.
## Main definitions
* `Matrix.SpecialLinearGroup` is the type of matrices with determinant 1
* `Matrix.SpecialLinearGroup.group` gives the group structure (under multiplication)
* `Matrix.SpecialLinearGroup.toGL` is the embedding `SLₙ(R) → GLₙ(R)`
## Notation
For `m : ℕ`, we introduce the notation `SL(m,R)` for the special linear group on the fintype
`n = Fin m`, in the locale `MatrixGroups`.
## Implementation notes
The inverse operation in the `SpecialLinearGroup` is defined to be the adjugate
matrix, so that `SpecialLinearGroup n R` has a group structure for all `CommRing R`.
We define the elements of `SpecialLinearGroup` to be matrices, since we need to
compute their determinant. This is in contrast with `GeneralLinearGroup R M`,
which consists of invertible `R`-linear maps on `M`.
We provide `Matrix.SpecialLinearGroup.hasCoeToFun` for convenience, but do not state any
lemmas about it, and use `Matrix.SpecialLinearGroup.coeFn_eq_coe` to eliminate it `⇑` in favor
of a regular `↑` coercion.
## References
* https://en.wikipedia.org/wiki/Special_linear_group
## Tags
matrix group, group, matrix inverse
-/
namespace Matrix
universe u v
open Matrix
open LinearMap
section
variable (n : Type u) [DecidableEq n] [Fintype n] (R : Type v) [CommRing R]
/-- `SpecialLinearGroup n R` is the group of `n` by `n` `R`-matrices with determinant equal to 1.
-/
def SpecialLinearGroup :=
{ A : Matrix n n R // A.det = 1 }
#align matrix.special_linear_group Matrix.SpecialLinearGroup
end
@[inherit_doc]
scoped[MatrixGroups] notation "SL(" n ", " R ")" => Matrix.SpecialLinearGroup (Fin n) R
namespace SpecialLinearGroup
variable {n : Type u} [DecidableEq n] [Fintype n] {R : Type v} [CommRing R]
instance hasCoeToMatrix : Coe (SpecialLinearGroup n R) (Matrix n n R) :=
⟨fun A => A.val⟩
#align matrix.special_linear_group.has_coe_to_matrix Matrix.SpecialLinearGroup.hasCoeToMatrix
/-- In this file, Lean often has a hard time working out the values of `n` and `R` for an expression
like `det ↑A`. Rather than writing `(A : Matrix n n R)` everywhere in this file which is annoyingly
verbose, or `A.val` which is not the simp-normal form for subtypes, we create a local notation
`↑ₘA`. This notation references the local `n` and `R` variables, so is not valid as a global
notation. -/
local notation:1024 "↑ₘ" A:1024 => ((A : SpecialLinearGroup n R) : Matrix n n R)
-- Porting note: moved this section upwards because it used to be not simp-normal.
-- Now it is, since coercion arrows are unfolded.
section CoeFnInstance
/-- This instance is here for convenience, but is literally the same as the coercion from
`hasCoeToMatrix`. -/
instance instCoeFun : CoeFun (SpecialLinearGroup n R) fun _ => n → n → R where coe A := ↑ₘA
end CoeFnInstance
theorem ext_iff (A B : SpecialLinearGroup n R) : A = B ↔ ∀ i j, ↑ₘA i j = ↑ₘB i j :=
Subtype.ext_iff.trans Matrix.ext_iff.symm
#align matrix.special_linear_group.ext_iff Matrix.SpecialLinearGroup.ext_iff
@[ext]
theorem ext (A B : SpecialLinearGroup n R) : (∀ i j, ↑ₘA i j = ↑ₘB i j) → A = B :=
(SpecialLinearGroup.ext_iff A B).mpr
#align matrix.special_linear_group.ext Matrix.SpecialLinearGroup.ext
instance subsingleton_of_subsingleton [Subsingleton n] : Subsingleton (SpecialLinearGroup n R) := by
refine ⟨fun ⟨A, hA⟩ ⟨B, hB⟩ ↦ ?_⟩
ext i j
rcases isEmpty_or_nonempty n with hn | hn; · exfalso; exact IsEmpty.false i
rw [det_eq_elem_of_subsingleton _ i] at hA hB
simp only [Subsingleton.elim j i, hA, hB]
instance hasInv : Inv (SpecialLinearGroup n R) :=
⟨fun A => ⟨adjugate A, by rw [det_adjugate, A.prop, one_pow]⟩⟩
#align matrix.special_linear_group.has_inv Matrix.SpecialLinearGroup.hasInv
instance hasMul : Mul (SpecialLinearGroup n R) :=
⟨fun A B => ⟨↑ₘA * ↑ₘB, by rw [det_mul, A.prop, B.prop, one_mul]⟩⟩
#align matrix.special_linear_group.has_mul Matrix.SpecialLinearGroup.hasMul
instance hasOne : One (SpecialLinearGroup n R) :=
⟨⟨1, det_one⟩⟩
#align matrix.special_linear_group.has_one Matrix.SpecialLinearGroup.hasOne
instance : Pow (SpecialLinearGroup n R) ℕ where
pow x n := ⟨↑ₘx ^ n, (det_pow _ _).trans <| x.prop.symm ▸ one_pow _⟩
instance : Inhabited (SpecialLinearGroup n R) :=
⟨1⟩
/-- The transpose of a matrix in `SL(n, R)` -/
def transpose (A : SpecialLinearGroup n R) : SpecialLinearGroup n R :=
⟨A.1.transpose, A.1.det_transpose ▸ A.2⟩
@[inherit_doc]
scoped postfix:1024 "ᵀ" => SpecialLinearGroup.transpose
section CoeLemmas
variable (A B : SpecialLinearGroup n R)
-- Porting note: shouldn't be `@[simp]` because cast+mk gets reduced anyway
theorem coe_mk (A : Matrix n n R) (h : det A = 1) : ↑(⟨A, h⟩ : SpecialLinearGroup n R) = A :=
rfl
#align matrix.special_linear_group.coe_mk Matrix.SpecialLinearGroup.coe_mk
@[simp]
theorem coe_inv : ↑ₘA⁻¹ = adjugate A :=
rfl
#align matrix.special_linear_group.coe_inv Matrix.SpecialLinearGroup.coe_inv
@[simp]
theorem coe_mul : ↑ₘ(A * B) = ↑ₘA * ↑ₘB :=
rfl
#align matrix.special_linear_group.coe_mul Matrix.SpecialLinearGroup.coe_mul
@[simp]
theorem coe_one : ↑ₘ(1 : SpecialLinearGroup n R) = (1 : Matrix n n R) :=
rfl
#align matrix.special_linear_group.coe_one Matrix.SpecialLinearGroup.coe_one
@[simp]
theorem det_coe : det ↑ₘA = 1 :=
A.2
#align matrix.special_linear_group.det_coe Matrix.SpecialLinearGroup.det_coe
@[simp]
theorem coe_pow (m : ℕ) : ↑ₘ(A ^ m) = ↑ₘA ^ m :=
rfl
#align matrix.special_linear_group.coe_pow Matrix.SpecialLinearGroup.coe_pow
@[simp]
lemma coe_transpose (A : SpecialLinearGroup n R) : ↑ₘAᵀ = (↑ₘA)ᵀ :=
rfl
theorem det_ne_zero [Nontrivial R] (g : SpecialLinearGroup n R) : det ↑ₘg ≠ 0 := by
rw [g.det_coe]
norm_num
#align matrix.special_linear_group.det_ne_zero Matrix.SpecialLinearGroup.det_ne_zero
theorem row_ne_zero [Nontrivial R] (g : SpecialLinearGroup n R) (i : n) : ↑ₘg i ≠ 0 := fun h =>
g.det_ne_zero <| det_eq_zero_of_row_eq_zero i <| by simp [h]
#align matrix.special_linear_group.row_ne_zero Matrix.SpecialLinearGroup.row_ne_zero
end CoeLemmas
instance monoid : Monoid (SpecialLinearGroup n R) :=
Function.Injective.monoid (↑) Subtype.coe_injective coe_one coe_mul coe_pow
instance : Group (SpecialLinearGroup n R) :=
{ SpecialLinearGroup.monoid, SpecialLinearGroup.hasInv with
mul_left_inv := fun A => by
ext1
simp [adjugate_mul] }
/-- A version of `Matrix.toLin' A` that produces linear equivalences. -/
def toLin' : SpecialLinearGroup n R →* (n → R) ≃ₗ[R] n → R where
toFun A :=
LinearEquiv.ofLinear (Matrix.toLin' ↑ₘA) (Matrix.toLin' ↑ₘA⁻¹)
(by rw [← toLin'_mul, ← coe_mul, mul_right_inv, coe_one, toLin'_one])
(by rw [← toLin'_mul, ← coe_mul, mul_left_inv, coe_one, toLin'_one])
map_one' := LinearEquiv.toLinearMap_injective Matrix.toLin'_one
map_mul' A B := LinearEquiv.toLinearMap_injective <| Matrix.toLin'_mul ↑ₘA ↑ₘB
#align matrix.special_linear_group.to_lin' Matrix.SpecialLinearGroup.toLin'
theorem toLin'_apply (A : SpecialLinearGroup n R) (v : n → R) :
SpecialLinearGroup.toLin' A v = Matrix.toLin' (↑ₘA) v :=
rfl
#align matrix.special_linear_group.to_lin'_apply Matrix.SpecialLinearGroup.toLin'_apply
theorem toLin'_to_linearMap (A : SpecialLinearGroup n R) :
↑(SpecialLinearGroup.toLin' A) = Matrix.toLin' ↑ₘA :=
rfl
#align matrix.special_linear_group.to_lin'_to_linear_map Matrix.SpecialLinearGroup.toLin'_to_linearMap
theorem toLin'_symm_apply (A : SpecialLinearGroup n R) (v : n → R) :
A.toLin'.symm v = Matrix.toLin' (↑ₘA⁻¹) v :=
rfl
#align matrix.special_linear_group.to_lin'_symm_apply Matrix.SpecialLinearGroup.toLin'_symm_apply
theorem toLin'_symm_to_linearMap (A : SpecialLinearGroup n R) :
↑A.toLin'.symm = Matrix.toLin' ↑ₘA⁻¹ :=
rfl
#align matrix.special_linear_group.to_lin'_symm_to_linear_map Matrix.SpecialLinearGroup.toLin'_symm_to_linearMap
theorem toLin'_injective :
Function.Injective ↑(toLin' : SpecialLinearGroup n R →* (n → R) ≃ₗ[R] n → R) := fun _ _ h =>
Subtype.coe_injective <| Matrix.toLin'.injective <| LinearEquiv.toLinearMap_injective.eq_iff.mpr h
#align matrix.special_linear_group.to_lin'_injective Matrix.SpecialLinearGroup.toLin'_injective
/-- `toGL` is the map from the special linear group to the general linear group -/
def toGL : SpecialLinearGroup n R →* GeneralLinearGroup R (n → R) :=
(GeneralLinearGroup.generalLinearEquiv _ _).symm.toMonoidHom.comp toLin'
set_option linter.uppercaseLean3 false in
#align matrix.special_linear_group.to_GL Matrix.SpecialLinearGroup.toGL
-- Porting note (#11036): broken dot notation
theorem coe_toGL (A : SpecialLinearGroup n R) : SpecialLinearGroup.toGL A = A.toLin'.toLinearMap :=
rfl
set_option linter.uppercaseLean3 false in
#align matrix.special_linear_group.coe_to_GL Matrix.SpecialLinearGroup.coe_toGL
variable {S : Type*} [CommRing S]
/-- A ring homomorphism from `R` to `S` induces a group homomorphism from
`SpecialLinearGroup n R` to `SpecialLinearGroup n S`. -/
@[simps]
def map (f : R →+* S) : SpecialLinearGroup n R →* SpecialLinearGroup n S where
toFun g :=
⟨f.mapMatrix ↑ₘg, by
rw [← f.map_det]
simp [g.prop]⟩
map_one' := Subtype.ext <| f.mapMatrix.map_one
map_mul' x y := Subtype.ext <| f.mapMatrix.map_mul ↑ₘx ↑ₘy
#align matrix.special_linear_group.map Matrix.SpecialLinearGroup.map
section center
open Subgroup
@[simp]
theorem center_eq_bot_of_subsingleton [Subsingleton n] :
center (SpecialLinearGroup n R) = ⊥ :=
eq_bot_iff.mpr fun x _ ↦ by rw [mem_bot, Subsingleton.elim x 1]
theorem scalar_eq_self_of_mem_center
{A : SpecialLinearGroup n R} (hA : A ∈ center (SpecialLinearGroup n R)) (i : n) :
scalar n (A i i) = A := by
obtain ⟨r : R, hr : scalar n r = A⟩ := mem_range_scalar_of_commute_transvectionStruct fun t ↦
Subtype.ext_iff.mp <| Subgroup.mem_center_iff.mp hA ⟨t.toMatrix, by simp⟩
simp [← congr_fun₂ hr i i, ← hr]
theorem scalar_eq_coe_self_center
(A : center (SpecialLinearGroup n R)) (i : n) :
scalar n ((A : Matrix n n R) i i) = A :=
scalar_eq_self_of_mem_center A.property i
/-- The center of a special linear group of degree `n` is the subgroup of scalar matrices, for which
the scalars are the `n`-th roots of unity. -/
| Mathlib/LinearAlgebra/Matrix/SpecialLinearGroup.lean | 285 | 293 | theorem mem_center_iff {A : SpecialLinearGroup n R} :
A ∈ center (SpecialLinearGroup n R) ↔ ∃ (r : R), r ^ (Fintype.card n) = 1 ∧ scalar n r = A := by |
rcases isEmpty_or_nonempty n with hn | ⟨⟨i⟩⟩; · exact ⟨by aesop, by simp [Subsingleton.elim A 1]⟩
refine ⟨fun h ↦ ⟨A i i, ?_, ?_⟩, fun ⟨r, _, hr⟩ ↦ mem_center_iff.mpr fun B ↦ ?_⟩
· have : det ((scalar n) (A i i)) = 1 := (scalar_eq_self_of_mem_center h i).symm ▸ A.property
simpa using this
· exact scalar_eq_self_of_mem_center h i
· suffices ↑ₘ(B * A) = ↑ₘ(A * B) from Subtype.val_injective this
simpa only [coe_mul, ← hr] using (scalar_commute (n := n) r (Commute.all r) B).symm
|
/-
Copyright (c) 2021 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying
-/
import Mathlib.MeasureTheory.Measure.Sub
import Mathlib.MeasureTheory.Decomposition.SignedHahn
import Mathlib.MeasureTheory.Function.AEEqOfIntegral
#align_import measure_theory.decomposition.lebesgue from "leanprover-community/mathlib"@"b2ff9a3d7a15fd5b0f060b135421d6a89a999c2f"
/-!
# Lebesgue decomposition
This file proves the Lebesgue decomposition theorem. The Lebesgue decomposition theorem states that,
given two σ-finite measures `μ` and `ν`, there exists a σ-finite measure `ξ` and a measurable
function `f` such that `μ = ξ + fν` and `ξ` is mutually singular with respect to `ν`.
The Lebesgue decomposition provides the Radon-Nikodym theorem readily.
## Main definitions
* `MeasureTheory.Measure.HaveLebesgueDecomposition` : A pair of measures `μ` and `ν` is said
to `HaveLebesgueDecomposition` if there exist a measure `ξ` and a measurable function `f`,
such that `ξ` is mutually singular with respect to `ν` and `μ = ξ + ν.withDensity f`
* `MeasureTheory.Measure.singularPart` : If a pair of measures `HaveLebesgueDecomposition`,
then `singularPart` chooses the measure from `HaveLebesgueDecomposition`, otherwise it
returns the zero measure.
* `MeasureTheory.Measure.rnDeriv`: If a pair of measures
`HaveLebesgueDecomposition`, then `rnDeriv` chooses the measurable function from
`HaveLebesgueDecomposition`, otherwise it returns the zero function.
## Main results
* `MeasureTheory.Measure.haveLebesgueDecomposition_of_sigmaFinite` :
the Lebesgue decomposition theorem.
* `MeasureTheory.Measure.eq_singularPart` : Given measures `μ` and `ν`, if `s` is a measure
mutually singular to `ν` and `f` is a measurable function such that `μ = s + fν`, then
`s = μ.singularPart ν`.
* `MeasureTheory.Measure.eq_rnDeriv` : Given measures `μ` and `ν`, if `s` is a
measure mutually singular to `ν` and `f` is a measurable function such that `μ = s + fν`,
then `f = μ.rnDeriv ν`.
## Tags
Lebesgue decomposition theorem
-/
open scoped MeasureTheory NNReal ENNReal
open Set
namespace MeasureTheory
namespace Measure
variable {α β : Type*} {m : MeasurableSpace α} {μ ν : Measure α}
/-- A pair of measures `μ` and `ν` is said to `HaveLebesgueDecomposition` if there exists a
measure `ξ` and a measurable function `f`, such that `ξ` is mutually singular with respect to
`ν` and `μ = ξ + ν.withDensity f`. -/
class HaveLebesgueDecomposition (μ ν : Measure α) : Prop where
lebesgue_decomposition :
∃ p : Measure α × (α → ℝ≥0∞), Measurable p.2 ∧ p.1 ⟂ₘ ν ∧ μ = p.1 + ν.withDensity p.2
#align measure_theory.measure.have_lebesgue_decomposition MeasureTheory.Measure.HaveLebesgueDecomposition
#align measure_theory.measure.have_lebesgue_decomposition.lebesgue_decomposition MeasureTheory.Measure.HaveLebesgueDecomposition.lebesgue_decomposition
open Classical in
/-- If a pair of measures `HaveLebesgueDecomposition`, then `singularPart` chooses the
measure from `HaveLebesgueDecomposition`, otherwise it returns the zero measure. For sigma-finite
measures, `μ = μ.singularPart ν + ν.withDensity (μ.rnDeriv ν)`. -/
noncomputable irreducible_def singularPart (μ ν : Measure α) : Measure α :=
if h : HaveLebesgueDecomposition μ ν then (Classical.choose h.lebesgue_decomposition).1 else 0
#align measure_theory.measure.singular_part MeasureTheory.Measure.singularPart
open Classical in
/-- If a pair of measures `HaveLebesgueDecomposition`, then `rnDeriv` chooses the
measurable function from `HaveLebesgueDecomposition`, otherwise it returns the zero function.
For sigma-finite measures, `μ = μ.singularPart ν + ν.withDensity (μ.rnDeriv ν)`. -/
noncomputable irreducible_def rnDeriv (μ ν : Measure α) : α → ℝ≥0∞ :=
if h : HaveLebesgueDecomposition μ ν then (Classical.choose h.lebesgue_decomposition).2 else 0
#align measure_theory.measure.rn_deriv MeasureTheory.Measure.rnDeriv
section ByDefinition
theorem haveLebesgueDecomposition_spec (μ ν : Measure α) [h : HaveLebesgueDecomposition μ ν] :
Measurable (μ.rnDeriv ν) ∧
μ.singularPart ν ⟂ₘ ν ∧ μ = μ.singularPart ν + ν.withDensity (μ.rnDeriv ν) := by
rw [singularPart, rnDeriv, dif_pos h, dif_pos h]
exact Classical.choose_spec h.lebesgue_decomposition
#align measure_theory.measure.have_lebesgue_decomposition_spec MeasureTheory.Measure.haveLebesgueDecomposition_spec
lemma rnDeriv_of_not_haveLebesgueDecomposition (h : ¬ HaveLebesgueDecomposition μ ν) :
μ.rnDeriv ν = 0 := by
rw [rnDeriv, dif_neg h]
lemma singularPart_of_not_haveLebesgueDecomposition (h : ¬ HaveLebesgueDecomposition μ ν) :
μ.singularPart ν = 0 := by
rw [singularPart, dif_neg h]
@[measurability]
theorem measurable_rnDeriv (μ ν : Measure α) : Measurable <| μ.rnDeriv ν := by
by_cases h : HaveLebesgueDecomposition μ ν
· exact (haveLebesgueDecomposition_spec μ ν).1
· rw [rnDeriv_of_not_haveLebesgueDecomposition h]
exact measurable_zero
#align measure_theory.measure.measurable_rn_deriv MeasureTheory.Measure.measurable_rnDeriv
theorem mutuallySingular_singularPart (μ ν : Measure α) : μ.singularPart ν ⟂ₘ ν := by
by_cases h : HaveLebesgueDecomposition μ ν
· exact (haveLebesgueDecomposition_spec μ ν).2.1
· rw [singularPart_of_not_haveLebesgueDecomposition h]
exact MutuallySingular.zero_left
#align measure_theory.measure.mutually_singular_singular_part MeasureTheory.Measure.mutuallySingular_singularPart
theorem haveLebesgueDecomposition_add (μ ν : Measure α) [HaveLebesgueDecomposition μ ν] :
μ = μ.singularPart ν + ν.withDensity (μ.rnDeriv ν) :=
(haveLebesgueDecomposition_spec μ ν).2.2
#align measure_theory.measure.have_lebesgue_decomposition_add MeasureTheory.Measure.haveLebesgueDecomposition_add
lemma singularPart_add_rnDeriv (μ ν : Measure α) [HaveLebesgueDecomposition μ ν] :
μ.singularPart ν + ν.withDensity (μ.rnDeriv ν) = μ := (haveLebesgueDecomposition_add μ ν).symm
lemma rnDeriv_add_singularPart (μ ν : Measure α) [HaveLebesgueDecomposition μ ν] :
ν.withDensity (μ.rnDeriv ν) + μ.singularPart ν = μ := by rw [add_comm, singularPart_add_rnDeriv]
end ByDefinition
section HaveLebesgueDecomposition
instance instHaveLebesgueDecompositionZeroLeft : HaveLebesgueDecomposition 0 ν where
lebesgue_decomposition := ⟨⟨0, 0⟩, measurable_zero, MutuallySingular.zero_left, by simp⟩
instance instHaveLebesgueDecompositionZeroRight : HaveLebesgueDecomposition μ 0 where
lebesgue_decomposition := ⟨⟨μ, 0⟩, measurable_zero, MutuallySingular.zero_right, by simp⟩
instance instHaveLebesgueDecompositionSelf : HaveLebesgueDecomposition μ μ where
lebesgue_decomposition := ⟨⟨0, 1⟩, measurable_const, MutuallySingular.zero_left, by simp⟩
instance haveLebesgueDecompositionSMul' (μ ν : Measure α) [HaveLebesgueDecomposition μ ν]
(r : ℝ≥0∞) : (r • μ).HaveLebesgueDecomposition ν where
lebesgue_decomposition := by
obtain ⟨hmeas, hsing, hadd⟩ := haveLebesgueDecomposition_spec μ ν
refine ⟨⟨r • μ.singularPart ν, r • μ.rnDeriv ν⟩, hmeas.const_smul _, hsing.smul _, ?_⟩
simp only [ENNReal.smul_def]
rw [withDensity_smul _ hmeas, ← smul_add, ← hadd]
instance haveLebesgueDecompositionSMul (μ ν : Measure α) [HaveLebesgueDecomposition μ ν]
(r : ℝ≥0) : (r • μ).HaveLebesgueDecomposition ν := by
rw [ENNReal.smul_def]; infer_instance
#align measure_theory.measure.have_lebesgue_decomposition_smul MeasureTheory.Measure.haveLebesgueDecompositionSMul
instance haveLebesgueDecompositionSMulRight (μ ν : Measure α) [HaveLebesgueDecomposition μ ν]
(r : ℝ≥0) :
μ.HaveLebesgueDecomposition (r • ν) where
lebesgue_decomposition := by
obtain ⟨hmeas, hsing, hadd⟩ := haveLebesgueDecomposition_spec μ ν
by_cases hr : r = 0
· exact ⟨⟨μ, 0⟩, measurable_const, by simp [hr], by simp⟩
refine ⟨⟨μ.singularPart ν, r⁻¹ • μ.rnDeriv ν⟩, hmeas.const_smul _,
hsing.mono_ac AbsolutelyContinuous.rfl smul_absolutelyContinuous, ?_⟩
have : r⁻¹ • rnDeriv μ ν = ((r⁻¹ : ℝ≥0) : ℝ≥0∞) • rnDeriv μ ν := by simp [ENNReal.smul_def]
rw [this, withDensity_smul _ hmeas, ENNReal.smul_def r, withDensity_smul_measure,
← smul_assoc, smul_eq_mul, ENNReal.coe_inv hr, ENNReal.inv_mul_cancel, one_smul]
· exact hadd
· simp [hr]
· exact ENNReal.coe_ne_top
theorem haveLebesgueDecomposition_withDensity (μ : Measure α) {f : α → ℝ≥0∞} (hf : Measurable f) :
(μ.withDensity f).HaveLebesgueDecomposition μ := ⟨⟨⟨0, f⟩, hf, .zero_left, (zero_add _).symm⟩⟩
instance haveLebesgueDecompositionRnDeriv (μ ν : Measure α) :
HaveLebesgueDecomposition (ν.withDensity (μ.rnDeriv ν)) ν :=
haveLebesgueDecomposition_withDensity ν (measurable_rnDeriv _ _)
instance instHaveLebesgueDecompositionSingularPart :
HaveLebesgueDecomposition (μ.singularPart ν) ν :=
⟨⟨μ.singularPart ν, 0⟩, measurable_zero, mutuallySingular_singularPart μ ν, by simp⟩
end HaveLebesgueDecomposition
theorem singularPart_le (μ ν : Measure α) : μ.singularPart ν ≤ μ := by
by_cases hl : HaveLebesgueDecomposition μ ν
· conv_rhs => rw [haveLebesgueDecomposition_add μ ν]
exact Measure.le_add_right le_rfl
· rw [singularPart, dif_neg hl]
exact Measure.zero_le μ
#align measure_theory.measure.singular_part_le MeasureTheory.Measure.singularPart_le
theorem withDensity_rnDeriv_le (μ ν : Measure α) : ν.withDensity (μ.rnDeriv ν) ≤ μ := by
by_cases hl : HaveLebesgueDecomposition μ ν
· conv_rhs => rw [haveLebesgueDecomposition_add μ ν]
exact Measure.le_add_left le_rfl
· rw [rnDeriv, dif_neg hl, withDensity_zero]
exact Measure.zero_le μ
#align measure_theory.measure.with_density_rn_deriv_le MeasureTheory.Measure.withDensity_rnDeriv_le
lemma _root_.AEMeasurable.singularPart {β : Type*} {_ : MeasurableSpace β} {f : α → β}
(hf : AEMeasurable f μ) (ν : Measure α) :
AEMeasurable f (μ.singularPart ν) :=
AEMeasurable.mono_measure hf (Measure.singularPart_le _ _)
lemma _root_.AEMeasurable.withDensity_rnDeriv {β : Type*} {_ : MeasurableSpace β} {f : α → β}
(hf : AEMeasurable f μ) (ν : Measure α) :
AEMeasurable f (ν.withDensity (μ.rnDeriv ν)) :=
AEMeasurable.mono_measure hf (Measure.withDensity_rnDeriv_le _ _)
lemma MutuallySingular.singularPart (h : μ ⟂ₘ ν) (ν' : Measure α) :
μ.singularPart ν' ⟂ₘ ν :=
h.mono (singularPart_le μ ν') le_rfl
lemma absolutelyContinuous_withDensity_rnDeriv [HaveLebesgueDecomposition ν μ] (hμν : μ ≪ ν) :
μ ≪ μ.withDensity (ν.rnDeriv μ) := by
rw [haveLebesgueDecomposition_add ν μ] at hμν
refine AbsolutelyContinuous.mk (fun s _ hνs ↦ ?_)
obtain ⟨t, _, ht1, ht2⟩ := mutuallySingular_singularPart ν μ
rw [← inter_union_compl s]
refine le_antisymm ((measure_union_le (s ∩ t) (s ∩ tᶜ)).trans ?_) (zero_le _)
simp only [nonpos_iff_eq_zero, add_eq_zero]
constructor
· refine hμν ?_
simp only [coe_add, Pi.add_apply, add_eq_zero]
constructor
· exact measure_mono_null Set.inter_subset_right ht1
· exact measure_mono_null Set.inter_subset_left hνs
· exact measure_mono_null Set.inter_subset_right ht2
lemma singularPart_eq_zero_of_ac (h : μ ≪ ν) : μ.singularPart ν = 0 := by
rw [← MutuallySingular.self_iff]
exact MutuallySingular.mono_ac (mutuallySingular_singularPart _ _)
AbsolutelyContinuous.rfl ((absolutelyContinuous_of_le (singularPart_le _ _)).trans h)
@[simp]
theorem singularPart_zero (ν : Measure α) : (0 : Measure α).singularPart ν = 0 :=
singularPart_eq_zero_of_ac (AbsolutelyContinuous.zero _)
#align measure_theory.measure.singular_part_zero MeasureTheory.Measure.singularPart_zero
@[simp]
lemma singularPart_zero_right (μ : Measure α) : μ.singularPart 0 = μ := by
conv_rhs => rw [haveLebesgueDecomposition_add μ 0]
simp
lemma singularPart_eq_zero (μ ν : Measure α) [μ.HaveLebesgueDecomposition ν] :
μ.singularPart ν = 0 ↔ μ ≪ ν := by
have h_dec := haveLebesgueDecomposition_add μ ν
refine ⟨fun h ↦ ?_, singularPart_eq_zero_of_ac⟩
rw [h, zero_add] at h_dec
rw [h_dec]
exact withDensity_absolutelyContinuous ν _
@[simp]
lemma withDensity_rnDeriv_eq_zero (μ ν : Measure α) [μ.HaveLebesgueDecomposition ν] :
ν.withDensity (μ.rnDeriv ν) = 0 ↔ μ ⟂ₘ ν := by
have h_dec := haveLebesgueDecomposition_add μ ν
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· rw [h, add_zero] at h_dec
rw [h_dec]
exact mutuallySingular_singularPart μ ν
· rw [← MutuallySingular.self_iff]
rw [h_dec, MutuallySingular.add_left_iff] at h
refine MutuallySingular.mono_ac h.2 AbsolutelyContinuous.rfl ?_
exact withDensity_absolutelyContinuous _ _
@[simp]
lemma rnDeriv_eq_zero (μ ν : Measure α) [μ.HaveLebesgueDecomposition ν] :
μ.rnDeriv ν =ᵐ[ν] 0 ↔ μ ⟂ₘ ν := by
rw [← withDensity_rnDeriv_eq_zero, withDensity_eq_zero_iff (measurable_rnDeriv _ _).aemeasurable]
lemma rnDeriv_zero (ν : Measure α) : (0 : Measure α).rnDeriv ν =ᵐ[ν] 0 := by
rw [rnDeriv_eq_zero]
exact MutuallySingular.zero_left
lemma MutuallySingular.rnDeriv_ae_eq_zero (hμν : μ ⟂ₘ ν) :
μ.rnDeriv ν =ᵐ[ν] 0 := by
by_cases h : μ.HaveLebesgueDecomposition ν
· rw [rnDeriv_eq_zero]
exact hμν
· rw [rnDeriv_of_not_haveLebesgueDecomposition h]
@[simp]
theorem singularPart_withDensity (ν : Measure α) (f : α → ℝ≥0∞) :
(ν.withDensity f).singularPart ν = 0 :=
singularPart_eq_zero_of_ac (withDensity_absolutelyContinuous _ _)
#align measure_theory.measure.singular_part_with_density MeasureTheory.Measure.singularPart_withDensity
lemma rnDeriv_singularPart (μ ν : Measure α) :
(μ.singularPart ν).rnDeriv ν =ᵐ[ν] 0 := by
rw [rnDeriv_eq_zero]
exact mutuallySingular_singularPart μ ν
@[simp]
lemma singularPart_self (μ : Measure α) : μ.singularPart μ = 0 :=
singularPart_eq_zero_of_ac Measure.AbsolutelyContinuous.rfl
lemma rnDeriv_self (μ : Measure α) [SigmaFinite μ] : μ.rnDeriv μ =ᵐ[μ] fun _ ↦ 1 := by
have h := rnDeriv_add_singularPart μ μ
rw [singularPart_self, add_zero] at h
have h_one : μ = μ.withDensity 1 := by simp
conv_rhs at h => rw [h_one]
rwa [withDensity_eq_iff_of_sigmaFinite (measurable_rnDeriv _ _).aemeasurable] at h
exact aemeasurable_const
lemma singularPart_eq_self [μ.HaveLebesgueDecomposition ν] : μ.singularPart ν = μ ↔ μ ⟂ₘ ν := by
have h_dec := haveLebesgueDecomposition_add μ ν
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· rw [← h]
exact mutuallySingular_singularPart _ _
· conv_rhs => rw [h_dec]
rw [(withDensity_rnDeriv_eq_zero _ _).mpr h, add_zero]
@[simp]
lemma singularPart_singularPart (μ ν : Measure α) :
(μ.singularPart ν).singularPart ν = μ.singularPart ν := by
rw [Measure.singularPart_eq_self]
exact Measure.mutuallySingular_singularPart _ _
instance singularPart.instIsFiniteMeasure [IsFiniteMeasure μ] :
IsFiniteMeasure (μ.singularPart ν) :=
isFiniteMeasure_of_le μ <| singularPart_le μ ν
#align measure_theory.measure.singular_part.measure_theory.is_finite_measure MeasureTheory.Measure.singularPart.instIsFiniteMeasure
instance singularPart.instSigmaFinite [SigmaFinite μ] : SigmaFinite (μ.singularPart ν) :=
sigmaFinite_of_le μ <| singularPart_le μ ν
#align measure_theory.measure.singular_part.measure_theory.sigma_finite MeasureTheory.Measure.singularPart.instSigmaFinite
instance singularPart.instIsLocallyFiniteMeasure [TopologicalSpace α] [IsLocallyFiniteMeasure μ] :
IsLocallyFiniteMeasure (μ.singularPart ν) :=
isLocallyFiniteMeasure_of_le <| singularPart_le μ ν
#align measure_theory.measure.singular_part.measure_theory.is_locally_finite_measure MeasureTheory.Measure.singularPart.instIsLocallyFiniteMeasure
instance withDensity.instIsFiniteMeasure [IsFiniteMeasure μ] :
IsFiniteMeasure (ν.withDensity <| μ.rnDeriv ν) :=
isFiniteMeasure_of_le μ <| withDensity_rnDeriv_le μ ν
#align measure_theory.measure.with_density.measure_theory.is_finite_measure MeasureTheory.Measure.withDensity.instIsFiniteMeasure
instance withDensity.instSigmaFinite [SigmaFinite μ] :
SigmaFinite (ν.withDensity <| μ.rnDeriv ν) :=
sigmaFinite_of_le μ <| withDensity_rnDeriv_le μ ν
#align measure_theory.measure.with_density.measure_theory.sigma_finite MeasureTheory.Measure.withDensity.instSigmaFinite
instance withDensity.instIsLocallyFiniteMeasure [TopologicalSpace α] [IsLocallyFiniteMeasure μ] :
IsLocallyFiniteMeasure (ν.withDensity <| μ.rnDeriv ν) :=
isLocallyFiniteMeasure_of_le <| withDensity_rnDeriv_le μ ν
#align measure_theory.measure.with_density.measure_theory.is_locally_finite_measure MeasureTheory.Measure.withDensity.instIsLocallyFiniteMeasure
section RNDerivFinite
theorem lintegral_rnDeriv_lt_top_of_measure_ne_top (ν : Measure α) {s : Set α} (hs : μ s ≠ ∞) :
∫⁻ x in s, μ.rnDeriv ν x ∂ν < ∞ := by
by_cases hl : HaveLebesgueDecomposition μ ν
· suffices (∫⁻ x in toMeasurable μ s, μ.rnDeriv ν x ∂ν) < ∞ from
lt_of_le_of_lt (lintegral_mono_set (subset_toMeasurable _ _)) this
rw [← withDensity_apply _ (measurableSet_toMeasurable _ _)]
calc
_ ≤ (singularPart μ ν) (toMeasurable μ s) + _ := le_add_self
_ = μ s := by rw [← Measure.add_apply, ← haveLebesgueDecomposition_add, measure_toMeasurable]
_ < ⊤ := hs.lt_top
· simp only [Measure.rnDeriv, dif_neg hl, Pi.zero_apply, lintegral_zero, ENNReal.zero_lt_top]
#align measure_theory.measure.lintegral_rn_deriv_lt_top_of_measure_ne_top MeasureTheory.Measure.lintegral_rnDeriv_lt_top_of_measure_ne_top
theorem lintegral_rnDeriv_lt_top (μ ν : Measure α) [IsFiniteMeasure μ] :
∫⁻ x, μ.rnDeriv ν x ∂ν < ∞ := by
rw [← set_lintegral_univ]
exact lintegral_rnDeriv_lt_top_of_measure_ne_top _ (measure_lt_top _ _).ne
#align measure_theory.measure.lintegral_rn_deriv_lt_top MeasureTheory.Measure.lintegral_rnDeriv_lt_top
lemma integrable_toReal_rnDeriv [IsFiniteMeasure μ] :
Integrable (fun x ↦ (μ.rnDeriv ν x).toReal) ν :=
integrable_toReal_of_lintegral_ne_top (Measure.measurable_rnDeriv _ _).aemeasurable
(Measure.lintegral_rnDeriv_lt_top _ _).ne
/-- The Radon-Nikodym derivative of a sigma-finite measure `μ` with respect to another
measure `ν` is `ν`-almost everywhere finite. -/
theorem rnDeriv_lt_top (μ ν : Measure α) [SigmaFinite μ] : ∀ᵐ x ∂ν, μ.rnDeriv ν x < ∞ := by
suffices ∀ n, ∀ᵐ x ∂ν, x ∈ spanningSets μ n → μ.rnDeriv ν x < ∞ by
filter_upwards [ae_all_iff.2 this] with _ hx using hx _ (mem_spanningSetsIndex _ _)
intro n
rw [← ae_restrict_iff' (measurable_spanningSets _ _)]
apply ae_lt_top (measurable_rnDeriv _ _)
refine (lintegral_rnDeriv_lt_top_of_measure_ne_top _ ?_).ne
exact (measure_spanningSets_lt_top _ _).ne
#align measure_theory.measure.rn_deriv_lt_top MeasureTheory.Measure.rnDeriv_lt_top
lemma rnDeriv_ne_top (μ ν : Measure α) [SigmaFinite μ] : ∀ᵐ x ∂ν, μ.rnDeriv ν x ≠ ∞ := by
filter_upwards [Measure.rnDeriv_lt_top μ ν] with x hx using hx.ne
end RNDerivFinite
/-- Given measures `μ` and `ν`, if `s` is a measure mutually singular to `ν` and `f` is a
measurable function such that `μ = s + fν`, then `s = μ.singularPart μ`.
This theorem provides the uniqueness of the `singularPart` in the Lebesgue decomposition theorem,
while `MeasureTheory.Measure.eq_rnDeriv` provides the uniqueness of the
`rnDeriv`. -/
theorem eq_singularPart {s : Measure α} {f : α → ℝ≥0∞} (hf : Measurable f) (hs : s ⟂ₘ ν)
(hadd : μ = s + ν.withDensity f) : s = μ.singularPart ν := by
have : HaveLebesgueDecomposition μ ν := ⟨⟨⟨s, f⟩, hf, hs, hadd⟩⟩
obtain ⟨hmeas, hsing, hadd'⟩ := haveLebesgueDecomposition_spec μ ν
obtain ⟨⟨S, hS₁, hS₂, hS₃⟩, ⟨T, hT₁, hT₂, hT₃⟩⟩ := hs, hsing
rw [hadd'] at hadd
have hνinter : ν (S ∩ T)ᶜ = 0 := by
rw [compl_inter]
refine nonpos_iff_eq_zero.1 (le_trans (measure_union_le _ _) ?_)
rw [hT₃, hS₃, add_zero]
have heq : s.restrict (S ∩ T)ᶜ = (μ.singularPart ν).restrict (S ∩ T)ᶜ := by
ext1 A hA
have hf : ν.withDensity f (A ∩ (S ∩ T)ᶜ) = 0 := by
refine withDensity_absolutelyContinuous ν _ ?_
rw [← nonpos_iff_eq_zero]
exact hνinter ▸ measure_mono inter_subset_right
have hrn : ν.withDensity (μ.rnDeriv ν) (A ∩ (S ∩ T)ᶜ) = 0 := by
refine withDensity_absolutelyContinuous ν _ ?_
rw [← nonpos_iff_eq_zero]
exact hνinter ▸ measure_mono inter_subset_right
rw [restrict_apply hA, restrict_apply hA, ← add_zero (s (A ∩ (S ∩ T)ᶜ)), ← hf, ← add_apply, ←
hadd, add_apply, hrn, add_zero]
have heq' : ∀ A : Set α, MeasurableSet A → s A = s.restrict (S ∩ T)ᶜ A := by
intro A hA
have hsinter : s (A ∩ (S ∩ T)) = 0 := by
rw [← nonpos_iff_eq_zero]
exact hS₂ ▸ measure_mono (inter_subset_right.trans inter_subset_left)
rw [restrict_apply hA, ← diff_eq, AEDisjoint.measure_diff_left hsinter]
ext1 A hA
have hμinter : μ.singularPart ν (A ∩ (S ∩ T)) = 0 := by
rw [← nonpos_iff_eq_zero]
exact hT₂ ▸ measure_mono (inter_subset_right.trans inter_subset_right)
rw [heq' A hA, heq, restrict_apply hA, ← diff_eq, AEDisjoint.measure_diff_left hμinter]
#align measure_theory.measure.eq_singular_part MeasureTheory.Measure.eq_singularPart
theorem singularPart_smul (μ ν : Measure α) (r : ℝ≥0) :
(r • μ).singularPart ν = r • μ.singularPart ν := by
by_cases hr : r = 0
· rw [hr, zero_smul, zero_smul, singularPart_zero]
by_cases hl : HaveLebesgueDecomposition μ ν
· refine (eq_singularPart ((measurable_rnDeriv μ ν).const_smul (r : ℝ≥0∞))
(MutuallySingular.smul r (mutuallySingular_singularPart _ _)) ?_).symm
rw [withDensity_smul _ (measurable_rnDeriv _ _), ← smul_add,
← haveLebesgueDecomposition_add μ ν, ENNReal.smul_def]
· rw [singularPart, singularPart, dif_neg hl, dif_neg, smul_zero]
refine fun hl' ↦ hl ?_
rw [← inv_smul_smul₀ hr μ]
infer_instance
#align measure_theory.measure.singular_part_smul MeasureTheory.Measure.singularPart_smul
theorem singularPart_smul_right (μ ν : Measure α) (r : ℝ≥0) (hr : r ≠ 0) :
μ.singularPart (r • ν) = μ.singularPart ν := by
by_cases hl : HaveLebesgueDecomposition μ ν
· refine (eq_singularPart ((measurable_rnDeriv μ ν).const_smul r⁻¹) ?_ ?_).symm
· exact (mutuallySingular_singularPart μ ν).mono_ac AbsolutelyContinuous.rfl
smul_absolutelyContinuous
· rw [ENNReal.smul_def r, withDensity_smul_measure, ← withDensity_smul]
swap; · exact (measurable_rnDeriv _ _).const_smul _
convert haveLebesgueDecomposition_add μ ν
ext x
simp only [Pi.smul_apply]
rw [← ENNReal.smul_def, smul_inv_smul₀ hr]
· rw [singularPart, singularPart, dif_neg hl, dif_neg]
refine fun hl' ↦ hl ?_
rw [← inv_smul_smul₀ hr ν]
infer_instance
theorem singularPart_add (μ₁ μ₂ ν : Measure α) [HaveLebesgueDecomposition μ₁ ν]
[HaveLebesgueDecomposition μ₂ ν] :
(μ₁ + μ₂).singularPart ν = μ₁.singularPart ν + μ₂.singularPart ν := by
refine (eq_singularPart ((measurable_rnDeriv μ₁ ν).add (measurable_rnDeriv μ₂ ν))
((mutuallySingular_singularPart _ _).add_left (mutuallySingular_singularPart _ _)) ?_).symm
erw [withDensity_add_left (measurable_rnDeriv μ₁ ν)]
conv_rhs => rw [add_assoc, add_comm (μ₂.singularPart ν), ← add_assoc, ← add_assoc]
rw [← haveLebesgueDecomposition_add μ₁ ν, add_assoc, add_comm (ν.withDensity (μ₂.rnDeriv ν)),
← haveLebesgueDecomposition_add μ₂ ν]
#align measure_theory.measure.singular_part_add MeasureTheory.Measure.singularPart_add
lemma singularPart_restrict (μ ν : Measure α) [HaveLebesgueDecomposition μ ν]
{s : Set α} (hs : MeasurableSet s) :
(μ.restrict s).singularPart ν = (μ.singularPart ν).restrict s := by
refine (Measure.eq_singularPart (f := s.indicator (μ.rnDeriv ν)) ?_ ?_ ?_).symm
· exact (μ.measurable_rnDeriv ν).indicator hs
· exact (Measure.mutuallySingular_singularPart μ ν).restrict s
· ext t
rw [withDensity_indicator hs, ← restrict_withDensity hs, ← Measure.restrict_add,
← μ.haveLebesgueDecomposition_add ν]
/-- Given measures `μ` and `ν`, if `s` is a measure mutually singular to `ν` and `f` is a
measurable function such that `μ = s + fν`, then `f = μ.rnDeriv ν`.
This theorem provides the uniqueness of the `rnDeriv` in the Lebesgue decomposition
theorem, while `MeasureTheory.Measure.eq_singularPart` provides the uniqueness of the
`singularPart`. Here, the uniqueness is given in terms of the measures, while the uniqueness in
terms of the functions is given in `eq_rnDeriv`. -/
theorem eq_withDensity_rnDeriv {s : Measure α} {f : α → ℝ≥0∞} (hf : Measurable f) (hs : s ⟂ₘ ν)
(hadd : μ = s + ν.withDensity f) : ν.withDensity f = ν.withDensity (μ.rnDeriv ν) := by
have : HaveLebesgueDecomposition μ ν := ⟨⟨⟨s, f⟩, hf, hs, hadd⟩⟩
obtain ⟨hmeas, hsing, hadd'⟩ := haveLebesgueDecomposition_spec μ ν
obtain ⟨⟨S, hS₁, hS₂, hS₃⟩, ⟨T, hT₁, hT₂, hT₃⟩⟩ := hs, hsing
rw [hadd'] at hadd
have hνinter : ν (S ∩ T)ᶜ = 0 := by
rw [compl_inter]
refine nonpos_iff_eq_zero.1 (le_trans (measure_union_le _ _) ?_)
rw [hT₃, hS₃, add_zero]
have heq :
(ν.withDensity f).restrict (S ∩ T) = (ν.withDensity (μ.rnDeriv ν)).restrict (S ∩ T) := by
ext1 A hA
have hs : s (A ∩ (S ∩ T)) = 0 := by
rw [← nonpos_iff_eq_zero]
exact hS₂ ▸ measure_mono (inter_subset_right.trans inter_subset_left)
have hsing : μ.singularPart ν (A ∩ (S ∩ T)) = 0 := by
rw [← nonpos_iff_eq_zero]
exact hT₂ ▸ measure_mono (inter_subset_right.trans inter_subset_right)
rw [restrict_apply hA, restrict_apply hA, ← add_zero (ν.withDensity f (A ∩ (S ∩ T))), ← hs, ←
add_apply, add_comm, ← hadd, add_apply, hsing, zero_add]
have heq' :
∀ A : Set α, MeasurableSet A → ν.withDensity f A = (ν.withDensity f).restrict (S ∩ T) A := by
intro A hA
have hνfinter : ν.withDensity f (A ∩ (S ∩ T)ᶜ) = 0 := by
rw [← nonpos_iff_eq_zero]
exact withDensity_absolutelyContinuous ν f hνinter ▸ measure_mono inter_subset_right
rw [restrict_apply hA, ← add_zero (ν.withDensity f (A ∩ (S ∩ T))), ← hνfinter, ← diff_eq,
measure_inter_add_diff _ (hS₁.inter hT₁)]
ext1 A hA
have hνrn : ν.withDensity (μ.rnDeriv ν) (A ∩ (S ∩ T)ᶜ) = 0 := by
rw [← nonpos_iff_eq_zero]
exact
withDensity_absolutelyContinuous ν (μ.rnDeriv ν) hνinter ▸
measure_mono inter_subset_right
rw [heq' A hA, heq, ← add_zero ((ν.withDensity (μ.rnDeriv ν)).restrict (S ∩ T) A), ← hνrn,
restrict_apply hA, ← diff_eq, measure_inter_add_diff _ (hS₁.inter hT₁)]
#align measure_theory.measure.eq_with_density_rn_deriv MeasureTheory.Measure.eq_withDensity_rnDeriv
theorem eq_withDensity_rnDeriv₀ {s : Measure α} {f : α → ℝ≥0∞}
(hf : AEMeasurable f ν) (hs : s ⟂ₘ ν) (hadd : μ = s + ν.withDensity f) :
ν.withDensity f = ν.withDensity (μ.rnDeriv ν) := by
rw [withDensity_congr_ae hf.ae_eq_mk] at hadd ⊢
exact eq_withDensity_rnDeriv hf.measurable_mk hs hadd
theorem eq_rnDeriv₀ [SigmaFinite ν] {s : Measure α} {f : α → ℝ≥0∞}
(hf : AEMeasurable f ν) (hs : s ⟂ₘ ν) (hadd : μ = s + ν.withDensity f) :
f =ᵐ[ν] μ.rnDeriv ν :=
(withDensity_eq_iff_of_sigmaFinite hf (measurable_rnDeriv _ _).aemeasurable).mp
(eq_withDensity_rnDeriv₀ hf hs hadd)
/-- Given measures `μ` and `ν`, if `s` is a measure mutually singular to `ν` and `f` is a
measurable function such that `μ = s + fν`, then `f = μ.rnDeriv ν`.
This theorem provides the uniqueness of the `rnDeriv` in the Lebesgue decomposition
theorem, while `MeasureTheory.Measure.eq_singularPart` provides the uniqueness of the
`singularPart`. Here, the uniqueness is given in terms of the functions, while the uniqueness in
terms of the functions is given in `eq_withDensity_rnDeriv`. -/
theorem eq_rnDeriv [SigmaFinite ν] {s : Measure α} {f : α → ℝ≥0∞} (hf : Measurable f) (hs : s ⟂ₘ ν)
(hadd : μ = s + ν.withDensity f) : f =ᵐ[ν] μ.rnDeriv ν :=
eq_rnDeriv₀ hf.aemeasurable hs hadd
#align measure_theory.measure.eq_rn_deriv MeasureTheory.Measure.eq_rnDeriv
/-- The Radon-Nikodym derivative of `f ν` with respect to `ν` is `f`. -/
theorem rnDeriv_withDensity₀ (ν : Measure α) [SigmaFinite ν] {f : α → ℝ≥0∞}
(hf : AEMeasurable f ν) :
(ν.withDensity f).rnDeriv ν =ᵐ[ν] f :=
have : ν.withDensity f = 0 + ν.withDensity f := by rw [zero_add]
(eq_rnDeriv₀ hf MutuallySingular.zero_left this).symm
/-- The Radon-Nikodym derivative of `f ν` with respect to `ν` is `f`. -/
theorem rnDeriv_withDensity (ν : Measure α) [SigmaFinite ν] {f : α → ℝ≥0∞} (hf : Measurable f) :
(ν.withDensity f).rnDeriv ν =ᵐ[ν] f :=
rnDeriv_withDensity₀ ν hf.aemeasurable
#align measure_theory.measure.rn_deriv_with_density MeasureTheory.Measure.rnDeriv_withDensity
lemma rnDeriv_restrict (μ ν : Measure α) [HaveLebesgueDecomposition μ ν] [SigmaFinite ν]
{s : Set α} (hs : MeasurableSet s) :
(μ.restrict s).rnDeriv ν =ᵐ[ν] s.indicator (μ.rnDeriv ν) := by
refine (eq_rnDeriv (s := (μ.restrict s).singularPart ν)
((measurable_rnDeriv _ _).indicator hs) (mutuallySingular_singularPart _ _) ?_).symm
rw [singularPart_restrict _ _ hs, withDensity_indicator hs, ← restrict_withDensity hs,
← Measure.restrict_add, ← μ.haveLebesgueDecomposition_add ν]
/-- The Radon-Nikodym derivative of the restriction of a measure to a measurable set is the
indicator function of this set. -/
theorem rnDeriv_restrict_self (ν : Measure α) [SigmaFinite ν] {s : Set α} (hs : MeasurableSet s) :
(ν.restrict s).rnDeriv ν =ᵐ[ν] s.indicator 1 := by
rw [← withDensity_indicator_one hs]
exact rnDeriv_withDensity _ (measurable_one.indicator hs)
#align measure_theory.measure.rn_deriv_restrict MeasureTheory.Measure.rnDeriv_restrict_self
/-- Radon-Nikodym derivative of the scalar multiple of a measure.
See also `rnDeriv_smul_left'`, which requires sigma-finite `ν` and `μ`. -/
theorem rnDeriv_smul_left (ν μ : Measure α) [IsFiniteMeasure ν]
[ν.HaveLebesgueDecomposition μ] (r : ℝ≥0) :
(r • ν).rnDeriv μ =ᵐ[μ] r • ν.rnDeriv μ := by
rw [← withDensity_eq_iff]
· simp_rw [ENNReal.smul_def]
rw [withDensity_smul _ (measurable_rnDeriv _ _)]
suffices (r • ν).singularPart μ + withDensity μ (rnDeriv (r • ν) μ)
= (r • ν).singularPart μ + r • withDensity μ (rnDeriv ν μ) by
rwa [Measure.add_right_inj] at this
rw [← (r • ν).haveLebesgueDecomposition_add μ, singularPart_smul, ← smul_add,
← ν.haveLebesgueDecomposition_add μ]
· exact (measurable_rnDeriv _ _).aemeasurable
· exact (measurable_rnDeriv _ _).aemeasurable.const_smul _
· exact (lintegral_rnDeriv_lt_top (r • ν) μ).ne
/-- Radon-Nikodym derivative of the scalar multiple of a measure.
See also `rnDeriv_smul_left_of_ne_top'`, which requires sigma-finite `ν` and `μ`. -/
theorem rnDeriv_smul_left_of_ne_top (ν μ : Measure α) [IsFiniteMeasure ν]
[ν.HaveLebesgueDecomposition μ] {r : ℝ≥0∞} (hr : r ≠ ∞) :
(r • ν).rnDeriv μ =ᵐ[μ] r • ν.rnDeriv μ := by
have h : (r.toNNReal • ν).rnDeriv μ =ᵐ[μ] r.toNNReal • ν.rnDeriv μ :=
rnDeriv_smul_left ν μ r.toNNReal
simpa [ENNReal.smul_def, ENNReal.coe_toNNReal hr] using h
/-- Radon-Nikodym derivative with respect to the scalar multiple of a measure.
See also `rnDeriv_smul_right'`, which requires sigma-finite `ν` and `μ`. -/
theorem rnDeriv_smul_right (ν μ : Measure α) [IsFiniteMeasure ν]
[ν.HaveLebesgueDecomposition μ] {r : ℝ≥0} (hr : r ≠ 0) :
ν.rnDeriv (r • μ) =ᵐ[μ] r⁻¹ • ν.rnDeriv μ := by
refine (absolutelyContinuous_smul <| ENNReal.coe_ne_zero.2 hr).ae_le
(?_ : ν.rnDeriv (r • μ) =ᵐ[r • μ] r⁻¹ • ν.rnDeriv μ)
rw [← withDensity_eq_iff]
rotate_left
· exact (measurable_rnDeriv _ _).aemeasurable
· exact (measurable_rnDeriv _ _).aemeasurable.const_smul _
· exact (lintegral_rnDeriv_lt_top ν _).ne
· simp_rw [ENNReal.smul_def]
rw [withDensity_smul _ (measurable_rnDeriv _ _)]
suffices ν.singularPart (r • μ) + withDensity (r • μ) (rnDeriv ν (r • μ))
= ν.singularPart (r • μ) + r⁻¹ • withDensity (r • μ) (rnDeriv ν μ) by
rwa [add_right_inj] at this
rw [← ν.haveLebesgueDecomposition_add (r • μ), singularPart_smul_right _ _ _ hr,
ENNReal.smul_def r, withDensity_smul_measure, ← ENNReal.smul_def, ← smul_assoc,
smul_eq_mul, inv_mul_cancel hr, one_smul]
exact ν.haveLebesgueDecomposition_add μ
/-- Radon-Nikodym derivative with respect to the scalar multiple of a measure.
See also `rnDeriv_smul_right_of_ne_top'`, which requires sigma-finite `ν` and `μ`. -/
theorem rnDeriv_smul_right_of_ne_top (ν μ : Measure α) [IsFiniteMeasure ν]
[ν.HaveLebesgueDecomposition μ] {r : ℝ≥0∞} (hr : r ≠ 0) (hr_ne_top : r ≠ ∞) :
ν.rnDeriv (r • μ) =ᵐ[μ] r⁻¹ • ν.rnDeriv μ := by
have h : ν.rnDeriv (r.toNNReal • μ) =ᵐ[μ] r.toNNReal⁻¹ • ν.rnDeriv μ := by
refine rnDeriv_smul_right ν μ ?_
rw [ne_eq, ENNReal.toNNReal_eq_zero_iff]
simp [hr, hr_ne_top]
have : (r.toNNReal)⁻¹ • rnDeriv ν μ = r⁻¹ • rnDeriv ν μ := by
ext x
simp only [Pi.smul_apply, ENNReal.smul_def, ne_eq, smul_eq_mul]
rw [ENNReal.coe_inv, ENNReal.coe_toNNReal hr_ne_top]
rw [ne_eq, ENNReal.toNNReal_eq_zero_iff]
simp [hr, hr_ne_top]
simp_rw [this, ENNReal.smul_def, ENNReal.coe_toNNReal hr_ne_top] at h
exact h
/-- Radon-Nikodym derivative of a sum of two measures.
See also `rnDeriv_add'`, which requires sigma-finite `ν₁`, `ν₂` and `μ`. -/
lemma rnDeriv_add (ν₁ ν₂ μ : Measure α) [IsFiniteMeasure ν₁] [IsFiniteMeasure ν₂]
[ν₁.HaveLebesgueDecomposition μ] [ν₂.HaveLebesgueDecomposition μ]
[(ν₁ + ν₂).HaveLebesgueDecomposition μ] :
(ν₁ + ν₂).rnDeriv μ =ᵐ[μ] ν₁.rnDeriv μ + ν₂.rnDeriv μ := by
rw [← withDensity_eq_iff]
· suffices (ν₁ + ν₂).singularPart μ + μ.withDensity ((ν₁ + ν₂).rnDeriv μ)
= (ν₁ + ν₂).singularPart μ + μ.withDensity (ν₁.rnDeriv μ + ν₂.rnDeriv μ) by
rwa [add_right_inj] at this
rw [← (ν₁ + ν₂).haveLebesgueDecomposition_add μ, singularPart_add,
withDensity_add_left (measurable_rnDeriv _ _), add_assoc,
add_comm (ν₂.singularPart μ), add_assoc, add_comm _ (ν₂.singularPart μ),
← ν₂.haveLebesgueDecomposition_add μ, ← add_assoc, ← ν₁.haveLebesgueDecomposition_add μ]
· exact (measurable_rnDeriv _ _).aemeasurable
· exact ((measurable_rnDeriv _ _).add (measurable_rnDeriv _ _)).aemeasurable
· exact (lintegral_rnDeriv_lt_top (ν₁ + ν₂) μ).ne
open VectorMeasure SignedMeasure
/-- If two finite measures `μ` and `ν` are not mutually singular, there exists some `ε > 0` and
a measurable set `E`, such that `ν(E) > 0` and `E` is positive with respect to `μ - εν`.
This lemma is useful for the Lebesgue decomposition theorem. -/
theorem exists_positive_of_not_mutuallySingular (μ ν : Measure α) [IsFiniteMeasure μ]
[IsFiniteMeasure ν] (h : ¬μ ⟂ₘ ν) :
∃ ε : ℝ≥0, 0 < ε ∧
∃ E : Set α,
MeasurableSet E ∧ 0 < ν E ∧ 0 ≤[E] μ.toSignedMeasure - (ε • ν).toSignedMeasure := by
-- for all `n : ℕ`, obtain the Hahn decomposition for `μ - (1 / n) ν`
have :
∀ n : ℕ, ∃ i : Set α,
MeasurableSet i ∧
0 ≤[i] μ.toSignedMeasure - ((1 / (n + 1) : ℝ≥0) • ν).toSignedMeasure ∧
μ.toSignedMeasure - ((1 / (n + 1) : ℝ≥0) • ν).toSignedMeasure ≤[iᶜ] 0 := by
intro; exact exists_compl_positive_negative _
choose f hf₁ hf₂ hf₃ using this
-- set `A` to be the intersection of all the negative parts of obtained Hahn decompositions
-- and we show that `μ A = 0`
let A := ⋂ n, (f n)ᶜ
have hAmeas : MeasurableSet A := MeasurableSet.iInter fun n ↦ (hf₁ n).compl
have hA₂ : ∀ n : ℕ, μ.toSignedMeasure - ((1 / (n + 1) : ℝ≥0) • ν).toSignedMeasure ≤[A] 0 := by
intro n; exact restrict_le_restrict_subset _ _ (hf₁ n).compl (hf₃ n) (iInter_subset _ _)
have hA₃ : ∀ n : ℕ, μ A ≤ (1 / (n + 1) : ℝ≥0) * ν A := by
intro n
have := nonpos_of_restrict_le_zero _ (hA₂ n)
rwa [toSignedMeasure_sub_apply hAmeas, sub_nonpos, ENNReal.toReal_le_toReal] at this
exacts [measure_ne_top _ _, measure_ne_top _ _]
have hμ : μ A = 0 := by
lift μ A to ℝ≥0 using measure_ne_top _ _ with μA
lift ν A to ℝ≥0 using measure_ne_top _ _ with νA
rw [ENNReal.coe_eq_zero]
by_cases hb : 0 < νA
· suffices ∀ b, 0 < b → μA ≤ b by
by_contra h
have h' := this (μA / 2) (half_pos (zero_lt_iff.2 h))
rw [← @Classical.not_not (μA ≤ μA / 2)] at h'
exact h' (not_le.2 (NNReal.half_lt_self h))
intro c hc
have : ∃ n : ℕ, 1 / (n + 1 : ℝ) < c * (νA : ℝ)⁻¹ := by
refine exists_nat_one_div_lt ?_
positivity
rcases this with ⟨n, hn⟩
have hb₁ : (0 : ℝ) < (νA : ℝ)⁻¹ := by rw [_root_.inv_pos]; exact hb
have h' : 1 / (↑n + 1) * νA < c := by
rw [← NNReal.coe_lt_coe, ← mul_lt_mul_right hb₁, NNReal.coe_mul, mul_assoc, ←
NNReal.coe_inv, ← NNReal.coe_mul, _root_.mul_inv_cancel, ← NNReal.coe_mul, mul_one,
NNReal.coe_inv]
· exact hn
· exact hb.ne'
refine le_trans ?_ h'.le
rw [← ENNReal.coe_le_coe, ENNReal.coe_mul]
exact hA₃ n
· rw [not_lt, le_zero_iff] at hb
specialize hA₃ 0
simp? [hb] at hA₃ says
simp only [CharP.cast_eq_zero, zero_add, ne_eq, one_ne_zero, not_false_eq_true, div_self,
ENNReal.coe_one, hb, ENNReal.coe_zero, mul_zero, nonpos_iff_eq_zero,
ENNReal.coe_eq_zero] at hA₃
assumption
-- since `μ` and `ν` are not mutually singular, `μ A = 0` implies `ν Aᶜ > 0`
rw [MutuallySingular] at h; push_neg at h
have := h _ hAmeas hμ
simp_rw [A, compl_iInter, compl_compl] at this
-- as `Aᶜ = ⋃ n, f n`, `ν Aᶜ > 0` implies there exists some `n` such that `ν (f n) > 0`
obtain ⟨n, hn⟩ := exists_measure_pos_of_not_measure_iUnion_null this
-- thus, choosing `f n` as the set `E` suffices
exact ⟨1 / (n + 1), by simp, f n, hf₁ n, hn, hf₂ n⟩
#align measure_theory.measure.exists_positive_of_not_mutually_singular MeasureTheory.Measure.exists_positive_of_not_mutuallySingular
namespace LebesgueDecomposition
/-- Given two measures `μ` and `ν`, `measurableLE μ ν` is the set of measurable
functions `f`, such that, for all measurable sets `A`, `∫⁻ x in A, f x ∂μ ≤ ν A`.
This is useful for the Lebesgue decomposition theorem. -/
def measurableLE (μ ν : Measure α) : Set (α → ℝ≥0∞) :=
{f | Measurable f ∧ ∀ (A : Set α), MeasurableSet A → (∫⁻ x in A, f x ∂μ) ≤ ν A}
#align measure_theory.measure.lebesgue_decomposition.measurable_le MeasureTheory.Measure.LebesgueDecomposition.measurableLE
theorem zero_mem_measurableLE : (0 : α → ℝ≥0∞) ∈ measurableLE μ ν :=
⟨measurable_zero, fun A _ ↦ by simp⟩
#align measure_theory.measure.lebesgue_decomposition.zero_mem_measurable_le MeasureTheory.Measure.LebesgueDecomposition.zero_mem_measurableLE
theorem sup_mem_measurableLE {f g : α → ℝ≥0∞} (hf : f ∈ measurableLE μ ν)
(hg : g ∈ measurableLE μ ν) : (fun a ↦ f a ⊔ g a) ∈ measurableLE μ ν := by
simp_rw [ENNReal.sup_eq_max]
refine ⟨Measurable.max hf.1 hg.1, fun A hA ↦ ?_⟩
have h₁ := hA.inter (measurableSet_le hf.1 hg.1)
have h₂ := hA.inter (measurableSet_lt hg.1 hf.1)
rw [set_lintegral_max hf.1 hg.1]
refine (add_le_add (hg.2 _ h₁) (hf.2 _ h₂)).trans_eq ?_
simp only [← not_le, ← compl_setOf, ← diff_eq]
exact measure_inter_add_diff _ (measurableSet_le hf.1 hg.1)
#align measure_theory.measure.lebesgue_decomposition.sup_mem_measurable_le MeasureTheory.Measure.LebesgueDecomposition.sup_mem_measurableLE
theorem iSup_succ_eq_sup {α} (f : ℕ → α → ℝ≥0∞) (m : ℕ) (a : α) :
⨆ (k : ℕ) (_ : k ≤ m + 1), f k a = f m.succ a ⊔ ⨆ (k : ℕ) (_ : k ≤ m), f k a := by
set c := ⨆ (k : ℕ) (_ : k ≤ m + 1), f k a with hc
set d := f m.succ a ⊔ ⨆ (k : ℕ) (_ : k ≤ m), f k a with hd
rw [le_antisymm_iff, hc, hd]
constructor
· refine iSup₂_le fun n hn ↦ ?_
rcases Nat.of_le_succ hn with (h | h)
· exact le_sup_of_le_right (le_iSup₂ (f := fun k (_ : k ≤ m) ↦ f k a) n h)
· exact h ▸ le_sup_left
· refine sup_le ?_ (biSup_mono fun n hn ↦ hn.trans m.le_succ)
exact @le_iSup₂ ℝ≥0∞ ℕ (fun i ↦ i ≤ m + 1) _ _ (m + 1) le_rfl
#align measure_theory.measure.lebesgue_decomposition.supr_succ_eq_sup MeasureTheory.Measure.LebesgueDecomposition.iSup_succ_eq_sup
| Mathlib/MeasureTheory/Decomposition/Lebesgue.lean | 778 | 789 | theorem iSup_mem_measurableLE (f : ℕ → α → ℝ≥0∞) (hf : ∀ n, f n ∈ measurableLE μ ν) (n : ℕ) :
(fun x ↦ ⨆ (k) (_ : k ≤ n), f k x) ∈ measurableLE μ ν := by |
induction' n with m hm
· constructor
· simp [(hf 0).1]
· intro A hA; simp [(hf 0).2 A hA]
· have :
(fun a : α ↦ ⨆ (k : ℕ) (_ : k ≤ m + 1), f k a) = fun a ↦
f m.succ a ⊔ ⨆ (k : ℕ) (_ : k ≤ m), f k a :=
funext fun _ ↦ iSup_succ_eq_sup _ _ _
refine ⟨measurable_iSup fun n ↦ Measurable.iSup_Prop _ (hf n).1, fun A hA ↦ ?_⟩
rw [this]; exact (sup_mem_measurableLE (hf m.succ) hm).2 A hA
|
/-
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 -/
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'
#align list.last_reverse List.getLast_reverse
#noalign list.ilast'_mem --List.ilast'_mem
@[simp]
theorem get_attach (L : List α) (i) :
(L.attach.get i).1 = L.get ⟨i, length_attach L ▸ i.2⟩ :=
calc
(L.attach.get i).1 = (L.attach.map Subtype.val).get ⟨i, by simpa using i.2⟩ := by
rw [get_map]
_ = L.get { val := i, isLt := _ } := by congr 2 <;> simp
#align list.nth_le_attach List.get_attach
@[simp 1100]
theorem mem_map_swap (x : α) (y : β) (xs : List (α × β)) :
(y, x) ∈ map Prod.swap xs ↔ (x, y) ∈ xs := by
induction' xs with x xs xs_ih
· simp only [not_mem_nil, map_nil]
· cases' x with a b
simp only [mem_cons, Prod.mk.inj_iff, map, Prod.swap_prod_mk, Prod.exists, xs_ih, and_comm]
#align list.mem_map_swap List.mem_map_swap
theorem dropSlice_eq (xs : List α) (n m : ℕ) : dropSlice n m xs = xs.take n ++ xs.drop (n + m) := by
induction n generalizing xs
· cases xs <;> simp [dropSlice]
· cases xs <;> simp [dropSlice, *, Nat.succ_add]
#align list.slice_eq List.dropSlice_eq
| Mathlib/Data/List/Basic.lean | 3,577 | 3,590 | theorem sizeOf_dropSlice_lt [SizeOf α] (i j : ℕ) (hj : 0 < j) (xs : List α) (hi : i < xs.length) :
SizeOf.sizeOf (List.dropSlice i j xs) < SizeOf.sizeOf xs := by |
induction xs generalizing i j hj with
| nil => cases hi
| cons x xs xs_ih =>
cases i <;> simp only [List.dropSlice]
· cases j with
| zero => contradiction
| succ n =>
dsimp only [drop]; apply lt_of_le_of_lt (drop_sizeOf_le xs n)
simp only [cons.sizeOf_spec]; omega
· simp only [cons.sizeOf_spec, Nat.add_lt_add_iff_left]
apply xs_ih _ j hj
apply lt_of_succ_lt_succ hi
|
/-
Copyright (c) 2024 Mitchell Lee. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mitchell Lee
-/
import Mathlib.LinearAlgebra.TensorProduct.RightExactness
import Mathlib.LinearAlgebra.TensorProduct.Finiteness
/-! # Vanishing of elements in a tensor product of two modules
Let $M$ and $N$ be modules over a commutative ring $R$. Recall that every element of $M \otimes N$
can be written as a finite sum $\sum_{i} m_i \otimes n_i$ of pure tensors
(`TensorProduct.exists_finset`). We would like to determine under what circumstances such an
expression vanishes.
Let us say that an expression $\sum_{i \in \iota} m_i \otimes n_i$ in $M \otimes N$
*vanishes trivially* (`TensorProduct.VanishesTrivially`) if there exist a finite index type
$\kappa$, elements $(y_j)_{j \in \kappa}$ of $N$, and elements
$(a_{ij})_{i \in \iota, j \in \kappa}$ of $R$ such that for all $i$,
$$n_i = \sum_j a_{ij} y_j$$
and for all $j$,
$$\sum_{i} a_{ij} m_i = 0.$$
(The terminology "trivial" comes from [Stacks 00HK](https://stacks.math.columbia.edu/tag/00HK).)
It is not difficult to show (`TensorProduct.sum_tmul_eq_zero_of_vanishesTrivially`) that if
$\sum_i m_i \otimes n_i$ vanishes trivially, then it vanishes; that is,
$\sum_i m_i \otimes n_i = 0$.
The *equational criterion for vanishing* (`TensorProduct.vanishesTrivially_iff_sum_tmul_eq_zero`),
which appears as
[A. Altman and S. Kleiman, *A term of commutative algebra* (Lemma 8.16)][altman2021term],
states that if the elements $m_i$ generate the module $M$, then $\sum_i m_i \otimes n_i = 0$ if and
only if the expression $\sum_i m_i \otimes n_i$ vanishes trivially.
We also prove the following generalization
(`TensorProduct.vanishesTrivially_iff_sum_tmul_eq_zero_of_rTensor_injective`). If the submodule
$M' \subseteq M$ generated by the $m_i$ satisfies the property that the induced map
$M' \otimes N \to M \otimes N$ is injective, then $\sum_i m_i \otimes n_i = 0$ if and only if the
expression $\sum_i m_i \otimes n_i$ vanishes trivially. (In the case that $M = R$, this yields the
*equational criterion for flatness* `Module.Flat.iff_forall_isTrivialRelation`.)
Conversely (`TensorProduct.rTensor_injective_of_forall_vanishesTrivially`),
suppose that for every equation $\sum_i m_i \otimes n_i = 0$, the expression
$\sum_i m_i \otimes n_i$ vanishes trivially. Then the induced map $M' \otimes N \to M \otimes N$
is injective for every submodule $M' \subseteq M$.
## References
* [A. Altman and S. Kleiman, *A term of commutative algebra* (Lemma 8.16)][altman2021term]
## TODO
* Prove the same theorems with $M$ and $N$ swapped.
* Prove the same theorems with universe polymorphism.
-/
universe u
variable (R : Type u) [CommRing R]
variable {M : Type u} [AddCommGroup M] [Module R M]
variable {N : Type u} [AddCommGroup N] [Module R N]
open Classical DirectSum LinearMap Function Submodule
namespace TensorProduct
variable {ι : Type u} [Fintype ι] {m : ι → M} {n : ι → N}
variable (m n) in
/-- An expression $\sum_i m_i \otimes n_i$ in $M \otimes N$
*vanishes trivially* if there exist a finite index type $\kappa$,
elements $(y_j)_{j \in \kappa}$ of $N$, and elements $(a_{ij})_{i \in \iota, j \in \kappa}$ of $R$
such that for all $i$,
$$n_i = \sum_j a_{ij} y_j$$
and for all $j$,
$$\sum_{i} a_{ij} m_i = 0.$$
Note that this condition is not symmetric in $M$ and $N$.
(The terminology "trivial" comes from [Stacks 00HK](https://stacks.math.columbia.edu/tag/00HK).)-/
abbrev VanishesTrivially : Prop :=
∃ (κ : Type u) (_ : Fintype κ) (a : ι → κ → R) (y : κ → N),
(∀ i, n i = ∑ j, a i j • y j) ∧ ∀ j, ∑ i, a i j • m i = 0
/-- **Equational criterion for vanishing**
[A. Altman and S. Kleiman, *A term of commutative algebra* (Lemma 8.16)][altman2021term],
backward direction.
If the expression $\sum_i m_i \otimes n_i$ vanishes trivially, then it vanishes.
That is, $\sum_i m_i \otimes n_i = 0$. -/
theorem sum_tmul_eq_zero_of_vanishesTrivially (hmn : VanishesTrivially R m n) :
∑ i, m i ⊗ₜ n i = (0 : M ⊗[R] N) := by
obtain ⟨κ, _, a, y, h₁, h₂⟩ := hmn
simp_rw [h₁, tmul_sum, tmul_smul]
rw [Finset.sum_comm]
simp_rw [← tmul_smul, ← smul_tmul, ← sum_tmul, h₂, zero_tmul, Finset.sum_const_zero]
/-- **Equational criterion for vanishing**
[A. Altman and S. Kleiman, *A term of commutative algebra* (Lemma 8.16)][altman2021term],
forward direction.
Assume that the $m_i$ generate $M$. If the expression $\sum_i m_i \otimes n_i$
vanishes, then it vanishes trivially. -/
theorem vanishesTrivially_of_sum_tmul_eq_zero (hm : Submodule.span R (Set.range m) = ⊤)
(hmn : ∑ i, m i ⊗ₜ n i = (0 : M ⊗[R] N)) : VanishesTrivially R m n := by
-- Define a map $G \colon R^\iota \to M$ whose matrix entries are the $m_i$. It is surjective.
set G : (ι →₀ R) →ₗ[R] M := Finsupp.total ι M R m with hG
have G_basis_eq (i : ι) : G (Finsupp.single i 1) = m i := by simp [hG, toModule_lof]
have G_surjective : Surjective G := by
apply LinearMap.range_eq_top.mp
apply top_le_iff.mp
rw [← hm]
apply Submodule.span_le.mpr
rintro _ ⟨i, rfl⟩
use Finsupp.single i 1, G_basis_eq i
/- Consider the element $\sum_i e_i \otimes n_i$ of $R^\iota \otimes N$. It is in the kernel of
$R^\iota \otimes N \to M \otimes N$. -/
set en : (ι →₀ R) ⊗[R] N := ∑ i, Finsupp.single i 1 ⊗ₜ n i with hen
have en_mem_ker : en ∈ ker (rTensor N G) := by simp [hen, G_basis_eq, hmn]
-- We have an exact sequence $\ker G \to R^\iota \to M \to 0$.
have exact_ker_subtype : Exact (ker G).subtype G := G.exact_subtype_ker_map
-- Tensor the exact sequence with $N$.
have exact_rTensor_ker_subtype : Exact (rTensor N (ker G).subtype) (rTensor N G) :=
rTensor_exact (M := ↥(ker G)) N exact_ker_subtype G_surjective
/- We conclude that $\sum_i e_i \otimes n_i$ is in the range of
$\ker G \otimes N \to R^\iota \otimes N$. -/
have en_mem_range : en ∈ range (rTensor N (ker G).subtype) :=
exact_rTensor_ker_subtype.linearMap_ker_eq ▸ en_mem_ker
/- There is an element of in $\ker G \otimes N$ that maps to $\sum_i e_i \otimes n_i$.
Write it as a finite sum of pure tensors. -/
obtain ⟨kn, hkn⟩ := en_mem_range
obtain ⟨ma, rfl : kn = ∑ kj ∈ ma, kj.1 ⊗ₜ[R] kj.2⟩ := exists_finset kn
use ↑↑ma, FinsetCoe.fintype ma
/- Let $\sum_j k_j \otimes y_j$ be the sum obtained in the previous step.
In order to show that $\sum_i m_i \otimes n_i$ vanishes trivially, it suffices to prove that there
exist $(a_{ij})_{i, j}$ such that for all $i$,
$$n_i = \sum_j a_{ij} y_j$$
and for all $j$,
$$\sum_{i} a_{ij} m_i = 0.$$
For this, take $a_{ij}$ to be the coefficient of $e_i$ in $k_j$. -/
use fun i ⟨⟨kj, _⟩, _⟩ ↦ (kj : ι →₀ R) i
use fun ⟨⟨_, yj⟩, _⟩ ↦ yj
constructor
· intro i
apply_fun finsuppScalarLeft R N ι at hkn
apply_fun (· i) at hkn
symm at hkn
simp only [map_sum, finsuppScalarLeft_apply_tmul, zero_smul, Finsupp.single_zero,
Finsupp.sum_single_index, one_smul, Finsupp.finset_sum_apply, Finsupp.single_apply,
Finset.sum_ite_eq', Finset.mem_univ, ↓reduceIte, rTensor_tmul, coeSubtype, Finsupp.sum_apply,
Finsupp.sum_ite_eq', Finsupp.mem_support_iff, ne_eq, ite_not, en] at hkn
simp only [Finset.univ_eq_attach, Finset.sum_attach ma (fun x ↦ (x.1 : ι →₀ R) i • x.2)]
convert hkn using 2 with x _
split
· next h'x => rw [h'x, zero_smul]
· rfl
· rintro ⟨⟨⟨k, hk⟩, _⟩, _⟩
simpa only [hG, Finsupp.total_apply, zero_smul, implies_true, Finsupp.sum_fintype] using
mem_ker.mp hk
/-- **Equational criterion for vanishing**
[A. Altman and S. Kleiman, *A term of commutative algebra* (Lemma 8.16)][altman2021term].
Assume that the $m_i$ generate $M$. Then the expression $\sum_i m_i \otimes n_i$ vanishes
trivially if and only if it vanishes. -/
theorem vanishesTrivially_iff_sum_tmul_eq_zero (hm : Submodule.span R (Set.range m) = ⊤) :
VanishesTrivially R m n ↔ ∑ i, m i ⊗ₜ n i = (0 : M ⊗[R] N) :=
⟨sum_tmul_eq_zero_of_vanishesTrivially R, vanishesTrivially_of_sum_tmul_eq_zero R hm⟩
/-- **Equational criterion for vanishing**
[A. Altman and S. Kleiman, *A term of commutative algebra* (Lemma 8.16)][altman2021term],
forward direction, generalization.
Assume that the submodule $M' \subseteq M$ generated by the $m_i$
satisfies the property that the map $M' \otimes N \to M \otimes N$ is injective. If the expression
$\sum_i m_i \otimes n_i$ vanishes, then it vanishes trivially. -/
theorem vanishesTrivially_of_sum_tmul_eq_zero_of_rTensor_injective
(hm : Injective (rTensor N (span R (Set.range m)).subtype))
(hmn : ∑ i, m i ⊗ₜ n i = (0 : M ⊗[R] N)) : VanishesTrivially R m n := by
-- Restrict `m` on the codomain to $M'$, then apply `vanishesTrivially_of_sum_tmul_eq_zero`.
have mem_M' i : m i ∈ span R (Set.range m) := subset_span ⟨i, rfl⟩
set m' : ι → span R (Set.range m) := Subtype.coind m mem_M' with m'_eq
have hm' : span R (Set.range m') = ⊤ := by
apply map_injective_of_injective (injective_subtype (span R (Set.range m)))
rw [Submodule.map_span, Submodule.map_top, range_subtype, coeSubtype, ← Set.range_comp]
rfl
have hm'n : ∑ i, m' i ⊗ₜ n i = (0 : span R (Set.range m) ⊗[R] N) := by
apply hm
simp only [m'_eq, map_sum, rTensor_tmul, coeSubtype, Subtype.coind_coe, _root_.map_zero, hmn]
have : VanishesTrivially R m' n := vanishesTrivially_of_sum_tmul_eq_zero R hm' hm'n
unfold VanishesTrivially at this ⊢
convert this with κ _ a y j
convert (injective_iff_map_eq_zero' _).mp (injective_subtype (span R (Set.range m))) _
simp [m'_eq]
/-- **Equational criterion for vanishing**
[A. Altman and S. Kleiman, *A term of commutative algebra* (Lemma 8.16)][altman2021term],
generalization.
Assume that the submodule $M' \subseteq M$ generated by the $m_i$ satisfies the
property that the map $M' \otimes N \to M \otimes N$ is injective. Then the expression
$\sum_i m_i \otimes n_i$ vanishes trivially if and only if it vanishes. -/
theorem vanishesTrivially_iff_sum_tmul_eq_zero_of_rTensor_injective
(hm : Injective (rTensor N (span R (Set.range m)).subtype)) :
VanishesTrivially R m n ↔ ∑ i, m i ⊗ₜ n i = (0 : M ⊗[R] N) :=
⟨sum_tmul_eq_zero_of_vanishesTrivially R,
vanishesTrivially_of_sum_tmul_eq_zero_of_rTensor_injective R hm⟩
/-- Converse of `TensorProduct.vanishesTrivially_of_sum_tmul_eq_zero_of_rTensor_injective`.
Assume that every expression $\sum_i m_i \otimes n_i$ which vanishes also vanishes trivially.
Then, for every submodule $M' \subseteq M$, the map $M' \otimes N \to M \otimes N$ is injective. -/
theorem rTensor_injective_of_forall_vanishesTrivially
(hMN : ∀ {ι : Type u} [Fintype ι] {m : ι → M} {n : ι → N},
∑ i, m i ⊗ₜ n i = (0 : M ⊗[R] N) → VanishesTrivially R m n)
(M' : Submodule R M) : Injective (rTensor N M'.subtype) := by
apply (injective_iff_map_eq_zero _).mpr
rintro x hx
obtain ⟨s, rfl⟩ := exists_finset x
rw [← Finset.sum_attach]
apply sum_tmul_eq_zero_of_vanishesTrivially
simp only [map_sum, rTensor_tmul, coeSubtype] at hx
have := hMN ((Finset.sum_attach s _).trans hx)
unfold VanishesTrivially at this ⊢
convert this with κ _ a y j
symm
convert (injective_iff_map_eq_zero' _).mp (injective_subtype M') _
simp
/-- Every expression $\sum_i m_i \otimes n_i$ which vanishes also vanishes trivially if and only if
for every submodule $M' \subseteq M$, the map $M' \otimes N \to M \otimes N$ is injective. -/
theorem forall_vanishesTrivially_iff_forall_rTensor_injective :
(∀ {ι : Type u} [Fintype ι] {m : ι → M} {n : ι → N},
∑ i, m i ⊗ₜ n i = (0 : M ⊗[R] N) → VanishesTrivially R m n) ↔
∀ M' : Submodule R M, Injective (rTensor N M'.subtype) := by
constructor
· intro h
exact rTensor_injective_of_forall_vanishesTrivially R h
· intro h ι _ m n hmn
exact vanishesTrivially_of_sum_tmul_eq_zero_of_rTensor_injective R (h _) hmn
/-- Every expression $\sum_i m_i \otimes n_i$ which vanishes also vanishes trivially if and only if
for every finitely generated submodule $M' \subseteq M$, the map $M' \otimes N \to M \otimes N$ is
injective. -/
| Mathlib/LinearAlgebra/TensorProduct/Vanishing.lean | 243 | 252 | theorem forall_vanishesTrivially_iff_forall_FG_rTensor_injective :
(∀ {ι : Type u} [Fintype ι] {m : ι → M} {n : ι → N},
∑ i, m i ⊗ₜ n i = (0 : M ⊗[R] N) → VanishesTrivially R m n) ↔
∀ (M' : Submodule R M) (_ : M'.FG), Injective (rTensor N M'.subtype) := by |
constructor
· intro h M' _
exact rTensor_injective_of_forall_vanishesTrivially R h M'
· intro h ι _ m n hmn
exact vanishesTrivially_of_sum_tmul_eq_zero_of_rTensor_injective R
(h _ (fg_span (Set.finite_range _))) hmn
|
/-
Copyright (c) 2018 Mitchell Rowett. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mitchell Rowett, Scott Morrison
-/
import Mathlib.Algebra.Quotient
import Mathlib.Algebra.Group.Subgroup.Actions
import Mathlib.Algebra.Group.Subgroup.MulOpposite
import Mathlib.GroupTheory.GroupAction.Basic
import Mathlib.SetTheory.Cardinal.Finite
#align_import group_theory.coset from "leanprover-community/mathlib"@"f7fc89d5d5ff1db2d1242c7bb0e9062ce47ef47c"
/-!
# Cosets
This file develops the basic theory of left and right cosets.
When `G` is a group and `a : G`, `s : Set G`, with `open scoped Pointwise` we can write:
* the left coset of `s` by `a` as `a • s`
* the right coset of `s` by `a` as `MulOpposite.op a • s` (or `op a • s` with `open MulOpposite`)
If instead `G` is an additive group, we can write (with `open scoped Pointwise` still)
* the left coset of `s` by `a` as `a +ᵥ s`
* the right coset of `s` by `a` as `AddOpposite.op a +ᵥ s` (or `op a • s` with `open AddOpposite`)
## Main definitions
* `QuotientGroup.quotient s`: the quotient type representing the left cosets with respect to a
subgroup `s`, for an `AddGroup` this is `QuotientAddGroup.quotient s`.
* `QuotientGroup.mk`: the canonical map from `α` to `α/s` for a subgroup `s` of `α`, for an
`AddGroup` this is `QuotientAddGroup.mk`.
* `Subgroup.leftCosetEquivSubgroup`: the natural bijection between a left coset and the subgroup,
for an `AddGroup` this is `AddSubgroup.leftCosetEquivAddSubgroup`.
## Notation
* `G ⧸ H` is the quotient of the (additive) group `G` by the (additive) subgroup `H`
## TODO
Properly merge with pointwise actions on sets, by renaming and deduplicating lemmas as appropriate.
-/
open Function MulOpposite Set
open scoped Pointwise
variable {α : Type*}
#align left_coset HSMul.hSMul
#align left_add_coset HVAdd.hVAdd
#noalign right_coset
#noalign right_add_coset
section CosetMul
variable [Mul α]
@[to_additive mem_leftAddCoset]
theorem mem_leftCoset {s : Set α} {x : α} (a : α) (hxS : x ∈ s) : a * x ∈ a • s :=
mem_image_of_mem (fun b : α => a * b) hxS
#align mem_left_coset mem_leftCoset
#align mem_left_add_coset mem_leftAddCoset
@[to_additive mem_rightAddCoset]
theorem mem_rightCoset {s : Set α} {x : α} (a : α) (hxS : x ∈ s) : x * a ∈ op a • s :=
mem_image_of_mem (fun b : α => b * a) hxS
#align mem_right_coset mem_rightCoset
#align mem_right_add_coset mem_rightAddCoset
/-- Equality of two left cosets `a * s` and `b * s`. -/
@[to_additive LeftAddCosetEquivalence "Equality of two left cosets `a + s` and `b + s`."]
def LeftCosetEquivalence (s : Set α) (a b : α) :=
a • s = b • s
#align left_coset_equivalence LeftCosetEquivalence
#align left_add_coset_equivalence LeftAddCosetEquivalence
@[to_additive leftAddCosetEquivalence_rel]
theorem leftCosetEquivalence_rel (s : Set α) : Equivalence (LeftCosetEquivalence s) :=
@Equivalence.mk _ (LeftCosetEquivalence s) (fun _ => rfl) Eq.symm Eq.trans
#align left_coset_equivalence_rel leftCosetEquivalence_rel
#align left_add_coset_equivalence_rel leftAddCosetEquivalence_rel
/-- Equality of two right cosets `s * a` and `s * b`. -/
@[to_additive RightAddCosetEquivalence "Equality of two right cosets `s + a` and `s + b`."]
def RightCosetEquivalence (s : Set α) (a b : α) :=
op a • s = op b • s
#align right_coset_equivalence RightCosetEquivalence
#align right_add_coset_equivalence RightAddCosetEquivalence
@[to_additive rightAddCosetEquivalence_rel]
theorem rightCosetEquivalence_rel (s : Set α) : Equivalence (RightCosetEquivalence s) :=
@Equivalence.mk _ (RightCosetEquivalence s) (fun _a => rfl) Eq.symm Eq.trans
#align right_coset_equivalence_rel rightCosetEquivalence_rel
#align right_add_coset_equivalence_rel rightAddCosetEquivalence_rel
end CosetMul
section CosetSemigroup
variable [Semigroup α]
@[to_additive leftAddCoset_assoc]
theorem leftCoset_assoc (s : Set α) (a b : α) : a • (b • s) = (a * b) • s := by
simp [← image_smul, (image_comp _ _ _).symm, Function.comp, mul_assoc]
#align left_coset_assoc leftCoset_assoc
#align left_add_coset_assoc leftAddCoset_assoc
@[to_additive rightAddCoset_assoc]
theorem rightCoset_assoc (s : Set α) (a b : α) : op b • op a • s = op (a * b) • s := by
simp [← image_smul, (image_comp _ _ _).symm, Function.comp, mul_assoc]
#align right_coset_assoc rightCoset_assoc
#align right_add_coset_assoc rightAddCoset_assoc
@[to_additive leftAddCoset_rightAddCoset]
theorem leftCoset_rightCoset (s : Set α) (a b : α) : op b • a • s = a • (op b • s) := by
simp [← image_smul, (image_comp _ _ _).symm, Function.comp, mul_assoc]
#align left_coset_right_coset leftCoset_rightCoset
#align left_add_coset_right_add_coset leftAddCoset_rightAddCoset
end CosetSemigroup
section CosetMonoid
variable [Monoid α] (s : Set α)
@[to_additive zero_leftAddCoset]
theorem one_leftCoset : (1 : α) • s = s :=
Set.ext <| by simp [← image_smul]
#align one_left_coset one_leftCoset
#align zero_left_add_coset zero_leftAddCoset
@[to_additive rightAddCoset_zero]
theorem rightCoset_one : op (1 : α) • s = s :=
Set.ext <| by simp [← image_smul]
#align right_coset_one rightCoset_one
#align right_add_coset_zero rightAddCoset_zero
end CosetMonoid
section CosetSubmonoid
open Submonoid
variable [Monoid α] (s : Submonoid α)
@[to_additive mem_own_leftAddCoset]
theorem mem_own_leftCoset (a : α) : a ∈ a • (s : Set α) :=
suffices a * 1 ∈ a • (s : Set α) by simpa
mem_leftCoset a (one_mem s : 1 ∈ s)
#align mem_own_left_coset mem_own_leftCoset
#align mem_own_left_add_coset mem_own_leftAddCoset
@[to_additive mem_own_rightAddCoset]
theorem mem_own_rightCoset (a : α) : a ∈ op a • (s : Set α) :=
suffices 1 * a ∈ op a • (s : Set α) by simpa
mem_rightCoset a (one_mem s : 1 ∈ s)
#align mem_own_right_coset mem_own_rightCoset
#align mem_own_right_add_coset mem_own_rightAddCoset
@[to_additive mem_leftAddCoset_leftAddCoset]
theorem mem_leftCoset_leftCoset {a : α} (ha : a • (s : Set α) = s) : a ∈ s := by
rw [← SetLike.mem_coe, ← ha]; exact mem_own_leftCoset s a
#align mem_left_coset_left_coset mem_leftCoset_leftCoset
#align mem_left_add_coset_left_add_coset mem_leftAddCoset_leftAddCoset
@[to_additive mem_rightAddCoset_rightAddCoset]
theorem mem_rightCoset_rightCoset {a : α} (ha : op a • (s : Set α) = s) : a ∈ s := by
rw [← SetLike.mem_coe, ← ha]; exact mem_own_rightCoset s a
#align mem_right_coset_right_coset mem_rightCoset_rightCoset
#align mem_right_add_coset_right_add_coset mem_rightAddCoset_rightAddCoset
end CosetSubmonoid
section CosetGroup
variable [Group α] {s : Set α} {x : α}
@[to_additive mem_leftAddCoset_iff]
theorem mem_leftCoset_iff (a : α) : x ∈ a • s ↔ a⁻¹ * x ∈ s :=
Iff.intro (fun ⟨b, hb, Eq⟩ => by simp [Eq.symm, hb]) fun h => ⟨a⁻¹ * x, h, by simp⟩
#align mem_left_coset_iff mem_leftCoset_iff
#align mem_left_add_coset_iff mem_leftAddCoset_iff
@[to_additive mem_rightAddCoset_iff]
theorem mem_rightCoset_iff (a : α) : x ∈ op a • s ↔ x * a⁻¹ ∈ s :=
Iff.intro (fun ⟨b, hb, Eq⟩ => by simp [Eq.symm, hb]) fun h => ⟨x * a⁻¹, h, by simp⟩
#align mem_right_coset_iff mem_rightCoset_iff
#align mem_right_add_coset_iff mem_rightAddCoset_iff
end CosetGroup
section CosetSubgroup
open Subgroup
variable [Group α] (s : Subgroup α)
@[to_additive leftAddCoset_mem_leftAddCoset]
theorem leftCoset_mem_leftCoset {a : α} (ha : a ∈ s) : a • (s : Set α) = s :=
Set.ext <| by simp [mem_leftCoset_iff, mul_mem_cancel_left (s.inv_mem ha)]
#align left_coset_mem_left_coset leftCoset_mem_leftCoset
#align left_add_coset_mem_left_add_coset leftAddCoset_mem_leftAddCoset
@[to_additive rightAddCoset_mem_rightAddCoset]
theorem rightCoset_mem_rightCoset {a : α} (ha : a ∈ s) : op a • (s : Set α) = s :=
Set.ext fun b => by simp [mem_rightCoset_iff, mul_mem_cancel_right (s.inv_mem ha)]
#align right_coset_mem_right_coset rightCoset_mem_rightCoset
#align right_add_coset_mem_right_add_coset rightAddCoset_mem_rightAddCoset
@[to_additive]
theorem orbit_subgroup_eq_rightCoset (a : α) : MulAction.orbit s a = op a • s :=
Set.ext fun _b => ⟨fun ⟨c, d⟩ => ⟨c, c.2, d⟩, fun ⟨c, d, e⟩ => ⟨⟨c, d⟩, e⟩⟩
#align orbit_subgroup_eq_right_coset orbit_subgroup_eq_rightCoset
#align orbit_add_subgroup_eq_right_coset orbit_addSubgroup_eq_rightCoset
@[to_additive]
theorem orbit_subgroup_eq_self_of_mem {a : α} (ha : a ∈ s) : MulAction.orbit s a = s :=
(orbit_subgroup_eq_rightCoset s a).trans (rightCoset_mem_rightCoset s ha)
#align orbit_subgroup_eq_self_of_mem orbit_subgroup_eq_self_of_mem
#align orbit_add_subgroup_eq_self_of_mem orbit_addSubgroup_eq_self_of_mem
@[to_additive]
theorem orbit_subgroup_one_eq_self : MulAction.orbit s (1 : α) = s :=
orbit_subgroup_eq_self_of_mem s s.one_mem
#align orbit_subgroup_one_eq_self orbit_subgroup_one_eq_self
#align orbit_add_subgroup_zero_eq_self orbit_addSubgroup_zero_eq_self
@[to_additive eq_addCosets_of_normal]
theorem eq_cosets_of_normal (N : s.Normal) (g : α) : g • (s : Set α) = op g • s :=
Set.ext fun a => by simp [mem_leftCoset_iff, mem_rightCoset_iff]; rw [N.mem_comm_iff]
#align eq_cosets_of_normal eq_cosets_of_normal
#align eq_add_cosets_of_normal eq_addCosets_of_normal
@[to_additive normal_of_eq_addCosets]
theorem normal_of_eq_cosets (h : ∀ g : α, g • (s : Set α) = op g • s) : s.Normal :=
⟨fun a ha g =>
show g * a * g⁻¹ ∈ (s : Set α) by rw [← mem_rightCoset_iff, ← h]; exact mem_leftCoset g ha⟩
#align normal_of_eq_cosets normal_of_eq_cosets
#align normal_of_eq_add_cosets normal_of_eq_addCosets
@[to_additive normal_iff_eq_addCosets]
theorem normal_iff_eq_cosets : s.Normal ↔ ∀ g : α, g • (s : Set α) = op g • s :=
⟨@eq_cosets_of_normal _ _ s, normal_of_eq_cosets s⟩
#align normal_iff_eq_cosets normal_iff_eq_cosets
#align normal_iff_eq_add_cosets normal_iff_eq_addCosets
@[to_additive leftAddCoset_eq_iff]
theorem leftCoset_eq_iff {x y : α} : x • (s : Set α) = y • s ↔ x⁻¹ * y ∈ s := by
rw [Set.ext_iff]
simp_rw [mem_leftCoset_iff, SetLike.mem_coe]
constructor
· intro h
apply (h y).mpr
rw [mul_left_inv]
exact s.one_mem
· intro h z
rw [← mul_inv_cancel_right x⁻¹ y]
rw [mul_assoc]
exact s.mul_mem_cancel_left h
#align left_coset_eq_iff leftCoset_eq_iff
#align left_add_coset_eq_iff leftAddCoset_eq_iff
@[to_additive rightAddCoset_eq_iff]
theorem rightCoset_eq_iff {x y : α} : op x • (s : Set α) = op y • s ↔ y * x⁻¹ ∈ s := by
rw [Set.ext_iff]
simp_rw [mem_rightCoset_iff, SetLike.mem_coe]
constructor
· intro h
apply (h y).mpr
rw [mul_right_inv]
exact s.one_mem
· intro h z
rw [← inv_mul_cancel_left y x⁻¹]
rw [← mul_assoc]
exact s.mul_mem_cancel_right h
#align right_coset_eq_iff rightCoset_eq_iff
#align right_add_coset_eq_iff rightAddCoset_eq_iff
end CosetSubgroup
-- Porting note: see https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/.E2.9C.94.20to_additive.2Emap_namespace
run_cmd Lean.Elab.Command.liftCoreM <| ToAdditive.insertTranslation `QuotientGroup `QuotientAddGroup
namespace QuotientGroup
variable [Group α] (s : Subgroup α)
/-- The equivalence relation corresponding to the partition of a group by left cosets
of a subgroup. -/
@[to_additive "The equivalence relation corresponding to the partition of a group by left cosets
of a subgroup."]
def leftRel : Setoid α :=
MulAction.orbitRel s.op α
#align quotient_group.left_rel QuotientGroup.leftRel
#align quotient_add_group.left_rel QuotientAddGroup.leftRel
variable {s}
@[to_additive]
theorem leftRel_apply {x y : α} : @Setoid.r _ (leftRel s) x y ↔ x⁻¹ * y ∈ s :=
calc
(∃ a : s.op, y * MulOpposite.unop a = x) ↔ ∃ a : s, y * a = x :=
s.equivOp.symm.exists_congr_left
_ ↔ ∃ a : s, x⁻¹ * y = a⁻¹ := by
simp only [inv_mul_eq_iff_eq_mul, Subgroup.coe_inv, eq_mul_inv_iff_mul_eq]
_ ↔ x⁻¹ * y ∈ s := by simp [exists_inv_mem_iff_exists_mem]
#align quotient_group.left_rel_apply QuotientGroup.leftRel_apply
#align quotient_add_group.left_rel_apply QuotientAddGroup.leftRel_apply
variable (s)
@[to_additive]
theorem leftRel_eq : @Setoid.r _ (leftRel s) = fun x y => x⁻¹ * y ∈ s :=
funext₂ <| by
simp only [eq_iff_iff]
apply leftRel_apply
#align quotient_group.left_rel_eq QuotientGroup.leftRel_eq
#align quotient_add_group.left_rel_eq QuotientAddGroup.leftRel_eq
theorem leftRel_r_eq_leftCosetEquivalence :
@Setoid.r _ (QuotientGroup.leftRel s) = LeftCosetEquivalence s := by
ext
rw [leftRel_eq]
exact (leftCoset_eq_iff s).symm
#align quotient_group.left_rel_r_eq_left_coset_equivalence QuotientGroup.leftRel_r_eq_leftCosetEquivalence
@[to_additive]
instance leftRelDecidable [DecidablePred (· ∈ s)] : DecidableRel (leftRel s).r := fun x y => by
rw [leftRel_eq]
exact ‹DecidablePred (· ∈ s)› _
#align quotient_group.left_rel_decidable QuotientGroup.leftRelDecidable
#align quotient_add_group.left_rel_decidable QuotientAddGroup.leftRelDecidable
/-- `α ⧸ s` is the quotient type representing the left cosets of `s`.
If `s` is a normal subgroup, `α ⧸ s` is a group -/
@[to_additive "`α ⧸ s` is the quotient type representing the left cosets of `s`. If `s` is a normal
subgroup, `α ⧸ s` is a group"]
instance instHasQuotientSubgroup : HasQuotient α (Subgroup α) :=
⟨fun s => Quotient (leftRel s)⟩
/-- The equivalence relation corresponding to the partition of a group by right cosets of a
subgroup. -/
@[to_additive "The equivalence relation corresponding to the partition of a group by right cosets
of a subgroup."]
def rightRel : Setoid α :=
MulAction.orbitRel s α
#align quotient_group.right_rel QuotientGroup.rightRel
#align quotient_add_group.right_rel QuotientAddGroup.rightRel
variable {s}
@[to_additive]
theorem rightRel_apply {x y : α} : @Setoid.r _ (rightRel s) x y ↔ y * x⁻¹ ∈ s :=
calc
(∃ a : s, (a : α) * y = x) ↔ ∃ a : s, y * x⁻¹ = a⁻¹ := by
simp only [mul_inv_eq_iff_eq_mul, Subgroup.coe_inv, eq_inv_mul_iff_mul_eq]
_ ↔ y * x⁻¹ ∈ s := by simp [exists_inv_mem_iff_exists_mem]
#align quotient_group.right_rel_apply QuotientGroup.rightRel_apply
#align quotient_add_group.right_rel_apply QuotientAddGroup.rightRel_apply
variable (s)
@[to_additive]
theorem rightRel_eq : @Setoid.r _ (rightRel s) = fun x y => y * x⁻¹ ∈ s :=
funext₂ <| by
simp only [eq_iff_iff]
apply rightRel_apply
#align quotient_group.right_rel_eq QuotientGroup.rightRel_eq
#align quotient_add_group.right_rel_eq QuotientAddGroup.rightRel_eq
theorem rightRel_r_eq_rightCosetEquivalence :
@Setoid.r _ (QuotientGroup.rightRel s) = RightCosetEquivalence s := by
ext
rw [rightRel_eq]
exact (rightCoset_eq_iff s).symm
#align quotient_group.right_rel_r_eq_right_coset_equivalence QuotientGroup.rightRel_r_eq_rightCosetEquivalence
@[to_additive]
instance rightRelDecidable [DecidablePred (· ∈ s)] : DecidableRel (rightRel s).r := fun x y => by
rw [rightRel_eq]
exact ‹DecidablePred (· ∈ s)› _
#align quotient_group.right_rel_decidable QuotientGroup.rightRelDecidable
#align quotient_add_group.right_rel_decidable QuotientAddGroup.rightRelDecidable
/-- Right cosets are in bijection with left cosets. -/
@[to_additive "Right cosets are in bijection with left cosets."]
def quotientRightRelEquivQuotientLeftRel : Quotient (QuotientGroup.rightRel s) ≃ α ⧸ s where
toFun :=
Quotient.map' (fun g => g⁻¹) fun a b => by
rw [leftRel_apply, rightRel_apply]
exact fun h => (congr_arg (· ∈ s) (by simp [mul_assoc])).mp (s.inv_mem h)
-- Porting note: replace with `by group`
invFun :=
Quotient.map' (fun g => g⁻¹) fun a b => by
rw [leftRel_apply, rightRel_apply]
exact fun h => (congr_arg (· ∈ s) (by simp [mul_assoc])).mp (s.inv_mem h)
-- Porting note: replace with `by group`
left_inv g :=
Quotient.inductionOn' g fun g =>
Quotient.sound'
(by
simp only [inv_inv]
exact Quotient.exact' rfl)
right_inv g :=
Quotient.inductionOn' g fun g =>
Quotient.sound'
(by
simp only [inv_inv]
exact Quotient.exact' rfl)
#align quotient_group.quotient_right_rel_equiv_quotient_left_rel QuotientGroup.quotientRightRelEquivQuotientLeftRel
#align quotient_add_group.quotient_right_rel_equiv_quotient_left_rel QuotientAddGroup.quotientRightRelEquivQuotientLeftRel
@[to_additive]
instance fintypeQuotientRightRel [Fintype (α ⧸ s)] :
Fintype (Quotient (QuotientGroup.rightRel s)) :=
Fintype.ofEquiv (α ⧸ s) (QuotientGroup.quotientRightRelEquivQuotientLeftRel s).symm
#align quotient_group.fintype_quotient_right_rel QuotientGroup.fintypeQuotientRightRel
#align quotient_add_group.fintype_quotient_right_rel QuotientAddGroup.fintypeQuotientRightRel
@[to_additive]
theorem card_quotient_rightRel [Fintype (α ⧸ s)] :
Fintype.card (Quotient (QuotientGroup.rightRel s)) = Fintype.card (α ⧸ s) :=
Fintype.ofEquiv_card (QuotientGroup.quotientRightRelEquivQuotientLeftRel s).symm
#align quotient_group.card_quotient_right_rel QuotientGroup.card_quotient_rightRel
#align quotient_add_group.card_quotient_right_rel QuotientAddGroup.card_quotient_rightRel
end QuotientGroup
namespace QuotientGroup
variable [Group α] {s : Subgroup α}
@[to_additive]
instance fintype [Fintype α] (s : Subgroup α) [DecidableRel (leftRel s).r] : Fintype (α ⧸ s) :=
Quotient.fintype (leftRel s)
#align quotient_group.fintype QuotientGroup.fintype
#align quotient_add_group.fintype QuotientAddGroup.fintype
/-- The canonical map from a group `α` to the quotient `α ⧸ s`. -/
@[to_additive (attr := coe) "The canonical map from an `AddGroup` `α` to the quotient `α ⧸ s`."]
abbrev mk (a : α) : α ⧸ s :=
Quotient.mk'' a
#align quotient_group.mk QuotientGroup.mk
#align quotient_add_group.mk QuotientAddGroup.mk
@[to_additive]
theorem mk_surjective : Function.Surjective <| @mk _ _ s :=
Quotient.surjective_Quotient_mk''
#align quotient_group.mk_surjective QuotientGroup.mk_surjective
#align quotient_add_group.mk_surjective QuotientAddGroup.mk_surjective
@[to_additive (attr := simp)]
lemma range_mk : range (QuotientGroup.mk (s := s)) = univ := range_iff_surjective.mpr mk_surjective
@[to_additive (attr := elab_as_elim)]
theorem induction_on {C : α ⧸ s → Prop} (x : α ⧸ s) (H : ∀ z, C (QuotientGroup.mk z)) : C x :=
Quotient.inductionOn' x H
#align quotient_group.induction_on QuotientGroup.induction_on
#align quotient_add_group.induction_on QuotientAddGroup.induction_on
@[to_additive]
instance : Coe α (α ⧸ s) :=
⟨mk⟩
@[to_additive (attr := elab_as_elim)]
theorem induction_on' {C : α ⧸ s → Prop} (x : α ⧸ s) (H : ∀ z : α, C z) : C x :=
Quotient.inductionOn' x H
#align quotient_group.induction_on' QuotientGroup.induction_on'
#align quotient_add_group.induction_on' QuotientAddGroup.induction_on'
@[to_additive (attr := simp)]
theorem quotient_liftOn_mk {β} (f : α → β) (h) (x : α) : Quotient.liftOn' (x : α ⧸ s) f h = f x :=
rfl
#align quotient_group.quotient_lift_on_coe QuotientGroup.quotient_liftOn_mk
#align quotient_add_group.quotient_lift_on_coe QuotientAddGroup.quotient_liftOn_mk
@[to_additive]
theorem forall_mk {C : α ⧸ s → Prop} : (∀ x : α ⧸ s, C x) ↔ ∀ x : α, C x :=
mk_surjective.forall
#align quotient_group.forall_coe QuotientGroup.forall_mk
#align quotient_add_group.forall_coe QuotientAddGroup.forall_mk
@[to_additive]
theorem exists_mk {C : α ⧸ s → Prop} : (∃ x : α ⧸ s, C x) ↔ ∃ x : α, C x :=
mk_surjective.exists
#align quotient_group.exists_coe QuotientGroup.exists_mk
#align quotient_add_group.exists_coe QuotientAddGroup.exists_mk
@[to_additive]
instance (s : Subgroup α) : Inhabited (α ⧸ s) :=
⟨((1 : α) : α ⧸ s)⟩
@[to_additive]
protected theorem eq {a b : α} : (a : α ⧸ s) = b ↔ a⁻¹ * b ∈ s :=
calc
_ ↔ @Setoid.r _ (leftRel s) a b := Quotient.eq''
_ ↔ _ := by rw [leftRel_apply]
#align quotient_group.eq QuotientGroup.eq
#align quotient_add_group.eq QuotientAddGroup.eq
@[to_additive]
theorem eq' {a b : α} : (mk a : α ⧸ s) = mk b ↔ a⁻¹ * b ∈ s :=
QuotientGroup.eq
#align quotient_group.eq' QuotientGroup.eq'
#align quotient_add_group.eq' QuotientAddGroup.eq'
@[to_additive] -- Porting note (#10618): `simp` can prove this.
theorem out_eq' (a : α ⧸ s) : mk a.out' = a :=
Quotient.out_eq' a
#align quotient_group.out_eq' QuotientGroup.out_eq'
#align quotient_add_group.out_eq' QuotientAddGroup.out_eq'
variable (s)
/- It can be useful to write `obtain ⟨h, H⟩ := mk_out'_eq_mul ...`, and then `rw [H]` or
`simp_rw [H]` or `simp only [H]`. In order for `simp_rw` and `simp only` to work, this lemma is
stated in terms of an arbitrary `h : s`, rather than the specific `h = g⁻¹ * (mk g).out'`. -/
@[to_additive QuotientAddGroup.mk_out'_eq_mul]
theorem mk_out'_eq_mul (g : α) : ∃ h : s, (mk g : α ⧸ s).out' = g * h :=
⟨⟨g⁻¹ * (mk g).out', eq'.mp (mk g).out_eq'.symm⟩, by rw [mul_inv_cancel_left]⟩
#align quotient_group.mk_out'_eq_mul QuotientGroup.mk_out'_eq_mul
#align quotient_add_group.mk_out'_eq_mul QuotientAddGroup.mk_out'_eq_mul
variable {s} {a b : α}
@[to_additive (attr := simp)]
| Mathlib/GroupTheory/Coset.lean | 529 | 530 | theorem mk_mul_of_mem (a : α) (hb : b ∈ s) : (mk (a * b) : α ⧸ s) = mk a := by |
rwa [eq', mul_inv_rev, inv_mul_cancel_right, s.inv_mem_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
-/
import Mathlib.Data.Set.Finite
import Mathlib.Data.Countable.Basic
import Mathlib.Logic.Equiv.List
import Mathlib.Data.Set.Subsingleton
#align_import data.set.countable from "leanprover-community/mathlib"@"1f0096e6caa61e9c849ec2adbd227e960e9dff58"
/-!
# Countable sets
In this file we define `Set.Countable s` as `Countable s`
and prove basic properties of this definition.
Note that this definition does not provide a computable encoding.
For a noncomputable conversion to `Encodable s`, use `Set.Countable.nonempty_encodable`.
## Keywords
sets, countable set
-/
noncomputable section
open scoped Classical
open Function Set Encodable
universe u v w x
variable {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x}
namespace Set
/-- A set `s` is countable if the corresponding subtype is countable,
i.e., there exists an injective map `f : s → ℕ`.
Note that this is an abbreviation, so `hs : Set.Countable s` in the proof context
is the same as an instance `Countable s`.
For a constructive version, see `Encodable`.
-/
protected def Countable (s : Set α) : Prop := Countable s
#align set.countable Set.Countable
@[simp]
theorem countable_coe_iff {s : Set α} : Countable s ↔ s.Countable := .rfl
#align set.countable_coe_iff Set.countable_coe_iff
/-- Prove `Set.Countable` from a `Countable` instance on the subtype. -/
theorem to_countable (s : Set α) [Countable s] : s.Countable := ‹_›
#align set.to_countable Set.to_countable
/-- Restate `Set.Countable` as a `Countable` instance. -/
alias ⟨_root_.Countable.to_set, Countable.to_subtype⟩ := countable_coe_iff
#align countable.to_set Countable.to_set
#align set.countable.to_subtype Set.Countable.to_subtype
protected theorem countable_iff_exists_injective {s : Set α} :
s.Countable ↔ ∃ f : s → ℕ, Injective f :=
countable_iff_exists_injective s
#align set.countable_iff_exists_injective Set.countable_iff_exists_injective
/-- A set `s : Set α` is countable if and only if there exists a function `α → ℕ` injective
on `s`. -/
theorem countable_iff_exists_injOn {s : Set α} : s.Countable ↔ ∃ f : α → ℕ, InjOn f s :=
Set.countable_iff_exists_injective.trans exists_injOn_iff_injective.symm
#align set.countable_iff_exists_inj_on Set.countable_iff_exists_injOn
theorem countable_iff_nonempty_encodable {s : Set α} : s.Countable ↔ Nonempty (Encodable s) :=
Encodable.nonempty_encodable.symm
alias ⟨Countable.nonempty_encodable, _⟩ := countable_iff_nonempty_encodable
/-- Convert `Set.Countable s` to `Encodable s` (noncomputable). -/
protected def Countable.toEncodable {s : Set α} (hs : s.Countable) : Encodable s :=
Classical.choice hs.nonempty_encodable
#align set.countable.to_encodable Set.Countable.toEncodable
section Enumerate
/-- Noncomputably enumerate elements in a set. The `default` value is used to extend the domain to
all of `ℕ`. -/
def enumerateCountable {s : Set α} (h : s.Countable) (default : α) : ℕ → α := fun n =>
match @Encodable.decode s h.toEncodable n with
| some y => y
| none => default
#align set.enumerate_countable Set.enumerateCountable
theorem subset_range_enumerate {s : Set α} (h : s.Countable) (default : α) :
s ⊆ range (enumerateCountable h default) := fun x hx =>
⟨@Encodable.encode s h.toEncodable ⟨x, hx⟩, by
letI := h.toEncodable
simp [enumerateCountable, Encodable.encodek]⟩
#align set.subset_range_enumerate Set.subset_range_enumerate
lemma range_enumerateCountable_subset {s : Set α} (h : s.Countable) (default : α) :
range (enumerateCountable h default) ⊆ insert default s := by
refine range_subset_iff.mpr (fun n ↦ ?_)
rw [enumerateCountable]
match @decode s (Countable.toEncodable h) n with
| none => exact mem_insert _ _
| some val => simp
lemma range_enumerateCountable_of_mem {s : Set α} (h : s.Countable) {default : α}
(h_mem : default ∈ s) :
range (enumerateCountable h default) = s :=
subset_antisymm ((range_enumerateCountable_subset h _).trans_eq (insert_eq_of_mem h_mem))
(subset_range_enumerate h default)
lemma enumerateCountable_mem {s : Set α} (h : s.Countable) {default : α} (h_mem : default ∈ s)
(n : ℕ) :
enumerateCountable h default n ∈ s := by
conv_rhs => rw [← range_enumerateCountable_of_mem h h_mem]
exact mem_range_self n
end Enumerate
theorem Countable.mono {s₁ s₂ : Set α} (h : s₁ ⊆ s₂) (hs : s₂.Countable) : s₁.Countable :=
have := hs.to_subtype; (inclusion_injective h).countable
#align set.countable.mono Set.Countable.mono
theorem countable_range [Countable ι] (f : ι → β) : (range f).Countable :=
surjective_onto_range.countable.to_set
#align set.countable_range Set.countable_range
theorem countable_iff_exists_subset_range [Nonempty α] {s : Set α} :
s.Countable ↔ ∃ f : ℕ → α, s ⊆ range f :=
⟨fun h => by
inhabit α
exact ⟨enumerateCountable h default, subset_range_enumerate _ _⟩, fun ⟨f, hsf⟩ =>
(countable_range f).mono hsf⟩
#align set.countable_iff_exists_subset_range Set.countable_iff_exists_subset_range
/-- A non-empty set is countable iff there exists a surjection from the
natural numbers onto the subtype induced by the set.
-/
protected theorem countable_iff_exists_surjective {s : Set α} (hs : s.Nonempty) :
s.Countable ↔ ∃ f : ℕ → s, Surjective f :=
@countable_iff_exists_surjective s hs.to_subtype
#align set.countable_iff_exists_surjective Set.countable_iff_exists_surjective
alias ⟨Countable.exists_surjective, _⟩ := Set.countable_iff_exists_surjective
#align set.countable.exists_surjective Set.Countable.exists_surjective
theorem countable_univ [Countable α] : (univ : Set α).Countable :=
to_countable univ
#align set.countable_univ Set.countable_univ
theorem countable_univ_iff : (univ : Set α).Countable ↔ Countable α :=
countable_coe_iff.symm.trans (Equiv.Set.univ _).countable_iff
/-- If `s : Set α` is a nonempty countable set, then there exists a map
`f : ℕ → α` such that `s = range f`. -/
theorem Countable.exists_eq_range {s : Set α} (hc : s.Countable) (hs : s.Nonempty) :
∃ f : ℕ → α, s = range f := by
rcases hc.exists_surjective hs with ⟨f, hf⟩
refine ⟨(↑) ∘ f, ?_⟩
rw [hf.range_comp, Subtype.range_coe]
#align set.countable.exists_eq_range Set.Countable.exists_eq_range
@[simp] theorem countable_empty : (∅ : Set α).Countable := to_countable _
#align set.countable_empty Set.countable_empty
@[simp] theorem countable_singleton (a : α) : ({a} : Set α).Countable := to_countable _
#align set.countable_singleton Set.countable_singleton
theorem Countable.image {s : Set α} (hs : s.Countable) (f : α → β) : (f '' s).Countable := by
rw [image_eq_range]
have := hs.to_subtype
apply countable_range
#align set.countable.image Set.Countable.image
theorem MapsTo.countable_of_injOn {s : Set α} {t : Set β} {f : α → β} (hf : MapsTo f s t)
(hf' : InjOn f s) (ht : t.Countable) : s.Countable :=
have := ht.to_subtype
have : Injective (hf.restrict f s t) := (injOn_iff_injective.1 hf').codRestrict _
this.countable
#align set.maps_to.countable_of_inj_on Set.MapsTo.countable_of_injOn
theorem Countable.preimage_of_injOn {s : Set β} (hs : s.Countable) {f : α → β}
(hf : InjOn f (f ⁻¹' s)) : (f ⁻¹' s).Countable :=
(mapsTo_preimage f s).countable_of_injOn hf hs
#align set.countable.preimage_of_inj_on Set.Countable.preimage_of_injOn
protected theorem Countable.preimage {s : Set β} (hs : s.Countable) {f : α → β} (hf : Injective f) :
(f ⁻¹' s).Countable :=
hs.preimage_of_injOn hf.injOn
#align set.countable.preimage Set.Countable.preimage
theorem exists_seq_iSup_eq_top_iff_countable [CompleteLattice α] {p : α → Prop} (h : ∃ x, p x) :
(∃ s : ℕ → α, (∀ n, p (s n)) ∧ ⨆ n, s n = ⊤) ↔
∃ S : Set α, S.Countable ∧ (∀ s ∈ S, p s) ∧ sSup S = ⊤ := by
constructor
· rintro ⟨s, hps, hs⟩
refine ⟨range s, countable_range s, forall_mem_range.2 hps, ?_⟩
rwa [sSup_range]
· rintro ⟨S, hSc, hps, hS⟩
rcases eq_empty_or_nonempty S with (rfl | hne)
· rw [sSup_empty] at hS
haveI := subsingleton_of_bot_eq_top hS
rcases h with ⟨x, hx⟩
exact ⟨fun _ => x, fun _ => hx, Subsingleton.elim _ _⟩
· rcases (Set.countable_iff_exists_surjective hne).1 hSc with ⟨s, hs⟩
refine ⟨fun n => s n, fun n => hps _ (s n).coe_prop, ?_⟩
rwa [hs.iSup_comp, ← sSup_eq_iSup']
#align set.exists_seq_supr_eq_top_iff_countable Set.exists_seq_iSup_eq_top_iff_countable
theorem exists_seq_cover_iff_countable {p : Set α → Prop} (h : ∃ s, p s) :
(∃ s : ℕ → Set α, (∀ n, p (s n)) ∧ ⋃ n, s n = univ) ↔
∃ S : Set (Set α), S.Countable ∧ (∀ s ∈ S, p s) ∧ ⋃₀ S = univ :=
exists_seq_iSup_eq_top_iff_countable h
#align set.exists_seq_cover_iff_countable Set.exists_seq_cover_iff_countable
theorem countable_of_injective_of_countable_image {s : Set α} {f : α → β} (hf : InjOn f s)
(hs : (f '' s).Countable) : s.Countable :=
(mapsTo_image _ _).countable_of_injOn hf hs
#align set.countable_of_injective_of_countable_image Set.countable_of_injective_of_countable_image
theorem countable_iUnion {t : ι → Set α} [Countable ι] (ht : ∀ i, (t i).Countable) :
(⋃ i, t i).Countable := by
have := fun i ↦ (ht i).to_subtype
rw [iUnion_eq_range_psigma]
apply countable_range
#align set.countable_Union Set.countable_iUnion
@[simp]
theorem countable_iUnion_iff [Countable ι] {t : ι → Set α} :
(⋃ i, t i).Countable ↔ ∀ i, (t i).Countable :=
⟨fun h _ => h.mono <| subset_iUnion _ _, countable_iUnion⟩
#align set.countable_Union_iff Set.countable_iUnion_iff
theorem Countable.biUnion_iff {s : Set α} {t : ∀ a ∈ s, Set β} (hs : s.Countable) :
(⋃ a ∈ s, t a ‹_›).Countable ↔ ∀ a (ha : a ∈ s), (t a ha).Countable := by
have := hs.to_subtype
rw [biUnion_eq_iUnion, countable_iUnion_iff, SetCoe.forall']
#align set.countable.bUnion_iff Set.Countable.biUnion_iff
theorem Countable.sUnion_iff {s : Set (Set α)} (hs : s.Countable) :
(⋃₀ s).Countable ↔ ∀ a ∈ s, a.Countable := by rw [sUnion_eq_biUnion, hs.biUnion_iff]
#align set.countable.sUnion_iff Set.Countable.sUnion_iff
alias ⟨_, Countable.biUnion⟩ := Countable.biUnion_iff
#align set.countable.bUnion Set.Countable.biUnion
alias ⟨_, Countable.sUnion⟩ := Countable.sUnion_iff
#align set.countable.sUnion Set.Countable.sUnion
@[simp]
| Mathlib/Data/Set/Countable.lean | 252 | 253 | theorem countable_union {s t : Set α} : (s ∪ t).Countable ↔ s.Countable ∧ t.Countable := by |
simp [union_eq_iUnion, and_comm]
|
/-
Copyright (c) 2024 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Algebra.GroupPower.IterateHom
import Mathlib.Algebra.Module.Defs
import Mathlib.Algebra.Order.Archimedean
import Mathlib.Algebra.Order.Group.Instances
import Mathlib.GroupTheory.GroupAction.Pi
/-!
# Maps (semi)conjugating a shift to a shift
Denote by $S^1$ the unit circle `UnitAddCircle`.
A common way to study a self-map $f\colon S^1\to S^1$ of degree `1`
is to lift it to a map $\tilde f\colon \mathbb R\to \mathbb R$
such that $\tilde f(x + 1) = \tilde f(x)+1$ for all `x`.
In this file we define a structure and a typeclass
for bundled maps satisfying `f (x + a) = f x + b`.
We use parameters `a` and `b` instead of `1` to accomodate for two use cases:
- maps between circles of different lengths;
- self-maps $f\colon S^1\to S^1$ of degree other than one,
including orientation-reversing maps.
-/
open Function Set
/-- A bundled map `f : G → H` such that `f (x + a) = f x + b` for all `x`.
One can think about `f` as a lift to `G` of a map between two `AddCircle`s. -/
structure AddConstMap (G H : Type*) [Add G] [Add H] (a : G) (b : H) where
/-- The underlying function of an `AddConstMap`.
Use automatic coercion to function instead. -/
protected toFun : G → H
/-- An `AddConstMap` satisfies `f (x + a) = f x + b`. Use `map_add_const` instead. -/
map_add_const' (x : G) : toFun (x + a) = toFun x + b
@[inherit_doc]
scoped [AddConstMap] notation:25 G " →+c[" a ", " b "] " H => AddConstMap G H a b
/-- Typeclass for maps satisfying `f (x + a) = f x + b`.
Note that `a` and `b` are `outParam`s,
so one should not add instances like
`[AddConstMapClass F G H a b] : AddConstMapClass F G H (-a) (-b)`. -/
class AddConstMapClass (F : Type*) (G H : outParam Type*) [Add G] [Add H]
(a : outParam G) (b : outParam H) extends DFunLike F G fun _ ↦ H where
/-- A map of `AddConstMapClass` class semiconjugates shift by `a` to the shift by `b`:
`∀ x, f (x + a) = f x + b`. -/
map_add_const (f : F) (x : G) : f (x + a) = f x + b
namespace AddConstMapClass
/-!
### Properties of `AddConstMapClass` maps
In this section we prove properties like `f (x + n • a) = f x + n • b`.
-/
attribute [simp] map_add_const
variable {F G H : Type*} {a : G} {b : H}
protected theorem semiconj [Add G] [Add H] [AddConstMapClass F G H a b] (f : F) :
Semiconj f (· + a) (· + b) :=
map_add_const f
@[simp]
theorem map_add_nsmul [AddMonoid G] [AddMonoid H] [AddConstMapClass F G H a b]
(f : F) (x : G) (n : ℕ) : f (x + n • a) = f x + n • b := by
simpa using (AddConstMapClass.semiconj f).iterate_right n x
@[simp]
| Mathlib/Algebra/AddConstMap/Basic.lean | 78 | 79 | theorem map_add_nat' [AddMonoidWithOne G] [AddMonoid H] [AddConstMapClass F G H 1 b]
(f : F) (x : G) (n : ℕ) : f (x + n) = f x + n • b := by | simp [← map_add_nsmul]
|
/-
Copyright (c) 2020 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import Mathlib.MeasureTheory.Integral.Lebesgue
import Mathlib.Analysis.MeanInequalities
import Mathlib.Analysis.MeanInequalitiesPow
import Mathlib.MeasureTheory.Function.SpecialFunctions.Basic
#align_import measure_theory.integral.mean_inequalities from "leanprover-community/mathlib"@"13bf7613c96a9fd66a81b9020a82cad9a6ea1fcf"
/-!
# Mean value inequalities for integrals
In this file we prove several inequalities on integrals, notably the Hölder inequality and
the Minkowski inequality. The versions for finite sums are in `Analysis.MeanInequalities`.
## Main results
Hölder's inequality for the Lebesgue integral of `ℝ≥0∞` and `ℝ≥0` functions: we prove
`∫ (f * g) ∂μ ≤ (∫ f^p ∂μ) ^ (1/p) * (∫ g^q ∂μ) ^ (1/q)` for `p`, `q` conjugate real exponents
and `α → (E)NNReal` functions in two cases,
* `ENNReal.lintegral_mul_le_Lp_mul_Lq` : ℝ≥0∞ functions,
* `NNReal.lintegral_mul_le_Lp_mul_Lq` : ℝ≥0 functions.
`ENNReal.lintegral_mul_norm_pow_le` is a variant where the exponents are not reciprocals:
`∫ (f ^ p * g ^ q) ∂μ ≤ (∫ f ∂μ) ^ p * (∫ g ∂μ) ^ q` where `p, q ≥ 0` and `p + q = 1`.
`ENNReal.lintegral_prod_norm_pow_le` generalizes this to a finite family of functions:
`∫ (∏ i, f i ^ p i) ∂μ ≤ ∏ i, (∫ f i ∂μ) ^ p i` when the `p` is a collection
of nonnegative weights with sum 1.
Minkowski's inequality for the Lebesgue integral of measurable functions with `ℝ≥0∞` values:
we prove `(∫ (f + g)^p ∂μ) ^ (1/p) ≤ (∫ f^p ∂μ) ^ (1/p) + (∫ g^p ∂μ) ^ (1/p)` for `1 ≤ p`.
-/
section LIntegral
/-!
### Hölder's inequality for the Lebesgue integral of ℝ≥0∞ and ℝ≥0 functions
We prove `∫ (f * g) ∂μ ≤ (∫ f^p ∂μ) ^ (1/p) * (∫ g^q ∂μ) ^ (1/q)` for `p`, `q`
conjugate real exponents and `α → (E)NNReal` functions in several cases, the first two being useful
only to prove the more general results:
* `ENNReal.lintegral_mul_le_one_of_lintegral_rpow_eq_one` : ℝ≥0∞ functions for which the
integrals on the right are equal to 1,
* `ENNReal.lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_ne_top` : ℝ≥0∞ functions for which the
integrals on the right are neither ⊤ nor 0,
* `ENNReal.lintegral_mul_le_Lp_mul_Lq` : ℝ≥0∞ functions,
* `NNReal.lintegral_mul_le_Lp_mul_Lq` : ℝ≥0 functions.
-/
noncomputable section
open scoped Classical
open NNReal ENNReal MeasureTheory Finset
set_option linter.uppercaseLean3 false
variable {α : Type*} [MeasurableSpace α] {μ : Measure α}
namespace ENNReal
theorem lintegral_mul_le_one_of_lintegral_rpow_eq_one {p q : ℝ} (hpq : p.IsConjExponent q)
{f g : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hf_norm : ∫⁻ a, f a ^ p ∂μ = 1)
(hg_norm : ∫⁻ a, g a ^ q ∂μ = 1) : (∫⁻ a, (f * g) a ∂μ) ≤ 1 := by
calc
(∫⁻ a : α, (f * g) a ∂μ) ≤
∫⁻ a : α, f a ^ p / ENNReal.ofReal p + g a ^ q / ENNReal.ofReal q ∂μ :=
lintegral_mono fun a => young_inequality (f a) (g a) hpq
_ = 1 := by
simp only [div_eq_mul_inv]
rw [lintegral_add_left']
· rw [lintegral_mul_const'' _ (hf.pow_const p), lintegral_mul_const', hf_norm, hg_norm,
one_mul, one_mul, hpq.inv_add_inv_conj_ennreal]
simp [hpq.symm.pos]
· exact (hf.pow_const _).mul_const _
#align ennreal.lintegral_mul_le_one_of_lintegral_rpow_eq_one ENNReal.lintegral_mul_le_one_of_lintegral_rpow_eq_one
/-- Function multiplied by the inverse of its p-seminorm `(∫⁻ f^p ∂μ) ^ 1/p`-/
def funMulInvSnorm (f : α → ℝ≥0∞) (p : ℝ) (μ : Measure α) : α → ℝ≥0∞ := fun a =>
f a * ((∫⁻ c, f c ^ p ∂μ) ^ (1 / p))⁻¹
#align ennreal.fun_mul_inv_snorm ENNReal.funMulInvSnorm
theorem fun_eq_funMulInvSnorm_mul_snorm {p : ℝ} (f : α → ℝ≥0∞) (hf_nonzero : (∫⁻ a, f a ^ p ∂μ) ≠ 0)
(hf_top : (∫⁻ a, f a ^ p ∂μ) ≠ ⊤) {a : α} :
f a = funMulInvSnorm f p μ a * (∫⁻ c, f c ^ p ∂μ) ^ (1 / p) := by
simp [funMulInvSnorm, mul_assoc, ENNReal.inv_mul_cancel, hf_nonzero, hf_top]
#align ennreal.fun_eq_fun_mul_inv_snorm_mul_snorm ENNReal.fun_eq_funMulInvSnorm_mul_snorm
theorem funMulInvSnorm_rpow {p : ℝ} (hp0 : 0 < p) {f : α → ℝ≥0∞} {a : α} :
funMulInvSnorm f p μ a ^ p = f a ^ p * (∫⁻ c, f c ^ p ∂μ)⁻¹ := by
rw [funMulInvSnorm, mul_rpow_of_nonneg _ _ (le_of_lt hp0)]
suffices h_inv_rpow : ((∫⁻ c : α, f c ^ p ∂μ) ^ (1 / p))⁻¹ ^ p = (∫⁻ c : α, f c ^ p ∂μ)⁻¹ by
rw [h_inv_rpow]
rw [inv_rpow, ← rpow_mul, one_div_mul_cancel hp0.ne', rpow_one]
#align ennreal.fun_mul_inv_snorm_rpow ENNReal.funMulInvSnorm_rpow
theorem lintegral_rpow_funMulInvSnorm_eq_one {p : ℝ} (hp0_lt : 0 < p) {f : α → ℝ≥0∞}
(hf_nonzero : (∫⁻ a, f a ^ p ∂μ) ≠ 0) (hf_top : (∫⁻ a, f a ^ p ∂μ) ≠ ⊤) :
∫⁻ c, funMulInvSnorm f p μ c ^ p ∂μ = 1 := by
simp_rw [funMulInvSnorm_rpow hp0_lt]
rw [lintegral_mul_const', ENNReal.mul_inv_cancel hf_nonzero hf_top]
rwa [inv_ne_top]
#align ennreal.lintegral_rpow_fun_mul_inv_snorm_eq_one ENNReal.lintegral_rpow_funMulInvSnorm_eq_one
/-- Hölder's inequality in case of finite non-zero integrals -/
theorem lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_ne_top {p q : ℝ} (hpq : p.IsConjExponent q)
{f g : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hf_nontop : (∫⁻ a, f a ^ p ∂μ) ≠ ⊤)
(hg_nontop : (∫⁻ a, g a ^ q ∂μ) ≠ ⊤) (hf_nonzero : (∫⁻ a, f a ^ p ∂μ) ≠ 0)
(hg_nonzero : (∫⁻ a, g a ^ q ∂μ) ≠ 0) :
(∫⁻ a, (f * g) a ∂μ) ≤ (∫⁻ a, f a ^ p ∂μ) ^ (1 / p) * (∫⁻ a, g a ^ q ∂μ) ^ (1 / q) := by
let npf := (∫⁻ c : α, f c ^ p ∂μ) ^ (1 / p)
let nqg := (∫⁻ c : α, g c ^ q ∂μ) ^ (1 / q)
calc
(∫⁻ a : α, (f * g) a ∂μ) =
∫⁻ a : α, (funMulInvSnorm f p μ * funMulInvSnorm g q μ) a * (npf * nqg) ∂μ := by
refine lintegral_congr fun a => ?_
rw [Pi.mul_apply, fun_eq_funMulInvSnorm_mul_snorm f hf_nonzero hf_nontop,
fun_eq_funMulInvSnorm_mul_snorm g hg_nonzero hg_nontop, Pi.mul_apply]
ring
_ ≤ npf * nqg := by
rw [lintegral_mul_const' (npf * nqg) _
(by simp [npf, nqg, hf_nontop, hg_nontop, hf_nonzero, hg_nonzero, ENNReal.mul_eq_top])]
refine mul_le_of_le_one_left' ?_
have hf1 := lintegral_rpow_funMulInvSnorm_eq_one hpq.pos hf_nonzero hf_nontop
have hg1 := lintegral_rpow_funMulInvSnorm_eq_one hpq.symm.pos hg_nonzero hg_nontop
exact lintegral_mul_le_one_of_lintegral_rpow_eq_one hpq (hf.mul_const _) hf1 hg1
#align ennreal.lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_ne_top ENNReal.lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_ne_top
theorem ae_eq_zero_of_lintegral_rpow_eq_zero {p : ℝ} (hp0 : 0 ≤ p) {f : α → ℝ≥0∞}
(hf : AEMeasurable f μ) (hf_zero : ∫⁻ a, f a ^ p ∂μ = 0) : f =ᵐ[μ] 0 := by
rw [lintegral_eq_zero_iff' (hf.pow_const p)] at hf_zero
filter_upwards [hf_zero] with x
rw [Pi.zero_apply, ← not_imp_not]
exact fun hx => (rpow_pos_of_nonneg (pos_iff_ne_zero.2 hx) hp0).ne'
#align ennreal.ae_eq_zero_of_lintegral_rpow_eq_zero ENNReal.ae_eq_zero_of_lintegral_rpow_eq_zero
theorem lintegral_mul_eq_zero_of_lintegral_rpow_eq_zero {p : ℝ} (hp0 : 0 ≤ p) {f g : α → ℝ≥0∞}
(hf : AEMeasurable f μ) (hf_zero : ∫⁻ a, f a ^ p ∂μ = 0) : (∫⁻ a, (f * g) a ∂μ) = 0 := by
rw [← @lintegral_zero_fun α _ μ]
refine lintegral_congr_ae ?_
suffices h_mul_zero : f * g =ᵐ[μ] 0 * g by rwa [zero_mul] at h_mul_zero
have hf_eq_zero : f =ᵐ[μ] 0 := ae_eq_zero_of_lintegral_rpow_eq_zero hp0 hf hf_zero
exact hf_eq_zero.mul (ae_eq_refl g)
#align ennreal.lintegral_mul_eq_zero_of_lintegral_rpow_eq_zero ENNReal.lintegral_mul_eq_zero_of_lintegral_rpow_eq_zero
theorem lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_eq_top {p q : ℝ} (hp0_lt : 0 < p) (hq0 : 0 ≤ q)
{f g : α → ℝ≥0∞} (hf_top : ∫⁻ a, f a ^ p ∂μ = ⊤) (hg_nonzero : (∫⁻ a, g a ^ q ∂μ) ≠ 0) :
(∫⁻ a, (f * g) a ∂μ) ≤ (∫⁻ a, f a ^ p ∂μ) ^ (1 / p) * (∫⁻ a, g a ^ q ∂μ) ^ (1 / q) := by
refine le_trans le_top (le_of_eq ?_)
have hp0_inv_lt : 0 < 1 / p := by simp [hp0_lt]
rw [hf_top, ENNReal.top_rpow_of_pos hp0_inv_lt]
simp [hq0, hg_nonzero]
#align ennreal.lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_eq_top ENNReal.lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_eq_top
/-- Hölder's inequality for functions `α → ℝ≥0∞`. The integral of the product of two functions
is bounded by the product of their `ℒp` and `ℒq` seminorms when `p` and `q` are conjugate
exponents. -/
theorem lintegral_mul_le_Lp_mul_Lq (μ : Measure α) {p q : ℝ} (hpq : p.IsConjExponent q)
{f g : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) :
(∫⁻ a, (f * g) a ∂μ) ≤ (∫⁻ a, f a ^ p ∂μ) ^ (1 / p) * (∫⁻ a, g a ^ q ∂μ) ^ (1 / q) := by
by_cases hf_zero : ∫⁻ a, f a ^ p ∂μ = 0
· refine Eq.trans_le ?_ (zero_le _)
exact lintegral_mul_eq_zero_of_lintegral_rpow_eq_zero hpq.nonneg hf hf_zero
by_cases hg_zero : ∫⁻ a, g a ^ q ∂μ = 0
· refine Eq.trans_le ?_ (zero_le _)
rw [mul_comm]
exact lintegral_mul_eq_zero_of_lintegral_rpow_eq_zero hpq.symm.nonneg hg hg_zero
by_cases hf_top : ∫⁻ a, f a ^ p ∂μ = ⊤
· exact lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_eq_top hpq.pos hpq.symm.nonneg hf_top hg_zero
by_cases hg_top : ∫⁻ a, g a ^ q ∂μ = ⊤
· rw [mul_comm, mul_comm ((∫⁻ a : α, f a ^ p ∂μ) ^ (1 / p))]
exact lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_eq_top hpq.symm.pos hpq.nonneg hg_top hf_zero
-- non-⊤ non-zero case
exact ENNReal.lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_ne_top hpq hf hf_top hg_top hf_zero hg_zero
#align ennreal.lintegral_mul_le_Lp_mul_Lq ENNReal.lintegral_mul_le_Lp_mul_Lq
/-- A different formulation of Hölder's inequality for two functions, with two exponents that sum to
1, instead of reciprocals of -/
theorem lintegral_mul_norm_pow_le {α} [MeasurableSpace α] {μ : Measure α}
{f g : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ)
{p q : ℝ} (hp : 0 ≤ p) (hq : 0 ≤ q) (hpq : p + q = 1) :
∫⁻ a, f a ^ p * g a ^ q ∂μ ≤ (∫⁻ a, f a ∂μ) ^ p * (∫⁻ a, g a ∂μ) ^ q := by
rcases hp.eq_or_lt with rfl|hp
· rw [zero_add] at hpq
simp [hpq]
rcases hq.eq_or_lt with rfl|hq
· rw [add_zero] at hpq
simp [hpq]
have h2p : 1 < 1 / p := by
rw [one_div]
apply one_lt_inv hp
linarith
have h2pq : (1 / p)⁻¹ + (1 / q)⁻¹ = 1 := by simp [hp.ne', hq.ne', hpq]
have := ENNReal.lintegral_mul_le_Lp_mul_Lq μ ⟨h2p, h2pq⟩ (hf.pow_const p) (hg.pow_const q)
simpa [← ENNReal.rpow_mul, hp.ne', hq.ne'] using this
/-- A version of Hölder with multiple arguments -/
theorem lintegral_prod_norm_pow_le {α ι : Type*} [MeasurableSpace α] {μ : Measure α}
(s : Finset ι) {f : ι → α → ℝ≥0∞} (hf : ∀ i ∈ s, AEMeasurable (f i) μ)
{p : ι → ℝ} (hp : ∑ i ∈ s, p i = 1) (h2p : ∀ i ∈ s, 0 ≤ p i) :
∫⁻ a, ∏ i ∈ s, f i a ^ p i ∂μ ≤ ∏ i ∈ s, (∫⁻ a, f i a ∂μ) ^ p i := by
induction s using Finset.induction generalizing p with
| empty =>
simp at hp
| @insert i₀ s hi₀ ih =>
rcases eq_or_ne (p i₀) 1 with h2i₀|h2i₀
· simp [hi₀]
have h2p : ∀ i ∈ s, p i = 0 := by
simpa [hi₀, h2i₀, sum_eq_zero_iff_of_nonneg (fun i hi ↦ h2p i <| mem_insert_of_mem hi)]
using hp
calc ∫⁻ a, f i₀ a ^ p i₀ * ∏ i ∈ s, f i a ^ p i ∂μ
= ∫⁻ a, f i₀ a ^ p i₀ * ∏ i ∈ s, 1 ∂μ := by
congr! 3 with x
apply prod_congr rfl fun i hi ↦ by rw [h2p i hi, ENNReal.rpow_zero]
_ ≤ (∫⁻ a, f i₀ a ∂μ) ^ p i₀ * ∏ i ∈ s, 1 := by simp [h2i₀]
_ = (∫⁻ a, f i₀ a ∂μ) ^ p i₀ * ∏ i ∈ s, (∫⁻ a, f i a ∂μ) ^ p i := by
congr 1
apply prod_congr rfl fun i hi ↦ by rw [h2p i hi, ENNReal.rpow_zero]
· have hpi₀ : 0 ≤ 1 - p i₀ := by
simp_rw [sub_nonneg, ← hp, single_le_sum h2p (mem_insert_self ..)]
have h2pi₀ : 1 - p i₀ ≠ 0 := by
rwa [sub_ne_zero, ne_comm]
let q := fun i ↦ p i / (1 - p i₀)
have hq : ∑ i ∈ s, q i = 1 := by
rw [← Finset.sum_div, ← sum_insert_sub hi₀, hp, div_self h2pi₀]
have h2q : ∀ i ∈ s, 0 ≤ q i :=
fun i hi ↦ div_nonneg (h2p i <| mem_insert_of_mem hi) hpi₀
calc ∫⁻ a, ∏ i ∈ insert i₀ s, f i a ^ p i ∂μ
= ∫⁻ a, f i₀ a ^ p i₀ * ∏ i ∈ s, f i a ^ p i ∂μ := by simp [hi₀]
_ = ∫⁻ a, f i₀ a ^ p i₀ * (∏ i ∈ s, f i a ^ q i) ^ (1 - p i₀) ∂μ := by
simp [← ENNReal.prod_rpow_of_nonneg hpi₀, ← ENNReal.rpow_mul,
div_mul_cancel₀ (h := h2pi₀)]
_ ≤ (∫⁻ a, f i₀ a ∂μ) ^ p i₀ * (∫⁻ a, ∏ i ∈ s, f i a ^ q i ∂μ) ^ (1 - p i₀) := by
apply ENNReal.lintegral_mul_norm_pow_le
· exact hf i₀ <| mem_insert_self ..
· exact s.aemeasurable_prod fun i hi ↦ (hf i <| mem_insert_of_mem hi).pow_const _
· exact h2p i₀ <| mem_insert_self ..
· exact hpi₀
· apply add_sub_cancel
_ ≤ (∫⁻ a, f i₀ a ∂μ) ^ p i₀ * (∏ i ∈ s, (∫⁻ a, f i a ∂μ) ^ q i) ^ (1 - p i₀) := by
gcongr -- behavior of gcongr is heartbeat-dependent, which makes code really fragile...
exact ih (fun i hi ↦ hf i <| mem_insert_of_mem hi) hq h2q
_ = (∫⁻ a, f i₀ a ∂μ) ^ p i₀ * ∏ i ∈ s, (∫⁻ a, f i a ∂μ) ^ p i := by
simp [← ENNReal.prod_rpow_of_nonneg hpi₀, ← ENNReal.rpow_mul,
div_mul_cancel₀ (h := h2pi₀)]
_ = ∏ i ∈ insert i₀ s, (∫⁻ a, f i a ∂μ) ^ p i := by simp [hi₀]
/-- A version of Hölder with multiple arguments, one of which plays a distinguished role. -/
theorem lintegral_mul_prod_norm_pow_le {α ι : Type*} [MeasurableSpace α] {μ : Measure α}
(s : Finset ι) {g : α → ℝ≥0∞} {f : ι → α → ℝ≥0∞} (hg : AEMeasurable g μ)
(hf : ∀ i ∈ s, AEMeasurable (f i) μ) (q : ℝ) {p : ι → ℝ} (hpq : q + ∑ i ∈ s, p i = 1)
(hq : 0 ≤ q) (hp : ∀ i ∈ s, 0 ≤ p i) :
∫⁻ a, g a ^ q * ∏ i ∈ s, f i a ^ p i ∂μ ≤
(∫⁻ a, g a ∂μ) ^ q * ∏ i ∈ s, (∫⁻ a, f i a ∂μ) ^ p i := by
suffices
∫⁻ t, ∏ j ∈ insertNone s, Option.elim j (g t) (fun j ↦ f j t) ^ Option.elim j q p ∂μ
≤ ∏ j ∈ insertNone s, (∫⁻ t, Option.elim j (g t) (fun j ↦ f j t) ∂μ) ^ Option.elim j q p by
simpa using this
refine ENNReal.lintegral_prod_norm_pow_le _ ?_ ?_ ?_
· rintro (_|i) hi
· exact hg
· refine hf i ?_
simpa using hi
· simp_rw [sum_insertNone, Option.elim]
exact hpq
· rintro (_|i) hi
· exact hq
· refine hp i ?_
simpa using hi
theorem lintegral_rpow_add_lt_top_of_lintegral_rpow_lt_top {p : ℝ} {f g : α → ℝ≥0∞}
(hf : AEMeasurable f μ) (hf_top : (∫⁻ a, f a ^ p ∂μ) < ⊤) (hg_top : (∫⁻ a, g a ^ p ∂μ) < ⊤)
(hp1 : 1 ≤ p) : (∫⁻ a, (f + g) a ^ p ∂μ) < ⊤ := by
have hp0_lt : 0 < p := lt_of_lt_of_le zero_lt_one hp1
have hp0 : 0 ≤ p := le_of_lt hp0_lt
calc
(∫⁻ a : α, (f a + g a) ^ p ∂μ) ≤
∫⁻ a, (2 : ℝ≥0∞) ^ (p - 1) * f a ^ p + (2 : ℝ≥0∞) ^ (p - 1) * g a ^ p ∂μ := by
refine lintegral_mono fun a => ?_
dsimp only
have h_zero_lt_half_rpow : (0 : ℝ≥0∞) < (1 / 2 : ℝ≥0∞) ^ p := by
rw [← ENNReal.zero_rpow_of_pos hp0_lt]
exact ENNReal.rpow_lt_rpow (by simp [zero_lt_one]) hp0_lt
have h_rw : (1 / 2 : ℝ≥0∞) ^ p * (2 : ℝ≥0∞) ^ (p - 1) = 1 / 2 := by
rw [sub_eq_add_neg, ENNReal.rpow_add _ _ two_ne_zero ENNReal.coe_ne_top, ← mul_assoc, ←
ENNReal.mul_rpow_of_nonneg _ _ hp0, one_div,
ENNReal.inv_mul_cancel two_ne_zero ENNReal.coe_ne_top, ENNReal.one_rpow, one_mul,
ENNReal.rpow_neg_one]
rw [← ENNReal.mul_le_mul_left (ne_of_lt h_zero_lt_half_rpow).symm _]
· rw [mul_add, ← mul_assoc, ← mul_assoc, h_rw, ← ENNReal.mul_rpow_of_nonneg _ _ hp0, mul_add]
refine
ENNReal.rpow_arith_mean_le_arith_mean2_rpow (1 / 2 : ℝ≥0∞) (1 / 2 : ℝ≥0∞) (f a) (g a) ?_
hp1
rw [ENNReal.div_add_div_same, one_add_one_eq_two,
ENNReal.div_self two_ne_zero ENNReal.coe_ne_top]
· rw [← lt_top_iff_ne_top]
refine ENNReal.rpow_lt_top_of_nonneg hp0 ?_
rw [one_div, ENNReal.inv_ne_top]
exact two_ne_zero
_ < ⊤ := by
have h_two : (2 : ℝ≥0∞) ^ (p - 1) ≠ ⊤ :=
ENNReal.rpow_ne_top_of_nonneg (by simp [hp1]) ENNReal.coe_ne_top
rw [lintegral_add_left', lintegral_const_mul'' _ (hf.pow_const p),
lintegral_const_mul' _ _ h_two, ENNReal.add_lt_top]
· exact ⟨ENNReal.mul_lt_top h_two hf_top.ne, ENNReal.mul_lt_top h_two hg_top.ne⟩
· exact (hf.pow_const p).const_mul _
#align ennreal.lintegral_rpow_add_lt_top_of_lintegral_rpow_lt_top ENNReal.lintegral_rpow_add_lt_top_of_lintegral_rpow_lt_top
theorem lintegral_Lp_mul_le_Lq_mul_Lr {α} [MeasurableSpace α] {p q r : ℝ} (hp0_lt : 0 < p)
(hpq : p < q) (hpqr : 1 / p = 1 / q + 1 / r) (μ : Measure α) {f g : α → ℝ≥0∞}
(hf : AEMeasurable f μ) (hg : AEMeasurable g μ) :
(∫⁻ a, (f * g) a ^ p ∂μ) ^ (1 / p) ≤
(∫⁻ a, f a ^ q ∂μ) ^ (1 / q) * (∫⁻ a, g a ^ r ∂μ) ^ (1 / r) := by
have hp0_ne : p ≠ 0 := (ne_of_lt hp0_lt).symm
have hp0 : 0 ≤ p := le_of_lt hp0_lt
have hq0_lt : 0 < q := lt_of_le_of_lt hp0 hpq
have hq0_ne : q ≠ 0 := (ne_of_lt hq0_lt).symm
have h_one_div_r : 1 / r = 1 / p - 1 / q := by rw [hpqr]; simp
let p2 := q / p
let q2 := p2.conjExponent
have hp2q2 : p2.IsConjExponent q2 :=
.conjExponent (by simp [p2, q2, _root_.lt_div_iff, hpq, hp0_lt])
calc
(∫⁻ a : α, (f * g) a ^ p ∂μ) ^ (1 / p) = (∫⁻ a : α, f a ^ p * g a ^ p ∂μ) ^ (1 / p) := by
simp_rw [Pi.mul_apply, ENNReal.mul_rpow_of_nonneg _ _ hp0]
_ ≤ ((∫⁻ a, f a ^ (p * p2) ∂μ) ^ (1 / p2) *
(∫⁻ a, g a ^ (p * q2) ∂μ) ^ (1 / q2)) ^ (1 / p) := by
gcongr
simp_rw [ENNReal.rpow_mul]
exact ENNReal.lintegral_mul_le_Lp_mul_Lq μ hp2q2 (hf.pow_const _) (hg.pow_const _)
_ = (∫⁻ a : α, f a ^ q ∂μ) ^ (1 / q) * (∫⁻ a : α, g a ^ r ∂μ) ^ (1 / r) := by
rw [@ENNReal.mul_rpow_of_nonneg _ _ (1 / p) (by simp [hp0]), ← ENNReal.rpow_mul, ←
ENNReal.rpow_mul]
have hpp2 : p * p2 = q := by
symm
rw [mul_comm, ← div_eq_iff hp0_ne]
have hpq2 : p * q2 = r := by
rw [← inv_inv r, ← one_div, ← one_div, h_one_div_r]
field_simp [p2, q2, Real.conjExponent, hp0_ne, hq0_ne]
simp_rw [div_mul_div_comm, mul_one, mul_comm p2, mul_comm q2, hpp2, hpq2]
#align ennreal.lintegral_Lp_mul_le_Lq_mul_Lr ENNReal.lintegral_Lp_mul_le_Lq_mul_Lr
theorem lintegral_mul_rpow_le_lintegral_rpow_mul_lintegral_rpow {p q : ℝ}
(hpq : p.IsConjExponent q) {f g : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ)
(hf_top : (∫⁻ a, f a ^ p ∂μ) ≠ ⊤) :
(∫⁻ a, f a * g a ^ (p - 1) ∂μ) ≤
(∫⁻ a, f a ^ p ∂μ) ^ (1 / p) * (∫⁻ a, g a ^ p ∂μ) ^ (1 / q) := by
refine le_trans (ENNReal.lintegral_mul_le_Lp_mul_Lq μ hpq hf (hg.pow_const _)) ?_
by_cases hf_zero_rpow : (∫⁻ a : α, f a ^ p ∂μ) ^ (1 / p) = 0
· rw [hf_zero_rpow, zero_mul]
exact zero_le _
have hf_top_rpow : (∫⁻ a : α, f a ^ p ∂μ) ^ (1 / p) ≠ ⊤ := by
by_contra h
refine hf_top ?_
have hp_not_neg : ¬p < 0 := by simp [hpq.nonneg]
simpa [hpq.pos, hp_not_neg] using h
refine (ENNReal.mul_le_mul_left hf_zero_rpow hf_top_rpow).mpr (le_of_eq ?_)
congr
ext1 a
rw [← ENNReal.rpow_mul, hpq.sub_one_mul_conj]
#align ennreal.lintegral_mul_rpow_le_lintegral_rpow_mul_lintegral_rpow ENNReal.lintegral_mul_rpow_le_lintegral_rpow_mul_lintegral_rpow
theorem lintegral_rpow_add_le_add_snorm_mul_lintegral_rpow_add {p q : ℝ}
(hpq : p.IsConjExponent q) {f g : α → ℝ≥0∞} (hf : AEMeasurable f μ)
(hf_top : (∫⁻ a, f a ^ p ∂μ) ≠ ⊤) (hg : AEMeasurable g μ) (hg_top : (∫⁻ a, g a ^ p ∂μ) ≠ ⊤) :
(∫⁻ a, (f + g) a ^ p ∂μ) ≤
((∫⁻ a, f a ^ p ∂μ) ^ (1 / p) + (∫⁻ a, g a ^ p ∂μ) ^ (1 / p)) *
(∫⁻ a, (f a + g a) ^ p ∂μ) ^ (1 / q) := by
calc
(∫⁻ a, (f + g) a ^ p ∂μ) ≤ ∫⁻ a, (f + g) a * (f + g) a ^ (p - 1) ∂μ := by
gcongr with a
by_cases h_zero : (f + g) a = 0
· rw [h_zero, ENNReal.zero_rpow_of_pos hpq.pos]
exact zero_le _
by_cases h_top : (f + g) a = ⊤
· rw [h_top, ENNReal.top_rpow_of_pos hpq.sub_one_pos, ENNReal.top_mul_top]
exact le_top
refine le_of_eq ?_
nth_rw 2 [← ENNReal.rpow_one ((f + g) a)]
rw [← ENNReal.rpow_add _ _ h_zero h_top, add_sub_cancel]
_ = (∫⁻ a : α, f a * (f + g) a ^ (p - 1) ∂μ) + ∫⁻ a : α, g a * (f + g) a ^ (p - 1) ∂μ := by
have h_add_m : AEMeasurable (fun a : α => (f + g) a ^ (p - 1 : ℝ)) μ :=
(hf.add hg).pow_const _
have h_add_apply :
(∫⁻ a : α, (f + g) a * (f + g) a ^ (p - 1) ∂μ) =
∫⁻ a : α, (f a + g a) * (f + g) a ^ (p - 1) ∂μ :=
rfl
simp_rw [h_add_apply, add_mul]
rw [lintegral_add_left' (hf.mul h_add_m)]
_ ≤
((∫⁻ a, f a ^ p ∂μ) ^ (1 / p) + (∫⁻ a, g a ^ p ∂μ) ^ (1 / p)) *
(∫⁻ a, (f a + g a) ^ p ∂μ) ^ (1 / q) := by
rw [add_mul]
gcongr
· exact lintegral_mul_rpow_le_lintegral_rpow_mul_lintegral_rpow hpq hf (hf.add hg) hf_top
· exact lintegral_mul_rpow_le_lintegral_rpow_mul_lintegral_rpow hpq hg (hf.add hg) hg_top
#align ennreal.lintegral_rpow_add_le_add_snorm_mul_lintegral_rpow_add ENNReal.lintegral_rpow_add_le_add_snorm_mul_lintegral_rpow_add
private theorem lintegral_Lp_add_le_aux {p q : ℝ} (hpq : p.IsConjExponent q) {f g : α → ℝ≥0∞}
(hf : AEMeasurable f μ) (hf_top : (∫⁻ a, f a ^ p ∂μ) ≠ ⊤) (hg : AEMeasurable g μ)
(hg_top : (∫⁻ a, g a ^ p ∂μ) ≠ ⊤) (h_add_zero : (∫⁻ a, (f + g) a ^ p ∂μ) ≠ 0)
(h_add_top : (∫⁻ a, (f + g) a ^ p ∂μ) ≠ ⊤) :
(∫⁻ a, (f + g) a ^ p ∂μ) ^ (1 / p) ≤
(∫⁻ a, f a ^ p ∂μ) ^ (1 / p) + (∫⁻ a, g a ^ p ∂μ) ^ (1 / p) := by
have hp_not_nonpos : ¬p ≤ 0 := by simp [hpq.pos]
have htop_rpow : (∫⁻ a, (f + g) a ^ p ∂μ) ^ (1 / p) ≠ ⊤ := by
by_contra h
exact h_add_top (@ENNReal.rpow_eq_top_of_nonneg _ (1 / p) (by simp [hpq.nonneg]) h)
have h0_rpow : (∫⁻ a, (f + g) a ^ p ∂μ) ^ (1 / p) ≠ 0 := by
simp [h_add_zero, h_add_top, hpq.nonneg, hp_not_nonpos, -Pi.add_apply]
suffices h :
1 ≤
(∫⁻ a : α, (f + g) a ^ p ∂μ) ^ (-(1 / p)) *
((∫⁻ a : α, f a ^ p ∂μ) ^ (1 / p) + (∫⁻ a : α, g a ^ p ∂μ) ^ (1 / p)) by
rwa [← mul_le_mul_left h0_rpow htop_rpow, ← mul_assoc, ← rpow_add _ _ h_add_zero h_add_top, ←
sub_eq_add_neg, _root_.sub_self, rpow_zero, one_mul, mul_one] at h
have h :
(∫⁻ a : α, (f + g) a ^ p ∂μ) ≤
((∫⁻ a : α, f a ^ p ∂μ) ^ (1 / p) + (∫⁻ a : α, g a ^ p ∂μ) ^ (1 / p)) *
(∫⁻ a : α, (f + g) a ^ p ∂μ) ^ (1 / q) :=
lintegral_rpow_add_le_add_snorm_mul_lintegral_rpow_add hpq hf hf_top hg hg_top
have h_one_div_q : 1 / q = 1 - 1 / p := by
nth_rw 2 [← hpq.inv_add_inv_conj]
ring
simp_rw [h_one_div_q, sub_eq_add_neg 1 (1 / p), ENNReal.rpow_add _ _ h_add_zero h_add_top,
rpow_one] at h
conv_rhs at h => enter [2]; rw [mul_comm]
conv_lhs at h => rw [← one_mul (∫⁻ a : α, (f + g) a ^ p ∂μ)]
rwa [← mul_assoc, ENNReal.mul_le_mul_right h_add_zero h_add_top, mul_comm] at h
/-- **Minkowski's inequality for functions** `α → ℝ≥0∞`: the `ℒp` seminorm of the sum of two
functions is bounded by the sum of their `ℒp` seminorms. -/
| Mathlib/MeasureTheory/Integral/MeanInequalities.lean | 437 | 462 | theorem lintegral_Lp_add_le {p : ℝ} {f g : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ)
(hp1 : 1 ≤ p) :
(∫⁻ a, (f + g) a ^ p ∂μ) ^ (1 / p) ≤
(∫⁻ a, f a ^ p ∂μ) ^ (1 / p) + (∫⁻ a, g a ^ p ∂μ) ^ (1 / p) := by |
have hp_pos : 0 < p := lt_of_lt_of_le zero_lt_one hp1
by_cases hf_top : ∫⁻ a, f a ^ p ∂μ = ⊤
· simp [hf_top, hp_pos]
by_cases hg_top : ∫⁻ a, g a ^ p ∂μ = ⊤
· simp [hg_top, hp_pos]
by_cases h1 : p = 1
· refine le_of_eq ?_
simp_rw [h1, one_div_one, ENNReal.rpow_one]
exact lintegral_add_left' hf _
have hp1_lt : 1 < p := by
refine lt_of_le_of_ne hp1 ?_
symm
exact h1
have hpq := Real.IsConjExponent.conjExponent hp1_lt
by_cases h0 : (∫⁻ a, (f + g) a ^ p ∂μ) = 0
· rw [h0, @ENNReal.zero_rpow_of_pos (1 / p) (by simp [lt_of_lt_of_le zero_lt_one hp1])]
exact zero_le _
have htop : (∫⁻ a, (f + g) a ^ p ∂μ) ≠ ⊤ := by
rw [← Ne] at hf_top hg_top
rw [← lt_top_iff_ne_top] at hf_top hg_top ⊢
exact lintegral_rpow_add_lt_top_of_lintegral_rpow_lt_top hf hf_top hg_top hp1
exact lintegral_Lp_add_le_aux hpq hf hf_top hg hg_top h0 htop
|
/-
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.Topology.Separation
import Mathlib.Topology.UniformSpace.Basic
import Mathlib.Topology.UniformSpace.Cauchy
#align_import topology.uniform_space.uniform_convergence from "leanprover-community/mathlib"@"2705404e701abc6b3127da906f40bae062a169c9"
/-!
# Uniform convergence
A sequence of functions `Fₙ` (with values in a metric space) converges uniformly on a set `s` to a
function `f` if, for all `ε > 0`, for all large enough `n`, one has for all `y ∈ s` the inequality
`dist (f y, Fₙ y) < ε`. Under uniform convergence, many properties of the `Fₙ` pass to the limit,
most notably continuity. We prove this in the file, defining the notion of uniform convergence
in the more general setting of uniform spaces, and with respect to an arbitrary indexing set
endowed with a filter (instead of just `ℕ` with `atTop`).
## Main results
Let `α` be a topological space, `β` a uniform space, `Fₙ` and `f` be functions from `α` to `β`
(where the index `n` belongs to an indexing type `ι` endowed with a filter `p`).
* `TendstoUniformlyOn F f p s`: the fact that `Fₙ` converges uniformly to `f` on `s`. This means
that, for any entourage `u` of the diagonal, for large enough `n` (with respect to `p`), one has
`(f y, Fₙ y) ∈ u` for all `y ∈ s`.
* `TendstoUniformly F f p`: same notion with `s = univ`.
* `TendstoUniformlyOn.continuousOn`: a uniform limit on a set of functions which are continuous
on this set is itself continuous on this set.
* `TendstoUniformly.continuous`: a uniform limit of continuous functions is continuous.
* `TendstoUniformlyOn.tendsto_comp`: If `Fₙ` tends uniformly to `f` on a set `s`, and `gₙ` tends
to `x` within `s`, then `Fₙ gₙ` tends to `f x` if `f` is continuous at `x` within `s`.
* `TendstoUniformly.tendsto_comp`: If `Fₙ` tends uniformly to `f`, and `gₙ` tends to `x`, then
`Fₙ gₙ` tends to `f x`.
We also define notions where the convergence is locally uniform, called
`TendstoLocallyUniformlyOn F f p s` and `TendstoLocallyUniformly F f p`. The previous theorems
all have corresponding versions under locally uniform convergence.
Finally, we introduce the notion of a uniform Cauchy sequence, which is to uniform
convergence what a Cauchy sequence is to the usual notion of convergence.
## Implementation notes
We derive most of our initial results from an auxiliary definition `TendstoUniformlyOnFilter`.
This definition in and of itself can sometimes be useful, e.g., when studying the local behavior
of the `Fₙ` near a point, which would typically look like `TendstoUniformlyOnFilter F f p (𝓝 x)`.
Still, while this may be the "correct" definition (see
`tendstoUniformlyOn_iff_tendstoUniformlyOnFilter`), it is somewhat unwieldy to work with in
practice. Thus, we provide the more traditional definition in `TendstoUniformlyOn`.
Most results hold under weaker assumptions of locally uniform approximation. In a first section,
we prove the results under these weaker assumptions. Then, we derive the results on uniform
convergence from them.
## Tags
Uniform limit, uniform convergence, tends uniformly to
-/
noncomputable section
open Topology Uniformity Filter Set
universe u v w x
variable {α : Type u} {β : Type v} {γ : Type w} {ι : Type x} [UniformSpace β]
variable {F : ι → α → β} {f : α → β} {s s' : Set α} {x : α} {p : Filter ι} {p' : Filter α}
{g : ι → α}
/-!
### Different notions of uniform convergence
We define uniform convergence and locally uniform convergence, on a set or in the whole space.
-/
/-- A sequence of functions `Fₙ` converges uniformly on a filter `p'` to a limiting function `f`
with respect to the filter `p` if, for any entourage of the diagonal `u`, one has
`p ×ˢ p'`-eventually `(f x, Fₙ x) ∈ u`. -/
def TendstoUniformlyOnFilter (F : ι → α → β) (f : α → β) (p : Filter ι) (p' : Filter α) :=
∀ u ∈ 𝓤 β, ∀ᶠ n : ι × α in p ×ˢ p', (f n.snd, F n.fst n.snd) ∈ u
#align tendsto_uniformly_on_filter TendstoUniformlyOnFilter
/--
A sequence of functions `Fₙ` converges uniformly on a filter `p'` to a limiting function `f` w.r.t.
filter `p` iff the function `(n, x) ↦ (f x, Fₙ x)` converges along `p ×ˢ p'` to the uniformity.
In other words: one knows nothing about the behavior of `x` in this limit besides it being in `p'`.
-/
theorem tendstoUniformlyOnFilter_iff_tendsto :
TendstoUniformlyOnFilter F f p p' ↔
Tendsto (fun q : ι × α => (f q.2, F q.1 q.2)) (p ×ˢ p') (𝓤 β) :=
Iff.rfl
#align tendsto_uniformly_on_filter_iff_tendsto tendstoUniformlyOnFilter_iff_tendsto
/-- A sequence of functions `Fₙ` converges uniformly on a set `s` to a limiting function `f` with
respect to the filter `p` if, for any entourage of the diagonal `u`, one has `p`-eventually
`(f x, Fₙ x) ∈ u` for all `x ∈ s`. -/
def TendstoUniformlyOn (F : ι → α → β) (f : α → β) (p : Filter ι) (s : Set α) :=
∀ u ∈ 𝓤 β, ∀ᶠ n in p, ∀ x : α, x ∈ s → (f x, F n x) ∈ u
#align tendsto_uniformly_on TendstoUniformlyOn
theorem tendstoUniformlyOn_iff_tendstoUniformlyOnFilter :
TendstoUniformlyOn F f p s ↔ TendstoUniformlyOnFilter F f p (𝓟 s) := by
simp only [TendstoUniformlyOn, TendstoUniformlyOnFilter]
apply forall₂_congr
simp_rw [eventually_prod_principal_iff]
simp
#align tendsto_uniformly_on_iff_tendsto_uniformly_on_filter tendstoUniformlyOn_iff_tendstoUniformlyOnFilter
alias ⟨TendstoUniformlyOn.tendstoUniformlyOnFilter, TendstoUniformlyOnFilter.tendstoUniformlyOn⟩ :=
tendstoUniformlyOn_iff_tendstoUniformlyOnFilter
#align tendsto_uniformly_on.tendsto_uniformly_on_filter TendstoUniformlyOn.tendstoUniformlyOnFilter
#align tendsto_uniformly_on_filter.tendsto_uniformly_on TendstoUniformlyOnFilter.tendstoUniformlyOn
/-- A sequence of functions `Fₙ` converges uniformly on a set `s` to a limiting function `f` w.r.t.
filter `p` iff the function `(n, x) ↦ (f x, Fₙ x)` converges along `p ×ˢ 𝓟 s` to the uniformity.
In other words: one knows nothing about the behavior of `x` in this limit besides it being in `s`.
-/
theorem tendstoUniformlyOn_iff_tendsto {F : ι → α → β} {f : α → β} {p : Filter ι} {s : Set α} :
TendstoUniformlyOn F f p s ↔
Tendsto (fun q : ι × α => (f q.2, F q.1 q.2)) (p ×ˢ 𝓟 s) (𝓤 β) := by
simp [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter, tendstoUniformlyOnFilter_iff_tendsto]
#align tendsto_uniformly_on_iff_tendsto tendstoUniformlyOn_iff_tendsto
/-- A sequence of functions `Fₙ` converges uniformly to a limiting function `f` with respect to a
filter `p` if, for any entourage of the diagonal `u`, one has `p`-eventually
`(f x, Fₙ x) ∈ u` for all `x`. -/
def TendstoUniformly (F : ι → α → β) (f : α → β) (p : Filter ι) :=
∀ u ∈ 𝓤 β, ∀ᶠ n in p, ∀ x : α, (f x, F n x) ∈ u
#align tendsto_uniformly TendstoUniformly
-- Porting note: moved from below
theorem tendstoUniformlyOn_univ : TendstoUniformlyOn F f p univ ↔ TendstoUniformly F f p := by
simp [TendstoUniformlyOn, TendstoUniformly]
#align tendsto_uniformly_on_univ tendstoUniformlyOn_univ
theorem tendstoUniformly_iff_tendstoUniformlyOnFilter :
TendstoUniformly F f p ↔ TendstoUniformlyOnFilter F f p ⊤ := by
rw [← tendstoUniformlyOn_univ, tendstoUniformlyOn_iff_tendstoUniformlyOnFilter, principal_univ]
#align tendsto_uniformly_iff_tendsto_uniformly_on_filter tendstoUniformly_iff_tendstoUniformlyOnFilter
theorem TendstoUniformly.tendstoUniformlyOnFilter (h : TendstoUniformly F f p) :
TendstoUniformlyOnFilter F f p ⊤ := by rwa [← tendstoUniformly_iff_tendstoUniformlyOnFilter]
#align tendsto_uniformly.tendsto_uniformly_on_filter TendstoUniformly.tendstoUniformlyOnFilter
theorem tendstoUniformlyOn_iff_tendstoUniformly_comp_coe :
TendstoUniformlyOn F f p s ↔ TendstoUniformly (fun i (x : s) => F i x) (f ∘ (↑)) p :=
forall₂_congr fun u _ => by simp
#align tendsto_uniformly_on_iff_tendsto_uniformly_comp_coe tendstoUniformlyOn_iff_tendstoUniformly_comp_coe
/-- A sequence of functions `Fₙ` converges uniformly to a limiting function `f` w.r.t.
filter `p` iff the function `(n, x) ↦ (f x, Fₙ x)` converges along `p ×ˢ ⊤` to the uniformity.
In other words: one knows nothing about the behavior of `x` in this limit.
-/
theorem tendstoUniformly_iff_tendsto {F : ι → α → β} {f : α → β} {p : Filter ι} :
TendstoUniformly F f p ↔ Tendsto (fun q : ι × α => (f q.2, F q.1 q.2)) (p ×ˢ ⊤) (𝓤 β) := by
simp [tendstoUniformly_iff_tendstoUniformlyOnFilter, tendstoUniformlyOnFilter_iff_tendsto]
#align tendsto_uniformly_iff_tendsto tendstoUniformly_iff_tendsto
/-- Uniform converence implies pointwise convergence. -/
theorem TendstoUniformlyOnFilter.tendsto_at (h : TendstoUniformlyOnFilter F f p p')
(hx : 𝓟 {x} ≤ p') : Tendsto (fun n => F n x) p <| 𝓝 (f x) := by
refine Uniform.tendsto_nhds_right.mpr fun u hu => mem_map.mpr ?_
filter_upwards [(h u hu).curry]
intro i h
simpa using h.filter_mono hx
#align tendsto_uniformly_on_filter.tendsto_at TendstoUniformlyOnFilter.tendsto_at
/-- Uniform converence implies pointwise convergence. -/
theorem TendstoUniformlyOn.tendsto_at (h : TendstoUniformlyOn F f p s) {x : α} (hx : x ∈ s) :
Tendsto (fun n => F n x) p <| 𝓝 (f x) :=
h.tendstoUniformlyOnFilter.tendsto_at
(le_principal_iff.mpr <| mem_principal.mpr <| singleton_subset_iff.mpr <| hx)
#align tendsto_uniformly_on.tendsto_at TendstoUniformlyOn.tendsto_at
/-- Uniform converence implies pointwise convergence. -/
theorem TendstoUniformly.tendsto_at (h : TendstoUniformly F f p) (x : α) :
Tendsto (fun n => F n x) p <| 𝓝 (f x) :=
h.tendstoUniformlyOnFilter.tendsto_at le_top
#align tendsto_uniformly.tendsto_at TendstoUniformly.tendsto_at
-- Porting note: tendstoUniformlyOn_univ moved up
theorem TendstoUniformlyOnFilter.mono_left {p'' : Filter ι} (h : TendstoUniformlyOnFilter F f p p')
(hp : p'' ≤ p) : TendstoUniformlyOnFilter F f p'' p' := fun u hu =>
(h u hu).filter_mono (p'.prod_mono_left hp)
#align tendsto_uniformly_on_filter.mono_left TendstoUniformlyOnFilter.mono_left
theorem TendstoUniformlyOnFilter.mono_right {p'' : Filter α} (h : TendstoUniformlyOnFilter F f p p')
(hp : p'' ≤ p') : TendstoUniformlyOnFilter F f p p'' := fun u hu =>
(h u hu).filter_mono (p.prod_mono_right hp)
#align tendsto_uniformly_on_filter.mono_right TendstoUniformlyOnFilter.mono_right
theorem TendstoUniformlyOn.mono {s' : Set α} (h : TendstoUniformlyOn F f p s) (h' : s' ⊆ s) :
TendstoUniformlyOn F f p s' :=
tendstoUniformlyOn_iff_tendstoUniformlyOnFilter.mpr
(h.tendstoUniformlyOnFilter.mono_right (le_principal_iff.mpr <| mem_principal.mpr h'))
#align tendsto_uniformly_on.mono TendstoUniformlyOn.mono
theorem TendstoUniformlyOnFilter.congr {F' : ι → α → β} (hf : TendstoUniformlyOnFilter F f p p')
(hff' : ∀ᶠ n : ι × α in p ×ˢ p', F n.fst n.snd = F' n.fst n.snd) :
TendstoUniformlyOnFilter F' f p p' := by
refine fun u hu => ((hf u hu).and hff').mono fun n h => ?_
rw [← h.right]
exact h.left
#align tendsto_uniformly_on_filter.congr TendstoUniformlyOnFilter.congr
theorem TendstoUniformlyOn.congr {F' : ι → α → β} (hf : TendstoUniformlyOn F f p s)
(hff' : ∀ᶠ n in p, Set.EqOn (F n) (F' n) s) : TendstoUniformlyOn F' f p s := by
rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter] at hf ⊢
refine hf.congr ?_
rw [eventually_iff] at hff' ⊢
simp only [Set.EqOn] at hff'
simp only [mem_prod_principal, hff', mem_setOf_eq]
#align tendsto_uniformly_on.congr TendstoUniformlyOn.congr
theorem TendstoUniformlyOn.congr_right {g : α → β} (hf : TendstoUniformlyOn F f p s)
(hfg : EqOn f g s) : TendstoUniformlyOn F g p s := fun u hu => by
filter_upwards [hf u hu] with i hi a ha using hfg ha ▸ hi a ha
#align tendsto_uniformly_on.congr_right TendstoUniformlyOn.congr_right
protected theorem TendstoUniformly.tendstoUniformlyOn (h : TendstoUniformly F f p) :
TendstoUniformlyOn F f p s :=
(tendstoUniformlyOn_univ.2 h).mono (subset_univ s)
#align tendsto_uniformly.tendsto_uniformly_on TendstoUniformly.tendstoUniformlyOn
/-- Composing on the right by a function preserves uniform convergence on a filter -/
theorem TendstoUniformlyOnFilter.comp (h : TendstoUniformlyOnFilter F f p p') (g : γ → α) :
TendstoUniformlyOnFilter (fun n => F n ∘ g) (f ∘ g) p (p'.comap g) := by
rw [tendstoUniformlyOnFilter_iff_tendsto] at h ⊢
exact h.comp (tendsto_id.prod_map tendsto_comap)
#align tendsto_uniformly_on_filter.comp TendstoUniformlyOnFilter.comp
/-- Composing on the right by a function preserves uniform convergence on a set -/
theorem TendstoUniformlyOn.comp (h : TendstoUniformlyOn F f p s) (g : γ → α) :
TendstoUniformlyOn (fun n => F n ∘ g) (f ∘ g) p (g ⁻¹' s) := by
rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter] at h ⊢
simpa [TendstoUniformlyOn, comap_principal] using TendstoUniformlyOnFilter.comp h g
#align tendsto_uniformly_on.comp TendstoUniformlyOn.comp
/-- Composing on the right by a function preserves uniform convergence -/
theorem TendstoUniformly.comp (h : TendstoUniformly F f p) (g : γ → α) :
TendstoUniformly (fun n => F n ∘ g) (f ∘ g) p := by
rw [tendstoUniformly_iff_tendstoUniformlyOnFilter] at h ⊢
simpa [principal_univ, comap_principal] using h.comp g
#align tendsto_uniformly.comp TendstoUniformly.comp
/-- Composing on the left by a uniformly continuous function preserves
uniform convergence on a filter -/
theorem UniformContinuous.comp_tendstoUniformlyOnFilter [UniformSpace γ] {g : β → γ}
(hg : UniformContinuous g) (h : TendstoUniformlyOnFilter F f p p') :
TendstoUniformlyOnFilter (fun i => g ∘ F i) (g ∘ f) p p' := fun _u hu => h _ (hg hu)
#align uniform_continuous.comp_tendsto_uniformly_on_filter UniformContinuous.comp_tendstoUniformlyOnFilter
/-- Composing on the left by a uniformly continuous function preserves
uniform convergence on a set -/
theorem UniformContinuous.comp_tendstoUniformlyOn [UniformSpace γ] {g : β → γ}
(hg : UniformContinuous g) (h : TendstoUniformlyOn F f p s) :
TendstoUniformlyOn (fun i => g ∘ F i) (g ∘ f) p s := fun _u hu => h _ (hg hu)
#align uniform_continuous.comp_tendsto_uniformly_on UniformContinuous.comp_tendstoUniformlyOn
/-- Composing on the left by a uniformly continuous function preserves uniform convergence -/
theorem UniformContinuous.comp_tendstoUniformly [UniformSpace γ] {g : β → γ}
(hg : UniformContinuous g) (h : TendstoUniformly F f p) :
TendstoUniformly (fun i => g ∘ F i) (g ∘ f) p := fun _u hu => h _ (hg hu)
#align uniform_continuous.comp_tendsto_uniformly UniformContinuous.comp_tendstoUniformly
theorem TendstoUniformlyOnFilter.prod_map {ι' α' β' : Type*} [UniformSpace β'] {F' : ι' → α' → β'}
{f' : α' → β'} {q : Filter ι'} {q' : Filter α'} (h : TendstoUniformlyOnFilter F f p p')
(h' : TendstoUniformlyOnFilter F' f' q q') :
TendstoUniformlyOnFilter (fun i : ι × ι' => Prod.map (F i.1) (F' i.2)) (Prod.map f f')
(p ×ˢ q) (p' ×ˢ q') := by
rw [tendstoUniformlyOnFilter_iff_tendsto] at h h' ⊢
rw [uniformity_prod_eq_comap_prod, tendsto_comap_iff, ← map_swap4_prod, tendsto_map'_iff]
convert h.prod_map h' -- seems to be faster than `exact` here
#align tendsto_uniformly_on_filter.prod_map TendstoUniformlyOnFilter.prod_map
theorem TendstoUniformlyOn.prod_map {ι' α' β' : Type*} [UniformSpace β'] {F' : ι' → α' → β'}
{f' : α' → β'} {p' : Filter ι'} {s' : Set α'} (h : TendstoUniformlyOn F f p s)
(h' : TendstoUniformlyOn F' f' p' s') :
TendstoUniformlyOn (fun i : ι × ι' => Prod.map (F i.1) (F' i.2)) (Prod.map f f') (p ×ˢ p')
(s ×ˢ s') := by
rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter] at h h' ⊢
simpa only [prod_principal_principal] using h.prod_map h'
#align tendsto_uniformly_on.prod_map TendstoUniformlyOn.prod_map
theorem TendstoUniformly.prod_map {ι' α' β' : Type*} [UniformSpace β'] {F' : ι' → α' → β'}
{f' : α' → β'} {p' : Filter ι'} (h : TendstoUniformly F f p) (h' : TendstoUniformly F' f' p') :
TendstoUniformly (fun i : ι × ι' => Prod.map (F i.1) (F' i.2)) (Prod.map f f') (p ×ˢ p') := by
rw [← tendstoUniformlyOn_univ, ← univ_prod_univ] at *
exact h.prod_map h'
#align tendsto_uniformly.prod_map TendstoUniformly.prod_map
theorem TendstoUniformlyOnFilter.prod {ι' β' : Type*} [UniformSpace β'] {F' : ι' → α → β'}
{f' : α → β'} {q : Filter ι'} (h : TendstoUniformlyOnFilter F f p p')
(h' : TendstoUniformlyOnFilter F' f' q p') :
TendstoUniformlyOnFilter (fun (i : ι × ι') a => (F i.1 a, F' i.2 a)) (fun a => (f a, f' a))
(p ×ˢ q) p' :=
fun u hu => ((h.prod_map h') u hu).diag_of_prod_right
#align tendsto_uniformly_on_filter.prod TendstoUniformlyOnFilter.prod
theorem TendstoUniformlyOn.prod {ι' β' : Type*} [UniformSpace β'] {F' : ι' → α → β'} {f' : α → β'}
{p' : Filter ι'} (h : TendstoUniformlyOn F f p s) (h' : TendstoUniformlyOn F' f' p' s) :
TendstoUniformlyOn (fun (i : ι × ι') a => (F i.1 a, F' i.2 a)) (fun a => (f a, f' a))
(p.prod p') s :=
(congr_arg _ s.inter_self).mp ((h.prod_map h').comp fun a => (a, a))
#align tendsto_uniformly_on.prod TendstoUniformlyOn.prod
theorem TendstoUniformly.prod {ι' β' : Type*} [UniformSpace β'] {F' : ι' → α → β'} {f' : α → β'}
{p' : Filter ι'} (h : TendstoUniformly F f p) (h' : TendstoUniformly F' f' p') :
TendstoUniformly (fun (i : ι × ι') a => (F i.1 a, F' i.2 a)) (fun a => (f a, f' a))
(p ×ˢ p') :=
(h.prod_map h').comp fun a => (a, a)
#align tendsto_uniformly.prod TendstoUniformly.prod
/-- Uniform convergence on a filter `p'` to a constant function is equivalent to convergence in
`p ×ˢ p'`. -/
theorem tendsto_prod_filter_iff {c : β} :
Tendsto (↿F) (p ×ˢ p') (𝓝 c) ↔ TendstoUniformlyOnFilter F (fun _ => c) p p' := by
simp_rw [nhds_eq_comap_uniformity, tendsto_comap_iff]
rfl
#align tendsto_prod_filter_iff tendsto_prod_filter_iff
/-- Uniform convergence on a set `s` to a constant function is equivalent to convergence in
`p ×ˢ 𝓟 s`. -/
theorem tendsto_prod_principal_iff {c : β} :
Tendsto (↿F) (p ×ˢ 𝓟 s) (𝓝 c) ↔ TendstoUniformlyOn F (fun _ => c) p s := by
rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter]
exact tendsto_prod_filter_iff
#align tendsto_prod_principal_iff tendsto_prod_principal_iff
/-- Uniform convergence to a constant function is equivalent to convergence in `p ×ˢ ⊤`. -/
theorem tendsto_prod_top_iff {c : β} :
Tendsto (↿F) (p ×ˢ ⊤) (𝓝 c) ↔ TendstoUniformly F (fun _ => c) p := by
rw [tendstoUniformly_iff_tendstoUniformlyOnFilter]
exact tendsto_prod_filter_iff
#align tendsto_prod_top_iff tendsto_prod_top_iff
/-- Uniform convergence on the empty set is vacuously true -/
theorem tendstoUniformlyOn_empty : TendstoUniformlyOn F f p ∅ := fun u _ => by simp
#align tendsto_uniformly_on_empty tendstoUniformlyOn_empty
/-- Uniform convergence on a singleton is equivalent to regular convergence -/
theorem tendstoUniformlyOn_singleton_iff_tendsto :
TendstoUniformlyOn F f p {x} ↔ Tendsto (fun n : ι => F n x) p (𝓝 (f x)) := by
simp_rw [tendstoUniformlyOn_iff_tendsto, Uniform.tendsto_nhds_right, tendsto_def]
exact forall₂_congr fun u _ => by simp [mem_prod_principal, preimage]
#align tendsto_uniformly_on_singleton_iff_tendsto tendstoUniformlyOn_singleton_iff_tendsto
/-- If a sequence `g` converges to some `b`, then the sequence of constant functions
`fun n ↦ fun a ↦ g n` converges to the constant function `fun a ↦ b` on any set `s` -/
theorem Filter.Tendsto.tendstoUniformlyOnFilter_const {g : ι → β} {b : β} (hg : Tendsto g p (𝓝 b))
(p' : Filter α) :
TendstoUniformlyOnFilter (fun n : ι => fun _ : α => g n) (fun _ : α => b) p p' := by
simpa only [nhds_eq_comap_uniformity, tendsto_comap_iff] using hg.comp (tendsto_fst (g := p'))
#align filter.tendsto.tendsto_uniformly_on_filter_const Filter.Tendsto.tendstoUniformlyOnFilter_const
/-- If a sequence `g` converges to some `b`, then the sequence of constant functions
`fun n ↦ fun a ↦ g n` converges to the constant function `fun a ↦ b` on any set `s` -/
theorem Filter.Tendsto.tendstoUniformlyOn_const {g : ι → β} {b : β} (hg : Tendsto g p (𝓝 b))
(s : Set α) : TendstoUniformlyOn (fun n : ι => fun _ : α => g n) (fun _ : α => b) p s :=
tendstoUniformlyOn_iff_tendstoUniformlyOnFilter.mpr (hg.tendstoUniformlyOnFilter_const (𝓟 s))
#align filter.tendsto.tendsto_uniformly_on_const Filter.Tendsto.tendstoUniformlyOn_const
-- Porting note (#10756): new lemma
theorem UniformContinuousOn.tendstoUniformlyOn [UniformSpace α] [UniformSpace γ] {x : α} {U : Set α}
{V : Set β} {F : α → β → γ} (hF : UniformContinuousOn (↿F) (U ×ˢ V)) (hU : x ∈ U) :
TendstoUniformlyOn F (F x) (𝓝[U] x) V := by
set φ := fun q : α × β => ((x, q.2), q)
rw [tendstoUniformlyOn_iff_tendsto]
change Tendsto (Prod.map (↿F) ↿F ∘ φ) (𝓝[U] x ×ˢ 𝓟 V) (𝓤 γ)
simp only [nhdsWithin, SProd.sprod, Filter.prod, comap_inf, inf_assoc, comap_principal,
inf_principal]
refine hF.comp (Tendsto.inf ?_ <| tendsto_principal_principal.2 fun x hx => ⟨⟨hU, hx.2⟩, hx⟩)
simp only [uniformity_prod_eq_comap_prod, tendsto_comap_iff, (· ∘ ·),
nhds_eq_comap_uniformity, comap_comap]
exact tendsto_comap.prod_mk (tendsto_diag_uniformity _ _)
theorem UniformContinuousOn.tendstoUniformly [UniformSpace α] [UniformSpace γ] {x : α} {U : Set α}
(hU : U ∈ 𝓝 x) {F : α → β → γ} (hF : UniformContinuousOn (↿F) (U ×ˢ (univ : Set β))) :
TendstoUniformly F (F x) (𝓝 x) := by
simpa only [tendstoUniformlyOn_univ, nhdsWithin_eq_nhds.2 hU]
using hF.tendstoUniformlyOn (mem_of_mem_nhds hU)
#align uniform_continuous_on.tendsto_uniformly UniformContinuousOn.tendstoUniformly
theorem UniformContinuous₂.tendstoUniformly [UniformSpace α] [UniformSpace γ] {f : α → β → γ}
(h : UniformContinuous₂ f) {x : α} : TendstoUniformly f (f x) (𝓝 x) :=
UniformContinuousOn.tendstoUniformly univ_mem <| by rwa [univ_prod_univ, uniformContinuousOn_univ]
#align uniform_continuous₂.tendsto_uniformly UniformContinuous₂.tendstoUniformly
/-- A sequence is uniformly Cauchy if eventually all of its pairwise differences are
uniformly bounded -/
def UniformCauchySeqOnFilter (F : ι → α → β) (p : Filter ι) (p' : Filter α) : Prop :=
∀ u ∈ 𝓤 β, ∀ᶠ m : (ι × ι) × α in (p ×ˢ p) ×ˢ p', (F m.fst.fst m.snd, F m.fst.snd m.snd) ∈ u
#align uniform_cauchy_seq_on_filter UniformCauchySeqOnFilter
/-- A sequence is uniformly Cauchy if eventually all of its pairwise differences are
uniformly bounded -/
def UniformCauchySeqOn (F : ι → α → β) (p : Filter ι) (s : Set α) : Prop :=
∀ u ∈ 𝓤 β, ∀ᶠ m : ι × ι in p ×ˢ p, ∀ x : α, x ∈ s → (F m.fst x, F m.snd x) ∈ u
#align uniform_cauchy_seq_on UniformCauchySeqOn
theorem uniformCauchySeqOn_iff_uniformCauchySeqOnFilter :
UniformCauchySeqOn F p s ↔ UniformCauchySeqOnFilter F p (𝓟 s) := by
simp only [UniformCauchySeqOn, UniformCauchySeqOnFilter]
refine forall₂_congr fun u hu => ?_
rw [eventually_prod_principal_iff]
#align uniform_cauchy_seq_on_iff_uniform_cauchy_seq_on_filter uniformCauchySeqOn_iff_uniformCauchySeqOnFilter
theorem UniformCauchySeqOn.uniformCauchySeqOnFilter (hF : UniformCauchySeqOn F p s) :
UniformCauchySeqOnFilter F p (𝓟 s) := by rwa [← uniformCauchySeqOn_iff_uniformCauchySeqOnFilter]
#align uniform_cauchy_seq_on.uniform_cauchy_seq_on_filter UniformCauchySeqOn.uniformCauchySeqOnFilter
/-- A sequence that converges uniformly is also uniformly Cauchy -/
theorem TendstoUniformlyOnFilter.uniformCauchySeqOnFilter (hF : TendstoUniformlyOnFilter F f p p') :
UniformCauchySeqOnFilter F p p' := by
intro u hu
rcases comp_symm_of_uniformity hu with ⟨t, ht, htsymm, htmem⟩
have := tendsto_swap4_prod.eventually ((hF t ht).prod_mk (hF t ht))
apply this.diag_of_prod_right.mono
simp only [and_imp, Prod.forall]
intro n1 n2 x hl hr
exact Set.mem_of_mem_of_subset (prod_mk_mem_compRel (htsymm hl) hr) htmem
#align tendsto_uniformly_on_filter.uniform_cauchy_seq_on_filter TendstoUniformlyOnFilter.uniformCauchySeqOnFilter
/-- A sequence that converges uniformly is also uniformly Cauchy -/
theorem TendstoUniformlyOn.uniformCauchySeqOn (hF : TendstoUniformlyOn F f p s) :
UniformCauchySeqOn F p s :=
uniformCauchySeqOn_iff_uniformCauchySeqOnFilter.mpr
hF.tendstoUniformlyOnFilter.uniformCauchySeqOnFilter
#align tendsto_uniformly_on.uniform_cauchy_seq_on TendstoUniformlyOn.uniformCauchySeqOn
/-- A uniformly Cauchy sequence converges uniformly to its limit -/
theorem UniformCauchySeqOnFilter.tendstoUniformlyOnFilter_of_tendsto [NeBot p]
(hF : UniformCauchySeqOnFilter F p p')
(hF' : ∀ᶠ x : α in p', Tendsto (fun n => F n x) p (𝓝 (f x))) :
TendstoUniformlyOnFilter F f p p' := by
-- Proof idea: |f_n(x) - f(x)| ≤ |f_n(x) - f_m(x)| + |f_m(x) - f(x)|. We choose `n`
-- so that |f_n(x) - f_m(x)| is uniformly small across `s` whenever `m ≥ n`. Then for
-- a fixed `x`, we choose `m` sufficiently large such that |f_m(x) - f(x)| is small.
intro u hu
rcases comp_symm_of_uniformity hu with ⟨t, ht, htsymm, htmem⟩
-- We will choose n, x, and m simultaneously. n and x come from hF. m comes from hF'
-- But we need to promote hF' to the full product filter to use it
have hmc : ∀ᶠ x in (p ×ˢ p) ×ˢ p', Tendsto (fun n : ι => F n x.snd) p (𝓝 (f x.snd)) := by
rw [eventually_prod_iff]
exact ⟨fun _ => True, by simp, _, hF', by simp⟩
-- To apply filter operations we'll need to do some order manipulation
rw [Filter.eventually_swap_iff]
have := tendsto_prodAssoc.eventually (tendsto_prod_swap.eventually ((hF t ht).and hmc))
apply this.curry.mono
simp only [Equiv.prodAssoc_apply, eventually_and, eventually_const, Prod.snd_swap, Prod.fst_swap,
and_imp, Prod.forall]
-- Complete the proof
intro x n hx hm'
refine Set.mem_of_mem_of_subset (mem_compRel.mpr ?_) htmem
rw [Uniform.tendsto_nhds_right] at hm'
have := hx.and (hm' ht)
obtain ⟨m, hm⟩ := this.exists
exact ⟨F m x, ⟨hm.2, htsymm hm.1⟩⟩
#align uniform_cauchy_seq_on_filter.tendsto_uniformly_on_filter_of_tendsto UniformCauchySeqOnFilter.tendstoUniformlyOnFilter_of_tendsto
/-- A uniformly Cauchy sequence converges uniformly to its limit -/
theorem UniformCauchySeqOn.tendstoUniformlyOn_of_tendsto [NeBot p] (hF : UniformCauchySeqOn F p s)
(hF' : ∀ x : α, x ∈ s → Tendsto (fun n => F n x) p (𝓝 (f x))) : TendstoUniformlyOn F f p s :=
tendstoUniformlyOn_iff_tendstoUniformlyOnFilter.mpr
(hF.uniformCauchySeqOnFilter.tendstoUniformlyOnFilter_of_tendsto hF')
#align uniform_cauchy_seq_on.tendsto_uniformly_on_of_tendsto UniformCauchySeqOn.tendstoUniformlyOn_of_tendsto
theorem UniformCauchySeqOnFilter.mono_left {p'' : Filter ι} (hf : UniformCauchySeqOnFilter F p p')
(hp : p'' ≤ p) : UniformCauchySeqOnFilter F p'' p' := by
intro u hu
have := (hf u hu).filter_mono (p'.prod_mono_left (Filter.prod_mono hp hp))
exact this.mono (by simp)
#align uniform_cauchy_seq_on_filter.mono_left UniformCauchySeqOnFilter.mono_left
theorem UniformCauchySeqOnFilter.mono_right {p'' : Filter α} (hf : UniformCauchySeqOnFilter F p p')
(hp : p'' ≤ p') : UniformCauchySeqOnFilter F p p'' := fun u hu =>
have := (hf u hu).filter_mono ((p ×ˢ p).prod_mono_right hp)
this.mono (by simp)
#align uniform_cauchy_seq_on_filter.mono_right UniformCauchySeqOnFilter.mono_right
theorem UniformCauchySeqOn.mono {s' : Set α} (hf : UniformCauchySeqOn F p s) (hss' : s' ⊆ s) :
UniformCauchySeqOn F p s' := by
rw [uniformCauchySeqOn_iff_uniformCauchySeqOnFilter] at hf ⊢
exact hf.mono_right (le_principal_iff.mpr <| mem_principal.mpr hss')
#align uniform_cauchy_seq_on.mono UniformCauchySeqOn.mono
/-- Composing on the right by a function preserves uniform Cauchy sequences -/
theorem UniformCauchySeqOnFilter.comp {γ : Type*} (hf : UniformCauchySeqOnFilter F p p')
(g : γ → α) : UniformCauchySeqOnFilter (fun n => F n ∘ g) p (p'.comap g) := fun u hu => by
obtain ⟨pa, hpa, pb, hpb, hpapb⟩ := eventually_prod_iff.mp (hf u hu)
rw [eventually_prod_iff]
refine ⟨pa, hpa, pb ∘ g, ?_, fun hx _ hy => hpapb hx hy⟩
exact eventually_comap.mpr (hpb.mono fun x hx y hy => by simp only [hx, hy, Function.comp_apply])
#align uniform_cauchy_seq_on_filter.comp UniformCauchySeqOnFilter.comp
/-- Composing on the right by a function preserves uniform Cauchy sequences -/
theorem UniformCauchySeqOn.comp {γ : Type*} (hf : UniformCauchySeqOn F p s) (g : γ → α) :
UniformCauchySeqOn (fun n => F n ∘ g) p (g ⁻¹' s) := by
rw [uniformCauchySeqOn_iff_uniformCauchySeqOnFilter] at hf ⊢
simpa only [UniformCauchySeqOn, comap_principal] using hf.comp g
#align uniform_cauchy_seq_on.comp UniformCauchySeqOn.comp
/-- Composing on the left by a uniformly continuous function preserves
uniform Cauchy sequences -/
theorem UniformContinuous.comp_uniformCauchySeqOn [UniformSpace γ] {g : β → γ}
(hg : UniformContinuous g) (hf : UniformCauchySeqOn F p s) :
UniformCauchySeqOn (fun n => g ∘ F n) p s := fun _u hu => hf _ (hg hu)
#align uniform_continuous.comp_uniform_cauchy_seq_on UniformContinuous.comp_uniformCauchySeqOn
theorem UniformCauchySeqOn.prod_map {ι' α' β' : Type*} [UniformSpace β'] {F' : ι' → α' → β'}
{p' : Filter ι'} {s' : Set α'} (h : UniformCauchySeqOn F p s)
(h' : UniformCauchySeqOn F' p' s') :
UniformCauchySeqOn (fun i : ι × ι' => Prod.map (F i.1) (F' i.2)) (p ×ˢ p') (s ×ˢ s') := by
intro u hu
rw [uniformity_prod_eq_prod, mem_map, mem_prod_iff] at hu
obtain ⟨v, hv, w, hw, hvw⟩ := hu
simp_rw [mem_prod, Prod.map_apply, and_imp, Prod.forall]
rw [← Set.image_subset_iff] at hvw
apply (tendsto_swap4_prod.eventually ((h v hv).prod_mk (h' w hw))).mono
intro x hx a b ha hb
exact hvw ⟨_, mk_mem_prod (hx.1 a ha) (hx.2 b hb), rfl⟩
#align uniform_cauchy_seq_on.prod_map UniformCauchySeqOn.prod_map
theorem UniformCauchySeqOn.prod {ι' β' : Type*} [UniformSpace β'] {F' : ι' → α → β'}
{p' : Filter ι'} (h : UniformCauchySeqOn F p s) (h' : UniformCauchySeqOn F' p' s) :
UniformCauchySeqOn (fun (i : ι × ι') a => (F i.fst a, F' i.snd a)) (p ×ˢ p') s :=
(congr_arg _ s.inter_self).mp ((h.prod_map h').comp fun a => (a, a))
#align uniform_cauchy_seq_on.prod UniformCauchySeqOn.prod
theorem UniformCauchySeqOn.prod' {β' : Type*} [UniformSpace β'] {F' : ι → α → β'}
(h : UniformCauchySeqOn F p s) (h' : UniformCauchySeqOn F' p s) :
UniformCauchySeqOn (fun (i : ι) a => (F i a, F' i a)) p s := fun u hu =>
have hh : Tendsto (fun x : ι => (x, x)) p (p ×ˢ p) := tendsto_diag
(hh.prod_map hh).eventually ((h.prod h') u hu)
#align uniform_cauchy_seq_on.prod' UniformCauchySeqOn.prod'
/-- If a sequence of functions is uniformly Cauchy on a set, then the values at each point form
a Cauchy sequence. -/
| Mathlib/Topology/UniformSpace/UniformConvergence.lean | 546 | 551 | theorem UniformCauchySeqOn.cauchy_map [hp : NeBot p] (hf : UniformCauchySeqOn F p s) (hx : x ∈ s) :
Cauchy (map (fun i => F i x) p) := by |
simp only [cauchy_map_iff, hp, true_and_iff]
intro u hu
rw [mem_map]
filter_upwards [hf u hu] with p hp using hp x hx
|
/-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.RingTheory.Nilpotent.Basic
import Mathlib.RingTheory.UniqueFactorizationDomain
#align_import algebra.squarefree from "leanprover-community/mathlib"@"00d163e35035c3577c1c79fa53b68de17781ffc1"
/-!
# Squarefree elements of monoids
An element of a monoid is squarefree when it is not divisible by any squares
except the squares of units.
Results about squarefree natural numbers are proved in `Data.Nat.Squarefree`.
## Main Definitions
- `Squarefree r` indicates that `r` is only divisible by `x * x` if `x` is a unit.
## Main Results
- `multiplicity.squarefree_iff_multiplicity_le_one`: `x` is `Squarefree` iff for every `y`, either
`multiplicity y x ≤ 1` or `IsUnit y`.
- `UniqueFactorizationMonoid.squarefree_iff_nodup_factors`: A nonzero element `x` of a unique
factorization monoid is squarefree iff `factors x` has no duplicate factors.
## Tags
squarefree, multiplicity
-/
variable {R : Type*}
/-- An element of a monoid is squarefree if the only squares that
divide it are the squares of units. -/
def Squarefree [Monoid R] (r : R) : Prop :=
∀ x : R, x * x ∣ r → IsUnit x
#align squarefree Squarefree
theorem IsRelPrime.of_squarefree_mul [CommMonoid R] {m n : R} (h : Squarefree (m * n)) :
IsRelPrime m n := fun c hca hcb ↦ h c (mul_dvd_mul hca hcb)
@[simp]
theorem IsUnit.squarefree [CommMonoid R] {x : R} (h : IsUnit x) : Squarefree x := fun _ hdvd =>
isUnit_of_mul_isUnit_left (isUnit_of_dvd_unit hdvd h)
#align is_unit.squarefree IsUnit.squarefree
-- @[simp] -- Porting note (#10618): simp can prove this
theorem squarefree_one [CommMonoid R] : Squarefree (1 : R) :=
isUnit_one.squarefree
#align squarefree_one squarefree_one
@[simp]
theorem not_squarefree_zero [MonoidWithZero R] [Nontrivial R] : ¬Squarefree (0 : R) := by
erw [not_forall]
exact ⟨0, by simp⟩
#align not_squarefree_zero not_squarefree_zero
theorem Squarefree.ne_zero [MonoidWithZero R] [Nontrivial R] {m : R} (hm : Squarefree (m : R)) :
m ≠ 0 := by
rintro rfl
exact not_squarefree_zero hm
#align squarefree.ne_zero Squarefree.ne_zero
@[simp]
theorem Irreducible.squarefree [CommMonoid R] {x : R} (h : Irreducible x) : Squarefree x := by
rintro y ⟨z, hz⟩
rw [mul_assoc] at hz
rcases h.isUnit_or_isUnit hz with (hu | hu)
· exact hu
· apply isUnit_of_mul_isUnit_left hu
#align irreducible.squarefree Irreducible.squarefree
@[simp]
theorem Prime.squarefree [CancelCommMonoidWithZero R] {x : R} (h : Prime x) : Squarefree x :=
h.irreducible.squarefree
#align prime.squarefree Prime.squarefree
theorem Squarefree.of_mul_left [CommMonoid R] {m n : R} (hmn : Squarefree (m * n)) : Squarefree m :=
fun p hp => hmn p (dvd_mul_of_dvd_left hp n)
#align squarefree.of_mul_left Squarefree.of_mul_left
theorem Squarefree.of_mul_right [CommMonoid R] {m n : R} (hmn : Squarefree (m * n)) :
Squarefree n := fun p hp => hmn p (dvd_mul_of_dvd_right hp m)
#align squarefree.of_mul_right Squarefree.of_mul_right
theorem Squarefree.squarefree_of_dvd [CommMonoid R] {x y : R} (hdvd : x ∣ y) (hsq : Squarefree y) :
Squarefree x := fun _ h => hsq _ (h.trans hdvd)
#align squarefree.squarefree_of_dvd Squarefree.squarefree_of_dvd
theorem Squarefree.eq_zero_or_one_of_pow_of_not_isUnit [CommMonoid R] {x : R} {n : ℕ}
(h : Squarefree (x ^ n)) (h' : ¬ IsUnit x) :
n = 0 ∨ n = 1 := by
contrapose! h'
replace h' : 2 ≤ n := by omega
have : x * x ∣ x ^ n := by rw [← sq]; exact pow_dvd_pow x h'
exact h.squarefree_of_dvd this x (refl _)
section SquarefreeGcdOfSquarefree
variable {α : Type*} [CancelCommMonoidWithZero α] [GCDMonoid α]
theorem Squarefree.gcd_right (a : α) {b : α} (hb : Squarefree b) : Squarefree (gcd a b) :=
hb.squarefree_of_dvd (gcd_dvd_right _ _)
#align squarefree.gcd_right Squarefree.gcd_right
theorem Squarefree.gcd_left {a : α} (b : α) (ha : Squarefree a) : Squarefree (gcd a b) :=
ha.squarefree_of_dvd (gcd_dvd_left _ _)
#align squarefree.gcd_left Squarefree.gcd_left
end SquarefreeGcdOfSquarefree
namespace multiplicity
section CommMonoid
variable [CommMonoid R] [DecidableRel (Dvd.dvd : R → R → Prop)]
theorem squarefree_iff_multiplicity_le_one (r : R) :
Squarefree r ↔ ∀ x : R, multiplicity x r ≤ 1 ∨ IsUnit x := by
refine forall_congr' fun a => ?_
rw [← sq, pow_dvd_iff_le_multiplicity, or_iff_not_imp_left, not_le, imp_congr _ Iff.rfl]
norm_cast
rw [← one_add_one_eq_two]
simpa using PartENat.add_one_le_iff_lt (PartENat.natCast_ne_top 1)
#align multiplicity.squarefree_iff_multiplicity_le_one multiplicity.squarefree_iff_multiplicity_le_one
end CommMonoid
section CancelCommMonoidWithZero
variable [CancelCommMonoidWithZero R] [WfDvdMonoid R]
theorem finite_prime_left {a b : R} (ha : Prime a) (hb : b ≠ 0) : multiplicity.Finite a b :=
finite_of_not_isUnit ha.not_unit hb
#align multiplicity.finite_prime_left multiplicity.finite_prime_left
end CancelCommMonoidWithZero
end multiplicity
section Irreducible
variable [CommMonoidWithZero R] [WfDvdMonoid R]
theorem squarefree_iff_no_irreducibles {x : R} (hx₀ : x ≠ 0) :
Squarefree x ↔ ∀ p, Irreducible p → ¬ (p * p ∣ x) := by
refine ⟨fun h p hp hp' ↦ hp.not_unit (h p hp'), fun h d hd ↦ by_contra fun hdu ↦ ?_⟩
have hd₀ : d ≠ 0 := ne_zero_of_dvd_ne_zero (ne_zero_of_dvd_ne_zero hx₀ hd) (dvd_mul_left d d)
obtain ⟨p, irr, dvd⟩ := WfDvdMonoid.exists_irreducible_factor hdu hd₀
exact h p irr ((mul_dvd_mul dvd dvd).trans hd)
theorem irreducible_sq_not_dvd_iff_eq_zero_and_no_irreducibles_or_squarefree (r : R) :
(∀ x : R, Irreducible x → ¬x * x ∣ r) ↔ (r = 0 ∧ ∀ x : R, ¬Irreducible x) ∨ Squarefree r := by
refine ⟨fun h ↦ ?_, ?_⟩
· rcases eq_or_ne r 0 with (rfl | hr)
· exact .inl (by simpa using h)
· exact .inr ((squarefree_iff_no_irreducibles hr).mpr h)
· rintro (⟨rfl, h⟩ | h)
· simpa using h
intro x hx t
exact hx.not_unit (h x t)
#align irreducible_sq_not_dvd_iff_eq_zero_and_no_irreducibles_or_squarefree irreducible_sq_not_dvd_iff_eq_zero_and_no_irreducibles_or_squarefree
| Mathlib/Algebra/Squarefree/Basic.lean | 166 | 168 | theorem squarefree_iff_irreducible_sq_not_dvd_of_ne_zero {r : R} (hr : r ≠ 0) :
Squarefree r ↔ ∀ x : R, Irreducible x → ¬x * x ∣ r := by |
simpa [hr] using (irreducible_sq_not_dvd_iff_eq_zero_and_no_irreducibles_or_squarefree r).symm
|
/-
Copyright (c) 2020 Jannis Limperg. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jannis Limperg
-/
import Mathlib.Data.List.OfFn
import Mathlib.Data.List.Range
#align_import data.list.indexes from "leanprover-community/mathlib"@"8631e2d5ea77f6c13054d9151d82b83069680cb1"
/-!
# Lemmas about List.*Idx functions.
Some specification lemmas for `List.mapIdx`, `List.mapIdxM`, `List.foldlIdx` and `List.foldrIdx`.
-/
assert_not_exists MonoidWithZero
universe u v
open Function
namespace List
variable {α : Type u} {β : Type v}
section MapIdx
-- Porting note: Add back old definition because it's easier for writing proofs.
/-- Lean3 `map_with_index` helper function -/
protected def oldMapIdxCore (f : ℕ → α → β) : ℕ → List α → List β
| _, [] => []
| k, a :: as => f k a :: List.oldMapIdxCore f (k + 1) as
/-- Given a function `f : ℕ → α → β` and `as : List α`, `as = [a₀, a₁, ...]`, returns the list
`[f 0 a₀, f 1 a₁, ...]`. -/
protected def oldMapIdx (f : ℕ → α → β) (as : List α) : List β :=
List.oldMapIdxCore f 0 as
@[simp]
theorem mapIdx_nil {α β} (f : ℕ → α → β) : mapIdx f [] = [] :=
rfl
#align list.map_with_index_nil List.mapIdx_nil
-- Porting note (#10756): new theorem.
protected theorem oldMapIdxCore_eq (l : List α) (f : ℕ → α → β) (n : ℕ) :
l.oldMapIdxCore f n = l.oldMapIdx fun i a ↦ f (i + n) a := by
induction' l with hd tl hl generalizing f n
· rfl
· rw [List.oldMapIdx]
simp only [List.oldMapIdxCore, hl, Nat.add_left_comm, Nat.add_comm, Nat.add_zero]
#noalign list.map_with_index_core_eq
-- Porting note: convert new definition to old definition.
-- A few new theorems are added to achieve this
-- 1. Prove that `oldMapIdxCore f (l ++ [e]) = oldMapIdxCore f l ++ [f l.length e]`
-- 2. Prove that `oldMapIdx f (l ++ [e]) = oldMapIdx f l ++ [f l.length e]`
-- 3. Prove list induction using `∀ l e, p [] → (p l → p (l ++ [e])) → p l`
-- Porting note (#10756): new theorem.
theorem list_reverse_induction (p : List α → Prop) (base : p [])
(ind : ∀ (l : List α) (e : α), p l → p (l ++ [e])) : (∀ (l : List α), p l) := by
let q := fun l ↦ p (reverse l)
have pq : ∀ l, p (reverse l) → q l := by simp only [q, reverse_reverse]; intro; exact id
have qp : ∀ l, q (reverse l) → p l := by simp only [q, reverse_reverse]; intro; exact id
intro l
apply qp
generalize (reverse l) = l
induction' l with head tail ih
· apply pq; simp only [reverse_nil, base]
· apply pq; simp only [reverse_cons]; apply ind; apply qp; rw [reverse_reverse]; exact ih
-- Porting note (#10756): new theorem.
protected theorem oldMapIdxCore_append : ∀ (f : ℕ → α → β) (n : ℕ) (l₁ l₂ : List α),
List.oldMapIdxCore f n (l₁ ++ l₂) =
List.oldMapIdxCore f n l₁ ++ List.oldMapIdxCore f (n + l₁.length) l₂ := by
intros f n l₁ l₂
generalize e : (l₁ ++ l₂).length = len
revert n l₁ l₂
induction' len with len ih <;> intros n l₁ l₂ h
· have l₁_nil : l₁ = [] := by
cases l₁
· rfl
· contradiction
have l₂_nil : l₂ = [] := by
cases l₂
· rfl
· rw [List.length_append] at h; contradiction
simp only [l₁_nil, l₂_nil]; rfl
· cases' l₁ with head tail
· rfl
· simp only [List.oldMapIdxCore, List.append_eq, length_cons, cons_append,cons.injEq, true_and]
suffices n + Nat.succ (length tail) = n + 1 + tail.length by
rw [this]
apply ih (n + 1) _ _ _
simp only [cons_append, length_cons, length_append, Nat.succ.injEq] at h
simp only [length_append, h]
rw [Nat.add_assoc]; simp only [Nat.add_comm]
-- Porting note (#10756): new theorem.
protected theorem oldMapIdx_append : ∀ (f : ℕ → α → β) (l : List α) (e : α),
List.oldMapIdx f (l ++ [e]) = List.oldMapIdx f l ++ [f l.length e] := by
intros f l e
unfold List.oldMapIdx
rw [List.oldMapIdxCore_append f 0 l [e]]
simp only [Nat.zero_add]; rfl
-- Porting note (#10756): new theorem.
theorem mapIdxGo_append : ∀ (f : ℕ → α → β) (l₁ l₂ : List α) (arr : Array β),
mapIdx.go f (l₁ ++ l₂) arr = mapIdx.go f l₂ (List.toArray (mapIdx.go f l₁ arr)) := by
intros f l₁ l₂ arr
generalize e : (l₁ ++ l₂).length = len
revert l₁ l₂ arr
induction' len with len ih <;> intros l₁ l₂ arr h
· have l₁_nil : l₁ = [] := by
cases l₁
· rfl
· contradiction
have l₂_nil : l₂ = [] := by
cases l₂
· rfl
· rw [List.length_append] at h; contradiction
rw [l₁_nil, l₂_nil]; simp only [mapIdx.go, Array.toList_eq, Array.toArray_data]
· cases' l₁ with head tail <;> simp only [mapIdx.go]
· simp only [nil_append, Array.toList_eq, Array.toArray_data]
· simp only [List.append_eq]
rw [ih]
· simp only [cons_append, length_cons, length_append, Nat.succ.injEq] at h
simp only [length_append, h]
-- Porting note (#10756): new theorem.
theorem mapIdxGo_length : ∀ (f : ℕ → α → β) (l : List α) (arr : Array β),
length (mapIdx.go f l arr) = length l + arr.size := by
intro f l
induction' l with head tail ih
· intro; simp only [mapIdx.go, Array.toList_eq, length_nil, Nat.zero_add]
· intro; simp only [mapIdx.go]; rw [ih]; simp only [Array.size_push, length_cons];
simp only [Nat.add_succ, add_zero, Nat.add_comm]
-- Porting note (#10756): new theorem.
theorem mapIdx_append_one : ∀ (f : ℕ → α → β) (l : List α) (e : α),
mapIdx f (l ++ [e]) = mapIdx f l ++ [f l.length e] := by
intros f l e
unfold mapIdx
rw [mapIdxGo_append f l [e]]
simp only [mapIdx.go, Array.size_toArray, mapIdxGo_length, length_nil, Nat.add_zero,
Array.toList_eq, Array.push_data, Array.data_toArray]
-- Porting note (#10756): new theorem.
protected theorem new_def_eq_old_def :
∀ (f : ℕ → α → β) (l : List α), l.mapIdx f = List.oldMapIdx f l := by
intro f
apply list_reverse_induction
· rfl
· intro l e h
rw [List.oldMapIdx_append, mapIdx_append_one, h]
@[local simp]
theorem map_enumFrom_eq_zipWith : ∀ (l : List α) (n : ℕ) (f : ℕ → α → β),
map (uncurry f) (enumFrom n l) = zipWith (fun i ↦ f (i + n)) (range (length l)) l := by
intro l
generalize e : l.length = len
revert l
induction' len with len ih <;> intros l e n f
· have : l = [] := by
cases l
· rfl
· contradiction
rw [this]; rfl
· cases' l with head tail
· contradiction
· simp only [map, uncurry_apply_pair, range_succ_eq_map, zipWith, Nat.zero_add,
zipWith_map_left]
rw [ih]
· suffices (fun i ↦ f (i + (n + 1))) = ((fun i ↦ f (i + n)) ∘ Nat.succ) by
rw [this]
rfl
funext n' a
simp only [comp, Nat.add_assoc, Nat.add_comm, Nat.add_succ]
simp only [length_cons, Nat.succ.injEq] at e; exact e
theorem mapIdx_eq_enum_map (l : List α) (f : ℕ → α → β) :
l.mapIdx f = l.enum.map (Function.uncurry f) := by
rw [List.new_def_eq_old_def]
induction' l with hd tl hl generalizing f
· rfl
· rw [List.oldMapIdx, List.oldMapIdxCore, List.oldMapIdxCore_eq, hl]
simp [map, enum_eq_zip_range, map_uncurry_zip_eq_zipWith]
#align list.map_with_index_eq_enum_map List.mapIdx_eq_enum_map
@[simp]
theorem mapIdx_cons (l : List α) (f : ℕ → α → β) (a : α) :
mapIdx f (a :: l) = f 0 a :: mapIdx (fun i ↦ f (i + 1)) l := by
simp [mapIdx_eq_enum_map, enum_eq_zip_range, map_uncurry_zip_eq_zipWith,
range_succ_eq_map, zipWith_map_left]
#align list.map_with_index_cons List.mapIdx_cons
theorem mapIdx_append (K L : List α) (f : ℕ → α → β) :
(K ++ L).mapIdx f = K.mapIdx f ++ L.mapIdx fun i a ↦ f (i + K.length) a := by
induction' K with a J IH generalizing f
· rfl
· simp [IH fun i ↦ f (i + 1), Nat.add_assoc, Nat.succ_eq_add_one]
#align list.map_with_index_append List.mapIdx_append
@[simp]
theorem length_mapIdx (l : List α) (f : ℕ → α → β) : (l.mapIdx f).length = l.length := by
induction' l with hd tl IH generalizing f
· rfl
· simp [IH]
#align list.length_map_with_index List.length_mapIdx
@[simp]
theorem mapIdx_eq_nil {f : ℕ → α → β} {l : List α} : List.mapIdx f l = [] ↔ l = [] := by
rw [List.mapIdx_eq_enum_map, List.map_eq_nil, List.enum_eq_nil]
set_option linter.deprecated false in
@[simp, deprecated (since := "2023-02-11")]
theorem nthLe_mapIdx (l : List α) (f : ℕ → α → β) (i : ℕ) (h : i < l.length)
(h' : i < (l.mapIdx f).length := h.trans_le (l.length_mapIdx f).ge) :
(l.mapIdx f).nthLe i h' = f i (l.nthLe i h) := by
simp [mapIdx_eq_enum_map, enum_eq_zip_range]
#align list.nth_le_map_with_index List.nthLe_mapIdx
theorem mapIdx_eq_ofFn (l : List α) (f : ℕ → α → β) :
l.mapIdx f = ofFn fun i : Fin l.length ↦ f (i : ℕ) (l.get i) := by
induction l generalizing f with
| nil => simp
| cons _ _ IH => simp [IH]
#align list.map_with_index_eq_of_fn List.mapIdx_eq_ofFn
end MapIdx
section FoldrIdx
-- Porting note: Changed argument order of `foldrIdxSpec` to align better with `foldrIdx`.
/-- Specification of `foldrIdx`. -/
def foldrIdxSpec (f : ℕ → α → β → β) (b : β) (as : List α) (start : ℕ) : β :=
foldr (uncurry f) b <| enumFrom start as
#align list.foldr_with_index_aux_spec List.foldrIdxSpecₓ
theorem foldrIdxSpec_cons (f : ℕ → α → β → β) (b a as start) :
foldrIdxSpec f b (a :: as) start = f start a (foldrIdxSpec f b as (start + 1)) :=
rfl
#align list.foldr_with_index_aux_spec_cons List.foldrIdxSpec_consₓ
theorem foldrIdx_eq_foldrIdxSpec (f : ℕ → α → β → β) (b as start) :
foldrIdx f b as start = foldrIdxSpec f b as start := by
induction as generalizing start
· rfl
· simp only [foldrIdx, foldrIdxSpec_cons, *]
#align list.foldr_with_index_aux_eq_foldr_with_index_aux_spec List.foldrIdx_eq_foldrIdxSpecₓ
theorem foldrIdx_eq_foldr_enum (f : ℕ → α → β → β) (b : β) (as : List α) :
foldrIdx f b as = foldr (uncurry f) b (enum as) := by
simp only [foldrIdx, foldrIdxSpec, foldrIdx_eq_foldrIdxSpec, enum]
#align list.foldr_with_index_eq_foldr_enum List.foldrIdx_eq_foldr_enum
end FoldrIdx
theorem indexesValues_eq_filter_enum (p : α → Prop) [DecidablePred p] (as : List α) :
indexesValues p as = filter (p ∘ Prod.snd) (enum as) := by
simp (config := { unfoldPartialApp := true }) [indexesValues, foldrIdx_eq_foldr_enum, uncurry,
filter_eq_foldr, cond_eq_if]
#align list.indexes_values_eq_filter_enum List.indexesValues_eq_filter_enum
theorem findIdxs_eq_map_indexesValues (p : α → Prop) [DecidablePred p] (as : List α) :
findIdxs p as = map Prod.fst (indexesValues p as) := by
simp (config := { unfoldPartialApp := true }) only [indexesValues_eq_filter_enum,
map_filter_eq_foldr, findIdxs, uncurry, foldrIdx_eq_foldr_enum, decide_eq_true_eq, comp_apply,
Bool.cond_decide]
#align list.find_indexes_eq_map_indexes_values List.findIdxs_eq_map_indexesValues
section FindIdx -- TODO: upstream to Batteries
theorem findIdx_eq_length {p : α → Bool} {xs : List α} :
xs.findIdx p = xs.length ↔ ∀ x ∈ xs, ¬p x := by
induction xs with
| nil => simp_all
| cons x xs ih =>
rw [findIdx_cons, length_cons]
constructor <;> intro h
· have : ¬p x := by contrapose h; simp_all
simp_all
· simp_rw [h x (mem_cons_self x xs), cond_false, Nat.succ.injEq, ih]
exact fun y hy ↦ h y <| mem_cons.mpr (Or.inr hy)
theorem findIdx_le_length (p : α → Bool) {xs : List α} : xs.findIdx p ≤ xs.length := by
by_cases e : ∃ x ∈ xs, p x
· exact (findIdx_lt_length_of_exists e).le
· push_neg at e; exact (findIdx_eq_length.mpr e).le
| Mathlib/Data/List/Indexes.lean | 292 | 298 | theorem findIdx_lt_length {p : α → Bool} {xs : List α} :
xs.findIdx p < xs.length ↔ ∃ x ∈ xs, p x := by |
rw [← not_iff_not, not_lt]
have := @le_antisymm_iff _ _ (xs.findIdx p) xs.length
simp only [findIdx_le_length, true_and] at this
rw [← this, findIdx_eq_length, not_exists]
simp only [Bool.not_eq_true, not_and]
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.