Context stringlengths 295 65.3k | file_name stringlengths 21 74 | start int64 14 1.41k | end int64 20 1.41k | theorem stringlengths 27 1.42k | proof stringlengths 0 4.57k |
|---|---|---|---|---|---|
/-
Copyright (c) 2019 Jean Lo. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jean Lo, Yaël Dillies, Moritz Doll
-/
import Mathlib.Algebra.Order.Pi
import Mathlib.Analysis.Convex.Function
import Mathlib.Analysis.LocallyConvex.Basic
import Mathlib.Data.Real.Pointwise
/-!
# Seminorms
This file defines seminorms.
A seminorm is a function to the reals which is positive-semidefinite, absolutely homogeneous, and
subadditive. They are closely related to convex sets, and a topological vector space is locally
convex if and only if its topology is induced by a family of seminorms.
## Main declarations
For a module over a normed ring:
* `Seminorm`: A function to the reals that is positive-semidefinite, absolutely homogeneous, and
subadditive.
* `normSeminorm 𝕜 E`: The norm on `E` as a seminorm.
## References
* [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966]
## Tags
seminorm, locally convex, LCTVS
-/
assert_not_exists balancedCore
open NormedField Set Filter
open scoped NNReal Pointwise Topology Uniformity
variable {R R' 𝕜 𝕜₂ 𝕜₃ 𝕝 E E₂ E₃ F ι : Type*}
/-- A seminorm on a module over a normed ring is a function to the reals that is positive
semidefinite, positive homogeneous, and subadditive. -/
structure Seminorm (𝕜 : Type*) (E : Type*) [SeminormedRing 𝕜] [AddGroup E] [SMul 𝕜 E] extends
AddGroupSeminorm E where
/-- The seminorm of a scalar multiplication is the product of the absolute value of the scalar
and the original seminorm. -/
smul' : ∀ (a : 𝕜) (x : E), toFun (a • x) = ‖a‖ * toFun x
attribute [nolint docBlame] Seminorm.toAddGroupSeminorm
/-- `SeminormClass F 𝕜 E` states that `F` is a type of seminorms on the `𝕜`-module `E`.
You should extend this class when you extend `Seminorm`. -/
class SeminormClass (F : Type*) (𝕜 E : outParam Type*) [SeminormedRing 𝕜] [AddGroup E]
[SMul 𝕜 E] [FunLike F E ℝ] : Prop extends AddGroupSeminormClass F E ℝ where
/-- The seminorm of a scalar multiplication is the product of the absolute value of the scalar
and the original seminorm. -/
map_smul_eq_mul (f : F) (a : 𝕜) (x : E) : f (a • x) = ‖a‖ * f x
export SeminormClass (map_smul_eq_mul)
section Of
/-- Alternative constructor for a `Seminorm` on an `AddCommGroup E` that is a module over a
`SeminormedRing 𝕜`. -/
def Seminorm.of [SeminormedRing 𝕜] [AddCommGroup E] [Module 𝕜 E] (f : E → ℝ)
(add_le : ∀ x y : E, f (x + y) ≤ f x + f y) (smul : ∀ (a : 𝕜) (x : E), f (a • x) = ‖a‖ * f x) :
Seminorm 𝕜 E where
toFun := f
map_zero' := by rw [← zero_smul 𝕜 (0 : E), smul, norm_zero, zero_mul]
add_le' := add_le
smul' := smul
neg' x := by rw [← neg_one_smul 𝕜, smul, norm_neg, ← smul, one_smul]
/-- Alternative constructor for a `Seminorm` over a normed field `𝕜` that only assumes `f 0 = 0`
and an inequality for the scalar multiplication. -/
def Seminorm.ofSMulLE [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] (f : E → ℝ) (map_zero : f 0 = 0)
(add_le : ∀ x y, f (x + y) ≤ f x + f y) (smul_le : ∀ (r : 𝕜) (x), f (r • x) ≤ ‖r‖ * f x) :
Seminorm 𝕜 E :=
Seminorm.of f add_le fun r x => by
refine le_antisymm (smul_le r x) ?_
by_cases h : r = 0
· simp [h, map_zero]
rw [← mul_le_mul_left (inv_pos.mpr (norm_pos_iff.mpr h))]
rw [inv_mul_cancel_left₀ (norm_ne_zero_iff.mpr h)]
specialize smul_le r⁻¹ (r • x)
rw [norm_inv] at smul_le
convert smul_le
simp [h]
end Of
namespace Seminorm
section SeminormedRing
variable [SeminormedRing 𝕜]
section AddGroup
variable [AddGroup E]
section SMul
variable [SMul 𝕜 E]
instance instFunLike : FunLike (Seminorm 𝕜 E) E ℝ where
coe f := f.toFun
coe_injective' f g h := by
rcases f with ⟨⟨_⟩⟩
rcases g with ⟨⟨_⟩⟩
congr
instance instSeminormClass : SeminormClass (Seminorm 𝕜 E) 𝕜 E where
map_zero f := f.map_zero'
map_add_le_add f := f.add_le'
map_neg_eq_map f := f.neg'
map_smul_eq_mul f := f.smul'
@[ext]
theorem ext {p q : Seminorm 𝕜 E} (h : ∀ x, (p : E → ℝ) x = q x) : p = q :=
DFunLike.ext p q h
instance instZero : Zero (Seminorm 𝕜 E) :=
⟨{ AddGroupSeminorm.instZeroAddGroupSeminorm.zero with
smul' := fun _ _ => (mul_zero _).symm }⟩
@[simp]
theorem coe_zero : ⇑(0 : Seminorm 𝕜 E) = 0 :=
rfl
@[simp]
theorem zero_apply (x : E) : (0 : Seminorm 𝕜 E) x = 0 :=
rfl
instance : Inhabited (Seminorm 𝕜 E) :=
⟨0⟩
variable (p : Seminorm 𝕜 E) (x : E) (r : ℝ)
/-- Any action on `ℝ` which factors through `ℝ≥0` applies to a seminorm. -/
instance instSMul [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] : SMul R (Seminorm 𝕜 E) where
smul r p :=
{ r • p.toAddGroupSeminorm with
toFun := fun x => r • p x
smul' := fun _ _ => by
simp only [← smul_one_smul ℝ≥0 r (_ : ℝ), NNReal.smul_def, smul_eq_mul]
rw [map_smul_eq_mul, mul_left_comm] }
instance [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] [SMul R' ℝ] [SMul R' ℝ≥0]
[IsScalarTower R' ℝ≥0 ℝ] [SMul R R'] [IsScalarTower R R' ℝ] :
IsScalarTower R R' (Seminorm 𝕜 E) where
smul_assoc r a p := ext fun x => smul_assoc r a (p x)
theorem coe_smul [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] (r : R) (p : Seminorm 𝕜 E) :
⇑(r • p) = r • ⇑p :=
rfl
@[simp]
theorem smul_apply [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] (r : R) (p : Seminorm 𝕜 E)
(x : E) : (r • p) x = r • p x :=
rfl
instance instAdd : Add (Seminorm 𝕜 E) where
add p q :=
{ p.toAddGroupSeminorm + q.toAddGroupSeminorm with
toFun := fun x => p x + q x
smul' := fun a x => by simp only [map_smul_eq_mul, map_smul_eq_mul, mul_add] }
theorem coe_add (p q : Seminorm 𝕜 E) : ⇑(p + q) = p + q :=
rfl
@[simp]
theorem add_apply (p q : Seminorm 𝕜 E) (x : E) : (p + q) x = p x + q x :=
rfl
instance instAddMonoid : AddMonoid (Seminorm 𝕜 E) :=
DFunLike.coe_injective.addMonoid _ rfl coe_add fun _ _ => by rfl
instance instAddCommMonoid : AddCommMonoid (Seminorm 𝕜 E) :=
DFunLike.coe_injective.addCommMonoid _ rfl coe_add fun _ _ => by rfl
instance instPartialOrder : PartialOrder (Seminorm 𝕜 E) :=
PartialOrder.lift _ DFunLike.coe_injective
instance instIsOrderedCancelAddMonoid : IsOrderedCancelAddMonoid (Seminorm 𝕜 E) :=
DFunLike.coe_injective.isOrderedCancelAddMonoid _ rfl coe_add fun _ _ => rfl
instance instMulAction [Monoid R] [MulAction R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] :
MulAction R (Seminorm 𝕜 E) :=
DFunLike.coe_injective.mulAction _ (by intros; rfl)
variable (𝕜 E)
/-- `coeFn` as an `AddMonoidHom`. Helper definition for showing that `Seminorm 𝕜 E` is a module. -/
@[simps]
def coeFnAddMonoidHom : AddMonoidHom (Seminorm 𝕜 E) (E → ℝ) where
toFun := (↑)
map_zero' := coe_zero
map_add' := coe_add
theorem coeFnAddMonoidHom_injective : Function.Injective (coeFnAddMonoidHom 𝕜 E) :=
show @Function.Injective (Seminorm 𝕜 E) (E → ℝ) (↑) from DFunLike.coe_injective
variable {𝕜 E}
instance instDistribMulAction [Monoid R] [DistribMulAction R ℝ] [SMul R ℝ≥0]
[IsScalarTower R ℝ≥0 ℝ] : DistribMulAction R (Seminorm 𝕜 E) :=
(coeFnAddMonoidHom_injective 𝕜 E).distribMulAction _ (by intros; rfl)
instance instModule [Semiring R] [Module R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] :
Module R (Seminorm 𝕜 E) :=
(coeFnAddMonoidHom_injective 𝕜 E).module R _ (by intros; rfl)
instance instSup : Max (Seminorm 𝕜 E) where
max p q :=
{ p.toAddGroupSeminorm ⊔ q.toAddGroupSeminorm with
toFun := p ⊔ q
smul' := fun x v =>
(congr_arg₂ max (map_smul_eq_mul p x v) (map_smul_eq_mul q x v)).trans <|
(mul_max_of_nonneg _ _ <| norm_nonneg x).symm }
@[simp]
theorem coe_sup (p q : Seminorm 𝕜 E) : ⇑(p ⊔ q) = (p : E → ℝ) ⊔ (q : E → ℝ) :=
rfl
theorem sup_apply (p q : Seminorm 𝕜 E) (x : E) : (p ⊔ q) x = p x ⊔ q x :=
rfl
theorem smul_sup [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] (r : R) (p q : Seminorm 𝕜 E) :
r • (p ⊔ q) = r • p ⊔ r • q :=
have real.smul_max : ∀ x y : ℝ, r • max x y = max (r • x) (r • y) := fun x y => by
simpa only [← smul_eq_mul, ← NNReal.smul_def, smul_one_smul ℝ≥0 r (_ : ℝ)] using
mul_max_of_nonneg x y (r • (1 : ℝ≥0) : ℝ≥0).coe_nonneg
ext fun _ => real.smul_max _ _
@[simp, norm_cast]
theorem coe_le_coe {p q : Seminorm 𝕜 E} : (p : E → ℝ) ≤ q ↔ p ≤ q :=
Iff.rfl
@[simp, norm_cast]
theorem coe_lt_coe {p q : Seminorm 𝕜 E} : (p : E → ℝ) < q ↔ p < q :=
Iff.rfl
theorem le_def {p q : Seminorm 𝕜 E} : p ≤ q ↔ ∀ x, p x ≤ q x :=
Iff.rfl
theorem lt_def {p q : Seminorm 𝕜 E} : p < q ↔ p ≤ q ∧ ∃ x, p x < q x :=
@Pi.lt_def _ _ _ p q
instance instSemilatticeSup : SemilatticeSup (Seminorm 𝕜 E) :=
Function.Injective.semilatticeSup _ DFunLike.coe_injective coe_sup
end SMul
end AddGroup
section Module
variable [SeminormedRing 𝕜₂] [SeminormedRing 𝕜₃]
variable {σ₁₂ : 𝕜 →+* 𝕜₂} [RingHomIsometric σ₁₂]
variable {σ₂₃ : 𝕜₂ →+* 𝕜₃} [RingHomIsometric σ₂₃]
variable {σ₁₃ : 𝕜 →+* 𝕜₃} [RingHomIsometric σ₁₃]
variable [AddCommGroup E] [AddCommGroup E₂] [AddCommGroup E₃]
variable [Module 𝕜 E] [Module 𝕜₂ E₂] [Module 𝕜₃ E₃]
variable [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ]
/-- Composition of a seminorm with a linear map is a seminorm. -/
def comp (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) : Seminorm 𝕜 E :=
{ p.toAddGroupSeminorm.comp f.toAddMonoidHom with
toFun := fun x => p (f x)
-- Porting note: the `simp only` below used to be part of the `rw`.
-- I'm not sure why this change was needed, and am worried by it!
-- Note: https://github.com/leanprover-community/mathlib4/pull/8386 had to change `map_smulₛₗ` to `map_smulₛₗ _`
smul' := fun _ _ => by simp only [map_smulₛₗ _]; rw [map_smul_eq_mul, RingHomIsometric.is_iso] }
theorem coe_comp (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) : ⇑(p.comp f) = p ∘ f :=
rfl
@[simp]
theorem comp_apply (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (x : E) : (p.comp f) x = p (f x) :=
rfl
@[simp]
theorem comp_id (p : Seminorm 𝕜 E) : p.comp LinearMap.id = p :=
ext fun _ => rfl
@[simp]
theorem comp_zero (p : Seminorm 𝕜₂ E₂) : p.comp (0 : E →ₛₗ[σ₁₂] E₂) = 0 :=
ext fun _ => map_zero p
@[simp]
theorem zero_comp (f : E →ₛₗ[σ₁₂] E₂) : (0 : Seminorm 𝕜₂ E₂).comp f = 0 :=
ext fun _ => rfl
theorem comp_comp [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] (p : Seminorm 𝕜₃ E₃) (g : E₂ →ₛₗ[σ₂₃] E₃)
(f : E →ₛₗ[σ₁₂] E₂) : p.comp (g.comp f) = (p.comp g).comp f :=
ext fun _ => rfl
theorem add_comp (p q : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) :
(p + q).comp f = p.comp f + q.comp f :=
ext fun _ => rfl
theorem comp_add_le (p : Seminorm 𝕜₂ E₂) (f g : E →ₛₗ[σ₁₂] E₂) :
p.comp (f + g) ≤ p.comp f + p.comp g := fun _ => map_add_le_add p _ _
theorem smul_comp (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (c : R) :
(c • p).comp f = c • p.comp f :=
ext fun _ => rfl
theorem comp_mono {p q : Seminorm 𝕜₂ E₂} (f : E →ₛₗ[σ₁₂] E₂) (hp : p ≤ q) : p.comp f ≤ q.comp f :=
fun _ => hp _
/-- The composition as an `AddMonoidHom`. -/
@[simps]
def pullback (f : E →ₛₗ[σ₁₂] E₂) : Seminorm 𝕜₂ E₂ →+ Seminorm 𝕜 E where
toFun := fun p => p.comp f
map_zero' := zero_comp f
map_add' := fun p q => add_comp p q f
instance instOrderBot : OrderBot (Seminorm 𝕜 E) where
bot := 0
bot_le := apply_nonneg
@[simp]
theorem coe_bot : ⇑(⊥ : Seminorm 𝕜 E) = 0 :=
rfl
theorem bot_eq_zero : (⊥ : Seminorm 𝕜 E) = 0 :=
rfl
theorem smul_le_smul {p q : Seminorm 𝕜 E} {a b : ℝ≥0} (hpq : p ≤ q) (hab : a ≤ b) :
a • p ≤ b • q := by
simp_rw [le_def]
intro x
exact mul_le_mul hab (hpq x) (apply_nonneg p x) (NNReal.coe_nonneg b)
theorem finset_sup_apply (p : ι → Seminorm 𝕜 E) (s : Finset ι) (x : E) :
s.sup p x = ↑(s.sup fun i => ⟨p i x, apply_nonneg (p i) x⟩ : ℝ≥0) := by
induction' s using Finset.cons_induction_on with a s ha ih
· rw [Finset.sup_empty, Finset.sup_empty, coe_bot, _root_.bot_eq_zero, Pi.zero_apply]
norm_cast
· rw [Finset.sup_cons, Finset.sup_cons, coe_sup, Pi.sup_apply, NNReal.coe_max, NNReal.coe_mk, ih]
theorem exists_apply_eq_finset_sup (p : ι → Seminorm 𝕜 E) {s : Finset ι} (hs : s.Nonempty) (x : E) :
∃ i ∈ s, s.sup p x = p i x := by
rcases Finset.exists_mem_eq_sup s hs (fun i ↦ (⟨p i x, apply_nonneg _ _⟩ : ℝ≥0)) with ⟨i, hi, hix⟩
rw [finset_sup_apply]
exact ⟨i, hi, congr_arg _ hix⟩
theorem zero_or_exists_apply_eq_finset_sup (p : ι → Seminorm 𝕜 E) (s : Finset ι) (x : E) :
s.sup p x = 0 ∨ ∃ i ∈ s, s.sup p x = p i x := by
rcases Finset.eq_empty_or_nonempty s with (rfl|hs)
· left; rfl
· right; exact exists_apply_eq_finset_sup p hs x
theorem finset_sup_smul (p : ι → Seminorm 𝕜 E) (s : Finset ι) (C : ℝ≥0) :
s.sup (C • p) = C • s.sup p := by
ext x
rw [smul_apply, finset_sup_apply, finset_sup_apply]
symm
exact congr_arg ((↑) : ℝ≥0 → ℝ) (NNReal.mul_finset_sup C s (fun i ↦ ⟨p i x, apply_nonneg _ _⟩))
theorem finset_sup_le_sum (p : ι → Seminorm 𝕜 E) (s : Finset ι) : s.sup p ≤ ∑ i ∈ s, p i := by
classical
refine Finset.sup_le_iff.mpr ?_
intro i hi
rw [Finset.sum_eq_sum_diff_singleton_add hi, le_add_iff_nonneg_left]
exact bot_le
theorem finset_sup_apply_le {p : ι → Seminorm 𝕜 E} {s : Finset ι} {x : E} {a : ℝ} (ha : 0 ≤ a)
(h : ∀ i, i ∈ s → p i x ≤ a) : s.sup p x ≤ a := by
lift a to ℝ≥0 using ha
rw [finset_sup_apply, NNReal.coe_le_coe]
exact Finset.sup_le h
theorem le_finset_sup_apply {p : ι → Seminorm 𝕜 E} {s : Finset ι} {x : E} {i : ι}
(hi : i ∈ s) : p i x ≤ s.sup p x :=
(Finset.le_sup hi : p i ≤ s.sup p) x
theorem finset_sup_apply_lt {p : ι → Seminorm 𝕜 E} {s : Finset ι} {x : E} {a : ℝ} (ha : 0 < a)
(h : ∀ i, i ∈ s → p i x < a) : s.sup p x < a := by
lift a to ℝ≥0 using ha.le
rw [finset_sup_apply, NNReal.coe_lt_coe, Finset.sup_lt_iff]
· exact h
· exact NNReal.coe_pos.mpr ha
theorem norm_sub_map_le_sub (p : Seminorm 𝕜 E) (x y : E) : ‖p x - p y‖ ≤ p (x - y) :=
abs_sub_map_le_sub p x y
end Module
end SeminormedRing
section SeminormedCommRing
variable [SeminormedRing 𝕜] [SeminormedCommRing 𝕜₂]
variable {σ₁₂ : 𝕜 →+* 𝕜₂} [RingHomIsometric σ₁₂]
variable [AddCommGroup E] [AddCommGroup E₂] [Module 𝕜 E] [Module 𝕜₂ E₂]
theorem comp_smul (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (c : 𝕜₂) :
p.comp (c • f) = ‖c‖₊ • p.comp f :=
ext fun _ => by
rw [comp_apply, smul_apply, LinearMap.smul_apply, map_smul_eq_mul, NNReal.smul_def, coe_nnnorm,
smul_eq_mul, comp_apply]
theorem comp_smul_apply (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (c : 𝕜₂) (x : E) :
p.comp (c • f) x = ‖c‖ * p (f x) :=
map_smul_eq_mul p _ _
end SeminormedCommRing
section NormedField
variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] {p q : Seminorm 𝕜 E} {x : E}
/-- Auxiliary lemma to show that the infimum of seminorms is well-defined. -/
theorem bddBelow_range_add : BddBelow (range fun u => p u + q (x - u)) :=
⟨0, by
rintro _ ⟨x, rfl⟩
dsimp; positivity⟩
noncomputable instance instInf : Min (Seminorm 𝕜 E) where
min p q :=
{ p.toAddGroupSeminorm ⊓ q.toAddGroupSeminorm with
toFun := fun x => ⨅ u : E, p u + q (x - u)
smul' := by
intro a x
obtain rfl | ha := eq_or_ne a 0
· rw [norm_zero, zero_mul, zero_smul]
refine
ciInf_eq_of_forall_ge_of_forall_gt_exists_lt
(fun i => by positivity)
fun x hx => ⟨0, by rwa [map_zero, sub_zero, map_zero, add_zero]⟩
simp_rw [Real.mul_iInf_of_nonneg (norm_nonneg a), mul_add, ← map_smul_eq_mul p, ←
map_smul_eq_mul q, smul_sub]
refine
Function.Surjective.iInf_congr ((a⁻¹ • ·) : E → E)
(fun u => ⟨a • u, inv_smul_smul₀ ha u⟩) fun u => ?_
rw [smul_inv_smul₀ ha] }
@[simp]
theorem inf_apply (p q : Seminorm 𝕜 E) (x : E) : (p ⊓ q) x = ⨅ u : E, p u + q (x - u) :=
rfl
noncomputable instance instLattice : Lattice (Seminorm 𝕜 E) :=
{ Seminorm.instSemilatticeSup with
inf := (· ⊓ ·)
inf_le_left := fun p q x =>
ciInf_le_of_le bddBelow_range_add x <| by
simp only [sub_self, map_zero, add_zero]; rfl
inf_le_right := fun p q x =>
ciInf_le_of_le bddBelow_range_add 0 <| by
simp only [sub_self, map_zero, zero_add, sub_zero]; rfl
le_inf := fun a _ _ hab hac _ =>
le_ciInf fun _ => (le_map_add_map_sub a _ _).trans <| add_le_add (hab _) (hac _) }
theorem smul_inf [SMul R ℝ] [SMul R ℝ≥0] [IsScalarTower R ℝ≥0 ℝ] (r : R) (p q : Seminorm 𝕜 E) :
r • (p ⊓ q) = r • p ⊓ r • q := by
ext
simp_rw [smul_apply, inf_apply, smul_apply, ← smul_one_smul ℝ≥0 r (_ : ℝ), NNReal.smul_def,
smul_eq_mul, Real.mul_iInf_of_nonneg (NNReal.coe_nonneg _), mul_add]
section Classical
open Classical in
/-- We define the supremum of an arbitrary subset of `Seminorm 𝕜 E` as follows:
* if `s` is `BddAbove` *as a set of functions `E → ℝ`* (that is, if `s` is pointwise bounded
above), we take the pointwise supremum of all elements of `s`, and we prove that it is indeed a
seminorm.
* otherwise, we take the zero seminorm `⊥`.
There are two things worth mentioning here:
* First, it is not trivial at first that `s` being bounded above *by a function* implies
being bounded above *as a seminorm*. We show this in `Seminorm.bddAbove_iff` by using
that the `Sup s` as defined here is then a bounding seminorm for `s`. So it is important to make
the case disjunction on `BddAbove ((↑) '' s : Set (E → ℝ))` and not `BddAbove s`.
* Since the pointwise `Sup` already gives `0` at points where a family of functions is
not bounded above, one could hope that just using the pointwise `Sup` would work here, without the
need for an additional case disjunction. As discussed on Zulip, this doesn't work because this can
give a function which does *not* satisfy the seminorm axioms (typically sub-additivity).
-/
noncomputable instance instSupSet : SupSet (Seminorm 𝕜 E) where
sSup s :=
if h : BddAbove ((↑) '' s : Set (E → ℝ)) then
{ toFun := ⨆ p : s, ((p : Seminorm 𝕜 E) : E → ℝ)
map_zero' := by
rw [iSup_apply, ← @Real.iSup_const_zero s]
congr!
rename_i _ _ _ i
exact map_zero i.1
add_le' := fun x y => by
rcases h with ⟨q, hq⟩
obtain rfl | h := s.eq_empty_or_nonempty
· simp [Real.iSup_of_isEmpty]
haveI : Nonempty ↑s := h.coe_sort
simp only [iSup_apply]
refine ciSup_le fun i =>
((i : Seminorm 𝕜 E).add_le' x y).trans <| add_le_add
-- Porting note: `f` is provided to force `Subtype.val` to appear.
-- A type ascription on `_` would have also worked, but would have been more verbose.
(le_ciSup (f := fun i => (Subtype.val i : Seminorm 𝕜 E).toFun x) ⟨q x, ?_⟩ i)
(le_ciSup (f := fun i => (Subtype.val i : Seminorm 𝕜 E).toFun y) ⟨q y, ?_⟩ i)
<;> rw [mem_upperBounds, forall_mem_range]
<;> exact fun j => hq (mem_image_of_mem _ j.2) _
neg' := fun x => by
simp only [iSup_apply]
congr! 2
rename_i _ _ _ i
exact i.1.neg' _
smul' := fun a x => by
simp only [iSup_apply]
rw [← smul_eq_mul,
Real.smul_iSup_of_nonneg (norm_nonneg a) fun i : s => (i : Seminorm 𝕜 E) x]
congr!
rename_i _ _ _ i
exact i.1.smul' a x }
else ⊥
protected theorem coe_sSup_eq' {s : Set <| Seminorm 𝕜 E}
(hs : BddAbove ((↑) '' s : Set (E → ℝ))) : ↑(sSup s) = ⨆ p : s, ((p : Seminorm 𝕜 E) : E → ℝ) :=
congr_arg _ (dif_pos hs)
protected theorem bddAbove_iff {s : Set <| Seminorm 𝕜 E} :
BddAbove s ↔ BddAbove ((↑) '' s : Set (E → ℝ)) :=
⟨fun ⟨q, hq⟩ => ⟨q, forall_mem_image.2 fun _ hp => hq hp⟩, fun H =>
⟨sSup s, fun p hp x => by
dsimp
rw [Seminorm.coe_sSup_eq' H, iSup_apply]
rcases H with ⟨q, hq⟩
exact
le_ciSup ⟨q x, forall_mem_range.mpr fun i : s => hq (mem_image_of_mem _ i.2) x⟩ ⟨p, hp⟩⟩⟩
protected theorem bddAbove_range_iff {ι : Sort*} {p : ι → Seminorm 𝕜 E} :
BddAbove (range p) ↔ ∀ x, BddAbove (range fun i ↦ p i x) := by
rw [Seminorm.bddAbove_iff, ← range_comp, bddAbove_range_pi]; rfl
protected theorem coe_sSup_eq {s : Set <| Seminorm 𝕜 E} (hs : BddAbove s) :
↑(sSup s) = ⨆ p : s, ((p : Seminorm 𝕜 E) : E → ℝ) :=
Seminorm.coe_sSup_eq' (Seminorm.bddAbove_iff.mp hs)
protected theorem coe_iSup_eq {ι : Sort*} {p : ι → Seminorm 𝕜 E} (hp : BddAbove (range p)) :
↑(⨆ i, p i) = ⨆ i, ((p i : Seminorm 𝕜 E) : E → ℝ) := by
rw [← sSup_range, Seminorm.coe_sSup_eq hp]
exact iSup_range' (fun p : Seminorm 𝕜 E => (p : E → ℝ)) p
protected theorem sSup_apply {s : Set (Seminorm 𝕜 E)} (hp : BddAbove s) {x : E} :
(sSup s) x = ⨆ p : s, (p : E → ℝ) x := by
rw [Seminorm.coe_sSup_eq hp, iSup_apply]
protected theorem iSup_apply {ι : Sort*} {p : ι → Seminorm 𝕜 E}
(hp : BddAbove (range p)) {x : E} : (⨆ i, p i) x = ⨆ i, p i x := by
rw [Seminorm.coe_iSup_eq hp, iSup_apply]
protected theorem sSup_empty : sSup (∅ : Set (Seminorm 𝕜 E)) = ⊥ := by
ext
rw [Seminorm.sSup_apply bddAbove_empty, Real.iSup_of_isEmpty]
rfl
private theorem isLUB_sSup (s : Set (Seminorm 𝕜 E)) (hs₁ : BddAbove s) (hs₂ : s.Nonempty) :
IsLUB s (sSup s) := by
refine ⟨fun p hp x => ?_, fun p hp x => ?_⟩ <;> haveI : Nonempty ↑s := hs₂.coe_sort <;>
dsimp <;> rw [Seminorm.coe_sSup_eq hs₁, iSup_apply]
· rcases hs₁ with ⟨q, hq⟩
exact le_ciSup ⟨q x, forall_mem_range.mpr fun i : s => hq i.2 x⟩ ⟨p, hp⟩
· exact ciSup_le fun q => hp q.2 x
/-- `Seminorm 𝕜 E` is a conditionally complete lattice.
Note that, while `inf`, `sup` and `sSup` have good definitional properties (corresponding to
the instances given here for `Inf`, `Sup` and `SupSet` respectively), `sInf s` is just
defined as the supremum of the lower bounds of `s`, which is not really useful in practice. If you
need to use `sInf` on seminorms, then you should probably provide a more workable definition first,
but this is unlikely to happen so we keep the "bad" definition for now. -/
noncomputable instance instConditionallyCompleteLattice :
ConditionallyCompleteLattice (Seminorm 𝕜 E) :=
conditionallyCompleteLatticeOfLatticeOfsSup (Seminorm 𝕜 E) Seminorm.isLUB_sSup
end Classical
end NormedField
/-! ### Seminorm ball -/
section SeminormedRing
variable [SeminormedRing 𝕜]
section AddCommGroup
variable [AddCommGroup E]
section SMul
variable [SMul 𝕜 E] (p : Seminorm 𝕜 E)
/-- The ball of radius `r` at `x` with respect to seminorm `p` is the set of elements `y` with
`p (y - x) < r`. -/
def ball (x : E) (r : ℝ) :=
{ y : E | p (y - x) < r }
/-- The closed ball of radius `r` at `x` with respect to seminorm `p` is the set of elements `y`
with `p (y - x) ≤ r`. -/
def closedBall (x : E) (r : ℝ) :=
{ y : E | p (y - x) ≤ r }
variable {x y : E} {r : ℝ}
@[simp]
theorem mem_ball : y ∈ ball p x r ↔ p (y - x) < r :=
Iff.rfl
@[simp]
theorem mem_closedBall : y ∈ closedBall p x r ↔ p (y - x) ≤ r :=
Iff.rfl
theorem mem_ball_self (hr : 0 < r) : x ∈ ball p x r := by simp [hr]
theorem mem_closedBall_self (hr : 0 ≤ r) : x ∈ closedBall p x r := by simp [hr]
theorem mem_ball_zero : y ∈ ball p 0 r ↔ p y < r := by rw [mem_ball, sub_zero]
theorem mem_closedBall_zero : y ∈ closedBall p 0 r ↔ p y ≤ r := by rw [mem_closedBall, sub_zero]
theorem ball_zero_eq : ball p 0 r = { y : E | p y < r } :=
Set.ext fun _ => p.mem_ball_zero
theorem closedBall_zero_eq : closedBall p 0 r = { y : E | p y ≤ r } :=
Set.ext fun _ => p.mem_closedBall_zero
theorem ball_subset_closedBall (x r) : ball p x r ⊆ closedBall p x r := fun _ h =>
(mem_closedBall _).mpr ((mem_ball _).mp h).le
theorem closedBall_eq_biInter_ball (x r) : closedBall p x r = ⋂ ρ > r, ball p x ρ := by
ext y; simp_rw [mem_closedBall, mem_iInter₂, mem_ball, ← forall_lt_iff_le']
@[simp]
theorem ball_zero' (x : E) (hr : 0 < r) : ball (0 : Seminorm 𝕜 E) x r = Set.univ := by
rw [Set.eq_univ_iff_forall, ball]
simp [hr]
@[simp]
theorem closedBall_zero' (x : E) (hr : 0 < r) : closedBall (0 : Seminorm 𝕜 E) x r = Set.univ :=
eq_univ_of_subset (ball_subset_closedBall _ _ _) (ball_zero' x hr)
theorem ball_smul (p : Seminorm 𝕜 E) {c : NNReal} (hc : 0 < c) (r : ℝ) (x : E) :
(c • p).ball x r = p.ball x (r / c) := by
ext
rw [mem_ball, mem_ball, smul_apply, NNReal.smul_def, smul_eq_mul, mul_comm,
lt_div_iff₀ (NNReal.coe_pos.mpr hc)]
theorem closedBall_smul (p : Seminorm 𝕜 E) {c : NNReal} (hc : 0 < c) (r : ℝ) (x : E) :
(c • p).closedBall x r = p.closedBall x (r / c) := by
ext
rw [mem_closedBall, mem_closedBall, smul_apply, NNReal.smul_def, smul_eq_mul, mul_comm,
le_div_iff₀ (NNReal.coe_pos.mpr hc)]
theorem ball_sup (p : Seminorm 𝕜 E) (q : Seminorm 𝕜 E) (e : E) (r : ℝ) :
ball (p ⊔ q) e r = ball p e r ∩ ball q e r := by
simp_rw [ball, ← Set.setOf_and, coe_sup, Pi.sup_apply, sup_lt_iff]
theorem closedBall_sup (p : Seminorm 𝕜 E) (q : Seminorm 𝕜 E) (e : E) (r : ℝ) :
closedBall (p ⊔ q) e r = closedBall p e r ∩ closedBall q e r := by
simp_rw [closedBall, ← Set.setOf_and, coe_sup, Pi.sup_apply, sup_le_iff]
theorem ball_finset_sup' (p : ι → Seminorm 𝕜 E) (s : Finset ι) (H : s.Nonempty) (e : E) (r : ℝ) :
ball (s.sup' H p) e r = s.inf' H fun i => ball (p i) e r := by
induction H using Finset.Nonempty.cons_induction with
| singleton => simp
| cons _ _ _ hs ih =>
rw [Finset.sup'_cons hs, Finset.inf'_cons hs, ball_sup]
-- Porting note: `rw` can't use `inf_eq_inter` here, but `simp` can?
simp only [inf_eq_inter, ih]
theorem closedBall_finset_sup' (p : ι → Seminorm 𝕜 E) (s : Finset ι) (H : s.Nonempty) (e : E)
(r : ℝ) : closedBall (s.sup' H p) e r = s.inf' H fun i => closedBall (p i) e r := by
induction H using Finset.Nonempty.cons_induction with
| singleton => simp
| cons _ _ _ hs ih =>
rw [Finset.sup'_cons hs, Finset.inf'_cons hs, closedBall_sup]
-- Porting note: `rw` can't use `inf_eq_inter` here, but `simp` can?
simp only [inf_eq_inter, ih]
theorem ball_mono {p : Seminorm 𝕜 E} {r₁ r₂ : ℝ} (h : r₁ ≤ r₂) : p.ball x r₁ ⊆ p.ball x r₂ :=
fun _ (hx : _ < _) => hx.trans_le h
theorem closedBall_mono {p : Seminorm 𝕜 E} {r₁ r₂ : ℝ} (h : r₁ ≤ r₂) :
p.closedBall x r₁ ⊆ p.closedBall x r₂ := fun _ (hx : _ ≤ _) => hx.trans h
theorem ball_antitone {p q : Seminorm 𝕜 E} (h : q ≤ p) : p.ball x r ⊆ q.ball x r := fun _ =>
(h _).trans_lt
theorem closedBall_antitone {p q : Seminorm 𝕜 E} (h : q ≤ p) :
p.closedBall x r ⊆ q.closedBall x r := fun _ => (h _).trans
theorem ball_add_ball_subset (p : Seminorm 𝕜 E) (r₁ r₂ : ℝ) (x₁ x₂ : E) :
p.ball (x₁ : E) r₁ + p.ball (x₂ : E) r₂ ⊆ p.ball (x₁ + x₂) (r₁ + r₂) := by
rintro x ⟨y₁, hy₁, y₂, hy₂, rfl⟩
rw [mem_ball, add_sub_add_comm]
exact (map_add_le_add p _ _).trans_lt (add_lt_add hy₁ hy₂)
theorem closedBall_add_closedBall_subset (p : Seminorm 𝕜 E) (r₁ r₂ : ℝ) (x₁ x₂ : E) :
p.closedBall (x₁ : E) r₁ + p.closedBall (x₂ : E) r₂ ⊆ p.closedBall (x₁ + x₂) (r₁ + r₂) := by
rintro x ⟨y₁, hy₁, y₂, hy₂, rfl⟩
rw [mem_closedBall, add_sub_add_comm]
exact (map_add_le_add p _ _).trans (add_le_add hy₁ hy₂)
theorem sub_mem_ball (p : Seminorm 𝕜 E) (x₁ x₂ y : E) (r : ℝ) :
x₁ - x₂ ∈ p.ball y r ↔ x₁ ∈ p.ball (x₂ + y) r := by simp_rw [mem_ball, sub_sub]
theorem sub_mem_closedBall (p : Seminorm 𝕜 E) (x₁ x₂ y : E) (r : ℝ) :
x₁ - x₂ ∈ p.closedBall y r ↔ x₁ ∈ p.closedBall (x₂ + y) r := by
simp_rw [mem_closedBall, sub_sub]
/-- The image of a ball under addition with a singleton is another ball. -/
theorem vadd_ball (p : Seminorm 𝕜 E) : x +ᵥ p.ball y r = p.ball (x +ᵥ y) r :=
letI := AddGroupSeminorm.toSeminormedAddCommGroup p.toAddGroupSeminorm
Metric.vadd_ball x y r
/-- The image of a closed ball under addition with a singleton is another closed ball. -/
theorem vadd_closedBall (p : Seminorm 𝕜 E) : x +ᵥ p.closedBall y r = p.closedBall (x +ᵥ y) r :=
letI := AddGroupSeminorm.toSeminormedAddCommGroup p.toAddGroupSeminorm
Metric.vadd_closedBall x y r
end SMul
section Module
variable [Module 𝕜 E]
variable [SeminormedRing 𝕜₂] [AddCommGroup E₂] [Module 𝕜₂ E₂]
variable {σ₁₂ : 𝕜 →+* 𝕜₂} [RingHomIsometric σ₁₂]
theorem ball_comp (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (x : E) (r : ℝ) :
(p.comp f).ball x r = f ⁻¹' p.ball (f x) r := by
ext
simp_rw [ball, mem_preimage, comp_apply, Set.mem_setOf_eq, map_sub]
theorem closedBall_comp (p : Seminorm 𝕜₂ E₂) (f : E →ₛₗ[σ₁₂] E₂) (x : E) (r : ℝ) :
(p.comp f).closedBall x r = f ⁻¹' p.closedBall (f x) r := by
ext
simp_rw [closedBall, mem_preimage, comp_apply, Set.mem_setOf_eq, map_sub]
variable (p : Seminorm 𝕜 E)
theorem preimage_metric_ball {r : ℝ} : p ⁻¹' Metric.ball 0 r = { x | p x < r } := by
ext x
simp only [mem_setOf, mem_preimage, mem_ball_zero_iff, Real.norm_of_nonneg (apply_nonneg p _)]
theorem preimage_metric_closedBall {r : ℝ} : p ⁻¹' Metric.closedBall 0 r = { x | p x ≤ r } := by
ext x
simp only [mem_setOf, mem_preimage, mem_closedBall_zero_iff,
Real.norm_of_nonneg (apply_nonneg p _)]
theorem ball_zero_eq_preimage_ball {r : ℝ} : p.ball 0 r = p ⁻¹' Metric.ball 0 r := by
rw [ball_zero_eq, preimage_metric_ball]
theorem closedBall_zero_eq_preimage_closedBall {r : ℝ} :
p.closedBall 0 r = p ⁻¹' Metric.closedBall 0 r := by
rw [closedBall_zero_eq, preimage_metric_closedBall]
@[simp]
theorem ball_bot {r : ℝ} (x : E) (hr : 0 < r) : ball (⊥ : Seminorm 𝕜 E) x r = Set.univ :=
ball_zero' x hr
@[simp]
theorem closedBall_bot {r : ℝ} (x : E) (hr : 0 < r) :
closedBall (⊥ : Seminorm 𝕜 E) x r = Set.univ :=
closedBall_zero' x hr
/-- Seminorm-balls at the origin are balanced. -/
theorem balanced_ball_zero (r : ℝ) : Balanced 𝕜 (ball p 0 r) := by
rintro a ha x ⟨y, hy, hx⟩
rw [mem_ball_zero, ← hx, map_smul_eq_mul]
calc
_ ≤ p y := mul_le_of_le_one_left (apply_nonneg p _) ha
_ < r := by rwa [mem_ball_zero] at hy
/-- Closed seminorm-balls at the origin are balanced. -/
theorem balanced_closedBall_zero (r : ℝ) : Balanced 𝕜 (closedBall p 0 r) := by
rintro a ha x ⟨y, hy, hx⟩
rw [mem_closedBall_zero, ← hx, map_smul_eq_mul]
calc
_ ≤ p y := mul_le_of_le_one_left (apply_nonneg p _) ha
_ ≤ r := by rwa [mem_closedBall_zero] at hy
theorem ball_finset_sup_eq_iInter (p : ι → Seminorm 𝕜 E) (s : Finset ι) (x : E) {r : ℝ}
(hr : 0 < r) : ball (s.sup p) x r = ⋂ i ∈ s, ball (p i) x r := by
lift r to NNReal using hr.le
simp_rw [ball, iInter_setOf, finset_sup_apply, NNReal.coe_lt_coe,
Finset.sup_lt_iff (show ⊥ < r from hr), ← NNReal.coe_lt_coe, NNReal.coe_mk]
theorem closedBall_finset_sup_eq_iInter (p : ι → Seminorm 𝕜 E) (s : Finset ι) (x : E) {r : ℝ}
(hr : 0 ≤ r) : closedBall (s.sup p) x r = ⋂ i ∈ s, closedBall (p i) x r := by
lift r to NNReal using hr
simp_rw [closedBall, iInter_setOf, finset_sup_apply, NNReal.coe_le_coe, Finset.sup_le_iff, ←
NNReal.coe_le_coe, NNReal.coe_mk]
theorem ball_finset_sup (p : ι → Seminorm 𝕜 E) (s : Finset ι) (x : E) {r : ℝ} (hr : 0 < r) :
ball (s.sup p) x r = s.inf fun i => ball (p i) x r := by
rw [Finset.inf_eq_iInf]
exact ball_finset_sup_eq_iInter _ _ _ hr
theorem closedBall_finset_sup (p : ι → Seminorm 𝕜 E) (s : Finset ι) (x : E) {r : ℝ} (hr : 0 ≤ r) :
closedBall (s.sup p) x r = s.inf fun i => closedBall (p i) x r := by
rw [Finset.inf_eq_iInf]
exact closedBall_finset_sup_eq_iInter _ _ _ hr
@[simp]
theorem ball_eq_emptyset (p : Seminorm 𝕜 E) {x : E} {r : ℝ} (hr : r ≤ 0) : p.ball x r = ∅ := by
ext
rw [Seminorm.mem_ball, Set.mem_empty_iff_false, iff_false, not_lt]
exact hr.trans (apply_nonneg p _)
@[simp]
theorem closedBall_eq_emptyset (p : Seminorm 𝕜 E) {x : E} {r : ℝ} (hr : r < 0) :
p.closedBall x r = ∅ := by
ext
rw [Seminorm.mem_closedBall, Set.mem_empty_iff_false, iff_false, not_le]
exact hr.trans_le (apply_nonneg _ _)
theorem closedBall_smul_ball (p : Seminorm 𝕜 E) {r₁ : ℝ} (hr₁ : r₁ ≠ 0) (r₂ : ℝ) :
Metric.closedBall (0 : 𝕜) r₁ • p.ball 0 r₂ ⊆ p.ball 0 (r₁ * r₂) := by
simp only [smul_subset_iff, mem_ball_zero, mem_closedBall_zero_iff, map_smul_eq_mul]
refine fun a ha b hb ↦ mul_lt_mul' ha hb (apply_nonneg _ _) ?_
exact hr₁.lt_or_lt.resolve_left <| ((norm_nonneg a).trans ha).not_lt
theorem ball_smul_closedBall (p : Seminorm 𝕜 E) (r₁ : ℝ) {r₂ : ℝ} (hr₂ : r₂ ≠ 0) :
Metric.ball (0 : 𝕜) r₁ • p.closedBall 0 r₂ ⊆ p.ball 0 (r₁ * r₂) := by
simp only [smul_subset_iff, mem_ball_zero, mem_closedBall_zero, mem_ball_zero_iff,
map_smul_eq_mul]
intro a ha b hb
rw [mul_comm, mul_comm r₁]
refine mul_lt_mul' hb ha (norm_nonneg _) (hr₂.lt_or_lt.resolve_left ?_)
exact ((apply_nonneg p b).trans hb).not_lt
theorem ball_smul_ball (p : Seminorm 𝕜 E) (r₁ r₂ : ℝ) :
Metric.ball (0 : 𝕜) r₁ • p.ball 0 r₂ ⊆ p.ball 0 (r₁ * r₂) := by
rcases eq_or_ne r₂ 0 with rfl | hr₂
· simp
· exact (smul_subset_smul_left (ball_subset_closedBall _ _ _)).trans
(ball_smul_closedBall _ _ hr₂)
theorem closedBall_smul_closedBall (p : Seminorm 𝕜 E) (r₁ r₂ : ℝ) :
Metric.closedBall (0 : 𝕜) r₁ • p.closedBall 0 r₂ ⊆ p.closedBall 0 (r₁ * r₂) := by
simp only [smul_subset_iff, mem_closedBall_zero, mem_closedBall_zero_iff, map_smul_eq_mul]
intro a ha b hb
gcongr
exact (norm_nonneg _).trans ha
theorem neg_mem_ball_zero {r : ℝ} {x : E} : -x ∈ ball p 0 r ↔ x ∈ ball p 0 r := by
simp only [mem_ball_zero, map_neg_eq_map]
theorem neg_mem_closedBall_zero {r : ℝ} {x : E} : -x ∈ closedBall p 0 r ↔ x ∈ closedBall p 0 r := by
simp only [mem_closedBall_zero, map_neg_eq_map]
@[simp]
theorem neg_ball (p : Seminorm 𝕜 E) (r : ℝ) (x : E) : -ball p x r = ball p (-x) r := by
ext
rw [Set.mem_neg, mem_ball, mem_ball, ← neg_add', sub_neg_eq_add, map_neg_eq_map]
@[simp]
theorem neg_closedBall (p : Seminorm 𝕜 E) (r : ℝ) (x : E) :
-closedBall p x r = closedBall p (-x) r := by
ext
rw [Set.mem_neg, mem_closedBall, mem_closedBall, ← neg_add', sub_neg_eq_add, map_neg_eq_map]
end Module
end AddCommGroup
end SeminormedRing
section NormedField
variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] (p : Seminorm 𝕜 E) {r : ℝ} {x : E}
theorem closedBall_iSup {ι : Sort*} {p : ι → Seminorm 𝕜 E} (hp : BddAbove (range p)) (e : E)
{r : ℝ} (hr : 0 < r) : closedBall (⨆ i, p i) e r = ⋂ i, closedBall (p i) e r := by
cases isEmpty_or_nonempty ι
· rw [iSup_of_empty', iInter_of_empty, Seminorm.sSup_empty]
exact closedBall_bot _ hr
· ext x
have := Seminorm.bddAbove_range_iff.mp hp (x - e)
simp only [mem_closedBall, mem_iInter, Seminorm.iSup_apply hp, ciSup_le_iff this]
| Mathlib/Analysis/Seminorm.lean | 890 | 894 | theorem ball_norm_mul_subset {p : Seminorm 𝕜 E} {k : 𝕜} {r : ℝ} :
p.ball 0 (‖k‖ * r) ⊆ k • p.ball 0 r := by | rcases eq_or_ne k 0 with (rfl | hk)
· rw [norm_zero, zero_mul, ball_eq_emptyset _ le_rfl]
exact empty_subset _ |
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Analysis.SpecificLimits.Basic
import Mathlib.Topology.MetricSpace.IsometricSMul
/-!
# Hausdorff distance
The Hausdorff distance on subsets of a metric (or emetric) space.
Given two subsets `s` and `t` of a metric space, their Hausdorff distance is the smallest `d`
such that any point `s` is within `d` of a point in `t`, and conversely. This quantity
is often infinite (think of `s` bounded and `t` unbounded), and therefore better
expressed in the setting of emetric spaces.
## Main definitions
This files introduces:
* `EMetric.infEdist x s`, the infimum edistance of a point `x` to a set `s` in an emetric space
* `EMetric.hausdorffEdist s t`, the Hausdorff edistance of two sets in an emetric space
* Versions of these notions on metric spaces, called respectively `Metric.infDist`
and `Metric.hausdorffDist`
## Main results
* `infEdist_closure`: the edistance to a set and its closure coincide
* `EMetric.mem_closure_iff_infEdist_zero`: a point `x` belongs to the closure of `s` iff
`infEdist x s = 0`
* `IsCompact.exists_infEdist_eq_edist`: if `s` is compact and non-empty, there exists a point `y`
which attains this edistance
* `IsOpen.exists_iUnion_isClosed`: every open set `U` can be written as the increasing union
of countably many closed subsets of `U`
* `hausdorffEdist_closure`: replacing a set by its closure does not change the Hausdorff edistance
* `hausdorffEdist_zero_iff_closure_eq_closure`: two sets have Hausdorff edistance zero
iff their closures coincide
* the Hausdorff edistance is symmetric and satisfies the triangle inequality
* in particular, closed sets in an emetric space are an emetric space
(this is shown in `EMetricSpace.closeds.emetricspace`)
* versions of these notions on metric spaces
* `hausdorffEdist_ne_top_of_nonempty_of_bounded`: if two sets in a metric space
are nonempty and bounded in a metric space, they are at finite Hausdorff edistance.
## Tags
metric space, Hausdorff distance
-/
noncomputable section
open NNReal ENNReal Topology Set Filter Pointwise Bornology
universe u v w
variable {ι : Sort*} {α : Type u} {β : Type v}
namespace EMetric
section InfEdist
variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] {x y : α} {s t : Set α} {Φ : α → β}
/-! ### Distance of a point to a set as a function into `ℝ≥0∞`. -/
/-- The minimal edistance of a point to a set -/
def infEdist (x : α) (s : Set α) : ℝ≥0∞ :=
⨅ y ∈ s, edist x y
@[simp]
theorem infEdist_empty : infEdist x ∅ = ∞ :=
iInf_emptyset
theorem le_infEdist {d} : d ≤ infEdist x s ↔ ∀ y ∈ s, d ≤ edist x y := by
simp only [infEdist, le_iInf_iff]
/-- The edist to a union is the minimum of the edists -/
@[simp]
theorem infEdist_union : infEdist x (s ∪ t) = infEdist x s ⊓ infEdist x t :=
iInf_union
@[simp]
theorem infEdist_iUnion (f : ι → Set α) (x : α) : infEdist x (⋃ i, f i) = ⨅ i, infEdist x (f i) :=
iInf_iUnion f _
lemma infEdist_biUnion {ι : Type*} (f : ι → Set α) (I : Set ι) (x : α) :
infEdist x (⋃ i ∈ I, f i) = ⨅ i ∈ I, infEdist x (f i) := by simp only [infEdist_iUnion]
/-- The edist to a singleton is the edistance to the single point of this singleton -/
@[simp]
theorem infEdist_singleton : infEdist x {y} = edist x y :=
iInf_singleton
/-- The edist to a set is bounded above by the edist to any of its points -/
theorem infEdist_le_edist_of_mem (h : y ∈ s) : infEdist x s ≤ edist x y :=
iInf₂_le y h
/-- If a point `x` belongs to `s`, then its edist to `s` vanishes -/
theorem infEdist_zero_of_mem (h : x ∈ s) : infEdist x s = 0 :=
nonpos_iff_eq_zero.1 <| @edist_self _ _ x ▸ infEdist_le_edist_of_mem h
/-- The edist is antitone with respect to inclusion. -/
theorem infEdist_anti (h : s ⊆ t) : infEdist x t ≤ infEdist x s :=
iInf_le_iInf_of_subset h
/-- The edist to a set is `< r` iff there exists a point in the set at edistance `< r` -/
theorem infEdist_lt_iff {r : ℝ≥0∞} : infEdist x s < r ↔ ∃ y ∈ s, edist x y < r := by
simp_rw [infEdist, iInf_lt_iff, exists_prop]
/-- The edist of `x` to `s` is bounded by the sum of the edist of `y` to `s` and
the edist from `x` to `y` -/
theorem infEdist_le_infEdist_add_edist : infEdist x s ≤ infEdist y s + edist x y :=
calc
⨅ z ∈ s, edist x z ≤ ⨅ z ∈ s, edist y z + edist x y :=
iInf₂_mono fun _ _ => (edist_triangle _ _ _).trans_eq (add_comm _ _)
_ = (⨅ z ∈ s, edist y z) + edist x y := by simp only [ENNReal.iInf_add]
| Mathlib/Topology/MetricSpace/HausdorffDistance.lean | 120 | 121 | theorem infEdist_le_edist_add_infEdist : infEdist x s ≤ edist x y + infEdist y s := by | rw [add_comm] |
/-
Copyright (c) 2017 Mario Carneiro. 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.Family
/-! # Ordinal exponential
In this file we define the power function and the logarithm function on ordinals. The two are
related by the lemma `Ordinal.opow_le_iff_le_log : b ^ c ≤ x ↔ c ≤ log b x` for nontrivial inputs
`b`, `c`.
-/
noncomputable section
open Function Set Equiv Order
open scoped Cardinal Ordinal
universe u v w
namespace Ordinal
/-- The ordinal exponential, defined by transfinite recursion.
We call this `opow` in theorems in order to disambiguate from other exponentials. -/
instance instPow : Pow Ordinal Ordinal :=
⟨fun a b ↦ if a = 0 then 1 - b else
limitRecOn b 1 (fun _ x ↦ x * a) fun o _ f ↦ ⨆ x : Iio o, f x.1 x.2⟩
private theorem opow_of_ne_zero {a b : Ordinal} (h : a ≠ 0) : a ^ b =
limitRecOn b 1 (fun _ x ↦ x * a) fun o _ f ↦ ⨆ x : Iio o, f x.1 x.2 :=
if_neg h
/-- `0 ^ a = 1` if `a = 0` and `0 ^ a = 0` otherwise. -/
theorem zero_opow' (a : Ordinal) : 0 ^ a = 1 - a :=
if_pos rfl
theorem zero_opow_le (a : Ordinal) : (0 : Ordinal) ^ a ≤ 1 := by
rw [zero_opow']
exact sub_le_self 1 a
@[simp]
theorem zero_opow {a : Ordinal} (a0 : a ≠ 0) : (0 : Ordinal) ^ a = 0 := by
rwa [zero_opow', Ordinal.sub_eq_zero_iff_le, one_le_iff_ne_zero]
@[simp]
theorem opow_zero (a : Ordinal) : a ^ (0 : Ordinal) = 1 := by
obtain rfl | h := eq_or_ne a 0
· rw [zero_opow', Ordinal.sub_zero]
· rw [opow_of_ne_zero h, limitRecOn_zero]
@[simp]
theorem opow_succ (a b : Ordinal) : a ^ succ b = a ^ b * a := by
obtain rfl | h := eq_or_ne a 0
· rw [zero_opow (succ_ne_zero b), mul_zero]
· rw [opow_of_ne_zero h, opow_of_ne_zero h, limitRecOn_succ]
theorem opow_limit {a b : Ordinal} (ha : a ≠ 0) (hb : IsLimit b) :
a ^ b = ⨆ x : Iio b, a ^ x.1 := by
simp_rw [opow_of_ne_zero ha, limitRecOn_limit _ _ _ _ hb]
theorem opow_le_of_limit {a b c : Ordinal} (a0 : a ≠ 0) (h : IsLimit b) :
a ^ b ≤ c ↔ ∀ b' < b, a ^ b' ≤ c := by
rw [opow_limit a0 h, Ordinal.iSup_le_iff, Subtype.forall]
rfl
theorem lt_opow_of_limit {a b c : Ordinal} (b0 : b ≠ 0) (h : IsLimit c) :
a < b ^ c ↔ ∃ c' < c, a < b ^ c' := by
rw [← not_iff_not, not_exists]
simp only [not_lt, opow_le_of_limit b0 h, exists_prop, not_and]
@[simp]
theorem opow_one (a : Ordinal) : a ^ (1 : Ordinal) = a := by
rw [← succ_zero, opow_succ]
simp only [opow_zero, one_mul]
@[simp]
theorem one_opow (a : Ordinal) : (1 : Ordinal) ^ a = 1 := by
induction a using limitRecOn with
| zero => simp only [opow_zero]
| succ _ ih =>
simp only [opow_succ, ih, mul_one]
| isLimit b l IH =>
refine eq_of_forall_ge_iff fun c => ?_
rw [opow_le_of_limit Ordinal.one_ne_zero l]
exact ⟨fun H => by simpa only [opow_zero] using H 0 l.pos, fun H b' h => by rwa [IH _ h]⟩
theorem opow_pos {a : Ordinal} (b : Ordinal) (a0 : 0 < a) : 0 < a ^ b := by
have h0 : 0 < a ^ (0 : Ordinal) := by simp only [opow_zero, zero_lt_one]
induction b using limitRecOn with
| zero => exact h0
| succ b IH =>
rw [opow_succ]
exact mul_pos IH a0
| isLimit b l _ =>
exact (lt_opow_of_limit (Ordinal.pos_iff_ne_zero.1 a0) l).2 ⟨0, l.pos, h0⟩
theorem opow_ne_zero {a : Ordinal} (b : Ordinal) (a0 : a ≠ 0) : a ^ b ≠ 0 :=
Ordinal.pos_iff_ne_zero.1 <| opow_pos b <| Ordinal.pos_iff_ne_zero.2 a0
@[simp]
theorem opow_eq_zero {a b : Ordinal} : a ^ b = 0 ↔ a = 0 ∧ b ≠ 0 := by
obtain rfl | ha := eq_or_ne a 0
· obtain rfl | hb := eq_or_ne b 0
· simp
· simp [hb]
· simp [opow_ne_zero b ha, ha]
@[simp, norm_cast]
theorem opow_natCast (a : Ordinal) (n : ℕ) : a ^ (n : Ordinal) = a ^ n := by
induction n with
| zero => rw [Nat.cast_zero, opow_zero, pow_zero]
| succ n IH => rw [Nat.cast_succ, add_one_eq_succ, opow_succ, pow_succ, IH]
theorem isNormal_opow {a : Ordinal} (h : 1 < a) : IsNormal (a ^ ·) :=
have a0 : 0 < a := zero_lt_one.trans h
⟨fun b => by simpa only [mul_one, opow_succ] using (mul_lt_mul_iff_left (opow_pos b a0)).2 h,
fun _ l _ => opow_le_of_limit (ne_of_gt a0) l⟩
theorem opow_lt_opow_iff_right {a b c : Ordinal} (a1 : 1 < a) : a ^ b < a ^ c ↔ b < c :=
(isNormal_opow a1).lt_iff
theorem opow_le_opow_iff_right {a b c : Ordinal} (a1 : 1 < a) : a ^ b ≤ a ^ c ↔ b ≤ c :=
(isNormal_opow a1).le_iff
theorem opow_right_inj {a b c : Ordinal} (a1 : 1 < a) : a ^ b = a ^ c ↔ b = c :=
(isNormal_opow a1).inj
theorem isLimit_opow {a b : Ordinal} (a1 : 1 < a) : IsLimit b → IsLimit (a ^ b) :=
(isNormal_opow a1).isLimit
theorem isLimit_opow_left {a b : Ordinal} (l : IsLimit a) (hb : b ≠ 0) : IsLimit (a ^ b) := by
rcases zero_or_succ_or_limit b with (e | ⟨b, rfl⟩ | l')
· exact absurd e hb
· rw [opow_succ]
exact isLimit_mul (opow_pos _ l.pos) l
· exact isLimit_opow l.one_lt l'
theorem opow_le_opow_right {a b c : Ordinal} (h₁ : 0 < a) (h₂ : b ≤ c) : a ^ b ≤ a ^ c := by
rcases lt_or_eq_of_le (one_le_iff_pos.2 h₁) with h₁ | h₁
· exact (opow_le_opow_iff_right h₁).2 h₂
· subst a
-- Porting note: `le_refl` is required.
simp only [one_opow, le_refl]
theorem opow_le_opow_left {a b : Ordinal} (c : Ordinal) (ab : a ≤ b) : a ^ c ≤ b ^ c := by
by_cases a0 : a = 0
-- Porting note: `le_refl` is required.
· subst a
by_cases c0 : c = 0
· subst c
simp only [opow_zero, le_refl]
· simp only [zero_opow c0, Ordinal.zero_le]
· induction c using limitRecOn with
| zero => simp only [opow_zero, le_refl]
| succ c IH =>
simpa only [opow_succ] using mul_le_mul' IH ab
| isLimit c l IH =>
exact
(opow_le_of_limit a0 l).2 fun b' h =>
(IH _ h).trans (opow_le_opow_right ((Ordinal.pos_iff_ne_zero.2 a0).trans_le ab) h.le)
theorem opow_le_opow {a b c d : Ordinal} (hac : a ≤ c) (hbd : b ≤ d) (hc : 0 < c) : a ^ b ≤ c ^ d :=
(opow_le_opow_left b hac).trans (opow_le_opow_right hc hbd)
theorem left_le_opow (a : Ordinal) {b : Ordinal} (b1 : 0 < b) : a ≤ a ^ b := by
nth_rw 1 [← opow_one a]
rcases le_or_gt a 1 with a1 | a1
· rcases lt_or_eq_of_le a1 with a0 | a1
· rw [lt_one_iff_zero] at a0
rw [a0, zero_opow Ordinal.one_ne_zero]
exact Ordinal.zero_le _
rw [a1, one_opow, one_opow]
rwa [opow_le_opow_iff_right a1, one_le_iff_pos]
theorem left_lt_opow {a b : Ordinal} (ha : 1 < a) (hb : 1 < b) : a < a ^ b := by
conv_lhs => rw [← opow_one a]
rwa [opow_lt_opow_iff_right ha]
theorem right_le_opow {a : Ordinal} (b : Ordinal) (a1 : 1 < a) : b ≤ a ^ b :=
(isNormal_opow a1).le_apply
theorem opow_lt_opow_left_of_succ {a b c : Ordinal} (ab : a < b) : a ^ succ c < b ^ succ c := by
rw [opow_succ, opow_succ]
exact
(mul_le_mul_right' (opow_le_opow_left c ab.le) a).trans_lt
(mul_lt_mul_of_pos_left ab (opow_pos c ((Ordinal.zero_le a).trans_lt ab)))
theorem opow_add (a b c : Ordinal) : a ^ (b + c) = a ^ b * a ^ c := by
rcases eq_or_ne a 0 with (rfl | a0)
· rcases eq_or_ne c 0 with (rfl | c0)
· simp
have : b + c ≠ 0 := ((Ordinal.pos_iff_ne_zero.2 c0).trans_le (le_add_left _ _)).ne'
simp only [zero_opow c0, zero_opow this, mul_zero]
rcases eq_or_lt_of_le (one_le_iff_ne_zero.2 a0) with (rfl | a1)
· simp only [one_opow, mul_one]
induction c using limitRecOn with
| zero => simp
| succ c IH =>
rw [add_succ, opow_succ, IH, opow_succ, mul_assoc]
| isLimit c l IH =>
refine
eq_of_forall_ge_iff fun d =>
(((isNormal_opow a1).trans (isNormal_add_right b)).limit_le l).trans ?_
dsimp only [Function.comp_def]
simp +contextual only [IH]
exact
(((isNormal_mul_right <| opow_pos b (Ordinal.pos_iff_ne_zero.2 a0)).trans
(isNormal_opow a1)).limit_le
l).symm
theorem opow_one_add (a b : Ordinal) : a ^ (1 + b) = a * a ^ b := by rw [opow_add, opow_one]
theorem opow_dvd_opow (a : Ordinal) {b c : Ordinal} (h : b ≤ c) : a ^ b ∣ a ^ c :=
⟨a ^ (c - b), by rw [← opow_add, Ordinal.add_sub_cancel_of_le h]⟩
theorem opow_dvd_opow_iff {a b c : Ordinal} (a1 : 1 < a) : a ^ b ∣ a ^ c ↔ b ≤ c :=
⟨fun h =>
le_of_not_lt fun hn =>
not_le_of_lt ((opow_lt_opow_iff_right a1).2 hn) <|
le_of_dvd (opow_ne_zero _ <| one_le_iff_ne_zero.1 <| a1.le) h,
opow_dvd_opow _⟩
theorem opow_mul (a b c : Ordinal) : a ^ (b * c) = (a ^ b) ^ c := by
by_cases b0 : b = 0; · simp only [b0, zero_mul, opow_zero, one_opow]
by_cases a0 : a = 0
· subst a
by_cases c0 : c = 0
· simp only [c0, mul_zero, opow_zero]
simp only [zero_opow b0, zero_opow c0, zero_opow (mul_ne_zero b0 c0)]
rcases eq_or_lt_of_le (one_le_iff_ne_zero.2 a0) with a1 | a1
· subst a1
simp only [one_opow]
induction c using limitRecOn with
| zero => simp only [mul_zero, opow_zero]
| succ c IH =>
rw [mul_succ, opow_add, IH, opow_succ]
| isLimit c l IH =>
refine
eq_of_forall_ge_iff fun d =>
(((isNormal_opow a1).trans (isNormal_mul_right (Ordinal.pos_iff_ne_zero.2 b0))).limit_le
l).trans
?_
dsimp only [Function.comp_def]
simp +contextual only [IH]
exact (opow_le_of_limit (opow_ne_zero _ a0) l).symm
theorem opow_mul_add_pos {b v : Ordinal} (hb : b ≠ 0) (u : Ordinal) (hv : v ≠ 0) (w : Ordinal) :
0 < b ^ u * v + w :=
(opow_pos u <| Ordinal.pos_iff_ne_zero.2 hb).trans_le <|
(le_mul_left _ <| Ordinal.pos_iff_ne_zero.2 hv).trans <| le_add_right _ _
theorem opow_mul_add_lt_opow_mul_succ {b u w : Ordinal} (v : Ordinal) (hw : w < b ^ u) :
b ^ u * v + w < b ^ u * succ v := by
rwa [mul_succ, add_lt_add_iff_left]
theorem opow_mul_add_lt_opow_succ {b u v w : Ordinal} (hvb : v < b) (hw : w < b ^ u) :
b ^ u * v + w < b ^ succ u := by
convert (opow_mul_add_lt_opow_mul_succ v hw).trans_le
(mul_le_mul_left' (succ_le_of_lt hvb) _) using 1
exact opow_succ b u
/-! ### Ordinal logarithm -/
/-- The ordinal logarithm is the solution `u` to the equation `x = b ^ u * v + w` where `v < b` and
`w < b ^ u`. -/
@[pp_nodot]
def log (b : Ordinal) (x : Ordinal) : Ordinal :=
if 1 < b then pred (sInf { o | x < b ^ o }) else 0
/-- The set in the definition of `log` is nonempty. -/
private theorem log_nonempty {b x : Ordinal} (h : 1 < b) : { o : Ordinal | x < b ^ o }.Nonempty :=
⟨_, succ_le_iff.1 (right_le_opow _ h)⟩
theorem log_def {b : Ordinal} (h : 1 < b) (x : Ordinal) : log b x = pred (sInf { o | x < b ^ o }) :=
if_pos h
theorem log_of_left_le_one {b : Ordinal} (h : b ≤ 1) (x : Ordinal) : log b x = 0 :=
if_neg h.not_lt
@[simp]
theorem log_zero_left : ∀ b, log 0 b = 0 :=
log_of_left_le_one zero_le_one
@[simp]
theorem log_zero_right (b : Ordinal) : log b 0 = 0 := by
obtain hb | hb := lt_or_le 1 b
· rw [log_def hb, ← Ordinal.le_zero, pred_le, succ_zero]
apply csInf_le'
rw [mem_setOf, opow_one]
exact bot_lt_of_lt hb
· rw [log_of_left_le_one hb]
@[simp]
theorem log_one_left : ∀ b, log 1 b = 0 :=
log_of_left_le_one le_rfl
theorem succ_log_def {b x : Ordinal} (hb : 1 < b) (hx : x ≠ 0) :
succ (log b x) = sInf { o : Ordinal | x < b ^ o } := by
let t := sInf { o : Ordinal | x < b ^ o }
have : x < b ^ t := csInf_mem (log_nonempty hb)
rcases zero_or_succ_or_limit t with (h | h | h)
· refine ((one_le_iff_ne_zero.2 hx).not_lt ?_).elim
simpa only [h, opow_zero] using this
· rw [show log b x = pred t from log_def hb x, succ_pred_iff_is_succ.2 h]
· rcases (lt_opow_of_limit (zero_lt_one.trans hb).ne' h).1 this with ⟨a, h₁, h₂⟩
exact h₁.not_le.elim ((le_csInf_iff'' (log_nonempty hb)).1 le_rfl a h₂)
| Mathlib/SetTheory/Ordinal/Exponential.lean | 311 | 316 | theorem lt_opow_succ_log_self {b : Ordinal} (hb : 1 < b) (x : Ordinal) :
x < b ^ succ (log b x) := by | rcases eq_or_ne x 0 with (rfl | hx)
· apply opow_pos _ (zero_lt_one.trans hb)
· rw [succ_log_def hb hx]
exact csInf_mem (log_nonempty hb) |
/-
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
/-!
# 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 / ‖x‖)
else if 0 ≤ x.im then Real.arcsin ((-x).im / ‖x‖) + π else Real.arcsin ((-x).im / ‖x‖) - π
theorem sin_arg (x : ℂ) : Real.sin (arg x) = x.im / ‖x‖ := by
unfold arg; split_ifs <;>
simp [sub_eq_add_neg, arg, Real.sin_arcsin (abs_le.1 (abs_im_div_norm_le_one x)).1
(abs_le.1 (abs_im_div_norm_le_one x)).2, Real.sin_add, neg_div, Real.arcsin_neg, Real.sin_neg]
theorem cos_arg {x : ℂ} (hx : x ≠ 0) : Real.cos (arg x) = x.re / ‖x‖ := by
rw [arg]
split_ifs with h₁ h₂
· rw [Real.cos_arcsin]
field_simp [Real.sqrt_sq, (norm_pos_iff.mpr 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₁), *]
@[simp]
theorem norm_mul_exp_arg_mul_I (x : ℂ) : ‖x‖ * exp (arg x * I) = x := by
rcases eq_or_ne x 0 with (rfl | hx)
· simp
· have : ‖x‖ ≠ 0 := norm_ne_zero_iff.mpr hx
apply Complex.ext <;> field_simp [sin_arg, cos_arg hx, this, mul_comm ‖x‖]
@[simp]
theorem norm_mul_cos_add_sin_mul_I (x : ℂ) : (‖x‖ * (cos (arg x) + sin (arg x) * I) : ℂ) = x := by
rw [← exp_mul_I, norm_mul_exp_arg_mul_I]
@[simp]
lemma norm_mul_cos_arg (x : ℂ) : ‖x‖ * Real.cos (arg x) = x.re := by
simpa [-norm_mul_cos_add_sin_mul_I] using congr_arg re (norm_mul_cos_add_sin_mul_I x)
@[simp]
lemma norm_mul_sin_arg (x : ℂ) : ‖x‖ * Real.sin (arg x) = x.im := by
simpa [-norm_mul_cos_add_sin_mul_I] using congr_arg im (norm_mul_cos_add_sin_mul_I x)
theorem norm_eq_one_iff (z : ℂ) : ‖z‖ = 1 ↔ ∃ θ : ℝ, exp (θ * I) = z := by
refine ⟨fun hz => ⟨arg z, ?_⟩, ?_⟩
· calc
exp (arg z * I) = ‖z‖ * exp (arg z * I) := by rw [hz, ofReal_one, one_mul]
_ = z :=norm_mul_exp_arg_mul_I z
· rintro ⟨θ, rfl⟩
exact Complex.norm_exp_ofReal_mul_I θ
@[deprecated (since := "2025-02-16")] alias abs_mul_exp_arg_mul_I := norm_mul_exp_arg_mul_I
@[deprecated (since := "2025-02-16")] alias abs_mul_cos_add_sin_mul_I := norm_mul_cos_add_sin_mul_I
@[deprecated (since := "2025-02-16")] alias abs_mul_cos_arg := norm_mul_cos_arg
@[deprecated (since := "2025-02-16")] alias abs_mul_sin_arg := norm_mul_sin_arg
@[deprecated (since := "2025-02-16")] alias abs_eq_one_iff := norm_eq_one_iff
@[simp]
theorem range_exp_mul_I : (Set.range fun x : ℝ => exp (x * I)) = Metric.sphere 0 1 := by
ext x
simp only [mem_sphere_zero_iff_norm, norm_eq_one_iff, Set.mem_range]
theorem arg_mul_cos_add_sin_mul_I {r : ℝ} (hr : 0 < r) {θ : ℝ} (hθ : θ ∈ Set.Ioc (-π) π) :
arg (r * (cos θ + sin θ * I)) = θ := by
simp only [arg, norm_mul, norm_cos_add_sin_mul_I, Complex.norm_of_nonneg hr.le, mul_one]
simp only [re_ofReal_mul, im_ofReal_mul, neg_im, ← ofReal_cos, ← ofReal_sin, ←
mk_eq_add_mul_I, neg_div, mul_div_cancel_left₀ _ hr.ne', mul_nonneg_iff_right_nonneg_of_pos hr]
by_cases h₁ : θ ∈ Set.Icc (-(π / 2)) (π / 2)
· rw [if_pos]
exacts [Real.arcsin_sin' h₁, Real.cos_nonneg_of_mem_Icc h₁]
· rw [Set.mem_Icc, not_and_or, not_le, not_le] at h₁
rcases h₁ with h₁ | h₁
· replace hθ := hθ.1
have hcos : Real.cos θ < 0 := by
rw [← neg_pos, ← Real.cos_add_pi]
refine Real.cos_pos_of_mem_Ioo ⟨?_, ?_⟩ <;> linarith
have hsin : Real.sin θ < 0 := Real.sin_neg_of_neg_of_neg_pi_lt (by linarith) hθ
rw [if_neg, if_neg, ← Real.sin_add_pi, Real.arcsin_sin, add_sub_cancel_right] <;> [linarith;
linarith; exact hsin.not_le; exact hcos.not_le]
· replace hθ := hθ.2
have hcos : Real.cos θ < 0 := Real.cos_neg_of_pi_div_two_lt_of_lt h₁ (by linarith)
have hsin : 0 ≤ Real.sin θ := Real.sin_nonneg_of_mem_Icc ⟨by linarith, hθ⟩
rw [if_neg, if_pos, ← Real.sin_sub_pi, Real.arcsin_sin, sub_add_cancel] <;> [linarith;
linarith; exact hsin; exact hcos.not_le]
theorem arg_cos_add_sin_mul_I {θ : ℝ} (hθ : θ ∈ Set.Ioc (-π) π) : arg (cos θ + sin θ * I) = θ := by
rw [← one_mul (_ + _), ← ofReal_one, arg_mul_cos_add_sin_mul_I zero_lt_one hθ]
lemma arg_exp_mul_I (θ : ℝ) :
arg (exp (θ * I)) = toIocMod (mul_pos two_pos Real.pi_pos) (-π) θ := by
convert arg_cos_add_sin_mul_I (θ := toIocMod (mul_pos two_pos Real.pi_pos) (-π) θ) _ using 2
· rw [← exp_mul_I, eq_sub_of_add_eq <| toIocMod_add_toIocDiv_zsmul _ _ θ, ofReal_sub,
ofReal_zsmul, ofReal_mul, ofReal_ofNat, exp_mul_I_periodic.sub_zsmul_eq]
· convert toIocMod_mem_Ioc _ _ _
ring
@[simp]
theorem arg_zero : arg 0 = 0 := by simp [arg, le_refl]
theorem ext_norm_arg {x y : ℂ} (h₁ : ‖x‖ = ‖y‖) (h₂ : x.arg = y.arg) : x = y := by
rw [← norm_mul_exp_arg_mul_I x, ← norm_mul_exp_arg_mul_I y, h₁, h₂]
theorem ext_norm_arg_iff {x y : ℂ} : x = y ↔ ‖x‖ = ‖y‖ ∧ arg x = arg y :=
⟨fun h => h ▸ ⟨rfl, rfl⟩, and_imp.2 ext_norm_arg⟩
@[deprecated (since := "2025-02-16")] alias ext_abs_arg := ext_norm_arg
@[deprecated (since := "2025-02-16")] alias ext_abs_arg_iff := ext_norm_arg_iff
theorem arg_mem_Ioc (z : ℂ) : arg z ∈ Set.Ioc (-π) π := by
have hπ : 0 < π := Real.pi_pos
rcases eq_or_ne z 0 with (rfl | hz)
· simp [hπ, hπ.le]
rcases existsUnique_add_zsmul_mem_Ioc Real.two_pi_pos (arg z) (-π) with ⟨N, hN, -⟩
rw [two_mul, neg_add_cancel_left, ← two_mul, zsmul_eq_mul] at hN
rw [← norm_mul_cos_add_sin_mul_I z, ← cos_add_int_mul_two_pi _ N, ← sin_add_int_mul_two_pi _ N]
have := arg_mul_cos_add_sin_mul_I (norm_pos_iff.mpr hz) hN
push_cast at this
rwa [this]
@[simp]
theorem range_arg : Set.range arg = Set.Ioc (-π) π :=
(Set.range_subset_iff.2 arg_mem_Ioc).antisymm fun _ hx => ⟨_, arg_cos_add_sin_mul_I hx⟩
theorem arg_le_pi (x : ℂ) : arg x ≤ π :=
(arg_mem_Ioc x).2
theorem neg_pi_lt_arg (x : ℂ) : -π < arg x :=
(arg_mem_Ioc x).1
theorem abs_arg_le_pi (z : ℂ) : |arg z| ≤ π :=
abs_le.2 ⟨(neg_pi_lt_arg z).le, arg_le_pi z⟩
@[simp]
theorem arg_nonneg_iff {z : ℂ} : 0 ≤ arg z ↔ 0 ≤ z.im := by
rcases eq_or_ne z 0 with (rfl | h₀); · simp
calc
0 ≤ arg z ↔ 0 ≤ Real.sin (arg z) :=
⟨fun h => Real.sin_nonneg_of_mem_Icc ⟨h, arg_le_pi z⟩, by
contrapose!
intro h
exact Real.sin_neg_of_neg_of_neg_pi_lt h (neg_pi_lt_arg _)⟩
_ ↔ _ := by rw [sin_arg, le_div_iff₀ (norm_pos_iff.mpr h₀), zero_mul]
@[simp]
theorem arg_neg_iff {z : ℂ} : arg z < 0 ↔ z.im < 0 :=
lt_iff_lt_of_le_iff_le arg_nonneg_iff
theorem arg_real_mul (x : ℂ) {r : ℝ} (hr : 0 < r) : arg (r * x) = arg x := by
rcases eq_or_ne x 0 with (rfl | hx); · rw [mul_zero]
conv_lhs =>
rw [← norm_mul_cos_add_sin_mul_I x, ← mul_assoc, ← ofReal_mul,
arg_mul_cos_add_sin_mul_I (mul_pos hr (norm_pos_iff.mpr hx)) x.arg_mem_Ioc]
theorem arg_mul_real {r : ℝ} (hr : 0 < r) (x : ℂ) : arg (x * r) = arg x :=
mul_comm x r ▸ arg_real_mul x hr
theorem arg_eq_arg_iff {x y : ℂ} (hx : x ≠ 0) (hy : y ≠ 0) :
arg x = arg y ↔ (‖y‖ / ‖x‖ : ℂ) * x = y := by
simp only [ext_norm_arg_iff, norm_mul, norm_div, norm_real, norm_norm,
div_mul_cancel₀ _ (norm_ne_zero_iff.mpr hx), eq_self_iff_true, true_and]
rw [← ofReal_div, arg_real_mul]
exact div_pos (norm_pos_iff.mpr hy) (norm_pos_iff.mpr hx)
@[simp] lemma arg_one : arg 1 = 0 := by simp [arg, zero_le_one]
/-- This holds true for all `x : ℂ` because of the junk values `0 / 0 = 0` and `arg 0 = 0`. -/
@[simp] lemma arg_div_self (x : ℂ) : arg (x / x) = 0 := by
obtain rfl | hx := eq_or_ne x 0 <;> simp [*]
@[simp]
theorem arg_neg_one : arg (-1) = π := by simp [arg, le_refl, not_le.2 (zero_lt_one' ℝ)]
@[simp]
theorem arg_I : arg I = π / 2 := by simp [arg, le_refl]
@[simp]
theorem arg_neg_I : arg (-I) = -(π / 2) := by simp [arg, le_refl]
@[simp]
theorem tan_arg (x : ℂ) : Real.tan (arg x) = x.im / x.re := by
by_cases h : x = 0
· simp only [h, zero_div, Complex.zero_im, Complex.arg_zero, Real.tan_zero, Complex.zero_re]
rw [Real.tan_eq_sin_div_cos, sin_arg, cos_arg h,
div_div_div_cancel_right₀ (norm_ne_zero_iff.mpr h)]
theorem arg_ofReal_of_nonneg {x : ℝ} (hx : 0 ≤ x) : arg x = 0 := by simp [arg, hx]
@[simp, norm_cast]
lemma natCast_arg {n : ℕ} : arg n = 0 :=
ofReal_natCast n ▸ arg_ofReal_of_nonneg n.cast_nonneg
@[simp]
lemma ofNat_arg {n : ℕ} [n.AtLeastTwo] : arg ofNat(n) = 0 :=
natCast_arg
theorem arg_eq_zero_iff {z : ℂ} : arg z = 0 ↔ 0 ≤ z.re ∧ z.im = 0 := by
refine ⟨fun h => ?_, ?_⟩
· rw [← norm_mul_cos_add_sin_mul_I z, h]
simp [norm_nonneg]
· obtain ⟨x, y⟩ := z
rintro ⟨h, rfl : y = 0⟩
exact arg_ofReal_of_nonneg h
open ComplexOrder in
lemma arg_eq_zero_iff_zero_le {z : ℂ} : arg z = 0 ↔ 0 ≤ z := by
rw [arg_eq_zero_iff, eq_comm, nonneg_iff]
theorem arg_eq_pi_iff {z : ℂ} : arg z = π ↔ z.re < 0 ∧ z.im = 0 := by
by_cases h₀ : z = 0
· simp [h₀, lt_irrefl, Real.pi_ne_zero.symm]
constructor
· intro h
rw [← norm_mul_cos_add_sin_mul_I z, h]
simp [h₀]
· obtain ⟨x, y⟩ := z
rintro ⟨h : x < 0, rfl : y = 0⟩
rw [← arg_neg_one, ← arg_real_mul (-1) (neg_pos.2 h)]
simp [← ofReal_def]
open ComplexOrder in
lemma arg_eq_pi_iff_lt_zero {z : ℂ} : arg z = π ↔ z < 0 := arg_eq_pi_iff
theorem arg_lt_pi_iff {z : ℂ} : arg z < π ↔ 0 ≤ z.re ∨ z.im ≠ 0 := by
rw [(arg_le_pi z).lt_iff_ne, not_iff_comm, not_or, not_le, Classical.not_not, arg_eq_pi_iff]
theorem arg_ofReal_of_neg {x : ℝ} (hx : x < 0) : arg x = π :=
arg_eq_pi_iff.2 ⟨hx, rfl⟩
theorem arg_eq_pi_div_two_iff {z : ℂ} : arg z = π / 2 ↔ z.re = 0 ∧ 0 < z.im := by
by_cases h₀ : z = 0; · simp [h₀, lt_irrefl, Real.pi_div_two_pos.ne]
constructor
· intro h
rw [← norm_mul_cos_add_sin_mul_I z, h]
simp [h₀]
· obtain ⟨x, y⟩ := z
rintro ⟨rfl : x = 0, hy : 0 < y⟩
rw [← arg_I, ← arg_real_mul I hy, ofReal_mul', I_re, I_im, mul_zero, mul_one]
theorem arg_eq_neg_pi_div_two_iff {z : ℂ} : arg z = -(π / 2) ↔ z.re = 0 ∧ z.im < 0 := by
by_cases h₀ : z = 0; · simp [h₀, lt_irrefl, Real.pi_ne_zero]
constructor
· intro h
rw [← norm_mul_cos_add_sin_mul_I z, h]
simp [h₀]
· obtain ⟨x, y⟩ := z
rintro ⟨rfl : x = 0, hy : y < 0⟩
rw [← arg_neg_I, ← arg_real_mul (-I) (neg_pos.2 hy), mk_eq_add_mul_I]
simp
theorem arg_of_re_nonneg {x : ℂ} (hx : 0 ≤ x.re) : arg x = Real.arcsin (x.im / ‖x‖) :=
if_pos hx
theorem arg_of_re_neg_of_im_nonneg {x : ℂ} (hx_re : x.re < 0) (hx_im : 0 ≤ x.im) :
arg x = Real.arcsin ((-x).im / ‖x‖) + π := by
simp only [arg, hx_re.not_le, hx_im, if_true, if_false]
theorem arg_of_re_neg_of_im_neg {x : ℂ} (hx_re : x.re < 0) (hx_im : x.im < 0) :
arg x = Real.arcsin ((-x).im / ‖x‖) - π := by
simp only [arg, hx_re.not_le, hx_im.not_le, if_false]
theorem arg_of_im_nonneg_of_ne_zero {z : ℂ} (h₁ : 0 ≤ z.im) (h₂ : z ≠ 0) :
arg z = Real.arccos (z.re / ‖z‖) := by
rw [← cos_arg h₂, Real.arccos_cos (arg_nonneg_iff.2 h₁) (arg_le_pi _)]
theorem arg_of_im_pos {z : ℂ} (hz : 0 < z.im) : arg z = Real.arccos (z.re / ‖z‖) :=
arg_of_im_nonneg_of_ne_zero hz.le fun h => hz.ne' <| h.symm ▸ rfl
theorem arg_of_im_neg {z : ℂ} (hz : z.im < 0) : arg z = -Real.arccos (z.re / ‖z‖) := by
have h₀ : z ≠ 0 := mt (congr_arg im) hz.ne
rw [← cos_arg h₀, ← Real.cos_neg, Real.arccos_cos, neg_neg]
exacts [neg_nonneg.2 (arg_neg_iff.2 hz).le, neg_le.2 (neg_pi_lt_arg z).le]
theorem arg_conj (x : ℂ) : arg (conj x) = if arg x = π then π else -arg x := by
simp_rw [arg_eq_pi_iff, arg, neg_im, conj_im, conj_re, norm_conj, neg_div, neg_neg,
Real.arcsin_neg]
rcases lt_trichotomy x.re 0 with (hr | hr | hr) <;>
rcases lt_trichotomy x.im 0 with (hi | hi | hi)
· simp [hr, hr.not_le, hi.le, hi.ne, not_le.2 hi, add_comm]
· simp [hr, hr.not_le, hi]
· simp [hr, hr.not_le, hi.ne.symm, hi.le, not_le.2 hi, sub_eq_neg_add]
· simp [hr]
· simp [hr]
· simp [hr]
· simp [hr, hr.le, hi.ne]
· simp [hr, hr.le, hr.le.not_lt]
· simp [hr, hr.le, hr.le.not_lt]
theorem arg_inv (x : ℂ) : arg x⁻¹ = if arg x = π then π else -arg x := by
rw [← arg_conj, inv_def, mul_comm]
by_cases hx : x = 0
· simp [hx]
· exact arg_real_mul (conj x) (by simp [hx])
@[simp] lemma abs_arg_inv (x : ℂ) : |x⁻¹.arg| = |x.arg| := by rw [arg_inv]; split_ifs <;> simp [*]
-- TODO: Replace the next two lemmas by general facts about periodic functions
lemma norm_eq_one_iff' : ‖x‖ = 1 ↔ ∃ θ ∈ Set.Ioc (-π) π, exp (θ * I) = x := by
rw [norm_eq_one_iff]
constructor
· rintro ⟨θ, rfl⟩
refine ⟨toIocMod (mul_pos two_pos Real.pi_pos) (-π) θ, ?_, ?_⟩
· convert toIocMod_mem_Ioc _ _ _
ring
· rw [eq_sub_of_add_eq <| toIocMod_add_toIocDiv_zsmul _ _ θ, ofReal_sub,
ofReal_zsmul, ofReal_mul, ofReal_ofNat, exp_mul_I_periodic.sub_zsmul_eq]
· rintro ⟨θ, _, rfl⟩
exact ⟨θ, rfl⟩
@[deprecated (since := "2025-02-16")] alias abs_eq_one_iff' := norm_eq_one_iff'
lemma image_exp_Ioc_eq_sphere : (fun θ : ℝ ↦ exp (θ * I)) '' Set.Ioc (-π) π = sphere 0 1 := by
ext; simpa using norm_eq_one_iff'.symm
theorem arg_le_pi_div_two_iff {z : ℂ} : arg z ≤ π / 2 ↔ 0 ≤ re z ∨ im z < 0 := by
rcases le_or_lt 0 (re z) with hre | hre
· simp only [hre, arg_of_re_nonneg hre, Real.arcsin_le_pi_div_two, true_or]
simp only [hre.not_le, false_or]
rcases le_or_lt 0 (im z) with him | him
· simp only [him.not_lt]
rw [iff_false, not_le, arg_of_re_neg_of_im_nonneg hre him, ← sub_lt_iff_lt_add, half_sub,
Real.neg_pi_div_two_lt_arcsin, neg_im, neg_div, neg_lt_neg_iff, div_lt_one, ←
abs_of_nonneg him, abs_im_lt_norm]
exacts [hre.ne, norm_pos_iff.mpr <| ne_of_apply_ne re hre.ne]
· simp only [him]
rw [iff_true, arg_of_re_neg_of_im_neg hre him]
exact (sub_le_self _ Real.pi_pos.le).trans (Real.arcsin_le_pi_div_two _)
theorem neg_pi_div_two_le_arg_iff {z : ℂ} : -(π / 2) ≤ arg z ↔ 0 ≤ re z ∨ 0 ≤ im z := by
rcases le_or_lt 0 (re z) with hre | hre
· simp only [hre, arg_of_re_nonneg hre, Real.neg_pi_div_two_le_arcsin, true_or]
simp only [hre.not_le, false_or]
rcases le_or_lt 0 (im z) with him | him
· simp only [him]
rw [iff_true, arg_of_re_neg_of_im_nonneg hre him]
exact (Real.neg_pi_div_two_le_arcsin _).trans (le_add_of_nonneg_right Real.pi_pos.le)
· simp only [him.not_le]
rw [iff_false, not_le, arg_of_re_neg_of_im_neg hre him, sub_lt_iff_lt_add', ←
sub_eq_add_neg, sub_half, Real.arcsin_lt_pi_div_two, div_lt_one, neg_im, ← abs_of_neg him,
abs_im_lt_norm]
exacts [hre.ne, norm_pos_iff.mpr <| ne_of_apply_ne re hre.ne]
lemma neg_pi_div_two_lt_arg_iff {z : ℂ} : -(π / 2) < arg z ↔ 0 < re z ∨ 0 ≤ im z := by
rw [lt_iff_le_and_ne, neg_pi_div_two_le_arg_iff, ne_comm, Ne, arg_eq_neg_pi_div_two_iff]
rcases lt_trichotomy z.re 0 with hre | hre | hre
· simp [hre.ne, hre.not_le, hre.not_lt]
· simp [hre]
· simp [hre, hre.le, hre.ne']
lemma arg_lt_pi_div_two_iff {z : ℂ} : arg z < π / 2 ↔ 0 < re z ∨ im z < 0 ∨ z = 0 := by
rw [lt_iff_le_and_ne, arg_le_pi_div_two_iff, Ne, arg_eq_pi_div_two_iff]
rcases lt_trichotomy z.re 0 with hre | hre | hre
· have : z ≠ 0 := by simp [Complex.ext_iff, hre.ne]
simp [hre.ne, hre.not_le, hre.not_lt, this]
· have : z = 0 ↔ z.im = 0 := by simp [Complex.ext_iff, hre]
simp [hre, this, or_comm, le_iff_eq_or_lt]
· simp [hre, hre.le, hre.ne']
@[simp]
theorem abs_arg_le_pi_div_two_iff {z : ℂ} : |arg z| ≤ π / 2 ↔ 0 ≤ re z := by
rw [abs_le, arg_le_pi_div_two_iff, neg_pi_div_two_le_arg_iff, ← or_and_left, ← not_le,
and_not_self_iff, or_false]
@[simp]
theorem abs_arg_lt_pi_div_two_iff {z : ℂ} : |arg z| < π / 2 ↔ 0 < re z ∨ z = 0 := by
rw [abs_lt, arg_lt_pi_div_two_iff, neg_pi_div_two_lt_arg_iff, ← or_and_left]
rcases eq_or_ne z 0 with hz | hz
· simp [hz]
· simp_rw [hz, or_false, ← not_lt, not_and_self_iff, or_false]
@[simp]
theorem arg_conj_coe_angle (x : ℂ) : (arg (conj x) : Real.Angle) = -arg x := by
by_cases h : arg x = π <;> simp [arg_conj, h]
@[simp]
theorem arg_inv_coe_angle (x : ℂ) : (arg x⁻¹ : Real.Angle) = -arg x := by
by_cases h : arg x = π <;> simp [arg_inv, h]
theorem arg_neg_eq_arg_sub_pi_of_im_pos {x : ℂ} (hi : 0 < x.im) : arg (-x) = arg x - π := by
rw [arg_of_im_pos hi, arg_of_im_neg (show (-x).im < 0 from Left.neg_neg_iff.2 hi)]
simp [neg_div, Real.arccos_neg]
theorem arg_neg_eq_arg_add_pi_of_im_neg {x : ℂ} (hi : x.im < 0) : arg (-x) = arg x + π := by
rw [arg_of_im_neg hi, arg_of_im_pos (show 0 < (-x).im from Left.neg_pos_iff.2 hi)]
simp [neg_div, Real.arccos_neg, add_comm, ← sub_eq_add_neg]
theorem arg_neg_eq_arg_sub_pi_iff {x : ℂ} :
arg (-x) = arg x - π ↔ 0 < x.im ∨ x.im = 0 ∧ x.re < 0 := by
rcases lt_trichotomy x.im 0 with (hi | hi | hi)
· simp [hi, hi.ne, hi.not_lt, arg_neg_eq_arg_add_pi_of_im_neg, sub_eq_add_neg, ←
add_eq_zero_iff_eq_neg, Real.pi_ne_zero]
· rw [(ext rfl hi : x = x.re)]
rcases lt_trichotomy x.re 0 with (hr | hr | hr)
· rw [arg_ofReal_of_neg hr, ← ofReal_neg, arg_ofReal_of_nonneg (Left.neg_pos_iff.2 hr).le]
simp [hr]
· simp [hr, hi, Real.pi_ne_zero]
· rw [arg_ofReal_of_nonneg hr.le, ← ofReal_neg, arg_ofReal_of_neg (Left.neg_neg_iff.2 hr)]
simp [hr.not_lt, ← add_eq_zero_iff_eq_neg, Real.pi_ne_zero]
· simp [hi, arg_neg_eq_arg_sub_pi_of_im_pos]
theorem arg_neg_eq_arg_add_pi_iff {x : ℂ} :
arg (-x) = arg x + π ↔ x.im < 0 ∨ x.im = 0 ∧ 0 < x.re := by
rcases lt_trichotomy x.im 0 with (hi | hi | hi)
· simp [hi, arg_neg_eq_arg_add_pi_of_im_neg]
· rw [(ext rfl hi : x = x.re)]
rcases lt_trichotomy x.re 0 with (hr | hr | hr)
· rw [arg_ofReal_of_neg hr, ← ofReal_neg, arg_ofReal_of_nonneg (Left.neg_pos_iff.2 hr).le]
simp [hr.not_lt, ← two_mul, Real.pi_ne_zero]
· simp [hr, hi, Real.pi_ne_zero.symm]
· rw [arg_ofReal_of_nonneg hr.le, ← ofReal_neg, arg_ofReal_of_neg (Left.neg_neg_iff.2 hr)]
simp [hr]
· simp [hi, hi.ne.symm, hi.not_lt, arg_neg_eq_arg_sub_pi_of_im_pos, sub_eq_add_neg, ←
add_eq_zero_iff_neg_eq, Real.pi_ne_zero]
theorem arg_neg_coe_angle {x : ℂ} (hx : x ≠ 0) : (arg (-x) : Real.Angle) = arg x + π := by
rcases lt_trichotomy x.im 0 with (hi | hi | hi)
· rw [arg_neg_eq_arg_add_pi_of_im_neg hi, Real.Angle.coe_add]
· rw [(ext rfl hi : x = x.re)]
rcases lt_trichotomy x.re 0 with (hr | hr | hr)
· rw [arg_ofReal_of_neg hr, ← ofReal_neg, arg_ofReal_of_nonneg (Left.neg_pos_iff.2 hr).le, ←
Real.Angle.coe_add, ← two_mul, Real.Angle.coe_two_pi, Real.Angle.coe_zero]
· exact False.elim (hx (ext hr hi))
· rw [arg_ofReal_of_nonneg hr.le, ← ofReal_neg, arg_ofReal_of_neg (Left.neg_neg_iff.2 hr),
Real.Angle.coe_zero, zero_add]
· rw [arg_neg_eq_arg_sub_pi_of_im_pos hi, Real.Angle.coe_sub, Real.Angle.sub_coe_pi_eq_add_coe_pi]
| Mathlib/Analysis/SpecialFunctions/Complex/Arg.lean | 448 | 450 | theorem arg_mul_cos_add_sin_mul_I_eq_toIocMod {r : ℝ} (hr : 0 < r) (θ : ℝ) :
arg (r * (cos θ + sin θ * I)) = toIocMod Real.two_pi_pos (-π) θ := by | have hi : toIocMod Real.two_pi_pos (-π) θ ∈ Set.Ioc (-π) π := by |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Sébastien Gouëzel,
Rémy Degenne, David Loeffler
-/
import Mathlib.Analysis.SpecialFunctions.Pow.Complex
import Qq
/-! # Power function on `ℝ`
We construct the power functions `x ^ y`, where `x` and `y` are real numbers.
-/
noncomputable section
open Real ComplexConjugate Finset Set
/-
## Definitions
-/
namespace Real
variable {x y z : ℝ}
/-- The real power function `x ^ y`, defined as the real part of the complex power function.
For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`, one sets `0 ^ 0=1` and `0 ^ y=0` for
`y ≠ 0`. For `x < 0`, the definition is somewhat arbitrary as it depends on the choice of a complex
determination of the logarithm. With our conventions, it is equal to `exp (y log x) cos (π y)`. -/
noncomputable def rpow (x y : ℝ) :=
((x : ℂ) ^ (y : ℂ)).re
noncomputable instance : Pow ℝ ℝ := ⟨rpow⟩
@[simp]
theorem rpow_eq_pow (x y : ℝ) : rpow x y = x ^ y := rfl
theorem rpow_def (x y : ℝ) : x ^ y = ((x : ℂ) ^ (y : ℂ)).re := rfl
theorem rpow_def_of_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) :
x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) := by
simp only [rpow_def, Complex.cpow_def]; split_ifs <;>
simp_all [(Complex.ofReal_log hx).symm, -Complex.ofReal_mul,
(Complex.ofReal_mul _ _).symm, Complex.exp_ofReal_re, Complex.ofReal_eq_zero]
theorem rpow_def_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : x ^ y = exp (log x * y) := by
rw [rpow_def_of_nonneg (le_of_lt hx), if_neg (ne_of_gt hx)]
theorem exp_mul (x y : ℝ) : exp (x * y) = exp x ^ y := by rw [rpow_def_of_pos (exp_pos _), log_exp]
@[simp, norm_cast]
theorem rpow_intCast (x : ℝ) (n : ℤ) : x ^ (n : ℝ) = x ^ n := by
simp only [rpow_def, ← Complex.ofReal_zpow, Complex.cpow_intCast, Complex.ofReal_intCast,
Complex.ofReal_re]
@[simp, norm_cast]
theorem rpow_natCast (x : ℝ) (n : ℕ) : x ^ (n : ℝ) = x ^ n := by simpa using rpow_intCast x n
@[simp]
| Mathlib/Analysis/SpecialFunctions/Pow/Real.lean | 60 | 60 | theorem exp_one_rpow (x : ℝ) : exp 1 ^ x = exp x := by | rw [← exp_mul, one_mul] |
/-
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.Algebra.ModEq
import Mathlib.Algebra.Order.Archimedean.Basic
import Mathlib.Algebra.Ring.Periodic
import Mathlib.Data.Int.SuccPred
import Mathlib.Order.Circular
/-!
# Reducing to an interval modulo its length
This file defines operations that reduce a number (in an `Archimedean`
`LinearOrderedAddCommGroup`) to a number in a given interval, modulo the length of that
interval.
## Main definitions
* `toIcoDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`,
subtracted from `b`, is in `Ico a (a + p)`.
* `toIcoMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ico a (a + p)`.
* `toIocDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`,
subtracted from `b`, is in `Ioc a (a + p)`.
* `toIocMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ioc a (a + p)`.
-/
assert_not_exists TwoSidedIdeal
noncomputable section
section LinearOrderedAddCommGroup
variable {α : Type*} [AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α] [hα : Archimedean α]
{p : α} (hp : 0 < p)
{a b c : α} {n : ℤ}
section
include hp
/--
The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ico a (a + p)`. -/
def toIcoDiv (a b : α) : ℤ :=
(existsUnique_sub_zsmul_mem_Ico hp b a).choose
theorem sub_toIcoDiv_zsmul_mem_Ico (a b : α) : b - toIcoDiv hp a b • p ∈ Set.Ico a (a + p) :=
(existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.1
theorem toIcoDiv_eq_of_sub_zsmul_mem_Ico (h : b - n • p ∈ Set.Ico a (a + p)) :
toIcoDiv hp a b = n :=
((existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.2 _ h).symm
/--
The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ioc a (a + p)`. -/
def toIocDiv (a b : α) : ℤ :=
(existsUnique_sub_zsmul_mem_Ioc hp b a).choose
theorem sub_toIocDiv_zsmul_mem_Ioc (a b : α) : b - toIocDiv hp a b • p ∈ Set.Ioc a (a + p) :=
(existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.1
theorem toIocDiv_eq_of_sub_zsmul_mem_Ioc (h : b - n • p ∈ Set.Ioc a (a + p)) :
toIocDiv hp a b = n :=
((existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.2 _ h).symm
/-- Reduce `b` to the interval `Ico a (a + p)`. -/
def toIcoMod (a b : α) : α :=
b - toIcoDiv hp a b • p
/-- Reduce `b` to the interval `Ioc a (a + p)`. -/
def toIocMod (a b : α) : α :=
b - toIocDiv hp a b • p
theorem toIcoMod_mem_Ico (a b : α) : toIcoMod hp a b ∈ Set.Ico a (a + p) :=
sub_toIcoDiv_zsmul_mem_Ico hp a b
theorem toIcoMod_mem_Ico' (b : α) : toIcoMod hp 0 b ∈ Set.Ico 0 p := by
convert toIcoMod_mem_Ico hp 0 b
exact (zero_add p).symm
theorem toIocMod_mem_Ioc (a b : α) : toIocMod hp a b ∈ Set.Ioc a (a + p) :=
sub_toIocDiv_zsmul_mem_Ioc hp a b
theorem left_le_toIcoMod (a b : α) : a ≤ toIcoMod hp a b :=
(Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).1
theorem left_lt_toIocMod (a b : α) : a < toIocMod hp a b :=
(Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).1
theorem toIcoMod_lt_right (a b : α) : toIcoMod hp a b < a + p :=
(Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).2
theorem toIocMod_le_right (a b : α) : toIocMod hp a b ≤ a + p :=
(Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).2
@[simp]
theorem self_sub_toIcoDiv_zsmul (a b : α) : b - toIcoDiv hp a b • p = toIcoMod hp a b :=
rfl
@[simp]
theorem self_sub_toIocDiv_zsmul (a b : α) : b - toIocDiv hp a b • p = toIocMod hp a b :=
rfl
@[simp]
theorem toIcoDiv_zsmul_sub_self (a b : α) : toIcoDiv hp a b • p - b = -toIcoMod hp a b := by
rw [toIcoMod, neg_sub]
@[simp]
theorem toIocDiv_zsmul_sub_self (a b : α) : toIocDiv hp a b • p - b = -toIocMod hp a b := by
rw [toIocMod, neg_sub]
@[simp]
theorem toIcoMod_sub_self (a b : α) : toIcoMod hp a b - b = -toIcoDiv hp a b • p := by
rw [toIcoMod, sub_sub_cancel_left, neg_smul]
@[simp]
theorem toIocMod_sub_self (a b : α) : toIocMod hp a b - b = -toIocDiv hp a b • p := by
rw [toIocMod, sub_sub_cancel_left, neg_smul]
@[simp]
theorem self_sub_toIcoMod (a b : α) : b - toIcoMod hp a b = toIcoDiv hp a b • p := by
rw [toIcoMod, sub_sub_cancel]
@[simp]
theorem self_sub_toIocMod (a b : α) : b - toIocMod hp a b = toIocDiv hp a b • p := by
rw [toIocMod, sub_sub_cancel]
@[simp]
theorem toIcoMod_add_toIcoDiv_zsmul (a b : α) : toIcoMod hp a b + toIcoDiv hp a b • p = b := by
rw [toIcoMod, sub_add_cancel]
@[simp]
theorem toIocMod_add_toIocDiv_zsmul (a b : α) : toIocMod hp a b + toIocDiv hp a b • p = b := by
rw [toIocMod, sub_add_cancel]
@[simp]
theorem toIcoDiv_zsmul_sub_toIcoMod (a b : α) : toIcoDiv hp a b • p + toIcoMod hp a b = b := by
rw [add_comm, toIcoMod_add_toIcoDiv_zsmul]
@[simp]
theorem toIocDiv_zsmul_sub_toIocMod (a b : α) : toIocDiv hp a b • p + toIocMod hp a b = b := by
rw [add_comm, toIocMod_add_toIocDiv_zsmul]
theorem toIcoMod_eq_iff : toIcoMod hp a b = c ↔ c ∈ Set.Ico a (a + p) ∧ ∃ z : ℤ, b = c + z • p := by
refine
⟨fun h =>
⟨h ▸ toIcoMod_mem_Ico hp a b, toIcoDiv hp a b, h ▸ (toIcoMod_add_toIcoDiv_zsmul _ _ _).symm⟩,
?_⟩
simp_rw [← @sub_eq_iff_eq_add]
rintro ⟨hc, n, rfl⟩
rw [← toIcoDiv_eq_of_sub_zsmul_mem_Ico hp hc, toIcoMod]
| Mathlib/Algebra/Order/ToIntervalMod.lean | 153 | 154 | theorem toIocMod_eq_iff : toIocMod hp a b = c ↔ c ∈ Set.Ioc a (a + p) ∧ ∃ z : ℤ, b = c + z • p := by | refine |
/-
Copyright (c) 2023 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz
-/
import Mathlib.CategoryTheory.Sites.Sieves
import Mathlib.CategoryTheory.EffectiveEpi.Basic
/-!
# Effective epimorphic sieves
We define the notion of effective epimorphic (pre)sieves and provide some API for relating the
notion with the notions of effective epimorphism and effective epimorphic family.
More precisely, if `f` is a morphism, then `f` is an effective epi if and only if the sieve
it generates is effective epimorphic; see `CategoryTheory.Sieve.effectiveEpimorphic_singleton`.
The analogous statement for a family of morphisms is in the theorem
`CategoryTheory.Sieve.effectiveEpimorphic_family`.
-/
namespace CategoryTheory
open Limits
variable {C : Type*} [Category C]
/-- A sieve is effective epimorphic if the associated cocone is a colimit cocone. -/
def Sieve.EffectiveEpimorphic {X : C} (S : Sieve X) : Prop :=
Nonempty (IsColimit (S : Presieve X).cocone)
/-- A presieve is effective epimorphic if the cocone associated to the sieve it generates
is a colimit cocone. -/
abbrev Presieve.EffectiveEpimorphic {X : C} (S : Presieve X) : Prop :=
(Sieve.generate S).EffectiveEpimorphic
/--
The sieve of morphisms which factor through a given morphism `f`.
This is equal to `Sieve.generate (Presieve.singleton f)`, but has
more convenient definitional properties.
-/
def Sieve.generateSingleton {X Y : C} (f : Y ⟶ X) : Sieve X where
arrows Z := { g | ∃ (e : Z ⟶ Y), e ≫ f = g }
downward_closed := by
rintro W Z g ⟨e,rfl⟩ q
exact ⟨q ≫ e, by simp⟩
lemma Sieve.generateSingleton_eq {X Y : C} (f : Y ⟶ X) :
Sieve.generate (Presieve.singleton f) = Sieve.generateSingleton f := by
ext Z g
constructor
· rintro ⟨W,i,p,⟨⟩,rfl⟩
exact ⟨i,rfl⟩
· rintro ⟨g,h⟩
exact ⟨Y,g,f,⟨⟩,h⟩
/--
Implementation: This is a construction which will be used in the proof that
the sieve generated by a single arrow is effective epimorphic if and only if
the arrow is an effective epi.
-/
def isColimitOfEffectiveEpiStruct {X Y : C} (f : Y ⟶ X) (Hf : EffectiveEpiStruct f) :
IsColimit (Sieve.generateSingleton f : Presieve X).cocone :=
letI D := ObjectProperty.FullSubcategory fun T : Over X => Sieve.generateSingleton f T.hom
letI F : D ⥤ _ := (Sieve.generateSingleton f).arrows.diagram
{ desc := fun S => Hf.desc (S.ι.app ⟨Over.mk f, ⟨𝟙 _, by simp⟩⟩) <| by
intro Z g₁ g₂ h
let Y' : D := ⟨Over.mk f, 𝟙 _, by simp⟩
let Z' : D := ⟨Over.mk (g₁ ≫ f), g₁, rfl⟩
let g₁' : Z' ⟶ Y' := Over.homMk g₁
let g₂' : Z' ⟶ Y' := Over.homMk g₂ (by simp [Y', Z', h])
change F.map g₁' ≫ _ = F.map g₂' ≫ _
simp only [Y', F, S.w]
fac := by
rintro S ⟨T,g,hT⟩
dsimp
nth_rewrite 1 [← hT, Category.assoc, Hf.fac]
let y : D := ⟨Over.mk f, 𝟙 _, by simp⟩
let x : D := ⟨Over.mk T.hom, g, hT⟩
let g' : x ⟶ y := Over.homMk g
change F.map g' ≫ _ = _
rw [S.w]
rfl
uniq := by
intro S m hm
dsimp
generalize_proofs h1 h2
apply Hf.uniq _ h2
exact hm ⟨Over.mk f, 𝟙 _, by simp⟩ }
/--
Implementation: This is a construction which will be used in the proof that
the sieve generated by a single arrow is effective epimorphic if and only if
the arrow is an effective epi.
-/
noncomputable
def effectiveEpiStructOfIsColimit {X Y : C} (f : Y ⟶ X)
(Hf : IsColimit (Sieve.generateSingleton f : Presieve X).cocone) :
EffectiveEpiStruct f :=
let aux {W : C} (e : Y ⟶ W)
(h : ∀ {Z : C} (g₁ g₂ : Z ⟶ Y), g₁ ≫ f = g₂ ≫ f → g₁ ≫ e = g₂ ≫ e) :
Cocone (Sieve.generateSingleton f).arrows.diagram :=
{ pt := W
ι := {
app := fun ⟨_,hT⟩ => hT.choose ≫ e
naturality := by
rintro ⟨A,hA⟩ ⟨B,hB⟩ (q : A ⟶ B)
dsimp; simp only [← Category.assoc, Category.comp_id]
apply h
rw [Category.assoc, hB.choose_spec, hA.choose_spec, Over.w] } }
{ desc := fun {_} e h => Hf.desc (aux e h)
fac := by
intro W e h
dsimp
have := Hf.fac (aux e h) ⟨Over.mk f, 𝟙 _, by simp⟩
dsimp [aux] at this; rw [this]; clear this
nth_rewrite 2 [← Category.id_comp e]
apply h
generalize_proofs hh
rw [hh.choose_spec, Category.id_comp]
uniq := by
intro W e h m hm
dsimp
apply Hf.uniq (aux e h)
rintro ⟨A,g,hA⟩
dsimp
nth_rewrite 1 [← hA, Category.assoc, hm]
apply h
generalize_proofs hh
rwa [hh.choose_spec] }
theorem Sieve.effectiveEpimorphic_singleton {X Y : C} (f : Y ⟶ X) :
(Presieve.singleton f).EffectiveEpimorphic ↔ (EffectiveEpi f) := by
constructor
· intro (h : Nonempty _)
rw [Sieve.generateSingleton_eq] at h
constructor
apply Nonempty.map (effectiveEpiStructOfIsColimit _) h
· rintro ⟨h⟩
show Nonempty _
rw [Sieve.generateSingleton_eq]
apply Nonempty.map (isColimitOfEffectiveEpiStruct _) h
/--
The sieve of morphisms which factor through a morphism in a given family.
This is equal to `Sieve.generate (Presieve.ofArrows X π)`, but has
more convenient definitional properties.
-/
def Sieve.generateFamily {B : C} {α : Type*} (X : α → C) (π : (a : α) → (X a ⟶ B)) :
Sieve B where
arrows Y := { f | ∃ (a : α) (g : Y ⟶ X a), g ≫ π a = f }
downward_closed := by
rintro Y₁ Y₂ g₁ ⟨a,q,rfl⟩ e
exact ⟨a, e ≫ q, by simp⟩
lemma Sieve.generateFamily_eq {B : C} {α : Type*} (X : α → C) (π : (a : α) → (X a ⟶ B)) :
Sieve.generate (Presieve.ofArrows X π) = Sieve.generateFamily X π := by
ext Y g
constructor
· rintro ⟨W, g, f, ⟨a⟩, rfl⟩
exact ⟨a, g, rfl⟩
· rintro ⟨a, g, rfl⟩
exact ⟨_, g, π a, ⟨a⟩, rfl⟩
/--
Implementation: This is a construction which will be used in the proof that
the sieve generated by a family of arrows is effective epimorphic if and only if
the family is an effective epi.
-/
def isColimitOfEffectiveEpiFamilyStruct {B : C} {α : Type*}
(X : α → C) (π : (a : α) → (X a ⟶ B)) (H : EffectiveEpiFamilyStruct X π) :
IsColimit (Sieve.generateFamily X π : Presieve B).cocone :=
letI D := ObjectProperty.FullSubcategory fun T : Over B => Sieve.generateFamily X π T.hom
letI F : D ⥤ _ := (Sieve.generateFamily X π).arrows.diagram
{ desc := fun S => H.desc (fun a => S.ι.app ⟨Over.mk (π a), ⟨a,𝟙 _, by simp⟩⟩) <| by
intro Z a₁ a₂ g₁ g₂ h
dsimp
let A₁ : D := ⟨Over.mk (π a₁), a₁, 𝟙 _, by simp⟩
let A₂ : D := ⟨Over.mk (π a₂), a₂, 𝟙 _, by simp⟩
let Z' : D := ⟨Over.mk (g₁ ≫ π a₁), a₁, g₁, rfl⟩
let i₁ : Z' ⟶ A₁ := Over.homMk g₁
let i₂ : Z' ⟶ A₂ := Over.homMk g₂
change F.map i₁ ≫ _ = F.map i₂ ≫ _
simp only [F, A₁, A₂, S.w]
fac := by
intro S ⟨T, a, (g : T.left ⟶ X a), hT⟩
dsimp
nth_rewrite 1 [← hT, Category.assoc, H.fac]
let A : D := ⟨Over.mk (π a), a, 𝟙 _, by simp⟩
let B : D := ⟨Over.mk T.hom, a, g, hT⟩
let i : B ⟶ A := Over.homMk g
change F.map i ≫ _ = _
rw [S.w]
rfl
uniq := by
intro S m hm; dsimp
apply H.uniq
intro a
exact hm ⟨Over.mk (π a), a, 𝟙 _, by simp⟩ }
/--
Implementation: This is a construction which will be used in the proof that
the sieve generated by a family of arrows is effective epimorphic if and only if
the family is an effective epi.
-/
noncomputable
def effectiveEpiFamilyStructOfIsColimit {B : C} {α : Type*}
(X : α → C) (π : (a : α) → (X a ⟶ B))
(H : IsColimit (Sieve.generateFamily X π : Presieve B).cocone) :
EffectiveEpiFamilyStruct X π :=
let aux {W : C} (e : (a : α) → (X a ⟶ W))
(h : ∀ {Z : C} (a₁ a₂ : α) (g₁ : Z ⟶ X a₁) (g₂ : Z ⟶ X a₂),
g₁ ≫ π _ = g₂ ≫ π _ → g₁ ≫ e _ = g₂ ≫ e _) :
Cocone (Sieve.generateFamily X π).arrows.diagram := {
pt := W
ι := {
app := fun ⟨_,hT⟩ => hT.choose_spec.choose ≫ e hT.choose
naturality := by
intro ⟨A,a,(g₁ : A.left ⟶ _),ha⟩ ⟨B,b,(g₂ : B.left ⟶ _),hb⟩ (q : A ⟶ B)
dsimp; rw [Category.comp_id, ← Category.assoc]
apply h; rw [Category.assoc]
generalize_proofs h1 h2 h3 h4
rw [h2.choose_spec, h4.choose_spec, Over.w] } }
{ desc := fun {_} e h => H.desc (aux e h)
fac := by
intro W e h a
dsimp
have := H.fac (aux e h) ⟨Over.mk (π a), a, 𝟙 _, by simp⟩
dsimp [aux] at this; rw [this]; clear this
conv_rhs => rw [← Category.id_comp (e a)]
apply h
generalize_proofs h1 h2
rw [h2.choose_spec, Category.id_comp]
uniq := by
intro W e h m hm
apply H.uniq (aux e h)
rintro ⟨T, a, (g : T.left ⟶ _), ha⟩
dsimp
nth_rewrite 1 [← ha, Category.assoc, hm]
apply h
generalize_proofs h1 h2
rwa [h2.choose_spec] }
| Mathlib/CategoryTheory/Sites/EffectiveEpimorphic.lean | 244 | 255 | theorem Sieve.effectiveEpimorphic_family {B : C} {α : Type*}
(X : α → C) (π : (a : α) → (X a ⟶ B)) :
(Presieve.ofArrows X π).EffectiveEpimorphic ↔ EffectiveEpiFamily X π := by | constructor
· intro (h : Nonempty _)
rw [Sieve.generateFamily_eq] at h
constructor
apply Nonempty.map (effectiveEpiFamilyStructOfIsColimit _ _) h
· rintro ⟨h⟩
show Nonempty _
rw [Sieve.generateFamily_eq]
apply Nonempty.map (isColimitOfEffectiveEpiFamilyStruct _ _) h |
/-
Copyright (c) 2021 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Scott Carnahan
-/
import Mathlib.Algebra.Algebra.Subalgebra.Lattice
import Mathlib.Algebra.Module.BigOperators
import Mathlib.Data.Finset.MulAntidiagonal
import Mathlib.Data.Finset.SMulAntidiagonal
import Mathlib.GroupTheory.GroupAction.Ring
import Mathlib.RingTheory.HahnSeries.Addition
/-!
# Multiplicative properties of Hahn series
If `Γ` is ordered and `R` has zero, then `HahnSeries Γ R` consists of formal series over `Γ` with
coefficients in `R`, whose supports are partially well-ordered. This module introduces
multiplication and scalar multiplication on Hahn series. If `Γ` is an ordered cancellative
commutative additive monoid and `R` is a semiring, then we get a semiring structure on
`HahnSeries Γ R`. If `Γ` has an ordered vector-addition on `Γ'` and `R` has a scalar multiplication
on `V`, we define `HahnModule Γ' R V` as a type alias for `HahnSeries Γ' V` that admits a scalar
multiplication from `HahnSeries Γ R`. The scalar action of `R` on `HahnSeries Γ R` is compatible
with the action of `HahnSeries Γ R` on `HahnModule Γ' R V`.
## Main Definitions
* `HahnModule` is a type alias for `HahnSeries`, which we use for defining scalar multiplication
of `HahnSeries Γ R` on `HahnModule Γ' R V` for an `R`-module `V`, where `Γ'` admits an ordered
cancellative vector addition operation from `Γ`. The type alias allows us to avoid a potential
instance diamond.
* `HahnModule.of` is the isomorphism from `HahnSeries Γ V` to `HahnModule Γ R V`.
* `HahnSeries.C` is the `constant term` ring homomorphism `R →+* HahnSeries Γ R`.
* `HahnSeries.embDomainRingHom` is the ring homomorphism `HahnSeries Γ R →+* HahnSeries Γ' R`
induced by an order embedding `Γ ↪o Γ'`.
## Main results
* If `R` is a (commutative) (semi-)ring, then so is `HahnSeries Γ R`.
* If `V` is an `R`-module, then `HahnModule Γ' R V` is a `HahnSeries Γ R`-module.
## TODO
The following may be useful for composing vertex operators, but they seem to take time.
* rightTensorMap: `HahnModule Γ' R U ⊗[R] V →ₗ[R] HahnModule Γ' R (U ⊗[R] V)`
* leftTensorMap: `U ⊗[R] HahnModule Γ' R V →ₗ[R] HahnModule Γ' R (U ⊗[R] V)`
## References
- [J. van der Hoeven, *Operators on Generalized Power Series*][van_der_hoeven]
-/
open Finset Function Pointwise
noncomputable section
variable {Γ Γ' R S V : Type*}
namespace HahnSeries
variable [Zero Γ] [PartialOrder Γ]
instance [Zero R] [One R] : One (HahnSeries Γ R) :=
⟨single 0 1⟩
open Classical in
@[simp]
theorem coeff_one [Zero R] [One R] {a : Γ} :
(1 : HahnSeries Γ R).coeff a = if a = 0 then 1 else 0 :=
coeff_single
@[deprecated (since := "2025-01-31")] alias one_coeff := coeff_one
@[simp]
theorem single_zero_one [Zero R] [One R] : single (0 : Γ) (1 : R) = 1 :=
rfl
@[simp]
theorem support_one [MulZeroOneClass R] [Nontrivial R] : support (1 : HahnSeries Γ R) = {0} :=
support_single_of_ne one_ne_zero
@[simp]
theorem orderTop_one [MulZeroOneClass R] [Nontrivial R] : orderTop (1 : HahnSeries Γ R) = 0 := by
rw [← single_zero_one, orderTop_single one_ne_zero, WithTop.coe_eq_zero]
@[simp]
theorem order_one [MulZeroOneClass R] : order (1 : HahnSeries Γ R) = 0 := by
cases subsingleton_or_nontrivial R
· rw [Subsingleton.elim (1 : HahnSeries Γ R) 0, order_zero]
· exact order_single one_ne_zero
@[simp]
theorem leadingCoeff_one [MulZeroOneClass R] : (1 : HahnSeries Γ R).leadingCoeff = 1 := by
simp [leadingCoeff_eq]
@[simp]
protected lemma map_one [MonoidWithZero R] [MonoidWithZero S] (f : R →*₀ S) :
(1 : HahnSeries Γ R).map f = (1 : HahnSeries Γ S) := by
ext g
by_cases h : g = 0 <;> simp [h]
end HahnSeries
/-- We introduce a type alias for `HahnSeries` in order to work with scalar multiplication by
series. If we wrote a `SMul (HahnSeries Γ R) (HahnSeries Γ V)` instance, then when
`V = HahnSeries Γ R`, we would have two different actions of `HahnSeries Γ R` on `HahnSeries Γ V`.
See `Mathlib.Algebra.Polynomial.Module` for more discussion on this problem. -/
@[nolint unusedArguments]
def HahnModule (Γ R V : Type*) [PartialOrder Γ] [Zero V] [SMul R V] :=
HahnSeries Γ V
namespace HahnModule
section
variable [PartialOrder Γ] [Zero V] [SMul R V]
/-- The casting function to the type synonym. -/
def of (R : Type*) [SMul R V] : HahnSeries Γ V ≃ HahnModule Γ R V :=
Equiv.refl _
/-- Recursion principle to reduce a result about the synonym to the original type. -/
@[elab_as_elim]
def rec {motive : HahnModule Γ R V → Sort*} (h : ∀ x : HahnSeries Γ V, motive (of R x)) :
∀ x, motive x :=
fun x => h <| (of R).symm x
@[ext]
theorem ext (x y : HahnModule Γ R V) (h : ((of R).symm x).coeff = ((of R).symm y).coeff) : x = y :=
(of R).symm.injective <| HahnSeries.coeff_inj.1 h
end
section SMul
variable [PartialOrder Γ] [AddCommMonoid V] [SMul R V]
instance instAddCommMonoid : AddCommMonoid (HahnModule Γ R V) :=
inferInstanceAs <| AddCommMonoid (HahnSeries Γ V)
instance instBaseSMul {V} [Monoid R] [AddMonoid V] [DistribMulAction R V] :
SMul R (HahnModule Γ R V) :=
inferInstanceAs <| SMul R (HahnSeries Γ V)
@[simp] theorem of_zero : of R (0 : HahnSeries Γ V) = 0 := rfl
@[simp] theorem of_add (x y : HahnSeries Γ V) : of R (x + y) = of R x + of R y := rfl
@[simp] theorem of_symm_zero : (of R).symm (0 : HahnModule Γ R V) = 0 := rfl
@[simp] theorem of_symm_add (x y : HahnModule Γ R V) :
(of R).symm (x + y) = (of R).symm x + (of R).symm y := rfl
variable [PartialOrder Γ'] [VAdd Γ Γ'] [IsOrderedCancelVAdd Γ Γ']
instance instSMul [Zero R] : SMul (HahnSeries Γ R) (HahnModule Γ' R V) where
smul x y := (of R) {
coeff := fun a =>
∑ ij ∈ VAddAntidiagonal x.isPWO_support ((of R).symm y).isPWO_support a,
x.coeff ij.fst • ((of R).symm y).coeff ij.snd
isPWO_support' :=
haveI h :
{ a : Γ' |
(∑ ij ∈ VAddAntidiagonal x.isPWO_support ((of R).symm y).isPWO_support a,
x.coeff ij.fst • ((of R).symm y).coeff ij.snd) ≠ 0 } ⊆
{ a : Γ' | (VAddAntidiagonal x.isPWO_support
((of R).symm y).isPWO_support a).Nonempty } := by
intro a ha
contrapose! ha
simp [not_nonempty_iff_eq_empty.1 ha]
isPWO_support_vaddAntidiagonal.mono h }
theorem coeff_smul [Zero R] (x : HahnSeries Γ R) (y : HahnModule Γ' R V) (a : Γ') :
((of R).symm <| x • y).coeff a =
∑ ij ∈ VAddAntidiagonal x.isPWO_support ((of R).symm y).isPWO_support a,
x.coeff ij.fst • ((of R).symm y).coeff ij.snd :=
rfl
@[deprecated (since := "2025-01-31")] alias smul_coeff := coeff_smul
end SMul
section SMulZeroClass
variable [PartialOrder Γ] [PartialOrder Γ'] [VAdd Γ Γ'] [IsOrderedCancelVAdd Γ Γ']
[AddCommMonoid V]
instance instBaseSMulZeroClass [SMulZeroClass R V] :
SMulZeroClass R (HahnModule Γ R V) :=
inferInstanceAs <| SMulZeroClass R (HahnSeries Γ V)
@[simp] theorem of_smul [SMulZeroClass R V] (r : R) (x : HahnSeries Γ V) :
(of R) (r • x) = r • (of R) x := rfl
@[simp] theorem of_symm_smul [SMulZeroClass R V] (r : R) (x : HahnModule Γ R V) :
(of R).symm (r • x) = r • (of R).symm x := rfl
variable [Zero R]
instance instSMulZeroClass [SMulZeroClass R V] :
SMulZeroClass (HahnSeries Γ R) (HahnModule Γ' R V) where
smul_zero x := by
ext
simp [coeff_smul]
theorem coeff_smul_right [SMulZeroClass R V] {x : HahnSeries Γ R} {y : HahnModule Γ' R V} {a : Γ'}
{s : Set Γ'} (hs : s.IsPWO) (hys : ((of R).symm y).support ⊆ s) :
((of R).symm <| x • y).coeff a =
∑ ij ∈ VAddAntidiagonal x.isPWO_support hs a,
x.coeff ij.fst • ((of R).symm y).coeff ij.snd := by
classical
rw [coeff_smul]
apply sum_subset_zero_on_sdiff (vaddAntidiagonal_mono_right hys) _ fun _ _ => rfl
intro b hb
simp only [not_and, mem_sdiff, mem_vaddAntidiagonal, HahnSeries.mem_support, not_imp_not] at hb
rw [hb.2 hb.1.1 hb.1.2.2, smul_zero]
@[deprecated (since := "2025-01-31")] alias smul_coeff_right := coeff_smul_right
theorem coeff_smul_left [SMulWithZero R V] {x : HahnSeries Γ R}
{y : HahnModule Γ' R V} {a : Γ'} {s : Set Γ}
(hs : s.IsPWO) (hxs : x.support ⊆ s) :
((of R).symm <| x • y).coeff a =
∑ ij ∈ VAddAntidiagonal hs ((of R).symm y).isPWO_support a,
x.coeff ij.fst • ((of R).symm y).coeff ij.snd := by
classical
rw [coeff_smul]
apply sum_subset_zero_on_sdiff (vaddAntidiagonal_mono_left hxs) _ fun _ _ => rfl
intro b hb
simp only [not_and', mem_sdiff, mem_vaddAntidiagonal, HahnSeries.mem_support, not_ne_iff] at hb
rw [hb.2 ⟨hb.1.2.1, hb.1.2.2⟩, zero_smul]
@[deprecated (since := "2025-01-31")] alias smul_coeff_left := coeff_smul_left
end SMulZeroClass
section DistribSMul
variable [PartialOrder Γ] [PartialOrder Γ'] [VAdd Γ Γ'] [IsOrderedCancelVAdd Γ Γ'] [AddCommMonoid V]
theorem smul_add [Zero R] [DistribSMul R V] (x : HahnSeries Γ R) (y z : HahnModule Γ' R V) :
x • (y + z) = x • y + x • z := by
ext k
have hwf := ((of R).symm y).isPWO_support.union ((of R).symm z).isPWO_support
rw [coeff_smul_right hwf, of_symm_add]
· simp_all only [HahnSeries.coeff_add', Pi.add_apply, smul_add, of_symm_add]
rw [coeff_smul_right hwf Set.subset_union_right,
coeff_smul_right hwf Set.subset_union_left]
simp_all [sum_add_distrib]
· intro b
simp_all only [Set.isPWO_union, HahnSeries.isPWO_support, and_self, of_symm_add,
HahnSeries.coeff_add', Pi.add_apply, ne_eq, Set.mem_union, HahnSeries.mem_support]
contrapose!
intro h
rw [h.1, h.2, add_zero]
instance instDistribSMul [MonoidWithZero R] [DistribSMul R V] : DistribSMul (HahnSeries Γ R)
(HahnModule Γ' R V) where
smul_add := smul_add
theorem add_smul [AddCommMonoid R] [SMulWithZero R V] {x y : HahnSeries Γ R}
{z : HahnModule Γ' R V} (h : ∀ (r s : R) (u : V), (r + s) • u = r • u + s • u) :
(x + y) • z = x • z + y • z := by
ext a
have hwf := x.isPWO_support.union y.isPWO_support
rw [coeff_smul_left hwf, HahnSeries.coeff_add', of_symm_add]
· simp_all only [Pi.add_apply, HahnSeries.coeff_add']
rw [coeff_smul_left hwf Set.subset_union_right,
coeff_smul_left hwf Set.subset_union_left]
simp only [HahnSeries.coeff_add, h, sum_add_distrib]
· intro b
simp_all only [Set.isPWO_union, HahnSeries.isPWO_support, and_self, HahnSeries.mem_support,
HahnSeries.coeff_add, ne_eq, Set.mem_union, Set.mem_setOf_eq, mem_support]
contrapose!
intro h
rw [h.1, h.2, add_zero]
theorem coeff_single_smul_vadd [MulZeroClass R] [SMulWithZero R V] {r : R} {x : HahnModule Γ' R V}
{a : Γ'} {b : Γ} :
((of R).symm (HahnSeries.single b r • x)).coeff (b +ᵥ a) = r • ((of R).symm x).coeff a := by
by_cases hr : r = 0
· simp_all only [map_zero, zero_smul, coeff_smul, HahnSeries.support_zero, HahnSeries.coeff_zero,
sum_const_zero]
simp only [hr, coeff_smul, coeff_smul, HahnSeries.support_single_of_ne, ne_eq, not_false_iff,
smul_eq_mul]
by_cases hx : ((of R).symm x).coeff a = 0
· simp only [hx, smul_zero]
rw [sum_congr _ fun _ _ => rfl, sum_empty]
ext ⟨a1, a2⟩
simp only [not_mem_empty, not_and, Set.mem_singleton_iff, Classical.not_not,
mem_vaddAntidiagonal, Set.mem_setOf_eq, iff_false]
rintro rfl h2 h1
rw [IsCancelVAdd.left_cancel a1 a2 a h1] at h2
exact h2 hx
trans ∑ ij ∈ {(b, a)},
(HahnSeries.single b r).coeff ij.fst • ((of R).symm x).coeff ij.snd
· apply sum_congr _ fun _ _ => rfl
ext ⟨a1, a2⟩
simp only [Set.mem_singleton_iff, Prod.mk_inj, mem_vaddAntidiagonal, mem_singleton,
Set.mem_setOf_eq]
constructor
· rintro ⟨rfl, _, h1⟩
exact ⟨rfl, IsCancelVAdd.left_cancel a1 a2 a h1⟩
· rintro ⟨rfl, rfl⟩
exact ⟨rfl, by exact hx, rfl⟩
· simp
@[deprecated (since := "2025-01-31")] alias single_smul_coeff_add := coeff_single_smul_vadd
theorem coeff_single_zero_smul {Γ} [AddCommMonoid Γ] [PartialOrder Γ] [AddAction Γ Γ']
[IsOrderedCancelVAdd Γ Γ'] [MulZeroClass R] [SMulWithZero R V] {r : R}
{x : HahnModule Γ' R V} {a : Γ'} :
((of R).symm ((HahnSeries.single 0 r : HahnSeries Γ R) • x)).coeff a =
r • ((of R).symm x).coeff a := by
nth_rw 1 [← zero_vadd Γ a]
exact coeff_single_smul_vadd
@[deprecated (since := "2025-01-31")] alias single_zero_smul_coeff := coeff_single_zero_smul
@[simp]
theorem single_zero_smul_eq_smul (Γ) [AddCommMonoid Γ] [PartialOrder Γ] [AddAction Γ Γ']
[IsOrderedCancelVAdd Γ Γ'] [MulZeroClass R] [SMulWithZero R V] {r : R}
{x : HahnModule Γ' R V} :
(HahnSeries.single (0 : Γ) r) • x = r • x := by
ext
exact coeff_single_zero_smul
@[simp]
theorem zero_smul' [Zero R] [SMulWithZero R V] {x : HahnModule Γ' R V} :
(0 : HahnSeries Γ R) • x = 0 := by
ext
simp [coeff_smul]
@[simp]
theorem one_smul' {Γ} [AddCommMonoid Γ] [PartialOrder Γ] [AddAction Γ Γ'] [IsOrderedCancelVAdd Γ Γ']
[MonoidWithZero R] [MulActionWithZero R V] {x : HahnModule Γ' R V} :
(1 : HahnSeries Γ R) • x = x := by
ext g
exact coeff_single_zero_smul.trans (one_smul R (x.coeff g))
| Mathlib/RingTheory/HahnSeries/Multiplication.lean | 331 | 339 | theorem support_smul_subset_vadd_support' [MulZeroClass R] [SMulWithZero R V] {x : HahnSeries Γ R}
{y : HahnModule Γ' R V} :
((of R).symm (x • y)).support ⊆ x.support +ᵥ ((of R).symm y).support := by | apply Set.Subset.trans (fun x hx => _) support_vaddAntidiagonal_subset_vadd
· exact x.isPWO_support
· exact y.isPWO_support
intro x hx
contrapose! hx
simp only [Set.mem_setOf_eq, not_nonempty_iff_eq_empty] at hx |
/-
Copyright (c) 2021 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Algebra.Group.Embedding
import Mathlib.Algebra.Order.Ring.Int
import Mathlib.Algebra.Ring.CharZero
import Mathlib.Order.Interval.Finset.Basic
/-!
# Finite intervals of integers
This file proves that `ℤ` is a `LocallyFiniteOrder` and calculates the cardinality of its
intervals as finsets and fintypes.
-/
assert_not_exists Field
open Finset Int
namespace Int
instance instLocallyFiniteOrder : LocallyFiniteOrder ℤ where
finsetIcc a b :=
(Finset.range (b + 1 - a).toNat).map <| Nat.castEmbedding.trans <| addLeftEmbedding a
finsetIco a b := (Finset.range (b - a).toNat).map <| Nat.castEmbedding.trans <| addLeftEmbedding a
finsetIoc a b :=
(Finset.range (b - a).toNat).map <| Nat.castEmbedding.trans <| addLeftEmbedding (a + 1)
finsetIoo a b :=
(Finset.range (b - a - 1).toNat).map <| Nat.castEmbedding.trans <| addLeftEmbedding (a + 1)
finset_mem_Icc a b x := by
simp_rw [mem_map, mem_range, Int.lt_toNat, Function.Embedding.trans_apply,
Nat.castEmbedding_apply, addLeftEmbedding_apply]
constructor
· rintro ⟨a, h, rfl⟩
rw [lt_sub_iff_add_lt, Int.lt_add_one_iff, add_comm] at h
exact ⟨Int.le.intro a rfl, h⟩
· rintro ⟨ha, hb⟩
use (x - a).toNat
rw [← lt_add_one_iff] at hb
rw [toNat_sub_of_le ha]
exact ⟨sub_lt_sub_right hb _, add_sub_cancel _ _⟩
finset_mem_Ico a b x := by
simp_rw [mem_map, mem_range, Int.lt_toNat, Function.Embedding.trans_apply,
Nat.castEmbedding_apply, addLeftEmbedding_apply]
constructor
· rintro ⟨a, h, rfl⟩
exact ⟨Int.le.intro a rfl, lt_sub_iff_add_lt'.mp h⟩
· rintro ⟨ha, hb⟩
use (x - a).toNat
rw [toNat_sub_of_le ha]
exact ⟨sub_lt_sub_right hb _, add_sub_cancel _ _⟩
finset_mem_Ioc a b x := by
simp_rw [mem_map, mem_range, Int.lt_toNat, Function.Embedding.trans_apply,
Nat.castEmbedding_apply, addLeftEmbedding_apply]
constructor
· rintro ⟨a, h, rfl⟩
rw [← add_one_le_iff, le_sub_iff_add_le', add_comm _ (1 : ℤ), ← add_assoc] at h
exact ⟨Int.le.intro a rfl, h⟩
· rintro ⟨ha, hb⟩
use (x - (a + 1)).toNat
rw [toNat_sub_of_le ha, ← add_one_le_iff, sub_add, add_sub_cancel_right]
exact ⟨sub_le_sub_right hb _, add_sub_cancel _ _⟩
finset_mem_Ioo a b x := by
simp_rw [mem_map, mem_range, Int.lt_toNat, Function.Embedding.trans_apply,
Nat.castEmbedding_apply, addLeftEmbedding_apply]
constructor
· rintro ⟨a, h, rfl⟩
rw [sub_sub, lt_sub_iff_add_lt'] at h
exact ⟨Int.le.intro a rfl, h⟩
· rintro ⟨ha, hb⟩
use (x - (a + 1)).toNat
rw [toNat_sub_of_le ha, sub_sub]
exact ⟨sub_lt_sub_right hb _, add_sub_cancel _ _⟩
variable (a b : ℤ)
theorem Icc_eq_finset_map :
Icc a b =
(Finset.range (b + 1 - a).toNat).map (Nat.castEmbedding.trans <| addLeftEmbedding a) :=
rfl
theorem Ico_eq_finset_map :
Ico a b = (Finset.range (b - a).toNat).map (Nat.castEmbedding.trans <| addLeftEmbedding a) :=
rfl
theorem Ioc_eq_finset_map :
Ioc a b =
(Finset.range (b - a).toNat).map (Nat.castEmbedding.trans <| addLeftEmbedding (a + 1)) :=
rfl
theorem Ioo_eq_finset_map :
Ioo a b =
(Finset.range (b - a - 1).toNat).map (Nat.castEmbedding.trans <| addLeftEmbedding (a + 1)) :=
rfl
theorem uIcc_eq_finset_map :
uIcc a b = (range (max a b + 1 - min a b).toNat).map
(Nat.castEmbedding.trans <| addLeftEmbedding <| min a b) := rfl
@[simp]
theorem card_Icc : #(Icc a b) = (b + 1 - a).toNat := (card_map _).trans <| card_range _
@[simp]
theorem card_Ico : #(Ico a b) = (b - a).toNat := (card_map _).trans <| card_range _
@[simp]
theorem card_Ioc : #(Ioc a b) = (b - a).toNat := (card_map _).trans <| card_range _
@[simp]
theorem card_Ioo : #(Ioo a b) = (b - a - 1).toNat := (card_map _).trans <| card_range _
@[simp]
theorem card_uIcc : #(uIcc a b) = (b - a).natAbs + 1 :=
(card_map _).trans <|
(Nat.cast_inj (R := ℤ)).mp <| by
rw [card_range,
Int.toNat_of_nonneg (sub_nonneg_of_le <| le_add_one min_le_max), Int.natCast_add,
Int.natCast_natAbs, add_comm, add_sub_assoc, max_sub_min_eq_abs, add_comm, Int.ofNat_one]
theorem card_Icc_of_le (h : a ≤ b + 1) : (#(Icc a b) : ℤ) = b + 1 - a := by
rw [card_Icc, toNat_sub_of_le h]
theorem card_Ico_of_le (h : a ≤ b) : (#(Ico a b) : ℤ) = b - a := by
rw [card_Ico, toNat_sub_of_le h]
theorem card_Ioc_of_le (h : a ≤ b) : (#(Ioc a b) : ℤ) = b - a := by
rw [card_Ioc, toNat_sub_of_le h]
theorem card_Ioo_of_lt (h : a < b) : (#(Ioo a b) : ℤ) = b - a - 1 := by
rw [card_Ioo, sub_sub, toNat_sub_of_le h]
theorem Icc_eq_pair : Finset.Icc a (a + 1) = {a, a + 1} := by
ext
simp
omega
@[deprecated Fintype.card_Icc (since := "2025-03-28")]
theorem card_fintype_Icc : Fintype.card (Set.Icc a b) = (b + 1 - a).toNat := by
simp
@[deprecated Fintype.card_Ico (since := "2025-03-28")]
theorem card_fintype_Ico : Fintype.card (Set.Ico a b) = (b - a).toNat := by
simp
@[deprecated Fintype.card_Ioc (since := "2025-03-28")]
theorem card_fintype_Ioc : Fintype.card (Set.Ioc a b) = (b - a).toNat := by
simp
@[deprecated Fintype.card_Ioo (since := "2025-03-28")]
theorem card_fintype_Ioo : Fintype.card (Set.Ioo a b) = (b - a - 1).toNat := by
simp
@[deprecated Fintype.card_uIcc (since := "2025-03-28")]
theorem card_fintype_uIcc : Fintype.card (Set.uIcc a b) = (b - a).natAbs + 1 := by
simp
theorem card_fintype_Icc_of_le (h : a ≤ b + 1) : (Fintype.card (Set.Icc a b) : ℤ) = b + 1 - a := by
simp [h]
theorem card_fintype_Ico_of_le (h : a ≤ b) : (Fintype.card (Set.Ico a b) : ℤ) = b - a := by
simp [h]
| Mathlib/Data/Int/Interval.lean | 165 | 166 | theorem card_fintype_Ioc_of_le (h : a ≤ b) : (Fintype.card (Set.Ioc a b) : ℤ) = b - a := by | simp [h] |
/-
Copyright (c) 2019 Calle Sönne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Calle Sönne
-/
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic
import Mathlib.Analysis.Normed.Group.AddCircle
import Mathlib.Algebra.CharZero.Quotient
import Mathlib.Topology.Instances.Sign
/-!
# The type of angles
In this file we define `Real.Angle` to be the quotient group `ℝ/2πℤ` and prove a few simple lemmas
about trigonometric functions and angles.
-/
open Real
noncomputable section
namespace Real
/-- The type of angles -/
def Angle : Type :=
AddCircle (2 * π)
-- The `NormedAddCommGroup, Inhabited` instances should be constructed by a deriving handler.
-- https://github.com/leanprover-community/mathlib4/issues/380
namespace Angle
instance : NormedAddCommGroup Angle :=
inferInstanceAs (NormedAddCommGroup (AddCircle (2 * π)))
instance : Inhabited Angle :=
inferInstanceAs (Inhabited (AddCircle (2 * π)))
/-- The canonical map from `ℝ` to the quotient `Angle`. -/
@[coe]
protected def coe (r : ℝ) : Angle := QuotientAddGroup.mk r
instance : Coe ℝ Angle := ⟨Angle.coe⟩
instance : CircularOrder Real.Angle :=
QuotientAddGroup.circularOrder (hp' := ⟨by norm_num [pi_pos]⟩)
@[continuity]
theorem continuous_coe : Continuous ((↑) : ℝ → Angle) :=
continuous_quotient_mk'
/-- Coercion `ℝ → Angle` as an additive homomorphism. -/
def coeHom : ℝ →+ Angle :=
QuotientAddGroup.mk' _
@[simp]
theorem coe_coeHom : (coeHom : ℝ → Angle) = ((↑) : ℝ → Angle) :=
rfl
/-- An induction principle to deduce results for `Angle` from those for `ℝ`, used with
`induction θ using Real.Angle.induction_on`. -/
@[elab_as_elim]
protected theorem induction_on {p : Angle → Prop} (θ : Angle) (h : ∀ x : ℝ, p x) : p θ :=
Quotient.inductionOn' θ h
@[simp]
theorem coe_zero : ↑(0 : ℝ) = (0 : Angle) :=
rfl
@[simp]
theorem coe_add (x y : ℝ) : ↑(x + y : ℝ) = (↑x + ↑y : Angle) :=
rfl
@[simp]
theorem coe_neg (x : ℝ) : ↑(-x : ℝ) = -(↑x : Angle) :=
rfl
@[simp]
theorem coe_sub (x y : ℝ) : ↑(x - y : ℝ) = (↑x - ↑y : Angle) :=
rfl
theorem coe_nsmul (n : ℕ) (x : ℝ) : ↑(n • x : ℝ) = n • (↑x : Angle) :=
rfl
theorem coe_zsmul (z : ℤ) (x : ℝ) : ↑(z • x : ℝ) = z • (↑x : Angle) :=
rfl
theorem coe_eq_zero_iff {x : ℝ} : (x : Angle) = 0 ↔ ∃ n : ℤ, n • (2 * π) = x :=
AddCircle.coe_eq_zero_iff (2 * π)
@[simp, norm_cast]
theorem natCast_mul_eq_nsmul (x : ℝ) (n : ℕ) : ↑((n : ℝ) * x) = n • (↑x : Angle) := by
simpa only [nsmul_eq_mul] using coeHom.map_nsmul x n
@[simp, norm_cast]
theorem intCast_mul_eq_zsmul (x : ℝ) (n : ℤ) : ↑((n : ℝ) * x : ℝ) = n • (↑x : Angle) := by
simpa only [zsmul_eq_mul] using coeHom.map_zsmul x n
theorem angle_eq_iff_two_pi_dvd_sub {ψ θ : ℝ} : (θ : Angle) = ψ ↔ ∃ k : ℤ, θ - ψ = 2 * π * k := by
simp only [QuotientAddGroup.eq, AddSubgroup.zmultiples_eq_closure,
AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm]
rw [Angle.coe, Angle.coe, QuotientAddGroup.eq]
simp only [AddSubgroup.zmultiples_eq_closure,
AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm]
@[simp]
theorem coe_two_pi : ↑(2 * π : ℝ) = (0 : Angle) :=
angle_eq_iff_two_pi_dvd_sub.2 ⟨1, by rw [sub_zero, Int.cast_one, mul_one]⟩
@[simp]
theorem neg_coe_pi : -(π : Angle) = π := by
rw [← coe_neg, angle_eq_iff_two_pi_dvd_sub]
use -1
simp [two_mul, sub_eq_add_neg]
@[simp]
theorem two_nsmul_coe_div_two (θ : ℝ) : (2 : ℕ) • (↑(θ / 2) : Angle) = θ := by
rw [← coe_nsmul, two_nsmul, add_halves]
@[simp]
theorem two_zsmul_coe_div_two (θ : ℝ) : (2 : ℤ) • (↑(θ / 2) : Angle) = θ := by
rw [← coe_zsmul, two_zsmul, add_halves]
theorem two_nsmul_neg_pi_div_two : (2 : ℕ) • (↑(-π / 2) : Angle) = π := by
rw [two_nsmul_coe_div_two, coe_neg, neg_coe_pi]
theorem two_zsmul_neg_pi_div_two : (2 : ℤ) • (↑(-π / 2) : Angle) = π := by
rw [two_zsmul, ← two_nsmul, two_nsmul_neg_pi_div_two]
theorem sub_coe_pi_eq_add_coe_pi (θ : Angle) : θ - π = θ + π := by
rw [sub_eq_add_neg, neg_coe_pi]
@[simp]
theorem two_nsmul_coe_pi : (2 : ℕ) • (π : Angle) = 0 := by simp [← natCast_mul_eq_nsmul]
@[simp]
theorem two_zsmul_coe_pi : (2 : ℤ) • (π : Angle) = 0 := by simp [← intCast_mul_eq_zsmul]
@[simp]
| Mathlib/Analysis/SpecialFunctions/Trigonometric/Angle.lean | 141 | 142 | theorem coe_pi_add_coe_pi : (π : Real.Angle) + π = 0 := by | rw [← two_nsmul, two_nsmul_coe_pi] |
/-
Copyright (c) 2023 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser, Brendan Murphy
-/
import Mathlib.Data.Fin.Tuple.Basic
import Mathlib.Logic.Equiv.Fin.Basic
import Mathlib.Logic.Function.OfArity
/-!
# Currying and uncurrying of n-ary functions
A function of `n` arguments can either be written as `f a₁ a₂ ⋯ aₙ` or `f' ![a₁, a₂, ⋯, aₙ]`.
This file provides the currying and uncurrying operations that convert between the two, as
n-ary generalizations of the binary `curry` and `uncurry`.
## Main definitions
* `Function.OfArity.uncurry`: convert an `n`-ary function to a function from `Fin n → α`.
* `Function.OfArity.curry`: convert a function from `Fin n → α` to an `n`-ary function.
* `Function.FromTypes.uncurry`: convert an `p`-ary heterogeneous function to a
function from `(i : Fin n) → p i`.
* `Function.FromTypes.curry`: convert a function from `(i : Fin n) → p i` to a
`p`-ary heterogeneous function.
-/
universe u v w w'
namespace Function.FromTypes
open Matrix (vecCons vecHead vecTail vecEmpty)
/-- Uncurry all the arguments of `Function.FromTypes p τ` to get
a function from a tuple.
Note this can be used on raw functions if used. -/
def uncurry : {n : ℕ} → {p : Fin n → Type u} → {τ : Type u} →
(f : Function.FromTypes p τ) → ((i : Fin n) → p i) → τ
| 0 , _, _, f => fun _ => f
| _ + 1, _, _, f => fun args => (f (args 0)).uncurry (args ∘' Fin.succ)
/-- Curry all the arguments of `Function.FromTypes p τ` to get a function from a tuple. -/
def curry : {n : ℕ} → {p : Fin n → Type u} → {τ : Type u} →
(((i : Fin n) → p i) → τ) → Function.FromTypes p τ
| 0 , _, _, f => f isEmptyElim
| _ + 1, _, _, f => fun a => curry (fun args => f (Fin.cons a args))
@[simp]
theorem uncurry_apply_cons {n : ℕ} {α} {p : Fin n → Type u} {τ : Type u}
(f : Function.FromTypes (vecCons α p) τ) (a : α) (args : (i : Fin n) → p i) :
uncurry f (Fin.cons a args) = @uncurry _ p _ (f a) args := rfl
@[simp low]
theorem uncurry_apply_succ {n : ℕ} {p : Fin (n + 1) → Type u} {τ : Type u}
(f : Function.FromTypes p τ) (args : (i : Fin (n + 1)) → p i) :
uncurry f args = uncurry (f (args 0)) (Fin.tail args) :=
@uncurry_apply_cons n (p 0) (vecTail p) τ f (args 0) (Fin.tail args)
@[simp]
theorem curry_apply_cons {n : ℕ} {α} {p : Fin n → Type u} {τ : Type u}
(f : ((i : Fin (n + 1)) → (vecCons α p) i) → τ) (a : α) :
curry f a = @curry _ p _ (f ∘' Fin.cons a) := rfl
@[simp low]
theorem curry_apply_succ {n : ℕ} {p : Fin (n + 1) → Type u} {τ : Type u}
(f : ((i : Fin (n + 1)) → p i) → τ) (a : p 0) :
curry f a = curry (f ∘ Fin.cons a) := rfl
variable {n : ℕ} {p : Fin n → Type u} {τ : Type u}
@[simp]
theorem curry_uncurry (f : Function.FromTypes p τ) : curry (uncurry f) = f := by
induction n with
| zero => rfl
| succ n ih => exact funext (ih <| f ·)
@[simp]
| Mathlib/Data/Fin/Tuple/Curry.lean | 79 | 84 | theorem uncurry_curry (f : ((i : Fin n) → p i) → τ) :
uncurry (curry f) = f := by | ext args
induction n with
| zero => exact congrArg f (Subsingleton.allEq _ _)
| succ n ih => exact Eq.trans (ih _ _) (congrArg f (Fin.cons_self_tail args)) |
/-
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.Algebra.ModEq
import Mathlib.Algebra.Order.Archimedean.Basic
import Mathlib.Algebra.Ring.Periodic
import Mathlib.Data.Int.SuccPred
import Mathlib.Order.Circular
/-!
# Reducing to an interval modulo its length
This file defines operations that reduce a number (in an `Archimedean`
`LinearOrderedAddCommGroup`) to a number in a given interval, modulo the length of that
interval.
## Main definitions
* `toIcoDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`,
subtracted from `b`, is in `Ico a (a + p)`.
* `toIcoMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ico a (a + p)`.
* `toIocDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`,
subtracted from `b`, is in `Ioc a (a + p)`.
* `toIocMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ioc a (a + p)`.
-/
assert_not_exists TwoSidedIdeal
noncomputable section
section LinearOrderedAddCommGroup
variable {α : Type*} [AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α] [hα : Archimedean α]
{p : α} (hp : 0 < p)
{a b c : α} {n : ℤ}
section
include hp
/--
The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ico a (a + p)`. -/
def toIcoDiv (a b : α) : ℤ :=
(existsUnique_sub_zsmul_mem_Ico hp b a).choose
theorem sub_toIcoDiv_zsmul_mem_Ico (a b : α) : b - toIcoDiv hp a b • p ∈ Set.Ico a (a + p) :=
(existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.1
theorem toIcoDiv_eq_of_sub_zsmul_mem_Ico (h : b - n • p ∈ Set.Ico a (a + p)) :
toIcoDiv hp a b = n :=
((existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.2 _ h).symm
/--
The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ioc a (a + p)`. -/
def toIocDiv (a b : α) : ℤ :=
(existsUnique_sub_zsmul_mem_Ioc hp b a).choose
theorem sub_toIocDiv_zsmul_mem_Ioc (a b : α) : b - toIocDiv hp a b • p ∈ Set.Ioc a (a + p) :=
(existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.1
theorem toIocDiv_eq_of_sub_zsmul_mem_Ioc (h : b - n • p ∈ Set.Ioc a (a + p)) :
toIocDiv hp a b = n :=
((existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.2 _ h).symm
/-- Reduce `b` to the interval `Ico a (a + p)`. -/
def toIcoMod (a b : α) : α :=
b - toIcoDiv hp a b • p
/-- Reduce `b` to the interval `Ioc a (a + p)`. -/
def toIocMod (a b : α) : α :=
b - toIocDiv hp a b • p
theorem toIcoMod_mem_Ico (a b : α) : toIcoMod hp a b ∈ Set.Ico a (a + p) :=
sub_toIcoDiv_zsmul_mem_Ico hp a b
theorem toIcoMod_mem_Ico' (b : α) : toIcoMod hp 0 b ∈ Set.Ico 0 p := by
convert toIcoMod_mem_Ico hp 0 b
exact (zero_add p).symm
theorem toIocMod_mem_Ioc (a b : α) : toIocMod hp a b ∈ Set.Ioc a (a + p) :=
sub_toIocDiv_zsmul_mem_Ioc hp a b
theorem left_le_toIcoMod (a b : α) : a ≤ toIcoMod hp a b :=
(Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).1
theorem left_lt_toIocMod (a b : α) : a < toIocMod hp a b :=
(Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).1
theorem toIcoMod_lt_right (a b : α) : toIcoMod hp a b < a + p :=
(Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).2
theorem toIocMod_le_right (a b : α) : toIocMod hp a b ≤ a + p :=
(Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).2
@[simp]
theorem self_sub_toIcoDiv_zsmul (a b : α) : b - toIcoDiv hp a b • p = toIcoMod hp a b :=
rfl
@[simp]
theorem self_sub_toIocDiv_zsmul (a b : α) : b - toIocDiv hp a b • p = toIocMod hp a b :=
rfl
@[simp]
theorem toIcoDiv_zsmul_sub_self (a b : α) : toIcoDiv hp a b • p - b = -toIcoMod hp a b := by
rw [toIcoMod, neg_sub]
@[simp]
theorem toIocDiv_zsmul_sub_self (a b : α) : toIocDiv hp a b • p - b = -toIocMod hp a b := by
rw [toIocMod, neg_sub]
@[simp]
theorem toIcoMod_sub_self (a b : α) : toIcoMod hp a b - b = -toIcoDiv hp a b • p := by
rw [toIcoMod, sub_sub_cancel_left, neg_smul]
@[simp]
theorem toIocMod_sub_self (a b : α) : toIocMod hp a b - b = -toIocDiv hp a b • p := by
rw [toIocMod, sub_sub_cancel_left, neg_smul]
@[simp]
theorem self_sub_toIcoMod (a b : α) : b - toIcoMod hp a b = toIcoDiv hp a b • p := by
rw [toIcoMod, sub_sub_cancel]
@[simp]
theorem self_sub_toIocMod (a b : α) : b - toIocMod hp a b = toIocDiv hp a b • p := by
rw [toIocMod, sub_sub_cancel]
@[simp]
theorem toIcoMod_add_toIcoDiv_zsmul (a b : α) : toIcoMod hp a b + toIcoDiv hp a b • p = b := by
rw [toIcoMod, sub_add_cancel]
@[simp]
theorem toIocMod_add_toIocDiv_zsmul (a b : α) : toIocMod hp a b + toIocDiv hp a b • p = b := by
rw [toIocMod, sub_add_cancel]
@[simp]
theorem toIcoDiv_zsmul_sub_toIcoMod (a b : α) : toIcoDiv hp a b • p + toIcoMod hp a b = b := by
rw [add_comm, toIcoMod_add_toIcoDiv_zsmul]
@[simp]
theorem toIocDiv_zsmul_sub_toIocMod (a b : α) : toIocDiv hp a b • p + toIocMod hp a b = b := by
rw [add_comm, toIocMod_add_toIocDiv_zsmul]
theorem toIcoMod_eq_iff : toIcoMod hp a b = c ↔ c ∈ Set.Ico a (a + p) ∧ ∃ z : ℤ, b = c + z • p := by
refine
⟨fun h =>
⟨h ▸ toIcoMod_mem_Ico hp a b, toIcoDiv hp a b, h ▸ (toIcoMod_add_toIcoDiv_zsmul _ _ _).symm⟩,
?_⟩
simp_rw [← @sub_eq_iff_eq_add]
rintro ⟨hc, n, rfl⟩
rw [← toIcoDiv_eq_of_sub_zsmul_mem_Ico hp hc, toIcoMod]
theorem toIocMod_eq_iff : toIocMod hp a b = c ↔ c ∈ Set.Ioc a (a + p) ∧ ∃ z : ℤ, b = c + z • p := by
refine
⟨fun h =>
⟨h ▸ toIocMod_mem_Ioc hp a b, toIocDiv hp a b, h ▸ (toIocMod_add_toIocDiv_zsmul hp _ _).symm⟩,
?_⟩
simp_rw [← @sub_eq_iff_eq_add]
rintro ⟨hc, n, rfl⟩
rw [← toIocDiv_eq_of_sub_zsmul_mem_Ioc hp hc, toIocMod]
@[simp]
theorem toIcoDiv_apply_left (a : α) : toIcoDiv hp a a = 0 :=
toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp]
@[simp]
theorem toIocDiv_apply_left (a : α) : toIocDiv hp a a = -1 :=
toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp]
@[simp]
theorem toIcoMod_apply_left (a : α) : toIcoMod hp a a = a := by
rw [toIcoMod_eq_iff hp, Set.left_mem_Ico]
exact ⟨lt_add_of_pos_right _ hp, 0, by simp⟩
@[simp]
theorem toIocMod_apply_left (a : α) : toIocMod hp a a = a + p := by
rw [toIocMod_eq_iff hp, Set.right_mem_Ioc]
exact ⟨lt_add_of_pos_right _ hp, -1, by simp⟩
theorem toIcoDiv_apply_right (a : α) : toIcoDiv hp a (a + p) = 1 :=
toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp]
theorem toIocDiv_apply_right (a : α) : toIocDiv hp a (a + p) = 0 :=
toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp]
theorem toIcoMod_apply_right (a : α) : toIcoMod hp a (a + p) = a := by
rw [toIcoMod_eq_iff hp, Set.left_mem_Ico]
exact ⟨lt_add_of_pos_right _ hp, 1, by simp⟩
theorem toIocMod_apply_right (a : α) : toIocMod hp a (a + p) = a + p := by
rw [toIocMod_eq_iff hp, Set.right_mem_Ioc]
exact ⟨lt_add_of_pos_right _ hp, 0, by simp⟩
@[simp]
theorem toIcoDiv_add_zsmul (a b : α) (m : ℤ) : toIcoDiv hp a (b + m • p) = toIcoDiv hp a b + m :=
toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by
simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIcoDiv_zsmul_mem_Ico hp a b
@[simp]
theorem toIcoDiv_add_zsmul' (a b : α) (m : ℤ) :
toIcoDiv hp (a + m • p) b = toIcoDiv hp a b - m := by
refine toIcoDiv_eq_of_sub_zsmul_mem_Ico _ ?_
rw [sub_smul, ← sub_add, add_right_comm]
simpa using sub_toIcoDiv_zsmul_mem_Ico hp a b
@[simp]
theorem toIocDiv_add_zsmul (a b : α) (m : ℤ) : toIocDiv hp a (b + m • p) = toIocDiv hp a b + m :=
toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by
simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIocDiv_zsmul_mem_Ioc hp a b
@[simp]
theorem toIocDiv_add_zsmul' (a b : α) (m : ℤ) :
toIocDiv hp (a + m • p) b = toIocDiv hp a b - m := by
refine toIocDiv_eq_of_sub_zsmul_mem_Ioc _ ?_
rw [sub_smul, ← sub_add, add_right_comm]
simpa using sub_toIocDiv_zsmul_mem_Ioc hp a b
@[simp]
theorem toIcoDiv_zsmul_add (a b : α) (m : ℤ) : toIcoDiv hp a (m • p + b) = m + toIcoDiv hp a b := by
rw [add_comm, toIcoDiv_add_zsmul, add_comm]
/-! Note we omit `toIcoDiv_zsmul_add'` as `-m + toIcoDiv hp a b` is not very convenient. -/
@[simp]
theorem toIocDiv_zsmul_add (a b : α) (m : ℤ) : toIocDiv hp a (m • p + b) = m + toIocDiv hp a b := by
rw [add_comm, toIocDiv_add_zsmul, add_comm]
/-! Note we omit `toIocDiv_zsmul_add'` as `-m + toIocDiv hp a b` is not very convenient. -/
@[simp]
theorem toIcoDiv_sub_zsmul (a b : α) (m : ℤ) : toIcoDiv hp a (b - m • p) = toIcoDiv hp a b - m := by
rw [sub_eq_add_neg, ← neg_smul, toIcoDiv_add_zsmul, sub_eq_add_neg]
@[simp]
theorem toIcoDiv_sub_zsmul' (a b : α) (m : ℤ) :
toIcoDiv hp (a - m • p) b = toIcoDiv hp a b + m := by
rw [sub_eq_add_neg, ← neg_smul, toIcoDiv_add_zsmul', sub_neg_eq_add]
@[simp]
theorem toIocDiv_sub_zsmul (a b : α) (m : ℤ) : toIocDiv hp a (b - m • p) = toIocDiv hp a b - m := by
rw [sub_eq_add_neg, ← neg_smul, toIocDiv_add_zsmul, sub_eq_add_neg]
@[simp]
theorem toIocDiv_sub_zsmul' (a b : α) (m : ℤ) :
toIocDiv hp (a - m • p) b = toIocDiv hp a b + m := by
rw [sub_eq_add_neg, ← neg_smul, toIocDiv_add_zsmul', sub_neg_eq_add]
@[simp]
theorem toIcoDiv_add_right (a b : α) : toIcoDiv hp a (b + p) = toIcoDiv hp a b + 1 := by
simpa only [one_zsmul] using toIcoDiv_add_zsmul hp a b 1
@[simp]
theorem toIcoDiv_add_right' (a b : α) : toIcoDiv hp (a + p) b = toIcoDiv hp a b - 1 := by
simpa only [one_zsmul] using toIcoDiv_add_zsmul' hp a b 1
@[simp]
theorem toIocDiv_add_right (a b : α) : toIocDiv hp a (b + p) = toIocDiv hp a b + 1 := by
simpa only [one_zsmul] using toIocDiv_add_zsmul hp a b 1
@[simp]
theorem toIocDiv_add_right' (a b : α) : toIocDiv hp (a + p) b = toIocDiv hp a b - 1 := by
simpa only [one_zsmul] using toIocDiv_add_zsmul' hp a b 1
@[simp]
theorem toIcoDiv_add_left (a b : α) : toIcoDiv hp a (p + b) = toIcoDiv hp a b + 1 := by
rw [add_comm, toIcoDiv_add_right]
@[simp]
theorem toIcoDiv_add_left' (a b : α) : toIcoDiv hp (p + a) b = toIcoDiv hp a b - 1 := by
rw [add_comm, toIcoDiv_add_right']
@[simp]
theorem toIocDiv_add_left (a b : α) : toIocDiv hp a (p + b) = toIocDiv hp a b + 1 := by
rw [add_comm, toIocDiv_add_right]
@[simp]
theorem toIocDiv_add_left' (a b : α) : toIocDiv hp (p + a) b = toIocDiv hp a b - 1 := by
rw [add_comm, toIocDiv_add_right']
@[simp]
theorem toIcoDiv_sub (a b : α) : toIcoDiv hp a (b - p) = toIcoDiv hp a b - 1 := by
simpa only [one_zsmul] using toIcoDiv_sub_zsmul hp a b 1
@[simp]
theorem toIcoDiv_sub' (a b : α) : toIcoDiv hp (a - p) b = toIcoDiv hp a b + 1 := by
simpa only [one_zsmul] using toIcoDiv_sub_zsmul' hp a b 1
@[simp]
theorem toIocDiv_sub (a b : α) : toIocDiv hp a (b - p) = toIocDiv hp a b - 1 := by
simpa only [one_zsmul] using toIocDiv_sub_zsmul hp a b 1
@[simp]
theorem toIocDiv_sub' (a b : α) : toIocDiv hp (a - p) b = toIocDiv hp a b + 1 := by
simpa only [one_zsmul] using toIocDiv_sub_zsmul' hp a b 1
theorem toIcoDiv_sub_eq_toIcoDiv_add (a b c : α) :
toIcoDiv hp a (b - c) = toIcoDiv hp (a + c) b := by
apply toIcoDiv_eq_of_sub_zsmul_mem_Ico
rw [← sub_right_comm, Set.sub_mem_Ico_iff_left, add_right_comm]
exact sub_toIcoDiv_zsmul_mem_Ico hp (a + c) b
theorem toIocDiv_sub_eq_toIocDiv_add (a b c : α) :
toIocDiv hp a (b - c) = toIocDiv hp (a + c) b := by
apply toIocDiv_eq_of_sub_zsmul_mem_Ioc
rw [← sub_right_comm, Set.sub_mem_Ioc_iff_left, add_right_comm]
exact sub_toIocDiv_zsmul_mem_Ioc hp (a + c) b
theorem toIcoDiv_sub_eq_toIcoDiv_add' (a b c : α) :
toIcoDiv hp (a - c) b = toIcoDiv hp a (b + c) := by
rw [← sub_neg_eq_add, toIcoDiv_sub_eq_toIcoDiv_add, sub_eq_add_neg]
theorem toIocDiv_sub_eq_toIocDiv_add' (a b c : α) :
toIocDiv hp (a - c) b = toIocDiv hp a (b + c) := by
rw [← sub_neg_eq_add, toIocDiv_sub_eq_toIocDiv_add, sub_eq_add_neg]
theorem toIcoDiv_neg (a b : α) : toIcoDiv hp a (-b) = -(toIocDiv hp (-a) b + 1) := by
suffices toIcoDiv hp a (-b) = -toIocDiv hp (-(a + p)) b by
rwa [neg_add, ← sub_eq_add_neg, toIocDiv_sub_eq_toIocDiv_add', toIocDiv_add_right] at this
rw [← neg_eq_iff_eq_neg, eq_comm]
apply toIocDiv_eq_of_sub_zsmul_mem_Ioc
obtain ⟨hc, ho⟩ := sub_toIcoDiv_zsmul_mem_Ico hp a (-b)
rw [← neg_lt_neg_iff, neg_sub' (-b), neg_neg, ← neg_smul] at ho
rw [← neg_le_neg_iff, neg_sub' (-b), neg_neg, ← neg_smul] at hc
refine ⟨ho, hc.trans_eq ?_⟩
rw [neg_add, neg_add_cancel_right]
theorem toIcoDiv_neg' (a b : α) : toIcoDiv hp (-a) b = -(toIocDiv hp a (-b) + 1) := by
simpa only [neg_neg] using toIcoDiv_neg hp (-a) (-b)
theorem toIocDiv_neg (a b : α) : toIocDiv hp a (-b) = -(toIcoDiv hp (-a) b + 1) := by
rw [← neg_neg b, toIcoDiv_neg, neg_neg, neg_neg, neg_add', neg_neg, add_sub_cancel_right]
theorem toIocDiv_neg' (a b : α) : toIocDiv hp (-a) b = -(toIcoDiv hp a (-b) + 1) := by
simpa only [neg_neg] using toIocDiv_neg hp (-a) (-b)
@[simp]
theorem toIcoMod_add_zsmul (a b : α) (m : ℤ) : toIcoMod hp a (b + m • p) = toIcoMod hp a b := by
rw [toIcoMod, toIcoDiv_add_zsmul, toIcoMod, add_smul]
abel
@[simp]
theorem toIcoMod_add_zsmul' (a b : α) (m : ℤ) :
toIcoMod hp (a + m • p) b = toIcoMod hp a b + m • p := by
simp only [toIcoMod, toIcoDiv_add_zsmul', sub_smul, sub_add]
@[simp]
theorem toIocMod_add_zsmul (a b : α) (m : ℤ) : toIocMod hp a (b + m • p) = toIocMod hp a b := by
rw [toIocMod, toIocDiv_add_zsmul, toIocMod, add_smul]
abel
@[simp]
theorem toIocMod_add_zsmul' (a b : α) (m : ℤ) :
toIocMod hp (a + m • p) b = toIocMod hp a b + m • p := by
simp only [toIocMod, toIocDiv_add_zsmul', sub_smul, sub_add]
@[simp]
theorem toIcoMod_zsmul_add (a b : α) (m : ℤ) : toIcoMod hp a (m • p + b) = toIcoMod hp a b := by
rw [add_comm, toIcoMod_add_zsmul]
@[simp]
theorem toIcoMod_zsmul_add' (a b : α) (m : ℤ) :
toIcoMod hp (m • p + a) b = m • p + toIcoMod hp a b := by
rw [add_comm, toIcoMod_add_zsmul', add_comm]
@[simp]
theorem toIocMod_zsmul_add (a b : α) (m : ℤ) : toIocMod hp a (m • p + b) = toIocMod hp a b := by
rw [add_comm, toIocMod_add_zsmul]
@[simp]
theorem toIocMod_zsmul_add' (a b : α) (m : ℤ) :
toIocMod hp (m • p + a) b = m • p + toIocMod hp a b := by
rw [add_comm, toIocMod_add_zsmul', add_comm]
@[simp]
theorem toIcoMod_sub_zsmul (a b : α) (m : ℤ) : toIcoMod hp a (b - m • p) = toIcoMod hp a b := by
rw [sub_eq_add_neg, ← neg_smul, toIcoMod_add_zsmul]
@[simp]
theorem toIcoMod_sub_zsmul' (a b : α) (m : ℤ) :
toIcoMod hp (a - m • p) b = toIcoMod hp a b - m • p := by
simp_rw [sub_eq_add_neg, ← neg_smul, toIcoMod_add_zsmul']
@[simp]
theorem toIocMod_sub_zsmul (a b : α) (m : ℤ) : toIocMod hp a (b - m • p) = toIocMod hp a b := by
rw [sub_eq_add_neg, ← neg_smul, toIocMod_add_zsmul]
@[simp]
theorem toIocMod_sub_zsmul' (a b : α) (m : ℤ) :
toIocMod hp (a - m • p) b = toIocMod hp a b - m • p := by
simp_rw [sub_eq_add_neg, ← neg_smul, toIocMod_add_zsmul']
@[simp]
theorem toIcoMod_add_right (a b : α) : toIcoMod hp a (b + p) = toIcoMod hp a b := by
simpa only [one_zsmul] using toIcoMod_add_zsmul hp a b 1
@[simp]
theorem toIcoMod_add_right' (a b : α) : toIcoMod hp (a + p) b = toIcoMod hp a b + p := by
simpa only [one_zsmul] using toIcoMod_add_zsmul' hp a b 1
@[simp]
theorem toIocMod_add_right (a b : α) : toIocMod hp a (b + p) = toIocMod hp a b := by
simpa only [one_zsmul] using toIocMod_add_zsmul hp a b 1
@[simp]
| Mathlib/Algebra/Order/ToIntervalMod.lean | 407 | 409 | theorem toIocMod_add_right' (a b : α) : toIocMod hp (a + p) b = toIocMod hp a b + p := by | simpa only [one_zsmul] using toIocMod_add_zsmul' hp a b 1 |
/-
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, Johan Commelin
-/
import Mathlib.Analysis.Analytic.Basic
import Mathlib.Combinatorics.Enumerative.Composition
/-!
# Composition of analytic functions
In this file we prove that the composition of analytic functions is analytic.
The argument is the following. Assume `g z = ∑' qₙ (z, ..., z)` and `f y = ∑' pₖ (y, ..., y)`. Then
`g (f y) = ∑' qₙ (∑' pₖ (y, ..., y), ..., ∑' pₖ (y, ..., y))
= ∑' qₙ (p_{i₁} (y, ..., y), ..., p_{iₙ} (y, ..., y))`.
For each `n` and `i₁, ..., iₙ`, define a `i₁ + ... + iₙ` multilinear function mapping
`(y₀, ..., y_{i₁ + ... + iₙ - 1})` to
`qₙ (p_{i₁} (y₀, ..., y_{i₁-1}), p_{i₂} (y_{i₁}, ..., y_{i₁ + i₂ - 1}), ..., p_{iₙ} (....)))`.
Then `g ∘ f` is obtained by summing all these multilinear functions.
To formalize this, we use compositions of an integer `N`, i.e., its decompositions into
a sum `i₁ + ... + iₙ` of positive integers. Given such a composition `c` and two formal
multilinear series `q` and `p`, let `q.compAlongComposition p c` be the above multilinear
function. Then the `N`-th coefficient in the power series expansion of `g ∘ f` is the sum of these
terms over all `c : Composition N`.
To complete the proof, we need to show that this power series has a positive radius of convergence.
This follows from the fact that `Composition N` has cardinality `2^(N-1)` and estimates on
the norm of `qₙ` and `pₖ`, which give summability. We also need to show that it indeed converges to
`g ∘ f`. For this, we note that the composition of partial sums converges to `g ∘ f`, and that it
corresponds to a part of the whole sum, on a subset that increases to the whole space. By
summability of the norms, this implies the overall convergence.
## Main results
* `q.comp p` is the formal composition of the formal multilinear series `q` and `p`.
* `HasFPowerSeriesAt.comp` states that if two functions `g` and `f` admit power series expansions
`q` and `p`, then `g ∘ f` admits a power series expansion given by `q.comp p`.
* `AnalyticAt.comp` states that the composition of analytic functions is analytic.
* `FormalMultilinearSeries.comp_assoc` states that composition is associative on formal
multilinear series.
## Implementation details
The main technical difficulty is to write down things. In particular, we need to define precisely
`q.compAlongComposition p c` and to show that it is indeed a continuous multilinear
function. This requires a whole interface built on the class `Composition`. Once this is set,
the main difficulty is to reorder the sums, writing the composition of the partial sums as a sum
over some subset of `Σ n, Composition n`. We need to check that the reordering is a bijection,
running over difficulties due to the dependent nature of the types under consideration, that are
controlled thanks to the interface for `Composition`.
The associativity of composition on formal multilinear series is a nontrivial result: it does not
follow from the associativity of composition of analytic functions, as there is no uniqueness for
the formal multilinear series representing a function (and also, it holds even when the radius of
convergence of the series is `0`). Instead, we give a direct proof, which amounts to reordering
double sums in a careful way. The change of variables is a canonical (combinatorial) bijection
`Composition.sigmaEquivSigmaPi` between `(Σ (a : Composition n), Composition a.length)` and
`(Σ (c : Composition n), Π (i : Fin c.length), Composition (c.blocksFun i))`, and is described
in more details below in the paragraph on associativity.
-/
noncomputable section
variable {𝕜 : Type*} {E F G H : Type*}
open Filter List
open scoped Topology NNReal ENNReal
section Topological
variable [CommRing 𝕜] [AddCommGroup E] [AddCommGroup F] [AddCommGroup G]
variable [Module 𝕜 E] [Module 𝕜 F] [Module 𝕜 G]
variable [TopologicalSpace E] [TopologicalSpace F] [TopologicalSpace G]
/-! ### Composing formal multilinear series -/
namespace FormalMultilinearSeries
variable [IsTopologicalAddGroup E] [ContinuousConstSMul 𝕜 E]
variable [IsTopologicalAddGroup F] [ContinuousConstSMul 𝕜 F]
variable [IsTopologicalAddGroup G] [ContinuousConstSMul 𝕜 G]
/-!
In this paragraph, we define the composition of formal multilinear series, by summing over all
possible compositions of `n`.
-/
/-- Given a formal multilinear series `p`, a composition `c` of `n` and the index `i` of a
block of `c`, we may define a function on `Fin n → E` by picking the variables in the `i`-th block
of `n`, and applying the corresponding coefficient of `p` to these variables. This function is
called `p.applyComposition c v i` for `v : Fin n → E` and `i : Fin c.length`. -/
def applyComposition (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (c : Composition n) :
(Fin n → E) → Fin c.length → F := fun v i => p (c.blocksFun i) (v ∘ c.embedding i)
theorem applyComposition_ones (p : FormalMultilinearSeries 𝕜 E F) (n : ℕ) :
p.applyComposition (Composition.ones n) = fun v i =>
p 1 fun _ => v (Fin.castLE (Composition.length_le _) i) := by
funext v i
apply p.congr (Composition.ones_blocksFun _ _)
intro j hjn hj1
obtain rfl : j = 0 := by omega
refine congr_arg v ?_
rw [Fin.ext_iff, Fin.coe_castLE, Composition.ones_embedding, Fin.val_mk]
theorem applyComposition_single (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (hn : 0 < n)
(v : Fin n → E) : p.applyComposition (Composition.single n hn) v = fun _j => p n v := by
ext j
refine p.congr (by simp) fun i hi1 hi2 => ?_
dsimp
congr 1
convert Composition.single_embedding hn ⟨i, hi2⟩ using 1
obtain ⟨j_val, j_property⟩ := j
have : j_val = 0 := le_bot_iff.1 (Nat.lt_succ_iff.1 j_property)
congr!
simp
@[simp]
theorem removeZero_applyComposition (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ}
(c : Composition n) : p.removeZero.applyComposition c = p.applyComposition c := by
ext v i
simp [applyComposition, zero_lt_one.trans_le (c.one_le_blocksFun i), removeZero_of_pos]
/-- Technical lemma stating how `p.applyComposition` commutes with updating variables. This
will be the key point to show that functions constructed from `applyComposition` retain
multilinearity. -/
theorem applyComposition_update (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (c : Composition n)
(j : Fin n) (v : Fin n → E) (z : E) :
p.applyComposition c (Function.update v j z) =
Function.update (p.applyComposition c v) (c.index j)
(p (c.blocksFun (c.index j))
(Function.update (v ∘ c.embedding (c.index j)) (c.invEmbedding j) z)) := by
ext k
by_cases h : k = c.index j
· rw [h]
let r : Fin (c.blocksFun (c.index j)) → Fin n := c.embedding (c.index j)
simp only [Function.update_self]
change p (c.blocksFun (c.index j)) (Function.update v j z ∘ r) = _
let j' := c.invEmbedding j
suffices B : Function.update v j z ∘ r = Function.update (v ∘ r) j' z by rw [B]
suffices C : Function.update v (r j') z ∘ r = Function.update (v ∘ r) j' z by
convert C; exact (c.embedding_comp_inv j).symm
exact Function.update_comp_eq_of_injective _ (c.embedding _).injective _ _
· simp only [h, Function.update_eq_self, Function.update_of_ne, Ne, not_false_iff]
let r : Fin (c.blocksFun k) → Fin n := c.embedding k
change p (c.blocksFun k) (Function.update v j z ∘ r) = p (c.blocksFun k) (v ∘ r)
suffices B : Function.update v j z ∘ r = v ∘ r by rw [B]
apply Function.update_comp_eq_of_not_mem_range
rwa [c.mem_range_embedding_iff']
@[simp]
theorem compContinuousLinearMap_applyComposition {n : ℕ} (p : FormalMultilinearSeries 𝕜 F G)
(f : E →L[𝕜] F) (c : Composition n) (v : Fin n → E) :
(p.compContinuousLinearMap f).applyComposition c v = p.applyComposition c (f ∘ v) := by
simp (config := {unfoldPartialApp := true}) [applyComposition]; rfl
end FormalMultilinearSeries
namespace ContinuousMultilinearMap
open FormalMultilinearSeries
variable [IsTopologicalAddGroup E] [ContinuousConstSMul 𝕜 E]
variable [IsTopologicalAddGroup F] [ContinuousConstSMul 𝕜 F]
/-- Given a formal multilinear series `p`, a composition `c` of `n` and a continuous multilinear
map `f` in `c.length` variables, one may form a continuous multilinear map in `n` variables by
applying the right coefficient of `p` to each block of the composition, and then applying `f` to
the resulting vector. It is called `f.compAlongComposition p c`. -/
def compAlongComposition {n : ℕ} (p : FormalMultilinearSeries 𝕜 E F) (c : Composition n)
(f : F [×c.length]→L[𝕜] G) : E [×n]→L[𝕜] G where
toMultilinearMap :=
MultilinearMap.mk' (fun v ↦ f (p.applyComposition c v))
(fun v i x y ↦ by simp only [applyComposition_update, map_update_add])
(fun v i c x ↦ by simp only [applyComposition_update, map_update_smul])
cont :=
f.cont.comp <|
continuous_pi fun _ => (coe_continuous _).comp <| continuous_pi fun _ => continuous_apply _
@[simp]
theorem compAlongComposition_apply {n : ℕ} (p : FormalMultilinearSeries 𝕜 E F) (c : Composition n)
(f : F [×c.length]→L[𝕜] G) (v : Fin n → E) :
(f.compAlongComposition p c) v = f (p.applyComposition c v) :=
rfl
end ContinuousMultilinearMap
namespace FormalMultilinearSeries
variable [IsTopologicalAddGroup E] [ContinuousConstSMul 𝕜 E]
variable [IsTopologicalAddGroup F] [ContinuousConstSMul 𝕜 F]
variable [IsTopologicalAddGroup G] [ContinuousConstSMul 𝕜 G]
/-- Given two formal multilinear series `q` and `p` and a composition `c` of `n`, one may
form a continuous multilinear map in `n` variables by applying the right coefficient of `p` to each
block of the composition, and then applying `q c.length` to the resulting vector. It is
called `q.compAlongComposition p c`. -/
def compAlongComposition {n : ℕ} (q : FormalMultilinearSeries 𝕜 F G)
(p : FormalMultilinearSeries 𝕜 E F) (c : Composition n) : (E [×n]→L[𝕜] G) :=
(q c.length).compAlongComposition p c
@[simp]
theorem compAlongComposition_apply {n : ℕ} (q : FormalMultilinearSeries 𝕜 F G)
(p : FormalMultilinearSeries 𝕜 E F) (c : Composition n) (v : Fin n → E) :
(q.compAlongComposition p c) v = q c.length (p.applyComposition c v) :=
rfl
/-- Formal composition of two formal multilinear series. The `n`-th coefficient in the composition
is defined to be the sum of `q.compAlongComposition p c` over all compositions of
`n`. In other words, this term (as a multilinear function applied to `v_0, ..., v_{n-1}`) is
`∑'_{k} ∑'_{i₁ + ... + iₖ = n} qₖ (p_{i_1} (...), ..., p_{i_k} (...))`, where one puts all variables
`v_0, ..., v_{n-1}` in increasing order in the dots.
In general, the composition `q ∘ p` only makes sense when the constant coefficient of `p` vanishes.
We give a general formula but which ignores the value of `p 0` instead.
-/
protected def comp (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) :
FormalMultilinearSeries 𝕜 E G := fun n => ∑ c : Composition n, q.compAlongComposition p c
/-- The `0`-th coefficient of `q.comp p` is `q 0`. Since these maps are multilinear maps in zero
variables, but on different spaces, we can not state this directly, so we state it when applied to
arbitrary vectors (which have to be the zero vector). -/
theorem comp_coeff_zero (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F)
(v : Fin 0 → E) (v' : Fin 0 → F) : (q.comp p) 0 v = q 0 v' := by
let c : Composition 0 := Composition.ones 0
dsimp [FormalMultilinearSeries.comp]
have : {c} = (Finset.univ : Finset (Composition 0)) := by
apply Finset.eq_of_subset_of_card_le <;> simp [Finset.card_univ, composition_card 0]
rw [← this, Finset.sum_singleton, compAlongComposition_apply]
symm; congr! -- Porting note: needed the stronger `congr!`!
@[simp]
theorem comp_coeff_zero' (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F)
(v : Fin 0 → E) : (q.comp p) 0 v = q 0 fun _i => 0 :=
q.comp_coeff_zero p v _
/-- The `0`-th coefficient of `q.comp p` is `q 0`. When `p` goes from `E` to `E`, this can be
expressed as a direct equality -/
theorem comp_coeff_zero'' (q : FormalMultilinearSeries 𝕜 E F) (p : FormalMultilinearSeries 𝕜 E E) :
(q.comp p) 0 = q 0 := by ext v; exact q.comp_coeff_zero p _ _
/-- The first coefficient of a composition of formal multilinear series is the composition of the
first coefficients seen as continuous linear maps. -/
theorem comp_coeff_one (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F)
(v : Fin 1 → E) : (q.comp p) 1 v = q 1 fun _i => p 1 v := by
have : {Composition.ones 1} = (Finset.univ : Finset (Composition 1)) :=
Finset.eq_univ_of_card _ (by simp [composition_card])
simp only [FormalMultilinearSeries.comp, compAlongComposition_apply, ← this,
Finset.sum_singleton]
refine q.congr (by simp) fun i hi1 hi2 => ?_
simp only [applyComposition_ones]
exact p.congr rfl fun j _hj1 hj2 => by congr! -- Porting note: needed the stronger `congr!`
/-- Only `0`-th coefficient of `q.comp p` depends on `q 0`. -/
theorem removeZero_comp_of_pos (q : FormalMultilinearSeries 𝕜 F G)
(p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (hn : 0 < n) :
q.removeZero.comp p n = q.comp p n := by
ext v
simp only [FormalMultilinearSeries.comp, compAlongComposition,
ContinuousMultilinearMap.compAlongComposition_apply, ContinuousMultilinearMap.sum_apply]
refine Finset.sum_congr rfl fun c _hc => ?_
rw [removeZero_of_pos _ (c.length_pos_of_pos hn)]
@[simp]
theorem comp_removeZero (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) :
q.comp p.removeZero = q.comp p := by ext n; simp [FormalMultilinearSeries.comp]
end FormalMultilinearSeries
end Topological
variable [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F]
[NormedSpace 𝕜 F] [NormedAddCommGroup G] [NormedSpace 𝕜 G] [NormedAddCommGroup H]
[NormedSpace 𝕜 H]
namespace FormalMultilinearSeries
/-- The norm of `f.compAlongComposition p c` is controlled by the product of
the norms of the relevant bits of `f` and `p`. -/
theorem compAlongComposition_bound {n : ℕ} (p : FormalMultilinearSeries 𝕜 E F) (c : Composition n)
(f : F [×c.length]→L[𝕜] G) (v : Fin n → E) :
‖f.compAlongComposition p c v‖ ≤ (‖f‖ * ∏ i, ‖p (c.blocksFun i)‖) * ∏ i : Fin n, ‖v i‖ :=
calc
‖f.compAlongComposition p c v‖ = ‖f (p.applyComposition c v)‖ := rfl
_ ≤ ‖f‖ * ∏ i, ‖p.applyComposition c v i‖ := ContinuousMultilinearMap.le_opNorm _ _
_ ≤ ‖f‖ * ∏ i, ‖p (c.blocksFun i)‖ * ∏ j : Fin (c.blocksFun i), ‖(v ∘ c.embedding i) j‖ := by
apply mul_le_mul_of_nonneg_left _ (norm_nonneg _)
refine Finset.prod_le_prod (fun i _hi => norm_nonneg _) fun i _hi => ?_
apply ContinuousMultilinearMap.le_opNorm
_ = (‖f‖ * ∏ i, ‖p (c.blocksFun i)‖) *
∏ i, ∏ j : Fin (c.blocksFun i), ‖(v ∘ c.embedding i) j‖ := by
rw [Finset.prod_mul_distrib, mul_assoc]
_ = (‖f‖ * ∏ i, ‖p (c.blocksFun i)‖) * ∏ i : Fin n, ‖v i‖ := by
rw [← c.blocksFinEquiv.prod_comp, ← Finset.univ_sigma_univ, Finset.prod_sigma]
congr
/-- The norm of `q.compAlongComposition p c` is controlled by the product of
the norms of the relevant bits of `q` and `p`. -/
theorem compAlongComposition_norm {n : ℕ} (q : FormalMultilinearSeries 𝕜 F G)
(p : FormalMultilinearSeries 𝕜 E F) (c : Composition n) :
‖q.compAlongComposition p c‖ ≤ ‖q c.length‖ * ∏ i, ‖p (c.blocksFun i)‖ :=
ContinuousMultilinearMap.opNorm_le_bound (by positivity) (compAlongComposition_bound _ _ _)
theorem compAlongComposition_nnnorm {n : ℕ} (q : FormalMultilinearSeries 𝕜 F G)
(p : FormalMultilinearSeries 𝕜 E F) (c : Composition n) :
‖q.compAlongComposition p c‖₊ ≤ ‖q c.length‖₊ * ∏ i, ‖p (c.blocksFun i)‖₊ := by
rw [← NNReal.coe_le_coe]; push_cast; exact q.compAlongComposition_norm p c
/-!
### The identity formal power series
We will now define the identity power series, and show that it is a neutral element for left and
right composition.
-/
section
variable (𝕜 E)
/-- The identity formal multilinear series, with all coefficients equal to `0` except for `n = 1`
where it is (the continuous multilinear version of) the identity. We allow an arbitrary
constant coefficient `x`. -/
def id (x : E) : FormalMultilinearSeries 𝕜 E E
| 0 => ContinuousMultilinearMap.uncurry0 𝕜 _ x
| 1 => (continuousMultilinearCurryFin1 𝕜 E E).symm (ContinuousLinearMap.id 𝕜 E)
| _ => 0
@[simp] theorem id_apply_zero (x : E) (v : Fin 0 → E) :
(FormalMultilinearSeries.id 𝕜 E x) 0 v = x := rfl
/-- The first coefficient of `id 𝕜 E` is the identity. -/
@[simp]
theorem id_apply_one (x : E) (v : Fin 1 → E) : (FormalMultilinearSeries.id 𝕜 E x) 1 v = v 0 :=
rfl
/-- The `n`th coefficient of `id 𝕜 E` is the identity when `n = 1`. We state this in a dependent
way, as it will often appear in this form. -/
theorem id_apply_one' (x : E) {n : ℕ} (h : n = 1) (v : Fin n → E) :
(id 𝕜 E x) n v = v ⟨0, h.symm ▸ zero_lt_one⟩ := by
subst n
apply id_apply_one
/-- For `n ≠ 1`, the `n`-th coefficient of `id 𝕜 E` is zero, by definition. -/
@[simp]
theorem id_apply_of_one_lt (x : E) {n : ℕ} (h : 1 < n) :
(FormalMultilinearSeries.id 𝕜 E x) n = 0 := by
match n with
| 0 => contradiction
| 1 => contradiction
| n + 2 => rfl
end
@[simp]
theorem comp_id (p : FormalMultilinearSeries 𝕜 E F) (x : E) : p.comp (id 𝕜 E x) = p := by
ext1 n
dsimp [FormalMultilinearSeries.comp]
rw [Finset.sum_eq_single (Composition.ones n)]
· show compAlongComposition p (id 𝕜 E x) (Composition.ones n) = p n
ext v
rw [compAlongComposition_apply]
apply p.congr (Composition.ones_length n)
intros
rw [applyComposition_ones]
refine congr_arg v ?_
rw [Fin.ext_iff, Fin.coe_castLE, Fin.val_mk]
· show
∀ b : Composition n,
b ∈ Finset.univ → b ≠ Composition.ones n → compAlongComposition p (id 𝕜 E x) b = 0
intro b _ hb
obtain ⟨k, hk, lt_k⟩ : ∃ (k : ℕ), k ∈ Composition.blocks b ∧ 1 < k :=
Composition.ne_ones_iff.1 hb
obtain ⟨i, hi⟩ : ∃ (i : Fin b.blocks.length), b.blocks[i] = k :=
List.get_of_mem hk
let j : Fin b.length := ⟨i.val, b.blocks_length ▸ i.prop⟩
have A : 1 < b.blocksFun j := by convert lt_k
ext v
rw [compAlongComposition_apply, ContinuousMultilinearMap.zero_apply]
apply ContinuousMultilinearMap.map_coord_zero _ j
dsimp [applyComposition]
rw [id_apply_of_one_lt _ _ _ A, ContinuousMultilinearMap.zero_apply]
· simp
@[simp]
theorem id_comp (p : FormalMultilinearSeries 𝕜 E F) (v0 : Fin 0 → E) :
(id 𝕜 F (p 0 v0)).comp p = p := by
ext1 n
obtain rfl | n_pos := n.eq_zero_or_pos
· ext v
simp only [comp_coeff_zero', id_apply_zero]
congr with i
exact i.elim0
· dsimp [FormalMultilinearSeries.comp]
rw [Finset.sum_eq_single (Composition.single n n_pos)]
· show compAlongComposition (id 𝕜 F (p 0 v0)) p (Composition.single n n_pos) = p n
ext v
rw [compAlongComposition_apply, id_apply_one' _ _ _ (Composition.single_length n_pos)]
dsimp [applyComposition]
refine p.congr rfl fun i him hin => congr_arg v <| ?_
ext; simp
· show
∀ b : Composition n, b ∈ Finset.univ → b ≠ Composition.single n n_pos →
compAlongComposition (id 𝕜 F (p 0 v0)) p b = 0
intro b _ hb
have A : 1 < b.length := by
have : b.length ≠ 1 := by simpa [Composition.eq_single_iff_length] using hb
have : 0 < b.length := Composition.length_pos_of_pos b n_pos
omega
ext v
rw [compAlongComposition_apply, id_apply_of_one_lt _ _ _ A,
ContinuousMultilinearMap.zero_apply, ContinuousMultilinearMap.zero_apply]
· simp
/-- Variant of `id_comp` in which the zero coefficient is given by an equality hypothesis instead
of a definitional equality. Useful for rewriting or simplifying out in some situations. -/
theorem id_comp' (p : FormalMultilinearSeries 𝕜 E F) (x : F) (v0 : Fin 0 → E) (h : x = p 0 v0) :
(id 𝕜 F x).comp p = p := by
simp [h]
/-! ### Summability properties of the composition of formal power series -/
section
/-- If two formal multilinear series have positive radius of convergence, then the terms appearing
in the definition of their composition are also summable (when multiplied by a suitable positive
geometric term). -/
theorem comp_summable_nnreal (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F)
(hq : 0 < q.radius) (hp : 0 < p.radius) :
∃ r > (0 : ℝ≥0),
Summable fun i : Σ n, Composition n => ‖q.compAlongComposition p i.2‖₊ * r ^ i.1 := by
/- This follows from the fact that the growth rate of `‖qₙ‖` and `‖pₙ‖` is at most geometric,
giving a geometric bound on each `‖q.compAlongComposition p op‖`, together with the
fact that there are `2^(n-1)` compositions of `n`, giving at most a geometric loss. -/
rcases ENNReal.lt_iff_exists_nnreal_btwn.1 (lt_min zero_lt_one hq) with ⟨rq, rq_pos, hrq⟩
rcases ENNReal.lt_iff_exists_nnreal_btwn.1 (lt_min zero_lt_one hp) with ⟨rp, rp_pos, hrp⟩
simp only [lt_min_iff, ENNReal.coe_lt_one_iff, ENNReal.coe_pos] at hrp hrq rp_pos rq_pos
obtain ⟨Cq, _hCq0, hCq⟩ : ∃ Cq > 0, ∀ n, ‖q n‖₊ * rq ^ n ≤ Cq :=
q.nnnorm_mul_pow_le_of_lt_radius hrq.2
obtain ⟨Cp, hCp1, hCp⟩ : ∃ Cp ≥ 1, ∀ n, ‖p n‖₊ * rp ^ n ≤ Cp := by
rcases p.nnnorm_mul_pow_le_of_lt_radius hrp.2 with ⟨Cp, -, hCp⟩
exact ⟨max Cp 1, le_max_right _ _, fun n => (hCp n).trans (le_max_left _ _)⟩
let r0 : ℝ≥0 := (4 * Cp)⁻¹
have r0_pos : 0 < r0 := inv_pos.2 (mul_pos zero_lt_four (zero_lt_one.trans_le hCp1))
set r : ℝ≥0 := rp * rq * r0
have r_pos : 0 < r := mul_pos (mul_pos rp_pos rq_pos) r0_pos
have I :
∀ i : Σ n : ℕ, Composition n, ‖q.compAlongComposition p i.2‖₊ * r ^ i.1 ≤ Cq / 4 ^ i.1 := by
rintro ⟨n, c⟩
have A := calc
‖q c.length‖₊ * rq ^ n ≤ ‖q c.length‖₊ * rq ^ c.length :=
mul_le_mul' le_rfl (pow_le_pow_of_le_one rq.2 hrq.1.le c.length_le)
_ ≤ Cq := hCq _
have B := calc
(∏ i, ‖p (c.blocksFun i)‖₊) * rp ^ n = ∏ i, ‖p (c.blocksFun i)‖₊ * rp ^ c.blocksFun i := by
simp only [Finset.prod_mul_distrib, Finset.prod_pow_eq_pow_sum, c.sum_blocksFun]
_ ≤ ∏ _i : Fin c.length, Cp := Finset.prod_le_prod' fun i _ => hCp _
_ = Cp ^ c.length := by simp
_ ≤ Cp ^ n := pow_right_mono₀ hCp1 c.length_le
calc
‖q.compAlongComposition p c‖₊ * r ^ n ≤
(‖q c.length‖₊ * ∏ i, ‖p (c.blocksFun i)‖₊) * r ^ n :=
mul_le_mul' (q.compAlongComposition_nnnorm p c) le_rfl
_ = ‖q c.length‖₊ * rq ^ n * ((∏ i, ‖p (c.blocksFun i)‖₊) * rp ^ n) * r0 ^ n := by
ring
_ ≤ Cq * Cp ^ n * r0 ^ n := mul_le_mul' (mul_le_mul' A B) le_rfl
_ = Cq / 4 ^ n := by
simp only [r0]
field_simp [mul_pow, (zero_lt_one.trans_le hCp1).ne']
ring
refine ⟨r, r_pos, NNReal.summable_of_le I ?_⟩
simp_rw [div_eq_mul_inv]
refine Summable.mul_left _ ?_
have : ∀ n : ℕ, HasSum (fun c : Composition n => (4 ^ n : ℝ≥0)⁻¹) (2 ^ (n - 1) / 4 ^ n) := by
intro n
convert hasSum_fintype fun c : Composition n => (4 ^ n : ℝ≥0)⁻¹
simp [Finset.card_univ, composition_card, div_eq_mul_inv]
refine NNReal.summable_sigma.2 ⟨fun n => (this n).summable, (NNReal.summable_nat_add_iff 1).1 ?_⟩
convert (NNReal.summable_geometric (NNReal.div_lt_one_of_lt one_lt_two)).mul_left (1 / 4) using 1
ext1 n
rw [(this _).tsum_eq, add_tsub_cancel_right]
field_simp [← mul_assoc, pow_succ, mul_pow, show (4 : ℝ≥0) = 2 * 2 by norm_num,
mul_right_comm]
end
/-- Bounding below the radius of the composition of two formal multilinear series assuming
summability over all compositions. -/
theorem le_comp_radius_of_summable (q : FormalMultilinearSeries 𝕜 F G)
(p : FormalMultilinearSeries 𝕜 E F) (r : ℝ≥0)
(hr : Summable fun i : Σ n, Composition n => ‖q.compAlongComposition p i.2‖₊ * r ^ i.1) :
(r : ℝ≥0∞) ≤ (q.comp p).radius := by
refine
le_radius_of_bound_nnreal _
(∑' i : Σ n, Composition n, ‖compAlongComposition q p i.snd‖₊ * r ^ i.fst) fun n => ?_
calc
‖FormalMultilinearSeries.comp q p n‖₊ * r ^ n ≤
∑' c : Composition n, ‖compAlongComposition q p c‖₊ * r ^ n := by
rw [tsum_fintype, ← Finset.sum_mul]
exact mul_le_mul' (nnnorm_sum_le _ _) le_rfl
_ ≤ ∑' i : Σ n : ℕ, Composition n, ‖compAlongComposition q p i.snd‖₊ * r ^ i.fst :=
NNReal.tsum_comp_le_tsum_of_inj hr sigma_mk_injective
/-!
### Composing analytic functions
Now, we will prove that the composition of the partial sums of `q` and `p` up to order `N` is
given by a sum over some large subset of `Σ n, Composition n` of `q.compAlongComposition p`, to
deduce that the series for `q.comp p` indeed converges to `g ∘ f` when `q` is a power series for
`g` and `p` is a power series for `f`.
This proof is a big reindexing argument of a sum. Since it is a bit involved, we define first
the source of the change of variables (`compPartialSumSource`), its target
(`compPartialSumTarget`) and the change of variables itself (`compChangeOfVariables`) before
giving the main statement in `comp_partialSum`. -/
/-- Source set in the change of variables to compute the composition of partial sums of formal
power series.
See also `comp_partialSum`. -/
def compPartialSumSource (m M N : ℕ) : Finset (Σ n, Fin n → ℕ) :=
Finset.sigma (Finset.Ico m M) (fun n : ℕ => Fintype.piFinset fun _i : Fin n => Finset.Ico 1 N :)
@[simp]
theorem mem_compPartialSumSource_iff (m M N : ℕ) (i : Σ n, Fin n → ℕ) :
i ∈ compPartialSumSource m M N ↔
(m ≤ i.1 ∧ i.1 < M) ∧ ∀ a : Fin i.1, 1 ≤ i.2 a ∧ i.2 a < N := by
simp only [compPartialSumSource, Finset.mem_Ico, Fintype.mem_piFinset, Finset.mem_sigma]
/-- Change of variables appearing to compute the composition of partial sums of formal
power series -/
def compChangeOfVariables (m M N : ℕ) (i : Σ n, Fin n → ℕ) (hi : i ∈ compPartialSumSource m M N) :
Σ n, Composition n := by
rcases i with ⟨n, f⟩
rw [mem_compPartialSumSource_iff] at hi
refine ⟨∑ j, f j, ofFn fun a => f a, fun {i} hi' => ?_, by simp [sum_ofFn]⟩
obtain ⟨j, rfl⟩ : ∃ j : Fin n, f j = i := by rwa [mem_ofFn', Set.mem_range] at hi'
exact (hi.2 j).1
@[simp]
theorem compChangeOfVariables_length (m M N : ℕ) {i : Σ n, Fin n → ℕ}
(hi : i ∈ compPartialSumSource m M N) :
Composition.length (compChangeOfVariables m M N i hi).2 = i.1 := by
rcases i with ⟨k, blocks_fun⟩
dsimp [compChangeOfVariables]
simp only [Composition.length, map_ofFn, length_ofFn]
theorem compChangeOfVariables_blocksFun (m M N : ℕ) {i : Σ n, Fin n → ℕ}
(hi : i ∈ compPartialSumSource m M N) (j : Fin i.1) :
(compChangeOfVariables m M N i hi).2.blocksFun
⟨j, (compChangeOfVariables_length m M N hi).symm ▸ j.2⟩ =
i.2 j := by
rcases i with ⟨n, f⟩
dsimp [Composition.blocksFun, Composition.blocks, compChangeOfVariables]
simp only [map_ofFn, List.getElem_ofFn, Function.comp_apply]
/-- Target set in the change of variables to compute the composition of partial sums of formal
power series, here given a a set. -/
def compPartialSumTargetSet (m M N : ℕ) : Set (Σ n, Composition n) :=
{i | m ≤ i.2.length ∧ i.2.length < M ∧ ∀ j : Fin i.2.length, i.2.blocksFun j < N}
theorem compPartialSumTargetSet_image_compPartialSumSource (m M N : ℕ)
(i : Σ n, Composition n) (hi : i ∈ compPartialSumTargetSet m M N) :
∃ (j : _) (hj : j ∈ compPartialSumSource m M N), compChangeOfVariables m M N j hj = i := by
rcases i with ⟨n, c⟩
refine ⟨⟨c.length, c.blocksFun⟩, ?_, ?_⟩
· simp only [compPartialSumTargetSet, Set.mem_setOf_eq] at hi
simp only [mem_compPartialSumSource_iff, hi.left, hi.right, true_and, and_true]
exact fun a => c.one_le_blocks' _
· dsimp [compChangeOfVariables]
rw [Composition.sigma_eq_iff_blocks_eq]
simp only [Composition.blocksFun, Composition.blocks, Subtype.coe_eta]
conv_rhs => rw [← List.ofFn_get c.blocks]
/-- Target set in the change of variables to compute the composition of partial sums of formal
power series, here given a a finset.
See also `comp_partialSum`. -/
def compPartialSumTarget (m M N : ℕ) : Finset (Σ n, Composition n) :=
Set.Finite.toFinset <|
((Finset.finite_toSet _).dependent_image _).subset <|
compPartialSumTargetSet_image_compPartialSumSource m M N
@[simp]
theorem mem_compPartialSumTarget_iff {m M N : ℕ} {a : Σ n, Composition n} :
a ∈ compPartialSumTarget m M N ↔
m ≤ a.2.length ∧ a.2.length < M ∧ ∀ j : Fin a.2.length, a.2.blocksFun j < N := by
simp [compPartialSumTarget, compPartialSumTargetSet]
/-- `compChangeOfVariables m M N` is a bijection between `compPartialSumSource m M N`
and `compPartialSumTarget m M N`, yielding equal sums for functions that correspond to each
other under the bijection. As `compChangeOfVariables m M N` is a dependent function, stating
that it is a bijection is not directly possible, but the consequence on sums can be stated
more easily. -/
theorem compChangeOfVariables_sum {α : Type*} [AddCommMonoid α] (m M N : ℕ)
(f : (Σ n : ℕ, Fin n → ℕ) → α) (g : (Σ n, Composition n) → α)
(h : ∀ (e) (he : e ∈ compPartialSumSource m M N), f e = g (compChangeOfVariables m M N e he)) :
∑ e ∈ compPartialSumSource m M N, f e = ∑ e ∈ compPartialSumTarget m M N, g e := by
apply Finset.sum_bij (compChangeOfVariables m M N)
-- We should show that the correspondence we have set up is indeed a bijection
-- between the index sets of the two sums.
-- 1 - show that the image belongs to `compPartialSumTarget m N N`
· rintro ⟨k, blocks_fun⟩ H
rw [mem_compPartialSumSource_iff] at H
simp only [mem_compPartialSumTarget_iff, Composition.length, Composition.blocks, H.left,
map_ofFn, length_ofFn, true_and, compChangeOfVariables]
intro j
simp only [Composition.blocksFun, (H.right _).right, List.get_ofFn]
-- 2 - show that the map is injective
· rintro ⟨k, blocks_fun⟩ H ⟨k', blocks_fun'⟩ H' heq
obtain rfl : k = k' := by
have := (compChangeOfVariables_length m M N H).symm
rwa [heq, compChangeOfVariables_length] at this
congr
funext i
calc
blocks_fun i = (compChangeOfVariables m M N _ H).2.blocksFun _ :=
(compChangeOfVariables_blocksFun m M N H i).symm
_ = (compChangeOfVariables m M N _ H').2.blocksFun _ := by
apply Composition.blocksFun_congr <;>
first | rw [heq] | rfl
_ = blocks_fun' i := compChangeOfVariables_blocksFun m M N H' i
-- 3 - show that the map is surjective
· intro i hi
apply compPartialSumTargetSet_image_compPartialSumSource m M N i
simpa [compPartialSumTarget] using hi
-- 4 - show that the composition gives the `compAlongComposition` application
· rintro ⟨k, blocks_fun⟩ H
rw [h]
/-- The auxiliary set corresponding to the composition of partial sums asymptotically contains
all possible compositions. -/
theorem compPartialSumTarget_tendsto_prod_atTop :
Tendsto (fun (p : ℕ × ℕ) => compPartialSumTarget 0 p.1 p.2) atTop atTop := by
apply Monotone.tendsto_atTop_finset
· intro m n hmn a ha
have : ∀ i, i < m.1 → i < n.1 := fun i hi => lt_of_lt_of_le hi hmn.1
have : ∀ i, i < m.2 → i < n.2 := fun i hi => lt_of_lt_of_le hi hmn.2
aesop
· rintro ⟨n, c⟩
simp only [mem_compPartialSumTarget_iff]
obtain ⟨n, hn⟩ : BddAbove ((Finset.univ.image fun i : Fin c.length => c.blocksFun i) : Set ℕ) :=
Finset.bddAbove _
refine
⟨max n c.length + 1, bot_le, lt_of_le_of_lt (le_max_right n c.length) (lt_add_one _), fun j =>
lt_of_le_of_lt (le_trans ?_ (le_max_left _ _)) (lt_add_one _)⟩
apply hn
simp only [Finset.mem_image_of_mem, Finset.mem_coe, Finset.mem_univ]
/-- The auxiliary set corresponding to the composition of partial sums asymptotically contains
all possible compositions. -/
theorem compPartialSumTarget_tendsto_atTop :
Tendsto (fun N => compPartialSumTarget 0 N N) atTop atTop := by
apply Tendsto.comp compPartialSumTarget_tendsto_prod_atTop tendsto_atTop_diagonal
/-- Composing the partial sums of two multilinear series coincides with the sum over all
compositions in `compPartialSumTarget 0 N N`. This is precisely the motivation for the
definition of `compPartialSumTarget`. -/
theorem comp_partialSum (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F)
(M N : ℕ) (z : E) :
q.partialSum M (∑ i ∈ Finset.Ico 1 N, p i fun _j => z) =
∑ i ∈ compPartialSumTarget 0 M N, q.compAlongComposition p i.2 fun _j => z := by
-- we expand the composition, using the multilinearity of `q` to expand along each coordinate.
suffices H :
(∑ n ∈ Finset.range M,
∑ r ∈ Fintype.piFinset fun i : Fin n => Finset.Ico 1 N,
q n fun i : Fin n => p (r i) fun _j => z) =
∑ i ∈ compPartialSumTarget 0 M N, q.compAlongComposition p i.2 fun _j => z by
simpa only [FormalMultilinearSeries.partialSum, ContinuousMultilinearMap.map_sum_finset] using H
-- rewrite the first sum as a big sum over a sigma type, in the finset
-- `compPartialSumTarget 0 N N`
rw [Finset.range_eq_Ico, Finset.sum_sigma']
-- use `compChangeOfVariables_sum`, saying that this change of variables respects sums
apply compChangeOfVariables_sum 0 M N
rintro ⟨k, blocks_fun⟩ H
apply congr _ (compChangeOfVariables_length 0 M N H).symm
intros
rw [← compChangeOfVariables_blocksFun 0 M N H, applyComposition, Function.comp_def]
end FormalMultilinearSeries
open FormalMultilinearSeries
/-- If two functions `g` and `f` have power series `q` and `p` respectively at `f x` and `x`, within
two sets `s` and `t` such that `f` maps `s` to `t`, then `g ∘ f` admits the power
series `q.comp p` at `x` within `s`. -/
theorem HasFPowerSeriesWithinAt.comp {g : F → G} {f : E → F} {q : FormalMultilinearSeries 𝕜 F G}
{p : FormalMultilinearSeries 𝕜 E F} {x : E} {t : Set F} {s : Set E}
(hg : HasFPowerSeriesWithinAt g q t (f x)) (hf : HasFPowerSeriesWithinAt f p s x)
(hs : Set.MapsTo f s t) : HasFPowerSeriesWithinAt (g ∘ f) (q.comp p) s x := by
/- Consider `rf` and `rg` such that `f` and `g` have power series expansion on the disks
of radius `rf` and `rg`. -/
rcases hg with ⟨rg, Hg⟩
rcases hf with ⟨rf, Hf⟩
-- The terms defining `q.comp p` are geometrically summable in a disk of some radius `r`.
rcases q.comp_summable_nnreal p Hg.radius_pos Hf.radius_pos with ⟨r, r_pos : 0 < r, hr⟩
/- We will consider `y` which is smaller than `r` and `rf`, and also small enough that
`f (x + y)` is close enough to `f x` to be in the disk where `g` is well behaved. Let
`min (r, rf, δ)` be this new radius. -/
obtain ⟨δ, δpos, hδ⟩ :
∃ δ : ℝ≥0∞, 0 < δ ∧ ∀ {z : E}, z ∈ insert x s ∩ EMetric.ball x δ
→ f z ∈ insert (f x) t ∩ EMetric.ball (f x) rg := by
have : insert (f x) t ∩ EMetric.ball (f x) rg ∈ 𝓝[insert (f x) t] (f x) := by
apply inter_mem_nhdsWithin
exact EMetric.ball_mem_nhds _ Hg.r_pos
have := Hf.analyticWithinAt.continuousWithinAt_insert.tendsto_nhdsWithin (hs.insert x) this
rcases EMetric.mem_nhdsWithin_iff.1 this with ⟨δ, δpos, Hδ⟩
exact ⟨δ, δpos, fun {z} hz => Hδ (by rwa [Set.inter_comm])⟩
let rf' := min rf δ
have min_pos : 0 < min rf' r := by
simp only [rf', r_pos, Hf.r_pos, δpos, lt_min_iff, ENNReal.coe_pos, and_self_iff]
/- We will show that `g ∘ f` admits the power series `q.comp p` in the disk of
radius `min (r, rf', δ)`. -/
refine ⟨min rf' r, ?_⟩
refine
⟨le_trans (min_le_right rf' r) (FormalMultilinearSeries.le_comp_radius_of_summable q p r hr),
min_pos, fun {y} h'y hy ↦ ?_⟩
/- Let `y` satisfy `‖y‖ < min (r, rf', δ)`. We want to show that `g (f (x + y))` is the sum of
`q.comp p` applied to `y`. -/
-- First, check that `y` is small enough so that estimates for `f` and `g` apply.
have y_mem : y ∈ EMetric.ball (0 : E) rf :=
(EMetric.ball_subset_ball (le_trans (min_le_left _ _) (min_le_left _ _))) hy
have fy_mem : f (x + y) ∈ insert (f x) t ∩ EMetric.ball (f x) rg := by
apply hδ
have : y ∈ EMetric.ball (0 : E) δ :=
(EMetric.ball_subset_ball (le_trans (min_le_left _ _) (min_le_right _ _))) hy
simpa [-Set.mem_insert_iff, edist_eq_enorm_sub, h'y]
/- Now the proof starts. To show that the sum of `q.comp p` at `y` is `g (f (x + y))`,
we will write `q.comp p` applied to `y` as a big sum over all compositions.
Since the sum is summable, to get its convergence it suffices to get
the convergence along some increasing sequence of sets.
We will use the sequence of sets `compPartialSumTarget 0 n n`,
along which the sum is exactly the composition of the partial sums of `q` and `p`, by design.
To show that it converges to `g (f (x + y))`, pointwise convergence would not be enough,
but we have uniform convergence to save the day. -/
-- First step: the partial sum of `p` converges to `f (x + y)`.
have A : Tendsto (fun n ↦ (n, ∑ a ∈ Finset.Ico 1 n, p a fun _ ↦ y))
atTop (atTop ×ˢ 𝓝 (f (x + y) - f x)) := by
apply Tendsto.prodMk tendsto_id
have L : ∀ᶠ n in atTop, (∑ a ∈ Finset.range n, p a fun _b ↦ y) - f x
= ∑ a ∈ Finset.Ico 1 n, p a fun _b ↦ y := by
rw [eventually_atTop]
refine ⟨1, fun n hn => ?_⟩
symm
rw [eq_sub_iff_add_eq', Finset.range_eq_Ico, ← Hf.coeff_zero fun _i => y,
Finset.sum_eq_sum_Ico_succ_bot hn]
have :
Tendsto (fun n => (∑ a ∈ Finset.range n, p a fun _b => y) - f x) atTop
(𝓝 (f (x + y) - f x)) :=
(Hf.hasSum h'y y_mem).tendsto_sum_nat.sub tendsto_const_nhds
exact Tendsto.congr' L this
-- Second step: the composition of the partial sums of `q` and `p` converges to `g (f (x + y))`.
have B : Tendsto (fun n => q.partialSum n (∑ a ∈ Finset.Ico 1 n, p a fun _b ↦ y)) atTop
(𝓝 (g (f (x + y)))) := by
-- we use the fact that the partial sums of `q` converge to `g (f (x + y))`, uniformly on a
-- neighborhood of `f (x + y)`.
have : Tendsto (fun (z : ℕ × F) ↦ q.partialSum z.1 z.2)
(atTop ×ˢ 𝓝 (f (x + y) - f x)) (𝓝 (g (f x + (f (x + y) - f x)))) := by
apply Hg.tendsto_partialSum_prod (y := f (x + y) - f x)
· simpa [edist_eq_enorm_sub] using fy_mem.2
· simpa using fy_mem.1
simpa using this.comp A
-- Third step: the sum over all compositions in `compPartialSumTarget 0 n n` converges to
-- `g (f (x + y))`. As this sum is exactly the composition of the partial sum, this is a direct
-- consequence of the second step
have C :
Tendsto
(fun n => ∑ i ∈ compPartialSumTarget 0 n n, q.compAlongComposition p i.2 fun _j => y)
atTop (𝓝 (g (f (x + y)))) := by
simpa [comp_partialSum] using B
-- Fourth step: the sum over all compositions is `g (f (x + y))`. This follows from the
-- convergence along a subsequence proved in the third step, and the fact that the sum is Cauchy
-- thanks to the summability properties.
have D :
HasSum (fun i : Σ n, Composition n => q.compAlongComposition p i.2 fun _j => y)
(g (f (x + y))) :=
haveI cau :
CauchySeq fun s : Finset (Σ n, Composition n) =>
∑ i ∈ s, q.compAlongComposition p i.2 fun _j => y := by
apply cauchySeq_finset_of_norm_bounded _ (NNReal.summable_coe.2 hr) _
simp only [coe_nnnorm, NNReal.coe_mul, NNReal.coe_pow]
rintro ⟨n, c⟩
calc
‖(compAlongComposition q p c) fun _j : Fin n => y‖ ≤
‖compAlongComposition q p c‖ * ∏ _j : Fin n, ‖y‖ := by
apply ContinuousMultilinearMap.le_opNorm
_ ≤ ‖compAlongComposition q p c‖ * (r : ℝ) ^ n := by
rw [Finset.prod_const, Finset.card_fin]
gcongr
rw [EMetric.mem_ball, edist_zero_eq_enorm] at hy
have := le_trans (le_of_lt hy) (min_le_right _ _)
rwa [enorm_le_coe, ← NNReal.coe_le_coe, coe_nnnorm] at this
tendsto_nhds_of_cauchySeq_of_subseq cau compPartialSumTarget_tendsto_atTop C
-- Fifth step: the sum over `n` of `q.comp p n` can be expressed as a particular resummation of
-- the sum over all compositions, by grouping together the compositions of the same
-- integer `n`. The convergence of the whole sum therefore implies the converence of the sum
-- of `q.comp p n`
have E : HasSum (fun n => (q.comp p) n fun _j => y) (g (f (x + y))) := by
apply D.sigma
intro n
simp only [compAlongComposition_apply, FormalMultilinearSeries.comp,
ContinuousMultilinearMap.sum_apply]
exact hasSum_fintype _
rw [Function.comp_apply]
exact E
/-- If two functions `g` and `f` have power series `q` and `p` respectively at `f x` and `x`,
then `g ∘ f` admits the power series `q.comp p` at `x` within `s`. -/
theorem HasFPowerSeriesAt.comp {g : F → G} {f : E → F} {q : FormalMultilinearSeries 𝕜 F G}
{p : FormalMultilinearSeries 𝕜 E F} {x : E}
(hg : HasFPowerSeriesAt g q (f x)) (hf : HasFPowerSeriesAt f p x) :
HasFPowerSeriesAt (g ∘ f) (q.comp p) x := by
rw [← hasFPowerSeriesWithinAt_univ] at hf hg ⊢
apply hg.comp hf (by simp)
/-- If two functions `g` and `f` are analytic respectively at `f x` and `x`, within
two sets `s` and `t` such that `f` maps `s` to `t`, then `g ∘ f` is analytic at `x` within `s`. -/
theorem AnalyticWithinAt.comp {g : F → G} {f : E → F} {x : E} {t : Set F} {s : Set E}
(hg : AnalyticWithinAt 𝕜 g t (f x)) (hf : AnalyticWithinAt 𝕜 f s x) (h : Set.MapsTo f s t) :
AnalyticWithinAt 𝕜 (g ∘ f) s x := by
let ⟨_q, hq⟩ := hg
let ⟨_p, hp⟩ := hf
exact (hq.comp hp h).analyticWithinAt
/-- Version of `AnalyticWithinAt.comp` where point equality is a separate hypothesis. -/
theorem AnalyticWithinAt.comp_of_eq {g : F → G} {f : E → F} {y : F} {x : E} {t : Set F} {s : Set E}
(hg : AnalyticWithinAt 𝕜 g t y) (hf : AnalyticWithinAt 𝕜 f s x) (h : Set.MapsTo f s t)
(hy : f x = y) :
AnalyticWithinAt 𝕜 (g ∘ f) s x := by
rw [← hy] at hg
exact hg.comp hf h
lemma AnalyticOn.comp {f : F → G} {g : E → F} {s : Set F}
{t : Set E} (hf : AnalyticOn 𝕜 f s) (hg : AnalyticOn 𝕜 g t) (h : Set.MapsTo g t s) :
AnalyticOn 𝕜 (f ∘ g) t :=
fun x m ↦ (hf _ (h m)).comp (hg x m) h
/-- If two functions `g` and `f` are analytic respectively at `f x` and `x`, then `g ∘ f` is
analytic at `x`. -/
@[fun_prop]
theorem AnalyticAt.comp {g : F → G} {f : E → F} {x : E} (hg : AnalyticAt 𝕜 g (f x))
(hf : AnalyticAt 𝕜 f x) : AnalyticAt 𝕜 (g ∘ f) x := by
rw [← analyticWithinAt_univ] at hg hf ⊢
apply hg.comp hf (by simp)
/-- If two functions `g` and `f` are analytic respectively at `f x` and `x`, then `g ∘ f` is
analytic at `x`. -/
@[fun_prop]
theorem AnalyticAt.comp' {g : F → G} {f : E → F} {x : E} (hg : AnalyticAt 𝕜 g (f x))
(hf : AnalyticAt 𝕜 f x) : AnalyticAt 𝕜 (fun z ↦ g (f z)) x :=
hg.comp hf
/-- Version of `AnalyticAt.comp` where point equality is a separate hypothesis. -/
theorem AnalyticAt.comp_of_eq {g : F → G} {f : E → F} {y : F} {x : E} (hg : AnalyticAt 𝕜 g y)
(hf : AnalyticAt 𝕜 f x) (hy : f x = y) : AnalyticAt 𝕜 (g ∘ f) x := by
rw [← hy] at hg
exact hg.comp hf
/-- Version of `AnalyticAt.comp` where point equality is a separate hypothesis. -/
theorem AnalyticAt.comp_of_eq' {g : F → G} {f : E → F} {y : F} {x : E} (hg : AnalyticAt 𝕜 g y)
(hf : AnalyticAt 𝕜 f x) (hy : f x = y) : AnalyticAt 𝕜 (fun z ↦ g (f z)) x := by
apply hg.comp_of_eq hf hy
theorem AnalyticAt.comp_analyticWithinAt {g : F → G} {f : E → F} {x : E} {s : Set E}
(hg : AnalyticAt 𝕜 g (f x)) (hf : AnalyticWithinAt 𝕜 f s x) :
AnalyticWithinAt 𝕜 (g ∘ f) s x := by
rw [← analyticWithinAt_univ] at hg
exact hg.comp hf (Set.mapsTo_univ _ _)
theorem AnalyticAt.comp_analyticWithinAt_of_eq {g : F → G} {f : E → F} {x : E} {y : F} {s : Set E}
(hg : AnalyticAt 𝕜 g y) (hf : AnalyticWithinAt 𝕜 f s x) (h : f x = y) :
AnalyticWithinAt 𝕜 (g ∘ f) s x := by
rw [← h] at hg
exact hg.comp_analyticWithinAt hf
/-- If two functions `g` and `f` are analytic respectively on `s.image f` and `s`, then `g ∘ f` is
analytic on `s`. -/
theorem AnalyticOnNhd.comp' {s : Set E} {g : F → G} {f : E → F} (hg : AnalyticOnNhd 𝕜 g (s.image f))
(hf : AnalyticOnNhd 𝕜 f s) : AnalyticOnNhd 𝕜 (g ∘ f) s :=
fun z hz => (hg (f z) (Set.mem_image_of_mem f hz)).comp (hf z hz)
theorem AnalyticOnNhd.comp {s : Set E} {t : Set F} {g : F → G} {f : E → F}
(hg : AnalyticOnNhd 𝕜 g t) (hf : AnalyticOnNhd 𝕜 f s) (st : Set.MapsTo f s t) :
AnalyticOnNhd 𝕜 (g ∘ f) s :=
comp' (mono hg (Set.mapsTo'.mp st)) hf
lemma AnalyticOnNhd.comp_analyticOn {f : F → G} {g : E → F} {s : Set F}
{t : Set E} (hf : AnalyticOnNhd 𝕜 f s) (hg : AnalyticOn 𝕜 g t) (h : Set.MapsTo g t s) :
AnalyticOn 𝕜 (f ∘ g) t :=
fun x m ↦ (hf _ (h m)).comp_analyticWithinAt (hg x m)
/-!
### Associativity of the composition of formal multilinear series
In this paragraph, we prove the associativity of the composition of formal power series.
By definition,
```
(r.comp q).comp p n v
= ∑_{i₁ + ... + iₖ = n} (r.comp q)ₖ (p_{i₁} (v₀, ..., v_{i₁ -1}), p_{i₂} (...), ..., p_{iₖ}(...))
= ∑_{a : Composition n} (r.comp q) a.length (applyComposition p a v)
```
decomposing `r.comp q` in the same way, we get
```
(r.comp q).comp p n v
= ∑_{a : Composition n} ∑_{b : Composition a.length}
r b.length (applyComposition q b (applyComposition p a v))
```
On the other hand,
```
r.comp (q.comp p) n v = ∑_{c : Composition n} r c.length (applyComposition (q.comp p) c v)
```
Here, `applyComposition (q.comp p) c v` is a vector of length `c.length`, whose `i`-th term is
given by `(q.comp p) (c.blocksFun i) (v_l, v_{l+1}, ..., v_{m-1})` where `{l, ..., m-1}` is the
`i`-th block in the composition `c`, of length `c.blocksFun i` by definition. To compute this term,
we expand it as `∑_{dᵢ : Composition (c.blocksFun i)} q dᵢ.length (applyComposition p dᵢ v')`,
where `v' = (v_l, v_{l+1}, ..., v_{m-1})`. Therefore, we get
```
r.comp (q.comp p) n v =
∑_{c : Composition n} ∑_{d₀ : Composition (c.blocksFun 0),
..., d_{c.length - 1} : Composition (c.blocksFun (c.length - 1))}
r c.length (fun i ↦ q dᵢ.length (applyComposition p dᵢ v'ᵢ))
```
To show that these terms coincide, we need to explain how to reindex the sums to put them in
bijection (and then the terms we are summing will correspond to each other). Suppose we have a
composition `a` of `n`, and a composition `b` of `a.length`. Then `b` indicates how to group
together some blocks of `a`, giving altogether `b.length` blocks of blocks. These blocks of blocks
can be called `d₀, ..., d_{a.length - 1}`, and one obtains a composition `c` of `n` by saying that
each `dᵢ` is one single block. Conversely, if one starts from `c` and the `dᵢ`s, one can concatenate
the `dᵢ`s to obtain a composition `a` of `n`, and register the lengths of the `dᵢ`s in a composition
`b` of `a.length`.
An example might be enlightening. Suppose `a = [2, 2, 3, 4, 2]`. It is a composition of
length 5 of 13. The content of the blocks may be represented as `0011222333344`.
Now take `b = [2, 3]` as a composition of `a.length = 5`. It says that the first 2 blocks of `a`
should be merged, and the last 3 blocks of `a` should be merged, giving a new composition of `13`
made of two blocks of length `4` and `9`, i.e., `c = [4, 9]`. But one can also remember that
the new first block was initially made of two blocks of size `2`, so `d₀ = [2, 2]`, and the new
second block was initially made of three blocks of size `3`, `4` and `2`, so `d₁ = [3, 4, 2]`.
This equivalence is called `Composition.sigmaEquivSigmaPi n` below.
We start with preliminary results on compositions, of a very specialized nature, then define the
equivalence `Composition.sigmaEquivSigmaPi n`, and we deduce finally the associativity of
composition of formal multilinear series in `FormalMultilinearSeries.comp_assoc`.
-/
namespace Composition
variable {n : ℕ}
/-- Rewriting equality in the dependent type `Σ (a : Composition n), Composition a.length)` in
non-dependent terms with lists, requiring that the blocks coincide. -/
theorem sigma_composition_eq_iff (i j : Σ a : Composition n, Composition a.length) :
i = j ↔ i.1.blocks = j.1.blocks ∧ i.2.blocks = j.2.blocks := by
refine ⟨by rintro rfl; exact ⟨rfl, rfl⟩, ?_⟩
rcases i with ⟨a, b⟩
rcases j with ⟨a', b'⟩
rintro ⟨h, h'⟩
obtain rfl : a = a' := by ext1; exact h
obtain rfl : b = b' := by ext1; exact h'
rfl
/-- Rewriting equality in the dependent type
`Σ (c : Composition n), Π (i : Fin c.length), Composition (c.blocksFun i)` in
non-dependent terms with lists, requiring that the lists of blocks coincide. -/
theorem sigma_pi_composition_eq_iff
(u v : Σ c : Composition n, ∀ i : Fin c.length, Composition (c.blocksFun i)) :
u = v ↔ (ofFn fun i => (u.2 i).blocks) = ofFn fun i => (v.2 i).blocks := by
refine ⟨fun H => by rw [H], fun H => ?_⟩
rcases u with ⟨a, b⟩
rcases v with ⟨a', b'⟩
dsimp at H
obtain rfl : a = a' := by
ext1
have :
map List.sum (ofFn fun i : Fin (Composition.length a) => (b i).blocks) =
map List.sum (ofFn fun i : Fin (Composition.length a') => (b' i).blocks) := by
rw [H]
simp only [map_ofFn] at this
change
(ofFn fun i : Fin (Composition.length a) => (b i).blocks.sum) =
ofFn fun i : Fin (Composition.length a') => (b' i).blocks.sum at this
simpa [Composition.blocks_sum, Composition.ofFn_blocksFun] using this
ext1
· rfl
· simp only [heq_eq_eq, ofFn_inj] at H ⊢
ext1 i
ext1
exact congrFun H i
/-- When `a` is a composition of `n` and `b` is a composition of `a.length`, `a.gather b` is the
composition of `n` obtained by gathering all the blocks of `a` corresponding to a block of `b`.
For instance, if `a = [6, 5, 3, 5, 2]` and `b = [2, 3]`, one should gather together
the first two blocks of `a` and its last three blocks, giving `a.gather b = [11, 10]`. -/
def gather (a : Composition n) (b : Composition a.length) : Composition n where
blocks := (a.blocks.splitWrtComposition b).map sum
blocks_pos := by
rw [forall_mem_map]
intro j hj
suffices H : ∀ i ∈ j, 1 ≤ i from calc
0 < j.length := length_pos_of_mem_splitWrtComposition hj
_ ≤ j.sum := length_le_sum_of_one_le _ H
intro i hi
apply a.one_le_blocks
rw [← a.blocks.flatten_splitWrtComposition b]
exact mem_flatten_of_mem hj hi
blocks_sum := by rw [← sum_flatten, flatten_splitWrtComposition, a.blocks_sum]
theorem length_gather (a : Composition n) (b : Composition a.length) :
length (a.gather b) = b.length :=
show (map List.sum (a.blocks.splitWrtComposition b)).length = b.blocks.length by
rw [length_map, length_splitWrtComposition]
/-- An auxiliary function used in the definition of `sigmaEquivSigmaPi` below, associating to
two compositions `a` of `n` and `b` of `a.length`, and an index `i` bounded by the length of
`a.gather b`, the subcomposition of `a` made of those blocks belonging to the `i`-th block of
`a.gather b`. -/
def sigmaCompositionAux (a : Composition n) (b : Composition a.length)
(i : Fin (a.gather b).length) : Composition ((a.gather b).blocksFun i) where
blocks :=
(a.blocks.splitWrtComposition b)[i.val]'(by
rw [length_splitWrtComposition, ← length_gather]; exact i.2)
blocks_pos {i} hi :=
a.blocks_pos
(by
rw [← a.blocks.flatten_splitWrtComposition b]
exact mem_flatten_of_mem (List.getElem_mem _) hi)
blocks_sum := by simp [Composition.blocksFun, getElem_map, Composition.gather]
theorem length_sigmaCompositionAux (a : Composition n) (b : Composition a.length)
(i : Fin b.length) :
Composition.length (Composition.sigmaCompositionAux a b ⟨i, (length_gather a b).symm ▸ i.2⟩) =
Composition.blocksFun b i :=
show List.length ((splitWrtComposition a.blocks b)[i.1]) = blocksFun b i by
rw [getElem_map_rev List.length, getElem_of_eq (map_length_splitWrtComposition _ _), blocksFun,
get_eq_getElem]
| Mathlib/Analysis/Analytic/Composition.lean | 1,046 | 1,084 | theorem blocksFun_sigmaCompositionAux (a : Composition n) (b : Composition a.length)
(i : Fin b.length) (j : Fin (blocksFun b i)) :
blocksFun (sigmaCompositionAux a b ⟨i, (length_gather a b).symm ▸ i.2⟩)
⟨j, (length_sigmaCompositionAux a b i).symm ▸ j.2⟩ =
blocksFun a (embedding b i j) := by | unfold sigmaCompositionAux
rw [blocksFun, get_eq_getElem, getElem_of_eq (getElem_splitWrtComposition _ _ _ _),
getElem_drop, getElem_take]; rfl
/-- Auxiliary lemma to prove that the composition of formal multilinear series is associative.
Consider a composition `a` of `n` and a composition `b` of `a.length`. Grouping together some
blocks of `a` according to `b` as in `a.gather b`, one can compute the total size of the blocks
of `a` up to an index `sizeUpTo b i + j` (where the `j` corresponds to a set of blocks of `a`
that do not fill a whole block of `a.gather b`). The first part corresponds to a sum of blocks
in `a.gather b`, and the second one to a sum of blocks in the next block of
`sigmaCompositionAux a b`. This is the content of this lemma. -/
theorem sizeUpTo_sizeUpTo_add (a : Composition n) (b : Composition a.length) {i j : ℕ}
(hi : i < b.length) (hj : j < blocksFun b ⟨i, hi⟩) :
sizeUpTo a (sizeUpTo b i + j) =
sizeUpTo (a.gather b) i +
sizeUpTo (sigmaCompositionAux a b ⟨i, (length_gather a b).symm ▸ hi⟩) j := by
induction j with
| zero =>
show
sum (take (b.blocks.take i).sum a.blocks) =
sum (take i (map sum (splitWrtComposition a.blocks b)))
induction' i with i IH
· rfl
· have A : i < b.length := Nat.lt_of_succ_lt hi
have B : i < List.length (map List.sum (splitWrtComposition a.blocks b)) := by simp [A]
have C : 0 < blocksFun b ⟨i, A⟩ := Composition.blocks_pos' _ _ _
rw [sum_take_succ _ _ B, ← IH A C]
have :
take (sum (take i b.blocks)) a.blocks =
take (sum (take i b.blocks)) (take (sum (take (i + 1) b.blocks)) a.blocks) := by
rw [take_take, min_eq_left]
apply monotone_sum_take _ (Nat.le_succ _)
rw [this, getElem_map, getElem_splitWrtComposition, ← |
/-
Copyright (c) 2014 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Leonardo de Moura, Mario Carneiro, Floris van Doorn
-/
import Mathlib.Algebra.Field.Basic
import Mathlib.Algebra.GroupWithZero.Units.Lemmas
import Mathlib.Algebra.Order.Ring.Abs
import Mathlib.Order.Bounds.Basic
import Mathlib.Order.Bounds.OrderIso
import Mathlib.Tactic.Positivity.Core
/-!
# Lemmas about linear ordered (semi)fields
-/
open Function OrderDual
variable {ι α β : Type*}
section LinearOrderedSemifield
variable [Semifield α] [LinearOrder α] [IsStrictOrderedRing α] {a b c d e : α} {m n : ℤ}
/-!
### Relating two divisions.
-/
@[deprecated div_le_div_iff_of_pos_right (since := "2024-11-12")]
theorem div_le_div_right (hc : 0 < c) : a / c ≤ b / c ↔ a ≤ b := div_le_div_iff_of_pos_right hc
@[deprecated div_lt_div_iff_of_pos_right (since := "2024-11-12")]
theorem div_lt_div_right (hc : 0 < c) : a / c < b / c ↔ a < b := div_lt_div_iff_of_pos_right hc
@[deprecated div_lt_div_iff_of_pos_left (since := "2024-11-13")]
theorem div_lt_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b < a / c ↔ c < b :=
div_lt_div_iff_of_pos_left ha hb hc
@[deprecated div_le_div_iff_of_pos_left (since := "2024-11-12")]
theorem div_le_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b ≤ a / c ↔ c ≤ b :=
div_le_div_iff_of_pos_left ha hb hc
@[deprecated div_lt_div_iff₀ (since := "2024-11-12")]
theorem div_lt_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b < c / d ↔ a * d < c * b :=
div_lt_div_iff₀ b0 d0
@[deprecated div_le_div_iff₀ (since := "2024-11-12")]
theorem div_le_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b ≤ c / d ↔ a * d ≤ c * b :=
div_le_div_iff₀ b0 d0
@[deprecated div_le_div₀ (since := "2024-11-12")]
theorem div_le_div (hc : 0 ≤ c) (hac : a ≤ c) (hd : 0 < d) (hbd : d ≤ b) : a / b ≤ c / d :=
div_le_div₀ hc hac hd hbd
@[deprecated div_lt_div₀ (since := "2024-11-12")]
theorem div_lt_div (hac : a < c) (hbd : d ≤ b) (c0 : 0 ≤ c) (d0 : 0 < d) : a / b < c / d :=
div_lt_div₀ hac hbd c0 d0
@[deprecated div_lt_div₀' (since := "2024-11-12")]
theorem div_lt_div' (hac : a ≤ c) (hbd : d < b) (c0 : 0 < c) (d0 : 0 < d) : a / b < c / d :=
div_lt_div₀' hac hbd c0 d0
/-!
### Relating one division and involving `1`
-/
@[bound]
theorem div_le_self (ha : 0 ≤ a) (hb : 1 ≤ b) : a / b ≤ a := by
simpa only [div_one] using div_le_div_of_nonneg_left ha zero_lt_one hb
@[bound]
theorem div_lt_self (ha : 0 < a) (hb : 1 < b) : a / b < a := by
simpa only [div_one] using div_lt_div_of_pos_left ha zero_lt_one hb
@[bound]
theorem le_div_self (ha : 0 ≤ a) (hb₀ : 0 < b) (hb₁ : b ≤ 1) : a ≤ a / b := by
simpa only [div_one] using div_le_div_of_nonneg_left ha hb₀ hb₁
theorem one_le_div (hb : 0 < b) : 1 ≤ a / b ↔ b ≤ a := by rw [le_div_iff₀ hb, one_mul]
theorem div_le_one (hb : 0 < b) : a / b ≤ 1 ↔ a ≤ b := by rw [div_le_iff₀ hb, one_mul]
theorem one_lt_div (hb : 0 < b) : 1 < a / b ↔ b < a := by rw [lt_div_iff₀ hb, one_mul]
theorem div_lt_one (hb : 0 < b) : a / b < 1 ↔ a < b := by rw [div_lt_iff₀ hb, one_mul]
theorem one_div_le (ha : 0 < a) (hb : 0 < b) : 1 / a ≤ b ↔ 1 / b ≤ a := by
simpa using inv_le_comm₀ ha hb
theorem one_div_lt (ha : 0 < a) (hb : 0 < b) : 1 / a < b ↔ 1 / b < a := by
simpa using inv_lt_comm₀ ha hb
theorem le_one_div (ha : 0 < a) (hb : 0 < b) : a ≤ 1 / b ↔ b ≤ 1 / a := by
simpa using le_inv_comm₀ ha hb
theorem lt_one_div (ha : 0 < a) (hb : 0 < b) : a < 1 / b ↔ b < 1 / a := by
simpa using lt_inv_comm₀ ha hb
@[bound] lemma Bound.one_lt_div_of_pos_of_lt (b0 : 0 < b) : b < a → 1 < a / b := (one_lt_div b0).mpr
@[bound] lemma Bound.div_lt_one_of_pos_of_lt (b0 : 0 < b) : a < b → a / b < 1 := (div_lt_one b0).mpr
/-!
### Relating two divisions, involving `1`
-/
theorem one_div_le_one_div_of_le (ha : 0 < a) (h : a ≤ b) : 1 / b ≤ 1 / a := by
simpa using inv_anti₀ ha h
theorem one_div_lt_one_div_of_lt (ha : 0 < a) (h : a < b) : 1 / b < 1 / a := by
rwa [lt_div_iff₀' ha, ← div_eq_mul_one_div, div_lt_one (ha.trans h)]
theorem le_of_one_div_le_one_div (ha : 0 < a) (h : 1 / a ≤ 1 / b) : b ≤ a :=
le_imp_le_of_lt_imp_lt (one_div_lt_one_div_of_lt ha) h
theorem lt_of_one_div_lt_one_div (ha : 0 < a) (h : 1 / a < 1 / b) : b < a :=
lt_imp_lt_of_le_imp_le (one_div_le_one_div_of_le ha) h
/-- For the single implications with fewer assumptions, see `one_div_le_one_div_of_le` and
`le_of_one_div_le_one_div` -/
theorem one_div_le_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a ≤ 1 / b ↔ b ≤ a :=
div_le_div_iff_of_pos_left zero_lt_one ha hb
/-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_lt` and
`lt_of_one_div_lt_one_div` -/
theorem one_div_lt_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a < 1 / b ↔ b < a :=
div_lt_div_iff_of_pos_left zero_lt_one ha hb
theorem one_lt_one_div (h1 : 0 < a) (h2 : a < 1) : 1 < 1 / a := by
rwa [lt_one_div (@zero_lt_one α _ _ _ _ _) h1, one_div_one]
theorem one_le_one_div (h1 : 0 < a) (h2 : a ≤ 1) : 1 ≤ 1 / a := by
rwa [le_one_div (@zero_lt_one α _ _ _ _ _) h1, one_div_one]
/-!
### Results about halving.
The equalities also hold in semifields of characteristic `0`.
-/
theorem half_pos (h : 0 < a) : 0 < a / 2 :=
div_pos h zero_lt_two
theorem one_half_pos : (0 : α) < 1 / 2 :=
half_pos zero_lt_one
@[simp]
theorem half_le_self_iff : a / 2 ≤ a ↔ 0 ≤ a := by
rw [div_le_iff₀ (zero_lt_two' α), mul_two, le_add_iff_nonneg_left]
@[simp]
theorem half_lt_self_iff : a / 2 < a ↔ 0 < a := by
rw [div_lt_iff₀ (zero_lt_two' α), mul_two, lt_add_iff_pos_left]
alias ⟨_, half_le_self⟩ := half_le_self_iff
alias ⟨_, half_lt_self⟩ := half_lt_self_iff
alias div_two_lt_of_pos := half_lt_self
theorem one_half_lt_one : (1 / 2 : α) < 1 :=
half_lt_self zero_lt_one
theorem two_inv_lt_one : (2⁻¹ : α) < 1 :=
(one_div _).symm.trans_lt one_half_lt_one
theorem left_lt_add_div_two : a < (a + b) / 2 ↔ a < b := by simp [lt_div_iff₀, mul_two]
theorem add_div_two_lt_right : (a + b) / 2 < b ↔ a < b := by simp [div_lt_iff₀, mul_two]
theorem add_thirds (a : α) : a / 3 + a / 3 + a / 3 = a := by
rw [div_add_div_same, div_add_div_same, ← two_mul, ← add_one_mul 2 a, two_add_one_eq_three,
mul_div_cancel_left₀ a three_ne_zero]
/-!
### Miscellaneous lemmas
-/
@[simp] lemma div_pos_iff_of_pos_left (ha : 0 < a) : 0 < a / b ↔ 0 < b := by
simp only [div_eq_mul_inv, mul_pos_iff_of_pos_left ha, inv_pos]
@[simp] lemma div_pos_iff_of_pos_right (hb : 0 < b) : 0 < a / b ↔ 0 < a := by
simp only [div_eq_mul_inv, mul_pos_iff_of_pos_right (inv_pos.2 hb)]
theorem mul_le_mul_of_mul_div_le (h : a * (b / c) ≤ d) (hc : 0 < c) : b * a ≤ d * c := by
rw [← mul_div_assoc] at h
rwa [mul_comm b, ← div_le_iff₀ hc]
theorem div_mul_le_div_mul_of_div_le_div (h : a / b ≤ c / d) (he : 0 ≤ e) :
a / (b * e) ≤ c / (d * e) := by
rw [div_mul_eq_div_mul_one_div, div_mul_eq_div_mul_one_div]
exact mul_le_mul_of_nonneg_right h (one_div_nonneg.2 he)
theorem exists_pos_mul_lt {a : α} (h : 0 < a) (b : α) : ∃ c : α, 0 < c ∧ b * c < a := by
have : 0 < a / max (b + 1) 1 := div_pos h (lt_max_iff.2 (Or.inr zero_lt_one))
refine ⟨a / max (b + 1) 1, this, ?_⟩
rw [← lt_div_iff₀ this, div_div_cancel₀ h.ne']
exact lt_max_iff.2 (Or.inl <| lt_add_one _)
theorem exists_pos_lt_mul {a : α} (h : 0 < a) (b : α) : ∃ c : α, 0 < c ∧ b < c * a :=
let ⟨c, hc₀, hc⟩ := exists_pos_mul_lt h b;
⟨c⁻¹, inv_pos.2 hc₀, by rwa [← div_eq_inv_mul, lt_div_iff₀ hc₀]⟩
lemma monotone_div_right_of_nonneg (ha : 0 ≤ a) : Monotone (· / a) :=
fun _b _c hbc ↦ div_le_div_of_nonneg_right hbc ha
lemma strictMono_div_right_of_pos (ha : 0 < a) : StrictMono (· / a) :=
fun _b _c hbc ↦ div_lt_div_of_pos_right hbc ha
theorem Monotone.div_const {β : Type*} [Preorder β] {f : β → α} (hf : Monotone f) {c : α}
(hc : 0 ≤ c) : Monotone fun x => f x / c := (monotone_div_right_of_nonneg hc).comp hf
theorem StrictMono.div_const {β : Type*} [Preorder β] {f : β → α} (hf : StrictMono f) {c : α}
(hc : 0 < c) : StrictMono fun x => f x / c := by
simpa only [div_eq_mul_inv] using hf.mul_const (inv_pos.2 hc)
-- see Note [lower instance priority]
instance (priority := 100) LinearOrderedSemiField.toDenselyOrdered : DenselyOrdered α where
dense a₁ a₂ h :=
⟨(a₁ + a₂) / 2,
calc
a₁ = (a₁ + a₁) / 2 := (add_self_div_two a₁).symm
_ < (a₁ + a₂) / 2 := div_lt_div_of_pos_right (add_lt_add_left h _) zero_lt_two
,
calc
(a₁ + a₂) / 2 < (a₂ + a₂) / 2 := div_lt_div_of_pos_right (add_lt_add_right h _) zero_lt_two
_ = a₂ := add_self_div_two a₂
⟩
theorem min_div_div_right {c : α} (hc : 0 ≤ c) (a b : α) : min (a / c) (b / c) = min a b / c :=
(monotone_div_right_of_nonneg hc).map_min.symm
theorem max_div_div_right {c : α} (hc : 0 ≤ c) (a b : α) : max (a / c) (b / c) = max a b / c :=
(monotone_div_right_of_nonneg hc).map_max.symm
theorem one_div_strictAntiOn : StrictAntiOn (fun x : α => 1 / x) (Set.Ioi 0) :=
fun _ x1 _ y1 xy => (one_div_lt_one_div (Set.mem_Ioi.mp y1) (Set.mem_Ioi.mp x1)).mpr xy
theorem one_div_pow_le_one_div_pow_of_le (a1 : 1 ≤ a) {m n : ℕ} (mn : m ≤ n) :
1 / a ^ n ≤ 1 / a ^ m := by
refine (one_div_le_one_div ?_ ?_).mpr (pow_right_mono₀ a1 mn) <;>
exact pow_pos (zero_lt_one.trans_le a1) _
theorem one_div_pow_lt_one_div_pow_of_lt (a1 : 1 < a) {m n : ℕ} (mn : m < n) :
1 / a ^ n < 1 / a ^ m := by
refine (one_div_lt_one_div ?_ ?_).2 (pow_lt_pow_right₀ a1 mn) <;>
exact pow_pos (zero_lt_one.trans a1) _
theorem one_div_pow_anti (a1 : 1 ≤ a) : Antitone fun n : ℕ => 1 / a ^ n := fun _ _ =>
one_div_pow_le_one_div_pow_of_le a1
theorem one_div_pow_strictAnti (a1 : 1 < a) : StrictAnti fun n : ℕ => 1 / a ^ n := fun _ _ =>
one_div_pow_lt_one_div_pow_of_lt a1
theorem inv_strictAntiOn : StrictAntiOn (fun x : α => x⁻¹) (Set.Ioi 0) := fun _ hx _ hy xy =>
(inv_lt_inv₀ hy hx).2 xy
theorem inv_pow_le_inv_pow_of_le (a1 : 1 ≤ a) {m n : ℕ} (mn : m ≤ n) : (a ^ n)⁻¹ ≤ (a ^ m)⁻¹ := by
convert one_div_pow_le_one_div_pow_of_le a1 mn using 1 <;> simp
theorem inv_pow_lt_inv_pow_of_lt (a1 : 1 < a) {m n : ℕ} (mn : m < n) : (a ^ n)⁻¹ < (a ^ m)⁻¹ := by
convert one_div_pow_lt_one_div_pow_of_lt a1 mn using 1 <;> simp
theorem inv_pow_anti (a1 : 1 ≤ a) : Antitone fun n : ℕ => (a ^ n)⁻¹ := fun _ _ =>
inv_pow_le_inv_pow_of_le a1
theorem inv_pow_strictAnti (a1 : 1 < a) : StrictAnti fun n : ℕ => (a ^ n)⁻¹ := fun _ _ =>
inv_pow_lt_inv_pow_of_lt a1
theorem le_iff_forall_one_lt_le_mul₀ {α : Type*}
[Semifield α] [LinearOrder α] [IsStrictOrderedRing α]
{a b : α} (hb : 0 ≤ b) : a ≤ b ↔ ∀ ε, 1 < ε → a ≤ b * ε := by
refine ⟨fun h _ hε ↦ h.trans <| le_mul_of_one_le_right hb hε.le, fun h ↦ ?_⟩
obtain rfl|hb := hb.eq_or_lt
· simp_rw [zero_mul] at h
exact h 2 one_lt_two
refine le_of_forall_gt_imp_ge_of_dense fun x hbx => ?_
convert h (x / b) ((one_lt_div hb).mpr hbx)
rw [mul_div_cancel₀ _ hb.ne']
/-! ### Results about `IsGLB` -/
theorem IsGLB.mul_left {s : Set α} (ha : 0 ≤ a) (hs : IsGLB s b) :
IsGLB ((fun b => a * b) '' s) (a * b) := by
rcases lt_or_eq_of_le ha with (ha | rfl)
· exact (OrderIso.mulLeft₀ _ ha).isGLB_image'.2 hs
· simp_rw [zero_mul]
rw [hs.nonempty.image_const]
exact isGLB_singleton
theorem IsGLB.mul_right {s : Set α} (ha : 0 ≤ a) (hs : IsGLB s b) :
IsGLB ((fun b => b * a) '' s) (b * a) := by simpa [mul_comm] using hs.mul_left ha
end LinearOrderedSemifield
section
variable [Field α] [LinearOrder α] [IsStrictOrderedRing α] {a b c d : α} {n : ℤ}
/-! ### Lemmas about pos, nonneg, nonpos, neg -/
theorem div_pos_iff : 0 < a / b ↔ 0 < a ∧ 0 < b ∨ a < 0 ∧ b < 0 := by
simp only [division_def, mul_pos_iff, inv_pos, inv_lt_zero]
theorem div_neg_iff : a / b < 0 ↔ 0 < a ∧ b < 0 ∨ a < 0 ∧ 0 < b := by
simp [division_def, mul_neg_iff]
theorem div_nonneg_iff : 0 ≤ a / b ↔ 0 ≤ a ∧ 0 ≤ b ∨ a ≤ 0 ∧ b ≤ 0 := by
simp [division_def, mul_nonneg_iff]
theorem div_nonpos_iff : a / b ≤ 0 ↔ 0 ≤ a ∧ b ≤ 0 ∨ a ≤ 0 ∧ 0 ≤ b := by
simp [division_def, mul_nonpos_iff]
theorem div_nonneg_of_nonpos (ha : a ≤ 0) (hb : b ≤ 0) : 0 ≤ a / b :=
div_nonneg_iff.2 <| Or.inr ⟨ha, hb⟩
theorem div_pos_of_neg_of_neg (ha : a < 0) (hb : b < 0) : 0 < a / b :=
div_pos_iff.2 <| Or.inr ⟨ha, hb⟩
theorem div_neg_of_neg_of_pos (ha : a < 0) (hb : 0 < b) : a / b < 0 :=
div_neg_iff.2 <| Or.inr ⟨ha, hb⟩
theorem div_neg_of_pos_of_neg (ha : 0 < a) (hb : b < 0) : a / b < 0 :=
div_neg_iff.2 <| Or.inl ⟨ha, hb⟩
/-! ### Relating one division with another term -/
theorem div_le_iff_of_neg (hc : c < 0) : b / c ≤ a ↔ a * c ≤ b :=
⟨fun h => div_mul_cancel₀ b (ne_of_lt hc) ▸ mul_le_mul_of_nonpos_right h hc.le, fun h =>
calc
a = a * c * (1 / c) := mul_mul_div a (ne_of_lt hc)
_ ≥ b * (1 / c) := mul_le_mul_of_nonpos_right h (one_div_neg.2 hc).le
_ = b / c := (div_eq_mul_one_div b c).symm
⟩
theorem div_le_iff_of_neg' (hc : c < 0) : b / c ≤ a ↔ c * a ≤ b := by
rw [mul_comm, div_le_iff_of_neg hc]
theorem le_div_iff_of_neg (hc : c < 0) : a ≤ b / c ↔ b ≤ a * c := by
rw [← neg_neg c, mul_neg, div_neg, le_neg, div_le_iff₀ (neg_pos.2 hc), neg_mul]
theorem le_div_iff_of_neg' (hc : c < 0) : a ≤ b / c ↔ b ≤ c * a := by
rw [mul_comm, le_div_iff_of_neg hc]
theorem div_lt_iff_of_neg (hc : c < 0) : b / c < a ↔ a * c < b :=
lt_iff_lt_of_le_iff_le <| le_div_iff_of_neg hc
theorem div_lt_iff_of_neg' (hc : c < 0) : b / c < a ↔ c * a < b := by
rw [mul_comm, div_lt_iff_of_neg hc]
theorem lt_div_iff_of_neg (hc : c < 0) : a < b / c ↔ b < a * c :=
lt_iff_lt_of_le_iff_le <| div_le_iff_of_neg hc
theorem lt_div_iff_of_neg' (hc : c < 0) : a < b / c ↔ b < c * a := by
rw [mul_comm, lt_div_iff_of_neg hc]
theorem div_le_one_of_ge (h : b ≤ a) (hb : b ≤ 0) : a / b ≤ 1 := by
simpa only [neg_div_neg_eq] using div_le_one_of_le₀ (neg_le_neg h) (neg_nonneg_of_nonpos hb)
/-! ### Bi-implications of inequalities using inversions -/
theorem inv_le_inv_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ ≤ b⁻¹ ↔ b ≤ a := by
rw [← one_div, div_le_iff_of_neg ha, ← div_eq_inv_mul, div_le_iff_of_neg hb, one_mul]
theorem inv_le_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ ≤ b ↔ b⁻¹ ≤ a := by
rw [← inv_le_inv_of_neg hb (inv_lt_zero.2 ha), inv_inv]
theorem le_inv_of_neg (ha : a < 0) (hb : b < 0) : a ≤ b⁻¹ ↔ b ≤ a⁻¹ := by
rw [← inv_le_inv_of_neg (inv_lt_zero.2 hb) ha, inv_inv]
theorem inv_lt_inv_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ < b⁻¹ ↔ b < a :=
lt_iff_lt_of_le_iff_le (inv_le_inv_of_neg hb ha)
theorem inv_lt_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ < b ↔ b⁻¹ < a :=
lt_iff_lt_of_le_iff_le (le_inv_of_neg hb ha)
theorem lt_inv_of_neg (ha : a < 0) (hb : b < 0) : a < b⁻¹ ↔ b < a⁻¹ :=
lt_iff_lt_of_le_iff_le (inv_le_of_neg hb ha)
/-!
### Monotonicity results involving inversion
-/
theorem sub_inv_antitoneOn_Ioi :
AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Ioi c) :=
antitoneOn_iff_forall_lt.mpr fun _ ha _ hb hab ↦
inv_le_inv₀ (sub_pos.mpr hb) (sub_pos.mpr ha) |>.mpr <| sub_le_sub (le_of_lt hab) le_rfl
theorem sub_inv_antitoneOn_Iio :
AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Iio c) :=
antitoneOn_iff_forall_lt.mpr fun _ ha _ hb hab ↦
inv_le_inv_of_neg (sub_neg.mpr hb) (sub_neg.mpr ha) |>.mpr <| sub_le_sub (le_of_lt hab) le_rfl
theorem sub_inv_antitoneOn_Icc_right (ha : c < a) :
AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Icc a b) := by
by_cases hab : a ≤ b
· exact sub_inv_antitoneOn_Ioi.mono <| (Set.Icc_subset_Ioi_iff hab).mpr ha
· simp [hab, Set.Subsingleton.antitoneOn]
theorem sub_inv_antitoneOn_Icc_left (ha : b < c) :
AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Icc a b) := by
by_cases hab : a ≤ b
· exact sub_inv_antitoneOn_Iio.mono <| (Set.Icc_subset_Iio_iff hab).mpr ha
· simp [hab, Set.Subsingleton.antitoneOn]
theorem inv_antitoneOn_Ioi :
AntitoneOn (fun x : α ↦ x⁻¹) (Set.Ioi 0) := by
convert sub_inv_antitoneOn_Ioi (α := α)
exact (sub_zero _).symm
theorem inv_antitoneOn_Iio :
AntitoneOn (fun x : α ↦ x⁻¹) (Set.Iio 0) := by
convert sub_inv_antitoneOn_Iio (α := α)
exact (sub_zero _).symm
theorem inv_antitoneOn_Icc_right (ha : 0 < a) :
AntitoneOn (fun x : α ↦ x⁻¹) (Set.Icc a b) := by
convert sub_inv_antitoneOn_Icc_right ha
exact (sub_zero _).symm
theorem inv_antitoneOn_Icc_left (hb : b < 0) :
AntitoneOn (fun x : α ↦ x⁻¹) (Set.Icc a b) := by
convert sub_inv_antitoneOn_Icc_left hb
exact (sub_zero _).symm
/-! ### Relating two divisions -/
| Mathlib/Algebra/Order/Field/Basic.lean | 436 | 437 | theorem div_le_div_of_nonpos_of_le (hc : c ≤ 0) (h : b ≤ a) : a / c ≤ b / c := by | rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c] |
/-
Copyright (c) 2019 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.Nat.Choose.Basic
import Mathlib.Data.List.FinRange
import Mathlib.Data.List.Perm.Basic
import Mathlib.Data.List.Lex
import Mathlib.Data.List.Induction
/-! # sublists
`List.Sublists` gives a list of all (not necessarily contiguous) sublists of a list.
This file contains basic results on this function.
-/
universe u v w
variable {α : Type u} {β : Type v} {γ : Type w}
open Nat
namespace List
/-! ### sublists -/
@[simp]
theorem sublists'_nil : sublists' (@nil α) = [[]] :=
rfl
@[simp]
theorem sublists'_singleton (a : α) : sublists' [a] = [[], [a]] :=
rfl
/-- Auxiliary helper definition for `sublists'` -/
def sublists'Aux (a : α) (r₁ r₂ : List (List α)) : List (List α) :=
r₁.foldl (init := r₂) fun r l => r ++ [a :: l]
theorem sublists'Aux_eq_array_foldl (a : α) : ∀ (r₁ r₂ : List (List α)),
sublists'Aux a r₁ r₂ = ((r₁.toArray).foldl (init := r₂.toArray)
(fun r l => r.push (a :: l))).toList := by
intro r₁ r₂
rw [sublists'Aux, Array.foldl_toList]
have := List.foldl_hom Array.toList (g₁ := fun r l => r.push (a :: l))
(g₂ := fun r l => r ++ [a :: l]) (l := r₁) (init := r₂.toArray) (by simp)
simpa using this
theorem sublists'_eq_sublists'Aux (l : List α) :
sublists' l = l.foldr (fun a r => sublists'Aux a r r) [[]] := by
simp only [sublists', sublists'Aux_eq_array_foldl]
rw [← List.foldr_hom Array.toList]
· intros _ _; congr
theorem sublists'Aux_eq_map (a : α) (r₁ : List (List α)) : ∀ (r₂ : List (List α)),
sublists'Aux a r₁ r₂ = r₂ ++ map (cons a) r₁ :=
List.reverseRecOn r₁ (fun _ => by simp [sublists'Aux]) fun r₁ l ih r₂ => by
rw [map_append, map_singleton, ← append_assoc, ← ih, sublists'Aux, foldl_append, foldl]
simp [sublists'Aux]
@[simp 900]
theorem sublists'_cons (a : α) (l : List α) :
sublists' (a :: l) = sublists' l ++ map (cons a) (sublists' l) := by
simp [sublists'_eq_sublists'Aux, foldr_cons, sublists'Aux_eq_map]
@[simp]
theorem mem_sublists' {s t : List α} : s ∈ sublists' t ↔ s <+ t := by
induction' t with a t IH generalizing s
· simp only [sublists'_nil, mem_singleton]
exact ⟨fun h => by rw [h], eq_nil_of_sublist_nil⟩
simp only [sublists'_cons, mem_append, IH, mem_map]
constructor <;> intro h
· rcases h with (h | ⟨s, h, rfl⟩)
· exact sublist_cons_of_sublist _ h
· exact h.cons_cons _
· obtain - | ⟨-, h⟩ | ⟨-, h⟩ := h
· exact Or.inl h
· exact Or.inr ⟨_, h, rfl⟩
@[simp]
theorem length_sublists' : ∀ l : List α, length (sublists' l) = 2 ^ length l
| [] => rfl
| a :: l => by
simp +arith only [sublists'_cons, length_append, length_sublists' l,
length_map, length, Nat.pow_succ']
@[simp]
theorem sublists_nil : sublists (@nil α) = [[]] :=
rfl
@[simp]
theorem sublists_singleton (a : α) : sublists [a] = [[], [a]] :=
rfl
/-- Auxiliary helper function for `sublists` -/
def sublistsAux (a : α) (r : List (List α)) : List (List α) :=
r.foldl (init := []) fun r l => r ++ [l, a :: l]
theorem sublistsAux_eq_array_foldl :
sublistsAux = fun (a : α) (r : List (List α)) =>
(r.toArray.foldl (init := #[])
fun r l => (r.push l).push (a :: l)).toList := by
funext a r
simp only [sublistsAux, Array.foldl_toList, Array.mkEmpty]
have := foldl_hom Array.toList (g₁ := fun r l => (r.push l).push (a :: l))
(g₂ := fun r l => r ++ [l, a :: l]) (l := r) (init := #[]) (by simp)
simpa using this
theorem sublistsAux_eq_flatMap :
sublistsAux = fun (a : α) (r : List (List α)) => r.flatMap fun l => [l, a :: l] :=
funext fun a => funext fun r =>
List.reverseRecOn r
(by simp [sublistsAux])
(fun r l ih => by
rw [flatMap_append, ← ih, flatMap_singleton, sublistsAux, foldl_append]
simp [sublistsAux])
@[csimp] theorem sublists_eq_sublistsFast : @sublists = @sublistsFast := by
ext α l : 2
trans l.foldr sublistsAux [[]]
· rw [sublistsAux_eq_flatMap, sublists]
· simp only [sublistsFast, sublistsAux_eq_array_foldl, Array.foldr_toList]
rw [← foldr_hom Array.toList]
· intros _ _; congr
theorem sublists_append (l₁ l₂ : List α) :
sublists (l₁ ++ l₂) = (sublists l₂) >>= (fun x => (sublists l₁).map (· ++ x)) := by
simp only [sublists, foldr_append]
induction l₁ with
| nil => simp
| cons a l₁ ih =>
rw [foldr_cons, ih]
simp [List.flatMap, flatten_flatten, Function.comp_def]
theorem sublists_cons (a : α) (l : List α) :
sublists (a :: l) = sublists l >>= (fun x => [x, a :: x]) :=
show sublists ([a] ++ l) = _ by
rw [sublists_append]
simp only [sublists_singleton, map_cons, bind_eq_flatMap, nil_append, cons_append, map_nil]
@[simp]
theorem sublists_concat (l : List α) (a : α) :
sublists (l ++ [a]) = sublists l ++ map (fun x => x ++ [a]) (sublists l) := by
rw [sublists_append, sublists_singleton, bind_eq_flatMap, flatMap_cons, flatMap_cons, flatMap_nil,
map_id'' append_nil, append_nil]
theorem sublists_reverse (l : List α) : sublists (reverse l) = map reverse (sublists' l) := by
induction' l with hd tl ih <;> [rfl;
simp only [reverse_cons, sublists_append, sublists'_cons, map_append, ih, sublists_singleton,
map_eq_map, bind_eq_flatMap, map_map, flatMap_cons, append_nil, flatMap_nil,
Function.comp_def]]
theorem sublists_eq_sublists' (l : List α) : sublists l = map reverse (sublists' (reverse l)) := by
rw [← sublists_reverse, reverse_reverse]
theorem sublists'_reverse (l : List α) : sublists' (reverse l) = map reverse (sublists l) := by
simp only [sublists_eq_sublists', map_map, map_id'' reverse_reverse, Function.comp_def]
theorem sublists'_eq_sublists (l : List α) : sublists' l = map reverse (sublists (reverse l)) := by
rw [← sublists'_reverse, reverse_reverse]
@[simp]
theorem mem_sublists {s t : List α} : s ∈ sublists t ↔ s <+ t := by
rw [← reverse_sublist, ← mem_sublists', sublists'_reverse,
mem_map_of_injective reverse_injective]
@[simp]
theorem length_sublists (l : List α) : length (sublists l) = 2 ^ length l := by
simp only [sublists_eq_sublists', length_map, length_sublists', length_reverse]
theorem map_pure_sublist_sublists (l : List α) : map pure l <+ sublists l := by
induction' l using reverseRecOn with l a ih <;> simp only [map, map_append, sublists_concat]
· simp only [sublists_nil, sublist_cons_self]
exact ((append_sublist_append_left _).2 <|
singleton_sublist.2 <| mem_map.2 ⟨[], mem_sublists.2 (nil_sublist _), by rfl⟩).trans
((append_sublist_append_right _).2 ih)
/-! ### sublistsLen -/
/-- Auxiliary function to construct the list of all sublists of a given length. Given an
integer `n`, a list `l`, a function `f` and an auxiliary list `L`, it returns the list made of
`f` applied to all sublists of `l` of length `n`, concatenated with `L`. -/
def sublistsLenAux : ℕ → List α → (List α → β) → List β → List β
| 0, _, f, r => f [] :: r
| _ + 1, [], _, r => r
| n + 1, a :: l, f, r => sublistsLenAux (n + 1) l f (sublistsLenAux n l (f ∘ List.cons a) r)
/-- The list of all sublists of a list `l` that are of length `n`. For instance, for
`l = [0, 1, 2, 3]` and `n = 2`, one gets
`[[2, 3], [1, 3], [1, 2], [0, 3], [0, 2], [0, 1]]`. -/
def sublistsLen (n : ℕ) (l : List α) : List (List α) :=
sublistsLenAux n l id []
theorem sublistsLenAux_append :
∀ (n : ℕ) (l : List α) (f : List α → β) (g : β → γ) (r : List β) (s : List γ),
sublistsLenAux n l (g ∘ f) (r.map g ++ s) = (sublistsLenAux n l f r).map g ++ s
| 0, l, f, g, r, s => by unfold sublistsLenAux; simp
| _ + 1, [], _, _, _, _ => rfl
| n + 1, a :: l, f, g, r, s => by
unfold sublistsLenAux
simp only [show (g ∘ f) ∘ List.cons a = g ∘ f ∘ List.cons a by rfl, sublistsLenAux_append,
sublistsLenAux_append]
theorem sublistsLenAux_eq (l : List α) (n) (f : List α → β) (r) :
sublistsLenAux n l f r = (sublistsLen n l).map f ++ r := by
rw [sublistsLen, ← sublistsLenAux_append]; rfl
| Mathlib/Data/List/Sublists.lean | 209 | 210 | theorem sublistsLenAux_zero (l : List α) (f : List α → β) (r) :
sublistsLenAux 0 l f r = f [] :: r := by | cases l <;> rfl |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Sébastien Gouëzel,
Rémy Degenne, David Loeffler
-/
import Mathlib.Analysis.SpecialFunctions.Pow.Real
/-!
# Power function on `ℝ≥0` and `ℝ≥0∞`
We construct the power functions `x ^ y` where
* `x` is a nonnegative real number and `y` is a real number;
* `x` is a number from `[0, +∞]` (a.k.a. `ℝ≥0∞`) and `y` is a real number.
We also prove basic properties of these functions.
-/
noncomputable section
open Real NNReal ENNReal ComplexConjugate Finset Function Set
namespace NNReal
variable {x : ℝ≥0} {w y z : ℝ}
/-- The nonnegative real power function `x^y`, defined for `x : ℝ≥0` and `y : ℝ` as the
restriction of the real power function. For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`,
one sets `0 ^ 0 = 1` and `0 ^ y = 0` for `y ≠ 0`. -/
noncomputable def rpow (x : ℝ≥0) (y : ℝ) : ℝ≥0 :=
⟨(x : ℝ) ^ y, Real.rpow_nonneg x.2 y⟩
noncomputable instance : Pow ℝ≥0 ℝ :=
⟨rpow⟩
@[simp]
theorem rpow_eq_pow (x : ℝ≥0) (y : ℝ) : rpow x y = x ^ y :=
rfl
@[simp, norm_cast]
theorem coe_rpow (x : ℝ≥0) (y : ℝ) : ((x ^ y : ℝ≥0) : ℝ) = (x : ℝ) ^ y :=
rfl
@[simp]
theorem rpow_zero (x : ℝ≥0) : x ^ (0 : ℝ) = 1 :=
NNReal.eq <| Real.rpow_zero _
@[simp]
theorem rpow_eq_zero_iff {x : ℝ≥0} {y : ℝ} : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 := by
rw [← NNReal.coe_inj, coe_rpow, ← NNReal.coe_eq_zero]
exact Real.rpow_eq_zero_iff_of_nonneg x.2
lemma rpow_eq_zero (hy : y ≠ 0) : x ^ y = 0 ↔ x = 0 := by simp [hy]
@[simp]
theorem zero_rpow {x : ℝ} (h : x ≠ 0) : (0 : ℝ≥0) ^ x = 0 :=
NNReal.eq <| Real.zero_rpow h
@[simp]
theorem rpow_one (x : ℝ≥0) : x ^ (1 : ℝ) = x :=
NNReal.eq <| Real.rpow_one _
lemma rpow_neg (x : ℝ≥0) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ :=
NNReal.eq <| Real.rpow_neg x.2 _
@[simp, norm_cast]
lemma rpow_natCast (x : ℝ≥0) (n : ℕ) : x ^ (n : ℝ) = x ^ n :=
NNReal.eq <| by simpa only [coe_rpow, coe_pow] using Real.rpow_natCast x n
@[simp, norm_cast]
lemma rpow_intCast (x : ℝ≥0) (n : ℤ) : x ^ (n : ℝ) = x ^ n := by
cases n <;> simp only [Int.ofNat_eq_coe, Int.cast_natCast, rpow_natCast, zpow_natCast,
Int.cast_negSucc, rpow_neg, zpow_negSucc]
@[simp]
theorem one_rpow (x : ℝ) : (1 : ℝ≥0) ^ x = 1 :=
NNReal.eq <| Real.one_rpow _
theorem rpow_add {x : ℝ≥0} (hx : x ≠ 0) (y z : ℝ) : x ^ (y + z) = x ^ y * x ^ z :=
NNReal.eq <| Real.rpow_add ((NNReal.coe_pos.trans pos_iff_ne_zero).mpr hx) _ _
theorem rpow_add' (h : y + z ≠ 0) (x : ℝ≥0) : x ^ (y + z) = x ^ y * x ^ z :=
NNReal.eq <| Real.rpow_add' x.2 h
lemma rpow_add_intCast (hx : x ≠ 0) (y : ℝ) (n : ℤ) : x ^ (y + n) = x ^ y * x ^ n := by
ext; exact Real.rpow_add_intCast (mod_cast hx) _ _
lemma rpow_add_natCast (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y + n) = x ^ y * x ^ n := by
ext; exact Real.rpow_add_natCast (mod_cast hx) _ _
lemma rpow_sub_intCast (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y - n) = x ^ y / x ^ n := by
ext; exact Real.rpow_sub_intCast (mod_cast hx) _ _
lemma rpow_sub_natCast (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y - n) = x ^ y / x ^ n := by
ext; exact Real.rpow_sub_natCast (mod_cast hx) _ _
lemma rpow_add_intCast' {n : ℤ} (h : y + n ≠ 0) (x : ℝ≥0) : x ^ (y + n) = x ^ y * x ^ n := by
ext; exact Real.rpow_add_intCast' (mod_cast x.2) h
lemma rpow_add_natCast' {n : ℕ} (h : y + n ≠ 0) (x : ℝ≥0) : x ^ (y + n) = x ^ y * x ^ n := by
ext; exact Real.rpow_add_natCast' (mod_cast x.2) h
lemma rpow_sub_intCast' {n : ℤ} (h : y - n ≠ 0) (x : ℝ≥0) : x ^ (y - n) = x ^ y / x ^ n := by
ext; exact Real.rpow_sub_intCast' (mod_cast x.2) h
lemma rpow_sub_natCast' {n : ℕ} (h : y - n ≠ 0) (x : ℝ≥0) : x ^ (y - n) = x ^ y / x ^ n := by
ext; exact Real.rpow_sub_natCast' (mod_cast x.2) h
lemma rpow_add_one (hx : x ≠ 0) (y : ℝ) : x ^ (y + 1) = x ^ y * x := by
simpa using rpow_add_natCast hx y 1
lemma rpow_sub_one (hx : x ≠ 0) (y : ℝ) : x ^ (y - 1) = x ^ y / x := by
simpa using rpow_sub_natCast hx y 1
lemma rpow_add_one' (h : y + 1 ≠ 0) (x : ℝ≥0) : x ^ (y + 1) = x ^ y * x := by
rw [rpow_add' h, rpow_one]
lemma rpow_one_add' (h : 1 + y ≠ 0) (x : ℝ≥0) : x ^ (1 + y) = x * x ^ y := by
rw [rpow_add' h, rpow_one]
theorem rpow_add_of_nonneg (x : ℝ≥0) {y z : ℝ} (hy : 0 ≤ y) (hz : 0 ≤ z) :
x ^ (y + z) = x ^ y * x ^ z := by
ext; exact Real.rpow_add_of_nonneg x.2 hy hz
/-- Variant of `NNReal.rpow_add'` that avoids having to prove `y + z = w` twice. -/
lemma rpow_of_add_eq (x : ℝ≥0) (hw : w ≠ 0) (h : y + z = w) : x ^ w = x ^ y * x ^ z := by
rw [← h, rpow_add']; rwa [h]
theorem rpow_mul (x : ℝ≥0) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z :=
NNReal.eq <| Real.rpow_mul x.2 y z
lemma rpow_natCast_mul (x : ℝ≥0) (n : ℕ) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by
rw [rpow_mul, rpow_natCast]
lemma rpow_mul_natCast (x : ℝ≥0) (y : ℝ) (n : ℕ) : x ^ (y * n) = (x ^ y) ^ n := by
rw [rpow_mul, rpow_natCast]
lemma rpow_intCast_mul (x : ℝ≥0) (n : ℤ) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by
rw [rpow_mul, rpow_intCast]
lemma rpow_mul_intCast (x : ℝ≥0) (y : ℝ) (n : ℤ) : x ^ (y * n) = (x ^ y) ^ n := by
rw [rpow_mul, rpow_intCast]
theorem rpow_neg_one (x : ℝ≥0) : x ^ (-1 : ℝ) = x⁻¹ := by simp [rpow_neg]
theorem rpow_sub {x : ℝ≥0} (hx : x ≠ 0) (y z : ℝ) : x ^ (y - z) = x ^ y / x ^ z :=
NNReal.eq <| Real.rpow_sub ((NNReal.coe_pos.trans pos_iff_ne_zero).mpr hx) y z
theorem rpow_sub' (h : y - z ≠ 0) (x : ℝ≥0) : x ^ (y - z) = x ^ y / x ^ z :=
NNReal.eq <| Real.rpow_sub' x.2 h
lemma rpow_sub_one' (h : y - 1 ≠ 0) (x : ℝ≥0) : x ^ (y - 1) = x ^ y / x := by
rw [rpow_sub' h, rpow_one]
lemma rpow_one_sub' (h : 1 - y ≠ 0) (x : ℝ≥0) : x ^ (1 - y) = x / x ^ y := by
rw [rpow_sub' h, rpow_one]
theorem rpow_inv_rpow_self {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ y) ^ (1 / y) = x := by
field_simp [← rpow_mul]
theorem rpow_self_rpow_inv {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ (1 / y)) ^ y = x := by
field_simp [← rpow_mul]
theorem inv_rpow (x : ℝ≥0) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ :=
NNReal.eq <| Real.inv_rpow x.2 y
theorem div_rpow (x y : ℝ≥0) (z : ℝ) : (x / y) ^ z = x ^ z / y ^ z :=
NNReal.eq <| Real.div_rpow x.2 y.2 z
theorem sqrt_eq_rpow (x : ℝ≥0) : sqrt x = x ^ (1 / (2 : ℝ)) := by
refine NNReal.eq ?_
push_cast
exact Real.sqrt_eq_rpow x.1
@[simp]
lemma rpow_ofNat (x : ℝ≥0) (n : ℕ) [n.AtLeastTwo] :
x ^ (ofNat(n) : ℝ) = x ^ (OfNat.ofNat n : ℕ) :=
rpow_natCast x n
theorem rpow_two (x : ℝ≥0) : x ^ (2 : ℝ) = x ^ 2 := rpow_ofNat x 2
theorem mul_rpow {x y : ℝ≥0} {z : ℝ} : (x * y) ^ z = x ^ z * y ^ z :=
NNReal.eq <| Real.mul_rpow x.2 y.2
/-- `rpow` as a `MonoidHom` -/
@[simps]
def rpowMonoidHom (r : ℝ) : ℝ≥0 →* ℝ≥0 where
toFun := (· ^ r)
map_one' := one_rpow _
map_mul' _x _y := mul_rpow
/-- `rpow` variant of `List.prod_map_pow` for `ℝ≥0` -/
theorem list_prod_map_rpow (l : List ℝ≥0) (r : ℝ) :
(l.map (· ^ r)).prod = l.prod ^ r :=
l.prod_hom (rpowMonoidHom r)
theorem list_prod_map_rpow' {ι} (l : List ι) (f : ι → ℝ≥0) (r : ℝ) :
(l.map (f · ^ r)).prod = (l.map f).prod ^ r := by
rw [← list_prod_map_rpow, List.map_map]; rfl
/-- `rpow` version of `Multiset.prod_map_pow` for `ℝ≥0`. -/
lemma multiset_prod_map_rpow {ι} (s : Multiset ι) (f : ι → ℝ≥0) (r : ℝ) :
(s.map (f · ^ r)).prod = (s.map f).prod ^ r :=
s.prod_hom' (rpowMonoidHom r) _
/-- `rpow` version of `Finset.prod_pow` for `ℝ≥0`. -/
lemma finset_prod_rpow {ι} (s : Finset ι) (f : ι → ℝ≥0) (r : ℝ) :
(∏ i ∈ s, f i ^ r) = (∏ i ∈ s, f i) ^ r :=
multiset_prod_map_rpow _ _ _
-- note: these don't really belong here, but they're much easier to prove in terms of the above
section Real
/-- `rpow` version of `List.prod_map_pow` for `Real`. -/
theorem _root_.Real.list_prod_map_rpow (l : List ℝ) (hl : ∀ x ∈ l, (0 : ℝ) ≤ x) (r : ℝ) :
(l.map (· ^ r)).prod = l.prod ^ r := by
lift l to List ℝ≥0 using hl
have := congr_arg ((↑) : ℝ≥0 → ℝ) (NNReal.list_prod_map_rpow l r)
push_cast at this
rw [List.map_map] at this ⊢
exact mod_cast this
theorem _root_.Real.list_prod_map_rpow' {ι} (l : List ι) (f : ι → ℝ)
(hl : ∀ i ∈ l, (0 : ℝ) ≤ f i) (r : ℝ) :
(l.map (f · ^ r)).prod = (l.map f).prod ^ r := by
rw [← Real.list_prod_map_rpow (l.map f) _ r, List.map_map]
· rfl
simpa using hl
/-- `rpow` version of `Multiset.prod_map_pow`. -/
theorem _root_.Real.multiset_prod_map_rpow {ι} (s : Multiset ι) (f : ι → ℝ)
(hs : ∀ i ∈ s, (0 : ℝ) ≤ f i) (r : ℝ) :
(s.map (f · ^ r)).prod = (s.map f).prod ^ r := by
induction' s using Quotient.inductionOn with l
simpa using Real.list_prod_map_rpow' l f hs r
/-- `rpow` version of `Finset.prod_pow`. -/
theorem _root_.Real.finset_prod_rpow
{ι} (s : Finset ι) (f : ι → ℝ) (hs : ∀ i ∈ s, 0 ≤ f i) (r : ℝ) :
(∏ i ∈ s, f i ^ r) = (∏ i ∈ s, f i) ^ r :=
Real.multiset_prod_map_rpow s.val f hs r
end Real
@[gcongr] theorem rpow_le_rpow {x y : ℝ≥0} {z : ℝ} (h₁ : x ≤ y) (h₂ : 0 ≤ z) : x ^ z ≤ y ^ z :=
Real.rpow_le_rpow x.2 h₁ h₂
@[gcongr] theorem rpow_lt_rpow {x y : ℝ≥0} {z : ℝ} (h₁ : x < y) (h₂ : 0 < z) : x ^ z < y ^ z :=
Real.rpow_lt_rpow x.2 h₁ h₂
theorem rpow_lt_rpow_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ z < y ^ z ↔ x < y :=
Real.rpow_lt_rpow_iff x.2 y.2 hz
theorem rpow_le_rpow_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ z ≤ y ^ z ↔ x ≤ y :=
Real.rpow_le_rpow_iff x.2 y.2 hz
theorem le_rpow_inv_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ≤ y ^ z⁻¹ ↔ x ^ z ≤ y := by
rw [← rpow_le_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz.ne']
theorem rpow_inv_le_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ z⁻¹ ≤ y ↔ x ≤ y ^ z := by
rw [← rpow_le_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz.ne']
theorem lt_rpow_inv_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x < y ^ z⁻¹ ↔ x ^z < y := by
simp only [← not_le, rpow_inv_le_iff hz]
theorem rpow_inv_lt_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ z⁻¹ < y ↔ x < y ^ z := by
simp only [← not_le, le_rpow_inv_iff hz]
section
variable {y : ℝ≥0}
lemma rpow_lt_rpow_of_neg (hx : 0 < x) (hxy : x < y) (hz : z < 0) : y ^ z < x ^ z :=
Real.rpow_lt_rpow_of_neg hx hxy hz
lemma rpow_le_rpow_of_nonpos (hx : 0 < x) (hxy : x ≤ y) (hz : z ≤ 0) : y ^ z ≤ x ^ z :=
Real.rpow_le_rpow_of_nonpos hx hxy hz
lemma rpow_lt_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z < y ^ z ↔ y < x :=
Real.rpow_lt_rpow_iff_of_neg hx hy hz
lemma rpow_le_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z ≤ y ^ z ↔ y ≤ x :=
Real.rpow_le_rpow_iff_of_neg hx hy hz
lemma le_rpow_inv_iff_of_pos (hy : 0 ≤ y) (hz : 0 < z) (x : ℝ≥0) : x ≤ y ^ z⁻¹ ↔ x ^ z ≤ y :=
Real.le_rpow_inv_iff_of_pos x.2 hy hz
lemma rpow_inv_le_iff_of_pos (hy : 0 ≤ y) (hz : 0 < z) (x : ℝ≥0) : x ^ z⁻¹ ≤ y ↔ x ≤ y ^ z :=
Real.rpow_inv_le_iff_of_pos x.2 hy hz
lemma lt_rpow_inv_iff_of_pos (hy : 0 ≤ y) (hz : 0 < z) (x : ℝ≥0) : x < y ^ z⁻¹ ↔ x ^ z < y :=
Real.lt_rpow_inv_iff_of_pos x.2 hy hz
lemma rpow_inv_lt_iff_of_pos (hy : 0 ≤ y) (hz : 0 < z) (x : ℝ≥0) : x ^ z⁻¹ < y ↔ x < y ^ z :=
Real.rpow_inv_lt_iff_of_pos x.2 hy hz
lemma le_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ≤ y ^ z⁻¹ ↔ y ≤ x ^ z :=
Real.le_rpow_inv_iff_of_neg hx hy hz
lemma lt_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x < y ^ z⁻¹ ↔ y < x ^ z :=
Real.lt_rpow_inv_iff_of_neg hx hy hz
lemma rpow_inv_lt_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ < y ↔ y ^ z < x :=
Real.rpow_inv_lt_iff_of_neg hx hy hz
lemma rpow_inv_le_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ ≤ y ↔ y ^ z ≤ x :=
Real.rpow_inv_le_iff_of_neg hx hy hz
end
@[gcongr] theorem rpow_lt_rpow_of_exponent_lt {x : ℝ≥0} {y z : ℝ} (hx : 1 < x) (hyz : y < z) :
x ^ y < x ^ z :=
Real.rpow_lt_rpow_of_exponent_lt hx hyz
@[gcongr] theorem rpow_le_rpow_of_exponent_le {x : ℝ≥0} {y z : ℝ} (hx : 1 ≤ x) (hyz : y ≤ z) :
x ^ y ≤ x ^ z :=
Real.rpow_le_rpow_of_exponent_le hx hyz
theorem rpow_lt_rpow_of_exponent_gt {x : ℝ≥0} {y z : ℝ} (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) :
x ^ y < x ^ z :=
Real.rpow_lt_rpow_of_exponent_gt hx0 hx1 hyz
theorem rpow_le_rpow_of_exponent_ge {x : ℝ≥0} {y z : ℝ} (hx0 : 0 < x) (hx1 : x ≤ 1) (hyz : z ≤ y) :
x ^ y ≤ x ^ z :=
Real.rpow_le_rpow_of_exponent_ge hx0 hx1 hyz
theorem rpow_pos {p : ℝ} {x : ℝ≥0} (hx_pos : 0 < x) : 0 < x ^ p := by
have rpow_pos_of_nonneg : ∀ {p : ℝ}, 0 < p → 0 < x ^ p := by
intro p hp_pos
rw [← zero_rpow hp_pos.ne']
exact rpow_lt_rpow hx_pos hp_pos
rcases lt_trichotomy (0 : ℝ) p with (hp_pos | rfl | hp_neg)
· exact rpow_pos_of_nonneg hp_pos
· simp only [zero_lt_one, rpow_zero]
· rw [← neg_neg p, rpow_neg, inv_pos]
exact rpow_pos_of_nonneg (neg_pos.mpr hp_neg)
theorem rpow_lt_one {x : ℝ≥0} {z : ℝ} (hx1 : x < 1) (hz : 0 < z) : x ^ z < 1 :=
Real.rpow_lt_one (coe_nonneg x) hx1 hz
theorem rpow_le_one {x : ℝ≥0} {z : ℝ} (hx2 : x ≤ 1) (hz : 0 ≤ z) : x ^ z ≤ 1 :=
Real.rpow_le_one x.2 hx2 hz
theorem rpow_lt_one_of_one_lt_of_neg {x : ℝ≥0} {z : ℝ} (hx : 1 < x) (hz : z < 0) : x ^ z < 1 :=
Real.rpow_lt_one_of_one_lt_of_neg hx hz
theorem rpow_le_one_of_one_le_of_nonpos {x : ℝ≥0} {z : ℝ} (hx : 1 ≤ x) (hz : z ≤ 0) : x ^ z ≤ 1 :=
Real.rpow_le_one_of_one_le_of_nonpos hx hz
theorem one_lt_rpow {x : ℝ≥0} {z : ℝ} (hx : 1 < x) (hz : 0 < z) : 1 < x ^ z :=
Real.one_lt_rpow hx hz
theorem one_le_rpow {x : ℝ≥0} {z : ℝ} (h : 1 ≤ x) (h₁ : 0 ≤ z) : 1 ≤ x ^ z :=
Real.one_le_rpow h h₁
theorem one_lt_rpow_of_pos_of_lt_one_of_neg {x : ℝ≥0} {z : ℝ} (hx1 : 0 < x) (hx2 : x < 1)
(hz : z < 0) : 1 < x ^ z :=
Real.one_lt_rpow_of_pos_of_lt_one_of_neg hx1 hx2 hz
theorem one_le_rpow_of_pos_of_le_one_of_nonpos {x : ℝ≥0} {z : ℝ} (hx1 : 0 < x) (hx2 : x ≤ 1)
(hz : z ≤ 0) : 1 ≤ x ^ z :=
Real.one_le_rpow_of_pos_of_le_one_of_nonpos hx1 hx2 hz
theorem rpow_le_self_of_le_one {x : ℝ≥0} {z : ℝ} (hx : x ≤ 1) (h_one_le : 1 ≤ z) : x ^ z ≤ x := by
rcases eq_bot_or_bot_lt x with (rfl | (h : 0 < x))
· have : z ≠ 0 := by linarith
simp [this]
nth_rw 2 [← NNReal.rpow_one x]
exact NNReal.rpow_le_rpow_of_exponent_ge h hx h_one_le
theorem rpow_left_injective {x : ℝ} (hx : x ≠ 0) : Function.Injective fun y : ℝ≥0 => y ^ x :=
fun y z hyz => by simpa only [rpow_inv_rpow_self hx] using congr_arg (fun y => y ^ (1 / x)) hyz
theorem rpow_eq_rpow_iff {x y : ℝ≥0} {z : ℝ} (hz : z ≠ 0) : x ^ z = y ^ z ↔ x = y :=
(rpow_left_injective hz).eq_iff
theorem rpow_left_surjective {x : ℝ} (hx : x ≠ 0) : Function.Surjective fun y : ℝ≥0 => y ^ x :=
fun y => ⟨y ^ x⁻¹, by simp_rw [← rpow_mul, inv_mul_cancel₀ hx, rpow_one]⟩
theorem rpow_left_bijective {x : ℝ} (hx : x ≠ 0) : Function.Bijective fun y : ℝ≥0 => y ^ x :=
⟨rpow_left_injective hx, rpow_left_surjective hx⟩
theorem eq_rpow_inv_iff {x y : ℝ≥0} {z : ℝ} (hz : z ≠ 0) : x = y ^ z⁻¹ ↔ x ^ z = y := by
rw [← rpow_eq_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz]
theorem rpow_inv_eq_iff {x y : ℝ≥0} {z : ℝ} (hz : z ≠ 0) : x ^ z⁻¹ = y ↔ x = y ^ z := by
rw [← rpow_eq_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz]
@[simp] lemma rpow_rpow_inv {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ y) ^ y⁻¹ = x := by
rw [← rpow_mul, mul_inv_cancel₀ hy, rpow_one]
@[simp] lemma rpow_inv_rpow {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0) : (x ^ y⁻¹) ^ y = x := by
rw [← rpow_mul, inv_mul_cancel₀ hy, rpow_one]
theorem pow_rpow_inv_natCast (x : ℝ≥0) {n : ℕ} (hn : n ≠ 0) : (x ^ n) ^ (n⁻¹ : ℝ) = x := by
rw [← NNReal.coe_inj, coe_rpow, NNReal.coe_pow]
exact Real.pow_rpow_inv_natCast x.2 hn
theorem rpow_inv_natCast_pow (x : ℝ≥0) {n : ℕ} (hn : n ≠ 0) : (x ^ (n⁻¹ : ℝ)) ^ n = x := by
rw [← NNReal.coe_inj, NNReal.coe_pow, coe_rpow]
exact Real.rpow_inv_natCast_pow x.2 hn
theorem _root_.Real.toNNReal_rpow_of_nonneg {x y : ℝ} (hx : 0 ≤ x) :
Real.toNNReal (x ^ y) = Real.toNNReal x ^ y := by
nth_rw 1 [← Real.coe_toNNReal x hx]
rw [← NNReal.coe_rpow, Real.toNNReal_coe]
theorem strictMono_rpow_of_pos {z : ℝ} (h : 0 < z) : StrictMono fun x : ℝ≥0 => x ^ z :=
fun x y hxy => by simp only [NNReal.rpow_lt_rpow hxy h, coe_lt_coe]
theorem monotone_rpow_of_nonneg {z : ℝ} (h : 0 ≤ z) : Monotone fun x : ℝ≥0 => x ^ z :=
h.eq_or_lt.elim (fun h0 => h0 ▸ by simp only [rpow_zero, monotone_const]) fun h0 =>
(strictMono_rpow_of_pos h0).monotone
/-- Bundles `fun x : ℝ≥0 => x ^ y` into an order isomorphism when `y : ℝ` is positive,
where the inverse is `fun x : ℝ≥0 => x ^ (1 / y)`. -/
@[simps! apply]
def orderIsoRpow (y : ℝ) (hy : 0 < y) : ℝ≥0 ≃o ℝ≥0 :=
(strictMono_rpow_of_pos hy).orderIsoOfRightInverse (fun x => x ^ y) (fun x => x ^ (1 / y))
fun x => by
dsimp
rw [← rpow_mul, one_div_mul_cancel hy.ne.symm, rpow_one]
theorem orderIsoRpow_symm_eq (y : ℝ) (hy : 0 < y) :
(orderIsoRpow y hy).symm = orderIsoRpow (1 / y) (one_div_pos.2 hy) := by
simp only [orderIsoRpow, one_div_one_div]; rfl
theorem _root_.Real.nnnorm_rpow_of_nonneg {x y : ℝ} (hx : 0 ≤ x) : ‖x ^ y‖₊ = ‖x‖₊ ^ y := by
ext; exact Real.norm_rpow_of_nonneg hx
end NNReal
namespace ENNReal
/-- The real power function `x^y` on extended nonnegative reals, defined for `x : ℝ≥0∞` and
`y : ℝ` as the restriction of the real power function if `0 < x < ⊤`, and with the natural values
for `0` and `⊤` (i.e., `0 ^ x = 0` for `x > 0`, `1` for `x = 0` and `⊤` for `x < 0`, and
`⊤ ^ x = 1 / 0 ^ x`). -/
noncomputable def rpow : ℝ≥0∞ → ℝ → ℝ≥0∞
| some x, y => if x = 0 ∧ y < 0 then ⊤ else (x ^ y : ℝ≥0)
| none, y => if 0 < y then ⊤ else if y = 0 then 1 else 0
noncomputable instance : Pow ℝ≥0∞ ℝ :=
⟨rpow⟩
@[simp]
theorem rpow_eq_pow (x : ℝ≥0∞) (y : ℝ) : rpow x y = x ^ y :=
rfl
@[simp]
theorem rpow_zero {x : ℝ≥0∞} : x ^ (0 : ℝ) = 1 := by
cases x <;>
· dsimp only [(· ^ ·), Pow.pow, rpow]
simp [lt_irrefl]
theorem top_rpow_def (y : ℝ) : (⊤ : ℝ≥0∞) ^ y = if 0 < y then ⊤ else if y = 0 then 1 else 0 :=
rfl
@[simp]
theorem top_rpow_of_pos {y : ℝ} (h : 0 < y) : (⊤ : ℝ≥0∞) ^ y = ⊤ := by simp [top_rpow_def, h]
@[simp]
theorem top_rpow_of_neg {y : ℝ} (h : y < 0) : (⊤ : ℝ≥0∞) ^ y = 0 := by
simp [top_rpow_def, asymm h, ne_of_lt h]
@[simp]
theorem zero_rpow_of_pos {y : ℝ} (h : 0 < y) : (0 : ℝ≥0∞) ^ y = 0 := by
rw [← ENNReal.coe_zero, ← ENNReal.some_eq_coe]
dsimp only [(· ^ ·), rpow, Pow.pow]
simp [h, asymm h, ne_of_gt h]
@[simp]
theorem zero_rpow_of_neg {y : ℝ} (h : y < 0) : (0 : ℝ≥0∞) ^ y = ⊤ := by
rw [← ENNReal.coe_zero, ← ENNReal.some_eq_coe]
dsimp only [(· ^ ·), rpow, Pow.pow]
simp [h, ne_of_gt h]
theorem zero_rpow_def (y : ℝ) : (0 : ℝ≥0∞) ^ y = if 0 < y then 0 else if y = 0 then 1 else ⊤ := by
rcases lt_trichotomy (0 : ℝ) y with (H | rfl | H)
· simp [H, ne_of_gt, zero_rpow_of_pos, lt_irrefl]
· simp [lt_irrefl]
· simp [H, asymm H, ne_of_lt, zero_rpow_of_neg]
@[simp]
theorem zero_rpow_mul_self (y : ℝ) : (0 : ℝ≥0∞) ^ y * (0 : ℝ≥0∞) ^ y = (0 : ℝ≥0∞) ^ y := by
rw [zero_rpow_def]
split_ifs
exacts [zero_mul _, one_mul _, top_mul_top]
@[norm_cast]
theorem coe_rpow_of_ne_zero {x : ℝ≥0} (h : x ≠ 0) (y : ℝ) : (↑(x ^ y) : ℝ≥0∞) = x ^ y := by
rw [← ENNReal.some_eq_coe]
dsimp only [(· ^ ·), Pow.pow, rpow]
simp [h]
@[norm_cast]
theorem coe_rpow_of_nonneg (x : ℝ≥0) {y : ℝ} (h : 0 ≤ y) : ↑(x ^ y) = (x : ℝ≥0∞) ^ y := by
by_cases hx : x = 0
· rcases le_iff_eq_or_lt.1 h with (H | H)
· simp [hx, H.symm]
· simp [hx, zero_rpow_of_pos H, NNReal.zero_rpow (ne_of_gt H)]
· exact coe_rpow_of_ne_zero hx _
theorem coe_rpow_def (x : ℝ≥0) (y : ℝ) :
(x : ℝ≥0∞) ^ y = if x = 0 ∧ y < 0 then ⊤ else ↑(x ^ y) :=
rfl
theorem rpow_ofNNReal {M : ℝ≥0} {P : ℝ} (hP : 0 ≤ P) : (M : ℝ≥0∞) ^ P = ↑(M ^ P) := by
rw [ENNReal.coe_rpow_of_nonneg _ hP, ← ENNReal.rpow_eq_pow]
@[simp]
theorem rpow_one (x : ℝ≥0∞) : x ^ (1 : ℝ) = x := by
cases x
· exact dif_pos zero_lt_one
· change ite _ _ _ = _
simp only [NNReal.rpow_one, some_eq_coe, ite_eq_right_iff, top_ne_coe, and_imp]
exact fun _ => zero_le_one.not_lt
@[simp]
theorem one_rpow (x : ℝ) : (1 : ℝ≥0∞) ^ x = 1 := by
rw [← coe_one, ← coe_rpow_of_ne_zero one_ne_zero]
simp
@[simp]
theorem rpow_eq_zero_iff {x : ℝ≥0∞} {y : ℝ} : x ^ y = 0 ↔ x = 0 ∧ 0 < y ∨ x = ⊤ ∧ y < 0 := by
cases x with
| top =>
rcases lt_trichotomy y 0 with (H | H | H) <;>
simp [H, top_rpow_of_neg, top_rpow_of_pos, le_of_lt]
| coe x =>
by_cases h : x = 0
· rcases lt_trichotomy y 0 with (H | H | H) <;>
simp [h, H, zero_rpow_of_neg, zero_rpow_of_pos, le_of_lt]
· simp [← coe_rpow_of_ne_zero h, h]
lemma rpow_eq_zero_iff_of_pos {x : ℝ≥0∞} {y : ℝ} (hy : 0 < y) : x ^ y = 0 ↔ x = 0 := by
simp [hy, hy.not_lt]
@[simp]
theorem rpow_eq_top_iff {x : ℝ≥0∞} {y : ℝ} : x ^ y = ⊤ ↔ x = 0 ∧ y < 0 ∨ x = ⊤ ∧ 0 < y := by
cases x with
| top =>
rcases lt_trichotomy y 0 with (H | H | H) <;>
simp [H, top_rpow_of_neg, top_rpow_of_pos, le_of_lt]
| coe x =>
by_cases h : x = 0
· rcases lt_trichotomy y 0 with (H | H | H) <;>
simp [h, H, zero_rpow_of_neg, zero_rpow_of_pos, le_of_lt]
· simp [← coe_rpow_of_ne_zero h, h]
theorem rpow_eq_top_iff_of_pos {x : ℝ≥0∞} {y : ℝ} (hy : 0 < y) : x ^ y = ⊤ ↔ x = ⊤ := by
simp [rpow_eq_top_iff, hy, asymm hy]
lemma rpow_lt_top_iff_of_pos {x : ℝ≥0∞} {y : ℝ} (hy : 0 < y) : x ^ y < ∞ ↔ x < ∞ := by
simp only [lt_top_iff_ne_top, Ne, rpow_eq_top_iff_of_pos hy]
theorem rpow_eq_top_of_nonneg (x : ℝ≥0∞) {y : ℝ} (hy0 : 0 ≤ y) : x ^ y = ⊤ → x = ⊤ := by
rw [ENNReal.rpow_eq_top_iff]
rintro (h|h)
· exfalso
rw [lt_iff_not_ge] at h
exact h.right hy0
· exact h.left
theorem rpow_ne_top_of_nonneg {x : ℝ≥0∞} {y : ℝ} (hy0 : 0 ≤ y) (h : x ≠ ⊤) : x ^ y ≠ ⊤ :=
mt (ENNReal.rpow_eq_top_of_nonneg x hy0) h
theorem rpow_lt_top_of_nonneg {x : ℝ≥0∞} {y : ℝ} (hy0 : 0 ≤ y) (h : x ≠ ⊤) : x ^ y < ⊤ :=
lt_top_iff_ne_top.mpr (ENNReal.rpow_ne_top_of_nonneg hy0 h)
theorem rpow_add {x : ℝ≥0∞} (y z : ℝ) (hx : x ≠ 0) (h'x : x ≠ ⊤) : x ^ (y + z) = x ^ y * x ^ z := by
cases x with
| top => exact (h'x rfl).elim
| coe x =>
have : x ≠ 0 := fun h => by simp [h] at hx
simp [← coe_rpow_of_ne_zero this, NNReal.rpow_add this]
theorem rpow_add_of_nonneg {x : ℝ≥0∞} (y z : ℝ) (hy : 0 ≤ y) (hz : 0 ≤ z) :
x ^ (y + z) = x ^ y * x ^ z := by
induction x using recTopCoe
· rcases hy.eq_or_lt with rfl|hy
· rw [rpow_zero, one_mul, zero_add]
rcases hz.eq_or_lt with rfl|hz
· rw [rpow_zero, mul_one, add_zero]
simp [top_rpow_of_pos, hy, hz, add_pos hy hz]
simp [← coe_rpow_of_nonneg, hy, hz, add_nonneg hy hz, NNReal.rpow_add_of_nonneg _ hy hz]
theorem rpow_neg (x : ℝ≥0∞) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ := by
cases x with
| top =>
rcases lt_trichotomy y 0 with (H | H | H) <;>
simp [top_rpow_of_pos, top_rpow_of_neg, H, neg_pos.mpr]
| coe x =>
by_cases h : x = 0
· rcases lt_trichotomy y 0 with (H | H | H) <;>
simp [h, zero_rpow_of_pos, zero_rpow_of_neg, H, neg_pos.mpr]
· have A : x ^ y ≠ 0 := by simp [h]
simp [← coe_rpow_of_ne_zero h, ← coe_inv A, NNReal.rpow_neg]
theorem rpow_sub {x : ℝ≥0∞} (y z : ℝ) (hx : x ≠ 0) (h'x : x ≠ ⊤) : x ^ (y - z) = x ^ y / x ^ z := by
rw [sub_eq_add_neg, rpow_add _ _ hx h'x, rpow_neg, div_eq_mul_inv]
theorem rpow_neg_one (x : ℝ≥0∞) : x ^ (-1 : ℝ) = x⁻¹ := by simp [rpow_neg]
theorem rpow_mul (x : ℝ≥0∞) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z := by
cases x with
| top =>
rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;>
rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;>
simp [Hy, Hz, zero_rpow_of_neg, zero_rpow_of_pos, top_rpow_of_neg, top_rpow_of_pos,
mul_pos_of_neg_of_neg, mul_neg_of_neg_of_pos, mul_neg_of_pos_of_neg]
| coe x =>
by_cases h : x = 0
· rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;>
rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;>
simp [h, Hy, Hz, zero_rpow_of_neg, zero_rpow_of_pos, top_rpow_of_neg, top_rpow_of_pos,
mul_pos_of_neg_of_neg, mul_neg_of_neg_of_pos, mul_neg_of_pos_of_neg]
· have : x ^ y ≠ 0 := by simp [h]
simp [← coe_rpow_of_ne_zero, h, this, NNReal.rpow_mul]
@[simp, norm_cast]
theorem rpow_natCast (x : ℝ≥0∞) (n : ℕ) : x ^ (n : ℝ) = x ^ n := by
cases x
· cases n <;> simp [top_rpow_of_pos (Nat.cast_add_one_pos _), top_pow (Nat.succ_ne_zero _)]
· simp [← coe_rpow_of_nonneg _ (Nat.cast_nonneg n)]
@[simp]
lemma rpow_ofNat (x : ℝ≥0∞) (n : ℕ) [n.AtLeastTwo] :
x ^ (ofNat(n) : ℝ) = x ^ (OfNat.ofNat n) :=
rpow_natCast x n
@[simp, norm_cast]
lemma rpow_intCast (x : ℝ≥0∞) (n : ℤ) : x ^ (n : ℝ) = x ^ n := by
cases n <;> simp only [Int.ofNat_eq_coe, Int.cast_natCast, rpow_natCast, zpow_natCast,
Int.cast_negSucc, rpow_neg, zpow_negSucc]
theorem rpow_two (x : ℝ≥0∞) : x ^ (2 : ℝ) = x ^ 2 := rpow_ofNat x 2
theorem mul_rpow_eq_ite (x y : ℝ≥0∞) (z : ℝ) :
(x * y) ^ z = if (x = 0 ∧ y = ⊤ ∨ x = ⊤ ∧ y = 0) ∧ z < 0 then ⊤ else x ^ z * y ^ z := by
rcases eq_or_ne z 0 with (rfl | hz); · simp
replace hz := hz.lt_or_lt
wlog hxy : x ≤ y
· convert this y x z hz (le_of_not_le hxy) using 2 <;> simp only [mul_comm, and_comm, or_comm]
rcases eq_or_ne x 0 with (rfl | hx0)
· induction y <;> rcases hz with hz | hz <;> simp [*, hz.not_lt]
rcases eq_or_ne y 0 with (rfl | hy0)
· exact (hx0 (bot_unique hxy)).elim
induction x
· rcases hz with hz | hz <;> simp [hz, top_unique hxy]
induction y
· rw [ne_eq, coe_eq_zero] at hx0
rcases hz with hz | hz <;> simp [*]
simp only [*, if_false]
norm_cast at *
rw [← coe_rpow_of_ne_zero (mul_ne_zero hx0 hy0), NNReal.mul_rpow]
norm_cast
theorem mul_rpow_of_ne_top {x y : ℝ≥0∞} (hx : x ≠ ⊤) (hy : y ≠ ⊤) (z : ℝ) :
(x * y) ^ z = x ^ z * y ^ z := by simp [*, mul_rpow_eq_ite]
@[norm_cast]
theorem coe_mul_rpow (x y : ℝ≥0) (z : ℝ) : ((x : ℝ≥0∞) * y) ^ z = (x : ℝ≥0∞) ^ z * (y : ℝ≥0∞) ^ z :=
mul_rpow_of_ne_top coe_ne_top coe_ne_top z
theorem prod_coe_rpow {ι} (s : Finset ι) (f : ι → ℝ≥0) (r : ℝ) :
∏ i ∈ s, (f i : ℝ≥0∞) ^ r = ((∏ i ∈ s, f i : ℝ≥0) : ℝ≥0∞) ^ r := by
classical
induction s using Finset.induction with
| empty => simp
| insert _ _ hi ih => simp_rw [prod_insert hi, ih, ← coe_mul_rpow, coe_mul]
theorem mul_rpow_of_ne_zero {x y : ℝ≥0∞} (hx : x ≠ 0) (hy : y ≠ 0) (z : ℝ) :
(x * y) ^ z = x ^ z * y ^ z := by simp [*, mul_rpow_eq_ite]
theorem mul_rpow_of_nonneg (x y : ℝ≥0∞) {z : ℝ} (hz : 0 ≤ z) : (x * y) ^ z = x ^ z * y ^ z := by
simp [hz.not_lt, mul_rpow_eq_ite]
theorem prod_rpow_of_ne_top {ι} {s : Finset ι} {f : ι → ℝ≥0∞} (hf : ∀ i ∈ s, f i ≠ ∞) (r : ℝ) :
∏ i ∈ s, f i ^ r = (∏ i ∈ s, f i) ^ r := by
classical
induction s using Finset.induction with
| empty => simp
| insert i s hi ih =>
have h2f : ∀ i ∈ s, f i ≠ ∞ := fun i hi ↦ hf i <| mem_insert_of_mem hi
rw [prod_insert hi, prod_insert hi, ih h2f, ← mul_rpow_of_ne_top <| hf i <| mem_insert_self ..]
apply prod_ne_top h2f
theorem prod_rpow_of_nonneg {ι} {s : Finset ι} {f : ι → ℝ≥0∞} {r : ℝ} (hr : 0 ≤ r) :
∏ i ∈ s, f i ^ r = (∏ i ∈ s, f i) ^ r := by
classical
induction s using Finset.induction with
| empty => simp
| insert _ _ hi ih => simp_rw [prod_insert hi, ih, ← mul_rpow_of_nonneg _ _ hr]
theorem inv_rpow (x : ℝ≥0∞) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ := by
rcases eq_or_ne y 0 with (rfl | hy); · simp only [rpow_zero, inv_one]
replace hy := hy.lt_or_lt
rcases eq_or_ne x 0 with (rfl | h0); · cases hy <;> simp [*]
rcases eq_or_ne x ⊤ with (rfl | h_top); · cases hy <;> simp [*]
apply ENNReal.eq_inv_of_mul_eq_one_left
rw [← mul_rpow_of_ne_zero (ENNReal.inv_ne_zero.2 h_top) h0, ENNReal.inv_mul_cancel h0 h_top,
one_rpow]
theorem div_rpow_of_nonneg (x y : ℝ≥0∞) {z : ℝ} (hz : 0 ≤ z) : (x / y) ^ z = x ^ z / y ^ z := by
rw [div_eq_mul_inv, mul_rpow_of_nonneg _ _ hz, inv_rpow, div_eq_mul_inv]
theorem strictMono_rpow_of_pos {z : ℝ} (h : 0 < z) : StrictMono fun x : ℝ≥0∞ => x ^ z := by
intro x y hxy
lift x to ℝ≥0 using ne_top_of_lt hxy
rcases eq_or_ne y ∞ with (rfl | hy)
· simp only [top_rpow_of_pos h, ← coe_rpow_of_nonneg _ h.le, coe_lt_top]
· lift y to ℝ≥0 using hy
simp only [← coe_rpow_of_nonneg _ h.le, NNReal.rpow_lt_rpow (coe_lt_coe.1 hxy) h, coe_lt_coe]
theorem monotone_rpow_of_nonneg {z : ℝ} (h : 0 ≤ z) : Monotone fun x : ℝ≥0∞ => x ^ z :=
h.eq_or_lt.elim (fun h0 => h0 ▸ by simp only [rpow_zero, monotone_const]) fun h0 =>
(strictMono_rpow_of_pos h0).monotone
/-- Bundles `fun x : ℝ≥0∞ => x ^ y` into an order isomorphism when `y : ℝ` is positive,
where the inverse is `fun x : ℝ≥0∞ => x ^ (1 / y)`. -/
@[simps! apply]
def orderIsoRpow (y : ℝ) (hy : 0 < y) : ℝ≥0∞ ≃o ℝ≥0∞ :=
(strictMono_rpow_of_pos hy).orderIsoOfRightInverse (fun x => x ^ y) (fun x => x ^ (1 / y))
fun x => by
dsimp
rw [← rpow_mul, one_div_mul_cancel hy.ne.symm, rpow_one]
theorem orderIsoRpow_symm_apply (y : ℝ) (hy : 0 < y) :
(orderIsoRpow y hy).symm = orderIsoRpow (1 / y) (one_div_pos.2 hy) := by
simp only [orderIsoRpow, one_div_one_div]
rfl
@[gcongr] theorem rpow_le_rpow {x y : ℝ≥0∞} {z : ℝ} (h₁ : x ≤ y) (h₂ : 0 ≤ z) : x ^ z ≤ y ^ z :=
monotone_rpow_of_nonneg h₂ h₁
@[gcongr] theorem rpow_lt_rpow {x y : ℝ≥0∞} {z : ℝ} (h₁ : x < y) (h₂ : 0 < z) : x ^ z < y ^ z :=
strictMono_rpow_of_pos h₂ h₁
theorem rpow_le_rpow_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ^ z ≤ y ^ z ↔ x ≤ y :=
(strictMono_rpow_of_pos hz).le_iff_le
theorem rpow_lt_rpow_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ^ z < y ^ z ↔ x < y :=
(strictMono_rpow_of_pos hz).lt_iff_lt
theorem le_rpow_inv_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ≤ y ^ z⁻¹ ↔ x ^ z ≤ y := by
nth_rw 1 [← rpow_one x]
nth_rw 1 [← @mul_inv_cancel₀ _ _ z hz.ne']
rw [rpow_mul, @rpow_le_rpow_iff _ _ z⁻¹ (by simp [hz])]
theorem rpow_inv_lt_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ^ z⁻¹ < y ↔ x < y ^ z := by
simp only [← not_le, le_rpow_inv_iff hz]
theorem lt_rpow_inv_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x < y ^ z⁻¹ ↔ x ^ z < y := by
nth_rw 1 [← rpow_one x]
nth_rw 1 [← @mul_inv_cancel₀ _ _ z (ne_of_lt hz).symm]
rw [rpow_mul, @rpow_lt_rpow_iff _ _ z⁻¹ (by simp [hz])]
theorem rpow_inv_le_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ^ z⁻¹ ≤ y ↔ x ≤ y ^ z := by
nth_rw 1 [← ENNReal.rpow_one y]
nth_rw 1 [← @mul_inv_cancel₀ _ _ z hz.ne.symm]
rw [ENNReal.rpow_mul, ENNReal.rpow_le_rpow_iff (inv_pos.2 hz)]
theorem rpow_lt_rpow_of_exponent_lt {x : ℝ≥0∞} {y z : ℝ} (hx : 1 < x) (hx' : x ≠ ⊤) (hyz : y < z) :
x ^ y < x ^ z := by
lift x to ℝ≥0 using hx'
rw [one_lt_coe_iff] at hx
simp [← coe_rpow_of_ne_zero (ne_of_gt (lt_trans zero_lt_one hx)),
NNReal.rpow_lt_rpow_of_exponent_lt hx hyz]
@[gcongr] theorem rpow_le_rpow_of_exponent_le {x : ℝ≥0∞} {y z : ℝ} (hx : 1 ≤ x) (hyz : y ≤ z) :
x ^ y ≤ x ^ z := by
cases x
· rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;>
rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;>
simp [Hy, Hz, top_rpow_of_neg, top_rpow_of_pos, le_refl] <;>
linarith
· simp only [one_le_coe_iff, some_eq_coe] at hx
simp [← coe_rpow_of_ne_zero (ne_of_gt (lt_of_lt_of_le zero_lt_one hx)),
NNReal.rpow_le_rpow_of_exponent_le hx hyz]
theorem rpow_lt_rpow_of_exponent_gt {x : ℝ≥0∞} {y z : ℝ} (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) :
x ^ y < x ^ z := by
lift x to ℝ≥0 using ne_of_lt (lt_of_lt_of_le hx1 le_top)
simp only [coe_lt_one_iff, coe_pos] at hx0 hx1
simp [← coe_rpow_of_ne_zero (ne_of_gt hx0), NNReal.rpow_lt_rpow_of_exponent_gt hx0 hx1 hyz]
theorem rpow_le_rpow_of_exponent_ge {x : ℝ≥0∞} {y z : ℝ} (hx1 : x ≤ 1) (hyz : z ≤ y) :
x ^ y ≤ x ^ z := by
lift x to ℝ≥0 using ne_of_lt (lt_of_le_of_lt hx1 coe_lt_top)
by_cases h : x = 0
· rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;>
rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;>
simp [Hy, Hz, h, zero_rpow_of_neg, zero_rpow_of_pos, le_refl] <;>
linarith
· rw [coe_le_one_iff] at hx1
simp [← coe_rpow_of_ne_zero h,
NNReal.rpow_le_rpow_of_exponent_ge (bot_lt_iff_ne_bot.mpr h) hx1 hyz]
| Mathlib/Analysis/SpecialFunctions/Pow/NNReal.lean | 799 | 805 | theorem rpow_le_self_of_le_one {x : ℝ≥0∞} {z : ℝ} (hx : x ≤ 1) (h_one_le : 1 ≤ z) : x ^ z ≤ x := by | nth_rw 2 [← ENNReal.rpow_one x]
exact ENNReal.rpow_le_rpow_of_exponent_ge hx h_one_le
theorem le_rpow_self_of_one_le {x : ℝ≥0∞} {z : ℝ} (hx : 1 ≤ x) (h_one_le : 1 ≤ z) : x ≤ x ^ z := by
nth_rw 1 [← ENNReal.rpow_one x]
exact ENNReal.rpow_le_rpow_of_exponent_le hx h_one_le |
/-
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, Johan Commelin
-/
import Mathlib.Analysis.Analytic.Basic
import Mathlib.Combinatorics.Enumerative.Composition
/-!
# Composition of analytic functions
In this file we prove that the composition of analytic functions is analytic.
The argument is the following. Assume `g z = ∑' qₙ (z, ..., z)` and `f y = ∑' pₖ (y, ..., y)`. Then
`g (f y) = ∑' qₙ (∑' pₖ (y, ..., y), ..., ∑' pₖ (y, ..., y))
= ∑' qₙ (p_{i₁} (y, ..., y), ..., p_{iₙ} (y, ..., y))`.
For each `n` and `i₁, ..., iₙ`, define a `i₁ + ... + iₙ` multilinear function mapping
`(y₀, ..., y_{i₁ + ... + iₙ - 1})` to
`qₙ (p_{i₁} (y₀, ..., y_{i₁-1}), p_{i₂} (y_{i₁}, ..., y_{i₁ + i₂ - 1}), ..., p_{iₙ} (....)))`.
Then `g ∘ f` is obtained by summing all these multilinear functions.
To formalize this, we use compositions of an integer `N`, i.e., its decompositions into
a sum `i₁ + ... + iₙ` of positive integers. Given such a composition `c` and two formal
multilinear series `q` and `p`, let `q.compAlongComposition p c` be the above multilinear
function. Then the `N`-th coefficient in the power series expansion of `g ∘ f` is the sum of these
terms over all `c : Composition N`.
To complete the proof, we need to show that this power series has a positive radius of convergence.
This follows from the fact that `Composition N` has cardinality `2^(N-1)` and estimates on
the norm of `qₙ` and `pₖ`, which give summability. We also need to show that it indeed converges to
`g ∘ f`. For this, we note that the composition of partial sums converges to `g ∘ f`, and that it
corresponds to a part of the whole sum, on a subset that increases to the whole space. By
summability of the norms, this implies the overall convergence.
## Main results
* `q.comp p` is the formal composition of the formal multilinear series `q` and `p`.
* `HasFPowerSeriesAt.comp` states that if two functions `g` and `f` admit power series expansions
`q` and `p`, then `g ∘ f` admits a power series expansion given by `q.comp p`.
* `AnalyticAt.comp` states that the composition of analytic functions is analytic.
* `FormalMultilinearSeries.comp_assoc` states that composition is associative on formal
multilinear series.
## Implementation details
The main technical difficulty is to write down things. In particular, we need to define precisely
`q.compAlongComposition p c` and to show that it is indeed a continuous multilinear
function. This requires a whole interface built on the class `Composition`. Once this is set,
the main difficulty is to reorder the sums, writing the composition of the partial sums as a sum
over some subset of `Σ n, Composition n`. We need to check that the reordering is a bijection,
running over difficulties due to the dependent nature of the types under consideration, that are
controlled thanks to the interface for `Composition`.
The associativity of composition on formal multilinear series is a nontrivial result: it does not
follow from the associativity of composition of analytic functions, as there is no uniqueness for
the formal multilinear series representing a function (and also, it holds even when the radius of
convergence of the series is `0`). Instead, we give a direct proof, which amounts to reordering
double sums in a careful way. The change of variables is a canonical (combinatorial) bijection
`Composition.sigmaEquivSigmaPi` between `(Σ (a : Composition n), Composition a.length)` and
`(Σ (c : Composition n), Π (i : Fin c.length), Composition (c.blocksFun i))`, and is described
in more details below in the paragraph on associativity.
-/
noncomputable section
variable {𝕜 : Type*} {E F G H : Type*}
open Filter List
open scoped Topology NNReal ENNReal
section Topological
variable [CommRing 𝕜] [AddCommGroup E] [AddCommGroup F] [AddCommGroup G]
variable [Module 𝕜 E] [Module 𝕜 F] [Module 𝕜 G]
variable [TopologicalSpace E] [TopologicalSpace F] [TopologicalSpace G]
/-! ### Composing formal multilinear series -/
namespace FormalMultilinearSeries
variable [IsTopologicalAddGroup E] [ContinuousConstSMul 𝕜 E]
variable [IsTopologicalAddGroup F] [ContinuousConstSMul 𝕜 F]
variable [IsTopologicalAddGroup G] [ContinuousConstSMul 𝕜 G]
/-!
In this paragraph, we define the composition of formal multilinear series, by summing over all
possible compositions of `n`.
-/
/-- Given a formal multilinear series `p`, a composition `c` of `n` and the index `i` of a
block of `c`, we may define a function on `Fin n → E` by picking the variables in the `i`-th block
of `n`, and applying the corresponding coefficient of `p` to these variables. This function is
called `p.applyComposition c v i` for `v : Fin n → E` and `i : Fin c.length`. -/
def applyComposition (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (c : Composition n) :
(Fin n → E) → Fin c.length → F := fun v i => p (c.blocksFun i) (v ∘ c.embedding i)
theorem applyComposition_ones (p : FormalMultilinearSeries 𝕜 E F) (n : ℕ) :
p.applyComposition (Composition.ones n) = fun v i =>
p 1 fun _ => v (Fin.castLE (Composition.length_le _) i) := by
funext v i
apply p.congr (Composition.ones_blocksFun _ _)
intro j hjn hj1
obtain rfl : j = 0 := by omega
refine congr_arg v ?_
rw [Fin.ext_iff, Fin.coe_castLE, Composition.ones_embedding, Fin.val_mk]
theorem applyComposition_single (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (hn : 0 < n)
(v : Fin n → E) : p.applyComposition (Composition.single n hn) v = fun _j => p n v := by
ext j
refine p.congr (by simp) fun i hi1 hi2 => ?_
dsimp
congr 1
convert Composition.single_embedding hn ⟨i, hi2⟩ using 1
obtain ⟨j_val, j_property⟩ := j
have : j_val = 0 := le_bot_iff.1 (Nat.lt_succ_iff.1 j_property)
congr!
simp
@[simp]
theorem removeZero_applyComposition (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ}
(c : Composition n) : p.removeZero.applyComposition c = p.applyComposition c := by
ext v i
simp [applyComposition, zero_lt_one.trans_le (c.one_le_blocksFun i), removeZero_of_pos]
/-- Technical lemma stating how `p.applyComposition` commutes with updating variables. This
will be the key point to show that functions constructed from `applyComposition` retain
multilinearity. -/
theorem applyComposition_update (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (c : Composition n)
(j : Fin n) (v : Fin n → E) (z : E) :
p.applyComposition c (Function.update v j z) =
Function.update (p.applyComposition c v) (c.index j)
(p (c.blocksFun (c.index j))
(Function.update (v ∘ c.embedding (c.index j)) (c.invEmbedding j) z)) := by
ext k
by_cases h : k = c.index j
· rw [h]
let r : Fin (c.blocksFun (c.index j)) → Fin n := c.embedding (c.index j)
simp only [Function.update_self]
change p (c.blocksFun (c.index j)) (Function.update v j z ∘ r) = _
let j' := c.invEmbedding j
suffices B : Function.update v j z ∘ r = Function.update (v ∘ r) j' z by rw [B]
suffices C : Function.update v (r j') z ∘ r = Function.update (v ∘ r) j' z by
convert C; exact (c.embedding_comp_inv j).symm
exact Function.update_comp_eq_of_injective _ (c.embedding _).injective _ _
· simp only [h, Function.update_eq_self, Function.update_of_ne, Ne, not_false_iff]
let r : Fin (c.blocksFun k) → Fin n := c.embedding k
change p (c.blocksFun k) (Function.update v j z ∘ r) = p (c.blocksFun k) (v ∘ r)
suffices B : Function.update v j z ∘ r = v ∘ r by rw [B]
apply Function.update_comp_eq_of_not_mem_range
rwa [c.mem_range_embedding_iff']
@[simp]
theorem compContinuousLinearMap_applyComposition {n : ℕ} (p : FormalMultilinearSeries 𝕜 F G)
(f : E →L[𝕜] F) (c : Composition n) (v : Fin n → E) :
(p.compContinuousLinearMap f).applyComposition c v = p.applyComposition c (f ∘ v) := by
simp (config := {unfoldPartialApp := true}) [applyComposition]; rfl
end FormalMultilinearSeries
namespace ContinuousMultilinearMap
open FormalMultilinearSeries
variable [IsTopologicalAddGroup E] [ContinuousConstSMul 𝕜 E]
variable [IsTopologicalAddGroup F] [ContinuousConstSMul 𝕜 F]
/-- Given a formal multilinear series `p`, a composition `c` of `n` and a continuous multilinear
map `f` in `c.length` variables, one may form a continuous multilinear map in `n` variables by
applying the right coefficient of `p` to each block of the composition, and then applying `f` to
the resulting vector. It is called `f.compAlongComposition p c`. -/
def compAlongComposition {n : ℕ} (p : FormalMultilinearSeries 𝕜 E F) (c : Composition n)
(f : F [×c.length]→L[𝕜] G) : E [×n]→L[𝕜] G where
toMultilinearMap :=
MultilinearMap.mk' (fun v ↦ f (p.applyComposition c v))
(fun v i x y ↦ by simp only [applyComposition_update, map_update_add])
(fun v i c x ↦ by simp only [applyComposition_update, map_update_smul])
cont :=
f.cont.comp <|
continuous_pi fun _ => (coe_continuous _).comp <| continuous_pi fun _ => continuous_apply _
@[simp]
theorem compAlongComposition_apply {n : ℕ} (p : FormalMultilinearSeries 𝕜 E F) (c : Composition n)
(f : F [×c.length]→L[𝕜] G) (v : Fin n → E) :
(f.compAlongComposition p c) v = f (p.applyComposition c v) :=
rfl
end ContinuousMultilinearMap
namespace FormalMultilinearSeries
variable [IsTopologicalAddGroup E] [ContinuousConstSMul 𝕜 E]
variable [IsTopologicalAddGroup F] [ContinuousConstSMul 𝕜 F]
variable [IsTopologicalAddGroup G] [ContinuousConstSMul 𝕜 G]
/-- Given two formal multilinear series `q` and `p` and a composition `c` of `n`, one may
form a continuous multilinear map in `n` variables by applying the right coefficient of `p` to each
block of the composition, and then applying `q c.length` to the resulting vector. It is
called `q.compAlongComposition p c`. -/
def compAlongComposition {n : ℕ} (q : FormalMultilinearSeries 𝕜 F G)
(p : FormalMultilinearSeries 𝕜 E F) (c : Composition n) : (E [×n]→L[𝕜] G) :=
(q c.length).compAlongComposition p c
@[simp]
theorem compAlongComposition_apply {n : ℕ} (q : FormalMultilinearSeries 𝕜 F G)
(p : FormalMultilinearSeries 𝕜 E F) (c : Composition n) (v : Fin n → E) :
(q.compAlongComposition p c) v = q c.length (p.applyComposition c v) :=
rfl
/-- Formal composition of two formal multilinear series. The `n`-th coefficient in the composition
is defined to be the sum of `q.compAlongComposition p c` over all compositions of
`n`. In other words, this term (as a multilinear function applied to `v_0, ..., v_{n-1}`) is
`∑'_{k} ∑'_{i₁ + ... + iₖ = n} qₖ (p_{i_1} (...), ..., p_{i_k} (...))`, where one puts all variables
`v_0, ..., v_{n-1}` in increasing order in the dots.
In general, the composition `q ∘ p` only makes sense when the constant coefficient of `p` vanishes.
We give a general formula but which ignores the value of `p 0` instead.
-/
protected def comp (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) :
FormalMultilinearSeries 𝕜 E G := fun n => ∑ c : Composition n, q.compAlongComposition p c
/-- The `0`-th coefficient of `q.comp p` is `q 0`. Since these maps are multilinear maps in zero
variables, but on different spaces, we can not state this directly, so we state it when applied to
arbitrary vectors (which have to be the zero vector). -/
theorem comp_coeff_zero (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F)
(v : Fin 0 → E) (v' : Fin 0 → F) : (q.comp p) 0 v = q 0 v' := by
let c : Composition 0 := Composition.ones 0
dsimp [FormalMultilinearSeries.comp]
have : {c} = (Finset.univ : Finset (Composition 0)) := by
apply Finset.eq_of_subset_of_card_le <;> simp [Finset.card_univ, composition_card 0]
rw [← this, Finset.sum_singleton, compAlongComposition_apply]
symm; congr! -- Porting note: needed the stronger `congr!`!
@[simp]
theorem comp_coeff_zero' (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F)
(v : Fin 0 → E) : (q.comp p) 0 v = q 0 fun _i => 0 :=
q.comp_coeff_zero p v _
/-- The `0`-th coefficient of `q.comp p` is `q 0`. When `p` goes from `E` to `E`, this can be
expressed as a direct equality -/
theorem comp_coeff_zero'' (q : FormalMultilinearSeries 𝕜 E F) (p : FormalMultilinearSeries 𝕜 E E) :
(q.comp p) 0 = q 0 := by ext v; exact q.comp_coeff_zero p _ _
/-- The first coefficient of a composition of formal multilinear series is the composition of the
first coefficients seen as continuous linear maps. -/
theorem comp_coeff_one (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F)
(v : Fin 1 → E) : (q.comp p) 1 v = q 1 fun _i => p 1 v := by
have : {Composition.ones 1} = (Finset.univ : Finset (Composition 1)) :=
Finset.eq_univ_of_card _ (by simp [composition_card])
simp only [FormalMultilinearSeries.comp, compAlongComposition_apply, ← this,
Finset.sum_singleton]
refine q.congr (by simp) fun i hi1 hi2 => ?_
simp only [applyComposition_ones]
exact p.congr rfl fun j _hj1 hj2 => by congr! -- Porting note: needed the stronger `congr!`
/-- Only `0`-th coefficient of `q.comp p` depends on `q 0`. -/
theorem removeZero_comp_of_pos (q : FormalMultilinearSeries 𝕜 F G)
(p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (hn : 0 < n) :
q.removeZero.comp p n = q.comp p n := by
ext v
simp only [FormalMultilinearSeries.comp, compAlongComposition,
ContinuousMultilinearMap.compAlongComposition_apply, ContinuousMultilinearMap.sum_apply]
refine Finset.sum_congr rfl fun c _hc => ?_
rw [removeZero_of_pos _ (c.length_pos_of_pos hn)]
@[simp]
theorem comp_removeZero (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F) :
q.comp p.removeZero = q.comp p := by ext n; simp [FormalMultilinearSeries.comp]
end FormalMultilinearSeries
end Topological
variable [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F]
[NormedSpace 𝕜 F] [NormedAddCommGroup G] [NormedSpace 𝕜 G] [NormedAddCommGroup H]
[NormedSpace 𝕜 H]
namespace FormalMultilinearSeries
/-- The norm of `f.compAlongComposition p c` is controlled by the product of
the norms of the relevant bits of `f` and `p`. -/
theorem compAlongComposition_bound {n : ℕ} (p : FormalMultilinearSeries 𝕜 E F) (c : Composition n)
(f : F [×c.length]→L[𝕜] G) (v : Fin n → E) :
‖f.compAlongComposition p c v‖ ≤ (‖f‖ * ∏ i, ‖p (c.blocksFun i)‖) * ∏ i : Fin n, ‖v i‖ :=
calc
‖f.compAlongComposition p c v‖ = ‖f (p.applyComposition c v)‖ := rfl
_ ≤ ‖f‖ * ∏ i, ‖p.applyComposition c v i‖ := ContinuousMultilinearMap.le_opNorm _ _
_ ≤ ‖f‖ * ∏ i, ‖p (c.blocksFun i)‖ * ∏ j : Fin (c.blocksFun i), ‖(v ∘ c.embedding i) j‖ := by
apply mul_le_mul_of_nonneg_left _ (norm_nonneg _)
refine Finset.prod_le_prod (fun i _hi => norm_nonneg _) fun i _hi => ?_
apply ContinuousMultilinearMap.le_opNorm
_ = (‖f‖ * ∏ i, ‖p (c.blocksFun i)‖) *
∏ i, ∏ j : Fin (c.blocksFun i), ‖(v ∘ c.embedding i) j‖ := by
rw [Finset.prod_mul_distrib, mul_assoc]
_ = (‖f‖ * ∏ i, ‖p (c.blocksFun i)‖) * ∏ i : Fin n, ‖v i‖ := by
rw [← c.blocksFinEquiv.prod_comp, ← Finset.univ_sigma_univ, Finset.prod_sigma]
congr
/-- The norm of `q.compAlongComposition p c` is controlled by the product of
the norms of the relevant bits of `q` and `p`. -/
theorem compAlongComposition_norm {n : ℕ} (q : FormalMultilinearSeries 𝕜 F G)
(p : FormalMultilinearSeries 𝕜 E F) (c : Composition n) :
‖q.compAlongComposition p c‖ ≤ ‖q c.length‖ * ∏ i, ‖p (c.blocksFun i)‖ :=
ContinuousMultilinearMap.opNorm_le_bound (by positivity) (compAlongComposition_bound _ _ _)
theorem compAlongComposition_nnnorm {n : ℕ} (q : FormalMultilinearSeries 𝕜 F G)
(p : FormalMultilinearSeries 𝕜 E F) (c : Composition n) :
‖q.compAlongComposition p c‖₊ ≤ ‖q c.length‖₊ * ∏ i, ‖p (c.blocksFun i)‖₊ := by
rw [← NNReal.coe_le_coe]; push_cast; exact q.compAlongComposition_norm p c
/-!
### The identity formal power series
We will now define the identity power series, and show that it is a neutral element for left and
right composition.
-/
section
variable (𝕜 E)
/-- The identity formal multilinear series, with all coefficients equal to `0` except for `n = 1`
where it is (the continuous multilinear version of) the identity. We allow an arbitrary
constant coefficient `x`. -/
def id (x : E) : FormalMultilinearSeries 𝕜 E E
| 0 => ContinuousMultilinearMap.uncurry0 𝕜 _ x
| 1 => (continuousMultilinearCurryFin1 𝕜 E E).symm (ContinuousLinearMap.id 𝕜 E)
| _ => 0
@[simp] theorem id_apply_zero (x : E) (v : Fin 0 → E) :
(FormalMultilinearSeries.id 𝕜 E x) 0 v = x := rfl
/-- The first coefficient of `id 𝕜 E` is the identity. -/
@[simp]
theorem id_apply_one (x : E) (v : Fin 1 → E) : (FormalMultilinearSeries.id 𝕜 E x) 1 v = v 0 :=
rfl
/-- The `n`th coefficient of `id 𝕜 E` is the identity when `n = 1`. We state this in a dependent
way, as it will often appear in this form. -/
theorem id_apply_one' (x : E) {n : ℕ} (h : n = 1) (v : Fin n → E) :
(id 𝕜 E x) n v = v ⟨0, h.symm ▸ zero_lt_one⟩ := by
subst n
apply id_apply_one
/-- For `n ≠ 1`, the `n`-th coefficient of `id 𝕜 E` is zero, by definition. -/
@[simp]
theorem id_apply_of_one_lt (x : E) {n : ℕ} (h : 1 < n) :
(FormalMultilinearSeries.id 𝕜 E x) n = 0 := by
match n with
| 0 => contradiction
| 1 => contradiction
| n + 2 => rfl
end
@[simp]
theorem comp_id (p : FormalMultilinearSeries 𝕜 E F) (x : E) : p.comp (id 𝕜 E x) = p := by
ext1 n
dsimp [FormalMultilinearSeries.comp]
rw [Finset.sum_eq_single (Composition.ones n)]
· show compAlongComposition p (id 𝕜 E x) (Composition.ones n) = p n
ext v
rw [compAlongComposition_apply]
apply p.congr (Composition.ones_length n)
intros
rw [applyComposition_ones]
refine congr_arg v ?_
rw [Fin.ext_iff, Fin.coe_castLE, Fin.val_mk]
· show
∀ b : Composition n,
b ∈ Finset.univ → b ≠ Composition.ones n → compAlongComposition p (id 𝕜 E x) b = 0
intro b _ hb
obtain ⟨k, hk, lt_k⟩ : ∃ (k : ℕ), k ∈ Composition.blocks b ∧ 1 < k :=
Composition.ne_ones_iff.1 hb
obtain ⟨i, hi⟩ : ∃ (i : Fin b.blocks.length), b.blocks[i] = k :=
List.get_of_mem hk
let j : Fin b.length := ⟨i.val, b.blocks_length ▸ i.prop⟩
have A : 1 < b.blocksFun j := by convert lt_k
ext v
rw [compAlongComposition_apply, ContinuousMultilinearMap.zero_apply]
apply ContinuousMultilinearMap.map_coord_zero _ j
dsimp [applyComposition]
rw [id_apply_of_one_lt _ _ _ A, ContinuousMultilinearMap.zero_apply]
· simp
@[simp]
theorem id_comp (p : FormalMultilinearSeries 𝕜 E F) (v0 : Fin 0 → E) :
(id 𝕜 F (p 0 v0)).comp p = p := by
ext1 n
obtain rfl | n_pos := n.eq_zero_or_pos
· ext v
simp only [comp_coeff_zero', id_apply_zero]
congr with i
exact i.elim0
· dsimp [FormalMultilinearSeries.comp]
rw [Finset.sum_eq_single (Composition.single n n_pos)]
· show compAlongComposition (id 𝕜 F (p 0 v0)) p (Composition.single n n_pos) = p n
ext v
rw [compAlongComposition_apply, id_apply_one' _ _ _ (Composition.single_length n_pos)]
dsimp [applyComposition]
refine p.congr rfl fun i him hin => congr_arg v <| ?_
ext; simp
· show
∀ b : Composition n, b ∈ Finset.univ → b ≠ Composition.single n n_pos →
compAlongComposition (id 𝕜 F (p 0 v0)) p b = 0
intro b _ hb
have A : 1 < b.length := by
have : b.length ≠ 1 := by simpa [Composition.eq_single_iff_length] using hb
have : 0 < b.length := Composition.length_pos_of_pos b n_pos
omega
ext v
rw [compAlongComposition_apply, id_apply_of_one_lt _ _ _ A,
ContinuousMultilinearMap.zero_apply, ContinuousMultilinearMap.zero_apply]
· simp
/-- Variant of `id_comp` in which the zero coefficient is given by an equality hypothesis instead
of a definitional equality. Useful for rewriting or simplifying out in some situations. -/
theorem id_comp' (p : FormalMultilinearSeries 𝕜 E F) (x : F) (v0 : Fin 0 → E) (h : x = p 0 v0) :
(id 𝕜 F x).comp p = p := by
simp [h]
/-! ### Summability properties of the composition of formal power series -/
section
/-- If two formal multilinear series have positive radius of convergence, then the terms appearing
in the definition of their composition are also summable (when multiplied by a suitable positive
geometric term). -/
theorem comp_summable_nnreal (q : FormalMultilinearSeries 𝕜 F G) (p : FormalMultilinearSeries 𝕜 E F)
(hq : 0 < q.radius) (hp : 0 < p.radius) :
∃ r > (0 : ℝ≥0),
Summable fun i : Σ n, Composition n => ‖q.compAlongComposition p i.2‖₊ * r ^ i.1 := by
/- This follows from the fact that the growth rate of `‖qₙ‖` and `‖pₙ‖` is at most geometric,
giving a geometric bound on each `‖q.compAlongComposition p op‖`, together with the
fact that there are `2^(n-1)` compositions of `n`, giving at most a geometric loss. -/
rcases ENNReal.lt_iff_exists_nnreal_btwn.1 (lt_min zero_lt_one hq) with ⟨rq, rq_pos, hrq⟩
rcases ENNReal.lt_iff_exists_nnreal_btwn.1 (lt_min zero_lt_one hp) with ⟨rp, rp_pos, hrp⟩
simp only [lt_min_iff, ENNReal.coe_lt_one_iff, ENNReal.coe_pos] at hrp hrq rp_pos rq_pos
obtain ⟨Cq, _hCq0, hCq⟩ : ∃ Cq > 0, ∀ n, ‖q n‖₊ * rq ^ n ≤ Cq :=
q.nnnorm_mul_pow_le_of_lt_radius hrq.2
obtain ⟨Cp, hCp1, hCp⟩ : ∃ Cp ≥ 1, ∀ n, ‖p n‖₊ * rp ^ n ≤ Cp := by
rcases p.nnnorm_mul_pow_le_of_lt_radius hrp.2 with ⟨Cp, -, hCp⟩
exact ⟨max Cp 1, le_max_right _ _, fun n => (hCp n).trans (le_max_left _ _)⟩
let r0 : ℝ≥0 := (4 * Cp)⁻¹
have r0_pos : 0 < r0 := inv_pos.2 (mul_pos zero_lt_four (zero_lt_one.trans_le hCp1))
set r : ℝ≥0 := rp * rq * r0
have r_pos : 0 < r := mul_pos (mul_pos rp_pos rq_pos) r0_pos
have I :
∀ i : Σ n : ℕ, Composition n, ‖q.compAlongComposition p i.2‖₊ * r ^ i.1 ≤ Cq / 4 ^ i.1 := by
rintro ⟨n, c⟩
have A := calc
‖q c.length‖₊ * rq ^ n ≤ ‖q c.length‖₊ * rq ^ c.length :=
mul_le_mul' le_rfl (pow_le_pow_of_le_one rq.2 hrq.1.le c.length_le)
_ ≤ Cq := hCq _
have B := calc
(∏ i, ‖p (c.blocksFun i)‖₊) * rp ^ n = ∏ i, ‖p (c.blocksFun i)‖₊ * rp ^ c.blocksFun i := by
simp only [Finset.prod_mul_distrib, Finset.prod_pow_eq_pow_sum, c.sum_blocksFun]
_ ≤ ∏ _i : Fin c.length, Cp := Finset.prod_le_prod' fun i _ => hCp _
_ = Cp ^ c.length := by simp
_ ≤ Cp ^ n := pow_right_mono₀ hCp1 c.length_le
calc
‖q.compAlongComposition p c‖₊ * r ^ n ≤
(‖q c.length‖₊ * ∏ i, ‖p (c.blocksFun i)‖₊) * r ^ n :=
mul_le_mul' (q.compAlongComposition_nnnorm p c) le_rfl
_ = ‖q c.length‖₊ * rq ^ n * ((∏ i, ‖p (c.blocksFun i)‖₊) * rp ^ n) * r0 ^ n := by
ring
_ ≤ Cq * Cp ^ n * r0 ^ n := mul_le_mul' (mul_le_mul' A B) le_rfl
_ = Cq / 4 ^ n := by
simp only [r0]
field_simp [mul_pow, (zero_lt_one.trans_le hCp1).ne']
ring
refine ⟨r, r_pos, NNReal.summable_of_le I ?_⟩
simp_rw [div_eq_mul_inv]
refine Summable.mul_left _ ?_
have : ∀ n : ℕ, HasSum (fun c : Composition n => (4 ^ n : ℝ≥0)⁻¹) (2 ^ (n - 1) / 4 ^ n) := by
intro n
convert hasSum_fintype fun c : Composition n => (4 ^ n : ℝ≥0)⁻¹
simp [Finset.card_univ, composition_card, div_eq_mul_inv]
refine NNReal.summable_sigma.2 ⟨fun n => (this n).summable, (NNReal.summable_nat_add_iff 1).1 ?_⟩
convert (NNReal.summable_geometric (NNReal.div_lt_one_of_lt one_lt_two)).mul_left (1 / 4) using 1
ext1 n
rw [(this _).tsum_eq, add_tsub_cancel_right]
field_simp [← mul_assoc, pow_succ, mul_pow, show (4 : ℝ≥0) = 2 * 2 by norm_num,
mul_right_comm]
end
/-- Bounding below the radius of the composition of two formal multilinear series assuming
summability over all compositions. -/
theorem le_comp_radius_of_summable (q : FormalMultilinearSeries 𝕜 F G)
(p : FormalMultilinearSeries 𝕜 E F) (r : ℝ≥0)
(hr : Summable fun i : Σ n, Composition n => ‖q.compAlongComposition p i.2‖₊ * r ^ i.1) :
(r : ℝ≥0∞) ≤ (q.comp p).radius := by
refine
le_radius_of_bound_nnreal _
(∑' i : Σ n, Composition n, ‖compAlongComposition q p i.snd‖₊ * r ^ i.fst) fun n => ?_
calc
‖FormalMultilinearSeries.comp q p n‖₊ * r ^ n ≤
∑' c : Composition n, ‖compAlongComposition q p c‖₊ * r ^ n := by
rw [tsum_fintype, ← Finset.sum_mul]
exact mul_le_mul' (nnnorm_sum_le _ _) le_rfl
_ ≤ ∑' i : Σ n : ℕ, Composition n, ‖compAlongComposition q p i.snd‖₊ * r ^ i.fst :=
NNReal.tsum_comp_le_tsum_of_inj hr sigma_mk_injective
/-!
### Composing analytic functions
Now, we will prove that the composition of the partial sums of `q` and `p` up to order `N` is
given by a sum over some large subset of `Σ n, Composition n` of `q.compAlongComposition p`, to
deduce that the series for `q.comp p` indeed converges to `g ∘ f` when `q` is a power series for
`g` and `p` is a power series for `f`.
This proof is a big reindexing argument of a sum. Since it is a bit involved, we define first
the source of the change of variables (`compPartialSumSource`), its target
(`compPartialSumTarget`) and the change of variables itself (`compChangeOfVariables`) before
giving the main statement in `comp_partialSum`. -/
/-- Source set in the change of variables to compute the composition of partial sums of formal
power series.
See also `comp_partialSum`. -/
def compPartialSumSource (m M N : ℕ) : Finset (Σ n, Fin n → ℕ) :=
Finset.sigma (Finset.Ico m M) (fun n : ℕ => Fintype.piFinset fun _i : Fin n => Finset.Ico 1 N :)
@[simp]
theorem mem_compPartialSumSource_iff (m M N : ℕ) (i : Σ n, Fin n → ℕ) :
i ∈ compPartialSumSource m M N ↔
(m ≤ i.1 ∧ i.1 < M) ∧ ∀ a : Fin i.1, 1 ≤ i.2 a ∧ i.2 a < N := by
simp only [compPartialSumSource, Finset.mem_Ico, Fintype.mem_piFinset, Finset.mem_sigma]
/-- Change of variables appearing to compute the composition of partial sums of formal
power series -/
def compChangeOfVariables (m M N : ℕ) (i : Σ n, Fin n → ℕ) (hi : i ∈ compPartialSumSource m M N) :
Σ n, Composition n := by
rcases i with ⟨n, f⟩
rw [mem_compPartialSumSource_iff] at hi
refine ⟨∑ j, f j, ofFn fun a => f a, fun {i} hi' => ?_, by simp [sum_ofFn]⟩
obtain ⟨j, rfl⟩ : ∃ j : Fin n, f j = i := by rwa [mem_ofFn', Set.mem_range] at hi'
exact (hi.2 j).1
@[simp]
theorem compChangeOfVariables_length (m M N : ℕ) {i : Σ n, Fin n → ℕ}
(hi : i ∈ compPartialSumSource m M N) :
Composition.length (compChangeOfVariables m M N i hi).2 = i.1 := by
rcases i with ⟨k, blocks_fun⟩
dsimp [compChangeOfVariables]
simp only [Composition.length, map_ofFn, length_ofFn]
theorem compChangeOfVariables_blocksFun (m M N : ℕ) {i : Σ n, Fin n → ℕ}
(hi : i ∈ compPartialSumSource m M N) (j : Fin i.1) :
(compChangeOfVariables m M N i hi).2.blocksFun
⟨j, (compChangeOfVariables_length m M N hi).symm ▸ j.2⟩ =
i.2 j := by
rcases i with ⟨n, f⟩
dsimp [Composition.blocksFun, Composition.blocks, compChangeOfVariables]
simp only [map_ofFn, List.getElem_ofFn, Function.comp_apply]
/-- Target set in the change of variables to compute the composition of partial sums of formal
power series, here given a a set. -/
def compPartialSumTargetSet (m M N : ℕ) : Set (Σ n, Composition n) :=
{i | m ≤ i.2.length ∧ i.2.length < M ∧ ∀ j : Fin i.2.length, i.2.blocksFun j < N}
theorem compPartialSumTargetSet_image_compPartialSumSource (m M N : ℕ)
(i : Σ n, Composition n) (hi : i ∈ compPartialSumTargetSet m M N) :
∃ (j : _) (hj : j ∈ compPartialSumSource m M N), compChangeOfVariables m M N j hj = i := by
rcases i with ⟨n, c⟩
refine ⟨⟨c.length, c.blocksFun⟩, ?_, ?_⟩
· simp only [compPartialSumTargetSet, Set.mem_setOf_eq] at hi
simp only [mem_compPartialSumSource_iff, hi.left, hi.right, true_and, and_true]
exact fun a => c.one_le_blocks' _
· dsimp [compChangeOfVariables]
rw [Composition.sigma_eq_iff_blocks_eq]
simp only [Composition.blocksFun, Composition.blocks, Subtype.coe_eta]
conv_rhs => rw [← List.ofFn_get c.blocks]
/-- Target set in the change of variables to compute the composition of partial sums of formal
power series, here given a a finset.
See also `comp_partialSum`. -/
def compPartialSumTarget (m M N : ℕ) : Finset (Σ n, Composition n) :=
Set.Finite.toFinset <|
((Finset.finite_toSet _).dependent_image _).subset <|
compPartialSumTargetSet_image_compPartialSumSource m M N
@[simp]
theorem mem_compPartialSumTarget_iff {m M N : ℕ} {a : Σ n, Composition n} :
a ∈ compPartialSumTarget m M N ↔
m ≤ a.2.length ∧ a.2.length < M ∧ ∀ j : Fin a.2.length, a.2.blocksFun j < N := by
simp [compPartialSumTarget, compPartialSumTargetSet]
/-- `compChangeOfVariables m M N` is a bijection between `compPartialSumSource m M N`
and `compPartialSumTarget m M N`, yielding equal sums for functions that correspond to each
other under the bijection. As `compChangeOfVariables m M N` is a dependent function, stating
that it is a bijection is not directly possible, but the consequence on sums can be stated
more easily. -/
| Mathlib/Analysis/Analytic/Composition.lean | 602 | 613 | theorem compChangeOfVariables_sum {α : Type*} [AddCommMonoid α] (m M N : ℕ)
(f : (Σ n : ℕ, Fin n → ℕ) → α) (g : (Σ n, Composition n) → α)
(h : ∀ (e) (he : e ∈ compPartialSumSource m M N), f e = g (compChangeOfVariables m M N e he)) :
∑ e ∈ compPartialSumSource m M N, f e = ∑ e ∈ compPartialSumTarget m M N, g e := by | apply Finset.sum_bij (compChangeOfVariables m M N)
-- We should show that the correspondence we have set up is indeed a bijection
-- between the index sets of the two sums.
-- 1 - show that the image belongs to `compPartialSumTarget m N N`
· rintro ⟨k, blocks_fun⟩ H
rw [mem_compPartialSumSource_iff] at H
simp only [mem_compPartialSumTarget_iff, Composition.length, Composition.blocks, H.left,
map_ofFn, length_ofFn, true_and, compChangeOfVariables] |
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Kim Morrison
-/
import Mathlib.Tactic.NormNum.Basic
import Mathlib.Tactic.TryThis
import Mathlib.Util.AtomM
/-!
# The `abel` tactic
Evaluate expressions in the language of additive, commutative monoids and groups.
-/
-- TODO: assert_not_exists NonUnitalNonAssociativeSemiring
assert_not_exists OrderedAddCommMonoid TopologicalSpace PseudoMetricSpace
namespace Mathlib.Tactic.Abel
open Lean Elab Meta Tactic Qq
initialize registerTraceClass `abel
initialize registerTraceClass `abel.detail
/--
Tactic for evaluating equations in the language of
*additive*, commutative monoids and groups.
`abel` and its variants work as both tactics and conv tactics.
* `abel1` fails if the target is not an equality that is provable by the axioms of
commutative monoids/groups.
* `abel_nf` rewrites all group expressions into a normal form.
* In tactic mode, `abel_nf at h` can be used to rewrite in a hypothesis.
* `abel_nf (config := cfg)` allows for additional configuration:
* `red`: the reducibility setting (overridden by `!`)
* `zetaDelta`: if true, local let variables can be unfolded (overridden by `!`)
* `recursive`: if true, `abel_nf` will also recurse into atoms
* `abel!`, `abel1!`, `abel_nf!` will use a more aggressive reducibility setting to identify atoms.
For example:
```
example [AddCommMonoid α] (a b : α) : a + (b + a) = a + a + b := by abel
example [AddCommGroup α] (a : α) : (3 : ℤ) • a = a + (2 : ℤ) • a := by abel
```
## Future work
* In mathlib 3, `abel` accepted additional optional arguments:
```
syntax "abel" (&" raw" <|> &" term")? (location)? : tactic
```
It is undecided whether these features should be restored eventually.
-/
syntax (name := abel) "abel" "!"? : tactic
/-- The `Context` for a call to `abel`.
Stores a few options for this call, and caches some common subexpressions
such as typeclass instances and `0 : α`.
-/
structure Context where
/-- The type of the ambient additive commutative group or monoid. -/
α : Expr
/-- The universe level for `α`. -/
univ : Level
/-- The expression representing `0 : α`. -/
α0 : Expr
/-- Specify whether we are in an additive commutative group or an additive commutative monoid. -/
isGroup : Bool
/-- The `AddCommGroup α` or `AddCommMonoid α` expression. -/
inst : Expr
/-- Populate a `context` object for evaluating `e`. -/
def mkContext (e : Expr) : MetaM Context := do
let α ← inferType e
let c ← synthInstance (← mkAppM ``AddCommMonoid #[α])
let cg ← synthInstance? (← mkAppM ``AddCommGroup #[α])
let u ← mkFreshLevelMVar
_ ← isDefEq (.sort (.succ u)) (← inferType α)
let α0 ← Expr.ofNat α 0
match cg with
| some cg => return ⟨α, u, α0, true, cg⟩
| _ => return ⟨α, u, α0, false, c⟩
/-- The monad for `Abel` contains, in addition to the `AtomM` state,
some information about the current type we are working over, so that we can consistently
use group lemmas or monoid lemmas as appropriate. -/
abbrev M := ReaderT Context AtomM
/-- Apply the function `n : ∀ {α} [inst : AddWhatever α], _` to the
implicit parameters in the context, and the given list of arguments. -/
def Context.app (c : Context) (n : Name) (inst : Expr) : Array Expr → Expr :=
mkAppN (((@Expr.const n [c.univ]).app c.α).app inst)
/-- Apply the function `n : ∀ {α} [inst α], _` to the implicit parameters in the
context, and the given list of arguments.
Compared to `context.app`, this takes the name of the typeclass, rather than an
inferred typeclass instance.
-/
def Context.mkApp (c : Context) (n inst : Name) (l : Array Expr) : MetaM Expr := do
return c.app n (← synthInstance ((Expr.const inst [c.univ]).app c.α)) l
/-- Add the letter "g" to the end of the name, e.g. turning `term` into `termg`.
This is used to choose between declarations taking `AddCommMonoid` and those
taking `AddCommGroup` instances.
-/
def addG : Name → Name
| .str p s => .str p (s ++ "g")
| n => n
/-- Apply the function `n : ∀ {α} [AddComm{Monoid,Group} α]` to the given list of arguments.
Will use the `AddComm{Monoid,Group}` instance that has been cached in the context.
-/
def iapp (n : Name) (xs : Array Expr) : M Expr := do
let c ← read
return c.app (if c.isGroup then addG n else n) c.inst xs
/-- A type synonym used by `abel` to represent `n • x + a` in an additive commutative monoid. -/
def term {α} [AddCommMonoid α] (n : ℕ) (x a : α) : α := n • x + a
/-- A type synonym used by `abel` to represent `n • x + a` in an additive commutative group. -/
def termg {α} [AddCommGroup α] (n : ℤ) (x a : α) : α := n • x + a
/-- Evaluate a term with coefficient `n`, atom `x` and successor terms `a`. -/
def mkTerm (n x a : Expr) : M Expr := iapp ``term #[n, x, a]
/-- Interpret an integer as a coefficient to a term. -/
def intToExpr (n : ℤ) : M Expr := do
Expr.ofInt (mkConst (if (← read).isGroup then ``Int else ``Nat) []) n
/-- A normal form for `abel`.
Expressions are represented as a list of terms of the form `e = n • x`,
where `n : ℤ` and `x` is an arbitrary element of the additive commutative monoid or group.
We explicitly track the `Expr` forms of `e` and `n`, even though they could be reconstructed,
for efficiency. -/
inductive NormalExpr : Type
| zero (e : Expr) : NormalExpr
| nterm (e : Expr) (n : Expr × ℤ) (x : ℕ × Expr) (a : NormalExpr) : NormalExpr
deriving Inhabited
/-- Extract the expression from a normal form. -/
def NormalExpr.e : NormalExpr → Expr
| .zero e => e
| .nterm e .. => e
instance : Coe NormalExpr Expr where coe := NormalExpr.e
/-- Construct the normal form representing a single term. -/
def NormalExpr.term' (n : Expr × ℤ) (x : ℕ × Expr) (a : NormalExpr) : M NormalExpr :=
return .nterm (← mkTerm n.1 x.2 a) n x a
/-- Construct the normal form representing zero. -/
def NormalExpr.zero' : M NormalExpr := return NormalExpr.zero (← read).α0
open NormalExpr
theorem const_add_term {α} [AddCommMonoid α] (k n x a a') (h : k + a = a') :
k + @term α _ n x a = term n x a' := by
simp [h.symm, term, add_comm, add_assoc]
theorem const_add_termg {α} [AddCommGroup α] (k n x a a') (h : k + a = a') :
k + @termg α _ n x a = termg n x a' := by
simp [h.symm, termg, add_comm, add_assoc]
theorem term_add_const {α} [AddCommMonoid α] (n x a k a') (h : a + k = a') :
@term α _ n x a + k = term n x a' := by
simp [h.symm, term, add_assoc]
theorem term_add_constg {α} [AddCommGroup α] (n x a k a') (h : a + k = a') :
@termg α _ n x a + k = termg n x a' := by
simp [h.symm, termg, add_assoc]
theorem term_add_term {α} [AddCommMonoid α] (n₁ x a₁ n₂ a₂ n' a') (h₁ : n₁ + n₂ = n')
(h₂ : a₁ + a₂ = a') : @term α _ n₁ x a₁ + @term α _ n₂ x a₂ = term n' x a' := by
simp [h₁.symm, h₂.symm, term, add_nsmul, add_assoc, add_left_comm]
theorem term_add_termg {α} [AddCommGroup α] (n₁ x a₁ n₂ a₂ n' a')
(h₁ : n₁ + n₂ = n') (h₂ : a₁ + a₂ = a') :
@termg α _ n₁ x a₁ + @termg α _ n₂ x a₂ = termg n' x a' := by
simp only [termg, h₁.symm, add_zsmul, h₂.symm]
exact add_add_add_comm (n₁ • x) a₁ (n₂ • x) a₂
theorem zero_term {α} [AddCommMonoid α] (x a) : @term α _ 0 x a = a := by
simp [term, zero_nsmul, one_nsmul]
theorem zero_termg {α} [AddCommGroup α] (x a) : @termg α _ 0 x a = a := by
simp [termg, zero_zsmul]
/--
Interpret the sum of two expressions in `abel`'s normal form.
-/
partial def evalAdd : NormalExpr → NormalExpr → M (NormalExpr × Expr)
| zero _, e₂ => do
let p ← mkAppM ``zero_add #[e₂]
return (e₂, p)
| e₁, zero _ => do
let p ← mkAppM ``add_zero #[e₁]
return (e₁, p)
| he₁@(nterm e₁ n₁ x₁ a₁), he₂@(nterm e₂ n₂ x₂ a₂) => do
if x₁.1 = x₂.1 then
let n' ← Mathlib.Meta.NormNum.eval (← mkAppM ``HAdd.hAdd #[n₁.1, n₂.1])
let (a', h₂) ← evalAdd a₁ a₂
let k := n₁.2 + n₂.2
let p₁ ← iapp ``term_add_term
#[n₁.1, x₁.2, a₁, n₂.1, a₂, n'.expr, a', ← n'.getProof, h₂]
if k = 0 then do
let p ← mkEqTrans p₁ (← iapp ``zero_term #[x₁.2, a'])
return (a', p)
else return (← term' (n'.expr, k) x₁ a', p₁)
else if x₁.1 < x₂.1 then do
let (a', h) ← evalAdd a₁ he₂
return (← term' n₁ x₁ a', ← iapp ``term_add_const #[n₁.1, x₁.2, a₁, e₂, a', h])
else do
let (a', h) ← evalAdd he₁ a₂
return (← term' n₂ x₂ a', ← iapp ``const_add_term #[e₁, n₂.1, x₂.2, a₂, a', h])
theorem term_neg {α} [AddCommGroup α] (n x a n' a')
(h₁ : -n = n') (h₂ : -a = a') : -@termg α _ n x a = termg n' x a' := by
simpa [h₂.symm, h₁.symm, termg] using add_comm _ _
/--
Interpret a negated expression in `abel`'s normal form.
-/
def evalNeg : NormalExpr → M (NormalExpr × Expr)
| (zero _) => do
let p ← (← read).mkApp ``neg_zero ``NegZeroClass #[]
return (← zero', p)
| (nterm _ n x a) => do
let n' ← Mathlib.Meta.NormNum.eval (← mkAppM ``Neg.neg #[n.1])
let (a', h₂) ← evalNeg a
return (← term' (n'.expr, -n.2) x a',
(← read).app ``term_neg (← read).inst #[n.1, x.2, a, n'.expr, a', ← n'.getProof, h₂])
/-- A synonym for `•`, used internally in `abel`. -/
def smul {α} [AddCommMonoid α] (n : ℕ) (x : α) : α := n • x
/-- A synonym for `•`, used internally in `abel`. -/
def smulg {α} [AddCommGroup α] (n : ℤ) (x : α) : α := n • x
theorem zero_smul {α} [AddCommMonoid α] (c) : smul c (0 : α) = 0 := by
simp [smul, nsmul_zero]
theorem zero_smulg {α} [AddCommGroup α] (c) : smulg c (0 : α) = 0 := by
simp [smulg, zsmul_zero]
theorem term_smul {α} [AddCommMonoid α] (c n x a n' a')
(h₁ : c * n = n') (h₂ : smul c a = a') :
smul c (@term α _ n x a) = term n' x a' := by
simp [h₂.symm, h₁.symm, term, smul, nsmul_add, mul_nsmul']
theorem term_smulg {α} [AddCommGroup α] (c n x a n' a')
(h₁ : c * n = n') (h₂ : smulg c a = a') :
smulg c (@termg α _ n x a) = termg n' x a' := by
simp [h₂.symm, h₁.symm, termg, smulg, zsmul_add, mul_zsmul]
/--
Auxiliary function for `evalSMul'`.
-/
def evalSMul (k : Expr × ℤ) : NormalExpr → M (NormalExpr × Expr)
| zero _ => return (← zero', ← iapp ``zero_smul #[k.1])
| nterm _ n x a => do
let n' ← Mathlib.Meta.NormNum.eval (← mkAppM ``HMul.hMul #[k.1, n.1])
let (a', h₂) ← evalSMul k a
return (← term' (n'.expr, k.2 * n.2) x a',
← iapp ``term_smul #[k.1, n.1, x.2, a, n'.expr, a', ← n'.getProof, h₂])
theorem term_atom {α} [AddCommMonoid α] (x : α) : x = term 1 x 0 := by simp [term]
theorem term_atomg {α} [AddCommGroup α] (x : α) : x = termg 1 x 0 := by simp [termg]
theorem term_atom_pf {α} [AddCommMonoid α] (x x' : α) (h : x = x') : x = term 1 x' 0 := by
simp [term, h]
theorem term_atom_pfg {α} [AddCommGroup α] (x x' : α) (h : x = x') : x = termg 1 x' 0 := by
simp [termg, h]
/-- Interpret an expression as an atom for `abel`'s normal form. -/
def evalAtom (e : Expr) : M (NormalExpr × Expr) := do
let { expr := e', proof?, .. } ← (← readThe AtomM.Context).evalAtom e
let (i, a) ← AtomM.addAtom e'
let p ← match proof? with
| none => iapp ``term_atom #[e]
| some p => iapp ``term_atom_pf #[e, a, p]
return (← term' (← intToExpr 1, 1) (i, a) (← zero'), p)
| Mathlib/Tactic/Abel.lean | 287 | 289 | theorem unfold_sub {α} [SubtractionMonoid α] (a b c : α) (h : a + -b = c) : a - b = c := by | rw [sub_eq_add_neg, h] |
/-
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, Floris van Doorn
-/
import Mathlib.Analysis.Calculus.ContDiff.Defs
import Mathlib.Analysis.Calculus.ContDiff.FaaDiBruno
import Mathlib.Analysis.Calculus.FDeriv.Add
import Mathlib.Analysis.Calculus.FDeriv.Mul
/-!
# Higher differentiability of composition
We prove that the composition of `C^n` functions is `C^n`.
We also expand the API around `C^n` functions.
## Main results
* `ContDiff.comp` states that the composition of two `C^n` functions is `C^n`.
Similar results are given for `C^n` functions on domains.
## Notations
We use the notation `E [×n]→L[𝕜] F` for the space of continuous multilinear maps on `E^n` with
values in `F`. This is the space in which the `n`-th derivative of a function from `E` to `F` lives.
In this file, we denote `(⊤ : ℕ∞) : WithTop ℕ∞` with `∞` and `⊤ : WithTop ℕ∞` with `ω`.
## Tags
derivative, differentiability, higher derivative, `C^n`, multilinear, Taylor series, formal series
-/
noncomputable section
open scoped NNReal Nat ContDiff
universe u uE uF uG
attribute [local instance 1001]
NormedAddCommGroup.toAddCommGroup AddCommGroup.toAddCommMonoid
open Set Fin Filter Function
open scoped Topology
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜]
{E : Type uE} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type uF}
[NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type uG} [NormedAddCommGroup G] [NormedSpace 𝕜 G]
{X : Type*} [NormedAddCommGroup X] [NormedSpace 𝕜 X] {s t : Set E} {f : E → F}
{g : F → G} {x x₀ : E} {b : E × F → G} {m n : WithTop ℕ∞} {p : E → FormalMultilinearSeries 𝕜 E F}
/-! ### Constants -/
section constants
theorem iteratedFDerivWithin_succ_const (n : ℕ) (c : F) :
iteratedFDerivWithin 𝕜 (n + 1) (fun _ : E ↦ c) s = 0 := by
induction n with
| zero =>
ext1
simp [iteratedFDerivWithin_succ_eq_comp_left, iteratedFDerivWithin_zero_eq_comp, comp_def]
| succ n IH =>
rw [iteratedFDerivWithin_succ_eq_comp_left, IH]
simp only [Pi.zero_def, comp_def, fderivWithin_const, map_zero]
@[simp]
theorem iteratedFDerivWithin_zero_fun {i : ℕ} :
iteratedFDerivWithin 𝕜 i (fun _ : E ↦ (0 : F)) s = 0 := by
cases i with
| zero => ext; simp
| succ i => apply iteratedFDerivWithin_succ_const
@[simp]
theorem iteratedFDeriv_zero_fun {n : ℕ} : (iteratedFDeriv 𝕜 n fun _ : E ↦ (0 : F)) = 0 :=
funext fun x ↦ by simp only [← iteratedFDerivWithin_univ, iteratedFDerivWithin_zero_fun]
theorem contDiff_zero_fun : ContDiff 𝕜 n fun _ : E => (0 : F) :=
analyticOnNhd_const.contDiff
/-- Constants are `C^∞`. -/
theorem contDiff_const {c : F} : ContDiff 𝕜 n fun _ : E => c :=
analyticOnNhd_const.contDiff
theorem contDiffOn_const {c : F} {s : Set E} : ContDiffOn 𝕜 n (fun _ : E => c) s :=
contDiff_const.contDiffOn
theorem contDiffAt_const {c : F} : ContDiffAt 𝕜 n (fun _ : E => c) x :=
contDiff_const.contDiffAt
theorem contDiffWithinAt_const {c : F} : ContDiffWithinAt 𝕜 n (fun _ : E => c) s x :=
contDiffAt_const.contDiffWithinAt
@[nontriviality]
theorem contDiff_of_subsingleton [Subsingleton F] : ContDiff 𝕜 n f := by
rw [Subsingleton.elim f fun _ => 0]; exact contDiff_const
@[nontriviality]
theorem contDiffAt_of_subsingleton [Subsingleton F] : ContDiffAt 𝕜 n f x := by
rw [Subsingleton.elim f fun _ => 0]; exact contDiffAt_const
@[nontriviality]
theorem contDiffWithinAt_of_subsingleton [Subsingleton F] : ContDiffWithinAt 𝕜 n f s x := by
rw [Subsingleton.elim f fun _ => 0]; exact contDiffWithinAt_const
@[nontriviality]
theorem contDiffOn_of_subsingleton [Subsingleton F] : ContDiffOn 𝕜 n f s := by
rw [Subsingleton.elim f fun _ => 0]; exact contDiffOn_const
theorem iteratedFDerivWithin_const_of_ne {n : ℕ} (hn : n ≠ 0) (c : F) (s : Set E) :
iteratedFDerivWithin 𝕜 n (fun _ : E ↦ c) s = 0 := by
cases n with
| zero => contradiction
| succ n => exact iteratedFDerivWithin_succ_const n c
theorem iteratedFDeriv_const_of_ne {n : ℕ} (hn : n ≠ 0) (c : F) :
(iteratedFDeriv 𝕜 n fun _ : E ↦ c) = 0 := by
simp only [← iteratedFDerivWithin_univ, iteratedFDerivWithin_const_of_ne hn]
theorem iteratedFDeriv_succ_const (n : ℕ) (c : F) :
(iteratedFDeriv 𝕜 (n + 1) fun _ : E ↦ c) = 0 :=
iteratedFDeriv_const_of_ne (by simp) _
theorem contDiffWithinAt_singleton : ContDiffWithinAt 𝕜 n f {x} x :=
(contDiffWithinAt_const (c := f x)).congr (by simp) rfl
end constants
/-! ### Smoothness of linear functions -/
section linear
/-- Unbundled bounded linear functions are `C^n`. -/
theorem IsBoundedLinearMap.contDiff (hf : IsBoundedLinearMap 𝕜 f) : ContDiff 𝕜 n f :=
(ContinuousLinearMap.analyticOnNhd hf.toContinuousLinearMap univ).contDiff
theorem ContinuousLinearMap.contDiff (f : E →L[𝕜] F) : ContDiff 𝕜 n f :=
f.isBoundedLinearMap.contDiff
theorem ContinuousLinearEquiv.contDiff (f : E ≃L[𝕜] F) : ContDiff 𝕜 n f :=
(f : E →L[𝕜] F).contDiff
theorem LinearIsometry.contDiff (f : E →ₗᵢ[𝕜] F) : ContDiff 𝕜 n f :=
f.toContinuousLinearMap.contDiff
theorem LinearIsometryEquiv.contDiff (f : E ≃ₗᵢ[𝕜] F) : ContDiff 𝕜 n f :=
(f : E →L[𝕜] F).contDiff
/-- The identity is `C^n`. -/
theorem contDiff_id : ContDiff 𝕜 n (id : E → E) :=
IsBoundedLinearMap.id.contDiff
theorem contDiffWithinAt_id {s x} : ContDiffWithinAt 𝕜 n (id : E → E) s x :=
contDiff_id.contDiffWithinAt
theorem contDiffAt_id {x} : ContDiffAt 𝕜 n (id : E → E) x :=
contDiff_id.contDiffAt
theorem contDiffOn_id {s} : ContDiffOn 𝕜 n (id : E → E) s :=
contDiff_id.contDiffOn
/-- Bilinear functions are `C^n`. -/
theorem IsBoundedBilinearMap.contDiff (hb : IsBoundedBilinearMap 𝕜 b) : ContDiff 𝕜 n b :=
(hb.toContinuousLinearMap.analyticOnNhd_bilinear _).contDiff
/-- If `f` admits a Taylor series `p` in a set `s`, and `g` is linear, then `g ∘ f` admits a Taylor
series whose `k`-th term is given by `g ∘ (p k)`. -/
theorem HasFTaylorSeriesUpToOn.continuousLinearMap_comp {n : WithTop ℕ∞} (g : F →L[𝕜] G)
(hf : HasFTaylorSeriesUpToOn n f p s) :
HasFTaylorSeriesUpToOn n (g ∘ f) (fun x k => g.compContinuousMultilinearMap (p x k)) s where
zero_eq x hx := congr_arg g (hf.zero_eq x hx)
fderivWithin m hm x hx := (ContinuousLinearMap.compContinuousMultilinearMapL 𝕜
(fun _ : Fin m => E) F G g).hasFDerivAt.comp_hasFDerivWithinAt x (hf.fderivWithin m hm x hx)
cont m hm := (ContinuousLinearMap.compContinuousMultilinearMapL 𝕜
(fun _ : Fin m => E) F G g).continuous.comp_continuousOn (hf.cont m hm)
/-- Composition by continuous linear maps on the left preserves `C^n` functions in a domain
at a point. -/
theorem ContDiffWithinAt.continuousLinearMap_comp (g : F →L[𝕜] G)
(hf : ContDiffWithinAt 𝕜 n f s x) : ContDiffWithinAt 𝕜 n (g ∘ f) s x := by
match n with
| ω =>
obtain ⟨u, hu, p, hp, h'p⟩ := hf
refine ⟨u, hu, _, hp.continuousLinearMap_comp g, fun i ↦ ?_⟩
change AnalyticOn 𝕜
(fun x ↦ (ContinuousLinearMap.compContinuousMultilinearMapL 𝕜
(fun _ : Fin i ↦ E) F G g) (p x i)) u
apply AnalyticOnNhd.comp_analyticOn _ (h'p i) (Set.mapsTo_univ _ _)
exact ContinuousLinearMap.analyticOnNhd _ _
| (n : ℕ∞) =>
intro m hm
rcases hf m hm with ⟨u, hu, p, hp⟩
exact ⟨u, hu, _, hp.continuousLinearMap_comp g⟩
/-- Composition by continuous linear maps on the left preserves `C^n` functions in a domain
at a point. -/
theorem ContDiffAt.continuousLinearMap_comp (g : F →L[𝕜] G) (hf : ContDiffAt 𝕜 n f x) :
ContDiffAt 𝕜 n (g ∘ f) x :=
ContDiffWithinAt.continuousLinearMap_comp g hf
/-- Composition by continuous linear maps on the left preserves `C^n` functions on domains. -/
theorem ContDiffOn.continuousLinearMap_comp (g : F →L[𝕜] G) (hf : ContDiffOn 𝕜 n f s) :
ContDiffOn 𝕜 n (g ∘ f) s := fun x hx => (hf x hx).continuousLinearMap_comp g
/-- Composition by continuous linear maps on the left preserves `C^n` functions. -/
theorem ContDiff.continuousLinearMap_comp {f : E → F} (g : F →L[𝕜] G) (hf : ContDiff 𝕜 n f) :
ContDiff 𝕜 n fun x => g (f x) :=
contDiffOn_univ.1 <| ContDiffOn.continuousLinearMap_comp _ (contDiffOn_univ.2 hf)
/-- The iterated derivative within a set of the composition with a linear map on the left is
obtained by applying the linear map to the iterated derivative. -/
theorem ContinuousLinearMap.iteratedFDerivWithin_comp_left {f : E → F} (g : F →L[𝕜] G)
(hf : ContDiffWithinAt 𝕜 n f s x) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) {i : ℕ} (hi : i ≤ n) :
iteratedFDerivWithin 𝕜 i (g ∘ f) s x =
g.compContinuousMultilinearMap (iteratedFDerivWithin 𝕜 i f s x) := by
rcases hf.contDiffOn' hi (by simp) with ⟨U, hU, hxU, hfU⟩
rw [← iteratedFDerivWithin_inter_open hU hxU, ← iteratedFDerivWithin_inter_open (f := f) hU hxU]
rw [insert_eq_of_mem hx] at hfU
exact .symm <| (hfU.ftaylorSeriesWithin (hs.inter hU)).continuousLinearMap_comp g
|>.eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl (hs.inter hU) ⟨hx, hxU⟩
/-- The iterated derivative of the composition with a linear map on the left is
obtained by applying the linear map to the iterated derivative. -/
| Mathlib/Analysis/Calculus/ContDiff/Basic.lean | 223 | 226 | theorem ContinuousLinearMap.iteratedFDeriv_comp_left {f : E → F} (g : F →L[𝕜] G)
(hf : ContDiffAt 𝕜 n f x) {i : ℕ} (hi : i ≤ n) :
iteratedFDeriv 𝕜 i (g ∘ f) x = g.compContinuousMultilinearMap (iteratedFDeriv 𝕜 i f x) := by | simp only [← iteratedFDerivWithin_univ] |
/-
Copyright (c) 2023 Jireh Loreaux. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jireh Loreaux
-/
import Mathlib.Algebra.Algebra.NonUnitalSubalgebra
import Mathlib.Algebra.Star.StarAlgHom
import Mathlib.Algebra.Star.Center
import Mathlib.Algebra.Star.SelfAdjoint
/-!
# Non-unital Star Subalgebras
In this file we define `NonUnitalStarSubalgebra`s and the usual operations on them
(`map`, `comap`).
## TODO
* once we have scalar actions by semigroups (as opposed to monoids), implement the action of a
non-unital subalgebra on the larger algebra.
-/
namespace StarMemClass
/-- If a type carries an involutive star, then any star-closed subset does too. -/
instance instInvolutiveStar {S R : Type*} [InvolutiveStar R] [SetLike S R] [StarMemClass S R]
(s : S) : InvolutiveStar s where
star_involutive r := Subtype.ext <| star_star (r : R)
/-- In a star magma (i.e., a multiplication with an antimultiplicative involutive star
operation), any star-closed subset which is also closed under multiplication is itself a star
magma. -/
instance instStarMul {S R : Type*} [Mul R] [StarMul R] [SetLike S R]
[MulMemClass S R] [StarMemClass S R] (s : S) : StarMul s where
star_mul _ _ := Subtype.ext <| star_mul _ _
/-- In a `StarAddMonoid` (i.e., an additive monoid with an additive involutive star operation), any
star-closed subset which is also closed under addition and contains zero is itself a
`StarAddMonoid`. -/
instance instStarAddMonoid {S R : Type*} [AddMonoid R] [StarAddMonoid R] [SetLike S R]
[AddSubmonoidClass S R] [StarMemClass S R] (s : S) : StarAddMonoid s where
star_add _ _ := Subtype.ext <| star_add _ _
/-- In a star ring (i.e., a non-unital, non-associative, semiring with an additive,
antimultiplicative, involutive star operation), a star-closed non-unital subsemiring is itself a
star ring. -/
instance instStarRing {S R : Type*} [NonUnitalNonAssocSemiring R] [StarRing R] [SetLike S R]
[NonUnitalSubsemiringClass S R] [StarMemClass S R] (s : S) : StarRing s :=
{ StarMemClass.instStarMul s, StarMemClass.instStarAddMonoid s with }
/-- In a star `R`-module (i.e., `star (r • m) = (star r) • m`) any star-closed subset which is also
closed under the scalar action by `R` is itself a star `R`-module. -/
instance instStarModule {S : Type*} (R : Type*) {M : Type*} [Star R] [Star M] [SMul R M]
[StarModule R M] [SetLike S M] [SMulMemClass S R M] [StarMemClass S M] (s : S) :
StarModule R s where
star_smul _ _ := Subtype.ext <| star_smul _ _
end StarMemClass
universe u u' v v' w w' w''
variable {F : Type v'} {R' : Type u'} {R : Type u}
variable {A : Type v} {B : Type w} {C : Type w'}
namespace NonUnitalStarSubalgebraClass
variable [CommSemiring R] [NonUnitalNonAssocSemiring A]
variable [Star A] [Module R A]
variable {S : Type w''} [SetLike S A] [NonUnitalSubsemiringClass S A]
variable [hSR : SMulMemClass S R A] [StarMemClass S A] (s : S)
/-- Embedding of a non-unital star subalgebra into the non-unital star algebra. -/
def subtype (s : S) : s →⋆ₙₐ[R] A :=
{ NonUnitalSubalgebraClass.subtype s with
toFun := Subtype.val
map_star' := fun _ => rfl }
variable {s} in
@[simp]
lemma subtype_apply (x : s) : subtype s x = x := rfl
lemma subtype_injective :
Function.Injective (subtype s) :=
Subtype.coe_injective
@[simp]
theorem coe_subtype : (subtype s : s → A) = Subtype.val :=
rfl
@[deprecated (since := "2025-02-18")]
alias coeSubtype := coe_subtype
end NonUnitalStarSubalgebraClass
/-- A non-unital star subalgebra is a non-unital subalgebra which is closed under the `star`
operation. -/
structure NonUnitalStarSubalgebra (R : Type u) (A : Type v) [CommSemiring R]
[NonUnitalNonAssocSemiring A] [Module R A] [Star A] : Type v
extends NonUnitalSubalgebra R A where
/-- The `carrier` of a `NonUnitalStarSubalgebra` is closed under the `star` operation. -/
star_mem' : ∀ {a : A} (_ha : a ∈ carrier), star a ∈ carrier
/-- Reinterpret a `NonUnitalStarSubalgebra` as a `NonUnitalSubalgebra`. -/
add_decl_doc NonUnitalStarSubalgebra.toNonUnitalSubalgebra
namespace NonUnitalStarSubalgebra
variable [CommSemiring R]
variable [NonUnitalNonAssocSemiring A] [Module R A] [Star A]
variable [NonUnitalNonAssocSemiring B] [Module R B] [Star B]
variable [NonUnitalNonAssocSemiring C] [Module R C] [Star C]
variable [FunLike F A B] [NonUnitalAlgHomClass F R A B] [StarHomClass F A B]
instance instSetLike : SetLike (NonUnitalStarSubalgebra R A) A where
coe {s} := s.carrier
coe_injective' p q h := by cases p; cases q; congr; exact SetLike.coe_injective h
/-- The actual `NonUnitalStarSubalgebra` obtained from an element of a type satisfying
`NonUnitalSubsemiringClass`, `SMulMemClass` and `StarMemClass`. -/
@[simps]
def ofClass {S R A : Type*} [CommSemiring R] [NonUnitalNonAssocSemiring A] [Module R A] [Star A]
[SetLike S A] [NonUnitalSubsemiringClass S A] [SMulMemClass S R A] [StarMemClass S A]
(s : S) : NonUnitalStarSubalgebra R A where
carrier := s
add_mem' := add_mem
zero_mem' := zero_mem _
mul_mem' := mul_mem
smul_mem' := SMulMemClass.smul_mem
star_mem' := star_mem
instance (priority := 100) : CanLift (Set A) (NonUnitalStarSubalgebra R A) (↑)
(fun s ↦ 0 ∈ s ∧ (∀ {x y}, x ∈ s → y ∈ s → x + y ∈ s) ∧ (∀ {x y}, x ∈ s → y ∈ s → x * y ∈ s) ∧
(∀ (r : R) {x}, x ∈ s → r • x ∈ s) ∧ ∀ {x}, x ∈ s → star x ∈ s) where
prf s h :=
⟨ { carrier := s
zero_mem' := h.1
add_mem' := h.2.1
mul_mem' := h.2.2.1
smul_mem' := h.2.2.2.1
star_mem' := h.2.2.2.2 },
rfl ⟩
instance instNonUnitalSubsemiringClass :
NonUnitalSubsemiringClass (NonUnitalStarSubalgebra R A) A where
add_mem {s} := s.add_mem'
mul_mem {s} := s.mul_mem'
zero_mem {s} := s.zero_mem'
instance instSMulMemClass : SMulMemClass (NonUnitalStarSubalgebra R A) R A where
smul_mem {s} := s.smul_mem'
instance instStarMemClass : StarMemClass (NonUnitalStarSubalgebra R A) A where
star_mem {s} := s.star_mem'
instance instNonUnitalSubringClass {R : Type u} {A : Type v} [CommRing R] [NonUnitalNonAssocRing A]
[Module R A] [Star A] : NonUnitalSubringClass (NonUnitalStarSubalgebra R A) A :=
{ NonUnitalStarSubalgebra.instNonUnitalSubsemiringClass with
neg_mem := fun _S {x} hx => neg_one_smul R x ▸ SMulMemClass.smul_mem _ hx }
theorem mem_carrier {s : NonUnitalStarSubalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s :=
Iff.rfl
@[ext]
theorem ext {S T : NonUnitalStarSubalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T :=
SetLike.ext h
@[simp]
theorem mem_toNonUnitalSubalgebra {S : NonUnitalStarSubalgebra R A} {x} :
x ∈ S.toNonUnitalSubalgebra ↔ x ∈ S :=
Iff.rfl
@[simp]
theorem coe_toNonUnitalSubalgebra (S : NonUnitalStarSubalgebra R A) :
(↑S.toNonUnitalSubalgebra : Set A) = S :=
rfl
theorem toNonUnitalSubalgebra_injective :
Function.Injective
(toNonUnitalSubalgebra : NonUnitalStarSubalgebra R A → NonUnitalSubalgebra R A) :=
fun S T h =>
ext fun x => by rw [← mem_toNonUnitalSubalgebra, ← mem_toNonUnitalSubalgebra, h]
theorem toNonUnitalSubalgebra_inj {S U : NonUnitalStarSubalgebra R A} :
S.toNonUnitalSubalgebra = U.toNonUnitalSubalgebra ↔ S = U :=
toNonUnitalSubalgebra_injective.eq_iff
theorem toNonUnitalSubalgebra_le_iff {S₁ S₂ : NonUnitalStarSubalgebra R A} :
S₁.toNonUnitalSubalgebra ≤ S₂.toNonUnitalSubalgebra ↔ S₁ ≤ S₂ :=
Iff.rfl
/-- Copy of a non-unital star subalgebra with a new `carrier` equal to the old one.
Useful to fix definitional equalities. -/
protected def copy (S : NonUnitalStarSubalgebra R A) (s : Set A) (hs : s = ↑S) :
NonUnitalStarSubalgebra R A :=
{ S.toNonUnitalSubalgebra.copy s hs with
star_mem' := @fun x (hx : x ∈ s) => by
show star x ∈ s
rw [hs] at hx ⊢
exact S.star_mem' hx }
@[simp]
theorem coe_copy (S : NonUnitalStarSubalgebra R A) (s : Set A) (hs : s = ↑S) :
(S.copy s hs : Set A) = s :=
rfl
theorem copy_eq (S : NonUnitalStarSubalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S :=
SetLike.coe_injective hs
variable (S : NonUnitalStarSubalgebra R A)
/-- A non-unital star subalgebra over a ring is also a `Subring`. -/
def toNonUnitalSubring {R : Type u} {A : Type v} [CommRing R] [NonUnitalRing A] [Module R A]
[Star A] (S : NonUnitalStarSubalgebra R A) : NonUnitalSubring A where
toNonUnitalSubsemiring := S.toNonUnitalSubsemiring
neg_mem' := neg_mem (s := S)
@[simp]
theorem mem_toNonUnitalSubring {R : Type u} {A : Type v} [CommRing R] [NonUnitalRing A] [Module R A]
[Star A] {S : NonUnitalStarSubalgebra R A} {x} : x ∈ S.toNonUnitalSubring ↔ x ∈ S :=
Iff.rfl
@[simp]
theorem coe_toNonUnitalSubring {R : Type u} {A : Type v} [CommRing R] [NonUnitalRing A] [Module R A]
[Star A] (S : NonUnitalStarSubalgebra R A) : (↑S.toNonUnitalSubring : Set A) = S :=
rfl
theorem toNonUnitalSubring_injective {R : Type u} {A : Type v} [CommRing R] [NonUnitalRing A]
[Module R A] [Star A] :
Function.Injective (toNonUnitalSubring : NonUnitalStarSubalgebra R A → NonUnitalSubring A) :=
fun S T h => ext fun x => by rw [← mem_toNonUnitalSubring, ← mem_toNonUnitalSubring, h]
theorem toNonUnitalSubring_inj {R : Type u} {A : Type v} [CommRing R] [NonUnitalRing A] [Module R A]
[Star A] {S U : NonUnitalStarSubalgebra R A} :
S.toNonUnitalSubring = U.toNonUnitalSubring ↔ S = U :=
toNonUnitalSubring_injective.eq_iff
instance instInhabited : Inhabited S :=
⟨(0 : S.toNonUnitalSubalgebra)⟩
section
/-! `NonUnitalStarSubalgebra`s inherit structure from their `NonUnitalSubsemiringClass` and
`NonUnitalSubringClass` instances. -/
instance toNonUnitalSemiring {R A} [CommSemiring R] [NonUnitalSemiring A] [Module R A] [Star A]
(S : NonUnitalStarSubalgebra R A) : NonUnitalSemiring S :=
inferInstance
instance toNonUnitalCommSemiring {R A} [CommSemiring R] [NonUnitalCommSemiring A] [Module R A]
[Star A] (S : NonUnitalStarSubalgebra R A) : NonUnitalCommSemiring S :=
inferInstance
instance toNonUnitalRing {R A} [CommRing R] [NonUnitalRing A] [Module R A] [Star A]
(S : NonUnitalStarSubalgebra R A) : NonUnitalRing S :=
inferInstance
instance toNonUnitalCommRing {R A} [CommRing R] [NonUnitalCommRing A] [Module R A] [Star A]
(S : NonUnitalStarSubalgebra R A) : NonUnitalCommRing S :=
inferInstance
end
/-- The forgetful map from `NonUnitalStarSubalgebra` to `NonUnitalSubalgebra` as an
`OrderEmbedding` -/
def toNonUnitalSubalgebra' : NonUnitalStarSubalgebra R A ↪o NonUnitalSubalgebra R A where
toEmbedding :=
{ toFun := fun S => S.toNonUnitalSubalgebra
inj' := fun S T h => ext <| by apply SetLike.ext_iff.1 h }
map_rel_iff' := SetLike.coe_subset_coe.symm.trans SetLike.coe_subset_coe
section
/-! `NonUnitalStarSubalgebra`s inherit structure from their `Submodule` coercions. -/
instance module' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] : Module R' S :=
SMulMemClass.toModule' _ R' R A S
instance instModule : Module R S :=
S.module'
instance instIsScalarTower' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A] :
IsScalarTower R' R S :=
S.toNonUnitalSubalgebra.instIsScalarTower'
instance instIsScalarTower [IsScalarTower R A A] : IsScalarTower R S S where
smul_assoc r x y := Subtype.ext <| smul_assoc r (x : A) (y : A)
instance instSMulCommClass' [Semiring R'] [SMul R' R] [Module R' A] [IsScalarTower R' R A]
[SMulCommClass R' R A] : SMulCommClass R' R S where
smul_comm r' r s := Subtype.ext <| smul_comm r' r (s : A)
instance instSMulCommClass [SMulCommClass R A A] : SMulCommClass R S S where
smul_comm r x y := Subtype.ext <| smul_comm r (x : A) (y : A)
end
instance noZeroSMulDivisors_bot [NoZeroSMulDivisors R A] : NoZeroSMulDivisors R S :=
⟨fun {c x} h =>
have : c = 0 ∨ (x : A) = 0 := eq_zero_or_eq_zero_of_smul_eq_zero (congr_arg ((↑) : S → A) h)
this.imp_right (@Subtype.ext_iff _ _ x 0).mpr⟩
protected theorem coe_add (x y : S) : (↑(x + y) : A) = ↑x + ↑y :=
rfl
protected theorem coe_mul (x y : S) : (↑(x * y) : A) = ↑x * ↑y :=
rfl
protected theorem coe_zero : ((0 : S) : A) = 0 :=
rfl
protected theorem coe_neg {R : Type u} {A : Type v} [CommRing R] [NonUnitalNonAssocRing A]
[Module R A] [Star A] {S : NonUnitalStarSubalgebra R A} (x : S) : (↑(-x) : A) = -↑x :=
rfl
protected theorem coe_sub {R : Type u} {A : Type v} [CommRing R] [NonUnitalNonAssocRing A]
[Module R A] [Star A] {S : NonUnitalStarSubalgebra R A} (x y : S) : (↑(x - y) : A) = ↑x - ↑y :=
rfl
@[simp, norm_cast]
theorem coe_smul [SMul R' R] [SMul R' A] [IsScalarTower R' R A] (r : R') (x : S) :
↑(r • x) = r • (x : A) :=
rfl
protected theorem coe_eq_zero {x : S} : (x : A) = 0 ↔ x = 0 :=
ZeroMemClass.coe_eq_zero
@[simp]
theorem toNonUnitalSubalgebra_subtype :
NonUnitalSubalgebraClass.subtype S = NonUnitalStarSubalgebraClass.subtype S :=
rfl
@[simp]
theorem toSubring_subtype {R A : Type*} [CommRing R] [NonUnitalNonAssocRing A] [Module R A] [Star A]
(S : NonUnitalStarSubalgebra R A) :
NonUnitalSubringClass.subtype S = NonUnitalStarSubalgebraClass.subtype S :=
rfl
/-- Transport a non-unital star subalgebra via a non-unital star algebra homomorphism. -/
def map (f : F) (S : NonUnitalStarSubalgebra R A) : NonUnitalStarSubalgebra R B where
toNonUnitalSubalgebra := S.toNonUnitalSubalgebra.map (f : A →ₙₐ[R] B)
star_mem' := by rintro _ ⟨a, ha, rfl⟩; exact ⟨star a, star_mem (s := S) ha, map_star f a⟩
theorem map_mono {S₁ S₂ : NonUnitalStarSubalgebra R A} {f : F} :
S₁ ≤ S₂ → (map f S₁ : NonUnitalStarSubalgebra R B) ≤ map f S₂ :=
Set.image_subset f
theorem map_injective {f : F} (hf : Function.Injective f) :
Function.Injective (map f : NonUnitalStarSubalgebra R A → NonUnitalStarSubalgebra R B) :=
fun _S₁ _S₂ ih =>
ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih
@[simp]
theorem map_id (S : NonUnitalStarSubalgebra R A) : map (NonUnitalStarAlgHom.id R A) S = S :=
SetLike.coe_injective <| Set.image_id _
theorem map_map (S : NonUnitalStarSubalgebra R A) (g : B →⋆ₙₐ[R] C) (f : A →⋆ₙₐ[R] B) :
(S.map f).map g = S.map (g.comp f) :=
SetLike.coe_injective <| Set.image_image _ _ _
@[simp]
theorem mem_map {S : NonUnitalStarSubalgebra R A} {f : F} {y : B} :
y ∈ map f S ↔ ∃ x ∈ S, f x = y :=
NonUnitalSubalgebra.mem_map
theorem map_toNonUnitalSubalgebra {S : NonUnitalStarSubalgebra R A} {f : F} :
(map f S : NonUnitalStarSubalgebra R B).toNonUnitalSubalgebra =
NonUnitalSubalgebra.map f S.toNonUnitalSubalgebra :=
SetLike.coe_injective rfl
@[simp]
theorem coe_map (S : NonUnitalStarSubalgebra R A) (f : F) : map f S = f '' S :=
rfl
/-- Preimage of a non-unital star subalgebra under a non-unital star algebra homomorphism. -/
def comap (f : F) (S : NonUnitalStarSubalgebra R B) : NonUnitalStarSubalgebra R A where
toNonUnitalSubalgebra := S.toNonUnitalSubalgebra.comap f
star_mem' := @fun a (ha : f a ∈ S) =>
show f (star a) ∈ S from (map_star f a).symm ▸ star_mem (s := S) ha
theorem map_le {S : NonUnitalStarSubalgebra R A} {f : F} {U : NonUnitalStarSubalgebra R B} :
map f S ≤ U ↔ S ≤ comap f U :=
Set.image_subset_iff
theorem gc_map_comap (f : F) : GaloisConnection (map f) (comap f) :=
fun _S _U => map_le
@[simp]
theorem mem_comap (S : NonUnitalStarSubalgebra R B) (f : F) (x : A) : x ∈ comap f S ↔ f x ∈ S :=
Iff.rfl
@[simp, norm_cast]
theorem coe_comap (S : NonUnitalStarSubalgebra R B) (f : F) : comap f S = f ⁻¹' (S : Set B) :=
rfl
instance instNoZeroDivisors {R A : Type*} [CommSemiring R] [NonUnitalSemiring A] [NoZeroDivisors A]
[Module R A] [Star A] (S : NonUnitalStarSubalgebra R A) : NoZeroDivisors S :=
NonUnitalSubsemiringClass.noZeroDivisors S
end NonUnitalStarSubalgebra
namespace NonUnitalSubalgebra
variable [CommSemiring R] [NonUnitalSemiring A] [Module R A] [Star A]
variable (s : NonUnitalSubalgebra R A)
/-- A non-unital subalgebra closed under `star` is a non-unital star subalgebra. -/
def toNonUnitalStarSubalgebra (h_star : ∀ x, x ∈ s → star x ∈ s) : NonUnitalStarSubalgebra R A :=
{ s with
star_mem' := @h_star }
@[simp]
theorem mem_toNonUnitalStarSubalgebra {s : NonUnitalSubalgebra R A} {h_star} {x} :
x ∈ s.toNonUnitalStarSubalgebra h_star ↔ x ∈ s :=
Iff.rfl
@[simp]
theorem coe_toNonUnitalStarSubalgebra (s : NonUnitalSubalgebra R A) (h_star) :
(s.toNonUnitalStarSubalgebra h_star : Set A) = s :=
rfl
@[simp]
theorem toNonUnitalStarSubalgebra_toNonUnitalSubalgebra (s : NonUnitalSubalgebra R A) (h_star) :
(s.toNonUnitalStarSubalgebra h_star).toNonUnitalSubalgebra = s :=
SetLike.coe_injective rfl
@[simp]
theorem _root_.NonUnitalStarSubalgebra.toNonUnitalSubalgebra_toNonUnitalStarSubalgebra
(S : NonUnitalStarSubalgebra R A) :
(S.toNonUnitalSubalgebra.toNonUnitalStarSubalgebra fun _ => star_mem (s := S)) = S :=
SetLike.coe_injective rfl
end NonUnitalSubalgebra
namespace NonUnitalStarAlgHom
variable [CommSemiring R]
variable [NonUnitalNonAssocSemiring A] [Module R A] [Star A]
variable [NonUnitalNonAssocSemiring B] [Module R B] [Star B]
variable [NonUnitalNonAssocSemiring C] [Module R C] [Star C]
variable [FunLike F A B] [NonUnitalAlgHomClass F R A B] [StarHomClass F A B]
/-- Range of an `NonUnitalAlgHom` as a `NonUnitalStarSubalgebra`. -/
protected def range (φ : F) : NonUnitalStarSubalgebra R B where
toNonUnitalSubalgebra := NonUnitalAlgHom.range (φ : A →ₙₐ[R] B)
star_mem' := by rintro _ ⟨a, rfl⟩; exact ⟨star a, map_star φ a⟩
@[simp]
theorem mem_range (φ : F) {y : B} :
y ∈ (NonUnitalStarAlgHom.range φ : NonUnitalStarSubalgebra R B) ↔ ∃ x : A, φ x = y :=
NonUnitalRingHom.mem_srange
theorem mem_range_self (φ : F) (x : A) :
φ x ∈ (NonUnitalStarAlgHom.range φ : NonUnitalStarSubalgebra R B) :=
(NonUnitalAlgHom.mem_range φ).2 ⟨x, rfl⟩
@[simp]
theorem coe_range (φ : F) :
((NonUnitalStarAlgHom.range φ : NonUnitalStarSubalgebra R B) : Set B) = Set.range (φ : A → B) :=
by ext; rw [SetLike.mem_coe, mem_range]; rfl
theorem range_comp (f : A →⋆ₙₐ[R] B) (g : B →⋆ₙₐ[R] C) :
NonUnitalStarAlgHom.range (g.comp f) = (NonUnitalStarAlgHom.range f).map g :=
SetLike.coe_injective (Set.range_comp g f)
theorem range_comp_le_range (f : A →⋆ₙₐ[R] B) (g : B →⋆ₙₐ[R] C) :
NonUnitalStarAlgHom.range (g.comp f) ≤ NonUnitalStarAlgHom.range g :=
SetLike.coe_mono (Set.range_comp_subset_range f g)
/-- Restrict the codomain of a non-unital star algebra homomorphism. -/
def codRestrict (f : F) (S : NonUnitalStarSubalgebra R B) (hf : ∀ x, f x ∈ S) : A →⋆ₙₐ[R] S where
toNonUnitalAlgHom := NonUnitalAlgHom.codRestrict f S.toNonUnitalSubalgebra hf
map_star' := fun a => Subtype.ext <| map_star f a
@[simp]
theorem subtype_comp_codRestrict (f : F) (S : NonUnitalStarSubalgebra R B) (hf : ∀ x : A, f x ∈ S) :
(NonUnitalStarSubalgebraClass.subtype S).comp (NonUnitalStarAlgHom.codRestrict f S hf) = f :=
NonUnitalStarAlgHom.ext fun _ => rfl
@[simp]
theorem coe_codRestrict (f : F) (S : NonUnitalStarSubalgebra R B) (hf : ∀ x, f x ∈ S) (x : A) :
↑(NonUnitalStarAlgHom.codRestrict f S hf x) = f x :=
rfl
theorem injective_codRestrict (f : F) (S : NonUnitalStarSubalgebra R B) (hf : ∀ x : A, f x ∈ S) :
Function.Injective (NonUnitalStarAlgHom.codRestrict f S hf) ↔ Function.Injective f :=
⟨fun H _x _y hxy => H <| Subtype.eq hxy, fun H _x _y hxy => H (congr_arg Subtype.val hxy :)⟩
/-- Restrict the codomain of a non-unital star algebra homomorphism `f` to `f.range`.
This is the bundled version of `Set.rangeFactorization`. -/
abbrev rangeRestrict (f : F) :
A →⋆ₙₐ[R] (NonUnitalStarAlgHom.range f : NonUnitalStarSubalgebra R B) :=
NonUnitalStarAlgHom.codRestrict f (NonUnitalStarAlgHom.range f)
(NonUnitalStarAlgHom.mem_range_self f)
/-- The equalizer of two non-unital star `R`-algebra homomorphisms -/
def equalizer (ϕ ψ : F) : NonUnitalStarSubalgebra R A where
toNonUnitalSubalgebra := NonUnitalAlgHom.equalizer ϕ ψ
star_mem' := @fun x (hx : ϕ x = ψ x) => by simp [map_star, hx]
@[simp]
theorem mem_equalizer (φ ψ : F) (x : A) :
x ∈ NonUnitalStarAlgHom.equalizer φ ψ ↔ φ x = ψ x :=
Iff.rfl
end NonUnitalStarAlgHom
namespace StarAlgEquiv
variable [CommSemiring R]
variable [NonUnitalSemiring A] [Module R A] [Star A]
variable [NonUnitalSemiring B] [Module R B] [Star B]
variable [NonUnitalSemiring C] [Module R C] [Star C]
variable [FunLike F A B] [NonUnitalAlgHomClass F R A B] [StarHomClass F A B]
/-- Restrict a non-unital star algebra homomorphism with a left inverse to an algebra isomorphism
to its range.
This is a computable alternative to `StarAlgEquiv.ofInjective`. -/
def ofLeftInverse' {g : B → A} {f : F} (h : Function.LeftInverse g f) :
A ≃⋆ₐ[R] NonUnitalStarAlgHom.range f :=
{ NonUnitalStarAlgHom.rangeRestrict f with
toFun := NonUnitalStarAlgHom.rangeRestrict f
invFun := g ∘ (NonUnitalStarSubalgebraClass.subtype <| NonUnitalStarAlgHom.range f)
left_inv := h
right_inv := fun x =>
Subtype.ext <|
let ⟨x', hx'⟩ := (NonUnitalStarAlgHom.mem_range f).mp x.prop
show f (g x) = x by rw [← hx', h x'] }
@[simp]
theorem ofLeftInverse'_apply {g : B → A} {f : F} (h : Function.LeftInverse g f) (x : A) :
ofLeftInverse' h x = f x :=
rfl
@[simp]
theorem ofLeftInverse'_symm_apply {g : B → A} {f : F} (h : Function.LeftInverse g f)
(x : NonUnitalStarAlgHom.range f) : (ofLeftInverse' h).symm x = g x :=
rfl
/-- Restrict an injective non-unital star algebra homomorphism to a star algebra isomorphism -/
noncomputable def ofInjective' (f : F) (hf : Function.Injective f) :
A ≃⋆ₐ[R] NonUnitalStarAlgHom.range f :=
ofLeftInverse' (Classical.choose_spec hf.hasLeftInverse)
@[simp]
theorem ofInjective'_apply (f : F) (hf : Function.Injective f) (x : A) :
ofInjective' f hf x = f x :=
rfl
end StarAlgEquiv
/-! ### The star closure of a subalgebra -/
namespace NonUnitalSubalgebra
open scoped Pointwise
variable [CommSemiring R] [StarRing R]
variable [NonUnitalSemiring A] [StarRing A] [Module R A]
variable [StarModule R A]
/-- The pointwise `star` of a non-unital subalgebra is a non-unital subalgebra. -/
instance instInvolutiveStar : InvolutiveStar (NonUnitalSubalgebra R A) where
star S :=
{ carrier := star S.carrier
mul_mem' := @fun x y hx hy => by simpa only [Set.mem_star, NonUnitalSubalgebra.mem_carrier]
using (star_mul x y).symm ▸ mul_mem hy hx
add_mem' := @fun x y hx hy => by simpa only [Set.mem_star, NonUnitalSubalgebra.mem_carrier]
using (star_add x y).symm ▸ add_mem hx hy
zero_mem' := Set.mem_star.mp ((star_zero A).symm ▸ zero_mem S : star (0 : A) ∈ S)
smul_mem' := fun r x hx => by simpa only [Set.mem_star, NonUnitalSubalgebra.mem_carrier]
using (star_smul r x).symm ▸ SMulMemClass.smul_mem (star r) hx }
star_involutive S := NonUnitalSubalgebra.ext fun x =>
⟨fun hx => star_star x ▸ hx, fun hx => ((star_star x).symm ▸ hx : star (star x) ∈ S)⟩
@[simp]
theorem mem_star_iff (S : NonUnitalSubalgebra R A) (x : A) : x ∈ star S ↔ star x ∈ S :=
Iff.rfl
theorem star_mem_star_iff (S : NonUnitalSubalgebra R A) (x : A) : star x ∈ star S ↔ x ∈ S := by
simp
@[simp]
theorem coe_star (S : NonUnitalSubalgebra R A) : star S = star (S : Set A) :=
rfl
theorem star_mono : Monotone (star : NonUnitalSubalgebra R A → NonUnitalSubalgebra R A) :=
fun _ _ h _ hx => h hx
variable (R)
variable [IsScalarTower R A A] [SMulCommClass R A A]
/-- The star operation on `NonUnitalSubalgebra` commutes with `NonUnitalAlgebra.adjoin`. -/
theorem star_adjoin_comm (s : Set A) :
star (NonUnitalAlgebra.adjoin R s) = NonUnitalAlgebra.adjoin R (star s) :=
have this :
∀ t : Set A, NonUnitalAlgebra.adjoin R (star t) ≤ star (NonUnitalAlgebra.adjoin R t) := fun _ =>
NonUnitalAlgebra.adjoin_le fun _ hx => NonUnitalAlgebra.subset_adjoin R hx
le_antisymm (by simpa only [star_star] using NonUnitalSubalgebra.star_mono (this (star s)))
(this s)
variable {R}
/-- The `NonUnitalStarSubalgebra` obtained from `S : NonUnitalSubalgebra R A` by taking the
smallest non-unital subalgebra containing both `S` and `star S`. -/
@[simps!]
def starClosure (S : NonUnitalSubalgebra R A) : NonUnitalStarSubalgebra R A where
toNonUnitalSubalgebra := S ⊔ star S
star_mem' := @fun a (ha : a ∈ S ⊔ star S) => show star a ∈ S ⊔ star S by
simp only [← mem_star_iff _ a, ← (@NonUnitalAlgebra.gi R A _ _ _ _ _).l_sup_u _ _] at *
convert ha using 2
simp only [Set.sup_eq_union, star_adjoin_comm, Set.union_star, coe_star, star_star,
Set.union_comm]
theorem starClosure_le {S₁ : NonUnitalSubalgebra R A} {S₂ : NonUnitalStarSubalgebra R A}
(h : S₁ ≤ S₂.toNonUnitalSubalgebra) : S₁.starClosure ≤ S₂ :=
NonUnitalStarSubalgebra.toNonUnitalSubalgebra_le_iff.1 <|
sup_le h fun x hx =>
(star_star x ▸ star_mem (show star x ∈ S₂ from h <| (S₁.mem_star_iff _).1 hx) : x ∈ S₂)
theorem starClosure_le_iff {S₁ : NonUnitalSubalgebra R A} {S₂ : NonUnitalStarSubalgebra R A} :
S₁.starClosure ≤ S₂ ↔ S₁ ≤ S₂.toNonUnitalSubalgebra :=
⟨fun h => le_sup_left.trans h, starClosure_le⟩
@[simp]
theorem starClosure_toNonunitalSubalgebra {S : NonUnitalSubalgebra R A} :
S.starClosure.toNonUnitalSubalgebra = S ⊔ star S :=
rfl
@[mono]
theorem starClosure_mono : Monotone (starClosure (R := R) (A := A)) :=
fun _ _ h => starClosure_le <| h.trans le_sup_left
end NonUnitalSubalgebra
namespace NonUnitalStarAlgebra
variable [CommSemiring R] [StarRing R]
variable [NonUnitalSemiring A] [StarRing A] [Module R A]
variable [NonUnitalSemiring B] [StarRing B] [Module R B]
variable [FunLike F A B] [NonUnitalAlgHomClass F R A B] [StarHomClass F A B]
section StarSubAlgebraA
variable [IsScalarTower R A A] [SMulCommClass R A A] [StarModule R A]
open scoped Pointwise
open NonUnitalStarSubalgebra
variable (R)
/-- The minimal non-unital subalgebra that includes `s`. -/
def adjoin (s : Set A) : NonUnitalStarSubalgebra R A where
toNonUnitalSubalgebra := NonUnitalAlgebra.adjoin R (s ∪ star s)
star_mem' _ := by
rwa [NonUnitalSubalgebra.mem_carrier, ← NonUnitalSubalgebra.mem_star_iff,
NonUnitalSubalgebra.star_adjoin_comm, Set.union_star, star_star, Set.union_comm]
theorem adjoin_eq_starClosure_adjoin (s : Set A) :
adjoin R s = (NonUnitalAlgebra.adjoin R s).starClosure :=
toNonUnitalSubalgebra_injective <| show
NonUnitalAlgebra.adjoin R (s ∪ star s) =
NonUnitalAlgebra.adjoin R s ⊔ star (NonUnitalAlgebra.adjoin R s)
from
(NonUnitalSubalgebra.star_adjoin_comm R s).symm ▸ NonUnitalAlgebra.adjoin_union s (star s)
theorem adjoin_toNonUnitalSubalgebra (s : Set A) :
(adjoin R s).toNonUnitalSubalgebra = NonUnitalAlgebra.adjoin R (s ∪ star s) :=
rfl
@[aesop safe 20 apply (rule_sets := [SetLike])]
theorem subset_adjoin (s : Set A) : s ⊆ adjoin R s :=
Set.subset_union_left.trans <| NonUnitalAlgebra.subset_adjoin R
theorem star_subset_adjoin (s : Set A) : star s ⊆ adjoin R s :=
Set.subset_union_right.trans <| NonUnitalAlgebra.subset_adjoin R
theorem self_mem_adjoin_singleton (x : A) : x ∈ adjoin R ({x} : Set A) :=
NonUnitalAlgebra.subset_adjoin R <| Set.mem_union_left _ (Set.mem_singleton x)
theorem star_self_mem_adjoin_singleton (x : A) : star x ∈ adjoin R ({x} : Set A) :=
star_mem <| self_mem_adjoin_singleton R x
@[elab_as_elim]
lemma adjoin_induction {s : Set A} {p : (x : A) → x ∈ adjoin R s → Prop}
(mem : ∀ (x : A) (hx : x ∈ s), p x (subset_adjoin R s hx))
(add : ∀ x y hx hy, p x hx → p y hy → p (x + y) (add_mem hx hy))
(zero : p 0 (zero_mem _)) (mul : ∀ x y hx hy, p x hx → p y hy → p (x * y) (mul_mem hx hy))
(smul : ∀ (r : R) x hx, p x hx → p (r • x) (SMulMemClass.smul_mem r hx))
(star : ∀ x hx, p x hx → p (star x) (star_mem hx))
{a : A} (ha : a ∈ adjoin R s) : p a ha := by
refine NonUnitalAlgebra.adjoin_induction (fun x hx ↦ ?_) add zero mul smul ha
simp only [Set.mem_union, Set.mem_star] at hx
obtain (hx | hx) := hx
· exact mem x hx
· simpa using star _ (NonUnitalAlgebra.subset_adjoin R (by simpa using Or.inl hx)) (mem _ hx)
variable {R}
protected theorem gc : GaloisConnection (adjoin R : Set A → NonUnitalStarSubalgebra R A) (↑) := by
intro s S
rw [← toNonUnitalSubalgebra_le_iff, adjoin_toNonUnitalSubalgebra,
NonUnitalAlgebra.adjoin_le_iff, coe_toNonUnitalSubalgebra]
exact ⟨fun h => Set.subset_union_left.trans h,
fun h => Set.union_subset h fun x hx => star_star x ▸ star_mem (show star x ∈ S from h hx)⟩
/-- Galois insertion between `adjoin` and `Subtype.val`. -/
protected def gi : GaloisInsertion (adjoin R : Set A → NonUnitalStarSubalgebra R A) (↑) where
choice s hs := (adjoin R s).copy s <| le_antisymm (NonUnitalStarAlgebra.gc.le_u_l s) hs
gc := NonUnitalStarAlgebra.gc
le_l_u S := (NonUnitalStarAlgebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl
choice_eq _ _ := NonUnitalStarSubalgebra.copy_eq _ _ _
theorem adjoin_le {S : NonUnitalStarSubalgebra R A} {s : Set A} (hs : s ⊆ S) : adjoin R s ≤ S :=
NonUnitalStarAlgebra.gc.l_le hs
theorem adjoin_le_iff {S : NonUnitalStarSubalgebra R A} {s : Set A} : adjoin R s ≤ S ↔ s ⊆ S :=
NonUnitalStarAlgebra.gc _ _
lemma adjoin_eq (s : NonUnitalStarSubalgebra R A) : adjoin R (s : Set A) = s :=
le_antisymm (adjoin_le le_rfl) (subset_adjoin R (s : Set A))
lemma adjoin_eq_span (s : Set A) :
(adjoin R s).toSubmodule = Submodule.span R (Subsemigroup.closure (s ∪ star s)) := by
rw [adjoin_toNonUnitalSubalgebra, NonUnitalAlgebra.adjoin_eq_span]
@[simp]
lemma span_eq_toSubmodule {R} [CommSemiring R] [Module R A] (s : NonUnitalStarSubalgebra R A) :
Submodule.span R (s : Set A) = s.toSubmodule := by
simp [SetLike.ext'_iff, Submodule.coe_span_eq_self]
theorem _root_.NonUnitalSubalgebra.starClosure_eq_adjoin (S : NonUnitalSubalgebra R A) :
S.starClosure = adjoin R (S : Set A) :=
le_antisymm (NonUnitalSubalgebra.starClosure_le_iff.2 <| subset_adjoin R (S : Set A))
(adjoin_le (le_sup_left : S ≤ S ⊔ star S))
instance : CompleteLattice (NonUnitalStarSubalgebra R A) :=
GaloisInsertion.liftCompleteLattice NonUnitalStarAlgebra.gi
@[simp]
theorem coe_top : ((⊤ : NonUnitalStarSubalgebra R A) : Set A) = Set.univ :=
rfl
@[simp]
theorem mem_top {x : A} : x ∈ (⊤ : NonUnitalStarSubalgebra R A) :=
Set.mem_univ x
@[simp]
theorem top_toNonUnitalSubalgebra :
(⊤ : NonUnitalStarSubalgebra R A).toNonUnitalSubalgebra = ⊤ := by ext; simp
@[simp]
theorem toNonUnitalSubalgebra_eq_top {S : NonUnitalStarSubalgebra R A} :
S.toNonUnitalSubalgebra = ⊤ ↔ S = ⊤ :=
NonUnitalStarSubalgebra.toNonUnitalSubalgebra_injective.eq_iff' top_toNonUnitalSubalgebra
theorem mem_sup_left {S T : NonUnitalStarSubalgebra R A} : ∀ {x : A}, x ∈ S → x ∈ S ⊔ T := by
rw [← SetLike.le_def]
exact le_sup_left
theorem mem_sup_right {S T : NonUnitalStarSubalgebra R A} : ∀ {x : A}, x ∈ T → x ∈ S ⊔ T := by
rw [← SetLike.le_def]
exact le_sup_right
theorem mul_mem_sup {S T : NonUnitalStarSubalgebra R A} {x y : A} (hx : x ∈ S) (hy : y ∈ T) :
x * y ∈ S ⊔ T :=
mul_mem (mem_sup_left hx) (mem_sup_right hy)
theorem map_sup [IsScalarTower R B B] [SMulCommClass R B B] [StarModule R B] (f : F)
(S T : NonUnitalStarSubalgebra R A) :
((S ⊔ T).map f : NonUnitalStarSubalgebra R B) = S.map f ⊔ T.map f :=
(NonUnitalStarSubalgebra.gc_map_comap f).l_sup
theorem map_inf [IsScalarTower R B B] [SMulCommClass R B B] [StarModule R B] (f : F)
(hf : Function.Injective f) (S T : NonUnitalStarSubalgebra R A) :
((S ⊓ T).map f : NonUnitalStarSubalgebra R B) = S.map f ⊓ T.map f :=
SetLike.coe_injective (Set.image_inter hf)
@[simp, norm_cast]
theorem coe_inf (S T : NonUnitalStarSubalgebra R A) : (↑(S ⊓ T) : Set A) = (S : Set A) ∩ T :=
rfl
@[simp]
theorem mem_inf {S T : NonUnitalStarSubalgebra R A} {x : A} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T :=
Iff.rfl
@[simp]
theorem inf_toNonUnitalSubalgebra (S T : NonUnitalStarSubalgebra R A) :
(S ⊓ T).toNonUnitalSubalgebra = S.toNonUnitalSubalgebra ⊓ T.toNonUnitalSubalgebra :=
SetLike.coe_injective <| coe_inf _ _
-- it's a bit surprising `rfl` fails here.
@[simp, norm_cast]
theorem coe_sInf (S : Set (NonUnitalStarSubalgebra R A)) : (↑(sInf S) : Set A) = ⋂ s ∈ S, ↑s :=
sInf_image
theorem mem_sInf {S : Set (NonUnitalStarSubalgebra R A)} {x : A} : x ∈ sInf S ↔ ∀ p ∈ S, x ∈ p := by
simp only [← SetLike.mem_coe, coe_sInf, Set.mem_iInter₂]
@[simp]
theorem sInf_toNonUnitalSubalgebra (S : Set (NonUnitalStarSubalgebra R A)) :
(sInf S).toNonUnitalSubalgebra = sInf (NonUnitalStarSubalgebra.toNonUnitalSubalgebra '' S) :=
SetLike.coe_injective <| by simp
@[simp, norm_cast]
theorem coe_iInf {ι : Sort*} {S : ι → NonUnitalStarSubalgebra R A} :
(↑(⨅ i, S i) : Set A) = ⋂ i, S i := by simp [iInf]
theorem mem_iInf {ι : Sort*} {S : ι → NonUnitalStarSubalgebra R A} {x : A} :
(x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by simp only [iInf, mem_sInf, Set.forall_mem_range]
theorem map_iInf {ι : Sort*} [Nonempty ι]
[IsScalarTower R B B] [SMulCommClass R B B] [StarModule R B] (f : F)
(hf : Function.Injective f) (S : ι → NonUnitalStarSubalgebra R A) :
((⨅ i, S i).map f : NonUnitalStarSubalgebra R B) = ⨅ i, (S i).map f := by
apply SetLike.coe_injective
simpa using (Set.injOn_of_injective hf).image_iInter_eq (s := SetLike.coe ∘ S)
@[simp]
theorem iInf_toNonUnitalSubalgebra {ι : Sort*} (S : ι → NonUnitalStarSubalgebra R A) :
(⨅ i, S i).toNonUnitalSubalgebra = ⨅ i, (S i).toNonUnitalSubalgebra :=
SetLike.coe_injective <| by simp
instance : Inhabited (NonUnitalStarSubalgebra R A) :=
⟨⊥⟩
theorem mem_bot {x : A} : x ∈ (⊥ : NonUnitalStarSubalgebra R A) ↔ x = 0 :=
show x ∈ NonUnitalAlgebra.adjoin R (∅ ∪ star ∅ : Set A) ↔ x = 0 by
rw [Set.star_empty, Set.union_empty, NonUnitalAlgebra.adjoin_empty, NonUnitalAlgebra.mem_bot]
theorem toNonUnitalSubalgebra_bot :
(⊥ : NonUnitalStarSubalgebra R A).toNonUnitalSubalgebra = ⊥ := by
ext x
simp only [mem_bot, NonUnitalStarSubalgebra.mem_toNonUnitalSubalgebra, NonUnitalAlgebra.mem_bot]
@[simp]
theorem coe_bot : ((⊥ : NonUnitalStarSubalgebra R A) : Set A) = {0} := by
simp only [Set.ext_iff, NonUnitalStarAlgebra.mem_bot, SetLike.mem_coe, Set.mem_singleton_iff,
forall_const]
theorem eq_top_iff {S : NonUnitalStarSubalgebra R A} : S = ⊤ ↔ ∀ x : A, x ∈ S :=
⟨fun h x => by rw [h]; exact mem_top,
fun h => by ext x; exact ⟨fun _ => mem_top, fun _ => h x⟩⟩
@[simp]
theorem range_id : NonUnitalStarAlgHom.range (NonUnitalStarAlgHom.id R A) = ⊤ :=
SetLike.coe_injective Set.range_id
@[simp]
theorem map_bot [IsScalarTower R B B] [SMulCommClass R B B] [StarModule R B] (f : F) :
(⊥ : NonUnitalStarSubalgebra R A).map f = ⊥ :=
SetLike.coe_injective <| by simp [NonUnitalAlgebra.coe_bot, NonUnitalStarSubalgebra.coe_map]
@[simp]
theorem comap_top [IsScalarTower R B B] [SMulCommClass R B B] [StarModule R B] (f : F) :
(⊤ : NonUnitalStarSubalgebra R B).comap f = ⊤ :=
eq_top_iff.2 fun _x => mem_top
/-- `NonUnitalStarAlgHom` to `⊤ : NonUnitalStarSubalgebra R A`. -/
def toTop : A →⋆ₙₐ[R] (⊤ : NonUnitalStarSubalgebra R A) :=
NonUnitalStarAlgHom.codRestrict (NonUnitalStarAlgHom.id R A) ⊤ fun _ => mem_top
end StarSubAlgebraA
theorem range_eq_top [IsScalarTower R B B] [SMulCommClass R B B] [StarModule R B]
(f : F) : NonUnitalStarAlgHom.range f = (⊤ : NonUnitalStarSubalgebra R B) ↔
Function.Surjective f :=
NonUnitalStarAlgebra.eq_top_iff
@[deprecated (since := "2024-11-11")] alias range_top_iff_surjective := range_eq_top
@[simp]
theorem map_top [IsScalarTower R A A] [SMulCommClass R A A] [StarModule R A] (f : F) :
(⊤ : NonUnitalStarSubalgebra R A).map f = NonUnitalStarAlgHom.range f :=
SetLike.coe_injective Set.image_univ
end NonUnitalStarAlgebra
namespace NonUnitalStarSubalgebra
open NonUnitalStarAlgebra
variable [CommSemiring R]
variable [NonUnitalSemiring A] [StarRing A] [Module R A]
variable [NonUnitalSemiring B] [StarRing B] [Module R B]
variable [FunLike F A B] [NonUnitalAlgHomClass F R A B] [StarHomClass F A B]
variable (S : NonUnitalStarSubalgebra R A)
section StarSubalgebra
variable [StarRing R]
variable [IsScalarTower R A A] [SMulCommClass R A A] [StarModule R A]
variable [IsScalarTower R B B] [SMulCommClass R B B] [StarModule R B]
lemma _root_.NonUnitalStarAlgHom.map_adjoin (f : F) (s : Set A) :
map f (adjoin R s) = adjoin R (f '' s) :=
Set.image_preimage.l_comm_of_u_comm (gc_map_comap f) NonUnitalStarAlgebra.gi.gc
NonUnitalStarAlgebra.gi.gc fun _t => rfl
@[simp]
lemma _root_.NonUnitalStarAlgHom.map_adjoin_singleton (f : F) (x : A) :
map f (adjoin R {x}) = adjoin R {f x} := by
simp [NonUnitalStarAlgHom.map_adjoin]
instance subsingleton_of_subsingleton [Subsingleton A] :
Subsingleton (NonUnitalStarSubalgebra R A) :=
⟨fun B C => ext fun x => by simp only [Subsingleton.elim x 0, zero_mem B, zero_mem C]⟩
instance _root_.NonUnitalStarAlgHom.subsingleton [Subsingleton (NonUnitalStarSubalgebra R A)] :
Subsingleton (A →⋆ₙₐ[R] B) :=
⟨fun f g => NonUnitalStarAlgHom.ext fun a =>
have : a ∈ (⊥ : NonUnitalStarSubalgebra R A) :=
Subsingleton.elim (⊤ : NonUnitalStarSubalgebra R A) ⊥ ▸ mem_top
(mem_bot.mp this).symm ▸ (map_zero f).trans (map_zero g).symm⟩
/--
The map `S → T` when `S` is a non-unital star subalgebra contained in the non-unital star
algebra `T`.
This is the non-unital star subalgebra version of `Submodule.inclusion`, or
`NonUnitalSubalgebra.inclusion` -/
def inclusion {S T : NonUnitalStarSubalgebra R A} (h : S ≤ T) : S →⋆ₙₐ[R] T where
toNonUnitalAlgHom := NonUnitalSubalgebra.inclusion h
map_star' _ := rfl
theorem inclusion_injective {S T : NonUnitalStarSubalgebra R A} (h : S ≤ T) :
Function.Injective (inclusion h) :=
fun _ _ => Subtype.ext ∘ Subtype.mk.inj
@[simp]
theorem inclusion_self {S : NonUnitalStarSubalgebra R A} :
inclusion (le_refl S) = NonUnitalAlgHom.id R S :=
NonUnitalAlgHom.ext fun _x => Subtype.ext rfl
@[simp]
theorem inclusion_mk {S T : NonUnitalStarSubalgebra R A} (h : S ≤ T) (x : A) (hx : x ∈ S) :
inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=
rfl
theorem inclusion_right {S T : NonUnitalStarSubalgebra R A} (h : S ≤ T) (x : T) (m : (x : A) ∈ S) :
inclusion h ⟨x, m⟩ = x :=
Subtype.ext rfl
@[simp]
theorem inclusion_inclusion {S T U : NonUnitalStarSubalgebra R A} (hst : S ≤ T) (htu : T ≤ U)
(x : S) : inclusion htu (inclusion hst x) = inclusion (le_trans hst htu) x :=
Subtype.ext rfl
@[simp]
theorem val_inclusion {S T : NonUnitalStarSubalgebra R A} (h : S ≤ T) (s : S) :
(inclusion h s : A) = s :=
rfl
end StarSubalgebra
theorem range_val : NonUnitalStarAlgHom.range (NonUnitalStarSubalgebraClass.subtype S) = S :=
ext <| Set.ext_iff.1 <|
(NonUnitalStarAlgHom.coe_range (NonUnitalStarSubalgebraClass.subtype S)).trans Subtype.range_val
section Prod
variable (S₁ : NonUnitalStarSubalgebra R B)
/-- The product of two non-unital star subalgebras is a non-unital star subalgebra. -/
def prod : NonUnitalStarSubalgebra R (A × B) :=
{ S.toNonUnitalSubalgebra.prod S₁.toNonUnitalSubalgebra with
carrier := S ×ˢ S₁
star_mem' := fun hx => ⟨star_mem hx.1, star_mem hx.2⟩ }
@[simp]
theorem coe_prod : (prod S S₁ : Set (A × B)) = (S : Set A) ×ˢ S₁ :=
rfl
theorem prod_toNonUnitalSubalgebra :
(S.prod S₁).toNonUnitalSubalgebra = S.toNonUnitalSubalgebra.prod S₁.toNonUnitalSubalgebra :=
rfl
@[simp]
theorem mem_prod {S : NonUnitalStarSubalgebra R A} {S₁ : NonUnitalStarSubalgebra R B} {x : A × B} :
x ∈ prod S S₁ ↔ x.1 ∈ S ∧ x.2 ∈ S₁ :=
Set.mem_prod
variable [StarRing R]
variable [IsScalarTower R A A] [SMulCommClass R A A] [StarModule R A]
variable [IsScalarTower R B B] [SMulCommClass R B B] [StarModule R B]
@[simp]
theorem prod_top : (prod ⊤ ⊤ : NonUnitalStarSubalgebra R (A × B)) = ⊤ := by ext; simp
theorem prod_mono {S T : NonUnitalStarSubalgebra R A} {S₁ T₁ : NonUnitalStarSubalgebra R B} :
S ≤ T → S₁ ≤ T₁ → prod S S₁ ≤ prod T T₁ :=
Set.prod_mono
@[simp]
theorem prod_inf_prod {S T : NonUnitalStarSubalgebra R A} {S₁ T₁ : NonUnitalStarSubalgebra R B} :
S.prod S₁ ⊓ T.prod T₁ = (S ⊓ T).prod (S₁ ⊓ T₁) :=
SetLike.coe_injective Set.prod_inter_prod
end Prod
section iSupLift
variable {ι : Type*}
variable [StarRing R] [IsScalarTower R A A] [SMulCommClass R A A] [StarModule R A]
section StarSubalgebraB
variable [IsScalarTower R B B] [SMulCommClass R B B] [StarModule R B]
theorem coe_iSup_of_directed [Nonempty ι] {S : ι → NonUnitalStarSubalgebra R A}
(dir : Directed (· ≤ ·) S) : ↑(iSup S) = ⋃ i, (S i : Set A) :=
let K : NonUnitalStarSubalgebra R A :=
{ __ := NonUnitalSubalgebra.copy _ _ (NonUnitalSubalgebra.coe_iSup_of_directed dir).symm
star_mem' := fun hx ↦
let ⟨i, hi⟩ := Set.mem_iUnion.1 hx
Set.mem_iUnion.2 ⟨i, star_mem (s := S i) hi⟩ }
have : iSup S = K := le_antisymm (iSup_le fun i ↦ le_iSup (fun i ↦ (S i : Set A)) i)
(Set.iUnion_subset fun _ ↦ le_iSup S _)
this.symm ▸ rfl
/-- Define a non-unital star algebra homomorphism on a directed supremum of non-unital star
subalgebras by defining it on each non-unital star subalgebra, and proving that it agrees on the
intersection of non-unital star subalgebras. -/
noncomputable def iSupLift [Nonempty ι] (K : ι → NonUnitalStarSubalgebra R A)
(dir : Directed (· ≤ ·) K) (f : ∀ i, K i →⋆ₙₐ[R] B)
(hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h))
(T : NonUnitalStarSubalgebra R A) (hT : T = iSup K) : ↥T →⋆ₙₐ[R] B := by
subst hT
exact
{ toFun :=
Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x)
(fun i j x hxi hxj => by
let ⟨k, hik, hjk⟩ := dir i j
simp only
rw [hf i k hik, hf j k hjk]
rfl)
_ (by rw [coe_iSup_of_directed dir])
map_zero' := by
dsimp only [SetLike.coe_sort_coe, NonUnitalAlgHom.coe_comp, Function.comp_apply,
inclusion_mk, Eq.ndrec, id_eq, eq_mpr_eq_cast]
exact Set.iUnionLift_const _ (fun i : ι => (0 : K i)) (fun _ => rfl) _ (by simp)
map_mul' := by
dsimp only [SetLike.coe_sort_coe, NonUnitalAlgHom.coe_comp, Function.comp_apply,
inclusion_mk, Eq.ndrec, id_eq, eq_mpr_eq_cast, ZeroMemClass.coe_zero,
AddSubmonoid.mk_add_mk, Set.inclusion_mk]
apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·))
all_goals simp
map_add' := by
dsimp only [SetLike.coe_sort_coe, NonUnitalAlgHom.coe_comp, Function.comp_apply,
inclusion_mk, Eq.ndrec, id_eq, eq_mpr_eq_cast]
apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·))
all_goals simp
map_smul' := fun r => by
dsimp only [SetLike.coe_sort_coe, NonUnitalAlgHom.coe_comp, Function.comp_apply,
inclusion_mk, Eq.ndrec, id_eq, eq_mpr_eq_cast]
apply Set.iUnionLift_unary (coe_iSup_of_directed dir) _ (fun _ x => r • x)
(fun _ _ => rfl)
all_goals simp
map_star' := by
dsimp only [SetLike.coe_sort_coe, NonUnitalStarAlgHom.comp_apply, inclusion_mk, Eq.ndrec,
id_eq, eq_mpr_eq_cast, ZeroMemClass.coe_zero, AddSubmonoid.mk_add_mk, Set.inclusion_mk,
MulMemClass.mk_mul_mk, NonUnitalAlgHom.toDistribMulActionHom_eq_coe,
DistribMulActionHom.toFun_eq_coe, NonUnitalAlgHom.coe_to_distribMulActionHom,
NonUnitalAlgHom.coe_mk]
apply Set.iUnionLift_unary (coe_iSup_of_directed dir) _ (fun _ x => star x)
(fun _ _ => rfl)
all_goals simp [map_star] }
end StarSubalgebraB
variable [Nonempty ι] {K : ι → NonUnitalStarSubalgebra R A} {dir : Directed (· ≤ ·) K}
{f : ∀ i, K i →⋆ₙₐ[R] B} {hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h)}
{T : NonUnitalStarSubalgebra R A} {hT : T = iSup K}
@[simp]
theorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) :
iSupLift K dir f hf T hT (inclusion h x) = f i x := by
subst T
dsimp [iSupLift]
apply Set.iUnionLift_inclusion
exact h
@[simp]
theorem iSupLift_comp_inclusion {i : ι} (h : K i ≤ T) :
(iSupLift K dir f hf T hT).comp (inclusion h) = f i := by ext; simp
@[simp]
| Mathlib/Algebra/Star/NonUnitalSubalgebra.lean | 1,088 | 1,089 | theorem iSupLift_mk {i : ι} (x : K i) (hx : (x : A) ∈ T) :
iSupLift K dir f hf T hT ⟨x, hx⟩ = f i x := by | |
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Simon Hudon, Mario Carneiro
-/
import Aesop
import Mathlib.Algebra.Group.Defs
import Mathlib.Data.Nat.Init
import Mathlib.Data.Int.Init
import Mathlib.Logic.Function.Iterate
import Mathlib.Tactic.SimpRw
import Mathlib.Tactic.SplitIfs
/-!
# Basic lemmas about semigroups, monoids, and groups
This file lists various basic lemmas about semigroups, monoids, and groups. Most proofs are
one-liners from the corresponding axioms. For the definitions of semigroups, monoids and groups, see
`Algebra/Group/Defs.lean`.
-/
assert_not_exists MonoidWithZero DenselyOrdered
open Function
variable {α β G M : Type*}
section ite
variable [Pow α β]
@[to_additive (attr := simp) dite_smul]
lemma pow_dite (p : Prop) [Decidable p] (a : α) (b : p → β) (c : ¬ p → β) :
a ^ (if h : p then b h else c h) = if h : p then a ^ b h else a ^ c h := by split_ifs <;> rfl
@[to_additive (attr := simp) smul_dite]
lemma dite_pow (p : Prop) [Decidable p] (a : p → α) (b : ¬ p → α) (c : β) :
(if h : p then a h else b h) ^ c = if h : p then a h ^ c else b h ^ c := by split_ifs <;> rfl
@[to_additive (attr := simp) ite_smul]
lemma pow_ite (p : Prop) [Decidable p] (a : α) (b c : β) :
a ^ (if p then b else c) = if p then a ^ b else a ^ c := pow_dite _ _ _ _
@[to_additive (attr := simp) smul_ite]
lemma ite_pow (p : Prop) [Decidable p] (a b : α) (c : β) :
(if p then a else b) ^ c = if p then a ^ c else b ^ c := dite_pow _ _ _ _
set_option linter.existingAttributeWarning false in
attribute [to_additive (attr := simp)] dite_smul smul_dite ite_smul smul_ite
end ite
section Semigroup
variable [Semigroup α]
@[to_additive]
instance Semigroup.to_isAssociative : Std.Associative (α := α) (· * ·) := ⟨mul_assoc⟩
/-- Composing two multiplications on the left by `y` then `x`
is equal to a multiplication on the left by `x * y`.
-/
@[to_additive (attr := simp) "Composing two additions on the left by `y` then `x`
is equal to an addition on the left by `x + y`."]
theorem comp_mul_left (x y : α) : (x * ·) ∘ (y * ·) = (x * y * ·) := by
ext z
simp [mul_assoc]
/-- Composing two multiplications on the right by `y` and `x`
is equal to a multiplication on the right by `y * x`.
-/
@[to_additive (attr := simp) "Composing two additions on the right by `y` and `x`
is equal to an addition on the right by `y + x`."]
theorem comp_mul_right (x y : α) : (· * x) ∘ (· * y) = (· * (y * x)) := by
ext z
simp [mul_assoc]
end Semigroup
@[to_additive]
instance CommMagma.to_isCommutative [CommMagma G] : Std.Commutative (α := G) (· * ·) := ⟨mul_comm⟩
section MulOneClass
variable [MulOneClass M]
@[to_additive]
theorem ite_mul_one {P : Prop} [Decidable P] {a b : M} :
ite P (a * b) 1 = ite P a 1 * ite P b 1 := by
by_cases h : P <;> simp [h]
@[to_additive]
theorem ite_one_mul {P : Prop} [Decidable P] {a b : M} :
ite P 1 (a * b) = ite P 1 a * ite P 1 b := by
by_cases h : P <;> simp [h]
@[to_additive]
theorem eq_one_iff_eq_one_of_mul_eq_one {a b : M} (h : a * b = 1) : a = 1 ↔ b = 1 := by
constructor <;> (rintro rfl; simpa using h)
@[to_additive]
theorem one_mul_eq_id : ((1 : M) * ·) = id :=
funext one_mul
@[to_additive]
theorem mul_one_eq_id : (· * (1 : M)) = id :=
funext mul_one
end MulOneClass
section CommSemigroup
variable [CommSemigroup G]
@[to_additive]
theorem mul_left_comm (a b c : G) : a * (b * c) = b * (a * c) := by
rw [← mul_assoc, mul_comm a, mul_assoc]
@[to_additive]
theorem mul_right_comm (a b c : G) : a * b * c = a * c * b := by
rw [mul_assoc, mul_comm b, mul_assoc]
@[to_additive]
theorem mul_mul_mul_comm (a b c d : G) : a * b * (c * d) = a * c * (b * d) := by
simp only [mul_left_comm, mul_assoc]
@[to_additive]
theorem mul_rotate (a b c : G) : a * b * c = b * c * a := by
simp only [mul_left_comm, mul_comm]
@[to_additive]
theorem mul_rotate' (a b c : G) : a * (b * c) = b * (c * a) := by
simp only [mul_left_comm, mul_comm]
end CommSemigroup
attribute [local simp] mul_assoc sub_eq_add_neg
section Monoid
variable [Monoid M] {a b : M} {m n : ℕ}
@[to_additive boole_nsmul]
lemma pow_boole (P : Prop) [Decidable P] (a : M) :
(a ^ if P then 1 else 0) = if P then a else 1 := by simp only [pow_ite, pow_one, pow_zero]
@[to_additive nsmul_add_sub_nsmul]
lemma pow_mul_pow_sub (a : M) (h : m ≤ n) : a ^ m * a ^ (n - m) = a ^ n := by
rw [← pow_add, Nat.add_comm, Nat.sub_add_cancel h]
@[to_additive sub_nsmul_nsmul_add]
lemma pow_sub_mul_pow (a : M) (h : m ≤ n) : a ^ (n - m) * a ^ m = a ^ n := by
rw [← pow_add, Nat.sub_add_cancel h]
@[to_additive sub_one_nsmul_add]
lemma mul_pow_sub_one (hn : n ≠ 0) (a : M) : a * a ^ (n - 1) = a ^ n := by
rw [← pow_succ', Nat.sub_add_cancel <| Nat.one_le_iff_ne_zero.2 hn]
@[to_additive add_sub_one_nsmul]
lemma pow_sub_one_mul (hn : n ≠ 0) (a : M) : a ^ (n - 1) * a = a ^ n := by
rw [← pow_succ, Nat.sub_add_cancel <| Nat.one_le_iff_ne_zero.2 hn]
/-- If `x ^ n = 1`, then `x ^ m` is the same as `x ^ (m % n)` -/
@[to_additive nsmul_eq_mod_nsmul "If `n • x = 0`, then `m • x` is the same as `(m % n) • x`"]
lemma pow_eq_pow_mod (m : ℕ) (ha : a ^ n = 1) : a ^ m = a ^ (m % n) := by
calc
a ^ m = a ^ (m % n + n * (m / n)) := by rw [Nat.mod_add_div]
_ = a ^ (m % n) := by simp [pow_add, pow_mul, ha]
@[to_additive] lemma pow_mul_pow_eq_one : ∀ n, a * b = 1 → a ^ n * b ^ n = 1
| 0, _ => by simp
| n + 1, h =>
calc
a ^ n.succ * b ^ n.succ = a ^ n * a * (b * b ^ n) := by rw [pow_succ, pow_succ']
_ = a ^ n * (a * b) * b ^ n := by simp only [mul_assoc]
_ = 1 := by simp [h, pow_mul_pow_eq_one]
@[to_additive (attr := simp)]
lemma mul_left_iterate (a : M) : ∀ n : ℕ, (a * ·)^[n] = (a ^ n * ·)
| 0 => by ext; simp
| n + 1 => by ext; simp [pow_succ, mul_left_iterate]
@[to_additive (attr := simp)]
lemma mul_right_iterate (a : M) : ∀ n : ℕ, (· * a)^[n] = (· * a ^ n)
| 0 => by ext; simp
| n + 1 => by ext; simp [pow_succ', mul_right_iterate]
@[to_additive]
lemma mul_left_iterate_apply_one (a : M) : (a * ·)^[n] 1 = a ^ n := by simp [mul_right_iterate]
@[to_additive]
lemma mul_right_iterate_apply_one (a : M) : (· * a)^[n] 1 = a ^ n := by simp [mul_right_iterate]
@[to_additive (attr := simp)]
lemma pow_iterate (k : ℕ) : ∀ n : ℕ, (fun x : M ↦ x ^ k)^[n] = (· ^ k ^ n)
| 0 => by ext; simp
| n + 1 => by ext; simp [pow_iterate, Nat.pow_succ', pow_mul]
end Monoid
section CommMonoid
variable [CommMonoid M] {x y z : M}
@[to_additive]
theorem inv_unique (hy : x * y = 1) (hz : x * z = 1) : y = z :=
left_inv_eq_right_inv (Trans.trans (mul_comm _ _) hy) hz
@[to_additive nsmul_add] lemma mul_pow (a b : M) : ∀ n, (a * b) ^ n = a ^ n * b ^ n
| 0 => by rw [pow_zero, pow_zero, pow_zero, one_mul]
| n + 1 => by rw [pow_succ', pow_succ', pow_succ', mul_pow, mul_mul_mul_comm]
end CommMonoid
section LeftCancelMonoid
variable [Monoid M] [IsLeftCancelMul M] {a b : M}
@[to_additive (attr := simp)]
theorem mul_eq_left : a * b = a ↔ b = 1 := calc
a * b = a ↔ a * b = a * 1 := by rw [mul_one]
_ ↔ b = 1 := mul_left_cancel_iff
@[deprecated (since := "2025-03-05")] alias mul_right_eq_self := mul_eq_left
@[deprecated (since := "2025-03-05")] alias add_right_eq_self := add_eq_left
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] mul_right_eq_self
@[to_additive (attr := simp)]
theorem left_eq_mul : a = a * b ↔ b = 1 :=
eq_comm.trans mul_eq_left
@[deprecated (since := "2025-03-05")] alias self_eq_mul_right := left_eq_mul
@[deprecated (since := "2025-03-05")] alias self_eq_add_right := left_eq_add
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] self_eq_mul_right
@[to_additive]
theorem mul_ne_left : a * b ≠ a ↔ b ≠ 1 := mul_eq_left.not
@[deprecated (since := "2025-03-05")] alias mul_right_ne_self := mul_ne_left
@[deprecated (since := "2025-03-05")] alias add_right_ne_self := add_ne_left
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] mul_right_ne_self
@[to_additive]
theorem left_ne_mul : a ≠ a * b ↔ b ≠ 1 := left_eq_mul.not
@[deprecated (since := "2025-03-05")] alias self_ne_mul_right := left_ne_mul
@[deprecated (since := "2025-03-05")] alias self_ne_add_right := left_ne_add
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] self_ne_mul_right
end LeftCancelMonoid
section RightCancelMonoid
variable [RightCancelMonoid M] {a b : M}
@[to_additive (attr := simp)]
theorem mul_eq_right : a * b = b ↔ a = 1 := calc
a * b = b ↔ a * b = 1 * b := by rw [one_mul]
_ ↔ a = 1 := mul_right_cancel_iff
@[deprecated (since := "2025-03-05")] alias mul_left_eq_self := mul_eq_right
@[deprecated (since := "2025-03-05")] alias add_left_eq_self := add_eq_right
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] mul_left_eq_self
@[to_additive (attr := simp)]
theorem right_eq_mul : b = a * b ↔ a = 1 :=
eq_comm.trans mul_eq_right
@[deprecated (since := "2025-03-05")] alias self_eq_mul_left := right_eq_mul
@[deprecated (since := "2025-03-05")] alias self_eq_add_left := right_eq_add
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] self_eq_mul_left
@[to_additive]
theorem mul_ne_right : a * b ≠ b ↔ a ≠ 1 := mul_eq_right.not
@[deprecated (since := "2025-03-05")] alias mul_left_ne_self := mul_ne_right
@[deprecated (since := "2025-03-05")] alias add_left_ne_self := add_ne_right
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] mul_left_ne_self
@[to_additive]
theorem right_ne_mul : b ≠ a * b ↔ a ≠ 1 := right_eq_mul.not
@[deprecated (since := "2025-03-05")] alias self_ne_mul_left := right_ne_mul
@[deprecated (since := "2025-03-05")] alias self_ne_add_left := right_ne_add
set_option linter.existingAttributeWarning false in
attribute [to_additive existing] self_ne_mul_left
end RightCancelMonoid
section CancelCommMonoid
variable [CancelCommMonoid α] {a b c d : α}
@[to_additive] lemma eq_iff_eq_of_mul_eq_mul (h : a * b = c * d) : a = c ↔ b = d := by aesop
@[to_additive] lemma ne_iff_ne_of_mul_eq_mul (h : a * b = c * d) : a ≠ c ↔ b ≠ d := by aesop
end CancelCommMonoid
section InvolutiveInv
variable [InvolutiveInv G] {a b : G}
@[to_additive (attr := simp)]
theorem inv_involutive : Function.Involutive (Inv.inv : G → G) :=
inv_inv
@[to_additive (attr := simp)]
theorem inv_surjective : Function.Surjective (Inv.inv : G → G) :=
inv_involutive.surjective
@[to_additive]
theorem inv_injective : Function.Injective (Inv.inv : G → G) :=
inv_involutive.injective
@[to_additive (attr := simp)]
theorem inv_inj : a⁻¹ = b⁻¹ ↔ a = b :=
inv_injective.eq_iff
@[to_additive]
theorem inv_eq_iff_eq_inv : a⁻¹ = b ↔ a = b⁻¹ :=
⟨fun h => h ▸ (inv_inv a).symm, fun h => h.symm ▸ inv_inv b⟩
variable (G)
@[to_additive]
theorem inv_comp_inv : Inv.inv ∘ Inv.inv = @id G :=
inv_involutive.comp_self
@[to_additive]
theorem leftInverse_inv : LeftInverse (fun a : G ↦ a⁻¹) fun a ↦ a⁻¹ :=
inv_inv
@[to_additive]
theorem rightInverse_inv : RightInverse (fun a : G ↦ a⁻¹) fun a ↦ a⁻¹ :=
inv_inv
end InvolutiveInv
section DivInvMonoid
variable [DivInvMonoid G]
@[to_additive]
theorem mul_one_div (x y : G) : x * (1 / y) = x / y := by
rw [div_eq_mul_inv, one_mul, div_eq_mul_inv]
@[to_additive, field_simps] -- The attributes are out of order on purpose
theorem mul_div_assoc' (a b c : G) : a * (b / c) = a * b / c :=
(mul_div_assoc _ _ _).symm
@[to_additive]
theorem mul_div (a b c : G) : a * (b / c) = a * b / c := by simp only [mul_assoc, div_eq_mul_inv]
@[to_additive]
theorem div_eq_mul_one_div (a b : G) : a / b = a * (1 / b) := by rw [div_eq_mul_inv, one_div]
end DivInvMonoid
section DivInvOneMonoid
variable [DivInvOneMonoid G]
@[to_additive (attr := simp)]
theorem div_one (a : G) : a / 1 = a := by simp [div_eq_mul_inv]
@[to_additive]
theorem one_div_one : (1 : G) / 1 = 1 :=
div_one _
end DivInvOneMonoid
section DivisionMonoid
variable [DivisionMonoid α] {a b c d : α}
attribute [local simp] mul_assoc div_eq_mul_inv
@[to_additive]
theorem eq_inv_of_mul_eq_one_right (h : a * b = 1) : b = a⁻¹ :=
(inv_eq_of_mul_eq_one_right h).symm
@[to_additive]
theorem eq_one_div_of_mul_eq_one_left (h : b * a = 1) : b = 1 / a := by
rw [eq_inv_of_mul_eq_one_left h, one_div]
@[to_additive]
theorem eq_one_div_of_mul_eq_one_right (h : a * b = 1) : b = 1 / a := by
rw [eq_inv_of_mul_eq_one_right h, one_div]
@[to_additive]
theorem eq_of_div_eq_one (h : a / b = 1) : a = b :=
inv_injective <| inv_eq_of_mul_eq_one_right <| by rwa [← div_eq_mul_inv]
@[to_additive]
lemma eq_of_inv_mul_eq_one (h : a⁻¹ * b = 1) : a = b := by simpa using eq_inv_of_mul_eq_one_left h
@[to_additive]
lemma eq_of_mul_inv_eq_one (h : a * b⁻¹ = 1) : a = b := by simpa using eq_inv_of_mul_eq_one_left h
@[to_additive]
theorem div_ne_one_of_ne : a ≠ b → a / b ≠ 1 :=
mt eq_of_div_eq_one
variable (a b c)
@[to_additive]
theorem one_div_mul_one_div_rev : 1 / a * (1 / b) = 1 / (b * a) := by simp
@[to_additive]
theorem inv_div_left : a⁻¹ / b = (b * a)⁻¹ := by simp
@[to_additive (attr := simp)]
theorem inv_div : (a / b)⁻¹ = b / a := by simp
@[to_additive]
theorem one_div_div : 1 / (a / b) = b / a := by simp
@[to_additive]
theorem one_div_one_div : 1 / (1 / a) = a := by simp
@[to_additive]
theorem div_eq_div_iff_comm : a / b = c / d ↔ b / a = d / c :=
inv_inj.symm.trans <| by simp only [inv_div]
@[to_additive]
instance (priority := 100) DivisionMonoid.toDivInvOneMonoid : DivInvOneMonoid α :=
{ DivisionMonoid.toDivInvMonoid with
inv_one := by simpa only [one_div, inv_inv] using (inv_div (1 : α) 1).symm }
@[to_additive (attr := simp)]
lemma inv_pow (a : α) : ∀ n : ℕ, a⁻¹ ^ n = (a ^ n)⁻¹
| 0 => by rw [pow_zero, pow_zero, inv_one]
| n + 1 => by rw [pow_succ', pow_succ, inv_pow _ n, mul_inv_rev]
-- the attributes are intentionally out of order. `smul_zero` proves `zsmul_zero`.
@[to_additive zsmul_zero, simp]
lemma one_zpow : ∀ n : ℤ, (1 : α) ^ n = 1
| (n : ℕ) => by rw [zpow_natCast, one_pow]
| .negSucc n => by rw [zpow_negSucc, one_pow, inv_one]
@[to_additive (attr := simp) neg_zsmul]
lemma zpow_neg (a : α) : ∀ n : ℤ, a ^ (-n) = (a ^ n)⁻¹
| (_ + 1 : ℕ) => DivInvMonoid.zpow_neg' _ _
| 0 => by simp
| Int.negSucc n => by
rw [zpow_negSucc, inv_inv, ← zpow_natCast]
rfl
@[to_additive neg_one_zsmul_add]
lemma mul_zpow_neg_one (a b : α) : (a * b) ^ (-1 : ℤ) = b ^ (-1 : ℤ) * a ^ (-1 : ℤ) := by
simp only [zpow_neg, zpow_one, mul_inv_rev]
@[to_additive zsmul_neg]
lemma inv_zpow (a : α) : ∀ n : ℤ, a⁻¹ ^ n = (a ^ n)⁻¹
| (n : ℕ) => by rw [zpow_natCast, zpow_natCast, inv_pow]
| .negSucc n => by rw [zpow_negSucc, zpow_negSucc, inv_pow]
@[to_additive (attr := simp) zsmul_neg']
lemma inv_zpow' (a : α) (n : ℤ) : a⁻¹ ^ n = a ^ (-n) := by rw [inv_zpow, zpow_neg]
@[to_additive nsmul_zero_sub]
lemma one_div_pow (a : α) (n : ℕ) : (1 / a) ^ n = 1 / a ^ n := by simp only [one_div, inv_pow]
@[to_additive zsmul_zero_sub]
lemma one_div_zpow (a : α) (n : ℤ) : (1 / a) ^ n = 1 / a ^ n := by simp only [one_div, inv_zpow]
variable {a b c}
@[to_additive (attr := simp)]
theorem inv_eq_one : a⁻¹ = 1 ↔ a = 1 :=
inv_injective.eq_iff' inv_one
@[to_additive (attr := simp)]
theorem one_eq_inv : 1 = a⁻¹ ↔ a = 1 :=
eq_comm.trans inv_eq_one
@[to_additive]
theorem inv_ne_one : a⁻¹ ≠ 1 ↔ a ≠ 1 :=
inv_eq_one.not
@[to_additive]
theorem eq_of_one_div_eq_one_div (h : 1 / a = 1 / b) : a = b := by
rw [← one_div_one_div a, h, one_div_one_div]
-- Note that `mul_zsmul` and `zpow_mul` have the primes swapped
-- when additivised since their argument order,
-- and therefore the more "natural" choice of lemma, is reversed.
@[to_additive mul_zsmul'] lemma zpow_mul (a : α) : ∀ m n : ℤ, a ^ (m * n) = (a ^ m) ^ n
| (m : ℕ), (n : ℕ) => by
rw [zpow_natCast, zpow_natCast, ← pow_mul, ← zpow_natCast]
rfl
| (m : ℕ), .negSucc n => by
rw [zpow_natCast, zpow_negSucc, ← pow_mul, Int.ofNat_mul_negSucc, zpow_neg, inv_inj,
← zpow_natCast]
| .negSucc m, (n : ℕ) => by
rw [zpow_natCast, zpow_negSucc, ← inv_pow, ← pow_mul, Int.negSucc_mul_ofNat, zpow_neg, inv_pow,
inv_inj, ← zpow_natCast]
| .negSucc m, .negSucc n => by
rw [zpow_negSucc, zpow_negSucc, Int.negSucc_mul_negSucc, inv_pow, inv_inv, ← pow_mul, ←
zpow_natCast]
rfl
@[to_additive mul_zsmul]
lemma zpow_mul' (a : α) (m n : ℤ) : a ^ (m * n) = (a ^ n) ^ m := by rw [Int.mul_comm, zpow_mul]
@[to_additive]
theorem zpow_comm (a : α) (m n : ℤ) : (a ^ m) ^ n = (a ^ n) ^ m := by rw [← zpow_mul, zpow_mul']
variable (a b c)
@[to_additive, field_simps] -- The attributes are out of order on purpose
theorem div_div_eq_mul_div : a / (b / c) = a * c / b := by simp
@[to_additive (attr := simp)]
theorem div_inv_eq_mul : a / b⁻¹ = a * b := by simp
@[to_additive]
theorem div_mul_eq_div_div_swap : a / (b * c) = a / c / b := by
simp only [mul_assoc, mul_inv_rev, div_eq_mul_inv]
end DivisionMonoid
section DivisionCommMonoid
variable [DivisionCommMonoid α] (a b c d : α)
attribute [local simp] mul_assoc mul_comm mul_left_comm div_eq_mul_inv
@[to_additive neg_add]
theorem mul_inv : (a * b)⁻¹ = a⁻¹ * b⁻¹ := by simp
@[to_additive]
theorem inv_div' : (a / b)⁻¹ = a⁻¹ / b⁻¹ := by simp
@[to_additive]
theorem div_eq_inv_mul : a / b = b⁻¹ * a := by simp
@[to_additive]
theorem inv_mul_eq_div : a⁻¹ * b = b / a := by simp
@[to_additive] lemma inv_div_comm (a b : α) : a⁻¹ / b = b⁻¹ / a := by simp
@[to_additive]
| Mathlib/Algebra/Group/Basic.lean | 554 | 554 | theorem inv_mul' : (a * b)⁻¹ = a⁻¹ / b := by | simp |
/-
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.Group.Commute.Basic
import Mathlib.Algebra.Group.Pointwise.Set.Finite
import Mathlib.Algebra.Group.Subgroup.Finite
import Mathlib.Algebra.Module.NatInt
import Mathlib.Algebra.Order.Group.Action
import Mathlib.Algebra.Order.Ring.Abs
import Mathlib.Data.Int.ModEq
import Mathlib.Dynamics.PeriodicPts.Lemmas
import Mathlib.GroupTheory.Index
import Mathlib.NumberTheory.Divisors
import Mathlib.Order.Interval.Set.Infinite
/-!
# 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
-/
assert_not_exists Field
open Function Fintype Nat Pointwise Subgroup Submonoid
open scoped Finset
variable {G H A α β : Type*}
section Monoid
variable [Monoid G] {a b x y : G} {n m : ℕ}
section IsOfFinOrder
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/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]
/-- `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 * ·)
theorem isOfFinAddOrder_ofMul_iff : IsOfFinAddOrder (Additive.ofMul x) ↔ IsOfFinOrder x :=
Iff.rfl
theorem isOfFinOrder_ofAdd_iff {α : Type*} [AddMonoid α] {x : α} :
IsOfFinOrder (Multiplicative.ofAdd x) ↔ IsOfFinAddOrder x := Iff.rfl
@[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]
@[to_additive] alias ⟨IsOfFinOrder.exists_pow_eq_one, _⟩ := isOfFinOrder_iff_pow_eq_one
@[to_additive]
lemma isOfFinOrder_iff_zpow_eq_one {G} [DivisionMonoid 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, ?_⟩⟩
rcases (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
/-- 1 is of finite order in any monoid. -/
@[to_additive (attr := simp) "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⟩
@[to_additive]
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]⟩
@[to_additive]
lemma IsOfFinOrder.of_pow {n : ℕ} (h : IsOfFinOrder (a ^ n)) (hn : n ≠ 0) : IsOfFinOrder a := by
rw [isOfFinOrder_iff_pow_eq_one] at *
rcases h with ⟨m, hm, ha⟩
exact ⟨n * m, mul_pos hn.bot_lt hm, by rwa [pow_mul]⟩
@[to_additive (attr := simp)]
lemma isOfFinOrder_pow {n : ℕ} : IsOfFinOrder (a ^ n) ↔ IsOfFinOrder a ∨ n = 0 := by
rcases Decidable.eq_or_ne n 0 with rfl | hn
· simp
· exact ⟨fun h ↦ .inl <| h.of_pow hn, fun h ↦ (h.resolve_right hn).pow⟩
/-- 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
theorem IsConj.isOfFinOrder (h : IsConj x y) : IsOfFinOrder x → IsOfFinOrder y := by
simp_rw [isOfFinOrder_iff_pow_eq_one]
rintro ⟨n, n_gt_0, eq'⟩
exact ⟨n, n_gt_0, by rw [← isConj_one_right, ← eq']; exact h.pow n⟩
/-- 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]⟩
/-- 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⟩
/-- 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
@[simp]
theorem addOrderOf_ofMul_eq_orderOf (x : G) : addOrderOf (Additive.ofMul x) = orderOf x :=
rfl
@[simp]
lemma orderOf_ofAdd_eq_addOrderOf {α : Type*} [AddMonoid α] (a : α) :
orderOf (Multiplicative.ofAdd a) = addOrderOf a := rfl
@[to_additive]
protected lemma IsOfFinOrder.orderOf_pos (h : IsOfFinOrder x) : 0 < orderOf x :=
minimalPeriod_pos_of_mem_periodicPts h
@[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 (https://github.com/leanprover-community/mathlib4/issues/12129): additional beta reduction needed in the middle of the rewrite
rw [orderOf, mul_left_iterate]; beta_reduce; rw [mul_one]
@[to_additive]
theorem orderOf_eq_zero (h : ¬IsOfFinOrder x) : orderOf x = 0 := by
rwa [orderOf, minimalPeriod, dif_neg]
@[to_additive]
theorem orderOf_eq_zero_iff : orderOf x = 0 ↔ ¬IsOfFinOrder x :=
⟨fun h H ↦ H.orderOf_pos.ne' h, orderOf_eq_zero⟩
@[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]
@[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'⟩
/-- 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]
@[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
@[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)
@[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])
@[to_additive (attr := simp)]
theorem orderOf_one : orderOf (1 : G) = 1 := by
rw [orderOf, ← minimalPeriod_id (x := (1 : G)), ← one_mul_eq_id]
@[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]
@[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]
@[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)
@[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⟩
@[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]
@[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)
@[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 _
@[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
@[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]
@[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
@[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]⟩
/-- 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`
obtain ⟨a, ha⟩ := exists_eq_mul_right_of_dvd (orderOf_dvd_of_pow_eq_one hx)
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_mul_dvd 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⟩)
@[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]
/-- 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]
/-- 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.toMonoidHom 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
@[to_additive]
| Mathlib/GroupTheory/OrderOfElement.lean | 338 | 355 | theorem orderOf_units {y : Gˣ} : orderOf (y : G) = orderOf y :=
orderOf_injective (Units.coeHom G) Units.ext y
/-- If the order of `x` is finite, then `x` is a unit with inverse `x ^ (orderOf x - 1)`. -/
@[to_additive (attr := simps) "If the additive order of `x` is finite, then `x` is an additive
unit with inverse `(addOrderOf x - 1) • x`. "]
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]⟩
@[to_additive]
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 | |
/-
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, Kenny Lau, Johan Commelin, Mario Carneiro, Kevin Buzzard,
Amelia Livingston, Yury Kudryashov
-/
import Mathlib.Algebra.BigOperators.Group.Multiset.Defs
import Mathlib.Algebra.FreeMonoid.Basic
import Mathlib.Algebra.Group.Idempotent
import Mathlib.Algebra.Group.Nat.Hom
import Mathlib.Algebra.Group.Submonoid.MulOpposite
import Mathlib.Algebra.Group.Submonoid.Operations
import Mathlib.Data.Fintype.EquivFin
import Mathlib.Data.Int.Basic
/-!
# Submonoids: membership criteria
In this file we prove various facts about membership in a submonoid:
* `pow_mem`, `nsmul_mem`: if `x ∈ S` where `S` is a multiplicative (resp., additive) submonoid and
`n` is a natural number, then `x^n` (resp., `n • x`) belongs to `S`;
* `mem_iSup_of_directed`, `coe_iSup_of_directed`, `mem_sSup_of_directedOn`,
`coe_sSup_of_directedOn`: the supremum of a directed collection of submonoid is their union.
* `sup_eq_range`, `mem_sup`: supremum of two submonoids `S`, `T` of a commutative monoid is the set
of products;
* `closure_singleton_eq`, `mem_closure_singleton`, `mem_closure_pair`: the multiplicative (resp.,
additive) closure of `{x}` consists of powers (resp., natural multiples) of `x`, and a similar
result holds for the closure of `{x, y}`.
## Tags
submonoid, submonoids
-/
assert_not_exists MonoidWithZero
variable {M A B : Type*}
section Assoc
variable [Monoid M] [SetLike B M] [SubmonoidClass B M] {S : B}
end Assoc
section NonAssoc
variable [MulOneClass M]
open Set
namespace Submonoid
-- TODO: this section can be generalized to `[SubmonoidClass B M] [CompleteLattice B]`
-- such that `CompleteLattice.LE` coincides with `SetLike.LE`
@[to_additive]
theorem mem_iSup_of_directed {ι} [hι : Nonempty ι] {S : ι → Submonoid M} (hS : Directed (· ≤ ·) S)
{x : M} : (x ∈ ⨆ i, S i) ↔ ∃ i, x ∈ S i := by
refine ⟨?_, fun ⟨i, hi⟩ ↦ le_iSup S i hi⟩
suffices x ∈ closure (⋃ i, (S i : Set M)) → ∃ i, x ∈ S i by
simpa only [closure_iUnion, closure_eq (S _)] using this
refine closure_induction (fun _ ↦ mem_iUnion.1) ?_ ?_
· exact hι.elim fun i ↦ ⟨i, (S i).one_mem⟩
· rintro x y - - ⟨i, hi⟩ ⟨j, hj⟩
rcases hS i j with ⟨k, hki, hkj⟩
exact ⟨k, (S k).mul_mem (hki hi) (hkj hj)⟩
@[to_additive]
theorem coe_iSup_of_directed {ι} [Nonempty ι] {S : ι → Submonoid M} (hS : Directed (· ≤ ·) S) :
((⨆ i, S i : Submonoid M) : Set M) = ⋃ i, S i :=
Set.ext fun x ↦ by simp [mem_iSup_of_directed hS]
@[to_additive]
theorem mem_sSup_of_directedOn {S : Set (Submonoid M)} (Sne : S.Nonempty)
(hS : DirectedOn (· ≤ ·) S) {x : M} : x ∈ sSup S ↔ ∃ s ∈ S, x ∈ s := by
haveI : Nonempty S := Sne.to_subtype
simp [sSup_eq_iSup', mem_iSup_of_directed hS.directed_val, SetCoe.exists, Subtype.coe_mk]
@[to_additive]
theorem coe_sSup_of_directedOn {S : Set (Submonoid M)} (Sne : S.Nonempty)
(hS : DirectedOn (· ≤ ·) S) : (↑(sSup S) : Set M) = ⋃ s ∈ S, ↑s :=
Set.ext fun x => by simp [mem_sSup_of_directedOn Sne hS]
@[to_additive]
theorem mem_sup_left {S T : Submonoid M} : ∀ {x : M}, x ∈ S → x ∈ S ⊔ T := by
rw [← SetLike.le_def]
exact le_sup_left
@[to_additive]
theorem mem_sup_right {S T : Submonoid M} : ∀ {x : M}, x ∈ T → x ∈ S ⊔ T := by
rw [← SetLike.le_def]
exact le_sup_right
@[to_additive]
theorem mul_mem_sup {S T : Submonoid M} {x y : M} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T :=
(S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy)
@[to_additive]
theorem mem_iSup_of_mem {ι : Sort*} {S : ι → Submonoid M} (i : ι) :
∀ {x : M}, x ∈ S i → x ∈ iSup S := by
rw [← SetLike.le_def]
exact le_iSup _ _
@[to_additive]
theorem mem_sSup_of_mem {S : Set (Submonoid M)} {s : Submonoid M} (hs : s ∈ S) :
∀ {x : M}, x ∈ s → x ∈ sSup S := by
rw [← SetLike.le_def]
exact le_sSup hs
/-- An induction principle for elements of `⨆ i, S i`.
If `C` holds for `1` and all elements of `S i` for all `i`, and is preserved under multiplication,
then it holds for all elements of the supremum of `S`. -/
@[to_additive (attr := elab_as_elim)
" An induction principle for elements of `⨆ i, S i`.
If `C` holds for `0` and all elements of `S i` for all `i`, and is preserved under addition,
then it holds for all elements of the supremum of `S`. "]
theorem iSup_induction {ι : Sort*} (S : ι → Submonoid M) {motive : M → Prop} {x : M}
(hx : x ∈ ⨆ i, S i) (mem : ∀ (i), ∀ x ∈ S i, motive x) (one : motive 1)
(mul : ∀ x y, motive x → motive y → motive (x * y)) : motive x := by
rw [iSup_eq_closure] at hx
refine closure_induction (fun x hx => ?_) one (fun _ _ _ _ ↦ mul _ _) hx
obtain ⟨i, hi⟩ := Set.mem_iUnion.mp hx
exact mem _ _ hi
/-- A dependent version of `Submonoid.iSup_induction`. -/
@[to_additive (attr := elab_as_elim) "A dependent version of `AddSubmonoid.iSup_induction`. "]
theorem iSup_induction' {ι : Sort*} (S : ι → Submonoid M) {motive : ∀ x, (x ∈ ⨆ i, S i) → Prop}
(mem : ∀ (i), ∀ (x) (hxS : x ∈ S i), motive x (mem_iSup_of_mem i hxS))
(one : motive 1 (one_mem _))
(mul : ∀ x y hx hy, motive x hx → motive y hy → motive (x * y) (mul_mem ‹_› ‹_›)) {x : M}
(hx : x ∈ ⨆ i, S i) : motive x hx := by
refine Exists.elim (?_ : ∃ Hx, motive x Hx) fun (hx : x ∈ ⨆ i, S i) (hc : motive x hx) => hc
refine @iSup_induction _ _ ι S (fun m => ∃ hm, motive m hm) _ hx (fun i x hx => ?_) ?_
fun x y => ?_
· exact ⟨_, mem _ _ hx⟩
· exact ⟨_, one⟩
· rintro ⟨_, Cx⟩ ⟨_, Cy⟩
exact ⟨_, mul _ _ _ _ Cx Cy⟩
end Submonoid
end NonAssoc
namespace FreeMonoid
variable {α : Type*}
open Submonoid
@[to_additive]
theorem closure_range_of : closure (Set.range <| @of α) = ⊤ :=
eq_top_iff.2 fun x _ =>
FreeMonoid.recOn x (one_mem _) fun _x _xs hxs =>
mul_mem (subset_closure <| Set.mem_range_self _) hxs
end FreeMonoid
namespace Submonoid
variable [Monoid M] {a : M}
open MonoidHom
theorem closure_singleton_eq (x : M) : closure ({x} : Set M) = mrange (powersHom M x) :=
closure_eq_of_le (Set.singleton_subset_iff.2 ⟨Multiplicative.ofAdd 1, pow_one x⟩) fun _ ⟨_, hn⟩ =>
hn ▸ pow_mem (subset_closure <| Set.mem_singleton _) _
/-- The submonoid generated by an element of a monoid equals the set of natural number powers of
the element. -/
theorem mem_closure_singleton {x y : M} : y ∈ closure ({x} : Set M) ↔ ∃ n : ℕ, x ^ n = y := by
rw [closure_singleton_eq, mem_mrange]; rfl
theorem mem_closure_singleton_self {y : M} : y ∈ closure ({y} : Set M) :=
mem_closure_singleton.2 ⟨1, pow_one y⟩
theorem closure_singleton_one : closure ({1} : Set M) = ⊥ := by
simp [eq_bot_iff_forall, mem_closure_singleton]
section Submonoid
variable {S : Submonoid M} [Fintype S]
open Fintype
/- curly brackets `{}` are used here instead of instance brackets `[]` because
the instance in a goal is often not the same as the one inferred by type class inference. -/
@[to_additive]
theorem card_bot {_ : Fintype (⊥ : Submonoid M)} : card (⊥ : Submonoid M) = 1 :=
card_eq_one_iff.2
⟨⟨(1 : M), Set.mem_singleton 1⟩, fun ⟨_y, hy⟩ => Subtype.eq <| mem_bot.1 hy⟩
@[to_additive]
theorem eq_bot_of_card_le (h : card S ≤ 1) : S = ⊥ :=
let _ := card_le_one_iff_subsingleton.mp h
eq_bot_of_subsingleton S
@[to_additive]
theorem eq_bot_of_card_eq (h : card S = 1) : S = ⊥ :=
S.eq_bot_of_card_le (le_of_eq h)
@[to_additive card_le_one_iff_eq_bot]
theorem card_le_one_iff_eq_bot : card S ≤ 1 ↔ S = ⊥ :=
⟨fun h =>
(eq_bot_iff_forall _).2 fun x hx => by
simpa [Subtype.ext_iff] using card_le_one_iff.1 h ⟨x, hx⟩ 1,
fun h => by simp [h]⟩
@[to_additive]
lemma eq_bot_iff_card : S = ⊥ ↔ card S = 1 :=
⟨by rintro rfl; exact card_bot, eq_bot_of_card_eq⟩
end Submonoid
@[to_additive]
theorem _root_.FreeMonoid.mrange_lift {α} (f : α → M) :
mrange (FreeMonoid.lift f) = closure (Set.range f) := by
rw [mrange_eq_map, ← FreeMonoid.closure_range_of, map_mclosure, ← Set.range_comp,
FreeMonoid.lift_comp_of]
@[to_additive]
theorem closure_eq_mrange (s : Set M) : closure s = mrange (FreeMonoid.lift ((↑) : s → M)) := by
rw [FreeMonoid.mrange_lift, Subtype.range_coe]
@[to_additive]
theorem closure_eq_image_prod (s : Set M) :
(closure s : Set M) = List.prod '' { l : List M | ∀ x ∈ l, x ∈ s } := by
rw [closure_eq_mrange, coe_mrange, ← Set.range_list_map_coe, ← Set.range_comp]
exact congrArg _ (funext <| FreeMonoid.lift_apply _)
@[to_additive]
| Mathlib/Algebra/Group/Submonoid/Membership.lean | 227 | 229 | theorem exists_list_of_mem_closure {s : Set M} {x : M} (hx : x ∈ closure s) :
∃ l : List M, (∀ y ∈ l, y ∈ s) ∧ l.prod = x := by | rwa [← SetLike.mem_coe, closure_eq_image_prod, Set.mem_image] at hx |
/-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Jalex Stark, Kyle Miller, Lu-Ming Zhang
-/
import Mathlib.Combinatorics.SimpleGraph.Basic
import Mathlib.Combinatorics.SimpleGraph.Connectivity.WalkCounting
import Mathlib.LinearAlgebra.Matrix.Trace
import Mathlib.LinearAlgebra.Matrix.Symmetric
/-!
# Adjacency Matrices
This module defines the adjacency matrix of a graph, and provides theorems connecting graph
properties to computational properties of the matrix.
## Main definitions
* `Matrix.IsAdjMatrix`: `A : Matrix V V α` is qualified as an "adjacency matrix" if
(1) every entry of `A` is `0` or `1`,
(2) `A` is symmetric,
(3) every diagonal entry of `A` is `0`.
* `Matrix.IsAdjMatrix.to_graph`: for `A : Matrix V V α` and `h : A.IsAdjMatrix`,
`h.to_graph` is the simple graph induced by `A`.
* `Matrix.compl`: for `A : Matrix V V α`, `A.compl` is supposed to be
the adjacency matrix of the complement graph of the graph induced by `A`.
* `SimpleGraph.adjMatrix`: the adjacency matrix of a `SimpleGraph`.
* `SimpleGraph.adjMatrix_pow_apply_eq_card_walk`: each entry of the `n`th power of
a graph's adjacency matrix counts the number of length-`n` walks between the corresponding
pair of vertices.
-/
open Matrix
open Finset Matrix SimpleGraph
variable {V α : Type*}
namespace Matrix
/-- `A : Matrix V V α` is qualified as an "adjacency matrix" if
(1) every entry of `A` is `0` or `1`,
(2) `A` is symmetric,
(3) every diagonal entry of `A` is `0`. -/
structure IsAdjMatrix [Zero α] [One α] (A : Matrix V V α) : Prop where
zero_or_one : ∀ i j, A i j = 0 ∨ A i j = 1 := by aesop
symm : A.IsSymm := by aesop
apply_diag : ∀ i, A i i = 0 := by aesop
namespace IsAdjMatrix
variable {A : Matrix V V α}
@[simp]
theorem apply_diag_ne [MulZeroOneClass α] [Nontrivial α] (h : IsAdjMatrix A) (i : V) :
¬A i i = 1 := by simp [h.apply_diag i]
@[simp]
theorem apply_ne_one_iff [MulZeroOneClass α] [Nontrivial α] (h : IsAdjMatrix A) (i j : V) :
¬A i j = 1 ↔ A i j = 0 := by obtain h | h := h.zero_or_one i j <;> simp [h]
@[simp]
theorem apply_ne_zero_iff [MulZeroOneClass α] [Nontrivial α] (h : IsAdjMatrix A) (i j : V) :
¬A i j = 0 ↔ A i j = 1 := by rw [← apply_ne_one_iff h, Classical.not_not]
/-- For `A : Matrix V V α` and `h : IsAdjMatrix A`,
`h.toGraph` is the simple graph whose adjacency matrix is `A`. -/
@[simps]
def toGraph [MulZeroOneClass α] [Nontrivial α] (h : IsAdjMatrix A) : SimpleGraph V where
Adj i j := A i j = 1
symm i j hij := by simp only; rwa [h.symm.apply i j]
loopless i := by simp [h]
instance [MulZeroOneClass α] [Nontrivial α] [DecidableEq α] (h : IsAdjMatrix A) :
DecidableRel h.toGraph.Adj := by
simp only [toGraph]
infer_instance
end IsAdjMatrix
/-- For `A : Matrix V V α`, `A.compl` is supposed to be the adjacency matrix of
the complement graph of the graph induced by `A.adjMatrix`. -/
def compl [Zero α] [One α] [DecidableEq α] [DecidableEq V] (A : Matrix V V α) : Matrix V V α :=
fun i j => ite (i = j) 0 (ite (A i j = 0) 1 0)
section Compl
variable [DecidableEq α] [DecidableEq V] (A : Matrix V V α)
@[simp]
theorem compl_apply_diag [Zero α] [One α] (i : V) : A.compl i i = 0 := by simp [compl]
@[simp]
theorem compl_apply [Zero α] [One α] (i j : V) : A.compl i j = 0 ∨ A.compl i j = 1 := by
unfold compl
split_ifs <;> simp
@[simp]
theorem isSymm_compl [Zero α] [One α] (h : A.IsSymm) : A.compl.IsSymm := by
ext
simp [compl, h.apply, eq_comm]
@[simp]
theorem isAdjMatrix_compl [Zero α] [One α] (h : A.IsSymm) : IsAdjMatrix A.compl :=
{ symm := by simp [h] }
namespace IsAdjMatrix
variable {A}
@[simp]
theorem compl [Zero α] [One α] (h : IsAdjMatrix A) : IsAdjMatrix A.compl :=
isAdjMatrix_compl A h.symm
theorem toGraph_compl_eq [MulZeroOneClass α] [Nontrivial α] (h : IsAdjMatrix A) :
h.compl.toGraph = h.toGraphᶜ := by
ext v w
rcases h.zero_or_one v w with h | h <;> by_cases hvw : v = w <;> simp [Matrix.compl, h, hvw]
end IsAdjMatrix
end Compl
end Matrix
open Matrix
namespace SimpleGraph
variable (G : SimpleGraph V) [DecidableRel G.Adj]
variable (α) in
/-- `adjMatrix G α` is the matrix `A` such that `A i j = (1 : α)` if `i` and `j` are
adjacent in the simple graph `G`, and otherwise `A i j = 0`. -/
def adjMatrix [Zero α] [One α] : Matrix V V α :=
of fun i j => if G.Adj i j then (1 : α) else 0
-- TODO: set as an equation lemma for `adjMatrix`, see https://github.com/leanprover-community/mathlib4/pull/3024
@[simp]
theorem adjMatrix_apply (v w : V) [Zero α] [One α] :
G.adjMatrix α v w = if G.Adj v w then 1 else 0 :=
rfl
@[simp]
theorem transpose_adjMatrix [Zero α] [One α] : (G.adjMatrix α)ᵀ = G.adjMatrix α := by
ext
simp [adj_comm]
@[simp]
theorem isSymm_adjMatrix [Zero α] [One α] : (G.adjMatrix α).IsSymm :=
transpose_adjMatrix G
variable (α)
/-- The adjacency matrix of `G` is an adjacency matrix. -/
@[simp]
theorem isAdjMatrix_adjMatrix [Zero α] [One α] : (G.adjMatrix α).IsAdjMatrix :=
{ zero_or_one := fun i j => by by_cases h : G.Adj i j <;> simp [h] }
/-- The graph induced by the adjacency matrix of `G` is `G` itself. -/
theorem toGraph_adjMatrix_eq [MulZeroOneClass α] [Nontrivial α] :
(G.isAdjMatrix_adjMatrix α).toGraph = G := by
ext
simp only [IsAdjMatrix.toGraph_adj, adjMatrix_apply, ite_eq_left_iff, zero_ne_one]
apply Classical.not_not
variable {α}
/-- The sum of the identity, the adjacency matrix, and its complement is the all-ones matrix. -/
theorem one_add_adjMatrix_add_compl_adjMatrix_eq_allOnes [DecidableEq V] [DecidableEq α]
[AddMonoidWithOne α] : 1 + G.adjMatrix α + (G.adjMatrix α).compl = Matrix.of fun _ _ ↦ 1 := by
ext i j
unfold Matrix.compl
rw [of_apply, add_apply, adjMatrix_apply, add_apply, adjMatrix_apply, one_apply]
by_cases h : G.Adj i j
· aesop
· split_ifs <;> simp_all
variable [Fintype V]
@[simp]
theorem adjMatrix_dotProduct [NonAssocSemiring α] (v : V) (vec : V → α) :
dotProduct (G.adjMatrix α v) vec = ∑ u ∈ G.neighborFinset v, vec u := by
simp [neighborFinset_eq_filter, dotProduct, sum_filter]
@[simp]
theorem dotProduct_adjMatrix [NonAssocSemiring α] (v : V) (vec : V → α) :
dotProduct vec (G.adjMatrix α v) = ∑ u ∈ G.neighborFinset v, vec u := by
simp [neighborFinset_eq_filter, dotProduct, sum_filter, Finset.sum_apply]
@[simp]
theorem adjMatrix_mulVec_apply [NonAssocSemiring α] (v : V) (vec : V → α) :
(G.adjMatrix α *ᵥ vec) v = ∑ u ∈ G.neighborFinset v, vec u := by
rw [mulVec, adjMatrix_dotProduct]
@[simp]
theorem adjMatrix_vecMul_apply [NonAssocSemiring α] (v : V) (vec : V → α) :
(vec ᵥ* G.adjMatrix α) v = ∑ u ∈ G.neighborFinset v, vec u := by
simp only [← dotProduct_adjMatrix, vecMul]
refine congr rfl ?_; ext x
rw [← transpose_apply (adjMatrix α G) x v, transpose_adjMatrix]
@[simp]
theorem adjMatrix_mul_apply [NonAssocSemiring α] (M : Matrix V V α) (v w : V) :
(G.adjMatrix α * M) v w = ∑ u ∈ G.neighborFinset v, M u w := by
simp [mul_apply, neighborFinset_eq_filter, sum_filter]
@[simp]
theorem mul_adjMatrix_apply [NonAssocSemiring α] (M : Matrix V V α) (v w : V) :
(M * G.adjMatrix α) v w = ∑ u ∈ G.neighborFinset w, M v u := by
simp [mul_apply, neighborFinset_eq_filter, sum_filter, adj_comm]
variable (α) in
@[simp]
theorem trace_adjMatrix [AddCommMonoid α] [One α] : Matrix.trace (G.adjMatrix α) = 0 := by
simp [Matrix.trace]
| Mathlib/Combinatorics/SimpleGraph/AdjMatrix.lean | 224 | 226 | theorem adjMatrix_mul_self_apply_self [NonAssocSemiring α] (i : V) :
(G.adjMatrix α * G.adjMatrix α) i i = degree G i := by | simp [filter_true_of_mem] |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker
-/
import Mathlib.Algebra.Polynomial.Reverse
import Mathlib.Algebra.Regular.SMul
/-!
# Theory of monic polynomials
We give several tools for proving that polynomials are monic, e.g.
`Monic.mul`, `Monic.map`, `Monic.pow`.
-/
noncomputable section
open Finset
open Polynomial
namespace Polynomial
universe u v y
variable {R : Type u} {S : Type v} {a b : R} {m n : ℕ} {ι : Type y}
section Semiring
variable [Semiring R] {p q r : R[X]}
theorem monic_zero_iff_subsingleton : Monic (0 : R[X]) ↔ Subsingleton R :=
subsingleton_iff_zero_eq_one
theorem not_monic_zero_iff : ¬Monic (0 : R[X]) ↔ (0 : R) ≠ 1 :=
(monic_zero_iff_subsingleton.trans subsingleton_iff_zero_eq_one.symm).not
theorem monic_zero_iff_subsingleton' :
Monic (0 : R[X]) ↔ (∀ f g : R[X], f = g) ∧ ∀ a b : R, a = b :=
Polynomial.monic_zero_iff_subsingleton.trans
⟨by
intro
simp [eq_iff_true_of_subsingleton], fun h => subsingleton_iff.mpr h.2⟩
theorem Monic.as_sum (hp : p.Monic) :
p = X ^ p.natDegree + ∑ i ∈ range p.natDegree, C (p.coeff i) * X ^ i := by
conv_lhs => rw [p.as_sum_range_C_mul_X_pow, sum_range_succ_comm]
suffices C (p.coeff p.natDegree) = 1 by rw [this, one_mul]
exact congr_arg C hp
theorem ne_zero_of_ne_zero_of_monic (hp : p ≠ 0) (hq : Monic q) : q ≠ 0 := by
rintro rfl
rw [Monic.def, leadingCoeff_zero] at hq
rw [← mul_one p, ← C_1, ← hq, C_0, mul_zero] at hp
exact hp rfl
theorem Monic.map [Semiring S] (f : R →+* S) (hp : Monic p) : Monic (p.map f) := by
unfold Monic
nontriviality
have : f p.leadingCoeff ≠ 0 := by
rw [show _ = _ from hp, f.map_one]
exact one_ne_zero
rw [Polynomial.leadingCoeff, coeff_map]
suffices p.coeff (p.map f).natDegree = 1 by simp [this]
rwa [natDegree_eq_of_degree_eq (degree_map_eq_of_leadingCoeff_ne_zero f this)]
theorem monic_C_mul_of_mul_leadingCoeff_eq_one {b : R} (hp : b * p.leadingCoeff = 1) :
Monic (C b * p) := by
unfold Monic
nontriviality
rw [leadingCoeff_mul' _] <;> simp [leadingCoeff_C b, hp]
theorem monic_mul_C_of_leadingCoeff_mul_eq_one {b : R} (hp : p.leadingCoeff * b = 1) :
Monic (p * C b) := by
unfold Monic
nontriviality
rw [leadingCoeff_mul' _] <;> simp [leadingCoeff_C b, hp]
theorem monic_of_degree_le (n : ℕ) (H1 : degree p ≤ n) (H2 : coeff p n = 1) : Monic p :=
Decidable.byCases
(fun H : degree p < n => eq_of_zero_eq_one (H2 ▸ (coeff_eq_zero_of_degree_lt H).symm) _ _)
fun H : ¬degree p < n => by
rwa [Monic, Polynomial.leadingCoeff, natDegree, (lt_or_eq_of_le H1).resolve_left H]
theorem monic_X_pow_add {n : ℕ} (H : degree p < n) : Monic (X ^ n + p) :=
monic_of_degree_le n
(le_trans (degree_add_le _ _) (max_le (degree_X_pow_le _) (le_of_lt H)))
(by rw [coeff_add, coeff_X_pow, if_pos rfl, coeff_eq_zero_of_degree_lt H, add_zero])
variable (a) in
theorem monic_X_pow_add_C {n : ℕ} (h : n ≠ 0) : (X ^ n + C a).Monic :=
monic_X_pow_add <| (lt_of_le_of_lt degree_C_le
(by simp only [Nat.cast_pos, Nat.pos_iff_ne_zero, ne_eq, h, not_false_eq_true]))
theorem monic_X_add_C (x : R) : Monic (X + C x) :=
pow_one (X : R[X]) ▸ monic_X_pow_add_C x one_ne_zero
theorem Monic.mul (hp : Monic p) (hq : Monic q) : Monic (p * q) :=
letI := Classical.decEq R
if h0 : (0 : R) = 1 then
haveI := subsingleton_of_zero_eq_one h0
Subsingleton.elim _ _
else by
have : p.leadingCoeff * q.leadingCoeff ≠ 0 := by
simp [Monic.def.1 hp, Monic.def.1 hq, Ne.symm h0]
rw [Monic.def, leadingCoeff_mul' this, Monic.def.1 hp, Monic.def.1 hq, one_mul]
theorem Monic.pow (hp : Monic p) : ∀ n : ℕ, Monic (p ^ n)
| 0 => monic_one
| n + 1 => by
rw [pow_succ]
exact (Monic.pow hp n).mul hp
theorem Monic.add_of_left (hp : Monic p) (hpq : degree q < degree p) : Monic (p + q) := by
rwa [Monic, add_comm, leadingCoeff_add_of_degree_lt hpq]
theorem Monic.add_of_right (hq : Monic q) (hpq : degree p < degree q) : Monic (p + q) := by
rwa [Monic, leadingCoeff_add_of_degree_lt hpq]
theorem Monic.of_mul_monic_left (hp : p.Monic) (hpq : (p * q).Monic) : q.Monic := by
contrapose! hpq
rw [Monic.def] at hpq ⊢
rwa [leadingCoeff_monic_mul hp]
theorem Monic.of_mul_monic_right (hq : q.Monic) (hpq : (p * q).Monic) : p.Monic := by
contrapose! hpq
rw [Monic.def] at hpq ⊢
rwa [leadingCoeff_mul_monic hq]
namespace Monic
lemma comp (hp : p.Monic) (hq : q.Monic) (h : q.natDegree ≠ 0) : (p.comp q).Monic := by
nontriviality R
have : (p.comp q).natDegree = p.natDegree * q.natDegree :=
natDegree_comp_eq_of_mul_ne_zero <| by simp [hp.leadingCoeff, hq.leadingCoeff]
rw [Monic.def, Polynomial.leadingCoeff, this, coeff_comp_degree_mul_degree h, hp.leadingCoeff,
hq.leadingCoeff, one_pow, mul_one]
lemma comp_X_add_C (hp : p.Monic) (r : R) : (p.comp (X + C r)).Monic := by
nontriviality R
refine hp.comp (monic_X_add_C _) fun ha ↦ ?_
rw [natDegree_X_add_C] at ha
exact one_ne_zero ha
@[simp]
theorem natDegree_eq_zero_iff_eq_one (hp : p.Monic) : p.natDegree = 0 ↔ p = 1 := by
constructor <;> intro h
swap
· rw [h]
exact natDegree_one
have : p = C (p.coeff 0) := by
rw [← Polynomial.degree_le_zero_iff]
rwa [Polynomial.natDegree_eq_zero_iff_degree_le_zero] at h
rw [this]
rw [← h, ← Polynomial.leadingCoeff, Monic.def.1 hp, C_1]
@[simp]
theorem degree_le_zero_iff_eq_one (hp : p.Monic) : p.degree ≤ 0 ↔ p = 1 := by
rw [← hp.natDegree_eq_zero_iff_eq_one, natDegree_eq_zero_iff_degree_le_zero]
theorem natDegree_mul (hp : p.Monic) (hq : q.Monic) :
(p * q).natDegree = p.natDegree + q.natDegree := by
nontriviality R
apply natDegree_mul'
simp [hp.leadingCoeff, hq.leadingCoeff]
theorem degree_mul_comm (hp : p.Monic) (q : R[X]) : (p * q).degree = (q * p).degree := by
by_cases h : q = 0
· simp [h]
rw [degree_mul', hp.degree_mul]
· exact add_comm _ _
· rwa [hp.leadingCoeff, one_mul, leadingCoeff_ne_zero]
nonrec theorem natDegree_mul' (hp : p.Monic) (hq : q ≠ 0) :
(p * q).natDegree = p.natDegree + q.natDegree := by
rw [natDegree_mul']
simpa [hp.leadingCoeff, leadingCoeff_ne_zero]
theorem natDegree_mul_comm (hp : p.Monic) (q : R[X]) : (p * q).natDegree = (q * p).natDegree := by
by_cases h : q = 0
· simp [h]
rw [hp.natDegree_mul' h, Polynomial.natDegree_mul', add_comm]
simpa [hp.leadingCoeff, leadingCoeff_ne_zero]
theorem not_dvd_of_natDegree_lt (hp : Monic p) (h0 : q ≠ 0) (hl : natDegree q < natDegree p) :
¬p ∣ q := by
rintro ⟨r, rfl⟩
rw [hp.natDegree_mul' <| right_ne_zero_of_mul h0] at hl
exact hl.not_le (Nat.le_add_right _ _)
theorem not_dvd_of_degree_lt (hp : Monic p) (h0 : q ≠ 0) (hl : degree q < degree p) : ¬p ∣ q :=
Monic.not_dvd_of_natDegree_lt hp h0 <| natDegree_lt_natDegree h0 hl
theorem nextCoeff_mul (hp : Monic p) (hq : Monic q) :
nextCoeff (p * q) = nextCoeff p + nextCoeff q := by
nontriviality
simp only [← coeff_one_reverse]
rw [reverse_mul] <;> simp [hp.leadingCoeff, hq.leadingCoeff, mul_coeff_one, add_comm]
theorem nextCoeff_pow (hp : p.Monic) (n : ℕ) : (p ^ n).nextCoeff = n • p.nextCoeff := by
induction n with
| zero => rw [pow_zero, zero_smul, ← map_one (f := C), nextCoeff_C_eq_zero]
| succ n ih => rw [pow_succ, (hp.pow n).nextCoeff_mul hp, ih, succ_nsmul]
theorem eq_one_of_map_eq_one {S : Type*} [Semiring S] [Nontrivial S] (f : R →+* S) (hp : p.Monic)
(map_eq : p.map f = 1) : p = 1 := by
nontriviality R
have hdeg : p.degree = 0 := by
rw [← degree_map_eq_of_leadingCoeff_ne_zero f _, map_eq, degree_one]
· rw [hp.leadingCoeff, f.map_one]
exact one_ne_zero
have hndeg : p.natDegree = 0 :=
WithBot.coe_eq_coe.mp ((degree_eq_natDegree hp.ne_zero).symm.trans hdeg)
convert eq_C_of_degree_eq_zero hdeg
rw [← hndeg, ← Polynomial.leadingCoeff, hp.leadingCoeff, C.map_one]
theorem natDegree_pow (hp : p.Monic) (n : ℕ) : (p ^ n).natDegree = n * p.natDegree := by
induction n with
| zero => simp
| succ n hn => rw [pow_succ, (hp.pow n).natDegree_mul hp, hn, Nat.succ_mul, add_comm]
end Monic
@[simp]
theorem natDegree_pow_X_add_C [Nontrivial R] (n : ℕ) (r : R) : ((X + C r) ^ n).natDegree = n := by
rw [(monic_X_add_C r).natDegree_pow, natDegree_X_add_C, mul_one]
theorem Monic.eq_one_of_isUnit (hm : Monic p) (hpu : IsUnit p) : p = 1 := by
nontriviality R
obtain ⟨q, h⟩ := hpu.exists_right_inv
have := hm.natDegree_mul' (right_ne_zero_of_mul_eq_one h)
rw [h, natDegree_one, eq_comm, add_eq_zero] at this
exact hm.natDegree_eq_zero_iff_eq_one.mp this.1
theorem Monic.isUnit_iff (hm : p.Monic) : IsUnit p ↔ p = 1 :=
⟨hm.eq_one_of_isUnit, fun h => h.symm ▸ isUnit_one⟩
theorem eq_of_monic_of_associated (hp : p.Monic) (hq : q.Monic) (hpq : Associated p q) : p = q := by
obtain ⟨u, rfl⟩ := hpq
rw [(hp.of_mul_monic_left hq).eq_one_of_isUnit u.isUnit, mul_one]
end Semiring
section CommSemiring
variable [CommSemiring R] {p : R[X]}
theorem monic_multiset_prod_of_monic (t : Multiset ι) (f : ι → R[X]) (ht : ∀ i ∈ t, Monic (f i)) :
Monic (t.map f).prod := by
revert ht
refine t.induction_on ?_ ?_; · simp
intro a t ih ht
rw [Multiset.map_cons, Multiset.prod_cons]
exact (ht _ (Multiset.mem_cons_self _ _)).mul (ih fun _ hi => ht _ (Multiset.mem_cons_of_mem hi))
theorem monic_prod_of_monic (s : Finset ι) (f : ι → R[X]) (hs : ∀ i ∈ s, Monic (f i)) :
Monic (∏ i ∈ s, f i) :=
monic_multiset_prod_of_monic s.1 f hs
theorem monic_finprod_of_monic (α : Type*) (f : α → R[X])
(hf : ∀ i ∈ Function.mulSupport f, Monic (f i)) :
Monic (finprod f) := by
classical
rw [finprod_def]
split_ifs
· exact monic_prod_of_monic _ _ fun a ha => hf a ((Set.Finite.mem_toFinset _).mp ha)
· exact monic_one
theorem Monic.nextCoeff_multiset_prod (t : Multiset ι) (f : ι → R[X]) (h : ∀ i ∈ t, Monic (f i)) :
nextCoeff (t.map f).prod = (t.map fun i => nextCoeff (f i)).sum := by
revert h
refine Multiset.induction_on t ?_ fun a t ih ht => ?_
· simp only [Multiset.not_mem_zero, forall_prop_of_true, forall_prop_of_false, Multiset.map_zero,
Multiset.prod_zero, Multiset.sum_zero, not_false_iff, forall_true_iff]
rw [← C_1]
rw [nextCoeff_C_eq_zero]
· rw [Multiset.map_cons, Multiset.prod_cons, Multiset.map_cons, Multiset.sum_cons,
Monic.nextCoeff_mul, ih]
exacts [fun i hi => ht i (Multiset.mem_cons_of_mem hi), ht a (Multiset.mem_cons_self _ _),
monic_multiset_prod_of_monic _ _ fun b bs => ht _ (Multiset.mem_cons_of_mem bs)]
theorem Monic.nextCoeff_prod (s : Finset ι) (f : ι → R[X]) (h : ∀ i ∈ s, Monic (f i)) :
nextCoeff (∏ i ∈ s, f i) = ∑ i ∈ s, nextCoeff (f i) :=
Monic.nextCoeff_multiset_prod s.1 f h
variable [NoZeroDivisors R] {p q : R[X]}
lemma irreducible_of_monic (hp : p.Monic) (hp1 : p ≠ 1) :
Irreducible p ↔ ∀ f g : R[X], f.Monic → g.Monic → f * g = p → f = 1 ∨ g = 1 := by
refine
⟨fun h f g hf hg hp => (h.2 hp.symm).imp hf.eq_one_of_isUnit hg.eq_one_of_isUnit, fun h =>
⟨hp1 ∘ hp.eq_one_of_isUnit, fun f g hfg =>
(h (g * C f.leadingCoeff) (f * C g.leadingCoeff) ?_ ?_ ?_).symm.imp
(isUnit_of_mul_eq_one f _)
(isUnit_of_mul_eq_one g _)⟩⟩
· rwa [Monic, leadingCoeff_mul, leadingCoeff_C, ← leadingCoeff_mul, mul_comm, ← hfg, ← Monic]
· rwa [Monic, leadingCoeff_mul, leadingCoeff_C, ← leadingCoeff_mul, ← hfg, ← Monic]
· rw [mul_mul_mul_comm, ← C_mul, ← leadingCoeff_mul, ← hfg, hp.leadingCoeff, C_1, mul_one,
mul_comm, ← hfg]
lemma Monic.irreducible_iff_natDegree (hp : p.Monic) :
Irreducible p ↔
p ≠ 1 ∧ ∀ f g : R[X], f.Monic → g.Monic → f * g = p → f.natDegree = 0 ∨ g.natDegree = 0 := by
by_cases hp1 : p = 1; · simp [hp1]
rw [irreducible_of_monic hp hp1, and_iff_right hp1]
refine forall₄_congr fun a b ha hb => ?_
rw [ha.natDegree_eq_zero_iff_eq_one, hb.natDegree_eq_zero_iff_eq_one]
lemma Monic.irreducible_iff_natDegree' (hp : p.Monic) : Irreducible p ↔ p ≠ 1 ∧
∀ f g : R[X], f.Monic → g.Monic → f * g = p → g.natDegree ∉ Ioc 0 (p.natDegree / 2) := by
simp_rw [hp.irreducible_iff_natDegree, mem_Ioc, Nat.le_div_iff_mul_le zero_lt_two, mul_two]
apply and_congr_right'
constructor <;> intro h f g hf hg he <;> subst he
· rw [hf.natDegree_mul hg, add_le_add_iff_right]
exact fun ha => (h f g hf hg rfl).elim (ha.1.trans_le ha.2).ne' ha.1.ne'
· simp_rw [hf.natDegree_mul hg, pos_iff_ne_zero] at h
contrapose! h
obtain hl | hl := le_total f.natDegree g.natDegree
· exact ⟨g, f, hg, hf, mul_comm g f, h.1, add_le_add_left hl _⟩
· exact ⟨f, g, hf, hg, rfl, h.2, add_le_add_right hl _⟩
/-- Alternate phrasing of `Polynomial.Monic.irreducible_iff_natDegree'` where we only have to check
one divisor at a time. -/
lemma Monic.irreducible_iff_lt_natDegree_lt {p : R[X]} (hp : p.Monic) (hp1 : p ≠ 1) :
Irreducible p ↔ ∀ q, Monic q → natDegree q ∈ Finset.Ioc 0 (natDegree p / 2) → ¬ q ∣ p := by
rw [hp.irreducible_iff_natDegree', and_iff_right hp1]
constructor
· rintro h g hg hdg ⟨f, rfl⟩
exact h f g (hg.of_mul_monic_left hp) hg (mul_comm f g) hdg
· rintro h f g - hg rfl hdg
exact h g hg hdg (dvd_mul_left g f)
lemma Monic.not_irreducible_iff_exists_add_mul_eq_coeff (hm : p.Monic) (hnd : p.natDegree = 2) :
¬Irreducible p ↔ ∃ c₁ c₂, p.coeff 0 = c₁ * c₂ ∧ p.coeff 1 = c₁ + c₂ := by
cases subsingleton_or_nontrivial R
· simp [natDegree_of_subsingleton] at hnd
rw [hm.irreducible_iff_natDegree', and_iff_right, hnd]
· push_neg
constructor
· rintro ⟨a, b, ha, hb, rfl, hdb⟩
simp only [zero_lt_two, Nat.div_self, Nat.Ioc_succ_singleton, zero_add, mem_singleton] at hdb
have hda := hnd
rw [ha.natDegree_mul hb, hdb] at hda
use a.coeff 0, b.coeff 0, mul_coeff_zero a b
simpa only [nextCoeff, hnd, add_right_cancel hda, hdb] using ha.nextCoeff_mul hb
· rintro ⟨c₁, c₂, hmul, hadd⟩
refine
⟨X + C c₁, X + C c₂, monic_X_add_C _, monic_X_add_C _, ?_, ?_⟩
· rw [p.as_sum_range_C_mul_X_pow, hnd, Finset.sum_range_succ, Finset.sum_range_succ,
Finset.sum_range_one, ← hnd, hm.coeff_natDegree, hnd, hmul, hadd, C_mul, C_add, C_1]
ring
· rw [mem_Ioc, natDegree_X_add_C _]
simp
· rintro rfl
simp [natDegree_one] at hnd
end CommSemiring
section Semiring
variable [Semiring R]
@[simp]
theorem Monic.natDegree_map [Semiring S] [Nontrivial S] {P : R[X]} (hmo : P.Monic) (f : R →+* S) :
(P.map f).natDegree = P.natDegree := by
refine le_antisymm natDegree_map_le (le_natDegree_of_ne_zero ?_)
rw [coeff_map, Monic.coeff_natDegree hmo, RingHom.map_one]
exact one_ne_zero
@[simp]
theorem Monic.degree_map [Semiring S] [Nontrivial S] {P : R[X]} (hmo : P.Monic) (f : R →+* S) :
(P.map f).degree = P.degree := by
by_cases hP : P = 0
· simp [hP]
· refine le_antisymm degree_map_le ?_
rw [degree_eq_natDegree hP]
refine le_degree_of_ne_zero ?_
rw [coeff_map, Monic.coeff_natDegree hmo, RingHom.map_one]
exact one_ne_zero
section Injective
open Function
variable [Semiring S] {f : R →+* S}
theorem degree_map_eq_of_injective (hf : Injective f) (p : R[X]) : degree (p.map f) = degree p :=
letI := Classical.decEq R
if h : p = 0 then by simp [h]
else
degree_map_eq_of_leadingCoeff_ne_zero _
(by rw [← f.map_zero]; exact mt hf.eq_iff.1 (mt leadingCoeff_eq_zero.1 h))
theorem natDegree_map_eq_of_injective (hf : Injective f) (p : R[X]) :
natDegree (p.map f) = natDegree p :=
natDegree_eq_of_degree_eq (degree_map_eq_of_injective hf p)
theorem leadingCoeff_map' (hf : Injective f) (p : R[X]) :
leadingCoeff (p.map f) = f (leadingCoeff p) := by
unfold leadingCoeff
rw [coeff_map, natDegree_map_eq_of_injective hf p]
theorem nextCoeff_map (hf : Injective f) (p : R[X]) : (p.map f).nextCoeff = f p.nextCoeff := by
unfold nextCoeff
rw [natDegree_map_eq_of_injective hf]
split_ifs <;> simp [*]
theorem leadingCoeff_of_injective (hf : Injective f) (p : R[X]) :
leadingCoeff (p.map f) = f (leadingCoeff p) := by
delta leadingCoeff
rw [coeff_map f, natDegree_map_eq_of_injective hf p]
| Mathlib/Algebra/Polynomial/Monic.lean | 415 | 419 | theorem monic_of_injective (hf : Injective f) {p : R[X]} (hp : (p.map f).Monic) : p.Monic := by | apply hf
rw [← leadingCoeff_of_injective hf, hp.leadingCoeff, f.map_one]
theorem _root_.Function.Injective.monic_map_iff (hf : Injective f) {p : R[X]} : |
/-
Copyright (c) 2020 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Kim Morrison
-/
import Mathlib.Algebra.Order.Interval.Set.Instances
import Mathlib.Order.Interval.Set.ProjIcc
import Mathlib.Topology.Algebra.Ring.Real
/-!
# The unit interval, as a topological space
Use `open unitInterval` to turn on the notation `I := Set.Icc (0 : ℝ) (1 : ℝ)`.
We provide basic instances, as well as a custom tactic for discharging
`0 ≤ ↑x`, `0 ≤ 1 - ↑x`, `↑x ≤ 1`, and `1 - ↑x ≤ 1` when `x : I`.
-/
noncomputable section
open Topology Filter Set Int Set.Icc
/-! ### The unit interval -/
/-- The unit interval `[0,1]` in ℝ. -/
abbrev unitInterval : Set ℝ :=
Set.Icc 0 1
@[inherit_doc]
scoped[unitInterval] notation "I" => unitInterval
namespace unitInterval
theorem zero_mem : (0 : ℝ) ∈ I :=
⟨le_rfl, zero_le_one⟩
theorem one_mem : (1 : ℝ) ∈ I :=
⟨zero_le_one, le_rfl⟩
theorem mul_mem {x y : ℝ} (hx : x ∈ I) (hy : y ∈ I) : x * y ∈ I :=
⟨mul_nonneg hx.1 hy.1, mul_le_one₀ hx.2 hy.1 hy.2⟩
theorem div_mem {x y : ℝ} (hx : 0 ≤ x) (hy : 0 ≤ y) (hxy : x ≤ y) : x / y ∈ I :=
⟨div_nonneg hx hy, div_le_one_of_le₀ hxy hy⟩
theorem fract_mem (x : ℝ) : fract x ∈ I :=
⟨fract_nonneg _, (fract_lt_one _).le⟩
theorem mem_iff_one_sub_mem {t : ℝ} : t ∈ I ↔ 1 - t ∈ I := by
rw [mem_Icc, mem_Icc]
constructor <;> intro <;> constructor <;> linarith
instance hasZero : Zero I :=
⟨⟨0, zero_mem⟩⟩
instance hasOne : One I :=
⟨⟨1, by constructor <;> norm_num⟩⟩
instance : ZeroLEOneClass I := ⟨zero_le_one (α := ℝ)⟩
instance : CompleteLattice I := have : Fact ((0 : ℝ) ≤ 1) := ⟨zero_le_one⟩; inferInstance
lemma univ_eq_Icc : (univ : Set I) = Icc (0 : I) (1 : I) := Icc_bot_top.symm
@[norm_cast] theorem coe_ne_zero {x : I} : (x : ℝ) ≠ 0 ↔ x ≠ 0 := coe_eq_zero.not
@[norm_cast] theorem coe_ne_one {x : I} : (x : ℝ) ≠ 1 ↔ x ≠ 1 := coe_eq_one.not
@[simp, norm_cast] theorem coe_pos {x : I} : (0 : ℝ) < x ↔ 0 < x := Iff.rfl
@[simp, norm_cast] theorem coe_lt_one {x : I} : (x : ℝ) < 1 ↔ x < 1 := Iff.rfl
instance : Nonempty I :=
⟨0⟩
instance : Mul I :=
⟨fun x y => ⟨x * y, mul_mem x.2 y.2⟩⟩
theorem mul_le_left {x y : I} : x * y ≤ x :=
Subtype.coe_le_coe.mp <| mul_le_of_le_one_right x.2.1 y.2.2
theorem mul_le_right {x y : I} : x * y ≤ y :=
Subtype.coe_le_coe.mp <| mul_le_of_le_one_left y.2.1 x.2.2
/-- Unit interval central symmetry. -/
def symm : I → I := fun t => ⟨1 - t, mem_iff_one_sub_mem.mp t.prop⟩
@[inherit_doc]
scoped notation "σ" => unitInterval.symm
@[simp]
theorem symm_zero : σ 0 = 1 :=
Subtype.ext <| by simp [symm]
@[simp]
theorem symm_one : σ 1 = 0 :=
Subtype.ext <| by simp [symm]
@[simp]
theorem symm_symm (x : I) : σ (σ x) = x :=
Subtype.ext <| by simp [symm]
theorem symm_involutive : Function.Involutive (symm : I → I) := symm_symm
theorem symm_bijective : Function.Bijective (symm : I → I) := symm_involutive.bijective
@[simp]
theorem coe_symm_eq (x : I) : (σ x : ℝ) = 1 - x :=
rfl
@[simp]
theorem symm_projIcc (x : ℝ) :
symm (projIcc 0 1 zero_le_one x) = projIcc 0 1 zero_le_one (1 - x) := by
ext
rcases le_total x 0 with h₀ | h₀
· simp [projIcc_of_le_left, projIcc_of_right_le, h₀]
· rcases le_total x 1 with h₁ | h₁
· lift x to I using ⟨h₀, h₁⟩
simp_rw [← coe_symm_eq, projIcc_val]
· simp [projIcc_of_le_left, projIcc_of_right_le, h₁]
@[continuity, fun_prop]
theorem continuous_symm : Continuous σ :=
Continuous.subtype_mk (by fun_prop) _
/-- `unitInterval.symm` as a `Homeomorph`. -/
@[simps]
def symmHomeomorph : I ≃ₜ I where
toFun := symm
invFun := symm
left_inv := symm_symm
right_inv := symm_symm
theorem strictAnti_symm : StrictAnti σ := fun _ _ h ↦ sub_lt_sub_left (α := ℝ) h _
@[simp]
theorem symm_inj {i j : I} : σ i = σ j ↔ i = j := symm_bijective.injective.eq_iff
theorem half_le_symm_iff (t : I) : 1 / 2 ≤ (σ t : ℝ) ↔ (t : ℝ) ≤ 1 / 2 := by
rw [coe_symm_eq, le_sub_iff_add_le, add_comm, ← le_sub_iff_add_le, sub_half]
@[simp]
lemma symm_eq_one {i : I} : σ i = 1 ↔ i = 0 := by
rw [← symm_zero, symm_inj]
@[simp]
lemma symm_eq_zero {i : I} : σ i = 0 ↔ i = 1 := by
rw [← symm_one, symm_inj]
@[simp]
theorem symm_le_symm {i j : I} : σ i ≤ σ j ↔ j ≤ i := by
simp only [symm, Subtype.mk_le_mk, sub_le_sub_iff, add_le_add_iff_left, Subtype.coe_le_coe]
| Mathlib/Topology/UnitInterval.lean | 154 | 155 | theorem le_symm_comm {i j : I} : i ≤ σ j ↔ j ≤ σ i := by | rw [← symm_le_symm, symm_symm] |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Sébastien Gouëzel,
Rémy Degenne, David Loeffler
-/
import Mathlib.Analysis.SpecialFunctions.Complex.Log
/-! # Power function on `ℂ`
We construct the power functions `x ^ y`, where `x` and `y` are complex numbers.
-/
open Real Topology Filter ComplexConjugate Finset Set
namespace Complex
/-- The complex power function `x ^ y`, given by `x ^ y = exp(y log x)` (where `log` is the
principal determination of the logarithm), unless `x = 0` where one sets `0 ^ 0 = 1` and
`0 ^ y = 0` for `y ≠ 0`. -/
noncomputable def cpow (x y : ℂ) : ℂ :=
if x = 0 then if y = 0 then 1 else 0 else exp (log x * y)
noncomputable instance : Pow ℂ ℂ :=
⟨cpow⟩
@[simp]
theorem cpow_eq_pow (x y : ℂ) : cpow x y = x ^ y :=
rfl
theorem cpow_def (x y : ℂ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) :=
rfl
theorem cpow_def_of_ne_zero {x : ℂ} (hx : x ≠ 0) (y : ℂ) : x ^ y = exp (log x * y) :=
if_neg hx
@[simp]
theorem cpow_zero (x : ℂ) : x ^ (0 : ℂ) = 1 := by simp [cpow_def]
@[simp]
theorem cpow_eq_zero_iff (x y : ℂ) : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 := by
simp only [cpow_def]
split_ifs <;> simp [*, exp_ne_zero]
theorem cpow_ne_zero_iff {x y : ℂ} :
x ^ y ≠ 0 ↔ x ≠ 0 ∨ y = 0 := by
rw [ne_eq, cpow_eq_zero_iff, not_and_or, ne_eq, not_not]
theorem cpow_ne_zero_iff_of_exponent_ne_zero {x y : ℂ} (hy : y ≠ 0) :
x ^ y ≠ 0 ↔ x ≠ 0 := by simp [hy]
@[simp]
theorem zero_cpow {x : ℂ} (h : x ≠ 0) : (0 : ℂ) ^ x = 0 := by simp [cpow_def, *]
| Mathlib/Analysis/SpecialFunctions/Pow/Complex.lean | 55 | 55 | theorem zero_cpow_eq_iff {x : ℂ} {a : ℂ} : (0 : ℂ) ^ x = a ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by | |
/-
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.Algebra.ModEq
import Mathlib.Algebra.Order.Archimedean.Basic
import Mathlib.Algebra.Ring.Periodic
import Mathlib.Data.Int.SuccPred
import Mathlib.Order.Circular
/-!
# Reducing to an interval modulo its length
This file defines operations that reduce a number (in an `Archimedean`
`LinearOrderedAddCommGroup`) to a number in a given interval, modulo the length of that
interval.
## Main definitions
* `toIcoDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`,
subtracted from `b`, is in `Ico a (a + p)`.
* `toIcoMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ico a (a + p)`.
* `toIocDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`,
subtracted from `b`, is in `Ioc a (a + p)`.
* `toIocMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ioc a (a + p)`.
-/
assert_not_exists TwoSidedIdeal
noncomputable section
section LinearOrderedAddCommGroup
variable {α : Type*} [AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α] [hα : Archimedean α]
{p : α} (hp : 0 < p)
{a b c : α} {n : ℤ}
section
include hp
/--
The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ico a (a + p)`. -/
def toIcoDiv (a b : α) : ℤ :=
(existsUnique_sub_zsmul_mem_Ico hp b a).choose
theorem sub_toIcoDiv_zsmul_mem_Ico (a b : α) : b - toIcoDiv hp a b • p ∈ Set.Ico a (a + p) :=
(existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.1
theorem toIcoDiv_eq_of_sub_zsmul_mem_Ico (h : b - n • p ∈ Set.Ico a (a + p)) :
toIcoDiv hp a b = n :=
((existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.2 _ h).symm
/--
The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ioc a (a + p)`. -/
def toIocDiv (a b : α) : ℤ :=
(existsUnique_sub_zsmul_mem_Ioc hp b a).choose
theorem sub_toIocDiv_zsmul_mem_Ioc (a b : α) : b - toIocDiv hp a b • p ∈ Set.Ioc a (a + p) :=
(existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.1
theorem toIocDiv_eq_of_sub_zsmul_mem_Ioc (h : b - n • p ∈ Set.Ioc a (a + p)) :
toIocDiv hp a b = n :=
((existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.2 _ h).symm
/-- Reduce `b` to the interval `Ico a (a + p)`. -/
def toIcoMod (a b : α) : α :=
b - toIcoDiv hp a b • p
/-- Reduce `b` to the interval `Ioc a (a + p)`. -/
def toIocMod (a b : α) : α :=
b - toIocDiv hp a b • p
theorem toIcoMod_mem_Ico (a b : α) : toIcoMod hp a b ∈ Set.Ico a (a + p) :=
sub_toIcoDiv_zsmul_mem_Ico hp a b
theorem toIcoMod_mem_Ico' (b : α) : toIcoMod hp 0 b ∈ Set.Ico 0 p := by
convert toIcoMod_mem_Ico hp 0 b
exact (zero_add p).symm
theorem toIocMod_mem_Ioc (a b : α) : toIocMod hp a b ∈ Set.Ioc a (a + p) :=
sub_toIocDiv_zsmul_mem_Ioc hp a b
theorem left_le_toIcoMod (a b : α) : a ≤ toIcoMod hp a b :=
(Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).1
theorem left_lt_toIocMod (a b : α) : a < toIocMod hp a b :=
(Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).1
theorem toIcoMod_lt_right (a b : α) : toIcoMod hp a b < a + p :=
(Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).2
theorem toIocMod_le_right (a b : α) : toIocMod hp a b ≤ a + p :=
(Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).2
@[simp]
theorem self_sub_toIcoDiv_zsmul (a b : α) : b - toIcoDiv hp a b • p = toIcoMod hp a b :=
rfl
@[simp]
theorem self_sub_toIocDiv_zsmul (a b : α) : b - toIocDiv hp a b • p = toIocMod hp a b :=
rfl
@[simp]
theorem toIcoDiv_zsmul_sub_self (a b : α) : toIcoDiv hp a b • p - b = -toIcoMod hp a b := by
rw [toIcoMod, neg_sub]
@[simp]
theorem toIocDiv_zsmul_sub_self (a b : α) : toIocDiv hp a b • p - b = -toIocMod hp a b := by
rw [toIocMod, neg_sub]
@[simp]
theorem toIcoMod_sub_self (a b : α) : toIcoMod hp a b - b = -toIcoDiv hp a b • p := by
rw [toIcoMod, sub_sub_cancel_left, neg_smul]
@[simp]
theorem toIocMod_sub_self (a b : α) : toIocMod hp a b - b = -toIocDiv hp a b • p := by
rw [toIocMod, sub_sub_cancel_left, neg_smul]
@[simp]
theorem self_sub_toIcoMod (a b : α) : b - toIcoMod hp a b = toIcoDiv hp a b • p := by
rw [toIcoMod, sub_sub_cancel]
@[simp]
theorem self_sub_toIocMod (a b : α) : b - toIocMod hp a b = toIocDiv hp a b • p := by
rw [toIocMod, sub_sub_cancel]
@[simp]
theorem toIcoMod_add_toIcoDiv_zsmul (a b : α) : toIcoMod hp a b + toIcoDiv hp a b • p = b := by
rw [toIcoMod, sub_add_cancel]
@[simp]
theorem toIocMod_add_toIocDiv_zsmul (a b : α) : toIocMod hp a b + toIocDiv hp a b • p = b := by
rw [toIocMod, sub_add_cancel]
@[simp]
theorem toIcoDiv_zsmul_sub_toIcoMod (a b : α) : toIcoDiv hp a b • p + toIcoMod hp a b = b := by
rw [add_comm, toIcoMod_add_toIcoDiv_zsmul]
@[simp]
theorem toIocDiv_zsmul_sub_toIocMod (a b : α) : toIocDiv hp a b • p + toIocMod hp a b = b := by
rw [add_comm, toIocMod_add_toIocDiv_zsmul]
theorem toIcoMod_eq_iff : toIcoMod hp a b = c ↔ c ∈ Set.Ico a (a + p) ∧ ∃ z : ℤ, b = c + z • p := by
refine
⟨fun h =>
⟨h ▸ toIcoMod_mem_Ico hp a b, toIcoDiv hp a b, h ▸ (toIcoMod_add_toIcoDiv_zsmul _ _ _).symm⟩,
?_⟩
simp_rw [← @sub_eq_iff_eq_add]
rintro ⟨hc, n, rfl⟩
rw [← toIcoDiv_eq_of_sub_zsmul_mem_Ico hp hc, toIcoMod]
theorem toIocMod_eq_iff : toIocMod hp a b = c ↔ c ∈ Set.Ioc a (a + p) ∧ ∃ z : ℤ, b = c + z • p := by
refine
⟨fun h =>
⟨h ▸ toIocMod_mem_Ioc hp a b, toIocDiv hp a b, h ▸ (toIocMod_add_toIocDiv_zsmul hp _ _).symm⟩,
?_⟩
simp_rw [← @sub_eq_iff_eq_add]
rintro ⟨hc, n, rfl⟩
rw [← toIocDiv_eq_of_sub_zsmul_mem_Ioc hp hc, toIocMod]
@[simp]
theorem toIcoDiv_apply_left (a : α) : toIcoDiv hp a a = 0 :=
toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp]
@[simp]
theorem toIocDiv_apply_left (a : α) : toIocDiv hp a a = -1 :=
toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp]
@[simp]
theorem toIcoMod_apply_left (a : α) : toIcoMod hp a a = a := by
rw [toIcoMod_eq_iff hp, Set.left_mem_Ico]
exact ⟨lt_add_of_pos_right _ hp, 0, by simp⟩
@[simp]
theorem toIocMod_apply_left (a : α) : toIocMod hp a a = a + p := by
rw [toIocMod_eq_iff hp, Set.right_mem_Ioc]
exact ⟨lt_add_of_pos_right _ hp, -1, by simp⟩
theorem toIcoDiv_apply_right (a : α) : toIcoDiv hp a (a + p) = 1 :=
toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp]
theorem toIocDiv_apply_right (a : α) : toIocDiv hp a (a + p) = 0 :=
toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp]
theorem toIcoMod_apply_right (a : α) : toIcoMod hp a (a + p) = a := by
rw [toIcoMod_eq_iff hp, Set.left_mem_Ico]
exact ⟨lt_add_of_pos_right _ hp, 1, by simp⟩
theorem toIocMod_apply_right (a : α) : toIocMod hp a (a + p) = a + p := by
rw [toIocMod_eq_iff hp, Set.right_mem_Ioc]
exact ⟨lt_add_of_pos_right _ hp, 0, by simp⟩
@[simp]
theorem toIcoDiv_add_zsmul (a b : α) (m : ℤ) : toIcoDiv hp a (b + m • p) = toIcoDiv hp a b + m :=
toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by
simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIcoDiv_zsmul_mem_Ico hp a b
@[simp]
theorem toIcoDiv_add_zsmul' (a b : α) (m : ℤ) :
toIcoDiv hp (a + m • p) b = toIcoDiv hp a b - m := by
refine toIcoDiv_eq_of_sub_zsmul_mem_Ico _ ?_
rw [sub_smul, ← sub_add, add_right_comm]
simpa using sub_toIcoDiv_zsmul_mem_Ico hp a b
@[simp]
theorem toIocDiv_add_zsmul (a b : α) (m : ℤ) : toIocDiv hp a (b + m • p) = toIocDiv hp a b + m :=
toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by
simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIocDiv_zsmul_mem_Ioc hp a b
@[simp]
theorem toIocDiv_add_zsmul' (a b : α) (m : ℤ) :
toIocDiv hp (a + m • p) b = toIocDiv hp a b - m := by
refine toIocDiv_eq_of_sub_zsmul_mem_Ioc _ ?_
rw [sub_smul, ← sub_add, add_right_comm]
simpa using sub_toIocDiv_zsmul_mem_Ioc hp a b
@[simp]
theorem toIcoDiv_zsmul_add (a b : α) (m : ℤ) : toIcoDiv hp a (m • p + b) = m + toIcoDiv hp a b := by
rw [add_comm, toIcoDiv_add_zsmul, add_comm]
/-! Note we omit `toIcoDiv_zsmul_add'` as `-m + toIcoDiv hp a b` is not very convenient. -/
@[simp]
theorem toIocDiv_zsmul_add (a b : α) (m : ℤ) : toIocDiv hp a (m • p + b) = m + toIocDiv hp a b := by
rw [add_comm, toIocDiv_add_zsmul, add_comm]
/-! Note we omit `toIocDiv_zsmul_add'` as `-m + toIocDiv hp a b` is not very convenient. -/
@[simp]
theorem toIcoDiv_sub_zsmul (a b : α) (m : ℤ) : toIcoDiv hp a (b - m • p) = toIcoDiv hp a b - m := by
rw [sub_eq_add_neg, ← neg_smul, toIcoDiv_add_zsmul, sub_eq_add_neg]
@[simp]
theorem toIcoDiv_sub_zsmul' (a b : α) (m : ℤ) :
toIcoDiv hp (a - m • p) b = toIcoDiv hp a b + m := by
rw [sub_eq_add_neg, ← neg_smul, toIcoDiv_add_zsmul', sub_neg_eq_add]
@[simp]
theorem toIocDiv_sub_zsmul (a b : α) (m : ℤ) : toIocDiv hp a (b - m • p) = toIocDiv hp a b - m := by
rw [sub_eq_add_neg, ← neg_smul, toIocDiv_add_zsmul, sub_eq_add_neg]
@[simp]
theorem toIocDiv_sub_zsmul' (a b : α) (m : ℤ) :
toIocDiv hp (a - m • p) b = toIocDiv hp a b + m := by
rw [sub_eq_add_neg, ← neg_smul, toIocDiv_add_zsmul', sub_neg_eq_add]
@[simp]
theorem toIcoDiv_add_right (a b : α) : toIcoDiv hp a (b + p) = toIcoDiv hp a b + 1 := by
simpa only [one_zsmul] using toIcoDiv_add_zsmul hp a b 1
@[simp]
theorem toIcoDiv_add_right' (a b : α) : toIcoDiv hp (a + p) b = toIcoDiv hp a b - 1 := by
simpa only [one_zsmul] using toIcoDiv_add_zsmul' hp a b 1
@[simp]
theorem toIocDiv_add_right (a b : α) : toIocDiv hp a (b + p) = toIocDiv hp a b + 1 := by
simpa only [one_zsmul] using toIocDiv_add_zsmul hp a b 1
@[simp]
theorem toIocDiv_add_right' (a b : α) : toIocDiv hp (a + p) b = toIocDiv hp a b - 1 := by
simpa only [one_zsmul] using toIocDiv_add_zsmul' hp a b 1
@[simp]
theorem toIcoDiv_add_left (a b : α) : toIcoDiv hp a (p + b) = toIcoDiv hp a b + 1 := by
rw [add_comm, toIcoDiv_add_right]
@[simp]
theorem toIcoDiv_add_left' (a b : α) : toIcoDiv hp (p + a) b = toIcoDiv hp a b - 1 := by
rw [add_comm, toIcoDiv_add_right']
@[simp]
theorem toIocDiv_add_left (a b : α) : toIocDiv hp a (p + b) = toIocDiv hp a b + 1 := by
rw [add_comm, toIocDiv_add_right]
@[simp]
theorem toIocDiv_add_left' (a b : α) : toIocDiv hp (p + a) b = toIocDiv hp a b - 1 := by
rw [add_comm, toIocDiv_add_right']
@[simp]
theorem toIcoDiv_sub (a b : α) : toIcoDiv hp a (b - p) = toIcoDiv hp a b - 1 := by
simpa only [one_zsmul] using toIcoDiv_sub_zsmul hp a b 1
@[simp]
theorem toIcoDiv_sub' (a b : α) : toIcoDiv hp (a - p) b = toIcoDiv hp a b + 1 := by
simpa only [one_zsmul] using toIcoDiv_sub_zsmul' hp a b 1
@[simp]
theorem toIocDiv_sub (a b : α) : toIocDiv hp a (b - p) = toIocDiv hp a b - 1 := by
simpa only [one_zsmul] using toIocDiv_sub_zsmul hp a b 1
@[simp]
theorem toIocDiv_sub' (a b : α) : toIocDiv hp (a - p) b = toIocDiv hp a b + 1 := by
simpa only [one_zsmul] using toIocDiv_sub_zsmul' hp a b 1
theorem toIcoDiv_sub_eq_toIcoDiv_add (a b c : α) :
toIcoDiv hp a (b - c) = toIcoDiv hp (a + c) b := by
apply toIcoDiv_eq_of_sub_zsmul_mem_Ico
rw [← sub_right_comm, Set.sub_mem_Ico_iff_left, add_right_comm]
exact sub_toIcoDiv_zsmul_mem_Ico hp (a + c) b
| Mathlib/Algebra/Order/ToIntervalMod.lean | 304 | 305 | theorem toIocDiv_sub_eq_toIocDiv_add (a b c : α) :
toIocDiv hp a (b - c) = toIocDiv hp (a + c) b := by | |
/-
Copyright (c) 2022 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Oleksandr Manzyuk
-/
import Mathlib.CategoryTheory.Bicategory.Basic
import Mathlib.CategoryTheory.Monoidal.Mon_
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Equalizers
/-!
# The category of bimodule objects over a pair of monoid objects.
-/
universe v₁ v₂ u₁ u₂
open CategoryTheory
open CategoryTheory.MonoidalCategory
variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory.{v₁} C]
section
open CategoryTheory.Limits
variable [HasCoequalizers C]
section
variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)]
theorem id_tensor_π_preserves_coequalizer_inv_desc {W X Y Z : C} (f g : X ⟶ Y) (h : Z ⊗ Y ⟶ W)
(wh : (Z ◁ f) ≫ h = (Z ◁ g) ≫ h) :
(Z ◁ coequalizer.π f g) ≫
(PreservesCoequalizer.iso (tensorLeft Z) f g).inv ≫ coequalizer.desc h wh =
h :=
map_π_preserves_coequalizer_inv_desc (tensorLeft Z) f g h wh
theorem id_tensor_π_preserves_coequalizer_inv_colimMap_desc {X Y Z X' Y' Z' : C} (f g : X ⟶ Y)
(f' g' : X' ⟶ Y') (p : Z ⊗ X ⟶ X') (q : Z ⊗ Y ⟶ Y') (wf : (Z ◁ f) ≫ q = p ≫ f')
(wg : (Z ◁ g) ≫ q = p ≫ g') (h : Y' ⟶ Z') (wh : f' ≫ h = g' ≫ h) :
(Z ◁ coequalizer.π f g) ≫
(PreservesCoequalizer.iso (tensorLeft Z) f g).inv ≫
colimMap (parallelPairHom (Z ◁ f) (Z ◁ g) f' g' p q wf wg) ≫ coequalizer.desc h wh =
q ≫ h :=
map_π_preserves_coequalizer_inv_colimMap_desc (tensorLeft Z) f g f' g' p q wf wg h wh
end
section
variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)]
theorem π_tensor_id_preserves_coequalizer_inv_desc {W X Y Z : C} (f g : X ⟶ Y) (h : Y ⊗ Z ⟶ W)
(wh : (f ▷ Z) ≫ h = (g ▷ Z) ≫ h) :
(coequalizer.π f g ▷ Z) ≫
(PreservesCoequalizer.iso (tensorRight Z) f g).inv ≫ coequalizer.desc h wh =
h :=
map_π_preserves_coequalizer_inv_desc (tensorRight Z) f g h wh
theorem π_tensor_id_preserves_coequalizer_inv_colimMap_desc {X Y Z X' Y' Z' : C} (f g : X ⟶ Y)
(f' g' : X' ⟶ Y') (p : X ⊗ Z ⟶ X') (q : Y ⊗ Z ⟶ Y') (wf : (f ▷ Z) ≫ q = p ≫ f')
(wg : (g ▷ Z) ≫ q = p ≫ g') (h : Y' ⟶ Z') (wh : f' ≫ h = g' ≫ h) :
(coequalizer.π f g ▷ Z) ≫
(PreservesCoequalizer.iso (tensorRight Z) f g).inv ≫
colimMap (parallelPairHom (f ▷ Z) (g ▷ Z) f' g' p q wf wg) ≫ coequalizer.desc h wh =
q ≫ h :=
map_π_preserves_coequalizer_inv_colimMap_desc (tensorRight Z) f g f' g' p q wf wg h wh
end
end
/-- A bimodule object for a pair of monoid objects, all internal to some monoidal category. -/
structure Bimod (A B : Mon_ C) where
/-- The underlying monoidal category -/
X : C
/-- The left action of this bimodule object -/
actLeft : A.X ⊗ X ⟶ X
one_actLeft : (A.one ▷ X) ≫ actLeft = (λ_ X).hom := by aesop_cat
left_assoc :
(A.mul ▷ X) ≫ actLeft = (α_ A.X A.X X).hom ≫ (A.X ◁ actLeft) ≫ actLeft := by aesop_cat
/-- The right action of this bimodule object -/
actRight : X ⊗ B.X ⟶ X
actRight_one : (X ◁ B.one) ≫ actRight = (ρ_ X).hom := by aesop_cat
right_assoc :
(X ◁ B.mul) ≫ actRight = (α_ X B.X B.X).inv ≫ (actRight ▷ B.X) ≫ actRight := by
aesop_cat
middle_assoc :
(actLeft ▷ B.X) ≫ actRight = (α_ A.X X B.X).hom ≫ (A.X ◁ actRight) ≫ actLeft := by
aesop_cat
attribute [reassoc (attr := simp)] Bimod.one_actLeft Bimod.actRight_one Bimod.left_assoc
Bimod.right_assoc Bimod.middle_assoc
namespace Bimod
variable {A B : Mon_ C} (M : Bimod A B)
/-- A morphism of bimodule objects. -/
@[ext]
structure Hom (M N : Bimod A B) where
/-- The morphism between `M`'s monoidal category and `N`'s monoidal category -/
hom : M.X ⟶ N.X
left_act_hom : M.actLeft ≫ hom = (A.X ◁ hom) ≫ N.actLeft := by aesop_cat
right_act_hom : M.actRight ≫ hom = (hom ▷ B.X) ≫ N.actRight := by aesop_cat
attribute [reassoc (attr := simp)] Hom.left_act_hom Hom.right_act_hom
/-- The identity morphism on a bimodule object. -/
@[simps]
def id' (M : Bimod A B) : Hom M M where hom := 𝟙 M.X
instance homInhabited (M : Bimod A B) : Inhabited (Hom M M) :=
⟨id' M⟩
/-- Composition of bimodule object morphisms. -/
@[simps]
def comp {M N O : Bimod A B} (f : Hom M N) (g : Hom N O) : Hom M O where hom := f.hom ≫ g.hom
instance : Category (Bimod A B) where
Hom M N := Hom M N
id := id'
comp f g := comp f g
@[ext]
lemma hom_ext {M N : Bimod A B} (f g : M ⟶ N) (h : f.hom = g.hom) : f = g :=
Hom.ext h
@[simp]
theorem id_hom' (M : Bimod A B) : (𝟙 M : Hom M M).hom = 𝟙 M.X :=
rfl
@[simp]
theorem comp_hom' {M N K : Bimod A B} (f : M ⟶ N) (g : N ⟶ K) :
(f ≫ g : Hom M K).hom = f.hom ≫ g.hom :=
rfl
/-- Construct an isomorphism of bimodules by giving an isomorphism between the underlying objects
and checking compatibility with left and right actions only in the forward direction.
-/
@[simps]
def isoOfIso {X Y : Mon_ C} {P Q : Bimod X Y} (f : P.X ≅ Q.X)
(f_left_act_hom : P.actLeft ≫ f.hom = (X.X ◁ f.hom) ≫ Q.actLeft)
(f_right_act_hom : P.actRight ≫ f.hom = (f.hom ▷ Y.X) ≫ Q.actRight) : P ≅ Q where
hom :=
{ hom := f.hom }
inv :=
{ hom := f.inv
left_act_hom := by
rw [← cancel_mono f.hom, Category.assoc, Category.assoc, Iso.inv_hom_id, Category.comp_id,
f_left_act_hom, ← Category.assoc, ← MonoidalCategory.whiskerLeft_comp, Iso.inv_hom_id,
MonoidalCategory.whiskerLeft_id, Category.id_comp]
right_act_hom := by
rw [← cancel_mono f.hom, Category.assoc, Category.assoc, Iso.inv_hom_id, Category.comp_id,
f_right_act_hom, ← Category.assoc, ← comp_whiskerRight, Iso.inv_hom_id,
MonoidalCategory.id_whiskerRight, Category.id_comp] }
hom_inv_id := by ext; dsimp; rw [Iso.hom_inv_id]
inv_hom_id := by ext; dsimp; rw [Iso.inv_hom_id]
variable (A)
/-- A monoid object as a bimodule over itself. -/
@[simps]
def regular : Bimod A A where
X := A.X
actLeft := A.mul
actRight := A.mul
instance : Inhabited (Bimod A A) :=
⟨regular A⟩
/-- The forgetful functor from bimodule objects to the ambient category. -/
def forget : Bimod A B ⥤ C where
obj A := A.X
map f := f.hom
open CategoryTheory.Limits
variable [HasCoequalizers C]
namespace TensorBimod
variable {R S T : Mon_ C} (P : Bimod R S) (Q : Bimod S T)
/-- The underlying object of the tensor product of two bimodules. -/
noncomputable def X : C :=
coequalizer (P.actRight ▷ Q.X) ((α_ _ _ _).hom ≫ (P.X ◁ Q.actLeft))
section
variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)]
/-- Left action for the tensor product of two bimodules. -/
noncomputable def actLeft : R.X ⊗ X P Q ⟶ X P Q :=
(PreservesCoequalizer.iso (tensorLeft R.X) _ _).inv ≫
colimMap
(parallelPairHom _ _ _ _
((α_ _ _ _).inv ≫ ((α_ _ _ _).inv ▷ _) ≫ (P.actLeft ▷ S.X ▷ Q.X))
((α_ _ _ _).inv ≫ (P.actLeft ▷ Q.X))
(by
dsimp
simp only [Category.assoc]
slice_lhs 1 2 => rw [associator_inv_naturality_middle]
slice_rhs 3 4 => rw [← comp_whiskerRight, middle_assoc, comp_whiskerRight]
monoidal)
(by
dsimp
slice_lhs 1 1 => rw [MonoidalCategory.whiskerLeft_comp]
slice_lhs 2 3 => rw [associator_inv_naturality_right]
slice_lhs 3 4 => rw [whisker_exchange]
monoidal))
theorem whiskerLeft_π_actLeft :
(R.X ◁ coequalizer.π _ _) ≫ actLeft P Q =
(α_ _ _ _).inv ≫ (P.actLeft ▷ Q.X) ≫ coequalizer.π _ _ := by
erw [map_π_preserves_coequalizer_inv_colimMap (tensorLeft _)]
simp only [Category.assoc]
theorem one_act_left' : (R.one ▷ _) ≫ actLeft P Q = (λ_ _).hom := by
refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_
dsimp [X]
-- Porting note: had to replace `rw` by `erw`
slice_lhs 1 2 => erw [whisker_exchange]
slice_lhs 2 3 => rw [whiskerLeft_π_actLeft]
slice_lhs 1 2 => rw [associator_inv_naturality_left]
slice_lhs 2 3 => rw [← comp_whiskerRight, one_actLeft]
slice_rhs 1 2 => rw [leftUnitor_naturality]
monoidal
theorem left_assoc' :
(R.mul ▷ _) ≫ actLeft P Q = (α_ R.X R.X _).hom ≫ (R.X ◁ actLeft P Q) ≫ actLeft P Q := by
refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_
dsimp [X]
slice_lhs 1 2 => rw [whisker_exchange]
slice_lhs 2 3 => rw [whiskerLeft_π_actLeft]
slice_lhs 1 2 => rw [associator_inv_naturality_left]
slice_lhs 2 3 => rw [← comp_whiskerRight, left_assoc, comp_whiskerRight, comp_whiskerRight]
slice_rhs 1 2 => rw [associator_naturality_right]
slice_rhs 2 3 =>
rw [← MonoidalCategory.whiskerLeft_comp, whiskerLeft_π_actLeft,
MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp]
slice_rhs 4 5 => rw [whiskerLeft_π_actLeft]
slice_rhs 3 4 => rw [associator_inv_naturality_middle]
monoidal
end
section
variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)]
/-- Right action for the tensor product of two bimodules. -/
noncomputable def actRight : X P Q ⊗ T.X ⟶ X P Q :=
(PreservesCoequalizer.iso (tensorRight T.X) _ _).inv ≫
colimMap
(parallelPairHom _ _ _ _
((α_ _ _ _).hom ≫ (α_ _ _ _).hom ≫ (P.X ◁ S.X ◁ Q.actRight) ≫ (α_ _ _ _).inv)
((α_ _ _ _).hom ≫ (P.X ◁ Q.actRight))
(by
dsimp
slice_lhs 1 2 => rw [associator_naturality_left]
slice_lhs 2 3 => rw [← whisker_exchange]
simp)
(by
dsimp
simp only [comp_whiskerRight, whisker_assoc, Category.assoc, Iso.inv_hom_id_assoc]
slice_lhs 3 4 =>
rw [← MonoidalCategory.whiskerLeft_comp, middle_assoc,
MonoidalCategory.whiskerLeft_comp]
simp))
theorem π_tensor_id_actRight :
(coequalizer.π _ _ ▷ T.X) ≫ actRight P Q =
(α_ _ _ _).hom ≫ (P.X ◁ Q.actRight) ≫ coequalizer.π _ _ := by
erw [map_π_preserves_coequalizer_inv_colimMap (tensorRight _)]
simp only [Category.assoc]
theorem actRight_one' : (_ ◁ T.one) ≫ actRight P Q = (ρ_ _).hom := by
refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_
dsimp [X]
-- Porting note: had to replace `rw` by `erw`
slice_lhs 1 2 =>erw [← whisker_exchange]
slice_lhs 2 3 => rw [π_tensor_id_actRight]
slice_lhs 1 2 => rw [associator_naturality_right]
slice_lhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp, actRight_one]
simp
theorem right_assoc' :
(_ ◁ T.mul) ≫ actRight P Q =
(α_ _ T.X T.X).inv ≫ (actRight P Q ▷ T.X) ≫ actRight P Q := by
refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_
dsimp [X]
-- Porting note: had to replace some `rw` by `erw`
slice_lhs 1 2 => rw [← whisker_exchange]
slice_lhs 2 3 => rw [π_tensor_id_actRight]
slice_lhs 1 2 => rw [associator_naturality_right]
slice_lhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp, right_assoc,
MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp]
slice_rhs 1 2 => rw [associator_inv_naturality_left]
slice_rhs 2 3 => rw [← comp_whiskerRight, π_tensor_id_actRight, comp_whiskerRight,
comp_whiskerRight]
slice_rhs 4 5 => rw [π_tensor_id_actRight]
simp
end
section
variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)]
variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)]
theorem middle_assoc' :
(actLeft P Q ▷ T.X) ≫ actRight P Q =
(α_ R.X _ T.X).hom ≫ (R.X ◁ actRight P Q) ≫ actLeft P Q := by
refine (cancel_epi ((tensorLeft _ ⋙ tensorRight _).map (coequalizer.π _ _))).1 ?_
dsimp [X]
slice_lhs 1 2 => rw [← comp_whiskerRight, whiskerLeft_π_actLeft, comp_whiskerRight,
comp_whiskerRight]
slice_lhs 3 4 => rw [π_tensor_id_actRight]
slice_lhs 2 3 => rw [associator_naturality_left]
-- Porting note: had to replace `rw` by `erw`
slice_rhs 1 2 => rw [associator_naturality_middle]
slice_rhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp, π_tensor_id_actRight,
MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp]
slice_rhs 4 5 => rw [whiskerLeft_π_actLeft]
slice_rhs 3 4 => rw [associator_inv_naturality_right]
slice_rhs 4 5 => rw [whisker_exchange]
simp
end
end TensorBimod
section
variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)]
variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)]
/-- Tensor product of two bimodule objects as a bimodule object. -/
@[simps]
noncomputable def tensorBimod {X Y Z : Mon_ C} (M : Bimod X Y) (N : Bimod Y Z) : Bimod X Z where
X := TensorBimod.X M N
actLeft := TensorBimod.actLeft M N
actRight := TensorBimod.actRight M N
one_actLeft := TensorBimod.one_act_left' M N
actRight_one := TensorBimod.actRight_one' M N
left_assoc := TensorBimod.left_assoc' M N
right_assoc := TensorBimod.right_assoc' M N
middle_assoc := TensorBimod.middle_assoc' M N
/-- Left whiskering for morphisms of bimodule objects. -/
@[simps]
noncomputable def whiskerLeft {X Y Z : Mon_ C} (M : Bimod X Y) {N₁ N₂ : Bimod Y Z} (f : N₁ ⟶ N₂) :
M.tensorBimod N₁ ⟶ M.tensorBimod N₂ where
hom :=
colimMap
(parallelPairHom _ _ _ _ (_ ◁ f.hom) (_ ◁ f.hom)
(by rw [whisker_exchange])
(by
simp only [Category.assoc, tensor_whiskerLeft, Iso.inv_hom_id_assoc,
Iso.cancel_iso_hom_left]
slice_lhs 1 2 => rw [← MonoidalCategory.whiskerLeft_comp, Hom.left_act_hom]
simp))
left_act_hom := by
refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_
dsimp
slice_lhs 1 2 => rw [TensorBimod.whiskerLeft_π_actLeft]
slice_lhs 3 4 => rw [ι_colimMap, parallelPairHom_app_one]
slice_rhs 1 2 => rw [← MonoidalCategory.whiskerLeft_comp, ι_colimMap, parallelPairHom_app_one,
MonoidalCategory.whiskerLeft_comp]
slice_rhs 2 3 => rw [TensorBimod.whiskerLeft_π_actLeft]
slice_rhs 1 2 => rw [associator_inv_naturality_right]
slice_rhs 2 3 => rw [whisker_exchange]
simp
right_act_hom := by
refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_
dsimp
slice_lhs 1 2 => rw [TensorBimod.π_tensor_id_actRight]
slice_lhs 3 4 => rw [ι_colimMap, parallelPairHom_app_one]
slice_lhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp, Hom.right_act_hom]
slice_rhs 1 2 =>
rw [← comp_whiskerRight, ι_colimMap, parallelPairHom_app_one, comp_whiskerRight]
slice_rhs 2 3 => rw [TensorBimod.π_tensor_id_actRight]
simp
/-- Right whiskering for morphisms of bimodule objects. -/
@[simps]
noncomputable def whiskerRight {X Y Z : Mon_ C} {M₁ M₂ : Bimod X Y} (f : M₁ ⟶ M₂) (N : Bimod Y Z) :
M₁.tensorBimod N ⟶ M₂.tensorBimod N where
hom :=
colimMap
(parallelPairHom _ _ _ _ (f.hom ▷ _ ▷ _) (f.hom ▷ _)
(by rw [← comp_whiskerRight, Hom.right_act_hom, comp_whiskerRight])
(by
slice_lhs 2 3 => rw [whisker_exchange]
simp))
left_act_hom := by
refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_
dsimp
slice_lhs 1 2 => rw [TensorBimod.whiskerLeft_π_actLeft]
slice_lhs 3 4 => rw [ι_colimMap, parallelPairHom_app_one]
slice_lhs 2 3 => rw [← comp_whiskerRight, Hom.left_act_hom]
slice_rhs 1 2 => rw [← MonoidalCategory.whiskerLeft_comp, ι_colimMap, parallelPairHom_app_one,
MonoidalCategory.whiskerLeft_comp]
slice_rhs 2 3 => rw [TensorBimod.whiskerLeft_π_actLeft]
slice_rhs 1 2 => rw [associator_inv_naturality_middle]
simp
right_act_hom := by
refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_
dsimp
slice_lhs 1 2 => rw [TensorBimod.π_tensor_id_actRight]
slice_lhs 3 4 => rw [ι_colimMap, parallelPairHom_app_one]
slice_lhs 2 3 => rw [whisker_exchange]
slice_rhs 1 2 => rw [← comp_whiskerRight, ι_colimMap, parallelPairHom_app_one,
comp_whiskerRight]
slice_rhs 2 3 => rw [TensorBimod.π_tensor_id_actRight]
simp
end
namespace AssociatorBimod
variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)]
variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)]
variable {R S T U : Mon_ C} (P : Bimod R S) (Q : Bimod S T) (L : Bimod T U)
/-- An auxiliary morphism for the definition of the underlying morphism of the forward component of
the associator isomorphism. -/
noncomputable def homAux : (P.tensorBimod Q).X ⊗ L.X ⟶ (P.tensorBimod (Q.tensorBimod L)).X :=
(PreservesCoequalizer.iso (tensorRight L.X) _ _).inv ≫
coequalizer.desc ((α_ _ _ _).hom ≫ (P.X ◁ coequalizer.π _ _) ≫ coequalizer.π _ _)
(by
dsimp; dsimp [TensorBimod.X]
slice_lhs 1 2 => rw [associator_naturality_left]
slice_lhs 2 3 => rw [← whisker_exchange]
slice_lhs 3 4 => rw [coequalizer.condition]
slice_lhs 2 3 => rw [associator_naturality_right]
slice_lhs 3 4 =>
rw [← MonoidalCategory.whiskerLeft_comp,
TensorBimod.whiskerLeft_π_actLeft, MonoidalCategory.whiskerLeft_comp]
simp)
/-- The underlying morphism of the forward component of the associator isomorphism. -/
noncomputable def hom :
((P.tensorBimod Q).tensorBimod L).X ⟶ (P.tensorBimod (Q.tensorBimod L)).X :=
coequalizer.desc (homAux P Q L)
(by
dsimp [homAux]
refine (cancel_epi ((tensorRight _ ⋙ tensorRight _).map (coequalizer.π _ _))).1 ?_
dsimp [TensorBimod.X]
slice_lhs 1 2 => rw [← comp_whiskerRight, TensorBimod.π_tensor_id_actRight,
comp_whiskerRight, comp_whiskerRight]
slice_lhs 3 5 => rw [π_tensor_id_preserves_coequalizer_inv_desc]
slice_lhs 2 3 => rw [associator_naturality_middle]
slice_lhs 3 4 =>
rw [← MonoidalCategory.whiskerLeft_comp, coequalizer.condition,
MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp]
slice_rhs 1 2 => rw [associator_naturality_left]
slice_rhs 2 3 => rw [← whisker_exchange]
slice_rhs 3 5 => rw [π_tensor_id_preserves_coequalizer_inv_desc]
simp)
theorem hom_left_act_hom' :
((P.tensorBimod Q).tensorBimod L).actLeft ≫ hom P Q L =
(R.X ◁ hom P Q L) ≫ (P.tensorBimod (Q.tensorBimod L)).actLeft := by
dsimp; dsimp [hom, homAux]
refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_
rw [tensorLeft_map]
slice_lhs 1 2 => rw [TensorBimod.whiskerLeft_π_actLeft]
slice_lhs 3 4 => rw [coequalizer.π_desc]
slice_rhs 1 2 => rw [← MonoidalCategory.whiskerLeft_comp, coequalizer.π_desc,
MonoidalCategory.whiskerLeft_comp]
refine (cancel_epi ((tensorRight _ ⋙ tensorLeft _).map (coequalizer.π _ _))).1 ?_
dsimp; dsimp [TensorBimod.X]
slice_lhs 1 2 => rw [associator_inv_naturality_middle]
slice_lhs 2 3 =>
rw [← comp_whiskerRight, TensorBimod.whiskerLeft_π_actLeft,
comp_whiskerRight, comp_whiskerRight]
slice_lhs 4 6 => rw [π_tensor_id_preserves_coequalizer_inv_desc]
slice_lhs 3 4 => rw [associator_naturality_left]
slice_rhs 1 3 =>
rw [← MonoidalCategory.whiskerLeft_comp, ← MonoidalCategory.whiskerLeft_comp,
π_tensor_id_preserves_coequalizer_inv_desc, MonoidalCategory.whiskerLeft_comp,
MonoidalCategory.whiskerLeft_comp]
slice_rhs 3 4 => erw [TensorBimod.whiskerLeft_π_actLeft P (Q.tensorBimod L)]
slice_rhs 2 3 => erw [associator_inv_naturality_right]
slice_rhs 3 4 => erw [whisker_exchange]
monoidal
theorem hom_right_act_hom' :
((P.tensorBimod Q).tensorBimod L).actRight ≫ hom P Q L =
(hom P Q L ▷ U.X) ≫ (P.tensorBimod (Q.tensorBimod L)).actRight := by
dsimp; dsimp [hom, homAux]
refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_
rw [tensorRight_map]
slice_lhs 1 2 => rw [TensorBimod.π_tensor_id_actRight]
slice_lhs 3 4 => rw [coequalizer.π_desc]
slice_rhs 1 2 => rw [← comp_whiskerRight, coequalizer.π_desc, comp_whiskerRight]
refine (cancel_epi ((tensorRight _ ⋙ tensorRight _).map (coequalizer.π _ _))).1 ?_
dsimp; dsimp [TensorBimod.X]
slice_lhs 1 2 => rw [associator_naturality_left]
slice_lhs 2 3 => rw [← whisker_exchange]
slice_lhs 3 5 => rw [π_tensor_id_preserves_coequalizer_inv_desc]
slice_lhs 2 3 => rw [associator_naturality_right]
slice_rhs 1 3 =>
rw [← comp_whiskerRight, ← comp_whiskerRight, π_tensor_id_preserves_coequalizer_inv_desc,
comp_whiskerRight, comp_whiskerRight]
slice_rhs 3 4 => erw [TensorBimod.π_tensor_id_actRight P (Q.tensorBimod L)]
slice_rhs 2 3 => erw [associator_naturality_middle]
dsimp
slice_rhs 3 4 =>
rw [← MonoidalCategory.whiskerLeft_comp, TensorBimod.π_tensor_id_actRight,
MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp]
monoidal
/-- An auxiliary morphism for the definition of the underlying morphism of the inverse component of
the associator isomorphism. -/
noncomputable def invAux : P.X ⊗ (Q.tensorBimod L).X ⟶ ((P.tensorBimod Q).tensorBimod L).X :=
(PreservesCoequalizer.iso (tensorLeft P.X) _ _).inv ≫
coequalizer.desc ((α_ _ _ _).inv ≫ (coequalizer.π _ _ ▷ L.X) ≫ coequalizer.π _ _)
(by
dsimp; dsimp [TensorBimod.X]
slice_lhs 1 2 => rw [associator_inv_naturality_middle]
rw [← Iso.inv_hom_id_assoc (α_ _ _ _) (P.X ◁ Q.actRight), comp_whiskerRight]
slice_lhs 3 4 =>
rw [← comp_whiskerRight, Category.assoc, ← TensorBimod.π_tensor_id_actRight,
comp_whiskerRight]
slice_lhs 4 5 => rw [coequalizer.condition]
slice_lhs 3 4 => rw [associator_naturality_left]
slice_rhs 1 2 => rw [MonoidalCategory.whiskerLeft_comp]
slice_rhs 2 3 => rw [associator_inv_naturality_right]
slice_rhs 3 4 => rw [whisker_exchange]
monoidal)
/-- The underlying morphism of the inverse component of the associator isomorphism. -/
noncomputable def inv :
(P.tensorBimod (Q.tensorBimod L)).X ⟶ ((P.tensorBimod Q).tensorBimod L).X :=
coequalizer.desc (invAux P Q L)
(by
dsimp [invAux]
refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_
dsimp [TensorBimod.X]
slice_lhs 1 2 => rw [whisker_exchange]
slice_lhs 2 4 => rw [id_tensor_π_preserves_coequalizer_inv_desc]
slice_lhs 1 2 => rw [associator_inv_naturality_left]
slice_lhs 2 3 =>
rw [← comp_whiskerRight, coequalizer.condition, comp_whiskerRight, comp_whiskerRight]
slice_rhs 1 2 => rw [associator_naturality_right]
slice_rhs 2 3 =>
rw [← MonoidalCategory.whiskerLeft_comp, TensorBimod.whiskerLeft_π_actLeft,
MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp]
slice_rhs 4 6 => rw [id_tensor_π_preserves_coequalizer_inv_desc]
slice_rhs 3 4 => rw [associator_inv_naturality_middle]
monoidal)
theorem hom_inv_id : hom P Q L ≫ inv P Q L = 𝟙 _ := by
dsimp [hom, homAux, inv, invAux]
apply coequalizer.hom_ext
slice_lhs 1 2 => rw [coequalizer.π_desc]
refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_
rw [tensorRight_map]
slice_lhs 1 3 => rw [π_tensor_id_preserves_coequalizer_inv_desc]
slice_lhs 3 4 => rw [coequalizer.π_desc]
slice_lhs 2 4 => rw [id_tensor_π_preserves_coequalizer_inv_desc]
slice_lhs 1 3 => rw [Iso.hom_inv_id_assoc]
dsimp only [TensorBimod.X]
slice_rhs 2 3 => rw [Category.comp_id]
rfl
theorem inv_hom_id : inv P Q L ≫ hom P Q L = 𝟙 _ := by
dsimp [hom, homAux, inv, invAux]
apply coequalizer.hom_ext
slice_lhs 1 2 => rw [coequalizer.π_desc]
refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_
rw [tensorLeft_map]
slice_lhs 1 3 => rw [id_tensor_π_preserves_coequalizer_inv_desc]
slice_lhs 3 4 => rw [coequalizer.π_desc]
slice_lhs 2 4 => rw [π_tensor_id_preserves_coequalizer_inv_desc]
slice_lhs 1 3 => rw [Iso.inv_hom_id_assoc]
dsimp only [TensorBimod.X]
slice_rhs 2 3 => rw [Category.comp_id]
rfl
end AssociatorBimod
namespace LeftUnitorBimod
variable {R S : Mon_ C} (P : Bimod R S)
/-- The underlying morphism of the forward component of the left unitor isomorphism. -/
noncomputable def hom : TensorBimod.X (regular R) P ⟶ P.X :=
coequalizer.desc P.actLeft (by dsimp; rw [Category.assoc, left_assoc])
/-- The underlying morphism of the inverse component of the left unitor isomorphism. -/
noncomputable def inv : P.X ⟶ TensorBimod.X (regular R) P :=
(λ_ P.X).inv ≫ (R.one ▷ _) ≫ coequalizer.π _ _
theorem hom_inv_id : hom P ≫ inv P = 𝟙 _ := by
dsimp only [hom, inv, TensorBimod.X]
ext; dsimp
slice_lhs 1 2 => rw [coequalizer.π_desc]
slice_lhs 1 2 => rw [leftUnitor_inv_naturality]
slice_lhs 2 3 => rw [whisker_exchange]
slice_lhs 3 3 => rw [← Iso.inv_hom_id_assoc (α_ R.X R.X P.X) (R.X ◁ P.actLeft)]
slice_lhs 4 6 => rw [← Category.assoc, ← coequalizer.condition]
slice_lhs 2 3 => rw [associator_inv_naturality_left]
slice_lhs 3 4 => rw [← comp_whiskerRight, Mon_.one_mul]
slice_rhs 1 2 => rw [Category.comp_id]
monoidal
theorem inv_hom_id : inv P ≫ hom P = 𝟙 _ := by
dsimp [hom, inv]
slice_lhs 3 4 => rw [coequalizer.π_desc]
rw [one_actLeft, Iso.inv_hom_id]
variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)]
variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)]
theorem hom_left_act_hom' :
((regular R).tensorBimod P).actLeft ≫ hom P = (R.X ◁ hom P) ≫ P.actLeft := by
dsimp; dsimp [hom, TensorBimod.actLeft, regular]
refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_
dsimp
slice_lhs 1 4 => rw [id_tensor_π_preserves_coequalizer_inv_colimMap_desc]
slice_lhs 2 3 => rw [left_assoc]
slice_rhs 1 2 => rw [← MonoidalCategory.whiskerLeft_comp, coequalizer.π_desc]
rw [Iso.inv_hom_id_assoc]
theorem hom_right_act_hom' :
((regular R).tensorBimod P).actRight ≫ hom P = (hom P ▷ S.X) ≫ P.actRight := by
dsimp; dsimp [hom, TensorBimod.actRight, regular]
refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_
dsimp
slice_lhs 1 4 => rw [π_tensor_id_preserves_coequalizer_inv_colimMap_desc]
slice_rhs 1 2 => rw [← comp_whiskerRight, coequalizer.π_desc]
slice_rhs 1 2 => rw [middle_assoc]
simp only [Category.assoc]
end LeftUnitorBimod
namespace RightUnitorBimod
variable {R S : Mon_ C} (P : Bimod R S)
/-- The underlying morphism of the forward component of the right unitor isomorphism. -/
noncomputable def hom : TensorBimod.X P (regular S) ⟶ P.X :=
coequalizer.desc P.actRight (by dsimp; rw [Category.assoc, right_assoc, Iso.hom_inv_id_assoc])
/-- The underlying morphism of the inverse component of the right unitor isomorphism. -/
noncomputable def inv : P.X ⟶ TensorBimod.X P (regular S) :=
(ρ_ P.X).inv ≫ (_ ◁ S.one) ≫ coequalizer.π _ _
theorem hom_inv_id : hom P ≫ inv P = 𝟙 _ := by
dsimp only [hom, inv, TensorBimod.X]
ext; dsimp
slice_lhs 1 2 => rw [coequalizer.π_desc]
slice_lhs 1 2 => rw [rightUnitor_inv_naturality]
slice_lhs 2 3 => rw [← whisker_exchange]
slice_lhs 3 4 => rw [coequalizer.condition]
slice_lhs 2 3 => rw [associator_naturality_right]
slice_lhs 3 4 => rw [← MonoidalCategory.whiskerLeft_comp, Mon_.mul_one]
slice_rhs 1 2 => rw [Category.comp_id]
monoidal
theorem inv_hom_id : inv P ≫ hom P = 𝟙 _ := by
dsimp [hom, inv]
slice_lhs 3 4 => rw [coequalizer.π_desc]
rw [actRight_one, Iso.inv_hom_id]
variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)]
variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)]
theorem hom_left_act_hom' :
(P.tensorBimod (regular S)).actLeft ≫ hom P = (R.X ◁ hom P) ≫ P.actLeft := by
dsimp; dsimp [hom, TensorBimod.actLeft, regular]
refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_
dsimp
slice_lhs 1 4 => rw [id_tensor_π_preserves_coequalizer_inv_colimMap_desc]
slice_lhs 2 3 => rw [middle_assoc]
slice_rhs 1 2 => rw [← MonoidalCategory.whiskerLeft_comp, coequalizer.π_desc]
rw [Iso.inv_hom_id_assoc]
theorem hom_right_act_hom' :
(P.tensorBimod (regular S)).actRight ≫ hom P = (hom P ▷ S.X) ≫ P.actRight := by
dsimp; dsimp [hom, TensorBimod.actRight, regular]
refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_
dsimp
slice_lhs 1 4 => rw [π_tensor_id_preserves_coequalizer_inv_colimMap_desc]
slice_lhs 2 3 => rw [right_assoc]
slice_rhs 1 2 => rw [← comp_whiskerRight, coequalizer.π_desc]
rw [Iso.hom_inv_id_assoc]
end RightUnitorBimod
variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)]
variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)]
/-- The associator as a bimodule isomorphism. -/
noncomputable def associatorBimod {W X Y Z : Mon_ C} (L : Bimod W X) (M : Bimod X Y)
(N : Bimod Y Z) : (L.tensorBimod M).tensorBimod N ≅ L.tensorBimod (M.tensorBimod N) :=
isoOfIso
{ hom := AssociatorBimod.hom L M N
inv := AssociatorBimod.inv L M N
hom_inv_id := AssociatorBimod.hom_inv_id L M N
inv_hom_id := AssociatorBimod.inv_hom_id L M N } (AssociatorBimod.hom_left_act_hom' L M N)
(AssociatorBimod.hom_right_act_hom' L M N)
/-- The left unitor as a bimodule isomorphism. -/
noncomputable def leftUnitorBimod {X Y : Mon_ C} (M : Bimod X Y) : (regular X).tensorBimod M ≅ M :=
isoOfIso
{ hom := LeftUnitorBimod.hom M
inv := LeftUnitorBimod.inv M
hom_inv_id := LeftUnitorBimod.hom_inv_id M
inv_hom_id := LeftUnitorBimod.inv_hom_id M } (LeftUnitorBimod.hom_left_act_hom' M)
(LeftUnitorBimod.hom_right_act_hom' M)
/-- The right unitor as a bimodule isomorphism. -/
noncomputable def rightUnitorBimod {X Y : Mon_ C} (M : Bimod X Y) : M.tensorBimod (regular Y) ≅ M :=
isoOfIso
{ hom := RightUnitorBimod.hom M
inv := RightUnitorBimod.inv M
hom_inv_id := RightUnitorBimod.hom_inv_id M
inv_hom_id := RightUnitorBimod.inv_hom_id M } (RightUnitorBimod.hom_left_act_hom' M)
(RightUnitorBimod.hom_right_act_hom' M)
theorem whiskerLeft_id_bimod {X Y Z : Mon_ C} {M : Bimod X Y} {N : Bimod Y Z} :
whiskerLeft M (𝟙 N) = 𝟙 (M.tensorBimod N) := by
ext
apply Limits.coequalizer.hom_ext
dsimp only [tensorBimod_X, whiskerLeft_hom, id_hom']
simp only [MonoidalCategory.whiskerLeft_id, ι_colimMap, parallelPair_obj_one,
parallelPairHom_app_one, Category.id_comp]
erw [Category.comp_id]
theorem id_whiskerRight_bimod {X Y Z : Mon_ C} {M : Bimod X Y} {N : Bimod Y Z} :
whiskerRight (𝟙 M) N = 𝟙 (M.tensorBimod N) := by
ext
apply Limits.coequalizer.hom_ext
dsimp only [tensorBimod_X, whiskerRight_hom, id_hom']
simp only [MonoidalCategory.id_whiskerRight, ι_colimMap, parallelPair_obj_one,
parallelPairHom_app_one, Category.id_comp]
erw [Category.comp_id]
| Mathlib/CategoryTheory/Monoidal/Bimod.lean | 746 | 749 | theorem whiskerLeft_comp_bimod {X Y Z : Mon_ C} (M : Bimod X Y) {N P Q : Bimod Y Z} (f : N ⟶ P)
(g : P ⟶ Q) : whiskerLeft M (f ≫ g) = whiskerLeft M f ≫ whiskerLeft M g := by | ext
apply Limits.coequalizer.hom_ext |
/-
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.Data.Finset.Option
import Mathlib.Data.PFun
import Mathlib.Data.Part
/-!
# Image of a `Finset α` under a partially defined function
In this file we define `Part.toFinset` and `Finset.pimage`. We also prove some trivial lemmas about
these definitions.
## Tags
finite set, image, partial function
-/
variable {α β : Type*}
namespace Part
/-- Convert an `o : Part α` with decidable `Part.Dom o` to `Finset α`. -/
def toFinset (o : Part α) [Decidable o.Dom] : Finset α :=
o.toOption.toFinset
@[simp]
theorem mem_toFinset {o : Part α} [Decidable o.Dom] {x : α} : x ∈ o.toFinset ↔ x ∈ o := by
simp [toFinset]
@[simp]
theorem toFinset_none [Decidable (none : Part α).Dom] : none.toFinset = (∅ : Finset α) := by
simp [toFinset]
@[simp]
theorem toFinset_some {a : α} [Decidable (some a).Dom] : (some a).toFinset = {a} := by
simp [toFinset]
@[simp]
theorem coe_toFinset (o : Part α) [Decidable o.Dom] : (o.toFinset : Set α) = { x | x ∈ o } :=
Set.ext fun _ => mem_toFinset
end Part
namespace Finset
variable [DecidableEq β] {f g : α →. β} [∀ x, Decidable (f x).Dom] [∀ x, Decidable (g x).Dom]
{s t : Finset α} {b : β}
/-- Image of `s : Finset α` under a partially defined function `f : α →. β`. -/
def pimage (f : α →. β) [∀ x, Decidable (f x).Dom] (s : Finset α) : Finset β :=
s.biUnion fun x => (f x).toFinset
@[simp]
theorem mem_pimage : b ∈ s.pimage f ↔ ∃ a ∈ s, b ∈ f a := by
simp [pimage]
@[simp, norm_cast]
theorem coe_pimage : (s.pimage f : Set β) = f.image s :=
Set.ext fun _ => mem_pimage
@[simp]
theorem pimage_some (s : Finset α) (f : α → β) [∀ x, Decidable (Part.some <| f x).Dom] :
(s.pimage fun x => Part.some (f x)) = s.image f := by
ext
simp [eq_comm]
theorem pimage_congr (h₁ : s = t) (h₂ : ∀ x ∈ t, f x = g x) : s.pimage f = t.pimage g := by
aesop
/-- Rewrite `s.pimage f` in terms of `Finset.filter`, `Finset.attach`, and `Finset.image`. -/
theorem pimage_eq_image_filter : s.pimage f =
{x ∈ s | (f x).Dom}.attach.image
fun x : { x // x ∈ filter (fun x => (f x).Dom) s } =>
(f x).get (mem_filter.mp x.coe_prop).2 := by
aesop (add simp Part.mem_eq)
theorem pimage_union [DecidableEq α] : (s ∪ t).pimage f = s.pimage f ∪ t.pimage f :=
coe_inj.1 <| by
simp only [coe_pimage, coe_union, ← PFun.image_union]
@[simp]
theorem pimage_empty : pimage f ∅ = ∅ := by
ext
simp
| Mathlib/Data/Finset/PImage.lean | 90 | 97 | theorem pimage_subset {t : Finset β} : s.pimage f ⊆ t ↔ ∀ x ∈ s, ∀ y ∈ f x, y ∈ t := by | simp [subset_iff, @forall_swap _ β]
@[mono]
theorem pimage_mono (h : s ⊆ t) : s.pimage f ⊆ t.pimage f :=
pimage_subset.2 fun x hx _ hy => mem_pimage.2 ⟨x, h hx, hy⟩
theorem pimage_inter [DecidableEq α] : (s ∩ t).pimage f ⊆ s.pimage f ∩ t.pimage f := by |
/-
Copyright (c) 2022 Bolton Bailey. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne
-/
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Analysis.SpecialFunctions.Pow.Real
import Mathlib.Data.Int.Log
/-!
# Real logarithm base `b`
In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We
define this as the division of the natural logarithms of the argument and the base, so that we have
a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and
`logb (-b) x = logb b x`.
We prove some basic properties of this function and its relation to `rpow`.
## Tags
logarithm, continuity
-/
open Set Filter Function
open Topology
noncomputable section
namespace Real
variable {b x y : ℝ}
/-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to
be `logb b |x|` for `x < 0`, and `0` for `x = 0`. -/
@[pp_nodot]
noncomputable def logb (b x : ℝ) : ℝ :=
log x / log b
theorem log_div_log : log x / log b = logb b x :=
rfl
@[simp]
theorem logb_zero : logb b 0 = 0 := by simp [logb]
@[simp]
theorem logb_one : logb b 1 = 0 := by simp [logb]
theorem logb_zero_left : logb 0 x = 0 := by simp only [← log_div_log, log_zero, div_zero]
@[simp] theorem logb_zero_left_eq_zero : logb 0 = 0 := by ext; rw [logb_zero_left, Pi.zero_apply]
theorem logb_one_left : logb 1 x = 0 := by simp only [← log_div_log, log_one, div_zero]
@[simp] theorem logb_one_left_eq_zero : logb 1 = 0 := by ext; rw [logb_one_left, Pi.zero_apply]
@[simp]
lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 :=
div_self (log_pos hb).ne'
lemma logb_self_eq_one_iff : logb b b = 1 ↔ b ≠ 0 ∧ b ≠ 1 ∧ b ≠ -1 :=
Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero
@[simp]
theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs]
@[simp]
theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by
rw [← logb_abs x, ← logb_abs (-x), abs_neg]
theorem logb_mul (hx : x ≠ 0) (hy : y ≠ 0) : logb b (x * y) = logb b x + logb b y := by
simp_rw [logb, log_mul hx hy, add_div]
theorem logb_div (hx : x ≠ 0) (hy : y ≠ 0) : logb b (x / y) = logb b x - logb b y := by
simp_rw [logb, log_div hx hy, sub_div]
@[simp]
theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div]
theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div]
theorem inv_logb_mul_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) :
(logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by
simp_rw [inv_logb]; exact logb_mul h₁ h₂
theorem inv_logb_div_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) :
(logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by
simp_rw [inv_logb]; exact logb_div h₁ h₂
theorem logb_mul_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) :
logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_mul_base h₁ h₂ c, inv_inv]
theorem logb_div_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) :
logb (a / b) c = ((logb a c)⁻¹ - (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_div_base h₁ h₂ c, inv_inv]
theorem mul_logb {a b c : ℝ} (h₁ : b ≠ 0) (h₂ : b ≠ 1) (h₃ : b ≠ -1) :
logb a b * logb b c = logb a c := by
unfold logb
rw [mul_comm, div_mul_div_cancel₀ (log_ne_zero.mpr ⟨h₁, h₂, h₃⟩)]
theorem div_logb {a b c : ℝ} (h₁ : c ≠ 0) (h₂ : c ≠ 1) (h₃ : c ≠ -1) :
logb a c / logb b c = logb a b :=
div_div_div_cancel_left' _ _ <| log_ne_zero.mpr ⟨h₁, h₂, h₃⟩
theorem logb_rpow_eq_mul_logb_of_pos (hx : 0 < x) : logb b (x ^ y) = y * logb b x := by
rw [logb, log_rpow hx, logb, mul_div_assoc]
theorem logb_pow (b x : ℝ) (k : ℕ) : logb b (x ^ k) = k * logb b x := by
rw [logb, logb, log_pow, mul_div_assoc]
section BPosAndNeOne
variable (b_pos : 0 < b) (b_ne_one : b ≠ 1)
include b_pos b_ne_one
private theorem log_b_ne_zero : log b ≠ 0 := by
have b_ne_zero : b ≠ 0 := by linarith
have b_ne_minus_one : b ≠ -1 := by linarith
simp [b_ne_one, b_ne_zero, b_ne_minus_one]
@[simp]
theorem logb_rpow : logb b (b ^ x) = x := by
rw [logb, div_eq_iff, log_rpow b_pos]
exact log_b_ne_zero b_pos b_ne_one
theorem rpow_logb_eq_abs (hx : x ≠ 0) : b ^ logb b x = |x| := by
apply log_injOn_pos
· simp only [Set.mem_Ioi]
apply rpow_pos_of_pos b_pos
· simp only [abs_pos, mem_Ioi, Ne, hx, not_false_iff]
rw [log_rpow b_pos, logb, log_abs]
field_simp [log_b_ne_zero b_pos b_ne_one]
@[simp]
theorem rpow_logb (hx : 0 < x) : b ^ logb b x = x := by
rw [rpow_logb_eq_abs b_pos b_ne_one hx.ne']
exact abs_of_pos hx
theorem rpow_logb_of_neg (hx : x < 0) : b ^ logb b x = -x := by
rw [rpow_logb_eq_abs b_pos b_ne_one (ne_of_lt hx)]
exact abs_of_neg hx
theorem logb_eq_iff_rpow_eq (hy : 0 < y) : logb b y = x ↔ b ^ x = y := by
constructor <;> rintro rfl
· exact rpow_logb b_pos b_ne_one hy
· exact logb_rpow b_pos b_ne_one
theorem surjOn_logb : SurjOn (logb b) (Ioi 0) univ := fun x _ =>
⟨b ^ x, rpow_pos_of_pos b_pos x, logb_rpow b_pos b_ne_one⟩
theorem logb_surjective : Surjective (logb b) := fun x => ⟨b ^ x, logb_rpow b_pos b_ne_one⟩
@[simp]
theorem range_logb : range (logb b) = univ :=
(logb_surjective b_pos b_ne_one).range_eq
theorem surjOn_logb' : SurjOn (logb b) (Iio 0) univ := by
intro x _
use -b ^ x
constructor
· simp only [Right.neg_neg_iff, Set.mem_Iio]
apply rpow_pos_of_pos b_pos
· rw [logb_neg_eq_logb, logb_rpow b_pos b_ne_one]
end BPosAndNeOne
section OneLtB
variable (hb : 1 < b)
include hb
private theorem b_pos : 0 < b := by linarith
-- Name has a prime added to avoid clashing with `b_ne_one` further down the file
private theorem b_ne_one' : b ≠ 1 := by linarith
@[simp]
theorem logb_le_logb (h : 0 < x) (h₁ : 0 < y) : logb b x ≤ logb b y ↔ x ≤ y := by
rw [logb, logb, div_le_div_iff_of_pos_right (log_pos hb), log_le_log_iff h h₁]
@[gcongr]
theorem logb_le_logb_of_le (h : 0 < x) (hxy : x ≤ y) : logb b x ≤ logb b y :=
(logb_le_logb hb h (by linarith)).mpr hxy
@[gcongr]
theorem logb_lt_logb (hx : 0 < x) (hxy : x < y) : logb b x < logb b y := by
rw [logb, logb, div_lt_div_iff_of_pos_right (log_pos hb)]
exact log_lt_log hx hxy
@[simp]
theorem logb_lt_logb_iff (hx : 0 < x) (hy : 0 < y) : logb b x < logb b y ↔ x < y := by
rw [logb, logb, div_lt_div_iff_of_pos_right (log_pos hb)]
exact log_lt_log_iff hx hy
theorem logb_le_iff_le_rpow (hx : 0 < x) : logb b x ≤ y ↔ x ≤ b ^ y := by
rw [← rpow_le_rpow_left_iff hb, rpow_logb (b_pos hb) (b_ne_one' hb) hx]
theorem logb_lt_iff_lt_rpow (hx : 0 < x) : logb b x < y ↔ x < b ^ y := by
rw [← rpow_lt_rpow_left_iff hb, rpow_logb (b_pos hb) (b_ne_one' hb) hx]
theorem le_logb_iff_rpow_le (hy : 0 < y) : x ≤ logb b y ↔ b ^ x ≤ y := by
rw [← rpow_le_rpow_left_iff hb, rpow_logb (b_pos hb) (b_ne_one' hb) hy]
theorem lt_logb_iff_rpow_lt (hy : 0 < y) : x < logb b y ↔ b ^ x < y := by
rw [← rpow_lt_rpow_left_iff hb, rpow_logb (b_pos hb) (b_ne_one' hb) hy]
theorem logb_pos_iff (hx : 0 < x) : 0 < logb b x ↔ 1 < x := by
rw [← @logb_one b]
rw [logb_lt_logb_iff hb zero_lt_one hx]
theorem logb_pos (hx : 1 < x) : 0 < logb b x := by
rw [logb_pos_iff hb (lt_trans zero_lt_one hx)]
exact hx
theorem logb_neg_iff (h : 0 < x) : logb b x < 0 ↔ x < 1 := by
rw [← logb_one]
exact logb_lt_logb_iff hb h zero_lt_one
theorem logb_neg (h0 : 0 < x) (h1 : x < 1) : logb b x < 0 :=
(logb_neg_iff hb h0).2 h1
theorem logb_nonneg_iff (hx : 0 < x) : 0 ≤ logb b x ↔ 1 ≤ x := by
rw [← not_lt, logb_neg_iff hb hx, not_lt]
theorem logb_nonneg (hx : 1 ≤ x) : 0 ≤ logb b x :=
(logb_nonneg_iff hb (zero_lt_one.trans_le hx)).2 hx
theorem logb_nonpos_iff (hx : 0 < x) : logb b x ≤ 0 ↔ x ≤ 1 := by
rw [← not_lt, logb_pos_iff hb hx, not_lt]
theorem logb_nonpos_iff' (hx : 0 ≤ x) : logb b x ≤ 0 ↔ x ≤ 1 := by
rcases hx.eq_or_lt with (rfl | hx)
· simp [le_refl, zero_le_one]
exact logb_nonpos_iff hb hx
theorem logb_nonpos (hx : 0 ≤ x) (h'x : x ≤ 1) : logb b x ≤ 0 :=
(logb_nonpos_iff' hb hx).2 h'x
theorem strictMonoOn_logb : StrictMonoOn (logb b) (Set.Ioi 0) := fun _ hx _ _ hxy =>
logb_lt_logb hb hx hxy
theorem strictAntiOn_logb : StrictAntiOn (logb b) (Set.Iio 0) := by
rintro x (hx : x < 0) y (hy : y < 0) hxy
rw [← logb_abs y, ← logb_abs x]
refine logb_lt_logb hb (abs_pos.2 hy.ne) ?_
rwa [abs_of_neg hy, abs_of_neg hx, neg_lt_neg_iff]
theorem logb_injOn_pos : Set.InjOn (logb b) (Set.Ioi 0) :=
(strictMonoOn_logb hb).injOn
theorem eq_one_of_pos_of_logb_eq_zero (h₁ : 0 < x) (h₂ : logb b x = 0) : x = 1 :=
logb_injOn_pos hb (Set.mem_Ioi.2 h₁) (Set.mem_Ioi.2 zero_lt_one) (h₂.trans Real.logb_one.symm)
theorem logb_ne_zero_of_pos_of_ne_one (hx_pos : 0 < x) (hx : x ≠ 1) : logb b x ≠ 0 :=
mt (eq_one_of_pos_of_logb_eq_zero hb hx_pos) hx
theorem tendsto_logb_atTop : Tendsto (logb b) atTop atTop :=
Tendsto.atTop_div_const (log_pos hb) tendsto_log_atTop
end OneLtB
section BPosAndBLtOne
variable (b_pos : 0 < b) (b_lt_one : b < 1)
include b_lt_one
private theorem b_ne_one : b ≠ 1 := by linarith
include b_pos
@[simp]
theorem logb_le_logb_of_base_lt_one (h : 0 < x) (h₁ : 0 < y) : logb b x ≤ logb b y ↔ y ≤ x := by
rw [logb, logb, div_le_div_right_of_neg (log_neg b_pos b_lt_one), log_le_log_iff h₁ h]
theorem logb_lt_logb_of_base_lt_one (hx : 0 < x) (hxy : x < y) : logb b y < logb b x := by
rw [logb, logb, div_lt_div_right_of_neg (log_neg b_pos b_lt_one)]
exact log_lt_log hx hxy
@[simp]
theorem logb_lt_logb_iff_of_base_lt_one (hx : 0 < x) (hy : 0 < y) :
logb b x < logb b y ↔ y < x := by
rw [logb, logb, div_lt_div_right_of_neg (log_neg b_pos b_lt_one)]
exact log_lt_log_iff hy hx
theorem logb_le_iff_le_rpow_of_base_lt_one (hx : 0 < x) : logb b x ≤ y ↔ b ^ y ≤ x := by
rw [← rpow_le_rpow_left_iff_of_base_lt_one b_pos b_lt_one, rpow_logb b_pos (b_ne_one b_lt_one) hx]
theorem logb_lt_iff_lt_rpow_of_base_lt_one (hx : 0 < x) : logb b x < y ↔ b ^ y < x := by
rw [← rpow_lt_rpow_left_iff_of_base_lt_one b_pos b_lt_one, rpow_logb b_pos (b_ne_one b_lt_one) hx]
theorem le_logb_iff_rpow_le_of_base_lt_one (hy : 0 < y) : x ≤ logb b y ↔ y ≤ b ^ x := by
rw [← rpow_le_rpow_left_iff_of_base_lt_one b_pos b_lt_one, rpow_logb b_pos (b_ne_one b_lt_one) hy]
theorem lt_logb_iff_rpow_lt_of_base_lt_one (hy : 0 < y) : x < logb b y ↔ y < b ^ x := by
rw [← rpow_lt_rpow_left_iff_of_base_lt_one b_pos b_lt_one, rpow_logb b_pos (b_ne_one b_lt_one) hy]
theorem logb_pos_iff_of_base_lt_one (hx : 0 < x) : 0 < logb b x ↔ x < 1 := by
rw [← @logb_one b, logb_lt_logb_iff_of_base_lt_one b_pos b_lt_one zero_lt_one hx]
theorem logb_pos_of_base_lt_one (hx : 0 < x) (hx' : x < 1) : 0 < logb b x := by
rw [logb_pos_iff_of_base_lt_one b_pos b_lt_one hx]
exact hx'
theorem logb_neg_iff_of_base_lt_one (h : 0 < x) : logb b x < 0 ↔ 1 < x := by
rw [← @logb_one b, logb_lt_logb_iff_of_base_lt_one b_pos b_lt_one h zero_lt_one]
theorem logb_neg_of_base_lt_one (h1 : 1 < x) : logb b x < 0 :=
(logb_neg_iff_of_base_lt_one b_pos b_lt_one (lt_trans zero_lt_one h1)).2 h1
| Mathlib/Analysis/SpecialFunctions/Log/Base.lean | 312 | 314 | theorem logb_nonneg_iff_of_base_lt_one (hx : 0 < x) : 0 ≤ logb b x ↔ x ≤ 1 := by | rw [← not_lt, logb_neg_iff_of_base_lt_one b_pos b_lt_one hx, not_lt] |
/-
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.MFDeriv.SpecificFunctions
/-!
# Differentiability of models with corners and (extended) charts
In this file, we analyse the differentiability of charts, models with corners and extended charts.
We show that
* models with corners are differentiable
* charts are differentiable on their source
* `mdifferentiableOn_extChartAt`: `extChartAt` is differentiable on its source
Suppose a partial homeomorphism `e` is differentiable. This file shows
* `PartialHomeomorph.MDifferentiable.mfderiv`: its derivative is a continuous linear equivalence
* `PartialHomeomorph.MDifferentiable.mfderiv_bijective`: its derivative is bijective;
there are also spelling with trivial kernel and full range
In particular, (extended) charts have bijective differential.
## Tags
charts, differentiable, bijective
-/
noncomputable section
open scoped Manifold ContDiff
open Bundle Set Topology
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜]
{E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H]
{I : ModelWithCorners 𝕜 E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M]
{E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H' : Type*} [TopologicalSpace H']
{I' : ModelWithCorners 𝕜 E' H'} {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M']
{E'' : Type*} [NormedAddCommGroup E''] [NormedSpace 𝕜 E''] {H'' : Type*} [TopologicalSpace H'']
{I'' : ModelWithCorners 𝕜 E'' H''} {M'' : Type*} [TopologicalSpace M''] [ChartedSpace H'' M'']
section ModelWithCorners
namespace ModelWithCorners
/- In general, the model with corner `I` is implicit in most theorems in differential geometry, but
this section is about `I` as a map, not as a parameter. Therefore, we make it explicit. -/
variable (I)
/-! #### Model with corners -/
protected theorem hasMFDerivAt {x} : HasMFDerivAt I 𝓘(𝕜, E) I x (ContinuousLinearMap.id _ _) :=
⟨I.continuousAt, (hasFDerivWithinAt_id _ _).congr' I.rightInvOn (mem_range_self _)⟩
protected theorem hasMFDerivWithinAt {s x} :
HasMFDerivWithinAt I 𝓘(𝕜, E) I s x (ContinuousLinearMap.id _ _) :=
I.hasMFDerivAt.hasMFDerivWithinAt
protected theorem mdifferentiableWithinAt {s x} : MDifferentiableWithinAt I 𝓘(𝕜, E) I s x :=
I.hasMFDerivWithinAt.mdifferentiableWithinAt
protected theorem mdifferentiableAt {x} : MDifferentiableAt I 𝓘(𝕜, E) I x :=
I.hasMFDerivAt.mdifferentiableAt
protected theorem mdifferentiableOn {s} : MDifferentiableOn I 𝓘(𝕜, E) I s := fun _ _ =>
I.mdifferentiableWithinAt
protected theorem mdifferentiable : MDifferentiable I 𝓘(𝕜, E) I := fun _ => I.mdifferentiableAt
theorem hasMFDerivWithinAt_symm {x} (hx : x ∈ range I) :
HasMFDerivWithinAt 𝓘(𝕜, E) I I.symm (range I) x (ContinuousLinearMap.id _ _) :=
⟨I.continuousWithinAt_symm,
(hasFDerivWithinAt_id _ _).congr' (fun _y hy => I.rightInvOn hy.1) ⟨hx, mem_range_self _⟩⟩
theorem mdifferentiableOn_symm : MDifferentiableOn 𝓘(𝕜, E) I I.symm (range I) := fun _x hx =>
(I.hasMFDerivWithinAt_symm hx).mdifferentiableWithinAt
theorem mdifferentiableWithinAt_symm {z : E} (hz : z ∈ range I) :
MDifferentiableWithinAt 𝓘(𝕜, E) I I.symm (range I) z :=
I.mdifferentiableOn_symm z hz
end ModelWithCorners
end ModelWithCorners
section Charts
variable [IsManifold I 1 M] [IsManifold I' 1 M']
[IsManifold I'' 1 M''] {e : PartialHomeomorph M H}
| Mathlib/Geometry/Manifold/MFDeriv/Atlas.lean | 89 | 106 | theorem mdifferentiableAt_atlas (h : e ∈ atlas H M) {x : M} (hx : x ∈ e.source) :
MDifferentiableAt I I e x := by | rw [mdifferentiableAt_iff]
refine ⟨(e.continuousOn x hx).continuousAt (e.open_source.mem_nhds hx), ?_⟩
have mem :
I ((chartAt H x : M → H) x) ∈ I.symm ⁻¹' ((chartAt H x).symm ≫ₕ e).source ∩ range I := by
simp only [hx, mfld_simps]
have : (chartAt H x).symm.trans e ∈ contDiffGroupoid 1 I :=
HasGroupoid.compatible (chart_mem_atlas H x) h
have A :
ContDiffOn 𝕜 1 (I ∘ (chartAt H x).symm.trans e ∘ I.symm)
(I.symm ⁻¹' ((chartAt H x).symm.trans e).source ∩ range I) :=
this.1
have B := A.differentiableOn le_rfl (I ((chartAt H x : M → H) x)) mem
simp only [mfld_simps] at B
rw [inter_comm, differentiableWithinAt_inter] at B
· simpa only [mfld_simps]
· apply IsOpen.mem_nhds ((PartialHomeomorph.open_source _).preimage I.continuous_symm) mem.1 |
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Kim Morrison
-/
import Mathlib.Analysis.Convex.Combination
import Mathlib.LinearAlgebra.AffineSpace.Independent
import Mathlib.Tactic.FieldSimp
/-!
# Carathéodory's convexity theorem
Convex hull can be regarded as a refinement of affine span. Both are closure operators but whereas
convex hull takes values in the lattice of convex subsets, affine span takes values in the much
coarser sublattice of affine subspaces.
The cost of this refinement is that one no longer has bases. However Carathéodory's convexity
theorem offers some compensation. Given a set `s` together with a point `x` in its convex hull,
Carathéodory says that one may find an affine-independent family of elements `s` whose convex hull
contains `x`. Thus the difference from the case of affine span is that the affine-independent family
depends on `x`.
In particular, in finite dimensions Carathéodory's theorem implies that the convex hull of a set `s`
in `𝕜ᵈ` is the union of the convex hulls of the `(d + 1)`-tuples in `s`.
## Main results
* `convexHull_eq_union`: Carathéodory's convexity theorem
## Implementation details
This theorem was formalized as part of the Sphere Eversion project.
## Tags
convex hull, caratheodory
-/
open Set Finset
universe u
variable {𝕜 : Type*} {E : Type u} [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜]
[AddCommGroup E] [Module 𝕜 E]
namespace Caratheodory
/-- If `x` is in the convex hull of some finset `t` whose elements are not affine-independent,
then it is in the convex hull of a strict subset of `t`. -/
theorem mem_convexHull_erase [DecidableEq E] {t : Finset E} (h : ¬AffineIndependent 𝕜 ((↑) : t → E))
{x : E} (m : x ∈ convexHull 𝕜 (↑t : Set E)) :
∃ y : (↑t : Set E), x ∈ convexHull 𝕜 (↑(t.erase y) : Set E) := by
simp only [Finset.convexHull_eq, mem_setOf_eq] at m ⊢
obtain ⟨f, fpos, fsum, rfl⟩ := m
obtain ⟨g, gcombo, gsum, gpos⟩ := exists_nontrivial_relation_sum_zero_of_not_affine_ind h
replace gpos := exists_pos_of_sum_zero_of_exists_nonzero g gsum gpos
clear h
let s := {z ∈ t | 0 < g z}
obtain ⟨i₀, mem, w⟩ : ∃ i₀ ∈ s, ∀ i ∈ s, f i₀ / g i₀ ≤ f i / g i := by
apply s.exists_min_image fun z => f z / g z
obtain ⟨x, hx, hgx⟩ : ∃ x ∈ t, 0 < g x := gpos
exact ⟨x, mem_filter.mpr ⟨hx, hgx⟩⟩
have hg : 0 < g i₀ := by
rw [mem_filter] at mem
exact mem.2
have hi₀ : i₀ ∈ t := filter_subset _ _ mem
let k : E → 𝕜 := fun z => f z - f i₀ / g i₀ * g z
have hk : k i₀ = 0 := by field_simp [k, ne_of_gt hg]
have ksum : ∑ e ∈ t.erase i₀, k e = 1 := by
calc
∑ e ∈ t.erase i₀, k e = ∑ e ∈ t, k e := by
conv_rhs => rw [← insert_erase hi₀, sum_insert (not_mem_erase i₀ t), hk, zero_add]
_ = ∑ e ∈ t, (f e - f i₀ / g i₀ * g e) := rfl
_ = 1 := by rw [sum_sub_distrib, fsum, ← mul_sum, gsum, mul_zero, sub_zero]
refine ⟨⟨i₀, hi₀⟩, k, ?_, by convert ksum, ?_⟩
· simp only [k, and_imp, sub_nonneg, mem_erase, Ne, Subtype.coe_mk]
intro e _ het
by_cases hes : e ∈ s
· have hge : 0 < g e := by
rw [mem_filter] at hes
exact hes.2
rw [← le_div_iff₀ hge]
exact w _ hes
· calc
_ ≤ 0 := by
apply mul_nonpos_of_nonneg_of_nonpos
· apply div_nonneg (fpos i₀ (mem_of_subset (filter_subset _ t) mem)) (le_of_lt hg)
· simpa only [s, mem_filter, het, true_and, not_lt] using hes
_ ≤ f e := fpos e het
· rw [Subtype.coe_mk, centerMass_eq_of_sum_1 _ id ksum]
calc
∑ e ∈ t.erase i₀, k e • e = ∑ e ∈ t, k e • e := sum_erase _ (by rw [hk, zero_smul])
_ = ∑ e ∈ t, (f e - f i₀ / g i₀ * g e) • e := rfl
_ = t.centerMass f id := by
simp only [sub_smul, mul_smul, sum_sub_distrib, ← smul_sum, gcombo, smul_zero, sub_zero,
centerMass, fsum, inv_one, one_smul, id]
variable {s : Set E} {x : E}
/-- Given a point `x` in the convex hull of a set `s`, this is a finite subset of `s` of minimum
cardinality, whose convex hull contains `x`. -/
noncomputable def minCardFinsetOfMemConvexHull (hx : x ∈ convexHull 𝕜 s) : Finset E :=
Function.argminOn Finset.card { t | ↑t ⊆ s ∧ x ∈ convexHull 𝕜 (t : Set E) } <| by
simpa only [convexHull_eq_union_convexHull_finite_subsets s, exists_prop, mem_iUnion] using hx
variable (hx : x ∈ convexHull 𝕜 s)
theorem minCardFinsetOfMemConvexHull_subseteq : ↑(minCardFinsetOfMemConvexHull hx) ⊆ s :=
(Function.argminOn_mem _ { t : Finset E | ↑t ⊆ s ∧ x ∈ convexHull 𝕜 (t : Set E) } _).1
theorem mem_minCardFinsetOfMemConvexHull :
x ∈ convexHull 𝕜 (minCardFinsetOfMemConvexHull hx : Set E) :=
(Function.argminOn_mem _ { t : Finset E | ↑t ⊆ s ∧ x ∈ convexHull 𝕜 (t : Set E) } _).2
theorem minCardFinsetOfMemConvexHull_nonempty : (minCardFinsetOfMemConvexHull hx).Nonempty := by
rw [← Finset.coe_nonempty, ← @convexHull_nonempty_iff 𝕜]
exact ⟨x, mem_minCardFinsetOfMemConvexHull hx⟩
theorem minCardFinsetOfMemConvexHull_card_le_card {t : Finset E} (ht₁ : ↑t ⊆ s)
(ht₂ : x ∈ convexHull 𝕜 (t : Set E)) : #(minCardFinsetOfMemConvexHull hx) ≤ #t :=
Function.argminOn_le _ _ (by exact ⟨ht₁, ht₂⟩)
| Mathlib/Analysis/Convex/Caratheodory.lean | 124 | 126 | theorem affineIndependent_minCardFinsetOfMemConvexHull :
AffineIndependent 𝕜 ((↑) : minCardFinsetOfMemConvexHull hx → E) := by | let k := #(minCardFinsetOfMemConvexHull hx) - 1 |
/-
Copyright (c) 2021 Aaron Anderson, Jesse Michael Han, Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Jesse Michael Han, Floris van Doorn
-/
import Mathlib.Data.Finset.Basic
import Mathlib.ModelTheory.Syntax
import Mathlib.Data.List.ProdSigma
/-!
# Basics on First-Order Semantics
This file defines the interpretations of first-order terms, formulas, sentences, and theories
in a style inspired by the [Flypitch project](https://flypitch.github.io/).
## Main Definitions
- `FirstOrder.Language.Term.realize` is defined so that `t.realize v` is the term `t` evaluated at
variables `v`.
- `FirstOrder.Language.BoundedFormula.Realize` is defined so that `φ.Realize v xs` is the bounded
formula `φ` evaluated at tuples of variables `v` and `xs`.
- `FirstOrder.Language.Formula.Realize` is defined so that `φ.Realize v` is the formula `φ`
evaluated at variables `v`.
- `FirstOrder.Language.Sentence.Realize` is defined so that `φ.Realize M` is the sentence `φ`
evaluated in the structure `M`. Also denoted `M ⊨ φ`.
- `FirstOrder.Language.Theory.Model` is defined so that `T.Model M` is true if and only if every
sentence of `T` is realized in `M`. Also denoted `T ⊨ φ`.
## Main Results
- Several results in this file show that syntactic constructions such as `relabel`, `castLE`,
`liftAt`, `subst`, and the actions of language maps commute with realization of terms, formulas,
sentences, and theories.
## Implementation Notes
- Formulas use a modified version of de Bruijn variables. Specifically, a `L.BoundedFormula α n`
is a formula with some variables indexed by a type `α`, which cannot be quantified over, and some
indexed by `Fin n`, which can. For any `φ : L.BoundedFormula α (n + 1)`, we define the formula
`∀' φ : L.BoundedFormula α n` by universally quantifying over the variable indexed by
`n : Fin (n + 1)`.
## References
For the Flypitch project:
- [J. Han, F. van Doorn, *A formal proof of the independence of the continuum hypothesis*]
[flypitch_cpp]
- [J. Han, F. van Doorn, *A formalization of forcing and the unprovability of
the continuum hypothesis*][flypitch_itp]
-/
universe u v w u' v'
namespace FirstOrder
namespace Language
variable {L : Language.{u, v}} {L' : Language}
variable {M : Type w} {N P : Type*} [L.Structure M] [L.Structure N] [L.Structure P]
variable {α : Type u'} {β : Type v'} {γ : Type*}
open FirstOrder Cardinal
open Structure Cardinal Fin
namespace Term
/-- A term `t` with variables indexed by `α` can be evaluated by giving a value to each variable. -/
def realize (v : α → M) : ∀ _t : L.Term α, M
| var k => v k
| func f ts => funMap f fun i => (ts i).realize v
@[simp]
theorem realize_var (v : α → M) (k) : realize v (var k : L.Term α) = v k := rfl
@[simp]
theorem realize_func (v : α → M) {n} (f : L.Functions n) (ts) :
realize v (func f ts : L.Term α) = funMap f fun i => (ts i).realize v := rfl
@[simp]
theorem realize_relabel {t : L.Term α} {g : α → β} {v : β → M} :
(t.relabel g).realize v = t.realize (v ∘ g) := by
induction t with
| var => rfl
| func f ts ih => simp [ih]
@[simp]
theorem realize_liftAt {n n' m : ℕ} {t : L.Term (α ⊕ (Fin n))} {v : α ⊕ (Fin (n + n')) → M} :
(t.liftAt n' m).realize v =
t.realize (v ∘ Sum.map id fun i : Fin _ =>
if ↑i < m then Fin.castAdd n' i else Fin.addNat i n') :=
realize_relabel
@[simp]
theorem realize_constants {c : L.Constants} {v : α → M} : c.term.realize v = c :=
funMap_eq_coe_constants
@[simp]
theorem realize_functions_apply₁ {f : L.Functions 1} {t : L.Term α} {v : α → M} :
(f.apply₁ t).realize v = funMap f ![t.realize v] := by
rw [Functions.apply₁, Term.realize]
refine congr rfl (funext fun i => ?_)
simp only [Matrix.cons_val_fin_one]
@[simp]
theorem realize_functions_apply₂ {f : L.Functions 2} {t₁ t₂ : L.Term α} {v : α → M} :
(f.apply₂ t₁ t₂).realize v = funMap f ![t₁.realize v, t₂.realize v] := by
rw [Functions.apply₂, Term.realize]
refine congr rfl (funext (Fin.cases ?_ ?_))
· simp only [Matrix.cons_val_zero]
· simp only [Matrix.cons_val_succ, Matrix.cons_val_fin_one, forall_const]
theorem realize_con {A : Set M} {a : A} {v : α → M} : (L.con a).term.realize v = a :=
rfl
@[simp]
theorem realize_subst {t : L.Term α} {tf : α → L.Term β} {v : β → M} :
(t.subst tf).realize v = t.realize fun a => (tf a).realize v := by
induction t with
| var => rfl
| func _ _ ih => simp [ih]
theorem realize_restrictVar [DecidableEq α] {t : L.Term α} {f : t.varFinset → β}
{v : β → M} (v' : α → M) (hv' : ∀ a, v (f a) = v' a) :
(t.restrictVar f).realize v = t.realize v' := by
induction t with
| var => simp [restrictVar, hv']
| func _ _ ih =>
exact congr rfl (funext fun i => ih i ((by simp [Function.comp_apply, hv'])))
/-- A special case of `realize_restrictVar`, included because we can add the `simp` attribute
to it -/
@[simp]
theorem realize_restrictVar' [DecidableEq α] {t : L.Term α} {s : Set α} (h : ↑t.varFinset ⊆ s)
{v : α → M} : (t.restrictVar (Set.inclusion h)).realize (v ∘ (↑)) = t.realize v :=
realize_restrictVar _ (by simp)
theorem realize_restrictVarLeft [DecidableEq α] {γ : Type*} {t : L.Term (α ⊕ γ)}
{f : t.varFinsetLeft → β}
{xs : β ⊕ γ → M} (xs' : α → M) (hxs' : ∀ a, xs (Sum.inl (f a)) = xs' a) :
(t.restrictVarLeft f).realize xs = t.realize (Sum.elim xs' (xs ∘ Sum.inr)) := by
induction t with
| var a => cases a <;> simp [restrictVarLeft, hxs']
| func _ _ ih =>
exact congr rfl (funext fun i => ih i (by simp [hxs']))
/-- A special case of `realize_restrictVarLeft`, included because we can add the `simp` attribute
to it -/
@[simp]
theorem realize_restrictVarLeft' [DecidableEq α] {γ : Type*} {t : L.Term (α ⊕ γ)} {s : Set α}
(h : ↑t.varFinsetLeft ⊆ s) {v : α → M} {xs : γ → M} :
(t.restrictVarLeft (Set.inclusion h)).realize (Sum.elim (v ∘ (↑)) xs) =
t.realize (Sum.elim v xs) :=
realize_restrictVarLeft _ (by simp)
@[simp]
theorem realize_constantsToVars [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M]
{t : L[[α]].Term β} {v : β → M} :
t.constantsToVars.realize (Sum.elim (fun a => ↑(L.con a)) v) = t.realize v := by
induction t with
| var => simp
| @func n f ts ih =>
cases n
· cases f
· simp only [realize, ih, constantsOn, constantsOnFunc, constantsToVars]
-- Porting note: below lemma does not work with simp for some reason
rw [withConstants_funMap_sumInl]
· simp only [realize, constantsToVars, Sum.elim_inl, funMap_eq_coe_constants]
rfl
· obtain - | f := f
· simp only [realize, ih, constantsOn, constantsOnFunc, constantsToVars]
-- Porting note: below lemma does not work with simp for some reason
rw [withConstants_funMap_sumInl]
· exact isEmptyElim f
@[simp]
| Mathlib/ModelTheory/Semantics.lean | 178 | 188 | theorem realize_varsToConstants [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M]
{t : L.Term (α ⊕ β)} {v : β → M} :
t.varsToConstants.realize v = t.realize (Sum.elim (fun a => ↑(L.con a)) v) := by | induction t with
| var ab => rcases ab with a | b <;> simp [Language.con]
| func f ts ih =>
simp only [realize, constantsOn, constantsOnFunc, ih, varsToConstants]
-- Porting note: below lemma does not work with simp for some reason
rw [withConstants_funMap_sumInl]
theorem realize_constantsVarsEquivLeft [L[[α]].Structure M] |
/-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.BooleanAlgebra
import Mathlib.Tactic.Common
/-!
# Co-Heyting boundary
The boundary of an element of a co-Heyting algebra is the intersection of its Heyting negation with
itself. The boundary in the co-Heyting algebra of closed sets coincides with the topological
boundary.
## Main declarations
* `Coheyting.boundary`: Co-Heyting boundary. `Coheyting.boundary a = a ⊓ ¬a`
## Notation
`∂ a` is notation for `Coheyting.boundary a` in locale `Heyting`.
-/
assert_not_exists RelIso
variable {α : Type*}
namespace Coheyting
variable [CoheytingAlgebra α] {a b : α}
/-- The boundary of an element of a co-Heyting algebra is the intersection of its Heyting negation
with itself. Note that this is always `⊥` for a boolean algebra. -/
def boundary (a : α) : α :=
a ⊓ ¬a
/-- The boundary of an element of a co-Heyting algebra. -/
scoped[Heyting] prefix:120 "∂ " => Coheyting.boundary
open Heyting
-- TODO: Should hnot be named hNot?
theorem inf_hnot_self (a : α) : a ⊓ ¬a = ∂ a :=
rfl
theorem boundary_le : ∂ a ≤ a :=
inf_le_left
theorem boundary_le_hnot : ∂ a ≤ ¬a :=
inf_le_right
@[simp]
theorem boundary_bot : ∂ (⊥ : α) = ⊥ := bot_inf_eq _
@[simp]
theorem boundary_top : ∂ (⊤ : α) = ⊥ := by rw [boundary, hnot_top, inf_bot_eq]
theorem boundary_hnot_le (a : α) : ∂ (¬a) ≤ ∂ a :=
(inf_comm _ _).trans_le <| inf_le_inf_right _ hnot_hnot_le
@[simp]
| Mathlib/Order/Heyting/Boundary.lean | 63 | 63 | theorem boundary_hnot_hnot (a : α) : ∂ (¬¬a) = ∂ (¬a) := by | |
/-
Copyright (c) 2021 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Kyle Miller
-/
import Mathlib.CategoryTheory.ConcreteCategory.Basic
import Mathlib.Util.AddRelatedDecl
import Batteries.Tactic.Lint
/-!
# Tools to reformulate category-theoretic lemmas in concrete categories
## The `elementwise` attribute
The `elementwise` attribute generates lemmas for concrete categories from lemmas
that equate morphisms in a category.
A sort of inverse to this for the `Type*` category is the `@[higher_order]` attribute.
For more details, see the documentation attached to the `syntax` declaration.
## Main definitions
- The `@[elementwise]` attribute.
- The ``elementwise_of% h` term elaborator.
## Implementation
This closely follows the implementation of the `@[reassoc]` attribute, due to Simon Hudon and
reimplemented by Kim Morrison in Lean 4.
-/
open Lean Meta Elab Tactic
open Mathlib.Tactic
namespace Tactic.Elementwise
open CategoryTheory
section theorems
universe u
theorem forall_congr_forget_Type (α : Type u) (p : α → Prop) :
(∀ (x : (forget (Type u)).obj α), p x) ↔ ∀ (x : α), p x := Iff.rfl
attribute [local instance] HasForget.instFunLike HasForget.hasCoeToSort
theorem forget_hom_Type (α β : Type u) (f : α ⟶ β) : DFunLike.coe f = f := rfl
| Mathlib/Tactic/CategoryTheory/Elementwise.lean | 52 | 53 | theorem hom_elementwise {C : Type*} [Category C] [HasForget C]
{X Y : C} {f g : X ⟶ Y} (h : f = g) (x : X) : f x = g x := by | rw [h] |
/-
Copyright (c) 2023 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Analysis.Calculus.LineDeriv.Basic
import Mathlib.Analysis.Calculus.FDeriv.Measurable
/-! # Measurability of the line derivative
We prove in `measurable_lineDeriv` that the line derivative of a function (with respect to a
locally compact scalar field) is measurable, provided the function is continuous.
In `measurable_lineDeriv_uncurry`, assuming additionally that the source space is second countable,
we show that `(x, v) ↦ lineDeriv 𝕜 f x v` is also measurable.
An assumption such as continuity is necessary, as otherwise one could alternate in a non-measurable
way between differentiable and non-differentiable functions along the various lines
directed by `v`.
-/
open MeasureTheory
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] [LocallyCompactSpace 𝕜]
{E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] [MeasurableSpace E] [OpensMeasurableSpace E]
{F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] [CompleteSpace F]
{f : E → F} {v : E}
/-!
Measurability of the line derivative `lineDeriv 𝕜 f x v` with respect to a fixed direction `v`.
-/
theorem measurableSet_lineDifferentiableAt (hf : Continuous f) :
MeasurableSet {x : E | LineDifferentiableAt 𝕜 f x v} := by
borelize 𝕜
let g : E → 𝕜 → F := fun x t ↦ f (x + t • v)
have hg : Continuous g.uncurry := by fun_prop
exact measurable_prodMk_right (measurableSet_of_differentiableAt_with_param 𝕜 hg)
theorem measurable_lineDeriv [MeasurableSpace F] [BorelSpace F]
(hf : Continuous f) : Measurable (fun x ↦ lineDeriv 𝕜 f x v) := by
borelize 𝕜
let g : E → 𝕜 → F := fun x t ↦ f (x + t • v)
have hg : Continuous g.uncurry := by fun_prop
exact (measurable_deriv_with_param hg).comp measurable_prodMk_right
theorem stronglyMeasurable_lineDeriv [SecondCountableTopologyEither E F] (hf : Continuous f) :
StronglyMeasurable (fun x ↦ lineDeriv 𝕜 f x v) := by
borelize 𝕜
let g : E → 𝕜 → F := fun x t ↦ f (x + t • v)
have hg : Continuous g.uncurry := by fun_prop
exact (stronglyMeasurable_deriv_with_param hg).comp_measurable measurable_prodMk_right
theorem aemeasurable_lineDeriv [MeasurableSpace F] [BorelSpace F]
(hf : Continuous f) (μ : Measure E) :
AEMeasurable (fun x ↦ lineDeriv 𝕜 f x v) μ :=
(measurable_lineDeriv hf).aemeasurable
theorem aestronglyMeasurable_lineDeriv [SecondCountableTopologyEither E F]
(hf : Continuous f) (μ : Measure E) :
AEStronglyMeasurable (fun x ↦ lineDeriv 𝕜 f x v) μ :=
(stronglyMeasurable_lineDeriv hf).aestronglyMeasurable
/-!
Measurability of the line derivative `lineDeriv 𝕜 f x v` when varying both `x` and `v`. For this,
we need an additional second countability assumption on `E` to make sure that open sets are
measurable in `E × E`.
-/
variable [SecondCountableTopology E]
| Mathlib/Analysis/Calculus/LineDeriv/Measurable.lean | 72 | 81 | theorem measurableSet_lineDifferentiableAt_uncurry (hf : Continuous f) :
MeasurableSet {p : E × E | LineDifferentiableAt 𝕜 f p.1 p.2} := by | borelize 𝕜
let g : (E × E) → 𝕜 → F := fun p t ↦ f (p.1 + t • p.2)
have : Continuous g.uncurry :=
hf.comp <| (continuous_fst.comp continuous_fst).add
<| continuous_snd.smul (continuous_snd.comp continuous_fst)
have M_meas : MeasurableSet {q : (E × E) × 𝕜 | DifferentiableAt 𝕜 (g q.1) q.2} :=
measurableSet_of_differentiableAt_with_param 𝕜 this
exact measurable_prodMk_right M_meas |
/-
Copyright (c) 2021 David Wärn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Wärn, Antoine Labelle, Rémi Bottinelli
-/
import Mathlib.Combinatorics.Quiver.Path
import Mathlib.Combinatorics.Quiver.Push
/-!
## Symmetric quivers and arrow reversal
This file contains constructions related to symmetric quivers:
* `Symmetrify V` adds formal inverses to each arrow of `V`.
* `HasReverse` is the class of quivers where each arrow has an assigned formal inverse.
* `HasInvolutiveReverse` extends `HasReverse` by requiring that the reverse of the reverse
is equal to the original arrow.
* `Prefunctor.PreserveReverse` is the class of prefunctors mapping reverses to reverses.
* `Symmetrify.of`, `Symmetrify.lift`, and the associated lemmas witness the universal property
of `Symmetrify`.
-/
universe v u w v'
namespace Quiver
/-- A type synonym for the symmetrized quiver (with an arrow both ways for each original arrow).
NB: this does not work for `Prop`-valued quivers. It requires `[Quiver.{v+1} V]`. -/
def Symmetrify (V : Type*) := V
instance symmetrifyQuiver (V : Type u) [Quiver V] : Quiver (Symmetrify V) :=
⟨fun a b : V ↦ (a ⟶ b) ⊕ (b ⟶ a)⟩
variable (U V W : Type*) [Quiver.{u + 1} U] [Quiver.{v + 1} V] [Quiver.{w + 1} W]
/-- A quiver `HasReverse` if we can reverse an arrow `p` from `a` to `b` to get an arrow
`p.reverse` from `b` to `a`. -/
class HasReverse where
/-- the map which sends an arrow to its reverse -/
reverse' : ∀ {a b : V}, (a ⟶ b) → (b ⟶ a)
/-- Reverse the direction of an arrow. -/
def reverse {V} [Quiver.{v + 1} V] [HasReverse V] {a b : V} : (a ⟶ b) → (b ⟶ a) :=
HasReverse.reverse'
/-- A quiver `HasInvolutiveReverse` if reversing twice is the identity. -/
class HasInvolutiveReverse extends HasReverse V where
/-- `reverse` is involutive -/
inv' : ∀ {a b : V} (f : a ⟶ b), reverse (reverse f) = f
variable {U V W}
@[simp]
theorem reverse_reverse [h : HasInvolutiveReverse V] {a b : V} (f : a ⟶ b) :
reverse (reverse f) = f := by apply h.inv'
@[simp]
theorem reverse_inj [h : HasInvolutiveReverse V] {a b : V}
(f g : a ⟶ b) : reverse f = reverse g ↔ f = g := by
constructor
· rintro h
simpa using congr_arg Quiver.reverse h
· rintro h
congr
| Mathlib/Combinatorics/Quiver/Symmetric.lean | 66 | 72 | theorem eq_reverse_iff [h : HasInvolutiveReverse V] {a b : V} (f : a ⟶ b)
(g : b ⟶ a) : f = reverse g ↔ reverse f = g := by | rw [← reverse_inj, reverse_reverse]
section MapReverse
variable [HasReverse U] [HasReverse V] [HasReverse W] |
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis
-/
import Mathlib.RingTheory.Valuation.Basic
import Mathlib.NumberTheory.Padics.PadicNorm
import Mathlib.Analysis.Normed.Field.Lemmas
import Mathlib.Tactic.Peel
import Mathlib.Topology.MetricSpace.Ultra.Basic
/-!
# p-adic numbers
This file defines the `p`-adic numbers (rationals) `ℚ_[p]` as
the completion of `ℚ` with respect to the `p`-adic norm.
We show that the `p`-adic norm on `ℚ` extends to `ℚ_[p]`, that `ℚ` is embedded in `ℚ_[p]`,
and that `ℚ_[p]` is Cauchy complete.
## Important definitions
* `Padic` : the type of `p`-adic numbers
* `padicNormE` : the rational valued `p`-adic norm on `ℚ_[p]`
* `Padic.addValuation` : the additive `p`-adic valuation on `ℚ_[p]`, with values in `WithTop ℤ`
## Notation
We introduce the notation `ℚ_[p]` for the `p`-adic numbers.
## Implementation notes
Much, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically
by taking `[Fact p.Prime]` as a type class argument.
We use the same concrete Cauchy sequence construction that is used to construct `ℝ`.
`ℚ_[p]` inherits a field structure from this construction.
The extension of the norm on `ℚ` to `ℚ_[p]` is *not* analogous to extending the absolute value to
`ℝ` and hence the proof that `ℚ_[p]` is complete is different from the proof that ℝ is complete.
`padicNormE` is the rational-valued `p`-adic norm on `ℚ_[p]`.
To instantiate `ℚ_[p]` as a normed field, we must cast this into an `ℝ`-valued norm.
The `ℝ`-valued norm, using notation `‖ ‖` from normed spaces,
is the canonical representation of this norm.
`simp` prefers `padicNorm` to `padicNormE` when possible.
Since `padicNormE` and `‖ ‖` have different types, `simp` does not rewrite one to the other.
Coercions from `ℚ` to `ℚ_[p]` are set up to work with the `norm_cast` tactic.
## References
* [F. Q. Gouvêa, *p-adic numbers*][gouvea1997]
* [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019]
* <https://en.wikipedia.org/wiki/P-adic_number>
## Tags
p-adic, p adic, padic, norm, valuation, cauchy, completion, p-adic completion
-/
noncomputable section
open Nat padicNorm CauSeq CauSeq.Completion Metric
/-- The type of Cauchy sequences of rationals with respect to the `p`-adic norm. -/
abbrev PadicSeq (p : ℕ) :=
CauSeq _ (padicNorm p)
namespace PadicSeq
section
variable {p : ℕ} [Fact p.Prime]
/-- The `p`-adic norm of the entries of a nonzero Cauchy sequence of rationals is eventually
constant. -/
theorem stationary {f : CauSeq ℚ (padicNorm p)} (hf : ¬f ≈ 0) :
∃ N, ∀ m n, N ≤ m → N ≤ n → padicNorm p (f n) = padicNorm p (f m) :=
have : ∃ ε > 0, ∃ N1, ∀ j ≥ N1, ε ≤ padicNorm p (f j) :=
CauSeq.abv_pos_of_not_limZero <| not_limZero_of_not_congr_zero hf
let ⟨ε, hε, N1, hN1⟩ := this
let ⟨N2, hN2⟩ := CauSeq.cauchy₂ f hε
⟨max N1 N2, fun n m hn hm ↦ by
have : padicNorm p (f n - f m) < ε := hN2 _ (max_le_iff.1 hn).2 _ (max_le_iff.1 hm).2
have : padicNorm p (f n - f m) < padicNorm p (f n) :=
lt_of_lt_of_le this <| hN1 _ (max_le_iff.1 hn).1
have : padicNorm p (f n - f m) < max (padicNorm p (f n)) (padicNorm p (f m)) :=
lt_max_iff.2 (Or.inl this)
by_contra hne
rw [← padicNorm.neg (f m)] at hne
have hnam := add_eq_max_of_ne hne
rw [padicNorm.neg, max_comm] at hnam
rw [← hnam, sub_eq_add_neg, add_comm] at this
apply _root_.lt_irrefl _ this⟩
/-- For all `n ≥ stationaryPoint f hf`, the `p`-adic norm of `f n` is the same. -/
def stationaryPoint {f : PadicSeq p} (hf : ¬f ≈ 0) : ℕ :=
Classical.choose <| stationary hf
theorem stationaryPoint_spec {f : PadicSeq p} (hf : ¬f ≈ 0) :
∀ {m n},
stationaryPoint hf ≤ m → stationaryPoint hf ≤ n → padicNorm p (f n) = padicNorm p (f m) :=
@(Classical.choose_spec <| stationary hf)
open Classical in
/-- Since the norm of the entries of a Cauchy sequence is eventually stationary,
we can lift the norm to sequences. -/
def norm (f : PadicSeq p) : ℚ :=
if hf : f ≈ 0 then 0 else padicNorm p (f (stationaryPoint hf))
theorem norm_zero_iff (f : PadicSeq p) : f.norm = 0 ↔ f ≈ 0 := by
constructor
· intro h
by_contra hf
unfold norm at h
split_ifs at h
apply hf
intro ε hε
exists stationaryPoint hf
intro j hj
have heq := stationaryPoint_spec hf le_rfl hj
simpa [h, heq]
· intro h
simp [norm, h]
end
section Embedding
open CauSeq
variable {p : ℕ} [Fact p.Prime]
theorem equiv_zero_of_val_eq_of_equiv_zero {f g : PadicSeq p}
(h : ∀ k, padicNorm p (f k) = padicNorm p (g k)) (hf : f ≈ 0) : g ≈ 0 := fun ε hε ↦
let ⟨i, hi⟩ := hf _ hε
⟨i, fun j hj ↦ by simpa [h] using hi _ hj⟩
theorem norm_nonzero_of_not_equiv_zero {f : PadicSeq p} (hf : ¬f ≈ 0) : f.norm ≠ 0 :=
hf ∘ f.norm_zero_iff.1
theorem norm_eq_norm_app_of_nonzero {f : PadicSeq p} (hf : ¬f ≈ 0) :
∃ k, f.norm = padicNorm p k ∧ k ≠ 0 :=
have heq : f.norm = padicNorm p (f <| stationaryPoint hf) := by simp [norm, hf]
⟨f <| stationaryPoint hf, heq, fun h ↦
norm_nonzero_of_not_equiv_zero hf (by simpa [h] using heq)⟩
theorem not_limZero_const_of_nonzero {q : ℚ} (hq : q ≠ 0) : ¬LimZero (const (padicNorm p) q) :=
fun h' ↦ hq <| const_limZero.1 h'
theorem not_equiv_zero_const_of_nonzero {q : ℚ} (hq : q ≠ 0) : ¬const (padicNorm p) q ≈ 0 :=
fun h : LimZero (const (padicNorm p) q - 0) ↦
not_limZero_const_of_nonzero (p := p) hq <| by simpa using h
theorem norm_nonneg (f : PadicSeq p) : 0 ≤ f.norm := by
classical exact if hf : f ≈ 0 then by simp [hf, norm] else by simp [norm, hf, padicNorm.nonneg]
/-- An auxiliary lemma for manipulating sequence indices. -/
theorem lift_index_left_left {f : PadicSeq p} (hf : ¬f ≈ 0) (v2 v3 : ℕ) :
padicNorm p (f (stationaryPoint hf)) =
padicNorm p (f (max (stationaryPoint hf) (max v2 v3))) := by
apply stationaryPoint_spec hf
· apply le_max_left
· exact le_rfl
/-- An auxiliary lemma for manipulating sequence indices. -/
theorem lift_index_left {f : PadicSeq p} (hf : ¬f ≈ 0) (v1 v3 : ℕ) :
padicNorm p (f (stationaryPoint hf)) =
padicNorm p (f (max v1 (max (stationaryPoint hf) v3))) := by
apply stationaryPoint_spec hf
· apply le_trans
· apply le_max_left _ v3
· apply le_max_right
· exact le_rfl
/-- An auxiliary lemma for manipulating sequence indices. -/
theorem lift_index_right {f : PadicSeq p} (hf : ¬f ≈ 0) (v1 v2 : ℕ) :
padicNorm p (f (stationaryPoint hf)) =
padicNorm p (f (max v1 (max v2 (stationaryPoint hf)))) := by
apply stationaryPoint_spec hf
· apply le_trans
· apply le_max_right v2
· apply le_max_right
· exact le_rfl
end Embedding
section Valuation
open CauSeq
variable {p : ℕ} [Fact p.Prime]
/-! ### Valuation on `PadicSeq` -/
open Classical in
/-- The `p`-adic valuation on `ℚ` lifts to `PadicSeq p`.
`Valuation f` is defined to be the valuation of the (`ℚ`-valued) stationary point of `f`. -/
def valuation (f : PadicSeq p) : ℤ :=
if hf : f ≈ 0 then 0 else padicValRat p (f (stationaryPoint hf))
theorem norm_eq_zpow_neg_valuation {f : PadicSeq p} (hf : ¬f ≈ 0) :
f.norm = (p : ℚ) ^ (-f.valuation : ℤ) := by
rw [norm, valuation, dif_neg hf, dif_neg hf, padicNorm, if_neg]
intro H
apply CauSeq.not_limZero_of_not_congr_zero hf
intro ε hε
use stationaryPoint hf
intro n hn
rw [stationaryPoint_spec hf le_rfl hn]
simpa [H] using hε
@[deprecated (since := "2024-12-10")] alias norm_eq_pow_val := norm_eq_zpow_neg_valuation
theorem val_eq_iff_norm_eq {f g : PadicSeq p} (hf : ¬f ≈ 0) (hg : ¬g ≈ 0) :
f.valuation = g.valuation ↔ f.norm = g.norm := by
rw [norm_eq_zpow_neg_valuation hf, norm_eq_zpow_neg_valuation hg, ← neg_inj, zpow_right_inj₀]
· exact mod_cast (Fact.out : p.Prime).pos
· exact mod_cast (Fact.out : p.Prime).ne_one
end Valuation
end PadicSeq
section
open PadicSeq
-- Porting note: Commented out `padic_index_simp` tactic
/-
private unsafe def index_simp_core (hh hf hg : expr)
(at_ : Interactive.Loc := Interactive.Loc.ns [none]) : tactic Unit := do
let [v1, v2, v3] ← [hh, hf, hg].mapM fun n => tactic.mk_app `` stationary_point [n] <|> return n
let e1 ← tactic.mk_app `` lift_index_left_left [hh, v2, v3] <|> return q(True)
let e2 ← tactic.mk_app `` lift_index_left [hf, v1, v3] <|> return q(True)
let e3 ← tactic.mk_app `` lift_index_right [hg, v1, v2] <|> return q(True)
let sl ← [e1, e2, e3].foldlM (fun s e => simp_lemmas.add s e) simp_lemmas.mk
when at_ (tactic.simp_target sl >> tactic.skip)
let hs ← at_.get_locals
hs (tactic.simp_hyp sl [])
/-- This is a special-purpose tactic that lifts `padicNorm (f (stationary_point f))` to
`padicNorm (f (max _ _ _))`. -/
unsafe def tactic.interactive.padic_index_simp (l : interactive.parse interactive.types.pexpr_list)
(at_ : interactive.parse interactive.types.location) : tactic Unit := do
let [h, f, g] ← l.mapM tactic.i_to_expr
index_simp_core h f g at_
-/
end
namespace PadicSeq
section Embedding
open CauSeq
variable {p : ℕ} [hp : Fact p.Prime]
theorem norm_mul (f g : PadicSeq p) : (f * g).norm = f.norm * g.norm := by
classical
exact if hf : f ≈ 0 then by
have hg : f * g ≈ 0 := mul_equiv_zero' _ hf
simp only [hf, hg, norm, dif_pos, zero_mul]
else
if hg : g ≈ 0 then by
have hf : f * g ≈ 0 := mul_equiv_zero _ hg
simp only [hf, hg, norm, dif_pos, mul_zero]
else by
unfold norm
have hfg := mul_not_equiv_zero hf hg
simp only [hfg, hf, hg, dite_false]
-- Porting note: originally `padic_index_simp [hfg, hf, hg]`
rw [lift_index_left_left hfg, lift_index_left hf, lift_index_right hg]
apply padicNorm.mul
theorem eq_zero_iff_equiv_zero (f : PadicSeq p) : mk f = 0 ↔ f ≈ 0 :=
mk_eq
theorem ne_zero_iff_nequiv_zero (f : PadicSeq p) : mk f ≠ 0 ↔ ¬f ≈ 0 :=
eq_zero_iff_equiv_zero _ |>.not
theorem norm_const (q : ℚ) : norm (const (padicNorm p) q) = padicNorm p q := by
obtain rfl | hq := eq_or_ne q 0
· simp [norm]
· simp [norm, not_equiv_zero_const_of_nonzero hq]
theorem norm_values_discrete (a : PadicSeq p) (ha : ¬a ≈ 0) : ∃ z : ℤ, a.norm = (p : ℚ) ^ (-z) := by
let ⟨k, hk, hk'⟩ := norm_eq_norm_app_of_nonzero ha
simpa [hk] using padicNorm.values_discrete hk'
theorem norm_one : norm (1 : PadicSeq p) = 1 := by
have h1 : ¬(1 : PadicSeq p) ≈ 0 := one_not_equiv_zero _
simp [h1, norm, hp.1.one_lt]
private theorem norm_eq_of_equiv_aux {f g : PadicSeq p} (hf : ¬f ≈ 0) (hg : ¬g ≈ 0) (hfg : f ≈ g)
(h : padicNorm p (f (stationaryPoint hf)) ≠ padicNorm p (g (stationaryPoint hg)))
(hlt : padicNorm p (g (stationaryPoint hg)) < padicNorm p (f (stationaryPoint hf))) :
False := by
have hpn : 0 < padicNorm p (f (stationaryPoint hf)) - padicNorm p (g (stationaryPoint hg)) :=
sub_pos_of_lt hlt
obtain ⟨N, hN⟩ := hfg _ hpn
let i := max N (max (stationaryPoint hf) (stationaryPoint hg))
have hi : N ≤ i := le_max_left _ _
have hN' := hN _ hi
-- Porting note: originally `padic_index_simp [N, hf, hg] at hN' h hlt`
rw [lift_index_left hf N (stationaryPoint hg), lift_index_right hg N (stationaryPoint hf)]
at hN' h hlt
have hpne : padicNorm p (f i) ≠ padicNorm p (-g i) := by rwa [← padicNorm.neg (g i)] at h
rw [CauSeq.sub_apply, sub_eq_add_neg, add_eq_max_of_ne hpne, padicNorm.neg, max_eq_left_of_lt hlt]
at hN'
have : padicNorm p (f i) < padicNorm p (f i) := by
apply lt_of_lt_of_le hN'
apply sub_le_self
apply padicNorm.nonneg
exact lt_irrefl _ this
private theorem norm_eq_of_equiv {f g : PadicSeq p} (hf : ¬f ≈ 0) (hg : ¬g ≈ 0) (hfg : f ≈ g) :
padicNorm p (f (stationaryPoint hf)) = padicNorm p (g (stationaryPoint hg)) := by
by_contra h
cases lt_or_le (padicNorm p (g (stationaryPoint hg))) (padicNorm p (f (stationaryPoint hf))) with
| inl hlt =>
exact norm_eq_of_equiv_aux hf hg hfg h hlt
| inr hle =>
apply norm_eq_of_equiv_aux hg hf (Setoid.symm hfg) (Ne.symm h)
exact lt_of_le_of_ne hle h
theorem norm_equiv {f g : PadicSeq p} (hfg : f ≈ g) : f.norm = g.norm := by
classical
exact if hf : f ≈ 0 then by
have hg : g ≈ 0 := Setoid.trans (Setoid.symm hfg) hf
simp [norm, hf, hg]
else by
have hg : ¬g ≈ 0 := hf ∘ Setoid.trans hfg
unfold norm; split_ifs; exact norm_eq_of_equiv hf hg hfg
private theorem norm_nonarchimedean_aux {f g : PadicSeq p} (hfg : ¬f + g ≈ 0) (hf : ¬f ≈ 0)
(hg : ¬g ≈ 0) : (f + g).norm ≤ max f.norm g.norm := by
unfold norm; split_ifs
-- Porting note: originally `padic_index_simp [hfg, hf, hg]`
rw [lift_index_left_left hfg, lift_index_left hf, lift_index_right hg]
apply padicNorm.nonarchimedean
theorem norm_nonarchimedean (f g : PadicSeq p) : (f + g).norm ≤ max f.norm g.norm := by
classical
exact if hfg : f + g ≈ 0 then by
have : 0 ≤ max f.norm g.norm := le_max_of_le_left (norm_nonneg _)
simpa only [hfg, norm]
else
if hf : f ≈ 0 then by
have hfg' : f + g ≈ g := by
change LimZero (f - 0) at hf
show LimZero (f + g - g); · simpa only [sub_zero, add_sub_cancel_right] using hf
have hcfg : (f + g).norm = g.norm := norm_equiv hfg'
have hcl : f.norm = 0 := (norm_zero_iff f).2 hf
have : max f.norm g.norm = g.norm := by rw [hcl]; exact max_eq_right (norm_nonneg _)
rw [this, hcfg]
else
if hg : g ≈ 0 then by
have hfg' : f + g ≈ f := by
change LimZero (g - 0) at hg
show LimZero (f + g - f); · simpa only [add_sub_cancel_left, sub_zero] using hg
have hcfg : (f + g).norm = f.norm := norm_equiv hfg'
have hcl : g.norm = 0 := (norm_zero_iff g).2 hg
have : max f.norm g.norm = f.norm := by rw [hcl]; exact max_eq_left (norm_nonneg _)
rw [this, hcfg]
else norm_nonarchimedean_aux hfg hf hg
theorem norm_eq {f g : PadicSeq p} (h : ∀ k, padicNorm p (f k) = padicNorm p (g k)) :
f.norm = g.norm := by
classical
exact if hf : f ≈ 0 then by
have hg : g ≈ 0 := equiv_zero_of_val_eq_of_equiv_zero h hf
simp only [hf, hg, norm, dif_pos]
else by
have hg : ¬g ≈ 0 := fun hg ↦
hf <| equiv_zero_of_val_eq_of_equiv_zero (by simp only [h, forall_const, eq_self_iff_true]) hg
simp only [hg, hf, norm, dif_neg, not_false_iff]
let i := max (stationaryPoint hf) (stationaryPoint hg)
have hpf : padicNorm p (f (stationaryPoint hf)) = padicNorm p (f i) := by
apply stationaryPoint_spec
· apply le_max_left
· exact le_rfl
have hpg : padicNorm p (g (stationaryPoint hg)) = padicNorm p (g i) := by
apply stationaryPoint_spec
· apply le_max_right
· exact le_rfl
rw [hpf, hpg, h]
theorem norm_neg (a : PadicSeq p) : (-a).norm = a.norm :=
norm_eq <| by simp
theorem norm_eq_of_add_equiv_zero {f g : PadicSeq p} (h : f + g ≈ 0) : f.norm = g.norm := by
have : LimZero (f + g - 0) := h
have : f ≈ -g := show LimZero (f - -g) by simpa only [sub_zero, sub_neg_eq_add]
have : f.norm = (-g).norm := norm_equiv this
simpa only [norm_neg] using this
theorem add_eq_max_of_ne {f g : PadicSeq p} (hfgne : f.norm ≠ g.norm) :
(f + g).norm = max f.norm g.norm := by
classical
have hfg : ¬f + g ≈ 0 := mt norm_eq_of_add_equiv_zero hfgne
exact if hf : f ≈ 0 then by
have : LimZero (f - 0) := hf
have : f + g ≈ g := show LimZero (f + g - g) by simpa only [sub_zero, add_sub_cancel_right]
have h1 : (f + g).norm = g.norm := norm_equiv this
have h2 : f.norm = 0 := (norm_zero_iff _).2 hf
rw [h1, h2, max_eq_right (norm_nonneg _)]
else
if hg : g ≈ 0 then by
have : LimZero (g - 0) := hg
have : f + g ≈ f := show LimZero (f + g - f) by simpa only [add_sub_cancel_left, sub_zero]
have h1 : (f + g).norm = f.norm := norm_equiv this
have h2 : g.norm = 0 := (norm_zero_iff _).2 hg
rw [h1, h2, max_eq_left (norm_nonneg _)]
else by
unfold norm at hfgne ⊢; split_ifs at hfgne ⊢
-- Porting note: originally `padic_index_simp [hfg, hf, hg] at hfgne ⊢`
rw [lift_index_left hf, lift_index_right hg] at hfgne
· rw [lift_index_left_left hfg, lift_index_left hf, lift_index_right hg]
exact padicNorm.add_eq_max_of_ne hfgne
end Embedding
end PadicSeq
/-- The `p`-adic numbers `ℚ_[p]` are the Cauchy completion of `ℚ` with respect to the `p`-adic norm.
-/
def Padic (p : ℕ) [Fact p.Prime] :=
CauSeq.Completion.Cauchy (padicNorm p)
/-- notation for p-padic rationals -/
notation "ℚ_[" p "]" => Padic p
namespace Padic
section Completion
variable {p : ℕ} [Fact p.Prime]
instance field : Field ℚ_[p] :=
Cauchy.field
instance : Inhabited ℚ_[p] :=
⟨0⟩
-- short circuits
instance : CommRing ℚ_[p] :=
Cauchy.commRing
instance : Ring ℚ_[p] :=
Cauchy.ring
instance : Zero ℚ_[p] := by infer_instance
instance : One ℚ_[p] := by infer_instance
instance : Add ℚ_[p] := by infer_instance
instance : Mul ℚ_[p] := by infer_instance
instance : Sub ℚ_[p] := by infer_instance
instance : Neg ℚ_[p] := by infer_instance
instance : Div ℚ_[p] := by infer_instance
instance : AddCommGroup ℚ_[p] := by infer_instance
/-- Builds the equivalence class of a Cauchy sequence of rationals. -/
def mk : PadicSeq p → ℚ_[p] :=
Quotient.mk'
variable (p)
theorem zero_def : (0 : ℚ_[p]) = ⟦0⟧ := rfl
theorem mk_eq {f g : PadicSeq p} : mk f = mk g ↔ f ≈ g :=
Quotient.eq'
theorem const_equiv {q r : ℚ} : const (padicNorm p) q ≈ const (padicNorm p) r ↔ q = r :=
⟨fun heq ↦ eq_of_sub_eq_zero <| const_limZero.1 heq, fun heq ↦ by
rw [heq]⟩
@[norm_cast]
theorem coe_inj {q r : ℚ} : (↑q : ℚ_[p]) = ↑r ↔ q = r :=
⟨(const_equiv p).1 ∘ Quotient.eq'.1, fun h ↦ by rw [h]⟩
instance : CharZero ℚ_[p] :=
⟨fun m n ↦ by
rw [← Rat.cast_natCast]
norm_cast
exact id⟩
@[norm_cast]
theorem coe_add : ∀ {x y : ℚ}, (↑(x + y) : ℚ_[p]) = ↑x + ↑y :=
Rat.cast_add _ _
@[norm_cast]
theorem coe_neg : ∀ {x : ℚ}, (↑(-x) : ℚ_[p]) = -↑x :=
Rat.cast_neg _
@[norm_cast]
theorem coe_mul : ∀ {x y : ℚ}, (↑(x * y) : ℚ_[p]) = ↑x * ↑y :=
Rat.cast_mul _ _
@[norm_cast]
theorem coe_sub : ∀ {x y : ℚ}, (↑(x - y) : ℚ_[p]) = ↑x - ↑y :=
Rat.cast_sub _ _
@[norm_cast]
theorem coe_div : ∀ {x y : ℚ}, (↑(x / y) : ℚ_[p]) = ↑x / ↑y :=
Rat.cast_div _ _
@[norm_cast]
theorem coe_one : (↑(1 : ℚ) : ℚ_[p]) = 1 := rfl
@[norm_cast]
theorem coe_zero : (↑(0 : ℚ) : ℚ_[p]) = 0 := rfl
end Completion
end Padic
/-- The rational-valued `p`-adic norm on `ℚ_[p]` is lifted from the norm on Cauchy sequences. The
canonical form of this function is the normed space instance, with notation `‖ ‖`. -/
def padicNormE {p : ℕ} [hp : Fact p.Prime] : AbsoluteValue ℚ_[p] ℚ where
toFun := Quotient.lift PadicSeq.norm <| @PadicSeq.norm_equiv _ _
map_mul' q r := Quotient.inductionOn₂ q r <| PadicSeq.norm_mul
nonneg' q := Quotient.inductionOn q <| PadicSeq.norm_nonneg
eq_zero' q := Quotient.inductionOn q fun r ↦ by
rw [Padic.zero_def, Quotient.eq]
exact PadicSeq.norm_zero_iff r
add_le' q r := by
trans
max ((Quotient.lift PadicSeq.norm <| @PadicSeq.norm_equiv _ _) q)
((Quotient.lift PadicSeq.norm <| @PadicSeq.norm_equiv _ _) r)
· exact Quotient.inductionOn₂ q r <| PadicSeq.norm_nonarchimedean
refine max_le_add_of_nonneg (Quotient.inductionOn q <| PadicSeq.norm_nonneg) ?_
exact Quotient.inductionOn r <| PadicSeq.norm_nonneg
namespace padicNormE
section Embedding
open PadicSeq
variable {p : ℕ} [Fact p.Prime]
theorem defn (f : PadicSeq p) {ε : ℚ} (hε : 0 < ε) :
∃ N, ∀ i ≥ N, padicNormE (Padic.mk f - f i : ℚ_[p]) < ε := by
dsimp [padicNormE]
-- `change ∃ N, ∀ i ≥ N, (f - const _ (f i)).norm < ε` also works, but is very slow
suffices hyp : ∃ N, ∀ i ≥ N, (f - const _ (f i)).norm < ε by peel hyp with N; use N
by_contra! h
obtain ⟨N, hN⟩ := cauchy₂ f hε
rcases h N with ⟨i, hi, hge⟩
have hne : ¬f - const (padicNorm p) (f i) ≈ 0 := fun h ↦ by
rw [PadicSeq.norm, dif_pos h] at hge
exact not_lt_of_ge hge hε
unfold PadicSeq.norm at hge; split_ifs at hge
apply not_le_of_gt _ hge
cases _root_.le_total N (stationaryPoint hne) with
| inl hgen =>
exact hN _ hgen _ hi
| inr hngen =>
have := stationaryPoint_spec hne le_rfl hngen
rw [← this]
exact hN _ le_rfl _ hi
/-- Theorems about `padicNormE` are named with a `'` so the names do not conflict with the
equivalent theorems about `norm` (`‖ ‖`). -/
theorem nonarchimedean' (q r : ℚ_[p]) :
padicNormE (q + r : ℚ_[p]) ≤ max (padicNormE q) (padicNormE r) :=
Quotient.inductionOn₂ q r <| norm_nonarchimedean
/-- Theorems about `padicNormE` are named with a `'` so the names do not conflict with the
equivalent theorems about `norm` (`‖ ‖`). -/
theorem add_eq_max_of_ne' {q r : ℚ_[p]} :
padicNormE q ≠ padicNormE r → padicNormE (q + r : ℚ_[p]) = max (padicNormE q) (padicNormE r) :=
Quotient.inductionOn₂ q r fun _ _ ↦ PadicSeq.add_eq_max_of_ne
@[simp]
theorem eq_padic_norm' (q : ℚ) : padicNormE (q : ℚ_[p]) = padicNorm p q :=
norm_const _
protected theorem image' {q : ℚ_[p]} : q ≠ 0 → ∃ n : ℤ, padicNormE q = (p : ℚ) ^ (-n) :=
Quotient.inductionOn q fun f hf ↦
have : ¬f ≈ 0 := (ne_zero_iff_nequiv_zero f).1 hf
norm_values_discrete f this
end Embedding
end padicNormE
namespace Padic
section Complete
open PadicSeq Padic
variable {p : ℕ} [Fact p.Prime] (f : CauSeq _ (@padicNormE p _))
theorem rat_dense' (q : ℚ_[p]) {ε : ℚ} (hε : 0 < ε) : ∃ r : ℚ, padicNormE (q - r : ℚ_[p]) < ε :=
Quotient.inductionOn q fun q' ↦
have : ∃ N, ∀ m ≥ N, ∀ n ≥ N, padicNorm p (q' m - q' n) < ε := cauchy₂ _ hε
let ⟨N, hN⟩ := this
⟨q' N, by
classical
dsimp [padicNormE]
-- Porting note: this used to be `change`, but that times out.
convert_to PadicSeq.norm (q' - const _ (q' N)) < ε
rcases Decidable.em (q' - const (padicNorm p) (q' N) ≈ 0) with heq | hne'
· simpa only [heq, PadicSeq.norm, dif_pos]
· simp only [PadicSeq.norm, dif_neg hne']
change padicNorm p (q' _ - q' _) < ε
rcases Decidable.em (stationaryPoint hne' ≤ N) with hle | hle
· have := (stationaryPoint_spec hne' le_rfl hle).symm
simp only [const_apply, sub_apply, padicNorm.zero, sub_self] at this
simpa only [this]
· exact hN _ (lt_of_not_ge hle).le _ le_rfl⟩
private theorem div_nat_pos (n : ℕ) : 0 < 1 / (n + 1 : ℚ) :=
div_pos zero_lt_one (mod_cast succ_pos _)
/-- `limSeq f`, for `f` a Cauchy sequence of `p`-adic numbers, is a sequence of rationals with the
same limit point as `f`. -/
def limSeq : ℕ → ℚ :=
fun n ↦ Classical.choose (rat_dense' (f n) (div_nat_pos n))
theorem exi_rat_seq_conv {ε : ℚ} (hε : 0 < ε) :
∃ N, ∀ i ≥ N, padicNormE (f i - (limSeq f i : ℚ_[p]) : ℚ_[p]) < ε := by
refine (exists_nat_gt (1 / ε)).imp fun N hN i hi ↦ ?_
have h := Classical.choose_spec (rat_dense' (f i) (div_nat_pos i))
refine lt_of_lt_of_le h ((div_le_iff₀' <| mod_cast succ_pos _).mpr ?_)
rw [right_distrib]
apply le_add_of_le_of_nonneg
· exact (div_le_iff₀ hε).mp (le_trans (le_of_lt hN) (mod_cast hi))
· apply le_of_lt
simpa
theorem exi_rat_seq_conv_cauchy : IsCauSeq (padicNorm p) (limSeq f) := fun ε hε ↦ by
have hε3 : 0 < ε / 3 := div_pos hε (by norm_num)
let ⟨N, hN⟩ := exi_rat_seq_conv f hε3
let ⟨N2, hN2⟩ := f.cauchy₂ hε3
exists max N N2
intro j hj
suffices
padicNormE (limSeq f j - f (max N N2) + (f (max N N2) - limSeq f (max N N2)) : ℚ_[p]) < ε by
ring_nf at this ⊢
rw [← padicNormE.eq_padic_norm']
exact mod_cast this
apply lt_of_le_of_lt
· apply padicNormE.add_le
· rw [← add_thirds ε]
apply _root_.add_lt_add
· suffices padicNormE (limSeq f j - f j + (f j - f (max N N2)) : ℚ_[p]) < ε / 3 + ε / 3 by
simpa only [sub_add_sub_cancel]
apply lt_of_le_of_lt
· apply padicNormE.add_le
· apply _root_.add_lt_add
· rw [padicNormE.map_sub]
apply mod_cast hN j
exact le_of_max_le_left hj
· exact hN2 _ (le_of_max_le_right hj) _ (le_max_right _ _)
· apply mod_cast hN (max N N2)
apply le_max_left
private def lim' : PadicSeq p :=
⟨_, exi_rat_seq_conv_cauchy f⟩
private def lim : ℚ_[p] :=
⟦lim' f⟧
theorem complete' : ∃ q : ℚ_[p], ∀ ε > 0, ∃ N, ∀ i ≥ N, padicNormE (q - f i : ℚ_[p]) < ε :=
⟨lim f, fun ε hε ↦ by
obtain ⟨N, hN⟩ := exi_rat_seq_conv f (half_pos hε)
obtain ⟨N2, hN2⟩ := padicNormE.defn (lim' f) (half_pos hε)
refine ⟨max N N2, fun i hi ↦ ?_⟩
rw [← sub_add_sub_cancel _ (lim' f i : ℚ_[p]) _]
refine (padicNormE.add_le _ _).trans_lt ?_
rw [← add_halves ε]
apply _root_.add_lt_add
· apply hN2 _ (le_of_max_le_right hi)
· rw [padicNormE.map_sub]
exact hN _ (le_of_max_le_left hi)⟩
theorem complete'' : ∃ q : ℚ_[p], ∀ ε > 0, ∃ N, ∀ i ≥ N, padicNormE (f i - q : ℚ_[p]) < ε := by
obtain ⟨x, hx⟩ := complete' f
refine ⟨x, fun ε hε => ?_⟩
obtain ⟨N, hN⟩ := hx ε hε
refine ⟨N, fun i hi => ?_⟩
rw [padicNormE.map_sub]
exact hN i hi
end Complete
section NormedSpace
variable (p : ℕ) [Fact p.Prime]
instance : Dist ℚ_[p] :=
⟨fun x y ↦ padicNormE (x - y : ℚ_[p])⟩
instance : IsUltrametricDist ℚ_[p] :=
⟨fun x y z ↦ by simpa [dist] using padicNormE.nonarchimedean' (x - y) (y - z)⟩
instance metricSpace : MetricSpace ℚ_[p] where
dist_self := by simp [dist]
dist := dist
dist_comm x y := by simp [dist, ← padicNormE.map_neg (x - y : ℚ_[p])]
dist_triangle x y z := by
dsimp [dist]
exact mod_cast padicNormE.sub_le x y z
eq_of_dist_eq_zero := by
dsimp [dist]; intro _ _ h
apply eq_of_sub_eq_zero
apply padicNormE.eq_zero.1
exact mod_cast h
instance : Norm ℚ_[p] :=
⟨fun x ↦ padicNormE x⟩
instance normedField : NormedField ℚ_[p] :=
{ Padic.field,
Padic.metricSpace p with
dist_eq := fun _ _ ↦ rfl
norm_mul := by simp [Norm.norm, map_mul]
norm := norm }
instance isAbsoluteValue : IsAbsoluteValue fun a : ℚ_[p] ↦ ‖a‖ where
abv_nonneg' := norm_nonneg
abv_eq_zero' := norm_eq_zero
abv_add' := norm_add_le
abv_mul' := by simp [Norm.norm, map_mul]
theorem rat_dense (q : ℚ_[p]) {ε : ℝ} (hε : 0 < ε) : ∃ r : ℚ, ‖q - r‖ < ε :=
let ⟨ε', hε'l, hε'r⟩ := exists_rat_btwn hε
let ⟨r, hr⟩ := rat_dense' q (ε := ε') (by simpa using hε'l)
⟨r, lt_trans (by simpa [Norm.norm] using hr) hε'r⟩
end NormedSpace
end Padic
namespace padicNormE
section NormedSpace
variable {p : ℕ} [hp : Fact p.Prime]
-- Porting note: Linter thinks this is a duplicate simp lemma, so `priority` is assigned
@[simp (high)]
protected theorem mul (q r : ℚ_[p]) : ‖q * r‖ = ‖q‖ * ‖r‖ := by simp [Norm.norm, map_mul]
protected theorem is_norm (q : ℚ_[p]) : ↑(padicNormE q) = ‖q‖ := rfl
theorem nonarchimedean (q r : ℚ_[p]) : ‖q + r‖ ≤ max ‖q‖ ‖r‖ := by
dsimp [norm]
exact mod_cast nonarchimedean' _ _
theorem add_eq_max_of_ne {q r : ℚ_[p]} (h : ‖q‖ ≠ ‖r‖) : ‖q + r‖ = max ‖q‖ ‖r‖ := by
dsimp [norm] at h ⊢
have : padicNormE q ≠ padicNormE r := mod_cast h
exact mod_cast add_eq_max_of_ne' this
@[simp]
theorem eq_padicNorm (q : ℚ) : ‖(q : ℚ_[p])‖ = padicNorm p q := by
dsimp [norm]
rw [← padicNormE.eq_padic_norm']
@[simp]
theorem norm_p : ‖(p : ℚ_[p])‖ = (p : ℝ)⁻¹ := by
rw [← @Rat.cast_natCast ℝ _ p]
rw [← @Rat.cast_natCast ℚ_[p] _ p]
simp [hp.1.ne_zero, hp.1.ne_one, norm, padicNorm, padicValRat, padicValInt, zpow_neg,
-Rat.cast_natCast]
theorem norm_p_lt_one : ‖(p : ℚ_[p])‖ < 1 := by
rw [norm_p]
exact inv_lt_one_of_one_lt₀ <| mod_cast hp.1.one_lt
-- Porting note: Linter thinks this is a duplicate simp lemma, so `priority` is assigned
@[simp (high)]
theorem norm_p_zpow (n : ℤ) : ‖(p : ℚ_[p]) ^ n‖ = (p : ℝ) ^ (-n) := by
rw [norm_zpow, norm_p, zpow_neg, inv_zpow]
-- Porting note: Linter thinks this is a duplicate simp lemma, so `priority` is assigned
@[simp (high)]
theorem norm_p_pow (n : ℕ) : ‖(p : ℚ_[p]) ^ n‖ = (p : ℝ) ^ (-n : ℤ) := by
rw [← norm_p_zpow, zpow_natCast]
instance : NontriviallyNormedField ℚ_[p] :=
{ Padic.normedField p with
non_trivial :=
⟨p⁻¹, by
rw [norm_inv, norm_p, inv_inv]
exact mod_cast hp.1.one_lt⟩ }
protected theorem image {q : ℚ_[p]} : q ≠ 0 → ∃ n : ℤ, ‖q‖ = ↑((p : ℚ) ^ (-n)) :=
Quotient.inductionOn q fun f hf ↦
have : ¬f ≈ 0 := (PadicSeq.ne_zero_iff_nequiv_zero f).1 hf
let ⟨n, hn⟩ := PadicSeq.norm_values_discrete f this
⟨n, by rw [← hn]; rfl⟩
protected theorem is_rat (q : ℚ_[p]) : ∃ q' : ℚ, ‖q‖ = q' := by
classical
exact if h : q = 0 then ⟨0, by simp [h]⟩
else
let ⟨n, hn⟩ := padicNormE.image h
⟨_, hn⟩
/-- `ratNorm q`, for a `p`-adic number `q` is the `p`-adic norm of `q`, as rational number.
The lemma `padicNormE.eq_ratNorm` asserts `‖q‖ = ratNorm q`. -/
def ratNorm (q : ℚ_[p]) : ℚ :=
Classical.choose (padicNormE.is_rat q)
theorem eq_ratNorm (q : ℚ_[p]) : ‖q‖ = ratNorm q :=
Classical.choose_spec (padicNormE.is_rat q)
theorem norm_rat_le_one : ∀ {q : ℚ} (_ : ¬p ∣ q.den), ‖(q : ℚ_[p])‖ ≤ 1
| ⟨n, d, hn, hd⟩ => fun hq : ¬p ∣ d ↦
if hnz : n = 0 then by
have : (⟨n, d, hn, hd⟩ : ℚ) = 0 := Rat.zero_iff_num_zero.mpr hnz
norm_num [this]
else by
have hnz' : (⟨n, d, hn, hd⟩ : ℚ) ≠ 0 := mt Rat.zero_iff_num_zero.1 hnz
rw [padicNormE.eq_padicNorm]
norm_cast
-- Porting note: `Nat.cast_zero` instead of another `norm_cast` call
rw [padicNorm.eq_zpow_of_nonzero hnz', padicValRat, neg_sub,
padicValNat.eq_zero_of_not_dvd hq, Nat.cast_zero, zero_sub, zpow_neg, zpow_natCast]
apply inv_le_one_of_one_le₀
norm_cast
apply one_le_pow
exact hp.1.pos
| Mathlib/NumberTheory/Padics/PadicNumbers.lean | 837 | 841 | theorem norm_int_le_one (z : ℤ) : ‖(z : ℚ_[p])‖ ≤ 1 :=
suffices ‖((z : ℚ) : ℚ_[p])‖ ≤ 1 by simpa
norm_rat_le_one <| by simp [hp.1.ne_one]
theorem norm_int_lt_one_iff_dvd (k : ℤ) : ‖(k : ℚ_[p])‖ < 1 ↔ ↑p ∣ k := by | |
/-
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.Algebra.BigOperators.Option
import Mathlib.Analysis.BoxIntegral.Box.Basic
import Mathlib.Data.Set.Pairwise.Lattice
/-!
# Partitions of rectangular boxes in `ℝⁿ`
In this file we define (pre)partitions of rectangular boxes in `ℝⁿ`. A partition of a box `I` in
`ℝⁿ` (see `BoxIntegral.Prepartition` and `BoxIntegral.Prepartition.IsPartition`) is a finite set
of pairwise disjoint boxes such that their union is exactly `I`. We use `boxes : Finset (Box ι)` to
store the set of boxes.
Many lemmas about box integrals deal with pairwise disjoint collections of subboxes, so we define a
structure `BoxIntegral.Prepartition (I : BoxIntegral.Box ι)` that stores a collection of boxes
such that
* each box `J ∈ boxes` is a subbox of `I`;
* the boxes are pairwise disjoint as sets in `ℝⁿ`.
Then we define a predicate `BoxIntegral.Prepartition.IsPartition`; `π.IsPartition` means that the
boxes of `π` actually cover the whole `I`. We also define some operations on prepartitions:
* `BoxIntegral.Prepartition.biUnion`: split each box of a partition into smaller boxes;
* `BoxIntegral.Prepartition.restrict`: restrict a partition to a smaller box.
We also define a `SemilatticeInf` structure on `BoxIntegral.Prepartition I` for all
`I : BoxIntegral.Box ι`.
## Tags
rectangular box, partition
-/
open Set Finset Function
open scoped NNReal
noncomputable section
namespace BoxIntegral
variable {ι : Type*}
/-- A prepartition of `I : BoxIntegral.Box ι` is a finite set of pairwise disjoint subboxes of
`I`. -/
structure Prepartition (I : Box ι) where
/-- The underlying set of boxes -/
boxes : Finset (Box ι)
/-- Each box is a sub-box of `I` -/
le_of_mem' : ∀ J ∈ boxes, J ≤ I
/-- The boxes in a prepartition are pairwise disjoint. -/
pairwiseDisjoint : Set.Pairwise (↑boxes) (Disjoint on ((↑) : Box ι → Set (ι → ℝ)))
namespace Prepartition
variable {I J J₁ J₂ : Box ι} (π : Prepartition I) {π₁ π₂ : Prepartition I} {x : ι → ℝ}
instance : Membership (Box ι) (Prepartition I) :=
⟨fun π J => J ∈ π.boxes⟩
@[simp]
theorem mem_boxes : J ∈ π.boxes ↔ J ∈ π := Iff.rfl
@[simp]
theorem mem_mk {s h₁ h₂} : J ∈ (mk s h₁ h₂ : Prepartition I) ↔ J ∈ s := Iff.rfl
theorem disjoint_coe_of_mem (h₁ : J₁ ∈ π) (h₂ : J₂ ∈ π) (h : J₁ ≠ J₂) :
Disjoint (J₁ : Set (ι → ℝ)) J₂ :=
π.pairwiseDisjoint h₁ h₂ h
theorem eq_of_mem_of_mem (h₁ : J₁ ∈ π) (h₂ : J₂ ∈ π) (hx₁ : x ∈ J₁) (hx₂ : x ∈ J₂) : J₁ = J₂ :=
by_contra fun H => (π.disjoint_coe_of_mem h₁ h₂ H).le_bot ⟨hx₁, hx₂⟩
theorem eq_of_le_of_le (h₁ : J₁ ∈ π) (h₂ : J₂ ∈ π) (hle₁ : J ≤ J₁) (hle₂ : J ≤ J₂) : J₁ = J₂ :=
π.eq_of_mem_of_mem h₁ h₂ (hle₁ J.upper_mem) (hle₂ J.upper_mem)
theorem eq_of_le (h₁ : J₁ ∈ π) (h₂ : J₂ ∈ π) (hle : J₁ ≤ J₂) : J₁ = J₂ :=
π.eq_of_le_of_le h₁ h₂ le_rfl hle
theorem le_of_mem (hJ : J ∈ π) : J ≤ I :=
π.le_of_mem' J hJ
theorem lower_le_lower (hJ : J ∈ π) : I.lower ≤ J.lower :=
Box.antitone_lower (π.le_of_mem hJ)
theorem upper_le_upper (hJ : J ∈ π) : J.upper ≤ I.upper :=
Box.monotone_upper (π.le_of_mem hJ)
theorem injective_boxes : Function.Injective (boxes : Prepartition I → Finset (Box ι)) := by
rintro ⟨s₁, h₁, h₁'⟩ ⟨s₂, h₂, h₂'⟩ (rfl : s₁ = s₂)
rfl
@[ext]
theorem ext (h : ∀ J, J ∈ π₁ ↔ J ∈ π₂) : π₁ = π₂ :=
injective_boxes <| Finset.ext h
/-- The singleton prepartition `{J}`, `J ≤ I`. -/
@[simps]
def single (I J : Box ι) (h : J ≤ I) : Prepartition I :=
⟨{J}, by simpa, by simp⟩
@[simp]
theorem mem_single {J'} (h : J ≤ I) : J' ∈ single I J h ↔ J' = J :=
mem_singleton
/-- We say that `π ≤ π'` if each box of `π` is a subbox of some box of `π'`. -/
instance : LE (Prepartition I) :=
⟨fun π π' => ∀ ⦃I⦄, I ∈ π → ∃ I' ∈ π', I ≤ I'⟩
instance partialOrder : PartialOrder (Prepartition I) where
le := (· ≤ ·)
le_refl _ I hI := ⟨I, hI, le_rfl⟩
le_trans _ _ _ h₁₂ h₂₃ _ hI₁ :=
let ⟨_, hI₂, hI₁₂⟩ := h₁₂ hI₁
let ⟨I₃, hI₃, hI₂₃⟩ := h₂₃ hI₂
⟨I₃, hI₃, hI₁₂.trans hI₂₃⟩
le_antisymm := by
suffices ∀ {π₁ π₂ : Prepartition I}, π₁ ≤ π₂ → π₂ ≤ π₁ → π₁.boxes ⊆ π₂.boxes from
fun π₁ π₂ h₁ h₂ => injective_boxes (Subset.antisymm (this h₁ h₂) (this h₂ h₁))
intro π₁ π₂ h₁ h₂ J hJ
rcases h₁ hJ with ⟨J', hJ', hle⟩; rcases h₂ hJ' with ⟨J'', hJ'', hle'⟩
obtain rfl : J = J'' := π₁.eq_of_le hJ hJ'' (hle.trans hle')
obtain rfl : J' = J := le_antisymm ‹_› ‹_›
assumption
instance : OrderTop (Prepartition I) where
top := single I I le_rfl
le_top π _ hJ := ⟨I, by simp, π.le_of_mem hJ⟩
instance : OrderBot (Prepartition I) where
bot := ⟨∅,
fun _ hJ => (Finset.not_mem_empty _ hJ).elim,
fun _ hJ => (Set.not_mem_empty _ <| Finset.coe_empty ▸ hJ).elim⟩
bot_le _ _ hJ := (Finset.not_mem_empty _ hJ).elim
instance : Inhabited (Prepartition I) := ⟨⊤⟩
theorem le_def : π₁ ≤ π₂ ↔ ∀ J ∈ π₁, ∃ J' ∈ π₂, J ≤ J' := Iff.rfl
@[simp]
theorem mem_top : J ∈ (⊤ : Prepartition I) ↔ J = I :=
mem_singleton
@[simp]
theorem top_boxes : (⊤ : Prepartition I).boxes = {I} := rfl
@[simp]
theorem not_mem_bot : J ∉ (⊥ : Prepartition I) :=
Finset.not_mem_empty _
@[simp]
theorem bot_boxes : (⊥ : Prepartition I).boxes = ∅ := rfl
/-- An auxiliary lemma used to prove that the same point can't belong to more than
`2 ^ Fintype.card ι` closed boxes of a prepartition. -/
theorem injOn_setOf_mem_Icc_setOf_lower_eq (x : ι → ℝ) :
InjOn (fun J : Box ι => { i | J.lower i = x i }) { J | J ∈ π ∧ x ∈ Box.Icc J } := by
rintro J₁ ⟨h₁, hx₁⟩ J₂ ⟨h₂, hx₂⟩ (H : { i | J₁.lower i = x i } = { i | J₂.lower i = x i })
suffices ∀ i, (Ioc (J₁.lower i) (J₁.upper i) ∩ Ioc (J₂.lower i) (J₂.upper i)).Nonempty by
choose y hy₁ hy₂ using this
exact π.eq_of_mem_of_mem h₁ h₂ hy₁ hy₂
intro i
simp only [Set.ext_iff, mem_setOf] at H
rcases (hx₁.1 i).eq_or_lt with hi₁ | hi₁
· have hi₂ : J₂.lower i = x i := (H _).1 hi₁
have H₁ : x i < J₁.upper i := by simpa only [hi₁] using J₁.lower_lt_upper i
have H₂ : x i < J₂.upper i := by simpa only [hi₂] using J₂.lower_lt_upper i
rw [Set.Ioc_inter_Ioc, hi₁, hi₂, sup_idem, Set.nonempty_Ioc]
exact lt_min H₁ H₂
· have hi₂ : J₂.lower i < x i := (hx₂.1 i).lt_of_ne (mt (H _).2 hi₁.ne)
exact ⟨x i, ⟨hi₁, hx₁.2 i⟩, ⟨hi₂, hx₂.2 i⟩⟩
open scoped Classical in
/-- The set of boxes of a prepartition that contain `x` in their closures has cardinality
at most `2 ^ Fintype.card ι`. -/
theorem card_filter_mem_Icc_le [Fintype ι] (x : ι → ℝ) :
#{J ∈ π.boxes | x ∈ Box.Icc J} ≤ 2 ^ Fintype.card ι := by
rw [← Fintype.card_set]
refine Finset.card_le_card_of_injOn (fun J : Box ι => { i | J.lower i = x i })
(fun _ _ => Finset.mem_univ _) ?_
simpa using π.injOn_setOf_mem_Icc_setOf_lower_eq x
/-- Given a prepartition `π : BoxIntegral.Prepartition I`, `π.iUnion` is the part of `I` covered by
the boxes of `π`. -/
protected def iUnion : Set (ι → ℝ) :=
⋃ J ∈ π, ↑J
theorem iUnion_def : π.iUnion = ⋃ J ∈ π, ↑J := rfl
theorem iUnion_def' : π.iUnion = ⋃ J ∈ π.boxes, ↑J := rfl
-- Porting note: Previous proof was `:= Set.mem_iUnion₂`
@[simp]
theorem mem_iUnion : x ∈ π.iUnion ↔ ∃ J ∈ π, x ∈ J := by
convert Set.mem_iUnion₂
rw [Box.mem_coe, exists_prop]
@[simp]
theorem iUnion_single (h : J ≤ I) : (single I J h).iUnion = J := by simp [iUnion_def]
@[simp]
theorem iUnion_top : (⊤ : Prepartition I).iUnion = I := by simp [Prepartition.iUnion]
@[simp]
theorem iUnion_eq_empty : π₁.iUnion = ∅ ↔ π₁ = ⊥ := by
simp [← injective_boxes.eq_iff, Finset.ext_iff, Prepartition.iUnion, imp_false]
@[simp]
theorem iUnion_bot : (⊥ : Prepartition I).iUnion = ∅ :=
iUnion_eq_empty.2 rfl
theorem subset_iUnion (h : J ∈ π) : ↑J ⊆ π.iUnion :=
subset_biUnion_of_mem h
theorem iUnion_subset : π.iUnion ⊆ I :=
iUnion₂_subset π.le_of_mem'
@[mono]
theorem iUnion_mono (h : π₁ ≤ π₂) : π₁.iUnion ⊆ π₂.iUnion := fun _ hx =>
let ⟨_, hJ₁, hx⟩ := π₁.mem_iUnion.1 hx
let ⟨J₂, hJ₂, hle⟩ := h hJ₁
π₂.mem_iUnion.2 ⟨J₂, hJ₂, hle hx⟩
theorem disjoint_boxes_of_disjoint_iUnion (h : Disjoint π₁.iUnion π₂.iUnion) :
Disjoint π₁.boxes π₂.boxes :=
Finset.disjoint_left.2 fun J h₁ h₂ =>
Disjoint.le_bot (h.mono (π₁.subset_iUnion h₁) (π₂.subset_iUnion h₂)) ⟨J.upper_mem, J.upper_mem⟩
theorem le_iff_nonempty_imp_le_and_iUnion_subset :
π₁ ≤ π₂ ↔
(∀ J ∈ π₁, ∀ J' ∈ π₂, (J ∩ J' : Set (ι → ℝ)).Nonempty → J ≤ J') ∧ π₁.iUnion ⊆ π₂.iUnion := by
constructor
· refine fun H => ⟨fun J hJ J' hJ' Hne => ?_, iUnion_mono H⟩
rcases H hJ with ⟨J'', hJ'', Hle⟩
rcases Hne with ⟨x, hx, hx'⟩
rwa [π₂.eq_of_mem_of_mem hJ' hJ'' hx' (Hle hx)]
· rintro ⟨H, HU⟩ J hJ
simp only [Set.subset_def, mem_iUnion] at HU
rcases HU J.upper ⟨J, hJ, J.upper_mem⟩ with ⟨J₂, hJ₂, hx⟩
exact ⟨J₂, hJ₂, H _ hJ _ hJ₂ ⟨_, J.upper_mem, hx⟩⟩
theorem eq_of_boxes_subset_iUnion_superset (h₁ : π₁.boxes ⊆ π₂.boxes) (h₂ : π₂.iUnion ⊆ π₁.iUnion) :
π₁ = π₂ :=
le_antisymm (fun J hJ => ⟨J, h₁ hJ, le_rfl⟩) <|
le_iff_nonempty_imp_le_and_iUnion_subset.2
⟨fun _ hJ₁ _ hJ₂ Hne =>
(π₂.eq_of_mem_of_mem hJ₁ (h₁ hJ₂) Hne.choose_spec.1 Hne.choose_spec.2).le, h₂⟩
open scoped Classical in
/-- Given a prepartition `π` of a box `I` and a collection of prepartitions `πi J` of all boxes
`J ∈ π`, returns the prepartition of `I` into the union of the boxes of all `πi J`.
Though we only use the values of `πi` on the boxes of `π`, we require `πi` to be a globally defined
function. -/
@[simps]
def biUnion (πi : ∀ J : Box ι, Prepartition J) : Prepartition I where
boxes := π.boxes.biUnion fun J => (πi J).boxes
le_of_mem' J hJ := by
simp only [Finset.mem_biUnion, exists_prop, mem_boxes] at hJ
rcases hJ with ⟨J', hJ', hJ⟩
exact ((πi J').le_of_mem hJ).trans (π.le_of_mem hJ')
pairwiseDisjoint := by
simp only [Set.Pairwise, Finset.mem_coe, Finset.mem_biUnion]
rintro J₁' ⟨J₁, hJ₁, hJ₁'⟩ J₂' ⟨J₂, hJ₂, hJ₂'⟩ Hne
rw [Function.onFun, Set.disjoint_left]
rintro x hx₁ hx₂; apply Hne
obtain rfl : J₁ = J₂ :=
π.eq_of_mem_of_mem hJ₁ hJ₂ ((πi J₁).le_of_mem hJ₁' hx₁) ((πi J₂).le_of_mem hJ₂' hx₂)
exact (πi J₁).eq_of_mem_of_mem hJ₁' hJ₂' hx₁ hx₂
variable {πi πi₁ πi₂ : ∀ J : Box ι, Prepartition J}
@[simp]
theorem mem_biUnion : J ∈ π.biUnion πi ↔ ∃ J' ∈ π, J ∈ πi J' := by simp [biUnion]
theorem biUnion_le (πi : ∀ J, Prepartition J) : π.biUnion πi ≤ π := fun _ hJ =>
let ⟨J', hJ', hJ⟩ := π.mem_biUnion.1 hJ
⟨J', hJ', (πi J').le_of_mem hJ⟩
@[simp]
theorem biUnion_top : (π.biUnion fun _ => ⊤) = π := by
ext
simp
@[congr]
theorem biUnion_congr (h : π₁ = π₂) (hi : ∀ J ∈ π₁, πi₁ J = πi₂ J) :
π₁.biUnion πi₁ = π₂.biUnion πi₂ := by
subst π₂
ext J
simp only [mem_biUnion]
constructor <;> exact fun ⟨J', h₁, h₂⟩ => ⟨J', h₁, hi J' h₁ ▸ h₂⟩
theorem biUnion_congr_of_le (h : π₁ = π₂) (hi : ∀ J ≤ I, πi₁ J = πi₂ J) :
π₁.biUnion πi₁ = π₂.biUnion πi₂ :=
biUnion_congr h fun J hJ => hi J (π₁.le_of_mem hJ)
@[simp]
theorem iUnion_biUnion (πi : ∀ J : Box ι, Prepartition J) :
(π.biUnion πi).iUnion = ⋃ J ∈ π, (πi J).iUnion := by simp [Prepartition.iUnion]
open scoped Classical in
@[simp]
theorem sum_biUnion_boxes {M : Type*} [AddCommMonoid M] (π : Prepartition I)
(πi : ∀ J, Prepartition J) (f : Box ι → M) :
(∑ J ∈ π.boxes.biUnion fun J => (πi J).boxes, f J) =
∑ J ∈ π.boxes, ∑ J' ∈ (πi J).boxes, f J' := by
refine Finset.sum_biUnion fun J₁ h₁ J₂ h₂ hne => Finset.disjoint_left.2 fun J' h₁' h₂' => ?_
exact hne (π.eq_of_le_of_le h₁ h₂ ((πi J₁).le_of_mem h₁') ((πi J₂).le_of_mem h₂'))
open scoped Classical in
/-- Given a box `J ∈ π.biUnion πi`, returns the box `J' ∈ π` such that `J ∈ πi J'`.
For `J ∉ π.biUnion πi`, returns `I`. -/
def biUnionIndex (πi : ∀ (J : Box ι), Prepartition J) (J : Box ι) : Box ι :=
if hJ : J ∈ π.biUnion πi then (π.mem_biUnion.1 hJ).choose else I
theorem biUnionIndex_mem (hJ : J ∈ π.biUnion πi) : π.biUnionIndex πi J ∈ π := by
rw [biUnionIndex, dif_pos hJ]
exact (π.mem_biUnion.1 hJ).choose_spec.1
theorem biUnionIndex_le (πi : ∀ J, Prepartition J) (J : Box ι) : π.biUnionIndex πi J ≤ I := by
by_cases hJ : J ∈ π.biUnion πi
· exact π.le_of_mem (π.biUnionIndex_mem hJ)
· rw [biUnionIndex, dif_neg hJ]
theorem mem_biUnionIndex (hJ : J ∈ π.biUnion πi) : J ∈ πi (π.biUnionIndex πi J) := by
convert (π.mem_biUnion.1 hJ).choose_spec.2 <;> exact dif_pos hJ
theorem le_biUnionIndex (hJ : J ∈ π.biUnion πi) : J ≤ π.biUnionIndex πi J :=
le_of_mem _ (π.mem_biUnionIndex hJ)
/-- Uniqueness property of `BoxIntegral.Prepartition.biUnionIndex`. -/
theorem biUnionIndex_of_mem (hJ : J ∈ π) {J'} (hJ' : J' ∈ πi J) : π.biUnionIndex πi J' = J :=
have : J' ∈ π.biUnion πi := π.mem_biUnion.2 ⟨J, hJ, hJ'⟩
π.eq_of_le_of_le (π.biUnionIndex_mem this) hJ (π.le_biUnionIndex this) (le_of_mem _ hJ')
theorem biUnion_assoc (πi : ∀ J, Prepartition J) (πi' : Box ι → ∀ J : Box ι, Prepartition J) :
(π.biUnion fun J => (πi J).biUnion (πi' J)) =
(π.biUnion πi).biUnion fun J => πi' (π.biUnionIndex πi J) J := by
ext J
simp only [mem_biUnion, exists_prop]
constructor
· rintro ⟨J₁, hJ₁, J₂, hJ₂, hJ⟩
refine ⟨J₂, ⟨J₁, hJ₁, hJ₂⟩, ?_⟩
rwa [π.biUnionIndex_of_mem hJ₁ hJ₂]
· rintro ⟨J₁, ⟨J₂, hJ₂, hJ₁⟩, hJ⟩
refine ⟨J₂, hJ₂, J₁, hJ₁, ?_⟩
rwa [π.biUnionIndex_of_mem hJ₂ hJ₁] at hJ
/-- Create a `BoxIntegral.Prepartition` from a collection of possibly empty boxes by filtering out
the empty one if it exists. -/
def ofWithBot (boxes : Finset (WithBot (Box ι)))
(le_of_mem : ∀ J ∈ boxes, (J : WithBot (Box ι)) ≤ I)
(pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ι))) Disjoint) :
Prepartition I where
boxes := Finset.eraseNone boxes
le_of_mem' J hJ := by
rw [mem_eraseNone] at hJ
simpa only [WithBot.some_eq_coe, WithBot.coe_le_coe] using le_of_mem _ hJ
pairwiseDisjoint J₁ h₁ J₂ h₂ hne := by
simp only [mem_coe, mem_eraseNone] at h₁ h₂
exact Box.disjoint_coe.1 (pairwise_disjoint h₁ h₂ (mt Option.some_inj.1 hne))
@[simp]
theorem mem_ofWithBot {boxes : Finset (WithBot (Box ι))} {h₁ h₂} :
J ∈ (ofWithBot boxes h₁ h₂ : Prepartition I) ↔ (J : WithBot (Box ι)) ∈ boxes :=
mem_eraseNone
@[simp]
theorem iUnion_ofWithBot (boxes : Finset (WithBot (Box ι)))
(le_of_mem : ∀ J ∈ boxes, (J : WithBot (Box ι)) ≤ I)
(pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ι))) Disjoint) :
(ofWithBot boxes le_of_mem pairwise_disjoint).iUnion = ⋃ J ∈ boxes, ↑J := by
suffices ⋃ (J : Box ι) (_ : ↑J ∈ boxes), ↑J = ⋃ J ∈ boxes, (J : Set (ι → ℝ)) by
simpa [ofWithBot, Prepartition.iUnion]
simp only [← Box.biUnion_coe_eq_coe, @iUnion_comm _ _ (Box ι), @iUnion_comm _ _ (@Eq _ _ _),
iUnion_iUnion_eq_right]
theorem ofWithBot_le {boxes : Finset (WithBot (Box ι))}
{le_of_mem : ∀ J ∈ boxes, (J : WithBot (Box ι)) ≤ I}
{pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ι))) Disjoint}
(H : ∀ J ∈ boxes, J ≠ ⊥ → ∃ J' ∈ π, J ≤ ↑J') :
ofWithBot boxes le_of_mem pairwise_disjoint ≤ π := by
have : ∀ J : Box ι, ↑J ∈ boxes → ∃ J' ∈ π, J ≤ J' := fun J hJ => by
simpa only [WithBot.coe_le_coe] using H J hJ WithBot.coe_ne_bot
simpa [ofWithBot, le_def]
theorem le_ofWithBot {boxes : Finset (WithBot (Box ι))}
{le_of_mem : ∀ J ∈ boxes, (J : WithBot (Box ι)) ≤ I}
{pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ι))) Disjoint}
(H : ∀ J ∈ π, ∃ J' ∈ boxes, ↑J ≤ J') : π ≤ ofWithBot boxes le_of_mem pairwise_disjoint := by
intro J hJ
rcases H J hJ with ⟨J', J'mem, hle⟩
lift J' to Box ι using ne_bot_of_le_ne_bot WithBot.coe_ne_bot hle
exact ⟨J', mem_ofWithBot.2 J'mem, WithBot.coe_le_coe.1 hle⟩
theorem ofWithBot_mono {boxes₁ : Finset (WithBot (Box ι))}
{le_of_mem₁ : ∀ J ∈ boxes₁, (J : WithBot (Box ι)) ≤ I}
{pairwise_disjoint₁ : Set.Pairwise (boxes₁ : Set (WithBot (Box ι))) Disjoint}
{boxes₂ : Finset (WithBot (Box ι))} {le_of_mem₂ : ∀ J ∈ boxes₂, (J : WithBot (Box ι)) ≤ I}
{pairwise_disjoint₂ : Set.Pairwise (boxes₂ : Set (WithBot (Box ι))) Disjoint}
(H : ∀ J ∈ boxes₁, J ≠ ⊥ → ∃ J' ∈ boxes₂, J ≤ J') :
ofWithBot boxes₁ le_of_mem₁ pairwise_disjoint₁ ≤
ofWithBot boxes₂ le_of_mem₂ pairwise_disjoint₂ :=
le_ofWithBot _ fun J hJ => H J (mem_ofWithBot.1 hJ) WithBot.coe_ne_bot
theorem sum_ofWithBot {M : Type*} [AddCommMonoid M] (boxes : Finset (WithBot (Box ι)))
(le_of_mem : ∀ J ∈ boxes, (J : WithBot (Box ι)) ≤ I)
(pairwise_disjoint : Set.Pairwise (boxes : Set (WithBot (Box ι))) Disjoint) (f : Box ι → M) :
(∑ J ∈ (ofWithBot boxes le_of_mem pairwise_disjoint).boxes, f J) =
∑ J ∈ boxes, Option.elim' 0 f J :=
Finset.sum_eraseNone _ _
open scoped Classical in
/-- Restrict a prepartition to a box. -/
def restrict (π : Prepartition I) (J : Box ι) : Prepartition J :=
ofWithBot (π.boxes.image fun J' : Box ι => J ⊓ J')
(fun J' hJ' => by
rcases Finset.mem_image.1 hJ' with ⟨J', -, rfl⟩
exact inf_le_left)
(by
simp only [Set.Pairwise, onFun, Finset.mem_coe, Finset.mem_image]
rintro _ ⟨J₁, h₁, rfl⟩ _ ⟨J₂, h₂, rfl⟩ Hne
have : J₁ ≠ J₂ := by
rintro rfl
exact Hne rfl
exact ((Box.disjoint_coe.2 <| π.disjoint_coe_of_mem h₁ h₂ this).inf_left' _).inf_right' _)
@[simp]
theorem mem_restrict : J₁ ∈ π.restrict J ↔ ∃ J' ∈ π, (J₁ : WithBot (Box ι)) = ↑J ⊓ ↑J' := by
simp [restrict, eq_comm]
theorem mem_restrict' : J₁ ∈ π.restrict J ↔ ∃ J' ∈ π, (J₁ : Set (ι → ℝ)) = ↑J ∩ ↑J' := by
simp only [mem_restrict, ← Box.withBotCoe_inj, Box.coe_inf, Box.coe_coe]
@[mono]
theorem restrict_mono {π₁ π₂ : Prepartition I} (Hle : π₁ ≤ π₂) : π₁.restrict J ≤ π₂.restrict J := by
classical
refine ofWithBot_mono fun J₁ hJ₁ hne => ?_
rw [Finset.mem_image] at hJ₁; rcases hJ₁ with ⟨J₁, hJ₁, rfl⟩
rcases Hle hJ₁ with ⟨J₂, hJ₂, hle⟩
exact ⟨_, Finset.mem_image_of_mem _ hJ₂, inf_le_inf_left _ <| WithBot.coe_le_coe.2 hle⟩
theorem monotone_restrict : Monotone fun π : Prepartition I => restrict π J :=
fun _ _ => restrict_mono
/-- Restricting to a larger box does not change the set of boxes. We cannot claim equality
of prepartitions because they have different types. -/
theorem restrict_boxes_of_le (π : Prepartition I) (h : I ≤ J) : (π.restrict J).boxes = π.boxes := by
classical
simp only [restrict, ofWithBot, eraseNone_eq_biUnion]
refine Finset.image_biUnion.trans ?_
refine (Finset.biUnion_congr rfl ?_).trans Finset.biUnion_singleton_eq_self
intro J' hJ'
rw [inf_of_le_right, ← WithBot.some_eq_coe, Option.toFinset_some]
exact WithBot.coe_le_coe.2 ((π.le_of_mem hJ').trans h)
@[simp]
theorem restrict_self : π.restrict I = π :=
injective_boxes <| restrict_boxes_of_le π le_rfl
@[simp]
theorem iUnion_restrict : (π.restrict J).iUnion = (J : Set (ι → ℝ)) ∩ (π.iUnion) := by
simp [restrict, ← inter_iUnion, ← iUnion_def]
@[simp]
theorem restrict_biUnion (πi : ∀ J, Prepartition J) (hJ : J ∈ π) :
(π.biUnion πi).restrict J = πi J := by
refine (eq_of_boxes_subset_iUnion_superset (fun J₁ h₁ => ?_) ?_).symm
· refine (mem_restrict _).2 ⟨J₁, π.mem_biUnion.2 ⟨J, hJ, h₁⟩, (inf_of_le_right ?_).symm⟩
exact WithBot.coe_le_coe.2 (le_of_mem _ h₁)
· simp only [iUnion_restrict, iUnion_biUnion, Set.subset_def, Set.mem_inter_iff, Set.mem_iUnion]
rintro x ⟨hxJ, J₁, h₁, hx⟩
obtain rfl : J = J₁ := π.eq_of_mem_of_mem hJ h₁ hxJ (iUnion_subset _ hx)
exact hx
theorem biUnion_le_iff {πi : ∀ J, Prepartition J} {π' : Prepartition I} :
π.biUnion πi ≤ π' ↔ ∀ J ∈ π, πi J ≤ π'.restrict J := by
constructor <;> intro H J hJ
· rw [← π.restrict_biUnion πi hJ]
exact restrict_mono H
· rw [mem_biUnion] at hJ
rcases hJ with ⟨J₁, h₁, hJ⟩
rcases H J₁ h₁ hJ with ⟨J₂, h₂, Hle⟩
rcases π'.mem_restrict.mp h₂ with ⟨J₃, h₃, H⟩
exact ⟨J₃, h₃, Hle.trans <| WithBot.coe_le_coe.1 <| H.trans_le inf_le_right⟩
| Mathlib/Analysis/BoxIntegral/Partition/Basic.lean | 491 | 492 | theorem le_biUnion_iff {πi : ∀ J, Prepartition J} {π' : Prepartition I} :
π' ≤ π.biUnion πi ↔ π' ≤ π ∧ ∀ J ∈ π, π'.restrict J ≤ πi J := by | |
/-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Robert Y. Lewis
-/
import Mathlib.Algebra.MvPolynomial.Monad
/-!
## Expand multivariate polynomials
Given a multivariate polynomial `φ`, one may replace every occurrence of `X i` by `X i ^ n`,
for some natural number `n`.
This operation is called `MvPolynomial.expand` and it is an algebra homomorphism.
### Main declaration
* `MvPolynomial.expand`: expand a polynomial by a factor of p, so `∑ aₙ xⁿ` becomes `∑ aₙ xⁿᵖ`.
-/
namespace MvPolynomial
variable {σ τ R S : Type*} [CommSemiring R] [CommSemiring S]
/-- Expand the polynomial by a factor of p, so `∑ aₙ xⁿ` becomes `∑ aₙ xⁿᵖ`.
See also `Polynomial.expand`. -/
noncomputable def expand (p : ℕ) : MvPolynomial σ R →ₐ[R] MvPolynomial σ R :=
{ (eval₂Hom C fun i ↦ X i ^ p : MvPolynomial σ R →+* MvPolynomial σ R) with
commutes' := fun _ ↦ eval₂Hom_C _ _ _ }
theorem expand_C (p : ℕ) (r : R) : expand p (C r : MvPolynomial σ R) = C r :=
eval₂Hom_C _ _ _
@[simp]
theorem expand_X (p : ℕ) (i : σ) : expand p (X i : MvPolynomial σ R) = X i ^ p :=
eval₂Hom_X' _ _ _
@[simp]
theorem expand_monomial (p : ℕ) (d : σ →₀ ℕ) (r : R) :
expand p (monomial d r) = C r * ∏ i ∈ d.support, (X i ^ p) ^ d i :=
bind₁_monomial _ _ _
theorem expand_one_apply (f : MvPolynomial σ R) : expand 1 f = f := by
simp only [expand, pow_one, eval₂Hom_eq_bind₂, bind₂_C_left, RingHom.toMonoidHom_eq_coe,
RingHom.coe_monoidHom_id, AlgHom.coe_mk, RingHom.coe_mk, MonoidHom.id_apply, RingHom.id_apply]
@[simp]
theorem expand_one : expand 1 = AlgHom.id R (MvPolynomial σ R) := by
ext1 f
rw [expand_one_apply, AlgHom.id_apply]
| Mathlib/Algebra/MvPolynomial/Expand.lean | 53 | 55 | theorem expand_comp_bind₁ (p : ℕ) (f : σ → MvPolynomial τ R) :
(expand p).comp (bind₁ f) = bind₁ fun i ↦ expand p (f i) := by | apply algHom_ext |
/-
Copyright (c) 2021 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Data.Matrix.Basis
import Mathlib.Data.Matrix.DMatrix
import Mathlib.LinearAlgebra.Matrix.Determinant.Basic
import Mathlib.LinearAlgebra.Matrix.Reindex
import Mathlib.Tactic.FieldSimp
/-!
# Transvections
Transvections are matrices of the form `1 + stdBasisMatrix i j c`, where `stdBasisMatrix i j c`
is the basic matrix with a `c` at position `(i, j)`. Multiplying by such a transvection on the left
(resp. on the right) amounts to adding `c` times the `j`-th row to the `i`-th row
(resp `c` times the `i`-th column to the `j`-th column). Therefore, they are useful to present
algorithms operating on rows and columns.
Transvections are a special case of *elementary matrices* (according to most references, these also
contain the matrices exchanging rows, and the matrices multiplying a row by a constant).
We show that, over a field, any matrix can be written as `L * D * L'`, where `L` and `L'` are
products of transvections and `D` is diagonal. In other words, one can reduce a matrix to diagonal
form by operations on its rows and columns, a variant of Gauss' pivot algorithm.
## Main definitions and results
* `transvection i j c` is the matrix equal to `1 + stdBasisMatrix i j c`.
* `TransvectionStruct n R` is a structure containing the data of `i, j, c` and a proof that
`i ≠ j`. These are often easier to manipulate than straight matrices, especially in inductive
arguments.
* `exists_list_transvec_mul_diagonal_mul_list_transvec` states that any matrix `M` over a field can
be written in the form `t_1 * ... * t_k * D * t'_1 * ... * t'_l`, where `D` is diagonal and
the `t_i`, `t'_j` are transvections.
* `diagonal_transvection_induction` shows that a property which is true for diagonal matrices and
transvections, and invariant under product, is true for all matrices.
* `diagonal_transvection_induction_of_det_ne_zero` is the same statement over invertible matrices.
## Implementation details
The proof of the reduction results is done inductively on the size of the matrices, reducing an
`(r + 1) × (r + 1)` matrix to a matrix whose last row and column are zeroes, except possibly for
the last diagonal entry. This step is done as follows.
If all the coefficients on the last row and column are zero, there is nothing to do. Otherwise,
one can put a nonzero coefficient in the last diagonal entry by a row or column operation, and then
subtract this last diagonal entry from the other entries in the last row and column to make them
vanish.
This step is done in the type `Fin r ⊕ Unit`, where `Fin r` is useful to choose arbitrarily some
order in which we cancel the coefficients, and the sum structure is useful to use the formalism of
block matrices.
To proceed with the induction, we reindex our matrices to reduce to the above situation.
-/
universe u₁ u₂
namespace Matrix
variable (n p : Type*) (R : Type u₂) {𝕜 : Type*} [Field 𝕜]
variable [DecidableEq n] [DecidableEq p]
variable [CommRing R]
section Transvection
variable {R n} (i j : n)
/-- The transvection matrix `transvection i j c` is equal to the identity plus `c` at position
`(i, j)`. Multiplying by it on the left (as in `transvection i j c * M`) corresponds to adding
`c` times the `j`-th row of `M` to its `i`-th row. Multiplying by it on the right corresponds
to adding `c` times the `i`-th column to the `j`-th column. -/
def transvection (c : R) : Matrix n n R :=
1 + Matrix.stdBasisMatrix i j c
@[simp]
theorem transvection_zero : transvection i j (0 : R) = 1 := by simp [transvection]
section
/-- A transvection matrix is obtained from the identity by adding `c` times the `j`-th row to
the `i`-th row. -/
theorem updateRow_eq_transvection [Finite n] (c : R) :
updateRow (1 : Matrix n n R) i ((1 : Matrix n n R) i + c • (1 : Matrix n n R) j) =
transvection i j c := by
cases nonempty_fintype n
ext a b
by_cases ha : i = a
· by_cases hb : j = b
· simp only [ha, updateRow_self, Pi.add_apply, one_apply, Pi.smul_apply, hb, ↓reduceIte,
smul_eq_mul, mul_one, transvection, add_apply, StdBasisMatrix.apply_same]
· simp only [ha, updateRow_self, Pi.add_apply, one_apply, Pi.smul_apply, hb, ↓reduceIte,
smul_eq_mul, mul_zero, add_zero, transvection, add_apply, and_false, not_false_eq_true,
StdBasisMatrix.apply_of_ne]
· simp only [updateRow_ne, transvection, ha, Ne.symm ha, StdBasisMatrix.apply_of_ne, add_zero,
Algebra.id.smul_eq_mul, Ne, not_false_iff, DMatrix.add_apply, Pi.smul_apply,
mul_zero, false_and, add_apply]
variable [Fintype n]
theorem transvection_mul_transvection_same (h : i ≠ j) (c d : R) :
transvection i j c * transvection i j d = transvection i j (c + d) := by
simp [transvection, Matrix.add_mul, Matrix.mul_add, h, h.symm, add_smul, add_assoc,
stdBasisMatrix_add]
@[simp]
theorem transvection_mul_apply_same (b : n) (c : R) (M : Matrix n n R) :
(transvection i j c * M) i b = M i b + c * M j b := by simp [transvection, Matrix.add_mul]
@[simp]
theorem mul_transvection_apply_same (a : n) (c : R) (M : Matrix n n R) :
(M * transvection i j c) a j = M a j + c * M a i := by
simp [transvection, Matrix.mul_add, mul_comm]
@[simp]
theorem transvection_mul_apply_of_ne (a b : n) (ha : a ≠ i) (c : R) (M : Matrix n n R) :
(transvection i j c * M) a b = M a b := by simp [transvection, Matrix.add_mul, ha]
@[simp]
| Mathlib/LinearAlgebra/Matrix/Transvection.lean | 125 | 127 | theorem mul_transvection_apply_of_ne (a b : n) (hb : b ≠ j) (c : R) (M : Matrix n n R) :
(M * transvection i j c) a b = M a b := by | simp [transvection, Matrix.mul_add, hb] |
/-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Jeremy Avigad, Minchao Wu, Mario Carneiro
-/
import Mathlib.Algebra.NeZero
import Mathlib.Data.Finset.Attach
import Mathlib.Data.Finset.Disjoint
import Mathlib.Data.Finset.Erase
import Mathlib.Data.Finset.Filter
import Mathlib.Data.Finset.Range
import Mathlib.Data.Finset.SDiff
/-! # Image and map operations on finite sets
This file provides the finite analog of `Set.image`, along with some other similar functions.
Note there are two ways to take the image over a finset; via `Finset.image` which applies the
function then removes duplicates (requiring `DecidableEq`), or via `Finset.map` which exploits
injectivity of the function to avoid needing to deduplicate. Choosing between these is similar to
choosing between `insert` and `Finset.cons`, or between `Finset.union` and `Finset.disjUnion`.
## Main definitions
* `Finset.image`: Given a function `f : α → β`, `s.image f` is the image finset in `β`.
* `Finset.map`: Given an embedding `f : α ↪ β`, `s.map f` is the image finset in `β`.
* `Finset.filterMap` Given a function `f : α → Option β`, `s.filterMap f` is the
image finset in `β`, filtering out `none`s.
* `Finset.subtype`: `s.subtype p` is the finset of `Subtype p` whose elements belong to `s`.
* `Finset.fin`:`s.fin n` is the finset of all elements of `s` less than `n`.
-/
assert_not_exists Monoid OrderedCommMonoid
variable {α β γ : Type*}
open Multiset
open Function
namespace Finset
/-! ### map -/
section Map
open Function
/-- When `f` is an embedding of `α` in `β` and `s` is a finset in `α`, then `s.map f` is the image
finset in `β`. The embedding condition guarantees that there are no duplicates in the image. -/
def map (f : α ↪ β) (s : Finset α) : Finset β :=
⟨s.1.map f, s.2.map f.2⟩
@[simp]
theorem map_val (f : α ↪ β) (s : Finset α) : (map f s).1 = s.1.map f :=
rfl
@[simp]
theorem map_empty (f : α ↪ β) : (∅ : Finset α).map f = ∅ :=
rfl
variable {f : α ↪ β} {s : Finset α}
@[simp]
theorem mem_map {b : β} : b ∈ s.map f ↔ ∃ a ∈ s, f a = b :=
Multiset.mem_map
-- Higher priority to apply before `mem_map`.
@[simp 1100]
theorem mem_map_equiv {f : α ≃ β} {b : β} : b ∈ s.map f.toEmbedding ↔ f.symm b ∈ s := by
rw [mem_map]
exact
⟨by
rintro ⟨a, H, rfl⟩
simpa, fun h => ⟨_, h, by simp⟩⟩
@[simp 1100]
theorem mem_map' (f : α ↪ β) {a} {s : Finset α} : f a ∈ s.map f ↔ a ∈ s :=
mem_map_of_injective f.2
theorem mem_map_of_mem (f : α ↪ β) {a} {s : Finset α} : a ∈ s → f a ∈ s.map f :=
(mem_map' _).2
theorem forall_mem_map {f : α ↪ β} {s : Finset α} {p : ∀ a, a ∈ s.map f → Prop} :
(∀ y (H : y ∈ s.map f), p y H) ↔ ∀ x (H : x ∈ s), p (f x) (mem_map_of_mem _ H) :=
⟨fun h y hy => h (f y) (mem_map_of_mem _ hy),
fun h x hx => by
obtain ⟨y, hy, rfl⟩ := mem_map.1 hx
exact h _ hy⟩
theorem apply_coe_mem_map (f : α ↪ β) (s : Finset α) (x : s) : f x ∈ s.map f :=
mem_map_of_mem f x.prop
@[simp, norm_cast]
theorem coe_map (f : α ↪ β) (s : Finset α) : (s.map f : Set β) = f '' s :=
Set.ext (by simp only [mem_coe, mem_map, Set.mem_image, implies_true])
theorem coe_map_subset_range (f : α ↪ β) (s : Finset α) : (s.map f : Set β) ⊆ Set.range f :=
calc
↑(s.map f) = f '' s := coe_map f s
_ ⊆ Set.range f := Set.image_subset_range f ↑s
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
theorem map_perm {σ : Equiv.Perm α} (hs : { a | σ a ≠ a } ⊆ s) : s.map (σ : α ↪ α) = s :=
coe_injective <| (coe_map _ _).trans <| Set.image_perm hs
theorem map_toFinset [DecidableEq α] [DecidableEq β] {s : Multiset α} :
s.toFinset.map f = (s.map f).toFinset :=
ext fun _ => by simp only [mem_map, Multiset.mem_map, exists_prop, Multiset.mem_toFinset]
@[simp]
theorem map_refl : s.map (Embedding.refl _) = s :=
ext fun _ => by simpa only [mem_map, exists_prop] using exists_eq_right
@[simp]
theorem map_cast_heq {α β} (h : α = β) (s : Finset α) :
HEq (s.map (Equiv.cast h).toEmbedding) s := by
subst h
simp
theorem map_map (f : α ↪ β) (g : β ↪ γ) (s : Finset α) : (s.map f).map g = s.map (f.trans g) :=
eq_of_veq <| by simp only [map_val, Multiset.map_map]; rfl
theorem map_comm {β'} {f : β ↪ γ} {g : α ↪ β} {f' : α ↪ β'} {g' : β' ↪ γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) : (s.map g).map f = (s.map f').map g' := by
simp_rw [map_map, Embedding.trans, Function.comp_def, h_comm]
theorem _root_.Function.Semiconj.finset_map {f : α ↪ β} {ga : α ↪ α} {gb : β ↪ β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (map f) (map ga) (map gb) := fun _ =>
map_comm h
theorem _root_.Function.Commute.finset_map {f g : α ↪ α} (h : Function.Commute f g) :
Function.Commute (map f) (map g) :=
Function.Semiconj.finset_map h
@[simp]
theorem map_subset_map {s₁ s₂ : Finset α} : s₁.map f ⊆ s₂.map f ↔ s₁ ⊆ s₂ :=
⟨fun h _ xs => (mem_map' _).1 <| h <| (mem_map' f).2 xs,
fun h => by simp [subset_def, Multiset.map_subset_map h]⟩
@[gcongr] alias ⟨_, _root_.GCongr.finsetMap_subset⟩ := map_subset_map
/-- The `Finset` version of `Equiv.subset_symm_image`. -/
theorem subset_map_symm {t : Finset β} {f : α ≃ β} : s ⊆ t.map f.symm ↔ s.map f ⊆ t := by
constructor <;> intro h x hx
· simp only [mem_map_equiv, Equiv.symm_symm] at hx
simpa using h hx
· simp only [mem_map_equiv]
exact h (by simp [hx])
/-- The `Finset` version of `Equiv.symm_image_subset`. -/
theorem map_symm_subset {t : Finset β} {f : α ≃ β} : t.map f.symm ⊆ s ↔ t ⊆ s.map f := by
simp only [← subset_map_symm, Equiv.symm_symm]
/-- Associate to an embedding `f` from `α` to `β` the order embedding that maps a finset to its
image under `f`. -/
def mapEmbedding (f : α ↪ β) : Finset α ↪o Finset β :=
OrderEmbedding.ofMapLEIff (map f) fun _ _ => map_subset_map
@[simp]
theorem map_inj {s₁ s₂ : Finset α} : s₁.map f = s₂.map f ↔ s₁ = s₂ :=
(mapEmbedding f).injective.eq_iff
theorem map_injective (f : α ↪ β) : Injective (map f) :=
(mapEmbedding f).injective
@[simp]
theorem map_ssubset_map {s t : Finset α} : s.map f ⊂ t.map f ↔ s ⊂ t := (mapEmbedding f).lt_iff_lt
@[gcongr] alias ⟨_, _root_.GCongr.finsetMap_ssubset⟩ := map_ssubset_map
@[simp]
theorem mapEmbedding_apply : mapEmbedding f s = map f s :=
rfl
theorem filter_map {p : β → Prop} [DecidablePred p] :
(s.map f).filter p = (s.filter (p ∘ f)).map f :=
eq_of_veq (Multiset.filter_map _ _ _)
lemma map_filter' (p : α → Prop) [DecidablePred p] (f : α ↪ β) (s : Finset α)
[DecidablePred (∃ a, p a ∧ f a = ·)] :
(s.filter p).map f = (s.map f).filter fun b => ∃ a, p a ∧ f a = b := by
simp [Function.comp_def, filter_map, f.injective.eq_iff]
lemma filter_attach' [DecidableEq α] (s : Finset α) (p : s → Prop) [DecidablePred p] :
s.attach.filter p =
(s.filter fun x => ∃ h, p ⟨x, h⟩).attach.map
⟨Subtype.map id <| filter_subset _ _, Subtype.map_injective _ injective_id⟩ :=
eq_of_veq <| Multiset.filter_attach' _ _
lemma filter_attach (p : α → Prop) [DecidablePred p] (s : Finset α) :
s.attach.filter (fun a : s ↦ p a) =
(s.filter p).attach.map ((Embedding.refl _).subtypeMap mem_of_mem_filter) :=
eq_of_veq <| Multiset.filter_attach _ _
theorem map_filter {f : α ≃ β} {p : α → Prop} [DecidablePred p] :
(s.filter p).map f.toEmbedding = (s.map f.toEmbedding).filter (p ∘ f.symm) := by
simp only [filter_map, Function.comp_def, Equiv.toEmbedding_apply, Equiv.symm_apply_apply]
@[simp]
theorem disjoint_map {s t : Finset α} (f : α ↪ β) :
Disjoint (s.map f) (t.map f) ↔ Disjoint s t :=
mod_cast Set.disjoint_image_iff f.injective (s := s) (t := t)
theorem map_disjUnion {f : α ↪ β} (s₁ s₂ : Finset α) (h) (h' := (disjoint_map _).mpr h) :
(s₁.disjUnion s₂ h).map f = (s₁.map f).disjUnion (s₂.map f) h' :=
eq_of_veq <| Multiset.map_add _ _ _
/-- A version of `Finset.map_disjUnion` for writing in the other direction. -/
theorem map_disjUnion' {f : α ↪ β} (s₁ s₂ : Finset α) (h') (h := (disjoint_map _).mp h') :
(s₁.disjUnion s₂ h).map f = (s₁.map f).disjUnion (s₂.map f) h' :=
map_disjUnion _ _ _
theorem map_union [DecidableEq α] [DecidableEq β] {f : α ↪ β} (s₁ s₂ : Finset α) :
(s₁ ∪ s₂).map f = s₁.map f ∪ s₂.map f :=
mod_cast Set.image_union f s₁ s₂
theorem map_inter [DecidableEq α] [DecidableEq β] {f : α ↪ β} (s₁ s₂ : Finset α) :
(s₁ ∩ s₂).map f = s₁.map f ∩ s₂.map f :=
mod_cast Set.image_inter f.injective (s := s₁) (t := s₂)
@[simp]
theorem map_singleton (f : α ↪ β) (a : α) : map f {a} = {f a} :=
coe_injective <| by simp only [coe_map, coe_singleton, Set.image_singleton]
@[simp]
theorem map_insert [DecidableEq α] [DecidableEq β] (f : α ↪ β) (a : α) (s : Finset α) :
(insert a s).map f = insert (f a) (s.map f) := by
simp only [insert_eq, map_union, map_singleton]
@[simp]
theorem map_cons (f : α ↪ β) (a : α) (s : Finset α) (ha : a ∉ s) :
(cons a s ha).map f = cons (f a) (s.map f) (by simpa using ha) :=
eq_of_veq <| Multiset.map_cons f a s.val
@[simp]
theorem map_eq_empty : s.map f = ∅ ↔ s = ∅ := (map_injective f).eq_iff' (map_empty f)
@[simp]
theorem map_nonempty : (s.map f).Nonempty ↔ s.Nonempty :=
mod_cast Set.image_nonempty (f := f) (s := s)
@[aesop safe apply (rule_sets := [finsetNonempty])]
protected alias ⟨_, Nonempty.map⟩ := map_nonempty
@[simp]
theorem map_nontrivial : (s.map f).Nontrivial ↔ s.Nontrivial :=
mod_cast Set.image_nontrivial f.injective (s := s)
theorem attach_map_val {s : Finset α} : s.attach.map (Embedding.subtype _) = s :=
eq_of_veq <| by rw [map_val, attach_val]; exact Multiset.attach_map_val _
end Map
theorem range_add_one' (n : ℕ) :
range (n + 1) = insert 0 ((range n).map ⟨fun i => i + 1, fun i j => by simp⟩) := by
ext (⟨⟩ | ⟨n⟩) <;> simp [Nat.zero_lt_succ n]
/-! ### image -/
section Image
variable [DecidableEq β]
/-- `image f s` is the forward image of `s` under `f`. -/
def image (f : α → β) (s : Finset α) : Finset β :=
(s.1.map f).toFinset
@[simp]
theorem image_val (f : α → β) (s : Finset α) : (image f s).1 = (s.1.map f).dedup :=
rfl
@[simp]
theorem image_empty (f : α → β) : (∅ : Finset α).image f = ∅ :=
rfl
variable {f g : α → β} {s : Finset α} {t : Finset β} {a : α} {b c : β}
@[simp]
theorem mem_image : b ∈ s.image f ↔ ∃ a ∈ s, f a = b := by
simp only [mem_def, image_val, mem_dedup, Multiset.mem_map, exists_prop]
theorem mem_image_of_mem (f : α → β) {a} (h : a ∈ s) : f a ∈ s.image f :=
mem_image.2 ⟨_, h, rfl⟩
lemma forall_mem_image {p : β → Prop} : (∀ y ∈ s.image f, p y) ↔ ∀ ⦃x⦄, x ∈ s → p (f x) := by simp
lemma exists_mem_image {p : β → Prop} : (∃ y ∈ s.image f, p y) ↔ ∃ x ∈ s, p (f x) := by simp
@[deprecated (since := "2024-11-23")] alias forall_image := forall_mem_image
theorem map_eq_image (f : α ↪ β) (s : Finset α) : s.map f = s.image f :=
eq_of_veq (s.map f).2.dedup.symm
-- Not `@[simp]` since `mem_image` already gets most of the way there.
theorem mem_image_const : c ∈ s.image (const α b) ↔ s.Nonempty ∧ b = c := by
rw [mem_image]
simp only [exists_prop, const_apply, exists_and_right]
rfl
theorem mem_image_const_self : b ∈ s.image (const α b) ↔ s.Nonempty :=
mem_image_const.trans <| and_iff_left rfl
instance canLift (c) (p) [CanLift β α c p] :
CanLift (Finset β) (Finset α) (image c) fun s => ∀ x ∈ s, p x where
prf := by
rintro ⟨⟨l⟩, hd : l.Nodup⟩ hl
lift l to List α using hl
exact ⟨⟨l, hd.of_map _⟩, ext fun a => by simp⟩
theorem image_congr (h : (s : Set α).EqOn f g) : Finset.image f s = Finset.image g s := by
ext
simp_rw [mem_image, ← bex_def]
exact exists₂_congr fun x hx => by rw [h hx]
theorem _root_.Function.Injective.mem_finset_image (hf : Injective f) :
f a ∈ s.image f ↔ a ∈ s := by
refine ⟨fun h => ?_, Finset.mem_image_of_mem f⟩
obtain ⟨y, hy, heq⟩ := mem_image.1 h
exact hf heq ▸ hy
@[simp, norm_cast]
theorem coe_image : ↑(s.image f) = f '' ↑s :=
Set.ext <| by simp only [mem_coe, mem_image, Set.mem_image, implies_true]
@[simp]
lemma image_nonempty : (s.image f).Nonempty ↔ s.Nonempty :=
mod_cast Set.image_nonempty (f := f) (s := (s : Set α))
@[aesop safe apply (rule_sets := [finsetNonempty])]
protected theorem Nonempty.image (h : s.Nonempty) (f : α → β) : (s.image f).Nonempty :=
image_nonempty.2 h
alias ⟨Nonempty.of_image, _⟩ := image_nonempty
theorem image_toFinset [DecidableEq α] {s : Multiset α} :
s.toFinset.image f = (s.map f).toFinset :=
ext fun _ => by simp only [mem_image, Multiset.mem_toFinset, exists_prop, Multiset.mem_map]
theorem image_val_of_injOn (H : Set.InjOn f s) : (image f s).1 = s.1.map f :=
(s.2.map_on H).dedup
@[simp]
theorem image_id [DecidableEq α] : s.image id = s :=
ext fun _ => by simp only [mem_image, exists_prop, id, exists_eq_right]
@[simp]
theorem image_id' [DecidableEq α] : (s.image fun x => x) = s :=
image_id
theorem image_image [DecidableEq γ] {g : β → γ} : (s.image f).image g = s.image (g ∘ f) :=
eq_of_veq <| by simp only [image_val, dedup_map_dedup_eq, Multiset.map_map]
theorem image_comm {β'} [DecidableEq β'] [DecidableEq γ] {f : β → γ} {g : α → β} {f' : α → β'}
{g' : β' → γ} (h_comm : ∀ a, f (g a) = g' (f' a)) :
(s.image g).image f = (s.image f').image g' := by simp_rw [image_image, comp_def, h_comm]
theorem _root_.Function.Semiconj.finset_image [DecidableEq α] {f : α → β} {ga : α → α} {gb : β → β}
(h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ =>
image_comm h
theorem _root_.Function.Commute.finset_image [DecidableEq α] {f g : α → α}
(h : Function.Commute f g) : Function.Commute (image f) (image g) :=
Function.Semiconj.finset_image h
theorem image_subset_image {s₁ s₂ : Finset α} (h : s₁ ⊆ s₂) : s₁.image f ⊆ s₂.image f := by
simp only [subset_def, image_val, subset_dedup', dedup_subset', Multiset.map_subset_map h]
theorem image_subset_iff : s.image f ⊆ t ↔ ∀ x ∈ s, f x ∈ t :=
calc
s.image f ⊆ t ↔ f '' ↑s ⊆ ↑t := by norm_cast
_ ↔ _ := Set.image_subset_iff
theorem image_mono (f : α → β) : Monotone (Finset.image f) := fun _ _ => image_subset_image
lemma image_injective (hf : Injective f) : Injective (image f) := by
simpa only [funext (map_eq_image _)] using map_injective ⟨f, hf⟩
lemma image_inj {t : Finset α} (hf : Injective f) : s.image f = t.image f ↔ s = t :=
(image_injective hf).eq_iff
theorem image_subset_image_iff {t : Finset α} (hf : Injective f) :
s.image f ⊆ t.image f ↔ s ⊆ t :=
mod_cast Set.image_subset_image_iff hf (s := s) (t := t)
lemma image_ssubset_image {t : Finset α} (hf : Injective f) : s.image f ⊂ t.image f ↔ s ⊂ t := by
simp_rw [← lt_iff_ssubset]
exact lt_iff_lt_of_le_iff_le' (image_subset_image_iff hf) (image_subset_image_iff hf)
theorem coe_image_subset_range : ↑(s.image f) ⊆ Set.range f :=
calc
↑(s.image f) = f '' ↑s := coe_image
_ ⊆ Set.range f := Set.image_subset_range f ↑s
theorem filter_image {p : β → Prop} [DecidablePred p] :
(s.image f).filter p = (s.filter fun a ↦ p (f a)).image f :=
ext fun b => by
simp only [mem_filter, mem_image, exists_prop]
exact
⟨by rintro ⟨⟨x, h1, rfl⟩, h2⟩; exact ⟨x, ⟨h1, h2⟩, rfl⟩,
by rintro ⟨x, ⟨h1, h2⟩, rfl⟩; exact ⟨⟨x, h1, rfl⟩, h2⟩⟩
theorem fiber_nonempty_iff_mem_image {y : β} : (s.filter (f · = y)).Nonempty ↔ y ∈ s.image f := by
simp [Finset.Nonempty]
theorem image_union [DecidableEq α] {f : α → β} (s₁ s₂ : Finset α) :
(s₁ ∪ s₂).image f = s₁.image f ∪ s₂.image f :=
mod_cast Set.image_union f s₁ s₂
theorem image_inter_subset [DecidableEq α] (f : α → β) (s t : Finset α) :
(s ∩ t).image f ⊆ s.image f ∩ t.image f :=
(image_mono f).map_inf_le s t
theorem image_inter_of_injOn [DecidableEq α] {f : α → β} (s t : Finset α)
(hf : Set.InjOn f (s ∪ t)) : (s ∩ t).image f = s.image f ∩ t.image f :=
coe_injective <| by
push_cast
exact Set.image_inter_on fun a ha b hb => hf (Or.inr ha) <| Or.inl hb
theorem image_inter [DecidableEq α] (s₁ s₂ : Finset α) (hf : Injective f) :
(s₁ ∩ s₂).image f = s₁.image f ∩ s₂.image f :=
image_inter_of_injOn _ _ hf.injOn
@[simp]
theorem image_singleton (f : α → β) (a : α) : image f {a} = {f a} :=
ext fun x => by simpa only [mem_image, exists_prop, mem_singleton, exists_eq_left] using eq_comm
@[simp]
theorem image_insert [DecidableEq α] (f : α → β) (a : α) (s : Finset α) :
(insert a s).image f = insert (f a) (s.image f) := by
simp only [insert_eq, image_singleton, image_union]
theorem erase_image_subset_image_erase [DecidableEq α] (f : α → β) (s : Finset α) (a : α) :
(s.image f).erase (f a) ⊆ (s.erase a).image f := by
simp only [subset_iff, and_imp, exists_prop, mem_image, exists_imp, mem_erase]
rintro b hb x hx rfl
exact ⟨_, ⟨ne_of_apply_ne f hb, hx⟩, rfl⟩
@[simp]
theorem image_erase [DecidableEq α] {f : α → β} (hf : Injective f) (s : Finset α) (a : α) :
(s.erase a).image f = (s.image f).erase (f a) :=
coe_injective <| by push_cast [Set.image_diff hf, Set.image_singleton]; rfl
@[simp]
theorem image_eq_empty : s.image f = ∅ ↔ s = ∅ := mod_cast Set.image_eq_empty (f := f) (s := s)
theorem image_sdiff [DecidableEq α] {f : α → β} (s t : Finset α) (hf : Injective f) :
(s \ t).image f = s.image f \ t.image f :=
mod_cast Set.image_diff hf s t
lemma image_sdiff_of_injOn [DecidableEq α] {t : Finset α} (hf : Set.InjOn f s) (hts : t ⊆ s) :
(s \ t).image f = s.image f \ t.image f :=
mod_cast Set.image_diff_of_injOn hf <| coe_subset.2 hts
theorem _root_.Disjoint.of_image_finset {s t : Finset α} {f : α → β}
(h : Disjoint (s.image f) (t.image f)) : Disjoint s t :=
disjoint_iff_ne.2 fun _ ha _ hb =>
ne_of_apply_ne f <| h.forall_ne_finset (mem_image_of_mem _ ha) (mem_image_of_mem _ hb)
theorem mem_range_iff_mem_finset_range_of_mod_eq' [DecidableEq α] {f : ℕ → α} {a : α} {n : ℕ}
(hn : 0 < n) (h : ∀ i, f (i % n) = f i) :
a ∈ Set.range f ↔ a ∈ (Finset.range n).image fun i => f i := by
constructor
· rintro ⟨i, hi⟩
simp only [mem_image, exists_prop, mem_range]
exact ⟨i % n, Nat.mod_lt i hn, (rfl.congr hi).mp (h i)⟩
· rintro h
simp only [mem_image, exists_prop, Set.mem_range, mem_range] at *
rcases h with ⟨i, _, ha⟩
exact ⟨i, ha⟩
theorem mem_range_iff_mem_finset_range_of_mod_eq [DecidableEq α] {f : ℤ → α} {a : α} {n : ℕ}
(hn : 0 < n) (h : ∀ i, f (i % n) = f i) :
a ∈ Set.range f ↔ a ∈ (Finset.range n).image (fun (i : ℕ) => f i) :=
suffices (∃ i, f (i % n) = a) ↔ ∃ i, i < n ∧ f ↑i = a by simpa [h]
have hn' : 0 < (n : ℤ) := Int.ofNat_lt.mpr hn
Iff.intro
(fun ⟨i, hi⟩ =>
have : 0 ≤ i % ↑n := Int.emod_nonneg _ (ne_of_gt hn')
⟨Int.toNat (i % n), by
rw [← Int.ofNat_lt, Int.toNat_of_nonneg this]; exact ⟨Int.emod_lt_of_pos i hn', hi⟩⟩)
fun ⟨i, hi, ha⟩ =>
⟨i, by rw [Int.emod_eq_of_lt (Int.ofNat_zero_le _) (Int.ofNat_lt_ofNat_of_lt hi), ha]⟩
@[simp]
theorem attach_image_val [DecidableEq α] {s : Finset α} : s.attach.image Subtype.val = s :=
eq_of_veq <| by rw [image_val, attach_val, Multiset.attach_map_val, dedup_eq_self]
@[simp]
theorem attach_insert [DecidableEq α] {a : α} {s : Finset α} :
attach (insert a s) =
insert (⟨a, mem_insert_self a s⟩ : { x // x ∈ insert a s })
((attach s).image fun x => ⟨x.1, mem_insert_of_mem x.2⟩) :=
ext fun ⟨x, hx⟩ =>
⟨Or.casesOn (mem_insert.1 hx)
(fun h : x = a => fun _ => mem_insert.2 <| Or.inl <| Subtype.eq h) fun h : x ∈ s => fun _ =>
mem_insert_of_mem <| mem_image.2 <| ⟨⟨x, h⟩, mem_attach _ _, Subtype.eq rfl⟩,
fun _ => Finset.mem_attach _ _⟩
@[simp]
theorem disjoint_image {s t : Finset α} {f : α → β} (hf : Injective f) :
Disjoint (s.image f) (t.image f) ↔ Disjoint s t :=
mod_cast Set.disjoint_image_iff hf (s := s) (t := t)
theorem image_const {s : Finset α} (h : s.Nonempty) (b : β) : (s.image fun _ => b) = singleton b :=
mod_cast Set.Nonempty.image_const (coe_nonempty.2 h) b
@[simp]
theorem map_erase [DecidableEq α] (f : α ↪ β) (s : Finset α) (a : α) :
(s.erase a).map f = (s.map f).erase (f a) := by
simp_rw [map_eq_image]
exact s.image_erase f.2 a
end Image
/-! ### filterMap -/
section FilterMap
/-- `filterMap f s` is a combination filter/map operation on `s`.
The function `f : α → Option β` is applied to each element of `s`;
if `f a` is `some b` then `b` is included in the result, otherwise
`a` is excluded from the resulting finset.
In notation, `filterMap f s` is the finset `{b : β | ∃ a ∈ s , f a = some b}`. -/
-- TODO: should there be `filterImage` too?
def filterMap (f : α → Option β) (s : Finset α)
(f_inj : ∀ a a' b, b ∈ f a → b ∈ f a' → a = a') : Finset β :=
⟨s.val.filterMap f, s.nodup.filterMap f f_inj⟩
variable (f : α → Option β) (s' : Finset α) {s t : Finset α}
{f_inj : ∀ a a' b, b ∈ f a → b ∈ f a' → a = a'}
@[simp]
theorem filterMap_val : (filterMap f s' f_inj).1 = s'.1.filterMap f := rfl
@[simp]
theorem filterMap_empty : (∅ : Finset α).filterMap f f_inj = ∅ := rfl
@[simp]
theorem mem_filterMap {b : β} : b ∈ s.filterMap f f_inj ↔ ∃ a ∈ s, f a = some b :=
s.val.mem_filterMap f
@[simp, norm_cast]
theorem coe_filterMap : (s.filterMap f f_inj : Set β) = {b | ∃ a ∈ s, f a = some b} :=
Set.ext (by simp only [mem_coe, mem_filterMap, Option.mem_def, Set.mem_setOf_eq, implies_true])
@[simp]
theorem filterMap_some : s.filterMap some (by simp) = s :=
ext fun _ => by simp only [mem_filterMap, Option.some.injEq, exists_eq_right]
theorem filterMap_mono (h : s ⊆ t) :
filterMap f s f_inj ⊆ filterMap f t f_inj := by
rw [← val_le_iff] at h ⊢
exact Multiset.filterMap_le_filterMap f h
@[simp]
| Mathlib/Data/Finset/Image.lean | 560 | 562 | theorem _root_.List.toFinset_filterMap [DecidableEq α] [DecidableEq β] (s : List α) :
(s.filterMap f).toFinset = s.toFinset.filterMap f f_inj := by | simp [← Finset.coe_inj] |
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Analysis.SpecificLimits.Basic
import Mathlib.Topology.MetricSpace.IsometricSMul
/-!
# Hausdorff distance
The Hausdorff distance on subsets of a metric (or emetric) space.
Given two subsets `s` and `t` of a metric space, their Hausdorff distance is the smallest `d`
such that any point `s` is within `d` of a point in `t`, and conversely. This quantity
is often infinite (think of `s` bounded and `t` unbounded), and therefore better
expressed in the setting of emetric spaces.
## Main definitions
This files introduces:
* `EMetric.infEdist x s`, the infimum edistance of a point `x` to a set `s` in an emetric space
* `EMetric.hausdorffEdist s t`, the Hausdorff edistance of two sets in an emetric space
* Versions of these notions on metric spaces, called respectively `Metric.infDist`
and `Metric.hausdorffDist`
## Main results
* `infEdist_closure`: the edistance to a set and its closure coincide
* `EMetric.mem_closure_iff_infEdist_zero`: a point `x` belongs to the closure of `s` iff
`infEdist x s = 0`
* `IsCompact.exists_infEdist_eq_edist`: if `s` is compact and non-empty, there exists a point `y`
which attains this edistance
* `IsOpen.exists_iUnion_isClosed`: every open set `U` can be written as the increasing union
of countably many closed subsets of `U`
* `hausdorffEdist_closure`: replacing a set by its closure does not change the Hausdorff edistance
* `hausdorffEdist_zero_iff_closure_eq_closure`: two sets have Hausdorff edistance zero
iff their closures coincide
* the Hausdorff edistance is symmetric and satisfies the triangle inequality
* in particular, closed sets in an emetric space are an emetric space
(this is shown in `EMetricSpace.closeds.emetricspace`)
* versions of these notions on metric spaces
* `hausdorffEdist_ne_top_of_nonempty_of_bounded`: if two sets in a metric space
are nonempty and bounded in a metric space, they are at finite Hausdorff edistance.
## Tags
metric space, Hausdorff distance
-/
noncomputable section
open NNReal ENNReal Topology Set Filter Pointwise Bornology
universe u v w
variable {ι : Sort*} {α : Type u} {β : Type v}
namespace EMetric
section InfEdist
variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] {x y : α} {s t : Set α} {Φ : α → β}
/-! ### Distance of a point to a set as a function into `ℝ≥0∞`. -/
/-- The minimal edistance of a point to a set -/
def infEdist (x : α) (s : Set α) : ℝ≥0∞ :=
⨅ y ∈ s, edist x y
@[simp]
theorem infEdist_empty : infEdist x ∅ = ∞ :=
iInf_emptyset
theorem le_infEdist {d} : d ≤ infEdist x s ↔ ∀ y ∈ s, d ≤ edist x y := by
simp only [infEdist, le_iInf_iff]
/-- The edist to a union is the minimum of the edists -/
@[simp]
theorem infEdist_union : infEdist x (s ∪ t) = infEdist x s ⊓ infEdist x t :=
iInf_union
@[simp]
theorem infEdist_iUnion (f : ι → Set α) (x : α) : infEdist x (⋃ i, f i) = ⨅ i, infEdist x (f i) :=
iInf_iUnion f _
lemma infEdist_biUnion {ι : Type*} (f : ι → Set α) (I : Set ι) (x : α) :
infEdist x (⋃ i ∈ I, f i) = ⨅ i ∈ I, infEdist x (f i) := by simp only [infEdist_iUnion]
/-- The edist to a singleton is the edistance to the single point of this singleton -/
@[simp]
theorem infEdist_singleton : infEdist x {y} = edist x y :=
iInf_singleton
/-- The edist to a set is bounded above by the edist to any of its points -/
theorem infEdist_le_edist_of_mem (h : y ∈ s) : infEdist x s ≤ edist x y :=
iInf₂_le y h
/-- If a point `x` belongs to `s`, then its edist to `s` vanishes -/
theorem infEdist_zero_of_mem (h : x ∈ s) : infEdist x s = 0 :=
nonpos_iff_eq_zero.1 <| @edist_self _ _ x ▸ infEdist_le_edist_of_mem h
/-- The edist is antitone with respect to inclusion. -/
theorem infEdist_anti (h : s ⊆ t) : infEdist x t ≤ infEdist x s :=
iInf_le_iInf_of_subset h
/-- The edist to a set is `< r` iff there exists a point in the set at edistance `< r` -/
theorem infEdist_lt_iff {r : ℝ≥0∞} : infEdist x s < r ↔ ∃ y ∈ s, edist x y < r := by
simp_rw [infEdist, iInf_lt_iff, exists_prop]
/-- The edist of `x` to `s` is bounded by the sum of the edist of `y` to `s` and
the edist from `x` to `y` -/
theorem infEdist_le_infEdist_add_edist : infEdist x s ≤ infEdist y s + edist x y :=
calc
⨅ z ∈ s, edist x z ≤ ⨅ z ∈ s, edist y z + edist x y :=
iInf₂_mono fun _ _ => (edist_triangle _ _ _).trans_eq (add_comm _ _)
_ = (⨅ z ∈ s, edist y z) + edist x y := by simp only [ENNReal.iInf_add]
theorem infEdist_le_edist_add_infEdist : infEdist x s ≤ edist x y + infEdist y s := by
rw [add_comm]
exact infEdist_le_infEdist_add_edist
theorem edist_le_infEdist_add_ediam (hy : y ∈ s) : edist x y ≤ infEdist x s + diam s := by
simp_rw [infEdist, ENNReal.iInf_add]
refine le_iInf₂ fun i hi => ?_
calc
edist x y ≤ edist x i + edist i y := edist_triangle _ _ _
_ ≤ edist x i + diam s := add_le_add le_rfl (edist_le_diam_of_mem hi hy)
/-- The edist to a set depends continuously on the point -/
@[continuity]
theorem continuous_infEdist : Continuous fun x => infEdist x s :=
continuous_of_le_add_edist 1 (by simp) <| by
simp only [one_mul, infEdist_le_infEdist_add_edist, forall₂_true_iff]
/-- The edist to a set and to its closure coincide -/
theorem infEdist_closure : infEdist x (closure s) = infEdist x s := by
refine le_antisymm (infEdist_anti subset_closure) ?_
refine ENNReal.le_of_forall_pos_le_add fun ε εpos h => ?_
have ε0 : 0 < (ε / 2 : ℝ≥0∞) := by simpa [pos_iff_ne_zero] using εpos
have : infEdist x (closure s) < infEdist x (closure s) + ε / 2 :=
ENNReal.lt_add_right h.ne ε0.ne'
obtain ⟨y : α, ycs : y ∈ closure s, hy : edist x y < infEdist x (closure s) + ↑ε / 2⟩ :=
infEdist_lt_iff.mp this
obtain ⟨z : α, zs : z ∈ s, dyz : edist y z < ↑ε / 2⟩ := EMetric.mem_closure_iff.1 ycs (ε / 2) ε0
calc
infEdist x s ≤ edist x z := infEdist_le_edist_of_mem zs
_ ≤ edist x y + edist y z := edist_triangle _ _ _
_ ≤ infEdist x (closure s) + ε / 2 + ε / 2 := add_le_add (le_of_lt hy) (le_of_lt dyz)
_ = infEdist x (closure s) + ↑ε := by rw [add_assoc, ENNReal.add_halves]
/-- A point belongs to the closure of `s` iff its infimum edistance to this set vanishes -/
theorem mem_closure_iff_infEdist_zero : x ∈ closure s ↔ infEdist x s = 0 :=
⟨fun h => by
rw [← infEdist_closure]
exact infEdist_zero_of_mem h,
fun h =>
EMetric.mem_closure_iff.2 fun ε εpos => infEdist_lt_iff.mp <| by rwa [h]⟩
/-- Given a closed set `s`, a point belongs to `s` iff its infimum edistance to this set vanishes -/
theorem mem_iff_infEdist_zero_of_closed (h : IsClosed s) : x ∈ s ↔ infEdist x s = 0 := by
rw [← mem_closure_iff_infEdist_zero, h.closure_eq]
/-- The infimum edistance of a point to a set is positive if and only if the point is not in the
closure of the set. -/
theorem infEdist_pos_iff_not_mem_closure {x : α} {E : Set α} :
0 < infEdist x E ↔ x ∉ closure E := by
rw [mem_closure_iff_infEdist_zero, pos_iff_ne_zero]
theorem infEdist_closure_pos_iff_not_mem_closure {x : α} {E : Set α} :
0 < infEdist x (closure E) ↔ x ∉ closure E := by
rw [infEdist_closure, infEdist_pos_iff_not_mem_closure]
theorem exists_real_pos_lt_infEdist_of_not_mem_closure {x : α} {E : Set α} (h : x ∉ closure E) :
∃ ε : ℝ, 0 < ε ∧ ENNReal.ofReal ε < infEdist x E := by
rw [← infEdist_pos_iff_not_mem_closure, ENNReal.lt_iff_exists_real_btwn] at h
rcases h with ⟨ε, ⟨_, ⟨ε_pos, ε_lt⟩⟩⟩
exact ⟨ε, ⟨ENNReal.ofReal_pos.mp ε_pos, ε_lt⟩⟩
theorem disjoint_closedBall_of_lt_infEdist {r : ℝ≥0∞} (h : r < infEdist x s) :
Disjoint (closedBall x r) s := by
rw [disjoint_left]
intro y hy h'y
apply lt_irrefl (infEdist x s)
calc
infEdist x s ≤ edist x y := infEdist_le_edist_of_mem h'y
_ ≤ r := by rwa [mem_closedBall, edist_comm] at hy
_ < infEdist x s := h
/-- The infimum edistance is invariant under isometries -/
theorem infEdist_image (hΦ : Isometry Φ) : infEdist (Φ x) (Φ '' t) = infEdist x t := by
simp only [infEdist, iInf_image, hΦ.edist_eq]
@[to_additive (attr := simp)]
theorem infEdist_smul {M} [SMul M α] [IsIsometricSMul M α] (c : M) (x : α) (s : Set α) :
infEdist (c • x) (c • s) = infEdist x s :=
infEdist_image (isometry_smul _ _)
theorem _root_.IsOpen.exists_iUnion_isClosed {U : Set α} (hU : IsOpen U) :
∃ F : ℕ → Set α, (∀ n, IsClosed (F n)) ∧ (∀ n, F n ⊆ U) ∧ ⋃ n, F n = U ∧ Monotone F := by
obtain ⟨a, a_pos, a_lt_one⟩ : ∃ a : ℝ≥0∞, 0 < a ∧ a < 1 := exists_between zero_lt_one
let F := fun n : ℕ => (fun x => infEdist x Uᶜ) ⁻¹' Ici (a ^ n)
have F_subset : ∀ n, F n ⊆ U := fun n x hx ↦ by
by_contra h
have : infEdist x Uᶜ ≠ 0 := ((ENNReal.pow_pos a_pos _).trans_le hx).ne'
exact this (infEdist_zero_of_mem h)
refine ⟨F, fun n => IsClosed.preimage continuous_infEdist isClosed_Ici, F_subset, ?_, ?_⟩
· show ⋃ n, F n = U
refine Subset.antisymm (by simp only [iUnion_subset_iff, F_subset, forall_const]) fun x hx => ?_
have : ¬x ∈ Uᶜ := by simpa using hx
rw [mem_iff_infEdist_zero_of_closed hU.isClosed_compl] at this
have B : 0 < infEdist x Uᶜ := by simpa [pos_iff_ne_zero] using this
have : Filter.Tendsto (fun n => a ^ n) atTop (𝓝 0) :=
ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one a_lt_one
rcases ((tendsto_order.1 this).2 _ B).exists with ⟨n, hn⟩
simp only [mem_iUnion, mem_Ici, mem_preimage]
exact ⟨n, hn.le⟩
show Monotone F
intro m n hmn x hx
simp only [F, mem_Ici, mem_preimage] at hx ⊢
apply le_trans (pow_le_pow_right_of_le_one' a_lt_one.le hmn) hx
theorem _root_.IsCompact.exists_infEdist_eq_edist (hs : IsCompact s) (hne : s.Nonempty) (x : α) :
∃ y ∈ s, infEdist x s = edist x y := by
have A : Continuous fun y => edist x y := continuous_const.edist continuous_id
obtain ⟨y, ys, hy⟩ := hs.exists_isMinOn hne A.continuousOn
exact ⟨y, ys, le_antisymm (infEdist_le_edist_of_mem ys) (by rwa [le_infEdist])⟩
theorem exists_pos_forall_lt_edist (hs : IsCompact s) (ht : IsClosed t) (hst : Disjoint s t) :
∃ r : ℝ≥0, 0 < r ∧ ∀ x ∈ s, ∀ y ∈ t, (r : ℝ≥0∞) < edist x y := by
rcases s.eq_empty_or_nonempty with (rfl | hne)
· use 1
simp
obtain ⟨x, hx, h⟩ := hs.exists_isMinOn hne continuous_infEdist.continuousOn
have : 0 < infEdist x t :=
pos_iff_ne_zero.2 fun H => hst.le_bot ⟨hx, (mem_iff_infEdist_zero_of_closed ht).mpr H⟩
rcases ENNReal.lt_iff_exists_nnreal_btwn.1 this with ⟨r, h₀, hr⟩
exact ⟨r, ENNReal.coe_pos.mp h₀, fun y hy z hz => hr.trans_le <| le_infEdist.1 (h hy) z hz⟩
end InfEdist
/-! ### The Hausdorff distance as a function into `ℝ≥0∞`. -/
/-- The Hausdorff edistance between two sets is the smallest `r` such that each set
is contained in the `r`-neighborhood of the other one -/
irreducible_def hausdorffEdist {α : Type u} [PseudoEMetricSpace α] (s t : Set α) : ℝ≥0∞ :=
(⨆ x ∈ s, infEdist x t) ⊔ ⨆ y ∈ t, infEdist y s
section HausdorffEdist
variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] {x : α} {s t u : Set α} {Φ : α → β}
/-- The Hausdorff edistance of a set to itself vanishes. -/
@[simp]
theorem hausdorffEdist_self : hausdorffEdist s s = 0 := by
simp only [hausdorffEdist_def, sup_idem, ENNReal.iSup_eq_zero]
exact fun x hx => infEdist_zero_of_mem hx
/-- The Haudorff edistances of `s` to `t` and of `t` to `s` coincide. -/
theorem hausdorffEdist_comm : hausdorffEdist s t = hausdorffEdist t s := by
simp only [hausdorffEdist_def]; apply sup_comm
/-- Bounding the Hausdorff edistance by bounding the edistance of any point
in each set to the other set -/
theorem hausdorffEdist_le_of_infEdist {r : ℝ≥0∞} (H1 : ∀ x ∈ s, infEdist x t ≤ r)
(H2 : ∀ x ∈ t, infEdist x s ≤ r) : hausdorffEdist s t ≤ r := by
simp only [hausdorffEdist_def, sup_le_iff, iSup_le_iff]
exact ⟨H1, H2⟩
/-- Bounding the Hausdorff edistance by exhibiting, for any point in each set,
another point in the other set at controlled distance -/
theorem hausdorffEdist_le_of_mem_edist {r : ℝ≥0∞} (H1 : ∀ x ∈ s, ∃ y ∈ t, edist x y ≤ r)
(H2 : ∀ x ∈ t, ∃ y ∈ s, edist x y ≤ r) : hausdorffEdist s t ≤ r := by
refine hausdorffEdist_le_of_infEdist (fun x xs ↦ ?_) (fun x xt ↦ ?_)
· rcases H1 x xs with ⟨y, yt, hy⟩
exact le_trans (infEdist_le_edist_of_mem yt) hy
· rcases H2 x xt with ⟨y, ys, hy⟩
exact le_trans (infEdist_le_edist_of_mem ys) hy
/-- The distance to a set is controlled by the Hausdorff distance. -/
theorem infEdist_le_hausdorffEdist_of_mem (h : x ∈ s) : infEdist x t ≤ hausdorffEdist s t := by
rw [hausdorffEdist_def]
refine le_trans ?_ le_sup_left
exact le_iSup₂ (α := ℝ≥0∞) x h
/-- If the Hausdorff distance is `< r`, then any point in one of the sets has
a corresponding point at distance `< r` in the other set. -/
theorem exists_edist_lt_of_hausdorffEdist_lt {r : ℝ≥0∞} (h : x ∈ s) (H : hausdorffEdist s t < r) :
∃ y ∈ t, edist x y < r :=
infEdist_lt_iff.mp <|
calc
infEdist x t ≤ hausdorffEdist s t := infEdist_le_hausdorffEdist_of_mem h
_ < r := H
/-- The distance from `x` to `s` or `t` is controlled in terms of the Hausdorff distance
between `s` and `t`. -/
theorem infEdist_le_infEdist_add_hausdorffEdist :
infEdist x t ≤ infEdist x s + hausdorffEdist s t :=
ENNReal.le_of_forall_pos_le_add fun ε εpos h => by
have ε0 : (ε / 2 : ℝ≥0∞) ≠ 0 := by simpa [pos_iff_ne_zero] using εpos
have : infEdist x s < infEdist x s + ε / 2 :=
ENNReal.lt_add_right (ENNReal.add_lt_top.1 h).1.ne ε0
obtain ⟨y : α, ys : y ∈ s, dxy : edist x y < infEdist x s + ↑ε / 2⟩ := infEdist_lt_iff.mp this
have : hausdorffEdist s t < hausdorffEdist s t + ε / 2 :=
ENNReal.lt_add_right (ENNReal.add_lt_top.1 h).2.ne ε0
obtain ⟨z : α, zt : z ∈ t, dyz : edist y z < hausdorffEdist s t + ↑ε / 2⟩ :=
exists_edist_lt_of_hausdorffEdist_lt ys this
calc
infEdist x t ≤ edist x z := infEdist_le_edist_of_mem zt
_ ≤ edist x y + edist y z := edist_triangle _ _ _
_ ≤ infEdist x s + ε / 2 + (hausdorffEdist s t + ε / 2) := add_le_add dxy.le dyz.le
_ = infEdist x s + hausdorffEdist s t + ε := by
simp [ENNReal.add_halves, add_comm, add_left_comm]
/-- The Hausdorff edistance is invariant under isometries. -/
theorem hausdorffEdist_image (h : Isometry Φ) :
hausdorffEdist (Φ '' s) (Φ '' t) = hausdorffEdist s t := by
simp only [hausdorffEdist_def, iSup_image, infEdist_image h]
/-- The Hausdorff distance is controlled by the diameter of the union. -/
theorem hausdorffEdist_le_ediam (hs : s.Nonempty) (ht : t.Nonempty) :
hausdorffEdist s t ≤ diam (s ∪ t) := by
rcases hs with ⟨x, xs⟩
rcases ht with ⟨y, yt⟩
refine hausdorffEdist_le_of_mem_edist ?_ ?_
· intro z hz
exact ⟨y, yt, edist_le_diam_of_mem (subset_union_left hz) (subset_union_right yt)⟩
· intro z hz
exact ⟨x, xs, edist_le_diam_of_mem (subset_union_right hz) (subset_union_left xs)⟩
/-- The Hausdorff distance satisfies the triangle inequality. -/
theorem hausdorffEdist_triangle : hausdorffEdist s u ≤ hausdorffEdist s t + hausdorffEdist t u := by
rw [hausdorffEdist_def]
simp only [sup_le_iff, iSup_le_iff]
constructor
· show ∀ x ∈ s, infEdist x u ≤ hausdorffEdist s t + hausdorffEdist t u
exact fun x xs =>
calc
infEdist x u ≤ infEdist x t + hausdorffEdist t u :=
infEdist_le_infEdist_add_hausdorffEdist
_ ≤ hausdorffEdist s t + hausdorffEdist t u :=
add_le_add_right (infEdist_le_hausdorffEdist_of_mem xs) _
· show ∀ x ∈ u, infEdist x s ≤ hausdorffEdist s t + hausdorffEdist t u
exact fun x xu =>
calc
infEdist x s ≤ infEdist x t + hausdorffEdist t s :=
infEdist_le_infEdist_add_hausdorffEdist
_ ≤ hausdorffEdist u t + hausdorffEdist t s :=
add_le_add_right (infEdist_le_hausdorffEdist_of_mem xu) _
_ = hausdorffEdist s t + hausdorffEdist t u := by simp [hausdorffEdist_comm, add_comm]
/-- Two sets are at zero Hausdorff edistance if and only if they have the same closure. -/
theorem hausdorffEdist_zero_iff_closure_eq_closure :
hausdorffEdist s t = 0 ↔ closure s = closure t := by
simp only [hausdorffEdist_def, ENNReal.sup_eq_zero, ENNReal.iSup_eq_zero, ← subset_def,
← mem_closure_iff_infEdist_zero, subset_antisymm_iff, isClosed_closure.closure_subset_iff]
/-- The Hausdorff edistance between a set and its closure vanishes. -/
@[simp]
theorem hausdorffEdist_self_closure : hausdorffEdist s (closure s) = 0 := by
rw [hausdorffEdist_zero_iff_closure_eq_closure, closure_closure]
/-- Replacing a set by its closure does not change the Hausdorff edistance. -/
@[simp]
theorem hausdorffEdist_closure₁ : hausdorffEdist (closure s) t = hausdorffEdist s t := by
refine le_antisymm ?_ ?_
· calc
_ ≤ hausdorffEdist (closure s) s + hausdorffEdist s t := hausdorffEdist_triangle
_ = hausdorffEdist s t := by simp [hausdorffEdist_comm]
· calc
_ ≤ hausdorffEdist s (closure s) + hausdorffEdist (closure s) t := hausdorffEdist_triangle
_ = hausdorffEdist (closure s) t := by simp
/-- Replacing a set by its closure does not change the Hausdorff edistance. -/
@[simp]
theorem hausdorffEdist_closure₂ : hausdorffEdist s (closure t) = hausdorffEdist s t := by
simp [@hausdorffEdist_comm _ _ s _]
/-- The Hausdorff edistance between sets or their closures is the same. -/
theorem hausdorffEdist_closure : hausdorffEdist (closure s) (closure t) = hausdorffEdist s t := by
simp
/-- Two closed sets are at zero Hausdorff edistance if and only if they coincide. -/
theorem hausdorffEdist_zero_iff_eq_of_closed (hs : IsClosed s) (ht : IsClosed t) :
hausdorffEdist s t = 0 ↔ s = t := by
rw [hausdorffEdist_zero_iff_closure_eq_closure, hs.closure_eq, ht.closure_eq]
/-- The Haudorff edistance to the empty set is infinite. -/
theorem hausdorffEdist_empty (ne : s.Nonempty) : hausdorffEdist s ∅ = ∞ := by
rcases ne with ⟨x, xs⟩
have : infEdist x ∅ ≤ hausdorffEdist s ∅ := infEdist_le_hausdorffEdist_of_mem xs
simpa using this
/-- If a set is at finite Hausdorff edistance of a nonempty set, it is nonempty. -/
theorem nonempty_of_hausdorffEdist_ne_top (hs : s.Nonempty) (fin : hausdorffEdist s t ≠ ⊤) :
t.Nonempty :=
t.eq_empty_or_nonempty.resolve_left fun ht ↦ fin (ht.symm ▸ hausdorffEdist_empty hs)
theorem empty_or_nonempty_of_hausdorffEdist_ne_top (fin : hausdorffEdist s t ≠ ⊤) :
(s = ∅ ∧ t = ∅) ∨ (s.Nonempty ∧ t.Nonempty) := by
rcases s.eq_empty_or_nonempty with hs | hs
· rcases t.eq_empty_or_nonempty with ht | ht
· exact Or.inl ⟨hs, ht⟩
· rw [hausdorffEdist_comm] at fin
exact Or.inr ⟨nonempty_of_hausdorffEdist_ne_top ht fin, ht⟩
· exact Or.inr ⟨hs, nonempty_of_hausdorffEdist_ne_top hs fin⟩
end HausdorffEdist
-- section
end EMetric
/-! Now, we turn to the same notions in metric spaces. To avoid the difficulties related to
`sInf` and `sSup` on `ℝ` (which is only conditionally complete), we use the notions in `ℝ≥0∞`
formulated in terms of the edistance, and coerce them to `ℝ`.
Then their properties follow readily from the corresponding properties in `ℝ≥0∞`,
modulo some tedious rewriting of inequalities from one to the other. -/
--namespace
namespace Metric
section
variable [PseudoMetricSpace α] [PseudoMetricSpace β] {s t u : Set α} {x y : α} {Φ : α → β}
open EMetric
/-! ### Distance of a point to a set as a function into `ℝ`. -/
/-- The minimal distance of a point to a set -/
def infDist (x : α) (s : Set α) : ℝ :=
ENNReal.toReal (infEdist x s)
theorem infDist_eq_iInf : infDist x s = ⨅ y : s, dist x y := by
rw [infDist, infEdist, iInf_subtype', ENNReal.toReal_iInf]
· simp only [dist_edist]
· exact fun _ ↦ edist_ne_top _ _
/-- The minimal distance is always nonnegative -/
theorem infDist_nonneg : 0 ≤ infDist x s := toReal_nonneg
/-- The minimal distance to the empty set is 0 (if you want to have the more reasonable
value `∞` instead, use `EMetric.infEdist`, which takes values in `ℝ≥0∞`) -/
@[simp]
theorem infDist_empty : infDist x ∅ = 0 := by simp [infDist]
lemma isGLB_infDist (hs : s.Nonempty) : IsGLB ((dist x ·) '' s) (infDist x s) := by
simpa [infDist_eq_iInf, sInf_image']
using isGLB_csInf (hs.image _) ⟨0, by simp [lowerBounds, dist_nonneg]⟩
/-- In a metric space, the minimal edistance to a nonempty set is finite. -/
theorem infEdist_ne_top (h : s.Nonempty) : infEdist x s ≠ ⊤ := by
rcases h with ⟨y, hy⟩
exact ne_top_of_le_ne_top (edist_ne_top _ _) (infEdist_le_edist_of_mem hy)
@[simp]
theorem infEdist_eq_top_iff : infEdist x s = ∞ ↔ s = ∅ := by
rcases s.eq_empty_or_nonempty with rfl | hs <;> simp [*, Nonempty.ne_empty, infEdist_ne_top]
/-- The minimal distance of a point to a set containing it vanishes. -/
theorem infDist_zero_of_mem (h : x ∈ s) : infDist x s = 0 := by
simp [infEdist_zero_of_mem h, infDist]
/-- The minimal distance to a singleton is the distance to the unique point in this singleton. -/
@[simp]
theorem infDist_singleton : infDist x {y} = dist x y := by simp [infDist, dist_edist]
/-- The minimal distance to a set is bounded by the distance to any point in this set. -/
theorem infDist_le_dist_of_mem (h : y ∈ s) : infDist x s ≤ dist x y := by
rw [dist_edist, infDist]
exact ENNReal.toReal_mono (edist_ne_top _ _) (infEdist_le_edist_of_mem h)
/-- The minimal distance is monotone with respect to inclusion. -/
theorem infDist_le_infDist_of_subset (h : s ⊆ t) (hs : s.Nonempty) : infDist x t ≤ infDist x s :=
ENNReal.toReal_mono (infEdist_ne_top hs) (infEdist_anti h)
lemma le_infDist {r : ℝ} (hs : s.Nonempty) : r ≤ infDist x s ↔ ∀ ⦃y⦄, y ∈ s → r ≤ dist x y := by
simp_rw [infDist, ← ENNReal.ofReal_le_iff_le_toReal (infEdist_ne_top hs), le_infEdist,
ENNReal.ofReal_le_iff_le_toReal (edist_ne_top _ _), ← dist_edist]
/-- The minimal distance to a set `s` is `< r` iff there exists a point in `s` at distance `< r`. -/
theorem infDist_lt_iff {r : ℝ} (hs : s.Nonempty) : infDist x s < r ↔ ∃ y ∈ s, dist x y < r := by
simp [← not_le, le_infDist hs]
/-- The minimal distance from `x` to `s` is bounded by the distance from `y` to `s`, modulo
the distance between `x` and `y`. -/
| Mathlib/Topology/MetricSpace/HausdorffDistance.lean | 488 | 491 | theorem infDist_le_infDist_add_dist : infDist x s ≤ infDist y s + dist x y := by | rw [infDist, infDist, dist_edist]
refine ENNReal.toReal_le_add' infEdist_le_infEdist_add_edist ?_ (flip absurd (edist_ne_top _ _))
simp only [infEdist_eq_top_iff, imp_self] |
/-
Copyright (c) 2021 Frédéric Dupuis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Frédéric Dupuis
-/
import Mathlib.Algebra.Group.Subgroup.Defs
import Mathlib.Algebra.Module.Defs
import Mathlib.Algebra.Star.Pi
import Mathlib.Algebra.Star.Rat
/-!
# Self-adjoint, skew-adjoint and normal elements of a star additive group
This file defines `selfAdjoint R` (resp. `skewAdjoint R`), where `R` is a star additive group,
as the additive subgroup containing the elements that satisfy `star x = x` (resp. `star x = -x`).
This includes, for instance, (skew-)Hermitian operators on Hilbert spaces.
We also define `IsStarNormal R`, a `Prop` that states that an element `x` satisfies
`star x * x = x * star x`.
## Implementation notes
* When `R` is a `StarModule R₂ R`, then `selfAdjoint R` has a natural
`Module (selfAdjoint R₂) (selfAdjoint R)` structure. However, doing this literally would be
undesirable since in the main case of interest (`R₂ = ℂ`) we want `Module ℝ (selfAdjoint R)`
and not `Module (selfAdjoint ℂ) (selfAdjoint R)`. We solve this issue by adding the typeclass
`[TrivialStar R₃]`, of which `ℝ` is an instance (registered in `Data/Real/Basic`), and then
add a `[Module R₃ (selfAdjoint R)]` instance whenever we have
`[Module R₃ R] [TrivialStar R₃]`. (Another approach would have been to define
`[StarInvariantScalars R₃ R]` to express the fact that `star (x • v) = x • star v`, but
this typeclass would have the disadvantage of taking two type arguments.)
## TODO
* Define `IsSkewAdjoint` to match `IsSelfAdjoint`.
* Define `fun z x => z * x * star z` (i.e. conjugation by `z`) as a monoid action of `R` on `R`
(similar to the existing `ConjAct` for groups), and then state the fact that `selfAdjoint R` is
invariant under it.
-/
open Function
variable {R A : Type*}
/-- An element is self-adjoint if it is equal to its star. -/
def IsSelfAdjoint [Star R] (x : R) : Prop :=
star x = x
/-- An element of a star monoid is normal if it commutes with its adjoint. -/
@[mk_iff]
class IsStarNormal [Mul R] [Star R] (x : R) : Prop where
/-- A normal element of a star monoid commutes with its adjoint. -/
star_comm_self : Commute (star x) x
export IsStarNormal (star_comm_self)
theorem star_comm_self' [Mul R] [Star R] (x : R) [IsStarNormal x] : star x * x = x * star x :=
IsStarNormal.star_comm_self
namespace IsSelfAdjoint
-- named to match `Commute.allₓ`
/-- All elements are self-adjoint when `star` is trivial. -/
theorem all [Star R] [TrivialStar R] (r : R) : IsSelfAdjoint r :=
star_trivial _
theorem star_eq [Star R] {x : R} (hx : IsSelfAdjoint x) : star x = x :=
hx
theorem _root_.isSelfAdjoint_iff [Star R] {x : R} : IsSelfAdjoint x ↔ star x = x :=
Iff.rfl
@[simp]
theorem star_iff [InvolutiveStar R] {x : R} : IsSelfAdjoint (star x) ↔ IsSelfAdjoint x := by
simpa only [IsSelfAdjoint, star_star] using eq_comm
@[simp]
theorem star_mul_self [Mul R] [StarMul R] (x : R) : IsSelfAdjoint (star x * x) := by
simp only [IsSelfAdjoint, star_mul, star_star]
@[simp]
theorem mul_star_self [Mul R] [StarMul R] (x : R) : IsSelfAdjoint (x * star x) := by
simpa only [star_star] using star_mul_self (star x)
/-- Self-adjoint elements commute if and only if their product is self-adjoint. -/
lemma commute_iff {R : Type*} [Mul R] [StarMul R] {x y : R}
(hx : IsSelfAdjoint x) (hy : IsSelfAdjoint y) : Commute x y ↔ IsSelfAdjoint (x * y) := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· rw [isSelfAdjoint_iff, star_mul, hx.star_eq, hy.star_eq, h.eq]
· simpa only [star_mul, hx.star_eq, hy.star_eq] using h.symm
/-- Functions in a `StarHomClass` preserve self-adjoint elements. -/
@[aesop 10% apply]
theorem map {F R S : Type*} [Star R] [Star S] [FunLike F R S] [StarHomClass F R S]
{x : R} (hx : IsSelfAdjoint x) (f : F) : IsSelfAdjoint (f x) :=
show star (f x) = f x from map_star f x ▸ congr_arg f hx
/- note: this lemma is *not* marked as `simp` so that Lean doesn't look for a `[TrivialStar R]`
instance every time it sees `⊢ IsSelfAdjoint (f x)`, which will likely occur relatively often. -/
theorem _root_.isSelfAdjoint_map {F R S : Type*} [Star R] [Star S] [FunLike F R S]
[StarHomClass F R S] [TrivialStar R] (f : F) (x : R) : IsSelfAdjoint (f x) :=
(IsSelfAdjoint.all x).map f
section AddMonoid
variable [AddMonoid R] [StarAddMonoid R]
variable (R) in
@[simp] protected theorem zero : IsSelfAdjoint (0 : R) := star_zero R
@[aesop 90% apply]
theorem add {x y : R} (hx : IsSelfAdjoint x) (hy : IsSelfAdjoint y) : IsSelfAdjoint (x + y) := by
simp only [isSelfAdjoint_iff, star_add, hx.star_eq, hy.star_eq]
end AddMonoid
section AddGroup
variable [AddGroup R] [StarAddMonoid R]
@[aesop safe apply]
theorem neg {x : R} (hx : IsSelfAdjoint x) : IsSelfAdjoint (-x) := by
simp only [isSelfAdjoint_iff, star_neg, hx.star_eq]
@[aesop 90% apply]
| Mathlib/Algebra/Star/SelfAdjoint.lean | 127 | 128 | theorem sub {x y : R} (hx : IsSelfAdjoint x) (hy : IsSelfAdjoint y) : IsSelfAdjoint (x - y) := by | simp only [isSelfAdjoint_iff, star_sub, hx.star_eq, hy.star_eq] |
/-
Copyright (c) 2021 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.CategoryTheory.Monoidal.Functor
/-!
# Preadditive monoidal categories
A monoidal category is `MonoidalPreadditive` if it is preadditive and tensor product of morphisms
is linear in both factors.
-/
noncomputable section
namespace CategoryTheory
open CategoryTheory.Limits
open CategoryTheory.MonoidalCategory
variable (C : Type*) [Category C] [Preadditive C] [MonoidalCategory C]
/-- A category is `MonoidalPreadditive` if tensoring is additive in both factors.
Note we don't `extend Preadditive C` here, as `Abelian C` already extends it,
and we'll need to have both typeclasses sometimes.
-/
class MonoidalPreadditive : Prop where
whiskerLeft_zero : ∀ {X Y Z : C}, X ◁ (0 : Y ⟶ Z) = 0 := by aesop_cat
zero_whiskerRight : ∀ {X Y Z : C}, (0 : Y ⟶ Z) ▷ X = 0 := by aesop_cat
whiskerLeft_add : ∀ {X Y Z : C} (f g : Y ⟶ Z), X ◁ (f + g) = X ◁ f + X ◁ g := by aesop_cat
add_whiskerRight : ∀ {X Y Z : C} (f g : Y ⟶ Z), (f + g) ▷ X = f ▷ X + g ▷ X := by aesop_cat
attribute [simp] MonoidalPreadditive.whiskerLeft_zero MonoidalPreadditive.zero_whiskerRight
attribute [simp] MonoidalPreadditive.whiskerLeft_add MonoidalPreadditive.add_whiskerRight
variable {C}
variable [MonoidalPreadditive C]
namespace MonoidalPreadditive
-- The priority setting will not be needed when we replace `𝟙 X ⊗ f` by `X ◁ f`.
@[simp (low)]
theorem tensor_zero {W X Y Z : C} (f : W ⟶ X) : f ⊗ (0 : Y ⟶ Z) = 0 := by
simp [tensorHom_def]
-- The priority setting will not be needed when we replace `f ⊗ 𝟙 X` by `f ▷ X`.
@[simp (low)]
| Mathlib/CategoryTheory/Monoidal/Preadditive.lean | 52 | 53 | theorem zero_tensor {W X Y Z : C} (f : Y ⟶ Z) : (0 : W ⟶ X) ⊗ f = 0 := by | simp [tensorHom_def] |
/-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Frédéric Dupuis, Heather Macbeth
-/
import Mathlib.Analysis.Convex.Basic
import Mathlib.Analysis.InnerProductSpace.Orthogonal
import Mathlib.Analysis.InnerProductSpace.Symmetric
import Mathlib.Analysis.NormedSpace.RCLike
import Mathlib.Analysis.RCLike.Lemmas
import Mathlib.Algebra.DirectSum.Decomposition
/-!
# The orthogonal projection
Given a nonempty complete subspace `K` of an inner product space `E`, this file constructs
`K.orthogonalProjection : E →L[𝕜] K`, the orthogonal projection of `E` onto `K`. This map
satisfies: for any point `u` in `E`, the point `v = K.orthogonalProjection u` in `K` minimizes the
distance `‖u - v‖` to `u`.
Also a linear isometry equivalence `K.reflection : E ≃ₗᵢ[𝕜] E` is constructed, by choosing, for
each `u : E`, the point `K.reflection u` to satisfy
`u + (K.reflection u) = 2 • K.orthogonalProjection u`.
Basic API for `orthogonalProjection` and `reflection` is developed.
Next, the orthogonal projection is used to prove a series of more subtle lemmas about the
orthogonal complement of complete subspaces of `E` (the orthogonal complement itself was
defined in `Analysis.InnerProductSpace.Orthogonal`); the lemma
`Submodule.sup_orthogonal_of_completeSpace`, stating that for a complete subspace `K` of `E` we have
`K ⊔ Kᗮ = ⊤`, is a typical example.
## References
The orthogonal projection construction is adapted from
* [Clément & Martin, *The Lax-Milgram Theorem. A detailed proof to be formalized in Coq*]
* [Clément & Martin, *A Coq formal proof of the Lax–Milgram theorem*]
The Coq code is available at the following address: <http://www.lri.fr/~sboldo/elfic/index.html>
-/
noncomputable section
open InnerProductSpace
open RCLike Real Filter
open LinearMap (ker range)
open Topology Finsupp
variable {𝕜 E F : Type*} [RCLike 𝕜]
variable [NormedAddCommGroup E] [NormedAddCommGroup F]
variable [InnerProductSpace 𝕜 E] [InnerProductSpace ℝ F]
local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y
local notation "absR" => abs
/-! ### Orthogonal projection in inner product spaces -/
-- FIXME this monolithic proof causes a deterministic timeout with `-T50000`
-- It should be broken in a sequence of more manageable pieces,
-- perhaps with individual statements for the three steps below.
/-- **Existence of minimizers**, aka the **Hilbert projection theorem**.
Let `u` be a point in a real inner product space, and let `K` be a nonempty complete convex subset.
Then there exists a (unique) `v` in `K` that minimizes the distance `‖u - v‖` to `u`. -/
theorem exists_norm_eq_iInf_of_complete_convex {K : Set F} (ne : K.Nonempty) (h₁ : IsComplete K)
(h₂ : Convex ℝ K) : ∀ u : F, ∃ v ∈ K, ‖u - v‖ = ⨅ w : K, ‖u - w‖ := fun u => by
let δ := ⨅ w : K, ‖u - w‖
letI : Nonempty K := ne.to_subtype
have zero_le_δ : 0 ≤ δ := le_ciInf fun _ => norm_nonneg _
have δ_le : ∀ w : K, δ ≤ ‖u - w‖ := ciInf_le ⟨0, Set.forall_mem_range.2 fun _ => norm_nonneg _⟩
have δ_le' : ∀ w ∈ K, δ ≤ ‖u - w‖ := fun w hw => δ_le ⟨w, hw⟩
-- Step 1: since `δ` is the infimum, can find a sequence `w : ℕ → K` in `K`
-- such that `‖u - w n‖ < δ + 1 / (n + 1)` (which implies `‖u - w n‖ --> δ`);
-- maybe this should be a separate lemma
have exists_seq : ∃ w : ℕ → K, ∀ n, ‖u - w n‖ < δ + 1 / (n + 1) := by
have hδ : ∀ n : ℕ, δ < δ + 1 / (n + 1) := fun n =>
lt_add_of_le_of_pos le_rfl Nat.one_div_pos_of_nat
have h := fun n => exists_lt_of_ciInf_lt (hδ n)
let w : ℕ → K := fun n => Classical.choose (h n)
exact ⟨w, fun n => Classical.choose_spec (h n)⟩
rcases exists_seq with ⟨w, hw⟩
have norm_tendsto : Tendsto (fun n => ‖u - w n‖) atTop (𝓝 δ) := by
have h : Tendsto (fun _ : ℕ => δ) atTop (𝓝 δ) := tendsto_const_nhds
have h' : Tendsto (fun n : ℕ => δ + 1 / (n + 1)) atTop (𝓝 δ) := by
convert h.add tendsto_one_div_add_atTop_nhds_zero_nat
simp only [add_zero]
exact tendsto_of_tendsto_of_tendsto_of_le_of_le h h' (fun x => δ_le _) fun x => le_of_lt (hw _)
-- Step 2: Prove that the sequence `w : ℕ → K` is a Cauchy sequence
have seq_is_cauchy : CauchySeq fun n => (w n : F) := by
rw [cauchySeq_iff_le_tendsto_0]
-- splits into three goals
let b := fun n : ℕ => 8 * δ * (1 / (n + 1)) + 4 * (1 / (n + 1)) * (1 / (n + 1))
use fun n => √(b n)
constructor
-- first goal : `∀ (n : ℕ), 0 ≤ √(b n)`
· intro n
exact sqrt_nonneg _
constructor
-- second goal : `∀ (n m N : ℕ), N ≤ n → N ≤ m → dist ↑(w n) ↑(w m) ≤ √(b N)`
· intro p q N hp hq
let wp := (w p : F)
let wq := (w q : F)
let a := u - wq
let b := u - wp
let half := 1 / (2 : ℝ)
let div := 1 / ((N : ℝ) + 1)
have :
4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ + ‖wp - wq‖ * ‖wp - wq‖ =
2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) :=
calc
4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ + ‖wp - wq‖ * ‖wp - wq‖ =
2 * ‖u - half • (wq + wp)‖ * (2 * ‖u - half • (wq + wp)‖) + ‖wp - wq‖ * ‖wp - wq‖ :=
by ring
_ =
absR (2 : ℝ) * ‖u - half • (wq + wp)‖ * (absR (2 : ℝ) * ‖u - half • (wq + wp)‖) +
‖wp - wq‖ * ‖wp - wq‖ := by
rw [abs_of_nonneg]
exact zero_le_two
_ =
‖(2 : ℝ) • (u - half • (wq + wp))‖ * ‖(2 : ℝ) • (u - half • (wq + wp))‖ +
‖wp - wq‖ * ‖wp - wq‖ := by simp [norm_smul]
_ = ‖a + b‖ * ‖a + b‖ + ‖a - b‖ * ‖a - b‖ := by
rw [smul_sub, smul_smul, mul_one_div_cancel (_root_.two_ne_zero : (2 : ℝ) ≠ 0), ←
one_add_one_eq_two, add_smul]
simp only [one_smul]
have eq₁ : wp - wq = a - b := (sub_sub_sub_cancel_left _ _ _).symm
have eq₂ : u + u - (wq + wp) = a + b := by
show u + u - (wq + wp) = u - wq + (u - wp)
abel
rw [eq₁, eq₂]
_ = 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) := parallelogram_law_with_norm ℝ _ _
have eq : δ ≤ ‖u - half • (wq + wp)‖ := by
rw [smul_add]
apply δ_le'
apply h₂
repeat' exact Subtype.mem _
repeat' exact le_of_lt one_half_pos
exact add_halves 1
have eq₁ : 4 * δ * δ ≤ 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ := by
simp_rw [mul_assoc]
gcongr
have eq₂ : ‖a‖ ≤ δ + div :=
le_trans (le_of_lt <| hw q) (add_le_add_left (Nat.one_div_le_one_div hq) _)
have eq₂' : ‖b‖ ≤ δ + div :=
le_trans (le_of_lt <| hw p) (add_le_add_left (Nat.one_div_le_one_div hp) _)
rw [dist_eq_norm]
apply nonneg_le_nonneg_of_sq_le_sq
· exact sqrt_nonneg _
rw [mul_self_sqrt]
· calc
‖wp - wq‖ * ‖wp - wq‖ =
2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) - 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ := by
simp [← this]
_ ≤ 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) - 4 * δ * δ := by gcongr
_ ≤ 2 * ((δ + div) * (δ + div) + (δ + div) * (δ + div)) - 4 * δ * δ := by gcongr
_ = 8 * δ * div + 4 * div * div := by ring
positivity
-- third goal : `Tendsto (fun (n : ℕ) => √(b n)) atTop (𝓝 0)`
suffices Tendsto (fun x ↦ √(8 * δ * x + 4 * x * x) : ℝ → ℝ) (𝓝 0) (𝓝 0)
from this.comp tendsto_one_div_add_atTop_nhds_zero_nat
exact Continuous.tendsto' (by fun_prop) _ _ (by simp)
-- Step 3: By completeness of `K`, let `w : ℕ → K` converge to some `v : K`.
-- Prove that it satisfies all requirements.
rcases cauchySeq_tendsto_of_isComplete h₁ (fun n => Subtype.mem _) seq_is_cauchy with
⟨v, hv, w_tendsto⟩
use v
use hv
have h_cont : Continuous fun v => ‖u - v‖ :=
Continuous.comp continuous_norm (Continuous.sub continuous_const continuous_id)
have : Tendsto (fun n => ‖u - w n‖) atTop (𝓝 ‖u - v‖) := by
convert Tendsto.comp h_cont.continuousAt w_tendsto
exact tendsto_nhds_unique this norm_tendsto
/-- Characterization of minimizers for the projection on a convex set in a real inner product
space. -/
theorem norm_eq_iInf_iff_real_inner_le_zero {K : Set F} (h : Convex ℝ K) {u : F} {v : F}
(hv : v ∈ K) : (‖u - v‖ = ⨅ w : K, ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by
letI : Nonempty K := ⟨⟨v, hv⟩⟩
constructor
· intro eq w hw
let δ := ⨅ w : K, ‖u - w‖
let p := ⟪u - v, w - v⟫_ℝ
let q := ‖w - v‖ ^ 2
have δ_le (w : K) : δ ≤ ‖u - w‖ := ciInf_le ⟨0, fun _ ⟨_, h⟩ => h ▸ norm_nonneg _⟩ _
have δ_le' (w) (hw : w ∈ K) : δ ≤ ‖u - w‖ := δ_le ⟨w, hw⟩
have (θ : ℝ) (hθ₁ : 0 < θ) (hθ₂ : θ ≤ 1) : 2 * p ≤ θ * q := by
have : ‖u - v‖ ^ 2 ≤ ‖u - v‖ ^ 2 - 2 * θ * ⟪u - v, w - v⟫_ℝ + θ * θ * ‖w - v‖ ^ 2 :=
calc ‖u - v‖ ^ 2
_ ≤ ‖u - (θ • w + (1 - θ) • v)‖ ^ 2 := by
simp only [sq]; apply mul_self_le_mul_self (norm_nonneg _)
rw [eq]; apply δ_le'
apply h hw hv
exacts [le_of_lt hθ₁, sub_nonneg.2 hθ₂, add_sub_cancel _ _]
_ = ‖u - v - θ • (w - v)‖ ^ 2 := by
have : u - (θ • w + (1 - θ) • v) = u - v - θ • (w - v) := by
rw [smul_sub, sub_smul, one_smul]
simp only [sub_eq_add_neg, add_comm, add_left_comm, add_assoc, neg_add_rev]
rw [this]
_ = ‖u - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) + θ * θ * ‖w - v‖ ^ 2 := by
rw [@norm_sub_sq ℝ, inner_smul_right, norm_smul]
simp only [sq]
show
‖u - v‖ * ‖u - v‖ - 2 * (θ * inner (u - v) (w - v)) +
absR θ * ‖w - v‖ * (absR θ * ‖w - v‖) =
‖u - v‖ * ‖u - v‖ - 2 * θ * inner (u - v) (w - v) + θ * θ * (‖w - v‖ * ‖w - v‖)
rw [abs_of_pos hθ₁]; ring
have eq₁ :
‖u - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) + θ * θ * ‖w - v‖ ^ 2 =
‖u - v‖ ^ 2 + (θ * θ * ‖w - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v)) := by
abel
rw [eq₁, le_add_iff_nonneg_right] at this
have eq₂ :
θ * θ * ‖w - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) =
θ * (θ * ‖w - v‖ ^ 2 - 2 * inner (u - v) (w - v)) := by ring
rw [eq₂] at this
exact le_of_sub_nonneg (nonneg_of_mul_nonneg_right this hθ₁)
by_cases hq : q = 0
· rw [hq] at this
have : p ≤ 0 := by
have := this (1 : ℝ) (by norm_num) (by norm_num)
linarith
exact this
· have q_pos : 0 < q := lt_of_le_of_ne (sq_nonneg _) fun h ↦ hq h.symm
by_contra hp
rw [not_le] at hp
let θ := min (1 : ℝ) (p / q)
have eq₁ : θ * q ≤ p :=
calc
θ * q ≤ p / q * q := mul_le_mul_of_nonneg_right (min_le_right _ _) (sq_nonneg _)
_ = p := div_mul_cancel₀ _ hq
have : 2 * p ≤ p :=
calc
2 * p ≤ θ * q := by
exact this θ (lt_min (by norm_num) (div_pos hp q_pos)) (by norm_num [θ])
_ ≤ p := eq₁
linarith
· intro h
apply le_antisymm
· apply le_ciInf
intro w
apply nonneg_le_nonneg_of_sq_le_sq (norm_nonneg _)
have := h w w.2
calc
‖u - v‖ * ‖u - v‖ ≤ ‖u - v‖ * ‖u - v‖ - 2 * inner (u - v) ((w : F) - v) := by linarith
_ ≤ ‖u - v‖ ^ 2 - 2 * inner (u - v) ((w : F) - v) + ‖(w : F) - v‖ ^ 2 := by
rw [sq]
refine le_add_of_nonneg_right ?_
exact sq_nonneg _
_ = ‖u - v - (w - v)‖ ^ 2 := (@norm_sub_sq ℝ _ _ _ _ _ _).symm
_ = ‖u - w‖ * ‖u - w‖ := by
have : u - v - (w - v) = u - w := by abel
rw [this, sq]
· show ⨅ w : K, ‖u - w‖ ≤ (fun w : K => ‖u - w‖) ⟨v, hv⟩
apply ciInf_le
use 0
rintro y ⟨z, rfl⟩
exact norm_nonneg _
variable (K : Submodule 𝕜 E)
namespace Submodule
/-- Existence of projections on complete subspaces.
Let `u` be a point in an inner product space, and let `K` be a nonempty complete subspace.
Then there exists a (unique) `v` in `K` that minimizes the distance `‖u - v‖` to `u`.
This point `v` is usually called the orthogonal projection of `u` onto `K`.
-/
theorem exists_norm_eq_iInf_of_complete_subspace (h : IsComplete (↑K : Set E)) :
∀ u : E, ∃ v ∈ K, ‖u - v‖ = ⨅ w : (K : Set E), ‖u - w‖ := by
letI : InnerProductSpace ℝ E := InnerProductSpace.rclikeToReal 𝕜 E
letI : Module ℝ E := RestrictScalars.module ℝ 𝕜 E
let K' : Submodule ℝ E := Submodule.restrictScalars ℝ K
exact exists_norm_eq_iInf_of_complete_convex ⟨0, K'.zero_mem⟩ h K'.convex
/-- Characterization of minimizers in the projection on a subspace, in the real case.
Let `u` be a point in a real inner product space, and let `K` be a nonempty subspace.
Then point `v` minimizes the distance `‖u - v‖` over points in `K` if and only if
for all `w ∈ K`, `⟪u - v, w⟫ = 0` (i.e., `u - v` is orthogonal to the subspace `K`).
This is superseded by `norm_eq_iInf_iff_inner_eq_zero` that gives the same conclusion over
any `RCLike` field.
-/
theorem norm_eq_iInf_iff_real_inner_eq_zero (K : Submodule ℝ F) {u : F} {v : F} (hv : v ∈ K) :
(‖u - v‖ = ⨅ w : (↑K : Set F), ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w⟫_ℝ = 0 :=
Iff.intro
(by
intro h
have h : ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by
rwa [norm_eq_iInf_iff_real_inner_le_zero] at h
exacts [K.convex, hv]
intro w hw
have le : ⟪u - v, w⟫_ℝ ≤ 0 := by
let w' := w + v
have : w' ∈ K := Submodule.add_mem _ hw hv
have h₁ := h w' this
have h₂ : w' - v = w := by
simp only [w', add_neg_cancel_right, sub_eq_add_neg]
rw [h₂] at h₁
exact h₁
have ge : ⟪u - v, w⟫_ℝ ≥ 0 := by
let w'' := -w + v
have : w'' ∈ K := Submodule.add_mem _ (Submodule.neg_mem _ hw) hv
have h₁ := h w'' this
have h₂ : w'' - v = -w := by
simp only [w'', neg_inj, add_neg_cancel_right, sub_eq_add_neg]
rw [h₂, inner_neg_right] at h₁
linarith
exact le_antisymm le ge)
(by
intro h
have : ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by
intro w hw
let w' := w - v
have : w' ∈ K := Submodule.sub_mem _ hw hv
have h₁ := h w' this
exact le_of_eq h₁
rwa [norm_eq_iInf_iff_real_inner_le_zero]
exacts [Submodule.convex _, hv])
/-- Characterization of minimizers in the projection on a subspace.
Let `u` be a point in an inner product space, and let `K` be a nonempty subspace.
Then point `v` minimizes the distance `‖u - v‖` over points in `K` if and only if
for all `w ∈ K`, `⟪u - v, w⟫ = 0` (i.e., `u - v` is orthogonal to the subspace `K`)
-/
theorem norm_eq_iInf_iff_inner_eq_zero {u : E} {v : E} (hv : v ∈ K) :
(‖u - v‖ = ⨅ w : K, ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w⟫ = 0 := by
letI : InnerProductSpace ℝ E := InnerProductSpace.rclikeToReal 𝕜 E
letI : Module ℝ E := RestrictScalars.module ℝ 𝕜 E
let K' : Submodule ℝ E := K.restrictScalars ℝ
constructor
· intro H
have A : ∀ w ∈ K, re ⟪u - v, w⟫ = 0 := (K'.norm_eq_iInf_iff_real_inner_eq_zero hv).1 H
intro w hw
apply RCLike.ext
· simp [A w hw]
· symm
calc
im (0 : 𝕜) = 0 := im.map_zero
_ = re ⟪u - v, (-I : 𝕜) • w⟫ := (A _ (K.smul_mem (-I) hw)).symm
_ = re (-I * ⟪u - v, w⟫) := by rw [inner_smul_right]
_ = im ⟪u - v, w⟫ := by simp
· intro H
have : ∀ w ∈ K', ⟪u - v, w⟫_ℝ = 0 := by
intro w hw
rw [real_inner_eq_re_inner, H w hw]
exact zero_re'
exact (K'.norm_eq_iInf_iff_real_inner_eq_zero hv).2 this
/-- A subspace `K : Submodule 𝕜 E` has an orthogonal projection if every vector `v : E` admits an
orthogonal projection to `K`. -/
class HasOrthogonalProjection (K : Submodule 𝕜 E) : Prop where
exists_orthogonal (v : E) : ∃ w ∈ K, v - w ∈ Kᗮ
instance (priority := 100) HasOrthogonalProjection.ofCompleteSpace [CompleteSpace K] :
K.HasOrthogonalProjection where
exists_orthogonal v := by
rcases K.exists_norm_eq_iInf_of_complete_subspace (completeSpace_coe_iff_isComplete.mp ‹_›) v
with ⟨w, hwK, hw⟩
refine ⟨w, hwK, (K.mem_orthogonal' _).2 ?_⟩
rwa [← K.norm_eq_iInf_iff_inner_eq_zero hwK]
instance [K.HasOrthogonalProjection] : Kᗮ.HasOrthogonalProjection where
exists_orthogonal v := by
rcases HasOrthogonalProjection.exists_orthogonal (K := K) v with ⟨w, hwK, hw⟩
refine ⟨_, hw, ?_⟩
rw [sub_sub_cancel]
exact K.le_orthogonal_orthogonal hwK
instance HasOrthogonalProjection.map_linearIsometryEquiv [K.HasOrthogonalProjection]
{E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') :
(K.map (f.toLinearEquiv : E →ₗ[𝕜] E')).HasOrthogonalProjection where
exists_orthogonal v := by
rcases HasOrthogonalProjection.exists_orthogonal (K := K) (f.symm v) with ⟨w, hwK, hw⟩
refine ⟨f w, Submodule.mem_map_of_mem hwK, Set.forall_mem_image.2 fun u hu ↦ ?_⟩
erw [← f.symm.inner_map_map, f.symm_apply_apply, map_sub, f.symm_apply_apply, hw u hu]
instance HasOrthogonalProjection.map_linearIsometryEquiv' [K.HasOrthogonalProjection]
{E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') :
(K.map f.toLinearIsometry).HasOrthogonalProjection :=
HasOrthogonalProjection.map_linearIsometryEquiv K f
instance : (⊤ : Submodule 𝕜 E).HasOrthogonalProjection := ⟨fun v ↦ ⟨v, trivial, by simp⟩⟩
section orthogonalProjection
variable [K.HasOrthogonalProjection]
/-- The orthogonal projection onto a complete subspace, as an
unbundled function. This definition is only intended for use in
setting up the bundled version `orthogonalProjection` and should not
be used once that is defined. -/
def orthogonalProjectionFn (v : E) :=
(HasOrthogonalProjection.exists_orthogonal (K := K) v).choose
variable {K}
/-- The unbundled orthogonal projection is in the given subspace.
This lemma is only intended for use in setting up the bundled version
and should not be used once that is defined. -/
theorem orthogonalProjectionFn_mem (v : E) : K.orthogonalProjectionFn v ∈ K :=
(HasOrthogonalProjection.exists_orthogonal (K := K) v).choose_spec.left
/-- The characterization of the unbundled orthogonal projection. This
lemma is only intended for use in setting up the bundled version
and should not be used once that is defined. -/
theorem orthogonalProjectionFn_inner_eq_zero (v : E) :
∀ w ∈ K, ⟪v - K.orthogonalProjectionFn v, w⟫ = 0 :=
(K.mem_orthogonal' _).1 (HasOrthogonalProjection.exists_orthogonal (K := K) v).choose_spec.right
/-- The unbundled orthogonal projection is the unique point in `K`
with the orthogonality property. This lemma is only intended for use
in setting up the bundled version and should not be used once that is
defined. -/
theorem eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero {u v : E} (hvm : v ∈ K)
(hvo : ∀ w ∈ K, ⟪u - v, w⟫ = 0) : K.orthogonalProjectionFn u = v := by
rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜]
have hvs : K.orthogonalProjectionFn u - v ∈ K :=
Submodule.sub_mem K (orthogonalProjectionFn_mem u) hvm
have huo : ⟪u - K.orthogonalProjectionFn u, K.orthogonalProjectionFn u - v⟫ = 0 :=
orthogonalProjectionFn_inner_eq_zero u _ hvs
have huv : ⟪u - v, K.orthogonalProjectionFn u - v⟫ = 0 := hvo _ hvs
have houv : ⟪u - v - (u - K.orthogonalProjectionFn u), K.orthogonalProjectionFn u - v⟫ = 0 := by
rw [inner_sub_left, huo, huv, sub_zero]
rwa [sub_sub_sub_cancel_left] at houv
variable (K)
theorem orthogonalProjectionFn_norm_sq (v : E) :
‖v‖ * ‖v‖ =
‖v - K.orthogonalProjectionFn v‖ * ‖v - K.orthogonalProjectionFn v‖ +
‖K.orthogonalProjectionFn v‖ * ‖K.orthogonalProjectionFn v‖ := by
set p := K.orthogonalProjectionFn v
have h' : ⟪v - p, p⟫ = 0 :=
orthogonalProjectionFn_inner_eq_zero _ _ (orthogonalProjectionFn_mem v)
convert norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (v - p) p h' using 2 <;> simp
/-- The orthogonal projection onto a complete subspace. -/
def orthogonalProjection : E →L[𝕜] K :=
LinearMap.mkContinuous
{ toFun := fun v => ⟨K.orthogonalProjectionFn v, orthogonalProjectionFn_mem v⟩
map_add' := fun x y => by
have hm : K.orthogonalProjectionFn x + K.orthogonalProjectionFn y ∈ K :=
Submodule.add_mem K (orthogonalProjectionFn_mem x) (orthogonalProjectionFn_mem y)
have ho :
∀ w ∈ K, ⟪x + y - (K.orthogonalProjectionFn x + K.orthogonalProjectionFn y), w⟫ = 0 := by
intro w hw
rw [add_sub_add_comm, inner_add_left, orthogonalProjectionFn_inner_eq_zero _ w hw,
orthogonalProjectionFn_inner_eq_zero _ w hw, add_zero]
ext
simp [eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hm ho]
map_smul' := fun c x => by
have hm : c • K.orthogonalProjectionFn x ∈ K :=
Submodule.smul_mem K _ (orthogonalProjectionFn_mem x)
have ho : ∀ w ∈ K, ⟪c • x - c • K.orthogonalProjectionFn x, w⟫ = 0 := by
intro w hw
rw [← smul_sub, inner_smul_left, orthogonalProjectionFn_inner_eq_zero _ w hw,
mul_zero]
ext
simp [eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hm ho] }
1 fun x => by
simp only [one_mul, LinearMap.coe_mk]
refine le_of_pow_le_pow_left₀ two_ne_zero (norm_nonneg _) ?_
change ‖K.orthogonalProjectionFn x‖ ^ 2 ≤ ‖x‖ ^ 2
nlinarith [K.orthogonalProjectionFn_norm_sq x]
variable {K}
@[simp]
theorem orthogonalProjectionFn_eq (v : E) :
K.orthogonalProjectionFn v = (K.orthogonalProjection v : E) :=
rfl
/-- The characterization of the orthogonal projection. -/
@[simp]
theorem orthogonalProjection_inner_eq_zero (v : E) :
∀ w ∈ K, ⟪v - K.orthogonalProjection v, w⟫ = 0 :=
orthogonalProjectionFn_inner_eq_zero v
/-- The difference of `v` from its orthogonal projection onto `K` is in `Kᗮ`. -/
@[simp]
theorem sub_orthogonalProjection_mem_orthogonal (v : E) : v - K.orthogonalProjection v ∈ Kᗮ := by
intro w hw
rw [inner_eq_zero_symm]
exact orthogonalProjection_inner_eq_zero _ _ hw
/-- The orthogonal projection is the unique point in `K` with the
orthogonality property. -/
theorem eq_orthogonalProjection_of_mem_of_inner_eq_zero {u v : E} (hvm : v ∈ K)
(hvo : ∀ w ∈ K, ⟪u - v, w⟫ = 0) : (K.orthogonalProjection u : E) = v :=
eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hvm hvo
/-- A point in `K` with the orthogonality property (here characterized in terms of `Kᗮ`) must be the
orthogonal projection. -/
theorem eq_orthogonalProjection_of_mem_orthogonal {u v : E} (hv : v ∈ K)
(hvo : u - v ∈ Kᗮ) : (K.orthogonalProjection u : E) = v :=
eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hv <| (Submodule.mem_orthogonal' _ _).1 hvo
/-- A point in `K` with the orthogonality property (here characterized in terms of `Kᗮ`) must be the
orthogonal projection. -/
theorem eq_orthogonalProjection_of_mem_orthogonal' {u v z : E}
(hv : v ∈ K) (hz : z ∈ Kᗮ) (hu : u = v + z) : (K.orthogonalProjection u : E) = v :=
eq_orthogonalProjection_of_mem_orthogonal hv (by simpa [hu] )
@[simp]
theorem orthogonalProjection_orthogonal_val (u : E) :
(Kᗮ.orthogonalProjection u : E) = u - K.orthogonalProjection u :=
eq_orthogonalProjection_of_mem_orthogonal' (sub_orthogonalProjection_mem_orthogonal _)
(K.le_orthogonal_orthogonal (K.orthogonalProjection u).2) <| by simp
theorem orthogonalProjection_orthogonal (u : E) :
Kᗮ.orthogonalProjection u =
⟨u - K.orthogonalProjection u, sub_orthogonalProjection_mem_orthogonal _⟩ :=
Subtype.eq <| orthogonalProjection_orthogonal_val _
/-- The orthogonal projection of `y` on `U` minimizes the distance `‖y - x‖` for `x ∈ U`. -/
theorem orthogonalProjection_minimal {U : Submodule 𝕜 E} [U.HasOrthogonalProjection] (y : E) :
‖y - U.orthogonalProjection y‖ = ⨅ x : U, ‖y - x‖ := by
rw [U.norm_eq_iInf_iff_inner_eq_zero (Submodule.coe_mem _)]
exact orthogonalProjection_inner_eq_zero _
/-- The orthogonal projections onto equal subspaces are coerced back to the same point in `E`. -/
theorem eq_orthogonalProjection_of_eq_submodule {K' : Submodule 𝕜 E} [K'.HasOrthogonalProjection]
(h : K = K') (u : E) : (K.orthogonalProjection u : E) = (K'.orthogonalProjection u : E) := by
subst h; rfl
/-- The orthogonal projection sends elements of `K` to themselves. -/
@[simp]
theorem orthogonalProjection_mem_subspace_eq_self (v : K) : K.orthogonalProjection v = v := by
ext
apply eq_orthogonalProjection_of_mem_of_inner_eq_zero <;> simp
/-- A point equals its orthogonal projection if and only if it lies in the subspace. -/
theorem orthogonalProjection_eq_self_iff {v : E} : (K.orthogonalProjection v : E) = v ↔ v ∈ K := by
refine ⟨fun h => ?_, fun h => eq_orthogonalProjection_of_mem_of_inner_eq_zero h ?_⟩
· rw [← h]
simp
· simp
@[simp]
theorem orthogonalProjection_eq_zero_iff {v : E} : K.orthogonalProjection v = 0 ↔ v ∈ Kᗮ := by
refine ⟨fun h ↦ ?_, fun h ↦ Subtype.eq <| eq_orthogonalProjection_of_mem_orthogonal
(zero_mem _) ?_⟩
· simpa [h] using sub_orthogonalProjection_mem_orthogonal (K := K) v
· simpa
@[simp]
theorem ker_orthogonalProjection : LinearMap.ker K.orthogonalProjection = Kᗮ := by
ext; exact orthogonalProjection_eq_zero_iff
theorem _root_.LinearIsometry.map_orthogonalProjection {E E' : Type*} [NormedAddCommGroup E]
[NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E →ₗᵢ[𝕜] E')
(p : Submodule 𝕜 E) [p.HasOrthogonalProjection] [(p.map f.toLinearMap).HasOrthogonalProjection]
(x : E) : f (p.orthogonalProjection x) = (p.map f.toLinearMap).orthogonalProjection (f x) := by
refine (eq_orthogonalProjection_of_mem_of_inner_eq_zero ?_ fun y hy => ?_).symm
· refine Submodule.apply_coe_mem_map _ _
rcases hy with ⟨x', hx', rfl : f x' = y⟩
rw [← f.map_sub, f.inner_map_map, orthogonalProjection_inner_eq_zero x x' hx']
theorem _root_.LinearIsometry.map_orthogonalProjection' {E E' : Type*} [NormedAddCommGroup E]
[NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E →ₗᵢ[𝕜] E')
(p : Submodule 𝕜 E) [p.HasOrthogonalProjection] [(p.map f).HasOrthogonalProjection] (x : E) :
f (p.orthogonalProjection x) = (p.map f).orthogonalProjection (f x) :=
have : (p.map f.toLinearMap).HasOrthogonalProjection := ‹_›
f.map_orthogonalProjection p x
/-- Orthogonal projection onto the `Submodule.map` of a subspace. -/
theorem orthogonalProjection_map_apply {E E' : Type*} [NormedAddCommGroup E]
[NormedAddCommGroup E'] [InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E')
(p : Submodule 𝕜 E) [p.HasOrthogonalProjection] (x : E') :
((p.map (f.toLinearEquiv : E →ₗ[𝕜] E')).orthogonalProjection x : E') =
f (p.orthogonalProjection (f.symm x)) := by
simpa only [f.coe_toLinearIsometry, f.apply_symm_apply] using
(f.toLinearIsometry.map_orthogonalProjection' p (f.symm x)).symm
/-- The orthogonal projection onto the trivial submodule is the zero map. -/
@[simp]
theorem orthogonalProjection_bot : (⊥ : Submodule 𝕜 E).orthogonalProjection = 0 := by ext
variable (K)
/-- The orthogonal projection has norm `≤ 1`. -/
theorem orthogonalProjection_norm_le : ‖K.orthogonalProjection‖ ≤ 1 :=
LinearMap.mkContinuous_norm_le _ (by norm_num) _
variable (𝕜)
theorem smul_orthogonalProjection_singleton {v : E} (w : E) :
((‖v‖ ^ 2 : ℝ) : 𝕜) • ((𝕜 ∙ v).orthogonalProjection w : E) = ⟪v, w⟫ • v := by
suffices (((𝕜 ∙ v).orthogonalProjection (((‖v‖ : 𝕜) ^ 2) • w)) : E) = ⟪v, w⟫ • v by
simpa using this
apply eq_orthogonalProjection_of_mem_of_inner_eq_zero
· rw [Submodule.mem_span_singleton]
use ⟪v, w⟫
· rw [← Submodule.mem_orthogonal', Submodule.mem_orthogonal_singleton_iff_inner_left]
simp [inner_sub_left, inner_smul_left, inner_self_eq_norm_sq_to_K, mul_comm]
/-- Formula for orthogonal projection onto a single vector. -/
theorem orthogonalProjection_singleton {v : E} (w : E) :
((𝕜 ∙ v).orthogonalProjection w : E) = (⟪v, w⟫ / ((‖v‖ ^ 2 : ℝ) : 𝕜)) • v := by
by_cases hv : v = 0
· rw [hv, eq_orthogonalProjection_of_eq_submodule (Submodule.span_zero_singleton 𝕜)]
simp
have hv' : ‖v‖ ≠ 0 := ne_of_gt (norm_pos_iff.mpr hv)
have key :
(((‖v‖ ^ 2 : ℝ) : 𝕜)⁻¹ * ((‖v‖ ^ 2 : ℝ) : 𝕜)) • (((𝕜 ∙ v).orthogonalProjection w) : E) =
(((‖v‖ ^ 2 : ℝ) : 𝕜)⁻¹ * ⟪v, w⟫) • v := by
simp [mul_smul, smul_orthogonalProjection_singleton 𝕜 w, -map_pow]
convert key using 1 <;> field_simp [hv']
/-- Formula for orthogonal projection onto a single unit vector. -/
theorem orthogonalProjection_unit_singleton {v : E} (hv : ‖v‖ = 1) (w : E) :
((𝕜 ∙ v).orthogonalProjection w : E) = ⟪v, w⟫ • v := by
rw [← smul_orthogonalProjection_singleton 𝕜 w]
simp [hv]
end orthogonalProjection
section reflection
variable [K.HasOrthogonalProjection]
/-- Auxiliary definition for `reflection`: the reflection as a linear equivalence. -/
def reflectionLinearEquiv : E ≃ₗ[𝕜] E :=
LinearEquiv.ofInvolutive
(2 • (K.subtype.comp K.orthogonalProjection.toLinearMap) - LinearMap.id) fun x => by
simp [two_smul]
/-- Reflection in a complete subspace of an inner product space. The word "reflection" is
sometimes understood to mean specifically reflection in a codimension-one subspace, and sometimes
more generally to cover operations such as reflection in a point. The definition here, of
reflection in a subspace, is a more general sense of the word that includes both those common
cases. -/
def reflection : E ≃ₗᵢ[𝕜] E :=
{ K.reflectionLinearEquiv with
norm_map' := by
intro x
let w : K := K.orthogonalProjection x
let v := x - w
have : ⟪v, w⟫ = 0 := orthogonalProjection_inner_eq_zero x w w.2
convert norm_sub_eq_norm_add this using 2
· rw [LinearEquiv.coe_mk, reflectionLinearEquiv, LinearEquiv.toFun_eq_coe,
LinearEquiv.coe_ofInvolutive, LinearMap.sub_apply, LinearMap.id_apply, two_smul,
LinearMap.add_apply, LinearMap.comp_apply, Submodule.subtype_apply,
ContinuousLinearMap.coe_coe]
dsimp [v]
abel
· simp only [v, add_sub_cancel, eq_self_iff_true] }
variable {K}
/-- The result of reflecting. -/
theorem reflection_apply (p : E) : K.reflection p = 2 • (K.orthogonalProjection p : E) - p :=
rfl
/-- Reflection is its own inverse. -/
@[simp]
theorem reflection_symm : K.reflection.symm = K.reflection :=
rfl
/-- Reflection is its own inverse. -/
@[simp]
theorem reflection_inv : K.reflection⁻¹ = K.reflection :=
rfl
variable (K)
/-- Reflecting twice in the same subspace. -/
@[simp]
theorem reflection_reflection (p : E) : K.reflection (K.reflection p) = p :=
K.reflection.left_inv p
/-- Reflection is involutive. -/
theorem reflection_involutive : Function.Involutive K.reflection :=
K.reflection_reflection
/-- Reflection is involutive. -/
@[simp]
theorem reflection_trans_reflection :
K.reflection.trans K.reflection = LinearIsometryEquiv.refl 𝕜 E :=
LinearIsometryEquiv.ext <| reflection_involutive K
/-- Reflection is involutive. -/
@[simp]
theorem reflection_mul_reflection : K.reflection * K.reflection = 1 :=
reflection_trans_reflection _
theorem reflection_orthogonal_apply (v : E) : Kᗮ.reflection v = -K.reflection v := by
simp [reflection_apply]; abel
theorem reflection_orthogonal : Kᗮ.reflection = .trans K.reflection (.neg _) := by
ext; apply reflection_orthogonal_apply
variable {K}
theorem reflection_singleton_apply (u v : E) :
reflection (𝕜 ∙ u) v = 2 • (⟪u, v⟫ / ((‖u‖ : 𝕜) ^ 2)) • u - v := by
rw [reflection_apply, orthogonalProjection_singleton, ofReal_pow]
/-- A point is its own reflection if and only if it is in the subspace. -/
theorem reflection_eq_self_iff (x : E) : K.reflection x = x ↔ x ∈ K := by
rw [← orthogonalProjection_eq_self_iff, reflection_apply, sub_eq_iff_eq_add', ← two_smul 𝕜,
two_smul ℕ, ← two_smul 𝕜]
refine (smul_right_injective E ?_).eq_iff
exact two_ne_zero
theorem reflection_mem_subspace_eq_self {x : E} (hx : x ∈ K) : K.reflection x = x :=
(reflection_eq_self_iff x).mpr hx
/-- Reflection in the `Submodule.map` of a subspace. -/
theorem reflection_map_apply {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E']
[InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') (K : Submodule 𝕜 E)
[K.HasOrthogonalProjection] (x : E') :
reflection (K.map (f.toLinearEquiv : E →ₗ[𝕜] E')) x = f (K.reflection (f.symm x)) := by
simp [two_smul, reflection_apply, orthogonalProjection_map_apply f K x]
/-- Reflection in the `Submodule.map` of a subspace. -/
theorem reflection_map {E E' : Type*} [NormedAddCommGroup E] [NormedAddCommGroup E']
[InnerProductSpace 𝕜 E] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') (K : Submodule 𝕜 E)
[K.HasOrthogonalProjection] :
reflection (K.map (f.toLinearEquiv : E →ₗ[𝕜] E')) = f.symm.trans (K.reflection.trans f) :=
LinearIsometryEquiv.ext <| reflection_map_apply f K
/-- Reflection through the trivial subspace {0} is just negation. -/
@[simp]
theorem reflection_bot : reflection (⊥ : Submodule 𝕜 E) = LinearIsometryEquiv.neg 𝕜 := by
ext; simp [reflection_apply]
end reflection
end Submodule
section Orthogonal
namespace Submodule
/-- If `K₁` is complete and contained in `K₂`, `K₁` and `K₁ᗮ ⊓ K₂` span `K₂`. -/
theorem sup_orthogonal_inf_of_completeSpace {K₁ K₂ : Submodule 𝕜 E} (h : K₁ ≤ K₂)
[K₁.HasOrthogonalProjection] : K₁ ⊔ K₁ᗮ ⊓ K₂ = K₂ := by
ext x
rw [Submodule.mem_sup]
let v : K₁ := orthogonalProjection K₁ x
have hvm : x - v ∈ K₁ᗮ := sub_orthogonalProjection_mem_orthogonal x
constructor
· rintro ⟨y, hy, z, hz, rfl⟩
exact K₂.add_mem (h hy) hz.2
· exact fun hx => ⟨v, v.prop, x - v, ⟨hvm, K₂.sub_mem hx (h v.prop)⟩, add_sub_cancel _ _⟩
variable {K} in
/-- If `K` is complete, `K` and `Kᗮ` span the whole space. -/
theorem sup_orthogonal_of_completeSpace [K.HasOrthogonalProjection] : K ⊔ Kᗮ = ⊤ := by
convert Submodule.sup_orthogonal_inf_of_completeSpace (le_top : K ≤ ⊤) using 2
simp
/-- If `K` is complete, any `v` in `E` can be expressed as a sum of elements of `K` and `Kᗮ`. -/
theorem exists_add_mem_mem_orthogonal [K.HasOrthogonalProjection] (v : E) :
∃ y ∈ K, ∃ z ∈ Kᗮ, v = y + z :=
⟨K.orthogonalProjection v, Subtype.coe_prop _, v - K.orthogonalProjection v,
sub_orthogonalProjection_mem_orthogonal _, by simp⟩
/-- If `K` admits an orthogonal projection, then the orthogonal complement of its orthogonal
complement is itself. -/
@[simp]
theorem orthogonal_orthogonal [K.HasOrthogonalProjection] : Kᗮᗮ = K := by
ext v
constructor
· obtain ⟨y, hy, z, hz, rfl⟩ := K.exists_add_mem_mem_orthogonal v
intro hv
have hz' : z = 0 := by
have hyz : ⟪z, y⟫ = 0 := by simp [hz y hy, inner_eq_zero_symm]
simpa [inner_add_right, hyz] using hv z hz
simp [hy, hz']
· intro hv w hw
rw [inner_eq_zero_symm]
exact hw v hv
/-- In a Hilbert space, the orthogonal complement of the orthogonal complement of a subspace `K`
is the topological closure of `K`.
Note that the completeness assumption is necessary. Let `E` be the space `ℕ →₀ ℝ` with inner space
structure inherited from `PiLp 2 (fun _ : ℕ ↦ ℝ)`. Let `K` be the subspace of sequences with the sum
of all elements equal to zero. Then `Kᗮ = ⊥`, `Kᗮᗮ = ⊤`. -/
theorem orthogonal_orthogonal_eq_closure [CompleteSpace E] :
Kᗮᗮ = K.topologicalClosure := by
refine le_antisymm ?_ ?_
· convert Submodule.orthogonal_orthogonal_monotone K.le_topologicalClosure using 1
rw [K.topologicalClosure.orthogonal_orthogonal]
· exact K.topologicalClosure_minimal K.le_orthogonal_orthogonal Kᗮ.isClosed_orthogonal
variable {K}
/-- If `K` admits an orthogonal projection, `K` and `Kᗮ` are complements of each other. -/
theorem isCompl_orthogonal_of_completeSpace [K.HasOrthogonalProjection] : IsCompl K Kᗮ :=
⟨K.orthogonal_disjoint, codisjoint_iff.2 Submodule.sup_orthogonal_of_completeSpace⟩
@[simp]
theorem orthogonalComplement_eq_orthogonalComplement {L : Submodule 𝕜 E} [K.HasOrthogonalProjection]
[L.HasOrthogonalProjection] : Kᗮ = Lᗮ ↔ K = L :=
⟨fun h ↦ by simpa using congr(Submodule.orthogonal $(h)),
fun h ↦ congr(Submodule.orthogonal $(h))⟩
@[simp]
theorem orthogonal_eq_bot_iff [K.HasOrthogonalProjection] : Kᗮ = ⊥ ↔ K = ⊤ := by
refine ⟨?_, fun h => by rw [h, Submodule.top_orthogonal_eq_bot]⟩
intro h
have : K ⊔ Kᗮ = ⊤ := Submodule.sup_orthogonal_of_completeSpace
rwa [h, sup_comm, bot_sup_eq] at this
/-- The orthogonal projection onto `K` of an element of `Kᗮ` is zero. -/
theorem orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero [K.HasOrthogonalProjection]
{v : E} (hv : v ∈ Kᗮ) : K.orthogonalProjection v = 0 := by
ext
convert eq_orthogonalProjection_of_mem_orthogonal (K := K) _ _ <;> simp [hv]
/-- The projection into `U` from an orthogonal submodule `V` is the zero map. -/
theorem IsOrtho.orthogonalProjection_comp_subtypeL {U V : Submodule 𝕜 E}
[U.HasOrthogonalProjection] (h : U ⟂ V) : U.orthogonalProjection ∘L V.subtypeL = 0 :=
ContinuousLinearMap.ext fun v =>
orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero <| h.symm v.prop
/-- The projection into `U` from `V` is the zero map if and only if `U` and `V` are orthogonal. -/
theorem orthogonalProjection_comp_subtypeL_eq_zero_iff {U V : Submodule 𝕜 E}
[U.HasOrthogonalProjection] : U.orthogonalProjection ∘L V.subtypeL = 0 ↔ U ⟂ V :=
⟨fun h u hu v hv => by
convert orthogonalProjection_inner_eq_zero v u hu using 2
have : U.orthogonalProjection v = 0 := DFunLike.congr_fun h (⟨_, hv⟩ : V)
rw [this, Submodule.coe_zero, sub_zero], Submodule.IsOrtho.orthogonalProjection_comp_subtypeL⟩
theorem orthogonalProjection_eq_linear_proj [K.HasOrthogonalProjection] (x : E) :
K.orthogonalProjection x =
K.linearProjOfIsCompl _ Submodule.isCompl_orthogonal_of_completeSpace x := by
have : IsCompl K Kᗮ := Submodule.isCompl_orthogonal_of_completeSpace
conv_lhs => rw [← Submodule.linear_proj_add_linearProjOfIsCompl_eq_self this x]
rw [map_add, orthogonalProjection_mem_subspace_eq_self,
orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero (Submodule.coe_mem _), add_zero]
theorem orthogonalProjection_coe_linearMap_eq_linearProj [K.HasOrthogonalProjection] :
(K.orthogonalProjection : E →ₗ[𝕜] K) =
K.linearProjOfIsCompl _ Submodule.isCompl_orthogonal_of_completeSpace :=
LinearMap.ext <| orthogonalProjection_eq_linear_proj
/-- The reflection in `K` of an element of `Kᗮ` is its negation. -/
theorem reflection_mem_subspace_orthogonalComplement_eq_neg [K.HasOrthogonalProjection] {v : E}
(hv : v ∈ Kᗮ) : K.reflection v = -v := by
simp [reflection_apply, orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero hv]
/-- The orthogonal projection onto `Kᗮ` of an element of `K` is zero. -/
theorem orthogonalProjection_mem_subspace_orthogonal_precomplement_eq_zero
[Kᗮ.HasOrthogonalProjection] {v : E} (hv : v ∈ K) : Kᗮ.orthogonalProjection v = 0 :=
orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero (K.le_orthogonal_orthogonal hv)
/-- If `U ≤ V`, then projecting on `V` and then on `U` is the same as projecting on `U`. -/
theorem orthogonalProjection_orthogonalProjection_of_le {U V : Submodule 𝕜 E}
[U.HasOrthogonalProjection] [V.HasOrthogonalProjection] (h : U ≤ V) (x : E) :
U.orthogonalProjection (V.orthogonalProjection x) = U.orthogonalProjection x :=
Eq.symm <| by
simpa only [sub_eq_zero, map_sub] using
orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero
(Submodule.orthogonal_le h (sub_orthogonalProjection_mem_orthogonal x))
/-- Given a monotone family `U` of complete submodules of `E` and a fixed `x : E`,
the orthogonal projection of `x` on `U i` tends to the orthogonal projection of `x` on
`(⨆ i, U i).topologicalClosure` along `atTop`. -/
theorem orthogonalProjection_tendsto_closure_iSup {ι : Type*} [Preorder ι]
(U : ι → Submodule 𝕜 E) [∀ i, (U i).HasOrthogonalProjection]
[(⨆ i, U i).topologicalClosure.HasOrthogonalProjection] (hU : Monotone U) (x : E) :
Filter.Tendsto (fun i => ((U i).orthogonalProjection x : E)) atTop
(𝓝 ((⨆ i, U i).topologicalClosure.orthogonalProjection x : E)) := by
refine .of_neBot_imp fun h ↦ ?_
cases atTop_neBot_iff.mp h
let y := ((⨆ i, U i).topologicalClosure.orthogonalProjection x : E)
have proj_x : ∀ i, (U i).orthogonalProjection x = (U i).orthogonalProjection y := fun i =>
(orthogonalProjection_orthogonalProjection_of_le
((le_iSup U i).trans (iSup U).le_topologicalClosure) _).symm
suffices ∀ ε > 0, ∃ I, ∀ i ≥ I, ‖((U i).orthogonalProjection y : E) - y‖ < ε by
simpa only [proj_x, NormedAddCommGroup.tendsto_atTop] using this
intro ε hε
obtain ⟨a, ha, hay⟩ : ∃ a ∈ ⨆ i, U i, dist y a < ε := by
have y_mem : y ∈ (⨆ i, U i).topologicalClosure := Submodule.coe_mem _
rw [← SetLike.mem_coe, Submodule.topologicalClosure_coe, Metric.mem_closure_iff] at y_mem
exact y_mem ε hε
rw [dist_eq_norm] at hay
obtain ⟨I, hI⟩ : ∃ I, a ∈ U I := by rwa [Submodule.mem_iSup_of_directed _ hU.directed_le] at ha
refine ⟨I, fun i (hi : I ≤ i) => ?_⟩
rw [norm_sub_rev, orthogonalProjection_minimal]
refine lt_of_le_of_lt ?_ hay
change _ ≤ ‖y - (⟨a, hU hi hI⟩ : U i)‖
exact ciInf_le ⟨0, Set.forall_mem_range.mpr fun _ => norm_nonneg _⟩ _
/-- Given a monotone family `U` of complete submodules of `E` with dense span supremum,
and a fixed `x : E`, the orthogonal projection of `x` on `U i` tends to `x` along `at_top`. -/
theorem orthogonalProjection_tendsto_self {ι : Type*} [Preorder ι]
(U : ι → Submodule 𝕜 E) [∀ t, (U t).HasOrthogonalProjection] (hU : Monotone U) (x : E)
(hU' : ⊤ ≤ (⨆ t, U t).topologicalClosure) :
Filter.Tendsto (fun t => ((U t).orthogonalProjection x : E)) atTop (𝓝 x) := by
have : (⨆ i, U i).topologicalClosure.HasOrthogonalProjection := by
rw [top_unique hU']
infer_instance
convert orthogonalProjection_tendsto_closure_iSup U hU x
rw [eq_comm, orthogonalProjection_eq_self_iff, top_unique hU']
trivial
/-- The orthogonal complement satisfies `Kᗮᗮᗮ = Kᗮ`. -/
theorem triorthogonal_eq_orthogonal [CompleteSpace E] : Kᗮᗮᗮ = Kᗮ := by
rw [Kᗮ.orthogonal_orthogonal_eq_closure]
exact K.isClosed_orthogonal.submodule_topologicalClosure_eq
/-- The closure of `K` is the full space iff `Kᗮ` is trivial. -/
theorem topologicalClosure_eq_top_iff [CompleteSpace E] :
K.topologicalClosure = ⊤ ↔ Kᗮ = ⊥ := by
rw [← K.orthogonal_orthogonal_eq_closure]
constructor <;> intro h
· rw [← Submodule.triorthogonal_eq_orthogonal, h, Submodule.top_orthogonal_eq_bot]
· rw [h, Submodule.bot_orthogonal_eq_top]
end Submodule
namespace Dense
/- TODO: Move to another file? -/
open Submodule
variable {K} {x y : E}
theorem eq_zero_of_inner_left (hK : Dense (K : Set E)) (h : ∀ v : K, ⟪x, v⟫ = 0) : x = 0 := by
have : (⟪x, ·⟫) = 0 := (continuous_const.inner continuous_id).ext_on
hK continuous_const (Subtype.forall.1 h)
simpa using congr_fun this x
theorem eq_zero_of_mem_orthogonal (hK : Dense (K : Set E)) (h : x ∈ Kᗮ) : x = 0 :=
eq_zero_of_inner_left hK fun v ↦ (mem_orthogonal' _ _).1 h _ v.2
/-- If `S` is dense and `x - y ∈ Kᗮ`, then `x = y`. -/
theorem eq_of_sub_mem_orthogonal (hK : Dense (K : Set E)) (h : x - y ∈ Kᗮ) : x = y :=
sub_eq_zero.1 <| eq_zero_of_mem_orthogonal hK h
theorem eq_of_inner_left (hK : Dense (K : Set E)) (h : ∀ v : K, ⟪x, v⟫ = ⟪y, v⟫) : x = y :=
hK.eq_of_sub_mem_orthogonal (Submodule.sub_mem_orthogonal_of_inner_left h)
theorem eq_of_inner_right (hK : Dense (K : Set E)) (h : ∀ v : K, ⟪(v : E), x⟫ = ⟪(v : E), y⟫) :
x = y :=
hK.eq_of_sub_mem_orthogonal (Submodule.sub_mem_orthogonal_of_inner_right h)
theorem eq_zero_of_inner_right (hK : Dense (K : Set E)) (h : ∀ v : K, ⟪(v : E), x⟫ = 0) : x = 0 :=
hK.eq_of_inner_right fun v => by rw [inner_zero_right, h v]
end Dense
namespace Submodule
variable {K}
/-- The reflection in `Kᗮ` of an element of `K` is its negation. -/
theorem reflection_mem_subspace_orthogonal_precomplement_eq_neg [K.HasOrthogonalProjection] {v : E}
(hv : v ∈ K) : Kᗮ.reflection v = -v :=
reflection_mem_subspace_orthogonalComplement_eq_neg (K.le_orthogonal_orthogonal hv)
/-- The orthogonal projection onto `(𝕜 ∙ v)ᗮ` of `v` is zero. -/
theorem orthogonalProjection_orthogonalComplement_singleton_eq_zero (v : E) :
(𝕜 ∙ v)ᗮ.orthogonalProjection v = 0 :=
orthogonalProjection_mem_subspace_orthogonal_precomplement_eq_zero
(Submodule.mem_span_singleton_self v)
/-- The reflection in `(𝕜 ∙ v)ᗮ` of `v` is `-v`. -/
| Mathlib/Analysis/InnerProductSpace/Projection.lean | 967 | 972 | theorem reflection_orthogonalComplement_singleton_eq_neg (v : E) : reflection (𝕜 ∙ v)ᗮ v = -v :=
reflection_mem_subspace_orthogonal_precomplement_eq_neg (Submodule.mem_span_singleton_self v)
theorem reflection_sub {v w : F} (h : ‖v‖ = ‖w‖) : reflection (ℝ ∙ (v - w))ᗮ v = w := by | set R : F ≃ₗᵢ[ℝ] F := reflection (ℝ ∙ v - w)ᗮ
suffices R v + R v = w + w by |
/-
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.Basic
import Mathlib.Tactic.Bound.Attribute
import Mathlib.Topology.Algebra.InfiniteSum.Module
/-!
# 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`.
* `AnalyticOnNhd 𝕜 f s`: the function `f` is analytic at every point of `s`.
We also define versions of `HasFPowerSeriesOnBall`, `AnalyticAt`, and `AnalyticOnNhd` restricted to
a set, similar to `ContinuousWithinAt`. See `Mathlib.Analysis.Analytic.Within` for basic properties.
* `AnalyticWithinAt 𝕜 f s x` means a power series at `x` converges to `f` on `𝓝[s ∪ {x}] x`.
* `AnalyticOn 𝕜 f s t` means `∀ x ∈ t, AnalyticWithinAt 𝕜 f s x`.
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`.
## 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 Topology NNReal Filter ENNReal Set Asymptotics
namespace FormalMultilinearSeries
variable [Semiring 𝕜] [AddCommMonoid E] [AddCommMonoid F] [Module 𝕜 E] [Module 𝕜 F]
variable [TopologicalSpace E] [TopologicalSpace F]
variable [ContinuousAdd E] [ContinuousAdd 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
/-- 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
/-- 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
fun_prop
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∞)
/-- 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
/-- 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
/-- 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)
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
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 _ => h.le_tsum' _
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
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)
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
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 _⟩
@[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])
/-- `0` has infinite radius of convergence -/
@[simp] lemma zero_radius : (0 : FormalMultilinearSeries 𝕜 E F).radius = ∞ := by
rw [← constFormalMultilinearSeries_zero]
exact 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
/-- 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
/-- 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
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)⟩
/-- 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
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_iff_of_pos_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)
/-- 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)⟩
/-- 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)⟩
/-- 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⟩
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 _)
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
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)
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 _)
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
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
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
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)
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
/-- 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 : _) (_ : 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 => ?_⟩
rw [inv_pow, ← div_eq_mul_inv]
exact hCp n
lemma radius_le_of_le {𝕜' E' F' : Type*}
[NontriviallyNormedField 𝕜'] [NormedAddCommGroup E'] [NormedSpace 𝕜' E']
[NormedAddCommGroup F'] [NormedSpace 𝕜' F']
{p : FormalMultilinearSeries 𝕜 E F} {q : FormalMultilinearSeries 𝕜' E' F'}
(h : ∀ n, ‖p n‖ ≤ ‖q n‖) : q.radius ≤ p.radius := by
apply le_of_forall_nnreal_lt (fun r hr ↦ ?_)
rcases norm_mul_pow_le_of_lt_radius _ hr with ⟨C, -, hC⟩
apply le_radius_of_bound _ C (fun n ↦ ?_)
apply le_trans _ (hC n)
gcongr
exact h n
/-- 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 _)
@[simp]
theorem radius_neg (p : FormalMultilinearSeries 𝕜 E F) : (-p).radius = p.radius := by
simp only [radius, neg_apply, norm_neg]
theorem radius_le_smul {p : FormalMultilinearSeries 𝕜 E F} {c : 𝕜} : p.radius ≤ (c • p).radius := by
simp only [radius, smul_apply]
refine iSup_mono fun r ↦ iSup_mono' fun C ↦ ⟨‖c‖ * C, iSup_mono' fun h ↦ ?_⟩
simp only [le_refl, exists_prop, and_true]
intro n
rw [norm_smul c (p n), mul_assoc]
gcongr
exact h n
theorem radius_smul_eq (p : FormalMultilinearSeries 𝕜 E F) {c : 𝕜} (hc : c ≠ 0) :
(c • p).radius = p.radius := by
apply eq_of_le_of_le _ radius_le_smul
exact radius_le_smul.trans_eq (congr_arg _ <| inv_smul_smul₀ hc p)
@[simp]
theorem radius_shift (p : FormalMultilinearSeries 𝕜 E F) : p.shift.radius = p.radius := by
simp only [radius, shift, Nat.succ_eq_add_one, ContinuousMultilinearMap.curryRight_norm]
congr
ext r
apply eq_of_le_of_le
· apply iSup_mono'
intro C
use ‖p 0‖ ⊔ (C * r)
apply iSup_mono'
intro h
simp only [le_refl, le_sup_iff, exists_prop, and_true]
intro n
rcases n with - | m
· simp
right
rw [pow_succ, ← mul_assoc]
apply mul_le_mul_of_nonneg_right (h m) zero_le_coe
· apply iSup_mono'
intro C
use ‖p 1‖ ⊔ C / r
apply iSup_mono'
intro h
simp only [le_refl, le_sup_iff, exists_prop, and_true]
intro n
cases eq_zero_or_pos r with
| inl hr =>
rw [hr]
cases n <;> simp
| inr hr =>
right
rw [← NNReal.coe_pos] at hr
specialize h (n + 1)
rw [le_div_iff₀ hr]
rwa [pow_succ, ← mul_assoc] at h
@[simp]
theorem radius_unshift (p : FormalMultilinearSeries 𝕜 E (E →L[𝕜] F)) (z : F) :
(p.unshift z).radius = p.radius := by
rw [← radius_shift, unshift_shift]
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
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)
end FormalMultilinearSeries
/-! ### Expanding a function as a power series -/
section
variable {f g : E → F} {p pf : FormalMultilinearSeries 𝕜 E F} {s t : Set E} {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))
/-- Analogue of `HasFPowerSeriesOnBall` where convergence is required only on a set `s`. We also
require convergence at `x` as the behavior of this notion is very bad otherwise. -/
structure HasFPowerSeriesWithinOnBall (f : E → F) (p : FormalMultilinearSeries 𝕜 E F) (s : Set E)
(x : E) (r : ℝ≥0∞) : Prop where
/-- `p` converges on `ball 0 r` -/
r_le : r ≤ p.radius
/-- The radius of convergence is positive -/
r_pos : 0 < r
/-- `p converges to f` within `s` -/
hasSum : ∀ {y}, x + y ∈ insert x s → y ∈ EMetric.ball (0 : E) r →
HasSum (fun n : ℕ => p n fun _ : Fin n => y) (f (x + y))
/-- 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
/-- Analogue of `HasFPowerSeriesAt` where convergence is required only on a set `s`. -/
def HasFPowerSeriesWithinAt (f : E → F) (p : FormalMultilinearSeries 𝕜 E F) (s : Set E) (x : E) :=
∃ r, HasFPowerSeriesWithinOnBall f p s x r
-- Teach the `bound` tactic that power series have positive radius
attribute [bound_forward] HasFPowerSeriesOnBall.r_pos HasFPowerSeriesWithinOnBall.r_pos
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`. -/
@[fun_prop]
def AnalyticAt (f : E → F) (x : E) :=
∃ p : FormalMultilinearSeries 𝕜 E F, HasFPowerSeriesAt f p x
/-- `f` is analytic within `s` at `x` if it has a power series at `x` that converges on `𝓝[s] x` -/
def AnalyticWithinAt (f : E → F) (s : Set E) (x : E) : Prop :=
∃ p : FormalMultilinearSeries 𝕜 E F, HasFPowerSeriesWithinAt f p s x
/-- 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 AnalyticOnNhd (f : E → F) (s : Set E) :=
∀ x, x ∈ s → AnalyticAt 𝕜 f x
/-- `f` is analytic within `s` if it is analytic within `s` at each point of `s`. Note that
this is weaker than `AnalyticOnNhd 𝕜 f s`, as `f` is allowed to be arbitrary outside `s`. -/
def AnalyticOn (f : E → F) (s : Set E) : Prop :=
∀ x ∈ s, AnalyticWithinAt 𝕜 f s x
/-!
### `HasFPowerSeriesOnBall` and `HasFPowerSeriesWithinOnBall`
-/
variable {𝕜}
theorem HasFPowerSeriesOnBall.hasFPowerSeriesAt (hf : HasFPowerSeriesOnBall f p x r) :
HasFPowerSeriesAt f p x :=
⟨r, hf⟩
theorem HasFPowerSeriesAt.analyticAt (hf : HasFPowerSeriesAt f p x) : AnalyticAt 𝕜 f x :=
⟨p, hf⟩
theorem HasFPowerSeriesOnBall.analyticAt (hf : HasFPowerSeriesOnBall f p x r) : AnalyticAt 𝕜 f x :=
hf.hasFPowerSeriesAt.analyticAt
theorem HasFPowerSeriesWithinOnBall.hasFPowerSeriesWithinAt
(hf : HasFPowerSeriesWithinOnBall f p s x r) : HasFPowerSeriesWithinAt f p s x :=
⟨r, hf⟩
theorem HasFPowerSeriesWithinAt.analyticWithinAt (hf : HasFPowerSeriesWithinAt f p s x) :
AnalyticWithinAt 𝕜 f s x := ⟨p, hf⟩
theorem HasFPowerSeriesWithinOnBall.analyticWithinAt (hf : HasFPowerSeriesWithinOnBall f p s x r) :
AnalyticWithinAt 𝕜 f s x :=
hf.hasFPowerSeriesWithinAt.analyticWithinAt
/-- 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 }
theorem HasFPowerSeriesWithinOnBall.hasSum_sub (hf : HasFPowerSeriesWithinOnBall f p s x r) {y : E}
(hy : y ∈ (insert x s) ∩ 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_enorm_sub] using hy.2
have := hf.hasSum (by simpa only [add_sub_cancel] using hy.1) this
simpa only [add_sub_cancel]
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_enorm_sub] using hy
simpa only [add_sub_cancel] using hf.hasSum this
theorem HasFPowerSeriesOnBall.radius_pos (hf : HasFPowerSeriesOnBall f p x r) : 0 < p.radius :=
lt_of_lt_of_le hf.r_pos hf.r_le
theorem HasFPowerSeriesWithinOnBall.radius_pos (hf : HasFPowerSeriesWithinOnBall f p s x r) :
0 < p.radius :=
lt_of_lt_of_le hf.r_pos hf.r_le
theorem HasFPowerSeriesAt.radius_pos (hf : HasFPowerSeriesAt f p x) : 0 < p.radius :=
let ⟨_, hr⟩ := hf
hr.radius_pos
theorem HasFPowerSeriesWithinOnBall.of_le
(hf : HasFPowerSeriesWithinOnBall f p s x r) (r'_pos : 0 < r') (hr : r' ≤ r) :
HasFPowerSeriesWithinOnBall f p s x r' :=
⟨le_trans hr hf.1, r'_pos, fun hy h'y => hf.hasSum hy (EMetric.ball_subset_ball hr h'y)⟩
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)⟩
lemma HasFPowerSeriesWithinOnBall.congr {f g : E → F} {p : FormalMultilinearSeries 𝕜 E F}
{s : Set E} {x : E} {r : ℝ≥0∞} (h : HasFPowerSeriesWithinOnBall f p s x r)
(h' : EqOn g f (s ∩ EMetric.ball x r)) (h'' : g x = f x) :
HasFPowerSeriesWithinOnBall g p s x r := by
refine ⟨h.r_le, h.r_pos, ?_⟩
intro y hy h'y
convert h.hasSum hy h'y using 1
simp only [mem_insert_iff, add_eq_left] at hy
rcases hy with rfl | hy
· simpa using h''
· apply h'
refine ⟨hy, ?_⟩
simpa [edist_eq_enorm_sub] using h'y
/-- Variant of `HasFPowerSeriesWithinOnBall.congr` in which one requests equality on `insert x s`
instead of separating `x` and `s`. -/
lemma HasFPowerSeriesWithinOnBall.congr' {f g : E → F} {p : FormalMultilinearSeries 𝕜 E F}
{s : Set E} {x : E} {r : ℝ≥0∞} (h : HasFPowerSeriesWithinOnBall f p s x r)
(h' : EqOn g f (insert x s ∩ EMetric.ball x r)) :
HasFPowerSeriesWithinOnBall g p s x r := by
refine ⟨h.r_le, h.r_pos, fun {y} hy h'y ↦ ?_⟩
convert h.hasSum hy h'y using 1
exact h' ⟨hy, by simpa [edist_eq_enorm_sub] using h'y⟩
lemma HasFPowerSeriesWithinAt.congr {f g : E → F} {p : FormalMultilinearSeries 𝕜 E F} {s : Set E}
{x : E} (h : HasFPowerSeriesWithinAt f p s x) (h' : g =ᶠ[𝓝[s] x] f) (h'' : g x = f x) :
HasFPowerSeriesWithinAt g p s x := by
rcases h with ⟨r, hr⟩
obtain ⟨ε, εpos, hε⟩ : ∃ ε > 0, EMetric.ball x ε ∩ s ⊆ {y | g y = f y} :=
EMetric.mem_nhdsWithin_iff.1 h'
let r' := min r ε
refine ⟨r', ?_⟩
have := hr.of_le (r' := r') (by simp [r', εpos, hr.r_pos]) (min_le_left _ _)
apply this.congr _ h''
intro z hz
exact hε ⟨EMetric.ball_subset_ball (min_le_right _ _) hz.2, hz.1⟩
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_enorm_sub] using hy }
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)⟩
theorem HasFPowerSeriesWithinOnBall.unique (hf : HasFPowerSeriesWithinOnBall f p s x r)
(hg : HasFPowerSeriesWithinOnBall g p s x r) :
(insert x s ∩ EMetric.ball x r).EqOn f g := fun _ hy ↦
(hf.hasSum_sub hy).unique (hg.hasSum_sub hy)
theorem HasFPowerSeriesOnBall.unique (hf : HasFPowerSeriesOnBall f p x r)
(hg : HasFPowerSeriesOnBall g p x r) : (EMetric.ball x r).EqOn f g := fun _ hy ↦
(hf.hasSum_sub hy).unique (hg.hasSum_sub hy)
protected theorem HasFPowerSeriesWithinAt.eventually (hf : HasFPowerSeriesWithinAt f p s x) :
∀ᶠ r : ℝ≥0∞ in 𝓝[>] 0, HasFPowerSeriesWithinOnBall f p s x r :=
let ⟨_, hr⟩ := hf
mem_of_superset (Ioo_mem_nhdsGT hr.r_pos) fun _ hr' => hr.of_le hr'.1 hr'.2.le
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_nhdsGT hr.r_pos) fun _ hr' => hr.mono hr'.1 hr'.2.le
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
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
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
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
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
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
@[simp] lemma hasFPowerSeriesWithinOnBall_univ :
HasFPowerSeriesWithinOnBall f p univ x r ↔ HasFPowerSeriesOnBall f p x r := by
constructor
· intro h
refine ⟨h.r_le, h.r_pos, fun {y} m ↦ h.hasSum (by simp) m⟩
· intro h
exact ⟨h.r_le, h.r_pos, fun {y} _ m => h.hasSum m⟩
@[simp] lemma hasFPowerSeriesWithinAt_univ :
HasFPowerSeriesWithinAt f p univ x ↔ HasFPowerSeriesAt f p x := by
simp only [HasFPowerSeriesWithinAt, hasFPowerSeriesWithinOnBall_univ, HasFPowerSeriesAt]
lemma HasFPowerSeriesWithinOnBall.mono (hf : HasFPowerSeriesWithinOnBall f p s x r) (h : t ⊆ s) :
HasFPowerSeriesWithinOnBall f p t x r where
r_le := hf.r_le
r_pos := hf.r_pos
hasSum hy h'y := hf.hasSum (insert_subset_insert h hy) h'y
lemma HasFPowerSeriesOnBall.hasFPowerSeriesWithinOnBall (hf : HasFPowerSeriesOnBall f p x r) :
HasFPowerSeriesWithinOnBall f p s x r := by
rw [← hasFPowerSeriesWithinOnBall_univ] at hf
exact hf.mono (subset_univ _)
lemma HasFPowerSeriesWithinAt.mono (hf : HasFPowerSeriesWithinAt f p s x) (h : t ⊆ s) :
HasFPowerSeriesWithinAt f p t x := by
obtain ⟨r, hp⟩ := hf
exact ⟨r, hp.mono h⟩
lemma HasFPowerSeriesAt.hasFPowerSeriesWithinAt (hf : HasFPowerSeriesAt f p x) :
HasFPowerSeriesWithinAt f p s x := by
rw [← hasFPowerSeriesWithinAt_univ] at hf
apply hf.mono (subset_univ _)
theorem HasFPowerSeriesWithinAt.mono_of_mem_nhdsWithin
(h : HasFPowerSeriesWithinAt f p s x) (hst : s ∈ 𝓝[t] x) :
HasFPowerSeriesWithinAt f p t x := by
rcases h with ⟨r, hr⟩
rcases EMetric.mem_nhdsWithin_iff.1 hst with ⟨r', r'_pos, hr'⟩
refine ⟨min r r', ?_⟩
have Z := hr.of_le (by simp [r'_pos, hr.r_pos]) (min_le_left r r')
refine ⟨Z.r_le, Z.r_pos, fun {y} hy h'y ↦ ?_⟩
apply Z.hasSum ?_ h'y
simp only [mem_insert_iff, add_eq_left] at hy
rcases hy with rfl | hy
· simp
apply mem_insert_of_mem _ (hr' ?_)
simp only [EMetric.mem_ball, edist_eq_enorm_sub, sub_zero, lt_min_iff, mem_inter_iff,
add_sub_cancel_left, hy, and_true] at h'y ⊢
exact h'y.2
@[deprecated (since := "2024-10-31")]
alias HasFPowerSeriesWithinAt.mono_of_mem := HasFPowerSeriesWithinAt.mono_of_mem_nhdsWithin
@[simp] lemma hasFPowerSeriesWithinOnBall_insert_self :
HasFPowerSeriesWithinOnBall f p (insert x s) x r ↔ HasFPowerSeriesWithinOnBall f p s x r := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ <;>
exact ⟨h.r_le, h.r_pos, fun {y} ↦ by simpa only [insert_idem] using h.hasSum (y := y)⟩
@[simp] theorem hasFPowerSeriesWithinAt_insert {y : E} :
HasFPowerSeriesWithinAt f p (insert y s) x ↔ HasFPowerSeriesWithinAt f p s x := by
rcases eq_or_ne x y with rfl | hy
· simp [HasFPowerSeriesWithinAt]
· refine ⟨fun h ↦ h.mono (subset_insert _ _), fun h ↦ ?_⟩
apply HasFPowerSeriesWithinAt.mono_of_mem_nhdsWithin h
rw [nhdsWithin_insert_of_ne hy]
exact self_mem_nhdsWithin
theorem HasFPowerSeriesWithinOnBall.coeff_zero (hf : HasFPowerSeriesWithinOnBall f pf s 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 _ => 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 (by simp) zero_mem).unique (hasSum_single _ this)
simpa [v_eq] using A.symm
theorem HasFPowerSeriesOnBall.coeff_zero (hf : HasFPowerSeriesOnBall f pf x r)
(v : Fin 0 → E) : pf 0 v = f x := by
rw [← hasFPowerSeriesWithinOnBall_univ] at hf
exact hf.coeff_zero v
theorem HasFPowerSeriesWithinAt.coeff_zero (hf : HasFPowerSeriesWithinAt f pf s x) (v : Fin 0 → E) :
pf 0 v = f x :=
let ⟨_, hrf⟩ := hf
hrf.coeff_zero v
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
/-!
### Analytic functions
-/
@[simp] theorem analyticOn_empty : AnalyticOn 𝕜 f ∅ := by intro; simp
@[simp] theorem analyticOnNhd_empty : AnalyticOnNhd 𝕜 f ∅ := by intro; simp
@[simp] lemma analyticWithinAt_univ :
AnalyticWithinAt 𝕜 f univ x ↔ AnalyticAt 𝕜 f x := by
simp [AnalyticWithinAt, AnalyticAt]
@[simp] lemma analyticOn_univ {f : E → F} :
AnalyticOn 𝕜 f univ ↔ AnalyticOnNhd 𝕜 f univ := by
simp only [AnalyticOn, analyticWithinAt_univ, AnalyticOnNhd]
lemma AnalyticWithinAt.mono (hf : AnalyticWithinAt 𝕜 f s x) (h : t ⊆ s) :
AnalyticWithinAt 𝕜 f t x := by
obtain ⟨p, hp⟩ := hf
exact ⟨p, hp.mono h⟩
lemma AnalyticAt.analyticWithinAt (hf : AnalyticAt 𝕜 f x) : AnalyticWithinAt 𝕜 f s x := by
rw [← analyticWithinAt_univ] at hf
apply hf.mono (subset_univ _)
lemma AnalyticOnNhd.analyticOn (hf : AnalyticOnNhd 𝕜 f s) : AnalyticOn 𝕜 f s :=
fun x hx ↦ (hf x hx).analyticWithinAt
lemma AnalyticWithinAt.congr_of_eventuallyEq {f g : E → F} {s : Set E} {x : E}
(hf : AnalyticWithinAt 𝕜 f s x) (hs : g =ᶠ[𝓝[s] x] f) (hx : g x = f x) :
AnalyticWithinAt 𝕜 g s x := by
rcases hf with ⟨p, hp⟩
exact ⟨p, hp.congr hs hx⟩
lemma AnalyticWithinAt.congr_of_eventuallyEq_insert {f g : E → F} {s : Set E} {x : E}
(hf : AnalyticWithinAt 𝕜 f s x) (hs : g =ᶠ[𝓝[insert x s] x] f) :
AnalyticWithinAt 𝕜 g s x := by
apply hf.congr_of_eventuallyEq (nhdsWithin_mono x (subset_insert x s) hs)
apply mem_of_mem_nhdsWithin (mem_insert x s) hs
lemma AnalyticWithinAt.congr {f g : E → F} {s : Set E} {x : E}
(hf : AnalyticWithinAt 𝕜 f s x) (hs : EqOn g f s) (hx : g x = f x) :
AnalyticWithinAt 𝕜 g s x :=
hf.congr_of_eventuallyEq hs.eventuallyEq_nhdsWithin hx
lemma AnalyticOn.congr {f g : E → F} {s : Set E}
(hf : AnalyticOn 𝕜 f s) (hs : EqOn g f s) :
AnalyticOn 𝕜 g s :=
fun x m ↦ (hf x m).congr hs (hs m)
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 AnalyticOnNhd.mono {s t : Set E} (hf : AnalyticOnNhd 𝕜 f t) (hst : s ⊆ t) :
AnalyticOnNhd 𝕜 f s :=
fun z hz => hf z (hst hz)
theorem AnalyticOnNhd.congr' (hf : AnalyticOnNhd 𝕜 f s) (hg : f =ᶠ[𝓝ˢ s] g) :
AnalyticOnNhd 𝕜 g s :=
fun z hz => (hf z hz).congr (mem_nhdsSet_iff_forall.mp hg z hz)
theorem analyticOnNhd_congr' (h : f =ᶠ[𝓝ˢ s] g) : AnalyticOnNhd 𝕜 f s ↔ AnalyticOnNhd 𝕜 g s :=
⟨fun hf => hf.congr' h, fun hg => hg.congr' h.symm⟩
theorem AnalyticOnNhd.congr (hs : IsOpen s) (hf : AnalyticOnNhd 𝕜 f s) (hg : s.EqOn f g) :
AnalyticOnNhd 𝕜 g s :=
hf.congr' <| mem_nhdsSet_iff_forall.mpr
(fun _ hz => eventuallyEq_iff_exists_mem.mpr ⟨s, hs.mem_nhds hz, hg⟩)
theorem analyticOnNhd_congr (hs : IsOpen s) (h : s.EqOn f g) : AnalyticOnNhd 𝕜 f s ↔
AnalyticOnNhd 𝕜 g s := ⟨fun hf => hf.congr hs h, fun hg => hg.congr hs h.symm⟩
theorem AnalyticWithinAt.mono_of_mem_nhdsWithin
(h : AnalyticWithinAt 𝕜 f s x) (hst : s ∈ 𝓝[t] x) : AnalyticWithinAt 𝕜 f t x := by
rcases h with ⟨p, hp⟩
exact ⟨p, hp.mono_of_mem_nhdsWithin hst⟩
@[deprecated (since := "2024-10-31")]
alias AnalyticWithinAt.mono_of_mem := AnalyticWithinAt.mono_of_mem_nhdsWithin
lemma AnalyticOn.mono {f : E → F} {s t : Set E} (h : AnalyticOn 𝕜 f t)
(hs : s ⊆ t) : AnalyticOn 𝕜 f s :=
fun _ m ↦ (h _ (hs m)).mono hs
@[simp] theorem analyticWithinAt_insert {f : E → F} {s : Set E} {x y : E} :
AnalyticWithinAt 𝕜 f (insert y s) x ↔ AnalyticWithinAt 𝕜 f s x := by
simp [AnalyticWithinAt]
/-!
### Composition with linear maps
-/
/-- If a function `f` has a power series `p` on a ball within a set and `g` is linear,
then `g ∘ f` has the power series `g ∘ p` on the same ball. -/
theorem ContinuousLinearMap.comp_hasFPowerSeriesWithinOnBall (g : F →L[𝕜] G)
(h : HasFPowerSeriesWithinOnBall f p s x r) :
HasFPowerSeriesWithinOnBall (g ∘ f) (g.compFormalMultilinearSeries p) s x r where
r_le := h.r_le.trans (p.radius_le_radius_continuousLinearMap_comp _)
r_pos := h.r_pos
hasSum hy h'y := by
simpa only [ContinuousLinearMap.compFormalMultilinearSeries_apply,
ContinuousLinearMap.compContinuousMultilinearMap_coe, Function.comp_apply] using
g.hasSum (h.hasSum hy h'y)
/-- 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 := by
rw [← hasFPowerSeriesWithinOnBall_univ] at h ⊢
exact g.comp_hasFPowerSeriesWithinOnBall h
/-- 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 (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_hasFPowerSeriesWithinOnBall hp⟩
/-- If a function `f` is analytic on a set `s` and `g` is linear, then `g ∘ f` is analytic
on `s`. -/
theorem ContinuousLinearMap.comp_analyticOnNhd
{s : Set E} (g : F →L[𝕜] G) (h : AnalyticOnNhd 𝕜 f s) :
AnalyticOnNhd 𝕜 (g ∘ f) s := by
rintro x hx
rcases h x hx with ⟨p, r, hp⟩
exact ⟨g.compFormalMultilinearSeries p, r, g.comp_hasFPowerSeriesOnBall hp⟩
/-!
### Relation between analytic function and the partial sums of its power series
-/
theorem HasFPowerSeriesWithinOnBall.tendsto_partialSum
(hf : HasFPowerSeriesWithinOnBall f p s x r) {y : E} (hy : y ∈ EMetric.ball (0 : E) r)
(h'y : x + y ∈ insert x s) :
Tendsto (fun n => p.partialSum n y) atTop (𝓝 (f (x + y))) :=
(hf.hasSum h'y hy).tendsto_sum_nat
theorem HasFPowerSeriesOnBall.tendsto_partialSum
(hf : HasFPowerSeriesOnBall f p x r) {y : E} (hy : y ∈ EMetric.ball (0 : E) r) :
Tendsto (fun n => p.partialSum n y) atTop (𝓝 (f (x + y))) :=
(hf.hasSum hy).tendsto_sum_nat
theorem HasFPowerSeriesAt.tendsto_partialSum
(hf : HasFPowerSeriesAt f p x) :
∀ᶠ y in 𝓝 0, Tendsto (fun n => p.partialSum n y) atTop (𝓝 (f (x + y))) := by
rcases hf with ⟨r, hr⟩
filter_upwards [EMetric.ball_mem_nhds (0 : E) hr.r_pos] with y hy
exact hr.tendsto_partialSum hy
open Finset in
/-- If a function admits a power series expansion within a ball, then the partial sums
`p.partialSum n z` converge to `f (x + y)` as `n → ∞` and `z → y`. Note that `x + z` doesn't need
to belong to the set where the power series expansion holds. -/
theorem HasFPowerSeriesWithinOnBall.tendsto_partialSum_prod {y : E}
(hf : HasFPowerSeriesWithinOnBall f p s x r) (hy : y ∈ EMetric.ball (0 : E) r)
(h'y : x + y ∈ insert x s) :
Tendsto (fun (z : ℕ × E) ↦ p.partialSum z.1 z.2) (atTop ×ˢ 𝓝 y) (𝓝 (f (x + y))) := by
have A : Tendsto (fun (z : ℕ × E) ↦ p.partialSum z.1 y) (atTop ×ˢ 𝓝 y) (𝓝 (f (x + y))) := by
apply (hf.tendsto_partialSum hy h'y).comp tendsto_fst
suffices Tendsto (fun (z : ℕ × E) ↦ p.partialSum z.1 z.2 - p.partialSum z.1 y)
(atTop ×ˢ 𝓝 y) (𝓝 0) by simpa using A.add this
apply Metric.tendsto_nhds.2 (fun ε εpos ↦ ?_)
obtain ⟨r', yr', r'r⟩ : ∃ (r' : ℝ≥0), ‖y‖₊ < r' ∧ r' < r := by
simp [edist_zero_eq_enorm] at hy
simpa using ENNReal.lt_iff_exists_nnreal_btwn.1 hy
have yr'_2 : ‖y‖ < r' := by simpa [← coe_nnnorm] using yr'
have S : Summable fun n ↦ ‖p n‖ * ↑r' ^ n := p.summable_norm_mul_pow (r'r.trans_le hf.r_le)
obtain ⟨k, hk⟩ : ∃ k, ∑' (n : ℕ), ‖p (n + k)‖ * ↑r' ^ (n + k) < ε / 4 := by
have : Tendsto (fun k ↦ ∑' n, ‖p (n + k)‖ * ↑r' ^ (n + k)) atTop (𝓝 0) := by
apply _root_.tendsto_sum_nat_add (f := fun n ↦ ‖p n‖ * ↑r' ^ n)
exact ((tendsto_order.1 this).2 _ (by linarith)).exists
have A : ∀ᶠ (z : ℕ × E) in atTop ×ˢ 𝓝 y,
dist (p.partialSum k z.2) (p.partialSum k y) < ε / 4 := by
have : ContinuousAt (fun z ↦ p.partialSum k z) y := (p.partialSum_continuous k).continuousAt
exact tendsto_snd (Metric.tendsto_nhds.1 this.tendsto (ε / 4) (by linarith))
have B : ∀ᶠ (z : ℕ × E) in atTop ×ˢ 𝓝 y, ‖z.2‖₊ < r' := by
suffices ∀ᶠ (z : E) in 𝓝 y, ‖z‖₊ < r' from tendsto_snd this
have : Metric.ball 0 r' ∈ 𝓝 y := Metric.isOpen_ball.mem_nhds (by simpa using yr'_2)
filter_upwards [this] with a ha using by simpa [← coe_nnnorm] using ha
have C : ∀ᶠ (z : ℕ × E) in atTop ×ˢ 𝓝 y, k ≤ z.1 := tendsto_fst (Ici_mem_atTop _)
filter_upwards [A, B, C]
rintro ⟨n, z⟩ hz h'z hkn
simp only [dist_eq_norm, sub_zero] at hz ⊢
have I (w : E) (hw : ‖w‖₊ < r') : ‖∑ i ∈ Ico k n, p i (fun _ ↦ w)‖ ≤ ε / 4 := calc
‖∑ i ∈ Ico k n, p i (fun _ ↦ w)‖
_ = ‖∑ i ∈ range (n - k), p (i + k) (fun _ ↦ w)‖ := by
rw [sum_Ico_eq_sum_range]
congr with i
rw [add_comm k]
_ ≤ ∑ i ∈ range (n - k), ‖p (i + k) (fun _ ↦ w)‖ := norm_sum_le _ _
_ ≤ ∑ i ∈ range (n - k), ‖p (i + k)‖ * ‖w‖ ^ (i + k) := by
gcongr with i _hi; exact ((p (i + k)).le_opNorm _).trans_eq (by simp)
_ ≤ ∑ i ∈ range (n - k), ‖p (i + k)‖ * ↑r' ^ (i + k) := by
gcongr with i _hi; simpa [← coe_nnnorm] using hw.le
_ ≤ ∑' i, ‖p (i + k)‖ * ↑r' ^ (i + k) := by
apply Summable.sum_le_tsum _ (fun i _hi ↦ by positivity)
apply ((_root_.summable_nat_add_iff k).2 S)
_ ≤ ε / 4 := hk.le
calc
‖p.partialSum n z - p.partialSum n y‖
_ = ‖∑ i ∈ range n, p i (fun _ ↦ z) - ∑ i ∈ range n, p i (fun _ ↦ y)‖ := rfl
_ = ‖(∑ i ∈ range k, p i (fun _ ↦ z) + ∑ i ∈ Ico k n, p i (fun _ ↦ z))
- (∑ i ∈ range k, p i (fun _ ↦ y) + ∑ i ∈ Ico k n, p i (fun _ ↦ y))‖ := by
simp [sum_range_add_sum_Ico _ hkn]
_ = ‖(p.partialSum k z - p.partialSum k y) + (∑ i ∈ Ico k n, p i (fun _ ↦ z))
+ (- ∑ i ∈ Ico k n, p i (fun _ ↦ y))‖ := by
congr 1
simp only [FormalMultilinearSeries.partialSum]
abel
_ ≤ ‖p.partialSum k z - p.partialSum k y‖ + ‖∑ i ∈ Ico k n, p i (fun _ ↦ z)‖
+ ‖- ∑ i ∈ Ico k n, p i (fun _ ↦ y)‖ := norm_add₃_le
_ ≤ ε / 4 + ε / 4 + ε / 4 := by
gcongr
· exact I _ h'z
· simp only [norm_neg]; exact I _ yr'
_ < ε := by linarith
/-- If a function admits a power series on a ball, then the partial sums
`p.partialSum n z` converges to `f (x + y)` as `n → ∞` and `z → y`. -/
theorem HasFPowerSeriesOnBall.tendsto_partialSum_prod {y : E}
(hf : HasFPowerSeriesOnBall f p x r) (hy : y ∈ EMetric.ball (0 : E) r) :
Tendsto (fun (z : ℕ × E) ↦ p.partialSum z.1 z.2) (atTop ×ˢ 𝓝 y) (𝓝 (f (x + y))) :=
(hf.hasFPowerSeriesWithinOnBall (s := univ)).tendsto_partialSum_prod hy (by simp)
/-- 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
`HasFPowerSeriesWithinOnBall.uniform_geometric_approx` for a weaker version. -/
theorem HasFPowerSeriesWithinOnBall.uniform_geometric_approx' {r' : ℝ≥0}
(hf : HasFPowerSeriesWithinOnBall f p s x r) (h : (r' : ℝ≥0∞) < r) :
∃ a ∈ Ioo (0 : ℝ) 1, ∃ C > 0, ∀ y ∈ Metric.ball (0 : E) r', ∀ n, x + y ∈ insert x s →
‖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 ys => ?_⟩
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)
simpa [enorm] using 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 ys 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]
/-- 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
rw [← hasFPowerSeriesWithinOnBall_univ] at hf
simpa using hf.uniform_geometric_approx' h
/-- If a function admits a power series expansion within a set in a ball, then it is exponentially
close to the partial sums of this power series on strict subdisks of the disk of convergence. -/
theorem HasFPowerSeriesWithinOnBall.uniform_geometric_approx {r' : ℝ≥0}
(hf : HasFPowerSeriesWithinOnBall f p s x r) (h : (r' : ℝ≥0∞) < r) :
∃ a ∈ Ioo (0 : ℝ) 1,
∃ C > 0, ∀ y ∈ Metric.ball (0 : E) r', ∀ n, x + y ∈ insert x s →
‖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,
x + y ∈ insert x s → ‖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 ys => (hp y hy n ys).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)
/-- 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
rw [← hasFPowerSeriesWithinOnBall_univ] at hf
simpa using hf.uniform_geometric_approx h
/-- Taylor formula for an analytic function within a set, `IsBigO` version. -/
theorem HasFPowerSeriesWithinAt.isBigO_sub_partialSum_pow
(hf : HasFPowerSeriesWithinAt f p s x) (n : ℕ) :
(fun y : E => f (x + y) - p.partialSum n y)
=O[𝓝[(x + ·)⁻¹' insert x s] 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,
x + y ∈ insert x s → ‖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 [inter_mem_nhdsWithin _ (Metric.ball_mem_nhds (0 : E) r'0)] with y hy
simpa [mul_pow, mul_div_assoc, mul_assoc, div_mul_eq_mul_div, div_pow]
using hp y hy.2 n (by simpa using hy.1)
/-- 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
rw [← hasFPowerSeriesWithinAt_univ] at hf
simpa using hf.isBigO_sub_partialSum_pow n
/-- If `f` has formal power series `∑ n, pₙ` in a set, within 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 HasFPowerSeriesWithinOnBall.isBigO_image_sub_image_sub_deriv_principal
(hf : HasFPowerSeriesWithinOnBall f p s 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' ∩ ((insert x s) ×ˢ (insert x s)))]
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 [ENNReal.coe_zero, EMetric.ball_zero, empty_inter, principal_empty, isBigO_bot]
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' ∩ ((insert x s) ×ˢ (insert x s)),
‖f y.1 - f y.2 - p 1 fun _ => y.1 - y.2‖ ≤ L y := by
intro y ⟨hy', ys⟩
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 ⟨ys.1, hy.1⟩).sub (hf.hasSum_sub ⟨ys.2, 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_update_sub,
← Pi.single, Subsingleton.pi_single_eq, sub_sub_sub_cancel_right]
rw [EMetric.mem_ball, edist_eq_enorm_sub, enorm_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
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
_ ≤ 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
((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' ∩ ((insert x s) ×ˢ (insert x s)))]
fun y => ‖y - (x, x)‖ * ‖y.1 - y.2‖ from
.trans (.of_norm_eventuallyLE (eventually_principal.2 hL)) this
simp_rw [L, mul_right_comm _ (_ * _)]
exact (isBigO_refl _ _).const_mul_left _
/-- 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
rw [← hasFPowerSeriesWithinOnBall_univ] at hf
simpa using hf.isBigO_image_sub_image_sub_deriv_principal hr
/-- If `f` has formal power series `∑ n, pₙ` within a set, 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 HasFPowerSeriesWithinOnBall.image_sub_sub_deriv_le
(hf : HasFPowerSeriesWithinOnBall f p s x r) (hr : r' < r) :
∃ C, ∀ᵉ (y ∈ insert x s ∩ EMetric.ball x r') (z ∈ insert x s ∩ EMetric.ball x r'),
‖f y - f z - p 1 fun _ => y - z‖ ≤ C * max ‖y - x‖ ‖z - x‖ * ‖y - z‖ := by
have := hf.isBigO_image_sub_image_sub_deriv_principal hr
simp only [isBigO_principal, mem_inter_iff, EMetric.mem_ball, Prod.edist_eq, max_lt_iff, mem_prod,
norm_mul, Real.norm_eq_abs, abs_norm, and_imp, Prod.forall, mul_assoc] at this ⊢
rcases this with ⟨C, hC⟩
exact ⟨C, fun y ys hy z zs hz ↦ hC y z hy hz ys zs⟩
/-- 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‖`. -/
| Mathlib/Analysis/Analytic/Basic.lean | 1,142 | 1,148 | 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 | rw [← hasFPowerSeriesWithinOnBall_univ] at hf
simpa only [mem_univ, insert_eq_of_mem, univ_inter] using hf.image_sub_sub_deriv_le hr |
/-
Copyright (c) 2021 Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard, Ines Wright, Joachim Breitner
-/
import Mathlib.GroupTheory.Solvable
import Mathlib.GroupTheory.Sylow
import Mathlib.Algebra.Group.Subgroup.Order
import Mathlib.GroupTheory.Commutator.Finite
/-!
# Nilpotent groups
An API for nilpotent groups, that is, groups for which the upper central series
reaches `⊤`.
## Main definitions
Recall that if `H K : Subgroup G` then `⁅H, K⁆ : Subgroup G` is the subgroup of `G` generated
by the commutators `hkh⁻¹k⁻¹`. Recall also Lean's conventions that `⊤` denotes the
subgroup `G` of `G`, and `⊥` denotes the trivial subgroup `{1}`.
* `upperCentralSeries G : ℕ → Subgroup G` : the upper central series of a group `G`.
This is an increasing sequence of normal subgroups `H n` of `G` with `H 0 = ⊥` and
`H (n + 1) / H n` is the centre of `G / H n`.
* `lowerCentralSeries G : ℕ → Subgroup G` : the lower central series of a group `G`.
This is a decreasing sequence of normal subgroups `H n` of `G` with `H 0 = ⊤` and
`H (n + 1) = ⁅H n, G⁆`.
* `IsNilpotent` : A group G is nilpotent if its upper central series reaches `⊤`, or
equivalently if its lower central series reaches `⊥`.
* `Group.nilpotencyClass` : the length of the upper central series of a nilpotent group.
* `IsAscendingCentralSeries (H : ℕ → Subgroup G) : Prop` and
* `IsDescendingCentralSeries (H : ℕ → Subgroup G) : Prop` : Note that in the literature
a "central series" for a group is usually defined to be a *finite* sequence of normal subgroups
`H 0`, `H 1`, ..., starting at `⊤`, finishing at `⊥`, and with each `H n / H (n + 1)`
central in `G / H (n + 1)`. In this formalisation it is convenient to have two weaker predicates
on an infinite sequence of subgroups `H n` of `G`: we say a sequence is a *descending central
series* if it starts at `G` and `⁅H n, ⊤⁆ ⊆ H (n + 1)` for all `n`. Note that this series
may not terminate at `⊥`, and the `H i` need not be normal. Similarly a sequence is an
*ascending central series* if `H 0 = ⊥` and `⁅H (n + 1), ⊤⁆ ⊆ H n` for all `n`, again with no
requirement that the series reaches `⊤` or that the `H i` are normal.
## Main theorems
`G` is *defined* to be nilpotent if the upper central series reaches `⊤`.
* `nilpotent_iff_finite_ascending_central_series` : `G` is nilpotent iff some ascending central
series reaches `⊤`.
* `nilpotent_iff_finite_descending_central_series` : `G` is nilpotent iff some descending central
series reaches `⊥`.
* `nilpotent_iff_lower` : `G` is nilpotent iff the lower central series reaches `⊥`.
* The `Group.nilpotencyClass` can likewise be obtained from these equivalent
definitions, see `least_ascending_central_series_length_eq_nilpotencyClass`,
`least_descending_central_series_length_eq_nilpotencyClass` and
`lowerCentralSeries_length_eq_nilpotencyClass`.
* If `G` is nilpotent, then so are its subgroups, images, quotients and preimages.
Binary and finite products of nilpotent groups are nilpotent.
Infinite products are nilpotent if their nilpotent class is bounded.
Corresponding lemmas about the `Group.nilpotencyClass` are provided.
* The `Group.nilpotencyClass` of `G ⧸ center G` is given explicitly, and an induction principle
is derived from that.
* `IsNilpotent.to_isSolvable`: If `G` is nilpotent, it is solvable.
## Warning
A "central series" is usually defined to be a finite sequence of normal subgroups going
from `⊥` to `⊤` with the property that each subquotient is contained within the centre of
the associated quotient of `G`. This means that if `G` is not nilpotent, then
none of what we have called `upperCentralSeries G`, `lowerCentralSeries G` or
the sequences satisfying `IsAscendingCentralSeries` or `IsDescendingCentralSeries`
are actually central series. Note that the fact that the upper and lower central series
are not central series if `G` is not nilpotent is a standard abuse of notation.
-/
open Subgroup
section WithGroup
variable {G : Type*} [Group G] (H : Subgroup G) [Normal H]
/-- If `H` is a normal subgroup of `G`, then the set `{x : G | ∀ y : G, x*y*x⁻¹*y⁻¹ ∈ H}`
is a subgroup of `G` (because it is the preimage in `G` of the centre of the
quotient group `G/H`.)
-/
def upperCentralSeriesStep : Subgroup G where
carrier := { x : G | ∀ y : G, x * y * x⁻¹ * y⁻¹ ∈ H }
one_mem' y := by simp [Subgroup.one_mem]
mul_mem' {a b} ha hb y := by
convert Subgroup.mul_mem _ (ha (b * y * b⁻¹)) (hb y) using 1
group
inv_mem' {x} hx y := by
specialize hx y⁻¹
rw [mul_assoc, inv_inv] at hx ⊢
exact Subgroup.Normal.mem_comm inferInstance hx
theorem mem_upperCentralSeriesStep (x : G) :
x ∈ upperCentralSeriesStep H ↔ ∀ y, x * y * x⁻¹ * y⁻¹ ∈ H := Iff.rfl
open QuotientGroup
/-- The proof that `upperCentralSeriesStep H` is the preimage of the centre of `G/H` under
the canonical surjection. -/
theorem upperCentralSeriesStep_eq_comap_center :
upperCentralSeriesStep H = Subgroup.comap (mk' H) (center (G ⧸ H)) := by
ext
rw [mem_comap, mem_center_iff, forall_mk]
apply forall_congr'
intro y
rw [coe_mk', ← QuotientGroup.mk_mul, ← QuotientGroup.mk_mul, eq_comm, eq_iff_div_mem,
div_eq_mul_inv, mul_inv_rev, mul_assoc]
instance : Normal (upperCentralSeriesStep H) := by
rw [upperCentralSeriesStep_eq_comap_center]
infer_instance
variable (G)
/-- An auxiliary type-theoretic definition defining both the upper central series of
a group, and a proof that it is normal, all in one go. -/
def upperCentralSeriesAux : ℕ → Σ'H : Subgroup G, Normal H
| 0 => ⟨⊥, inferInstance⟩
| n + 1 =>
let un := upperCentralSeriesAux n
let _un_normal := un.2
⟨upperCentralSeriesStep un.1, inferInstance⟩
/-- `upperCentralSeries G n` is the `n`th term in the upper central series of `G`. -/
def upperCentralSeries (n : ℕ) : Subgroup G :=
(upperCentralSeriesAux G n).1
instance upperCentralSeries_normal (n : ℕ) : Normal (upperCentralSeries G n) :=
(upperCentralSeriesAux G n).2
@[simp]
theorem upperCentralSeries_zero : upperCentralSeries G 0 = ⊥ := rfl
@[simp]
theorem upperCentralSeries_one : upperCentralSeries G 1 = center G := by
ext
simp only [upperCentralSeries, upperCentralSeriesAux, upperCentralSeriesStep,
Subgroup.mem_center_iff, mem_mk, mem_bot, Set.mem_setOf_eq]
exact forall_congr' fun y => by rw [mul_inv_eq_one, mul_inv_eq_iff_eq_mul, eq_comm]
variable {G}
/-- The `n+1`st term of the upper central series `H i` has underlying set equal to the `x` such
that `⁅x,G⁆ ⊆ H n`. -/
theorem mem_upperCentralSeries_succ_iff {n : ℕ} {x : G} :
x ∈ upperCentralSeries G (n + 1) ↔ ∀ y : G, x * y * x⁻¹ * y⁻¹ ∈ upperCentralSeries G n :=
Iff.rfl
@[simp] lemma comap_upperCentralSeries {H : Type*} [Group H] (e : H ≃* G) :
∀ n, (upperCentralSeries G n).comap e = upperCentralSeries H n
| 0 => by simpa [MonoidHom.ker_eq_bot_iff] using e.injective
| n + 1 => by
ext
simp [mem_upperCentralSeries_succ_iff, ← comap_upperCentralSeries e n,
← e.toEquiv.forall_congr_right]
namespace Group
variable (G) in
-- `IsNilpotent` is already defined in the root namespace (for elements of rings).
-- TODO: Rename it to `IsNilpotentElement`?
/-- A group `G` is nilpotent if its upper central series is eventually `G`. -/
@[mk_iff]
class IsNilpotent (G : Type*) [Group G] : Prop where
nilpotent' : ∃ n : ℕ, upperCentralSeries G n = ⊤
lemma IsNilpotent.nilpotent (G : Type*) [Group G] [IsNilpotent G] :
∃ n : ℕ, upperCentralSeries G n = ⊤ := Group.IsNilpotent.nilpotent'
lemma isNilpotent_congr {H : Type*} [Group H] (e : G ≃* H) : IsNilpotent G ↔ IsNilpotent H := by
simp_rw [isNilpotent_iff]
refine exists_congr fun n ↦ ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· simp [← Subgroup.comap_top e.symm.toMonoidHom, ← h]
· simp [← Subgroup.comap_top e.toMonoidHom, ← h]
@[simp] lemma isNilpotent_top : IsNilpotent (⊤ : Subgroup G) ↔ IsNilpotent G :=
isNilpotent_congr Subgroup.topEquiv
variable (G) in
/-- A group `G` is virtually nilpotent if it has a nilpotent cofinite subgroup `N`. -/
def IsVirtuallyNilpotent : Prop := ∃ N : Subgroup G, IsNilpotent N ∧ FiniteIndex N
lemma IsNilpotent.isVirtuallyNilpotent (hG : IsNilpotent G) : IsVirtuallyNilpotent G :=
⟨⊤, by simpa, inferInstance⟩
end Group
open Group
/-- A sequence of subgroups of `G` is an ascending central series if `H 0` is trivial and
`⁅H (n + 1), G⁆ ⊆ H n` for all `n`. Note that we do not require that `H n = G` for some `n`. -/
def IsAscendingCentralSeries (H : ℕ → Subgroup G) : Prop :=
H 0 = ⊥ ∧ ∀ (x : G) (n : ℕ), x ∈ H (n + 1) → ∀ g, x * g * x⁻¹ * g⁻¹ ∈ H n
/-- A sequence of subgroups of `G` is a descending central series if `H 0` is `G` and
`⁅H n, G⁆ ⊆ H (n + 1)` for all `n`. Note that we do not require that `H n = {1}` for some `n`. -/
def IsDescendingCentralSeries (H : ℕ → Subgroup G) :=
H 0 = ⊤ ∧ ∀ (x : G) (n : ℕ), x ∈ H n → ∀ g, x * g * x⁻¹ * g⁻¹ ∈ H (n + 1)
/-- Any ascending central series for a group is bounded above by the upper central series. -/
theorem ascending_central_series_le_upper (H : ℕ → Subgroup G) (hH : IsAscendingCentralSeries H) :
∀ n : ℕ, H n ≤ upperCentralSeries G n
| 0 => hH.1.symm ▸ le_refl ⊥
| n + 1 => by
intro x hx
rw [mem_upperCentralSeries_succ_iff]
exact fun y => ascending_central_series_le_upper H hH n (hH.2 x n hx y)
variable (G)
/-- The upper central series of a group is an ascending central series. -/
theorem upperCentralSeries_isAscendingCentralSeries :
IsAscendingCentralSeries (upperCentralSeries G) :=
⟨rfl, fun _x _n h => h⟩
theorem upperCentralSeries_mono : Monotone (upperCentralSeries G) := by
refine monotone_nat_of_le_succ ?_
intro n x hx y
rw [mul_assoc, mul_assoc, ← mul_assoc y x⁻¹ y⁻¹]
exact mul_mem hx (Normal.conj_mem (upperCentralSeries_normal G n) x⁻¹ (inv_mem hx) y)
/-- A group `G` is nilpotent iff there exists an ascending central series which reaches `G` in
finitely many steps. -/
theorem nilpotent_iff_finite_ascending_central_series :
IsNilpotent G ↔ ∃ n : ℕ, ∃ H : ℕ → Subgroup G, IsAscendingCentralSeries H ∧ H n = ⊤ := by
constructor
· rintro ⟨n, nH⟩
exact ⟨_, _, upperCentralSeries_isAscendingCentralSeries G, nH⟩
· rintro ⟨n, H, hH, hn⟩
use n
rw [eq_top_iff, ← hn]
exact ascending_central_series_le_upper H hH n
theorem is_descending_rev_series_of_is_ascending {H : ℕ → Subgroup G} {n : ℕ} (hn : H n = ⊤)
(hasc : IsAscendingCentralSeries H) : IsDescendingCentralSeries fun m : ℕ => H (n - m) := by
obtain ⟨h0, hH⟩ := hasc
refine ⟨hn, fun x m hx g => ?_⟩
dsimp at hx
by_cases hm : n ≤ m
· rw [tsub_eq_zero_of_le hm, h0, Subgroup.mem_bot] at hx
subst hx
rw [show (1 : G) * g * (1⁻¹ : G) * g⁻¹ = 1 by group]
exact Subgroup.one_mem _
· push_neg at hm
apply hH
convert hx using 1
rw [tsub_add_eq_add_tsub (Nat.succ_le_of_lt hm), Nat.succ_eq_add_one, Nat.add_sub_add_right]
@[deprecated (since := "2024-12-25")]
alias is_decending_rev_series_of_is_ascending := is_descending_rev_series_of_is_ascending
theorem is_ascending_rev_series_of_is_descending {H : ℕ → Subgroup G} {n : ℕ} (hn : H n = ⊥)
(hdesc : IsDescendingCentralSeries H) : IsAscendingCentralSeries fun m : ℕ => H (n - m) := by
obtain ⟨h0, hH⟩ := hdesc
refine ⟨hn, fun x m hx g => ?_⟩
dsimp only at hx ⊢
by_cases hm : n ≤ m
· have hnm : n - m = 0 := tsub_eq_zero_iff_le.mpr hm
rw [hnm, h0]
exact mem_top _
· push_neg at hm
convert hH x _ hx g using 1
rw [tsub_add_eq_add_tsub (Nat.succ_le_of_lt hm), Nat.succ_eq_add_one, Nat.add_sub_add_right]
/-- A group `G` is nilpotent iff there exists a descending central series which reaches the
trivial group in a finite time. -/
theorem nilpotent_iff_finite_descending_central_series :
IsNilpotent G ↔ ∃ n : ℕ, ∃ H : ℕ → Subgroup G, IsDescendingCentralSeries H ∧ H n = ⊥ := by
rw [nilpotent_iff_finite_ascending_central_series]
constructor
· rintro ⟨n, H, hH, hn⟩
refine ⟨n, fun m => H (n - m), is_descending_rev_series_of_is_ascending G hn hH, ?_⟩
dsimp only
rw [tsub_self]
exact hH.1
· rintro ⟨n, H, hH, hn⟩
refine ⟨n, fun m => H (n - m), is_ascending_rev_series_of_is_descending G hn hH, ?_⟩
dsimp only
rw [tsub_self]
exact hH.1
/-- The lower central series of a group `G` is a sequence `H n` of subgroups of `G`, defined
by `H 0` is all of `G` and for `n≥1`, `H (n + 1) = ⁅H n, G⁆` -/
def lowerCentralSeries (G : Type*) [Group G] : ℕ → Subgroup G
| 0 => ⊤
| n + 1 => ⁅lowerCentralSeries G n, ⊤⁆
variable {G}
@[simp]
theorem lowerCentralSeries_zero : lowerCentralSeries G 0 = ⊤ := rfl
@[simp]
theorem lowerCentralSeries_one : lowerCentralSeries G 1 = commutator G := rfl
theorem mem_lowerCentralSeries_succ_iff (n : ℕ) (q : G) :
q ∈ lowerCentralSeries G (n + 1) ↔
q ∈ closure { x | ∃ p ∈ lowerCentralSeries G n,
∃ q ∈ (⊤ : Subgroup G), p * q * p⁻¹ * q⁻¹ = x } := Iff.rfl
theorem lowerCentralSeries_succ (n : ℕ) :
lowerCentralSeries G (n + 1) =
closure { x | ∃ p ∈ lowerCentralSeries G n, ∃ q ∈ (⊤ : Subgroup G), p * q * p⁻¹ * q⁻¹ = x } :=
rfl
instance lowerCentralSeries_normal (n : ℕ) : Normal (lowerCentralSeries G n) := by
induction' n with d hd
· exact (⊤ : Subgroup G).normal_of_characteristic
· exact @Subgroup.commutator_normal _ _ (lowerCentralSeries G d) ⊤ hd _
theorem lowerCentralSeries_antitone : Antitone (lowerCentralSeries G) := by
refine antitone_nat_of_succ_le fun n x hx => ?_
simp only [mem_lowerCentralSeries_succ_iff, exists_prop, mem_top, exists_true_left,
true_and] at hx
refine
closure_induction ?_ (Subgroup.one_mem _) (fun _ _ _ _ ↦ mul_mem) (fun _ _ ↦ inv_mem) hx
rintro y ⟨z, hz, a, ha⟩
rw [← ha, mul_assoc, mul_assoc, ← mul_assoc a z⁻¹ a⁻¹]
exact mul_mem hz (Normal.conj_mem (lowerCentralSeries_normal n) z⁻¹ (inv_mem hz) a)
/-- The lower central series of a group is a descending central series. -/
theorem lowerCentralSeries_isDescendingCentralSeries :
IsDescendingCentralSeries (lowerCentralSeries G) := by
constructor
· rfl
intro x n hxn g
exact commutator_mem_commutator hxn (mem_top g)
/-- Any descending central series for a group is bounded below by the lower central series. -/
theorem descending_central_series_ge_lower (H : ℕ → Subgroup G) (hH : IsDescendingCentralSeries H) :
∀ n : ℕ, lowerCentralSeries G n ≤ H n
| 0 => hH.1.symm ▸ le_refl ⊤
| n + 1 => commutator_le.mpr fun x hx q _ =>
hH.2 x n (descending_central_series_ge_lower H hH n hx) q
/-- A group is nilpotent if and only if its lower central series eventually reaches
the trivial subgroup. -/
theorem nilpotent_iff_lowerCentralSeries : IsNilpotent G ↔ ∃ n, lowerCentralSeries G n = ⊥ := by
rw [nilpotent_iff_finite_descending_central_series]
constructor
· rintro ⟨n, H, ⟨h0, hs⟩, hn⟩
use n
rw [eq_bot_iff, ← hn]
exact descending_central_series_ge_lower H ⟨h0, hs⟩ n
· rintro ⟨n, hn⟩
exact ⟨n, lowerCentralSeries G, lowerCentralSeries_isDescendingCentralSeries, hn⟩
section Classical
variable [hG : IsNilpotent G]
variable (G) in
open scoped Classical in
/-- The nilpotency class of a nilpotent group is the smallest natural `n` such that
the `n`'th term of the upper central series is `G`. -/
noncomputable def Group.nilpotencyClass : ℕ := Nat.find (IsNilpotent.nilpotent G)
open scoped Classical in
@[simp]
theorem upperCentralSeries_nilpotencyClass : upperCentralSeries G (Group.nilpotencyClass G) = ⊤ :=
Nat.find_spec (IsNilpotent.nilpotent G)
theorem upperCentralSeries_eq_top_iff_nilpotencyClass_le {n : ℕ} :
upperCentralSeries G n = ⊤ ↔ Group.nilpotencyClass G ≤ n := by
classical
constructor
· intro h
exact Nat.find_le h
· intro h
rw [eq_top_iff, ← upperCentralSeries_nilpotencyClass]
exact upperCentralSeries_mono _ h
open scoped Classical in
/-- The nilpotency class of a nilpotent `G` is equal to the smallest `n` for which an ascending
central series reaches `G` in its `n`'th term. -/
theorem least_ascending_central_series_length_eq_nilpotencyClass :
Nat.find ((nilpotent_iff_finite_ascending_central_series G).mp hG) =
Group.nilpotencyClass G := by
refine le_antisymm (Nat.find_mono ?_) (Nat.find_mono ?_)
· intro n hn
exact ⟨upperCentralSeries G, upperCentralSeries_isAscendingCentralSeries G, hn⟩
· rintro n ⟨H, ⟨hH, hn⟩⟩
rw [← top_le_iff, ← hn]
exact ascending_central_series_le_upper H hH n
open scoped Classical in
/-- The nilpotency class of a nilpotent `G` is equal to the smallest `n` for which the descending
central series reaches `⊥` in its `n`'th term. -/
theorem least_descending_central_series_length_eq_nilpotencyClass :
Nat.find ((nilpotent_iff_finite_descending_central_series G).mp hG) =
Group.nilpotencyClass G := by
rw [← least_ascending_central_series_length_eq_nilpotencyClass]
refine le_antisymm (Nat.find_mono ?_) (Nat.find_mono ?_)
· rintro n ⟨H, ⟨hH, hn⟩⟩
refine ⟨fun m => H (n - m), is_descending_rev_series_of_is_ascending G hn hH, ?_⟩
dsimp only
rw [tsub_self]
exact hH.1
· rintro n ⟨H, ⟨hH, hn⟩⟩
refine ⟨fun m => H (n - m), is_ascending_rev_series_of_is_descending G hn hH, ?_⟩
dsimp only
rw [tsub_self]
exact hH.1
open scoped Classical in
/-- The nilpotency class of a nilpotent `G` is equal to the length of the lower central series. -/
theorem lowerCentralSeries_length_eq_nilpotencyClass :
Nat.find (nilpotent_iff_lowerCentralSeries.mp hG) = Group.nilpotencyClass (G := G) := by
rw [← least_descending_central_series_length_eq_nilpotencyClass]
refine le_antisymm (Nat.find_mono ?_) (Nat.find_mono ?_)
· rintro n ⟨H, ⟨hH, hn⟩⟩
rw [← le_bot_iff, ← hn]
exact descending_central_series_ge_lower H hH n
· rintro n h
exact ⟨lowerCentralSeries G, ⟨lowerCentralSeries_isDescendingCentralSeries, h⟩⟩
@[simp]
theorem lowerCentralSeries_nilpotencyClass :
lowerCentralSeries G (Group.nilpotencyClass G) = ⊥ := by
classical
rw [← lowerCentralSeries_length_eq_nilpotencyClass]
exact Nat.find_spec (nilpotent_iff_lowerCentralSeries.mp hG)
theorem lowerCentralSeries_eq_bot_iff_nilpotencyClass_le {n : ℕ} :
lowerCentralSeries G n = ⊥ ↔ Group.nilpotencyClass G ≤ n := by
classical
constructor
· intro h
rw [← lowerCentralSeries_length_eq_nilpotencyClass]
exact Nat.find_le h
· intro h
rw [eq_bot_iff, ← lowerCentralSeries_nilpotencyClass]
exact lowerCentralSeries_antitone h
end Classical
theorem lowerCentralSeries_map_subtype_le (H : Subgroup G) (n : ℕ) :
(lowerCentralSeries H n).map H.subtype ≤ lowerCentralSeries G n := by
induction' n with d hd
· simp
· rw [lowerCentralSeries_succ, lowerCentralSeries_succ, MonoidHom.map_closure]
apply Subgroup.closure_mono
rintro x1 ⟨x2, ⟨x3, hx3, x4, _hx4, rfl⟩, rfl⟩
exact ⟨x3, hd (mem_map.mpr ⟨x3, hx3, rfl⟩), x4, by simp⟩
/-- A subgroup of a nilpotent group is nilpotent -/
instance Subgroup.isNilpotent (H : Subgroup G) [hG : IsNilpotent G] : IsNilpotent H := by
rw [nilpotent_iff_lowerCentralSeries] at *
rcases hG with ⟨n, hG⟩
use n
have := lowerCentralSeries_map_subtype_le H n
simp only [hG, SetLike.le_def, mem_map, forall_apply_eq_imp_iff₂, exists_imp] at this
exact eq_bot_iff.mpr fun x hx => Subtype.ext (this x ⟨hx, rfl⟩)
/-- The nilpotency class of a subgroup is less or equal to the nilpotency class of the group -/
theorem Subgroup.nilpotencyClass_le (H : Subgroup G) [hG : IsNilpotent G] :
Group.nilpotencyClass H ≤ Group.nilpotencyClass G := by
repeat rw [← lowerCentralSeries_length_eq_nilpotencyClass]
classical apply Nat.find_mono
intro n hG
have := lowerCentralSeries_map_subtype_le H n
simp only [hG, SetLike.le_def, mem_map, forall_apply_eq_imp_iff₂, exists_imp] at this
exact eq_bot_iff.mpr fun x hx => Subtype.ext (this x ⟨hx, rfl⟩)
instance (priority := 100) Group.isNilpotent_of_subsingleton [Subsingleton G] : IsNilpotent G :=
nilpotent_iff_lowerCentralSeries.2 ⟨0, Subsingleton.elim ⊤ ⊥⟩
theorem upperCentralSeries.map {H : Type*} [Group H] {f : G →* H} (h : Function.Surjective f)
(n : ℕ) : Subgroup.map f (upperCentralSeries G n) ≤ upperCentralSeries H n := by
induction' n with d hd
· simp
· rintro _ ⟨x, hx : x ∈ upperCentralSeries G d.succ, rfl⟩ y'
rcases h y' with ⟨y, rfl⟩
simpa using hd (mem_map_of_mem f (hx y))
theorem lowerCentralSeries.map {H : Type*} [Group H] (f : G →* H) (n : ℕ) :
Subgroup.map f (lowerCentralSeries G n) ≤ lowerCentralSeries H n := by
induction' n with d hd
· simp
· rintro a ⟨x, hx : x ∈ lowerCentralSeries G d.succ, rfl⟩
refine closure_induction (hx := hx) ?_ (by simp [f.map_one, Subgroup.one_mem _])
(fun y z _ _ hy hz => by simp [MonoidHom.map_mul, Subgroup.mul_mem _ hy hz]) (fun y _ hy => by
rw [f.map_inv]; exact Subgroup.inv_mem _ hy)
rintro a ⟨y, hy, z, ⟨-, rfl⟩⟩
apply mem_closure.mpr
exact fun K hK => hK ⟨f y, hd (mem_map_of_mem f hy), by simp [commutatorElement_def]⟩
theorem lowerCentralSeries_succ_eq_bot {n : ℕ} (h : lowerCentralSeries G n ≤ center G) :
lowerCentralSeries G (n + 1) = ⊥ := by
rw [lowerCentralSeries_succ, closure_eq_bot_iff, Set.subset_singleton_iff]
rintro x ⟨y, hy1, z, ⟨⟩, rfl⟩
rw [mul_assoc, ← mul_inv_rev, mul_inv_eq_one, eq_comm]
exact mem_center_iff.mp (h hy1) z
/-- The preimage of a nilpotent group is nilpotent if the kernel of the homomorphism is contained
in the center -/
theorem isNilpotent_of_ker_le_center {H : Type*} [Group H] (f : G →* H) (hf1 : f.ker ≤ center G)
(hH : IsNilpotent H) : IsNilpotent G := by
rw [nilpotent_iff_lowerCentralSeries] at *
rcases hH with ⟨n, hn⟩
use n + 1
refine lowerCentralSeries_succ_eq_bot (le_trans ((Subgroup.map_eq_bot_iff _).mp ?_) hf1)
exact eq_bot_iff.mpr (hn ▸ lowerCentralSeries.map f n)
theorem nilpotencyClass_le_of_ker_le_center {H : Type*} [Group H] (f : G →* H)
(hf1 : f.ker ≤ center G) (hH : IsNilpotent H) :
Group.nilpotencyClass (hG := isNilpotent_of_ker_le_center f hf1 hH) ≤
Group.nilpotencyClass H + 1 := by
haveI : IsNilpotent G := isNilpotent_of_ker_le_center f hf1 hH
rw [← lowerCentralSeries_length_eq_nilpotencyClass]
classical apply Nat.find_min'
refine lowerCentralSeries_succ_eq_bot (le_trans ((Subgroup.map_eq_bot_iff _).mp ?_) hf1)
rw [eq_bot_iff]
apply le_trans (lowerCentralSeries.map f _)
simp only [lowerCentralSeries_nilpotencyClass, le_bot_iff]
/-- The range of a surjective homomorphism from a nilpotent group is nilpotent -/
theorem nilpotent_of_surjective {G' : Type*} [Group G'] [h : IsNilpotent G] (f : G →* G')
(hf : Function.Surjective f) : IsNilpotent G' := by
rcases h with ⟨n, hn⟩
use n
apply eq_top_iff.mpr
calc
⊤ = f.range := symm (f.range_eq_top_of_surjective hf)
_ = Subgroup.map f ⊤ := MonoidHom.range_eq_map _
_ = Subgroup.map f (upperCentralSeries G n) := by rw [hn]
_ ≤ upperCentralSeries G' n := upperCentralSeries.map hf n
/-- The nilpotency class of the range of a surjective homomorphism from a
nilpotent group is less or equal the nilpotency class of the domain -/
theorem nilpotencyClass_le_of_surjective {G' : Type*} [Group G'] (f : G →* G')
(hf : Function.Surjective f) [h : IsNilpotent G] :
Group.nilpotencyClass (hG := nilpotent_of_surjective _ hf) ≤ Group.nilpotencyClass G := by
classical apply Nat.find_mono
intro n hn
rw [eq_top_iff]
calc
⊤ = f.range := symm (f.range_eq_top_of_surjective hf)
_ = Subgroup.map f ⊤ := MonoidHom.range_eq_map _
_ = Subgroup.map f (upperCentralSeries G n) := by rw [hn]
_ ≤ upperCentralSeries G' n := upperCentralSeries.map hf n
/-- Nilpotency respects isomorphisms -/
theorem nilpotent_of_mulEquiv {G' : Type*} [Group G'] [_h : IsNilpotent G] (f : G ≃* G') :
IsNilpotent G' :=
nilpotent_of_surjective f.toMonoidHom (MulEquiv.surjective f)
/-- A quotient of a nilpotent group is nilpotent -/
instance nilpotent_quotient_of_nilpotent (H : Subgroup G) [H.Normal] [_h : IsNilpotent G] :
IsNilpotent (G ⧸ H) :=
nilpotent_of_surjective (QuotientGroup.mk' H) QuotientGroup.mk_surjective
/-- The nilpotency class of a quotient of `G` is less or equal the nilpotency class of `G` -/
theorem nilpotencyClass_quotient_le (H : Subgroup G) [H.Normal] [_h : IsNilpotent G] :
Group.nilpotencyClass (G ⧸ H) ≤ Group.nilpotencyClass G :=
nilpotencyClass_le_of_surjective (QuotientGroup.mk' H) QuotientGroup.mk_surjective
-- This technical lemma helps with rewriting the subgroup, which occurs in indices
private theorem comap_center_subst {H₁ H₂ : Subgroup G} [Normal H₁] [Normal H₂] (h : H₁ = H₂) :
comap (mk' H₁) (center (G ⧸ H₁)) = comap (mk' H₂) (center (G ⧸ H₂)) := by subst h; rfl
theorem comap_upperCentralSeries_quotient_center (n : ℕ) :
comap (mk' (center G)) (upperCentralSeries (G ⧸ center G) n) = upperCentralSeries G n.succ := by
induction' n with n ih
· simp only [upperCentralSeries_zero, MonoidHom.comap_bot, ker_mk',
(upperCentralSeries_one G).symm]
· let Hn := upperCentralSeries (G ⧸ center G) n
calc
comap (mk' (center G)) (upperCentralSeriesStep Hn) =
comap (mk' (center G)) (comap (mk' Hn) (center ((G ⧸ center G) ⧸ Hn))) := by
rw [upperCentralSeriesStep_eq_comap_center]
_ = comap (mk' (comap (mk' (center G)) Hn)) (center (G ⧸ comap (mk' (center G)) Hn)) :=
QuotientGroup.comap_comap_center
_ = comap (mk' (upperCentralSeries G n.succ)) (center (G ⧸ upperCentralSeries G n.succ)) :=
(comap_center_subst ih)
_ = upperCentralSeriesStep (upperCentralSeries G n.succ) :=
symm (upperCentralSeriesStep_eq_comap_center _)
theorem nilpotencyClass_zero_iff_subsingleton [IsNilpotent G] :
Group.nilpotencyClass G = 0 ↔ Subsingleton G := by
classical
rw [Group.nilpotencyClass, Nat.find_eq_zero, upperCentralSeries_zero,
subsingleton_iff_bot_eq_top, Subgroup.subsingleton_iff]
/-- Quotienting the `center G` reduces the nilpotency class by 1 -/
theorem nilpotencyClass_quotient_center [hH : IsNilpotent G] :
Group.nilpotencyClass (G ⧸ center G) = Group.nilpotencyClass G - 1 := by
generalize hn : Group.nilpotencyClass G = n
rcases n with (rfl | n)
· simp [nilpotencyClass_zero_iff_subsingleton] at *
exact Quotient.instSubsingletonQuotient (leftRel (center G))
· suffices Group.nilpotencyClass (G ⧸ center G) = n by simpa
apply le_antisymm
· apply upperCentralSeries_eq_top_iff_nilpotencyClass_le.mp
apply comap_injective (f := (mk' (center G))) Quot.mk_surjective
rw [comap_upperCentralSeries_quotient_center, comap_top, Nat.succ_eq_add_one, ← hn]
exact upperCentralSeries_nilpotencyClass
· apply le_of_add_le_add_right
calc
n + 1 = Group.nilpotencyClass G := hn.symm
_ ≤ Group.nilpotencyClass (G ⧸ center G) + 1 :=
nilpotencyClass_le_of_ker_le_center _ (le_of_eq (ker_mk' _)) _
/-- The nilpotency class of a non-trivial group is one more than its quotient by the center -/
theorem nilpotencyClass_eq_quotient_center_plus_one [hH : IsNilpotent G] [Nontrivial G] :
Group.nilpotencyClass G = Group.nilpotencyClass (G ⧸ center G) + 1 := by
rw [nilpotencyClass_quotient_center]
rcases h : Group.nilpotencyClass G with ⟨⟩
· exfalso
rw [nilpotencyClass_zero_iff_subsingleton] at h
apply false_of_nontrivial_of_subsingleton G
· simp
/-- If the quotient by `center G` is nilpotent, then so is G. -/
theorem of_quotient_center_nilpotent (h : IsNilpotent (G ⧸ center G)) : IsNilpotent G := by
obtain ⟨n, hn⟩ := h.nilpotent
use n.succ
simp [← comap_upperCentralSeries_quotient_center, hn]
/-- A custom induction principle for nilpotent groups. The base case is a trivial group
(`subsingleton G`), and in the induction step, one can assume the hypothesis for
the group quotiented by its center. -/
@[elab_as_elim]
theorem nilpotent_center_quotient_ind {P : ∀ (G) [Group G] [IsNilpotent G], Prop}
(G : Type*) [Group G] [IsNilpotent G]
(hbase : ∀ (G) [Group G] [Subsingleton G], P G)
(hstep : ∀ (G) [Group G] [IsNilpotent G], P (G ⧸ center G) → P G) : P G := by
obtain ⟨n, h⟩ : ∃ n, Group.nilpotencyClass G = n := ⟨_, rfl⟩
induction' n with n ih generalizing G
· haveI := nilpotencyClass_zero_iff_subsingleton.mp h
exact hbase _
· have hn : Group.nilpotencyClass (G ⧸ center G) = n := by
simp [nilpotencyClass_quotient_center, h]
exact hstep _ (ih _ hn)
theorem derived_le_lower_central (n : ℕ) : derivedSeries G n ≤ lowerCentralSeries G n := by
induction' n with i ih
· simp
· apply commutator_mono ih
simp
/-- Abelian groups are nilpotent -/
instance (priority := 100) CommGroup.isNilpotent {G : Type*} [CommGroup G] : IsNilpotent G := by
use 1
rw [upperCentralSeries_one]
apply CommGroup.center_eq_top
/-- Abelian groups have nilpotency class at most one -/
theorem CommGroup.nilpotencyClass_le_one {G : Type*} [CommGroup G] :
Group.nilpotencyClass G ≤ 1 := by
rw [← upperCentralSeries_eq_top_iff_nilpotencyClass_le, upperCentralSeries_one]
apply CommGroup.center_eq_top
/-- Groups with nilpotency class at most one are abelian -/
def commGroupOfNilpotencyClass [IsNilpotent G] (h : Group.nilpotencyClass G ≤ 1) : CommGroup G :=
Group.commGroupOfCenterEqTop <| by
rw [← upperCentralSeries_one]
exact upperCentralSeries_eq_top_iff_nilpotencyClass_le.mpr h
section Prod
variable {G₁ G₂ : Type*} [Group G₁] [Group G₂]
theorem lowerCentralSeries_prod (n : ℕ) :
lowerCentralSeries (G₁ × G₂) n = (lowerCentralSeries G₁ n).prod (lowerCentralSeries G₂ n) := by
induction' n with n ih
· simp
· calc
lowerCentralSeries (G₁ × G₂) n.succ = ⁅lowerCentralSeries (G₁ × G₂) n, ⊤⁆ := rfl
_ = ⁅(lowerCentralSeries G₁ n).prod (lowerCentralSeries G₂ n), ⊤⁆ := by rw [ih]
_ = ⁅(lowerCentralSeries G₁ n).prod (lowerCentralSeries G₂ n), (⊤ : Subgroup G₁).prod ⊤⁆ := by
simp
_ = ⁅lowerCentralSeries G₁ n, (⊤ : Subgroup G₁)⁆.prod ⁅lowerCentralSeries G₂ n, ⊤⁆ :=
(commutator_prod_prod _ _ _ _)
_ = (lowerCentralSeries G₁ n.succ).prod (lowerCentralSeries G₂ n.succ) := rfl
/-- Products of nilpotent groups are nilpotent -/
instance isNilpotent_prod [IsNilpotent G₁] [IsNilpotent G₂] : IsNilpotent (G₁ × G₂) := by
rw [nilpotent_iff_lowerCentralSeries]
refine ⟨max (Group.nilpotencyClass G₁) (Group.nilpotencyClass G₂), ?_⟩
rw [lowerCentralSeries_prod,
lowerCentralSeries_eq_bot_iff_nilpotencyClass_le.mpr (le_max_left _ _),
lowerCentralSeries_eq_bot_iff_nilpotencyClass_le.mpr (le_max_right _ _), bot_prod_bot]
/-- The nilpotency class of a product is the max of the nilpotency classes of the factors -/
theorem nilpotencyClass_prod [IsNilpotent G₁] [IsNilpotent G₂] :
Group.nilpotencyClass (G₁ × G₂) =
max (Group.nilpotencyClass G₁) (Group.nilpotencyClass G₂) := by
refine eq_of_forall_ge_iff fun k => ?_
simp only [max_le_iff, ← lowerCentralSeries_eq_bot_iff_nilpotencyClass_le,
lowerCentralSeries_prod, prod_eq_bot_iff]
end Prod
section BoundedPi
-- First the case of infinite products with bounded nilpotency class
variable {η : Type*} {Gs : η → Type*} [∀ i, Group (Gs i)]
theorem lowerCentralSeries_pi_le (n : ℕ) :
lowerCentralSeries (∀ i, Gs i) n ≤ Subgroup.pi Set.univ
fun i => lowerCentralSeries (Gs i) n := by
let pi := fun f : ∀ i, Subgroup (Gs i) => Subgroup.pi Set.univ f
induction' n with n ih
· simp [pi_top]
· calc
lowerCentralSeries (∀ i, Gs i) n.succ = ⁅lowerCentralSeries (∀ i, Gs i) n, ⊤⁆ := rfl
_ ≤ ⁅pi fun i => lowerCentralSeries (Gs i) n, ⊤⁆ := commutator_mono ih (le_refl _)
_ = ⁅pi fun i => lowerCentralSeries (Gs i) n, pi fun i => ⊤⁆ := by simp [pi, pi_top]
_ ≤ pi fun i => ⁅lowerCentralSeries (Gs i) n, ⊤⁆ := commutator_pi_pi_le _ _
_ = pi fun i => lowerCentralSeries (Gs i) n.succ := rfl
/-- products of nilpotent groups are nilpotent if their nilpotency class is bounded -/
theorem isNilpotent_pi_of_bounded_class [∀ i, IsNilpotent (Gs i)] (n : ℕ)
(h : ∀ i, Group.nilpotencyClass (Gs i) ≤ n) : IsNilpotent (∀ i, Gs i) := by
rw [nilpotent_iff_lowerCentralSeries]
refine ⟨n, ?_⟩
rw [eq_bot_iff]
apply le_trans (lowerCentralSeries_pi_le _)
rw [← eq_bot_iff, pi_eq_bot_iff]
intro i
apply lowerCentralSeries_eq_bot_iff_nilpotencyClass_le.mpr (h i)
end BoundedPi
section FinitePi
-- Now for finite products
variable {η : Type*} {Gs : η → Type*} [∀ i, Group (Gs i)]
theorem lowerCentralSeries_pi_of_finite [Finite η] (n : ℕ) :
lowerCentralSeries (∀ i, Gs i) n = Subgroup.pi Set.univ
fun i => lowerCentralSeries (Gs i) n := by
let pi := fun f : ∀ i, Subgroup (Gs i) => Subgroup.pi Set.univ f
induction' n with n ih
· simp [pi_top]
· calc
lowerCentralSeries (∀ i, Gs i) n.succ = ⁅lowerCentralSeries (∀ i, Gs i) n, ⊤⁆ := rfl
_ = ⁅pi fun i => lowerCentralSeries (Gs i) n, ⊤⁆ := by rw [ih]
_ = ⁅pi fun i => lowerCentralSeries (Gs i) n, pi fun i => ⊤⁆ := by simp [pi, pi_top]
_ = pi fun i => ⁅lowerCentralSeries (Gs i) n, ⊤⁆ := commutator_pi_pi_of_finite _ _
_ = pi fun i => lowerCentralSeries (Gs i) n.succ := rfl
/-- n-ary products of nilpotent groups are nilpotent -/
instance isNilpotent_pi [Finite η] [∀ i, IsNilpotent (Gs i)] : IsNilpotent (∀ i, Gs i) := by
cases nonempty_fintype η
rw [nilpotent_iff_lowerCentralSeries]
refine ⟨Finset.univ.sup fun i => Group.nilpotencyClass (Gs i), ?_⟩
rw [lowerCentralSeries_pi_of_finite, pi_eq_bot_iff]
intro i
rw [lowerCentralSeries_eq_bot_iff_nilpotencyClass_le]
exact Finset.le_sup (f := fun i => Group.nilpotencyClass (Gs i)) (Finset.mem_univ i)
/-- The nilpotency class of an n-ary product is the sup of the nilpotency classes of the factors -/
theorem nilpotencyClass_pi [Fintype η] [∀ i, IsNilpotent (Gs i)] :
Group.nilpotencyClass (∀ i, Gs i) = Finset.univ.sup fun i => Group.nilpotencyClass (Gs i) := by
apply eq_of_forall_ge_iff
intro k
simp only [Finset.sup_le_iff, ← lowerCentralSeries_eq_bot_iff_nilpotencyClass_le,
lowerCentralSeries_pi_of_finite, pi_eq_bot_iff, Finset.mem_univ, true_imp_iff]
end FinitePi
/-- A nilpotent subgroup is solvable -/
instance (priority := 100) IsNilpotent.to_isSolvable [h : IsNilpotent G] : IsSolvable G := by
obtain ⟨n, hn⟩ := nilpotent_iff_lowerCentralSeries.1 h
use n
rw [eq_bot_iff, ← hn]
exact derived_le_lower_central n
| Mathlib/GroupTheory/Nilpotent.lean | 778 | 789 | theorem normalizerCondition_of_isNilpotent [h : IsNilpotent G] : NormalizerCondition G := by | -- roughly based on https://groupprops.subwiki.org/wiki/Nilpotent_implies_normalizer_condition
rw [normalizerCondition_iff_only_full_group_self_normalizing]
apply @nilpotent_center_quotient_ind _ G _ _ <;> clear! G
· intro G _ _ H _
exact @Subsingleton.elim _ Unique.instSubsingleton _ _
· intro G _ _ ih H hH
have hch : center G ≤ H := Subgroup.center_le_normalizer.trans (le_of_eq hH)
have hkh : (mk' (center G)).ker ≤ H := by simpa using hch
have hsur : Function.Surjective (mk' (center G)) := Quot.mk_surjective
let H' := H.map (mk' (center G))
have hH' : H'.normalizer = H' := by |
/-
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 Batteries.Data.List.Perm
import Mathlib.Tactic.Common
/-!
# Counting in lists
This file proves basic properties of `List.countP` and `List.count`, which count the number of
elements of a list satisfying a predicate and equal to a given element respectively.
-/
assert_not_exists Monoid Set.range
open Nat
variable {α β : Type*}
namespace List
@[simp]
theorem countP_lt_length_iff {l : List α} {p : α → Bool} :
l.countP p < l.length ↔ ∃ a ∈ l, p a = false := by
simp [Nat.lt_iff_le_and_ne, countP_le_length]
variable [DecidableEq α] {l l₁ l₂ : List α}
@[simp]
theorem count_lt_length_iff {a : α} : l.count a < l.length ↔ ∃ b ∈ l, b ≠ a := by simp [count]
lemma countP_erase (p : α → Bool) (l : List α) (a : α) :
countP p (l.erase a) = countP p l - if a ∈ l ∧ p a then 1 else 0 := by
rw [countP_eq_length_filter, countP_eq_length_filter, ← erase_filter, length_erase]
aesop
lemma count_diff (a : α) (l₁ : List α) :
∀ l₂, count a (l₁.diff l₂) = count a l₁ - count a l₂
| [] => rfl
| b :: l₂ => by
simp only [diff_cons, count_diff, count_erase, beq_iff_eq, Nat.sub_right_comm, count_cons,
Nat.sub_add_eq]
lemma countP_diff (hl : l₂ <+~ l₁) (p : α → Bool) :
countP p (l₁.diff l₂) = countP p l₁ - countP p l₂ := by
refine (Nat.sub_eq_of_eq_add ?_).symm
rw [← countP_append]
exact ((subperm_append_diff_self_of_count_le <| subperm_ext_iff.1 hl).symm.trans
perm_append_comm).countP_eq _
@[simp]
| Mathlib/Data/List/Count.lean | 54 | 57 | theorem count_map_of_injective [DecidableEq β] (l : List α) (f : α → β)
(hf : Function.Injective f) (x : α) : count (f x) (map f l) = count x l := by | simp only [count, countP_map]
unfold Function.comp |
/-
Copyright (c) 2017 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Tim Baumann, Stephen Morgan, Kim Morrison, Floris van Doorn
-/
import Mathlib.CategoryTheory.Functor.FullyFaithful
import Mathlib.CategoryTheory.ObjectProperty.FullSubcategory
import Mathlib.CategoryTheory.Whiskering
import Mathlib.CategoryTheory.EssentialImage
import Mathlib.Tactic.CategoryTheory.Slice
/-!
# Equivalence of categories
An equivalence of categories `C` and `D` is a pair of functors `F : C ⥤ D` and `G : D ⥤ C` such
that `η : 𝟭 C ≅ F ⋙ G` and `ε : G ⋙ F ≅ 𝟭 D`. In many situations, equivalences are a better
notion of "sameness" of categories than the stricter isomorphism of categories.
Recall that one way to express that two functors `F : C ⥤ D` and `G : D ⥤ C` are adjoint is using
two natural transformations `η : 𝟭 C ⟶ F ⋙ G` and `ε : G ⋙ F ⟶ 𝟭 D`, called the unit and the
counit, such that the compositions `F ⟶ FGF ⟶ F` and `G ⟶ GFG ⟶ G` are the identity. Unfortunately,
it is not the case that the natural isomorphisms `η` and `ε` in the definition of an equivalence
automatically give an adjunction. However, it is true that
* if one of the two compositions is the identity, then so is the other, and
* given an equivalence of categories, it is always possible to refine `η` in such a way that the
identities are satisfied.
For this reason, in mathlib we define an equivalence to be a "half-adjoint equivalence", which is
a tuple `(F, G, η, ε)` as in the first paragraph such that the composite `F ⟶ FGF ⟶ F` is the
identity. By the remark above, this already implies that the tuple is an "adjoint equivalence",
i.e., that the composite `G ⟶ GFG ⟶ G` is also the identity.
We also define essentially surjective functors and show that a functor is an equivalence if and only
if it is full, faithful and essentially surjective.
## Main definitions
* `Equivalence`: bundled (half-)adjoint equivalences of categories
* `Functor.EssSurj`: type class on a functor `F` containing the data of the preimages
and the isomorphisms `F.obj (preimage d) ≅ d`.
* `Functor.IsEquivalence`: type class on a functor `F` which is full, faithful and
essentially surjective.
## Main results
* `Equivalence.mk`: upgrade an equivalence to a (half-)adjoint equivalence
* `isEquivalence_iff_of_iso`: when `F` and `G` are isomorphic functors,
`F` is an equivalence iff `G` is.
* `Functor.asEquivalenceFunctor`: construction of an equivalence of categories from
a functor `F` which satisfies the property `F.IsEquivalence` (i.e. `F` is full, faithful
and essentially surjective).
## Notations
We write `C ≌ D` (`\backcong`, not to be confused with `≅`/`\cong`) for a bundled equivalence.
-/
namespace CategoryTheory
open CategoryTheory.Functor NatIso Category
-- declare the `v`'s first; see `CategoryTheory.Category` for an explanation
universe v₁ v₂ v₃ u₁ u₂ u₃
/-- We define an equivalence as a (half)-adjoint equivalence, a pair of functors with
a unit and counit which are natural isomorphisms and the triangle law `Fη ≫ εF = 1`, or in other
words the composite `F ⟶ FGF ⟶ F` is the identity.
In `unit_inverse_comp`, we show that this is actually an adjoint equivalence, i.e., that the
composite `G ⟶ GFG ⟶ G` is also the identity.
The triangle equation is written as a family of equalities between morphisms, it is more
complicated if we write it as an equality of natural transformations, because then we would have
to insert natural transformations like `F ⟶ F1`. -/
@[ext, stacks 001J]
structure Equivalence (C : Type u₁) (D : Type u₂) [Category.{v₁} C] [Category.{v₂} D] where mk' ::
/-- A functor in one direction -/
functor : C ⥤ D
/-- A functor in the other direction -/
inverse : D ⥤ C
/-- The composition `functor ⋙ inverse` is isomorphic to the identity -/
unitIso : 𝟭 C ≅ functor ⋙ inverse
/-- The composition `inverse ⋙ functor` is also isomorphic to the identity -/
counitIso : inverse ⋙ functor ≅ 𝟭 D
/-- The natural isomorphisms compose to the identity. -/
functor_unitIso_comp :
∀ X : C, functor.map (unitIso.hom.app X) ≫ counitIso.hom.app (functor.obj X) =
𝟙 (functor.obj X) := by aesop_cat
/-- We infix the usual notation for an equivalence -/
infixr:10 " ≌ " => Equivalence
variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D]
namespace Equivalence
/-- The unit of an equivalence of categories. -/
abbrev unit (e : C ≌ D) : 𝟭 C ⟶ e.functor ⋙ e.inverse :=
e.unitIso.hom
/-- The counit of an equivalence of categories. -/
abbrev counit (e : C ≌ D) : e.inverse ⋙ e.functor ⟶ 𝟭 D :=
e.counitIso.hom
/-- The inverse of the unit of an equivalence of categories. -/
abbrev unitInv (e : C ≌ D) : e.functor ⋙ e.inverse ⟶ 𝟭 C :=
e.unitIso.inv
/-- The inverse of the counit of an equivalence of categories. -/
abbrev counitInv (e : C ≌ D) : 𝟭 D ⟶ e.inverse ⋙ e.functor :=
e.counitIso.inv
/- While these abbreviations are convenient, they also cause some trouble,
preventing structure projections from unfolding. -/
@[simp]
theorem Equivalence_mk'_unit (functor inverse unit_iso counit_iso f) :
(⟨functor, inverse, unit_iso, counit_iso, f⟩ : C ≌ D).unit = unit_iso.hom :=
rfl
@[simp]
theorem Equivalence_mk'_counit (functor inverse unit_iso counit_iso f) :
(⟨functor, inverse, unit_iso, counit_iso, f⟩ : C ≌ D).counit = counit_iso.hom :=
rfl
@[simp]
theorem Equivalence_mk'_unitInv (functor inverse unit_iso counit_iso f) :
(⟨functor, inverse, unit_iso, counit_iso, f⟩ : C ≌ D).unitInv = unit_iso.inv :=
rfl
@[simp]
theorem Equivalence_mk'_counitInv (functor inverse unit_iso counit_iso f) :
(⟨functor, inverse, unit_iso, counit_iso, f⟩ : C ≌ D).counitInv = counit_iso.inv :=
rfl
@[reassoc]
theorem counit_naturality (e : C ≌ D) {X Y : D} (f : X ⟶ Y) :
e.functor.map (e.inverse.map f) ≫ e.counit.app Y = e.counit.app X ≫ f :=
e.counit.naturality f
@[reassoc]
theorem unit_naturality (e : C ≌ D) {X Y : C} (f : X ⟶ Y) :
e.unit.app X ≫ e.inverse.map (e.functor.map f) = f ≫ e.unit.app Y :=
(e.unit.naturality f).symm
@[reassoc]
theorem counitInv_naturality (e : C ≌ D) {X Y : D} (f : X ⟶ Y) :
e.counitInv.app X ≫ e.functor.map (e.inverse.map f) = f ≫ e.counitInv.app Y :=
(e.counitInv.naturality f).symm
@[reassoc]
theorem unitInv_naturality (e : C ≌ D) {X Y : C} (f : X ⟶ Y) :
e.inverse.map (e.functor.map f) ≫ e.unitInv.app Y = e.unitInv.app X ≫ f :=
e.unitInv.naturality f
@[reassoc (attr := simp)]
theorem functor_unit_comp (e : C ≌ D) (X : C) :
e.functor.map (e.unit.app X) ≫ e.counit.app (e.functor.obj X) = 𝟙 (e.functor.obj X) :=
e.functor_unitIso_comp X
@[reassoc (attr := simp)]
theorem counitInv_functor_comp (e : C ≌ D) (X : C) :
e.counitInv.app (e.functor.obj X) ≫ e.functor.map (e.unitInv.app X) = 𝟙 (e.functor.obj X) := by
simpa using Iso.inv_eq_inv
(e.functor.mapIso (e.unitIso.app X) ≪≫ e.counitIso.app (e.functor.obj X)) (Iso.refl _)
| Mathlib/CategoryTheory/Equivalence.lean | 166 | 170 | theorem counitInv_app_functor (e : C ≌ D) (X : C) :
e.counitInv.app (e.functor.obj X) = e.functor.map (e.unit.app X) := by | symm
simp only [id_obj, comp_obj, counitInv]
rw [← Iso.app_inv, ← Iso.comp_hom_eq_id (e.counitIso.app _), Iso.app_hom, functor_unit_comp] |
/-
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.Algebra.MonoidAlgebra.Defs
/-!
# Division of `AddMonoidAlgebra` by monomials
This file is most important for when `G = ℕ` (polynomials) or `G = σ →₀ ℕ` (multivariate
polynomials).
In order to apply in maximal generality (such as for `LaurentPolynomial`s), this uses
`∃ d, g' = g + d` in many places instead of `g ≤ g'`.
## Main definitions
* `AddMonoidAlgebra.divOf x g`: divides `x` by the monomial `AddMonoidAlgebra.of k G g`
* `AddMonoidAlgebra.modOf x g`: the remainder upon dividing `x` by the monomial
`AddMonoidAlgebra.of k G g`.
## Main results
* `AddMonoidAlgebra.divOf_add_modOf`, `AddMonoidAlgebra.modOf_add_divOf`: `divOf` and
`modOf` are well-behaved as quotient and remainder operators.
## Implementation notes
`∃ d, g' = g + d` is used as opposed to some other permutation up to commutativity in order to match
the definition of `semigroupDvd`. The results in this file could be duplicated for
`MonoidAlgebra` by using `g ∣ g'`, but this can't be done automatically, and in any case is not
likely to be very useful.
-/
variable {k G : Type*} [Semiring k]
namespace AddMonoidAlgebra
section
variable [AddCommMonoid G]
/-- Divide by `of' k G g`, discarding terms not divisible by this. -/
noncomputable def divOf [IsCancelAdd G] (x : k[G]) (g : G) : k[G] :=
-- note: comapping by `+ g` has the effect of subtracting `g` from every element in
-- the support, and discarding the elements of the support from which `g` can't be subtracted.
-- If `G` is an additive group, such as `ℤ` when used for `LaurentPolynomial`,
-- then no discarding occurs.
@Finsupp.comapDomain.addMonoidHom _ _ _ _ (g + ·) (add_right_injective g) x
local infixl:70 " /ᵒᶠ " => divOf
section divOf
variable [IsCancelAdd G]
@[simp]
theorem divOf_apply (g : G) (x : k[G]) (g' : G) : (x /ᵒᶠ g) g' = x (g + g') :=
rfl
@[simp]
theorem support_divOf (g : G) (x : k[G]) :
(x /ᵒᶠ g).support =
x.support.preimage (g + ·) (Function.Injective.injOn (add_right_injective g)) :=
rfl
@[simp]
theorem zero_divOf (g : G) : (0 : k[G]) /ᵒᶠ g = 0 :=
map_zero (Finsupp.comapDomain.addMonoidHom _)
@[simp]
theorem divOf_zero (x : k[G]) : x /ᵒᶠ 0 = x := by
ext
simp only [AddMonoidAlgebra.divOf_apply, zero_add]
theorem add_divOf (x y : k[G]) (g : G) : (x + y) /ᵒᶠ g = x /ᵒᶠ g + y /ᵒᶠ g :=
map_add (Finsupp.comapDomain.addMonoidHom _) _ _
theorem divOf_add (x : k[G]) (a b : G) : x /ᵒᶠ (a + b) = x /ᵒᶠ a /ᵒᶠ b := by
ext
simp only [AddMonoidAlgebra.divOf_apply, add_assoc]
/-- A bundled version of `AddMonoidAlgebra.divOf`. -/
@[simps]
noncomputable def divOfHom : Multiplicative G →* AddMonoid.End k[G] where
toFun g :=
{ toFun := fun x => divOf x g.toAdd
map_zero' := zero_divOf _
map_add' := fun x y => add_divOf x y g.toAdd }
map_one' := AddMonoidHom.ext divOf_zero
map_mul' g₁ g₂ :=
AddMonoidHom.ext fun _x =>
(congr_arg _ (add_comm g₁.toAdd g₂.toAdd)).trans
(divOf_add _ _ _)
theorem of'_mul_divOf (a : G) (x : k[G]) : of' k G a * x /ᵒᶠ a = x := by
ext
rw [AddMonoidAlgebra.divOf_apply, of'_apply, single_mul_apply_aux, one_mul]
intro c hc
exact add_right_inj _
theorem mul_of'_divOf (x : k[G]) (a : G) : x * of' k G a /ᵒᶠ a = x := by
ext
rw [AddMonoidAlgebra.divOf_apply, of'_apply, mul_single_apply_aux, mul_one]
intro c hc
rw [add_comm]
exact add_right_inj _
theorem of'_divOf (a : G) : of' k G a /ᵒᶠ a = 1 := by
simpa only [one_mul] using mul_of'_divOf (1 : k[G]) a
end divOf
/-- The remainder upon division by `of' k G g`. -/
noncomputable def modOf (x : k[G]) (g : G) : k[G] :=
letI := Classical.decPred fun g₁ => ∃ g₂, g₁ = g + g₂
x.filter fun g₁ => ¬∃ g₂, g₁ = g + g₂
local infixl:70 " %ᵒᶠ " => modOf
@[simp]
theorem modOf_apply_of_not_exists_add (x : k[G]) (g : G) (g' : G)
(h : ¬∃ d, g' = g + d) : (x %ᵒᶠ g) g' = x g' := by
classical exact Finsupp.filter_apply_pos _ _ h
@[simp]
theorem modOf_apply_of_exists_add (x : k[G]) (g : G) (g' : G)
(h : ∃ d, g' = g + d) : (x %ᵒᶠ g) g' = 0 := by
classical exact Finsupp.filter_apply_neg _ _ <| by rwa [Classical.not_not]
@[simp]
theorem modOf_apply_add_self (x : k[G]) (g : G) (d : G) : (x %ᵒᶠ g) (d + g) = 0 :=
modOf_apply_of_exists_add _ _ _ ⟨_, add_comm _ _⟩
theorem modOf_apply_self_add (x : k[G]) (g : G) (d : G) : (x %ᵒᶠ g) (g + d) = 0 :=
modOf_apply_of_exists_add _ _ _ ⟨_, rfl⟩
theorem of'_mul_modOf (g : G) (x : k[G]) : of' k G g * x %ᵒᶠ g = 0 := by
ext g'
rw [Finsupp.zero_apply]
obtain ⟨d, rfl⟩ | h := em (∃ d, g' = g + d)
· rw [modOf_apply_self_add]
· rw [modOf_apply_of_not_exists_add _ _ _ h, of'_apply, single_mul_apply_of_not_exists_add _ _ h]
theorem mul_of'_modOf (x : k[G]) (g : G) : x * of' k G g %ᵒᶠ g = 0 := by
ext g'
rw [Finsupp.zero_apply]
obtain ⟨d, rfl⟩ | h := em (∃ d, g' = g + d)
· rw [modOf_apply_self_add]
· rw [modOf_apply_of_not_exists_add _ _ _ h, of'_apply, mul_single_apply_of_not_exists_add]
simpa only [add_comm] using h
theorem of'_modOf (g : G) : of' k G g %ᵒᶠ g = 0 := by
simpa only [one_mul] using mul_of'_modOf (1 : k[G]) g
theorem divOf_add_modOf [IsCancelAdd G] (x : k[G]) (g : G) :
of' k G g * (x /ᵒᶠ g) + x %ᵒᶠ g = x := by
ext g'
rw [Finsupp.add_apply] -- Porting note: changed from `simp_rw` which can't see through the type
obtain ⟨d, rfl⟩ | h := em (∃ d, g' = g + d)
swap
· rw [modOf_apply_of_not_exists_add x _ _ h, of'_apply, single_mul_apply_of_not_exists_add _ _ h,
zero_add]
· rw [modOf_apply_self_add, add_zero]
rw [of'_apply, single_mul_apply_aux _ _ _, one_mul, divOf_apply]
intro a ha
exact add_right_inj _
| Mathlib/Algebra/MonoidAlgebra/Division.lean | 171 | 172 | theorem modOf_add_divOf [IsCancelAdd G] (x : k[G]) (g : G) :
x %ᵒᶠ g + of' k G g * (x /ᵒᶠ g) = x := by | |
/-
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
/-!
# 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
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]
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]
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]
theorem einfsep_top :
s.einfsep = ∞ ↔ ∀ x ∈ s, ∀ y ∈ s, x ≠ y → edist x y = ∞ := by
simp_rw [einfsep, iInf_eq_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]
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]
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]
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⟩
theorem nontrivial_of_einfsep_ne_top (hs : s.einfsep ≠ ∞) : s.Nontrivial :=
nontrivial_of_einfsep_lt_top (lt_top_iff_ne_top.mpr hs)
theorem Subsingleton.einfsep (hs : s.Subsingleton) : s.einfsep = ∞ := by
rw [einfsep_top]
exact fun _ hx _ hy hxy => (hxy <| hs hx hy).elim
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]
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
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
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'
theorem le_einfsep {d} (h : ∀ x ∈ s, ∀ y ∈ s, x ≠ y → d ≤ edist x y) : d ≤ s.einfsep :=
le_einfsep_iff.2 h
@[simp]
theorem einfsep_empty : (∅ : Set α).einfsep = ∞ :=
subsingleton_empty.einfsep
@[simp]
theorem einfsep_singleton : ({x} : Set α).einfsep = ∞ :=
subsingleton_singleton.einfsep
theorem einfsep_iUnion_mem_option {ι : Type*} (o : Option ι) (s : ι → Set α) :
(⋃ i ∈ o, s i).einfsep = ⨅ i ∈ o, (s i).einfsep := by cases o <;> simp
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)
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
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
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
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
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
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]
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]
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]
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]
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⟩
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
end EDist
section PseudoEMetricSpace
variable [PseudoEMetricSpace α] {x y z : α} {s : 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]
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)
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]
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)
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)
theorem einfsep_eq_top_iff : s.einfsep = ∞ ↔ s.Subsingleton :=
⟨subsingleton_of_einfsep_eq_top, Subsingleton.einfsep⟩
theorem Nontrivial.einfsep_ne_top (hs : s.Nontrivial) : s.einfsep ≠ ∞ := by
contrapose! hs
rw [not_nontrivial_iff]
exact subsingleton_of_einfsep_eq_top hs
theorem Nontrivial.einfsep_lt_top (hs : s.Nontrivial) : s.einfsep < ∞ := by
rw [lt_top_iff_ne_top]
exact hs.einfsep_ne_top
theorem einfsep_lt_top_iff : s.einfsep < ∞ ↔ s.Nontrivial :=
⟨nontrivial_of_einfsep_lt_top, Nontrivial.einfsep_lt_top⟩
theorem einfsep_ne_top_iff : s.einfsep ≠ ∞ ↔ s.Nontrivial :=
⟨nontrivial_of_einfsep_ne_top, Nontrivial.einfsep_ne_top⟩
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)
end PseudoMetricSpace
section EMetricSpace
variable [EMetricSpace α] {s : Set α}
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.top_pos
theorem relatively_discrete_of_finite [Finite s] :
∃ C > 0, ∀ x ∈ s, ∀ y ∈ s, x ≠ y → C ≤ edist x y := by
rw [← einfsep_pos]
exact einfsep_pos_of_finite
theorem Finite.einfsep_pos (hs : s.Finite) : 0 < s.einfsep :=
letI := hs.fintype
einfsep_pos_of_finite
theorem Finite.relatively_discrete (hs : s.Finite) :
∃ C > 0, ∀ x ∈ s, ∀ y ∈ s, x ≠ y → C ≤ edist x y :=
letI := hs.fintype
relatively_discrete_of_finite
end EMetricSpace
end Einfsep
section Infsep
open ENNReal
open Set Function
/-- The "infimum separation" of a set with an edist function. -/
noncomputable def infsep [EDist α] (s : Set α) : ℝ :=
ENNReal.toReal s.einfsep
section EDist
variable [EDist α] {x y : α} {s : Set α}
theorem infsep_zero : s.infsep = 0 ↔ s.einfsep = 0 ∨ s.einfsep = ∞ := by
rw [infsep, ENNReal.toReal_eq_zero_iff]
theorem infsep_nonneg : 0 ≤ s.infsep :=
ENNReal.toReal_nonneg
theorem infsep_pos : 0 < s.infsep ↔ 0 < s.einfsep ∧ s.einfsep < ∞ := by
simp_rw [infsep, ENNReal.toReal_pos_iff]
theorem Subsingleton.infsep_zero (hs : s.Subsingleton) : s.infsep = 0 :=
Set.infsep_zero.mpr <| Or.inr hs.einfsep
theorem nontrivial_of_infsep_pos (hs : 0 < s.infsep) : s.Nontrivial := by
contrapose hs
rw [not_nontrivial_iff] at hs
exact hs.infsep_zero ▸ lt_irrefl _
theorem infsep_empty : (∅ : Set α).infsep = 0 :=
subsingleton_empty.infsep_zero
theorem infsep_singleton : ({x} : Set α).infsep = 0 :=
subsingleton_singleton.infsep_zero
theorem infsep_pair_le_toReal_inf (hxy : x ≠ y) :
({x, y} : Set α).infsep ≤ (edist x y ⊓ edist y x).toReal := by
simp_rw [infsep, einfsep_pair_eq_inf hxy]
simp
end EDist
section PseudoEMetricSpace
variable [PseudoEMetricSpace α] {x y : α}
theorem infsep_pair_eq_toReal : ({x, y} : Set α).infsep = (edist x y).toReal := by
by_cases hxy : x = y
· rw [hxy]
simp only [infsep_singleton, pair_eq_singleton, edist_self, ENNReal.toReal_zero]
· rw [infsep, einfsep_pair hxy]
end PseudoEMetricSpace
section PseudoMetricSpace
variable [PseudoMetricSpace α] {x y z : α} {s t : Set α}
theorem Nontrivial.le_infsep_iff {d} (hs : s.Nontrivial) :
d ≤ s.infsep ↔ ∀ x ∈ s, ∀ y ∈ s, x ≠ y → d ≤ dist x y := by
simp_rw [infsep, ← ENNReal.ofReal_le_iff_le_toReal hs.einfsep_ne_top, le_einfsep_iff, edist_dist,
ENNReal.ofReal_le_ofReal_iff dist_nonneg]
theorem Nontrivial.infsep_lt_iff {d} (hs : s.Nontrivial) :
s.infsep < d ↔ ∃ x ∈ s, ∃ y ∈ s, x ≠ y ∧ dist x y < d := by
rw [← not_iff_not]
push_neg
exact hs.le_infsep_iff
theorem Nontrivial.le_infsep {d} (hs : s.Nontrivial)
(h : ∀ x ∈ s, ∀ y ∈ s, x ≠ y → d ≤ dist x y) : d ≤ s.infsep :=
hs.le_infsep_iff.2 h
theorem le_edist_of_le_infsep {d x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y)
(hd : d ≤ s.infsep) : d ≤ dist x y := by
by_cases hs : s.Nontrivial
· exact hs.le_infsep_iff.1 hd x hx y hy hxy
· rw [not_nontrivial_iff] at hs
rw [hs.infsep_zero] at hd
exact le_trans hd dist_nonneg
theorem infsep_le_dist_of_mem (hx : x ∈ s) (hy : y ∈ s) (hxy : x ≠ y) : s.infsep ≤ dist x y :=
le_edist_of_le_infsep hx hy hxy le_rfl
theorem infsep_le_of_mem_of_edist_le {d x} (hx : x ∈ s) {y} (hy : y ∈ s) (hxy : x ≠ y)
(hxy' : dist x y ≤ d) : s.infsep ≤ d :=
le_trans (infsep_le_dist_of_mem hx hy hxy) hxy'
theorem infsep_pair : ({x, y} : Set α).infsep = dist x y := by
rw [infsep_pair_eq_toReal, edist_dist]
exact ENNReal.toReal_ofReal dist_nonneg
theorem infsep_triple (hxy : x ≠ y) (hyz : y ≠ z) (hxz : x ≠ z) :
({x, y, z} : Set α).infsep = dist x y ⊓ dist x z ⊓ dist y z := by
simp only [infsep, einfsep_triple hxy hyz hxz, ENNReal.toReal_inf, edist_ne_top x y,
edist_ne_top x z, edist_ne_top y z, dist_edist, Ne, inf_eq_top_iff, and_self_iff,
not_false_iff]
theorem Nontrivial.infsep_anti (hs : s.Nontrivial) (hst : s ⊆ t) : t.infsep ≤ s.infsep :=
ENNReal.toReal_mono hs.einfsep_ne_top (einfsep_anti hst)
theorem infsep_eq_iInf [Decidable s.Nontrivial] :
s.infsep = if s.Nontrivial then ⨅ d : s.offDiag, (uncurry dist) (d : α × α) else 0 := by
split_ifs with hs
· have hb : BddBelow (uncurry dist '' s.offDiag) := by
refine ⟨0, fun d h => ?_⟩
simp_rw [mem_image, Prod.exists, uncurry_apply_pair] at h
rcases h with ⟨_, _, _, rfl⟩
exact dist_nonneg
refine eq_of_forall_le_iff fun _ => ?_
simp_rw [hs.le_infsep_iff, le_ciInf_set_iff (offDiag_nonempty.mpr hs) hb, imp_forall_iff,
mem_offDiag, Prod.forall, uncurry_apply_pair, and_imp]
· exact (not_nontrivial_iff.mp hs).infsep_zero
theorem Nontrivial.infsep_eq_iInf (hs : s.Nontrivial) :
s.infsep = ⨅ d : s.offDiag, (uncurry dist) (d : α × α) := by
classical rw [Set.infsep_eq_iInf, if_pos hs]
theorem infsep_of_fintype [Decidable s.Nontrivial] [DecidableEq α] [Fintype s] : s.infsep =
if hs : s.Nontrivial then s.offDiag.toFinset.inf' (by simpa) (uncurry dist) else 0 := by
split_ifs with hs
· refine eq_of_forall_le_iff fun _ => ?_
simp_rw [hs.le_infsep_iff, imp_forall_iff, Finset.le_inf'_iff, mem_toFinset, mem_offDiag,
Prod.forall, uncurry_apply_pair, and_imp]
· rw [not_nontrivial_iff] at hs
exact hs.infsep_zero
theorem Nontrivial.infsep_of_fintype [DecidableEq α] [Fintype s] (hs : s.Nontrivial) :
s.infsep = s.offDiag.toFinset.inf' (by simpa) (uncurry dist) := by
classical rw [Set.infsep_of_fintype, dif_pos hs]
theorem Finite.infsep [Decidable s.Nontrivial] (hsf : s.Finite) :
s.infsep =
if hs : s.Nontrivial then hsf.offDiag.toFinset.inf' (by simpa) (uncurry dist) else 0 := by
split_ifs with hs
· refine eq_of_forall_le_iff fun _ => ?_
simp_rw [hs.le_infsep_iff, imp_forall_iff, Finset.le_inf'_iff, Finite.mem_toFinset,
mem_offDiag, Prod.forall, uncurry_apply_pair, and_imp]
· rw [not_nontrivial_iff] at hs
exact hs.infsep_zero
theorem Finite.infsep_of_nontrivial (hsf : s.Finite) (hs : s.Nontrivial) :
s.infsep = hsf.offDiag.toFinset.inf' (by simpa) (uncurry dist) := by
classical simp_rw [hsf.infsep, dif_pos hs]
theorem _root_.Finset.coe_infsep [DecidableEq α] (s : Finset α) : (s : Set α).infsep =
if hs : s.offDiag.Nonempty then s.offDiag.inf' hs (uncurry dist) else 0 := by
have H : (s : Set α).Nontrivial ↔ s.offDiag.Nonempty := by
rw [← Set.offDiag_nonempty, ← Finset.coe_offDiag, Finset.coe_nonempty]
split_ifs with hs
· simp_rw [(H.mpr hs).infsep_of_fintype, ← Finset.coe_offDiag, Finset.toFinset_coe]
· exact (not_nontrivial_iff.mp (H.mp.mt hs)).infsep_zero
theorem _root_.Finset.coe_infsep_of_offDiag_nonempty [DecidableEq α] {s : Finset α}
(hs : s.offDiag.Nonempty) : (s : Set α).infsep = s.offDiag.inf' hs (uncurry dist) := by
rw [Finset.coe_infsep, dif_pos hs]
| Mathlib/Topology/MetricSpace/Infsep.lean | 428 | 432 | theorem _root_.Finset.coe_infsep_of_offDiag_empty
[DecidableEq α] {s : Finset α} (hs : s.offDiag = ∅) : (s : Set α).infsep = 0 := by | rw [← Finset.not_nonempty_iff_eq_empty] at hs
rw [Finset.coe_infsep, dif_neg hs] |
/-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Kenny Lau
-/
import Mathlib.RingTheory.MvPowerSeries.Basic
import Mathlib.Data.Finsupp.Interval
import Mathlib.Algebra.MvPolynomial.Eval
/-!
# Formal (multivariate) power series - Truncation
* `MvPowerSeries.trunc n φ` truncates a formal multivariate power series
to the multivariate polynomial that has the same coefficients as `φ`,
for all `m < n`, and `0` otherwise.
Note that here, `m` and `n` have types `σ →₀ ℕ`,
so that `m < n` means that `m ≠ n` and `m s ≤ n s` for all `s : σ`.
* `MvPowerSeries.trunc_one` : truncation of the unit power series
* `MvPowerSeries.trunc_C` : truncation of a constant
* `MvPowerSeries.trunc_C_mul` : truncation of constant multiple.
* `MvPowerSeries.trunc' n φ` truncates a formal multivariate power series
to the multivariate polynomial that has the same coefficients as `φ`,
for all `m ≤ n`, and `0` otherwise.
Here, `m` and `n` have types `σ →₀ ℕ` so that `m ≤ n` means that `m s ≤ n s` for all `s : σ`.
* `MvPowerSeries.coeff_mul_eq_coeff_trunc'_mul_trunc'` : compares the coefficients
of a product with those of the product of truncations.
* `MvPowerSeries.trunc'_one` : truncation of a the unit power series.
* `MvPowerSeries.trunc'_C` : truncation of a constant.
* `MvPowerSeries.trunc'_C_mul` : truncation of a constant multiple.
* `MvPowerSeries.trunc'_map` : image of a truncation under a change of rings
## TODO
* Unify both versions using a general purpose API
-/
noncomputable section
open Finset (antidiagonal mem_antidiagonal)
namespace MvPowerSeries
open Finsupp
variable {σ R S : Type*}
section TruncLT
variable [DecidableEq σ] [CommSemiring R] (n : σ →₀ ℕ)
/-- Auxiliary definition for the truncation function. -/
def truncFun (φ : MvPowerSeries σ R) : MvPolynomial σ R :=
∑ m ∈ Finset.Iio n, MvPolynomial.monomial m (coeff R m φ)
| Mathlib/RingTheory/MvPowerSeries/Trunc.lean | 71 | 73 | theorem coeff_truncFun (m : σ →₀ ℕ) (φ : MvPowerSeries σ R) :
(truncFun n φ).coeff m = if m < n then coeff R m φ else 0 := by | classical |
/-
Copyright (c) 2018 Michael Jendrusch. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Jendrusch, Kim Morrison, Bhavik Mehta, Jakob von Raumer
-/
import Mathlib.CategoryTheory.EqToHom
import Mathlib.CategoryTheory.Functor.Trifunctor
import Mathlib.CategoryTheory.Products.Basic
/-!
# Monoidal categories
A monoidal category is a category equipped with a tensor product, unitors, and an associator.
In the definition, we provide the tensor product as a pair of functions
* `tensorObj : C → C → C`
* `tensorHom : (X₁ ⟶ Y₁) → (X₂ ⟶ Y₂) → ((X₁ ⊗ X₂) ⟶ (Y₁ ⊗ Y₂))`
and allow use of the overloaded notation `⊗` for both.
The unitors and associator are provided componentwise.
The tensor product can be expressed as a functor via `tensor : C × C ⥤ C`.
The unitors and associator are gathered together as natural
isomorphisms in `leftUnitor_nat_iso`, `rightUnitor_nat_iso` and `associator_nat_iso`.
Some consequences of the definition are proved in other files after proving the coherence theorem,
e.g. `(λ_ (𝟙_ C)).hom = (ρ_ (𝟙_ C)).hom` in `CategoryTheory.Monoidal.CoherenceLemmas`.
## Implementation notes
In the definition of monoidal categories, we also provide the whiskering operators:
* `whiskerLeft (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : X ⊗ Y₁ ⟶ X ⊗ Y₂`, denoted by `X ◁ f`,
* `whiskerRight {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : X₁ ⊗ Y ⟶ X₂ ⊗ Y`, denoted by `f ▷ Y`.
These are products of an object and a morphism (the terminology "whiskering"
is borrowed from 2-category theory). The tensor product of morphisms `tensorHom` can be defined
in terms of the whiskerings. There are two possible such definitions, which are related by
the exchange property of the whiskerings. These two definitions are accessed by `tensorHom_def`
and `tensorHom_def'`. By default, `tensorHom` is defined so that `tensorHom_def` holds
definitionally.
If you want to provide `tensorHom` and define `whiskerLeft` and `whiskerRight` in terms of it,
you can use the alternative constructor `CategoryTheory.MonoidalCategory.ofTensorHom`.
The whiskerings are useful when considering simp-normal forms of morphisms in monoidal categories.
### Simp-normal form for morphisms
Rewriting involving associators and unitors could be very complicated. We try to ease this
complexity by putting carefully chosen simp lemmas that rewrite any morphisms into the simp-normal
form defined below. Rewriting into simp-normal form is especially useful in preprocessing
performed by the `coherence` tactic.
The simp-normal form of morphisms is defined to be an expression that has the minimal number of
parentheses. More precisely,
1. it is a composition of morphisms like `f₁ ≫ f₂ ≫ f₃ ≫ f₄ ≫ f₅` such that each `fᵢ` is
either a structural morphisms (morphisms made up only of identities, associators, unitors)
or non-structural morphisms, and
2. each non-structural morphism in the composition is of the form `X₁ ◁ X₂ ◁ X₃ ◁ f ▷ X₄ ▷ X₅`,
where each `Xᵢ` is a object that is not the identity or a tensor and `f` is a non-structural
morphisms that is not the identity or a composite.
Note that `X₁ ◁ X₂ ◁ X₃ ◁ f ▷ X₄ ▷ X₅` is actually `X₁ ◁ (X₂ ◁ (X₃ ◁ ((f ▷ X₄) ▷ X₅)))`.
Currently, the simp lemmas don't rewrite `𝟙 X ⊗ f` and `f ⊗ 𝟙 Y` into `X ◁ f` and `f ▷ Y`,
respectively, since it requires a huge refactoring. We hope to add these simp lemmas soon.
## References
* Tensor categories, Etingof, Gelaki, Nikshych, Ostrik,
http://www-math.mit.edu/~etingof/egnobookfinal.pdf
* <https://stacks.math.columbia.edu/tag/0FFK>.
-/
universe v u
open CategoryTheory.Category
open CategoryTheory.Iso
namespace CategoryTheory
/-- Auxiliary structure to carry only the data fields of (and provide notation for)
`MonoidalCategory`. -/
class MonoidalCategoryStruct (C : Type u) [𝒞 : Category.{v} C] where
/-- curried tensor product of objects -/
tensorObj : C → C → C
/-- left whiskering for morphisms -/
whiskerLeft (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) : tensorObj X Y₁ ⟶ tensorObj X Y₂
/-- right whiskering for morphisms -/
whiskerRight {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) : tensorObj X₁ Y ⟶ tensorObj X₂ Y
/-- Tensor product of identity maps is the identity: `(𝟙 X₁ ⊗ 𝟙 X₂) = 𝟙 (X₁ ⊗ X₂)` -/
-- By default, it is defined in terms of whiskerings.
tensorHom {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) : (tensorObj X₁ X₂ ⟶ tensorObj Y₁ Y₂) :=
whiskerRight f X₂ ≫ whiskerLeft Y₁ g
/-- The tensor unity in the monoidal structure `𝟙_ C` -/
tensorUnit (C) : C
/-- The associator isomorphism `(X ⊗ Y) ⊗ Z ≃ X ⊗ (Y ⊗ Z)` -/
associator : ∀ X Y Z : C, tensorObj (tensorObj X Y) Z ≅ tensorObj X (tensorObj Y Z)
/-- The left unitor: `𝟙_ C ⊗ X ≃ X` -/
leftUnitor : ∀ X : C, tensorObj tensorUnit X ≅ X
/-- The right unitor: `X ⊗ 𝟙_ C ≃ X` -/
rightUnitor : ∀ X : C, tensorObj X tensorUnit ≅ X
namespace MonoidalCategory
export MonoidalCategoryStruct
(tensorObj whiskerLeft whiskerRight tensorHom tensorUnit associator leftUnitor rightUnitor)
end MonoidalCategory
namespace MonoidalCategory
/-- Notation for `tensorObj`, the tensor product of objects in a monoidal category -/
scoped infixr:70 " ⊗ " => MonoidalCategoryStruct.tensorObj
/-- Notation for the `whiskerLeft` operator of monoidal categories -/
scoped infixr:81 " ◁ " => MonoidalCategoryStruct.whiskerLeft
/-- Notation for the `whiskerRight` operator of monoidal categories -/
scoped infixl:81 " ▷ " => MonoidalCategoryStruct.whiskerRight
/-- Notation for `tensorHom`, the tensor product of morphisms in a monoidal category -/
scoped infixr:70 " ⊗ " => MonoidalCategoryStruct.tensorHom
/-- Notation for `tensorUnit`, the two-sided identity of `⊗` -/
scoped notation "𝟙_ " C:arg => MonoidalCategoryStruct.tensorUnit C
/-- Notation for the monoidal `associator`: `(X ⊗ Y) ⊗ Z ≃ X ⊗ (Y ⊗ Z)` -/
scoped notation "α_" => MonoidalCategoryStruct.associator
/-- Notation for the `leftUnitor`: `𝟙_C ⊗ X ≃ X` -/
scoped notation "λ_" => MonoidalCategoryStruct.leftUnitor
/-- Notation for the `rightUnitor`: `X ⊗ 𝟙_C ≃ X` -/
scoped notation "ρ_" => MonoidalCategoryStruct.rightUnitor
/-- The property that the pentagon relation is satisfied by four objects
in a category equipped with a `MonoidalCategoryStruct`. -/
def Pentagon {C : Type u} [Category.{v} C] [MonoidalCategoryStruct C]
(Y₁ Y₂ Y₃ Y₄ : C) : Prop :=
(α_ Y₁ Y₂ Y₃).hom ▷ Y₄ ≫ (α_ Y₁ (Y₂ ⊗ Y₃) Y₄).hom ≫ Y₁ ◁ (α_ Y₂ Y₃ Y₄).hom =
(α_ (Y₁ ⊗ Y₂) Y₃ Y₄).hom ≫ (α_ Y₁ Y₂ (Y₃ ⊗ Y₄)).hom
end MonoidalCategory
open MonoidalCategory
/--
In a monoidal category, we can take the tensor product of objects, `X ⊗ Y` and of morphisms `f ⊗ g`.
Tensor product does not need to be strictly associative on objects, but there is a
specified associator, `α_ X Y Z : (X ⊗ Y) ⊗ Z ≅ X ⊗ (Y ⊗ Z)`. There is a tensor unit `𝟙_ C`,
with specified left and right unitor isomorphisms `λ_ X : 𝟙_ C ⊗ X ≅ X` and `ρ_ X : X ⊗ 𝟙_ C ≅ X`.
These associators and unitors satisfy the pentagon and triangle equations. -/
@[stacks 0FFK]
-- Porting note: The Mathport did not translate the temporary notation
class MonoidalCategory (C : Type u) [𝒞 : Category.{v} C] extends MonoidalCategoryStruct C where
tensorHom_def {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) :
f ⊗ g = (f ▷ X₂) ≫ (Y₁ ◁ g) := by
aesop_cat
/-- Tensor product of identity maps is the identity: `(𝟙 X₁ ⊗ 𝟙 X₂) = 𝟙 (X₁ ⊗ X₂)` -/
tensor_id : ∀ X₁ X₂ : C, 𝟙 X₁ ⊗ 𝟙 X₂ = 𝟙 (X₁ ⊗ X₂) := by aesop_cat
/--
Tensor product of compositions is composition of tensor products:
`(f₁ ≫ g₁) ⊗ (f₂ ≫ g₂) = (f₁ ⊗ f₂) ≫ (g₁ ⊗ g₂)`
-/
tensor_comp :
∀ {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (g₁ : Y₁ ⟶ Z₁) (g₂ : Y₂ ⟶ Z₂),
(f₁ ≫ g₁) ⊗ (f₂ ≫ g₂) = (f₁ ⊗ f₂) ≫ (g₁ ⊗ g₂) := by
aesop_cat
whiskerLeft_id : ∀ (X Y : C), X ◁ 𝟙 Y = 𝟙 (X ⊗ Y) := by
aesop_cat
id_whiskerRight : ∀ (X Y : C), 𝟙 X ▷ Y = 𝟙 (X ⊗ Y) := by
aesop_cat
/-- Naturality of the associator isomorphism: `(f₁ ⊗ f₂) ⊗ f₃ ≃ f₁ ⊗ (f₂ ⊗ f₃)` -/
associator_naturality :
∀ {X₁ X₂ X₃ Y₁ Y₂ Y₃ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (f₃ : X₃ ⟶ Y₃),
((f₁ ⊗ f₂) ⊗ f₃) ≫ (α_ Y₁ Y₂ Y₃).hom = (α_ X₁ X₂ X₃).hom ≫ (f₁ ⊗ (f₂ ⊗ f₃)) := by
aesop_cat
/--
Naturality of the left unitor, commutativity of `𝟙_ C ⊗ X ⟶ 𝟙_ C ⊗ Y ⟶ Y` and `𝟙_ C ⊗ X ⟶ X ⟶ Y`
-/
leftUnitor_naturality :
∀ {X Y : C} (f : X ⟶ Y), 𝟙_ _ ◁ f ≫ (λ_ Y).hom = (λ_ X).hom ≫ f := by
aesop_cat
/--
Naturality of the right unitor: commutativity of `X ⊗ 𝟙_ C ⟶ Y ⊗ 𝟙_ C ⟶ Y` and `X ⊗ 𝟙_ C ⟶ X ⟶ Y`
-/
rightUnitor_naturality :
∀ {X Y : C} (f : X ⟶ Y), f ▷ 𝟙_ _ ≫ (ρ_ Y).hom = (ρ_ X).hom ≫ f := by
aesop_cat
/--
The pentagon identity relating the isomorphism between `X ⊗ (Y ⊗ (Z ⊗ W))` and `((X ⊗ Y) ⊗ Z) ⊗ W`
-/
pentagon :
∀ W X Y Z : C,
(α_ W X Y).hom ▷ Z ≫ (α_ W (X ⊗ Y) Z).hom ≫ W ◁ (α_ X Y Z).hom =
(α_ (W ⊗ X) Y Z).hom ≫ (α_ W X (Y ⊗ Z)).hom := by
aesop_cat
/--
The identity relating the isomorphisms between `X ⊗ (𝟙_ C ⊗ Y)`, `(X ⊗ 𝟙_ C) ⊗ Y` and `X ⊗ Y`
-/
triangle :
∀ X Y : C, (α_ X (𝟙_ _) Y).hom ≫ X ◁ (λ_ Y).hom = (ρ_ X).hom ▷ Y := by
aesop_cat
attribute [reassoc] MonoidalCategory.tensorHom_def
attribute [reassoc, simp] MonoidalCategory.whiskerLeft_id
attribute [reassoc, simp] MonoidalCategory.id_whiskerRight
attribute [reassoc] MonoidalCategory.tensor_comp
attribute [simp] MonoidalCategory.tensor_comp
attribute [reassoc] MonoidalCategory.associator_naturality
attribute [reassoc] MonoidalCategory.leftUnitor_naturality
attribute [reassoc] MonoidalCategory.rightUnitor_naturality
attribute [reassoc (attr := simp)] MonoidalCategory.pentagon
attribute [reassoc (attr := simp)] MonoidalCategory.triangle
namespace MonoidalCategory
variable {C : Type u} [𝒞 : Category.{v} C] [MonoidalCategory C]
@[simp]
theorem id_tensorHom (X : C) {Y₁ Y₂ : C} (f : Y₁ ⟶ Y₂) :
𝟙 X ⊗ f = X ◁ f := by
simp [tensorHom_def]
@[simp]
theorem tensorHom_id {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) :
f ⊗ 𝟙 Y = f ▷ Y := by
simp [tensorHom_def]
@[reassoc, simp]
theorem whiskerLeft_comp (W : C) {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) :
W ◁ (f ≫ g) = W ◁ f ≫ W ◁ g := by
simp only [← id_tensorHom, ← tensor_comp, comp_id]
@[reassoc, simp]
theorem id_whiskerLeft {X Y : C} (f : X ⟶ Y) :
𝟙_ C ◁ f = (λ_ X).hom ≫ f ≫ (λ_ Y).inv := by
rw [← assoc, ← leftUnitor_naturality]; simp [id_tensorHom]
@[reassoc, simp]
theorem tensor_whiskerLeft (X Y : C) {Z Z' : C} (f : Z ⟶ Z') :
(X ⊗ Y) ◁ f = (α_ X Y Z).hom ≫ X ◁ Y ◁ f ≫ (α_ X Y Z').inv := by
simp only [← id_tensorHom, ← tensorHom_id]
rw [← assoc, ← associator_naturality]
simp
@[reassoc, simp]
theorem comp_whiskerRight {W X Y : C} (f : W ⟶ X) (g : X ⟶ Y) (Z : C) :
(f ≫ g) ▷ Z = f ▷ Z ≫ g ▷ Z := by
simp only [← tensorHom_id, ← tensor_comp, id_comp]
@[reassoc, simp]
theorem whiskerRight_id {X Y : C} (f : X ⟶ Y) :
f ▷ 𝟙_ C = (ρ_ X).hom ≫ f ≫ (ρ_ Y).inv := by
rw [← assoc, ← rightUnitor_naturality]; simp [tensorHom_id]
@[reassoc, simp]
theorem whiskerRight_tensor {X X' : C} (f : X ⟶ X') (Y Z : C) :
f ▷ (Y ⊗ Z) = (α_ X Y Z).inv ≫ f ▷ Y ▷ Z ≫ (α_ X' Y Z).hom := by
simp only [← id_tensorHom, ← tensorHom_id]
rw [associator_naturality]
simp [tensor_id]
@[reassoc, simp]
theorem whisker_assoc (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) :
(X ◁ f) ▷ Z = (α_ X Y Z).hom ≫ X ◁ f ▷ Z ≫ (α_ X Y' Z).inv := by
simp only [← id_tensorHom, ← tensorHom_id]
rw [← assoc, ← associator_naturality]
simp
@[reassoc]
theorem whisker_exchange {W X Y Z : C} (f : W ⟶ X) (g : Y ⟶ Z) :
W ◁ g ≫ f ▷ Z = f ▷ Y ≫ X ◁ g := by
simp only [← id_tensorHom, ← tensorHom_id, ← tensor_comp, id_comp, comp_id]
@[reassoc]
theorem tensorHom_def' {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ⟶ Y₁) (g : X₂ ⟶ Y₂) :
f ⊗ g = X₁ ◁ g ≫ f ▷ Y₂ :=
whisker_exchange f g ▸ tensorHom_def f g
@[reassoc (attr := simp)]
theorem whiskerLeft_hom_inv (X : C) {Y Z : C} (f : Y ≅ Z) :
X ◁ f.hom ≫ X ◁ f.inv = 𝟙 (X ⊗ Y) := by
rw [← whiskerLeft_comp, hom_inv_id, whiskerLeft_id]
@[reassoc (attr := simp)]
theorem hom_inv_whiskerRight {X Y : C} (f : X ≅ Y) (Z : C) :
f.hom ▷ Z ≫ f.inv ▷ Z = 𝟙 (X ⊗ Z) := by
rw [← comp_whiskerRight, hom_inv_id, id_whiskerRight]
@[reassoc (attr := simp)]
theorem whiskerLeft_inv_hom (X : C) {Y Z : C} (f : Y ≅ Z) :
X ◁ f.inv ≫ X ◁ f.hom = 𝟙 (X ⊗ Z) := by
rw [← whiskerLeft_comp, inv_hom_id, whiskerLeft_id]
@[reassoc (attr := simp)]
theorem inv_hom_whiskerRight {X Y : C} (f : X ≅ Y) (Z : C) :
f.inv ▷ Z ≫ f.hom ▷ Z = 𝟙 (Y ⊗ Z) := by
rw [← comp_whiskerRight, inv_hom_id, id_whiskerRight]
@[reassoc (attr := simp)]
theorem whiskerLeft_hom_inv' (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] :
X ◁ f ≫ X ◁ inv f = 𝟙 (X ⊗ Y) := by
rw [← whiskerLeft_comp, IsIso.hom_inv_id, whiskerLeft_id]
@[reassoc (attr := simp)]
theorem hom_inv_whiskerRight' {X Y : C} (f : X ⟶ Y) [IsIso f] (Z : C) :
f ▷ Z ≫ inv f ▷ Z = 𝟙 (X ⊗ Z) := by
rw [← comp_whiskerRight, IsIso.hom_inv_id, id_whiskerRight]
@[reassoc (attr := simp)]
theorem whiskerLeft_inv_hom' (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] :
X ◁ inv f ≫ X ◁ f = 𝟙 (X ⊗ Z) := by
rw [← whiskerLeft_comp, IsIso.inv_hom_id, whiskerLeft_id]
@[reassoc (attr := simp)]
theorem inv_hom_whiskerRight' {X Y : C} (f : X ⟶ Y) [IsIso f] (Z : C) :
inv f ▷ Z ≫ f ▷ Z = 𝟙 (Y ⊗ Z) := by
rw [← comp_whiskerRight, IsIso.inv_hom_id, id_whiskerRight]
/-- The left whiskering of an isomorphism is an isomorphism. -/
@[simps]
def whiskerLeftIso (X : C) {Y Z : C} (f : Y ≅ Z) : X ⊗ Y ≅ X ⊗ Z where
hom := X ◁ f.hom
inv := X ◁ f.inv
instance whiskerLeft_isIso (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] : IsIso (X ◁ f) :=
(whiskerLeftIso X (asIso f)).isIso_hom
@[simp]
theorem inv_whiskerLeft (X : C) {Y Z : C} (f : Y ⟶ Z) [IsIso f] :
inv (X ◁ f) = X ◁ inv f := by
aesop_cat
@[simp]
lemma whiskerLeftIso_refl (W X : C) :
whiskerLeftIso W (Iso.refl X) = Iso.refl (W ⊗ X) :=
Iso.ext (whiskerLeft_id W X)
@[simp]
lemma whiskerLeftIso_trans (W : C) {X Y Z : C} (f : X ≅ Y) (g : Y ≅ Z) :
whiskerLeftIso W (f ≪≫ g) = whiskerLeftIso W f ≪≫ whiskerLeftIso W g :=
Iso.ext (whiskerLeft_comp W f.hom g.hom)
@[simp]
lemma whiskerLeftIso_symm (W : C) {X Y : C} (f : X ≅ Y) :
(whiskerLeftIso W f).symm = whiskerLeftIso W f.symm := rfl
/-- The right whiskering of an isomorphism is an isomorphism. -/
@[simps!]
def whiskerRightIso {X Y : C} (f : X ≅ Y) (Z : C) : X ⊗ Z ≅ Y ⊗ Z where
hom := f.hom ▷ Z
inv := f.inv ▷ Z
instance whiskerRight_isIso {X Y : C} (f : X ⟶ Y) (Z : C) [IsIso f] : IsIso (f ▷ Z) :=
(whiskerRightIso (asIso f) Z).isIso_hom
@[simp]
theorem inv_whiskerRight {X Y : C} (f : X ⟶ Y) (Z : C) [IsIso f] :
inv (f ▷ Z) = inv f ▷ Z := by
aesop_cat
@[simp]
lemma whiskerRightIso_refl (X W : C) :
whiskerRightIso (Iso.refl X) W = Iso.refl (X ⊗ W) :=
Iso.ext (id_whiskerRight X W)
@[simp]
lemma whiskerRightIso_trans {X Y Z : C} (f : X ≅ Y) (g : Y ≅ Z) (W : C) :
whiskerRightIso (f ≪≫ g) W = whiskerRightIso f W ≪≫ whiskerRightIso g W :=
Iso.ext (comp_whiskerRight f.hom g.hom W)
@[simp]
lemma whiskerRightIso_symm {X Y : C} (f : X ≅ Y) (W : C) :
(whiskerRightIso f W).symm = whiskerRightIso f.symm W := rfl
/-- The tensor product of two isomorphisms is an isomorphism. -/
@[simps]
def tensorIso {X Y X' Y' : C} (f : X ≅ Y)
(g : X' ≅ Y') : X ⊗ X' ≅ Y ⊗ Y' where
hom := f.hom ⊗ g.hom
inv := f.inv ⊗ g.inv
hom_inv_id := by rw [← tensor_comp, Iso.hom_inv_id, Iso.hom_inv_id, ← tensor_id]
inv_hom_id := by rw [← tensor_comp, Iso.inv_hom_id, Iso.inv_hom_id, ← tensor_id]
/-- Notation for `tensorIso`, the tensor product of isomorphisms -/
scoped infixr:70 " ⊗ " => tensorIso
theorem tensorIso_def {X Y X' Y' : C} (f : X ≅ Y) (g : X' ≅ Y') :
f ⊗ g = whiskerRightIso f X' ≪≫ whiskerLeftIso Y g :=
Iso.ext (tensorHom_def f.hom g.hom)
theorem tensorIso_def' {X Y X' Y' : C} (f : X ≅ Y) (g : X' ≅ Y') :
f ⊗ g = whiskerLeftIso X g ≪≫ whiskerRightIso f Y' :=
Iso.ext (tensorHom_def' f.hom g.hom)
instance tensor_isIso {W X Y Z : C} (f : W ⟶ X) [IsIso f] (g : Y ⟶ Z) [IsIso g] : IsIso (f ⊗ g) :=
(asIso f ⊗ asIso g).isIso_hom
@[simp]
theorem inv_tensor {W X Y Z : C} (f : W ⟶ X) [IsIso f] (g : Y ⟶ Z) [IsIso g] :
inv (f ⊗ g) = inv f ⊗ inv g := by
simp [tensorHom_def ,whisker_exchange]
variable {W X Y Z : C}
theorem whiskerLeft_dite {P : Prop} [Decidable P]
(X : C) {Y Z : C} (f : P → (Y ⟶ Z)) (f' : ¬P → (Y ⟶ Z)) :
X ◁ (if h : P then f h else f' h) = if h : P then X ◁ f h else X ◁ f' h := by
split_ifs <;> rfl
theorem dite_whiskerRight {P : Prop} [Decidable P]
{X Y : C} (f : P → (X ⟶ Y)) (f' : ¬P → (X ⟶ Y)) (Z : C) :
(if h : P then f h else f' h) ▷ Z = if h : P then f h ▷ Z else f' h ▷ Z := by
split_ifs <;> rfl
theorem tensor_dite {P : Prop} [Decidable P] {W X Y Z : C} (f : W ⟶ X) (g : P → (Y ⟶ Z))
(g' : ¬P → (Y ⟶ Z)) : (f ⊗ if h : P then g h else g' h) =
if h : P then f ⊗ g h else f ⊗ g' h := by split_ifs <;> rfl
theorem dite_tensor {P : Prop} [Decidable P] {W X Y Z : C} (f : W ⟶ X) (g : P → (Y ⟶ Z))
(g' : ¬P → (Y ⟶ Z)) : (if h : P then g h else g' h) ⊗ f =
if h : P then g h ⊗ f else g' h ⊗ f := by split_ifs <;> rfl
@[simp]
theorem whiskerLeft_eqToHom (X : C) {Y Z : C} (f : Y = Z) :
X ◁ eqToHom f = eqToHom (congr_arg₂ tensorObj rfl f) := by
cases f
simp only [whiskerLeft_id, eqToHom_refl]
@[simp]
theorem eqToHom_whiskerRight {X Y : C} (f : X = Y) (Z : C) :
eqToHom f ▷ Z = eqToHom (congr_arg₂ tensorObj f rfl) := by
cases f
simp only [id_whiskerRight, eqToHom_refl]
@[reassoc]
theorem associator_naturality_left {X X' : C} (f : X ⟶ X') (Y Z : C) :
f ▷ Y ▷ Z ≫ (α_ X' Y Z).hom = (α_ X Y Z).hom ≫ f ▷ (Y ⊗ Z) := by simp
@[reassoc]
theorem associator_inv_naturality_left {X X' : C} (f : X ⟶ X') (Y Z : C) :
f ▷ (Y ⊗ Z) ≫ (α_ X' Y Z).inv = (α_ X Y Z).inv ≫ f ▷ Y ▷ Z := by simp
@[reassoc]
theorem whiskerRight_tensor_symm {X X' : C} (f : X ⟶ X') (Y Z : C) :
f ▷ Y ▷ Z = (α_ X Y Z).hom ≫ f ▷ (Y ⊗ Z) ≫ (α_ X' Y Z).inv := by simp
@[reassoc]
theorem associator_naturality_middle (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) :
(X ◁ f) ▷ Z ≫ (α_ X Y' Z).hom = (α_ X Y Z).hom ≫ X ◁ f ▷ Z := by simp
@[reassoc]
| Mathlib/CategoryTheory/Monoidal/Category.lean | 452 | 455 | theorem associator_inv_naturality_middle (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) :
X ◁ f ▷ Z ≫ (α_ X Y' Z).inv = (α_ X Y Z).inv ≫ (X ◁ f) ▷ Z := by | simp
@[reassoc] |
/-
Copyright (c) 2023 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Algebra.Ring.CharZero
import Mathlib.Algebra.Ring.Int.Units
import Mathlib.GroupTheory.Coprod.Basic
import Mathlib.GroupTheory.Complement
/-!
## HNN Extensions of Groups
This file defines the HNN extension of a group `G`, `HNNExtension G A B φ`. Given a group `G`,
subgroups `A` and `B` and an isomorphism `φ` of `A` and `B`, we adjoin a letter `t` to `G`, such
that for any `a ∈ A`, the conjugate of `of a` by `t` is `of (φ a)`, where `of` is the canonical map
from `G` into the `HNNExtension`. This construction is named after Graham Higman, Bernhard Neumann
and Hanna Neumann.
## Main definitions
- `HNNExtension G A B φ` : The HNN Extension of a group `G`, where `A` and `B` are subgroups and `φ`
is an isomorphism between `A` and `B`.
- `HNNExtension.of` : The canonical embedding of `G` into `HNNExtension G A B φ`.
- `HNNExtension.t` : The stable letter of the HNN extension.
- `HNNExtension.lift` : Define a function `HNNExtension G A B φ →* H`, by defining it on `G` and `t`
- `HNNExtension.of_injective` : The canonical embedding `G →* HNNExtension G A B φ` is injective.
- `HNNExtension.ReducedWord.toList_eq_nil_of_mem_of_range` : Britton's Lemma. If an element of
`G` is represented by a reduced word, then this reduced word does not contain `t`.
-/
assert_not_exists Field
open Monoid Coprod Multiplicative Subgroup Function
/-- The relation we quotient the coproduct by to form an `HNNExtension`. -/
def HNNExtension.con (G : Type*) [Group G] (A B : Subgroup G) (φ : A ≃* B) :
Con (G ∗ Multiplicative ℤ) :=
conGen (fun x y => ∃ (a : A),
x = inr (ofAdd 1) * inl (a : G) ∧
y = inl (φ a : G) * inr (ofAdd 1))
/-- The HNN Extension of a group `G`, `HNNExtension G A B φ`. Given a group `G`, subgroups `A` and
`B` and an isomorphism `φ` of `A` and `B`, we adjoin a letter `t` to `G`, such that for
any `a ∈ A`, the conjugate of `of a` by `t` is `of (φ a)`, where `of` is the canonical
map from `G` into the `HNNExtension`. -/
def HNNExtension (G : Type*) [Group G] (A B : Subgroup G) (φ : A ≃* B) : Type _ :=
(HNNExtension.con G A B φ).Quotient
variable {G : Type*} [Group G] {A B : Subgroup G} {φ : A ≃* B} {H : Type*}
[Group H] {M : Type*} [Monoid M]
instance : Group (HNNExtension G A B φ) := by
delta HNNExtension; infer_instance
namespace HNNExtension
/-- The canonical embedding `G →* HNNExtension G A B φ` -/
def of : G →* HNNExtension G A B φ :=
(HNNExtension.con G A B φ).mk'.comp inl
/-- The stable letter of the `HNNExtension` -/
def t : HNNExtension G A B φ :=
(HNNExtension.con G A B φ).mk'.comp inr (ofAdd 1)
theorem t_mul_of (a : A) :
t * (of (a : G) : HNNExtension G A B φ) = of (φ a : G) * t :=
(Con.eq _).2 <| ConGen.Rel.of _ _ <| ⟨a, by simp⟩
theorem of_mul_t (b : B) :
(of (b : G) : HNNExtension G A B φ) * t = t * of (φ.symm b : G) := by
rw [t_mul_of]; simp
theorem equiv_eq_conj (a : A) :
(of (φ a : G) : HNNExtension G A B φ) = t * of (a : G) * t⁻¹ := by
rw [t_mul_of]; simp
theorem equiv_symm_eq_conj (b : B) :
(of (φ.symm b : G) : HNNExtension G A B φ) = t⁻¹ * of (b : G) * t := by
rw [mul_assoc, of_mul_t]; simp
theorem inv_t_mul_of (b : B) :
t⁻¹ * (of (b : G) : HNNExtension G A B φ) = of (φ.symm b : G) * t⁻¹ := by
rw [equiv_symm_eq_conj]; simp
theorem of_mul_inv_t (a : A) :
(of (a : G) : HNNExtension G A B φ) * t⁻¹ = t⁻¹ * of (φ a : G) := by
rw [equiv_eq_conj]; simp [mul_assoc]
/-- Define a function `HNNExtension G A B φ →* H`, by defining it on `G` and `t` -/
def lift (f : G →* H) (x : H) (hx : ∀ a : A, x * f ↑a = f (φ a : G) * x) :
HNNExtension G A B φ →* H :=
Con.lift _ (Coprod.lift f (zpowersHom H x)) (Con.conGen_le <| by
rintro _ _ ⟨a, rfl, rfl⟩
simp [hx])
@[simp]
theorem lift_t (f : G →* H) (x : H) (hx : ∀ a : A, x * f ↑a = f (φ a : G) * x) :
lift f x hx t = x := by
delta HNNExtension; simp [lift, t]
@[simp]
theorem lift_of (f : G →* H) (x : H) (hx : ∀ a : A, x * f ↑a = f (φ a : G) * x) (g : G) :
lift f x hx (of g) = f g := by
delta HNNExtension; simp [lift, of]
@[ext high]
theorem hom_ext {f g : HNNExtension G A B φ →* M}
(hg : f.comp of = g.comp of) (ht : f t = g t) : f = g :=
(MonoidHom.cancel_right Con.mk'_surjective).mp <|
Coprod.hom_ext hg (MonoidHom.ext_mint ht)
@[elab_as_elim]
theorem induction_on {motive : HNNExtension G A B φ → Prop}
(x : HNNExtension G A B φ) (of : ∀ g, motive (of g))
(t : motive t) (mul : ∀ x y, motive x → motive y → motive (x * y))
(inv : ∀ x, motive x → motive x⁻¹) : motive x := by
let S : Subgroup (HNNExtension G A B φ) :=
{ carrier := setOf motive
one_mem' := by simpa using of 1
mul_mem' := mul _ _
inv_mem' := inv _ }
let f : HNNExtension G A B φ →* S :=
lift (HNNExtension.of.codRestrict S of)
⟨HNNExtension.t, t⟩ (by intro a; ext; simp [equiv_eq_conj, mul_assoc])
have hf : S.subtype.comp f = MonoidHom.id _ :=
hom_ext (by ext; simp [f]) (by simp [f])
show motive (MonoidHom.id _ x)
rw [← hf]
exact (f x).2
variable (A B φ)
/-- To avoid duplicating code, we define `toSubgroup A B u` and `toSubgroupEquiv u`
where `u : ℤˣ` is `1` or `-1`. `toSubgroup A B u` is `A` when `u = 1` and `B` when `u = -1`,
and `toSubgroupEquiv` is `φ` when `u = 1` and `φ⁻¹` when `u = -1`. `toSubgroup u` is the subgroup
such that for any `a ∈ toSubgroup u`, `t ^ (u : ℤ) * a = toSubgroupEquiv a * t ^ (u : ℤ)`. -/
def toSubgroup (u : ℤˣ) : Subgroup G :=
if u = 1 then A else B
@[simp]
theorem toSubgroup_one : toSubgroup A B 1 = A := rfl
@[simp]
theorem toSubgroup_neg_one : toSubgroup A B (-1) = B := rfl
variable {A B}
/-- To avoid duplicating code, we define `toSubgroup A B u` and `toSubgroupEquiv u`
where `u : ℤˣ` is `1` or `-1`. `toSubgroup A B u` is `A` when `u = 1` and `B` when `u = -1`,
and `toSubgroupEquiv` is the group ismorphism from `toSubgroup A B u` to `toSubgroup A B (-u)`.
It is defined to be `φ` when `u = 1` and `φ⁻¹` when `u = -1`. -/
def toSubgroupEquiv (u : ℤˣ) : toSubgroup A B u ≃* toSubgroup A B (-u) :=
if hu : u = 1 then hu ▸ φ else by
convert φ.symm <;>
cases Int.units_eq_one_or u <;> simp_all
@[simp]
theorem toSubgroupEquiv_one : toSubgroupEquiv φ 1 = φ := rfl
@[simp]
| Mathlib/GroupTheory/HNNExtension.lean | 164 | 170 | theorem toSubgroupEquiv_neg_one : toSubgroupEquiv φ (-1) = φ.symm := rfl
@[simp]
theorem toSubgroupEquiv_neg_apply (u : ℤˣ) (a : toSubgroup A B u) :
(toSubgroupEquiv φ (-u) (toSubgroupEquiv φ u a) : G) = a := by | rcases Int.units_eq_one_or u with rfl | rfl
· simp [toSubgroup] |
/-
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]
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 https://github.com/leanprover-community/mathlib4/issues/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 https://github.com/leanprover-community/mathlib4/issues/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 https://github.com/leanprover-community/mathlib4/issues/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) =
QuadraticMap.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
dsimp
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, QuadraticMap.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. -/
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
/-- `reverse` acts only on the right of the tensor product. -/
theorem toBaseChange_reverse (Q : QuadraticForm R V) (x : CliffordAlgebra (Q.baseChange A)) :
toBaseChange A Q (reverse x) =
TensorProduct.map LinearMap.id reverse (toBaseChange A Q x) := by
have := DFunLike.congr_fun (toBaseChange_comp_reverseOp A Q) x
refine (congr_arg unop this).trans ?_; clear this
refine (LinearMap.congr_fun (TensorProduct.AlgebraTensorModule.map_comp _ _ _ _).symm _).trans ?_
rw [reverse, ← AlgEquiv.toLinearMap, ← AlgEquiv.toLinearEquiv_toLinearMap,
AlgEquiv.toLinearEquiv_toOpposite]
dsimp
-- `simp` fails here due to a timeout looking for a `Subsingleton` instance!?
rw [LinearEquiv.self_trans_symm]
rfl
attribute [ext] TensorProduct.ext
| Mathlib/LinearAlgebra/CliffordAlgebra/BaseChange.lean | 156 | 160 | theorem toBaseChange_comp_ofBaseChange (Q : QuadraticForm R V) :
(toBaseChange A Q).comp (ofBaseChange A Q) = AlgHom.id _ _ := by | ext v
simp |
/-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Mario Carneiro, Sean Leather
-/
import Mathlib.Data.Finset.Card
import Mathlib.Data.Finset.Union
/-!
# Finite sets in `Option α`
In this file we define
* `Option.toFinset`: construct an empty or singleton `Finset α` from an `Option α`;
* `Finset.insertNone`: given `s : Finset α`, lift it to a finset on `Option α` using `Option.some`
and then insert `Option.none`;
* `Finset.eraseNone`: given `s : Finset (Option α)`, returns `t : Finset α` such that
`x ∈ t ↔ some x ∈ s`.
Then we prove some basic lemmas about these definitions.
## Tags
finset, option
-/
variable {α β : Type*}
open Function
namespace Option
/-- Construct an empty or singleton finset from an `Option` -/
def toFinset (o : Option α) : Finset α :=
o.elim ∅ singleton
@[simp]
theorem toFinset_none : none.toFinset = (∅ : Finset α) :=
rfl
@[simp]
theorem toFinset_some {a : α} : (some a).toFinset = {a} :=
rfl
@[simp]
theorem mem_toFinset {a : α} {o : Option α} : a ∈ o.toFinset ↔ a ∈ o := by
cases o <;> simp [eq_comm]
theorem card_toFinset (o : Option α) : o.toFinset.card = o.elim 0 1 := by cases o <;> rfl
end Option
namespace Finset
/-- Given a finset on `α`, lift it to being a finset on `Option α`
using `Option.some` and then insert `Option.none`. -/
def insertNone : Finset α ↪o Finset (Option α) :=
(OrderEmbedding.ofMapLEIff fun s => cons none (s.map Embedding.some) <| by simp) fun s t => by
rw [le_iff_subset, cons_subset_cons, map_subset_map, le_iff_subset]
@[simp]
theorem mem_insertNone {s : Finset α} : ∀ {o : Option α}, o ∈ insertNone s ↔ ∀ a ∈ o, a ∈ s
| none => iff_of_true (Multiset.mem_cons_self _ _) fun a h => by cases h
| some a => Multiset.mem_cons.trans <| by simp
lemma forall_mem_insertNone {s : Finset α} {p : Option α → Prop} :
(∀ a ∈ insertNone s, p a) ↔ p none ∧ ∀ a ∈ s, p a := by simp [Option.forall]
theorem some_mem_insertNone {s : Finset α} {a : α} : some a ∈ insertNone s ↔ a ∈ s := by simp
lemma none_mem_insertNone {s : Finset α} : none ∈ insertNone s := by simp
@[aesop safe apply (rule_sets := [finsetNonempty])]
lemma insertNone_nonempty {s : Finset α} : insertNone s |>.Nonempty := ⟨none, none_mem_insertNone⟩
@[simp]
theorem card_insertNone (s : Finset α) : s.insertNone.card = s.card + 1 := by simp [insertNone]
/-- Given `s : Finset (Option α)`, `eraseNone s : Finset α` is the set of `x : α` such that
`some x ∈ s`. -/
def eraseNone : Finset (Option α) →o Finset α :=
(Finset.mapEmbedding (Equiv.optionIsSomeEquiv α).toEmbedding).toOrderHom.comp
⟨Finset.subtype _, subtype_mono⟩
@[simp]
theorem mem_eraseNone {s : Finset (Option α)} {x : α} : x ∈ eraseNone s ↔ some x ∈ s := by
simp [eraseNone]
lemma forall_mem_eraseNone {s : Finset (Option α)} {p : Option α → Prop} :
(∀ a ∈ eraseNone s, p a) ↔ ∀ a : α, (a : Option α) ∈ s → p a := by simp [Option.forall]
theorem eraseNone_eq_biUnion [DecidableEq α] (s : Finset (Option α)) :
eraseNone s = s.biUnion Option.toFinset := by
ext
simp
@[simp]
theorem eraseNone_map_some (s : Finset α) : eraseNone (s.map Embedding.some) = s := by
ext
simp
@[simp]
theorem eraseNone_image_some [DecidableEq (Option α)] (s : Finset α) :
eraseNone (s.image some) = s := by simpa only [map_eq_image] using eraseNone_map_some s
@[simp]
theorem coe_eraseNone (s : Finset (Option α)) : (eraseNone s : Set α) = some ⁻¹' s :=
Set.ext fun _ => mem_eraseNone
@[simp]
theorem eraseNone_union [DecidableEq (Option α)] [DecidableEq α] (s t : Finset (Option α)) :
eraseNone (s ∪ t) = eraseNone s ∪ eraseNone t := by
ext
simp
@[simp]
| Mathlib/Data/Finset/Option.lean | 118 | 119 | theorem eraseNone_inter [DecidableEq (Option α)] [DecidableEq α] (s t : Finset (Option α)) :
eraseNone (s ∩ t) = eraseNone s ∩ eraseNone t := by | |
/-
Copyright (c) 2022 Kevin H. Wilson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin H. Wilson
-/
import Mathlib.MeasureTheory.Integral.IntervalIntegral.Basic
import Mathlib.Data.Set.Function
/-!
# Comparing sums and integrals
## Summary
It is often the case that error terms in analysis can be computed by comparing
an infinite sum to the improper integral of an antitone function. This file will eventually enable
that.
At the moment it contains several lemmas in this direction, for antitone or monotone functions
(or products of antitone and monotone functions), formulated for sums on `range i` or `Ico a b`.
`TODO`: Add more lemmas to the API to directly address limiting issues
## Main Results
* `AntitoneOn.integral_le_sum`: The integral of an antitone function is at most the sum of its
values at integer steps aligning with the left-hand side of the interval
* `AntitoneOn.sum_le_integral`: The sum of an antitone function along integer steps aligning with
the right-hand side of the interval is at most the integral of the function along that interval
* `MonotoneOn.integral_le_sum`: The integral of a monotone function is at most the sum of its
values at integer steps aligning with the right-hand side of the interval
* `MonotoneOn.sum_le_integral`: The sum of a monotone function along integer steps aligning with
the left-hand side of the interval is at most the integral of the function along that interval
* `sum_mul_Ico_le_integral_of_monotone_antitone`: the sum of `f i * g i` on an interval is bounded
by the integral of `f x * g (x - 1)` if `f` is monotone and `g` is antitone.
* `integral_le_sum_mul_Ico_of_antitone_monotone`: the sum of `f i * g i` on an interval is bounded
below by the integral of `f x * g (x - 1)` if `f` is antitone and `g` is monotone.
## Tags
analysis, comparison, asymptotics
-/
open Set MeasureTheory MeasureSpace
variable {x₀ : ℝ} {a b : ℕ} {f g : ℝ → ℝ}
lemma sum_Ico_le_integral_of_le
(hab : a ≤ b) (h : ∀ i ∈ Ico a b, ∀ x ∈ Ico (i : ℝ) (i + 1 : ℕ), f i ≤ g x)
(hg : IntegrableOn g (Set.Ico a b)) :
∑ i ∈ Finset.Ico a b, f i ≤ ∫ x in a..b, g x := by
have A i (hi : i ∈ Finset.Ico a b) : IntervalIntegrable g volume i (i + 1 : ℕ) := by
rw [intervalIntegrable_iff_integrableOn_Ico_of_le (by simp)]
apply hg.mono _ le_rfl
rintro x ⟨hx, h'x⟩
simp only [Finset.mem_Ico, mem_Ico] at hi ⊢
exact ⟨le_trans (mod_cast hi.1) hx, h'x.trans_le (mod_cast hi.2)⟩
calc
∑ i ∈ Finset.Ico a b, f i
_ = ∑ i ∈ Finset.Ico a b, (∫ x in (i : ℝ)..(i + 1 : ℕ), f i) := by simp
_ ≤ ∑ i ∈ Finset.Ico a b, (∫ x in (i : ℝ)..(i + 1 : ℕ), g x) := by
apply Finset.sum_le_sum (fun i hi ↦ ?_)
apply intervalIntegral.integral_mono_on_of_le_Ioo (by simp) (by simp) (A _ hi) (fun x hx ↦ ?_)
exact h _ (by simpa using hi) _ (Ioo_subset_Ico_self hx)
_ = ∫ x in a..b, g x := by
rw [intervalIntegral.sum_integral_adjacent_intervals_Ico (a := fun i ↦ i) hab]
intro i hi
exact A _ (by simpa using hi)
lemma integral_le_sum_Ico_of_le
(hab : a ≤ b) (h : ∀ i ∈ Ico a b, ∀ x ∈ Ico (i : ℝ) (i + 1 : ℕ), g x ≤ f i)
(hg : IntegrableOn g (Set.Ico a b)) :
∫ x in a..b, g x ≤ ∑ i ∈ Finset.Ico a b, f i := by
convert neg_le_neg (sum_Ico_le_integral_of_le (f := -f) (g := -g) hab
(fun i hi x hx ↦ neg_le_neg (h i hi x hx)) hg.neg) <;> simp
theorem AntitoneOn.integral_le_sum (hf : AntitoneOn f (Icc x₀ (x₀ + a))) :
(∫ x in x₀..x₀ + a, f x) ≤ ∑ i ∈ Finset.range a, f (x₀ + i) := by
have hint : ∀ k : ℕ, k < a → IntervalIntegrable f volume (x₀ + k) (x₀ + (k + 1 : ℕ)) := by
intro k hk
refine (hf.mono ?_).intervalIntegrable
rw [uIcc_of_le]
· apply Icc_subset_Icc
· simp only [le_add_iff_nonneg_right, Nat.cast_nonneg]
· simp only [add_le_add_iff_left, Nat.cast_le, Nat.succ_le_of_lt hk]
· simp only [add_le_add_iff_left, Nat.cast_le, Nat.le_succ]
calc
∫ x in x₀..x₀ + a, f x = ∑ i ∈ Finset.range a, ∫ x in x₀ + i..x₀ + (i + 1 : ℕ), f x := by
convert (intervalIntegral.sum_integral_adjacent_intervals hint).symm
simp only [Nat.cast_zero, add_zero]
_ ≤ ∑ i ∈ Finset.range a, ∫ _ in x₀ + i..x₀ + (i + 1 : ℕ), f (x₀ + i) := by
apply Finset.sum_le_sum fun i hi => ?_
have ia : i < a := Finset.mem_range.1 hi
refine intervalIntegral.integral_mono_on (by simp) (hint _ ia) (by simp) fun x hx => ?_
apply hf _ _ hx.1
· simp only [ia.le, mem_Icc, le_add_iff_nonneg_right, Nat.cast_nonneg, add_le_add_iff_left,
Nat.cast_le, and_self_iff]
· refine mem_Icc.2 ⟨le_trans (by simp) hx.1, le_trans hx.2 ?_⟩
simp only [add_le_add_iff_left, Nat.cast_le, Nat.succ_le_of_lt ia]
_ = ∑ i ∈ Finset.range a, f (x₀ + i) := by simp
theorem AntitoneOn.integral_le_sum_Ico (hab : a ≤ b) (hf : AntitoneOn f (Set.Icc a b)) :
(∫ x in a..b, f x) ≤ ∑ x ∈ Finset.Ico a b, f x := by
rw [(Nat.sub_add_cancel hab).symm, Nat.cast_add]
conv =>
congr
congr
· skip
· skip
rw [add_comm]
· skip
· skip
congr
congr
rw [← zero_add a]
rw [← Finset.sum_Ico_add, Nat.Ico_zero_eq_range]
conv =>
rhs
congr
· skip
ext
rw [Nat.cast_add]
apply AntitoneOn.integral_le_sum
simp only [hf, hab, Nat.cast_sub, add_sub_cancel]
| Mathlib/Analysis/SumIntegralComparisons.lean | 126 | 147 | theorem AntitoneOn.sum_le_integral (hf : AntitoneOn f (Icc x₀ (x₀ + a))) :
(∑ i ∈ Finset.range a, f (x₀ + (i + 1 : ℕ))) ≤ ∫ x in x₀..x₀ + a, f x := by | have hint : ∀ k : ℕ, k < a → IntervalIntegrable f volume (x₀ + k) (x₀ + (k + 1 : ℕ)) := by
intro k hk
refine (hf.mono ?_).intervalIntegrable
rw [uIcc_of_le]
· apply Icc_subset_Icc
· simp only [le_add_iff_nonneg_right, Nat.cast_nonneg]
· simp only [add_le_add_iff_left, Nat.cast_le, Nat.succ_le_of_lt hk]
· simp only [add_le_add_iff_left, Nat.cast_le, Nat.le_succ]
calc
(∑ i ∈ Finset.range a, f (x₀ + (i + 1 : ℕ))) =
∑ i ∈ Finset.range a, ∫ _ in x₀ + i..x₀ + (i + 1 : ℕ), f (x₀ + (i + 1 : ℕ)) := by simp
_ ≤ ∑ i ∈ Finset.range a, ∫ x in x₀ + i..x₀ + (i + 1 : ℕ), f x := by
apply Finset.sum_le_sum fun i hi => ?_
have ia : i + 1 ≤ a := Finset.mem_range.1 hi
refine intervalIntegral.integral_mono_on (by simp) (by simp) (hint _ ia) fun x hx => ?_
apply hf _ _ hx.2
· refine mem_Icc.2 ⟨le_trans (le_add_of_nonneg_right (Nat.cast_nonneg _)) hx.1,
le_trans hx.2 ?_⟩
simp only [Nat.cast_le, add_le_add_iff_left, ia]
· refine mem_Icc.2 ⟨le_add_of_nonneg_right (Nat.cast_nonneg _), ?_⟩ |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Aaron Anderson, Yakov Pechersky
-/
import Mathlib.Data.Fintype.Card
import Mathlib.Algebra.Group.Commute.Basic
import Mathlib.Algebra.Group.End
import Mathlib.Data.Finset.NoncommProd
/-!
# support of a permutation
## Main definitions
In the following, `f g : Equiv.Perm α`.
* `Equiv.Perm.Disjoint`: two permutations `f` and `g` are `Disjoint` if every element is fixed
either by `f`, or by `g`.
Equivalently, `f` and `g` are `Disjoint` iff their `support` are disjoint.
* `Equiv.Perm.IsSwap`: `f = swap x y` for `x ≠ y`.
* `Equiv.Perm.support`: the elements `x : α` that are not fixed by `f`.
Assume `α` is a Fintype:
* `Equiv.Perm.fixed_point_card_lt_of_ne_one f` says that `f` has
strictly less than `Fintype.card α - 1` fixed points, unless `f = 1`.
(Equivalently, `f.support` has at least 2 elements.)
-/
open Equiv Finset Function
namespace Equiv.Perm
variable {α : Type*}
section Disjoint
/-- Two permutations `f` and `g` are `Disjoint` if their supports are disjoint, i.e.,
every element is fixed either by `f`, or by `g`. -/
def Disjoint (f g : Perm α) :=
∀ x, f x = x ∨ g x = x
variable {f g h : Perm α}
@[symm]
theorem Disjoint.symm : Disjoint f g → Disjoint g f := by simp only [Disjoint, or_comm, imp_self]
theorem Disjoint.symmetric : Symmetric (@Disjoint α) := fun _ _ => Disjoint.symm
instance : IsSymm (Perm α) Disjoint :=
⟨Disjoint.symmetric⟩
theorem disjoint_comm : Disjoint f g ↔ Disjoint g f :=
⟨Disjoint.symm, Disjoint.symm⟩
theorem Disjoint.commute (h : Disjoint f g) : Commute f g :=
Equiv.ext fun x =>
(h x).elim
(fun hf =>
(h (g x)).elim (fun hg => by simp [mul_apply, hf, hg]) fun hg => by
simp [mul_apply, hf, g.injective hg])
fun hg =>
(h (f x)).elim (fun hf => by simp [mul_apply, f.injective hf, hg]) fun hf => by
simp [mul_apply, hf, hg]
@[simp]
theorem disjoint_one_left (f : Perm α) : Disjoint 1 f := fun _ => Or.inl rfl
@[simp]
theorem disjoint_one_right (f : Perm α) : Disjoint f 1 := fun _ => Or.inr rfl
theorem disjoint_iff_eq_or_eq : Disjoint f g ↔ ∀ x : α, f x = x ∨ g x = x :=
Iff.rfl
@[simp]
theorem disjoint_refl_iff : Disjoint f f ↔ f = 1 := by
refine ⟨fun h => ?_, fun h => h.symm ▸ disjoint_one_left 1⟩
ext x
rcases h x with hx | hx <;> simp [hx]
theorem Disjoint.inv_left (h : Disjoint f g) : Disjoint f⁻¹ g := by
intro x
rw [inv_eq_iff_eq, eq_comm]
exact h x
theorem Disjoint.inv_right (h : Disjoint f g) : Disjoint f g⁻¹ :=
h.symm.inv_left.symm
@[simp]
theorem disjoint_inv_left_iff : Disjoint f⁻¹ g ↔ Disjoint f g := by
refine ⟨fun h => ?_, Disjoint.inv_left⟩
convert h.inv_left
@[simp]
theorem disjoint_inv_right_iff : Disjoint f g⁻¹ ↔ Disjoint f g := by
rw [disjoint_comm, disjoint_inv_left_iff, disjoint_comm]
theorem Disjoint.mul_left (H1 : Disjoint f h) (H2 : Disjoint g h) : Disjoint (f * g) h := fun x =>
by cases H1 x <;> cases H2 x <;> simp [*]
theorem Disjoint.mul_right (H1 : Disjoint f g) (H2 : Disjoint f h) : Disjoint f (g * h) := by
rw [disjoint_comm]
exact H1.symm.mul_left H2.symm
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: make it `@[simp]`
theorem disjoint_conj (h : Perm α) : Disjoint (h * f * h⁻¹) (h * g * h⁻¹) ↔ Disjoint f g :=
(h⁻¹).forall_congr fun {_} ↦ by simp only [mul_apply, eq_inv_iff_eq]
theorem Disjoint.conj (H : Disjoint f g) (h : Perm α) : Disjoint (h * f * h⁻¹) (h * g * h⁻¹) :=
(disjoint_conj h).2 H
theorem disjoint_prod_right (l : List (Perm α)) (h : ∀ g ∈ l, Disjoint f g) :
Disjoint f l.prod := by
induction' l with g l ih
· exact disjoint_one_right _
· rw [List.prod_cons]
exact (h _ List.mem_cons_self).mul_right (ih fun g hg => h g (List.mem_cons_of_mem _ hg))
theorem disjoint_noncommProd_right {ι : Type*} {k : ι → Perm α} {s : Finset ι}
(hs : Set.Pairwise s fun i j ↦ Commute (k i) (k j))
(hg : ∀ i ∈ s, g.Disjoint (k i)) :
Disjoint g (s.noncommProd k (hs)) :=
noncommProd_induction s k hs g.Disjoint (fun _ _ ↦ Disjoint.mul_right) (disjoint_one_right g) hg
open scoped List in
theorem disjoint_prod_perm {l₁ l₂ : List (Perm α)} (hl : l₁.Pairwise Disjoint) (hp : l₁ ~ l₂) :
l₁.prod = l₂.prod :=
hp.prod_eq' <| hl.imp Disjoint.commute
theorem nodup_of_pairwise_disjoint {l : List (Perm α)} (h1 : (1 : Perm α) ∉ l)
(h2 : l.Pairwise Disjoint) : l.Nodup := by
refine List.Pairwise.imp_of_mem ?_ h2
intro τ σ h_mem _ h_disjoint _
subst τ
suffices (σ : Perm α) = 1 by
rw [this] at h_mem
exact h1 h_mem
exact ext fun a => or_self_iff.mp (h_disjoint a)
theorem pow_apply_eq_self_of_apply_eq_self {x : α} (hfx : f x = x) : ∀ n : ℕ, (f ^ n) x = x
| 0 => rfl
| n + 1 => by rw [pow_succ, mul_apply, hfx, pow_apply_eq_self_of_apply_eq_self hfx n]
theorem zpow_apply_eq_self_of_apply_eq_self {x : α} (hfx : f x = x) : ∀ n : ℤ, (f ^ n) x = x
| (n : ℕ) => pow_apply_eq_self_of_apply_eq_self hfx n
| Int.negSucc n => by rw [zpow_negSucc, inv_eq_iff_eq, pow_apply_eq_self_of_apply_eq_self hfx]
theorem pow_apply_eq_of_apply_apply_eq_self {x : α} (hffx : f (f x) = x) :
∀ n : ℕ, (f ^ n) x = x ∨ (f ^ n) x = f x
| 0 => Or.inl rfl
| n + 1 =>
(pow_apply_eq_of_apply_apply_eq_self hffx n).elim
(fun h => Or.inr (by rw [pow_succ', mul_apply, h]))
fun h => Or.inl (by rw [pow_succ', mul_apply, h, hffx])
theorem zpow_apply_eq_of_apply_apply_eq_self {x : α} (hffx : f (f x) = x) :
∀ i : ℤ, (f ^ i) x = x ∨ (f ^ i) x = f x
| (n : ℕ) => pow_apply_eq_of_apply_apply_eq_self hffx n
| Int.negSucc n => by
rw [zpow_negSucc, inv_eq_iff_eq, ← f.injective.eq_iff, ← mul_apply, ← pow_succ', eq_comm,
inv_eq_iff_eq, ← mul_apply, ← pow_succ, @eq_comm _ x, or_comm]
exact pow_apply_eq_of_apply_apply_eq_self hffx _
theorem Disjoint.mul_apply_eq_iff {σ τ : Perm α} (hστ : Disjoint σ τ) {a : α} :
(σ * τ) a = a ↔ σ a = a ∧ τ a = a := by
refine ⟨fun h => ?_, fun h => by rw [mul_apply, h.2, h.1]⟩
rcases hστ a with hσ | hτ
· exact ⟨hσ, σ.injective (h.trans hσ.symm)⟩
· exact ⟨(congr_arg σ hτ).symm.trans h, hτ⟩
theorem Disjoint.mul_eq_one_iff {σ τ : Perm α} (hστ : Disjoint σ τ) :
σ * τ = 1 ↔ σ = 1 ∧ τ = 1 := by
simp_rw [Perm.ext_iff, one_apply, hστ.mul_apply_eq_iff, forall_and]
theorem Disjoint.zpow_disjoint_zpow {σ τ : Perm α} (hστ : Disjoint σ τ) (m n : ℤ) :
Disjoint (σ ^ m) (τ ^ n) := fun x =>
Or.imp (fun h => zpow_apply_eq_self_of_apply_eq_self h m)
(fun h => zpow_apply_eq_self_of_apply_eq_self h n) (hστ x)
theorem Disjoint.pow_disjoint_pow {σ τ : Perm α} (hστ : Disjoint σ τ) (m n : ℕ) :
Disjoint (σ ^ m) (τ ^ n) :=
hστ.zpow_disjoint_zpow m n
end Disjoint
section IsSwap
variable [DecidableEq α]
/-- `f.IsSwap` indicates that the permutation `f` is a transposition of two elements. -/
def IsSwap (f : Perm α) : Prop :=
∃ x y, x ≠ y ∧ f = swap x y
@[simp]
theorem ofSubtype_swap_eq {p : α → Prop} [DecidablePred p] (x y : Subtype p) :
ofSubtype (Equiv.swap x y) = Equiv.swap ↑x ↑y :=
Equiv.ext fun z => by
by_cases hz : p z
· rw [swap_apply_def, ofSubtype_apply_of_mem _ hz]
split_ifs with hzx hzy
· simp_rw [hzx, Subtype.coe_eta, swap_apply_left]
· simp_rw [hzy, Subtype.coe_eta, swap_apply_right]
· rw [swap_apply_of_ne_of_ne] <;>
simp [Subtype.ext_iff, *]
· rw [ofSubtype_apply_of_not_mem _ hz, swap_apply_of_ne_of_ne]
· intro h
apply hz
rw [h]
exact Subtype.prop x
intro h
apply hz
rw [h]
exact Subtype.prop y
theorem IsSwap.of_subtype_isSwap {p : α → Prop} [DecidablePred p] {f : Perm (Subtype p)}
(h : f.IsSwap) : (ofSubtype f).IsSwap :=
let ⟨⟨x, hx⟩, ⟨y, hy⟩, hxy⟩ := h
⟨x, y, by
simp only [Ne, Subtype.ext_iff] at hxy
exact hxy.1, by
rw [hxy.2, ofSubtype_swap_eq]⟩
theorem ne_and_ne_of_swap_mul_apply_ne_self {f : Perm α} {x y : α} (hy : (swap x (f x) * f) y ≠ y) :
f y ≠ y ∧ y ≠ x := by
simp only [swap_apply_def, mul_apply, f.injective.eq_iff] at *
by_cases h : f y = x
· constructor <;> intro <;> simp_all only [if_true, eq_self_iff_true, not_true, Ne]
· split_ifs at hy with h <;> try { simp [*] at * }
end IsSwap
section support
section Set
variable (p q : Perm α)
theorem set_support_inv_eq : { x | p⁻¹ x ≠ x } = { x | p x ≠ x } := by
ext x
simp only [Set.mem_setOf_eq, Ne]
rw [inv_def, symm_apply_eq, eq_comm]
theorem set_support_apply_mem {p : Perm α} {a : α} :
p a ∈ { x | p x ≠ x } ↔ a ∈ { x | p x ≠ x } := by simp
| Mathlib/GroupTheory/Perm/Support.lean | 248 | 253 | theorem set_support_zpow_subset (n : ℤ) : { x | (p ^ n) x ≠ x } ⊆ { x | p x ≠ x } := by | intro x
simp only [Set.mem_setOf_eq, Ne]
intro hx H
simp [zpow_apply_eq_self_of_apply_eq_self H] at hx |
/-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, Edward Ayers
-/
import Mathlib.CategoryTheory.Limits.Shapes.Pullback.HasPullback
import Mathlib.Data.Set.BooleanAlgebra
/-!
# 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
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) :=
ObjectProperty.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 :=
ObjectProperty.ι _ ⋙ Over.forget X
/-- 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 (ObjectProperty.ι _)
/-- 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
/-- Structure which contains the data and properties for a morphism `h` satisfying
`Presieve.bind S R h`. -/
structure BindStruct (S : Presieve X) (R : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → Presieve Y)
{Z : C} (h : Z ⟶ X) where
/-- the intermediate object -/
Y : C
/-- a morphism in the family of presieves `R` -/
g : Z ⟶ Y
/-- a morphism in the presieve `S` -/
f : Y ⟶ X
hf : S f
hg : R hf g
fac : g ≫ f = h
attribute [reassoc (attr := simp)] BindStruct.fac
/-- If a morphism `h` satisfies `Presieve.bind S R h`, this is a choice of a structure
in `BindStruct S R h`. -/
noncomputable def bind.bindStruct {S : Presieve X} {R : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → Presieve Y}
{Z : C} {h : Z ⟶ X} (H : bind S R h) : BindStruct S R h :=
Nonempty.some (by
obtain ⟨Y, g, f, hf, hg, fac⟩ := H
exact ⟨{ hf := hf, hg := hg, fac := fac, .. }⟩)
lemma BindStruct.bind {S : Presieve X} {R : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → Presieve Y}
{Z : C} {h : Z ⟶ X} (b : BindStruct S R h) : bind S R h :=
⟨b.Y, b.g, b.f, b.hf, b.hg, b.fac⟩
@[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⟩
-- 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
@[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
theorem singleton_self : singleton f f :=
singleton.mk
/-- 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 h f)
theorem pullback_singleton [HasPullbacks C] (g : Z ⟶ X) :
pullbackArrows f (singleton g) = singleton (pullback.snd g f) := by
funext W
ext h
constructor
· rintro ⟨W, _, _, _⟩
exact singleton.mk
· rintro ⟨_⟩
exact pullbackArrows.mk Z g singleton.mk
/-- 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)
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
theorem ofArrows_pullback [HasPullbacks C] {ι : Type*} (Z : ι → C) (g : ∀ i : ι, Z i ⟶ X) :
(ofArrows (fun i => pullback (g i) f) fun _ => pullback.snd _ _) =
pullbackArrows f (ofArrows Z g) := by
funext T
ext h
constructor
· rintro ⟨hk⟩
exact pullbackArrows.mk _ _ (ofArrows.mk hk)
· rintro ⟨W, k, ⟨_⟩⟩
apply ofArrows.mk
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 _ 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 _)
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
obtain ⟨i⟩ := hg
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)
@[simp]
theorem functorPullback_mem (R : Presieve (F.obj X)) {Y} (f : Y ⟶ X) :
R.functorPullback F f ↔ R (F.map f) :=
Iff.rfl
@[simp]
theorem functorPullback_id (R : Presieve X) : R.functorPullback (𝟭 _) = R :=
rfl
/-- 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
/-- 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
/-- 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⟩
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⟩
theorem image_mem_functorPushforward (R : Presieve X) {f : Y ⟶ X} (h : R f) :
R.functorPushforward F (F.map f) :=
⟨Y, f, 𝟙 _, h, by simp⟩
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)
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
@[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
open Lattice
/-- The supremum of a collection of sieves: the union of them all. -/
protected def sup (𝒮 : Set (Sieve X)) : Sieve X where
arrows _ := { f | ∃ S ∈ 𝒮, Sieve.arrows S f }
downward_closed {_ _ f} hf _ := by
obtain ⟨S, hS, hf⟩ := hf
exact ⟨S, hS, S.downward_closed hf _⟩
/-- 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
/-- The union of two sieves is a sieve. -/
protected def union (S R : Sieve X) : Sieve X where
arrows _ f := S f ∨ R f
downward_closed := by rintro _ _ _ (h | h) g <;> simp [h]
/-- The intersection of two sieves is a sieve. -/
protected def inter (S R : Sieve X) : Sieve X where
arrows _ f := S f ∧ R f
downward_closed := by
rintro _ _ _ ⟨h₁, h₂⟩ g
simp [h₁, h₂]
/-- 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 _ _ _ := id
le_trans _ _ _ S₁₂ S₂₃ _ _ h := S₂₃ _ (S₁₂ _ h)
le_antisymm _ _ p q := Sieve.ext fun _ _ => ⟨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 _ _ hf := ⟨S, hS, hf⟩
sSup_le := fun _ _ ha _ _ ⟨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) :=
⟨⊤⟩
@[simp]
theorem sInf_apply {Ss : Set (Sieve X)} {Y} (f : Y ⟶ X) :
sInf Ss f ↔ ∀ (S : Sieve X) (_ : S ∈ Ss), S f :=
Iff.rfl
@[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]
@[simp]
theorem inter_apply {R S : Sieve X} {Y} (f : Y ⟶ X) : (R ⊓ S) f ↔ R f ∧ S f :=
Iff.rfl
@[simp]
theorem union_apply {R S : Sieve X} {Y} (f : Y ⟶ X) : (R ⊔ S) f ↔ R f ∨ S f :=
Iff.rfl
@[simp]
theorem top_apply (f : Y ⟶ X) : (⊤ : Sieve X) f :=
trivial
/-- 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⟩
/-- 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 _ _ h => R h
downward_closed := by
rintro Y Z f ⟨W, f, h, hh, hf, rfl⟩ g
exact ⟨_, g ≫ f, _, hh, by simp [hf]⟩
/-- Structure which contains the data and properties for a morphism `h` satisfying
`Sieve.bind S R h`. -/
abbrev BindStruct (S : Presieve X) (R : ∀ ⦃Y⦄ ⦃f : Y ⟶ X⦄, S f → Sieve Y)
{Z : C} (h : Z ⟶ X) :=
Presieve.BindStruct S (fun _ _ hf ↦ R hf) h
open Order Lattice
theorem generate_le_iff (R : Presieve X) (S : Sieve X) : generate R ≤ S ↔ R ≤ S :=
⟨fun H _ _ hg => H _ ⟨_, 𝟙 _, _, hg, id_comp _⟩, fun ss Y f => by
rintro ⟨Z, f, g, hg, rfl⟩
exact S.downward_closed (ss Z hg) f⟩
/-- Show that there is a galois insertion (generate, set_over). -/
def giGenerate : GaloisInsertion (generate : Presieve X → Sieve X) arrows where
gc := generate_le_iff
choice 𝒢 _ := generate 𝒢
choice_eq _ _ := rfl
le_l_u _ _ _ hf := ⟨_, 𝟙 _, _, hf, id_comp _⟩
theorem le_generate (R : Presieve X) : R ≤ generate R :=
giGenerate.gc.le_u_l R
@[simp]
theorem generate_sieve (S : Sieve X) : generate S = S :=
giGenerate.l_u_eq S
/-- 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⟩
/-- 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⟩
@[simp]
theorem generate_of_singleton_isSplitEpi (f : Y ⟶ X) [IsSplitEpi f] :
generate (Presieve.singleton f) = ⊤ :=
generate_of_contains_isSplitEpi f (Presieve.singleton_self _)
@[simp]
theorem generate_top : generate (⊤ : Presieve X) = ⊤ :=
generate_of_contains_isSplitEpi (𝟙 _) ⟨⟩
@[simp]
lemma comp_mem_iff (i : X ⟶ Y) (f : Y ⟶ Z) [IsIso i] (S : Sieve Z) :
S (i ≫ f) ↔ S f := by
refine ⟨fun H ↦ ?_, fun H ↦ S.downward_closed H _⟩
convert S.downward_closed H (inv i)
simp
section
variable {I : Type*} {X : C} (Y : I → C) (f : ∀ i, Y i ⟶ X)
/-- The sieve of `X` generated by family of morphisms `Y i ⟶ X`. -/
abbrev ofArrows : Sieve X := generate (Presieve.ofArrows Y f)
lemma ofArrows_mk (i : I) : ofArrows Y f (f i) :=
⟨_, 𝟙 _, _, ⟨i⟩, by simp⟩
lemma mem_ofArrows_iff {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)
variable {Y f} {W : C} {g : W ⟶ X} (hg : ofArrows Y f g)
include hg in
lemma ofArrows.exists : ∃ (i : I) (h : W ⟶ Y i), g = h ≫ f i := by
obtain ⟨_, h, _, ⟨i⟩, rfl⟩ := hg
exact ⟨i, h, rfl⟩
/-- When `hg : Sieve.ofArrows Y f g`, this is a choice of `i` such that `g`
factors through `f i`. -/
noncomputable def ofArrows.i : I := (ofArrows.exists hg).choose
/-- When `hg : Sieve.ofArrows Y f g`, this is a morphism `h : W ⟶ Y (i hg)` such
that `h ≫ f (i hg) = g`. -/
noncomputable def ofArrows.h : W ⟶ Y (i hg) := (ofArrows.exists hg).choose_spec.choose
@[reassoc (attr := simp)]
lemma ofArrows.fac : h hg ≫ f (i hg) = g :=
(ofArrows.exists hg).choose_spec.choose_spec.symm
end
/-- The sieve generated by two morphisms. -/
abbrev ofTwoArrows {U V X : C} (i : U ⟶ X) (j : V ⟶ X) : Sieve X :=
Sieve.ofArrows (Y := pairFunction U V) (fun k ↦ WalkingPair.casesOn k i j)
/-- 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 _ sl := S (sl ≫ h)
downward_closed g := by simp [g]
@[simp]
theorem pullback_id : S.pullback (𝟙 _) = S := by simp [Sieve.ext_iff]
@[simp]
theorem pullback_top {f : Y ⟶ X} : (⊤ : Sieve X).pullback f = ⊤ :=
top_unique fun _ _ => id
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]
@[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]
theorem mem_iff_pullback_eq_top (f : Y ⟶ X) : S f ↔ S.pullback f = ⊤ := by
rw [← id_mem_iff_eq_top, pullback_apply, id_comp]
@[deprecated (since := "2025-02-28")]
alias pullback_eq_top_iff_mem := mem_iff_pullback_eq_top
theorem pullback_eq_top_of_mem (S : Sieve X) {f : Y ⟶ X} : S f → S.pullback f = ⊤ :=
(mem_iff_pullback_eq_top f).1
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 _ gf := ∃ g, g ≫ f = gf ∧ R g
downward_closed := fun ⟨j, k, z⟩ h => ⟨h ≫ j, by simp [k], by simp [z]⟩
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⟩
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⟩⟩
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⟩
theorem pullback_monotone (f : Y ⟶ X) : Monotone (Sieve.pullback f) :=
(galoisConnection f).monotone_u
theorem pushforward_monotone (f : Y ⟶ X) : Monotone (Sieve.pushforward f) :=
(galoisConnection f).monotone_l
theorem le_pushforward_pullback (f : Y ⟶ X) (R : Sieve Y) : R ≤ (R.pushforward f).pullback f :=
(galoisConnection f).le_u_l _
theorem pullback_pushforward_le (f : Y ⟶ X) (R : Sieve X) : (R.pullback f).pushforward f ≤ R :=
(galoisConnection f).l_u_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
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⟩
| Mathlib/CategoryTheory/Sites/Sieves.lean | 601 | 604 | 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 |
/-
Copyright (c) 2020 Frédéric Dupuis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Frédéric Dupuis
-/
import Mathlib.Algebra.Algebra.Field
import Mathlib.Algebra.BigOperators.Balance
import Mathlib.Algebra.Order.BigOperators.Expect
import Mathlib.Algebra.Order.Star.Basic
import Mathlib.Analysis.CStarAlgebra.Basic
import Mathlib.Analysis.Normed.Operator.ContinuousLinearMap
import Mathlib.Data.Real.Sqrt
import Mathlib.LinearAlgebra.Basis.VectorSpace
/-!
# `RCLike`: a typeclass for ℝ or ℂ
This file defines the typeclass `RCLike` intended to have only two instances:
ℝ and ℂ. It is meant for definitions and theorems which hold for both the real and the complex case,
and in particular when the real case follows directly from the complex case by setting `re` to `id`,
`im` to zero and so on. Its API follows closely that of ℂ.
Applications include defining inner products and Hilbert spaces for both the real and
complex case. One typically produces the definitions and proof for an arbitrary field of this
typeclass, which basically amounts to doing the complex case, and the two cases then fall out
immediately from the two instances of the class.
The instance for `ℝ` is registered in this file.
The instance for `ℂ` is declared in `Mathlib/Analysis/Complex/Basic.lean`.
## Implementation notes
The coercion from reals into an `RCLike` field is done by registering `RCLike.ofReal` as
a `CoeTC`. For this to work, we must proceed carefully to avoid problems involving circular
coercions in the case `K=ℝ`; in particular, we cannot use the plain `Coe` and must set
priorities carefully. This problem was already solved for `ℕ`, and we copy the solution detailed
in `Mathlib/Data/Nat/Cast/Defs.lean`. See also Note [coercion into rings] for more details.
In addition, several lemmas need to be set at priority 900 to make sure that they do not override
their counterparts in `Mathlib/Analysis/Complex/Basic.lean` (which causes linter errors).
A few lemmas requiring heavier imports are in `Mathlib/Analysis/RCLike/Lemmas.lean`.
-/
open Fintype
open scoped BigOperators ComplexConjugate
section
local notation "𝓚" => algebraMap ℝ _
/--
This typeclass captures properties shared by ℝ and ℂ, with an API that closely matches that of ℂ.
-/
class RCLike (K : semiOutParam Type*) extends DenselyNormedField K, StarRing K,
NormedAlgebra ℝ K, CompleteSpace K where
/-- The real part as an additive monoid homomorphism -/
re : K →+ ℝ
/-- The imaginary part as an additive monoid homomorphism -/
im : K →+ ℝ
/-- Imaginary unit in `K`. Meant to be set to `0` for `K = ℝ`. -/
I : K
I_re_ax : re I = 0
I_mul_I_ax : I = 0 ∨ I * I = -1
re_add_im_ax : ∀ z : K, 𝓚 (re z) + 𝓚 (im z) * I = z
ofReal_re_ax : ∀ r : ℝ, re (𝓚 r) = r
ofReal_im_ax : ∀ r : ℝ, im (𝓚 r) = 0
mul_re_ax : ∀ z w : K, re (z * w) = re z * re w - im z * im w
mul_im_ax : ∀ z w : K, im (z * w) = re z * im w + im z * re w
conj_re_ax : ∀ z : K, re (conj z) = re z
conj_im_ax : ∀ z : K, im (conj z) = -im z
conj_I_ax : conj I = -I
norm_sq_eq_def_ax : ∀ z : K, ‖z‖ ^ 2 = re z * re z + im z * im z
mul_im_I_ax : ∀ z : K, im z * im I = im z
/-- only an instance in the `ComplexOrder` locale -/
[toPartialOrder : PartialOrder K]
le_iff_re_im {z w : K} : z ≤ w ↔ re z ≤ re w ∧ im z = im w
-- note we cannot put this in the `extends` clause
[toDecidableEq : DecidableEq K]
scoped[ComplexOrder] attribute [instance 100] RCLike.toPartialOrder
attribute [instance 100] RCLike.toDecidableEq
end
variable {K E : Type*} [RCLike K]
namespace RCLike
/-- Coercion from `ℝ` to an `RCLike` field. -/
@[coe] abbrev ofReal : ℝ → K := Algebra.cast
/- The priority must be set at 900 to ensure that coercions are tried in the right order.
See Note [coercion into rings], or `Mathlib/Data/Nat/Cast/Basic.lean` for more details. -/
noncomputable instance (priority := 900) algebraMapCoe : CoeTC ℝ K :=
⟨ofReal⟩
theorem ofReal_alg (x : ℝ) : (x : K) = x • (1 : K) :=
Algebra.algebraMap_eq_smul_one x
theorem real_smul_eq_coe_mul (r : ℝ) (z : K) : r • z = (r : K) * z :=
Algebra.smul_def r z
theorem real_smul_eq_coe_smul [AddCommGroup E] [Module K E] [Module ℝ E] [IsScalarTower ℝ K E]
(r : ℝ) (x : E) : r • x = (r : K) • x := by rw [RCLike.ofReal_alg, smul_one_smul]
theorem algebraMap_eq_ofReal : ⇑(algebraMap ℝ K) = ofReal :=
rfl
@[simp, rclike_simps]
theorem re_add_im (z : K) : (re z : K) + im z * I = z :=
RCLike.re_add_im_ax z
@[simp, norm_cast, rclike_simps]
theorem ofReal_re : ∀ r : ℝ, re (r : K) = r :=
RCLike.ofReal_re_ax
@[simp, norm_cast, rclike_simps]
theorem ofReal_im : ∀ r : ℝ, im (r : K) = 0 :=
RCLike.ofReal_im_ax
@[simp, rclike_simps]
theorem mul_re : ∀ z w : K, re (z * w) = re z * re w - im z * im w :=
RCLike.mul_re_ax
@[simp, rclike_simps]
theorem mul_im : ∀ z w : K, im (z * w) = re z * im w + im z * re w :=
RCLike.mul_im_ax
theorem ext_iff {z w : K} : z = w ↔ re z = re w ∧ im z = im w :=
⟨fun h => h ▸ ⟨rfl, rfl⟩, fun ⟨h₁, h₂⟩ => re_add_im z ▸ re_add_im w ▸ h₁ ▸ h₂ ▸ rfl⟩
theorem ext {z w : K} (hre : re z = re w) (him : im z = im w) : z = w :=
ext_iff.2 ⟨hre, him⟩
@[norm_cast]
theorem ofReal_zero : ((0 : ℝ) : K) = 0 :=
algebraMap.coe_zero
@[rclike_simps]
theorem zero_re' : re (0 : K) = (0 : ℝ) :=
map_zero re
@[norm_cast]
theorem ofReal_one : ((1 : ℝ) : K) = 1 :=
map_one (algebraMap ℝ K)
@[simp, rclike_simps]
theorem one_re : re (1 : K) = 1 := by rw [← ofReal_one, ofReal_re]
@[simp, rclike_simps]
theorem one_im : im (1 : K) = 0 := by rw [← ofReal_one, ofReal_im]
theorem ofReal_injective : Function.Injective ((↑) : ℝ → K) :=
(algebraMap ℝ K).injective
@[norm_cast]
theorem ofReal_inj {z w : ℝ} : (z : K) = (w : K) ↔ z = w :=
algebraMap.coe_inj
-- replaced by `RCLike.ofNat_re`
-- replaced by `RCLike.ofNat_im`
theorem ofReal_eq_zero {x : ℝ} : (x : K) = 0 ↔ x = 0 :=
algebraMap.lift_map_eq_zero_iff x
theorem ofReal_ne_zero {x : ℝ} : (x : K) ≠ 0 ↔ x ≠ 0 :=
ofReal_eq_zero.not
@[rclike_simps, norm_cast]
theorem ofReal_add (r s : ℝ) : ((r + s : ℝ) : K) = r + s :=
algebraMap.coe_add _ _
-- replaced by `RCLike.ofReal_ofNat`
@[rclike_simps, norm_cast]
theorem ofReal_neg (r : ℝ) : ((-r : ℝ) : K) = -r :=
algebraMap.coe_neg r
@[rclike_simps, norm_cast]
theorem ofReal_sub (r s : ℝ) : ((r - s : ℝ) : K) = r - s :=
map_sub (algebraMap ℝ K) r s
@[rclike_simps, norm_cast]
theorem ofReal_sum {α : Type*} (s : Finset α) (f : α → ℝ) :
((∑ i ∈ s, f i : ℝ) : K) = ∑ i ∈ s, (f i : K) :=
map_sum (algebraMap ℝ K) _ _
@[simp, rclike_simps, norm_cast]
theorem ofReal_finsupp_sum {α M : Type*} [Zero M] (f : α →₀ M) (g : α → M → ℝ) :
((f.sum fun a b => g a b : ℝ) : K) = f.sum fun a b => (g a b : K) :=
map_finsuppSum (algebraMap ℝ K) f g
@[rclike_simps, norm_cast]
theorem ofReal_mul (r s : ℝ) : ((r * s : ℝ) : K) = r * s :=
algebraMap.coe_mul _ _
@[rclike_simps, norm_cast]
theorem ofReal_pow (r : ℝ) (n : ℕ) : ((r ^ n : ℝ) : K) = (r : K) ^ n :=
map_pow (algebraMap ℝ K) r n
@[rclike_simps, norm_cast]
theorem ofReal_prod {α : Type*} (s : Finset α) (f : α → ℝ) :
((∏ i ∈ s, f i : ℝ) : K) = ∏ i ∈ s, (f i : K) :=
map_prod (algebraMap ℝ K) _ _
@[simp, rclike_simps, norm_cast]
theorem ofReal_finsuppProd {α M : Type*} [Zero M] (f : α →₀ M) (g : α → M → ℝ) :
((f.prod fun a b => g a b : ℝ) : K) = f.prod fun a b => (g a b : K) :=
map_finsuppProd _ f g
@[deprecated (since := "2025-04-06")] alias ofReal_finsupp_prod := ofReal_finsuppProd
@[simp, norm_cast, rclike_simps]
theorem real_smul_ofReal (r x : ℝ) : r • (x : K) = (r : K) * (x : K) :=
real_smul_eq_coe_mul _ _
@[rclike_simps]
theorem re_ofReal_mul (r : ℝ) (z : K) : re (↑r * z) = r * re z := by
simp only [mul_re, ofReal_im, zero_mul, ofReal_re, sub_zero]
@[rclike_simps]
theorem im_ofReal_mul (r : ℝ) (z : K) : im (↑r * z) = r * im z := by
simp only [add_zero, ofReal_im, zero_mul, ofReal_re, mul_im]
@[rclike_simps]
theorem smul_re (r : ℝ) (z : K) : re (r • z) = r * re z := by
rw [real_smul_eq_coe_mul, re_ofReal_mul]
@[rclike_simps]
theorem smul_im (r : ℝ) (z : K) : im (r • z) = r * im z := by
rw [real_smul_eq_coe_mul, im_ofReal_mul]
@[rclike_simps, norm_cast]
theorem norm_ofReal (r : ℝ) : ‖(r : K)‖ = |r| :=
norm_algebraMap' K r
/-! ### Characteristic zero -/
-- see Note [lower instance priority]
/-- ℝ and ℂ are both of characteristic zero. -/
instance (priority := 100) charZero_rclike : CharZero K :=
(RingHom.charZero_iff (algebraMap ℝ K).injective).1 inferInstance
@[rclike_simps, norm_cast]
lemma ofReal_expect {α : Type*} (s : Finset α) (f : α → ℝ) : 𝔼 i ∈ s, f i = 𝔼 i ∈ s, (f i : K) :=
map_expect (algebraMap ..) ..
@[norm_cast]
lemma ofReal_balance {ι : Type*} [Fintype ι] (f : ι → ℝ) (i : ι) :
((balance f i : ℝ) : K) = balance ((↑) ∘ f) i := map_balance (algebraMap ..) ..
@[simp] lemma ofReal_comp_balance {ι : Type*} [Fintype ι] (f : ι → ℝ) :
ofReal ∘ balance f = balance (ofReal ∘ f : ι → K) := funext <| ofReal_balance _
/-! ### The imaginary unit, `I` -/
/-- The imaginary unit. -/
@[simp, rclike_simps]
theorem I_re : re (I : K) = 0 :=
I_re_ax
@[simp, rclike_simps]
theorem I_im (z : K) : im z * im (I : K) = im z :=
mul_im_I_ax z
@[simp, rclike_simps]
theorem I_im' (z : K) : im (I : K) * im z = im z := by rw [mul_comm, I_im]
@[rclike_simps] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11119): was `simp`
theorem I_mul_re (z : K) : re (I * z) = -im z := by
simp only [I_re, zero_sub, I_im', zero_mul, mul_re]
theorem I_mul_I : (I : K) = 0 ∨ (I : K) * I = -1 :=
I_mul_I_ax
variable (𝕜) in
lemma I_eq_zero_or_im_I_eq_one : (I : K) = 0 ∨ im (I : K) = 1 :=
I_mul_I (K := K) |>.imp_right fun h ↦ by simpa [h] using (I_mul_re (I : K)).symm
@[simp, rclike_simps]
theorem conj_re (z : K) : re (conj z) = re z :=
RCLike.conj_re_ax z
@[simp, rclike_simps]
theorem conj_im (z : K) : im (conj z) = -im z :=
RCLike.conj_im_ax z
@[simp, rclike_simps]
theorem conj_I : conj (I : K) = -I :=
RCLike.conj_I_ax
@[simp, rclike_simps]
theorem conj_ofReal (r : ℝ) : conj (r : K) = (r : K) := by
rw [ext_iff]
simp only [ofReal_im, conj_im, eq_self_iff_true, conj_re, and_self_iff, neg_zero]
-- replaced by `RCLike.conj_ofNat`
theorem conj_nat_cast (n : ℕ) : conj (n : K) = n := map_natCast _ _
theorem conj_ofNat (n : ℕ) [n.AtLeastTwo] : conj (ofNat(n) : K) = ofNat(n) :=
map_ofNat _ _
@[rclike_simps, simp]
theorem conj_neg_I : conj (-I) = (I : K) := by rw [map_neg, conj_I, neg_neg]
theorem conj_eq_re_sub_im (z : K) : conj z = re z - im z * I :=
(congr_arg conj (re_add_im z).symm).trans <| by
rw [map_add, map_mul, conj_I, conj_ofReal, conj_ofReal, mul_neg, sub_eq_add_neg]
theorem sub_conj (z : K) : z - conj z = 2 * im z * I :=
calc
z - conj z = re z + im z * I - (re z - im z * I) := by rw [re_add_im, ← conj_eq_re_sub_im]
_ = 2 * im z * I := by rw [add_sub_sub_cancel, ← two_mul, mul_assoc]
@[rclike_simps]
theorem conj_smul (r : ℝ) (z : K) : conj (r • z) = r • conj z := by
rw [conj_eq_re_sub_im, conj_eq_re_sub_im, smul_re, smul_im, ofReal_mul, ofReal_mul,
real_smul_eq_coe_mul r (_ - _), mul_sub, mul_assoc]
theorem add_conj (z : K) : z + conj z = 2 * re z :=
calc
z + conj z = re z + im z * I + (re z - im z * I) := by rw [re_add_im, conj_eq_re_sub_im]
_ = 2 * re z := by rw [add_add_sub_cancel, two_mul]
theorem re_eq_add_conj (z : K) : ↑(re z) = (z + conj z) / 2 := by
rw [add_conj, mul_div_cancel_left₀ (re z : K) two_ne_zero]
theorem im_eq_conj_sub (z : K) : ↑(im z) = I * (conj z - z) / 2 := by
rw [← neg_inj, ← ofReal_neg, ← I_mul_re, re_eq_add_conj, map_mul, conj_I, ← neg_div, ← mul_neg,
neg_sub, mul_sub, neg_mul, sub_eq_add_neg]
open List in
/-- There are several equivalent ways to say that a number `z` is in fact a real number. -/
theorem is_real_TFAE (z : K) : TFAE [conj z = z, ∃ r : ℝ, (r : K) = z, ↑(re z) = z, im z = 0] := by
tfae_have 1 → 4
| h => by
rw [← @ofReal_inj K, im_eq_conj_sub, h, sub_self, mul_zero, zero_div,
ofReal_zero]
tfae_have 4 → 3
| h => by
conv_rhs => rw [← re_add_im z, h, ofReal_zero, zero_mul, add_zero]
tfae_have 3 → 2 := fun h => ⟨_, h⟩
tfae_have 2 → 1 := fun ⟨r, hr⟩ => hr ▸ conj_ofReal _
tfae_finish
theorem conj_eq_iff_real {z : K} : conj z = z ↔ ∃ r : ℝ, z = (r : K) :=
calc
_ ↔ ∃ r : ℝ, (r : K) = z := (is_real_TFAE z).out 0 1
_ ↔ _ := by simp only [eq_comm]
theorem conj_eq_iff_re {z : K} : conj z = z ↔ (re z : K) = z :=
(is_real_TFAE z).out 0 2
theorem conj_eq_iff_im {z : K} : conj z = z ↔ im z = 0 :=
(is_real_TFAE z).out 0 3
@[simp]
theorem star_def : (Star.star : K → K) = conj :=
rfl
variable (K)
/-- Conjugation as a ring equivalence. This is used to convert the inner product into a
sesquilinear product. -/
abbrev conjToRingEquiv : K ≃+* Kᵐᵒᵖ :=
starRingEquiv
variable {K} {z : K}
/-- The norm squared function. -/
def normSq : K →*₀ ℝ where
toFun z := re z * re z + im z * im z
map_zero' := by simp only [add_zero, mul_zero, map_zero]
map_one' := by simp only [one_im, add_zero, mul_one, one_re, mul_zero]
map_mul' z w := by
simp only [mul_im, mul_re]
ring
theorem normSq_apply (z : K) : normSq z = re z * re z + im z * im z :=
rfl
theorem norm_sq_eq_def {z : K} : ‖z‖ ^ 2 = re z * re z + im z * im z :=
norm_sq_eq_def_ax z
theorem normSq_eq_def' (z : K) : normSq z = ‖z‖ ^ 2 :=
norm_sq_eq_def.symm
@[rclike_simps]
theorem normSq_zero : normSq (0 : K) = 0 :=
normSq.map_zero
@[rclike_simps]
theorem normSq_one : normSq (1 : K) = 1 :=
normSq.map_one
theorem normSq_nonneg (z : K) : 0 ≤ normSq z :=
add_nonneg (mul_self_nonneg _) (mul_self_nonneg _)
@[rclike_simps] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11119): was `simp`
theorem normSq_eq_zero {z : K} : normSq z = 0 ↔ z = 0 :=
map_eq_zero _
@[simp, rclike_simps]
theorem normSq_pos {z : K} : 0 < normSq z ↔ z ≠ 0 := by
rw [lt_iff_le_and_ne, Ne, eq_comm]; simp [normSq_nonneg]
@[simp, rclike_simps]
theorem normSq_neg (z : K) : normSq (-z) = normSq z := by simp only [normSq_eq_def', norm_neg]
@[simp, rclike_simps]
theorem normSq_conj (z : K) : normSq (conj z) = normSq z := by
simp only [normSq_apply, neg_mul, mul_neg, neg_neg, rclike_simps]
@[rclike_simps] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11119): was `simp`
theorem normSq_mul (z w : K) : normSq (z * w) = normSq z * normSq w :=
map_mul _ z w
theorem normSq_add (z w : K) : normSq (z + w) = normSq z + normSq w + 2 * re (z * conj w) := by
simp only [normSq_apply, map_add, rclike_simps]
ring
theorem re_sq_le_normSq (z : K) : re z * re z ≤ normSq z :=
le_add_of_nonneg_right (mul_self_nonneg _)
theorem im_sq_le_normSq (z : K) : im z * im z ≤ normSq z :=
le_add_of_nonneg_left (mul_self_nonneg _)
theorem mul_conj (z : K) : z * conj z = ‖z‖ ^ 2 := by
apply ext <;> simp [← ofReal_pow, norm_sq_eq_def, mul_comm]
theorem conj_mul (z : K) : conj z * z = ‖z‖ ^ 2 := by rw [mul_comm, mul_conj]
lemma inv_eq_conj (hz : ‖z‖ = 1) : z⁻¹ = conj z :=
inv_eq_of_mul_eq_one_left <| by simp_rw [conj_mul, hz, algebraMap.coe_one, one_pow]
theorem normSq_sub (z w : K) : normSq (z - w) = normSq z + normSq w - 2 * re (z * conj w) := by
simp only [normSq_add, sub_eq_add_neg, map_neg, mul_neg, normSq_neg, map_neg]
theorem sqrt_normSq_eq_norm {z : K} : √(normSq z) = ‖z‖ := by
rw [normSq_eq_def', Real.sqrt_sq (norm_nonneg _)]
/-! ### Inversion -/
@[rclike_simps, norm_cast]
theorem ofReal_inv (r : ℝ) : ((r⁻¹ : ℝ) : K) = (r : K)⁻¹ :=
map_inv₀ _ r
theorem inv_def (z : K) : z⁻¹ = conj z * ((‖z‖ ^ 2)⁻¹ : ℝ) := by
rcases eq_or_ne z 0 with (rfl | h₀)
· simp
· apply inv_eq_of_mul_eq_one_right
rw [← mul_assoc, mul_conj, ofReal_inv, ofReal_pow, mul_inv_cancel₀]
simpa
@[simp, rclike_simps]
theorem inv_re (z : K) : re z⁻¹ = re z / normSq z := by
rw [inv_def, normSq_eq_def', mul_comm, re_ofReal_mul, conj_re, div_eq_inv_mul]
@[simp, rclike_simps]
theorem inv_im (z : K) : im z⁻¹ = -im z / normSq z := by
rw [inv_def, normSq_eq_def', mul_comm, im_ofReal_mul, conj_im, div_eq_inv_mul]
theorem div_re (z w : K) : re (z / w) = re z * re w / normSq w + im z * im w / normSq w := by
simp only [div_eq_mul_inv, mul_assoc, sub_eq_add_neg, neg_mul, mul_neg, neg_neg, map_neg,
rclike_simps]
theorem div_im (z w : K) : im (z / w) = im z * re w / normSq w - re z * im w / normSq w := by
simp only [div_eq_mul_inv, mul_assoc, sub_eq_add_neg, add_comm, neg_mul, mul_neg, map_neg,
rclike_simps]
@[rclike_simps] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11119): was `simp`
theorem conj_inv (x : K) : conj x⁻¹ = (conj x)⁻¹ :=
star_inv₀ _
lemma conj_div (x y : K) : conj (x / y) = conj x / conj y := map_div' conj conj_inv _ _
--TODO: Do we rather want the map as an explicit definition?
lemma exists_norm_eq_mul_self (x : K) : ∃ c, ‖c‖ = 1 ∧ ↑‖x‖ = c * x := by
obtain rfl | hx := eq_or_ne x 0
· exact ⟨1, by simp⟩
· exact ⟨‖x‖ / x, by simp [norm_ne_zero_iff.2, hx]⟩
lemma exists_norm_mul_eq_self (x : K) : ∃ c, ‖c‖ = 1 ∧ c * ‖x‖ = x := by
obtain rfl | hx := eq_or_ne x 0
· exact ⟨1, by simp⟩
· exact ⟨x / ‖x‖, by simp [norm_ne_zero_iff.2, hx]⟩
@[rclike_simps, norm_cast]
theorem ofReal_div (r s : ℝ) : ((r / s : ℝ) : K) = r / s :=
map_div₀ (algebraMap ℝ K) r s
theorem div_re_ofReal {z : K} {r : ℝ} : re (z / r) = re z / r := by
rw [div_eq_inv_mul, div_eq_inv_mul, ← ofReal_inv, re_ofReal_mul]
@[rclike_simps, norm_cast]
theorem ofReal_zpow (r : ℝ) (n : ℤ) : ((r ^ n : ℝ) : K) = (r : K) ^ n :=
map_zpow₀ (algebraMap ℝ K) r n
theorem I_mul_I_of_nonzero : (I : K) ≠ 0 → (I : K) * I = -1 :=
I_mul_I_ax.resolve_left
@[simp, rclike_simps]
theorem inv_I : (I : K)⁻¹ = -I := by
by_cases h : (I : K) = 0
· simp [h]
· field_simp [I_mul_I_of_nonzero h]
@[simp, rclike_simps]
theorem div_I (z : K) : z / I = -(z * I) := by rw [div_eq_mul_inv, inv_I, mul_neg]
@[rclike_simps] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11119): was `simp`
theorem normSq_inv (z : K) : normSq z⁻¹ = (normSq z)⁻¹ :=
map_inv₀ normSq z
@[rclike_simps] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11119): was `simp`
theorem normSq_div (z w : K) : normSq (z / w) = normSq z / normSq w :=
map_div₀ normSq z w
@[simp 1100, rclike_simps]
theorem norm_conj (z : K) : ‖conj z‖ = ‖z‖ := by simp only [← sqrt_normSq_eq_norm, normSq_conj]
@[simp, rclike_simps] lemma nnnorm_conj (z : K) : ‖conj z‖₊ = ‖z‖₊ := by simp [nnnorm]
@[simp, rclike_simps] lemma enorm_conj (z : K) : ‖conj z‖ₑ = ‖z‖ₑ := by simp [enorm]
instance (priority := 100) : CStarRing K where
norm_mul_self_le x := le_of_eq <| ((norm_mul _ _).trans <| congr_arg (· * ‖x‖) (norm_conj _)).symm
instance : StarModule ℝ K where
star_smul r a := by
apply RCLike.ext <;> simp [RCLike.smul_re, RCLike.smul_im]
/-! ### Cast lemmas -/
@[rclike_simps, norm_cast]
theorem ofReal_natCast (n : ℕ) : ((n : ℝ) : K) = n :=
map_natCast (algebraMap ℝ K) n
@[rclike_simps, norm_cast]
lemma ofReal_nnratCast (q : ℚ≥0) : ((q : ℝ) : K) = q := map_nnratCast (algebraMap ℝ K) _
@[simp, rclike_simps] -- Porting note: removed `norm_cast`
theorem natCast_re (n : ℕ) : re (n : K) = n := by rw [← ofReal_natCast, ofReal_re]
@[simp, rclike_simps, norm_cast]
theorem natCast_im (n : ℕ) : im (n : K) = 0 := by rw [← ofReal_natCast, ofReal_im]
@[simp, rclike_simps]
theorem ofNat_re (n : ℕ) [n.AtLeastTwo] : re (ofNat(n) : K) = ofNat(n) :=
natCast_re n
@[simp, rclike_simps]
theorem ofNat_im (n : ℕ) [n.AtLeastTwo] : im (ofNat(n) : K) = 0 :=
natCast_im n
@[rclike_simps, norm_cast]
theorem ofReal_ofNat (n : ℕ) [n.AtLeastTwo] : ((ofNat(n) : ℝ) : K) = ofNat(n) :=
ofReal_natCast n
theorem ofNat_mul_re (n : ℕ) [n.AtLeastTwo] (z : K) :
re (ofNat(n) * z) = ofNat(n) * re z := by
rw [← ofReal_ofNat, re_ofReal_mul]
theorem ofNat_mul_im (n : ℕ) [n.AtLeastTwo] (z : K) :
im (ofNat(n) * z) = ofNat(n) * im z := by
rw [← ofReal_ofNat, im_ofReal_mul]
@[rclike_simps, norm_cast]
theorem ofReal_intCast (n : ℤ) : ((n : ℝ) : K) = n :=
map_intCast _ n
@[simp, rclike_simps] -- Porting note: removed `norm_cast`
theorem intCast_re (n : ℤ) : re (n : K) = n := by rw [← ofReal_intCast, ofReal_re]
@[simp, rclike_simps, norm_cast]
theorem intCast_im (n : ℤ) : im (n : K) = 0 := by rw [← ofReal_intCast, ofReal_im]
@[rclike_simps, norm_cast]
theorem ofReal_ratCast (n : ℚ) : ((n : ℝ) : K) = n :=
map_ratCast _ n
@[simp, rclike_simps] -- Porting note: removed `norm_cast`
theorem ratCast_re (q : ℚ) : re (q : K) = q := by rw [← ofReal_ratCast, ofReal_re]
@[simp, rclike_simps, norm_cast]
theorem ratCast_im (q : ℚ) : im (q : K) = 0 := by rw [← ofReal_ratCast, ofReal_im]
/-! ### Norm -/
theorem norm_of_nonneg {r : ℝ} (h : 0 ≤ r) : ‖(r : K)‖ = r :=
(norm_ofReal _).trans (abs_of_nonneg h)
@[simp, rclike_simps, norm_cast]
theorem norm_natCast (n : ℕ) : ‖(n : K)‖ = n := by
rw [← ofReal_natCast]
exact norm_of_nonneg (Nat.cast_nonneg n)
@[simp, rclike_simps, norm_cast] lemma nnnorm_natCast (n : ℕ) : ‖(n : K)‖₊ = n := by simp [nnnorm]
@[simp, rclike_simps]
theorem norm_ofNat (n : ℕ) [n.AtLeastTwo] : ‖(ofNat(n) : K)‖ = ofNat(n) :=
norm_natCast n
@[simp, rclike_simps]
lemma nnnorm_ofNat (n : ℕ) [n.AtLeastTwo] : ‖(ofNat(n) : K)‖₊ = ofNat(n) :=
nnnorm_natCast n
lemma norm_two : ‖(2 : K)‖ = 2 := norm_ofNat 2
lemma nnnorm_two : ‖(2 : K)‖₊ = 2 := nnnorm_ofNat 2
@[simp, rclike_simps, norm_cast]
lemma norm_nnratCast (q : ℚ≥0) : ‖(q : K)‖ = q := by
rw [← ofReal_nnratCast]; exact norm_of_nonneg q.cast_nonneg
@[simp, rclike_simps, norm_cast]
lemma nnnorm_nnratCast (q : ℚ≥0) : ‖(q : K)‖₊ = q := by simp [nnnorm]
variable (K) in
lemma norm_nsmul [NormedAddCommGroup E] [NormedSpace K E] (n : ℕ) (x : E) : ‖n • x‖ = n • ‖x‖ := by
simpa [Nat.cast_smul_eq_nsmul] using norm_smul (n : K) x
variable (K) in
lemma nnnorm_nsmul [NormedAddCommGroup E] [NormedSpace K E] (n : ℕ) (x : E) :
‖n • x‖₊ = n • ‖x‖₊ := by simpa [Nat.cast_smul_eq_nsmul] using nnnorm_smul (n : K) x
section NormedField
variable [NormedField E] [CharZero E] [NormedSpace K E]
include K
variable (K) in
lemma norm_nnqsmul (q : ℚ≥0) (x : E) : ‖q • x‖ = q • ‖x‖ := by
simpa [NNRat.cast_smul_eq_nnqsmul] using norm_smul (q : K) x
variable (K) in
lemma nnnorm_nnqsmul (q : ℚ≥0) (x : E) : ‖q • x‖₊ = q • ‖x‖₊ := by
simpa [NNRat.cast_smul_eq_nnqsmul] using nnnorm_smul (q : K) x
@[bound]
lemma norm_expect_le {ι : Type*} {s : Finset ι} {f : ι → E} : ‖𝔼 i ∈ s, f i‖ ≤ 𝔼 i ∈ s, ‖f i‖ :=
Finset.le_expect_of_subadditive norm_zero norm_add_le fun _ _ ↦ by rw [norm_nnqsmul K]
end NormedField
theorem mul_self_norm (z : K) : ‖z‖ * ‖z‖ = normSq z := by rw [normSq_eq_def', sq]
attribute [rclike_simps] norm_zero norm_one norm_eq_zero abs_norm norm_inv norm_div
theorem abs_re_le_norm (z : K) : |re z| ≤ ‖z‖ := by
rw [mul_self_le_mul_self_iff (abs_nonneg _) (norm_nonneg _), abs_mul_abs_self, mul_self_norm]
apply re_sq_le_normSq
theorem abs_im_le_norm (z : K) : |im z| ≤ ‖z‖ := by
rw [mul_self_le_mul_self_iff (abs_nonneg _) (norm_nonneg _), abs_mul_abs_self, mul_self_norm]
apply im_sq_le_normSq
theorem norm_re_le_norm (z : K) : ‖re z‖ ≤ ‖z‖ :=
abs_re_le_norm z
theorem norm_im_le_norm (z : K) : ‖im z‖ ≤ ‖z‖ :=
abs_im_le_norm z
theorem re_le_norm (z : K) : re z ≤ ‖z‖ :=
(abs_le.1 (abs_re_le_norm z)).2
theorem im_le_norm (z : K) : im z ≤ ‖z‖ :=
(abs_le.1 (abs_im_le_norm _)).2
theorem im_eq_zero_of_le {a : K} (h : ‖a‖ ≤ re a) : im a = 0 := by
simpa only [mul_self_norm a, normSq_apply, left_eq_add, mul_self_eq_zero]
using congr_arg (fun z => z * z) ((re_le_norm a).antisymm h)
theorem re_eq_self_of_le {a : K} (h : ‖a‖ ≤ re a) : (re a : K) = a := by
rw [← conj_eq_iff_re, conj_eq_iff_im, im_eq_zero_of_le h]
open IsAbsoluteValue
theorem abs_re_div_norm_le_one (z : K) : |re z / ‖z‖| ≤ 1 := by
rw [abs_div, abs_norm]
exact div_le_one_of_le₀ (abs_re_le_norm _) (norm_nonneg _)
theorem abs_im_div_norm_le_one (z : K) : |im z / ‖z‖| ≤ 1 := by
rw [abs_div, abs_norm]
exact div_le_one_of_le₀ (abs_im_le_norm _) (norm_nonneg _)
theorem norm_I_of_ne_zero (hI : (I : K) ≠ 0) : ‖(I : K)‖ = 1 := by
rw [← mul_self_inj_of_nonneg (norm_nonneg I) zero_le_one, one_mul, ← norm_mul,
I_mul_I_of_nonzero hI, norm_neg, norm_one]
theorem re_eq_norm_of_mul_conj (x : K) : re (x * conj x) = ‖x * conj x‖ := by
rw [mul_conj, ← ofReal_pow]; simp [-map_pow]
theorem norm_sq_re_add_conj (x : K) : ‖x + conj x‖ ^ 2 = re (x + conj x) ^ 2 := by
rw [add_conj, ← ofReal_ofNat, ← ofReal_mul, norm_ofReal, sq_abs, ofReal_re]
theorem norm_sq_re_conj_add (x : K) : ‖conj x + x‖ ^ 2 = re (conj x + x) ^ 2 := by
rw [add_comm, norm_sq_re_add_conj]
/-! ### Cauchy sequences -/
theorem isCauSeq_re (f : CauSeq K norm) : IsCauSeq abs fun n => re (f n) := fun _ ε0 =>
(f.cauchy ε0).imp fun i H j ij =>
lt_of_le_of_lt (by simpa only [map_sub] using abs_re_le_norm (f j - f i)) (H _ ij)
theorem isCauSeq_im (f : CauSeq K norm) : IsCauSeq abs fun n => im (f n) := fun _ ε0 =>
(f.cauchy ε0).imp fun i H j ij =>
lt_of_le_of_lt (by simpa only [map_sub] using abs_im_le_norm (f j - f i)) (H _ ij)
/-- The real part of a K Cauchy sequence, as a real Cauchy sequence. -/
noncomputable def cauSeqRe (f : CauSeq K norm) : CauSeq ℝ abs :=
⟨_, isCauSeq_re f⟩
/-- The imaginary part of a K Cauchy sequence, as a real Cauchy sequence. -/
noncomputable def cauSeqIm (f : CauSeq K norm) : CauSeq ℝ abs :=
⟨_, isCauSeq_im f⟩
theorem isCauSeq_norm {f : ℕ → K} (hf : IsCauSeq norm f) : IsCauSeq abs (norm ∘ f) := fun ε ε0 =>
let ⟨i, hi⟩ := hf ε ε0
⟨i, fun j hj => lt_of_le_of_lt (abs_norm_sub_norm_le _ _) (hi j hj)⟩
end RCLike
section Instances
noncomputable instance Real.instRCLike : RCLike ℝ where
re := AddMonoidHom.id ℝ
im := 0
I := 0
I_re_ax := by simp only [AddMonoidHom.map_zero]
I_mul_I_ax := Or.intro_left _ rfl
re_add_im_ax z := by
simp only [add_zero, mul_zero, Algebra.id.map_eq_id, RingHom.id_apply, AddMonoidHom.id_apply]
ofReal_re_ax _ := rfl
ofReal_im_ax _ := rfl
mul_re_ax z w := by simp only [sub_zero, mul_zero, AddMonoidHom.zero_apply, AddMonoidHom.id_apply]
mul_im_ax z w := by simp only [add_zero, zero_mul, mul_zero, AddMonoidHom.zero_apply]
conj_re_ax z := by simp only [starRingEnd_apply, star_id_of_comm]
conj_im_ax _ := by simp only [neg_zero, AddMonoidHom.zero_apply]
conj_I_ax := by simp only [RingHom.map_zero, neg_zero]
norm_sq_eq_def_ax z := by simp only [sq, Real.norm_eq_abs, ← abs_mul, abs_mul_self z, add_zero,
mul_zero, AddMonoidHom.zero_apply, AddMonoidHom.id_apply]
mul_im_I_ax _ := by simp only [mul_zero, AddMonoidHom.zero_apply]
le_iff_re_im := (and_iff_left rfl).symm
end Instances
namespace RCLike
section Order
open scoped ComplexOrder
variable {z w : K}
| Mathlib/Analysis/RCLike/Basic.lean | 753 | 754 | theorem lt_iff_re_im : z < w ↔ re z < re w ∧ im z = im w := by | simp_rw [lt_iff_le_and_ne, @RCLike.le_iff_re_im K] |
/-
Copyright (c) 2022 Bolton Bailey. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bolton Bailey, Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne
-/
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Analysis.SpecialFunctions.Pow.Real
import Mathlib.Data.Int.Log
/-!
# Real logarithm base `b`
In this file we define `Real.logb` to be the logarithm of a real number in a given base `b`. We
define this as the division of the natural logarithms of the argument and the base, so that we have
a globally defined function with `logb b 0 = 0`, `logb b (-x) = logb b x` `logb 0 x = 0` and
`logb (-b) x = logb b x`.
We prove some basic properties of this function and its relation to `rpow`.
## Tags
logarithm, continuity
-/
open Set Filter Function
open Topology
noncomputable section
namespace Real
variable {b x y : ℝ}
/-- The real logarithm in a given base. As with the natural logarithm, we define `logb b x` to
be `logb b |x|` for `x < 0`, and `0` for `x = 0`. -/
@[pp_nodot]
noncomputable def logb (b x : ℝ) : ℝ :=
log x / log b
theorem log_div_log : log x / log b = logb b x :=
rfl
@[simp]
theorem logb_zero : logb b 0 = 0 := by simp [logb]
@[simp]
theorem logb_one : logb b 1 = 0 := by simp [logb]
theorem logb_zero_left : logb 0 x = 0 := by simp only [← log_div_log, log_zero, div_zero]
@[simp] theorem logb_zero_left_eq_zero : logb 0 = 0 := by ext; rw [logb_zero_left, Pi.zero_apply]
theorem logb_one_left : logb 1 x = 0 := by simp only [← log_div_log, log_one, div_zero]
@[simp] theorem logb_one_left_eq_zero : logb 1 = 0 := by ext; rw [logb_one_left, Pi.zero_apply]
@[simp]
lemma logb_self_eq_one (hb : 1 < b) : logb b b = 1 :=
div_self (log_pos hb).ne'
lemma logb_self_eq_one_iff : logb b b = 1 ↔ b ≠ 0 ∧ b ≠ 1 ∧ b ≠ -1 :=
Iff.trans ⟨fun h h' => by simp [logb, h'] at h, div_self⟩ log_ne_zero
@[simp]
theorem logb_abs (x : ℝ) : logb b |x| = logb b x := by rw [logb, logb, log_abs]
@[simp]
theorem logb_neg_eq_logb (x : ℝ) : logb b (-x) = logb b x := by
rw [← logb_abs x, ← logb_abs (-x), abs_neg]
theorem logb_mul (hx : x ≠ 0) (hy : y ≠ 0) : logb b (x * y) = logb b x + logb b y := by
simp_rw [logb, log_mul hx hy, add_div]
theorem logb_div (hx : x ≠ 0) (hy : y ≠ 0) : logb b (x / y) = logb b x - logb b y := by
simp_rw [logb, log_div hx hy, sub_div]
@[simp]
theorem logb_inv (x : ℝ) : logb b x⁻¹ = -logb b x := by simp [logb, neg_div]
theorem inv_logb (a b : ℝ) : (logb a b)⁻¹ = logb b a := by simp_rw [logb, inv_div]
theorem inv_logb_mul_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) :
(logb (a * b) c)⁻¹ = (logb a c)⁻¹ + (logb b c)⁻¹ := by
simp_rw [inv_logb]; exact logb_mul h₁ h₂
theorem inv_logb_div_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) :
(logb (a / b) c)⁻¹ = (logb a c)⁻¹ - (logb b c)⁻¹ := by
simp_rw [inv_logb]; exact logb_div h₁ h₂
theorem logb_mul_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) :
logb (a * b) c = ((logb a c)⁻¹ + (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_mul_base h₁ h₂ c, inv_inv]
theorem logb_div_base {a b : ℝ} (h₁ : a ≠ 0) (h₂ : b ≠ 0) (c : ℝ) :
logb (a / b) c = ((logb a c)⁻¹ - (logb b c)⁻¹)⁻¹ := by rw [← inv_logb_div_base h₁ h₂ c, inv_inv]
theorem mul_logb {a b c : ℝ} (h₁ : b ≠ 0) (h₂ : b ≠ 1) (h₃ : b ≠ -1) :
logb a b * logb b c = logb a c := by
unfold logb
rw [mul_comm, div_mul_div_cancel₀ (log_ne_zero.mpr ⟨h₁, h₂, h₃⟩)]
theorem div_logb {a b c : ℝ} (h₁ : c ≠ 0) (h₂ : c ≠ 1) (h₃ : c ≠ -1) :
logb a c / logb b c = logb a b :=
div_div_div_cancel_left' _ _ <| log_ne_zero.mpr ⟨h₁, h₂, h₃⟩
theorem logb_rpow_eq_mul_logb_of_pos (hx : 0 < x) : logb b (x ^ y) = y * logb b x := by
rw [logb, log_rpow hx, logb, mul_div_assoc]
theorem logb_pow (b x : ℝ) (k : ℕ) : logb b (x ^ k) = k * logb b x := by
rw [logb, logb, log_pow, mul_div_assoc]
section BPosAndNeOne
variable (b_pos : 0 < b) (b_ne_one : b ≠ 1)
include b_pos b_ne_one
private theorem log_b_ne_zero : log b ≠ 0 := by
have b_ne_zero : b ≠ 0 := by linarith
have b_ne_minus_one : b ≠ -1 := by linarith
simp [b_ne_one, b_ne_zero, b_ne_minus_one]
@[simp]
theorem logb_rpow : logb b (b ^ x) = x := by
rw [logb, div_eq_iff, log_rpow b_pos]
exact log_b_ne_zero b_pos b_ne_one
theorem rpow_logb_eq_abs (hx : x ≠ 0) : b ^ logb b x = |x| := by
apply log_injOn_pos
· simp only [Set.mem_Ioi]
apply rpow_pos_of_pos b_pos
· simp only [abs_pos, mem_Ioi, Ne, hx, not_false_iff]
rw [log_rpow b_pos, logb, log_abs]
field_simp [log_b_ne_zero b_pos b_ne_one]
@[simp]
| Mathlib/Analysis/SpecialFunctions/Log/Base.lean | 137 | 143 | theorem rpow_logb (hx : 0 < x) : b ^ logb b x = x := by | rw [rpow_logb_eq_abs b_pos b_ne_one hx.ne']
exact abs_of_pos hx
theorem rpow_logb_of_neg (hx : x < 0) : b ^ logb b x = -x := by
rw [rpow_logb_eq_abs b_pos b_ne_one (ne_of_lt hx)]
exact abs_of_neg hx |
/-
Copyright (c) 2022 Michael Stoll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Stoll
-/
import Mathlib.Data.Fintype.Parity
import Mathlib.NumberTheory.LegendreSymbol.ZModChar
import Mathlib.FieldTheory.Finite.Basic
/-!
# Quadratic characters of finite fields
This file defines the quadratic character on a finite field `F` and proves
some basic statements about it.
## Tags
quadratic character
-/
/-!
### Definition of the quadratic character
We define the quadratic character of a finite field `F` with values in ℤ.
-/
section Define
/-- Define the quadratic character with values in ℤ on a monoid with zero `α`.
It takes the value zero at zero; for non-zero argument `a : α`, it is `1`
if `a` is a square, otherwise it is `-1`.
This only deserves the name "character" when it is multiplicative,
e.g., when `α` is a finite field. See `quadraticCharFun_mul`.
We will later define `quadraticChar` to be a multiplicative character
of type `MulChar F ℤ`, when the domain is a finite field `F`.
-/
def quadraticCharFun (α : Type*) [MonoidWithZero α] [DecidableEq α]
[DecidablePred (IsSquare : α → Prop)] (a : α) : ℤ :=
if a = 0 then 0 else if IsSquare a then 1 else -1
end Define
/-!
### Basic properties of the quadratic character
We prove some properties of the quadratic character.
We work with a finite field `F` here.
The interesting case is when the characteristic of `F` is odd.
-/
section quadraticChar
open MulChar
variable {F : Type*} [Field F] [Fintype F] [DecidableEq F]
/-- Some basic API lemmas -/
theorem quadraticCharFun_eq_zero_iff {a : F} : quadraticCharFun F a = 0 ↔ a = 0 := by
simp only [quadraticCharFun]
by_cases ha : a = 0
· simp only [ha, if_true]
· simp only [ha, if_false]
split_ifs <;> simp only [neg_eq_zero, one_ne_zero, not_false_iff]
@[simp]
theorem quadraticCharFun_zero : quadraticCharFun F 0 = 0 := by
simp only [quadraticCharFun, if_true]
@[simp]
| Mathlib/NumberTheory/LegendreSymbol/QuadraticChar/Basic.lean | 75 | 76 | theorem quadraticCharFun_one : quadraticCharFun F 1 = 1 := by | simp only [quadraticCharFun, one_ne_zero, IsSquare.one, if_true, if_false] |
/-
Copyright (c) 2017 Mario Carneiro. 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.Cardinal.Arithmetic
import Mathlib.SetTheory.Ordinal.FixedPoint
/-!
# Cofinality
This file contains the definition of cofinality of an order and an ordinal number.
## Main Definitions
* `Order.cof r` is the cofinality of a reflexive order. This is the smallest cardinality of a subset
`s` that is *cofinal*, i.e. `∀ x, ∃ y ∈ s, r x y`.
* `Ordinal.cof o` is the cofinality of the ordinal `o` when viewed as a linear order.
## Main Statements
* `Cardinal.lt_power_cof`: A consequence of König's theorem stating that `c < c ^ c.ord.cof` for
`c ≥ ℵ₀`.
## Implementation Notes
* The cofinality is defined for ordinals.
If `c` is a cardinal number, its cofinality is `c.ord.cof`.
-/
noncomputable section
open Function Cardinal Set Order
open scoped Ordinal
universe u v w
variable {α : Type u} {β : Type v} {r : α → α → Prop} {s : β → β → Prop}
/-! ### Cofinality of orders -/
attribute [local instance] IsRefl.swap
namespace Order
/-- Cofinality of a reflexive order `≼`. This is the smallest cardinality
of a subset `S : Set α` such that `∀ a, ∃ b ∈ S, a ≼ b`. -/
def cof (r : α → α → Prop) : Cardinal :=
sInf { c | ∃ S : Set α, (∀ a, ∃ b ∈ S, r a b) ∧ #S = c }
/-- The set in the definition of `Order.cof` is nonempty. -/
private theorem cof_nonempty (r : α → α → Prop) [IsRefl α r] :
{ c | ∃ S : Set α, (∀ a, ∃ b ∈ S, r a b) ∧ #S = c }.Nonempty :=
⟨_, Set.univ, fun a => ⟨a, ⟨⟩, refl _⟩, rfl⟩
theorem cof_le (r : α → α → Prop) {S : Set α} (h : ∀ a, ∃ b ∈ S, r a b) : cof r ≤ #S :=
csInf_le' ⟨S, h, rfl⟩
theorem le_cof [IsRefl α r] (c : Cardinal) :
c ≤ cof r ↔ ∀ {S : Set α}, (∀ a, ∃ b ∈ S, r a b) → c ≤ #S := by
rw [cof, le_csInf_iff'' (cof_nonempty r)]
use fun H S h => H _ ⟨S, h, rfl⟩
rintro H d ⟨S, h, rfl⟩
exact H h
end Order
namespace RelIso
private theorem cof_le_lift [IsRefl β s] (f : r ≃r s) :
Cardinal.lift.{v} (Order.cof r) ≤ Cardinal.lift.{u} (Order.cof s) := by
rw [Order.cof, Order.cof, lift_sInf, lift_sInf, le_csInf_iff'' ((Order.cof_nonempty s).image _)]
rintro - ⟨-, ⟨u, H, rfl⟩, rfl⟩
apply csInf_le'
refine ⟨_, ⟨f.symm '' u, fun a => ?_, rfl⟩, lift_mk_eq'.2 ⟨(f.symm.toEquiv.image u).symm⟩⟩
rcases H (f a) with ⟨b, hb, hb'⟩
refine ⟨f.symm b, mem_image_of_mem _ hb, f.map_rel_iff.1 ?_⟩
rwa [RelIso.apply_symm_apply]
theorem cof_eq_lift [IsRefl β s] (f : r ≃r s) :
Cardinal.lift.{v} (Order.cof r) = Cardinal.lift.{u} (Order.cof s) :=
have := f.toRelEmbedding.isRefl
(f.cof_le_lift).antisymm (f.symm.cof_le_lift)
theorem cof_eq {α β : Type u} {r : α → α → Prop} {s} [IsRefl β s] (f : r ≃r s) :
Order.cof r = Order.cof s :=
lift_inj.1 (f.cof_eq_lift)
end RelIso
/-! ### Cofinality of ordinals -/
namespace Ordinal
/-- Cofinality of an ordinal. This is the smallest cardinal of a subset `S` of the ordinal which is
unbounded, in the sense `∀ a, ∃ b ∈ S, a ≤ b`.
In particular, `cof 0 = 0` and `cof (succ o) = 1`. -/
def cof (o : Ordinal.{u}) : Cardinal.{u} :=
o.liftOn (fun a ↦ Order.cof (swap a.rᶜ)) fun _ _ ⟨f⟩ ↦ f.compl.swap.cof_eq
theorem cof_type (r : α → α → Prop) [IsWellOrder α r] : (type r).cof = Order.cof (swap rᶜ) :=
rfl
theorem cof_type_lt [LinearOrder α] [IsWellOrder α (· < ·)] :
(@type α (· < ·) _).cof = @Order.cof α (· ≤ ·) := by
rw [cof_type, compl_lt, swap_ge]
theorem cof_eq_cof_toType (o : Ordinal) : o.cof = @Order.cof o.toType (· ≤ ·) := by
conv_lhs => rw [← type_toType o, cof_type_lt]
theorem le_cof_type [IsWellOrder α r] {c} : c ≤ cof (type r) ↔ ∀ S, Unbounded r S → c ≤ #S :=
(le_csInf_iff'' (Order.cof_nonempty _)).trans
⟨fun H S h => H _ ⟨S, h, rfl⟩, by
rintro H d ⟨S, h, rfl⟩
exact H _ h⟩
theorem cof_type_le [IsWellOrder α r] {S : Set α} (h : Unbounded r S) : cof (type r) ≤ #S :=
le_cof_type.1 le_rfl S h
theorem lt_cof_type [IsWellOrder α r] {S : Set α} : #S < cof (type r) → Bounded r S := by
simpa using not_imp_not.2 cof_type_le
theorem cof_eq (r : α → α → Prop) [IsWellOrder α r] : ∃ S, Unbounded r S ∧ #S = cof (type r) :=
csInf_mem (Order.cof_nonempty (swap rᶜ))
theorem ord_cof_eq (r : α → α → Prop) [IsWellOrder α r] :
∃ S, Unbounded r S ∧ type (Subrel r (· ∈ S)) = (cof (type r)).ord := by
let ⟨S, hS, e⟩ := cof_eq r
let ⟨s, _, e'⟩ := Cardinal.ord_eq S
let T : Set α := { a | ∃ aS : a ∈ S, ∀ b : S, s b ⟨_, aS⟩ → r b a }
suffices Unbounded r T by
refine ⟨T, this, le_antisymm ?_ (Cardinal.ord_le.2 <| cof_type_le this)⟩
rw [← e, e']
refine
(RelEmbedding.ofMonotone
(fun a : T =>
(⟨a,
let ⟨aS, _⟩ := a.2
aS⟩ :
S))
fun a b h => ?_).ordinal_type_le
rcases a with ⟨a, aS, ha⟩
rcases b with ⟨b, bS, hb⟩
change s ⟨a, _⟩ ⟨b, _⟩
refine ((trichotomous_of s _ _).resolve_left fun hn => ?_).resolve_left ?_
· exact asymm h (ha _ hn)
· intro e
injection e with e
subst b
exact irrefl _ h
intro a
have : { b : S | ¬r b a }.Nonempty :=
let ⟨b, bS, ba⟩ := hS a
⟨⟨b, bS⟩, ba⟩
let b := (IsWellFounded.wf : WellFounded s).min _ this
have ba : ¬r b a := IsWellFounded.wf.min_mem _ this
refine ⟨b, ⟨b.2, fun c => not_imp_not.1 fun h => ?_⟩, ba⟩
rw [show ∀ b : S, (⟨b, b.2⟩ : S) = b by intro b; cases b; rfl]
exact IsWellFounded.wf.not_lt_min _ this (IsOrderConnected.neg_trans h ba)
/-! ### Cofinality of suprema and least strict upper bounds -/
private theorem card_mem_cof {o} : ∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = o.card :=
⟨_, _, lsub_typein o, mk_toType o⟩
/-- The set in the `lsub` characterization of `cof` is nonempty. -/
theorem cof_lsub_def_nonempty (o) :
{ a : Cardinal | ∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a }.Nonempty :=
⟨_, card_mem_cof⟩
theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o =
sInf { a : Cardinal | ∃ (ι : Type u) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a } := by
refine le_antisymm (le_csInf (cof_lsub_def_nonempty o) ?_) (csInf_le' ?_)
· rintro a ⟨ι, f, hf, rfl⟩
rw [← type_toType o]
refine
(cof_type_le fun a => ?_).trans
(@mk_le_of_injective _ _
(fun s : typein ((· < ·) : o.toType → o.toType → Prop) ⁻¹' Set.range f =>
Classical.choose s.prop)
fun s t hst => by
let H := congr_arg f hst
rwa [Classical.choose_spec s.prop, Classical.choose_spec t.prop, typein_inj,
Subtype.coe_inj] at H)
have := typein_lt_self a
simp_rw [← hf, lt_lsub_iff] at this
obtain ⟨i, hi⟩ := this
refine ⟨enum (α := o.toType) (· < ·) ⟨f i, ?_⟩, ?_, ?_⟩
· rw [type_toType, ← hf]
apply lt_lsub
· rw [mem_preimage, typein_enum]
exact mem_range_self i
· rwa [← typein_le_typein, typein_enum]
· rcases cof_eq (α := o.toType) (· < ·) with ⟨S, hS, hS'⟩
let f : S → Ordinal := fun s => typein LT.lt s.val
refine ⟨S, f, le_antisymm (lsub_le fun i => typein_lt_self (o := o) i)
(le_of_forall_lt fun a ha => ?_), by rwa [type_toType o] at hS'⟩
rw [← type_toType o] at ha
rcases hS (enum (· < ·) ⟨a, ha⟩) with ⟨b, hb, hb'⟩
rw [← typein_le_typein, typein_enum] at hb'
exact hb'.trans_lt (lt_lsub.{u, u} f ⟨b, hb⟩)
@[simp]
theorem lift_cof (o) : Cardinal.lift.{u, v} (cof o) = cof (Ordinal.lift.{u, v} o) := by
refine inductionOn o fun α r _ ↦ ?_
rw [← type_uLift, cof_type, cof_type, ← Cardinal.lift_id'.{v, u} (Order.cof _),
← Cardinal.lift_umax]
apply RelIso.cof_eq_lift ⟨Equiv.ulift.symm, _⟩
simp [swap]
theorem cof_le_card (o) : cof o ≤ card o := by
rw [cof_eq_sInf_lsub]
exact csInf_le' card_mem_cof
theorem cof_ord_le (c : Cardinal) : c.ord.cof ≤ c := by simpa using cof_le_card c.ord
theorem ord_cof_le (o : Ordinal.{u}) : o.cof.ord ≤ o :=
(ord_le_ord.2 (cof_le_card o)).trans (ord_card_le o)
theorem exists_lsub_cof (o : Ordinal) :
∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = cof o := by
rw [cof_eq_sInf_lsub]
exact csInf_mem (cof_lsub_def_nonempty o)
theorem cof_lsub_le {ι} (f : ι → Ordinal) : cof (lsub.{u, u} f) ≤ #ι := by
rw [cof_eq_sInf_lsub]
exact csInf_le' ⟨ι, f, rfl, rfl⟩
theorem cof_lsub_le_lift {ι} (f : ι → Ordinal) :
cof (lsub.{u, v} f) ≤ Cardinal.lift.{v, u} #ι := by
rw [← mk_uLift.{u, v}]
convert cof_lsub_le.{max u v} fun i : ULift.{v, u} ι => f i.down
exact
lsub_eq_of_range_eq.{u, max u v, max u v}
(Set.ext fun x => ⟨fun ⟨i, hi⟩ => ⟨ULift.up.{v, u} i, hi⟩, fun ⟨i, hi⟩ => ⟨_, hi⟩⟩)
theorem le_cof_iff_lsub {o : Ordinal} {a : Cardinal} :
a ≤ cof o ↔ ∀ {ι} (f : ι → Ordinal), lsub.{u, u} f = o → a ≤ #ι := by
rw [cof_eq_sInf_lsub]
exact
(le_csInf_iff'' (cof_lsub_def_nonempty o)).trans
⟨fun H ι f hf => H _ ⟨ι, f, hf, rfl⟩, fun H b ⟨ι, f, hf, hb⟩ => by
rw [← hb]
exact H _ hf⟩
theorem lsub_lt_ord_lift {ι} {f : ι → Ordinal} {c : Ordinal}
(hι : Cardinal.lift.{v, u} #ι < c.cof)
(hf : ∀ i, f i < c) : lsub.{u, v} f < c :=
lt_of_le_of_ne (lsub_le hf) fun h => by
subst h
exact (cof_lsub_le_lift.{u, v} f).not_lt hι
theorem lsub_lt_ord {ι} {f : ι → Ordinal} {c : Ordinal} (hι : #ι < c.cof) :
(∀ i, f i < c) → lsub.{u, u} f < c :=
lsub_lt_ord_lift (by rwa [(#ι).lift_id])
theorem cof_iSup_le_lift {ι} {f : ι → Ordinal} (H : ∀ i, f i < iSup f) :
cof (iSup f) ≤ Cardinal.lift.{v, u} #ι := by
rw [← Ordinal.sup] at *
rw [← sup_eq_lsub_iff_lt_sup.{u, v}] at H
rw [H]
exact cof_lsub_le_lift f
theorem cof_iSup_le {ι} {f : ι → Ordinal} (H : ∀ i, f i < iSup f) :
cof (iSup f) ≤ #ι := by
rw [← (#ι).lift_id]
exact cof_iSup_le_lift H
theorem iSup_lt_ord_lift {ι} {f : ι → Ordinal} {c : Ordinal} (hι : Cardinal.lift.{v, u} #ι < c.cof)
(hf : ∀ i, f i < c) : iSup f < c :=
(sup_le_lsub.{u, v} f).trans_lt (lsub_lt_ord_lift hι hf)
theorem iSup_lt_ord {ι} {f : ι → Ordinal} {c : Ordinal} (hι : #ι < c.cof) :
(∀ i, f i < c) → iSup f < c :=
iSup_lt_ord_lift (by rwa [(#ι).lift_id])
theorem iSup_lt_lift {ι} {f : ι → Cardinal} {c : Cardinal}
(hι : Cardinal.lift.{v, u} #ι < c.ord.cof)
(hf : ∀ i, f i < c) : iSup f < c := by
rw [← ord_lt_ord, iSup_ord (Cardinal.bddAbove_range _)]
refine iSup_lt_ord_lift hι fun i => ?_
rw [ord_lt_ord]
apply hf
theorem iSup_lt {ι} {f : ι → Cardinal} {c : Cardinal} (hι : #ι < c.ord.cof) :
(∀ i, f i < c) → iSup f < c :=
iSup_lt_lift (by rwa [(#ι).lift_id])
theorem nfpFamily_lt_ord_lift {ι} {f : ι → Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c)
(hc' : Cardinal.lift.{v, u} #ι < cof c) (hf : ∀ (i), ∀ b < c, f i b < c) {a} (ha : a < c) :
nfpFamily f a < c := by
refine iSup_lt_ord_lift ((Cardinal.lift_le.2 (mk_list_le_max ι)).trans_lt ?_) fun l => ?_
· rw [lift_max]
apply max_lt _ hc'
rwa [Cardinal.lift_aleph0]
· induction' l with i l H
· exact ha
· exact hf _ _ H
theorem nfpFamily_lt_ord {ι} {f : ι → Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c) (hc' : #ι < cof c)
(hf : ∀ (i), ∀ b < c, f i b < c) {a} : a < c → nfpFamily.{u, u} f a < c :=
nfpFamily_lt_ord_lift hc (by rwa [(#ι).lift_id]) hf
theorem nfp_lt_ord {f : Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c) (hf : ∀ i < c, f i < c) {a} :
a < c → nfp f a < c :=
nfpFamily_lt_ord_lift hc (by simpa using Cardinal.one_lt_aleph0.trans hc) fun _ => hf
theorem exists_blsub_cof (o : Ordinal) :
∃ f : ∀ a < (cof o).ord, Ordinal, blsub.{u, u} _ f = o := by
rcases exists_lsub_cof o with ⟨ι, f, hf, hι⟩
rcases Cardinal.ord_eq ι with ⟨r, hr, hι'⟩
rw [← @blsub_eq_lsub' ι r hr] at hf
rw [← hι, hι']
exact ⟨_, hf⟩
theorem le_cof_iff_blsub {b : Ordinal} {a : Cardinal} :
a ≤ cof b ↔ ∀ {o} (f : ∀ a < o, Ordinal), blsub.{u, u} o f = b → a ≤ o.card :=
le_cof_iff_lsub.trans
⟨fun H o f hf => by simpa using H _ hf, fun H ι f hf => by
rcases Cardinal.ord_eq ι with ⟨r, hr, hι'⟩
rw [← @blsub_eq_lsub' ι r hr] at hf
simpa using H _ hf⟩
theorem cof_blsub_le_lift {o} (f : ∀ a < o, Ordinal) :
cof (blsub.{u, v} o f) ≤ Cardinal.lift.{v, u} o.card := by
rw [← mk_toType o]
exact cof_lsub_le_lift _
theorem cof_blsub_le {o} (f : ∀ a < o, Ordinal) : cof (blsub.{u, u} o f) ≤ o.card := by
rw [← o.card.lift_id]
exact cof_blsub_le_lift f
theorem blsub_lt_ord_lift {o : Ordinal.{u}} {f : ∀ a < o, Ordinal} {c : Ordinal}
(ho : Cardinal.lift.{v, u} o.card < c.cof) (hf : ∀ i hi, f i hi < c) : blsub.{u, v} o f < c :=
lt_of_le_of_ne (blsub_le hf) fun h =>
ho.not_le (by simpa [← iSup_ord, hf, h] using cof_blsub_le_lift.{u, v} f)
theorem blsub_lt_ord {o : Ordinal} {f : ∀ a < o, Ordinal} {c : Ordinal} (ho : o.card < c.cof)
(hf : ∀ i hi, f i hi < c) : blsub.{u, u} o f < c :=
blsub_lt_ord_lift (by rwa [o.card.lift_id]) hf
theorem cof_bsup_le_lift {o : Ordinal} {f : ∀ a < o, Ordinal} (H : ∀ i h, f i h < bsup.{u, v} o f) :
cof (bsup.{u, v} o f) ≤ Cardinal.lift.{v, u} o.card := by
rw [← bsup_eq_blsub_iff_lt_bsup.{u, v}] at H
rw [H]
exact cof_blsub_le_lift.{u, v} f
theorem cof_bsup_le {o : Ordinal} {f : ∀ a < o, Ordinal} :
(∀ i h, f i h < bsup.{u, u} o f) → cof (bsup.{u, u} o f) ≤ o.card := by
rw [← o.card.lift_id]
exact cof_bsup_le_lift
theorem bsup_lt_ord_lift {o : Ordinal} {f : ∀ a < o, Ordinal} {c : Ordinal}
(ho : Cardinal.lift.{v, u} o.card < c.cof) (hf : ∀ i hi, f i hi < c) : bsup.{u, v} o f < c :=
(bsup_le_blsub f).trans_lt (blsub_lt_ord_lift ho hf)
theorem bsup_lt_ord {o : Ordinal} {f : ∀ a < o, Ordinal} {c : Ordinal} (ho : o.card < c.cof) :
(∀ i hi, f i hi < c) → bsup.{u, u} o f < c :=
bsup_lt_ord_lift (by rwa [o.card.lift_id])
/-! ### Basic results -/
@[simp]
theorem cof_zero : cof 0 = 0 := by
refine LE.le.antisymm ?_ (Cardinal.zero_le _)
rw [← card_zero]
exact cof_le_card 0
@[simp]
theorem cof_eq_zero {o} : cof o = 0 ↔ o = 0 :=
⟨inductionOn o fun _ r _ z =>
let ⟨_, hl, e⟩ := cof_eq r
type_eq_zero_iff_isEmpty.2 <|
⟨fun a =>
let ⟨_, h, _⟩ := hl a
(mk_eq_zero_iff.1 (e.trans z)).elim' ⟨_, h⟩⟩,
fun e => by simp [e]⟩
theorem cof_ne_zero {o} : cof o ≠ 0 ↔ o ≠ 0 :=
cof_eq_zero.not
@[simp]
theorem cof_succ (o) : cof (succ o) = 1 := by
apply le_antisymm
· refine inductionOn o fun α r _ => ?_
change cof (type _) ≤ _
rw [← (_ : #_ = 1)]
· apply cof_type_le
refine fun a => ⟨Sum.inr PUnit.unit, Set.mem_singleton _, ?_⟩
rcases a with (a | ⟨⟨⟨⟩⟩⟩) <;> simp [EmptyRelation]
· rw [Cardinal.mk_fintype, Set.card_singleton]
simp
· rw [← Cardinal.succ_zero, succ_le_iff]
simpa [lt_iff_le_and_ne, Cardinal.zero_le] using fun h =>
succ_ne_zero o (cof_eq_zero.1 (Eq.symm h))
@[simp]
theorem cof_eq_one_iff_is_succ {o} : cof.{u} o = 1 ↔ ∃ a, o = succ a :=
⟨inductionOn o fun α r _ z => by
rcases cof_eq r with ⟨S, hl, e⟩; rw [z] at e
obtain ⟨a⟩ := mk_ne_zero_iff.1 (by rw [e]; exact one_ne_zero)
refine
⟨typein r a,
Eq.symm <|
Quotient.sound
⟨RelIso.ofSurjective (RelEmbedding.ofMonotone ?_ fun x y => ?_) fun x => ?_⟩⟩
· apply Sum.rec <;> [exact Subtype.val; exact fun _ => a]
· rcases x with (x | ⟨⟨⟨⟩⟩⟩) <;> rcases y with (y | ⟨⟨⟨⟩⟩⟩) <;>
simp [Subrel, Order.Preimage, EmptyRelation]
exact x.2
· suffices r x a ∨ ∃ _ : PUnit.{u}, ↑a = x by
convert this
dsimp [RelEmbedding.ofMonotone]; simp
rcases trichotomous_of r x a with (h | h | h)
· exact Or.inl h
· exact Or.inr ⟨PUnit.unit, h.symm⟩
· rcases hl x with ⟨a', aS, hn⟩
refine absurd h ?_
convert hn
change (a : α) = ↑(⟨a', aS⟩ : S)
have := le_one_iff_subsingleton.1 (le_of_eq e)
congr!,
fun ⟨a, e⟩ => by simp [e]⟩
/-! ### Fundamental sequences -/
-- TODO: move stuff about fundamental sequences to their own file.
/-- A fundamental sequence for `a` is an increasing sequence of length `o = cof a` that converges at
`a`. We provide `o` explicitly in order to avoid type rewrites. -/
def IsFundamentalSequence (a o : Ordinal.{u}) (f : ∀ b < o, Ordinal.{u}) : Prop :=
o ≤ a.cof.ord ∧ (∀ {i j} (hi hj), i < j → f i hi < f j hj) ∧ blsub.{u, u} o f = a
namespace IsFundamentalSequence
variable {a o : Ordinal.{u}} {f : ∀ b < o, Ordinal.{u}}
protected theorem cof_eq (hf : IsFundamentalSequence a o f) : a.cof.ord = o :=
hf.1.antisymm' <| by
rw [← hf.2.2]
exact (ord_le_ord.2 (cof_blsub_le f)).trans (ord_card_le o)
protected theorem strict_mono (hf : IsFundamentalSequence a o f) {i j} :
∀ hi hj, i < j → f i hi < f j hj :=
hf.2.1
theorem blsub_eq (hf : IsFundamentalSequence a o f) : blsub.{u, u} o f = a :=
hf.2.2
theorem ord_cof (hf : IsFundamentalSequence a o f) :
IsFundamentalSequence a a.cof.ord fun i hi => f i (hi.trans_le (by rw [hf.cof_eq])) := by
have H := hf.cof_eq
subst H
exact hf
theorem id_of_le_cof (h : o ≤ o.cof.ord) : IsFundamentalSequence o o fun a _ => a :=
⟨h, @fun _ _ _ _ => id, blsub_id o⟩
protected theorem zero {f : ∀ b < (0 : Ordinal), Ordinal} : IsFundamentalSequence 0 0 f :=
⟨by rw [cof_zero, ord_zero], @fun i _ hi => (Ordinal.not_lt_zero i hi).elim, blsub_zero f⟩
protected theorem succ : IsFundamentalSequence (succ o) 1 fun _ _ => o := by
refine ⟨?_, @fun i j hi hj h => ?_, blsub_const Ordinal.one_ne_zero o⟩
· rw [cof_succ, ord_one]
· rw [lt_one_iff_zero] at hi hj
rw [hi, hj] at h
exact h.false.elim
protected theorem monotone (hf : IsFundamentalSequence a o f) {i j : Ordinal} (hi : i < o)
(hj : j < o) (hij : i ≤ j) : f i hi ≤ f j hj := by
rcases lt_or_eq_of_le hij with (hij | rfl)
· exact (hf.2.1 hi hj hij).le
· rfl
theorem trans {a o o' : Ordinal.{u}} {f : ∀ b < o, Ordinal.{u}} (hf : IsFundamentalSequence a o f)
{g : ∀ b < o', Ordinal.{u}} (hg : IsFundamentalSequence o o' g) :
IsFundamentalSequence a o' fun i hi =>
f (g i hi) (by rw [← hg.2.2]; apply lt_blsub) := by
refine ⟨?_, @fun i j _ _ h => hf.2.1 _ _ (hg.2.1 _ _ h), ?_⟩
· rw [hf.cof_eq]
exact hg.1.trans (ord_cof_le o)
· rw [@blsub_comp.{u, u, u} o _ f (@IsFundamentalSequence.monotone _ _ f hf)]
· exact hf.2.2
· exact hg.2.2
protected theorem lt {a o : Ordinal} {s : Π p < o, Ordinal}
(h : IsFundamentalSequence a o s) {p : Ordinal} (hp : p < o) : s p hp < a :=
h.blsub_eq ▸ lt_blsub s p hp
end IsFundamentalSequence
/-- Every ordinal has a fundamental sequence. -/
theorem exists_fundamental_sequence (a : Ordinal.{u}) :
∃ f, IsFundamentalSequence a a.cof.ord f := by
suffices h : ∃ o f, IsFundamentalSequence a o f by
rcases h with ⟨o, f, hf⟩
exact ⟨_, hf.ord_cof⟩
rcases exists_lsub_cof a with ⟨ι, f, hf, hι⟩
rcases ord_eq ι with ⟨r, wo, hr⟩
haveI := wo
let r' := Subrel r fun i ↦ ∀ j, r j i → f j < f i
let hrr' : r' ↪r r := Subrel.relEmbedding _ _
haveI := hrr'.isWellOrder
refine
⟨_, _, hrr'.ordinal_type_le.trans ?_, @fun i j _ h _ => (enum r' ⟨j, h⟩).prop _ ?_,
le_antisymm (blsub_le fun i hi => lsub_le_iff.1 hf.le _) ?_⟩
· rw [← hι, hr]
· change r (hrr'.1 _) (hrr'.1 _)
rwa [hrr'.2, @enum_lt_enum _ r']
· rw [← hf, lsub_le_iff]
intro i
suffices h : ∃ i' hi', f i ≤ bfamilyOfFamily' r' (fun i => f i) i' hi' by
rcases h with ⟨i', hi', hfg⟩
exact hfg.trans_lt (lt_blsub _ _ _)
by_cases h : ∀ j, r j i → f j < f i
· refine ⟨typein r' ⟨i, h⟩, typein_lt_type _ _, ?_⟩
rw [bfamilyOfFamily'_typein]
· push_neg at h
obtain ⟨hji, hij⟩ := wo.wf.min_mem _ h
refine ⟨typein r' ⟨_, fun k hkj => lt_of_lt_of_le ?_ hij⟩, typein_lt_type _ _, ?_⟩
· by_contra! H
exact (wo.wf.not_lt_min _ h ⟨IsTrans.trans _ _ _ hkj hji, H⟩) hkj
· rwa [bfamilyOfFamily'_typein]
@[simp]
theorem cof_cof (a : Ordinal.{u}) : cof (cof a).ord = cof a := by
obtain ⟨f, hf⟩ := exists_fundamental_sequence a
obtain ⟨g, hg⟩ := exists_fundamental_sequence a.cof.ord
exact ord_injective (hf.trans hg).cof_eq.symm
protected theorem IsNormal.isFundamentalSequence {f : Ordinal.{u} → Ordinal.{u}} (hf : IsNormal f)
{a o} (ha : IsLimit a) {g} (hg : IsFundamentalSequence a o g) :
IsFundamentalSequence (f a) o fun b hb => f (g b hb) := by
refine ⟨?_, @fun i j _ _ h => hf.strictMono (hg.2.1 _ _ h), ?_⟩
· rcases exists_lsub_cof (f a) with ⟨ι, f', hf', hι⟩
rw [← hg.cof_eq, ord_le_ord, ← hι]
suffices (lsub.{u, u} fun i => sInf { b : Ordinal | f' i ≤ f b }) = a by
rw [← this]
apply cof_lsub_le
have H : ∀ i, ∃ b < a, f' i ≤ f b := fun i => by
have := lt_lsub.{u, u} f' i
rw [hf', ← IsNormal.blsub_eq.{u, u} hf ha, lt_blsub_iff] at this
simpa using this
refine (lsub_le fun i => ?_).antisymm (le_of_forall_lt fun b hb => ?_)
· rcases H i with ⟨b, hb, hb'⟩
exact lt_of_le_of_lt (csInf_le' hb') hb
· have := hf.strictMono hb
rw [← hf', lt_lsub_iff] at this
obtain ⟨i, hi⟩ := this
rcases H i with ⟨b, _, hb⟩
exact
((le_csInf_iff'' ⟨b, by exact hb⟩).2 fun c hc =>
hf.strictMono.le_iff_le.1 (hi.trans hc)).trans_lt (lt_lsub _ i)
· rw [@blsub_comp.{u, u, u} a _ (fun b _ => f b) (@fun i j _ _ h => hf.strictMono.monotone h) g
hg.2.2]
exact IsNormal.blsub_eq.{u, u} hf ha
theorem IsNormal.cof_eq {f} (hf : IsNormal f) {a} (ha : IsLimit a) : cof (f a) = cof a :=
let ⟨_, hg⟩ := exists_fundamental_sequence a
ord_injective (hf.isFundamentalSequence ha hg).cof_eq
theorem IsNormal.cof_le {f} (hf : IsNormal f) (a) : cof a ≤ cof (f a) := by
rcases zero_or_succ_or_limit a with (rfl | ⟨b, rfl⟩ | ha)
· rw [cof_zero]
exact zero_le _
· rw [cof_succ, Cardinal.one_le_iff_ne_zero, cof_ne_zero, ← Ordinal.pos_iff_ne_zero]
exact (Ordinal.zero_le (f b)).trans_lt (hf.1 b)
· rw [hf.cof_eq ha]
@[simp]
theorem cof_add (a b : Ordinal) : b ≠ 0 → cof (a + b) = cof b := fun h => by
rcases zero_or_succ_or_limit b with (rfl | ⟨c, rfl⟩ | hb)
· contradiction
· rw [add_succ, cof_succ, cof_succ]
· exact (isNormal_add_right a).cof_eq hb
theorem aleph0_le_cof {o} : ℵ₀ ≤ cof o ↔ IsLimit o := by
rcases zero_or_succ_or_limit o with (rfl | ⟨o, rfl⟩ | l)
· simp [not_zero_isLimit, Cardinal.aleph0_ne_zero]
· simp [not_succ_isLimit, Cardinal.one_lt_aleph0]
· simp only [l, iff_true]
refine le_of_not_lt fun h => ?_
obtain ⟨n, e⟩ := Cardinal.lt_aleph0.1 h
have := cof_cof o
rw [e, ord_nat] at this
cases n
· simp at e
simp [e, not_zero_isLimit] at l
· rw [natCast_succ, cof_succ] at this
rw [← this, cof_eq_one_iff_is_succ] at e
rcases e with ⟨a, rfl⟩
exact not_succ_isLimit _ l
@[simp]
theorem cof_preOmega {o : Ordinal} (ho : IsSuccPrelimit o) : (preOmega o).cof = o.cof := by
by_cases h : IsMin o
· simp [h.eq_bot]
· exact isNormal_preOmega.cof_eq ⟨h, ho⟩
@[simp]
theorem cof_omega {o : Ordinal} (ho : o.IsLimit) : (ω_ o).cof = o.cof :=
isNormal_omega.cof_eq ho
@[simp]
theorem cof_omega0 : cof ω = ℵ₀ :=
(aleph0_le_cof.2 isLimit_omega0).antisymm' <| by
rw [← card_omega0]
apply cof_le_card
theorem cof_eq' (r : α → α → Prop) [IsWellOrder α r] (h : IsLimit (type r)) :
∃ S : Set α, (∀ a, ∃ b ∈ S, r a b) ∧ #S = cof (type r) :=
let ⟨S, H, e⟩ := cof_eq r
⟨S, fun a =>
let a' := enum r ⟨_, h.succ_lt (typein_lt_type r a)⟩
let ⟨b, h, ab⟩ := H a'
⟨b, h,
(IsOrderConnected.conn a b a' <|
(typein_lt_typein r).1
(by
rw [typein_enum]
exact lt_succ (typein _ _))).resolve_right
ab⟩,
e⟩
@[simp]
theorem cof_univ : cof univ.{u, v} = Cardinal.univ.{u, v} :=
le_antisymm (cof_le_card _)
(by
refine le_of_forall_lt fun c h => ?_
rcases lt_univ'.1 h with ⟨c, rfl⟩
rcases @cof_eq Ordinal.{u} (· < ·) _ with ⟨S, H, Se⟩
rw [univ, ← lift_cof, ← Cardinal.lift_lift.{u+1, v, u}, Cardinal.lift_lt, ← Se]
refine lt_of_not_ge fun h => ?_
obtain ⟨a, e⟩ := Cardinal.mem_range_lift_of_le h
refine Quotient.inductionOn a (fun α e => ?_) e
obtain ⟨f⟩ := Quotient.exact e
have f := Equiv.ulift.symm.trans f
let g a := (f a).1
let o := succ (iSup g)
rcases H o with ⟨b, h, l⟩
refine l (lt_succ_iff.2 ?_)
rw [← show g (f.symm ⟨b, h⟩) = b by simp [g]]
apply Ordinal.le_iSup)
end Ordinal
namespace Cardinal
open Ordinal
/-! ### Results on sets -/
theorem mk_bounded_subset {α : Type*} (h : ∀ x < #α, 2 ^ x < #α) {r : α → α → Prop}
[IsWellOrder α r] (hr : (#α).ord = type r) : #{ s : Set α // Bounded r s } = #α := by
rcases eq_or_ne #α 0 with (ha | ha)
· rw [ha]
haveI := mk_eq_zero_iff.1 ha
rw [mk_eq_zero_iff]
constructor
rintro ⟨s, hs⟩
exact (not_unbounded_iff s).2 hs (unbounded_of_isEmpty s)
have h' : IsStrongLimit #α := ⟨ha, @h⟩
have ha := h'.aleph0_le
apply le_antisymm
· have : { s : Set α | Bounded r s } = ⋃ i, 𝒫{ j | r j i } := setOf_exists _
rw [← coe_setOf, this]
refine mk_iUnion_le_sum_mk.trans ((sum_le_iSup (fun i => #(𝒫{ j | r j i }))).trans
((mul_le_max_of_aleph0_le_left ha).trans ?_))
rw [max_eq_left]
apply ciSup_le' _
intro i
rw [mk_powerset]
apply (h'.two_power_lt _).le
rw [coe_setOf, card_typein, ← lt_ord, hr]
apply typein_lt_type
· refine @mk_le_of_injective α _ (fun x => Subtype.mk {x} ?_) ?_
· apply bounded_singleton
rw [← hr]
apply isLimit_ord ha
· intro a b hab
simpa [singleton_eq_singleton_iff] using hab
theorem mk_subset_mk_lt_cof {α : Type*} (h : ∀ x < #α, 2 ^ x < #α) :
#{ s : Set α // #s < cof (#α).ord } = #α := by
rcases eq_or_ne #α 0 with (ha | ha)
· simp [ha]
have h' : IsStrongLimit #α := ⟨ha, @h⟩
rcases ord_eq α with ⟨r, wo, hr⟩
haveI := wo
apply le_antisymm
· conv_rhs => rw [← mk_bounded_subset h hr]
apply mk_le_mk_of_subset
intro s hs
rw [hr] at hs
exact lt_cof_type hs
· refine @mk_le_of_injective α _ (fun x => Subtype.mk {x} ?_) ?_
· rw [mk_singleton]
exact one_lt_aleph0.trans_le (aleph0_le_cof.2 (isLimit_ord h'.aleph0_le))
· intro a b hab
simpa [singleton_eq_singleton_iff] using hab
/-- If the union of s is unbounded and s is smaller than the cofinality,
then s has an unbounded member -/
| Mathlib/SetTheory/Cardinal/Cofinality.lean | 704 | 719 | theorem unbounded_of_unbounded_sUnion (r : α → α → Prop) [wo : IsWellOrder α r] {s : Set (Set α)}
(h₁ : Unbounded r <| ⋃₀ s) (h₂ : #s < Order.cof (swap rᶜ)) : ∃ x ∈ s, Unbounded r x := by | by_contra! h
simp_rw [not_unbounded_iff] at h
let f : s → α := fun x : s => wo.wf.sup x (h x.1 x.2)
refine h₂.not_le (le_trans (csInf_le' ⟨range f, fun x => ?_, rfl⟩) mk_range_le)
rcases h₁ x with ⟨y, ⟨c, hc, hy⟩, hxy⟩
exact ⟨f ⟨c, hc⟩, mem_range_self _, fun hxz => hxy (Trans.trans (wo.wf.lt_sup _ hy) hxz)⟩
/-- If the union of s is unbounded and s is smaller than the cofinality,
then s has an unbounded member -/
theorem unbounded_of_unbounded_iUnion {α β : Type u} (r : α → α → Prop) [wo : IsWellOrder α r]
(s : β → Set α) (h₁ : Unbounded r <| ⋃ x, s x) (h₂ : #β < Order.cof (swap rᶜ)) :
∃ x : β, Unbounded r (s x) := by
rw [← sUnion_range] at h₁
rcases unbounded_of_unbounded_sUnion r h₁ (mk_range_le.trans_lt h₂) with ⟨_, ⟨x, rfl⟩, u⟩ |
/-
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.RingTheory.WittVector.Frobenius
import Mathlib.RingTheory.WittVector.Verschiebung
import Mathlib.RingTheory.WittVector.MulP
/-!
## Identities between operations on the ring of Witt vectors
In this file we derive common identities between the Frobenius and Verschiebung operators.
## Main declarations
* `frobenius_verschiebung`: the composition of Frobenius and Verschiebung is multiplication by `p`
* `verschiebung_mul_frobenius`: the “projection formula”: `V(x * F y) = V x * y`
* `iterate_verschiebung_mul_coeff`: an identity from [Haze09] 6.2
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
namespace WittVector
variable {p : ℕ} {R : Type*} [hp : Fact p.Prime] [CommRing R]
-- type as `\bbW`
local notation "𝕎" => WittVector p
noncomputable section
-- Porting note: `ghost_calc` failure: `simp only []` and the manual instances had to be added.
/-- The composition of Frobenius and Verschiebung is multiplication by `p`. -/
theorem frobenius_verschiebung (x : 𝕎 R) : frobenius (verschiebung x) = x * p := by
have : IsPoly p fun {R} [CommRing R] x ↦ frobenius (verschiebung x) :=
IsPoly.comp (hg := frobenius_isPoly p) (hf := verschiebung_isPoly)
have : IsPoly p fun {R} [CommRing R] x ↦ x * p := mulN_isPoly p p
ghost_calc x
ghost_simp [mul_comm]
/-- Verschiebung is the same as multiplication by `p` on the ring of Witt vectors of `ZMod p`. -/
theorem verschiebung_zmod (x : 𝕎 (ZMod p)) : verschiebung x = x * p := by
rw [← frobenius_verschiebung, frobenius_zmodp]
variable (p R)
theorem coeff_p_pow [CharP R p] (i : ℕ) : ((p : 𝕎 R) ^ i).coeff i = 1 := by
induction' i with i h
· simp only [one_coeff_zero, Ne, pow_zero]
· rw [pow_succ, ← frobenius_verschiebung, coeff_frobenius_charP,
verschiebung_coeff_succ, h, one_pow]
theorem coeff_p_pow_eq_zero [CharP R p] {i j : ℕ} (hj : j ≠ i) : ((p : 𝕎 R) ^ i).coeff j = 0 := by
induction' i with i hi generalizing j
· rw [pow_zero, one_coeff_eq_of_pos]
exact Nat.pos_of_ne_zero hj
· rw [pow_succ, ← frobenius_verschiebung, coeff_frobenius_charP]
cases j
· rw [verschiebung_coeff_zero, zero_pow hp.out.ne_zero]
· rw [verschiebung_coeff_succ, hi (ne_of_apply_ne _ hj), zero_pow hp.out.ne_zero]
theorem coeff_p [CharP R p] (i : ℕ) : (p : 𝕎 R).coeff i = if i = 1 then 1 else 0 := by
split_ifs with hi
· simpa only [hi, pow_one] using coeff_p_pow p R 1
· simpa only [pow_one] using coeff_p_pow_eq_zero p R hi
@[simp]
theorem coeff_p_zero [CharP R p] : (p : 𝕎 R).coeff 0 = 0 := by
rw [coeff_p, if_neg]
exact zero_ne_one
@[simp]
theorem coeff_p_one [CharP R p] : (p : 𝕎 R).coeff 1 = 1 := by rw [coeff_p, if_pos rfl]
| Mathlib/RingTheory/WittVector/Identities.lean | 81 | 83 | theorem p_nonzero [Nontrivial R] [CharP R p] : (p : 𝕎 R) ≠ 0 := by | intro h
simpa only [h, zero_coeff, zero_ne_one] using coeff_p_one p R |
/-
Copyright (c) 2023 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Analysis.Calculus.Deriv.Add
import Mathlib.Analysis.Calculus.Deriv.Linear
import Mathlib.LinearAlgebra.AffineSpace.AffineMap
/-!
# Derivatives of affine maps
In this file we prove formulas for one-dimensional derivatives of affine maps `f : 𝕜 →ᵃ[𝕜] E`. We
also specialise some of these results to `AffineMap.lineMap` because it is useful to transfer MVT
from dimension 1 to a domain in higher dimension.
## TODO
Add theorems about `deriv`s and `fderiv`s of `ContinuousAffineMap`s once they will be ported to
Mathlib 4.
## Keywords
affine map, derivative, differentiability
-/
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜]
{E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E]
(f : 𝕜 →ᵃ[𝕜] E) {a b : E} {L : Filter 𝕜} {s : Set 𝕜} {x : 𝕜}
namespace AffineMap
theorem hasStrictDerivAt : HasStrictDerivAt f (f.linear 1) x := by
rw [f.decomp]
exact f.linear.hasStrictDerivAt.add_const (f 0)
theorem hasDerivAtFilter : HasDerivAtFilter f (f.linear 1) x L := by
rw [f.decomp]
exact f.linear.hasDerivAtFilter.add_const (f 0)
theorem hasDerivWithinAt : HasDerivWithinAt f (f.linear 1) s x := f.hasDerivAtFilter
theorem hasDerivAt : HasDerivAt f (f.linear 1) x := f.hasDerivAtFilter
protected theorem derivWithin (hs : UniqueDiffWithinAt 𝕜 s x) :
derivWithin f s x = f.linear 1 :=
f.hasDerivWithinAt.derivWithin hs
@[simp] protected theorem deriv : deriv f x = f.linear 1 := f.hasDerivAt.deriv
protected theorem differentiableAt : DifferentiableAt 𝕜 f x := f.hasDerivAt.differentiableAt
protected theorem differentiable : Differentiable 𝕜 f := fun _ ↦ f.differentiableAt
protected theorem differentiableWithinAt : DifferentiableWithinAt 𝕜 f s x :=
f.differentiableAt.differentiableWithinAt
protected theorem differentiableOn : DifferentiableOn 𝕜 f s := fun _ _ ↦ f.differentiableWithinAt
/-!
### Line map
In this section we specialize some lemmas to `AffineMap.lineMap` because this map is very useful to
deduce higher dimensional lemmas from one-dimensional versions.
-/
| Mathlib/Analysis/Calculus/Deriv/AffineMap.lean | 64 | 65 | theorem hasStrictDerivAt_lineMap : HasStrictDerivAt (lineMap a b) (b - a) x := by | simpa using (lineMap a b : 𝕜 →ᵃ[𝕜] E).hasStrictDerivAt |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker
-/
import Mathlib.Algebra.MonoidAlgebra.Support
import Mathlib.Algebra.Polynomial.Basic
import Mathlib.Data.Nat.Choose.Sum
import Mathlib.Algebra.CharP.Defs
/-!
# Theory of univariate polynomials
The theorems include formulas for computing coefficients, such as
`coeff_add`, `coeff_sum`, `coeff_mul`
-/
noncomputable section
open Finsupp Finset AddMonoidAlgebra
open Polynomial
namespace Polynomial
universe u v
variable {R : Type u} {S : Type v} {a b : R} {n m : ℕ}
variable [Semiring R] {p q r : R[X]}
section Coeff
@[simp]
theorem coeff_add (p q : R[X]) (n : ℕ) : coeff (p + q) n = coeff p n + coeff q n := by
rcases p with ⟨⟩
rcases q with ⟨⟩
simp_rw [← ofFinsupp_add, coeff]
exact Finsupp.add_apply _ _ _
@[simp]
theorem coeff_smul [SMulZeroClass S R] (r : S) (p : R[X]) (n : ℕ) :
coeff (r • p) n = r • coeff p n := by
rcases p with ⟨⟩
simp_rw [← ofFinsupp_smul, coeff]
exact Finsupp.smul_apply _ _ _
theorem support_smul [SMulZeroClass S R] (r : S) (p : R[X]) :
support (r • p) ⊆ support p := by
intro i hi
simp? [mem_support_iff] at hi ⊢ says simp only [mem_support_iff, coeff_smul, ne_eq] at hi ⊢
contrapose! hi
simp [hi]
open scoped Pointwise in
theorem card_support_mul_le : #(p * q).support ≤ #p.support * #q.support := by
calc #(p * q).support
_ = #(p.toFinsupp * q.toFinsupp).support := by rw [← support_toFinsupp, toFinsupp_mul]
_ ≤ #(p.toFinsupp.support + q.toFinsupp.support) :=
Finset.card_le_card (AddMonoidAlgebra.support_mul p.toFinsupp q.toFinsupp)
_ ≤ #p.support * #q.support := Finset.card_image₂_le ..
/-- `Polynomial.sum` as a linear map. -/
@[simps]
def lsum {R A M : Type*} [Semiring R] [Semiring A] [AddCommMonoid M] [Module R A] [Module R M]
(f : ℕ → A →ₗ[R] M) : A[X] →ₗ[R] M where
toFun p := p.sum (f · ·)
map_add' p q := sum_add_index p q _ (fun n => (f n).map_zero) fun n _ _ => (f n).map_add _ _
map_smul' c p := by
rw [sum_eq_of_subset (f · ·) (fun n => (f n).map_zero) (support_smul c p)]
simp only [sum_def, Finset.smul_sum, coeff_smul, LinearMap.map_smul, RingHom.id_apply]
variable (R) in
/-- The nth coefficient, as a linear map. -/
def lcoeff (n : ℕ) : R[X] →ₗ[R] R where
toFun p := coeff p n
map_add' p q := coeff_add p q n
map_smul' r p := coeff_smul r p n
@[simp]
theorem lcoeff_apply (n : ℕ) (f : R[X]) : lcoeff R n f = coeff f n :=
rfl
@[simp]
theorem finset_sum_coeff {ι : Type*} (s : Finset ι) (f : ι → R[X]) (n : ℕ) :
coeff (∑ b ∈ s, f b) n = ∑ b ∈ s, coeff (f b) n :=
map_sum (lcoeff R n) _ _
lemma coeff_list_sum (l : List R[X]) (n : ℕ) :
l.sum.coeff n = (l.map (lcoeff R n)).sum :=
map_list_sum (lcoeff R n) _
lemma coeff_list_sum_map {ι : Type*} (l : List ι) (f : ι → R[X]) (n : ℕ) :
(l.map f).sum.coeff n = (l.map (fun a => (f a).coeff n)).sum := by
simp_rw [coeff_list_sum, List.map_map, Function.comp_def, lcoeff_apply]
@[simp]
theorem coeff_sum [Semiring S] (n : ℕ) (f : ℕ → R → S[X]) :
coeff (p.sum f) n = p.sum fun a b => coeff (f a b) n := by
rcases p with ⟨⟩
simp [Polynomial.sum, support_ofFinsupp, coeff_ofFinsupp]
/-- Decomposes the coefficient of the product `p * q` as a sum
over `antidiagonal`. A version which sums over `range (n + 1)` can be obtained
by using `Finset.Nat.sum_antidiagonal_eq_sum_range_succ`. -/
theorem coeff_mul (p q : R[X]) (n : ℕ) :
coeff (p * q) n = ∑ x ∈ antidiagonal n, coeff p x.1 * coeff q x.2 := by
rcases p with ⟨p⟩; rcases q with ⟨q⟩
simp_rw [← ofFinsupp_mul, coeff]
exact AddMonoidAlgebra.mul_apply_antidiagonal p q n _ Finset.mem_antidiagonal
@[simp]
theorem mul_coeff_zero (p q : R[X]) : coeff (p * q) 0 = coeff p 0 * coeff q 0 := by simp [coeff_mul]
theorem mul_coeff_one (p q : R[X]) :
coeff (p * q) 1 = coeff p 0 * coeff q 1 + coeff p 1 * coeff q 0 := by
rw [coeff_mul, Nat.antidiagonal_eq_map]
simp [sum_range_succ]
/-- `constantCoeff p` returns the constant term of the polynomial `p`,
defined as `coeff p 0`. This is a ring homomorphism. -/
@[simps]
def constantCoeff : R[X] →+* R where
toFun p := coeff p 0
map_one' := coeff_one_zero
map_mul' := mul_coeff_zero
map_zero' := coeff_zero 0
map_add' p q := coeff_add p q 0
theorem isUnit_C {x : R} : IsUnit (C x) ↔ IsUnit x :=
⟨fun h => (congr_arg IsUnit coeff_C_zero).mp (h.map <| @constantCoeff R _), fun h => h.map C⟩
theorem coeff_mul_X_zero (p : R[X]) : coeff (p * X) 0 = 0 := by simp
theorem coeff_X_mul_zero (p : R[X]) : coeff (X * p) 0 = 0 := by simp
theorem coeff_C_mul_X_pow (x : R) (k n : ℕ) :
coeff (C x * X ^ k : R[X]) n = if n = k then x else 0 := by
rw [C_mul_X_pow_eq_monomial, coeff_monomial]
congr 1
simp [eq_comm]
theorem coeff_C_mul_X (x : R) (n : ℕ) : coeff (C x * X : R[X]) n = if n = 1 then x else 0 := by
rw [← pow_one X, coeff_C_mul_X_pow]
@[simp]
theorem coeff_C_mul (p : R[X]) : coeff (C a * p) n = a * coeff p n := by
rcases p with ⟨p⟩
simp_rw [← monomial_zero_left, ← ofFinsupp_single, ← ofFinsupp_mul, coeff]
exact AddMonoidAlgebra.single_zero_mul_apply p a n
theorem C_mul' (a : R) (f : R[X]) : C a * f = a • f := by
ext
rw [coeff_C_mul, coeff_smul, smul_eq_mul]
@[simp]
theorem coeff_mul_C (p : R[X]) (n : ℕ) (a : R) : coeff (p * C a) n = coeff p n * a := by
rcases p with ⟨p⟩
simp_rw [← monomial_zero_left, ← ofFinsupp_single, ← ofFinsupp_mul, coeff]
exact AddMonoidAlgebra.mul_single_zero_apply p a n
@[simp] lemma coeff_mul_natCast {a k : ℕ} :
coeff (p * (a : R[X])) k = coeff p k * (↑a : R) := coeff_mul_C _ _ _
@[simp] lemma coeff_natCast_mul {a k : ℕ} :
coeff ((a : R[X]) * p) k = a * coeff p k := coeff_C_mul _
@[simp] lemma coeff_mul_ofNat {a k : ℕ} [Nat.AtLeastTwo a] :
coeff (p * (ofNat(a) : R[X])) k = coeff p k * ofNat(a) := coeff_mul_C _ _ _
@[simp] lemma coeff_ofNat_mul {a k : ℕ} [Nat.AtLeastTwo a] :
coeff ((ofNat(a) : R[X]) * p) k = ofNat(a) * coeff p k := coeff_C_mul _
@[simp] lemma coeff_mul_intCast [Ring S] {p : S[X]} {a : ℤ} {k : ℕ} :
coeff (p * (a : S[X])) k = coeff p k * (↑a : S) := coeff_mul_C _ _ _
@[simp] lemma coeff_intCast_mul [Ring S] {p : S[X]} {a : ℤ} {k : ℕ} :
coeff ((a : S[X]) * p) k = a * coeff p k := coeff_C_mul _
@[simp]
theorem coeff_X_pow (k n : ℕ) : coeff (X ^ k : R[X]) n = if n = k then 1 else 0 := by
simp only [one_mul, RingHom.map_one, ← coeff_C_mul_X_pow]
theorem coeff_X_pow_self (n : ℕ) : coeff (X ^ n : R[X]) n = 1 := by simp
section Fewnomials
open Finset
theorem support_binomial {k m : ℕ} (hkm : k ≠ m) {x y : R} (hx : x ≠ 0) (hy : y ≠ 0) :
support (C x * X ^ k + C y * X ^ m) = {k, m} := by
apply subset_antisymm (support_binomial' k m x y)
simp_rw [insert_subset_iff, singleton_subset_iff, mem_support_iff, coeff_add, coeff_C_mul,
coeff_X_pow_self, mul_one, coeff_X_pow, if_neg hkm, if_neg hkm.symm, mul_zero, zero_add,
add_zero, Ne, hx, hy, not_false_eq_true, and_true]
theorem support_trinomial {k m n : ℕ} (hkm : k < m) (hmn : m < n) {x y z : R} (hx : x ≠ 0)
(hy : y ≠ 0) (hz : z ≠ 0) :
support (C x * X ^ k + C y * X ^ m + C z * X ^ n) = {k, m, n} := by
apply subset_antisymm (support_trinomial' k m n x y z)
simp_rw [insert_subset_iff, singleton_subset_iff, mem_support_iff, coeff_add, coeff_C_mul,
coeff_X_pow_self, mul_one, coeff_X_pow, if_neg hkm.ne, if_neg hkm.ne', if_neg hmn.ne,
if_neg hmn.ne', if_neg (hkm.trans hmn).ne, if_neg (hkm.trans hmn).ne', mul_zero, add_zero,
zero_add, Ne, hx, hy, hz, not_false_eq_true, and_true]
theorem card_support_binomial {k m : ℕ} (h : k ≠ m) {x y : R} (hx : x ≠ 0) (hy : y ≠ 0) :
#(support (C x * X ^ k + C y * X ^ m)) = 2 := by
rw [support_binomial h hx hy, card_insert_of_not_mem (mt mem_singleton.mp h), card_singleton]
theorem card_support_trinomial {k m n : ℕ} (hkm : k < m) (hmn : m < n) {x y z : R} (hx : x ≠ 0)
(hy : y ≠ 0) (hz : z ≠ 0) : #(support (C x * X ^ k + C y * X ^ m + C z * X ^ n)) = 3 := by
rw [support_trinomial hkm hmn hx hy hz,
card_insert_of_not_mem
(mt mem_insert.mp (not_or_intro hkm.ne (mt mem_singleton.mp (hkm.trans hmn).ne))),
card_insert_of_not_mem (mt mem_singleton.mp hmn.ne), card_singleton]
end Fewnomials
@[simp]
theorem coeff_mul_X_pow (p : R[X]) (n d : ℕ) :
coeff (p * Polynomial.X ^ n) (d + n) = coeff p d := by
rw [coeff_mul, Finset.sum_eq_single (d, n), coeff_X_pow, if_pos rfl, mul_one]
· rintro ⟨i, j⟩ h1 h2
rw [coeff_X_pow, if_neg, mul_zero]
rintro rfl
apply h2
rw [mem_antidiagonal, add_right_cancel_iff] at h1
subst h1
rfl
· exact fun h1 => (h1 (mem_antidiagonal.2 rfl)).elim
@[simp]
theorem coeff_X_pow_mul (p : R[X]) (n d : ℕ) :
coeff (Polynomial.X ^ n * p) (d + n) = coeff p d := by
rw [(commute_X_pow p n).eq, coeff_mul_X_pow]
theorem coeff_mul_X_pow' (p : R[X]) (n d : ℕ) :
(p * X ^ n).coeff d = ite (n ≤ d) (p.coeff (d - n)) 0 := by
split_ifs with h
· rw [← tsub_add_cancel_of_le h, coeff_mul_X_pow, add_tsub_cancel_right]
· refine (coeff_mul _ _ _).trans (Finset.sum_eq_zero fun x hx => ?_)
rw [coeff_X_pow, if_neg, mul_zero]
exact ((le_of_add_le_right (mem_antidiagonal.mp hx).le).trans_lt <| not_le.mp h).ne
theorem coeff_X_pow_mul' (p : R[X]) (n d : ℕ) :
(X ^ n * p).coeff d = ite (n ≤ d) (p.coeff (d - n)) 0 := by
rw [(commute_X_pow p n).eq, coeff_mul_X_pow']
@[simp]
theorem coeff_mul_X (p : R[X]) (n : ℕ) : coeff (p * X) (n + 1) = coeff p n := by
simpa only [pow_one] using coeff_mul_X_pow p 1 n
@[simp]
theorem coeff_X_mul (p : R[X]) (n : ℕ) : coeff (X * p) (n + 1) = coeff p n := by
rw [(commute_X p).eq, coeff_mul_X]
theorem coeff_mul_monomial (p : R[X]) (n d : ℕ) (r : R) :
coeff (p * monomial n r) (d + n) = coeff p d * r := by
rw [← C_mul_X_pow_eq_monomial, ← X_pow_mul, ← mul_assoc, coeff_mul_C, coeff_mul_X_pow]
theorem coeff_monomial_mul (p : R[X]) (n d : ℕ) (r : R) :
coeff (monomial n r * p) (d + n) = r * coeff p d := by
rw [← C_mul_X_pow_eq_monomial, mul_assoc, coeff_C_mul, X_pow_mul, coeff_mul_X_pow]
-- This can already be proved by `simp`.
theorem coeff_mul_monomial_zero (p : R[X]) (d : ℕ) (r : R) :
coeff (p * monomial 0 r) d = coeff p d * r :=
coeff_mul_monomial p 0 d r
-- This can already be proved by `simp`.
theorem coeff_monomial_zero_mul (p : R[X]) (d : ℕ) (r : R) :
coeff (monomial 0 r * p) d = r * coeff p d :=
coeff_monomial_mul p 0 d r
theorem mul_X_pow_eq_zero {p : R[X]} {n : ℕ} (H : p * X ^ n = 0) : p = 0 :=
ext fun k => (coeff_mul_X_pow p n k).symm.trans <| ext_iff.1 H (k + n)
theorem isRegular_X_pow (n : ℕ) : IsRegular (X ^ n : R[X]) := by
suffices IsLeftRegular (X^n : R[X]) from
⟨this, this.right_of_commute (fun p => commute_X_pow p n)⟩
intro P Q (hPQ : X^n * P = X^n * Q)
ext i
rw [← coeff_X_pow_mul P n i, hPQ, coeff_X_pow_mul Q n i]
@[simp] theorem isRegular_X : IsRegular (X : R[X]) := pow_one (X : R[X]) ▸ isRegular_X_pow 1
theorem coeff_X_add_C_pow (r : R) (n k : ℕ) :
((X + C r) ^ n).coeff k = r ^ (n - k) * (n.choose k : R) := by
rw [(commute_X (C r : R[X])).add_pow, ← lcoeff_apply, map_sum]
simp only [one_pow, mul_one, lcoeff_apply, ← C_eq_natCast, ← C_pow, coeff_mul_C, Nat.cast_id]
rw [Finset.sum_eq_single k, coeff_X_pow_self, one_mul]
· intro _ _ h
simp [coeff_X_pow, h.symm]
· simp only [coeff_X_pow_self, one_mul, not_lt, Finset.mem_range]
intro h
rw [Nat.choose_eq_zero_of_lt h, Nat.cast_zero, mul_zero]
theorem coeff_X_add_one_pow (R : Type*) [Semiring R] (n k : ℕ) :
((X + 1) ^ n).coeff k = (n.choose k : R) := by rw [← C_1, coeff_X_add_C_pow, one_pow, one_mul]
theorem coeff_one_add_X_pow (R : Type*) [Semiring R] (n k : ℕ) :
((1 + X) ^ n).coeff k = (n.choose k : R) := by rw [add_comm _ X, coeff_X_add_one_pow]
theorem C_dvd_iff_dvd_coeff (r : R) (φ : R[X]) : C r ∣ φ ↔ ∀ i, r ∣ φ.coeff i := by
constructor
· rintro ⟨φ, rfl⟩ c
rw [coeff_C_mul]
apply dvd_mul_right
· intro h
choose c hc using h
classical
let c' : ℕ → R := fun i => if i ∈ φ.support then c i else 0
let ψ : R[X] := ∑ i ∈ φ.support, monomial i (c' i)
use ψ
ext i
simp only [c', ψ, coeff_C_mul, mem_support_iff, coeff_monomial, finset_sum_coeff,
Finset.sum_ite_eq']
split_ifs with hi
· rw [hc]
· rw [Classical.not_not] at hi
rwa [mul_zero]
| Mathlib/Algebra/Polynomial/Coeff.lean | 325 | 330 | theorem smul_eq_C_mul (a : R) : a • p = C a * p := by | simp [ext_iff]
theorem update_eq_add_sub_coeff {R : Type*} [Ring R] (p : R[X]) (n : ℕ) (a : R) :
p.update n a = p + Polynomial.C (a - p.coeff n) * Polynomial.X ^ n := by
ext
rw [coeff_update_apply, coeff_add, coeff_C_mul_X_pow] |
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.MeasureTheory.Measure.Comap
import Mathlib.MeasureTheory.Measure.QuasiMeasurePreserving
/-!
# Restricting a measure to a subset or a subtype
Given a measure `μ` on a type `α` and a subset `s` of `α`, we define a measure `μ.restrict s` as
the restriction of `μ` to `s` (still as a measure on `α`).
We investigate how this notion interacts with usual operations on measures (sum, pushforward,
pullback), and on sets (inclusion, union, Union).
We also study the relationship between the restriction of a measure to a subtype (given by the
pullback under `Subtype.val`) and the restriction to a set as above.
-/
open scoped ENNReal NNReal Topology
open Set MeasureTheory Measure Filter MeasurableSpace ENNReal Function
variable {R α β δ γ ι : Type*}
namespace MeasureTheory
variable {m0 : MeasurableSpace α} [MeasurableSpace β] [MeasurableSpace γ]
variable {μ μ₁ μ₂ μ₃ ν ν' ν₁ ν₂ : Measure α} {s s' t : Set α}
namespace Measure
/-! ### Restricting a measure -/
/-- Restrict a measure `μ` to a set `s` as an `ℝ≥0∞`-linear map. -/
noncomputable def restrictₗ {m0 : MeasurableSpace α} (s : Set α) : Measure α →ₗ[ℝ≥0∞] Measure α :=
liftLinear (OuterMeasure.restrict s) fun μ s' hs' t => by
suffices μ (s ∩ t) = μ (s ∩ t ∩ s') + μ ((s ∩ t) \ s') by
simpa [← Set.inter_assoc, Set.inter_comm _ s, ← inter_diff_assoc]
exact le_toOuterMeasure_caratheodory _ _ hs' _
/-- Restrict a measure `μ` to a set `s`. -/
noncomputable def restrict {_m0 : MeasurableSpace α} (μ : Measure α) (s : Set α) : Measure α :=
restrictₗ s μ
@[simp]
theorem restrictₗ_apply {_m0 : MeasurableSpace α} (s : Set α) (μ : Measure α) :
restrictₗ s μ = μ.restrict s :=
rfl
/-- This lemma shows that `restrict` and `toOuterMeasure` commute. Note that the LHS has a
restrict on measures and the RHS has a restrict on outer measures. -/
theorem restrict_toOuterMeasure_eq_toOuterMeasure_restrict (h : MeasurableSet s) :
(μ.restrict s).toOuterMeasure = OuterMeasure.restrict s μ.toOuterMeasure := by
simp_rw [restrict, restrictₗ, liftLinear, LinearMap.coe_mk, AddHom.coe_mk,
toMeasure_toOuterMeasure, OuterMeasure.restrict_trim h, μ.trimmed]
theorem restrict_apply₀ (ht : NullMeasurableSet t (μ.restrict s)) : μ.restrict s t = μ (t ∩ s) := by
rw [← restrictₗ_apply, restrictₗ, liftLinear_apply₀ _ ht, OuterMeasure.restrict_apply,
coe_toOuterMeasure]
/-- If `t` is a measurable set, then the measure of `t` with respect to the restriction of
the measure to `s` equals the outer measure of `t ∩ s`. An alternate version requiring that `s`
be measurable instead of `t` exists as `Measure.restrict_apply'`. -/
@[simp]
theorem restrict_apply (ht : MeasurableSet t) : μ.restrict s t = μ (t ∩ s) :=
restrict_apply₀ ht.nullMeasurableSet
/-- Restriction of a measure to a subset is monotone both in set and in measure. -/
theorem restrict_mono' {_m0 : MeasurableSpace α} ⦃s s' : Set α⦄ ⦃μ ν : Measure α⦄ (hs : s ≤ᵐ[μ] s')
(hμν : μ ≤ ν) : μ.restrict s ≤ ν.restrict s' :=
Measure.le_iff.2 fun t ht => calc
μ.restrict s t = μ (t ∩ s) := restrict_apply ht
_ ≤ μ (t ∩ s') := (measure_mono_ae <| hs.mono fun _x hx ⟨hxt, hxs⟩ => ⟨hxt, hx hxs⟩)
_ ≤ ν (t ∩ s') := le_iff'.1 hμν (t ∩ s')
_ = ν.restrict s' t := (restrict_apply ht).symm
/-- Restriction of a measure to a subset is monotone both in set and in measure. -/
@[mono, gcongr]
theorem restrict_mono {_m0 : MeasurableSpace α} ⦃s s' : Set α⦄ (hs : s ⊆ s') ⦃μ ν : Measure α⦄
(hμν : μ ≤ ν) : μ.restrict s ≤ ν.restrict s' :=
restrict_mono' (ae_of_all _ hs) hμν
@[gcongr]
theorem restrict_mono_measure {_ : MeasurableSpace α} {μ ν : Measure α} (h : μ ≤ ν) (s : Set α) :
μ.restrict s ≤ ν.restrict s :=
restrict_mono subset_rfl h
@[gcongr]
theorem restrict_mono_set {_ : MeasurableSpace α} (μ : Measure α) {s t : Set α} (h : s ⊆ t) :
μ.restrict s ≤ μ.restrict t :=
restrict_mono h le_rfl
theorem restrict_mono_ae (h : s ≤ᵐ[μ] t) : μ.restrict s ≤ μ.restrict t :=
restrict_mono' h (le_refl μ)
theorem restrict_congr_set (h : s =ᵐ[μ] t) : μ.restrict s = μ.restrict t :=
le_antisymm (restrict_mono_ae h.le) (restrict_mono_ae h.symm.le)
/-- If `s` is a measurable set, then the outer measure of `t` with respect to the restriction of
the measure to `s` equals the outer measure of `t ∩ s`. This is an alternate version of
`Measure.restrict_apply`, requiring that `s` is measurable instead of `t`. -/
@[simp]
theorem restrict_apply' (hs : MeasurableSet s) : μ.restrict s t = μ (t ∩ s) := by
rw [← toOuterMeasure_apply,
Measure.restrict_toOuterMeasure_eq_toOuterMeasure_restrict hs,
OuterMeasure.restrict_apply s t _, toOuterMeasure_apply]
theorem restrict_apply₀' (hs : NullMeasurableSet s μ) : μ.restrict s t = μ (t ∩ s) := by
rw [← restrict_congr_set hs.toMeasurable_ae_eq,
restrict_apply' (measurableSet_toMeasurable _ _),
measure_congr ((ae_eq_refl t).inter hs.toMeasurable_ae_eq)]
theorem restrict_le_self : μ.restrict s ≤ μ :=
Measure.le_iff.2 fun t ht => calc
μ.restrict s t = μ (t ∩ s) := restrict_apply ht
_ ≤ μ t := measure_mono inter_subset_left
variable (μ)
theorem restrict_eq_self (h : s ⊆ t) : μ.restrict t s = μ s :=
(le_iff'.1 restrict_le_self s).antisymm <|
calc
μ s ≤ μ (toMeasurable (μ.restrict t) s ∩ t) :=
measure_mono (subset_inter (subset_toMeasurable _ _) h)
_ = μ.restrict t s := by
rw [← restrict_apply (measurableSet_toMeasurable _ _), measure_toMeasurable]
@[simp]
theorem restrict_apply_self (s : Set α) : (μ.restrict s) s = μ s :=
restrict_eq_self μ Subset.rfl
variable {μ}
theorem restrict_apply_univ (s : Set α) : μ.restrict s univ = μ s := by
rw [restrict_apply MeasurableSet.univ, Set.univ_inter]
theorem le_restrict_apply (s t : Set α) : μ (t ∩ s) ≤ μ.restrict s t :=
calc
μ (t ∩ s) = μ.restrict s (t ∩ s) := (restrict_eq_self μ inter_subset_right).symm
_ ≤ μ.restrict s t := measure_mono inter_subset_left
theorem restrict_apply_le (s t : Set α) : μ.restrict s t ≤ μ t :=
Measure.le_iff'.1 restrict_le_self _
theorem restrict_apply_superset (h : s ⊆ t) : μ.restrict s t = μ s :=
((measure_mono (subset_univ _)).trans_eq <| restrict_apply_univ _).antisymm
((restrict_apply_self μ s).symm.trans_le <| measure_mono h)
@[simp]
theorem restrict_add {_m0 : MeasurableSpace α} (μ ν : Measure α) (s : Set α) :
(μ + ν).restrict s = μ.restrict s + ν.restrict s :=
(restrictₗ s).map_add μ ν
@[simp]
theorem restrict_zero {_m0 : MeasurableSpace α} (s : Set α) : (0 : Measure α).restrict s = 0 :=
(restrictₗ s).map_zero
@[simp]
theorem restrict_smul {_m0 : MeasurableSpace α} {R : Type*} [SMul R ℝ≥0∞]
[IsScalarTower R ℝ≥0∞ ℝ≥0∞] (c : R) (μ : Measure α) (s : Set α) :
(c • μ).restrict s = c • μ.restrict s := by
simpa only [smul_one_smul] using (restrictₗ s).map_smul (c • 1) μ
theorem restrict_restrict₀ (hs : NullMeasurableSet s (μ.restrict t)) :
(μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
ext fun u hu => by
simp only [Set.inter_assoc, restrict_apply hu,
restrict_apply₀ (hu.nullMeasurableSet.inter hs)]
@[simp]
theorem restrict_restrict (hs : MeasurableSet s) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
restrict_restrict₀ hs.nullMeasurableSet
theorem restrict_restrict_of_subset (h : s ⊆ t) : (μ.restrict t).restrict s = μ.restrict s := by
ext1 u hu
rw [restrict_apply hu, restrict_apply hu, restrict_eq_self]
exact inter_subset_right.trans h
theorem restrict_restrict₀' (ht : NullMeasurableSet t μ) :
(μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
ext fun u hu => by simp only [restrict_apply hu, restrict_apply₀' ht, inter_assoc]
theorem restrict_restrict' (ht : MeasurableSet t) :
(μ.restrict t).restrict s = μ.restrict (s ∩ t) :=
restrict_restrict₀' ht.nullMeasurableSet
theorem restrict_comm (hs : MeasurableSet s) :
(μ.restrict t).restrict s = (μ.restrict s).restrict t := by
rw [restrict_restrict hs, restrict_restrict' hs, inter_comm]
theorem restrict_apply_eq_zero (ht : MeasurableSet t) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 := by
rw [restrict_apply ht]
theorem measure_inter_eq_zero_of_restrict (h : μ.restrict s t = 0) : μ (t ∩ s) = 0 :=
nonpos_iff_eq_zero.1 (h ▸ le_restrict_apply _ _)
theorem restrict_apply_eq_zero' (hs : MeasurableSet s) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 := by
rw [restrict_apply' hs]
@[simp]
| Mathlib/MeasureTheory/Measure/Restrict.lean | 203 | 205 | theorem restrict_eq_zero : μ.restrict s = 0 ↔ μ s = 0 := by | rw [← measure_univ_eq_zero, restrict_apply_univ] |
/-
Copyright (c) 2019 Gabriel Ebner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner, Sébastien Gouëzel, Yury Kudryashov, Anatole Dedecker
-/
import Mathlib.Analysis.Calculus.Deriv.Basic
import Mathlib.Analysis.Calculus.FDeriv.Add
/-!
# One-dimensional derivatives of sums etc
In this file we prove formulas about derivatives of `f + g`, `-f`, `f - g`, and `∑ i, f i x` for
functions from the base field to a normed space over this field.
For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of
`Analysis/Calculus/Deriv/Basic`.
## Keywords
derivative
-/
universe u v w
open scoped Topology Filter ENNReal
open Asymptotics Set
variable {𝕜 : Type u} [NontriviallyNormedField 𝕜]
variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F]
variable {f g : 𝕜 → F}
variable {f' g' : F}
variable {x : 𝕜} {s : Set 𝕜} {L : Filter 𝕜}
section Add
/-! ### Derivative of the sum of two functions -/
nonrec theorem HasDerivAtFilter.add (hf : HasDerivAtFilter f f' x L)
(hg : HasDerivAtFilter g g' x L) : HasDerivAtFilter (fun y => f y + g y) (f' + g') x L := by
simpa using (hf.add hg).hasDerivAtFilter
nonrec theorem HasStrictDerivAt.add (hf : HasStrictDerivAt f f' x) (hg : HasStrictDerivAt g g' x) :
HasStrictDerivAt (fun y => f y + g y) (f' + g') x := by simpa using (hf.add hg).hasStrictDerivAt
nonrec theorem HasDerivWithinAt.add (hf : HasDerivWithinAt f f' s x)
(hg : HasDerivWithinAt g g' s x) : HasDerivWithinAt (fun y => f y + g y) (f' + g') s x :=
hf.add hg
nonrec theorem HasDerivAt.add (hf : HasDerivAt f f' x) (hg : HasDerivAt g g' x) :
HasDerivAt (fun x => f x + g x) (f' + g') x :=
hf.add hg
theorem derivWithin_add (hf : DifferentiableWithinAt 𝕜 f s x)
(hg : DifferentiableWithinAt 𝕜 g s x) :
derivWithin (fun y => f y + g y) s x = derivWithin f s x + derivWithin g s x := by
by_cases hsx : UniqueDiffWithinAt 𝕜 s x
· exact (hf.hasDerivWithinAt.add hg.hasDerivWithinAt).derivWithin hsx
· simp [derivWithin_zero_of_not_uniqueDiffWithinAt hsx]
@[simp]
theorem deriv_add (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) :
deriv (fun y => f y + g y) x = deriv f x + deriv g x :=
(hf.hasDerivAt.add hg.hasDerivAt).deriv
@[simp]
theorem hasDerivAtFilter_add_const_iff (c : F) :
HasDerivAtFilter (f · + c) f' x L ↔ HasDerivAtFilter f f' x L :=
hasFDerivAtFilter_add_const_iff c
alias ⟨_, HasDerivAtFilter.add_const⟩ := hasDerivAtFilter_add_const_iff
@[simp]
theorem hasStrictDerivAt_add_const_iff (c : F) :
HasStrictDerivAt (f · + c) f' x ↔ HasStrictDerivAt f f' x :=
hasStrictFDerivAt_add_const_iff c
alias ⟨_, HasStrictDerivAt.add_const⟩ := hasStrictDerivAt_add_const_iff
@[simp]
theorem hasDerivWithinAt_add_const_iff (c : F) :
HasDerivWithinAt (f · + c) f' s x ↔ HasDerivWithinAt f f' s x :=
hasDerivAtFilter_add_const_iff c
alias ⟨_, HasDerivWithinAt.add_const⟩ := hasDerivWithinAt_add_const_iff
@[simp]
theorem hasDerivAt_add_const_iff (c : F) : HasDerivAt (f · + c) f' x ↔ HasDerivAt f f' x :=
hasDerivAtFilter_add_const_iff c
alias ⟨_, HasDerivAt.add_const⟩ := hasDerivAt_add_const_iff
theorem derivWithin_add_const (c : F) :
derivWithin (fun y => f y + c) s x = derivWithin f s x := by
simp only [derivWithin, fderivWithin_add_const]
theorem deriv_add_const (c : F) : deriv (fun y => f y + c) x = deriv f x := by
simp only [deriv, fderiv_add_const]
@[simp]
theorem deriv_add_const' (c : F) : (deriv fun y => f y + c) = deriv f :=
funext fun _ => deriv_add_const c
theorem hasDerivAtFilter_const_add_iff (c : F) :
HasDerivAtFilter (c + f ·) f' x L ↔ HasDerivAtFilter f f' x L :=
hasFDerivAtFilter_const_add_iff c
alias ⟨_, HasDerivAtFilter.const_add⟩ := hasDerivAtFilter_const_add_iff
@[simp]
theorem hasStrictDerivAt_const_add_iff (c : F) :
HasStrictDerivAt (c + f ·) f' x ↔ HasStrictDerivAt f f' x :=
hasStrictFDerivAt_const_add_iff c
alias ⟨_, HasStrictDerivAt.const_add⟩ := hasStrictDerivAt_const_add_iff
@[simp]
theorem hasDerivWithinAt_const_add_iff (c : F) :
HasDerivWithinAt (c + f ·) f' s x ↔ HasDerivWithinAt f f' s x :=
hasDerivAtFilter_const_add_iff c
alias ⟨_, HasDerivWithinAt.const_add⟩ := hasDerivWithinAt_const_add_iff
@[simp]
theorem hasDerivAt_const_add_iff (c : F) : HasDerivAt (c + f ·) f' x ↔ HasDerivAt f f' x :=
hasDerivAtFilter_const_add_iff c
alias ⟨_, HasDerivAt.const_add⟩ := hasDerivAt_const_add_iff
theorem derivWithin_const_add (c : F) :
derivWithin (c + f ·) s x = derivWithin f s x := by
simp only [derivWithin, fderivWithin_const_add]
@[simp]
theorem derivWithin_const_add_fun (c : F) :
derivWithin (c + f ·) = derivWithin f := by
ext
apply derivWithin_const_add
theorem deriv_const_add (c : F) : deriv (c + f ·) x = deriv f x := by
simp only [deriv, fderiv_const_add]
@[simp]
theorem deriv_const_add' (c : F) : (deriv (c + f ·)) = deriv f :=
funext fun _ => deriv_const_add c
lemma differentiableAt_comp_const_add {a b : 𝕜} :
DifferentiableAt 𝕜 (fun x ↦ f (b + x)) a ↔ DifferentiableAt 𝕜 f (b + a) := by
refine ⟨fun H ↦ ?_, fun H ↦ H.comp _ (differentiable_id.const_add _).differentiableAt⟩
convert DifferentiableAt.comp (b + a) (by simpa)
(differentiable_id.const_add (-b)).differentiableAt
ext
simp
lemma differentiableAt_comp_add_const {a b : 𝕜} :
DifferentiableAt 𝕜 (fun x ↦ f (x + b)) a ↔ DifferentiableAt 𝕜 f (a + b) := by
simpa [add_comm b] using differentiableAt_comp_const_add (f := f) (b := b)
lemma differentiableAt_iff_comp_const_add {a b : 𝕜} :
DifferentiableAt 𝕜 f a ↔ DifferentiableAt 𝕜 (fun x ↦ f (b + x)) (-b + a) := by
simp [differentiableAt_comp_const_add]
lemma differentiableAt_iff_comp_add_const {a b : 𝕜} :
DifferentiableAt 𝕜 f a ↔ DifferentiableAt 𝕜 (fun x ↦ f (x + b)) (a - b) := by
simp [differentiableAt_comp_add_const]
end Add
section Sum
/-! ### Derivative of a finite sum of functions -/
variable {ι : Type*} {u : Finset ι} {A : ι → 𝕜 → F} {A' : ι → F}
theorem HasDerivAtFilter.sum (h : ∀ i ∈ u, HasDerivAtFilter (A i) (A' i) x L) :
HasDerivAtFilter (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) x L := by
simpa [ContinuousLinearMap.sum_apply] using (HasFDerivAtFilter.sum h).hasDerivAtFilter
theorem HasStrictDerivAt.sum (h : ∀ i ∈ u, HasStrictDerivAt (A i) (A' i) x) :
HasStrictDerivAt (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) x := by
simpa [ContinuousLinearMap.sum_apply] using (HasStrictFDerivAt.sum h).hasStrictDerivAt
theorem HasDerivWithinAt.sum (h : ∀ i ∈ u, HasDerivWithinAt (A i) (A' i) s x) :
HasDerivWithinAt (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) s x :=
HasDerivAtFilter.sum h
theorem HasDerivAt.sum (h : ∀ i ∈ u, HasDerivAt (A i) (A' i) x) :
HasDerivAt (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) x :=
HasDerivAtFilter.sum h
theorem derivWithin_sum (h : ∀ i ∈ u, DifferentiableWithinAt 𝕜 (A i) s x) :
derivWithin (fun y => ∑ i ∈ u, A i y) s x = ∑ i ∈ u, derivWithin (A i) s x := by
by_cases hsx : UniqueDiffWithinAt 𝕜 s x
· exact (HasDerivWithinAt.sum fun i hi => (h i hi).hasDerivWithinAt).derivWithin hsx
· simp [derivWithin_zero_of_not_uniqueDiffWithinAt hsx]
@[simp]
theorem deriv_sum (h : ∀ i ∈ u, DifferentiableAt 𝕜 (A i) x) :
deriv (fun y => ∑ i ∈ u, A i y) x = ∑ i ∈ u, deriv (A i) x :=
(HasDerivAt.sum fun i hi => (h i hi).hasDerivAt).deriv
end Sum
section Neg
/-! ### Derivative of the negative of a function -/
nonrec theorem HasDerivAtFilter.neg (h : HasDerivAtFilter f f' x L) :
HasDerivAtFilter (fun x => -f x) (-f') x L := by simpa using h.neg.hasDerivAtFilter
nonrec theorem HasDerivWithinAt.neg (h : HasDerivWithinAt f f' s x) :
HasDerivWithinAt (fun x => -f x) (-f') s x :=
h.neg
nonrec theorem HasDerivAt.neg (h : HasDerivAt f f' x) : HasDerivAt (fun x => -f x) (-f') x :=
h.neg
nonrec theorem HasStrictDerivAt.neg (h : HasStrictDerivAt f f' x) :
HasStrictDerivAt (fun x => -f x) (-f') x := by simpa using h.neg.hasStrictDerivAt
theorem derivWithin.neg : derivWithin (fun y => -f y) s x = -derivWithin f s x := by
by_cases hsx : UniqueDiffWithinAt 𝕜 s x
· simp only [derivWithin, fderivWithin_neg hsx, ContinuousLinearMap.neg_apply]
· simp [derivWithin_zero_of_not_uniqueDiffWithinAt hsx]
theorem deriv.neg : deriv (fun y => -f y) x = -deriv f x := by
simp only [deriv, fderiv_neg, ContinuousLinearMap.neg_apply]
@[simp]
theorem deriv.neg' : (deriv fun y => -f y) = fun x => -deriv f x :=
funext fun _ => deriv.neg
end Neg
section Neg2
/-! ### Derivative of the negation function (i.e `Neg.neg`) -/
variable (s x L)
theorem hasDerivAtFilter_neg : HasDerivAtFilter Neg.neg (-1) x L :=
HasDerivAtFilter.neg <| hasDerivAtFilter_id _ _
theorem hasDerivWithinAt_neg : HasDerivWithinAt Neg.neg (-1) s x :=
hasDerivAtFilter_neg _ _
theorem hasDerivAt_neg : HasDerivAt Neg.neg (-1) x :=
hasDerivAtFilter_neg _ _
theorem hasDerivAt_neg' : HasDerivAt (fun x => -x) (-1) x :=
hasDerivAtFilter_neg _ _
theorem hasStrictDerivAt_neg : HasStrictDerivAt Neg.neg (-1) x :=
HasStrictDerivAt.neg <| hasStrictDerivAt_id _
theorem deriv_neg : deriv Neg.neg x = -1 :=
HasDerivAt.deriv (hasDerivAt_neg x)
@[simp]
theorem deriv_neg' : deriv (Neg.neg : 𝕜 → 𝕜) = fun _ => -1 :=
funext deriv_neg
@[simp]
theorem deriv_neg'' : deriv (fun x : 𝕜 => -x) x = -1 :=
deriv_neg x
theorem derivWithin_neg (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin Neg.neg s x = -1 :=
(hasDerivWithinAt_neg x s).derivWithin hxs
theorem differentiable_neg : Differentiable 𝕜 (Neg.neg : 𝕜 → 𝕜) :=
Differentiable.neg differentiable_id
theorem differentiableOn_neg : DifferentiableOn 𝕜 (Neg.neg : 𝕜 → 𝕜) s :=
DifferentiableOn.neg differentiableOn_id
lemma differentiableAt_comp_neg {a : 𝕜} :
DifferentiableAt 𝕜 (fun x ↦ f (-x)) a ↔ DifferentiableAt 𝕜 f (-a) := by
refine ⟨fun H ↦ ?_, fun H ↦ H.comp a differentiable_neg.differentiableAt⟩
convert ((neg_neg a).symm ▸ H).comp (-a) differentiable_neg.differentiableAt
ext
simp only [Function.comp_apply, neg_neg]
lemma differentiableAt_iff_comp_neg {a : 𝕜} :
DifferentiableAt 𝕜 f a ↔ DifferentiableAt 𝕜 (fun x ↦ f (-x)) (-a) := by
simp_rw [← differentiableAt_comp_neg, neg_neg]
end Neg2
section Sub
/-! ### Derivative of the difference of two functions -/
theorem HasDerivAtFilter.sub (hf : HasDerivAtFilter f f' x L) (hg : HasDerivAtFilter g g' x L) :
HasDerivAtFilter (fun x => f x - g x) (f' - g') x L := by
simpa only [sub_eq_add_neg] using hf.add hg.neg
nonrec theorem HasDerivWithinAt.sub (hf : HasDerivWithinAt f f' s x)
(hg : HasDerivWithinAt g g' s x) : HasDerivWithinAt (fun x => f x - g x) (f' - g') s x :=
hf.sub hg
nonrec theorem HasDerivAt.sub (hf : HasDerivAt f f' x) (hg : HasDerivAt g g' x) :
HasDerivAt (fun x => f x - g x) (f' - g') x :=
hf.sub hg
theorem HasStrictDerivAt.sub (hf : HasStrictDerivAt f f' x) (hg : HasStrictDerivAt g g' x) :
HasStrictDerivAt (fun x => f x - g x) (f' - g') x := by
simpa only [sub_eq_add_neg] using hf.add hg.neg
theorem derivWithin_sub (hf : DifferentiableWithinAt 𝕜 f s x)
(hg : DifferentiableWithinAt 𝕜 g s x) :
derivWithin (fun y => f y - g y) s x = derivWithin f s x - derivWithin g s x := by
simp only [sub_eq_add_neg, derivWithin_add hf hg.neg, derivWithin.neg]
@[simp]
theorem deriv_sub (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) :
deriv (fun y => f y - g y) x = deriv f x - deriv g x :=
(hf.hasDerivAt.sub hg.hasDerivAt).deriv
@[simp]
theorem hasDerivAtFilter_sub_const_iff (c : F) :
HasDerivAtFilter (fun x => f x - c) f' x L ↔ HasDerivAtFilter f f' x L :=
hasFDerivAtFilter_sub_const_iff c
alias ⟨_, HasDerivAtFilter.sub_const⟩ := hasDerivAtFilter_sub_const_iff
@[simp]
theorem hasDerivWithinAt_sub_const_iff (c : F) :
HasDerivWithinAt (f · - c) f' s x ↔ HasDerivWithinAt f f' s x :=
hasDerivAtFilter_sub_const_iff c
alias ⟨_, HasDerivWithinAt.sub_const⟩ := hasDerivWithinAt_sub_const_iff
@[simp]
theorem hasDerivAt_sub_const_iff (c : F) : HasDerivAt (f · - c) f' x ↔ HasDerivAt f f' x :=
hasDerivAtFilter_sub_const_iff c
alias ⟨_, HasDerivAt.sub_const⟩ := hasDerivAt_sub_const_iff
theorem derivWithin_sub_const (c : F) :
derivWithin (fun y => f y - c) s x = derivWithin f s x := by
simp only [derivWithin, fderivWithin_sub_const]
@[simp]
theorem derivWithin_sub_const_fun (c : F) : derivWithin (f · - c) = derivWithin f := by
ext
apply derivWithin_sub_const
theorem deriv_sub_const (c : F) : deriv (fun y => f y - c) x = deriv f x := by
simp only [deriv, fderiv_sub_const]
@[simp]
theorem deriv_sub_const_fun (c : F) : deriv (f · - c) = deriv f := by
ext
apply deriv_sub_const
theorem HasDerivAtFilter.const_sub (c : F) (hf : HasDerivAtFilter f f' x L) :
HasDerivAtFilter (fun x => c - f x) (-f') x L := by
simpa only [sub_eq_add_neg] using hf.neg.const_add c
nonrec theorem HasDerivWithinAt.const_sub (c : F) (hf : HasDerivWithinAt f f' s x) :
HasDerivWithinAt (fun x => c - f x) (-f') s x :=
hf.const_sub c
theorem HasStrictDerivAt.const_sub (c : F) (hf : HasStrictDerivAt f f' x) :
HasStrictDerivAt (fun x => c - f x) (-f') x := by
simpa only [sub_eq_add_neg] using hf.neg.const_add c
nonrec theorem HasDerivAt.const_sub (c : F) (hf : HasDerivAt f f' x) :
HasDerivAt (fun x => c - f x) (-f') x :=
hf.const_sub c
| Mathlib/Analysis/Calculus/Deriv/Add.lean | 373 | 375 | theorem derivWithin_const_sub (c : F) :
derivWithin (fun y => c - f y) s x = -derivWithin f s x := by | simp [sub_eq_add_neg, derivWithin.neg] |
/-
Copyright (c) 2023 Alex Keizer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex Keizer
-/
import Mathlib.Data.Vector.Basic
import Mathlib.Data.Vector.Snoc
/-!
This file establishes a set of normalization lemmas for `map`/`mapAccumr` operations on vectors
-/
variable {α β γ ζ σ σ₁ σ₂ φ : Type*} {n : ℕ} {s : σ} {s₁ : σ₁} {s₂ : σ₂}
namespace List
namespace Vector
/-!
## Fold nested `mapAccumr`s into one
-/
section Fold
section Unary
variable (xs : Vector α n) (f₁ : β → σ₁ → σ₁ × γ) (f₂ : α → σ₂ → σ₂ × β)
@[simp]
theorem mapAccumr_mapAccumr :
mapAccumr f₁ (mapAccumr f₂ xs s₂).snd s₁
= let m := (mapAccumr (fun x s =>
let r₂ := f₂ x s.snd
let r₁ := f₁ r₂.snd s.fst
((r₁.fst, r₂.fst), r₁.snd)
) xs (s₁, s₂))
(m.fst.fst, m.snd) := by
induction xs using Vector.revInductionOn generalizing s₁ s₂ <;> simp_all
@[simp]
theorem mapAccumr_map {s : σ₁} (f₂ : α → β) :
(mapAccumr f₁ (map f₂ xs) s) = (mapAccumr (fun x s => f₁ (f₂ x) s) xs s) := by
induction xs using Vector.revInductionOn generalizing s <;> simp_all
@[simp]
| Mathlib/Data/Vector/MapLemmas.lean | 43 | 47 | theorem map_mapAccumr {s : σ₂} (f₁ : β → γ) :
(map f₁ (mapAccumr f₂ xs s).snd) = (mapAccumr (fun x s =>
let r := (f₂ x s); (r.fst, f₁ r.snd)
) xs s).snd := by | induction xs using Vector.revInductionOn generalizing s <;> simp_all |
/-
Copyright (c) 2019 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Yury Kudryashov, Sébastien Gouëzel, Chris Hughes
-/
import Mathlib.Data.Fin.Rev
import Mathlib.Data.Nat.Find
/-!
# Operation on tuples
We interpret maps `∀ i : Fin n, α i` as `n`-tuples of elements of possibly varying type `α i`,
`(α 0, …, α (n-1))`. A particular case is `Fin n → α` of elements with all the same type.
In this case when `α i` is a constant map, then tuples are isomorphic (but not definitionally equal)
to `Vector`s.
## Main declarations
There are three (main) ways to consider `Fin n` as a subtype of `Fin (n + 1)`, hence three (main)
ways to move between tuples of length `n` and of length `n + 1` by adding/removing an entry.
### Adding at the start
* `Fin.succ`: Send `i : Fin n` to `i + 1 : Fin (n + 1)`. This is defined in Core.
* `Fin.cases`: Induction/recursion principle for `Fin`: To prove a property/define a function for
all `Fin (n + 1)`, it is enough to prove/define it for `0` and for `i.succ` for all `i : Fin n`.
This is defined in Core.
* `Fin.cons`: Turn a tuple `f : Fin n → α` and an entry `a : α` into a tuple
`Fin.cons a f : Fin (n + 1) → α` by adding `a` at the start. In general, tuples can be dependent
functions, in which case `f : ∀ i : Fin n, α i.succ` and `a : α 0`. This is a special case of
`Fin.cases`.
* `Fin.tail`: Turn a tuple `f : Fin (n + 1) → α` into a tuple `Fin.tail f : Fin n → α` by forgetting
the start. In general, tuples can be dependent functions,
in which case `Fin.tail f : ∀ i : Fin n, α i.succ`.
### Adding at the end
* `Fin.castSucc`: Send `i : Fin n` to `i : Fin (n + 1)`. This is defined in Core.
* `Fin.lastCases`: Induction/recursion principle for `Fin`: To prove a property/define a function
for all `Fin (n + 1)`, it is enough to prove/define it for `last n` and for `i.castSucc` for all
`i : Fin n`. This is defined in Core.
* `Fin.snoc`: Turn a tuple `f : Fin n → α` and an entry `a : α` into a tuple
`Fin.snoc f a : Fin (n + 1) → α` by adding `a` at the end. In general, tuples can be dependent
functions, in which case `f : ∀ i : Fin n, α i.castSucc` and `a : α (last n)`. This is a
special case of `Fin.lastCases`.
* `Fin.init`: Turn a tuple `f : Fin (n + 1) → α` into a tuple `Fin.init f : Fin n → α` by forgetting
the start. In general, tuples can be dependent functions,
in which case `Fin.init f : ∀ i : Fin n, α i.castSucc`.
### Adding in the middle
For a **pivot** `p : Fin (n + 1)`,
* `Fin.succAbove`: Send `i : Fin n` to
* `i : Fin (n + 1)` if `i < p`,
* `i + 1 : Fin (n + 1)` if `p ≤ i`.
* `Fin.succAboveCases`: Induction/recursion principle for `Fin`: To prove a property/define a
function for all `Fin (n + 1)`, it is enough to prove/define it for `p` and for `p.succAbove i`
for all `i : Fin n`.
* `Fin.insertNth`: Turn a tuple `f : Fin n → α` and an entry `a : α` into a tuple
`Fin.insertNth f a : Fin (n + 1) → α` by adding `a` in position `p`. In general, tuples can be
dependent functions, in which case `f : ∀ i : Fin n, α (p.succAbove i)` and `a : α p`. This is a
special case of `Fin.succAboveCases`.
* `Fin.removeNth`: Turn a tuple `f : Fin (n + 1) → α` into a tuple `Fin.removeNth p f : Fin n → α`
by forgetting the `p`-th value. In general, tuples can be dependent functions,
in which case `Fin.removeNth f : ∀ i : Fin n, α (succAbove p i)`.
`p = 0` means we add at the start. `p = last n` means we add at the end.
### Miscellaneous
* `Fin.find p` : returns the first index `n` where `p n` is satisfied, and `none` if it is never
satisfied.
* `Fin.append a b` : append two tuples.
* `Fin.repeat n a` : repeat a tuple `n` times.
-/
assert_not_exists Monoid
universe u v
namespace Fin
variable {m n : ℕ}
open Function
section Tuple
/-- There is exactly one tuple of size zero. -/
example (α : Fin 0 → Sort u) : Unique (∀ i : Fin 0, α i) := by infer_instance
theorem tuple0_le {α : Fin 0 → Type*} [∀ i, Preorder (α i)] (f g : ∀ i, α i) : f ≤ g :=
finZeroElim
variable {α : Fin (n + 1) → Sort u} (x : α 0) (q : ∀ i, α i) (p : ∀ i : Fin n, α i.succ) (i : Fin n)
(y : α i.succ) (z : α 0)
/-- The tail of an `n+1` tuple, i.e., its last `n` entries. -/
def tail (q : ∀ i, α i) : ∀ i : Fin n, α i.succ := fun i ↦ q i.succ
theorem tail_def {n : ℕ} {α : Fin (n + 1) → Sort*} {q : ∀ i, α i} :
(tail fun k : Fin (n + 1) ↦ q k) = fun k : Fin n ↦ q k.succ :=
rfl
/-- Adding an element at the beginning of an `n`-tuple, to get an `n+1`-tuple. -/
def cons (x : α 0) (p : ∀ i : Fin n, α i.succ) : ∀ i, α i := fun j ↦ Fin.cases x p j
@[simp]
theorem tail_cons : tail (cons x p) = p := by
simp +unfoldPartialApp [tail, cons]
@[simp]
theorem cons_succ : cons x p i.succ = p i := by simp [cons]
@[simp]
| Mathlib/Data/Fin/Tuple/Basic.lean | 117 | 118 | theorem cons_zero : cons x p 0 = x := by | simp [cons] |
/-
Copyright (c) 2019 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne
-/
import Mathlib.Algebra.BigOperators.Expect
import Mathlib.Algebra.BigOperators.Field
import Mathlib.Analysis.Convex.Jensen
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.SpecialFunctions.Pow.NNReal
import Mathlib.Data.Real.ConjExponents
/-!
# Mean value inequalities
In this file we prove several inequalities for finite sums, including AM-GM inequality,
HM-GM inequality, Young's inequality, Hölder inequality, and Minkowski inequality. Versions for
integrals of some of these inequalities are available in
`Mathlib.MeasureTheory.Integral.MeanInequalities`.
## Main theorems
### AM-GM inequality:
The inequality says that the geometric mean of a tuple of non-negative numbers is less than or equal
to their arithmetic mean. We prove the weighted version of this inequality: if $w$ and $z$
are two non-negative vectors and $\sum_{i\in s} w_i=1$, then
$$
\prod_{i\in s} z_i^{w_i} ≤ \sum_{i\in s} w_iz_i.
$$
The classical version is a special case of this inequality for $w_i=\frac{1}{n}$.
We prove a few versions of this inequality. Each of the following lemmas comes in two versions:
a version for real-valued non-negative functions is in the `Real` namespace, and a version for
`NNReal`-valued functions is in the `NNReal` namespace.
- `geom_mean_le_arith_mean_weighted` : weighted version for functions on `Finset`s;
- `geom_mean_le_arith_mean2_weighted` : weighted version for two numbers;
- `geom_mean_le_arith_mean3_weighted` : weighted version for three numbers;
- `geom_mean_le_arith_mean4_weighted` : weighted version for four numbers.
### HM-GM inequality:
The inequality says that the harmonic mean of a tuple of positive numbers is less than or equal
to their geometric mean. We prove the weighted version of this inequality: if $w$ and $z$
are two positive vectors and $\sum_{i\in s} w_i=1$, then
$$
1/(\sum_{i\in s} w_i/z_i) ≤ \prod_{i\in s} z_i^{w_i}
$$
The classical version is proven as a special case of this inequality for $w_i=\frac{1}{n}$.
The inequalities are proven only for real valued positive functions on `Finset`s, and namespaced in
`Real`. The weighted version follows as a corollary of the weighted AM-GM inequality.
### Young's inequality
Young's inequality says that for non-negative numbers `a`, `b`, `p`, `q` such that
$\frac{1}{p}+\frac{1}{q}=1$ we have
$$
ab ≤ \frac{a^p}{p} + \frac{b^q}{q}.
$$
This inequality is a special case of the AM-GM inequality. It is then used to prove Hölder's
inequality (see below).
### Hölder's inequality
The inequality says that for two conjugate exponents `p` and `q` (i.e., for two positive numbers
such that $\frac{1}{p}+\frac{1}{q}=1$) and any two non-negative vectors their inner product is
less than or equal to the product of the $L_p$ norm of the first vector and the $L_q$ norm of the
second vector:
$$
\sum_{i\in s} a_ib_i ≤ \sqrt[p]{\sum_{i\in s} a_i^p}\sqrt[q]{\sum_{i\in s} b_i^q}.
$$
We give versions of this result in `ℝ`, `ℝ≥0` and `ℝ≥0∞`.
There are at least two short proofs of this inequality. In our proof we prenormalize both vectors,
then apply Young's inequality to each $a_ib_i$. Another possible proof would be to deduce this
inequality from the generalized mean inequality for well-chosen vectors and weights.
### Minkowski's inequality
The inequality says that for `p ≥ 1` the function
$$
\|a\|_p=\sqrt[p]{\sum_{i\in s} a_i^p}
$$
satisfies the triangle inequality $\|a+b\|_p\le \|a\|_p+\|b\|_p$.
We give versions of this result in `Real`, `ℝ≥0` and `ℝ≥0∞`.
We deduce this inequality from Hölder's inequality. Namely, Hölder inequality implies that $\|a\|_p$
is the maximum of the inner product $\sum_{i\in s}a_ib_i$ over `b` such that $\|b\|_q\le 1$. Now
Minkowski's inequality follows from the fact that the maximum value of the sum of two functions is
less than or equal to the sum of the maximum values of the summands.
## TODO
- each inequality `A ≤ B` should come with a theorem `A = B ↔ _`; one of the ways to prove them
is to define `StrictConvexOn` functions.
- generalized mean inequality with any `p ≤ q`, including negative numbers;
- prove that the power mean tends to the geometric mean as the exponent tends to zero.
-/
universe u v
open Finset NNReal ENNReal
open scoped BigOperators
noncomputable section
variable {ι : Type u} (s : Finset ι)
section GeomMeanLEArithMean
/-! ### AM-GM inequality -/
namespace Real
/-- **AM-GM inequality**: The geometric mean is less than or equal to the arithmetic mean, weighted
version for real-valued nonnegative functions. -/
theorem geom_mean_le_arith_mean_weighted (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i)
(hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) :
∏ i ∈ s, z i ^ w i ≤ ∑ i ∈ s, w i * z i := by
-- If some number `z i` equals zero and has non-zero weight, then LHS is 0 and RHS is nonnegative.
by_cases A : ∃ i ∈ s, z i = 0 ∧ w i ≠ 0
· rcases A with ⟨i, his, hzi, hwi⟩
rw [prod_eq_zero his]
· exact sum_nonneg fun j hj => mul_nonneg (hw j hj) (hz j hj)
· rw [hzi]
exact zero_rpow hwi
-- If all numbers `z i` with non-zero weight are positive, then we apply Jensen's inequality
-- for `exp` and numbers `log (z i)` with weights `w i`.
· simp only [not_exists, not_and, Ne, Classical.not_not] at A
have := convexOn_exp.map_sum_le hw hw' fun i _ => Set.mem_univ <| log (z i)
simp only [exp_sum, smul_eq_mul, mul_comm (w _) (log _)] at this
convert this using 1 <;> [apply prod_congr rfl;apply sum_congr rfl] <;> intro i hi
· rcases eq_or_lt_of_le (hz i hi) with hz | hz
· simp [A i hi hz.symm]
· exact rpow_def_of_pos hz _
· rcases eq_or_lt_of_le (hz i hi) with hz | hz
· simp [A i hi hz.symm]
· rw [exp_log hz]
/-- **AM-GM inequality**: The **geometric mean is less than or equal to the arithmetic mean. -/
theorem geom_mean_le_arith_mean {ι : Type*} (s : Finset ι) (w : ι → ℝ) (z : ι → ℝ)
(hw : ∀ i ∈ s, 0 ≤ w i) (hw' : 0 < ∑ i ∈ s, w i) (hz : ∀ i ∈ s, 0 ≤ z i) :
(∏ i ∈ s, z i ^ w i) ^ (∑ i ∈ s, w i)⁻¹ ≤ (∑ i ∈ s, w i * z i) / (∑ i ∈ s, w i) := by
convert geom_mean_le_arith_mean_weighted s (fun i => (w i) / ∑ i ∈ s, w i) z ?_ ?_ hz using 2
· rw [← finset_prod_rpow _ _ (fun i hi => rpow_nonneg (hz _ hi) _) _]
refine Finset.prod_congr rfl (fun _ ih => ?_)
rw [div_eq_mul_inv, rpow_mul (hz _ ih)]
· simp_rw [div_eq_mul_inv, mul_assoc, mul_comm, ← mul_assoc, ← Finset.sum_mul, mul_comm]
· exact fun _ hi => div_nonneg (hw _ hi) (le_of_lt hw')
· simp_rw [div_eq_mul_inv, ← Finset.sum_mul]
exact mul_inv_cancel₀ (by linarith)
theorem geom_mean_weighted_of_constant (w z : ι → ℝ) (x : ℝ) (hw : ∀ i ∈ s, 0 ≤ w i)
(hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) (hx : ∀ i ∈ s, w i ≠ 0 → z i = x) :
∏ i ∈ s, z i ^ w i = x :=
calc
∏ i ∈ s, z i ^ w i = ∏ i ∈ s, x ^ w i := by
refine prod_congr rfl fun i hi => ?_
rcases eq_or_ne (w i) 0 with h₀ | h₀
· rw [h₀, rpow_zero, rpow_zero]
· rw [hx i hi h₀]
_ = x := by
rw [← rpow_sum_of_nonneg _ hw, hw', rpow_one]
have : (∑ i ∈ s, w i) ≠ 0 := by
rw [hw']
exact one_ne_zero
obtain ⟨i, his, hi⟩ := exists_ne_zero_of_sum_ne_zero this
rw [← hx i his hi]
exact hz i his
theorem arith_mean_weighted_of_constant (w z : ι → ℝ) (x : ℝ) (hw' : ∑ i ∈ s, w i = 1)
(hx : ∀ i ∈ s, w i ≠ 0 → z i = x) : ∑ i ∈ s, w i * z i = x :=
calc
∑ i ∈ s, w i * z i = ∑ i ∈ s, w i * x := by
refine sum_congr rfl fun i hi => ?_
rcases eq_or_ne (w i) 0 with hwi | hwi
· rw [hwi, zero_mul, zero_mul]
· rw [hx i hi hwi]
_ = x := by rw [← sum_mul, hw', one_mul]
theorem geom_mean_eq_arith_mean_weighted_of_constant (w z : ι → ℝ) (x : ℝ) (hw : ∀ i ∈ s, 0 ≤ w i)
(hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) (hx : ∀ i ∈ s, w i ≠ 0 → z i = x) :
∏ i ∈ s, z i ^ w i = ∑ i ∈ s, w i * z i := by
rw [geom_mean_weighted_of_constant, arith_mean_weighted_of_constant] <;> assumption
/-- **AM-GM inequality - equality condition**: This theorem provides the equality condition for the
*positive* weighted version of the AM-GM inequality for real-valued nonnegative functions. -/
theorem geom_mean_eq_arith_mean_weighted_iff' (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 < w i)
(hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) :
∏ i ∈ s, z i ^ w i = ∑ i ∈ s, w i * z i ↔ ∀ j ∈ s, z j = ∑ i ∈ s, w i * z i := by
by_cases A : ∃ i ∈ s, z i = 0 ∧ w i ≠ 0
· rcases A with ⟨i, his, hzi, hwi⟩
rw [prod_eq_zero his]
· constructor
· intro h
rw [← h]
intro j hj
apply eq_zero_of_ne_zero_of_mul_left_eq_zero (ne_of_lt (hw j hj)).symm
apply (sum_eq_zero_iff_of_nonneg ?_).mp h.symm j hj
exact fun i hi => (mul_nonneg_iff_of_pos_left (hw i hi)).mpr (hz i hi)
· intro h
convert h i his
exact hzi.symm
· rw [hzi]
exact zero_rpow hwi
· simp only [not_exists, not_and] at A
have hz' := fun i h => lt_of_le_of_ne (hz i h) (fun a => (A i h a.symm) (ne_of_gt (hw i h)))
have := strictConvexOn_exp.map_sum_eq_iff hw hw' fun i _ => Set.mem_univ <| log (z i)
simp only [exp_sum, smul_eq_mul, mul_comm (w _) (log _)] at this
convert this using 1
· apply Eq.congr <;>
[apply prod_congr rfl; apply sum_congr rfl] <;>
intro i hi <;>
simp only [exp_mul, exp_log (hz' i hi)]
· constructor <;> intro h j hj
· rw [← arith_mean_weighted_of_constant s w _ (log (z j)) hw' fun i _ => congrFun rfl]
apply sum_congr rfl
intro x hx
simp only [mul_comm, h j hj, h x hx]
· rw [← arith_mean_weighted_of_constant s w _ (z j) hw' fun i _ => congrFun rfl]
apply sum_congr rfl
intro x hx
simp only [log_injOn_pos (hz' j hj) (hz' x hx), h j hj, h x hx]
/-- **AM-GM inequality - equality condition**: This theorem provides the equality condition for the
weighted version of the AM-GM inequality for real-valued nonnegative functions. -/
theorem geom_mean_eq_arith_mean_weighted_iff (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i)
(hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) :
∏ i ∈ s, z i ^ w i = ∑ i ∈ s, w i * z i ↔ ∀ j ∈ s, w j ≠ 0 → z j = ∑ i ∈ s, w i * z i := by
have h (i) (_ : i ∈ s) : w i * z i ≠ 0 → w i ≠ 0 := by apply left_ne_zero_of_mul
have h' (i) (_ : i ∈ s) : z i ^ w i ≠ 1 → w i ≠ 0 := by
by_contra!
obtain ⟨h1, h2⟩ := this
simp only [h2, rpow_zero, ne_self_iff_false] at h1
rw [← sum_filter_of_ne h, ← prod_filter_of_ne h', geom_mean_eq_arith_mean_weighted_iff']
· simp
· simp +contextual [(hw _ _).gt_iff_ne]
· rwa [sum_filter_ne_zero]
· simp_all only [ne_eq, mul_eq_zero, not_or, not_false_eq_true, and_imp, implies_true, mem_filter]
/-- **AM-GM inequality - strict inequality condition**: This theorem provides the strict inequality
condition for the *positive* weighted version of the AM-GM inequality for real-valued nonnegative
functions. -/
theorem geom_mean_lt_arith_mean_weighted_iff_of_pos (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 < w i)
(hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) :
∏ i ∈ s, z i ^ w i < ∑ i ∈ s, w i * z i ↔ ∃ j ∈ s, ∃ k ∈ s, z j ≠ z k:= by
constructor
· intro h
by_contra! h_contra
rw [(geom_mean_eq_arith_mean_weighted_iff' s w z hw hw' hz).mpr ?_] at h
· exact (lt_self_iff_false _).mp h
· intro j hjs
rw [← arith_mean_weighted_of_constant s w (fun _ => z j) (z j) hw' fun _ _ => congrFun rfl]
apply sum_congr rfl (fun x a => congrArg (HMul.hMul (w x)) (h_contra j hjs x a))
· rintro ⟨j, hjs, k, hks, hzjk⟩
have := geom_mean_le_arith_mean_weighted s w z (fun i a => le_of_lt (hw i a)) hw' hz
by_contra! h
apply le_antisymm this at h
apply (geom_mean_eq_arith_mean_weighted_iff' s w z hw hw' hz).mp at h
simp only [h j hjs, h k hks, ne_eq, not_true_eq_false] at hzjk
end Real
namespace NNReal
/-- **AM-GM inequality**: The geometric mean is less than or equal to the arithmetic mean, weighted
version for `NNReal`-valued functions. -/
theorem geom_mean_le_arith_mean_weighted (w z : ι → ℝ≥0) (hw' : ∑ i ∈ s, w i = 1) :
(∏ i ∈ s, z i ^ (w i : ℝ)) ≤ ∑ i ∈ s, w i * z i :=
mod_cast
Real.geom_mean_le_arith_mean_weighted _ _ _ (fun i _ => (w i).coe_nonneg)
(by assumption_mod_cast) fun i _ => (z i).coe_nonneg
/-- **AM-GM inequality**: The geometric mean is less than or equal to the arithmetic mean, weighted
version for two `NNReal` numbers. -/
theorem geom_mean_le_arith_mean2_weighted (w₁ w₂ p₁ p₂ : ℝ≥0) :
w₁ + w₂ = 1 → p₁ ^ (w₁ : ℝ) * p₂ ^ (w₂ : ℝ) ≤ w₁ * p₁ + w₂ * p₂ := by
simpa only [Fin.prod_univ_succ, Fin.sum_univ_succ, Finset.prod_empty, Finset.sum_empty,
Finset.univ_eq_empty, Fin.cons_succ, Fin.cons_zero, add_zero, mul_one] using
geom_mean_le_arith_mean_weighted univ ![w₁, w₂] ![p₁, p₂]
theorem geom_mean_le_arith_mean3_weighted (w₁ w₂ w₃ p₁ p₂ p₃ : ℝ≥0) :
w₁ + w₂ + w₃ = 1 →
p₁ ^ (w₁ : ℝ) * p₂ ^ (w₂ : ℝ) * p₃ ^ (w₃ : ℝ) ≤ w₁ * p₁ + w₂ * p₂ + w₃ * p₃ := by
simpa only [Fin.prod_univ_succ, Fin.sum_univ_succ, Finset.prod_empty, Finset.sum_empty,
Finset.univ_eq_empty, Fin.cons_succ, Fin.cons_zero, add_zero, mul_one, ← add_assoc,
mul_assoc] using geom_mean_le_arith_mean_weighted univ ![w₁, w₂, w₃] ![p₁, p₂, p₃]
theorem geom_mean_le_arith_mean4_weighted (w₁ w₂ w₃ w₄ p₁ p₂ p₃ p₄ : ℝ≥0) :
w₁ + w₂ + w₃ + w₄ = 1 →
p₁ ^ (w₁ : ℝ) * p₂ ^ (w₂ : ℝ) * p₃ ^ (w₃ : ℝ) * p₄ ^ (w₄ : ℝ) ≤
w₁ * p₁ + w₂ * p₂ + w₃ * p₃ + w₄ * p₄ := by
simpa only [Fin.prod_univ_succ, Fin.sum_univ_succ, Finset.prod_empty, Finset.sum_empty,
Finset.univ_eq_empty, Fin.cons_succ, Fin.cons_zero, add_zero, mul_one, ← add_assoc,
mul_assoc] using geom_mean_le_arith_mean_weighted univ ![w₁, w₂, w₃, w₄] ![p₁, p₂, p₃, p₄]
end NNReal
namespace Real
theorem geom_mean_le_arith_mean2_weighted {w₁ w₂ p₁ p₂ : ℝ} (hw₁ : 0 ≤ w₁) (hw₂ : 0 ≤ w₂)
(hp₁ : 0 ≤ p₁) (hp₂ : 0 ≤ p₂) (hw : w₁ + w₂ = 1) : p₁ ^ w₁ * p₂ ^ w₂ ≤ w₁ * p₁ + w₂ * p₂ :=
NNReal.geom_mean_le_arith_mean2_weighted ⟨w₁, hw₁⟩ ⟨w₂, hw₂⟩ ⟨p₁, hp₁⟩ ⟨p₂, hp₂⟩ <|
NNReal.coe_inj.1 <| by assumption
theorem geom_mean_le_arith_mean3_weighted {w₁ w₂ w₃ p₁ p₂ p₃ : ℝ} (hw₁ : 0 ≤ w₁) (hw₂ : 0 ≤ w₂)
(hw₃ : 0 ≤ w₃) (hp₁ : 0 ≤ p₁) (hp₂ : 0 ≤ p₂) (hp₃ : 0 ≤ p₃) (hw : w₁ + w₂ + w₃ = 1) :
p₁ ^ w₁ * p₂ ^ w₂ * p₃ ^ w₃ ≤ w₁ * p₁ + w₂ * p₂ + w₃ * p₃ :=
NNReal.geom_mean_le_arith_mean3_weighted ⟨w₁, hw₁⟩ ⟨w₂, hw₂⟩ ⟨w₃, hw₃⟩ ⟨p₁, hp₁⟩ ⟨p₂, hp₂⟩
⟨p₃, hp₃⟩ <|
NNReal.coe_inj.1 hw
theorem geom_mean_le_arith_mean4_weighted {w₁ w₂ w₃ w₄ p₁ p₂ p₃ p₄ : ℝ} (hw₁ : 0 ≤ w₁)
(hw₂ : 0 ≤ w₂) (hw₃ : 0 ≤ w₃) (hw₄ : 0 ≤ w₄) (hp₁ : 0 ≤ p₁) (hp₂ : 0 ≤ p₂) (hp₃ : 0 ≤ p₃)
(hp₄ : 0 ≤ p₄) (hw : w₁ + w₂ + w₃ + w₄ = 1) :
p₁ ^ w₁ * p₂ ^ w₂ * p₃ ^ w₃ * p₄ ^ w₄ ≤ w₁ * p₁ + w₂ * p₂ + w₃ * p₃ + w₄ * p₄ :=
NNReal.geom_mean_le_arith_mean4_weighted ⟨w₁, hw₁⟩ ⟨w₂, hw₂⟩ ⟨w₃, hw₃⟩ ⟨w₄, hw₄⟩ ⟨p₁, hp₁⟩
⟨p₂, hp₂⟩ ⟨p₃, hp₃⟩ ⟨p₄, hp₄⟩ <|
NNReal.coe_inj.1 <| by assumption
/-- As an example application of AM-GM we prove that the **Motzkin polynomial** is nonnegative.
This bivariate polynomial cannot be written as a sum of squares. -/
lemma motzkin_polynomial_nonneg (x y : ℝ) :
0 ≤ x ^ 4 * y ^ 2 + x ^ 2 * y ^ 4 - 3 * x ^ 2 * y ^ 2 + 1 := by
have nn₁ : 0 ≤ x ^ 4 * y ^ 2 := by positivity
have nn₂ : 0 ≤ x ^ 2 * y ^ 4 := by positivity
have key := geom_mean_le_arith_mean3_weighted (by norm_num) (by norm_num) (by norm_num)
nn₁ nn₂ zero_le_one (add_thirds 1)
rw [one_rpow, mul_one, ← mul_rpow nn₁ nn₂, ← mul_add, ← mul_add,
show x ^ 4 * y ^ 2 * (x ^ 2 * y ^ 4) = (x ^ 2) ^ 3 * (y ^ 2) ^ 3 by ring,
mul_rpow (by positivity) (by positivity),
← rpow_natCast _ 3, ← rpow_mul (sq_nonneg x), ← rpow_natCast _ 3, ← rpow_mul (sq_nonneg y),
show ((3 : ℕ) * ((1 : ℝ) / 3)) = 1 by norm_num, rpow_one, rpow_one] at key
linarith
end Real
end GeomMeanLEArithMean
section HarmMeanLEGeomMean
/-! ### HM-GM inequality -/
namespace Real
/-- **HM-GM inequality**: The harmonic mean is less than or equal to the geometric mean, weighted
version for real-valued nonnegative functions. -/
theorem harm_mean_le_geom_mean_weighted (w z : ι → ℝ) (hs : s.Nonempty) (hw : ∀ i ∈ s, 0 < w i)
(hw' : ∑ i ∈ s, w i = 1) (hz : ∀ i ∈ s, 0 < z i) :
(∑ i ∈ s, w i / z i)⁻¹ ≤ ∏ i ∈ s, z i ^ w i := by
have : ∏ i ∈ s, (1 / z) i ^ w i ≤ ∑ i ∈ s, w i * (1 / z) i :=
geom_mean_le_arith_mean_weighted s w (1/z) (fun i hi ↦ le_of_lt (hw i hi)) hw'
(fun i hi ↦ one_div_nonneg.2 (le_of_lt (hz i hi)))
have p_pos : 0 < ∏ i ∈ s, (z i)⁻¹ ^ w i :=
prod_pos fun i hi => rpow_pos_of_pos (inv_pos.2 (hz i hi)) _
have s_pos : 0 < ∑ i ∈ s, w i * (z i)⁻¹ :=
sum_pos (fun i hi => mul_pos (hw i hi) (inv_pos.2 (hz i hi))) hs
norm_num at this
rw [← inv_le_inv₀ s_pos p_pos] at this
apply le_trans this
have p_pos₂ : 0 < (∏ i ∈ s, (z i) ^ w i)⁻¹ :=
inv_pos.2 (prod_pos fun i hi => rpow_pos_of_pos ((hz i hi)) _ )
rw [← inv_inv (∏ i ∈ s, z i ^ w i), inv_le_inv₀ p_pos p_pos₂, ← Finset.prod_inv_distrib]
gcongr
· exact fun i hi ↦ inv_nonneg.mpr (Real.rpow_nonneg (le_of_lt (hz i hi)) _)
· rw [Real.inv_rpow]; apply fun i hi ↦ le_of_lt (hz i hi); assumption
/-- **HM-GM inequality**: The **harmonic mean is less than or equal to the geometric mean. -/
theorem harm_mean_le_geom_mean {ι : Type*} (s : Finset ι) (hs : s.Nonempty) (w : ι → ℝ)
(z : ι → ℝ) (hw : ∀ i ∈ s, 0 < w i) (hw' : 0 < ∑ i ∈ s, w i) (hz : ∀ i ∈ s, 0 < z i) :
(∑ i ∈ s, w i) / (∑ i ∈ s, w i / z i) ≤ (∏ i ∈ s, z i ^ w i) ^ (∑ i ∈ s, w i)⁻¹ := by
have := harm_mean_le_geom_mean_weighted s (fun i => (w i) / ∑ i ∈ s, w i) z hs ?_ ?_ hz
· simp only at this
set n := ∑ i ∈ s, w i
nth_rw 1 [div_eq_mul_inv, (show n = (n⁻¹)⁻¹ by norm_num), ← mul_inv, Finset.mul_sum _ _ n⁻¹]
simp_rw [inv_mul_eq_div n ((w _)/(z _)), div_right_comm _ _ n]
convert this
rw [← Real.finset_prod_rpow s _ (fun i hi ↦ Real.rpow_nonneg (le_of_lt <| hz i hi) _)]
refine Finset.prod_congr rfl (fun i hi => ?_)
rw [← Real.rpow_mul (le_of_lt <| hz i hi) (w _) n⁻¹, div_eq_mul_inv (w _) n]
· exact fun i hi ↦ div_pos (hw i hi) hw'
· simp_rw [div_eq_mul_inv (w _) (∑ i ∈ s, w i), ← Finset.sum_mul _ _ (∑ i ∈ s, w i)⁻¹]
exact mul_inv_cancel₀ hw'.ne'
end Real
end HarmMeanLEGeomMean
section Young
/-! ### Young's inequality -/
namespace Real
/-- **Young's inequality**, a version for nonnegative real numbers. -/
theorem young_inequality_of_nonneg {a b p q : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b)
(hpq : p.HolderConjugate q) : a * b ≤ a ^ p / p + b ^ q / q := by
simpa [← rpow_mul, ha, hb, hpq.ne_zero, hpq.symm.ne_zero, _root_.div_eq_inv_mul] using
geom_mean_le_arith_mean2_weighted hpq.inv_nonneg hpq.symm.inv_nonneg
(rpow_nonneg ha p) (rpow_nonneg hb q) hpq.inv_add_inv_eq_one
/-- **Young's inequality**, a version for arbitrary real numbers. -/
theorem young_inequality (a b : ℝ) {p q : ℝ} (hpq : p.HolderConjugate q) :
a * b ≤ |a| ^ p / p + |b| ^ q / q :=
calc
a * b ≤ |a * b| := le_abs_self (a * b)
_ = |a| * |b| := abs_mul a b
_ ≤ |a| ^ p / p + |b| ^ q / q :=
Real.young_inequality_of_nonneg (abs_nonneg a) (abs_nonneg b) hpq
end Real
namespace NNReal
/-- **Young's inequality**, `ℝ≥0` version. We use `{p q : ℝ≥0}` in order to avoid constructing
witnesses of `0 ≤ p` and `0 ≤ q` for the denominators. -/
theorem young_inequality (a b : ℝ≥0) {p q : ℝ≥0} (hpq : p.HolderConjugate q) :
a * b ≤ a ^ (p : ℝ) / p + b ^ (q : ℝ) / q :=
Real.young_inequality_of_nonneg a.coe_nonneg b.coe_nonneg hpq.coe
/-- **Young's inequality**, `ℝ≥0` version with real conjugate exponents. -/
theorem young_inequality_real (a b : ℝ≥0) {p q : ℝ} (hpq : p.HolderConjugate q) :
a * b ≤ a ^ p / Real.toNNReal p + b ^ q / Real.toNNReal q := by
simpa [Real.coe_toNNReal, hpq.nonneg, hpq.symm.nonneg] using young_inequality a b hpq.toNNReal
end NNReal
namespace ENNReal
/-- **Young's inequality**, `ℝ≥0∞` version with real conjugate exponents. -/
theorem young_inequality (a b : ℝ≥0∞) {p q : ℝ} (hpq : p.HolderConjugate q) :
a * b ≤ a ^ p / ENNReal.ofReal p + b ^ q / ENNReal.ofReal q := by
by_cases h : a = ⊤ ∨ b = ⊤
· refine le_trans le_top (le_of_eq ?_)
repeat rw [div_eq_mul_inv]
rcases h with h | h <;> rw [h] <;> simp [h, hpq.pos, hpq.symm.pos]
push_neg at h
-- if a ≠ ⊤ and b ≠ ⊤, use the nnreal version: nnreal.young_inequality_real
rw [← coe_toNNReal h.left, ← coe_toNNReal h.right, ← coe_mul, ← coe_rpow_of_nonneg _ hpq.nonneg,
← coe_rpow_of_nonneg _ hpq.symm.nonneg, ENNReal.ofReal, ENNReal.ofReal, ←
@coe_div (Real.toNNReal p) _ (by simp [hpq.pos]), ←
@coe_div (Real.toNNReal q) _ (by simp [hpq.symm.pos]), ← coe_add, coe_le_coe]
exact NNReal.young_inequality_real a.toNNReal b.toNNReal hpq
end ENNReal
end Young
section HoelderMinkowski
/-! ### Hölder's and Minkowski's inequalities -/
namespace NNReal
private theorem inner_le_Lp_mul_Lp_of_norm_le_one (f g : ι → ℝ≥0) {p q : ℝ}
(hpq : p.HolderConjugate q) (hf : ∑ i ∈ s, f i ^ p ≤ 1) (hg : ∑ i ∈ s, g i ^ q ≤ 1) :
∑ i ∈ s, f i * g i ≤ 1 := by
have hp : 0 < p.toNNReal := zero_lt_one.trans hpq.toNNReal.lt
have hq : 0 < q.toNNReal := zero_lt_one.trans hpq.toNNReal.symm.lt
calc
∑ i ∈ s, f i * g i ≤ ∑ i ∈ s, (f i ^ p / Real.toNNReal p + g i ^ q / Real.toNNReal q) :=
Finset.sum_le_sum fun i _ => young_inequality_real (f i) (g i) hpq
_ = (∑ i ∈ s, f i ^ p) / Real.toNNReal p + (∑ i ∈ s, g i ^ q) / Real.toNNReal q := by
rw [sum_add_distrib, sum_div, sum_div]
_ ≤ 1 / Real.toNNReal p + 1 / Real.toNNReal q := by
refine add_le_add ?_ ?_ <;> rwa [div_le_iff₀, div_mul_cancel₀] <;> positivity
_ = 1 := by simp_rw [one_div, hpq.toNNReal.inv_add_inv_eq_one]
private theorem inner_le_Lp_mul_Lp_of_norm_eq_zero (f g : ι → ℝ≥0) {p q : ℝ}
(hpq : p.HolderConjugate q) (hf : ∑ i ∈ s, f i ^ p = 0) :
∑ i ∈ s, f i * g i ≤ (∑ i ∈ s, f i ^ p) ^ (1 / p) * (∑ i ∈ s, g i ^ q) ^ (1 / q) := by
simp only [hf, hpq.ne_zero, one_div, sum_eq_zero_iff, zero_rpow, zero_mul,
inv_eq_zero, Ne, not_false_iff, le_zero_iff, mul_eq_zero]
intro i his
left
rw [sum_eq_zero_iff] at hf
exact (rpow_eq_zero_iff.mp (hf i his)).left
/-- **Hölder inequality**: The scalar product of two functions is bounded by the product of their
`L^p` and `L^q` norms when `p` and `q` are conjugate exponents. Version for sums over finite sets,
with `ℝ≥0`-valued functions. -/
theorem inner_le_Lp_mul_Lq (f g : ι → ℝ≥0) {p q : ℝ} (hpq : p.HolderConjugate q) :
∑ i ∈ s, f i * g i ≤ (∑ i ∈ s, f i ^ p) ^ (1 / p) * (∑ i ∈ s, g i ^ q) ^ (1 / q) := by
obtain hf | hf := eq_zero_or_pos (∑ i ∈ s, f i ^ p)
· exact inner_le_Lp_mul_Lp_of_norm_eq_zero s f g hpq hf
obtain hg | hg := eq_zero_or_pos (∑ i ∈ s, g i ^ q)
· calc
∑ i ∈ s, f i * g i = ∑ i ∈ s, g i * f i := by
congr with i
rw [mul_comm]
_ ≤ (∑ i ∈ s, g i ^ q) ^ (1 / q) * (∑ i ∈ s, f i ^ p) ^ (1 / p) :=
(inner_le_Lp_mul_Lp_of_norm_eq_zero s g f hpq.symm hg)
_ = (∑ i ∈ s, f i ^ p) ^ (1 / p) * (∑ i ∈ s, g i ^ q) ^ (1 / q) := mul_comm _ _
let f' i := f i / (∑ i ∈ s, f i ^ p) ^ (1 / p)
let g' i := g i / (∑ i ∈ s, g i ^ q) ^ (1 / q)
suffices (∑ i ∈ s, f' i * g' i) ≤ 1 by
simp_rw [f', g', div_mul_div_comm, ← sum_div] at this
rwa [div_le_iff₀, one_mul] at this
-- TODO: We are missing a positivity extension here
exact mul_pos (rpow_pos hf) (rpow_pos hg)
refine inner_le_Lp_mul_Lp_of_norm_le_one s f' g' hpq (le_of_eq ?_) (le_of_eq ?_)
· simp_rw [f', div_rpow, ← sum_div, ← rpow_mul, one_div, inv_mul_cancel₀ hpq.ne_zero, rpow_one,
div_self hf.ne']
· simp_rw [g', div_rpow, ← sum_div, ← rpow_mul, one_div, inv_mul_cancel₀ hpq.symm.ne_zero,
rpow_one, div_self hg.ne']
/-- **Weighted Hölder inequality**. -/
lemma inner_le_weight_mul_Lp (s : Finset ι) {p : ℝ} (hp : 1 ≤ p) (w f : ι → ℝ≥0) :
∑ i ∈ s, w i * f i ≤ (∑ i ∈ s, w i) ^ (1 - p⁻¹) * (∑ i ∈ s, w i * f i ^ p) ^ p⁻¹ := by
obtain rfl | hp := hp.eq_or_lt
· simp
calc
_ = ∑ i ∈ s, w i ^ (1 - p⁻¹) * (w i ^ p⁻¹ * f i) := ?_
_ ≤ (∑ i ∈ s, (w i ^ (1 - p⁻¹)) ^ (1 - p⁻¹)⁻¹) ^ (1 / (1 - p⁻¹)⁻¹) *
(∑ i ∈ s, (w i ^ p⁻¹ * f i) ^ p) ^ (1 / p) :=
inner_le_Lp_mul_Lq _ _ _ (.symm <| Real.holderConjugate_iff.mpr ⟨hp, by simp⟩)
_ = _ := ?_
· congr with i
rw [← mul_assoc, ← rpow_of_add_eq _ one_ne_zero, rpow_one]
simp
· have hp₀ : p ≠ 0 := by positivity
have hp₁ : 1 - p⁻¹ ≠ 0 := by simp [sub_eq_zero, hp.ne']
simp [mul_rpow, div_inv_eq_mul, one_mul, one_div, hp₀, hp₁]
/-- **Hölder inequality**: the scalar product of two functions is bounded by the product of their
`L^p` and `L^q` norms when `p` and `q` are conjugate exponents. A version for `NNReal`-valued
functions. For an alternative version, convenient if the infinite sums are already expressed as
`p`-th powers, see `inner_le_Lp_mul_Lq_hasSum`. -/
| Mathlib/Analysis/MeanInequalities.lean | 542 | 561 | theorem inner_le_Lp_mul_Lq_tsum {f g : ι → ℝ≥0} {p q : ℝ} (hpq : p.HolderConjugate q)
(hf : Summable fun i => f i ^ p) (hg : Summable fun i => g i ^ q) :
(Summable fun i => f i * g i) ∧
∑' i, f i * g i ≤ (∑' i, f i ^ p) ^ (1 / p) * (∑' i, g i ^ q) ^ (1 / q) := by | have H₁ : ∀ s : Finset ι,
∑ i ∈ s, f i * g i ≤ (∑' i, f i ^ p) ^ (1 / p) * (∑' i, g i ^ q) ^ (1 / q) := by
intro s
refine le_trans (inner_le_Lp_mul_Lq s f g hpq) (mul_le_mul ?_ ?_ bot_le bot_le)
· rw [NNReal.rpow_le_rpow_iff (one_div_pos.mpr hpq.pos)]
exact hf.sum_le_tsum _ (fun _ _ => zero_le _)
· rw [NNReal.rpow_le_rpow_iff (one_div_pos.mpr hpq.symm.pos)]
exact hg.sum_le_tsum _ (fun _ _ => zero_le _)
have bdd : BddAbove (Set.range fun s => ∑ i ∈ s, f i * g i) := by
refine ⟨(∑' i, f i ^ p) ^ (1 / p) * (∑' i, g i ^ q) ^ (1 / q), ?_⟩
rintro a ⟨s, rfl⟩
exact H₁ s
have H₂ : Summable _ := (hasSum_of_isLUB _ (isLUB_ciSup bdd)).summable
exact ⟨H₂, H₂.tsum_le_of_sum_le H₁⟩
theorem summable_mul_of_Lp_Lq {f g : ι → ℝ≥0} {p q : ℝ} (hpq : p.HolderConjugate q) |
/-
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
-/
import Mathlib.MeasureTheory.MeasurableSpace.CountablyGenerated
import Mathlib.MeasureTheory.Measure.MutuallySingular
import Mathlib.MeasureTheory.Measure.Typeclasses.NoAtoms
import Mathlib.MeasureTheory.Measure.Typeclasses.Probability
import Mathlib.MeasureTheory.Measure.Typeclasses.SFinite
/-!
# Dirac measure
In this file we define the Dirac measure `MeasureTheory.Measure.dirac a`
and prove some basic facts about it.
-/
open Function Set
open scoped ENNReal
noncomputable section
variable {α β δ : Type*} [MeasurableSpace α] [MeasurableSpace β] {s : Set α} {a : α}
namespace MeasureTheory
namespace Measure
/-- The dirac measure. -/
def dirac (a : α) : Measure α := (OuterMeasure.dirac a).toMeasure (by simp)
instance : MeasureSpace PUnit :=
⟨dirac PUnit.unit⟩
theorem le_dirac_apply {a} : s.indicator 1 a ≤ dirac a s :=
OuterMeasure.dirac_apply a s ▸ le_toMeasure_apply _ _ _
@[simp]
theorem dirac_apply' (a : α) (hs : MeasurableSet s) : dirac a s = s.indicator 1 a :=
toMeasure_apply _ _ hs
@[simp]
theorem dirac_apply_of_mem {a : α} (h : a ∈ s) : dirac a s = 1 := by
have : ∀ t : Set α, a ∈ t → t.indicator (1 : α → ℝ≥0∞) a = 1 := fun t ht => indicator_of_mem ht 1
refine le_antisymm (this univ trivial ▸ ?_) (this s h ▸ le_dirac_apply)
rw [← dirac_apply' a MeasurableSet.univ]
exact measure_mono (subset_univ s)
@[simp]
theorem dirac_apply [MeasurableSingletonClass α] (a : α) (s : Set α) :
dirac a s = s.indicator 1 a := by
by_cases h : a ∈ s; · rw [dirac_apply_of_mem h, indicator_of_mem h, Pi.one_apply]
rw [indicator_of_not_mem h, ← nonpos_iff_eq_zero]
calc
dirac a s ≤ dirac a {a}ᶜ := measure_mono (subset_compl_comm.1 <| singleton_subset_iff.2 h)
_ = 0 := by simp [dirac_apply' _ (measurableSet_singleton _).compl]
@[simp] lemma dirac_ne_zero : dirac a ≠ 0 :=
fun h ↦ by simpa [h] using dirac_apply_of_mem (mem_univ a)
theorem map_dirac {f : α → β} (hf : Measurable f) (a : α) : (dirac a).map f = dirac (f a) := by
classical
exact ext fun s hs => by simp [hs, map_apply hf hs, hf hs, indicator_apply]
@[simp]
lemma map_const (μ : Measure α) (c : β) : μ.map (fun _ ↦ c) = (μ Set.univ) • dirac c := by
ext s hs
simp only [aemeasurable_const, measurable_const, Measure.coe_smul, Pi.smul_apply,
dirac_apply' _ hs, smul_eq_mul]
classical
rw [Measure.map_apply measurable_const hs, Set.preimage_const]
by_cases hsc : c ∈ s
· rw [(Set.indicator_eq_one_iff_mem _).mpr hsc, mul_one, if_pos hsc]
· rw [if_neg hsc, (Set.indicator_eq_zero_iff_not_mem _).mpr hsc, measure_empty, mul_zero]
@[simp]
theorem restrict_singleton (μ : Measure α) (a : α) : μ.restrict {a} = μ {a} • dirac a := by
ext1 s hs
by_cases ha : a ∈ s
· have : s ∩ {a} = {a} := by simpa
simp [*]
· have : s ∩ {a} = ∅ := inter_singleton_eq_empty.2 ha
simp [*]
/-- Two measures on a countable space are equal if they agree on singletons. -/
theorem ext_of_singleton [Countable α] {μ ν : Measure α} (h : ∀ a, μ {a} = ν {a}) : μ = ν :=
ext_of_sUnion_eq_univ (countable_range singleton) (by aesop) (by aesop)
/-- Two measures on a countable space are equal if and only if they agree on singletons. -/
theorem ext_iff_singleton [Countable α] {μ ν : Measure α} : μ = ν ↔ ∀ a, μ {a} = ν {a} :=
⟨fun h _ ↦ h ▸ rfl, ext_of_singleton⟩
theorem _root_.MeasureTheory.ext_iff_measureReal_singleton [Countable α]
{μ1 μ2 : Measure α} [SigmaFinite μ1] [SigmaFinite μ2] :
μ1 = μ2 ↔ ∀ x, μ1.real {x} = μ2.real {x} := by
rw [Measure.ext_iff_singleton]
congr! with x
rw [measureReal_def, measureReal_def, ENNReal.toReal_eq_toReal_iff]
simp [measure_singleton_lt_top, ne_of_lt]
/-- If `f` is a map with countable codomain, then `μ.map f` is a sum of Dirac measures. -/
| Mathlib/MeasureTheory/Measure/Dirac.lean | 103 | 110 | theorem map_eq_sum [Countable β] [MeasurableSingletonClass β] (μ : Measure α) (f : α → β)
(hf : Measurable f) : μ.map f = sum fun b : β => μ (f ⁻¹' {b}) • dirac b := by | ext s
have : ∀ y ∈ s, MeasurableSet (f ⁻¹' {y}) := fun y _ => hf (measurableSet_singleton _)
simp [← tsum_measure_preimage_singleton (to_countable s) this, *,
tsum_subtype s fun b => μ (f ⁻¹' {b}), ← indicator_mul_right s fun b => μ (f ⁻¹' {b})]
/-- A measure on a countable type is a sum of Dirac measures. -/ |
/-
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.Nat.PrimeFin
import Mathlib.Data.Nat.Factorization.Defs
import Mathlib.Data.Nat.GCD.BigOperators
import Mathlib.Order.Interval.Finset.Nat
import Mathlib.Tactic.IntervalCases
/-!
# Basic lemmas on prime factorizations
-/
open Finset List Finsupp
namespace Nat
variable {a b m n p : ℕ}
/-! ### Basic facts about factorization -/
/-! ## Lemmas characterising when `n.factorization p = 0` -/
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))
@[simp]
theorem factorization_one_right (n : ℕ) : n.factorization 1 = 0 :=
factorization_eq_zero_of_non_prime _ not_prime_one
theorem dvd_of_factorization_pos {n p : ℕ} (hn : n.factorization p ≠ 0) : p ∣ n :=
dvd_of_mem_primeFactorsList <| mem_primeFactors_iff_mem_primeFactorsList.1 <| mem_support_iff.2 hn
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.1 hr0).2
/-- 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_primeFactorsList_multiset n]
simp [factorization, AddEquiv.map_eq_zero_iff, Multiset.coe_eq_zero]
/-! ## Lemmas about factorizations of products and powers -/
/-- 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
/-- 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
/-! ## Lemmas about factorizations of primes and prime powers -/
/-- 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]
/-- 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
rw [← Nat.factorization_prod_pow_eq_self hn, h]
simp
/-- 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
/-! ### Equivalence between `ℕ+` and `ℕ →₀ ℕ` with support in the primes. -/
theorem eq_factorization_iff {n : ℕ} {f : ℕ →₀ ℕ} (hn : n ≠ 0) (hf : ∀ p ∈ f.support, Prime p) :
f = n.factorization ↔ f.prod (· ^ ·) = n :=
⟨fun h => by rw [h, factorization_prod_pow_eq_self hn], fun h => by
rw [← h, prod_pow_factorization_eq_self hf]⟩
theorem factorizationEquiv_inv_apply {f : ℕ →₀ ℕ} (hf : ∀ p ∈ f.support, Prime p) :
(factorizationEquiv.symm ⟨f, hf⟩).1 = f.prod (· ^ ·) :=
rfl
@[simp]
theorem ordProj_of_not_prime (n p : ℕ) (hp : ¬p.Prime) : ordProj[p] n = 1 := by
simp [factorization_eq_zero_of_non_prime n hp]
@[deprecated (since := "2024-10-24")] alias ord_proj_of_not_prime := ordProj_of_not_prime
@[simp]
theorem ordCompl_of_not_prime (n p : ℕ) (hp : ¬p.Prime) : ordCompl[p] n = n := by
simp [factorization_eq_zero_of_non_prime n hp]
@[deprecated (since := "2024-10-24")] alias ord_compl_of_not_prime := ordCompl_of_not_prime
theorem ordCompl_dvd (n p : ℕ) : ordCompl[p] n ∣ n :=
div_dvd_of_dvd (ordProj_dvd n p)
@[deprecated (since := "2024-10-24")] alias ord_compl_dvd := ordCompl_dvd
theorem ordProj_pos (n p : ℕ) : 0 < ordProj[p] n := by
if pp : p.Prime then simp [pow_pos pp.pos] else simp [pp]
@[deprecated (since := "2024-10-24")] alias ord_proj_pos := ordProj_pos
theorem ordProj_le {n : ℕ} (p : ℕ) (hn : n ≠ 0) : ordProj[p] n ≤ n :=
le_of_dvd hn.bot_lt (Nat.ordProj_dvd n p)
@[deprecated (since := "2024-10-24")] alias ord_proj_le := ordProj_le
theorem ordCompl_pos {n : ℕ} (p : ℕ) (hn : n ≠ 0) : 0 < ordCompl[p] n := by
if pp : p.Prime then
exact Nat.div_pos (ordProj_le p hn) (ordProj_pos n p)
else
simpa [Nat.factorization_eq_zero_of_non_prime n pp] using hn.bot_lt
@[deprecated (since := "2024-10-24")] alias ord_compl_pos := ordCompl_pos
theorem ordCompl_le (n p : ℕ) : ordCompl[p] n ≤ n :=
Nat.div_le_self _ _
@[deprecated (since := "2024-10-24")] alias ord_compl_le := ordCompl_le
theorem ordProj_mul_ordCompl_eq_self (n p : ℕ) : ordProj[p] n * ordCompl[p] n = n :=
Nat.mul_div_cancel' (ordProj_dvd n p)
@[deprecated (since := "2024-10-24")]
alias ord_proj_mul_ord_compl_eq_self := ordProj_mul_ordCompl_eq_self
theorem ordProj_mul {a b : ℕ} (p : ℕ) (ha : a ≠ 0) (hb : b ≠ 0) :
ordProj[p] (a * b) = ordProj[p] a * ordProj[p] b := by
simp [factorization_mul ha hb, pow_add]
@[deprecated (since := "2024-10-24")] alias ord_proj_mul := ordProj_mul
theorem ordCompl_mul (a b p : ℕ) : ordCompl[p] (a * b) = ordCompl[p] a * ordCompl[p] b := by
if ha : a = 0 then simp [ha] else
if hb : b = 0 then simp [hb] else
simp only [ordProj_mul p ha hb]
rw [div_mul_div_comm (ordProj_dvd a p) (ordProj_dvd b p)]
@[deprecated (since := "2024-10-24")] alias ord_compl_mul := ordCompl_mul
/-! ### Factorization and divisibility -/
/-- A crude upper bound on `n.factorization p` -/
theorem factorization_lt {n : ℕ} (p : ℕ) (hn : n ≠ 0) : n.factorization p < n := by
by_cases pp : p.Prime
· exact (Nat.pow_lt_pow_iff_right pp.one_lt).1 <| (ordProj_le p hn).trans_lt <|
Nat.lt_pow_self pp.one_lt
· simpa only [factorization_eq_zero_of_non_prime n pp] using hn.bot_lt
/-- An upper bound on `n.factorization p` -/
theorem factorization_le_of_le_pow {n p b : ℕ} (hb : n ≤ p ^ b) : n.factorization p ≤ b := by
if hn : n = 0 then simp [hn] else
if pp : p.Prime then
exact (Nat.pow_le_pow_iff_right pp.one_lt).1 ((ordProj_le p hn).trans hb)
else
simp [factorization_eq_zero_of_non_prime n pp]
theorem factorization_prime_le_iff_dvd {d n : ℕ} (hd : d ≠ 0) (hn : n ≠ 0) :
(∀ p : ℕ, p.Prime → d.factorization p ≤ n.factorization p) ↔ d ∣ n := by
rw [← factorization_le_iff_dvd hd hn]
refine ⟨fun h p => (em p.Prime).elim (h p) fun hp => ?_, fun h p _ => h p⟩
simp_rw [factorization_eq_zero_of_non_prime _ hp]
rfl
theorem factorization_le_factorization_mul_left {a b : ℕ} (hb : b ≠ 0) :
a.factorization ≤ (a * b).factorization := by
rcases eq_or_ne a 0 with (rfl | ha)
· simp
rw [factorization_le_iff_dvd ha <| mul_ne_zero ha hb]
exact Dvd.intro b rfl
theorem factorization_le_factorization_mul_right {a b : ℕ} (ha : a ≠ 0) :
b.factorization ≤ (a * b).factorization := by
rw [mul_comm]
apply factorization_le_factorization_mul_left ha
theorem Prime.pow_dvd_iff_le_factorization {p k n : ℕ} (pp : Prime p) (hn : n ≠ 0) :
p ^ k ∣ n ↔ k ≤ n.factorization p := by
rw [← factorization_le_iff_dvd (pow_pos pp.pos k).ne' hn, pp.factorization_pow, single_le_iff]
theorem Prime.pow_dvd_iff_dvd_ordProj {p k n : ℕ} (pp : Prime p) (hn : n ≠ 0) :
p ^ k ∣ n ↔ p ^ k ∣ ordProj[p] n := by
rw [pow_dvd_pow_iff_le_right pp.one_lt, pp.pow_dvd_iff_le_factorization hn]
@[deprecated (since := "2024-10-24")]
alias Prime.pow_dvd_iff_dvd_ord_proj := Prime.pow_dvd_iff_dvd_ordProj
theorem Prime.dvd_iff_one_le_factorization {p n : ℕ} (pp : Prime p) (hn : n ≠ 0) :
p ∣ n ↔ 1 ≤ n.factorization p :=
Iff.trans (by simp) (pp.pow_dvd_iff_le_factorization hn)
theorem exists_factorization_lt_of_lt {a b : ℕ} (ha : a ≠ 0) (hab : a < b) :
∃ p : ℕ, a.factorization p < b.factorization p := by
have hb : b ≠ 0 := (ha.bot_lt.trans hab).ne'
contrapose! hab
rw [← Finsupp.le_def, factorization_le_iff_dvd hb ha] at hab
exact le_of_dvd ha.bot_lt hab
@[simp]
theorem factorization_div {d n : ℕ} (h : d ∣ n) :
(n / d).factorization = n.factorization - d.factorization := by
rcases eq_or_ne d 0 with (rfl | hd); · simp [zero_dvd_iff.mp h]
rcases eq_or_ne n 0 with (rfl | hn); · simp [tsub_eq_zero_of_le]
apply add_left_injective d.factorization
simp only
rw [tsub_add_cancel_of_le <| (Nat.factorization_le_iff_dvd hd hn).mpr h, ←
Nat.factorization_mul (Nat.div_pos (Nat.le_of_dvd hn.bot_lt h) hd.bot_lt).ne' hd,
Nat.div_mul_cancel h]
theorem dvd_ordProj_of_dvd {n p : ℕ} (hn : n ≠ 0) (pp : p.Prime) (h : p ∣ n) : p ∣ ordProj[p] n :=
dvd_pow_self p (Prime.factorization_pos_of_dvd pp hn h).ne'
@[deprecated (since := "2024-10-24")] alias dvd_ord_proj_of_dvd := dvd_ordProj_of_dvd
theorem not_dvd_ordCompl {n p : ℕ} (hp : Prime p) (hn : n ≠ 0) : ¬p ∣ ordCompl[p] n := by
rw [Nat.Prime.dvd_iff_one_le_factorization hp (ordCompl_pos p hn).ne']
rw [Nat.factorization_div (Nat.ordProj_dvd n p)]
simp [hp.factorization]
@[deprecated (since := "2024-10-24")] alias not_dvd_ord_compl := not_dvd_ordCompl
theorem coprime_ordCompl {n p : ℕ} (hp : Prime p) (hn : n ≠ 0) : Coprime p (ordCompl[p] n) :=
(or_iff_left (not_dvd_ordCompl hp hn)).mp <| coprime_or_dvd_of_prime hp _
@[deprecated (since := "2024-10-24")] alias coprime_ord_compl := coprime_ordCompl
theorem factorization_ordCompl (n p : ℕ) :
(ordCompl[p] n).factorization = n.factorization.erase p := by
if hn : n = 0 then simp [hn] else
if pp : p.Prime then ?_ else
simp [pp]
ext q
rcases eq_or_ne q p with (rfl | hqp)
· simp only [Finsupp.erase_same, factorization_eq_zero_iff, not_dvd_ordCompl pp hn]
simp
· rw [Finsupp.erase_ne hqp, factorization_div (ordProj_dvd n p)]
simp [pp.factorization, hqp.symm]
@[deprecated (since := "2024-10-24")] alias factorization_ord_compl := factorization_ordCompl
-- `ordCompl[p] n` is the largest divisor of `n` not divisible by `p`.
theorem dvd_ordCompl_of_dvd_not_dvd {p d n : ℕ} (hdn : d ∣ n) (hpd : ¬p ∣ d) :
d ∣ ordCompl[p] n := by
if hn0 : n = 0 then simp [hn0] else
if hd0 : d = 0 then simp [hd0] at hpd else
rw [← factorization_le_iff_dvd hd0 (ordCompl_pos p hn0).ne', factorization_ordCompl]
intro q
if hqp : q = p then
simp [factorization_eq_zero_iff, hqp, hpd]
else
simp [hqp, (factorization_le_iff_dvd hd0 hn0).2 hdn q]
@[deprecated (since := "2024-10-24")]
alias dvd_ord_compl_of_dvd_not_dvd := dvd_ordCompl_of_dvd_not_dvd
/-- If `n` is a nonzero natural number and `p ≠ 1`, then there are natural numbers `e`
and `n'` such that `n'` is not divisible by `p` and `n = p^e * n'`. -/
theorem exists_eq_pow_mul_and_not_dvd {n : ℕ} (hn : n ≠ 0) (p : ℕ) (hp : p ≠ 1) :
∃ e n' : ℕ, ¬p ∣ n' ∧ n = p ^ e * n' :=
let ⟨a', h₁, h₂⟩ :=
(Nat.finiteMultiplicity_iff.mpr ⟨hp, Nat.pos_of_ne_zero hn⟩).exists_eq_pow_mul_and_not_dvd
⟨_, a', h₂, h₁⟩
/-- Any nonzero natural number is the product of an odd part `m` and a power of
two `2 ^ k`. -/
theorem exists_eq_two_pow_mul_odd {n : ℕ} (hn : n ≠ 0) :
∃ k m : ℕ, Odd m ∧ n = 2 ^ k * m :=
let ⟨k, m, hm, hn⟩ := exists_eq_pow_mul_and_not_dvd hn 2 (succ_ne_self 1)
⟨k, m, not_even_iff_odd.1 (mt Even.two_dvd hm), hn⟩
theorem dvd_iff_div_factorization_eq_tsub {d n : ℕ} (hd : d ≠ 0) (hdn : d ≤ n) :
d ∣ n ↔ (n / d).factorization = n.factorization - d.factorization := by
refine ⟨factorization_div, ?_⟩
rcases eq_or_lt_of_le hdn with (rfl | hd_lt_n); · simp
have h1 : n / d ≠ 0 := by simp [*]
intro h
rw [dvd_iff_le_div_mul n d]
by_contra h2
obtain ⟨p, hp⟩ := exists_factorization_lt_of_lt (mul_ne_zero h1 hd) (not_le.mp h2)
rwa [factorization_mul h1 hd, add_apply, ← lt_tsub_iff_right, h, tsub_apply,
lt_self_iff_false] at hp
theorem ordProj_dvd_ordProj_of_dvd {a b : ℕ} (hb0 : b ≠ 0) (hab : a ∣ b) (p : ℕ) :
ordProj[p] a ∣ ordProj[p] b := by
rcases em' p.Prime with (pp | pp); · simp [pp]
rcases eq_or_ne a 0 with (rfl | ha0); · simp
rw [pow_dvd_pow_iff_le_right pp.one_lt]
exact (factorization_le_iff_dvd ha0 hb0).2 hab p
@[deprecated (since := "2024-10-24")]
alias ord_proj_dvd_ord_proj_of_dvd := ordProj_dvd_ordProj_of_dvd
theorem ordProj_dvd_ordProj_iff_dvd {a b : ℕ} (ha0 : a ≠ 0) (hb0 : b ≠ 0) :
(∀ p : ℕ, ordProj[p] a ∣ ordProj[p] b) ↔ a ∣ b := by
refine ⟨fun h => ?_, fun hab p => ordProj_dvd_ordProj_of_dvd hb0 hab p⟩
rw [← factorization_le_iff_dvd ha0 hb0]
intro q
rcases le_or_lt q 1 with (hq_le | hq1)
· interval_cases q <;> simp
exact (pow_dvd_pow_iff_le_right hq1).1 (h q)
@[deprecated (since := "2024-10-24")]
alias ord_proj_dvd_ord_proj_iff_dvd := ordProj_dvd_ordProj_iff_dvd
theorem ordCompl_dvd_ordCompl_of_dvd {a b : ℕ} (hab : a ∣ b) (p : ℕ) :
ordCompl[p] a ∣ ordCompl[p] b := by
rcases em' p.Prime with (pp | pp)
· simp [pp, hab]
rcases eq_or_ne b 0 with (rfl | hb0)
· simp
rcases eq_or_ne a 0 with (rfl | ha0)
· cases hb0 (zero_dvd_iff.1 hab)
have ha := (Nat.div_pos (ordProj_le p ha0) (ordProj_pos a p)).ne'
have hb := (Nat.div_pos (ordProj_le p hb0) (ordProj_pos b p)).ne'
rw [← factorization_le_iff_dvd ha hb, factorization_ordCompl a p, factorization_ordCompl b p]
intro q
rcases eq_or_ne q p with (rfl | hqp)
· simp
simp_rw [erase_ne hqp]
exact (factorization_le_iff_dvd ha0 hb0).2 hab q
@[deprecated (since := "2024-10-24")]
alias ord_compl_dvd_ord_compl_of_dvd := ordCompl_dvd_ordCompl_of_dvd
theorem ordCompl_dvd_ordCompl_iff_dvd (a b : ℕ) :
(∀ p : ℕ, ordCompl[p] a ∣ ordCompl[p] b) ↔ a ∣ b := by
refine ⟨fun h => ?_, fun hab p => ordCompl_dvd_ordCompl_of_dvd hab p⟩
rcases eq_or_ne b 0 with (rfl | hb0)
· simp
if pa : a.Prime then ?_ else simpa [pa] using h a
if pb : b.Prime then ?_ else simpa [pb] using h b
rw [prime_dvd_prime_iff_eq pa pb]
by_contra hab
apply pa.ne_one
rw [← Nat.dvd_one, ← Nat.mul_dvd_mul_iff_left hb0.bot_lt, mul_one]
simpa [Prime.factorization_self pb, Prime.factorization pa, hab] using h b
@[deprecated (since := "2024-10-24")]
alias ord_compl_dvd_ord_compl_iff_dvd := ordCompl_dvd_ordCompl_iff_dvd
theorem dvd_iff_prime_pow_dvd_dvd (n d : ℕ) :
d ∣ n ↔ ∀ p k : ℕ, Prime p → p ^ k ∣ d → p ^ k ∣ n := by
rcases eq_or_ne n 0 with (rfl | hn)
· simp
rcases eq_or_ne d 0 with (rfl | hd)
· simp only [zero_dvd_iff, hn, false_iff, not_forall]
exact ⟨2, n, prime_two, dvd_zero _, mt (le_of_dvd hn.bot_lt) (n.lt_two_pow_self).not_le⟩
refine ⟨fun h p k _ hpkd => dvd_trans hpkd h, ?_⟩
rw [← factorization_prime_le_iff_dvd hd hn]
intro h p pp
simp_rw [← pp.pow_dvd_iff_le_factorization hn]
exact h p _ pp (ordProj_dvd _ _)
theorem prod_primeFactors_dvd (n : ℕ) : ∏ p ∈ n.primeFactors, p ∣ n := by
by_cases hn : n = 0
· subst hn
simp
· simpa [prod_primeFactorsList hn] using (n.primeFactorsList : Multiset ℕ).toFinset_prod_dvd_prod
theorem factorization_gcd {a b : ℕ} (ha_pos : a ≠ 0) (hb_pos : b ≠ 0) :
(gcd a b).factorization = a.factorization ⊓ b.factorization := by
let dfac := a.factorization ⊓ b.factorization
let d := dfac.prod (· ^ ·)
have dfac_prime : ∀ p : ℕ, p ∈ dfac.support → Prime p := by
intro p hp
have : p ∈ a.primeFactorsList ∧ p ∈ b.primeFactorsList := by simpa [dfac] using hp
exact prime_of_mem_primeFactorsList this.1
have h1 : d.factorization = dfac := prod_pow_factorization_eq_self dfac_prime
have hd_pos : d ≠ 0 := (factorizationEquiv.invFun ⟨dfac, dfac_prime⟩).2.ne'
suffices d = gcd a b by rwa [← this]
apply gcd_greatest
· rw [← factorization_le_iff_dvd hd_pos ha_pos, h1]
exact inf_le_left
· rw [← factorization_le_iff_dvd hd_pos hb_pos, h1]
exact inf_le_right
· intro e hea heb
rcases Decidable.eq_or_ne e 0 with (rfl | he_pos)
· simp only [zero_dvd_iff] at hea
contradiction
have hea' := (factorization_le_iff_dvd he_pos ha_pos).mpr hea
have heb' := (factorization_le_iff_dvd he_pos hb_pos).mpr heb
simp [dfac, ← factorization_le_iff_dvd he_pos hd_pos, h1, hea', heb']
theorem factorization_lcm {a b : ℕ} (ha : a ≠ 0) (hb : b ≠ 0) :
(a.lcm b).factorization = a.factorization ⊔ b.factorization := by
rw [← add_right_inj (a.gcd b).factorization, ←
factorization_mul (mt gcd_eq_zero_iff.1 fun h => ha h.1) (lcm_ne_zero ha hb), gcd_mul_lcm,
factorization_gcd ha hb, factorization_mul ha hb]
ext1
exact (min_add_max _ _).symm
variable (a b)
@[simp]
lemma factorizationLCMLeft_zero_left : factorizationLCMLeft 0 b = 1 := by
simp [factorizationLCMLeft]
@[simp]
lemma factorizationLCMLeft_zero_right : factorizationLCMLeft a 0 = 1 := by
simp [factorizationLCMLeft]
@[simp]
lemma factorizationLCRight_zero_left : factorizationLCMRight 0 b = 1 := by
simp [factorizationLCMRight]
@[simp]
lemma factorizationLCMRight_zero_right : factorizationLCMRight a 0 = 1 := by
simp [factorizationLCMRight]
lemma factorizationLCMLeft_pos :
0 < factorizationLCMLeft a b := by
apply Nat.pos_of_ne_zero
rw [factorizationLCMLeft, Finsupp.prod_ne_zero_iff]
intro p _ H
by_cases h : b.factorization p ≤ a.factorization p
· simp only [h, reduceIte, pow_eq_zero_iff', ne_eq] at H
simpa [H.1] using H.2
· simp only [h, reduceIte, one_ne_zero] at H
lemma factorizationLCMRight_pos :
0 < factorizationLCMRight a b := by
apply Nat.pos_of_ne_zero
rw [factorizationLCMRight, Finsupp.prod_ne_zero_iff]
intro p _ H
by_cases h : b.factorization p ≤ a.factorization p
· simp only [h, reduceIte, pow_eq_zero_iff', ne_eq, reduceCtorEq] at H
· simp only [h, ↓reduceIte, pow_eq_zero_iff', ne_eq] at H
simpa [H.1] using H.2
lemma coprime_factorizationLCMLeft_factorizationLCMRight :
(factorizationLCMLeft a b).Coprime (factorizationLCMRight a b) := by
rw [factorizationLCMLeft, factorizationLCMRight]
refine coprime_prod_left_iff.mpr fun p hp ↦ coprime_prod_right_iff.mpr fun q hq ↦ ?_
dsimp only; split_ifs with h h'
any_goals simp only [coprime_one_right_eq_true, coprime_one_left_eq_true]
refine coprime_pow_primes _ _ (prime_of_mem_primeFactors hp) (prime_of_mem_primeFactors hq) ?_
contrapose! h'; rwa [← h']
variable {a b}
lemma factorizationLCMLeft_mul_factorizationLCMRight (ha : a ≠ 0) (hb : b ≠ 0) :
(factorizationLCMLeft a b) * (factorizationLCMRight a b) = lcm a b := by
rw [← factorization_prod_pow_eq_self (lcm_ne_zero ha hb), factorizationLCMLeft,
factorizationLCMRight, ← prod_mul]
congr; ext p n; split_ifs <;> simp
variable (a b)
lemma factorizationLCMLeft_dvd_left : factorizationLCMLeft a b ∣ a := by
rcases eq_or_ne a 0 with rfl | ha
· simp only [dvd_zero]
rcases eq_or_ne b 0 with rfl | hb
· simp [factorizationLCMLeft]
nth_rewrite 2 [← factorization_prod_pow_eq_self ha]
rw [prod_of_support_subset (s := (lcm a b).factorization.support)]
· apply prod_dvd_prod_of_dvd; rintro p -; dsimp only; split_ifs with le
· rw [factorization_lcm ha hb]; apply pow_dvd_pow; exact sup_le le_rfl le
· apply one_dvd
· intro p hp; rw [mem_support_iff] at hp ⊢
rw [factorization_lcm ha hb]; exact (lt_sup_iff.mpr <| .inl <| Nat.pos_of_ne_zero hp).ne'
· intros; rw [pow_zero]
lemma factorizationLCMRight_dvd_right : factorizationLCMRight a b ∣ b := by
rcases eq_or_ne a 0 with rfl | ha
· simp [factorizationLCMRight]
rcases eq_or_ne b 0 with rfl | hb
· simp only [dvd_zero]
nth_rewrite 2 [← factorization_prod_pow_eq_self hb]
rw [prod_of_support_subset (s := (lcm a b).factorization.support)]
· apply Finset.prod_dvd_prod_of_dvd; rintro p -; dsimp only; split_ifs with le
· apply one_dvd
· rw [factorization_lcm ha hb]; apply pow_dvd_pow; exact sup_le (not_le.1 le).le le_rfl
· intro p hp; rw [mem_support_iff] at hp ⊢
rw [factorization_lcm ha hb]; exact (lt_sup_iff.mpr <| .inr <| Nat.pos_of_ne_zero hp).ne'
· intros; rw [pow_zero]
@[to_additive sum_primeFactors_gcd_add_sum_primeFactors_mul]
theorem prod_primeFactors_gcd_mul_prod_primeFactors_mul {β : Type*} [CommMonoid β] (m n : ℕ)
(f : ℕ → β) :
(m.gcd n).primeFactors.prod f * (m * n).primeFactors.prod f =
m.primeFactors.prod f * n.primeFactors.prod f := by
obtain rfl | hm₀ := eq_or_ne m 0
· simp
obtain rfl | hn₀ := eq_or_ne n 0
· simp
· rw [primeFactors_mul hm₀ hn₀, primeFactors_gcd hm₀ hn₀, mul_comm, Finset.prod_union_inter]
theorem setOf_pow_dvd_eq_Icc_factorization {n p : ℕ} (pp : p.Prime) (hn : n ≠ 0) :
{ i : ℕ | i ≠ 0 ∧ p ^ i ∣ n } = Set.Icc 1 (n.factorization p) := by
ext
simp [Nat.lt_succ_iff, one_le_iff_ne_zero, pp.pow_dvd_iff_le_factorization hn]
/-- The set of positive powers of prime `p` that divide `n` is exactly the set of
positive natural numbers up to `n.factorization p`. -/
theorem Icc_factorization_eq_pow_dvd (n : ℕ) {p : ℕ} (pp : Prime p) :
Icc 1 (n.factorization p) = {i ∈ Ico 1 n | p ^ i ∣ n} := by
rcases eq_or_ne n 0 with (rfl | hn)
· simp
ext x
simp only [mem_Icc, Finset.mem_filter, mem_Ico, and_assoc, and_congr_right_iff,
pp.pow_dvd_iff_le_factorization hn, iff_and_self]
exact fun _ H => lt_of_le_of_lt H (factorization_lt p hn)
theorem factorization_eq_card_pow_dvd (n : ℕ) {p : ℕ} (pp : p.Prime) :
n.factorization p = #{i ∈ Ico 1 n | p ^ i ∣ n} := by
simp [← Icc_factorization_eq_pow_dvd n pp]
theorem Ico_filter_pow_dvd_eq {n p b : ℕ} (pp : p.Prime) (hn : n ≠ 0) (hb : n ≤ p ^ b) :
{i ∈ Ico 1 n | p ^ i ∣ n} = {i ∈ Icc 1 b | p ^ i ∣ n} := by
ext x
simp only [Finset.mem_filter, mem_Ico, mem_Icc, and_congr_left_iff, and_congr_right_iff]
rintro h1 -
exact iff_of_true (lt_of_pow_dvd_right hn pp.two_le h1) <|
(Nat.pow_le_pow_iff_right pp.one_lt).1 <| (le_of_dvd hn.bot_lt h1).trans hb
/-! ### Factorization and coprimes -/
/-- If `p` is a prime factor of `a` then the power of `p` in `a` is the same that in `a * b`,
for any `b` coprime to `a`. -/
theorem factorization_eq_of_coprime_left {p a b : ℕ} (hab : Coprime a b)
(hpa : p ∈ a.primeFactorsList) : (a * b).factorization p = a.factorization p := by
rw [factorization_mul_apply_of_coprime hab, ← primeFactorsList_count_eq,
← primeFactorsList_count_eq,
count_eq_zero_of_not_mem (coprime_primeFactorsList_disjoint hab hpa), add_zero]
/-- If `p` is a prime factor of `b` then the power of `p` in `b` is the same that in `a * b`,
for any `a` coprime to `b`. -/
theorem factorization_eq_of_coprime_right {p a b : ℕ} (hab : Coprime a b)
(hpb : p ∈ b.primeFactorsList) : (a * b).factorization p = b.factorization p := by
rw [mul_comm]
exact factorization_eq_of_coprime_left (coprime_comm.mp hab) hpb
/-- Two positive naturals are equal if their prime padic valuations are equal -/
theorem eq_iff_prime_padicValNat_eq (a b : ℕ) (ha : a ≠ 0) (hb : b ≠ 0) :
a = b ↔ ∀ p : ℕ, p.Prime → padicValNat p a = padicValNat p b := by
constructor
· rintro rfl
simp
· intro h
refine eq_of_factorization_eq ha hb fun p => ?_
by_cases pp : p.Prime
· simp [factorization_def, pp, h p pp]
· simp [factorization_eq_zero_of_non_prime, pp]
theorem prod_pow_prime_padicValNat (n : Nat) (hn : n ≠ 0) (m : Nat) (pr : n < m) :
∏ p ∈ range m with p.Prime, p ^ padicValNat p n = n := by
nth_rw 2 [← factorization_prod_pow_eq_self hn]
rw [eq_comm]
apply Finset.prod_subset_one_on_sdiff
· exact fun p hp => Finset.mem_filter.mpr ⟨Finset.mem_range.2 <| pr.trans_le' <|
le_of_mem_primeFactors hp, prime_of_mem_primeFactors hp⟩
· intro p hp
obtain ⟨hp1, hp2⟩ := Finset.mem_sdiff.mp hp
rw [← factorization_def n (Finset.mem_filter.mp hp1).2]
simp [Finsupp.not_mem_support_iff.mp hp2]
· intro p hp
simp [factorization_def n (prime_of_mem_primeFactors hp)]
/-! ### Lemmas about factorizations of particular functions -/
-- TODO: Port lemmas from `Data/Nat/Multiplicity` to here, re-written in terms of `factorization`
/-- Exactly `n / p` naturals in `[1, n]` are multiples of `p`.
See `Nat.card_multiples'` for an alternative spelling of the statement. -/
| Mathlib/Data/Nat/Factorization/Basic.lean | 575 | 590 | theorem card_multiples (n p : ℕ) : #{e ∈ range n | p ∣ e + 1} = n / p := by | induction' n with n hn
· simp
simp [Nat.succ_div, add_ite, add_zero, Finset.range_succ, filter_insert, apply_ite card,
card_insert_of_not_mem, hn]
/-- Exactly `n / p` naturals in `(0, n]` are multiples of `p`. -/
theorem Ioc_filter_dvd_card_eq_div (n p : ℕ) : #{x ∈ Ioc 0 n | p ∣ x} = n / p := by
induction' n with n IH
· simp
-- TODO: Golf away `h1` after Yaël PRs a lemma asserting this
have h1 : Ioc 0 n.succ = insert n.succ (Ioc 0 n) := by
rcases n.eq_zero_or_pos with (rfl | hn)
· simp
simp_rw [← Ico_succ_succ, Ico_insert_right (succ_le_succ hn.le), Ico_succ_right]
simp [Nat.succ_div, add_ite, add_zero, h1, filter_insert, apply_ite card, card_insert_eq_ite, IH, |
/-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.Lie.Ideal
/-!
# Ideal operations for Lie algebras
Given a Lie module `M` over a Lie algebra `L`, there is a natural action of the Lie ideals of `L`
on the Lie submodules of `M`. In the special case that `M = L` with the adjoint action, this
provides a pairing of Lie ideals which is especially important. For example, it can be used to
define solvability / nilpotency of a Lie algebra via the derived / lower-central series.
## Main definitions
* `LieSubmodule.hasBracket`
* `LieSubmodule.lieIdeal_oper_eq_linear_span`
* `LieIdeal.map_bracket_le`
* `LieIdeal.comap_bracket_le`
## Notation
Given a Lie module `M` over a Lie algebra `L`, together with a Lie submodule `N ⊆ M` and a Lie
ideal `I ⊆ L`, we introduce the notation `⁅I, N⁆` for the Lie submodule of `M` corresponding to
the action defined in this file.
## Tags
lie algebra, ideal operation
-/
universe u v w w₁ w₂
namespace LieSubmodule
variable {R : Type u} {L : Type v} {M : Type w} {M₂ : Type w₁}
variable [CommRing R] [LieRing L]
variable [AddCommGroup M] [Module R M] [LieRingModule L M]
variable [AddCommGroup M₂] [Module R M₂] [LieRingModule L M₂]
variable (N N' : LieSubmodule R L M) (N₂ : LieSubmodule R L M₂)
variable (f : M →ₗ⁅R,L⁆ M₂)
section LieIdealOperations
theorem map_comap_le : map f (comap f N₂) ≤ N₂ :=
(N₂ : Set M₂).image_preimage_subset f
theorem map_comap_eq (hf : N₂ ≤ f.range) : map f (comap f N₂) = N₂ := by
rw [SetLike.ext'_iff]
exact Set.image_preimage_eq_of_subset hf
theorem le_comap_map : N ≤ comap f (map f N) :=
(N : Set M).subset_preimage_image f
theorem comap_map_eq (hf : f.ker = ⊥) : comap f (map f N) = N := by
rw [SetLike.ext'_iff]
exact (N : Set M).preimage_image_eq (f.ker_eq_bot.mp hf)
@[simp]
theorem map_comap_incl : map N.incl (comap N.incl N') = N ⊓ N' := by
rw [← toSubmodule_inj]
exact (N : Submodule R M).map_comap_subtype N'
variable [LieAlgebra R L] [LieModule R L M₂] (I J : LieIdeal R L)
/-- Given a Lie module `M` over a Lie algebra `L`, the set of Lie ideals of `L` acts on the set
of submodules of `M`. -/
instance hasBracket : Bracket (LieIdeal R L) (LieSubmodule R L M) :=
⟨fun I N => lieSpan R L { ⁅(x : L), (n : M)⁆ | (x : I) (n : N) }⟩
theorem lieIdeal_oper_eq_span :
⁅I, N⁆ = lieSpan R L { ⁅(x : L), (n : M)⁆ | (x : I) (n : N) } :=
rfl
/-- See also `LieSubmodule.lieIdeal_oper_eq_linear_span'` and
`LieSubmodule.lieIdeal_oper_eq_tensor_map_range`. -/
theorem lieIdeal_oper_eq_linear_span [LieModule R L M] :
(↑⁅I, N⁆ : Submodule R M) = Submodule.span R { ⁅(x : L), (n : M)⁆ | (x : I) (n : N) } := by
apply le_antisymm
· let s := { ⁅(x : L), (n : M)⁆ | (x : I) (n : N) }
have aux : ∀ (y : L), ∀ m' ∈ Submodule.span R s, ⁅y, m'⁆ ∈ Submodule.span R s := by
intro y m' hm'
refine Submodule.span_induction (R := R) (M := M) (s := s)
(p := fun m' _ ↦ ⁅y, m'⁆ ∈ Submodule.span R s) ?_ ?_ ?_ ?_ hm'
· rintro m'' ⟨x, n, hm''⟩; rw [← hm'', leibniz_lie]
refine Submodule.add_mem _ ?_ ?_ <;> apply Submodule.subset_span
· use ⟨⁅y, ↑x⁆, I.lie_mem x.property⟩, n
· use x, ⟨⁅y, ↑n⁆, N.lie_mem n.property⟩
· simp only [lie_zero, Submodule.zero_mem]
· intro m₁ m₂ _ _ hm₁ hm₂; rw [lie_add]; exact Submodule.add_mem _ hm₁ hm₂
· intro t m'' _ hm''; rw [lie_smul]; exact Submodule.smul_mem _ t hm''
change _ ≤ ({ Submodule.span R s with lie_mem := fun hm' => aux _ _ hm' } : LieSubmodule R L M)
rw [lieIdeal_oper_eq_span, lieSpan_le]
exact Submodule.subset_span
· rw [lieIdeal_oper_eq_span]; apply submodule_span_le_lieSpan
theorem lieIdeal_oper_eq_linear_span' [LieModule R L M] :
(↑⁅I, N⁆ : Submodule R M) = Submodule.span R { ⁅x, n⁆ | (x ∈ I) (n ∈ N) } := by
rw [lieIdeal_oper_eq_linear_span]
congr
ext m
constructor
· rintro ⟨⟨x, hx⟩, ⟨n, hn⟩, rfl⟩
exact ⟨x, hx, n, hn, rfl⟩
· rintro ⟨x, hx, n, hn, rfl⟩
exact ⟨⟨x, hx⟩, ⟨n, hn⟩, rfl⟩
theorem lie_le_iff : ⁅I, N⁆ ≤ N' ↔ ∀ x ∈ I, ∀ m ∈ N, ⁅x, m⁆ ∈ N' := by
rw [lieIdeal_oper_eq_span, LieSubmodule.lieSpan_le]
refine ⟨fun h x hx m hm => h ⟨⟨x, hx⟩, ⟨m, hm⟩, rfl⟩, ?_⟩
rintro h _ ⟨⟨x, hx⟩, ⟨m, hm⟩, rfl⟩
exact h x hx m hm
variable {N I} in
theorem lie_coe_mem_lie (x : I) (m : N) : ⁅(x : L), (m : M)⁆ ∈ ⁅I, N⁆ := by
rw [lieIdeal_oper_eq_span]; apply subset_lieSpan; use x, m
variable {N I} in
theorem lie_mem_lie {x : L} {m : M} (hx : x ∈ I) (hm : m ∈ N) : ⁅x, m⁆ ∈ ⁅I, N⁆ :=
lie_coe_mem_lie ⟨x, hx⟩ ⟨m, hm⟩
theorem lie_comm : ⁅I, J⁆ = ⁅J, I⁆ := by
suffices ∀ I J : LieIdeal R L, ⁅I, J⁆ ≤ ⁅J, I⁆ by exact le_antisymm (this I J) (this J I)
clear! I J; intro I J
rw [lieIdeal_oper_eq_span, lieSpan_le]; rintro x ⟨y, z, h⟩; rw [← h]
rw [← lie_skew, ← lie_neg, ← LieSubmodule.coe_neg]
apply lie_coe_mem_lie
theorem lie_le_right : ⁅I, N⁆ ≤ N := by
rw [lieIdeal_oper_eq_span, lieSpan_le]; rintro m ⟨x, n, hn⟩; rw [← hn]
exact N.lie_mem n.property
theorem lie_le_left : ⁅I, J⁆ ≤ I := by rw [lie_comm]; exact lie_le_right I J
theorem lie_le_inf : ⁅I, J⁆ ≤ I ⊓ J := by rw [le_inf_iff]; exact ⟨lie_le_left I J, lie_le_right J I⟩
@[simp]
| Mathlib/Algebra/Lie/IdealOperations.lean | 141 | 145 | theorem lie_bot : ⁅I, (⊥ : LieSubmodule R L M)⁆ = ⊥ := by | rw [eq_bot_iff]; apply lie_le_right
@[simp]
theorem bot_lie : ⁅(⊥ : LieIdeal R L), N⁆ = ⊥ := by
suffices ⁅(⊥ : LieIdeal R L), N⁆ ≤ ⊥ by exact le_bot_iff.mp this |
/-
Copyright (c) 2014 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Jeremy Avigad
-/
import Mathlib.Algebra.Order.Group.Nat
import Mathlib.Algebra.Order.Ring.Canonical
/-!
# Distance function on ℕ
This file defines a simple distance function on naturals from truncated subtraction.
-/
namespace Nat
/-- Distance (absolute value of difference) between natural numbers. -/
def dist (n m : ℕ) :=
n - m + (m - n)
theorem dist_comm (n m : ℕ) : dist n m = dist m n := by simp [dist, add_comm]
@[simp]
theorem dist_self (n : ℕ) : dist n n = 0 := by simp [dist, tsub_self]
theorem eq_of_dist_eq_zero {n m : ℕ} (h : dist n m = 0) : n = m :=
have : n - m = 0 := Nat.eq_zero_of_add_eq_zero_right h
have : n ≤ m := tsub_eq_zero_iff_le.mp this
have : m - n = 0 := Nat.eq_zero_of_add_eq_zero_left h
have : m ≤ n := tsub_eq_zero_iff_le.mp this
le_antisymm ‹n ≤ m› ‹m ≤ n›
theorem dist_eq_zero {n m : ℕ} (h : n = m) : dist n m = 0 := by rw [h, dist_self]
theorem dist_eq_sub_of_le {n m : ℕ} (h : n ≤ m) : dist n m = m - n := by
rw [dist, tsub_eq_zero_iff_le.mpr h, zero_add]
theorem dist_eq_sub_of_le_right {n m : ℕ} (h : m ≤ n) : dist n m = n - m := by
rw [dist_comm]; apply dist_eq_sub_of_le h
theorem dist_tri_left (n m : ℕ) : m ≤ dist n m + n :=
le_trans le_tsub_add (add_le_add_right (Nat.le_add_left _ _) _)
theorem dist_tri_right (n m : ℕ) : m ≤ n + dist n m := by rw [add_comm]; apply dist_tri_left
theorem dist_tri_left' (n m : ℕ) : n ≤ dist n m + m := by rw [dist_comm]; apply dist_tri_left
theorem dist_tri_right' (n m : ℕ) : n ≤ m + dist n m := by rw [dist_comm]; apply dist_tri_right
theorem dist_zero_right (n : ℕ) : dist n 0 = n :=
Eq.trans (dist_eq_sub_of_le_right (zero_le n)) (tsub_zero n)
theorem dist_zero_left (n : ℕ) : dist 0 n = n :=
Eq.trans (dist_eq_sub_of_le (zero_le n)) (tsub_zero n)
theorem dist_add_add_right (n k m : ℕ) : dist (n + k) (m + k) = dist n m :=
calc
dist (n + k) (m + k) = n + k - (m + k) + (m + k - (n + k)) := rfl
_ = n - m + (m + k - (n + k)) := by rw [@add_tsub_add_eq_tsub_right]
_ = n - m + (m - n) := by rw [@add_tsub_add_eq_tsub_right]
| Mathlib/Data/Nat/Dist.lean | 63 | 63 | theorem dist_add_add_left (k n m : ℕ) : dist (k + n) (k + m) = dist n m := by | |
/-
Copyright (c) 2021 Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard, Ines Wright, Joachim Breitner
-/
import Mathlib.GroupTheory.Solvable
import Mathlib.GroupTheory.Sylow
import Mathlib.Algebra.Group.Subgroup.Order
import Mathlib.GroupTheory.Commutator.Finite
/-!
# Nilpotent groups
An API for nilpotent groups, that is, groups for which the upper central series
reaches `⊤`.
## Main definitions
Recall that if `H K : Subgroup G` then `⁅H, K⁆ : Subgroup G` is the subgroup of `G` generated
by the commutators `hkh⁻¹k⁻¹`. Recall also Lean's conventions that `⊤` denotes the
subgroup `G` of `G`, and `⊥` denotes the trivial subgroup `{1}`.
* `upperCentralSeries G : ℕ → Subgroup G` : the upper central series of a group `G`.
This is an increasing sequence of normal subgroups `H n` of `G` with `H 0 = ⊥` and
`H (n + 1) / H n` is the centre of `G / H n`.
* `lowerCentralSeries G : ℕ → Subgroup G` : the lower central series of a group `G`.
This is a decreasing sequence of normal subgroups `H n` of `G` with `H 0 = ⊤` and
`H (n + 1) = ⁅H n, G⁆`.
* `IsNilpotent` : A group G is nilpotent if its upper central series reaches `⊤`, or
equivalently if its lower central series reaches `⊥`.
* `Group.nilpotencyClass` : the length of the upper central series of a nilpotent group.
* `IsAscendingCentralSeries (H : ℕ → Subgroup G) : Prop` and
* `IsDescendingCentralSeries (H : ℕ → Subgroup G) : Prop` : Note that in the literature
a "central series" for a group is usually defined to be a *finite* sequence of normal subgroups
`H 0`, `H 1`, ..., starting at `⊤`, finishing at `⊥`, and with each `H n / H (n + 1)`
central in `G / H (n + 1)`. In this formalisation it is convenient to have two weaker predicates
on an infinite sequence of subgroups `H n` of `G`: we say a sequence is a *descending central
series* if it starts at `G` and `⁅H n, ⊤⁆ ⊆ H (n + 1)` for all `n`. Note that this series
may not terminate at `⊥`, and the `H i` need not be normal. Similarly a sequence is an
*ascending central series* if `H 0 = ⊥` and `⁅H (n + 1), ⊤⁆ ⊆ H n` for all `n`, again with no
requirement that the series reaches `⊤` or that the `H i` are normal.
## Main theorems
`G` is *defined* to be nilpotent if the upper central series reaches `⊤`.
* `nilpotent_iff_finite_ascending_central_series` : `G` is nilpotent iff some ascending central
series reaches `⊤`.
* `nilpotent_iff_finite_descending_central_series` : `G` is nilpotent iff some descending central
series reaches `⊥`.
* `nilpotent_iff_lower` : `G` is nilpotent iff the lower central series reaches `⊥`.
* The `Group.nilpotencyClass` can likewise be obtained from these equivalent
definitions, see `least_ascending_central_series_length_eq_nilpotencyClass`,
`least_descending_central_series_length_eq_nilpotencyClass` and
`lowerCentralSeries_length_eq_nilpotencyClass`.
* If `G` is nilpotent, then so are its subgroups, images, quotients and preimages.
Binary and finite products of nilpotent groups are nilpotent.
Infinite products are nilpotent if their nilpotent class is bounded.
Corresponding lemmas about the `Group.nilpotencyClass` are provided.
* The `Group.nilpotencyClass` of `G ⧸ center G` is given explicitly, and an induction principle
is derived from that.
* `IsNilpotent.to_isSolvable`: If `G` is nilpotent, it is solvable.
## Warning
A "central series" is usually defined to be a finite sequence of normal subgroups going
from `⊥` to `⊤` with the property that each subquotient is contained within the centre of
the associated quotient of `G`. This means that if `G` is not nilpotent, then
none of what we have called `upperCentralSeries G`, `lowerCentralSeries G` or
the sequences satisfying `IsAscendingCentralSeries` or `IsDescendingCentralSeries`
are actually central series. Note that the fact that the upper and lower central series
are not central series if `G` is not nilpotent is a standard abuse of notation.
-/
open Subgroup
section WithGroup
variable {G : Type*} [Group G] (H : Subgroup G) [Normal H]
/-- If `H` is a normal subgroup of `G`, then the set `{x : G | ∀ y : G, x*y*x⁻¹*y⁻¹ ∈ H}`
is a subgroup of `G` (because it is the preimage in `G` of the centre of the
quotient group `G/H`.)
-/
def upperCentralSeriesStep : Subgroup G where
carrier := { x : G | ∀ y : G, x * y * x⁻¹ * y⁻¹ ∈ H }
one_mem' y := by simp [Subgroup.one_mem]
mul_mem' {a b} ha hb y := by
convert Subgroup.mul_mem _ (ha (b * y * b⁻¹)) (hb y) using 1
group
inv_mem' {x} hx y := by
specialize hx y⁻¹
rw [mul_assoc, inv_inv] at hx ⊢
exact Subgroup.Normal.mem_comm inferInstance hx
theorem mem_upperCentralSeriesStep (x : G) :
x ∈ upperCentralSeriesStep H ↔ ∀ y, x * y * x⁻¹ * y⁻¹ ∈ H := Iff.rfl
open QuotientGroup
/-- The proof that `upperCentralSeriesStep H` is the preimage of the centre of `G/H` under
the canonical surjection. -/
theorem upperCentralSeriesStep_eq_comap_center :
upperCentralSeriesStep H = Subgroup.comap (mk' H) (center (G ⧸ H)) := by
ext
rw [mem_comap, mem_center_iff, forall_mk]
apply forall_congr'
intro y
rw [coe_mk', ← QuotientGroup.mk_mul, ← QuotientGroup.mk_mul, eq_comm, eq_iff_div_mem,
div_eq_mul_inv, mul_inv_rev, mul_assoc]
instance : Normal (upperCentralSeriesStep H) := by
rw [upperCentralSeriesStep_eq_comap_center]
infer_instance
variable (G)
/-- An auxiliary type-theoretic definition defining both the upper central series of
a group, and a proof that it is normal, all in one go. -/
def upperCentralSeriesAux : ℕ → Σ'H : Subgroup G, Normal H
| 0 => ⟨⊥, inferInstance⟩
| n + 1 =>
let un := upperCentralSeriesAux n
let _un_normal := un.2
⟨upperCentralSeriesStep un.1, inferInstance⟩
/-- `upperCentralSeries G n` is the `n`th term in the upper central series of `G`. -/
def upperCentralSeries (n : ℕ) : Subgroup G :=
(upperCentralSeriesAux G n).1
instance upperCentralSeries_normal (n : ℕ) : Normal (upperCentralSeries G n) :=
(upperCentralSeriesAux G n).2
@[simp]
theorem upperCentralSeries_zero : upperCentralSeries G 0 = ⊥ := rfl
@[simp]
theorem upperCentralSeries_one : upperCentralSeries G 1 = center G := by
ext
simp only [upperCentralSeries, upperCentralSeriesAux, upperCentralSeriesStep,
Subgroup.mem_center_iff, mem_mk, mem_bot, Set.mem_setOf_eq]
exact forall_congr' fun y => by rw [mul_inv_eq_one, mul_inv_eq_iff_eq_mul, eq_comm]
variable {G}
/-- The `n+1`st term of the upper central series `H i` has underlying set equal to the `x` such
that `⁅x,G⁆ ⊆ H n`. -/
theorem mem_upperCentralSeries_succ_iff {n : ℕ} {x : G} :
x ∈ upperCentralSeries G (n + 1) ↔ ∀ y : G, x * y * x⁻¹ * y⁻¹ ∈ upperCentralSeries G n :=
Iff.rfl
@[simp] lemma comap_upperCentralSeries {H : Type*} [Group H] (e : H ≃* G) :
∀ n, (upperCentralSeries G n).comap e = upperCentralSeries H n
| 0 => by simpa [MonoidHom.ker_eq_bot_iff] using e.injective
| n + 1 => by
ext
simp [mem_upperCentralSeries_succ_iff, ← comap_upperCentralSeries e n,
← e.toEquiv.forall_congr_right]
namespace Group
variable (G) in
-- `IsNilpotent` is already defined in the root namespace (for elements of rings).
-- TODO: Rename it to `IsNilpotentElement`?
/-- A group `G` is nilpotent if its upper central series is eventually `G`. -/
@[mk_iff]
class IsNilpotent (G : Type*) [Group G] : Prop where
nilpotent' : ∃ n : ℕ, upperCentralSeries G n = ⊤
lemma IsNilpotent.nilpotent (G : Type*) [Group G] [IsNilpotent G] :
∃ n : ℕ, upperCentralSeries G n = ⊤ := Group.IsNilpotent.nilpotent'
lemma isNilpotent_congr {H : Type*} [Group H] (e : G ≃* H) : IsNilpotent G ↔ IsNilpotent H := by
simp_rw [isNilpotent_iff]
refine exists_congr fun n ↦ ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· simp [← Subgroup.comap_top e.symm.toMonoidHom, ← h]
· simp [← Subgroup.comap_top e.toMonoidHom, ← h]
@[simp] lemma isNilpotent_top : IsNilpotent (⊤ : Subgroup G) ↔ IsNilpotent G :=
isNilpotent_congr Subgroup.topEquiv
variable (G) in
/-- A group `G` is virtually nilpotent if it has a nilpotent cofinite subgroup `N`. -/
def IsVirtuallyNilpotent : Prop := ∃ N : Subgroup G, IsNilpotent N ∧ FiniteIndex N
lemma IsNilpotent.isVirtuallyNilpotent (hG : IsNilpotent G) : IsVirtuallyNilpotent G :=
⟨⊤, by simpa, inferInstance⟩
end Group
open Group
/-- A sequence of subgroups of `G` is an ascending central series if `H 0` is trivial and
`⁅H (n + 1), G⁆ ⊆ H n` for all `n`. Note that we do not require that `H n = G` for some `n`. -/
def IsAscendingCentralSeries (H : ℕ → Subgroup G) : Prop :=
H 0 = ⊥ ∧ ∀ (x : G) (n : ℕ), x ∈ H (n + 1) → ∀ g, x * g * x⁻¹ * g⁻¹ ∈ H n
/-- A sequence of subgroups of `G` is a descending central series if `H 0` is `G` and
`⁅H n, G⁆ ⊆ H (n + 1)` for all `n`. Note that we do not require that `H n = {1}` for some `n`. -/
def IsDescendingCentralSeries (H : ℕ → Subgroup G) :=
H 0 = ⊤ ∧ ∀ (x : G) (n : ℕ), x ∈ H n → ∀ g, x * g * x⁻¹ * g⁻¹ ∈ H (n + 1)
/-- Any ascending central series for a group is bounded above by the upper central series. -/
theorem ascending_central_series_le_upper (H : ℕ → Subgroup G) (hH : IsAscendingCentralSeries H) :
∀ n : ℕ, H n ≤ upperCentralSeries G n
| 0 => hH.1.symm ▸ le_refl ⊥
| n + 1 => by
intro x hx
rw [mem_upperCentralSeries_succ_iff]
exact fun y => ascending_central_series_le_upper H hH n (hH.2 x n hx y)
variable (G)
/-- The upper central series of a group is an ascending central series. -/
theorem upperCentralSeries_isAscendingCentralSeries :
IsAscendingCentralSeries (upperCentralSeries G) :=
⟨rfl, fun _x _n h => h⟩
theorem upperCentralSeries_mono : Monotone (upperCentralSeries G) := by
refine monotone_nat_of_le_succ ?_
intro n x hx y
rw [mul_assoc, mul_assoc, ← mul_assoc y x⁻¹ y⁻¹]
exact mul_mem hx (Normal.conj_mem (upperCentralSeries_normal G n) x⁻¹ (inv_mem hx) y)
/-- A group `G` is nilpotent iff there exists an ascending central series which reaches `G` in
finitely many steps. -/
theorem nilpotent_iff_finite_ascending_central_series :
IsNilpotent G ↔ ∃ n : ℕ, ∃ H : ℕ → Subgroup G, IsAscendingCentralSeries H ∧ H n = ⊤ := by
constructor
· rintro ⟨n, nH⟩
exact ⟨_, _, upperCentralSeries_isAscendingCentralSeries G, nH⟩
· rintro ⟨n, H, hH, hn⟩
use n
rw [eq_top_iff, ← hn]
exact ascending_central_series_le_upper H hH n
theorem is_descending_rev_series_of_is_ascending {H : ℕ → Subgroup G} {n : ℕ} (hn : H n = ⊤)
(hasc : IsAscendingCentralSeries H) : IsDescendingCentralSeries fun m : ℕ => H (n - m) := by
obtain ⟨h0, hH⟩ := hasc
refine ⟨hn, fun x m hx g => ?_⟩
dsimp at hx
by_cases hm : n ≤ m
· rw [tsub_eq_zero_of_le hm, h0, Subgroup.mem_bot] at hx
subst hx
rw [show (1 : G) * g * (1⁻¹ : G) * g⁻¹ = 1 by group]
exact Subgroup.one_mem _
· push_neg at hm
apply hH
convert hx using 1
rw [tsub_add_eq_add_tsub (Nat.succ_le_of_lt hm), Nat.succ_eq_add_one, Nat.add_sub_add_right]
@[deprecated (since := "2024-12-25")]
alias is_decending_rev_series_of_is_ascending := is_descending_rev_series_of_is_ascending
theorem is_ascending_rev_series_of_is_descending {H : ℕ → Subgroup G} {n : ℕ} (hn : H n = ⊥)
(hdesc : IsDescendingCentralSeries H) : IsAscendingCentralSeries fun m : ℕ => H (n - m) := by
obtain ⟨h0, hH⟩ := hdesc
refine ⟨hn, fun x m hx g => ?_⟩
dsimp only at hx ⊢
by_cases hm : n ≤ m
· have hnm : n - m = 0 := tsub_eq_zero_iff_le.mpr hm
rw [hnm, h0]
exact mem_top _
· push_neg at hm
convert hH x _ hx g using 1
rw [tsub_add_eq_add_tsub (Nat.succ_le_of_lt hm), Nat.succ_eq_add_one, Nat.add_sub_add_right]
/-- A group `G` is nilpotent iff there exists a descending central series which reaches the
trivial group in a finite time. -/
theorem nilpotent_iff_finite_descending_central_series :
IsNilpotent G ↔ ∃ n : ℕ, ∃ H : ℕ → Subgroup G, IsDescendingCentralSeries H ∧ H n = ⊥ := by
rw [nilpotent_iff_finite_ascending_central_series]
constructor
· rintro ⟨n, H, hH, hn⟩
refine ⟨n, fun m => H (n - m), is_descending_rev_series_of_is_ascending G hn hH, ?_⟩
dsimp only
rw [tsub_self]
exact hH.1
· rintro ⟨n, H, hH, hn⟩
refine ⟨n, fun m => H (n - m), is_ascending_rev_series_of_is_descending G hn hH, ?_⟩
dsimp only
rw [tsub_self]
exact hH.1
/-- The lower central series of a group `G` is a sequence `H n` of subgroups of `G`, defined
by `H 0` is all of `G` and for `n≥1`, `H (n + 1) = ⁅H n, G⁆` -/
def lowerCentralSeries (G : Type*) [Group G] : ℕ → Subgroup G
| 0 => ⊤
| n + 1 => ⁅lowerCentralSeries G n, ⊤⁆
variable {G}
@[simp]
theorem lowerCentralSeries_zero : lowerCentralSeries G 0 = ⊤ := rfl
@[simp]
theorem lowerCentralSeries_one : lowerCentralSeries G 1 = commutator G := rfl
theorem mem_lowerCentralSeries_succ_iff (n : ℕ) (q : G) :
q ∈ lowerCentralSeries G (n + 1) ↔
q ∈ closure { x | ∃ p ∈ lowerCentralSeries G n,
∃ q ∈ (⊤ : Subgroup G), p * q * p⁻¹ * q⁻¹ = x } := Iff.rfl
theorem lowerCentralSeries_succ (n : ℕ) :
lowerCentralSeries G (n + 1) =
closure { x | ∃ p ∈ lowerCentralSeries G n, ∃ q ∈ (⊤ : Subgroup G), p * q * p⁻¹ * q⁻¹ = x } :=
rfl
instance lowerCentralSeries_normal (n : ℕ) : Normal (lowerCentralSeries G n) := by
induction' n with d hd
· exact (⊤ : Subgroup G).normal_of_characteristic
· exact @Subgroup.commutator_normal _ _ (lowerCentralSeries G d) ⊤ hd _
theorem lowerCentralSeries_antitone : Antitone (lowerCentralSeries G) := by
refine antitone_nat_of_succ_le fun n x hx => ?_
simp only [mem_lowerCentralSeries_succ_iff, exists_prop, mem_top, exists_true_left,
true_and] at hx
refine
closure_induction ?_ (Subgroup.one_mem _) (fun _ _ _ _ ↦ mul_mem) (fun _ _ ↦ inv_mem) hx
rintro y ⟨z, hz, a, ha⟩
rw [← ha, mul_assoc, mul_assoc, ← mul_assoc a z⁻¹ a⁻¹]
exact mul_mem hz (Normal.conj_mem (lowerCentralSeries_normal n) z⁻¹ (inv_mem hz) a)
/-- The lower central series of a group is a descending central series. -/
theorem lowerCentralSeries_isDescendingCentralSeries :
IsDescendingCentralSeries (lowerCentralSeries G) := by
constructor
· rfl
intro x n hxn g
exact commutator_mem_commutator hxn (mem_top g)
/-- Any descending central series for a group is bounded below by the lower central series. -/
theorem descending_central_series_ge_lower (H : ℕ → Subgroup G) (hH : IsDescendingCentralSeries H) :
∀ n : ℕ, lowerCentralSeries G n ≤ H n
| 0 => hH.1.symm ▸ le_refl ⊤
| n + 1 => commutator_le.mpr fun x hx q _ =>
hH.2 x n (descending_central_series_ge_lower H hH n hx) q
/-- A group is nilpotent if and only if its lower central series eventually reaches
the trivial subgroup. -/
theorem nilpotent_iff_lowerCentralSeries : IsNilpotent G ↔ ∃ n, lowerCentralSeries G n = ⊥ := by
rw [nilpotent_iff_finite_descending_central_series]
constructor
· rintro ⟨n, H, ⟨h0, hs⟩, hn⟩
use n
rw [eq_bot_iff, ← hn]
exact descending_central_series_ge_lower H ⟨h0, hs⟩ n
· rintro ⟨n, hn⟩
exact ⟨n, lowerCentralSeries G, lowerCentralSeries_isDescendingCentralSeries, hn⟩
section Classical
variable [hG : IsNilpotent G]
variable (G) in
open scoped Classical in
/-- The nilpotency class of a nilpotent group is the smallest natural `n` such that
the `n`'th term of the upper central series is `G`. -/
noncomputable def Group.nilpotencyClass : ℕ := Nat.find (IsNilpotent.nilpotent G)
open scoped Classical in
@[simp]
theorem upperCentralSeries_nilpotencyClass : upperCentralSeries G (Group.nilpotencyClass G) = ⊤ :=
Nat.find_spec (IsNilpotent.nilpotent G)
theorem upperCentralSeries_eq_top_iff_nilpotencyClass_le {n : ℕ} :
upperCentralSeries G n = ⊤ ↔ Group.nilpotencyClass G ≤ n := by
classical
constructor
· intro h
exact Nat.find_le h
· intro h
rw [eq_top_iff, ← upperCentralSeries_nilpotencyClass]
exact upperCentralSeries_mono _ h
open scoped Classical in
/-- The nilpotency class of a nilpotent `G` is equal to the smallest `n` for which an ascending
central series reaches `G` in its `n`'th term. -/
theorem least_ascending_central_series_length_eq_nilpotencyClass :
Nat.find ((nilpotent_iff_finite_ascending_central_series G).mp hG) =
Group.nilpotencyClass G := by
refine le_antisymm (Nat.find_mono ?_) (Nat.find_mono ?_)
· intro n hn
exact ⟨upperCentralSeries G, upperCentralSeries_isAscendingCentralSeries G, hn⟩
· rintro n ⟨H, ⟨hH, hn⟩⟩
rw [← top_le_iff, ← hn]
exact ascending_central_series_le_upper H hH n
open scoped Classical in
/-- The nilpotency class of a nilpotent `G` is equal to the smallest `n` for which the descending
central series reaches `⊥` in its `n`'th term. -/
theorem least_descending_central_series_length_eq_nilpotencyClass :
Nat.find ((nilpotent_iff_finite_descending_central_series G).mp hG) =
Group.nilpotencyClass G := by
rw [← least_ascending_central_series_length_eq_nilpotencyClass]
refine le_antisymm (Nat.find_mono ?_) (Nat.find_mono ?_)
· rintro n ⟨H, ⟨hH, hn⟩⟩
refine ⟨fun m => H (n - m), is_descending_rev_series_of_is_ascending G hn hH, ?_⟩
dsimp only
rw [tsub_self]
exact hH.1
· rintro n ⟨H, ⟨hH, hn⟩⟩
refine ⟨fun m => H (n - m), is_ascending_rev_series_of_is_descending G hn hH, ?_⟩
dsimp only
rw [tsub_self]
exact hH.1
open scoped Classical in
/-- The nilpotency class of a nilpotent `G` is equal to the length of the lower central series. -/
theorem lowerCentralSeries_length_eq_nilpotencyClass :
Nat.find (nilpotent_iff_lowerCentralSeries.mp hG) = Group.nilpotencyClass (G := G) := by
rw [← least_descending_central_series_length_eq_nilpotencyClass]
refine le_antisymm (Nat.find_mono ?_) (Nat.find_mono ?_)
· rintro n ⟨H, ⟨hH, hn⟩⟩
rw [← le_bot_iff, ← hn]
exact descending_central_series_ge_lower H hH n
· rintro n h
exact ⟨lowerCentralSeries G, ⟨lowerCentralSeries_isDescendingCentralSeries, h⟩⟩
@[simp]
theorem lowerCentralSeries_nilpotencyClass :
lowerCentralSeries G (Group.nilpotencyClass G) = ⊥ := by
classical
rw [← lowerCentralSeries_length_eq_nilpotencyClass]
exact Nat.find_spec (nilpotent_iff_lowerCentralSeries.mp hG)
theorem lowerCentralSeries_eq_bot_iff_nilpotencyClass_le {n : ℕ} :
lowerCentralSeries G n = ⊥ ↔ Group.nilpotencyClass G ≤ n := by
classical
constructor
· intro h
rw [← lowerCentralSeries_length_eq_nilpotencyClass]
exact Nat.find_le h
· intro h
rw [eq_bot_iff, ← lowerCentralSeries_nilpotencyClass]
exact lowerCentralSeries_antitone h
end Classical
theorem lowerCentralSeries_map_subtype_le (H : Subgroup G) (n : ℕ) :
(lowerCentralSeries H n).map H.subtype ≤ lowerCentralSeries G n := by
induction' n with d hd
· simp
· rw [lowerCentralSeries_succ, lowerCentralSeries_succ, MonoidHom.map_closure]
apply Subgroup.closure_mono
rintro x1 ⟨x2, ⟨x3, hx3, x4, _hx4, rfl⟩, rfl⟩
exact ⟨x3, hd (mem_map.mpr ⟨x3, hx3, rfl⟩), x4, by simp⟩
/-- A subgroup of a nilpotent group is nilpotent -/
instance Subgroup.isNilpotent (H : Subgroup G) [hG : IsNilpotent G] : IsNilpotent H := by
rw [nilpotent_iff_lowerCentralSeries] at *
rcases hG with ⟨n, hG⟩
use n
have := lowerCentralSeries_map_subtype_le H n
simp only [hG, SetLike.le_def, mem_map, forall_apply_eq_imp_iff₂, exists_imp] at this
exact eq_bot_iff.mpr fun x hx => Subtype.ext (this x ⟨hx, rfl⟩)
/-- The nilpotency class of a subgroup is less or equal to the nilpotency class of the group -/
theorem Subgroup.nilpotencyClass_le (H : Subgroup G) [hG : IsNilpotent G] :
Group.nilpotencyClass H ≤ Group.nilpotencyClass G := by
repeat rw [← lowerCentralSeries_length_eq_nilpotencyClass]
classical apply Nat.find_mono
intro n hG
have := lowerCentralSeries_map_subtype_le H n
simp only [hG, SetLike.le_def, mem_map, forall_apply_eq_imp_iff₂, exists_imp] at this
exact eq_bot_iff.mpr fun x hx => Subtype.ext (this x ⟨hx, rfl⟩)
instance (priority := 100) Group.isNilpotent_of_subsingleton [Subsingleton G] : IsNilpotent G :=
nilpotent_iff_lowerCentralSeries.2 ⟨0, Subsingleton.elim ⊤ ⊥⟩
theorem upperCentralSeries.map {H : Type*} [Group H] {f : G →* H} (h : Function.Surjective f)
(n : ℕ) : Subgroup.map f (upperCentralSeries G n) ≤ upperCentralSeries H n := by
induction' n with d hd
· simp
· rintro _ ⟨x, hx : x ∈ upperCentralSeries G d.succ, rfl⟩ y'
rcases h y' with ⟨y, rfl⟩
simpa using hd (mem_map_of_mem f (hx y))
theorem lowerCentralSeries.map {H : Type*} [Group H] (f : G →* H) (n : ℕ) :
Subgroup.map f (lowerCentralSeries G n) ≤ lowerCentralSeries H n := by
induction' n with d hd
· simp
· rintro a ⟨x, hx : x ∈ lowerCentralSeries G d.succ, rfl⟩
refine closure_induction (hx := hx) ?_ (by simp [f.map_one, Subgroup.one_mem _])
(fun y z _ _ hy hz => by simp [MonoidHom.map_mul, Subgroup.mul_mem _ hy hz]) (fun y _ hy => by
rw [f.map_inv]; exact Subgroup.inv_mem _ hy)
rintro a ⟨y, hy, z, ⟨-, rfl⟩⟩
apply mem_closure.mpr
exact fun K hK => hK ⟨f y, hd (mem_map_of_mem f hy), by simp [commutatorElement_def]⟩
theorem lowerCentralSeries_succ_eq_bot {n : ℕ} (h : lowerCentralSeries G n ≤ center G) :
lowerCentralSeries G (n + 1) = ⊥ := by
rw [lowerCentralSeries_succ, closure_eq_bot_iff, Set.subset_singleton_iff]
rintro x ⟨y, hy1, z, ⟨⟩, rfl⟩
rw [mul_assoc, ← mul_inv_rev, mul_inv_eq_one, eq_comm]
exact mem_center_iff.mp (h hy1) z
/-- The preimage of a nilpotent group is nilpotent if the kernel of the homomorphism is contained
in the center -/
theorem isNilpotent_of_ker_le_center {H : Type*} [Group H] (f : G →* H) (hf1 : f.ker ≤ center G)
(hH : IsNilpotent H) : IsNilpotent G := by
rw [nilpotent_iff_lowerCentralSeries] at *
rcases hH with ⟨n, hn⟩
use n + 1
refine lowerCentralSeries_succ_eq_bot (le_trans ((Subgroup.map_eq_bot_iff _).mp ?_) hf1)
exact eq_bot_iff.mpr (hn ▸ lowerCentralSeries.map f n)
theorem nilpotencyClass_le_of_ker_le_center {H : Type*} [Group H] (f : G →* H)
(hf1 : f.ker ≤ center G) (hH : IsNilpotent H) :
Group.nilpotencyClass (hG := isNilpotent_of_ker_le_center f hf1 hH) ≤
Group.nilpotencyClass H + 1 := by
haveI : IsNilpotent G := isNilpotent_of_ker_le_center f hf1 hH
rw [← lowerCentralSeries_length_eq_nilpotencyClass]
classical apply Nat.find_min'
refine lowerCentralSeries_succ_eq_bot (le_trans ((Subgroup.map_eq_bot_iff _).mp ?_) hf1)
rw [eq_bot_iff]
apply le_trans (lowerCentralSeries.map f _)
simp only [lowerCentralSeries_nilpotencyClass, le_bot_iff]
/-- The range of a surjective homomorphism from a nilpotent group is nilpotent -/
theorem nilpotent_of_surjective {G' : Type*} [Group G'] [h : IsNilpotent G] (f : G →* G')
(hf : Function.Surjective f) : IsNilpotent G' := by
rcases h with ⟨n, hn⟩
use n
apply eq_top_iff.mpr
calc
⊤ = f.range := symm (f.range_eq_top_of_surjective hf)
_ = Subgroup.map f ⊤ := MonoidHom.range_eq_map _
_ = Subgroup.map f (upperCentralSeries G n) := by rw [hn]
_ ≤ upperCentralSeries G' n := upperCentralSeries.map hf n
/-- The nilpotency class of the range of a surjective homomorphism from a
nilpotent group is less or equal the nilpotency class of the domain -/
theorem nilpotencyClass_le_of_surjective {G' : Type*} [Group G'] (f : G →* G')
(hf : Function.Surjective f) [h : IsNilpotent G] :
Group.nilpotencyClass (hG := nilpotent_of_surjective _ hf) ≤ Group.nilpotencyClass G := by
classical apply Nat.find_mono
intro n hn
rw [eq_top_iff]
calc
⊤ = f.range := symm (f.range_eq_top_of_surjective hf)
_ = Subgroup.map f ⊤ := MonoidHom.range_eq_map _
_ = Subgroup.map f (upperCentralSeries G n) := by rw [hn]
_ ≤ upperCentralSeries G' n := upperCentralSeries.map hf n
/-- Nilpotency respects isomorphisms -/
theorem nilpotent_of_mulEquiv {G' : Type*} [Group G'] [_h : IsNilpotent G] (f : G ≃* G') :
IsNilpotent G' :=
nilpotent_of_surjective f.toMonoidHom (MulEquiv.surjective f)
/-- A quotient of a nilpotent group is nilpotent -/
instance nilpotent_quotient_of_nilpotent (H : Subgroup G) [H.Normal] [_h : IsNilpotent G] :
IsNilpotent (G ⧸ H) :=
nilpotent_of_surjective (QuotientGroup.mk' H) QuotientGroup.mk_surjective
/-- The nilpotency class of a quotient of `G` is less or equal the nilpotency class of `G` -/
theorem nilpotencyClass_quotient_le (H : Subgroup G) [H.Normal] [_h : IsNilpotent G] :
Group.nilpotencyClass (G ⧸ H) ≤ Group.nilpotencyClass G :=
nilpotencyClass_le_of_surjective (QuotientGroup.mk' H) QuotientGroup.mk_surjective
-- This technical lemma helps with rewriting the subgroup, which occurs in indices
private theorem comap_center_subst {H₁ H₂ : Subgroup G} [Normal H₁] [Normal H₂] (h : H₁ = H₂) :
comap (mk' H₁) (center (G ⧸ H₁)) = comap (mk' H₂) (center (G ⧸ H₂)) := by subst h; rfl
theorem comap_upperCentralSeries_quotient_center (n : ℕ) :
comap (mk' (center G)) (upperCentralSeries (G ⧸ center G) n) = upperCentralSeries G n.succ := by
induction' n with n ih
· simp only [upperCentralSeries_zero, MonoidHom.comap_bot, ker_mk',
(upperCentralSeries_one G).symm]
· let Hn := upperCentralSeries (G ⧸ center G) n
calc
comap (mk' (center G)) (upperCentralSeriesStep Hn) =
comap (mk' (center G)) (comap (mk' Hn) (center ((G ⧸ center G) ⧸ Hn))) := by
rw [upperCentralSeriesStep_eq_comap_center]
_ = comap (mk' (comap (mk' (center G)) Hn)) (center (G ⧸ comap (mk' (center G)) Hn)) :=
QuotientGroup.comap_comap_center
_ = comap (mk' (upperCentralSeries G n.succ)) (center (G ⧸ upperCentralSeries G n.succ)) :=
(comap_center_subst ih)
_ = upperCentralSeriesStep (upperCentralSeries G n.succ) :=
symm (upperCentralSeriesStep_eq_comap_center _)
theorem nilpotencyClass_zero_iff_subsingleton [IsNilpotent G] :
Group.nilpotencyClass G = 0 ↔ Subsingleton G := by
classical
rw [Group.nilpotencyClass, Nat.find_eq_zero, upperCentralSeries_zero,
subsingleton_iff_bot_eq_top, Subgroup.subsingleton_iff]
/-- Quotienting the `center G` reduces the nilpotency class by 1 -/
theorem nilpotencyClass_quotient_center [hH : IsNilpotent G] :
Group.nilpotencyClass (G ⧸ center G) = Group.nilpotencyClass G - 1 := by
generalize hn : Group.nilpotencyClass G = n
rcases n with (rfl | n)
· simp [nilpotencyClass_zero_iff_subsingleton] at *
exact Quotient.instSubsingletonQuotient (leftRel (center G))
· suffices Group.nilpotencyClass (G ⧸ center G) = n by simpa
apply le_antisymm
· apply upperCentralSeries_eq_top_iff_nilpotencyClass_le.mp
apply comap_injective (f := (mk' (center G))) Quot.mk_surjective
rw [comap_upperCentralSeries_quotient_center, comap_top, Nat.succ_eq_add_one, ← hn]
exact upperCentralSeries_nilpotencyClass
· apply le_of_add_le_add_right
calc
n + 1 = Group.nilpotencyClass G := hn.symm
_ ≤ Group.nilpotencyClass (G ⧸ center G) + 1 :=
nilpotencyClass_le_of_ker_le_center _ (le_of_eq (ker_mk' _)) _
/-- The nilpotency class of a non-trivial group is one more than its quotient by the center -/
theorem nilpotencyClass_eq_quotient_center_plus_one [hH : IsNilpotent G] [Nontrivial G] :
Group.nilpotencyClass G = Group.nilpotencyClass (G ⧸ center G) + 1 := by
rw [nilpotencyClass_quotient_center]
rcases h : Group.nilpotencyClass G with ⟨⟩
· exfalso
rw [nilpotencyClass_zero_iff_subsingleton] at h
apply false_of_nontrivial_of_subsingleton G
· simp
/-- If the quotient by `center G` is nilpotent, then so is G. -/
theorem of_quotient_center_nilpotent (h : IsNilpotent (G ⧸ center G)) : IsNilpotent G := by
obtain ⟨n, hn⟩ := h.nilpotent
use n.succ
simp [← comap_upperCentralSeries_quotient_center, hn]
/-- A custom induction principle for nilpotent groups. The base case is a trivial group
(`subsingleton G`), and in the induction step, one can assume the hypothesis for
the group quotiented by its center. -/
@[elab_as_elim]
theorem nilpotent_center_quotient_ind {P : ∀ (G) [Group G] [IsNilpotent G], Prop}
(G : Type*) [Group G] [IsNilpotent G]
(hbase : ∀ (G) [Group G] [Subsingleton G], P G)
(hstep : ∀ (G) [Group G] [IsNilpotent G], P (G ⧸ center G) → P G) : P G := by
obtain ⟨n, h⟩ : ∃ n, Group.nilpotencyClass G = n := ⟨_, rfl⟩
induction' n with n ih generalizing G
· haveI := nilpotencyClass_zero_iff_subsingleton.mp h
exact hbase _
· have hn : Group.nilpotencyClass (G ⧸ center G) = n := by
simp [nilpotencyClass_quotient_center, h]
exact hstep _ (ih _ hn)
theorem derived_le_lower_central (n : ℕ) : derivedSeries G n ≤ lowerCentralSeries G n := by
induction' n with i ih
· simp
· apply commutator_mono ih
simp
/-- Abelian groups are nilpotent -/
instance (priority := 100) CommGroup.isNilpotent {G : Type*} [CommGroup G] : IsNilpotent G := by
use 1
rw [upperCentralSeries_one]
apply CommGroup.center_eq_top
/-- Abelian groups have nilpotency class at most one -/
theorem CommGroup.nilpotencyClass_le_one {G : Type*} [CommGroup G] :
Group.nilpotencyClass G ≤ 1 := by
rw [← upperCentralSeries_eq_top_iff_nilpotencyClass_le, upperCentralSeries_one]
apply CommGroup.center_eq_top
/-- Groups with nilpotency class at most one are abelian -/
def commGroupOfNilpotencyClass [IsNilpotent G] (h : Group.nilpotencyClass G ≤ 1) : CommGroup G :=
Group.commGroupOfCenterEqTop <| by
rw [← upperCentralSeries_one]
exact upperCentralSeries_eq_top_iff_nilpotencyClass_le.mpr h
section Prod
variable {G₁ G₂ : Type*} [Group G₁] [Group G₂]
theorem lowerCentralSeries_prod (n : ℕ) :
lowerCentralSeries (G₁ × G₂) n = (lowerCentralSeries G₁ n).prod (lowerCentralSeries G₂ n) := by
induction' n with n ih
· simp
· calc
lowerCentralSeries (G₁ × G₂) n.succ = ⁅lowerCentralSeries (G₁ × G₂) n, ⊤⁆ := rfl
_ = ⁅(lowerCentralSeries G₁ n).prod (lowerCentralSeries G₂ n), ⊤⁆ := by rw [ih]
_ = ⁅(lowerCentralSeries G₁ n).prod (lowerCentralSeries G₂ n), (⊤ : Subgroup G₁).prod ⊤⁆ := by
simp
_ = ⁅lowerCentralSeries G₁ n, (⊤ : Subgroup G₁)⁆.prod ⁅lowerCentralSeries G₂ n, ⊤⁆ :=
(commutator_prod_prod _ _ _ _)
_ = (lowerCentralSeries G₁ n.succ).prod (lowerCentralSeries G₂ n.succ) := rfl
/-- Products of nilpotent groups are nilpotent -/
instance isNilpotent_prod [IsNilpotent G₁] [IsNilpotent G₂] : IsNilpotent (G₁ × G₂) := by
rw [nilpotent_iff_lowerCentralSeries]
refine ⟨max (Group.nilpotencyClass G₁) (Group.nilpotencyClass G₂), ?_⟩
rw [lowerCentralSeries_prod,
lowerCentralSeries_eq_bot_iff_nilpotencyClass_le.mpr (le_max_left _ _),
lowerCentralSeries_eq_bot_iff_nilpotencyClass_le.mpr (le_max_right _ _), bot_prod_bot]
/-- The nilpotency class of a product is the max of the nilpotency classes of the factors -/
theorem nilpotencyClass_prod [IsNilpotent G₁] [IsNilpotent G₂] :
Group.nilpotencyClass (G₁ × G₂) =
max (Group.nilpotencyClass G₁) (Group.nilpotencyClass G₂) := by
refine eq_of_forall_ge_iff fun k => ?_
simp only [max_le_iff, ← lowerCentralSeries_eq_bot_iff_nilpotencyClass_le,
lowerCentralSeries_prod, prod_eq_bot_iff]
end Prod
section BoundedPi
-- First the case of infinite products with bounded nilpotency class
variable {η : Type*} {Gs : η → Type*} [∀ i, Group (Gs i)]
theorem lowerCentralSeries_pi_le (n : ℕ) :
lowerCentralSeries (∀ i, Gs i) n ≤ Subgroup.pi Set.univ
fun i => lowerCentralSeries (Gs i) n := by
let pi := fun f : ∀ i, Subgroup (Gs i) => Subgroup.pi Set.univ f
induction' n with n ih
· simp [pi_top]
· calc
lowerCentralSeries (∀ i, Gs i) n.succ = ⁅lowerCentralSeries (∀ i, Gs i) n, ⊤⁆ := rfl
_ ≤ ⁅pi fun i => lowerCentralSeries (Gs i) n, ⊤⁆ := commutator_mono ih (le_refl _)
_ = ⁅pi fun i => lowerCentralSeries (Gs i) n, pi fun i => ⊤⁆ := by simp [pi, pi_top]
_ ≤ pi fun i => ⁅lowerCentralSeries (Gs i) n, ⊤⁆ := commutator_pi_pi_le _ _
_ = pi fun i => lowerCentralSeries (Gs i) n.succ := rfl
/-- products of nilpotent groups are nilpotent if their nilpotency class is bounded -/
theorem isNilpotent_pi_of_bounded_class [∀ i, IsNilpotent (Gs i)] (n : ℕ)
(h : ∀ i, Group.nilpotencyClass (Gs i) ≤ n) : IsNilpotent (∀ i, Gs i) := by
rw [nilpotent_iff_lowerCentralSeries]
refine ⟨n, ?_⟩
rw [eq_bot_iff]
apply le_trans (lowerCentralSeries_pi_le _)
rw [← eq_bot_iff, pi_eq_bot_iff]
intro i
apply lowerCentralSeries_eq_bot_iff_nilpotencyClass_le.mpr (h i)
end BoundedPi
section FinitePi
-- Now for finite products
variable {η : Type*} {Gs : η → Type*} [∀ i, Group (Gs i)]
theorem lowerCentralSeries_pi_of_finite [Finite η] (n : ℕ) :
lowerCentralSeries (∀ i, Gs i) n = Subgroup.pi Set.univ
fun i => lowerCentralSeries (Gs i) n := by
let pi := fun f : ∀ i, Subgroup (Gs i) => Subgroup.pi Set.univ f
induction' n with n ih
· simp [pi_top]
· calc
lowerCentralSeries (∀ i, Gs i) n.succ = ⁅lowerCentralSeries (∀ i, Gs i) n, ⊤⁆ := rfl
_ = ⁅pi fun i => lowerCentralSeries (Gs i) n, ⊤⁆ := by rw [ih]
_ = ⁅pi fun i => lowerCentralSeries (Gs i) n, pi fun i => ⊤⁆ := by simp [pi, pi_top]
_ = pi fun i => ⁅lowerCentralSeries (Gs i) n, ⊤⁆ := commutator_pi_pi_of_finite _ _
_ = pi fun i => lowerCentralSeries (Gs i) n.succ := rfl
/-- n-ary products of nilpotent groups are nilpotent -/
instance isNilpotent_pi [Finite η] [∀ i, IsNilpotent (Gs i)] : IsNilpotent (∀ i, Gs i) := by
cases nonempty_fintype η
rw [nilpotent_iff_lowerCentralSeries]
refine ⟨Finset.univ.sup fun i => Group.nilpotencyClass (Gs i), ?_⟩
rw [lowerCentralSeries_pi_of_finite, pi_eq_bot_iff]
intro i
rw [lowerCentralSeries_eq_bot_iff_nilpotencyClass_le]
exact Finset.le_sup (f := fun i => Group.nilpotencyClass (Gs i)) (Finset.mem_univ i)
/-- The nilpotency class of an n-ary product is the sup of the nilpotency classes of the factors -/
theorem nilpotencyClass_pi [Fintype η] [∀ i, IsNilpotent (Gs i)] :
Group.nilpotencyClass (∀ i, Gs i) = Finset.univ.sup fun i => Group.nilpotencyClass (Gs i) := by
apply eq_of_forall_ge_iff
intro k
simp only [Finset.sup_le_iff, ← lowerCentralSeries_eq_bot_iff_nilpotencyClass_le,
lowerCentralSeries_pi_of_finite, pi_eq_bot_iff, Finset.mem_univ, true_imp_iff]
end FinitePi
/-- A nilpotent subgroup is solvable -/
instance (priority := 100) IsNilpotent.to_isSolvable [h : IsNilpotent G] : IsSolvable G := by
obtain ⟨n, hn⟩ := nilpotent_iff_lowerCentralSeries.1 h
use n
rw [eq_bot_iff, ← hn]
exact derived_le_lower_central n
theorem normalizerCondition_of_isNilpotent [h : IsNilpotent G] : NormalizerCondition G := by
-- roughly based on https://groupprops.subwiki.org/wiki/Nilpotent_implies_normalizer_condition
rw [normalizerCondition_iff_only_full_group_self_normalizing]
apply @nilpotent_center_quotient_ind _ G _ _ <;> clear! G
· intro G _ _ H _
exact @Subsingleton.elim _ Unique.instSubsingleton _ _
· intro G _ _ ih H hH
have hch : center G ≤ H := Subgroup.center_le_normalizer.trans (le_of_eq hH)
have hkh : (mk' (center G)).ker ≤ H := by simpa using hch
have hsur : Function.Surjective (mk' (center G)) := Quot.mk_surjective
let H' := H.map (mk' (center G))
have hH' : H'.normalizer = H' := by
apply comap_injective hsur
rw [comap_normalizer_eq_of_surjective _ hsur, comap_map_eq_self hkh]
exact hH
apply map_injective_of_ker_le (mk' (center G)) hkh le_top
exact (ih H' hH').trans (symm (map_top_of_surjective _ hsur))
end WithGroup
section WithFiniteGroup
open Group Fintype
variable {G : Type*} [hG : Group G]
/-- A p-group is nilpotent -/
| Mathlib/GroupTheory/Nilpotent.lean | 805 | 810 | theorem IsPGroup.isNilpotent [Finite G] {p : ℕ} [hp : Fact (Nat.Prime p)] (h : IsPGroup p G) :
IsNilpotent G := by | cases nonempty_fintype G
classical
revert hG
apply @Fintype.induction_subsingleton_or_nontrivial _ G _ |
/-
Copyright (c) 2023 Jireh Loreaux. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jireh Loreaux
-/
import Mathlib.Algebra.Star.Basic
import Mathlib.Algebra.Star.Pointwise
import Mathlib.Algebra.Group.Center
/-! # `Set.center`, `Set.centralizer` and the `star` operation -/
variable {R : Type*} [Mul R] [StarMul R] {a : R} {s : Set R}
theorem Set.star_mem_center (ha : a ∈ Set.center R) : star a ∈ Set.center R where
comm := by simpa only [star_mul, star_star] using fun g =>
congr_arg star ((mem_center_iff.1 ha).comm <| star g).symm
left_assoc b c := calc
star a * (b * c) = star a * (star (star b) * star (star c)) := by rw [star_star, star_star]
_ = star a * star (star c * star b) := by rw [star_mul]
_ = star ((star c * star b) * a) := by rw [← star_mul]
_ = star (star c * (star b * a)) := by rw [ha.right_assoc]
_ = star (star b * a) * c := by rw [star_mul, star_star]
_ = (star a * b) * c := by rw [star_mul, star_star]
mid_assoc b c := calc
b * star a * c = star (star c * star (b * star a)) := by rw [← star_mul, star_star]
_ = star (star c * (a * star b)) := by rw [star_mul b, star_star]
_ = star ((star c * a) * star b) := by rw [ha.mid_assoc]
_ = b * (star a * c) := by rw [star_mul, star_star, star_mul (star c), star_star]
right_assoc b c := calc
b * c * star a = star (a * star (b * c)) := by rw [star_mul, star_star]
_ = star (a * (star c * star b)) := by rw [star_mul b]
_ = star ((a * star c) * star b) := by rw [ha.left_assoc]
_ = b * star (a * star c) := by rw [star_mul, star_star]
_ = b * (c * star a) := by rw [star_mul, star_star]
| Mathlib/Algebra/Star/Center.lean | 36 | 37 | theorem Set.star_centralizer : star s.centralizer = (star s).centralizer := by | simp_rw [centralizer, ← commute_iff_eq] |
/-
Copyright (c) 2023 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Analysis.Calculus.LineDeriv.Basic
import Mathlib.Analysis.Calculus.FDeriv.Measurable
/-! # Measurability of the line derivative
We prove in `measurable_lineDeriv` that the line derivative of a function (with respect to a
locally compact scalar field) is measurable, provided the function is continuous.
In `measurable_lineDeriv_uncurry`, assuming additionally that the source space is second countable,
we show that `(x, v) ↦ lineDeriv 𝕜 f x v` is also measurable.
An assumption such as continuity is necessary, as otherwise one could alternate in a non-measurable
way between differentiable and non-differentiable functions along the various lines
directed by `v`.
-/
open MeasureTheory
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] [LocallyCompactSpace 𝕜]
{E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] [MeasurableSpace E] [OpensMeasurableSpace E]
{F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] [CompleteSpace F]
{f : E → F} {v : E}
/-!
Measurability of the line derivative `lineDeriv 𝕜 f x v` with respect to a fixed direction `v`.
-/
theorem measurableSet_lineDifferentiableAt (hf : Continuous f) :
MeasurableSet {x : E | LineDifferentiableAt 𝕜 f x v} := by
borelize 𝕜
let g : E → 𝕜 → F := fun x t ↦ f (x + t • v)
have hg : Continuous g.uncurry := by fun_prop
exact measurable_prodMk_right (measurableSet_of_differentiableAt_with_param 𝕜 hg)
theorem measurable_lineDeriv [MeasurableSpace F] [BorelSpace F]
(hf : Continuous f) : Measurable (fun x ↦ lineDeriv 𝕜 f x v) := by
borelize 𝕜
let g : E → 𝕜 → F := fun x t ↦ f (x + t • v)
have hg : Continuous g.uncurry := by fun_prop
exact (measurable_deriv_with_param hg).comp measurable_prodMk_right
| Mathlib/Analysis/Calculus/LineDeriv/Measurable.lean | 47 | 52 | theorem stronglyMeasurable_lineDeriv [SecondCountableTopologyEither E F] (hf : Continuous f) :
StronglyMeasurable (fun x ↦ lineDeriv 𝕜 f x v) := by | borelize 𝕜
let g : E → 𝕜 → F := fun x t ↦ f (x + t • v)
have hg : Continuous g.uncurry := by fun_prop
exact (stronglyMeasurable_deriv_with_param hg).comp_measurable measurable_prodMk_right |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir
-/
import Mathlib.Algebra.CharP.Defs
import Mathlib.Algebra.Order.CauSeq.BigOperators
import Mathlib.Algebra.Order.Star.Basic
import Mathlib.Data.Complex.BigOperators
import Mathlib.Data.Complex.Norm
import Mathlib.Data.Nat.Choose.Sum
/-!
# Exponential Function
This file contains the definitions of the real and complex exponential function.
## Main definitions
* `Complex.exp`: The complex exponential function, defined via its Taylor series
* `Real.exp`: The real exponential function, defined as the real part of the complex exponential
-/
open CauSeq Finset IsAbsoluteValue
open scoped ComplexConjugate
namespace Complex
theorem isCauSeq_norm_exp (z : ℂ) :
IsCauSeq abs fun n => ∑ m ∈ range n, ‖z ^ m / m.factorial‖ :=
let ⟨n, hn⟩ := exists_nat_gt ‖z‖
have hn0 : (0 : ℝ) < n := lt_of_le_of_lt (norm_nonneg _) hn
IsCauSeq.series_ratio_test n (‖z‖ / n) (div_nonneg (norm_nonneg _) (le_of_lt hn0))
(by rwa [div_lt_iff₀ hn0, one_mul]) fun m hm => by
rw [abs_norm, abs_norm, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul,
← div_div, mul_div_assoc, mul_div_right_comm, Complex.norm_mul, Complex.norm_div,
norm_natCast]
gcongr
exact le_trans hm (Nat.le_succ _)
@[deprecated (since := "2025-02-16")] alias isCauSeq_abs_exp := isCauSeq_norm_exp
noncomputable section
theorem isCauSeq_exp (z : ℂ) : IsCauSeq (‖·‖) fun n => ∑ m ∈ range n, z ^ m / m.factorial :=
(isCauSeq_norm_exp z).of_abv
/-- The Cauchy sequence consisting of partial sums of the Taylor series of
the complex exponential function -/
@[pp_nodot]
def exp' (z : ℂ) : CauSeq ℂ (‖·‖) :=
⟨fun n => ∑ m ∈ range n, z ^ m / m.factorial, isCauSeq_exp z⟩
/-- The complex exponential function, defined via its Taylor series -/
@[pp_nodot]
def exp (z : ℂ) : ℂ :=
CauSeq.lim (exp' z)
/-- scoped notation for the complex exponential function -/
scoped notation "cexp" => Complex.exp
end
end Complex
namespace Real
open Complex
noncomputable section
/-- The real exponential function, defined as the real part of the complex exponential -/
@[pp_nodot]
nonrec def exp (x : ℝ) : ℝ :=
(exp x).re
/-- scoped notation for the real exponential function -/
scoped notation "rexp" => Real.exp
end
end Real
namespace Complex
variable (x y : ℂ)
@[simp]
theorem exp_zero : exp 0 = 1 := by
rw [exp]
refine lim_eq_of_equiv_const fun ε ε0 => ⟨1, fun j hj => ?_⟩
convert (config := .unfoldSameFun) ε0 -- ε0 : ε > 0 but goal is _ < ε
rcases j with - | j
· exact absurd hj (not_le_of_gt zero_lt_one)
· dsimp [exp']
induction' j with j ih
· dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl]
· rw [← ih (by simp [Nat.succ_le_succ])]
simp only [sum_range_succ, pow_succ]
simp
theorem exp_add : exp (x + y) = exp x * exp y := by
have hj : ∀ j : ℕ, (∑ m ∈ range j, (x + y) ^ m / m.factorial) =
∑ i ∈ range j, ∑ k ∈ range (i + 1), x ^ k / k.factorial *
(y ^ (i - k) / (i - k).factorial) := by
intro j
refine Finset.sum_congr rfl fun m _ => ?_
rw [add_pow, div_eq_mul_inv, sum_mul]
refine Finset.sum_congr rfl fun I hi => ?_
have h₁ : (m.choose I : ℂ) ≠ 0 :=
Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi))))
have h₂ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi)
rw [← h₂, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv]
simp only [mul_left_comm (m.choose I : ℂ), mul_assoc, mul_left_comm (m.choose I : ℂ)⁻¹,
mul_comm (m.choose I : ℂ)]
rw [inv_mul_cancel₀ h₁]
simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm]
simp_rw [exp, exp', lim_mul_lim]
apply (lim_eq_lim_of_equiv _).symm
simp only [hj]
exact cauchy_product (isCauSeq_norm_exp x) (isCauSeq_exp y)
/-- the exponential function as a monoid hom from `Multiplicative ℂ` to `ℂ` -/
@[simps]
noncomputable def expMonoidHom : MonoidHom (Multiplicative ℂ) ℂ :=
{ toFun := fun z => exp z.toAdd,
map_one' := by simp,
map_mul' := by simp [exp_add] }
theorem exp_list_sum (l : List ℂ) : exp l.sum = (l.map exp).prod :=
map_list_prod (M := Multiplicative ℂ) expMonoidHom l
theorem exp_multiset_sum (s : Multiset ℂ) : exp s.sum = (s.map exp).prod :=
@MonoidHom.map_multiset_prod (Multiplicative ℂ) ℂ _ _ expMonoidHom s
theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℂ) :
exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) :=
map_prod (β := Multiplicative ℂ) expMonoidHom f s
lemma exp_nsmul (x : ℂ) (n : ℕ) : exp (n • x) = exp x ^ n :=
@MonoidHom.map_pow (Multiplicative ℂ) ℂ _ _ expMonoidHom _ _
theorem exp_nat_mul (x : ℂ) : ∀ n : ℕ, exp (n * x) = exp x ^ n
| 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero]
| Nat.succ n => by rw [pow_succ, Nat.cast_add_one, add_mul, exp_add, ← exp_nat_mul _ n, one_mul]
@[simp]
theorem exp_ne_zero : exp x ≠ 0 := fun h =>
zero_ne_one (α := ℂ) <| by rw [← exp_zero, ← add_neg_cancel x, exp_add, h]; simp
theorem exp_neg : exp (-x) = (exp x)⁻¹ := by
rw [← mul_right_inj' (exp_ne_zero x), ← exp_add]; simp [mul_inv_cancel₀ (exp_ne_zero x)]
theorem exp_sub : exp (x - y) = exp x / exp y := by
simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv]
theorem exp_int_mul (z : ℂ) (n : ℤ) : Complex.exp (n * z) = Complex.exp z ^ n := by
cases n
· simp [exp_nat_mul]
· simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul]
@[simp]
theorem exp_conj : exp (conj x) = conj (exp x) := by
dsimp [exp]
rw [← lim_conj]
refine congr_arg CauSeq.lim (CauSeq.ext fun _ => ?_)
dsimp [exp', Function.comp_def, cauSeqConj]
rw [map_sum (starRingEnd _)]
refine sum_congr rfl fun n _ => ?_
rw [map_div₀, map_pow, ← ofReal_natCast, conj_ofReal]
@[simp]
theorem ofReal_exp_ofReal_re (x : ℝ) : ((exp x).re : ℂ) = exp x :=
conj_eq_iff_re.1 <| by rw [← exp_conj, conj_ofReal]
@[simp, norm_cast]
theorem ofReal_exp (x : ℝ) : (Real.exp x : ℂ) = exp x :=
ofReal_exp_ofReal_re _
@[simp]
theorem exp_ofReal_im (x : ℝ) : (exp x).im = 0 := by rw [← ofReal_exp_ofReal_re, ofReal_im]
theorem exp_ofReal_re (x : ℝ) : (exp x).re = Real.exp x :=
rfl
end Complex
namespace Real
open Complex
variable (x y : ℝ)
@[simp]
theorem exp_zero : exp 0 = 1 := by simp [Real.exp]
nonrec theorem exp_add : exp (x + y) = exp x * exp y := by simp [exp_add, exp]
/-- the exponential function as a monoid hom from `Multiplicative ℝ` to `ℝ` -/
@[simps]
noncomputable def expMonoidHom : MonoidHom (Multiplicative ℝ) ℝ :=
{ toFun := fun x => exp x.toAdd,
map_one' := by simp,
map_mul' := by simp [exp_add] }
theorem exp_list_sum (l : List ℝ) : exp l.sum = (l.map exp).prod :=
map_list_prod (M := Multiplicative ℝ) expMonoidHom l
theorem exp_multiset_sum (s : Multiset ℝ) : exp s.sum = (s.map exp).prod :=
@MonoidHom.map_multiset_prod (Multiplicative ℝ) ℝ _ _ expMonoidHom s
theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℝ) :
exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) :=
map_prod (β := Multiplicative ℝ) expMonoidHom f s
lemma exp_nsmul (x : ℝ) (n : ℕ) : exp (n • x) = exp x ^ n :=
@MonoidHom.map_pow (Multiplicative ℝ) ℝ _ _ expMonoidHom _ _
nonrec theorem exp_nat_mul (x : ℝ) (n : ℕ) : exp (n * x) = exp x ^ n :=
ofReal_injective (by simp [exp_nat_mul])
@[simp]
nonrec theorem exp_ne_zero : exp x ≠ 0 := fun h =>
exp_ne_zero x <| by rw [exp, ← ofReal_inj] at h; simp_all
nonrec theorem exp_neg : exp (-x) = (exp x)⁻¹ :=
ofReal_injective <| by simp [exp_neg]
theorem exp_sub : exp (x - y) = exp x / exp y := by
simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv]
open IsAbsoluteValue Nat
theorem sum_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) (n : ℕ) : ∑ i ∈ range n, x ^ i / i ! ≤ exp x :=
calc
∑ i ∈ range n, x ^ i / i ! ≤ lim (⟨_, isCauSeq_re (exp' x)⟩ : CauSeq ℝ abs) := by
refine le_lim (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp only [exp', const_apply, re_sum]
norm_cast
refine sum_le_sum_of_subset_of_nonneg (range_mono hj) fun _ _ _ ↦ ?_
positivity
_ = exp x := by rw [exp, Complex.exp, ← cauSeqRe, lim_re]
lemma pow_div_factorial_le_exp (hx : 0 ≤ x) (n : ℕ) : x ^ n / n ! ≤ exp x :=
calc
x ^ n / n ! ≤ ∑ k ∈ range (n + 1), x ^ k / k ! :=
single_le_sum (f := fun k ↦ x ^ k / k !) (fun k _ ↦ by positivity) (self_mem_range_succ n)
_ ≤ exp x := sum_le_exp_of_nonneg hx _
theorem quadratic_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : 1 + x + x ^ 2 / 2 ≤ exp x :=
calc
1 + x + x ^ 2 / 2 = ∑ i ∈ range 3, x ^ i / i ! := by
simp only [sum_range_succ, range_one, sum_singleton, _root_.pow_zero, factorial, cast_one,
ne_eq, one_ne_zero, not_false_eq_true, div_self, pow_one, mul_one, div_one, Nat.mul_one,
cast_succ, add_right_inj]
ring_nf
_ ≤ exp x := sum_le_exp_of_nonneg hx 3
private theorem add_one_lt_exp_of_pos {x : ℝ} (hx : 0 < x) : x + 1 < exp x :=
(by nlinarith : x + 1 < 1 + x + x ^ 2 / 2).trans_le (quadratic_le_exp_of_nonneg hx.le)
private theorem add_one_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : x + 1 ≤ exp x := by
rcases eq_or_lt_of_le hx with (rfl | h)
· simp
exact (add_one_lt_exp_of_pos h).le
theorem one_le_exp {x : ℝ} (hx : 0 ≤ x) : 1 ≤ exp x := by linarith [add_one_le_exp_of_nonneg hx]
@[bound]
theorem exp_pos (x : ℝ) : 0 < exp x :=
(le_total 0 x).elim (lt_of_lt_of_le zero_lt_one ∘ one_le_exp) fun h => by
rw [← neg_neg x, Real.exp_neg]
exact inv_pos.2 (lt_of_lt_of_le zero_lt_one (one_le_exp (neg_nonneg.2 h)))
@[bound]
lemma exp_nonneg (x : ℝ) : 0 ≤ exp x := x.exp_pos.le
@[simp]
theorem abs_exp (x : ℝ) : |exp x| = exp x :=
abs_of_pos (exp_pos _)
lemma exp_abs_le (x : ℝ) : exp |x| ≤ exp x + exp (-x) := by
cases le_total x 0 <;> simp [abs_of_nonpos, abs_of_nonneg, exp_nonneg, *]
@[mono]
theorem exp_strictMono : StrictMono exp := fun x y h => by
rw [← sub_add_cancel y x, Real.exp_add]
exact (lt_mul_iff_one_lt_left (exp_pos _)).2
(lt_of_lt_of_le (by linarith) (add_one_le_exp_of_nonneg (by linarith)))
@[gcongr]
theorem exp_lt_exp_of_lt {x y : ℝ} (h : x < y) : exp x < exp y := exp_strictMono h
@[mono]
theorem exp_monotone : Monotone exp :=
exp_strictMono.monotone
@[gcongr, bound]
theorem exp_le_exp_of_le {x y : ℝ} (h : x ≤ y) : exp x ≤ exp y := exp_monotone h
@[simp]
theorem exp_lt_exp {x y : ℝ} : exp x < exp y ↔ x < y :=
exp_strictMono.lt_iff_lt
@[simp]
theorem exp_le_exp {x y : ℝ} : exp x ≤ exp y ↔ x ≤ y :=
exp_strictMono.le_iff_le
theorem exp_injective : Function.Injective exp :=
exp_strictMono.injective
@[simp]
theorem exp_eq_exp {x y : ℝ} : exp x = exp y ↔ x = y :=
exp_injective.eq_iff
@[simp]
theorem exp_eq_one_iff : exp x = 1 ↔ x = 0 :=
exp_injective.eq_iff' exp_zero
@[simp]
theorem one_lt_exp_iff {x : ℝ} : 1 < exp x ↔ 0 < x := by rw [← exp_zero, exp_lt_exp]
@[bound] private alias ⟨_, Bound.one_lt_exp_of_pos⟩ := one_lt_exp_iff
@[simp]
theorem exp_lt_one_iff {x : ℝ} : exp x < 1 ↔ x < 0 := by rw [← exp_zero, exp_lt_exp]
@[simp]
theorem exp_le_one_iff {x : ℝ} : exp x ≤ 1 ↔ x ≤ 0 :=
exp_zero ▸ exp_le_exp
@[simp]
theorem one_le_exp_iff {x : ℝ} : 1 ≤ exp x ↔ 0 ≤ x :=
exp_zero ▸ exp_le_exp
end Real
namespace Complex
theorem sum_div_factorial_le {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α]
(n j : ℕ) (hn : 0 < n) :
(∑ m ∈ range j with n ≤ m, (1 / m.factorial : α)) ≤ n.succ / (n.factorial * n) :=
calc
(∑ m ∈ range j with n ≤ m, (1 / m.factorial : α)) =
∑ m ∈ range (j - n), (1 / ((m + n).factorial : α)) := by
refine sum_nbij' (· - n) (· + n) ?_ ?_ ?_ ?_ ?_ <;>
simp +contextual [lt_tsub_iff_right, tsub_add_cancel_of_le]
_ ≤ ∑ m ∈ range (j - n), ((n.factorial : α) * (n.succ : α) ^ m)⁻¹ := by
simp_rw [one_div]
gcongr
rw [← Nat.cast_pow, ← Nat.cast_mul, Nat.cast_le, add_comm]
exact Nat.factorial_mul_pow_le_factorial
_ = (n.factorial : α)⁻¹ * ∑ m ∈ range (j - n), (n.succ : α)⁻¹ ^ m := by
simp [mul_inv, ← mul_sum, ← sum_mul, mul_comm, inv_pow]
_ = ((n.succ : α) - n.succ * (n.succ : α)⁻¹ ^ (j - n)) / (n.factorial * n) := by
have h₁ : (n.succ : α) ≠ 1 :=
@Nat.cast_one α _ ▸ mt Nat.cast_inj.1 (mt Nat.succ.inj (pos_iff_ne_zero.1 hn))
have h₂ : (n.succ : α) ≠ 0 := by positivity
have h₃ : (n.factorial * n : α) ≠ 0 := by positivity
have h₄ : (n.succ - 1 : α) = n := by simp
rw [geom_sum_inv h₁ h₂, eq_div_iff_mul_eq h₃, mul_comm _ (n.factorial * n : α),
← mul_assoc (n.factorial⁻¹ : α), ← mul_inv_rev, h₄, ← mul_assoc (n.factorial * n : α),
mul_comm (n : α) n.factorial, mul_inv_cancel₀ h₃, one_mul, mul_comm]
_ ≤ n.succ / (n.factorial * n : α) := by gcongr; apply sub_le_self; positivity
theorem exp_bound {x : ℂ} (hx : ‖x‖ ≤ 1) {n : ℕ} (hn : 0 < n) :
‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤
‖x‖ ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹) := by
rw [← lim_const (abv := norm) (∑ m ∈ range n, _), exp, sub_eq_add_neg,
← lim_neg, lim_add, ← lim_norm]
refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp_rw [← sub_eq_add_neg]
show
‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤
‖x‖ ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹)
rw [sum_range_sub_sum_range hj]
calc
‖∑ m ∈ range j with n ≤ m, (x ^ m / m.factorial : ℂ)‖
= ‖∑ m ∈ range j with n ≤ m, (x ^ n * (x ^ (m - n) / m.factorial) : ℂ)‖ := by
refine congr_arg norm (sum_congr rfl fun m hm => ?_)
rw [mem_filter, mem_range] at hm
rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2]
_ ≤ ∑ m ∈ range j with n ≤ m, ‖x ^ n * (x ^ (m - n) / m.factorial)‖ :=
IsAbsoluteValue.abv_sum norm ..
_ ≤ ∑ m ∈ range j with n ≤ m, ‖x‖ ^ n * (1 / m.factorial) := by
simp_rw [Complex.norm_mul, Complex.norm_pow, Complex.norm_div, norm_natCast]
gcongr
rw [Complex.norm_pow]
exact pow_le_one₀ (norm_nonneg _) hx
_ = ‖x‖ ^ n * ∑ m ∈ range j with n ≤ m, (1 / m.factorial : ℝ) := by
simp [abs_mul, abv_pow abs, abs_div, ← mul_sum]
_ ≤ ‖x‖ ^ n * (n.succ * (n.factorial * n : ℝ)⁻¹) := by
gcongr
exact sum_div_factorial_le _ _ hn
theorem exp_bound' {x : ℂ} {n : ℕ} (hx : ‖x‖ / n.succ ≤ 1 / 2) :
‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n / n.factorial * 2 := by
rw [← lim_const (abv := norm) (∑ m ∈ range n, _),
exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_norm]
refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp_rw [← sub_eq_add_neg]
show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤
‖x‖ ^ n / n.factorial * 2
let k := j - n
have hj : j = n + k := (add_tsub_cancel_of_le hj).symm
rw [hj, sum_range_add_sub_sum_range]
calc
‖∑ i ∈ range k, x ^ (n + i) / ((n + i).factorial : ℂ)‖ ≤
∑ i ∈ range k, ‖x ^ (n + i) / ((n + i).factorial : ℂ)‖ :=
IsAbsoluteValue.abv_sum _ _ _
_ ≤ ∑ i ∈ range k, ‖x‖ ^ (n + i) / (n + i).factorial := by
simp [norm_natCast, Complex.norm_pow]
_ ≤ ∑ i ∈ range k, ‖x‖ ^ (n + i) / ((n.factorial : ℝ) * (n.succ : ℝ) ^ i) := ?_
_ = ∑ i ∈ range k, ‖x‖ ^ n / n.factorial * (‖x‖ ^ i / (n.succ : ℝ) ^ i) := ?_
_ ≤ ‖x‖ ^ n / ↑n.factorial * 2 := ?_
· gcongr
exact mod_cast Nat.factorial_mul_pow_le_factorial
· refine Finset.sum_congr rfl fun _ _ => ?_
simp only [pow_add, div_eq_inv_mul, mul_inv, mul_left_comm, mul_assoc]
· rw [← mul_sum]
gcongr
simp_rw [← div_pow]
rw [geom_sum_eq, div_le_iff_of_neg]
· trans (-1 : ℝ)
· linarith
· simp only [neg_le_sub_iff_le_add, div_pow, Nat.cast_succ, le_add_iff_nonneg_left]
positivity
· linarith
· linarith
theorem norm_exp_sub_one_le {x : ℂ} (hx : ‖x‖ ≤ 1) : ‖exp x - 1‖ ≤ 2 * ‖x‖ :=
calc
‖exp x - 1‖ = ‖exp x - ∑ m ∈ range 1, x ^ m / m.factorial‖ := by simp [sum_range_succ]
_ ≤ ‖x‖ ^ 1 * ((Nat.succ 1 : ℝ) * ((Nat.factorial 1) * (1 : ℕ) : ℝ)⁻¹) :=
(exp_bound hx (by decide))
_ = 2 * ‖x‖ := by simp [two_mul, mul_two, mul_add, mul_comm, add_mul, Nat.factorial]
theorem norm_exp_sub_one_sub_id_le {x : ℂ} (hx : ‖x‖ ≤ 1) : ‖exp x - 1 - x‖ ≤ ‖x‖ ^ 2 :=
calc
‖exp x - 1 - x‖ = ‖exp x - ∑ m ∈ range 2, x ^ m / m.factorial‖ := by
simp [sub_eq_add_neg, sum_range_succ_comm, add_assoc, Nat.factorial]
_ ≤ ‖x‖ ^ 2 * ((Nat.succ 2 : ℝ) * (Nat.factorial 2 * (2 : ℕ) : ℝ)⁻¹) :=
(exp_bound hx (by decide))
_ ≤ ‖x‖ ^ 2 * 1 := by gcongr; norm_num [Nat.factorial]
_ = ‖x‖ ^ 2 := by rw [mul_one]
lemma norm_exp_sub_sum_le_exp_norm_sub_sum (x : ℂ) (n : ℕ) :
‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖
≤ Real.exp ‖x‖ - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by
rw [← CauSeq.lim_const (abv := norm) (∑ m ∈ range n, _), Complex.exp, sub_eq_add_neg,
← CauSeq.lim_neg, CauSeq.lim_add, ← lim_norm]
refine CauSeq.lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp_rw [← sub_eq_add_neg]
calc ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖
_ ≤ (∑ m ∈ range j, ‖x‖ ^ m / m.factorial) - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by
rw [sum_range_sub_sum_range hj, sum_range_sub_sum_range hj]
refine (IsAbsoluteValue.abv_sum norm ..).trans_eq ?_
congr with i
simp [Complex.norm_pow]
_ ≤ Real.exp ‖x‖ - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by
gcongr
exact Real.sum_le_exp_of_nonneg (norm_nonneg _) _
lemma norm_exp_le_exp_norm (x : ℂ) : ‖exp x‖ ≤ Real.exp ‖x‖ := by
convert norm_exp_sub_sum_le_exp_norm_sub_sum x 0 using 1 <;> simp
lemma norm_exp_sub_sum_le_norm_mul_exp (x : ℂ) (n : ℕ) :
‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n * Real.exp ‖x‖ := by
rw [← CauSeq.lim_const (abv := norm) (∑ m ∈ range n, _), Complex.exp, sub_eq_add_neg,
← CauSeq.lim_neg, CauSeq.lim_add, ← lim_norm]
refine CauSeq.lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩)
simp_rw [← sub_eq_add_neg]
show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ _
rw [sum_range_sub_sum_range hj]
calc
‖∑ m ∈ range j with n ≤ m, (x ^ m / m.factorial : ℂ)‖
= ‖∑ m ∈ range j with n ≤ m, (x ^ n * (x ^ (m - n) / m.factorial) : ℂ)‖ := by
refine congr_arg norm (sum_congr rfl fun m hm => ?_)
rw [mem_filter, mem_range] at hm
rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2]
_ ≤ ∑ m ∈ range j with n ≤ m, ‖x ^ n * (x ^ (m - n) / m.factorial)‖ :=
IsAbsoluteValue.abv_sum norm ..
_ ≤ ∑ m ∈ range j with n ≤ m, ‖x‖ ^ n * (‖x‖ ^ (m - n) / (m - n).factorial) := by
simp_rw [Complex.norm_mul, Complex.norm_pow, Complex.norm_div, norm_natCast]
gcongr with i hi
· rw [Complex.norm_pow]
· simp
_ = ‖x‖ ^ n * ∑ m ∈ range j with n ≤ m, (‖x‖ ^ (m - n) / (m - n).factorial) := by
rw [← mul_sum]
_ = ‖x‖ ^ n * ∑ m ∈ range (j - n), (‖x‖ ^ m / m.factorial) := by
congr 1
refine (sum_bij (fun m hm ↦ m + n) ?_ ?_ ?_ ?_).symm
· intro a ha
simp only [mem_filter, mem_range, le_add_iff_nonneg_left, zero_le, and_true]
simp only [mem_range] at ha
rwa [← lt_tsub_iff_right]
· intro a ha b hb hab
simpa using hab
· intro b hb
simp only [mem_range, exists_prop]
simp only [mem_filter, mem_range] at hb
refine ⟨b - n, ?_, ?_⟩
· rw [tsub_lt_tsub_iff_right hb.2]
exact hb.1
· rw [tsub_add_cancel_of_le hb.2]
· simp
_ ≤ ‖x‖ ^ n * Real.exp ‖x‖ := by
gcongr
refine Real.sum_le_exp_of_nonneg ?_ _
exact norm_nonneg _
@[deprecated (since := "2025-02-16")] alias abs_exp_sub_one_le := norm_exp_sub_one_le
@[deprecated (since := "2025-02-16")] alias abs_exp_sub_one_sub_id_le := norm_exp_sub_one_sub_id_le
@[deprecated (since := "2025-02-16")] alias abs_exp_sub_sum_le_exp_abs_sub_sum :=
norm_exp_sub_sum_le_exp_norm_sub_sum
@[deprecated (since := "2025-02-16")] alias abs_exp_le_exp_abs := norm_exp_le_exp_norm
@[deprecated (since := "2025-02-16")] alias abs_exp_sub_sum_le_abs_mul_exp :=
norm_exp_sub_sum_le_norm_mul_exp
end Complex
namespace Real
open Complex Finset
nonrec theorem exp_bound {x : ℝ} (hx : |x| ≤ 1) {n : ℕ} (hn : 0 < n) :
|exp x - ∑ m ∈ range n, x ^ m / m.factorial| ≤ |x| ^ n * (n.succ / (n.factorial * n)) := by
have hxc : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx
convert exp_bound hxc hn using 2 <;>
norm_cast
theorem exp_bound' {x : ℝ} (h1 : 0 ≤ x) (h2 : x ≤ 1) {n : ℕ} (hn : 0 < n) :
Real.exp x ≤ (∑ m ∈ Finset.range n, x ^ m / m.factorial) +
x ^ n * (n + 1) / (n.factorial * n) := by
have h3 : |x| = x := by simpa
have h4 : |x| ≤ 1 := by rwa [h3]
have h' := Real.exp_bound h4 hn
rw [h3] at h'
have h'' := (abs_sub_le_iff.1 h').1
have t := sub_le_iff_le_add'.1 h''
simpa [mul_div_assoc] using t
theorem abs_exp_sub_one_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1| ≤ 2 * |x| := by
have : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx
exact_mod_cast Complex.norm_exp_sub_one_le (x := x) this
theorem abs_exp_sub_one_sub_id_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1 - x| ≤ x ^ 2 := by
rw [← sq_abs]
have : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx
exact_mod_cast Complex.norm_exp_sub_one_sub_id_le this
/-- A finite initial segment of the exponential series, followed by an arbitrary tail.
For fixed `n` this is just a linear map wrt `r`, and each map is a simple linear function
of the previous (see `expNear_succ`), with `expNear n x r ⟶ exp x` as `n ⟶ ∞`,
for any `r`. -/
noncomputable def expNear (n : ℕ) (x r : ℝ) : ℝ :=
(∑ m ∈ range n, x ^ m / m.factorial) + x ^ n / n.factorial * r
@[simp]
theorem expNear_zero (x r) : expNear 0 x r = r := by simp [expNear]
@[simp]
theorem expNear_succ (n x r) : expNear (n + 1) x r = expNear n x (1 + x / (n + 1) * r) := by
simp [expNear, range_succ, mul_add, add_left_comm, add_assoc, pow_succ, div_eq_mul_inv,
mul_inv, Nat.factorial]
ac_rfl
theorem expNear_sub (n x r₁ r₂) : expNear n x r₁ -
expNear n x r₂ = x ^ n / n.factorial * (r₁ - r₂) := by
simp [expNear, mul_sub]
theorem exp_approx_end (n m : ℕ) (x : ℝ) (e₁ : n + 1 = m) (h : |x| ≤ 1) :
|exp x - expNear m x 0| ≤ |x| ^ m / m.factorial * ((m + 1) / m) := by
simp only [expNear, mul_zero, add_zero]
convert exp_bound (n := m) h ?_ using 1
· field_simp [mul_comm]
· omega
theorem exp_approx_succ {n} {x a₁ b₁ : ℝ} (m : ℕ) (e₁ : n + 1 = m) (a₂ b₂ : ℝ)
(e : |1 + x / m * a₂ - a₁| ≤ b₁ - |x| / m * b₂)
(h : |exp x - expNear m x a₂| ≤ |x| ^ m / m.factorial * b₂) :
|exp x - expNear n x a₁| ≤ |x| ^ n / n.factorial * b₁ := by
refine (abs_sub_le _ _ _).trans ((add_le_add_right h _).trans ?_)
subst e₁; rw [expNear_succ, expNear_sub, abs_mul]
convert mul_le_mul_of_nonneg_left (a := |x| ^ n / ↑(Nat.factorial n))
(le_sub_iff_add_le'.1 e) ?_ using 1
· simp [mul_add, pow_succ', div_eq_mul_inv, abs_mul, abs_inv, ← pow_abs, mul_inv, Nat.factorial]
ac_rfl
· simp [div_nonneg, abs_nonneg]
| Mathlib/Data/Complex/Exponential.lean | 593 | 599 | theorem exp_approx_end' {n} {x a b : ℝ} (m : ℕ) (e₁ : n + 1 = m) (rm : ℝ) (er : ↑m = rm)
(h : |x| ≤ 1) (e : |1 - a| ≤ b - |x| / rm * ((rm + 1) / rm)) :
|exp x - expNear n x a| ≤ |x| ^ n / n.factorial * b := by | subst er
exact exp_approx_succ _ e₁ _ _ (by simpa using e) (exp_approx_end _ _ _ e₁ h)
theorem exp_1_approx_succ_eq {n} {a₁ b₁ : ℝ} {m : ℕ} (en : n + 1 = m) {rm : ℝ} (er : ↑m = rm) |
/-
Copyright (c) 2022 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.CategoryTheory.Comma.Over.Pullback
import Mathlib.CategoryTheory.Limits.Shapes.KernelPair
import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq
import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Assoc
/-!
# The diagonal object of a morphism.
We provide various API and isomorphisms considering the diagonal object `Δ_{Y/X} := pullback f f`
of a morphism `f : X ⟶ Y`.
-/
open CategoryTheory
noncomputable section
namespace CategoryTheory.Limits
variable {C : Type*} [Category C] {X Y Z : C}
namespace pullback
section Diagonal
variable (f : X ⟶ Y) [HasPullback f f]
/-- The diagonal object of a morphism `f : X ⟶ Y` is `Δ_{X/Y} := pullback f f`. -/
abbrev diagonalObj : C :=
pullback f f
/-- The diagonal morphism `X ⟶ Δ_{X/Y}` for a morphism `f : X ⟶ Y`. -/
def diagonal : X ⟶ diagonalObj f :=
pullback.lift (𝟙 _) (𝟙 _) rfl
@[reassoc (attr := simp)]
theorem diagonal_fst : diagonal f ≫ pullback.fst _ _ = 𝟙 _ :=
pullback.lift_fst _ _ _
@[reassoc (attr := simp)]
theorem diagonal_snd : diagonal f ≫ pullback.snd _ _ = 𝟙 _ :=
pullback.lift_snd _ _ _
instance : IsSplitMono (diagonal f) :=
⟨⟨⟨pullback.fst _ _, diagonal_fst f⟩⟩⟩
instance : IsSplitEpi (pullback.fst f f) :=
⟨⟨⟨diagonal f, diagonal_fst f⟩⟩⟩
instance : IsSplitEpi (pullback.snd f f) :=
⟨⟨⟨diagonal f, diagonal_snd f⟩⟩⟩
instance [Mono f] : IsIso (diagonal f) := by
rw [(IsIso.inv_eq_of_inv_hom_id (diagonal_fst f)).symm]
infer_instance
lemma isIso_diagonal_iff : IsIso (diagonal f) ↔ Mono f :=
⟨fun H ↦ ⟨fun _ _ e ↦ by rw [← lift_fst _ _ e, (cancel_epi (g := fst f f) (h := snd f f)
(diagonal f)).mp (by simp), lift_snd]⟩, fun _ ↦ inferInstance⟩
/-- The two projections `Δ_{X/Y} ⟶ X` form a kernel pair for `f : X ⟶ Y`. -/
theorem diagonal_isKernelPair : IsKernelPair f (pullback.fst f f) (pullback.snd f f) :=
IsPullback.of_hasPullback f f
end Diagonal
end pullback
variable [HasPullbacks C]
open pullback
section
variable {U V₁ V₂ : C} (f : X ⟶ Y) (i : U ⟶ Y)
variable (i₁ : V₁ ⟶ pullback f i) (i₂ : V₂ ⟶ pullback f i)
@[reassoc (attr := simp)]
theorem pullback_diagonal_map_snd_fst_fst :
(pullback.snd (diagonal f)
(map (i₁ ≫ snd f i) (i₂ ≫ snd f i) f f (i₁ ≫ fst f i) (i₂ ≫ fst f i) i
(by simp [condition]) (by simp [condition]))) ≫
fst _ _ ≫ i₁ ≫ fst _ _ =
pullback.fst _ _ := by
conv_rhs => rw [← Category.comp_id (pullback.fst _ _)]
rw [← diagonal_fst f, pullback.condition_assoc, pullback.lift_fst]
@[reassoc (attr := simp)]
theorem pullback_diagonal_map_snd_snd_fst :
(pullback.snd (diagonal f)
(map (i₁ ≫ snd f i) (i₂ ≫ snd f i) f f (i₁ ≫ fst f i) (i₂ ≫ fst f i) i
(by simp [condition]) (by simp [condition]))) ≫
snd _ _ ≫ i₂ ≫ fst _ _ =
pullback.fst _ _ := by
conv_rhs => rw [← Category.comp_id (pullback.fst _ _)]
rw [← diagonal_snd f, pullback.condition_assoc, pullback.lift_snd]
variable [HasPullback i₁ i₂]
/-- The underlying map of `pullbackDiagonalIso` -/
abbrev pullbackDiagonalMapIso.hom :
pullback (diagonal f)
(map (i₁ ≫ snd _ _) (i₂ ≫ snd _ _) f f (i₁ ≫ fst _ _) (i₂ ≫ fst _ _) i
(by simp only [Category.assoc, condition])
(by simp only [Category.assoc, condition])) ⟶
pullback i₁ i₂ :=
pullback.lift (pullback.snd _ _ ≫ pullback.fst _ _) (pullback.snd _ _ ≫ pullback.snd _ _) (by
ext
· simp only [Category.assoc, pullback_diagonal_map_snd_fst_fst,
pullback_diagonal_map_snd_snd_fst]
· simp only [Category.assoc, condition])
/-- The underlying inverse of `pullbackDiagonalIso` -/
abbrev pullbackDiagonalMapIso.inv : pullback i₁ i₂ ⟶
pullback (diagonal f)
(map (i₁ ≫ snd _ _) (i₂ ≫ snd _ _) f f (i₁ ≫ fst _ _) (i₂ ≫ fst _ _) i
(by simp only [Category.assoc, condition])
(by simp only [Category.assoc, condition])) :=
pullback.lift (pullback.fst _ _ ≫ i₁ ≫ pullback.fst _ _)
(pullback.map _ _ _ _ (𝟙 _) (𝟙 _) (pullback.snd _ _) (Category.id_comp _).symm
(Category.id_comp _).symm) (by
ext
· simp only [Category.assoc, diagonal_fst, Category.comp_id, limit.lift_π,
PullbackCone.mk_pt, PullbackCone.mk_π_app, limit.lift_π_assoc, cospan_left]
· simp only [condition_assoc, Category.assoc, diagonal_snd, Category.comp_id, limit.lift_π,
PullbackCone.mk_pt, PullbackCone.mk_π_app, limit.lift_π_assoc, cospan_right])
/-- This iso witnesses the fact that
given `f : X ⟶ Y`, `i : U ⟶ Y`, and `i₁ : V₁ ⟶ X ×[Y] U`, `i₂ : V₂ ⟶ X ×[Y] U`, the diagram
```
V₁ ×[X ×[Y] U] V₂ ⟶ V₁ ×[U] V₂
| |
| |
↓ ↓
X ⟶ X ×[Y] X
```
is a pullback square.
Also see `pullback_fst_map_snd_isPullback`.
-/
def pullbackDiagonalMapIso :
pullback (diagonal f)
(map (i₁ ≫ snd _ _) (i₂ ≫ snd _ _) f f (i₁ ≫ fst _ _) (i₂ ≫ fst _ _) i
(by simp only [Category.assoc, condition])
(by simp only [Category.assoc, condition])) ≅
pullback i₁ i₂ where
hom := pullbackDiagonalMapIso.hom f i i₁ i₂
inv := pullbackDiagonalMapIso.inv f i i₁ i₂
@[reassoc (attr := simp)]
theorem pullbackDiagonalMapIso.hom_fst :
(pullbackDiagonalMapIso f i i₁ i₂).hom ≫ pullback.fst _ _ =
pullback.snd _ _ ≫ pullback.fst _ _ := by
delta pullbackDiagonalMapIso
simp only [limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app]
@[reassoc (attr := simp)]
theorem pullbackDiagonalMapIso.hom_snd :
(pullbackDiagonalMapIso f i i₁ i₂).hom ≫ pullback.snd _ _ =
pullback.snd _ _ ≫ pullback.snd _ _ := by
delta pullbackDiagonalMapIso
simp only [limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app]
@[reassoc (attr := simp)]
theorem pullbackDiagonalMapIso.inv_fst :
(pullbackDiagonalMapIso f i i₁ i₂).inv ≫ pullback.fst _ _ =
pullback.fst _ _ ≫ i₁ ≫ pullback.fst _ _ := by
delta pullbackDiagonalMapIso
simp only [limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app]
@[reassoc (attr := simp)]
theorem pullbackDiagonalMapIso.inv_snd_fst :
(pullbackDiagonalMapIso f i i₁ i₂).inv ≫ pullback.snd _ _ ≫ pullback.fst _ _ =
pullback.fst _ _ := by
delta pullbackDiagonalMapIso
simp
@[reassoc (attr := simp)]
theorem pullbackDiagonalMapIso.inv_snd_snd :
(pullbackDiagonalMapIso f i i₁ i₂).inv ≫ pullback.snd _ _ ≫ pullback.snd _ _ =
pullback.snd _ _ := by
delta pullbackDiagonalMapIso
simp
theorem pullback_fst_map_snd_isPullback :
IsPullback (fst _ _ ≫ i₁ ≫ fst _ _)
(map i₁ i₂ (i₁ ≫ snd _ _) (i₂ ≫ snd _ _) _ _ _
(Category.id_comp _).symm (Category.id_comp _).symm)
(diagonal f)
(map (i₁ ≫ snd _ _) (i₂ ≫ snd _ _) f f (i₁ ≫ fst _ _) (i₂ ≫ fst _ _) i (by simp [condition])
(by simp [condition])) :=
IsPullback.of_iso_pullback ⟨by ext <;> simp [condition_assoc]⟩
(pullbackDiagonalMapIso f i i₁ i₂).symm (pullbackDiagonalMapIso.inv_fst f i i₁ i₂)
(by aesop_cat)
end
section
variable {S T : C} (f : X ⟶ T) (g : Y ⟶ T) (i : T ⟶ S)
variable [HasPullback i i] [HasPullback f g] [HasPullback (f ≫ i) (g ≫ i)]
variable
[HasPullback (diagonal i)
(pullback.map (f ≫ i) (g ≫ i) i i f g (𝟙 _) (Category.comp_id _) (Category.comp_id _))]
/-- This iso witnesses the fact that
given `f : X ⟶ T`, `g : Y ⟶ T`, and `i : T ⟶ S`, the diagram
```
X ×ₜ Y ⟶ X ×ₛ Y
| |
| |
↓ ↓
T ⟶ T ×ₛ T
```
is a pullback square.
Also see `pullback_map_diagonal_isPullback`.
-/
def pullbackDiagonalMapIdIso :
pullback (diagonal i)
(pullback.map (f ≫ i) (g ≫ i) i i f g (𝟙 _) (Category.comp_id _) (Category.comp_id _)) ≅
pullback f g := by
refine ?_ ≪≫
pullbackDiagonalMapIso i (𝟙 _) (f ≫ inv (pullback.fst _ _)) (g ≫ inv (pullback.fst _ _)) ≪≫ ?_
· refine @asIso _ _ _ _ (pullback.map _ _ _ _ (𝟙 T) ((pullback.congrHom ?_ ?_).hom) (𝟙 _) ?_ ?_)
?_
· rw [← Category.comp_id (pullback.snd ..), ← condition, Category.assoc, IsIso.inv_hom_id_assoc]
· rw [← Category.comp_id (pullback.snd ..), ← condition, Category.assoc, IsIso.inv_hom_id_assoc]
· rw [Category.comp_id, Category.id_comp]
· ext <;> simp
· infer_instance
· refine @asIso _ _ _ _ (pullback.map _ _ _ _ (𝟙 _) (𝟙 _) (pullback.fst _ _) ?_ ?_) ?_
· rw [Category.assoc, IsIso.inv_hom_id, Category.comp_id, Category.id_comp]
· rw [Category.assoc, IsIso.inv_hom_id, Category.comp_id, Category.id_comp]
· infer_instance
@[reassoc (attr := simp)]
theorem pullbackDiagonalMapIdIso_hom_fst :
(pullbackDiagonalMapIdIso f g i).hom ≫ pullback.fst _ _ =
pullback.snd _ _ ≫ pullback.fst _ _ := by
delta pullbackDiagonalMapIdIso
simp
@[reassoc (attr := simp)]
theorem pullbackDiagonalMapIdIso_hom_snd :
(pullbackDiagonalMapIdIso f g i).hom ≫ pullback.snd _ _ =
pullback.snd _ _ ≫ pullback.snd _ _ := by
delta pullbackDiagonalMapIdIso
simp
@[reassoc (attr := simp)]
theorem pullbackDiagonalMapIdIso_inv_fst :
(pullbackDiagonalMapIdIso f g i).inv ≫ pullback.fst _ _ = pullback.fst _ _ ≫ f := by
rw [Iso.inv_comp_eq, ← Category.comp_id (pullback.fst _ _), ← diagonal_fst i,
pullback.condition_assoc]
simp
@[reassoc (attr := simp)]
theorem pullbackDiagonalMapIdIso_inv_snd_fst :
(pullbackDiagonalMapIdIso f g i).inv ≫ pullback.snd _ _ ≫ pullback.fst _ _ =
pullback.fst _ _ := by
rw [Iso.inv_comp_eq]
simp
@[reassoc (attr := simp)]
theorem pullbackDiagonalMapIdIso_inv_snd_snd :
(pullbackDiagonalMapIdIso f g i).inv ≫ pullback.snd _ _ ≫ pullback.snd _ _ =
pullback.snd _ _ := by
rw [Iso.inv_comp_eq]
simp
theorem pullback.diagonal_comp (f : X ⟶ Y) (g : Y ⟶ Z) :
diagonal (f ≫ g) = diagonal f ≫ (pullbackDiagonalMapIdIso f f g).inv ≫ pullback.snd _ _ := by
ext <;> simp
@[reassoc]
lemma pullback.comp_diagonal (f : X ⟶ Y) (g : Y ⟶ Z) :
f ≫ pullback.diagonal g = pullback.diagonal (f ≫ g) ≫
pullback.map (f ≫ g) (f ≫ g) g g f f (𝟙 Z) (by simp) (by simp) := by
ext <;> simp
theorem pullback_map_diagonal_isPullback :
IsPullback (pullback.fst _ _ ≫ f)
(pullback.map f g (f ≫ i) (g ≫ i) _ _ i (Category.id_comp _).symm (Category.id_comp _).symm)
(diagonal i)
(pullback.map (f ≫ i) (g ≫ i) i i f g (𝟙 _) (Category.comp_id _) (Category.comp_id _)) := by
apply IsPullback.of_iso_pullback _ (pullbackDiagonalMapIdIso f g i).symm
· simp
· ext <;> simp
· constructor
ext <;> simp [condition]
/-- The diagonal object of `X ×[Z] Y ⟶ X` is isomorphic to `Δ_{Y/Z} ×[Z] X`. -/
def diagonalObjPullbackFstIso {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) :
diagonalObj (pullback.fst f g) ≅
pullback (pullback.snd _ _ ≫ g : diagonalObj g ⟶ Z) f :=
pullbackRightPullbackFstIso _ _ _ ≪≫
pullback.congrHom pullback.condition rfl ≪≫
pullbackAssoc _ _ _ _ ≪≫ pullbackSymmetry _ _ ≪≫ pullback.congrHom pullback.condition rfl
@[reassoc (attr := simp)]
theorem diagonalObjPullbackFstIso_hom_fst_fst {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) :
(diagonalObjPullbackFstIso f g).hom ≫ pullback.fst _ _ ≫ pullback.fst _ _ =
pullback.fst _ _ ≫ pullback.snd _ _ := by
delta diagonalObjPullbackFstIso
simp
@[reassoc (attr := simp)]
theorem diagonalObjPullbackFstIso_hom_fst_snd {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) :
(diagonalObjPullbackFstIso f g).hom ≫ pullback.fst _ _ ≫ pullback.snd _ _ =
pullback.snd _ _ ≫ pullback.snd _ _ := by
delta diagonalObjPullbackFstIso
simp
@[reassoc (attr := simp)]
theorem diagonalObjPullbackFstIso_hom_snd {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) :
(diagonalObjPullbackFstIso f g).hom ≫ pullback.snd _ _ =
pullback.fst _ _ ≫ pullback.fst _ _ := by
delta diagonalObjPullbackFstIso
simp
@[reassoc (attr := simp)]
theorem diagonalObjPullbackFstIso_inv_fst_fst {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) :
(diagonalObjPullbackFstIso f g).inv ≫ pullback.fst _ _ ≫ pullback.fst _ _ =
pullback.snd _ _ := by
delta diagonalObjPullbackFstIso
simp
@[reassoc (attr := simp)]
| Mathlib/CategoryTheory/Limits/Shapes/Diagonal.lean | 338 | 341 | theorem diagonalObjPullbackFstIso_inv_fst_snd {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) :
(diagonalObjPullbackFstIso f g).inv ≫ pullback.fst _ _ ≫ pullback.snd _ _ =
pullback.fst _ _ ≫ pullback.fst _ _ := by | delta diagonalObjPullbackFstIso |
/-
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.Support
import Mathlib.Data.ENat.Basic
/-!
# Trailing degree of univariate polynomials
## Main definitions
* `trailingDegree p`: the multiplicity of `X` in the polynomial `p`
* `natTrailingDegree`: a variant of `trailingDegree` that takes values in the natural numbers
* `trailingCoeff`: the coefficient at index `natTrailingDegree p`
Converts most results about `degree`, `natDegree` and `leadingCoeff` to results about the bottom
end of a polynomial
-/
noncomputable section
open Function Polynomial Finsupp Finset
open scoped Polynomial
namespace Polynomial
universe u v
variable {R : Type u} {S : Type v} {a b : R} {n m : ℕ}
section Semiring
variable [Semiring R] {p q r : R[X]}
/-- `trailingDegree p` is the multiplicity of `x` in the polynomial `p`, i.e. the smallest
`X`-exponent in `p`.
`trailingDegree p = some n` when `p ≠ 0` and `n` is the smallest power of `X` that appears
in `p`, otherwise
`trailingDegree 0 = ⊤`. -/
def trailingDegree (p : R[X]) : ℕ∞ :=
p.support.min
theorem trailingDegree_lt_wf : WellFounded fun p q : R[X] => trailingDegree p < trailingDegree q :=
InvImage.wf trailingDegree wellFounded_lt
/-- `natTrailingDegree p` forces `trailingDegree p` to `ℕ`, by defining
`natTrailingDegree ⊤ = 0`. -/
def natTrailingDegree (p : R[X]) : ℕ :=
ENat.toNat (trailingDegree p)
/-- `trailingCoeff p` gives the coefficient of the smallest power of `X` in `p`. -/
def trailingCoeff (p : R[X]) : R :=
coeff p (natTrailingDegree p)
/-- a polynomial is `monic_at` if its trailing coefficient is 1 -/
def TrailingMonic (p : R[X]) :=
trailingCoeff p = (1 : R)
theorem TrailingMonic.def : TrailingMonic p ↔ trailingCoeff p = 1 :=
Iff.rfl
instance TrailingMonic.decidable [DecidableEq R] : Decidable (TrailingMonic p) :=
inferInstanceAs <| Decidable (trailingCoeff p = (1 : R))
@[simp]
theorem TrailingMonic.trailingCoeff {p : R[X]} (hp : p.TrailingMonic) : trailingCoeff p = 1 :=
hp
@[simp]
theorem trailingDegree_zero : trailingDegree (0 : R[X]) = ⊤ :=
rfl
@[simp]
theorem trailingCoeff_zero : trailingCoeff (0 : R[X]) = 0 :=
rfl
@[simp]
theorem natTrailingDegree_zero : natTrailingDegree (0 : R[X]) = 0 :=
rfl
@[simp]
theorem trailingDegree_eq_top : trailingDegree p = ⊤ ↔ p = 0 :=
⟨fun h => support_eq_empty.1 (Finset.min_eq_top.1 h), fun h => by simp [h]⟩
theorem trailingDegree_eq_natTrailingDegree (hp : p ≠ 0) :
trailingDegree p = (natTrailingDegree p : ℕ∞) :=
.symm <| ENat.coe_toNat <| mt trailingDegree_eq_top.1 hp
theorem trailingDegree_eq_iff_natTrailingDegree_eq {p : R[X]} {n : ℕ} (hp : p ≠ 0) :
p.trailingDegree = n ↔ p.natTrailingDegree = n := by
rw [trailingDegree_eq_natTrailingDegree hp, Nat.cast_inj]
theorem trailingDegree_eq_iff_natTrailingDegree_eq_of_pos {p : R[X]} {n : ℕ} (hn : n ≠ 0) :
p.trailingDegree = n ↔ p.natTrailingDegree = n := by
rw [natTrailingDegree, ENat.toNat_eq_iff hn]
theorem natTrailingDegree_eq_of_trailingDegree_eq_some {p : R[X]} {n : ℕ}
(h : trailingDegree p = n) : natTrailingDegree p = n := by
simp [natTrailingDegree, h]
@[simp]
theorem natTrailingDegree_le_trailingDegree : ↑(natTrailingDegree p) ≤ trailingDegree p :=
ENat.coe_toNat_le_self _
theorem natTrailingDegree_eq_of_trailingDegree_eq [Semiring S] {q : S[X]}
(h : trailingDegree p = trailingDegree q) : natTrailingDegree p = natTrailingDegree q := by
unfold natTrailingDegree
rw [h]
theorem trailingDegree_le_of_ne_zero (h : coeff p n ≠ 0) : trailingDegree p ≤ n :=
min_le (mem_support_iff.2 h)
theorem natTrailingDegree_le_of_ne_zero (h : coeff p n ≠ 0) : natTrailingDegree p ≤ n :=
ENat.toNat_le_of_le_coe <| trailingDegree_le_of_ne_zero h
@[simp] lemma coeff_natTrailingDegree_eq_zero : coeff p p.natTrailingDegree = 0 ↔ p = 0 := by
constructor
· rintro h
by_contra hp
obtain ⟨n, hpn, hn⟩ := by simpa using min_mem_image_coe <| support_nonempty.2 hp
obtain rfl := (trailingDegree_eq_iff_natTrailingDegree_eq hp).1 hn.symm
exact hpn h
· rintro rfl
simp
lemma coeff_natTrailingDegree_ne_zero : coeff p p.natTrailingDegree ≠ 0 ↔ p ≠ 0 :=
coeff_natTrailingDegree_eq_zero.not
@[simp]
lemma trailingDegree_eq_zero : trailingDegree p = 0 ↔ coeff p 0 ≠ 0 :=
Finset.min_eq_bot.trans mem_support_iff
@[simp] lemma natTrailingDegree_eq_zero : natTrailingDegree p = 0 ↔ p = 0 ∨ coeff p 0 ≠ 0 := by
simp [natTrailingDegree, or_comm]
lemma natTrailingDegree_ne_zero : natTrailingDegree p ≠ 0 ↔ p ≠ 0 ∧ coeff p 0 = 0 :=
natTrailingDegree_eq_zero.not.trans <| by rw [not_or, not_ne_iff]
lemma trailingDegree_ne_zero : trailingDegree p ≠ 0 ↔ coeff p 0 = 0 :=
trailingDegree_eq_zero.not_left
@[simp] theorem trailingDegree_le_trailingDegree (h : coeff q (natTrailingDegree p) ≠ 0) :
trailingDegree q ≤ trailingDegree p :=
(trailingDegree_le_of_ne_zero h).trans natTrailingDegree_le_trailingDegree
theorem trailingDegree_ne_of_natTrailingDegree_ne {n : ℕ} :
p.natTrailingDegree ≠ n → trailingDegree p ≠ n :=
mt fun h => by rw [natTrailingDegree, h, ENat.toNat_coe]
theorem natTrailingDegree_le_of_trailingDegree_le {n : ℕ} {hp : p ≠ 0}
(H : (n : ℕ∞) ≤ trailingDegree p) : n ≤ natTrailingDegree p := by
rwa [trailingDegree_eq_natTrailingDegree hp, Nat.cast_le] at H
theorem natTrailingDegree_le_natTrailingDegree (hq : q ≠ 0)
(hpq : p.trailingDegree ≤ q.trailingDegree) : p.natTrailingDegree ≤ q.natTrailingDegree :=
ENat.toNat_le_toNat hpq <| by simpa
@[simp]
theorem trailingDegree_monomial (ha : a ≠ 0) : trailingDegree (monomial n a) = n := by
rw [trailingDegree, support_monomial n ha, min_singleton]
rfl
theorem natTrailingDegree_monomial (ha : a ≠ 0) : natTrailingDegree (monomial n a) = n := by
rw [natTrailingDegree, trailingDegree_monomial ha]
rfl
theorem natTrailingDegree_monomial_le : natTrailingDegree (monomial n a) ≤ n :=
letI := Classical.decEq R
if ha : a = 0 then by simp [ha] else (natTrailingDegree_monomial ha).le
theorem le_trailingDegree_monomial : ↑n ≤ trailingDegree (monomial n a) :=
letI := Classical.decEq R
if ha : a = 0 then by simp [ha] else (trailingDegree_monomial ha).ge
@[simp]
theorem trailingDegree_C (ha : a ≠ 0) : trailingDegree (C a) = (0 : ℕ∞) :=
trailingDegree_monomial ha
theorem le_trailingDegree_C : (0 : ℕ∞) ≤ trailingDegree (C a) :=
le_trailingDegree_monomial
theorem trailingDegree_one_le : (0 : ℕ∞) ≤ trailingDegree (1 : R[X]) := by
rw [← C_1]
exact le_trailingDegree_C
@[simp]
theorem natTrailingDegree_C (a : R) : natTrailingDegree (C a) = 0 :=
nonpos_iff_eq_zero.1 natTrailingDegree_monomial_le
@[simp]
theorem natTrailingDegree_one : natTrailingDegree (1 : R[X]) = 0 :=
natTrailingDegree_C 1
@[simp]
| Mathlib/Algebra/Polynomial/Degree/TrailingDegree.lean | 199 | 201 | theorem natTrailingDegree_natCast (n : ℕ) : natTrailingDegree (n : R[X]) = 0 := by | simp only [← C_eq_natCast, natTrailingDegree_C] |
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johannes Hölzl, Patrick Massot
-/
import Mathlib.Data.Set.Image
import Mathlib.Data.SProd
/-!
# Sets in product and pi types
This file proves basic properties of product of sets in `α × β` and in `Π i, α i`, and of the
diagonal of a type.
## Main declarations
This file contains basic results on the following notions, which are defined in `Set.Operations`.
* `Set.prod`: Binary product of sets. For `s : Set α`, `t : Set β`, we have
`s.prod t : Set (α × β)`. Denoted by `s ×ˢ t`.
* `Set.diagonal`: Diagonal of a type. `Set.diagonal α = {(x, x) | x : α}`.
* `Set.offDiag`: Off-diagonal. `s ×ˢ s` without the diagonal.
* `Set.pi`: Arbitrary product of sets.
-/
open Function
namespace Set
/-! ### Cartesian binary product of sets -/
section Prod
variable {α β γ δ : Type*} {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {a : α} {b : β}
theorem Subsingleton.prod (hs : s.Subsingleton) (ht : t.Subsingleton) :
(s ×ˢ t).Subsingleton := fun _x hx _y hy ↦
Prod.ext (hs hx.1 hy.1) (ht hx.2 hy.2)
noncomputable instance decidableMemProd [DecidablePred (· ∈ s)] [DecidablePred (· ∈ t)] :
DecidablePred (· ∈ s ×ˢ t) := fun x => inferInstanceAs (Decidable (x.1 ∈ s ∧ x.2 ∈ t))
@[gcongr]
theorem prod_mono (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : s₁ ×ˢ t₁ ⊆ s₂ ×ˢ t₂ :=
fun _ ⟨h₁, h₂⟩ => ⟨hs h₁, ht h₂⟩
@[gcongr]
theorem prod_mono_left (hs : s₁ ⊆ s₂) : s₁ ×ˢ t ⊆ s₂ ×ˢ t :=
prod_mono hs Subset.rfl
@[gcongr]
theorem prod_mono_right (ht : t₁ ⊆ t₂) : s ×ˢ t₁ ⊆ s ×ˢ t₂ :=
prod_mono Subset.rfl ht
@[simp]
theorem prod_self_subset_prod_self : s₁ ×ˢ s₁ ⊆ s₂ ×ˢ s₂ ↔ s₁ ⊆ s₂ :=
⟨fun h _ hx => (h (mk_mem_prod hx hx)).1, fun h _ hx => ⟨h hx.1, h hx.2⟩⟩
@[simp]
theorem prod_self_ssubset_prod_self : s₁ ×ˢ s₁ ⊂ s₂ ×ˢ s₂ ↔ s₁ ⊂ s₂ :=
and_congr prod_self_subset_prod_self <| not_congr prod_self_subset_prod_self
theorem prod_subset_iff {P : Set (α × β)} : s ×ˢ t ⊆ P ↔ ∀ x ∈ s, ∀ y ∈ t, (x, y) ∈ P :=
⟨fun h _ hx _ hy => h (mk_mem_prod hx hy), fun h ⟨_, _⟩ hp => h _ hp.1 _ hp.2⟩
theorem forall_prod_set {p : α × β → Prop} : (∀ x ∈ s ×ˢ t, p x) ↔ ∀ x ∈ s, ∀ y ∈ t, p (x, y) :=
prod_subset_iff
theorem exists_prod_set {p : α × β → Prop} : (∃ x ∈ s ×ˢ t, p x) ↔ ∃ x ∈ s, ∃ y ∈ t, p (x, y) := by
simp [and_assoc]
@[simp]
theorem prod_empty : s ×ˢ (∅ : Set β) = ∅ := by
ext
exact iff_of_eq (and_false _)
@[simp]
theorem empty_prod : (∅ : Set α) ×ˢ t = ∅ := by
ext
exact iff_of_eq (false_and _)
@[simp, mfld_simps]
theorem univ_prod_univ : @univ α ×ˢ @univ β = univ := by
ext
exact iff_of_eq (true_and _)
theorem univ_prod {t : Set β} : (univ : Set α) ×ˢ t = Prod.snd ⁻¹' t := by simp [prod_eq]
theorem prod_univ {s : Set α} : s ×ˢ (univ : Set β) = Prod.fst ⁻¹' s := by simp [prod_eq]
@[simp] lemma prod_eq_univ [Nonempty α] [Nonempty β] : s ×ˢ t = univ ↔ s = univ ∧ t = univ := by
simp [eq_univ_iff_forall, forall_and]
theorem singleton_prod : ({a} : Set α) ×ˢ t = Prod.mk a '' t := by
ext ⟨x, y⟩
simp [and_left_comm, eq_comm]
theorem prod_singleton : s ×ˢ ({b} : Set β) = (fun a => (a, b)) '' s := by
ext ⟨x, y⟩
simp [and_left_comm, eq_comm]
@[simp]
theorem singleton_prod_singleton : ({a} : Set α) ×ˢ ({b} : Set β) = {(a, b)} := by ext ⟨c, d⟩; simp
@[simp]
theorem union_prod : (s₁ ∪ s₂) ×ˢ t = s₁ ×ˢ t ∪ s₂ ×ˢ t := by
ext ⟨x, y⟩
simp [or_and_right]
@[simp]
theorem prod_union : s ×ˢ (t₁ ∪ t₂) = s ×ˢ t₁ ∪ s ×ˢ t₂ := by
ext ⟨x, y⟩
simp [and_or_left]
theorem inter_prod : (s₁ ∩ s₂) ×ˢ t = s₁ ×ˢ t ∩ s₂ ×ˢ t := by
ext ⟨x, y⟩
simp only [← and_and_right, mem_inter_iff, mem_prod]
theorem prod_inter : s ×ˢ (t₁ ∩ t₂) = s ×ˢ t₁ ∩ s ×ˢ t₂ := by
ext ⟨x, y⟩
simp only [← and_and_left, mem_inter_iff, mem_prod]
@[mfld_simps]
theorem prod_inter_prod : s₁ ×ˢ t₁ ∩ s₂ ×ˢ t₂ = (s₁ ∩ s₂) ×ˢ (t₁ ∩ t₂) := by
ext ⟨x, y⟩
simp [and_assoc, and_left_comm]
lemma compl_prod_eq_union {α β : Type*} (s : Set α) (t : Set β) :
(s ×ˢ t)ᶜ = (sᶜ ×ˢ univ) ∪ (univ ×ˢ tᶜ) := by
ext p
simp only [mem_compl_iff, mem_prod, not_and, mem_union, mem_univ, and_true, true_and]
constructor <;> intro h
· by_cases fst_in_s : p.fst ∈ s
· exact Or.inr (h fst_in_s)
· exact Or.inl fst_in_s
· intro fst_in_s
simpa only [fst_in_s, not_true, false_or] using h
@[simp]
theorem disjoint_prod : Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) ↔ Disjoint s₁ s₂ ∨ Disjoint t₁ t₂ := by
simp_rw [disjoint_left, mem_prod, not_and_or, Prod.forall, and_imp, ← @forall_or_right α, ←
@forall_or_left β, ← @forall_or_right (_ ∈ s₁), ← @forall_or_left (_ ∈ t₁)]
theorem Disjoint.set_prod_left (hs : Disjoint s₁ s₂) (t₁ t₂ : Set β) :
Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) :=
disjoint_left.2 fun ⟨_a, _b⟩ ⟨ha₁, _⟩ ⟨ha₂, _⟩ => disjoint_left.1 hs ha₁ ha₂
theorem Disjoint.set_prod_right (ht : Disjoint t₁ t₂) (s₁ s₂ : Set α) :
Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) :=
disjoint_left.2 fun ⟨_a, _b⟩ ⟨_, hb₁⟩ ⟨_, hb₂⟩ => disjoint_left.1 ht hb₁ hb₂
theorem prodMap_image_prod (f : α → β) (g : γ → δ) (s : Set α) (t : Set γ) :
(Prod.map f g) '' (s ×ˢ t) = (f '' s) ×ˢ (g '' t) := by
ext
aesop
theorem insert_prod : insert a s ×ˢ t = Prod.mk a '' t ∪ s ×ˢ t := by
simp only [insert_eq, union_prod, singleton_prod]
theorem prod_insert : s ×ˢ insert b t = (fun a => (a, b)) '' s ∪ s ×ˢ t := by
simp only [insert_eq, prod_union, prod_singleton]
theorem prod_preimage_eq {f : γ → α} {g : δ → β} :
(f ⁻¹' s) ×ˢ (g ⁻¹' t) = (fun p : γ × δ => (f p.1, g p.2)) ⁻¹' s ×ˢ t :=
rfl
theorem prod_preimage_left {f : γ → α} :
(f ⁻¹' s) ×ˢ t = (fun p : γ × β => (f p.1, p.2)) ⁻¹' s ×ˢ t :=
rfl
theorem prod_preimage_right {g : δ → β} :
s ×ˢ (g ⁻¹' t) = (fun p : α × δ => (p.1, g p.2)) ⁻¹' s ×ˢ t :=
rfl
theorem preimage_prod_map_prod (f : α → β) (g : γ → δ) (s : Set β) (t : Set δ) :
Prod.map f g ⁻¹' s ×ˢ t = (f ⁻¹' s) ×ˢ (g ⁻¹' t) :=
rfl
theorem mk_preimage_prod (f : γ → α) (g : γ → β) :
(fun x => (f x, g x)) ⁻¹' s ×ˢ t = f ⁻¹' s ∩ g ⁻¹' t :=
rfl
@[simp]
theorem mk_preimage_prod_left (hb : b ∈ t) : (fun a => (a, b)) ⁻¹' s ×ˢ t = s := by
ext a
simp [hb]
@[simp]
theorem mk_preimage_prod_right (ha : a ∈ s) : Prod.mk a ⁻¹' s ×ˢ t = t := by
ext b
simp [ha]
@[simp]
theorem mk_preimage_prod_left_eq_empty (hb : b ∉ t) : (fun a => (a, b)) ⁻¹' s ×ˢ t = ∅ := by
ext a
simp [hb]
@[simp]
theorem mk_preimage_prod_right_eq_empty (ha : a ∉ s) : Prod.mk a ⁻¹' s ×ˢ t = ∅ := by
ext b
simp [ha]
theorem mk_preimage_prod_left_eq_if [DecidablePred (· ∈ t)] :
(fun a => (a, b)) ⁻¹' s ×ˢ t = if b ∈ t then s else ∅ := by split_ifs with h <;> simp [h]
theorem mk_preimage_prod_right_eq_if [DecidablePred (· ∈ s)] :
Prod.mk a ⁻¹' s ×ˢ t = if a ∈ s then t else ∅ := by split_ifs with h <;> simp [h]
theorem mk_preimage_prod_left_fn_eq_if [DecidablePred (· ∈ t)] (f : γ → α) :
(fun a => (f a, b)) ⁻¹' s ×ˢ t = if b ∈ t then f ⁻¹' s else ∅ := by
rw [← mk_preimage_prod_left_eq_if, prod_preimage_left, preimage_preimage]
theorem mk_preimage_prod_right_fn_eq_if [DecidablePred (· ∈ s)] (g : δ → β) :
(fun b => (a, g b)) ⁻¹' s ×ˢ t = if a ∈ s then g ⁻¹' t else ∅ := by
rw [← mk_preimage_prod_right_eq_if, prod_preimage_right, preimage_preimage]
@[simp]
theorem preimage_swap_prod (s : Set α) (t : Set β) : Prod.swap ⁻¹' s ×ˢ t = t ×ˢ s := by
ext ⟨x, y⟩
simp [and_comm]
@[simp]
theorem image_swap_prod (s : Set α) (t : Set β) : Prod.swap '' s ×ˢ t = t ×ˢ s := by
rw [image_swap_eq_preimage_swap, preimage_swap_prod]
theorem mapsTo_swap_prod (s : Set α) (t : Set β) : MapsTo Prod.swap (s ×ˢ t) (t ×ˢ s) :=
fun _ ⟨hx, hy⟩ ↦ ⟨hy, hx⟩
theorem prod_image_image_eq {m₁ : α → γ} {m₂ : β → δ} :
(m₁ '' s) ×ˢ (m₂ '' t) = (fun p : α × β => (m₁ p.1, m₂ p.2)) '' s ×ˢ t :=
ext <| by
simp [-exists_and_right, exists_and_right.symm, and_left_comm, and_assoc, and_comm]
theorem prod_range_range_eq {m₁ : α → γ} {m₂ : β → δ} :
range m₁ ×ˢ range m₂ = range fun p : α × β => (m₁ p.1, m₂ p.2) :=
ext <| by simp [range]
@[simp, mfld_simps]
theorem range_prodMap {m₁ : α → γ} {m₂ : β → δ} : range (Prod.map m₁ m₂) = range m₁ ×ˢ range m₂ :=
prod_range_range_eq.symm
@[deprecated (since := "2025-04-10")] alias range_prod_map := range_prodMap
theorem prod_range_univ_eq {m₁ : α → γ} :
range m₁ ×ˢ (univ : Set β) = range fun p : α × β => (m₁ p.1, p.2) :=
ext <| by simp [range]
theorem prod_univ_range_eq {m₂ : β → δ} :
(univ : Set α) ×ˢ range m₂ = range fun p : α × β => (p.1, m₂ p.2) :=
ext <| by simp [range]
theorem range_pair_subset (f : α → β) (g : α → γ) :
(range fun x => (f x, g x)) ⊆ range f ×ˢ range g := by
have : (fun x => (f x, g x)) = Prod.map f g ∘ fun x => (x, x) := funext fun x => rfl
rw [this, ← range_prodMap]
apply range_comp_subset_range
theorem Nonempty.prod : s.Nonempty → t.Nonempty → (s ×ˢ t).Nonempty := fun ⟨x, hx⟩ ⟨y, hy⟩ =>
⟨(x, y), ⟨hx, hy⟩⟩
theorem Nonempty.fst : (s ×ˢ t).Nonempty → s.Nonempty := fun ⟨x, hx⟩ => ⟨x.1, hx.1⟩
theorem Nonempty.snd : (s ×ˢ t).Nonempty → t.Nonempty := fun ⟨x, hx⟩ => ⟨x.2, hx.2⟩
@[simp]
theorem prod_nonempty_iff : (s ×ˢ t).Nonempty ↔ s.Nonempty ∧ t.Nonempty :=
⟨fun h => ⟨h.fst, h.snd⟩, fun h => h.1.prod h.2⟩
@[simp]
theorem prod_eq_empty_iff : s ×ˢ t = ∅ ↔ s = ∅ ∨ t = ∅ := by
simp only [not_nonempty_iff_eq_empty.symm, prod_nonempty_iff, not_and_or]
theorem prod_sub_preimage_iff {W : Set γ} {f : α × β → γ} :
s ×ˢ t ⊆ f ⁻¹' W ↔ ∀ a b, a ∈ s → b ∈ t → f (a, b) ∈ W := by simp [subset_def]
theorem image_prodMk_subset_prod {f : α → β} {g : α → γ} {s : Set α} :
(fun x => (f x, g x)) '' s ⊆ (f '' s) ×ˢ (g '' s) := by
rintro _ ⟨x, hx, rfl⟩
exact mk_mem_prod (mem_image_of_mem f hx) (mem_image_of_mem g hx)
@[deprecated (since := "2025-02-22")]
alias image_prod_mk_subset_prod := image_prodMk_subset_prod
theorem image_prodMk_subset_prod_left (hb : b ∈ t) : (fun a => (a, b)) '' s ⊆ s ×ˢ t := by
rintro _ ⟨a, ha, rfl⟩
exact ⟨ha, hb⟩
@[deprecated (since := "2025-02-22")]
alias image_prod_mk_subset_prod_left := image_prodMk_subset_prod_left
theorem image_prodMk_subset_prod_right (ha : a ∈ s) : Prod.mk a '' t ⊆ s ×ˢ t := by
rintro _ ⟨b, hb, rfl⟩
exact ⟨ha, hb⟩
@[deprecated (since := "2025-02-22")]
alias image_prod_mk_subset_prod_right := image_prodMk_subset_prod_right
theorem prod_subset_preimage_fst (s : Set α) (t : Set β) : s ×ˢ t ⊆ Prod.fst ⁻¹' s :=
inter_subset_left
theorem fst_image_prod_subset (s : Set α) (t : Set β) : Prod.fst '' s ×ˢ t ⊆ s :=
image_subset_iff.2 <| prod_subset_preimage_fst s t
theorem fst_image_prod (s : Set β) {t : Set α} (ht : t.Nonempty) : Prod.fst '' s ×ˢ t = s :=
(fst_image_prod_subset _ _).antisymm fun y hy =>
let ⟨x, hx⟩ := ht
⟨(y, x), ⟨hy, hx⟩, rfl⟩
lemma mapsTo_fst_prod {s : Set α} {t : Set β} : MapsTo Prod.fst (s ×ˢ t) s :=
fun _ hx ↦ (mem_prod.1 hx).1
theorem prod_subset_preimage_snd (s : Set α) (t : Set β) : s ×ˢ t ⊆ Prod.snd ⁻¹' t :=
inter_subset_right
theorem snd_image_prod_subset (s : Set α) (t : Set β) : Prod.snd '' s ×ˢ t ⊆ t :=
image_subset_iff.2 <| prod_subset_preimage_snd s t
theorem snd_image_prod {s : Set α} (hs : s.Nonempty) (t : Set β) : Prod.snd '' s ×ˢ t = t :=
(snd_image_prod_subset _ _).antisymm fun y y_in =>
let ⟨x, x_in⟩ := hs
⟨(x, y), ⟨x_in, y_in⟩, rfl⟩
lemma mapsTo_snd_prod {s : Set α} {t : Set β} : MapsTo Prod.snd (s ×ˢ t) t :=
fun _ hx ↦ (mem_prod.1 hx).2
theorem prod_diff_prod : s ×ˢ t \ s₁ ×ˢ t₁ = s ×ˢ (t \ t₁) ∪ (s \ s₁) ×ˢ t := by
ext x
by_cases h₁ : x.1 ∈ s₁ <;> by_cases h₂ : x.2 ∈ t₁ <;> simp [*]
/-- A product set is included in a product set if and only factors are included, or a factor of the
first set is empty. -/
theorem prod_subset_prod_iff : s ×ˢ t ⊆ s₁ ×ˢ t₁ ↔ s ⊆ s₁ ∧ t ⊆ t₁ ∨ s = ∅ ∨ t = ∅ := by
rcases (s ×ˢ t).eq_empty_or_nonempty with h | h
· simp [h, prod_eq_empty_iff.1 h]
have st : s.Nonempty ∧ t.Nonempty := by rwa [prod_nonempty_iff] at h
refine ⟨fun H => Or.inl ⟨?_, ?_⟩, ?_⟩
· have := image_subset (Prod.fst : α × β → α) H
rwa [fst_image_prod _ st.2, fst_image_prod _ (h.mono H).snd] at this
· have := image_subset (Prod.snd : α × β → β) H
rwa [snd_image_prod st.1, snd_image_prod (h.mono H).fst] at this
· intro H
simp only [st.1.ne_empty, st.2.ne_empty, or_false] at H
exact prod_mono H.1 H.2
theorem prod_eq_prod_iff_of_nonempty (h : (s ×ˢ t).Nonempty) :
s ×ˢ t = s₁ ×ˢ t₁ ↔ s = s₁ ∧ t = t₁ := by
constructor
· intro heq
have h₁ : (s₁ ×ˢ t₁ : Set _).Nonempty := by rwa [← heq]
rw [prod_nonempty_iff] at h h₁
rw [← fst_image_prod s h.2, ← fst_image_prod s₁ h₁.2, heq, eq_self_iff_true, true_and, ←
snd_image_prod h.1 t, ← snd_image_prod h₁.1 t₁, heq]
· rintro ⟨rfl, rfl⟩
rfl
theorem prod_eq_prod_iff :
s ×ˢ t = s₁ ×ˢ t₁ ↔ s = s₁ ∧ t = t₁ ∨ (s = ∅ ∨ t = ∅) ∧ (s₁ = ∅ ∨ t₁ = ∅) := by
symm
rcases eq_empty_or_nonempty (s ×ˢ t) with h | h
· simp_rw [h, @eq_comm _ ∅, prod_eq_empty_iff, prod_eq_empty_iff.mp h, true_and,
or_iff_right_iff_imp]
rintro ⟨rfl, rfl⟩
exact prod_eq_empty_iff.mp h
rw [prod_eq_prod_iff_of_nonempty h]
rw [nonempty_iff_ne_empty, Ne, prod_eq_empty_iff] at h
simp_rw [h, false_and, or_false]
@[simp]
theorem prod_eq_iff_eq (ht : t.Nonempty) : s ×ˢ t = s₁ ×ˢ t ↔ s = s₁ := by
simp_rw [prod_eq_prod_iff, ht.ne_empty, and_true, or_iff_left_iff_imp, or_false]
rintro ⟨rfl, rfl⟩
rfl
theorem subset_prod {s : Set (α × β)} : s ⊆ (Prod.fst '' s) ×ˢ (Prod.snd '' s) :=
fun _ hp ↦ mem_prod.2 ⟨mem_image_of_mem _ hp, mem_image_of_mem _ hp⟩
section Mono
variable [Preorder α] {f : α → Set β} {g : α → Set γ}
theorem _root_.Monotone.set_prod (hf : Monotone f) (hg : Monotone g) :
Monotone fun x => f x ×ˢ g x :=
fun _ _ h => prod_mono (hf h) (hg h)
theorem _root_.Antitone.set_prod (hf : Antitone f) (hg : Antitone g) :
Antitone fun x => f x ×ˢ g x :=
fun _ _ h => prod_mono (hf h) (hg h)
theorem _root_.MonotoneOn.set_prod (hf : MonotoneOn f s) (hg : MonotoneOn g s) :
MonotoneOn (fun x => f x ×ˢ g x) s := fun _ ha _ hb h => prod_mono (hf ha hb h) (hg ha hb h)
theorem _root_.AntitoneOn.set_prod (hf : AntitoneOn f s) (hg : AntitoneOn g s) :
AntitoneOn (fun x => f x ×ˢ g x) s := fun _ ha _ hb h => prod_mono (hf ha hb h) (hg ha hb h)
end Mono
end Prod
/-! ### Diagonal
In this section we prove some lemmas about the diagonal set `{p | p.1 = p.2}` and the diagonal map
`fun x ↦ (x, x)`.
-/
section Diagonal
variable {α : Type*} {s t : Set α}
lemma diagonal_nonempty [Nonempty α] : (diagonal α).Nonempty :=
Nonempty.elim ‹_› fun x => ⟨_, mem_diagonal x⟩
instance decidableMemDiagonal [h : DecidableEq α] (x : α × α) : Decidable (x ∈ diagonal α) :=
h x.1 x.2
theorem preimage_coe_coe_diagonal (s : Set α) :
Prod.map (fun x : s => (x : α)) (fun x : s => (x : α)) ⁻¹' diagonal α = diagonal s := by
ext ⟨⟨x, hx⟩, ⟨y, hy⟩⟩
simp [Set.diagonal]
@[simp]
theorem range_diag : (range fun x => (x, x)) = diagonal α := by
ext ⟨x, y⟩
simp [diagonal, eq_comm]
theorem diagonal_subset_iff {s} : diagonal α ⊆ s ↔ ∀ x, (x, x) ∈ s := by
rw [← range_diag, range_subset_iff]
@[simp]
theorem prod_subset_compl_diagonal_iff_disjoint : s ×ˢ t ⊆ (diagonal α)ᶜ ↔ Disjoint s t :=
prod_subset_iff.trans disjoint_iff_forall_ne.symm
@[simp]
theorem diag_preimage_prod (s t : Set α) : (fun x => (x, x)) ⁻¹' s ×ˢ t = s ∩ t :=
rfl
theorem diag_preimage_prod_self (s : Set α) : (fun x => (x, x)) ⁻¹' s ×ˢ s = s :=
inter_self s
theorem diag_image (s : Set α) : (fun x => (x, x)) '' s = diagonal α ∩ s ×ˢ s := by
rw [← range_diag, ← image_preimage_eq_range_inter, diag_preimage_prod_self]
theorem diagonal_eq_univ_iff : diagonal α = univ ↔ Subsingleton α := by
simp only [subsingleton_iff, eq_univ_iff_forall, Prod.forall, mem_diagonal_iff]
theorem diagonal_eq_univ [Subsingleton α] : diagonal α = univ := diagonal_eq_univ_iff.2 ‹_›
end Diagonal
/-- A function is `Function.const α a` for some `a` if and only if `∀ x y, f x = f y`. -/
theorem range_const_eq_diagonal {α β : Type*} [hβ : Nonempty β] :
range (const α) = {f : α → β | ∀ x y, f x = f y} := by
refine (range_eq_iff _ _).mpr ⟨fun _ _ _ ↦ rfl, fun f hf ↦ ?_⟩
rcases isEmpty_or_nonempty α with h|⟨⟨a⟩⟩
· exact hβ.elim fun b ↦ ⟨b, Subsingleton.elim _ _⟩
· exact ⟨f a, funext fun x ↦ hf _ _⟩
end Set
section Pullback
open Set
variable {X Y Z}
/-- The fiber product $X \times_Y Z$. -/
abbrev Function.Pullback (f : X → Y) (g : Z → Y) := {p : X × Z // f p.1 = g p.2}
/-- The fiber product $X \times_Y X$. -/
abbrev Function.PullbackSelf (f : X → Y) := f.Pullback f
/-- The projection from the fiber product to the first factor. -/
def Function.Pullback.fst {f : X → Y} {g : Z → Y} (p : f.Pullback g) : X := p.val.1
/-- The projection from the fiber product to the second factor. -/
def Function.Pullback.snd {f : X → Y} {g : Z → Y} (p : f.Pullback g) : Z := p.val.2
open Function.Pullback in
lemma Function.pullback_comm_sq (f : X → Y) (g : Z → Y) :
f ∘ @fst X Y Z f g = g ∘ @snd X Y Z f g := funext fun p ↦ p.2
/-- The diagonal map $\Delta: X \to X \times_Y X$. -/
@[simps]
def toPullbackDiag (f : X → Y) (x : X) : f.Pullback f := ⟨(x, x), rfl⟩
/-- The diagonal $\Delta(X) \subseteq X \times_Y X$. -/
def Function.pullbackDiagonal (f : X → Y) : Set (f.Pullback f) := {p | p.fst = p.snd}
/-- Three functions between the three pairs of spaces $X_i, Y_i, Z_i$ that are compatible
induce a function $X_1 \times_{Y_1} Z_1 \to X_2 \times_{Y_2} Z_2$. -/
def Function.mapPullback {X₁ X₂ Y₁ Y₂ Z₁ Z₂}
{f₁ : X₁ → Y₁} {g₁ : Z₁ → Y₁} {f₂ : X₂ → Y₂} {g₂ : Z₂ → Y₂}
(mapX : X₁ → X₂) (mapY : Y₁ → Y₂) (mapZ : Z₁ → Z₂)
(commX : f₂ ∘ mapX = mapY ∘ f₁) (commZ : g₂ ∘ mapZ = mapY ∘ g₁)
(p : f₁.Pullback g₁) : f₂.Pullback g₂ :=
⟨(mapX p.fst, mapZ p.snd),
(congr_fun commX _).trans <| (congr_arg mapY p.2).trans <| congr_fun commZ.symm _⟩
open Function.Pullback in
/-- The projection $(X \times_Y Z) \times_Z (X \times_Y Z) \to X \times_Y X$. -/
def Function.PullbackSelf.map_fst {f : X → Y} {g : Z → Y} :
(@snd X Y Z f g).PullbackSelf → f.PullbackSelf :=
mapPullback fst g fst (pullback_comm_sq f g) (pullback_comm_sq f g)
open Function.Pullback in
/-- The projection $(X \times_Y Z) \times_X (X \times_Y Z) \to Z \times_Y Z$. -/
def Function.PullbackSelf.map_snd {f : X → Y} {g : Z → Y} :
(@fst X Y Z f g).PullbackSelf → g.PullbackSelf :=
mapPullback snd f snd (pullback_comm_sq f g).symm (pullback_comm_sq f g).symm
open Function.PullbackSelf Function.Pullback
theorem preimage_map_fst_pullbackDiagonal {f : X → Y} {g : Z → Y} :
@map_fst X Y Z f g ⁻¹' pullbackDiagonal f = pullbackDiagonal (@snd X Y Z f g) := by
ext ⟨⟨p₁, p₂⟩, he⟩
simp_rw [pullbackDiagonal, mem_setOf, Subtype.ext_iff, Prod.ext_iff]
exact (and_iff_left he).symm
theorem Function.Injective.preimage_pullbackDiagonal {f : X → Y} {g : Z → X} (inj : g.Injective) :
mapPullback g id g (by rfl) (by rfl) ⁻¹' pullbackDiagonal f = pullbackDiagonal (f ∘ g) :=
ext fun _ ↦ inj.eq_iff
theorem image_toPullbackDiag (f : X → Y) (s : Set X) :
toPullbackDiag f '' s = pullbackDiagonal f ∩ Subtype.val ⁻¹' s ×ˢ s := by
ext x
constructor
· rintro ⟨x, hx, rfl⟩
exact ⟨rfl, hx, hx⟩
· obtain ⟨⟨x, y⟩, h⟩ := x
rintro ⟨rfl : x = y, h2x⟩
exact mem_image_of_mem _ h2x.1
theorem range_toPullbackDiag (f : X → Y) : range (toPullbackDiag f) = pullbackDiagonal f := by
rw [← image_univ, image_toPullbackDiag, univ_prod_univ, preimage_univ, inter_univ]
theorem injective_toPullbackDiag (f : X → Y) : (toPullbackDiag f).Injective :=
fun _ _ h ↦ congr_arg Prod.fst (congr_arg Subtype.val h)
end Pullback
namespace Set
section OffDiag
variable {α : Type*} {s t : Set α} {a : α}
theorem offDiag_mono : Monotone (offDiag : Set α → Set (α × α)) := fun _ _ h _ =>
And.imp (@h _) <| And.imp_left <| @h _
@[simp]
theorem offDiag_nonempty : s.offDiag.Nonempty ↔ s.Nontrivial := by
simp [offDiag, Set.Nonempty, Set.Nontrivial]
@[simp]
theorem offDiag_eq_empty : s.offDiag = ∅ ↔ s.Subsingleton := by
rw [← not_nonempty_iff_eq_empty, ← not_nontrivial_iff, offDiag_nonempty.not]
alias ⟨_, Nontrivial.offDiag_nonempty⟩ := offDiag_nonempty
alias ⟨_, Subsingleton.offDiag_eq_empty⟩ := offDiag_nonempty
variable (s t)
theorem offDiag_subset_prod : s.offDiag ⊆ s ×ˢ s := fun _ hx => ⟨hx.1, hx.2.1⟩
theorem offDiag_eq_sep_prod : s.offDiag = { x ∈ s ×ˢ s | x.1 ≠ x.2 } :=
ext fun _ => and_assoc.symm
@[simp]
theorem offDiag_empty : (∅ : Set α).offDiag = ∅ := by simp
@[simp]
theorem offDiag_singleton (a : α) : ({a} : Set α).offDiag = ∅ := by simp
@[simp]
theorem offDiag_univ : (univ : Set α).offDiag = (diagonal α)ᶜ :=
ext <| by simp
@[simp]
theorem prod_sdiff_diagonal : s ×ˢ s \ diagonal α = s.offDiag :=
ext fun _ => and_assoc
@[simp]
theorem disjoint_diagonal_offDiag : Disjoint (diagonal α) s.offDiag :=
disjoint_left.mpr fun _ hd ho => ho.2.2 hd
theorem offDiag_inter : (s ∩ t).offDiag = s.offDiag ∩ t.offDiag :=
ext fun x => by
simp only [mem_offDiag, mem_inter_iff]
tauto
variable {s t}
theorem offDiag_union (h : Disjoint s t) :
(s ∪ t).offDiag = s.offDiag ∪ t.offDiag ∪ s ×ˢ t ∪ t ×ˢ s := by
ext x
simp only [mem_offDiag, mem_union, ne_eq, mem_prod]
constructor
· rintro ⟨h0|h0, h1|h1, h2⟩ <;> simp [h0, h1, h2]
· rintro (((⟨h0, h1, h2⟩|⟨h0, h1, h2⟩)|⟨h0, h1⟩)|⟨h0, h1⟩) <;> simp [*]
· rintro h3
rw [h3] at h0
exact Set.disjoint_left.mp h h0 h1
· rintro h3
rw [h3] at h0
exact (Set.disjoint_right.mp h h0 h1).elim
theorem offDiag_insert (ha : a ∉ s) : (insert a s).offDiag = s.offDiag ∪ {a} ×ˢ s ∪ s ×ˢ {a} := by
rw [insert_eq, union_comm, offDiag_union, offDiag_singleton, union_empty, union_right_comm]
rw [disjoint_left]
rintro b hb (rfl : b = a)
exact ha hb
end OffDiag
/-! ### Cartesian set-indexed product of sets -/
section Pi
variable {ι : Type*} {α β : ι → Type*} {s s₁ s₂ : Set ι} {t t₁ t₂ : ∀ i, Set (α i)} {i : ι}
@[simp]
theorem empty_pi (s : ∀ i, Set (α i)) : pi ∅ s = univ := by
ext
simp [pi]
theorem subsingleton_univ_pi (ht : ∀ i, (t i).Subsingleton) :
(univ.pi t).Subsingleton := fun _f hf _g hg ↦ funext fun i ↦
(ht i) (hf _ <| mem_univ _) (hg _ <| mem_univ _)
@[simp]
theorem pi_univ (s : Set ι) : (pi s fun i => (univ : Set (α i))) = univ :=
eq_univ_of_forall fun _ _ _ => mem_univ _
@[simp]
theorem pi_univ_ite (s : Set ι) [DecidablePred (· ∈ s)] (t : ∀ i, Set (α i)) :
(pi univ fun i => if i ∈ s then t i else univ) = s.pi t := by
ext; simp_rw [Set.mem_pi]; apply forall_congr'; intro i; split_ifs with h <;> simp [h]
theorem pi_mono (h : ∀ i ∈ s, t₁ i ⊆ t₂ i) : pi s t₁ ⊆ pi s t₂ := fun _ hx i hi => h i hi <| hx i hi
theorem pi_inter_distrib : (s.pi fun i => t i ∩ t₁ i) = s.pi t ∩ s.pi t₁ :=
ext fun x => by simp only [forall_and, mem_pi, mem_inter_iff]
theorem pi_congr (h : s₁ = s₂) (h' : ∀ i ∈ s₁, t₁ i = t₂ i) : s₁.pi t₁ = s₂.pi t₂ :=
h ▸ ext fun _ => forall₂_congr fun i hi => h' i hi ▸ Iff.rfl
theorem pi_eq_empty (hs : i ∈ s) (ht : t i = ∅) : s.pi t = ∅ := by
ext f
simp only [mem_empty_iff_false, not_forall, iff_false, mem_pi, Classical.not_imp]
exact ⟨i, hs, by simp [ht]⟩
theorem univ_pi_eq_empty (ht : t i = ∅) : pi univ t = ∅ :=
pi_eq_empty (mem_univ i) ht
theorem pi_nonempty_iff : (s.pi t).Nonempty ↔ ∀ i, ∃ x, i ∈ s → x ∈ t i := by
simp [Classical.skolem, Set.Nonempty]
theorem univ_pi_nonempty_iff : (pi univ t).Nonempty ↔ ∀ i, (t i).Nonempty := by
simp [Classical.skolem, Set.Nonempty]
theorem pi_eq_empty_iff : s.pi t = ∅ ↔ ∃ i, IsEmpty (α i) ∨ i ∈ s ∧ t i = ∅ := by
rw [← not_nonempty_iff_eq_empty, pi_nonempty_iff]
push_neg
refine exists_congr fun i => ?_
cases isEmpty_or_nonempty (α i) <;> simp [*, forall_and, eq_empty_iff_forall_not_mem]
@[simp]
theorem univ_pi_eq_empty_iff : pi univ t = ∅ ↔ ∃ i, t i = ∅ := by
simp [← not_nonempty_iff_eq_empty, univ_pi_nonempty_iff]
@[simp]
theorem univ_pi_empty [h : Nonempty ι] : pi univ (fun _ => ∅ : ∀ i, Set (α i)) = ∅ :=
univ_pi_eq_empty_iff.2 <| h.elim fun x => ⟨x, rfl⟩
@[simp]
theorem disjoint_univ_pi : Disjoint (pi univ t₁) (pi univ t₂) ↔ ∃ i, Disjoint (t₁ i) (t₂ i) := by
simp only [disjoint_iff_inter_eq_empty, ← pi_inter_distrib, univ_pi_eq_empty_iff]
theorem Disjoint.set_pi (hi : i ∈ s) (ht : Disjoint (t₁ i) (t₂ i)) : Disjoint (s.pi t₁) (s.pi t₂) :=
disjoint_left.2 fun _ h₁ h₂ => disjoint_left.1 ht (h₁ _ hi) (h₂ _ hi)
theorem uniqueElim_preimage [Unique ι] (t : ∀ i, Set (α i)) :
uniqueElim ⁻¹' pi univ t = t (default : ι) := by ext; simp [Unique.forall_iff]
section Nonempty
variable [∀ i, Nonempty (α i)]
theorem pi_eq_empty_iff' : s.pi t = ∅ ↔ ∃ i ∈ s, t i = ∅ := by simp [pi_eq_empty_iff]
@[simp]
theorem disjoint_pi : Disjoint (s.pi t₁) (s.pi t₂) ↔ ∃ i ∈ s, Disjoint (t₁ i) (t₂ i) := by
simp only [disjoint_iff_inter_eq_empty, ← pi_inter_distrib, pi_eq_empty_iff']
end Nonempty
@[simp]
theorem insert_pi (i : ι) (s : Set ι) (t : ∀ i, Set (α i)) :
pi (insert i s) t = eval i ⁻¹' t i ∩ pi s t := by
ext
simp [pi, or_imp, forall_and]
@[simp]
theorem singleton_pi (i : ι) (t : ∀ i, Set (α i)) : pi {i} t = eval i ⁻¹' t i := by
ext
simp [pi]
theorem singleton_pi' (i : ι) (t : ∀ i, Set (α i)) : pi {i} t = { x | x i ∈ t i } :=
singleton_pi i t
theorem univ_pi_singleton (f : ∀ i, α i) : (pi univ fun i => {f i}) = ({f} : Set (∀ i, α i)) :=
ext fun g => by simp [funext_iff]
theorem preimage_pi (s : Set ι) (t : ∀ i, Set (β i)) (f : ∀ i, α i → β i) :
(fun (g : ∀ i, α i) i => f _ (g i)) ⁻¹' s.pi t = s.pi fun i => f i ⁻¹' t i :=
rfl
theorem pi_if {p : ι → Prop} [h : DecidablePred p] (s : Set ι) (t₁ t₂ : ∀ i, Set (α i)) :
(pi s fun i => if p i then t₁ i else t₂ i) =
pi ({ i ∈ s | p i }) t₁ ∩ pi ({ i ∈ s | ¬p i }) t₂ := by
ext f
refine ⟨fun h => ?_, ?_⟩
· constructor <;>
· rintro i ⟨his, hpi⟩
simpa [*] using h i
· rintro ⟨ht₁, ht₂⟩ i his
by_cases p i <;> simp_all
theorem union_pi : (s₁ ∪ s₂).pi t = s₁.pi t ∩ s₂.pi t := by
simp [pi, or_imp, forall_and, setOf_and]
| Mathlib/Data/Set/Prod.lean | 735 | 738 | theorem union_pi_inter
(ht₁ : ∀ i ∉ s₁, t₁ i = univ) (ht₂ : ∀ i ∉ s₂, t₂ i = univ) :
(s₁ ∪ s₂).pi (fun i ↦ t₁ i ∩ t₂ i) = s₁.pi t₁ ∩ s₂.pi t₂ := by | ext x |
/-
Copyright (c) 2023 Peter Nelson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Peter Nelson
-/
import Mathlib.SetTheory.Cardinal.Finite
import Mathlib.Data.Set.Finite.Powerset
/-!
# Noncomputable Set Cardinality
We define the cardinality of set `s` as a term `Set.encard s : ℕ∞` and a term `Set.ncard s : ℕ`.
The latter takes the junk value of zero if `s` is infinite. Both functions are noncomputable, and
are defined in terms of `ENat.card` (which takes a type as its argument); this file can be seen
as an API for the same function in the special case where the type is a coercion of a `Set`,
allowing for smoother interactions with the `Set` API.
`Set.encard` never takes junk values, so is more mathematically natural than `Set.ncard`, even
though it takes values in a less convenient type. It is probably the right choice in settings where
one is concerned with the cardinalities of sets that may or may not be infinite.
`Set.ncard` has a nicer codomain, but when using it, `Set.Finite` hypotheses are normally needed to
make sure its values are meaningful. More generally, `Set.ncard` is intended to be used over the
obvious alternative `Finset.card` when finiteness is 'propositional' rather than 'structural'.
When working with sets that are finite by virtue of their definition, then `Finset.card` probably
makes more sense. One setting where `Set.ncard` works nicely is in a type `α` with `[Finite α]`,
where every set is automatically finite. In this setting, we use default arguments and a simple
tactic so that finiteness goals are discharged automatically in `Set.ncard` theorems.
## Main Definitions
* `Set.encard s` is the cardinality of the set `s` as an extended natural number, with value `⊤` if
`s` is infinite.
* `Set.ncard s` is the cardinality of the set `s` as a natural number, provided `s` is Finite.
If `s` is Infinite, then `Set.ncard s = 0`.
* `toFinite_tac` is a tactic that tries to synthesize a `Set.Finite s` argument with
`Set.toFinite`. This will work for `s : Set α` where there is a `Finite α` instance.
## Implementation Notes
The theorems in this file are very similar to those in `Data.Finset.Card`, but with `Set` operations
instead of `Finset`. We first prove all the theorems for `Set.encard`, and then derive most of the
`Set.ncard` results as a consequence. Things are done this way to avoid reliance on the `Finset` API
for theorems about infinite sets, and to allow for a refactor that removes or modifies `Set.ncard`
in the future.
Nearly all the theorems for `Set.ncard` require finiteness of one or more of their arguments. We
provide this assumption with a default argument of the form `(hs : s.Finite := by toFinite_tac)`,
where `toFinite_tac` will find an `s.Finite` term in the cases where `s` is a set in a `Finite`
type.
Often, where there are two set arguments `s` and `t`, the finiteness of one follows from the other
in the context of the theorem, in which case we only include the ones that are needed, and derive
the other inside the proof. A few of the theorems, such as `ncard_union_le` do not require
finiteness arguments; they are true by coincidence due to junk values.
-/
namespace Set
variable {α β : Type*} {s t : Set α}
/-- The cardinality of a set as a term in `ℕ∞` -/
noncomputable def encard (s : Set α) : ℕ∞ := ENat.card s
@[simp] theorem encard_univ_coe (s : Set α) : encard (univ : Set s) = encard s := by
rw [encard, encard, ENat.card_congr (Equiv.Set.univ ↑s)]
theorem encard_univ (α : Type*) :
encard (univ : Set α) = ENat.card α := by
rw [encard, ENat.card_congr (Equiv.Set.univ α)]
theorem Finite.encard_eq_coe_toFinset_card (h : s.Finite) : s.encard = h.toFinset.card := by
have := h.fintype
rw [encard, ENat.card_eq_coe_fintype_card, toFinite_toFinset, toFinset_card]
theorem encard_eq_coe_toFinset_card (s : Set α) [Fintype s] : encard s = s.toFinset.card := by
have h := toFinite s
rw [h.encard_eq_coe_toFinset_card, toFinite_toFinset]
@[simp] theorem toENat_cardinalMk (s : Set α) : (Cardinal.mk s).toENat = s.encard := rfl
theorem toENat_cardinalMk_subtype (P : α → Prop) :
(Cardinal.mk {x // P x}).toENat = {x | P x}.encard :=
rfl
@[simp] theorem coe_fintypeCard (s : Set α) [Fintype s] : Fintype.card s = s.encard := by
simp [encard_eq_coe_toFinset_card]
@[simp, norm_cast] theorem encard_coe_eq_coe_finsetCard (s : Finset α) :
encard (s : Set α) = s.card := by
rw [Finite.encard_eq_coe_toFinset_card (Finset.finite_toSet s)]; simp
@[simp] theorem Infinite.encard_eq {s : Set α} (h : s.Infinite) : s.encard = ⊤ := by
have := h.to_subtype
rw [encard, ENat.card_eq_top_of_infinite]
@[simp] theorem encard_eq_zero : s.encard = 0 ↔ s = ∅ := by
rw [encard, ENat.card_eq_zero_iff_empty, isEmpty_subtype, eq_empty_iff_forall_not_mem]
@[simp] theorem encard_empty : (∅ : Set α).encard = 0 := by
rw [encard_eq_zero]
theorem nonempty_of_encard_ne_zero (h : s.encard ≠ 0) : s.Nonempty := by
rwa [nonempty_iff_ne_empty, Ne, ← encard_eq_zero]
theorem encard_ne_zero : s.encard ≠ 0 ↔ s.Nonempty := by
rw [ne_eq, encard_eq_zero, nonempty_iff_ne_empty]
@[simp] theorem encard_pos : 0 < s.encard ↔ s.Nonempty := by
rw [pos_iff_ne_zero, encard_ne_zero]
protected alias ⟨_, Nonempty.encard_pos⟩ := encard_pos
@[simp] theorem encard_singleton (e : α) : ({e} : Set α).encard = 1 := by
rw [encard, ENat.card_eq_coe_fintype_card, Fintype.card_ofSubsingleton, Nat.cast_one]
theorem encard_union_eq (h : Disjoint s t) : (s ∪ t).encard = s.encard + t.encard := by
classical
simp [encard, ENat.card_congr (Equiv.Set.union h)]
theorem encard_insert_of_not_mem {a : α} (has : a ∉ s) : (insert a s).encard = s.encard + 1 := by
rw [← union_singleton, encard_union_eq (by simpa), encard_singleton]
theorem Finite.encard_lt_top (h : s.Finite) : s.encard < ⊤ := by
induction s, h using Set.Finite.induction_on with
| empty => simp
| insert hat _ ht' =>
rw [encard_insert_of_not_mem hat]
exact lt_tsub_iff_right.1 ht'
theorem Finite.encard_eq_coe (h : s.Finite) : s.encard = ENat.toNat s.encard :=
(ENat.coe_toNat h.encard_lt_top.ne).symm
theorem Finite.exists_encard_eq_coe (h : s.Finite) : ∃ (n : ℕ), s.encard = n :=
⟨_, h.encard_eq_coe⟩
@[simp] theorem encard_lt_top_iff : s.encard < ⊤ ↔ s.Finite :=
⟨fun h ↦ by_contra fun h' ↦ h.ne (Infinite.encard_eq h'), Finite.encard_lt_top⟩
@[simp] theorem encard_eq_top_iff : s.encard = ⊤ ↔ s.Infinite := by
rw [← not_iff_not, ← Ne, ← lt_top_iff_ne_top, encard_lt_top_iff, not_infinite]
alias ⟨_, encard_eq_top⟩ := encard_eq_top_iff
theorem encard_ne_top_iff : s.encard ≠ ⊤ ↔ s.Finite := by
simp
theorem finite_of_encard_le_coe {k : ℕ} (h : s.encard ≤ k) : s.Finite := by
rw [← encard_lt_top_iff]; exact h.trans_lt (WithTop.coe_lt_top _)
theorem finite_of_encard_eq_coe {k : ℕ} (h : s.encard = k) : s.Finite :=
finite_of_encard_le_coe h.le
theorem encard_le_coe_iff {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ ∃ (n₀ : ℕ), s.encard = n₀ ∧ n₀ ≤ k :=
⟨fun h ↦ ⟨finite_of_encard_le_coe h, by rwa [ENat.le_coe_iff] at h⟩,
fun ⟨_,⟨n₀,hs, hle⟩⟩ ↦ by rwa [hs, Nat.cast_le]⟩
@[simp]
theorem encard_prod : (s ×ˢ t).encard = s.encard * t.encard := by
simp [Set.encard, ENat.card_congr (Equiv.Set.prod ..)]
section Lattice
theorem encard_le_encard (h : s ⊆ t) : s.encard ≤ t.encard := by
rw [← union_diff_cancel h, encard_union_eq disjoint_sdiff_right]; exact le_self_add
@[deprecated (since := "2025-01-05")] alias encard_le_card := encard_le_encard
theorem encard_mono {α : Type*} : Monotone (encard : Set α → ℕ∞) :=
fun _ _ ↦ encard_le_encard
theorem encard_diff_add_encard_of_subset (h : s ⊆ t) : (t \ s).encard + s.encard = t.encard := by
rw [← encard_union_eq disjoint_sdiff_left, diff_union_self, union_eq_self_of_subset_right h]
@[simp] theorem one_le_encard_iff_nonempty : 1 ≤ s.encard ↔ s.Nonempty := by
rw [nonempty_iff_ne_empty, Ne, ← encard_eq_zero, ENat.one_le_iff_ne_zero]
theorem encard_diff_add_encard_inter (s t : Set α) :
(s \ t).encard + (s ∩ t).encard = s.encard := by
rw [← encard_union_eq (disjoint_of_subset_right inter_subset_right disjoint_sdiff_left),
diff_union_inter]
theorem encard_union_add_encard_inter (s t : Set α) :
(s ∪ t).encard + (s ∩ t).encard = s.encard + t.encard := by
rw [← diff_union_self, encard_union_eq disjoint_sdiff_left, add_right_comm,
encard_diff_add_encard_inter]
theorem encard_eq_encard_iff_encard_diff_eq_encard_diff (h : (s ∩ t).Finite) :
s.encard = t.encard ↔ (s \ t).encard = (t \ s).encard := by
rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s,
WithTop.add_right_inj h.encard_lt_top.ne]
theorem encard_le_encard_iff_encard_diff_le_encard_diff (h : (s ∩ t).Finite) :
s.encard ≤ t.encard ↔ (s \ t).encard ≤ (t \ s).encard := by
rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s,
WithTop.add_le_add_iff_right h.encard_lt_top.ne]
theorem encard_lt_encard_iff_encard_diff_lt_encard_diff (h : (s ∩ t).Finite) :
s.encard < t.encard ↔ (s \ t).encard < (t \ s).encard := by
rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s,
WithTop.add_lt_add_iff_right h.encard_lt_top.ne]
theorem encard_union_le (s t : Set α) : (s ∪ t).encard ≤ s.encard + t.encard := by
rw [← encard_union_add_encard_inter]; exact le_self_add
theorem finite_iff_finite_of_encard_eq_encard (h : s.encard = t.encard) : s.Finite ↔ t.Finite := by
rw [← encard_lt_top_iff, ← encard_lt_top_iff, h]
theorem infinite_iff_infinite_of_encard_eq_encard (h : s.encard = t.encard) :
s.Infinite ↔ t.Infinite := by rw [← encard_eq_top_iff, h, encard_eq_top_iff]
theorem Finite.finite_of_encard_le {s : Set α} {t : Set β} (hs : s.Finite)
(h : t.encard ≤ s.encard) : t.Finite :=
encard_lt_top_iff.1 (h.trans_lt hs.encard_lt_top)
lemma Finite.eq_of_subset_of_encard_le' (ht : t.Finite) (hst : s ⊆ t) (hts : t.encard ≤ s.encard) :
s = t := by
rw [← zero_add (a := encard s), ← encard_diff_add_encard_of_subset hst] at hts
have hdiff := WithTop.le_of_add_le_add_right (ht.subset hst).encard_lt_top.ne hts
rw [nonpos_iff_eq_zero, encard_eq_zero, diff_eq_empty] at hdiff
exact hst.antisymm hdiff
theorem Finite.eq_of_subset_of_encard_le (hs : s.Finite) (hst : s ⊆ t)
(hts : t.encard ≤ s.encard) : s = t :=
(hs.finite_of_encard_le hts).eq_of_subset_of_encard_le' hst hts
theorem Finite.encard_lt_encard (hs : s.Finite) (h : s ⊂ t) : s.encard < t.encard :=
(encard_mono h.subset).lt_of_ne fun he ↦ h.ne (hs.eq_of_subset_of_encard_le h.subset he.symm.le)
theorem encard_strictMono [Finite α] : StrictMono (encard : Set α → ℕ∞) :=
fun _ _ h ↦ (toFinite _).encard_lt_encard h
theorem encard_diff_add_encard (s t : Set α) : (s \ t).encard + t.encard = (s ∪ t).encard := by
rw [← encard_union_eq disjoint_sdiff_left, diff_union_self]
theorem encard_le_encard_diff_add_encard (s t : Set α) : s.encard ≤ (s \ t).encard + t.encard :=
(encard_mono subset_union_left).trans_eq (encard_diff_add_encard _ _).symm
theorem tsub_encard_le_encard_diff (s t : Set α) : s.encard - t.encard ≤ (s \ t).encard := by
rw [tsub_le_iff_left, add_comm]; apply encard_le_encard_diff_add_encard
theorem encard_add_encard_compl (s : Set α) : s.encard + sᶜ.encard = (univ : Set α).encard := by
rw [← encard_union_eq disjoint_compl_right, union_compl_self]
end Lattice
section InsertErase
variable {a b : α}
theorem encard_insert_le (s : Set α) (x : α) : (insert x s).encard ≤ s.encard + 1 := by
rw [← union_singleton, ← encard_singleton x]; apply encard_union_le
theorem encard_singleton_inter (s : Set α) (x : α) : ({x} ∩ s).encard ≤ 1 := by
rw [← encard_singleton x]; exact encard_le_encard inter_subset_left
theorem encard_diff_singleton_add_one (h : a ∈ s) :
(s \ {a}).encard + 1 = s.encard := by
rw [← encard_insert_of_not_mem (fun h ↦ h.2 rfl), insert_diff_singleton, insert_eq_of_mem h]
theorem encard_diff_singleton_of_mem (h : a ∈ s) :
(s \ {a}).encard = s.encard - 1 := by
rw [← encard_diff_singleton_add_one h, ← WithTop.add_right_inj WithTop.one_ne_top,
tsub_add_cancel_of_le (self_le_add_left _ _)]
theorem encard_tsub_one_le_encard_diff_singleton (s : Set α) (x : α) :
s.encard - 1 ≤ (s \ {x}).encard := by
rw [← encard_singleton x]; apply tsub_encard_le_encard_diff
theorem encard_exchange (ha : a ∉ s) (hb : b ∈ s) : (insert a (s \ {b})).encard = s.encard := by
rw [encard_insert_of_not_mem, encard_diff_singleton_add_one hb]
simp_all only [not_true, mem_diff, mem_singleton_iff, false_and, not_false_eq_true]
theorem encard_exchange' (ha : a ∉ s) (hb : b ∈ s) : (insert a s \ {b}).encard = s.encard := by
rw [← insert_diff_singleton_comm (by rintro rfl; exact ha hb), encard_exchange ha hb]
theorem encard_eq_add_one_iff {k : ℕ∞} :
s.encard = k + 1 ↔ (∃ a t, ¬a ∈ t ∧ insert a t = s ∧ t.encard = k) := by
refine ⟨fun h ↦ ?_, ?_⟩
· obtain ⟨a, ha⟩ := nonempty_of_encard_ne_zero (s := s) (by simp [h])
refine ⟨a, s \ {a}, fun h ↦ h.2 rfl, by rwa [insert_diff_singleton, insert_eq_of_mem], ?_⟩
rw [← WithTop.add_right_inj WithTop.one_ne_top, ← h,
encard_diff_singleton_add_one ha]
rintro ⟨a, t, h, rfl, rfl⟩
rw [encard_insert_of_not_mem h]
/-- Every set is either empty, infinite, or can have its `encard` reduced by a removal. Intended
for well-founded induction on the value of `encard`. -/
theorem eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt (s : Set α) :
s = ∅ ∨ s.encard = ⊤ ∨ ∃ a ∈ s, (s \ {a}).encard < s.encard := by
refine s.eq_empty_or_nonempty.elim Or.inl (Or.inr ∘ fun ⟨a,ha⟩ ↦
(s.finite_or_infinite.elim (fun hfin ↦ Or.inr ⟨a, ha, ?_⟩) (Or.inl ∘ Infinite.encard_eq)))
rw [← encard_diff_singleton_add_one ha]; nth_rw 1 [← add_zero (encard _)]
exact WithTop.add_lt_add_left hfin.diff.encard_lt_top.ne zero_lt_one
end InsertErase
section SmallSets
theorem encard_pair {x y : α} (hne : x ≠ y) : ({x, y} : Set α).encard = 2 := by
rw [encard_insert_of_not_mem (by simpa), ← one_add_one_eq_two,
WithTop.add_right_inj WithTop.one_ne_top, encard_singleton]
theorem encard_eq_one : s.encard = 1 ↔ ∃ x, s = {x} := by
refine ⟨fun h ↦ ?_, fun ⟨x, hx⟩ ↦ by rw [hx, encard_singleton]⟩
obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp)
exact ⟨x, ((finite_singleton x).eq_of_subset_of_encard_le (by simpa) (by simp [h])).symm⟩
theorem encard_le_one_iff_eq : s.encard ≤ 1 ↔ s = ∅ ∨ ∃ x, s = {x} := by
rw [le_iff_lt_or_eq, lt_iff_not_le, ENat.one_le_iff_ne_zero, not_not, encard_eq_zero,
encard_eq_one]
theorem encard_le_one_iff : s.encard ≤ 1 ↔ ∀ a b, a ∈ s → b ∈ s → a = b := by
rw [encard_le_one_iff_eq, or_iff_not_imp_left, ← Ne, ← nonempty_iff_ne_empty]
refine ⟨fun h a b has hbs ↦ ?_,
fun h ⟨x, hx⟩ ↦ ⟨x, ((singleton_subset_iff.2 hx).antisymm' (fun y hy ↦ h _ _ hy hx))⟩⟩
obtain ⟨x, rfl⟩ := h ⟨_, has⟩
rw [(has : a = x), (hbs : b = x)]
theorem encard_le_one_iff_subsingleton : s.encard ≤ 1 ↔ s.Subsingleton := by
rw [encard_le_one_iff, Set.Subsingleton]
tauto
theorem one_lt_encard_iff_nontrivial : 1 < s.encard ↔ s.Nontrivial := by
rw [← not_iff_not, not_lt, Set.not_nontrivial_iff, ← encard_le_one_iff_subsingleton]
theorem one_lt_encard_iff : 1 < s.encard ↔ ∃ a b, a ∈ s ∧ b ∈ s ∧ a ≠ b := by
rw [← not_iff_not, not_exists, not_lt, encard_le_one_iff]; aesop
theorem exists_ne_of_one_lt_encard (h : 1 < s.encard) (a : α) : ∃ b ∈ s, b ≠ a := by
by_contra! h'
obtain ⟨b, b', hb, hb', hne⟩ := one_lt_encard_iff.1 h
apply hne
rw [h' b hb, h' b' hb']
theorem encard_eq_two : s.encard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by
refine ⟨fun h ↦ ?_, fun ⟨x, y, hne, hs⟩ ↦ by rw [hs, encard_pair hne]⟩
obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp)
rw [← insert_eq_of_mem hx, ← insert_diff_singleton, encard_insert_of_not_mem (fun h ↦ h.2 rfl),
← one_add_one_eq_two, WithTop.add_right_inj (WithTop.one_ne_top), encard_eq_one] at h
obtain ⟨y, h⟩ := h
refine ⟨x, y, by rintro rfl; exact (h.symm.subset rfl).2 rfl, ?_⟩
rw [← h, insert_diff_singleton, insert_eq_of_mem hx]
theorem encard_eq_three {α : Type u_1} {s : Set α} :
encard s = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z} := by
refine ⟨fun h ↦ ?_, fun ⟨x, y, z, hxy, hyz, hxz, hs⟩ ↦ ?_⟩
· obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp)
rw [← insert_eq_of_mem hx, ← insert_diff_singleton,
encard_insert_of_not_mem (fun h ↦ h.2 rfl), (by exact rfl : (3 : ℕ∞) = 2 + 1),
WithTop.add_right_inj WithTop.one_ne_top, encard_eq_two] at h
obtain ⟨y, z, hne, hs⟩ := h
refine ⟨x, y, z, ?_, ?_, hne, ?_⟩
· rintro rfl; exact (hs.symm.subset (Or.inl rfl)).2 rfl
· rintro rfl; exact (hs.symm.subset (Or.inr rfl)).2 rfl
rw [← hs, insert_diff_singleton, insert_eq_of_mem hx]
rw [hs, encard_insert_of_not_mem, encard_insert_of_not_mem, encard_singleton] <;> aesop
theorem Nat.encard_range (k : ℕ) : {i | i < k}.encard = k := by
convert encard_coe_eq_coe_finsetCard (Finset.range k) using 1
· rw [Finset.coe_range, Iio_def]
rw [Finset.card_range]
end SmallSets
theorem Finite.eq_insert_of_subset_of_encard_eq_succ (hs : s.Finite) (h : s ⊆ t)
(hst : t.encard = s.encard + 1) : ∃ a, t = insert a s := by
rw [← encard_diff_add_encard_of_subset h, add_comm, WithTop.add_left_inj hs.encard_lt_top.ne,
encard_eq_one] at hst
obtain ⟨x, hx⟩ := hst; use x; rw [← diff_union_of_subset h, hx, singleton_union]
theorem exists_subset_encard_eq {k : ℕ∞} (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.encard = k := by
revert hk
refine ENat.nat_induction k (fun _ ↦ ⟨∅, empty_subset _, by simp⟩) (fun n IH hle ↦ ?_) ?_
· obtain ⟨t₀, ht₀s, ht₀⟩ := IH (le_trans (by simp) hle)
simp only [Nat.cast_succ] at *
have hne : t₀ ≠ s := by
rintro rfl; rw [ht₀, ← Nat.cast_one, ← Nat.cast_add, Nat.cast_le] at hle; simp at hle
obtain ⟨x, hx⟩ := exists_of_ssubset (ht₀s.ssubset_of_ne hne)
exact ⟨insert x t₀, insert_subset hx.1 ht₀s, by rw [encard_insert_of_not_mem hx.2, ht₀]⟩
simp only [top_le_iff, encard_eq_top_iff]
exact fun _ hi ↦ ⟨s, Subset.rfl, hi⟩
theorem exists_superset_subset_encard_eq {k : ℕ∞}
(hst : s ⊆ t) (hsk : s.encard ≤ k) (hkt : k ≤ t.encard) :
∃ r, s ⊆ r ∧ r ⊆ t ∧ r.encard = k := by
obtain (hs | hs) := eq_or_ne s.encard ⊤
· rw [hs, top_le_iff] at hsk; subst hsk; exact ⟨s, Subset.rfl, hst, hs⟩
obtain ⟨k, rfl⟩ := exists_add_of_le hsk
obtain ⟨k', hk'⟩ := exists_add_of_le hkt
have hk : k ≤ encard (t \ s) := by
rw [← encard_diff_add_encard_of_subset hst, add_comm] at hkt
exact WithTop.le_of_add_le_add_right hs hkt
obtain ⟨r', hr', rfl⟩ := exists_subset_encard_eq hk
refine ⟨s ∪ r', subset_union_left, union_subset hst (hr'.trans diff_subset), ?_⟩
rw [encard_union_eq (disjoint_of_subset_right hr' disjoint_sdiff_right)]
section Function
variable {s : Set α} {t : Set β} {f : α → β}
theorem InjOn.encard_image (h : InjOn f s) : (f '' s).encard = s.encard := by
rw [encard, ENat.card_image_of_injOn h, encard]
theorem encard_congr (e : s ≃ t) : s.encard = t.encard := by
rw [← encard_univ_coe, ← encard_univ_coe t, encard_univ, encard_univ, ENat.card_congr e]
theorem _root_.Function.Injective.encard_image (hf : f.Injective) (s : Set α) :
(f '' s).encard = s.encard :=
hf.injOn.encard_image
theorem _root_.Function.Embedding.encard_le (e : s ↪ t) : s.encard ≤ t.encard := by
rw [← encard_univ_coe, ← e.injective.encard_image, ← Subtype.coe_injective.encard_image]
exact encard_mono (by simp)
theorem encard_image_le (f : α → β) (s : Set α) : (f '' s).encard ≤ s.encard := by
obtain (h | h) := isEmpty_or_nonempty α
· rw [s.eq_empty_of_isEmpty]; simp
rw [← (f.invFunOn_injOn_image s).encard_image]
apply encard_le_encard
exact f.invFunOn_image_image_subset s
theorem Finite.injOn_of_encard_image_eq (hs : s.Finite) (h : (f '' s).encard = s.encard) :
InjOn f s := by
obtain (h' | hne) := isEmpty_or_nonempty α
· rw [s.eq_empty_of_isEmpty]; simp
rw [← (f.invFunOn_injOn_image s).encard_image] at h
rw [injOn_iff_invFunOn_image_image_eq_self]
exact hs.eq_of_subset_of_encard_le' (f.invFunOn_image_image_subset s) h.symm.le
theorem encard_preimage_of_injective_subset_range (hf : f.Injective) (ht : t ⊆ range f) :
(f ⁻¹' t).encard = t.encard := by
rw [← hf.encard_image, image_preimage_eq_inter_range, inter_eq_self_of_subset_left ht]
lemma encard_preimage_of_bijective (hf : f.Bijective) (t : Set β) : (f ⁻¹' t).encard = t.encard :=
encard_preimage_of_injective_subset_range hf.injective (by simp [hf.surjective.range_eq])
theorem encard_le_encard_of_injOn (hf : MapsTo f s t) (f_inj : InjOn f s) :
s.encard ≤ t.encard := by
rw [← f_inj.encard_image]; apply encard_le_encard; rintro _ ⟨x, hx, rfl⟩; exact hf hx
theorem Finite.exists_injOn_of_encard_le [Nonempty β] {s : Set α} {t : Set β} (hs : s.Finite)
(hle : s.encard ≤ t.encard) : ∃ (f : α → β), s ⊆ f ⁻¹' t ∧ InjOn f s := by
classical
obtain (rfl | h | ⟨a, has, -⟩) := s.eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt
· simp
· exact (encard_ne_top_iff.mpr hs h).elim
obtain ⟨b, hbt⟩ := encard_pos.1 ((encard_pos.2 ⟨_, has⟩).trans_le hle)
have hle' : (s \ {a}).encard ≤ (t \ {b}).encard := by
rwa [← WithTop.add_le_add_iff_right WithTop.one_ne_top,
encard_diff_singleton_add_one has, encard_diff_singleton_add_one hbt]
obtain ⟨f₀, hf₀s, hinj⟩ := exists_injOn_of_encard_le hs.diff hle'
simp only [preimage_diff, subset_def, mem_diff, mem_singleton_iff, mem_preimage, and_imp] at hf₀s
use Function.update f₀ a b
rw [← insert_eq_of_mem has, ← insert_diff_singleton, injOn_insert (fun h ↦ h.2 rfl)]
simp only [mem_diff, mem_singleton_iff, not_true, and_false, insert_diff_singleton, subset_def,
mem_insert_iff, mem_preimage, ne_eq, Function.update_apply, forall_eq_or_imp, ite_true, and_imp,
mem_image, ite_eq_left_iff, not_exists, not_and, not_forall, exists_prop, and_iff_right hbt]
refine ⟨?_, ?_, fun x hxs hxa ↦ ⟨hxa, (hf₀s x hxs hxa).2⟩⟩
· rintro x hx; split_ifs with h
· assumption
· exact (hf₀s x hx h).1
exact InjOn.congr hinj (fun x ⟨_, hxa⟩ ↦ by rwa [Function.update_of_ne])
termination_by encard s
theorem Finite.exists_bijOn_of_encard_eq [Nonempty β] (hs : s.Finite) (h : s.encard = t.encard) :
∃ (f : α → β), BijOn f s t := by
obtain ⟨f, hf, hinj⟩ := hs.exists_injOn_of_encard_le h.le; use f
convert hinj.bijOn_image
rw [(hs.image f).eq_of_subset_of_encard_le (image_subset_iff.mpr hf)
(h.symm.trans hinj.encard_image.symm).le]
end Function
section ncard
open Nat
/-- A tactic (for use in default params) that applies `Set.toFinite` to synthesize a `Set.Finite`
term. -/
syntax "toFinite_tac" : tactic
macro_rules
| `(tactic| toFinite_tac) => `(tactic| apply Set.toFinite)
/-- A tactic useful for transferring proofs for `encard` to their corresponding `card` statements -/
syntax "to_encard_tac" : tactic
macro_rules
| `(tactic| to_encard_tac) => `(tactic|
simp only [← Nat.cast_le (α := ℕ∞), ← Nat.cast_inj (R := ℕ∞), Nat.cast_add, Nat.cast_one])
/-- The cardinality of `s : Set α` . Has the junk value `0` if `s` is infinite -/
noncomputable def ncard (s : Set α) : ℕ := ENat.toNat s.encard
theorem ncard_def (s : Set α) : s.ncard = ENat.toNat s.encard := rfl
theorem Finite.cast_ncard_eq (hs : s.Finite) : s.ncard = s.encard := by
rwa [ncard, ENat.coe_toNat_eq_self, ne_eq, encard_eq_top_iff, Set.Infinite, not_not]
lemma ncard_le_encard (s : Set α) : s.ncard ≤ s.encard := ENat.coe_toNat_le_self _
theorem Nat.card_coe_set_eq (s : Set α) : Nat.card s = s.ncard := by
obtain (h | h) := s.finite_or_infinite
· have := h.fintype
rw [ncard, h.encard_eq_coe_toFinset_card, Nat.card_eq_fintype_card,
toFinite_toFinset, toFinset_card, ENat.toNat_coe]
have := infinite_coe_iff.2 h
rw [ncard, h.encard_eq, Nat.card_eq_zero_of_infinite, ENat.toNat_top]
theorem ncard_eq_toFinset_card (s : Set α) (hs : s.Finite := by toFinite_tac) :
s.ncard = hs.toFinset.card := by
rw [← Nat.card_coe_set_eq, @Nat.card_eq_fintype_card _ hs.fintype,
@Finite.card_toFinset _ _ hs.fintype hs]
theorem ncard_eq_toFinset_card' (s : Set α) [Fintype s] :
s.ncard = s.toFinset.card := by
simp [← Nat.card_coe_set_eq, Nat.card_eq_fintype_card]
lemma cast_ncard {s : Set α} (hs : s.Finite) :
(s.ncard : Cardinal) = Cardinal.mk s := @Nat.cast_card _ hs
theorem encard_le_coe_iff_finite_ncard_le {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ s.ncard ≤ k := by
rw [encard_le_coe_iff, and_congr_right_iff]
exact fun hfin ↦ ⟨fun ⟨n₀, hn₀, hle⟩ ↦ by rwa [ncard_def, hn₀, ENat.toNat_coe],
fun h ↦ ⟨s.ncard, by rw [hfin.cast_ncard_eq], h⟩⟩
theorem Infinite.ncard (hs : s.Infinite) : s.ncard = 0 := by
rw [← Nat.card_coe_set_eq, @Nat.card_eq_zero_of_infinite _ hs.to_subtype]
@[gcongr]
theorem ncard_le_ncard (hst : s ⊆ t) (ht : t.Finite := by toFinite_tac) :
s.ncard ≤ t.ncard := by
rw [← Nat.cast_le (α := ℕ∞), ht.cast_ncard_eq, (ht.subset hst).cast_ncard_eq]
exact encard_mono hst
theorem ncard_mono [Finite α] : @Monotone (Set α) _ _ _ ncard := fun _ _ ↦ ncard_le_ncard
@[simp] theorem ncard_eq_zero (hs : s.Finite := by toFinite_tac) :
s.ncard = 0 ↔ s = ∅ := by
rw [← Nat.cast_inj (R := ℕ∞), hs.cast_ncard_eq, Nat.cast_zero, encard_eq_zero]
@[simp, norm_cast] theorem ncard_coe_Finset (s : Finset α) : (s : Set α).ncard = s.card := by
rw [ncard_eq_toFinset_card _, Finset.finite_toSet_toFinset]
theorem ncard_univ (α : Type*) : (univ : Set α).ncard = Nat.card α := by
rcases finite_or_infinite α with h | h
· have hft := Fintype.ofFinite α
rw [ncard_eq_toFinset_card, Finite.toFinset_univ, Finset.card_univ, Nat.card_eq_fintype_card]
rw [Nat.card_eq_zero_of_infinite, Infinite.ncard]
exact infinite_univ
@[simp] theorem ncard_empty (α : Type*) : (∅ : Set α).ncard = 0 := by
rw [ncard_eq_zero]
| Mathlib/Data/Set/Card.lean | 560 | 561 | theorem ncard_pos (hs : s.Finite := by | toFinite_tac) : 0 < s.ncard ↔ s.Nonempty := by
rw [pos_iff_ne_zero, Ne, ncard_eq_zero hs, nonempty_iff_ne_empty] |
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker
-/
import Mathlib.Algebra.Polynomial.Reverse
import Mathlib.Algebra.Regular.SMul
/-!
# Theory of monic polynomials
We give several tools for proving that polynomials are monic, e.g.
`Monic.mul`, `Monic.map`, `Monic.pow`.
-/
noncomputable section
open Finset
open Polynomial
namespace Polynomial
universe u v y
variable {R : Type u} {S : Type v} {a b : R} {m n : ℕ} {ι : Type y}
section Semiring
variable [Semiring R] {p q r : R[X]}
theorem monic_zero_iff_subsingleton : Monic (0 : R[X]) ↔ Subsingleton R :=
subsingleton_iff_zero_eq_one
theorem not_monic_zero_iff : ¬Monic (0 : R[X]) ↔ (0 : R) ≠ 1 :=
(monic_zero_iff_subsingleton.trans subsingleton_iff_zero_eq_one.symm).not
theorem monic_zero_iff_subsingleton' :
Monic (0 : R[X]) ↔ (∀ f g : R[X], f = g) ∧ ∀ a b : R, a = b :=
Polynomial.monic_zero_iff_subsingleton.trans
⟨by
intro
simp [eq_iff_true_of_subsingleton], fun h => subsingleton_iff.mpr h.2⟩
theorem Monic.as_sum (hp : p.Monic) :
p = X ^ p.natDegree + ∑ i ∈ range p.natDegree, C (p.coeff i) * X ^ i := by
conv_lhs => rw [p.as_sum_range_C_mul_X_pow, sum_range_succ_comm]
suffices C (p.coeff p.natDegree) = 1 by rw [this, one_mul]
exact congr_arg C hp
theorem ne_zero_of_ne_zero_of_monic (hp : p ≠ 0) (hq : Monic q) : q ≠ 0 := by
rintro rfl
rw [Monic.def, leadingCoeff_zero] at hq
rw [← mul_one p, ← C_1, ← hq, C_0, mul_zero] at hp
exact hp rfl
theorem Monic.map [Semiring S] (f : R →+* S) (hp : Monic p) : Monic (p.map f) := by
unfold Monic
nontriviality
have : f p.leadingCoeff ≠ 0 := by
rw [show _ = _ from hp, f.map_one]
exact one_ne_zero
rw [Polynomial.leadingCoeff, coeff_map]
suffices p.coeff (p.map f).natDegree = 1 by simp [this]
rwa [natDegree_eq_of_degree_eq (degree_map_eq_of_leadingCoeff_ne_zero f this)]
theorem monic_C_mul_of_mul_leadingCoeff_eq_one {b : R} (hp : b * p.leadingCoeff = 1) :
Monic (C b * p) := by
unfold Monic
nontriviality
rw [leadingCoeff_mul' _] <;> simp [leadingCoeff_C b, hp]
theorem monic_mul_C_of_leadingCoeff_mul_eq_one {b : R} (hp : p.leadingCoeff * b = 1) :
Monic (p * C b) := by
unfold Monic
nontriviality
rw [leadingCoeff_mul' _] <;> simp [leadingCoeff_C b, hp]
theorem monic_of_degree_le (n : ℕ) (H1 : degree p ≤ n) (H2 : coeff p n = 1) : Monic p :=
Decidable.byCases
(fun H : degree p < n => eq_of_zero_eq_one (H2 ▸ (coeff_eq_zero_of_degree_lt H).symm) _ _)
fun H : ¬degree p < n => by
rwa [Monic, Polynomial.leadingCoeff, natDegree, (lt_or_eq_of_le H1).resolve_left H]
theorem monic_X_pow_add {n : ℕ} (H : degree p < n) : Monic (X ^ n + p) :=
monic_of_degree_le n
(le_trans (degree_add_le _ _) (max_le (degree_X_pow_le _) (le_of_lt H)))
(by rw [coeff_add, coeff_X_pow, if_pos rfl, coeff_eq_zero_of_degree_lt H, add_zero])
variable (a) in
theorem monic_X_pow_add_C {n : ℕ} (h : n ≠ 0) : (X ^ n + C a).Monic :=
monic_X_pow_add <| (lt_of_le_of_lt degree_C_le
(by simp only [Nat.cast_pos, Nat.pos_iff_ne_zero, ne_eq, h, not_false_eq_true]))
theorem monic_X_add_C (x : R) : Monic (X + C x) :=
pow_one (X : R[X]) ▸ monic_X_pow_add_C x one_ne_zero
theorem Monic.mul (hp : Monic p) (hq : Monic q) : Monic (p * q) :=
letI := Classical.decEq R
if h0 : (0 : R) = 1 then
haveI := subsingleton_of_zero_eq_one h0
Subsingleton.elim _ _
else by
have : p.leadingCoeff * q.leadingCoeff ≠ 0 := by
simp [Monic.def.1 hp, Monic.def.1 hq, Ne.symm h0]
rw [Monic.def, leadingCoeff_mul' this, Monic.def.1 hp, Monic.def.1 hq, one_mul]
theorem Monic.pow (hp : Monic p) : ∀ n : ℕ, Monic (p ^ n)
| 0 => monic_one
| n + 1 => by
rw [pow_succ]
exact (Monic.pow hp n).mul hp
theorem Monic.add_of_left (hp : Monic p) (hpq : degree q < degree p) : Monic (p + q) := by
rwa [Monic, add_comm, leadingCoeff_add_of_degree_lt hpq]
theorem Monic.add_of_right (hq : Monic q) (hpq : degree p < degree q) : Monic (p + q) := by
rwa [Monic, leadingCoeff_add_of_degree_lt hpq]
theorem Monic.of_mul_monic_left (hp : p.Monic) (hpq : (p * q).Monic) : q.Monic := by
contrapose! hpq
rw [Monic.def] at hpq ⊢
rwa [leadingCoeff_monic_mul hp]
theorem Monic.of_mul_monic_right (hq : q.Monic) (hpq : (p * q).Monic) : p.Monic := by
contrapose! hpq
rw [Monic.def] at hpq ⊢
rwa [leadingCoeff_mul_monic hq]
namespace Monic
lemma comp (hp : p.Monic) (hq : q.Monic) (h : q.natDegree ≠ 0) : (p.comp q).Monic := by
nontriviality R
have : (p.comp q).natDegree = p.natDegree * q.natDegree :=
natDegree_comp_eq_of_mul_ne_zero <| by simp [hp.leadingCoeff, hq.leadingCoeff]
rw [Monic.def, Polynomial.leadingCoeff, this, coeff_comp_degree_mul_degree h, hp.leadingCoeff,
hq.leadingCoeff, one_pow, mul_one]
lemma comp_X_add_C (hp : p.Monic) (r : R) : (p.comp (X + C r)).Monic := by
nontriviality R
refine hp.comp (monic_X_add_C _) fun ha ↦ ?_
rw [natDegree_X_add_C] at ha
exact one_ne_zero ha
@[simp]
theorem natDegree_eq_zero_iff_eq_one (hp : p.Monic) : p.natDegree = 0 ↔ p = 1 := by
constructor <;> intro h
swap
· rw [h]
exact natDegree_one
have : p = C (p.coeff 0) := by
rw [← Polynomial.degree_le_zero_iff]
rwa [Polynomial.natDegree_eq_zero_iff_degree_le_zero] at h
rw [this]
rw [← h, ← Polynomial.leadingCoeff, Monic.def.1 hp, C_1]
@[simp]
theorem degree_le_zero_iff_eq_one (hp : p.Monic) : p.degree ≤ 0 ↔ p = 1 := by
rw [← hp.natDegree_eq_zero_iff_eq_one, natDegree_eq_zero_iff_degree_le_zero]
theorem natDegree_mul (hp : p.Monic) (hq : q.Monic) :
(p * q).natDegree = p.natDegree + q.natDegree := by
nontriviality R
apply natDegree_mul'
simp [hp.leadingCoeff, hq.leadingCoeff]
theorem degree_mul_comm (hp : p.Monic) (q : R[X]) : (p * q).degree = (q * p).degree := by
by_cases h : q = 0
· simp [h]
rw [degree_mul', hp.degree_mul]
· exact add_comm _ _
· rwa [hp.leadingCoeff, one_mul, leadingCoeff_ne_zero]
nonrec theorem natDegree_mul' (hp : p.Monic) (hq : q ≠ 0) :
(p * q).natDegree = p.natDegree + q.natDegree := by
rw [natDegree_mul']
simpa [hp.leadingCoeff, leadingCoeff_ne_zero]
theorem natDegree_mul_comm (hp : p.Monic) (q : R[X]) : (p * q).natDegree = (q * p).natDegree := by
by_cases h : q = 0
· simp [h]
rw [hp.natDegree_mul' h, Polynomial.natDegree_mul', add_comm]
simpa [hp.leadingCoeff, leadingCoeff_ne_zero]
theorem not_dvd_of_natDegree_lt (hp : Monic p) (h0 : q ≠ 0) (hl : natDegree q < natDegree p) :
¬p ∣ q := by
rintro ⟨r, rfl⟩
rw [hp.natDegree_mul' <| right_ne_zero_of_mul h0] at hl
exact hl.not_le (Nat.le_add_right _ _)
theorem not_dvd_of_degree_lt (hp : Monic p) (h0 : q ≠ 0) (hl : degree q < degree p) : ¬p ∣ q :=
Monic.not_dvd_of_natDegree_lt hp h0 <| natDegree_lt_natDegree h0 hl
theorem nextCoeff_mul (hp : Monic p) (hq : Monic q) :
nextCoeff (p * q) = nextCoeff p + nextCoeff q := by
nontriviality
simp only [← coeff_one_reverse]
rw [reverse_mul] <;> simp [hp.leadingCoeff, hq.leadingCoeff, mul_coeff_one, add_comm]
theorem nextCoeff_pow (hp : p.Monic) (n : ℕ) : (p ^ n).nextCoeff = n • p.nextCoeff := by
induction n with
| zero => rw [pow_zero, zero_smul, ← map_one (f := C), nextCoeff_C_eq_zero]
| succ n ih => rw [pow_succ, (hp.pow n).nextCoeff_mul hp, ih, succ_nsmul]
theorem eq_one_of_map_eq_one {S : Type*} [Semiring S] [Nontrivial S] (f : R →+* S) (hp : p.Monic)
(map_eq : p.map f = 1) : p = 1 := by
nontriviality R
have hdeg : p.degree = 0 := by
rw [← degree_map_eq_of_leadingCoeff_ne_zero f _, map_eq, degree_one]
· rw [hp.leadingCoeff, f.map_one]
exact one_ne_zero
have hndeg : p.natDegree = 0 :=
WithBot.coe_eq_coe.mp ((degree_eq_natDegree hp.ne_zero).symm.trans hdeg)
convert eq_C_of_degree_eq_zero hdeg
rw [← hndeg, ← Polynomial.leadingCoeff, hp.leadingCoeff, C.map_one]
theorem natDegree_pow (hp : p.Monic) (n : ℕ) : (p ^ n).natDegree = n * p.natDegree := by
induction n with
| zero => simp
| succ n hn => rw [pow_succ, (hp.pow n).natDegree_mul hp, hn, Nat.succ_mul, add_comm]
end Monic
@[simp]
theorem natDegree_pow_X_add_C [Nontrivial R] (n : ℕ) (r : R) : ((X + C r) ^ n).natDegree = n := by
rw [(monic_X_add_C r).natDegree_pow, natDegree_X_add_C, mul_one]
theorem Monic.eq_one_of_isUnit (hm : Monic p) (hpu : IsUnit p) : p = 1 := by
nontriviality R
obtain ⟨q, h⟩ := hpu.exists_right_inv
have := hm.natDegree_mul' (right_ne_zero_of_mul_eq_one h)
rw [h, natDegree_one, eq_comm, add_eq_zero] at this
exact hm.natDegree_eq_zero_iff_eq_one.mp this.1
theorem Monic.isUnit_iff (hm : p.Monic) : IsUnit p ↔ p = 1 :=
⟨hm.eq_one_of_isUnit, fun h => h.symm ▸ isUnit_one⟩
theorem eq_of_monic_of_associated (hp : p.Monic) (hq : q.Monic) (hpq : Associated p q) : p = q := by
obtain ⟨u, rfl⟩ := hpq
rw [(hp.of_mul_monic_left hq).eq_one_of_isUnit u.isUnit, mul_one]
end Semiring
section CommSemiring
variable [CommSemiring R] {p : R[X]}
theorem monic_multiset_prod_of_monic (t : Multiset ι) (f : ι → R[X]) (ht : ∀ i ∈ t, Monic (f i)) :
Monic (t.map f).prod := by
revert ht
refine t.induction_on ?_ ?_; · simp
intro a t ih ht
rw [Multiset.map_cons, Multiset.prod_cons]
exact (ht _ (Multiset.mem_cons_self _ _)).mul (ih fun _ hi => ht _ (Multiset.mem_cons_of_mem hi))
theorem monic_prod_of_monic (s : Finset ι) (f : ι → R[X]) (hs : ∀ i ∈ s, Monic (f i)) :
Monic (∏ i ∈ s, f i) :=
monic_multiset_prod_of_monic s.1 f hs
theorem monic_finprod_of_monic (α : Type*) (f : α → R[X])
(hf : ∀ i ∈ Function.mulSupport f, Monic (f i)) :
Monic (finprod f) := by
classical
rw [finprod_def]
split_ifs
· exact monic_prod_of_monic _ _ fun a ha => hf a ((Set.Finite.mem_toFinset _).mp ha)
· exact monic_one
theorem Monic.nextCoeff_multiset_prod (t : Multiset ι) (f : ι → R[X]) (h : ∀ i ∈ t, Monic (f i)) :
nextCoeff (t.map f).prod = (t.map fun i => nextCoeff (f i)).sum := by
revert h
refine Multiset.induction_on t ?_ fun a t ih ht => ?_
· simp only [Multiset.not_mem_zero, forall_prop_of_true, forall_prop_of_false, Multiset.map_zero,
Multiset.prod_zero, Multiset.sum_zero, not_false_iff, forall_true_iff]
rw [← C_1]
rw [nextCoeff_C_eq_zero]
· rw [Multiset.map_cons, Multiset.prod_cons, Multiset.map_cons, Multiset.sum_cons,
Monic.nextCoeff_mul, ih]
exacts [fun i hi => ht i (Multiset.mem_cons_of_mem hi), ht a (Multiset.mem_cons_self _ _),
monic_multiset_prod_of_monic _ _ fun b bs => ht _ (Multiset.mem_cons_of_mem bs)]
theorem Monic.nextCoeff_prod (s : Finset ι) (f : ι → R[X]) (h : ∀ i ∈ s, Monic (f i)) :
nextCoeff (∏ i ∈ s, f i) = ∑ i ∈ s, nextCoeff (f i) :=
Monic.nextCoeff_multiset_prod s.1 f h
variable [NoZeroDivisors R] {p q : R[X]}
lemma irreducible_of_monic (hp : p.Monic) (hp1 : p ≠ 1) :
Irreducible p ↔ ∀ f g : R[X], f.Monic → g.Monic → f * g = p → f = 1 ∨ g = 1 := by
refine
⟨fun h f g hf hg hp => (h.2 hp.symm).imp hf.eq_one_of_isUnit hg.eq_one_of_isUnit, fun h =>
⟨hp1 ∘ hp.eq_one_of_isUnit, fun f g hfg =>
(h (g * C f.leadingCoeff) (f * C g.leadingCoeff) ?_ ?_ ?_).symm.imp
(isUnit_of_mul_eq_one f _)
(isUnit_of_mul_eq_one g _)⟩⟩
· rwa [Monic, leadingCoeff_mul, leadingCoeff_C, ← leadingCoeff_mul, mul_comm, ← hfg, ← Monic]
· rwa [Monic, leadingCoeff_mul, leadingCoeff_C, ← leadingCoeff_mul, ← hfg, ← Monic]
· rw [mul_mul_mul_comm, ← C_mul, ← leadingCoeff_mul, ← hfg, hp.leadingCoeff, C_1, mul_one,
mul_comm, ← hfg]
lemma Monic.irreducible_iff_natDegree (hp : p.Monic) :
Irreducible p ↔
p ≠ 1 ∧ ∀ f g : R[X], f.Monic → g.Monic → f * g = p → f.natDegree = 0 ∨ g.natDegree = 0 := by
by_cases hp1 : p = 1; · simp [hp1]
rw [irreducible_of_monic hp hp1, and_iff_right hp1]
refine forall₄_congr fun a b ha hb => ?_
rw [ha.natDegree_eq_zero_iff_eq_one, hb.natDegree_eq_zero_iff_eq_one]
lemma Monic.irreducible_iff_natDegree' (hp : p.Monic) : Irreducible p ↔ p ≠ 1 ∧
∀ f g : R[X], f.Monic → g.Monic → f * g = p → g.natDegree ∉ Ioc 0 (p.natDegree / 2) := by
simp_rw [hp.irreducible_iff_natDegree, mem_Ioc, Nat.le_div_iff_mul_le zero_lt_two, mul_two]
apply and_congr_right'
constructor <;> intro h f g hf hg he <;> subst he
· rw [hf.natDegree_mul hg, add_le_add_iff_right]
exact fun ha => (h f g hf hg rfl).elim (ha.1.trans_le ha.2).ne' ha.1.ne'
· simp_rw [hf.natDegree_mul hg, pos_iff_ne_zero] at h
contrapose! h
obtain hl | hl := le_total f.natDegree g.natDegree
· exact ⟨g, f, hg, hf, mul_comm g f, h.1, add_le_add_left hl _⟩
· exact ⟨f, g, hf, hg, rfl, h.2, add_le_add_right hl _⟩
/-- Alternate phrasing of `Polynomial.Monic.irreducible_iff_natDegree'` where we only have to check
one divisor at a time. -/
lemma Monic.irreducible_iff_lt_natDegree_lt {p : R[X]} (hp : p.Monic) (hp1 : p ≠ 1) :
Irreducible p ↔ ∀ q, Monic q → natDegree q ∈ Finset.Ioc 0 (natDegree p / 2) → ¬ q ∣ p := by
rw [hp.irreducible_iff_natDegree', and_iff_right hp1]
constructor
· rintro h g hg hdg ⟨f, rfl⟩
exact h f g (hg.of_mul_monic_left hp) hg (mul_comm f g) hdg
· rintro h f g - hg rfl hdg
exact h g hg hdg (dvd_mul_left g f)
lemma Monic.not_irreducible_iff_exists_add_mul_eq_coeff (hm : p.Monic) (hnd : p.natDegree = 2) :
¬Irreducible p ↔ ∃ c₁ c₂, p.coeff 0 = c₁ * c₂ ∧ p.coeff 1 = c₁ + c₂ := by
cases subsingleton_or_nontrivial R
· simp [natDegree_of_subsingleton] at hnd
rw [hm.irreducible_iff_natDegree', and_iff_right, hnd]
· push_neg
constructor
· rintro ⟨a, b, ha, hb, rfl, hdb⟩
simp only [zero_lt_two, Nat.div_self, Nat.Ioc_succ_singleton, zero_add, mem_singleton] at hdb
have hda := hnd
rw [ha.natDegree_mul hb, hdb] at hda
use a.coeff 0, b.coeff 0, mul_coeff_zero a b
simpa only [nextCoeff, hnd, add_right_cancel hda, hdb] using ha.nextCoeff_mul hb
· rintro ⟨c₁, c₂, hmul, hadd⟩
refine
⟨X + C c₁, X + C c₂, monic_X_add_C _, monic_X_add_C _, ?_, ?_⟩
· rw [p.as_sum_range_C_mul_X_pow, hnd, Finset.sum_range_succ, Finset.sum_range_succ,
Finset.sum_range_one, ← hnd, hm.coeff_natDegree, hnd, hmul, hadd, C_mul, C_add, C_1]
ring
· rw [mem_Ioc, natDegree_X_add_C _]
simp
· rintro rfl
simp [natDegree_one] at hnd
end CommSemiring
section Semiring
variable [Semiring R]
@[simp]
theorem Monic.natDegree_map [Semiring S] [Nontrivial S] {P : R[X]} (hmo : P.Monic) (f : R →+* S) :
(P.map f).natDegree = P.natDegree := by
refine le_antisymm natDegree_map_le (le_natDegree_of_ne_zero ?_)
rw [coeff_map, Monic.coeff_natDegree hmo, RingHom.map_one]
exact one_ne_zero
@[simp]
theorem Monic.degree_map [Semiring S] [Nontrivial S] {P : R[X]} (hmo : P.Monic) (f : R →+* S) :
(P.map f).degree = P.degree := by
by_cases hP : P = 0
· simp [hP]
· refine le_antisymm degree_map_le ?_
rw [degree_eq_natDegree hP]
refine le_degree_of_ne_zero ?_
rw [coeff_map, Monic.coeff_natDegree hmo, RingHom.map_one]
exact one_ne_zero
section Injective
open Function
variable [Semiring S] {f : R →+* S}
theorem degree_map_eq_of_injective (hf : Injective f) (p : R[X]) : degree (p.map f) = degree p :=
letI := Classical.decEq R
if h : p = 0 then by simp [h]
else
degree_map_eq_of_leadingCoeff_ne_zero _
(by rw [← f.map_zero]; exact mt hf.eq_iff.1 (mt leadingCoeff_eq_zero.1 h))
theorem natDegree_map_eq_of_injective (hf : Injective f) (p : R[X]) :
natDegree (p.map f) = natDegree p :=
natDegree_eq_of_degree_eq (degree_map_eq_of_injective hf p)
theorem leadingCoeff_map' (hf : Injective f) (p : R[X]) :
leadingCoeff (p.map f) = f (leadingCoeff p) := by
unfold leadingCoeff
rw [coeff_map, natDegree_map_eq_of_injective hf p]
theorem nextCoeff_map (hf : Injective f) (p : R[X]) : (p.map f).nextCoeff = f p.nextCoeff := by
unfold nextCoeff
rw [natDegree_map_eq_of_injective hf]
split_ifs <;> simp [*]
theorem leadingCoeff_of_injective (hf : Injective f) (p : R[X]) :
leadingCoeff (p.map f) = f (leadingCoeff p) := by
delta leadingCoeff
rw [coeff_map f, natDegree_map_eq_of_injective hf p]
theorem monic_of_injective (hf : Injective f) {p : R[X]} (hp : (p.map f).Monic) : p.Monic := by
apply hf
rw [← leadingCoeff_of_injective hf, hp.leadingCoeff, f.map_one]
theorem _root_.Function.Injective.monic_map_iff (hf : Injective f) {p : R[X]} :
p.Monic ↔ (p.map f).Monic :=
⟨Monic.map _, Polynomial.monic_of_injective hf⟩
end Injective
end Semiring
section Ring
variable [Ring R] {p : R[X]}
theorem monic_X_sub_C (x : R) : Monic (X - C x) := by
simpa only [sub_eq_add_neg, C_neg] using monic_X_add_C (-x)
theorem monic_X_pow_sub {n : ℕ} (H : degree p < n) : Monic (X ^ n - p) := by
simpa [sub_eq_add_neg] using monic_X_pow_add (show degree (-p) < n by rwa [← degree_neg p] at H)
/-- `X ^ n - a` is monic. -/
theorem monic_X_pow_sub_C {R : Type u} [Ring R] (a : R) {n : ℕ} (h : n ≠ 0) :
(X ^ n - C a).Monic := by
simpa only [map_neg, ← sub_eq_add_neg] using monic_X_pow_add_C (-a) h
theorem not_isUnit_X_pow_sub_one (R : Type*) [Ring R] [Nontrivial R] (n : ℕ) :
¬IsUnit (X ^ n - 1 : R[X]) := by
intro h
rcases eq_or_ne n 0 with (rfl | hn)
· simp at h
apply hn
rw [← @natDegree_one R, ← (monic_X_pow_sub_C _ hn).eq_one_of_isUnit h, natDegree_X_pow_sub_C]
lemma Monic.comp_X_sub_C {p : R[X]} (hp : p.Monic) (r : R) : (p.comp (X - C r)).Monic := by
simpa using hp.comp_X_add_C (-r)
theorem Monic.sub_of_left {p q : R[X]} (hp : Monic p) (hpq : degree q < degree p) :
Monic (p - q) := by
rw [sub_eq_add_neg]
apply hp.add_of_left
rwa [degree_neg]
| Mathlib/Algebra/Polynomial/Monic.lean | 459 | 467 | theorem Monic.sub_of_right {p q : R[X]} (hq : q.leadingCoeff = -1) (hpq : degree p < degree q) :
Monic (p - q) := by | have : (-q).coeff (-q).natDegree = 1 := by
rw [natDegree_neg, coeff_neg, show q.coeff q.natDegree = -1 from hq, neg_neg]
rw [sub_eq_add_neg]
apply Monic.add_of_right this
rwa [degree_neg]
end Ring |
/-
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.Order.SuccPred.LinearLocallyFinite
import Mathlib.Probability.Martingale.Basic
/-!
# Optional sampling theorem
If `τ` is a bounded stopping time and `σ` is another stopping time, then the value of a martingale
`f` at the stopping time `min τ σ` is almost everywhere equal to
`μ[stoppedValue f τ | hσ.measurableSpace]`.
## Main results
* `stoppedValue_ae_eq_condExp_of_le_const`: the value of a martingale `f` at a stopping time `τ`
bounded by `n` is the conditional expectation of `f n` with respect to the σ-algebra generated by
`τ`.
* `stoppedValue_ae_eq_condExp_of_le`: if `τ` and `σ` are two stopping times with `σ ≤ τ` and `τ` is
bounded, then the value of a martingale `f` at `σ` is the conditional expectation of its value at
`τ` with respect to the σ-algebra generated by `σ`.
* `stoppedValue_min_ae_eq_condExp`: the optional sampling theorem. If `τ` is a bounded stopping
time and `σ` is another stopping time, then the value of a martingale `f` at the stopping time
`min τ σ` is almost everywhere equal to the conditional expectation of `f` stopped at `τ`
with respect to the σ-algebra generated by `σ`.
-/
open scoped MeasureTheory ENNReal
open TopologicalSpace
namespace MeasureTheory
namespace Martingale
variable {Ω E : Type*} {m : MeasurableSpace Ω} {μ : Measure Ω} [NormedAddCommGroup E]
[NormedSpace ℝ E] [CompleteSpace E]
section FirstCountableTopology
variable {ι : Type*} [LinearOrder ι] [TopologicalSpace ι] [OrderTopology ι]
[FirstCountableTopology ι] {ℱ : Filtration ι m} [SigmaFiniteFiltration μ ℱ] {τ σ : Ω → ι}
{f : ι → Ω → E} {i n : ι}
theorem condExp_stopping_time_ae_eq_restrict_eq_const
[(Filter.atTop : Filter ι).IsCountablyGenerated] (h : Martingale f ℱ μ)
(hτ : IsStoppingTime ℱ τ) [SigmaFinite (μ.trim hτ.measurableSpace_le)] (hin : i ≤ n) :
μ[f n|hτ.measurableSpace] =ᵐ[μ.restrict {x | τ x = i}] f i := by
refine Filter.EventuallyEq.trans ?_ (ae_restrict_of_ae (h.condExp_ae_eq hin))
refine condExp_ae_eq_restrict_of_measurableSpace_eq_on hτ.measurableSpace_le (ℱ.le i)
(hτ.measurableSet_eq' i) fun t => ?_
rw [Set.inter_comm _ t, IsStoppingTime.measurableSet_inter_eq_iff]
@[deprecated (since := "2025-01-21")]
alias condexp_stopping_time_ae_eq_restrict_eq_const := condExp_stopping_time_ae_eq_restrict_eq_const
| Mathlib/Probability/Martingale/OptionalSampling.lean | 61 | 74 | theorem condExp_stopping_time_ae_eq_restrict_eq_const_of_le_const (h : Martingale f ℱ μ)
(hτ : IsStoppingTime ℱ τ) (hτ_le : ∀ x, τ x ≤ n)
[SigmaFinite (μ.trim (hτ.measurableSpace_le_of_le hτ_le))] (i : ι) :
μ[f n|hτ.measurableSpace] =ᵐ[μ.restrict {x | τ x = i}] f i := by | by_cases hin : i ≤ n
· refine Filter.EventuallyEq.trans ?_ (ae_restrict_of_ae (h.condExp_ae_eq hin))
refine condExp_ae_eq_restrict_of_measurableSpace_eq_on (hτ.measurableSpace_le_of_le hτ_le)
(ℱ.le i) (hτ.measurableSet_eq' i) fun t => ?_
rw [Set.inter_comm _ t, IsStoppingTime.measurableSet_inter_eq_iff]
· suffices {x : Ω | τ x = i} = ∅ by simp [this]; norm_cast
ext1 x
simp only [Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false]
rintro rfl
exact hin (hτ_le x) |
/-
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, Sébastien Gouëzel, Patrick Massot
-/
import Mathlib.Topology.UniformSpace.Cauchy
import Mathlib.Topology.UniformSpace.Separation
import Mathlib.Topology.DenseEmbedding
/-!
# Uniform embeddings of uniform spaces.
Extension of uniform continuous functions.
-/
open Filter Function Set Uniformity Topology
section
universe u v w
variable {α : Type u} {β : Type v} {γ : Type w} [UniformSpace α] [UniformSpace β] [UniformSpace γ]
{f : α → β}
/-!
### Uniform inducing maps
-/
/-- A map `f : α → β` between uniform spaces is called *uniform inducing* if the uniformity filter
on `α` is the pullback of the uniformity filter on `β` under `Prod.map f f`. If `α` is a separated
space, then this implies that `f` is injective, hence it is a `IsUniformEmbedding`. -/
@[mk_iff]
structure IsUniformInducing (f : α → β) : Prop where
/-- The uniformity filter on the domain is the pullback of the uniformity filter on the codomain
under `Prod.map f f`. -/
comap_uniformity : comap (fun x : α × α => (f x.1, f x.2)) (𝓤 β) = 𝓤 α
lemma isUniformInducing_iff_uniformSpace {f : α → β} :
IsUniformInducing f ↔ ‹UniformSpace β›.comap f = ‹UniformSpace α› := by
rw [isUniformInducing_iff, UniformSpace.ext_iff, Filter.ext_iff]
rfl
protected alias ⟨IsUniformInducing.comap_uniformSpace, _⟩ := isUniformInducing_iff_uniformSpace
lemma isUniformInducing_iff' {f : α → β} :
IsUniformInducing f ↔ UniformContinuous f ∧ comap (Prod.map f f) (𝓤 β) ≤ 𝓤 α := by
rw [isUniformInducing_iff, UniformContinuous, tendsto_iff_comap, le_antisymm_iff, and_comm]; rfl
protected lemma Filter.HasBasis.isUniformInducing_iff {ι ι'} {p : ι → Prop} {p' : ι' → Prop} {s s'}
(h : (𝓤 α).HasBasis p s) (h' : (𝓤 β).HasBasis p' s') {f : α → β} :
IsUniformInducing f ↔
(∀ i, p' i → ∃ j, p j ∧ ∀ x y, (x, y) ∈ s j → (f x, f y) ∈ s' i) ∧
(∀ j, p j → ∃ i, p' i ∧ ∀ x y, (f x, f y) ∈ s' i → (x, y) ∈ s j) := by
simp [isUniformInducing_iff', h.uniformContinuous_iff h', (h'.comap _).le_basis_iff h, subset_def]
theorem IsUniformInducing.mk' {f : α → β}
(h : ∀ s, s ∈ 𝓤 α ↔ ∃ t ∈ 𝓤 β, ∀ x y : α, (f x, f y) ∈ t → (x, y) ∈ s) : IsUniformInducing f :=
⟨by simp [eq_comm, Filter.ext_iff, subset_def, h]⟩
theorem IsUniformInducing.id : IsUniformInducing (@id α) :=
⟨by rw [← Prod.map_def, Prod.map_id, comap_id]⟩
theorem IsUniformInducing.comp {g : β → γ} (hg : IsUniformInducing g) {f : α → β}
(hf : IsUniformInducing f) : IsUniformInducing (g ∘ f) :=
⟨by rw [← hf.1, ← hg.1, comap_comap]; rfl⟩
| Mathlib/Topology/UniformSpace/UniformEmbedding.lean | 67 | 68 | theorem IsUniformInducing.of_comp_iff {g : β → γ} (hg : IsUniformInducing g) {f : α → β} :
IsUniformInducing (g ∘ f) ↔ IsUniformInducing f := by | |
/-
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.Complex.Basic
import Mathlib.Data.Nat.Prime.Basic
import Mathlib.Data.Real.Archimedean
import Mathlib.NumberTheory.Zsqrtd.Basic
/-!
# Gaussian integers
The Gaussian integers are complex integer, complex numbers whose real and imaginary parts are both
integers.
## Main definitions
The Euclidean domain structure on `ℤ[i]` is defined in this file.
The homomorphism `GaussianInt.toComplex` into the complex numbers is also defined in this file.
## See also
See `NumberTheory.Zsqrtd.QuadraticReciprocity` for:
* `prime_iff_mod_four_eq_three_of_nat_prime`:
A prime natural number is prime in `ℤ[i]` if and only if it is `3` mod `4`
## Notations
This file uses the local notation `ℤ[i]` for `GaussianInt`
## Implementation notes
Gaussian integers are implemented using the more general definition `Zsqrtd`, the type of integers
adjoined a square root of `d`, in this case `-1`. The definition is reducible, so that properties
and definitions about `Zsqrtd` can easily be used.
-/
open Zsqrtd Complex
open scoped ComplexConjugate
/-- The Gaussian integers, defined as `ℤ√(-1)`. -/
abbrev GaussianInt : Type :=
Zsqrtd (-1)
local notation "ℤ[i]" => GaussianInt
namespace GaussianInt
instance : Repr ℤ[i] :=
⟨fun x _ => "⟨" ++ repr x.re ++ ", " ++ repr x.im ++ "⟩"⟩
instance instCommRing : CommRing ℤ[i] :=
Zsqrtd.commRing
section
attribute [-instance] Complex.instField -- Avoid making things noncomputable unnecessarily.
/-- The embedding of the Gaussian integers into the complex numbers, as a ring homomorphism. -/
def toComplex : ℤ[i] →+* ℂ :=
Zsqrtd.lift ⟨I, by simp⟩
end
instance : Coe ℤ[i] ℂ :=
⟨toComplex⟩
theorem toComplex_def (x : ℤ[i]) : (x : ℂ) = x.re + x.im * I :=
rfl
theorem toComplex_def' (x y : ℤ) : ((⟨x, y⟩ : ℤ[i]) : ℂ) = x + y * I := by simp [toComplex_def]
theorem toComplex_def₂ (x : ℤ[i]) : (x : ℂ) = ⟨x.re, x.im⟩ := by
apply Complex.ext <;> simp [toComplex_def]
@[simp]
| Mathlib/NumberTheory/Zsqrtd/GaussianInt.lean | 81 | 81 | theorem to_real_re (x : ℤ[i]) : ((x.re : ℤ) : ℝ) = (x : ℂ).re := by | simp [toComplex_def] |
/-
Copyright (c) 2022 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Analysis.InnerProductSpace.Orientation
import Mathlib.MeasureTheory.Measure.Lebesgue.EqHaar
/-!
# Volume forms and measures on inner product spaces
A volume form induces a Lebesgue measure on general finite-dimensional real vector spaces. In this
file, we discuss the specific situation of inner product spaces, where an orientation gives
rise to a canonical volume form. We show that the measure coming from this volume form gives
measure `1` to the parallelepiped spanned by any orthonormal basis, and that it coincides with
the canonical `volume` from the `MeasureSpace` instance.
-/
open Module MeasureTheory MeasureTheory.Measure Set
variable {ι E F : Type*}
variable [NormedAddCommGroup F] [InnerProductSpace ℝ F]
[NormedAddCommGroup E] [InnerProductSpace ℝ E]
[MeasurableSpace E] [BorelSpace E] [MeasurableSpace F] [BorelSpace F]
namespace LinearIsometryEquiv
variable (f : E ≃ₗᵢ[ℝ] F)
/-- Every linear isometry equivalence is a measurable equivalence. -/
def toMeasurableEquiv : E ≃ᵐ F where
toEquiv := f
measurable_toFun := f.continuous.measurable
measurable_invFun := f.symm.continuous.measurable
@[deprecated (since := "2025-03-22")] alias toMeasureEquiv := toMeasurableEquiv
@[simp] theorem coe_toMeasurableEquiv : (f.toMeasurableEquiv : E → F) = f := rfl
@[deprecated (since := "2025-03-22")] alias coe_toMeasureEquiv := coe_toMeasurableEquiv
theorem toMeasurableEquiv_symm : f.toMeasurableEquiv.symm = f.symm.toMeasurableEquiv := rfl
@[deprecated (since := "2025-03-22")] alias toMeasureEquiv_symm := toMeasurableEquiv_symm
end LinearIsometryEquiv
variable [Fintype ι]
variable [FiniteDimensional ℝ E] [FiniteDimensional ℝ F]
section
variable {m n : ℕ} [_i : Fact (finrank ℝ F = n)]
/-- The volume form coming from an orientation in an inner product space gives measure `1` to the
parallelepiped associated to any orthonormal basis. This is a rephrasing of
`abs_volumeForm_apply_of_orthonormal` in terms of measures. -/
theorem Orientation.measure_orthonormalBasis (o : Orientation ℝ F (Fin n))
(b : OrthonormalBasis ι ℝ F) : o.volumeForm.measure (parallelepiped b) = 1 := by
have e : ι ≃ Fin n := by
refine Fintype.equivFinOfCardEq ?_
rw [← _i.out, finrank_eq_card_basis b.toBasis]
have A : ⇑b = b.reindex e ∘ e := by
ext x
simp only [OrthonormalBasis.coe_reindex, Function.comp_apply, Equiv.symm_apply_apply]
rw [A, parallelepiped_comp_equiv, AlternatingMap.measure_parallelepiped,
o.abs_volumeForm_apply_of_orthonormal, ENNReal.ofReal_one]
/-- In an oriented inner product space, the measure coming from the canonical volume form
associated to an orientation coincides with the volume. -/
theorem Orientation.measure_eq_volume (o : Orientation ℝ F (Fin n)) :
o.volumeForm.measure = volume := by
have A : o.volumeForm.measure (stdOrthonormalBasis ℝ F).toBasis.parallelepiped = 1 :=
Orientation.measure_orthonormalBasis o (stdOrthonormalBasis ℝ F)
rw [addHaarMeasure_unique o.volumeForm.measure
(stdOrthonormalBasis ℝ F).toBasis.parallelepiped, A, one_smul]
simp only [volume, Basis.addHaar]
end
/-- The volume measure in a finite-dimensional inner product space gives measure `1` to the
parallelepiped spanned by any orthonormal basis. -/
theorem OrthonormalBasis.volume_parallelepiped (b : OrthonormalBasis ι ℝ F) :
volume (parallelepiped b) = 1 := by
haveI : Fact (finrank ℝ F = finrank ℝ F) := ⟨rfl⟩
let o := (stdOrthonormalBasis ℝ F).toBasis.orientation
rw [← o.measure_eq_volume]
exact o.measure_orthonormalBasis b
/-- The Haar measure defined by any orthonormal basis of a finite-dimensional inner product space
is equal to its volume measure. -/
theorem OrthonormalBasis.addHaar_eq_volume {ι F : Type*} [Fintype ι] [NormedAddCommGroup F]
[InnerProductSpace ℝ F] [FiniteDimensional ℝ F] [MeasurableSpace F] [BorelSpace F]
(b : OrthonormalBasis ι ℝ F) :
b.toBasis.addHaar = volume := by
rw [Basis.addHaar_eq_iff]
exact b.volume_parallelepiped
/-- An orthonormal basis of a finite-dimensional inner product space defines a measurable
equivalence between the space and the Euclidean space of the same dimension. -/
noncomputable def OrthonormalBasis.measurableEquiv (b : OrthonormalBasis ι ℝ F) :
F ≃ᵐ EuclideanSpace ℝ ι := b.repr.toHomeomorph.toMeasurableEquiv
/-- The measurable equivalence defined by an orthonormal basis is volume preserving. -/
theorem OrthonormalBasis.measurePreserving_measurableEquiv (b : OrthonormalBasis ι ℝ F) :
MeasurePreserving b.measurableEquiv volume volume := by
convert (b.measurableEquiv.symm.measurable.measurePreserving _).symm
rw [← (EuclideanSpace.basisFun ι ℝ).addHaar_eq_volume]
erw [MeasurableEquiv.coe_toEquiv_symm, Basis.map_addHaar _ b.repr.symm.toContinuousLinearEquiv]
exact b.addHaar_eq_volume.symm
theorem OrthonormalBasis.measurePreserving_repr (b : OrthonormalBasis ι ℝ F) :
MeasurePreserving b.repr volume volume := b.measurePreserving_measurableEquiv
theorem OrthonormalBasis.measurePreserving_repr_symm (b : OrthonormalBasis ι ℝ F) :
MeasurePreserving b.repr.symm volume volume := b.measurePreserving_measurableEquiv.symm
section PiLp
variable (ι : Type*) [Fintype ι]
/-- The measure equivalence between `EuclideanSpace ℝ ι` and `ι → ℝ` is volume preserving. -/
theorem EuclideanSpace.volume_preserving_measurableEquiv :
MeasurePreserving (EuclideanSpace.measurableEquiv ι) := by
suffices volume = map (EuclideanSpace.measurableEquiv ι).symm volume by
convert ((EuclideanSpace.measurableEquiv ι).symm.measurable.measurePreserving _).symm
rw [← addHaarMeasure_eq_volume_pi, ← Basis.parallelepiped_basisFun, ← Basis.addHaar_def,
coe_measurableEquiv_symm, ← PiLp.continuousLinearEquiv_symm_apply 2 ℝ, Basis.map_addHaar]
exact (EuclideanSpace.basisFun _ _).addHaar_eq_volume.symm
/-- A copy of `EuclideanSpace.volume_preserving_measurableEquiv` for the canonical spelling of the
equivalence. -/
theorem PiLp.volume_preserving_equiv : MeasurePreserving (WithLp.equiv 2 (ι → ℝ)) :=
EuclideanSpace.volume_preserving_measurableEquiv ι
/-- The reverse direction of `PiLp.volume_preserving_measurableEquiv`, since
`MeasurePreserving.symm` only works for `MeasurableEquiv`s. -/
| Mathlib/MeasureTheory/Measure/Haar/InnerProductSpace.lean | 138 | 143 | theorem PiLp.volume_preserving_equiv_symm : MeasurePreserving (WithLp.equiv 2 (ι → ℝ)).symm :=
(EuclideanSpace.volume_preserving_measurableEquiv ι).symm
lemma volume_euclideanSpace_eq_dirac [IsEmpty ι] :
(volume : Measure (EuclideanSpace ℝ ι)) = Measure.dirac 0 := by | rw [← ((EuclideanSpace.volume_preserving_measurableEquiv ι).symm).map_eq, |
/-
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
/-!
# 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 Module 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₂)
@[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
unfold oangle
fun_prop (disch := simp [*])
/-- The angle ∡AAB at a point. -/
@[simp]
theorem oangle_self_left (p₁ p₂ : P) : ∡ p₁ p₁ p₂ = 0 := by simp [oangle]
/-- The angle ∡ABB at a point. -/
@[simp]
theorem oangle_self_right (p₁ p₂ : P) : ∡ p₁ p₂ p₂ = 0 := by simp [oangle]
/-- The angle ∡ABA at a point. -/
@[simp]
theorem oangle_self_left_right (p₁ p₂ : P) : ∡ p₁ p₂ p₁ = 0 :=
o.oangle_self _
/-- 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
/-- 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
/-- 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
/-- 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)
/-- 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)
/-- 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)
/-- 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)
/-- 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)
/-- 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)
/-- 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)
/-- 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)
/-- 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)
/-- 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
/-- 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
/-- 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
/-- 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)
/-- 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)
/-- 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)
/-- 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)
/-- 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)
/-- 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)
/-- 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 _ _
/-- 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 _ _
/-- 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
/-- 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
/-- 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))]
convert Iff.rfl
ext i
fin_cases i <;> rfl
/-- 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]
/-- 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]
/-- 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]
/-- 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₃₂₆₅
/-- 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₃₂₆₅
/-- 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₃)
/-- 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₃)
/-- 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₃)
/-- 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₃)
/-- 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₃)
/-- 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]
/-- 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
/-- 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
/-- 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
/-- 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₂)
/-- 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₂)
/-- 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₂)
/-- 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
/-- 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
/-- 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
/-- 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
/-- 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
/-- 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₂)
/-- 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
/-- 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
/-- 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
/-- 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
/-- 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
/-- 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
/-- 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]
/-- Swapping the second 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_swap₁₃_sign, ← oangle_swap₁₂_sign, oangle_swap₁₃_sign]
/-- Rotating the points in an oriented angle does not change the sign of that angle. -/
theorem oangle_rotate_sign (p₁ p₂ p₃ : P) : (∡ p₂ p₃ p₁).sign = (∡ p₁ p₂ p₃).sign := by
rw [← oangle_swap₁₂_sign, oangle_swap₁₃_sign]
/-- The oriented angle between three points is π if and only if the second point is strictly
between the other two. -/
theorem oangle_eq_pi_iff_sbtw {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ = π ↔ Sbtw ℝ p₁ p₂ p₃ := by
rw [oangle_eq_pi_iff_angle_eq_pi, angle_eq_pi_iff_sbtw]
/-- If the second of three points is strictly between the other two, the oriented angle at that
point is π. -/
theorem _root_.Sbtw.oangle₁₂₃_eq_pi {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∡ p₁ p₂ p₃ = π :=
oangle_eq_pi_iff_sbtw.2 h
/-- If the second of three points is strictly between the other two, the oriented angle at that
point (reversed) is π. -/
theorem _root_.Sbtw.oangle₃₂₁_eq_pi {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∡ p₃ p₂ p₁ = π := by
rw [oangle_eq_pi_iff_oangle_rev_eq_pi, ← h.oangle₁₂₃_eq_pi]
/-- If the second of three points is weakly between the other two, the oriented angle at the
first point is zero. -/
theorem _root_.Wbtw.oangle₂₁₃_eq_zero {p₁ p₂ p₃ : P} (h : Wbtw ℝ p₁ p₂ p₃) : ∡ p₂ p₁ p₃ = 0 := by
by_cases hp₂p₁ : p₂ = p₁; · simp [hp₂p₁]
by_cases hp₃p₁ : p₃ = p₁; · simp [hp₃p₁]
rw [oangle_eq_zero_iff_angle_eq_zero hp₂p₁ hp₃p₁]
exact h.angle₂₁₃_eq_zero_of_ne hp₂p₁
/-- If the second of three points is strictly between the other two, the oriented angle at the
first point is zero. -/
theorem _root_.Sbtw.oangle₂₁₃_eq_zero {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∡ p₂ p₁ p₃ = 0 :=
h.wbtw.oangle₂₁₃_eq_zero
/-- If the second of three points is weakly between the other two, the oriented angle at the
first point (reversed) is zero. -/
theorem _root_.Wbtw.oangle₃₁₂_eq_zero {p₁ p₂ p₃ : P} (h : Wbtw ℝ p₁ p₂ p₃) : ∡ p₃ p₁ p₂ = 0 := by
rw [oangle_eq_zero_iff_oangle_rev_eq_zero, h.oangle₂₁₃_eq_zero]
/-- If the second of three points is strictly between the other two, the oriented angle at the
first point (reversed) is zero. -/
theorem _root_.Sbtw.oangle₃₁₂_eq_zero {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∡ p₃ p₁ p₂ = 0 :=
h.wbtw.oangle₃₁₂_eq_zero
/-- If the second of three points is weakly between the other two, the oriented angle at the
third point is zero. -/
theorem _root_.Wbtw.oangle₂₃₁_eq_zero {p₁ p₂ p₃ : P} (h : Wbtw ℝ p₁ p₂ p₃) : ∡ p₂ p₃ p₁ = 0 :=
h.symm.oangle₂₁₃_eq_zero
/-- If the second of three points is strictly between the other two, the oriented angle at the
third point is zero. -/
theorem _root_.Sbtw.oangle₂₃₁_eq_zero {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∡ p₂ p₃ p₁ = 0 :=
h.wbtw.oangle₂₃₁_eq_zero
/-- If the second of three points is weakly between the other two, the oriented angle at the
third point (reversed) is zero. -/
theorem _root_.Wbtw.oangle₁₃₂_eq_zero {p₁ p₂ p₃ : P} (h : Wbtw ℝ p₁ p₂ p₃) : ∡ p₁ p₃ p₂ = 0 :=
h.symm.oangle₃₁₂_eq_zero
/-- If the second of three points is strictly between the other two, the oriented angle at the
third point (reversed) is zero. -/
theorem _root_.Sbtw.oangle₁₃₂_eq_zero {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∡ p₁ p₃ p₂ = 0 :=
h.wbtw.oangle₁₃₂_eq_zero
/-- The oriented angle between three points is zero if and only if one of the first and third
points is weakly between the other two. -/
theorem oangle_eq_zero_iff_wbtw {p₁ p₂ p₃ : P} :
∡ p₁ p₂ p₃ = 0 ↔ Wbtw ℝ p₂ p₁ p₃ ∨ Wbtw ℝ p₂ p₃ p₁ := by
by_cases hp₁p₂ : p₁ = p₂; · simp [hp₁p₂]
by_cases hp₃p₂ : p₃ = p₂; · simp [hp₃p₂]
rw [oangle_eq_zero_iff_angle_eq_zero hp₁p₂ hp₃p₂, angle_eq_zero_iff_ne_and_wbtw]
simp [hp₁p₂, hp₃p₂]
/-- An oriented angle is unchanged by replacing the first point by one weakly further away on the
same ray. -/
theorem _root_.Wbtw.oangle_eq_left {p₁ p₁' p₂ p₃ : P} (h : Wbtw ℝ p₂ p₁ p₁') (hp₁p₂ : p₁ ≠ p₂) :
∡ p₁ p₂ p₃ = ∡ p₁' p₂ p₃ := by
by_cases hp₃p₂ : p₃ = p₂; · simp [hp₃p₂]
by_cases hp₁'p₂ : p₁' = p₂; · rw [hp₁'p₂, wbtw_self_iff] at h; exact False.elim (hp₁p₂ h)
rw [← oangle_add hp₁'p₂ hp₁p₂ hp₃p₂, h.oangle₃₁₂_eq_zero, zero_add]
/-- An oriented angle is unchanged by replacing the first point by one strictly further away on
the same ray. -/
theorem _root_.Sbtw.oangle_eq_left {p₁ p₁' p₂ p₃ : P} (h : Sbtw ℝ p₂ p₁ p₁') :
∡ p₁ p₂ p₃ = ∡ p₁' p₂ p₃ :=
h.wbtw.oangle_eq_left h.ne_left
/-- An oriented angle is unchanged by replacing the third point by one weakly further away on the
same ray. -/
theorem _root_.Wbtw.oangle_eq_right {p₁ p₂ p₃ p₃' : P} (h : Wbtw ℝ p₂ p₃ p₃') (hp₃p₂ : p₃ ≠ p₂) :
∡ p₁ p₂ p₃ = ∡ p₁ p₂ p₃' := by rw [oangle_rev, h.oangle_eq_left hp₃p₂, ← oangle_rev]
/-- An oriented angle is unchanged by replacing the third point by one strictly further away on
the same ray. -/
theorem _root_.Sbtw.oangle_eq_right {p₁ p₂ p₃ p₃' : P} (h : Sbtw ℝ p₂ p₃ p₃') :
∡ p₁ p₂ p₃ = ∡ p₁ p₂ p₃' :=
h.wbtw.oangle_eq_right h.ne_left
/-- An oriented angle is unchanged by replacing the first point with the midpoint of the segment
between it and the second point. -/
@[simp]
theorem oangle_midpoint_left (p₁ p₂ p₃ : P) : ∡ (midpoint ℝ p₁ p₂) p₂ p₃ = ∡ p₁ p₂ p₃ := by
by_cases h : p₁ = p₂; · simp [h]
exact (sbtw_midpoint_of_ne ℝ h).symm.oangle_eq_left
/-- An oriented angle is unchanged by replacing the first point with the midpoint of the segment
between the second point and that point. -/
@[simp]
theorem oangle_midpoint_rev_left (p₁ p₂ p₃ : P) : ∡ (midpoint ℝ p₂ p₁) p₂ p₃ = ∡ p₁ p₂ p₃ := by
rw [midpoint_comm, oangle_midpoint_left]
/-- An oriented angle is unchanged by replacing the third point with the midpoint of the segment
between it and the second point. -/
@[simp]
theorem oangle_midpoint_right (p₁ p₂ p₃ : P) : ∡ p₁ p₂ (midpoint ℝ p₃ p₂) = ∡ p₁ p₂ p₃ := by
by_cases h : p₃ = p₂; · simp [h]
exact (sbtw_midpoint_of_ne ℝ h).symm.oangle_eq_right
/-- An oriented angle is unchanged by replacing the third point with the midpoint of the segment
between the second point and that point. -/
@[simp]
theorem oangle_midpoint_rev_right (p₁ p₂ p₃ : P) : ∡ p₁ p₂ (midpoint ℝ p₂ p₃) = ∡ p₁ p₂ p₃ := by
rw [midpoint_comm, oangle_midpoint_right]
/-- Replacing the first point by one on the same line but the opposite ray adds π to the oriented
angle. -/
theorem _root_.Sbtw.oangle_eq_add_pi_left
{p₁ p₁' p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₁') (hp₃p₂ : p₃ ≠ p₂) :
∡ p₁ p₂ p₃ = ∡ p₁' p₂ p₃ + π := by
rw [← h.oangle₁₂₃_eq_pi, oangle_add_swap h.left_ne h.right_ne hp₃p₂]
/-- Replacing the third point by one on the same line but the opposite ray adds π to the oriented
angle. -/
theorem _root_.Sbtw.oangle_eq_add_pi_right
{p₁ p₂ p₃ p₃' : P} (h : Sbtw ℝ p₃ p₂ p₃') (hp₁p₂ : p₁ ≠ p₂) :
∡ p₁ p₂ p₃ = ∡ p₁ p₂ p₃' + π := by
rw [← h.oangle₃₂₁_eq_pi, oangle_add hp₁p₂ h.right_ne h.left_ne]
/-- Replacing both the first and third points by ones on the same lines but the opposite rays
does not change the oriented angle (vertically opposite angles). -/
theorem _root_.Sbtw.oangle_eq_left_right {p₁ p₁' p₂ p₃ p₃' : P} (h₁ : Sbtw ℝ p₁ p₂ p₁')
(h₃ : Sbtw ℝ p₃ p₂ p₃') : ∡ p₁ p₂ p₃ = ∡ p₁' p₂ p₃' := by
rw [h₁.oangle_eq_add_pi_left h₃.left_ne, h₃.oangle_eq_add_pi_right h₁.right_ne, add_assoc,
Real.Angle.coe_pi_add_coe_pi, add_zero]
/-- Replacing the first point by one on the same line does not change twice the oriented angle. -/
theorem _root_.Collinear.two_zsmul_oangle_eq_left {p₁ p₁' p₂ p₃ : P}
(h : Collinear ℝ ({p₁, p₂, p₁'} : Set P)) (hp₁p₂ : p₁ ≠ p₂) (hp₁'p₂ : p₁' ≠ p₂) :
(2 : ℤ) • ∡ p₁ p₂ p₃ = (2 : ℤ) • ∡ p₁' p₂ p₃ := by
by_cases hp₃p₂ : p₃ = p₂; · simp [hp₃p₂]
rcases h.wbtw_or_wbtw_or_wbtw with (hw | hw | hw)
· have hw' : Sbtw ℝ p₁ p₂ p₁' := ⟨hw, hp₁p₂.symm, hp₁'p₂.symm⟩
rw [hw'.oangle_eq_add_pi_left hp₃p₂, smul_add, Real.Angle.two_zsmul_coe_pi, add_zero]
· rw [hw.oangle_eq_left hp₁'p₂]
· rw [hw.symm.oangle_eq_left hp₁p₂]
/-- Replacing the third point by one on the same line does not change twice the oriented angle. -/
theorem _root_.Collinear.two_zsmul_oangle_eq_right {p₁ p₂ p₃ p₃' : P}
(h : Collinear ℝ ({p₃, p₂, p₃'} : Set P)) (hp₃p₂ : p₃ ≠ p₂) (hp₃'p₂ : p₃' ≠ p₂) :
(2 : ℤ) • ∡ p₁ p₂ p₃ = (2 : ℤ) • ∡ p₁ p₂ p₃' := by
rw [oangle_rev, smul_neg, h.two_zsmul_oangle_eq_left hp₃p₂ hp₃'p₂, ← smul_neg, ← oangle_rev]
/-- Two different points are equidistant from a third point if and only if that third point
equals some multiple of a `π / 2` rotation of the vector between those points, plus the midpoint
of those points. -/
theorem dist_eq_iff_eq_smul_rotation_pi_div_two_vadd_midpoint {p₁ p₂ p : P} (h : p₁ ≠ p₂) :
dist p₁ p = dist p₂ p ↔
∃ r : ℝ, r • o.rotation (π / 2 : ℝ) (p₂ -ᵥ p₁) +ᵥ midpoint ℝ p₁ p₂ = p := by
refine ⟨fun hd => ?_, fun hr => ?_⟩
· have hi : ⟪p₂ -ᵥ p₁, p -ᵥ midpoint ℝ p₁ p₂⟫ = 0 := by
rw [@dist_eq_norm_vsub' V, @dist_eq_norm_vsub' V, ←
mul_self_inj (norm_nonneg _) (norm_nonneg _), ← real_inner_self_eq_norm_mul_norm, ←
real_inner_self_eq_norm_mul_norm] at hd
simp_rw [vsub_midpoint, ← vsub_sub_vsub_cancel_left p₂ p₁ p, inner_sub_left, inner_add_right,
inner_smul_right, hd, real_inner_comm (p -ᵥ p₁)]
abel
rw [@Orientation.inner_eq_zero_iff_eq_zero_or_eq_smul_rotation_pi_div_two V _ _ _ o,
or_iff_right (vsub_ne_zero.2 h.symm)] at hi
rcases hi with ⟨r, hr⟩
rw [eq_comm, ← eq_vadd_iff_vsub_eq] at hr
exact ⟨r, hr.symm⟩
· rcases hr with ⟨r, rfl⟩
simp_rw [@dist_eq_norm_vsub V, vsub_vadd_eq_vsub_sub, left_vsub_midpoint, right_vsub_midpoint,
invOf_eq_inv, ← neg_vsub_eq_vsub_rev p₂ p₁, ← mul_self_inj (norm_nonneg _) (norm_nonneg _), ←
real_inner_self_eq_norm_mul_norm, inner_sub_sub_self]
simp [-neg_vsub_eq_vsub_rev]
open AffineSubspace
/-- Given two pairs of distinct points on the same line, such that the vectors between those
pairs of points are on the same ray (oriented in the same direction on that line), and a fifth
point, the angles at the fifth point between each of those two pairs of points have the same
sign. -/
theorem _root_.Collinear.oangle_sign_of_sameRay_vsub {p₁ p₂ p₃ p₄ : P} (p₅ : P) (hp₁p₂ : p₁ ≠ p₂)
(hp₃p₄ : p₃ ≠ p₄) (hc : Collinear ℝ ({p₁, p₂, p₃, p₄} : Set P))
(hr : SameRay ℝ (p₂ -ᵥ p₁) (p₄ -ᵥ p₃)) : (∡ p₁ p₅ p₂).sign = (∡ p₃ p₅ p₄).sign := by
by_cases hc₅₁₂ : Collinear ℝ ({p₅, p₁, p₂} : Set P)
· have hc₅₁₂₃₄ : Collinear ℝ ({p₅, p₁, p₂, p₃, p₄} : Set P) :=
(hc.collinear_insert_iff_of_ne (Set.mem_insert _ _)
(Set.mem_insert_of_mem _ (Set.mem_insert _ _)) hp₁p₂).2 hc₅₁₂
have hc₅₃₄ : Collinear ℝ ({p₅, p₃, p₄} : Set P) :=
(hc.collinear_insert_iff_of_ne
(Set.mem_insert_of_mem _ (Set.mem_insert_of_mem _ (Set.mem_insert _ _)))
(Set.mem_insert_of_mem _ (Set.mem_insert_of_mem _ (Set.mem_insert_of_mem _
(Set.mem_singleton _)))) hp₃p₄).1 hc₅₁₂₃₄
rw [Set.insert_comm] at hc₅₁₂ hc₅₃₄
have hs₁₅₂ := oangle_eq_zero_or_eq_pi_iff_collinear.2 hc₅₁₂
have hs₃₅₄ := oangle_eq_zero_or_eq_pi_iff_collinear.2 hc₅₃₄
rw [← Real.Angle.sign_eq_zero_iff] at hs₁₅₂ hs₃₅₄
rw [hs₁₅₂, hs₃₅₄]
· let s : Set (P × P × P) :=
(fun x : line[ℝ, p₁, p₂] × V => (x.1, p₅, x.2 +ᵥ (x.1 : P))) ''
Set.univ ×ˢ {v | SameRay ℝ (p₂ -ᵥ p₁) v ∧ v ≠ 0}
have hco : IsConnected s :=
haveI : ConnectedSpace line[ℝ, p₁, p₂] := AddTorsor.connectedSpace _ _
(isConnected_univ.prod (isConnected_setOf_sameRay_and_ne_zero
(vsub_ne_zero.2 hp₁p₂.symm))).image _ (by fun_prop)
have hf : ContinuousOn (fun p : P × P × P => ∡ p.1 p.2.1 p.2.2) s := by
refine continuousOn_of_forall_continuousAt fun p hp => continuousAt_oangle ?_ ?_
all_goals
simp_rw [s, Set.mem_image, Set.mem_prod, Set.mem_univ, true_and, Prod.ext_iff] at hp
obtain ⟨q₁, q₅, q₂⟩ := p
dsimp only at hp ⊢
obtain ⟨⟨⟨q, hq⟩, v⟩, hv, rfl, rfl, rfl⟩ := hp
dsimp only [Subtype.coe_mk, Set.mem_setOf] at hv ⊢
obtain ⟨hvr, -⟩ := hv
rintro rfl
refine hc₅₁₂ ((collinear_insert_iff_of_mem_affineSpan ?_).2 (collinear_pair _ _ _))
· exact hq
· refine vadd_mem_of_mem_direction ?_ hq
rw [← exists_nonneg_left_iff_sameRay (vsub_ne_zero.2 hp₁p₂.symm)] at hvr
obtain ⟨r, -, rfl⟩ := hvr
rw [direction_affineSpan]
exact smul_vsub_rev_mem_vectorSpan_pair _ _ _
have hsp : ∀ p : P × P × P, p ∈ s → ∡ p.1 p.2.1 p.2.2 ≠ 0 ∧ ∡ p.1 p.2.1 p.2.2 ≠ π := by
intro p hp
simp_rw [s, Set.mem_image, Set.mem_prod, Set.mem_setOf, Set.mem_univ, true_and,
Prod.ext_iff] at hp
obtain ⟨q₁, q₅, q₂⟩ := p
dsimp only at hp ⊢
obtain ⟨⟨⟨q, hq⟩, v⟩, hv, rfl, rfl, rfl⟩ := hp
dsimp only [Subtype.coe_mk, Set.mem_setOf] at hv ⊢
obtain ⟨hvr, hv0⟩ := hv
rw [← exists_nonneg_left_iff_sameRay (vsub_ne_zero.2 hp₁p₂.symm)] at hvr
obtain ⟨r, -, rfl⟩ := hvr
change q ∈ line[ℝ, p₁, p₂] at hq
rw [oangle_ne_zero_and_ne_pi_iff_affineIndependent]
refine affineIndependent_of_ne_of_mem_of_not_mem_of_mem ?_ hq
(fun h => hc₅₁₂ ((collinear_insert_iff_of_mem_affineSpan h).2 (collinear_pair _ _ _))) ?_
· rwa [← @vsub_ne_zero V, vsub_vadd_eq_vsub_sub, vsub_self, zero_sub, neg_ne_zero]
· refine vadd_mem_of_mem_direction ?_ hq
rw [direction_affineSpan]
exact smul_vsub_rev_mem_vectorSpan_pair _ _ _
have hp₁p₂s : (p₁, p₅, p₂) ∈ s := by
simp_rw [s, Set.mem_image, Set.mem_prod, Set.mem_setOf, Set.mem_univ, true_and,
Prod.ext_iff]
refine ⟨⟨⟨p₁, left_mem_affineSpan_pair ℝ _ _⟩, p₂ -ᵥ p₁⟩,
⟨SameRay.rfl, vsub_ne_zero.2 hp₁p₂.symm⟩, ?_⟩
simp
have hp₃p₄s : (p₃, p₅, p₄) ∈ s := by
simp_rw [s, Set.mem_image, Set.mem_prod, Set.mem_setOf, Set.mem_univ, true_and,
Prod.ext_iff]
refine ⟨⟨⟨p₃, hc.mem_affineSpan_of_mem_of_ne (Set.mem_insert _ _)
(Set.mem_insert_of_mem _ (Set.mem_insert _ _))
(Set.mem_insert_of_mem _ (Set.mem_insert_of_mem _ (Set.mem_insert _ _))) hp₁p₂⟩, p₄ -ᵥ p₃⟩,
⟨hr, vsub_ne_zero.2 hp₃p₄.symm⟩, ?_⟩
simp
convert Real.Angle.sign_eq_of_continuousOn hco hf hsp hp₃p₄s hp₁p₂s
/-- Given three points in strict order on the same line, and a fourth point, the angles at the
fourth point between the first and second or second and third points have the same sign. -/
theorem _root_.Sbtw.oangle_sign_eq {p₁ p₂ p₃ : P} (p₄ : P) (h : Sbtw ℝ p₁ p₂ p₃) :
(∡ p₁ p₄ p₂).sign = (∡ p₂ p₄ p₃).sign :=
haveI hc : Collinear ℝ ({p₁, p₂, p₂, p₃} : Set P) := by simpa using h.wbtw.collinear
hc.oangle_sign_of_sameRay_vsub _ h.left_ne h.ne_right h.wbtw.sameRay_vsub
/-- Given three points in weak order on the same line, with the first not equal to the second,
and a fourth point, the angles at the fourth point between the first and second or first and
third points have the same sign. -/
theorem _root_.Wbtw.oangle_sign_eq_of_ne_left {p₁ p₂ p₃ : P} (p₄ : P) (h : Wbtw ℝ p₁ p₂ p₃)
(hne : p₁ ≠ p₂) : (∡ p₁ p₄ p₂).sign = (∡ p₁ p₄ p₃).sign :=
haveI hc : Collinear ℝ ({p₁, p₂, p₁, p₃} : Set P) := by
simpa [Set.insert_comm p₂] using h.collinear
hc.oangle_sign_of_sameRay_vsub _ hne (h.left_ne_right_of_ne_left hne.symm) h.sameRay_vsub_left
/-- Given three points in strict order on the same line, and a fourth point, the angles at the
fourth point between the first and second or first and third points have the same sign. -/
| Mathlib/Geometry/Euclidean/Angle/Oriented/Affine.lean | 687 | 763 | theorem _root_.Sbtw.oangle_sign_eq_left {p₁ p₂ p₃ : P} (p₄ : P) (h : Sbtw ℝ p₁ p₂ p₃) :
(∡ p₁ p₄ p₂).sign = (∡ p₁ p₄ p₃).sign :=
h.wbtw.oangle_sign_eq_of_ne_left _ h.left_ne
/-- Given three points in weak order on the same line, with the second not equal to the third,
and a fourth point, the angles at the fourth point between the second and third or first and
third points have the same sign. -/
theorem _root_.Wbtw.oangle_sign_eq_of_ne_right {p₁ p₂ p₃ : P} (p₄ : P) (h : Wbtw ℝ p₁ p₂ p₃)
(hne : p₂ ≠ p₃) : (∡ p₂ p₄ p₃).sign = (∡ p₁ p₄ p₃).sign := by | simp_rw [oangle_rev p₃, Real.Angle.sign_neg, h.symm.oangle_sign_eq_of_ne_left _ hne.symm]
/-- Given three points in strict order on the same line, and a fourth point, the angles at the
fourth point between the second and third or first and third points have the same sign. -/
theorem _root_.Sbtw.oangle_sign_eq_right {p₁ p₂ p₃ : P} (p₄ : P) (h : Sbtw ℝ p₁ p₂ p₃) :
(∡ p₂ p₄ p₃).sign = (∡ p₁ p₄ p₃).sign :=
h.wbtw.oangle_sign_eq_of_ne_right _ h.ne_right
/-- Given two points in an affine subspace, the angles between those two points at two other
points on the same side of that subspace have the same sign. -/
theorem _root_.AffineSubspace.SSameSide.oangle_sign_eq {s : AffineSubspace ℝ P} {p₁ p₂ p₃ p₄ : P}
(hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (hp₃p₄ : s.SSameSide p₃ p₄) :
(∡ p₁ p₄ p₂).sign = (∡ p₁ p₃ p₂).sign := by
by_cases h : p₁ = p₂; · simp [h]
let sp : Set (P × P × P) := (fun p : P => (p₁, p, p₂)) '' {p | s.SSameSide p₃ p}
have hc : IsConnected sp :=
(isConnected_setOf_sSameSide hp₃p₄.2.1 hp₃p₄.nonempty).image _ (by fun_prop)
have hf : ContinuousOn (fun p : P × P × P => ∡ p.1 p.2.1 p.2.2) sp := by
refine continuousOn_of_forall_continuousAt fun p hp => continuousAt_oangle ?_ ?_
all_goals
simp_rw [sp, Set.mem_image, Set.mem_setOf] at hp
obtain ⟨p', hp', rfl⟩ := hp
dsimp only
rintro rfl
· exact hp'.2.2 hp₁
· exact hp'.2.2 hp₂
have hsp : ∀ p : P × P × P, p ∈ sp → ∡ p.1 p.2.1 p.2.2 ≠ 0 ∧ ∡ p.1 p.2.1 p.2.2 ≠ π := by
intro p hp
simp_rw [sp, Set.mem_image, Set.mem_setOf] at hp
obtain ⟨p', hp', rfl⟩ := hp
dsimp only
rw [oangle_ne_zero_and_ne_pi_iff_affineIndependent]
exact affineIndependent_of_ne_of_mem_of_not_mem_of_mem h hp₁ hp'.2.2 hp₂
have hp₃ : (p₁, p₃, p₂) ∈ sp :=
Set.mem_image_of_mem _ (sSameSide_self_iff.2 ⟨hp₃p₄.nonempty, hp₃p₄.2.1⟩)
have hp₄ : (p₁, p₄, p₂) ∈ sp := Set.mem_image_of_mem _ hp₃p₄
convert Real.Angle.sign_eq_of_continuousOn hc hf hsp hp₃ hp₄
/-- Given two points in an affine subspace, the angles between those two points at two other
points on opposite sides of that subspace have opposite signs. -/
theorem _root_.AffineSubspace.SOppSide.oangle_sign_eq_neg {s : AffineSubspace ℝ P} {p₁ p₂ p₃ p₄ : P}
(hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (hp₃p₄ : s.SOppSide p₃ p₄) :
(∡ p₁ p₄ p₂).sign = -(∡ p₁ p₃ p₂).sign := by
have hp₁p₃ : p₁ ≠ p₃ := by rintro rfl; exact hp₃p₄.left_not_mem hp₁
rw [← (hp₃p₄.symm.trans (sOppSide_pointReflection hp₁ hp₃p₄.left_not_mem)).oangle_sign_eq hp₁ hp₂,
← oangle_rotate_sign p₁, ← oangle_rotate_sign p₁, oangle_swap₁₃_sign,
(sbtw_pointReflection_of_ne ℝ hp₁p₃).symm.oangle_sign_eq _]
end EuclideanGeometry |
/-
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.Algebra.Algebra.Subalgebra.Tower
import Mathlib.Data.Finite.Sum
import Mathlib.Data.Matrix.Block
import Mathlib.Data.Matrix.Notation
import Mathlib.LinearAlgebra.Basis.Basic
import Mathlib.LinearAlgebra.Basis.Fin
import Mathlib.LinearAlgebra.Basis.Prod
import Mathlib.LinearAlgebra.Basis.SMul
import Mathlib.LinearAlgebra.Matrix.StdBasis
import Mathlib.RingTheory.AlgebraTower
import Mathlib.RingTheory.Ideal.Span
/-!
# Linear maps and matrices
This file defines the maps to send matrices to a linear map,
and to send linear maps between modules with a finite bases
to matrices. This defines a linear equivalence between linear maps
between finite-dimensional vector spaces and matrices indexed by
the respective bases.
## 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.
* `LinearMap.toMatrix`: given bases `v₁ : ι → M₁` and `v₂ : κ → M₂`,
the `R`-linear equivalence from `M₁ →ₗ[R] M₂` to `Matrix κ ι R`
* `Matrix.toLin`: the inverse of `LinearMap.toMatrix`
* `LinearMap.toMatrix'`: the `R`-linear equivalence from `(m → R) →ₗ[R] (n → R)`
to `Matrix m n R` (with the standard basis on `m → R` and `n → R`)
* `Matrix.toLin'`: the inverse of `LinearMap.toMatrix'`
* `algEquivMatrix`: given a basis indexed by `n`, the `R`-algebra equivalence between
`R`-endomorphisms of `M` and `Matrix n n R`
## Issues
This file was originally written without attention to non-commutative rings,
and so mostly only works in the commutative setting. This should be fixed.
In particular, `Matrix.mulVec` gives us a linear equivalence
`Matrix m n R ≃ₗ[R] (n → R) →ₗ[Rᵐᵒᵖ] (m → R)`
while `Matrix.vecMul` gives us a linear equivalence
`Matrix m n R ≃ₗ[Rᵐᵒᵖ] (m → R) →ₗ[R] (n → R)`.
At present, the first equivalence is developed in detail but only for commutative rings
(and we omit the distinction between `Rᵐᵒᵖ` and `R`),
while the second equivalence is developed only in brief, but for not-necessarily-commutative rings.
Naming is slightly inconsistent between the two developments.
In the original (commutative) development `linear` is abbreviated to `lin`,
although this is not consistent with the rest of mathlib.
In the new (non-commutative) development `linear` is not abbreviated, and declarations use `_right`
to indicate they use the right action of matrices on vectors (via `Matrix.vecMul`).
When the two developments are made uniform, the names should be made uniform, too,
by choosing between `linear` and `lin` consistently,
and (presumably) adding `_left` where necessary.
## Tags
linear_map, matrix, linear_equiv, diagonal, det, trace
-/
noncomputable section
open LinearMap Matrix Set Submodule
section ToMatrixRight
variable {R : Type*} [Semiring R]
variable {l m n : Type*}
/-- `Matrix.vecMul M` is a linear map. -/
def Matrix.vecMulLinear [Fintype m] (M : Matrix m n R) : (m → R) →ₗ[R] n → R where
toFun x := x ᵥ* M
map_add' _ _ := funext fun _ ↦ add_dotProduct _ _ _
map_smul' _ _ := funext fun _ ↦ smul_dotProduct _ _ _
@[simp] theorem Matrix.vecMulLinear_apply [Fintype m] (M : Matrix m n R) (x : m → R) :
M.vecMulLinear x = x ᵥ* M := rfl
theorem Matrix.coe_vecMulLinear [Fintype m] (M : Matrix m n R) :
(M.vecMulLinear : _ → _) = M.vecMul := rfl
variable [Fintype m]
theorem range_vecMulLinear (M : Matrix m n R) :
LinearMap.range M.vecMulLinear = span R (range M.row) := by
letI := Classical.decEq m
simp_rw [range_eq_map, ← iSup_range_single, Submodule.map_iSup, range_eq_map, ←
Ideal.span_singleton_one, Ideal.span, Submodule.map_span, image_image, image_singleton,
Matrix.vecMulLinear_apply, iSup_span, range_eq_iUnion, iUnion_singleton_eq_range,
LinearMap.single, LinearMap.coe_mk, AddHom.coe_mk, row_def]
unfold vecMul
simp_rw [single_dotProduct, one_mul]
theorem Matrix.vecMul_injective_iff {R : Type*} [Ring R] {M : Matrix m n R} :
Function.Injective M.vecMul ↔ LinearIndependent R M.row := by
rw [← coe_vecMulLinear]
simp only [← LinearMap.ker_eq_bot, Fintype.linearIndependent_iff, Submodule.eq_bot_iff,
LinearMap.mem_ker, vecMulLinear_apply, row_def]
refine ⟨fun h c h0 ↦ congr_fun <| h c ?_, fun h c h0 ↦ funext <| h c ?_⟩
· rw [← h0]
ext i
simp [vecMul, dotProduct]
· rw [← h0]
ext j
simp [vecMul, dotProduct]
lemma Matrix.linearIndependent_rows_of_isUnit {R : Type*} [Ring R] {A : Matrix m m R}
[DecidableEq m] (ha : IsUnit A) : LinearIndependent R A.row := by
rw [← Matrix.vecMul_injective_iff]
exact Matrix.vecMul_injective_of_isUnit ha
section
variable [DecidableEq m]
/-- Linear maps `(m → R) →ₗ[R] (n → R)` are linearly equivalent over `Rᵐᵒᵖ` to `Matrix m n R`,
by having matrices act by right multiplication.
-/
def LinearMap.toMatrixRight' : ((m → R) →ₗ[R] n → R) ≃ₗ[Rᵐᵒᵖ] Matrix m n R where
toFun f i j := f (single R (fun _ ↦ R) i 1) j
invFun := Matrix.vecMulLinear
right_inv M := by
ext i j
simp
left_inv f := by
apply (Pi.basisFun R m).ext
intro j; ext i
simp
map_add' f g := by
ext i j
simp only [Pi.add_apply, LinearMap.add_apply, Matrix.add_apply]
map_smul' c f := by
ext i j
simp only [Pi.smul_apply, LinearMap.smul_apply, RingHom.id_apply, Matrix.smul_apply]
/-- A `Matrix m n R` is linearly equivalent over `Rᵐᵒᵖ` to a linear map `(m → R) →ₗ[R] (n → R)`,
by having matrices act by right multiplication. -/
abbrev Matrix.toLinearMapRight' [DecidableEq m] : Matrix m n R ≃ₗ[Rᵐᵒᵖ] (m → R) →ₗ[R] n → R :=
LinearEquiv.symm LinearMap.toMatrixRight'
@[simp]
theorem Matrix.toLinearMapRight'_apply (M : Matrix m n R) (v : m → R) :
(Matrix.toLinearMapRight') M v = v ᵥ* M := rfl
@[simp]
theorem Matrix.toLinearMapRight'_mul [Fintype l] [DecidableEq l] (M : Matrix l m R)
(N : Matrix m n R) :
Matrix.toLinearMapRight' (M * N) =
(Matrix.toLinearMapRight' N).comp (Matrix.toLinearMapRight' M) :=
LinearMap.ext fun _x ↦ (vecMul_vecMul _ M N).symm
theorem Matrix.toLinearMapRight'_mul_apply [Fintype l] [DecidableEq l] (M : Matrix l m R)
(N : Matrix m n R) (x) :
Matrix.toLinearMapRight' (M * N) x =
Matrix.toLinearMapRight' N (Matrix.toLinearMapRight' M x) :=
(vecMul_vecMul _ M N).symm
@[simp]
theorem Matrix.toLinearMapRight'_one :
Matrix.toLinearMapRight' (1 : Matrix m m R) = LinearMap.id := by
ext
simp [Module.End.one_apply]
/-- If `M` and `M'` are each other's inverse matrices, they provide an equivalence between `n → A`
and `m → A` corresponding to `M.vecMul` and `M'.vecMul`. -/
@[simps]
def Matrix.toLinearEquivRight'OfInv [Fintype n] [DecidableEq n] {M : Matrix m n R}
{M' : Matrix n m R} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : (n → R) ≃ₗ[R] m → R :=
{ LinearMap.toMatrixRight'.symm M' with
toFun := Matrix.toLinearMapRight' M'
invFun := Matrix.toLinearMapRight' M
left_inv := fun x ↦ by
rw [← Matrix.toLinearMapRight'_mul_apply, hM'M, Matrix.toLinearMapRight'_one, id_apply]
right_inv := fun x ↦ by
rw [← Matrix.toLinearMapRight'_mul_apply, hMM', Matrix.toLinearMapRight'_one, id_apply] }
end
end ToMatrixRight
/-!
From this point on, we only work with commutative rings,
and fail to distinguish between `Rᵐᵒᵖ` and `R`.
This should eventually be remedied.
-/
section mulVec
variable {R : Type*} [CommSemiring R]
variable {k l m n : Type*}
/-- `Matrix.mulVec M` is a linear map. -/
def Matrix.mulVecLin [Fintype n] (M : Matrix m n R) : (n → R) →ₗ[R] m → R where
toFun := M.mulVec
map_add' _ _ := funext fun _ ↦ dotProduct_add _ _ _
map_smul' _ _ := funext fun _ ↦ dotProduct_smul _ _ _
theorem Matrix.coe_mulVecLin [Fintype n] (M : Matrix m n R) :
(M.mulVecLin : _ → _) = M.mulVec := rfl
@[simp]
theorem Matrix.mulVecLin_apply [Fintype n] (M : Matrix m n R) (v : n → R) :
M.mulVecLin v = M *ᵥ v :=
rfl
@[simp]
theorem Matrix.mulVecLin_zero [Fintype n] : Matrix.mulVecLin (0 : Matrix m n R) = 0 :=
LinearMap.ext zero_mulVec
@[simp]
theorem Matrix.mulVecLin_add [Fintype n] (M N : Matrix m n R) :
(M + N).mulVecLin = M.mulVecLin + N.mulVecLin :=
LinearMap.ext fun _ ↦ add_mulVec _ _ _
@[simp] theorem Matrix.mulVecLin_transpose [Fintype m] (M : Matrix m n R) :
Mᵀ.mulVecLin = M.vecMulLinear := by
ext; simp [mulVec_transpose]
@[simp] theorem Matrix.vecMulLinear_transpose [Fintype n] (M : Matrix m n R) :
Mᵀ.vecMulLinear = M.mulVecLin := by
ext; simp [vecMul_transpose]
theorem Matrix.mulVecLin_submatrix [Fintype n] [Fintype l] (f₁ : m → k) (e₂ : n ≃ l)
(M : Matrix k l R) :
(M.submatrix f₁ e₂).mulVecLin = funLeft R R f₁ ∘ₗ M.mulVecLin ∘ₗ funLeft _ _ e₂.symm :=
LinearMap.ext fun _ ↦ submatrix_mulVec_equiv _ _ _ _
/-- A variant of `Matrix.mulVecLin_submatrix` that keeps around `LinearEquiv`s. -/
theorem Matrix.mulVecLin_reindex [Fintype n] [Fintype l] (e₁ : k ≃ m) (e₂ : l ≃ n)
(M : Matrix k l R) :
(reindex e₁ e₂ M).mulVecLin =
↑(LinearEquiv.funCongrLeft R R e₁.symm) ∘ₗ
M.mulVecLin ∘ₗ ↑(LinearEquiv.funCongrLeft R R e₂) :=
Matrix.mulVecLin_submatrix _ _ _
variable [Fintype n]
@[simp]
theorem Matrix.mulVecLin_one [DecidableEq n] :
Matrix.mulVecLin (1 : Matrix n n R) = LinearMap.id := by
ext; simp [Matrix.one_apply, Pi.single_apply, eq_comm]
@[simp]
theorem Matrix.mulVecLin_mul [Fintype m] (M : Matrix l m R) (N : Matrix m n R) :
Matrix.mulVecLin (M * N) = (Matrix.mulVecLin M).comp (Matrix.mulVecLin N) :=
LinearMap.ext fun _ ↦ (mulVec_mulVec _ _ _).symm
theorem Matrix.ker_mulVecLin_eq_bot_iff {M : Matrix m n R} :
(LinearMap.ker M.mulVecLin) = ⊥ ↔ ∀ v, M *ᵥ v = 0 → v = 0 := by
simp only [Submodule.eq_bot_iff, LinearMap.mem_ker, Matrix.mulVecLin_apply]
theorem Matrix.range_mulVecLin (M : Matrix m n R) :
LinearMap.range M.mulVecLin = span R (range M.col) := by
rw [← vecMulLinear_transpose, range_vecMulLinear, row_transpose]
theorem Matrix.mulVec_injective_iff {R : Type*} [CommRing R] {M : Matrix m n R} :
Function.Injective M.mulVec ↔ LinearIndependent R M.col := by
change Function.Injective (fun x ↦ _) ↔ _
simp_rw [← M.vecMul_transpose, vecMul_injective_iff, row_transpose]
lemma Matrix.linearIndependent_cols_of_isUnit {R : Type*} [CommRing R] [Fintype m]
{A : Matrix m m R} [DecidableEq m] (ha : IsUnit A) :
LinearIndependent R A.col := by
rw [← Matrix.mulVec_injective_iff]
exact Matrix.mulVec_injective_of_isUnit ha
end mulVec
section ToMatrix'
variable {R : Type*} [CommSemiring R]
variable {k l m n : Type*} [DecidableEq n] [Fintype n]
/-- Linear maps `(n → R) →ₗ[R] (m → R)` are linearly equivalent to `Matrix m n R`. -/
def LinearMap.toMatrix' : ((n → R) →ₗ[R] m → R) ≃ₗ[R] Matrix m n R where
toFun f := of fun i j ↦ f (Pi.single j 1) i
invFun := Matrix.mulVecLin
right_inv M := by
ext i j
simp only [Matrix.mulVec_single_one, Matrix.mulVecLin_apply, of_apply, transpose_apply]
left_inv f := by
apply (Pi.basisFun R n).ext
intro j; ext i
simp only [Pi.basisFun_apply, Matrix.mulVec_single_one,
Matrix.mulVecLin_apply, of_apply, transpose_apply]
map_add' f g := by
ext i j
simp only [Pi.add_apply, LinearMap.add_apply, of_apply, Matrix.add_apply]
map_smul' c f := by
ext i j
simp only [Pi.smul_apply, LinearMap.smul_apply, RingHom.id_apply, of_apply, Matrix.smul_apply]
/-- A `Matrix m n R` is linearly equivalent to a linear map `(n → R) →ₗ[R] (m → R)`.
Note that the forward-direction does not require `DecidableEq` and is `Matrix.vecMulLin`. -/
def Matrix.toLin' : Matrix m n R ≃ₗ[R] (n → R) →ₗ[R] m → R :=
LinearMap.toMatrix'.symm
theorem Matrix.toLin'_apply' (M : Matrix m n R) : Matrix.toLin' M = M.mulVecLin :=
rfl
@[simp]
theorem LinearMap.toMatrix'_symm :
(LinearMap.toMatrix'.symm : Matrix m n R ≃ₗ[R] _) = Matrix.toLin' :=
rfl
@[simp]
theorem Matrix.toLin'_symm :
(Matrix.toLin'.symm : ((n → R) →ₗ[R] m → R) ≃ₗ[R] _) = LinearMap.toMatrix' :=
rfl
@[simp]
theorem LinearMap.toMatrix'_toLin' (M : Matrix m n R) : LinearMap.toMatrix' (Matrix.toLin' M) = M :=
LinearMap.toMatrix'.apply_symm_apply M
@[simp]
theorem Matrix.toLin'_toMatrix' (f : (n → R) →ₗ[R] m → R) :
Matrix.toLin' (LinearMap.toMatrix' f) = f :=
Matrix.toLin'.apply_symm_apply f
@[simp]
theorem LinearMap.toMatrix'_apply (f : (n → R) →ₗ[R] m → R) (i j) :
LinearMap.toMatrix' f i j = f (fun j' ↦ if j' = j then 1 else 0) i := by
simp only [LinearMap.toMatrix', LinearEquiv.coe_mk, of_apply]
congr! with i
split_ifs with h
· rw [h, Pi.single_eq_same]
apply Pi.single_eq_of_ne h
@[simp]
theorem Matrix.toLin'_apply (M : Matrix m n R) (v : n → R) : Matrix.toLin' M v = M *ᵥ v :=
rfl
@[simp]
theorem Matrix.toLin'_one : Matrix.toLin' (1 : Matrix n n R) = LinearMap.id :=
Matrix.mulVecLin_one
@[simp]
theorem LinearMap.toMatrix'_id : LinearMap.toMatrix' (LinearMap.id : (n → R) →ₗ[R] n → R) = 1 := by
ext
rw [Matrix.one_apply, LinearMap.toMatrix'_apply, id_apply]
@[simp]
theorem LinearMap.toMatrix'_one : LinearMap.toMatrix' (1 : (n → R) →ₗ[R] n → R) = 1 :=
LinearMap.toMatrix'_id
@[simp]
theorem Matrix.toLin'_mul [Fintype m] [DecidableEq m] (M : Matrix l m R) (N : Matrix m n R) :
Matrix.toLin' (M * N) = (Matrix.toLin' M).comp (Matrix.toLin' N) :=
Matrix.mulVecLin_mul _ _
@[simp]
theorem Matrix.toLin'_submatrix [Fintype l] [DecidableEq l] (f₁ : m → k) (e₂ : n ≃ l)
(M : Matrix k l R) :
Matrix.toLin' (M.submatrix f₁ e₂) =
funLeft R R f₁ ∘ₗ (Matrix.toLin' M) ∘ₗ funLeft _ _ e₂.symm :=
Matrix.mulVecLin_submatrix _ _ _
/-- A variant of `Matrix.toLin'_submatrix` that keeps around `LinearEquiv`s. -/
theorem Matrix.toLin'_reindex [Fintype l] [DecidableEq l] (e₁ : k ≃ m) (e₂ : l ≃ n)
(M : Matrix k l R) :
Matrix.toLin' (reindex e₁ e₂ M) =
↑(LinearEquiv.funCongrLeft R R e₁.symm) ∘ₗ (Matrix.toLin' M) ∘ₗ
↑(LinearEquiv.funCongrLeft R R e₂) :=
Matrix.mulVecLin_reindex _ _ _
/-- Shortcut lemma for `Matrix.toLin'_mul` and `LinearMap.comp_apply` -/
theorem Matrix.toLin'_mul_apply [Fintype m] [DecidableEq m] (M : Matrix l m R) (N : Matrix m n R)
(x) : Matrix.toLin' (M * N) x = Matrix.toLin' M (Matrix.toLin' N x) := by
rw [Matrix.toLin'_mul, LinearMap.comp_apply]
theorem LinearMap.toMatrix'_comp [Fintype l] [DecidableEq l] (f : (n → R) →ₗ[R] m → R)
(g : (l → R) →ₗ[R] n → R) :
LinearMap.toMatrix' (f.comp g) = LinearMap.toMatrix' f * LinearMap.toMatrix' g := by
suffices f.comp g = Matrix.toLin' (LinearMap.toMatrix' f * LinearMap.toMatrix' g) by
rw [this, LinearMap.toMatrix'_toLin']
rw [Matrix.toLin'_mul, Matrix.toLin'_toMatrix', Matrix.toLin'_toMatrix']
theorem LinearMap.toMatrix'_mul [Fintype m] [DecidableEq m] (f g : (m → R) →ₗ[R] m → R) :
LinearMap.toMatrix' (f * g) = LinearMap.toMatrix' f * LinearMap.toMatrix' g :=
LinearMap.toMatrix'_comp f g
@[simp]
theorem LinearMap.toMatrix'_algebraMap (x : R) :
LinearMap.toMatrix' (algebraMap R (Module.End R (n → R)) x) = scalar n x := by
simp [Module.algebraMap_end_eq_smul_id, smul_eq_diagonal_mul]
theorem Matrix.ker_toLin'_eq_bot_iff {M : Matrix n n R} :
LinearMap.ker (Matrix.toLin' M) = ⊥ ↔ ∀ v, M *ᵥ v = 0 → v = 0 :=
Matrix.ker_mulVecLin_eq_bot_iff
theorem Matrix.range_toLin' (M : Matrix m n R) :
LinearMap.range (Matrix.toLin' M) = span R (range M.col) :=
Matrix.range_mulVecLin _
/-- If `M` and `M'` are each other's inverse matrices, they provide an equivalence between `m → A`
and `n → A` corresponding to `M.mulVec` and `M'.mulVec`. -/
@[simps]
def Matrix.toLin'OfInv [Fintype m] [DecidableEq m] {M : Matrix m n R} {M' : Matrix n m R}
(hMM' : M * M' = 1) (hM'M : M' * M = 1) : (m → R) ≃ₗ[R] n → R :=
{ Matrix.toLin' M' with
toFun := Matrix.toLin' M'
invFun := Matrix.toLin' M
left_inv := fun x ↦ by rw [← Matrix.toLin'_mul_apply, hMM', Matrix.toLin'_one, id_apply]
right_inv := fun x ↦ by
rw [← Matrix.toLin'_mul_apply, hM'M, Matrix.toLin'_one, id_apply] }
/-- Linear maps `(n → R) →ₗ[R] (n → R)` are algebra equivalent to `Matrix n n R`. -/
def LinearMap.toMatrixAlgEquiv' : ((n → R) →ₗ[R] n → R) ≃ₐ[R] Matrix n n R :=
AlgEquiv.ofLinearEquiv LinearMap.toMatrix' LinearMap.toMatrix'_one LinearMap.toMatrix'_mul
/-- A `Matrix n n R` is algebra equivalent to a linear map `(n → R) →ₗ[R] (n → R)`. -/
def Matrix.toLinAlgEquiv' : Matrix n n R ≃ₐ[R] (n → R) →ₗ[R] n → R :=
LinearMap.toMatrixAlgEquiv'.symm
@[simp]
theorem LinearMap.toMatrixAlgEquiv'_symm :
(LinearMap.toMatrixAlgEquiv'.symm : Matrix n n R ≃ₐ[R] _) = Matrix.toLinAlgEquiv' :=
rfl
@[simp]
theorem Matrix.toLinAlgEquiv'_symm :
(Matrix.toLinAlgEquiv'.symm : ((n → R) →ₗ[R] n → R) ≃ₐ[R] _) = LinearMap.toMatrixAlgEquiv' :=
rfl
@[simp]
theorem LinearMap.toMatrixAlgEquiv'_toLinAlgEquiv' (M : Matrix n n R) :
LinearMap.toMatrixAlgEquiv' (Matrix.toLinAlgEquiv' M) = M :=
LinearMap.toMatrixAlgEquiv'.apply_symm_apply M
@[simp]
theorem Matrix.toLinAlgEquiv'_toMatrixAlgEquiv' (f : (n → R) →ₗ[R] n → R) :
Matrix.toLinAlgEquiv' (LinearMap.toMatrixAlgEquiv' f) = f :=
Matrix.toLinAlgEquiv'.apply_symm_apply f
@[simp]
theorem LinearMap.toMatrixAlgEquiv'_apply (f : (n → R) →ₗ[R] n → R) (i j) :
LinearMap.toMatrixAlgEquiv' f i j = f (fun j' ↦ if j' = j then 1 else 0) i := by
simp [LinearMap.toMatrixAlgEquiv']
@[simp]
theorem Matrix.toLinAlgEquiv'_apply (M : Matrix n n R) (v : n → R) :
Matrix.toLinAlgEquiv' M v = M *ᵥ v :=
rfl
theorem Matrix.toLinAlgEquiv'_one : Matrix.toLinAlgEquiv' (1 : Matrix n n R) = LinearMap.id :=
Matrix.toLin'_one
@[simp]
theorem LinearMap.toMatrixAlgEquiv'_id :
LinearMap.toMatrixAlgEquiv' (LinearMap.id : (n → R) →ₗ[R] n → R) = 1 :=
LinearMap.toMatrix'_id
theorem LinearMap.toMatrixAlgEquiv'_comp (f g : (n → R) →ₗ[R] n → R) :
LinearMap.toMatrixAlgEquiv' (f.comp g) =
LinearMap.toMatrixAlgEquiv' f * LinearMap.toMatrixAlgEquiv' g :=
LinearMap.toMatrix'_comp _ _
theorem LinearMap.toMatrixAlgEquiv'_mul (f g : (n → R) →ₗ[R] n → R) :
LinearMap.toMatrixAlgEquiv' (f * g) =
LinearMap.toMatrixAlgEquiv' f * LinearMap.toMatrixAlgEquiv' g :=
LinearMap.toMatrixAlgEquiv'_comp f g
end ToMatrix'
section ToMatrix
section Finite
variable {R : Type*} [CommSemiring R]
variable {l m n : Type*} [Fintype n] [Finite m] [DecidableEq n]
variable {M₁ M₂ : Type*} [AddCommMonoid M₁] [AddCommMonoid M₂] [Module R M₁] [Module R M₂]
variable (v₁ : Basis n R M₁) (v₂ : Basis m R M₂)
/-- Given bases of two modules `M₁` and `M₂` over a commutative ring `R`, we get a linear
equivalence between linear maps `M₁ →ₗ M₂` and matrices over `R` indexed by the bases. -/
def LinearMap.toMatrix : (M₁ →ₗ[R] M₂) ≃ₗ[R] Matrix m n R :=
LinearEquiv.trans (LinearEquiv.arrowCongr v₁.equivFun v₂.equivFun) LinearMap.toMatrix'
/-- `LinearMap.toMatrix'` is a particular case of `LinearMap.toMatrix`, for the standard basis
`Pi.basisFun R n`. -/
theorem LinearMap.toMatrix_eq_toMatrix' :
LinearMap.toMatrix (Pi.basisFun R n) (Pi.basisFun R n) = LinearMap.toMatrix' :=
rfl
/-- Given bases of two modules `M₁` and `M₂` over a commutative ring `R`, we get a linear
equivalence between matrices over `R` indexed by the bases and linear maps `M₁ →ₗ M₂`. -/
def Matrix.toLin : Matrix m n R ≃ₗ[R] M₁ →ₗ[R] M₂ :=
(LinearMap.toMatrix v₁ v₂).symm
/-- `Matrix.toLin'` is a particular case of `Matrix.toLin`, for the standard basis
`Pi.basisFun R n`. -/
theorem Matrix.toLin_eq_toLin' : Matrix.toLin (Pi.basisFun R n) (Pi.basisFun R m) = Matrix.toLin' :=
rfl
@[simp]
theorem LinearMap.toMatrix_symm : (LinearMap.toMatrix v₁ v₂).symm = Matrix.toLin v₁ v₂ :=
rfl
@[simp]
theorem Matrix.toLin_symm : (Matrix.toLin v₁ v₂).symm = LinearMap.toMatrix v₁ v₂ :=
rfl
@[simp]
theorem Matrix.toLin_toMatrix (f : M₁ →ₗ[R] M₂) :
Matrix.toLin v₁ v₂ (LinearMap.toMatrix v₁ v₂ f) = f := by
rw [← Matrix.toLin_symm, LinearEquiv.apply_symm_apply]
@[simp]
theorem LinearMap.toMatrix_toLin (M : Matrix m n R) :
LinearMap.toMatrix v₁ v₂ (Matrix.toLin v₁ v₂ M) = M := by
rw [← Matrix.toLin_symm, LinearEquiv.symm_apply_apply]
theorem LinearMap.toMatrix_apply (f : M₁ →ₗ[R] M₂) (i : m) (j : n) :
LinearMap.toMatrix v₁ v₂ f i j = v₂.repr (f (v₁ j)) i := by
rw [LinearMap.toMatrix, LinearEquiv.trans_apply, LinearMap.toMatrix'_apply,
LinearEquiv.arrowCongr_apply, Basis.equivFun_symm_apply, Finset.sum_eq_single j, if_pos rfl,
one_smul, Basis.equivFun_apply]
· intro j' _ hj'
rw [if_neg hj', zero_smul]
· intro hj
have := Finset.mem_univ j
contradiction
theorem LinearMap.toMatrix_transpose_apply (f : M₁ →ₗ[R] M₂) (j : n) :
(LinearMap.toMatrix v₁ v₂ f)ᵀ j = v₂.repr (f (v₁ j)) :=
funext fun i ↦ f.toMatrix_apply _ _ i j
theorem LinearMap.toMatrix_apply' (f : M₁ →ₗ[R] M₂) (i : m) (j : n) :
LinearMap.toMatrix v₁ v₂ f i j = v₂.repr (f (v₁ j)) i :=
LinearMap.toMatrix_apply v₁ v₂ f i j
theorem LinearMap.toMatrix_transpose_apply' (f : M₁ →ₗ[R] M₂) (j : n) :
(LinearMap.toMatrix v₁ v₂ f)ᵀ j = v₂.repr (f (v₁ j)) :=
LinearMap.toMatrix_transpose_apply v₁ v₂ f j
/-- This will be a special case of `LinearMap.toMatrix_id_eq_basis_toMatrix`. -/
theorem LinearMap.toMatrix_id : LinearMap.toMatrix v₁ v₁ id = 1 := by
ext i j
simp [LinearMap.toMatrix_apply, Matrix.one_apply, Finsupp.single_apply, eq_comm]
@[simp]
theorem LinearMap.toMatrix_one : LinearMap.toMatrix v₁ v₁ 1 = 1 :=
LinearMap.toMatrix_id v₁
@[simp]
lemma LinearMap.toMatrix_singleton {ι : Type*} [Unique ι] (f : R →ₗ[R] R) (i j : ι) :
f.toMatrix (.singleton ι R) (.singleton ι R) i j = f 1 := by
simp [toMatrix, Subsingleton.elim j default]
@[simp]
theorem Matrix.toLin_one : Matrix.toLin v₁ v₁ 1 = LinearMap.id := by
rw [← LinearMap.toMatrix_id v₁, Matrix.toLin_toMatrix]
theorem LinearMap.toMatrix_reindexRange [DecidableEq M₁] (f : M₁ →ₗ[R] M₂) (k : m) (i : n) :
LinearMap.toMatrix v₁.reindexRange v₂.reindexRange f ⟨v₂ k, Set.mem_range_self k⟩
⟨v₁ i, Set.mem_range_self i⟩ =
LinearMap.toMatrix v₁ v₂ f k i := by
simp_rw [LinearMap.toMatrix_apply, Basis.reindexRange_self, Basis.reindexRange_repr]
@[simp]
theorem LinearMap.toMatrix_algebraMap (x : R) :
LinearMap.toMatrix v₁ v₁ (algebraMap R (Module.End R M₁) x) = scalar n x := by
simp [Module.algebraMap_end_eq_smul_id, LinearMap.toMatrix_id, smul_eq_diagonal_mul]
theorem LinearMap.toMatrix_mulVec_repr (f : M₁ →ₗ[R] M₂) (x : M₁) :
LinearMap.toMatrix v₁ v₂ f *ᵥ v₁.repr x = v₂.repr (f x) := by
ext i
rw [← Matrix.toLin'_apply, LinearMap.toMatrix, LinearEquiv.trans_apply, Matrix.toLin'_toMatrix',
LinearEquiv.arrowCongr_apply, v₂.equivFun_apply]
congr
exact v₁.equivFun.symm_apply_apply x
@[simp]
| Mathlib/LinearAlgebra/Matrix/ToLin.lean | 582 | 584 | theorem LinearMap.toMatrix_basis_equiv [Fintype l] [DecidableEq l] (b : Basis l R M₁)
(b' : Basis l R M₂) :
LinearMap.toMatrix b' b (b'.equiv b (Equiv.refl l) : M₂ →ₗ[R] M₁) = 1 := by | |
/-
Copyright (c) 2021 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Algebra.BigOperators.Fin
import Mathlib.Algebra.Order.Module.Algebra
import Mathlib.Algebra.Ring.Subring.Units
import Mathlib.LinearAlgebra.LinearIndependent.Defs
import Mathlib.Tactic.LinearCombination
import Mathlib.Tactic.Module
import Mathlib.Tactic.Positivity.Basic
/-!
# Rays in modules
This file defines rays in modules.
## Main definitions
* `SameRay`: two vectors belong to the same ray if they are proportional with a nonnegative
coefficient.
* `Module.Ray` is a type for the equivalence class of nonzero vectors in a module with some
common positive multiple.
-/
noncomputable section
section StrictOrderedCommSemiring
-- TODO: remove `[IsStrictOrderedRing R]` and `@[nolint unusedArguments]`.
/-- Two vectors are in the same ray if either one of them is zero or some positive multiples of them
are equal (in the typical case over a field, this means one of them is a nonnegative multiple of
the other). -/
@[nolint unusedArguments]
def SameRay (R : Type*) [CommSemiring R] [PartialOrder R] [IsStrictOrderedRing R]
{M : Type*} [AddCommMonoid M] [Module R M] (v₁ v₂ : M) : Prop :=
v₁ = 0 ∨ v₂ = 0 ∨ ∃ r₁ r₂ : R, 0 < r₁ ∧ 0 < r₂ ∧ r₁ • v₁ = r₂ • v₂
variable {R : Type*} [CommSemiring R] [PartialOrder R] [IsStrictOrderedRing R]
variable {M : Type*} [AddCommMonoid M] [Module R M]
variable {N : Type*} [AddCommMonoid N] [Module R N]
variable (ι : Type*) [DecidableEq ι]
namespace SameRay
variable {x y z : M}
@[simp]
theorem zero_left (y : M) : SameRay R 0 y :=
Or.inl rfl
@[simp]
theorem zero_right (x : M) : SameRay R x 0 :=
Or.inr <| Or.inl rfl
@[nontriviality]
theorem of_subsingleton [Subsingleton M] (x y : M) : SameRay R x y := by
rw [Subsingleton.elim x 0]
exact zero_left _
@[nontriviality]
theorem of_subsingleton' [Subsingleton R] (x y : M) : SameRay R x y :=
haveI := Module.subsingleton R M
of_subsingleton x y
/-- `SameRay` is reflexive. -/
@[refl]
theorem refl (x : M) : SameRay R x x := by
nontriviality R
exact Or.inr (Or.inr <| ⟨1, 1, zero_lt_one, zero_lt_one, rfl⟩)
protected theorem rfl : SameRay R x x :=
refl _
/-- `SameRay` is symmetric. -/
@[symm]
theorem symm (h : SameRay R x y) : SameRay R y x :=
(or_left_comm.1 h).imp_right <| Or.imp_right fun ⟨r₁, r₂, h₁, h₂, h⟩ => ⟨r₂, r₁, h₂, h₁, h.symm⟩
/-- If `x` and `y` are nonzero vectors on the same ray, then there exist positive numbers `r₁ r₂`
such that `r₁ • x = r₂ • y`. -/
theorem exists_pos (h : SameRay R x y) (hx : x ≠ 0) (hy : y ≠ 0) :
∃ r₁ r₂ : R, 0 < r₁ ∧ 0 < r₂ ∧ r₁ • x = r₂ • y :=
(h.resolve_left hx).resolve_left hy
theorem sameRay_comm : SameRay R x y ↔ SameRay R y x :=
⟨SameRay.symm, SameRay.symm⟩
/-- `SameRay` is transitive unless the vector in the middle is zero and both other vectors are
nonzero. -/
theorem trans (hxy : SameRay R x y) (hyz : SameRay R y z) (hy : y = 0 → x = 0 ∨ z = 0) :
SameRay R x z := by
rcases eq_or_ne x 0 with (rfl | hx); · exact zero_left z
rcases eq_or_ne z 0 with (rfl | hz); · exact zero_right x
rcases eq_or_ne y 0 with (rfl | hy)
· exact (hy rfl).elim (fun h => (hx h).elim) fun h => (hz h).elim
rcases hxy.exists_pos hx hy with ⟨r₁, r₂, hr₁, hr₂, h₁⟩
rcases hyz.exists_pos hy hz with ⟨r₃, r₄, hr₃, hr₄, h₂⟩
refine Or.inr (Or.inr <| ⟨r₃ * r₁, r₂ * r₄, mul_pos hr₃ hr₁, mul_pos hr₂ hr₄, ?_⟩)
rw [mul_smul, mul_smul, h₁, ← h₂, smul_comm]
variable {S : Type*} [CommSemiring S] [PartialOrder S]
[Algebra S R] [Module S M] [SMulPosMono S R]
[IsScalarTower S R M] {a : S}
/-- A vector is in the same ray as a nonnegative multiple of itself. -/
lemma sameRay_nonneg_smul_right (v : M) (h : 0 ≤ a) : SameRay R v (a • v) := by
obtain h | h := (algebraMap_nonneg R h).eq_or_gt
· rw [← algebraMap_smul R a v, h, zero_smul]
exact zero_right _
· refine Or.inr <| Or.inr ⟨algebraMap S R a, 1, h, by nontriviality R; exact zero_lt_one, ?_⟩
module
/-- A nonnegative multiple of a vector is in the same ray as that vector. -/
lemma sameRay_nonneg_smul_left (v : M) (ha : 0 ≤ a) : SameRay R (a • v) v :=
(sameRay_nonneg_smul_right v ha).symm
/-- A vector is in the same ray as a positive multiple of itself. -/
lemma sameRay_pos_smul_right (v : M) (ha : 0 < a) : SameRay R v (a • v) :=
sameRay_nonneg_smul_right v ha.le
/-- A positive multiple of a vector is in the same ray as that vector. -/
lemma sameRay_pos_smul_left (v : M) (ha : 0 < a) : SameRay R (a • v) v :=
sameRay_nonneg_smul_left v ha.le
/-- A vector is in the same ray as a nonnegative multiple of one it is in the same ray as. -/
lemma nonneg_smul_right (h : SameRay R x y) (ha : 0 ≤ a) : SameRay R x (a • y) :=
h.trans (sameRay_nonneg_smul_right y ha) fun hy => Or.inr <| by rw [hy, smul_zero]
/-- A nonnegative multiple of a vector is in the same ray as one it is in the same ray as. -/
lemma nonneg_smul_left (h : SameRay R x y) (ha : 0 ≤ a) : SameRay R (a • x) y :=
(h.symm.nonneg_smul_right ha).symm
/-- A vector is in the same ray as a positive multiple of one it is in the same ray as. -/
theorem pos_smul_right (h : SameRay R x y) (ha : 0 < a) : SameRay R x (a • y) :=
h.nonneg_smul_right ha.le
/-- A positive multiple of a vector is in the same ray as one it is in the same ray as. -/
theorem pos_smul_left (h : SameRay R x y) (hr : 0 < a) : SameRay R (a • x) y :=
h.nonneg_smul_left hr.le
/-- If two vectors are on the same ray then they remain so after applying a linear map. -/
theorem map (f : M →ₗ[R] N) (h : SameRay R x y) : SameRay R (f x) (f y) :=
(h.imp fun hx => by rw [hx, map_zero]) <|
Or.imp (fun hy => by rw [hy, map_zero]) fun ⟨r₁, r₂, hr₁, hr₂, h⟩ =>
⟨r₁, r₂, hr₁, hr₂, by rw [← f.map_smul, ← f.map_smul, h]⟩
/-- The images of two vectors under an injective linear map are on the same ray if and only if the
original vectors are on the same ray. -/
theorem _root_.Function.Injective.sameRay_map_iff
{F : Type*} [FunLike F M N] [LinearMapClass F R M N]
{f : F} (hf : Function.Injective f) :
SameRay R (f x) (f y) ↔ SameRay R x y := by
simp only [SameRay, map_zero, ← hf.eq_iff, map_smul]
/-- The images of two vectors under a linear equivalence are on the same ray if and only if the
original vectors are on the same ray. -/
@[simp]
theorem sameRay_map_iff (e : M ≃ₗ[R] N) : SameRay R (e x) (e y) ↔ SameRay R x y :=
Function.Injective.sameRay_map_iff (EquivLike.injective e)
/-- If two vectors are on the same ray then both scaled by the same action are also on the same
ray. -/
theorem smul {S : Type*} [Monoid S] [DistribMulAction S M] [SMulCommClass R S M]
(h : SameRay R x y) (s : S) : SameRay R (s • x) (s • y) :=
h.map (s • (LinearMap.id : M →ₗ[R] M))
/-- If `x` and `y` are on the same ray as `z`, then so is `x + y`. -/
theorem add_left (hx : SameRay R x z) (hy : SameRay R y z) : SameRay R (x + y) z := by
rcases eq_or_ne x 0 with (rfl | hx₀); · rwa [zero_add]
rcases eq_or_ne y 0 with (rfl | hy₀); · rwa [add_zero]
rcases eq_or_ne z 0 with (rfl | hz₀); · apply zero_right
rcases hx.exists_pos hx₀ hz₀ with ⟨rx, rz₁, hrx, hrz₁, Hx⟩
rcases hy.exists_pos hy₀ hz₀ with ⟨ry, rz₂, hry, hrz₂, Hy⟩
refine Or.inr (Or.inr ⟨rx * ry, ry * rz₁ + rx * rz₂, mul_pos hrx hry, ?_, ?_⟩)
· positivity
· convert congr(ry • $Hx + rx • $Hy) using 1 <;> module
/-- If `y` and `z` are on the same ray as `x`, then so is `y + z`. -/
theorem add_right (hy : SameRay R x y) (hz : SameRay R x z) : SameRay R x (y + z) :=
(hy.symm.add_left hz.symm).symm
end SameRay
set_option linter.unusedVariables false in
/-- Nonzero vectors, as used to define rays. This type depends on an unused argument `R` so that
`RayVector.Setoid` can be an instance. -/
@[nolint unusedArguments]
def RayVector (R M : Type*) [Zero M] :=
{ v : M // v ≠ 0 }
instance RayVector.coe [Zero M] : CoeOut (RayVector R M) M where
coe := Subtype.val
instance {R M : Type*} [Zero M] [Nontrivial M] : Nonempty (RayVector R M) :=
let ⟨x, hx⟩ := exists_ne (0 : M)
⟨⟨x, hx⟩⟩
variable (R M)
/-- The setoid of the `SameRay` relation for the subtype of nonzero vectors. -/
instance RayVector.Setoid : Setoid (RayVector R M) where
r x y := SameRay R (x : M) y
iseqv :=
⟨fun _ => SameRay.refl _, fun h => h.symm, by
intros x y z hxy hyz
exact hxy.trans hyz fun hy => (y.2 hy).elim⟩
/-- A ray (equivalence class of nonzero vectors with common positive multiples) in a module. -/
def Module.Ray :=
Quotient (RayVector.Setoid R M)
variable {R M}
/-- Equivalence of nonzero vectors, in terms of `SameRay`. -/
theorem equiv_iff_sameRay {v₁ v₂ : RayVector R M} : v₁ ≈ v₂ ↔ SameRay R (v₁ : M) v₂ :=
Iff.rfl
variable (R)
/-- The ray given by a nonzero vector. -/
def rayOfNeZero (v : M) (h : v ≠ 0) : Module.Ray R M :=
⟦⟨v, h⟩⟧
/-- An induction principle for `Module.Ray`, used as `induction x using Module.Ray.ind`. -/
theorem Module.Ray.ind {C : Module.Ray R M → Prop} (h : ∀ (v) (hv : v ≠ 0), C (rayOfNeZero R v hv))
(x : Module.Ray R M) : C x :=
Quotient.ind (Subtype.rec <| h) x
variable {R}
instance [Nontrivial M] : Nonempty (Module.Ray R M) :=
Nonempty.map Quotient.mk' inferInstance
/-- The rays given by two nonzero vectors are equal if and only if those vectors
satisfy `SameRay`. -/
theorem ray_eq_iff {v₁ v₂ : M} (hv₁ : v₁ ≠ 0) (hv₂ : v₂ ≠ 0) :
rayOfNeZero R _ hv₁ = rayOfNeZero R _ hv₂ ↔ SameRay R v₁ v₂ :=
Quotient.eq'
/-- The ray given by a positive multiple of a nonzero vector. -/
@[simp]
theorem ray_pos_smul {v : M} (h : v ≠ 0) {r : R} (hr : 0 < r) (hrv : r • v ≠ 0) :
rayOfNeZero R (r • v) hrv = rayOfNeZero R v h :=
(ray_eq_iff _ _).2 <| SameRay.sameRay_pos_smul_left v hr
/-- An equivalence between modules implies an equivalence between ray vectors. -/
def RayVector.mapLinearEquiv (e : M ≃ₗ[R] N) : RayVector R M ≃ RayVector R N :=
Equiv.subtypeEquiv e.toEquiv fun _ => e.map_ne_zero_iff.symm
/-- An equivalence between modules implies an equivalence between rays. -/
def Module.Ray.map (e : M ≃ₗ[R] N) : Module.Ray R M ≃ Module.Ray R N :=
Quotient.congr (RayVector.mapLinearEquiv e) fun _ _=> (SameRay.sameRay_map_iff _).symm
@[simp]
theorem Module.Ray.map_apply (e : M ≃ₗ[R] N) (v : M) (hv : v ≠ 0) :
Module.Ray.map e (rayOfNeZero _ v hv) = rayOfNeZero _ (e v) (e.map_ne_zero_iff.2 hv) :=
rfl
@[simp]
theorem Module.Ray.map_refl : (Module.Ray.map <| LinearEquiv.refl R M) = Equiv.refl _ :=
Equiv.ext <| Module.Ray.ind R fun _ _ => rfl
@[simp]
theorem Module.Ray.map_symm (e : M ≃ₗ[R] N) : (Module.Ray.map e).symm = Module.Ray.map e.symm :=
rfl
section Action
variable {G : Type*} [Group G] [DistribMulAction G M]
/-- Any invertible action preserves the non-zeroness of ray vectors. This is primarily of interest
when `G = Rˣ` -/
instance {R : Type*} : MulAction G (RayVector R M) where
smul r := Subtype.map (r • ·) fun _ => (smul_ne_zero_iff_ne _).2
mul_smul a b _ := Subtype.ext <| mul_smul a b _
one_smul _ := Subtype.ext <| one_smul _ _
variable [SMulCommClass R G M]
/-- Any invertible action preserves the non-zeroness of rays. This is primarily of interest when
`G = Rˣ` -/
instance : MulAction G (Module.Ray R M) where
smul r := Quotient.map (r • ·) fun _ _ h => h.smul _
mul_smul a b := Quotient.ind fun _ => congr_arg Quotient.mk' <| mul_smul a b _
one_smul := Quotient.ind fun _ => congr_arg Quotient.mk' <| one_smul _ _
/-- The action via `LinearEquiv.apply_distribMulAction` corresponds to `Module.Ray.map`. -/
@[simp]
theorem Module.Ray.linearEquiv_smul_eq_map (e : M ≃ₗ[R] M) (v : Module.Ray R M) :
e • v = Module.Ray.map e v :=
rfl
@[simp]
theorem smul_rayOfNeZero (g : G) (v : M) (hv) :
g • rayOfNeZero R v hv = rayOfNeZero R (g • v) ((smul_ne_zero_iff_ne _).2 hv) :=
rfl
end Action
namespace Module.Ray
/-- Scaling by a positive unit is a no-op. -/
theorem units_smul_of_pos (u : Rˣ) (hu : 0 < (u : R)) (v : Module.Ray R M) : u • v = v := by
induction v using Module.Ray.ind
rw [smul_rayOfNeZero, ray_eq_iff]
exact SameRay.sameRay_pos_smul_left _ hu
/-- An arbitrary `RayVector` giving a ray. -/
def someRayVector (x : Module.Ray R M) : RayVector R M :=
Quotient.out x
/-- The ray of `someRayVector`. -/
@[simp]
theorem someRayVector_ray (x : Module.Ray R M) : (⟦x.someRayVector⟧ : Module.Ray R M) = x :=
Quotient.out_eq _
/-- An arbitrary nonzero vector giving a ray. -/
def someVector (x : Module.Ray R M) : M :=
x.someRayVector
/-- `someVector` is nonzero. -/
@[simp]
theorem someVector_ne_zero (x : Module.Ray R M) : x.someVector ≠ 0 :=
x.someRayVector.property
/-- The ray of `someVector`. -/
@[simp]
theorem someVector_ray (x : Module.Ray R M) : rayOfNeZero R _ x.someVector_ne_zero = x :=
(congr_arg _ (Subtype.coe_eta _ _) :).trans x.out_eq
end Module.Ray
end StrictOrderedCommSemiring
section StrictOrderedCommRing
variable {R : Type*} [CommRing R] [PartialOrder R] [IsStrictOrderedRing R]
variable {M N : Type*} [AddCommGroup M] [AddCommGroup N] [Module R M] [Module R N] {x y : M}
/-- `SameRay.neg` as an `iff`. -/
@[simp]
theorem sameRay_neg_iff : SameRay R (-x) (-y) ↔ SameRay R x y := by
simp only [SameRay, neg_eq_zero, smul_neg, neg_inj]
alias ⟨SameRay.of_neg, SameRay.neg⟩ := sameRay_neg_iff
theorem sameRay_neg_swap : SameRay R (-x) y ↔ SameRay R x (-y) := by rw [← sameRay_neg_iff, neg_neg]
theorem eq_zero_of_sameRay_neg_smul_right [NoZeroSMulDivisors R M] {r : R} (hr : r < 0)
(h : SameRay R x (r • x)) : x = 0 := by
rcases h with (rfl | h₀ | ⟨r₁, r₂, hr₁, hr₂, h⟩)
· rfl
· simpa [hr.ne] using h₀
· rw [← sub_eq_zero, smul_smul, ← sub_smul, smul_eq_zero] at h
refine h.resolve_left (ne_of_gt <| sub_pos.2 ?_)
exact (mul_neg_of_pos_of_neg hr₂ hr).trans hr₁
/-- If a vector is in the same ray as its negation, that vector is zero. -/
theorem eq_zero_of_sameRay_self_neg [NoZeroSMulDivisors R M] (h : SameRay R x (-x)) : x = 0 := by
nontriviality M; haveI : Nontrivial R := Module.nontrivial R M
refine eq_zero_of_sameRay_neg_smul_right (neg_lt_zero.2 (zero_lt_one' R)) ?_
rwa [neg_one_smul]
namespace RayVector
/-- Negating a nonzero vector. -/
instance {R : Type*} : Neg (RayVector R M) :=
⟨fun v => ⟨-v, neg_ne_zero.2 v.prop⟩⟩
/-- Negating a nonzero vector commutes with coercion to the underlying module. -/
@[simp, norm_cast]
theorem coe_neg {R : Type*} (v : RayVector R M) : ↑(-v) = -(v : M) :=
rfl
/-- Negating a nonzero vector twice produces the original vector. -/
instance {R : Type*} : InvolutiveNeg (RayVector R M) where
neg := Neg.neg
neg_neg v := by rw [Subtype.ext_iff, coe_neg, coe_neg, neg_neg]
/-- If two nonzero vectors are equivalent, so are their negations. -/
@[simp]
theorem equiv_neg_iff {v₁ v₂ : RayVector R M} : -v₁ ≈ -v₂ ↔ v₁ ≈ v₂ :=
sameRay_neg_iff
end RayVector
variable (R)
/-- Negating a ray. -/
instance : Neg (Module.Ray R M) :=
⟨Quotient.map (fun v => -v) fun _ _ => RayVector.equiv_neg_iff.2⟩
/-- The ray given by the negation of a nonzero vector. -/
@[simp]
theorem neg_rayOfNeZero (v : M) (h : v ≠ 0) :
-rayOfNeZero R _ h = rayOfNeZero R (-v) (neg_ne_zero.2 h) :=
rfl
namespace Module.Ray
variable {R}
/-- Negating a ray twice produces the original ray. -/
instance : InvolutiveNeg (Module.Ray R M) where
neg := Neg.neg
neg_neg x := by apply ind R (by simp) x
-- Quotient.ind (fun a => congr_arg Quotient.mk' <| neg_neg _) x
/-- A ray does not equal its own negation. -/
theorem ne_neg_self [NoZeroSMulDivisors R M] (x : Module.Ray R M) : x ≠ -x := by
induction x using Module.Ray.ind with | h x hx =>
rw [neg_rayOfNeZero, Ne, ray_eq_iff]
exact mt eq_zero_of_sameRay_self_neg hx
theorem neg_units_smul (u : Rˣ) (v : Module.Ray R M) : -u • v = -(u • v) := by
induction v using Module.Ray.ind
simp only [smul_rayOfNeZero, Units.smul_def, Units.val_neg, neg_smul, neg_rayOfNeZero]
/-- Scaling by a negative unit is negation. -/
theorem units_smul_of_neg (u : Rˣ) (hu : (u : R) < 0) (v : Module.Ray R M) : u • v = -v := by
rw [← neg_inj, neg_neg, ← neg_units_smul, units_smul_of_pos]
rwa [Units.val_neg, Right.neg_pos_iff]
@[simp]
protected theorem map_neg (f : M ≃ₗ[R] N) (v : Module.Ray R M) : map f (-v) = -map f v := by
induction v using Module.Ray.ind with | h g hg => simp
end Module.Ray
end StrictOrderedCommRing
section LinearOrderedCommRing
variable {R : Type*} [CommRing R] [LinearOrder R] [IsStrictOrderedRing R]
variable {M : Type*} [AddCommGroup M] [Module R M]
/-- `SameRay` follows from membership of `MulAction.orbit` for the `Units.posSubgroup`. -/
theorem sameRay_of_mem_orbit {v₁ v₂ : M} (h : v₁ ∈ MulAction.orbit (Units.posSubgroup R) v₂) :
SameRay R v₁ v₂ := by
rcases h with ⟨⟨r, hr : 0 < r.1⟩, rfl : r • v₂ = v₁⟩
exact SameRay.sameRay_pos_smul_left _ hr
/-- Scaling by an inverse unit is the same as scaling by itself. -/
@[simp]
theorem units_inv_smul (u : Rˣ) (v : Module.Ray R M) : u⁻¹ • v = u • v :=
have := mul_self_pos.2 u.ne_zero
calc
u⁻¹ • v = (u * u) • u⁻¹ • v := Eq.symm <| (u⁻¹ • v).units_smul_of_pos _ (by exact this)
_ = u • v := by rw [mul_smul, smul_inv_smul]
section
variable [NoZeroSMulDivisors R M]
@[simp]
theorem sameRay_smul_right_iff {v : M} {r : R} : SameRay R v (r • v) ↔ 0 ≤ r ∨ v = 0 :=
⟨fun hrv => or_iff_not_imp_left.2 fun hr => eq_zero_of_sameRay_neg_smul_right (not_le.1 hr) hrv,
or_imp.2 ⟨SameRay.sameRay_nonneg_smul_right v, fun h => h.symm ▸ SameRay.zero_left _⟩⟩
/-- A nonzero vector is in the same ray as a multiple of itself if and only if that multiple
is positive. -/
theorem sameRay_smul_right_iff_of_ne {v : M} (hv : v ≠ 0) {r : R} (hr : r ≠ 0) :
SameRay R v (r • v) ↔ 0 < r := by
simp only [sameRay_smul_right_iff, hv, or_false, hr.symm.le_iff_lt]
@[simp]
theorem sameRay_smul_left_iff {v : M} {r : R} : SameRay R (r • v) v ↔ 0 ≤ r ∨ v = 0 :=
SameRay.sameRay_comm.trans sameRay_smul_right_iff
/-- A multiple of a nonzero vector is in the same ray as that vector if and only if that multiple
is positive. -/
theorem sameRay_smul_left_iff_of_ne {v : M} (hv : v ≠ 0) {r : R} (hr : r ≠ 0) :
SameRay R (r • v) v ↔ 0 < r :=
SameRay.sameRay_comm.trans (sameRay_smul_right_iff_of_ne hv hr)
@[simp]
theorem sameRay_neg_smul_right_iff {v : M} {r : R} : SameRay R (-v) (r • v) ↔ r ≤ 0 ∨ v = 0 := by
rw [← sameRay_neg_iff, neg_neg, ← neg_smul, sameRay_smul_right_iff, neg_nonneg]
theorem sameRay_neg_smul_right_iff_of_ne {v : M} {r : R} (hv : v ≠ 0) (hr : r ≠ 0) :
SameRay R (-v) (r • v) ↔ r < 0 := by
simp only [sameRay_neg_smul_right_iff, hv, or_false, hr.le_iff_lt]
@[simp]
theorem sameRay_neg_smul_left_iff {v : M} {r : R} : SameRay R (r • v) (-v) ↔ r ≤ 0 ∨ v = 0 :=
SameRay.sameRay_comm.trans sameRay_neg_smul_right_iff
theorem sameRay_neg_smul_left_iff_of_ne {v : M} {r : R} (hv : v ≠ 0) (hr : r ≠ 0) :
SameRay R (r • v) (-v) ↔ r < 0 :=
SameRay.sameRay_comm.trans <| sameRay_neg_smul_right_iff_of_ne hv hr
@[simp]
theorem units_smul_eq_self_iff {u : Rˣ} {v : Module.Ray R M} : u • v = v ↔ 0 < (u : R) := by
induction v using Module.Ray.ind with | h v hv =>
simp only [smul_rayOfNeZero, ray_eq_iff, Units.smul_def, sameRay_smul_left_iff_of_ne hv u.ne_zero]
@[simp]
theorem units_smul_eq_neg_iff {u : Rˣ} {v : Module.Ray R M} : u • v = -v ↔ u.1 < 0 := by
rw [← neg_inj, neg_neg, ← Module.Ray.neg_units_smul, units_smul_eq_self_iff, Units.val_neg,
neg_pos]
/-- Two vectors are in the same ray, or the first is in the same ray as the negation of the
second, if and only if they are not linearly independent. -/
theorem sameRay_or_sameRay_neg_iff_not_linearIndependent {x y : M} :
SameRay R x y ∨ SameRay R x (-y) ↔ ¬LinearIndependent R ![x, y] := by
by_cases hx : x = 0; · simpa [hx] using fun h : LinearIndependent R ![0, y] => h.ne_zero 0 rfl
by_cases hy : y = 0; · simpa [hy] using fun h : LinearIndependent R ![x, 0] => h.ne_zero 1 rfl
simp_rw [Fintype.not_linearIndependent_iff]
refine ⟨fun h => ?_, fun h => ?_⟩
· rcases h with ((hx0 | hy0 | ⟨r₁, r₂, hr₁, _, h⟩) | (hx0 | hy0 | ⟨r₁, r₂, hr₁, _, h⟩))
· exact False.elim (hx hx0)
· exact False.elim (hy hy0)
· refine ⟨![r₁, -r₂], ?_⟩
rw [Fin.sum_univ_two, Fin.exists_fin_two]
simp [h, hr₁.ne.symm]
· exact False.elim (hx hx0)
· exact False.elim (hy (neg_eq_zero.1 hy0))
· refine ⟨![r₁, r₂], ?_⟩
rw [Fin.sum_univ_two, Fin.exists_fin_two]
simp [h, hr₁.ne.symm]
· rcases h with ⟨m, hm, hmne⟩
rw [Fin.sum_univ_two, add_eq_zero_iff_eq_neg] at hm
dsimp only [Matrix.cons_val] at hm
rcases lt_trichotomy (m 0) 0 with (hm0 | hm0 | hm0) <;>
rcases lt_trichotomy (m 1) 0 with (hm1 | hm1 | hm1)
· refine
Or.inr (Or.inr (Or.inr ⟨-m 0, -m 1, Left.neg_pos_iff.2 hm0, Left.neg_pos_iff.2 hm1, ?_⟩))
linear_combination (norm := module) -hm
· exfalso
simp [hm1, hx, hm0.ne] at hm
· refine Or.inl (Or.inr (Or.inr ⟨-m 0, m 1, Left.neg_pos_iff.2 hm0, hm1, ?_⟩))
linear_combination (norm := module) -hm
· exfalso
simp [hm0, hy, hm1.ne] at hm
· rw [Fin.exists_fin_two] at hmne
exact False.elim (not_and_or.2 hmne ⟨hm0, hm1⟩)
· exfalso
simp [hm0, hy, hm1.ne.symm] at hm
· refine Or.inl (Or.inr (Or.inr ⟨m 0, -m 1, hm0, Left.neg_pos_iff.2 hm1, ?_⟩))
rwa [neg_smul]
· exfalso
simp [hm1, hx, hm0.ne.symm] at hm
· refine Or.inr (Or.inr (Or.inr ⟨m 0, m 1, hm0, hm1, ?_⟩))
rwa [smul_neg]
/-- Two vectors are in the same ray, or they are nonzero and the first is in the same ray as the
negation of the second, if and only if they are not linearly independent. -/
theorem sameRay_or_ne_zero_and_sameRay_neg_iff_not_linearIndependent {x y : M} :
SameRay R x y ∨ x ≠ 0 ∧ y ≠ 0 ∧ SameRay R x (-y) ↔ ¬LinearIndependent R ![x, y] := by
rw [← sameRay_or_sameRay_neg_iff_not_linearIndependent]
by_cases hx : x = 0; · simp [hx]
by_cases hy : y = 0 <;> simp [hx, hy]
end
end LinearOrderedCommRing
namespace SameRay
variable {R : Type*} [Field R] [LinearOrder R] [IsStrictOrderedRing R]
variable {M : Type*} [AddCommGroup M] [Module R M] {x y v₁ v₂ : M}
theorem exists_pos_left (h : SameRay R x y) (hx : x ≠ 0) (hy : y ≠ 0) :
∃ r : R, 0 < r ∧ r • x = y :=
let ⟨r₁, r₂, hr₁, hr₂, h⟩ := h.exists_pos hx hy
⟨r₂⁻¹ * r₁, mul_pos (inv_pos.2 hr₂) hr₁, by rw [mul_smul, h, inv_smul_smul₀ hr₂.ne']⟩
theorem exists_pos_right (h : SameRay R x y) (hx : x ≠ 0) (hy : y ≠ 0) :
∃ r : R, 0 < r ∧ x = r • y :=
(h.symm.exists_pos_left hy hx).imp fun _ => And.imp_right Eq.symm
/-- If a vector `v₂` is on the same ray as a nonzero vector `v₁`, then it is equal to `c • v₁` for
some nonnegative `c`. -/
| Mathlib/LinearAlgebra/Ray.lean | 577 | 579 | theorem exists_nonneg_left (h : SameRay R x y) (hx : x ≠ 0) : ∃ r : R, 0 ≤ r ∧ r • x = y := by | obtain rfl | hy := eq_or_ne y 0
· exact ⟨0, le_rfl, zero_smul _ _⟩ |
/-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Jeremy Avigad
-/
import Mathlib.Logic.Basic
import Mathlib.Logic.Function.Defs
import Mathlib.Order.Defs.LinearOrder
/-!
# Booleans
This file proves various trivial lemmas about booleans and their
relation to decidable propositions.
## Tags
bool, boolean, Bool, De Morgan
-/
namespace Bool
section
/-!
This section contains lemmas about booleans which were present in core Lean 3.
The remainder of this file contains lemmas about booleans from mathlib 3.
-/
theorem true_eq_false_eq_False : ¬true = false := by decide
theorem false_eq_true_eq_False : ¬false = true := by decide
theorem eq_false_eq_not_eq_true (b : Bool) : (¬b = true) = (b = false) := by simp
theorem eq_true_eq_not_eq_false (b : Bool) : (¬b = false) = (b = true) := by simp
theorem eq_false_of_not_eq_true {b : Bool} : ¬b = true → b = false :=
Eq.mp (eq_false_eq_not_eq_true b)
theorem eq_true_of_not_eq_false {b : Bool} : ¬b = false → b = true :=
Eq.mp (eq_true_eq_not_eq_false b)
theorem and_eq_true_eq_eq_true_and_eq_true (a b : Bool) :
((a && b) = true) = (a = true ∧ b = true) := by simp
theorem or_eq_true_eq_eq_true_or_eq_true (a b : Bool) :
((a || b) = true) = (a = true ∨ b = true) := by simp
theorem not_eq_true_eq_eq_false (a : Bool) : (not a = true) = (a = false) := by cases a <;> simp
#adaptation_note /-- nightly-2024-03-05
this is no longer a simp lemma, as the LHS simplifies. -/
theorem and_eq_false_eq_eq_false_or_eq_false (a b : Bool) :
((a && b) = false) = (a = false ∨ b = false) := by
cases a <;> cases b <;> simp
theorem or_eq_false_eq_eq_false_and_eq_false (a b : Bool) :
((a || b) = false) = (a = false ∧ b = false) := by
cases a <;> cases b <;> simp
theorem not_eq_false_eq_eq_true (a : Bool) : (not a = false) = (a = true) := by cases a <;> simp
theorem coe_false : ↑false = False := by simp
theorem coe_true : ↑true = True := by simp
theorem coe_sort_false : (false : Prop) = False := by simp
theorem coe_sort_true : (true : Prop) = True := by simp
theorem decide_iff (p : Prop) [d : Decidable p] : decide p = true ↔ p := by simp
theorem decide_true {p : Prop} [Decidable p] : p → decide p :=
(decide_iff p).2
theorem of_decide_true {p : Prop} [Decidable p] : decide p → p :=
(decide_iff p).1
theorem bool_iff_false {b : Bool} : ¬b ↔ b = false := by cases b <;> decide
theorem bool_eq_false {b : Bool} : ¬b → b = false :=
bool_iff_false.1
theorem decide_false_iff (p : Prop) {_ : Decidable p} : decide p = false ↔ ¬p :=
bool_iff_false.symm.trans (not_congr (decide_iff _))
theorem decide_false {p : Prop} [Decidable p] : ¬p → decide p = false :=
(decide_false_iff p).2
theorem of_decide_false {p : Prop} [Decidable p] : decide p = false → ¬p :=
(decide_false_iff p).1
theorem decide_congr {p q : Prop} [Decidable p] [Decidable q] (h : p ↔ q) : decide p = decide q :=
decide_eq_decide.mpr h
theorem coe_xor_iff (a b : Bool) : xor a b ↔ Xor' (a = true) (b = true) := by
cases a <;> cases b <;> decide
end
theorem dichotomy (b : Bool) : b = false ∨ b = true := by cases b <;> simp
theorem not_ne_id : not ≠ id := fun h ↦ false_ne_true <| congrFun h true
theorem or_inl {a b : Bool} (H : a) : a || b := by simp [H]
theorem or_inr {a b : Bool} (H : b) : a || b := by cases a <;> simp [H]
theorem and_elim_left : ∀ {a b : Bool}, a && b → a := by decide
theorem and_intro : ∀ {a b : Bool}, a → b → a && b := by decide
theorem and_elim_right : ∀ {a b : Bool}, a && b → b := by decide
lemma eq_not_iff : ∀ {a b : Bool}, a = !b ↔ a ≠ b := by decide
lemma not_eq_iff : ∀ {a b : Bool}, !a = b ↔ a ≠ b := by decide
theorem ne_not {a b : Bool} : a ≠ !b ↔ a = b :=
not_eq_not
lemma not_ne_self : ∀ b : Bool, (!b) ≠ b := by decide
lemma self_ne_not : ∀ b : Bool, b ≠ !b := by decide
lemma eq_or_eq_not : ∀ a b, a = b ∨ a = !b := by decide
-- TODO naming issue: these two `not` are different.
theorem not_iff_not : ∀ {b : Bool}, !b ↔ ¬b := by simp
theorem eq_true_of_not_eq_false' {a : Bool} : !a = false → a = true := by
cases a <;> decide
theorem eq_false_of_not_eq_true' {a : Bool} : !a = true → a = false := by
cases a <;> decide
theorem bne_eq_xor : bne = xor := by funext a b; revert a b; decide
attribute [simp] xor_assoc
theorem xor_iff_ne : ∀ {x y : Bool}, xor x y = true ↔ x ≠ y := by decide
/-! ### De Morgan's laws for booleans -/
instance linearOrder : LinearOrder Bool where
le_refl := by decide
le_trans := by decide
le_antisymm := by decide
le_total := by decide
toDecidableLE := inferInstance
toDecidableEq := inferInstance
toDecidableLT := inferInstance
lt_iff_le_not_le := by decide
max_def := by decide
min_def := by decide
| Mathlib/Data/Bool/Basic.lean | 158 | 159 | theorem lt_iff : ∀ {x y : Bool}, x < y ↔ x = false ∧ y = true := by | decide |
/-
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.Calculus.BumpFunction.FiniteDimension
import Mathlib.Geometry.Manifold.ContMDiff.Atlas
import Mathlib.Geometry.Manifold.ContMDiff.NormedSpace
import Mathlib.Topology.MetricSpace.ProperSpace.Lemmas
/-!
# Smooth bump functions on a smooth manifold
In this file we define `SmoothBumpFunction I c` to be a bundled smooth "bump" function centered at
`c`. It is a structure that consists of two real numbers `0 < rIn < rOut` with small enough `rOut`.
We define a coercion to function for this type, and for `f : SmoothBumpFunction I c`, the function
`⇑f` written in the extended chart at `c` has the following properties:
* `f x = 1` in the closed ball of radius `f.rIn` centered at `c`;
* `f x = 0` outside of the ball of radius `f.rOut` centered at `c`;
* `0 ≤ f x ≤ 1` for all `x`.
The actual statements involve (pre)images under `extChartAt I f` and are given as lemmas in the
`SmoothBumpFunction` namespace.
## Tags
manifold, smooth bump function
-/
universe uE uF uH uM
variable {E : Type uE} [NormedAddCommGroup E] [NormedSpace ℝ E]
{H : Type uH} [TopologicalSpace H] {I : ModelWithCorners ℝ E H} {M : Type uM} [TopologicalSpace M]
[ChartedSpace H M]
open Function Filter Module Set Metric
open scoped Topology Manifold ContDiff
noncomputable section
/-!
### Smooth bump function
In this section we define a structure for a bundled smooth bump function and prove its properties.
-/
variable (I) in
/-- Given a smooth manifold modelled on a finite dimensional space `E`,
`f : SmoothBumpFunction I M` is a smooth function on `M` such that in the extended chart `e` at
`f.c`:
* `f x = 1` in the closed ball of radius `f.rIn` centered at `f.c`;
* `f x = 0` outside of the ball of radius `f.rOut` centered at `f.c`;
* `0 ≤ f x ≤ 1` for all `x`.
The structure contains data required to construct a function with these properties. The function is
available as `⇑f` or `f x`. Formal statements of the properties listed above involve some
(pre)images under `extChartAt I f.c` and are given as lemmas in the `SmoothBumpFunction`
namespace. -/
structure SmoothBumpFunction (c : M) extends ContDiffBump (extChartAt I c c) where
closedBall_subset : closedBall (extChartAt I c c) rOut ∩ range I ⊆ (extChartAt I c).target
namespace SmoothBumpFunction
section FiniteDimensional
variable [FiniteDimensional ℝ E]
variable {c : M} (f : SmoothBumpFunction I c) {x : M}
/-- The function defined by `f : SmoothBumpFunction c`. Use automatic coercion to function
instead. -/
@[coe] def toFun : M → ℝ :=
indicator (chartAt H c).source (f.toContDiffBump ∘ extChartAt I c)
instance : CoeFun (SmoothBumpFunction I c) fun _ => M → ℝ :=
⟨toFun⟩
theorem coe_def : ⇑f = indicator (chartAt H c).source (f.toContDiffBump ∘ extChartAt I c) :=
rfl
end FiniteDimensional
variable {c : M} (f : SmoothBumpFunction I c) {x : M}
theorem rOut_pos : 0 < f.rOut :=
f.toContDiffBump.rOut_pos
theorem ball_subset : ball (extChartAt I c c) f.rOut ∩ range I ⊆ (extChartAt I c).target :=
Subset.trans (inter_subset_inter_left _ ball_subset_closedBall) f.closedBall_subset
theorem ball_inter_range_eq_ball_inter_target :
ball (extChartAt I c c) f.rOut ∩ range I =
ball (extChartAt I c c) f.rOut ∩ (extChartAt I c).target :=
(subset_inter inter_subset_left f.ball_subset).antisymm <| inter_subset_inter_right _ <|
extChartAt_target_subset_range _
section FiniteDimensional
variable [FiniteDimensional ℝ E]
theorem eqOn_source : EqOn f (f.toContDiffBump ∘ extChartAt I c) (chartAt H c).source :=
eqOn_indicator
theorem eventuallyEq_of_mem_source (hx : x ∈ (chartAt H c).source) :
f =ᶠ[𝓝 x] f.toContDiffBump ∘ extChartAt I c :=
f.eqOn_source.eventuallyEq_of_mem <| (chartAt H c).open_source.mem_nhds hx
theorem one_of_dist_le (hs : x ∈ (chartAt H c).source)
(hd : dist (extChartAt I c x) (extChartAt I c c) ≤ f.rIn) : f x = 1 := by
simp only [f.eqOn_source hs, (· ∘ ·), f.one_of_mem_closedBall hd]
theorem support_eq_inter_preimage :
support f = (chartAt H c).source ∩ extChartAt I c ⁻¹' ball (extChartAt I c c) f.rOut := by
rw [coe_def, support_indicator, support_comp_eq_preimage, ← extChartAt_source I,
← (extChartAt I c).symm_image_target_inter_eq', ← (extChartAt I c).symm_image_target_inter_eq',
f.support_eq]
theorem isOpen_support : IsOpen (support f) := by
rw [support_eq_inter_preimage]
exact isOpen_extChartAt_preimage c isOpen_ball
theorem support_eq_symm_image :
support f = (extChartAt I c).symm '' (ball (extChartAt I c c) f.rOut ∩ range I) := by
rw [f.support_eq_inter_preimage, ← extChartAt_source I,
← (extChartAt I c).symm_image_target_inter_eq', inter_comm,
ball_inter_range_eq_ball_inter_target]
| Mathlib/Geometry/Manifold/BumpFunction.lean | 131 | 132 | theorem support_subset_source : support f ⊆ (chartAt H c).source := by | rw [f.support_eq_inter_preimage, ← extChartAt_source I]; exact inter_subset_left |
/-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Yakov Pechersky
-/
import Mathlib.Data.List.Nodup
import Mathlib.Data.List.Infix
import Mathlib.Data.Quot
/-!
# List rotation
This file proves basic results about `List.rotate`, the list rotation.
## Main declarations
* `List.IsRotated l₁ l₂`: States that `l₁` is a rotated version of `l₂`.
* `List.cyclicPermutations l`: The list of all cyclic permutants of `l`, up to the length of `l`.
## Tags
rotated, rotation, permutation, cycle
-/
universe u
variable {α : Type u}
open Nat Function
namespace List
theorem rotate_mod (l : List α) (n : ℕ) : l.rotate (n % l.length) = l.rotate n := by simp [rotate]
@[simp]
theorem rotate_nil (n : ℕ) : ([] : List α).rotate n = [] := by simp [rotate]
@[simp]
theorem rotate_zero (l : List α) : l.rotate 0 = l := by simp [rotate]
theorem rotate'_nil (n : ℕ) : ([] : List α).rotate' n = [] := by simp
@[simp]
theorem rotate'_zero (l : List α) : l.rotate' 0 = l := by cases l <;> rfl
theorem rotate'_cons_succ (l : List α) (a : α) (n : ℕ) :
(a :: l : List α).rotate' n.succ = (l ++ [a]).rotate' n := by simp [rotate']
@[simp]
theorem length_rotate' : ∀ (l : List α) (n : ℕ), (l.rotate' n).length = l.length
| [], _ => by simp
| _ :: _, 0 => rfl
| a :: l, n + 1 => by rw [List.rotate', length_rotate' (l ++ [a]) n]; simp
theorem rotate'_eq_drop_append_take :
∀ {l : List α} {n : ℕ}, n ≤ l.length → l.rotate' n = l.drop n ++ l.take n
| [], n, h => by simp [drop_append_of_le_length h]
| l, 0, h => by simp [take_append_of_le_length h]
| a :: l, n + 1, h => by
have hnl : n ≤ l.length := le_of_succ_le_succ h
have hnl' : n ≤ (l ++ [a]).length := by
rw [length_append, length_cons, List.length]; exact le_of_succ_le h
rw [rotate'_cons_succ, rotate'_eq_drop_append_take hnl', drop, take,
drop_append_of_le_length hnl, take_append_of_le_length hnl]; simp
| Mathlib/Data/List/Rotate.lean | 67 | 76 | theorem rotate'_rotate' : ∀ (l : List α) (n m : ℕ), (l.rotate' n).rotate' m = l.rotate' (n + m)
| a :: l, 0, m => by simp
| [], n, m => by simp
| a :: l, n + 1, m => by
rw [rotate'_cons_succ, rotate'_rotate' _ n, Nat.add_right_comm, ← rotate'_cons_succ,
Nat.succ_eq_add_one]
@[simp]
theorem rotate'_length (l : List α) : rotate' l l.length = l := by | rw [rotate'_eq_drop_append_take le_rfl]; simp |
/-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Mathlib.Data.Stream.Defs
import Mathlib.Logic.Function.Basic
import Mathlib.Data.List.Defs
import Mathlib.Data.Nat.Basic
import Mathlib.Tactic.Common
/-!
# Streams a.k.a. infinite lists a.k.a. infinite sequences
-/
open Nat Function Option
namespace Stream'
universe u v w
variable {α : Type u} {β : Type v} {δ : Type w}
variable (m n : ℕ) (x y : List α) (a b : Stream' α)
instance [Inhabited α] : Inhabited (Stream' α) :=
⟨Stream'.const default⟩
@[simp] protected theorem eta (s : Stream' α) : head s :: tail s = s :=
funext fun i => by cases i <;> rfl
/-- Alias for `Stream'.eta` to match `List` API. -/
alias cons_head_tail := Stream'.eta
@[ext]
protected theorem ext {s₁ s₂ : Stream' α} : (∀ n, get s₁ n = get s₂ n) → s₁ = s₂ :=
fun h => funext h
@[simp]
theorem get_zero_cons (a : α) (s : Stream' α) : get (a::s) 0 = a :=
rfl
@[simp]
theorem head_cons (a : α) (s : Stream' α) : head (a::s) = a :=
rfl
@[simp]
theorem tail_cons (a : α) (s : Stream' α) : tail (a::s) = s :=
rfl
@[simp]
theorem get_drop (n m : ℕ) (s : Stream' α) : get (drop m s) n = get s (m + n) := by
rw [Nat.add_comm]
rfl
theorem tail_eq_drop (s : Stream' α) : tail s = drop 1 s :=
rfl
@[simp]
theorem drop_drop (n m : ℕ) (s : Stream' α) : drop n (drop m s) = drop (m + n) s := by
ext; simp [Nat.add_assoc]
@[simp] theorem get_tail {n : ℕ} {s : Stream' α} : s.tail.get n = s.get (n + 1) := rfl
@[simp] theorem tail_drop' {i : ℕ} {s : Stream' α} : tail (drop i s) = s.drop (i + 1) := by
ext; simp [Nat.add_comm, Nat.add_assoc, Nat.add_left_comm]
@[simp] theorem drop_tail' {i : ℕ} {s : Stream' α} : drop i (tail s) = s.drop (i + 1) := rfl
theorem tail_drop (n : ℕ) (s : Stream' α) : tail (drop n s) = drop n (tail s) := by simp
theorem get_succ (n : ℕ) (s : Stream' α) : get s (succ n) = get (tail s) n :=
rfl
@[simp]
theorem get_succ_cons (n : ℕ) (s : Stream' α) (x : α) : get (x :: s) n.succ = get s n :=
rfl
@[simp] lemma get_cons_append_zero {a : α} {x : List α} {s : Stream' α} :
(a :: x ++ₛ s).get 0 = a := rfl
@[simp] lemma append_eq_cons {a : α} {as : Stream' α} : [a] ++ₛ as = a :: as := by rfl
@[simp] theorem drop_zero {s : Stream' α} : s.drop 0 = s := rfl
theorem drop_succ (n : ℕ) (s : Stream' α) : drop (succ n) s = drop n (tail s) :=
rfl
theorem head_drop (a : Stream' α) (n : ℕ) : (a.drop n).head = a.get n := by simp
theorem cons_injective2 : Function.Injective2 (cons : α → Stream' α → Stream' α) := fun x y s t h =>
⟨by rw [← get_zero_cons x s, h, get_zero_cons],
Stream'.ext fun n => by rw [← get_succ_cons n _ x, h, get_succ_cons]⟩
theorem cons_injective_left (s : Stream' α) : Function.Injective fun x => cons x s :=
cons_injective2.left _
theorem cons_injective_right (x : α) : Function.Injective (cons x) :=
cons_injective2.right _
theorem all_def (p : α → Prop) (s : Stream' α) : All p s = ∀ n, p (get s n) :=
rfl
theorem any_def (p : α → Prop) (s : Stream' α) : Any p s = ∃ n, p (get s n) :=
rfl
@[simp]
theorem mem_cons (a : α) (s : Stream' α) : a ∈ a::s :=
Exists.intro 0 rfl
theorem mem_cons_of_mem {a : α} {s : Stream' α} (b : α) : a ∈ s → a ∈ b::s := fun ⟨n, h⟩ =>
Exists.intro (succ n) (by rw [get_succ, tail_cons, h])
theorem eq_or_mem_of_mem_cons {a b : α} {s : Stream' α} : (a ∈ b::s) → a = b ∨ a ∈ s :=
fun ⟨n, h⟩ => by
rcases n with - | n'
· left
exact h
· right
rw [get_succ, tail_cons] at h
exact ⟨n', h⟩
theorem mem_of_get_eq {n : ℕ} {s : Stream' α} {a : α} : a = get s n → a ∈ s := fun h =>
Exists.intro n h
section Map
variable (f : α → β)
theorem drop_map (n : ℕ) (s : Stream' α) : drop n (map f s) = map f (drop n s) :=
Stream'.ext fun _ => rfl
@[simp]
theorem get_map (n : ℕ) (s : Stream' α) : get (map f s) n = f (get s n) :=
rfl
theorem tail_map (s : Stream' α) : tail (map f s) = map f (tail s) := rfl
@[simp]
theorem head_map (s : Stream' α) : head (map f s) = f (head s) :=
rfl
theorem map_eq (s : Stream' α) : map f s = f (head s)::map f (tail s) := by
rw [← Stream'.eta (map f s), tail_map, head_map]
theorem map_cons (a : α) (s : Stream' α) : map f (a::s) = f a::map f s := by
rw [← Stream'.eta (map f (a::s)), map_eq]; rfl
@[simp]
theorem map_id (s : Stream' α) : map id s = s :=
rfl
@[simp]
theorem map_map (g : β → δ) (f : α → β) (s : Stream' α) : map g (map f s) = map (g ∘ f) s :=
rfl
@[simp]
theorem map_tail (s : Stream' α) : map f (tail s) = tail (map f s) :=
rfl
theorem mem_map {a : α} {s : Stream' α} : a ∈ s → f a ∈ map f s := fun ⟨n, h⟩ =>
Exists.intro n (by rw [get_map, h])
theorem exists_of_mem_map {f} {b : β} {s : Stream' α} : b ∈ map f s → ∃ a, a ∈ s ∧ f a = b :=
fun ⟨n, h⟩ => ⟨get s n, ⟨n, rfl⟩, h.symm⟩
end Map
section Zip
variable (f : α → β → δ)
theorem drop_zip (n : ℕ) (s₁ : Stream' α) (s₂ : Stream' β) :
drop n (zip f s₁ s₂) = zip f (drop n s₁) (drop n s₂) :=
Stream'.ext fun _ => rfl
@[simp]
theorem get_zip (n : ℕ) (s₁ : Stream' α) (s₂ : Stream' β) :
get (zip f s₁ s₂) n = f (get s₁ n) (get s₂ n) :=
rfl
theorem head_zip (s₁ : Stream' α) (s₂ : Stream' β) : head (zip f s₁ s₂) = f (head s₁) (head s₂) :=
rfl
theorem tail_zip (s₁ : Stream' α) (s₂ : Stream' β) :
tail (zip f s₁ s₂) = zip f (tail s₁) (tail s₂) :=
rfl
theorem zip_eq (s₁ : Stream' α) (s₂ : Stream' β) :
zip f s₁ s₂ = f (head s₁) (head s₂)::zip f (tail s₁) (tail s₂) := by
rw [← Stream'.eta (zip f s₁ s₂)]; rfl
@[simp]
theorem get_enum (s : Stream' α) (n : ℕ) : get (enum s) n = (n, s.get n) :=
rfl
theorem enum_eq_zip (s : Stream' α) : enum s = zip Prod.mk nats s :=
rfl
end Zip
@[simp]
theorem mem_const (a : α) : a ∈ const a :=
Exists.intro 0 rfl
theorem const_eq (a : α) : const a = a::const a := by
apply Stream'.ext; intro n
cases n <;> rfl
@[simp]
theorem tail_const (a : α) : tail (const a) = const a :=
suffices tail (a::const a) = const a by rwa [← const_eq] at this
rfl
@[simp]
theorem map_const (f : α → β) (a : α) : map f (const a) = const (f a) :=
rfl
@[simp]
theorem get_const (n : ℕ) (a : α) : get (const a) n = a :=
rfl
@[simp]
theorem drop_const (n : ℕ) (a : α) : drop n (const a) = const a :=
Stream'.ext fun _ => rfl
@[simp]
theorem head_iterate (f : α → α) (a : α) : head (iterate f a) = a :=
rfl
theorem get_succ_iterate' (n : ℕ) (f : α → α) (a : α) :
get (iterate f a) (succ n) = f (get (iterate f a) n) := rfl
theorem tail_iterate (f : α → α) (a : α) : tail (iterate f a) = iterate f (f a) := by
ext n
rw [get_tail]
induction' n with n' ih
· rfl
· rw [get_succ_iterate', ih, get_succ_iterate']
theorem iterate_eq (f : α → α) (a : α) : iterate f a = a::iterate f (f a) := by
rw [← Stream'.eta (iterate f a)]
rw [tail_iterate]; rfl
@[simp]
theorem get_zero_iterate (f : α → α) (a : α) : get (iterate f a) 0 = a :=
rfl
theorem get_succ_iterate (n : ℕ) (f : α → α) (a : α) :
get (iterate f a) (succ n) = get (iterate f (f a)) n := by rw [get_succ, tail_iterate]
section Bisim
variable (R : Stream' α → Stream' α → Prop)
/-- equivalence relation -/
local infixl:50 " ~ " => R
/-- Streams `s₁` and `s₂` are defined to be bisimulations if
their heads are equal and tails are bisimulations. -/
def IsBisimulation :=
∀ ⦃s₁ s₂⦄, s₁ ~ s₂ →
head s₁ = head s₂ ∧ tail s₁ ~ tail s₂
theorem get_of_bisim (bisim : IsBisimulation R) {s₁ s₂} :
∀ n, s₁ ~ s₂ → get s₁ n = get s₂ n ∧ drop (n + 1) s₁ ~ drop (n + 1) s₂
| 0, h => bisim h
| n + 1, h =>
match bisim h with
| ⟨_, trel⟩ => get_of_bisim bisim n trel
-- If two streams are bisimilar, then they are equal
theorem eq_of_bisim (bisim : IsBisimulation R) {s₁ s₂} : s₁ ~ s₂ → s₁ = s₂ := fun r =>
Stream'.ext fun n => And.left (get_of_bisim R bisim n r)
end Bisim
theorem bisim_simple (s₁ s₂ : Stream' α) :
head s₁ = head s₂ → s₁ = tail s₁ → s₂ = tail s₂ → s₁ = s₂ := fun hh ht₁ ht₂ =>
eq_of_bisim (fun s₁ s₂ => head s₁ = head s₂ ∧ s₁ = tail s₁ ∧ s₂ = tail s₂)
(fun s₁ s₂ ⟨h₁, h₂, h₃⟩ => by
constructor
· exact h₁
rw [← h₂, ← h₃]
(repeat' constructor) <;> assumption)
(And.intro hh (And.intro ht₁ ht₂))
theorem coinduction {s₁ s₂ : Stream' α} :
head s₁ = head s₂ →
(∀ (β : Type u) (fr : Stream' α → β),
fr s₁ = fr s₂ → fr (tail s₁) = fr (tail s₂)) → s₁ = s₂ :=
fun hh ht =>
eq_of_bisim
(fun s₁ s₂ =>
head s₁ = head s₂ ∧
∀ (β : Type u) (fr : Stream' α → β), fr s₁ = fr s₂ → fr (tail s₁) = fr (tail s₂))
(fun s₁ s₂ h =>
have h₁ : head s₁ = head s₂ := And.left h
have h₂ : head (tail s₁) = head (tail s₂) := And.right h α (@head α) h₁
have h₃ :
∀ (β : Type u) (fr : Stream' α → β),
fr (tail s₁) = fr (tail s₂) → fr (tail (tail s₁)) = fr (tail (tail s₂)) :=
fun β fr => And.right h β fun s => fr (tail s)
And.intro h₁ (And.intro h₂ h₃))
(And.intro hh ht)
@[simp]
theorem iterate_id (a : α) : iterate id a = const a :=
coinduction rfl fun β fr ch => by rw [tail_iterate, tail_const]; exact ch
theorem map_iterate (f : α → α) (a : α) : iterate f (f a) = map f (iterate f a) := by
funext n
induction' n with n' ih
· rfl
· unfold map iterate get
rw [map, get] at ih
rw [iterate]
exact congrArg f ih
section Corec
theorem corec_def (f : α → β) (g : α → α) (a : α) : corec f g a = map f (iterate g a) :=
rfl
theorem corec_eq (f : α → β) (g : α → α) (a : α) : corec f g a = f a :: corec f g (g a) := by
rw [corec_def, map_eq, head_iterate, tail_iterate]; rfl
theorem corec_id_id_eq_const (a : α) : corec id id a = const a := by
rw [corec_def, map_id, iterate_id]
theorem corec_id_f_eq_iterate (f : α → α) (a : α) : corec id f a = iterate f a :=
rfl
end Corec
section Corec'
theorem corec'_eq (f : α → β × α) (a : α) : corec' f a = (f a).1 :: corec' f (f a).2 :=
corec_eq _ _ _
end Corec'
theorem unfolds_eq (g : α → β) (f : α → α) (a : α) : unfolds g f a = g a :: unfolds g f (f a) := by
unfold unfolds; rw [corec_eq]
theorem get_unfolds_head_tail : ∀ (n : ℕ) (s : Stream' α),
get (unfolds head tail s) n = get s n := by
intro n; induction' n with n' ih
· intro s
rfl
· intro s
rw [get_succ, get_succ, unfolds_eq, tail_cons, ih]
theorem unfolds_head_eq : ∀ s : Stream' α, unfolds head tail s = s := fun s =>
Stream'.ext fun n => get_unfolds_head_tail n s
theorem interleave_eq (s₁ s₂ : Stream' α) : s₁ ⋈ s₂ = head s₁::head s₂::(tail s₁ ⋈ tail s₂) := by
let t := tail s₁ ⋈ tail s₂
show s₁ ⋈ s₂ = head s₁::head s₂::t
unfold interleave; unfold corecOn; rw [corec_eq]; dsimp; rw [corec_eq]; rfl
theorem tail_interleave (s₁ s₂ : Stream' α) : tail (s₁ ⋈ s₂) = s₂ ⋈ tail s₁ := by
unfold interleave corecOn; rw [corec_eq]; rfl
theorem interleave_tail_tail (s₁ s₂ : Stream' α) : tail s₁ ⋈ tail s₂ = tail (tail (s₁ ⋈ s₂)) := by
rw [interleave_eq s₁ s₂]; rfl
theorem get_interleave_left : ∀ (n : ℕ) (s₁ s₂ : Stream' α),
get (s₁ ⋈ s₂) (2 * n) = get s₁ n
| 0, _, _ => rfl
| n + 1, s₁, s₂ => by
change get (s₁ ⋈ s₂) (succ (succ (2 * n))) = get s₁ (succ n)
rw [get_succ, get_succ, interleave_eq, tail_cons, tail_cons]
rw [get_interleave_left n (tail s₁) (tail s₂)]
rfl
theorem get_interleave_right : ∀ (n : ℕ) (s₁ s₂ : Stream' α),
get (s₁ ⋈ s₂) (2 * n + 1) = get s₂ n
| 0, _, _ => rfl
| n + 1, s₁, s₂ => by
change get (s₁ ⋈ s₂) (succ (succ (2 * n + 1))) = get s₂ (succ n)
rw [get_succ, get_succ, interleave_eq, tail_cons, tail_cons,
get_interleave_right n (tail s₁) (tail s₂)]
rfl
theorem mem_interleave_left {a : α} {s₁ : Stream' α} (s₂ : Stream' α) : a ∈ s₁ → a ∈ s₁ ⋈ s₂ :=
fun ⟨n, h⟩ => Exists.intro (2 * n) (by rw [h, get_interleave_left])
theorem mem_interleave_right {a : α} {s₁ : Stream' α} (s₂ : Stream' α) : a ∈ s₂ → a ∈ s₁ ⋈ s₂ :=
fun ⟨n, h⟩ => Exists.intro (2 * n + 1) (by rw [h, get_interleave_right])
theorem odd_eq (s : Stream' α) : odd s = even (tail s) :=
rfl
@[simp]
theorem head_even (s : Stream' α) : head (even s) = head s :=
rfl
theorem tail_even (s : Stream' α) : tail (even s) = even (tail (tail s)) := by
unfold even
rw [corec_eq]
rfl
theorem even_cons_cons (a₁ a₂ : α) (s : Stream' α) : even (a₁::a₂::s) = a₁::even s := by
unfold even
rw [corec_eq]; rfl
theorem even_tail (s : Stream' α) : even (tail s) = odd s :=
rfl
theorem even_interleave (s₁ s₂ : Stream' α) : even (s₁ ⋈ s₂) = s₁ :=
eq_of_bisim (fun s₁' s₁ => ∃ s₂, s₁' = even (s₁ ⋈ s₂))
(fun s₁' s₁ ⟨s₂, h₁⟩ => by
rw [h₁]
constructor
· rfl
· exact ⟨tail s₂, by rw [interleave_eq, even_cons_cons, tail_cons]⟩)
(Exists.intro s₂ rfl)
theorem interleave_even_odd (s₁ : Stream' α) : even s₁ ⋈ odd s₁ = s₁ :=
eq_of_bisim (fun s' s => s' = even s ⋈ odd s)
(fun s' s (h : s' = even s ⋈ odd s) => by
rw [h]; constructor
· rfl
· simp [odd_eq, odd_eq, tail_interleave, tail_even])
rfl
theorem get_even : ∀ (n : ℕ) (s : Stream' α), get (even s) n = get s (2 * n)
| 0, _ => rfl
| succ n, s => by
change get (even s) (succ n) = get s (succ (succ (2 * n)))
rw [get_succ, get_succ, tail_even, get_even n]; rfl
theorem get_odd : ∀ (n : ℕ) (s : Stream' α), get (odd s) n = get s (2 * n + 1) := fun n s => by
rw [odd_eq, get_even]; rfl
theorem mem_of_mem_even (a : α) (s : Stream' α) : a ∈ even s → a ∈ s := fun ⟨n, h⟩ =>
Exists.intro (2 * n) (by rw [h, get_even])
theorem mem_of_mem_odd (a : α) (s : Stream' α) : a ∈ odd s → a ∈ s := fun ⟨n, h⟩ =>
Exists.intro (2 * n + 1) (by rw [h, get_odd])
@[simp] theorem nil_append_stream (s : Stream' α) : appendStream' [] s = s :=
rfl
theorem cons_append_stream (a : α) (l : List α) (s : Stream' α) :
appendStream' (a::l) s = a::appendStream' l s :=
rfl
@[simp] theorem append_append_stream : ∀ (l₁ l₂ : List α) (s : Stream' α),
l₁ ++ l₂ ++ₛ s = l₁ ++ₛ (l₂ ++ₛ s)
| [], _, _ => rfl
| List.cons a l₁, l₂, s => by
rw [List.cons_append, cons_append_stream, cons_append_stream, append_append_stream l₁]
lemma get_append_left (h : n < x.length) : (x ++ₛ a).get n = x[n] := by
induction' x with b x ih generalizing n
· simp at h
· rcases n with (_ | n)
· simp
· simp [ih n (by simpa using h), cons_append_stream]
@[simp] lemma get_append_right : (x ++ₛ a).get (x.length + n) = a.get n := by
induction' x <;> simp [Nat.succ_add, *, cons_append_stream]
@[simp] lemma get_append_length : (x ++ₛ a).get x.length = a.get 0 := get_append_right 0 x a
lemma append_right_injective (h : x ++ₛ a = x ++ₛ b) : a = b := by
ext n; replace h := congr_arg (fun a ↦ a.get (x.length + n)) h; simpa using h
@[simp] lemma append_right_inj : x ++ₛ a = x ++ₛ b ↔ a = b :=
⟨append_right_injective x a b, by simp +contextual⟩
lemma append_left_injective (h : x ++ₛ a = y ++ₛ b) (hl : x.length = y.length) : x = y := by
apply List.ext_getElem hl
intros
rw [← get_append_left, ← get_append_left, h]
theorem map_append_stream (f : α → β) :
∀ (l : List α) (s : Stream' α), map f (l ++ₛ s) = List.map f l ++ₛ map f s
| [], _ => rfl
| List.cons a l, s => by
rw [cons_append_stream, List.map_cons, map_cons, cons_append_stream, map_append_stream f l]
theorem drop_append_stream : ∀ (l : List α) (s : Stream' α), drop l.length (l ++ₛ s) = s
| [], s => by rfl
| List.cons a l, s => by
rw [List.length_cons, drop_succ, cons_append_stream, tail_cons, drop_append_stream l s]
theorem append_stream_head_tail (s : Stream' α) : [head s] ++ₛ tail s = s := by
simp
theorem mem_append_stream_right : ∀ {a : α} (l : List α) {s : Stream' α}, a ∈ s → a ∈ l ++ₛ s
| _, [], _, h => h
| a, List.cons _ l, s, h =>
have ih : a ∈ l ++ₛ s := mem_append_stream_right l h
mem_cons_of_mem _ ih
theorem mem_append_stream_left : ∀ {a : α} {l : List α} (s : Stream' α), a ∈ l → a ∈ l ++ₛ s
| _, [], _, h => absurd h List.not_mem_nil
| a, List.cons b l, s, h =>
Or.elim (List.eq_or_mem_of_mem_cons h) (fun aeqb : a = b => Exists.intro 0 aeqb)
fun ainl : a ∈ l => mem_cons_of_mem b (mem_append_stream_left s ainl)
@[simp]
theorem take_zero (s : Stream' α) : take 0 s = [] :=
rfl
-- This lemma used to be simp, but we removed it from the simp set because:
-- 1) It duplicates the (often large) `s` term, resulting in large tactic states.
-- 2) It conflicts with the very useful `dropLast_take` lemma below (causing nonconfluence).
theorem take_succ (n : ℕ) (s : Stream' α) : take (succ n) s = head s::take n (tail s) :=
rfl
@[simp] theorem take_succ_cons {a : α} (n : ℕ) (s : Stream' α) :
take (n+1) (a::s) = a :: take n s := rfl
theorem take_succ' {s : Stream' α} : ∀ n, s.take (n+1) = s.take n ++ [s.get n]
| 0 => rfl
| n+1 => by rw [take_succ, take_succ' n, ← List.cons_append, ← take_succ, get_tail]
@[simp]
theorem length_take (n : ℕ) (s : Stream' α) : (take n s).length = n := by
induction n generalizing s <;> simp [*, take_succ]
@[simp]
theorem take_take {s : Stream' α} : ∀ {m n}, (s.take n).take m = s.take (min n m)
| 0, n => by rw [Nat.min_zero, List.take_zero, take_zero]
| m, 0 => by rw [Nat.zero_min, take_zero, List.take_nil]
| m+1, n+1 => by rw [take_succ, List.take_succ_cons, Nat.succ_min_succ, take_succ, take_take]
@[simp] theorem concat_take_get {n : ℕ} {s : Stream' α} : s.take n ++ [s.get n] = s.take (n + 1) :=
(take_succ' n).symm
theorem getElem?_take {s : Stream' α} : ∀ {k n}, k < n → (s.take n)[k]? = s.get k
| 0, _+1, _ => by simp only [length_take, zero_lt_succ, List.getElem?_eq_getElem]; rfl
| k+1, n+1, h => by
rw [take_succ, List.getElem?_cons_succ, getElem?_take (Nat.lt_of_succ_lt_succ h), get_succ]
@[deprecated (since := "2025-02-14")] alias get?_take := getElem?_take
theorem getElem?_take_succ (n : ℕ) (s : Stream' α) :
(take (succ n) s)[n]? = some (get s n) :=
getElem?_take (Nat.lt_succ_self n)
@[deprecated (since := "2025-02-14")] alias get?_take_succ := getElem?_take_succ
@[simp] theorem dropLast_take {n : ℕ} {xs : Stream' α} :
(Stream'.take n xs).dropLast = Stream'.take (n-1) xs := by
cases n with
| zero => simp
| succ n => rw [take_succ', List.dropLast_concat, Nat.add_one_sub_one]
@[simp]
theorem append_take_drop : ∀ (n : ℕ) (s : Stream' α),
appendStream' (take n s) (drop n s) = s := by
intro n
induction' n with n' ih
· intro s
rfl
· intro s
rw [take_succ, drop_succ, cons_append_stream, ih (tail s), Stream'.eta]
lemma append_take : x ++ (a.take n) = (x ++ₛ a).take (x.length + n) := by
induction' x <;> simp [take, Nat.add_comm, cons_append_stream, *]
@[simp] lemma take_get (h : m < (a.take n).length) : (a.take n)[m] = a.get m := by
nth_rw 2 [← append_take_drop n a]; rw [get_append_left]
theorem take_append_of_le_length (h : n ≤ x.length) :
(x ++ₛ a).take n = x.take n := by
apply List.ext_getElem (by simp [h])
intro _ _ _; rw [List.getElem_take, take_get, get_append_left]
lemma take_add : a.take (m + n) = a.take m ++ (a.drop m).take n := by
apply append_left_injective _ _ (a.drop (m + n)) ((a.drop m).drop n) <;>
simp [- drop_drop]
@[gcongr] lemma take_prefix_take_left (h : m ≤ n) : a.take m <+: a.take n := by
rw [(by simp [h] : a.take m = (a.take n).take m)]
apply List.take_prefix
@[simp] lemma take_prefix : a.take m <+: a.take n ↔ m ≤ n :=
⟨fun h ↦ by simpa using h.length_le, take_prefix_take_left m n a⟩
lemma map_take (f : α → β) : (a.take n).map f = (a.map f).take n := by
apply List.ext_getElem <;> simp
lemma take_drop : (a.drop m).take n = (a.take (m + n)).drop m := by
apply List.ext_getElem <;> simp
lemma drop_append_of_le_length (h : n ≤ x.length) :
(x ++ₛ a).drop n = x.drop n ++ₛ a := by
obtain ⟨m, hm⟩ := Nat.exists_eq_add_of_le h
ext k; rcases lt_or_ge k m with _ | hk
· rw [get_drop, get_append_left, get_append_left, List.getElem_drop]; simpa [hm]
· obtain ⟨p, rfl⟩ := Nat.exists_eq_add_of_le hk
have hm' : m = (x.drop n).length := by simp [hm]
simp_rw [get_drop, ← Nat.add_assoc, ← hm, get_append_right, hm', get_append_right]
-- Take theorem reduces a proof of equality of infinite streams to an
-- induction over all their finite approximations.
theorem take_theorem (s₁ s₂ : Stream' α) : (∀ n : ℕ, take n s₁ = take n s₂) → s₁ = s₂ := by
intro h; apply Stream'.ext; intro n
induction' n with n _
· have aux := h 1
simp? [take] at aux says
simp only [take, List.cons.injEq, and_true] at aux
exact aux
· have h₁ : some (get s₁ (succ n)) = some (get s₂ (succ n)) := by
rw [← getElem?_take_succ, ← getElem?_take_succ, h (succ (succ n))]
injection h₁
protected theorem cycle_g_cons (a : α) (a₁ : α) (l₁ : List α) (a₀ : α) (l₀ : List α) :
Stream'.cycleG (a, a₁::l₁, a₀, l₀) = (a₁, l₁, a₀, l₀) :=
rfl
theorem cycle_eq : ∀ (l : List α) (h : l ≠ []), cycle l h = l ++ₛ cycle l h
| [], h => absurd rfl h
| List.cons a l, _ =>
have gen : ∀ l' a', corec Stream'.cycleF Stream'.cycleG (a', l', a, l) =
(a'::l') ++ₛ corec Stream'.cycleF Stream'.cycleG (a, l, a, l) := by
intro l'
induction' l' with a₁ l₁ ih
· intros
rw [corec_eq]
rfl
· intros
rw [corec_eq, Stream'.cycle_g_cons, ih a₁]
rfl
gen l a
theorem mem_cycle {a : α} {l : List α} : ∀ h : l ≠ [], a ∈ l → a ∈ cycle l h := fun h ainl => by
rw [cycle_eq]; exact mem_append_stream_left _ ainl
@[simp]
theorem cycle_singleton (a : α) : cycle [a] (by simp) = const a :=
coinduction rfl fun β fr ch => by rwa [cycle_eq, const_eq]
theorem tails_eq (s : Stream' α) : tails s = tail s::tails (tail s) := by
unfold tails; rw [corec_eq]; rfl
@[simp]
theorem get_tails : ∀ (n : ℕ) (s : Stream' α), get (tails s) n = drop n (tail s) := by
intro n; induction' n with n' ih
· intros
rfl
· intro s
rw [get_succ, drop_succ, tails_eq, tail_cons, ih]
theorem tails_eq_iterate (s : Stream' α) : tails s = iterate tail (tail s) :=
rfl
theorem inits_core_eq (l : List α) (s : Stream' α) :
initsCore l s = l::initsCore (l ++ [head s]) (tail s) := by
unfold initsCore corecOn
rw [corec_eq]
theorem tail_inits (s : Stream' α) :
tail (inits s) = initsCore [head s, head (tail s)] (tail (tail s)) := by
unfold inits
rw [inits_core_eq]; rfl
theorem inits_tail (s : Stream' α) : inits (tail s) = initsCore [head (tail s)] (tail (tail s)) :=
rfl
theorem cons_get_inits_core :
∀ (a : α) (n : ℕ) (l : List α) (s : Stream' α),
(a::get (initsCore l s) n) = get (initsCore (a::l) s) n := by
intro a n
induction' n with n' ih
· intros
rfl
· intro l s
rw [get_succ, inits_core_eq, tail_cons, ih, inits_core_eq (a::l) s]
rfl
@[simp]
theorem get_inits : ∀ (n : ℕ) (s : Stream' α), get (inits s) n = take (succ n) s := by
intro n; induction' n with n' ih
· intros
rfl
· intros
rw [get_succ, take_succ, ← ih, tail_inits, inits_tail, cons_get_inits_core]
theorem inits_eq (s : Stream' α) :
inits s = [head s]::map (List.cons (head s)) (inits (tail s)) := by
apply Stream'.ext; intro n
cases n
· rfl
· rw [get_inits, get_succ, tail_cons, get_map, get_inits]
rfl
| Mathlib/Data/Stream/Init.lean | 692 | 695 | theorem zip_inits_tails (s : Stream' α) : zip appendStream' (inits s) (tails s) = const s := by | apply Stream'.ext; intro n
rw [get_zip, get_inits, get_tails, get_const, take_succ, cons_append_stream, append_take_drop,
Stream'.eta] |
/-
Copyright (c) 2019 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Bhavik Mehta
-/
import Mathlib.CategoryTheory.Comma.Over.Basic
import Mathlib.CategoryTheory.Discrete.Basic
import Mathlib.CategoryTheory.EpiMono
import Mathlib.CategoryTheory.Limits.Shapes.Terminal
/-!
# Binary (co)products
We define a category `WalkingPair`, which is the index category
for a binary (co)product diagram. A convenience method `pair X Y`
constructs the functor from the walking pair, hitting the given objects.
We define `prod X Y` and `coprod X Y` as limits and colimits of such functors.
Typeclasses `HasBinaryProducts` and `HasBinaryCoproducts` assert the existence
of (co)limits shaped as walking pairs.
We include lemmas for simplifying equations involving projections and coprojections, and define
braiding and associating isomorphisms, and the product comparison morphism.
## References
* [Stacks: Products of pairs](https://stacks.math.columbia.edu/tag/001R)
* [Stacks: coproducts of pairs](https://stacks.math.columbia.edu/tag/04AN)
-/
universe v v₁ u u₁ u₂
open CategoryTheory
namespace CategoryTheory.Limits
/-- The type of objects for the diagram indexing a binary (co)product. -/
inductive WalkingPair : Type
| left
| right
deriving DecidableEq, Inhabited
open WalkingPair
/-- The equivalence swapping left and right.
-/
def WalkingPair.swap : WalkingPair ≃ WalkingPair where
toFun
| left => right
| right => left
invFun
| left => right
| right => left
left_inv j := by cases j <;> rfl
right_inv j := by cases j <;> rfl
@[simp]
theorem WalkingPair.swap_apply_left : WalkingPair.swap left = right :=
rfl
@[simp]
theorem WalkingPair.swap_apply_right : WalkingPair.swap right = left :=
rfl
@[simp]
theorem WalkingPair.swap_symm_apply_tt : WalkingPair.swap.symm left = right :=
rfl
@[simp]
theorem WalkingPair.swap_symm_apply_ff : WalkingPair.swap.symm right = left :=
rfl
/-- An equivalence from `WalkingPair` to `Bool`, sometimes useful when reindexing limits.
-/
def WalkingPair.equivBool : WalkingPair ≃ Bool where
toFun
| left => true
| right => false
-- to match equiv.sum_equiv_sigma_bool
invFun b := Bool.recOn b right left
left_inv j := by cases j <;> rfl
right_inv b := by cases b <;> rfl
@[simp]
theorem WalkingPair.equivBool_apply_left : WalkingPair.equivBool left = true :=
rfl
@[simp]
theorem WalkingPair.equivBool_apply_right : WalkingPair.equivBool right = false :=
rfl
@[simp]
theorem WalkingPair.equivBool_symm_apply_true : WalkingPair.equivBool.symm true = left :=
rfl
@[simp]
theorem WalkingPair.equivBool_symm_apply_false : WalkingPair.equivBool.symm false = right :=
rfl
variable {C : Type u}
/-- The function on the walking pair, sending the two points to `X` and `Y`. -/
def pairFunction (X Y : C) : WalkingPair → C := fun j => WalkingPair.casesOn j X Y
@[simp]
theorem pairFunction_left (X Y : C) : pairFunction X Y left = X :=
rfl
@[simp]
theorem pairFunction_right (X Y : C) : pairFunction X Y right = Y :=
rfl
variable [Category.{v} C]
/-- The diagram on the walking pair, sending the two points to `X` and `Y`. -/
def pair (X Y : C) : Discrete WalkingPair ⥤ C :=
Discrete.functor fun j => WalkingPair.casesOn j X Y
@[simp]
theorem pair_obj_left (X Y : C) : (pair X Y).obj ⟨left⟩ = X :=
rfl
@[simp]
theorem pair_obj_right (X Y : C) : (pair X Y).obj ⟨right⟩ = Y :=
rfl
section
variable {F G : Discrete WalkingPair ⥤ C} (f : F.obj ⟨left⟩ ⟶ G.obj ⟨left⟩)
(g : F.obj ⟨right⟩ ⟶ G.obj ⟨right⟩)
attribute [local aesop safe tactic (rule_sets := [CategoryTheory])]
CategoryTheory.Discrete.discreteCases
/-- The natural transformation between two functors out of the
walking pair, specified by its components. -/
def mapPair : F ⟶ G where
app
| ⟨left⟩ => f
| ⟨right⟩ => g
naturality := fun ⟨X⟩ ⟨Y⟩ ⟨⟨u⟩⟩ => by aesop_cat
@[simp]
theorem mapPair_left : (mapPair f g).app ⟨left⟩ = f :=
rfl
@[simp]
theorem mapPair_right : (mapPair f g).app ⟨right⟩ = g :=
rfl
/-- The natural isomorphism between two functors out of the walking pair, specified by its
components. -/
@[simps!]
def mapPairIso (f : F.obj ⟨left⟩ ≅ G.obj ⟨left⟩) (g : F.obj ⟨right⟩ ≅ G.obj ⟨right⟩) : F ≅ G :=
NatIso.ofComponents (fun j ↦ match j with
| ⟨left⟩ => f
| ⟨right⟩ => g)
(fun ⟨⟨u⟩⟩ => by aesop_cat)
end
/-- Every functor out of the walking pair is naturally isomorphic (actually, equal) to a `pair` -/
@[simps!]
def diagramIsoPair (F : Discrete WalkingPair ⥤ C) :
F ≅ pair (F.obj ⟨WalkingPair.left⟩) (F.obj ⟨WalkingPair.right⟩) :=
mapPairIso (Iso.refl _) (Iso.refl _)
section
variable {D : Type u₁} [Category.{v₁} D]
/-- The natural isomorphism between `pair X Y ⋙ F` and `pair (F.obj X) (F.obj Y)`. -/
def pairComp (X Y : C) (F : C ⥤ D) : pair X Y ⋙ F ≅ pair (F.obj X) (F.obj Y) :=
diagramIsoPair _
end
/-- A binary fan is just a cone on a diagram indexing a product. -/
abbrev BinaryFan (X Y : C) :=
Cone (pair X Y)
/-- The first projection of a binary fan. -/
abbrev BinaryFan.fst {X Y : C} (s : BinaryFan X Y) :=
s.π.app ⟨WalkingPair.left⟩
/-- The second projection of a binary fan. -/
abbrev BinaryFan.snd {X Y : C} (s : BinaryFan X Y) :=
s.π.app ⟨WalkingPair.right⟩
@[simp]
theorem BinaryFan.π_app_left {X Y : C} (s : BinaryFan X Y) : s.π.app ⟨WalkingPair.left⟩ = s.fst :=
rfl
@[simp]
theorem BinaryFan.π_app_right {X Y : C} (s : BinaryFan X Y) : s.π.app ⟨WalkingPair.right⟩ = s.snd :=
rfl
/-- Constructs an isomorphism of `BinaryFan`s out of an isomorphism of the tips that commutes with
the projections. -/
def BinaryFan.ext {A B : C} {c c' : BinaryFan A B} (e : c.pt ≅ c'.pt)
(h₁ : c.fst = e.hom ≫ c'.fst) (h₂ : c.snd = e.hom ≫ c'.snd) : c ≅ c' :=
Cones.ext e (fun j => by rcases j with ⟨⟨⟩⟩ <;> assumption)
@[simp]
lemma BinaryFan.ext_hom_hom {A B : C} {c c' : BinaryFan A B} (e : c.pt ≅ c'.pt)
(h₁ : c.fst = e.hom ≫ c'.fst) (h₂ : c.snd = e.hom ≫ c'.snd) :
(ext e h₁ h₂).hom.hom = e.hom := rfl
/-- A convenient way to show that a binary fan is a limit. -/
def BinaryFan.IsLimit.mk {X Y : C} (s : BinaryFan X Y)
(lift : ∀ {T : C} (_ : T ⟶ X) (_ : T ⟶ Y), T ⟶ s.pt)
(hl₁ : ∀ {T : C} (f : T ⟶ X) (g : T ⟶ Y), lift f g ≫ s.fst = f)
(hl₂ : ∀ {T : C} (f : T ⟶ X) (g : T ⟶ Y), lift f g ≫ s.snd = g)
(uniq :
∀ {T : C} (f : T ⟶ X) (g : T ⟶ Y) (m : T ⟶ s.pt) (_ : m ≫ s.fst = f) (_ : m ≫ s.snd = g),
m = lift f g) :
IsLimit s :=
Limits.IsLimit.mk (fun t => lift (BinaryFan.fst t) (BinaryFan.snd t))
(by
rintro t (rfl | rfl)
· exact hl₁ _ _
· exact hl₂ _ _)
fun _ _ h => uniq _ _ _ (h ⟨WalkingPair.left⟩) (h ⟨WalkingPair.right⟩)
theorem BinaryFan.IsLimit.hom_ext {W X Y : C} {s : BinaryFan X Y} (h : IsLimit s) {f g : W ⟶ s.pt}
(h₁ : f ≫ s.fst = g ≫ s.fst) (h₂ : f ≫ s.snd = g ≫ s.snd) : f = g :=
h.hom_ext fun j => Discrete.recOn j fun j => WalkingPair.casesOn j h₁ h₂
/-- A binary cofan is just a cocone on a diagram indexing a coproduct. -/
abbrev BinaryCofan (X Y : C) := Cocone (pair X Y)
/-- The first inclusion of a binary cofan. -/
abbrev BinaryCofan.inl {X Y : C} (s : BinaryCofan X Y) := s.ι.app ⟨WalkingPair.left⟩
/-- The second inclusion of a binary cofan. -/
abbrev BinaryCofan.inr {X Y : C} (s : BinaryCofan X Y) := s.ι.app ⟨WalkingPair.right⟩
/-- Constructs an isomorphism of `BinaryCofan`s out of an isomorphism of the tips that commutes with
the injections. -/
def BinaryCofan.ext {A B : C} {c c' : BinaryCofan A B} (e : c.pt ≅ c'.pt)
(h₁ : c.inl ≫ e.hom = c'.inl) (h₂ : c.inr ≫ e.hom = c'.inr) : c ≅ c' :=
Cocones.ext e (fun j => by rcases j with ⟨⟨⟩⟩ <;> assumption)
@[simp]
lemma BinaryCofan.ext_hom_hom {A B : C} {c c' : BinaryCofan A B} (e : c.pt ≅ c'.pt)
(h₁ : c.inl ≫ e.hom = c'.inl) (h₂ : c.inr ≫ e.hom = c'.inr) :
(ext e h₁ h₂).hom.hom = e.hom := rfl
@[simp]
theorem BinaryCofan.ι_app_left {X Y : C} (s : BinaryCofan X Y) :
s.ι.app ⟨WalkingPair.left⟩ = s.inl := rfl
@[simp]
theorem BinaryCofan.ι_app_right {X Y : C} (s : BinaryCofan X Y) :
s.ι.app ⟨WalkingPair.right⟩ = s.inr := rfl
/-- A convenient way to show that a binary cofan is a colimit. -/
def BinaryCofan.IsColimit.mk {X Y : C} (s : BinaryCofan X Y)
(desc : ∀ {T : C} (_ : X ⟶ T) (_ : Y ⟶ T), s.pt ⟶ T)
(hd₁ : ∀ {T : C} (f : X ⟶ T) (g : Y ⟶ T), s.inl ≫ desc f g = f)
(hd₂ : ∀ {T : C} (f : X ⟶ T) (g : Y ⟶ T), s.inr ≫ desc f g = g)
(uniq :
∀ {T : C} (f : X ⟶ T) (g : Y ⟶ T) (m : s.pt ⟶ T) (_ : s.inl ≫ m = f) (_ : s.inr ≫ m = g),
m = desc f g) :
IsColimit s :=
Limits.IsColimit.mk (fun t => desc (BinaryCofan.inl t) (BinaryCofan.inr t))
(by
rintro t (rfl | rfl)
· exact hd₁ _ _
· exact hd₂ _ _)
fun _ _ h => uniq _ _ _ (h ⟨WalkingPair.left⟩) (h ⟨WalkingPair.right⟩)
theorem BinaryCofan.IsColimit.hom_ext {W X Y : C} {s : BinaryCofan X Y} (h : IsColimit s)
{f g : s.pt ⟶ W} (h₁ : s.inl ≫ f = s.inl ≫ g) (h₂ : s.inr ≫ f = s.inr ≫ g) : f = g :=
h.hom_ext fun j => Discrete.recOn j fun j => WalkingPair.casesOn j h₁ h₂
variable {X Y : C}
section
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
/-- A binary fan with vertex `P` consists of the two projections `π₁ : P ⟶ X` and `π₂ : P ⟶ Y`. -/
@[simps pt]
def BinaryFan.mk {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : BinaryFan X Y where
pt := P
π := { app := fun | { as := j } => match j with | left => π₁ | right => π₂ }
/-- A binary cofan with vertex `P` consists of the two inclusions `ι₁ : X ⟶ P` and `ι₂ : Y ⟶ P`. -/
@[simps pt]
def BinaryCofan.mk {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : BinaryCofan X Y where
pt := P
ι := { app := fun | { as := j } => match j with | left => ι₁ | right => ι₂ }
end
@[simp]
theorem BinaryFan.mk_fst {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : (BinaryFan.mk π₁ π₂).fst = π₁ :=
rfl
@[simp]
theorem BinaryFan.mk_snd {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : (BinaryFan.mk π₁ π₂).snd = π₂ :=
rfl
@[simp]
theorem BinaryCofan.mk_inl {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : (BinaryCofan.mk ι₁ ι₂).inl = ι₁ :=
rfl
@[simp]
theorem BinaryCofan.mk_inr {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : (BinaryCofan.mk ι₁ ι₂).inr = ι₂ :=
rfl
/-- Every `BinaryFan` is isomorphic to an application of `BinaryFan.mk`. -/
def isoBinaryFanMk {X Y : C} (c : BinaryFan X Y) : c ≅ BinaryFan.mk c.fst c.snd :=
Cones.ext (Iso.refl _) fun ⟨l⟩ => by cases l; repeat simp
/-- Every `BinaryFan` is isomorphic to an application of `BinaryFan.mk`. -/
def isoBinaryCofanMk {X Y : C} (c : BinaryCofan X Y) : c ≅ BinaryCofan.mk c.inl c.inr :=
Cocones.ext (Iso.refl _) fun ⟨l⟩ => by cases l; repeat simp
/-- This is a more convenient formulation to show that a `BinaryFan` constructed using
`BinaryFan.mk` is a limit cone.
-/
def BinaryFan.isLimitMk {W : C} {fst : W ⟶ X} {snd : W ⟶ Y} (lift : ∀ s : BinaryFan X Y, s.pt ⟶ W)
(fac_left : ∀ s : BinaryFan X Y, lift s ≫ fst = s.fst)
(fac_right : ∀ s : BinaryFan X Y, lift s ≫ snd = s.snd)
(uniq :
∀ (s : BinaryFan X Y) (m : s.pt ⟶ W) (_ : m ≫ fst = s.fst) (_ : m ≫ snd = s.snd),
m = lift s) :
IsLimit (BinaryFan.mk fst snd) :=
{ lift := lift
fac := fun s j => by
rcases j with ⟨⟨⟩⟩
exacts [fac_left s, fac_right s]
uniq := fun s m w => uniq s m (w ⟨WalkingPair.left⟩) (w ⟨WalkingPair.right⟩) }
/-- This is a more convenient formulation to show that a `BinaryCofan` constructed using
`BinaryCofan.mk` is a colimit cocone.
-/
def BinaryCofan.isColimitMk {W : C} {inl : X ⟶ W} {inr : Y ⟶ W}
(desc : ∀ s : BinaryCofan X Y, W ⟶ s.pt)
(fac_left : ∀ s : BinaryCofan X Y, inl ≫ desc s = s.inl)
(fac_right : ∀ s : BinaryCofan X Y, inr ≫ desc s = s.inr)
(uniq :
∀ (s : BinaryCofan X Y) (m : W ⟶ s.pt) (_ : inl ≫ m = s.inl) (_ : inr ≫ m = s.inr),
m = desc s) :
IsColimit (BinaryCofan.mk inl inr) :=
{ desc := desc
fac := fun s j => by
rcases j with ⟨⟨⟩⟩
exacts [fac_left s, fac_right s]
uniq := fun s m w => uniq s m (w ⟨WalkingPair.left⟩) (w ⟨WalkingPair.right⟩) }
/-- If `s` is a limit binary fan over `X` and `Y`, then every pair of morphisms `f : W ⟶ X` and
`g : W ⟶ Y` induces a morphism `l : W ⟶ s.pt` satisfying `l ≫ s.fst = f` and `l ≫ s.snd = g`.
-/
@[simps]
def BinaryFan.IsLimit.lift' {W X Y : C} {s : BinaryFan X Y} (h : IsLimit s) (f : W ⟶ X)
(g : W ⟶ Y) : { l : W ⟶ s.pt // l ≫ s.fst = f ∧ l ≫ s.snd = g } :=
⟨h.lift <| BinaryFan.mk f g, h.fac _ _, h.fac _ _⟩
/-- If `s` is a colimit binary cofan over `X` and `Y`,, then every pair of morphisms `f : X ⟶ W` and
`g : Y ⟶ W` induces a morphism `l : s.pt ⟶ W` satisfying `s.inl ≫ l = f` and `s.inr ≫ l = g`.
-/
@[simps]
def BinaryCofan.IsColimit.desc' {W X Y : C} {s : BinaryCofan X Y} (h : IsColimit s) (f : X ⟶ W)
(g : Y ⟶ W) : { l : s.pt ⟶ W // s.inl ≫ l = f ∧ s.inr ≫ l = g } :=
⟨h.desc <| BinaryCofan.mk f g, h.fac _ _, h.fac _ _⟩
/-- Binary products are symmetric. -/
def BinaryFan.isLimitFlip {X Y : C} {c : BinaryFan X Y} (hc : IsLimit c) :
IsLimit (BinaryFan.mk c.snd c.fst) :=
BinaryFan.isLimitMk (fun s => hc.lift (BinaryFan.mk s.snd s.fst)) (fun _ => hc.fac _ _)
(fun _ => hc.fac _ _) fun s _ e₁ e₂ =>
BinaryFan.IsLimit.hom_ext hc
(e₂.trans (hc.fac (BinaryFan.mk s.snd s.fst) ⟨WalkingPair.left⟩).symm)
(e₁.trans (hc.fac (BinaryFan.mk s.snd s.fst) ⟨WalkingPair.right⟩).symm)
theorem BinaryFan.isLimit_iff_isIso_fst {X Y : C} (h : IsTerminal Y) (c : BinaryFan X Y) :
Nonempty (IsLimit c) ↔ IsIso c.fst := by
constructor
· rintro ⟨H⟩
obtain ⟨l, hl, -⟩ := BinaryFan.IsLimit.lift' H (𝟙 X) (h.from X)
exact
⟨⟨l,
BinaryFan.IsLimit.hom_ext H (by simpa [hl, -Category.comp_id] using Category.comp_id _)
(h.hom_ext _ _),
hl⟩⟩
· intro
exact
⟨BinaryFan.IsLimit.mk _ (fun f _ => f ≫ inv c.fst) (fun _ _ => by simp)
(fun _ _ => h.hom_ext _ _) fun _ _ _ e _ => by simp [← e]⟩
theorem BinaryFan.isLimit_iff_isIso_snd {X Y : C} (h : IsTerminal X) (c : BinaryFan X Y) :
Nonempty (IsLimit c) ↔ IsIso c.snd := by
refine Iff.trans ?_ (BinaryFan.isLimit_iff_isIso_fst h (BinaryFan.mk c.snd c.fst))
exact
⟨fun h => ⟨BinaryFan.isLimitFlip h.some⟩, fun h =>
⟨(BinaryFan.isLimitFlip h.some).ofIsoLimit (isoBinaryFanMk c).symm⟩⟩
/-- If `X' ≅ X`, then `X × Y` also is the product of `X'` and `Y`. -/
noncomputable def BinaryFan.isLimitCompLeftIso {X Y X' : C} (c : BinaryFan X Y) (f : X ⟶ X')
[IsIso f] (h : IsLimit c) : IsLimit (BinaryFan.mk (c.fst ≫ f) c.snd) := by
fapply BinaryFan.isLimitMk
· exact fun s => h.lift (BinaryFan.mk (s.fst ≫ inv f) s.snd)
· intro s -- Porting note: simp timed out here
simp only [Category.comp_id,BinaryFan.π_app_left,IsIso.inv_hom_id,
BinaryFan.mk_fst,IsLimit.fac_assoc,eq_self_iff_true,Category.assoc]
· intro s -- Porting note: simp timed out here
simp only [BinaryFan.π_app_right,BinaryFan.mk_snd,eq_self_iff_true,IsLimit.fac]
· intro s m e₁ e₂
-- Porting note: simpa timed out here also
apply BinaryFan.IsLimit.hom_ext h
· simpa only
[BinaryFan.π_app_left,BinaryFan.mk_fst,Category.assoc,IsLimit.fac,IsIso.eq_comp_inv]
· simpa only [BinaryFan.π_app_right,BinaryFan.mk_snd,IsLimit.fac]
/-- If `Y' ≅ Y`, then `X x Y` also is the product of `X` and `Y'`. -/
noncomputable def BinaryFan.isLimitCompRightIso {X Y Y' : C} (c : BinaryFan X Y) (f : Y ⟶ Y')
[IsIso f] (h : IsLimit c) : IsLimit (BinaryFan.mk c.fst (c.snd ≫ f)) :=
BinaryFan.isLimitFlip <| BinaryFan.isLimitCompLeftIso _ f (BinaryFan.isLimitFlip h)
/-- Binary coproducts are symmetric. -/
def BinaryCofan.isColimitFlip {X Y : C} {c : BinaryCofan X Y} (hc : IsColimit c) :
IsColimit (BinaryCofan.mk c.inr c.inl) :=
BinaryCofan.isColimitMk (fun s => hc.desc (BinaryCofan.mk s.inr s.inl)) (fun _ => hc.fac _ _)
(fun _ => hc.fac _ _) fun s _ e₁ e₂ =>
BinaryCofan.IsColimit.hom_ext hc
(e₂.trans (hc.fac (BinaryCofan.mk s.inr s.inl) ⟨WalkingPair.left⟩).symm)
(e₁.trans (hc.fac (BinaryCofan.mk s.inr s.inl) ⟨WalkingPair.right⟩).symm)
theorem BinaryCofan.isColimit_iff_isIso_inl {X Y : C} (h : IsInitial Y) (c : BinaryCofan X Y) :
Nonempty (IsColimit c) ↔ IsIso c.inl := by
constructor
· rintro ⟨H⟩
obtain ⟨l, hl, -⟩ := BinaryCofan.IsColimit.desc' H (𝟙 X) (h.to X)
refine ⟨⟨l, hl, BinaryCofan.IsColimit.hom_ext H (?_) (h.hom_ext _ _)⟩⟩
rw [Category.comp_id]
have e : (inl c ≫ l) ≫ inl c = 𝟙 X ≫ inl c := congrArg (·≫inl c) hl
rwa [Category.assoc,Category.id_comp] at e
· intro
exact
⟨BinaryCofan.IsColimit.mk _ (fun f _ => inv c.inl ≫ f)
(fun _ _ => IsIso.hom_inv_id_assoc _ _) (fun _ _ => h.hom_ext _ _) fun _ _ _ e _ =>
(IsIso.eq_inv_comp _).mpr e⟩
theorem BinaryCofan.isColimit_iff_isIso_inr {X Y : C} (h : IsInitial X) (c : BinaryCofan X Y) :
Nonempty (IsColimit c) ↔ IsIso c.inr := by
refine Iff.trans ?_ (BinaryCofan.isColimit_iff_isIso_inl h (BinaryCofan.mk c.inr c.inl))
exact
⟨fun h => ⟨BinaryCofan.isColimitFlip h.some⟩, fun h =>
⟨(BinaryCofan.isColimitFlip h.some).ofIsoColimit (isoBinaryCofanMk c).symm⟩⟩
/-- If `X' ≅ X`, then `X ⨿ Y` also is the coproduct of `X'` and `Y`. -/
noncomputable def BinaryCofan.isColimitCompLeftIso {X Y X' : C} (c : BinaryCofan X Y) (f : X' ⟶ X)
[IsIso f] (h : IsColimit c) : IsColimit (BinaryCofan.mk (f ≫ c.inl) c.inr) := by
fapply BinaryCofan.isColimitMk
· exact fun s => h.desc (BinaryCofan.mk (inv f ≫ s.inl) s.inr)
· intro s
-- Porting note: simp timed out here too
simp only [IsColimit.fac,BinaryCofan.ι_app_left,eq_self_iff_true,
Category.assoc,BinaryCofan.mk_inl,IsIso.hom_inv_id_assoc]
· intro s
-- Porting note: simp timed out here too
simp only [IsColimit.fac,BinaryCofan.ι_app_right,eq_self_iff_true,BinaryCofan.mk_inr]
· intro s m e₁ e₂
apply BinaryCofan.IsColimit.hom_ext h
· rw [← cancel_epi f]
-- Porting note: simp timed out here too
simpa only [IsColimit.fac,BinaryCofan.ι_app_left,eq_self_iff_true,
Category.assoc,BinaryCofan.mk_inl,IsIso.hom_inv_id_assoc] using e₁
-- Porting note: simp timed out here too
· simpa only [IsColimit.fac,BinaryCofan.ι_app_right,eq_self_iff_true,BinaryCofan.mk_inr]
/-- If `Y' ≅ Y`, then `X ⨿ Y` also is the coproduct of `X` and `Y'`. -/
noncomputable def BinaryCofan.isColimitCompRightIso {X Y Y' : C} (c : BinaryCofan X Y) (f : Y' ⟶ Y)
[IsIso f] (h : IsColimit c) : IsColimit (BinaryCofan.mk c.inl (f ≫ c.inr)) :=
BinaryCofan.isColimitFlip <| BinaryCofan.isColimitCompLeftIso _ f (BinaryCofan.isColimitFlip h)
/-- An abbreviation for `HasLimit (pair X Y)`. -/
abbrev HasBinaryProduct (X Y : C) :=
HasLimit (pair X Y)
/-- An abbreviation for `HasColimit (pair X Y)`. -/
abbrev HasBinaryCoproduct (X Y : C) :=
HasColimit (pair X Y)
/-- If we have a product of `X` and `Y`, we can access it using `prod X Y` or
`X ⨯ Y`. -/
noncomputable abbrev prod (X Y : C) [HasBinaryProduct X Y] :=
limit (pair X Y)
/-- If we have a coproduct of `X` and `Y`, we can access it using `coprod X Y` or
`X ⨿ Y`. -/
noncomputable abbrev coprod (X Y : C) [HasBinaryCoproduct X Y] :=
colimit (pair X Y)
/-- Notation for the product -/
notation:20 X " ⨯ " Y:20 => prod X Y
/-- Notation for the coproduct -/
notation:20 X " ⨿ " Y:20 => coprod X Y
/-- The projection map to the first component of the product. -/
noncomputable abbrev prod.fst {X Y : C} [HasBinaryProduct X Y] : X ⨯ Y ⟶ X :=
limit.π (pair X Y) ⟨WalkingPair.left⟩
/-- The projection map to the second component of the product. -/
noncomputable abbrev prod.snd {X Y : C} [HasBinaryProduct X Y] : X ⨯ Y ⟶ Y :=
limit.π (pair X Y) ⟨WalkingPair.right⟩
/-- The inclusion map from the first component of the coproduct. -/
noncomputable abbrev coprod.inl {X Y : C} [HasBinaryCoproduct X Y] : X ⟶ X ⨿ Y :=
colimit.ι (pair X Y) ⟨WalkingPair.left⟩
/-- The inclusion map from the second component of the coproduct. -/
noncomputable abbrev coprod.inr {X Y : C} [HasBinaryCoproduct X Y] : Y ⟶ X ⨿ Y :=
colimit.ι (pair X Y) ⟨WalkingPair.right⟩
/-- The binary fan constructed from the projection maps is a limit. -/
noncomputable def prodIsProd (X Y : C) [HasBinaryProduct X Y] :
IsLimit (BinaryFan.mk (prod.fst : X ⨯ Y ⟶ X) prod.snd) :=
(limit.isLimit _).ofIsoLimit (Cones.ext (Iso.refl _) (fun ⟨u⟩ => by
cases u
· dsimp; simp only [Category.id_comp]; rfl
· dsimp; simp only [Category.id_comp]; rfl
))
/-- The binary cofan constructed from the coprojection maps is a colimit. -/
noncomputable def coprodIsCoprod (X Y : C) [HasBinaryCoproduct X Y] :
IsColimit (BinaryCofan.mk (coprod.inl : X ⟶ X ⨿ Y) coprod.inr) :=
(colimit.isColimit _).ofIsoColimit (Cocones.ext (Iso.refl _) (fun ⟨u⟩ => by
cases u
· dsimp; simp only [Category.comp_id]
· dsimp; simp only [Category.comp_id]
))
@[ext 1100]
theorem prod.hom_ext {W X Y : C} [HasBinaryProduct X Y] {f g : W ⟶ X ⨯ Y}
(h₁ : f ≫ prod.fst = g ≫ prod.fst) (h₂ : f ≫ prod.snd = g ≫ prod.snd) : f = g :=
BinaryFan.IsLimit.hom_ext (limit.isLimit _) h₁ h₂
@[ext 1100]
theorem coprod.hom_ext {W X Y : C} [HasBinaryCoproduct X Y] {f g : X ⨿ Y ⟶ W}
(h₁ : coprod.inl ≫ f = coprod.inl ≫ g) (h₂ : coprod.inr ≫ f = coprod.inr ≫ g) : f = g :=
BinaryCofan.IsColimit.hom_ext (colimit.isColimit _) h₁ h₂
/-- If the product of `X` and `Y` exists, then every pair of morphisms `f : W ⟶ X` and `g : W ⟶ Y`
induces a morphism `prod.lift f g : W ⟶ X ⨯ Y`. -/
noncomputable abbrev prod.lift {W X Y : C} [HasBinaryProduct X Y]
(f : W ⟶ X) (g : W ⟶ Y) : W ⟶ X ⨯ Y :=
limit.lift _ (BinaryFan.mk f g)
/-- diagonal arrow of the binary product in the category `fam I` -/
noncomputable abbrev diag (X : C) [HasBinaryProduct X X] : X ⟶ X ⨯ X :=
prod.lift (𝟙 _) (𝟙 _)
/-- If the coproduct of `X` and `Y` exists, then every pair of morphisms `f : X ⟶ W` and
`g : Y ⟶ W` induces a morphism `coprod.desc f g : X ⨿ Y ⟶ W`. -/
noncomputable abbrev coprod.desc {W X Y : C} [HasBinaryCoproduct X Y]
(f : X ⟶ W) (g : Y ⟶ W) : X ⨿ Y ⟶ W :=
colimit.desc _ (BinaryCofan.mk f g)
/-- codiagonal arrow of the binary coproduct -/
noncomputable abbrev codiag (X : C) [HasBinaryCoproduct X X] : X ⨿ X ⟶ X :=
coprod.desc (𝟙 _) (𝟙 _)
@[reassoc]
theorem prod.lift_fst {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) :
prod.lift f g ≫ prod.fst = f :=
limit.lift_π _ _
@[reassoc]
theorem prod.lift_snd {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) :
prod.lift f g ≫ prod.snd = g :=
limit.lift_π _ _
@[reassoc]
theorem coprod.inl_desc {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) :
coprod.inl ≫ coprod.desc f g = f :=
colimit.ι_desc _ _
@[reassoc]
theorem coprod.inr_desc {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) :
coprod.inr ≫ coprod.desc f g = g :=
colimit.ι_desc _ _
instance prod.mono_lift_of_mono_left {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y)
[Mono f] : Mono (prod.lift f g) :=
mono_of_mono_fac <| prod.lift_fst _ _
instance prod.mono_lift_of_mono_right {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y)
[Mono g] : Mono (prod.lift f g) :=
mono_of_mono_fac <| prod.lift_snd _ _
instance coprod.epi_desc_of_epi_left {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W)
[Epi f] : Epi (coprod.desc f g) :=
epi_of_epi_fac <| coprod.inl_desc _ _
instance coprod.epi_desc_of_epi_right {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W)
[Epi g] : Epi (coprod.desc f g) :=
epi_of_epi_fac <| coprod.inr_desc _ _
/-- If the product of `X` and `Y` exists, then every pair of morphisms `f : W ⟶ X` and `g : W ⟶ Y`
induces a morphism `l : W ⟶ X ⨯ Y` satisfying `l ≫ Prod.fst = f` and `l ≫ Prod.snd = g`. -/
noncomputable def prod.lift' {W X Y : C} [HasBinaryProduct X Y] (f : W ⟶ X) (g : W ⟶ Y) :
{ l : W ⟶ X ⨯ Y // l ≫ prod.fst = f ∧ l ≫ prod.snd = g } :=
⟨prod.lift f g, prod.lift_fst _ _, prod.lift_snd _ _⟩
/-- If the coproduct of `X` and `Y` exists, then every pair of morphisms `f : X ⟶ W` and
`g : Y ⟶ W` induces a morphism `l : X ⨿ Y ⟶ W` satisfying `coprod.inl ≫ l = f` and
`coprod.inr ≫ l = g`. -/
noncomputable def coprod.desc' {W X Y : C} [HasBinaryCoproduct X Y] (f : X ⟶ W) (g : Y ⟶ W) :
{ l : X ⨿ Y ⟶ W // coprod.inl ≫ l = f ∧ coprod.inr ≫ l = g } :=
⟨coprod.desc f g, coprod.inl_desc _ _, coprod.inr_desc _ _⟩
/-- If the products `W ⨯ X` and `Y ⨯ Z` exist, then every pair of morphisms `f : W ⟶ Y` and
`g : X ⟶ Z` induces a morphism `prod.map f g : W ⨯ X ⟶ Y ⨯ Z`. -/
noncomputable def prod.map {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z]
(f : W ⟶ Y) (g : X ⟶ Z) : W ⨯ X ⟶ Y ⨯ Z :=
limMap (mapPair f g)
/-- If the coproducts `W ⨿ X` and `Y ⨿ Z` exist, then every pair of morphisms `f : W ⟶ Y` and
`g : W ⟶ Z` induces a morphism `coprod.map f g : W ⨿ X ⟶ Y ⨿ Z`. -/
noncomputable def coprod.map {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z]
(f : W ⟶ Y) (g : X ⟶ Z) : W ⨿ X ⟶ Y ⨿ Z :=
colimMap (mapPair f g)
noncomputable section ProdLemmas
-- Making the reassoc version of this a simp lemma seems to be more harmful than helpful.
@[reassoc, simp]
theorem prod.comp_lift {V W X Y : C} [HasBinaryProduct X Y] (f : V ⟶ W) (g : W ⟶ X) (h : W ⟶ Y) :
f ≫ prod.lift g h = prod.lift (f ≫ g) (f ≫ h) := by ext <;> simp
theorem prod.comp_diag {X Y : C} [HasBinaryProduct Y Y] (f : X ⟶ Y) :
f ≫ diag Y = prod.lift f f := by simp
@[reassoc (attr := simp)]
theorem prod.map_fst {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y)
(g : X ⟶ Z) : prod.map f g ≫ prod.fst = prod.fst ≫ f :=
limMap_π _ _
@[reassoc (attr := simp)]
theorem prod.map_snd {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y)
(g : X ⟶ Z) : prod.map f g ≫ prod.snd = prod.snd ≫ g :=
limMap_π _ _
@[simp]
theorem prod.map_id_id {X Y : C} [HasBinaryProduct X Y] : prod.map (𝟙 X) (𝟙 Y) = 𝟙 _ := by
ext <;> simp
@[simp]
theorem prod.lift_fst_snd {X Y : C} [HasBinaryProduct X Y] :
prod.lift prod.fst prod.snd = 𝟙 (X ⨯ Y) := by ext <;> simp
@[reassoc (attr := simp)]
theorem prod.lift_map {V W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : V ⟶ W)
(g : V ⟶ X) (h : W ⟶ Y) (k : X ⟶ Z) :
prod.lift f g ≫ prod.map h k = prod.lift (f ≫ h) (g ≫ k) := by ext <;> simp
@[simp]
theorem prod.lift_fst_comp_snd_comp {W X Y Z : C} [HasBinaryProduct W Y] [HasBinaryProduct X Z]
(g : W ⟶ X) (g' : Y ⟶ Z) : prod.lift (prod.fst ≫ g) (prod.snd ≫ g') = prod.map g g' := by
rw [← prod.lift_map]
simp
-- We take the right hand side here to be simp normal form, as this way composition lemmas for
-- `f ≫ h` and `g ≫ k` can fire (eg `id_comp`) , while `map_fst` and `map_snd` can still work just
-- as well.
@[reassoc (attr := simp)]
theorem prod.map_map {A₁ A₂ A₃ B₁ B₂ B₃ : C} [HasBinaryProduct A₁ B₁] [HasBinaryProduct A₂ B₂]
[HasBinaryProduct A₃ B₃] (f : A₁ ⟶ A₂) (g : B₁ ⟶ B₂) (h : A₂ ⟶ A₃) (k : B₂ ⟶ B₃) :
prod.map f g ≫ prod.map h k = prod.map (f ≫ h) (g ≫ k) := by ext <;> simp
-- TODO: is it necessary to weaken the assumption here?
@[reassoc]
theorem prod.map_swap {A B X Y : C} (f : A ⟶ B) (g : X ⟶ Y)
[HasLimitsOfShape (Discrete WalkingPair) C] :
prod.map (𝟙 X) f ≫ prod.map g (𝟙 B) = prod.map g (𝟙 A) ≫ prod.map (𝟙 Y) f := by simp
@[reassoc]
theorem prod.map_comp_id {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasBinaryProduct X W]
[HasBinaryProduct Z W] [HasBinaryProduct Y W] :
prod.map (f ≫ g) (𝟙 W) = prod.map f (𝟙 W) ≫ prod.map g (𝟙 W) := by simp
@[reassoc]
theorem prod.map_id_comp {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasBinaryProduct W X]
[HasBinaryProduct W Y] [HasBinaryProduct W Z] :
prod.map (𝟙 W) (f ≫ g) = prod.map (𝟙 W) f ≫ prod.map (𝟙 W) g := by simp
/-- If the products `W ⨯ X` and `Y ⨯ Z` exist, then every pair of isomorphisms `f : W ≅ Y` and
`g : X ≅ Z` induces an isomorphism `prod.mapIso f g : W ⨯ X ≅ Y ⨯ Z`. -/
@[simps]
def prod.mapIso {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ≅ Y)
(g : X ≅ Z) : W ⨯ X ≅ Y ⨯ Z where
hom := prod.map f.hom g.hom
inv := prod.map f.inv g.inv
instance isIso_prod {W X Y Z : C} [HasBinaryProduct W X] [HasBinaryProduct Y Z] (f : W ⟶ Y)
(g : X ⟶ Z) [IsIso f] [IsIso g] : IsIso (prod.map f g) :=
(prod.mapIso (asIso f) (asIso g)).isIso_hom
instance prod.map_mono {C : Type*} [Category C] {W X Y Z : C} (f : W ⟶ Y) (g : X ⟶ Z) [Mono f]
[Mono g] [HasBinaryProduct W X] [HasBinaryProduct Y Z] : Mono (prod.map f g) :=
⟨fun i₁ i₂ h => by
ext
· rw [← cancel_mono f]
simpa using congr_arg (fun f => f ≫ prod.fst) h
· rw [← cancel_mono g]
simpa using congr_arg (fun f => f ≫ prod.snd) h⟩
@[reassoc]
theorem prod.diag_map {X Y : C} (f : X ⟶ Y) [HasBinaryProduct X X] [HasBinaryProduct Y Y] :
diag X ≫ prod.map f f = f ≫ diag Y := by simp
@[reassoc]
theorem prod.diag_map_fst_snd {X Y : C} [HasBinaryProduct X Y] [HasBinaryProduct (X ⨯ Y) (X ⨯ Y)] :
diag (X ⨯ Y) ≫ prod.map prod.fst prod.snd = 𝟙 (X ⨯ Y) := by simp
@[reassoc]
theorem prod.diag_map_fst_snd_comp [HasLimitsOfShape (Discrete WalkingPair) C] {X X' Y Y' : C}
(g : X ⟶ Y) (g' : X' ⟶ Y') :
diag (X ⨯ X') ≫ prod.map (prod.fst ≫ g) (prod.snd ≫ g') = prod.map g g' := by simp
instance {X : C} [HasBinaryProduct X X] : IsSplitMono (diag X) :=
IsSplitMono.mk' { retraction := prod.fst }
end ProdLemmas
noncomputable section CoprodLemmas
@[reassoc, simp]
theorem coprod.desc_comp {V W X Y : C} [HasBinaryCoproduct X Y] (f : V ⟶ W) (g : X ⟶ V)
(h : Y ⟶ V) : coprod.desc g h ≫ f = coprod.desc (g ≫ f) (h ≫ f) := by
ext <;> simp
theorem coprod.diag_comp {X Y : C} [HasBinaryCoproduct X X] (f : X ⟶ Y) :
codiag X ≫ f = coprod.desc f f := by simp
@[reassoc (attr := simp)]
theorem coprod.inl_map {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ⟶ Y)
(g : X ⟶ Z) : coprod.inl ≫ coprod.map f g = f ≫ coprod.inl :=
ι_colimMap _ _
@[reassoc (attr := simp)]
theorem coprod.inr_map {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ⟶ Y)
(g : X ⟶ Z) : coprod.inr ≫ coprod.map f g = g ≫ coprod.inr :=
ι_colimMap _ _
@[simp]
theorem coprod.map_id_id {X Y : C} [HasBinaryCoproduct X Y] : coprod.map (𝟙 X) (𝟙 Y) = 𝟙 _ := by
ext <;> simp
@[simp]
theorem coprod.desc_inl_inr {X Y : C} [HasBinaryCoproduct X Y] :
coprod.desc coprod.inl coprod.inr = 𝟙 (X ⨿ Y) := by ext <;> simp
-- The simp linter says simp can prove the reassoc version of this lemma.
@[reassoc, simp]
theorem coprod.map_desc {S T U V W : C} [HasBinaryCoproduct U W] [HasBinaryCoproduct T V]
(f : U ⟶ S) (g : W ⟶ S) (h : T ⟶ U) (k : V ⟶ W) :
coprod.map h k ≫ coprod.desc f g = coprod.desc (h ≫ f) (k ≫ g) := by
ext <;> simp
@[simp]
theorem coprod.desc_comp_inl_comp_inr {W X Y Z : C} [HasBinaryCoproduct W Y]
[HasBinaryCoproduct X Z] (g : W ⟶ X) (g' : Y ⟶ Z) :
coprod.desc (g ≫ coprod.inl) (g' ≫ coprod.inr) = coprod.map g g' := by
rw [← coprod.map_desc]; simp
-- We take the right hand side here to be simp normal form, as this way composition lemmas for
-- `f ≫ h` and `g ≫ k` can fire (eg `id_comp`) , while `inl_map` and `inr_map` can still work just
-- as well.
@[reassoc (attr := simp)]
theorem coprod.map_map {A₁ A₂ A₃ B₁ B₂ B₃ : C} [HasBinaryCoproduct A₁ B₁] [HasBinaryCoproduct A₂ B₂]
[HasBinaryCoproduct A₃ B₃] (f : A₁ ⟶ A₂) (g : B₁ ⟶ B₂) (h : A₂ ⟶ A₃) (k : B₂ ⟶ B₃) :
coprod.map f g ≫ coprod.map h k = coprod.map (f ≫ h) (g ≫ k) := by
ext <;> simp
-- I don't think it's a good idea to make any of the following three simp lemmas.
@[reassoc]
theorem coprod.map_swap {A B X Y : C} (f : A ⟶ B) (g : X ⟶ Y)
[HasColimitsOfShape (Discrete WalkingPair) C] :
coprod.map (𝟙 X) f ≫ coprod.map g (𝟙 B) = coprod.map g (𝟙 A) ≫ coprod.map (𝟙 Y) f := by simp
@[reassoc]
theorem coprod.map_comp_id {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasBinaryCoproduct Z W]
[HasBinaryCoproduct Y W] [HasBinaryCoproduct X W] :
coprod.map (f ≫ g) (𝟙 W) = coprod.map f (𝟙 W) ≫ coprod.map g (𝟙 W) := by simp
@[reassoc]
theorem coprod.map_id_comp {X Y Z W : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasBinaryCoproduct W X]
[HasBinaryCoproduct W Y] [HasBinaryCoproduct W Z] :
coprod.map (𝟙 W) (f ≫ g) = coprod.map (𝟙 W) f ≫ coprod.map (𝟙 W) g := by simp
/-- If the coproducts `W ⨿ X` and `Y ⨿ Z` exist, then every pair of isomorphisms `f : W ≅ Y` and
`g : W ≅ Z` induces an isomorphism `coprod.mapIso f g : W ⨿ X ≅ Y ⨿ Z`. -/
@[simps]
def coprod.mapIso {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ≅ Y)
(g : X ≅ Z) : W ⨿ X ≅ Y ⨿ Z where
hom := coprod.map f.hom g.hom
inv := coprod.map f.inv g.inv
instance isIso_coprod {W X Y Z : C} [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] (f : W ⟶ Y)
(g : X ⟶ Z) [IsIso f] [IsIso g] : IsIso (coprod.map f g) :=
(coprod.mapIso (asIso f) (asIso g)).isIso_hom
instance coprod.map_epi {C : Type*} [Category C] {W X Y Z : C} (f : W ⟶ Y) (g : X ⟶ Z) [Epi f]
[Epi g] [HasBinaryCoproduct W X] [HasBinaryCoproduct Y Z] : Epi (coprod.map f g) :=
⟨fun i₁ i₂ h => by
ext
· rw [← cancel_epi f]
simpa using congr_arg (fun f => coprod.inl ≫ f) h
· rw [← cancel_epi g]
simpa using congr_arg (fun f => coprod.inr ≫ f) h⟩
@[reassoc]
theorem coprod.map_codiag {X Y : C} (f : X ⟶ Y) [HasBinaryCoproduct X X] [HasBinaryCoproduct Y Y] :
coprod.map f f ≫ codiag Y = codiag X ≫ f := by simp
@[reassoc]
theorem coprod.map_inl_inr_codiag {X Y : C} [HasBinaryCoproduct X Y]
[HasBinaryCoproduct (X ⨿ Y) (X ⨿ Y)] :
coprod.map coprod.inl coprod.inr ≫ codiag (X ⨿ Y) = 𝟙 (X ⨿ Y) := by simp
@[reassoc]
theorem coprod.map_comp_inl_inr_codiag [HasColimitsOfShape (Discrete WalkingPair) C] {X X' Y Y' : C}
(g : X ⟶ Y) (g' : X' ⟶ Y') :
coprod.map (g ≫ coprod.inl) (g' ≫ coprod.inr) ≫ codiag (Y ⨿ Y') = coprod.map g g' := by simp
end CoprodLemmas
variable (C)
/-- `HasBinaryProducts` represents a choice of product for every pair of objects. -/
@[stacks 001T]
abbrev HasBinaryProducts :=
HasLimitsOfShape (Discrete WalkingPair) C
/-- `HasBinaryCoproducts` represents a choice of coproduct for every pair of objects. -/
@[stacks 04AP]
abbrev HasBinaryCoproducts :=
HasColimitsOfShape (Discrete WalkingPair) C
/-- If `C` has all limits of diagrams `pair X Y`, then it has all binary products -/
theorem hasBinaryProducts_of_hasLimit_pair [∀ {X Y : C}, HasLimit (pair X Y)] :
HasBinaryProducts C :=
{ has_limit := fun F => hasLimit_of_iso (diagramIsoPair F).symm }
/-- If `C` has all colimits of diagrams `pair X Y`, then it has all binary coproducts -/
theorem hasBinaryCoproducts_of_hasColimit_pair [∀ {X Y : C}, HasColimit (pair X Y)] :
HasBinaryCoproducts C :=
{ has_colimit := fun F => hasColimit_of_iso (diagramIsoPair F) }
noncomputable section
variable {C}
/-- The braiding isomorphism which swaps a binary product. -/
@[simps]
def prod.braiding (P Q : C) [HasBinaryProduct P Q] [HasBinaryProduct Q P] : P ⨯ Q ≅ Q ⨯ P where
hom := prod.lift prod.snd prod.fst
inv := prod.lift prod.snd prod.fst
/-- The braiding isomorphism can be passed through a map by swapping the order. -/
@[reassoc]
| Mathlib/CategoryTheory/Limits/Shapes/BinaryProducts.lean | 872 | 873 | theorem braid_natural [HasBinaryProducts C] {W X Y Z : C} (f : X ⟶ Y) (g : Z ⟶ W) :
prod.map f g ≫ (prod.braiding _ _).hom = (prod.braiding _ _).hom ≫ prod.map g f := by | simp |
/-
Copyright (c) 2021 Aaron Anderson, Jesse Michael Han, Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Jesse Michael Han, Floris van Doorn
-/
import Mathlib.Data.Fin.VecNotation
import Mathlib.SetTheory.Cardinal.Basic
/-!
# Basics on First-Order Structures
This file defines first-order languages and structures in the style of the
[Flypitch project](https://flypitch.github.io/), as well as several important maps between
structures.
## Main Definitions
- A `FirstOrder.Language` defines a language as a pair of functions from the natural numbers to
`Type l`. One sends `n` to the type of `n`-ary functions, and the other sends `n` to the type of
`n`-ary relations.
- A `FirstOrder.Language.Structure` interprets the symbols of a given `FirstOrder.Language` in the
context of a given type.
- A `FirstOrder.Language.Hom`, denoted `M →[L] N`, is a map from the `L`-structure `M` to the
`L`-structure `N` that commutes with the interpretations of functions, and which preserves the
interpretations of relations (although only in the forward direction).
- A `FirstOrder.Language.Embedding`, denoted `M ↪[L] N`, is an embedding from the `L`-structure `M`
to the `L`-structure `N` that commutes with the interpretations of functions, and which preserves
the interpretations of relations in both directions.
- A `FirstOrder.Language.Equiv`, denoted `M ≃[L] N`, is an equivalence from the `L`-structure `M`
to the `L`-structure `N` that commutes with the interpretations of functions, and which preserves
the interpretations of relations in both directions.
## References
For the Flypitch project:
- [J. Han, F. van Doorn, *A formal proof of the independence of the continuum hypothesis*]
[flypitch_cpp]
- [J. Han, F. van Doorn, *A formalization of forcing and the unprovability of
the continuum hypothesis*][flypitch_itp]
-/
universe u v u' v' w w'
open Cardinal
namespace FirstOrder
/-! ### Languages and Structures -/
-- intended to be used with explicit universe parameters
/-- A first-order language consists of a type of functions of every natural-number arity and a
type of relations of every natural-number arity. -/
@[nolint checkUnivs]
structure Language where
/-- For every arity, a `Type*` of functions of that arity -/
Functions : ℕ → Type u
/-- For every arity, a `Type*` of relations of that arity -/
Relations : ℕ → Type v
namespace Language
variable (L : Language.{u, v})
/-- A language is relational when it has no function symbols. -/
abbrev IsRelational : Prop := ∀ n, IsEmpty (L.Functions n)
/-- A language is algebraic when it has no relation symbols. -/
abbrev IsAlgebraic : Prop := ∀ n, IsEmpty (L.Relations n)
/-- The empty language has no symbols. -/
protected def empty : Language :=
⟨fun _ => Empty, fun _ => Empty⟩
deriving IsAlgebraic, IsRelational
instance : Inhabited Language :=
⟨Language.empty⟩
/-- The sum of two languages consists of the disjoint union of their symbols. -/
protected def sum (L' : Language.{u', v'}) : Language :=
⟨fun n => L.Functions n ⊕ L'.Functions n, fun n => L.Relations n ⊕ L'.Relations n⟩
/-- The type of constants in a given language. -/
protected abbrev Constants :=
L.Functions 0
/-- The type of symbols in a given language. -/
abbrev Symbols :=
(Σ l, L.Functions l) ⊕ (Σ l, L.Relations l)
/-- The cardinality of a language is the cardinality of its type of symbols. -/
def card : Cardinal :=
#L.Symbols
variable {L} {L' : Language.{u', v'}}
theorem card_eq_card_functions_add_card_relations :
L.card =
(Cardinal.sum fun l => Cardinal.lift.{v} #(L.Functions l)) +
Cardinal.sum fun l => Cardinal.lift.{u} #(L.Relations l) := by
simp only [card, mk_sum, mk_sigma, lift_sum]
instance isRelational_sum [L.IsRelational] [L'.IsRelational] : IsRelational (L.sum L') :=
fun _ => instIsEmptySum
instance isAlgebraic_sum [L.IsAlgebraic] [L'.IsAlgebraic] : IsAlgebraic (L.sum L') :=
fun _ => instIsEmptySum
@[simp]
theorem card_empty : Language.empty.card = 0 := by simp only [card, mk_sum, mk_sigma, mk_eq_zero,
sum_const, mk_eq_aleph0, lift_id', mul_zero, add_zero]
@[deprecated (since := "2025-02-05")] alias empty_card := card_empty
instance isEmpty_empty : IsEmpty Language.empty.Symbols := by
simp only [Language.Symbols, isEmpty_sum, isEmpty_sigma]
exact ⟨fun _ => inferInstance, fun _ => inferInstance⟩
instance Countable.countable_functions [h : Countable L.Symbols] : Countable (Σl, L.Functions l) :=
@Function.Injective.countable _ _ h _ Sum.inl_injective
@[simp]
theorem card_functions_sum (i : ℕ) :
#((L.sum L').Functions i)
= (Cardinal.lift.{u'} #(L.Functions i) + Cardinal.lift.{u} #(L'.Functions i) : Cardinal) := by
simp [Language.sum]
@[simp]
theorem card_relations_sum (i : ℕ) :
#((L.sum L').Relations i) =
Cardinal.lift.{v'} #(L.Relations i) + Cardinal.lift.{v} #(L'.Relations i) := by
simp [Language.sum]
theorem card_sum :
(L.sum L').card = Cardinal.lift.{max u' v'} L.card + Cardinal.lift.{max u v} L'.card := by
simp only [card, mk_sum, mk_sigma, card_functions_sum, sum_add_distrib', lift_add, lift_sum,
lift_lift, card_relations_sum, add_assoc,
add_comm (Cardinal.sum fun i => (#(L'.Functions i)).lift)]
/-- Passes a `DecidableEq` instance on a type of function symbols through the `Language`
constructor. Despite the fact that this is proven by `inferInstance`, it is still needed -
see the `example`s in `ModelTheory/Ring/Basic`. -/
instance instDecidableEqFunctions {f : ℕ → Type*} {R : ℕ → Type*} (n : ℕ) [DecidableEq (f n)] :
DecidableEq ((⟨f, R⟩ : Language).Functions n) := inferInstance
/-- Passes a `DecidableEq` instance on a type of relation symbols through the `Language`
constructor. Despite the fact that this is proven by `inferInstance`, it is still needed -
see the `example`s in `ModelTheory/Ring/Basic`. -/
instance instDecidableEqRelations {f : ℕ → Type*} {R : ℕ → Type*} (n : ℕ) [DecidableEq (R n)] :
DecidableEq ((⟨f, R⟩ : Language).Relations n) := inferInstance
variable (L) (M : Type w)
/-- A first-order structure on a type `M` consists of interpretations of all the symbols in a given
language. Each function of arity `n` is interpreted as a function sending tuples of length `n`
(modeled as `(Fin n → M)`) to `M`, and a relation of arity `n` is a function from tuples of length
`n` to `Prop`. -/
@[ext]
class Structure where
/-- Interpretation of the function symbols -/
funMap : ∀ {n}, L.Functions n → (Fin n → M) → M := by
exact fun {n} => isEmptyElim
/-- Interpretation of the relation symbols -/
RelMap : ∀ {n}, L.Relations n → (Fin n → M) → Prop := by
exact fun {n} => isEmptyElim
variable (N : Type w') [L.Structure M] [L.Structure N]
open Structure
/-- Used for defining `FirstOrder.Language.Theory.ModelType.instInhabited`. -/
def Inhabited.trivialStructure {α : Type*} [Inhabited α] : L.Structure α :=
⟨default, default⟩
/-! ### Maps -/
/-- A homomorphism between first-order structures is a function that commutes with the
interpretations of functions and maps tuples in one structure where a given relation is true to
tuples in the second structure where that relation is still true. -/
structure Hom where
/-- The underlying function of a homomorphism of structures -/
toFun : M → N
/-- The homomorphism commutes with the interpretations of the function symbols -/
-- Porting note:
-- The autoparam here used to be `obviously`. We would like to replace it with `aesop`
-- but that isn't currently sufficient.
-- See https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Aesop.20and.20cases
-- If that can be improved, we should change this to `by aesop` and remove the proofs below.
map_fun' : ∀ {n} (f : L.Functions n) (x), toFun (funMap f x) = funMap f (toFun ∘ x) := by
intros; trivial
/-- The homomorphism sends related elements to related elements -/
map_rel' : ∀ {n} (r : L.Relations n) (x), RelMap r x → RelMap r (toFun ∘ x) := by
-- Porting note: see porting note on `Hom.map_fun'`
intros; trivial
@[inherit_doc]
scoped[FirstOrder] notation:25 A " →[" L "] " B => FirstOrder.Language.Hom L A B
/-- An embedding of first-order structures is an embedding that commutes with the
interpretations of functions and relations. -/
structure Embedding extends M ↪ N where
map_fun' : ∀ {n} (f : L.Functions n) (x), toFun (funMap f x) = funMap f (toFun ∘ x) := by
-- Porting note: see porting note on `Hom.map_fun'`
intros; trivial
map_rel' : ∀ {n} (r : L.Relations n) (x), RelMap r (toFun ∘ x) ↔ RelMap r x := by
-- Porting note: see porting note on `Hom.map_fun'`
intros; trivial
@[inherit_doc]
scoped[FirstOrder] notation:25 A " ↪[" L "] " B => FirstOrder.Language.Embedding L A B
/-- An equivalence of first-order structures is an equivalence that commutes with the
interpretations of functions and relations. -/
structure Equiv extends M ≃ N where
map_fun' : ∀ {n} (f : L.Functions n) (x), toFun (funMap f x) = funMap f (toFun ∘ x) := by
-- Porting note: see porting note on `Hom.map_fun'`
intros; trivial
map_rel' : ∀ {n} (r : L.Relations n) (x), RelMap r (toFun ∘ x) ↔ RelMap r x := by
-- Porting note: see porting note on `Hom.map_fun'`
intros; trivial
@[inherit_doc]
scoped[FirstOrder] notation:25 A " ≃[" L "] " B => FirstOrder.Language.Equiv L A B
variable {L M N} {P : Type*} [L.Structure P] {Q : Type*} [L.Structure Q]
/-- Interpretation of a constant symbol -/
@[coe]
def constantMap (c : L.Constants) : M := funMap c default
instance : CoeTC L.Constants M :=
⟨constantMap⟩
theorem funMap_eq_coe_constants {c : L.Constants} {x : Fin 0 → M} : funMap c x = c :=
congr rfl (funext finZeroElim)
/-- Given a language with a nonempty type of constants, any structure will be nonempty. This cannot
be a global instance, because `L` becomes a metavariable. -/
theorem nonempty_of_nonempty_constants [h : Nonempty L.Constants] : Nonempty M :=
h.map (↑)
/-- `HomClass L F M N` states that `F` is a type of `L`-homomorphisms. You should extend this
typeclass when you extend `FirstOrder.Language.Hom`. -/
class HomClass (L : outParam Language) (F : Type*) (M N : outParam Type*)
[FunLike F M N] [L.Structure M] [L.Structure N] : Prop where
map_fun : ∀ (φ : F) {n} (f : L.Functions n) (x), φ (funMap f x) = funMap f (φ ∘ x)
map_rel : ∀ (φ : F) {n} (r : L.Relations n) (x), RelMap r x → RelMap r (φ ∘ x)
/-- `StrongHomClass L F M N` states that `F` is a type of `L`-homomorphisms which preserve
relations in both directions. -/
class StrongHomClass (L : outParam Language) (F : Type*) (M N : outParam Type*)
[FunLike F M N] [L.Structure M] [L.Structure N] : Prop where
map_fun : ∀ (φ : F) {n} (f : L.Functions n) (x), φ (funMap f x) = funMap f (φ ∘ x)
map_rel : ∀ (φ : F) {n} (r : L.Relations n) (x), RelMap r (φ ∘ x) ↔ RelMap r x
instance (priority := 100) StrongHomClass.homClass {F : Type*} [L.Structure M]
[L.Structure N] [FunLike F M N] [StrongHomClass L F M N] : HomClass L F M N where
map_fun := StrongHomClass.map_fun
map_rel φ _ R x := (StrongHomClass.map_rel φ R x).2
/-- Not an instance to avoid a loop. -/
theorem HomClass.strongHomClassOfIsAlgebraic [L.IsAlgebraic] {F M N} [L.Structure M] [L.Structure N]
[FunLike F M N] [HomClass L F M N] : StrongHomClass L F M N where
map_fun := HomClass.map_fun
map_rel _ _ := isEmptyElim
theorem HomClass.map_constants {F M N} [L.Structure M] [L.Structure N] [FunLike F M N]
[HomClass L F M N] (φ : F) (c : L.Constants) : φ c = c :=
(HomClass.map_fun φ c default).trans (congr rfl (funext default))
attribute [inherit_doc FirstOrder.Language.Hom.map_fun'] FirstOrder.Language.Embedding.map_fun'
FirstOrder.Language.HomClass.map_fun FirstOrder.Language.StrongHomClass.map_fun
FirstOrder.Language.Equiv.map_fun'
attribute [inherit_doc FirstOrder.Language.Hom.map_rel'] FirstOrder.Language.Embedding.map_rel'
FirstOrder.Language.HomClass.map_rel FirstOrder.Language.StrongHomClass.map_rel
FirstOrder.Language.Equiv.map_rel'
namespace Hom
instance instFunLike : FunLike (M →[L] N) M N where
coe := Hom.toFun
coe_injective' f g h := by cases f; cases g; cases h; rfl
instance homClass : HomClass L (M →[L] N) M N where
map_fun := map_fun'
map_rel := map_rel'
instance [L.IsAlgebraic] : StrongHomClass L (M →[L] N) M N :=
HomClass.strongHomClassOfIsAlgebraic
@[simp]
theorem toFun_eq_coe {f : M →[L] N} : f.toFun = (f : M → N) :=
rfl
@[ext]
theorem ext ⦃f g : M →[L] N⦄ (h : ∀ x, f x = g x) : f = g :=
DFunLike.ext f g h
@[simp]
theorem map_fun (φ : M →[L] N) {n : ℕ} (f : L.Functions n) (x : Fin n → M) :
φ (funMap f x) = funMap f (φ ∘ x) :=
HomClass.map_fun φ f x
@[simp]
theorem map_constants (φ : M →[L] N) (c : L.Constants) : φ c = c :=
HomClass.map_constants φ c
@[simp]
theorem map_rel (φ : M →[L] N) {n : ℕ} (r : L.Relations n) (x : Fin n → M) :
RelMap r x → RelMap r (φ ∘ x) :=
HomClass.map_rel φ r x
variable (L) (M)
/-- The identity map from a structure to itself. -/
@[refl]
def id : M →[L] M where
toFun m := m
variable {L} {M}
instance : Inhabited (M →[L] M) :=
⟨id L M⟩
@[simp]
theorem id_apply (x : M) : id L M x = x :=
rfl
/-- Composition of first-order homomorphisms. -/
@[trans]
def comp (hnp : N →[L] P) (hmn : M →[L] N) : M →[L] P where
toFun := hnp ∘ hmn
-- Porting note: should be done by autoparam?
map_fun' _ _ := by simp; rfl
-- Porting note: should be done by autoparam?
map_rel' _ _ h := map_rel _ _ _ (map_rel _ _ _ h)
@[simp]
theorem comp_apply (g : N →[L] P) (f : M →[L] N) (x : M) : g.comp f x = g (f x) :=
rfl
/-- Composition of first-order homomorphisms is associative. -/
theorem comp_assoc (f : M →[L] N) (g : N →[L] P) (h : P →[L] Q) :
(h.comp g).comp f = h.comp (g.comp f) :=
rfl
@[simp]
theorem comp_id (f : M →[L] N) : f.comp (id L M) = f :=
rfl
@[simp]
theorem id_comp (f : M →[L] N) : (id L N).comp f = f :=
rfl
end Hom
/-- Any element of a `HomClass` can be realized as a first_order homomorphism. -/
@[simps] def HomClass.toHom {F M N} [L.Structure M] [L.Structure N] [FunLike F M N]
[HomClass L F M N] : F → M →[L] N := fun φ =>
⟨φ, HomClass.map_fun φ, HomClass.map_rel φ⟩
namespace Embedding
instance funLike : FunLike (M ↪[L] N) M N where
coe f := f.toFun
coe_injective' f g h := by
cases f
cases g
congr
ext x
exact funext_iff.1 h x
instance embeddingLike : EmbeddingLike (M ↪[L] N) M N where
injective' f := f.toEmbedding.injective
instance strongHomClass : StrongHomClass L (M ↪[L] N) M N where
map_fun := map_fun'
map_rel := map_rel'
@[simp]
theorem map_fun (φ : M ↪[L] N) {n : ℕ} (f : L.Functions n) (x : Fin n → M) :
φ (funMap f x) = funMap f (φ ∘ x) :=
HomClass.map_fun φ f x
@[simp]
theorem map_constants (φ : M ↪[L] N) (c : L.Constants) : φ c = c :=
HomClass.map_constants φ c
@[simp]
theorem map_rel (φ : M ↪[L] N) {n : ℕ} (r : L.Relations n) (x : Fin n → M) :
RelMap r (φ ∘ x) ↔ RelMap r x :=
StrongHomClass.map_rel φ r x
/-- A first-order embedding is also a first-order homomorphism. -/
def toHom : (M ↪[L] N) → M →[L] N :=
HomClass.toHom
@[simp]
theorem coe_toHom {f : M ↪[L] N} : (f.toHom : M → N) = f :=
rfl
theorem coe_injective : @Function.Injective (M ↪[L] N) (M → N) (↑)
| f, g, h => by
cases f
cases g
congr
ext x
exact funext_iff.1 h x
@[ext]
theorem ext ⦃f g : M ↪[L] N⦄ (h : ∀ x, f x = g x) : f = g :=
coe_injective (funext h)
theorem toHom_injective : @Function.Injective (M ↪[L] N) (M →[L] N) (·.toHom) := by
intro f f' h
ext
exact congr_fun (congr_arg (↑) h) _
@[simp]
theorem toHom_inj {f g : M ↪[L] N} : f.toHom = g.toHom ↔ f = g :=
⟨fun h ↦ toHom_injective h, fun h ↦ congr_arg (·.toHom) h⟩
theorem injective (f : M ↪[L] N) : Function.Injective f :=
f.toEmbedding.injective
/-- In an algebraic language, any injective homomorphism is an embedding. -/
@[simps!]
def ofInjective [L.IsAlgebraic] {f : M →[L] N} (hf : Function.Injective f) : M ↪[L] N :=
{ f with
inj' := hf
map_rel' := fun {_} r x => StrongHomClass.map_rel f r x }
@[simp]
theorem coeFn_ofInjective [L.IsAlgebraic] {f : M →[L] N} (hf : Function.Injective f) :
(ofInjective hf : M → N) = f :=
rfl
@[simp]
theorem ofInjective_toHom [L.IsAlgebraic] {f : M →[L] N} (hf : Function.Injective f) :
(ofInjective hf).toHom = f := by
ext; simp
variable (L) (M)
/-- The identity embedding from a structure to itself. -/
@[refl]
def refl : M ↪[L] M where toEmbedding := Function.Embedding.refl M
variable {L} {M}
instance : Inhabited (M ↪[L] M) :=
⟨refl L M⟩
@[simp]
theorem refl_apply (x : M) : refl L M x = x :=
rfl
/-- Composition of first-order embeddings. -/
@[trans]
def comp (hnp : N ↪[L] P) (hmn : M ↪[L] N) : M ↪[L] P where
toFun := hnp ∘ hmn
inj' := hnp.injective.comp hmn.injective
-- Porting note: should be done by autoparam?
map_fun' := by intros; simp only [Function.comp_apply, map_fun]; trivial
-- Porting note: should be done by autoparam?
map_rel' := by intros; rw [Function.comp_assoc, map_rel, map_rel]
@[simp]
theorem comp_apply (g : N ↪[L] P) (f : M ↪[L] N) (x : M) : g.comp f x = g (f x) :=
rfl
/-- Composition of first-order embeddings is associative. -/
theorem comp_assoc (f : M ↪[L] N) (g : N ↪[L] P) (h : P ↪[L] Q) :
(h.comp g).comp f = h.comp (g.comp f) :=
rfl
theorem comp_injective (h : N ↪[L] P) :
Function.Injective (h.comp : (M ↪[L] N) → (M ↪[L] P)) := by
intro f g hfg
ext x; exact h.injective (DFunLike.congr_fun hfg x)
@[simp]
theorem comp_inj (h : N ↪[L] P) (f g : M ↪[L] N) : h.comp f = h.comp g ↔ f = g :=
⟨fun eq ↦ h.comp_injective eq, congr_arg h.comp⟩
theorem toHom_comp_injective (h : N ↪[L] P) :
Function.Injective (h.toHom.comp : (M →[L] N) → (M →[L] P)) := by
intro f g hfg
ext x; exact h.injective (DFunLike.congr_fun hfg x)
@[simp]
theorem toHom_comp_inj (h : N ↪[L] P) (f g : M →[L] N) : h.toHom.comp f = h.toHom.comp g ↔ f = g :=
⟨fun eq ↦ h.toHom_comp_injective eq, congr_arg h.toHom.comp⟩
@[simp]
theorem comp_toHom (hnp : N ↪[L] P) (hmn : M ↪[L] N) :
(hnp.comp hmn).toHom = hnp.toHom.comp hmn.toHom :=
rfl
@[simp]
theorem comp_refl (f : M ↪[L] N) : f.comp (refl L M) = f := DFunLike.coe_injective rfl
@[simp]
theorem refl_comp (f : M ↪[L] N) : (refl L N).comp f = f := DFunLike.coe_injective rfl
@[simp]
theorem refl_toHom : (refl L M).toHom = Hom.id L M :=
rfl
end Embedding
/-- Any element of an injective `StrongHomClass` can be realized as a first_order embedding. -/
@[simps] def StrongHomClass.toEmbedding {F M N} [L.Structure M] [L.Structure N] [FunLike F M N]
[EmbeddingLike F M N] [StrongHomClass L F M N] : F → M ↪[L] N := fun φ =>
⟨⟨φ, EmbeddingLike.injective φ⟩, StrongHomClass.map_fun φ, StrongHomClass.map_rel φ⟩
namespace Equiv
instance : EquivLike (M ≃[L] N) M N where
coe f := f.toFun
inv f := f.invFun
left_inv f := f.left_inv
right_inv f := f.right_inv
coe_injective' f g h₁ h₂ := by
cases f
cases g
simp only [mk.injEq]
ext x
exact funext_iff.1 h₁ x
instance : StrongHomClass L (M ≃[L] N) M N where
map_fun := map_fun'
map_rel := map_rel'
/-- The inverse of a first-order equivalence is a first-order equivalence. -/
@[symm]
def symm (f : M ≃[L] N) : N ≃[L] M :=
{ f.toEquiv.symm with
map_fun' := fun n f' {x} => by
simp only [Equiv.toFun_as_coe]
rw [Equiv.symm_apply_eq]
refine Eq.trans ?_ (f.map_fun' f' (f.toEquiv.symm ∘ x)).symm
rw [← Function.comp_assoc, Equiv.toFun_as_coe, Equiv.self_comp_symm, Function.id_comp]
map_rel' := fun n r {x} => by
simp only [Equiv.toFun_as_coe]
refine (f.map_rel' r (f.toEquiv.symm ∘ x)).symm.trans ?_
rw [← Function.comp_assoc, Equiv.toFun_as_coe, Equiv.self_comp_symm, Function.id_comp] }
@[simp]
theorem symm_symm (f : M ≃[L] N) :
f.symm.symm = f :=
rfl
theorem symm_bijective : Function.Bijective (symm : (M ≃[L] N) → _) :=
Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩
@[simp]
theorem apply_symm_apply (f : M ≃[L] N) (a : N) : f (f.symm a) = a :=
f.toEquiv.apply_symm_apply a
@[simp]
theorem symm_apply_apply (f : M ≃[L] N) (a : M) : f.symm (f a) = a :=
f.toEquiv.symm_apply_apply a
@[simp]
theorem map_fun (φ : M ≃[L] N) {n : ℕ} (f : L.Functions n) (x : Fin n → M) :
φ (funMap f x) = funMap f (φ ∘ x) :=
HomClass.map_fun φ f x
@[simp]
theorem map_constants (φ : M ≃[L] N) (c : L.Constants) : φ c = c :=
HomClass.map_constants φ c
@[simp]
theorem map_rel (φ : M ≃[L] N) {n : ℕ} (r : L.Relations n) (x : Fin n → M) :
RelMap r (φ ∘ x) ↔ RelMap r x :=
StrongHomClass.map_rel φ r x
/-- A first-order equivalence is also a first-order embedding. -/
def toEmbedding : (M ≃[L] N) → M ↪[L] N :=
StrongHomClass.toEmbedding
/-- A first-order equivalence is also a first-order homomorphism. -/
def toHom : (M ≃[L] N) → M →[L] N :=
HomClass.toHom
@[simp]
theorem toEmbedding_toHom (f : M ≃[L] N) : f.toEmbedding.toHom = f.toHom :=
rfl
@[simp]
theorem coe_toHom {f : M ≃[L] N} : (f.toHom : M → N) = (f : M → N) :=
rfl
@[simp]
theorem coe_toEmbedding (f : M ≃[L] N) : (f.toEmbedding : M → N) = (f : M → N) :=
rfl
theorem injective_toEmbedding : Function.Injective (toEmbedding : (M ≃[L] N) → M ↪[L] N) := by
intro _ _ h; apply DFunLike.coe_injective; exact congr_arg (DFunLike.coe ∘ Embedding.toHom) h
theorem coe_injective : @Function.Injective (M ≃[L] N) (M → N) (↑) :=
DFunLike.coe_injective
@[ext]
theorem ext ⦃f g : M ≃[L] N⦄ (h : ∀ x, f x = g x) : f = g :=
coe_injective (funext h)
theorem bijective (f : M ≃[L] N) : Function.Bijective f :=
EquivLike.bijective f
theorem injective (f : M ≃[L] N) : Function.Injective f :=
EquivLike.injective f
theorem surjective (f : M ≃[L] N) : Function.Surjective f :=
EquivLike.surjective f
variable (L) (M)
/-- The identity equivalence from a structure to itself. -/
@[refl]
def refl : M ≃[L] M where toEquiv := _root_.Equiv.refl M
variable {L} {M}
instance : Inhabited (M ≃[L] M) :=
⟨refl L M⟩
@[simp]
theorem refl_apply (x : M) : refl L M x = x := by simp [refl]; rfl
/-- Composition of first-order equivalences. -/
@[trans]
def comp (hnp : N ≃[L] P) (hmn : M ≃[L] N) : M ≃[L] P :=
{ hmn.toEquiv.trans hnp.toEquiv with
toFun := hnp ∘ hmn
-- Porting note: should be done by autoparam?
map_fun' := by intros; simp only [Function.comp_apply, map_fun]; trivial
-- Porting note: should be done by autoparam?
map_rel' := by intros; rw [Function.comp_assoc, map_rel, map_rel] }
@[simp]
theorem comp_apply (g : N ≃[L] P) (f : M ≃[L] N) (x : M) : g.comp f x = g (f x) :=
rfl
@[simp]
theorem comp_refl (g : M ≃[L] N) : g.comp (refl L M) = g :=
rfl
@[simp]
theorem refl_comp (g : M ≃[L] N) : (refl L N).comp g = g :=
rfl
@[simp]
theorem refl_toEmbedding : (refl L M).toEmbedding = Embedding.refl L M :=
rfl
@[simp]
theorem refl_toHom : (refl L M).toHom = Hom.id L M :=
rfl
/-- Composition of first-order homomorphisms is associative. -/
theorem comp_assoc (f : M ≃[L] N) (g : N ≃[L] P) (h : P ≃[L] Q) :
(h.comp g).comp f = h.comp (g.comp f) :=
rfl
theorem injective_comp (h : N ≃[L] P) :
Function.Injective (h.comp : (M ≃[L] N) → (M ≃[L] P)) := by
intro f g hfg
ext x; exact h.injective (congr_fun (congr_arg DFunLike.coe hfg) x)
@[simp]
theorem comp_toHom (hnp : N ≃[L] P) (hmn : M ≃[L] N) :
(hnp.comp hmn).toHom = hnp.toHom.comp hmn.toHom :=
rfl
@[simp]
theorem comp_toEmbedding (hnp : N ≃[L] P) (hmn : M ≃[L] N) :
(hnp.comp hmn).toEmbedding = hnp.toEmbedding.comp hmn.toEmbedding :=
rfl
@[simp]
theorem self_comp_symm (f : M ≃[L] N) : f.comp f.symm = refl L N := by
ext; rw [comp_apply, apply_symm_apply, refl_apply]
@[simp]
theorem symm_comp_self (f : M ≃[L] N) : f.symm.comp f = refl L M := by
ext; rw [comp_apply, symm_apply_apply, refl_apply]
@[simp]
| Mathlib/ModelTheory/Basic.lean | 693 | 695 | theorem symm_comp_self_toEmbedding (f : M ≃[L] N) :
f.symm.toEmbedding.comp f.toEmbedding = Embedding.refl L M := by | rw [← comp_toEmbedding, symm_comp_self, refl_toEmbedding] |
/-
Copyright (c) 2020 Frédéric Dupuis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Frédéric Dupuis, Eric Wieser
-/
import Mathlib.LinearAlgebra.Multilinear.TensorProduct
import Mathlib.Tactic.AdaptationNote
import Mathlib.LinearAlgebra.Multilinear.Curry
/-!
# Tensor product of an indexed family of modules over commutative semirings
We define the tensor product of an indexed family `s : ι → Type*` of modules over commutative
semirings. We denote this space by `⨂[R] i, s i` and define it as `FreeAddMonoid (R × Π i, s i)`
quotiented by the appropriate equivalence relation. The treatment follows very closely that of the
binary tensor product in `LinearAlgebra/TensorProduct.lean`.
## Main definitions
* `PiTensorProduct R s` with `R` a commutative semiring and `s : ι → Type*` is the tensor product
of all the `s i`'s. This is denoted by `⨂[R] i, s i`.
* `tprod R f` with `f : Π i, s i` is the tensor product of the vectors `f i` over all `i : ι`.
This is bundled as a multilinear map from `Π i, s i` to `⨂[R] i, s i`.
* `liftAddHom` constructs an `AddMonoidHom` from `(⨂[R] i, s i)` to some space `F` from a
function `φ : (R × Π i, s i) → F` with the appropriate properties.
* `lift φ` with `φ : MultilinearMap R s E` is the corresponding linear map
`(⨂[R] i, s i) →ₗ[R] E`. This is bundled as a linear equivalence.
* `PiTensorProduct.reindex e` re-indexes the components of `⨂[R] i : ι, M` along `e : ι ≃ ι₂`.
* `PiTensorProduct.tmulEquiv` equivalence between a `TensorProduct` of `PiTensorProduct`s and
a single `PiTensorProduct`.
## Notations
* `⨂[R] i, s i` is defined as localized notation in locale `TensorProduct`.
* `⨂ₜ[R] i, f i` with `f : ∀ i, s i` is defined globally as the tensor product of all the `f i`'s.
## Implementation notes
* We define it via `FreeAddMonoid (R × Π i, s i)` with the `R` representing a "hidden" tensor
factor, rather than `FreeAddMonoid (Π i, s i)` to ensure that, if `ι` is an empty type,
the space is isomorphic to the base ring `R`.
* We have not restricted the index type `ι` to be a `Fintype`, as nothing we do here strictly
requires it. However, problems may arise in the case where `ι` is infinite; use at your own
caution.
* Instead of requiring `DecidableEq ι` as an argument to `PiTensorProduct` itself, we include it
as an argument in the constructors of the relation. A decidability instance still has to come
from somewhere due to the use of `Function.update`, but this hides it from the downstream user.
See the implementation notes for `MultilinearMap` for an extended discussion of this choice.
## TODO
* Define tensor powers, symmetric subspace, etc.
* API for the various ways `ι` can be split into subsets; connect this with the binary
tensor product.
* Include connection with holors.
* Port more of the API from the binary tensor product over to this case.
## Tags
multilinear, tensor, tensor product
-/
suppress_compilation
open Function
section Semiring
variable {ι ι₂ ι₃ : Type*}
variable {R : Type*} [CommSemiring R]
variable {R₁ R₂ : Type*}
variable {s : ι → Type*} [∀ i, AddCommMonoid (s i)] [∀ i, Module R (s i)]
variable {M : Type*} [AddCommMonoid M] [Module R M]
variable {E : Type*} [AddCommMonoid E] [Module R E]
variable {F : Type*} [AddCommMonoid F]
namespace PiTensorProduct
variable (R) (s)
/-- The relation on `FreeAddMonoid (R × Π i, s i)` that generates a congruence whose quotient is
the tensor product. -/
inductive Eqv : FreeAddMonoid (R × Π i, s i) → FreeAddMonoid (R × Π i, s i) → Prop
| of_zero : ∀ (r : R) (f : Π i, s i) (i : ι) (_ : f i = 0), Eqv (FreeAddMonoid.of (r, f)) 0
| of_zero_scalar : ∀ f : Π i, s i, Eqv (FreeAddMonoid.of (0, f)) 0
| of_add : ∀ (_ : DecidableEq ι) (r : R) (f : Π i, s i) (i : ι) (m₁ m₂ : s i),
Eqv (FreeAddMonoid.of (r, update f i m₁) + FreeAddMonoid.of (r, update f i m₂))
(FreeAddMonoid.of (r, update f i (m₁ + m₂)))
| of_add_scalar : ∀ (r r' : R) (f : Π i, s i),
Eqv (FreeAddMonoid.of (r, f) + FreeAddMonoid.of (r', f)) (FreeAddMonoid.of (r + r', f))
| of_smul : ∀ (_ : DecidableEq ι) (r : R) (f : Π i, s i) (i : ι) (r' : R),
Eqv (FreeAddMonoid.of (r, update f i (r' • f i))) (FreeAddMonoid.of (r' * r, f))
| add_comm : ∀ x y, Eqv (x + y) (y + x)
end PiTensorProduct
variable (R) (s)
/-- `PiTensorProduct R s` with `R` a commutative semiring and `s : ι → Type*` is the tensor
product of all the `s i`'s. This is denoted by `⨂[R] i, s i`. -/
def PiTensorProduct : Type _ :=
(addConGen (PiTensorProduct.Eqv R s)).Quotient
variable {R}
unsuppress_compilation in
/-- This enables the notation `⨂[R] i : ι, s i` for the pi tensor product `PiTensorProduct`,
given an indexed family of types `s : ι → Type*`. -/
scoped[TensorProduct] notation3:100"⨂["R"] "(...)", "r:(scoped f => PiTensorProduct R f) => r
open TensorProduct
namespace PiTensorProduct
section Module
instance : AddCommMonoid (⨂[R] i, s i) :=
{ (addConGen (PiTensorProduct.Eqv R s)).addMonoid with
add_comm := fun x y ↦
AddCon.induction_on₂ x y fun _ _ ↦
Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.add_comm _ _ }
instance : Inhabited (⨂[R] i, s i) := ⟨0⟩
variable (R) {s}
/-- `tprodCoeff R r f` with `r : R` and `f : Π i, s i` is the tensor product of the vectors `f i`
over all `i : ι`, multiplied by the coefficient `r`. Note that this is meant as an auxiliary
definition for this file alone, and that one should use `tprod` defined below for most purposes. -/
def tprodCoeff (r : R) (f : Π i, s i) : ⨂[R] i, s i :=
AddCon.mk' _ <| FreeAddMonoid.of (r, f)
variable {R}
theorem zero_tprodCoeff (f : Π i, s i) : tprodCoeff R 0 f = 0 :=
Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_zero_scalar _
theorem zero_tprodCoeff' (z : R) (f : Π i, s i) (i : ι) (hf : f i = 0) : tprodCoeff R z f = 0 :=
Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_zero _ _ i hf
theorem add_tprodCoeff [DecidableEq ι] (z : R) (f : Π i, s i) (i : ι) (m₁ m₂ : s i) :
tprodCoeff R z (update f i m₁) + tprodCoeff R z (update f i m₂) =
tprodCoeff R z (update f i (m₁ + m₂)) :=
Quotient.sound' <| AddConGen.Rel.of _ _ (Eqv.of_add _ z f i m₁ m₂)
theorem add_tprodCoeff' (z₁ z₂ : R) (f : Π i, s i) :
tprodCoeff R z₁ f + tprodCoeff R z₂ f = tprodCoeff R (z₁ + z₂) f :=
Quotient.sound' <| AddConGen.Rel.of _ _ (Eqv.of_add_scalar z₁ z₂ f)
theorem smul_tprodCoeff_aux [DecidableEq ι] (z : R) (f : Π i, s i) (i : ι) (r : R) :
tprodCoeff R z (update f i (r • f i)) = tprodCoeff R (r * z) f :=
Quotient.sound' <| AddConGen.Rel.of _ _ <| Eqv.of_smul _ _ _ _ _
theorem smul_tprodCoeff [DecidableEq ι] (z : R) (f : Π i, s i) (i : ι) (r : R₁) [SMul R₁ R]
[IsScalarTower R₁ R R] [SMul R₁ (s i)] [IsScalarTower R₁ R (s i)] :
tprodCoeff R z (update f i (r • f i)) = tprodCoeff R (r • z) f := by
have h₁ : r • z = r • (1 : R) * z := by rw [smul_mul_assoc, one_mul]
have h₂ : r • f i = (r • (1 : R)) • f i := (smul_one_smul _ _ _).symm
rw [h₁, h₂]
exact smul_tprodCoeff_aux z f i _
/-- Construct an `AddMonoidHom` from `(⨂[R] i, s i)` to some space `F` from a function
`φ : (R × Π i, s i) → F` with the appropriate properties. -/
def liftAddHom (φ : (R × Π i, s i) → F)
(C0 : ∀ (r : R) (f : Π i, s i) (i : ι) (_ : f i = 0), φ (r, f) = 0)
(C0' : ∀ f : Π i, s i, φ (0, f) = 0)
(C_add : ∀ [DecidableEq ι] (r : R) (f : Π i, s i) (i : ι) (m₁ m₂ : s i),
φ (r, update f i m₁) + φ (r, update f i m₂) = φ (r, update f i (m₁ + m₂)))
(C_add_scalar : ∀ (r r' : R) (f : Π i, s i), φ (r, f) + φ (r', f) = φ (r + r', f))
(C_smul : ∀ [DecidableEq ι] (r : R) (f : Π i, s i) (i : ι) (r' : R),
φ (r, update f i (r' • f i)) = φ (r' * r, f)) :
(⨂[R] i, s i) →+ F :=
(addConGen (PiTensorProduct.Eqv R s)).lift (FreeAddMonoid.lift φ) <|
AddCon.addConGen_le fun x y hxy ↦
match hxy with
| Eqv.of_zero r' f i hf =>
(AddCon.ker_rel _).2 <| by simp [FreeAddMonoid.lift_eval_of, C0 r' f i hf]
| Eqv.of_zero_scalar f =>
(AddCon.ker_rel _).2 <| by simp [FreeAddMonoid.lift_eval_of, C0']
| Eqv.of_add inst z f i m₁ m₂ =>
(AddCon.ker_rel _).2 <| by simp [FreeAddMonoid.lift_eval_of, @C_add inst]
| Eqv.of_add_scalar z₁ z₂ f =>
(AddCon.ker_rel _).2 <| by simp [FreeAddMonoid.lift_eval_of, C_add_scalar]
| Eqv.of_smul inst z f i r' =>
(AddCon.ker_rel _).2 <| by simp [FreeAddMonoid.lift_eval_of, @C_smul inst]
| Eqv.add_comm x y =>
(AddCon.ker_rel _).2 <| by simp_rw [AddMonoidHom.map_add, add_comm]
/-- Induct using `tprodCoeff` -/
@[elab_as_elim]
protected theorem induction_on' {motive : (⨂[R] i, s i) → Prop} (z : ⨂[R] i, s i)
(tprodCoeff : ∀ (r : R) (f : Π i, s i), motive (tprodCoeff R r f))
(add : ∀ x y, motive x → motive y → motive (x + y)) :
motive z := by
have C0 : motive 0 := by
have h₁ := tprodCoeff 0 0
rwa [zero_tprodCoeff] at h₁
refine AddCon.induction_on z fun x ↦ FreeAddMonoid.recOn x C0 ?_
simp_rw [AddCon.coe_add]
refine fun f y ih ↦ add _ _ ?_ ih
convert tprodCoeff f.1 f.2
section DistribMulAction
variable [Monoid R₁] [DistribMulAction R₁ R] [SMulCommClass R₁ R R]
variable [Monoid R₂] [DistribMulAction R₂ R] [SMulCommClass R₂ R R]
-- Most of the time we want the instance below this one, which is easier for typeclass resolution
-- to find.
instance hasSMul' : SMul R₁ (⨂[R] i, s i) :=
⟨fun r ↦
liftAddHom (fun f : R × Π i, s i ↦ tprodCoeff R (r • f.1) f.2)
(fun r' f i hf ↦ by simp_rw [zero_tprodCoeff' _ f i hf])
(fun f ↦ by simp [zero_tprodCoeff]) (fun r' f i m₁ m₂ ↦ by simp [add_tprodCoeff])
(fun r' r'' f ↦ by simp [add_tprodCoeff', mul_add]) fun z f i r' ↦ by
simp [smul_tprodCoeff, mul_smul_comm]⟩
instance : SMul R (⨂[R] i, s i) :=
PiTensorProduct.hasSMul'
theorem smul_tprodCoeff' (r : R₁) (z : R) (f : Π i, s i) :
r • tprodCoeff R z f = tprodCoeff R (r • z) f := rfl
protected theorem smul_add (r : R₁) (x y : ⨂[R] i, s i) : r • (x + y) = r • x + r • y :=
AddMonoidHom.map_add _ _ _
instance distribMulAction' : DistribMulAction R₁ (⨂[R] i, s i) where
smul := (· • ·)
smul_add _ _ _ := AddMonoidHom.map_add _ _ _
mul_smul r r' x :=
PiTensorProduct.induction_on' x (fun {r'' f} ↦ by simp [smul_tprodCoeff', smul_smul])
fun {x y} ihx ihy ↦ by simp_rw [PiTensorProduct.smul_add, ihx, ihy]
one_smul x :=
PiTensorProduct.induction_on' x (fun {r f} ↦ by rw [smul_tprodCoeff', one_smul])
fun {z y} ihz ihy ↦ by simp_rw [PiTensorProduct.smul_add, ihz, ihy]
smul_zero _ := AddMonoidHom.map_zero _
instance smulCommClass' [SMulCommClass R₁ R₂ R] : SMulCommClass R₁ R₂ (⨂[R] i, s i) :=
⟨fun {r' r''} x ↦
PiTensorProduct.induction_on' x (fun {xr xf} ↦ by simp only [smul_tprodCoeff', smul_comm])
fun {z y} ihz ihy ↦ by simp_rw [PiTensorProduct.smul_add, ihz, ihy]⟩
instance isScalarTower' [SMul R₁ R₂] [IsScalarTower R₁ R₂ R] :
IsScalarTower R₁ R₂ (⨂[R] i, s i) :=
⟨fun {r' r''} x ↦
PiTensorProduct.induction_on' x (fun {xr xf} ↦ by simp only [smul_tprodCoeff', smul_assoc])
fun {z y} ihz ihy ↦ by simp_rw [PiTensorProduct.smul_add, ihz, ihy]⟩
end DistribMulAction
-- Most of the time we want the instance below this one, which is easier for typeclass resolution
-- to find.
instance module' [Semiring R₁] [Module R₁ R] [SMulCommClass R₁ R R] : Module R₁ (⨂[R] i, s i) :=
{ PiTensorProduct.distribMulAction' with
add_smul := fun r r' x ↦
PiTensorProduct.induction_on' x
(fun {r f} ↦ by simp_rw [smul_tprodCoeff', add_smul, add_tprodCoeff'])
fun {x y} ihx ihy ↦ by simp_rw [PiTensorProduct.smul_add, ihx, ihy, add_add_add_comm]
zero_smul := fun x ↦
PiTensorProduct.induction_on' x
(fun {r f} ↦ by simp_rw [smul_tprodCoeff', zero_smul, zero_tprodCoeff])
fun {x y} ihx ihy ↦ by simp_rw [PiTensorProduct.smul_add, ihx, ihy, add_zero] }
-- shortcut instances
instance : Module R (⨂[R] i, s i) :=
PiTensorProduct.module'
instance : SMulCommClass R R (⨂[R] i, s i) :=
PiTensorProduct.smulCommClass'
instance : IsScalarTower R R (⨂[R] i, s i) :=
PiTensorProduct.isScalarTower'
variable (R) in
/-- The canonical `MultilinearMap R s (⨂[R] i, s i)`.
`tprod R fun i => f i` has notation `⨂ₜ[R] i, f i`. -/
def tprod : MultilinearMap R s (⨂[R] i, s i) where
toFun := tprodCoeff R 1
map_update_add' {_ f} i x y := (add_tprodCoeff (1 : R) f i x y).symm
map_update_smul' {_ f} i r x := by
rw [smul_tprodCoeff', ← smul_tprodCoeff (1 : R) _ i, update_idem, update_self]
unsuppress_compilation in
@[inherit_doc tprod]
notation3:100 "⨂ₜ["R"] "(...)", "r:(scoped f => tprod R f) => r
theorem tprod_eq_tprodCoeff_one :
⇑(tprod R : MultilinearMap R s (⨂[R] i, s i)) = tprodCoeff R 1 := rfl
@[simp]
theorem tprodCoeff_eq_smul_tprod (z : R) (f : Π i, s i) : tprodCoeff R z f = z • tprod R f := by
have : z = z • (1 : R) := by simp only [mul_one, Algebra.id.smul_eq_mul]
conv_lhs => rw [this]
rfl
/-- The image of an element `p` of `FreeAddMonoid (R × Π i, s i)` in the `PiTensorProduct` is
equal to the sum of `a • ⨂ₜ[R] i, m i` over all the entries `(a, m)` of `p`.
-/
lemma _root_.FreeAddMonoid.toPiTensorProduct (p : FreeAddMonoid (R × Π i, s i)) :
AddCon.toQuotient (c := addConGen (PiTensorProduct.Eqv R s)) p =
List.sum (List.map (fun x ↦ x.1 • ⨂ₜ[R] i, x.2 i) p.toList) := by
-- TODO: this is defeq abuse: `p` is not a `List`.
match p with
| [] => rw [FreeAddMonoid.toList_nil, List.map_nil, List.sum_nil]; rfl
| x :: ps =>
rw [FreeAddMonoid.toList_cons, List.map_cons, List.sum_cons, ← List.singleton_append,
← toPiTensorProduct ps, ← tprodCoeff_eq_smul_tprod]
rfl
/-- The set of lifts of an element `x` of `⨂[R] i, s i` in `FreeAddMonoid (R × Π i, s i)`. -/
def lifts (x : ⨂[R] i, s i) : Set (FreeAddMonoid (R × Π i, s i)) :=
{p | AddCon.toQuotient (c := addConGen (PiTensorProduct.Eqv R s)) p = x}
/-- An element `p` of `FreeAddMonoid (R × Π i, s i)` lifts an element `x` of `⨂[R] i, s i`
if and only if `x` is equal to the sum of `a • ⨂ₜ[R] i, m i` over all the entries
`(a, m)` of `p`.
-/
lemma mem_lifts_iff (x : ⨂[R] i, s i) (p : FreeAddMonoid (R × Π i, s i)) :
p ∈ lifts x ↔ List.sum (List.map (fun x ↦ x.1 • ⨂ₜ[R] i, x.2 i) p.toList) = x := by
simp only [lifts, Set.mem_setOf_eq, FreeAddMonoid.toPiTensorProduct]
/-- Every element of `⨂[R] i, s i` has a lift in `FreeAddMonoid (R × Π i, s i)`.
-/
lemma nonempty_lifts (x : ⨂[R] i, s i) : Set.Nonempty (lifts x) := by
existsi @Quotient.out _ (addConGen (PiTensorProduct.Eqv R s)).toSetoid x
simp only [lifts, Set.mem_setOf_eq]
rw [← AddCon.quot_mk_eq_coe]
erw [Quot.out_eq]
/-- The empty list lifts the element `0` of `⨂[R] i, s i`.
-/
lemma lifts_zero : 0 ∈ lifts (0 : ⨂[R] i, s i) := by
rw [mem_lifts_iff]; erw [List.map_nil]; rw [List.sum_nil]
/-- If elements `p,q` of `FreeAddMonoid (R × Π i, s i)` lift elements `x,y` of `⨂[R] i, s i`
respectively, then `p + q` lifts `x + y`.
-/
lemma lifts_add {x y : ⨂[R] i, s i} {p q : FreeAddMonoid (R × Π i, s i)}
(hp : p ∈ lifts x) (hq : q ∈ lifts y) : p + q ∈ lifts (x + y) := by
simp only [lifts, Set.mem_setOf_eq, AddCon.coe_add]
rw [hp, hq]
/-- If an element `p` of `FreeAddMonoid (R × Π i, s i)` lifts an element `x` of `⨂[R] i, s i`,
and if `a` is an element of `R`, then the list obtained by multiplying the first entry of each
element of `p` by `a` lifts `a • x`.
-/
lemma lifts_smul {x : ⨂[R] i, s i} {p : FreeAddMonoid (R × Π i, s i)} (h : p ∈ lifts x) (a : R) :
p.map (fun (y : R × Π i, s i) ↦ (a * y.1, y.2)) ∈ lifts (a • x) := by
rw [mem_lifts_iff] at h ⊢
rw [← h]
simp [Function.comp_def, mul_smul, List.smul_sum]
/-- Induct using scaled versions of `PiTensorProduct.tprod`. -/
@[elab_as_elim]
protected theorem induction_on {motive : (⨂[R] i, s i) → Prop} (z : ⨂[R] i, s i)
(smul_tprod : ∀ (r : R) (f : Π i, s i), motive (r • tprod R f))
(add : ∀ x y, motive x → motive y → motive (x + y)) :
motive z := by
simp_rw [← tprodCoeff_eq_smul_tprod] at smul_tprod
exact PiTensorProduct.induction_on' z smul_tprod add
@[ext]
theorem ext {φ₁ φ₂ : (⨂[R] i, s i) →ₗ[R] E}
(H : φ₁.compMultilinearMap (tprod R) = φ₂.compMultilinearMap (tprod R)) : φ₁ = φ₂ := by
refine LinearMap.ext ?_
refine fun z ↦
PiTensorProduct.induction_on' z ?_ fun {x y} hx hy ↦ by rw [φ₁.map_add, φ₂.map_add, hx, hy]
· intro r f
rw [tprodCoeff_eq_smul_tprod, φ₁.map_smul, φ₂.map_smul]
apply congr_arg
exact MultilinearMap.congr_fun H f
/-- The pure tensors (i.e. the elements of the image of `PiTensorProduct.tprod`) span
the tensor product. -/
theorem span_tprod_eq_top :
Submodule.span R (Set.range (tprod R)) = (⊤ : Submodule R (⨂[R] i, s i)) :=
Submodule.eq_top_iff'.mpr fun t ↦ t.induction_on
(fun _ _ ↦ Submodule.smul_mem _ _
(Submodule.subset_span (by simp only [Set.mem_range, exists_apply_eq_apply])))
(fun _ _ hx hy ↦ Submodule.add_mem _ hx hy)
end Module
section Multilinear
open MultilinearMap
variable {s}
section lift
/-- Auxiliary function to constructing a linear map `(⨂[R] i, s i) → E` given a
`MultilinearMap R s E` with the property that its composition with the canonical
`MultilinearMap R s (⨂[R] i, s i)` is the given multilinear map. -/
def liftAux (φ : MultilinearMap R s E) : (⨂[R] i, s i) →+ E :=
liftAddHom (fun p : R × Π i, s i ↦ p.1 • φ p.2)
(fun z f i hf ↦ by simp_rw [map_coord_zero φ i hf, smul_zero])
(fun f ↦ by simp_rw [zero_smul])
(fun z f i m₁ m₂ ↦ by simp_rw [← smul_add, φ.map_update_add])
(fun z₁ z₂ f ↦ by rw [← add_smul])
fun z f i r ↦ by simp [φ.map_update_smul, smul_smul, mul_comm]
theorem liftAux_tprod (φ : MultilinearMap R s E) (f : Π i, s i) : liftAux φ (tprod R f) = φ f := by
simp only [liftAux, liftAddHom, tprod_eq_tprodCoeff_one, tprodCoeff, AddCon.coe_mk']
-- The end of this proof was very different before https://github.com/leanprover/lean4/pull/2644:
-- rw [FreeAddMonoid.of, FreeAddMonoid.ofList, Equiv.refl_apply, AddCon.lift_coe]
-- dsimp [FreeAddMonoid.lift, FreeAddMonoid.sumAux]
-- show _ • _ = _
-- rw [one_smul]
erw [AddCon.lift_coe]
rw [FreeAddMonoid.of]
dsimp [FreeAddMonoid.ofList]
rw [← one_smul R (φ f)]
erw [Equiv.refl_apply]
convert one_smul R (φ f)
simp
theorem liftAux_tprodCoeff (φ : MultilinearMap R s E) (z : R) (f : Π i, s i) :
liftAux φ (tprodCoeff R z f) = z • φ f := rfl
theorem liftAux.smul {φ : MultilinearMap R s E} (r : R) (x : ⨂[R] i, s i) :
liftAux φ (r • x) = r • liftAux φ x := by
refine PiTensorProduct.induction_on' x ?_ ?_
· intro z f
rw [smul_tprodCoeff' r z f, liftAux_tprodCoeff, liftAux_tprodCoeff, smul_assoc]
· intro z y ihz ihy
rw [smul_add, (liftAux φ).map_add, ihz, ihy, (liftAux φ).map_add, smul_add]
/-- Constructing a linear map `(⨂[R] i, s i) → E` given a `MultilinearMap R s E` with the
property that its composition with the canonical `MultilinearMap R s E` is
the given multilinear map `φ`. -/
def lift : MultilinearMap R s E ≃ₗ[R] (⨂[R] i, s i) →ₗ[R] E where
toFun φ := { liftAux φ with map_smul' := liftAux.smul }
invFun φ' := φ'.compMultilinearMap (tprod R)
left_inv φ := by
ext
simp [liftAux_tprod, LinearMap.compMultilinearMap]
right_inv φ := by
ext
simp [liftAux_tprod]
map_add' φ₁ φ₂ := by
ext
simp [liftAux_tprod]
map_smul' r φ₂ := by
ext
simp [liftAux_tprod]
variable {φ : MultilinearMap R s E}
@[simp]
theorem lift.tprod (f : Π i, s i) : lift φ (tprod R f) = φ f :=
liftAux_tprod φ f
theorem lift.unique' {φ' : (⨂[R] i, s i) →ₗ[R] E}
(H : φ'.compMultilinearMap (PiTensorProduct.tprod R) = φ) : φ' = lift φ :=
ext <| H.symm ▸ (lift.symm_apply_apply φ).symm
theorem lift.unique {φ' : (⨂[R] i, s i) →ₗ[R] E} (H : ∀ f, φ' (PiTensorProduct.tprod R f) = φ f) :
φ' = lift φ :=
lift.unique' (MultilinearMap.ext H)
@[simp]
theorem lift_symm (φ' : (⨂[R] i, s i) →ₗ[R] E) : lift.symm φ' = φ'.compMultilinearMap (tprod R) :=
rfl
@[simp]
theorem lift_tprod : lift (tprod R : MultilinearMap R s _) = LinearMap.id :=
Eq.symm <| lift.unique' rfl
end lift
section map
variable {t t' : ι → Type*}
variable [∀ i, AddCommMonoid (t i)] [∀ i, Module R (t i)]
variable [∀ i, AddCommMonoid (t' i)] [∀ i, Module R (t' i)]
variable (g : Π i, t i →ₗ[R] t' i) (f : Π i, s i →ₗ[R] t i)
/--
Let `sᵢ` and `tᵢ` be two families of `R`-modules.
Let `f` be a family of `R`-linear maps between `sᵢ` and `tᵢ`, i.e. `f : Πᵢ sᵢ → tᵢ`,
then there is an induced map `⨂ᵢ sᵢ → ⨂ᵢ tᵢ` by `⨂ aᵢ ↦ ⨂ fᵢ aᵢ`.
This is `TensorProduct.map` for an arbitrary family of modules.
-/
def map : (⨂[R] i, s i) →ₗ[R] ⨂[R] i, t i :=
lift <| (tprod R).compLinearMap f
@[simp] lemma map_tprod (x : Π i, s i) :
map f (tprod R x) = tprod R fun i ↦ f i (x i) :=
lift.tprod _
-- No lemmas about associativity, because we don't have associativity of `PiTensorProduct` yet.
theorem map_range_eq_span_tprod :
LinearMap.range (map f) =
Submodule.span R {t | ∃ (m : Π i, s i), tprod R (fun i ↦ f i (m i)) = t} := by
rw [← Submodule.map_top, ← span_tprod_eq_top, Submodule.map_span, ← Set.range_comp]
apply congrArg; ext x
simp only [Set.mem_range, comp_apply, map_tprod, Set.mem_setOf_eq]
/-- Given submodules `p i ⊆ s i`, this is the natural map: `⨂[R] i, p i → ⨂[R] i, s i`.
This is `TensorProduct.mapIncl` for an arbitrary family of modules.
-/
@[simp]
def mapIncl (p : Π i, Submodule R (s i)) : (⨂[R] i, p i) →ₗ[R] ⨂[R] i, s i :=
map fun (i : ι) ↦ (p i).subtype
theorem map_comp : map (fun (i : ι) ↦ g i ∘ₗ f i) = map g ∘ₗ map f := by
ext
simp only [LinearMap.compMultilinearMap_apply, map_tprod, LinearMap.coe_comp, Function.comp_apply]
theorem lift_comp_map (h : MultilinearMap R t E) :
lift h ∘ₗ map f = lift (h.compLinearMap f) := by
ext
simp only [LinearMap.compMultilinearMap_apply, LinearMap.coe_comp, Function.comp_apply,
map_tprod, lift.tprod, MultilinearMap.compLinearMap_apply]
attribute [local ext high] ext
@[simp]
theorem map_id : map (fun i ↦ (LinearMap.id : s i →ₗ[R] s i)) = .id := by
ext
simp only [LinearMap.compMultilinearMap_apply, map_tprod, LinearMap.id_coe, id_eq]
@[simp]
protected theorem map_one : map (fun (i : ι) ↦ (1 : s i →ₗ[R] s i)) = 1 :=
map_id
protected theorem map_mul (f₁ f₂ : Π i, s i →ₗ[R] s i) :
map (fun i ↦ f₁ i * f₂ i) = map f₁ * map f₂ :=
map_comp f₁ f₂
/-- Upgrading `PiTensorProduct.map` to a `MonoidHom` when `s = t`. -/
@[simps]
def mapMonoidHom : (Π i, s i →ₗ[R] s i) →* ((⨂[R] i, s i) →ₗ[R] ⨂[R] i, s i) where
toFun := map
map_one' := PiTensorProduct.map_one
map_mul' := PiTensorProduct.map_mul
@[simp]
protected theorem map_pow (f : Π i, s i →ₗ[R] s i) (n : ℕ) :
map (f ^ n) = map f ^ n := MonoidHom.map_pow mapMonoidHom _ _
open Function in
private theorem map_add_smul_aux [DecidableEq ι] (i : ι) (x : Π i, s i) (u : s i →ₗ[R] t i) :
(fun j ↦ update f i u j (x j)) = update (fun j ↦ (f j) (x j)) i (u (x i)) := by
ext j
exact apply_update (fun i F => F (x i)) f i u j
open Function in
protected theorem map_update_add [DecidableEq ι] (i : ι) (u v : s i →ₗ[R] t i) :
map (update f i (u + v)) = map (update f i u) + map (update f i v) := by
ext x
simp only [LinearMap.compMultilinearMap_apply, map_tprod, map_add_smul_aux, LinearMap.add_apply,
MultilinearMap.map_update_add]
@[deprecated (since := "2024-11-03")] protected alias map_add := PiTensorProduct.map_update_add
open Function in
protected theorem map_update_smul [DecidableEq ι] (i : ι) (c : R) (u : s i →ₗ[R] t i) :
map (update f i (c • u)) = c • map (update f i u) := by
ext x
simp only [LinearMap.compMultilinearMap_apply, map_tprod, map_add_smul_aux, LinearMap.smul_apply,
MultilinearMap.map_update_smul]
@[deprecated (since := "2024-11-03")] protected alias map_smul := PiTensorProduct.map_update_smul
variable (R s t)
/-- The tensor of a family of linear maps from `sᵢ` to `tᵢ`, as a multilinear map of
the family.
-/
@[simps]
noncomputable def mapMultilinear :
MultilinearMap R (fun (i : ι) ↦ s i →ₗ[R] t i) ((⨂[R] i, s i) →ₗ[R] ⨂[R] i, t i) where
toFun := map
map_update_smul' _ _ _ _ := PiTensorProduct.map_update_smul _ _ _ _
map_update_add' _ _ _ _ := PiTensorProduct.map_update_add _ _ _ _
variable {R s t}
/--
Let `sᵢ` and `tᵢ` be families of `R`-modules.
Then there is an `R`-linear map between `⨂ᵢ Hom(sᵢ, tᵢ)` and `Hom(⨂ᵢ sᵢ, ⨂ tᵢ)` defined by
`⨂ᵢ fᵢ ↦ ⨂ᵢ aᵢ ↦ ⨂ᵢ fᵢ aᵢ`.
This is `TensorProduct.homTensorHomMap` for an arbitrary family of modules.
Note that `PiTensorProduct.piTensorHomMap (tprod R f)` is equal to `PiTensorProduct.map f`.
-/
def piTensorHomMap : (⨂[R] i, s i →ₗ[R] t i) →ₗ[R] (⨂[R] i, s i) →ₗ[R] ⨂[R] i, t i :=
lift.toLinearMap ∘ₗ lift (MultilinearMap.piLinearMap <| tprod R)
@[simp] lemma piTensorHomMap_tprod_tprod (f : Π i, s i →ₗ[R] t i) (x : Π i, s i) :
piTensorHomMap (tprod R f) (tprod R x) = tprod R fun i ↦ f i (x i) := by
simp [piTensorHomMap]
lemma piTensorHomMap_tprod_eq_map (f : Π i, s i →ₗ[R] t i) :
piTensorHomMap (tprod R f) = map f := by
ext; simp
/-- If `s i` and `t i` are linearly equivalent for every `i` in `ι`, then `⨂[R] i, s i` and
`⨂[R] i, t i` are linearly equivalent.
This is the n-ary version of `TensorProduct.congr`
-/
noncomputable def congr (f : Π i, s i ≃ₗ[R] t i) :
(⨂[R] i, s i) ≃ₗ[R] ⨂[R] i, t i :=
.ofLinear
(map (fun i ↦ f i))
(map (fun i ↦ (f i).symm))
(by ext; simp)
(by ext; simp)
@[simp]
theorem congr_tprod (f : Π i, s i ≃ₗ[R] t i) (m : Π i, s i) :
congr f (tprod R m) = tprod R (fun (i : ι) ↦ (f i) (m i)) := by
simp only [congr, LinearEquiv.ofLinear_apply, map_tprod, LinearEquiv.coe_coe]
@[simp]
theorem congr_symm_tprod (f : Π i, s i ≃ₗ[R] t i) (p : Π i, t i) :
(congr f).symm (tprod R p) = tprod R (fun (i : ι) ↦ (f i).symm (p i)) := by
simp only [congr, LinearEquiv.ofLinear_symm_apply, map_tprod, LinearEquiv.coe_coe]
/--
Let `sᵢ`, `tᵢ` and `t'ᵢ` be families of `R`-modules, then `f : Πᵢ sᵢ → tᵢ → t'ᵢ` induces an
element of `Hom(⨂ᵢ sᵢ, Hom(⨂ tᵢ, ⨂ᵢ t'ᵢ))` defined by `⨂ᵢ aᵢ ↦ ⨂ᵢ bᵢ ↦ ⨂ᵢ fᵢ aᵢ bᵢ`.
This is `PiTensorProduct.map` for two arbitrary families of modules.
This is `TensorProduct.map₂` for families of modules.
-/
def map₂ (f : Π i, s i →ₗ[R] t i →ₗ[R] t' i) :
(⨂[R] i, s i) →ₗ[R] (⨂[R] i, t i) →ₗ[R] ⨂[R] i, t' i :=
lift <| LinearMap.compMultilinearMap piTensorHomMap <| (tprod R).compLinearMap f
lemma map₂_tprod_tprod (f : Π i, s i →ₗ[R] t i →ₗ[R] t' i) (x : Π i, s i) (y : Π i, t i) :
map₂ f (tprod R x) (tprod R y) = tprod R fun i ↦ f i (x i) (y i) := by
simp [map₂]
/--
Let `sᵢ`, `tᵢ` and `t'ᵢ` be families of `R`-modules.
Then there is a function from `⨂ᵢ Hom(sᵢ, Hom(tᵢ, t'ᵢ))` to `Hom(⨂ᵢ sᵢ, Hom(⨂ tᵢ, ⨂ᵢ t'ᵢ))`
defined by `⨂ᵢ fᵢ ↦ ⨂ᵢ aᵢ ↦ ⨂ᵢ bᵢ ↦ ⨂ᵢ fᵢ aᵢ bᵢ`. -/
def piTensorHomMapFun₂ : (⨂[R] i, s i →ₗ[R] t i →ₗ[R] t' i) →
(⨂[R] i, s i) →ₗ[R] (⨂[R] i, t i) →ₗ[R] (⨂[R] i, t' i) :=
fun φ => lift <| LinearMap.compMultilinearMap piTensorHomMap <|
(lift <| MultilinearMap.piLinearMap <| tprod R) φ
theorem piTensorHomMapFun₂_add (φ ψ : ⨂[R] i, s i →ₗ[R] t i →ₗ[R] t' i) :
piTensorHomMapFun₂ (φ + ψ) = piTensorHomMapFun₂ φ + piTensorHomMapFun₂ ψ := by
dsimp [piTensorHomMapFun₂]; ext; simp only [map_add, LinearMap.compMultilinearMap_apply,
lift.tprod, add_apply, LinearMap.add_apply]
theorem piTensorHomMapFun₂_smul (r : R) (φ : ⨂[R] i, s i →ₗ[R] t i →ₗ[R] t' i) :
piTensorHomMapFun₂ (r • φ) = r • piTensorHomMapFun₂ φ := by
dsimp [piTensorHomMapFun₂]; ext; simp only [map_smul, LinearMap.compMultilinearMap_apply,
lift.tprod, smul_apply, LinearMap.smul_apply]
/--
Let `sᵢ`, `tᵢ` and `t'ᵢ` be families of `R`-modules.
Then there is an linear map from `⨂ᵢ Hom(sᵢ, Hom(tᵢ, t'ᵢ))` to `Hom(⨂ᵢ sᵢ, Hom(⨂ tᵢ, ⨂ᵢ t'ᵢ))`
defined by `⨂ᵢ fᵢ ↦ ⨂ᵢ aᵢ ↦ ⨂ᵢ bᵢ ↦ ⨂ᵢ fᵢ aᵢ bᵢ`.
This is `TensorProduct.homTensorHomMap` for two arbitrary families of modules.
-/
def piTensorHomMap₂ : (⨂[R] i, s i →ₗ[R] t i →ₗ[R] t' i) →ₗ[R]
(⨂[R] i, s i) →ₗ[R] (⨂[R] i, t i) →ₗ[R] (⨂[R] i, t' i) where
toFun := piTensorHomMapFun₂
map_add' x y := piTensorHomMapFun₂_add x y
map_smul' x y := piTensorHomMapFun₂_smul x y
@[simp] lemma piTensorHomMap₂_tprod_tprod_tprod
(f : ∀ i, s i →ₗ[R] t i →ₗ[R] t' i) (a : ∀ i, s i) (b : ∀ i, t i) :
piTensorHomMap₂ (tprod R f) (tprod R a) (tprod R b) = tprod R (fun i ↦ f i (a i) (b i)) := by
simp [piTensorHomMapFun₂, piTensorHomMap₂]
end map
section
variable (R M)
variable (s) in
/-- Re-index the components of the tensor power by `e`. -/
def reindex (e : ι ≃ ι₂) : (⨂[R] i : ι, s i) ≃ₗ[R] ⨂[R] i : ι₂, s (e.symm i) :=
let f := domDomCongrLinearEquiv' R R s (⨂[R] (i : ι₂), s (e.symm i)) e
let g := domDomCongrLinearEquiv' R R s (⨂[R] (i : ι), s i) e
#adaptation_note /-- v4.7.0-rc1
An alternative to the last two proofs would be `aesop (simp_config := {zetaDelta := true})`
or a wrapper macro to that effect. -/
LinearEquiv.ofLinear (lift <| f.symm <| tprod R) (lift <| g <| tprod R)
(by aesop (add norm simp [f, g]))
(by aesop (add norm simp [f, g]))
end
@[simp]
theorem reindex_tprod (e : ι ≃ ι₂) (f : Π i, s i) :
reindex R s e (tprod R f) = tprod R fun i ↦ f (e.symm i) := by
dsimp [reindex]
exact liftAux_tprod _ f
@[simp]
theorem reindex_comp_tprod (e : ι ≃ ι₂) :
(reindex R s e).compMultilinearMap (tprod R) =
(domDomCongrLinearEquiv' R R s _ e).symm (tprod R) :=
MultilinearMap.ext <| reindex_tprod e
theorem lift_comp_reindex (e : ι ≃ ι₂) (φ : MultilinearMap R (fun i ↦ s (e.symm i)) E) :
lift φ ∘ₗ (reindex R s e) = lift ((domDomCongrLinearEquiv' R R s _ e).symm φ) := by
ext; simp [reindex]
@[simp]
theorem lift_comp_reindex_symm (e : ι ≃ ι₂) (φ : MultilinearMap R s E) :
lift φ ∘ₗ (reindex R s e).symm = lift (domDomCongrLinearEquiv' R R s _ e φ) := by
ext; simp [reindex]
theorem lift_reindex
(e : ι ≃ ι₂) (φ : MultilinearMap R (fun i ↦ s (e.symm i)) E) (x : ⨂[R] i, s i) :
lift φ (reindex R s e x) = lift ((domDomCongrLinearEquiv' R R s _ e).symm φ) x :=
LinearMap.congr_fun (lift_comp_reindex e φ) x
@[simp]
theorem lift_reindex_symm
(e : ι ≃ ι₂) (φ : MultilinearMap R s E) (x : ⨂[R] i, s (e.symm i)) :
lift φ (reindex R s e |>.symm x) = lift (domDomCongrLinearEquiv' R R s _ e φ) x :=
LinearMap.congr_fun (lift_comp_reindex_symm e φ) x
@[simp]
theorem reindex_trans (e : ι ≃ ι₂) (e' : ι₂ ≃ ι₃) :
(reindex R s e).trans (reindex R _ e') = reindex R s (e.trans e') := by
apply LinearEquiv.toLinearMap_injective
ext f
simp only [LinearEquiv.trans_apply, LinearEquiv.coe_coe, reindex_tprod,
LinearMap.coe_compMultilinearMap, Function.comp_apply, MultilinearMap.domDomCongr_apply,
reindex_comp_tprod]
congr
theorem reindex_reindex (e : ι ≃ ι₂) (e' : ι₂ ≃ ι₃) (x : ⨂[R] i, s i) :
reindex R _ e' (reindex R s e x) = reindex R s (e.trans e') x :=
LinearEquiv.congr_fun (reindex_trans e e' : _ = reindex R s (e.trans e')) x
/-- This lemma is impractical to state in the dependent case. -/
@[simp]
| Mathlib/LinearAlgebra/PiTensorProduct.lean | 747 | 749 | theorem reindex_symm (e : ι ≃ ι₂) :
(reindex R (fun _ ↦ M) e).symm = reindex R (fun _ ↦ M) e.symm := by | ext x |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.