Context
stringlengths
227
76.5k
target
stringlengths
0
11.6k
file_name
stringlengths
21
79
start
int64
14
3.67k
end
int64
16
3.69k
/- Copyright (c) 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] 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 _ · intro x rw [Set.mem_smul_set, Seminorm.mem_ball_zero] refine fun hx => ⟹k⁻¹ • x, ?_, ?_⟩ · rwa [Seminorm.mem_ball_zero, map_smul_eq_mul, norm_inv, ← mul_lt_mul_left <| norm_pos_iff.mpr hk, ← mul_assoc, ← div_eq_mul_inv ‖k‖ ‖k‖, div_self (ne_of_gt <| norm_pos_iff.mpr hk), one_mul] rw [← smul_assoc, smul_eq_mul, ← div_eq_mul_inv, div_self hk, one_smul] theorem smul_ball_zero {p : Seminorm 𝕜 E} {k : 𝕜} {r : ℝ} (hk : k ≠ 0) : k • p.ball 0 r = p.ball 0 (‖k‖ * r) := by ext rw [mem_smul_set_iff_inv_smul_mem₀ hk, p.mem_ball_zero, p.mem_ball_zero, map_smul_eq_mul, norm_inv, ← div_eq_inv_mul, div_lt_iff₀ (norm_pos_iff.2 hk), mul_comm] theorem smul_closedBall_subset {p : Seminorm 𝕜 E} {k : 𝕜} {r : ℝ} : k • p.closedBall 0 r ⊆ p.closedBall 0 (‖k‖ * r) := by rintro x ⟹y, hy, h⟩ rw [Seminorm.mem_closedBall_zero, ← h, map_smul_eq_mul] rw [Seminorm.mem_closedBall_zero] at hy gcongr theorem smul_closedBall_zero {p : Seminorm 𝕜 E} {k : 𝕜} {r : ℝ} (hk : 0 < ‖k‖) : k • p.closedBall 0 r = p.closedBall 0 (‖k‖ * r) := by refine subset_antisymm smul_closedBall_subset ?_ intro x rw [Set.mem_smul_set, Seminorm.mem_closedBall_zero] refine fun hx => ⟹k⁻¹ • x, ?_, ?_⟩ · rwa [Seminorm.mem_closedBall_zero, map_smul_eq_mul, norm_inv, ← mul_le_mul_left hk, ← mul_assoc, ← div_eq_mul_inv ‖k‖ ‖k‖, div_self (ne_of_gt hk), one_mul] rw [← smul_assoc, smul_eq_mul, ← div_eq_mul_inv, div_self (norm_pos_iff.mp hk), one_smul] theorem ball_zero_absorbs_ball_zero (p : Seminorm 𝕜 E) {r₁ r₂ : ℝ} (hr₁ : 0 < r₁) : Absorbs 𝕜 (p.ball 0 r₁) (p.ball 0 r₂) := by rcases exists_pos_lt_mul hr₁ r₂ with ⟹r, hr₀, hr⟩ refine .of_norm ⟹r, fun a ha x hx => ?_⟩ rw [smul_ball_zero (norm_pos_iff.1 <| hr₀.trans_le ha), p.mem_ball_zero] rw [p.mem_ball_zero] at hx exact hx.trans (hr.trans_le <| by gcongr) /-- Seminorm-balls at the origin are absorbent. -/ protected theorem absorbent_ball_zero (hr : 0 < r) : Absorbent 𝕜 (ball p (0 : E) r) := absorbent_iff_forall_absorbs_singleton.2 fun _ => (p.ball_zero_absorbs_ball_zero hr).mono_right <| singleton_subset_iff.2 <| p.mem_ball_zero.2 <| lt_add_one _ /-- Closed seminorm-balls at the origin are absorbent. -/ protected theorem absorbent_closedBall_zero (hr : 0 < r) : Absorbent 𝕜 (closedBall p (0 : E) r) := (p.absorbent_ball_zero hr).mono (p.ball_subset_closedBall _ _) /-- Seminorm-balls containing the origin are absorbent. -/ protected theorem absorbent_ball (hpr : p x < r) : Absorbent 𝕜 (ball p x r) := by refine (p.absorbent_ball_zero <| sub_pos.2 hpr).mono fun y hy => ?_ rw [p.mem_ball_zero] at hy exact p.mem_ball.2 ((map_sub_le_add p _ _).trans_lt <| add_lt_of_lt_sub_right hy) /-- Seminorm-balls containing the origin are absorbent. -/ protected theorem absorbent_closedBall (hpr : p x < r) : Absorbent 𝕜 (closedBall p x r) := by refine (p.absorbent_closedBall_zero <| sub_pos.2 hpr).mono fun y hy => ?_ rw [p.mem_closedBall_zero] at hy exact p.mem_closedBall.2 ((map_sub_le_add p _ _).trans <| add_le_of_le_sub_right hy) @[simp] theorem smul_ball_preimage (p : Seminorm 𝕜 E) (y : E) (r : ℝ) (a : 𝕜) (ha : a ≠ 0) : (a • ·) ⁻¹' p.ball y r = p.ball (a⁻¹ • y) (r / ‖a‖) := Set.ext fun _ => by rw [mem_preimage, mem_ball, mem_ball, lt_div_iff₀ (norm_pos_iff.mpr ha), mul_comm, ← map_smul_eq_mul p, smul_sub, smul_inv_smul₀ ha] @[simp] theorem smul_closedBall_preimage (p : Seminorm 𝕜 E) (y : E) (r : ℝ) (a : 𝕜) (ha : a ≠ 0) : (a • ·) ⁻¹' p.closedBall y r = p.closedBall (a⁻¹ • y) (r / ‖a‖) := Set.ext fun _ => by rw [mem_preimage, mem_closedBall, mem_closedBall, le_div_iff₀ (norm_pos_iff.mpr ha), mul_comm, ← map_smul_eq_mul p, smul_sub, smul_inv_smul₀ ha] end NormedField section Convex variable [NormedField 𝕜] [AddCommGroup E] [NormedSpace ℝ 𝕜] [Module 𝕜 E] section SMul variable [SMul ℝ E] [IsScalarTower ℝ 𝕜 E] (p : Seminorm 𝕜 E) /-- A seminorm is convex. Also see `convexOn_norm`. -/ protected theorem convexOn : ConvexOn ℝ univ p := by refine ⟹convex_univ, fun x _ y _ a b ha hb _ => ?_⟩ calc p (a • x + b • y) ≀ p (a • x) + p (b • y) := map_add_le_add p _ _ _ = ‖a • (1 : 𝕜)‖ * p x + ‖b • (1 : 𝕜)‖ * p y := by rw [← map_smul_eq_mul p, ← map_smul_eq_mul p, smul_one_smul, smul_one_smul] _ = a * p x + b * p y := by rw [norm_smul, norm_smul, norm_one, mul_one, mul_one, Real.norm_of_nonneg ha, Real.norm_of_nonneg hb] end SMul section Module variable [Module ℝ E] [IsScalarTower ℝ 𝕜 E] (p : Seminorm 𝕜 E) (x : E) (r : ℝ) /-- Seminorm-balls are convex. -/ theorem convex_ball : Convex ℝ (ball p x r) := by convert (p.convexOn.translate_left (-x)).convex_lt r ext y rw [preimage_univ, sep_univ, p.mem_ball, sub_eq_add_neg] rfl /-- Closed seminorm-balls are convex. -/ theorem convex_closedBall : Convex ℝ (closedBall p x r) := by rw [closedBall_eq_biInter_ball] exact convex_iInter₂ fun _ _ => convex_ball _ _ _ end Module end Convex section RestrictScalars variable (𝕜) {𝕜' : Type*} [NormedField 𝕜] [SeminormedRing 𝕜'] [NormedAlgebra 𝕜 𝕜'] [NormOneClass 𝕜'] [AddCommGroup E] [Module 𝕜' E] [SMul 𝕜 E] [IsScalarTower 𝕜 𝕜' E] /-- Reinterpret a seminorm over a field `𝕜'` as a seminorm over a smaller field `𝕜`. This will typically be used with `RCLike 𝕜'` and `𝕜 = ℝ`. -/ protected def restrictScalars (p : Seminorm 𝕜' E) : Seminorm 𝕜 E := { p with smul' := fun a x => by rw [← smul_one_smul 𝕜' a x, p.smul', norm_smul, norm_one, mul_one] } @[simp] theorem coe_restrictScalars (p : Seminorm 𝕜' E) : (p.restrictScalars 𝕜 : E → ℝ) = p := rfl @[simp] theorem restrictScalars_ball (p : Seminorm 𝕜' E) : (p.restrictScalars 𝕜).ball = p.ball := rfl @[simp] theorem restrictScalars_closedBall (p : Seminorm 𝕜' E) : (p.restrictScalars 𝕜).closedBall = p.closedBall := rfl end RestrictScalars /-! ### Continuity criterions for seminorms -/ section Continuity variable [NontriviallyNormedField 𝕜] [SeminormedRing 𝕝] [AddCommGroup E] [Module 𝕜 E] variable [Module 𝕝 E] /-- A seminorm is continuous at `0` if `p.closedBall 0 r ∈ 𝓝 0` for *all* `r > 0`. Over a `NontriviallyNormedField` it is actually enough to check that this is true for *some* `r`, see `Seminorm.continuousAt_zero'`. -/ theorem continuousAt_zero_of_forall' [TopologicalSpace E] {p : Seminorm 𝕝 E} (hp : ∀ r > 0, p.closedBall 0 r ∈ (𝓝 0 : Filter E)) : ContinuousAt p 0 := by simp_rw [Seminorm.closedBall_zero_eq_preimage_closedBall] at hp rwa [ContinuousAt, Metric.nhds_basis_closedBall.tendsto_right_iff, map_zero] theorem continuousAt_zero' [TopologicalSpace E] [ContinuousConstSMul 𝕜 E] {p : Seminorm 𝕜 E} {r : ℝ} (hp : p.closedBall 0 r ∈ (𝓝 0 : Filter E)) : ContinuousAt p 0 := by refine continuousAt_zero_of_forall' fun ε hε ↩ ?_ obtain ⟹k, hk₀, hk⟩ : ∃ k : 𝕜, 0 < ‖k‖ ∧ ‖k‖ * r < ε := by rcases le_or_lt r 0 with hr | hr · use 1; simpa using hr.trans_lt hε · simpa [lt_div_iff₀ hr] using exists_norm_lt 𝕜 (div_pos hε hr) rw [← set_smul_mem_nhds_zero_iff (norm_pos_iff.1 hk₀), smul_closedBall_zero hk₀] at hp exact mem_of_superset hp <| p.closedBall_mono hk.le /-- A seminorm is continuous at `0` if `p.ball 0 r ∈ 𝓝 0` for *all* `r > 0`. Over a `NontriviallyNormedField` it is actually enough to check that this is true for *some* `r`, see `Seminorm.continuousAt_zero'`. -/ theorem continuousAt_zero_of_forall [TopologicalSpace E] {p : Seminorm 𝕝 E} (hp : ∀ r > 0, p.ball 0 r ∈ (𝓝 0 : Filter E)) : ContinuousAt p 0 := continuousAt_zero_of_forall' (fun r hr ↩ Filter.mem_of_superset (hp r hr) <| p.ball_subset_closedBall _ _) theorem continuousAt_zero [TopologicalSpace E] [ContinuousConstSMul 𝕜 E] {p : Seminorm 𝕜 E} {r : ℝ} (hp : p.ball 0 r ∈ (𝓝 0 : Filter E)) : ContinuousAt p 0 := continuousAt_zero' (Filter.mem_of_superset hp <| p.ball_subset_closedBall _ _) protected theorem uniformContinuous_of_continuousAt_zero [UniformSpace E] [IsUniformAddGroup E] {p : Seminorm 𝕝 E} (hp : ContinuousAt p 0) : UniformContinuous p := by have hp : Filter.Tendsto p (𝓝 0) (𝓝 0) := map_zero p ▾ hp rw [UniformContinuous, uniformity_eq_comap_nhds_zero_swapped, Metric.uniformity_eq_comap_nhds_zero, Filter.tendsto_comap_iff] exact tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds (hp.comp Filter.tendsto_comap) (fun xy => dist_nonneg) fun xy => p.norm_sub_map_le_sub _ _ protected theorem continuous_of_continuousAt_zero [TopologicalSpace E] [IsTopologicalAddGroup E] {p : Seminorm 𝕝 E} (hp : ContinuousAt p 0) : Continuous p := by letI := IsTopologicalAddGroup.toUniformSpace E haveI : IsUniformAddGroup E := isUniformAddGroup_of_addCommGroup exact (Seminorm.uniformContinuous_of_continuousAt_zero hp).continuous /-- A seminorm is uniformly continuous if `p.ball 0 r ∈ 𝓝 0` for *all* `r > 0`. Over a `NontriviallyNormedField` it is actually enough to check that this is true for *some* `r`, see `Seminorm.uniformContinuous`. -/
protected theorem uniformContinuous_of_forall [UniformSpace E] [IsUniformAddGroup E] {p : Seminorm 𝕝 E} (hp : ∀ r > 0, p.ball 0 r ∈ (𝓝 0 : Filter E)) : UniformContinuous p := Seminorm.uniformContinuous_of_continuousAt_zero (continuousAt_zero_of_forall hp)
Mathlib/Analysis/Seminorm.lean
1,097
1,101
/- 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, Mario Carneiro -/ import Mathlib.Algebra.Order.Ring.Defs import Mathlib.Algebra.Order.Ring.Unbundled.Rat /-! # The rational numbers form a linear ordered field This file constructs the order on `ℚ` and proves that `ℚ` is a discrete, linearly ordered commutative ring. `ℚ` is in fact a linearly ordered field, but this fact is located in `Data.Rat.Field` instead of here because we need the order on `ℚ` to define `ℚ≥0`, which we itself need to define `Field`. ## Tags rat, rationals, field, ℚ, numerator, denominator, num, denom, order, ordering -/ assert_not_exists Field Finset Set.Icc GaloisConnection namespace Rat instance instIsOrderedAddMonoid : IsOrderedAddMonoid ℚ where add_le_add_left := fun _ _ ab _ => Rat.add_le_add_left.2 ab instance instZeroLEOneClass : ZeroLEOneClass ℚ where zero_le_one := by decide instance instIsStrictOrderedRing : IsStrictOrderedRing ℚ := .of_mul_pos fun _ _ ha hb ↩ (Rat.mul_nonneg ha.le hb.le).lt_of_ne' (mul_ne_zero ha.ne' hb.ne') end Rat
Mathlib/Algebra/Order/Ring/Rat.lean
252
261
/- 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.RingTheory.WittVector.StructurePolynomial /-! # Witt vectors In this file we define the type of `p`-typical Witt vectors and ring operations on it. The ring axioms are verified in `Mathlib/RingTheory/WittVector/Basic.lean`. For a fixed commutative ring `R` and prime `p`, a Witt vector `x : 𝕎 R` is an infinite sequence `ℕ → R` of elements of `R`. However, the ring operations `+` and `*` are not defined in the obvious component-wise way. Instead, these operations are defined via certain polynomials using the machinery in `Mathlib/RingTheory/WittVector/StructurePolynomial.lean`. The `n`th value of the sum of two Witt vectors can depend on the `0`-th through `n`th values of the summands. This effectively simulates a “carrying” operation. ## Main definitions * `WittVector p R`: the type of `p`-typical Witt vectors with coefficients in `R`. * `WittVector.coeff x n`: projects the `n`th value of the Witt vector `x`. ## Notation We use notation `𝕎 R`, entered `\bbW`, for the Witt vectors over `R`. ## References * [Hazewinkel, *Witt Vectors*][Haze09] * [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21] -/ noncomputable section /-- `WittVector p R` is the ring of `p`-typical Witt vectors over the commutative ring `R`, where `p` is a prime number. If `p` is invertible in `R`, this ring is isomorphic to `ℕ → R` (the product of `ℕ` copies of `R`). If `R` is a ring of characteristic `p`, then `WittVector p R` is a ring of characteristic `0`. The canonical example is `WittVector p (ZMod p)`, which is isomorphic to the `p`-adic integers `â„€_[p]`. -/ structure WittVector (p : ℕ) (R : Type*) where mk' :: /-- `x.coeff n` is the `n`th coefficient of the Witt vector `x`. This concept does not have a standard name in the literature. -/ coeff : ℕ → R -- Porting note: added to make the `p` argument explicit /-- Construct a Witt vector `mk p x : 𝕎 R` from a sequence `x` of elements of `R`. -/ def WittVector.mk (p : ℕ) {R : Type*} (coeff : ℕ → R) : WittVector p R := mk' coeff variable {p : ℕ} /- We cannot make this `localized` notation, because the `p` on the RHS doesn't occur on the left Hiding the `p` in the notation is very convenient, so we opt for repeating the `local notation` in other files that use Witt vectors. -/ local notation "𝕎" => WittVector p -- type as `\bbW` namespace WittVector variable {R : Type*} @[ext] theorem ext {x y : 𝕎 R} (h : ∀ n, x.coeff n = y.coeff n) : x = y := by cases x cases y simp only at h simp [funext_iff, h] variable (p) theorem coeff_mk (x : ℕ → R) : (mk p x).coeff = x := rfl /- These instances are not needed for the rest of the development, but it is interesting to establish early on that `WittVector p` is a lawful functor. -/ instance : Functor (WittVector p) where map f v := mk p (f ∘ v.coeff) mapConst a _ := mk p fun _ => a instance : LawfulFunctor (WittVector p) where map_const := rfl -- Porting note: no longer needs to deconstruct `v` to conclude `{coeff := v.coeff} = v` id_map _ := rfl comp_map _ _ _ := rfl variable [hp : Fact p.Prime] [CommRing R] open MvPolynomial section RingOperations /-- The polynomials used for defining the element `0` of the ring of Witt vectors. -/ def wittZero : ℕ → MvPolynomial (Fin 0 × ℕ) â„€ := wittStructureInt p 0 /-- The polynomials used for defining the element `1` of the ring of Witt vectors. -/ def wittOne : ℕ → MvPolynomial (Fin 0 × ℕ) â„€ := wittStructureInt p 1 /-- The polynomials used for defining the addition of the ring of Witt vectors. -/ def wittAdd : ℕ → MvPolynomial (Fin 2 × ℕ) â„€ := wittStructureInt p (X 0 + X 1) /-- The polynomials used for defining repeated addition of the ring of Witt vectors. -/ def wittNSMul (n : ℕ) : ℕ → MvPolynomial (Fin 1 × ℕ) â„€ := wittStructureInt p (n • X (0 : (Fin 1))) /-- The polynomials used for defining repeated addition of the ring of Witt vectors. -/ def wittZSMul (n : â„€) : ℕ → MvPolynomial (Fin 1 × ℕ) â„€ := wittStructureInt p (n • X (0 : (Fin 1))) /-- The polynomials used for describing the subtraction of the ring of Witt vectors. -/ def wittSub : ℕ → MvPolynomial (Fin 2 × ℕ) â„€ := wittStructureInt p (X 0 - X 1) /-- The polynomials used for defining the multiplication of the ring of Witt vectors. -/ def wittMul : ℕ → MvPolynomial (Fin 2 × ℕ) â„€ := wittStructureInt p (X 0 * X 1) /-- The polynomials used for defining the negation of the ring of Witt vectors. -/ def wittNeg : ℕ → MvPolynomial (Fin 1 × ℕ) â„€ := wittStructureInt p (-X 0) /-- The polynomials used for defining repeated addition of the ring of Witt vectors. -/ def wittPow (n : ℕ) : ℕ → MvPolynomial (Fin 1 × ℕ) â„€ := wittStructureInt p (X 0 ^ n) variable {p} /-- An auxiliary definition used in `WittVector.eval`. Evaluates a polynomial whose variables come from the disjoint union of `k` copies of `ℕ`, with a curried evaluation `x`. This can be defined more generally but we use only a specific instance here. -/ def peval {k : ℕ} (φ : MvPolynomial (Fin k × ℕ) â„€) (x : Fin k → ℕ → R) : R := aeval (Function.uncurry x) φ /-- Let `φ` be a family of polynomials, indexed by natural numbers, whose variables come from the disjoint union of `k` copies of `ℕ`, and let `xáµ¢` be a Witt vector for `0 ≀ i < k`. `eval φ x` evaluates `φ` mapping the variable `X_(i, n)` to the `n`th coefficient of `xáµ¢`. Instantiating `φ` with certain polynomials defined in `Mathlib/RingTheory/WittVector/StructurePolynomial.lean` establishes the ring operations on `𝕎 R`. For example, `WittVector.wittAdd` is such a `φ` with `k = 2`; evaluating this at `(x₀, x₁)` gives us the sum of two Witt vectors `x₀ + x₁`. -/ def eval {k : ℕ} (φ : ℕ → MvPolynomial (Fin k × ℕ) â„€) (x : Fin k → 𝕎 R) : 𝕎 R := mk p fun n => peval (φ n) fun i => (x i).coeff instance : Zero (𝕎 R) := ⟹eval (wittZero p) ![]⟩ instance : Inhabited (𝕎 R) := ⟹0⟩ instance : One (𝕎 R) := ⟹eval (wittOne p) ![]⟩ instance : Add (𝕎 R) := ⟹fun x y => eval (wittAdd p) ![x, y]⟩ instance : Sub (𝕎 R) := ⟹fun x y => eval (wittSub p) ![x, y]⟩ instance hasNatScalar : SMul ℕ (𝕎 R) := ⟹fun n x => eval (wittNSMul p n) ![x]⟩ instance hasIntScalar : SMul â„€ (𝕎 R) := ⟹fun n x => eval (wittZSMul p n) ![x]⟩ instance : Mul (𝕎 R) := ⟹fun x y => eval (wittMul p) ![x, y]⟩ instance : Neg (𝕎 R) := ⟹fun x => eval (wittNeg p) ![x]⟩ instance hasNatPow : Pow (𝕎 R) ℕ := ⟹fun x n => eval (wittPow p n) ![x]⟩ instance : NatCast (𝕎 R) := ⟹Nat.unaryCast⟩ instance : IntCast (𝕎 R) := ⟹Int.castDef⟩ end RingOperations section WittStructureSimplifications @[simp] theorem wittZero_eq_zero (n : ℕ) : wittZero p n = 0 := by apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective simp only [wittZero, wittStructureRat, bind₁, aeval_zero', constantCoeff_xInTermsOfW, map_zero, map_wittStructureInt] @[simp] theorem wittOne_zero_eq_one : wittOne p 0 = 1 := by apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective simp only [wittOne, wittStructureRat, xInTermsOfW_zero, map_one, bind₁_X_right, map_wittStructureInt] @[simp] theorem wittOne_pos_eq_zero (n : ℕ) (hn : 0 < n) : wittOne p n = 0 := by apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective simp only [wittOne, wittStructureRat, RingHom.map_zero, map_one, RingHom.map_one, map_wittStructureInt] induction n using Nat.strong_induction_on with | h n IH => ?_ rw [xInTermsOfW_eq] simp only [map_mul, map_sub, map_sum, map_pow, bind₁_X_right, bind₁_C_right] rw [sub_mul, one_mul] rw [Finset.sum_eq_single 0] · simp only [invOf_eq_inv, one_mul, inv_pow, tsub_zero, RingHom.map_one, pow_zero] simp only [one_pow, one_mul, xInTermsOfW_zero, sub_self, bind₁_X_right] · intro i hin hi0 rw [Finset.mem_range] at hin rw [IH _ hin (Nat.pos_of_ne_zero hi0), zero_pow (pow_ne_zero _ hp.1.ne_zero), mul_zero] · rw [Finset.mem_range]; intro; contradiction @[simp] theorem wittAdd_zero : wittAdd p 0 = X (0, 0) + X (1, 0) := by apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective simp only [wittAdd, wittStructureRat, map_add, rename_X, xInTermsOfW_zero, map_X, wittPolynomial_zero, bind₁_X_right, map_wittStructureInt] @[simp] theorem wittSub_zero : wittSub p 0 = X (0, 0) - X (1, 0) := by apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective simp only [wittSub, wittStructureRat, map_sub, rename_X, xInTermsOfW_zero, map_X, wittPolynomial_zero, bind₁_X_right, map_wittStructureInt] @[simp] theorem wittMul_zero : wittMul p 0 = X (0, 0) * X (1, 0) := by apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective simp only [wittMul, wittStructureRat, rename_X, xInTermsOfW_zero, map_X, wittPolynomial_zero, map_mul, bind₁_X_right, map_wittStructureInt] @[simp] theorem wittNeg_zero : wittNeg p 0 = -X (0, 0) := by apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective simp only [wittNeg, wittStructureRat, rename_X, xInTermsOfW_zero, map_X, wittPolynomial_zero, map_neg, bind₁_X_right, map_wittStructureInt] @[simp] theorem constantCoeff_wittAdd (n : ℕ) : constantCoeff (wittAdd p n) = 0 := by apply constantCoeff_wittStructureInt p _ _ n simp only [add_zero, RingHom.map_add, constantCoeff_X] @[simp] theorem constantCoeff_wittSub (n : ℕ) : constantCoeff (wittSub p n) = 0 := by apply constantCoeff_wittStructureInt p _ _ n simp only [sub_zero, RingHom.map_sub, constantCoeff_X] @[simp] theorem constantCoeff_wittMul (n : ℕ) : constantCoeff (wittMul p n) = 0 := by apply constantCoeff_wittStructureInt p _ _ n simp only [mul_zero, RingHom.map_mul, constantCoeff_X] @[simp] theorem constantCoeff_wittNeg (n : ℕ) : constantCoeff (wittNeg p n) = 0 := by apply constantCoeff_wittStructureInt p _ _ n simp only [neg_zero, RingHom.map_neg, constantCoeff_X] @[simp] theorem constantCoeff_wittNSMul (m : ℕ) (n : ℕ) : constantCoeff (wittNSMul p m n) = 0 := by apply constantCoeff_wittStructureInt p _ _ n simp only [smul_zero, map_nsmul, constantCoeff_X] @[simp] theorem constantCoeff_wittZSMul (z : â„€) (n : ℕ) : constantCoeff (wittZSMul p z n) = 0 := by apply constantCoeff_wittStructureInt p _ _ n simp only [smul_zero, map_zsmul, constantCoeff_X] end WittStructureSimplifications section Coeff variable (R) @[simp] theorem zero_coeff (n : ℕ) : (0 : 𝕎 R).coeff n = 0 := show (aeval _ (wittZero p n) : R) = 0 by simp only [wittZero_eq_zero, map_zero] @[simp] theorem one_coeff_zero : (1 : 𝕎 R).coeff 0 = 1 := show (aeval _ (wittOne p 0) : R) = 1 by simp only [wittOne_zero_eq_one, map_one] @[simp] theorem one_coeff_eq_of_pos (n : ℕ) (hn : 0 < n) : coeff (1 : 𝕎 R) n = 0 := show (aeval _ (wittOne p n) : R) = 0 by simp only [hn, wittOne_pos_eq_zero, map_zero] variable {p R} @[simp] theorem v2_coeff {p' R'} (x y : WittVector p' R') (i : Fin 2) : (![x, y] i).coeff = ![x.coeff, y.coeff] i := by fin_cases i <;> simp -- Porting note: the lemmas below needed `coeff_mk` added to the `simp` calls theorem add_coeff (x y : 𝕎 R) (n : ℕ) : (x + y).coeff n = peval (wittAdd p n) ![x.coeff, y.coeff] := by simp [(· + ·), Add.add, eval, coeff_mk] theorem sub_coeff (x y : 𝕎 R) (n : ℕ) : (x - y).coeff n = peval (wittSub p n) ![x.coeff, y.coeff] := by simp [(· - ·), Sub.sub, eval, coeff_mk] theorem mul_coeff (x y : 𝕎 R) (n : ℕ) : (x * y).coeff n = peval (wittMul p n) ![x.coeff, y.coeff] := by simp [(· * ·), Mul.mul, eval, coeff_mk] theorem neg_coeff (x : 𝕎 R) (n : ℕ) : (-x).coeff n = peval (wittNeg p n) ![x.coeff] := by simp [Neg.neg, eval, Matrix.cons_fin_one, coeff_mk] theorem nsmul_coeff (m : ℕ) (x : 𝕎 R) (n : ℕ) : (m • x).coeff n = peval (wittNSMul p m n) ![x.coeff] := by simp [(· • ·), SMul.smul, eval, Matrix.cons_fin_one, coeff_mk] theorem zsmul_coeff (m : â„€) (x : 𝕎 R) (n : ℕ) : (m • x).coeff n = peval (wittZSMul p m n) ![x.coeff] := by simp [(· • ·), SMul.smul, eval, Matrix.cons_fin_one, coeff_mk] theorem pow_coeff (m : ℕ) (x : 𝕎 R) (n : ℕ) : (x ^ m).coeff n = peval (wittPow p m n) ![x.coeff] := by simp [(· ^ ·), Pow.pow, eval, Matrix.cons_fin_one, coeff_mk] theorem add_coeff_zero (x y : 𝕎 R) : (x + y).coeff 0 = x.coeff 0 + y.coeff 0 := by simp [add_coeff, peval, Function.uncurry]
theorem mul_coeff_zero (x y : 𝕎 R) : (x * y).coeff 0 = x.coeff 0 * y.coeff 0 := by
Mathlib/RingTheory/WittVector/Defs.lean
338
339
/- Copyright (c) 2018 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Johannes Hölzl -/ import Mathlib.Algebra.Field.Subfield.Defs import Mathlib.Algebra.Order.Group.Pointwise.Interval import Mathlib.Analysis.Normed.Ring.Basic /-! # Normed division rings and fields In this file we define normed fields, and (more generally) normed division rings. We also prove some theorems about these definitions. Some useful results that relate the topology of the normed field to the discrete topology include: * `norm_eq_one_iff_ne_zero_of_discrete` Methods for constructing a normed field instance from a given real absolute value on a field are given in: * AbsoluteValue.toNormedField -/ -- Guard against import creep. assert_not_exists AddChar comap_norm_atTop DilationEquiv Finset.sup_mul_le_mul_sup_of_nonneg IsOfFinOrder Isometry.norm_map_of_map_one NNReal.isOpen_Ico_zero Rat.norm_cast_real RestrictScalars variable {G α β ι : Type*} open Filter open scoped Topology NNReal ENNReal /-- A normed division ring is a division ring endowed with a seminorm which satisfies the equality `‖x y‖ = ‖x‖ ‖y‖`. -/ class NormedDivisionRing (α : Type*) extends Norm α, DivisionRing α, MetricSpace α where /-- The distance is induced by the norm. -/ dist_eq : ∀ x y, dist x y = norm (x - y) /-- The norm is multiplicative. -/ protected norm_mul : ∀ a b, norm (a * b) = norm a * norm b -- see Note [lower instance priority] /-- A normed division ring is a normed ring. -/ instance (priority := 100) NormedDivisionRing.toNormedRing [β : NormedDivisionRing α] : NormedRing α := { β with norm_mul_le a b := (NormedDivisionRing.norm_mul a b).le } -- see Note [lower instance priority] /-- The norm on a normed division ring is strictly multiplicative. -/ instance (priority := 100) NormedDivisionRing.toNormMulClass [NormedDivisionRing α] : NormMulClass α where norm_mul := NormedDivisionRing.norm_mul section NormedDivisionRing variable [NormedDivisionRing α] {a b : α} instance (priority := 900) NormedDivisionRing.to_normOneClass : NormOneClass α := ⟹mul_left_cancel₀ (mt norm_eq_zero.1 (one_ne_zero' α)) <| by rw [← norm_mul, mul_one, mul_one]⟩ @[simp] theorem norm_div (a b : α) : ‖a / b‖ = ‖a‖ / ‖b‖ := map_div₀ (normHom : α →*₀ ℝ) a b @[simp] theorem nnnorm_div (a b : α) : ‖a / b‖₊ = ‖a‖₊ / ‖b‖₊ := map_div₀ (nnnormHom : α →*₀ ℝ≥0) a b @[simp] theorem norm_inv (a : α) : ‖a⁻¹‖ = ‖a‖⁻¹ := map_inv₀ (normHom : α →*₀ ℝ) a @[simp] theorem nnnorm_inv (a : α) : ‖a⁻¹‖₊ = ‖a‖₊⁻¹ := NNReal.eq <| by simp @[simp] lemma enorm_inv {a : α} (ha : a ≠ 0) : ‖a⁻¹‖ₑ = ‖a‖ₑ⁻¹ := by simp [enorm, ENNReal.coe_inv, ha] @[simp] theorem norm_zpow : ∀ (a : α) (n : â„€), ‖a ^ n‖ = ‖a‖ ^ n := map_zpow₀ (normHom : α →*₀ ℝ) @[simp] theorem nnnorm_zpow : ∀ (a : α) (n : â„€), ‖a ^ n‖₊ = ‖a‖₊ ^ n := map_zpow₀ (nnnormHom : α →*₀ ℝ≥0) theorem dist_inv_inv₀ {z w : α} (hz : z ≠ 0) (hw : w ≠ 0) : dist z⁻¹ w⁻¹ = dist z w / (‖z‖ * ‖w‖) := by rw [dist_eq_norm, inv_sub_inv' hz hw, norm_mul, norm_mul, norm_inv, norm_inv, mul_comm ‖z‖⁻¹, mul_assoc, dist_eq_norm', div_eq_mul_inv, mul_inv] theorem nndist_inv_inv₀ {z w : α} (hz : z ≠ 0) (hw : w ≠ 0) : nndist z⁻¹ w⁻¹ = nndist z w / (‖z‖₊ * ‖w‖₊) := NNReal.eq <| dist_inv_inv₀ hz hw lemma norm_commutator_sub_one_le (ha : a ≠ 0) (hb : b ≠ 0) : ‖a * b * a⁻¹ * b⁻¹ - 1‖ ≀ 2 * ‖a‖⁻¹ * ‖b‖⁻¹ * ‖a - 1‖ * ‖b - 1‖ := by simpa using norm_commutator_units_sub_one_le (.mk0 a ha) (.mk0 b hb) lemma nnnorm_commutator_sub_one_le (ha : a ≠ 0) (hb : b ≠ 0) : ‖a * b * a⁻¹ * b⁻¹ - 1‖₊ ≀ 2 * ‖a‖₊⁻¹ * ‖b‖₊⁻¹ * ‖a - 1‖₊ * ‖b - 1‖₊ := by simpa using nnnorm_commutator_units_sub_one_le (.mk0 a ha) (.mk0 b hb) namespace NormedDivisionRing section Discrete variable {𝕜 : Type*} [NormedDivisionRing 𝕜] [DiscreteTopology 𝕜] lemma norm_eq_one_iff_ne_zero_of_discrete {x : 𝕜} : ‖x‖ = 1 ↔ x ≠ 0 := by constructor <;> intro hx · contrapose! hx simp [hx] · have : IsOpen {(0 : 𝕜)} := isOpen_discrete {0} simp_rw [Metric.isOpen_singleton_iff, dist_eq_norm, sub_zero] at this obtain ⟚ε, εpos, h'⟩ := this wlog h : ‖x‖ < 1 generalizing 𝕜 with H · push_neg at h rcases h.eq_or_lt with h|h · rw [h] replace h := norm_inv x ▾ inv_lt_one_of_one_lt₀ h rw [← inv_inj, inv_one, ← norm_inv] exact H (by simpa) h' h obtain ⟹k, hk⟩ : ∃ k : ℕ, ‖x‖ ^ k < ε := exists_pow_lt_of_lt_one εpos h rw [← norm_pow] at hk specialize h' _ hk simp [hx] at h' @[simp] lemma norm_le_one_of_discrete (x : 𝕜) : ‖x‖ ≀ 1 := by rcases eq_or_ne x 0 with rfl|hx · simp · simp [norm_eq_one_iff_ne_zero_of_discrete.mpr hx] lemma unitClosedBall_eq_univ_of_discrete : (Metric.closedBall 0 1 : Set 𝕜) = Set.univ := by ext simp @[deprecated (since := "2024-12-01")] alias discreteTopology_unit_closedBall_eq_univ := unitClosedBall_eq_univ_of_discrete end Discrete end NormedDivisionRing end NormedDivisionRing /-- A normed field is a field with a norm satisfying ‖x y‖ = ‖x‖ ‖y‖. -/ class NormedField (α : Type*) extends Norm α, Field α, MetricSpace α where /-- The distance is induced by the norm. -/ dist_eq : ∀ x y, dist x y = norm (x - y) /-- The norm is multiplicative. -/ protected norm_mul : ∀ a b, norm (a * b) = norm a * norm b /-- A nontrivially normed field is a normed field in which there is an element of norm different from `0` and `1`. This makes it possible to bring any element arbitrarily close to `0` by multiplication by the powers of any element, and thus to relate algebra and topology. -/ class NontriviallyNormedField (α : Type*) extends NormedField α where /-- The norm attains a value exceeding 1. -/ non_trivial : ∃ x : α, 1 < ‖x‖ /-- A densely normed field is a normed field for which the image of the norm is dense in `ℝ≥0`, which means it is also nontrivially normed. However, not all nontrivally normed fields are densely normed; in particular, the `Padic`s exhibit this fact. -/ class DenselyNormedField (α : Type*) extends NormedField α where /-- The range of the norm is dense in the collection of nonnegative real numbers. -/ lt_norm_lt : ∀ x y : ℝ, 0 ≀ x → x < y → ∃ a : α, x < ‖a‖ ∧ ‖a‖ < y section NormedField /-- A densely normed field is always a nontrivially normed field. See note [lower instance priority]. -/ instance (priority := 100) DenselyNormedField.toNontriviallyNormedField [DenselyNormedField α] : NontriviallyNormedField α where non_trivial := let ⟹a, h, _⟩ := DenselyNormedField.lt_norm_lt 1 2 zero_le_one one_lt_two ⟹a, h⟩ variable [NormedField α] -- see Note [lower instance priority] instance (priority := 100) NormedField.toNormedDivisionRing : NormedDivisionRing α := { ‹NormedField α› with } -- see Note [lower instance priority] instance (priority := 100) NormedField.toNormedCommRing : NormedCommRing α := { ‹NormedField α› with norm_mul_le a b := (norm_mul a b).le } end NormedField namespace NormedField section Nontrivially variable (α) [NontriviallyNormedField α] theorem exists_one_lt_norm : ∃ x : α, 1 < ‖x‖ := ‹NontriviallyNormedField α›.non_trivial theorem exists_one_lt_nnnorm : ∃ x : α, 1 < ‖x‖₊ := exists_one_lt_norm α theorem exists_one_lt_enorm : ∃ x : α, 1 < ‖x‖ₑ := exists_one_lt_nnnorm α |>.imp fun _ => ENNReal.coe_lt_coe.mpr theorem exists_lt_norm (r : ℝ) : ∃ x : α, r < ‖x‖ := let ⟹w, hw⟩ := exists_one_lt_norm α let ⟹n, hn⟩ := pow_unbounded_of_one_lt r hw ⟹w ^ n, by rwa [norm_pow]⟩ theorem exists_lt_nnnorm (r : ℝ≥0) : ∃ x : α, r < ‖x‖₊ := exists_lt_norm α r theorem exists_lt_enorm {r : ℝ≥0∞} (hr : r ≠ ∞) : ∃ x : α, r < ‖x‖ₑ := by lift r to ℝ≥0 using hr exact mod_cast exists_lt_nnnorm α r theorem exists_norm_lt {r : ℝ} (hr : 0 < r) : ∃ x : α, 0 < ‖x‖ ∧ ‖x‖ < r := let ⟹w, hw⟩ := exists_lt_norm α r⁻¹ ⟹w⁻¹, by rwa [← Set.mem_Ioo, norm_inv, ← Set.mem_inv, Set.inv_Ioo_0_left hr]⟩ theorem exists_nnnorm_lt {r : ℝ≥0} (hr : 0 < r) : ∃ x : α, 0 < ‖x‖₊ ∧ ‖x‖₊ < r := exists_norm_lt α hr /-- TODO: merge with `_root_.exists_enorm_lt`. -/ theorem exists_enorm_lt {r : ℝ≥0∞} (hr : 0 < r) : ∃ x : α, 0 < ‖x‖ₑ ∧ ‖x‖ₑ < r := match r with | ∞ => exists_one_lt_enorm α |>.imp fun _ hx => ⟹zero_le_one.trans_lt hx, ENNReal.coe_lt_top⟩ | (r : ℝ≥0) => exists_nnnorm_lt α (ENNReal.coe_pos.mp hr) |>.imp fun _ => And.imp ENNReal.coe_pos.mpr ENNReal.coe_lt_coe.mpr theorem exists_norm_lt_one : ∃ x : α, 0 < ‖x‖ ∧ ‖x‖ < 1 := exists_norm_lt α one_pos theorem exists_nnnorm_lt_one : ∃ x : α, 0 < ‖x‖₊ ∧ ‖x‖₊ < 1 := exists_norm_lt_one _ theorem exists_enorm_lt_one : ∃ x : α, 0 < ‖x‖ₑ ∧ ‖x‖ₑ < 1 := exists_enorm_lt _ one_pos variable {α} @[instance] theorem nhdsNE_neBot (x : α) : NeBot (𝓝[≠] x) := by rw [← mem_closure_iff_nhdsWithin_neBot, Metric.mem_closure_iff] rintro ε ε0 rcases exists_norm_lt α ε0 with ⟹b, hb0, hbε⟩ refine ⟹x + b, mt (Set.mem_singleton_iff.trans add_eq_left).1 <| norm_pos_iff.1 hb0, ?_⟩ rwa [dist_comm, dist_eq_norm, add_sub_cancel_left] @[deprecated (since := "2025-03-02")] alias punctured_nhds_neBot := nhdsNE_neBot @[instance] theorem nhdsWithin_isUnit_neBot : NeBot (𝓝[{ x : α | IsUnit x }] 0) := by simpa only [isUnit_iff_ne_zero] using nhdsNE_neBot (0 : α) end Nontrivially section Densely variable (α) [DenselyNormedField α] theorem exists_lt_norm_lt {r₁ r₂ : ℝ} (h₀ : 0 ≀ r₁) (h : r₁ < r₂) : ∃ x : α, r₁ < ‖x‖ ∧ ‖x‖ < r₂ := DenselyNormedField.lt_norm_lt r₁ r₂ h₀ h theorem exists_lt_nnnorm_lt {r₁ r₂ : ℝ≥0} (h : r₁ < r₂) : ∃ x : α, r₁ < ‖x‖₊ ∧ ‖x‖₊ < r₂ := mod_cast exists_lt_norm_lt α r₁.prop h instance denselyOrdered_range_norm : DenselyOrdered (Set.range (norm : α → ℝ)) where dense := by rintro ⟹-, x, rfl⟩ ⟹-, y, rfl⟩ hxy let ⟹z, h⟩ := exists_lt_norm_lt α (norm_nonneg _) hxy exact ⟹⟹‖z‖, z, rfl⟩, h⟩ instance denselyOrdered_range_nnnorm : DenselyOrdered (Set.range (nnnorm : α → ℝ≥0)) where dense := by rintro ⟹-, x, rfl⟩ ⟹-, y, rfl⟩ hxy let ⟹z, h⟩ := exists_lt_nnnorm_lt α hxy exact ⟹⟹‖z‖₊, z, rfl⟩, h⟩ end Densely end NormedField /-- A normed field is nontrivially normed provided that the norm of some nonzero element is not one. -/ def NontriviallyNormedField.ofNormNeOne {𝕜 : Type*} [h' : NormedField 𝕜] (h : ∃ x : 𝕜, x ≠ 0 ∧ ‖x‖ ≠ 1) : NontriviallyNormedField 𝕜 where toNormedField := h' non_trivial := by rcases h with ⟹x, hx, hx1⟩ rcases hx1.lt_or_lt with hlt | hlt · use x⁻¹ rw [norm_inv] exact (one_lt_inv₀ (norm_pos_iff.2 hx)).2 hlt · exact ⟹x, hlt⟩ noncomputable instance Real.normedField : NormedField ℝ := { Real.normedAddCommGroup, Real.field with norm_mul := abs_mul } noncomputable instance Real.denselyNormedField : DenselyNormedField ℝ where lt_norm_lt _ _ h₀ hr := let ⟹x, h⟩ := exists_between hr ⟹x, by rwa [Real.norm_eq_abs, abs_of_nonneg (h₀.trans h.1.le)]⟩ namespace Real theorem toNNReal_mul_nnnorm {x : ℝ} (y : ℝ) (hx : 0 ≀ x) : x.toNNReal * ‖y‖₊ = ‖x * y‖₊ := by ext simp only [NNReal.coe_mul, nnnorm_mul, coe_nnnorm, Real.toNNReal_of_nonneg, norm_of_nonneg, hx, NNReal.coe_mk] theorem nnnorm_mul_toNNReal (x : ℝ) {y : ℝ} (hy : 0 ≀ y) : ‖x‖₊ * y.toNNReal = ‖x * y‖₊ := by rw [mul_comm, mul_comm x, toNNReal_mul_nnnorm x hy] end Real /-! ### Induced normed structures -/ section Induced variable {F : Type*} (R S : Type*) [FunLike F R S] /-- An injective non-unital ring homomorphism from a `DivisionRing` to a `NormedRing` induces a `NormedDivisionRing` structure on the domain. See note [reducible non-instances] -/ abbrev NormedDivisionRing.induced [DivisionRing R] [NormedDivisionRing S] [NonUnitalRingHomClass F R S] (f : F) (hf : Function.Injective f) : NormedDivisionRing R := { NormedAddCommGroup.induced R S f hf, ‹DivisionRing R› with norm_mul x y := show ‖f _‖ = _ from (map_mul f x y).symm ▾ norm_mul (f x) (f y) } /-- An injective non-unital ring homomorphism from a `Field` to a `NormedRing` induces a `NormedField` structure on the domain. See note [reducible non-instances] -/ abbrev NormedField.induced [Field R] [NormedField S] [NonUnitalRingHomClass F R S] (f : F) (hf : Function.Injective f) : NormedField R := { NormedDivisionRing.induced R S f hf with mul_comm := mul_comm } end Induced namespace SubfieldClass variable {S F : Type*} [SetLike S F] /-- If `s` is a subfield of a normed field `F`, then `s` is equipped with an induced normed field structure. -/ instance toNormedField [NormedField F] [SubfieldClass S F] (s : S) : NormedField s := NormedField.induced s F (SubringClass.subtype s) Subtype.val_injective end SubfieldClass namespace AbsoluteValue /-- A real absolute value on a field determines a `NormedField` structure. -/ noncomputable def toNormedField {K : Type*} [Field K] (v : AbsoluteValue K ℝ) : NormedField K where toField := inferInstanceAs (Field K) __ := v.toNormedRing norm_mul := v.map_mul end AbsoluteValue
Mathlib/Analysis/Normed/Field/Basic.lean
404
406
/- 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) :
Mathlib/Data/Set/Card.lean
260
261
/- 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.Algebra.Field.NegOnePow import Mathlib.Algebra.Field.Periodic import Mathlib.Algebra.QuadraticDiscriminant import Mathlib.Analysis.SpecialFunctions.Exp /-! # Trigonometric functions ## Main definitions This file contains the definition of `π`. See also `Analysis.SpecialFunctions.Trigonometric.Inverse` and `Analysis.SpecialFunctions.Trigonometric.Arctan` for the inverse trigonometric functions. See also `Analysis.SpecialFunctions.Complex.Arg` and `Analysis.SpecialFunctions.Complex.Log` for the complex argument function and the complex logarithm. ## Main statements Many basic inequalities on the real trigonometric functions are established. The continuity of the usual trigonometric functions is proved. Several facts about the real trigonometric functions have the proofs deferred to `Analysis.SpecialFunctions.Trigonometric.Complex`, as they are most easily proved by appealing to the corresponding fact for complex trigonometric functions. See also `Analysis.SpecialFunctions.Trigonometric.Chebyshev` for the multiple angle formulas in terms of Chebyshev polynomials. ## Tags sin, cos, tan, angle -/ noncomputable section open Topology Filter Set namespace Complex @[continuity, fun_prop] theorem continuous_sin : Continuous sin := by change Continuous fun z => (exp (-z * I) - exp (z * I)) * I / 2 fun_prop @[fun_prop] theorem continuousOn_sin {s : Set ℂ} : ContinuousOn sin s := continuous_sin.continuousOn @[continuity, fun_prop] theorem continuous_cos : Continuous cos := by change Continuous fun z => (exp (z * I) + exp (-z * I)) / 2 fun_prop @[fun_prop] theorem continuousOn_cos {s : Set ℂ} : ContinuousOn cos s := continuous_cos.continuousOn @[continuity, fun_prop] theorem continuous_sinh : Continuous sinh := by change Continuous fun z => (exp z - exp (-z)) / 2 fun_prop @[continuity, fun_prop] theorem continuous_cosh : Continuous cosh := by change Continuous fun z => (exp z + exp (-z)) / 2 fun_prop end Complex namespace Real variable {x y z : ℝ} @[continuity, fun_prop] theorem continuous_sin : Continuous sin := Complex.continuous_re.comp (Complex.continuous_sin.comp Complex.continuous_ofReal) @[fun_prop] theorem continuousOn_sin {s} : ContinuousOn sin s := continuous_sin.continuousOn @[continuity, fun_prop] theorem continuous_cos : Continuous cos := Complex.continuous_re.comp (Complex.continuous_cos.comp Complex.continuous_ofReal) @[fun_prop] theorem continuousOn_cos {s} : ContinuousOn cos s := continuous_cos.continuousOn @[continuity, fun_prop] theorem continuous_sinh : Continuous sinh := Complex.continuous_re.comp (Complex.continuous_sinh.comp Complex.continuous_ofReal) @[continuity, fun_prop] theorem continuous_cosh : Continuous cosh := Complex.continuous_re.comp (Complex.continuous_cosh.comp Complex.continuous_ofReal) end Real namespace Real theorem exists_cos_eq_zero : 0 ∈ cos '' Icc (1 : ℝ) 2 := intermediate_value_Icc' (by norm_num) continuousOn_cos ⟹le_of_lt cos_two_neg, le_of_lt cos_one_pos⟩ /-- The number π = 3.14159265... Defined here using choice as twice a zero of cos in [1,2], from which one can derive all its properties. For explicit bounds on π, see `Data.Real.Pi.Bounds`. Denoted `π`, once the `Real` namespace is opened. -/ protected noncomputable def pi : ℝ := 2 * Classical.choose exists_cos_eq_zero @[inherit_doc] scoped notation "π" => Real.pi @[simp] theorem cos_pi_div_two : cos (π / 2) = 0 := by rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)] exact (Classical.choose_spec exists_cos_eq_zero).2 theorem one_le_pi_div_two : (1 : ℝ) ≀ π / 2 := by rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)] exact (Classical.choose_spec exists_cos_eq_zero).1.1 theorem pi_div_two_le_two : π / 2 ≀ 2 := by rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)] exact (Classical.choose_spec exists_cos_eq_zero).1.2 theorem two_le_pi : (2 : ℝ) ≀ π := (div_le_div_iff_of_pos_right (show (0 : ℝ) < 2 by norm_num)).1 (by rw [div_self (two_ne_zero' ℝ)]; exact one_le_pi_div_two) theorem pi_le_four : π ≀ 4 := (div_le_div_iff_of_pos_right (show (0 : ℝ) < 2 by norm_num)).1 (calc π / 2 ≀ 2 := pi_div_two_le_two _ = 4 / 2 := by norm_num) @[bound] theorem pi_pos : 0 < π := lt_of_lt_of_le (by norm_num) two_le_pi @[bound] theorem pi_nonneg : 0 ≀ π := pi_pos.le theorem pi_ne_zero : π ≠ 0 := pi_pos.ne' theorem pi_div_two_pos : 0 < π / 2 := half_pos pi_pos theorem two_pi_pos : 0 < 2 * π := by linarith [pi_pos] end Real namespace Mathlib.Meta.Positivity open Lean.Meta Qq /-- Extension for the `positivity` tactic: `π` is always positive. -/ @[positivity Real.pi] def evalRealPi : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(Real.pi) => assertInstancesCommute pure (.positive q(Real.pi_pos)) | _, _, _ => throwError "not Real.pi" end Mathlib.Meta.Positivity namespace NNReal open Real open Real NNReal /-- `π` considered as a nonnegative real. -/ noncomputable def pi : ℝ≥0 := ⟚π, Real.pi_pos.le⟩ @[simp] theorem coe_real_pi : (pi : ℝ) = π := rfl theorem pi_pos : 0 < pi := mod_cast Real.pi_pos theorem pi_ne_zero : pi ≠ 0 := pi_pos.ne' end NNReal namespace Real @[simp] theorem sin_pi : sin π = 0 := by rw [← mul_div_cancel_left₀ π (two_ne_zero' ℝ), two_mul, add_div, sin_add, cos_pi_div_two]; simp @[simp] theorem cos_pi : cos π = -1 := by rw [← mul_div_cancel_left₀ π (two_ne_zero' ℝ), mul_div_assoc, cos_two_mul, cos_pi_div_two] norm_num @[simp] theorem sin_two_pi : sin (2 * π) = 0 := by simp [two_mul, sin_add] @[simp] theorem cos_two_pi : cos (2 * π) = 1 := by simp [two_mul, cos_add] theorem sin_antiperiodic : Function.Antiperiodic sin π := by simp [sin_add] theorem sin_periodic : Function.Periodic sin (2 * π) := sin_antiperiodic.periodic_two_mul @[simp] theorem sin_add_pi (x : ℝ) : sin (x + π) = -sin x := sin_antiperiodic x @[simp] theorem sin_add_two_pi (x : ℝ) : sin (x + 2 * π) = sin x := sin_periodic x @[simp] theorem sin_sub_pi (x : ℝ) : sin (x - π) = -sin x := sin_antiperiodic.sub_eq x @[simp] theorem sin_sub_two_pi (x : ℝ) : sin (x - 2 * π) = sin x := sin_periodic.sub_eq x @[simp] theorem sin_pi_sub (x : ℝ) : sin (π - x) = sin x := neg_neg (sin x) ▾ sin_neg x ▾ sin_antiperiodic.sub_eq' @[simp] theorem sin_two_pi_sub (x : ℝ) : sin (2 * π - x) = -sin x := sin_neg x ▾ sin_periodic.sub_eq' @[simp] theorem sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 := sin_antiperiodic.nat_mul_eq_of_eq_zero sin_zero n @[simp] theorem sin_int_mul_pi (n : â„€) : sin (n * π) = 0 := sin_antiperiodic.int_mul_eq_of_eq_zero sin_zero n @[simp] theorem sin_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x + n * (2 * π)) = sin x := sin_periodic.nat_mul n x @[simp] theorem sin_add_int_mul_two_pi (x : ℝ) (n : â„€) : sin (x + n * (2 * π)) = sin x := sin_periodic.int_mul n x @[simp] theorem sin_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x - n * (2 * π)) = sin x := sin_periodic.sub_nat_mul_eq n @[simp] theorem sin_sub_int_mul_two_pi (x : ℝ) (n : â„€) : sin (x - n * (2 * π)) = sin x := sin_periodic.sub_int_mul_eq n @[simp] theorem sin_nat_mul_two_pi_sub (x : ℝ) (n : ℕ) : sin (n * (2 * π) - x) = -sin x := sin_neg x ▾ sin_periodic.nat_mul_sub_eq n @[simp] theorem sin_int_mul_two_pi_sub (x : ℝ) (n : â„€) : sin (n * (2 * π) - x) = -sin x := sin_neg x ▾ sin_periodic.int_mul_sub_eq n theorem sin_add_int_mul_pi (x : ℝ) (n : â„€) : sin (x + n * π) = (-1) ^ n * sin x := n.cast_negOnePow ℝ ▾ sin_antiperiodic.add_int_mul_eq n theorem sin_add_nat_mul_pi (x : ℝ) (n : ℕ) : sin (x + n * π) = (-1) ^ n * sin x := sin_antiperiodic.add_nat_mul_eq n theorem sin_sub_int_mul_pi (x : ℝ) (n : â„€) : sin (x - n * π) = (-1) ^ n * sin x := n.cast_negOnePow ℝ ▾ sin_antiperiodic.sub_int_mul_eq n theorem sin_sub_nat_mul_pi (x : ℝ) (n : ℕ) : sin (x - n * π) = (-1) ^ n * sin x := sin_antiperiodic.sub_nat_mul_eq n theorem sin_int_mul_pi_sub (x : ℝ) (n : â„€) : sin (n * π - x) = -((-1) ^ n * sin x) := by simpa only [sin_neg, mul_neg, Int.cast_negOnePow] using sin_antiperiodic.int_mul_sub_eq n theorem sin_nat_mul_pi_sub (x : ℝ) (n : ℕ) : sin (n * π - x) = -((-1) ^ n * sin x) := by simpa only [sin_neg, mul_neg] using sin_antiperiodic.nat_mul_sub_eq n theorem cos_antiperiodic : Function.Antiperiodic cos π := by simp [cos_add] theorem cos_periodic : Function.Periodic cos (2 * π) := cos_antiperiodic.periodic_two_mul @[simp] theorem abs_cos_int_mul_pi (k : â„€) : |cos (k * π)| = 1 := by simp [abs_cos_eq_sqrt_one_sub_sin_sq] @[simp] theorem cos_add_pi (x : ℝ) : cos (x + π) = -cos x := cos_antiperiodic x @[simp] theorem cos_add_two_pi (x : ℝ) : cos (x + 2 * π) = cos x := cos_periodic x @[simp] theorem cos_sub_pi (x : ℝ) : cos (x - π) = -cos x := cos_antiperiodic.sub_eq x @[simp] theorem cos_sub_two_pi (x : ℝ) : cos (x - 2 * π) = cos x := cos_periodic.sub_eq x @[simp] theorem cos_pi_sub (x : ℝ) : cos (π - x) = -cos x := cos_neg x ▾ cos_antiperiodic.sub_eq' @[simp] theorem cos_two_pi_sub (x : ℝ) : cos (2 * π - x) = cos x := cos_neg x ▾ cos_periodic.sub_eq' @[simp] theorem cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 := (cos_periodic.nat_mul_eq n).trans cos_zero @[simp] theorem cos_int_mul_two_pi (n : â„€) : cos (n * (2 * π)) = 1 := (cos_periodic.int_mul_eq n).trans cos_zero @[simp] theorem cos_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x + n * (2 * π)) = cos x := cos_periodic.nat_mul n x @[simp] theorem cos_add_int_mul_two_pi (x : ℝ) (n : â„€) : cos (x + n * (2 * π)) = cos x := cos_periodic.int_mul n x @[simp] theorem cos_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x - n * (2 * π)) = cos x := cos_periodic.sub_nat_mul_eq n @[simp] theorem cos_sub_int_mul_two_pi (x : ℝ) (n : â„€) : cos (x - n * (2 * π)) = cos x := cos_periodic.sub_int_mul_eq n @[simp] theorem cos_nat_mul_two_pi_sub (x : ℝ) (n : ℕ) : cos (n * (2 * π) - x) = cos x := cos_neg x ▾ cos_periodic.nat_mul_sub_eq n @[simp] theorem cos_int_mul_two_pi_sub (x : ℝ) (n : â„€) : cos (n * (2 * π) - x) = cos x := cos_neg x ▾ cos_periodic.int_mul_sub_eq n theorem cos_add_int_mul_pi (x : ℝ) (n : â„€) : cos (x + n * π) = (-1) ^ n * cos x := n.cast_negOnePow ℝ ▾ cos_antiperiodic.add_int_mul_eq n theorem cos_add_nat_mul_pi (x : ℝ) (n : ℕ) : cos (x + n * π) = (-1) ^ n * cos x := cos_antiperiodic.add_nat_mul_eq n theorem cos_sub_int_mul_pi (x : ℝ) (n : â„€) : cos (x - n * π) = (-1) ^ n * cos x := n.cast_negOnePow ℝ ▾ cos_antiperiodic.sub_int_mul_eq n theorem cos_sub_nat_mul_pi (x : ℝ) (n : ℕ) : cos (x - n * π) = (-1) ^ n * cos x := cos_antiperiodic.sub_nat_mul_eq n theorem cos_int_mul_pi_sub (x : ℝ) (n : â„€) : cos (n * π - x) = (-1) ^ n * cos x := n.cast_negOnePow ℝ ▾ cos_neg x ▾ cos_antiperiodic.int_mul_sub_eq n theorem cos_nat_mul_pi_sub (x : ℝ) (n : ℕ) : cos (n * π - x) = (-1) ^ n * cos x := cos_neg x ▾ cos_antiperiodic.nat_mul_sub_eq n theorem cos_nat_mul_two_pi_add_pi (n : ℕ) : cos (n * (2 * π) + π) = -1 := by simpa only [cos_zero] using (cos_periodic.nat_mul n).add_antiperiod_eq cos_antiperiodic theorem cos_int_mul_two_pi_add_pi (n : â„€) : cos (n * (2 * π) + π) = -1 := by simpa only [cos_zero] using (cos_periodic.int_mul n).add_antiperiod_eq cos_antiperiodic theorem cos_nat_mul_two_pi_sub_pi (n : ℕ) : cos (n * (2 * π) - π) = -1 := by simpa only [cos_zero] using (cos_periodic.nat_mul n).sub_antiperiod_eq cos_antiperiodic theorem cos_int_mul_two_pi_sub_pi (n : â„€) : cos (n * (2 * π) - π) = -1 := by simpa only [cos_zero] using (cos_periodic.int_mul n).sub_antiperiod_eq cos_antiperiodic theorem sin_pos_of_pos_of_lt_pi {x : ℝ} (h0x : 0 < x) (hxp : x < π) : 0 < sin x := if hx2 : x ≀ 2 then sin_pos_of_pos_of_le_two h0x hx2 else have : (2 : ℝ) + 2 = 4 := by norm_num have : π - x ≀ 2 := sub_le_iff_le_add.2 (le_trans pi_le_four (this ▾ add_le_add_left (le_of_not_ge hx2) _)) sin_pi_sub x ▾ sin_pos_of_pos_of_le_two (sub_pos.2 hxp) this theorem sin_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo 0 π) : 0 < sin x := sin_pos_of_pos_of_lt_pi hx.1 hx.2 theorem sin_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc 0 π) : 0 ≀ sin x := by rw [← closure_Ioo pi_ne_zero.symm] at hx exact closure_lt_subset_le continuous_const continuous_sin (closure_mono (fun y => sin_pos_of_mem_Ioo) hx) theorem sin_nonneg_of_nonneg_of_le_pi {x : ℝ} (h0x : 0 ≀ x) (hxp : x ≀ π) : 0 ≀ sin x := sin_nonneg_of_mem_Icc ⟹h0x, hxp⟩ theorem sin_neg_of_neg_of_neg_pi_lt {x : ℝ} (hx0 : x < 0) (hpx : -π < x) : sin x < 0 := neg_pos.1 <| sin_neg x ▾ sin_pos_of_pos_of_lt_pi (neg_pos.2 hx0) (neg_lt.1 hpx) theorem sin_nonpos_of_nonnpos_of_neg_pi_le {x : ℝ} (hx0 : x ≀ 0) (hpx : -π ≀ x) : sin x ≀ 0 := neg_nonneg.1 <| sin_neg x ▾ sin_nonneg_of_nonneg_of_le_pi (neg_nonneg.2 hx0) (neg_le.1 hpx) @[simp] theorem sin_pi_div_two : sin (π / 2) = 1 := have : sin (π / 2) = 1 √ sin (π / 2) = -1 := by simpa [sq, mul_self_eq_one_iff] using sin_sq_add_cos_sq (π / 2) this.resolve_right fun h => show ¬(0 : ℝ) < -1 by norm_num <| h ▾ sin_pos_of_pos_of_lt_pi pi_div_two_pos (half_lt_self pi_pos) theorem sin_add_pi_div_two (x : ℝ) : sin (x + π / 2) = cos x := by simp [sin_add] theorem sin_sub_pi_div_two (x : ℝ) : sin (x - π / 2) = -cos x := by simp [sub_eq_add_neg, sin_add] theorem sin_pi_div_two_sub (x : ℝ) : sin (π / 2 - x) = cos x := by simp [sub_eq_add_neg, sin_add] theorem cos_add_pi_div_two (x : ℝ) : cos (x + π / 2) = -sin x := by simp [cos_add] theorem cos_sub_pi_div_two (x : ℝ) : cos (x - π / 2) = sin x := by simp [sub_eq_add_neg, cos_add] theorem cos_pi_div_two_sub (x : ℝ) : cos (π / 2 - x) = sin x := by rw [← cos_neg, neg_sub, cos_sub_pi_div_two] theorem cos_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo (-(π / 2)) (π / 2)) : 0 < cos x := sin_add_pi_div_two x ▾ sin_pos_of_mem_Ioo ⟹by linarith [hx.1], by linarith [hx.2]⟩ theorem cos_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : 0 ≀ cos x := sin_add_pi_div_two x ▾ sin_nonneg_of_mem_Icc ⟹by linarith [hx.1], by linarith [hx.2]⟩ theorem cos_nonneg_of_neg_pi_div_two_le_of_le {x : ℝ} (hl : -(π / 2) ≀ x) (hu : x ≀ π / 2) : 0 ≀ cos x := cos_nonneg_of_mem_Icc ⟹hl, hu⟩ theorem cos_neg_of_pi_div_two_lt_of_lt {x : ℝ} (hx₁ : π / 2 < x) (hx₂ : x < π + π / 2) : cos x < 0 := neg_pos.1 <| cos_pi_sub x ▾ cos_pos_of_mem_Ioo ⟹by linarith, by linarith⟩ theorem cos_nonpos_of_pi_div_two_le_of_le {x : ℝ} (hx₁ : π / 2 ≀ x) (hx₂ : x ≀ π + π / 2) : cos x ≀ 0 := neg_nonneg.1 <| cos_pi_sub x ▾ cos_nonneg_of_mem_Icc ⟹by linarith, by linarith⟩ theorem sin_eq_sqrt_one_sub_cos_sq {x : ℝ} (hl : 0 ≀ x) (hu : x ≀ π) : sin x = √(1 - cos x ^ 2) := by rw [← abs_sin_eq_sqrt_one_sub_cos_sq, abs_of_nonneg (sin_nonneg_of_nonneg_of_le_pi hl hu)] theorem cos_eq_sqrt_one_sub_sin_sq {x : ℝ} (hl : -(π / 2) ≀ x) (hu : x ≀ π / 2) : cos x = √(1 - sin x ^ 2) := by rw [← abs_cos_eq_sqrt_one_sub_sin_sq, abs_of_nonneg (cos_nonneg_of_mem_Icc ⟹hl, hu⟩)] lemma cos_half {x : ℝ} (hl : -π ≀ x) (hr : x ≀ π) : cos (x / 2) = sqrt ((1 + cos x) / 2) := by have : 0 ≀ cos (x / 2) := cos_nonneg_of_mem_Icc <| by constructor <;> linarith rw [← sqrt_sq this, cos_sq, add_div, two_mul, add_halves] lemma abs_sin_half (x : ℝ) : |sin (x / 2)| = sqrt ((1 - cos x) / 2) := by rw [← sqrt_sq_eq_abs, sin_sq_eq_half_sub, two_mul, add_halves, sub_div] lemma sin_half_eq_sqrt {x : ℝ} (hl : 0 ≀ x) (hr : x ≀ 2 * π) : sin (x / 2) = sqrt ((1 - cos x) / 2) := by rw [← abs_sin_half, abs_of_nonneg] apply sin_nonneg_of_nonneg_of_le_pi <;> linarith lemma sin_half_eq_neg_sqrt {x : ℝ} (hl : -(2 * π) ≀ x) (hr : x ≀ 0) : sin (x / 2) = -sqrt ((1 - cos x) / 2) := by rw [← abs_sin_half, abs_of_nonpos, neg_neg] apply sin_nonpos_of_nonnpos_of_neg_pi_le <;> linarith theorem sin_eq_zero_iff_of_lt_of_lt {x : ℝ} (hx₁ : -π < x) (hx₂ : x < π) : sin x = 0 ↔ x = 0 := ⟹fun h => by contrapose! h cases h.lt_or_lt with | inl h0 => exact (sin_neg_of_neg_of_neg_pi_lt h0 hx₁).ne | inr h0 => exact (sin_pos_of_pos_of_lt_pi h0 hx₂).ne', fun h => by simp [h]⟩ theorem sin_eq_zero_iff {x : ℝ} : sin x = 0 ↔ ∃ n : â„€, (n : ℝ) * π = x := ⟹fun h => ⟹⌊x / π⌋, le_antisymm (sub_nonneg.1 (Int.sub_floor_div_mul_nonneg _ pi_pos)) (sub_nonpos.1 <| le_of_not_gt fun h₃ => (sin_pos_of_pos_of_lt_pi h₃ (Int.sub_floor_div_mul_lt _ pi_pos)).ne (by simp [sub_eq_add_neg, sin_add, h, sin_int_mul_pi]))⟩, fun ⟹_, hn⟩ => hn ▾ sin_int_mul_pi _⟩ theorem sin_ne_zero_iff {x : ℝ} : sin x ≠ 0 ↔ ∀ n : â„€, (n : ℝ) * π ≠ x := by rw [← not_exists, not_iff_not, sin_eq_zero_iff] theorem sin_eq_zero_iff_cos_eq {x : ℝ} : sin x = 0 ↔ cos x = 1 √ cos x = -1 := by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq x, sq, sq, ← sub_eq_iff_eq_add, sub_self] exact ⟹fun h => by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ Eq.symm⟩ theorem cos_eq_one_iff (x : ℝ) : cos x = 1 ↔ ∃ n : â„€, (n : ℝ) * (2 * π) = x := ⟹fun h => let ⟹n, hn⟩ := sin_eq_zero_iff.1 (sin_eq_zero_iff_cos_eq.2 (Or.inl h)) ⟹n / 2, (Int.emod_two_eq_zero_or_one n).elim (fun hn0 => by rwa [← mul_assoc, ← @Int.cast_two ℝ, ← Int.cast_mul, Int.ediv_mul_cancel (Int.dvd_iff_emod_eq_zero.2 hn0)]) fun hn1 => by rw [← Int.emod_add_ediv n 2, hn1, Int.cast_add, Int.cast_one, add_mul, one_mul, add_comm, mul_comm (2 : â„€), Int.cast_mul, mul_assoc, Int.cast_two] at hn rw [← hn, cos_int_mul_two_pi_add_pi] at h exact absurd h (by norm_num)⟩, fun ⟹_, hn⟩ => hn ▾ cos_int_mul_two_pi _⟩ theorem cos_eq_one_iff_of_lt_of_lt {x : ℝ} (hx₁ : -(2 * π) < x) (hx₂ : x < 2 * π) : cos x = 1 ↔ x = 0 := ⟹fun h => by rcases (cos_eq_one_iff _).1 h with ⟹n, rfl⟩ rw [mul_lt_iff_lt_one_left two_pi_pos] at hx₂ rw [neg_lt, neg_mul_eq_neg_mul, mul_lt_iff_lt_one_left two_pi_pos] at hx₁ norm_cast at hx₁ hx₂ obtain rfl : n = 0 := le_antisymm (by omega) (by omega) simp, fun h => by simp [h]⟩ theorem sin_lt_sin_of_lt_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≀ x) (hy₂ : y ≀ π / 2) (hxy : x < y) : sin x < sin y := by rw [← sub_pos, sin_sub_sin] have : 0 < sin ((y - x) / 2) := by apply sin_pos_of_pos_of_lt_pi <;> linarith have : 0 < cos ((y + x) / 2) := by refine cos_pos_of_mem_Ioo ⟹?_, ?_⟩ <;> linarith positivity theorem strictMonoOn_sin : StrictMonoOn sin (Icc (-(π / 2)) (π / 2)) := fun _ hx _ hy hxy => sin_lt_sin_of_lt_of_le_pi_div_two hx.1 hy.2 hxy theorem cos_lt_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≀ x) (hy₂ : y ≀ π) (hxy : x < y) : cos y < cos x := by rw [← sin_pi_div_two_sub, ← sin_pi_div_two_sub] apply sin_lt_sin_of_lt_of_le_pi_div_two <;> linarith theorem cos_lt_cos_of_nonneg_of_le_pi_div_two {x y : ℝ} (hx₁ : 0 ≀ x) (hy₂ : y ≀ π / 2) (hxy : x < y) : cos y < cos x := cos_lt_cos_of_nonneg_of_le_pi hx₁ (hy₂.trans (by linarith)) hxy theorem strictAntiOn_cos : StrictAntiOn cos (Icc 0 π) := fun _ hx _ hy hxy => cos_lt_cos_of_nonneg_of_le_pi hx.1 hy.2 hxy theorem cos_le_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≀ x) (hy₂ : y ≀ π) (hxy : x ≀ y) : cos y ≀ cos x := (strictAntiOn_cos.le_iff_le ⟹hx₁.trans hxy, hy₂⟩ ⟹hx₁, hxy.trans hy₂⟩).2 hxy theorem sin_le_sin_of_le_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≀ x) (hy₂ : y ≀ π / 2) (hxy : x ≀ y) : sin x ≀ sin y := (strictMonoOn_sin.le_iff_le ⟹hx₁, hxy.trans hy₂⟩ ⟹hx₁.trans hxy, hy₂⟩).2 hxy theorem injOn_sin : InjOn sin (Icc (-(π / 2)) (π / 2)) := strictMonoOn_sin.injOn theorem injOn_cos : InjOn cos (Icc 0 π) := strictAntiOn_cos.injOn theorem surjOn_sin : SurjOn sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) := by simpa only [sin_neg, sin_pi_div_two] using intermediate_value_Icc (neg_le_self pi_div_two_pos.le) continuous_sin.continuousOn theorem surjOn_cos : SurjOn cos (Icc 0 π) (Icc (-1) 1) := by simpa only [cos_zero, cos_pi] using intermediate_value_Icc' pi_pos.le continuous_cos.continuousOn theorem sin_mem_Icc (x : ℝ) : sin x ∈ Icc (-1 : ℝ) 1 := ⟹neg_one_le_sin x, sin_le_one x⟩ theorem cos_mem_Icc (x : ℝ) : cos x ∈ Icc (-1 : ℝ) 1 := ⟹neg_one_le_cos x, cos_le_one x⟩ theorem mapsTo_sin (s : Set ℝ) : MapsTo sin s (Icc (-1 : ℝ) 1) := fun x _ => sin_mem_Icc x theorem mapsTo_cos (s : Set ℝ) : MapsTo cos s (Icc (-1 : ℝ) 1) := fun x _ => cos_mem_Icc x theorem bijOn_sin : BijOn sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) := ⟹mapsTo_sin _, injOn_sin, surjOn_sin⟩ theorem bijOn_cos : BijOn cos (Icc 0 π) (Icc (-1) 1) := ⟹mapsTo_cos _, injOn_cos, surjOn_cos⟩ @[simp] theorem range_cos : range cos = (Icc (-1) 1 : Set ℝ) := Subset.antisymm (range_subset_iff.2 cos_mem_Icc) surjOn_cos.subset_range @[simp] theorem range_sin : range sin = (Icc (-1) 1 : Set ℝ) := Subset.antisymm (range_subset_iff.2 sin_mem_Icc) surjOn_sin.subset_range theorem range_cos_infinite : (range Real.cos).Infinite := by rw [Real.range_cos] exact Icc_infinite (by norm_num) theorem range_sin_infinite : (range Real.sin).Infinite := by rw [Real.range_sin] exact Icc_infinite (by norm_num) section CosDivSq variable (x : ℝ) /-- the series `sqrtTwoAddSeries x n` is `sqrt(2 + sqrt(2 + ... ))` with `n` square roots, starting with `x`. We define it here because `cos (pi / 2 ^ (n+1)) = sqrtTwoAddSeries 0 n / 2` -/ @[simp] noncomputable def sqrtTwoAddSeries (x : ℝ) : ℕ → ℝ | 0 => x | n + 1 => √(2 + sqrtTwoAddSeries x n) theorem sqrtTwoAddSeries_zero : sqrtTwoAddSeries x 0 = x := by simp theorem sqrtTwoAddSeries_one : sqrtTwoAddSeries 0 1 = √2 := by simp theorem sqrtTwoAddSeries_two : sqrtTwoAddSeries 0 2 = √(2 + √2) := by simp theorem sqrtTwoAddSeries_zero_nonneg : ∀ n : ℕ, 0 ≀ sqrtTwoAddSeries 0 n | 0 => le_refl 0 | _ + 1 => sqrt_nonneg _ theorem sqrtTwoAddSeries_nonneg {x : ℝ} (h : 0 ≀ x) : ∀ n : ℕ, 0 ≀ sqrtTwoAddSeries x n | 0 => h | _ + 1 => sqrt_nonneg _ theorem sqrtTwoAddSeries_lt_two : ∀ n : ℕ, sqrtTwoAddSeries 0 n < 2 | 0 => by norm_num | n + 1 => by refine lt_of_lt_of_le ?_ (sqrt_sq zero_lt_two.le).le rw [sqrtTwoAddSeries, sqrt_lt_sqrt_iff, ← lt_sub_iff_add_lt'] · refine (sqrtTwoAddSeries_lt_two n).trans_le ?_ norm_num · exact add_nonneg zero_le_two (sqrtTwoAddSeries_zero_nonneg n) theorem sqrtTwoAddSeries_succ (x : ℝ) : ∀ n : ℕ, sqrtTwoAddSeries x (n + 1) = sqrtTwoAddSeries (√(2 + x)) n | 0 => rfl | n + 1 => by rw [sqrtTwoAddSeries, sqrtTwoAddSeries_succ _ _, sqrtTwoAddSeries] theorem sqrtTwoAddSeries_monotone_left {x y : ℝ} (h : x ≀ y) : ∀ n : ℕ, sqrtTwoAddSeries x n ≀ sqrtTwoAddSeries y n | 0 => h | n + 1 => by rw [sqrtTwoAddSeries, sqrtTwoAddSeries] exact sqrt_le_sqrt (add_le_add_left (sqrtTwoAddSeries_monotone_left h _) _) @[simp] theorem cos_pi_over_two_pow : ∀ n : ℕ, cos (π / 2 ^ (n + 1)) = sqrtTwoAddSeries 0 n / 2 | 0 => by simp | n + 1 => by have A : (1 : ℝ) < 2 ^ (n + 1) := one_lt_pow₀ one_lt_two n.succ_ne_zero have B : π / 2 ^ (n + 1) < π := div_lt_self pi_pos A have C : 0 < π / 2 ^ (n + 1) := by positivity rw [pow_succ, div_mul_eq_div_div, cos_half, cos_pi_over_two_pow n, sqrtTwoAddSeries, add_div_eq_mul_add_div, one_mul, ← div_mul_eq_div_div, sqrt_div, sqrt_mul_self] <;> linarith [sqrtTwoAddSeries_nonneg le_rfl n] theorem sin_sq_pi_over_two_pow (n : ℕ) : sin (π / 2 ^ (n + 1)) ^ 2 = 1 - (sqrtTwoAddSeries 0 n / 2) ^ 2 := by rw [sin_sq, cos_pi_over_two_pow] theorem sin_sq_pi_over_two_pow_succ (n : ℕ) : sin (π / 2 ^ (n + 2)) ^ 2 = 1 / 2 - sqrtTwoAddSeries 0 n / 4 := by rw [sin_sq_pi_over_two_pow, sqrtTwoAddSeries, div_pow, sq_sqrt, add_div, ← sub_sub] · congr · norm_num · norm_num · exact add_nonneg two_pos.le (sqrtTwoAddSeries_zero_nonneg _) @[simp] theorem sin_pi_over_two_pow_succ (n : ℕ) : sin (π / 2 ^ (n + 2)) = √(2 - sqrtTwoAddSeries 0 n) / 2 := by rw [eq_div_iff_mul_eq two_ne_zero, eq_comm, sqrt_eq_iff_eq_sq, mul_pow, sin_sq_pi_over_two_pow_succ, sub_mul] · congr <;> norm_num · rw [sub_nonneg] exact (sqrtTwoAddSeries_lt_two _).le refine mul_nonneg (sin_nonneg_of_nonneg_of_le_pi ?_ ?_) zero_le_two · positivity · exact div_le_self pi_pos.le <| one_le_pow₀ one_le_two @[simp] theorem cos_pi_div_four : cos (π / 4) = √2 / 2 := by trans cos (π / 2 ^ 2) · congr norm_num · simp @[simp] theorem sin_pi_div_four : sin (π / 4) = √2 / 2 := by trans sin (π / 2 ^ 2) · congr norm_num · simp @[simp] theorem cos_pi_div_eight : cos (π / 8) = √(2 + √2) / 2 := by trans cos (π / 2 ^ 3) · congr norm_num · simp @[simp] theorem sin_pi_div_eight : sin (π / 8) = √(2 - √2) / 2 := by trans sin (π / 2 ^ 3) · congr norm_num · simp @[simp] theorem cos_pi_div_sixteen : cos (π / 16) = √(2 + √(2 + √2)) / 2 := by trans cos (π / 2 ^ 4) · congr norm_num · simp @[simp] theorem sin_pi_div_sixteen : sin (π / 16) = √(2 - √(2 + √2)) / 2 := by trans sin (π / 2 ^ 4) · congr norm_num · simp @[simp] theorem cos_pi_div_thirty_two : cos (π / 32) = √(2 + √(2 + √(2 + √2))) / 2 := by trans cos (π / 2 ^ 5) · congr norm_num · simp @[simp] theorem sin_pi_div_thirty_two : sin (π / 32) = √(2 - √(2 + √(2 + √2))) / 2 := by trans sin (π / 2 ^ 5) · congr norm_num · simp -- This section is also a convenient location for other explicit values of `sin` and `cos`. /-- The cosine of `π / 3` is `1 / 2`. -/ @[simp] theorem cos_pi_div_three : cos (π / 3) = 1 / 2 := by have h₁ : (2 * cos (π / 3) - 1) ^ 2 * (2 * cos (π / 3) + 2) = 0 := by have : cos (3 * (π / 3)) = cos π := by congr 1 ring linarith [cos_pi, cos_three_mul (π / 3)] rcases mul_eq_zero.mp h₁ with h | h · linarith [pow_eq_zero h] · have : cos π < cos (π / 3) := by refine cos_lt_cos_of_nonneg_of_le_pi ?_ le_rfl ?_ <;> linarith [pi_pos] linarith [cos_pi] /-- The cosine of `π / 6` is `√3 / 2`. -/ @[simp] theorem cos_pi_div_six : cos (π / 6) = √3 / 2 := by rw [show (6 : ℝ) = 3 * 2 by norm_num, div_mul_eq_div_div, cos_half, cos_pi_div_three, one_add_div, ← div_mul_eq_div_div, two_add_one_eq_three, sqrt_div, sqrt_mul_self] <;> linarith [pi_pos] /-- The square of the cosine of `π / 6` is `3 / 4` (this is sometimes more convenient than the result for cosine itself). -/ theorem sq_cos_pi_div_six : cos (π / 6) ^ 2 = 3 / 4 := by rw [cos_pi_div_six, div_pow, sq_sqrt] <;> norm_num /-- The sine of `π / 6` is `1 / 2`. -/ @[simp] theorem sin_pi_div_six : sin (π / 6) = 1 / 2 := by rw [← cos_pi_div_two_sub, ← cos_pi_div_three] congr ring /-- The square of the sine of `π / 3` is `3 / 4` (this is sometimes more convenient than the result for cosine itself). -/ theorem sq_sin_pi_div_three : sin (π / 3) ^ 2 = 3 / 4 := by rw [← cos_pi_div_two_sub, ← sq_cos_pi_div_six] congr ring /-- The sine of `π / 3` is `√3 / 2`. -/ @[simp] theorem sin_pi_div_three : sin (π / 3) = √3 / 2 := by rw [← cos_pi_div_two_sub, ← cos_pi_div_six] congr ring theorem quadratic_root_cos_pi_div_five : letI c := cos (π / 5) 4 * c ^ 2 - 2 * c - 1 = 0 := by set Ξ := π / 5 with hΞ set c := cos Ξ set s := sin Ξ suffices 2 * c = 4 * c ^ 2 - 1 by simp [this] have hs : s ≠ 0 := by rw [ne_eq, sin_eq_zero_iff, hΞ] push_neg intro n hn replace hn : n * 5 = 1 := by field_simp [mul_comm _ π, mul_assoc] at hn; norm_cast at hn omega suffices s * (2 * c) = s * (4 * c ^ 2 - 1) from mul_left_cancel₀ hs this calc s * (2 * c) = 2 * s * c := by rw [← mul_assoc, mul_comm 2] _ = sin (2 * Ξ) := by rw [sin_two_mul] _ = sin (π - 2 * Ξ) := by rw [sin_pi_sub] _ = sin (2 * Ξ + Ξ) := by congr; field_simp [hΞ]; linarith _ = sin (2 * Ξ) * c + cos (2 * Ξ) * s := sin_add (2 * Ξ) Ξ _ = 2 * s * c * c + cos (2 * Ξ) * s := by rw [sin_two_mul] _ = 2 * s * c * c + (2 * c ^ 2 - 1) * s := by rw [cos_two_mul] _ = s * (2 * c * c) + s * (2 * c ^ 2 - 1) := by linarith _ = s * (4 * c ^ 2 - 1) := by linarith open Polynomial in theorem Polynomial.isRoot_cos_pi_div_five : (4 • X ^ 2 - 2 • X - C 1 : ℝ[X]).IsRoot (cos (π / 5)) := by simpa using quadratic_root_cos_pi_div_five /-- The cosine of `π / 5` is `(1 + √5) / 4`. -/ @[simp] theorem cos_pi_div_five : cos (π / 5) = (1 + √5) / 4 := by set c := cos (π / 5) have : 4 * (c * c) + (-2) * c + (-1) = 0 := by rw [← sq, neg_mul, ← sub_eq_add_neg, ← sub_eq_add_neg] exact quadratic_root_cos_pi_div_five have hd : discrim 4 (-2) (-1) = (2 * √5) * (2 * √5) := by norm_num [discrim, mul_mul_mul_comm] rcases (quadratic_eq_zero_iff (by norm_num) hd c).mp this with h | h · field_simp [h]; linarith · absurd (show 0 ≀ c from cos_nonneg_of_mem_Icc <| by constructor <;> linarith [pi_pos.le]) rw [not_le, h] exact div_neg_of_neg_of_pos (by norm_num [lt_sqrt]) (by positivity) end CosDivSq /-- `Real.sin` as an `OrderIso` between `[-(π / 2), π / 2]` and `[-1, 1]`. -/ def sinOrderIso : Icc (-(π / 2)) (π / 2) ≃o Icc (-1 : ℝ) 1 := (strictMonoOn_sin.orderIso _ _).trans <| OrderIso.setCongr _ _ bijOn_sin.image_eq @[simp] theorem coe_sinOrderIso_apply (x : Icc (-(π / 2)) (π / 2)) : (sinOrderIso x : ℝ) = sin x := rfl theorem sinOrderIso_apply (x : Icc (-(π / 2)) (π / 2)) : sinOrderIso x = ⟹sin x, sin_mem_Icc x⟩ := rfl @[simp] theorem tan_pi_div_four : tan (π / 4) = 1 := by rw [tan_eq_sin_div_cos, cos_pi_div_four, sin_pi_div_four] have h : √2 / 2 > 0 := by positivity exact div_self (ne_of_gt h) @[simp] theorem tan_pi_div_two : tan (π / 2) = 0 := by simp [tan_eq_sin_div_cos] @[simp] theorem tan_pi_div_six : tan (π / 6) = 1 / sqrt 3 := by rw [tan_eq_sin_div_cos, sin_pi_div_six, cos_pi_div_six] ring @[simp] theorem tan_pi_div_three : tan (π / 3) = sqrt 3 := by rw [tan_eq_sin_div_cos, sin_pi_div_three, cos_pi_div_three] ring theorem tan_pos_of_pos_of_lt_pi_div_two {x : ℝ} (h0x : 0 < x) (hxp : x < π / 2) : 0 < tan x := by rw [tan_eq_sin_div_cos] exact div_pos (sin_pos_of_pos_of_lt_pi h0x (by linarith)) (cos_pos_of_mem_Ioo ⟹by linarith, hxp⟩) theorem tan_nonneg_of_nonneg_of_le_pi_div_two {x : ℝ} (h0x : 0 ≀ x) (hxp : x ≀ π / 2) : 0 ≀ tan x := match lt_or_eq_of_le h0x, lt_or_eq_of_le hxp with | Or.inl hx0, Or.inl hxp => le_of_lt (tan_pos_of_pos_of_lt_pi_div_two hx0 hxp) | Or.inl _, Or.inr hxp => by simp [hxp, tan_eq_sin_div_cos] | Or.inr hx0, _ => by simp [hx0.symm] theorem tan_neg_of_neg_of_pi_div_two_lt {x : ℝ} (hx0 : x < 0) (hpx : -(π / 2) < x) : tan x < 0 := neg_pos.1 (tan_neg x ▾ tan_pos_of_pos_of_lt_pi_div_two (by linarith) (by linarith [pi_pos])) theorem tan_nonpos_of_nonpos_of_neg_pi_div_two_le {x : ℝ} (hx0 : x ≀ 0) (hpx : -(π / 2) ≀ x) : tan x ≀ 0 := neg_nonneg.1 (tan_neg x ▾ tan_nonneg_of_nonneg_of_le_pi_div_two (by linarith) (by linarith)) theorem strictMonoOn_tan : StrictMonoOn tan (Ioo (-(π / 2)) (π / 2)) := by rintro x hx y hy hlt rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos, div_lt_div_iff₀ (cos_pos_of_mem_Ioo hx) (cos_pos_of_mem_Ioo hy), mul_comm, ← sub_pos, ← sin_sub] exact sin_pos_of_pos_of_lt_pi (sub_pos.2 hlt) <| by linarith [hx.1, hy.2] theorem tan_lt_tan_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) < x) (hy₂ : y < π / 2) (hxy : x < y) : tan x < tan y := strictMonoOn_tan ⟹hx₁, hxy.trans hy₂⟩ ⟹hx₁.trans hxy, hy₂⟩ hxy theorem tan_lt_tan_of_nonneg_of_lt_pi_div_two {x y : ℝ} (hx₁ : 0 ≀ x) (hy₂ : y < π / 2) (hxy : x < y) : tan x < tan y := tan_lt_tan_of_lt_of_lt_pi_div_two (by linarith) hy₂ hxy theorem injOn_tan : InjOn tan (Ioo (-(π / 2)) (π / 2)) := strictMonoOn_tan.injOn theorem tan_inj_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2) (hy₁ : -(π / 2) < y) (hy₂ : y < π / 2) (hxy : tan x = tan y) : x = y := injOn_tan ⟹hx₁, hx₂⟩ ⟹hy₁, hy₂⟩ hxy theorem tan_periodic : Function.Periodic tan π := by simpa only [Function.Periodic, tan_eq_sin_div_cos] using sin_antiperiodic.div cos_antiperiodic @[simp] theorem tan_pi : tan π = 0 := by rw [tan_periodic.eq, tan_zero] theorem tan_add_pi (x : ℝ) : tan (x + π) = tan x := tan_periodic x theorem tan_sub_pi (x : ℝ) : tan (x - π) = tan x := tan_periodic.sub_eq x theorem tan_pi_sub (x : ℝ) : tan (π - x) = -tan x := tan_neg x ▾ tan_periodic.sub_eq' theorem tan_pi_div_two_sub (x : ℝ) : tan (π / 2 - x) = (tan x)⁻¹ := by rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos, inv_div, sin_pi_div_two_sub, cos_pi_div_two_sub] theorem tan_nat_mul_pi (n : ℕ) : tan (n * π) = 0 := tan_zero ▾ tan_periodic.nat_mul_eq n theorem tan_int_mul_pi (n : â„€) : tan (n * π) = 0 := tan_zero ▾ tan_periodic.int_mul_eq n theorem tan_add_nat_mul_pi (x : ℝ) (n : ℕ) : tan (x + n * π) = tan x := tan_periodic.nat_mul n x theorem tan_add_int_mul_pi (x : ℝ) (n : â„€) : tan (x + n * π) = tan x := tan_periodic.int_mul n x theorem tan_sub_nat_mul_pi (x : ℝ) (n : ℕ) : tan (x - n * π) = tan x := tan_periodic.sub_nat_mul_eq n theorem tan_sub_int_mul_pi (x : ℝ) (n : â„€) : tan (x - n * π) = tan x := tan_periodic.sub_int_mul_eq n theorem tan_nat_mul_pi_sub (x : ℝ) (n : ℕ) : tan (n * π - x) = -tan x := tan_neg x ▾ tan_periodic.nat_mul_sub_eq n theorem tan_int_mul_pi_sub (x : ℝ) (n : â„€) : tan (n * π - x) = -tan x := tan_neg x ▾ tan_periodic.int_mul_sub_eq n theorem tendsto_sin_pi_div_two : Tendsto sin (𝓝[<] (π / 2)) (𝓝 1) := by convert continuous_sin.continuousWithinAt.tendsto simp theorem tendsto_cos_pi_div_two : Tendsto cos (𝓝[<] (π / 2)) (𝓝[>] 0) := by apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within · convert continuous_cos.continuousWithinAt.tendsto simp · filter_upwards [Ioo_mem_nhdsLT (neg_lt_self pi_div_two_pos)] with x hx exact cos_pos_of_mem_Ioo hx theorem tendsto_tan_pi_div_two : Tendsto tan (𝓝[<] (π / 2)) atTop := by convert tendsto_cos_pi_div_two.inv_tendsto_nhdsGT_zero.atTop_mul_pos zero_lt_one tendsto_sin_pi_div_two using 1 simp only [Pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos] theorem tendsto_sin_neg_pi_div_two : Tendsto sin (𝓝[>] (-(π / 2))) (𝓝 (-1)) := by convert continuous_sin.continuousWithinAt.tendsto using 2 simp theorem tendsto_cos_neg_pi_div_two : Tendsto cos (𝓝[>] (-(π / 2))) (𝓝[>] 0) := by apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within · convert continuous_cos.continuousWithinAt.tendsto simp · filter_upwards [Ioo_mem_nhdsGT (neg_lt_self pi_div_two_pos)] with x hx exact cos_pos_of_mem_Ioo hx theorem tendsto_tan_neg_pi_div_two : Tendsto tan (𝓝[>] (-(π / 2))) atBot := by convert tendsto_cos_neg_pi_div_two.inv_tendsto_nhdsGT_zero.atTop_mul_neg (by norm_num) tendsto_sin_neg_pi_div_two using 1 simp only [Pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos] end Real namespace Complex open Real theorem sin_eq_zero_iff_cos_eq {z : ℂ} : sin z = 0 ↔ cos z = 1 √ cos z = -1 := by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq, sq, sq, ← sub_eq_iff_eq_add, sub_self] exact ⟹fun h => by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ Eq.symm⟩ @[simp] theorem cos_pi_div_two : cos (π / 2) = 0 := calc cos (π / 2) = Real.cos (π / 2) := by rw [ofReal_cos]; simp _ = 0 := by simp @[simp] theorem sin_pi_div_two : sin (π / 2) = 1 := calc sin (π / 2) = Real.sin (π / 2) := by rw [ofReal_sin]; simp _ = 1 := by simp @[simp] theorem sin_pi : sin π = 0 := by rw [← ofReal_sin, Real.sin_pi]; simp @[simp] theorem cos_pi : cos π = -1 := by rw [← ofReal_cos, Real.cos_pi]; simp @[simp] theorem sin_two_pi : sin (2 * π) = 0 := by simp [two_mul, sin_add] @[simp] theorem cos_two_pi : cos (2 * π) = 1 := by simp [two_mul, cos_add] theorem sin_antiperiodic : Function.Antiperiodic sin π := by simp [sin_add] theorem sin_periodic : Function.Periodic sin (2 * π) := sin_antiperiodic.periodic_two_mul theorem sin_add_pi (x : ℂ) : sin (x + π) = -sin x := sin_antiperiodic x theorem sin_add_two_pi (x : ℂ) : sin (x + 2 * π) = sin x := sin_periodic x theorem sin_sub_pi (x : ℂ) : sin (x - π) = -sin x := sin_antiperiodic.sub_eq x theorem sin_sub_two_pi (x : ℂ) : sin (x - 2 * π) = sin x := sin_periodic.sub_eq x theorem sin_pi_sub (x : ℂ) : sin (π - x) = sin x := neg_neg (sin x) ▾ sin_neg x ▾ sin_antiperiodic.sub_eq' theorem sin_two_pi_sub (x : ℂ) : sin (2 * π - x) = -sin x := sin_neg x ▾ sin_periodic.sub_eq' theorem sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 := sin_antiperiodic.nat_mul_eq_of_eq_zero sin_zero n theorem sin_int_mul_pi (n : â„€) : sin (n * π) = 0 := sin_antiperiodic.int_mul_eq_of_eq_zero sin_zero n theorem sin_add_nat_mul_two_pi (x : ℂ) (n : ℕ) : sin (x + n * (2 * π)) = sin x := sin_periodic.nat_mul n x theorem sin_add_int_mul_two_pi (x : ℂ) (n : â„€) : sin (x + n * (2 * π)) = sin x := sin_periodic.int_mul n x theorem sin_sub_nat_mul_two_pi (x : ℂ) (n : ℕ) : sin (x - n * (2 * π)) = sin x := sin_periodic.sub_nat_mul_eq n theorem sin_sub_int_mul_two_pi (x : ℂ) (n : â„€) : sin (x - n * (2 * π)) = sin x := sin_periodic.sub_int_mul_eq n theorem sin_nat_mul_two_pi_sub (x : ℂ) (n : ℕ) : sin (n * (2 * π) - x) = -sin x := sin_neg x ▾ sin_periodic.nat_mul_sub_eq n theorem sin_int_mul_two_pi_sub (x : ℂ) (n : â„€) : sin (n * (2 * π) - x) = -sin x := sin_neg x ▾ sin_periodic.int_mul_sub_eq n theorem cos_antiperiodic : Function.Antiperiodic cos π := by simp [cos_add] theorem cos_periodic : Function.Periodic cos (2 * π) := cos_antiperiodic.periodic_two_mul theorem cos_add_pi (x : ℂ) : cos (x + π) = -cos x := cos_antiperiodic x theorem cos_add_two_pi (x : ℂ) : cos (x + 2 * π) = cos x := cos_periodic x theorem cos_sub_pi (x : ℂ) : cos (x - π) = -cos x := cos_antiperiodic.sub_eq x theorem cos_sub_two_pi (x : ℂ) : cos (x - 2 * π) = cos x := cos_periodic.sub_eq x theorem cos_pi_sub (x : ℂ) : cos (π - x) = -cos x := cos_neg x ▾ cos_antiperiodic.sub_eq' theorem cos_two_pi_sub (x : ℂ) : cos (2 * π - x) = cos x := cos_neg x ▾ cos_periodic.sub_eq' theorem cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 := (cos_periodic.nat_mul_eq n).trans cos_zero theorem cos_int_mul_two_pi (n : â„€) : cos (n * (2 * π)) = 1 := (cos_periodic.int_mul_eq n).trans cos_zero theorem cos_add_nat_mul_two_pi (x : ℂ) (n : ℕ) : cos (x + n * (2 * π)) = cos x := cos_periodic.nat_mul n x theorem cos_add_int_mul_two_pi (x : ℂ) (n : â„€) : cos (x + n * (2 * π)) = cos x := cos_periodic.int_mul n x theorem cos_sub_nat_mul_two_pi (x : ℂ) (n : ℕ) : cos (x - n * (2 * π)) = cos x := cos_periodic.sub_nat_mul_eq n theorem cos_sub_int_mul_two_pi (x : ℂ) (n : â„€) : cos (x - n * (2 * π)) = cos x := cos_periodic.sub_int_mul_eq n theorem cos_nat_mul_two_pi_sub (x : ℂ) (n : ℕ) : cos (n * (2 * π) - x) = cos x := cos_neg x ▾ cos_periodic.nat_mul_sub_eq n theorem cos_int_mul_two_pi_sub (x : ℂ) (n : â„€) : cos (n * (2 * π) - x) = cos x := cos_neg x ▾ cos_periodic.int_mul_sub_eq n theorem cos_nat_mul_two_pi_add_pi (n : ℕ) : cos (n * (2 * π) + π) = -1 := by simpa only [cos_zero] using (cos_periodic.nat_mul n).add_antiperiod_eq cos_antiperiodic theorem cos_int_mul_two_pi_add_pi (n : â„€) : cos (n * (2 * π) + π) = -1 := by simpa only [cos_zero] using (cos_periodic.int_mul n).add_antiperiod_eq cos_antiperiodic theorem cos_nat_mul_two_pi_sub_pi (n : ℕ) : cos (n * (2 * π) - π) = -1 := by simpa only [cos_zero] using (cos_periodic.nat_mul n).sub_antiperiod_eq cos_antiperiodic theorem cos_int_mul_two_pi_sub_pi (n : â„€) : cos (n * (2 * π) - π) = -1 := by simpa only [cos_zero] using (cos_periodic.int_mul n).sub_antiperiod_eq cos_antiperiodic theorem sin_add_pi_div_two (x : ℂ) : sin (x + π / 2) = cos x := by simp [sin_add] theorem sin_sub_pi_div_two (x : ℂ) : sin (x - π / 2) = -cos x := by simp [sub_eq_add_neg, sin_add] theorem sin_pi_div_two_sub (x : ℂ) : sin (π / 2 - x) = cos x := by simp [sub_eq_add_neg, sin_add] theorem cos_add_pi_div_two (x : ℂ) : cos (x + π / 2) = -sin x := by simp [cos_add] theorem cos_sub_pi_div_two (x : ℂ) : cos (x - π / 2) = sin x := by simp [sub_eq_add_neg, cos_add] theorem cos_pi_div_two_sub (x : ℂ) : cos (π / 2 - x) = sin x := by rw [← cos_neg, neg_sub, cos_sub_pi_div_two] theorem tan_periodic : Function.Periodic tan π := by simpa only [tan_eq_sin_div_cos] using sin_antiperiodic.div cos_antiperiodic theorem tan_add_pi (x : ℂ) : tan (x + π) = tan x := tan_periodic x theorem tan_sub_pi (x : ℂ) : tan (x - π) = tan x := tan_periodic.sub_eq x theorem tan_pi_sub (x : ℂ) : tan (π - x) = -tan x := tan_neg x ▾ tan_periodic.sub_eq' theorem tan_pi_div_two_sub (x : ℂ) : tan (π / 2 - x) = (tan x)⁻¹ := by rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos, inv_div, sin_pi_div_two_sub, cos_pi_div_two_sub] theorem tan_nat_mul_pi (n : ℕ) : tan (n * π) = 0 :=
tan_zero ▾ tan_periodic.nat_mul_eq n
Mathlib/Analysis/SpecialFunctions/Trigonometric/Basic.lean
1,150
1,150
/- 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.Complex /-! # The `arctan` function. Inequalities, identities and `Real.tan` as a `PartialHomeomorph` between `(-(π / 2), π / 2)` and the whole line. The result of `arctan x + arctan y` is given by `arctan_add`, `arctan_add_eq_add_pi` or `arctan_add_eq_sub_pi` depending on whether `x * y < 1` and `0 < x`. As an application of `arctan_add` we give four Machin-like formulas (linear combinations of arctangents equal to `π / 4 = arctan 1`), including John Machin's original one at `four_mul_arctan_inv_5_sub_arctan_inv_239`. -/ noncomputable section namespace Real open Set Filter open scoped Topology Real theorem tan_add {x y : ℝ} (h : ((∀ k : â„€, x ≠ (2 * k + 1) * π / 2) ∧ ∀ l : â„€, y ≠ (2 * l + 1) * π / 2) √ (∃ k : â„€, x = (2 * k + 1) * π / 2) ∧ ∃ l : â„€, y = (2 * l + 1) * π / 2) : tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) := by simpa only [← Complex.ofReal_inj, Complex.ofReal_sub, Complex.ofReal_add, Complex.ofReal_div, Complex.ofReal_mul, Complex.ofReal_tan] using @Complex.tan_add (x : ℂ) (y : ℂ) (by convert h <;> norm_cast) theorem tan_add' {x y : ℝ} (h : (∀ k : â„€, x ≠ (2 * k + 1) * π / 2) ∧ ∀ l : â„€, y ≠ (2 * l + 1) * π / 2) : tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) := tan_add (Or.inl h) theorem tan_two_mul {x : ℝ} : tan (2 * x) = 2 * tan x / (1 - tan x ^ 2) := by have := @Complex.tan_two_mul x norm_cast at * theorem tan_int_mul_pi_div_two (n : â„€) : tan (n * π / 2) = 0 := tan_eq_zero_iff.mpr (by use n) theorem continuousOn_tan : ContinuousOn tan {x | cos x ≠ 0} := by suffices ContinuousOn (fun x => sin x / cos x) {x | cos x ≠ 0} by have h_eq : (fun x => sin x / cos x) = tan := by ext1 x; rw [tan_eq_sin_div_cos] rwa [h_eq] at this exact continuousOn_sin.div continuousOn_cos fun x => id @[continuity] theorem continuous_tan : Continuous fun x : {x | cos x ≠ 0} => tan x := continuousOn_iff_continuous_restrict.1 continuousOn_tan theorem continuousOn_tan_Ioo : ContinuousOn tan (Ioo (-(π / 2)) (π / 2)) := by refine ContinuousOn.mono continuousOn_tan fun x => ?_ simp only [and_imp, mem_Ioo, mem_setOf_eq, Ne] rw [cos_eq_zero_iff] rintro hx_gt hx_lt ⟹r, hxr_eq⟩ rcases le_or_lt 0 r with h | h · rw [lt_iff_not_ge] at hx_lt refine hx_lt ?_
rw [hxr_eq, ← one_mul (π / 2), mul_div_assoc, ge_iff_le, mul_le_mul_right (half_pos pi_pos)] simp [h] · rw [lt_iff_not_ge] at hx_gt refine hx_gt ?_ rw [hxr_eq, ← one_mul (π / 2), mul_div_assoc, ge_iff_le, neg_mul_eq_neg_mul, mul_le_mul_right (half_pos pi_pos)] have hr_le : r ≀ -1 := by rwa [Int.lt_iff_add_one_le, ← le_neg_iff_add_nonpos_right] at h rw [← le_sub_iff_add_le, mul_comm, ← le_div_iff₀] · norm_num rw [← Int.cast_one, ← Int.cast_neg]; norm_cast · exact zero_lt_two theorem surjOn_tan : SurjOn tan (Ioo (-(π / 2)) (π / 2)) univ := have := neg_lt_self pi_div_two_pos continuousOn_tan_Ioo.surjOn_of_tendsto (nonempty_Ioo.2 this) (by rw [tendsto_comp_coe_Ioo_atBot this]; exact tendsto_tan_neg_pi_div_two) (by rw [tendsto_comp_coe_Ioo_atTop this]; exact tendsto_tan_pi_div_two) theorem tan_surjective : Function.Surjective tan := fun _ => surjOn_tan.subset_range trivial
Mathlib/Analysis/SpecialFunctions/Trigonometric/Arctan.lean
68
86
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne -/ import Mathlib.MeasureTheory.Integral.Bochner.Basic import Mathlib.MeasureTheory.Integral.Bochner.L1 import Mathlib.MeasureTheory.Integral.Bochner.VitaliCaratheodory deprecated_module (since := "2025-04-13")
Mathlib/MeasureTheory/Integral/Bochner.lean
1,143
1,163
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.ExactSequence import Mathlib.Algebra.Homology.ShortComplex.Limits import Mathlib.CategoryTheory.Abelian.Refinements /-! # The snake lemma The snake lemma is a standard tool in homological algebra. The basic situation is when we have a diagram as follows in an abelian category `C`, with exact rows: L₁.X₁ ⟶ L₁.X₂ ⟶ L₁.X₃ ⟶ 0 | | | |v₁₂.τ₁ |v₁₂.τ₂ |v₁₂.τ₃ v v v 0 ⟶ L₂.X₁ ⟶ L₂.X₂ ⟶ L₂.X₃ We shall think of this diagram as the datum of a morphism `v₁₂ : L₁ ⟶ L₂` in the category `ShortComplex C` such that both `L₁` and `L₂` are exact, and `L₁.g` is epi and `L₂.f` is a mono (which is equivalent to saying that `L₁.X₃` is the cokernel of `L₁.f` and `L₂.X₁` is the kernel of `L₂.g`). Then, we may introduce the kernels and cokernels of the vertical maps. In other words, we may introduce short complexes `L₀` and `L₃` that are respectively the kernel and the cokernel of `v₁₂`. All these data constitute a `SnakeInput C`. Given such a `S : SnakeInput C`, we define a connecting homomorphism `S.ÎŽ : L₀.X₃ ⟶ L₃.X₁` and show that it is part of an exact sequence `L₀.X₁ ⟶ L₀.X₂ ⟶ L₀.X₃ ⟶ L₃.X₁ ⟶ L₃.X₂ ⟶ L₃.X₃`. Each of the four exactness statement is first stated separately as lemmas `L₀_exact`, `L₁'_exact`, `L₂'_exact` and `L₃_exact` and the full 6-term exact sequence is stated as `snake_lemma`. This sequence can even be extended with an extra `0` on the left (see `mono_L₀_f`) if `L₁.X₁ ⟶ L₁.X₂` is a mono (i.e. `L₁` is short exact), and similarly an extra `0` can be added on the right (`epi_L₃_g`) if `L₂.X₂ ⟶ L₂.X₃` is an epi (i.e. `L₂` is short exact). These results were also obtained in the Liquid Tensor Experiment. The code and the proof here are slightly easier because of the use of the category `ShortComplex C`, the use of duality (which allows to construct only half of the sequence, and deducing the other half by arguing in the opposite category), and the use of "refinements" (see `CategoryTheory.Abelian.Refinements`) instead of a weak form of pseudo-elements. -/ namespace CategoryTheory open Category Limits Preadditive variable (C : Type*) [Category C] [Abelian C] namespace ShortComplex /-- A snake input in an abelian category `C` consists of morphisms of short complexes `L₀ ⟶ L₁ ⟶ L₂ ⟶ L₃` (which should be visualized vertically) such that `L₀` and `L₃` are respectively the kernel and the cokernel of `L₁ ⟶ L₂`, `L₁` and `L₂` are exact, `L₁.g` is epi and `L₂.f` is mono. -/ structure SnakeInput where /-- the zeroth row -/ L₀ : ShortComplex C /-- the first row -/ L₁ : ShortComplex C /-- the second row -/ L₂ : ShortComplex C /-- the third row -/ L₃ : ShortComplex C /-- the morphism from the zeroth row to the first row -/ v₀₁ : L₀ ⟶ L₁ /-- the morphism from the first row to the second row -/ v₁₂ : L₁ ⟶ L₂ /-- the morphism from the second row to the third row -/ v₂₃ : L₂ ⟶ L₃ w₀₂ : v₀₁ ≫ v₁₂ = 0 := by aesop_cat w₁₃ : v₁₂ ≫ v₂₃ = 0 := by aesop_cat /-- `L₀` is the kernel of `v₁₂ : L₁ ⟶ L₂`. -/ h₀ : IsLimit (KernelFork.ofι _ w₀₂) /-- `L₃` is the cokernel of `v₁₂ : L₁ ⟶ L₂`. -/ h₃ : IsColimit (CokernelCofork.ofπ _ w₁₃) L₁_exact : L₁.Exact epi_L₁_g : Epi L₁.g L₂_exact : L₂.Exact mono_L₂_f : Mono L₂.f initialize_simps_projections SnakeInput (-h₀, -h₃) namespace SnakeInput attribute [reassoc (attr := simp)] w₀₂ w₁₃ attribute [instance] epi_L₁_g attribute [instance] mono_L₂_f variable {C} variable (S : SnakeInput C) /-- The snake input in the opposite category that is deduced from a snake input. -/ @[simps] noncomputable def op : SnakeInput Cᵒᵖ where L₀ := S.L₃.op L₁ := S.L₂.op L₂ := S.L₁.op L₃ := S.L₀.op epi_L₁_g := by dsimp; infer_instance mono_L₂_f := by dsimp; infer_instance v₀₁ := opMap S.v₂₃ v₁₂ := opMap S.v₁₂ v₂₃ := opMap S.v₀₁ w₀₂ := congr_arg opMap S.w₁₃ w₁₃ := congr_arg opMap S.w₀₂ h₀ := isLimitForkMapOfIsLimit' (ShortComplex.opEquiv C).functor _ (CokernelCofork.IsColimit.ofπOp _ _ S.h₃) h₃ := isColimitCoforkMapOfIsColimit' (ShortComplex.opEquiv C).functor _ (KernelFork.IsLimit.ofιOp _ _ S.h₀) L₁_exact := S.L₂_exact.op L₂_exact := S.L₁_exact.op @[reassoc (attr := simp)] lemma w₀₂_τ₁ : S.v₀₁.τ₁ ≫ S.v₁₂.τ₁ = 0 := by rw [← comp_τ₁, S.w₀₂, zero_τ₁] @[reassoc (attr := simp)] lemma w₀₂_τ₂ : S.v₀₁.τ₂ ≫ S.v₁₂.τ₂ = 0 := by rw [← comp_τ₂, S.w₀₂, zero_τ₂] @[reassoc (attr := simp)] lemma w₀₂_τ₃ : S.v₀₁.τ₃ ≫ S.v₁₂.τ₃ = 0 := by rw [← comp_τ₃, S.w₀₂, zero_τ₃] @[reassoc (attr := simp)] lemma w₁₃_τ₁ : S.v₁₂.τ₁ ≫ S.v₂₃.τ₁ = 0 := by rw [← comp_τ₁, S.w₁₃, zero_τ₁] @[reassoc (attr := simp)] lemma w₁₃_τ₂ : S.v₁₂.τ₂ ≫ S.v₂₃.τ₂ = 0 := by rw [← comp_τ₂, S.w₁₃, zero_τ₂] @[reassoc (attr := simp)] lemma w₁₃_τ₃ : S.v₁₂.τ₃ ≫ S.v₂₃.τ₃ = 0 := by rw [← comp_τ₃, S.w₁₃, zero_τ₃] /-- `L₀.X₁` is the kernel of `v₁₂.τ₁ : L₁.X₁ ⟶ L₂.X₁`. -/ noncomputable def h₀τ₁ : IsLimit (KernelFork.ofι S.v₀₁.τ₁ S.w₀₂_τ₁) := isLimitForkMapOfIsLimit' π₁ S.w₀₂ S.h₀ /-- `L₀.X₂` is the kernel of `v₁₂.τ₂ : L₁.X₂ ⟶ L₂.X₂`. -/ noncomputable def h₀τ₂ : IsLimit (KernelFork.ofι S.v₀₁.τ₂ S.w₀₂_τ₂) := isLimitForkMapOfIsLimit' π₂ S.w₀₂ S.h₀ /-- `L₀.X₃` is the kernel of `v₁₂.τ₃ : L₁.X₃ ⟶ L₂.X₃`. -/ noncomputable def h₀τ₃ : IsLimit (KernelFork.ofι S.v₀₁.τ₃ S.w₀₂_τ₃) := isLimitForkMapOfIsLimit' π₃ S.w₀₂ S.h₀ instance mono_v₀₁_τ₁ : Mono S.v₀₁.τ₁ := mono_of_isLimit_fork S.h₀τ₁ instance mono_v₀₁_τ₂ : Mono S.v₀₁.τ₂ := mono_of_isLimit_fork S.h₀τ₂ instance mono_v₀₁_τ₃ : Mono S.v₀₁.τ₃ := mono_of_isLimit_fork S.h₀τ₃ /-- The upper part of the first column of the snake diagram is exact. -/ lemma exact_C₁_up : (ShortComplex.mk S.v₀₁.τ₁ S.v₁₂.τ₁ (by rw [← comp_τ₁, S.w₀₂, zero_τ₁])).Exact := exact_of_f_is_kernel _ S.h₀τ₁ /-- The upper part of the second column of the snake diagram is exact. -/ lemma exact_C₂_up : (ShortComplex.mk S.v₀₁.τ₂ S.v₁₂.τ₂ (by rw [← comp_τ₂, S.w₀₂, zero_τ₂])).Exact := exact_of_f_is_kernel _ S.h₀τ₂ /-- The upper part of the third column of the snake diagram is exact. -/ lemma exact_C₃_up : (ShortComplex.mk S.v₀₁.τ₃ S.v₁₂.τ₃ (by rw [← comp_τ₃, S.w₀₂, zero_τ₃])).Exact := exact_of_f_is_kernel _ S.h₀τ₃ instance mono_L₀_f [Mono S.L₁.f] : Mono S.L₀.f := by have : Mono (S.L₀.f ≫ S.v₀₁.τ₂) := by rw [← S.v₀₁.comm₁₂] apply mono_comp exact mono_of_mono _ S.v₀₁.τ₂ /-- `L₃.X₁` is the cokernel of `v₁₂.τ₁ : L₁.X₁ ⟶ L₂.X₁`. -/ noncomputable def h₃τ₁ : IsColimit (CokernelCofork.ofπ S.v₂₃.τ₁ S.w₁₃_τ₁) := isColimitCoforkMapOfIsColimit' π₁ S.w₁₃ S.h₃ /-- `L₃.X₂` is the cokernel of `v₁₂.τ₂ : L₁.X₂ ⟶ L₂.X₂`. -/ noncomputable def h₃τ₂ : IsColimit (CokernelCofork.ofπ S.v₂₃.τ₂ S.w₁₃_τ₂) := isColimitCoforkMapOfIsColimit' π₂ S.w₁₃ S.h₃ /-- `L₃.X₃` is the cokernel of `v₁₂.τ₃ : L₁.X₃ ⟶ L₂.X₃`. -/ noncomputable def h₃τ₃ : IsColimit (CokernelCofork.ofπ S.v₂₃.τ₃ S.w₁₃_τ₃) := isColimitCoforkMapOfIsColimit' π₃ S.w₁₃ S.h₃ instance epi_v₂₃_τ₁ : Epi S.v₂₃.τ₁ := epi_of_isColimit_cofork S.h₃τ₁ instance epi_v₂₃_τ₂ : Epi S.v₂₃.τ₂ := epi_of_isColimit_cofork S.h₃τ₂ instance epi_v₂₃_τ₃ : Epi S.v₂₃.τ₃ := epi_of_isColimit_cofork S.h₃τ₃ /-- The lower part of the first column of the snake diagram is exact. -/ lemma exact_C₁_down : (ShortComplex.mk S.v₁₂.τ₁ S.v₂₃.τ₁ (by rw [← comp_τ₁, S.w₁₃, zero_τ₁])).Exact := exact_of_g_is_cokernel _ S.h₃τ₁ /-- The lower part of the second column of the snake diagram is exact. -/ lemma exact_C₂_down : (ShortComplex.mk S.v₁₂.τ₂ S.v₂₃.τ₂ (by rw [← comp_τ₂, S.w₁₃, zero_τ₂])).Exact := exact_of_g_is_cokernel _ S.h₃τ₂ /-- The lower part of the third column of the snake diagram is exact. -/ lemma exact_C₃_down : (ShortComplex.mk S.v₁₂.τ₃ S.v₂₃.τ₃ (by rw [← comp_τ₃, S.w₁₃, zero_τ₃])).Exact := exact_of_g_is_cokernel _ S.h₃τ₃ instance epi_L₃_g [Epi S.L₂.g] : Epi S.L₃.g := by have : Epi (S.v₂₃.τ₂ ≫ S.L₃.g) := by rw [S.v₂₃.comm₂₃] apply epi_comp exact epi_of_epi S.v₂₃.τ₂ _ lemma L₀_exact : S.L₀.Exact := by rw [ShortComplex.exact_iff_exact_up_to_refinements] intro A x₂ hx₂ obtain ⟹A₁, π₁, hπ₁, y₁, hy₁⟩ := S.L₁_exact.exact_up_to_refinements (x₂ ≫ S.v₀₁.τ₂) (by rw [assoc, S.v₀₁.comm₂₃, reassoc_of% hx₂, zero_comp]) have hy₁' : y₁ ≫ S.v₁₂.τ₁ = 0 := by simp only [← cancel_mono S.L₂.f, assoc, zero_comp, S.v₁₂.comm₁₂, ← reassoc_of% hy₁, w₀₂_τ₂, comp_zero] obtain ⟹x₁, hx₁⟩ : ∃ x₁, x₁ ≫ S.v₀₁.τ₁ = y₁ := ⟹_, S.exact_C₁_up.lift_f y₁ hy₁'⟩ refine ⟹A₁, π₁, hπ₁, x₁, ?_⟩ simp only [← cancel_mono S.v₀₁.τ₂, assoc, ← S.v₀₁.comm₁₂, reassoc_of% hx₁, hy₁] lemma L₃_exact : S.L₃.Exact := S.op.L₀_exact.unop /-- The fiber product of `L₁.X₂` and `L₀.X₃` over `L₁.X₃`. This is an auxiliary object in the construction of the morphism `ÎŽ : L₀.X₃ ⟶ L₃.X₁`. -/ noncomputable def P := pullback S.L₁.g S.v₀₁.τ₃ /-- The canonical map `P ⟶ L₂.X₂`. -/ noncomputable def φ₂ : S.P ⟶ S.L₂.X₂ := pullback.fst _ _ ≫ S.v₁₂.τ₂ @[reassoc (attr := simp)] lemma lift_φ₂ {A : C} (a : A ⟶ S.L₁.X₂) (b : A ⟶ S.L₀.X₃) (h : a ≫ S.L₁.g = b ≫ S.v₀₁.τ₃) : pullback.lift a b h ≫ S.φ₂ = a ≫ S.v₁₂.τ₂ := by simp [φ₂] /-- The canonical map `P ⟶ L₂.X₁`. -/ noncomputable def φ₁ : S.P ⟶ S.L₂.X₁ := S.L₂_exact.lift S.φ₂ (by simp only [φ₂, assoc, S.v₁₂.comm₂₃, pullback.condition_assoc, w₀₂_τ₃, comp_zero]) @[reassoc (attr := simp)] lemma φ₁_L₂_f : S.φ₁ ≫ S.L₂.f = S.φ₂ := S.L₂_exact.lift_f _ _ /-- The short complex that is part of an exact sequence `L₁.X₁ ⟶ P ⟶ L₀.X₃ ⟶ 0`. -/ noncomputable def L₀' : ShortComplex C where X₁ := S.L₁.X₁ X₂ := S.P X₃ := S.L₀.X₃ f := pullback.lift S.L₁.f 0 (by simp) g := pullback.snd _ _ zero := by simp @[reassoc (attr := simp)] lemma L₁_f_φ₁ : S.L₀'.f ≫ S.φ₁ = S.v₁₂.τ₁ := by dsimp only [L₀'] simp only [← cancel_mono S.L₂.f, assoc, φ₁_L₂_f, φ₂, pullback.lift_fst_assoc, S.v₁₂.comm₁₂] instance : Epi S.L₀'.g := by dsimp only [L₀']; infer_instance instance [Mono S.L₁.f] : Mono S.L₀'.f := mono_of_mono_fac (show S.L₀'.f ≫ pullback.fst _ _ = S.L₁.f by simp [L₀']) lemma L₀'_exact : S.L₀'.Exact := by rw [ShortComplex.exact_iff_exact_up_to_refinements] intro A x₂ hx₂ dsimp [L₀'] at x₂ hx₂ obtain ⟹A', π, hπ, x₁, fac⟩ := S.L₁_exact.exact_up_to_refinements (x₂ ≫ pullback.fst _ _) (by rw [assoc, pullback.condition, reassoc_of% hx₂, zero_comp]) exact ⟹A', π, hπ, x₁, pullback.hom_ext (by simpa [L₀'] using fac) (by simp [L₀', hx₂])⟩ /-- The connecting homomorphism `ÎŽ : L₀.X₃ ⟶ L₃.X₁`. -/ noncomputable def ÎŽ : S.L₀.X₃ ⟶ S.L₃.X₁ := S.L₀'_exact.desc (S.φ₁ ≫ S.v₂₃.τ₁) (by simp only [L₁_f_φ₁_assoc, w₁₃_τ₁]) @[reassoc (attr := simp)] lemma snd_ÎŽ : (pullback.snd _ _ : S.P ⟶ _) ≫ S.ÎŽ = S.φ₁ ≫ S.v₂₃.τ₁ := S.L₀'_exact.g_desc _ _ /-- The pushout of `L₂.X₂` and `L₃.X₁` along `L₂.X₁`. -/ noncomputable def P' := pushout S.L₂.f S.v₂₃.τ₁ lemma snd_ÎŽ_inr : (pullback.snd _ _ : S.P ⟶ _) ≫ S.ÎŽ ≫ (pushout.inr _ _ : _ ⟶ S.P') = pullback.fst _ _ ≫ S.v₁₂.τ₂ ≫ pushout.inl _ _ := by simp only [snd_ÎŽ_assoc, ← pushout.condition, φ₂, φ₁_L₂_f_assoc, assoc] /-- The canonical morphism `L₀.X₂ ⟶ P`. -/ @[simp] noncomputable def L₀X₂ToP : S.L₀.X₂ ⟶ S.P := pullback.lift S.v₀₁.τ₂ S.L₀.g S.v₀₁.comm₂₃ @[reassoc] lemma L₀X₂ToP_comp_pullback_snd : S.L₀X₂ToP ≫ pullback.snd _ _ = S.L₀.g := by simp @[reassoc] lemma L₀X₂ToP_comp_φ₁ : S.L₀X₂ToP ≫ S.φ₁ = 0 := by simp only [← cancel_mono S.L₂.f, L₀X₂ToP, assoc, φ₂, φ₁_L₂_f, pullback.lift_fst_assoc, w₀₂_τ₂, zero_comp]
lemma L₀_g_ÎŽ : S.L₀.g ≫ S.ÎŽ = 0 := by rw [← L₀X₂ToP_comp_pullback_snd, assoc] erw [S.L₀'_exact.g_desc]
Mathlib/Algebra/Homology/ShortComplex/SnakeLemma.lean
292
294
/- Copyright (c) 2024 Christian Merten. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christian Merten -/ import Mathlib.CategoryTheory.Limits.Constructions.LimitsOfProductsAndEqualizers import Mathlib.CategoryTheory.Limits.FintypeCat import Mathlib.CategoryTheory.Limits.MonoCoprod import Mathlib.CategoryTheory.Limits.Shapes.ConcreteCategory import Mathlib.CategoryTheory.Limits.Shapes.Diagonal import Mathlib.CategoryTheory.SingleObj import Mathlib.Data.Finite.Card import Mathlib.Algebra.Equiv.TransferInstance /-! # Definition and basic properties of Galois categories We define the notion of a Galois category and a fiber functor as in SGA1, following the definitions in Lenstras notes (see below for a reference). ## Main definitions * `PreGaloisCategory` : defining properties of Galois categories not involving a fiber functor * `FiberFunctor` : a fiber functor from a `PreGaloisCategory` to `FintypeCat` * `GaloisCategory` : a `PreGaloisCategory` that admits a `FiberFunctor` * `IsConnected` : an object of a category is connected if it is not initial and does not have non-trivial subobjects ## Implementation details We mostly follow Def 3.1 in Lenstras notes. In axiom (G3) we omit the factorisation of morphisms in epimorphisms and monomorphisms as this is not needed for the proof of the fundamental theorem on Galois categories (and then follows from it). ## References * [lenstraGSchemes]: H. W. Lenstra. Galois theory for schemes. -/ universe u₁ u₂ v₁ v₂ w t namespace CategoryTheory open Limits Functor /-! A category `C` is a PreGalois category if it satisfies all properties of a Galois category in the sense of SGA1 that do not involve a fiber functor. A Galois category should furthermore admit a fiber functor. The only difference between `[PreGaloisCategory C] (F : C ⥀ FintypeCat) [FiberFunctor F]` and `[GaloisCategory C]` is that the former fixes one fiber functor `F`. -/ /-- Definition of a (Pre)Galois category. Lenstra, Def 3.1, (G1)-(G3) -/ class PreGaloisCategory (C : Type u₁) [Category.{u₂, u₁} C] : Prop where /-- `C` has a terminal object (G1). -/ hasTerminal : HasTerminal C := by infer_instance /-- `C` has pullbacks (G1). -/ hasPullbacks : HasPullbacks C := by infer_instance /-- `C` has finite coproducts (G2). -/ hasFiniteCoproducts : HasFiniteCoproducts C := by infer_instance /-- `C` has quotients by finite groups (G2). -/ hasQuotientsByFiniteGroups (G : Type u₂) [Group G] [Finite G] : HasColimitsOfShape (SingleObj G) C := by infer_instance /-- Every monomorphism in `C` induces an isomorphism on a direct summand (G3). -/ monoInducesIsoOnDirectSummand {X Y : C} (i : X ⟶ Y) [Mono i] : ∃ (Z : C) (u : Z ⟶ Y), Nonempty (IsColimit (BinaryCofan.mk i u)) namespace PreGaloisCategory /-- Definition of a fiber functor from a Galois category. Lenstra, Def 3.1, (G4)-(G6) -/ class FiberFunctor {C : Type u₁} [Category.{u₂, u₁} C] [PreGaloisCategory C] (F : C ⥀ FintypeCat.{w}) where /-- `F` preserves terminal objects (G4). -/ preservesTerminalObjects : PreservesLimitsOfShape (CategoryTheory.Discrete PEmpty.{1}) F := by infer_instance /-- `F` preserves pullbacks (G4). -/ preservesPullbacks : PreservesLimitsOfShape WalkingCospan F := by infer_instance /-- `F` preserves finite coproducts (G5). -/ preservesFiniteCoproducts : PreservesFiniteCoproducts F := by infer_instance /-- `F` preserves epimorphisms (G5). -/ preservesEpis : Functor.PreservesEpimorphisms F := by infer_instance /-- `F` preserves quotients by finite groups (G5). -/ preservesQuotientsByFiniteGroups (G : Type u₂) [Group G] [Finite G] : PreservesColimitsOfShape (SingleObj G) F := by infer_instance /-- `F` reflects isomorphisms (G6). -/ reflectsIsos : F.ReflectsIsomorphisms := by infer_instance /-- An object of a category `C` is connected if it is not initial and has no non-trivial subobjects. Lenstra, 3.12. -/ class IsConnected {C : Type u₁} [Category.{u₂, u₁} C] (X : C) : Prop where /-- `X` is not an initial object. -/ notInitial : IsInitial X → False /-- `X` has no non-trivial subobjects. -/ noTrivialComponent (Y : C) (i : Y ⟶ X) [Mono i] : (IsInitial Y → False) → IsIso i /-- A functor is said to preserve connectedness if whenever `X : C` is connected, also `F.obj X` is connected. -/ class PreservesIsConnected {C : Type u₁} [Category.{u₂, u₁} C] {D : Type v₁} [Category.{v₂, v₁} D] (F : C ⥀ D) : Prop where /-- `F.obj X` is connected if `X` is connected. -/ preserves : ∀ {X : C} [IsConnected X], IsConnected (F.obj X) section variable {C : Type u₁} [Category.{u₂, u₁} C] [PreGaloisCategory C] attribute [instance] hasTerminal hasPullbacks hasFiniteCoproducts hasQuotientsByFiniteGroups instance : HasFiniteLimits C := hasFiniteLimits_of_hasTerminal_and_pullbacks instance : HasBinaryProducts C := hasBinaryProducts_of_hasTerminal_and_pullbacks C instance : HasEqualizers C := hasEqualizers_of_hasPullbacks_and_binary_products -- A `PreGaloisCategory` has quotients by finite groups in arbitrary universes. -/ instance {G : Type*} [Group G] [Finite G] : HasColimitsOfShape (SingleObj G) C := by obtain ⟹G', hg, hf, ⟹e⟩⟩ := Finite.exists_type_univ_nonempty_mulEquiv G exact Limits.hasColimitsOfShape_of_equivalence e.toSingleObjEquiv.symm end namespace FiberFunctor variable {C : Type u₁} [Category.{u₂, u₁} C] {F : C ⥀ FintypeCat.{w}} [PreGaloisCategory C] [FiberFunctor F] attribute [instance] preservesTerminalObjects preservesPullbacks preservesEpis preservesFiniteCoproducts reflectsIsos preservesQuotientsByFiniteGroups noncomputable instance : ReflectsLimitsOfShape (Discrete PEmpty.{1}) F := reflectsLimitsOfShape_of_reflectsIsomorphisms noncomputable instance : ReflectsColimitsOfShape (Discrete PEmpty.{1}) F := reflectsColimitsOfShape_of_reflectsIsomorphisms noncomputable instance : PreservesFiniteLimits F := preservesFiniteLimits_of_preservesTerminal_and_pullbacks F /-- Fiber functors preserve quotients by finite groups in arbitrary universes. -/ instance {G : Type*} [Group G] [Finite G] : PreservesColimitsOfShape (SingleObj G) F := by choose G' hg hf he using Finite.exists_type_univ_nonempty_mulEquiv G exact Limits.preservesColimitsOfShape_of_equiv he.some.toSingleObjEquiv.symm F /-- Fiber functors reflect monomorphisms. -/ instance : ReflectsMonomorphisms F := ReflectsMonomorphisms.mk <| by intro X Y f _ haveI : IsIso (pullback.fst (F.map f) (F.map f)) := isIso_fst_of_mono (F.map f) haveI : IsIso (F.map (pullback.fst f f)) := by rw [← PreservesPullback.iso_hom_fst] exact IsIso.comp_isIso haveI : IsIso (pullback.fst f f) := isIso_of_reflects_iso (pullback.fst _ _) F exact (pullback.diagonal_isKernelPair f).mono_of_isIso_fst /-- Fiber functors are faithful. -/ instance : F.Faithful where map_injective {X Y} f g h := by haveI : IsIso (equalizer.ι (F.map f) (F.map g)) := equalizer.ι_of_eq h haveI : IsIso (F.map (equalizer.ι f g)) := by rw [← equalizerComparison_comp_π f g F] exact IsIso.comp_isIso haveI : IsIso (equalizer.ι f g) := isIso_of_reflects_iso _ F exact eq_of_epi_equalizer section /-- If `F` is a fiber functor and `E` is an equivalence between categories of finite types, then `F ⋙ E` is again a fiber functor. -/ lemma comp_right (E : FintypeCat.{w} ⥀ FintypeCat.{t}) [E.IsEquivalence] : FiberFunctor (F ⋙ E) where preservesQuotientsByFiniteGroups _ := comp_preservesColimitsOfShape F E end end FiberFunctor variable {C : Type u₁} [Category.{u₂, u₁} C] (F : C ⥀ FintypeCat.{w}) /-- The canonical action of `Aut F` on the fiber of each object. -/ instance (X : C) : MulAction (Aut F) (F.obj X) where smul σ x := σ.hom.app X x one_smul _ := rfl mul_smul _ _ _ := rfl lemma mulAction_def {X : C} (σ : Aut F) (x : F.obj X) : σ • x = σ.hom.app X x := rfl lemma mulAction_naturality {X Y : C} (σ : Aut F) (f : X ⟶ Y) (x : F.obj X) : σ • F.map f x = F.map f (σ • x) := FunctorToFintypeCat.naturality F F σ.hom f x /-- An object that is neither initial or connected has a non-trivial subobject. -/ lemma has_non_trivial_subobject_of_not_isConnected_of_not_initial (X : C) (hc : ¬ IsConnected X) (hi : IsInitial X → False) : ∃ (Y : C) (v : Y ⟶ X), (IsInitial Y → False) ∧ Mono v ∧ (¬ IsIso v) := by contrapose! hc exact ⟹hi, fun Y i hm hni ↩ hc Y i hni hm⟩ /-- The cardinality of the fiber is preserved under isomorphisms. -/ lemma card_fiber_eq_of_iso {X Y : C} (i : X ≅ Y) : Nat.card (F.obj X) = Nat.card (F.obj Y) := by have e : F.obj X ≃ F.obj Y := Iso.toEquiv (mapIso (F ⋙ FintypeCat.incl) i) exact Nat.card_eq_of_bijective e (Equiv.bijective e) variable [PreGaloisCategory C] [FiberFunctor F] /-- An object is initial if and only if its fiber is empty. -/ lemma initial_iff_fiber_empty (X : C) : Nonempty (IsInitial X) ↔ IsEmpty (F.obj X) := by rw [(IsInitial.isInitialIffObj F X).nonempty_congr] haveI : PreservesFiniteColimits (forget FintypeCat) := by show PreservesFiniteColimits FintypeCat.incl infer_instance haveI : ReflectsColimit (Functor.empty.{0} _) (forget FintypeCat) := by show ReflectsColimit (Functor.empty.{0} _) FintypeCat.incl infer_instance exact Concrete.initial_iff_empty_of_preserves_of_reflects (F.obj X) /-- An object is not initial if and only if its fiber is nonempty. -/ lemma not_initial_iff_fiber_nonempty (X : C) : (IsInitial X → False) ↔ Nonempty (F.obj X) := by rw [← not_isEmpty_iff] refine ⟹fun h he ↩ ?_, fun h hin ↩ h <| (initial_iff_fiber_empty F X).mp ⟹hin⟩⟩ exact Nonempty.elim ((initial_iff_fiber_empty F X).mpr he) h /-- An object whose fiber is inhabited is not initial. -/ lemma not_initial_of_inhabited {X : C} (x : F.obj X) (h : IsInitial X) : False := ((initial_iff_fiber_empty F X).mp ⟹h⟩).false x /-- The fiber of a connected object is nonempty. -/ instance nonempty_fiber_of_isConnected (X : C) [IsConnected X] : Nonempty (F.obj X) := by by_contra h have ⟹hin⟩ : Nonempty (IsInitial X) := (initial_iff_fiber_empty F X).mpr (not_nonempty_iff.mp h) exact IsConnected.notInitial hin /-- The fiber of the equalizer of `f g : X ⟶ Y` is equivalent to the set of agreement of `f` and `g`. -/ noncomputable def fiberEqualizerEquiv {X Y : C} (f g : X ⟶ Y) : F.obj (equalizer f g) ≃ { x : F.obj X // F.map f x = F.map g x } := (PreservesEqualizer.iso (F ⋙ FintypeCat.incl) f g ≪≫ Types.equalizerIso (F.map f) (F.map g)).toEquiv @[simp] lemma fiberEqualizerEquiv_symm_ι_apply {X Y : C} {f g : X ⟶ Y} (x : F.obj X) (h : F.map f x = F.map g x) : F.map (equalizer.ι f g) ((fiberEqualizerEquiv F f g).symm ⟹x, h⟩) = x := by simp [fiberEqualizerEquiv] change ((Types.equalizerIso _ _).inv ≫ _ ≫ (F ⋙ FintypeCat.incl).map (equalizer.ι f g)) _ = _ erw [PreservesEqualizer.iso_inv_ι, Types.equalizerIso_inv_comp_ι] /-- The fiber of the pullback is the fiber product of the fibers. -/ noncomputable def fiberPullbackEquiv {X A B : C} (f : A ⟶ X) (g : B ⟶ X) : F.obj (pullback f g) ≃ { p : F.obj A × F.obj B // F.map f p.1 = F.map g p.2 } := (PreservesPullback.iso (F ⋙ FintypeCat.incl) f g ≪≫ Types.pullbackIsoPullback (F.map f) (F.map g)).toEquiv @[simp] lemma fiberPullbackEquiv_symm_fst_apply {X A B : C} {f : A ⟶ X} {g : B ⟶ X} (a : F.obj A) (b : F.obj B) (h : F.map f a = F.map g b) : F.map (pullback.fst f g) ((fiberPullbackEquiv F f g).symm ⟹(a, b), h⟩) = a := by simp [fiberPullbackEquiv] change ((Types.pullbackIsoPullback _ _).inv ≫ _ ≫ (F ⋙ FintypeCat.incl).map (pullback.fst f g)) _ = _ erw [PreservesPullback.iso_inv_fst, Types.pullbackIsoPullback_inv_fst] @[simp] lemma fiberPullbackEquiv_symm_snd_apply {X A B : C} {f : A ⟶ X} {g : B ⟶ X} (a : F.obj A) (b : F.obj B) (h : F.map f a = F.map g b) : F.map (pullback.snd f g) ((fiberPullbackEquiv F f g).symm ⟹(a, b), h⟩) = b := by simp [fiberPullbackEquiv] change ((Types.pullbackIsoPullback _ _).inv ≫ _ ≫ (F ⋙ FintypeCat.incl).map (pullback.snd f g)) _ = _ erw [PreservesPullback.iso_inv_snd, Types.pullbackIsoPullback_inv_snd] /-- The fiber of the binary product is the binary product of the fibers. -/ noncomputable def fiberBinaryProductEquiv (X Y : C) : F.obj (X ⚯ Y) ≃ F.obj X × F.obj Y := (PreservesLimitPair.iso (F ⋙ FintypeCat.incl) X Y ≪≫ Types.binaryProductIso (F.obj X) (F.obj Y)).toEquiv @[simp] lemma fiberBinaryProductEquiv_symm_fst_apply {X Y : C} (x : F.obj X) (y : F.obj Y) : F.map prod.fst ((fiberBinaryProductEquiv F X Y).symm (x, y)) = x := by simp only [fiberBinaryProductEquiv, comp_obj, FintypeCat.incl_obj, Iso.toEquiv_comp, Equiv.symm_trans_apply, Iso.toEquiv_symm_fun] change ((Types.binaryProductIso _ _).inv ≫ _ ≫ (F ⋙ FintypeCat.incl).map prod.fst) _ = _ erw [PreservesLimitPair.iso_inv_fst, Types.binaryProductIso_inv_comp_fst] @[simp]
lemma fiberBinaryProductEquiv_symm_snd_apply {X Y : C} (x : F.obj X) (y : F.obj Y) : F.map prod.snd ((fiberBinaryProductEquiv F X Y).symm (x, y)) = y := by simp only [fiberBinaryProductEquiv, comp_obj, FintypeCat.incl_obj, Iso.toEquiv_comp, Equiv.symm_trans_apply, Iso.toEquiv_symm_fun] change ((Types.binaryProductIso _ _).inv ≫ _ ≫ (F ⋙ FintypeCat.incl).map prod.snd) _ = _
Mathlib/CategoryTheory/Galois/Basic.lean
293
297
/- 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, Adam Topaz -/ import Mathlib.Topology.Sheaves.SheafOfFunctions import Mathlib.Topology.Sheaves.Stalks import Mathlib.Topology.Sheaves.SheafCondition.UniqueGluing /-! # Functions satisfying a local predicate form a sheaf. At this stage, in `Mathlib/Topology/Sheaves/SheafOfFunctions.lean` we've proved that not-necessarily-continuous functions from a topological space into some type (or type family) form a sheaf. Why do the continuous functions form a sheaf? The point is just that continuity is a local condition, so one can use the lifting condition for functions to provide a candidate lift, then verify that the lift is actually continuous by using the factorisation condition for the lift (which guarantees that on each open set it agrees with the functions being lifted, which were assumed to be continuous). This file abstracts this argument to work for any collection of dependent functions on a topological space satisfying a "local predicate". As an application, we check that continuity is a local predicate in this sense, and provide * `TopCat.sheafToTop`: continuous functions into a topological space form a sheaf A sheaf constructed in this way has a natural map `stalkToFiber` from the stalks to the types in the ambient type family. We give conditions sufficient to show that this map is injective and/or surjective. -/ noncomputable section variable {X : TopCat} variable (T : X → Type*) open TopologicalSpace open Opposite open CategoryTheory open CategoryTheory.Limits open CategoryTheory.Limits.Types namespace TopCat /-- Given a topological space `X : TopCat` and a type family `T : X → Type`, a `P : PrelocalPredicate T` consists of: * a family of predicates `P.pred`, one for each `U : Opens X`, of the form `(Π x : U, T x) → Prop` * a proof that if `f : Π x : V, T x` satisfies the predicate on `V : Opens X`, then the restriction of `f` to any open subset `U` also satisfies the predicate. -/ structure PrelocalPredicate where /-- The underlying predicate of a prelocal predicate -/ pred : ∀ {U : Opens X}, (∀ x : U, T x) → Prop /-- The underlying predicate should be invariant under restriction -/ res : ∀ {U V : Opens X} (i : U ⟶ V) (f : ∀ x : V, T x) (_ : pred f), pred fun x : U ↩ f (i x) variable (X) /-- Continuity is a "prelocal" predicate on functions to a fixed topological space `T`. -/ @[simps!] def continuousPrelocal (T) [TopologicalSpace T] : PrelocalPredicate fun _ : X ↩ T where pred {_} f := Continuous f res {_ _} i _ h := Continuous.comp h (Opens.isOpenEmbedding_of_le i.le).continuous /-- Satisfying the inhabited linter. -/ instance inhabitedPrelocalPredicate (T) [TopologicalSpace T] : Inhabited (PrelocalPredicate fun _ : X ↩ T) := ⟹continuousPrelocal X T⟩ variable {X} in /-- Given a topological space `X : TopCat` and a type family `T : X → Type`, a `P : LocalPredicate T` consists of: * a family of predicates `P.pred`, one for each `U : Opens X`, of the form `(Π x : U, T x) → Prop` * a proof that if `f : Π x : V, T x` satisfies the predicate on `V : Opens X`, then the restriction of `f` to any open subset `U` also satisfies the predicate, and * a proof that given some `f : Π x : U, T x`, if for every `x : U` we can find an open set `x ∈ V ≀ U` so that the restriction of `f` to `V` satisfies the predicate, then `f` itself satisfies the predicate. -/ structure LocalPredicate extends PrelocalPredicate T where /-- A local predicate must be local --- provided that it is locally satisfied, it is also globally satisfied -/ locality : ∀ {U : Opens X} (f : ∀ x : U, T x) (_ : ∀ x : U, ∃ (V : Opens X) (_ : x.1 ∈ V) (i : V ⟶ U), pred fun x : V ↩ f (i x : U)), pred f /-- Continuity is a "local" predicate on functions to a fixed topological space `T`. -/ def continuousLocal (T) [TopologicalSpace T] : LocalPredicate fun _ : X ↩ T := { continuousPrelocal X T with locality := fun {U} f w ↩ by apply continuous_iff_continuousAt.2 intro x specialize w x rcases w with ⟹V, m, i, w⟩ dsimp at w rw [continuous_iff_continuousAt] at w specialize w ⟹x, m⟩ simpa using (Opens.isOpenEmbedding_of_le i.le).continuousAt_iff.1 w } /-- Satisfying the inhabited linter. -/ instance inhabitedLocalPredicate (T) [TopologicalSpace T] : Inhabited (LocalPredicate fun _ : X ↩ T) := ⟹continuousLocal X T⟩ variable {X T} /-- The conjunction of two prelocal predicates is prelocal. -/ def PrelocalPredicate.and (P Q : PrelocalPredicate T) : PrelocalPredicate T where pred f := P.pred f ∧ Q.pred f res i f h := ⟹P.res i f h.1, Q.res i f h.2⟩ /-- The conjunction of two prelocal predicates is prelocal. -/ def LocalPredicate.and (P Q : LocalPredicate T) : LocalPredicate T where __ := P.1.and Q.1 locality f w := by refine ⟹P.locality f ?_, Q.locality f ?_⟩ <;> (intro x; have ⟹V, hV, i, h⟩ := w x; use V, hV, i) exacts [h.1, h.2] /-- The local predicate of being a partial section of a function. -/ def isSection {T} (p : T → X) : LocalPredicate fun _ : X ↩ T where pred f := p ∘ f = (↑) res _ _ h := funext fun _ ↩ congr_fun h _ locality _ w := funext fun x ↩ have ⟹_, hV, _, h⟩ := w x; congr_fun h ⟹x, hV⟩ /-- Given a `P : PrelocalPredicate`, we can always construct a `LocalPredicate` by asking that the condition from `P` holds locally near every point. -/ def PrelocalPredicate.sheafify {T : X → Type*} (P : PrelocalPredicate T) : LocalPredicate T where pred {U} f := ∀ x : U, ∃ (V : Opens X) (_ : x.1 ∈ V) (i : V ⟶ U), P.pred fun x : V ↩ f (i x : U) res {V U} i f w x := by specialize w (i x) rcases w with ⟹V', m', i', p⟩ exact ⟹V ⊓ V', ⟹x.2, m'⟩, V.infLELeft _, P.res (V.infLERight V') _ p⟩ locality {U} f w x := by specialize w x rcases w with ⟹V, m, i, p⟩ specialize p ⟹x.1, m⟩ rcases p with ⟹V', m', i', p'⟩ exact ⟹V', m', i' ≫ i, p'⟩ theorem PrelocalPredicate.sheafifyOf {T : X → Type*} {P : PrelocalPredicate T} {U : Opens X} {f : ∀ x : U, T x} (h : P.pred f) : P.sheafify.pred f := fun x ↩ ⟹U, x.2, 𝟙 _, by convert h⟩
/-- The subpresheaf of dependent functions on `X` satisfying the "pre-local" predicate `P`. -/
Mathlib/Topology/Sheaves/LocalPredicate.lean
158
160
/- Copyright (c) 2019 Jan-David Salchow. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jan-David Salchow, Sébastien Gouëzel, Jean Lo -/ import Mathlib.Analysis.NormedSpace.OperatorNorm.Bilinear import Mathlib.Analysis.NormedSpace.OperatorNorm.NNNorm /-! # Operators on complete normed spaces This file contains statements about norms of operators on complete normed spaces, such as a version of the Banach-Alaoglu theorem (`ContinuousLinearMap.isCompact_image_coe_closedBall`). -/ suppress_compilation open Bornology Metric Set Real open Filter hiding map_smul open scoped NNReal Topology Uniformity -- the `ₗ` subscript variables are for special cases about linear (as opposed to semilinear) maps variable {𝕜 𝕜₂ E F Fₗ : Type*} variable [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedAddCommGroup Fₗ] variable [NontriviallyNormedField 𝕜] [NontriviallyNormedField 𝕜₂] [NormedSpace 𝕜 E] [NormedSpace 𝕜₂ F] [NormedSpace 𝕜 Fₗ] {σ₁₂ : 𝕜 →+* 𝕜₂} (f g : E →SL[σ₁₂] F) namespace ContinuousLinearMap section Completeness variable {E' : Type*} [SeminormedAddCommGroup E'] [NormedSpace 𝕜 E'] [RingHomIsometric σ₁₂] /-- Construct a bundled continuous (semi)linear map from a map `f : E → F` and a proof of the fact that it belongs to the closure of the image of a bounded set `s : Set (E →SL[σ₁₂] F)` under coercion to function. Coercion to function of the result is definitionally equal to `f`. -/ @[simps! -fullyApplied apply] def ofMemClosureImageCoeBounded (f : E' → F) {s : Set (E' →SL[σ₁₂] F)} (hs : IsBounded s) (hf : f ∈ closure (((↑) : (E' →SL[σ₁₂] F) → E' → F) '' s)) : E' →SL[σ₁₂] F := by -- `f` is a linear map due to `linearMapOfMemClosureRangeCoe` refine (linearMapOfMemClosureRangeCoe f ?_).mkContinuousOfExistsBound ?_ · refine closure_mono (image_subset_iff.2 fun g _ => ?_) hf exact ⟹g, rfl⟩ · -- We need to show that `f` has bounded norm. Choose `C` such that `‖g‖ ≀ C` for all `g ∈ s`. rcases isBounded_iff_forall_norm_le.1 hs with ⟹C, hC⟩ -- Then `‖g x‖ ≀ C * ‖x‖` for all `g ∈ s`, `x : E`, hence `‖f x‖ ≀ C * ‖x‖` for all `x`. have : ∀ x, IsClosed { g : E' → F | ‖g x‖ ≀ C * ‖x‖ } := fun x => isClosed_Iic.preimage (@continuous_apply E' (fun _ => F) _ x).norm refine ⟹C, fun x => (this x).closure_subset_iff.2 (image_subset_iff.2 fun g hg => ?_) hf⟩ exact g.le_of_opNorm_le (hC _ hg) _ /-- Let `f : E → F` be a map, let `g : α → E →SL[σ₁₂] F` be a family of continuous (semi)linear maps that takes values in a bounded set and converges to `f` pointwise along a nontrivial filter. Then `f` is a continuous (semi)linear map. -/ @[simps! -fullyApplied apply] def ofTendstoOfBoundedRange {α : Type*} {l : Filter α} [l.NeBot] (f : E' → F) (g : α → E' →SL[σ₁₂] F) (hf : Tendsto (fun a x => g a x) l (𝓝 f)) (hg : IsBounded (Set.range g)) : E' →SL[σ₁₂] F := ofMemClosureImageCoeBounded f hg <| mem_closure_of_tendsto hf <| Eventually.of_forall fun _ => mem_image_of_mem _ <| Set.mem_range_self _ /-- If a Cauchy sequence of continuous linear map converges to a continuous linear map pointwise, then it converges to the same map in norm. This lemma is used to prove that the space of continuous linear maps is complete provided that the codomain is a complete space. -/ theorem tendsto_of_tendsto_pointwise_of_cauchySeq {f : ℕ → E' →SL[σ₁₂] F} {g : E' →SL[σ₁₂] F} (hg : Tendsto (fun n x => f n x) atTop (𝓝 g)) (hf : CauchySeq f) : Tendsto f atTop (𝓝 g) := by /- Since `f` is a Cauchy sequence, there exists `b → 0` such that `‖f n - f m‖ ≀ b N` for any `m, n ≥ N`. -/ rcases cauchySeq_iff_le_tendsto_0.1 hf with ⟹b, hb₀, hfb, hb_lim⟩ -- Since `b → 0`, it suffices to show that `‖f n x - g x‖ ≀ b n * ‖x‖` for all `n` and `x`. suffices ∀ n x, ‖f n x - g x‖ ≀ b n * ‖x‖ from tendsto_iff_norm_sub_tendsto_zero.2 (squeeze_zero (fun n => norm_nonneg _) (fun n => opNorm_le_bound _ (hb₀ n) (this n)) hb_lim) intro n x -- Note that `f m x → g x`, hence `‖f n x - f m x‖ → ‖f n x - g x‖` as `m → ∞` have : Tendsto (fun m => ‖f n x - f m x‖) atTop (𝓝 ‖f n x - g x‖) := (tendsto_const_nhds.sub <| tendsto_pi_nhds.1 hg _).norm -- Thus it suffices to verify `‖f n x - f m x‖ ≀ b n * ‖x‖` for `m ≥ n`. refine le_of_tendsto this (eventually_atTop.2 ⟹n, fun m hm => ?_⟩) -- This inequality follows from `‖f n - f m‖ ≀ b n`. exact (f n - f m).le_of_opNorm_le (hfb _ _ _ le_rfl hm) _ /-- If the target space is complete, the space of continuous linear maps with its norm is also complete. This works also if the source space is seminormed. -/ instance [CompleteSpace F] : CompleteSpace (E' →SL[σ₁₂] F) := by -- We show that every Cauchy sequence converges. refine Metric.complete_of_cauchySeq_tendsto fun f hf => ?_ -- The evaluation at any point `v : E` is Cauchy. have cau : ∀ v, CauchySeq fun n => f n v := fun v => hf.map (lipschitz_apply v).uniformContinuous -- We assemble the limits points of those Cauchy sequences -- (which exist as `F` is complete) -- into a function which we call `G`. choose G hG using fun v => cauchySeq_tendsto_of_complete (cau v) -- Next, we show that this `G` is a continuous linear map. -- This is done in `ContinuousLinearMap.ofTendstoOfBoundedRange`. set Glin : E' →SL[σ₁₂] F := ofTendstoOfBoundedRange _ _ (tendsto_pi_nhds.mpr hG) hf.isBounded_range -- Finally, `f n` converges to `Glin` in norm because of -- `ContinuousLinearMap.tendsto_of_tendsto_pointwise_of_cauchySeq` exact ⟹Glin, tendsto_of_tendsto_pointwise_of_cauchySeq (tendsto_pi_nhds.2 hG) hf⟩ /-- Let `s` be a bounded set in the space of continuous (semi)linear maps `E →SL[σ] F` taking values in a proper space. Then `s` interpreted as a set in the space of maps `E → F` with topology of pointwise convergence is precompact: its closure is a compact set. -/ theorem isCompact_closure_image_coe_of_bounded [ProperSpace F] {s : Set (E' →SL[σ₁₂] F)} (hb : IsBounded s) : IsCompact (closure (((↑) : (E' →SL[σ₁₂] F) → E' → F) '' s)) := have : ∀ x, IsCompact (closure (apply' F σ₁₂ x '' s)) := fun x => ((apply' F σ₁₂ x).lipschitz.isBounded_image hb).isCompact_closure (isCompact_pi_infinite this).closure_of_subset (image_subset_iff.2 fun _ hg _ => subset_closure <| mem_image_of_mem _ hg) /-- Let `s` be a bounded set in the space of continuous (semi)linear maps `E →SL[σ] F` taking values in a proper space. If `s` interpreted as a set in the space of maps `E → F` with topology of pointwise convergence is closed, then it is compact. TODO: reformulate this in terms of a type synonym with the right topology. -/ theorem isCompact_image_coe_of_bounded_of_closed_image [ProperSpace F] {s : Set (E' →SL[σ₁₂] F)} (hb : IsBounded s) (hc : IsClosed (((↑) : (E' →SL[σ₁₂] F) → E' → F) '' s)) : IsCompact (((↑) : (E' →SL[σ₁₂] F) → E' → F) '' s) := hc.closure_eq ▾ isCompact_closure_image_coe_of_bounded hb /-- If a set `s` of semilinear functions is bounded and is closed in the weak-* topology, then its image under coercion to functions `E → F` is a closed set. We don't have a name for `E →SL[σ] F` with weak-* topology in `mathlib`, so we use an equivalent condition (see `isClosed_induced_iff'`). TODO: reformulate this in terms of a type synonym with the right topology. -/ theorem isClosed_image_coe_of_bounded_of_weak_closed {s : Set (E' →SL[σ₁₂] F)} (hb : IsBounded s) (hc : ∀ f : E' →SL[σ₁₂] F, (⇑f : E' → F) ∈ closure (((↑) : (E' →SL[σ₁₂] F) → E' → F) '' s) → f ∈ s) : IsClosed (((↑) : (E' →SL[σ₁₂] F) → E' → F) '' s) := isClosed_of_closure_subset fun f hf => ⟹ofMemClosureImageCoeBounded f hb hf, hc (ofMemClosureImageCoeBounded f hb hf) hf, rfl⟩ /-- If a set `s` of semilinear functions is bounded and is closed in the weak-* topology, then its image under coercion to functions `E → F` is a compact set. We don't have a name for `E →SL[σ] F` with weak-* topology in `mathlib`, so we use an equivalent condition (see `isClosed_induced_iff'`). -/ theorem isCompact_image_coe_of_bounded_of_weak_closed [ProperSpace F] {s : Set (E' →SL[σ₁₂] F)} (hb : IsBounded s) (hc : ∀ f : E' →SL[σ₁₂] F, (⇑f : E' → F) ∈ closure (((↑) : (E' →SL[σ₁₂] F) → E' → F) '' s) → f ∈ s) : IsCompact (((↑) : (E' →SL[σ₁₂] F) → E' → F) '' s) := isCompact_image_coe_of_bounded_of_closed_image hb <| isClosed_image_coe_of_bounded_of_weak_closed hb hc /-- A closed ball is closed in the weak-* topology. We don't have a name for `E →SL[σ] F` with weak-* topology in `mathlib`, so we use an equivalent condition (see `isClosed_induced_iff'`). -/ theorem is_weak_closed_closedBall (f₀ : E' →SL[σ₁₂] F) (r : ℝ) ⊃f : E' →SL[σ₁₂] F⩄ (hf : ⇑f ∈ closure (((↑) : (E' →SL[σ₁₂] F) → E' → F) '' closedBall f₀ r)) : f ∈ closedBall f₀ r := by have hr : 0 ≀ r := nonempty_closedBall.1 (closure_nonempty_iff.1 ⟹_, hf⟩).of_image refine mem_closedBall_iff_norm.2 (opNorm_le_bound _ hr fun x => ?_) have : IsClosed { g : E' → F | ‖g x - f₀ x‖ ≀ r * ‖x‖ } := isClosed_Iic.preimage ((@continuous_apply E' (fun _ => F) _ x).sub continuous_const).norm refine this.closure_subset_iff.2 (image_subset_iff.2 fun g hg => ?_) hf
exact (g - f₀).le_of_opNorm_le (mem_closedBall_iff_norm.1 hg) _ /-- The set of functions `f : E → F` that represent continuous linear maps `f : E →SL[σ₁₂] F` at distance `≀ r` from `f₀ : E →SL[σ₁₂] F` is closed in the topology of pointwise convergence. This is one of the key steps in the proof of the **Banach-Alaoglu** theorem. -/ theorem isClosed_image_coe_closedBall (f₀ : E →SL[σ₁₂] F) (r : ℝ) : IsClosed (((↑) : (E →SL[σ₁₂] F) → E → F) '' closedBall f₀ r) := isClosed_image_coe_of_bounded_of_weak_closed isBounded_closedBall (is_weak_closed_closedBall f₀ r)
Mathlib/Analysis/NormedSpace/OperatorNorm/Completeness.lean
157
165
/- Copyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import Mathlib.Algebra.BigOperators.Field import Mathlib.Algebra.Order.Chebyshev import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Order.Partition.Equipartition /-! # Numerical bounds for Szemerédi Regularity Lemma This file gathers the numerical facts required by the proof of Szemerédi's regularity lemma. This entire file is internal to the proof of Szemerédi Regularity Lemma. ## Main declarations * `SzemerediRegularity.stepBound`: During the inductive step, a partition of size `n` is blown to size at most `stepBound n`. * `SzemerediRegularity.initialBound`: The size of the partition we start the induction with. * `SzemerediRegularity.bound`: The upper bound on the size of the partition produced by our version of Szemerédi's regularity lemma. ## References [Yaël Dillies, Bhavik Mehta, *Formalising Szemerédi’s Regularity Lemma in Lean*][srl_itp] -/ open Finset Fintype Function Real namespace SzemerediRegularity /-- Auxiliary function for Szemerédi's regularity lemma. Blowing up a partition of size `n` during the induction results in a partition of size at most `stepBound n`. -/ def stepBound (n : ℕ) : ℕ := n * 4 ^ n theorem le_stepBound : id ≀ stepBound := fun n => Nat.le_mul_of_pos_right _ <| pow_pos (by norm_num) n theorem stepBound_mono : Monotone stepBound := fun _ _ h => Nat.mul_le_mul h <| Nat.pow_le_pow_right (by norm_num) h theorem stepBound_pos_iff {n : ℕ} : 0 < stepBound n ↔ 0 < n := mul_pos_iff_of_pos_right <| by positivity alias ⟹_, stepBound_pos⟩ := stepBound_pos_iff @[norm_cast] lemma coe_stepBound {α : Type*} [Semiring α] (n : ℕ) : (stepBound n : α) = n * 4 ^ n := by unfold stepBound; norm_cast end SzemerediRegularity open SzemerediRegularity variable {α : Type*} [DecidableEq α] [Fintype α] {P : Finpartition (univ : Finset α)} {u : Finset α} {ε : ℝ} local notation3 "m" => (card α / stepBound #P.parts : ℕ) local notation3 "a" => (card α / #P.parts - m * 4 ^ #P.parts : ℕ) namespace SzemerediRegularity.Positivity private theorem eps_pos {ε : ℝ} {n : ℕ} (h : 100 ≀ (4 : ℝ) ^ n * ε ^ 5) : 0 < ε := (Odd.pow_pos_iff (by decide)).mp (pos_of_mul_pos_right ((show 0 < (100 : ℝ) by norm_num).trans_le h) (by positivity)) private theorem m_pos [Nonempty α] (hPα : #P.parts * 16 ^ #P.parts ≀ card α) : 0 < m := Nat.div_pos (hPα.trans' <| by unfold stepBound; gcongr; norm_num) <| stepBound_pos (P.parts_nonempty <| univ_nonempty.ne_empty).card_pos /-- Local extension for the `positivity` tactic: A few facts that are needed many times for the proof of Szemerédi's regularity lemma. -/ scoped macro "sz_positivity" : tactic => `(tactic| { try have := m_pos ‹_› try have := eps_pos ‹_› positivity }) -- Original meta code /- meta def positivity_szemeredi_regularity : expr → tactic strictness | `(%%n / step_bound (finpartition.parts %%P).card) := do p ← to_expr ``((finpartition.parts %%P).card * 16^(finpartition.parts %%P).card ≀ %%n) >>= find_assumption, positive <$> mk_app ``m_pos [p] | ε := do typ ← infer_type ε, unify typ `(ℝ), p ← to_expr ``(100 ≀ 4 ^ _ * %%ε ^ 5) >>= find_assumption, positive <$> mk_app ``eps_pos [p] -/ end SzemerediRegularity.Positivity namespace SzemerediRegularity open scoped SzemerediRegularity.Positivity theorem m_pos [Nonempty α] (hPα : #P.parts * 16 ^ #P.parts ≀ card α) : 0 < m := by sz_positivity theorem coe_m_add_one_pos : 0 < (m : ℝ) + 1 := by positivity theorem one_le_m_coe [Nonempty α] (hPα : #P.parts * 16 ^ #P.parts ≀ card α) : (1 : ℝ) ≀ m := Nat.one_le_cast.2 <| m_pos hPα theorem eps_pow_five_pos (hPε : 100 ≀ (4 : ℝ) ^ #P.parts * ε ^ 5) : ↑0 < ε ^ 5 := pos_of_mul_pos_right ((by norm_num : (0 : ℝ) < 100).trans_le hPε) <| pow_nonneg (by norm_num) _ theorem eps_pos (hPε : 100 ≀ (4 : ℝ) ^ #P.parts * ε ^ 5) : 0 < ε := (Odd.pow_pos_iff (by decide)).mp (eps_pow_five_pos hPε) theorem hundred_div_ε_pow_five_le_m [Nonempty α] (hPα : #P.parts * 16 ^ #P.parts ≀ card α) (hPε : 100 ≀ (4 : ℝ) ^ #P.parts * ε ^ 5) : 100 / ε ^ 5 ≀ m := (div_le_of_le_mul₀ (eps_pow_five_pos hPε).le (by positivity) hPε).trans <| by norm_cast rwa [Nat.le_div_iff_mul_le (stepBound_pos (P.parts_nonempty <| univ_nonempty.ne_empty).card_pos), stepBound, mul_left_comm, ← mul_pow] theorem hundred_le_m [Nonempty α] (hPα : #P.parts * 16 ^ #P.parts ≀ card α) (hPε : 100 ≀ (4 : ℝ) ^ #P.parts * ε ^ 5) (hε : ε ≀ 1) : 100 ≀ m := mod_cast (hundred_div_ε_pow_five_le_m hPα hPε).trans' (le_div_self (by norm_num) (by sz_positivity) <| pow_le_one₀ (by sz_positivity) hε) theorem a_add_one_le_four_pow_parts_card : a + 1 ≀ 4 ^ #P.parts := by have h : 1 ≀ 4 ^ #P.parts := one_le_pow₀ (by norm_num) rw [stepBound, ← Nat.div_div_eq_div_mul] conv_rhs => rw [← Nat.sub_add_cancel h] rw [add_le_add_iff_right, tsub_le_iff_left, ← Nat.add_sub_assoc h] exact Nat.le_sub_one_of_lt (Nat.lt_div_mul_add h) theorem card_aux₁ (hucard : #u = m * 4 ^ #P.parts + a) : (4 ^ #P.parts - a) * m + a * (m + 1) = #u := by rw [hucard, mul_add, mul_one, ← add_assoc, ← add_mul, Nat.sub_add_cancel ((Nat.le_succ _).trans a_add_one_le_four_pow_parts_card), mul_comm] theorem card_aux₂ (hP : P.IsEquipartition) (hu : u ∈ P.parts) (hucard : #u ≠ m * 4 ^ #P.parts + a) : (4 ^ #P.parts - (a + 1)) * m + (a + 1) * (m + 1) = #u := by have : m * 4 ^ #P.parts ≀ card α / #P.parts := by rw [stepBound, ← Nat.div_div_eq_div_mul] exact Nat.div_mul_le_self _ _ rw [Nat.add_sub_of_le this] at hucard rw [(hP.card_parts_eq_average hu).resolve_left hucard, mul_add, mul_one, ← add_assoc, ← add_mul, Nat.sub_add_cancel a_add_one_le_four_pow_parts_card, ← add_assoc, mul_comm, Nat.add_sub_of_le this, card_univ] theorem pow_mul_m_le_card_part (hP : P.IsEquipartition) (hu : u ∈ P.parts) : (4 : ℝ) ^ #P.parts * m ≀ #u := by norm_cast rw [stepBound, ← Nat.div_div_eq_div_mul] exact (Nat.mul_div_le _ _).trans (hP.average_le_card_part hu) variable (P ε) (l : ℕ)
/-- Auxiliary function for Szemerédi's regularity lemma. The size of the partition by which we start blowing. -/ noncomputable def initialBound : ℕ := max 7 <| max l <| ⌊log (100 / ε ^ 5) / log 4⌋₊ + 1 theorem le_initialBound : l ≀ initialBound ε l := (le_max_left _ _).trans <| le_max_right _ _ theorem seven_le_initialBound : 7 ≀ initialBound ε l :=
Mathlib/Combinatorics/SimpleGraph/Regularity/Bound.lean
159
168
/- Copyright (c) 2023 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.Analysis.Calculus.SmoothSeries import Mathlib.Analysis.NormedSpace.OperatorNorm.Prod import Mathlib.Analysis.SpecialFunctions.Gaussian.PoissonSummation import Mathlib.Data.Complex.FiniteDimensional /-! # The two-variable Jacobi theta function This file defines the two-variable Jacobi theta function $$\theta(z, \tau) = \sum_{n \in \mathbb{Z}} \exp (2 i \pi n z + i \pi n ^ 2 \tau),$$ and proves the functional equation relating the values at `(z, τ)` and `(z / τ, -1 / τ)`, using Poisson's summation formula. We also show holomorphy (jointly in both variables). Additionally, we show some analogous results about the derivative (in the `z`-variable) $$\theta'(z, τ) = \sum_{n \in \mathbb{Z}} 2 \pi i n \exp (2 i \pi n z + i \pi n ^ 2 \tau).$$ (Note that the Mellin transform of `Ξ` will give us functional equations for `L`-functions of even Dirichlet characters, and that of `Ξ'` will do the same for odd Dirichlet characters.) -/ open Complex Real Asymptotics Filter Topology open scoped ComplexConjugate noncomputable section section term_defs /-! ## Definitions of the summands -/ /-- Summand in the series for the Jacobi theta function. -/ def jacobiTheta₂_term (n : â„€) (z τ : ℂ) : ℂ := cexp (2 * π * I * n * z + π * I * n ^ 2 * τ) /-- Summand in the series for the Fréchet derivative of the Jacobi theta function. -/ def jacobiTheta₂_term_fderiv (n : â„€) (z τ : ℂ) : ℂ × ℂ →L[ℂ] ℂ := cexp (2 * π * I * n * z + π * I * n ^ 2 * τ) • ((2 * π * I * n) • (ContinuousLinearMap.fst ℂ ℂ ℂ) + (π * I * n ^ 2) • (ContinuousLinearMap.snd ℂ ℂ ℂ)) lemma hasFDerivAt_jacobiTheta₂_term (n : â„€) (z τ : ℂ) : HasFDerivAt (fun p : ℂ × ℂ ↩ jacobiTheta₂_term n p.1 p.2) (jacobiTheta₂_term_fderiv n z τ) (z, τ) := by let f : ℂ × ℂ → ℂ := fun p ↩ 2 * π * I * n * p.1 + π * I * n ^ 2 * p.2 suffices HasFDerivAt f ((2 * π * I * n) • (ContinuousLinearMap.fst ℂ ℂ ℂ) + (π * I * n ^ 2) • (ContinuousLinearMap.snd ℂ ℂ ℂ)) (z, τ) from this.cexp exact (hasFDerivAt_fst.const_mul _).add (hasFDerivAt_snd.const_mul _) /-- Summand in the series for the `z`-derivative of the Jacobi theta function. -/ def jacobiTheta₂'_term (n : â„€) (z τ : ℂ) := 2 * π * I * n * jacobiTheta₂_term n z τ end term_defs section term_bounds /-! ## Bounds for the summands We show that the sums of the three functions `jacobiTheta₂_term`, `jacobiTheta₂'_term` and `jacobiTheta₂_term_fderiv` are locally uniformly convergent in the domain `0 < im τ`, and diverge everywhere else. -/ lemma norm_jacobiTheta₂_term (n : â„€) (z τ : ℂ) : ‖jacobiTheta₂_term n z τ‖ = rexp (-π * n ^ 2 * τ.im - 2 * π * n * z.im) := by rw [jacobiTheta₂_term, Complex.norm_exp, (by push_cast; ring : (2 * π : ℂ) * I * n * z + π * I * n ^ 2 * τ = (π * (2 * n):) * z * I + (π * n ^ 2 :) * τ * I), add_re, mul_I_re, im_ofReal_mul, mul_I_re, im_ofReal_mul] ring_nf /-- A uniform upper bound for `jacobiTheta₂_term` on compact subsets. -/ lemma norm_jacobiTheta₂_term_le {S T : ℝ} (hT : 0 < T) {z τ : ℂ} (hz : |im z| ≀ S) (hτ : T ≀ im τ) (n : â„€) : ‖jacobiTheta₂_term n z τ‖ ≀ rexp (-π * (T * n ^ 2 - 2 * S * |n|)) := by simp_rw [norm_jacobiTheta₂_term, Real.exp_le_exp, sub_eq_add_neg, neg_mul, ← neg_add, neg_le_neg_iff, mul_comm (2 : ℝ), mul_assoc π, ← mul_add, mul_le_mul_left pi_pos, mul_comm T, mul_comm S] refine add_le_add (mul_le_mul le_rfl hτ hT.le (sq_nonneg _)) ?_ rw [← mul_neg, mul_assoc, mul_assoc, mul_le_mul_left two_pos, mul_comm, neg_mul, ← mul_neg] refine le_trans ?_ (neg_abs_le _) rw [mul_neg, neg_le_neg_iff, abs_mul, Int.cast_abs] exact mul_le_mul_of_nonneg_left hz (abs_nonneg _) /-- A uniform upper bound for `jacobiTheta₂'_term` on compact subsets. -/ lemma norm_jacobiTheta₂'_term_le {S T : ℝ} (hT : 0 < T) {z τ : ℂ} (hz : |im z| ≀ S) (hτ : T ≀ im τ) (n : â„€) : ‖jacobiTheta₂'_term n z τ‖ ≀ 2 * π * |n| * rexp (-π * (T * n ^ 2 - 2 * S * |n|)) := by rw [jacobiTheta₂'_term, norm_mul] refine mul_le_mul (le_of_eq ?_) (norm_jacobiTheta₂_term_le hT hz hτ n) (norm_nonneg _) (by positivity) simp only [norm_mul, Complex.norm_two, norm_I, Complex.norm_of_nonneg pi_pos.le, norm_intCast, mul_one, Int.cast_abs]
/-- The uniform bound we have given is summable, and remains so after multiplying by any fixed power of `|n|` (we shall need this for `k = 0, 1, 2`). -/ lemma summable_pow_mul_jacobiTheta₂_term_bound (S : ℝ) {T : ℝ} (hT : 0 < T) (k : ℕ) : Summable (fun n : â„€ ↩ (|n| ^ k : ℝ) * Real.exp (-π * (T * n ^ 2 - 2 * S * |n|))) := by suffices Summable (fun n : ℕ ↩ (n ^ k : ℝ) * Real.exp (-π * (T * n ^ 2 - 2 * S * n))) by apply Summable.of_nat_of_neg <;> simpa only [Int.cast_neg, neg_sq, abs_neg, Int.cast_natCast, Nat.abs_cast] apply summable_of_isBigO_nat (summable_pow_mul_exp_neg_nat_mul k zero_lt_one) apply IsBigO.mul (isBigO_refl _ _) refine Real.isBigO_exp_comp_exp_comp.mpr (Tendsto.isBoundedUnder_le_atBot ?_) simp_rw [← tendsto_neg_atTop_iff, Pi.sub_apply] conv => enter [1, n] rw [show -(-π * (T * n ^ 2 - 2 * S * n) - -1 * n) = n * (π * T * n - (2 * π * S + 1)) by ring] refine tendsto_natCast_atTop_atTop.atTop_mul_atTop₀ (tendsto_atTop_add_const_right _ _ ?_)
Mathlib/NumberTheory/ModularForms/JacobiTheta/TwoVariable.lean
100
115
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Mario Carneiro -/ import Mathlib.Data.Subtype import Mathlib.Order.Defs.LinearOrder import Mathlib.Order.Notation import Mathlib.Tactic.GCongr.Core import Mathlib.Tactic.Spread import Mathlib.Tactic.Convert import Mathlib.Tactic.Inhabit import Mathlib.Tactic.SimpRw /-! # Basic definitions about `≀` and `<` This file proves basic results about orders, provides extensive dot notation, defines useful order classes and allows to transfer order instances. ## Type synonyms * `OrderDual α` : A type synonym reversing the meaning of all inequalities, with notation `αᵒᵈ`. * `AsLinearOrder α`: A type synonym to promote `PartialOrder α` to `LinearOrder α` using `IsTotal α (≀)`. ### Transferring orders - `Order.Preimage`, `Preorder.lift`: Transfers a (pre)order on `β` to an order on `α` using a function `f : α → β`. - `PartialOrder.lift`, `LinearOrder.lift`: Transfers a partial (resp., linear) order on `β` to a partial (resp., linear) order on `α` using an injective function `f`. ### Extra class * `DenselyOrdered`: An order with no gap, i.e. for any two elements `a < b` there exists `c` such that `a < c < b`. ## Notes `≀` and `<` are highly favored over `≥` and `>` in mathlib. The reason is that we can formulate all lemmas using `≀`/`<`, and `rw` has trouble unifying `≀` and `≥`. Hence choosing one direction spares us useless duplication. This is enforced by a linter. See Note [nolint_ge] for more infos. Dot notation is particularly useful on `≀` (`LE.le`) and `<` (`LT.lt`). To that end, we provide many aliases to dot notation-less lemmas. For example, `le_trans` is aliased with `LE.le.trans` and can be used to construct `hab.trans hbc : a ≀ c` when `hab : a ≀ b`, `hbc : b ≀ c`, `lt_of_le_of_lt` is aliased as `LE.le.trans_lt` and can be used to construct `hab.trans hbc : a < c` when `hab : a ≀ b`, `hbc : b < c`. ## TODO - expand module docs - automatic construction of dual definitions / theorems ## Tags preorder, order, partial order, poset, linear order, chain -/ open Function variable {ι α β : Type*} {π : ι → Type*} /-! ### Bare relations -/ attribute [ext] LE protected lemma LE.le.ge [LE α] {x y : α} (h : x ≀ y) : y ≥ x := h protected lemma GE.ge.le [LE α] {x y : α} (h : x ≥ y) : y ≀ x := h protected lemma LT.lt.gt [LT α] {x y : α} (h : x < y) : y > x := h protected lemma GT.gt.lt [LT α] {x y : α} (h : x > y) : y < x := h /-- Given a relation `R` on `β` and a function `f : α → β`, the preimage relation on `α` is defined by `x ≀ y ↔ f x ≀ f y`. It is the unique relation on `α` making `f` a `RelEmbedding` (assuming `f` is injective). -/ @[simp] def Order.Preimage (f : α → β) (s : β → β → Prop) (x y : α) : Prop := s (f x) (f y) @[inherit_doc] infixl:80 " ⁻¹'o " => Order.Preimage /-- The preimage of a decidable order is decidable. -/ instance Order.Preimage.decidable (f : α → β) (s : β → β → Prop) [H : DecidableRel s] : DecidableRel (f ⁻¹'o s) := fun _ _ ↩ H _ _ /-! ### Preorders -/ section Preorder variable [Preorder α] {a b c d : α} theorem le_trans' : b ≀ c → a ≀ b → a ≀ c := flip le_trans theorem lt_trans' : b < c → a < b → a < c := flip lt_trans theorem lt_of_le_of_lt' : b ≀ c → a < b → a < c := flip lt_of_lt_of_le theorem lt_of_lt_of_le' : b < c → a ≀ b → a < c := flip lt_of_le_of_lt theorem le_of_le_of_eq' : b ≀ c → a = b → a ≀ c := flip le_of_eq_of_le theorem le_of_eq_of_le' : b = c → a ≀ b → a ≀ c := flip le_of_le_of_eq theorem lt_of_lt_of_eq' : b < c → a = b → a < c := flip lt_of_eq_of_lt theorem lt_of_eq_of_lt' : b = c → a < b → a < c := flip lt_of_lt_of_eq theorem not_lt_iff_not_le_or_ge : ¬a < b ↔ ¬a ≀ b √ b ≀ a := by rw [lt_iff_le_not_le, Classical.not_and_iff_not_or_not, Classical.not_not] -- Unnecessary brackets are here for readability lemma not_lt_iff_le_imp_le : ¬ a < b ↔ (a ≀ b → b ≀ a) := by simp [not_lt_iff_not_le_or_ge, or_iff_not_imp_left] /-- If `x = y` then `y ≀ x`. Note: this lemma uses `y ≀ x` instead of `x ≥ y`, because `le` is used almost exclusively in mathlib. -/ lemma ge_of_eq (h : a = b) : b ≀ a := le_of_eq h.symm @[simp] lemma lt_self_iff_false (x : α) : x < x ↔ False := ⟹lt_irrefl x, False.elim⟩ alias LE.le.trans := le_trans alias LE.le.trans' := le_trans' alias LT.lt.trans := lt_trans alias LT.lt.trans' := lt_trans' alias LE.le.trans_lt := lt_of_le_of_lt alias LE.le.trans_lt' := lt_of_le_of_lt' alias LT.lt.trans_le := lt_of_lt_of_le alias LT.lt.trans_le' := lt_of_lt_of_le' alias LE.le.trans_eq := le_of_le_of_eq alias LE.le.trans_eq' := le_of_le_of_eq' alias LT.lt.trans_eq := lt_of_lt_of_eq alias LT.lt.trans_eq' := lt_of_lt_of_eq' alias Eq.trans_le := le_of_eq_of_le alias Eq.trans_ge := le_of_eq_of_le' alias Eq.trans_lt := lt_of_eq_of_lt alias Eq.trans_gt := lt_of_eq_of_lt' alias LE.le.lt_of_not_le := lt_of_le_not_le alias LE.le.lt_or_eq_dec := Decidable.lt_or_eq_of_le alias LT.lt.le := le_of_lt alias LT.lt.ne := ne_of_lt alias Eq.le := le_of_eq @[inherit_doc ge_of_eq] alias Eq.ge := ge_of_eq alias LT.lt.asymm := lt_asymm alias LT.lt.not_lt := lt_asymm theorem ne_of_not_le (h : ¬a ≀ b) : a ≠ b := fun hab ↩ h (le_of_eq hab) protected lemma Eq.not_lt (hab : a = b) : ¬a < b := fun h' ↩ h'.ne hab protected lemma Eq.not_gt (hab : a = b) : ¬b < a := hab.symm.not_lt @[simp] lemma le_of_subsingleton [Subsingleton α] : a ≀ b := (Subsingleton.elim a b).le -- Making this a @[simp] lemma causes confluence problems downstream. lemma not_lt_of_subsingleton [Subsingleton α] : ¬a < b := (Subsingleton.elim a b).not_lt namespace LT.lt protected theorem false : a < a → False := lt_irrefl a theorem ne' (h : a < b) : b ≠ a := h.ne.symm end LT.lt theorem le_of_forall_le (H : ∀ c, c ≀ a → c ≀ b) : a ≀ b := H _ le_rfl theorem le_of_forall_ge (H : ∀ c, a ≀ c → b ≀ c) : b ≀ a := H _ le_rfl @[deprecated (since := "2025-01-30")] alias le_of_forall_le' := le_of_forall_ge theorem forall_le_iff_le : (∀ ⊃c⩄, c ≀ a → c ≀ b) ↔ a ≀ b := ⟹le_of_forall_le, fun h _ hca ↩ le_trans hca h⟩ theorem forall_le_iff_ge : (∀ ⊃c⩄, a ≀ c → b ≀ c) ↔ b ≀ a := ⟹le_of_forall_ge, fun h _ hca ↩ le_trans h hca⟩ /-- monotonicity of `≀` with respect to `→` -/ theorem le_implies_le_of_le_of_le (hca : c ≀ a) (hbd : b ≀ d) : a ≀ b → c ≀ d := fun hab ↩ (hca.trans hab).trans hbd end Preorder /-! ### Partial order -/ section PartialOrder variable [PartialOrder α] {a b : α} theorem ge_antisymm : a ≀ b → b ≀ a → b = a := flip le_antisymm theorem lt_of_le_of_ne' : a ≀ b → b ≠ a → a < b := fun h₁ h₂ ↩ lt_of_le_of_ne h₁ h₂.symm theorem Ne.lt_of_le : a ≠ b → a ≀ b → a < b := flip lt_of_le_of_ne theorem Ne.lt_of_le' : b ≠ a → a ≀ b → a < b := flip lt_of_le_of_ne' alias LE.le.antisymm := le_antisymm alias LE.le.antisymm' := ge_antisymm alias LE.le.lt_of_ne := lt_of_le_of_ne alias LE.le.lt_of_ne' := lt_of_le_of_ne' alias LE.le.lt_or_eq := lt_or_eq_of_le -- Unnecessary brackets are here for readability lemma le_imp_eq_iff_le_imp_le : (a ≀ b → b = a) ↔ (a ≀ b → b ≀ a) where mp h hab := (h hab).le mpr h hab := (h hab).antisymm hab -- Unnecessary brackets are here for readability lemma ge_imp_eq_iff_le_imp_le : (a ≀ b → a = b) ↔ (a ≀ b → b ≀ a) where mp h hab := (h hab).ge mpr h hab := hab.antisymm (h hab) namespace LE.le theorem lt_iff_ne (h : a ≀ b) : a < b ↔ a ≠ b := ⟹fun h ↩ h.ne, h.lt_of_ne⟩ theorem gt_iff_ne (h : a ≀ b) : a < b ↔ b ≠ a := ⟹fun h ↩ h.ne.symm, h.lt_of_ne'⟩ theorem not_lt_iff_eq (h : a ≀ b) : ¬a < b ↔ a = b := h.lt_iff_ne.not_left theorem not_gt_iff_eq (h : a ≀ b) : ¬a < b ↔ b = a := h.gt_iff_ne.not_left theorem le_iff_eq (h : a ≀ b) : b ≀ a ↔ b = a := ⟹fun h' ↩ h'.antisymm h, Eq.le⟩ theorem ge_iff_eq (h : a ≀ b) : b ≀ a ↔ a = b := ⟹h.antisymm, Eq.ge⟩ end LE.le -- See Note [decidable namespace] protected theorem Decidable.le_iff_eq_or_lt [DecidableLE α] : a ≀ b ↔ a = b √ a < b := Decidable.le_iff_lt_or_eq.trans or_comm theorem le_iff_eq_or_lt : a ≀ b ↔ a = b √ a < b := le_iff_lt_or_eq.trans or_comm theorem lt_iff_le_and_ne : a < b ↔ a ≀ b ∧ a ≠ b := ⟹fun h ↩ ⟹le_of_lt h, ne_of_lt h⟩, fun ⟹h1, h2⟩ ↩ h1.lt_of_ne h2⟩ lemma eq_iff_not_lt_of_le (hab : a ≀ b) : a = b ↔ ¬ a < b := by simp [hab, lt_iff_le_and_ne] alias LE.le.eq_iff_not_lt := eq_iff_not_lt_of_le -- See Note [decidable namespace] protected theorem Decidable.eq_iff_le_not_lt [DecidableLE α] : a = b ↔ a ≀ b ∧ ¬a < b := ⟹fun h ↩ ⟹h.le, h ▾ lt_irrefl _⟩, fun ⟹h₁, h₂⟩ ↩ h₁.antisymm <| Decidable.byContradiction fun h₃ ↩ h₂ (h₁.lt_of_not_le h₃)⟩ theorem eq_iff_le_not_lt : a = b ↔ a ≀ b ∧ ¬a < b := haveI := Classical.dec Decidable.eq_iff_le_not_lt theorem eq_or_lt_of_le (h : a ≀ b) : a = b √ a < b := h.lt_or_eq.symm theorem eq_or_gt_of_le (h : a ≀ b) : b = a √ a < b := h.lt_or_eq.symm.imp Eq.symm id theorem gt_or_eq_of_le (h : a ≀ b) : a < b √ b = a := (eq_or_gt_of_le h).symm alias LE.le.eq_or_lt_dec := Decidable.eq_or_lt_of_le alias LE.le.eq_or_lt := eq_or_lt_of_le alias LE.le.eq_or_gt := eq_or_gt_of_le alias LE.le.gt_or_eq := gt_or_eq_of_le theorem eq_of_le_of_not_lt (hab : a ≀ b) (hba : ¬a < b) : a = b := hab.eq_or_lt.resolve_right hba theorem eq_of_ge_of_not_gt (hab : a ≀ b) (hba : ¬a < b) : b = a := (eq_of_le_of_not_lt hab hba).symm alias LE.le.eq_of_not_lt := eq_of_le_of_not_lt alias LE.le.eq_of_not_gt := eq_of_ge_of_not_gt theorem Ne.le_iff_lt (h : a ≠ b) : a ≀ b ↔ a < b := ⟹fun h' ↩ lt_of_le_of_ne h' h, fun h ↩ h.le⟩ theorem Ne.not_le_or_not_le (h : a ≠ b) : ¬a ≀ b √ ¬b ≀ a := not_and_or.1 <| le_antisymm_iff.not.1 h -- See Note [decidable namespace] protected theorem Decidable.ne_iff_lt_iff_le [DecidableEq α] : (a ≠ b ↔ a < b) ↔ a ≀ b := ⟹fun h ↩ Decidable.byCases le_of_eq (le_of_lt ∘ h.mp), fun h ↩ ⟹lt_of_le_of_ne h, ne_of_lt⟩⟩ @[simp] theorem ne_iff_lt_iff_le : (a ≠ b ↔ a < b) ↔ a ≀ b := haveI := Classical.dec Decidable.ne_iff_lt_iff_le lemma eq_of_forall_le_iff (H : ∀ c, c ≀ a ↔ c ≀ b) : a = b := ((H _).1 le_rfl).antisymm ((H _).2 le_rfl) lemma eq_of_forall_ge_iff (H : ∀ c, a ≀ c ↔ b ≀ c) : a = b := ((H _).2 le_rfl).antisymm ((H _).1 le_rfl) /-- To prove commutativity of a binary operation `○`, we only to check `a ○ b ≀ b ○ a` for all `a`, `b`. -/ lemma commutative_of_le {f : β → β → α} (comm : ∀ a b, f a b ≀ f b a) : ∀ a b, f a b = f b a := fun _ _ ↩ (comm _ _).antisymm <| comm _ _ /-- To prove associativity of a commutative binary operation `○`, we only to check `(a ○ b) ○ c ≀ a ○ (b ○ c)` for all `a`, `b`, `c`. -/ lemma associative_of_commutative_of_le {f : α → α → α} (comm : Std.Commutative f) (assoc : ∀ a b c, f (f a b) c ≀ f a (f b c)) : Std.Associative f where assoc a b c := le_antisymm (assoc _ _ _) <| by rw [comm.comm, comm.comm b, comm.comm _ c, comm.comm a] exact assoc .. end PartialOrder section LinearOrder variable [LinearOrder α] {a b : α} namespace LE.le lemma lt_or_le (h : a ≀ b) (c : α) : a < c √ c ≀ b := (lt_or_ge a c).imp id h.trans' lemma le_or_lt (h : a ≀ b) (c : α) : a ≀ c √ c < b := (le_or_gt a c).imp id h.trans_lt' lemma le_or_le (h : a ≀ b) (c : α) : a ≀ c √ c ≀ b := (h.lt_or_le c).imp le_of_lt id end LE.le namespace LT.lt lemma lt_or_lt (h : a < b) (c : α) : a < c √ c < b := (le_or_gt b c).imp h.trans_le id end LT.lt -- Variant of `min_def` with the branches reversed. theorem min_def' (a b : α) : min a b = if b ≀ a then b else a := by rw [min_def] rcases lt_trichotomy a b with (lt | eq | gt) · rw [if_pos lt.le, if_neg (not_le.mpr lt)] · rw [if_pos eq.le, if_pos eq.ge, eq] · rw [if_neg (not_le.mpr gt.gt), if_pos gt.le] -- Variant of `min_def` with the branches reversed. -- This is sometimes useful as it used to be the default. theorem max_def' (a b : α) : max a b = if b ≀ a then a else b := by rw [max_def] rcases lt_trichotomy a b with (lt | eq | gt) · rw [if_pos lt.le, if_neg (not_le.mpr lt)] · rw [if_pos eq.le, if_pos eq.ge, eq] · rw [if_neg (not_le.mpr gt.gt), if_pos gt.le] theorem lt_of_not_le (h : ¬b ≀ a) : a < b := ((le_total _ _).resolve_right h).lt_of_not_le h theorem lt_iff_not_le : a < b ↔ ¬b ≀ a := ⟹not_le_of_lt, lt_of_not_le⟩ theorem Ne.lt_or_lt (h : a ≠ b) : a < b √ b < a := lt_or_gt_of_ne h /-- A version of `ne_iff_lt_or_gt` with LHS and RHS reversed. -/ @[simp] theorem lt_or_lt_iff_ne : a < b √ b < a ↔ a ≠ b := ne_iff_lt_or_gt.symm theorem not_lt_iff_eq_or_lt : ¬a < b ↔ a = b √ b < a := not_lt.trans <| Decidable.le_iff_eq_or_lt.trans <| or_congr eq_comm Iff.rfl theorem exists_ge_of_linear (a b : α) : ∃ c, a ≀ c ∧ b ≀ c := match le_total a b with | Or.inl h => ⟹_, h, le_rfl⟩ | Or.inr h => ⟹_, le_rfl, h⟩ lemma exists_forall_ge_and {p q : α → Prop} : (∃ i, ∀ j ≥ i, p j) → (∃ i, ∀ j ≥ i, q j) → ∃ i, ∀ j ≥ i, p j ∧ q j | ⟹a, ha⟩, ⟹b, hb⟩ => let ⟹c, hac, hbc⟩ := exists_ge_of_linear a b ⟹c, fun _d hcd ↩ ⟹ha _ <| hac.trans hcd, hb _ <| hbc.trans hcd⟩⟩ theorem le_of_forall_lt (H : ∀ c, c < a → c < b) : a ≀ b := le_of_not_lt fun h ↩ lt_irrefl _ (H _ h) theorem forall_lt_iff_le : (∀ ⊃c⩄, c < a → c < b) ↔ a ≀ b := ⟹le_of_forall_lt, fun h _ hca ↩ lt_of_lt_of_le hca h⟩ theorem le_of_forall_lt' (H : ∀ c, a < c → b < c) : b ≀ a := le_of_not_lt fun h ↩ lt_irrefl _ (H _ h) theorem forall_lt_iff_le' : (∀ ⊃c⩄, a < c → b < c) ↔ b ≀ a := ⟹le_of_forall_lt', fun h _ hac ↩ lt_of_le_of_lt h hac⟩ theorem eq_of_forall_lt_iff (h : ∀ c, c < a ↔ c < b) : a = b := (le_of_forall_lt fun _ ↩ (h _).1).antisymm <| le_of_forall_lt fun _ ↩ (h _).2 theorem eq_of_forall_gt_iff (h : ∀ c, a < c ↔ b < c) : a = b := (le_of_forall_lt' fun _ ↩ (h _).2).antisymm <| le_of_forall_lt' fun _ ↩ (h _).1 section ltByCases variable {P : Sort*} {x y : α} @[simp] lemma ltByCases_lt (h : x < y) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} : ltByCases x y h₁ h₂ h₃ = h₁ h := dif_pos h @[simp] lemma ltByCases_gt (h : y < x) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} : ltByCases x y h₁ h₂ h₃ = h₃ h := (dif_neg h.not_lt).trans (dif_pos h) @[simp] lemma ltByCases_eq (h : x = y) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} : ltByCases x y h₁ h₂ h₃ = h₂ h := (dif_neg h.not_lt).trans (dif_neg h.not_gt) lemma ltByCases_not_lt (h : ¬ x < y) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} (p : ¬ y < x → x = y := fun h' => (le_antisymm (le_of_not_gt h') (le_of_not_gt h))) : ltByCases x y h₁ h₂ h₃ = if h' : y < x then h₃ h' else h₂ (p h') := dif_neg h lemma ltByCases_not_gt (h : ¬ y < x) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} (p : ¬ x < y → x = y := fun h' => (le_antisymm (le_of_not_gt h) (le_of_not_gt h'))) : ltByCases x y h₁ h₂ h₃ = if h' : x < y then h₁ h' else h₂ (p h') := dite_congr rfl (fun _ => rfl) (fun _ => dif_neg h) lemma ltByCases_ne (h : x ≠ y) {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} (p : ¬ x < y → y < x := fun h' => h.lt_or_lt.resolve_left h') : ltByCases x y h₁ h₂ h₃ = if h' : x < y then h₁ h' else h₃ (p h') := dite_congr rfl (fun _ => rfl) (fun _ => dif_pos _) lemma ltByCases_comm {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} (p : y = x → x = y := fun h' => h'.symm) : ltByCases x y h₁ h₂ h₃ = ltByCases y x h₃ (h₂ ∘ p) h₁ := by refine ltByCases x y (fun h => ?_) (fun h => ?_) (fun h => ?_) · rw [ltByCases_lt h, ltByCases_gt h] · rw [ltByCases_eq h, ltByCases_eq h.symm, comp_apply] · rw [ltByCases_lt h, ltByCases_gt h] lemma eq_iff_eq_of_lt_iff_lt_of_gt_iff_gt {x' y' : α} (ltc : (x < y) ↔ (x' < y')) (gtc : (y < x) ↔ (y' < x')) : x = y ↔ x' = y' := by simp_rw [eq_iff_le_not_lt, ← not_lt, ltc, gtc] lemma ltByCases_rec {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} (p : P) (hlt : (h : x < y) → h₁ h = p) (heq : (h : x = y) → h₂ h = p) (hgt : (h : y < x) → h₃ h = p) : ltByCases x y h₁ h₂ h₃ = p := ltByCases x y (fun h => ltByCases_lt h ▾ hlt h) (fun h => ltByCases_eq h ▾ heq h) (fun h => ltByCases_gt h ▾ hgt h) lemma ltByCases_eq_iff {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} {p : P} : ltByCases x y h₁ h₂ h₃ = p ↔ (∃ h, h₁ h = p) √ (∃ h, h₂ h = p) √ (∃ h, h₃ h = p) := by refine ltByCases x y (fun h => ?_) (fun h => ?_) (fun h => ?_) · simp only [ltByCases_lt, exists_prop_of_true, h, h.not_lt, not_false_eq_true, exists_prop_of_false, or_false, h.ne] · simp only [h, lt_self_iff_false, ltByCases_eq, not_false_eq_true, exists_prop_of_false, exists_prop_of_true, or_false, false_or] · simp only [ltByCases_gt, exists_prop_of_true, h, h.not_lt, not_false_eq_true, exists_prop_of_false, false_or, h.ne'] lemma ltByCases_congr {x' y' : α} {h₁ : x < y → P} {h₂ : x = y → P} {h₃ : y < x → P} {h₁' : x' < y' → P} {h₂' : x' = y' → P} {h₃' : y' < x' → P} (ltc : (x < y) ↔ (x' < y')) (gtc : (y < x) ↔ (y' < x')) (hh'₁ : ∀ (h : x' < y'), h₁ (ltc.mpr h) = h₁' h) (hh'₂ : ∀ (h : x' = y'), h₂ ((eq_iff_eq_of_lt_iff_lt_of_gt_iff_gt ltc gtc).mpr h) = h₂' h) (hh'₃ : ∀ (h : y' < x'), h₃ (gtc.mpr h) = h₃' h) : ltByCases x y h₁ h₂ h₃ = ltByCases x' y' h₁' h₂' h₃' := by refine ltByCases_rec _ (fun h => ?_) (fun h => ?_) (fun h => ?_) · rw [ltByCases_lt (ltc.mp h), hh'₁] · rw [eq_iff_eq_of_lt_iff_lt_of_gt_iff_gt ltc gtc] at h rw [ltByCases_eq h, hh'₂] · rw [ltByCases_gt (gtc.mp h), hh'₃] /-- Perform a case-split on the ordering of `x` and `y` in a decidable linear order, non-dependently. -/ abbrev ltTrichotomy (x y : α) (p q r : P) := ltByCases x y (fun _ => p) (fun _ => q) (fun _ => r) variable {p q r s : P} @[simp] lemma ltTrichotomy_lt (h : x < y) : ltTrichotomy x y p q r = p := ltByCases_lt h @[simp] lemma ltTrichotomy_gt (h : y < x) : ltTrichotomy x y p q r = r := ltByCases_gt h @[simp] lemma ltTrichotomy_eq (h : x = y) : ltTrichotomy x y p q r = q := ltByCases_eq h lemma ltTrichotomy_not_lt (h : ¬ x < y) : ltTrichotomy x y p q r = if y < x then r else q := ltByCases_not_lt h lemma ltTrichotomy_not_gt (h : ¬ y < x) : ltTrichotomy x y p q r = if x < y then p else q := ltByCases_not_gt h lemma ltTrichotomy_ne (h : x ≠ y) : ltTrichotomy x y p q r = if x < y then p else r := ltByCases_ne h lemma ltTrichotomy_comm : ltTrichotomy x y p q r = ltTrichotomy y x r q p := ltByCases_comm lemma ltTrichotomy_self {p : P} : ltTrichotomy x y p p p = p := ltByCases_rec p (fun _ => rfl) (fun _ => rfl) (fun _ => rfl) lemma ltTrichotomy_eq_iff : ltTrichotomy x y p q r = s ↔ (x < y ∧ p = s) √ (x = y ∧ q = s) √ (y < x ∧ r = s) := by refine ltByCases x y (fun h => ?_) (fun h => ?_) (fun h => ?_) · simp only [ltTrichotomy_lt, false_and, true_and, or_false, h, h.not_lt, h.ne] · simp only [ltTrichotomy_eq, false_and, true_and, or_false, false_or, h, lt_irrefl] · simp only [ltTrichotomy_gt, false_and, true_and, false_or, h, h.not_lt, h.ne'] lemma ltTrichotomy_congr {x' y' : α} {p' q' r' : P} (ltc : (x < y) ↔ (x' < y')) (gtc : (y < x) ↔ (y' < x')) (hh'₁ : x' < y' → p = p') (hh'₂ : x' = y' → q = q') (hh'₃ : y' < x' → r = r') : ltTrichotomy x y p q r = ltTrichotomy x' y' p' q' r' := ltByCases_congr ltc gtc hh'₁ hh'₂ hh'₃ end ltByCases /-! #### `min`/`max` recursors -/ section MinMaxRec variable {p : α → Prop} lemma min_rec (ha : a ≀ b → p a) (hb : b ≀ a → p b) : p (min a b) := by obtain hab | hba := le_total a b <;> simp [min_eq_left, min_eq_right, *] lemma max_rec (ha : b ≀ a → p a) (hb : a ≀ b → p b) : p (max a b) := by obtain hab | hba := le_total a b <;> simp [max_eq_left, max_eq_right, *] lemma min_rec' (p : α → Prop) (ha : p a) (hb : p b) : p (min a b) := min_rec (fun _ ↩ ha) fun _ ↩ hb lemma max_rec' (p : α → Prop) (ha : p a) (hb : p b) : p (max a b) := max_rec (fun _ ↩ ha) fun _ ↩ hb lemma min_def_lt (a b : α) : min a b = if a < b then a else b := by rw [min_comm, min_def, ← ite_not]; simp only [not_le] lemma max_def_lt (a b : α) : max a b = if a < b then b else a := by rw [max_comm, max_def, ← ite_not]; simp only [not_le] end MinMaxRec end LinearOrder /-! ### Implications -/ lemma lt_imp_lt_of_le_imp_le {β} [LinearOrder α] [Preorder β] {a b : α} {c d : β} (H : a ≀ b → c ≀ d) (h : d < c) : b < a := lt_of_not_le fun h' ↩ (H h').not_lt h lemma le_imp_le_iff_lt_imp_lt {β} [LinearOrder α] [LinearOrder β] {a b : α} {c d : β} : a ≀ b → c ≀ d ↔ d < c → b < a := ⟹lt_imp_lt_of_le_imp_le, le_imp_le_of_lt_imp_lt⟩ lemma lt_iff_lt_of_le_iff_le' {β} [Preorder α] [Preorder β] {a b : α} {c d : β} (H : a ≀ b ↔ c ≀ d) (H' : b ≀ a ↔ d ≀ c) : b < a ↔ d < c := lt_iff_le_not_le.trans <| (and_congr H' (not_congr H)).trans lt_iff_le_not_le.symm lemma lt_iff_lt_of_le_iff_le {β} [LinearOrder α] [LinearOrder β] {a b : α} {c d : β} (H : a ≀ b ↔ c ≀ d) : b < a ↔ d < c := not_le.symm.trans <| (not_congr H).trans <| not_le lemma le_iff_le_iff_lt_iff_lt {β} [LinearOrder α] [LinearOrder β] {a b : α} {c d : β} : (a ≀ b ↔ c ≀ d) ↔ (b < a ↔ d < c) := ⟹lt_iff_lt_of_le_iff_le, fun H ↩ not_lt.symm.trans <| (not_congr H).trans <| not_lt⟩ /-- A symmetric relation implies two values are equal, when it implies they're less-equal. -/ lemma rel_imp_eq_of_rel_imp_le [PartialOrder β] (r : α → α → Prop) [IsSymm α r] {f : α → β} (h : ∀ a b, r a b → f a ≀ f b) {a b : α} : r a b → f a = f b := fun hab ↩ le_antisymm (h a b hab) (h b a <| symm hab) /-! ### Extensionality lemmas -/ @[ext] lemma Preorder.toLE_injective : Function.Injective (@Preorder.toLE α) := fun | { lt := A_lt, lt_iff_le_not_le := A_iff, .. }, { lt := B_lt, lt_iff_le_not_le := B_iff, .. } => by rintro ⟚⟩ have : A_lt = B_lt := by funext a b rw [A_iff, B_iff] cases this congr @[ext] lemma PartialOrder.toPreorder_injective : Function.Injective (@PartialOrder.toPreorder α) := by rintro ⟚⟩ ⟚⟩ ⟚⟩; congr @[ext] lemma LinearOrder.toPartialOrder_injective : Function.Injective (@LinearOrder.toPartialOrder α) := fun | { le := A_le, lt := A_lt, toDecidableLE := A_decidableLE, toDecidableEq := A_decidableEq, toDecidableLT := A_decidableLT min := A_min, max := A_max, min_def := A_min_def, max_def := A_max_def, compare := A_compare, compare_eq_compareOfLessAndEq := A_compare_canonical, .. }, { le := B_le, lt := B_lt, toDecidableLE := B_decidableLE, toDecidableEq := B_decidableEq, toDecidableLT := B_decidableLT min := B_min, max := B_max, min_def := B_min_def, max_def := B_max_def, compare := B_compare, compare_eq_compareOfLessAndEq := B_compare_canonical, .. } => by rintro ⟚⟩ obtain rfl : A_decidableLE = B_decidableLE := Subsingleton.elim _ _ obtain rfl : A_decidableEq = B_decidableEq := Subsingleton.elim _ _ obtain rfl : A_decidableLT = B_decidableLT := Subsingleton.elim _ _ have : A_min = B_min := by funext a b exact (A_min_def _ _).trans (B_min_def _ _).symm cases this have : A_max = B_max := by funext a b exact (A_max_def _ _).trans (B_max_def _ _).symm cases this have : A_compare = B_compare := by funext a b exact (A_compare_canonical _ _).trans (B_compare_canonical _ _).symm congr lemma Preorder.ext {A B : Preorder α} (H : ∀ x y : α, (haveI := A; x ≀ y) ↔ x ≀ y) : A = B := by ext x y; exact H x y lemma PartialOrder.ext {A B : PartialOrder α} (H : ∀ x y : α, (haveI := A; x ≀ y) ↔ x ≀ y) : A = B := by ext x y; exact H x y lemma PartialOrder.ext_lt {A B : PartialOrder α} (H : ∀ x y : α, (haveI := A; x < y) ↔ x < y) : A = B := by ext x y; rw [le_iff_lt_or_eq, @le_iff_lt_or_eq _ A, H] lemma LinearOrder.ext {A B : LinearOrder α} (H : ∀ x y : α, (haveI := A; x ≀ y) ↔ x ≀ y) : A = B := by ext x y; exact H x y lemma LinearOrder.ext_lt {A B : LinearOrder α} (H : ∀ x y : α, (haveI := A; x < y) ↔ x < y) : A = B := LinearOrder.toPartialOrder_injective (PartialOrder.ext_lt H) /-! ### Order dual -/ /-- Type synonym to equip a type with the dual order: `≀` means `≥` and `<` means `>`. `αᵒᵈ` is notation for `OrderDual α`. -/ def OrderDual (α : Type*) : Type _ := α @[inherit_doc] notation:max α "ᵒᵈ" => OrderDual α namespace OrderDual instance (α : Type*) [h : Nonempty α] : Nonempty αᵒᵈ := h instance (α : Type*) [h : Subsingleton α] : Subsingleton αᵒᵈ := h instance (α : Type*) [LE α] : LE αᵒᵈ := ⟹fun x y : α ↩ y ≀ x⟩ instance (α : Type*) [LT α] : LT αᵒᵈ := ⟹fun x y : α ↩ y < x⟩ instance instOrd (α : Type*) [Ord α] : Ord αᵒᵈ where compare := fun (a b : α) ↩ compare b a instance instSup (α : Type*) [Min α] : Max αᵒᵈ := ⟹((· ⊓ ·) : α → α → α)⟩ instance instInf (α : Type*) [Max α] : Min αᵒᵈ := ⟹((· ⊔ ·) : α → α → α)⟩ instance instPreorder (α : Type*) [Preorder α] : Preorder αᵒᵈ where le_refl := fun _ ↩ le_refl _ le_trans := fun _ _ _ hab hbc ↩ hbc.trans hab lt_iff_le_not_le := fun _ _ ↩ lt_iff_le_not_le instance instPartialOrder (α : Type*) [PartialOrder α] : PartialOrder αᵒᵈ where __ := inferInstanceAs (Preorder αᵒᵈ) le_antisymm := fun a b hab hba ↩ @le_antisymm α _ a b hba hab instance instLinearOrder (α : Type*) [LinearOrder α] : LinearOrder αᵒᵈ where __ := inferInstanceAs (PartialOrder αᵒᵈ) __ := inferInstanceAs (Ord αᵒᵈ) le_total := fun a b : α ↩ le_total b a max := fun a b ↩ (min a b : α) min := fun a b ↩ (max a b : α) min_def := fun a b ↩ show (max .. : α) = _ by rw [max_comm, max_def]; rfl max_def := fun a b ↩ show (min .. : α) = _ by rw [min_comm, min_def]; rfl toDecidableLE := (inferInstance : DecidableRel (fun a b : α ↩ b ≀ a)) toDecidableLT := (inferInstance : DecidableRel (fun a b : α ↩ b < a)) toDecidableEq := (inferInstance : DecidableEq α) compare_eq_compareOfLessAndEq a b := by simp only [compare, LinearOrder.compare_eq_compareOfLessAndEq, compareOfLessAndEq, eq_comm] rfl /-- The opposite linear order to a given linear order -/ def _root_.LinearOrder.swap (α : Type*) (_ : LinearOrder α) : LinearOrder α := inferInstanceAs <| LinearOrder (OrderDual α) instance : ∀ [Inhabited α], Inhabited αᵒᵈ := fun [x : Inhabited α] => x theorem Ord.dual_dual (α : Type*) [H : Ord α] : OrderDual.instOrd αᵒᵈ = H := rfl theorem Preorder.dual_dual (α : Type*) [H : Preorder α] : OrderDual.instPreorder αᵒᵈ = H := rfl theorem instPartialOrder.dual_dual (α : Type*) [H : PartialOrder α] : OrderDual.instPartialOrder αᵒᵈ = H := rfl theorem instLinearOrder.dual_dual (α : Type*) [H : LinearOrder α] : OrderDual.instLinearOrder αᵒᵈ = H := rfl end OrderDual /-! ### `HasCompl` -/ instance Prop.hasCompl : HasCompl Prop := ⟹Not⟩ instance Pi.hasCompl [∀ i, HasCompl (π i)] : HasCompl (∀ i, π i) := ⟹fun x i ↩ (x i)ᶜ⟩ theorem Pi.compl_def [∀ i, HasCompl (π i)] (x : ∀ i, π i) : xᶜ = fun i ↩ (x i)ᶜ := rfl @[simp] theorem Pi.compl_apply [∀ i, HasCompl (π i)] (x : ∀ i, π i) (i : ι) : xᶜ i = (x i)ᶜ := rfl instance IsIrrefl.compl (r) [IsIrrefl α r] : IsRefl α rᶜ := ⟹@irrefl α r _⟩ instance IsRefl.compl (r) [IsRefl α r] : IsIrrefl α rᶜ := ⟹fun a ↩ not_not_intro (refl a)⟩ theorem compl_lt [LinearOrder α] : (· < · : α → α → _)ᶜ = (· ≥ ·) := by ext; simp [compl] theorem compl_le [LinearOrder α] : (· ≀ · : α → α → _)ᶜ = (· > ·) := by ext; simp [compl] theorem compl_gt [LinearOrder α] : (· > · : α → α → _)ᶜ = (· ≀ ·) := by ext; simp [compl] theorem compl_ge [LinearOrder α] : (· ≥ · : α → α → _)ᶜ = (· < ·) := by ext; simp [compl] instance Ne.instIsEquiv_compl : IsEquiv α (· ≠ ·)ᶜ := by convert eq_isEquiv α simp [compl] /-! ### Order instances on the function space -/ instance Pi.hasLe [∀ i, LE (π i)] : LE (∀ i, π i) where le x y := ∀ i, x i ≀ y i theorem Pi.le_def [∀ i, LE (π i)] {x y : ∀ i, π i} : x ≀ y ↔ ∀ i, x i ≀ y i := Iff.rfl instance Pi.preorder [∀ i, Preorder (π i)] : Preorder (∀ i, π i) where __ := inferInstanceAs (LE (∀ i, π i)) le_refl := fun a i ↩ le_refl (a i) le_trans := fun _ _ _ h₁ h₂ i ↩ le_trans (h₁ i) (h₂ i) theorem Pi.lt_def [∀ i, Preorder (π i)] {x y : ∀ i, π i} : x < y ↔ x ≀ y ∧ ∃ i, x i < y i := by simp +contextual [lt_iff_le_not_le, Pi.le_def] instance Pi.partialOrder [∀ i, PartialOrder (π i)] : PartialOrder (∀ i, π i) where __ := Pi.preorder le_antisymm := fun _ _ h1 h2 ↩ funext fun b ↩ (h1 b).antisymm (h2 b) namespace Sum variable {α₁ α₂ : Type*} [LE β] @[simp] lemma elim_le_elim_iff {u₁ v₁ : α₁ → β} {u₂ v₂ : α₂ → β} : Sum.elim u₁ u₂ ≀ Sum.elim v₁ v₂ ↔ u₁ ≀ v₁ ∧ u₂ ≀ v₂ := Sum.forall lemma const_le_elim_iff {b : β} {v₁ : α₁ → β} {v₂ : α₂ → β} : Function.const _ b ≀ Sum.elim v₁ v₂ ↔ Function.const _ b ≀ v₁ ∧ Function.const _ b ≀ v₂ := elim_const_const b ▾ elim_le_elim_iff .. lemma elim_le_const_iff {b : β} {u₁ : α₁ → β} {u₂ : α₂ → β} : Sum.elim u₁ u₂ ≀ Function.const _ b ↔ u₁ ≀ Function.const _ b ∧ u₂ ≀ Function.const _ b := elim_const_const b ▾ elim_le_elim_iff .. end Sum section Pi /-- A function `a` is strongly less than a function `b` if `a i < b i` for all `i`. -/ def StrongLT [∀ i, LT (π i)] (a b : ∀ i, π i) : Prop := ∀ i, a i < b i @[inherit_doc] local infixl:50 " ≺ " => StrongLT variable [∀ i, Preorder (π i)] {a b c : ∀ i, π i} theorem le_of_strongLT (h : a ≺ b) : a ≀ b := fun _ ↩ (h _).le theorem lt_of_strongLT [Nonempty ι] (h : a ≺ b) : a < b := by inhabit ι exact Pi.lt_def.2 ⟹le_of_strongLT h, default, h _⟩ theorem strongLT_of_strongLT_of_le (hab : a ≺ b) (hbc : b ≀ c) : a ≺ c := fun _ ↩ (hab _).trans_le <| hbc _ theorem strongLT_of_le_of_strongLT (hab : a ≀ b) (hbc : b ≺ c) : a ≺ c := fun _ ↩ (hab _).trans_lt <| hbc _ alias StrongLT.le := le_of_strongLT alias StrongLT.lt := lt_of_strongLT alias StrongLT.trans_le := strongLT_of_strongLT_of_le alias LE.le.trans_strongLT := strongLT_of_le_of_strongLT end Pi section Function variable [DecidableEq ι] [∀ i, Preorder (π i)] {x y : ∀ i, π i} {i : ι} {a b : π i} theorem le_update_iff : x ≀ Function.update y i a ↔ x i ≀ a ∧ ∀ (j) (_ : j ≠ i), x j ≀ y j := Function.forall_update_iff _ fun j z ↩ x j ≀ z theorem update_le_iff : Function.update x i a ≀ y ↔ a ≀ y i ∧ ∀ (j) (_ : j ≠ i), x j ≀ y j := Function.forall_update_iff _ fun j z ↩ z ≀ y j theorem update_le_update_iff : Function.update x i a ≀ Function.update y i b ↔ a ≀ b ∧ ∀ (j) (_ : j ≠ i), x j ≀ y j := by simp +contextual [update_le_iff] @[simp] theorem update_le_update_iff' : update x i a ≀ update x i b ↔ a ≀ b := by simp [update_le_update_iff] @[simp] theorem update_lt_update_iff : update x i a < update x i b ↔ a < b := lt_iff_lt_of_le_iff_le' update_le_update_iff' update_le_update_iff' @[simp] theorem le_update_self_iff : x ≀ update x i a ↔ x i ≀ a := by simp [le_update_iff] @[simp] theorem update_le_self_iff : update x i a ≀ x ↔ a ≀ x i := by simp [update_le_iff] @[simp] theorem lt_update_self_iff : x < update x i a ↔ x i < a := by simp [lt_iff_le_not_le] @[simp] theorem update_lt_self_iff : update x i a < x ↔ a < x i := by simp [lt_iff_le_not_le] end Function instance Pi.sdiff [∀ i, SDiff (π i)] : SDiff (∀ i, π i) := ⟹fun x y i ↩ x i \ y i⟩ theorem Pi.sdiff_def [∀ i, SDiff (π i)] (x y : ∀ i, π i) : x \ y = fun i ↩ x i \ y i := rfl @[simp] theorem Pi.sdiff_apply [∀ i, SDiff (π i)] (x y : ∀ i, π i) (i : ι) : (x \ y) i = x i \ y i := rfl namespace Function variable [Preorder α] [Nonempty β] {a b : α} @[simp] theorem const_le_const : const β a ≀ const β b ↔ a ≀ b := by simp [Pi.le_def] @[simp] theorem const_lt_const : const β a < const β b ↔ a < b := by simpa [Pi.lt_def] using le_of_lt end Function /-! ### Lifts of order instances -/ /-- Transfer a `Preorder` on `β` to a `Preorder` on `α` using a function `f : α → β`. See note [reducible non-instances]. -/ abbrev Preorder.lift [Preorder β] (f : α → β) : Preorder α where le x y := f x ≀ f y le_refl _ := le_rfl le_trans _ _ _ := _root_.le_trans lt x y := f x < f y lt_iff_le_not_le _ _ := _root_.lt_iff_le_not_le /-- Transfer a `PartialOrder` on `β` to a `PartialOrder` on `α` using an injective function `f : α → β`. See note [reducible non-instances]. -/ abbrev PartialOrder.lift [PartialOrder β] (f : α → β) (inj : Injective f) : PartialOrder α := { Preorder.lift f with le_antisymm := fun _ _ h₁ h₂ ↩ inj (h₁.antisymm h₂) } theorem compare_of_injective_eq_compareOfLessAndEq (a b : α) [LinearOrder β] [DecidableEq α] (f : α → β) (inj : Injective f) [Decidable (LT.lt (self := PartialOrder.lift f inj |>.toLT) a b)] : compare (f a) (f b) = @compareOfLessAndEq _ a b (PartialOrder.lift f inj |>.toLT) _ _ := by have h := LinearOrder.compare_eq_compareOfLessAndEq (f a) (f b) simp only [h, compareOfLessAndEq] split_ifs <;> try (first | rfl | contradiction) · have : ¬ f a = f b := by rename_i h; exact inj.ne h contradiction · have : f a = f b := by rename_i h; exact congrArg f h contradiction /-- Transfer a `LinearOrder` on `β` to a `LinearOrder` on `α` using an injective function `f : α → β`. This version takes `[Max α]` and `[Min α]` as arguments, then uses them for `max` and `min` fields. See `LinearOrder.lift'` for a version that autogenerates `min` and `max` fields, and `LinearOrder.liftWithOrd` for one that does not auto-generate `compare` fields. See note [reducible non-instances]. -/ abbrev LinearOrder.lift [LinearOrder β] [Max α] [Min α] (f : α → β) (inj : Injective f) (hsup : ∀ x y, f (x ⊔ y) = max (f x) (f y)) (hinf : ∀ x y, f (x ⊓ y) = min (f x) (f y)) : LinearOrder α := letI instOrdα : Ord α := ⟹fun a b ↩ compare (f a) (f b)⟩ letI decidableLE := fun x y ↩ (inferInstance : Decidable (f x ≀ f y)) letI decidableLT := fun x y ↩ (inferInstance : Decidable (f x < f y)) letI decidableEq := fun x y ↩ decidable_of_iff (f x = f y) inj.eq_iff { PartialOrder.lift f inj, instOrdα with le_total := fun x y ↩ le_total (f x) (f y) toDecidableLE := decidableLE toDecidableLT := decidableLT toDecidableEq := decidableEq min := (· ⊓ ·) max := (· ⊔ ·) min_def := by intros x y apply inj rw [apply_ite f] exact (hinf _ _).trans (min_def _ _) max_def := by intros x y apply inj rw [apply_ite f] exact (hsup _ _).trans (max_def _ _) compare_eq_compareOfLessAndEq := fun a b ↩ compare_of_injective_eq_compareOfLessAndEq a b f inj } /-- Transfer a `LinearOrder` on `β` to a `LinearOrder` on `α` using an injective function `f : α → β`. This version autogenerates `min` and `max` fields. See `LinearOrder.lift` for a version that takes `[Max α]` and `[Min α]`, then uses them as `max` and `min`. See `LinearOrder.liftWithOrd'` for a version which does not auto-generate `compare` fields. See note [reducible non-instances]. -/ abbrev LinearOrder.lift' [LinearOrder β] (f : α → β) (inj : Injective f) : LinearOrder α := @LinearOrder.lift α β _ ⟹fun x y ↩ if f x ≀ f y then y else x⟩ ⟹fun x y ↩ if f x ≀ f y then x else y⟩ f inj (fun _ _ ↩ (apply_ite f _ _ _).trans (max_def _ _).symm) fun _ _ ↩ (apply_ite f _ _ _).trans (min_def _ _).symm /-- Transfer a `LinearOrder` on `β` to a `LinearOrder` on `α` using an injective function `f : α → β`. This version takes `[Max α]` and `[Min α]` as arguments, then uses them for `max` and `min` fields. It also takes `[Ord α]` as an argument and uses them for `compare` fields. See `LinearOrder.lift` for a version that autogenerates `compare` fields, and `LinearOrder.liftWithOrd'` for one that auto-generates `min` and `max` fields. fields. See note [reducible non-instances]. -/ abbrev LinearOrder.liftWithOrd [LinearOrder β] [Max α] [Min α] [Ord α] (f : α → β) (inj : Injective f) (hsup : ∀ x y, f (x ⊔ y) = max (f x) (f y)) (hinf : ∀ x y, f (x ⊓ y) = min (f x) (f y)) (compare_f : ∀ a b : α, compare a b = compare (f a) (f b)) : LinearOrder α := letI decidableLE := fun x y ↩ (inferInstance : Decidable (f x ≀ f y)) letI decidableLT := fun x y ↩ (inferInstance : Decidable (f x < f y)) letI decidableEq := fun x y ↩ decidable_of_iff (f x = f y) inj.eq_iff { PartialOrder.lift f inj with le_total := fun x y ↩ le_total (f x) (f y) toDecidableLE := decidableLE toDecidableLT := decidableLT toDecidableEq := decidableEq min := (· ⊓ ·) max := (· ⊔ ·) min_def := by intros x y apply inj rw [apply_ite f] exact (hinf _ _).trans (min_def _ _) max_def := by intros x y apply inj rw [apply_ite f] exact (hsup _ _).trans (max_def _ _) compare_eq_compareOfLessAndEq := fun a b ↩ (compare_f a b).trans <| compare_of_injective_eq_compareOfLessAndEq a b f inj } /-- Transfer a `LinearOrder` on `β` to a `LinearOrder` on `α` using an injective function `f : α → β`. This version auto-generates `min` and `max` fields. It also takes `[Ord α]` as an argument and uses them for `compare` fields. See `LinearOrder.lift` for a version that autogenerates `compare` fields, and `LinearOrder.liftWithOrd` for one that doesn't auto-generate `min` and `max` fields. fields. See note [reducible non-instances]. -/ abbrev LinearOrder.liftWithOrd' [LinearOrder β] [Ord α] (f : α → β) (inj : Injective f) (compare_f : ∀ a b : α, compare a b = compare (f a) (f b)) : LinearOrder α := @LinearOrder.liftWithOrd α β _ ⟹fun x y ↩ if f x ≀ f y then y else x⟩ ⟹fun x y ↩ if f x ≀ f y then x else y⟩ _ f inj (fun _ _ ↩ (apply_ite f _ _ _).trans (max_def _ _).symm) (fun _ _ ↩ (apply_ite f _ _ _).trans (min_def _ _).symm) compare_f /-! ### Subtype of an order -/ namespace Subtype instance le [LE α] {p : α → Prop} : LE (Subtype p) := ⟹fun x y ↩ (x : α) ≀ y⟩ instance lt [LT α] {p : α → Prop} : LT (Subtype p) := ⟹fun x y ↩ (x : α) < y⟩ @[simp] theorem mk_le_mk [LE α] {p : α → Prop} {x y : α} {hx : p x} {hy : p y} : (⟹x, hx⟩ : Subtype p) ≀ ⟹y, hy⟩ ↔ x ≀ y := Iff.rfl @[simp] theorem mk_lt_mk [LT α] {p : α → Prop} {x y : α} {hx : p x} {hy : p y} : (⟹x, hx⟩ : Subtype p) < ⟹y, hy⟩ ↔ x < y := Iff.rfl @[simp, norm_cast] theorem coe_le_coe [LE α] {p : α → Prop} {x y : Subtype p} : (x : α) ≀ y ↔ x ≀ y := Iff.rfl @[gcongr] alias ⟹_, GCongr.coe_le_coe⟩ := coe_le_coe @[simp, norm_cast] theorem coe_lt_coe [LT α] {p : α → Prop} {x y : Subtype p} : (x : α) < y ↔ x < y := Iff.rfl @[gcongr] alias ⟹_, GCongr.coe_lt_coe⟩ := coe_lt_coe instance preorder [Preorder α] (p : α → Prop) : Preorder (Subtype p) := Preorder.lift (fun (a : Subtype p) ↩ (a : α)) instance partialOrder [PartialOrder α] (p : α → Prop) : PartialOrder (Subtype p) := PartialOrder.lift (fun (a : Subtype p) ↩ (a : α)) Subtype.coe_injective instance decidableLE [Preorder α] [h : DecidableLE α] {p : α → Prop} : DecidableLE (Subtype p) := fun a b ↩ h a b instance decidableLT [Preorder α] [h : DecidableLT α] {p : α → Prop} : DecidableLT (Subtype p) := fun a b ↩ h a b /-- A subtype of a linear order is a linear order. We explicitly give the proofs of decidable equality and decidable order in order to ensure the decidability instances are all definitionally equal. -/ instance instLinearOrder [LinearOrder α] (p : α → Prop) : LinearOrder (Subtype p) := @LinearOrder.lift (Subtype p) _ _ ⟹fun x y ↩ ⟹max x y, max_rec' _ x.2 y.2⟩⟩ ⟹fun x y ↩ ⟹min x y, min_rec' _ x.2 y.2⟩⟩ (fun (a : Subtype p) ↩ (a : α)) Subtype.coe_injective (fun _ _ ↩ rfl) fun _ _ ↩ rfl end Subtype /-! ### Pointwise order on `α × β` The lexicographic order is defined in `Data.Prod.Lex`, and the instances are available via the type synonym `α ×ₗ β = α × β`. -/ namespace Prod section LE variable [LE α] [LE β] {x y : α × β} {a a₁ a₂ : α} {b b₁ b₂ : β} instance : LE (α × β) where le p q := p.1 ≀ q.1 ∧ p.2 ≀ q.2 instance instDecidableLE [Decidable (x.1 ≀ y.1)] [Decidable (x.2 ≀ y.2)] : Decidable (x ≀ y) := inferInstanceAs (Decidable (x.1 ≀ y.1 ∧ x.2 ≀ y.2)) lemma le_def : x ≀ y ↔ x.1 ≀ y.1 ∧ x.2 ≀ y.2 := .rfl @[simp] lemma mk_le_mk : (a₁, b₁) ≀ (a₂, b₂) ↔ a₁ ≀ a₂ ∧ b₁ ≀ b₂ := .rfl @[simp] lemma swap_le_swap : x.swap ≀ y.swap ↔ x ≀ y := and_comm @[simp] lemma swap_le_mk : x.swap ≀ (b, a) ↔ x ≀ (a, b) := and_comm @[simp] lemma mk_le_swap : (b, a) ≀ x.swap ↔ (a, b) ≀ x := and_comm end LE section Preorder variable [Preorder α] [Preorder β] {a a₁ a₂ : α} {b b₁ b₂ : β} {x y : α × β} instance : Preorder (α × β) where __ := inferInstanceAs (LE (α × β)) le_refl := fun ⟹a, b⟩ ↩ ⟹le_refl a, le_refl b⟩ le_trans := fun ⟹_, _⟩ ⟹_, _⟩ ⟹_, _⟩ ⟹hac, hbd⟩ ⟹hce, hdf⟩ ↩ ⟹le_trans hac hce, le_trans hbd hdf⟩ @[simp] theorem swap_lt_swap : x.swap < y.swap ↔ x < y := and_congr swap_le_swap (not_congr swap_le_swap) @[simp] lemma swap_lt_mk : x.swap < (b, a) ↔ x < (a, b) := by rw [← swap_lt_swap]; simp @[simp] lemma mk_lt_swap : (b, a) < x.swap ↔ (a, b) < x := by rw [← swap_lt_swap]; simp theorem mk_le_mk_iff_left : (a₁, b) ≀ (a₂, b) ↔ a₁ ≀ a₂ := and_iff_left le_rfl theorem mk_le_mk_iff_right : (a, b₁) ≀ (a, b₂) ↔ b₁ ≀ b₂ := and_iff_right le_rfl theorem mk_lt_mk_iff_left : (a₁, b) < (a₂, b) ↔ a₁ < a₂ := lt_iff_lt_of_le_iff_le' mk_le_mk_iff_left mk_le_mk_iff_left theorem mk_lt_mk_iff_right : (a, b₁) < (a, b₂) ↔ b₁ < b₂ := lt_iff_lt_of_le_iff_le' mk_le_mk_iff_right mk_le_mk_iff_right theorem lt_iff : x < y ↔ x.1 < y.1 ∧ x.2 ≀ y.2 √ x.1 ≀ y.1 ∧ x.2 < y.2 := by refine ⟹fun h ↩ ?_, ?_⟩ · by_cases h₁ : y.1 ≀ x.1 · exact Or.inr ⟹h.1.1, LE.le.lt_of_not_le h.1.2 fun h₂ ↩ h.2 ⟹h₁, h₂⟩⟩ · exact Or.inl ⟹LE.le.lt_of_not_le h.1.1 h₁, h.1.2⟩ · rintro (⟹h₁, h₂⟩ | ⟹h₁, h₂⟩) · exact ⟹⟹h₁.le, h₂⟩, fun h ↩ h₁.not_le h.1⟩ · exact ⟹⟹h₁, h₂.le⟩, fun h ↩ h₂.not_le h.2⟩ @[simp] theorem mk_lt_mk : (a₁, b₁) < (a₂, b₂) ↔ a₁ < a₂ ∧ b₁ ≀ b₂ √ a₁ ≀ a₂ ∧ b₁ < b₂ := lt_iff protected lemma lt_of_lt_of_le (h₁ : x.1 < y.1) (h₂ : x.2 ≀ y.2) : x < y := by simp [lt_iff, *] protected lemma lt_of_le_of_lt (h₁ : x.1 ≀ y.1) (h₂ : x.2 < y.2) : x < y := by simp [lt_iff, *] lemma mk_lt_mk_of_lt_of_le (h₁ : a₁ < a₂) (h₂ : b₁ ≀ b₂) : (a₁, b₁) < (a₂, b₂) := by simp [lt_iff, *] lemma mk_lt_mk_of_le_of_lt (h₁ : a₁ ≀ a₂) (h₂ : b₁ < b₂) : (a₁, b₁) < (a₂, b₂) := by simp [lt_iff, *] end Preorder /-- The pointwise partial order on a product. (The lexicographic ordering is defined in `Order.Lexicographic`, and the instances are available via the type synonym `α ×ₗ β = α × β`.) -/ instance instPartialOrder (α β : Type*) [PartialOrder α] [PartialOrder β] : PartialOrder (α × β) where __ := inferInstanceAs (Preorder (α × β)) le_antisymm := fun _ _ ⟹hac, hbd⟩ ⟹hca, hdb⟩ ↩ Prod.ext (hac.antisymm hca) (hbd.antisymm hdb) end Prod /-! ### Additional order classes -/ /-- An order is dense if there is an element between any pair of distinct comparable elements. -/ class DenselyOrdered (α : Type*) [LT α] : Prop where /-- An order is dense if there is an element between any pair of distinct elements. -/ dense : ∀ a₁ a₂ : α, a₁ < a₂ → ∃ a, a₁ < a ∧ a < a₂ theorem exists_between [LT α] [DenselyOrdered α] : ∀ {a₁ a₂ : α}, a₁ < a₂ → ∃ a, a₁ < a ∧ a < a₂ := DenselyOrdered.dense _ _ instance OrderDual.denselyOrdered (α : Type*) [LT α] [h : DenselyOrdered α] : DenselyOrdered αᵒᵈ := ⟹fun _ _ ha ↩ (@exists_between α _ h _ _ ha).imp fun _ ↩ And.symm⟩ @[simp] theorem denselyOrdered_orderDual [LT α] : DenselyOrdered αᵒᵈ ↔ DenselyOrdered α := ⟹by convert @OrderDual.denselyOrdered αᵒᵈ _, @OrderDual.denselyOrdered α _⟩ /-- Any ordered subsingleton is densely ordered. Not an instance to avoid a heavy subsingleton typeclass search. -/ lemma Subsingleton.instDenselyOrdered {X : Type*} [Subsingleton X] [Preorder X] : DenselyOrdered X := ⟹fun _ _ h ↩ (not_lt_of_subsingleton h).elim⟩ instance [Preorder α] [Preorder β] [DenselyOrdered α] [DenselyOrdered β] : DenselyOrdered (α × β) := ⟹fun a b ↩ by simp_rw [Prod.lt_iff] rintro (⟹h₁, h₂⟩ | ⟹h₁, h₂⟩) · obtain ⟹c, ha, hb⟩ := exists_between h₁ exact ⟹(c, _), Or.inl ⟹ha, h₂⟩, Or.inl ⟹hb, le_rfl⟩⟩ · obtain ⟹c, ha, hb⟩ := exists_between h₂ exact ⟹(_, c), Or.inr ⟹h₁, ha⟩, Or.inr ⟹le_rfl, hb⟩⟩⟩ instance [∀ i, Preorder (π i)] [∀ i, DenselyOrdered (π i)] : DenselyOrdered (∀ i, π i) := ⟹fun a b ↩ by classical simp_rw [Pi.lt_def] rintro ⟹hab, i, hi⟩ obtain ⟹c, ha, hb⟩ := exists_between hi exact ⟹Function.update a i c, ⟹le_update_iff.2 ⟹ha.le, fun _ _ ↩ le_rfl⟩, i, by rwa [update_self]⟩, update_le_iff.2 ⟹hb.le, fun _ _ ↩ hab _⟩, i, by rwa [update_self]⟩⟩ section LinearOrder variable [LinearOrder α] [DenselyOrdered α] {a₁ a₂ : α} theorem le_of_forall_gt_imp_ge_of_dense (h : ∀ a, a₂ < a → a₁ ≀ a) : a₁ ≀ a₂ := le_of_not_gt fun ha ↩ let ⟹a, ha₁, ha₂⟩ := exists_between ha lt_irrefl a <| lt_of_lt_of_le ‹a < a₁› (h _ ‹a₂ < a›) lemma forall_gt_imp_ge_iff_le_of_dense : (∀ a, a₂ < a → a₁ ≀ a) ↔ a₁ ≀ a₂ := ⟹le_of_forall_gt_imp_ge_of_dense, fun ha _a ha₂ ↩ ha.trans ha₂.le⟩ lemma eq_of_le_of_forall_lt_imp_le_of_dense (h₁ : a₂ ≀ a₁) (h₂ : ∀ a, a₂ < a → a₁ ≀ a) : a₁ = a₂ := le_antisymm (le_of_forall_gt_imp_ge_of_dense h₂) h₁ theorem le_of_forall_lt_imp_le_of_dense (h : ∀ a < a₁, a ≀ a₂) : a₁ ≀ a₂ := le_of_not_gt fun ha ↩ let ⟹a, ha₁, ha₂⟩ := exists_between ha lt_irrefl a <| lt_of_le_of_lt (h _ ‹a < a₁›) ‹a₂ < a› lemma forall_lt_imp_le_iff_le_of_dense : (∀ a < a₁, a ≀ a₂) ↔ a₁ ≀ a₂ := ⟹le_of_forall_lt_imp_le_of_dense, fun ha _a ha₁ ↩ ha₁.le.trans ha⟩ theorem eq_of_le_of_forall_gt_imp_ge_of_dense (h₁ : a₂ ≀ a₁) (h₂ : ∀ a < a₁, a ≀ a₂) : a₁ = a₂ := (le_of_forall_lt_imp_le_of_dense h₂).antisymm h₁ @[deprecated (since := "2025-01-21")] alias le_of_forall_le_of_dense := le_of_forall_gt_imp_ge_of_dense @[deprecated (since := "2025-01-21")] alias le_of_forall_ge_of_dense := le_of_forall_lt_imp_le_of_dense @[deprecated (since := "2025-01-21")] alias forall_lt_le_iff := forall_lt_imp_le_iff_le_of_dense @[deprecated (since := "2025-01-21")] alias forall_gt_ge_iff := forall_gt_imp_ge_iff_le_of_dense @[deprecated (since := "2025-01-21")] alias eq_of_le_of_forall_le_of_dense := eq_of_le_of_forall_lt_imp_le_of_dense @[deprecated (since := "2025-01-21")] alias eq_of_le_of_forall_ge_of_dense := eq_of_le_of_forall_gt_imp_ge_of_dense end LinearOrder theorem dense_or_discrete [LinearOrder α] (a₁ a₂ : α) : (∃ a, a₁ < a ∧ a < a₂) √ (∀ a, a₁ < a → a₂ ≀ a) ∧ ∀ a < a₂, a ≀ a₁ := or_iff_not_imp_left.2 fun h ↩ ⟹fun a ha₁ ↩ le_of_not_gt fun ha₂ ↩ h ⟹a, ha₁, ha₂⟩, fun a ha₂ ↩ le_of_not_gt fun ha₁ ↩ h ⟹a, ha₁, ha₂⟩⟩ /-- If a linear order has no elements `x < y < z`, then it has at most two elements. -/ lemma eq_or_eq_or_eq_of_forall_not_lt_lt [LinearOrder α] (h : ∀ ⊃x y z : α⊄, x < y → y < z → False) (x y z : α) : x = y √ y = z √ x = z := by by_contra hne simp only [not_or, ← Ne.eq_def] at hne rcases hne.1.lt_or_lt with h₁ | h₁ <;> rcases hne.2.1.lt_or_lt with h₂ | h₂ <;> rcases hne.2.2.lt_or_lt with h₃ | h₃ exacts [h h₁ h₂, h h₂ h₃, h h₃ h₂, h h₃ h₁, h h₁ h₃, h h₂ h₃, h h₁ h₃, h h₂ h₁] namespace PUnit variable (a b : PUnit) instance instLinearOrder : LinearOrder PUnit where le := fun _ _ ↩ True lt := fun _ _ ↩ False max := fun _ _ ↩ unit min := fun _ _ ↩ unit toDecidableEq := inferInstance toDecidableLE := fun _ _ ↩ Decidable.isTrue trivial toDecidableLT := fun _ _ ↩ Decidable.isFalse id le_refl := by intros; trivial le_trans := by intros; trivial le_total := by intros; exact Or.inl trivial le_antisymm := by intros; rfl lt_iff_le_not_le := by simp only [not_true, and_false, forall_const] theorem max_eq : max a b = unit := rfl theorem min_eq : min a b = unit := rfl protected theorem le : a ≀ b := trivial theorem not_lt : ¬a < b := not_false instance : DenselyOrdered PUnit := ⟹fun _ _ ↩ False.elim⟩ end PUnit section «Prop» /-- Propositions form a complete boolean algebra, where the `≀` relation is given by implication. -/ instance Prop.le : LE Prop := ⟹(· → ·)⟩ @[simp] theorem le_Prop_eq : ((· ≀ ·) : Prop → Prop → Prop) = (· → ·) := rfl theorem subrelation_iff_le {r s : α → α → Prop} : Subrelation r s ↔ r ≀ s := Iff.rfl instance Prop.partialOrder : PartialOrder Prop where __ := Prop.le le_refl _ := id le_trans _ _ _ f g := g ∘ f le_antisymm _ _ Hab Hba := propext ⟹Hab, Hba⟩ end «Prop» /-! ### Linear order from a total partial order -/ /-- Type synonym to create an instance of `LinearOrder` from a `PartialOrder` and `IsTotal α (≀)` -/ def AsLinearOrder (α : Type*) := α instance [Inhabited α] : Inhabited (AsLinearOrder α) := ⟹(default : α)⟩ noncomputable instance AsLinearOrder.linearOrder [PartialOrder α] [IsTotal α (· ≀ ·)] : LinearOrder (AsLinearOrder α) where __ := inferInstanceAs (PartialOrder α) le_total := @total_of α (· ≀ ·) _ toDecidableLE := Classical.decRel _
Mathlib/Order/Basic.lean
1,540
1,542
/- Copyright (c) 2017 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Kim Morrison, Mario Carneiro, Andrew Yang -/ import Mathlib.Topology.Category.TopCat.Limits.Products /-! # Pullbacks and pushouts in the category of topological spaces -/ open TopologicalSpace Topology open CategoryTheory open CategoryTheory.Limits universe v u w noncomputable section namespace TopCat variable {J : Type v} [Category.{w} J] section Pullback variable {X Y Z : TopCat.{u}} /-- The first projection from the pullback. -/ abbrev pullbackFst (f : X ⟶ Z) (g : Y ⟶ Z) : TopCat.of { p : X × Y // f p.1 = g p.2 } ⟶ X := ofHom ⟹Prod.fst ∘ Subtype.val, by fun_prop⟩ lemma pullbackFst_apply (f : X ⟶ Z) (g : Y ⟶ Z) (x) : pullbackFst f g x = x.1.1 := rfl /-- The second projection from the pullback. -/ abbrev pullbackSnd (f : X ⟶ Z) (g : Y ⟶ Z) : TopCat.of { p : X × Y // f p.1 = g p.2 } ⟶ Y := ofHom ⟹Prod.snd ∘ Subtype.val, by fun_prop⟩ lemma pullbackSnd_apply (f : X ⟶ Z) (g : Y ⟶ Z) (x) : pullbackSnd f g x = x.1.2 := rfl /-- The explicit pullback cone of `X, Y` given by `{ p : X × Y // f p.1 = g p.2 }`. -/ def pullbackCone (f : X ⟶ Z) (g : Y ⟶ Z) : PullbackCone f g := PullbackCone.mk (pullbackFst f g) (pullbackSnd f g) (by dsimp [pullbackFst, pullbackSnd, Function.comp_def] ext ⟹x, h⟩ simpa) /-- The constructed cone is a limit. -/ def pullbackConeIsLimit (f : X ⟶ Z) (g : Y ⟶ Z) : IsLimit (pullbackCone f g) := PullbackCone.isLimitAux' _ (by intro S constructor; swap · exact ofHom { toFun := fun x => ⟹⟹S.fst x, S.snd x⟩, by simpa using ConcreteCategory.congr_hom S.condition x⟩ continuous_toFun := by fun_prop } refine ⟹?_, ?_, ?_⟩ · delta pullbackCone ext a dsimp · delta pullbackCone ext a dsimp · intro m h₁ h₂ ext x -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): used to be `ext x`. apply Subtype.ext apply Prod.ext · simpa using ConcreteCategory.congr_hom h₁ x · simpa using ConcreteCategory.congr_hom h₂ x) /-- The pullback of two maps can be identified as a subspace of `X × Y`. -/ def pullbackIsoProdSubtype (f : X ⟶ Z) (g : Y ⟶ Z) : pullback f g ≅ TopCat.of { p : X × Y // f p.1 = g p.2 } := (limit.isLimit _).conePointUniqueUpToIso (pullbackConeIsLimit f g) @[reassoc (attr := simp)] theorem pullbackIsoProdSubtype_inv_fst (f : X ⟶ Z) (g : Y ⟶ Z) : (pullbackIsoProdSubtype f g).inv ≫ pullback.fst _ _ = pullbackFst f g := by simp [pullbackCone, pullbackIsoProdSubtype] theorem pullbackIsoProdSubtype_inv_fst_apply (f : X ⟶ Z) (g : Y ⟶ Z) (x : { p : X × Y // f p.1 = g p.2 }) : pullback.fst f g ((pullbackIsoProdSubtype f g).inv x) = (x : X × Y).fst := ConcreteCategory.congr_hom (pullbackIsoProdSubtype_inv_fst f g) x @[reassoc (attr := simp)] theorem pullbackIsoProdSubtype_inv_snd (f : X ⟶ Z) (g : Y ⟶ Z) : (pullbackIsoProdSubtype f g).inv ≫ pullback.snd _ _ = pullbackSnd f g := by simp [pullbackCone, pullbackIsoProdSubtype] theorem pullbackIsoProdSubtype_inv_snd_apply (f : X ⟶ Z) (g : Y ⟶ Z) (x : { p : X × Y // f p.1 = g p.2 }) : pullback.snd f g ((pullbackIsoProdSubtype f g).inv x) = (x : X × Y).snd := ConcreteCategory.congr_hom (pullbackIsoProdSubtype_inv_snd f g) x theorem pullbackIsoProdSubtype_hom_fst (f : X ⟶ Z) (g : Y ⟶ Z) : (pullbackIsoProdSubtype f g).hom ≫ pullbackFst f g = pullback.fst _ _ := by rw [← Iso.eq_inv_comp, pullbackIsoProdSubtype_inv_fst] theorem pullbackIsoProdSubtype_hom_snd (f : X ⟶ Z) (g : Y ⟶ Z) : (pullbackIsoProdSubtype f g).hom ≫ pullbackSnd f g = pullback.snd _ _ := by rw [← Iso.eq_inv_comp, pullbackIsoProdSubtype_inv_snd] theorem pullbackIsoProdSubtype_hom_apply {f : X ⟶ Z} {g : Y ⟶ Z} (x : ↑(pullback f g)) : (pullbackIsoProdSubtype f g).hom x = ⟹⟹pullback.fst f g x, pullback.snd f g x⟩, by simpa using CategoryTheory.congr_fun pullback.condition x⟩ := by apply Subtype.ext; apply Prod.ext exacts [ConcreteCategory.congr_hom (pullbackIsoProdSubtype_hom_fst f g) x, ConcreteCategory.congr_hom (pullbackIsoProdSubtype_hom_snd f g) x] theorem pullback_topology {X Y Z : TopCat.{u}} (f : X ⟶ Z) (g : Y ⟶ Z) : (pullback f g).str = induced (pullback.fst f g) X.str ⊓ induced (pullback.snd f g) Y.str := by let homeo := homeoOfIso (pullbackIsoProdSubtype f g) refine homeo.isInducing.eq_induced.trans ?_ change induced homeo (induced _ ( (induced Prod.fst X.str) ⊓ (induced Prod.snd Y.str))) = _ simp only [induced_compose, induced_inf] congr theorem range_pullback_to_prod {X Y Z : TopCat} (f : X ⟶ Z) (g : Y ⟶ Z) : Set.range (prod.lift (pullback.fst f g) (pullback.snd f g)) = { x | (Limits.prod.fst ≫ f) x = (Limits.prod.snd ≫ g) x } := by ext x constructor · rintro ⟹y, rfl⟩ simp only [← ConcreteCategory.comp_apply, Set.mem_setOf_eq] simp [pullback.condition] · rintro (h : f (_, _).1 = g (_, _).2) use (pullbackIsoProdSubtype f g).inv ⟹⟹_, _⟩, h⟩ apply Concrete.limit_ext rintro ⟚⟚⟩⟩ <;> rw [← ConcreteCategory.comp_apply, ← ConcreteCategory.comp_apply, limit.lift_π] <;> -- This used to be `simp` before https://github.com/leanprover/lean4/pull/2644 aesop_cat /-- The pullback along an embedding is (isomorphic to) the preimage. -/ noncomputable def pullbackHomeoPreimage {X Y Z : Type*} [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z] (f : X → Z) (hf : Continuous f) (g : Y → Z) (hg : IsEmbedding g) : { p : X × Y // f p.1 = g p.2 } ≃ₜ f ⁻¹' Set.range g where toFun := fun x ↩ ⟹x.1.1, _, x.2.symm⟩ invFun := fun x ↩ ⟹⟹x.1, Exists.choose x.2⟩, (Exists.choose_spec x.2).symm⟩ left_inv := by intro x ext <;> dsimp apply hg.injective convert x.prop exact Exists.choose_spec (p := fun y ↩ g y = f (↑x : X × Y).1) _ right_inv := fun _ ↩ rfl continuous_toFun := by fun_prop continuous_invFun := by apply Continuous.subtype_mk refine continuous_subtype_val.prodMk <| hg.isInducing.continuous_iff.mpr ?_ convert hf.comp continuous_subtype_val ext x exact Exists.choose_spec x.2 theorem isInducing_pullback_to_prod {X Y Z : TopCat.{u}} (f : X ⟶ Z) (g : Y ⟶ Z) : IsInducing <| ⇑(prod.lift (pullback.fst f g) (pullback.snd f g)) := ⟹by simp [prod_topology, pullback_topology, induced_compose, ← coe_comp]⟩ @[deprecated (since := "2024-10-28")] alias inducing_pullback_to_prod := isInducing_pullback_to_prod theorem isEmbedding_pullback_to_prod {X Y Z : TopCat.{u}} (f : X ⟶ Z) (g : Y ⟶ Z) : IsEmbedding <| ⇑(prod.lift (pullback.fst f g) (pullback.snd f g)) := ⟹isInducing_pullback_to_prod f g, (TopCat.mono_iff_injective _).mp inferInstance⟩ @[deprecated (since := "2024-10-26")] alias embedding_pullback_to_prod := isEmbedding_pullback_to_prod /-- If the map `S ⟶ T` is mono, then there is a description of the image of `W ×ₛ X ⟶ Y ×ₜ Z`. -/ theorem range_pullback_map {W X Y Z S T : TopCat} (f₁ : W ⟶ S) (f₂ : X ⟶ S) (g₁ : Y ⟶ T) (g₂ : Z ⟶ T) (i₁ : W ⟶ Y) (i₂ : X ⟶ Z) (i₃ : S ⟶ T) [H₃ : Mono i₃] (eq₁ : f₁ ≫ i₃ = i₁ ≫ g₁) (eq₂ : f₂ ≫ i₃ = i₂ ≫ g₂) : Set.range (pullback.map f₁ f₂ g₁ g₂ i₁ i₂ i₃ eq₁ eq₂) = (pullback.fst g₁ g₂) ⁻¹' Set.range i₁ ∩ (pullback.snd g₁ g₂) ⁻¹' Set.range i₂ := by ext constructor · rintro ⟹y, rfl⟩ simp only [Set.mem_inter_iff, Set.mem_preimage, Set.mem_range] rw [← ConcreteCategory.comp_apply, ← ConcreteCategory.comp_apply] simp only [limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app] exact ⟹exists_apply_eq_apply _ _, exists_apply_eq_apply _ _⟩ rintro ⟹⟹x₁, hx₁⟩, ⟹x₂, hx₂⟩⟩ have : f₁ x₁ = f₂ x₂ := by apply (TopCat.mono_iff_injective _).mp H₃ rw [← ConcreteCategory.comp_apply, eq₁, ← ConcreteCategory.comp_apply, eq₂, ConcreteCategory.comp_apply, ConcreteCategory.comp_apply, hx₁, hx₂, ← ConcreteCategory.comp_apply, pullback.condition, ConcreteCategory.comp_apply] use (pullbackIsoProdSubtype f₁ f₂).inv ⟹⟹x₁, x₂⟩, this⟩ apply Concrete.limit_ext rintro (_ | _ | _) <;> rw [← ConcreteCategory.comp_apply, ← ConcreteCategory.comp_apply] · simp [hx₁, ← limit.w _ WalkingCospan.Hom.inl] · simp [hx₁] · simp [hx₂] theorem pullback_fst_range {X Y S : TopCat} (f : X ⟶ S) (g : Y ⟶ S) : Set.range (pullback.fst f g) = { x : X | ∃ y : Y, f x = g y } := by ext x constructor · rintro ⟹y, rfl⟩ use pullback.snd f g y exact CategoryTheory.congr_fun pullback.condition y · rintro ⟹y, eq⟩ use (TopCat.pullbackIsoProdSubtype f g).inv ⟹⟹x, y⟩, eq⟩ rw [pullbackIsoProdSubtype_inv_fst_apply] theorem pullback_snd_range {X Y S : TopCat} (f : X ⟶ S) (g : Y ⟶ S) : Set.range (pullback.snd f g) = { y : Y | ∃ x : X, f x = g y } := by ext y constructor · rintro ⟹x, rfl⟩ use pullback.fst f g x exact CategoryTheory.congr_fun pullback.condition x · rintro ⟹x, eq⟩ use (TopCat.pullbackIsoProdSubtype f g).inv ⟹⟹x, y⟩, eq⟩ rw [pullbackIsoProdSubtype_inv_snd_apply] /-- If there is a diagram where the morphisms `W ⟶ Y` and `X ⟶ Z` are embeddings, then the induced morphism `W ×ₛ X ⟶ Y ×ₜ Z` is also an embedding. ``` W ⟶ Y ↘ ↘ S ⟶ T ↗ ↗ X ⟶ Z ``` -/ theorem pullback_map_isEmbedding {W X Y Z S T : TopCat.{u}} (f₁ : W ⟶ S) (f₂ : X ⟶ S) (g₁ : Y ⟶ T) (g₂ : Z ⟶ T) {i₁ : W ⟶ Y} {i₂ : X ⟶ Z} (H₁ : IsEmbedding i₁) (H₂ : IsEmbedding i₂) (i₃ : S ⟶ T) (eq₁ : f₁ ≫ i₃ = i₁ ≫ g₁) (eq₂ : f₂ ≫ i₃ = i₂ ≫ g₂) : IsEmbedding (pullback.map f₁ f₂ g₁ g₂ i₁ i₂ i₃ eq₁ eq₂) := by refine .of_comp (ContinuousMap.continuous_toFun _) (show Continuous (prod.lift (pullback.fst g₁ g₂) (pullback.snd g₁ g₂)) from ContinuousMap.continuous_toFun _) ?_ suffices IsEmbedding (prod.lift (pullback.fst f₁ f₂) (pullback.snd f₁ f₂) ≫ Limits.prod.map i₁ i₂) by simpa [← coe_comp] using this rw [coe_comp] exact (isEmbedding_prodMap H₁ H₂).comp (isEmbedding_pullback_to_prod _ _) @[deprecated (since := "2024-10-26")] alias pullback_map_embedding_of_embeddings := pullback_map_isEmbedding /-- If there is a diagram where the morphisms `W ⟶ Y` and `X ⟶ Z` are open embeddings, and `S ⟶ T` is mono, then the induced morphism `W ×ₛ X ⟶ Y ×ₜ Z` is also an open embedding. ``` W ⟶ Y ↘ ↘ S ⟶ T ↗ ↗ X ⟶ Z ``` -/ theorem pullback_map_isOpenEmbedding {W X Y Z S T : TopCat.{u}} (f₁ : W ⟶ S) (f₂ : X ⟶ S) (g₁ : Y ⟶ T) (g₂ : Z ⟶ T) {i₁ : W ⟶ Y} {i₂ : X ⟶ Z} (H₁ : IsOpenEmbedding i₁) (H₂ : IsOpenEmbedding i₂) (i₃ : S ⟶ T) [H₃ : Mono i₃] (eq₁ : f₁ ≫ i₃ = i₁ ≫ g₁) (eq₂ : f₂ ≫ i₃ = i₂ ≫ g₂) : IsOpenEmbedding (pullback.map f₁ f₂ g₁ g₂ i₁ i₂ i₃ eq₁ eq₂) := by constructor · apply pullback_map_isEmbedding f₁ f₂ g₁ g₂ H₁.isEmbedding H₂.isEmbedding i₃ eq₁ eq₂ · rw [range_pullback_map] apply IsOpen.inter <;> apply Continuous.isOpen_preimage · apply ContinuousMap.continuous_toFun · exact H₁.isOpen_range · apply ContinuousMap.continuous_toFun · exact H₂.isOpen_range lemma snd_isEmbedding_of_left {X Y S : TopCat} {f : X ⟶ S} (H : IsEmbedding f) (g : Y ⟶ S) :
IsEmbedding <| ⇑(pullback.snd f g) := by convert (homeoOfIso (asIso (pullback.snd (𝟙 S) g))).isEmbedding.comp (pullback_map_isEmbedding (i₂ := 𝟙 Y) f g (𝟙 S) g H (homeoOfIso (Iso.refl _)).isEmbedding (𝟙 _) rfl (by simp)) simp [homeoOfIso, ← coe_comp] @[deprecated (since := "2024-10-26")] alias snd_embedding_of_left_embedding := snd_isEmbedding_of_left theorem fst_isEmbedding_of_right {X Y S : TopCat} (f : X ⟶ S) {g : Y ⟶ S} (H : IsEmbedding g) : IsEmbedding <| ⇑(pullback.fst f g) := by convert (homeoOfIso (asIso (pullback.fst f (𝟙 S)))).isEmbedding.comp (pullback_map_isEmbedding (i₁ := 𝟙 X) f g f (𝟙 _) (homeoOfIso (Iso.refl _)).isEmbedding H (𝟙 _) rfl (by simp))
Mathlib/Topology/Category/TopCat/Limits/Pullbacks.lean
283
296
/- 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.Tangent import Mathlib.Geometry.Manifold.ContMDiffMap import Mathlib.Geometry.Manifold.VectorBundle.Hom /-! ### Interactions between differentiability, smoothness and manifold derivatives We give the relation between `MDifferentiable`, `ContMDiff`, `mfderiv`, `tangentMap` and related notions. ## Main statements * `ContMDiffOn.contMDiffOn_tangentMapWithin` states that the bundled derivative of a `Cⁿ` function in a domain is `Cᵐ` when `m + 1 ≀ n`. * `ContMDiff.contMDiff_tangentMap` states that the bundled derivative of a `Cⁿ` function is `Cᵐ` when `m + 1 ≀ n`. -/ open Set Function Filter ChartedSpace IsManifold Bundle open scoped Topology Manifold Bundle /-! ### Definition of `C^n` functions between manifolds -/ variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {m n : WithTop ℕ∞} -- declare a charted space `M` over the pair `(E, H)`. {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] {I : ModelWithCorners 𝕜 E H} {M : Type*} [TopologicalSpace M] [ChartedSpace H M] -- declare a charted space `M'` over the pair `(E', H')`. {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H' : Type*} [TopologicalSpace H'] {I' : ModelWithCorners 𝕜 E' H'} {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M'] -- declare a `C^n` manifold `N` over the pair `(F, G)`. {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type*} [TopologicalSpace G] {J : ModelWithCorners 𝕜 F G} {N : Type*} [TopologicalSpace N] [ChartedSpace G N] [Js : IsManifold J 1 N] -- declare a charted space `N'` over the pair `(F', G')`. {F' : Type*} [NormedAddCommGroup F'] [NormedSpace 𝕜 F'] {G' : Type*} [TopologicalSpace G'] {J' : ModelWithCorners 𝕜 F' G'} {N' : Type*} [TopologicalSpace N'] [ChartedSpace G' N'] -- declare functions, sets {f : M → M'} {s : Set M} -- Porting note: section about deducing differentiability for `C^n` functions moved to -- `Geometry.Manifold.MFDeriv.Basic` /-! ### The derivative of a `C^(n+1)` function is `C^n` -/ section mfderiv variable [Is : IsManifold I 1 M] [I's : IsManifold I' 1 M'] /-- The function that sends `x` to the `y`-derivative of `f (x, y)` at `g (x)` is `C^m` at `x₀`, where the derivative is taken as a continuous linear map. We have to assume that `f` is `C^n` at `(x₀, g(x₀))` for `n ≥ m + 1` and `g` is `C^m` at `x₀`. We have to insert a coordinate change from `x₀` to `x` to make the derivative sensible. Version within a set. -/ protected theorem ContMDiffWithinAt.mfderivWithin {x₀ : N} {f : N → M → M'} {g : N → M} {t : Set N} {u : Set M} (hf : ContMDiffWithinAt (J.prod I) I' n (Function.uncurry f) (t ×ˢ u) (x₀, g x₀)) (hg : ContMDiffWithinAt J I m g t x₀) (hx₀ : x₀ ∈ t) (hu : MapsTo g t u) (hmn : m + 1 ≀ n) (h'u : UniqueMDiffOn I u) : ContMDiffWithinAt J 𝓘(𝕜, E →L[𝕜] E') m (inTangentCoordinates I I' g (fun x => f x (g x)) (fun x => mfderivWithin I I' (f x) u (g x)) x₀) t x₀ := by -- first localize the result to a smaller set, to make sure everything happens in chart domains let t' := t ∩ g ⁻¹' ((extChartAt I (g x₀)).source) have ht't : t' ⊆ t := inter_subset_left suffices ContMDiffWithinAt J 𝓘(𝕜, E →L[𝕜] E') m (inTangentCoordinates I I' g (fun x ↩ f x (g x)) (fun x ↩ mfderivWithin I I' (f x) u (g x)) x₀) t' x₀ by apply ContMDiffWithinAt.mono_of_mem_nhdsWithin this apply inter_mem self_mem_nhdsWithin exact hg.continuousWithinAt.preimage_mem_nhdsWithin (extChartAt_source_mem_nhds (g x₀)) -- register a few basic facts that maps send suitable neighborhoods to suitable neighborhoods, -- by continuity have hx₀gx₀ : (x₀, g x₀) ∈ t ×ˢ u := by simp [hx₀, hu hx₀] have h4f : ContinuousWithinAt (fun x => f x (g x)) t x₀ := by change ContinuousWithinAt ((Function.uncurry f) ∘ (fun x ↩ (x, g x))) t x₀ refine ContinuousWithinAt.comp hf.continuousWithinAt ?_ (fun y hy ↩ by simp [hy, hu hy]) exact (continuousWithinAt_id.prodMk hg.continuousWithinAt) have h4f := h4f.preimage_mem_nhdsWithin (extChartAt_source_mem_nhds (I := I') (f x₀ (g x₀))) have h3f := (contMDiffWithinAt_iff_contMDiffWithinAt_nhdsWithin (by simp)).mp (hf.of_le <| (self_le_add_left 1 m).trans hmn) simp only [Nat.cast_one, hx₀gx₀, insert_eq_of_mem] at h3f have h2f : ∀ᶠ x₂ in 𝓝[t] x₀, ContMDiffWithinAt I I' 1 (f x₂) u (g x₂) := by have : MapsTo (fun x ↩ (x, g x)) t (t ×ˢ u) := fun y hy ↩ by simp [hy, hu hy] filter_upwards [((continuousWithinAt_id.prodMk hg.continuousWithinAt) |>.tendsto_nhdsWithin this).eventually h3f, self_mem_nhdsWithin] with x hx h'x apply hx.comp (g x) (contMDiffWithinAt_const.prodMk contMDiffWithinAt_id) exact fun y hy ↩ by simp [h'x, hy] have h2g : g ⁻¹' (extChartAt I (g x₀)).source ∈ 𝓝[t] x₀ := hg.continuousWithinAt.preimage_mem_nhdsWithin (extChartAt_source_mem_nhds (g x₀)) -- key point: the derivative of `f` composed with extended charts, at the point `g x` read in the -- chart, is `C^n` in the vector space sense. This follows from `ContDiffWithinAt.fderivWithin`, -- which is the vector space analogue of the result we are proving. have : ContDiffWithinAt 𝕜 m (fun x ↩ fderivWithin 𝕜 (extChartAt I' (f x₀ (g x₀)) ∘ f ((extChartAt J x₀).symm x) ∘ (extChartAt I (g x₀)).symm) ((extChartAt I (g x₀)).target ∩ (extChartAt I (g x₀)).symm ⁻¹' u) (extChartAt I (g x₀) (g ((extChartAt J x₀).symm x)))) ((extChartAt J x₀).symm ⁻¹' t' ∩ range J) (extChartAt J x₀ x₀) := by have hf' := hf.mono (prod_mono_left ht't) have hg' := hg.mono (show t' ⊆ t from inter_subset_left) rw [contMDiffWithinAt_iff] at hf' hg' simp_rw [Function.comp_def, uncurry, extChartAt_prod, PartialEquiv.prod_coe_symm, ModelWithCorners.range_prod] at hf' ⊢ apply ContDiffWithinAt.fderivWithin _ _ _ (show (m : WithTop ℕ∞) + 1 ≀ n from mod_cast hmn ) · simp [hx₀, t'] · apply inter_subset_left.trans rw [preimage_subset_iff] intro a ha refine ⟹PartialEquiv.map_source _ (inter_subset_right ha :), ?_⟩ rw [mem_preimage, PartialEquiv.left_inv (extChartAt I (g x₀))] · exact hu (inter_subset_left ha) · exact (inter_subset_right ha :) · have : ((fun p ↩ ((extChartAt J x₀).symm p.1, (extChartAt I (g x₀)).symm p.2)) ⁻¹' t' ×ˢ u ∩ range J ×ˢ (extChartAt I (g x₀)).target) ⊆ ((fun p ↩ ((extChartAt J x₀).symm p.1, (extChartAt I (g x₀)).symm p.2)) ⁻¹' t' ×ˢ u ∩ range J ×ˢ range I) := by apply inter_subset_inter_right exact Set.prod_mono_right (extChartAt_target_subset_range (g x₀)) convert hf'.2.mono this · ext y; simp; tauto · simp · exact hg'.2 · exact UniqueMDiffOn.uniqueDiffOn_target_inter h'u (g x₀) -- reformulate the previous point as `C^n` in the manifold sense (but still for a map between -- vector spaces) have : ContMDiffWithinAt J 𝓘(𝕜, E →L[𝕜] E') m (fun x => fderivWithin 𝕜 (extChartAt I' (f x₀ (g x₀)) ∘ f x ∘ (extChartAt I (g x₀)).symm) ((extChartAt I (g x₀)).target ∩ (extChartAt I (g x₀)).symm ⁻¹' u) (extChartAt I (g x₀) (g x))) t' x₀ := by simp_rw [contMDiffWithinAt_iff_source (x := x₀), contMDiffWithinAt_iff_contDiffWithinAt, Function.comp_def] exact this -- finally, argue that the map we control in the previous point coincides locally with the map we -- want to prove the regularity of, so regularity of the latter follows from regularity of the -- former. apply this.congr_of_eventuallyEq_of_mem _ (by simp [t', hx₀]) apply nhdsWithin_mono _ ht't filter_upwards [h2f, h4f, h2g, self_mem_nhdsWithin] with x hx h'x h2 hxt have h1 : g x ∈ u := hu hxt have h3 : UniqueMDiffWithinAt 𝓘(𝕜, E) ((extChartAt I (g x₀)).target ∩ (extChartAt I (g x₀)).symm ⁻¹' u) ((extChartAt I (g x₀)) (g x)) := by apply UniqueDiffWithinAt.uniqueMDiffWithinAt apply UniqueMDiffOn.uniqueDiffOn_target_inter h'u refine ⟹PartialEquiv.map_source _ h2, ?_⟩ rwa [mem_preimage, PartialEquiv.left_inv _ h2] have A : mfderivWithin 𝓘(𝕜, E) I ((extChartAt I (g x₀)).symm) (range I) ((extChartAt I (g x₀)) (g x)) = mfderivWithin 𝓘(𝕜, E) I ((extChartAt I (g x₀)).symm) ((extChartAt I (g x₀)).target ∩ (extChartAt I (g x₀)).symm ⁻¹' u) ((extChartAt I (g x₀)) (g x)) := by apply (MDifferentiableWithinAt.mfderivWithin_mono _ h3 _).symm · apply mdifferentiableWithinAt_extChartAt_symm exact PartialEquiv.map_source (extChartAt I (g x₀)) h2 · exact inter_subset_left.trans (extChartAt_target_subset_range (g x₀)) rw [inTangentCoordinates_eq_mfderiv_comp, A, ← mfderivWithin_comp_of_eq, ← mfderiv_comp_mfderivWithin_of_eq] · exact mfderivWithin_eq_fderivWithin · exact mdifferentiableAt_extChartAt (by simpa using h'x) · apply MDifferentiableWithinAt.comp (I' := I) (u := u) _ _ _ inter_subset_right · convert hx.mdifferentiableWithinAt le_rfl exact PartialEquiv.left_inv (extChartAt I (g x₀)) h2 · apply (mdifferentiableWithinAt_extChartAt_symm _).mono · exact inter_subset_left.trans (extChartAt_target_subset_range (g x₀)) · exact PartialEquiv.map_source (extChartAt I (g x₀)) h2 · exact h3 · simp only [Function.comp_def, PartialEquiv.left_inv (extChartAt I (g x₀)) h2] · exact hx.mdifferentiableWithinAt le_rfl · apply (mdifferentiableWithinAt_extChartAt_symm _).mono · exact inter_subset_left.trans (extChartAt_target_subset_range (g x₀)) · exact PartialEquiv.map_source (extChartAt I (g x₀)) h2 · exact inter_subset_right · exact h3 · exact PartialEquiv.left_inv (extChartAt I (g x₀)) h2 · simpa using h2 · simpa using h'x /-- The derivative `D_yf(y)` is `C^m` at `x₀`, where the derivative is taken as a continuous linear map. We have to assume that `f` is `C^n` at `x₀` for some `n ≥ m + 1`. We have to insert a coordinate change from `x₀` to `x` to make the derivative sensible. This is a special case of `ContMDiffWithinAt.mfderivWithin` where `f` does not contain any parameters and `g = id`. -/ theorem ContMDiffWithinAt.mfderivWithin_const {x₀ : M} {f : M → M'} (hf : ContMDiffWithinAt I I' n f s x₀) (hmn : m + 1 ≀ n) (hx : x₀ ∈ s) (hs : UniqueMDiffOn I s) : ContMDiffWithinAt I 𝓘(𝕜, E →L[𝕜] E') m (inTangentCoordinates I I' id f (mfderivWithin I I' f s) x₀) s x₀ := by have : ContMDiffWithinAt (I.prod I) I' n (fun x : M × M => f x.2) (s ×ˢ s) (x₀, x₀) := ContMDiffWithinAt.comp (x₀, x₀) hf contMDiffWithinAt_snd mapsTo_snd_prod exact this.mfderivWithin contMDiffWithinAt_id hx (mapsTo_id _) hmn hs /-- The function that sends `x` to the `y`-derivative of `f(x,y)` at `g(x)` applied to `g₂(x)` is `C^n` at `x₀`, where the derivative is taken as a continuous linear map. We have to assume that `f` is `C^(n+1)` at `(x₀, g(x₀))` and `g` is `C^n` at `x₀`. We have to insert a coordinate change from `x₀` to `g₁(x)` to make the derivative sensible. This is similar to `ContMDiffWithinAt.mfderivWithin`, but where the continuous linear map is applied to a (variable) vector. -/ theorem ContMDiffWithinAt.mfderivWithin_apply {x₀ : N'} {f : N → M → M'} {g : N → M} {g₁ : N' → N} {g₂ : N' → E} {t : Set N} {u : Set M} {v : Set N'} (hf : ContMDiffWithinAt (J.prod I) I' n (Function.uncurry f) (t ×ˢ u) (g₁ x₀, g (g₁ x₀))) (hg : ContMDiffWithinAt J I m g t (g₁ x₀)) (hg₁ : ContMDiffWithinAt J' J m g₁ v x₀) (hg₂ : ContMDiffWithinAt J' 𝓘(𝕜, E) m g₂ v x₀) (hmn : m + 1 ≀ n) (h'g₁ : MapsTo g₁ v t) (hg₁x₀ : g₁ x₀ ∈ t) (h'g : MapsTo g t u) (hu : UniqueMDiffOn I u) : ContMDiffWithinAt J' 𝓘(𝕜, E') m (fun x => (inTangentCoordinates I I' g (fun x => f x (g x)) (fun x => mfderivWithin I I' (f x) u (g x)) (g₁ x₀) (g₁ x)) (g₂ x)) v x₀ := ((hf.mfderivWithin hg hg₁x₀ h'g hmn hu).comp_of_eq hg₁ h'g₁ rfl).clm_apply hg₂ /-- The function that sends `x` to the `y`-derivative of `f (x, y)` at `g (x)` is `C^m` at `x₀`, where the derivative is taken as a continuous linear map. We have to assume that `f` is `C^n` at `(x₀, g(x₀))` for `n ≥ m + 1` and `g` is `C^m` at `x₀`. We have to insert a coordinate change from `x₀` to `x` to make the derivative sensible. This result is used to show that maps into the 1-jet bundle and cotangent bundle are `C^n`. `ContMDiffAt.mfderiv_const` is a special case of this. -/ protected theorem ContMDiffAt.mfderiv {x₀ : N} (f : N → M → M') (g : N → M) (hf : ContMDiffAt (J.prod I) I' n (Function.uncurry f) (x₀, g x₀)) (hg : ContMDiffAt J I m g x₀) (hmn : m + 1 ≀ n) : ContMDiffAt J 𝓘(𝕜, E →L[𝕜] E') m (inTangentCoordinates I I' g (fun x ↩ f x (g x)) (fun x ↩ mfderiv I I' (f x) (g x)) x₀) x₀ := by rw [← contMDiffWithinAt_univ] at hf hg ⊢ rw [← univ_prod_univ] at hf simp_rw [← mfderivWithin_univ] exact ContMDiffWithinAt.mfderivWithin hf hg (mem_univ _) (mapsTo_univ _ _) hmn uniqueMDiffOn_univ /-- The derivative `D_yf(y)` is `C^m` at `x₀`, where the derivative is taken as a continuous linear map. We have to assume that `f` is `C^n` at `x₀` for some `n ≥ m + 1`. We have to insert a coordinate change from `x₀` to `x` to make the derivative sensible. This is a special case of `ContMDiffAt.mfderiv` where `f` does not contain any parameters and `g = id`. -/ theorem ContMDiffAt.mfderiv_const {x₀ : M} {f : M → M'} (hf : ContMDiffAt I I' n f x₀) (hmn : m + 1 ≀ n) : ContMDiffAt I 𝓘(𝕜, E →L[𝕜] E') m (inTangentCoordinates I I' id f (mfderiv I I' f) x₀) x₀ := haveI : ContMDiffAt (I.prod I) I' n (fun x : M × M => f x.2) (x₀, x₀) := ContMDiffAt.comp (x₀, x₀) hf contMDiffAt_snd this.mfderiv (fun _ => f) id contMDiffAt_id hmn /-- The function that sends `x` to the `y`-derivative of `f(x,y)` at `g(x)` applied to `g₂(x)` is `C^n` at `x₀`, where the derivative is taken as a continuous linear map. We have to assume that `f` is `C^(n+1)` at `(x₀, g(x₀))` and `g` is `C^n` at `x₀`. We have to insert a coordinate change from `x₀` to `g₁(x)` to make the derivative sensible. This is similar to `ContMDiffAt.mfderiv`, but where the continuous linear map is applied to a (variable) vector. -/ theorem ContMDiffAt.mfderiv_apply {x₀ : N'} (f : N → M → M') (g : N → M) (g₁ : N' → N) (g₂ : N' → E) (hf : ContMDiffAt (J.prod I) I' n (Function.uncurry f) (g₁ x₀, g (g₁ x₀))) (hg : ContMDiffAt J I m g (g₁ x₀)) (hg₁ : ContMDiffAt J' J m g₁ x₀) (hg₂ : ContMDiffAt J' 𝓘(𝕜, E) m g₂ x₀) (hmn : m + 1 ≀ n) : ContMDiffAt J' 𝓘(𝕜, E') m (fun x => inTangentCoordinates I I' g (fun x => f x (g x)) (fun x => mfderiv I I' (f x) (g x)) (g₁ x₀) (g₁ x) (g₂ x)) x₀ := ((hf.mfderiv f g hg hmn).comp_of_eq hg₁ rfl).clm_apply hg₂ end mfderiv /-! ### The tangent map of a `C^(n+1)` function is `C^n` -/ section tangentMap variable [Is : IsManifold I 1 M] [I's : IsManifold I' 1 M'] /-- If a function is `C^n` on a domain with unique derivatives, then its bundled derivative is `C^m` when `m+1 ≀ n`. -/ theorem ContMDiffOn.contMDiffOn_tangentMapWithin (hf : ContMDiffOn I I' n f s) (hmn : m + 1 ≀ n) (hs : UniqueMDiffOn I s) : ContMDiffOn I.tangent I'.tangent m (tangentMapWithin I I' f s) (π E (TangentSpace I) ⁻¹' s) := by intro x₀ hx₀ let s' : Set (TangentBundle I M) := (π E (TangentSpace I) ⁻¹' s) let b₁ : TangentBundle I M → M := fun p ↩ p.1 let v : Π (y : TangentBundle I M), TangentSpace I (b₁ y) := fun y ↩ y.2 have hv : ContMDiffWithinAt I.tangent I.tangent m (fun y ↩ (v y : TangentBundle I M)) s' x₀ := contMDiffWithinAt_id let b₂ : TangentBundle I M → M' := f ∘ b₁ have hb₂ : ContMDiffWithinAt I.tangent I' m b₂ s' x₀ := ((hf (b₁ x₀) hx₀).of_le (le_self_add.trans hmn)).comp _ (contMDiffWithinAt_proj (TangentSpace I)) (fun x h ↩ h) let ϕ : Π (y : TangentBundle I M), TangentSpace I (b₁ y) →L[𝕜] TangentSpace I' (b₂ y) := fun y ↩ mfderivWithin I I' f s (b₁ y) have hϕ : ContMDiffWithinAt I.tangent 𝓘(𝕜, E →L[𝕜] E') m (fun y ↩ ContinuousLinearMap.inCoordinates E (TangentSpace I (M := M)) E' (TangentSpace I' (M := M')) (b₁ x₀) (b₁ y) (b₂ x₀) (b₂ y) (ϕ y)) s' x₀ := by have A : ContMDiffWithinAt I 𝓘(𝕜, E →L[𝕜] E') m (fun y ↩ ContinuousLinearMap.inCoordinates E (TangentSpace I (M := M)) E' (TangentSpace I' (M := M')) (b₁ x₀) y (b₂ x₀) (f y) (mfderivWithin I I' f s y)) s (b₁ x₀) := ContMDiffWithinAt.mfderivWithin_const (hf _ hx₀) hmn hx₀ hs exact A.comp _ (contMDiffWithinAt_proj (TangentSpace I)) (fun x h ↩ h) exact ContMDiffWithinAt.clm_apply_of_inCoordinates hϕ hv hb₂ /-- If a function is `C^n` on a domain with unique derivatives, with `1 ≀ n`, then its bundled derivative is continuous there. -/ theorem ContMDiffOn.continuousOn_tangentMapWithin (hf : ContMDiffOn I I' n f s) (hmn : 1 ≀ n) (hs : UniqueMDiffOn I s) : ContinuousOn (tangentMapWithin I I' f s) (π E (TangentSpace I) ⁻¹' s) := by have : ContMDiffOn I.tangent I'.tangent 0 (tangentMapWithin I I' f s) (π E (TangentSpace I) ⁻¹' s) := hf.contMDiffOn_tangentMapWithin hmn hs exact this.continuousOn /-- If a function is `C^n`, then its bundled derivative is `C^m` when `m+1 ≀ n`. -/ theorem ContMDiff.contMDiff_tangentMap (hf : ContMDiff I I' n f) (hmn : m + 1 ≀ n) : ContMDiff I.tangent I'.tangent m (tangentMap I I' f) := by rw [← contMDiffOn_univ] at hf ⊢ convert hf.contMDiffOn_tangentMapWithin hmn uniqueMDiffOn_univ rw [tangentMapWithin_univ] /-- If a function is `C^n`, with `1 ≀ n`, then its bundled derivative is continuous. -/ theorem ContMDiff.continuous_tangentMap (hf : ContMDiff I I' n f) (hmn : 1 ≀ n) : Continuous (tangentMap I I' f) := by rw [← contMDiffOn_univ] at hf rw [continuous_iff_continuousOn_univ] convert hf.continuousOn_tangentMapWithin hmn uniqueMDiffOn_univ rw [tangentMapWithin_univ] @[deprecated (since := "2024-11-21")] alias Smooth.tangentMap := ContMDiff.contMDiff_tangentMap end tangentMap namespace TangentBundle
open Bundle /-- The derivative of the zero section of the tangent bundle maps `⟹x, v⟩` to `⟹⟹x, 0⟩, ⟹v, 0⟩⟩`. Note that, as currently framed, this is a statement in coordinates, thus reliant on the choice of the coordinate system we use on the tangent bundle. However, the result itself is coordinate-dependent only to the extent that the coordinates determine a splitting of the tangent bundle. Moreover, there is a canonical splitting at each point of the zero section (since there is a canonical horizontal space there, the tangent space to the zero section, in addition to the canonical vertical space which is the kernel of the derivative of the projection), and this canonical splitting is also the one that comes from the coordinates on the tangent bundle in our definitions. So this statement is not as crazy as it may seem. TODO define splittings of vector bundles; state this result invariantly. -/ theorem tangentMap_tangentBundle_pure [Is : IsManifold I 1 M] (p : TangentBundle I M) : tangentMap I I.tangent (zeroSection E (TangentSpace I)) p = ⟹⟹p.proj, 0⟩, ⟹p.2, 0⟩⟩ := by rcases p with ⟹x, v⟩ have N : I.symm ⁻¹' (chartAt H x).target ∈ 𝓝 (I ((chartAt H x) x)) := by apply IsOpen.mem_nhds · apply (PartialHomeomorph.open_target _).preimage I.continuous_invFun · simp only [mfld_simps] have A : MDifferentiableAt I I.tangent (fun x => @TotalSpace.mk M E (TangentSpace I) x 0) x := haveI : ContMDiff I (I.prod 𝓘(𝕜, E)) ⊀ (zeroSection E (TangentSpace I : M → Type _)) := Bundle.contMDiff_zeroSection 𝕜 (TangentSpace I : M → Type _) this.mdifferentiableAt le_top have B : fderivWithin 𝕜 (fun x' : E ↩ (x', (0 : E))) (Set.range I) (I ((chartAt H x) x)) v = (v, 0) := by rw [fderivWithin_eq_fderiv, DifferentiableAt.fderiv_prodMk] · simp · exact differentiableAt_id' · exact differentiableAt_const _ · exact ModelWithCorners.uniqueDiffWithinAt_image I · exact differentiableAt_id'.prodMk (differentiableAt_const _) simp +unfoldPartialApp only [Bundle.zeroSection, tangentMap, mfderiv, A, if_pos, chartAt, FiberBundle.chartedSpace_chartAt, TangentBundle.trivializationAt_apply, tangentBundleCore, Function.comp_def, ContinuousLinearMap.map_zero, mfld_simps] rw [← fderivWithin_inter N] at B rw [← fderivWithin_inter N, ← B] congr 1 refine fderivWithin_congr (fun y hy => ?_) ?_ · simp only [mfld_simps] at hy simp only [hy, Prod.mk_inj, mfld_simps] · simp only [Prod.mk_inj, mfld_simps] end TangentBundle namespace ContMDiffMap -- These helpers for dot notation have been moved here from -- `Mathlib/Geometry/Manifold/ContMDiffMap.lean` to avoid needing to import this file there. -- (However as a consequence we import `Mathlib/Geometry/Manifold/ContMDiffMap.lean` here now.) -- They could be moved to another file (perhaps a new file) if desired. open scoped Manifold ContDiff protected theorem mdifferentiable' (f : C^n⟮I, M; I', M'⟯) (hn : 1 ≀ n) : MDifferentiable I I' f := f.contMDiff.mdifferentiable hn protected theorem mdifferentiable (f : C^∞⟮I, M; I', M'⟯) : MDifferentiable I I' f := f.contMDiff.mdifferentiable (mod_cast le_top) protected theorem mdifferentiableAt (f : C^∞⟮I, M; I', M'⟯) {x} : MDifferentiableAt I I' f x := f.mdifferentiable x end ContMDiffMap section EquivTangentBundleProd variable (I I' M M') in /-- The tangent bundle of a product is canonically isomorphic to the product of the tangent bundles. -/ @[simps] def equivTangentBundleProd : TangentBundle (I.prod I') (M × M') ≃ (TangentBundle I M) × (TangentBundle I' M') where toFun p := (⟹p.1.1, p.2.1⟩, ⟹p.1.2, p.2.2⟩) invFun p := ⟹(p.1.1, p.2.1), (p.1.2, p.2.2)⟩ left_inv _ := rfl right_inv _ := rfl lemma equivTangentBundleProd_eq_tangentMap_prod_tangentMap : equivTangentBundleProd I M I' M' = fun (p : TangentBundle (I.prod I') (M × M')) ↩ (tangentMap (I.prod I') I Prod.fst p, tangentMap (I.prod I') I' Prod.snd p) := by simp only [tangentMap_prodFst, tangentMap_prodSnd]; rfl variable [IsManifold I 1 M] [IsManifold I' 1 M'] /-- The canonical equivalence between the tangent bundle of a product and the product of tangent bundles is smooth. -/ lemma contMDiff_equivTangentBundleProd : ContMDiff (I.prod I').tangent (I.tangent.prod I'.tangent) n (equivTangentBundleProd I M I' M') := by rw [equivTangentBundleProd_eq_tangentMap_prod_tangentMap] exact (contMDiff_fst.contMDiff_tangentMap le_rfl).prodMk (contMDiff_snd.contMDiff_tangentMap le_rfl) /-- The canonical equivalence between the product of tangent bundles and the tangent bundle of a product is smooth. -/ lemma contMDiff_equivTangentBundleProd_symm : ContMDiff (I.tangent.prod I'.tangent) (I.prod I').tangent n (equivTangentBundleProd I M I' M').symm := by /- Contrary to what one might expect, this proof is nontrivial. It is not a formalization issue: even on paper, I don't have a simple proof of the statement. The reason is that there is no nice functorial expression for the map from `TM × T'M` to `T (M × M')`, so I need to come back to the definition and break things into pieces. The argument goes as follows. Since we're looking at a map into a vector bundle whose basis map is smooth, it suffices to check the smoothness of the second component, in a chart. It lands in a product vector space `E × E'`, so it suffices to check that the composition with each projection to `E` and `E'` is smooth. We notice that the composition of this map with the first projection coincides with the projection `TM × TM' → TM` read in the target chart, which is smooth, so we're done. The issue is with checking differentiability everywhere (to justify that the derivative of a product is the product of the derivatives), and writing down things. -/ rintro ⟹a, b⟩ have U w w' : UniqueDiffWithinAt 𝕜 (Set.range (Prod.map I I')) (I w, I' w') := by simp only [range_prodMap] apply UniqueDiffWithinAt.prod · exact ModelWithCorners.uniqueDiffWithinAt_image I · exact ModelWithCorners.uniqueDiffWithinAt_image I' rw [contMDiffAt_totalSpace] simp only [equivTangentBundleProd, TangentBundle.trivializationAt_apply, mfld_simps, Equiv.coe_fn_symm_mk] refine ⟹?_, (contMDiffAt_prod_module_iff _).2 ⟹?_, ?_⟩⟩ · exact ContMDiffAt.prodMap (contMDiffAt_proj (TangentSpace I)) (contMDiffAt_proj (TangentSpace I')) · /- check that the composition with the first projection in the target chart is smooth. For this, we check that it coincides locally with the projection `pM : TM × TM' → TM` read in the target chart, which is obviously smooth. -/ have smooth_pM : ContMDiffAt (I.tangent.prod I'.tangent) I.tangent n Prod.fst (a, b) := contMDiffAt_fst apply ((contMDiffAt_totalSpace _ _).1 smooth_pM).2.congr_of_eventuallyEq filter_upwards [chart_source_mem_nhds (ModelProd (ModelProd H E) (ModelProd H' E')) (a, b)] with p hp -- now we have to check that the original map coincides locally with `pM` read in target chart. simp only [prodChartedSpace_chartAt, PartialHomeomorph.prod_toPartialEquiv, PartialEquiv.prod_source, Set.mem_prod, TangentBundle.mem_chart_source_iff] at hp let φ (x : E) := I ((chartAt H a.proj) ((chartAt H p.1.proj).symm (I.symm x))) have D0 : DifferentiableWithinAt 𝕜 φ (Set.range I) (I ((chartAt H p.1.proj) p.1.proj)) := by apply ContDiffWithinAt.differentiableWithinAt (n := 1) _ le_rfl apply contDiffWithinAt_ext_coord_change simp [hp.1] have D (w : TangentBundle I' M') : DifferentiableWithinAt 𝕜 (φ ∘ (Prod.fst : E × E' → E)) (Set.range (Prod.map ↑I ↑I')) (I ((chartAt H p.1.proj) p.1.proj), I' ((chartAt H' w.proj) w.proj)) := DifferentiableWithinAt.comp (t := Set.range I) _ (by exact D0) differentiableWithinAt_fst (by simp [mapsTo_fst_prod]) simp only [range_prodMap, ContinuousLinearMap.prod_apply, comp_def, comp_apply] rw [DifferentiableWithinAt.fderivWithin_prodMk (by exact D _) ?_ (U _ _)]; swap · let φ' (x : E') := I' ((chartAt H' b.proj) ((chartAt H' p.2.proj).symm (I'.symm x))) have D0' : DifferentiableWithinAt 𝕜 φ' (Set.range I') (I' ((chartAt H' p.2.proj) p.2.proj)) := by apply ContDiffWithinAt.differentiableWithinAt (n := 1) _ le_rfl apply contDiffWithinAt_ext_coord_change simp [hp.2] have D' : DifferentiableWithinAt 𝕜 (φ' ∘ Prod.snd) (Set.range (Prod.map I I')) (I ((chartAt H p.1.proj) p.1.proj), I' ((chartAt H' p.2.proj) p.2.proj)) := DifferentiableWithinAt.comp (t := Set.range I') _ (by exact D0') differentiableWithinAt_snd (by simp [mapsTo_snd_prod]) exact D' simp only [TangentBundle.trivializationAt_apply, mfld_simps] change fderivWithin 𝕜 (φ ∘ Prod.fst) _ _ _ = fderivWithin 𝕜 φ _ _ _ rw [range_prodMap] at U rw [fderivWithin_comp _ (by exact D0) differentiableWithinAt_fst mapsTo_fst_prod (U _ _)] simp [fderivWithin_fst, U] · /- check that the composition with the second projection in the target chart is smooth. For this, we check that it coincides locally with the projection `pM' : TM × TM' → TM'` read in the target chart, which is obviously smooth. -/ have smooth_pM' : ContMDiffAt (I.tangent.prod I'.tangent) I'.tangent n Prod.snd (a, b) := contMDiffAt_snd apply ((contMDiffAt_totalSpace _ _).1 smooth_pM').2.congr_of_eventuallyEq filter_upwards [chart_source_mem_nhds (ModelProd (ModelProd H E) (ModelProd H' E')) (a, b)] with p hp -- now we have to check that the original map coincides locally with `pM'` read in target chart. simp only [prodChartedSpace_chartAt, PartialHomeomorph.prod_toPartialEquiv,
Mathlib/Geometry/Manifold/ContMDiffMFDeriv.lean
344
518
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Yury Kudryashov -/ import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.Order.Sub.WithTop import Mathlib.Data.NNReal.Defs import Mathlib.Order.Interval.Set.WithBotTop /-! # Extended non-negative reals We define `ENNReal = ℝ≥0∞ := WithTop ℝ≥0` to be the type of extended nonnegative real numbers, i.e., the interval `[0, +∞]`. This type is used as the codomain of a `MeasureTheory.Measure`, and of the extended distance `edist` in an `EMetricSpace`. In this file we set up many of the instances on `ℝ≥0∞`, and provide relationships between `ℝ≥0∞` and `ℝ≥0`, and between `ℝ≥0∞` and `ℝ`. In particular, we provide a coercion from `ℝ≥0` to `ℝ≥0∞` as well as functions `ENNReal.toNNReal`, `ENNReal.ofReal` and `ENNReal.toReal`, all of which take the value zero wherever they cannot be the identity. Also included is the relationship between `ℝ≥0∞` and `ℕ`. The interaction of these functions, especially `ENNReal.ofReal` and `ENNReal.toReal`, with the algebraic and lattice structure can be found in `Data.ENNReal.Real`. This file proves many of the order properties of `ℝ≥0∞`, with the exception of the ways those relate to the algebraic structure, which are included in `Data.ENNReal.Operations`. This file also defines inversion and division: this includes `Inv` and `Div` instances on `ℝ≥0∞` making it into a `DivInvOneMonoid`. As a consequence of being a `DivInvOneMonoid`, `ℝ≥0∞` inherits a power operation with integer exponent: this and other properties is shown in `Data.ENNReal.Inv`. ## Main definitions * `ℝ≥0∞`: the extended nonnegative real numbers `[0, ∞]`; defined as `WithTop ℝ≥0`; it is equipped with the following structures: - coercion from `ℝ≥0` defined in the natural way; - the natural structure of a complete dense linear order: `↑p ≀ ↑q ↔ p ≀ q` and `∀ a, a ≀ ∞`; - `a + b` is defined so that `↑p + ↑q = ↑(p + q)` for `(p q : ℝ≥0)` and `a + ∞ = ∞ + a = ∞`; - `a * b` is defined so that `↑p * ↑q = ↑(p * q)` for `(p q : ℝ≥0)`, `0 * ∞ = ∞ * 0 = 0`, and `a * ∞ = ∞ * a = ∞` for `a ≠ 0`; - `a - b` is defined as the minimal `d` such that `a ≀ d + b`; this way we have `↑p - ↑q = ↑(p - q)`, `∞ - ↑p = ∞`, `↑p - ∞ = ∞ - ∞ = 0`; note that there is no negation, only subtraction; The addition and multiplication defined this way together with `0 = ↑0` and `1 = ↑1` turn `ℝ≥0∞` into a canonically ordered commutative semiring of characteristic zero. - `a⁻¹` is defined as `Inf {b | 1 ≀ a * b}`. This way we have `(↑p)⁻¹ = ↑(p⁻¹)` for `p : ℝ≥0`, `p ≠ 0`, `0⁻¹ = ∞`, and `∞⁻¹ = 0`. - `a / b` is defined as `a * b⁻¹`. This inversion and division include `Inv` and `Div` instances on `ℝ≥0∞`, making it into a `DivInvOneMonoid`. Further properties of these are shown in `Data.ENNReal.Inv`. * Coercions to/from other types: - coercion `ℝ≥0 → ℝ≥0∞` is defined as `Coe`, so one can use `(p : ℝ≥0)` in a context that expects `a : ℝ≥0∞`, and Lean will apply `coe` automatically; - `ENNReal.toNNReal` sends `↑p` to `p` and `∞` to `0`; - `ENNReal.toReal := coe ∘ ENNReal.toNNReal` sends `↑p`, `p : ℝ≥0` to `(↑p : ℝ)` and `∞` to `0`; - `ENNReal.ofReal := coe ∘ Real.toNNReal` sends `x : ℝ` to `↑⟹max x 0, _⟩` - `ENNReal.neTopEquivNNReal` is an equivalence between `{a : ℝ≥0∞ // a ≠ 0}` and `ℝ≥0`. ## Implementation notes We define a `CanLift ℝ≥0∞ ℝ≥0` instance, so one of the ways to prove theorems about an `ℝ≥0∞` number `a` is to consider the cases `a = ∞` and `a ≠ ∞`, and use the tactic `lift a to ℝ≥0 using ha` in the second case. This instance is even more useful if one already has `ha : a ≠ ∞` in the context, or if we have `(f : α → ℝ≥0∞) (hf : ∀ x, f x ≠ ∞)`. ## Notations * `ℝ≥0∞`: the type of the extended nonnegative real numbers; * `ℝ≥0`: the type of nonnegative real numbers `[0, ∞)`; defined in `Data.Real.NNReal`; * `∞`: a localized notation in `ENNReal` for `⊀ : ℝ≥0∞`. -/ assert_not_exists Finset open Function Set NNReal variable {α : Type*} /-- The extended nonnegative real numbers. This is usually denoted [0, ∞], and is relevant as the codomain of a measure. -/ def ENNReal := WithTop ℝ≥0 deriving Zero, Top, AddCommMonoidWithOne, SemilatticeSup, DistribLattice, Nontrivial @[inherit_doc] scoped[ENNReal] notation "ℝ≥0∞" => ENNReal /-- Notation for infinity as an `ENNReal` number. -/ scoped[ENNReal] notation "∞" => (⊀ : ENNReal) namespace ENNReal instance : OrderBot ℝ≥0∞ := inferInstanceAs (OrderBot (WithTop ℝ≥0)) instance : OrderTop ℝ≥0∞ := inferInstanceAs (OrderTop (WithTop ℝ≥0)) instance : BoundedOrder ℝ≥0∞ := inferInstanceAs (BoundedOrder (WithTop ℝ≥0)) instance : CharZero ℝ≥0∞ := inferInstanceAs (CharZero (WithTop ℝ≥0)) instance : Min ℝ≥0∞ := SemilatticeInf.toMin instance : Max ℝ≥0∞ := SemilatticeSup.toMax noncomputable instance : CommSemiring ℝ≥0∞ := inferInstanceAs (CommSemiring (WithTop ℝ≥0)) instance : PartialOrder ℝ≥0∞ := inferInstanceAs (PartialOrder (WithTop ℝ≥0)) instance : IsOrderedRing ℝ≥0∞ := inferInstanceAs (IsOrderedRing (WithTop ℝ≥0)) instance : CanonicallyOrderedAdd ℝ≥0∞ := inferInstanceAs (CanonicallyOrderedAdd (WithTop ℝ≥0)) instance : NoZeroDivisors ℝ≥0∞ := inferInstanceAs (NoZeroDivisors (WithTop ℝ≥0)) noncomputable instance : CompleteLinearOrder ℝ≥0∞ := inferInstanceAs (CompleteLinearOrder (WithTop ℝ≥0)) instance : DenselyOrdered ℝ≥0∞ := inferInstanceAs (DenselyOrdered (WithTop ℝ≥0)) instance : AddCommMonoid ℝ≥0∞ := inferInstanceAs (AddCommMonoid (WithTop ℝ≥0)) noncomputable instance : LinearOrder ℝ≥0∞ := inferInstanceAs (LinearOrder (WithTop ℝ≥0)) instance : IsOrderedAddMonoid ℝ≥0∞ := inferInstanceAs (IsOrderedAddMonoid (WithTop ℝ≥0)) instance instSub : Sub ℝ≥0∞ := inferInstanceAs (Sub (WithTop ℝ≥0)) instance : OrderedSub ℝ≥0∞ := inferInstanceAs (OrderedSub (WithTop ℝ≥0)) noncomputable instance : LinearOrderedAddCommMonoidWithTop ℝ≥0∞ := inferInstanceAs (LinearOrderedAddCommMonoidWithTop (WithTop ℝ≥0)) -- RFC: redefine using pattern matching? noncomputable instance : Inv ℝ≥0∞ := ⟹fun a => sInf { b | 1 ≀ a * b }⟩ noncomputable instance : DivInvMonoid ℝ≥0∞ where variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0} -- TODO: add a `WithTop` instance and use it here noncomputable instance : LinearOrderedCommMonoidWithZero ℝ≥0∞ := { inferInstanceAs (LinearOrderedAddCommMonoidWithTop ℝ≥0∞), inferInstanceAs (CommSemiring ℝ≥0∞) with bot_le _ := bot_le mul_le_mul_left := fun _ _ => mul_le_mul_left' zero_le_one := zero_le 1 } instance : Unique (AddUnits ℝ≥0∞) where default := 0 uniq a := AddUnits.ext <| le_zero_iff.1 <| by rw [← a.add_neg]; exact le_self_add instance : Inhabited ℝ≥0∞ := ⟹0⟩ /-- Coercion from `ℝ≥0` to `ℝ≥0∞`. -/ @[coe, match_pattern] def ofNNReal : ℝ≥0 → ℝ≥0∞ := WithTop.some instance : Coe ℝ≥0 ℝ≥0∞ := ⟹ofNNReal⟩ /-- A version of `WithTop.recTopCoe` that uses `ENNReal.ofNNReal`. -/ @[elab_as_elim, induction_eliminator, cases_eliminator] def recTopCoe {C : ℝ≥0∞ → Sort*} (top : C ∞) (coe : ∀ x : ℝ≥0, C x) (x : ℝ≥0∞) : C x := WithTop.recTopCoe top coe x instance canLift : CanLift ℝ≥0∞ ℝ≥0 ofNNReal (· ≠ ∞) := WithTop.canLift @[simp] theorem none_eq_top : (none : ℝ≥0∞) = ∞ := rfl @[simp] theorem some_eq_coe (a : ℝ≥0) : (Option.some a : ℝ≥0∞) = (↑a : ℝ≥0∞) := rfl @[simp] theorem some_eq_coe' (a : ℝ≥0) : (WithTop.some a : ℝ≥0∞) = (↑a : ℝ≥0∞) := rfl lemma coe_injective : Injective ((↑) : ℝ≥0 → ℝ≥0∞) := WithTop.coe_injective @[simp, norm_cast] lemma coe_inj : (p : ℝ≥0∞) = q ↔ p = q := coe_injective.eq_iff lemma coe_ne_coe : (p : ℝ≥0∞) ≠ q ↔ p ≠ q := coe_inj.not theorem range_coe' : range ofNNReal = Iio ∞ := WithTop.range_coe theorem range_coe : range ofNNReal = {∞}ᶜ := (isCompl_range_some_none ℝ≥0).symm.compl_eq.symm instance : NNRatCast ℝ≥0∞ where nnratCast r := ofNNReal r @[norm_cast] theorem coe_nnratCast (q : ℚ≥0) : ↑(q : ℝ≥0) = (q : ℝ≥0∞) := rfl /-- `toNNReal x` returns `x` if it is real, otherwise 0. -/ protected def toNNReal : ℝ≥0∞ → ℝ≥0 := WithTop.untopD 0 /-- `toReal x` returns `x` if it is real, `0` otherwise. -/ protected def toReal (a : ℝ≥0∞) : Real := a.toNNReal /-- `ofReal x` returns `x` if it is nonnegative, `0` otherwise. -/ protected def ofReal (r : Real) : ℝ≥0∞ := r.toNNReal @[simp, norm_cast] lemma toNNReal_coe (r : ℝ≥0) : (r : ℝ≥0∞).toNNReal = r := rfl @[simp] theorem coe_toNNReal : ∀ {a : ℝ≥0∞}, a ≠ ∞ → ↑a.toNNReal = a | ofNNReal _, _ => rfl | ⊀, h => (h rfl).elim @[simp] theorem coe_comp_toNNReal_comp {ι : Type*} {f : ι → ℝ≥0∞} (hf : ∀ x, f x ≠ ∞) : (fun (x : ℝ≥0) => (x : ℝ≥0∞)) ∘ ENNReal.toNNReal ∘ f = f := by ext x simp [coe_toNNReal (hf x)] @[simp] theorem ofReal_toReal {a : ℝ≥0∞} (h : a ≠ ∞) : ENNReal.ofReal a.toReal = a := by simp [ENNReal.toReal, ENNReal.ofReal, h] @[simp] theorem toReal_ofReal {r : ℝ} (h : 0 ≀ r) : (ENNReal.ofReal r).toReal = r := max_eq_left h theorem toReal_ofReal' {r : ℝ} : (ENNReal.ofReal r).toReal = max r 0 := rfl theorem coe_toNNReal_le_self : ∀ {a : ℝ≥0∞}, ↑a.toNNReal ≀ a | ofNNReal r => by rw [toNNReal_coe] | ⊀ => le_top theorem coe_nnreal_eq (r : ℝ≥0) : (r : ℝ≥0∞) = ENNReal.ofReal r := by rw [ENNReal.ofReal, Real.toNNReal_coe] theorem ofReal_eq_coe_nnreal {x : ℝ} (h : 0 ≀ x) : ENNReal.ofReal x = ofNNReal ⟹x, h⟩ := (coe_nnreal_eq ⟹x, h⟩).symm theorem ofNNReal_toNNReal (x : ℝ) : (Real.toNNReal x : ℝ≥0∞) = ENNReal.ofReal x := rfl @[simp] theorem ofReal_coe_nnreal : ENNReal.ofReal p = p := (coe_nnreal_eq p).symm @[simp, norm_cast] theorem coe_zero : ↑(0 : ℝ≥0) = (0 : ℝ≥0∞) := rfl @[simp, norm_cast] theorem coe_one : ↑(1 : ℝ≥0) = (1 : ℝ≥0∞) := rfl @[simp] theorem toReal_nonneg {a : ℝ≥0∞} : 0 ≀ a.toReal := a.toNNReal.2 @[norm_cast] theorem coe_toNNReal_eq_toReal (z : ℝ≥0∞) : (z.toNNReal : ℝ) = z.toReal := rfl @[simp] theorem toNNReal_toReal_eq (z : ℝ≥0∞) : z.toReal.toNNReal = z.toNNReal := by ext; simp [coe_toNNReal_eq_toReal] @[simp] theorem toNNReal_top : ∞.toNNReal = 0 := rfl @[deprecated (since := "2025-03-20")] alias top_toNNReal := toNNReal_top @[simp] theorem toReal_top : ∞.toReal = 0 := rfl @[deprecated (since := "2025-03-20")] alias top_toReal := toReal_top @[simp] theorem toReal_one : (1 : ℝ≥0∞).toReal = 1 := rfl @[deprecated (since := "2025-03-20")] alias one_toReal := toReal_one @[simp] theorem toNNReal_one : (1 : ℝ≥0∞).toNNReal = 1 := rfl @[deprecated (since := "2025-03-20")] alias one_toNNReal := toNNReal_one @[simp] theorem coe_toReal (r : ℝ≥0) : (r : ℝ≥0∞).toReal = r := rfl @[simp] theorem toNNReal_zero : (0 : ℝ≥0∞).toNNReal = 0 := rfl @[deprecated (since := "2025-03-20")] alias zero_toNNReal := toNNReal_zero @[simp] theorem toReal_zero : (0 : ℝ≥0∞).toReal = 0 := rfl @[deprecated (since := "2025-03-20")] alias zero_toReal := toReal_zero @[simp] theorem ofReal_zero : ENNReal.ofReal (0 : ℝ) = 0 := by simp [ENNReal.ofReal] @[simp] theorem ofReal_one : ENNReal.ofReal (1 : ℝ) = (1 : ℝ≥0∞) := by simp [ENNReal.ofReal] theorem ofReal_toReal_le {a : ℝ≥0∞} : ENNReal.ofReal a.toReal ≀ a := if ha : a = ∞ then ha.symm ▾ le_top else le_of_eq (ofReal_toReal ha) theorem forall_ennreal {p : ℝ≥0∞ → Prop} : (∀ a, p a) ↔ (∀ r : ℝ≥0, p r) ∧ p ∞ := Option.forall.trans and_comm theorem forall_ne_top {p : ℝ≥0∞ → Prop} : (∀ a, a ≠ ∞ → p a) ↔ ∀ r : ℝ≥0, p r := Option.forall_ne_none theorem exists_ne_top {p : ℝ≥0∞ → Prop} : (∃ a ≠ ∞, p a) ↔ ∃ r : ℝ≥0, p r := Option.exists_ne_none theorem toNNReal_eq_zero_iff (x : ℝ≥0∞) : x.toNNReal = 0 ↔ x = 0 √ x = ∞ := WithTop.untopD_eq_self_iff theorem toReal_eq_zero_iff (x : ℝ≥0∞) : x.toReal = 0 ↔ x = 0 √ x = ∞ := by simp [ENNReal.toReal, toNNReal_eq_zero_iff] theorem toNNReal_ne_zero : a.toNNReal ≠ 0 ↔ a ≠ 0 ∧ a ≠ ∞ := a.toNNReal_eq_zero_iff.not.trans not_or theorem toReal_ne_zero : a.toReal ≠ 0 ↔ a ≠ 0 ∧ a ≠ ∞ := a.toReal_eq_zero_iff.not.trans not_or theorem toNNReal_eq_one_iff (x : ℝ≥0∞) : x.toNNReal = 1 ↔ x = 1 := WithTop.untopD_eq_iff.trans <| by simp theorem toReal_eq_one_iff (x : ℝ≥0∞) : x.toReal = 1 ↔ x = 1 := by rw [ENNReal.toReal, NNReal.coe_eq_one, ENNReal.toNNReal_eq_one_iff] theorem toNNReal_ne_one : a.toNNReal ≠ 1 ↔ a ≠ 1 := a.toNNReal_eq_one_iff.not theorem toReal_ne_one : a.toReal ≠ 1 ↔ a ≠ 1 := a.toReal_eq_one_iff.not @[simp, aesop (rule_sets := [finiteness]) safe apply] theorem coe_ne_top : (r : ℝ≥0∞) ≠ ∞ := WithTop.coe_ne_top @[simp] theorem top_ne_coe : ∞ ≠ (r : ℝ≥0∞) := WithTop.top_ne_coe @[simp] theorem coe_lt_top : (r : ℝ≥0∞) < ∞ := WithTop.coe_lt_top r @[simp, aesop (rule_sets := [finiteness]) safe apply] theorem ofReal_ne_top {r : ℝ} : ENNReal.ofReal r ≠ ∞ := coe_ne_top @[simp] theorem ofReal_lt_top {r : ℝ} : ENNReal.ofReal r < ∞ := coe_lt_top @[simp] theorem top_ne_ofReal {r : ℝ} : ∞ ≠ ENNReal.ofReal r := top_ne_coe @[simp] theorem ofReal_toReal_eq_iff : ENNReal.ofReal a.toReal = a ↔ a ≠ ⊀ := ⟹fun h => by rw [← h] exact ofReal_ne_top, ofReal_toReal⟩ @[simp] theorem toReal_ofReal_eq_iff {a : ℝ} : (ENNReal.ofReal a).toReal = a ↔ 0 ≀ a := ⟹fun h => by rw [← h] exact toReal_nonneg, toReal_ofReal⟩ @[simp, aesop (rule_sets := [finiteness]) safe apply] theorem zero_ne_top : 0 ≠ ∞ := coe_ne_top @[simp] theorem top_ne_zero : ∞ ≠ 0 := top_ne_coe @[simp, aesop (rule_sets := [finiteness]) safe apply] theorem one_ne_top : 1 ≠ ∞ := coe_ne_top @[simp] theorem top_ne_one : ∞ ≠ 1 := top_ne_coe @[simp] theorem zero_lt_top : 0 < ∞ := coe_lt_top @[simp, norm_cast] theorem coe_le_coe : (↑r : ℝ≥0∞) ≀ ↑q ↔ r ≀ q := WithTop.coe_le_coe @[simp, norm_cast] theorem coe_lt_coe : (↑r : ℝ≥0∞) < ↑q ↔ r < q := WithTop.coe_lt_coe -- Needed until `@[gcongr]` accepts iff statements alias ⟹_, coe_le_coe_of_le⟩ := coe_le_coe attribute [gcongr] ENNReal.coe_le_coe_of_le -- Needed until `@[gcongr]` accepts iff statements alias ⟹_, coe_lt_coe_of_lt⟩ := coe_lt_coe attribute [gcongr] ENNReal.coe_lt_coe_of_lt theorem coe_mono : Monotone ofNNReal := fun _ _ => coe_le_coe.2 theorem coe_strictMono : StrictMono ofNNReal := fun _ _ => coe_lt_coe.2 @[simp, norm_cast] theorem coe_eq_zero : (↑r : ℝ≥0∞) = 0 ↔ r = 0 := coe_inj @[simp, norm_cast] theorem zero_eq_coe : 0 = (↑r : ℝ≥0∞) ↔ 0 = r := coe_inj @[simp, norm_cast] theorem coe_eq_one : (↑r : ℝ≥0∞) = 1 ↔ r = 1 := coe_inj @[simp, norm_cast] theorem one_eq_coe : 1 = (↑r : ℝ≥0∞) ↔ 1 = r := coe_inj @[simp, norm_cast] theorem coe_pos : 0 < (r : ℝ≥0∞) ↔ 0 < r := coe_lt_coe theorem coe_ne_zero : (r : ℝ≥0∞) ≠ 0 ↔ r ≠ 0 := coe_eq_zero.not lemma coe_ne_one : (r : ℝ≥0∞) ≠ 1 ↔ r ≠ 1 := coe_eq_one.not @[simp, norm_cast] lemma coe_add (x y : ℝ≥0) : (↑(x + y) : ℝ≥0∞) = x + y := rfl @[simp, norm_cast] lemma coe_mul (x y : ℝ≥0) : (↑(x * y) : ℝ≥0∞) = x * y := rfl @[norm_cast] lemma coe_nsmul (n : ℕ) (x : ℝ≥0) : (↑(n • x) : ℝ≥0∞) = n • x := rfl @[simp, norm_cast] lemma coe_pow (x : ℝ≥0) (n : ℕ) : (↑(x ^ n) : ℝ≥0∞) = x ^ n := rfl @[simp, norm_cast] theorem coe_ofNat (n : ℕ) [n.AtLeastTwo] : ((ofNat(n) : ℝ≥0) : ℝ≥0∞) = ofNat(n) := rfl -- TODO: add lemmas about `OfNat.ofNat` and `<`/`≀` theorem coe_two : ((2 : ℝ≥0) : ℝ≥0∞) = 2 := rfl theorem toNNReal_eq_toNNReal_iff (x y : ℝ≥0∞) : x.toNNReal = y.toNNReal ↔ x = y √ x = 0 ∧ y = ⊀ √ x = ⊀ ∧ y = 0 := WithTop.untopD_eq_untopD_iff theorem toReal_eq_toReal_iff (x y : ℝ≥0∞) : x.toReal = y.toReal ↔ x = y √ x = 0 ∧ y = ⊀ √ x = ⊀ ∧ y = 0 := by simp only [ENNReal.toReal, NNReal.coe_inj, toNNReal_eq_toNNReal_iff] theorem toNNReal_eq_toNNReal_iff' {x y : ℝ≥0∞} (hx : x ≠ ⊀) (hy : y ≠ ⊀) : x.toNNReal = y.toNNReal ↔ x = y := by simp only [ENNReal.toNNReal_eq_toNNReal_iff x y, hx, hy, and_false, false_and, or_false] theorem toReal_eq_toReal_iff' {x y : ℝ≥0∞} (hx : x ≠ ⊀) (hy : y ≠ ⊀) : x.toReal = y.toReal ↔ x = y := by simp only [ENNReal.toReal, NNReal.coe_inj, toNNReal_eq_toNNReal_iff' hx hy] theorem one_lt_two : (1 : ℝ≥0∞) < 2 := Nat.one_lt_ofNat /-- `(1 : ℝ≥0∞) ≀ 1`, recorded as a `Fact` for use with `Lp` spaces. -/ instance _root_.fact_one_le_one_ennreal : Fact ((1 : ℝ≥0∞) ≀ 1) := ⟹le_rfl⟩ /-- `(1 : ℝ≥0∞) ≀ 2`, recorded as a `Fact` for use with `Lp` spaces. -/ instance _root_.fact_one_le_two_ennreal : Fact ((1 : ℝ≥0∞) ≀ 2) := ⟹one_le_two⟩ /-- `(1 : ℝ≥0∞) ≀ ∞`, recorded as a `Fact` for use with `Lp` spaces. -/ instance _root_.fact_one_le_top_ennreal : Fact ((1 : ℝ≥0∞) ≀ ∞) := ⟹le_top⟩ /-- The set of numbers in `ℝ≥0∞` that are not equal to `∞` is equivalent to `ℝ≥0`. -/ def neTopEquivNNReal : { a | a ≠ ∞ } ≃ ℝ≥0 where toFun x := ENNReal.toNNReal x invFun x := ⟹x, coe_ne_top⟩ left_inv := fun x => Subtype.eq <| coe_toNNReal x.2 right_inv := toNNReal_coe theorem cinfi_ne_top [InfSet α] (f : ℝ≥0∞ → α) : ⹅ x : { x // x ≠ ∞ }, f x = ⹅ x : ℝ≥0, f x := Eq.symm <| neTopEquivNNReal.symm.surjective.iInf_congr _ fun _ => rfl theorem iInf_ne_top [CompleteLattice α] (f : ℝ≥0∞ → α) : ⹅ (x) (_ : x ≠ ∞), f x = ⹅ x : ℝ≥0, f x := by rw [iInf_subtype', cinfi_ne_top] theorem csupr_ne_top [SupSet α] (f : ℝ≥0∞ → α) : ⹆ x : { x // x ≠ ∞ }, f x = ⹆ x : ℝ≥0, f x := @cinfi_ne_top αᵒᵈ _ _ theorem iSup_ne_top [CompleteLattice α] (f : ℝ≥0∞ → α) : ⹆ (x) (_ : x ≠ ∞), f x = ⹆ x : ℝ≥0, f x := @iInf_ne_top αᵒᵈ _ _ theorem iInf_ennreal {α : Type*} [CompleteLattice α] {f : ℝ≥0∞ → α} : ⹅ n, f n = (⹅ n : ℝ≥0, f n) ⊓ f ∞ := (iInf_option f).trans (inf_comm _ _) theorem iSup_ennreal {α : Type*} [CompleteLattice α] {f : ℝ≥0∞ → α} : ⹆ n, f n = (⹆ n : ℝ≥0, f n) ⊔ f ∞ := @iInf_ennreal αᵒᵈ _ _ /-- Coercion `ℝ≥0 → ℝ≥0∞` as a `RingHom`. -/ def ofNNRealHom : ℝ≥0 →+* ℝ≥0∞ where toFun := some map_one' := coe_one map_mul' _ _ := coe_mul _ _ map_zero' := coe_zero map_add' _ _ := coe_add _ _ @[simp] theorem coe_ofNNRealHom : ⇑ofNNRealHom = some := rfl section Order theorem bot_eq_zero : (⊥ : ℝ≥0∞) = 0 := rfl -- `coe_lt_top` moved up theorem not_top_le_coe : ° ≀ ↑r := WithTop.not_top_le_coe r @[simp, norm_cast] theorem one_le_coe_iff : (1 : ℝ≥0∞) ≀ ↑r ↔ 1 ≀ r := coe_le_coe @[simp, norm_cast] theorem coe_le_one_iff : ↑r ≀ (1 : ℝ≥0∞) ↔ r ≀ 1 := coe_le_coe @[simp, norm_cast] theorem coe_lt_one_iff : (↑p : ℝ≥0∞) < 1 ↔ p < 1 := coe_lt_coe @[simp, norm_cast] theorem one_lt_coe_iff : 1 < (↑p : ℝ≥0∞) ↔ 1 < p := coe_lt_coe @[simp, norm_cast] theorem coe_natCast (n : ℕ) : ((n : ℝ≥0) : ℝ≥0∞) = n := rfl @[simp, norm_cast] lemma ofReal_natCast (n : ℕ) : ENNReal.ofReal n = n := by simp [ENNReal.ofReal] @[simp] theorem ofReal_ofNat (n : ℕ) [n.AtLeastTwo] : ENNReal.ofReal ofNat(n) = ofNat(n) := ofReal_natCast n @[simp, aesop (rule_sets := [finiteness]) safe apply] theorem natCast_ne_top (n : ℕ) : (n : ℝ≥0∞) ≠ ∞ := WithTop.natCast_ne_top n @[simp] theorem natCast_lt_top (n : ℕ) : (n : ℝ≥0∞) < ∞ := WithTop.natCast_lt_top n @[simp, aesop (rule_sets := [finiteness]) safe apply] lemma ofNat_ne_top {n : ℕ} [Nat.AtLeastTwo n] : ofNat(n) ≠ ∞ := natCast_ne_top n @[simp] lemma ofNat_lt_top {n : ℕ} [Nat.AtLeastTwo n] : ofNat(n) < ∞ := natCast_lt_top n @[simp] theorem top_ne_natCast (n : ℕ) : ∞ ≠ n := WithTop.top_ne_natCast n @[simp] theorem top_ne_ofNat {n : ℕ} [n.AtLeastTwo] : ∞ ≠ ofNat(n) := ofNat_ne_top.symm @[deprecated ofNat_ne_top (since := "2025-01-21")] lemma two_ne_top : (2 : ℝ≥0∞) ≠ ∞ := coe_ne_top @[deprecated ofNat_lt_top (since := "2025-01-21")] lemma two_lt_top : (2 : ℝ≥0∞) < ∞ := coe_lt_top @[simp] theorem one_lt_top : 1 < ∞ := coe_lt_top @[simp, norm_cast] theorem toNNReal_natCast (n : ℕ) : (n : ℝ≥0∞).toNNReal = n := by rw [← ENNReal.coe_natCast n, ENNReal.toNNReal_coe] @[deprecated (since := "2025-02-19")] alias toNNReal_nat := toNNReal_natCast theorem toNNReal_ofNat (n : ℕ) [n.AtLeastTwo] : ENNReal.toNNReal ofNat(n) = ofNat(n) := toNNReal_natCast n @[simp, norm_cast] theorem toReal_natCast (n : ℕ) : (n : ℝ≥0∞).toReal = n := by rw [← ENNReal.ofReal_natCast n, ENNReal.toReal_ofReal (Nat.cast_nonneg _)] @[deprecated (since := "2025-02-19")] alias toReal_nat := toReal_natCast @[simp] theorem toReal_ofNat (n : ℕ) [n.AtLeastTwo] : ENNReal.toReal ofNat(n) = ofNat(n) := toReal_natCast n lemma toNNReal_natCast_eq_toNNReal (n : ℕ) : (n : ℝ≥0∞).toNNReal = (n : ℝ).toNNReal := by rw [Real.toNNReal_of_nonneg (by positivity), ENNReal.toNNReal_natCast, mk_natCast] theorem le_coe_iff : a ≀ ↑r ↔ ∃ p : ℝ≥0, a = p ∧ p ≀ r := WithTop.le_coe_iff theorem coe_le_iff : ↑r ≀ a ↔ ∀ p : ℝ≥0, a = p → r ≀ p := WithTop.coe_le_iff theorem lt_iff_exists_coe : a < b ↔ ∃ p : ℝ≥0, a = p ∧ ↑p < b := WithTop.lt_iff_exists_coe theorem toReal_le_coe_of_le_coe {a : ℝ≥0∞} {b : ℝ≥0} (h : a ≀ b) : a.toReal ≀ b := by lift a to ℝ≥0 using ne_top_of_le_ne_top coe_ne_top h simpa using h @[simp] theorem max_eq_zero_iff : max a b = 0 ↔ a = 0 ∧ b = 0 := max_eq_bot theorem max_zero_left : max 0 a = a := max_eq_right (zero_le a) theorem max_zero_right : max a 0 = a := max_eq_left (zero_le a) theorem lt_iff_exists_rat_btwn : a < b ↔ ∃ q : ℚ, 0 ≀ q ∧ a < Real.toNNReal q ∧ (Real.toNNReal q : ℝ≥0∞) < b := ⟹fun h => by rcases lt_iff_exists_coe.1 h with ⟹p, rfl, _⟩ rcases exists_between h with ⟹c, pc, cb⟩ rcases lt_iff_exists_coe.1 cb with ⟹r, rfl, _⟩ rcases (NNReal.lt_iff_exists_rat_btwn _ _).1 (coe_lt_coe.1 pc) with ⟹q, hq0, pq, qr⟩ exact ⟹q, hq0, coe_lt_coe.2 pq, lt_trans (coe_lt_coe.2 qr) cb⟩, fun ⟹_, _, qa, qb⟩ => lt_trans qa qb⟩ theorem lt_iff_exists_real_btwn : a < b ↔ ∃ r : ℝ, 0 ≀ r ∧ a < ENNReal.ofReal r ∧ (ENNReal.ofReal r : ℝ≥0∞) < b := ⟹fun h => let ⟹q, q0, aq, qb⟩ := ENNReal.lt_iff_exists_rat_btwn.1 h ⟹q, Rat.cast_nonneg.2 q0, aq, qb⟩, fun ⟹_, _, qa, qb⟩ => lt_trans qa qb⟩ theorem lt_iff_exists_nnreal_btwn : a < b ↔ ∃ r : ℝ≥0, a < r ∧ (r : ℝ≥0∞) < b := WithTop.lt_iff_exists_coe_btwn theorem lt_iff_exists_add_pos_lt : a < b ↔ ∃ r : ℝ≥0, 0 < r ∧ a + r < b := by refine ⟹fun hab => ?_, fun ⟹r, _, hr⟩ => lt_of_le_of_lt le_self_add hr⟩ rcases lt_iff_exists_nnreal_btwn.1 hab with ⟹c, ac, cb⟩ lift a to ℝ≥0 using ac.ne_top rw [coe_lt_coe] at ac refine ⟹c - a, tsub_pos_iff_lt.2 ac, ?_⟩ rwa [← coe_add, add_tsub_cancel_of_le ac.le] theorem le_of_forall_pos_le_add (h : ∀ ε : ℝ≥0, 0 < ε → b < ∞ → a ≀ b + ε) : a ≀ b := by contrapose! h rcases lt_iff_exists_add_pos_lt.1 h with ⟹r, hr0, hr⟩ exact ⟹r, hr0, h.trans_le le_top, hr⟩ theorem natCast_lt_coe {n : ℕ} : n < (r : ℝ≥0∞) ↔ n < r := ENNReal.coe_natCast n ▾ coe_lt_coe theorem coe_lt_natCast {n : ℕ} : (r : ℝ≥0∞) < n ↔ r < n := ENNReal.coe_natCast n ▾ coe_lt_coe protected theorem exists_nat_gt {r : ℝ≥0∞} (h : r ≠ ∞) : ∃ n : ℕ, r < n := by lift r to ℝ≥0 using h rcases exists_nat_gt r with ⟹n, hn⟩ exact ⟹n, coe_lt_natCast.2 hn⟩ @[simp] theorem iUnion_Iio_coe_nat : ⋃ n : ℕ, Iio (n : ℝ≥0∞) = {∞}ᶜ := by ext x rw [mem_iUnion] exact ⟹fun ⟹n, hn⟩ => ne_top_of_lt hn, ENNReal.exists_nat_gt⟩ @[simp] theorem iUnion_Iic_coe_nat : ⋃ n : ℕ, Iic (n : ℝ≥0∞) = {∞}ᶜ := Subset.antisymm (iUnion_subset fun n _x hx => ne_top_of_le_ne_top (natCast_ne_top n) hx) <| iUnion_Iio_coe_nat ▾ iUnion_mono fun _ => Iio_subset_Iic_self @[simp] theorem iUnion_Ioc_coe_nat : ⋃ n : ℕ, Ioc a n = Ioi a \ {∞} := by simp only [← Ioi_inter_Iic, ← inter_iUnion, iUnion_Iic_coe_nat, diff_eq] @[simp] theorem iUnion_Ioo_coe_nat : ⋃ n : ℕ, Ioo a n = Ioi a \ {∞} := by simp only [← Ioi_inter_Iio, ← inter_iUnion, iUnion_Iio_coe_nat, diff_eq] @[simp] theorem iUnion_Icc_coe_nat : ⋃ n : ℕ, Icc a n = Ici a \ {∞} := by simp only [← Ici_inter_Iic, ← inter_iUnion, iUnion_Iic_coe_nat, diff_eq] @[simp] theorem iUnion_Ico_coe_nat : ⋃ n : ℕ, Ico a n = Ici a \ {∞} := by simp only [← Ici_inter_Iio, ← inter_iUnion, iUnion_Iio_coe_nat, diff_eq] @[simp] theorem iInter_Ici_coe_nat : ⋂ n : ℕ, Ici (n : ℝ≥0∞) = {∞} := by simp only [← compl_Iio, ← compl_iUnion, iUnion_Iio_coe_nat, compl_compl] @[simp] theorem iInter_Ioi_coe_nat : ⋂ n : ℕ, Ioi (n : ℝ≥0∞) = {∞} := by simp only [← compl_Iic, ← compl_iUnion, iUnion_Iic_coe_nat, compl_compl] @[simp, norm_cast] theorem coe_min (r p : ℝ≥0) : ((min r p : ℝ≥0) : ℝ≥0∞) = min (r : ℝ≥0∞) p := rfl @[simp, norm_cast] theorem coe_max (r p : ℝ≥0) : ((max r p : ℝ≥0) : ℝ≥0∞) = max (r : ℝ≥0∞) p := rfl theorem le_of_top_imp_top_of_toNNReal_le {a b : ℝ≥0∞} (h : a = ⊀ → b = ⊀) (h_nnreal : a ≠ ⊀ → b ≠ ⊀ → a.toNNReal ≀ b.toNNReal) : a ≀ b := by by_contra! hlt lift b to ℝ≥0 using hlt.ne_top lift a to ℝ≥0 using mt h coe_ne_top refine hlt.not_le ?_ simpa using h_nnreal @[simp] theorem abs_toReal {x : ℝ≥0∞} : |x.toReal| = x.toReal := by cases x <;> simp end Order section CompleteLattice variable {ι : Sort*} {f : ι → ℝ≥0} theorem coe_sSup {s : Set ℝ≥0} : BddAbove s → (↑(sSup s) : ℝ≥0∞) = ⹆ a ∈ s, ↑a := WithTop.coe_sSup theorem coe_sInf {s : Set ℝ≥0} (hs : s.Nonempty) : (↑(sInf s) : ℝ≥0∞) = ⹅ a ∈ s, ↑a := WithTop.coe_sInf hs (OrderBot.bddBelow s) theorem coe_iSup {ι : Sort*} {f : ι → ℝ≥0} (hf : BddAbove (range f)) : (↑(iSup f) : ℝ≥0∞) = ⹆ a, ↑(f a) := WithTop.coe_iSup _ hf @[norm_cast] theorem coe_iInf {ι : Sort*} [Nonempty ι] (f : ι → ℝ≥0) : (↑(iInf f) : ℝ≥0∞) = ⹅ a, ↑(f a) := WithTop.coe_iInf (OrderBot.bddBelow _) theorem coe_mem_upperBounds {s : Set ℝ≥0} : ↑r ∈ upperBounds (ofNNReal '' s) ↔ r ∈ upperBounds s := by simp +contextual [upperBounds, forall_mem_image, -mem_image, *] lemma iSup_coe_eq_top : ⹆ i, (f i : ℝ≥0∞) = ⊀ ↔ ¬ BddAbove (range f) := WithTop.iSup_coe_eq_top lemma iSup_coe_lt_top : ⹆ i, (f i : ℝ≥0∞) < ⊀ ↔ BddAbove (range f) := WithTop.iSup_coe_lt_top lemma iInf_coe_eq_top : ⹅ i, (f i : ℝ≥0∞) = ⊀ ↔ IsEmpty ι := WithTop.iInf_coe_eq_top lemma iInf_coe_lt_top : ⹅ i, (f i : ℝ≥0∞) < ⊀ ↔ Nonempty ι := WithTop.iInf_coe_lt_top end CompleteLattice section Bit -- TODO: add lemmas about `OfNat.ofNat` end Bit end ENNReal open ENNReal namespace Set
namespace OrdConnected
Mathlib/Data/ENNReal/Basic.lean
703
704
/- Copyright (c) 2022 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Data.Set.Image import Mathlib.Order.Interval.Set.Basic import Mathlib.Order.WithBot /-! # Intervals in `WithTop α` and `WithBot α` In this file we prove various lemmas about `Set.image`s and `Set.preimage`s of intervals under `some : α → WithTop α` and `some : α → WithBot α`. -/ open Set variable {α : Type*} /-! ### `WithTop` -/ namespace WithTop @[simp] theorem preimage_coe_top : (some : α → WithTop α) ⁻¹' {⊀} = (∅ : Set α) := eq_empty_of_subset_empty fun _ => coe_ne_top variable [Preorder α] {a b : α} theorem range_coe : range (some : α → WithTop α) = Iio ⊀ := by ext x rw [mem_Iio, WithTop.lt_top_iff_ne_top, mem_range, ne_top_iff_exists] @[simp] theorem preimage_coe_Ioi : (some : α → WithTop α) ⁻¹' Ioi a = Ioi a := ext fun _ => coe_lt_coe @[simp] theorem preimage_coe_Ici : (some : α → WithTop α) ⁻¹' Ici a = Ici a := ext fun _ => coe_le_coe @[simp] theorem preimage_coe_Iio : (some : α → WithTop α) ⁻¹' Iio a = Iio a := ext fun _ => coe_lt_coe @[simp] theorem preimage_coe_Iic : (some : α → WithTop α) ⁻¹' Iic a = Iic a := ext fun _ => coe_le_coe @[simp] theorem preimage_coe_Icc : (some : α → WithTop α) ⁻¹' Icc a b = Icc a b := by simp [← Ici_inter_Iic] @[simp] theorem preimage_coe_Ico : (some : α → WithTop α) ⁻¹' Ico a b = Ico a b := by simp [← Ici_inter_Iio] @[simp] theorem preimage_coe_Ioc : (some : α → WithTop α) ⁻¹' Ioc a b = Ioc a b := by simp [← Ioi_inter_Iic] @[simp] theorem preimage_coe_Ioo : (some : α → WithTop α) ⁻¹' Ioo a b = Ioo a b := by simp [← Ioi_inter_Iio] @[simp] theorem preimage_coe_Iio_top : (some : α → WithTop α) ⁻¹' Iio ⊀ = univ := by rw [← range_coe, preimage_range] @[simp] theorem preimage_coe_Ico_top : (some : α → WithTop α) ⁻¹' Ico a ⊀ = Ici a := by simp [← Ici_inter_Iio] @[simp] theorem preimage_coe_Ioo_top : (some : α → WithTop α) ⁻¹' Ioo a ⊀ = Ioi a := by simp [← Ioi_inter_Iio] theorem image_coe_Ioi : (some : α → WithTop α) '' Ioi a = Ioo (a : WithTop α) ⊀ := by rw [← preimage_coe_Ioi, image_preimage_eq_inter_range, range_coe, Ioi_inter_Iio] theorem image_coe_Ici : (some : α → WithTop α) '' Ici a = Ico (a : WithTop α) ⊀ := by rw [← preimage_coe_Ici, image_preimage_eq_inter_range, range_coe, Ici_inter_Iio] theorem image_coe_Iio : (some : α → WithTop α) '' Iio a = Iio (a : WithTop α) := by rw [← preimage_coe_Iio, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Iio_subset_Iio le_top)] theorem image_coe_Iic : (some : α → WithTop α) '' Iic a = Iic (a : WithTop α) := by rw [← preimage_coe_Iic, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Iic_subset_Iio.2 <| coe_lt_top a)] theorem image_coe_Icc : (some : α → WithTop α) '' Icc a b = Icc (a : WithTop α) b := by rw [← preimage_coe_Icc, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Subset.trans Icc_subset_Iic_self <| Iic_subset_Iio.2 <| coe_lt_top b)] theorem image_coe_Ico : (some : α → WithTop α) '' Ico a b = Ico (a : WithTop α) b := by rw [← preimage_coe_Ico, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Subset.trans Ico_subset_Iio_self <| Iio_subset_Iio le_top)] theorem image_coe_Ioc : (some : α → WithTop α) '' Ioc a b = Ioc (a : WithTop α) b := by rw [← preimage_coe_Ioc, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Subset.trans Ioc_subset_Iic_self <| Iic_subset_Iio.2 <| coe_lt_top b)] theorem image_coe_Ioo : (some : α → WithTop α) '' Ioo a b = Ioo (a : WithTop α) b := by rw [← preimage_coe_Ioo, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Subset.trans Ioo_subset_Iio_self <| Iio_subset_Iio le_top)] end WithTop /-! ### `WithBot` -/ namespace WithBot @[simp] theorem preimage_coe_bot : (some : α → WithBot α) ⁻¹' {⊥} = (∅ : Set α) := @WithTop.preimage_coe_top αᵒᵈ variable [Preorder α] {a b : α} theorem range_coe : range (some : α → WithBot α) = Ioi ⊥ := @WithTop.range_coe αᵒᵈ _ @[simp] theorem preimage_coe_Ioi : (some : α → WithBot α) ⁻¹' Ioi a = Ioi a := ext fun _ => coe_lt_coe @[simp] theorem preimage_coe_Ici : (some : α → WithBot α) ⁻¹' Ici a = Ici a := ext fun _ => coe_le_coe @[simp] theorem preimage_coe_Iio : (some : α → WithBot α) ⁻¹' Iio a = Iio a := ext fun _ => coe_lt_coe @[simp] theorem preimage_coe_Iic : (some : α → WithBot α) ⁻¹' Iic a = Iic a := ext fun _ => coe_le_coe @[simp] theorem preimage_coe_Icc : (some : α → WithBot α) ⁻¹' Icc a b = Icc a b := by simp [← Ici_inter_Iic] @[simp] theorem preimage_coe_Ico : (some : α → WithBot α) ⁻¹' Ico a b = Ico a b := by simp [← Ici_inter_Iio] @[simp] theorem preimage_coe_Ioc : (some : α → WithBot α) ⁻¹' Ioc a b = Ioc a b := by simp [← Ioi_inter_Iic] @[simp] theorem preimage_coe_Ioo : (some : α → WithBot α) ⁻¹' Ioo a b = Ioo a b := by simp [← Ioi_inter_Iio] @[simp] theorem preimage_coe_Ioi_bot : (some : α → WithBot α) ⁻¹' Ioi ⊥ = univ := by rw [← range_coe, preimage_range] @[simp] theorem preimage_coe_Ioc_bot : (some : α → WithBot α) ⁻¹' Ioc ⊥ a = Iic a := by simp [← Ioi_inter_Iic] @[simp] theorem preimage_coe_Ioo_bot : (some : α → WithBot α) ⁻¹' Ioo ⊥ a = Iio a := by simp [← Ioi_inter_Iio] theorem image_coe_Iio : (some : α → WithBot α) '' Iio a = Ioo (⊥ : WithBot α) a := by rw [← preimage_coe_Iio, image_preimage_eq_inter_range, range_coe, inter_comm, Ioi_inter_Iio] theorem image_coe_Iic : (some : α → WithBot α) '' Iic a = Ioc (⊥ : WithBot α) a := by rw [← preimage_coe_Iic, image_preimage_eq_inter_range, range_coe, inter_comm, Ioi_inter_Iic] theorem image_coe_Ioi : (some : α → WithBot α) '' Ioi a = Ioi (a : WithBot α) := by rw [← preimage_coe_Ioi, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Ioi_subset_Ioi bot_le)] theorem image_coe_Ici : (some : α → WithBot α) '' Ici a = Ici (a : WithBot α) := by rw [← preimage_coe_Ici, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Ici_subset_Ioi.2 <| bot_lt_coe a)] theorem image_coe_Icc : (some : α → WithBot α) '' Icc a b = Icc (a : WithBot α) b := by rw [← preimage_coe_Icc, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Subset.trans Icc_subset_Ici_self <| Ici_subset_Ioi.2 <| bot_lt_coe a)] theorem image_coe_Ioc : (some : α → WithBot α) '' Ioc a b = Ioc (a : WithBot α) b := by rw [← preimage_coe_Ioc, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Subset.trans Ioc_subset_Ioi_self <| Ioi_subset_Ioi bot_le)] theorem image_coe_Ico : (some : α → WithBot α) '' Ico a b = Ico (a : WithBot α) b := by rw [← preimage_coe_Ico, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Subset.trans Ico_subset_Ici_self <| Ici_subset_Ioi.2 <| bot_lt_coe a)] theorem image_coe_Ioo : (some : α → WithBot α) '' Ioo a b = Ioo (a : WithBot α) b := by rw [← preimage_coe_Ioo, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Subset.trans Ioo_subset_Ioi_self <| Ioi_subset_Ioi bot_le)] end WithBot
Mathlib/Order/Interval/Set/WithBotTop.lean
197
198
/- 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
Mathlib/Algebra/Order/Field/Basic.lean
235
236
/- Copyright (c) 2022 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import Mathlib.Analysis.InnerProductSpace.Dual import Mathlib.Analysis.InnerProductSpace.Orientation import Mathlib.Data.Complex.FiniteDimensional import Mathlib.Data.Complex.Orientation import Mathlib.Tactic.LinearCombination /-! # Oriented two-dimensional real inner product spaces This file defines constructions specific to the geometry of an oriented two-dimensional real inner product space `E`. ## Main declarations * `Orientation.areaForm`: an antisymmetric bilinear form `E →ₗ[ℝ] E →ₗ[ℝ] ℝ` (usual notation `ω`). Morally, when `ω` is evaluated on two vectors, it gives the oriented area of the parallelogram they span. (But mathlib does not yet have a construction of oriented area, and in fact the construction of oriented area should pass through `ω`.) * `Orientation.rightAngleRotation`: an isometric automorphism `E ≃ₗᵢ[ℝ] E` (usual notation `J`). This automorphism squares to -1. In a later file, rotations (`Orientation.rotation`) are defined, in such a way that this automorphism is equal to rotation by 90 degrees. * `Orientation.basisRightAngleRotation`: for a nonzero vector `x` in `E`, the basis `![x, J x]` for `E`. * `Orientation.kahler`: a complex-valued real-bilinear map `E →ₗ[ℝ] E →ₗ[ℝ] ℂ`. Its real part is the inner product and its imaginary part is `Orientation.areaForm`. For vectors `x` and `y` in `E`, the complex number `o.kahler x y` has modulus `‖x‖ * ‖y‖`. In a later file, oriented angles (`Orientation.oangle`) are defined, in such a way that the argument of `o.kahler x y` is the oriented angle from `x` to `y`. ## Main results * `Orientation.rightAngleRotation_rightAngleRotation`: the identity `J (J x) = - x` * `Orientation.nonneg_inner_and_areaForm_eq_zero_iff_sameRay`: `x`, `y` are in the same ray, if and only if `0 ≀ ⟪x, y⟫` and `ω x y = 0` * `Orientation.kahler_mul`: the identity `o.kahler x a * o.kahler a y = ‖a‖ ^ 2 * o.kahler x y` * `Complex.areaForm`, `Complex.rightAngleRotation`, `Complex.kahler`: the concrete interpretations of `areaForm`, `rightAngleRotation`, `kahler` for the oriented real inner product space `ℂ` * `Orientation.areaForm_map_complex`, `Orientation.rightAngleRotation_map_complex`, `Orientation.kahler_map_complex`: given an orientation-preserving isometry from `E` to `ℂ`, expressions for `areaForm`, `rightAngleRotation`, `kahler` as the pullback of their concrete interpretations on `ℂ` ## Implementation notes Notation `ω` for `Orientation.areaForm` and `J` for `Orientation.rightAngleRotation` should be defined locally in each file which uses them, since otherwise one would need a more cumbersome notation which mentions the orientation explicitly (something like `ω[o]`). Write ``` local notation "ω" => o.areaForm local notation "J" => o.rightAngleRotation ``` -/ noncomputable section open scoped RealInnerProductSpace ComplexConjugate open Module lemma FiniteDimensional.of_fact_finrank_eq_two {K V : Type*} [DivisionRing K] [AddCommGroup V] [Module K V] [Fact (finrank K V = 2)] : FiniteDimensional K V := .of_fact_finrank_eq_succ 1 attribute [local instance] FiniteDimensional.of_fact_finrank_eq_two variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [Fact (finrank ℝ E = 2)] (o : Orientation ℝ E (Fin 2)) namespace Orientation /-- An antisymmetric bilinear form on an oriented real inner product space of dimension 2 (usual notation `ω`). When evaluated on two vectors, it gives the oriented area of the parallelogram they span. -/ irreducible_def areaForm : E →ₗ[ℝ] E →ₗ[ℝ] ℝ := by let z : E [⋀^Fin 0]→ₗ[ℝ] ℝ ≃ₗ[ℝ] ℝ := AlternatingMap.constLinearEquivOfIsEmpty.symm let y : E [⋀^Fin 1]→ₗ[ℝ] ℝ →ₗ[ℝ] E →ₗ[ℝ] ℝ := LinearMap.llcomp ℝ E (E [⋀^Fin 0]→ₗ[ℝ] ℝ) ℝ z ∘ₗ AlternatingMap.curryLeftLinearMap exact y ∘ₗ AlternatingMap.curryLeftLinearMap (R' := ℝ) o.volumeForm local notation "ω" => o.areaForm theorem areaForm_to_volumeForm (x y : E) : ω x y = o.volumeForm ![x, y] := by simp [areaForm] @[simp] theorem areaForm_apply_self (x : E) : ω x x = 0 := by rw [areaForm_to_volumeForm] refine o.volumeForm.map_eq_zero_of_eq ![x, x] ?_ (?_ : (0 : Fin 2) ≠ 1) · simp · norm_num theorem areaForm_swap (x y : E) : ω x y = -ω y x := by simp only [areaForm_to_volumeForm] convert o.volumeForm.map_swap ![y, x] (_ : (0 : Fin 2) ≠ 1) · ext i fin_cases i <;> rfl · norm_num @[simp] theorem areaForm_neg_orientation : (-o).areaForm = -o.areaForm := by ext x y simp [areaForm_to_volumeForm] /-- Continuous linear map version of `Orientation.areaForm`, useful for calculus. -/ def areaForm' : E →L[ℝ] E →L[ℝ] ℝ := LinearMap.toContinuousLinearMap (↑(LinearMap.toContinuousLinearMap : (E →ₗ[ℝ] ℝ) ≃ₗ[ℝ] E →L[ℝ] ℝ) ∘ₗ o.areaForm) @[simp] theorem areaForm'_apply (x : E) : o.areaForm' x = LinearMap.toContinuousLinearMap (o.areaForm x) := rfl theorem abs_areaForm_le (x y : E) : |ω x y| ≀ ‖x‖ * ‖y‖ := by simpa [areaForm_to_volumeForm, Fin.prod_univ_succ] using o.abs_volumeForm_apply_le ![x, y] theorem areaForm_le (x y : E) : ω x y ≀ ‖x‖ * ‖y‖ := by simpa [areaForm_to_volumeForm, Fin.prod_univ_succ] using o.volumeForm_apply_le ![x, y] theorem abs_areaForm_of_orthogonal {x y : E} (h : ⟪x, y⟫ = 0) : |ω x y| = ‖x‖ * ‖y‖ := by rw [o.areaForm_to_volumeForm, o.abs_volumeForm_apply_of_pairwise_orthogonal] · simp [Fin.prod_univ_succ] intro i j hij fin_cases i <;> fin_cases j · simp_all · simpa using h · simpa [real_inner_comm] using h · simp_all theorem areaForm_map {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] [hF : Fact (finrank ℝ F = 2)] (φ : E ≃ₗᵢ[ℝ] F) (x y : F) : (Orientation.map (Fin 2) φ.toLinearEquiv o).areaForm x y = o.areaForm (φ.symm x) (φ.symm y) := by have : φ.symm ∘ ![x, y] = ![φ.symm x, φ.symm y] := by ext i fin_cases i <;> rfl simp [areaForm_to_volumeForm, volumeForm_map, this] /-- The area form is invariant under pullback by a positively-oriented isometric automorphism. -/ theorem areaForm_comp_linearIsometryEquiv (φ : E ≃ₗᵢ[ℝ] E) (hφ : 0 < LinearMap.det (φ.toLinearEquiv : E →ₗ[ℝ] E)) (x y : E) : o.areaForm (φ x) (φ y) = o.areaForm x y := by convert o.areaForm_map φ (φ x) (φ y) · symm rwa [← o.map_eq_iff_det_pos φ.toLinearEquiv] at hφ rw [@Fact.out (finrank ℝ E = 2), Fintype.card_fin] · simp · simp /-- Auxiliary construction for `Orientation.rightAngleRotation`, rotation by 90 degrees in an oriented real inner product space of dimension 2. -/ irreducible_def rightAngleRotationAux₁ : E →ₗ[ℝ] E := let to_dual : E ≃ₗ[ℝ] E →ₗ[ℝ] ℝ := (InnerProductSpace.toDual ℝ E).toLinearEquiv ≪≫ₗ LinearMap.toContinuousLinearMap.symm ↑to_dual.symm ∘ₗ ω @[simp] theorem inner_rightAngleRotationAux₁_left (x y : E) : ⟪o.rightAngleRotationAux₁ x, y⟫ = ω x y := by simp only [rightAngleRotationAux₁, LinearEquiv.trans_symm, LinearIsometryEquiv.toLinearEquiv_symm, LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, LinearEquiv.trans_apply, LinearIsometryEquiv.coe_toLinearEquiv] rw [InnerProductSpace.toDual_symm_apply] norm_cast @[simp] theorem inner_rightAngleRotationAux₁_right (x y : E) : ⟪x, o.rightAngleRotationAux₁ y⟫ = -ω x y := by rw [real_inner_comm] simp [o.areaForm_swap y x] /-- Auxiliary construction for `Orientation.rightAngleRotation`, rotation by 90 degrees in an oriented real inner product space of dimension 2. -/ def rightAngleRotationAux₂ : E →ₗᵢ[ℝ] E := { o.rightAngleRotationAux₁ with norm_map' := fun x => by refine le_antisymm ?_ ?_ · rcases eq_or_lt_of_le (norm_nonneg (o.rightAngleRotationAux₁ x)) with h | h · rw [← h] positivity refine le_of_mul_le_mul_right ?_ h rw [← real_inner_self_eq_norm_mul_norm, o.inner_rightAngleRotationAux₁_left] exact o.areaForm_le x (o.rightAngleRotationAux₁ x) · let K : Submodule ℝ E := ℝ ∙ x have : Nontrivial Kᗮ := by apply nontrivial_of_finrank_pos (R := ℝ) have : finrank ℝ K ≀ Finset.card {x} := by rw [← Set.toFinset_singleton] exact finrank_span_le_card ({x} : Set E) have : Finset.card {x} = 1 := Finset.card_singleton x have : finrank ℝ K + finrank ℝ Kᗮ = finrank ℝ E := K.finrank_add_finrank_orthogonal have : finrank ℝ E = 2 := Fact.out omega obtain ⟹w, hw₀⟩ : ∃ w : Kᗮ, w ≠ 0 := exists_ne 0 have hw' : ⟪x, (w : E)⟫ = 0 := Submodule.mem_orthogonal_singleton_iff_inner_right.mp w.2 have hw : (w : E) ≠ 0 := fun h => hw₀ (Submodule.coe_eq_zero.mp h) refine le_of_mul_le_mul_right ?_ (by rwa [norm_pos_iff] : 0 < ‖(w : E)‖) rw [← o.abs_areaForm_of_orthogonal hw'] rw [← o.inner_rightAngleRotationAux₁_left x w] exact abs_real_inner_le_norm (o.rightAngleRotationAux₁ x) w } @[simp] theorem rightAngleRotationAux₁_rightAngleRotationAux₁ (x : E) : o.rightAngleRotationAux₁ (o.rightAngleRotationAux₁ x) = -x := by apply ext_inner_left ℝ intro y have : ⟪o.rightAngleRotationAux₁ y, o.rightAngleRotationAux₁ x⟫ = ⟪y, x⟫ := LinearIsometry.inner_map_map o.rightAngleRotationAux₂ y x rw [o.inner_rightAngleRotationAux₁_right, ← o.inner_rightAngleRotationAux₁_left, this, inner_neg_right] /-- An isometric automorphism of an oriented real inner product space of dimension 2 (usual notation `J`). This automorphism squares to -1. We will define rotations in such a way that this automorphism is equal to rotation by 90 degrees. -/ irreducible_def rightAngleRotation : E ≃ₗᵢ[ℝ] E := LinearIsometryEquiv.ofLinearIsometry o.rightAngleRotationAux₂ (-o.rightAngleRotationAux₁) (by ext; simp [rightAngleRotationAux₂]) (by ext; simp [rightAngleRotationAux₂]) local notation "J" => o.rightAngleRotation @[simp] theorem inner_rightAngleRotation_left (x y : E) : ⟪J x, y⟫ = ω x y := by rw [rightAngleRotation] exact o.inner_rightAngleRotationAux₁_left x y @[simp] theorem inner_rightAngleRotation_right (x y : E) : ⟪x, J y⟫ = -ω x y := by rw [rightAngleRotation] exact o.inner_rightAngleRotationAux₁_right x y @[simp] theorem rightAngleRotation_rightAngleRotation (x : E) : J (J x) = -x := by rw [rightAngleRotation] exact o.rightAngleRotationAux₁_rightAngleRotationAux₁ x @[simp] theorem rightAngleRotation_symm : LinearIsometryEquiv.symm J = LinearIsometryEquiv.trans J (LinearIsometryEquiv.neg ℝ) := by rw [rightAngleRotation] exact LinearIsometryEquiv.toLinearIsometry_injective rfl theorem inner_rightAngleRotation_self (x : E) : ⟪J x, x⟫ = 0 := by simp theorem inner_rightAngleRotation_swap (x y : E) : ⟪x, J y⟫ = -⟪J x, y⟫ := by simp theorem inner_rightAngleRotation_swap' (x y : E) : ⟪J x, y⟫ = -⟪x, J y⟫ := by simp [o.inner_rightAngleRotation_swap x y] theorem inner_comp_rightAngleRotation (x y : E) : ⟪J x, J y⟫ = ⟪x, y⟫ := LinearIsometryEquiv.inner_map_map J x y @[simp] theorem areaForm_rightAngleRotation_left (x y : E) : ω (J x) y = -⟪x, y⟫ := by rw [← o.inner_comp_rightAngleRotation, o.inner_rightAngleRotation_right, neg_neg] @[simp] theorem areaForm_rightAngleRotation_right (x y : E) : ω x (J y) = ⟪x, y⟫ := by rw [← o.inner_rightAngleRotation_left, o.inner_comp_rightAngleRotation] theorem areaForm_comp_rightAngleRotation (x y : E) : ω (J x) (J y) = ω x y := by simp @[simp] theorem rightAngleRotation_trans_rightAngleRotation : LinearIsometryEquiv.trans J J = LinearIsometryEquiv.neg ℝ := by ext; simp theorem rightAngleRotation_neg_orientation (x : E) : (-o).rightAngleRotation x = -o.rightAngleRotation x := by apply ext_inner_right ℝ intro y rw [inner_rightAngleRotation_left] simp @[simp] theorem rightAngleRotation_trans_neg_orientation : (-o).rightAngleRotation = o.rightAngleRotation.trans (LinearIsometryEquiv.neg ℝ) := LinearIsometryEquiv.ext <| o.rightAngleRotation_neg_orientation theorem rightAngleRotation_map {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] [hF : Fact (finrank ℝ F = 2)] (φ : E ≃ₗᵢ[ℝ] F) (x : F) : (Orientation.map (Fin 2) φ.toLinearEquiv o).rightAngleRotation x = φ (o.rightAngleRotation (φ.symm x)) := by apply ext_inner_right ℝ intro y rw [inner_rightAngleRotation_left] trans ⟪J (φ.symm x), φ.symm y⟫ · simp [o.areaForm_map] trans ⟪φ (J (φ.symm x)), φ (φ.symm y)⟫ · rw [φ.inner_map_map] · simp /-- `J` commutes with any positively-oriented isometric automorphism. -/ theorem linearIsometryEquiv_comp_rightAngleRotation (φ : E ≃ₗᵢ[ℝ] E) (hφ : 0 < LinearMap.det (φ.toLinearEquiv : E →ₗ[ℝ] E)) (x : E) : φ (J x) = J (φ x) := by convert (o.rightAngleRotation_map φ (φ x)).symm · simp · symm rwa [← o.map_eq_iff_det_pos φ.toLinearEquiv] at hφ rw [@Fact.out (finrank ℝ E = 2), Fintype.card_fin] theorem rightAngleRotation_map' {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] [Fact (finrank ℝ F = 2)] (φ : E ≃ₗᵢ[ℝ] F) : (Orientation.map (Fin 2) φ.toLinearEquiv o).rightAngleRotation = (φ.symm.trans o.rightAngleRotation).trans φ := LinearIsometryEquiv.ext <| o.rightAngleRotation_map φ /-- `J` commutes with any positively-oriented isometric automorphism. -/ theorem linearIsometryEquiv_comp_rightAngleRotation' (φ : E ≃ₗᵢ[ℝ] E) (hφ : 0 < LinearMap.det (φ.toLinearEquiv : E →ₗ[ℝ] E)) : LinearIsometryEquiv.trans J φ = φ.trans J := LinearIsometryEquiv.ext <| o.linearIsometryEquiv_comp_rightAngleRotation φ hφ /-- For a nonzero vector `x` in an oriented two-dimensional real inner product space `E`, `![x, J x]` forms an (orthogonal) basis for `E`. -/ def basisRightAngleRotation (x : E) (hx : x ≠ 0) : Basis (Fin 2) ℝ E := @basisOfLinearIndependentOfCardEqFinrank ℝ _ _ _ _ _ _ _ ![x, J x] (linearIndependent_of_ne_zero_of_inner_eq_zero (fun i => by fin_cases i <;> simp [hx]) (by intro i j hij fin_cases i <;> fin_cases j <;> simp_all)) (@Fact.out (finrank ℝ E = 2)).symm @[simp] theorem coe_basisRightAngleRotation (x : E) (hx : x ≠ 0) : ⇑(o.basisRightAngleRotation x hx) = ![x, J x] := coe_basisOfLinearIndependentOfCardEqFinrank _ _ /-- For vectors `a x y : E`, the identity `⟪a, x⟫ * ⟪a, y⟫ + ω a x * ω a y = ‖a‖ ^ 2 * ⟪x, y⟫`. (See `Orientation.inner_mul_inner_add_areaForm_mul_areaForm` for the "applied" form.) -/ theorem inner_mul_inner_add_areaForm_mul_areaForm' (a x : E) : ⟪a, x⟫ • innerₛₗ ℝ a + ω a x • ω a = ‖a‖ ^ 2 • innerₛₗ ℝ x := by by_cases ha : a = 0 · simp [ha] apply (o.basisRightAngleRotation a ha).ext intro i fin_cases i · simp [real_inner_self_eq_norm_sq, mul_comm, real_inner_comm] · simp [real_inner_self_eq_norm_sq, mul_comm, o.areaForm_swap a x] /-- For vectors `a x y : E`, the identity `⟪a, x⟫ * ⟪a, y⟫ + ω a x * ω a y = ‖a‖ ^ 2 * ⟪x, y⟫`. -/ theorem inner_mul_inner_add_areaForm_mul_areaForm (a x y : E) : ⟪a, x⟫ * ⟪a, y⟫ + ω a x * ω a y = ‖a‖ ^ 2 * ⟪x, y⟫ := congr_arg (fun f : E →ₗ[ℝ] ℝ => f y) (o.inner_mul_inner_add_areaForm_mul_areaForm' a x) theorem inner_sq_add_areaForm_sq (a b : E) : ⟪a, b⟫ ^ 2 + ω a b ^ 2 = ‖a‖ ^ 2 * ‖b‖ ^ 2 := by simpa [sq, real_inner_self_eq_norm_sq] using o.inner_mul_inner_add_areaForm_mul_areaForm a b b /-- For vectors `a x y : E`, the identity `⟪a, x⟫ * ω a y - ω a x * ⟪a, y⟫ = ‖a‖ ^ 2 * ω x y`. (See `Orientation.inner_mul_areaForm_sub` for the "applied" form.) -/ theorem inner_mul_areaForm_sub' (a x : E) : ⟪a, x⟫ • ω a - ω a x • innerₛₗ ℝ a = ‖a‖ ^ 2 • ω x := by by_cases ha : a = 0 · simp [ha] apply (o.basisRightAngleRotation a ha).ext intro i fin_cases i · simp [real_inner_self_eq_norm_sq, mul_comm, o.areaForm_swap a x] · simp [real_inner_self_eq_norm_sq, mul_comm, real_inner_comm] /-- For vectors `a x y : E`, the identity `⟪a, x⟫ * ω a y - ω a x * ⟪a, y⟫ = ‖a‖ ^ 2 * ω x y`. -/ theorem inner_mul_areaForm_sub (a x y : E) : ⟪a, x⟫ * ω a y - ω a x * ⟪a, y⟫ = ‖a‖ ^ 2 * ω x y := congr_arg (fun f : E →ₗ[ℝ] ℝ => f y) (o.inner_mul_areaForm_sub' a x) theorem nonneg_inner_and_areaForm_eq_zero_iff_sameRay (x y : E) : 0 ≀ ⟪x, y⟫ ∧ ω x y = 0 ↔ SameRay ℝ x y := by by_cases hx : x = 0 · simp [hx] constructor · let a : ℝ := (o.basisRightAngleRotation x hx).repr y 0 let b : ℝ := (o.basisRightAngleRotation x hx).repr y 1 suffices ↑0 ≀ a * ‖x‖ ^ 2 ∧ b * ‖x‖ ^ 2 = 0 → SameRay ℝ x (a • x + b • J x) by rw [← (o.basisRightAngleRotation x hx).sum_repr y] simp only [Fin.sum_univ_succ, coe_basisRightAngleRotation, Matrix.cons_val_zero, Fin.succ_zero_eq_one', Finset.univ_eq_empty, Finset.sum_empty, areaForm_apply_self, map_smul, map_add, real_inner_smul_right, inner_add_right, Matrix.cons_val_one, Matrix.head_cons, Algebra.id.smul_eq_mul, areaForm_rightAngleRotation_right, mul_zero, add_zero, zero_add, neg_zero, inner_rightAngleRotation_right, real_inner_self_eq_norm_sq, zero_smul, one_smul] exact this rintro ⟹ha, hb⟩ have hx' : 0 < ‖x‖ := by simpa using hx have ha' : 0 ≀ a := nonneg_of_mul_nonneg_left ha (by positivity) have hb' : b = 0 := eq_zero_of_ne_zero_of_mul_right_eq_zero (pow_ne_zero 2 hx'.ne') hb exact (SameRay.sameRay_nonneg_smul_right x ha').add_right <| by simp [hb'] · intro h obtain ⟹r, hr, rfl⟩ := h.exists_nonneg_left hx simp only [inner_smul_right, real_inner_self_eq_norm_sq, LinearMap.map_smulₛₗ, areaForm_apply_self, Algebra.id.smul_eq_mul, mul_zero, eq_self_iff_true, and_true] positivity /-- A complex-valued real-bilinear map on an oriented real inner product space of dimension 2. Its real part is the inner product and its imaginary part is `Orientation.areaForm`. On `ℂ` with the standard orientation, `kahler w z = conj w * z`; see `Complex.kahler`. -/ def kahler : E →ₗ[ℝ] E →ₗ[ℝ] ℂ := LinearMap.llcomp ℝ E ℝ ℂ Complex.ofRealCLM ∘ₗ innerₛₗ ℝ + LinearMap.llcomp ℝ E ℝ ℂ ((LinearMap.lsmul ℝ ℂ).flip Complex.I) ∘ₗ ω theorem kahler_apply_apply (x y : E) : o.kahler x y = ⟪x, y⟫ + ω x y • Complex.I := rfl theorem kahler_swap (x y : E) : o.kahler x y = conj (o.kahler y x) := by simp only [kahler_apply_apply] rw [real_inner_comm, areaForm_swap] simp [Complex.conj_ofReal] @[simp] theorem kahler_apply_self (x : E) : o.kahler x x = ‖x‖ ^ 2 := by simp [kahler_apply_apply, real_inner_self_eq_norm_sq] @[simp] theorem kahler_rightAngleRotation_left (x y : E) : o.kahler (J x) y = -Complex.I * o.kahler x y := by simp only [o.areaForm_rightAngleRotation_left, o.inner_rightAngleRotation_left, o.kahler_apply_apply, Complex.ofReal_neg, Complex.real_smul] linear_combination ω x y * Complex.I_sq @[simp] theorem kahler_rightAngleRotation_right (x y : E) : o.kahler x (J y) = Complex.I * o.kahler x y := by simp only [o.areaForm_rightAngleRotation_right, o.inner_rightAngleRotation_right, o.kahler_apply_apply, Complex.ofReal_neg, Complex.real_smul] linear_combination -ω x y * Complex.I_sq -- @[simp] -- Porting note: simp normal form is `kahler_comp_rightAngleRotation'` theorem kahler_comp_rightAngleRotation (x y : E) : o.kahler (J x) (J y) = o.kahler x y := by simp only [kahler_rightAngleRotation_left, kahler_rightAngleRotation_right] linear_combination -o.kahler x y * Complex.I_sq theorem kahler_comp_rightAngleRotation' (x y : E) : -(Complex.I * (Complex.I * o.kahler x y)) = o.kahler x y := by linear_combination -o.kahler x y * Complex.I_sq
@[simp] theorem kahler_neg_orientation (x y : E) : (-o).kahler x y = conj (o.kahler x y) := by simp [kahler_apply_apply, Complex.conj_ofReal] theorem kahler_mul (a x y : E) : o.kahler x a * o.kahler a y = ‖a‖ ^ 2 * o.kahler x y := by trans ((‖a‖ ^ 2 :) : ℂ) * o.kahler x y · apply Complex.ext · simp only [o.kahler_apply_apply, Complex.add_im, Complex.add_re, Complex.I_im, Complex.I_re, Complex.mul_im, Complex.mul_re, Complex.ofReal_im, Complex.ofReal_re, Complex.real_smul] rw [real_inner_comm a x, o.areaForm_swap x a] linear_combination o.inner_mul_inner_add_areaForm_mul_areaForm a x y · simp only [o.kahler_apply_apply, Complex.add_im, Complex.add_re, Complex.I_im, Complex.I_re, Complex.mul_im, Complex.mul_re, Complex.ofReal_im, Complex.ofReal_re, Complex.real_smul] rw [real_inner_comm a x, o.areaForm_swap x a] linear_combination o.inner_mul_areaForm_sub a x y · norm_cast theorem normSq_kahler (x y : E) : Complex.normSq (o.kahler x y) = ‖x‖ ^ 2 * ‖y‖ ^ 2 := by simpa [kahler_apply_apply, Complex.normSq, sq] using o.inner_sq_add_areaForm_sq x y theorem norm_kahler (x y : E) : ‖o.kahler x y‖ = ‖x‖ * ‖y‖ := by rw [← sq_eq_sq₀, Complex.sq_norm] · linear_combination o.normSq_kahler x y · positivity · positivity
Mathlib/Analysis/InnerProductSpace/TwoDim.lean
446
472
/- Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Robert Y. Lewis, Johannes Hölzl, Mario Carneiro, Sébastien Gouëzel -/ import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Order.Interval.Finset.Nat import Mathlib.Topology.EMetricSpace.Defs import Mathlib.Topology.UniformSpace.Compact import Mathlib.Topology.UniformSpace.LocallyUniformConvergence import Mathlib.Topology.UniformSpace.UniformEmbedding /-! # Extended metric spaces Further results about extended metric spaces. -/ open Set Filter universe u v w variable {α : Type u} {β : Type v} {X : Type*} open scoped Uniformity Topology NNReal ENNReal Pointwise variable [PseudoEMetricSpace α] /-- The triangle (polygon) inequality for sequences of points; `Finset.Ico` version. -/ theorem edist_le_Ico_sum_edist (f : ℕ → α) {m n} (h : m ≀ n) : edist (f m) (f n) ≀ ∑ i ∈ Finset.Ico m n, edist (f i) (f (i + 1)) := by induction n, h using Nat.le_induction with | base => rw [Finset.Ico_self, Finset.sum_empty, edist_self] | succ n hle ihn => calc edist (f m) (f (n + 1)) ≀ edist (f m) (f n) + edist (f n) (f (n + 1)) := edist_triangle _ _ _ _ ≀ (∑ i ∈ Finset.Ico m n, _) + _ := add_le_add ihn le_rfl _ = ∑ i ∈ Finset.Ico m (n + 1), _ := by { rw [Nat.Ico_succ_right_eq_insert_Ico hle, Finset.sum_insert, add_comm]; simp } /-- The triangle (polygon) inequality for sequences of points; `Finset.range` version. -/ theorem edist_le_range_sum_edist (f : ℕ → α) (n : ℕ) : edist (f 0) (f n) ≀ ∑ i ∈ Finset.range n, edist (f i) (f (i + 1)) := Nat.Ico_zero_eq_range ▾ edist_le_Ico_sum_edist f (Nat.zero_le n) /-- A version of `edist_le_Ico_sum_edist` with each intermediate distance replaced with an upper estimate. -/ theorem edist_le_Ico_sum_of_edist_le {f : ℕ → α} {m n} (hmn : m ≀ n) {d : ℕ → ℝ≥0∞} (hd : ∀ {k}, m ≀ k → k < n → edist (f k) (f (k + 1)) ≀ d k) : edist (f m) (f n) ≀ ∑ i ∈ Finset.Ico m n, d i := le_trans (edist_le_Ico_sum_edist f hmn) <| Finset.sum_le_sum fun _k hk => hd (Finset.mem_Ico.1 hk).1 (Finset.mem_Ico.1 hk).2 /-- A version of `edist_le_range_sum_edist` with each intermediate distance replaced with an upper estimate. -/ theorem edist_le_range_sum_of_edist_le {f : ℕ → α} (n : ℕ) {d : ℕ → ℝ≥0∞} (hd : ∀ {k}, k < n → edist (f k) (f (k + 1)) ≀ d k) : edist (f 0) (f n) ≀ ∑ i ∈ Finset.range n, d i := Nat.Ico_zero_eq_range ▾ edist_le_Ico_sum_of_edist_le (zero_le n) fun _ => hd namespace EMetric theorem isUniformInducing_iff [PseudoEMetricSpace β] {f : α → β} : IsUniformInducing f ↔ UniformContinuous f ∧ ∀ ÎŽ > 0, ∃ ε > 0, ∀ {a b : α}, edist (f a) (f b) < ε → edist a b < ÎŽ := isUniformInducing_iff'.trans <| Iff.rfl.and <| ((uniformity_basis_edist.comap _).le_basis_iff uniformity_basis_edist).trans <| by simp only [subset_def, Prod.forall]; rfl /-- ε-ÎŽ characterization of uniform embeddings on pseudoemetric spaces -/ nonrec theorem isUniformEmbedding_iff [PseudoEMetricSpace β] {f : α → β} : IsUniformEmbedding f ↔ Function.Injective f ∧ UniformContinuous f ∧ ∀ ÎŽ > 0, ∃ ε > 0, ∀ {a b : α}, edist (f a) (f b) < ε → edist a b < ÎŽ := (isUniformEmbedding_iff _).trans <| and_comm.trans <| Iff.rfl.and isUniformInducing_iff /-- If a map between pseudoemetric spaces is a uniform embedding then the edistance between `f x` and `f y` is controlled in terms of the distance between `x` and `y`. In fact, this lemma holds for a `IsUniformInducing` map. TODO: generalize? -/ theorem controlled_of_isUniformEmbedding [PseudoEMetricSpace β] {f : α → β} (h : IsUniformEmbedding f) : (∀ ε > 0, ∃ ÎŽ > 0, ∀ {a b : α}, edist a b < ÎŽ → edist (f a) (f b) < ε) ∧ ∀ ÎŽ > 0, ∃ ε > 0, ∀ {a b : α}, edist (f a) (f b) < ε → edist a b < ÎŽ := ⟹uniformContinuous_iff.1 h.uniformContinuous, (isUniformEmbedding_iff.1 h).2.2⟩ /-- ε-ÎŽ characterization of Cauchy sequences on pseudoemetric spaces -/ protected theorem cauchy_iff {f : Filter α} : Cauchy f ↔ f ≠ ⊥ ∧ ∀ ε > 0, ∃ t ∈ f, ∀ x, x ∈ t → ∀ y, y ∈ t → edist x y < ε := by rw [← neBot_iff]; exact uniformity_basis_edist.cauchy_iff /-- A very useful criterion to show that a space is complete is to show that all sequences which satisfy a bound of the form `edist (u n) (u m) < B N` for all `n m ≥ N` are converging. This is often applied for `B N = 2^{-N}`, i.e., with a very fast convergence to `0`, which makes it possible to use arguments of converging series, while this is impossible to do in general for arbitrary Cauchy sequences. -/ theorem complete_of_convergent_controlled_sequences (B : ℕ → ℝ≥0∞) (hB : ∀ n, 0 < B n) (H : ∀ u : ℕ → α, (∀ N n m : ℕ, N ≀ n → N ≀ m → edist (u n) (u m) < B N) → ∃ x, Tendsto u atTop (𝓝 x)) : CompleteSpace α := UniformSpace.complete_of_convergent_controlled_sequences (fun n => { p : α × α | edist p.1 p.2 < B n }) (fun n => edist_mem_uniformity <| hB n) H /-- A sequentially complete pseudoemetric space is complete. -/ theorem complete_of_cauchySeq_tendsto : (∀ u : ℕ → α, CauchySeq u → ∃ a, Tendsto u atTop (𝓝 a)) → CompleteSpace α := UniformSpace.complete_of_cauchySeq_tendsto /-- Expressing locally uniform convergence on a set using `edist`. -/ theorem tendstoLocallyUniformlyOn_iff {ι : Type*} [TopologicalSpace β] {F : ι → β → α} {f : β → α} {p : Filter ι} {s : Set β} : TendstoLocallyUniformlyOn F f p s ↔ ∀ ε > 0, ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, ∀ᶠ n in p, ∀ y ∈ t, edist (f y) (F n y) < ε := by refine ⟹fun H ε hε => H _ (edist_mem_uniformity hε), fun H u hu x hx => ?_⟩ rcases mem_uniformity_edist.1 hu with ⟚ε, εpos, hε⟩ rcases H ε εpos x hx with ⟹t, ht, Ht⟩ exact ⟹t, ht, Ht.mono fun n hs x hx => hε (hs x hx)⟩ /-- Expressing uniform convergence on a set using `edist`. -/ theorem tendstoUniformlyOn_iff {ι : Type*} {F : ι → β → α} {f : β → α} {p : Filter ι} {s : Set β} : TendstoUniformlyOn F f p s ↔ ∀ ε > 0, ∀ᶠ n in p, ∀ x ∈ s, edist (f x) (F n x) < ε := by refine ⟹fun H ε hε => H _ (edist_mem_uniformity hε), fun H u hu => ?_⟩ rcases mem_uniformity_edist.1 hu with ⟚ε, εpos, hε⟩ exact (H ε εpos).mono fun n hs x hx => hε (hs x hx) /-- Expressing locally uniform convergence using `edist`. -/ theorem tendstoLocallyUniformly_iff {ι : Type*} [TopologicalSpace β] {F : ι → β → α} {f : β → α} {p : Filter ι} : TendstoLocallyUniformly F f p ↔ ∀ ε > 0, ∀ x : β, ∃ t ∈ 𝓝 x, ∀ᶠ n in p, ∀ y ∈ t, edist (f y) (F n y) < ε := by simp only [← tendstoLocallyUniformlyOn_univ, tendstoLocallyUniformlyOn_iff, mem_univ, forall_const, exists_prop, nhdsWithin_univ] /-- Expressing uniform convergence using `edist`. -/ theorem tendstoUniformly_iff {ι : Type*} {F : ι → β → α} {f : β → α} {p : Filter ι} : TendstoUniformly F f p ↔ ∀ ε > 0, ∀ᶠ n in p, ∀ x, edist (f x) (F n x) < ε := by simp only [← tendstoUniformlyOn_univ, tendstoUniformlyOn_iff, mem_univ, forall_const] end EMetric open EMetric namespace EMetric variable {x y z : α} {ε ε₁ ε₂ : ℝ≥0∞} {s t : Set α} theorem inseparable_iff : Inseparable x y ↔ edist x y = 0 := by simp [inseparable_iff_mem_closure, mem_closure_iff, edist_comm, forall_lt_iff_le'] alias ⟹_root_.Inseparable.edist_eq_zero, _⟩ := EMetric.inseparable_iff -- see Note [nolint_ge] /-- In a pseudoemetric space, Cauchy sequences are characterized by the fact that, eventually, the pseudoedistance between its elements is arbitrarily small -/ theorem cauchySeq_iff [Nonempty β] [SemilatticeSup β] {u : β → α} : CauchySeq u ↔ ∀ ε > 0, ∃ N, ∀ m, N ≀ m → ∀ n, N ≀ n → edist (u m) (u n) < ε := uniformity_basis_edist.cauchySeq_iff /-- A variation around the emetric characterization of Cauchy sequences -/ theorem cauchySeq_iff' [Nonempty β] [SemilatticeSup β] {u : β → α} : CauchySeq u ↔ ∀ ε > (0 : ℝ≥0∞), ∃ N, ∀ n ≥ N, edist (u n) (u N) < ε := uniformity_basis_edist.cauchySeq_iff' /-- A variation of the emetric characterization of Cauchy sequences that deals with `ℝ≥0` upper bounds. -/ theorem cauchySeq_iff_NNReal [Nonempty β] [SemilatticeSup β] {u : β → α} : CauchySeq u ↔ ∀ ε : ℝ≥0, 0 < ε → ∃ N, ∀ n, N ≀ n → edist (u n) (u N) < ε := uniformity_basis_edist_nnreal.cauchySeq_iff' theorem totallyBounded_iff {s : Set α} : TotallyBounded s ↔ ∀ ε > 0, ∃ t : Set α, t.Finite ∧ s ⊆ ⋃ y ∈ t, ball y ε := ⟹fun H _ε ε0 => H _ (edist_mem_uniformity ε0), fun H _r ru => let ⟚ε, ε0, hε⟩ := mem_uniformity_edist.1 ru let ⟹t, ft, h⟩ := H ε ε0 ⟹t, ft, h.trans <| iUnion₂_mono fun _ _ _ => hε⟩⟩ theorem totallyBounded_iff' {s : Set α} : TotallyBounded s ↔ ∀ ε > 0, ∃ t, t ⊆ s ∧ Set.Finite t ∧ s ⊆ ⋃ y ∈ t, ball y ε := ⟹fun H _ε ε0 => (totallyBounded_iff_subset.1 H) _ (edist_mem_uniformity ε0), fun H _r ru => let ⟚ε, ε0, hε⟩ := mem_uniformity_edist.1 ru let ⟹t, _, ft, h⟩ := H ε ε0 ⟹t, ft, h.trans <| iUnion₂_mono fun _ _ _ => hε⟩⟩ section Compact -- TODO: generalize to metrizable spaces /-- A compact set in a pseudo emetric space is separable, i.e., it is a subset of the closure of a countable set. -/ theorem subset_countable_closure_of_compact {s : Set α} (hs : IsCompact s) : ∃ t, t ⊆ s ∧ t.Countable ∧ s ⊆ closure t := by refine subset_countable_closure_of_almost_dense_set s fun ε hε => ?_ rcases totallyBounded_iff'.1 hs.totallyBounded ε hε with ⟹t, -, htf, hst⟩ exact ⟹t, htf.countable, hst.trans <| iUnion₂_mono fun _ _ => ball_subset_closedBall⟩ end Compact section SecondCountable open TopologicalSpace variable (α) in /-- A sigma compact pseudo emetric space has second countable topology. -/ instance (priority := 90) secondCountable_of_sigmaCompact [SigmaCompactSpace α] : SecondCountableTopology α := by suffices SeparableSpace α by exact UniformSpace.secondCountable_of_separable α choose T _ hTc hsubT using fun n => subset_countable_closure_of_compact (isCompact_compactCovering α n) refine ⟹⟹⋃ n, T n, countable_iUnion hTc, fun x => ?_⟩⟩ rcases iUnion_eq_univ_iff.1 (iUnion_compactCovering α) x with ⟹n, hn⟩ exact closure_mono (subset_iUnion _ n) (hsubT _ hn) theorem secondCountable_of_almost_dense_set (hs : ∀ ε > 0, ∃ t : Set α, t.Countable ∧ ⋃ x ∈ t, closedBall x ε = univ) : SecondCountableTopology α := by suffices SeparableSpace α from UniformSpace.secondCountable_of_separable α have : ∀ ε > 0, ∃ t : Set α, Set.Countable t ∧ univ ⊆ ⋃ x ∈ t, closedBall x ε := by simpa only [univ_subset_iff] using hs rcases subset_countable_closure_of_almost_dense_set (univ : Set α) this with ⟹t, -, htc, ht⟩ exact ⟹⟹t, htc, fun x => ht (mem_univ x)⟩⟩ end SecondCountable end EMetric variable {γ : Type w} [EMetricSpace γ] -- see Note [lower instance priority] /-- An emetric space is separated -/ instance (priority := 100) EMetricSpace.instT0Space : T0Space γ where t0 _ _ h := eq_of_edist_eq_zero <| inseparable_iff.1 h /-- A map between emetric spaces is a uniform embedding if and only if the edistance between `f x` and `f y` is controlled in terms of the distance between `x` and `y` and conversely. -/ theorem EMetric.isUniformEmbedding_iff' [PseudoEMetricSpace β] {f : γ → β} : IsUniformEmbedding f ↔ (∀ ε > 0, ∃ ÎŽ > 0, ∀ {a b : γ}, edist a b < ÎŽ → edist (f a) (f b) < ε) ∧ ∀ ÎŽ > 0, ∃ ε > 0, ∀ {a b : γ}, edist (f a) (f b) < ε → edist a b < ÎŽ := by rw [isUniformEmbedding_iff_isUniformInducing, isUniformInducing_iff, uniformContinuous_iff] /-- If a `PseudoEMetricSpace` is a T₀ space, then it is an `EMetricSpace`. -/ -- TODO: make it an instance? abbrev EMetricSpace.ofT0PseudoEMetricSpace (α : Type*) [PseudoEMetricSpace α] [T0Space α] : EMetricSpace α := { ‹PseudoEMetricSpace α› with eq_of_edist_eq_zero := fun h => (EMetric.inseparable_iff.2 h).eq } /-- The product of two emetric spaces, with the max distance, is an extended metric spaces. We make sure that the uniform structure thus constructed is the one corresponding to the product of uniform spaces, to avoid diamond problems. -/ instance Prod.emetricSpaceMax [EMetricSpace β] : EMetricSpace (γ × β) := .ofT0PseudoEMetricSpace _ namespace EMetric /-- A compact set in an emetric space is separable, i.e., it is the closure of a countable set. -/ theorem countable_closure_of_compact {s : Set γ} (hs : IsCompact s) : ∃ t, t ⊆ s ∧ t.Countable ∧ s = closure t := by rcases subset_countable_closure_of_compact hs with ⟹t, hts, htc, hsub⟩ exact ⟹t, hts, htc, hsub.antisymm (closure_minimal hts hs.isClosed)⟩ end EMetric /-! ### Separation quotient -/ instance [PseudoEMetricSpace X] : EDist (SeparationQuotient X) where edist := SeparationQuotient.lift₂ edist fun _ _ _ _ hx hy => edist_congr (EMetric.inseparable_iff.1 hx) (EMetric.inseparable_iff.1 hy) @[simp] theorem SeparationQuotient.edist_mk [PseudoEMetricSpace X] (x y : X) : edist (mk x) (mk y) = edist x y := rfl open SeparationQuotient in instance [PseudoEMetricSpace X] : EMetricSpace (SeparationQuotient X) := @EMetricSpace.ofT0PseudoEMetricSpace (SeparationQuotient X) { edist_self := surjective_mk.forall.2 edist_self, edist_comm := surjective_mk.forall₂.2 edist_comm, edist_triangle := surjective_mk.forall₃.2 edist_triangle, toUniformSpace := inferInstance, uniformity_edist := comap_injective (surjective_mk.prodMap surjective_mk) <| by simp [comap_mk_uniformity, PseudoEMetricSpace.uniformity_edist] } _ namespace TopologicalSpace section Compact open Topology /-- If a set `s` is separable in a (pseudo extended) metric space, then it admits a countable dense subset. This is not obvious, as the countable set whose closure covers `s` given by the definition of separability does not need in general to be contained in `s`. -/ theorem IsSeparable.exists_countable_dense_subset {s : Set α} (hs : IsSeparable s) : ∃ t, t ⊆ s ∧ t.Countable ∧ s ⊆ closure t := by have : ∀ ε > 0, ∃ t : Set α, t.Countable ∧ s ⊆ ⋃ x ∈ t, closedBall x ε := fun ε ε0 => by rcases hs with ⟹t, htc, hst⟩ refine ⟹t, htc, hst.trans fun x hx => ?_⟩ rcases mem_closure_iff.1 hx ε ε0 with ⟹y, hyt, hxy⟩ exact mem_iUnion₂.2 ⟹y, hyt, mem_closedBall.2 hxy.le⟩ exact subset_countable_closure_of_almost_dense_set _ this /-- If a set `s` is separable, then the corresponding subtype is separable in a (pseudo extended) metric space. This is not obvious, as the countable set whose closure covers `s` does not need in general to be contained in `s`. -/ theorem IsSeparable.separableSpace {s : Set α} (hs : IsSeparable s) : SeparableSpace s := by rcases hs.exists_countable_dense_subset with ⟹t, hts, htc, hst⟩ lift t to Set s using hts refine ⟹⟹t, countable_of_injective_of_countable_image Subtype.coe_injective.injOn htc, ?_⟩⟩ rwa [IsInducing.subtypeVal.dense_iff, Subtype.forall] end Compact end TopologicalSpace section LebesgueNumberLemma variable {s : Set α} theorem lebesgue_number_lemma_of_emetric {ι : Sort*} {c : ι → Set α} (hs : IsCompact s) (hc₁ : ∀ i, IsOpen (c i)) (hc₂ : s ⊆ ⋃ i, c i) : ∃ ÎŽ > 0, ∀ x ∈ s, ∃ i, ball x ÎŽ ⊆ c i := by simpa only [ball, UniformSpace.ball, preimage_setOf_eq, edist_comm] using uniformity_basis_edist.lebesgue_number_lemma hs hc₁ hc₂ theorem lebesgue_number_lemma_of_emetric_nhds' {c : (x : α) → x ∈ s → Set α} (hs : IsCompact s) (hc : ∀ x hx, c x hx ∈ 𝓝 x) : ∃ ÎŽ > 0, ∀ x ∈ s, ∃ y : s, ball x ÎŽ ⊆ c y y.2 := by simpa only [ball, UniformSpace.ball, preimage_setOf_eq, edist_comm] using uniformity_basis_edist.lebesgue_number_lemma_nhds' hs hc theorem lebesgue_number_lemma_of_emetric_nhds {c : α → Set α} (hs : IsCompact s) (hc : ∀ x ∈ s, c x ∈ 𝓝 x) : ∃ ÎŽ > 0, ∀ x ∈ s, ∃ y, ball x ÎŽ ⊆ c y := by simpa only [ball, UniformSpace.ball, preimage_setOf_eq, edist_comm] using uniformity_basis_edist.lebesgue_number_lemma_nhds hs hc theorem lebesgue_number_lemma_of_emetric_nhdsWithin' {c : (x : α) → x ∈ s → Set α} (hs : IsCompact s) (hc : ∀ x hx, c x hx ∈ 𝓝[s] x) : ∃ ÎŽ > 0, ∀ x ∈ s, ∃ y : s, ball x ÎŽ ∩ s ⊆ c y y.2 := by simpa only [ball, UniformSpace.ball, preimage_setOf_eq, edist_comm] using uniformity_basis_edist.lebesgue_number_lemma_nhdsWithin' hs hc theorem lebesgue_number_lemma_of_emetric_nhdsWithin {c : α → Set α} (hs : IsCompact s) (hc : ∀ x ∈ s, c x ∈ 𝓝[s] x) : ∃ ÎŽ > 0, ∀ x ∈ s, ∃ y, ball x ÎŽ ∩ s ⊆ c y := by simpa only [ball, UniformSpace.ball, preimage_setOf_eq, edist_comm] using uniformity_basis_edist.lebesgue_number_lemma_nhdsWithin hs hc theorem lebesgue_number_lemma_of_emetric_sUnion {c : Set (Set α)} (hs : IsCompact s) (hc₁ : ∀ t ∈ c, IsOpen t) (hc₂ : s ⊆ ⋃₀ c) : ∃ ÎŽ > 0, ∀ x ∈ s, ∃ t ∈ c, ball x ÎŽ ⊆ t := by rw [sUnion_eq_iUnion] at hc₂; simpa using lebesgue_number_lemma_of_emetric hs (by simpa) hc₂ end LebesgueNumberLemma
Mathlib/Topology/EMetricSpace/Basic.lean
963
965
/- Copyright (c) 2019 Kevin Kappelmann. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Kappelmann, Kyle Miller, Mario Carneiro -/ import Mathlib.Data.Finset.NatAntidiagonal import Mathlib.Data.Nat.GCD.Basic import Mathlib.Data.Nat.BinaryRec import Mathlib.Logic.Function.Iterate import Mathlib.Tactic.Ring import Mathlib.Tactic.Zify import Mathlib.Data.Nat.Choose.Basic import Mathlib.Algebra.BigOperators.Group.Finset.Basic /-! # Fibonacci Numbers This file defines the fibonacci series, proves results about it and introduces methods to compute it quickly. -/ /-! # The Fibonacci Sequence ## Summary Definition of the Fibonacci sequence `F₀ = 0, F₁ = 1, Fₙ₊₂ = Fₙ + Fₙ₊₁`. ## Main Definitions - `Nat.fib` returns the stream of Fibonacci numbers. ## Main Statements - `Nat.fib_add_two`: shows that `fib` indeed satisfies the Fibonacci recurrence `Fₙ₊₂ = Fₙ + Fₙ₊₁.`. - `Nat.fib_gcd`: `fib n` is a strong divisibility sequence. - `Nat.fib_succ_eq_sum_choose`: `fib` is given by the sum of `Nat.choose` along an antidiagonal. - `Nat.fib_succ_eq_succ_sum`: shows that `F₀ + F₁ + ⋯ + Fₙ = Fₙ₊₂ - 1`. - `Nat.fib_two_mul` and `Nat.fib_two_mul_add_one` are the basis for an efficient algorithm to compute `fib` (see `Nat.fastFib`). ## Implementation Notes For efficiency purposes, the sequence is defined using `Stream.iterate`. ## Tags fib, fibonacci -/ namespace Nat /-- Implementation of the fibonacci sequence satisfying `fib 0 = 0, fib 1 = 1, fib (n + 2) = fib n + fib (n + 1)`. *Note:* We use a stream iterator for better performance when compared to the naive recursive implementation. -/ @[pp_nodot] def fib (n : ℕ) : ℕ := ((fun p : ℕ × ℕ => (p.snd, p.fst + p.snd))^[n] (0, 1)).fst @[simp] theorem fib_zero : fib 0 = 0 := rfl @[simp] theorem fib_one : fib 1 = 1 := rfl @[simp] theorem fib_two : fib 2 = 1 := rfl /-- Shows that `fib` indeed satisfies the Fibonacci recurrence `Fₙ₊₂ = Fₙ + Fₙ₊₁.` -/ theorem fib_add_two {n : ℕ} : fib (n + 2) = fib n + fib (n + 1) := by simp [fib, Function.iterate_succ_apply'] lemma fib_add_one : ∀ {n}, n ≠ 0 → fib (n + 1) = fib (n - 1) + fib n | _n + 1, _ => fib_add_two theorem fib_le_fib_succ {n : ℕ} : fib n ≀ fib (n + 1) := by cases n <;> simp [fib_add_two] @[mono] theorem fib_mono : Monotone fib := monotone_nat_of_le_succ fun _ => fib_le_fib_succ @[simp] lemma fib_eq_zero : ∀ {n}, fib n = 0 ↔ n = 0 | 0 => Iff.rfl | 1 => Iff.rfl | n + 2 => by simp [fib_add_two, fib_eq_zero] @[simp] lemma fib_pos {n : ℕ} : 0 < fib n ↔ 0 < n := by simp [pos_iff_ne_zero] theorem fib_add_two_sub_fib_add_one {n : ℕ} : fib (n + 2) - fib (n + 1) = fib n := by rw [fib_add_two, add_tsub_cancel_right] theorem fib_lt_fib_succ {n : ℕ} (hn : 2 ≀ n) : fib n < fib (n + 1) := by rcases exists_add_of_le hn with ⟹n, rfl⟩ rw [← tsub_pos_iff_lt, add_comm 2, add_right_comm, fib_add_two, add_tsub_cancel_right, fib_pos] exact succ_pos n
/-- `fib (n + 2)` is strictly monotone. -/
Mathlib/Data/Nat/Fib/Basic.lean
106
106
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson -/ import Mathlib.Order.Monotone.Odd import Mathlib.Analysis.Calculus.LogDeriv import Mathlib.Analysis.SpecialFunctions.ExpDeriv import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic import Mathlib.Analysis.Calculus.Deriv.MeanValue /-! # Differentiability of trigonometric functions ## Main statements The differentiability of the usual trigonometric functions is proved, and their derivatives are computed. ## Tags sin, cos, tan, angle -/ noncomputable section open scoped Topology Filter open Set namespace Complex /-- The complex sine function is everywhere strictly differentiable, with the derivative `cos x`. -/ theorem hasStrictDerivAt_sin (x : ℂ) : HasStrictDerivAt sin (cos x) x := by simp only [cos, div_eq_mul_inv] convert ((((hasStrictDerivAt_id x).neg.mul_const I).cexp.sub ((hasStrictDerivAt_id x).mul_const I).cexp).mul_const I).mul_const (2 : ℂ)⁻¹ using 1 simp only [Function.comp, id] rw [sub_mul, mul_assoc, mul_assoc, I_mul_I, neg_one_mul, neg_neg, mul_one, one_mul, mul_assoc, I_mul_I, mul_neg_one, sub_neg_eq_add, add_comm] /-- The complex sine function is everywhere differentiable, with the derivative `cos x`. -/ theorem hasDerivAt_sin (x : ℂ) : HasDerivAt sin (cos x) x := (hasStrictDerivAt_sin x).hasDerivAt theorem contDiff_sin {n} : ContDiff ℂ n sin := (((contDiff_neg.mul contDiff_const).cexp.sub (contDiff_id.mul contDiff_const).cexp).mul contDiff_const).div_const _ @[simp] theorem differentiable_sin : Differentiable ℂ sin := fun x => (hasDerivAt_sin x).differentiableAt @[simp] theorem differentiableAt_sin {x : ℂ} : DifferentiableAt ℂ sin x := differentiable_sin x @[simp] theorem deriv_sin : deriv sin = cos := funext fun x => (hasDerivAt_sin x).deriv /-- The complex cosine function is everywhere strictly differentiable, with the derivative `-sin x`. -/ theorem hasStrictDerivAt_cos (x : ℂ) : HasStrictDerivAt cos (-sin x) x := by simp only [sin, div_eq_mul_inv, neg_mul_eq_neg_mul] convert (((hasStrictDerivAt_id x).mul_const I).cexp.add ((hasStrictDerivAt_id x).neg.mul_const I).cexp).mul_const (2 : ℂ)⁻¹ using 1 simp only [Function.comp, id] ring /-- The complex cosine function is everywhere differentiable, with the derivative `-sin x`. -/ theorem hasDerivAt_cos (x : ℂ) : HasDerivAt cos (-sin x) x := (hasStrictDerivAt_cos x).hasDerivAt theorem contDiff_cos {n} : ContDiff ℂ n cos := ((contDiff_id.mul contDiff_const).cexp.add (contDiff_neg.mul contDiff_const).cexp).div_const _ @[simp] theorem differentiable_cos : Differentiable ℂ cos := fun x => (hasDerivAt_cos x).differentiableAt @[simp] theorem differentiableAt_cos {x : ℂ} : DifferentiableAt ℂ cos x := differentiable_cos x theorem deriv_cos {x : ℂ} : deriv cos x = -sin x := (hasDerivAt_cos x).deriv @[simp] theorem deriv_cos' : deriv cos = fun x => -sin x := funext fun _ => deriv_cos /-- The complex hyperbolic sine function is everywhere strictly differentiable, with the derivative `cosh x`. -/ theorem hasStrictDerivAt_sinh (x : ℂ) : HasStrictDerivAt sinh (cosh x) x := by simp only [cosh, div_eq_mul_inv] convert ((hasStrictDerivAt_exp x).sub (hasStrictDerivAt_id x).neg.cexp).mul_const (2 : ℂ)⁻¹ using 1 rw [id, mul_neg_one, sub_eq_add_neg, neg_neg] /-- The complex hyperbolic sine function is everywhere differentiable, with the derivative `cosh x`. -/ theorem hasDerivAt_sinh (x : ℂ) : HasDerivAt sinh (cosh x) x := (hasStrictDerivAt_sinh x).hasDerivAt theorem contDiff_sinh {n} : ContDiff ℂ n sinh := (contDiff_exp.sub contDiff_neg.cexp).div_const _ @[simp] theorem differentiable_sinh : Differentiable ℂ sinh := fun x => (hasDerivAt_sinh x).differentiableAt @[simp] theorem differentiableAt_sinh {x : ℂ} : DifferentiableAt ℂ sinh x := differentiable_sinh x @[simp] theorem deriv_sinh : deriv sinh = cosh := funext fun x => (hasDerivAt_sinh x).deriv /-- The complex hyperbolic cosine function is everywhere strictly differentiable, with the derivative `sinh x`. -/ theorem hasStrictDerivAt_cosh (x : ℂ) : HasStrictDerivAt cosh (sinh x) x := by simp only [sinh, div_eq_mul_inv] convert ((hasStrictDerivAt_exp x).add (hasStrictDerivAt_id x).neg.cexp).mul_const (2 : ℂ)⁻¹ using 1 rw [id, mul_neg_one, sub_eq_add_neg] /-- The complex hyperbolic cosine function is everywhere differentiable, with the derivative `sinh x`. -/ theorem hasDerivAt_cosh (x : ℂ) : HasDerivAt cosh (sinh x) x := (hasStrictDerivAt_cosh x).hasDerivAt theorem contDiff_cosh {n} : ContDiff ℂ n cosh := (contDiff_exp.add contDiff_neg.cexp).div_const _ @[simp] theorem differentiable_cosh : Differentiable ℂ cosh := fun x => (hasDerivAt_cosh x).differentiableAt @[simp] theorem differentiableAt_cosh {x : ℂ} : DifferentiableAt ℂ cosh x := differentiable_cosh x @[simp] theorem deriv_cosh : deriv cosh = sinh := funext fun x => (hasDerivAt_cosh x).deriv end Complex section /-! ### Simp lemmas for derivatives of `fun x => Complex.cos (f x)` etc., `f : ℂ → ℂ` -/ variable {f : ℂ → ℂ} {f' x : ℂ} {s : Set ℂ} /-! #### `Complex.cos` -/ theorem HasStrictDerivAt.ccos (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) * f') x := (Complex.hasStrictDerivAt_cos (f x)).comp x hf theorem HasDerivAt.ccos (hf : HasDerivAt f f' x) : HasDerivAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) * f') x := (Complex.hasDerivAt_cos (f x)).comp x hf theorem HasDerivWithinAt.ccos (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) * f') s x := (Complex.hasDerivAt_cos (f x)).comp_hasDerivWithinAt x hf theorem derivWithin_ccos (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) : derivWithin (fun x => Complex.cos (f x)) s x = -Complex.sin (f x) * derivWithin f s x := hf.hasDerivWithinAt.ccos.derivWithin hxs @[simp] theorem deriv_ccos (hc : DifferentiableAt ℂ f x) : deriv (fun x => Complex.cos (f x)) x = -Complex.sin (f x) * deriv f x := hc.hasDerivAt.ccos.deriv /-! #### `Complex.sin` -/ theorem HasStrictDerivAt.csin (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun x => Complex.sin (f x)) (Complex.cos (f x) * f') x := (Complex.hasStrictDerivAt_sin (f x)).comp x hf theorem HasDerivAt.csin (hf : HasDerivAt f f' x) : HasDerivAt (fun x => Complex.sin (f x)) (Complex.cos (f x) * f') x := (Complex.hasDerivAt_sin (f x)).comp x hf theorem HasDerivWithinAt.csin (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun x => Complex.sin (f x)) (Complex.cos (f x) * f') s x := (Complex.hasDerivAt_sin (f x)).comp_hasDerivWithinAt x hf theorem derivWithin_csin (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) : derivWithin (fun x => Complex.sin (f x)) s x = Complex.cos (f x) * derivWithin f s x := hf.hasDerivWithinAt.csin.derivWithin hxs @[simp] theorem deriv_csin (hc : DifferentiableAt ℂ f x) : deriv (fun x => Complex.sin (f x)) x = Complex.cos (f x) * deriv f x := hc.hasDerivAt.csin.deriv /-! #### `Complex.cosh` -/ theorem HasStrictDerivAt.ccosh (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) * f') x := (Complex.hasStrictDerivAt_cosh (f x)).comp x hf theorem HasDerivAt.ccosh (hf : HasDerivAt f f' x) : HasDerivAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) * f') x := (Complex.hasDerivAt_cosh (f x)).comp x hf theorem HasDerivWithinAt.ccosh (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) * f') s x := (Complex.hasDerivAt_cosh (f x)).comp_hasDerivWithinAt x hf theorem derivWithin_ccosh (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) : derivWithin (fun x => Complex.cosh (f x)) s x = Complex.sinh (f x) * derivWithin f s x := hf.hasDerivWithinAt.ccosh.derivWithin hxs @[simp] theorem deriv_ccosh (hc : DifferentiableAt ℂ f x) : deriv (fun x => Complex.cosh (f x)) x = Complex.sinh (f x) * deriv f x := hc.hasDerivAt.ccosh.deriv /-! #### `Complex.sinh` -/ theorem HasStrictDerivAt.csinh (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) * f') x := (Complex.hasStrictDerivAt_sinh (f x)).comp x hf theorem HasDerivAt.csinh (hf : HasDerivAt f f' x) : HasDerivAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) * f') x := (Complex.hasDerivAt_sinh (f x)).comp x hf theorem HasDerivWithinAt.csinh (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) * f') s x := (Complex.hasDerivAt_sinh (f x)).comp_hasDerivWithinAt x hf theorem derivWithin_csinh (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) : derivWithin (fun x => Complex.sinh (f x)) s x = Complex.cosh (f x) * derivWithin f s x := hf.hasDerivWithinAt.csinh.derivWithin hxs @[simp] theorem deriv_csinh (hc : DifferentiableAt ℂ f x) : deriv (fun x => Complex.sinh (f x)) x = Complex.cosh (f x) * deriv f x := hc.hasDerivAt.csinh.deriv end section /-! ### Simp lemmas for derivatives of `fun x => Complex.cos (f x)` etc., `f : E → ℂ` -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f : E → ℂ} {f' : E →L[ℂ] ℂ} {x : E} {s : Set E} /-! #### `Complex.cos` -/ theorem HasStrictFDerivAt.ccos (hf : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) • f') x := (Complex.hasStrictDerivAt_cos (f x)).comp_hasStrictFDerivAt x hf theorem HasFDerivAt.ccos (hf : HasFDerivAt f f' x) : HasFDerivAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) • f') x := (Complex.hasDerivAt_cos (f x)).comp_hasFDerivAt x hf theorem HasFDerivWithinAt.ccos (hf : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) • f') s x := (Complex.hasDerivAt_cos (f x)).comp_hasFDerivWithinAt x hf theorem DifferentiableWithinAt.ccos (hf : DifferentiableWithinAt ℂ f s x) : DifferentiableWithinAt ℂ (fun x => Complex.cos (f x)) s x := hf.hasFDerivWithinAt.ccos.differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.ccos (hc : DifferentiableAt ℂ f x) : DifferentiableAt ℂ (fun x => Complex.cos (f x)) x := hc.hasFDerivAt.ccos.differentiableAt theorem DifferentiableOn.ccos (hc : DifferentiableOn ℂ f s) : DifferentiableOn ℂ (fun x => Complex.cos (f x)) s := fun x h => (hc x h).ccos @[simp, fun_prop] theorem Differentiable.ccos (hc : Differentiable ℂ f) : Differentiable ℂ fun x => Complex.cos (f x) := fun x => (hc x).ccos theorem fderivWithin_ccos (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) : fderivWithin ℂ (fun x => Complex.cos (f x)) s x = -Complex.sin (f x) • fderivWithin ℂ f s x := hf.hasFDerivWithinAt.ccos.fderivWithin hxs @[simp] theorem fderiv_ccos (hc : DifferentiableAt ℂ f x) : fderiv ℂ (fun x => Complex.cos (f x)) x = -Complex.sin (f x) • fderiv ℂ f x := hc.hasFDerivAt.ccos.fderiv theorem ContDiff.ccos {n} (h : ContDiff ℂ n f) : ContDiff ℂ n fun x => Complex.cos (f x) := Complex.contDiff_cos.comp h theorem ContDiffAt.ccos {n} (hf : ContDiffAt ℂ n f x) : ContDiffAt ℂ n (fun x => Complex.cos (f x)) x := Complex.contDiff_cos.contDiffAt.comp x hf theorem ContDiffOn.ccos {n} (hf : ContDiffOn ℂ n f s) : ContDiffOn ℂ n (fun x => Complex.cos (f x)) s := Complex.contDiff_cos.comp_contDiffOn hf theorem ContDiffWithinAt.ccos {n} (hf : ContDiffWithinAt ℂ n f s x) : ContDiffWithinAt ℂ n (fun x => Complex.cos (f x)) s x := Complex.contDiff_cos.contDiffAt.comp_contDiffWithinAt x hf /-! #### `Complex.sin` -/ theorem HasStrictFDerivAt.csin (hf : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (fun x => Complex.sin (f x)) (Complex.cos (f x) • f') x := (Complex.hasStrictDerivAt_sin (f x)).comp_hasStrictFDerivAt x hf theorem HasFDerivAt.csin (hf : HasFDerivAt f f' x) : HasFDerivAt (fun x => Complex.sin (f x)) (Complex.cos (f x) • f') x := (Complex.hasDerivAt_sin (f x)).comp_hasFDerivAt x hf theorem HasFDerivWithinAt.csin (hf : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (fun x => Complex.sin (f x)) (Complex.cos (f x) • f') s x := (Complex.hasDerivAt_sin (f x)).comp_hasFDerivWithinAt x hf theorem DifferentiableWithinAt.csin (hf : DifferentiableWithinAt ℂ f s x) : DifferentiableWithinAt ℂ (fun x => Complex.sin (f x)) s x := hf.hasFDerivWithinAt.csin.differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.csin (hc : DifferentiableAt ℂ f x) : DifferentiableAt ℂ (fun x => Complex.sin (f x)) x := hc.hasFDerivAt.csin.differentiableAt theorem DifferentiableOn.csin (hc : DifferentiableOn ℂ f s) : DifferentiableOn ℂ (fun x => Complex.sin (f x)) s := fun x h => (hc x h).csin @[simp, fun_prop] theorem Differentiable.csin (hc : Differentiable ℂ f) : Differentiable ℂ fun x => Complex.sin (f x) := fun x => (hc x).csin theorem fderivWithin_csin (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) : fderivWithin ℂ (fun x => Complex.sin (f x)) s x = Complex.cos (f x) • fderivWithin ℂ f s x := hf.hasFDerivWithinAt.csin.fderivWithin hxs @[simp] theorem fderiv_csin (hc : DifferentiableAt ℂ f x) : fderiv ℂ (fun x => Complex.sin (f x)) x = Complex.cos (f x) • fderiv ℂ f x := hc.hasFDerivAt.csin.fderiv theorem ContDiff.csin {n} (h : ContDiff ℂ n f) : ContDiff ℂ n fun x => Complex.sin (f x) := Complex.contDiff_sin.comp h theorem ContDiffAt.csin {n} (hf : ContDiffAt ℂ n f x) : ContDiffAt ℂ n (fun x => Complex.sin (f x)) x := Complex.contDiff_sin.contDiffAt.comp x hf theorem ContDiffOn.csin {n} (hf : ContDiffOn ℂ n f s) : ContDiffOn ℂ n (fun x => Complex.sin (f x)) s := Complex.contDiff_sin.comp_contDiffOn hf theorem ContDiffWithinAt.csin {n} (hf : ContDiffWithinAt ℂ n f s x) : ContDiffWithinAt ℂ n (fun x => Complex.sin (f x)) s x := Complex.contDiff_sin.contDiffAt.comp_contDiffWithinAt x hf /-! #### `Complex.cosh` -/ theorem HasStrictFDerivAt.ccosh (hf : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) • f') x := (Complex.hasStrictDerivAt_cosh (f x)).comp_hasStrictFDerivAt x hf theorem HasFDerivAt.ccosh (hf : HasFDerivAt f f' x) : HasFDerivAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) • f') x := (Complex.hasDerivAt_cosh (f x)).comp_hasFDerivAt x hf theorem HasFDerivWithinAt.ccosh (hf : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) • f') s x := (Complex.hasDerivAt_cosh (f x)).comp_hasFDerivWithinAt x hf theorem DifferentiableWithinAt.ccosh (hf : DifferentiableWithinAt ℂ f s x) : DifferentiableWithinAt ℂ (fun x => Complex.cosh (f x)) s x := hf.hasFDerivWithinAt.ccosh.differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.ccosh (hc : DifferentiableAt ℂ f x) : DifferentiableAt ℂ (fun x => Complex.cosh (f x)) x := hc.hasFDerivAt.ccosh.differentiableAt theorem DifferentiableOn.ccosh (hc : DifferentiableOn ℂ f s) : DifferentiableOn ℂ (fun x => Complex.cosh (f x)) s := fun x h => (hc x h).ccosh @[simp, fun_prop] theorem Differentiable.ccosh (hc : Differentiable ℂ f) : Differentiable ℂ fun x => Complex.cosh (f x) := fun x => (hc x).ccosh theorem fderivWithin_ccosh (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) : fderivWithin ℂ (fun x => Complex.cosh (f x)) s x = Complex.sinh (f x) • fderivWithin ℂ f s x := hf.hasFDerivWithinAt.ccosh.fderivWithin hxs @[simp] theorem fderiv_ccosh (hc : DifferentiableAt ℂ f x) : fderiv ℂ (fun x => Complex.cosh (f x)) x = Complex.sinh (f x) • fderiv ℂ f x := hc.hasFDerivAt.ccosh.fderiv theorem ContDiff.ccosh {n} (h : ContDiff ℂ n f) : ContDiff ℂ n fun x => Complex.cosh (f x) := Complex.contDiff_cosh.comp h theorem ContDiffAt.ccosh {n} (hf : ContDiffAt ℂ n f x) : ContDiffAt ℂ n (fun x => Complex.cosh (f x)) x := Complex.contDiff_cosh.contDiffAt.comp x hf theorem ContDiffOn.ccosh {n} (hf : ContDiffOn ℂ n f s) : ContDiffOn ℂ n (fun x => Complex.cosh (f x)) s := Complex.contDiff_cosh.comp_contDiffOn hf theorem ContDiffWithinAt.ccosh {n} (hf : ContDiffWithinAt ℂ n f s x) : ContDiffWithinAt ℂ n (fun x => Complex.cosh (f x)) s x := Complex.contDiff_cosh.contDiffAt.comp_contDiffWithinAt x hf /-! #### `Complex.sinh` -/ theorem HasStrictFDerivAt.csinh (hf : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) • f') x := (Complex.hasStrictDerivAt_sinh (f x)).comp_hasStrictFDerivAt x hf theorem HasFDerivAt.csinh (hf : HasFDerivAt f f' x) : HasFDerivAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) • f') x := (Complex.hasDerivAt_sinh (f x)).comp_hasFDerivAt x hf theorem HasFDerivWithinAt.csinh (hf : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) • f') s x := (Complex.hasDerivAt_sinh (f x)).comp_hasFDerivWithinAt x hf theorem DifferentiableWithinAt.csinh (hf : DifferentiableWithinAt ℂ f s x) : DifferentiableWithinAt ℂ (fun x => Complex.sinh (f x)) s x := hf.hasFDerivWithinAt.csinh.differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.csinh (hc : DifferentiableAt ℂ f x) : DifferentiableAt ℂ (fun x => Complex.sinh (f x)) x := hc.hasFDerivAt.csinh.differentiableAt theorem DifferentiableOn.csinh (hc : DifferentiableOn ℂ f s) : DifferentiableOn ℂ (fun x => Complex.sinh (f x)) s := fun x h => (hc x h).csinh @[simp, fun_prop] theorem Differentiable.csinh (hc : Differentiable ℂ f) : Differentiable ℂ fun x => Complex.sinh (f x) := fun x => (hc x).csinh theorem fderivWithin_csinh (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) : fderivWithin ℂ (fun x => Complex.sinh (f x)) s x = Complex.cosh (f x) • fderivWithin ℂ f s x := hf.hasFDerivWithinAt.csinh.fderivWithin hxs @[simp] theorem fderiv_csinh (hc : DifferentiableAt ℂ f x) : fderiv ℂ (fun x => Complex.sinh (f x)) x = Complex.cosh (f x) • fderiv ℂ f x := hc.hasFDerivAt.csinh.fderiv theorem ContDiff.csinh {n} (h : ContDiff ℂ n f) : ContDiff ℂ n fun x => Complex.sinh (f x) := Complex.contDiff_sinh.comp h theorem ContDiffAt.csinh {n} (hf : ContDiffAt ℂ n f x) : ContDiffAt ℂ n (fun x => Complex.sinh (f x)) x := Complex.contDiff_sinh.contDiffAt.comp x hf theorem ContDiffOn.csinh {n} (hf : ContDiffOn ℂ n f s) : ContDiffOn ℂ n (fun x => Complex.sinh (f x)) s := Complex.contDiff_sinh.comp_contDiffOn hf theorem ContDiffWithinAt.csinh {n} (hf : ContDiffWithinAt ℂ n f s x) : ContDiffWithinAt ℂ n (fun x => Complex.sinh (f x)) s x := Complex.contDiff_sinh.contDiffAt.comp_contDiffWithinAt x hf end namespace Real variable {x y z : ℝ} theorem hasStrictDerivAt_sin (x : ℝ) : HasStrictDerivAt sin (cos x) x := (Complex.hasStrictDerivAt_sin x).real_of_complex theorem hasDerivAt_sin (x : ℝ) : HasDerivAt sin (cos x) x := (hasStrictDerivAt_sin x).hasDerivAt theorem contDiff_sin {n} : ContDiff ℝ n sin := Complex.contDiff_sin.real_of_complex @[simp] theorem differentiable_sin : Differentiable ℝ sin := fun x => (hasDerivAt_sin x).differentiableAt @[simp] theorem differentiableAt_sin : DifferentiableAt ℝ sin x := differentiable_sin x @[simp] theorem deriv_sin : deriv sin = cos := funext fun x => (hasDerivAt_sin x).deriv theorem hasStrictDerivAt_cos (x : ℝ) : HasStrictDerivAt cos (-sin x) x := (Complex.hasStrictDerivAt_cos x).real_of_complex theorem hasDerivAt_cos (x : ℝ) : HasDerivAt cos (-sin x) x := (Complex.hasDerivAt_cos x).real_of_complex theorem contDiff_cos {n} : ContDiff ℝ n cos := Complex.contDiff_cos.real_of_complex @[simp] theorem differentiable_cos : Differentiable ℝ cos := fun x => (hasDerivAt_cos x).differentiableAt @[simp] theorem differentiableAt_cos : DifferentiableAt ℝ cos x := differentiable_cos x theorem deriv_cos : deriv cos x = -sin x := (hasDerivAt_cos x).deriv @[simp] theorem deriv_cos' : deriv cos = fun x => -sin x := funext fun _ => deriv_cos theorem hasStrictDerivAt_sinh (x : ℝ) : HasStrictDerivAt sinh (cosh x) x := (Complex.hasStrictDerivAt_sinh x).real_of_complex theorem hasDerivAt_sinh (x : ℝ) : HasDerivAt sinh (cosh x) x := (Complex.hasDerivAt_sinh x).real_of_complex theorem contDiff_sinh {n} : ContDiff ℝ n sinh := Complex.contDiff_sinh.real_of_complex @[simp] theorem differentiable_sinh : Differentiable ℝ sinh := fun x => (hasDerivAt_sinh x).differentiableAt @[simp] theorem differentiableAt_sinh : DifferentiableAt ℝ sinh x := differentiable_sinh x @[simp] theorem deriv_sinh : deriv sinh = cosh := funext fun x => (hasDerivAt_sinh x).deriv theorem hasStrictDerivAt_cosh (x : ℝ) : HasStrictDerivAt cosh (sinh x) x := (Complex.hasStrictDerivAt_cosh x).real_of_complex theorem hasDerivAt_cosh (x : ℝ) : HasDerivAt cosh (sinh x) x := (Complex.hasDerivAt_cosh x).real_of_complex theorem contDiff_cosh {n} : ContDiff ℝ n cosh := Complex.contDiff_cosh.real_of_complex @[simp] theorem differentiable_cosh : Differentiable ℝ cosh := fun x => (hasDerivAt_cosh x).differentiableAt @[simp] theorem differentiableAt_cosh : DifferentiableAt ℝ cosh x := differentiable_cosh x @[simp] theorem deriv_cosh : deriv cosh = sinh := funext fun x => (hasDerivAt_cosh x).deriv /-- `sinh` is strictly monotone. -/ theorem sinh_strictMono : StrictMono sinh := strictMono_of_deriv_pos <| by rw [Real.deriv_sinh]; exact cosh_pos /-- `sinh` is injective, `∀ a b, sinh a = sinh b → a = b`. -/ theorem sinh_injective : Function.Injective sinh := sinh_strictMono.injective @[simp] theorem sinh_inj : sinh x = sinh y ↔ x = y := sinh_injective.eq_iff @[simp] theorem sinh_le_sinh : sinh x ≀ sinh y ↔ x ≀ y := sinh_strictMono.le_iff_le @[simp] theorem sinh_lt_sinh : sinh x < sinh y ↔ x < y := sinh_strictMono.lt_iff_lt @[simp] lemma sinh_eq_zero : sinh x = 0 ↔ x = 0 := by rw [← @sinh_inj x, sinh_zero] lemma sinh_ne_zero : sinh x ≠ 0 ↔ x ≠ 0 := sinh_eq_zero.not @[simp] theorem sinh_pos_iff : 0 < sinh x ↔ 0 < x := by simpa only [sinh_zero] using @sinh_lt_sinh 0 x @[simp] theorem sinh_nonpos_iff : sinh x ≀ 0 ↔ x ≀ 0 := by simpa only [sinh_zero] using @sinh_le_sinh x 0 @[simp] theorem sinh_neg_iff : sinh x < 0 ↔ x < 0 := by simpa only [sinh_zero] using @sinh_lt_sinh x 0 @[simp] theorem sinh_nonneg_iff : 0 ≀ sinh x ↔ 0 ≀ x := by simpa only [sinh_zero] using @sinh_le_sinh 0 x theorem abs_sinh (x : ℝ) : |sinh x| = sinh |x| := by cases le_total x 0 <;> simp [abs_of_nonneg, abs_of_nonpos, *] theorem cosh_strictMonoOn : StrictMonoOn cosh (Ici 0) := strictMonoOn_of_deriv_pos (convex_Ici _) continuous_cosh.continuousOn fun x hx => by rw [interior_Ici, mem_Ioi] at hx; rwa [deriv_cosh, sinh_pos_iff] @[simp] theorem cosh_le_cosh : cosh x ≀ cosh y ↔ |x| ≀ |y| := cosh_abs x ▾ cosh_abs y ▾ cosh_strictMonoOn.le_iff_le (abs_nonneg x) (abs_nonneg y) @[simp] theorem cosh_lt_cosh : cosh x < cosh y ↔ |x| < |y| := lt_iff_lt_of_le_iff_le cosh_le_cosh @[simp] theorem one_le_cosh (x : ℝ) : 1 ≀ cosh x := cosh_zero ▾ cosh_le_cosh.2 (by simp only [_root_.abs_zero, _root_.abs_nonneg]) @[simp] theorem one_lt_cosh : 1 < cosh x ↔ x ≠ 0 := cosh_zero ▾ cosh_lt_cosh.trans (by simp only [_root_.abs_zero, abs_pos]) theorem sinh_sub_id_strictMono : StrictMono fun x => sinh x - x := by refine strictMono_of_odd_strictMonoOn_nonneg (fun x => by simp; abel) ?_ refine strictMonoOn_of_deriv_pos (convex_Ici _) ?_ fun x hx => ?_ · exact (continuous_sinh.sub continuous_id).continuousOn · rw [interior_Ici, mem_Ioi] at hx rw [deriv_sub, deriv_sinh, deriv_id'', sub_pos, one_lt_cosh] exacts [hx.ne', differentiableAt_sinh, differentiableAt_id] @[simp] theorem self_le_sinh_iff : x ≀ sinh x ↔ 0 ≀ x := calc x ≀ sinh x ↔ sinh 0 - 0 ≀ sinh x - x := by simp _ ↔ 0 ≀ x := sinh_sub_id_strictMono.le_iff_le @[simp] theorem sinh_le_self_iff : sinh x ≀ x ↔ x ≀ 0 := calc sinh x ≀ x ↔ sinh x - x ≀ sinh 0 - 0 := by simp _ ↔ x ≀ 0 := sinh_sub_id_strictMono.le_iff_le @[simp] theorem self_lt_sinh_iff : x < sinh x ↔ 0 < x := lt_iff_lt_of_le_iff_le sinh_le_self_iff @[simp] theorem sinh_lt_self_iff : sinh x < x ↔ x < 0 := lt_iff_lt_of_le_iff_le self_le_sinh_iff end Real section /-! ### Simp lemmas for derivatives of `fun x => Real.cos (f x)` etc., `f : ℝ → ℝ` -/ variable {f : ℝ → ℝ} {f' x : ℝ} {s : Set ℝ} /-! #### `Real.cos` -/ theorem HasStrictDerivAt.cos (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun x => Real.cos (f x)) (-Real.sin (f x) * f') x := (Real.hasStrictDerivAt_cos (f x)).comp x hf theorem HasDerivAt.cos (hf : HasDerivAt f f' x) : HasDerivAt (fun x => Real.cos (f x)) (-Real.sin (f x) * f') x := (Real.hasDerivAt_cos (f x)).comp x hf theorem HasDerivWithinAt.cos (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun x => Real.cos (f x)) (-Real.sin (f x) * f') s x := (Real.hasDerivAt_cos (f x)).comp_hasDerivWithinAt x hf theorem derivWithin_cos (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) : derivWithin (fun x => Real.cos (f x)) s x = -Real.sin (f x) * derivWithin f s x := hf.hasDerivWithinAt.cos.derivWithin hxs @[simp] theorem deriv_cos (hc : DifferentiableAt ℝ f x) : deriv (fun x => Real.cos (f x)) x = -Real.sin (f x) * deriv f x := hc.hasDerivAt.cos.deriv /-! #### `Real.sin` -/ theorem HasStrictDerivAt.sin (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun x => Real.sin (f x)) (Real.cos (f x) * f') x := (Real.hasStrictDerivAt_sin (f x)).comp x hf theorem HasDerivAt.sin (hf : HasDerivAt f f' x) : HasDerivAt (fun x => Real.sin (f x)) (Real.cos (f x) * f') x := (Real.hasDerivAt_sin (f x)).comp x hf theorem HasDerivWithinAt.sin (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun x => Real.sin (f x)) (Real.cos (f x) * f') s x := (Real.hasDerivAt_sin (f x)).comp_hasDerivWithinAt x hf
Mathlib/Analysis/SpecialFunctions/Trigonometric/Deriv.lean
702
702
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Sébastien Gouëzel, Frédéric Dupuis -/ import Mathlib.Analysis.InnerProductSpace.Subspace import Mathlib.LinearAlgebra.SesquilinearForm /-! # Orthogonal complements of submodules In this file, the `orthogonal` complement of a submodule `K` is defined, and basic API established. Some of the more subtle results about the orthogonal complement are delayed to `Analysis.InnerProductSpace.Projection`. See also `BilinForm.orthogonal` for orthogonality with respect to a general bilinear form. ## Notation The orthogonal complement of a submodule `K` is denoted by `Kᗮ`. The proposition that two submodules are orthogonal, `Submodule.IsOrtho`, is denoted by `U ⟂ V`. Note this is not the same unicode symbol as `⊥` (`Bot`). -/ variable {𝕜 E F : Type*} [RCLike 𝕜] variable [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] variable [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y namespace Submodule variable (K : Submodule 𝕜 E) /-- The subspace of vectors orthogonal to a given subspace, denoted `Kᗮ`. -/ def orthogonal : Submodule 𝕜 E where carrier := { v | ∀ u ∈ K, ⟪u, v⟫ = 0 } zero_mem' _ _ := inner_zero_right _ add_mem' hx hy u hu := by rw [inner_add_right, hx u hu, hy u hu, add_zero] smul_mem' c x hx u hu := by rw [inner_smul_right, hx u hu, mul_zero] @[inherit_doc] notation:1200 K "ᗮ" => orthogonal K /-- When a vector is in `Kᗮ`. -/ theorem mem_orthogonal (v : E) : v ∈ Kᗮ ↔ ∀ u ∈ K, ⟪u, v⟫ = 0 := Iff.rfl /-- When a vector is in `Kᗮ`, with the inner product the other way round. -/ theorem mem_orthogonal' (v : E) : v ∈ Kᗮ ↔ ∀ u ∈ K, ⟪v, u⟫ = 0 := by simp_rw [mem_orthogonal, inner_eq_zero_symm] variable {K}
/-- A vector in `K` is orthogonal to one in `Kᗮ`. -/
Mathlib/Analysis/InnerProductSpace/Orthogonal.lean
56
57
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser, Frédéric Dupuis -/ import Mathlib.Algebra.Star.SelfAdjoint import Mathlib.Algebra.Module.Basic import Mathlib.Algebra.Module.Equiv.Defs import Mathlib.Algebra.Module.LinearMap.Star import Mathlib.Algebra.Module.Rat import Mathlib.LinearAlgebra.Prod /-! # The star operation, bundled as a star-linear equiv We define `starLinearEquiv`, which is the star operation bundled as a star-linear map. It is defined on a star algebra `A` over the base ring `R`. This file also provides some lemmas that need `Algebra.Module.Basic` imported to prove. ## TODO - Define `starLinearEquiv` for noncommutative `R`. We only the commutative case for now since, in the noncommutative case, the ring hom needs to reverse the order of multiplication. This requires a ring hom of type `R →+* Rᵐᵒᵖ`, which is very undesirable in the commutative case. One way out would be to define a new typeclass `IsOp R S` and have an instance `IsOp R R` for commutative `R`. - Also note that such a definition involving `Rᵐᵒᵖ` or `is_op R S` would require adding the appropriate `RingHomInvPair` instances to be able to define the semilinear equivalence. -/ section SMulLemmas variable {R M : Type*} @[simp] theorem star_natCast_smul [Semiring R] [AddCommMonoid M] [Module R M] [StarAddMonoid M] (n : ℕ) (x : M) : star ((n : R) • x) = (n : R) • star x := map_natCast_smul (starAddEquiv : M ≃+ M) R R n x @[simp] theorem star_intCast_smul [Ring R] [AddCommGroup M] [Module R M] [StarAddMonoid M] (n : â„€) (x : M) : star ((n : R) • x) = (n : R) • star x := map_intCast_smul (starAddEquiv : M ≃+ M) R R n x @[simp] theorem star_inv_natCast_smul [DivisionSemiring R] [AddCommMonoid M] [Module R M] [StarAddMonoid M] (n : ℕ) (x : M) : star ((n⁻¹ : R) • x) = (n⁻¹ : R) • star x := map_inv_natCast_smul (starAddEquiv : M ≃+ M) R R n x @[simp] theorem star_inv_intCast_smul [DivisionRing R] [AddCommGroup M] [Module R M] [StarAddMonoid M] (n : â„€) (x : M) : star ((n⁻¹ : R) • x) = (n⁻¹ : R) • star x := map_inv_intCast_smul (starAddEquiv : M ≃+ M) R R n x @[simp] theorem star_ratCast_smul [DivisionRing R] [AddCommGroup M] [Module R M] [StarAddMonoid M] (n : ℚ) (x : M) : star ((n : R) • x) = (n : R) • star x := map_ratCast_smul (starAddEquiv : M ≃+ M) _ _ _ x /-! Per the naming convention, these two lemmas call `(q • ·)` `nnrat_smul` and `rat_smul` respectively, rather than `nnqsmul` and `qsmul` because the latter are reserved to the actions coming from `DivisionSemiring` and `DivisionRing`. We provide aliases with `nnqsmul` and `qsmul` for discoverability. -/ /-- Note that this lemma holds for an arbitrary `ℚ≥0`-action, rather than merely one coming from a `DivisionSemiring`. We keep both the `nnqsmul` and `nnrat_smul` naming conventions for discoverability. See `star_nnqsmul`. -/ @[simp high] lemma star_nnrat_smul [AddCommMonoid R] [StarAddMonoid R] [Module ℚ≥0 R] (q : ℚ≥0) (x : R) : star (q • x) = q • star x := map_nnrat_smul (starAddEquiv : R ≃+ R) _ _ /-- Note that this lemma holds for an arbitrary `ℚ`-action, rather than merely one coming from a `DivisionRing`. We keep both the `qsmul` and `rat_smul` naming conventions for discoverability. See `star_qsmul`. -/ @[simp high] lemma star_rat_smul [AddCommGroup R] [StarAddMonoid R] [Module ℚ R] (q : ℚ) (x : R) : star (q • x) = q • star x := map_rat_smul (starAddEquiv : R ≃+ R) _ _ /-- Note that this lemma holds for an arbitrary `ℚ≥0`-action, rather than merely one coming from a `DivisionSemiring`. We keep both the `nnqsmul` and `nnrat_smul` naming conventions for discoverability. See `star_nnrat_smul`. -/ alias star_nnqsmul := star_nnrat_smul /-- Note that this lemma holds for an arbitrary `ℚ`-action, rather than merely one coming from a `DivisionRing`. We keep both the `qsmul` and `rat_smul` naming conventions for discoverability. See `star_rat_smul`. -/ alias star_qsmul := star_rat_smul instance StarAddMonoid.toStarModuleNNRat [AddCommMonoid R] [Module ℚ≥0 R] [StarAddMonoid R] : StarModule ℚ≥0 R where star_smul := star_nnrat_smul instance StarAddMonoid.toStarModuleRat [AddCommGroup R] [Module ℚ R] [StarAddMonoid R] : StarModule ℚ R where star_smul := star_rat_smul end SMulLemmas /-- If `A` is a module over a commutative `R` with compatible actions, then `star` is a semilinear equivalence. -/ @[simps] def starLinearEquiv (R : Type*) {A : Type*} [CommSemiring R] [StarRing R] [AddCommMonoid A] [StarAddMonoid A] [Module R A] [StarModule R A] : A ≃ₗ⋆[R] A := { starAddEquiv with toFun := star map_smul' := star_smul } section SelfSkewAdjoint variable (R : Type*) (A : Type*) [Semiring R] [StarMul R] [TrivialStar R] [AddCommGroup A] [Module R A] [StarAddMonoid A] [StarModule R A] /-- The self-adjoint elements of a star module, as a submodule. -/ def selfAdjoint.submodule : Submodule R A := { selfAdjoint A with smul_mem' := fun _ _ => (IsSelfAdjoint.all _).smul } /-- The skew-adjoint elements of a star module, as a submodule. -/ def skewAdjoint.submodule : Submodule R A := { skewAdjoint A with smul_mem' := skewAdjoint.smul_mem } variable {A} [Invertible (2 : R)] /-- The self-adjoint part of an element of a star module, as a linear map. -/ @[simps] def selfAdjointPart : A →ₗ[R] selfAdjoint A where toFun x := ⟹(⅟ 2 : R) • (x + star x), by rw [selfAdjoint.mem_iff, star_smul, star_trivial, star_add, star_star, add_comm]⟩ map_add' x y := by ext simp [add_add_add_comm] map_smul' r x := by ext simp [← mul_smul, show ⅟ 2 * r = r * ⅟ 2 from Commute.invOf_left <| (2 : ℕ).cast_commute r] /-- The skew-adjoint part of an element of a star module, as a linear map. -/ @[simps] def skewAdjointPart : A →ₗ[R] skewAdjoint A where toFun x := ⟹(⅟ 2 : R) • (x - star x), by simp only [skewAdjoint.mem_iff, star_smul, star_sub, star_star, star_trivial, ← smul_neg, neg_sub]⟩ map_add' x y := by ext simp only [sub_add, ← smul_add, sub_sub_eq_add_sub, star_add, AddSubgroup.coe_mk, AddSubgroup.coe_add] map_smul' r x := by ext simp [← mul_smul, ← smul_sub, show r * ⅟ 2 = ⅟ 2 * r from Commute.invOf_right <| (2 : ℕ).commute_cast r] theorem StarModule.selfAdjointPart_add_skewAdjointPart (x : A) : (selfAdjointPart R x : A) + skewAdjointPart R x = x := by simp only [smul_sub, selfAdjointPart_apply_coe, smul_add, skewAdjointPart_apply_coe, add_add_sub_cancel, invOf_two_smul_add_invOf_two_smul] theorem IsSelfAdjoint.coe_selfAdjointPart_apply {x : A} (hx : IsSelfAdjoint x) : (selfAdjointPart R x : A) = x := by rw [selfAdjointPart_apply_coe, hx.star_eq, smul_add, invOf_two_smul_add_invOf_two_smul] theorem IsSelfAdjoint.selfAdjointPart_apply {x : A} (hx : IsSelfAdjoint x) : selfAdjointPart R x = ⟹x, hx⟩ := Subtype.eq (hx.coe_selfAdjointPart_apply R) -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: make it a `simp` theorem selfAdjointPart_comp_subtype_selfAdjoint : (selfAdjointPart R).comp (selfAdjoint.submodule R A).subtype = .id := LinearMap.ext fun x ↩ x.2.selfAdjointPart_apply R theorem IsSelfAdjoint.skewAdjointPart_apply {x : A} (hx : IsSelfAdjoint x) : skewAdjointPart R x = 0 := Subtype.eq <| by rw [skewAdjointPart_apply_coe, hx.star_eq, sub_self, smul_zero, ZeroMemClass.coe_zero] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: make it a `simp` theorem skewAdjointPart_comp_subtype_selfAdjoint : (skewAdjointPart R).comp (selfAdjoint.submodule R A).subtype = 0 := LinearMap.ext fun x ↩ x.2.skewAdjointPart_apply R -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: make it a `simp` theorem selfAdjointPart_comp_subtype_skewAdjoint :
(selfAdjointPart R).comp (skewAdjoint.submodule R A).subtype = 0 := LinearMap.ext fun ⟹x, (hx : _ = _)⟩ ↩ Subtype.eq <| by simp [hx] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: make it a `simp` theorem skewAdjointPart_comp_subtype_skewAdjoint :
Mathlib/Algebra/Star/Module.lean
184
188
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Order.Group.Unbundled.Int import Mathlib.Algebra.Ring.Nat import Mathlib.Data.Int.GCD /-! # Congruences modulo a natural number This file defines the equivalence relation `a ≡ b [MOD n]` on the natural numbers, and proves basic properties about it such as the Chinese Remainder Theorem `modEq_and_modEq_iff_modEq_mul`. ## Notations `a ≡ b [MOD n]` is notation for `nat.ModEq n a b`, which is defined to mean `a % n = b % n`. ## Tags ModEq, congruence, mod, MOD, modulo -/ assert_not_exists OrderedAddCommMonoid Function.support namespace Nat /-- Modular equality. `n.ModEq a b`, or `a ≡ b [MOD n]`, means that `a - b` is a multiple of `n`. -/ def ModEq (n a b : ℕ) := a % n = b % n @[inherit_doc] notation:50 a " ≡ " b " [MOD " n "]" => ModEq n a b variable {m n a b c d : ℕ} -- Since `ModEq` is semi-reducible, we need to provide the decidable instance manually instance : Decidable (ModEq n a b) := inferInstanceAs <| Decidable (a % n = b % n) namespace ModEq @[refl] protected theorem refl (a : ℕ) : a ≡ a [MOD n] := rfl protected theorem rfl : a ≡ a [MOD n] := ModEq.refl _ instance : IsRefl _ (ModEq n) := ⟹ModEq.refl⟩ @[symm] protected theorem symm : a ≡ b [MOD n] → b ≡ a [MOD n] := Eq.symm @[trans] protected theorem trans : a ≡ b [MOD n] → b ≡ c [MOD n] → a ≡ c [MOD n] := Eq.trans instance : Trans (ModEq n) (ModEq n) (ModEq n) where trans := Nat.ModEq.trans protected theorem comm : a ≡ b [MOD n] ↔ b ≡ a [MOD n] := ⟹ModEq.symm, ModEq.symm⟩ end ModEq theorem modEq_zero_iff_dvd : a ≡ 0 [MOD n] ↔ n ∣ a := by rw [ModEq, zero_mod, dvd_iff_mod_eq_zero] theorem _root_.Dvd.dvd.modEq_zero_nat (h : n ∣ a) : a ≡ 0 [MOD n] := modEq_zero_iff_dvd.2 h theorem _root_.Dvd.dvd.zero_modEq_nat (h : n ∣ a) : 0 ≡ a [MOD n] := h.modEq_zero_nat.symm theorem modEq_iff_dvd : a ≡ b [MOD n] ↔ (n : â„€) ∣ b - a := by rw [ModEq, eq_comm, ← Int.natCast_inj, Int.natCast_mod, Int.natCast_mod, Int.emod_eq_emod_iff_emod_sub_eq_zero, Int.dvd_iff_emod_eq_zero] alias ⟹ModEq.dvd, modEq_of_dvd⟩ := modEq_iff_dvd /-- A variant of `modEq_iff_dvd` with `Nat` divisibility -/ theorem modEq_iff_dvd' (h : a ≀ b) : a ≡ b [MOD n] ↔ n ∣ b - a := by rw [modEq_iff_dvd, ← Int.natCast_dvd_natCast, Int.ofNat_sub h] theorem mod_modEq (a n) : a % n ≡ a [MOD n] := mod_mod _ _ namespace ModEq lemma of_dvd (d : m ∣ n) (h : a ≡ b [MOD n]) : a ≡ b [MOD m] := modEq_of_dvd <| Int.ofNat_dvd.mpr d |>.trans h.dvd protected theorem mul_left' (c : ℕ) (h : a ≡ b [MOD n]) : c * a ≡ c * b [MOD c * n] := by unfold ModEq at *; rw [mul_mod_mul_left, mul_mod_mul_left, h] @[gcongr] protected theorem mul_left (c : ℕ) (h : a ≡ b [MOD n]) : c * a ≡ c * b [MOD n] := (h.mul_left' _).of_dvd (dvd_mul_left _ _) protected theorem mul_right' (c : ℕ) (h : a ≡ b [MOD n]) : a * c ≡ b * c [MOD n * c] := by rw [mul_comm a, mul_comm b, mul_comm n]; exact h.mul_left' c @[gcongr] protected theorem mul_right (c : ℕ) (h : a ≡ b [MOD n]) : a * c ≡ b * c [MOD n] := by rw [mul_comm a, mul_comm b]; exact h.mul_left c @[gcongr] protected theorem mul (h₁ : a ≡ b [MOD n]) (h₂ : c ≡ d [MOD n]) : a * c ≡ b * d [MOD n] := (h₂.mul_left _).trans (h₁.mul_right _) @[gcongr] protected theorem pow (m : ℕ) (h : a ≡ b [MOD n]) : a ^ m ≡ b ^ m [MOD n] := by induction m with | zero => rfl | succ d hd => rw [Nat.pow_succ, Nat.pow_succ] exact hd.mul h @[gcongr] protected theorem add (h₁ : a ≡ b [MOD n]) (h₂ : c ≡ d [MOD n]) : a + c ≡ b + d [MOD n] := by rw [modEq_iff_dvd, Int.natCast_add, Int.natCast_add, add_sub_add_comm] exact Int.dvd_add h₁.dvd h₂.dvd @[gcongr] protected theorem add_left (c : ℕ) (h : a ≡ b [MOD n]) : c + a ≡ c + b [MOD n] := ModEq.rfl.add h @[gcongr] protected theorem add_right (c : ℕ) (h : a ≡ b [MOD n]) : a + c ≡ b + c [MOD n] := h.add ModEq.rfl protected theorem add_left_cancel (h₁ : a ≡ b [MOD n]) (h₂ : a + c ≡ b + d [MOD n]) : c ≡ d [MOD n] := by simp only [modEq_iff_dvd, Int.natCast_add] at * rw [add_sub_add_comm] at h₂ convert Int.dvd_sub h₂ h₁ using 1 rw [add_sub_cancel_left] protected theorem add_left_cancel' (c : ℕ) (h : c + a ≡ c + b [MOD n]) : a ≡ b [MOD n] := ModEq.rfl.add_left_cancel h protected theorem add_right_cancel (h₁ : c ≡ d [MOD n]) (h₂ : a + c ≡ b + d [MOD n]) : a ≡ b [MOD n] := by rw [add_comm a, add_comm b] at h₂ exact h₁.add_left_cancel h₂ protected theorem add_right_cancel' (c : ℕ) (h : a + c ≡ b + c [MOD n]) : a ≡ b [MOD n] := ModEq.rfl.add_right_cancel h /-- Cancel left multiplication on both sides of the `≡` and in the modulus. For cancelling left multiplication in the modulus, see `Nat.ModEq.of_mul_left`. -/ protected theorem mul_left_cancel' {a b c m : ℕ} (hc : c ≠ 0) : c * a ≡ c * b [MOD c * m] → a ≡ b [MOD m] := by simp only [modEq_iff_dvd, Int.natCast_mul, ← Int.mul_sub] exact fun h => (Int.dvd_of_mul_dvd_mul_left (Int.ofNat_ne_zero.mpr hc) h) protected theorem mul_left_cancel_iff' {a b c m : ℕ} (hc : c ≠ 0) : c * a ≡ c * b [MOD c * m] ↔ a ≡ b [MOD m] := ⟹ModEq.mul_left_cancel' hc, ModEq.mul_left' _⟩ /-- Cancel right multiplication on both sides of the `≡` and in the modulus. For cancelling right multiplication in the modulus, see `Nat.ModEq.of_mul_right`. -/ protected theorem mul_right_cancel' {a b c m : ℕ} (hc : c ≠ 0) : a * c ≡ b * c [MOD m * c] → a ≡ b [MOD m] := by simp only [modEq_iff_dvd, Int.natCast_mul, ← Int.sub_mul] exact fun h => (Int.dvd_of_mul_dvd_mul_right (Int.ofNat_ne_zero.mpr hc) h) protected theorem mul_right_cancel_iff' {a b c m : ℕ} (hc : c ≠ 0) : a * c ≡ b * c [MOD m * c] ↔ a ≡ b [MOD m] := ⟹ModEq.mul_right_cancel' hc, ModEq.mul_right' _⟩ /-- Cancel left multiplication in the modulus. For cancelling left multiplication on both sides of the `≡`, see `nat.modeq.mul_left_cancel'`. -/ lemma of_mul_left (m : ℕ) (h : a ≡ b [MOD m * n]) : a ≡ b [MOD n] := by rw [modEq_iff_dvd] at * exact (dvd_mul_left (n : â„€) (m : â„€)).trans h /-- Cancel right multiplication in the modulus. For cancelling right multiplication on both sides of the `≡`, see `nat.modeq.mul_right_cancel'`. -/ lemma of_mul_right (m : ℕ) : a ≡ b [MOD n * m] → a ≡ b [MOD n] := mul_comm m n ▾ of_mul_left _ theorem of_div (h : a / c ≡ b / c [MOD m / c]) (ha : c ∣ a) (ha : c ∣ b) (ha : c ∣ m) : a ≡ b [MOD m] := by convert h.mul_left' c <;> rwa [Nat.mul_div_cancel'] end ModEq lemma modEq_sub (h : b ≀ a) : a ≡ b [MOD a - b] := (modEq_of_dvd <| by rw [Int.ofNat_sub h]).symm lemma modEq_one : a ≡ b [MOD 1] := modEq_of_dvd <| one_dvd _ @[simp] lemma modEq_zero_iff : a ≡ b [MOD 0] ↔ a = b := by rw [ModEq, mod_zero, mod_zero] @[simp] lemma add_modEq_left : n + a ≡ a [MOD n] := by rw [ModEq, add_mod_left] @[simp] lemma add_modEq_right : a + n ≡ a [MOD n] := by rw [ModEq, add_mod_right] namespace ModEq theorem le_of_lt_add (h1 : a ≡ b [MOD m]) (h2 : a < b + m) : a ≀ b := (le_total a b).elim id fun h3 => Nat.le_of_sub_eq_zero (eq_zero_of_dvd_of_lt ((modEq_iff_dvd' h3).mp h1.symm) (by omega)) theorem add_le_of_lt (h1 : a ≡ b [MOD m]) (h2 : a < b) : a + m ≀ b := le_of_lt_add (add_modEq_right.trans h1) (by omega) theorem dvd_iff (h : a ≡ b [MOD m]) (hdm : d ∣ m) : d ∣ a ↔ d ∣ b := by simp only [← modEq_zero_iff_dvd] replace h := h.of_dvd hdm exact ⟹h.symm.trans, h.trans⟩ theorem gcd_eq (h : a ≡ b [MOD m]) : gcd a m = gcd b m := by have h1 := gcd_dvd_right a m have h2 := gcd_dvd_right b m exact dvd_antisymm (dvd_gcd ((h.dvd_iff h1).mp (gcd_dvd_left a m)) h1) (dvd_gcd ((h.dvd_iff h2).mpr (gcd_dvd_left b m)) h2) lemma eq_of_abs_lt (h : a ≡ b [MOD m]) (h2 : |(b : â„€) - a| < m) : a = b := by apply Int.ofNat.inj rw [eq_comm, ← sub_eq_zero] exact Int.eq_zero_of_abs_lt_dvd h.dvd h2 lemma eq_of_lt_of_lt (h : a ≡ b [MOD m]) (ha : a < m) (hb : b < m) : a = b := h.eq_of_abs_lt <| Int.abs_sub_lt_of_lt_lt ha hb /-- To cancel a common factor `c` from a `ModEq` we must divide the modulus `m` by `gcd m c` -/ lemma cancel_left_div_gcd (hm : 0 < m) (h : c * a ≡ c * b [MOD m]) : a ≡ b [MOD m / gcd m c] := by let d := gcd m c have hmd := gcd_dvd_left m c have hcd := gcd_dvd_right m c rw [modEq_iff_dvd] refine @Int.dvd_of_dvd_mul_right_of_gcd_one (m / d) (c / d) (b - a) ?_ ?_ · show (m / d : â„€) ∣ c / d * (b - a) rw [mul_comm, ← Int.mul_ediv_assoc (b - a) (Int.natCast_dvd_natCast.mpr hcd), mul_comm] apply Int.ediv_dvd_ediv (Int.natCast_dvd_natCast.mpr hmd) rw [Int.mul_sub] exact modEq_iff_dvd.mp h · show Int.gcd (m / d) (c / d) = 1 simp only [d, ← Int.natCast_div, Int.gcd_natCast_natCast (m / d) (c / d), gcd_div hmd hcd, Nat.div_self (gcd_pos_of_pos_left c hm)] /-- To cancel a common factor `c` from a `ModEq` we must divide the modulus `m` by `gcd m c` -/ lemma cancel_right_div_gcd (hm : 0 < m) (h : a * c ≡ b * c [MOD m]) : a ≡ b [MOD m / gcd m c] := by apply cancel_left_div_gcd hm simpa [mul_comm] using h lemma cancel_left_div_gcd' (hm : 0 < m) (hcd : c ≡ d [MOD m]) (h : c * a ≡ d * b [MOD m]) : a ≡ b [MOD m / gcd m c] := (h.trans <| hcd.symm.mul_right b).cancel_left_div_gcd hm lemma cancel_right_div_gcd' (hm : 0 < m) (hcd : c ≡ d [MOD m]) (h : a * c ≡ b * d [MOD m]) : a ≡ b [MOD m / gcd m c] := (h.trans <| hcd.symm.mul_left b).cancel_right_div_gcd hm /-- A common factor that's coprime with the modulus can be cancelled from a `ModEq` -/ lemma cancel_left_of_coprime (hmc : gcd m c = 1) (h : c * a ≡ c * b [MOD m]) : a ≡ b [MOD m] := by rcases m.eq_zero_or_pos with (rfl | hm) · simp only [gcd_zero_left] at hmc simp only [gcd_zero_left, hmc, one_mul, modEq_zero_iff] at h subst h rfl simpa [hmc] using h.cancel_left_div_gcd hm /-- A common factor that's coprime with the modulus can be cancelled from a `ModEq` -/ lemma cancel_right_of_coprime (hmc : gcd m c = 1) (h : a * c ≡ b * c [MOD m]) : a ≡ b [MOD m] := cancel_left_of_coprime hmc <| by simpa [mul_comm] using h end ModEq /-- The natural number less than `lcm n m` congruent to `a` mod `n` and `b` mod `m` -/ def chineseRemainder' (h : a ≡ b [MOD gcd n m]) : { k // k ≡ a [MOD n] ∧ k ≡ b [MOD m] } := if hn : n = 0 then ⟹a, by rw [hn, gcd_zero_left] at h; constructor · rfl · exact h⟩ else if hm : m = 0 then ⟹b, by rw [hm, gcd_zero_right] at h; constructor · exact h.symm · rfl⟩ else ⟹let (c, d) := xgcd n m; Int.toNat ((n * c * b + m * d * a) / gcd n m % lcm n m), by rw [xgcd_val] dsimp rw [modEq_iff_dvd, modEq_iff_dvd, Int.toNat_of_nonneg (Int.emod_nonneg _ (Int.natCast_ne_zero.2 (lcm_ne_zero hn hm)))] have hnonzero : (gcd n m : â„€) ≠ 0 := by norm_cast rw [Nat.gcd_eq_zero_iff, not_and] exact fun _ => hm have hcoedvd : ∀ t, (gcd n m : â„€) ∣ t * (b - a) := fun t => h.dvd.mul_left _ have := gcd_eq_gcd_ab n m constructor <;> rw [Int.emod_def, ← sub_add] <;> refine Int.dvd_add ?_ (dvd_mul_of_dvd_left ?_ _) <;> try norm_cast · rw [← sub_eq_iff_eq_add'] at this rw [← this, Int.sub_mul, ← add_sub_assoc, add_comm, add_sub_assoc, ← Int.mul_sub, Int.add_ediv_of_dvd_left, Int.mul_ediv_cancel_left _ hnonzero, Int.mul_ediv_assoc _ h.dvd, ← sub_sub, sub_self, zero_sub, Int.dvd_neg, mul_assoc] · exact dvd_mul_right _ _ norm_cast exact dvd_mul_right _ _ · exact dvd_lcm_left n m · rw [← sub_eq_iff_eq_add] at this rw [← this, Int.sub_mul, sub_add, ← Int.mul_sub, Int.sub_ediv_of_dvd, Int.mul_ediv_cancel_left _ hnonzero, Int.mul_ediv_assoc _ h.dvd, ← sub_add, sub_self, zero_add, mul_assoc] · exact dvd_mul_right _ _ · exact hcoedvd _ · exact dvd_lcm_right n m⟩ /-- The natural number less than `n*m` congruent to `a` mod `n` and `b` mod `m` -/ def chineseRemainder (co : n.Coprime m) (a b : ℕ) : { k // k ≡ a [MOD n] ∧ k ≡ b [MOD m] } := chineseRemainder' (by convert @modEq_one a b) theorem chineseRemainder'_lt_lcm (h : a ≡ b [MOD gcd n m]) (hn : n ≠ 0) (hm : m ≠ 0) : ↑(chineseRemainder' h) < lcm n m := by
dsimp only [chineseRemainder'] rw [dif_neg hn, dif_neg hm, Subtype.coe_mk, xgcd_val, ← Int.toNat_natCast (lcm n m)] have lcm_pos := Int.natCast_pos.mpr (Nat.pos_of_ne_zero (lcm_ne_zero hn hm))
Mathlib/Data/Nat/ModEq.lean
325
327
/- Copyright (c) 2019 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard -/ import Mathlib.Data.EReal.Basic deprecated_module (since := "2025-04-13")
Mathlib/Data/Real/EReal.lean
1,671
1,677
/- 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 Batteries.Tactic.Init import Mathlib.Logic.Function.Defs /-! # Binary map of options This file defines the binary map of `Option`. This is mostly useful to define pointwise operations on intervals. ## Main declarations * `Option.map₂`: Binary map of options. ## Notes This file is very similar to the n-ary section of `Mathlib.Data.Set.Basic`, to `Mathlib.Data.Finset.NAry` and to `Mathlib.Order.Filter.NAry`. Please keep them in sync. We do not define `Option.map₃` as its only purpose so far would be to prove properties of `Option.map₂` and casing already fulfills this task. -/ universe u open Function namespace Option variable {α β γ ÎŽ : Type*} {f : α → β → γ} {a : Option α} {b : Option β} {c : Option γ} /-- The image of a binary function `f : α → β → γ` as a function `Option α → Option β → Option γ`. Mathematically this should be thought of as the image of the corresponding function `α × β → γ`. -/ def map₂ (f : α → β → γ) (a : Option α) (b : Option β) : Option γ := a.bind fun a => b.map <| f a /-- `Option.map₂` in terms of monadic operations. Note that this can't be taken as the definition because of the lack of universe polymorphism. -/ theorem map₂_def {α β γ : Type u} (f : α → β → γ) (a : Option α) (b : Option β) : map₂ f a b = f <$> a <*> b := by cases a <;> rfl @[simp] theorem map₂_some_some (f : α → β → γ) (a : α) (b : β) : map₂ f (some a) (some b) = f a b := rfl theorem map₂_coe_coe (f : α → β → γ) (a : α) (b : β) : map₂ f a b = f a b := rfl @[simp] theorem map₂_none_left (f : α → β → γ) (b : Option β) : map₂ f none b = none := rfl @[simp] theorem map₂_none_right (f : α → β → γ) (a : Option α) : map₂ f a none = none := by cases a <;> rfl @[simp] theorem map₂_coe_left (f : α → β → γ) (a : α) (b : Option β) : map₂ f a b = b.map fun b => f a b := rfl -- Porting note: This proof was `rfl` in Lean3, but now is not. @[simp] theorem map₂_coe_right (f : α → β → γ) (a : Option α) (b : β) : map₂ f a b = a.map fun a => f a b := by cases a <;> rfl theorem mem_map₂_iff {c : γ} : c ∈ map₂ f a b ↔ ∃ a' b', a' ∈ a ∧ b' ∈ b ∧ f a' b' = c := by simp [map₂, bind_eq_some] /-- `simp`-normal form of `mem_map₂_iff`. -/ @[simp] theorem map₂_eq_some_iff {c : γ} :
map₂ f a b = some c ↔ ∃ a' b', a' ∈ a ∧ b' ∈ b ∧ f a' b' = c := by simp [map₂, bind_eq_some]
Mathlib/Data/Option/NAry.lean
73
74
/- Copyright (c) 2022 Jakob von Raumer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jakob von Raumer, Kevin Klinge, Andrew Yang -/ import Mathlib.Algebra.Group.Submonoid.DistribMulAction import Mathlib.GroupTheory.OreLocalization.Basic import Mathlib.Algebra.GroupWithZero.Defs /-! # Localization over left Ore sets. This file proves results on the localization of rings (monoids with zeros) over a left Ore set. ## References * <https://ncatlab.org/nlab/show/Ore+localization> * [Zoran Å koda, *Noncommutative localization in noncommutative geometry*][skoda2006] ## Tags localization, Ore, non-commutative -/ assert_not_exists RelIso universe u open OreLocalization namespace OreLocalization section MonoidWithZero variable {R : Type*} [MonoidWithZero R] {S : Submonoid R} [OreSet S] @[simp] theorem zero_oreDiv' (s : S) : (0 : R) /ₒ s = 0 := by rw [OreLocalization.zero_def, oreDiv_eq_iff] exact ⟹s, 1, by simp [Submonoid.smul_def]⟩ instance : MonoidWithZero R[S⁻¹] where zero_mul x := by induction' x using OreLocalization.ind with r s rw [OreLocalization.zero_def, oreDiv_mul_char 0 r 1 s 0 1 (by simp), zero_mul, one_mul] mul_zero x := by induction' x using OreLocalization.ind with r s rw [OreLocalization.zero_def, mul_div_one, mul_zero, zero_oreDiv', zero_oreDiv'] end MonoidWithZero section CommMonoidWithZero variable {R : Type*} [CommMonoidWithZero R] {S : Submonoid R} [OreSet S] instance : CommMonoidWithZero R[S⁻¹] where __ := inferInstanceAs (MonoidWithZero R[S⁻¹]) __ := inferInstanceAs (CommMonoid R[S⁻¹]) end CommMonoidWithZero section DistribMulAction variable {R : Type*} [Monoid R] {S : Submonoid R} [OreSet S] {X : Type*} [AddMonoid X] variable [DistribMulAction R X] private def add'' (r₁ : X) (s₁ : S) (r₂ : X) (s₂ : S) : X[S⁻¹] := (oreDenom (s₁ : R) s₂ • r₁ + oreNum (s₁ : R) s₂ • r₂) /ₒ (oreDenom (s₁ : R) s₂ * s₁) private theorem add''_char (r₁ : X) (s₁ : S) (r₂ : X) (s₂ : S) (rb : R) (sb : R) (hb : sb * s₁ = rb * s₂) (h : sb * s₁ ∈ S) : add'' r₁ s₁ r₂ s₂ = (sb • r₁ + rb • r₂) /ₒ ⟹sb * s₁, h⟩ := by simp only [add''] have ha := ore_eq (s₁ : R) s₂ generalize oreNum (s₁ : R) s₂ = ra at * generalize oreDenom (s₁ : R) s₂ = sa at * rw [oreDiv_eq_iff] rcases oreCondition sb sa with ⟹rc, sc, hc⟩ have : sc * rb * s₂ = rc * ra * s₂ := by rw [mul_assoc rc, ← ha, ← mul_assoc, ← hc, mul_assoc, mul_assoc, hb] rcases ore_right_cancel _ _ s₂ this with ⟹sd, hd⟩ use sd * sc use sd * rc simp only [smul_add, smul_smul, Submonoid.smul_def, Submonoid.coe_mul] constructor · rw [mul_assoc _ _ rb, hd, mul_assoc, hc, mul_assoc, mul_assoc] · rw [mul_assoc, ← mul_assoc (sc : R), hc, mul_assoc, mul_assoc] attribute [local instance] OreLocalization.oreEqv private def add' (r₂ : X) (s₂ : S) : X[S⁻¹] → X[S⁻¹] := (--plus tilde Quotient.lift fun r₁s₁ : X × S => add'' r₁s₁.1 r₁s₁.2 r₂ s₂) <| by -- Porting note: `assoc_rw` & `noncomm_ring` were not ported yet rintro ⟹r₁', s₁'⟩ ⟹r₁, s₁⟩ ⟹sb, rb, hb, hb'⟩ -- s*, r* rcases oreCondition (s₁' : R) s₂ with ⟹rc, sc, hc⟩ --s~~, r~~ rcases oreCondition rb sc with ⟹rd, sd, hd⟩ -- s#, r# dsimp at * rw [add''_char _ _ _ _ rc sc hc (sc * s₁').2] have : sd * sb * s₁ = rd * rc * s₂ := by rw [mul_assoc, hb', ← mul_assoc, hd, mul_assoc, hc, ← mul_assoc] rw [add''_char _ _ _ _ (rd * rc : R) (sd * sb) this (sd * sb * s₁).2] rw [mul_smul, ← Submonoid.smul_def sb, hb, smul_smul, hd, oreDiv_eq_iff] use 1 use rd simp only [mul_smul, smul_add, one_smul, OneMemClass.coe_one, one_mul, true_and] rw [this, hc, mul_assoc] /-- The addition on the Ore localization. -/ @[irreducible] private def add : X[S⁻¹] → X[S⁻¹] → X[S⁻¹] := fun x => Quotient.lift (fun rs : X × S => add' rs.1 rs.2 x) (by rintro ⟹r₁, s₁⟩ ⟹r₂, s₂⟩ ⟹sb, rb, hb, hb'⟩ induction' x with r₃ s₃ show add'' _ _ _ _ = add'' _ _ _ _ dsimp only at * rcases oreCondition (s₃ : R) s₂ with ⟹rc, sc, hc⟩ rcases oreCondition rc sb with ⟹rd, sd, hd⟩ have : rd * rb * s₁ = sd * sc * s₃ := by rw [mul_assoc, ← hb', ← mul_assoc, ← hd, mul_assoc, ← hc, mul_assoc] rw [add''_char _ _ _ _ rc sc hc (sc * s₃).2] rw [add''_char _ _ _ _ _ _ this.symm (sd * sc * s₃).2] refine oreDiv_eq_iff.mpr ?_ simp only [Submonoid.mk_smul, smul_add] use sd, 1 simp only [one_smul, one_mul, mul_smul, ← hb, Submonoid.smul_def, ← mul_assoc, and_true] simp only [smul_smul, hd]) instance : Add X[S⁻¹] := ⟹add⟩ theorem oreDiv_add_oreDiv {r r' : X} {s s' : S} : r /ₒ s + r' /ₒ s' = (oreDenom (s : R) s' • r + oreNum (s : R) s' • r') /ₒ (oreDenom (s : R) s' * s) := by with_unfolding_all rfl theorem oreDiv_add_char' {r r' : X} (s s' : S) (rb : R) (sb : R) (h : sb * s = rb * s') (h' : sb * s ∈ S) : r /ₒ s + r' /ₒ s' = (sb • r + rb • r') /ₒ ⟹sb * s, h'⟩ := by with_unfolding_all exact add''_char r s r' s' rb sb h h' /-- A characterization of the addition on the Ore localizaion, allowing for arbitrary Ore numerator and Ore denominator. -/ theorem oreDiv_add_char {r r' : X} (s s' : S) (rb : R) (sb : S) (h : sb * s = rb * s') : r /ₒ s + r' /ₒ s' = (sb • r + rb • r') /ₒ (sb * s) := oreDiv_add_char' s s' rb sb h (sb * s).2 /-- Another characterization of the addition on the Ore localization, bundling up all witnesses and conditions into a sigma type. -/ def oreDivAddChar' (r r' : X) (s s' : S) : Σ'r'' : R, Σ's'' : S, s'' * s = r'' * s' ∧ r /ₒ s + r' /ₒ s' = (s'' • r + r'' • r') /ₒ (s'' * s) := ⟹oreNum (s : R) s', oreDenom (s : R) s', ore_eq (s : R) s', oreDiv_add_oreDiv⟩ @[simp] theorem add_oreDiv {r r' : X} {s : S} : r /ₒ s + r' /ₒ s = (r + r') /ₒ s := by simp [oreDiv_add_char s s 1 1 (by simp)] protected theorem add_assoc (x y z : X[S⁻¹]) : x + y + z = x + (y + z) := by induction' x with r₁ s₁ induction' y with r₂ s₂ induction' z with r₃ s₃ rcases oreDivAddChar' r₁ r₂ s₁ s₂ with ⟹ra, sa, ha, ha'⟩; rw [ha']; clear ha' rcases oreDivAddChar' (sa • r₁ + ra • r₂) r₃ (sa * s₁) s₃ with ⟹rc, sc, hc, q⟩; rw [q]; clear q simp only [smul_add, mul_assoc, add_assoc] simp_rw [← add_oreDiv, ← OreLocalization.expand'] congr 2 · rw [OreLocalization.expand r₂ s₂ ra (ha.symm ▾ (sa * s₁).2)]; congr; ext; exact ha · rw [OreLocalization.expand r₃ s₃ rc (hc.symm ▾ (sc * (sa * s₁)).2)]; congr; ext; exact hc @[simp] theorem zero_oreDiv (s : S) : (0 : X) /ₒ s = 0 := by rw [OreLocalization.zero_def, oreDiv_eq_iff] exact ⟹s, 1, by simp⟩ protected theorem zero_add (x : X[S⁻¹]) : 0 + x = x := by induction x rw [← zero_oreDiv, add_oreDiv]; simp protected theorem add_zero (x : X[S⁻¹]) : x + 0 = x := by induction x rw [← zero_oreDiv, add_oreDiv]; simp @[irreducible] private def nsmul : ℕ → X[S⁻¹] → X[S⁻¹] := nsmulRec instance : AddMonoid X[S⁻¹] where add_assoc := OreLocalization.add_assoc zero_add := OreLocalization.zero_add add_zero := OreLocalization.add_zero nsmul := nsmul nsmul_zero _ := by with_unfolding_all rfl nsmul_succ _ _ := by with_unfolding_all rfl protected theorem smul_zero (x : R[S⁻¹]) : x • (0 : X[S⁻¹]) = 0 := by induction' x with r s rw [OreLocalization.zero_def, smul_div_one, smul_zero, zero_oreDiv, zero_oreDiv] protected theorem smul_add (z : R[S⁻¹]) (x y : X[S⁻¹]) : z • (x + y) = z • x + z • y := by induction' x with r₁ s₁ induction' y with r₂ s₂ induction' z with r₃ s₃ rcases oreDivAddChar' r₁ r₂ s₁ s₂ with ⟹ra, sa, ha, ha'⟩; rw [ha']; clear ha'; norm_cast at ha rw [OreLocalization.expand' r₁ s₁ sa] rw [OreLocalization.expand r₂ s₂ ra (by rw [← ha]; apply SetLike.coe_mem)] rw [← Subtype.coe_eq_of_eq_mk ha] repeat rw [oreDiv_smul_oreDiv] simp only [smul_add, add_oreDiv] instance : DistribMulAction R[S⁻¹] X[S⁻¹] where smul_zero := OreLocalization.smul_zero smul_add := OreLocalization.smul_add instance {R₀} [Monoid R₀] [MulAction R₀ X] [MulAction R₀ R] [IsScalarTower R₀ R X] [IsScalarTower R₀ R R] : DistribMulAction R₀ X[S⁻¹] where smul_zero _ := by rw [← smul_one_oreDiv_one_smul, smul_zero] smul_add _ _ _ := by simp only [← smul_one_oreDiv_one_smul, smul_add] end DistribMulAction section AddCommMonoid variable {R : Type*} [Monoid R] {S : Submonoid R} [OreSet S] variable {X : Type*} [AddCommMonoid X] [DistribMulAction R X] protected theorem add_comm (x y : X[S⁻¹]) : x + y = y + x := by induction' x with r s induction' y with r' s' rcases oreDivAddChar' r r' s s' with ⟹ra, sa, ha, ha'⟩ rw [ha', oreDiv_add_char' s' s _ _ ha.symm (ha ▾ (sa * s).2), add_comm] congr; ext; exact ha instance instAddCommMonoidOreLocalization : AddCommMonoid X[S⁻¹] where add_comm := OreLocalization.add_comm end AddCommMonoid section AddGroup variable {R : Type*} [Monoid R] {S : Submonoid R} [OreSet S] variable {X : Type*} [AddGroup X] [DistribMulAction R X] /-- Negation on the Ore localization is defined via negation on the numerator. -/ @[irreducible] protected def neg : X[S⁻¹] → X[S⁻¹] := liftExpand (fun (r : X) (s : S) => -r /ₒ s) fun r t s ht => by -- Porting note (https://github.com/leanprover-community/mathlib4/issues/12129): additional beta reduction needed beta_reduce rw [← smul_neg, ← OreLocalization.expand] instance instNegOreLocalization : Neg X[S⁻¹] := ⟹OreLocalization.neg⟩ @[simp] protected theorem neg_def (r : X) (s : S) : -(r /ₒ s) = -r /ₒ s := by with_unfolding_all rfl protected theorem neg_add_cancel (x : X[S⁻¹]) : -x + x = 0 := by induction' x with r s; simp /-- `zsmul` of `OreLocalization` -/ @[irreducible] protected def zsmul : â„€ → X[S⁻¹] → X[S⁻¹] := zsmulRec unseal OreLocalization.zsmul in instance instAddGroupOreLocalization : AddGroup X[S⁻¹] where neg_add_cancel := OreLocalization.neg_add_cancel zsmul := OreLocalization.zsmul end AddGroup section AddCommGroup variable {R : Type*} [Monoid R] {S : Submonoid R} [OreSet S] variable {X : Type*} [AddCommGroup X] [DistribMulAction R X] instance : AddCommGroup X[S⁻¹] where __ := inferInstanceAs (AddGroup X[S⁻¹]) __ := inferInstanceAs (AddCommMonoid X[S⁻¹]) end AddCommGroup end OreLocalization
Mathlib/RingTheory/OreLocalization/Basic.lean
377
389
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Nat.ModEq import Mathlib.Data.Nat.Prime.Basic import Mathlib.NumberTheory.Zsqrtd.Basic /-! # Pell's equation and Matiyasevic's theorem This file solves Pell's equation, i.e. integer solutions to `x ^ 2 - d * y ^ 2 = 1` *in the special case that `d = a ^ 2 - 1`*. This is then applied to prove Matiyasevic's theorem that the power function is Diophantine, which is the last key ingredient in the solution to Hilbert's tenth problem. For the definition of Diophantine function, see `NumberTheory.Dioph`. For results on Pell's equation for arbitrary (positive, non-square) `d`, see `NumberTheory.Pell`. ## Main definition * `pell` is a function assigning to a natural number `n` the `n`-th solution to Pell's equation constructed recursively from the initial solution `(0, 1)`. ## Main statements * `eq_pell` shows that every solution to Pell's equation is recursively obtained using `pell` * `matiyasevic` shows that a certain system of Diophantine equations has a solution if and only if the first variable is the `x`-component in a solution to Pell's equation - the key step towards Hilbert's tenth problem in Davis' version of Matiyasevic's theorem. * `eq_pow_of_pell` shows that the power function is Diophantine. ## Implementation notes The proof of Matiyasevic's theorem doesn't follow Matiyasevic's original account of using Fibonacci numbers but instead Davis' variant of using solutions to Pell's equation. ## References * [M. Carneiro, _A Lean formalization of Matiyasevič's theorem_][carneiro2018matiyasevic] * [M. Davis, _Hilbert's tenth problem is unsolvable_][MR317916] ## Tags Pell's equation, Matiyasevic's theorem, Hilbert's tenth problem -/ namespace Pell open Nat section variable {d : â„€} /-- The property of being a solution to the Pell equation, expressed as a property of elements of `℀√d`. -/ def IsPell : ℀√d → Prop | ⟹x, y⟩ => x * x - d * y * y = 1 theorem isPell_norm : ∀ {b : ℀√d}, IsPell b ↔ b * star b = 1 | ⟹x, y⟩ => by simp [Zsqrtd.ext_iff, IsPell, mul_comm]; ring_nf theorem isPell_iff_mem_unitary : ∀ {b : ℀√d}, IsPell b ↔ b ∈ unitary (℀√d) | ⟹x, y⟩ => by rw [unitary.mem_iff, isPell_norm, mul_comm (star _), and_self_iff] theorem isPell_mul {b c : ℀√d} (hb : IsPell b) (hc : IsPell c) : IsPell (b * c) := isPell_norm.2 (by simp [mul_comm, mul_left_comm c, mul_assoc, star_mul, isPell_norm.1 hb, isPell_norm.1 hc]) theorem isPell_star : ∀ {b : ℀√d}, IsPell b ↔ IsPell (star b) | ⟹x, y⟩ => by simp [IsPell, Zsqrtd.star_mk] end section variable {a : ℕ} (a1 : 1 < a) private def d (_a1 : 1 < a) := a * a - 1 @[simp] theorem d_pos : 0 < d a1 := tsub_pos_of_lt (mul_lt_mul a1 (le_of_lt a1) (by decide) (Nat.zero_le _) : 1 * 1 < a * a) -- TODO(lint): Fix double namespace issue /-- The Pell sequences, i.e. the sequence of integer solutions to `x ^ 2 - d * y ^ 2 = 1`, where `d = a ^ 2 - 1`, defined together in mutual recursion. -/ --@[nolint dup_namespace] def pell : ℕ → ℕ × ℕ | 0 => (1, 0) | n+1 => ((pell n).1 * a + d a1 * (pell n).2, (pell n).1 + (pell n).2 * a) /-- The Pell `x` sequence. -/ def xn (n : ℕ) : ℕ := (pell a1 n).1 /-- The Pell `y` sequence. -/ def yn (n : ℕ) : ℕ := (pell a1 n).2 @[simp] theorem pell_val (n : ℕ) : pell a1 n = (xn a1 n, yn a1 n) := show pell a1 n = ((pell a1 n).1, (pell a1 n).2) from match pell a1 n with | (_, _) => rfl @[simp] theorem xn_zero : xn a1 0 = 1 := rfl @[simp] theorem yn_zero : yn a1 0 = 0 := rfl @[simp] theorem xn_succ (n : ℕ) : xn a1 (n + 1) = xn a1 n * a + d a1 * yn a1 n := rfl @[simp] theorem yn_succ (n : ℕ) : yn a1 (n + 1) = xn a1 n + yn a1 n * a := rfl theorem xn_one : xn a1 1 = a := by simp theorem yn_one : yn a1 1 = 1 := by simp /-- The Pell `x` sequence, considered as an integer sequence. -/ def xz (n : ℕ) : â„€ := xn a1 n /-- The Pell `y` sequence, considered as an integer sequence. -/ def yz (n : ℕ) : â„€ := yn a1 n section /-- The element `a` such that `d = a ^ 2 - 1`, considered as an integer. -/ def az (a : ℕ) : â„€ := a end include a1 in theorem asq_pos : 0 < a * a := le_trans (le_of_lt a1) (by have := @Nat.mul_le_mul_left 1 a a (le_of_lt a1); rwa [mul_one] at this) theorem dz_val : ↑(d a1) = az a * az a - 1 := have : 1 ≀ a * a := asq_pos a1 by rw [Pell.d, Int.ofNat_sub this]; rfl @[simp] theorem xz_succ (n : ℕ) : (xz a1 (n + 1)) = xz a1 n * az a + d a1 * yz a1 n := rfl @[simp] theorem yz_succ (n : ℕ) : yz a1 (n + 1) = xz a1 n + yz a1 n * az a := rfl /-- The Pell sequence can also be viewed as an element of `℀√d` -/ def pellZd (n : ℕ) : ℀√(d a1) := ⟹xn a1 n, yn a1 n⟩ @[simp] theorem pellZd_re (n : ℕ) : (pellZd a1 n).re = xn a1 n := rfl @[simp] theorem pellZd_im (n : ℕ) : (pellZd a1 n).im = yn a1 n := rfl theorem isPell_nat {x y : ℕ} : IsPell (⟹x, y⟩ : ℀√(d a1)) ↔ x * x - d a1 * y * y = 1 := ⟹fun h => (Nat.cast_inj (R := â„€)).1 (by rw [Int.ofNat_sub (Int.le_of_ofNat_le_ofNat <| Int.le.intro_sub _ h)]; exact h), fun h => show ((x * x : ℕ) - (d a1 * y * y : ℕ) : â„€) = 1 by rw [← Int.ofNat_sub <| le_of_lt <| Nat.lt_of_sub_eq_succ h, h]; rfl⟩ @[simp] theorem pellZd_succ (n : ℕ) : pellZd a1 (n + 1) = pellZd a1 n * ⟹a, 1⟩ := by ext <;> simp theorem isPell_one : IsPell (⟹a, 1⟩ : ℀√(d a1)) := show az a * az a - d a1 * 1 * 1 = 1 by simp [dz_val] theorem isPell_pellZd : ∀ n : ℕ, IsPell (pellZd a1 n) | 0 => rfl | n + 1 => by let o := isPell_one a1 simpa using Pell.isPell_mul (isPell_pellZd n) o @[simp] theorem pell_eqz (n : ℕ) : xz a1 n * xz a1 n - d a1 * yz a1 n * yz a1 n = 1 := isPell_pellZd a1 n @[simp] theorem pell_eq (n : ℕ) : xn a1 n * xn a1 n - d a1 * yn a1 n * yn a1 n = 1 := let pn := pell_eqz a1 n have h : (↑(xn a1 n * xn a1 n) : â„€) - ↑(d a1 * yn a1 n * yn a1 n) = 1 := by repeat' rw [Int.natCast_mul]; exact pn have hl : d a1 * yn a1 n * yn a1 n ≀ xn a1 n * xn a1 n := Nat.cast_le.1 <| Int.le.intro _ <| add_eq_of_eq_sub' <| Eq.symm h (Nat.cast_inj (R := â„€)).1 (by rw [Int.ofNat_sub hl]; exact h) instance dnsq : Zsqrtd.Nonsquare (d a1) := ⟹fun n h => have : n * n + 1 = a * a := by rw [← h]; exact Nat.succ_pred_eq_of_pos (asq_pos a1) have na : n < a := Nat.mul_self_lt_mul_self_iff.1 (by rw [← this]; exact Nat.lt_succ_self _) have : (n + 1) * (n + 1) ≀ n * n + 1 := by rw [this]; exact Nat.mul_self_le_mul_self na have : n + n ≀ 0 := @Nat.le_of_add_le_add_right _ (n * n + 1) _ (by ring_nf at this ⊢; assumption) Nat.ne_of_gt (d_pos a1) <| by rwa [Nat.eq_zero_of_le_zero ((Nat.le_add_left _ _).trans this)] at h⟩ theorem xn_ge_a_pow : ∀ n : ℕ, a ^ n ≀ xn a1 n | 0 => le_refl 1 | n + 1 => by simp only [_root_.pow_succ, xn_succ] exact le_trans (Nat.mul_le_mul_right _ (xn_ge_a_pow n)) (Nat.le_add_right _ _) theorem n_lt_xn (n) : n < xn a1 n := lt_of_lt_of_le (Nat.lt_pow_self a1) (xn_ge_a_pow a1 n) theorem x_pos (n) : 0 < xn a1 n := lt_of_le_of_lt (Nat.zero_le n) (n_lt_xn a1 n) theorem eq_pell_lem : ∀ (n) (b : ℀√(d a1)), 1 ≀ b → IsPell b → b ≀ pellZd a1 n → ∃ n, b = pellZd a1 n | 0, _ => fun h1 _ hl => ⟹0, @Zsqrtd.le_antisymm _ (dnsq a1) _ _ hl h1⟩ | n + 1, b => fun h1 hp h => have a1p : (0 : ℀√(d a1)) ≀ ⟹a, 1⟩ := trivial have am1p : (0 : ℀√(d a1)) ≀ ⟹a, -1⟩ := show (_ : Nat) ≀ _ by simp; exact Nat.pred_le _ have a1m : (⟹a, 1⟩ * ⟹a, -1⟩ : ℀√(d a1)) = 1 := isPell_norm.1 (isPell_one a1) if ha : (⟹↑a, 1⟩ : ℀√(d a1)) ≀ b then let ⟹m, e⟩ := eq_pell_lem n (b * ⟹a, -1⟩) (by rw [← a1m]; exact mul_le_mul_of_nonneg_right ha am1p) (isPell_mul hp (isPell_star.1 (isPell_one a1))) (by have t := mul_le_mul_of_nonneg_right h am1p rwa [pellZd_succ, mul_assoc, a1m, mul_one] at t) ⟹m + 1, by rw [show b = b * ⟹a, -1⟩ * ⟹a, 1⟩ by rw [mul_assoc, Eq.trans (mul_comm _ _) a1m]; simp, pellZd_succ, e]⟩ else suffices ¬1 < b from ⟹0, show b = 1 from (Or.resolve_left (lt_or_eq_of_le h1) this).symm⟩ fun h1l => by obtain ⟹x, y⟩ := b exact by have bm : (_ * ⟹_, _⟩ : ℀√d a1) = 1 := Pell.isPell_norm.1 hp have y0l : (0 : ℀√d a1) < ⟹x - x, y - -y⟩ := sub_lt_sub h1l fun hn : (1 : ℀√d a1) ≀ ⟹x, -y⟩ => by have t := mul_le_mul_of_nonneg_left hn (le_trans zero_le_one h1) rw [bm, mul_one] at t exact h1l t have yl2 : (⟹_, _⟩ : ℀√_) < ⟹_, _⟩ := show (⟹x, y⟩ - ⟹x, -y⟩ : ℀√d a1) < ⟹a, 1⟩ - ⟹a, -1⟩ from sub_lt_sub ha fun hn : (⟹x, -y⟩ : ℀√d a1) ≀ ⟹a, -1⟩ => by have t := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hn (le_trans zero_le_one h1)) a1p rw [bm, one_mul, mul_assoc, Eq.trans (mul_comm _ _) a1m, mul_one] at t exact ha t simp only [sub_self, sub_neg_eq_add] at y0l; simp only [Zsqrtd.neg_re, add_neg_cancel, Zsqrtd.neg_im, neg_neg] at yl2 exact match y, y0l, (yl2 : (⟹_, _⟩ : ℀√_) < ⟹_, _⟩) with | 0, y0l, _ => y0l (le_refl 0) | (y + 1 : ℕ), _, yl2 => yl2 (Zsqrtd.le_of_le_le (by simp [sub_eq_add_neg]) (let t := Int.ofNat_le_ofNat_of_le (Nat.succ_pos y) add_le_add t t)) | Int.negSucc _, y0l, _ => y0l trivial theorem eq_pellZd (b : ℀√(d a1)) (b1 : 1 ≀ b) (hp : IsPell b) : ∃ n, b = pellZd a1 n := let ⟹n, h⟩ := @Zsqrtd.le_arch (d a1) b eq_pell_lem a1 n b b1 hp <| h.trans <| by rw [Zsqrtd.natCast_val] exact Zsqrtd.le_of_le_le (Int.ofNat_le_ofNat_of_le <| le_of_lt <| n_lt_xn _ _) (Int.ofNat_zero_le _) /-- Every solution to **Pell's equation** is recursively obtained from the initial solution `(1,0)` using the recursion `pell`. -/ theorem eq_pell {x y : ℕ} (hp : x * x - d a1 * y * y = 1) : ∃ n, x = xn a1 n ∧ y = yn a1 n := have : (1 : ℀√(d a1)) ≀ ⟹x, y⟩ := match x, hp with | 0, (hp : 0 - _ = 1) => by rw [zero_tsub] at hp; contradiction | x + 1, _hp => Zsqrtd.le_of_le_le (Int.ofNat_le_ofNat_of_le <| Nat.succ_pos x) (Int.ofNat_zero_le _) let ⟹m, e⟩ := eq_pellZd a1 ⟹x, y⟩ this ((isPell_nat a1).2 hp) ⟹m, match x, y, e with | _, _, rfl => ⟹rfl, rfl⟩⟩ theorem pellZd_add (m) : ∀ n, pellZd a1 (m + n) = pellZd a1 m * pellZd a1 n | 0 => (mul_one _).symm | n + 1 => by rw [← add_assoc, pellZd_succ, pellZd_succ, pellZd_add _ n, ← mul_assoc] theorem xn_add (m n) : xn a1 (m + n) = xn a1 m * xn a1 n + d a1 * yn a1 m * yn a1 n := by injection pellZd_add a1 m n with h _ zify rw [h] simp [pellZd] theorem yn_add (m n) : yn a1 (m + n) = xn a1 m * yn a1 n + yn a1 m * xn a1 n := by injection pellZd_add a1 m n with _ h zify rw [h] simp [pellZd] theorem pellZd_sub {m n} (h : n ≀ m) : pellZd a1 (m - n) = pellZd a1 m * star (pellZd a1 n) := by let t := pellZd_add a1 n (m - n) rw [add_tsub_cancel_of_le h] at t rw [t, mul_comm (pellZd _ n) _, mul_assoc, isPell_norm.1 (isPell_pellZd _ _), mul_one] theorem xz_sub {m n} (h : n ≀ m) : xz a1 (m - n) = xz a1 m * xz a1 n - d a1 * yz a1 m * yz a1 n := by rw [sub_eq_add_neg, ← mul_neg] exact congr_arg Zsqrtd.re (pellZd_sub a1 h) theorem yz_sub {m n} (h : n ≀ m) : yz a1 (m - n) = xz a1 n * yz a1 m - xz a1 m * yz a1 n := by rw [sub_eq_add_neg, ← mul_neg, mul_comm, add_comm] exact congr_arg Zsqrtd.im (pellZd_sub a1 h) theorem xy_coprime (n) : (xn a1 n).Coprime (yn a1 n) := Nat.coprime_of_dvd' fun k _ kx ky => by let p := pell_eq a1 n rw [← p] exact Nat.dvd_sub (kx.mul_left _) (ky.mul_left _) theorem strictMono_y : StrictMono (yn a1) | _, 0, h => absurd h <| Nat.not_lt_zero _ | m, n + 1, h => by have : yn a1 m ≀ yn a1 n := Or.elim (lt_or_eq_of_le <| Nat.le_of_succ_le_succ h) (fun hl => le_of_lt <| strictMono_y hl) fun e => by rw [e] simp only [yn_succ, gt_iff_lt]; refine lt_of_le_of_lt ?_ (Nat.lt_add_of_pos_left <| x_pos a1 n) rw [← mul_one (yn a1 m)] exact mul_le_mul this (le_of_lt a1) (Nat.zero_le _) (Nat.zero_le _) theorem strictMono_x : StrictMono (xn a1) | _, 0, h => absurd h <| Nat.not_lt_zero _ | m, n + 1, h => by have : xn a1 m ≀ xn a1 n := Or.elim (lt_or_eq_of_le <| Nat.le_of_succ_le_succ h) (fun hl => le_of_lt <| strictMono_x hl) fun e => by rw [e] simp only [xn_succ, gt_iff_lt] refine lt_of_lt_of_le (lt_of_le_of_lt this ?_) (Nat.le_add_right _ _) have t := Nat.mul_lt_mul_of_pos_left a1 (x_pos a1 n) rwa [mul_one] at t theorem yn_ge_n : ∀ n, n ≀ yn a1 n | 0 => Nat.zero_le _ | n + 1 => show n < yn a1 (n + 1) from lt_of_le_of_lt (yn_ge_n n) (strictMono_y a1 <| Nat.lt_succ_self n) theorem y_mul_dvd (n) : ∀ k, yn a1 n ∣ yn a1 (n * k) | 0 => dvd_zero _ | k + 1 => by rw [Nat.mul_succ, yn_add]; exact dvd_add (dvd_mul_left _ _) ((y_mul_dvd _ k).mul_right _) theorem y_dvd_iff (m n) : yn a1 m ∣ yn a1 n ↔ m ∣ n := ⟹fun h => Nat.dvd_of_mod_eq_zero <| (Nat.eq_zero_or_pos _).resolve_right fun hp => by have co : Nat.Coprime (yn a1 m) (xn a1 (m * (n / m))) := Nat.Coprime.symm <| (xy_coprime a1 _).coprime_dvd_right (y_mul_dvd a1 m (n / m)) have m0 : 0 < m := m.eq_zero_or_pos.resolve_left fun e => by rw [e, Nat.mod_zero] at hp;rw [e] at h exact _root_.ne_of_lt (strictMono_y a1 hp) (eq_zero_of_zero_dvd h).symm rw [← Nat.mod_add_div n m, yn_add] at h exact not_le_of_gt (strictMono_y _ <| Nat.mod_lt n m0) (Nat.le_of_dvd (strictMono_y _ hp) <| co.dvd_of_dvd_mul_right <| (Nat.dvd_add_iff_right <| (y_mul_dvd _ _ _).mul_left _).2 h), fun ⟹k, e⟩ => by rw [e]; apply y_mul_dvd⟩ theorem xy_modEq_yn (n) : ∀ k, xn a1 (n * k) ≡ xn a1 n ^ k [MOD yn a1 n ^ 2] ∧ yn a1 (n * k) ≡ k * xn a1 n ^ (k - 1) * yn a1 n [MOD yn a1 n ^ 3] | 0 => by constructor <;> simpa using Nat.ModEq.refl _ | k + 1 => by let ⟹hx, hy⟩ := xy_modEq_yn n k have L : xn a1 (n * k) * xn a1 n + d a1 * yn a1 (n * k) * yn a1 n ≡ xn a1 n ^ k * xn a1 n + 0 [MOD yn a1 n ^ 2] := (hx.mul_right _).add <| modEq_zero_iff_dvd.2 <| by rw [_root_.pow_succ] exact mul_dvd_mul_right (dvd_mul_of_dvd_right (modEq_zero_iff_dvd.1 <| (hy.of_dvd <| by simp [_root_.pow_succ]).trans <| modEq_zero_iff_dvd.2 <| by simp) _) _ have R : xn a1 (n * k) * yn a1 n + yn a1 (n * k) * xn a1 n ≡ xn a1 n ^ k * yn a1 n + k * xn a1 n ^ k * yn a1 n [MOD yn a1 n ^ 3] := ModEq.add (by rw [_root_.pow_succ] exact hx.mul_right' _) <| by have : k * xn a1 n ^ (k - 1) * yn a1 n * xn a1 n = k * xn a1 n ^ k * yn a1 n := by rcases k with - | k <;> simp [_root_.pow_succ]; ring_nf rw [← this] exact hy.mul_right _ rw [add_tsub_cancel_right, Nat.mul_succ, xn_add, yn_add, pow_succ (xn _ n), Nat.succ_mul, add_comm (k * xn _ n ^ k) (xn _ n ^ k), right_distrib] exact ⟹L, R⟩ theorem ysq_dvd_yy (n) : yn a1 n * yn a1 n ∣ yn a1 (n * yn a1 n) := modEq_zero_iff_dvd.1 <| ((xy_modEq_yn a1 n (yn a1 n)).right.of_dvd <| by simp [_root_.pow_succ]).trans (modEq_zero_iff_dvd.2 <| by simp [mul_dvd_mul_left, mul_assoc]) theorem dvd_of_ysq_dvd {n t} (h : yn a1 n * yn a1 n ∣ yn a1 t) : yn a1 n ∣ t := have nt : n ∣ t := (y_dvd_iff a1 n t).1 <| dvd_of_mul_left_dvd h n.eq_zero_or_pos.elim (fun n0 => by rwa [n0] at nt ⊢) fun n0l : 0 < n => by let ⟹k, ke⟩ := nt have : yn a1 n ∣ k * xn a1 n ^ (k - 1) := Nat.dvd_of_mul_dvd_mul_right (strictMono_y a1 n0l) <| modEq_zero_iff_dvd.1 <| by have xm := (xy_modEq_yn a1 n k).right; rw [← ke] at xm exact (xm.of_dvd <| by simp [_root_.pow_succ]).symm.trans h.modEq_zero_nat rw [ke] exact dvd_mul_of_dvd_right (((xy_coprime _ _).pow_left _).symm.dvd_of_dvd_mul_right this) _ theorem pellZd_succ_succ (n) : pellZd a1 (n + 2) + pellZd a1 n = (2 * a : ℕ) * pellZd a1 (n + 1) := by have : (1 : ℀√(d a1)) + ⟹a, 1⟩ * ⟹a, 1⟩ = ⟹a, 1⟩ * (2 * a) := by rw [Zsqrtd.natCast_val] change (⟹_, _⟩ : ℀√(d a1)) = ⟹_, _⟩ rw [dz_val] dsimp [az] ext <;> dsimp <;> ring_nf simpa [mul_add, mul_comm, mul_left_comm, add_comm] using congr_arg (· * pellZd a1 n) this theorem xy_succ_succ (n) : xn a1 (n + 2) + xn a1 n = 2 * a * xn a1 (n + 1) ∧ yn a1 (n + 2) + yn a1 n = 2 * a * yn a1 (n + 1) := by have := pellZd_succ_succ a1 n; unfold pellZd at this rw [Zsqrtd.nsmul_val (2 * a : ℕ)] at this injection this with h₁ h₂ constructor <;> apply Int.ofNat.inj <;> [simpa using h₁; simpa using h₂] theorem xn_succ_succ (n) : xn a1 (n + 2) + xn a1 n = 2 * a * xn a1 (n + 1) := (xy_succ_succ a1 n).1 theorem yn_succ_succ (n) : yn a1 (n + 2) + yn a1 n = 2 * a * yn a1 (n + 1) := (xy_succ_succ a1 n).2 theorem xz_succ_succ (n) : xz a1 (n + 2) = (2 * a : ℕ) * xz a1 (n + 1) - xz a1 n := eq_sub_of_add_eq <| by delta xz; rw [← Int.natCast_add, ← Int.natCast_mul, xn_succ_succ] theorem yz_succ_succ (n) : yz a1 (n + 2) = (2 * a : ℕ) * yz a1 (n + 1) - yz a1 n := eq_sub_of_add_eq <| by delta yz; rw [← Int.natCast_add, ← Int.natCast_mul, yn_succ_succ] theorem yn_modEq_a_sub_one : ∀ n, yn a1 n ≡ n [MOD a - 1] | 0 => by simp [Nat.ModEq.refl] | 1 => by simp [Nat.ModEq.refl] | n + 2 => (yn_modEq_a_sub_one n).add_right_cancel <| by rw [yn_succ_succ, (by ring : n + 2 + n = 2 * (n + 1))] exact ((modEq_sub a1.le).mul_left 2).mul (yn_modEq_a_sub_one (n + 1)) theorem yn_modEq_two : ∀ n, yn a1 n ≡ n [MOD 2] | 0 => by rfl | 1 => by simp; rfl | n + 2 => (yn_modEq_two n).add_right_cancel <| by rw [yn_succ_succ, mul_assoc, (by ring : n + 2 + n = 2 * (n + 1))] exact (dvd_mul_right 2 _).modEq_zero_nat.trans (dvd_mul_right 2 _).zero_modEq_nat section theorem x_sub_y_dvd_pow_lem (y2 y1 y0 yn1 yn0 xn1 xn0 ay a2 : â„€) : (a2 * yn1 - yn0) * ay + y2 - (a2 * xn1 - xn0) = y2 - a2 * y1 + y0 + a2 * (yn1 * ay + y1 - xn1) - (yn0 * ay + y0 - xn0) := by ring end theorem x_sub_y_dvd_pow (y : ℕ) : ∀ n, (2 * a * y - y * y - 1 : â„€) ∣ yz a1 n * (a - y) + ↑(y ^ n) - xz a1 n | 0 => by simp [xz, yz, Int.ofNat_zero, Int.ofNat_one] | 1 => by simp [xz, yz, Int.ofNat_zero, Int.ofNat_one] | n + 2 => by have : (2 * a * y - y * y - 1 : â„€) ∣ ↑(y ^ (n + 2)) - ↑(2 * a) * ↑(y ^ (n + 1)) + ↑(y ^ n) := ⟹-↑(y ^ n), by simp [_root_.pow_succ, mul_add, Int.natCast_mul, show ((2 : ℕ) : â„€) = 2 from rfl, mul_comm, mul_left_comm] ring⟩ rw [xz_succ_succ, yz_succ_succ, x_sub_y_dvd_pow_lem ↑(y ^ (n + 2)) ↑(y ^ (n + 1)) ↑(y ^ n)] exact _root_.dvd_sub (dvd_add this <| (x_sub_y_dvd_pow _ (n + 1)).mul_left _) (x_sub_y_dvd_pow _ n) theorem xn_modEq_x2n_add_lem (n j) : xn a1 n ∣ d a1 * yn a1 n * (yn a1 n * xn a1 j) + xn a1 j := by have h1 : d a1 * yn a1 n * (yn a1 n * xn a1 j) + xn a1 j = (d a1 * yn a1 n * yn a1 n + 1) * xn a1 j := by simp [add_mul, mul_assoc] have h2 : d a1 * yn a1 n * yn a1 n + 1 = xn a1 n * xn a1 n := by zify at * apply add_eq_of_eq_sub' (Eq.symm (pell_eqz a1 n)) rw [h2] at h1; rw [h1, mul_assoc]; exact dvd_mul_right _ _ theorem xn_modEq_x2n_add (n j) : xn a1 (2 * n + j) + xn a1 j ≡ 0 [MOD xn a1 n] := by rw [two_mul, add_assoc, xn_add, add_assoc, ← zero_add 0] refine (dvd_mul_right (xn a1 n) (xn a1 (n + j))).modEq_zero_nat.add ?_ rw [yn_add, left_distrib, add_assoc, ← zero_add 0] exact ((dvd_mul_right _ _).mul_left _).modEq_zero_nat.add (xn_modEq_x2n_add_lem _ _ _).modEq_zero_nat theorem xn_modEq_x2n_sub_lem {n j} (h : j ≀ n) : xn a1 (2 * n - j) + xn a1 j ≡ 0 [MOD xn a1 n] := by have h1 : xz a1 n ∣ d a1 * yz a1 n * yz a1 (n - j) + xz a1 j := by rw [yz_sub _ h, mul_sub_left_distrib, sub_add_eq_add_sub] exact dvd_sub (by delta xz; delta yz rw [mul_comm (xn _ _ : â„€)] exact mod_cast (xn_modEq_x2n_add_lem _ n j)) ((dvd_mul_right _ _).mul_left _) rw [two_mul, add_tsub_assoc_of_le h, xn_add, add_assoc, ← zero_add 0] exact (dvd_mul_right _ _).modEq_zero_nat.add (Int.natCast_dvd_natCast.1 <| by simpa [xz, yz] using h1).modEq_zero_nat theorem xn_modEq_x2n_sub {n j} (h : j ≀ 2 * n) : xn a1 (2 * n - j) + xn a1 j ≡ 0 [MOD xn a1 n] := (le_total j n).elim (xn_modEq_x2n_sub_lem a1) fun jn => by have : 2 * n - j + j ≀ n + j := by rw [tsub_add_cancel_of_le h, two_mul]; exact Nat.add_le_add_left jn _ let t := xn_modEq_x2n_sub_lem a1 (Nat.le_of_add_le_add_right this) rwa [tsub_tsub_cancel_of_le h, add_comm] at t theorem xn_modEq_x4n_add (n j) : xn a1 (4 * n + j) ≡ xn a1 j [MOD xn a1 n] := ModEq.add_right_cancel' (xn a1 (2 * n + j)) <| by refine @ModEq.trans _ _ 0 _ ?_ (by rw [add_comm]; exact (xn_modEq_x2n_add _ _ _).symm) rw [show 4 * n = 2 * n + 2 * n from right_distrib 2 2 n, add_assoc] apply xn_modEq_x2n_add theorem xn_modEq_x4n_sub {n j} (h : j ≀ 2 * n) : xn a1 (4 * n - j) ≡ xn a1 j [MOD xn a1 n] := have h' : j ≀ 2 * n := le_trans h (by rw [Nat.succ_mul]) ModEq.add_right_cancel' (xn a1 (2 * n - j)) <| by refine @ModEq.trans _ _ 0 _ ?_ (by rw [add_comm]; exact (xn_modEq_x2n_sub _ h).symm) rw [show 4 * n = 2 * n + 2 * n from right_distrib 2 2 n, add_tsub_assoc_of_le h'] apply xn_modEq_x2n_add theorem eq_of_xn_modEq_lem1 {i n} : ∀ {j}, i < j → j < n → xn a1 i % xn a1 n < xn a1 j % xn a1 n | 0, ij, _ => absurd ij (Nat.not_lt_zero _) | j + 1, ij, jn => by suffices xn a1 j % xn a1 n < xn a1 (j + 1) % xn a1 n from (lt_or_eq_of_le (Nat.le_of_succ_le_succ ij)).elim (fun h => lt_trans (eq_of_xn_modEq_lem1 h (le_of_lt jn)) this) fun h => by rw [h]; exact this rw [Nat.mod_eq_of_lt (strictMono_x _ (Nat.lt_of_succ_lt jn)), Nat.mod_eq_of_lt (strictMono_x _ jn)] exact strictMono_x _ (Nat.lt_succ_self _) theorem eq_of_xn_modEq_lem2 {n} (h : 2 * xn a1 n = xn a1 (n + 1)) : a = 2 ∧ n = 0 := by rw [xn_succ, mul_comm] at h have : n = 0 := n.eq_zero_or_pos.resolve_right fun np => _root_.ne_of_lt (lt_of_le_of_lt (Nat.mul_le_mul_left _ a1) (Nat.lt_add_of_pos_right <| mul_pos (d_pos a1) (strictMono_y a1 np))) h cases this; simp at h; exact ⟹h.symm, rfl⟩ theorem eq_of_xn_modEq_lem3 {i n} (npos : 0 < n) : ∀ {j}, i < j → j ≀ 2 * n → j ≠ n → ¬(a = 2 ∧ n = 1 ∧ i = 0 ∧ j = 2) → xn a1 i % xn a1 n < xn a1 j % xn a1 n | 0, ij, _, _, _ => absurd ij (Nat.not_lt_zero _) | j + 1, ij, j2n, jnn, ntriv => have lem2 : ∀ k > n, k ≀ 2 * n → (↑(xn a1 k % xn a1 n) : â„€) = xn a1 n - xn a1 (2 * n - k) := fun k kn k2n => by let k2nl := lt_of_add_lt_add_right <| show 2 * n - k + k < n + k by rw [tsub_add_cancel_of_le] · rw [two_mul] exact add_lt_add_left kn n exact k2n have xle : xn a1 (2 * n - k) ≀ xn a1 n := le_of_lt <| strictMono_x a1 k2nl suffices xn a1 k % xn a1 n = xn a1 n - xn a1 (2 * n - k) by rw [this, Int.ofNat_sub xle] rw [← Nat.mod_eq_of_lt (Nat.sub_lt (x_pos a1 n) (x_pos a1 (2 * n - k)))] apply ModEq.add_right_cancel' (xn a1 (2 * n - k)) rw [tsub_add_cancel_of_le xle] have t := xn_modEq_x2n_sub_lem a1 k2nl.le rw [tsub_tsub_cancel_of_le k2n] at t exact t.trans dvd_rfl.zero_modEq_nat (lt_trichotomy j n).elim (fun jn : j < n => eq_of_xn_modEq_lem1 _ ij (lt_of_le_of_ne jn jnn)) fun o => o.elim (fun jn : j = n => by cases jn apply Int.lt_of_ofNat_lt_ofNat rw [lem2 (n + 1) (Nat.lt_succ_self _) j2n, show 2 * n - (n + 1) = n - 1 by rw [two_mul, tsub_add_eq_tsub_tsub, add_tsub_cancel_right]] refine lt_sub_left_of_add_lt (Int.ofNat_lt_ofNat_of_lt ?_) rcases lt_or_eq_of_le <| Nat.le_of_succ_le_succ ij with lin | ein · rw [Nat.mod_eq_of_lt (strictMono_x _ lin)] have ll : xn a1 (n - 1) + xn a1 (n - 1) ≀ xn a1 n := by rw [← two_mul, mul_comm, show xn a1 n = xn a1 (n - 1 + 1) by rw [tsub_add_cancel_of_le (succ_le_of_lt npos)], xn_succ] exact le_trans (Nat.mul_le_mul_left _ a1) (Nat.le_add_right _ _) have npm : (n - 1).succ = n := Nat.succ_pred_eq_of_pos npos have il : i ≀ n - 1 := by apply Nat.le_of_succ_le_succ rw [npm] exact lin rcases lt_or_eq_of_le il with ill | ile · exact lt_of_lt_of_le (Nat.add_lt_add_left (strictMono_x a1 ill) _) ll · rw [ile] apply lt_of_le_of_ne ll rw [← two_mul] exact fun e => ntriv <| by let ⟹a2, s1⟩ := @eq_of_xn_modEq_lem2 _ a1 (n - 1) (by rwa [tsub_add_cancel_of_le (succ_le_of_lt npos)]) have n1 : n = 1 := le_antisymm (tsub_eq_zero_iff_le.mp s1) npos rw [ile, a2, n1]; exact ⟹rfl, rfl, rfl, rfl⟩ · rw [ein, Nat.mod_self, add_zero] exact strictMono_x _ (Nat.pred_lt npos.ne')) fun jn : j > n => have lem1 : j ≠ n → xn a1 j % xn a1 n < xn a1 (j + 1) % xn a1 n → xn a1 i % xn a1 n < xn a1 (j + 1) % xn a1 n := fun jn s => (lt_or_eq_of_le (Nat.le_of_succ_le_succ ij)).elim (fun h => lt_trans (eq_of_xn_modEq_lem3 npos h (le_of_lt (Nat.lt_of_succ_le j2n)) jn fun ⟹_, n1, _, j2⟩ => by rw [n1, j2] at j2n; exact absurd j2n (by decide)) s) fun h => by rw [h]; exact s lem1 (_root_.ne_of_gt jn) <| Int.lt_of_ofNat_lt_ofNat <| by rw [lem2 j jn (le_of_lt j2n), lem2 (j + 1) (Nat.le_succ_of_le jn) j2n] refine sub_lt_sub_left (Int.ofNat_lt_ofNat_of_lt <| strictMono_x _ ?_) _ rw [Nat.sub_succ] exact Nat.pred_lt (_root_.ne_of_gt <| tsub_pos_of_lt j2n) theorem eq_of_xn_modEq_le {i j n} (ij : i ≀ j) (j2n : j ≀ 2 * n) (h : xn a1 i ≡ xn a1 j [MOD xn a1 n]) (ntriv : ¬(a = 2 ∧ n = 1 ∧ i = 0 ∧ j = 2)) : i = j := if npos : n = 0 then by simp_all else (lt_or_eq_of_le ij).resolve_left fun ij' => if jn : j = n then by refine _root_.ne_of_gt ?_ h rw [jn, Nat.mod_self] have x0 : 0 < xn a1 0 % xn a1 n := by rw [Nat.mod_eq_of_lt (strictMono_x a1 (Nat.pos_of_ne_zero npos))] exact Nat.succ_pos _ rcases i with - | i · exact x0 rw [jn] at ij' exact x0.trans (eq_of_xn_modEq_lem3 _ (Nat.pos_of_ne_zero npos) (Nat.succ_pos _) (le_trans ij j2n) (_root_.ne_of_lt ij') fun ⟹_, n1, _, i2⟩ => by rw [n1, i2] at ij'; exact absurd ij' (by decide)) else _root_.ne_of_lt (eq_of_xn_modEq_lem3 a1 (Nat.pos_of_ne_zero npos) ij' j2n jn ntriv) h theorem eq_of_xn_modEq {i j n} (i2n : i ≀ 2 * n) (j2n : j ≀ 2 * n) (h : xn a1 i ≡ xn a1 j [MOD xn a1 n]) (ntriv : a = 2 → n = 1 → (i = 0 → j ≠ 2) ∧ (i = 2 → j ≠ 0)) : i = j := (le_total i j).elim (fun ij => eq_of_xn_modEq_le a1 ij j2n h fun ⟹a2, n1, i0, j2⟩ => (ntriv a2 n1).left i0 j2) fun ij => (eq_of_xn_modEq_le a1 ij i2n h.symm fun ⟹a2, n1, j0, i2⟩ => (ntriv a2 n1).right i2 j0).symm theorem eq_of_xn_modEq' {i j n} (ipos : 0 < i) (hin : i ≀ n) (j4n : j ≀ 4 * n) (h : xn a1 j ≡ xn a1 i [MOD xn a1 n]) : j = i √ j + i = 4 * n := have i2n : i ≀ 2 * n := by apply le_trans hin; rw [two_mul]; apply Nat.le_add_left (le_or_gt j (2 * n)).imp (fun j2n : j ≀ 2 * n => eq_of_xn_modEq a1 j2n i2n h fun _ n1 => ⟹fun _ i2 => by rw [n1, i2] at hin; exact absurd hin (by decide), fun _ i0 => _root_.ne_of_gt ipos i0⟩) fun j2n : 2 * n < j => suffices i = 4 * n - j by rw [this, add_tsub_cancel_of_le j4n] have j42n : 4 * n - j ≀ 2 * n := by omega eq_of_xn_modEq a1 i2n j42n (h.symm.trans <| by let t := xn_modEq_x4n_sub a1 j42n rwa [tsub_tsub_cancel_of_le j4n] at t) (by omega) theorem modEq_of_xn_modEq {i j n} (ipos : 0 < i) (hin : i ≀ n) (h : xn a1 j ≡ xn a1 i [MOD xn a1 n]) : j ≡ i [MOD 4 * n] √ j + i ≡ 0 [MOD 4 * n] := let j' := j % (4 * n) have n4 : 0 < 4 * n := mul_pos (by decide) (ipos.trans_le hin) have jl : j' < 4 * n := Nat.mod_lt _ n4 have jj : j ≡ j' [MOD 4 * n] := by delta ModEq; rw [Nat.mod_eq_of_lt jl] have : ∀ j q, xn a1 (j + 4 * n * q) ≡ xn a1 j [MOD xn a1 n] := by intro j q; induction q with | zero => simp [ModEq.refl] | succ q IH => rw [Nat.mul_succ, ← add_assoc, add_comm] exact (xn_modEq_x4n_add _ _ _).trans IH Or.imp (fun ji : j' = i => by rwa [← ji]) (fun ji : j' + i = 4 * n => (jj.add_right _).trans <| by rw [ji] exact dvd_rfl.modEq_zero_nat) (eq_of_xn_modEq' a1 ipos hin jl.le <| (h.symm.trans <| by rw [← Nat.mod_add_div j (4 * n)] exact this j' _).symm) end theorem xy_modEq_of_modEq {a b c} (a1 : 1 < a) (b1 : 1 < b) (h : a ≡ b [MOD c]) : ∀ n, xn a1 n ≡ xn b1 n [MOD c] ∧ yn a1 n ≡ yn b1 n [MOD c] | 0 => by constructor <;> rfl | 1 => by simpa using ⟹h, ModEq.refl 1⟩ | n + 2 => ⟹(xy_modEq_of_modEq a1 b1 h n).left.add_right_cancel <| by rw [xn_succ_succ a1, xn_succ_succ b1] exact (h.mul_left _).mul (xy_modEq_of_modEq _ _ h (n + 1)).left, (xy_modEq_of_modEq a1 b1 h n).right.add_right_cancel <| by rw [yn_succ_succ a1, yn_succ_succ b1] exact (h.mul_left _).mul (xy_modEq_of_modEq _ _ h (n + 1)).right⟩ theorem matiyasevic {a k x y} : (∃ a1 : 1 < a, xn a1 k = x ∧ yn a1 k = y) ↔ 1 < a ∧ k ≀ y ∧ (x = 1 ∧ y = 0 √ ∃ u v s t b : ℕ, x * x - (a * a - 1) * y * y = 1 ∧ u * u - (a * a - 1) * v * v = 1 ∧ s * s - (b * b - 1) * t * t = 1 ∧ 1 < b ∧ b ≡ 1 [MOD 4 * y] ∧ b ≡ a [MOD u] ∧ 0 < v ∧ y * y ∣ v ∧ s ≡ x [MOD u] ∧ t ≡ k [MOD 4 * y]) := ⟹fun ⟹a1, hx, hy⟩ => by rw [← hx, ← hy] refine ⟹a1, (Nat.eq_zero_or_pos k).elim (fun k0 => by rw [k0]; exact ⟹le_rfl, Or.inl ⟹rfl, rfl⟩⟩) fun kpos => ?_⟩ exact let x := xn a1 k let y := yn a1 k let m := 2 * (k * y) let u := xn a1 m let v := yn a1 m have ky : k ≀ y := yn_ge_n a1 k have yv : y * y ∣ v := (ysq_dvd_yy a1 k).trans <| (y_dvd_iff _ _ _).2 <| dvd_mul_left _ _ have uco : Nat.Coprime u (4 * y) := have : 2 ∣ v := modEq_zero_iff_dvd.1 <| (yn_modEq_two _ _).trans (dvd_mul_right _ _).modEq_zero_nat have : Nat.Coprime u 2 := (xy_coprime a1 m).coprime_dvd_right this (this.mul_right this).mul_right <| (xy_coprime _ _).coprime_dvd_right (dvd_of_mul_left_dvd yv) let ⟹b, ba, bm1⟩ := chineseRemainder uco a 1 have m1 : 1 < m := have : 0 < k * y := mul_pos kpos (strictMono_y a1 kpos) Nat.mul_le_mul_left 2 this have vp : 0 < v := strictMono_y a1 (lt_trans zero_lt_one m1) have b1 : 1 < b := have : xn a1 1 < u := strictMono_x a1 m1 have : a < u := by simpa using this lt_of_lt_of_le a1 <| by delta ModEq at ba; rw [Nat.mod_eq_of_lt this] at ba; rw [← ba] apply Nat.mod_le let s := xn b1 k let t := yn b1 k have sx : s ≡ x [MOD u] := (xy_modEq_of_modEq b1 a1 ba k).left have tk : t ≡ k [MOD 4 * y] := have : 4 * y ∣ b - 1 := Int.natCast_dvd_natCast.1 <| by rw [Int.ofNat_sub (le_of_lt b1)]; exact bm1.symm.dvd (yn_modEq_a_sub_one _ _).of_dvd this ⟹ky, Or.inr ⟹u, v, s, t, b, pell_eq _ _, pell_eq _ _, pell_eq _ _, b1, bm1, ba, vp, yv, sx, tk⟩⟩, fun ⟹a1, ky, o⟩ => ⟹a1, match o with | Or.inl ⟹x1, y0⟩ => by rw [y0] at ky; rw [Nat.eq_zero_of_le_zero ky, x1, y0]; exact ⟹rfl, rfl⟩ | Or.inr ⟹u, v, s, t, b, xy, uv, st, b1, rem⟩ => match x, y, eq_pell a1 xy, u, v, eq_pell a1 uv, s, t, eq_pell b1 st, rem, ky with | _, _, ⟹i, rfl, rfl⟩, _, _, ⟹n, rfl, rfl⟩, _, _, ⟹j, rfl, rfl⟩, ⟹(bm1 : b ≡ 1 [MOD 4 * yn a1 i]), (ba : b ≡ a [MOD xn a1 n]), (vp : 0 < yn a1 n), (yv : yn a1 i * yn a1 i ∣ yn a1 n), (sx : xn b1 j ≡ xn a1 i [MOD xn a1 n]), (tk : yn b1 j ≡ k [MOD 4 * yn a1 i])⟩, (ky : k ≀ yn a1 i) => (Nat.eq_zero_or_pos i).elim (fun i0 => by simp only [i0, yn_zero, nonpos_iff_eq_zero] at ky; rw [i0, ky]; exact ⟹rfl, rfl⟩)
fun ipos => by suffices i = k by rw [this]; exact ⟹rfl, rfl⟩ clear o rem xy uv st have iln : i ≀ n := le_of_not_gt fun hin => not_lt_of_ge (Nat.le_of_dvd vp (dvd_of_mul_left_dvd yv)) (strictMono_y a1 hin) have yd : 4 * yn a1 i ∣ 4 * n := mul_dvd_mul_left _ <| dvd_of_ysq_dvd a1 yv have jk : j ≡ k [MOD 4 * yn a1 i] := have : 4 * yn a1 i ∣ b - 1 := Int.natCast_dvd_natCast.1 <| by rw [Int.ofNat_sub (le_of_lt b1)]; exact bm1.symm.dvd ((yn_modEq_a_sub_one b1 _).of_dvd this).symm.trans tk have ki : k + i < 4 * yn a1 i := lt_of_le_of_lt (_root_.add_le_add ky (yn_ge_n a1 i)) <| by rw [← two_mul] exact Nat.mul_lt_mul_of_pos_right (by decide) (strictMono_y a1 ipos) have ji : j ≡ i [MOD 4 * n] := have : xn a1 j ≡ xn a1 i [MOD xn a1 n] := (xy_modEq_of_modEq b1 a1 ba j).left.symm.trans sx (modEq_of_xn_modEq a1 ipos iln this).resolve_right fun ji : j + i ≡ 0 [MOD 4 * n] => not_le_of_gt ki <|
Mathlib/NumberTheory/PellMatiyasevic.lean
800
820
/- 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] 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 _ · intro x rw [Set.mem_smul_set, Seminorm.mem_ball_zero] refine fun hx => ⟹k⁻¹ • x, ?_, ?_⟩ · rwa [Seminorm.mem_ball_zero, map_smul_eq_mul, norm_inv, ← mul_lt_mul_left <| norm_pos_iff.mpr hk, ← mul_assoc, ← div_eq_mul_inv ‖k‖ ‖k‖, div_self (ne_of_gt <| norm_pos_iff.mpr hk), one_mul] rw [← smul_assoc, smul_eq_mul, ← div_eq_mul_inv, div_self hk, one_smul] theorem smul_ball_zero {p : Seminorm 𝕜 E} {k : 𝕜} {r : ℝ} (hk : k ≠ 0) : k • p.ball 0 r = p.ball 0 (‖k‖ * r) := by ext rw [mem_smul_set_iff_inv_smul_mem₀ hk, p.mem_ball_zero, p.mem_ball_zero, map_smul_eq_mul, norm_inv, ← div_eq_inv_mul, div_lt_iff₀ (norm_pos_iff.2 hk), mul_comm] theorem smul_closedBall_subset {p : Seminorm 𝕜 E} {k : 𝕜} {r : ℝ} : k • p.closedBall 0 r ⊆ p.closedBall 0 (‖k‖ * r) := by rintro x ⟹y, hy, h⟩ rw [Seminorm.mem_closedBall_zero, ← h, map_smul_eq_mul] rw [Seminorm.mem_closedBall_zero] at hy gcongr theorem smul_closedBall_zero {p : Seminorm 𝕜 E} {k : 𝕜} {r : ℝ} (hk : 0 < ‖k‖) : k • p.closedBall 0 r = p.closedBall 0 (‖k‖ * r) := by refine subset_antisymm smul_closedBall_subset ?_ intro x rw [Set.mem_smul_set, Seminorm.mem_closedBall_zero] refine fun hx => ⟹k⁻¹ • x, ?_, ?_⟩ · rwa [Seminorm.mem_closedBall_zero, map_smul_eq_mul, norm_inv, ← mul_le_mul_left hk, ← mul_assoc, ← div_eq_mul_inv ‖k‖ ‖k‖, div_self (ne_of_gt hk), one_mul] rw [← smul_assoc, smul_eq_mul, ← div_eq_mul_inv, div_self (norm_pos_iff.mp hk), one_smul] theorem ball_zero_absorbs_ball_zero (p : Seminorm 𝕜 E) {r₁ r₂ : ℝ} (hr₁ : 0 < r₁) : Absorbs 𝕜 (p.ball 0 r₁) (p.ball 0 r₂) := by rcases exists_pos_lt_mul hr₁ r₂ with ⟹r, hr₀, hr⟩ refine .of_norm ⟹r, fun a ha x hx => ?_⟩ rw [smul_ball_zero (norm_pos_iff.1 <| hr₀.trans_le ha), p.mem_ball_zero] rw [p.mem_ball_zero] at hx exact hx.trans (hr.trans_le <| by gcongr) /-- Seminorm-balls at the origin are absorbent. -/ protected theorem absorbent_ball_zero (hr : 0 < r) : Absorbent 𝕜 (ball p (0 : E) r) := absorbent_iff_forall_absorbs_singleton.2 fun _ => (p.ball_zero_absorbs_ball_zero hr).mono_right <| singleton_subset_iff.2 <| p.mem_ball_zero.2 <| lt_add_one _ /-- Closed seminorm-balls at the origin are absorbent. -/ protected theorem absorbent_closedBall_zero (hr : 0 < r) : Absorbent 𝕜 (closedBall p (0 : E) r) := (p.absorbent_ball_zero hr).mono (p.ball_subset_closedBall _ _) /-- Seminorm-balls containing the origin are absorbent. -/ protected theorem absorbent_ball (hpr : p x < r) : Absorbent 𝕜 (ball p x r) := by refine (p.absorbent_ball_zero <| sub_pos.2 hpr).mono fun y hy => ?_ rw [p.mem_ball_zero] at hy exact p.mem_ball.2 ((map_sub_le_add p _ _).trans_lt <| add_lt_of_lt_sub_right hy) /-- Seminorm-balls containing the origin are absorbent. -/ protected theorem absorbent_closedBall (hpr : p x < r) : Absorbent 𝕜 (closedBall p x r) := by refine (p.absorbent_closedBall_zero <| sub_pos.2 hpr).mono fun y hy => ?_ rw [p.mem_closedBall_zero] at hy exact p.mem_closedBall.2 ((map_sub_le_add p _ _).trans <| add_le_of_le_sub_right hy) @[simp] theorem smul_ball_preimage (p : Seminorm 𝕜 E) (y : E) (r : ℝ) (a : 𝕜) (ha : a ≠ 0) : (a • ·) ⁻¹' p.ball y r = p.ball (a⁻¹ • y) (r / ‖a‖) := Set.ext fun _ => by rw [mem_preimage, mem_ball, mem_ball, lt_div_iff₀ (norm_pos_iff.mpr ha), mul_comm, ← map_smul_eq_mul p, smul_sub, smul_inv_smul₀ ha] @[simp] theorem smul_closedBall_preimage (p : Seminorm 𝕜 E) (y : E) (r : ℝ) (a : 𝕜) (ha : a ≠ 0) : (a • ·) ⁻¹' p.closedBall y r = p.closedBall (a⁻¹ • y) (r / ‖a‖) := Set.ext fun _ => by rw [mem_preimage, mem_closedBall, mem_closedBall, le_div_iff₀ (norm_pos_iff.mpr ha), mul_comm, ← map_smul_eq_mul p, smul_sub, smul_inv_smul₀ ha] end NormedField section Convex variable [NormedField 𝕜] [AddCommGroup E] [NormedSpace ℝ 𝕜] [Module 𝕜 E] section SMul variable [SMul ℝ E] [IsScalarTower ℝ 𝕜 E] (p : Seminorm 𝕜 E) /-- A seminorm is convex. Also see `convexOn_norm`. -/ protected theorem convexOn : ConvexOn ℝ univ p := by refine ⟹convex_univ, fun x _ y _ a b ha hb _ => ?_⟩ calc p (a • x + b • y) ≀ p (a • x) + p (b • y) := map_add_le_add p _ _ _ = ‖a • (1 : 𝕜)‖ * p x + ‖b • (1 : 𝕜)‖ * p y := by rw [← map_smul_eq_mul p, ← map_smul_eq_mul p, smul_one_smul, smul_one_smul] _ = a * p x + b * p y := by rw [norm_smul, norm_smul, norm_one, mul_one, mul_one, Real.norm_of_nonneg ha, Real.norm_of_nonneg hb] end SMul section Module variable [Module ℝ E] [IsScalarTower ℝ 𝕜 E] (p : Seminorm 𝕜 E) (x : E) (r : ℝ) /-- Seminorm-balls are convex. -/ theorem convex_ball : Convex ℝ (ball p x r) := by convert (p.convexOn.translate_left (-x)).convex_lt r ext y rw [preimage_univ, sep_univ, p.mem_ball, sub_eq_add_neg] rfl /-- Closed seminorm-balls are convex. -/ theorem convex_closedBall : Convex ℝ (closedBall p x r) := by rw [closedBall_eq_biInter_ball] exact convex_iInter₂ fun _ _ => convex_ball _ _ _ end Module end Convex section RestrictScalars variable (𝕜) {𝕜' : Type*} [NormedField 𝕜] [SeminormedRing 𝕜'] [NormedAlgebra 𝕜 𝕜'] [NormOneClass 𝕜'] [AddCommGroup E] [Module 𝕜' E] [SMul 𝕜 E] [IsScalarTower 𝕜 𝕜' E] /-- Reinterpret a seminorm over a field `𝕜'` as a seminorm over a smaller field `𝕜`. This will typically be used with `RCLike 𝕜'` and `𝕜 = ℝ`. -/ protected def restrictScalars (p : Seminorm 𝕜' E) : Seminorm 𝕜 E := { p with smul' := fun a x => by rw [← smul_one_smul 𝕜' a x, p.smul', norm_smul, norm_one, mul_one] } @[simp] theorem coe_restrictScalars (p : Seminorm 𝕜' E) : (p.restrictScalars 𝕜 : E → ℝ) = p := rfl @[simp] theorem restrictScalars_ball (p : Seminorm 𝕜' E) : (p.restrictScalars 𝕜).ball = p.ball := rfl @[simp] theorem restrictScalars_closedBall (p : Seminorm 𝕜' E) : (p.restrictScalars 𝕜).closedBall = p.closedBall := rfl end RestrictScalars /-! ### Continuity criterions for seminorms -/ section Continuity variable [NontriviallyNormedField 𝕜] [SeminormedRing 𝕝] [AddCommGroup E] [Module 𝕜 E] variable [Module 𝕝 E] /-- A seminorm is continuous at `0` if `p.closedBall 0 r ∈ 𝓝 0` for *all* `r > 0`. Over a `NontriviallyNormedField` it is actually enough to check that this is true for *some* `r`, see `Seminorm.continuousAt_zero'`. -/ theorem continuousAt_zero_of_forall' [TopologicalSpace E] {p : Seminorm 𝕝 E} (hp : ∀ r > 0, p.closedBall 0 r ∈ (𝓝 0 : Filter E)) : ContinuousAt p 0 := by simp_rw [Seminorm.closedBall_zero_eq_preimage_closedBall] at hp rwa [ContinuousAt, Metric.nhds_basis_closedBall.tendsto_right_iff, map_zero] theorem continuousAt_zero' [TopologicalSpace E] [ContinuousConstSMul 𝕜 E] {p : Seminorm 𝕜 E} {r : ℝ} (hp : p.closedBall 0 r ∈ (𝓝 0 : Filter E)) : ContinuousAt p 0 := by refine continuousAt_zero_of_forall' fun ε hε ↩ ?_ obtain ⟹k, hk₀, hk⟩ : ∃ k : 𝕜, 0 < ‖k‖ ∧ ‖k‖ * r < ε := by rcases le_or_lt r 0 with hr | hr · use 1; simpa using hr.trans_lt hε · simpa [lt_div_iff₀ hr] using exists_norm_lt 𝕜 (div_pos hε hr) rw [← set_smul_mem_nhds_zero_iff (norm_pos_iff.1 hk₀), smul_closedBall_zero hk₀] at hp exact mem_of_superset hp <| p.closedBall_mono hk.le /-- A seminorm is continuous at `0` if `p.ball 0 r ∈ 𝓝 0` for *all* `r > 0`. Over a `NontriviallyNormedField` it is actually enough to check that this is true for *some* `r`, see `Seminorm.continuousAt_zero'`. -/ theorem continuousAt_zero_of_forall [TopologicalSpace E] {p : Seminorm 𝕝 E} (hp : ∀ r > 0, p.ball 0 r ∈ (𝓝 0 : Filter E)) : ContinuousAt p 0 := continuousAt_zero_of_forall' (fun r hr ↩ Filter.mem_of_superset (hp r hr) <| p.ball_subset_closedBall _ _) theorem continuousAt_zero [TopologicalSpace E] [ContinuousConstSMul 𝕜 E] {p : Seminorm 𝕜 E} {r : ℝ} (hp : p.ball 0 r ∈ (𝓝 0 : Filter E)) : ContinuousAt p 0 := continuousAt_zero' (Filter.mem_of_superset hp <| p.ball_subset_closedBall _ _) protected theorem uniformContinuous_of_continuousAt_zero [UniformSpace E] [IsUniformAddGroup E] {p : Seminorm 𝕝 E} (hp : ContinuousAt p 0) : UniformContinuous p := by have hp : Filter.Tendsto p (𝓝 0) (𝓝 0) := map_zero p ▾ hp rw [UniformContinuous, uniformity_eq_comap_nhds_zero_swapped, Metric.uniformity_eq_comap_nhds_zero, Filter.tendsto_comap_iff] exact tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds (hp.comp Filter.tendsto_comap) (fun xy => dist_nonneg) fun xy => p.norm_sub_map_le_sub _ _ protected theorem continuous_of_continuousAt_zero [TopologicalSpace E] [IsTopologicalAddGroup E] {p : Seminorm 𝕝 E} (hp : ContinuousAt p 0) : Continuous p := by letI := IsTopologicalAddGroup.toUniformSpace E haveI : IsUniformAddGroup E := isUniformAddGroup_of_addCommGroup exact (Seminorm.uniformContinuous_of_continuousAt_zero hp).continuous /-- A seminorm is uniformly continuous if `p.ball 0 r ∈ 𝓝 0` for *all* `r > 0`. Over a `NontriviallyNormedField` it is actually enough to check that this is true for *some* `r`, see `Seminorm.uniformContinuous`. -/ protected theorem uniformContinuous_of_forall [UniformSpace E] [IsUniformAddGroup E] {p : Seminorm 𝕝 E} (hp : ∀ r > 0, p.ball 0 r ∈ (𝓝 0 : Filter E)) : UniformContinuous p := Seminorm.uniformContinuous_of_continuousAt_zero (continuousAt_zero_of_forall hp) protected theorem uniformContinuous [UniformSpace E] [IsUniformAddGroup E] [ContinuousConstSMul 𝕜 E] {p : Seminorm 𝕜 E} {r : ℝ} (hp : p.ball 0 r ∈ (𝓝 0 : Filter E)) : UniformContinuous p := Seminorm.uniformContinuous_of_continuousAt_zero (continuousAt_zero hp) /-- A seminorm is uniformly continuous if `p.closedBall 0 r ∈ 𝓝 0` for *all* `r > 0`. Over a `NontriviallyNormedField` it is actually enough to check that this is true for *some* `r`, see `Seminorm.uniformContinuous'`. -/ protected theorem uniformContinuous_of_forall' [UniformSpace E] [IsUniformAddGroup E] {p : Seminorm 𝕝 E} (hp : ∀ r > 0, p.closedBall 0 r ∈ (𝓝 0 : Filter E)) : UniformContinuous p := Seminorm.uniformContinuous_of_continuousAt_zero (continuousAt_zero_of_forall' hp) protected theorem uniformContinuous' [UniformSpace E] [IsUniformAddGroup E] [ContinuousConstSMul 𝕜 E] {p : Seminorm 𝕜 E} {r : ℝ} (hp : p.closedBall 0 r ∈ (𝓝 0 : Filter E)) : UniformContinuous p := Seminorm.uniformContinuous_of_continuousAt_zero (continuousAt_zero' hp) /-- A seminorm is continuous if `p.ball 0 r ∈ 𝓝 0` for *all* `r > 0`. Over a `NontriviallyNormedField` it is actually enough to check that this is true for *some* `r`, see `Seminorm.continuous`. -/ protected theorem continuous_of_forall [TopologicalSpace E] [IsTopologicalAddGroup E] {p : Seminorm 𝕝 E} (hp : ∀ r > 0, p.ball 0 r ∈ (𝓝 0 : Filter E)) : Continuous p := Seminorm.continuous_of_continuousAt_zero (continuousAt_zero_of_forall hp) protected theorem continuous [TopologicalSpace E] [IsTopologicalAddGroup E] [ContinuousConstSMul 𝕜 E] {p : Seminorm 𝕜 E} {r : ℝ} (hp : p.ball 0 r ∈ (𝓝 0 : Filter E)) : Continuous p := Seminorm.continuous_of_continuousAt_zero (continuousAt_zero hp) /-- A seminorm is continuous if `p.closedBall 0 r ∈ 𝓝 0` for *all* `r > 0`. Over a `NontriviallyNormedField` it is actually enough to check that this is true for *some* `r`, see `Seminorm.continuous'`. -/ protected theorem continuous_of_forall' [TopologicalSpace E] [IsTopologicalAddGroup E] {p : Seminorm 𝕝 E} (hp : ∀ r > 0, p.closedBall 0 r ∈ (𝓝 0 : Filter E)) : Continuous p := Seminorm.continuous_of_continuousAt_zero (continuousAt_zero_of_forall' hp) protected theorem continuous' [TopologicalSpace E] [IsTopologicalAddGroup E] [ContinuousConstSMul 𝕜 E] {p : Seminorm 𝕜 E} {r : ℝ} (hp : p.closedBall 0 r ∈ (𝓝 0 : Filter E)) : Continuous p := Seminorm.continuous_of_continuousAt_zero (continuousAt_zero' hp) theorem continuous_of_le [TopologicalSpace E] [IsTopologicalAddGroup E] {p q : Seminorm 𝕝 E} (hq : Continuous q) (hpq : p ≀ q) : Continuous p := by refine Seminorm.continuous_of_forall (fun r hr ↩ Filter.mem_of_superset (IsOpen.mem_nhds ?_ <| q.mem_ball_self hr) (ball_antitone hpq)) rw [ball_zero_eq] exact isOpen_lt hq continuous_const lemma ball_mem_nhds [TopologicalSpace E] {p : Seminorm 𝕝 E} (hp : Continuous p) {r : ℝ} (hr : 0 < r) : p.ball 0 r ∈ (𝓝 0 : Filter E) := have this : Tendsto p (𝓝 0) (𝓝 0) := map_zero p ▾ hp.tendsto 0 by simpa only [p.ball_zero_eq] using this (Iio_mem_nhds hr) lemma uniformSpace_eq_of_hasBasis {ι} [UniformSpace E] [IsUniformAddGroup E] [ContinuousConstSMul 𝕜 E] {p' : ι → Prop} {s : ι → Set E} (p : Seminorm 𝕜 E) (hb : (𝓝 0 : Filter E).HasBasis p' s)
(h₁ : ∃ r, p.closedBall 0 r ∈ 𝓝 0) (h₂ : ∀ i, p' i → ∃ r > 0, p.ball 0 r ⊆ s i) : ‹UniformSpace E› = p.toAddGroupSeminorm.toSeminormedAddGroup.toUniformSpace := by refine IsUniformAddGroup.ext ‹_› p.toAddGroupSeminorm.toSeminormedAddCommGroup.to_isUniformAddGroup ?_ apply le_antisymm · rw [← @comap_norm_nhds_zero E p.toAddGroupSeminorm.toSeminormedAddGroup, ← tendsto_iff_comap] suffices Continuous p from this.tendsto' 0 _ (map_zero p) rcases h₁ with ⟹r, hr⟩ exact p.continuous' hr
Mathlib/Analysis/Seminorm.lean
1,161
1,169
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot -/ import Mathlib.Order.Filter.SmallSets import Mathlib.Topology.UniformSpace.Defs import Mathlib.Topology.ContinuousOn /-! # Basic results on uniform spaces Uniform spaces are a generalization of metric spaces and topological groups. ## Main definitions In this file we define a complete lattice structure on the type `UniformSpace X` of uniform structures on `X`, as well as the pullback (`UniformSpace.comap`) of uniform structures coming from the pullback of filters. Like distance functions, uniform structures cannot be pushed forward in general. ## Notations Localized in `Uniformity`, we have the notation `𝓀 X` for the uniformity on a uniform space `X`, and `○` for composition of relations, seen as terms with type `Set (X × X)`. ## References The formalization uses the books: * [N. Bourbaki, *General Topology*][bourbaki1966] * [I. M. James, *Topologies and Uniformities*][james1999] But it makes a more systematic use of the filter library. -/ open Set Filter Topology universe u v ua ub uc ud /-! ### Relations, seen as `Set (α × α)` -/ variable {α : Type ua} {β : Type ub} {γ : Type uc} {ÎŽ : Type ud} {ι : Sort*} open Uniformity section UniformSpace variable [UniformSpace α] /-- If `s ∈ 𝓀 α`, then for any natural `n`, for a subset `t` of a sufficiently small set in `𝓀 α`, we have `t ○ t ○ ... ○ t ⊆ s` (`n` compositions). -/ theorem eventually_uniformity_iterate_comp_subset {s : Set (α × α)} (hs : s ∈ 𝓀 α) (n : ℕ) : ∀ᶠ t in (𝓀 α).smallSets, (t ○ ·)^[n] t ⊆ s := by suffices ∀ᶠ t in (𝓀 α).smallSets, t ⊆ s ∧ (t ○ ·)^[n] t ⊆ s from (eventually_and.1 this).2 induction n generalizing s with | zero => simpa | succ _ ihn => rcases comp_mem_uniformity_sets hs with ⟹t, htU, hts⟩ refine (ihn htU).mono fun U hU => ?_ rw [Function.iterate_succ_apply'] exact ⟹hU.1.trans <| (subset_comp_self <| refl_le_uniformity htU).trans hts, (compRel_mono hU.1 hU.2).trans hts⟩ /-- If `s ∈ 𝓀 α`, then for a subset `t` of a sufficiently small set in `𝓀 α`, we have `t ○ t ⊆ s`. -/ theorem eventually_uniformity_comp_subset {s : Set (α × α)} (hs : s ∈ 𝓀 α) : ∀ᶠ t in (𝓀 α).smallSets, t ○ t ⊆ s := eventually_uniformity_iterate_comp_subset hs 1 /-! ### Balls in uniform spaces -/ namespace UniformSpace open UniformSpace (ball) lemma isOpen_ball (x : α) {V : Set (α × α)} (hV : IsOpen V) : IsOpen (ball x V) := hV.preimage <| .prodMk_right _ lemma isClosed_ball (x : α) {V : Set (α × α)} (hV : IsClosed V) : IsClosed (ball x V) := hV.preimage <| .prodMk_right _ /-! ### Neighborhoods in uniform spaces -/ theorem hasBasis_nhds_prod (x y : α) : HasBasis (𝓝 (x, y)) (fun s => s ∈ 𝓀 α ∧ IsSymmetricRel s) fun s => ball x s ×ˢ ball y s := by rw [nhds_prod_eq] apply (hasBasis_nhds x).prod_same_index (hasBasis_nhds y) rintro U V ⟹U_in, U_symm⟩ ⟹V_in, V_symm⟩ exact ⟹U ∩ V, ⟹(𝓀 α).inter_sets U_in V_in, U_symm.inter V_symm⟩, ball_inter_left x U V, ball_inter_right y U V⟩ end UniformSpace open UniformSpace theorem nhds_eq_uniformity_prod {a b : α} : 𝓝 (a, b) = (𝓀 α).lift' fun s : Set (α × α) => { y : α | (y, a) ∈ s } ×ˢ { y : α | (b, y) ∈ s } := by rw [nhds_prod_eq, nhds_nhds_eq_uniformity_uniformity_prod, lift_lift'_same_eq_lift'] · exact fun s => monotone_const.set_prod monotone_preimage · refine fun t => Monotone.set_prod ?_ monotone_const exact monotone_preimage (f := fun y => (y, a)) theorem nhdset_of_mem_uniformity {d : Set (α × α)} (s : Set (α × α)) (hd : d ∈ 𝓀 α) : ∃ t : Set (α × α), IsOpen t ∧ s ⊆ t ∧ t ⊆ { p | ∃ x y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d } := by let cl_d := { p : α × α | ∃ x y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d } have : ∀ p ∈ s, ∃ t, t ⊆ cl_d ∧ IsOpen t ∧ p ∈ t := fun ⟹x, y⟩ hp => mem_nhds_iff.mp <| show cl_d ∈ 𝓝 (x, y) by rw [nhds_eq_uniformity_prod, mem_lift'_sets] · exact ⟹d, hd, fun ⟹a, b⟩ ⟹ha, hb⟩ => ⟹x, y, ha, hp, hb⟩⟩ · exact fun _ _ h _ h' => ⟹h h'.1, h h'.2⟩ choose t ht using this exact ⟹(⋃ p : α × α, ⋃ h : p ∈ s, t p h : Set (α × α)), isOpen_iUnion fun p : α × α => isOpen_iUnion fun hp => (ht p hp).right.left, fun ⟹a, b⟩ hp => by simp only [mem_iUnion, Prod.exists]; exact ⟹a, b, hp, (ht (a, b) hp).right.right⟩, iUnion_subset fun p => iUnion_subset fun hp => (ht p hp).left⟩ /-- Entourages are neighborhoods of the diagonal. -/ theorem nhds_le_uniformity (x : α) : 𝓝 (x, x) ≀ 𝓀 α := by intro V V_in rcases comp_symm_mem_uniformity_sets V_in with ⟹w, w_in, w_symm, w_sub⟩ have : ball x w ×ˢ ball x w ∈ 𝓝 (x, x) := by rw [nhds_prod_eq] exact prod_mem_prod (ball_mem_nhds x w_in) (ball_mem_nhds x w_in) apply mem_of_superset this rintro ⟹u, v⟩ ⟹u_in, v_in⟩ exact w_sub (mem_comp_of_mem_ball w_symm u_in v_in) /-- Entourages are neighborhoods of the diagonal. -/ theorem iSup_nhds_le_uniformity : ⹆ x : α, 𝓝 (x, x) ≀ 𝓀 α := iSup_le nhds_le_uniformity /-- Entourages are neighborhoods of the diagonal. -/ theorem nhdsSet_diagonal_le_uniformity : 𝓝ˢ (diagonal α) ≀ 𝓀 α := (nhdsSet_diagonal α).trans_le iSup_nhds_le_uniformity section variable (α) theorem UniformSpace.has_seq_basis [IsCountablyGenerated <| 𝓀 α] : ∃ V : ℕ → Set (α × α), HasAntitoneBasis (𝓀 α) V ∧ ∀ n, IsSymmetricRel (V n) := let ⟹U, hsym, hbasis⟩ := (@UniformSpace.hasBasis_symmetric α _).exists_antitone_subbasis ⟹U, hbasis, fun n => (hsym n).2⟩ end /-! ### Closure and interior in uniform spaces -/ theorem closure_eq_uniformity (s : Set <| α × α) : closure s = ⋂ V ∈ { V | V ∈ 𝓀 α ∧ IsSymmetricRel V }, V ○ s ○ V := by ext ⟹x, y⟩ simp +contextual only [mem_closure_iff_nhds_basis (UniformSpace.hasBasis_nhds_prod x y), mem_iInter, mem_setOf_eq, and_imp, mem_comp_comp, exists_prop, ← mem_inter_iff, inter_comm, Set.Nonempty] theorem uniformity_hasBasis_closed : HasBasis (𝓀 α) (fun V : Set (α × α) => V ∈ 𝓀 α ∧ IsClosed V) id := by refine Filter.hasBasis_self.2 fun t h => ?_ rcases comp_comp_symm_mem_uniformity_sets h with ⟹w, w_in, w_symm, r⟩ refine ⟹closure w, mem_of_superset w_in subset_closure, isClosed_closure, ?_⟩ refine Subset.trans ?_ r rw [closure_eq_uniformity] apply iInter_subset_of_subset apply iInter_subset exact ⟹w_in, w_symm⟩ theorem uniformity_eq_uniformity_closure : 𝓀 α = (𝓀 α).lift' closure := Eq.symm <| uniformity_hasBasis_closed.lift'_closure_eq_self fun _ => And.right theorem Filter.HasBasis.uniformity_closure {p : ι → Prop} {U : ι → Set (α × α)} (h : (𝓀 α).HasBasis p U) : (𝓀 α).HasBasis p fun i => closure (U i) := (@uniformity_eq_uniformity_closure α _).symm ▾ h.lift'_closure /-- Closed entourages form a basis of the uniformity filter. -/ theorem uniformity_hasBasis_closure : HasBasis (𝓀 α) (fun V : Set (α × α) => V ∈ 𝓀 α) closure := (𝓀 α).basis_sets.uniformity_closure theorem closure_eq_inter_uniformity {t : Set (α × α)} : closure t = ⋂ d ∈ 𝓀 α, d ○ (t ○ d) := calc closure t = ⋂ (V) (_ : V ∈ 𝓀 α ∧ IsSymmetricRel V), V ○ t ○ V := closure_eq_uniformity t _ = ⋂ V ∈ 𝓀 α, V ○ t ○ V := Eq.symm <| UniformSpace.hasBasis_symmetric.biInter_mem fun _ _ hV => compRel_mono (compRel_mono hV Subset.rfl) hV _ = ⋂ V ∈ 𝓀 α, V ○ (t ○ V) := by simp only [compRel_assoc] theorem uniformity_eq_uniformity_interior : 𝓀 α = (𝓀 α).lift' interior := le_antisymm (le_iInf₂ fun d hd => by let ⟹s, hs, hs_comp⟩ := comp3_mem_uniformity hd let ⟹t, ht, hst, ht_comp⟩ := nhdset_of_mem_uniformity s hs have : s ⊆ interior d := calc s ⊆ t := hst _ ⊆ interior d := ht.subset_interior_iff.mpr fun x (hx : x ∈ t) => let ⟹x, y, h₁, h₂, h₃⟩ := ht_comp hx hs_comp ⟹x, h₁, y, h₂, h₃⟩ have : interior d ∈ 𝓀 α := by filter_upwards [hs] using this simp [this]) fun _ hs => ((𝓀 α).lift' interior).sets_of_superset (mem_lift' hs) interior_subset theorem interior_mem_uniformity {s : Set (α × α)} (hs : s ∈ 𝓀 α) : interior s ∈ 𝓀 α := by rw [uniformity_eq_uniformity_interior]; exact mem_lift' hs theorem mem_uniformity_isClosed {s : Set (α × α)} (h : s ∈ 𝓀 α) : ∃ t ∈ 𝓀 α, IsClosed t ∧ t ⊆ s := let ⟹t, ⟹ht_mem, htc⟩, hts⟩ := uniformity_hasBasis_closed.mem_iff.1 h ⟹t, ht_mem, htc, hts⟩ theorem isOpen_iff_isOpen_ball_subset {s : Set α} : IsOpen s ↔ ∀ x ∈ s, ∃ V ∈ 𝓀 α, IsOpen V ∧ ball x V ⊆ s := by rw [isOpen_iff_ball_subset] constructor <;> intro h x hx · obtain ⟹V, hV, hV'⟩ := h x hx exact ⟹interior V, interior_mem_uniformity hV, isOpen_interior, (ball_mono interior_subset x).trans hV'⟩ · obtain ⟹V, hV, -, hV'⟩ := h x hx exact ⟹V, hV, hV'⟩ @[deprecated (since := "2024-11-18")] alias isOpen_iff_open_ball_subset := isOpen_iff_isOpen_ball_subset /-- The uniform neighborhoods of all points of a dense set cover the whole space. -/ theorem Dense.biUnion_uniformity_ball {s : Set α} {U : Set (α × α)} (hs : Dense s) (hU : U ∈ 𝓀 α) : ⋃ x ∈ s, ball x U = univ := by refine iUnion₂_eq_univ_iff.2 fun y => ?_ rcases hs.inter_nhds_nonempty (mem_nhds_right y hU) with ⟹x, hxs, hxy : (x, y) ∈ U⟩ exact ⟹x, hxs, hxy⟩ /-- The uniform neighborhoods of all points of a dense indexed collection cover the whole space. -/ lemma DenseRange.iUnion_uniformity_ball {ι : Type*} {xs : ι → α} (xs_dense : DenseRange xs) {U : Set (α × α)} (hU : U ∈ uniformity α) : ⋃ i, UniformSpace.ball (xs i) U = univ := by rw [← biUnion_range (f := xs) (g := fun x ↩ UniformSpace.ball x U)] exact Dense.biUnion_uniformity_ball xs_dense hU /-! ### Uniformity bases -/ /-- Open elements of `𝓀 α` form a basis of `𝓀 α`. -/ theorem uniformity_hasBasis_open : HasBasis (𝓀 α) (fun V : Set (α × α) => V ∈ 𝓀 α ∧ IsOpen V) id := hasBasis_self.2 fun s hs => ⟹interior s, interior_mem_uniformity hs, isOpen_interior, interior_subset⟩ theorem Filter.HasBasis.mem_uniformity_iff {p : β → Prop} {s : β → Set (α × α)} (h : (𝓀 α).HasBasis p s) {t : Set (α × α)} : t ∈ 𝓀 α ↔ ∃ i, p i ∧ ∀ a b, (a, b) ∈ s i → (a, b) ∈ t := h.mem_iff.trans <| by simp only [Prod.forall, subset_def] /-- Open elements `s : Set (α × α)` of `𝓀 α` such that `(x, y) ∈ s ↔ (y, x) ∈ s` form a basis of `𝓀 α`. -/ theorem uniformity_hasBasis_open_symmetric : HasBasis (𝓀 α) (fun V : Set (α × α) => V ∈ 𝓀 α ∧ IsOpen V ∧ IsSymmetricRel V) id := by simp only [← and_assoc] refine uniformity_hasBasis_open.restrict fun s hs => ⟹symmetrizeRel s, ?_⟩ exact ⟹⟹symmetrize_mem_uniformity hs.1, IsOpen.inter hs.2 (hs.2.preimage continuous_swap)⟩, symmetric_symmetrizeRel s, symmetrizeRel_subset_self s⟩ theorem comp_open_symm_mem_uniformity_sets {s : Set (α × α)} (hs : s ∈ 𝓀 α) : ∃ t ∈ 𝓀 α, IsOpen t ∧ IsSymmetricRel t ∧ t ○ t ⊆ s := by obtain ⟹t, ht₁, ht₂⟩ := comp_mem_uniformity_sets hs obtain ⟹u, ⟹hu₁, hu₂, hu₃⟩, hu₄ : u ⊆ t⟩ := uniformity_hasBasis_open_symmetric.mem_iff.mp ht₁ exact ⟹u, hu₁, hu₂, hu₃, (compRel_mono hu₄ hu₄).trans ht₂⟩ end UniformSpace open uniformity section Constructions instance : PartialOrder (UniformSpace α) := PartialOrder.lift (fun u => 𝓀[u]) fun _ _ => UniformSpace.ext protected theorem UniformSpace.le_def {u₁ u₂ : UniformSpace α} : u₁ ≀ u₂ ↔ 𝓀[u₁] ≀ 𝓀[u₂] := Iff.rfl instance : InfSet (UniformSpace α) := ⟹fun s => UniformSpace.ofCore { uniformity := ⹅ u ∈ s, 𝓀[u] refl := le_iInf fun u => le_iInf fun _ => u.toCore.refl symm := le_iInf₂ fun u hu => le_trans (map_mono <| iInf_le_of_le _ <| iInf_le _ hu) u.symm comp := le_iInf₂ fun u hu => le_trans (lift'_mono (iInf_le_of_le _ <| iInf_le _ hu) <| le_rfl) u.comp }⟩ protected theorem UniformSpace.sInf_le {tt : Set (UniformSpace α)} {t : UniformSpace α} (h : t ∈ tt) : sInf tt ≀ t := show ⹅ u ∈ tt, 𝓀[u] ≀ 𝓀[t] from iInf₂_le t h protected theorem UniformSpace.le_sInf {tt : Set (UniformSpace α)} {t : UniformSpace α} (h : ∀ t' ∈ tt, t ≀ t') : t ≀ sInf tt := show 𝓀[t] ≀ ⹅ u ∈ tt, 𝓀[u] from le_iInf₂ h instance : Top (UniformSpace α) := ⟹@UniformSpace.mk α ⊀ ⊀ le_top le_top fun x ↩ by simp only [nhds_top, comap_top]⟩ instance : Bot (UniformSpace α) := ⟹{ toTopologicalSpace := ⊥ uniformity := 𝓟 idRel symm := by simp [Tendsto] comp := lift'_le (mem_principal_self _) <| principal_mono.2 id_compRel.subset nhds_eq_comap_uniformity := fun s => by let _ : TopologicalSpace α := ⊥; have := discreteTopology_bot α simp [idRel] }⟩ instance : Min (UniformSpace α) := ⟹fun u₁ u₂ => { uniformity := 𝓀[u₁] ⊓ 𝓀[u₂] symm := u₁.symm.inf u₂.symm comp := (lift'_inf_le _ _ _).trans <| inf_le_inf u₁.comp u₂.comp toTopologicalSpace := u₁.toTopologicalSpace ⊓ u₂.toTopologicalSpace nhds_eq_comap_uniformity := fun _ ↩ by rw [@nhds_inf _ u₁.toTopologicalSpace _, @nhds_eq_comap_uniformity _ u₁, @nhds_eq_comap_uniformity _ u₂, comap_inf] }⟩ instance : CompleteLattice (UniformSpace α) := { inferInstanceAs (PartialOrder (UniformSpace α)) with sup := fun a b => sInf { x | a ≀ x ∧ b ≀ x } le_sup_left := fun _ _ => UniformSpace.le_sInf fun _ ⟹h, _⟩ => h le_sup_right := fun _ _ => UniformSpace.le_sInf fun _ ⟹_, h⟩ => h sup_le := fun _ _ _ h₁ h₂ => UniformSpace.sInf_le ⟹h₁, h₂⟩ inf := (· ⊓ ·) le_inf := fun a _ _ h₁ h₂ => show a.uniformity ≀ _ from le_inf h₁ h₂ inf_le_left := fun a _ => show _ ≀ a.uniformity from inf_le_left inf_le_right := fun _ b => show _ ≀ b.uniformity from inf_le_right top := ⊀ le_top := fun a => show a.uniformity ≀ ⊀ from le_top bot := ⊥ bot_le := fun u => u.toCore.refl sSup := fun tt => sInf { t | ∀ t' ∈ tt, t' ≀ t } le_sSup := fun _ _ h => UniformSpace.le_sInf fun _ h' => h' _ h sSup_le := fun _ _ h => UniformSpace.sInf_le h sInf := sInf le_sInf := fun _ _ hs => UniformSpace.le_sInf hs sInf_le := fun _ _ ha => UniformSpace.sInf_le ha } theorem iInf_uniformity {ι : Sort*} {u : ι → UniformSpace α} : 𝓀[iInf u] = ⹅ i, 𝓀[u i] := iInf_range theorem inf_uniformity {u v : UniformSpace α} : 𝓀[u ⊓ v] = 𝓀[u] ⊓ 𝓀[v] := rfl lemma bot_uniformity : 𝓀[(⊥ : UniformSpace α)] = 𝓟 idRel := rfl lemma top_uniformity : 𝓀[(⊀ : UniformSpace α)] = ⊀ := rfl instance inhabitedUniformSpace : Inhabited (UniformSpace α) := ⟚⊥⟩ instance inhabitedUniformSpaceCore : Inhabited (UniformSpace.Core α) := ⟹@UniformSpace.toCore _ default⟩ instance [Subsingleton α] : Unique (UniformSpace α) where uniq u := bot_unique <| le_principal_iff.2 <| by rw [idRel, ← diagonal, diagonal_eq_univ]; exact univ_mem /-- Given `f : α → β` and a uniformity `u` on `β`, the inverse image of `u` under `f` is the inverse image in the filter sense of the induced function `α × α → β × β`. See note [reducible non-instances]. -/ abbrev UniformSpace.comap (f : α → β) (u : UniformSpace β) : UniformSpace α where uniformity := 𝓀[u].comap fun p : α × α => (f p.1, f p.2) symm := by simp only [tendsto_comap_iff, Prod.swap, (· ∘ ·)] exact tendsto_swap_uniformity.comp tendsto_comap comp := le_trans (by rw [comap_lift'_eq, comap_lift'_eq2] · exact lift'_mono' fun s _ ⟹a₁, a₂⟩ ⟹x, h₁, h₂⟩ => ⟹f x, h₁, h₂⟩ · exact monotone_id.compRel monotone_id) (comap_mono u.comp) toTopologicalSpace := u.toTopologicalSpace.induced f nhds_eq_comap_uniformity x := by simp only [nhds_induced, nhds_eq_comap_uniformity, comap_comap, Function.comp_def] theorem uniformity_comap {_ : UniformSpace β} (f : α → β) : 𝓀[UniformSpace.comap f ‹_›] = comap (Prod.map f f) (𝓀 β) := rfl lemma ball_preimage {f : α → β} {U : Set (β × β)} {x : α} : UniformSpace.ball x (Prod.map f f ⁻¹' U) = f ⁻¹' UniformSpace.ball (f x) U := by ext : 1 simp only [UniformSpace.ball, mem_preimage, Prod.map_apply] @[simp] theorem uniformSpace_comap_id {α : Type*} : UniformSpace.comap (id : α → α) = id := by ext : 2 rw [uniformity_comap, Prod.map_id, comap_id] theorem UniformSpace.comap_comap {α β γ} {uγ : UniformSpace γ} {f : α → β} {g : β → γ} : UniformSpace.comap (g ∘ f) uγ = UniformSpace.comap f (UniformSpace.comap g uγ) := by ext1 simp only [uniformity_comap, Filter.comap_comap, Prod.map_comp_map] theorem UniformSpace.comap_inf {α γ} {u₁ u₂ : UniformSpace γ} {f : α → γ} : (u₁ ⊓ u₂).comap f = u₁.comap f ⊓ u₂.comap f := UniformSpace.ext Filter.comap_inf theorem UniformSpace.comap_iInf {ι α γ} {u : ι → UniformSpace γ} {f : α → γ} : (⹅ i, u i).comap f = ⹅ i, (u i).comap f := by ext : 1 simp [uniformity_comap, iInf_uniformity] theorem UniformSpace.comap_mono {α γ} {f : α → γ} : Monotone fun u : UniformSpace γ => u.comap f := fun _ _ hu => Filter.comap_mono hu theorem uniformContinuous_iff {α β} {uα : UniformSpace α} {uβ : UniformSpace β} {f : α → β} : UniformContinuous f ↔ uα ≀ uβ.comap f := Filter.map_le_iff_le_comap theorem le_iff_uniformContinuous_id {u v : UniformSpace α} : u ≀ v ↔ @UniformContinuous _ _ u v id := by rw [uniformContinuous_iff, uniformSpace_comap_id, id] theorem uniformContinuous_comap {f : α → β} [u : UniformSpace β] : @UniformContinuous α β (UniformSpace.comap f u) u f := tendsto_comap theorem uniformContinuous_comap' {f : γ → β} {g : α → γ} [v : UniformSpace β] [u : UniformSpace α] (h : UniformContinuous (f ∘ g)) : @UniformContinuous α γ u (UniformSpace.comap f v) g := tendsto_comap_iff.2 h namespace UniformSpace theorem to_nhds_mono {u₁ u₂ : UniformSpace α} (h : u₁ ≀ u₂) (a : α) : @nhds _ (@UniformSpace.toTopologicalSpace _ u₁) a ≀ @nhds _ (@UniformSpace.toTopologicalSpace _ u₂) a := by rw [@nhds_eq_uniformity α u₁ a, @nhds_eq_uniformity α u₂ a]; exact lift'_mono h le_rfl theorem toTopologicalSpace_mono {u₁ u₂ : UniformSpace α} (h : u₁ ≀ u₂) : @UniformSpace.toTopologicalSpace _ u₁ ≀ @UniformSpace.toTopologicalSpace _ u₂ := le_of_nhds_le_nhds <| to_nhds_mono h theorem toTopologicalSpace_comap {f : α → β} {u : UniformSpace β} : @UniformSpace.toTopologicalSpace _ (UniformSpace.comap f u) = TopologicalSpace.induced f (@UniformSpace.toTopologicalSpace β u) := rfl lemma uniformSpace_eq_bot {u : UniformSpace α} : u = ⊥ ↔ idRel ∈ 𝓀[u] := le_bot_iff.symm.trans le_principal_iff protected lemma _root_.Filter.HasBasis.uniformSpace_eq_bot {ι p} {s : ι → Set (α × α)} {u : UniformSpace α} (h : 𝓀[u].HasBasis p s) : u = ⊥ ↔ ∃ i, p i ∧ Pairwise fun x y : α ↩ (x, y) ∉ s i := by simp [uniformSpace_eq_bot, h.mem_iff, subset_def, Pairwise, not_imp_not] theorem toTopologicalSpace_bot : @UniformSpace.toTopologicalSpace α ⊥ = ⊥ := rfl theorem toTopologicalSpace_top : @UniformSpace.toTopologicalSpace α ⊀ = ⊀ := rfl theorem toTopologicalSpace_iInf {ι : Sort*} {u : ι → UniformSpace α} : (iInf u).toTopologicalSpace = ⹅ i, (u i).toTopologicalSpace := TopologicalSpace.ext_nhds fun a ↩ by simp only [@nhds_eq_comap_uniformity _ (iInf u), nhds_iInf, iInf_uniformity, @nhds_eq_comap_uniformity _ (u _), Filter.comap_iInf] theorem toTopologicalSpace_sInf {s : Set (UniformSpace α)} : (sInf s).toTopologicalSpace = ⹅ i ∈ s, @UniformSpace.toTopologicalSpace α i := by rw [sInf_eq_iInf] simp only [← toTopologicalSpace_iInf] theorem toTopologicalSpace_inf {u v : UniformSpace α} : (u ⊓ v).toTopologicalSpace = u.toTopologicalSpace ⊓ v.toTopologicalSpace := rfl end UniformSpace theorem UniformContinuous.continuous [UniformSpace α] [UniformSpace β] {f : α → β} (hf : UniformContinuous f) : Continuous f := continuous_iff_le_induced.mpr <| UniformSpace.toTopologicalSpace_mono <| uniformContinuous_iff.1 hf /-- Uniform space structure on `ULift α`. -/ instance ULift.uniformSpace [UniformSpace α] : UniformSpace (ULift α) := UniformSpace.comap ULift.down ‹_› /-- Uniform space structure on `αᵒᵈ`. -/ instance OrderDual.instUniformSpace [UniformSpace α] : UniformSpace (αᵒᵈ) := ‹UniformSpace α› section UniformContinuousInfi -- TODO: add an `iff` lemma? theorem UniformContinuous.inf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ u₃ : UniformSpace β} (h₁ : UniformContinuous[u₁, u₂] f) (h₂ : UniformContinuous[u₁, u₃] f) : UniformContinuous[u₁, u₂ ⊓ u₃] f := tendsto_inf.mpr ⟹h₁, h₂⟩ theorem UniformContinuous.inf_dom_left {f : α → β} {u₁ u₂ : UniformSpace α} {u₃ : UniformSpace β} (hf : UniformContinuous[u₁, u₃] f) : UniformContinuous[u₁ ⊓ u₂, u₃] f := tendsto_inf_left hf theorem UniformContinuous.inf_dom_right {f : α → β} {u₁ u₂ : UniformSpace α} {u₃ : UniformSpace β} (hf : UniformContinuous[u₂, u₃] f) : UniformContinuous[u₁ ⊓ u₂, u₃] f := tendsto_inf_right hf theorem uniformContinuous_sInf_dom {f : α → β} {u₁ : Set (UniformSpace α)} {u₂ : UniformSpace β} {u : UniformSpace α} (h₁ : u ∈ u₁) (hf : UniformContinuous[u, u₂] f) : UniformContinuous[sInf u₁, u₂] f := by delta UniformContinuous rw [sInf_eq_iInf', iInf_uniformity] exact tendsto_iInf' ⟹u, h₁⟩ hf theorem uniformContinuous_sInf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ : Set (UniformSpace β)} : UniformContinuous[u₁, sInf u₂] f ↔ ∀ u ∈ u₂, UniformContinuous[u₁, u] f := by delta UniformContinuous rw [sInf_eq_iInf', iInf_uniformity, tendsto_iInf, SetCoe.forall] theorem uniformContinuous_iInf_dom {f : α → β} {u₁ : ι → UniformSpace α} {u₂ : UniformSpace β} {i : ι} (hf : UniformContinuous[u₁ i, u₂] f) : UniformContinuous[iInf u₁, u₂] f := by delta UniformContinuous rw [iInf_uniformity] exact tendsto_iInf' i hf theorem uniformContinuous_iInf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ : ι → UniformSpace β} : UniformContinuous[u₁, iInf u₂] f ↔ ∀ i, UniformContinuous[u₁, u₂ i] f := by delta UniformContinuous rw [iInf_uniformity, tendsto_iInf] end UniformContinuousInfi /-- A uniform space with the discrete uniformity has the discrete topology. -/ theorem discreteTopology_of_discrete_uniformity [hα : UniformSpace α] (h : uniformity α = 𝓟 idRel) : DiscreteTopology α := ⟹(UniformSpace.ext h.symm : ⊥ = hα) ▾ rfl⟩ instance : UniformSpace Empty := ⊥ instance : UniformSpace PUnit := ⊥ instance : UniformSpace Bool := ⊥ instance : UniformSpace ℕ := ⊥ instance : UniformSpace â„€ := ⊥ section variable [UniformSpace α] open Additive Multiplicative instance : UniformSpace (Additive α) := ‹UniformSpace α› instance : UniformSpace (Multiplicative α) := ‹UniformSpace α› theorem uniformContinuous_ofMul : UniformContinuous (ofMul : α → Additive α) := uniformContinuous_id theorem uniformContinuous_toMul : UniformContinuous (toMul : Additive α → α) := uniformContinuous_id theorem uniformContinuous_ofAdd : UniformContinuous (ofAdd : α → Multiplicative α) := uniformContinuous_id theorem uniformContinuous_toAdd : UniformContinuous (toAdd : Multiplicative α → α) := uniformContinuous_id theorem uniformity_additive : 𝓀 (Additive α) = (𝓀 α).map (Prod.map ofMul ofMul) := rfl theorem uniformity_multiplicative : 𝓀 (Multiplicative α) = (𝓀 α).map (Prod.map ofAdd ofAdd) := rfl end instance instUniformSpaceSubtype {p : α → Prop} [t : UniformSpace α] : UniformSpace (Subtype p) := UniformSpace.comap Subtype.val t theorem uniformity_subtype {p : α → Prop} [UniformSpace α] : 𝓀 (Subtype p) = comap (fun q : Subtype p × Subtype p => (q.1.1, q.2.1)) (𝓀 α) := rfl theorem uniformity_setCoe {s : Set α} [UniformSpace α] : 𝓀 s = comap (Prod.map ((↑) : s → α) ((↑) : s → α)) (𝓀 α) := rfl theorem map_uniformity_set_coe {s : Set α} [UniformSpace α] : map (Prod.map (↑) (↑)) (𝓀 s) = 𝓀 α ⊓ 𝓟 (s ×ˢ s) := by rw [uniformity_setCoe, map_comap, range_prodMap, Subtype.range_val] theorem uniformContinuous_subtype_val {p : α → Prop} [UniformSpace α] : UniformContinuous (Subtype.val : { a : α // p a } → α) := uniformContinuous_comap theorem UniformContinuous.subtype_mk {p : α → Prop} [UniformSpace α] [UniformSpace β] {f : β → α} (hf : UniformContinuous f) (h : ∀ x, p (f x)) : UniformContinuous (fun x => ⟹f x, h x⟩ : β → Subtype p) := uniformContinuous_comap' hf theorem uniformContinuousOn_iff_restrict [UniformSpace α] [UniformSpace β] {f : α → β} {s : Set α} : UniformContinuousOn f s ↔ UniformContinuous (s.restrict f) := by delta UniformContinuousOn UniformContinuous rw [← map_uniformity_set_coe, tendsto_map'_iff]; rfl theorem tendsto_of_uniformContinuous_subtype [UniformSpace α] [UniformSpace β] {f : α → β} {s : Set α} {a : α} (hf : UniformContinuous fun x : s => f x.val) (ha : s ∈ 𝓝 a) : Tendsto f (𝓝 a) (𝓝 (f a)) := by rw [(@map_nhds_subtype_coe_eq_nhds α _ s a (mem_of_mem_nhds ha) ha).symm] exact tendsto_map' hf.continuous.continuousAt theorem UniformContinuousOn.continuousOn [UniformSpace α] [UniformSpace β] {f : α → β} {s : Set α} (h : UniformContinuousOn f s) : ContinuousOn f s := by rw [uniformContinuousOn_iff_restrict] at h rw [continuousOn_iff_continuous_restrict] exact h.continuous @[to_additive] instance [UniformSpace α] : UniformSpace αᵐᵒᵖ := UniformSpace.comap MulOpposite.unop ‹_› @[to_additive] theorem uniformity_mulOpposite [UniformSpace α] : 𝓀 αᵐᵒᵖ = comap (fun q : αᵐᵒᵖ × αᵐᵒᵖ => (q.1.unop, q.2.unop)) (𝓀 α) := rfl @[to_additive (attr := simp)] theorem comap_uniformity_mulOpposite [UniformSpace α] : comap (fun p : α × α => (MulOpposite.op p.1, MulOpposite.op p.2)) (𝓀 αᵐᵒᵖ) = 𝓀 α := by simpa [uniformity_mulOpposite, comap_comap, (· ∘ ·)] using comap_id namespace MulOpposite @[to_additive] theorem uniformContinuous_unop [UniformSpace α] : UniformContinuous (unop : αᵐᵒᵖ → α) := uniformContinuous_comap @[to_additive] theorem uniformContinuous_op [UniformSpace α] : UniformContinuous (op : α → αᵐᵒᵖ) := uniformContinuous_comap' uniformContinuous_id end MulOpposite section Prod open UniformSpace /- a similar product space is possible on the function space (uniformity of pointwise convergence), but we want to have the uniformity of uniform convergence on function spaces -/ instance instUniformSpaceProd [u₁ : UniformSpace α] [u₂ : UniformSpace β] : UniformSpace (α × β) := u₁.comap Prod.fst ⊓ u₂.comap Prod.snd -- check the above produces no diamond for `simp` and typeclass search example [UniformSpace α] [UniformSpace β] : (instTopologicalSpaceProd : TopologicalSpace (α × β)) = UniformSpace.toTopologicalSpace := by with_reducible_and_instances rfl theorem uniformity_prod [UniformSpace α] [UniformSpace β] : 𝓀 (α × β) = ((𝓀 α).comap fun p : (α × β) × α × β => (p.1.1, p.2.1)) ⊓ (𝓀 β).comap fun p : (α × β) × α × β => (p.1.2, p.2.2) := rfl instance [UniformSpace α] [IsCountablyGenerated (𝓀 α)] [UniformSpace β] [IsCountablyGenerated (𝓀 β)] : IsCountablyGenerated (𝓀 (α × β)) := by rw [uniformity_prod] infer_instance theorem uniformity_prod_eq_comap_prod [UniformSpace α] [UniformSpace β] : 𝓀 (α × β) = comap (fun p : (α × β) × α × β => ((p.1.1, p.2.1), (p.1.2, p.2.2))) (𝓀 α ×ˢ 𝓀 β) := by simp_rw [uniformity_prod, prod_eq_inf, Filter.comap_inf, Filter.comap_comap, Function.comp_def] theorem uniformity_prod_eq_prod [UniformSpace α] [UniformSpace β] : 𝓀 (α × β) = map (fun p : (α × α) × β × β => ((p.1.1, p.2.1), (p.1.2, p.2.2))) (𝓀 α ×ˢ 𝓀 β) := by rw [map_swap4_eq_comap, uniformity_prod_eq_comap_prod] theorem mem_uniformity_of_uniformContinuous_invariant [UniformSpace α] [UniformSpace β] {s : Set (β × β)} {f : α → α → β} (hf : UniformContinuous fun p : α × α => f p.1 p.2) (hs : s ∈ 𝓀 β) : ∃ u ∈ 𝓀 α, ∀ a b c, (a, b) ∈ u → (f a c, f b c) ∈ s := by rw [UniformContinuous, uniformity_prod_eq_prod, tendsto_map'_iff] at hf rcases mem_prod_iff.1 (mem_map.1 <| hf hs) with ⟹u, hu, v, hv, huvt⟩ exact ⟹u, hu, fun a b c hab => @huvt ((_, _), (_, _)) ⟹hab, refl_mem_uniformity hv⟩⟩ /-- An entourage of the diagonal in `α` and an entourage in `β` yield an entourage in `α × β` once we permute coordinates. -/ def entourageProd (u : Set (α × α)) (v : Set (β × β)) : Set ((α × β) × α × β) := {((a₁, b₁),(a₂, b₂)) | (a₁, a₂) ∈ u ∧ (b₁, b₂) ∈ v} theorem mem_entourageProd {u : Set (α × α)} {v : Set (β × β)} {p : (α × β) × α × β} : p ∈ entourageProd u v ↔ (p.1.1, p.2.1) ∈ u ∧ (p.1.2, p.2.2) ∈ v := Iff.rfl theorem entourageProd_mem_uniformity [t₁ : UniformSpace α] [t₂ : UniformSpace β] {u : Set (α × α)} {v : Set (β × β)} (hu : u ∈ 𝓀 α) (hv : v ∈ 𝓀 β) : entourageProd u v ∈ 𝓀 (α × β) := by rw [uniformity_prod]; exact inter_mem_inf (preimage_mem_comap hu) (preimage_mem_comap hv) theorem ball_entourageProd (u : Set (α × α)) (v : Set (β × β)) (x : α × β) : ball x (entourageProd u v) = ball x.1 u ×ˢ ball x.2 v := by ext p; simp only [ball, entourageProd, Set.mem_setOf_eq, Set.mem_prod, Set.mem_preimage] lemma IsSymmetricRel.entourageProd {u : Set (α × α)} {v : Set (β × β)} (hu : IsSymmetricRel u) (hv : IsSymmetricRel v) : IsSymmetricRel (entourageProd u v) := Set.ext fun _ ↩ and_congr hu.mk_mem_comm hv.mk_mem_comm theorem Filter.HasBasis.uniformity_prod {ιa ιb : Type*} [UniformSpace α] [UniformSpace β] {pa : ιa → Prop} {pb : ιb → Prop} {sa : ιa → Set (α × α)} {sb : ιb → Set (β × β)} (ha : (𝓀 α).HasBasis pa sa) (hb : (𝓀 β).HasBasis pb sb) : (𝓀 (α × β)).HasBasis (fun i : ιa × ιb ↩ pa i.1 ∧ pb i.2) (fun i ↩ entourageProd (sa i.1) (sb i.2)) := (ha.comap _).inf (hb.comap _) theorem entourageProd_subset [UniformSpace α] [UniformSpace β] {s : Set ((α × β) × α × β)} (h : s ∈ 𝓀 (α × β)) : ∃ u ∈ 𝓀 α, ∃ v ∈ 𝓀 β, entourageProd u v ⊆ s := by rcases (((𝓀 α).basis_sets.uniformity_prod (𝓀 β).basis_sets).mem_iff' s).1 h with ⟹w, hw⟩ use w.1, hw.1.1, w.2, hw.1.2, hw.2 theorem tendsto_prod_uniformity_fst [UniformSpace α] [UniformSpace β] : Tendsto (fun p : (α × β) × α × β => (p.1.1, p.2.1)) (𝓀 (α × β)) (𝓀 α) := le_trans (map_mono inf_le_left) map_comap_le theorem tendsto_prod_uniformity_snd [UniformSpace α] [UniformSpace β] : Tendsto (fun p : (α × β) × α × β => (p.1.2, p.2.2)) (𝓀 (α × β)) (𝓀 β) := le_trans (map_mono inf_le_right) map_comap_le theorem uniformContinuous_fst [UniformSpace α] [UniformSpace β] : UniformContinuous fun p : α × β => p.1 := tendsto_prod_uniformity_fst theorem uniformContinuous_snd [UniformSpace α] [UniformSpace β] : UniformContinuous fun p : α × β => p.2 := tendsto_prod_uniformity_snd variable [UniformSpace α] [UniformSpace β] [UniformSpace γ] theorem UniformContinuous.prodMk {f₁ : α → β} {f₂ : α → γ} (h₁ : UniformContinuous f₁) (h₂ : UniformContinuous f₂) : UniformContinuous fun a => (f₁ a, f₂ a) := by rw [UniformContinuous, uniformity_prod] exact tendsto_inf.2 ⟹tendsto_comap_iff.2 h₁, tendsto_comap_iff.2 h₂⟩ @[deprecated (since := "2025-03-10")] alias UniformContinuous.prod_mk := UniformContinuous.prodMk theorem UniformContinuous.prodMk_left {f : α × β → γ} (h : UniformContinuous f) (b) : UniformContinuous fun a => f (a, b) := h.comp (uniformContinuous_id.prodMk uniformContinuous_const) @[deprecated (since := "2025-03-10")] alias UniformContinuous.prod_mk_left := UniformContinuous.prodMk_left theorem UniformContinuous.prodMk_right {f : α × β → γ} (h : UniformContinuous f) (a) : UniformContinuous fun b => f (a, b) := h.comp (uniformContinuous_const.prodMk uniformContinuous_id) @[deprecated (since := "2025-03-10")] alias UniformContinuous.prod_mk_right := UniformContinuous.prodMk_right theorem UniformContinuous.prodMap [UniformSpace ÎŽ] {f : α → γ} {g : β → ÎŽ} (hf : UniformContinuous f) (hg : UniformContinuous g) : UniformContinuous (Prod.map f g) := (hf.comp uniformContinuous_fst).prodMk (hg.comp uniformContinuous_snd) theorem toTopologicalSpace_prod {α} {β} [u : UniformSpace α] [v : UniformSpace β] : @UniformSpace.toTopologicalSpace (α × β) instUniformSpaceProd = @instTopologicalSpaceProd α β u.toTopologicalSpace v.toTopologicalSpace := rfl /-- A version of `UniformContinuous.inf_dom_left` for binary functions -/ theorem uniformContinuous_inf_dom_left₂ {α β γ} {f : α → β → γ} {ua1 ua2 : UniformSpace α} {ub1 ub2 : UniformSpace β} {uc1 : UniformSpace γ} (h : by haveI := ua1; haveI := ub1; exact UniformContinuous fun p : α × β => f p.1 p.2) : by haveI := ua1 ⊓ ua2; haveI := ub1 ⊓ ub2 exact UniformContinuous fun p : α × β => f p.1 p.2 := by -- proof essentially copied from `continuous_inf_dom_left₂` have ha := @UniformContinuous.inf_dom_left _ _ id ua1 ua2 ua1 (@uniformContinuous_id _ (id _)) have hb := @UniformContinuous.inf_dom_left _ _ id ub1 ub2 ub1 (@uniformContinuous_id _ (id _)) have h_unif_cont_id := @UniformContinuous.prodMap _ _ _ _ (ua1 ⊓ ua2) (ub1 ⊓ ub2) ua1 ub1 _ _ ha hb exact @UniformContinuous.comp _ _ _ (id _) (id _) _ _ _ h h_unif_cont_id /-- A version of `UniformContinuous.inf_dom_right` for binary functions -/ theorem uniformContinuous_inf_dom_right₂ {α β γ} {f : α → β → γ} {ua1 ua2 : UniformSpace α} {ub1 ub2 : UniformSpace β} {uc1 : UniformSpace γ} (h : by haveI := ua2; haveI := ub2; exact UniformContinuous fun p : α × β => f p.1 p.2) : by haveI := ua1 ⊓ ua2; haveI := ub1 ⊓ ub2 exact UniformContinuous fun p : α × β => f p.1 p.2 := by -- proof essentially copied from `continuous_inf_dom_right₂` have ha := @UniformContinuous.inf_dom_right _ _ id ua1 ua2 ua2 (@uniformContinuous_id _ (id _)) have hb := @UniformContinuous.inf_dom_right _ _ id ub1 ub2 ub2 (@uniformContinuous_id _ (id _)) have h_unif_cont_id := @UniformContinuous.prodMap _ _ _ _ (ua1 ⊓ ua2) (ub1 ⊓ ub2) ua2 ub2 _ _ ha hb exact @UniformContinuous.comp _ _ _ (id _) (id _) _ _ _ h h_unif_cont_id /-- A version of `uniformContinuous_sInf_dom` for binary functions -/ theorem uniformContinuous_sInf_dom₂ {α β γ} {f : α → β → γ} {uas : Set (UniformSpace α)} {ubs : Set (UniformSpace β)} {ua : UniformSpace α} {ub : UniformSpace β} {uc : UniformSpace γ} (ha : ua ∈ uas) (hb : ub ∈ ubs) (hf : UniformContinuous fun p : α × β => f p.1 p.2) : by haveI := sInf uas; haveI := sInf ubs exact @UniformContinuous _ _ _ uc fun p : α × β => f p.1 p.2 := by -- proof essentially copied from `continuous_sInf_dom` let _ : UniformSpace (α × β) := instUniformSpaceProd have ha := uniformContinuous_sInf_dom ha uniformContinuous_id have hb := uniformContinuous_sInf_dom hb uniformContinuous_id have h_unif_cont_id := @UniformContinuous.prodMap _ _ _ _ (sInf uas) (sInf ubs) ua ub _ _ ha hb exact @UniformContinuous.comp _ _ _ (id _) (id _) _ _ _ hf h_unif_cont_id end Prod section open UniformSpace Function variable {ÎŽ' : Type*} [UniformSpace α] [UniformSpace β] [UniformSpace γ] [UniformSpace ÎŽ] [UniformSpace ÎŽ'] local notation f " ∘₂ " g => Function.bicompr f g /-- Uniform continuity for functions of two variables. -/ def UniformContinuous₂ (f : α → β → γ) := UniformContinuous (uncurry f) theorem uniformContinuous₂_def (f : α → β → γ) : UniformContinuous₂ f ↔ UniformContinuous (uncurry f) := Iff.rfl theorem UniformContinuous₂.uniformContinuous {f : α → β → γ} (h : UniformContinuous₂ f) : UniformContinuous (uncurry f) := h theorem uniformContinuous₂_curry (f : α × β → γ) : UniformContinuous₂ (Function.curry f) ↔ UniformContinuous f := by rw [UniformContinuous₂, uncurry_curry] theorem UniformContinuous₂.comp {f : α → β → γ} {g : γ → ÎŽ} (hg : UniformContinuous g) (hf : UniformContinuous₂ f) : UniformContinuous₂ (g ∘₂ f) := hg.comp hf theorem UniformContinuous₂.bicompl {f : α → β → γ} {ga : ÎŽ → α} {gb : ÎŽ' → β} (hf : UniformContinuous₂ f) (hga : UniformContinuous ga) (hgb : UniformContinuous gb) : UniformContinuous₂ (bicompl f ga gb) := hf.uniformContinuous.comp (hga.prodMap hgb) end theorem toTopologicalSpace_subtype [u : UniformSpace α] {p : α → Prop} : @UniformSpace.toTopologicalSpace (Subtype p) instUniformSpaceSubtype = @instTopologicalSpaceSubtype α p u.toTopologicalSpace := rfl section Sum variable [UniformSpace α] [UniformSpace β] open Sum -- Obsolete auxiliary definitions and lemmas /-- Uniformity on a disjoint union. Entourages of the diagonal in the union are obtained
by taking independently an entourage of the diagonal in the first part, and an entourage of the diagonal in the second part. -/ instance Sum.instUniformSpace : UniformSpace (α ⊕ β) where uniformity := map (fun p : α × α => (inl p.1, inl p.2)) (𝓀 α) ⊔ map (fun p : β × β => (inr p.1, inr p.2)) (𝓀 β)
Mathlib/Topology/UniformSpace/Basic.lean
857
861
/- Copyright (c) 2024 Jeremy Tan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Tan -/ import Mathlib.Data.Int.Interval import Mathlib.Data.Int.ModEq import Mathlib.Data.Nat.Count import Mathlib.Data.Rat.Floor import Mathlib.Order.Interval.Finset.Nat /-! # Counting elements in an interval with given residue The theorems in this file generalise `Nat.card_multiples` in `Mathlib.Data.Nat.Factorization.Basic` to all integer intervals and any fixed residue (not just zero, which reduces to the multiples). Theorems are given for `Ico` and `Ioc` intervals. -/ open Finset Int namespace Int variable (a b : â„€) {r : â„€} lemma Ico_filter_modEq_eq (v : â„€) : {x ∈ Ico a b | x ≡ v [ZMOD r]} = {x ∈ Ico (a - v) (b - v) | r ∣ x}.map ⟹(· + v), add_left_injective v⟩ := by ext x simp_rw [mem_map, mem_filter, mem_Ico, Function.Embedding.coeFn_mk, ← eq_sub_iff_add_eq, exists_eq_right, modEq_comm, modEq_iff_dvd, sub_lt_sub_iff_right, sub_le_sub_iff_right] lemma Ioc_filter_modEq_eq (v : â„€) : {x ∈ Ioc a b | x ≡ v [ZMOD r]} = {x ∈ Ioc (a - v) (b - v) | r ∣ x}.map ⟹(· + v), add_left_injective v⟩ := by ext x simp_rw [mem_map, mem_filter, mem_Ioc, Function.Embedding.coeFn_mk, ← eq_sub_iff_add_eq, exists_eq_right, modEq_comm, modEq_iff_dvd, sub_lt_sub_iff_right, sub_le_sub_iff_right] variable (hr : 0 < r) include hr lemma Ico_filter_dvd_eq : {x ∈ Ico a b | r ∣ x} = (Ico ⌈a / (r : ℚ)⌉ ⌈b / (r : ℚ)⌉).map ⟹(· * r), mul_left_injective₀ hr.ne'⟩ := by ext x simp only [mem_map, mem_filter, mem_Ico, ceil_le, lt_ceil, div_le_iff₀, lt_div_iff₀, dvd_iff_exists_eq_mul_left, cast_pos.2 hr, ← cast_mul, cast_lt, cast_le] aesop lemma Ioc_filter_dvd_eq : {x ∈ Ioc a b | r ∣ x} = (Ioc ⌊a / (r : ℚ)⌋ ⌊b / (r : ℚ)⌋).map ⟹(· * r), mul_left_injective₀ hr.ne'⟩ := by ext x simp only [mem_map, mem_filter, mem_Ioc, floor_lt, le_floor, div_lt_iff₀, le_div_iff₀, dvd_iff_exists_eq_mul_left, cast_pos.2 hr, ← cast_mul, cast_lt, cast_le] aesop /-- There are `⌈b / r⌉ - ⌈a / r⌉` multiples of `r` in `[a, b)`, if `a ≀ b`. -/ theorem Ico_filter_dvd_card : #{x ∈ Ico a b | r ∣ x} = max (⌈b / (r : ℚ)⌉ - ⌈a / (r : ℚ)⌉) 0 := by rw [Ico_filter_dvd_eq _ _ hr, card_map, card_Ico, toNat_eq_max] /-- There are `⌊b / r⌋ - ⌊a / r⌋` multiples of `r` in `(a, b]`, if `a ≀ b`. -/ theorem Ioc_filter_dvd_card : #{x ∈ Ioc a b | r ∣ x} = max (⌊b / (r : ℚ)⌋ - ⌊a / (r : ℚ)⌋) 0 := by rw [Ioc_filter_dvd_eq _ _ hr, card_map, card_Ioc, toNat_eq_max] /-- There are `⌈(b - v) / r⌉ - ⌈(a - v) / r⌉` numbers congruent to `v` mod `r` in `[a, b)`, if `a ≀ b`. -/ theorem Ico_filter_modEq_card (v : â„€) : #{x ∈ Ico a b | x ≡ v [ZMOD r]} = max (⌈(b - v) / (r : ℚ)⌉ - ⌈(a - v) / (r : ℚ)⌉) 0 := by simp [Ico_filter_modEq_eq, Ico_filter_dvd_eq, toNat_eq_max, hr] /-- There are `⌊(b - v) / r⌋ - ⌊(a - v) / r⌋` numbers congruent to `v` mod `r` in `(a, b]`, if `a ≀ b`. -/ theorem Ioc_filter_modEq_card (v : â„€) : #{x ∈ Ioc a b | x ≡ v [ZMOD r]} = max (⌊(b - v) / (r : ℚ)⌋ - ⌊(a - v) / (r : ℚ)⌋) 0 := by simp [Ioc_filter_modEq_eq, Ioc_filter_dvd_eq, toNat_eq_max, hr]
end Int namespace Nat variable (a b : ℕ) {r : ℕ} lemma Ico_filter_modEq_cast {v : ℕ} :
Mathlib/Data/Int/CardIntervalMod.lean
81
87
/- Copyright (c) 2020 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot -/ import Mathlib.Topology.Path /-! # Path connectedness Continuing from `Mathlib.Topology.Path`, this file defines path components and path-connected spaces. ## Main definitions In the file the unit interval `[0, 1]` in `ℝ` is denoted by `I`, and `X` is a topological space. * `Joined (x y : X)` means there is a path between `x` and `y`. * `Joined.somePath (h : Joined x y)` selects some path between two points `x` and `y`. * `pathComponent (x : X)` is the set of points joined to `x`. * `PathConnectedSpace X` is a predicate class asserting that `X` is non-empty and every two points of `X` are joined. Then there are corresponding relative notions for `F : Set X`. * `JoinedIn F (x y : X)` means there is a path `γ` joining `x` to `y` with values in `F`. * `JoinedIn.somePath (h : JoinedIn F x y)` selects a path from `x` to `y` inside `F`. * `pathComponentIn F (x : X)` is the set of points joined to `x` in `F`. * `IsPathConnected F` asserts that `F` is non-empty and every two points of `F` are joined in `F`. ## Main theorems * `Joined` is an equivalence relation, while `JoinedIn F` is at least symmetric and transitive. One can link the absolute and relative version in two directions, using `(univ : Set X)` or the subtype `↥F`. * `pathConnectedSpace_iff_univ : PathConnectedSpace X ↔ IsPathConnected (univ : Set X)` * `isPathConnected_iff_pathConnectedSpace : IsPathConnected F ↔ PathConnectedSpace ↥F` Furthermore, it is shown that continuous images and quotients of path-connected sets/spaces are path-connected, and that every path-connected set/space is also connected. -/ noncomputable section open Topology Filter unitInterval Set Function variable {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] {x y z : X} {ι : Type*} /-! ### Being joined by a path -/ /-- The relation "being joined by a path". This is an equivalence relation. -/ def Joined (x y : X) : Prop := Nonempty (Path x y) @[refl] theorem Joined.refl (x : X) : Joined x x := ⟹Path.refl x⟩ /-- When two points are joined, choose some path from `x` to `y`. -/ def Joined.somePath (h : Joined x y) : Path x y := Nonempty.some h @[symm] theorem Joined.symm {x y : X} (h : Joined x y) : Joined y x := ⟹h.somePath.symm⟩ @[trans] theorem Joined.trans {x y z : X} (hxy : Joined x y) (hyz : Joined y z) : Joined x z := ⟹hxy.somePath.trans hyz.somePath⟩ variable (X) /-- The setoid corresponding the equivalence relation of being joined by a continuous path. -/ def pathSetoid : Setoid X where r := Joined iseqv := Equivalence.mk Joined.refl Joined.symm Joined.trans /-- The quotient type of points of a topological space modulo being joined by a continuous path. -/ def ZerothHomotopy := Quotient (pathSetoid X) instance ZerothHomotopy.inhabited : Inhabited (ZerothHomotopy ℝ) := ⟹@Quotient.mk' ℝ (pathSetoid ℝ) 0⟩ variable {X} /-! ### Being joined by a path inside a set -/ /-- The relation "being joined by a path in `F`". Not quite an equivalence relation since it's not reflexive for points that do not belong to `F`. -/ def JoinedIn (F : Set X) (x y : X) : Prop := ∃ γ : Path x y, ∀ t, γ t ∈ F variable {F : Set X} theorem JoinedIn.mem (h : JoinedIn F x y) : x ∈ F ∧ y ∈ F := by rcases h with ⟚γ, γ_in⟩ have : γ 0 ∈ F ∧ γ 1 ∈ F := by constructor <;> apply γ_in simpa using this theorem JoinedIn.source_mem (h : JoinedIn F x y) : x ∈ F := h.mem.1 theorem JoinedIn.target_mem (h : JoinedIn F x y) : y ∈ F := h.mem.2 /-- When `x` and `y` are joined in `F`, choose a path from `x` to `y` inside `F` -/ def JoinedIn.somePath (h : JoinedIn F x y) : Path x y := Classical.choose h theorem JoinedIn.somePath_mem (h : JoinedIn F x y) (t : I) : h.somePath t ∈ F := Classical.choose_spec h t /-- If `x` and `y` are joined in the set `F`, then they are joined in the subtype `F`. -/ theorem JoinedIn.joined_subtype (h : JoinedIn F x y) : Joined (⟹x, h.source_mem⟩ : F) (⟹y, h.target_mem⟩ : F) := ⟹{ toFun := fun t => ⟹h.somePath t, h.somePath_mem t⟩ continuous_toFun := by fun_prop source' := by simp target' := by simp }⟩ theorem JoinedIn.ofLine {f : ℝ → X} (hf : ContinuousOn f I) (h₀ : f 0 = x) (h₁ : f 1 = y) (hF : f '' I ⊆ F) : JoinedIn F x y := ⟹Path.ofLine hf h₀ h₁, fun t => hF <| Path.ofLine_mem hf h₀ h₁ t⟩ theorem JoinedIn.joined (h : JoinedIn F x y) : Joined x y := ⟹h.somePath⟩ theorem joinedIn_iff_joined (x_in : x ∈ F) (y_in : y ∈ F) : JoinedIn F x y ↔ Joined (⟹x, x_in⟩ : F) (⟹y, y_in⟩ : F) := ⟹fun h => h.joined_subtype, fun h => ⟹h.somePath.map continuous_subtype_val, by simp⟩⟩ @[simp] theorem joinedIn_univ : JoinedIn univ x y ↔ Joined x y := by simp [JoinedIn, Joined, exists_true_iff_nonempty] theorem JoinedIn.mono {U V : Set X} (h : JoinedIn U x y) (hUV : U ⊆ V) : JoinedIn V x y := ⟹h.somePath, fun t => hUV (h.somePath_mem t)⟩ theorem JoinedIn.refl (h : x ∈ F) : JoinedIn F x x := ⟹Path.refl x, fun _t => h⟩ @[symm] theorem JoinedIn.symm (h : JoinedIn F x y) : JoinedIn F y x := by obtain ⟹hx, hy⟩ := h.mem simp_all only [joinedIn_iff_joined] exact h.symm theorem JoinedIn.trans (hxy : JoinedIn F x y) (hyz : JoinedIn F y z) : JoinedIn F x z := by obtain ⟹hx, hy⟩ := hxy.mem obtain ⟹hx, hy⟩ := hyz.mem simp_all only [joinedIn_iff_joined] exact hxy.trans hyz theorem Specializes.joinedIn (h : x ″ y) (hx : x ∈ F) (hy : y ∈ F) : JoinedIn F x y := by refine ⟹⟹⟹Set.piecewise {1} (const I y) (const I x), ?_⟩, by simp, by simp⟩, fun t ↩ ?_⟩ · exact isClosed_singleton.continuous_piecewise_of_specializes continuous_const continuous_const fun _ ↩ h · simp only [Path.coe_mk_mk, piecewise] split_ifs <;> assumption theorem Inseparable.joinedIn (h : Inseparable x y) (hx : x ∈ F) (hy : y ∈ F) : JoinedIn F x y := h.specializes.joinedIn hx hy theorem JoinedIn.map_continuousOn (h : JoinedIn F x y) {f : X → Y} (hf : ContinuousOn f F) : JoinedIn (f '' F) (f x) (f y) := let ⟚γ, hγ⟩ := h ⟚γ.map' <| hf.mono (range_subset_iff.mpr hγ), fun t ↩ mem_image_of_mem _ (hγ t)⟩ theorem JoinedIn.map (h : JoinedIn F x y) {f : X → Y} (hf : Continuous f) : JoinedIn (f '' F) (f x) (f y) := h.map_continuousOn hf.continuousOn theorem Topology.IsInducing.joinedIn_image {f : X → Y} (hf : IsInducing f) (hx : x ∈ F) (hy : y ∈ F) : JoinedIn (f '' F) (f x) (f y) ↔ JoinedIn F x y := by refine ⟹?_, (.map · hf.continuous)⟩ rintro ⟚γ, hγ⟩ choose γ' hγ'F hγ' using hγ have h₀ : x ″ γ' 0 := by rw [← hf.specializes_iff, hγ', γ.source] have h₁ : γ' 1 ″ y := by rw [← hf.specializes_iff, hγ', γ.target] have h : JoinedIn F (γ' 0) (γ' 1) := by refine ⟚⟚⟚γ', ?_⟩, rfl, rfl⟩, hγ'F⟩ simpa only [hf.continuous_iff, comp_def, hγ'] using map_continuous γ exact (h₀.joinedIn hx (hγ'F _)).trans <| h.trans <| h₁.joinedIn (hγ'F _) hy @[deprecated (since := "2024-10-28")] alias Inducing.joinedIn_image := IsInducing.joinedIn_image /-! ### Path component -/ /-- The path component of `x` is the set of points that can be joined to `x`. -/ def pathComponent (x : X) := { y | Joined x y } theorem mem_pathComponent_iff : x ∈ pathComponent y ↔ Joined y x := .rfl @[simp] theorem mem_pathComponent_self (x : X) : x ∈ pathComponent x := Joined.refl x @[simp] theorem pathComponent.nonempty (x : X) : (pathComponent x).Nonempty := ⟹x, mem_pathComponent_self x⟩ theorem mem_pathComponent_of_mem (h : x ∈ pathComponent y) : y ∈ pathComponent x := Joined.symm h theorem pathComponent_symm : x ∈ pathComponent y ↔ y ∈ pathComponent x := ⟹fun h => mem_pathComponent_of_mem h, fun h => mem_pathComponent_of_mem h⟩ theorem pathComponent_congr (h : x ∈ pathComponent y) : pathComponent x = pathComponent y := by ext z constructor · intro h' rw [pathComponent_symm] exact (h.trans h').symm · intro h' rw [pathComponent_symm] at h' ⊢ exact h'.trans h theorem pathComponent_subset_component (x : X) : pathComponent x ⊆ connectedComponent x := fun y h => (isConnected_range h.somePath.continuous).subset_connectedComponent ⟹0, by simp⟩ ⟹1, by simp⟩ /-- The path component of `x` in `F` is the set of points that can be joined to `x` in `F`. -/ def pathComponentIn (x : X) (F : Set X) := { y | JoinedIn F x y } @[simp] theorem pathComponentIn_univ (x : X) : pathComponentIn x univ = pathComponent x := by simp [pathComponentIn, pathComponent, JoinedIn, Joined, exists_true_iff_nonempty] theorem Joined.mem_pathComponent (hyz : Joined y z) (hxy : y ∈ pathComponent x) : z ∈ pathComponent x := hxy.trans hyz theorem mem_pathComponentIn_self (h : x ∈ F) : x ∈ pathComponentIn x F := JoinedIn.refl h theorem pathComponentIn_subset : pathComponentIn x F ⊆ F := fun _ hy ↩ hy.target_mem theorem pathComponentIn_nonempty_iff : (pathComponentIn x F).Nonempty ↔ x ∈ F := ⟹fun ⟹_, ⟚γ, hγ⟩⟩ ↩ γ.source ▾ hγ 0, fun hx ↩ ⟹x, mem_pathComponentIn_self hx⟩⟩ theorem pathComponentIn_congr (h : x ∈ pathComponentIn y F) : pathComponentIn x F = pathComponentIn y F := by ext; exact ⟹h.trans, h.symm.trans⟩ @[gcongr] theorem pathComponentIn_mono {G : Set X} (h : F ⊆ G) : pathComponentIn x F ⊆ pathComponentIn x G := fun _ ⟚γ, hγ⟩ ↩ ⟚γ, fun t ↩ h (hγ t)⟩ /-! ### Path connected sets -/ /-- A set `F` is path connected if it contains a point that can be joined to all other in `F`. -/ def IsPathConnected (F : Set X) : Prop := ∃ x ∈ F, ∀ {y}, y ∈ F → JoinedIn F x y theorem isPathConnected_iff_eq : IsPathConnected F ↔ ∃ x ∈ F, pathComponentIn x F = F := by constructor <;> rintro ⟹x, x_in, h⟩ <;> use x, x_in · ext y exact ⟹fun hy => hy.mem.2, h⟩ · intro y y_in rwa [← h] at y_in theorem IsPathConnected.joinedIn (h : IsPathConnected F) : ∀ᵉ (x ∈ F) (y ∈ F), JoinedIn F x y := fun _x x_in _y y_in => let ⟹_b, _b_in, hb⟩ := h (hb x_in).symm.trans (hb y_in) theorem isPathConnected_iff : IsPathConnected F ↔ F.Nonempty ∧ ∀ᵉ (x ∈ F) (y ∈ F), JoinedIn F x y := ⟹fun h => ⟹let ⟹b, b_in, _hb⟩ := h; ⟹b, b_in⟩, h.joinedIn⟩, fun ⟹⟹b, b_in⟩, h⟩ => ⟹b, b_in, fun x_in => h _ b_in _ x_in⟩⟩ /-- If `f` is continuous on `F` and `F` is path-connected, so is `f(F)`. -/ theorem IsPathConnected.image' (hF : IsPathConnected F) {f : X → Y} (hf : ContinuousOn f F) : IsPathConnected (f '' F) := by rcases hF with ⟹x, x_in, hx⟩ use f x, mem_image_of_mem f x_in rintro _ ⟹y, y_in, rfl⟩ refine ⟹(hx y_in).somePath.map' ?_, fun t ↩ ⟹_, (hx y_in).somePath_mem t, rfl⟩⟩ exact hf.mono (range_subset_iff.2 (hx y_in).somePath_mem) /-- If `f` is continuous and `F` is path-connected, so is `f(F)`. -/ theorem IsPathConnected.image (hF : IsPathConnected F) {f : X → Y} (hf : Continuous f) : IsPathConnected (f '' F) := hF.image' hf.continuousOn /-- If `f : X → Y` is an inducing map, `f(F)` is path-connected iff `F` is. -/ nonrec theorem Topology.IsInducing.isPathConnected_iff {f : X → Y} (hf : IsInducing f) : IsPathConnected F ↔ IsPathConnected (f '' F) := by simp only [IsPathConnected, forall_mem_image, exists_mem_image] refine exists_congr fun x ↩ and_congr_right fun hx ↩ forall₂_congr fun y hy ↩ ?_ rw [hf.joinedIn_image hx hy] @[deprecated (since := "2024-10-28")] alias Inducing.isPathConnected_iff := IsInducing.isPathConnected_iff /-- If `h : X → Y` is a homeomorphism, `h(s)` is path-connected iff `s` is. -/ @[simp] theorem Homeomorph.isPathConnected_image {s : Set X} (h : X ≃ₜ Y) : IsPathConnected (h '' s) ↔ IsPathConnected s := h.isInducing.isPathConnected_iff.symm /-- If `h : X → Y` is a homeomorphism, `h⁻¹(s)` is path-connected iff `s` is. -/ @[simp] theorem Homeomorph.isPathConnected_preimage {s : Set Y} (h : X ≃ₜ Y) : IsPathConnected (h ⁻¹' s) ↔ IsPathConnected s := by rw [← Homeomorph.image_symm]; exact h.symm.isPathConnected_image theorem IsPathConnected.mem_pathComponent (h : IsPathConnected F) (x_in : x ∈ F) (y_in : y ∈ F) : y ∈ pathComponent x := (h.joinedIn x x_in y y_in).joined theorem IsPathConnected.subset_pathComponent (h : IsPathConnected F) (x_in : x ∈ F) : F ⊆ pathComponent x := fun _y y_in => h.mem_pathComponent x_in y_in theorem IsPathConnected.subset_pathComponentIn {s : Set X} (hs : IsPathConnected s) (hxs : x ∈ s) (hsF : s ⊆ F) : s ⊆ pathComponentIn x F := fun y hys ↩ (hs.joinedIn x hxs y hys).mono hsF theorem isPathConnected_singleton (x : X) : IsPathConnected ({x} : Set X) := by refine ⟹x, rfl, ?_⟩ rintro y rfl exact JoinedIn.refl rfl theorem isPathConnected_pathComponentIn (h : x ∈ F) : IsPathConnected (pathComponentIn x F) := ⟹x, mem_pathComponentIn_self h, fun ⟚γ, hγ⟩ ↩ by refine ⟚γ, fun t ↩ ⟹(γ.truncateOfLE t.2.1).cast (γ.extend_zero.symm) (γ.extend_extends' t).symm, fun t' ↩ ?_⟩⟩ dsimp [Path.truncateOfLE, Path.truncate] exact γ.extend_extends' ⟹min (max t'.1 0) t.1, by simp [t.2.1, t.2.2]⟩ ▾ hγ _⟩ theorem isPathConnected_pathComponent : IsPathConnected (pathComponent x) := by rw [← pathComponentIn_univ] exact isPathConnected_pathComponentIn (mem_univ x) theorem IsPathConnected.union {U V : Set X} (hU : IsPathConnected U) (hV : IsPathConnected V) (hUV : (U ∩ V).Nonempty) : IsPathConnected (U ∪ V) := by rcases hUV with ⟹x, xU, xV⟩ use x, Or.inl xU rintro y (yU | yV) · exact (hU.joinedIn x xU y yU).mono subset_union_left · exact (hV.joinedIn x xV y yV).mono subset_union_right /-- If a set `W` is path-connected, then it is also path-connected when seen as a set in a smaller ambient type `U` (when `U` contains `W`). -/ theorem IsPathConnected.preimage_coe {U W : Set X} (hW : IsPathConnected W) (hWU : W ⊆ U) : IsPathConnected (((↑) : U → X) ⁻¹' W) := by rwa [IsInducing.subtypeVal.isPathConnected_iff, Subtype.image_preimage_val, inter_eq_right.2 hWU] theorem IsPathConnected.exists_path_through_family {n : ℕ} {s : Set X} (h : IsPathConnected s) (p : Fin (n + 1) → X) (hp : ∀ i, p i ∈ s) : ∃ γ : Path (p 0) (p n), range γ ⊆ s ∧ ∀ i, p i ∈ range γ := by let p' : ℕ → X := fun k => if h : k < n + 1 then p ⟹k, h⟩ else p ⟹0, n.zero_lt_succ⟩ obtain ⟚γ, hγ⟩ : ∃ γ : Path (p' 0) (p' n), (∀ i ≀ n, p' i ∈ range γ) ∧ range γ ⊆ s := by have hp' : ∀ i ≀ n, p' i ∈ s := by intro i hi simp [p', Nat.lt_succ_of_le hi, hp] clear_value p' clear hp p induction n with | zero => use Path.refl (p' 0) constructor · rintro i hi rw [Nat.le_zero.mp hi] exact ⟹0, rfl⟩ · rw [range_subset_iff] rintro _x exact hp' 0 le_rfl | succ n hn => rcases hn fun i hi => hp' i <| Nat.le_succ_of_le hi with ⟚γ₀, hγ₀⟩ rcases h.joinedIn (p' n) (hp' n n.le_succ) (p' <| n + 1) (hp' (n + 1) <| le_rfl) with ⟚γ₁, hγ₁⟩ let γ : Path (p' 0) (p' <| n + 1) := γ₀.trans γ₁ use γ have range_eq : range γ = range γ₀ ∪ range γ₁ := γ₀.trans_range γ₁ constructor · rintro i hi by_cases hi' : i ≀ n · rw [range_eq] left exact hγ₀.1 i hi' · rw [not_le, ← Nat.succ_le_iff] at hi' have : i = n.succ := le_antisymm hi hi' rw [this] use 1 exact γ.target · rw [range_eq] apply union_subset hγ₀.2 rw [range_subset_iff] exact hγ₁ have hpp' : ∀ k < n + 1, p k = p' k := by intro k hk simp only [p', hk, dif_pos] congr ext rw [Fin.val_cast_of_lt hk] use γ.cast (hpp' 0 n.zero_lt_succ) (hpp' n n.lt_succ_self) simp only [γ.cast_coe] refine And.intro hγ.2 ?_ rintro ⟹i, hi⟩ suffices p ⟹i, hi⟩ = p' i by convert hγ.1 i (Nat.le_of_lt_succ hi) rw [← hpp' i hi] suffices i = i % n.succ by congr rw [Nat.mod_eq_of_lt hi] theorem IsPathConnected.exists_path_through_family' {n : ℕ} {s : Set X} (h : IsPathConnected s) (p : Fin (n + 1) → X) (hp : ∀ i, p i ∈ s) : ∃ (γ : Path (p 0) (p n)) (t : Fin (n + 1) → I), (∀ t, γ t ∈ s) ∧ ∀ i, γ (t i) = p i := by rcases h.exists_path_through_family p hp with ⟚γ, hγ⟩ rcases hγ with ⟹h₁, h₂⟩ simp only [range, mem_setOf_eq] at h₂ rw [range_subset_iff] at h₁ choose! t ht using h₂ exact ⟚γ, t, h₁, ht⟩ /-! ### Path connected spaces -/ /-- A topological space is path-connected if it is non-empty and every two points can be joined by a continuous path. -/ @[mk_iff] class PathConnectedSpace (X : Type*) [TopologicalSpace X] : Prop where /-- A path-connected space must be nonempty. -/ nonempty : Nonempty X /-- Any two points in a path-connected space must be joined by a continuous path. -/ joined : ∀ x y : X, Joined x y theorem pathConnectedSpace_iff_zerothHomotopy : PathConnectedSpace X ↔ Nonempty (ZerothHomotopy X) ∧ Subsingleton (ZerothHomotopy X) := by
letI := pathSetoid X constructor · intro h refine ⟹(nonempty_quotient_iff _).mpr h.1, ⟹?_⟩⟩ rintro ⟹x⟩ ⟹y⟩
Mathlib/Topology/Connected/PathConnected.lean
442
446
/- Copyright (c) 2019 Jan-David Salchow. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jan-David Salchow, Sébastien Gouëzel, Jean Lo -/ import Mathlib.Algebra.Algebra.Tower import Mathlib.Analysis.LocallyConvex.WithSeminorms import Mathlib.Topology.Algebra.Module.StrongTopology import Mathlib.Analysis.Normed.Operator.LinearIsometry import Mathlib.Analysis.Normed.Operator.ContinuousLinearMap import Mathlib.Tactic.SuppressCompilation /-! # Operator norm on the space of continuous linear maps Define the operator (semi)-norm on the space of continuous (semi)linear maps between (semi)-normed spaces, and prove its basic properties. In particular, show that this space is itself a semi-normed space. Since a lot of elementary properties don't require `‖x‖ = 0 → x = 0` we start setting up the theory for `SeminormedAddCommGroup`. Later we will specialize to `NormedAddCommGroup` in the file `NormedSpace.lean`. Note that most of statements that apply to semilinear maps only hold when the ring homomorphism is isometric, as expressed by the typeclass `[RingHomIsometric σ]`. -/ suppress_compilation open Bornology open Filter hiding map_smul open scoped NNReal Topology Uniformity -- the `ₗ` subscript variables are for special cases about linear (as opposed to semilinear) maps variable {𝕜 𝕜₂ 𝕜₃ E F Fₗ G 𝓕 : Type*} section SemiNormed open Metric ContinuousLinearMap variable [SeminormedAddCommGroup E] [SeminormedAddCommGroup F] [SeminormedAddCommGroup Fₗ] [SeminormedAddCommGroup G] variable [NontriviallyNormedField 𝕜] [NontriviallyNormedField 𝕜₂] [NontriviallyNormedField 𝕜₃] [NormedSpace 𝕜 E] [NormedSpace 𝕜₂ F] [NormedSpace 𝕜 Fₗ] [NormedSpace 𝕜₃ G] {σ₁₂ : 𝕜 →+* 𝕜₂} {σ₂₃ : 𝕜₂ →+* 𝕜₃} {σ₁₃ : 𝕜 →+* 𝕜₃} [RingHomCompTriple σ₁₂ σ₂₃ σ₁₃] variable [FunLike 𝓕 E F] /-- If `‖x‖ = 0` and `f` is continuous then `‖f x‖ = 0`. -/ theorem norm_image_of_norm_zero [SemilinearMapClass 𝓕 σ₁₂ E F] (f : 𝓕) (hf : Continuous f) {x : E} (hx : ‖x‖ = 0) : ‖f x‖ = 0 := by rw [← mem_closure_zero_iff_norm, ← specializes_iff_mem_closure, ← map_zero f] at * exact hx.map hf section variable [RingHomIsometric σ₁₂] theorem SemilinearMapClass.bound_of_shell_semi_normed [SemilinearMapClass 𝓕 σ₁₂ E F] (f : 𝓕) {ε C : ℝ} (ε_pos : 0 < ε) {c : 𝕜} (hc : 1 < ‖c‖) (hf : ∀ x, ε / ‖c‖ ≀ ‖x‖ → ‖x‖ < ε → ‖f x‖ ≀ C * ‖x‖) {x : E} (hx : ‖x‖ ≠ 0) : ‖f x‖ ≀ C * ‖x‖ := (normSeminorm 𝕜 E).bound_of_shell ((normSeminorm 𝕜₂ F).comp ⟹⟹f, map_add f⟩, map_smulₛₗ f⟩) ε_pos hc hf hx /-- A continuous linear map between seminormed spaces is bounded when the field is nontrivially normed. The continuity ensures boundedness on a ball of some radius `ε`. The nontriviality of the norm is then used to rescale any element into an element of norm in `[ε/C, ε]`, whose image has a controlled norm. The norm control for the original element follows by rescaling. -/ theorem SemilinearMapClass.bound_of_continuous [SemilinearMapClass 𝓕 σ₁₂ E F] (f : 𝓕) (hf : Continuous f) : ∃ C, 0 < C ∧ ∀ x : E, ‖f x‖ ≀ C * ‖x‖ := let φ : E →ₛₗ[σ₁₂] F := ⟹⟹f, map_add f⟩, map_smulₛₗ f⟩ ((normSeminorm 𝕜₂ F).comp φ).bound_of_continuous_normedSpace (continuous_norm.comp hf) end namespace ContinuousLinearMap theorem bound [RingHomIsometric σ₁₂] (f : E →SL[σ₁₂] F) : ∃ C, 0 < C ∧ ∀ x : E, ‖f x‖ ≀ C * ‖x‖ := SemilinearMapClass.bound_of_continuous f f.2 section open Filter variable (𝕜 E) /-- Given a unit-length element `x` of a normed space `E` over a field `𝕜`, the natural linear isometry map from `𝕜` to `E` by taking multiples of `x`. -/ def _root_.LinearIsometry.toSpanSingleton {v : E} (hv : ‖v‖ = 1) : 𝕜 →ₗᵢ[𝕜] E := { LinearMap.toSpanSingleton 𝕜 E v with norm_map' := fun x => by simp [norm_smul, hv] } variable {𝕜 E} @[simp] theorem _root_.LinearIsometry.toSpanSingleton_apply {v : E} (hv : ‖v‖ = 1) (a : 𝕜) : LinearIsometry.toSpanSingleton 𝕜 E hv a = a • v := rfl @[simp] theorem _root_.LinearIsometry.coe_toSpanSingleton {v : E} (hv : ‖v‖ = 1) : (LinearIsometry.toSpanSingleton 𝕜 E hv).toLinearMap = LinearMap.toSpanSingleton 𝕜 E v := rfl end section OpNorm open Set Real /-- The operator norm of a continuous linear map is the inf of all its bounds. -/ def opNorm (f : E →SL[σ₁₂] F) := sInf { c | 0 ≀ c ∧ ∀ x, ‖f x‖ ≀ c * ‖x‖ } instance hasOpNorm : Norm (E →SL[σ₁₂] F) := ⟹opNorm⟩ theorem norm_def (f : E →SL[σ₁₂] F) : ‖f‖ = sInf { c | 0 ≀ c ∧ ∀ x, ‖f x‖ ≀ c * ‖x‖ } := rfl -- So that invocations of `le_csInf` make sense: we show that the set of -- bounds is nonempty and bounded below. theorem bounds_nonempty [RingHomIsometric σ₁₂] {f : E →SL[σ₁₂] F} : ∃ c, c ∈ { c | 0 ≀ c ∧ ∀ x, ‖f x‖ ≀ c * ‖x‖ } := let ⟹M, hMp, hMb⟩ := f.bound ⟹M, le_of_lt hMp, hMb⟩ theorem bounds_bddBelow {f : E →SL[σ₁₂] F} : BddBelow { c | 0 ≀ c ∧ ∀ x, ‖f x‖ ≀ c * ‖x‖ } := ⟹0, fun _ ⟹hn, _⟩ => hn⟩ theorem isLeast_opNorm [RingHomIsometric σ₁₂] (f : E →SL[σ₁₂] F) : IsLeast {c | 0 ≀ c ∧ ∀ x, ‖f x‖ ≀ c * ‖x‖} ‖f‖ := by refine IsClosed.isLeast_csInf ?_ bounds_nonempty bounds_bddBelow simp only [setOf_and, setOf_forall] refine isClosed_Ici.inter <| isClosed_iInter fun _ ↩ isClosed_le ?_ ?_ <;> continuity /-- If one controls the norm of every `A x`, then one controls the norm of `A`. -/ theorem opNorm_le_bound (f : E →SL[σ₁₂] F) {M : ℝ} (hMp : 0 ≀ M) (hM : ∀ x, ‖f x‖ ≀ M * ‖x‖) : ‖f‖ ≀ M := csInf_le bounds_bddBelow ⟹hMp, hM⟩ /-- If one controls the norm of every `A x`, `‖x‖ ≠ 0`, then one controls the norm of `A`. -/ theorem opNorm_le_bound' (f : E →SL[σ₁₂] F) {M : ℝ} (hMp : 0 ≀ M) (hM : ∀ x, ‖x‖ ≠ 0 → ‖f x‖ ≀ M * ‖x‖) : ‖f‖ ≀ M := opNorm_le_bound f hMp fun x => (ne_or_eq ‖x‖ 0).elim (hM x) fun h => by simp only [h, mul_zero, norm_image_of_norm_zero f f.2 h, le_refl] theorem opNorm_le_of_lipschitz {f : E →SL[σ₁₂] F} {K : ℝ≥0} (hf : LipschitzWith K f) : ‖f‖ ≀ K := f.opNorm_le_bound K.2 fun x => by simpa only [dist_zero_right, f.map_zero] using hf.dist_le_mul x 0 theorem opNorm_eq_of_bounds {φ : E →SL[σ₁₂] F} {M : ℝ} (M_nonneg : 0 ≀ M) (h_above : ∀ x, ‖φ x‖ ≀ M * ‖x‖) (h_below : ∀ N ≥ 0, (∀ x, ‖φ x‖ ≀ N * ‖x‖) → M ≀ N) : ‖φ‖ = M := le_antisymm (φ.opNorm_le_bound M_nonneg h_above) ((le_csInf_iff ContinuousLinearMap.bounds_bddBelow ⟹M, M_nonneg, h_above⟩).mpr fun N ⟹N_nonneg, hN⟩ => h_below N N_nonneg hN) theorem opNorm_neg (f : E →SL[σ₁₂] F) : ‖-f‖ = ‖f‖ := by simp only [norm_def, neg_apply, norm_neg] theorem opNorm_nonneg (f : E →SL[σ₁₂] F) : 0 ≀ ‖f‖ := Real.sInf_nonneg fun _ ↩ And.left /-- The norm of the `0` operator is `0`. -/ theorem opNorm_zero : ‖(0 : E →SL[σ₁₂] F)‖ = 0 := le_antisymm (opNorm_le_bound _ le_rfl fun _ ↩ by simp) (opNorm_nonneg _) /-- The norm of the identity is at most `1`. It is in fact `1`, except when the space is trivial where it is `0`. It means that one can not do better than an inequality in general. -/ theorem norm_id_le : ‖id 𝕜 E‖ ≀ 1 := opNorm_le_bound _ zero_le_one fun x => by simp section variable [RingHomIsometric σ₁₂] [RingHomIsometric σ₂₃] (f g : E →SL[σ₁₂] F) (h : F →SL[σ₂₃] G) (x : E) /-- The fundamental property of the operator norm: `‖f x‖ ≀ ‖f‖ * ‖x‖`. -/ theorem le_opNorm : ‖f x‖ ≀ ‖f‖ * ‖x‖ := (isLeast_opNorm f).1.2 x theorem dist_le_opNorm (x y : E) : dist (f x) (f y) ≀ ‖f‖ * dist x y := by simp_rw [dist_eq_norm, ← map_sub, f.le_opNorm] theorem le_of_opNorm_le_of_le {x} {a b : ℝ} (hf : ‖f‖ ≀ a) (hx : ‖x‖ ≀ b) : ‖f x‖ ≀ a * b := (f.le_opNorm x).trans <| by gcongr; exact (opNorm_nonneg f).trans hf theorem le_opNorm_of_le {c : ℝ} {x} (h : ‖x‖ ≀ c) : ‖f x‖ ≀ ‖f‖ * c := f.le_of_opNorm_le_of_le le_rfl h theorem le_of_opNorm_le {c : ℝ} (h : ‖f‖ ≀ c) (x : E) : ‖f x‖ ≀ c * ‖x‖ := f.le_of_opNorm_le_of_le h le_rfl
theorem opNorm_le_iff {f : E →SL[σ₁₂] F} {M : ℝ} (hMp : 0 ≀ M) : ‖f‖ ≀ M ↔ ∀ x, ‖f x‖ ≀ M * ‖x‖ :=
Mathlib/Analysis/NormedSpace/OperatorNorm/Basic.lean
210
211
/- 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 -/ import Mathlib.Analysis.SpecialFunctions.Exp import Mathlib.Data.Nat.Factorization.Defs import Mathlib.Analysis.NormedSpace.Real import Mathlib.Data.Rat.Cast.CharZero /-! # Real logarithm In this file we define `Real.log` to be the logarithm of a real number. As usual, we extend it from its domain `(0, +∞)` to a globally defined function. We choose to do it so that `log 0 = 0` and `log (-x) = log x`. We prove some basic properties of this function and show that it is continuous. ## Tags logarithm, continuity -/ open Set Filter Function open Topology noncomputable section namespace Real variable {x y : ℝ} /-- The real logarithm function, equal to the inverse of the exponential for `x > 0`, to `log |x|` for `x < 0`, and to `0` for `0`. We use this unconventional extension to `(-∞, 0]` as it gives the formula `log (x * y) = log x + log y` for all nonzero `x` and `y`, and the derivative of `log` is `1/x` away from `0`. -/ @[pp_nodot] noncomputable def log (x : ℝ) : ℝ := if hx : x = 0 then 0 else expOrderIso.symm ⟹|x|, abs_pos.2 hx⟩ theorem log_of_ne_zero (hx : x ≠ 0) : log x = expOrderIso.symm ⟹|x|, abs_pos.2 hx⟩ := dif_neg hx theorem log_of_pos (hx : 0 < x) : log x = expOrderIso.symm ⟹x, hx⟩ := by rw [log_of_ne_zero hx.ne'] congr exact abs_of_pos hx theorem exp_log_eq_abs (hx : x ≠ 0) : exp (log x) = |x| := by rw [log_of_ne_zero hx, ← coe_expOrderIso_apply, OrderIso.apply_symm_apply, Subtype.coe_mk] theorem exp_log (hx : 0 < x) : exp (log x) = x := by rw [exp_log_eq_abs hx.ne'] exact abs_of_pos hx theorem exp_log_of_neg (hx : x < 0) : exp (log x) = -x := by rw [exp_log_eq_abs (ne_of_lt hx)] exact abs_of_neg hx theorem le_exp_log (x : ℝ) : x ≀ exp (log x) := by by_cases h_zero : x = 0 · rw [h_zero, log, dif_pos rfl, exp_zero] exact zero_le_one · rw [exp_log_eq_abs h_zero] exact le_abs_self _ @[simp] theorem log_exp (x : ℝ) : log (exp x) = x := exp_injective <| exp_log (exp_pos x) theorem exp_one_mul_le_exp {x : ℝ} : exp 1 * x ≀ exp x := by by_cases hx0 : x ≀ 0 · apply le_trans (mul_nonpos_of_nonneg_of_nonpos (exp_pos 1).le hx0) (exp_nonneg x) · have h := add_one_le_exp (log x) rwa [← exp_le_exp, exp_add, exp_log (lt_of_not_le hx0), mul_comm] at h theorem two_mul_le_exp {x : ℝ} : 2 * x ≀ exp x := by by_cases hx0 : x < 0 · exact le_trans (mul_nonpos_of_nonneg_of_nonpos (by simp only [Nat.ofNat_nonneg]) hx0.le) (exp_nonneg x) · apply le_trans (mul_le_mul_of_nonneg_right _ (le_of_not_lt hx0)) exp_one_mul_le_exp have := Real.add_one_le_exp 1 rwa [one_add_one_eq_two] at this theorem surjOn_log : SurjOn log (Ioi 0) univ := fun x _ => ⟹exp x, exp_pos x, log_exp x⟩ theorem log_surjective : Surjective log := fun x => ⟹exp x, log_exp x⟩ @[simp] theorem range_log : range log = univ := log_surjective.range_eq @[simp] theorem log_zero : log 0 = 0 := dif_pos rfl @[simp] theorem log_one : log 1 = 0 := exp_injective <| by rw [exp_log zero_lt_one, exp_zero] /-- This holds true for all `x : ℝ` because of the junk values `0 / 0 = 0` and `log 0 = 0`. -/ @[simp] lemma log_div_self (x : ℝ) : log (x / x) = 0 := by obtain rfl | hx := eq_or_ne x 0 <;> simp [*] @[simp] theorem log_abs (x : ℝ) : log |x| = log x := by by_cases h : x = 0 · simp [h] · rw [← exp_eq_exp, exp_log_eq_abs h, exp_log_eq_abs (abs_pos.2 h).ne', abs_abs] @[simp] theorem log_neg_eq_log (x : ℝ) : log (-x) = log x := by rw [← log_abs x, ← log_abs (-x), abs_neg] theorem sinh_log {x : ℝ} (hx : 0 < x) : sinh (log x) = (x - x⁻¹) / 2 := by rw [sinh_eq, exp_neg, exp_log hx] theorem cosh_log {x : ℝ} (hx : 0 < x) : cosh (log x) = (x + x⁻¹) / 2 := by rw [cosh_eq, exp_neg, exp_log hx] theorem surjOn_log' : SurjOn log (Iio 0) univ := fun x _ => ⟹-exp x, neg_lt_zero.2 <| exp_pos x, by rw [log_neg_eq_log, log_exp]⟩ theorem log_mul (hx : x ≠ 0) (hy : y ≠ 0) : log (x * y) = log x + log y := exp_injective <| by rw [exp_log_eq_abs (mul_ne_zero hx hy), exp_add, exp_log_eq_abs hx, exp_log_eq_abs hy, abs_mul] theorem log_div (hx : x ≠ 0) (hy : y ≠ 0) : log (x / y) = log x - log y := exp_injective <| by rw [exp_log_eq_abs (div_ne_zero hx hy), exp_sub, exp_log_eq_abs hx, exp_log_eq_abs hy, abs_div] @[simp] theorem log_inv (x : ℝ) : log x⁻¹ = -log x := by by_cases hx : x = 0; · simp [hx] rw [← exp_eq_exp, exp_log_eq_abs (inv_ne_zero hx), exp_neg, exp_log_eq_abs hx, abs_inv] theorem log_le_log_iff (h : 0 < x) (h₁ : 0 < y) : log x ≀ log y ↔ x ≀ y := by rw [← exp_le_exp, exp_log h, exp_log h₁] @[gcongr, bound] lemma log_le_log (hx : 0 < x) (hxy : x ≀ y) : log x ≀ log y := (log_le_log_iff hx (hx.trans_le hxy)).2 hxy @[gcongr, bound] theorem log_lt_log (hx : 0 < x) (h : x < y) : log x < log y := by rwa [← exp_lt_exp, exp_log hx, exp_log (lt_trans hx h)] theorem log_lt_log_iff (hx : 0 < x) (hy : 0 < y) : log x < log y ↔ x < y := by rw [← exp_lt_exp, exp_log hx, exp_log hy] theorem log_le_iff_le_exp (hx : 0 < x) : log x ≀ y ↔ x ≀ exp y := by rw [← exp_le_exp, exp_log hx] theorem log_lt_iff_lt_exp (hx : 0 < x) : log x < y ↔ x < exp y := by rw [← exp_lt_exp, exp_log hx] theorem le_log_iff_exp_le (hy : 0 < y) : x ≀ log y ↔ exp x ≀ y := by rw [← exp_le_exp, exp_log hy] theorem lt_log_iff_exp_lt (hy : 0 < y) : x < log y ↔ exp x < y := by rw [← exp_lt_exp, exp_log hy] theorem log_pos_iff (hx : 0 ≀ x) : 0 < log x ↔ 1 < x := by rcases hx.eq_or_lt with (rfl | hx) · simp [le_refl, zero_le_one] rw [← log_one] exact log_lt_log_iff zero_lt_one hx @[bound] theorem log_pos (hx : 1 < x) : 0 < log x := (log_pos_iff (lt_trans zero_lt_one hx).le).2 hx theorem log_pos_of_lt_neg_one (hx : x < -1) : 0 < log x := by rw [← neg_neg x, log_neg_eq_log] have : 1 < -x := by linarith exact log_pos this theorem log_neg_iff (h : 0 < x) : log x < 0 ↔ x < 1 := by rw [← log_one] exact log_lt_log_iff h zero_lt_one @[bound] theorem log_neg (h0 : 0 < x) (h1 : x < 1) : log x < 0 := (log_neg_iff h0).2 h1 theorem log_neg_of_lt_zero (h0 : x < 0) (h1 : -1 < x) : log x < 0 := by rw [← neg_neg x, log_neg_eq_log] have h0' : 0 < -x := by linarith have h1' : -x < 1 := by linarith exact log_neg h0' h1' theorem log_nonneg_iff (hx : 0 < x) : 0 ≀ log x ↔ 1 ≀ x := by rw [← not_lt, log_neg_iff hx, not_lt] @[bound] theorem log_nonneg (hx : 1 ≀ x) : 0 ≀ log x := (log_nonneg_iff (zero_lt_one.trans_le hx)).2 hx theorem log_nonpos_iff (hx : 0 ≀ x) : log x ≀ 0 ↔ x ≀ 1 := by rcases hx.eq_or_lt with (rfl | hx) · simp [le_refl, zero_le_one] rw [← not_lt, log_pos_iff hx.le, not_lt] @[deprecated (since := "2025-01-16")] alias log_nonpos_iff' := log_nonpos_iff @[bound] theorem log_nonpos (hx : 0 ≀ x) (h'x : x ≀ 1) : log x ≀ 0 := (log_nonpos_iff hx).2 h'x theorem log_natCast_nonneg (n : ℕ) : 0 ≀ log n := by if hn : n = 0 then simp [hn] else have : (1 : ℝ) ≀ n := mod_cast Nat.one_le_of_lt <| Nat.pos_of_ne_zero hn exact log_nonneg this theorem log_neg_natCast_nonneg (n : ℕ) : 0 ≀ log (-n) := by rw [← log_neg_eq_log, neg_neg] exact log_natCast_nonneg _ theorem log_intCast_nonneg (n : â„€) : 0 ≀ log n := by cases lt_trichotomy 0 n with | inl hn => have : (1 : ℝ) ≀ n := mod_cast hn exact log_nonneg this | inr hn => cases hn with | inl hn => simp [hn.symm] | inr hn => have : (1 : ℝ) ≀ -n := by rw [← neg_zero, ← lt_neg] at hn; exact mod_cast hn rw [← log_neg_eq_log] exact log_nonneg this theorem strictMonoOn_log : StrictMonoOn log (Set.Ioi 0) := fun _ hx _ _ hxy => log_lt_log hx hxy theorem strictAntiOn_log : StrictAntiOn log (Set.Iio 0) := by rintro x (hx : x < 0) y (hy : y < 0) hxy rw [← log_abs y, ← log_abs x] refine log_lt_log (abs_pos.2 hy.ne) ?_ rwa [abs_of_neg hy, abs_of_neg hx, neg_lt_neg_iff] theorem log_injOn_pos : Set.InjOn log (Set.Ioi 0) := strictMonoOn_log.injOn theorem log_lt_sub_one_of_pos (hx1 : 0 < x) (hx2 : x ≠ 1) : log x < x - 1 := by have h : log x ≠ 0 := by rwa [← log_one, log_injOn_pos.ne_iff hx1] exact mem_Ioi.mpr zero_lt_one linarith [add_one_lt_exp h, exp_log hx1] theorem eq_one_of_pos_of_log_eq_zero {x : ℝ} (h₁ : 0 < x) (h₂ : log x = 0) : x = 1 := log_injOn_pos (Set.mem_Ioi.2 h₁) (Set.mem_Ioi.2 zero_lt_one) (h₂.trans Real.log_one.symm) theorem log_ne_zero_of_pos_of_ne_one {x : ℝ} (hx_pos : 0 < x) (hx : x ≠ 1) : log x ≠ 0 := mt (eq_one_of_pos_of_log_eq_zero hx_pos) hx @[simp] theorem log_eq_zero {x : ℝ} : log x = 0 ↔ x = 0 √ x = 1 √ x = -1 := by constructor · intro h rcases lt_trichotomy x 0 with (x_lt_zero | rfl | x_gt_zero) · refine Or.inr (Or.inr (neg_eq_iff_eq_neg.mp ?_)) rw [← log_neg_eq_log x] at h exact eq_one_of_pos_of_log_eq_zero (neg_pos.mpr x_lt_zero) h · exact Or.inl rfl · exact Or.inr (Or.inl (eq_one_of_pos_of_log_eq_zero x_gt_zero h)) · rintro (rfl | rfl | rfl) <;> simp only [log_one, log_zero, log_neg_eq_log] theorem log_ne_zero {x : ℝ} : log x ≠ 0 ↔ x ≠ 0 ∧ x ≠ 1 ∧ x ≠ -1 := by simpa only [not_or] using log_eq_zero.not @[simp] theorem log_pow (x : ℝ) (n : ℕ) : log (x ^ n) = n * log x := by induction n with | zero => simp | succ n ih => rcases eq_or_ne x 0 with (rfl | hx) · simp · rw [pow_succ, log_mul (pow_ne_zero _ hx) hx, ih, Nat.cast_succ, add_mul, one_mul] @[simp] theorem log_zpow (x : ℝ) (n : â„€) : log (x ^ n) = n * log x := by cases n · rw [Int.ofNat_eq_coe, zpow_natCast, log_pow, Int.cast_natCast] · rw [zpow_negSucc, log_inv, log_pow, Int.cast_negSucc, Nat.cast_add_one, neg_mul_eq_neg_mul] theorem log_sqrt {x : ℝ} (hx : 0 ≀ x) : log (√x) = log x / 2 := by rw [eq_div_iff, mul_comm, ← Nat.cast_two, ← log_pow, sq_sqrt hx] exact two_ne_zero theorem log_le_sub_one_of_pos {x : ℝ} (hx : 0 < x) : log x ≀ x - 1 := by rw [le_sub_iff_add_le] convert add_one_le_exp (log x) rw [exp_log hx] lemma one_sub_inv_le_log_of_pos (hx : 0 < x) : 1 - x⁻¹ ≀ log x := by simpa [add_comm] using log_le_sub_one_of_pos (inv_pos.2 hx) /-- See `Real.log_le_sub_one_of_pos` for the stronger version when `x ≠ 0`. -/ lemma log_le_self (hx : 0 ≀ x) : log x ≀ x := by obtain rfl | hx := hx.eq_or_lt · simp · exact (log_le_sub_one_of_pos hx).trans (by linarith) /-- See `Real.one_sub_inv_le_log_of_pos` for the stronger version when `x ≠ 0`. -/ lemma neg_inv_le_log (hx : 0 ≀ x) : -x⁻¹ ≀ log x := by rw [neg_le, ← log_inv]; exact log_le_self <| inv_nonneg.2 hx /-- Bound for `|log x * x|` in the interval `(0, 1]`. -/ theorem abs_log_mul_self_lt (x : ℝ) (h1 : 0 < x) (h2 : x ≀ 1) : |log x * x| < 1 := by have : 0 < 1 / x := by simpa only [one_div, inv_pos] using h1 replace := log_le_sub_one_of_pos this replace : log (1 / x) < 1 / x := by linarith rw [log_div one_ne_zero h1.ne', log_one, zero_sub, lt_div_iff₀ h1] at this have aux : 0 ≀ -log x * x := by refine mul_nonneg ?_ h1.le rw [← log_inv] apply log_nonneg rw [← le_inv_comm₀ h1 zero_lt_one, inv_one] exact h2 rw [← abs_of_nonneg aux, neg_mul, abs_neg] at this exact this /-- The real logarithm function tends to `+∞` at `+∞`. -/ theorem tendsto_log_atTop : Tendsto log atTop atTop := tendsto_comp_exp_atTop.1 <| by simpa only [log_exp] using tendsto_id lemma tendsto_log_nhdsGT_zero : Tendsto log (𝓝[>] 0) atBot := by simpa [← tendsto_comp_exp_atBot] using tendsto_id @[deprecated (since := "2025-03-18")] alias tendsto_log_nhdsWithin_zero_right := tendsto_log_nhdsGT_zero theorem tendsto_log_nhdsNE_zero : Tendsto log (𝓝[≠] 0) atBot := by simpa [comp_def] using tendsto_log_nhdsGT_zero.comp tendsto_abs_nhdsNE_zero @[deprecated (since := "2025-03-18")] alias tendsto_log_nhdsWithin_zero := tendsto_log_nhdsNE_zero lemma tendsto_log_nhdsLT_zero : Tendsto log (𝓝[<] 0) atBot := tendsto_log_nhdsNE_zero.mono_left <| nhdsWithin_mono _ fun _ h ↩ ne_of_lt h @[deprecated (since := "2025-03-18")] alias tendsto_log_nhdsWithin_zero_left := tendsto_log_nhdsLT_zero theorem continuousOn_log : ContinuousOn log {0}ᶜ := by simp +unfoldPartialApp only [continuousOn_iff_continuous_restrict, restrict] conv in log _ => rw [log_of_ne_zero (show (x : ℝ) ≠ 0 from x.2)] exact expOrderIso.symm.continuous.comp (continuous_subtype_val.norm.subtype_mk _) /-- The real logarithm is continuous as a function from nonzero reals. -/ @[fun_prop] theorem continuous_log : Continuous fun x : { x : ℝ // x ≠ 0 } => log x := continuousOn_iff_continuous_restrict.1 <| continuousOn_log.mono fun _ => id /-- The real logarithm is continuous as a function from positive reals. -/ @[fun_prop] theorem continuous_log' : Continuous fun x : { x : ℝ // 0 < x } => log x := continuousOn_iff_continuous_restrict.1 <| continuousOn_log.mono fun _ hx => ne_of_gt hx theorem continuousAt_log (hx : x ≠ 0) : ContinuousAt log x := (continuousOn_log x hx).continuousAt <| isOpen_compl_singleton.mem_nhds hx @[simp] theorem continuousAt_log_iff : ContinuousAt log x ↔ x ≠ 0 := by refine ⟹?_, continuousAt_log⟩ rintro h rfl exact not_tendsto_nhds_of_tendsto_atBot tendsto_log_nhdsNE_zero _ <| h.tendsto.mono_left nhdsWithin_le_nhds theorem log_prod {α : Type*} (s : Finset α) (f : α → ℝ) (hf : ∀ x ∈ s, f x ≠ 0) : log (∏ i ∈ s, f i) = ∑ i ∈ s, log (f i) := by induction' s using Finset.cons_induction_on with a s ha ih · simp · rw [Finset.forall_mem_cons] at hf simp [ih hf.2, log_mul hf.1 (Finset.prod_ne_zero_iff.2 hf.2)] protected theorem _root_.Finsupp.log_prod {α β : Type*} [Zero β] (f : α →₀ β) (g : α → β → ℝ) (hg : ∀ a, g a (f a) = 0 → f a = 0) : log (f.prod g) = f.sum fun a b ↩ log (g a b) :=
log_prod _ _ fun _x hx h₀ ↩ Finsupp.mem_support_iff.1 hx <| hg _ h₀ theorem log_nat_eq_sum_factorization (n : ℕ) : log n = n.factorization.sum fun p t => t * log p := by rcases eq_or_ne n 0 with (rfl | hn)
Mathlib/Analysis/SpecialFunctions/Log/Basic.lean
378
382
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Finset.Fold import Mathlib.Data.Multiset.Bind import Mathlib.Order.SetNotation /-! # Unions of finite sets This file defines the union of a family `t : α → Finset β` of finsets bounded by a finset `s : Finset α`. ## Main declarations * `Finset.disjUnion`: Given a hypothesis `h` which states that finsets `s` and `t` are disjoint, `s.disjUnion t h` is the set such that `a ∈ disjUnion s t h` iff `a ∈ s` or `a ∈ t`; this does not require decidable equality on the type `α`. * `Finset.biUnion`: Finite unions of finsets; given an indexing function `f : α → Finset β` and an `s : Finset α`, `s.biUnion f` is the union of all finsets of the form `f a` for `a ∈ s`. ## TODO Remove `Finset.biUnion` in favour of `Finset.sup`. -/ assert_not_exists MonoidWithZero MulAction variable {α β γ : Type*} {s s₁ s₂ : Finset α} {t t₁ t₂ : α → Finset β} namespace Finset section DisjiUnion /-- `disjiUnion s f h` is the set such that `a ∈ disjiUnion s f` iff `a ∈ f i` for some `i ∈ s`. It is the same as `s.biUnion f`, but it does not require decidable equality on the type. The hypothesis ensures that the sets are disjoint. -/ def disjiUnion (s : Finset α) (t : α → Finset β) (hf : (s : Set α).PairwiseDisjoint t) : Finset β := ⟹s.val.bind (Finset.val ∘ t), Multiset.nodup_bind.2 ⟹fun a _ ↩ (t a).nodup, s.nodup.pairwise fun _ ha _ hb hab ↩ disjoint_val.2 <| hf ha hb hab⟩⟩ @[simp] lemma disjiUnion_val (s : Finset α) (t : α → Finset β) (h) : (s.disjiUnion t h).1 = s.1.bind fun a ↩ (t a).1 := rfl @[simp] lemma disjiUnion_empty (t : α → Finset β) : disjiUnion ∅ t (by simp) = ∅ := rfl @[simp] lemma mem_disjiUnion {b : β} {h} : b ∈ s.disjiUnion t h ↔ ∃ a ∈ s, b ∈ t a := by simp only [mem_def, disjiUnion_val, Multiset.mem_bind, exists_prop] @[simp, norm_cast]
lemma coe_disjiUnion {h} : (s.disjiUnion t h : Set β) = ⋃ x ∈ (s : Set α), t x := by simp [Set.ext_iff, mem_disjiUnion, Set.mem_iUnion, mem_coe, imp_true_iff]
Mathlib/Data/Finset/Union.lean
53
54
/- Copyright (c) 2022 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp, Eric Wieser, Jeremy Avigad, Johan Commelin -/ import Mathlib.Data.Matrix.Invertible import Mathlib.LinearAlgebra.Matrix.NonsingularInverse import Mathlib.LinearAlgebra.Matrix.PosDef /-! # 2×2 block matrices and the Schur complement This file proves properties of 2×2 block matrices `[A B; C D]` that relate to the Schur complement `D - C*A⁻¹*B`. Some of the results here generalize to 2×2 matrices in a category, rather than just a ring. A few results in this direction can be found in the file `Mathlib.CategoryTheory.Preadditive.Biproducts`, especially the declarations `CategoryTheory.Biprod.gaussian` and `CategoryTheory.Biprod.isoElim`. Compare with `Matrix.invertibleOfFromBlocks₁₁Invertible`. ## Main results * `Matrix.det_fromBlocks₁₁`, `Matrix.det_fromBlocks₂₂`: determinant of a block matrix in terms of the Schur complement. * `Matrix.invOf_fromBlocks_zero₂₁_eq`, `Matrix.invOf_fromBlocks_zero₁₂_eq`: the inverse of a block triangular matrix. * `Matrix.isUnit_fromBlocks_zero₂₁`, `Matrix.isUnit_fromBlocks_zero₁₂`: invertibility of a block triangular matrix. * `Matrix.det_one_add_mul_comm`: the **Weinstein–Aronszajn identity**. * `Matrix.PosSemidef.fromBlocks₁₁` and `Matrix.PosSemidef.fromBlocks₂₂`: If a matrix `A` is positive definite, then `[A B; Bᎎ D]` is positive semidefinite if and only if `D - Bᎎ A⁻¹ B` is positive semidefinite. -/ variable {l m n α : Type*} namespace Matrix open scoped Matrix section CommRing variable [Fintype l] [Fintype m] [Fintype n] variable [DecidableEq l] [DecidableEq m] [DecidableEq n] variable [CommRing α] /-- LDU decomposition of a block matrix with an invertible top-left corner, using the Schur complement. -/ theorem fromBlocks_eq_of_invertible₁₁ (A : Matrix m m α) (B : Matrix m n α) (C : Matrix l m α) (D : Matrix l n α) [Invertible A] : fromBlocks A B C D = fromBlocks 1 0 (C * ⅟ A) 1 * fromBlocks A 0 0 (D - C * ⅟ A * B) * fromBlocks 1 (⅟ A * B) 0 1 := by simp only [fromBlocks_multiply, Matrix.mul_zero, Matrix.zero_mul, add_zero, zero_add, Matrix.one_mul, Matrix.mul_one, invOf_mul_self, Matrix.mul_invOf_cancel_left, Matrix.invOf_mul_cancel_right, Matrix.mul_assoc, add_sub_cancel] /-- LDU decomposition of a block matrix with an invertible bottom-right corner, using the Schur complement. -/ theorem fromBlocks_eq_of_invertible₂₂ (A : Matrix l m α) (B : Matrix l n α) (C : Matrix n m α) (D : Matrix n n α) [Invertible D] : fromBlocks A B C D = fromBlocks 1 (B * ⅟ D) 0 1 * fromBlocks (A - B * ⅟ D * C) 0 0 D * fromBlocks 1 0 (⅟ D * C) 1 := (Matrix.reindex (Equiv.sumComm _ _) (Equiv.sumComm _ _)).injective <| by simpa [reindex_apply, Equiv.sumComm_symm, ← submatrix_mul_equiv _ _ _ (Equiv.sumComm n m), ← submatrix_mul_equiv _ _ _ (Equiv.sumComm n l), Equiv.sumComm_apply, fromBlocks_submatrix_sum_swap_sum_swap] using fromBlocks_eq_of_invertible₁₁ D C B A section Triangular /-! #### Block triangular matrices -/ /-- An upper-block-triangular matrix is invertible if its diagonal is. -/ def fromBlocksZero₂₁Invertible (A : Matrix m m α) (B : Matrix m n α) (D : Matrix n n α) [Invertible A] [Invertible D] : Invertible (fromBlocks A B 0 D) := invertibleOfLeftInverse _ (fromBlocks (⅟ A) (-(⅟ A * B * ⅟ D)) 0 (⅟ D)) <| by simp_rw [fromBlocks_multiply, Matrix.mul_zero, Matrix.zero_mul, zero_add, add_zero, Matrix.neg_mul, invOf_mul_self, Matrix.invOf_mul_cancel_right, add_neg_cancel, fromBlocks_one] /-- A lower-block-triangular matrix is invertible if its diagonal is. -/ def fromBlocksZero₁₂Invertible (A : Matrix m m α) (C : Matrix n m α) (D : Matrix n n α) [Invertible A] [Invertible D] : Invertible (fromBlocks A 0 C D) := invertibleOfLeftInverse _ (fromBlocks (⅟ A) 0 (-(⅟ D * C * ⅟ A)) (⅟ D)) <| by -- a symmetry argument is more work than just copying the proof simp_rw [fromBlocks_multiply, Matrix.mul_zero, Matrix.zero_mul, zero_add, add_zero, Matrix.neg_mul, invOf_mul_self, Matrix.invOf_mul_cancel_right, neg_add_cancel, fromBlocks_one] theorem invOf_fromBlocks_zero₂₁_eq (A : Matrix m m α) (B : Matrix m n α) (D : Matrix n n α) [Invertible A] [Invertible D] [Invertible (fromBlocks A B 0 D)] : ⅟ (fromBlocks A B 0 D) = fromBlocks (⅟ A) (-(⅟ A * B * ⅟ D)) 0 (⅟ D) := by letI := fromBlocksZero₂₁Invertible A B D convert (rfl : ⅟ (fromBlocks A B 0 D) = _) theorem invOf_fromBlocks_zero₁₂_eq (A : Matrix m m α) (C : Matrix n m α) (D : Matrix n n α) [Invertible A] [Invertible D] [Invertible (fromBlocks A 0 C D)] : ⅟ (fromBlocks A 0 C D) = fromBlocks (⅟ A) 0 (-(⅟ D * C * ⅟ A)) (⅟ D) := by letI := fromBlocksZero₁₂Invertible A C D convert (rfl : ⅟ (fromBlocks A 0 C D) = _) /-- Both diagonal entries of an invertible upper-block-triangular matrix are invertible (by reading
off the diagonal entries of the inverse). -/ def invertibleOfFromBlocksZero₂₁Invertible (A : Matrix m m α) (B : Matrix m n α) (D : Matrix n n α) [Invertible (fromBlocks A B 0 D)] : Invertible A × Invertible D where fst := invertibleOfLeftInverse _ (⅟ (fromBlocks A B 0 D)).toBlocks₁₁ <| by
Mathlib/LinearAlgebra/Matrix/SchurComplement.lean
107
111
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne -/ import Mathlib.MeasureTheory.Integral.FinMeasAdditive /-! # Extension of a linear function from indicators to L1 Given `T : Set α → E →L[ℝ] F` with `DominatedFinMeasAdditive ÎŒ T C`, we construct an extension of `T` to integrable simple functions, which are finite sums of indicators of measurable sets with finite measure, then to integrable functions, which are limits of integrable simple functions. The main result is a continuous linear map `(α →₁[ÎŒ] E) →L[ℝ] F`. This extension process is used to define the Bochner integral in the `Mathlib.MeasureTheory.Integral.Bochner.Basic` file and the conditional expectation of an integrable function in `Mathlib.MeasureTheory.Function.ConditionalExpectation.CondexpL1`. ## Main definitions - `setToL1 (hT : DominatedFinMeasAdditive ÎŒ T C) : (α →₁[ÎŒ] E) →L[ℝ] F`: the extension of `T` from indicators to L1. - `setToFun ÎŒ T (hT : DominatedFinMeasAdditive ÎŒ T C) (f : α → E) : F`: a version of the extension which applies to functions (with value 0 if the function is not integrable). ## Properties For most properties of `setToFun`, we provide two lemmas. One version uses hypotheses valid on all sets, like `T = T'`, and a second version which uses a primed name uses hypotheses on measurable sets with finite measure, like `∀ s, MeasurableSet s → ÎŒ s < ∞ → T s = T' s`. The lemmas listed here don't show all hypotheses. Refer to the actual lemmas for details. Linearity: - `setToFun_zero_left : setToFun ÎŒ 0 hT f = 0` - `setToFun_add_left : setToFun ÎŒ (T + T') _ f = setToFun ÎŒ T hT f + setToFun ÎŒ T' hT' f` - `setToFun_smul_left : setToFun ÎŒ (fun s ↩ c • (T s)) (hT.smul c) f = c • setToFun ÎŒ T hT f` - `setToFun_zero : setToFun ÎŒ T hT (0 : α → E) = 0` - `setToFun_neg : setToFun ÎŒ T hT (-f) = - setToFun ÎŒ T hT f` If `f` and `g` are integrable: - `setToFun_add : setToFun ÎŒ T hT (f + g) = setToFun ÎŒ T hT f + setToFun ÎŒ T hT g` - `setToFun_sub : setToFun ÎŒ T hT (f - g) = setToFun ÎŒ T hT f - setToFun ÎŒ T hT g` If `T` is verifies `∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x`: - `setToFun_smul : setToFun ÎŒ T hT (c • f) = c • setToFun ÎŒ T hT f` Other: - `setToFun_congr_ae (h : f =ᵐ[ÎŒ] g) : setToFun ÎŒ T hT f = setToFun ÎŒ T hT g` - `setToFun_measure_zero (h : ÎŒ = 0) : setToFun ÎŒ T hT f = 0` If the space is also an ordered additive group with an order closed topology and `T` is such that `0 ≀ T s x` for `0 ≀ x`, we also prove order-related properties: - `setToFun_mono_left (h : ∀ s x, T s x ≀ T' s x) : setToFun ÎŒ T hT f ≀ setToFun ÎŒ T' hT' f` - `setToFun_nonneg (hf : 0 ≀ᵐ[ÎŒ] f) : 0 ≀ setToFun ÎŒ T hT f` - `setToFun_mono (hfg : f ≀ᵐ[ÎŒ] g) : setToFun ÎŒ T hT f ≀ setToFun ÎŒ T hT g` -/ noncomputable section open scoped Topology NNReal open Set Filter TopologicalSpace ENNReal namespace MeasureTheory variable {α E F F' G 𝕜 : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] [NormedAddCommGroup F'] [NormedSpace ℝ F'] [NormedAddCommGroup G] {m : MeasurableSpace α} {ÎŒ : Measure α} namespace L1 open AEEqFun Lp.simpleFunc Lp namespace SimpleFunc theorem norm_eq_sum_mul (f : α →₁ₛ[ÎŒ] G) : ‖f‖ = ∑ x ∈ (toSimpleFunc f).range, ÎŒ.real (toSimpleFunc f ⁻¹' {x}) * ‖x‖ := by rw [norm_toSimpleFunc, eLpNorm_one_eq_lintegral_enorm] have h_eq := SimpleFunc.map_apply (‖·‖ₑ) (toSimpleFunc f) simp_rw [← h_eq, measureReal_def] rw [SimpleFunc.lintegral_eq_lintegral, SimpleFunc.map_lintegral, ENNReal.toReal_sum] · congr ext1 x rw [ENNReal.toReal_mul, mul_comm, ← ofReal_norm_eq_enorm, ENNReal.toReal_ofReal (norm_nonneg _)] · intro x _ by_cases hx0 : x = 0 · rw [hx0]; simp · exact ENNReal.mul_ne_top ENNReal.coe_ne_top (SimpleFunc.measure_preimage_lt_top_of_integrable _ (SimpleFunc.integrable f) hx0).ne section SetToL1S variable [NormedField 𝕜] [NormedSpace 𝕜 E] attribute [local instance] Lp.simpleFunc.module attribute [local instance] Lp.simpleFunc.normedSpace /-- Extend `Set α → (E →L[ℝ] F')` to `(α →₁ₛ[ÎŒ] E) → F'`. -/ def setToL1S (T : Set α → E →L[ℝ] F) (f : α →₁ₛ[ÎŒ] E) : F := (toSimpleFunc f).setToSimpleFunc T theorem setToL1S_eq_setToSimpleFunc (T : Set α → E →L[ℝ] F) (f : α →₁ₛ[ÎŒ] E) : setToL1S T f = (toSimpleFunc f).setToSimpleFunc T := rfl @[simp] theorem setToL1S_zero_left (f : α →₁ₛ[ÎŒ] E) : setToL1S (0 : Set α → E →L[ℝ] F) f = 0 := SimpleFunc.setToSimpleFunc_zero _ theorem setToL1S_zero_left' {T : Set α → E →L[ℝ] F} (h_zero : ∀ s, MeasurableSet s → ÎŒ s < ∞ → T s = 0) (f : α →₁ₛ[ÎŒ] E) : setToL1S T f = 0 := SimpleFunc.setToSimpleFunc_zero' h_zero _ (SimpleFunc.integrable f) theorem setToL1S_congr (T : Set α → E →L[ℝ] F) (h_zero : ∀ s, MeasurableSet s → ÎŒ s = 0 → T s = 0) (h_add : FinMeasAdditive ÎŒ T) {f g : α →₁ₛ[ÎŒ] E} (h : toSimpleFunc f =ᵐ[ÎŒ] toSimpleFunc g) : setToL1S T f = setToL1S T g := SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable f) h theorem setToL1S_congr_left (T T' : Set α → E →L[ℝ] F) (h : ∀ s, MeasurableSet s → ÎŒ s < ∞ → T s = T' s) (f : α →₁ₛ[ÎŒ] E) : setToL1S T f = setToL1S T' f := SimpleFunc.setToSimpleFunc_congr_left T T' h (simpleFunc.toSimpleFunc f) (SimpleFunc.integrable f) /-- `setToL1S` does not change if we replace the measure `ÎŒ` by `ÎŒ'` with `ÎŒ ≪ ÎŒ'`. The statement uses two functions `f` and `f'` because they have to belong to different types, but morally these are the same function (we have `f =ᵐ[ÎŒ] f'`). -/ theorem setToL1S_congr_measure {ÎŒ' : Measure α} (T : Set α → E →L[ℝ] F) (h_zero : ∀ s, MeasurableSet s → ÎŒ s = 0 → T s = 0) (h_add : FinMeasAdditive ÎŒ T) (hÎŒ : ÎŒ ≪ ÎŒ') (f : α →₁ₛ[ÎŒ] E) (f' : α →₁ₛ[ÎŒ'] E) (h : (f : α → E) =ᵐ[ÎŒ] f') : setToL1S T f = setToL1S T f' := by refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable f) ?_ refine (toSimpleFunc_eq_toFun f).trans ?_ suffices (f' : α → E) =ᵐ[ÎŒ] simpleFunc.toSimpleFunc f' from h.trans this have goal' : (f' : α → E) =ᵐ[ÎŒ'] simpleFunc.toSimpleFunc f' := (toSimpleFunc_eq_toFun f').symm exact hÎŒ.ae_eq goal' theorem setToL1S_add_left (T T' : Set α → E →L[ℝ] F) (f : α →₁ₛ[ÎŒ] E) : setToL1S (T + T') f = setToL1S T f + setToL1S T' f := SimpleFunc.setToSimpleFunc_add_left T T' theorem setToL1S_add_left' (T T' T'' : Set α → E →L[ℝ] F) (h_add : ∀ s, MeasurableSet s → ÎŒ s < ∞ → T'' s = T s + T' s) (f : α →₁ₛ[ÎŒ] E) : setToL1S T'' f = setToL1S T f + setToL1S T' f := SimpleFunc.setToSimpleFunc_add_left' T T' T'' h_add (SimpleFunc.integrable f) theorem setToL1S_smul_left (T : Set α → E →L[ℝ] F) (c : ℝ) (f : α →₁ₛ[ÎŒ] E) : setToL1S (fun s => c • T s) f = c • setToL1S T f := SimpleFunc.setToSimpleFunc_smul_left T c _ theorem setToL1S_smul_left' (T T' : Set α → E →L[ℝ] F) (c : ℝ) (h_smul : ∀ s, MeasurableSet s → ÎŒ s < ∞ → T' s = c • T s) (f : α →₁ₛ[ÎŒ] E) : setToL1S T' f = c • setToL1S T f := SimpleFunc.setToSimpleFunc_smul_left' T T' c h_smul (SimpleFunc.integrable f) theorem setToL1S_add (T : Set α → E →L[ℝ] F) (h_zero : ∀ s, MeasurableSet s → ÎŒ s = 0 → T s = 0) (h_add : FinMeasAdditive ÎŒ T) (f g : α →₁ₛ[ÎŒ] E) : setToL1S T (f + g) = setToL1S T f + setToL1S T g := by simp_rw [setToL1S] rw [← SimpleFunc.setToSimpleFunc_add T h_add (SimpleFunc.integrable f) (SimpleFunc.integrable g)] exact SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) (add_toSimpleFunc f g) theorem setToL1S_neg {T : Set α → E →L[ℝ] F} (h_zero : ∀ s, MeasurableSet s → ÎŒ s = 0 → T s = 0) (h_add : FinMeasAdditive ÎŒ T) (f : α →₁ₛ[ÎŒ] E) : setToL1S T (-f) = -setToL1S T f := by simp_rw [setToL1S] have : simpleFunc.toSimpleFunc (-f) =ᵐ[ÎŒ] ⇑(-simpleFunc.toSimpleFunc f) := neg_toSimpleFunc f rw [SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) this] exact SimpleFunc.setToSimpleFunc_neg T h_add (SimpleFunc.integrable f) theorem setToL1S_sub {T : Set α → E →L[ℝ] F} (h_zero : ∀ s, MeasurableSet s → ÎŒ s = 0 → T s = 0) (h_add : FinMeasAdditive ÎŒ T) (f g : α →₁ₛ[ÎŒ] E) : setToL1S T (f - g) = setToL1S T f - setToL1S T g := by rw [sub_eq_add_neg, setToL1S_add T h_zero h_add, setToL1S_neg h_zero h_add, sub_eq_add_neg] theorem setToL1S_smul_real (T : Set α → E →L[ℝ] F) (h_zero : ∀ s, MeasurableSet s → ÎŒ s = 0 → T s = 0) (h_add : FinMeasAdditive ÎŒ T) (c : ℝ) (f : α →₁ₛ[ÎŒ] E) : setToL1S T (c • f) = c • setToL1S T f := by simp_rw [setToL1S] rw [← SimpleFunc.setToSimpleFunc_smul_real T h_add c (SimpleFunc.integrable f)] refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) ?_ exact smul_toSimpleFunc c f theorem setToL1S_smul {E} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedSpace 𝕜 E] [DistribSMul 𝕜 F] (T : Set α → E →L[ℝ] F) (h_zero : ∀ s, MeasurableSet s → ÎŒ s = 0 → T s = 0) (h_add : FinMeasAdditive ÎŒ T) (h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (c : 𝕜) (f : α →₁ₛ[ÎŒ] E) : setToL1S T (c • f) = c • setToL1S T f := by simp_rw [setToL1S] rw [← SimpleFunc.setToSimpleFunc_smul T h_add h_smul c (SimpleFunc.integrable f)] refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) ?_ exact smul_toSimpleFunc c f theorem norm_setToL1S_le (T : Set α → E →L[ℝ] F) {C : ℝ} (hT_norm : ∀ s, MeasurableSet s → ÎŒ s < ∞ → ‖T s‖ ≀ C * ÎŒ.real s) (f : α →₁ₛ[ÎŒ] E) : ‖setToL1S T f‖ ≀ C * ‖f‖ := by rw [setToL1S, norm_eq_sum_mul f] exact SimpleFunc.norm_setToSimpleFunc_le_sum_mul_norm_of_integrable T hT_norm _ (SimpleFunc.integrable f) theorem setToL1S_indicatorConst {T : Set α → E →L[ℝ] F} {s : Set α} (h_zero : ∀ s, MeasurableSet s → ÎŒ s = 0 → T s = 0) (h_add : FinMeasAdditive ÎŒ T) (hs : MeasurableSet s) (hÎŒs : ÎŒ s < ∞) (x : E) : setToL1S T (simpleFunc.indicatorConst 1 hs hÎŒs.ne x) = T s x := by have h_empty : T ∅ = 0 := h_zero _ MeasurableSet.empty measure_empty rw [setToL1S_eq_setToSimpleFunc] refine Eq.trans ?_ (SimpleFunc.setToSimpleFunc_indicator T h_empty hs x) refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) ?_ exact toSimpleFunc_indicatorConst hs hÎŒs.ne x theorem setToL1S_const [IsFiniteMeasure ÎŒ] {T : Set α → E →L[ℝ] F} (h_zero : ∀ s, MeasurableSet s → ÎŒ s = 0 → T s = 0) (h_add : FinMeasAdditive ÎŒ T) (x : E) : setToL1S T (simpleFunc.indicatorConst 1 MeasurableSet.univ (measure_ne_top ÎŒ _) x) = T univ x := setToL1S_indicatorConst h_zero h_add MeasurableSet.univ (measure_lt_top _ _) x section Order variable {G'' G' : Type*} [NormedAddCommGroup G'] [PartialOrder G'] [IsOrderedAddMonoid G'] [NormedSpace ℝ G'] [NormedAddCommGroup G''] [PartialOrder G''] [IsOrderedAddMonoid G''] [NormedSpace ℝ G''] {T : Set α → G'' →L[ℝ] G'} theorem setToL1S_mono_left {T T' : Set α → E →L[ℝ] G''} (hTT' : ∀ s x, T s x ≀ T' s x) (f : α →₁ₛ[ÎŒ] E) : setToL1S T f ≀ setToL1S T' f := SimpleFunc.setToSimpleFunc_mono_left T T' hTT' _ theorem setToL1S_mono_left' {T T' : Set α → E →L[ℝ] G''} (hTT' : ∀ s, MeasurableSet s → ÎŒ s < ∞ → ∀ x, T s x ≀ T' s x) (f : α →₁ₛ[ÎŒ] E) : setToL1S T f ≀ setToL1S T' f := SimpleFunc.setToSimpleFunc_mono_left' T T' hTT' _ (SimpleFunc.integrable f) omit [IsOrderedAddMonoid G''] in theorem setToL1S_nonneg (h_zero : ∀ s, MeasurableSet s → ÎŒ s = 0 → T s = 0) (h_add : FinMeasAdditive ÎŒ T) (hT_nonneg : ∀ s, MeasurableSet s → ÎŒ s < ∞ → ∀ x, 0 ≀ x → 0 ≀ T s x) {f : α →₁ₛ[ÎŒ] G''} (hf : 0 ≀ f) : 0 ≀ setToL1S T f := by simp_rw [setToL1S] obtain ⟹f', hf', hff'⟩ := exists_simpleFunc_nonneg_ae_eq hf replace hff' : simpleFunc.toSimpleFunc f =ᵐ[ÎŒ] f' := (Lp.simpleFunc.toSimpleFunc_eq_toFun f).trans hff' rw [SimpleFunc.setToSimpleFunc_congr _ h_zero h_add (SimpleFunc.integrable _) hff'] exact SimpleFunc.setToSimpleFunc_nonneg' T hT_nonneg _ hf' ((SimpleFunc.integrable f).congr hff') theorem setToL1S_mono (h_zero : ∀ s, MeasurableSet s → ÎŒ s = 0 → T s = 0) (h_add : FinMeasAdditive ÎŒ T) (hT_nonneg : ∀ s, MeasurableSet s → ÎŒ s < ∞ → ∀ x, 0 ≀ x → 0 ≀ T s x) {f g : α →₁ₛ[ÎŒ] G''} (hfg : f ≀ g) : setToL1S T f ≀ setToL1S T g := by rw [← sub_nonneg] at hfg ⊢ rw [← setToL1S_sub h_zero h_add] exact setToL1S_nonneg h_zero h_add hT_nonneg hfg end Order variable [NormedSpace 𝕜 F] variable (α E ÎŒ 𝕜) /-- Extend `Set α → E →L[ℝ] F` to `(α →₁ₛ[ÎŒ] E) →L[𝕜] F`. -/ def setToL1SCLM' {T : Set α → E →L[ℝ] F} {C : ℝ} (hT : DominatedFinMeasAdditive ÎŒ T C) (h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) : (α →₁ₛ[ÎŒ] E) →L[𝕜] F := LinearMap.mkContinuous ⟹⟹setToL1S T, setToL1S_add T (fun _ => hT.eq_zero_of_measure_zero) hT.1⟩, setToL1S_smul T (fun _ => hT.eq_zero_of_measure_zero) hT.1 h_smul⟩ C fun f => norm_setToL1S_le T hT.2 f /-- Extend `Set α → E →L[ℝ] F` to `(α →₁ₛ[ÎŒ] E) →L[ℝ] F`. -/ def setToL1SCLM {T : Set α → E →L[ℝ] F} {C : ℝ} (hT : DominatedFinMeasAdditive ÎŒ T C) : (α →₁ₛ[ÎŒ] E) →L[ℝ] F := LinearMap.mkContinuous ⟹⟹setToL1S T, setToL1S_add T (fun _ => hT.eq_zero_of_measure_zero) hT.1⟩, setToL1S_smul_real T (fun _ => hT.eq_zero_of_measure_zero) hT.1⟩ C fun f => norm_setToL1S_le T hT.2 f variable {α E ÎŒ 𝕜} variable {T T' T'' : Set α → E →L[ℝ] F} {C C' C'' : ℝ} @[simp] theorem setToL1SCLM_zero_left (hT : DominatedFinMeasAdditive ÎŒ (0 : Set α → E →L[ℝ] F) C) (f : α →₁ₛ[ÎŒ] E) : setToL1SCLM α E ÎŒ hT f = 0 := setToL1S_zero_left _ theorem setToL1SCLM_zero_left' (hT : DominatedFinMeasAdditive ÎŒ T C) (h_zero : ∀ s, MeasurableSet s → ÎŒ s < ∞ → T s = 0) (f : α →₁ₛ[ÎŒ] E) : setToL1SCLM α E ÎŒ hT f = 0 := setToL1S_zero_left' h_zero f theorem setToL1SCLM_congr_left (hT : DominatedFinMeasAdditive ÎŒ T C) (hT' : DominatedFinMeasAdditive ÎŒ T' C') (h : T = T') (f : α →₁ₛ[ÎŒ] E) : setToL1SCLM α E ÎŒ hT f = setToL1SCLM α E ÎŒ hT' f := setToL1S_congr_left T T' (fun _ _ _ => by rw [h]) f theorem setToL1SCLM_congr_left' (hT : DominatedFinMeasAdditive ÎŒ T C) (hT' : DominatedFinMeasAdditive ÎŒ T' C') (h : ∀ s, MeasurableSet s → ÎŒ s < ∞ → T s = T' s) (f : α →₁ₛ[ÎŒ] E) : setToL1SCLM α E ÎŒ hT f = setToL1SCLM α E ÎŒ hT' f := setToL1S_congr_left T T' h f theorem setToL1SCLM_congr_measure {ÎŒ' : Measure α} (hT : DominatedFinMeasAdditive ÎŒ T C) (hT' : DominatedFinMeasAdditive ÎŒ' T C') (hÎŒ : ÎŒ ≪ ÎŒ') (f : α →₁ₛ[ÎŒ] E) (f' : α →₁ₛ[ÎŒ'] E) (h : (f : α → E) =ᵐ[ÎŒ] f') : setToL1SCLM α E ÎŒ hT f = setToL1SCLM α E ÎŒ' hT' f' := setToL1S_congr_measure T (fun _ => hT.eq_zero_of_measure_zero) hT.1 hÎŒ _ _ h theorem setToL1SCLM_add_left (hT : DominatedFinMeasAdditive ÎŒ T C) (hT' : DominatedFinMeasAdditive ÎŒ T' C') (f : α →₁ₛ[ÎŒ] E) : setToL1SCLM α E ÎŒ (hT.add hT') f = setToL1SCLM α E ÎŒ hT f + setToL1SCLM α E ÎŒ hT' f := setToL1S_add_left T T' f theorem setToL1SCLM_add_left' (hT : DominatedFinMeasAdditive ÎŒ T C) (hT' : DominatedFinMeasAdditive ÎŒ T' C') (hT'' : DominatedFinMeasAdditive ÎŒ T'' C'') (h_add : ∀ s, MeasurableSet s → ÎŒ s < ∞ → T'' s = T s + T' s) (f : α →₁ₛ[ÎŒ] E) : setToL1SCLM α E ÎŒ hT'' f = setToL1SCLM α E ÎŒ hT f + setToL1SCLM α E ÎŒ hT' f := setToL1S_add_left' T T' T'' h_add f theorem setToL1SCLM_smul_left (c : ℝ) (hT : DominatedFinMeasAdditive ÎŒ T C) (f : α →₁ₛ[ÎŒ] E) : setToL1SCLM α E ÎŒ (hT.smul c) f = c • setToL1SCLM α E ÎŒ hT f := setToL1S_smul_left T c f theorem setToL1SCLM_smul_left' (c : ℝ) (hT : DominatedFinMeasAdditive ÎŒ T C) (hT' : DominatedFinMeasAdditive ÎŒ T' C') (h_smul : ∀ s, MeasurableSet s → ÎŒ s < ∞ → T' s = c • T s) (f : α →₁ₛ[ÎŒ] E) : setToL1SCLM α E ÎŒ hT' f = c • setToL1SCLM α E ÎŒ hT f := setToL1S_smul_left' T T' c h_smul f theorem norm_setToL1SCLM_le {T : Set α → E →L[ℝ] F} {C : ℝ} (hT : DominatedFinMeasAdditive ÎŒ T C) (hC : 0 ≀ C) : ‖setToL1SCLM α E ÎŒ hT‖ ≀ C := LinearMap.mkContinuous_norm_le _ hC _ theorem norm_setToL1SCLM_le' {T : Set α → E →L[ℝ] F} {C : ℝ} (hT : DominatedFinMeasAdditive ÎŒ T C) : ‖setToL1SCLM α E ÎŒ hT‖ ≀ max C 0 := LinearMap.mkContinuous_norm_le' _ _ theorem setToL1SCLM_const [IsFiniteMeasure ÎŒ] {T : Set α → E →L[ℝ] F} {C : ℝ} (hT : DominatedFinMeasAdditive ÎŒ T C) (x : E) : setToL1SCLM α E ÎŒ hT (simpleFunc.indicatorConst 1 MeasurableSet.univ (measure_ne_top ÎŒ _) x) = T univ x := setToL1S_const (fun _ => hT.eq_zero_of_measure_zero) hT.1 x section Order variable {G' G'' : Type*} [NormedAddCommGroup G''] [PartialOrder G''] [IsOrderedAddMonoid G''] [NormedSpace ℝ G''] [NormedAddCommGroup G'] [PartialOrder G'] [IsOrderedAddMonoid G'] [NormedSpace ℝ G'] theorem setToL1SCLM_mono_left {T T' : Set α → E →L[ℝ] G''} {C C' : ℝ} (hT : DominatedFinMeasAdditive ÎŒ T C) (hT' : DominatedFinMeasAdditive ÎŒ T' C') (hTT' : ∀ s x, T s x ≀ T' s x) (f : α →₁ₛ[ÎŒ] E) : setToL1SCLM α E ÎŒ hT f ≀ setToL1SCLM α E ÎŒ hT' f := SimpleFunc.setToSimpleFunc_mono_left T T' hTT' _ theorem setToL1SCLM_mono_left' {T T' : Set α → E →L[ℝ] G''} {C C' : ℝ} (hT : DominatedFinMeasAdditive ÎŒ T C) (hT' : DominatedFinMeasAdditive ÎŒ T' C') (hTT' : ∀ s, MeasurableSet s → ÎŒ s < ∞ → ∀ x, T s x ≀ T' s x) (f : α →₁ₛ[ÎŒ] E) : setToL1SCLM α E ÎŒ hT f ≀ setToL1SCLM α E ÎŒ hT' f := SimpleFunc.setToSimpleFunc_mono_left' T T' hTT' _ (SimpleFunc.integrable f) omit [IsOrderedAddMonoid G'] in theorem setToL1SCLM_nonneg {T : Set α → G' →L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive ÎŒ T C) (hT_nonneg : ∀ s, MeasurableSet s → ÎŒ s < ∞ → ∀ x, 0 ≀ x → 0 ≀ T s x) {f : α →₁ₛ[ÎŒ] G'} (hf : 0 ≀ f) : 0 ≀ setToL1SCLM α G' ÎŒ hT f := setToL1S_nonneg (fun _ => hT.eq_zero_of_measure_zero) hT.1 hT_nonneg hf theorem setToL1SCLM_mono {T : Set α → G' →L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive ÎŒ T C) (hT_nonneg : ∀ s, MeasurableSet s → ÎŒ s < ∞ → ∀ x, 0 ≀ x → 0 ≀ T s x) {f g : α →₁ₛ[ÎŒ] G'} (hfg : f ≀ g) : setToL1SCLM α G' ÎŒ hT f ≀ setToL1SCLM α G' ÎŒ hT g := setToL1S_mono (fun _ => hT.eq_zero_of_measure_zero) hT.1 hT_nonneg hfg end Order end SetToL1S end SimpleFunc open SimpleFunc section SetToL1 attribute [local instance] Lp.simpleFunc.module attribute [local instance] Lp.simpleFunc.normedSpace variable (𝕜) [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace 𝕜 F] [CompleteSpace F] {T T' T'' : Set α → E →L[ℝ] F} {C C' C'' : ℝ} /-- Extend `Set α → (E →L[ℝ] F)` to `(α →₁[ÎŒ] E) →L[𝕜] F`. -/ def setToL1' (hT : DominatedFinMeasAdditive ÎŒ T C) (h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) : (α →₁[ÎŒ] E) →L[𝕜] F := (setToL1SCLM' α E 𝕜 ÎŒ hT h_smul).extend (coeToLp α E 𝕜) (simpleFunc.denseRange one_ne_top) simpleFunc.isUniformInducing variable {𝕜} /-- Extend `Set α → E →L[ℝ] F` to `(α →₁[ÎŒ] E) →L[ℝ] F`. -/ def setToL1 (hT : DominatedFinMeasAdditive ÎŒ T C) : (α →₁[ÎŒ] E) →L[ℝ] F := (setToL1SCLM α E ÎŒ hT).extend (coeToLp α E ℝ) (simpleFunc.denseRange one_ne_top) simpleFunc.isUniformInducing theorem setToL1_eq_setToL1SCLM (hT : DominatedFinMeasAdditive ÎŒ T C) (f : α →₁ₛ[ÎŒ] E) : setToL1 hT f = setToL1SCLM α E ÎŒ hT f := uniformly_extend_of_ind simpleFunc.isUniformInducing (simpleFunc.denseRange one_ne_top) (setToL1SCLM α E ÎŒ hT).uniformContinuous _ theorem setToL1_eq_setToL1' (hT : DominatedFinMeasAdditive ÎŒ T C) (h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (f : α →₁[ÎŒ] E) : setToL1 hT f = setToL1' 𝕜 hT h_smul f := rfl @[simp] theorem setToL1_zero_left (hT : DominatedFinMeasAdditive ÎŒ (0 : Set α → E →L[ℝ] F) C) (f : α →₁[ÎŒ] E) : setToL1 hT f = 0 := by suffices setToL1 hT = 0 by rw [this]; simp refine ContinuousLinearMap.extend_unique (setToL1SCLM α E ÎŒ hT) _ _ _ _ ?_ ext1 f rw [setToL1SCLM_zero_left hT f, ContinuousLinearMap.zero_comp, ContinuousLinearMap.zero_apply] theorem setToL1_zero_left' (hT : DominatedFinMeasAdditive ÎŒ T C) (h_zero : ∀ s, MeasurableSet s → ÎŒ s < ∞ → T s = 0) (f : α →₁[ÎŒ] E) : setToL1 hT f = 0 := by suffices setToL1 hT = 0 by rw [this]; simp refine ContinuousLinearMap.extend_unique (setToL1SCLM α E ÎŒ hT) _ _ _ _ ?_ ext1 f rw [setToL1SCLM_zero_left' hT h_zero f, ContinuousLinearMap.zero_comp, ContinuousLinearMap.zero_apply] theorem setToL1_congr_left (T T' : Set α → E →L[ℝ] F) {C C' : ℝ} (hT : DominatedFinMeasAdditive ÎŒ T C) (hT' : DominatedFinMeasAdditive ÎŒ T' C') (h : T = T') (f : α →₁[ÎŒ] E) : setToL1 hT f = setToL1 hT' f := by suffices setToL1 hT = setToL1 hT' by rw [this] refine ContinuousLinearMap.extend_unique (setToL1SCLM α E ÎŒ hT) _ _ _ _ ?_ ext1 f suffices setToL1 hT' f = setToL1SCLM α E ÎŒ hT f by rw [← this]; simp [coeToLp] rw [setToL1_eq_setToL1SCLM] exact setToL1SCLM_congr_left hT' hT h.symm f theorem setToL1_congr_left' (T T' : Set α → E →L[ℝ] F) {C C' : ℝ} (hT : DominatedFinMeasAdditive ÎŒ T C) (hT' : DominatedFinMeasAdditive ÎŒ T' C') (h : ∀ s, MeasurableSet s → ÎŒ s < ∞ → T s = T' s) (f : α →₁[ÎŒ] E) : setToL1 hT f = setToL1 hT' f := by suffices setToL1 hT = setToL1 hT' by rw [this] refine ContinuousLinearMap.extend_unique (setToL1SCLM α E ÎŒ hT) _ _ _ _ ?_ ext1 f suffices setToL1 hT' f = setToL1SCLM α E ÎŒ hT f by rw [← this]; simp [coeToLp] rw [setToL1_eq_setToL1SCLM] exact (setToL1SCLM_congr_left' hT hT' h f).symm theorem setToL1_add_left (hT : DominatedFinMeasAdditive ÎŒ T C) (hT' : DominatedFinMeasAdditive ÎŒ T' C') (f : α →₁[ÎŒ] E) : setToL1 (hT.add hT') f = setToL1 hT f + setToL1 hT' f := by suffices setToL1 (hT.add hT') = setToL1 hT + setToL1 hT' by rw [this, ContinuousLinearMap.add_apply] refine ContinuousLinearMap.extend_unique (setToL1SCLM α E ÎŒ (hT.add hT')) _ _ _ _ ?_ ext1 f suffices setToL1 hT f + setToL1 hT' f = setToL1SCLM α E ÎŒ (hT.add hT') f by rw [← this]; simp [coeToLp] rw [setToL1_eq_setToL1SCLM, setToL1_eq_setToL1SCLM, setToL1SCLM_add_left hT hT'] theorem setToL1_add_left' (hT : DominatedFinMeasAdditive ÎŒ T C) (hT' : DominatedFinMeasAdditive ÎŒ T' C') (hT'' : DominatedFinMeasAdditive ÎŒ T'' C'') (h_add : ∀ s, MeasurableSet s → ÎŒ s < ∞ → T'' s = T s + T' s) (f : α →₁[ÎŒ] E) : setToL1 hT'' f = setToL1 hT f + setToL1 hT' f := by suffices setToL1 hT'' = setToL1 hT + setToL1 hT' by rw [this, ContinuousLinearMap.add_apply] refine ContinuousLinearMap.extend_unique (setToL1SCLM α E ÎŒ hT'') _ _ _ _ ?_ ext1 f suffices setToL1 hT f + setToL1 hT' f = setToL1SCLM α E ÎŒ hT'' f by rw [← this]; simp [coeToLp] rw [setToL1_eq_setToL1SCLM, setToL1_eq_setToL1SCLM, setToL1SCLM_add_left' hT hT' hT'' h_add] theorem setToL1_smul_left (hT : DominatedFinMeasAdditive ÎŒ T C) (c : ℝ) (f : α →₁[ÎŒ] E) : setToL1 (hT.smul c) f = c • setToL1 hT f := by suffices setToL1 (hT.smul c) = c • setToL1 hT by rw [this, ContinuousLinearMap.smul_apply] refine ContinuousLinearMap.extend_unique (setToL1SCLM α E ÎŒ (hT.smul c)) _ _ _ _ ?_ ext1 f suffices c • setToL1 hT f = setToL1SCLM α E ÎŒ (hT.smul c) f by rw [← this]; simp [coeToLp] rw [setToL1_eq_setToL1SCLM, setToL1SCLM_smul_left c hT] theorem setToL1_smul_left' (hT : DominatedFinMeasAdditive ÎŒ T C) (hT' : DominatedFinMeasAdditive ÎŒ T' C') (c : ℝ) (h_smul : ∀ s, MeasurableSet s → ÎŒ s < ∞ → T' s = c • T s) (f : α →₁[ÎŒ] E) : setToL1 hT' f = c • setToL1 hT f := by suffices setToL1 hT' = c • setToL1 hT by rw [this, ContinuousLinearMap.smul_apply] refine ContinuousLinearMap.extend_unique (setToL1SCLM α E ÎŒ hT') _ _ _ _ ?_ ext1 f suffices c • setToL1 hT f = setToL1SCLM α E ÎŒ hT' f by rw [← this]; simp [coeToLp] rw [setToL1_eq_setToL1SCLM, setToL1SCLM_smul_left' c hT hT' h_smul] theorem setToL1_smul (hT : DominatedFinMeasAdditive ÎŒ T C) (h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (c : 𝕜) (f : α →₁[ÎŒ] E) : setToL1 hT (c • f) = c • setToL1 hT f := by rw [setToL1_eq_setToL1' hT h_smul, setToL1_eq_setToL1' hT h_smul] exact ContinuousLinearMap.map_smul _ _ _ theorem setToL1_simpleFunc_indicatorConst (hT : DominatedFinMeasAdditive ÎŒ T C) {s : Set α} (hs : MeasurableSet s) (hÎŒs : ÎŒ s < ∞) (x : E) : setToL1 hT (simpleFunc.indicatorConst 1 hs hÎŒs.ne x) = T s x := by rw [setToL1_eq_setToL1SCLM] exact setToL1S_indicatorConst (fun s => hT.eq_zero_of_measure_zero) hT.1 hs hÎŒs x theorem setToL1_indicatorConstLp (hT : DominatedFinMeasAdditive ÎŒ T C) {s : Set α} (hs : MeasurableSet s) (hÎŒs : ÎŒ s ≠ ∞) (x : E) : setToL1 hT (indicatorConstLp 1 hs hÎŒs x) = T s x := by rw [← Lp.simpleFunc.coe_indicatorConst hs hÎŒs x] exact setToL1_simpleFunc_indicatorConst hT hs hÎŒs.lt_top x theorem setToL1_const [IsFiniteMeasure ÎŒ] (hT : DominatedFinMeasAdditive ÎŒ T C) (x : E) : setToL1 hT (indicatorConstLp 1 MeasurableSet.univ (measure_ne_top _ _) x) = T univ x := setToL1_indicatorConstLp hT MeasurableSet.univ (measure_ne_top _ _) x section Order variable {G' G'' : Type*} [NormedAddCommGroup G''] [PartialOrder G''] [OrderClosedTopology G''] [IsOrderedAddMonoid G''] [NormedSpace ℝ G''] [CompleteSpace G''] [NormedAddCommGroup G'] [PartialOrder G'] [NormedSpace ℝ G'] theorem setToL1_mono_left' {T T' : Set α → E →L[ℝ] G''} {C C' : ℝ} (hT : DominatedFinMeasAdditive ÎŒ T C) (hT' : DominatedFinMeasAdditive ÎŒ T' C') (hTT' : ∀ s, MeasurableSet s → ÎŒ s < ∞ → ∀ x, T s x ≀ T' s x) (f : α →₁[ÎŒ] E) : setToL1 hT f ≀ setToL1 hT' f := by induction f using Lp.induction (hp_ne_top := one_ne_top) with | @indicatorConst c s hs hÎŒs => rw [setToL1_simpleFunc_indicatorConst hT hs hÎŒs, setToL1_simpleFunc_indicatorConst hT' hs hÎŒs] exact hTT' s hs hÎŒs c | @add f g hf hg _ hf_le hg_le => rw [(setToL1 hT).map_add, (setToL1 hT').map_add] exact add_le_add hf_le hg_le | isClosed => exact isClosed_le (setToL1 hT).continuous (setToL1 hT').continuous theorem setToL1_mono_left {T T' : Set α → E →L[ℝ] G''} {C C' : ℝ} (hT : DominatedFinMeasAdditive ÎŒ T C) (hT' : DominatedFinMeasAdditive ÎŒ T' C') (hTT' : ∀ s x, T s x ≀ T' s x) (f : α →₁[ÎŒ] E) : setToL1 hT f ≀ setToL1 hT' f := setToL1_mono_left' hT hT' (fun s _ _ x => hTT' s x) f theorem setToL1_nonneg {T : Set α → G' →L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive ÎŒ T C) (hT_nonneg : ∀ s, MeasurableSet s → ÎŒ s < ∞ → ∀ x, 0 ≀ x → 0 ≀ T s x) {f : α →₁[ÎŒ] G'} (hf : 0 ≀ f) : 0 ≀ setToL1 hT f := by suffices ∀ f : { g : α →₁[ÎŒ] G' // 0 ≀ g }, 0 ≀ setToL1 hT f from this (⟹f, hf⟩ : { g : α →₁[ÎŒ] G' // 0 ≀ g }) refine fun g => @isClosed_property { g : α →₁ₛ[ÎŒ] G' // 0 ≀ g } { g : α →₁[ÎŒ] G' // 0 ≀ g } _ _ (fun g => 0 ≀ setToL1 hT g) (denseRange_coeSimpleFuncNonnegToLpNonneg 1 ÎŒ G' one_ne_top) ?_ ?_ g · exact isClosed_le continuous_zero ((setToL1 hT).continuous.comp continuous_induced_dom) · intro g have : (coeSimpleFuncNonnegToLpNonneg 1 ÎŒ G' g : α →₁[ÎŒ] G') = (g : α →₁ₛ[ÎŒ] G') := rfl rw [this, setToL1_eq_setToL1SCLM] exact setToL1S_nonneg (fun s => hT.eq_zero_of_measure_zero) hT.1 hT_nonneg g.2 theorem setToL1_mono [IsOrderedAddMonoid G'] {T : Set α → G' →L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive ÎŒ T C) (hT_nonneg : ∀ s, MeasurableSet s → ÎŒ s < ∞ → ∀ x, 0 ≀ x → 0 ≀ T s x) {f g : α →₁[ÎŒ] G'} (hfg : f ≀ g) : setToL1 hT f ≀ setToL1 hT g := by rw [← sub_nonneg] at hfg ⊢ rw [← (setToL1 hT).map_sub] exact setToL1_nonneg hT hT_nonneg hfg end Order theorem norm_setToL1_le_norm_setToL1SCLM (hT : DominatedFinMeasAdditive ÎŒ T C) : ‖setToL1 hT‖ ≀ ‖setToL1SCLM α E ÎŒ hT‖ := calc ‖setToL1 hT‖ ≀ (1 : ℝ≥0) * ‖setToL1SCLM α E ÎŒ hT‖ := by refine ContinuousLinearMap.opNorm_extend_le (setToL1SCLM α E ÎŒ hT) (coeToLp α E ℝ) (simpleFunc.denseRange one_ne_top) fun x => le_of_eq ?_ rw [NNReal.coe_one, one_mul] simp [coeToLp] _ = ‖setToL1SCLM α E ÎŒ hT‖ := by rw [NNReal.coe_one, one_mul] theorem norm_setToL1_le_mul_norm (hT : DominatedFinMeasAdditive ÎŒ T C) (hC : 0 ≀ C) (f : α →₁[ÎŒ] E) : ‖setToL1 hT f‖ ≀ C * ‖f‖ := calc ‖setToL1 hT f‖ ≀ ‖setToL1SCLM α E ÎŒ hT‖ * ‖f‖ := ContinuousLinearMap.le_of_opNorm_le _ (norm_setToL1_le_norm_setToL1SCLM hT) _ _ ≀ C * ‖f‖ := mul_le_mul (norm_setToL1SCLM_le hT hC) le_rfl (norm_nonneg _) hC theorem norm_setToL1_le_mul_norm' (hT : DominatedFinMeasAdditive ÎŒ T C) (f : α →₁[ÎŒ] E) : ‖setToL1 hT f‖ ≀ max C 0 * ‖f‖ := calc ‖setToL1 hT f‖ ≀ ‖setToL1SCLM α E ÎŒ hT‖ * ‖f‖ := ContinuousLinearMap.le_of_opNorm_le _ (norm_setToL1_le_norm_setToL1SCLM hT) _ _ ≀ max C 0 * ‖f‖ := mul_le_mul (norm_setToL1SCLM_le' hT) le_rfl (norm_nonneg _) (le_max_right _ _) theorem norm_setToL1_le (hT : DominatedFinMeasAdditive ÎŒ T C) (hC : 0 ≀ C) : ‖setToL1 hT‖ ≀ C := ContinuousLinearMap.opNorm_le_bound _ hC (norm_setToL1_le_mul_norm hT hC) theorem norm_setToL1_le' (hT : DominatedFinMeasAdditive ÎŒ T C) : ‖setToL1 hT‖ ≀ max C 0 := ContinuousLinearMap.opNorm_le_bound _ (le_max_right _ _) (norm_setToL1_le_mul_norm' hT) theorem setToL1_lipschitz (hT : DominatedFinMeasAdditive ÎŒ T C) : LipschitzWith (Real.toNNReal C) (setToL1 hT) := (setToL1 hT).lipschitz.weaken (norm_setToL1_le' hT) /-- If `fs i → f` in `L1`, then `setToL1 hT (fs i) → setToL1 hT f`. -/ theorem tendsto_setToL1 (hT : DominatedFinMeasAdditive ÎŒ T C) (f : α →₁[ÎŒ] E) {ι} (fs : ι → α →₁[ÎŒ] E) {l : Filter ι} (hfs : Tendsto fs l (𝓝 f)) : Tendsto (fun i => setToL1 hT (fs i)) l (𝓝 <| setToL1 hT f) := ((setToL1 hT).continuous.tendsto _).comp hfs end SetToL1 end L1 section Function variable [CompleteSpace F] {T T' T'' : Set α → E →L[ℝ] F} {C C' C'' : ℝ} {f g : α → E} variable (ÎŒ T) open Classical in /-- Extend `T : Set α → E →L[ℝ] F` to `(α → E) → F` (for integrable functions `α → E`). We set it to 0 if the function is not integrable. -/ def setToFun (hT : DominatedFinMeasAdditive ÎŒ T C) (f : α → E) : F := if hf : Integrable f ÎŒ then L1.setToL1 hT (hf.toL1 f) else 0 variable {ÎŒ T} theorem setToFun_eq (hT : DominatedFinMeasAdditive ÎŒ T C) (hf : Integrable f ÎŒ) : setToFun ÎŒ T hT f = L1.setToL1 hT (hf.toL1 f) := dif_pos hf theorem L1.setToFun_eq_setToL1 (hT : DominatedFinMeasAdditive ÎŒ T C) (f : α →₁[ÎŒ] E) : setToFun ÎŒ T hT f = L1.setToL1 hT f := by rw [setToFun_eq hT (L1.integrable_coeFn f), Integrable.toL1_coeFn] theorem setToFun_undef (hT : DominatedFinMeasAdditive ÎŒ T C) (hf : ¬Integrable f ÎŒ) : setToFun ÎŒ T hT f = 0 := dif_neg hf theorem setToFun_non_aestronglyMeasurable (hT : DominatedFinMeasAdditive ÎŒ T C) (hf : ¬AEStronglyMeasurable f ÎŒ) : setToFun ÎŒ T hT f = 0 := setToFun_undef hT (not_and_of_not_left _ hf) @[deprecated (since := "2025-04-09")] alias setToFun_non_aEStronglyMeasurable := setToFun_non_aestronglyMeasurable theorem setToFun_congr_left (hT : DominatedFinMeasAdditive ÎŒ T C) (hT' : DominatedFinMeasAdditive ÎŒ T' C') (h : T = T') (f : α → E) : setToFun ÎŒ T hT f = setToFun ÎŒ T' hT' f := by by_cases hf : Integrable f ÎŒ · simp_rw [setToFun_eq _ hf, L1.setToL1_congr_left T T' hT hT' h] · simp_rw [setToFun_undef _ hf] theorem setToFun_congr_left' (hT : DominatedFinMeasAdditive ÎŒ T C) (hT' : DominatedFinMeasAdditive ÎŒ T' C') (h : ∀ s, MeasurableSet s → ÎŒ s < ∞ → T s = T' s) (f : α → E) : setToFun ÎŒ T hT f = setToFun ÎŒ T' hT' f := by by_cases hf : Integrable f ÎŒ · simp_rw [setToFun_eq _ hf, L1.setToL1_congr_left' T T' hT hT' h] · simp_rw [setToFun_undef _ hf] theorem setToFun_add_left (hT : DominatedFinMeasAdditive ÎŒ T C) (hT' : DominatedFinMeasAdditive ÎŒ T' C') (f : α → E) : setToFun ÎŒ (T + T') (hT.add hT') f = setToFun ÎŒ T hT f + setToFun ÎŒ T' hT' f := by by_cases hf : Integrable f ÎŒ · simp_rw [setToFun_eq _ hf, L1.setToL1_add_left hT hT'] · simp_rw [setToFun_undef _ hf, add_zero] theorem setToFun_add_left' (hT : DominatedFinMeasAdditive ÎŒ T C) (hT' : DominatedFinMeasAdditive ÎŒ T' C') (hT'' : DominatedFinMeasAdditive ÎŒ T'' C'') (h_add : ∀ s, MeasurableSet s → ÎŒ s < ∞ → T'' s = T s + T' s) (f : α → E) : setToFun ÎŒ T'' hT'' f = setToFun ÎŒ T hT f + setToFun ÎŒ T' hT' f := by by_cases hf : Integrable f ÎŒ · simp_rw [setToFun_eq _ hf, L1.setToL1_add_left' hT hT' hT'' h_add] · simp_rw [setToFun_undef _ hf, add_zero] theorem setToFun_smul_left (hT : DominatedFinMeasAdditive ÎŒ T C) (c : ℝ) (f : α → E) : setToFun ÎŒ (fun s => c • T s) (hT.smul c) f = c • setToFun ÎŒ T hT f := by by_cases hf : Integrable f ÎŒ · simp_rw [setToFun_eq _ hf, L1.setToL1_smul_left hT c] · simp_rw [setToFun_undef _ hf, smul_zero] theorem setToFun_smul_left' (hT : DominatedFinMeasAdditive ÎŒ T C) (hT' : DominatedFinMeasAdditive ÎŒ T' C') (c : ℝ) (h_smul : ∀ s, MeasurableSet s → ÎŒ s < ∞ → T' s = c • T s) (f : α → E) : setToFun ÎŒ T' hT' f = c • setToFun ÎŒ T hT f := by by_cases hf : Integrable f ÎŒ · simp_rw [setToFun_eq _ hf, L1.setToL1_smul_left' hT hT' c h_smul] · simp_rw [setToFun_undef _ hf, smul_zero] @[simp] theorem setToFun_zero (hT : DominatedFinMeasAdditive ÎŒ T C) : setToFun ÎŒ T hT (0 : α → E) = 0 := by rw [Pi.zero_def, setToFun_eq hT (integrable_zero _ _ _)] simp only [← Pi.zero_def] rw [Integrable.toL1_zero, ContinuousLinearMap.map_zero] @[simp] theorem setToFun_zero_left {hT : DominatedFinMeasAdditive ÎŒ (0 : Set α → E →L[ℝ] F) C} : setToFun ÎŒ 0 hT f = 0 := by by_cases hf : Integrable f ÎŒ · rw [setToFun_eq hT hf]; exact L1.setToL1_zero_left hT _ · exact setToFun_undef hT hf theorem setToFun_zero_left' (hT : DominatedFinMeasAdditive ÎŒ T C) (h_zero : ∀ s, MeasurableSet s → ÎŒ s < ∞ → T s = 0) : setToFun ÎŒ T hT f = 0 := by by_cases hf : Integrable f ÎŒ · rw [setToFun_eq hT hf]; exact L1.setToL1_zero_left' hT h_zero _ · exact setToFun_undef hT hf theorem setToFun_add (hT : DominatedFinMeasAdditive ÎŒ T C) (hf : Integrable f ÎŒ) (hg : Integrable g ÎŒ) : setToFun ÎŒ T hT (f + g) = setToFun ÎŒ T hT f + setToFun ÎŒ T hT g := by rw [setToFun_eq hT (hf.add hg), setToFun_eq hT hf, setToFun_eq hT hg, Integrable.toL1_add, (L1.setToL1 hT).map_add] theorem setToFun_finset_sum' (hT : DominatedFinMeasAdditive ÎŒ T C) {ι} (s : Finset ι) {f : ι → α → E} (hf : ∀ i ∈ s, Integrable (f i) ÎŒ) : setToFun ÎŒ T hT (∑ i ∈ s, f i) = ∑ i ∈ s, setToFun ÎŒ T hT (f i) := by classical revert hf refine Finset.induction_on s ?_ ?_ · intro _ simp only [setToFun_zero, Finset.sum_empty] · intro i s his ih hf simp only [his, Finset.sum_insert, not_false_iff] rw [setToFun_add hT (hf i (Finset.mem_insert_self i s)) _] · rw [ih fun i hi => hf i (Finset.mem_insert_of_mem hi)] · convert integrable_finset_sum s fun i hi => hf i (Finset.mem_insert_of_mem hi) with x simp theorem setToFun_finset_sum (hT : DominatedFinMeasAdditive ÎŒ T C) {ι} (s : Finset ι) {f : ι → α → E} (hf : ∀ i ∈ s, Integrable (f i) ÎŒ) : (setToFun ÎŒ T hT fun a => ∑ i ∈ s, f i a) = ∑ i ∈ s, setToFun ÎŒ T hT (f i) := by convert setToFun_finset_sum' hT s hf with a; simp theorem setToFun_neg (hT : DominatedFinMeasAdditive ÎŒ T C) (f : α → E) : setToFun ÎŒ T hT (-f) = -setToFun ÎŒ T hT f := by by_cases hf : Integrable f ÎŒ · rw [setToFun_eq hT hf, setToFun_eq hT hf.neg, Integrable.toL1_neg, (L1.setToL1 hT).map_neg] · rw [setToFun_undef hT hf, setToFun_undef hT, neg_zero] rwa [← integrable_neg_iff] at hf theorem setToFun_sub (hT : DominatedFinMeasAdditive ÎŒ T C) (hf : Integrable f ÎŒ) (hg : Integrable g ÎŒ) : setToFun ÎŒ T hT (f - g) = setToFun ÎŒ T hT f - setToFun ÎŒ T hT g := by rw [sub_eq_add_neg, sub_eq_add_neg, setToFun_add hT hf hg.neg, setToFun_neg hT g] theorem setToFun_smul [NontriviallyNormedField 𝕜] [NormedSpace 𝕜 E] [NormedSpace 𝕜 F] (hT : DominatedFinMeasAdditive ÎŒ T C) (h_smul : ∀ c : 𝕜, ∀ s x, T s (c • x) = c • T s x) (c : 𝕜) (f : α → E) : setToFun ÎŒ T hT (c • f) = c • setToFun ÎŒ T hT f := by by_cases hf : Integrable f ÎŒ · rw [setToFun_eq hT hf, setToFun_eq hT, Integrable.toL1_smul', L1.setToL1_smul hT h_smul c _] · by_cases hr : c = 0 · rw [hr]; simp · have hf' : ¬Integrable (c • f) ÎŒ := by rwa [integrable_smul_iff hr f] rw [setToFun_undef hT hf, setToFun_undef hT hf', smul_zero] theorem setToFun_congr_ae (hT : DominatedFinMeasAdditive ÎŒ T C) (h : f =ᵐ[ÎŒ] g) : setToFun ÎŒ T hT f = setToFun ÎŒ T hT g := by by_cases hfi : Integrable f ÎŒ · have hgi : Integrable g ÎŒ := hfi.congr h rw [setToFun_eq hT hfi, setToFun_eq hT hgi, (Integrable.toL1_eq_toL1_iff f g hfi hgi).2 h] · have hgi : ¬Integrable g ÎŒ := by rw [integrable_congr h] at hfi; exact hfi rw [setToFun_undef hT hfi, setToFun_undef hT hgi] theorem setToFun_measure_zero (hT : DominatedFinMeasAdditive ÎŒ T C) (h : ÎŒ = 0) : setToFun ÎŒ T hT f = 0 := by have : f =ᵐ[ÎŒ] 0 := by simp [h, EventuallyEq] rw [setToFun_congr_ae hT this, setToFun_zero] theorem setToFun_measure_zero' (hT : DominatedFinMeasAdditive ÎŒ T C) (h : ∀ s, MeasurableSet s → ÎŒ s < ∞ → ÎŒ s = 0) : setToFun ÎŒ T hT f = 0 := setToFun_zero_left' hT fun s hs hÎŒs => hT.eq_zero_of_measure_zero hs (h s hs hÎŒs) theorem setToFun_toL1 (hT : DominatedFinMeasAdditive ÎŒ T C) (hf : Integrable f ÎŒ) : setToFun ÎŒ T hT (hf.toL1 f) = setToFun ÎŒ T hT f := setToFun_congr_ae hT hf.coeFn_toL1 theorem setToFun_indicator_const (hT : DominatedFinMeasAdditive ÎŒ T C) {s : Set α} (hs : MeasurableSet s) (hÎŒs : ÎŒ s ≠ ∞) (x : E) : setToFun ÎŒ T hT (s.indicator fun _ => x) = T s x := by rw [setToFun_congr_ae hT (@indicatorConstLp_coeFn _ _ _ 1 _ _ _ hs hÎŒs x).symm] rw [L1.setToFun_eq_setToL1 hT] exact L1.setToL1_indicatorConstLp hT hs hÎŒs x theorem setToFun_const [IsFiniteMeasure ÎŒ] (hT : DominatedFinMeasAdditive ÎŒ T C) (x : E) : (setToFun ÎŒ T hT fun _ => x) = T univ x := by have : (fun _ : α => x) = Set.indicator univ fun _ => x := (indicator_univ _).symm rw [this] exact setToFun_indicator_const hT MeasurableSet.univ (measure_ne_top _ _) x section Order variable {G' G'' : Type*} [NormedAddCommGroup G''] [PartialOrder G''] [OrderClosedTopology G''] [IsOrderedAddMonoid G''] [NormedSpace ℝ G''] [CompleteSpace G''] [NormedAddCommGroup G'] [PartialOrder G'] [NormedSpace ℝ G'] theorem setToFun_mono_left' {T T' : Set α → E →L[ℝ] G''} {C C' : ℝ} (hT : DominatedFinMeasAdditive ÎŒ T C) (hT' : DominatedFinMeasAdditive ÎŒ T' C') (hTT' : ∀ s, MeasurableSet s → ÎŒ s < ∞ → ∀ x, T s x ≀ T' s x) (f : α → E) : setToFun ÎŒ T hT f ≀ setToFun ÎŒ T' hT' f := by by_cases hf : Integrable f ÎŒ · simp_rw [setToFun_eq _ hf]; exact L1.setToL1_mono_left' hT hT' hTT' _ · simp_rw [setToFun_undef _ hf, le_rfl] theorem setToFun_mono_left {T T' : Set α → E →L[ℝ] G''} {C C' : ℝ} (hT : DominatedFinMeasAdditive ÎŒ T C) (hT' : DominatedFinMeasAdditive ÎŒ T' C') (hTT' : ∀ s x, T s x ≀ T' s x) (f : α →₁[ÎŒ] E) : setToFun ÎŒ T hT f ≀ setToFun ÎŒ T' hT' f := setToFun_mono_left' hT hT' (fun s _ _ x => hTT' s x) f theorem setToFun_nonneg {T : Set α → G' →L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive ÎŒ T C) (hT_nonneg : ∀ s, MeasurableSet s → ÎŒ s < ∞ → ∀ x, 0 ≀ x → 0 ≀ T s x) {f : α → G'} (hf : 0 ≀ᵐ[ÎŒ] f) : 0 ≀ setToFun ÎŒ T hT f := by by_cases hfi : Integrable f ÎŒ · simp_rw [setToFun_eq _ hfi] refine L1.setToL1_nonneg hT hT_nonneg ?_ rw [← Lp.coeFn_le] have h0 := Lp.coeFn_zero G' 1 ÎŒ have h := Integrable.coeFn_toL1 hfi filter_upwards [h0, h, hf] with _ h0a ha hfa rw [h0a, ha] exact hfa · simp_rw [setToFun_undef _ hfi, le_rfl] theorem setToFun_mono [IsOrderedAddMonoid G'] {T : Set α → G' →L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive ÎŒ T C) (hT_nonneg : ∀ s, MeasurableSet s → ÎŒ s < ∞ → ∀ x, 0 ≀ x → 0 ≀ T s x) {f g : α → G'} (hf : Integrable f ÎŒ) (hg : Integrable g ÎŒ) (hfg : f ≀ᵐ[ÎŒ] g) : setToFun ÎŒ T hT f ≀ setToFun ÎŒ T hT g := by rw [← sub_nonneg, ← setToFun_sub hT hg hf] refine setToFun_nonneg hT hT_nonneg (hfg.mono fun a ha => ?_) rw [Pi.sub_apply, Pi.zero_apply, sub_nonneg] exact ha end Order @[continuity] theorem continuous_setToFun (hT : DominatedFinMeasAdditive ÎŒ T C) : Continuous fun f : α →₁[ÎŒ] E => setToFun ÎŒ T hT f := by simp_rw [L1.setToFun_eq_setToL1 hT]; exact ContinuousLinearMap.continuous _ /-- If `F i → f` in `L1`, then `setToFun ÎŒ T hT (F i) → setToFun ÎŒ T hT f`. -/ theorem tendsto_setToFun_of_L1 (hT : DominatedFinMeasAdditive ÎŒ T C) {ι} (f : α → E) (hfi : Integrable f ÎŒ) {fs : ι → α → E} {l : Filter ι} (hfsi : ∀ᶠ i in l, Integrable (fs i) ÎŒ) (hfs : Tendsto (fun i => ∫⁻ x, ‖fs i x - f x‖ₑ ∂Ό) l (𝓝 0)) : Tendsto (fun i => setToFun ÎŒ T hT (fs i)) l (𝓝 <| setToFun ÎŒ T hT f) := by classical let f_lp := hfi.toL1 f let F_lp i := if hFi : Integrable (fs i) ÎŒ then hFi.toL1 (fs i) else 0 have tendsto_L1 : Tendsto F_lp l (𝓝 f_lp) := by rw [Lp.tendsto_Lp_iff_tendsto_eLpNorm'] simp_rw [eLpNorm_one_eq_lintegral_enorm, Pi.sub_apply] refine (tendsto_congr' ?_).mp hfs filter_upwards [hfsi] with i hi refine lintegral_congr_ae ?_ filter_upwards [hi.coeFn_toL1, hfi.coeFn_toL1] with x hxi hxf simp_rw [F_lp, dif_pos hi, hxi, f_lp, hxf] suffices Tendsto (fun i => setToFun ÎŒ T hT (F_lp i)) l (𝓝 (setToFun ÎŒ T hT f)) by refine (tendsto_congr' ?_).mp this filter_upwards [hfsi] with i hi suffices h_ae_eq : F_lp i =ᵐ[ÎŒ] fs i from setToFun_congr_ae hT h_ae_eq simp_rw [F_lp, dif_pos hi] exact hi.coeFn_toL1 rw [setToFun_congr_ae hT hfi.coeFn_toL1.symm] exact ((continuous_setToFun hT).tendsto f_lp).comp tendsto_L1 theorem tendsto_setToFun_approxOn_of_measurable (hT : DominatedFinMeasAdditive ÎŒ T C) [MeasurableSpace E] [BorelSpace E] {f : α → E} {s : Set E} [SeparableSpace s] (hfi : Integrable f ÎŒ) (hfm : Measurable f) (hs : ∀ᵐ x ∂Ό, f x ∈ closure s) {y₀ : E} (h₀ : y₀ ∈ s) (h₀i : Integrable (fun _ => y₀) ÎŒ) : Tendsto (fun n => setToFun ÎŒ T hT (SimpleFunc.approxOn f hfm s y₀ h₀ n)) atTop (𝓝 <| setToFun ÎŒ T hT f) := tendsto_setToFun_of_L1 hT _ hfi (Eventually.of_forall (SimpleFunc.integrable_approxOn hfm hfi h₀ h₀i)) (SimpleFunc.tendsto_approxOn_L1_enorm hfm _ hs (hfi.sub h₀i).2) theorem tendsto_setToFun_approxOn_of_measurable_of_range_subset (hT : DominatedFinMeasAdditive ÎŒ T C) [MeasurableSpace E] [BorelSpace E] {f : α → E} (fmeas : Measurable f) (hf : Integrable f ÎŒ) (s : Set E) [SeparableSpace s] (hs : range f ∪ {0} ⊆ s) : Tendsto (fun n => setToFun ÎŒ T hT (SimpleFunc.approxOn f fmeas s 0 (hs <| by simp) n)) atTop (𝓝 <| setToFun ÎŒ T hT f) := by refine tendsto_setToFun_approxOn_of_measurable hT hf fmeas ?_ _ (integrable_zero _ _ _) exact Eventually.of_forall fun x => subset_closure (hs (Set.mem_union_left _ (mem_range_self _))) /-- Auxiliary lemma for `setToFun_congr_measure`: the function sending `f : α →₁[ÎŒ] G` to `f : α →₁[ÎŒ'] G` is continuous when `ÎŒ' ≀ c' • ÎŒ` for `c' ≠ ∞`. -/ theorem continuous_L1_toL1 {ÎŒ' : Measure α} (c' : ℝ≥0∞) (hc' : c' ≠ ∞) (hÎŒ'_le : ÎŒ' ≀ c' • ÎŒ) : Continuous fun f : α →₁[ÎŒ] G => (Integrable.of_measure_le_smul hc' hÎŒ'_le (L1.integrable_coeFn f)).toL1 f := by by_cases hc'0 : c' = 0 · have hÎŒ'0 : ÎŒ' = 0 := by rw [← Measure.nonpos_iff_eq_zero']; refine hÎŒ'_le.trans ?_; simp [hc'0] have h_im_zero : (fun f : α →₁[ÎŒ] G => (Integrable.of_measure_le_smul hc' hÎŒ'_le (L1.integrable_coeFn f)).toL1 f) = 0 := by ext1 f; ext1; simp_rw [hÎŒ'0]; simp only [ae_zero, EventuallyEq, eventually_bot] rw [h_im_zero] exact continuous_zero rw [Metric.continuous_iff] intro f ε hε_pos use ε / 2 / c'.toReal refine ⟹div_pos (half_pos hε_pos) (toReal_pos hc'0 hc'), ?_⟩ intro g hfg rw [Lp.dist_def] at hfg ⊢ let h_int := fun f' : α →₁[ÎŒ] G => (L1.integrable_coeFn f').of_measure_le_smul hc' hÎŒ'_le have : eLpNorm (⇑(Integrable.toL1 g (h_int g)) - ⇑(Integrable.toL1 f (h_int f))) 1 ÎŒ' = eLpNorm (⇑g - ⇑f) 1 ÎŒ' := eLpNorm_congr_ae ((Integrable.coeFn_toL1 _).sub (Integrable.coeFn_toL1 _)) rw [this] have h_eLpNorm_ne_top : eLpNorm (⇑g - ⇑f) 1 ÎŒ ≠ ∞ := by rw [← eLpNorm_congr_ae (Lp.coeFn_sub _ _)]; exact Lp.eLpNorm_ne_top _ calc (eLpNorm (⇑g - ⇑f) 1 ÎŒ').toReal ≀ (c' * eLpNorm (⇑g - ⇑f) 1 ÎŒ).toReal := by refine toReal_mono (ENNReal.mul_ne_top hc' h_eLpNorm_ne_top) ?_ refine (eLpNorm_mono_measure (⇑g - ⇑f) hÎŒ'_le).trans_eq ?_ rw [eLpNorm_smul_measure_of_ne_zero hc'0, smul_eq_mul] simp _ = c'.toReal * (eLpNorm (⇑g - ⇑f) 1 ÎŒ).toReal := toReal_mul _ ≀ c'.toReal * (ε / 2 / c'.toReal) := by gcongr _ = ε / 2 := by refine mul_div_cancel₀ (ε / 2) ?_; rw [Ne, toReal_eq_zero_iff]; simp [hc', hc'0] _ < ε := half_lt_self hε_pos theorem setToFun_congr_measure_of_integrable {ÎŒ' : Measure α} (c' : ℝ≥0∞) (hc' : c' ≠ ∞) (hÎŒ'_le : ÎŒ' ≀ c' • ÎŒ) (hT : DominatedFinMeasAdditive ÎŒ T C) (hT' : DominatedFinMeasAdditive ÎŒ' T C') (f : α → E) (hfÎŒ : Integrable f ÎŒ) : setToFun ÎŒ T hT f = setToFun ÎŒ' T hT' f := by -- integrability for `ÎŒ` implies integrability for `ÎŒ'`. have h_int : ∀ g : α → E, Integrable g ÎŒ → Integrable g ÎŒ' := fun g hg => Integrable.of_measure_le_smul hc' hÎŒ'_le hg -- We use `Integrable.induction` apply hfÎŒ.induction (P := fun f => setToFun ÎŒ T hT f = setToFun ÎŒ' T hT' f) · intro c s hs hÎŒs have hÎŒ's : ÎŒ' s ≠ ∞ := by refine ((hÎŒ'_le s).trans_lt ?_).ne rw [Measure.smul_apply, smul_eq_mul] exact ENNReal.mul_lt_top hc'.lt_top hÎŒs rw [setToFun_indicator_const hT hs hÎŒs.ne, setToFun_indicator_const hT' hs hÎŒ's] · intro f₂ g₂ _ hf₂ hg₂ h_eq_f h_eq_g rw [setToFun_add hT hf₂ hg₂, setToFun_add hT' (h_int f₂ hf₂) (h_int g₂ hg₂), h_eq_f, h_eq_g] · refine isClosed_eq (continuous_setToFun hT) ?_ have : (fun f : α →₁[ÎŒ] E => setToFun ÎŒ' T hT' f) = fun f : α →₁[ÎŒ] E => setToFun ÎŒ' T hT' ((h_int f (L1.integrable_coeFn f)).toL1 f) := by ext1 f; exact setToFun_congr_ae hT' (Integrable.coeFn_toL1 _).symm rw [this] exact (continuous_setToFun hT').comp (continuous_L1_toL1 c' hc' hÎŒ'_le) · intro f₂ g₂ hfg _ hf_eq have hfg' : f₂ =ᵐ[ÎŒ'] g₂ := (Measure.absolutelyContinuous_of_le_smul hÎŒ'_le).ae_eq hfg rw [← setToFun_congr_ae hT hfg, hf_eq, setToFun_congr_ae hT' hfg'] theorem setToFun_congr_measure {ÎŒ' : Measure α} (c c' : ℝ≥0∞) (hc : c ≠ ∞) (hc' : c' ≠ ∞) (hÎŒ_le : ÎŒ ≀ c • ÎŒ') (hÎŒ'_le : ÎŒ' ≀ c' • ÎŒ) (hT : DominatedFinMeasAdditive ÎŒ T C) (hT' : DominatedFinMeasAdditive ÎŒ' T C') (f : α → E) : setToFun ÎŒ T hT f = setToFun ÎŒ' T hT' f := by by_cases hf : Integrable f ÎŒ · exact setToFun_congr_measure_of_integrable c' hc' hÎŒ'_le hT hT' f hf · -- if `f` is not integrable, both `setToFun` are 0. have h_int : ∀ g : α → E, ¬Integrable g ÎŒ → ¬Integrable g ÎŒ' := fun g => mt fun h => h.of_measure_le_smul hc hÎŒ_le simp_rw [setToFun_undef _ hf, setToFun_undef _ (h_int f hf)] theorem setToFun_congr_measure_of_add_right {ÎŒ' : Measure α} (hT_add : DominatedFinMeasAdditive (ÎŒ + ÎŒ') T C') (hT : DominatedFinMeasAdditive ÎŒ T C) (f : α → E) (hf : Integrable f (ÎŒ + ÎŒ')) : setToFun (ÎŒ + ÎŒ') T hT_add f = setToFun ÎŒ T hT f := by refine setToFun_congr_measure_of_integrable 1 one_ne_top ?_ hT_add hT f hf rw [one_smul] nth_rw 1 [← add_zero ÎŒ] exact add_le_add le_rfl bot_le theorem setToFun_congr_measure_of_add_left {ÎŒ' : Measure α} (hT_add : DominatedFinMeasAdditive (ÎŒ + ÎŒ') T C') (hT : DominatedFinMeasAdditive ÎŒ' T C) (f : α → E) (hf : Integrable f (ÎŒ + ÎŒ')) : setToFun (ÎŒ + ÎŒ') T hT_add f = setToFun ÎŒ' T hT f := by refine setToFun_congr_measure_of_integrable 1 one_ne_top ?_ hT_add hT f hf rw [one_smul] nth_rw 1 [← zero_add ÎŒ'] exact add_le_add_right bot_le ÎŒ' theorem setToFun_top_smul_measure (hT : DominatedFinMeasAdditive (∞ • ÎŒ) T C) (f : α → E) : setToFun (∞ • ÎŒ) T hT f = 0 := by refine setToFun_measure_zero' hT fun s _ hÎŒs => ?_ rw [lt_top_iff_ne_top] at hÎŒs simp only [true_and, Measure.smul_apply, ENNReal.mul_eq_top, eq_self_iff_true, top_ne_zero, Ne, not_false_iff, not_or, Classical.not_not, smul_eq_mul] at hÎŒs simp only [hÎŒs.right, Measure.smul_apply, mul_zero, smul_eq_mul] theorem setToFun_congr_smul_measure (c : ℝ≥0∞) (hc_ne_top : c ≠ ∞) (hT : DominatedFinMeasAdditive ÎŒ T C) (hT_smul : DominatedFinMeasAdditive (c • ÎŒ) T C') (f : α → E) : setToFun ÎŒ T hT f = setToFun (c • ÎŒ) T hT_smul f := by by_cases hc0 : c = 0 · simp [hc0] at hT_smul have h : ∀ s, MeasurableSet s → ÎŒ s < ∞ → T s = 0 := fun s hs _ => hT_smul.eq_zero hs rw [setToFun_zero_left' _ h, setToFun_measure_zero] simp [hc0] refine setToFun_congr_measure c⁻¹ c ?_ hc_ne_top (le_of_eq ?_) le_rfl hT hT_smul f · simp [hc0] · rw [smul_smul, ENNReal.inv_mul_cancel hc0 hc_ne_top, one_smul] theorem norm_setToFun_le_mul_norm (hT : DominatedFinMeasAdditive ÎŒ T C) (f : α →₁[ÎŒ] E) (hC : 0 ≀ C) : ‖setToFun ÎŒ T hT f‖ ≀ C * ‖f‖ := by rw [L1.setToFun_eq_setToL1]; exact L1.norm_setToL1_le_mul_norm hT hC f theorem norm_setToFun_le_mul_norm' (hT : DominatedFinMeasAdditive ÎŒ T C) (f : α →₁[ÎŒ] E) : ‖setToFun ÎŒ T hT f‖ ≀ max C 0 * ‖f‖ := by rw [L1.setToFun_eq_setToL1]; exact L1.norm_setToL1_le_mul_norm' hT f theorem norm_setToFun_le (hT : DominatedFinMeasAdditive ÎŒ T C) (hf : Integrable f ÎŒ) (hC : 0 ≀ C) : ‖setToFun ÎŒ T hT f‖ ≀ C * ‖hf.toL1 f‖ := by rw [setToFun_eq hT hf]; exact L1.norm_setToL1_le_mul_norm hT hC _ theorem norm_setToFun_le' (hT : DominatedFinMeasAdditive ÎŒ T C) (hf : Integrable f ÎŒ) : ‖setToFun ÎŒ T hT f‖ ≀ max C 0 * ‖hf.toL1 f‖ := by rw [setToFun_eq hT hf]; exact L1.norm_setToL1_le_mul_norm' hT _ /-- Lebesgue dominated convergence theorem provides sufficient conditions under which almost everywhere convergence of a sequence of functions implies the convergence of their image by `setToFun`. We could weaken the condition `bound_integrable` to require `HasFiniteIntegral bound ÎŒ` instead (i.e. not requiring that `bound` is measurable), but in all applications proving integrability is easier. -/ theorem tendsto_setToFun_of_dominated_convergence (hT : DominatedFinMeasAdditive ÎŒ T C) {fs : ℕ → α → E} {f : α → E} (bound : α → ℝ) (fs_measurable : ∀ n, AEStronglyMeasurable (fs n) ÎŒ) (bound_integrable : Integrable bound ÎŒ) (h_bound : ∀ n, ∀ᵐ a ∂Ό, ‖fs n a‖ ≀ bound a) (h_lim : ∀ᵐ a ∂Ό, Tendsto (fun n => fs n a) atTop (𝓝 (f a))) : Tendsto (fun n => setToFun ÎŒ T hT (fs n)) atTop (𝓝 <| setToFun ÎŒ T hT f) := by -- `f` is a.e.-measurable, since it is the a.e.-pointwise limit of a.e.-measurable functions. have f_measurable : AEStronglyMeasurable f ÎŒ := aestronglyMeasurable_of_tendsto_ae _ fs_measurable h_lim -- all functions we consider are integrable have fs_int : ∀ n, Integrable (fs n) ÎŒ := fun n => bound_integrable.mono' (fs_measurable n) (h_bound _) have f_int : Integrable f ÎŒ := ⟹f_measurable, hasFiniteIntegral_of_dominated_convergence bound_integrable.hasFiniteIntegral h_bound h_lim⟩ -- it suffices to prove the result for the corresponding L1 functions suffices Tendsto (fun n => L1.setToL1 hT ((fs_int n).toL1 (fs n))) atTop (𝓝 (L1.setToL1 hT (f_int.toL1 f))) by convert this with n · exact setToFun_eq hT (fs_int n) · exact setToFun_eq hT f_int -- the convergence of setToL1 follows from the convergence of the L1 functions refine L1.tendsto_setToL1 hT _ _ ?_ -- up to some rewriting, what we need to prove is `h_lim` rw [tendsto_iff_norm_sub_tendsto_zero] have lintegral_norm_tendsto_zero : Tendsto (fun n => ENNReal.toReal <| ∫⁻ a, ENNReal.ofReal ‖fs n a - f a‖ ∂Ό) atTop (𝓝 0) := (tendsto_toReal zero_ne_top).comp (tendsto_lintegral_norm_of_dominated_convergence fs_measurable bound_integrable.hasFiniteIntegral h_bound h_lim) convert lintegral_norm_tendsto_zero with n rw [L1.norm_def] congr 1 refine lintegral_congr_ae ?_ rw [← Integrable.toL1_sub] refine ((fs_int n).sub f_int).coeFn_toL1.mono fun x hx => ?_ dsimp only rw [hx, ofReal_norm_eq_enorm, Pi.sub_apply] /-- Lebesgue dominated convergence theorem for filters with a countable basis -/ theorem tendsto_setToFun_filter_of_dominated_convergence (hT : DominatedFinMeasAdditive ÎŒ T C) {ι} {l : Filter ι} [l.IsCountablyGenerated] {fs : ι → α → E} {f : α → E} (bound : α → ℝ) (hfs_meas : ∀ᶠ n in l, AEStronglyMeasurable (fs n) ÎŒ) (h_bound : ∀ᶠ n in l, ∀ᵐ a ∂Ό, ‖fs n a‖ ≀ bound a) (bound_integrable : Integrable bound ÎŒ) (h_lim : ∀ᵐ a ∂Ό, Tendsto (fun n => fs n a) l (𝓝 (f a))) : Tendsto (fun n => setToFun ÎŒ T hT (fs n)) l (𝓝 <| setToFun ÎŒ T hT f) := by rw [tendsto_iff_seq_tendsto] intro x xl have hxl : ∀ s ∈ l, ∃ a, ∀ b ≥ a, x b ∈ s := by rwa [tendsto_atTop'] at xl have h : { x : ι | (fun n => AEStronglyMeasurable (fs n) ÎŒ) x } ∩ { x : ι | (fun n => ∀ᵐ a ∂Ό, ‖fs n a‖ ≀ bound a) x } ∈ l := inter_mem hfs_meas h_bound obtain ⟹k, h⟩ := hxl _ h rw [← tendsto_add_atTop_iff_nat k] refine tendsto_setToFun_of_dominated_convergence hT bound ?_ bound_integrable ?_ ?_ · exact fun n => (h _ (self_le_add_left _ _)).1 · exact fun n => (h _ (self_le_add_left _ _)).2 · filter_upwards [h_lim] refine fun a h_lin => @Tendsto.comp _ _ _ (fun n => x (n + k)) (fun n => fs n a) _ _ _ h_lin ?_ rwa [tendsto_add_atTop_iff_nat] variable {X : Type*} [TopologicalSpace X] [FirstCountableTopology X] theorem continuousWithinAt_setToFun_of_dominated (hT : DominatedFinMeasAdditive ÎŒ T C) {fs : X → α → E} {x₀ : X} {bound : α → ℝ} {s : Set X} (hfs_meas : ∀ᶠ x in 𝓝[s] x₀, AEStronglyMeasurable (fs x) ÎŒ) (h_bound : ∀ᶠ x in 𝓝[s] x₀, ∀ᵐ a ∂Ό, ‖fs x a‖ ≀ bound a) (bound_integrable : Integrable bound ÎŒ) (h_cont : ∀ᵐ a ∂Ό, ContinuousWithinAt (fun x => fs x a) s x₀) : ContinuousWithinAt (fun x => setToFun ÎŒ T hT (fs x)) s x₀ := tendsto_setToFun_filter_of_dominated_convergence hT bound ‹_› ‹_› ‹_› ‹_› theorem continuousAt_setToFun_of_dominated (hT : DominatedFinMeasAdditive ÎŒ T C) {fs : X → α → E} {x₀ : X} {bound : α → ℝ} (hfs_meas : ∀ᶠ x in 𝓝 x₀, AEStronglyMeasurable (fs x) ÎŒ) (h_bound : ∀ᶠ x in 𝓝 x₀, ∀ᵐ a ∂Ό, ‖fs x a‖ ≀ bound a) (bound_integrable : Integrable bound ÎŒ) (h_cont : ∀ᵐ a ∂Ό, ContinuousAt (fun x => fs x a) x₀) : ContinuousAt (fun x => setToFun ÎŒ T hT (fs x)) x₀ := tendsto_setToFun_filter_of_dominated_convergence hT bound ‹_› ‹_› ‹_› ‹_› theorem continuousOn_setToFun_of_dominated (hT : DominatedFinMeasAdditive ÎŒ T C) {fs : X → α → E} {bound : α → ℝ} {s : Set X} (hfs_meas : ∀ x ∈ s, AEStronglyMeasurable (fs x) ÎŒ) (h_bound : ∀ x ∈ s, ∀ᵐ a ∂Ό, ‖fs x a‖ ≀ bound a) (bound_integrable : Integrable bound ÎŒ) (h_cont : ∀ᵐ a ∂Ό, ContinuousOn (fun x => fs x a) s) : ContinuousOn (fun x => setToFun ÎŒ T hT (fs x)) s := by intro x hx refine continuousWithinAt_setToFun_of_dominated hT ?_ ?_ bound_integrable ?_ · filter_upwards [self_mem_nhdsWithin] with x hx using hfs_meas x hx · filter_upwards [self_mem_nhdsWithin] with x hx using h_bound x hx · filter_upwards [h_cont] with a ha using ha x hx theorem continuous_setToFun_of_dominated (hT : DominatedFinMeasAdditive ÎŒ T C) {fs : X → α → E} {bound : α → ℝ} (hfs_meas : ∀ x, AEStronglyMeasurable (fs x) ÎŒ) (h_bound : ∀ x, ∀ᵐ a ∂Ό, ‖fs x a‖ ≀ bound a) (bound_integrable : Integrable bound ÎŒ) (h_cont : ∀ᵐ a ∂Ό, Continuous fun x => fs x a) : Continuous fun x => setToFun ÎŒ T hT (fs x) := continuous_iff_continuousAt.mpr fun _ => continuousAt_setToFun_of_dominated hT (Eventually.of_forall hfs_meas) (Eventually.of_forall h_bound) ‹_› <| h_cont.mono fun _ => Continuous.continuousAt end Function end MeasureTheory
Mathlib/MeasureTheory/Integral/SetToL1.lean
1,396
1,405
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.FDeriv.Linear import Mathlib.Analysis.Calculus.FDeriv.Comp /-! # Additive operations on derivatives For detailed documentation of the Fréchet derivative, see the module docstring of `Analysis/Calculus/FDeriv/Basic.lean`. This file contains the usual formulas (and existence assertions) for the derivative of * sum of finitely many functions * multiplication of a function by a scalar constant * negative of a function * subtraction of two functions -/ open Filter Asymptotics ContinuousLinearMap noncomputable section section variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {f g : E → F} variable {f' g' : E →L[𝕜] F} variable {x : E} variable {s : Set E} variable {L : Filter E} section ConstSMul variable {R : Type*} [Semiring R] [Module R F] [SMulCommClass 𝕜 R F] [ContinuousConstSMul R F] /-! ### Derivative of a function multiplied by a constant -/ @[fun_prop] theorem HasStrictFDerivAt.const_smul (h : HasStrictFDerivAt f f' x) (c : R) : HasStrictFDerivAt (fun x => c • f x) (c • f') x := (c • (1 : F →L[𝕜] F)).hasStrictFDerivAt.comp x h theorem HasFDerivAtFilter.const_smul (h : HasFDerivAtFilter f f' x L) (c : R) : HasFDerivAtFilter (fun x => c • f x) (c • f') x L := (c • (1 : F →L[𝕜] F)).hasFDerivAtFilter.comp x h tendsto_map @[fun_prop] nonrec theorem HasFDerivWithinAt.const_smul (h : HasFDerivWithinAt f f' s x) (c : R) : HasFDerivWithinAt (fun x => c • f x) (c • f') s x := h.const_smul c @[fun_prop] nonrec theorem HasFDerivAt.const_smul (h : HasFDerivAt f f' x) (c : R) : HasFDerivAt (fun x => c • f x) (c • f') x := h.const_smul c @[fun_prop] theorem DifferentiableWithinAt.const_smul (h : DifferentiableWithinAt 𝕜 f s x) (c : R) : DifferentiableWithinAt 𝕜 (fun y => c • f y) s x := (h.hasFDerivWithinAt.const_smul c).differentiableWithinAt @[fun_prop] theorem DifferentiableAt.const_smul (h : DifferentiableAt 𝕜 f x) (c : R) : DifferentiableAt 𝕜 (fun y => c • f y) x := (h.hasFDerivAt.const_smul c).differentiableAt @[fun_prop] theorem DifferentiableOn.const_smul (h : DifferentiableOn 𝕜 f s) (c : R) : DifferentiableOn 𝕜 (fun y => c • f y) s := fun x hx => (h x hx).const_smul c @[fun_prop] theorem Differentiable.const_smul (h : Differentiable 𝕜 f) (c : R) : Differentiable 𝕜 fun y => c • f y := fun x => (h x).const_smul c theorem fderivWithin_const_smul (hxs : UniqueDiffWithinAt 𝕜 s x) (h : DifferentiableWithinAt 𝕜 f s x) (c : R) : fderivWithin 𝕜 (fun y => c • f y) s x = c • fderivWithin 𝕜 f s x := (h.hasFDerivWithinAt.const_smul c).fderivWithin hxs /-- Version of `fderivWithin_const_smul` written with `c • f` instead of `fun y ↩ c • f y`. -/ theorem fderivWithin_const_smul' (hxs : UniqueDiffWithinAt 𝕜 s x) (h : DifferentiableWithinAt 𝕜 f s x) (c : R) : fderivWithin 𝕜 (c • f) s x = c • fderivWithin 𝕜 f s x := fderivWithin_const_smul hxs h c theorem fderiv_const_smul (h : DifferentiableAt 𝕜 f x) (c : R) : fderiv 𝕜 (fun y => c • f y) x = c • fderiv 𝕜 f x := (h.hasFDerivAt.const_smul c).fderiv /-- Version of `fderiv_const_smul` written with `c • f` instead of `fun y ↩ c • f y`. -/ theorem fderiv_const_smul' (h : DifferentiableAt 𝕜 f x) (c : R) : fderiv 𝕜 (c • f) x = c • fderiv 𝕜 f x := (h.hasFDerivAt.const_smul c).fderiv end ConstSMul section Add /-! ### Derivative of the sum of two functions -/ @[fun_prop] nonrec theorem HasStrictFDerivAt.add (hf : HasStrictFDerivAt f f' x) (hg : HasStrictFDerivAt g g' x) : HasStrictFDerivAt (fun y => f y + g y) (f' + g') x := .of_isLittleO <| (hf.isLittleO.add hg.isLittleO).congr_left fun y => by simp only [LinearMap.sub_apply, LinearMap.add_apply, map_sub, map_add, add_apply] abel theorem HasFDerivAtFilter.add (hf : HasFDerivAtFilter f f' x L) (hg : HasFDerivAtFilter g g' x L) : HasFDerivAtFilter (fun y => f y + g y) (f' + g') x L := .of_isLittleO <| (hf.isLittleO.add hg.isLittleO).congr_left fun _ => by simp only [LinearMap.sub_apply, LinearMap.add_apply, map_sub, map_add, add_apply] abel @[fun_prop] nonrec theorem HasFDerivWithinAt.add (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt g g' s x) : HasFDerivWithinAt (fun y => f y + g y) (f' + g') s x := hf.add hg @[fun_prop] nonrec theorem HasFDerivAt.add (hf : HasFDerivAt f f' x) (hg : HasFDerivAt g g' x) : HasFDerivAt (fun x => f x + g x) (f' + g') x := hf.add hg @[fun_prop] theorem DifferentiableWithinAt.add (hf : DifferentiableWithinAt 𝕜 f s x) (hg : DifferentiableWithinAt 𝕜 g s x) : DifferentiableWithinAt 𝕜 (fun y => f y + g y) s x := (hf.hasFDerivWithinAt.add hg.hasFDerivWithinAt).differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.add (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) : DifferentiableAt 𝕜 (fun y => f y + g y) x := (hf.hasFDerivAt.add hg.hasFDerivAt).differentiableAt @[fun_prop] theorem DifferentiableOn.add (hf : DifferentiableOn 𝕜 f s) (hg : DifferentiableOn 𝕜 g s) : DifferentiableOn 𝕜 (fun y => f y + g y) s := fun x hx => (hf x hx).add (hg x hx) @[simp, fun_prop] theorem Differentiable.add (hf : Differentiable 𝕜 f) (hg : Differentiable 𝕜 g) : Differentiable 𝕜 fun y => f y + g y := fun x => (hf x).add (hg x) theorem fderivWithin_add (hxs : UniqueDiffWithinAt 𝕜 s x) (hf : DifferentiableWithinAt 𝕜 f s x) (hg : DifferentiableWithinAt 𝕜 g s x) : fderivWithin 𝕜 (fun y => f y + g y) s x = fderivWithin 𝕜 f s x + fderivWithin 𝕜 g s x := (hf.hasFDerivWithinAt.add hg.hasFDerivWithinAt).fderivWithin hxs /-- Version of `fderivWithin_add` where the function is written as `f + g` instead of `fun y ↩ f y + g y`. -/ theorem fderivWithin_add' (hxs : UniqueDiffWithinAt 𝕜 s x) (hf : DifferentiableWithinAt 𝕜 f s x) (hg : DifferentiableWithinAt 𝕜 g s x) : fderivWithin 𝕜 (f + g) s x = fderivWithin 𝕜 f s x + fderivWithin 𝕜 g s x := fderivWithin_add hxs hf hg theorem fderiv_add (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) : fderiv 𝕜 (fun y => f y + g y) x = fderiv 𝕜 f x + fderiv 𝕜 g x := (hf.hasFDerivAt.add hg.hasFDerivAt).fderiv /-- Version of `fderiv_add` where the function is written as `f + g` instead of `fun y ↩ f y + g y`. -/ theorem fderiv_add' (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) : fderiv 𝕜 (f + g) x = fderiv 𝕜 f x + fderiv 𝕜 g x := fderiv_add hf hg @[simp] theorem hasFDerivAtFilter_add_const_iff (c : F) : HasFDerivAtFilter (f · + c) f' x L ↔ HasFDerivAtFilter f f' x L := by simp [hasFDerivAtFilter_iff_isLittleOTVS] alias ⟹_, HasFDerivAtFilter.add_const⟩ := hasFDerivAtFilter_add_const_iff @[simp] theorem hasStrictFDerivAt_add_const_iff (c : F) : HasStrictFDerivAt (f · + c) f' x ↔ HasStrictFDerivAt f f' x := by simp [hasStrictFDerivAt_iff_isLittleO] @[fun_prop] alias ⟹_, HasStrictFDerivAt.add_const⟩ := hasStrictFDerivAt_add_const_iff @[simp] theorem hasFDerivWithinAt_add_const_iff (c : F) : HasFDerivWithinAt (f · + c) f' s x ↔ HasFDerivWithinAt f f' s x := hasFDerivAtFilter_add_const_iff c @[fun_prop] alias ⟹_, HasFDerivWithinAt.add_const⟩ := hasFDerivWithinAt_add_const_iff @[simp] theorem hasFDerivAt_add_const_iff (c : F) : HasFDerivAt (f · + c) f' x ↔ HasFDerivAt f f' x := hasFDerivAtFilter_add_const_iff c @[fun_prop] alias ⟹_, HasFDerivAt.add_const⟩ := hasFDerivAt_add_const_iff @[simp] theorem differentiableWithinAt_add_const_iff (c : F) : DifferentiableWithinAt 𝕜 (fun y => f y + c) s x ↔ DifferentiableWithinAt 𝕜 f s x := exists_congr fun _ ↩ hasFDerivWithinAt_add_const_iff c @[fun_prop] alias ⟹_, DifferentiableWithinAt.add_const⟩ := differentiableWithinAt_add_const_iff @[simp] theorem differentiableAt_add_const_iff (c : F) : DifferentiableAt 𝕜 (fun y => f y + c) x ↔ DifferentiableAt 𝕜 f x := exists_congr fun _ ↩ hasFDerivAt_add_const_iff c @[fun_prop] alias ⟹_, DifferentiableAt.add_const⟩ := differentiableAt_add_const_iff @[simp] theorem differentiableOn_add_const_iff (c : F) : DifferentiableOn 𝕜 (fun y => f y + c) s ↔ DifferentiableOn 𝕜 f s := forall₂_congr fun _ _ ↩ differentiableWithinAt_add_const_iff c @[fun_prop] alias ⟹_, DifferentiableOn.add_const⟩ := differentiableOn_add_const_iff @[simp] theorem differentiable_add_const_iff (c : F) : (Differentiable 𝕜 fun y => f y + c) ↔ Differentiable 𝕜 f := forall_congr' fun _ ↩ differentiableAt_add_const_iff c @[fun_prop] alias ⟹_, Differentiable.add_const⟩ := differentiable_add_const_iff @[simp] theorem fderivWithin_add_const (c : F) : fderivWithin 𝕜 (fun y => f y + c) s x = fderivWithin 𝕜 f s x := by classical simp [fderivWithin] @[simp] theorem fderiv_add_const (c : F) : fderiv 𝕜 (fun y => f y + c) x = fderiv 𝕜 f x := by simp only [← fderivWithin_univ, fderivWithin_add_const] @[simp] theorem hasFDerivAtFilter_const_add_iff (c : F) : HasFDerivAtFilter (c + f ·) f' x L ↔ HasFDerivAtFilter f f' x L := by simpa only [add_comm] using hasFDerivAtFilter_add_const_iff c alias ⟹_, HasFDerivAtFilter.const_add⟩ := hasFDerivAtFilter_const_add_iff @[simp] theorem hasStrictFDerivAt_const_add_iff (c : F) : HasStrictFDerivAt (c + f ·) f' x ↔ HasStrictFDerivAt f f' x := by simpa only [add_comm] using hasStrictFDerivAt_add_const_iff c @[fun_prop] alias ⟹_, HasStrictFDerivAt.const_add⟩ := hasStrictFDerivAt_const_add_iff @[simp] theorem hasFDerivWithinAt_const_add_iff (c : F) : HasFDerivWithinAt (c + f ·) f' s x ↔ HasFDerivWithinAt f f' s x := hasFDerivAtFilter_const_add_iff c @[fun_prop] alias ⟹_, HasFDerivWithinAt.const_add⟩ := hasFDerivWithinAt_const_add_iff @[simp] theorem hasFDerivAt_const_add_iff (c : F) : HasFDerivAt (c + f ·) f' x ↔ HasFDerivAt f f' x := hasFDerivAtFilter_const_add_iff c @[fun_prop] alias ⟹_, HasFDerivAt.const_add⟩ := hasFDerivAt_const_add_iff @[simp] theorem differentiableWithinAt_const_add_iff (c : F) : DifferentiableWithinAt 𝕜 (fun y => c + f y) s x ↔ DifferentiableWithinAt 𝕜 f s x := exists_congr fun _ ↩ hasFDerivWithinAt_const_add_iff c @[fun_prop] alias ⟹_, DifferentiableWithinAt.const_add⟩ := differentiableWithinAt_const_add_iff @[simp] theorem differentiableAt_const_add_iff (c : F) : DifferentiableAt 𝕜 (fun y => c + f y) x ↔ DifferentiableAt 𝕜 f x := exists_congr fun _ ↩ hasFDerivAt_const_add_iff c @[fun_prop] alias ⟹_, DifferentiableAt.const_add⟩ := differentiableAt_const_add_iff @[simp] theorem differentiableOn_const_add_iff (c : F) : DifferentiableOn 𝕜 (fun y => c + f y) s ↔ DifferentiableOn 𝕜 f s := forall₂_congr fun _ _ ↩ differentiableWithinAt_const_add_iff c @[fun_prop] alias ⟹_, DifferentiableOn.const_add⟩ := differentiableOn_const_add_iff @[simp] theorem differentiable_const_add_iff (c : F) : (Differentiable 𝕜 fun y => c + f y) ↔ Differentiable 𝕜 f := forall_congr' fun _ ↩ differentiableAt_const_add_iff c @[fun_prop] alias ⟹_, Differentiable.const_add⟩ := differentiable_const_add_iff @[simp] theorem fderivWithin_const_add (c : F) : fderivWithin 𝕜 (fun y => c + f y) s x = fderivWithin 𝕜 f s x := by simpa only [add_comm] using fderivWithin_add_const c @[simp]
theorem fderiv_const_add (c : F) : fderiv 𝕜 (fun y => c + f y) x = fderiv 𝕜 f x := by simp only [add_comm c, fderiv_add_const]
Mathlib/Analysis/Calculus/FDeriv/Add.lean
311
313
/- Copyright (c) 2018 Ellen Arlt. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ellen Arlt, Blair Shi, Sean Leather, Mario Carneiro, Johan Commelin, Lu-Ming Zhang -/ import Mathlib.Algebra.Algebra.Opposite import Mathlib.Algebra.Algebra.Pi import Mathlib.Algebra.BigOperators.RingEquiv import Mathlib.Data.Finite.Prod import Mathlib.Data.Matrix.Mul import Mathlib.LinearAlgebra.Pi /-! # Matrices This file contains basic results on matrices including bundled versions of matrix operators. ## Implementation notes For convenience, `Matrix m n α` is defined as `m → n → α`, as this allows elements of the matrix to be accessed with `A i j`. However, it is not advisable to _construct_ matrices using terms of the form `fun i j ↩ _` or even `(fun i j ↩ _ : Matrix m n α)`, as these are not recognized by Lean as having the right type. Instead, `Matrix.of` should be used. ## TODO Under various conditions, multiplication of infinite matrices makes sense. These have not yet been implemented. -/ assert_not_exists Star universe u u' v w variable {l m n o : Type*} {m' : o → Type*} {n' : o → Type*} variable {R : Type*} {S : Type*} {α : Type v} {β : Type w} {γ : Type*} namespace Matrix instance decidableEq [DecidableEq α] [Fintype m] [Fintype n] : DecidableEq (Matrix m n α) := Fintype.decidablePiFintype instance {n m} [Fintype m] [DecidableEq m] [Fintype n] [DecidableEq n] (α) [Fintype α] : Fintype (Matrix m n α) := inferInstanceAs (Fintype (m → n → α)) instance {n m} [Finite m] [Finite n] (α) [Finite α] : Finite (Matrix m n α) := inferInstanceAs (Finite (m → n → α)) section variable (R) /-- This is `Matrix.of` bundled as a linear equivalence. -/ def ofLinearEquiv [Semiring R] [AddCommMonoid α] [Module R α] : (m → n → α) ≃ₗ[R] Matrix m n α where __ := ofAddEquiv map_smul' _ _ := rfl @[simp] lemma coe_ofLinearEquiv [Semiring R] [AddCommMonoid α] [Module R α] : ⇑(ofLinearEquiv _ : (m → n → α) ≃ₗ[R] Matrix m n α) = of := rfl @[simp] lemma coe_ofLinearEquiv_symm [Semiring R] [AddCommMonoid α] [Module R α] : ⇑((ofLinearEquiv _).symm : Matrix m n α ≃ₗ[R] (m → n → α)) = of.symm := rfl end theorem sum_apply [AddCommMonoid α] (i : m) (j : n) (s : Finset β) (g : β → Matrix m n α) : (∑ c ∈ s, g c) i j = ∑ c ∈ s, g c i j := (congr_fun (s.sum_apply i g) j).trans (s.sum_apply j _) end Matrix open Matrix namespace Matrix section Diagonal variable [DecidableEq n] variable (n α) /-- `Matrix.diagonal` as an `AddMonoidHom`. -/ @[simps] def diagonalAddMonoidHom [AddZeroClass α] : (n → α) →+ Matrix n n α where toFun := diagonal map_zero' := diagonal_zero map_add' x y := (diagonal_add x y).symm variable (R) /-- `Matrix.diagonal` as a `LinearMap`. -/ @[simps] def diagonalLinearMap [Semiring R] [AddCommMonoid α] [Module R α] : (n → α) →ₗ[R] Matrix n n α := { diagonalAddMonoidHom n α with map_smul' := diagonal_smul } variable {n α R} section One variable [Zero α] [One α] lemma zero_le_one_elem [Preorder α] [ZeroLEOneClass α] (i j : n) : 0 ≀ (1 : Matrix n n α) i j := by by_cases hi : i = j · subst hi simp · simp [hi] lemma zero_le_one_row [Preorder α] [ZeroLEOneClass α] (i : n) : 0 ≀ (1 : Matrix n n α) i := zero_le_one_elem i end One end Diagonal section Diag variable (n α) /-- `Matrix.diag` as an `AddMonoidHom`. -/ @[simps] def diagAddMonoidHom [AddZeroClass α] : Matrix n n α →+ n → α where toFun := diag map_zero' := diag_zero map_add' := diag_add variable (R) /-- `Matrix.diag` as a `LinearMap`. -/ @[simps] def diagLinearMap [Semiring R] [AddCommMonoid α] [Module R α] : Matrix n n α →ₗ[R] n → α := { diagAddMonoidHom n α with map_smul' := diag_smul } variable {n α R} @[simp] theorem diag_list_sum [AddMonoid α] (l : List (Matrix n n α)) : diag l.sum = (l.map diag).sum := map_list_sum (diagAddMonoidHom n α) l @[simp] theorem diag_multiset_sum [AddCommMonoid α] (s : Multiset (Matrix n n α)) : diag s.sum = (s.map diag).sum := map_multiset_sum (diagAddMonoidHom n α) s @[simp] theorem diag_sum {ι} [AddCommMonoid α] (s : Finset ι) (f : ι → Matrix n n α) : diag (∑ i ∈ s, f i) = ∑ i ∈ s, diag (f i) := map_sum (diagAddMonoidHom n α) f s end Diag open Matrix section AddCommMonoid variable [AddCommMonoid α] [Mul α] end AddCommMonoid section NonAssocSemiring variable [NonAssocSemiring α] variable (α n) /-- `Matrix.diagonal` as a `RingHom`. -/ @[simps] def diagonalRingHom [Fintype n] [DecidableEq n] : (n → α) →+* Matrix n n α := { diagonalAddMonoidHom n α with toFun := diagonal map_one' := diagonal_one map_mul' := fun _ _ => (diagonal_mul_diagonal' _ _).symm } end NonAssocSemiring section Semiring variable [Semiring α] theorem diagonal_pow [Fintype n] [DecidableEq n] (v : n → α) (k : ℕ) : diagonal v ^ k = diagonal (v ^ k) := (map_pow (diagonalRingHom n α) v k).symm /-- The ring homomorphism `α →+* Matrix n n α` sending `a` to the diagonal matrix with `a` on the diagonal. -/ def scalar (n : Type u) [DecidableEq n] [Fintype n] : α →+* Matrix n n α := (diagonalRingHom n α).comp <| Pi.constRingHom n α section Scalar variable [DecidableEq n] [Fintype n] @[simp] theorem scalar_apply (a : α) : scalar n a = diagonal fun _ => a := rfl theorem scalar_inj [Nonempty n] {r s : α} : scalar n r = scalar n s ↔ r = s := (diagonal_injective.comp Function.const_injective).eq_iff theorem scalar_commute_iff {r : α} {M : Matrix n n α} : Commute (scalar n r) M ↔ r • M = MulOpposite.op r • M := by simp_rw [Commute, SemiconjBy, scalar_apply, ← smul_eq_diagonal_mul, ← op_smul_eq_mul_diagonal] theorem scalar_commute (r : α) (hr : ∀ r', Commute r r') (M : Matrix n n α) : Commute (scalar n r) M := scalar_commute_iff.2 <| ext fun _ _ => hr _ end Scalar end Semiring section Algebra variable [Fintype n] [DecidableEq n] variable [CommSemiring R] [Semiring α] [Semiring β] [Algebra R α] [Algebra R β] instance instAlgebra : Algebra R (Matrix n n α) where algebraMap := (Matrix.scalar n).comp (algebraMap R α) commutes' _ _ := scalar_commute _ (fun _ => Algebra.commutes _ _) _ smul_def' r x := by ext; simp [Matrix.scalar, Algebra.smul_def r] theorem algebraMap_matrix_apply {r : R} {i j : n} : algebraMap R (Matrix n n α) r i j = if i = j then algebraMap R α r else 0 := by dsimp [algebraMap, Algebra.algebraMap, Matrix.scalar] split_ifs with h <;> simp [h, Matrix.one_apply_ne] theorem algebraMap_eq_diagonal (r : R) : algebraMap R (Matrix n n α) r = diagonal (algebraMap R (n → α) r) := rfl theorem algebraMap_eq_diagonalRingHom : algebraMap R (Matrix n n α) = (diagonalRingHom n α).comp (algebraMap R _) := rfl @[simp] theorem map_algebraMap (r : R) (f : α → β) (hf : f 0 = 0) (hf₂ : f (algebraMap R α r) = algebraMap R β r) : (algebraMap R (Matrix n n α) r).map f = algebraMap R (Matrix n n β) r := by rw [algebraMap_eq_diagonal, algebraMap_eq_diagonal, diagonal_map hf] simp [hf₂] variable (R) /-- `Matrix.diagonal` as an `AlgHom`. -/ @[simps] def diagonalAlgHom : (n → α) →ₐ[R] Matrix n n α := { diagonalRingHom n α with toFun := diagonal commutes' := fun r => (algebraMap_eq_diagonal r).symm } end Algebra section AddHom variable [Add α] variable (R α) in /-- Extracting entries from a matrix as an additive homomorphism. -/ @[simps] def entryAddHom (i : m) (j : n) : AddHom (Matrix m n α) α where toFun M := M i j map_add' _ _ := rfl -- It is necessary to spell out the name of the coercion explicitly on the RHS -- for unification to succeed lemma entryAddHom_eq_comp {i : m} {j : n} : entryAddHom α i j = ((Pi.evalAddHom (fun _ => α) j).comp (Pi.evalAddHom _ i)).comp (AddHomClass.toAddHom ofAddEquiv.symm) := rfl end AddHom section AddMonoidHom variable [AddZeroClass α] variable (R α) in /-- Extracting entries from a matrix as an additive monoid homomorphism. Note this cannot be upgraded to a ring homomorphism, as it does not respect multiplication. -/ @[simps] def entryAddMonoidHom (i : m) (j : n) : Matrix m n α →+ α where toFun M := M i j map_add' _ _ := rfl map_zero' := rfl -- It is necessary to spell out the name of the coercion explicitly on the RHS -- for unification to succeed lemma entryAddMonoidHom_eq_comp {i : m} {j : n} : entryAddMonoidHom α i j = ((Pi.evalAddMonoidHom (fun _ => α) j).comp (Pi.evalAddMonoidHom _ i)).comp (AddMonoidHomClass.toAddMonoidHom ofAddEquiv.symm) := by rfl @[simp] lemma evalAddMonoidHom_comp_diagAddMonoidHom (i : m) : (Pi.evalAddMonoidHom _ i).comp (diagAddMonoidHom m α) = entryAddMonoidHom α i i := by simp [AddMonoidHom.ext_iff] @[simp] lemma entryAddMonoidHom_toAddHom {i : m} {j : n} : (entryAddMonoidHom α i j : AddHom _ _) = entryAddHom α i j := rfl end AddMonoidHom section LinearMap variable [Semiring R] [AddCommMonoid α] [Module R α] variable (R α) in /-- Extracting entries from a matrix as a linear map. Note this cannot be upgraded to an algebra homomorphism, as it does not respect multiplication. -/ @[simps] def entryLinearMap (i : m) (j : n) : Matrix m n α →ₗ[R] α where toFun M := M i j map_add' _ _ := rfl map_smul' _ _ := rfl -- It is necessary to spell out the name of the coercion explicitly on the RHS -- for unification to succeed lemma entryLinearMap_eq_comp {i : m} {j : n} : entryLinearMap R α i j = LinearMap.proj j ∘ₗ LinearMap.proj i ∘ₗ (ofLinearEquiv R).symm.toLinearMap := by rfl @[simp] lemma proj_comp_diagLinearMap (i : m) : LinearMap.proj i ∘ₗ diagLinearMap m R α = entryLinearMap R α i i := by simp [LinearMap.ext_iff] @[simp] lemma entryLinearMap_toAddMonoidHom {i : m} {j : n} : (entryLinearMap R α i j : _ →+ _) = entryAddMonoidHom α i j := rfl @[simp] lemma entryLinearMap_toAddHom {i : m} {j : n} : (entryLinearMap R α i j : AddHom _ _) = entryAddHom α i j := rfl end LinearMap end Matrix /-! ### Bundled versions of `Matrix.map` -/ namespace Equiv /-- The `Equiv` between spaces of matrices induced by an `Equiv` between their coefficients. This is `Matrix.map` as an `Equiv`. -/ @[simps apply] def mapMatrix (f : α ≃ β) : Matrix m n α ≃ Matrix m n β where toFun M := M.map f invFun M := M.map f.symm left_inv _ := Matrix.ext fun _ _ => f.symm_apply_apply _ right_inv _ := Matrix.ext fun _ _ => f.apply_symm_apply _ @[simp] theorem mapMatrix_refl : (Equiv.refl α).mapMatrix = Equiv.refl (Matrix m n α) := rfl @[simp] theorem mapMatrix_symm (f : α ≃ β) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m n β ≃ _) := rfl @[simp] theorem mapMatrix_trans (f : α ≃ β) (g : β ≃ γ) : f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m n α ≃ _) := rfl end Equiv namespace AddMonoidHom variable [AddZeroClass α] [AddZeroClass β] [AddZeroClass γ] /-- The `AddMonoidHom` between spaces of matrices induced by an `AddMonoidHom` between their coefficients. This is `Matrix.map` as an `AddMonoidHom`. -/ @[simps] def mapMatrix (f : α →+ β) : Matrix m n α →+ Matrix m n β where toFun M := M.map f map_zero' := Matrix.map_zero f f.map_zero map_add' := Matrix.map_add f f.map_add @[simp] theorem mapMatrix_id : (AddMonoidHom.id α).mapMatrix = AddMonoidHom.id (Matrix m n α) := rfl @[simp] theorem mapMatrix_comp (f : β →+ γ) (g : α →+ β) : f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m n α →+ _) := rfl @[simp] lemma entryAddMonoidHom_comp_mapMatrix (f : α →+ β) (i : m) (j : n) : (entryAddMonoidHom β i j).comp f.mapMatrix = f.comp (entryAddMonoidHom α i j) := rfl end AddMonoidHom namespace AddEquiv variable [Add α] [Add β] [Add γ] /-- The `AddEquiv` between spaces of matrices induced by an `AddEquiv` between their coefficients. This is `Matrix.map` as an `AddEquiv`. -/ @[simps apply] def mapMatrix (f : α ≃+ β) : Matrix m n α ≃+ Matrix m n β := { f.toEquiv.mapMatrix with toFun := fun M => M.map f invFun := fun M => M.map f.symm map_add' := Matrix.map_add f (map_add f) } @[simp] theorem mapMatrix_refl : (AddEquiv.refl α).mapMatrix = AddEquiv.refl (Matrix m n α) := rfl @[simp] theorem mapMatrix_symm (f : α ≃+ β) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m n β ≃+ _) := rfl @[simp] theorem mapMatrix_trans (f : α ≃+ β) (g : β ≃+ γ) : f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m n α ≃+ _) := rfl @[simp] lemma entryAddHom_comp_mapMatrix (f : α ≃+ β) (i : m) (j : n) : (entryAddHom β i j).comp (AddHomClass.toAddHom f.mapMatrix) = (f : AddHom α β).comp (entryAddHom _ i j) := rfl end AddEquiv namespace LinearMap variable [Semiring R] [AddCommMonoid α] [AddCommMonoid β] [AddCommMonoid γ] variable [Module R α] [Module R β] [Module R γ] /-- The `LinearMap` between spaces of matrices induced by a `LinearMap` between their coefficients. This is `Matrix.map` as a `LinearMap`. -/ @[simps] def mapMatrix (f : α →ₗ[R] β) : Matrix m n α →ₗ[R] Matrix m n β where toFun M := M.map f map_add' := Matrix.map_add f f.map_add map_smul' r := Matrix.map_smul f r (f.map_smul r) @[simp] theorem mapMatrix_id : LinearMap.id.mapMatrix = (LinearMap.id : Matrix m n α →ₗ[R] _) := rfl @[simp] theorem mapMatrix_comp (f : β →ₗ[R] γ) (g : α →ₗ[R] β) : f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m n α →ₗ[R] _) := rfl @[simp] lemma entryLinearMap_comp_mapMatrix (f : α →ₗ[R] β) (i : m) (j : n) : entryLinearMap R _ i j ∘ₗ f.mapMatrix = f ∘ₗ entryLinearMap R _ i j := rfl end LinearMap namespace LinearEquiv variable [Semiring R] [AddCommMonoid α] [AddCommMonoid β] [AddCommMonoid γ] variable [Module R α] [Module R β] [Module R γ] /-- The `LinearEquiv` between spaces of matrices induced by a `LinearEquiv` between their coefficients. This is `Matrix.map` as a `LinearEquiv`. -/ @[simps apply] def mapMatrix (f : α ≃ₗ[R] β) : Matrix m n α ≃ₗ[R] Matrix m n β := { f.toEquiv.mapMatrix, f.toLinearMap.mapMatrix with toFun := fun M => M.map f invFun := fun M => M.map f.symm } @[simp] theorem mapMatrix_refl : (LinearEquiv.refl R α).mapMatrix = LinearEquiv.refl R (Matrix m n α) := rfl @[simp] theorem mapMatrix_symm (f : α ≃ₗ[R] β) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m n β ≃ₗ[R] _) := rfl @[simp] theorem mapMatrix_trans (f : α ≃ₗ[R] β) (g : β ≃ₗ[R] γ) : f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m n α ≃ₗ[R] _) := rfl @[simp] lemma mapMatrix_toLinearMap (f : α ≃ₗ[R] β) : (f.mapMatrix : _ ≃ₗ[R] Matrix m n β).toLinearMap = f.toLinearMap.mapMatrix := by rfl @[simp] lemma entryLinearMap_comp_mapMatrix (f : α ≃ₗ[R] β) (i : m) (j : n) : entryLinearMap R _ i j ∘ₗ f.mapMatrix.toLinearMap = f.toLinearMap ∘ₗ entryLinearMap R _ i j := by simp only [mapMatrix_toLinearMap, LinearMap.entryLinearMap_comp_mapMatrix] end LinearEquiv namespace RingHom variable [Fintype m] [DecidableEq m] variable [NonAssocSemiring α] [NonAssocSemiring β] [NonAssocSemiring γ] /-- The `RingHom` between spaces of square matrices induced by a `RingHom` between their coefficients. This is `Matrix.map` as a `RingHom`. -/ @[simps] def mapMatrix (f : α →+* β) : Matrix m m α →+* Matrix m m β := { f.toAddMonoidHom.mapMatrix with toFun := fun M => M.map f map_one' := by simp map_mul' := fun _ _ => Matrix.map_mul } @[simp] theorem mapMatrix_id : (RingHom.id α).mapMatrix = RingHom.id (Matrix m m α) := rfl @[simp] theorem mapMatrix_comp (f : β →+* γ) (g : α →+* β) : f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m m α →+* _) := rfl end RingHom namespace RingEquiv variable [Fintype m] [DecidableEq m] variable [NonAssocSemiring α] [NonAssocSemiring β] [NonAssocSemiring γ] /-- The `RingEquiv` between spaces of square matrices induced by a `RingEquiv` between their coefficients. This is `Matrix.map` as a `RingEquiv`. -/ @[simps apply] def mapMatrix (f : α ≃+* β) : Matrix m m α ≃+* Matrix m m β := { f.toRingHom.mapMatrix, f.toAddEquiv.mapMatrix with toFun := fun M => M.map f invFun := fun M => M.map f.symm } @[simp] theorem mapMatrix_refl : (RingEquiv.refl α).mapMatrix = RingEquiv.refl (Matrix m m α) := rfl @[simp] theorem mapMatrix_symm (f : α ≃+* β) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m m β ≃+* _) := rfl @[simp] theorem mapMatrix_trans (f : α ≃+* β) (g : β ≃+* γ) : f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m m α ≃+* _) := rfl open MulOpposite in /-- For any ring `R`, we have ring isomorphism `Matₙₓₙ(Rᵒᵖ) ≅ (Matₙₓₙ(R))ᵒᵖ` given by transpose. -/ @[simps apply symm_apply] def mopMatrix : Matrix m m αᵐᵒᵖ ≃+* (Matrix m m α)ᵐᵒᵖ where toFun M := op (M.transpose.map unop) invFun M := M.unop.transpose.map op left_inv _ := by aesop right_inv _ := by aesop map_mul' _ _ := unop_injective <| by ext; simp [transpose, mul_apply] map_add' _ _ := by aesop end RingEquiv namespace AlgHom variable [Fintype m] [DecidableEq m] variable [CommSemiring R] [Semiring α] [Semiring β] [Semiring γ] variable [Algebra R α] [Algebra R β] [Algebra R γ] /-- The `AlgHom` between spaces of square matrices induced by an `AlgHom` between their coefficients. This is `Matrix.map` as an `AlgHom`. -/ @[simps] def mapMatrix (f : α →ₐ[R] β) : Matrix m m α →ₐ[R] Matrix m m β := { f.toRingHom.mapMatrix with toFun := fun M => M.map f commutes' := fun r => Matrix.map_algebraMap r f (map_zero _) (f.commutes r) } @[simp] theorem mapMatrix_id : (AlgHom.id R α).mapMatrix = AlgHom.id R (Matrix m m α) := rfl @[simp] theorem mapMatrix_comp (f : β →ₐ[R] γ) (g : α →ₐ[R] β) : f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m m α →ₐ[R] _) := rfl end AlgHom namespace AlgEquiv variable [Fintype m] [DecidableEq m] variable [CommSemiring R] [Semiring α] [Semiring β] [Semiring γ] variable [Algebra R α] [Algebra R β] [Algebra R γ] /-- The `AlgEquiv` between spaces of square matrices induced by an `AlgEquiv` between their coefficients. This is `Matrix.map` as an `AlgEquiv`. -/ @[simps apply] def mapMatrix (f : α ≃ₐ[R] β) : Matrix m m α ≃ₐ[R] Matrix m m β := { f.toAlgHom.mapMatrix, f.toRingEquiv.mapMatrix with toFun := fun M => M.map f invFun := fun M => M.map f.symm } @[simp] theorem mapMatrix_refl : AlgEquiv.refl.mapMatrix = (AlgEquiv.refl : Matrix m m α ≃ₐ[R] _) := rfl @[simp] theorem mapMatrix_symm (f : α ≃ₐ[R] β) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m m β ≃ₐ[R] _) := rfl @[simp] theorem mapMatrix_trans (f : α ≃ₐ[R] β) (g : β ≃ₐ[R] γ) : f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m m α ≃ₐ[R] _) := rfl /-- For any algebra `α` over a ring `R`, we have an `R`-algebra isomorphism `Matₙₓₙ(αᵒᵖ) ≅ (Matₙₓₙ(R))ᵒᵖ` given by transpose. If `α` is commutative, we can get rid of the `ᵒᵖ` in the left-hand side, see `Matrix.transposeAlgEquiv`. -/ @[simps!] def mopMatrix : Matrix m m αᵐᵒᵖ ≃ₐ[R] (Matrix m m α)ᵐᵒᵖ where __ := RingEquiv.mopMatrix commutes' _ := MulOpposite.unop_injective <| by ext; simp [algebraMap_matrix_apply, eq_comm, apply_ite MulOpposite.unop] end AlgEquiv open Matrix namespace Matrix section Transpose open Matrix variable (m n α) /-- `Matrix.transpose` as an `AddEquiv` -/ @[simps apply] def transposeAddEquiv [Add α] : Matrix m n α ≃+ Matrix n m α where toFun := transpose invFun := transpose left_inv := transpose_transpose right_inv := transpose_transpose map_add' := transpose_add @[simp] theorem transposeAddEquiv_symm [Add α] : (transposeAddEquiv m n α).symm = transposeAddEquiv n m α := rfl variable {m n α} theorem transpose_list_sum [AddMonoid α] (l : List (Matrix m n α)) : l.sumᵀ = (l.map transpose).sum := map_list_sum (transposeAddEquiv m n α) l theorem transpose_multiset_sum [AddCommMonoid α] (s : Multiset (Matrix m n α)) : s.sumᵀ = (s.map transpose).sum := (transposeAddEquiv m n α).toAddMonoidHom.map_multiset_sum s theorem transpose_sum [AddCommMonoid α] {ι : Type*} (s : Finset ι) (M : ι → Matrix m n α) : (∑ i ∈ s, M i)ᵀ = ∑ i ∈ s, (M i)ᵀ := map_sum (transposeAddEquiv m n α) _ s variable (m n R α) /-- `Matrix.transpose` as a `LinearMap` -/ @[simps apply] def transposeLinearEquiv [Semiring R] [AddCommMonoid α] [Module R α] : Matrix m n α ≃ₗ[R] Matrix n m α := { transposeAddEquiv m n α with map_smul' := transpose_smul } @[simp] theorem transposeLinearEquiv_symm [Semiring R] [AddCommMonoid α] [Module R α] : (transposeLinearEquiv m n R α).symm = transposeLinearEquiv n m R α := rfl variable {m n R α} variable (m α) /-- `Matrix.transpose` as a `RingEquiv` to the opposite ring -/ @[simps] def transposeRingEquiv [AddCommMonoid α] [CommSemigroup α] [Fintype m] : Matrix m m α ≃+* (Matrix m m α)ᵐᵒᵖ := { (transposeAddEquiv m m α).trans MulOpposite.opAddEquiv with toFun := fun M => MulOpposite.op Mᵀ invFun := fun M => M.unopᵀ map_mul' := fun M N => (congr_arg MulOpposite.op (transpose_mul M N)).trans (MulOpposite.op_mul _ _) left_inv := fun M => transpose_transpose M right_inv := fun M => MulOpposite.unop_injective <| transpose_transpose M.unop } variable {m α} @[simp] theorem transpose_pow [CommSemiring α] [Fintype m] [DecidableEq m] (M : Matrix m m α) (k : ℕ) : (M ^ k)ᵀ = Mᵀ ^ k := MulOpposite.op_injective <| map_pow (transposeRingEquiv m α) M k theorem transpose_list_prod [CommSemiring α] [Fintype m] [DecidableEq m] (l : List (Matrix m m α)) : l.prodᵀ = (l.map transpose).reverse.prod := (transposeRingEquiv m α).unop_map_list_prod l variable (R m α) /-- `Matrix.transpose` as an `AlgEquiv` to the opposite ring -/ @[simps] def transposeAlgEquiv [CommSemiring R] [CommSemiring α] [Fintype m] [DecidableEq m] [Algebra R α] : Matrix m m α ≃ₐ[R] (Matrix m m α)ᵐᵒᵖ := { (transposeAddEquiv m m α).trans MulOpposite.opAddEquiv, transposeRingEquiv m α with toFun := fun M => MulOpposite.op Mᵀ commutes' := fun r => by simp only [algebraMap_eq_diagonal, diagonal_transpose, MulOpposite.algebraMap_apply] } variable {R m α} end Transpose end Matrix
Mathlib/Data/Matrix/Basic.lean
1,344
1,347
/- Copyright (c) 2018 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Johannes Hölzl, Yaël Dillies -/ import Mathlib.Analysis.Normed.Group.Seminorm import Mathlib.Data.NNReal.Basic import Mathlib.Topology.Algebra.Support import Mathlib.Topology.MetricSpace.Basic import Mathlib.Topology.Order.Real /-! # Normed (semi)groups In this file we define 10 classes: * `Norm`, `NNNorm`: auxiliary classes endowing a type `α` with a function `norm : α → ℝ` (notation: `‖x‖`) and `nnnorm : α → ℝ≥0` (notation: `‖x‖₊`), respectively; * `Seminormed...Group`: A seminormed (additive) (commutative) group is an (additive) (commutative) group with a norm and a compatible pseudometric space structure: `∀ x y, dist x y = ‖x / y‖` or `∀ x y, dist x y = ‖x - y‖`, depending on the group operation. * `Normed...Group`: A normed (additive) (commutative) group is an (additive) (commutative) group with a norm and a compatible metric space structure. We also prove basic properties of (semi)normed groups and provide some instances. ## Notes The current convention `dist x y = ‖x - y‖` means that the distance is invariant under right addition, but actions in mathlib are usually from the left. This means we might want to change it to `dist x y = ‖-x + y‖`. The normed group hierarchy would lend itself well to a mixin design (that is, having `SeminormedGroup` and `SeminormedAddGroup` not extend `Group` and `AddGroup`), but we choose not to for performance concerns. ## Tags normed group -/ variable {𝓕 α ι κ E F G : Type*} open Filter Function Metric Bornology open ENNReal Filter NNReal Uniformity Pointwise Topology /-- Auxiliary class, endowing a type `E` with a function `norm : E → ℝ` with notation `‖x‖`. This class is designed to be extended in more interesting classes specifying the properties of the norm. -/ @[notation_class] class Norm (E : Type*) where /-- the `ℝ`-valued norm function. -/ norm : E → ℝ /-- Auxiliary class, endowing a type `α` with a function `nnnorm : α → ℝ≥0` with notation `‖x‖₊`. -/ @[notation_class] class NNNorm (E : Type*) where /-- the `ℝ≥0`-valued norm function. -/ nnnorm : E → ℝ≥0 /-- Auxiliary class, endowing a type `α` with a function `enorm : α → ℝ≥0∞` with notation `‖x‖ₑ`. -/ @[notation_class] class ENorm (E : Type*) where /-- the `ℝ≥0∞`-valued norm function. -/ enorm : E → ℝ≥0∞ export Norm (norm) export NNNorm (nnnorm) export ENorm (enorm) @[inherit_doc] notation "‖" e "‖" => norm e @[inherit_doc] notation "‖" e "‖₊" => nnnorm e @[inherit_doc] notation "‖" e "‖ₑ" => enorm e section ENorm variable {E : Type*} [NNNorm E] {x : E} {r : ℝ≥0} instance NNNorm.toENorm : ENorm E where enorm := (‖·‖₊ : E → ℝ≥0∞) lemma enorm_eq_nnnorm (x : E) : ‖x‖ₑ = ‖x‖₊ := rfl @[simp] lemma toNNReal_enorm (x : E) : ‖x‖ₑ.toNNReal = ‖x‖₊ := rfl @[simp, norm_cast] lemma coe_le_enorm : r ≀ ‖x‖ₑ ↔ r ≀ ‖x‖₊ := by simp [enorm] @[simp, norm_cast] lemma enorm_le_coe : ‖x‖ₑ ≀ r ↔ ‖x‖₊ ≀ r := by simp [enorm] @[simp, norm_cast] lemma coe_lt_enorm : r < ‖x‖ₑ ↔ r < ‖x‖₊ := by simp [enorm] @[simp, norm_cast] lemma enorm_lt_coe : ‖x‖ₑ < r ↔ ‖x‖₊ < r := by simp [enorm] @[simp] lemma enorm_ne_top : ‖x‖ₑ ≠ ∞ := by simp [enorm] @[simp] lemma enorm_lt_top : ‖x‖ₑ < ∞ := by simp [enorm] end ENorm /-- A type `E` equipped with a continuous map `‖·‖ₑ : E → ℝ≥0∞` NB. We do not demand that the topology is somehow defined by the enorm: for ℝ≥0∞ (the motivating example behind this definition), this is not true. -/ class ContinuousENorm (E : Type*) [TopologicalSpace E] extends ENorm E where continuous_enorm : Continuous enorm /-- An enormed monoid is an additive monoid endowed with a continuous enorm. -/ class ENormedAddMonoid (E : Type*) [TopologicalSpace E] extends ContinuousENorm E, AddMonoid E where enorm_eq_zero : ∀ x : E, ‖x‖ₑ = 0 ↔ x = 0 protected enorm_add_le : ∀ x y : E, ‖x + y‖ₑ ≀ ‖x‖ₑ + ‖y‖ₑ /-- An enormed monoid is a monoid endowed with a continuous enorm. -/ @[to_additive] class ENormedMonoid (E : Type*) [TopologicalSpace E] extends ContinuousENorm E, Monoid E where enorm_eq_zero : ∀ x : E, ‖x‖ₑ = 0 ↔ x = 1 enorm_mul_le : ∀ x y : E, ‖x * y‖ₑ ≀ ‖x‖ₑ + ‖y‖ₑ /-- An enormed commutative monoid is an additive commutative monoid endowed with a continuous enorm. We don't have `ENormedAddCommMonoid` extend `EMetricSpace`, since the canonical instance `ℝ≥0∞` is not an `EMetricSpace`. This is because `ℝ≥0∞` carries the order topology, which is distinct from the topology coming from `edist`. -/ class ENormedAddCommMonoid (E : Type*) [TopologicalSpace E] extends ENormedAddMonoid E, AddCommMonoid E where /-- An enormed commutative monoid is a commutative monoid endowed with a continuous enorm. -/ @[to_additive] class ENormedCommMonoid (E : Type*) [TopologicalSpace E] extends ENormedMonoid E, CommMonoid E where /-- A seminormed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a pseudometric space structure. -/ class SeminormedAddGroup (E : Type*) extends Norm E, AddGroup E, PseudoMetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop /-- A seminormed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a pseudometric space structure. -/ @[to_additive] class SeminormedGroup (E : Type*) extends Norm E, Group E, PseudoMetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop /-- A normed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a metric space structure. -/ class NormedAddGroup (E : Type*) extends Norm E, AddGroup E, MetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop /-- A normed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a metric space structure. -/ @[to_additive] class NormedGroup (E : Type*) extends Norm E, Group E, MetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop /-- A seminormed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a pseudometric space structure. -/ class SeminormedAddCommGroup (E : Type*) extends Norm E, AddCommGroup E, PseudoMetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop /-- A seminormed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a pseudometric space structure. -/ @[to_additive] class SeminormedCommGroup (E : Type*) extends Norm E, CommGroup E, PseudoMetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop /-- A normed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a metric space structure. -/ class NormedAddCommGroup (E : Type*) extends Norm E, AddCommGroup E, MetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop /-- A normed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a metric space structure. -/ @[to_additive] class NormedCommGroup (E : Type*) extends Norm E, CommGroup E, MetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedGroup.toSeminormedGroup [NormedGroup E] : SeminormedGroup E := { ‹NormedGroup E› with } -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedCommGroup.toSeminormedCommGroup [NormedCommGroup E] : SeminormedCommGroup E := { ‹NormedCommGroup E› with } -- See note [lower instance priority] @[to_additive] instance (priority := 100) SeminormedCommGroup.toSeminormedGroup [SeminormedCommGroup E] : SeminormedGroup E := { ‹SeminormedCommGroup E› with } -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedCommGroup.toNormedGroup [NormedCommGroup E] : NormedGroup E := { ‹NormedCommGroup E› with } -- See note [reducible non-instances] /-- Construct a `NormedGroup` from a `SeminormedGroup` satisfying `∀ x, ‖x‖ = 0 → x = 1`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedGroup` instance as a special case of a more general `SeminormedGroup` instance. -/ @[to_additive "Construct a `NormedAddGroup` from a `SeminormedAddGroup` satisfying `∀ x, ‖x‖ = 0 → x = 0`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedAddGroup` instance as a special case of a more general `SeminormedAddGroup` instance."] abbrev NormedGroup.ofSeparation [SeminormedGroup E] (h : ∀ x : E, ‖x‖ = 0 → x = 1) : NormedGroup E where dist_eq := ‹SeminormedGroup E›.dist_eq toMetricSpace := { eq_of_dist_eq_zero := fun hxy => div_eq_one.1 <| h _ <| (‹SeminormedGroup E›.dist_eq _ _).symm.trans hxy } -- See note [reducible non-instances] /-- Construct a `NormedCommGroup` from a `SeminormedCommGroup` satisfying `∀ x, ‖x‖ = 0 → x = 1`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedCommGroup` instance as a special case of a more general `SeminormedCommGroup` instance. -/ @[to_additive "Construct a `NormedAddCommGroup` from a `SeminormedAddCommGroup` satisfying `∀ x, ‖x‖ = 0 → x = 0`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedAddCommGroup` instance as a special case of a more general `SeminormedAddCommGroup` instance."] abbrev NormedCommGroup.ofSeparation [SeminormedCommGroup E] (h : ∀ x : E, ‖x‖ = 0 → x = 1) : NormedCommGroup E := { ‹SeminormedCommGroup E›, NormedGroup.ofSeparation h with } -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant distance. -/ @[to_additive "Construct a seminormed group from a translation-invariant distance."] abbrev SeminormedGroup.ofMulDist [Norm E] [Group E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≀ dist (x * z) (y * z)) : SeminormedGroup E where dist_eq x y := by rw [h₁]; apply le_antisymm · simpa only [div_eq_mul_inv, ← mul_inv_cancel y] using h₂ _ _ _ · simpa only [div_mul_cancel, one_mul] using h₂ (x / y) 1 y -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive "Construct a seminormed group from a translation-invariant pseudodistance."] abbrev SeminormedGroup.ofMulDist' [Norm E] [Group E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≀ dist x y) : SeminormedGroup E where dist_eq x y := by rw [h₁]; apply le_antisymm · simpa only [div_mul_cancel, one_mul] using h₂ (x / y) 1 y · simpa only [div_eq_mul_inv, ← mul_inv_cancel y] using h₂ _ _ _ -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive "Construct a seminormed group from a translation-invariant pseudodistance."] abbrev SeminormedCommGroup.ofMulDist [Norm E] [CommGroup E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≀ dist (x * z) (y * z)) : SeminormedCommGroup E := { SeminormedGroup.ofMulDist h₁ h₂ with mul_comm := mul_comm } -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive "Construct a seminormed group from a translation-invariant pseudodistance."] abbrev SeminormedCommGroup.ofMulDist' [Norm E] [CommGroup E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≀ dist x y) : SeminormedCommGroup E := { SeminormedGroup.ofMulDist' h₁ h₂ with mul_comm := mul_comm } -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant distance. -/ @[to_additive "Construct a normed group from a translation-invariant distance."] abbrev NormedGroup.ofMulDist [Norm E] [Group E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≀ dist (x * z) (y * z)) : NormedGroup E := { SeminormedGroup.ofMulDist h₁ h₂ with eq_of_dist_eq_zero := eq_of_dist_eq_zero } -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive "Construct a normed group from a translation-invariant pseudodistance."] abbrev NormedGroup.ofMulDist' [Norm E] [Group E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≀ dist x y) : NormedGroup E := { SeminormedGroup.ofMulDist' h₁ h₂ with eq_of_dist_eq_zero := eq_of_dist_eq_zero } -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive "Construct a normed group from a translation-invariant pseudodistance."] abbrev NormedCommGroup.ofMulDist [Norm E] [CommGroup E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≀ dist (x * z) (y * z)) : NormedCommGroup E := { NormedGroup.ofMulDist h₁ h₂ with mul_comm := mul_comm } -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive "Construct a normed group from a translation-invariant pseudodistance."] abbrev NormedCommGroup.ofMulDist' [Norm E] [CommGroup E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≀ dist x y) : NormedCommGroup E := { NormedGroup.ofMulDist' h₁ h₂ with mul_comm := mul_comm } -- See note [reducible non-instances] /-- Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive "Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] abbrev GroupSeminorm.toSeminormedGroup [Group E] (f : GroupSeminorm E) : SeminormedGroup E where dist x y := f (x / y) norm := f dist_eq _ _ := rfl dist_self x := by simp only [div_self', map_one_eq_zero] dist_triangle := le_map_div_add_map_div f dist_comm := map_div_rev f -- See note [reducible non-instances] /-- Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive "Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] abbrev GroupSeminorm.toSeminormedCommGroup [CommGroup E] (f : GroupSeminorm E) : SeminormedCommGroup E := { f.toSeminormedGroup with mul_comm := mul_comm } -- See note [reducible non-instances] /-- Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive "Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] abbrev GroupNorm.toNormedGroup [Group E] (f : GroupNorm E) : NormedGroup E := { f.toGroupSeminorm.toSeminormedGroup with eq_of_dist_eq_zero := fun h => div_eq_one.1 <| eq_one_of_map_eq_zero f h } -- See note [reducible non-instances] /-- Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive "Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] abbrev GroupNorm.toNormedCommGroup [CommGroup E] (f : GroupNorm E) : NormedCommGroup E := { f.toNormedGroup with mul_comm := mul_comm } section SeminormedGroup variable [SeminormedGroup E] [SeminormedGroup F] [SeminormedGroup G] {s : Set E} {a a₁ a₂ b c : E} {r r₁ r₂ : ℝ} @[to_additive] theorem dist_eq_norm_div (a b : E) : dist a b = ‖a / b‖ := SeminormedGroup.dist_eq _ _ @[to_additive] theorem dist_eq_norm_div' (a b : E) : dist a b = ‖b / a‖ := by rw [dist_comm, dist_eq_norm_div] alias dist_eq_norm := dist_eq_norm_sub alias dist_eq_norm' := dist_eq_norm_sub' @[to_additive of_forall_le_norm] lemma DiscreteTopology.of_forall_le_norm' (hpos : 0 < r) (hr : ∀ x : E, x ≠ 1 → r ≀ ‖x‖) : DiscreteTopology E := .of_forall_le_dist hpos fun x y hne ↩ by simp only [dist_eq_norm_div] exact hr _ (div_ne_one.2 hne) @[to_additive (attr := simp)] theorem dist_one_right (a : E) : dist a 1 = ‖a‖ := by rw [dist_eq_norm_div, div_one] @[to_additive] theorem inseparable_one_iff_norm {a : E} : Inseparable a 1 ↔ ‖a‖ = 0 := by rw [Metric.inseparable_iff, dist_one_right] @[to_additive] lemma dist_one_left (a : E) : dist 1 a = ‖a‖ := by rw [dist_comm, dist_one_right] @[to_additive (attr := simp)] lemma dist_one : dist (1 : E) = norm := funext dist_one_left @[to_additive] theorem norm_div_rev (a b : E) : ‖a / b‖ = ‖b / a‖ := by simpa only [dist_eq_norm_div] using dist_comm a b @[to_additive (attr := simp) norm_neg] theorem norm_inv' (a : E) : ‖a⁻¹‖ = ‖a‖ := by simpa using norm_div_rev 1 a @[to_additive (attr := simp) norm_abs_zsmul] theorem norm_zpow_abs (a : E) (n : â„€) : ‖a ^ |n|‖ = ‖a ^ n‖ := by rcases le_total 0 n with hn | hn <;> simp [hn, abs_of_nonneg, abs_of_nonpos] @[to_additive (attr := simp) norm_natAbs_smul] theorem norm_pow_natAbs (a : E) (n : â„€) : ‖a ^ n.natAbs‖ = ‖a ^ n‖ := by rw [← zpow_natCast, ← Int.abs_eq_natAbs, norm_zpow_abs] @[to_additive norm_isUnit_zsmul] theorem norm_zpow_isUnit (a : E) {n : â„€} (hn : IsUnit n) : ‖a ^ n‖ = ‖a‖ := by rw [← norm_pow_natAbs, Int.isUnit_iff_natAbs_eq.mp hn, pow_one] @[simp] theorem norm_units_zsmul {E : Type*} [SeminormedAddGroup E] (n : ℀ˣ) (a : E) : ‖n • a‖ = ‖a‖ := norm_isUnit_zsmul a n.isUnit open scoped symmDiff in @[to_additive] theorem dist_mulIndicator (s t : Set α) (f : α → E) (x : α) : dist (s.mulIndicator f x) (t.mulIndicator f x) = ‖(s ∆ t).mulIndicator f x‖ := by rw [dist_eq_norm_div, Set.apply_mulIndicator_symmDiff norm_inv'] /-- **Triangle inequality** for the norm. -/ @[to_additive norm_add_le "**Triangle inequality** for the norm."] theorem norm_mul_le' (a b : E) : ‖a * b‖ ≀ ‖a‖ + ‖b‖ := by simpa [dist_eq_norm_div] using dist_triangle a 1 b⁻¹ /-- **Triangle inequality** for the norm. -/ @[to_additive norm_add_le_of_le "**Triangle inequality** for the norm."] theorem norm_mul_le_of_le' (h₁ : ‖a₁‖ ≀ r₁) (h₂ : ‖a₂‖ ≀ r₂) : ‖a₁ * a₂‖ ≀ r₁ + r₂ := (norm_mul_le' a₁ a₂).trans <| add_le_add h₁ h₂ /-- **Triangle inequality** for the norm. -/ @[to_additive norm_add₃_le "**Triangle inequality** for the norm."] lemma norm_mul₃_le' : ‖a * b * c‖ ≀ ‖a‖ + ‖b‖ + ‖c‖ := norm_mul_le_of_le' (norm_mul_le' _ _) le_rfl @[to_additive] lemma norm_div_le_norm_div_add_norm_div (a b c : E) : ‖a / c‖ ≀ ‖a / b‖ + ‖b / c‖ := by simpa only [dist_eq_norm_div] using dist_triangle a b c @[to_additive (attr := simp) norm_nonneg] theorem norm_nonneg' (a : E) : 0 ≀ ‖a‖ := by rw [← dist_one_right] exact dist_nonneg attribute [bound] norm_nonneg @[to_additive (attr := simp) abs_norm] theorem abs_norm' (z : E) : |‖z‖| = ‖z‖ := abs_of_nonneg <| norm_nonneg' _ @[to_additive (attr := simp) norm_zero] theorem norm_one' : ‖(1 : E)‖ = 0 := by rw [← dist_one_right, dist_self] @[to_additive] theorem ne_one_of_norm_ne_zero : ‖a‖ ≠ 0 → a ≠ 1 := mt <| by rintro rfl exact norm_one' @[to_additive (attr := nontriviality) norm_of_subsingleton] theorem norm_of_subsingleton' [Subsingleton E] (a : E) : ‖a‖ = 0 := by rw [Subsingleton.elim a 1, norm_one'] @[to_additive zero_lt_one_add_norm_sq] theorem zero_lt_one_add_norm_sq' (x : E) : 0 < 1 + ‖x‖ ^ 2 := by positivity @[to_additive] theorem norm_div_le (a b : E) : ‖a / b‖ ≀ ‖a‖ + ‖b‖ := by simpa [dist_eq_norm_div] using dist_triangle a 1 b attribute [bound] norm_sub_le @[to_additive] theorem norm_div_le_of_le {r₁ r₂ : ℝ} (H₁ : ‖a₁‖ ≀ r₁) (H₂ : ‖a₂‖ ≀ r₂) : ‖a₁ / a₂‖ ≀ r₁ + r₂ := (norm_div_le a₁ a₂).trans <| add_le_add H₁ H₂ @[to_additive dist_le_norm_add_norm] theorem dist_le_norm_add_norm' (a b : E) : dist a b ≀ ‖a‖ + ‖b‖ := by rw [dist_eq_norm_div] apply norm_div_le @[to_additive abs_norm_sub_norm_le] theorem abs_norm_sub_norm_le' (a b : E) : |‖a‖ - ‖b‖| ≀ ‖a / b‖ := by simpa [dist_eq_norm_div] using abs_dist_sub_le a b 1 @[to_additive norm_sub_norm_le] theorem norm_sub_norm_le' (a b : E) : ‖a‖ - ‖b‖ ≀ ‖a / b‖ := (le_abs_self _).trans (abs_norm_sub_norm_le' a b) @[to_additive (attr := bound)] theorem norm_sub_le_norm_mul (a b : E) : ‖a‖ - ‖b‖ ≀ ‖a * b‖ := by simpa using norm_mul_le' (a * b) (b⁻¹) @[to_additive dist_norm_norm_le] theorem dist_norm_norm_le' (a b : E) : dist ‖a‖ ‖b‖ ≀ ‖a / b‖ := abs_norm_sub_norm_le' a b @[to_additive] theorem norm_le_norm_add_norm_div' (u v : E) : ‖u‖ ≀ ‖v‖ + ‖u / v‖ := by rw [add_comm] refine (norm_mul_le' _ _).trans_eq' ?_ rw [div_mul_cancel] @[to_additive] theorem norm_le_norm_add_norm_div (u v : E) : ‖v‖ ≀ ‖u‖ + ‖u / v‖ := by rw [norm_div_rev] exact norm_le_norm_add_norm_div' v u alias norm_le_insert' := norm_le_norm_add_norm_sub' alias norm_le_insert := norm_le_norm_add_norm_sub @[to_additive] theorem norm_le_mul_norm_add (u v : E) : ‖u‖ ≀ ‖u * v‖ + ‖v‖ := calc ‖u‖ = ‖u * v / v‖ := by rw [mul_div_cancel_right] _ ≀ ‖u * v‖ + ‖v‖ := norm_div_le _ _ /-- An analogue of `norm_le_mul_norm_add` for the multiplication from the left. -/ @[to_additive "An analogue of `norm_le_add_norm_add` for the addition from the left."] theorem norm_le_mul_norm_add' (u v : E) : ‖v‖ ≀ ‖u * v‖ + ‖u‖ := calc ‖v‖ = ‖u⁻¹ * (u * v)‖ := by rw [← mul_assoc, inv_mul_cancel, one_mul] _ ≀ ‖u⁻¹‖ + ‖u * v‖ := norm_mul_le' u⁻¹ (u * v) _ = ‖u * v‖ + ‖u‖ := by rw [norm_inv', add_comm] @[to_additive] lemma norm_mul_eq_norm_right {x : E} (y : E) (h : ‖x‖ = 0) : ‖x * y‖ = ‖y‖ := by apply le_antisymm ?_ ?_ · simpa [h] using norm_mul_le' x y · simpa [h] using norm_le_mul_norm_add' x y @[to_additive] lemma norm_mul_eq_norm_left (x : E) {y : E} (h : ‖y‖ = 0) : ‖x * y‖ = ‖x‖ := by apply le_antisymm ?_ ?_ · simpa [h] using norm_mul_le' x y · simpa [h] using norm_le_mul_norm_add x y @[to_additive] lemma norm_div_eq_norm_right {x : E} (y : E) (h : ‖x‖ = 0) : ‖x / y‖ = ‖y‖ := by apply le_antisymm ?_ ?_ · simpa [h] using norm_div_le x y · simpa [h, norm_div_rev x y] using norm_sub_norm_le' y x @[to_additive] lemma norm_div_eq_norm_left (x : E) {y : E} (h : ‖y‖ = 0) : ‖x / y‖ = ‖x‖ := by apply le_antisymm ?_ ?_ · simpa [h] using norm_div_le x y · simpa [h] using norm_sub_norm_le' x y @[to_additive ball_eq] theorem ball_eq' (y : E) (ε : ℝ) : ball y ε = { x | ‖x / y‖ < ε } := Set.ext fun a => by simp [dist_eq_norm_div] @[to_additive] theorem ball_one_eq (r : ℝ) : ball (1 : E) r = { x | ‖x‖ < r } := Set.ext fun a => by simp @[to_additive mem_ball_iff_norm] theorem mem_ball_iff_norm'' : b ∈ ball a r ↔ ‖b / a‖ < r := by rw [mem_ball, dist_eq_norm_div] @[to_additive mem_ball_iff_norm'] theorem mem_ball_iff_norm''' : b ∈ ball a r ↔ ‖a / b‖ < r := by rw [mem_ball', dist_eq_norm_div] @[to_additive] theorem mem_ball_one_iff : a ∈ ball (1 : E) r ↔ ‖a‖ < r := by rw [mem_ball, dist_one_right] @[to_additive mem_closedBall_iff_norm] theorem mem_closedBall_iff_norm'' : b ∈ closedBall a r ↔ ‖b / a‖ ≀ r := by rw [mem_closedBall, dist_eq_norm_div] @[to_additive] theorem mem_closedBall_one_iff : a ∈ closedBall (1 : E) r ↔ ‖a‖ ≀ r := by rw [mem_closedBall, dist_one_right] @[to_additive mem_closedBall_iff_norm'] theorem mem_closedBall_iff_norm''' : b ∈ closedBall a r ↔ ‖a / b‖ ≀ r := by rw [mem_closedBall', dist_eq_norm_div] @[to_additive norm_le_of_mem_closedBall] theorem norm_le_of_mem_closedBall' (h : b ∈ closedBall a r) : ‖b‖ ≀ ‖a‖ + r := (norm_le_norm_add_norm_div' _ _).trans <| add_le_add_left (by rwa [← dist_eq_norm_div]) _ @[to_additive norm_le_norm_add_const_of_dist_le] theorem norm_le_norm_add_const_of_dist_le' : dist a b ≀ r → ‖a‖ ≀ ‖b‖ + r := norm_le_of_mem_closedBall' @[to_additive norm_lt_of_mem_ball] theorem norm_lt_of_mem_ball' (h : b ∈ ball a r) : ‖b‖ < ‖a‖ + r := (norm_le_norm_add_norm_div' _ _).trans_lt <| add_lt_add_left (by rwa [← dist_eq_norm_div]) _ @[to_additive] theorem norm_div_sub_norm_div_le_norm_div (u v w : E) : ‖u / w‖ - ‖v / w‖ ≀ ‖u / v‖ := by simpa only [div_div_div_cancel_right] using norm_sub_norm_le' (u / w) (v / w) @[to_additive (attr := simp 1001) mem_sphere_iff_norm] -- Porting note: increase priority so the left-hand side doesn't reduce theorem mem_sphere_iff_norm' : b ∈ sphere a r ↔ ‖b / a‖ = r := by simp [dist_eq_norm_div] @[to_additive] -- `simp` can prove this theorem mem_sphere_one_iff_norm : a ∈ sphere (1 : E) r ↔ ‖a‖ = r := by simp [dist_eq_norm_div] @[to_additive (attr := simp) norm_eq_of_mem_sphere] theorem norm_eq_of_mem_sphere' (x : sphere (1 : E) r) : ‖(x : E)‖ = r := mem_sphere_one_iff_norm.mp x.2 @[to_additive] theorem ne_one_of_mem_sphere (hr : r ≠ 0) (x : sphere (1 : E) r) : (x : E) ≠ 1 := ne_one_of_norm_ne_zero <| by rwa [norm_eq_of_mem_sphere' x] @[to_additive ne_zero_of_mem_unit_sphere] theorem ne_one_of_mem_unit_sphere (x : sphere (1 : E) 1) : (x : E) ≠ 1 := ne_one_of_mem_sphere one_ne_zero _ variable (E) /-- The norm of a seminormed group as a group seminorm. -/ @[to_additive "The norm of a seminormed group as an additive group seminorm."] def normGroupSeminorm : GroupSeminorm E := ⟹norm, norm_one', norm_mul_le', norm_inv'⟩ @[to_additive (attr := simp)] theorem coe_normGroupSeminorm : ⇑(normGroupSeminorm E) = norm := rfl variable {E} @[to_additive] theorem NormedCommGroup.tendsto_nhds_one {f : α → E} {l : Filter α} : Tendsto f l (𝓝 1) ↔ ∀ ε > 0, ∀ᶠ x in l, ‖f x‖ < ε := Metric.tendsto_nhds.trans <| by simp only [dist_one_right] @[to_additive] theorem NormedCommGroup.tendsto_nhds_nhds {f : E → F} {x : E} {y : F} : Tendsto f (𝓝 x) (𝓝 y) ↔ ∀ ε > 0, ∃ ÎŽ > 0, ∀ x', ‖x' / x‖ < ÎŽ → ‖f x' / y‖ < ε := by simp_rw [Metric.tendsto_nhds_nhds, dist_eq_norm_div] @[to_additive] theorem NormedCommGroup.nhds_basis_norm_lt (x : E) : (𝓝 x).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { y | ‖y / x‖ < ε } := by simp_rw [← ball_eq'] exact Metric.nhds_basis_ball @[to_additive] theorem NormedCommGroup.nhds_one_basis_norm_lt : (𝓝 (1 : E)).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { y | ‖y‖ < ε } := by convert NormedCommGroup.nhds_basis_norm_lt (1 : E) simp @[to_additive] theorem NormedCommGroup.uniformity_basis_dist : (𝓀 E).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { p : E × E | ‖p.fst / p.snd‖ < ε } := by convert Metric.uniformity_basis_dist (α := E) using 1 simp [dist_eq_norm_div] open Finset variable [FunLike 𝓕 E F] section NNNorm -- See note [lower instance priority] @[to_additive] instance (priority := 100) SeminormedGroup.toNNNorm : NNNorm E := ⟹fun a => ⟹‖a‖, norm_nonneg' a⟩⟩ @[to_additive (attr := simp, norm_cast) coe_nnnorm] theorem coe_nnnorm' (a : E) : (‖a‖₊ : ℝ) = ‖a‖ := rfl @[to_additive (attr := simp) coe_comp_nnnorm] theorem coe_comp_nnnorm' : (toReal : ℝ≥0 → ℝ) ∘ (nnnorm : E → ℝ≥0) = norm := rfl @[to_additive (attr := simp) norm_toNNReal] theorem norm_toNNReal' : ‖a‖.toNNReal = ‖a‖₊ := @Real.toNNReal_coe ‖a‖₊ @[to_additive (attr := simp) toReal_enorm] lemma toReal_enorm' (x : E) : ‖x‖ₑ.toReal = ‖x‖ := by simp [enorm] @[to_additive (attr := simp) ofReal_norm] lemma ofReal_norm' (x : E) : .ofReal ‖x‖ = ‖x‖ₑ := by simp [enorm, ENNReal.ofReal, Real.toNNReal, nnnorm] @[to_additive enorm_eq_iff_norm_eq] theorem enorm'_eq_iff_norm_eq {x : E} {y : F} : ‖x‖ₑ = ‖y‖ₑ ↔ ‖x‖ = ‖y‖ := by simp only [← ofReal_norm'] refine ⟹fun h ↩ ?_, fun h ↩ by congr⟩ exact (Real.toNNReal_eq_toNNReal_iff (norm_nonneg' _) (norm_nonneg' _)).mp (ENNReal.coe_inj.mp h) @[to_additive enorm_le_iff_norm_le] theorem enorm'_le_iff_norm_le {x : E} {y : F} : ‖x‖ₑ ≀ ‖y‖ₑ ↔ ‖x‖ ≀ ‖y‖ := by simp only [← ofReal_norm'] refine ⟹fun h ↩ ?_, fun h ↩ by gcongr⟩ rw [ENNReal.ofReal_le_ofReal_iff (norm_nonneg' _)] at h exact h @[to_additive] theorem nndist_eq_nnnorm_div (a b : E) : nndist a b = ‖a / b‖₊ := NNReal.eq <| dist_eq_norm_div _ _ alias nndist_eq_nnnorm := nndist_eq_nnnorm_sub @[to_additive (attr := simp)] theorem nndist_one_right (a : E) : nndist a 1 = ‖a‖₊ := by simp [nndist_eq_nnnorm_div] @[to_additive (attr := simp)] lemma edist_one_right (a : E) : edist a 1 = ‖a‖ₑ := by simp [edist_nndist, nndist_one_right, enorm] @[to_additive (attr := simp) nnnorm_zero] theorem nnnorm_one' : ‖(1 : E)‖₊ = 0 := NNReal.eq norm_one' @[to_additive] theorem ne_one_of_nnnorm_ne_zero {a : E} : ‖a‖₊ ≠ 0 → a ≠ 1 := mt <| by rintro rfl exact nnnorm_one' @[to_additive nnnorm_add_le] theorem nnnorm_mul_le' (a b : E) : ‖a * b‖₊ ≀ ‖a‖₊ + ‖b‖₊ := NNReal.coe_le_coe.1 <| norm_mul_le' a b @[to_additive norm_nsmul_le] lemma norm_pow_le_mul_norm : ∀ {n : ℕ}, ‖a ^ n‖ ≀ n * ‖a‖ | 0 => by simp | n + 1 => by simpa [pow_succ, add_mul] using norm_mul_le_of_le' norm_pow_le_mul_norm le_rfl @[to_additive nnnorm_nsmul_le] lemma nnnorm_pow_le_mul_norm {n : ℕ} : ‖a ^ n‖₊ ≀ n * ‖a‖₊ := by simpa only [← NNReal.coe_le_coe, NNReal.coe_mul, NNReal.coe_natCast] using norm_pow_le_mul_norm @[to_additive (attr := simp) nnnorm_neg] theorem nnnorm_inv' (a : E) : ‖a⁻¹‖₊ = ‖a‖₊ := NNReal.eq <| norm_inv' a @[to_additive (attr := simp) nnnorm_abs_zsmul] theorem nnnorm_zpow_abs (a : E) (n : â„€) : ‖a ^ |n|‖₊ = ‖a ^ n‖₊ := NNReal.eq <| norm_zpow_abs a n @[to_additive (attr := simp) nnnorm_natAbs_smul] theorem nnnorm_pow_natAbs (a : E) (n : â„€) : ‖a ^ n.natAbs‖₊ = ‖a ^ n‖₊ := NNReal.eq <| norm_pow_natAbs a n @[to_additive nnnorm_isUnit_zsmul] theorem nnnorm_zpow_isUnit (a : E) {n : â„€} (hn : IsUnit n) : ‖a ^ n‖₊ = ‖a‖₊ := NNReal.eq <| norm_zpow_isUnit a hn @[simp] theorem nnnorm_units_zsmul {E : Type*} [SeminormedAddGroup E] (n : ℀ˣ) (a : E) : ‖n • a‖₊ = ‖a‖₊ := NNReal.eq <| norm_isUnit_zsmul a n.isUnit @[to_additive (attr := simp)] theorem nndist_one_left (a : E) : nndist 1 a = ‖a‖₊ := by simp [nndist_eq_nnnorm_div] @[to_additive (attr := simp)] theorem edist_one_left (a : E) : edist 1 a = ‖a‖₊ := by rw [edist_nndist, nndist_one_left] open scoped symmDiff in @[to_additive] theorem nndist_mulIndicator (s t : Set α) (f : α → E) (x : α) : nndist (s.mulIndicator f x) (t.mulIndicator f x) = ‖(s ∆ t).mulIndicator f x‖₊ := NNReal.eq <| dist_mulIndicator s t f x @[to_additive] theorem nnnorm_div_le (a b : E) : ‖a / b‖₊ ≀ ‖a‖₊ + ‖b‖₊ := NNReal.coe_le_coe.1 <| norm_div_le _ _ @[to_additive] lemma enorm_div_le : ‖a / b‖ₑ ≀ ‖a‖ₑ + ‖b‖ₑ := by simpa [enorm, ← ENNReal.coe_add] using nnnorm_div_le a b @[to_additive nndist_nnnorm_nnnorm_le] theorem nndist_nnnorm_nnnorm_le' (a b : E) : nndist ‖a‖₊ ‖b‖₊ ≀ ‖a / b‖₊ := NNReal.coe_le_coe.1 <| dist_norm_norm_le' a b @[to_additive] theorem nnnorm_le_nnnorm_add_nnnorm_div (a b : E) : ‖b‖₊ ≀ ‖a‖₊ + ‖a / b‖₊ := norm_le_norm_add_norm_div _ _ @[to_additive] theorem nnnorm_le_nnnorm_add_nnnorm_div' (a b : E) : ‖a‖₊ ≀ ‖b‖₊ + ‖a / b‖₊ := norm_le_norm_add_norm_div' _ _ alias nnnorm_le_insert' := nnnorm_le_nnnorm_add_nnnorm_sub' alias nnnorm_le_insert := nnnorm_le_nnnorm_add_nnnorm_sub @[to_additive] theorem nnnorm_le_mul_nnnorm_add (a b : E) : ‖a‖₊ ≀ ‖a * b‖₊ + ‖b‖₊ := norm_le_mul_norm_add _ _ /-- An analogue of `nnnorm_le_mul_nnnorm_add` for the multiplication from the left. -/ @[to_additive "An analogue of `nnnorm_le_add_nnnorm_add` for the addition from the left."] theorem nnnorm_le_mul_nnnorm_add' (a b : E) : ‖b‖₊ ≀ ‖a * b‖₊ + ‖a‖₊ := norm_le_mul_norm_add' _ _ @[to_additive] lemma nnnorm_mul_eq_nnnorm_right {x : E} (y : E) (h : ‖x‖₊ = 0) : ‖x * y‖₊ = ‖y‖₊ := NNReal.eq <| norm_mul_eq_norm_right _ <| congr_arg NNReal.toReal h @[to_additive] lemma nnnorm_mul_eq_nnnorm_left (x : E) {y : E} (h : ‖y‖₊ = 0) : ‖x * y‖₊ = ‖x‖₊ := NNReal.eq <| norm_mul_eq_norm_left _ <| congr_arg NNReal.toReal h @[to_additive] lemma nnnorm_div_eq_nnnorm_right {x : E} (y : E) (h : ‖x‖₊ = 0) : ‖x / y‖₊ = ‖y‖₊ := NNReal.eq <| norm_div_eq_norm_right _ <| congr_arg NNReal.toReal h @[to_additive] lemma nnnorm_div_eq_nnnorm_left (x : E) {y : E} (h : ‖y‖₊ = 0) : ‖x / y‖₊ = ‖x‖₊ := NNReal.eq <| norm_div_eq_norm_left _ <| congr_arg NNReal.toReal h /-- The non negative norm seen as an `ENNReal` and then as a `Real` is equal to the norm. -/ @[to_additive toReal_coe_nnnorm "The non negative norm seen as an `ENNReal` and then as a `Real` is equal to the norm."] theorem toReal_coe_nnnorm' (a : E) : (‖a‖₊ : ℝ≥0∞).toReal = ‖a‖ := rfl open scoped symmDiff in @[to_additive] theorem edist_mulIndicator (s t : Set α) (f : α → E) (x : α) : edist (s.mulIndicator f x) (t.mulIndicator f x) = ‖(s ∆ t).mulIndicator f x‖₊ := by rw [edist_nndist, nndist_mulIndicator] end NNNorm section ENorm @[to_additive (attr := simp) enorm_zero] lemma enorm_one' {E : Type*} [TopologicalSpace E] [ENormedMonoid E] : ‖(1 : E)‖ₑ = 0 := by rw [ENormedMonoid.enorm_eq_zero] @[to_additive exists_enorm_lt] lemma exists_enorm_lt' (E : Type*) [TopologicalSpace E] [ENormedMonoid E] [hbot : NeBot (𝓝[≠] (1 : E))] {c : ℝ≥0∞} (hc : c ≠ 0) : ∃ x ≠ (1 : E), ‖x‖ₑ < c := frequently_iff_neBot.mpr hbot |>.and_eventually (ContinuousENorm.continuous_enorm.tendsto' 1 0 (by simp) |>.eventually_lt_const hc.bot_lt) |>.exists @[to_additive (attr := simp) enorm_neg] lemma enorm_inv' (a : E) : ‖a⁻¹‖ₑ = ‖a‖ₑ := by simp [enorm] @[to_additive ofReal_norm_eq_enorm] lemma ofReal_norm_eq_enorm' (a : E) : .ofReal ‖a‖ = ‖a‖ₑ := ENNReal.ofReal_eq_coe_nnreal _ @[deprecated (since := "2025-01-17")] alias ofReal_norm_eq_coe_nnnorm := ofReal_norm_eq_enorm @[deprecated (since := "2025-01-17")] alias ofReal_norm_eq_coe_nnnorm' := ofReal_norm_eq_enorm' instance : ENorm ℝ≥0∞ where enorm x := x @[simp] lemma enorm_eq_self (x : ℝ≥0∞) : ‖x‖ₑ = x := rfl @[to_additive] theorem edist_eq_enorm_div (a b : E) : edist a b = ‖a / b‖ₑ := by rw [edist_dist, dist_eq_norm_div, ofReal_norm_eq_enorm'] @[deprecated (since := "2025-01-17")] alias edist_eq_coe_nnnorm_sub := edist_eq_enorm_sub @[deprecated (since := "2025-01-17")] alias edist_eq_coe_nnnorm_div := edist_eq_enorm_div @[to_additive] theorem edist_one_eq_enorm (x : E) : edist x 1 = ‖x‖ₑ := by rw [edist_eq_enorm_div, div_one] @[deprecated (since := "2025-01-17")] alias edist_eq_coe_nnnorm := edist_zero_eq_enorm @[deprecated (since := "2025-01-17")] alias edist_eq_coe_nnnorm' := edist_one_eq_enorm @[to_additive] theorem mem_emetric_ball_one_iff {r : ℝ≥0∞} : a ∈ EMetric.ball 1 r ↔ ‖a‖ₑ < r := by rw [EMetric.mem_ball, edist_one_eq_enorm] end ENorm section ContinuousENorm variable {E : Type*} [TopologicalSpace E] [ContinuousENorm E] @[continuity, fun_prop] lemma continuous_enorm : Continuous fun a : E ↩ ‖a‖ₑ := ContinuousENorm.continuous_enorm variable {X : Type*} [TopologicalSpace X] {f : X → E} {s : Set X} {a : X} @[fun_prop] lemma Continuous.enorm : Continuous f → Continuous (‖f ·‖ₑ) := continuous_enorm.comp lemma ContinuousAt.enorm {a : X} (h : ContinuousAt f a) : ContinuousAt (‖f ·‖ₑ) a := by fun_prop @[fun_prop] lemma ContinuousWithinAt.enorm {s : Set X} {a : X} (h : ContinuousWithinAt f s a) : ContinuousWithinAt (‖f ·‖ₑ) s a := (ContinuousENorm.continuous_enorm.continuousWithinAt).comp (t := Set.univ) h (fun _ _ ↩ by trivial) @[fun_prop] lemma ContinuousOn.enorm (h : ContinuousOn f s) : ContinuousOn (‖f ·‖ₑ) s := (ContinuousENorm.continuous_enorm.continuousOn).comp (t := Set.univ) h <| Set.mapsTo_univ _ _ end ContinuousENorm section ENormedMonoid variable {E : Type*} [TopologicalSpace E] [ENormedMonoid E] @[to_additive enorm_add_le] lemma enorm_mul_le' (a b : E) : ‖a * b‖ₑ ≀ ‖a‖ₑ + ‖b‖ₑ := ENormedMonoid.enorm_mul_le a b @[to_additive (attr := simp) enorm_eq_zero] lemma enorm_eq_zero' {a : E} : ‖a‖ₑ = 0 ↔ a = 1 := by simp [enorm, ENormedMonoid.enorm_eq_zero] @[to_additive enorm_ne_zero] lemma enorm_ne_zero' {a : E} : ‖a‖ₑ ≠ 0 ↔ a ≠ 1 := enorm_eq_zero'.ne @[to_additive (attr := simp) enorm_pos] lemma enorm_pos' {a : E} : 0 < ‖a‖ₑ ↔ a ≠ 1 := pos_iff_ne_zero.trans enorm_ne_zero' end ENormedMonoid instance : ENormedAddCommMonoid ℝ≥0∞ where continuous_enorm := continuous_id enorm_eq_zero := by simp enorm_add_le := by simp open Set in @[to_additive] lemma SeminormedGroup.disjoint_nhds (x : E) (f : Filter E) : Disjoint (𝓝 x) f ↔ ∃ ÎŽ > 0, ∀ᶠ y in f, ÎŽ ≀ ‖y / x‖ := by simp [NormedCommGroup.nhds_basis_norm_lt x |>.disjoint_iff_left, compl_setOf, eventually_iff] @[to_additive] lemma SeminormedGroup.disjoint_nhds_one (f : Filter E) : Disjoint (𝓝 1) f ↔ ∃ ÎŽ > 0, ∀ᶠ y in f, ÎŽ ≀ ‖y‖ := by simpa using disjoint_nhds 1 f end SeminormedGroup section Induced variable (E F) variable [FunLike 𝓕 E F] -- See note [reducible non-instances] /-- A group homomorphism from a `Group` to a `SeminormedGroup` induces a `SeminormedGroup` structure on the domain. -/ @[to_additive "A group homomorphism from an `AddGroup` to a `SeminormedAddGroup` induces a `SeminormedAddGroup` structure on the domain."] abbrev SeminormedGroup.induced [Group E] [SeminormedGroup F] [MonoidHomClass 𝓕 E F] (f : 𝓕) : SeminormedGroup E := { PseudoMetricSpace.induced f toPseudoMetricSpace with norm := fun x => ‖f x‖ dist_eq := fun x y => by simp only [map_div, ← dist_eq_norm_div]; rfl } -- See note [reducible non-instances] /-- A group homomorphism from a `CommGroup` to a `SeminormedGroup` induces a `SeminormedCommGroup` structure on the domain. -/ @[to_additive "A group homomorphism from an `AddCommGroup` to a `SeminormedAddGroup` induces a `SeminormedAddCommGroup` structure on the domain."] abbrev SeminormedCommGroup.induced [CommGroup E] [SeminormedGroup F] [MonoidHomClass 𝓕 E F] (f : 𝓕) : SeminormedCommGroup E := { SeminormedGroup.induced E F f with mul_comm := mul_comm } -- See note [reducible non-instances]. /-- An injective group homomorphism from a `Group` to a `NormedGroup` induces a `NormedGroup` structure on the domain. -/ @[to_additive "An injective group homomorphism from an `AddGroup` to a `NormedAddGroup` induces a `NormedAddGroup` structure on the domain."] abbrev NormedGroup.induced [Group E] [NormedGroup F] [MonoidHomClass 𝓕 E F] (f : 𝓕) (h : Injective f) : NormedGroup E := { SeminormedGroup.induced E F f, MetricSpace.induced f h _ with } -- See note [reducible non-instances]. /-- An injective group homomorphism from a `CommGroup` to a `NormedGroup` induces a `NormedCommGroup` structure on the domain. -/ @[to_additive "An injective group homomorphism from a `CommGroup` to a `NormedCommGroup` induces a `NormedCommGroup` structure on the domain."] abbrev NormedCommGroup.induced [CommGroup E] [NormedGroup F] [MonoidHomClass 𝓕 E F] (f : 𝓕) (h : Injective f) : NormedCommGroup E := { SeminormedGroup.induced E F f, MetricSpace.induced f h _ with mul_comm := mul_comm } end Induced namespace Real variable {r : ℝ} instance norm : Norm ℝ where norm r := |r| @[simp] theorem norm_eq_abs (r : ℝ) : ‖r‖ = |r| := rfl instance normedAddCommGroup : NormedAddCommGroup ℝ := ⟹fun _r _y => rfl⟩ theorem norm_of_nonneg (hr : 0 ≀ r) : ‖r‖ = r := abs_of_nonneg hr theorem norm_of_nonpos (hr : r ≀ 0) : ‖r‖ = -r := abs_of_nonpos hr theorem le_norm_self (r : ℝ) : r ≀ ‖r‖ := le_abs_self r @[simp 1100] lemma norm_natCast (n : ℕ) : ‖(n : ℝ)‖ = n := abs_of_nonneg n.cast_nonneg @[simp 1100] lemma nnnorm_natCast (n : ℕ) : ‖(n : ℝ)‖₊ = n := NNReal.eq <| norm_natCast _ @[simp 1100] lemma enorm_natCast (n : ℕ) : ‖(n : ℝ)‖ₑ = n := by simp [enorm] @[simp 1100] lemma norm_ofNat (n : ℕ) [n.AtLeastTwo] : ‖(ofNat(n) : ℝ)‖ = ofNat(n) := norm_natCast n @[simp 1100] lemma nnnorm_ofNat (n : ℕ) [n.AtLeastTwo] : ‖(ofNat(n) : ℝ)‖₊ = ofNat(n) := nnnorm_natCast n lemma norm_two : ‖(2 : ℝ)‖ = 2 := abs_of_pos zero_lt_two lemma nnnorm_two : ‖(2 : ℝ)‖₊ = 2 := NNReal.eq <| by simp @[simp 1100, norm_cast] lemma norm_nnratCast (q : ℚ≥0) : ‖(q : ℝ)‖ = q := norm_of_nonneg q.cast_nonneg @[simp 1100, norm_cast] lemma nnnorm_nnratCast (q : ℚ≥0) : ‖(q : ℝ)‖₊ = q := by simp [nnnorm, -norm_eq_abs] theorem nnnorm_of_nonneg (hr : 0 ≀ r) : ‖r‖₊ = ⟹r, hr⟩ := NNReal.eq <| norm_of_nonneg hr lemma enorm_of_nonneg (hr : 0 ≀ r) : ‖r‖ₑ = .ofReal r := by simp [enorm, nnnorm_of_nonneg hr, ENNReal.ofReal, toNNReal, hr] @[simp] lemma nnnorm_abs (r : ℝ) : ‖|r|‖₊ = ‖r‖₊ := by simp [nnnorm] @[simp] lemma enorm_abs (r : ℝ) : ‖|r|‖ₑ = ‖r‖ₑ := by simp [enorm] theorem enorm_eq_ofReal (hr : 0 ≀ r) : ‖r‖ₑ = .ofReal r := by rw [← ofReal_norm_eq_enorm, norm_of_nonneg hr] @[deprecated (since := "2025-01-17")] alias ennnorm_eq_ofReal := enorm_eq_ofReal theorem enorm_eq_ofReal_abs (r : ℝ) : ‖r‖ₑ = ENNReal.ofReal |r| := by rw [← enorm_eq_ofReal (abs_nonneg _), enorm_abs] @[deprecated (since := "2025-01-17")] alias ennnorm_eq_ofReal_abs := enorm_eq_ofReal_abs theorem toNNReal_eq_nnnorm_of_nonneg (hr : 0 ≀ r) : r.toNNReal = ‖r‖₊ := by rw [Real.toNNReal_of_nonneg hr] ext rw [coe_mk, coe_nnnorm r, Real.norm_eq_abs r, abs_of_nonneg hr] -- Porting note: this is due to the change from `Subtype.val` to `NNReal.toReal` for the coercion theorem ofReal_le_enorm (r : ℝ) : ENNReal.ofReal r ≀ ‖r‖ₑ := by rw [enorm_eq_ofReal_abs]; gcongr; exact le_abs_self _ @[deprecated (since := "2025-01-17")] alias ofReal_le_ennnorm := ofReal_le_enorm end Real namespace NNReal instance : NNNorm ℝ≥0 where nnnorm x := x @[simp] lemma nnnorm_eq_self (x : ℝ≥0) : ‖x‖₊ = x := rfl end NNReal section SeminormedCommGroup variable [SeminormedCommGroup E] [SeminormedCommGroup F] {a b : E} {r : ℝ} @[to_additive] theorem dist_inv (x y : E) : dist x⁻¹ y = dist x y⁻¹ := by simp_rw [dist_eq_norm_div, ← norm_inv' (x⁻¹ / y), inv_div, div_inv_eq_mul, mul_comm] theorem norm_multiset_sum_le {E} [SeminormedAddCommGroup E] (m : Multiset E) : ‖m.sum‖ ≀ (m.map fun x => ‖x‖).sum := m.le_sum_of_subadditive norm norm_zero norm_add_le @[to_additive existing] theorem norm_multiset_prod_le (m : Multiset E) : ‖m.prod‖ ≀ (m.map fun x => ‖x‖).sum := by rw [← Multiplicative.ofAdd_le, ofAdd_multiset_prod, Multiset.map_map] refine Multiset.le_prod_of_submultiplicative (Multiplicative.ofAdd ∘ norm) ?_ (fun x y => ?_) _ · simp only [comp_apply, norm_one', ofAdd_zero] · exact norm_mul_le' x y @[bound] theorem norm_sum_le {ι E} [SeminormedAddCommGroup E] (s : Finset ι) (f : ι → E) : ‖∑ i ∈ s, f i‖ ≀ ∑ i ∈ s, ‖f i‖ := s.le_sum_of_subadditive norm norm_zero norm_add_le f @[to_additive existing] theorem norm_prod_le (s : Finset ι) (f : ι → E) : ‖∏ i ∈ s, f i‖ ≀ ∑ i ∈ s, ‖f i‖ := by rw [← Multiplicative.ofAdd_le, ofAdd_sum] refine Finset.le_prod_of_submultiplicative (Multiplicative.ofAdd ∘ norm) ?_ (fun x y => ?_) _ _ · simp only [comp_apply, norm_one', ofAdd_zero] · exact norm_mul_le' x y @[to_additive] theorem norm_prod_le_of_le (s : Finset ι) {f : ι → E} {n : ι → ℝ} (h : ∀ b ∈ s, ‖f b‖ ≀ n b) : ‖∏ b ∈ s, f b‖ ≀ ∑ b ∈ s, n b := (norm_prod_le s f).trans <| Finset.sum_le_sum h @[to_additive] theorem dist_prod_prod_le_of_le (s : Finset ι) {f a : ι → E} {d : ι → ℝ} (h : ∀ b ∈ s, dist (f b) (a b) ≀ d b) : dist (∏ b ∈ s, f b) (∏ b ∈ s, a b) ≀ ∑ b ∈ s, d b := by simp only [dist_eq_norm_div, ← Finset.prod_div_distrib] at * exact norm_prod_le_of_le s h @[to_additive] theorem dist_prod_prod_le (s : Finset ι) (f a : ι → E) : dist (∏ b ∈ s, f b) (∏ b ∈ s, a b) ≀ ∑ b ∈ s, dist (f b) (a b) := dist_prod_prod_le_of_le s fun _ _ => le_rfl @[to_additive] theorem mul_mem_ball_iff_norm : a * b ∈ ball a r ↔ ‖b‖ < r := by rw [mem_ball_iff_norm'', mul_div_cancel_left] @[to_additive] theorem mul_mem_closedBall_iff_norm : a * b ∈ closedBall a r ↔ ‖b‖ ≀ r := by rw [mem_closedBall_iff_norm'', mul_div_cancel_left] @[to_additive (attr := simp 1001)] -- Porting note: increase priority so that the left-hand side doesn't simplify theorem preimage_mul_ball (a b : E) (r : ℝ) : (b * ·) ⁻¹' ball a r = ball (a / b) r := by ext c simp only [dist_eq_norm_div, Set.mem_preimage, mem_ball, div_div_eq_mul_div, mul_comm] @[to_additive (attr := simp 1001)] -- Porting note: increase priority so that the left-hand side doesn't simplify theorem preimage_mul_closedBall (a b : E) (r : ℝ) : (b * ·) ⁻¹' closedBall a r = closedBall (a / b) r := by ext c simp only [dist_eq_norm_div, Set.mem_preimage, mem_closedBall, div_div_eq_mul_div, mul_comm] @[to_additive (attr := simp)] theorem preimage_mul_sphere (a b : E) (r : ℝ) : (b * ·) ⁻¹' sphere a r = sphere (a / b) r := by ext c simp only [Set.mem_preimage, mem_sphere_iff_norm', div_div_eq_mul_div, mul_comm] @[to_additive] theorem pow_mem_closedBall {n : ℕ} (h : a ∈ closedBall b r) : a ^ n ∈ closedBall (b ^ n) (n • r) := by simp only [mem_closedBall, dist_eq_norm_div, ← div_pow] at h ⊢ refine norm_pow_le_mul_norm.trans ?_ simpa only [nsmul_eq_mul] using mul_le_mul_of_nonneg_left h n.cast_nonneg @[to_additive] theorem pow_mem_ball {n : ℕ} (hn : 0 < n) (h : a ∈ ball b r) : a ^ n ∈ ball (b ^ n) (n • r) := by simp only [mem_ball, dist_eq_norm_div, ← div_pow] at h ⊢ refine lt_of_le_of_lt norm_pow_le_mul_norm ?_ replace hn : 0 < (n : ℝ) := by norm_cast rw [nsmul_eq_mul] nlinarith @[to_additive] theorem mul_mem_closedBall_mul_iff {c : E} : a * c ∈ closedBall (b * c) r ↔ a ∈ closedBall b r := by simp only [mem_closedBall, dist_eq_norm_div, mul_div_mul_right_eq_div] @[to_additive] theorem mul_mem_ball_mul_iff {c : E} : a * c ∈ ball (b * c) r ↔ a ∈ ball b r := by simp only [mem_ball, dist_eq_norm_div, mul_div_mul_right_eq_div] @[to_additive] theorem smul_closedBall'' : a • closedBall b r = closedBall (a • b) r := by ext simp [mem_closedBall, Set.mem_smul_set, dist_eq_norm_div, div_eq_inv_mul, ← eq_inv_mul_iff_mul_eq, mul_assoc] @[to_additive] theorem smul_ball'' : a • ball b r = ball (a • b) r := by ext simp [mem_ball, Set.mem_smul_set, dist_eq_norm_div, _root_.div_eq_inv_mul, ← eq_inv_mul_iff_mul_eq, mul_assoc] @[to_additive] theorem nnnorm_multiset_prod_le (m : Multiset E) : ‖m.prod‖₊ ≀ (m.map fun x => ‖x‖₊).sum := NNReal.coe_le_coe.1 <| by push_cast rw [Multiset.map_map] exact norm_multiset_prod_le _ @[to_additive] theorem nnnorm_prod_le (s : Finset ι) (f : ι → E) : ‖∏ a ∈ s, f a‖₊ ≀ ∑ a ∈ s, ‖f a‖₊ := NNReal.coe_le_coe.1 <| by push_cast exact norm_prod_le _ _ @[to_additive] theorem nnnorm_prod_le_of_le (s : Finset ι) {f : ι → E} {n : ι → ℝ≥0} (h : ∀ b ∈ s, ‖f b‖₊ ≀ n b) : ‖∏ b ∈ s, f b‖₊ ≀ ∑ b ∈ s, n b := (norm_prod_le_of_le s h).trans_eq (NNReal.coe_sum ..).symm -- Porting note: increase priority so that the LHS doesn't simplify @[to_additive (attr := simp 1001) norm_norm] lemma norm_norm' (x : E) : ‖‖x‖‖ = ‖x‖ := Real.norm_of_nonneg (norm_nonneg' _) @[to_additive (attr := simp) nnnorm_norm] lemma nnnorm_norm' (x : E) : ‖‖x‖‖₊ = ‖x‖₊ := by simp [nnnorm] @[to_additive (attr := simp) enorm_norm] lemma enorm_norm' (x : E) : ‖‖x‖‖ₑ = ‖x‖ₑ := by simp [enorm] lemma enorm_enorm {ε : Type*} [ENorm ε] (x : ε) : ‖‖x‖ₑ‖ₑ = ‖x‖ₑ := by simp [enorm] end SeminormedCommGroup section NormedGroup variable [NormedGroup E] {a b : E} @[to_additive (attr := simp) norm_le_zero_iff] lemma norm_le_zero_iff' : ‖a‖ ≀ 0 ↔ a = 1 := by rw [← dist_one_right, dist_le_zero] @[to_additive (attr := simp) norm_pos_iff] lemma norm_pos_iff' : 0 < ‖a‖ ↔ a ≠ 1 := by rw [← not_le, norm_le_zero_iff'] @[to_additive (attr := simp) norm_eq_zero] lemma norm_eq_zero' : ‖a‖ = 0 ↔ a = 1 := (norm_nonneg' a).le_iff_eq.symm.trans norm_le_zero_iff' @[to_additive norm_ne_zero_iff] lemma norm_ne_zero_iff' : ‖a‖ ≠ 0 ↔ a ≠ 1 := norm_eq_zero'.not @[deprecated (since := "2024-11-24")] alias norm_le_zero_iff'' := norm_le_zero_iff' @[deprecated (since := "2024-11-24")] alias norm_le_zero_iff''' := norm_le_zero_iff' @[deprecated (since := "2024-11-24")] alias norm_pos_iff'' := norm_pos_iff' @[deprecated (since := "2024-11-24")] alias norm_eq_zero'' := norm_eq_zero' @[deprecated (since := "2024-11-24")] alias norm_eq_zero''' := norm_eq_zero' @[to_additive] theorem norm_div_eq_zero_iff : ‖a / b‖ = 0 ↔ a = b := by rw [norm_eq_zero', div_eq_one] @[to_additive] theorem norm_div_pos_iff : 0 < ‖a / b‖ ↔ a ≠ b := by rw [(norm_nonneg' _).lt_iff_ne, ne_comm] exact norm_div_eq_zero_iff.not @[to_additive eq_of_norm_sub_le_zero] theorem eq_of_norm_div_le_zero (h : ‖a / b‖ ≀ 0) : a = b := by rwa [← div_eq_one, ← norm_le_zero_iff'] alias ⟹eq_of_norm_div_eq_zero, _⟩ := norm_div_eq_zero_iff attribute [to_additive] eq_of_norm_div_eq_zero @[to_additive] theorem eq_one_or_norm_pos (a : E) : a = 1 √ 0 < ‖a‖ := by simpa [eq_comm] using (norm_nonneg' a).eq_or_lt @[to_additive] theorem eq_one_or_nnnorm_pos (a : E) : a = 1 √ 0 < ‖a‖₊ := eq_one_or_norm_pos a @[to_additive (attr := simp) nnnorm_eq_zero] theorem nnnorm_eq_zero' : ‖a‖₊ = 0 ↔ a = 1 := by rw [← NNReal.coe_eq_zero, coe_nnnorm', norm_eq_zero'] @[to_additive nnnorm_ne_zero_iff] theorem nnnorm_ne_zero_iff' : ‖a‖₊ ≠ 0 ↔ a ≠ 1 := nnnorm_eq_zero'.not @[to_additive (attr := simp) nnnorm_pos] lemma nnnorm_pos' : 0 < ‖a‖₊ ↔ a ≠ 1 := pos_iff_ne_zero.trans nnnorm_ne_zero_iff' variable (E) /-- The norm of a normed group as a group norm. -/ @[to_additive "The norm of a normed group as an additive group norm."] def normGroupNorm : GroupNorm E := { normGroupSeminorm _ with eq_one_of_map_eq_zero' := fun _ => norm_eq_zero'.1 } @[simp] theorem coe_normGroupNorm : ⇑(normGroupNorm E) = norm := rfl end NormedGroup section NormedAddGroup variable [NormedAddGroup E] [TopologicalSpace α] {f : α → E} /-! Some relations with `HasCompactSupport` -/ theorem hasCompactSupport_norm_iff : (HasCompactSupport fun x => ‖f x‖) ↔ HasCompactSupport f := hasCompactSupport_comp_left norm_eq_zero alias ⟹_, HasCompactSupport.norm⟩ := hasCompactSupport_norm_iff end NormedAddGroup lemma tendsto_norm_atTop_atTop : Tendsto (norm : ℝ → ℝ) atTop atTop := tendsto_abs_atTop_atTop /-! ### `positivity` extensions -/ namespace Mathlib.Meta.Positivity open Lean Meta Qq Function /-- Extension for the `positivity` tactic: multiplicative norms are always nonnegative, and positive on non-one inputs. -/ @[positivity ‖_‖] def evalMulNorm : PositivityExt where eval {u α} _ _ e := do match u, α, e with | 0, ~q(ℝ), ~q(@Norm.norm $E $_n $a) => let _seminormedGroup_E ← synthInstanceQ q(SeminormedGroup $E) assertInstancesCommute -- Check whether we are in a normed group and whether the context contains a `a ≠ 1` assumption let o : Option (Q(NormedGroup $E) × Q($a ≠ 1)) := ← do let .some normedGroup_E ← trySynthInstanceQ q(NormedGroup $E) | return none let some pa ← findLocalDeclWithTypeQ? q($a ≠ 1) | return none return some (normedGroup_E, pa) match o with -- If so, return a proof of `0 < ‖a‖` | some (_normedGroup_E, pa) => assertInstancesCommute return .positive q(norm_pos_iff'.2 $pa) -- Else, return a proof of `0 ≀ ‖a‖` | none => return .nonnegative q(norm_nonneg' $a) | _, _, _ => throwError "not `‖·‖`" /-- Extension for the `positivity` tactic: additive norms are always nonnegative, and positive on non-zero inputs. -/ @[positivity ‖_‖] def evalAddNorm : PositivityExt where eval {u α} _ _ e := do match u, α, e with | 0, ~q(ℝ), ~q(@Norm.norm $E $_n $a) => let _seminormedAddGroup_E ← synthInstanceQ q(SeminormedAddGroup $E) assertInstancesCommute -- Check whether we are in a normed group and whether the context contains a `a ≠ 0` assumption let o : Option (Q(NormedAddGroup $E) × Q($a ≠ 0)) := ← do let .some normedAddGroup_E ← trySynthInstanceQ q(NormedAddGroup $E) | return none let some pa ← findLocalDeclWithTypeQ? q($a ≠ 0) | return none return some (normedAddGroup_E, pa) match o with -- If so, return a proof of `0 < ‖a‖` | some (_normedAddGroup_E, pa) => assertInstancesCommute return .positive q(norm_pos_iff.2 $pa) -- Else, return a proof of `0 ≀ ‖a‖` | none => return .nonnegative q(norm_nonneg $a) | _, _, _ => throwError "not `‖·‖`" end Mathlib.Meta.Positivity
Mathlib/Analysis/Normed/Group/Basic.lean
1,572
1,573
/- Copyright (c) 2019 Johannes Hölzl, Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Zhouhang Zhou -/ import Mathlib.Dynamics.Ergodic.MeasurePreserving import Mathlib.MeasureTheory.Function.StronglyMeasurable.AEStronglyMeasurable import Mathlib.MeasureTheory.Integral.Lebesgue.Add import Mathlib.Order.Filter.Germ.Basic import Mathlib.Topology.ContinuousMap.Algebra /-! # Almost everywhere equal functions We build a space of equivalence classes of functions, where two functions are treated as identical if they are almost everywhere equal. We form the set of equivalence classes under the relation of being almost everywhere equal, which is sometimes known as the `L⁰` space. To use this space as a basis for the `L^p` spaces and for the Bochner integral, we consider equivalence classes of strongly measurable functions (or, equivalently, of almost everywhere strongly measurable functions.) See `L1Space.lean` for `L¹` space. ## Notation * `α →ₘ[ÎŒ] β` is the type of `L⁰` space, where `α` is a measurable space, `β` is a topological space, and `ÎŒ` is a measure on `α`. `f : α →ₘ β` is a "function" in `L⁰`. In comments, `[f]` is also used to denote an `L⁰` function. `ₘ` can be typed as `\_m`. Sometimes it is shown as a box if font is missing. ## Main statements * The linear structure of `L⁰` : Addition and scalar multiplication are defined on `L⁰` in the natural way, i.e., `[f] + [g] := [f + g]`, `c • [f] := [c • f]`. So defined, `α →ₘ β` inherits the linear structure of `β`. For example, if `β` is a module, then `α →ₘ β` is a module over the same ring. See `mk_add_mk`, `neg_mk`, `mk_sub_mk`, `smul_mk`, `add_toFun`, `neg_toFun`, `sub_toFun`, `smul_toFun` * The order structure of `L⁰` : `≀` can be defined in a similar way: `[f] ≀ [g]` if `f a ≀ g a` for almost all `a` in domain. And `α →ₘ β` inherits the preorder and partial order of `β`. TODO: Define `sup` and `inf` on `L⁰` so that it forms a lattice. It seems that `β` must be a linear order, since otherwise `f ⊔ g` may not be a measurable function. ## Implementation notes * `f.toFun` : To find a representative of `f : α →ₘ β`, use the coercion `(f : α → β)`, which is implemented as `f.toFun`. For each operation `op` in `L⁰`, there is a lemma called `coe_fn_op`, characterizing, say, `(f op g : α → β)`. * `ae_eq_fun.mk` : To constructs an `L⁰` function `α →ₘ β` from an almost everywhere strongly measurable function `f : α → β`, use `ae_eq_fun.mk` * `comp` : Use `comp g f` to get `[g ∘ f]` from `g : β → γ` and `[f] : α →ₘ γ` when `g` is continuous. Use `comp_measurable` if `g` is only measurable (this requires the target space to be second countable). * `comp₂` : Use `comp₂ g f₁ f₂` to get `[fun a ↩ g (f₁ a) (f₂ a)]`. For example, `[f + g]` is `comp₂ (+)` ## Tags function space, almost everywhere equal, `L⁰`, ae_eq_fun -/ -- Guard against import creep assert_not_exists InnerProductSpace noncomputable section open Topology Set Filter TopologicalSpace ENNReal EMetric MeasureTheory Function variable {α β γ ÎŽ : Type*} [MeasurableSpace α] {ÎŒ Μ : Measure α} namespace MeasureTheory section MeasurableSpace variable [TopologicalSpace β] variable (β) /-- The equivalence relation of being almost everywhere equal for almost everywhere strongly measurable functions. -/ def Measure.aeEqSetoid (ÎŒ : Measure α) : Setoid { f : α → β // AEStronglyMeasurable f ÎŒ } := ⟹fun f g => (f : α → β) =ᵐ[ÎŒ] g, fun {f} => ae_eq_refl f.val, fun {_ _} => ae_eq_symm, fun {_ _ _} => ae_eq_trans⟩ variable (α) /-- The space of equivalence classes of almost everywhere strongly measurable functions, where two strongly measurable functions are equivalent if they agree almost everywhere, i.e., they differ on a set of measure `0`. -/ def AEEqFun (ÎŒ : Measure α) : Type _ := Quotient (ÎŒ.aeEqSetoid β) variable {α β} @[inherit_doc MeasureTheory.AEEqFun] notation:25 α " →ₘ[" ÎŒ "] " β => AEEqFun α β ÎŒ end MeasurableSpace variable [TopologicalSpace ÎŽ] namespace AEEqFun section variable [TopologicalSpace β] /-- Construct the equivalence class `[f]` of an almost everywhere measurable function `f`, based on the equivalence relation of being almost everywhere equal. -/ def mk {β : Type*} [TopologicalSpace β] (f : α → β) (hf : AEStronglyMeasurable f ÎŒ) : α →ₘ[ÎŒ] β := Quotient.mk'' ⟹f, hf⟩ open scoped Classical in /-- Coercion from a space of equivalence classes of almost everywhere strongly measurable functions to functions. We ensure that if `f` has a constant representative, then we choose that one. -/ @[coe] def cast (f : α →ₘ[ÎŒ] β) : α → β := if h : ∃ (b : β), f = mk (const α b) aestronglyMeasurable_const then const α <| Classical.choose h else AEStronglyMeasurable.mk _ (Quotient.out f : { f : α → β // AEStronglyMeasurable f ÎŒ }).2 /-- A measurable representative of an `AEEqFun` [f] -/ instance instCoeFun : CoeFun (α →ₘ[ÎŒ] β) fun _ => α → β := ⟹cast⟩ protected theorem stronglyMeasurable (f : α →ₘ[ÎŒ] β) : StronglyMeasurable f := by simp only [cast] split_ifs with h · exact stronglyMeasurable_const · apply AEStronglyMeasurable.stronglyMeasurable_mk protected theorem aestronglyMeasurable (f : α →ₘ[ÎŒ] β) : AEStronglyMeasurable f ÎŒ := f.stronglyMeasurable.aestronglyMeasurable protected theorem measurable [PseudoMetrizableSpace β] [MeasurableSpace β] [BorelSpace β] (f : α →ₘ[ÎŒ] β) : Measurable f := f.stronglyMeasurable.measurable protected theorem aemeasurable [PseudoMetrizableSpace β] [MeasurableSpace β] [BorelSpace β] (f : α →ₘ[ÎŒ] β) : AEMeasurable f ÎŒ := f.measurable.aemeasurable @[simp] theorem quot_mk_eq_mk (f : α → β) (hf) : (Quot.mk (@Setoid.r _ <| ÎŒ.aeEqSetoid β) ⟹f, hf⟩ : α →ₘ[ÎŒ] β) = mk f hf := rfl @[simp] theorem mk_eq_mk {f g : α → β} {hf hg} : (mk f hf : α →ₘ[ÎŒ] β) = mk g hg ↔ f =ᵐ[ÎŒ] g := Quotient.eq'' @[simp] theorem mk_coeFn (f : α →ₘ[ÎŒ] β) : mk f f.aestronglyMeasurable = f := by conv_lhs => simp only [cast] split_ifs with h · exact Classical.choose_spec h |>.symm conv_rhs => rw [← Quotient.out_eq' f] rw [← mk, mk_eq_mk] exact (AEStronglyMeasurable.ae_eq_mk _).symm @[ext] theorem ext {f g : α →ₘ[ÎŒ] β} (h : f =ᵐ[ÎŒ] g) : f = g := by rwa [← f.mk_coeFn, ← g.mk_coeFn, mk_eq_mk] theorem coeFn_mk (f : α → β) (hf) : (mk f hf : α →ₘ[ÎŒ] β) =ᵐ[ÎŒ] f := by rw [← mk_eq_mk, mk_coeFn] @[elab_as_elim] theorem induction_on (f : α →ₘ[ÎŒ] β) {p : (α →ₘ[ÎŒ] β) → Prop} (H : ∀ f hf, p (mk f hf)) : p f := Quotient.inductionOn' f <| Subtype.forall.2 H @[elab_as_elim] theorem induction_on₂ {α' β' : Type*} [MeasurableSpace α'] [TopologicalSpace β'] {ÎŒ' : Measure α'} (f : α →ₘ[ÎŒ] β) (f' : α' →ₘ[ÎŒ'] β') {p : (α →ₘ[ÎŒ] β) → (α' →ₘ[ÎŒ'] β') → Prop} (H : ∀ f hf f' hf', p (mk f hf) (mk f' hf')) : p f f' := induction_on f fun f hf => induction_on f' <| H f hf @[elab_as_elim] theorem induction_on₃ {α' β' : Type*} [MeasurableSpace α'] [TopologicalSpace β'] {ÎŒ' : Measure α'} {α'' β'' : Type*} [MeasurableSpace α''] [TopologicalSpace β''] {ÎŒ'' : Measure α''} (f : α →ₘ[ÎŒ] β) (f' : α' →ₘ[ÎŒ'] β') (f'' : α'' →ₘ[ÎŒ''] β'') {p : (α →ₘ[ÎŒ] β) → (α' →ₘ[ÎŒ'] β') → (α'' →ₘ[ÎŒ''] β'') → Prop} (H : ∀ f hf f' hf' f'' hf'', p (mk f hf) (mk f' hf') (mk f'' hf'')) : p f f' f'' := induction_on f fun f hf => induction_on₂ f' f'' <| H f hf end /-! ### Composition of an a.e. equal function with a (quasi) measure preserving function -/ section compQuasiMeasurePreserving variable [TopologicalSpace γ] [MeasurableSpace β] {Μ : MeasureTheory.Measure β} {f : α → β} open MeasureTheory.Measure (QuasiMeasurePreserving) /-- Composition of an almost everywhere equal function and a quasi measure preserving function. See also `AEEqFun.compMeasurePreserving`. -/ def compQuasiMeasurePreserving (g : β →ₘ[Μ] γ) (f : α → β) (hf : QuasiMeasurePreserving f ÎŒ Μ) : α →ₘ[ÎŒ] γ := Quotient.liftOn' g (fun g ↩ mk (g ∘ f) <| g.2.comp_quasiMeasurePreserving hf) fun _ _ h ↩ mk_eq_mk.2 <| h.comp_tendsto hf.tendsto_ae @[simp] theorem compQuasiMeasurePreserving_mk {g : β → γ} (hg : AEStronglyMeasurable g Μ) (hf : QuasiMeasurePreserving f ÎŒ Μ) : (mk g hg).compQuasiMeasurePreserving f hf = mk (g ∘ f) (hg.comp_quasiMeasurePreserving hf) := rfl theorem compQuasiMeasurePreserving_eq_mk (g : β →ₘ[Μ] γ) (hf : QuasiMeasurePreserving f ÎŒ Μ) : g.compQuasiMeasurePreserving f hf = mk (g ∘ f) (g.aestronglyMeasurable.comp_quasiMeasurePreserving hf) := by rw [← compQuasiMeasurePreserving_mk g.aestronglyMeasurable hf, mk_coeFn] theorem coeFn_compQuasiMeasurePreserving (g : β →ₘ[Μ] γ) (hf : QuasiMeasurePreserving f ÎŒ Μ) : g.compQuasiMeasurePreserving f hf =ᵐ[ÎŒ] g ∘ f := by rw [compQuasiMeasurePreserving_eq_mk] apply coeFn_mk end compQuasiMeasurePreserving section compMeasurePreserving variable [TopologicalSpace γ] [MeasurableSpace β] {Μ : MeasureTheory.Measure β} {f : α → β} {g : β → γ} /-- Composition of an almost everywhere equal function and a quasi measure preserving function. This is an important special case of `AEEqFun.compQuasiMeasurePreserving`. We use a separate definition so that lemmas that need `f` to be measure preserving can be `@[simp]` lemmas. -/ def compMeasurePreserving (g : β →ₘ[Μ] γ) (f : α → β) (hf : MeasurePreserving f ÎŒ Μ) : α →ₘ[ÎŒ] γ := g.compQuasiMeasurePreserving f hf.quasiMeasurePreserving @[simp] theorem compMeasurePreserving_mk (hg : AEStronglyMeasurable g Μ) (hf : MeasurePreserving f ÎŒ Μ) : (mk g hg).compMeasurePreserving f hf = mk (g ∘ f) (hg.comp_quasiMeasurePreserving hf.quasiMeasurePreserving) := rfl theorem compMeasurePreserving_eq_mk (g : β →ₘ[Μ] γ) (hf : MeasurePreserving f ÎŒ Μ) : g.compMeasurePreserving f hf = mk (g ∘ f) (g.aestronglyMeasurable.comp_quasiMeasurePreserving hf.quasiMeasurePreserving) := g.compQuasiMeasurePreserving_eq_mk _ theorem coeFn_compMeasurePreserving (g : β →ₘ[Μ] γ) (hf : MeasurePreserving f ÎŒ Μ) : g.compMeasurePreserving f hf =ᵐ[ÎŒ] g ∘ f := g.coeFn_compQuasiMeasurePreserving _ end compMeasurePreserving variable [TopologicalSpace β] [TopologicalSpace γ] /-- Given a continuous function `g : β → γ`, and an almost everywhere equal function `[f] : α →ₘ β`, return the equivalence class of `g ∘ f`, i.e., the almost everywhere equal function `[g ∘ f] : α →ₘ γ`. -/ def comp (g : β → γ) (hg : Continuous g) (f : α →ₘ[ÎŒ] β) : α →ₘ[ÎŒ] γ := Quotient.liftOn' f (fun f => mk (g ∘ (f : α → β)) (hg.comp_aestronglyMeasurable f.2)) fun _ _ H => mk_eq_mk.2 <| H.fun_comp g @[simp] theorem comp_mk (g : β → γ) (hg : Continuous g) (f : α → β) (hf) : comp g hg (mk f hf : α →ₘ[ÎŒ] β) = mk (g ∘ f) (hg.comp_aestronglyMeasurable hf) := rfl theorem comp_eq_mk (g : β → γ) (hg : Continuous g) (f : α →ₘ[ÎŒ] β) : comp g hg f = mk (g ∘ f) (hg.comp_aestronglyMeasurable f.aestronglyMeasurable) := by rw [← comp_mk g hg f f.aestronglyMeasurable, mk_coeFn] theorem coeFn_comp (g : β → γ) (hg : Continuous g) (f : α →ₘ[ÎŒ] β) : comp g hg f =ᵐ[ÎŒ] g ∘ f := by rw [comp_eq_mk] apply coeFn_mk theorem comp_compQuasiMeasurePreserving {β : Type*} [MeasurableSpace β] {Μ} (g : γ → ÎŽ) (hg : Continuous g) (f : β →ₘ[Μ] γ) {φ : α → β} (hφ : Measure.QuasiMeasurePreserving φ ÎŒ Μ) : (comp g hg f).compQuasiMeasurePreserving φ hφ = comp g hg (f.compQuasiMeasurePreserving φ hφ) := by rcases f; rfl section CompMeasurable variable [MeasurableSpace β] [PseudoMetrizableSpace β] [BorelSpace β] [MeasurableSpace γ] [PseudoMetrizableSpace γ] [OpensMeasurableSpace γ] [SecondCountableTopology γ] /-- Given a measurable function `g : β → γ`, and an almost everywhere equal function `[f] : α →ₘ β`, return the equivalence class of `g ∘ f`, i.e., the almost everywhere equal function `[g ∘ f] : α →ₘ γ`. This requires that `γ` has a second countable topology. -/ def compMeasurable (g : β → γ) (hg : Measurable g) (f : α →ₘ[ÎŒ] β) : α →ₘ[ÎŒ] γ := Quotient.liftOn' f (fun f' => mk (g ∘ (f' : α → β)) (hg.comp_aemeasurable f'.2.aemeasurable).aestronglyMeasurable) fun _ _ H => mk_eq_mk.2 <| H.fun_comp g @[simp] theorem compMeasurable_mk (g : β → γ) (hg : Measurable g) (f : α → β) (hf : AEStronglyMeasurable f ÎŒ) : compMeasurable g hg (mk f hf : α →ₘ[ÎŒ] β) = mk (g ∘ f) (hg.comp_aemeasurable hf.aemeasurable).aestronglyMeasurable := rfl theorem compMeasurable_eq_mk (g : β → γ) (hg : Measurable g) (f : α →ₘ[ÎŒ] β) : compMeasurable g hg f = mk (g ∘ f) (hg.comp_aemeasurable f.aemeasurable).aestronglyMeasurable := by rw [← compMeasurable_mk g hg f f.aestronglyMeasurable, mk_coeFn] theorem coeFn_compMeasurable (g : β → γ) (hg : Measurable g) (f : α →ₘ[ÎŒ] β) : compMeasurable g hg f =ᵐ[ÎŒ] g ∘ f := by rw [compMeasurable_eq_mk] apply coeFn_mk end CompMeasurable /-- The class of `x ↩ (f x, g x)`. -/ def pair (f : α →ₘ[ÎŒ] β) (g : α →ₘ[ÎŒ] γ) : α →ₘ[ÎŒ] β × γ := Quotient.liftOn₂' f g (fun f g => mk (fun x => (f.1 x, g.1 x)) (f.2.prodMk g.2)) fun _f _g _f' _g' Hf Hg => mk_eq_mk.2 <| Hf.prodMk Hg @[simp] theorem pair_mk_mk (f : α → β) (hf) (g : α → γ) (hg) : (mk f hf : α →ₘ[ÎŒ] β).pair (mk g hg) = mk (fun x => (f x, g x)) (hf.prodMk hg) := rfl theorem pair_eq_mk (f : α →ₘ[ÎŒ] β) (g : α →ₘ[ÎŒ] γ) : f.pair g = mk (fun x => (f x, g x)) (f.aestronglyMeasurable.prodMk g.aestronglyMeasurable) := by simp only [← pair_mk_mk, mk_coeFn, f.aestronglyMeasurable, g.aestronglyMeasurable] theorem coeFn_pair (f : α →ₘ[ÎŒ] β) (g : α →ₘ[ÎŒ] γ) : f.pair g =ᵐ[ÎŒ] fun x => (f x, g x) := by rw [pair_eq_mk] apply coeFn_mk /-- Given a continuous function `g : β → γ → ÎŽ`, and almost everywhere equal functions `[f₁] : α →ₘ β` and `[f₂] : α →ₘ γ`, return the equivalence class of the function `fun a => g (f₁ a) (f₂ a)`, i.e., the almost everywhere equal function `[fun a => g (f₁ a) (f₂ a)] : α →ₘ γ` -/ def comp₂ (g : β → γ → ÎŽ) (hg : Continuous (uncurry g)) (f₁ : α →ₘ[ÎŒ] β) (f₂ : α →ₘ[ÎŒ] γ) : α →ₘ[ÎŒ] ÎŽ := comp _ hg (f₁.pair f₂) @[simp] theorem comp₂_mk_mk (g : β → γ → ÎŽ) (hg : Continuous (uncurry g)) (f₁ : α → β) (f₂ : α → γ) (hf₁ hf₂) : comp₂ g hg (mk f₁ hf₁ : α →ₘ[ÎŒ] β) (mk f₂ hf₂) = mk (fun a => g (f₁ a) (f₂ a)) (hg.comp_aestronglyMeasurable (hf₁.prodMk hf₂)) := rfl theorem comp₂_eq_pair (g : β → γ → ÎŽ) (hg : Continuous (uncurry g)) (f₁ : α →ₘ[ÎŒ] β) (f₂ : α →ₘ[ÎŒ] γ) : comp₂ g hg f₁ f₂ = comp _ hg (f₁.pair f₂) := rfl theorem comp₂_eq_mk (g : β → γ → ÎŽ) (hg : Continuous (uncurry g)) (f₁ : α →ₘ[ÎŒ] β) (f₂ : α →ₘ[ÎŒ] γ) : comp₂ g hg f₁ f₂ = mk (fun a => g (f₁ a) (f₂ a)) (hg.comp_aestronglyMeasurable (f₁.aestronglyMeasurable.prodMk f₂.aestronglyMeasurable)) := by rw [comp₂_eq_pair, pair_eq_mk, comp_mk]; rfl theorem coeFn_comp₂ (g : β → γ → ÎŽ) (hg : Continuous (uncurry g)) (f₁ : α →ₘ[ÎŒ] β) (f₂ : α →ₘ[ÎŒ] γ) : comp₂ g hg f₁ f₂ =ᵐ[ÎŒ] fun a => g (f₁ a) (f₂ a) := by rw [comp₂_eq_mk] apply coeFn_mk section variable [MeasurableSpace β] [PseudoMetrizableSpace β] [BorelSpace β] [MeasurableSpace γ] [PseudoMetrizableSpace γ] [BorelSpace γ] [SecondCountableTopologyEither β γ] [MeasurableSpace ÎŽ] [PseudoMetrizableSpace ÎŽ] [OpensMeasurableSpace ÎŽ] [SecondCountableTopology ÎŽ] /-- Given a measurable function `g : β → γ → ÎŽ`, and almost everywhere equal functions `[f₁] : α →ₘ β` and `[f₂] : α →ₘ γ`, return the equivalence class of the function `fun a => g (f₁ a) (f₂ a)`, i.e., the almost everywhere equal function `[fun a => g (f₁ a) (f₂ a)] : α →ₘ γ`. This requires `ÎŽ` to have second-countable topology. -/ def comp₂Measurable (g : β → γ → ÎŽ) (hg : Measurable (uncurry g)) (f₁ : α →ₘ[ÎŒ] β) (f₂ : α →ₘ[ÎŒ] γ) : α →ₘ[ÎŒ] ÎŽ := compMeasurable _ hg (f₁.pair f₂) @[simp] theorem comp₂Measurable_mk_mk (g : β → γ → ÎŽ) (hg : Measurable (uncurry g)) (f₁ : α → β) (f₂ : α → γ) (hf₁ hf₂) : comp₂Measurable g hg (mk f₁ hf₁ : α →ₘ[ÎŒ] β) (mk f₂ hf₂) = mk (fun a => g (f₁ a) (f₂ a)) (hg.comp_aemeasurable (hf₁.aemeasurable.prodMk hf₂.aemeasurable)).aestronglyMeasurable := rfl theorem comp₂Measurable_eq_pair (g : β → γ → ÎŽ) (hg : Measurable (uncurry g)) (f₁ : α →ₘ[ÎŒ] β) (f₂ : α →ₘ[ÎŒ] γ) : comp₂Measurable g hg f₁ f₂ = compMeasurable _ hg (f₁.pair f₂) := rfl theorem comp₂Measurable_eq_mk (g : β → γ → ÎŽ) (hg : Measurable (uncurry g)) (f₁ : α →ₘ[ÎŒ] β) (f₂ : α →ₘ[ÎŒ] γ) : comp₂Measurable g hg f₁ f₂ = mk (fun a => g (f₁ a) (f₂ a)) (hg.comp_aemeasurable (f₁.aemeasurable.prodMk f₂.aemeasurable)).aestronglyMeasurable := by rw [comp₂Measurable_eq_pair, pair_eq_mk, compMeasurable_mk]; rfl theorem coeFn_comp₂Measurable (g : β → γ → ÎŽ) (hg : Measurable (uncurry g)) (f₁ : α →ₘ[ÎŒ] β) (f₂ : α →ₘ[ÎŒ] γ) : comp₂Measurable g hg f₁ f₂ =ᵐ[ÎŒ] fun a => g (f₁ a) (f₂ a) := by rw [comp₂Measurable_eq_mk] apply coeFn_mk end /-- Interpret `f : α →ₘ[ÎŒ] β` as a germ at `ae ÎŒ` forgetting that `f` is almost everywhere strongly measurable. -/ def toGerm (f : α →ₘ[ÎŒ] β) : Germ (ae ÎŒ) β := Quotient.liftOn' f (fun f => ((f : α → β) : Germ (ae ÎŒ) β)) fun _ _ H => Germ.coe_eq.2 H @[simp] theorem mk_toGerm (f : α → β) (hf) : (mk f hf : α →ₘ[ÎŒ] β).toGerm = f := rfl theorem toGerm_eq (f : α →ₘ[ÎŒ] β) : f.toGerm = (f : α → β) := by rw [← mk_toGerm, mk_coeFn] theorem toGerm_injective : Injective (toGerm : (α →ₘ[ÎŒ] β) → Germ (ae ÎŒ) β) := fun f g H => ext <| Germ.coe_eq.1 <| by rwa [← toGerm_eq, ← toGerm_eq] @[simp] theorem compQuasiMeasurePreserving_toGerm {β : Type*} [MeasurableSpace β] {f : α → β} {Μ} (g : β →ₘ[Μ] γ) (hf : Measure.QuasiMeasurePreserving f ÎŒ Μ) : (g.compQuasiMeasurePreserving f hf).toGerm = g.toGerm.compTendsto f hf.tendsto_ae := by rcases g; rfl @[simp] theorem compMeasurePreserving_toGerm {β : Type*} [MeasurableSpace β] {f : α → β} {Μ} (g : β →ₘ[Μ] γ) (hf : MeasurePreserving f ÎŒ Μ) : (g.compMeasurePreserving f hf).toGerm = g.toGerm.compTendsto f hf.quasiMeasurePreserving.tendsto_ae := compQuasiMeasurePreserving_toGerm _ _ theorem comp_toGerm (g : β → γ) (hg : Continuous g) (f : α →ₘ[ÎŒ] β) : (comp g hg f).toGerm = f.toGerm.map g := induction_on f fun f _ => by simp theorem compMeasurable_toGerm [MeasurableSpace β] [BorelSpace β] [PseudoMetrizableSpace β] [PseudoMetrizableSpace γ] [SecondCountableTopology γ] [MeasurableSpace γ] [OpensMeasurableSpace γ] (g : β → γ) (hg : Measurable g) (f : α →ₘ[ÎŒ] β) : (compMeasurable g hg f).toGerm = f.toGerm.map g := induction_on f fun f _ => by simp theorem comp₂_toGerm (g : β → γ → ÎŽ) (hg : Continuous (uncurry g)) (f₁ : α →ₘ[ÎŒ] β) (f₂ : α →ₘ[ÎŒ] γ) : (comp₂ g hg f₁ f₂).toGerm = f₁.toGerm.map₂ g f₂.toGerm := induction_on₂ f₁ f₂ fun f₁ _ f₂ _ => by simp theorem comp₂Measurable_toGerm [PseudoMetrizableSpace β] [MeasurableSpace β] [BorelSpace β] [PseudoMetrizableSpace γ] [SecondCountableTopologyEither β γ] [MeasurableSpace γ] [BorelSpace γ] [PseudoMetrizableSpace ÎŽ] [SecondCountableTopology ÎŽ] [MeasurableSpace ÎŽ] [OpensMeasurableSpace ÎŽ] (g : β → γ → ÎŽ) (hg : Measurable (uncurry g)) (f₁ : α →ₘ[ÎŒ] β) (f₂ : α →ₘ[ÎŒ] γ) : (comp₂Measurable g hg f₁ f₂).toGerm = f₁.toGerm.map₂ g f₂.toGerm := induction_on₂ f₁ f₂ fun f₁ _ f₂ _ => by simp /-- Given a predicate `p` and an equivalence class `[f]`, return true if `p` holds of `f a` for almost all `a` -/ def LiftPred (p : β → Prop) (f : α →ₘ[ÎŒ] β) : Prop := f.toGerm.LiftPred p /-- Given a relation `r` and equivalence class `[f]` and `[g]`, return true if `r` holds of `(f a, g a)` for almost all `a` -/ def LiftRel (r : β → γ → Prop) (f : α →ₘ[ÎŒ] β) (g : α →ₘ[ÎŒ] γ) : Prop := f.toGerm.LiftRel r g.toGerm theorem liftRel_mk_mk {r : β → γ → Prop} {f : α → β} {g : α → γ} {hf hg} : LiftRel r (mk f hf : α →ₘ[ÎŒ] β) (mk g hg) ↔ ∀ᵐ a ∂Ό, r (f a) (g a) := Iff.rfl
theorem liftRel_iff_coeFn {r : β → γ → Prop} {f : α →ₘ[ÎŒ] β} {g : α →ₘ[ÎŒ] γ} : LiftRel r f g ↔ ∀ᵐ a ∂Ό, r (f a) (g a) := by rw [← liftRel_mk_mk, mk_coeFn, mk_coeFn] section Order
Mathlib/MeasureTheory/Function/AEEqFun.lean
472
476
/- 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.
Mathlib/LinearAlgebra/PiTensorProduct.lean
629
631
/- Copyright (c) 2022 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Topology.MetricSpace.HausdorffDistance /-! # Topological study of spaces `Π (n : ℕ), E n` When `E n` are topological spaces, the space `Π (n : ℕ), E n` is naturally a topological space (with the product topology). When `E n` are uniform spaces, it also inherits a uniform structure. However, it does not inherit a canonical metric space structure of the `E n`. Nevertheless, one can put a noncanonical metric space structure (or rather, several of them). This is done in this file. ## Main definitions and results One can define a combinatorial distance on `Π (n : ℕ), E n`, as follows: * `PiNat.cylinder x n` is the set of points `y` with `x i = y i` for `i < n`. * `PiNat.firstDiff x y` is the first index at which `x i ≠ y i`. * `PiNat.dist x y` is equal to `(1/2) ^ (firstDiff x y)`. It defines a distance on `Π (n : ℕ), E n`, compatible with the topology when the `E n` have the discrete topology. * `PiNat.metricSpace`: the metric space structure, given by this distance. Not registered as an instance. This space is a complete metric space. * `PiNat.metricSpaceOfDiscreteUniformity`: the same metric space structure, but adjusting the uniformity defeqness when the `E n` already have the discrete uniformity. Not registered as an instance * `PiNat.metricSpaceNatNat`: the particular case of `ℕ → ℕ`, not registered as an instance. These results are used to construct continuous functions on `Π n, E n`: * `PiNat.exists_retraction_of_isClosed`: given a nonempty closed subset `s` of `Π (n : ℕ), E n`, there exists a retraction onto `s`, i.e., a continuous map from the whole space to `s` restricting to the identity on `s`. * `exists_nat_nat_continuous_surjective_of_completeSpace`: given any nonempty complete metric space with second-countable topology, there exists a continuous surjection from `ℕ → ℕ` onto this space. One can also put distances on `Π (i : ι), E i` when the spaces `E i` are metric spaces (not discrete in general), and `ι` is countable. * `PiCountable.dist` is the distance on `Π i, E i` given by `dist x y = ∑' i, min (1/2)^(encode i) (dist (x i) (y i))`. * `PiCountable.metricSpace` is the corresponding metric space structure, adjusted so that the uniformity is definitionally the product uniformity. Not registered as an instance. -/ noncomputable section open Topology TopologicalSpace Set Metric Filter Function attribute [local simp] pow_le_pow_iff_right₀ one_lt_two inv_le_inv₀ zero_le_two zero_lt_two variable {E : ℕ → Type*} namespace PiNat /-! ### The firstDiff function -/ open Classical in /-- In a product space `Π n, E n`, then `firstDiff x y` is the first index at which `x` and `y` differ. If `x = y`, then by convention we set `firstDiff x x = 0`. -/ irreducible_def firstDiff (x y : ∀ n, E n) : ℕ := if h : x ≠ y then Nat.find (ne_iff.1 h) else 0 theorem apply_firstDiff_ne {x y : ∀ n, E n} (h : x ≠ y) : x (firstDiff x y) ≠ y (firstDiff x y) := by rw [firstDiff_def, dif_pos h] classical exact Nat.find_spec (ne_iff.1 h) theorem apply_eq_of_lt_firstDiff {x y : ∀ n, E n} {n : ℕ} (hn : n < firstDiff x y) : x n = y n := by rw [firstDiff_def] at hn split_ifs at hn with h · convert Nat.find_min (ne_iff.1 h) hn simp · exact (not_lt_zero' hn).elim theorem firstDiff_comm (x y : ∀ n, E n) : firstDiff x y = firstDiff y x := by classical simp only [firstDiff_def, ne_comm] theorem min_firstDiff_le (x y z : ∀ n, E n) (h : x ≠ z) : min (firstDiff x y) (firstDiff y z) ≀ firstDiff x z := by by_contra! H rw [lt_min_iff] at H refine apply_firstDiff_ne h ?_ calc x (firstDiff x z) = y (firstDiff x z) := apply_eq_of_lt_firstDiff H.1 _ = z (firstDiff x z) := apply_eq_of_lt_firstDiff H.2 /-! ### Cylinders -/ /-- In a product space `Π n, E n`, the cylinder set of length `n` around `x`, denoted `cylinder x n`, is the set of sequences `y` that coincide with `x` on the first `n` symbols, i.e., such that `y i = x i` for all `i < n`. -/ def cylinder (x : ∀ n, E n) (n : ℕ) : Set (∀ n, E n) := { y | ∀ i, i < n → y i = x i } theorem cylinder_eq_pi (x : ∀ n, E n) (n : ℕ) : cylinder x n = Set.pi (Finset.range n : Set ℕ) fun i : ℕ => {x i} := by ext y simp [cylinder] @[simp] theorem cylinder_zero (x : ∀ n, E n) : cylinder x 0 = univ := by simp [cylinder_eq_pi] theorem cylinder_anti (x : ∀ n, E n) {m n : ℕ} (h : m ≀ n) : cylinder x n ⊆ cylinder x m := fun _y hy i hi => hy i (hi.trans_le h) @[simp] theorem mem_cylinder_iff {x y : ∀ n, E n} {n : ℕ} : y ∈ cylinder x n ↔ ∀ i < n, y i = x i := Iff.rfl theorem self_mem_cylinder (x : ∀ n, E n) (n : ℕ) : x ∈ cylinder x n := by simp theorem mem_cylinder_iff_eq {x y : ∀ n, E n} {n : ℕ} : y ∈ cylinder x n ↔ cylinder y n = cylinder x n := by constructor · intro hy apply Subset.antisymm · intro z hz i hi rw [← hy i hi] exact hz i hi · intro z hz i hi rw [hy i hi] exact hz i hi · intro h rw [← h] exact self_mem_cylinder _ _ theorem mem_cylinder_comm (x y : ∀ n, E n) (n : ℕ) : y ∈ cylinder x n ↔ x ∈ cylinder y n := by simp [mem_cylinder_iff_eq, eq_comm] theorem mem_cylinder_iff_le_firstDiff {x y : ∀ n, E n} (hne : x ≠ y) (i : ℕ) : x ∈ cylinder y i ↔ i ≀ firstDiff x y := by constructor · intro h by_contra! exact apply_firstDiff_ne hne (h _ this) · intro hi j hj exact apply_eq_of_lt_firstDiff (hj.trans_le hi) theorem mem_cylinder_firstDiff (x y : ∀ n, E n) : x ∈ cylinder y (firstDiff x y) := fun _i hi => apply_eq_of_lt_firstDiff hi theorem cylinder_eq_cylinder_of_le_firstDiff (x y : ∀ n, E n) {n : ℕ} (hn : n ≀ firstDiff x y) : cylinder x n = cylinder y n := by rw [← mem_cylinder_iff_eq] intro i hi exact apply_eq_of_lt_firstDiff (hi.trans_le hn) theorem iUnion_cylinder_update (x : ∀ n, E n) (n : ℕ) : ⋃ k, cylinder (update x n k) (n + 1) = cylinder x n := by ext y simp only [mem_cylinder_iff, mem_iUnion] constructor · rintro ⟹k, hk⟩ i hi simpa [hi.ne] using hk i (Nat.lt_succ_of_lt hi) · intro H refine ⟹y n, fun i hi => ?_⟩ rcases Nat.lt_succ_iff_lt_or_eq.1 hi with (h'i | rfl) · simp [H i h'i, h'i.ne] · simp theorem update_mem_cylinder (x : ∀ n, E n) (n : ℕ) (y : E n) : update x n y ∈ cylinder x n := mem_cylinder_iff.2 fun i hi => by simp [hi.ne] section Res variable {α : Type*} open List /-- In the case where `E` has constant value `α`, the cylinder `cylinder x n` can be identified with the element of `List α` consisting of the first `n` entries of `x`. See `cylinder_eq_res`. We call this list `res x n`, the restriction of `x` to `n`. -/ def res (x : ℕ → α) : ℕ → List α | 0 => nil | Nat.succ n => x n :: res x n @[simp] theorem res_zero (x : ℕ → α) : res x 0 = @nil α := rfl @[simp] theorem res_succ (x : ℕ → α) (n : ℕ) : res x n.succ = x n :: res x n := rfl @[simp] theorem res_length (x : ℕ → α) (n : ℕ) : (res x n).length = n := by induction n <;> simp [*] /-- The restrictions of `x` and `y` to `n` are equal if and only if `x m = y m` for all `m < n`. -/ theorem res_eq_res {x y : ℕ → α} {n : ℕ} : res x n = res y n ↔ ∀ ⊃m⩄, m < n → x m = y m := by constructor <;> intro h · induction n with | zero => simp | succ n ih => intro m hm rw [Nat.lt_succ_iff_lt_or_eq] at hm simp only [res_succ, cons.injEq] at h rcases hm with hm | hm · exact ih h.2 hm rw [hm] exact h.1 · induction n with | zero => simp | succ n ih => simp only [res_succ, cons.injEq] refine ⟹h (Nat.lt_succ_self _), ih fun m hm => ?_⟩ exact h (hm.trans (Nat.lt_succ_self _)) theorem res_injective : Injective (@res α) := by intro x y h ext n apply res_eq_res.mp _ (Nat.lt_succ_self _) rw [h] /-- `cylinder x n` is equal to the set of sequences `y` with the same restriction to `n` as `x`. -/ theorem cylinder_eq_res (x : ℕ → α) (n : ℕ) : cylinder x n = { y | res y n = res x n } := by ext y dsimp [cylinder] rw [res_eq_res] end Res /-! ### A distance function on `Π n, E n` We define a distance function on `Π n, E n`, given by `dist x y = (1/2)^n` where `n` is the first index at which `x` and `y` differ. When each `E n` has the discrete topology, this distance will define the right topology on the product space. We do not record a global `Dist` instance nor a `MetricSpace` instance, as other distances may be used on these spaces, but we register them as local instances in this section. -/ open Classical in /-- The distance function on a product space `Π n, E n`, given by `dist x y = (1/2)^n` where `n` is the first index at which `x` and `y` differ. -/ protected def dist : Dist (∀ n, E n) := ⟹fun x y => if x ≠ y then (1 / 2 : ℝ) ^ firstDiff x y else 0⟩ attribute [local instance] PiNat.dist theorem dist_eq_of_ne {x y : ∀ n, E n} (h : x ≠ y) : dist x y = (1 / 2 : ℝ) ^ firstDiff x y := by simp [dist, h] protected theorem dist_self (x : ∀ n, E n) : dist x x = 0 := by simp [dist] protected theorem dist_comm (x y : ∀ n, E n) : dist x y = dist y x := by classical simp [dist, @eq_comm _ x y, firstDiff_comm] protected theorem dist_nonneg (x y : ∀ n, E n) : 0 ≀ dist x y := by rcases eq_or_ne x y with (rfl | h) · simp [dist] · simp [dist, h, zero_le_two] theorem dist_triangle_nonarch (x y z : ∀ n, E n) : dist x z ≀ max (dist x y) (dist y z) := by rcases eq_or_ne x z with (rfl | hxz) · simp [PiNat.dist_self x, PiNat.dist_nonneg] rcases eq_or_ne x y with (rfl | hxy) · simp rcases eq_or_ne y z with (rfl | hyz) · simp simp only [dist_eq_of_ne, hxz, hxy, hyz, inv_le_inv₀, one_div, inv_pow, zero_lt_two, Ne, not_false_iff, le_max_iff, pow_le_pow_iff_right₀, one_lt_two, pow_pos, min_le_iff.1 (min_firstDiff_le x y z hxz)] protected theorem dist_triangle (x y z : ∀ n, E n) : dist x z ≀ dist x y + dist y z := calc dist x z ≀ max (dist x y) (dist y z) := dist_triangle_nonarch x y z _ ≀ dist x y + dist y z := max_le_add_of_nonneg (PiNat.dist_nonneg _ _) (PiNat.dist_nonneg _ _) protected theorem eq_of_dist_eq_zero (x y : ∀ n, E n) (hxy : dist x y = 0) : x = y := by rcases eq_or_ne x y with (rfl | h); · rfl simp [dist_eq_of_ne h] at hxy theorem mem_cylinder_iff_dist_le {x y : ∀ n, E n} {n : ℕ} : y ∈ cylinder x n ↔ dist y x ≀ (1 / 2) ^ n := by rcases eq_or_ne y x with (rfl | hne) · simp [PiNat.dist_self] suffices (∀ i : ℕ, i < n → y i = x i) ↔ n ≀ firstDiff y x by simpa [dist_eq_of_ne hne] constructor · intro hy by_contra! H exact apply_firstDiff_ne hne (hy _ H) · intro h i hi exact apply_eq_of_lt_firstDiff (hi.trans_le h) theorem apply_eq_of_dist_lt {x y : ∀ n, E n} {n : ℕ} (h : dist x y < (1 / 2) ^ n) {i : ℕ} (hi : i ≀ n) : x i = y i := by rcases eq_or_ne x y with (rfl | hne) · rfl have : n < firstDiff x y := by simpa [dist_eq_of_ne hne, inv_lt_inv₀, pow_lt_pow_iff_right₀, one_lt_two] using h exact apply_eq_of_lt_firstDiff (hi.trans_lt this) /-- A function to a pseudo-metric-space is `1`-Lipschitz if and only if points in the same cylinder of length `n` are sent to points within distance `(1/2)^n`. Not expressed using `LipschitzWith` as we don't have a metric space structure -/ theorem lipschitz_with_one_iff_forall_dist_image_le_of_mem_cylinder {α : Type*} [PseudoMetricSpace α] {f : (∀ n, E n) → α} : (∀ x y : ∀ n, E n, dist (f x) (f y) ≀ dist x y) ↔ ∀ x y n, y ∈ cylinder x n → dist (f x) (f y) ≀ (1 / 2) ^ n := by constructor · intro H x y n hxy apply (H x y).trans rw [PiNat.dist_comm] exact mem_cylinder_iff_dist_le.1 hxy · intro H x y rcases eq_or_ne x y with (rfl | hne) · simp [PiNat.dist_nonneg] rw [dist_eq_of_ne hne] apply H x y (firstDiff x y) rw [firstDiff_comm] exact mem_cylinder_firstDiff _ _ variable (E) variable [∀ n, TopologicalSpace (E n)] [∀ n, DiscreteTopology (E n)] theorem isOpen_cylinder (x : ∀ n, E n) (n : ℕ) : IsOpen (cylinder x n) := by rw [PiNat.cylinder_eq_pi] exact isOpen_set_pi (Finset.range n).finite_toSet fun a _ => isOpen_discrete _ theorem isTopologicalBasis_cylinders : IsTopologicalBasis { s : Set (∀ n, E n) | ∃ (x : ∀ n, E n) (n : ℕ), s = cylinder x n } := by apply isTopologicalBasis_of_isOpen_of_nhds · rintro u ⟹x, n, rfl⟩ apply isOpen_cylinder · intro x u hx u_open obtain ⟹v, ⟹U, F, -, rfl⟩, xU, Uu⟩ : ∃ v ∈ { S : Set (∀ i : ℕ, E i) | ∃ (U : ∀ i : ℕ, Set (E i)) (F : Finset ℕ), (∀ i : ℕ, i ∈ F → U i ∈ { s : Set (E i) | IsOpen s }) ∧ S = (F : Set ℕ).pi U }, x ∈ v ∧ v ⊆ u := (isTopologicalBasis_pi fun n : ℕ => isTopologicalBasis_opens).exists_subset_of_mem_open hx u_open rcases Finset.bddAbove F with ⟹n, hn⟩ refine ⟹cylinder x (n + 1), ⟹x, n + 1, rfl⟩, self_mem_cylinder _ _, Subset.trans ?_ Uu⟩ intro y hy suffices ∀ i : ℕ, i ∈ F → y i ∈ U i by simpa intro i hi have : y i = x i := mem_cylinder_iff.1 hy i ((hn hi).trans_lt (lt_add_one n)) rw [this] simp only [Set.mem_pi, Finset.mem_coe] at xU exact xU i hi variable {E} theorem isOpen_iff_dist (s : Set (∀ n, E n)) : IsOpen s ↔ ∀ x ∈ s, ∃ ε > 0, ∀ y, dist x y < ε → y ∈ s := by constructor · intro hs x hx obtain ⟹v, ⟹y, n, rfl⟩, h'x, h's⟩ : ∃ v ∈ { s | ∃ (x : ∀ n : ℕ, E n) (n : ℕ), s = cylinder x n }, x ∈ v ∧ v ⊆ s := (isTopologicalBasis_cylinders E).exists_subset_of_mem_open hx hs rw [← mem_cylinder_iff_eq.1 h'x] at h's exact ⟹(1 / 2 : ℝ) ^ n, by simp, fun y hy => h's fun i hi => (apply_eq_of_dist_lt hy hi.le).symm⟩ · intro h refine (isTopologicalBasis_cylinders E).isOpen_iff.2 fun x hx => ?_ rcases h x hx with ⟚ε, εpos, hε⟩ obtain ⟹n, hn⟩ : ∃ n : ℕ, (1 / 2 : ℝ) ^ n < ε := exists_pow_lt_of_lt_one εpos one_half_lt_one refine ⟹cylinder x n, ⟹x, n, rfl⟩, self_mem_cylinder x n, fun y hy => hε y ?_⟩ rw [PiNat.dist_comm] exact (mem_cylinder_iff_dist_le.1 hy).trans_lt hn /-- Metric space structure on `Π (n : ℕ), E n` when the spaces `E n` have the discrete topology, where the distance is given by `dist x y = (1/2)^n`, where `n` is the smallest index where `x` and `y` differ. Not registered as a global instance by default. Warning: this definition makes sure that the topology is defeq to the original product topology, but it does not take care of a possible uniformity. If the `E n` have a uniform structure, then there will be two non-defeq uniform structures on `Π n, E n`, the product one and the one coming from the metric structure. In this case, use `metricSpaceOfDiscreteUniformity` instead. -/ protected def metricSpace : MetricSpace (∀ n, E n) := MetricSpace.ofDistTopology dist PiNat.dist_self PiNat.dist_comm PiNat.dist_triangle isOpen_iff_dist PiNat.eq_of_dist_eq_zero /-- Metric space structure on `Π (n : ℕ), E n` when the spaces `E n` have the discrete uniformity, where the distance is given by `dist x y = (1/2)^n`, where `n` is the smallest index where `x` and `y` differ. Not registered as a global instance by default. -/ protected def metricSpaceOfDiscreteUniformity {E : ℕ → Type*} [∀ n, UniformSpace (E n)] (h : ∀ n, uniformity (E n) = 𝓟 idRel) : MetricSpace (∀ n, E n) := haveI : ∀ n, DiscreteTopology (E n) := fun n => discreteTopology_of_discrete_uniformity (h n) { dist_triangle := PiNat.dist_triangle dist_comm := PiNat.dist_comm dist_self := PiNat.dist_self eq_of_dist_eq_zero := PiNat.eq_of_dist_eq_zero _ _ toUniformSpace := Pi.uniformSpace _ uniformity_dist := by simp only [Pi.uniformity, h, idRel, comap_principal, preimage_setOf_eq] apply le_antisymm · simp only [le_iInf_iff, le_principal_iff] intro ε εpos obtain ⟹n, hn⟩ : ∃ n, (1 / 2 : ℝ) ^ n < ε := exists_pow_lt_of_lt_one εpos (by norm_num) apply @mem_iInf_of_iInter _ _ _ _ _ (Finset.range n).finite_toSet fun i => { p : (∀ n : ℕ, E n) × ∀ n : ℕ, E n | p.fst i = p.snd i } · simp only [mem_principal, setOf_subset_setOf, imp_self, imp_true_iff] · rintro ⟹x, y⟩ hxy simp only [Finset.mem_coe, Finset.mem_range, iInter_coe_set, mem_iInter, mem_setOf_eq] at hxy apply lt_of_le_of_lt _ hn rw [← mem_cylinder_iff_dist_le, mem_cylinder_iff] exact hxy · simp only [le_iInf_iff, le_principal_iff] intro n refine mem_iInf_of_mem ((1 / 2) ^ n : ℝ) ?_ refine mem_iInf_of_mem (by positivity) ?_ simp only [mem_principal, setOf_subset_setOf, Prod.forall] intro x y hxy exact apply_eq_of_dist_lt hxy le_rfl } /-- Metric space structure on `ℕ → ℕ` where the distance is given by `dist x y = (1/2)^n`, where `n` is the smallest index where `x` and `y` differ. Not registered as a global instance by default. -/ def metricSpaceNatNat : MetricSpace (ℕ → ℕ) := PiNat.metricSpaceOfDiscreteUniformity fun _ => rfl attribute [local instance] PiNat.metricSpace protected theorem completeSpace : CompleteSpace (∀ n, E n) := by refine Metric.complete_of_convergent_controlled_sequences (fun n => (1 / 2) ^ n) (by simp) ?_ intro u hu refine ⟹fun n => u n n, tendsto_pi_nhds.2 fun i => ?_⟩ refine tendsto_const_nhds.congr' ?_ filter_upwards [Filter.Ici_mem_atTop i] with n hn exact apply_eq_of_dist_lt (hu i i n le_rfl hn) le_rfl /-! ### Retractions inside product spaces We show that, in a space `Π (n : ℕ), E n` where each `E n` is discrete, there is a retraction on any closed nonempty subset `s`, i.e., a continuous map `f` from the whole space to `s` restricting to the identity on `s`. The map `f` is defined as follows. For `x ∈ s`, let `f x = x`. Otherwise, consider the longest prefix `w` that `x` shares with an element of `s`, and let `f x = z_w` where `z_w` is an element of `s` starting with `w`. -/ theorem exists_disjoint_cylinder {s : Set (∀ n, E n)} (hs : IsClosed s) {x : ∀ n, E n} (hx : x ∉ s) : ∃ n, Disjoint s (cylinder x n) := by rcases eq_empty_or_nonempty s with (rfl | hne) · exact ⟹0, by simp⟩ have A : 0 < infDist x s := (hs.not_mem_iff_infDist_pos hne).1 hx obtain ⟹n, hn⟩ : ∃ n, (1 / 2 : ℝ) ^ n < infDist x s := exists_pow_lt_of_lt_one A one_half_lt_one refine ⟹n, disjoint_left.2 fun y ys hy => ?_⟩ apply lt_irrefl (infDist x s) calc infDist x s ≀ dist x y := infDist_le_dist_of_mem ys _ ≀ (1 / 2) ^ n := by rw [mem_cylinder_comm] at hy exact mem_cylinder_iff_dist_le.1 hy _ < infDist x s := hn open Classical in /-- Given a point `x` in a product space `Π (n : ℕ), E n`, and `s` a subset of this space, then `shortestPrefixDiff x s` if the smallest `n` for which there is no element of `s` having the same prefix of length `n` as `x`. If there is no such `n`, then use `0` by convention. -/ def shortestPrefixDiff {E : ℕ → Type*} (x : ∀ n, E n) (s : Set (∀ n, E n)) : ℕ := if h : ∃ n, Disjoint s (cylinder x n) then Nat.find h else 0 theorem firstDiff_lt_shortestPrefixDiff {s : Set (∀ n, E n)} (hs : IsClosed s) {x y : ∀ n, E n} (hx : x ∉ s) (hy : y ∈ s) : firstDiff x y < shortestPrefixDiff x s := by have A := exists_disjoint_cylinder hs hx rw [shortestPrefixDiff, dif_pos A] classical have B := Nat.find_spec A contrapose! B rw [not_disjoint_iff_nonempty_inter] refine ⟹y, hy, ?_⟩ rw [mem_cylinder_comm] exact cylinder_anti y B (mem_cylinder_firstDiff x y) theorem shortestPrefixDiff_pos {s : Set (∀ n, E n)} (hs : IsClosed s) (hne : s.Nonempty) {x : ∀ n, E n} (hx : x ∉ s) : 0 < shortestPrefixDiff x s := by rcases hne with ⟹y, hy⟩ exact (zero_le _).trans_lt (firstDiff_lt_shortestPrefixDiff hs hx hy) /-- Given a point `x` in a product space `Π (n : ℕ), E n`, and `s` a subset of this space, then `longestPrefix x s` if the largest `n` for which there is an element of `s` having the same prefix of length `n` as `x`. If there is no such `n`, use `0` by convention. -/ def longestPrefix {E : ℕ → Type*} (x : ∀ n, E n) (s : Set (∀ n, E n)) : ℕ := shortestPrefixDiff x s - 1 theorem firstDiff_le_longestPrefix {s : Set (∀ n, E n)} (hs : IsClosed s) {x y : ∀ n, E n} (hx : x ∉ s) (hy : y ∈ s) : firstDiff x y ≀ longestPrefix x s := by rw [longestPrefix, le_tsub_iff_right] · exact firstDiff_lt_shortestPrefixDiff hs hx hy · exact shortestPrefixDiff_pos hs ⟹y, hy⟩ hx theorem inter_cylinder_longestPrefix_nonempty {s : Set (∀ n, E n)} (hs : IsClosed s) (hne : s.Nonempty) (x : ∀ n, E n) : (s ∩ cylinder x (longestPrefix x s)).Nonempty := by by_cases hx : x ∈ s · exact ⟹x, hx, self_mem_cylinder _ _⟩ have A := exists_disjoint_cylinder hs hx have B : longestPrefix x s < shortestPrefixDiff x s := Nat.pred_lt (shortestPrefixDiff_pos hs hne hx).ne' rw [longestPrefix, shortestPrefixDiff, dif_pos A] at B ⊢ classical obtain ⟹y, ys, hy⟩ : ∃ y : ∀ n : ℕ, E n, y ∈ s ∧ x ∈ cylinder y (Nat.find A - 1) := by simpa only [not_disjoint_iff, mem_cylinder_comm] using Nat.find_min A B refine ⟹y, ys, ?_⟩ rw [mem_cylinder_iff_eq] at hy ⊢ rw [hy] theorem disjoint_cylinder_of_longestPrefix_lt {s : Set (∀ n, E n)} (hs : IsClosed s) {x : ∀ n, E n} (hx : x ∉ s) {n : ℕ} (hn : longestPrefix x s < n) : Disjoint s (cylinder x n) := by contrapose! hn rcases not_disjoint_iff_nonempty_inter.1 hn with ⟹y, ys, hy⟩ apply le_trans _ (firstDiff_le_longestPrefix hs hx ys) apply (mem_cylinder_iff_le_firstDiff (ne_of_mem_of_not_mem ys hx).symm _).1 rwa [mem_cylinder_comm] /-- If two points `x, y` coincide up to length `n`, and the longest common prefix of `x` with `s` is strictly shorter than `n`, then the longest common prefix of `y` with `s` is the same, and both cylinders of this length based at `x` and `y` coincide. -/ theorem cylinder_longestPrefix_eq_of_longestPrefix_lt_firstDiff {x y : ∀ n, E n} {s : Set (∀ n, E n)} (hs : IsClosed s) (hne : s.Nonempty) (H : longestPrefix x s < firstDiff x y) (xs : x ∉ s) (ys : y ∉ s) : cylinder x (longestPrefix x s) = cylinder y (longestPrefix y s) := by have l_eq : longestPrefix y s = longestPrefix x s := by rcases lt_trichotomy (longestPrefix y s) (longestPrefix x s) with (L | L | L) · have Ax : (s ∩ cylinder x (longestPrefix x s)).Nonempty := inter_cylinder_longestPrefix_nonempty hs hne x have Z := disjoint_cylinder_of_longestPrefix_lt hs ys L rw [firstDiff_comm] at H rw [cylinder_eq_cylinder_of_le_firstDiff _ _ H.le] at Z exact (Ax.not_disjoint Z).elim · exact L · have Ay : (s ∩ cylinder y (longestPrefix y s)).Nonempty := inter_cylinder_longestPrefix_nonempty hs hne y have A'y : (s ∩ cylinder y (longestPrefix x s).succ).Nonempty := Ay.mono (inter_subset_inter_right s (cylinder_anti _ L)) have Z := disjoint_cylinder_of_longestPrefix_lt hs xs (Nat.lt_succ_self _) rw [cylinder_eq_cylinder_of_le_firstDiff _ _ H] at Z exact (A'y.not_disjoint Z).elim rw [l_eq, ← mem_cylinder_iff_eq] exact cylinder_anti y H.le (mem_cylinder_firstDiff x y) /-- Given a closed nonempty subset `s` of `Π (n : ℕ), E n`, there exists a Lipschitz retraction onto this set, i.e., a Lipschitz map with range equal to `s`, equal to the identity on `s`. -/ theorem exists_lipschitz_retraction_of_isClosed {s : Set (∀ n, E n)} (hs : IsClosed s) (hne : s.Nonempty) : ∃ f : (∀ n, E n) → ∀ n, E n, (∀ x ∈ s, f x = x) ∧ range f = s ∧ LipschitzWith 1 f := by /- The map `f` is defined as follows. For `x ∈ s`, let `f x = x`. Otherwise, consider the longest prefix `w` that `x` shares with an element of `s`, and let `f x = z_w` where `z_w` is an element of `s` starting with `w`. All the desired properties are clear, except the fact that `f` is `1`-Lipschitz: if two points `x, y` belong to a common cylinder of length `n`, one should show that their images also belong to a common cylinder of length `n`. This is a case analysis: * if both `x, y ∈ s`, then this is clear. * if `x ∈ s` but `y ∉ s`, then the longest prefix `w` of `y` shared by an element of `s` is of length at least `n` (because of `x`), and then `f y` starts with `w` and therefore stays in the same length `n` cylinder. * if `x ∉ s`, `y ∉ s`, let `w` be the longest prefix of `x` shared by an element of `s`. If its length is `< n`, then it is also the longest prefix of `y`, and we get `f x = f y = z_w`. Otherwise, `f x` remains in the same `n`-cylinder as `x`. Similarly for `y`. Finally, `f x` and `f y` are again in the same `n`-cylinder, as desired. -/ classical set f := fun x => if x ∈ s then x else (inter_cylinder_longestPrefix_nonempty hs hne x).some have fs : ∀ x ∈ s, f x = x := fun x xs => by simp [f, xs] refine ⟹f, fs, ?_, ?_⟩ -- check that the range of `f` is `s`. · apply Subset.antisymm · rintro x ⟹y, rfl⟩ by_cases hy : y ∈ s · rwa [fs y hy] simpa [f, if_neg hy] using (inter_cylinder_longestPrefix_nonempty hs hne y).choose_spec.1 · intro x hx rw [← fs x hx] exact mem_range_self _ -- check that `f` is `1`-Lipschitz, by a case analysis. · refine LipschitzWith.mk_one fun x y => ?_ -- exclude the trivial cases where `x = y`, or `f x = f y`. rcases eq_or_ne x y with (rfl | hxy) · simp rcases eq_or_ne (f x) (f y) with (h' | hfxfy) · simp [h', dist_nonneg] have I2 : cylinder x (firstDiff x y) = cylinder y (firstDiff x y) := by rw [← mem_cylinder_iff_eq] apply mem_cylinder_firstDiff suffices firstDiff x y ≀ firstDiff (f x) (f y) by simpa [dist_eq_of_ne hxy, dist_eq_of_ne hfxfy] -- case where `x ∈ s` by_cases xs : x ∈ s · rw [fs x xs] at hfxfy ⊢ -- case where `y ∈ s`, trivial by_cases ys : y ∈ s · rw [fs y ys] -- case where `y ∉ s` have A : (s ∩ cylinder y (longestPrefix y s)).Nonempty := inter_cylinder_longestPrefix_nonempty hs hne y have fy : f y = A.some := by simp_rw [f, if_neg ys] have I : cylinder A.some (firstDiff x y) = cylinder y (firstDiff x y) := by rw [← mem_cylinder_iff_eq, firstDiff_comm] apply cylinder_anti y _ A.some_mem.2 exact firstDiff_le_longestPrefix hs ys xs rwa [← fy, ← I2, ← mem_cylinder_iff_eq, mem_cylinder_iff_le_firstDiff hfxfy.symm, firstDiff_comm _ x] at I -- case where `x ∉ s` · by_cases ys : y ∈ s -- case where `y ∈ s` (similar to the above) · have A : (s ∩ cylinder x (longestPrefix x s)).Nonempty := inter_cylinder_longestPrefix_nonempty hs hne x have fx : f x = A.some := by simp_rw [f, if_neg xs] have I : cylinder A.some (firstDiff x y) = cylinder x (firstDiff x y) := by rw [← mem_cylinder_iff_eq] apply cylinder_anti x _ A.some_mem.2 apply firstDiff_le_longestPrefix hs xs ys rw [fs y ys] at hfxfy ⊢ rwa [← fx, I2, ← mem_cylinder_iff_eq, mem_cylinder_iff_le_firstDiff hfxfy] at I -- case where `y ∉ s` · have Ax : (s ∩ cylinder x (longestPrefix x s)).Nonempty := inter_cylinder_longestPrefix_nonempty hs hne x have fx : f x = Ax.some := by simp_rw [f, if_neg xs] have Ay : (s ∩ cylinder y (longestPrefix y s)).Nonempty := inter_cylinder_longestPrefix_nonempty hs hne y have fy : f y = Ay.some := by simp_rw [f, if_neg ys] -- case where the common prefix to `x` and `s`, or `y` and `s`, is shorter than the -- common part to `x` and `y` -- then `f x = f y`. by_cases H : longestPrefix x s < firstDiff x y √ longestPrefix y s < firstDiff x y · have : cylinder x (longestPrefix x s) = cylinder y (longestPrefix y s) := by rcases H with H | H · exact cylinder_longestPrefix_eq_of_longestPrefix_lt_firstDiff hs hne H xs ys · symm rw [firstDiff_comm] at H exact cylinder_longestPrefix_eq_of_longestPrefix_lt_firstDiff hs hne H ys xs rw [fx, fy] at hfxfy apply (hfxfy _).elim congr -- case where the common prefix to `x` and `s` is long, as well as the common prefix to -- `y` and `s`. Then all points remain in the same cylinders. · push_neg at H have I1 : cylinder Ax.some (firstDiff x y) = cylinder x (firstDiff x y) := by rw [← mem_cylinder_iff_eq] exact cylinder_anti x H.1 Ax.some_mem.2 have I3 : cylinder y (firstDiff x y) = cylinder Ay.some (firstDiff x y) := by rw [eq_comm, ← mem_cylinder_iff_eq] exact cylinder_anti y H.2 Ay.some_mem.2 have : cylinder Ax.some (firstDiff x y) = cylinder Ay.some (firstDiff x y) := by rw [I1, I2, I3] rw [← fx, ← fy, ← mem_cylinder_iff_eq, mem_cylinder_iff_le_firstDiff hfxfy] at this exact this /-- Given a closed nonempty subset `s` of `Π (n : ℕ), E n`, there exists a retraction onto this set, i.e., a continuous map with range equal to `s`, equal to the identity on `s`. -/ theorem exists_retraction_of_isClosed {s : Set (∀ n, E n)} (hs : IsClosed s) (hne : s.Nonempty) : ∃ f : (∀ n, E n) → ∀ n, E n, (∀ x ∈ s, f x = x) ∧ range f = s ∧ Continuous f := by rcases exists_lipschitz_retraction_of_isClosed hs hne with ⟹f, fs, frange, hf⟩ exact ⟹f, fs, frange, hf.continuous⟩ theorem exists_retraction_subtype_of_isClosed {s : Set (∀ n, E n)} (hs : IsClosed s) (hne : s.Nonempty) : ∃ f : (∀ n, E n) → s, (∀ x : s, f x = x) ∧ Surjective f ∧ Continuous f := by obtain ⟹f, fs, rfl, f_cont⟩ : ∃ f : (∀ n, E n) → ∀ n, E n, (∀ x ∈ s, f x = x) ∧ range f = s ∧ Continuous f := exists_retraction_of_isClosed hs hne have A : ∀ x : range f, rangeFactorization f x = x := fun x ↩ Subtype.eq <| fs x x.2 exact ⟹rangeFactorization f, A, fun x => ⟹x, A x⟩, f_cont.subtype_mk _⟩ end PiNat open PiNat /-- Any nonempty complete second countable metric space is the continuous image of the fundamental space `ℕ → ℕ`. For a version of this theorem in the context of Polish spaces, see `exists_nat_nat_continuous_surjective_of_polishSpace`. -/ theorem exists_nat_nat_continuous_surjective_of_completeSpace (α : Type*) [MetricSpace α] [CompleteSpace α] [SecondCountableTopology α] [Nonempty α] : ∃ f : (ℕ → ℕ) → α, Continuous f ∧ Surjective f := by /- First, we define a surjective map from a closed subset `s` of `ℕ → ℕ`. Then, we compose this map with a retraction of `ℕ → ℕ` onto `s` to obtain the desired map. Let us consider a dense sequence `u` in `α`. Then `s` is the set of sequences `xₙ` such that the balls `closedBall (u xₙ) (1/2^n)` have a nonempty intersection. This set is closed, and we define `f x` there to be the unique point in the intersection. This function is continuous and surjective by design. -/ letI : MetricSpace (ℕ → ℕ) := PiNat.metricSpaceNatNat have I0 : (0 : ℝ) < 1 / 2 := by norm_num have I1 : (1 / 2 : ℝ) < 1 := by norm_num rcases exists_dense_seq α with ⟹u, hu⟩ let s : Set (ℕ → ℕ) := { x | (⋂ n : ℕ, closedBall (u (x n)) ((1 / 2) ^ n)).Nonempty } let g : s → α := fun x => x.2.some have A : ∀ (x : s) (n : ℕ), dist (g x) (u ((x : ℕ → ℕ) n)) ≀ (1 / 2) ^ n := fun x n => (mem_iInter.1 x.2.some_mem n :) have g_cont : Continuous g := by refine continuous_iff_continuousAt.2 fun y => ?_ refine continuousAt_of_locally_lipschitz zero_lt_one 4 fun x hxy => ?_ rcases eq_or_ne x y with (rfl | hne) · simp have hne' : x.1 ≠ y.1 := Subtype.coe_injective.ne hne have dist' : dist x y = dist x.1 y.1 := rfl let n := firstDiff x.1 y.1 - 1 have diff_pos : 0 < firstDiff x.1 y.1 := by by_contra! h apply apply_firstDiff_ne hne' rw [Nat.le_zero.1 h] apply apply_eq_of_dist_lt _ le_rfl rw [pow_zero] exact hxy have hn : firstDiff x.1 y.1 = n + 1 := (Nat.succ_pred_eq_of_pos diff_pos).symm rw [dist', dist_eq_of_ne hne', hn] have B : x.1 n = y.1 n := mem_cylinder_firstDiff x.1 y.1 n (Nat.pred_lt diff_pos.ne') calc dist (g x) (g y) ≀ dist (g x) (u (x.1 n)) + dist (g y) (u (x.1 n)) := dist_triangle_right _ _ _ _ = dist (g x) (u (x.1 n)) + dist (g y) (u (y.1 n)) := by rw [← B] _ ≀ (1 / 2) ^ n + (1 / 2) ^ n := add_le_add (A x n) (A y n) _ = 4 * (1 / 2) ^ (n + 1) := by ring have g_surj : Surjective g := fun y ↩ by have : ∀ n : ℕ, ∃ j, y ∈ closedBall (u j) ((1 / 2) ^ n) := fun n ↩ by rcases hu.exists_dist_lt y (by simp : (0 : ℝ) < (1 / 2) ^ n) with ⟹j, hj⟩ exact ⟹j, hj.le⟩ choose x hx using this have I : (⋂ n : ℕ, closedBall (u (x n)) ((1 / 2) ^ n)).Nonempty := ⟹y, mem_iInter.2 hx⟩ refine ⟹⟹x, I⟩, ?_⟩ refine dist_le_zero.1 ?_ have J : ∀ n : ℕ, dist (g ⟹x, I⟩) y ≀ (1 / 2) ^ n + (1 / 2) ^ n := fun n => calc dist (g ⟹x, I⟩) y ≀ dist (g ⟹x, I⟩) (u (x n)) + dist y (u (x n)) := dist_triangle_right _ _ _ _ ≀ (1 / 2) ^ n + (1 / 2) ^ n := add_le_add (A ⟹x, I⟩ n) (hx n) have L : Tendsto (fun n : ℕ => (1 / 2 : ℝ) ^ n + (1 / 2) ^ n) atTop (𝓝 (0 + 0)) := (tendsto_pow_atTop_nhds_zero_of_lt_one I0.le I1).add (tendsto_pow_atTop_nhds_zero_of_lt_one I0.le I1) rw [add_zero] at L exact ge_of_tendsto' L J have s_closed : IsClosed s := by refine isClosed_iff_clusterPt.mpr fun x hx ↩ ?_ have L : Tendsto (fun n : ℕ => diam (closedBall (u (x n)) ((1 / 2) ^ n))) atTop (𝓝 0) := by have : Tendsto (fun n : ℕ => (2 : ℝ) * (1 / 2) ^ n) atTop (𝓝 (2 * 0)) := (tendsto_pow_atTop_nhds_zero_of_lt_one I0.le I1).const_mul _ rw [mul_zero] at this exact squeeze_zero (fun n => diam_nonneg) (fun n => diam_closedBall (pow_nonneg I0.le _)) this refine nonempty_iInter_of_nonempty_biInter (fun n => isClosed_closedBall) (fun n => isBounded_closedBall) (fun N ↩ ?_) L obtain ⟹y, hxy, ys⟩ : ∃ y, y ∈ ball x ((1 / 2) ^ N) ∩ s := clusterPt_principal_iff.1 hx _ (ball_mem_nhds x (pow_pos I0 N)) have E : ⋂ (n : ℕ) (H : n ≀ N), closedBall (u (x n)) ((1 / 2) ^ n) = ⋂ (n : ℕ) (H : n ≀ N), closedBall (u (y n)) ((1 / 2) ^ n) := by refine iInter_congr fun n ↩ iInter_congr fun hn ↩ ?_ have : x n = y n := apply_eq_of_dist_lt (mem_ball'.1 hxy) hn rw [this] rw [E] apply Nonempty.mono _ ys apply iInter_subset_iInter₂ obtain ⟹f, -, f_surj, f_cont⟩ : ∃ f : (ℕ → ℕ) → s, (∀ x : s, f x = x) ∧ Surjective f ∧ Continuous f := by apply exists_retraction_subtype_of_isClosed s_closed simpa only [nonempty_coe_sort] using g_surj.nonempty exact ⟹g ∘ f, g_cont.comp f_cont, g_surj.comp f_surj⟩ namespace PiCountable /-! ### Products of (possibly non-discrete) metric spaces -/ variable {ι : Type*} [Encodable ι] {F : ι → Type*} [∀ i, MetricSpace (F i)] open Encodable /-- Given a countable family of metric spaces, one may put a distance on their product `Π i, E i`. It is highly non-canonical, though, and therefore not registered as a global instance. The distance we use here is `dist x y = ∑' i, min (1/2)^(encode i) (dist (x i) (y i))`. -/ protected def dist : Dist (∀ i, F i) := ⟹fun x y => ∑' i : ι, min ((1 / 2) ^ encode i) (dist (x i) (y i))⟩ attribute [local instance] PiCountable.dist theorem dist_eq_tsum (x y : ∀ i, F i) : dist x y = ∑' i : ι, min ((1 / 2) ^ encode i : ℝ) (dist (x i) (y i)) := rfl theorem dist_summable (x y : ∀ i, F i) : Summable fun i : ι => min ((1 / 2) ^ encode i : ℝ) (dist (x i) (y i)) := by refine .of_nonneg_of_le (fun i => ?_) (fun i => min_le_left _ _) summable_geometric_two_encode exact le_min (pow_nonneg (by norm_num) _) dist_nonneg theorem min_dist_le_dist_pi (x y : ∀ i, F i) (i : ι) : min ((1 / 2) ^ encode i : ℝ) (dist (x i) (y i)) ≀ dist x y := (dist_summable x y).le_tsum i fun j _ => le_min (by simp) dist_nonneg theorem dist_le_dist_pi_of_dist_lt {x y : ∀ i, F i} {i : ι} (h : dist x y < (1 / 2) ^ encode i) : dist (x i) (y i) ≀ dist x y := by simpa only [not_le.2 h, false_or] using min_le_iff.1 (min_dist_le_dist_pi x y i) open Topology Filter NNReal variable (E) /-- Given a countable family of metric spaces, one may put a distance on their product `Π i, E i`, defining the right topology and uniform structure. It is highly non-canonical, though, and therefore not registered as a global instance. The distance we use here is `dist x y = ∑' n, min (1/2)^(encode i) (dist (x n) (y n))`. -/ protected def metricSpace : MetricSpace (∀ i, F i) where dist_self x := by simp [dist_eq_tsum] dist_comm x y := by simp [dist_eq_tsum, dist_comm] dist_triangle x y z := have I : ∀ i, min ((1 / 2) ^ encode i : ℝ) (dist (x i) (z i)) ≀ min ((1 / 2) ^ encode i : ℝ) (dist (x i) (y i)) + min ((1 / 2) ^ encode i : ℝ) (dist (y i) (z i)) := fun i => calc min ((1 / 2) ^ encode i : ℝ) (dist (x i) (z i)) ≀ min ((1 / 2) ^ encode i : ℝ) (dist (x i) (y i) + dist (y i) (z i)) := min_le_min le_rfl (dist_triangle _ _ _) _ = min ((1 / 2) ^ encode i : ℝ) (min ((1 / 2) ^ encode i : ℝ) (dist (x i) (y i)) + min ((1 / 2) ^ encode i : ℝ) (dist (y i) (z i))) := by convert congr_arg ((↑) : ℝ≥0 → ℝ) (min_add_distrib ((1 / 2 : ℝ≥0) ^ encode i) (nndist (x i) (y i)) (nndist (y i) (z i))) _ ≀ min ((1 / 2) ^ encode i : ℝ) (dist (x i) (y i)) + min ((1 / 2) ^ encode i : ℝ) (dist (y i) (z i)) := min_le_right _ _ calc dist x z ≀ ∑' i, (min ((1 / 2) ^ encode i : ℝ) (dist (x i) (y i)) + min ((1 / 2) ^ encode i : ℝ) (dist (y i) (z i))) := (dist_summable x z).tsum_le_tsum I ((dist_summable x y).add (dist_summable y z)) _ = dist x y + dist y z := (dist_summable x y).tsum_add (dist_summable y z) eq_of_dist_eq_zero hxy := by ext1 n rw [← dist_le_zero, ← hxy] apply dist_le_dist_pi_of_dist_lt rw [hxy] simp toUniformSpace := Pi.uniformSpace _ uniformity_dist := by simp only [Pi.uniformity, comap_iInf, gt_iff_lt, preimage_setOf_eq, comap_principal, PseudoMetricSpace.uniformity_dist] apply le_antisymm · simp only [le_iInf_iff, le_principal_iff] intro ε εpos classical
obtain ⟹K, hK⟩ : ∃ K : Finset ι, (∑' i : { j // j ∉ K }, (1 / 2 : ℝ) ^ encode (i : ι)) < ε / 2 := ((tendsto_order.1 (tendsto_tsum_compl_atTop_zero fun i : ι => (1 / 2 : ℝ) ^ encode i)).2 _
Mathlib/Topology/MetricSpace/PiNat.lean
841
843
/- Copyright (c) 2021 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.Data.ULift import Mathlib.Data.ZMod.Defs import Mathlib.SetTheory.Cardinal.ToNat import Mathlib.SetTheory.Cardinal.ENat /-! # Finite Cardinality Functions ## Main Definitions * `Nat.card α` is the cardinality of `α` as a natural number. If `α` is infinite, `Nat.card α = 0`. * `ENat.card α` is the cardinality of `α` as an extended natural number. If `α` is infinite, `ENat.card α = ⊀`. * `PartENat.card α` is the cardinality of `α` as an extended natural number (using the legacy definition `PartENat := Part ℕ`). If `α` is infinite, `PartENat.card α = ⊀`. -/ assert_not_exists Field open Cardinal Function noncomputable section variable {α β : Type*} universe u v namespace Nat /-- `Nat.card α` is the cardinality of `α` as a natural number. If `α` is infinite, `Nat.card α = 0`. -/ protected def card (α : Type*) : ℕ := toNat (mk α) @[simp] theorem card_eq_fintype_card [Fintype α] : Nat.card α = Fintype.card α := mk_toNat_eq_card /-- Because this theorem takes `Fintype α` as a non-instance argument, it can be used in particular when `Fintype.card` ends up with different instance than the one found by inference -/ theorem _root_.Fintype.card_eq_nat_card {_ : Fintype α} : Fintype.card α = Nat.card α := mk_toNat_eq_card.symm lemma card_eq_finsetCard (s : Finset α) : Nat.card s = s.card := by simp only [Nat.card_eq_fintype_card, Fintype.card_coe] lemma card_eq_card_toFinset (s : Set α) [Fintype s] : Nat.card s = s.toFinset.card := by simp only [← Nat.card_eq_finsetCard, s.mem_toFinset] lemma card_eq_card_finite_toFinset {s : Set α} (hs : s.Finite) : Nat.card s = hs.toFinset.card := by simp only [← Nat.card_eq_finsetCard, hs.mem_toFinset] @[simp] theorem card_of_isEmpty [IsEmpty α] : Nat.card α = 0 := by simp [Nat.card] @[simp] lemma card_eq_zero_of_infinite [Infinite α] : Nat.card α = 0 := mk_toNat_of_infinite lemma cast_card [Finite α] : (Nat.card α : Cardinal) = Cardinal.mk α := by rw [Nat.card, Cardinal.cast_toNat_of_lt_aleph0] exact Cardinal.lt_aleph0_of_finite _ lemma _root_.Set.Infinite.card_eq_zero {s : Set α} (hs : s.Infinite) : Nat.card s = 0 := @card_eq_zero_of_infinite _ hs.to_subtype lemma card_eq_zero : Nat.card α = 0 ↔ IsEmpty α √ Infinite α := by simp [Nat.card, mk_eq_zero_iff, aleph0_le_mk_iff] lemma card_ne_zero : Nat.card α ≠ 0 ↔ Nonempty α ∧ Finite α := by simp [card_eq_zero, not_or] lemma card_pos_iff : 0 < Nat.card α ↔ Nonempty α ∧ Finite α := by simp [Nat.card, mk_eq_zero_iff, mk_lt_aleph0_iff] @[simp] lemma card_pos [Nonempty α] [Finite α] : 0 < Nat.card α := card_pos_iff.2 ⟚‹_›, ‹_›⟩ theorem finite_of_card_ne_zero (h : Nat.card α ≠ 0) : Finite α := (card_ne_zero.1 h).2 theorem card_congr (f : α ≃ β) : Nat.card α = Nat.card β := Cardinal.toNat_congr f lemma card_le_card_of_injective {α : Type u} {β : Type v} [Finite β] (f : α → β) (hf : Injective f) : Nat.card α ≀ Nat.card β := by simpa using toNat_le_toNat (lift_mk_le_lift_mk_of_injective hf) (by simp [lt_aleph0_of_finite])
lemma card_le_card_of_surjective {α : Type u} {β : Type v} [Finite α] (f : α → β) (hf : Surjective f) : Nat.card β ≀ Nat.card α := by have : lift.{u} #β ≀ lift.{v} #α := mk_le_of_surjective (ULift.map_surjective.2 hf)
Mathlib/SetTheory/Cardinal/Finite.lean
88
91
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Sébastien Gouëzel -/ import Mathlib.Analysis.Normed.Operator.Banach import Mathlib.Analysis.NormedSpace.OperatorNorm.NormedSpace import Mathlib.Topology.PartialHomeomorph /-! # Non-linear maps close to affine maps In this file we study a map `f` such that `‖f x - f y - f' (x - y)‖ ≀ c * ‖x - y‖` on an open set `s`, where `f' : E →L[𝕜] F` is a continuous linear map and `c` is suitably small. Maps of this type behave like `f a + f' (x - a)` near each `a ∈ s`. When `f'` is onto, we show that `f` is locally onto. When `f'` is a continuous linear equiv, we show that `f` is a homeomorphism between `s` and `f '' s`. More precisely, we define `ApproximatesLinearOn.toPartialHomeomorph` to be a `PartialHomeomorph` with `toFun = f`, `source = s`, and `target = f '' s`. between `s` and `f '' s`. More precisely, we define `ApproximatesLinearOn.toPartialHomeomorph` to be a `PartialHomeomorph` with `toFun = f`, `source = s`, and `target = f '' s`. Maps of this type naturally appear in the proof of the inverse function theorem (see next section), and `ApproximatesLinearOn.toPartialHomeomorph` will imply that the locally inverse function and `ApproximatesLinearOn.toPartialHomeomorph` will imply that the locally inverse function exists. We define this auxiliary notion to split the proof of the inverse function theorem into small lemmas. This approach makes it possible - to prove a lower estimate on the size of the domain of the inverse function; - to reuse parts of the proofs in the case if a function is not strictly differentiable. E.g., for a function `f : E × F → G` with estimates on `f x y₁ - f x y₂` but not on `f x₁ y - f x₂ y`. ## Notations We introduce some `local notation` to make formulas shorter: * by `N` we denote `‖f'⁻¹‖`; * by `g` we denote the auxiliary contracting map `x ↩ x + f'.symm (y - f x)` used to prove that `{x | f x = y}` is nonempty. -/ open Function Set Filter Metric open scoped Topology NNReal noncomputable section variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {ε : ℝ} open Filter Metric Set open ContinuousLinearMap (id) /-- We say that `f` approximates a continuous linear map `f'` on `s` with constant `c`, if `‖f x - f y - f' (x - y)‖ ≀ c * ‖x - y‖` whenever `x, y ∈ s`. This predicate is defined to facilitate the splitting of the inverse function theorem into small lemmas. Some of these lemmas can be useful, e.g., to prove that the inverse function is defined on a specific set. -/ def ApproximatesLinearOn (f : E → F) (f' : E →L[𝕜] F) (s : Set E) (c : ℝ≥0) : Prop := ∀ x ∈ s, ∀ y ∈ s, ‖f x - f y - f' (x - y)‖ ≀ c * ‖x - y‖ @[simp] theorem approximatesLinearOn_empty (f : E → F) (f' : E →L[𝕜] F) (c : ℝ≥0) : ApproximatesLinearOn f f' ∅ c := by simp [ApproximatesLinearOn] namespace ApproximatesLinearOn variable {f : E → F} /-! First we prove some properties of a function that `ApproximatesLinearOn` a (not necessarily invertible) continuous linear map. -/ section variable {f' : E →L[𝕜] F} {s t : Set E} {c c' : ℝ≥0} theorem mono_num (hc : c ≀ c') (hf : ApproximatesLinearOn f f' s c) : ApproximatesLinearOn f f' s c' := fun x hx y hy => le_trans (hf x hx y hy) (mul_le_mul_of_nonneg_right hc <| norm_nonneg _) theorem mono_set (hst : s ⊆ t) (hf : ApproximatesLinearOn f f' t c) : ApproximatesLinearOn f f' s c := fun x hx y hy => hf x (hst hx) y (hst hy) theorem approximatesLinearOn_iff_lipschitzOnWith {f : E → F} {f' : E →L[𝕜] F} {s : Set E} {c : ℝ≥0} : ApproximatesLinearOn f f' s c ↔ LipschitzOnWith c (f - ⇑f') s := by have : ∀ x y, f x - f y - f' (x - y) = (f - f') x - (f - f') y := fun x y ↩ by simp only [map_sub, Pi.sub_apply]; abel simp only [this, lipschitzOnWith_iff_norm_sub_le, ApproximatesLinearOn] alias ⟹lipschitzOnWith, _root_.LipschitzOnWith.approximatesLinearOn⟩ := approximatesLinearOn_iff_lipschitzOnWith theorem lipschitz_sub (hf : ApproximatesLinearOn f f' s c) : LipschitzWith c fun x : s => f x - f' x := hf.lipschitzOnWith.to_restrict protected theorem lipschitz (hf : ApproximatesLinearOn f f' s c) : LipschitzWith (‖f'‖₊ + c) (s.restrict f) := by simpa only [restrict_apply, add_sub_cancel] using (f'.lipschitz.restrict s).add hf.lipschitz_sub protected theorem continuous (hf : ApproximatesLinearOn f f' s c) : Continuous (s.restrict f) := hf.lipschitz.continuous protected theorem continuousOn (hf : ApproximatesLinearOn f f' s c) : ContinuousOn f s := continuousOn_iff_continuous_restrict.2 hf.continuous end
section LocallyOnto /-!
Mathlib/Analysis/Calculus/InverseFunctionTheorem/ApproximatesLinearOn.lean
118
121
/- Copyright (c) 2017 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Stephen Morgan, Kim Morrison -/ import Mathlib.CategoryTheory.Equivalence /-! # Opposite categories We provide a category instance on `Cᵒᵖ`. The morphisms `X ⟶ Y` are defined to be the morphisms `unop Y ⟶ unop X` in `C`. Here `Cᵒᵖ` is an irreducible typeclass synonym for `C` (it is the same one used in the algebra library). We also provide various mechanisms for constructing opposite morphisms, functors, and natural transformations. Unfortunately, because we do not have a definitional equality `op (op X) = X`, there are quite a few variations that are needed in practice. -/ universe v₁ v₂ u₁ u₂ -- morphism levels before object levels. See note [CategoryTheory universes]. open Opposite variable {C : Type u₁} section Quiver variable [Quiver.{v₁} C] theorem Quiver.Hom.op_inj {X Y : C} : Function.Injective (Quiver.Hom.op : (X ⟶ Y) → (Opposite.op Y ⟶ Opposite.op X)) := fun _ _ H => congr_arg Quiver.Hom.unop H theorem Quiver.Hom.unop_inj {X Y : Cᵒᵖ} : Function.Injective (Quiver.Hom.unop : (X ⟶ Y) → (Opposite.unop Y ⟶ Opposite.unop X)) := fun _ _ H => congr_arg Quiver.Hom.op H @[simp] theorem Quiver.Hom.unop_op {X Y : C} (f : X ⟶ Y) : f.op.unop = f := rfl @[simp] theorem Quiver.Hom.unop_op' {X Y : Cᵒᵖ} {x} : @Quiver.Hom.unop C _ X Y no_index (Opposite.op (unop := x)) = x := rfl @[simp] theorem Quiver.Hom.op_unop {X Y : Cᵒᵖ} (f : X ⟶ Y) : f.unop.op = f := rfl @[simp] theorem Quiver.Hom.unop_mk {X Y : Cᵒᵖ} (f : X ⟶ Y) : Quiver.Hom.unop {unop := f} = f := rfl end Quiver namespace CategoryTheory variable [Category.{v₁} C] /-- The opposite category. -/ @[stacks 001M] instance Category.opposite : Category.{v₁} Cᵒᵖ where comp f g := (g.unop ≫ f.unop).op id X := (𝟙 (unop X)).op @[simp, reassoc] theorem op_comp {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g).op = g.op ≫ f.op := rfl @[simp] theorem op_id {X : C} : (𝟙 X).op = 𝟙 (op X) := rfl @[simp, reassoc] theorem unop_comp {X Y Z : Cᵒᵖ} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g).unop = g.unop ≫ f.unop := rfl @[simp] theorem unop_id {X : Cᵒᵖ} : (𝟙 X).unop = 𝟙 (unop X) := rfl @[simp] theorem unop_id_op {X : C} : (𝟙 (op X)).unop = 𝟙 X := rfl @[simp] theorem op_id_unop {X : Cᵒᵖ} : (𝟙 (unop X)).op = 𝟙 X := rfl section variable (C) /-- The functor from the double-opposite of a category to the underlying category. -/ @[simps] def unopUnop : Cᵒᵖᵒᵖ ⥀ C where obj X := unop (unop X) map f := f.unop.unop /-- The functor from a category to its double-opposite. -/ @[simps] def opOp : C ⥀ Cᵒᵖᵒᵖ where obj X := op (op X) map f := f.op.op /-- The double opposite category is equivalent to the original. -/ @[simps] def opOpEquivalence : Cᵒᵖᵒᵖ ≌ C where functor := unopUnop C inverse := opOp C unitIso := Iso.refl (𝟭 Cᵒᵖᵒᵖ) counitIso := Iso.refl (opOp C ⋙ unopUnop C) instance : (opOp C).IsEquivalence := (opOpEquivalence C).isEquivalence_inverse instance : (unopUnop C).IsEquivalence := (opOpEquivalence C).isEquivalence_functor end /-- If `f` is an isomorphism, so is `f.op` -/ instance isIso_op {X Y : C} (f : X ⟶ Y) [IsIso f] : IsIso f.op := ⟹⟹(inv f).op, ⟹Quiver.Hom.unop_inj (by simp), Quiver.Hom.unop_inj (by simp)⟩⟩⟩ /-- If `f.op` is an isomorphism `f` must be too. (This cannot be an instance as it would immediately loop!) -/ theorem isIso_of_op {X Y : C} (f : X ⟶ Y) [IsIso f.op] : IsIso f := ⟹⟹(inv f.op).unop, ⟹Quiver.Hom.op_inj (by simp), Quiver.Hom.op_inj (by simp)⟩⟩⟩ theorem isIso_op_iff {X Y : C} (f : X ⟶ Y) : IsIso f.op ↔ IsIso f := ⟹fun _ => isIso_of_op _, fun _ => inferInstance⟩ theorem isIso_unop_iff {X Y : Cᵒᵖ} (f : X ⟶ Y) : IsIso f.unop ↔ IsIso f := by rw [← isIso_op_iff f.unop, Quiver.Hom.op_unop] instance isIso_unop {X Y : Cᵒᵖ} (f : X ⟶ Y) [IsIso f] : IsIso f.unop := (isIso_unop_iff _).2 inferInstance @[simp]
theorem op_inv {X Y : C} (f : X ⟶ Y) [IsIso f] : (inv f).op = inv f.op := by apply IsIso.eq_inv_of_hom_inv_id
Mathlib/CategoryTheory/Opposites.lean
145
146
/- Copyright (c) 2022 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.Order.Interval.Set.Monotone import Mathlib.Probability.Process.HittingTime import Mathlib.Probability.Martingale.Basic import Mathlib.Tactic.AdaptationNote /-! # Doob's upcrossing estimate Given a discrete real-valued submartingale $(f_n)_{n \in \mathbb{N}}$, denoting by $U_N(a, b)$ the number of times $f_n$ crossed from below $a$ to above $b$ before time $N$, Doob's upcrossing estimate (also known as Doob's inequality) states that $$(b - a) \mathbb{E}[U_N(a, b)] \le \mathbb{E}[(f_N - a)^+].$$ Doob's upcrossing estimate is an important inequality and is central in proving the martingale convergence theorems. ## Main definitions * `MeasureTheory.upperCrossingTime a b f N n`: is the stopping time corresponding to `f` crossing above `b` the `n`-th time before time `N` (if this does not occur then the value is taken to be `N`). * `MeasureTheory.lowerCrossingTime a b f N n`: is the stopping time corresponding to `f` crossing below `a` the `n`-th time before time `N` (if this does not occur then the value is taken to be `N`). * `MeasureTheory.upcrossingStrat a b f N`: is the predictable process which is 1 if `n` is between a consecutive pair of lower and upper crossings and is 0 otherwise. Intuitively one might think of the `upcrossingStrat` as the strategy of buying 1 share whenever the process crosses below `a` for the first time after selling and selling 1 share whenever the process crosses above `b` for the first time after buying. * `MeasureTheory.upcrossingsBefore a b f N`: is the number of times `f` crosses from below `a` to above `b` before time `N`. * `MeasureTheory.upcrossings a b f`: is the number of times `f` crosses from below `a` to above `b`. This takes value in `ℝ≥0∞` and so is allowed to be `∞`. ## Main results * `MeasureTheory.Adapted.isStoppingTime_upperCrossingTime`: `upperCrossingTime` is a stopping time whenever the process it is associated to is adapted. * `MeasureTheory.Adapted.isStoppingTime_lowerCrossingTime`: `lowerCrossingTime` is a stopping time whenever the process it is associated to is adapted. * `MeasureTheory.Submartingale.mul_integral_upcrossingsBefore_le_integral_pos_part`: Doob's upcrossing estimate. * `MeasureTheory.Submartingale.mul_lintegral_upcrossings_le_lintegral_pos_part`: the inequality obtained by taking the supremum on both sides of Doob's upcrossing estimate. ### References We mostly follow the proof from [Kallenberg, *Foundations of modern probability*][kallenberg2021] -/ open TopologicalSpace Filter open scoped NNReal ENNReal MeasureTheory ProbabilityTheory Topology namespace MeasureTheory variable {Ω ι : Type*} {m0 : MeasurableSpace Ω} {ÎŒ : Measure Ω} /-! ## Proof outline In this section, we will denote by $U_N(a, b)$ the number of upcrossings of $(f_n)$ from below $a$ to above $b$ before time $N$. To define $U_N(a, b)$, we will construct two stopping times corresponding to when $(f_n)$ crosses below $a$ and above $b$. Namely, we define $$ \sigma_n := \inf \{n \ge \tau_n \mid f_n \le a\} \wedge N; $$ $$ \tau_{n + 1} := \inf \{n \ge \sigma_n \mid f_n \ge b\} \wedge N. $$ These are `lowerCrossingTime` and `upperCrossingTime` in our formalization which are defined using `MeasureTheory.hitting` allowing us to specify a starting and ending time. Then, we may simply define $U_N(a, b) := \sup \{n \mid \tau_n < N\}$. Fixing $a < b \in \mathbb{R}$, we will first prove the theorem in the special case that $0 \le f_0$ and $a \le f_N$. In particular, we will show $$ (b - a) \mathbb{E}[U_N(a, b)] \le \mathbb{E}[f_N]. $$ This is `MeasureTheory.integral_mul_upcrossingsBefore_le_integral` in our formalization. To prove this, we use the fact that given a non-negative, bounded, predictable process $(C_n)$ (i.e. $(C_{n + 1})$ is adapted), $(C \bullet f)_n := \sum_{k \le n} C_{k + 1}(f_{k + 1} - f_k)$ is a submartingale if $(f_n)$ is. Define $C_n := \sum_{k \le n} \mathbf{1}_{[\sigma_k, \tau_{k + 1})}(n)$. It is easy to see that $(1 - C_n)$ is non-negative, bounded and predictable, and hence, given a submartingale $(f_n)$, $(1 - C) \bullet f$ is also a submartingale. Thus, by the submartingale property, $0 \le \mathbb{E}[((1 - C) \bullet f)_0] \le \mathbb{E}[((1 - C) \bullet f)_N]$ implying $$ \mathbb{E}[(C \bullet f)_N] \le \mathbb{E}[(1 \bullet f)_N] = \mathbb{E}[f_N] - \mathbb{E}[f_0]. $$ Furthermore, \begin{align} (C \bullet f)_N & = \sum_{n \le N} \sum_{k \le N} \mathbf{1}_{[\sigma_k, \tau_{k + 1})}(n)(f_{n + 1} - f_n)\\ & = \sum_{k \le N} \sum_{n \le N} \mathbf{1}_{[\sigma_k, \tau_{k + 1})}(n)(f_{n + 1} - f_n)\\ & = \sum_{k \le N} (f_{\sigma_k + 1} - f_{\sigma_k} + f_{\sigma_k + 2} - f_{\sigma_k + 1} + \cdots + f_{\tau_{k + 1}} - f_{\tau_{k + 1} - 1})\\ & = \sum_{k \le N} (f_{\tau_{k + 1}} - f_{\sigma_k}) \ge \sum_{k < U_N(a, b)} (b - a) = (b - a) U_N(a, b) \end{align} where the inequality follows since for all $k < U_N(a, b)$, $f_{\tau_{k + 1}} - f_{\sigma_k} \ge b - a$ while for all $k > U_N(a, b)$, $f_{\tau_{k + 1}} = f_{\sigma_k} = f_N$ and $f_{\tau_{U_N(a, b) + 1}} - f_{\sigma_{U_N(a, b)}} = f_N - a \ge 0$. Hence, we have $$ (b - a) \mathbb{E}[U_N(a, b)] \le \mathbb{E}[(C \bullet f)_N] \le \mathbb{E}[f_N] - \mathbb{E}[f_0] \le \mathbb{E}[f_N], $$ as required. To obtain the general case, we simply apply the above to $((f_n - a)^+)_n$. -/ /-- `lowerCrossingTimeAux a f c N` is the first time `f` reached below `a` after time `c` before time `N`. -/ noncomputable def lowerCrossingTimeAux [Preorder ι] [InfSet ι] (a : ℝ) (f : ι → Ω → ℝ) (c N : ι) : Ω → ι := hitting f (Set.Iic a) c N /-- `upperCrossingTime a b f N n` is the first time before time `N`, `f` reaches above `b` after `f` reached below `a` for the `n - 1`-th time. -/ noncomputable def upperCrossingTime [Preorder ι] [OrderBot ι] [InfSet ι] (a b : ℝ) (f : ι → Ω → ℝ) (N : ι) : ℕ → Ω → ι | 0 => ⊥ | n + 1 => fun ω => hitting f (Set.Ici b) (lowerCrossingTimeAux a f (upperCrossingTime a b f N n ω) N ω) N ω /-- `lowerCrossingTime a b f N n` is the first time before time `N`, `f` reaches below `a` after `f` reached above `b` for the `n`-th time. -/ noncomputable def lowerCrossingTime [Preorder ι] [OrderBot ι] [InfSet ι] (a b : ℝ) (f : ι → Ω → ℝ) (N : ι) (n : ℕ) : Ω → ι := fun ω => hitting f (Set.Iic a) (upperCrossingTime a b f N n ω) N ω section variable [Preorder ι] [OrderBot ι] [InfSet ι] variable {a b : ℝ} {f : ι → Ω → ℝ} {N : ι} {n : ℕ} {ω : Ω} @[simp] theorem upperCrossingTime_zero : upperCrossingTime a b f N 0 = ⊥ := rfl @[simp] theorem lowerCrossingTime_zero : lowerCrossingTime a b f N 0 = hitting f (Set.Iic a) ⊥ N := rfl theorem upperCrossingTime_succ : upperCrossingTime a b f N (n + 1) ω = hitting f (Set.Ici b) (lowerCrossingTimeAux a f (upperCrossingTime a b f N n ω) N ω) N ω := by rw [upperCrossingTime] theorem upperCrossingTime_succ_eq (ω : Ω) : upperCrossingTime a b f N (n + 1) ω = hitting f (Set.Ici b) (lowerCrossingTime a b f N n ω) N ω := by simp only [upperCrossingTime_succ] rfl end section ConditionallyCompleteLinearOrderBot variable [ConditionallyCompleteLinearOrderBot ι] variable {a b : ℝ} {f : ι → Ω → ℝ} {N : ι} {n m : ℕ} {ω : Ω} theorem upperCrossingTime_le : upperCrossingTime a b f N n ω ≀ N := by cases n · simp only [upperCrossingTime_zero, Pi.bot_apply, bot_le] · simp only [upperCrossingTime_succ, hitting_le] @[simp] theorem upperCrossingTime_zero' : upperCrossingTime a b f ⊥ n ω = ⊥ := eq_bot_iff.2 upperCrossingTime_le theorem lowerCrossingTime_le : lowerCrossingTime a b f N n ω ≀ N := by simp only [lowerCrossingTime, hitting_le ω] theorem upperCrossingTime_le_lowerCrossingTime : upperCrossingTime a b f N n ω ≀ lowerCrossingTime a b f N n ω := by simp only [lowerCrossingTime, le_hitting upperCrossingTime_le ω] theorem lowerCrossingTime_le_upperCrossingTime_succ : lowerCrossingTime a b f N n ω ≀ upperCrossingTime a b f N (n + 1) ω := by rw [upperCrossingTime_succ] exact le_hitting lowerCrossingTime_le ω theorem lowerCrossingTime_mono (hnm : n ≀ m) : lowerCrossingTime a b f N n ω ≀ lowerCrossingTime a b f N m ω := by suffices Monotone fun n => lowerCrossingTime a b f N n ω by exact this hnm exact monotone_nat_of_le_succ fun n => le_trans lowerCrossingTime_le_upperCrossingTime_succ upperCrossingTime_le_lowerCrossingTime theorem upperCrossingTime_mono (hnm : n ≀ m) : upperCrossingTime a b f N n ω ≀ upperCrossingTime a b f N m ω := by suffices Monotone fun n => upperCrossingTime a b f N n ω by exact this hnm exact monotone_nat_of_le_succ fun n => le_trans upperCrossingTime_le_lowerCrossingTime lowerCrossingTime_le_upperCrossingTime_succ end ConditionallyCompleteLinearOrderBot variable {a b : ℝ} {f : ℕ → Ω → ℝ} {N : ℕ} {n m : ℕ} {ω : Ω} theorem stoppedValue_lowerCrossingTime (h : lowerCrossingTime a b f N n ω ≠ N) : stoppedValue f (lowerCrossingTime a b f N n) ω ≀ a := by obtain ⟹j, hj₁, hj₂⟩ := (hitting_le_iff_of_lt _ (lt_of_le_of_ne lowerCrossingTime_le h)).1 le_rfl exact stoppedValue_hitting_mem ⟹j, ⟹hj₁.1, le_trans hj₁.2 lowerCrossingTime_le⟩, hj₂⟩ theorem stoppedValue_upperCrossingTime (h : upperCrossingTime a b f N (n + 1) ω ≠ N) : b ≀ stoppedValue f (upperCrossingTime a b f N (n + 1)) ω := by obtain ⟹j, hj₁, hj₂⟩ := (hitting_le_iff_of_lt _ (lt_of_le_of_ne upperCrossingTime_le h)).1 le_rfl exact stoppedValue_hitting_mem ⟹j, ⟹hj₁.1, le_trans hj₁.2 (hitting_le _)⟩, hj₂⟩ theorem upperCrossingTime_lt_lowerCrossingTime (hab : a < b) (hn : lowerCrossingTime a b f N (n + 1) ω ≠ N) : upperCrossingTime a b f N (n + 1) ω < lowerCrossingTime a b f N (n + 1) ω := by refine lt_of_le_of_ne upperCrossingTime_le_lowerCrossingTime fun h => not_le.2 hab <| le_trans ?_ (stoppedValue_lowerCrossingTime hn) simp only [stoppedValue] rw [← h] exact stoppedValue_upperCrossingTime (h.symm ▾ hn) theorem lowerCrossingTime_lt_upperCrossingTime (hab : a < b) (hn : upperCrossingTime a b f N (n + 1) ω ≠ N) : lowerCrossingTime a b f N n ω < upperCrossingTime a b f N (n + 1) ω := by refine lt_of_le_of_ne lowerCrossingTime_le_upperCrossingTime_succ fun h => not_le.2 hab <| le_trans (stoppedValue_upperCrossingTime hn) ?_ simp only [stoppedValue] rw [← h] exact stoppedValue_lowerCrossingTime (h.symm ▾ hn)
theorem upperCrossingTime_lt_succ (hab : a < b) (hn : upperCrossingTime a b f N (n + 1) ω ≠ N) : upperCrossingTime a b f N n ω < upperCrossingTime a b f N (n + 1) ω := lt_of_le_of_lt upperCrossingTime_le_lowerCrossingTime (lowerCrossingTime_lt_upperCrossingTime hab hn) theorem lowerCrossingTime_stabilize (hnm : n ≀ m) (hn : lowerCrossingTime a b f N n ω = N) : lowerCrossingTime a b f N m ω = N := le_antisymm lowerCrossingTime_le (le_trans (le_of_eq hn.symm) (lowerCrossingTime_mono hnm))
Mathlib/Probability/Martingale/Upcrossing.lean
242
249
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.Algebra.Polynomial.Module.AEval /-! # Polynomial module In this file, we define the polynomial module for an `R`-module `M`, i.e. the `R[X]`-module `M[X]`. This is defined as a type alias `PolynomialModule R M := ℕ →₀ M`, since there might be different module structures on `ℕ →₀ M` of interest. See the docstring of `PolynomialModule` for details. -/ universe u v open Polynomial /-- The `R[X]`-module `M[X]` for an `R`-module `M`. This is isomorphic (as an `R`-module) to `M[X]` when `M` is a ring. We require all the module instances `Module S (PolynomialModule R M)` to factor through `R` except `Module R[X] (PolynomialModule R M)`. In this constraint, we have the following instances for example : - `R` acts on `PolynomialModule R R[X]` - `R[X]` acts on `PolynomialModule R R[X]` as `R[Y]` acting on `R[X][Y]` - `R` acts on `PolynomialModule R[X] R[X]` - `R[X]` acts on `PolynomialModule R[X] R[X]` as `R[X]` acting on `R[X][Y]` - `R[X][X]` acts on `PolynomialModule R[X] R[X]` as `R[X][Y]` acting on itself This is also the reason why `R` is included in the alias, or else there will be two different instances of `Module R[X] (PolynomialModule R[X])`. See https://leanprover.zulipchat.com/#narrow/stream/144837-PR-reviews/topic/.2315065.20polynomial.20modules for the full discussion. -/ @[nolint unusedArguments] def PolynomialModule (R M : Type*) [CommRing R] [AddCommGroup M] [Module R M] := ℕ →₀ M variable (R M : Type*) [CommRing R] [AddCommGroup M] [Module R M] (I : Ideal R) -- The `Inhabited, AddCommGroup` instances should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 noncomputable instance : Inhabited (PolynomialModule R M) := Finsupp.instInhabited noncomputable instance : AddCommGroup (PolynomialModule R M) := Finsupp.instAddCommGroup variable {M} variable {S : Type*} [CommSemiring S] [Algebra S R] [Module S M] [IsScalarTower S R M] namespace PolynomialModule /-- This is required to have the `IsScalarTower S R M` instance to avoid diamonds. -/ @[nolint unusedArguments] noncomputable instance : Module S (PolynomialModule R M) := Finsupp.module ℕ M instance instFunLike : FunLike (PolynomialModule R M) ℕ M := Finsupp.instFunLike instance : CoeFun (PolynomialModule R M) fun _ => ℕ → M := inferInstanceAs <| CoeFun (_ →₀ _) _ theorem zero_apply (i : ℕ) : (0 : PolynomialModule R M) i = 0 := Finsupp.zero_apply theorem add_apply (g₁ g₂ : PolynomialModule R M) (a : ℕ) : (g₁ + g₂) a = g₁ a + g₂ a := Finsupp.add_apply g₁ g₂ a /-- The monomial `m * x ^ i`. This is defeq to `Finsupp.singleAddHom`, and is redefined here so that it has the desired type signature. -/ noncomputable def single (i : ℕ) : M →+ PolynomialModule R M := Finsupp.singleAddHom i theorem single_apply (i : ℕ) (m : M) (n : ℕ) : single R i m n = ite (i = n) m 0 := Finsupp.single_apply /-- `PolynomialModule.single` as a linear map. -/ noncomputable def lsingle (i : ℕ) : M →ₗ[R] PolynomialModule R M := Finsupp.lsingle i theorem lsingle_apply (i : ℕ) (m : M) (n : ℕ) : lsingle R i m n = ite (i = n) m 0 := Finsupp.single_apply theorem single_smul (i : ℕ) (r : R) (m : M) : single R i (r • m) = r • single R i m := (lsingle R i).map_smul r m variable {R} @[elab_as_elim] theorem induction_linear {motive : PolynomialModule R M → Prop} (f : PolynomialModule R M) (zero : motive 0) (add : ∀ f g, motive f → motive g → motive (f + g)) (single : ∀ a b, motive (single R a b)) : motive f := Finsupp.induction_linear f zero add single noncomputable instance polynomialModule : Module R[X] (PolynomialModule R M) := inferInstanceAs (Module R[X] (Module.AEval' (Finsupp.lmapDomain M R Nat.succ))) lemma smul_def (f : R[X]) (m : PolynomialModule R M) : f • m = aeval (Finsupp.lmapDomain M R Nat.succ) f m := by rfl instance (M : Type u) [AddCommGroup M] [Module R M] [Module S M] [IsScalarTower S R M] : IsScalarTower S R (PolynomialModule R M) := Finsupp.isScalarTower _ _ instance isScalarTower' (M : Type u) [AddCommGroup M] [Module R M] [Module S M] [IsScalarTower S R M] : IsScalarTower S R[X] (PolynomialModule R M) := by haveI : IsScalarTower R R[X] (PolynomialModule R M) := inferInstanceAs <| IsScalarTower R R[X] <| Module.AEval' <| Finsupp.lmapDomain M R Nat.succ constructor intro x y z rw [← @IsScalarTower.algebraMap_smul S R, ← @IsScalarTower.algebraMap_smul S R, smul_assoc] @[simp] theorem monomial_smul_single (i : ℕ) (r : R) (j : ℕ) (m : M) : monomial i r • single R j m = single R (i + j) (r • m) := by simp only [Module.End.mul_apply, Polynomial.aeval_monomial, Module.End.pow_apply, Module.algebraMap_end_apply, smul_def] induction i generalizing r j m with | zero => rw [Function.iterate_zero, zero_add] exact Finsupp.smul_single r j m | succ n hn => rw [Function.iterate_succ, Function.comp_apply, add_assoc, ← hn] congr 2 rw [Nat.one_add] exact Finsupp.mapDomain_single @[simp] theorem monomial_smul_apply (i : ℕ) (r : R) (g : PolynomialModule R M) (n : ℕ) : (monomial i r • g) n = ite (i ≀ n) (r • g (n - i)) 0 := by induction' g using PolynomialModule.induction_linear with p q hp hq · simp only [smul_zero, zero_apply, ite_self] · simp only [smul_add, add_apply, hp, hq] split_ifs exacts [rfl, zero_add 0] · rw [monomial_smul_single, single_apply, single_apply, smul_ite, smul_zero, ← ite_and] congr rw [eq_iff_iff] constructor · rintro rfl simp · rintro ⟹e, rfl⟩ rw [add_comm, tsub_add_cancel_of_le e] @[simp] theorem smul_single_apply (i : ℕ) (f : R[X]) (m : M) (n : ℕ) : (f • single R i m) n = ite (i ≀ n) (f.coeff (n - i) • m) 0 := by induction' f using Polynomial.induction_on' with p q hp hq · rw [add_smul, Finsupp.add_apply, hp, hq, coeff_add, add_smul] split_ifs exacts [rfl, zero_add 0] · rw [monomial_smul_single, single_apply, coeff_monomial, ite_smul, zero_smul] by_cases h : i ≀ n · simp_rw [eq_tsub_iff_add_eq_of_le h, if_pos h] · rw [if_neg h, if_neg] omega theorem smul_apply (f : R[X]) (g : PolynomialModule R M) (n : ℕ) : (f • g) n = ∑ x ∈ Finset.antidiagonal n, f.coeff x.1 • g x.2 := by induction f using Polynomial.induction_on' with | add p q hp hq => rw [add_smul, Finsupp.add_apply, hp, hq, ← Finset.sum_add_distrib] congr ext rw [coeff_add, add_smul] | monomial f_n f_a => rw [Finset.Nat.sum_antidiagonal_eq_sum_range_succ fun i j => (monomial f_n f_a).coeff i • g j, monomial_smul_apply] simp_rw [Polynomial.coeff_monomial, ← Finset.mem_range_succ_iff] rw [← Finset.sum_ite_eq (Finset.range (Nat.succ n)) f_n (fun x => f_a • g (n - x))] congr ext x split_ifs exacts [rfl, (zero_smul R _).symm] /-- `PolynomialModule R R` is isomorphic to `R[X]` as an `R[X]` module. -/ noncomputable def equivPolynomialSelf : PolynomialModule R R ≃ₗ[R[X]] R[X] := { (Polynomial.toFinsuppIso R).symm with map_smul' := fun r x => by dsimp rw [← RingEquiv.coe_toEquiv_symm, RingEquiv.coe_toEquiv] induction x using induction_linear with | zero => rw [smul_zero, map_zero, mul_zero] | add _ _ hp hq => rw [smul_add, map_add, map_add, mul_add, hp, hq] | single n a => ext i simp only [coeff_ofFinsupp, smul_single_apply, toFinsuppIso_symm_apply, coeff_ofFinsupp, single_apply, smul_eq_mul, Polynomial.coeff_mul, mul_ite, mul_zero] split_ifs with hn · rw [Finset.sum_eq_single (i - n, n)] · simp only [ite_true] · rintro ⟹p, q⟩ hpq1 hpq2 rw [Finset.mem_antidiagonal] at hpq1 split_ifs with H · dsimp at H exfalso apply hpq2 rw [← hpq1, H] simp only [add_le_iff_nonpos_left, nonpos_iff_eq_zero, add_tsub_cancel_right] · rfl · intro H exfalso apply H rw [Finset.mem_antidiagonal, tsub_add_cancel_of_le hn] · symm rw [Finset.sum_ite_of_false, Finset.sum_const_zero] simp_rw [Finset.mem_antidiagonal] intro x hx contrapose! hn rw [add_comm, ← hn] at hx exact Nat.le.intro hx } /-- `PolynomialModule R S` is isomorphic to `S[X]` as an `R` module. -/ noncomputable def equivPolynomial {S : Type*} [CommRing S] [Algebra R S] : PolynomialModule R S ≃ₗ[R] S[X] := { (Polynomial.toFinsuppIso S).symm with map_smul' := fun _ _ => rfl } @[simp] lemma equivPolynomialSelf_apply_eq (p : PolynomialModule R R) : equivPolynomialSelf p = equivPolynomial p := rfl @[simp] lemma equivPolynomial_single {S : Type*} [CommRing S] [Algebra R S] (n : ℕ) (x : S) : equivPolynomial (single R n x) = monomial n x := rfl variable (R' : Type*) {M' : Type*} [CommRing R'] [AddCommGroup M'] [Module R' M'] variable [Module R M'] /-- The image of a polynomial under a linear map. -/ noncomputable def map (f : M →ₗ[R] M') : PolynomialModule R M →ₗ[R] PolynomialModule R' M' := Finsupp.mapRange.linearMap f @[simp] theorem map_single (f : M →ₗ[R] M') (i : ℕ) (m : M) : map R' f (single R i m) = single R' i (f m) := Finsupp.mapRange_single (hf := f.map_zero) variable [Algebra R R'] [IsScalarTower R R' M'] theorem map_smul (f : M →ₗ[R] M') (p : R[X]) (q : PolynomialModule R M) : map R' f (p • q) = p.map (algebraMap R R') • map R' f q := by induction q using induction_linear with | zero => rw [smul_zero, map_zero, smul_zero] | add f g e₁ e₂ => rw [smul_add, map_add, e₁, e₂, map_add, smul_add] | single i m => induction p using Polynomial.induction_on' with | add _ _ e₁ e₂ => rw [add_smul, map_add, e₁, e₂, Polynomial.map_add, add_smul] | monomial => rw [monomial_smul_single, map_single, Polynomial.map_monomial, map_single, monomial_smul_single, f.map_smul, algebraMap_smul] /-- Evaluate a polynomial `p : PolynomialModule R M` at `r : R`. -/ @[simps! -isSimp] def eval (r : R) : PolynomialModule R M →ₗ[R] M where toFun p := p.sum fun i m => r ^ i • m map_add' _ _ := Finsupp.sum_add_index' (fun _ => smul_zero _) fun _ _ _ => smul_add _ _ _ map_smul' s m := by refine (Finsupp.sum_smul_index' ?_).trans ?_ · exact fun i => smul_zero _ · simp_rw [RingHom.id_apply, Finsupp.smul_sum] congr ext i c rw [smul_comm] @[simp] theorem eval_single (r : R) (i : ℕ) (m : M) : eval r (single R i m) = r ^ i • m := Finsupp.sum_single_index (smul_zero _) @[simp] theorem eval_lsingle (r : R) (i : ℕ) (m : M) : eval r (lsingle R i m) = r ^ i • m := eval_single r i m theorem eval_smul (p : R[X]) (q : PolynomialModule R M) (r : R) : eval r (p • q) = p.eval r • eval r q := by induction q using induction_linear with | zero => rw [smul_zero, map_zero, smul_zero] | add f g e₁ e₂ => rw [smul_add, map_add, e₁, e₂, map_add, smul_add] | single i m => induction p using Polynomial.induction_on' with | add _ _ e₁ e₂ => rw [add_smul, map_add, Polynomial.eval_add, e₁, e₂, add_smul] | monomial => simp only [monomial_smul_single, Polynomial.eval_monomial, eval_single]; module
@[simp] theorem eval_map (f : M →ₗ[R] M') (q : PolynomialModule R M) (r : R) : eval (algebraMap R R' r) (map R' f q) = f (eval r q) := by induction q using induction_linear with | zero => simp_rw [map_zero] | add f g e₁ e₂ => simp_rw [map_add, e₁, e₂] | single i m => simp only [map_single, eval_single, f.map_smul]; module @[simp] theorem eval_map' (f : M →ₗ[R] M) (q : PolynomialModule R M) (r : R) : eval r (map R f q) = f (eval r q) :=
Mathlib/Algebra/Polynomial/Module/Basic.lean
282
292
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.TrivSqZeroExt /-! # Dual numbers The dual numbers over `R` are of the form `a + bε`, where `a` and `b` are typically elements of a commutative ring `R`, and `ε` is a symbol satisfying `ε^2 = 0` that commutes with every other element. They are a special case of `TrivSqZeroExt R M` with `M = R`. ## Notation In the `DualNumber` locale: * `R[ε]` is a shorthand for `DualNumber R` * `ε` is a shorthand for `DualNumber.eps` ## Main definitions * `DualNumber` * `DualNumber.eps` * `DualNumber.lift` ## Implementation notes Rather than duplicating the API of `TrivSqZeroExt`, this file reuses the functions there. ## References * https://en.wikipedia.org/wiki/Dual_number -/ variable {R A B : Type*} /-- The type of dual numbers, numbers of the form $a + bε$ where $ε^2 = 0$. `R[ε]` is notation for `DualNumber R`. -/ abbrev DualNumber (R : Type*) : Type _ := TrivSqZeroExt R R /-- The unit element $ε$ that squares to zero, with notation `ε`. -/ def DualNumber.eps [Zero R] [One R] : DualNumber R := TrivSqZeroExt.inr 1 @[inherit_doc] scoped[DualNumber] notation "ε" => DualNumber.eps @[inherit_doc] scoped[DualNumber] postfix:1024 "[ε]" => DualNumber open DualNumber namespace DualNumber open TrivSqZeroExt @[simp] theorem fst_eps [Zero R] [One R] : fst ε = (0 : R) := fst_inr _ _ @[simp] theorem snd_eps [Zero R] [One R] : snd ε = (1 : R) := snd_inr _ _ /-- A version of `TrivSqZeroExt.snd_mul` with `*` instead of `•`. -/ @[simp] theorem snd_mul [Semiring R] (x y : R[ε]) : snd (x * y) = fst x * snd y + snd x * fst y := TrivSqZeroExt.snd_mul _ _ @[simp] theorem eps_mul_eps [Semiring R] : (ε * ε : R[ε]) = 0 := inr_mul_inr _ _ _ @[simp] theorem inv_eps [DivisionRing R] : (ε : R[ε])⁻¹ = 0 := TrivSqZeroExt.inv_inr 1 @[simp] theorem inr_eq_smul_eps [MulZeroOneClass R] (r : R) : inr r = (r • ε : R[ε]) := ext (mul_zero r).symm (mul_one r).symm /-- `ε` commutes with every element of the algebra. -/ theorem commute_eps_left [Semiring R] (x : DualNumber R) : Commute ε x := by ext <;> simp /-- `ε` commutes with every element of the algebra. -/ theorem commute_eps_right [Semiring R] (x : DualNumber R) : Commute x ε := (commute_eps_left x).symm variable {A : Type*} [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B] /-- For two `R`-algebra morphisms out of `A[ε]` to agree, it suffices for them to agree on the elements of `A` and the `A`-multiples of `ε`. -/ @[ext 1100] nonrec theorem algHom_ext' ⊃f g : A[ε] →ₐ[R] B⩄ (hinl : f.comp (inlAlgHom _ _ _) = g.comp (inlAlgHom _ _ _)) (hinr : f.toLinearMap ∘ₗ (LinearMap.toSpanSingleton A A[ε] ε).restrictScalars R = g.toLinearMap ∘ₗ (LinearMap.toSpanSingleton A A[ε] ε).restrictScalars R) : f = g := algHom_ext' hinl (by ext a show f (inr a) = g (inr a) simpa only [inr_eq_smul_eps] using DFunLike.congr_fun hinr a) /-- For two `R`-algebra morphisms out of `R[ε]` to agree, it suffices for them to agree on `ε`. -/ @[ext 1200] nonrec theorem algHom_ext ⊃f g : R[ε] →ₐ[R] A⩄ (hε : f ε = g ε) : f = g := by ext dsimp simp only [one_smul, hε] /-- A universal property of the dual numbers, providing a unique `A[ε] →ₐ[R] B` for every map `f : A →ₐ[R] B` and a choice of element `e : B` which squares to `0` and commutes with the range of `f`. This isomorphism is named to match the similar `Complex.lift`. Note that when `f : R →ₐ[R] B := Algebra.ofId R B`, the commutativity assumption is automatic, and we are free to choose any element `e : B`. -/ def lift : {fe : (A →ₐ[R] B) × B // fe.2 * fe.2 = 0 ∧ ∀ a, Commute fe.2 (fe.1 a)} ≃ (A[ε] →ₐ[R] B) := by refine Equiv.trans ?_ TrivSqZeroExt.liftEquiv exact { toFun := fun fe => ⟹ (fe.val.1, MulOpposite.op fe.val.2 • fe.val.1.toLinearMap), fun x y => show (fe.val.1 x * fe.val.2) * (fe.val.1 y * fe.val.2) = 0 by rw [(fe.prop.2 _).mul_mul_mul_comm, fe.prop.1, mul_zero], fun r x => show fe.val.1 (r * x) * fe.val.2 = fe.val.1 r * (fe.val.1 x * fe.val.2) by rw [map_mul, mul_assoc], fun r x => show fe.val.1 (x * r) * fe.val.2 = (fe.val.1 x * fe.val.2) * fe.val.1 r by rw [map_mul, (fe.prop.2 _).right_comm]⟩ invFun := fun fg => ⟹ (fg.val.1, fg.val.2 1), fg.prop.1 _ _, fun a => show fg.val.2 1 * fg.val.1 a = fg.val.1 a * fg.val.2 1 by rw [← fg.prop.2.1, ← fg.prop.2.2, smul_eq_mul, op_smul_eq_mul, mul_one, one_mul]⟩ left_inv := fun fe => Subtype.ext <| Prod.ext rfl <| show fe.val.1 1 * fe.val.2 = fe.val.2 by rw [map_one, one_mul] right_inv := fun fg => Subtype.ext <| Prod.ext rfl <| LinearMap.ext fun x => show fg.val.1 x * fg.val.2 1 = fg.val.2 x by rw [← fg.prop.2.1, smul_eq_mul, mul_one] } theorem lift_apply_apply (fe : {_fe : (A →ₐ[R] B) × B // _}) (a : A[ε]) : lift fe a = fe.val.1 a.fst + fe.val.1 a.snd * fe.val.2 := rfl @[simp] theorem coe_lift_symm_apply (F : A[ε] →ₐ[R] B) : (lift.symm F).val = (F.comp (inlAlgHom _ _ _), F ε) := rfl #adaptation_note /-- https://github.com/leanprover/lean4/pull/5338 The new unused variable linter flags `{fe : (A →ₐ[R] B) × B // _}`. -/ set_option linter.unusedVariables false in /-- When applied to `inl`, `DualNumber.lift` applies the map `f : A →ₐ[R] B`. -/ @[simp] theorem lift_apply_inl (fe : {fe : (A →ₐ[R] B) × B // _}) (a : A) : lift fe (inl a : A[ε]) = fe.val.1 a := by rw [lift_apply_apply, fst_inl, snd_inl, map_zero, zero_mul, add_zero] #adaptation_note /-- https://github.com/leanprover/lean4/pull/5338 The new unused variable linter flags `{fe : (A →ₐ[R] B) × B // _}`. -/ set_option linter.unusedVariables false in /-- Scaling on the left is sent by `DualNumber.lift` to multiplication on the left -/
@[simp] theorem lift_smul (fe : {fe : (A →ₐ[R] B) × B // _}) (a : A) (ad : A[ε]) : lift fe (a • ad) = fe.val.1 a * lift fe ad := by rw [← inl_mul_eq_smul, map_mul, lift_apply_inl]
Mathlib/Algebra/DualNumber.lean
164
166
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.HomotopyCategory import Mathlib.Algebra.Ring.NegOnePow import Mathlib.CategoryTheory.Shift.Quotient import Mathlib.CategoryTheory.Linear.LinearFunctor import Mathlib.Tactic.Linarith /-! # The shift on cochain complexes and on the homotopy category In this file, we show that for any preadditive category `C`, the categories `CochainComplex C â„€` and `HomotopyCategory C (ComplexShape.up â„€)` are equipped with a shift by `â„€`. We also show that if `F : C ⥀ D` is an additive functor, then the functors `F.mapHomologicalComplex (ComplexShape.up â„€)` and `F.mapHomotopyCategory (ComplexShape.up â„€)` commute with the shift by `â„€`. -/ assert_not_exists TwoSidedIdeal universe v v' u u' open CategoryTheory variable (C : Type u) [Category.{v} C] [Preadditive C] {D : Type u'} [Category.{v'} D] [Preadditive D] namespace CochainComplex open HomologicalComplex /-- The shift functor by `n : â„€` on `CochainComplex C â„€` which sends a cochain complex `K` to the complex which is `K.X (i + n)` in degree `i`, and which multiplies the differentials by `(-1)^n`. -/ @[simps] def shiftFunctor (n : â„€) : CochainComplex C â„€ ⥀ CochainComplex C â„€ where obj K := { X := fun i => K.X (i + n) d := fun _ _ => n.negOnePow • K.d _ _ d_comp_d' := by intros simp only [Linear.comp_units_smul, Linear.units_smul_comp, d_comp_d, smul_zero] shape := fun i j hij => by rw [K.shape, smul_zero] intro hij' apply hij dsimp at hij' ⊢ omega } map φ := { f := fun _ => φ.f _ comm' := by intros dsimp simp only [Linear.comp_units_smul, Hom.comm, Linear.units_smul_comp] } map_id := by intros; rfl map_comp := by intros; rfl instance (n : â„€) : (shiftFunctor C n).Additive where variable {C} /-- The canonical isomorphism `((shiftFunctor C n).obj K).X i ≅ K.X m` when `m = i + n`. -/ @[simp] def shiftFunctorObjXIso (K : CochainComplex C â„€) (n i m : â„€) (hm : m = i + n) : ((shiftFunctor C n).obj K).X i ≅ K.X m := K.XIsoOfEq hm.symm section variable (C) attribute [local simp] XIsoOfEq_hom_naturality /-- The shift functor by `n` on `CochainComplex C â„€` identifies to the identity functor when `n = 0`. -/ @[simps!] def shiftFunctorZero' (n : â„€) (h : n = 0) : shiftFunctor C n ≅ 𝟭 _ := NatIso.ofComponents (fun K => Hom.isoOfComponents (fun i => K.shiftFunctorObjXIso _ _ _ (by omega)) (fun _ _ _ => by dsimp; simp [h])) (fun _ ↩ by ext; dsimp; simp) /-- The compatibility of the shift functors on `CochainComplex C â„€` with respect to the addition of integers. -/ @[simps!] def shiftFunctorAdd' (n₁ n₂ n₁₂ : â„€) (h : n₁ + n₂ = n₁₂) : shiftFunctor C n₁₂ ≅ shiftFunctor C n₁ ⋙ shiftFunctor C n₂ := NatIso.ofComponents (fun K => Hom.isoOfComponents (fun i => K.shiftFunctorObjXIso _ _ _ (by omega)) (fun _ _ _ => by subst h dsimp simp only [add_comm n₁ n₂, Int.negOnePow_add, Linear.units_smul_comp, Linear.comp_units_smul, d_comp_XIsoOfEq_hom, smul_smul, XIsoOfEq_hom_comp_d])) (by intros; ext; dsimp; simp) attribute [local simp] XIsoOfEq instance : HasShift (CochainComplex C â„€) â„€ := hasShiftMk _ _ { F := shiftFunctor C zero := shiftFunctorZero' C _ rfl add := fun n₁ n₂ => shiftFunctorAdd' C n₁ n₂ _ rfl } instance (n : â„€) : (CategoryTheory.shiftFunctor (HomologicalComplex C (ComplexShape.up â„€)) n).Additive := (inferInstance : (CochainComplex.shiftFunctor C n).Additive) end @[simp] lemma shiftFunctor_obj_X' (K : CochainComplex C â„€) (n p : â„€) : ((CategoryTheory.shiftFunctor (CochainComplex C â„€) n).obj K).X p = K.X (p + n) := rfl @[simp] lemma shiftFunctor_map_f' {K L : CochainComplex C â„€} (φ : K ⟶ L) (n p : â„€) : ((CategoryTheory.shiftFunctor (CochainComplex C â„€) n).map φ).f p = φ.f (p + n) := rfl @[simp] lemma shiftFunctor_obj_d' (K : CochainComplex C â„€) (n i j : â„€) : ((CategoryTheory.shiftFunctor (CochainComplex C â„€) n).obj K).d i j = n.negOnePow • K.d _ _ := rfl lemma shiftFunctorAdd_inv_app_f (K : CochainComplex C â„€) (a b n : â„€) : ((shiftFunctorAdd (CochainComplex C â„€) a b).inv.app K).f n = (K.XIsoOfEq (by dsimp; rw [add_comm a, add_assoc])).hom := rfl lemma shiftFunctorAdd_hom_app_f (K : CochainComplex C â„€) (a b n : â„€) : ((shiftFunctorAdd (CochainComplex C â„€) a b).hom.app K).f n = (K.XIsoOfEq (by dsimp; rw [add_comm a, add_assoc])).hom := by have : IsIso (((shiftFunctorAdd (CochainComplex C â„€) a b).inv.app K).f n) := by rw [shiftFunctorAdd_inv_app_f] infer_instance rw [← cancel_mono (((shiftFunctorAdd (CochainComplex C â„€) a b).inv.app K).f n), ← comp_f, Iso.hom_inv_id_app, id_f, shiftFunctorAdd_inv_app_f] simp only [XIsoOfEq, eqToIso.hom, eqToHom_trans, eqToHom_refl] lemma shiftFunctorAdd'_inv_app_f' (K : CochainComplex C â„€) (a b ab : â„€) (h : a + b = ab) (n : â„€) : ((CategoryTheory.shiftFunctorAdd' (CochainComplex C â„€) a b ab h).inv.app K).f n = (K.XIsoOfEq (by dsimp; rw [← h, add_assoc, add_comm a])).hom := by subst h rw [shiftFunctorAdd'_eq_shiftFunctorAdd, shiftFunctorAdd_inv_app_f] lemma shiftFunctorAdd'_hom_app_f' (K : CochainComplex C â„€) (a b ab : â„€) (h : a + b = ab) (n : â„€) : ((CategoryTheory.shiftFunctorAdd' (CochainComplex C â„€) a b ab h).hom.app K).f n = (K.XIsoOfEq (by dsimp; rw [← h, add_assoc, add_comm a])).hom := by subst h rw [shiftFunctorAdd'_eq_shiftFunctorAdd, shiftFunctorAdd_hom_app_f]
lemma shiftFunctorZero_inv_app_f (K : CochainComplex C â„€) (n : â„€) : ((CategoryTheory.shiftFunctorZero (CochainComplex C â„€) â„€).inv.app K).f n = (K.XIsoOfEq (by dsimp; rw [add_zero])).hom := rfl lemma shiftFunctorZero_hom_app_f (K : CochainComplex C â„€) (n : â„€) : ((CategoryTheory.shiftFunctorZero (CochainComplex C â„€) â„€).hom.app K).f n = (K.XIsoOfEq (by dsimp; rw [add_zero])).hom := by have : IsIso (((shiftFunctorZero (CochainComplex C â„€) â„€).inv.app K).f n) := by
Mathlib/Algebra/Homology/HomotopyCategory/Shift.lean
153
161
/- Copyright (c) 2022 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.CategoryTheory.Abelian.Basic import Mathlib.CategoryTheory.Adjunction.Limits import Mathlib.CategoryTheory.Limits.Preserves.Shapes.AbelianImages import Mathlib.CategoryTheory.Preadditive.Transfer /-! # Transferring "abelian-ness" across a functor If `C` is an additive category, `D` is an abelian category, we have `F : C ⥀ D` `G : D ⥀ C` (both preserving zero morphisms), `G` is left exact (that is, preserves finite limits), and further we have `adj : G ⊣ F` and `i : F ⋙ G ≅ 𝟭 C`, then `C` is also abelian. A particular example is the transfer of `Abelian` instances from a category `C` to `ShrinkHoms C`; see `ShrinkHoms.abelian`. In this case, we also transfer the `Preadditive` structure. See <https://stacks.math.columbia.edu/tag/03A3> ## Notes The hypotheses, following the statement from the Stacks project, may appear surprising: we don't ask that the counit of the adjunction is an isomorphism, but just that we have some potentially unrelated isomorphism `i : F ⋙ G ≅ 𝟭 C`. However Lemma A1.1.1 from [Elephant] shows that in this situation the counit itself must be an isomorphism, and thus that `C` is a reflective subcategory of `D`. Someone may like to formalize that lemma, and restate this theorem in terms of `Reflective`. (That lemma has a nice string diagrammatic proof that holds in any bicategory.) -/ noncomputable section namespace CategoryTheory open Limits universe v₁ v₂ u₁ u₂ namespace AbelianOfAdjunction variable {C : Type u₁} [Category.{v₁} C] [Preadditive C] variable {D : Type u₂} [Category.{v₂} D] [Abelian D] variable (F : C ⥀ D) variable (G : D ⥀ C) [Functor.PreservesZeroMorphisms G] /-- No point making this an instance, as it requires `i`. -/ theorem hasKernels [PreservesFiniteLimits G] (i : F ⋙ G ≅ 𝟭 C) : HasKernels C := { has_limit := fun f => by have := NatIso.naturality_1 i f simp? at this says simp only [Functor.id_obj, Functor.comp_obj, Functor.comp_map, Functor.id_map] at this rw [← this] haveI : HasKernel (G.map (F.map f) ≫ i.hom.app _) := Limits.hasKernel_comp_mono _ _ apply Limits.hasKernel_iso_comp } /-- No point making this an instance, as it requires `i` and `adj`. -/
theorem hasCokernels (i : F ⋙ G ≅ 𝟭 C) (adj : G ⊣ F) : HasCokernels C := { has_colimit := fun f => by have : PreservesColimits G := adj.leftAdjoint_preservesColimits have := NatIso.naturality_1 i f simp? at this says simp only [Functor.id_obj, Functor.comp_obj, Functor.comp_map, Functor.id_map] at this rw [← this] haveI : HasCokernel (G.map (F.map f) ≫ i.hom.app _) := Limits.hasCokernel_comp_iso _ _ apply Limits.hasCokernel_epi_comp }
Mathlib/CategoryTheory/Abelian/Transfer.lean
64
72
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.Group.Action.Pointwise.Set.Basic import Mathlib.Algebra.Group.Submonoid.Membership import Mathlib.Algebra.Order.BigOperators.Group.List import Mathlib.Order.WellFoundedSet /-! # Pointwise instances on `Submonoid`s and `AddSubmonoid`s This file provides: * `Submonoid.inv` * `AddSubmonoid.neg` and the actions * `Submonoid.pointwiseMulAction` * `AddSubmonoid.pointwiseAddAction` which matches the action of `Set.mulActionSet`. ## Implementation notes Most of the lemmas in this file are direct copies of lemmas from `Mathlib.Algebra.Group.Pointwise.Set.Basic` and `Mathlib.Algebra.Group.Action.Pointwise.Set.Basic`. While the statements of these lemmas are defeq, we repeat them here due to them not being syntactically equal. Before adding new lemmas here, consider if they would also apply to the action on `Set`s. -/ assert_not_exists GroupWithZero open Set Pointwise variable {α G M R A S : Type*} variable [Monoid M] [AddMonoid A] @[to_additive (attr := simp, norm_cast)] lemma coe_mul_coe [SetLike S M] [SubmonoidClass S M] (H : S) : H * H = (H : Set M) := by aesop (add simp mem_mul) set_option linter.unusedVariables false in @[to_additive (attr := simp)] lemma coe_set_pow [SetLike S M] [SubmonoidClass S M] : ∀ {n} (hn : n ≠ 0) (H : S), (H ^ n : Set M) = H | 1, _, H => by simp | n + 2, _, H => by rw [pow_succ, coe_set_pow n.succ_ne_zero, coe_mul_coe] /-! Some lemmas about pointwise multiplication and submonoids. Ideally we put these in `GroupTheory.Submonoid.Basic`, but currently we cannot because that file is imported by this. -/ namespace Submonoid variable {s t u : Set M} @[to_additive] theorem mul_subset {S : Submonoid M} (hs : s ⊆ S) (ht : t ⊆ S) : s * t ⊆ S := mul_subset_iff.2 fun _x hx _y hy ↩ mul_mem (hs hx) (ht hy) @[to_additive] theorem mul_subset_closure (hs : s ⊆ u) (ht : t ⊆ u) : s * t ⊆ Submonoid.closure u := mul_subset (Subset.trans hs Submonoid.subset_closure) (Subset.trans ht Submonoid.subset_closure) @[to_additive] theorem coe_mul_self_eq (s : Submonoid M) : (s : Set M) * s = s := by ext x refine ⟹?_, fun h => ⟹x, h, 1, s.one_mem, mul_one x⟩⟩ rintro ⟹a, ha, b, hb, rfl⟩ exact s.mul_mem ha hb @[to_additive] theorem closure_mul_le (S T : Set M) : closure (S * T) ≀ closure S ⊔ closure T := sInf_le fun _x ⟹_s, hs, _t, ht, hx⟩ => hx ▾ (closure S ⊔ closure T).mul_mem (SetLike.le_def.mp le_sup_left <| subset_closure hs) (SetLike.le_def.mp le_sup_right <| subset_closure ht) @[to_additive] lemma closure_pow_le : ∀ {n}, n ≠ 0 → closure (s ^ n) ≀ closure s | 1, _ => by simp | n + 2, _ => calc closure (s ^ (n + 2)) _ = closure (s ^ (n + 1) * s) := by rw [pow_succ] _ ≀ closure (s ^ (n + 1)) ⊔ closure s := closure_mul_le .. _ ≀ closure s ⊔ closure s := by gcongr ?_ ⊔ _; exact closure_pow_le n.succ_ne_zero _ = closure s := sup_idem _ @[to_additive] lemma closure_pow {n : ℕ} (hs : 1 ∈ s) (hn : n ≠ 0) : closure (s ^ n) = closure s := (closure_pow_le hn).antisymm <| by gcongr; exact subset_pow hs hn @[to_additive] theorem sup_eq_closure_mul (H K : Submonoid M) : H ⊔ K = closure ((H : Set M) * (K : Set M)) := le_antisymm (sup_le (fun h hh => subset_closure ⟹h, hh, 1, K.one_mem, mul_one h⟩) fun k hk => subset_closure ⟹1, H.one_mem, k, hk, one_mul k⟩) ((closure_mul_le _ _).trans <| by rw [closure_eq, closure_eq]) @[to_additive] theorem pow_smul_mem_closure_smul {N : Type*} [CommMonoid N] [MulAction M N] [IsScalarTower M N N] (r : M) (s : Set N) {x : N} (hx : x ∈ closure s) : ∃ n : ℕ, r ^ n • x ∈ closure (r • s) := by induction hx using closure_induction with | mem x hx => exact ⟹1, subset_closure ⟹_, hx, by rw [pow_one]⟩⟩ | one => exact ⟹0, by simpa using one_mem _⟩ | mul x y _ _ hx hy => obtain ⟹⟹nx, hx⟩, ⟹ny, hy⟩⟩ := And.intro hx hy use ny + nx rw [pow_add, mul_smul, ← smul_mul_assoc, mul_comm, ← smul_mul_assoc] exact mul_mem hy hx variable [Group G] /-- The submonoid with every element inverted. -/ @[to_additive "The additive submonoid with every element negated."] protected def inv : Inv (Submonoid G) where inv S := { carrier := (S : Set G)⁻¹ mul_mem' := fun ha hb => by rw [mem_inv, mul_inv_rev]; exact mul_mem hb ha one_mem' := mem_inv.2 <| by rw [inv_one]; exact S.one_mem' } scoped[Pointwise] attribute [instance] Submonoid.inv AddSubmonoid.neg @[to_additive (attr := simp)] theorem coe_inv (S : Submonoid G) : ↑S⁻¹ = (S : Set G)⁻¹ := rfl @[to_additive (attr := simp)] theorem mem_inv {g : G} {S : Submonoid G} : g ∈ S⁻¹ ↔ g⁻¹ ∈ S := Iff.rfl /-- Inversion is involutive on submonoids. -/ @[to_additive "Inversion is involutive on additive submonoids."] def involutiveInv : InvolutiveInv (Submonoid G) := SetLike.coe_injective.involutiveInv _ fun _ => rfl scoped[Pointwise] attribute [instance] Submonoid.involutiveInv AddSubmonoid.involutiveNeg @[to_additive (attr := simp)] theorem inv_le_inv (S T : Submonoid G) : S⁻¹ ≀ T⁻¹ ↔ S ≀ T := SetLike.coe_subset_coe.symm.trans Set.inv_subset_inv @[to_additive] theorem inv_le (S T : Submonoid G) : S⁻¹ ≀ T ↔ S ≀ T⁻¹ := SetLike.coe_subset_coe.symm.trans Set.inv_subset /-- Pointwise inversion of submonoids as an order isomorphism. -/ @[to_additive (attr := simps!) "Pointwise negation of additive submonoids as an order isomorphism"] def invOrderIso : Submonoid G ≃o Submonoid G where toEquiv := Equiv.inv _ map_rel_iff' := inv_le_inv _ _ @[to_additive] theorem closure_inv (s : Set G) : closure s⁻¹ = (closure s)⁻¹ := by apply le_antisymm · rw [closure_le, coe_inv, ← Set.inv_subset, inv_inv] exact subset_closure · rw [inv_le, closure_le, coe_inv, ← Set.inv_subset] exact subset_closure @[to_additive] lemma mem_closure_inv (s : Set G) (x : G) : x ∈ closure s⁻¹ ↔ x⁻¹ ∈ closure s := by rw [closure_inv, mem_inv] @[to_additive (attr := simp)] theorem inv_inf (S T : Submonoid G) : (S ⊓ T)⁻¹ = S⁻¹ ⊓ T⁻¹ := SetLike.coe_injective Set.inter_inv @[to_additive (attr := simp)] theorem inv_sup (S T : Submonoid G) : (S ⊔ T)⁻¹ = S⁻¹ ⊔ T⁻¹ := (invOrderIso : Submonoid G ≃o Submonoid G).map_sup S T @[to_additive (attr := simp)] theorem inv_bot : (⊥ : Submonoid G)⁻¹ = ⊥ := SetLike.coe_injective <| (Set.inv_singleton 1).trans <| congr_arg _ inv_one @[to_additive (attr := simp)] theorem inv_top : (⊀ : Submonoid G)⁻¹ = ⊀ := SetLike.coe_injective <| Set.inv_univ @[to_additive (attr := simp)] theorem inv_iInf {ι : Sort*} (S : ι → Submonoid G) : (⹅ i, S i)⁻¹ = ⹅ i, (S i)⁻¹ := (invOrderIso : Submonoid G ≃o Submonoid G).map_iInf _ @[to_additive (attr := simp)] theorem inv_iSup {ι : Sort*} (S : ι → Submonoid G) : (⹆ i, S i)⁻¹ = ⹆ i, (S i)⁻¹ := (invOrderIso : Submonoid G ≃o Submonoid G).map_iSup _ end Submonoid namespace Submonoid section Monoid variable [Monoid α] [MulDistribMulAction α M] -- todo: add `to_additive`? /-- The action on a submonoid corresponding to applying the action to every element. This is available as an instance in the `Pointwise` locale. -/ protected def pointwiseMulAction : MulAction α (Submonoid M) where smul a S := S.map (MulDistribMulAction.toMonoidEnd _ M a) one_smul S := by change S.map _ = S simpa only [map_one] using S.map_id mul_smul _ _ S := (congr_arg (fun f : Monoid.End M => S.map f) (MonoidHom.map_mul _ _ _)).trans (S.map_map _ _).symm scoped[Pointwise] attribute [instance] Submonoid.pointwiseMulAction @[simp] theorem coe_pointwise_smul (a : α) (S : Submonoid M) : ↑(a • S) = a • (S : Set M) := rfl theorem smul_mem_pointwise_smul (m : M) (a : α) (S : Submonoid M) : m ∈ S → a • m ∈ a • S := (Set.smul_mem_smul_set : _ → _ ∈ a • (S : Set M)) instance : CovariantClass α (Submonoid M) HSMul.hSMul LE.le := ⟹fun _ _ => image_subset _⟩ theorem mem_smul_pointwise_iff_exists (m : M) (a : α) (S : Submonoid M) : m ∈ a • S ↔ ∃ s : M, s ∈ S ∧ a • s = m := (Set.mem_smul_set : m ∈ a • (S : Set M) ↔ _) @[simp] theorem smul_bot (a : α) : a • (⊥ : Submonoid M) = ⊥ := map_bot _ theorem smul_sup (a : α) (S T : Submonoid M) : a • (S ⊔ T) = a • S ⊔ a • T := map_sup _ _ _ theorem smul_closure (a : α) (s : Set M) : a • closure s = closure (a • s) := MonoidHom.map_mclosure _ _ lemma pointwise_isCentralScalar [MulDistribMulAction αᵐᵒᵖ M] [IsCentralScalar α M] : IsCentralScalar α (Submonoid M) := ⟹fun _ S => (congr_arg fun f : Monoid.End M => S.map f) <| MonoidHom.ext <| op_smul_eq_smul _⟩ scoped[Pointwise] attribute [instance] Submonoid.pointwise_isCentralScalar end Monoid section Group variable [Group α] [MulDistribMulAction α M] @[simp] theorem smul_mem_pointwise_smul_iff {a : α} {S : Submonoid M} {x : M} : a • x ∈ a • S ↔ x ∈ S := smul_mem_smul_set_iff theorem mem_pointwise_smul_iff_inv_smul_mem {a : α} {S : Submonoid M} {x : M} : x ∈ a • S ↔ a⁻¹ • x ∈ S := mem_smul_set_iff_inv_smul_mem theorem mem_inv_pointwise_smul_iff {a : α} {S : Submonoid M} {x : M} : x ∈ a⁻¹ • S ↔ a • x ∈ S := mem_inv_smul_set_iff @[simp] theorem pointwise_smul_le_pointwise_smul_iff {a : α} {S T : Submonoid M} : a • S ≀ a • T ↔ S ≀ T := smul_set_subset_smul_set_iff theorem pointwise_smul_subset_iff {a : α} {S T : Submonoid M} : a • S ≀ T ↔ S ≀ a⁻¹ • T := smul_set_subset_iff_subset_inv_smul_set theorem subset_pointwise_smul_iff {a : α} {S T : Submonoid M} : S ≀ a • T ↔ a⁻¹ • S ≀ T := subset_smul_set_iff end Group end Submonoid namespace Set.IsPWO variable [CommMonoid α] [PartialOrder α] [IsOrderedCancelMonoid α] {s : Set α} @[to_additive] theorem submonoid_closure (hpos : ∀ x : α, x ∈ s → 1 ≀ x) (h : s.IsPWO) : IsPWO (Submonoid.closure s : Set α) := by rw [Submonoid.closure_eq_image_prod] refine (h.partiallyWellOrderedOn_sublistForall₂ (· ≀ ·)).image_of_monotone_on ?_ exact fun l1 _ l2 hl2 h12 => h12.prod_le_prod' fun x hx => hpos x <| hl2 x hx end Set.IsPWO
Mathlib/Algebra/Group/Submonoid/Pointwise.lean
512
516
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Algebra.MvPolynomial.Degrees /-! # Variables of polynomials This file establishes many results about the variable sets of a multivariate polynomial. The *variable set* of a polynomial $P \in R[X]$ is a `Finset` containing each $x \in X$ that appears in a monomial in $P$. ## Main declarations * `MvPolynomial.vars p` : the finset of variables occurring in `p`. For example if `p = x⁎y+yz` then `vars p = {x, y, z}` ## Notation As in other polynomial files, we typically use the notation: + `σ τ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `r : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` -/ noncomputable section open Set Function Finsupp AddMonoidAlgebra universe u v w variable {R : Type u} {S : Type v} namespace MvPolynomial variable {σ τ : Type*} {r : R} {e : ℕ} {n m : σ} {s : σ →₀ ℕ} section CommSemiring variable [CommSemiring R] {p q : MvPolynomial σ R} section Vars /-! ### `vars` -/ /-- `vars p` is the set of variables appearing in the polynomial `p` -/ def vars (p : MvPolynomial σ R) : Finset σ := letI := Classical.decEq σ p.degrees.toFinset theorem vars_def [DecidableEq σ] (p : MvPolynomial σ R) : p.vars = p.degrees.toFinset := by rw [vars] convert rfl @[simp] theorem vars_0 : (0 : MvPolynomial σ R).vars = ∅ := by classical rw [vars_def, degrees_zero, Multiset.toFinset_zero] @[simp] theorem vars_monomial (h : r ≠ 0) : (monomial s r).vars = s.support := by classical rw [vars_def, degrees_monomial_eq _ _ h, Finsupp.toFinset_toMultiset] @[simp] theorem vars_C : (C r : MvPolynomial σ R).vars = ∅ := by classical rw [vars_def, degrees_C, Multiset.toFinset_zero] @[simp] theorem vars_X [Nontrivial R] : (X n : MvPolynomial σ R).vars = {n} := by rw [X, vars_monomial (one_ne_zero' R), Finsupp.support_single_ne_zero _ (one_ne_zero' ℕ)] theorem mem_vars (i : σ) : i ∈ p.vars ↔ ∃ d ∈ p.support, i ∈ d.support := by classical simp only [vars_def, Multiset.mem_toFinset, mem_degrees, mem_support_iff, exists_prop] theorem mem_support_not_mem_vars_zero {f : MvPolynomial σ R} {x : σ →₀ ℕ} (H : x ∈ f.support) {v : σ} (h : v ∉ vars f) : x v = 0 := by contrapose! h exact (mem_vars v).mpr ⟹x, H, Finsupp.mem_support_iff.mpr h⟩ theorem vars_add_subset [DecidableEq σ] (p q : MvPolynomial σ R) : (p + q).vars ⊆ p.vars ∪ q.vars := by intro x hx simp only [vars_def, Finset.mem_union, Multiset.mem_toFinset] at hx ⊢ simpa using Multiset.mem_of_le degrees_add_le hx theorem vars_add_of_disjoint [DecidableEq σ] (h : Disjoint p.vars q.vars) : (p + q).vars = p.vars ∪ q.vars := by refine (vars_add_subset p q).antisymm fun x hx => ?_ simp only [vars_def, Multiset.disjoint_toFinset] at h hx ⊢ rwa [degrees_add_of_disjoint h, Multiset.toFinset_union] section Mul theorem vars_mul [DecidableEq σ] (φ ψ : MvPolynomial σ R) : (φ * ψ).vars ⊆ φ.vars ∪ ψ.vars := by simp_rw [vars_def, ← Multiset.toFinset_add, Multiset.toFinset_subset] exact Multiset.subset_of_le degrees_mul_le @[simp] theorem vars_one : (1 : MvPolynomial σ R).vars = ∅ := vars_C theorem vars_pow (φ : MvPolynomial σ R) (n : ℕ) : (φ ^ n).vars ⊆ φ.vars := by classical induction n with | zero => simp | succ n ih => rw [pow_succ'] apply Finset.Subset.trans (vars_mul _ _) exact Finset.union_subset (Finset.Subset.refl _) ih /-- The variables of the product of a family of polynomials are a subset of the union of the sets of variables of each polynomial. -/ theorem vars_prod {ι : Type*} [DecidableEq σ] {s : Finset ι} (f : ι → MvPolynomial σ R) : (∏ i ∈ s, f i).vars ⊆ s.biUnion fun i => (f i).vars := by classical induction s using Finset.induction_on with | empty => simp | insert _ _ hs hsub => simp only [hs, Finset.biUnion_insert, Finset.prod_insert, not_false_iff] apply Finset.Subset.trans (vars_mul _ _) exact Finset.union_subset_union (Finset.Subset.refl _) hsub section IsDomain variable {A : Type*} [CommRing A] [NoZeroDivisors A] theorem vars_C_mul (a : A) (ha : a ≠ 0) (φ : MvPolynomial σ A) : (C a * φ : MvPolynomial σ A).vars = φ.vars := by ext1 i simp only [mem_vars, exists_prop, mem_support_iff] apply exists_congr intro d apply and_congr _ Iff.rfl rw [coeff_C_mul, mul_ne_zero_iff, eq_true ha, true_and] end IsDomain end Mul section Sum variable {ι : Type*} (t : Finset ι) (φ : ι → MvPolynomial σ R) theorem vars_sum_subset [DecidableEq σ] : (∑ i ∈ t, φ i).vars ⊆ Finset.biUnion t fun i => (φ i).vars := by classical induction t using Finset.induction_on with | empty => simp | insert _ _ has hsum => rw [Finset.biUnion_insert, Finset.sum_insert has] refine Finset.Subset.trans (vars_add_subset _ _) (Finset.union_subset_union (Finset.Subset.refl _) ?_) assumption theorem vars_sum_of_disjoint [DecidableEq σ] (h : Pairwise <| (Disjoint on fun i => (φ i).vars)) : (∑ i ∈ t, φ i).vars = Finset.biUnion t fun i => (φ i).vars := by classical induction t using Finset.induction_on with | empty => simp | insert _ _ has hsum => rw [Finset.biUnion_insert, Finset.sum_insert has, vars_add_of_disjoint, hsum]
unfold Pairwise onFun at h rw [hsum] simp only [Finset.disjoint_iff_ne] at h ⊢ intro v hv v2 hv2 rw [Finset.mem_biUnion] at hv2 rcases hv2 with ⟹i, his, hi⟩ refine h ?_ _ hv _ hi rintro rfl contradiction
Mathlib/Algebra/MvPolynomial/Variables.lean
180
189
/- Copyright (c) 2023 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.CharP.Basic import Mathlib.Algebra.CharP.Reduced import Mathlib.FieldTheory.KummerPolynomial import Mathlib.FieldTheory.Separable /-! # Perfect fields and rings In this file we define perfect fields, together with a generalisation to (commutative) rings in prime characteristic. ## Main definitions / statements: * `PerfectRing`: a ring of characteristic `p` (prime) is said to be perfect in the sense of Serre, if its absolute Frobenius map `x ↩ xᵖ` is bijective. * `PerfectField`: a field `K` is said to be perfect if every irreducible polynomial over `K` is separable. * `PerfectRing.toPerfectField`: a field that is perfect in the sense of Serre is a perfect field. * `PerfectField.toPerfectRing`: a perfect field of characteristic `p` (prime) is perfect in the sense of Serre. * `PerfectField.ofCharZero`: all fields of characteristic zero are perfect. * `PerfectField.ofFinite`: all finite fields are perfect. * `PerfectField.separable_iff_squarefree`: a polynomial over a perfect field is separable iff it is square-free. * `Algebra.IsAlgebraic.isSeparable_of_perfectField`, `Algebra.IsAlgebraic.perfectField`: if `L / K` is an algebraic extension, `K` is a perfect field, then `L / K` is separable, and `L` is also a perfect field. -/ open Function Polynomial /-- A perfect ring of characteristic `p` (prime) in the sense of Serre. NB: This is not related to the concept with the same name introduced by Bass (related to projective covers of modules). -/ class PerfectRing (R : Type*) (p : ℕ) [CommSemiring R] [ExpChar R p] : Prop where /-- A ring is perfect if the Frobenius map is bijective. -/ bijective_frobenius : Bijective <| frobenius R p section PerfectRing variable (R : Type*) (p m n : ℕ) [CommSemiring R] [ExpChar R p] /-- For a reduced ring, surjectivity of the Frobenius map is a sufficient condition for perfection. -/ lemma PerfectRing.ofSurjective (R : Type*) (p : ℕ) [CommRing R] [ExpChar R p] [IsReduced R] (h : Surjective <| frobenius R p) : PerfectRing R p := ⟹frobenius_inj R p, h⟩ instance PerfectRing.ofFiniteOfIsReduced (R : Type*) [CommRing R] [ExpChar R p] [Finite R] [IsReduced R] : PerfectRing R p := ofSurjective _ _ <| Finite.surjective_of_injective (frobenius_inj R p) variable [PerfectRing R p] @[simp] theorem bijective_frobenius : Bijective (frobenius R p) := PerfectRing.bijective_frobenius theorem bijective_iterateFrobenius : Bijective (iterateFrobenius R p n) := coe_iterateFrobenius R p n ▾ (bijective_frobenius R p).iterate n @[simp] theorem injective_frobenius : Injective (frobenius R p) := (bijective_frobenius R p).1 @[simp] theorem surjective_frobenius : Surjective (frobenius R p) := (bijective_frobenius R p).2 /-- The Frobenius automorphism for a perfect ring. -/ @[simps! apply] noncomputable def frobeniusEquiv : R ≃+* R := RingEquiv.ofBijective (frobenius R p) PerfectRing.bijective_frobenius @[simp] theorem coe_frobeniusEquiv : ⇑(frobeniusEquiv R p) = frobenius R p := rfl theorem frobeniusEquiv_def (x : R) : frobeniusEquiv R p x = x ^ p := rfl /-- The iterated Frobenius automorphism for a perfect ring. -/ @[simps! apply] noncomputable def iterateFrobeniusEquiv : R ≃+* R := RingEquiv.ofBijective (iterateFrobenius R p n) (bijective_iterateFrobenius R p n) @[simp] theorem coe_iterateFrobeniusEquiv : ⇑(iterateFrobeniusEquiv R p n) = iterateFrobenius R p n := rfl theorem iterateFrobeniusEquiv_def (x : R) : iterateFrobeniusEquiv R p n x = x ^ p ^ n := rfl theorem iterateFrobeniusEquiv_add_apply (x : R) : iterateFrobeniusEquiv R p (m + n) x = iterateFrobeniusEquiv R p m (iterateFrobeniusEquiv R p n x) := iterateFrobenius_add_apply R p m n x theorem iterateFrobeniusEquiv_add : iterateFrobeniusEquiv R p (m + n) = (iterateFrobeniusEquiv R p n).trans (iterateFrobeniusEquiv R p m) := RingEquiv.ext (iterateFrobeniusEquiv_add_apply R p m n) theorem iterateFrobeniusEquiv_symm_add_apply (x : R) : (iterateFrobeniusEquiv R p (m + n)).symm x = (iterateFrobeniusEquiv R p m).symm ((iterateFrobeniusEquiv R p n).symm x) := (iterateFrobeniusEquiv R p (m + n)).injective <| by rw [RingEquiv.apply_symm_apply, add_comm, iterateFrobeniusEquiv_add_apply, RingEquiv.apply_symm_apply, RingEquiv.apply_symm_apply] theorem iterateFrobeniusEquiv_symm_add : (iterateFrobeniusEquiv R p (m + n)).symm = (iterateFrobeniusEquiv R p n).symm.trans (iterateFrobeniusEquiv R p m).symm := RingEquiv.ext (iterateFrobeniusEquiv_symm_add_apply R p m n) theorem iterateFrobeniusEquiv_zero_apply (x : R) : iterateFrobeniusEquiv R p 0 x = x := by rw [iterateFrobeniusEquiv_def, pow_zero, pow_one] theorem iterateFrobeniusEquiv_one_apply (x : R) : iterateFrobeniusEquiv R p 1 x = x ^ p := by rw [iterateFrobeniusEquiv_def, pow_one] @[simp] theorem iterateFrobeniusEquiv_zero : iterateFrobeniusEquiv R p 0 = RingEquiv.refl R := RingEquiv.ext (iterateFrobeniusEquiv_zero_apply R p) @[simp] theorem iterateFrobeniusEquiv_one : iterateFrobeniusEquiv R p 1 = frobeniusEquiv R p := RingEquiv.ext (iterateFrobeniusEquiv_one_apply R p) theorem iterateFrobeniusEquiv_eq_pow : iterateFrobeniusEquiv R p n = frobeniusEquiv R p ^ n := DFunLike.ext' <| show _ = ⇑(RingAut.toPerm _ _) by rw [map_pow, Equiv.Perm.coe_pow]; exact (pow_iterate p n).symm theorem iterateFrobeniusEquiv_symm : (iterateFrobeniusEquiv R p n).symm = (frobeniusEquiv R p).symm ^ n := by rw [iterateFrobeniusEquiv_eq_pow]; exact (inv_pow _ _).symm @[simp] theorem frobeniusEquiv_symm_apply_frobenius (x : R) : (frobeniusEquiv R p).symm (frobenius R p x) = x := leftInverse_surjInv PerfectRing.bijective_frobenius x @[simp] theorem frobenius_apply_frobeniusEquiv_symm (x : R) : frobenius R p ((frobeniusEquiv R p).symm x) = x := surjInv_eq _ _ @[simp] theorem frobenius_comp_frobeniusEquiv_symm : (frobenius R p).comp (frobeniusEquiv R p).symm = RingHom.id R := by ext; simp @[simp] theorem frobeniusEquiv_symm_comp_frobenius : ((frobeniusEquiv R p).symm : R →+* R).comp (frobenius R p) = RingHom.id R := by ext; simp @[simp] theorem frobeniusEquiv_symm_pow_p (x : R) : ((frobeniusEquiv R p).symm x) ^ p = x := frobenius_apply_frobeniusEquiv_symm R p x theorem injective_pow_p {x y : R} (h : x ^ p = y ^ p) : x = y := (frobeniusEquiv R p).injective h lemma polynomial_expand_eq (f : R[X]) : expand R p f = (f.map (frobeniusEquiv R p).symm) ^ p := by rw [← (f.map (S := R) (frobeniusEquiv R p).symm).expand_char p, map_expand, map_map, frobenius_comp_frobeniusEquiv_symm, map_id] @[simp] theorem not_irreducible_expand (R p) [CommSemiring R] [Fact p.Prime] [CharP R p] [PerfectRing R p] (f : R[X]) : ¬ Irreducible (expand R p f) := by rw [polynomial_expand_eq] exact not_irreducible_pow (Fact.out : p.Prime).ne_one instance instPerfectRingProd (S : Type*) [CommSemiring S] [ExpChar S p] [PerfectRing S p] : PerfectRing (R × S) p where bijective_frobenius := (bijective_frobenius R p).prodMap (bijective_frobenius S p) end PerfectRing /-- A perfect field. See also `PerfectRing` for a generalisation in positive characteristic. -/ class PerfectField (K : Type*) [Field K] : Prop where /-- A field is perfect if every irreducible polynomial is separable. -/ separable_of_irreducible : ∀ {f : K[X]}, Irreducible f → f.Separable lemma PerfectRing.toPerfectField (K : Type*) (p : ℕ) [Field K] [ExpChar K p] [PerfectRing K p] : PerfectField K := by obtain hp | ⟹hp⟩ := ‹ExpChar K p› · exact ⟹Irreducible.separable⟩ refine PerfectField.mk fun hf ↩ ?_ rcases separable_or p hf with h | ⟹-, g, -, rfl⟩ · assumption · exfalso; revert hf; haveI := Fact.mk hp; simp namespace PerfectField variable {K : Type*} [Field K] instance ofCharZero [CharZero K] : PerfectField K := ⟹Irreducible.separable⟩ instance ofFinite [Finite K] : PerfectField K := by obtain ⟹p, _instP⟩ := CharP.exists K have : Fact p.Prime := ⟹CharP.char_is_prime K p⟩ exact PerfectRing.toPerfectField K p variable [PerfectField K] /-- A perfect field of characteristic `p` (prime) is a perfect ring. -/ instance toPerfectRing (p : ℕ) [hp : ExpChar K p] : PerfectRing K p := by refine PerfectRing.ofSurjective _ _ fun y ↩ ?_ rcases hp with _ | hp · simp [frobenius] rw [← not_forall_not] apply mt (X_pow_sub_C_irreducible_of_prime hp) apply mt separable_of_irreducible simp [separable_def, isCoprime_zero_right, isUnit_iff_degree_eq_zero, derivative_X_pow, degree_X_pow_sub_C hp.pos, hp.ne_zero] theorem separable_iff_squarefree {g : K[X]} : g.Separable ↔ Squarefree g := by refine ⟹Separable.squarefree, fun sqf ↩ isCoprime_of_irreducible_dvd (sqf.ne_zero ·.1) ?_⟩ rintro p (h : Irreducible p) ⟹q, rfl⟩ (dvd : p ∣ derivative (p * q)) replace dvd : p ∣ q := by rw [derivative_mul, dvd_add_left (dvd_mul_right p _)] at dvd exact (separable_of_irreducible h).dvd_of_dvd_mul_left dvd exact (h.1 : ¬ IsUnit p) (sqf _ <| mul_dvd_mul_left _ dvd) end PerfectField /-- If `L / K` is an algebraic extension, `K` is a perfect field, then `L / K` is separable. -/ instance Algebra.IsAlgebraic.isSeparable_of_perfectField {K L : Type*} [Field K] [Field L] [Algebra K L] [Algebra.IsAlgebraic K L] [PerfectField K] : Algebra.IsSeparable K L := ⟹fun x ↩ PerfectField.separable_of_irreducible <| minpoly.irreducible (Algebra.IsIntegral.isIntegral x)⟩ /-- If `L / K` is an algebraic extension, `K` is a perfect field, then so is `L`. -/ theorem Algebra.IsAlgebraic.perfectField {K L : Type*} [Field K] [Field L] [Algebra K L] [Algebra.IsAlgebraic K L] [PerfectField K] : PerfectField L := ⟹fun {f} hf ↩ by obtain ⟹_, _, hi, h⟩ := hf.exists_dvd_monic_irreducible_of_isIntegral (K := K) exact (PerfectField.separable_of_irreducible hi).map |>.of_dvd h⟩ namespace Polynomial variable {R : Type*} [CommRing R] [IsDomain R] (p n : ℕ) [ExpChar R p] (f : R[X]) open Multiset theorem roots_expand_pow_map_iterateFrobenius_le : (expand R (p ^ n) f).roots.map (iterateFrobenius R p n) ≀ p ^ n • f.roots := by classical refine le_iff_count.2 fun r ↩ ?_ by_cases h : ∃ s, r = s ^ p ^ n · obtain ⟹s, rfl⟩ := h simp_rw [count_nsmul, count_roots, ← rootMultiplicity_expand_pow, ← count_roots, count_map, count_eq_card_filter_eq] exact card_le_card (monotone_filter_right _ fun _ h ↩ iterateFrobenius_inj R p n h) convert Nat.zero_le _ simp_rw [count_map, card_eq_zero] exact ext' fun t ↩ count_zero t ▾ count_filter_of_neg fun h' ↩ h ⟹t, h'⟩ theorem roots_expand_map_frobenius_le : (expand R p f).roots.map (frobenius R p) ≀ p • f.roots := by rw [← iterateFrobenius_one] convert ← roots_expand_pow_map_iterateFrobenius_le p 1 f <;> apply pow_one theorem roots_expand_pow_image_iterateFrobenius_subset [DecidableEq R] : (expand R (p ^ n) f).roots.toFinset.image (iterateFrobenius R p n) ⊆ f.roots.toFinset := by rw [Finset.image_toFinset, ← (roots f).toFinset_nsmul _ (expChar_pow_pos R p n).ne', toFinset_subset] exact subset_of_le (roots_expand_pow_map_iterateFrobenius_le p n f) theorem roots_expand_image_frobenius_subset [DecidableEq R] : (expand R p f).roots.toFinset.image (frobenius R p) ⊆ f.roots.toFinset := by rw [← iterateFrobenius_one] convert ← roots_expand_pow_image_iterateFrobenius_subset p 1 f apply pow_one section PerfectRing variable {p n f} variable [PerfectRing R p] theorem roots_expand_pow : (expand R (p ^ n) f).roots = p ^ n • f.roots.map (iterateFrobeniusEquiv R p n).symm := by classical refine ext' fun r ↩ ?_ rw [count_roots, rootMultiplicity_expand_pow, ← count_roots, count_nsmul, count_map, count_eq_card_filter_eq]; congr; ext exact (iterateFrobeniusEquiv R p n).eq_symm_apply.symm theorem roots_expand : (expand R p f).roots = p • f.roots.map (frobeniusEquiv R p).symm := by conv_lhs => rw [← pow_one p, roots_expand_pow, iterateFrobeniusEquiv_eq_pow, pow_one] rfl theorem roots_X_pow_char_pow_sub_C {y : R} : (X ^ p ^ n - C y).roots = p ^ n • {(iterateFrobeniusEquiv R p n).symm y} := by have H := roots_expand_pow (p := p) (n := n) (f := X - C y) rwa [roots_X_sub_C, Multiset.map_singleton, map_sub, expand_X, expand_C] at H theorem roots_X_pow_char_pow_sub_C_pow {y : R} {m : ℕ} : ((X ^ p ^ n - C y) ^ m).roots = (m * p ^ n) • {(iterateFrobeniusEquiv R p n).symm y} := by rw [roots_pow, roots_X_pow_char_pow_sub_C, mul_smul] theorem roots_X_pow_char_sub_C {y : R} : (X ^ p - C y).roots = p • {(frobeniusEquiv R p).symm y} := by have H := roots_X_pow_char_pow_sub_C (p := p) (n := 1) (y := y) rwa [pow_one, iterateFrobeniusEquiv_one] at H theorem roots_X_pow_char_sub_C_pow {y : R} {m : ℕ} : ((X ^ p - C y) ^ m).roots = (m * p) • {(frobeniusEquiv R p).symm y} := by have H := roots_X_pow_char_pow_sub_C_pow (p := p) (n := 1) (y := y) (m := m) rwa [pow_one, iterateFrobeniusEquiv_one] at H theorem roots_expand_pow_map_iterateFrobenius : (expand R (p ^ n) f).roots.map (iterateFrobenius R p n) = p ^ n • f.roots := by simp_rw [← coe_iterateFrobeniusEquiv, roots_expand_pow, Multiset.map_nsmul, Multiset.map_map, comp_apply, RingEquiv.apply_symm_apply, map_id'] theorem roots_expand_map_frobenius : (expand R p f).roots.map (frobenius R p) = p • f.roots := by simp [roots_expand, Multiset.map_nsmul] theorem roots_expand_image_iterateFrobenius [DecidableEq R] : (expand R (p ^ n) f).roots.toFinset.image (iterateFrobenius R p n) = f.roots.toFinset := by rw [Finset.image_toFinset, roots_expand_pow_map_iterateFrobenius, (roots f).toFinset_nsmul _ (expChar_pow_pos R p n).ne']
theorem roots_expand_image_frobenius [DecidableEq R] : (expand R p f).roots.toFinset.image (frobenius R p) = f.roots.toFinset := by rw [Finset.image_toFinset, roots_expand_map_frobenius,
Mathlib/FieldTheory/Perfect.lean
321
324
/- 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] 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 ext i j simp [LinearMap.toMatrix_apply, Matrix.one_apply, Finsupp.single_apply, eq_comm] theorem LinearMap.toMatrix_smulBasis_left {G} [Group G] [DistribMulAction G M₁] [SMulCommClass G R M₁] (g : G) (f : M₁ →ₗ[R] M₂) : LinearMap.toMatrix (g • v₁) v₂ f = LinearMap.toMatrix v₁ v₂ (f ∘ₗ DistribMulAction.toLinearMap _ _ g) := by ext rw [LinearMap.toMatrix_apply, LinearMap.toMatrix_apply] dsimp theorem LinearMap.toMatrix_smulBasis_right {G} [Group G] [DistribMulAction G M₂] [SMulCommClass G R M₂] (g : G) (f : M₁ →ₗ[R] M₂) : LinearMap.toMatrix v₁ (g • v₂) f = LinearMap.toMatrix v₁ v₂ (DistribMulAction.toLinearMap _ _ g⁻¹ ∘ₗ f) := by ext rw [LinearMap.toMatrix_apply, LinearMap.toMatrix_apply] dsimp end Finite variable {R : Type*} [CommSemiring R] variable {l m n : Type*} [Fintype n] [Fintype 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₂) theorem Matrix.toLin_apply (M : Matrix m n R) (v : M₁) : Matrix.toLin v₁ v₂ M v = ∑ j, (M *áµ¥ v₁.repr v) j • v₂ j := show v₂.equivFun.symm (Matrix.toLin' M (v₁.repr v)) = _ by rw [Matrix.toLin'_apply, v₂.equivFun_symm_apply] @[simp] theorem Matrix.toLin_self (M : Matrix m n R) (i : n) : Matrix.toLin v₁ v₂ M (v₁ i) = ∑ j, M j i • v₂ j := by rw [Matrix.toLin_apply, Finset.sum_congr rfl fun j _hj ↩ ?_] rw [Basis.repr_self, Matrix.mulVec, dotProduct, Finset.sum_eq_single i, Finsupp.single_eq_same, mul_one] · intro i' _ i'_ne rw [Finsupp.single_eq_of_ne i'_ne.symm, mul_zero] · intros have := Finset.mem_univ i contradiction variable {M₃ : Type*} [AddCommMonoid M₃] [Module R M₃] (v₃ : Basis l R M₃) theorem LinearMap.toMatrix_comp [Finite l] [DecidableEq m] (f : M₂ →ₗ[R] M₃) (g : M₁ →ₗ[R] M₂) : LinearMap.toMatrix v₁ v₃ (f.comp g) = LinearMap.toMatrix v₂ v₃ f * LinearMap.toMatrix v₁ v₂ g := by simp_rw [LinearMap.toMatrix, LinearEquiv.trans_apply, LinearEquiv.arrowCongr_comp _ v₂.equivFun, LinearMap.toMatrix'_comp] theorem LinearMap.toMatrix_mul (f g : M₁ →ₗ[R] M₁) : LinearMap.toMatrix v₁ v₁ (f * g) = LinearMap.toMatrix v₁ v₁ f * LinearMap.toMatrix v₁ v₁ g := by rw [Module.End.mul_eq_comp, LinearMap.toMatrix_comp v₁ v₁ v₁ f g] lemma LinearMap.toMatrix_pow (f : M₁ →ₗ[R] M₁) (k : ℕ) : (toMatrix v₁ v₁ f) ^ k = toMatrix v₁ v₁ (f ^ k) := by induction k with | zero => simp | succ k ih => rw [pow_succ, pow_succ, ih, ← toMatrix_mul] theorem Matrix.toLin_mul [Finite l] [DecidableEq m] (A : Matrix l m R) (B : Matrix m n R) : Matrix.toLin v₁ v₃ (A * B) = (Matrix.toLin v₂ v₃ A).comp (Matrix.toLin v₁ v₂ B) := by apply (LinearMap.toMatrix v₁ v₃).injective haveI : DecidableEq l := fun _ _ ↩ Classical.propDecidable _ rw [LinearMap.toMatrix_comp v₁ v₂ v₃] repeat' rw [LinearMap.toMatrix_toLin] /-- Shortcut lemma for `Matrix.toLin_mul` and `LinearMap.comp_apply`. -/ theorem Matrix.toLin_mul_apply [Finite l] [DecidableEq m] (A : Matrix l m R) (B : Matrix m n R) (x) : Matrix.toLin v₁ v₃ (A * B) x = (Matrix.toLin v₂ v₃ A) (Matrix.toLin v₁ v₂ B x) := by rw [Matrix.toLin_mul v₁ v₂, LinearMap.comp_apply] /-- If `M` and `M` are each other's inverse matrices, `Matrix.toLin M` and `Matrix.toLin M'` form a linear equivalence. -/ @[simps] def Matrix.toLinOfInv [DecidableEq m] {M : Matrix m n R} {M' : Matrix n m R} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : M₁ ≃ₗ[R] M₂ := { Matrix.toLin v₁ v₂ M with toFun := Matrix.toLin v₁ v₂ M invFun := Matrix.toLin v₂ v₁ M' left_inv := fun x ↩ by rw [← Matrix.toLin_mul_apply, hM'M, Matrix.toLin_one, id_apply] right_inv := fun x ↩ by rw [← Matrix.toLin_mul_apply, hMM', Matrix.toLin_one, id_apply] } /-- Given a basis of a module `M₁` over a commutative ring `R`, we get an algebra equivalence between linear maps `M₁ →ₗ M₁` and square matrices over `R` indexed by the basis. -/ def LinearMap.toMatrixAlgEquiv : (M₁ →ₗ[R] M₁) ≃ₐ[R] Matrix n n R := AlgEquiv.ofLinearEquiv (LinearMap.toMatrix v₁ v₁) (LinearMap.toMatrix_one v₁) (LinearMap.toMatrix_mul v₁) /-- Given a basis of a module `M₁` over a commutative ring `R`, we get an algebra equivalence between square matrices over `R` indexed by the basis and linear maps `M₁ →ₗ M₁`. -/ def Matrix.toLinAlgEquiv : Matrix n n R ≃ₐ[R] M₁ →ₗ[R] M₁ := (LinearMap.toMatrixAlgEquiv v₁).symm @[simp] theorem LinearMap.toMatrixAlgEquiv_symm : (LinearMap.toMatrixAlgEquiv v₁).symm = Matrix.toLinAlgEquiv v₁ := rfl @[simp] theorem Matrix.toLinAlgEquiv_symm : (Matrix.toLinAlgEquiv v₁).symm = LinearMap.toMatrixAlgEquiv v₁ := rfl @[simp] theorem Matrix.toLinAlgEquiv_toMatrixAlgEquiv (f : M₁ →ₗ[R] M₁) : Matrix.toLinAlgEquiv v₁ (LinearMap.toMatrixAlgEquiv v₁ f) = f := by rw [← Matrix.toLinAlgEquiv_symm, AlgEquiv.apply_symm_apply] @[simp] theorem LinearMap.toMatrixAlgEquiv_toLinAlgEquiv (M : Matrix n n R) : LinearMap.toMatrixAlgEquiv v₁ (Matrix.toLinAlgEquiv v₁ M) = M := by rw [← Matrix.toLinAlgEquiv_symm, AlgEquiv.symm_apply_apply] theorem LinearMap.toMatrixAlgEquiv_apply (f : M₁ →ₗ[R] M₁) (i j : n) : LinearMap.toMatrixAlgEquiv v₁ f i j = v₁.repr (f (v₁ j)) i := by simp [LinearMap.toMatrixAlgEquiv, LinearMap.toMatrix_apply] theorem LinearMap.toMatrixAlgEquiv_transpose_apply (f : M₁ →ₗ[R] M₁) (j : n) : (LinearMap.toMatrixAlgEquiv v₁ f)ᵀ j = v₁.repr (f (v₁ j)) := funext fun i ↩ f.toMatrix_apply _ _ i j theorem LinearMap.toMatrixAlgEquiv_apply' (f : M₁ →ₗ[R] M₁) (i j : n) : LinearMap.toMatrixAlgEquiv v₁ f i j = v₁.repr (f (v₁ j)) i := LinearMap.toMatrixAlgEquiv_apply v₁ f i j theorem LinearMap.toMatrixAlgEquiv_transpose_apply' (f : M₁ →ₗ[R] M₁) (j : n) : (LinearMap.toMatrixAlgEquiv v₁ f)ᵀ j = v₁.repr (f (v₁ j)) := LinearMap.toMatrixAlgEquiv_transpose_apply v₁ f j theorem Matrix.toLinAlgEquiv_apply (M : Matrix n n R) (v : M₁) : Matrix.toLinAlgEquiv v₁ M v = ∑ j, (M *áµ¥ v₁.repr v) j • v₁ j := show v₁.equivFun.symm (Matrix.toLinAlgEquiv' M (v₁.repr v)) = _ by rw [Matrix.toLinAlgEquiv'_apply, v₁.equivFun_symm_apply] @[simp] theorem Matrix.toLinAlgEquiv_self (M : Matrix n n R) (i : n) : Matrix.toLinAlgEquiv v₁ M (v₁ i) = ∑ j, M j i • v₁ j := Matrix.toLin_self _ _ _ _ theorem LinearMap.toMatrixAlgEquiv_id : LinearMap.toMatrixAlgEquiv v₁ id = 1 := by simp_rw [LinearMap.toMatrixAlgEquiv, AlgEquiv.ofLinearEquiv_apply, LinearMap.toMatrix_id] theorem Matrix.toLinAlgEquiv_one : Matrix.toLinAlgEquiv v₁ 1 = LinearMap.id := by rw [← LinearMap.toMatrixAlgEquiv_id v₁, Matrix.toLinAlgEquiv_toMatrixAlgEquiv] theorem LinearMap.toMatrixAlgEquiv_reindexRange [DecidableEq M₁] (f : M₁ →ₗ[R] M₁) (k i : n) : LinearMap.toMatrixAlgEquiv v₁.reindexRange f ⟹v₁ k, Set.mem_range_self k⟩ ⟹v₁ i, Set.mem_range_self i⟩ = LinearMap.toMatrixAlgEquiv v₁ f k i := by simp_rw [LinearMap.toMatrixAlgEquiv_apply, Basis.reindexRange_self, Basis.reindexRange_repr] theorem LinearMap.toMatrixAlgEquiv_comp (f g : M₁ →ₗ[R] M₁) : LinearMap.toMatrixAlgEquiv v₁ (f.comp g) = LinearMap.toMatrixAlgEquiv v₁ f * LinearMap.toMatrixAlgEquiv v₁ g := by simp [LinearMap.toMatrixAlgEquiv, LinearMap.toMatrix_comp v₁ v₁ v₁ f g] theorem LinearMap.toMatrixAlgEquiv_mul (f g : M₁ →ₗ[R] M₁) : LinearMap.toMatrixAlgEquiv v₁ (f * g) = LinearMap.toMatrixAlgEquiv v₁ f * LinearMap.toMatrixAlgEquiv v₁ g := by rw [Module.End.mul_eq_comp, LinearMap.toMatrixAlgEquiv_comp v₁ f g] theorem Matrix.toLinAlgEquiv_mul (A B : Matrix n n R) : Matrix.toLinAlgEquiv v₁ (A * B) = (Matrix.toLinAlgEquiv v₁ A).comp (Matrix.toLinAlgEquiv v₁ B) := by convert Matrix.toLin_mul v₁ v₁ v₁ A B @[simp] theorem Matrix.toLin_finTwoProd_apply (a b c d : R) (x : R × R) : Matrix.toLin (Basis.finTwoProd R) (Basis.finTwoProd R) !![a, b; c, d] x = (a * x.fst + b * x.snd, c * x.fst + d * x.snd) := by simp [Matrix.toLin_apply, Matrix.mulVec, dotProduct] theorem Matrix.toLin_finTwoProd (a b c d : R) : Matrix.toLin (Basis.finTwoProd R) (Basis.finTwoProd R) !![a, b; c, d] = (a • LinearMap.fst R R R + b • LinearMap.snd R R R).prod (c • LinearMap.fst R R R + d • LinearMap.snd R R R) := LinearMap.ext <| Matrix.toLin_finTwoProd_apply _ _ _ _ @[simp] theorem toMatrix_distrib_mul_action_toLinearMap (x : R) : LinearMap.toMatrix v₁ v₁ (DistribMulAction.toLinearMap R M₁ x) = Matrix.diagonal fun _ ↩ x := by ext rw [LinearMap.toMatrix_apply, DistribMulAction.toLinearMap_apply, LinearEquiv.map_smul, Basis.repr_self, Finsupp.smul_single_one, Finsupp.single_eq_pi_single, Matrix.diagonal_apply, Pi.single_apply] lemma LinearMap.toMatrix_prodMap [DecidableEq m] [DecidableEq (n ⊕ m)] (φ₁ : Module.End R M₁) (φ₂ : Module.End R M₂) : toMatrix (v₁.prod v₂) (v₁.prod v₂) (φ₁.prodMap φ₂) = Matrix.fromBlocks (toMatrix v₁ v₁ φ₁) 0 0 (toMatrix v₂ v₂ φ₂) := by ext (i|i) (j|j) <;> simp [toMatrix] end ToMatrix namespace Algebra section Lmul variable {R S : Type*} [CommSemiring R] [Semiring S] [Algebra R S] variable {m : Type*} [Fintype m] [DecidableEq m] (b : Basis m R S) theorem toMatrix_lmul' (x : S) (i j) : LinearMap.toMatrix b b (lmul R S x) i j = b.repr (x * b j) i := by simp only [LinearMap.toMatrix_apply', coe_lmul_eq_mul, LinearMap.mul_apply'] @[simp] theorem toMatrix_lsmul (x : R) : LinearMap.toMatrix b b (Algebra.lsmul R R S x) = Matrix.diagonal fun _ ↩ x := toMatrix_distrib_mul_action_toLinearMap b x /-- `leftMulMatrix b x` is the matrix corresponding to the linear map `fun y ↩ x * y`. `leftMulMatrix_eq_repr_mul` gives a formula for the entries of `leftMulMatrix`. This definition is useful for doing (more) explicit computations with `LinearMap.mulLeft`, such as the trace form or norm map for algebras. -/ noncomputable def leftMulMatrix : S →ₐ[R] Matrix m m R where toFun x := LinearMap.toMatrix b b (Algebra.lmul R S x) map_zero' := by rw [map_zero, LinearEquiv.map_zero] map_one' := by rw [map_one, LinearMap.toMatrix_one] map_add' x y := by rw [map_add, LinearEquiv.map_add] map_mul' x y := by rw [map_mul, LinearMap.toMatrix_mul] commutes' r := by ext rw [lmul_algebraMap, toMatrix_lsmul, algebraMap_eq_diagonal, Pi.algebraMap_def, Algebra.id.map_eq_self] theorem leftMulMatrix_apply (x : S) : leftMulMatrix b x = LinearMap.toMatrix b b (lmul R S x) := rfl theorem leftMulMatrix_eq_repr_mul (x : S) (i j) : leftMulMatrix b x i j = b.repr (x * b j) i := by -- This is defeq to just `toMatrix_lmul' b x i j`, -- but the unfolding goes a lot faster with this explicit `rw`. rw [leftMulMatrix_apply, toMatrix_lmul' b x i j] theorem leftMulMatrix_mulVec_repr (x y : S) : leftMulMatrix b x *áµ¥ b.repr y = b.repr (x * y) := (LinearMap.mulLeft R x).toMatrix_mulVec_repr b b y @[simp] theorem toMatrix_lmul_eq (x : S) : LinearMap.toMatrix b b (LinearMap.mulLeft R x) = leftMulMatrix b x := rfl theorem leftMulMatrix_injective : Function.Injective (leftMulMatrix b) := fun x x' h ↩ calc x = Algebra.lmul R S x 1 := (mul_one x).symm _ = Algebra.lmul R S x' 1 := by rw [(LinearMap.toMatrix b b).injective h] _ = x' := mul_one x' @[simp] theorem smul_leftMulMatrix {G} [Group G] [DistribMulAction G S] [SMulCommClass G R S] [SMulCommClass G S S] (g : G) (x) : leftMulMatrix (g • b) x = leftMulMatrix b x := by ext simp_rw [leftMulMatrix_apply, LinearMap.toMatrix_apply, coe_lmul_eq_mul, LinearMap.mul_apply', Basis.repr_smul, Basis.smul_apply, LinearEquiv.trans_apply, DistribMulAction.toLinearEquiv_symm_apply, mul_smul_comm, inv_smul_smul] variable {A M n : Type*} [Fintype n] [DecidableEq n] [CommSemiring A] [AddCommMonoid M] [Module R M] [Module A M] [Algebra R A] [IsScalarTower R A M] (bA : Basis m R A) (bM : Basis n A M) lemma _root_.LinearMap.restrictScalars_toMatrix (f : M →ₗ[A] M) : (f.restrictScalars R).toMatrix (bA.smulTower' bM) (bA.smulTower' bM) = ((f.toMatrix bM bM).map (leftMulMatrix bA)).comp _ _ _ _ _ := by ext; simp [toMatrix, Basis.repr, Algebra.leftMulMatrix_apply, Basis.smulTower'_repr, Basis.smulTower'_apply, mul_comm] end Lmul section LmulTower variable {R S T : Type*} [CommSemiring R] [CommSemiring S] [Semiring T] variable [Algebra R S] [Algebra S T] [Algebra R T] [IsScalarTower R S T]
variable {m n : Type*} [Fintype m] [Fintype n] [DecidableEq m] [DecidableEq n] variable (b : Basis m R S) (c : Basis n S T) theorem smulTower_leftMulMatrix (x) (ik jk) : leftMulMatrix (b.smulTower c) x ik jk =
Mathlib/LinearAlgebra/Matrix/ToLin.lean
869
873
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Yakov Pechersky, Eric Wieser -/ import Mathlib.Data.List.Basic /-! # Properties of `List.enum` ## Deprecation note Many lemmas in this file have been replaced by theorems in Lean4, in terms of `xs[i]?` and `xs[i]` rather than `get` and `get?`. The deprecated results here are unused in Mathlib. Any downstream users who can not easily adapt may remove the deprecations as needed. -/ namespace List variable {α : Type*} theorem forall_mem_zipIdx {l : List α} {n : ℕ} {p : α × ℕ → Prop} : (∀ x ∈ l.zipIdx n, p x) ↔ ∀ (i : ℕ) (_ : i < length l), p (l[i], n + i) := by simp only [forall_mem_iff_getElem, getElem_zipIdx, length_zipIdx] /-- Variant of `forall_mem_zipIdx` with the `zipIdx` argument specialized to `0`. -/ theorem forall_mem_zipIdx' {l : List α} {p : α × ℕ → Prop} : (∀ x ∈ l.zipIdx, p x) ↔ ∀ (i : ℕ) (_ : i < length l), p (l[i], i) := forall_mem_zipIdx.trans <| by simp theorem exists_mem_zipIdx {l : List α} {n : ℕ} {p : α × ℕ → Prop} : (∃ x ∈ l.zipIdx n, p x) ↔ ∃ (i : ℕ) (_ : i < length l), p (l[i], n + i) := by simp only [exists_mem_iff_getElem, getElem_zipIdx, length_zipIdx] /-- Variant of `exists_mem_zipIdx` with the `zipIdx` argument specialized to `0`. -/ theorem exists_mem_zipIdx' {l : List α} {p : α × ℕ → Prop} : (∃ x ∈ l.zipIdx, p x) ↔ ∃ (i : ℕ) (_ : i < length l), p (l[i], i) := exists_mem_zipIdx.trans <| by simp @[deprecated (since := "2025-01-28")] alias forall_mem_enumFrom := forall_mem_zipIdx @[deprecated (since := "2025-01-28")] alias forall_mem_enum := forall_mem_zipIdx' @[deprecated (since := "2025-01-28")] alias exists_mem_enumFrom := exists_mem_zipIdx @[deprecated (since := "2025-01-28")] alias exists_mem_enum := exists_mem_zipIdx' end List
Mathlib/Data/List/Enum.lean
141
142
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Topology.Continuous import Mathlib.Topology.Defs.Induced /-! # Ordering on topologies and (co)induced topologies Topologies on a fixed type `α` are ordered, by reverse inclusion. That is, for topologies `t₁` and `t₂` on `α`, we write `t₁ ≀ t₂` if every set open in `t₂` is also open in `t₁`. (One also calls `t₁` *finer* than `t₂`, and `t₂` *coarser* than `t₁`.) Any function `f : α → β` induces * `TopologicalSpace.induced f : TopologicalSpace β → TopologicalSpace α`; * `TopologicalSpace.coinduced f : TopologicalSpace α → TopologicalSpace β`. Continuity, the ordering on topologies and (co)induced topologies are related as follows: * The identity map `(α, t₁) → (α, t₂)` is continuous iff `t₁ ≀ t₂`. * A map `f : (α, t) → (β, u)` is continuous * iff `t ≀ TopologicalSpace.induced f u` (`continuous_iff_le_induced`) * iff `TopologicalSpace.coinduced f t ≀ u` (`continuous_iff_coinduced_le`). Topologies on `α` form a complete lattice, with `⊥` the discrete topology and `⊀` the indiscrete topology. For a function `f : α → β`, `(TopologicalSpace.coinduced f, TopologicalSpace.induced f)` is a Galois connection between topologies on `α` and topologies on `β`. ## Implementation notes There is a Galois insertion between topologies on `α` (with the inclusion ordering) and all collections of sets in `α`. The complete lattice structure on topologies on `α` is defined as the reverse of the one obtained via this Galois insertion. More precisely, we use the corresponding Galois coinsertion between topologies on `α` (with the reversed inclusion ordering) and collections of sets in `α` (with the reversed inclusion ordering). ## Tags finer, coarser, induced topology, coinduced topology -/ open Function Set Filter Topology universe u v w namespace TopologicalSpace variable {α : Type u} /-- The open sets of the least topology containing a collection of basic sets. -/ inductive GenerateOpen (g : Set (Set α)) : Set α → Prop | basic : ∀ s ∈ g, GenerateOpen g s | univ : GenerateOpen g univ | inter : ∀ s t, GenerateOpen g s → GenerateOpen g t → GenerateOpen g (s ∩ t) | sUnion : ∀ S : Set (Set α), (∀ s ∈ S, GenerateOpen g s) → GenerateOpen g (⋃₀ S) /-- The smallest topological space containing the collection `g` of basic sets -/ def generateFrom (g : Set (Set α)) : TopologicalSpace α where IsOpen := GenerateOpen g isOpen_univ := GenerateOpen.univ isOpen_inter := GenerateOpen.inter isOpen_sUnion := GenerateOpen.sUnion theorem isOpen_generateFrom_of_mem {g : Set (Set α)} {s : Set α} (hs : s ∈ g) : IsOpen[generateFrom g] s := GenerateOpen.basic s hs theorem nhds_generateFrom {g : Set (Set α)} {a : α} : @nhds α (generateFrom g) a = ⹅ s ∈ { s | a ∈ s ∧ s ∈ g }, 𝓟 s := by letI := generateFrom g rw [nhds_def] refine le_antisymm (biInf_mono fun s ⟹as, sg⟩ => ⟹as, .basic _ sg⟩) <| le_iInf₂ ?_ rintro s ⟹ha, hs⟩ induction hs with | basic _ hs => exact iInf₂_le _ ⟹ha, hs⟩ | univ => exact le_top.trans_eq principal_univ.symm | inter _ _ _ _ hs ht => exact (le_inf (hs ha.1) (ht ha.2)).trans_eq inf_principal | sUnion _ _ hS => let ⟹t, htS, hat⟩ := ha exact (hS t htS hat).trans (principal_mono.2 <| subset_sUnion_of_mem htS) lemma tendsto_nhds_generateFrom_iff {β : Type*} {m : α → β} {f : Filter α} {g : Set (Set β)} {b : β} : Tendsto m f (@nhds β (generateFrom g) b) ↔ ∀ s ∈ g, b ∈ s → m ⁻¹' s ∈ f := by simp only [nhds_generateFrom, @forall_swap (b ∈ _), tendsto_iInf, mem_setOf_eq, and_imp, tendsto_principal]; rfl /-- Construct a topology on α given the filter of neighborhoods of each point of α. -/ protected def mkOfNhds (n : α → Filter α) : TopologicalSpace α where IsOpen s := ∀ a ∈ s, s ∈ n a isOpen_univ _ _ := univ_mem isOpen_inter := fun _s _t hs ht x ⟹hxs, hxt⟩ => inter_mem (hs x hxs) (ht x hxt) isOpen_sUnion := fun _s hs _a ⟹x, hx, hxa⟩ => mem_of_superset (hs x hx _ hxa) (subset_sUnion_of_mem hx) theorem nhds_mkOfNhds_of_hasBasis {n : α → Filter α} {ι : α → Sort*} {p : ∀ a, ι a → Prop} {s : ∀ a, ι a → Set α} (hb : ∀ a, (n a).HasBasis (p a) (s a)) (hpure : ∀ a i, p a i → a ∈ s a i) (hopen : ∀ a i, p a i → ∀ᶠ x in n a, s a i ∈ n x) (a : α) : @nhds α (.mkOfNhds n) a = n a := by let t : TopologicalSpace α := .mkOfNhds n apply le_antisymm · intro U hU replace hpure : pure ≀ n := fun x ↩ (hb x).ge_iff.2 (hpure x) refine mem_nhds_iff.2 ⟹{x | U ∈ n x}, fun x hx ↩ hpure x hx, fun x hx ↩ ?_, hU⟩ rcases (hb x).mem_iff.1 hx with ⟹i, hpi, hi⟩ exact (hopen x i hpi).mono fun y hy ↩ mem_of_superset hy hi · exact (nhds_basis_opens a).ge_iff.2 fun U ⟹haU, hUo⟩ ↩ hUo a haU theorem nhds_mkOfNhds (n : α → Filter α) (a : α) (h₀ : pure ≀ n) (h₁ : ∀ a, ∀ s ∈ n a, ∀ᶠ y in n a, s ∈ n y) : @nhds α (TopologicalSpace.mkOfNhds n) a = n a := nhds_mkOfNhds_of_hasBasis (fun a ↩ (n a).basis_sets) h₀ h₁ _ theorem nhds_mkOfNhds_single [DecidableEq α] {a₀ : α} {l : Filter α} (h : pure a₀ ≀ l) (b : α) : @nhds α (TopologicalSpace.mkOfNhds (update pure a₀ l)) b = (update pure a₀ l : α → Filter α) b := by refine nhds_mkOfNhds _ _ (le_update_iff.mpr ⟹h, fun _ _ => le_rfl⟩) fun a s hs => ?_ rcases eq_or_ne a a₀ with (rfl | ha) · filter_upwards [hs] with b hb rcases eq_or_ne b a with (rfl | hb) · exact hs · rwa [update_of_ne hb] · simpa only [update_of_ne ha, mem_pure, eventually_pure] using hs theorem nhds_mkOfNhds_filterBasis (B : α → FilterBasis α) (a : α) (h₀ : ∀ x, ∀ n ∈ B x, x ∈ n) (h₁ : ∀ x, ∀ n ∈ B x, ∃ n₁ ∈ B x, ∀ x' ∈ n₁, ∃ n₂ ∈ B x', n₂ ⊆ n) : @nhds α (TopologicalSpace.mkOfNhds fun x => (B x).filter) a = (B a).filter := nhds_mkOfNhds_of_hasBasis (fun a ↩ (B a).hasBasis) h₀ h₁ a section Lattice variable {α : Type u} {β : Type v} /-- The ordering on topologies on the type `α`. `t ≀ s` if every set open in `s` is also open in `t` (`t` is finer than `s`). -/ instance : PartialOrder (TopologicalSpace α) := { PartialOrder.lift (fun t => OrderDual.toDual IsOpen[t]) (fun _ _ => TopologicalSpace.ext) with le := fun s t => ∀ U, IsOpen[t] U → IsOpen[s] U } protected theorem le_def {α} {t s : TopologicalSpace α} : t ≀ s ↔ IsOpen[s] ≀ IsOpen[t] := Iff.rfl theorem le_generateFrom_iff_subset_isOpen {g : Set (Set α)} {t : TopologicalSpace α} : t ≀ generateFrom g ↔ g ⊆ { s | IsOpen[t] s } := ⟹fun ht s hs => ht _ <| .basic s hs, fun hg _s hs => hs.recOn (fun _ h => hg h) isOpen_univ (fun _ _ _ _ => IsOpen.inter) fun _ _ => isOpen_sUnion⟩ /-- If `s` equals the collection of open sets in the topology it generates, then `s` defines a topology. -/ protected def mkOfClosure (s : Set (Set α)) (hs : { u | GenerateOpen s u } = s) : TopologicalSpace α where IsOpen u := u ∈ s isOpen_univ := hs ▾ TopologicalSpace.GenerateOpen.univ isOpen_inter := hs ▾ TopologicalSpace.GenerateOpen.inter isOpen_sUnion := hs ▾ TopologicalSpace.GenerateOpen.sUnion theorem mkOfClosure_sets {s : Set (Set α)} {hs : { u | GenerateOpen s u } = s} : TopologicalSpace.mkOfClosure s hs = generateFrom s := TopologicalSpace.ext hs.symm theorem gc_generateFrom (α) : GaloisConnection (fun t : TopologicalSpace α => OrderDual.toDual { s | IsOpen[t] s }) (generateFrom ∘ OrderDual.ofDual) := fun _ _ => le_generateFrom_iff_subset_isOpen.symm /-- The Galois coinsertion between `TopologicalSpace α` and `(Set (Set α))ᵒᵈ` whose lower part sends a topology to its collection of open subsets, and whose upper part sends a collection of subsets of `α` to the topology they generate. -/ def gciGenerateFrom (α : Type*) : GaloisCoinsertion (fun t : TopologicalSpace α => OrderDual.toDual { s | IsOpen[t] s }) (generateFrom ∘ OrderDual.ofDual) where gc := gc_generateFrom α u_l_le _ s hs := TopologicalSpace.GenerateOpen.basic s hs choice g hg := TopologicalSpace.mkOfClosure g (Subset.antisymm hg <| le_generateFrom_iff_subset_isOpen.1 <| le_rfl) choice_eq _ _ := mkOfClosure_sets /-- Topologies on `α` form a complete lattice, with `⊥` the discrete topology and `⊀` the indiscrete topology. The infimum of a collection of topologies is the topology generated by all their open sets, while the supremum is the topology whose open sets are those sets open in every member of the collection. -/ instance : CompleteLattice (TopologicalSpace α) := (gciGenerateFrom α).liftCompleteLattice @[mono, gcongr] theorem generateFrom_anti {α} {g₁ g₂ : Set (Set α)} (h : g₁ ⊆ g₂) : generateFrom g₂ ≀ generateFrom g₁ := (gc_generateFrom _).monotone_u h theorem generateFrom_setOf_isOpen (t : TopologicalSpace α) : generateFrom { s | IsOpen[t] s } = t := (gciGenerateFrom α).u_l_eq t theorem leftInverse_generateFrom : LeftInverse generateFrom fun t : TopologicalSpace α => { s | IsOpen[t] s } := (gciGenerateFrom α).u_l_leftInverse theorem generateFrom_surjective : Surjective (generateFrom : Set (Set α) → TopologicalSpace α) := (gciGenerateFrom α).u_surjective theorem setOf_isOpen_injective : Injective fun t : TopologicalSpace α => { s | IsOpen[t] s } := (gciGenerateFrom α).l_injective end Lattice end TopologicalSpace section Lattice variable {α : Type*} {t t₁ t₂ : TopologicalSpace α} {s : Set α} theorem IsOpen.mono (hs : IsOpen[t₂] s) (h : t₁ ≀ t₂) : IsOpen[t₁] s := h s hs theorem IsClosed.mono (hs : IsClosed[t₂] s) (h : t₁ ≀ t₂) : IsClosed[t₁] s := (@isOpen_compl_iff α s t₁).mp <| hs.isOpen_compl.mono h theorem closure.mono (h : t₁ ≀ t₂) : closure[t₁] s ⊆ closure[t₂] s := @closure_minimal _ t₁ s (@closure _ t₂ s) subset_closure (IsClosed.mono isClosed_closure h) theorem isOpen_implies_isOpen_iff : (∀ s, IsOpen[t₁] s → IsOpen[t₂] s) ↔ t₂ ≀ t₁ := Iff.rfl /-- The only open sets in the indiscrete topology are the empty set and the whole space. -/ theorem TopologicalSpace.isOpen_top_iff {α} (U : Set α) : IsOpen[⊀] U ↔ U = ∅ √ U = univ := ⟹fun h => by induction h with | basic _ h => exact False.elim h | univ => exact .inr rfl | inter _ _ _ _ h₁ h₂ => rcases h₁ with (rfl | rfl) <;> rcases h₂ with (rfl | rfl) <;> simp | sUnion _ _ ih => exact sUnion_mem_empty_univ ih, by rintro (rfl | rfl) exacts [@isOpen_empty _ ⊀, @isOpen_univ _ ⊀]⟩ /-- A topological space is discrete if every set is open, that is, its topology equals the discrete topology `⊥`. -/ class DiscreteTopology (α : Type*) [t : TopologicalSpace α] : Prop where /-- The `TopologicalSpace` structure on a type with discrete topology is equal to `⊥`. -/ eq_bot : t = ⊥ theorem discreteTopology_bot (α : Type*) : @DiscreteTopology α ⊥ := @DiscreteTopology.mk α ⊥ rfl section DiscreteTopology variable [TopologicalSpace α] [DiscreteTopology α] {β : Type*} @[simp] theorem isOpen_discrete (s : Set α) : IsOpen s := (@DiscreteTopology.eq_bot α _).symm ▾ trivial @[simp] theorem isClosed_discrete (s : Set α) : IsClosed s := ⟹isOpen_discrete _⟩ theorem closure_discrete (s : Set α) : closure s = s := (isClosed_discrete _).closure_eq @[simp] theorem dense_discrete {s : Set α} : Dense s ↔ s = univ := by simp [dense_iff_closure_eq] @[simp] theorem denseRange_discrete {ι : Type*} {f : ι → α} : DenseRange f ↔ Surjective f := by rw [DenseRange, dense_discrete, range_eq_univ] @[nontriviality, continuity, fun_prop] theorem continuous_of_discreteTopology [TopologicalSpace β] {f : α → β} : Continuous f := continuous_def.2 fun _ _ => isOpen_discrete _ /-- A function to a discrete topological space is continuous if and only if the preimage of every singleton is open. -/ theorem continuous_discrete_rng {α} [TopologicalSpace α] [TopologicalSpace β] [DiscreteTopology β] {f : α → β} : Continuous f ↔ ∀ b : β, IsOpen (f ⁻¹' {b}) := ⟹fun h _ => (isOpen_discrete _).preimage h, fun h => ⟹fun s _ => by rw [← biUnion_of_singleton s, preimage_iUnion₂] exact isOpen_biUnion fun _ _ => h _⟩⟩ @[simp] theorem nhds_discrete (α : Type*) [TopologicalSpace α] [DiscreteTopology α] : @nhds α _ = pure := le_antisymm (fun _ s hs => (isOpen_discrete s).mem_nhds hs) pure_le_nhds theorem mem_nhds_discrete {x : α} {s : Set α} : s ∈ 𝓝 x ↔ x ∈ s := by rw [nhds_discrete, mem_pure] end DiscreteTopology theorem le_of_nhds_le_nhds (h : ∀ x, @nhds α t₁ x ≀ @nhds α t₂ x) : t₁ ≀ t₂ := fun s => by rw [@isOpen_iff_mem_nhds _ t₁, @isOpen_iff_mem_nhds _ t₂] exact fun hs a ha => h _ (hs _ ha) theorem eq_bot_of_singletons_open {t : TopologicalSpace α} (h : ∀ x, IsOpen[t] {x}) : t = ⊥ := bot_unique fun s _ => biUnion_of_singleton s ▾ isOpen_biUnion fun x _ => h x theorem forall_open_iff_discrete {X : Type*} [TopologicalSpace X] : (∀ s : Set X, IsOpen s) ↔ DiscreteTopology X := ⟹fun h => ⟹eq_bot_of_singletons_open fun _ => h _⟩, @isOpen_discrete _ _⟩ theorem discreteTopology_iff_forall_isClosed [TopologicalSpace α] : DiscreteTopology α ↔ ∀ s : Set α, IsClosed s := forall_open_iff_discrete.symm.trans <| compl_surjective.forall.trans <| forall_congr' fun _ ↩ isOpen_compl_iff theorem singletons_open_iff_discrete {X : Type*} [TopologicalSpace X] : (∀ a : X, IsOpen ({a} : Set X)) ↔ DiscreteTopology X := ⟹fun h => ⟹eq_bot_of_singletons_open h⟩, fun a _ => @isOpen_discrete _ _ a _⟩ theorem DiscreteTopology.of_finite_of_isClosed_singleton [TopologicalSpace α] [Finite α] (h : ∀ a : α, IsClosed {a}) : DiscreteTopology α := discreteTopology_iff_forall_isClosed.mpr fun s ↩ s.iUnion_of_singleton_coe ▾ isClosed_iUnion_of_finite fun _ ↩ h _ theorem discreteTopology_iff_singleton_mem_nhds [TopologicalSpace α] : DiscreteTopology α ↔ ∀ x : α, {x} ∈ 𝓝 x := by simp only [← singletons_open_iff_discrete, isOpen_iff_mem_nhds, mem_singleton_iff, forall_eq] /-- This lemma characterizes discrete topological spaces as those whose singletons are neighbourhoods. -/ theorem discreteTopology_iff_nhds [TopologicalSpace α] : DiscreteTopology α ↔ ∀ x : α, 𝓝 x = pure x := by simp [discreteTopology_iff_singleton_mem_nhds, le_pure_iff] apply forall_congr' (fun x ↩ ?_) simp [le_antisymm_iff, pure_le_nhds x] theorem discreteTopology_iff_nhds_ne [TopologicalSpace α] : DiscreteTopology α ↔ ∀ x : α, 𝓝[≠] x = ⊥ := by simp only [discreteTopology_iff_singleton_mem_nhds, nhdsWithin, inf_principal_eq_bot, compl_compl] /-- If the codomain of a continuous injective function has discrete topology, then so does the domain. See also `Embedding.discreteTopology` for an important special case. -/ theorem DiscreteTopology.of_continuous_injective {β : Type*} [TopologicalSpace α] [TopologicalSpace β] [DiscreteTopology β] {f : α → β} (hc : Continuous f) (hinj : Injective f) : DiscreteTopology α := forall_open_iff_discrete.1 fun s ↩ hinj.preimage_image s ▾ (isOpen_discrete _).preimage hc end Lattice section GaloisConnection variable {α β γ : Type*} theorem isOpen_induced_iff [t : TopologicalSpace β] {s : Set α} {f : α → β} : IsOpen[t.induced f] s ↔ ∃ t, IsOpen t ∧ f ⁻¹' t = s := Iff.rfl theorem isClosed_induced_iff [t : TopologicalSpace β] {s : Set α} {f : α → β} : IsClosed[t.induced f] s ↔ ∃ t, IsClosed t ∧ f ⁻¹' t = s := by letI := t.induced f simp only [← isOpen_compl_iff, isOpen_induced_iff] exact compl_surjective.exists.trans (by simp only [preimage_compl, compl_inj_iff]) theorem isOpen_coinduced {t : TopologicalSpace α} {s : Set β} {f : α → β} : IsOpen[t.coinduced f] s ↔ IsOpen (f ⁻¹' s) := Iff.rfl
theorem isClosed_coinduced {t : TopologicalSpace α} {s : Set β} {f : α → β} : IsClosed[t.coinduced f] s ↔ IsClosed (f ⁻¹' s) := by simp only [← isOpen_compl_iff, isOpen_coinduced (f := f), preimage_compl]
Mathlib/Topology/Order.lean
355
357
/- Copyright (c) 2021 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Kim Morrison -/ import Mathlib.Algebra.Group.Defs import Mathlib.Logic.Relation import Mathlib.Logic.Function.Basic /-! # Shapes of homological complexes We define a structure `ComplexShape ι` for describing the shapes of homological complexes indexed by a type `ι`. This is intended to capture chain complexes and cochain complexes, indexed by either `ℕ` or `â„€`, as well as more exotic examples. Rather than insisting that the indexing type has a `succ` function specifying where differentials should go, inside `c : ComplexShape` we have `c.Rel : ι → ι → Prop`, and when we define `HomologicalComplex` we only allow nonzero differentials `d i j` from `i` to `j` if `c.Rel i j`. Further, we require that `{ j // c.Rel i j }` and `{ i // c.Rel i j }` are subsingletons. This means that the shape consists of some union of lines, rays, intervals, and circles. Convenience functions `c.next` and `c.prev` provide these related elements when they exist, and return their input otherwise. This design aims to avoid certain problems arising from dependent type theory. In particular we never have to ensure morphisms `d i : X i ⟶ X (succ i)` compose as expected (which would often require rewriting by equations in the indexing type). Instead such identities become separate proof obligations when verifying that a complex we've constructed is of the desired shape. If `α` is an `AddRightCancelSemigroup`, then we define `up α : ComplexShape α`, the shape appropriate for cohomology, so `d : X i ⟶ X j` is nonzero only when `j = i + 1`, as well as `down α : ComplexShape α`, appropriate for homology, so `d : X i ⟶ X j` is nonzero only when `i = j + 1`. (Later we'll introduce `CochainComplex` and `ChainComplex` as abbreviations for `HomologicalComplex` with one of these shapes baked in.) -/ noncomputable section /-- A `c : ComplexShape ι` describes the shape of a chain complex, with chain groups indexed by `ι`. Typically `ι` will be `ℕ`, `â„€`, or `Fin n`. There is a relation `Rel : ι → ι → Prop`, and we will only allow a non-zero differential from `i` to `j` when `Rel i j`. There are axioms which imply `{ j // c.Rel i j }` and `{ i // c.Rel i j }` are subsingletons. This means that the shape consists of some union of lines, rays, intervals, and circles. Below we define `c.next` and `c.prev` which provide these related elements. -/ @[ext] structure ComplexShape (ι : Type*) where /-- Nonzero differentials `X i ⟶ X j` shall be allowed on homological complexes when `Rel i j` holds. -/ Rel : ι → ι → Prop /-- There is at most one nonzero differential from `X i`. -/ next_eq : ∀ {i j j'}, Rel i j → Rel i j' → j = j' /-- There is at most one nonzero differential to `X j`. -/ prev_eq : ∀ {i i' j}, Rel i j → Rel i' j → i = i' namespace ComplexShape variable {ι : Type*} /-- The complex shape where only differentials from each `X.i` to itself are allowed. This is mostly only useful so we can describe the relation of "related in `k` steps" below. -/ @[simps] def refl (ι : Type*) : ComplexShape ι where Rel i j := i = j next_eq w w' := w.symm.trans w' prev_eq w w' := w.trans w'.symm /-- The reverse of a `ComplexShape`. -/ @[simps] def symm (c : ComplexShape ι) : ComplexShape ι where Rel i j := c.Rel j i next_eq w w' := c.prev_eq w w' prev_eq w w' := c.next_eq w w' @[simp] theorem symm_symm (c : ComplexShape ι) : c.symm.symm = c := rfl theorem symm_bijective : Function.Bijective (ComplexShape.symm : ComplexShape ι → ComplexShape ι) := Function.bijective_iff_has_inverse.mpr ⟹_, symm_symm, symm_symm⟩ /-- The "composition" of two `ComplexShape`s. We need this to define "related in k steps" later. -/
@[simp] def trans (c₁ c₂ : ComplexShape ι) : ComplexShape ι where Rel := Relation.Comp c₁.Rel c₂.Rel
Mathlib/Algebra/Homology/ComplexShape.lean
100
102
/- Copyright (c) 2023 Andrew Yang, Patrick Lutz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.RingTheory.RootsOfUnity.PrimitiveRoots import Mathlib.FieldTheory.Galois.Basic import Mathlib.FieldTheory.KummerPolynomial import Mathlib.LinearAlgebra.Eigenspace.Minpoly import Mathlib.RingTheory.Norm.Basic /-! # Kummer Extensions ## Main result - `isCyclic_tfae`: Suppose `L/K` is a finite extension of dimension `n`, and `K` contains all `n`-th roots of unity. Then `L/K` is cyclic iff `L` is a splitting field of some irreducible polynomial of the form `Xⁿ - a : K[X]` iff `L = K[α]` for some `αⁿ ∈ K`. - `autEquivRootsOfUnity`: Given an instance `IsSplittingField K L (X ^ n - C a)` (perhaps via `isSplittingField_X_pow_sub_C_of_root_adjoin_eq_top`), then the galois group is isomorphic to `rootsOfUnity n K`, by sending `σ ↩ σ α / α` for `α ^ n = a`, and the inverse is given by `ÎŒ ↩ (α ↩ ÎŒ • α)`. - `autEquivZmod`: Furthermore, given an explicit choice `ζ` of a primitive `n`-th root of unity, the galois group is then isomorphic to `Multiplicative (ZMod n)` whose inverse is given by `i ↩ (α ↩ ζⁱ • α)`. ## Other results Criteria for `X ^ n - C a` to be irreducible is given: - `X_pow_sub_C_irreducible_iff_of_prime_pow`: For `n = p ^ k` an odd prime power, `X ^ n - C a` is irreducible iff `a` is not a `p`-power. - `X_pow_sub_C_irreducible_iff_forall_prime_of_odd`: For `n` odd, `X ^ n - C a` is irreducible iff `a` is not a `p`-power for all prime `p ∣ n`. - `X_pow_sub_C_irreducible_iff_of_odd`: For `n` odd, `X ^ n - C a` is irreducible iff `a` is not a `d`-power for `d ∣ n` and `d ≠ 1`. TODO: criteria for even `n`. See [serge_lang_algebra] VI,§9. TODO: relate Kummer extensions of degree 2 with the class `Algebra.IsQuadraticExtension`. -/ universe u variable {K : Type u} [Field K] open Polynomial IntermediateField AdjoinRoot section Splits theorem X_pow_sub_C_splits_of_isPrimitiveRoot {n : ℕ} {ζ : K} (hζ : IsPrimitiveRoot ζ n) {α a : K} (e : α ^ n = a) : (X ^ n - C a).Splits (RingHom.id _) := by cases n.eq_zero_or_pos with | inl hn => rw [hn, pow_zero, ← C.map_one, ← map_sub] exact splits_C _ _ | inr hn => rw [splits_iff_card_roots, ← nthRoots, hζ.card_nthRoots, natDegree_X_pow_sub_C, if_pos ⟚α, e⟩] -- make this private, as we only use it to prove a strictly more general version private theorem X_pow_sub_C_eq_prod' {n : ℕ} {ζ : K} (hζ : IsPrimitiveRoot ζ n) {α a : K} (hn : 0 < n) (e : α ^ n = a) : (X ^ n - C a) = ∏ i ∈ Finset.range n, (X - C (ζ ^ i * α)) := by rw [eq_prod_roots_of_monic_of_splits_id (monic_X_pow_sub_C _ (Nat.pos_iff_ne_zero.mp hn)) (X_pow_sub_C_splits_of_isPrimitiveRoot hζ e), ← nthRoots, hζ.nthRoots_eq e, Multiset.map_map] rfl lemma X_pow_sub_C_eq_prod {R : Type*} [CommRing R] [IsDomain R] {n : ℕ} {ζ : R} (hζ : IsPrimitiveRoot ζ n) {α a : R} (hn : 0 < n) (e : α ^ n = a) : (X ^ n - C a) = ∏ i ∈ Finset.range n, (X - C (ζ ^ i * α)) := by let K := FractionRing R let i := algebraMap R K have h := FaithfulSMul.algebraMap_injective R K apply_fun Polynomial.map i using map_injective i h simpa only [Polynomial.map_sub, Polynomial.map_pow, map_X, map_C, map_mul, map_pow, Polynomial.map_prod, Polynomial.map_mul] using X_pow_sub_C_eq_prod' (hζ.map_of_injective h) hn <| map_pow i α n ▾ congrArg i e end Splits section Irreducible theorem X_pow_mul_sub_C_irreducible {n m : ℕ} {a : K} (hm : Irreducible (X ^ m - C a)) (hn : ∀ (E : Type u) [Field E] [Algebra K E] (x : E) (_ : minpoly K x = X ^ m - C a), Irreducible (X ^ n - C (AdjoinSimple.gen K x))) : Irreducible (X ^ (n * m) - C a) := by have hm' : m ≠ 0 := by rintro rfl rw [pow_zero, ← C.map_one, ← map_sub] at hm exact not_irreducible_C _ hm simpa [pow_mul] using irreducible_comp (monic_X_pow_sub_C a hm') (monic_X_pow n) hm (by simpa only [Polynomial.map_pow, map_X] using hn) -- TODO: generalize to even `n` theorem X_pow_sub_C_irreducible_of_odd {n : ℕ} (hn : Odd n) {a : K} (ha : ∀ p : ℕ, p.Prime → p ∣ n → ∀ b : K, b ^ p ≠ a) : Irreducible (X ^ n - C a) := by induction n using induction_on_primes generalizing K a with | h₀ => simp [← Nat.not_even_iff_odd] at hn | h₁ => simpa using irreducible_X_sub_C a | h p n hp IH => rw [mul_comm] apply X_pow_mul_sub_C_irreducible (X_pow_sub_C_irreducible_of_prime hp (ha p hp (dvd_mul_right _ _))) intro E _ _ x hx have : IsIntegral K x := not_not.mp fun h ↩ by simpa only [degree_zero, degree_X_pow_sub_C hp.pos, WithBot.natCast_ne_bot] using congr_arg degree (hx.symm.trans (dif_neg h)) apply IH (Nat.odd_mul.mp hn).2 intros q hq hqn b hb apply ha q hq (dvd_mul_of_dvd_right hqn p) (Algebra.norm _ b) rw [← map_pow, hb, ← adjoin.powerBasis_gen this, Algebra.PowerBasis.norm_gen_eq_coeff_zero_minpoly] simp [minpoly_gen, hx, hp.ne_zero.symm, (Nat.odd_mul.mp hn).1.neg_pow] theorem X_pow_sub_C_irreducible_iff_forall_prime_of_odd {n : ℕ} (hn : Odd n) {a : K} : Irreducible (X ^ n - C a) ↔ (∀ p : ℕ, p.Prime → p ∣ n → ∀ b : K, b ^ p ≠ a) := ⟹fun e _ hp hpn ↩ pow_ne_of_irreducible_X_pow_sub_C e hpn hp.ne_one, X_pow_sub_C_irreducible_of_odd hn⟩ theorem X_pow_sub_C_irreducible_iff_of_odd {n : ℕ} (hn : Odd n) {a : K} : Irreducible (X ^ n - C a) ↔ (∀ d, d ∣ n → d ≠ 1 → ∀ b : K, b ^ d ≠ a) := ⟹fun e _ ↩ pow_ne_of_irreducible_X_pow_sub_C e, fun H ↩ X_pow_sub_C_irreducible_of_odd hn fun p hp hpn ↩ (H p hpn hp.ne_one)⟩ -- TODO: generalize to `p = 2` theorem X_pow_sub_C_irreducible_of_prime_pow {p : ℕ} (hp : p.Prime) (hp' : p ≠ 2) (n : ℕ) {a : K} (ha : ∀ b : K, b ^ p ≠ a) : Irreducible (X ^ (p ^ n) - C a) := by apply X_pow_sub_C_irreducible_of_odd (hp.odd_of_ne_two hp').pow intros q hq hq' simpa [(Nat.prime_dvd_prime_iff_eq hq hp).mp (hq.dvd_of_dvd_pow hq')] using ha theorem X_pow_sub_C_irreducible_iff_of_prime_pow {p : ℕ} (hp : p.Prime) (hp' : p ≠ 2) {n} (hn : n ≠ 0) {a : K} : Irreducible (X ^ p ^ n - C a) ↔ ∀ b, b ^ p ≠ a := ⟹(pow_ne_of_irreducible_X_pow_sub_C · (dvd_pow dvd_rfl hn) hp.ne_one), X_pow_sub_C_irreducible_of_prime_pow hp hp' n⟩ end Irreducible /-! ### Galois Group of `K[n√a]` We first develop the theory for a specific `K[n√a] := AdjoinRoot (X ^ n - C a)`. The main result is the description of the galois group: `autAdjoinRootXPowSubCEquiv`.
-/ variable {n : ℕ} (hζ : (primitiveRoots n K).Nonempty) variable (a : K) (H : Irreducible (X ^ n - C a)) set_option quotPrecheck false in scoped[KummerExtension] notation3 "K[" n "√" a "]" => AdjoinRoot (Polynomial.X ^ n - Polynomial.C a) attribute [nolint docBlame] KummerExtension.«termK[_√_]» open scoped KummerExtension section AdjoinRoot include hζ H in /-- Also see `Polynomial.separable_X_pow_sub_C_unit` -/ theorem Polynomial.separable_X_pow_sub_C_of_irreducible : (X ^ n - C a).Separable := by letI := Fact.mk H letI : Algebra K K[n√a] := inferInstance have hn := Nat.pos_iff_ne_zero.mpr (ne_zero_of_irreducible_X_pow_sub_C H) by_cases hn' : n = 1 · rw [hn', pow_one]; exact separable_X_sub_C have ⟚ζ, hζ⟩ := hζ rw [mem_primitiveRoots (Nat.pos_of_ne_zero <| ne_zero_of_irreducible_X_pow_sub_C H)] at hζ rw [← separable_map (algebraMap K K[n√a]), Polynomial.map_sub, Polynomial.map_pow, map_C, map_X, AdjoinRoot.algebraMap_eq, X_pow_sub_C_eq_prod (hζ.map_of_injective (algebraMap K _).injective) hn (root_X_pow_sub_C_pow n a), separable_prod_X_sub_C_iff'] #adaptation_note /-- https://github.com/leanprover/lean4/pull/5376
Mathlib/FieldTheory/KummerExtension.lean
151
179
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Filippo A. E. Nuccio -/ import Mathlib.Algebra.EuclideanDomain.Basic import Mathlib.RingTheory.FractionalIdeal.Basic import Mathlib.RingTheory.IntegralClosure.IsIntegral.Basic import Mathlib.RingTheory.LocalRing.Basic import Mathlib.RingTheory.PrincipalIdealDomain import Mathlib.Tactic.FieldSimp /-! # More operations on fractional ideals ## Main definitions * `map` is the pushforward of a fractional ideal along an algebra morphism Let `K` be the localization of `R` at `R⁰ = R \ {0}` (i.e. the field of fractions). * `FractionalIdeal R⁰ K` is the type of fractional ideals in the field of fractions * `Div (FractionalIdeal R⁰ K)` instance: the ideal quotient `I / J` (typically written $I : J$, but a `:` operator cannot be defined) ## Main statement * `isNoetherian` states that every fractional ideal of a noetherian integral domain is noetherian ## References * https://en.wikipedia.org/wiki/Fractional_ideal ## Tags fractional ideal, fractional ideals, invertible ideal -/ open IsLocalization Pointwise nonZeroDivisors namespace FractionalIdeal open Set Submodule variable {R : Type*} [CommRing R] {S : Submonoid R} {P : Type*} [CommRing P] variable [Algebra R P] section variable {P' : Type*} [CommRing P'] [Algebra R P'] variable {P'' : Type*} [CommRing P''] [Algebra R P''] theorem _root_.IsFractional.map (g : P →ₐ[R] P') {I : Submodule R P} : IsFractional S I → IsFractional S (Submodule.map g.toLinearMap I) | ⟹a, a_nonzero, hI⟩ => ⟹a, a_nonzero, fun b hb => by obtain ⟹b', b'_mem, hb'⟩ := Submodule.mem_map.mp hb rw [AlgHom.toLinearMap_apply] at hb' obtain ⟹x, hx⟩ := hI b' b'_mem use x rw [← g.commutes, hx, map_smul, hb']⟩ /-- `I.map g` is the pushforward of the fractional ideal `I` along the algebra morphism `g` -/ def map (g : P →ₐ[R] P') : FractionalIdeal S P → FractionalIdeal S P' := fun I => ⟹Submodule.map g.toLinearMap I, I.isFractional.map g⟩ @[simp, norm_cast] theorem coe_map (g : P →ₐ[R] P') (I : FractionalIdeal S P) : ↑(map g I) = Submodule.map g.toLinearMap I := rfl @[simp] theorem mem_map {I : FractionalIdeal S P} {g : P →ₐ[R] P'} {y : P'} : y ∈ I.map g ↔ ∃ x, x ∈ I ∧ g x = y := Submodule.mem_map variable (I J : FractionalIdeal S P) (g : P →ₐ[R] P') @[simp] theorem map_id : I.map (AlgHom.id _ _) = I := coeToSubmodule_injective (Submodule.map_id (I : Submodule R P)) @[simp] theorem map_comp (g' : P' →ₐ[R] P'') : I.map (g'.comp g) = (I.map g).map g' := coeToSubmodule_injective (Submodule.map_comp g.toLinearMap g'.toLinearMap I) @[simp, norm_cast] theorem map_coeIdeal (I : Ideal R) : (I : FractionalIdeal S P).map g = I := by ext x simp only [mem_coeIdeal] constructor · rintro ⟹_, ⟹y, hy, rfl⟩, rfl⟩ exact ⟹y, hy, (g.commutes y).symm⟩ · rintro ⟹y, hy, rfl⟩ exact ⟹_, ⟹y, hy, rfl⟩, g.commutes y⟩ @[simp] protected theorem map_one : (1 : FractionalIdeal S P).map g = 1 := map_coeIdeal g ⊀ @[simp] protected theorem map_zero : (0 : FractionalIdeal S P).map g = 0 := map_coeIdeal g 0 @[simp] protected theorem map_add : (I + J).map g = I.map g + J.map g := coeToSubmodule_injective (Submodule.map_sup _ _ _) @[simp] protected theorem map_mul : (I * J).map g = I.map g * J.map g := by simp only [mul_def] exact coeToSubmodule_injective (Submodule.map_mul _ _ _) @[simp] theorem map_map_symm (g : P ≃ₐ[R] P') : (I.map (g : P →ₐ[R] P')).map (g.symm : P' →ₐ[R] P) = I := by rw [← map_comp, g.symm_comp, map_id] @[simp] theorem map_symm_map (I : FractionalIdeal S P') (g : P ≃ₐ[R] P') : (I.map (g.symm : P' →ₐ[R] P)).map (g : P →ₐ[R] P') = I := by rw [← map_comp, g.comp_symm, map_id] theorem map_mem_map {f : P →ₐ[R] P'} (h : Function.Injective f) {x : P} {I : FractionalIdeal S P} : f x ∈ map f I ↔ x ∈ I := mem_map.trans ⟹fun ⟹_, hx', x'_eq⟩ => h x'_eq ▾ hx', fun h => ⟹x, h, rfl⟩⟩ theorem map_injective (f : P →ₐ[R] P') (h : Function.Injective f) : Function.Injective (map f : FractionalIdeal S P → FractionalIdeal S P') := fun _ _ hIJ => ext fun _ => (map_mem_map h).symm.trans (hIJ.symm ▾ map_mem_map h) /-- If `g` is an equivalence, `map g` is an isomorphism -/ def mapEquiv (g : P ≃ₐ[R] P') : FractionalIdeal S P ≃+* FractionalIdeal S P' where toFun := map g invFun := map g.symm map_add' I J := FractionalIdeal.map_add I J _ map_mul' I J := FractionalIdeal.map_mul I J _ left_inv I := by rw [← map_comp, AlgEquiv.symm_comp, map_id] right_inv I := by rw [← map_comp, AlgEquiv.comp_symm, map_id] @[simp] theorem coeFun_mapEquiv (g : P ≃ₐ[R] P') : (mapEquiv g : FractionalIdeal S P → FractionalIdeal S P') = map g := rfl @[simp] theorem mapEquiv_apply (g : P ≃ₐ[R] P') (I : FractionalIdeal S P) : mapEquiv g I = map (↑g) I := rfl @[simp] theorem mapEquiv_symm (g : P ≃ₐ[R] P') : ((mapEquiv g).symm : FractionalIdeal S P' ≃+* _) = mapEquiv g.symm := rfl @[simp] theorem mapEquiv_refl : mapEquiv AlgEquiv.refl = RingEquiv.refl (FractionalIdeal S P) := RingEquiv.ext fun x => by simp theorem isFractional_span_iff {s : Set P} : IsFractional S (span R s) ↔ ∃ a ∈ S, ∀ b : P, b ∈ s → IsInteger R (a • b) := ⟹fun ⟹a, a_mem, h⟩ => ⟹a, a_mem, fun b hb => h b (subset_span hb)⟩, fun ⟹a, a_mem, h⟩ => ⟹a, a_mem, fun _ hb => span_induction (hx := hb) h (by rw [smul_zero] exact isInteger_zero) (fun x y _ _ hx hy => by rw [smul_add] exact isInteger_add hx hy) fun s x _ hx => by rw [smul_comm] exact isInteger_smul hx⟩⟩ theorem isFractional_of_fg [IsLocalization S P] {I : Submodule R P} (hI : I.FG) : IsFractional S I := by rcases hI with ⟹I, rfl⟩ rcases exist_integer_multiples_of_finset S I with ⟹⟹s, hs1⟩, hs⟩ rw [isFractional_span_iff] exact ⟹s, hs1, hs⟩ theorem mem_span_mul_finite_of_mem_mul {I J : FractionalIdeal S P} {x : P} (hx : x ∈ I * J) : ∃ T T' : Finset P, (T : Set P) ⊆ I ∧ (T' : Set P) ⊆ J ∧ x ∈ span R (T * T' : Set P) := Submodule.mem_span_mul_finite_of_mem_mul (by simpa using mem_coe.mpr hx) variable (S) in theorem coeIdeal_fg (inj : Function.Injective (algebraMap R P)) (I : Ideal R) : FG ((I : FractionalIdeal S P) : Submodule R P) ↔ I.FG := coeSubmodule_fg _ inj _ theorem fg_unit (I : (FractionalIdeal S P)Ë£) : FG (I : Submodule R P) := Submodule.fg_unit <| Units.map (coeSubmoduleHom S P).toMonoidHom I theorem fg_of_isUnit (I : FractionalIdeal S P) (h : IsUnit I) : FG (I : Submodule R P) := fg_unit h.unit theorem _root_.Ideal.fg_of_isUnit (inj : Function.Injective (algebraMap R P)) (I : Ideal R) (h : IsUnit (I : FractionalIdeal S P)) : I.FG := by rw [← coeIdeal_fg S inj I] exact FractionalIdeal.fg_of_isUnit (R := R) I h variable (S P P') variable [IsLocalization S P] [IsLocalization S P'] /-- `canonicalEquiv f f'` is the canonical equivalence between the fractional ideals in `P` and in `P'`, which are both localizations of `R` at `S`. -/ noncomputable irreducible_def canonicalEquiv : FractionalIdeal S P ≃+* FractionalIdeal S P' := mapEquiv { ringEquivOfRingEquiv P P' (RingEquiv.refl R) (show S.map _ = S by rw [RingEquiv.toMonoidHom_refl, Submonoid.map_id]) with commutes' := fun _ => ringEquivOfRingEquiv_eq _ _ } @[simp] theorem mem_canonicalEquiv_apply {I : FractionalIdeal S P} {x : P'} : x ∈ canonicalEquiv S P P' I ↔ ∃ y ∈ I, IsLocalization.map P' (RingHom.id R) (fun y (hy : y ∈ S) => show RingHom.id R y ∈ S from hy) (y : P) = x := by rw [canonicalEquiv, mapEquiv_apply, mem_map] exact ⟹fun ⟹y, mem, Eq⟩ => ⟹y, mem, Eq⟩, fun ⟹y, mem, Eq⟩ => ⟹y, mem, Eq⟩⟩ @[simp] theorem canonicalEquiv_symm : (canonicalEquiv S P P').symm = canonicalEquiv S P' P := RingEquiv.ext fun I => SetLike.ext_iff.mpr fun x => by rw [mem_canonicalEquiv_apply, canonicalEquiv, mapEquiv_symm, mapEquiv_apply, mem_map] exact ⟹fun ⟹y, mem, Eq⟩ => ⟹y, mem, Eq⟩, fun ⟹y, mem, Eq⟩ => ⟹y, mem, Eq⟩⟩ theorem canonicalEquiv_flip (I) : canonicalEquiv S P P' (canonicalEquiv S P' P I) = I := by rw [← canonicalEquiv_symm, RingEquiv.symm_apply_apply] @[simp] theorem canonicalEquiv_canonicalEquiv (P'' : Type*) [CommRing P''] [Algebra R P''] [IsLocalization S P''] (I : FractionalIdeal S P) : canonicalEquiv S P' P'' (canonicalEquiv S P P' I) = canonicalEquiv S P P'' I := by ext simp only [IsLocalization.map_map, RingHomInvPair.comp_eq₂, mem_canonicalEquiv_apply, exists_prop, exists_exists_and_eq_and] theorem canonicalEquiv_trans_canonicalEquiv (P'' : Type*) [CommRing P''] [Algebra R P''] [IsLocalization S P''] : (canonicalEquiv S P P').trans (canonicalEquiv S P' P'') = canonicalEquiv S P P'' := RingEquiv.ext (canonicalEquiv_canonicalEquiv S P P' P'') @[simp] theorem canonicalEquiv_coeIdeal (I : Ideal R) : canonicalEquiv S P P' I = I := by ext simp [IsLocalization.map_eq] @[simp] theorem canonicalEquiv_self : canonicalEquiv S P P = RingEquiv.refl _ := by rw [← canonicalEquiv_trans_canonicalEquiv S P P] convert (canonicalEquiv S P P).symm_trans_self exact (canonicalEquiv_symm S P P).symm end section IsFractionRing /-! ### `IsFractionRing` section This section concerns fractional ideals in the field of fractions, i.e. the type `FractionalIdeal R⁰ K` where `IsFractionRing R K`. -/ variable {K K' : Type*} [Field K] [Field K'] variable [Algebra R K] [IsFractionRing R K] [Algebra R K'] [IsFractionRing R K'] variable {I J : FractionalIdeal R⁰ K} (h : K →ₐ[R] K') /-- Nonzero fractional ideals contain a nonzero integer. -/ theorem exists_ne_zero_mem_isInteger [Nontrivial R] (hI : I ≠ 0) : ∃ x, x ≠ 0 ∧ algebraMap R K x ∈ I := by obtain ⟹y : K, y_mem, y_not_mem⟩ := SetLike.exists_of_lt (by simpa only using bot_lt_iff_ne_bot.mpr hI) have y_ne_zero : y ≠ 0 := by simpa using y_not_mem obtain ⟹z, ⟹x, hx⟩⟩ := exists_integer_multiple R⁰ y refine ⟹x, ?_, ?_⟩ · rw [Ne, ← @IsFractionRing.to_map_eq_zero_iff R _ K, hx, Algebra.smul_def] exact mul_ne_zero (IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors z.2) y_ne_zero · rw [hx] exact smul_mem _ _ y_mem theorem map_ne_zero [Nontrivial R] (hI : I ≠ 0) : I.map h ≠ 0 := by obtain ⟹x, x_ne_zero, hx⟩ := exists_ne_zero_mem_isInteger hI contrapose! x_ne_zero with map_eq_zero refine IsFractionRing.to_map_eq_zero_iff.mp (eq_zero_iff.mp map_eq_zero _ (mem_map.mpr ?_)) exact ⟹algebraMap R K x, hx, h.commutes x⟩ @[simp] theorem map_eq_zero_iff [Nontrivial R] : I.map h = 0 ↔ I = 0 := ⟹not_imp_not.mp (map_ne_zero _), fun hI => hI.symm ▾ FractionalIdeal.map_zero h⟩ theorem coeIdeal_injective : Function.Injective (fun (I : Ideal R) ↩ (I : FractionalIdeal R⁰ K)) := coeIdeal_injective' le_rfl theorem coeIdeal_inj {I J : Ideal R} : (I : FractionalIdeal R⁰ K) = (J : FractionalIdeal R⁰ K) ↔ I = J := coeIdeal_inj' le_rfl @[simp] theorem coeIdeal_eq_zero {I : Ideal R} : (I : FractionalIdeal R⁰ K) = 0 ↔ I = ⊥ := coeIdeal_eq_zero' le_rfl
theorem coeIdeal_ne_zero {I : Ideal R} : (I : FractionalIdeal R⁰ K) ≠ 0 ↔ I ≠ ⊥ := coeIdeal_ne_zero' le_rfl @[simp] theorem coeIdeal_eq_one {I : Ideal R} : (I : FractionalIdeal R⁰ K) = 1 ↔ I = 1 := by simpa only [Ideal.one_eq_top] using coeIdeal_inj theorem coeIdeal_ne_one {I : Ideal R} : (I : FractionalIdeal R⁰ K) ≠ 1 ↔ I ≠ 1 := not_iff_not.mpr coeIdeal_eq_one theorem num_eq_zero_iff [Nontrivial R] {I : FractionalIdeal R⁰ K} : I.num = 0 ↔ I = 0 :=
Mathlib/RingTheory/FractionalIdeal/Operations.lean
306
316
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.Algebra.BigOperators.Group.Finset.Sigma import Mathlib.Algebra.Order.Interval.Finset.Basic import Mathlib.Order.Interval.Finset.Nat import Mathlib.Tactic.Linarith /-! # Results about big operators over intervals We prove results about big operators over intervals. -/ open Nat variable {α M : Type*} namespace Finset section PartialOrder variable [PartialOrder α] [CommMonoid M] {f : α → M} {a b : α} section LocallyFiniteOrder variable [LocallyFiniteOrder α] @[to_additive] lemma mul_prod_Ico_eq_prod_Icc (h : a ≀ b) : f b * ∏ x ∈ Ico a b, f x = ∏ x ∈ Icc a b, f x := by rw [Icc_eq_cons_Ico h, prod_cons] @[to_additive] lemma prod_Ico_mul_eq_prod_Icc (h : a ≀ b) : (∏ x ∈ Ico a b, f x) * f b = ∏ x ∈ Icc a b, f x := by rw [mul_comm, mul_prod_Ico_eq_prod_Icc h] @[to_additive] lemma mul_prod_Ioc_eq_prod_Icc (h : a ≀ b) : f a * ∏ x ∈ Ioc a b, f x = ∏ x ∈ Icc a b, f x := by rw [Icc_eq_cons_Ioc h, prod_cons] @[to_additive] lemma prod_Ioc_mul_eq_prod_Icc (h : a ≀ b) : (∏ x ∈ Ioc a b, f x) * f a = ∏ x ∈ Icc a b, f x := by rw [mul_comm, mul_prod_Ioc_eq_prod_Icc h] end LocallyFiniteOrder section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop α] @[to_additive] lemma mul_prod_Ioi_eq_prod_Ici (a : α) : f a * ∏ x ∈ Ioi a, f x = ∏ x ∈ Ici a, f x := by rw [Ici_eq_cons_Ioi, prod_cons] @[to_additive] lemma prod_Ioi_mul_eq_prod_Ici (a : α) : (∏ x ∈ Ioi a, f x) * f a = ∏ x ∈ Ici a, f x := by rw [mul_comm, mul_prod_Ioi_eq_prod_Ici] end LocallyFiniteOrderTop section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot α] @[to_additive] lemma mul_prod_Iio_eq_prod_Iic (a : α) : f a * ∏ x ∈ Iio a, f x = ∏ x ∈ Iic a, f x := by rw [Iic_eq_cons_Iio, prod_cons] @[to_additive] lemma prod_Iio_mul_eq_prod_Iic (a : α) : (∏ x ∈ Iio a, f x) * f a = ∏ x ∈ Iic a, f x := by rw [mul_comm, mul_prod_Iio_eq_prod_Iic] end LocallyFiniteOrderBot end PartialOrder section LinearOrder variable [Fintype α] [LinearOrder α] [LocallyFiniteOrderTop α] [LocallyFiniteOrderBot α] [CommMonoid M] @[to_additive] lemma prod_prod_Ioi_mul_eq_prod_prod_off_diag (f : α → α → M) : ∏ i, ∏ j ∈ Ioi i, f j i * f i j = ∏ i, ∏ j ∈ {i}ᶜ, f j i := by simp_rw [← Ioi_disjUnion_Iio, prod_disjUnion, prod_mul_distrib] congr 1 rw [prod_sigma', prod_sigma'] refine prod_nbij' (fun i ↩ ⟹i.2, i.1⟩) (fun i ↩ ⟹i.2, i.1⟩) ?_ ?_ ?_ ?_ ?_ <;> simp end LinearOrder section Generic variable [CommMonoid M] {s₂ s₁ s : Finset α} {a : α} {g f : α → M} @[to_additive] theorem prod_Ico_add' [AddCommMonoid α] [PartialOrder α] [IsOrderedCancelAddMonoid α] [ExistsAddOfLE α] [LocallyFiniteOrder α] (f : α → M) (a b c : α) : (∏ x ∈ Ico a b, f (x + c)) = ∏ x ∈ Ico (a + c) (b + c), f x := by rw [← map_add_right_Ico, prod_map] rfl @[to_additive] theorem prod_Ico_add [AddCommMonoid α] [PartialOrder α] [IsOrderedCancelAddMonoid α] [ExistsAddOfLE α] [LocallyFiniteOrder α] (f : α → M) (a b c : α) : (∏ x ∈ Ico a b, f (c + x)) = ∏ x ∈ Ico (a + c) (b + c), f x := by convert prod_Ico_add' f a b c using 2 rw [add_comm] @[to_additive (attr := simp)] theorem prod_Ico_add_right_sub_eq [AddCommMonoid α] [PartialOrder α] [IsOrderedCancelAddMonoid α] [ExistsAddOfLE α] [LocallyFiniteOrder α] [Sub α] [OrderedSub α] (a b c : α) : ∏ x ∈ Ico (a + c) (b + c), f (x - c) = ∏ x ∈ Ico a b, f x := by simp only [← map_add_right_Ico, prod_map, addRightEmbedding_apply, add_tsub_cancel_right] @[to_additive] theorem prod_Ico_succ_top {a b : ℕ} (hab : a ≀ b) (f : ℕ → M) : (∏ k ∈ Ico a (b + 1), f k) = (∏ k ∈ Ico a b, f k) * f b := by rw [Nat.Ico_succ_right_eq_insert_Ico hab, prod_insert right_not_mem_Ico, mul_comm] @[to_additive] theorem prod_eq_prod_Ico_succ_bot {a b : ℕ} (hab : a < b) (f : ℕ → M) : ∏ k ∈ Ico a b, f k = f a * ∏ k ∈ Ico (a + 1) b, f k := by have ha : a ∉ Ico (a + 1) b := by simp rw [← prod_insert ha, Nat.Ico_insert_succ_left hab] @[to_additive] theorem prod_Ico_consecutive (f : ℕ → M) {m n k : ℕ} (hmn : m ≀ n) (hnk : n ≀ k) : ((∏ i ∈ Ico m n, f i) * ∏ i ∈ Ico n k, f i) = ∏ i ∈ Ico m k, f i := Ico_union_Ico_eq_Ico hmn hnk ▾ Eq.symm (prod_union (Ico_disjoint_Ico_consecutive m n k)) @[to_additive] theorem prod_Ioc_consecutive (f : ℕ → M) {m n k : ℕ} (hmn : m ≀ n) (hnk : n ≀ k) : ((∏ i ∈ Ioc m n, f i) * ∏ i ∈ Ioc n k, f i) = ∏ i ∈ Ioc m k, f i := by rw [← Ioc_union_Ioc_eq_Ioc hmn hnk, prod_union] apply disjoint_left.2 fun x hx h'x => _ intros x hx h'x exact lt_irrefl _ ((mem_Ioc.1 h'x).1.trans_le (mem_Ioc.1 hx).2) @[to_additive] theorem prod_Ioc_succ_top {a b : ℕ} (hab : a ≀ b) (f : ℕ → M) : (∏ k ∈ Ioc a (b + 1), f k) = (∏ k ∈ Ioc a b, f k) * f (b + 1) := by rw [← prod_Ioc_consecutive _ hab (Nat.le_succ b), Nat.Ioc_succ_singleton, prod_singleton] @[to_additive] theorem prod_Icc_succ_top {a b : ℕ} (hab : a ≀ b + 1) (f : ℕ → M) : (∏ k ∈ Icc a (b + 1), f k) = (∏ k ∈ Icc a b, f k) * f (b + 1) := by rw [← Nat.Ico_succ_right, prod_Ico_succ_top hab, Nat.Ico_succ_right] @[to_additive] theorem prod_range_mul_prod_Ico (f : ℕ → M) {m n : ℕ} (h : m ≀ n) : ((∏ k ∈ range m, f k) * ∏ k ∈ Ico m n, f k) = ∏ k ∈ range n, f k := Nat.Ico_zero_eq_range ▾ Nat.Ico_zero_eq_range ▾ prod_Ico_consecutive f m.zero_le h @[to_additive] theorem prod_range_eq_mul_Ico (f : ℕ → M) {n : ℕ} (hn : 0 < n) : ∏ x ∈ Finset.range n, f x = f 0 * ∏ x ∈ Ico 1 n, f x := Finset.range_eq_Ico ▾ Finset.prod_eq_prod_Ico_succ_bot hn f @[to_additive] theorem prod_Ico_eq_mul_inv {ÎŽ : Type*} [CommGroup ÎŽ] (f : ℕ → ÎŽ) {m n : ℕ} (h : m ≀ n) : ∏ k ∈ Ico m n, f k = (∏ k ∈ range n, f k) * (∏ k ∈ range m, f k)⁻¹ := eq_mul_inv_iff_mul_eq.2 <| by (rw [mul_comm]; exact prod_range_mul_prod_Ico f h) @[to_additive] theorem prod_Ico_eq_div {ÎŽ : Type*} [CommGroup ÎŽ] (f : ℕ → ÎŽ) {m n : ℕ} (h : m ≀ n) : ∏ k ∈ Ico m n, f k = (∏ k ∈ range n, f k) / ∏ k ∈ range m, f k := by simpa only [div_eq_mul_inv] using prod_Ico_eq_mul_inv f h @[to_additive] theorem prod_range_div_prod_range {α : Type*} [CommGroup α] {f : ℕ → α} {n m : ℕ} (hnm : n ≀ m) : ((∏ k ∈ range m, f k) / ∏ k ∈ range n, f k) = ∏ k ∈ range m with n ≀ k, f k := by rw [← prod_Ico_eq_div f hnm] congr apply Finset.ext simp only [mem_Ico, mem_filter, mem_range, *] tauto /-- The two ways of summing over `(i, j)` in the range `a ≀ i ≀ j < b` are equal. -/ theorem sum_Ico_Ico_comm {M : Type*} [AddCommMonoid M] (a b : ℕ) (f : ℕ → ℕ → M) : (∑ i ∈ Finset.Ico a b, ∑ j ∈ Finset.Ico i b, f i j) = ∑ j ∈ Finset.Ico a b, ∑ i ∈ Finset.Ico a (j + 1), f i j := by rw [Finset.sum_sigma', Finset.sum_sigma'] refine sum_nbij' (fun x ↩ ⟹x.2, x.1⟩) (fun x ↩ ⟹x.2, x.1⟩) ?_ ?_ (fun _ _ ↩ rfl) (fun _ _ ↩ rfl) (fun _ _ ↩ rfl) <;> simp only [Finset.mem_Ico, Sigma.forall, Finset.mem_sigma] <;> rintro a b ⟹⟹h₁, h₂⟩, ⟹h₃, h₄⟩⟩ <;> omega /-- The two ways of summing over `(i, j)` in the range `a ≀ i < j < b` are equal. -/ theorem sum_Ico_Ico_comm' {M : Type*} [AddCommMonoid M] (a b : ℕ) (f : ℕ → ℕ → M) : (∑ i ∈ Finset.Ico a b, ∑ j ∈ Finset.Ico (i + 1) b, f i j) = ∑ j ∈ Finset.Ico a b, ∑ i ∈ Finset.Ico a j, f i j := by rw [Finset.sum_sigma', Finset.sum_sigma'] refine sum_nbij' (fun x ↩ ⟹x.2, x.1⟩) (fun x ↩ ⟹x.2, x.1⟩) ?_ ?_ (fun _ _ ↩ rfl) (fun _ _ ↩ rfl) (fun _ _ ↩ rfl) <;> simp only [Finset.mem_Ico, Sigma.forall, Finset.mem_sigma] <;> rintro a b ⟹⟹h₁, h₂⟩, ⟹h₃, h₄⟩⟩ <;> omega @[to_additive] theorem prod_Ico_eq_prod_range (f : ℕ → M) (m n : ℕ) : ∏ k ∈ Ico m n, f k = ∏ k ∈ range (n - m), f (m + k) := by by_cases h : m ≀ n · rw [← Nat.Ico_zero_eq_range, prod_Ico_add, zero_add, tsub_add_cancel_of_le h]
· replace h : n ≀ m := le_of_not_ge h rw [Ico_eq_empty_of_le h, tsub_eq_zero_iff_le.mpr h, range_zero, prod_empty, prod_empty] theorem prod_Ico_reflect (f : ℕ → M) (k : ℕ) {m n : ℕ} (h : m ≀ n + 1) : (∏ j ∈ Ico k m, f (n - j)) = ∏ j ∈ Ico (n + 1 - m) (n + 1 - k), f j := by have : ∀ i < m, i ≀ n := by intro i hi exact (add_le_add_iff_right 1).1 (le_trans (Nat.lt_iff_add_one_le.1 hi) h) rcases lt_or_le k m with hkm | hkm
Mathlib/Algebra/BigOperators/Intervals.lean
200
208
/- 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
Mathlib/Algebra/Group/Basic.lean
280
285
/- Copyright (c) 2022 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.NumberTheory.Cyclotomic.Discriminant import Mathlib.RingTheory.Polynomial.Eisenstein.IsIntegral import Mathlib.RingTheory.Ideal.Norm.AbsNorm import Mathlib.RingTheory.Prime /-! # Ring of integers of `p ^ n`-th cyclotomic fields We gather results about cyclotomic extensions of `ℚ`. In particular, we compute the ring of integers of a `p ^ n`-th cyclotomic extension of `ℚ`. ## Main results * `IsCyclotomicExtension.Rat.isIntegralClosure_adjoin_singleton_of_prime_pow`: if `K` is a `p ^ k`-th cyclotomic extension of `ℚ`, then `(adjoin â„€ {ζ})` is the integral closure of `â„€` in `K`. * `IsCyclotomicExtension.Rat.cyclotomicRing_isIntegralClosure_of_prime_pow`: the integral closure of `â„€` inside `CyclotomicField (p ^ k) ℚ` is `CyclotomicRing (p ^ k) â„€ ℚ`. * `IsCyclotomicExtension.Rat.absdiscr_prime_pow` and related results: the absolute discriminant of cyclotomic fields. -/ universe u open Algebra IsCyclotomicExtension Polynomial NumberField open scoped Cyclotomic Nat variable {p : ℕ+} {k : ℕ} {K : Type u} [Field K] {ζ : K} [hp : Fact (p : ℕ).Prime] namespace IsCyclotomicExtension.Rat variable [CharZero K] /-- The discriminant of the power basis given by `ζ - 1`. -/ theorem discr_prime_pow_ne_two' [IsCyclotomicExtension {p ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) (hk : p ^ (k + 1) ≠ 2) : discr ℚ (hζ.subOnePowerBasis ℚ).basis = (-1) ^ ((p ^ (k + 1) : ℕ).totient / 2) * p ^ ((p : ℕ) ^ k * ((p - 1) * (k + 1) - 1)) := by rw [← discr_prime_pow_ne_two hζ (cyclotomic.irreducible_rat (p ^ (k + 1)).pos) hk] exact hζ.discr_zeta_eq_discr_zeta_sub_one.symm theorem discr_odd_prime' [IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) (hodd : p ≠ 2) : discr ℚ (hζ.subOnePowerBasis ℚ).basis = (-1) ^ (((p : ℕ) - 1) / 2) * p ^ ((p : ℕ) - 2) := by rw [← discr_odd_prime hζ (cyclotomic.irreducible_rat hp.out.pos) hodd] exact hζ.discr_zeta_eq_discr_zeta_sub_one.symm /-- The discriminant of the power basis given by `ζ - 1`. Beware that in the cases `p ^ k = 1` and `p ^ k = 2` the formula uses `1 / 2 = 0` and `0 - 1 = 0`. It is useful only to have a uniform result. See also `IsCyclotomicExtension.Rat.discr_prime_pow_eq_unit_mul_pow'`. -/ theorem discr_prime_pow' [IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : discr ℚ (hζ.subOnePowerBasis ℚ).basis = (-1) ^ ((p ^ k : ℕ).totient / 2) * p ^ ((p : ℕ) ^ (k - 1) * ((p - 1) * k - 1)) := by rw [← discr_prime_pow hζ (cyclotomic.irreducible_rat (p ^ k).pos)] exact hζ.discr_zeta_eq_discr_zeta_sub_one.symm /-- If `p` is a prime and `IsCyclotomicExtension {p ^ k} K L`, then there are `u : ℀ˣ` and `n : ℕ` such that the discriminant of the power basis given by `ζ - 1` is `u * p ^ n`. Often this is enough and less cumbersome to use than `IsCyclotomicExtension.Rat.discr_prime_pow'`. -/ theorem discr_prime_pow_eq_unit_mul_pow' [IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : ∃ (u : ℀ˣ) (n : ℕ), discr ℚ (hζ.subOnePowerBasis ℚ).basis = u * p ^ n := by rw [hζ.discr_zeta_eq_discr_zeta_sub_one.symm] exact discr_prime_pow_eq_unit_mul_pow hζ (cyclotomic.irreducible_rat (p ^ k).pos) /-- If `K` is a `p ^ k`-th cyclotomic extension of `ℚ`, then `(adjoin â„€ {ζ})` is the integral closure of `â„€` in `K`. -/ theorem isIntegralClosure_adjoin_singleton_of_prime_pow [hcycl : IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : IsIntegralClosure (adjoin â„€ ({ζ} : Set K)) â„€ K := by refine ⟹Subtype.val_injective, @fun x => ⟹fun h => ⟹⟹x, ?_⟩, rfl⟩, ?_⟩⟩ swap · rintro ⟹y, rfl⟩ exact IsIntegral.algebraMap ((le_integralClosure_iff_isIntegral.1 (adjoin_le_integralClosure (hζ.isIntegral (p ^ k).pos))).isIntegral _) let B := hζ.subOnePowerBasis ℚ have hint : IsIntegral â„€ B.gen := (hζ.isIntegral (p ^ k).pos).sub isIntegral_one -- Porting note: the following `letI` was not needed because the locale `cyclotomic` set it -- as instances. letI := IsCyclotomicExtension.finiteDimensional {p ^ k} ℚ K have H := discr_mul_isIntegral_mem_adjoin ℚ hint h obtain ⟹u, n, hun⟩ := discr_prime_pow_eq_unit_mul_pow' hζ rw [hun] at H replace H := Subalgebra.smul_mem _ H u.inv rw [← smul_assoc, ← smul_mul_assoc, Units.inv_eq_val_inv, zsmul_eq_mul, ← Int.cast_mul, Units.inv_mul, Int.cast_one, one_mul, smul_def, map_pow] at H cases k · haveI : IsCyclotomicExtension {1} ℚ K := by simpa using hcycl have : x ∈ (⊥ : Subalgebra ℚ K) := by rw [singleton_one ℚ K] exact mem_top obtain ⟹y, rfl⟩ := mem_bot.1 this replace h := (isIntegral_algebraMap_iff (algebraMap ℚ K).injective).1 h obtain ⟹z, hz⟩ := IsIntegrallyClosed.isIntegral_iff.1 h rw [← hz, ← IsScalarTower.algebraMap_apply] exact Subalgebra.algebraMap_mem _ _ · have hmin : (minpoly â„€ B.gen).IsEisensteinAt (Submodule.span â„€ {((p : ℕ) : â„€)}) := by have h₁ := minpoly.isIntegrallyClosed_eq_field_fractions' ℚ hint have h₂ := hζ.minpoly_sub_one_eq_cyclotomic_comp (cyclotomic.irreducible_rat (p ^ _).pos) rw [IsPrimitiveRoot.subOnePowerBasis_gen] at h₁ rw [h₁, ← map_cyclotomic_int, show Int.castRingHom ℚ = algebraMap â„€ ℚ by rfl, show X + 1 = map (algebraMap â„€ ℚ) (X + 1) by simp, ← map_comp] at h₂ rw [IsPrimitiveRoot.subOnePowerBasis_gen, map_injective (algebraMap â„€ ℚ) (algebraMap â„€ ℚ).injective_int h₂] exact cyclotomic_prime_pow_comp_X_add_one_isEisensteinAt p _ refine adjoin_le ?_ (mem_adjoin_of_smul_prime_pow_smul_of_minpoly_isEisensteinAt (n := n) (Nat.prime_iff_prime_int.1 hp.out) hint h (by simpa using H) hmin) simp only [Set.singleton_subset_iff, SetLike.mem_coe] exact Subalgebra.sub_mem _ (self_mem_adjoin_singleton â„€ _) (Subalgebra.one_mem _) theorem isIntegralClosure_adjoin_singleton_of_prime [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ ↑p) : IsIntegralClosure (adjoin â„€ ({ζ} : Set K)) â„€ K := by rw [← pow_one p] at hζ hcycl exact isIntegralClosure_adjoin_singleton_of_prime_pow hζ /-- The integral closure of `â„€` inside `CyclotomicField (p ^ k) ℚ` is `CyclotomicRing (p ^ k) â„€ ℚ`. -/ theorem cyclotomicRing_isIntegralClosure_of_prime_pow : IsIntegralClosure (CyclotomicRing (p ^ k) â„€ ℚ) â„€ (CyclotomicField (p ^ k) ℚ) := by have hζ := zeta_spec (p ^ k) ℚ (CyclotomicField (p ^ k) ℚ) refine ⟹IsFractionRing.injective _ _, @fun x => ⟹fun h => ⟹⟹x, ?_⟩, rfl⟩, ?_⟩⟩ · obtain ⟹y, rfl⟩ := (isIntegralClosure_adjoin_singleton_of_prime_pow hζ).isIntegral_iff.1 h refine adjoin_mono ?_ y.2 simp only [PNat.pow_coe, Set.singleton_subset_iff, Set.mem_setOf_eq] exact hζ.pow_eq_one · rintro ⟹y, rfl⟩ exact IsIntegral.algebraMap ((IsCyclotomicExtension.integral {p ^ k} â„€ _).isIntegral _) theorem cyclotomicRing_isIntegralClosure_of_prime : IsIntegralClosure (CyclotomicRing p â„€ ℚ) â„€ (CyclotomicField p ℚ) := by rw [← pow_one p] exact cyclotomicRing_isIntegralClosure_of_prime_pow end IsCyclotomicExtension.Rat section PowerBasis open IsCyclotomicExtension.Rat namespace IsPrimitiveRoot section CharZero variable [CharZero K] /-- The algebra isomorphism `adjoin â„€ {ζ} ≃ₐ[â„€] (𝓞 K)`, where `ζ` is a primitive `p ^ k`-th root of unity and `K` is a `p ^ k`-th cyclotomic extension of `ℚ`. -/ @[simps!] noncomputable def _root_.IsPrimitiveRoot.adjoinEquivRingOfIntegers [IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : adjoin â„€ ({ζ} : Set K) ≃ₐ[â„€] 𝓞 K := let _ := isIntegralClosure_adjoin_singleton_of_prime_pow hζ IsIntegralClosure.equiv â„€ (adjoin â„€ ({ζ} : Set K)) K (𝓞 K) /-- The ring of integers of a `p ^ k`-th cyclotomic extension of `ℚ` is a cyclotomic extension. -/ instance IsCyclotomicExtension.ringOfIntegers [IsCyclotomicExtension {p ^ k} ℚ K] : IsCyclotomicExtension {p ^ k} â„€ (𝓞 K) := let _ := (zeta_spec (p ^ k) ℚ K).adjoin_isCyclotomicExtension â„€ IsCyclotomicExtension.equiv _ â„€ _ (zeta_spec (p ^ k) ℚ K).adjoinEquivRingOfIntegers /-- The integral `PowerBasis` of `𝓞 K` given by a primitive root of unity, where `K` is a `p ^ k` cyclotomic extension of `ℚ`. -/ noncomputable def integralPowerBasis [IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : PowerBasis â„€ (𝓞 K) := (Algebra.adjoin.powerBasis' (hζ.isIntegral (p ^ k).pos)).map hζ.adjoinEquivRingOfIntegers /-- Abbreviation to see a primitive root of unity as a member of the ring of integers. -/ abbrev toInteger {k : ℕ+} (hζ : IsPrimitiveRoot ζ k) : 𝓞 K := ⟚ζ, hζ.isIntegral k.pos⟩ end CharZero lemma coe_toInteger {k : ℕ+} (hζ : IsPrimitiveRoot ζ k) : hζ.toInteger.1 = ζ := rfl /-- `𝓞 K â§ž Ideal.span {ζ - 1}` is finite. -/ lemma finite_quotient_toInteger_sub_one [NumberField K] {k : ℕ+} (hk : 1 < k) (hζ : IsPrimitiveRoot ζ k) : Finite (𝓞 K â§ž Ideal.span {hζ.toInteger - 1}) := by refine Ideal.finiteQuotientOfFreeOfNeBot _ (fun h ↩ ?_) simp only [Ideal.span_singleton_eq_bot, sub_eq_zero, ← Subtype.coe_inj] at h exact hζ.ne_one hk (RingOfIntegers.ext_iff.1 h) /-- We have that `𝓞 K â§ž Ideal.span {ζ - 1}` has cardinality equal to the norm of `ζ - 1`. See the results below to compute this norm in various cases. -/ lemma card_quotient_toInteger_sub_one [NumberField K] {k : ℕ+} (hζ : IsPrimitiveRoot ζ k) : Nat.card (𝓞 K â§ž Ideal.span {hζ.toInteger - 1}) = (Algebra.norm â„€ (hζ.toInteger - 1)).natAbs := by rw [← Submodule.cardQuot_apply, ← Ideal.absNorm_apply, Ideal.absNorm_span_singleton] lemma toInteger_isPrimitiveRoot {k : ℕ+} (hζ : IsPrimitiveRoot ζ k) : IsPrimitiveRoot hζ.toInteger k := IsPrimitiveRoot.of_map_of_injective (by exact hζ) RingOfIntegers.coe_injective variable [CharZero K] @[simp] theorem integralPowerBasis_gen [hcycl : IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : hζ.integralPowerBasis.gen = hζ.toInteger := Subtype.ext <| show algebraMap _ K hζ.integralPowerBasis.gen = _ by rw [integralPowerBasis, PowerBasis.map_gen, adjoin.powerBasis'_gen] simp only [adjoinEquivRingOfIntegers_apply, IsIntegralClosure.algebraMap_lift] rfl #adaptation_note /-- https://github.com/leanprover/lean4/pull/5338 We name `hcycl` so it can be used as a named argument, but since https://github.com/leanprover/lean4/pull/5338, this is considered unused, so we need to disable the linter. -/ set_option linter.unusedVariables false in @[simp] theorem integralPowerBasis_dim [hcycl : IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : hζ.integralPowerBasis.dim = φ (p ^ k) := by simp [integralPowerBasis, ← cyclotomic_eq_minpoly hζ, natDegree_cyclotomic] /-- The algebra isomorphism `adjoin â„€ {ζ} ≃ₐ[â„€] (𝓞 K)`, where `ζ` is a primitive `p`-th root of unity and `K` is a `p`-th cyclotomic extension of `ℚ`. -/ @[simps!] noncomputable def _root_.IsPrimitiveRoot.adjoinEquivRingOfIntegers' [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) : adjoin â„€ ({ζ} : Set K) ≃ₐ[â„€] 𝓞 K := have : IsCyclotomicExtension {p ^ 1} ℚ K := by convert hcycl; rw [pow_one] adjoinEquivRingOfIntegers (p := p) (k := 1) (ζ := ζ) (by rwa [pow_one]) /-- The ring of integers of a `p`-th cyclotomic extension of `ℚ` is a cyclotomic extension. -/ instance _root_.IsCyclotomicExtension.ring_of_integers' [IsCyclotomicExtension {p} ℚ K] : IsCyclotomicExtension {p} â„€ (𝓞 K) := let _ := (zeta_spec p ℚ K).adjoin_isCyclotomicExtension â„€ IsCyclotomicExtension.equiv _ â„€ _ (zeta_spec p ℚ K).adjoinEquivRingOfIntegers' /-- The integral `PowerBasis` of `𝓞 K` given by a primitive root of unity, where `K` is a `p`-th cyclotomic extension of `ℚ`. -/ noncomputable def integralPowerBasis' [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) : PowerBasis â„€ (𝓞 K) := have : IsCyclotomicExtension {p ^ 1} ℚ K := by convert hcycl; rw [pow_one] integralPowerBasis (p := p) (k := 1) (ζ := ζ) (by rwa [pow_one]) @[simp] theorem integralPowerBasis'_gen [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) : hζ.integralPowerBasis'.gen = hζ.toInteger := integralPowerBasis_gen (hcycl := by rwa [pow_one]) (by rwa [pow_one]) @[simp] theorem power_basis_int'_dim [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) : hζ.integralPowerBasis'.dim = φ p := by rw [integralPowerBasis', integralPowerBasis_dim (hcycl := by rwa [pow_one]) (by rwa [pow_one]), pow_one] /-- The integral `PowerBasis` of `𝓞 K` given by `ζ - 1`, where `K` is a `p ^ k` cyclotomic extension of `ℚ`. -/ noncomputable def subOneIntegralPowerBasis [IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : PowerBasis â„€ (𝓞 K) := PowerBasis.ofGenMemAdjoin' hζ.integralPowerBasis (RingOfIntegers.isIntegral _) (by simp only [integralPowerBasis_gen, toInteger] convert Subalgebra.add_mem _ (self_mem_adjoin_singleton â„€ (⟚ζ - 1, _⟩ : 𝓞 K)) (Subalgebra.one_mem _) · simp · exact Subalgebra.sub_mem _ (hζ.isIntegral (by simp)) (Subalgebra.one_mem _)) @[simp] theorem subOneIntegralPowerBasis_gen [IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : hζ.subOneIntegralPowerBasis.gen = ⟚ζ - 1, Subalgebra.sub_mem _ (hζ.isIntegral (p ^ k).pos) (Subalgebra.one_mem _)⟩ := by simp [subOneIntegralPowerBasis] /-- The integral `PowerBasis` of `𝓞 K` given by `ζ - 1`, where `K` is a `p`-th cyclotomic extension of `ℚ`. -/ noncomputable def subOneIntegralPowerBasis' [IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) : PowerBasis â„€ (𝓞 K) := have : IsCyclotomicExtension {p ^ 1} ℚ K := by rwa [pow_one] subOneIntegralPowerBasis (p := p) (k := 1) (ζ := ζ) (by rwa [pow_one]) @[simp, nolint unusedHavesSuffices] theorem subOneIntegralPowerBasis'_gen [IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) : hζ.subOneIntegralPowerBasis'.gen = hζ.toInteger - 1 := -- The `unusedHavesSuffices` linter incorrectly thinks this `have` is unnecessary. have : IsCyclotomicExtension {p ^ 1} ℚ K := by rwa [pow_one] subOneIntegralPowerBasis_gen (by rwa [pow_one]) /-- `ζ - 1` is prime if `p ≠ 2` and `ζ` is a primitive `p ^ (k + 1)`-th root of unity. See `zeta_sub_one_prime` for a general statement. -/ theorem zeta_sub_one_prime_of_ne_two [IsCyclotomicExtension {p ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) (hodd : p ≠ 2) : Prime (hζ.toInteger - 1) := by letI := IsCyclotomicExtension.numberField {p ^ (k + 1)} ℚ K refine Ideal.prime_of_irreducible_absNorm_span (fun h ↩ ?_) ?_ · apply hζ.pow_ne_one_of_pos_of_lt zero_lt_one (one_lt_pow₀ hp.out.one_lt (by simp)) rw [sub_eq_zero] at h simpa using congrArg (algebraMap _ K) h rw [Nat.irreducible_iff_prime, Ideal.absNorm_span_singleton, ← Nat.prime_iff, ← Int.prime_iff_natAbs_prime] convert Nat.prime_iff_prime_int.1 hp.out apply RingHom.injective_int (algebraMap â„€ ℚ) rw [← Algebra.norm_localization (Sₘ := K) â„€ (nonZeroDivisors â„€)] simp only [PNat.pow_coe, id.map_eq_id, RingHomCompTriple.comp_eq, RingHom.coe_coe, Subalgebra.coe_val, algebraMap_int_eq, map_natCast] exact hζ.norm_sub_one_of_prime_ne_two (Polynomial.cyclotomic.irreducible_rat (PNat.pos _)) hodd /-- `ζ - 1` is prime if `ζ` is a primitive `2 ^ (k + 1)`-th root of unity. See `zeta_sub_one_prime` for a general statement. -/ theorem zeta_sub_one_prime_of_two_pow [IsCyclotomicExtension {(2 : ℕ+) ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑((2 : ℕ+) ^ (k + 1))) : Prime (hζ.toInteger - 1) := by letI := IsCyclotomicExtension.numberField {(2 : ℕ+) ^ (k + 1)} ℚ K refine Ideal.prime_of_irreducible_absNorm_span (fun h ↩ ?_) ?_ · apply hζ.pow_ne_one_of_pos_of_lt zero_lt_one (one_lt_pow₀ (by decide) (by simp)) rw [sub_eq_zero] at h simpa using congrArg (algebraMap _ K) h rw [Nat.irreducible_iff_prime, Ideal.absNorm_span_singleton, ← Nat.prime_iff, ← Int.prime_iff_natAbs_prime] cases k · convert Prime.neg Int.prime_two apply RingHom.injective_int (algebraMap â„€ ℚ) rw [← Algebra.norm_localization (Sₘ := K) â„€ (nonZeroDivisors â„€)] simp only [PNat.pow_coe, id.map_eq_id, RingHomCompTriple.comp_eq, RingHom.coe_coe, Subalgebra.coe_val, algebraMap_int_eq, map_neg, map_ofNat] simpa only [zero_add, pow_one, AddSubgroupClass.coe_sub, OneMemClass.coe_one, pow_zero] using hζ.norm_pow_sub_one_two (cyclotomic.irreducible_rat (by simp only [zero_add, pow_one, Nat.ofNat_pos])) convert Int.prime_two apply RingHom.injective_int (algebraMap â„€ ℚ) rw [← Algebra.norm_localization (Sₘ := K) â„€ (nonZeroDivisors â„€)] simp only [PNat.pow_coe, id.map_eq_id, RingHomCompTriple.comp_eq, RingHom.coe_coe, Subalgebra.coe_val, algebraMap_int_eq, map_natCast] exact hζ.norm_sub_one_two Nat.AtLeastTwo.prop (cyclotomic.irreducible_rat (by simp)) /-- `ζ - 1` is prime if `ζ` is a primitive `p ^ (k + 1)`-th root of unity. -/ theorem zeta_sub_one_prime [IsCyclotomicExtension {p ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) : Prime (hζ.toInteger - 1) := by by_cases htwo : p = 2 · subst htwo apply hζ.zeta_sub_one_prime_of_two_pow · apply hζ.zeta_sub_one_prime_of_ne_two htwo /-- `ζ - 1` is prime if `ζ` is a primitive `p`-th root of unity. -/ theorem zeta_sub_one_prime' [h : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) : Prime ((hζ.toInteger - 1)) := by convert zeta_sub_one_prime (k := 0) (by simpa only [zero_add, pow_one]) simpa only [zero_add, pow_one] theorem subOneIntegralPowerBasis_gen_prime [IsCyclotomicExtension {p ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) : Prime hζ.subOneIntegralPowerBasis.gen := by simpa only [subOneIntegralPowerBasis_gen] using hζ.zeta_sub_one_prime theorem subOneIntegralPowerBasis'_gen_prime [IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ ↑p) : Prime hζ.subOneIntegralPowerBasis'.gen := by simpa only [subOneIntegralPowerBasis'_gen] using hζ.zeta_sub_one_prime' /-- The norm, relative to `â„€`, of `ζ ^ p ^ s - 1` in a `p ^ (k + 1)`-th cyclotomic extension of `ℚ` is p ^ p ^ s` if `s ≀ k` and `p ^ (k - s + 1) ≠ 2`. -/ lemma norm_toInteger_pow_sub_one_of_prime_pow_ne_two [IsCyclotomicExtension {p ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) {s : ℕ} (hs : s ≀ k) (htwo : p ^ (k - s + 1) ≠ 2) : Algebra.norm â„€ (hζ.toInteger ^ (p : ℕ) ^ s - 1) = p ^ (p : ℕ) ^ s := by have : NumberField K := IsCyclotomicExtension.numberField {p ^ (k + 1)} ℚ K rw [Algebra.norm_eq_iff â„€ (Sₘ := K) (Rₘ := ℚ) rfl.le] simp [hζ.norm_pow_sub_one_of_prime_pow_ne_two (cyclotomic.irreducible_rat (by simp only [PNat.pow_coe, gt_iff_lt, PNat.pos, pow_pos])) hs htwo] /-- The norm, relative to `â„€`, of `ζ ^ 2 ^ k - 1` in a `2 ^ (k + 1)`-th cyclotomic extension of `ℚ` is `(-2) ^ 2 ^ k`. -/ lemma norm_toInteger_pow_sub_one_of_two [IsCyclotomicExtension {2 ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑((2 : ℕ+) ^ (k + 1))) : Algebra.norm â„€ (hζ.toInteger ^ 2 ^ k - 1) = (-2) ^ (2 : ℕ) ^ k := by have : NumberField K := IsCyclotomicExtension.numberField {2 ^ (k + 1)} ℚ K rw [Algebra.norm_eq_iff â„€ (Sₘ := K) (Rₘ := ℚ) rfl.le] simp [hζ.norm_pow_sub_one_two (cyclotomic.irreducible_rat (pow_pos (by decide) _))] /-- The norm, relative to `â„€`, of `ζ ^ p ^ s - 1` in a `p ^ (k + 1)`-th cyclotomic extension of `ℚ` is `p ^ p ^ s` if `s ≀ k` and `p ≠ 2`. -/ lemma norm_toInteger_pow_sub_one_of_prime_ne_two [IsCyclotomicExtension {p ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) {s : ℕ} (hs : s ≀ k) (hodd : p ≠ 2) : Algebra.norm â„€ (hζ.toInteger ^ (p : ℕ) ^ s - 1) = p ^ (p : ℕ) ^ s := by refine hζ.norm_toInteger_pow_sub_one_of_prime_pow_ne_two hs (fun h ↩ hodd ?_) suffices h : (p : ℕ) = 2 from PNat.coe_injective h apply eq_of_prime_pow_eq hp.out.prime Nat.prime_two.prime (k - s).succ_pos rw [pow_one] exact congr_arg Subtype.val h /-- The norm, relative to `â„€`, of `ζ - 1` in a `p ^ (k + 1)`-th cyclotomic extension of `ℚ` is `p` if `p ≠ 2`. -/ lemma norm_toInteger_sub_one_of_prime_ne_two [IsCyclotomicExtension {p ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) (hodd : p ≠ 2) : Algebra.norm â„€ (hζ.toInteger - 1) = p := by simpa only [pow_zero, pow_one] using hζ.norm_toInteger_pow_sub_one_of_prime_ne_two (Nat.zero_le _) hodd /-- The norm, relative to `â„€`, of `ζ - 1` in a `p`-th cyclotomic extension of `ℚ` is `p` if `p ≠ 2`. -/ lemma norm_toInteger_sub_one_of_prime_ne_two' [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) (h : p ≠ 2) : Algebra.norm â„€ (hζ.toInteger - 1) = p := by have : IsCyclotomicExtension {p ^ (0 + 1)} ℚ K := by simpa using hcycl replace hζ : IsPrimitiveRoot ζ (p ^ (0 + 1)) := by simpa using hζ exact hζ.norm_toInteger_sub_one_of_prime_ne_two h /-- The norm, relative to `â„€`, of `ζ - 1` in a `p ^ (k + 1)`-th cyclotomic extension of `ℚ` is a prime if `p ^ (k + 1) ≠ 2`. -/ lemma prime_norm_toInteger_sub_one_of_prime_pow_ne_two [IsCyclotomicExtension {p ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) (htwo : p ^ (k + 1) ≠ 2) : Prime (Algebra.norm â„€ (hζ.toInteger - 1)) := by have := hζ.norm_toInteger_pow_sub_one_of_prime_pow_ne_two (zero_le _) htwo simp only [pow_zero, pow_one] at this rw [this] exact Nat.prime_iff_prime_int.1 hp.out /-- The norm, relative to `â„€`, of `ζ - 1` in a `p ^ (k + 1)`-th cyclotomic extension of `ℚ` is a prime if `p ≠ 2`. -/ lemma prime_norm_toInteger_sub_one_of_prime_ne_two [hcycl : IsCyclotomicExtension {p ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) (hodd : p ≠ 2) : Prime (Algebra.norm â„€ (hζ.toInteger - 1)) := by have := hζ.norm_toInteger_sub_one_of_prime_ne_two hodd simp only [pow_zero, pow_one] at this rw [this] exact Nat.prime_iff_prime_int.1 hp.out /-- The norm, relative to `â„€`, of `ζ - 1` in a `p`-th cyclotomic extension of `ℚ` is a prime if `p ≠ 2`. -/ lemma prime_norm_toInteger_sub_one_of_prime_ne_two' [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ ↑p) (hodd : p ≠ 2) : Prime (Algebra.norm â„€ (hζ.toInteger - 1)) := by have : IsCyclotomicExtension {p ^ (0 + 1)} ℚ K := by simpa using hcycl replace hζ : IsPrimitiveRoot ζ (p ^ (0 + 1)) := by simpa using hζ exact hζ.prime_norm_toInteger_sub_one_of_prime_ne_two hodd /-- In a `p ^ (k + 1)`-th cyclotomic extension of `ℚ `, we have that `ζ` is not congruent to an integer modulo `p` if `p ^ (k + 1) ≠ 2`. -/ theorem not_exists_int_prime_dvd_sub_of_prime_pow_ne_two [hcycl : IsCyclotomicExtension {p ^ (k + 1)} ℚ K]
(hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) (htwo : p ^ (k + 1) ≠ 2) : ¬(∃ n : â„€, (p : 𝓞 K) ∣ (hζ.toInteger - n : 𝓞 K)) := by intro ⟹n, x, h⟩ -- Let `pB` be the power basis of `𝓞 K` given by powers of `ζ`. let pB := hζ.integralPowerBasis have hdim : pB.dim = ↑p ^ k * (↑p - 1) := by simp [integralPowerBasis_dim, pB, Nat.totient_prime_pow hp.1 (Nat.zero_lt_succ k)] replace hdim : 1 < pB.dim := by
Mathlib/NumberTheory/Cyclotomic/Rat.lean
440
447
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl, Sander Dahmen, Kim Morrison -/ import Mathlib.Algebra.Algebra.Tower import Mathlib.LinearAlgebra.LinearIndependent.Basic import Mathlib.Data.Set.Card /-! # Dimension of modules and vector spaces ## Main definitions * The rank of a module is defined as `Module.rank : Cardinal`. This is defined as the supremum of the cardinalities of linearly independent subsets. ## Main statements * `LinearMap.rank_le_of_injective`: the source of an injective linear map has dimension at most that of the target. * `LinearMap.rank_le_of_surjective`: the target of a surjective linear map has dimension at most that of that source. ## Implementation notes Many theorems in this file are not universe-generic when they relate dimensions in different universes. They should be as general as they can be without inserting `lift`s. The types `M`, `M'`, ... all live in different universes, and `M₁`, `M₂`, ... all live in the same universe. -/ noncomputable section universe w w' u u' v v' variable {R : Type u} {R' : Type u'} {M M₁ : Type v} {M' : Type v'} open Cardinal Submodule Function Set section Module section variable [Semiring R] [AddCommMonoid M] [Module R M] variable (R M) /-- The rank of a module, defined as a term of type `Cardinal`. We define this as the supremum of the cardinalities of linearly independent subsets. The supremum may not be attained, see https://mathoverflow.net/a/263053. For a free module over any ring satisfying the strong rank condition (e.g. left-noetherian rings, commutative rings, and in particular division rings and fields), this is the same as the dimension of the space (i.e. the cardinality of any basis). In particular this agrees with the usual notion of the dimension of a vector space. See also `Module.finrank` for a `ℕ`-valued function which returns the correct value for a finite-dimensional vector space (but 0 for an infinite-dimensional vector space). -/ @[stacks 09G3 "first part"] protected irreducible_def Module.rank : Cardinal := ⹆ ι : { s : Set M // LinearIndepOn R id s }, (#ι.1) theorem rank_le_card : Module.rank R M ≀ #M := (Module.rank_def _ _).trans_le (ciSup_le' fun _ ↩ mk_set_le _) lemma nonempty_linearIndependent_set : Nonempty {s : Set M // LinearIndepOn R id s } := ⟹⟹∅, linearIndepOn_empty _ _⟩⟩ end namespace LinearIndependent variable [Semiring R] [AddCommMonoid M] [Module R M] variable [Nontrivial R] theorem cardinal_lift_le_rank {ι : Type w} {v : ι → M} (hv : LinearIndependent R v) : Cardinal.lift.{v} #ι ≀ Cardinal.lift.{w} (Module.rank R M) := by rw [Module.rank] refine le_trans ?_ (lift_le.mpr <| le_ciSup (bddAbove_range _) ⟹_, hv.linearIndepOn_id⟩) exact lift_mk_le'.mpr ⟹(Equiv.ofInjective _ hv.injective).toEmbedding⟩ lemma aleph0_le_rank {ι : Type w} [Infinite ι] {v : ι → M} (hv : LinearIndependent R v) : ℵ₀ ≀ Module.rank R M := aleph0_le_lift.mp <| (aleph0_le_lift.mpr <| aleph0_le_mk ι).trans hv.cardinal_lift_le_rank theorem cardinal_le_rank {ι : Type v} {v : ι → M} (hv : LinearIndependent R v) : #ι ≀ Module.rank R M := by simpa using hv.cardinal_lift_le_rank theorem cardinal_le_rank' {s : Set M} (hs : LinearIndependent R (fun x => x : s → M)) : #s ≀ Module.rank R M := hs.cardinal_le_rank theorem _root_.LinearIndepOn.encard_le_toENat_rank {ι : Type*} {v : ι → M} {s : Set ι} (hs : LinearIndepOn R v s) : s.encard ≀ (Module.rank R M).toENat := by simpa using OrderHom.mono (β := ℕ∞) Cardinal.toENat hs.linearIndependent.cardinal_lift_le_rank end LinearIndependent section SurjectiveInjective section Semiring variable [Semiring R] [AddCommMonoid M] [Module R M] [Semiring R'] section variable [AddCommMonoid M'] [Module R' M'] /-- If `M / R` and `M' / R'` are modules, `i : R' → R` is an injective map non-zero elements, `j : M →+ M'` is an injective monoid homomorphism, such that the scalar multiplications on `M` and `M'` are compatible, then the rank of `M / R` is smaller than or equal to the rank of `M' / R'`. As a special case, taking `R = R'` it is `LinearMap.lift_rank_le_of_injective`. -/ theorem lift_rank_le_of_injective_injectiveₛ (i : R' → R) (j : M →+ M') (hi : Injective i) (hj : Injective j) (hc : ∀ (r : R') (m : M), j (i r • m) = r • j m) : lift.{v'} (Module.rank R M) ≀ lift.{v} (Module.rank R' M') := by simp_rw [Module.rank, lift_iSup (bddAbove_range _)] exact ciSup_mono' (bddAbove_range _) fun ⟹s, h⟩ ↩ ⟹⟹j '' s, LinearIndepOn.id_image (h.linearIndependent.map_of_injective_injectiveₛ i j hi hj hc)⟩, lift_mk_le'.mpr ⟹(Equiv.Set.image j s hj).toEmbedding⟩⟩ /-- If `M / R` and `M' / R'` are modules, `i : R → R'` is a surjective map, and `j : M →+ M'` is an injective monoid homomorphism, such that the scalar multiplications on `M` and `M'` are compatible, then the rank of `M / R` is smaller than or equal to the rank of `M' / R'`. As a special case, taking `R = R'` it is `LinearMap.lift_rank_le_of_injective`. -/ theorem lift_rank_le_of_surjective_injective (i : R → R') (j : M →+ M') (hi : Surjective i) (hj : Injective j) (hc : ∀ (r : R) (m : M), j (r • m) = i r • j m) : lift.{v'} (Module.rank R M) ≀ lift.{v} (Module.rank R' M') := by obtain ⟹i', hi'⟩ := hi.hasRightInverse refine lift_rank_le_of_injective_injectiveₛ i' j (fun _ _ h ↩ ?_) hj fun r m ↩ ?_ · apply_fun i at h rwa [hi', hi'] at h rw [hc (i' r) m, hi'] /-- If `M / R` and `M' / R'` are modules, `i : R → R'` is a bijective map which maps zero to zero, `j : M ≃+ M'` is a group isomorphism, such that the scalar multiplications on `M` and `M'` are compatible, then the rank of `M / R` is equal to the rank of `M' / R'`. As a special case, taking `R = R'` it is `LinearEquiv.lift_rank_eq`. -/ theorem lift_rank_eq_of_equiv_equiv (i : R → R') (j : M ≃+ M') (hi : Bijective i) (hc : ∀ (r : R) (m : M), j (r • m) = i r • j m) : lift.{v'} (Module.rank R M) = lift.{v} (Module.rank R' M') := (lift_rank_le_of_surjective_injective i j hi.2 j.injective hc).antisymm <| lift_rank_le_of_injective_injectiveₛ i j.symm hi.1 j.symm.injective fun _ _ ↩ j.symm_apply_eq.2 <| by erw [hc, j.apply_symm_apply] end section variable [AddCommMonoid M₁] [Module R' M₁] /-- The same-universe version of `lift_rank_le_of_injective_injective`. -/ theorem rank_le_of_injective_injectiveₛ (i : R' → R) (j : M →+ M₁) (hi : Injective i) (hj : Injective j) (hc : ∀ (r : R') (m : M), j (i r • m) = r • j m) : Module.rank R M ≀ Module.rank R' M₁ := by simpa only [lift_id] using lift_rank_le_of_injective_injectiveₛ i j hi hj hc /-- The same-universe version of `lift_rank_le_of_surjective_injective`. -/ theorem rank_le_of_surjective_injective (i : R → R') (j : M →+ M₁) (hi : Surjective i) (hj : Injective j) (hc : ∀ (r : R) (m : M), j (r • m) = i r • j m) : Module.rank R M ≀ Module.rank R' M₁ := by simpa only [lift_id] using lift_rank_le_of_surjective_injective i j hi hj hc /-- The same-universe version of `lift_rank_eq_of_equiv_equiv`. -/ theorem rank_eq_of_equiv_equiv (i : R → R') (j : M ≃+ M₁) (hi : Bijective i) (hc : ∀ (r : R) (m : M), j (r • m) = i r • j m) : Module.rank R M = Module.rank R' M₁ := by simpa only [lift_id] using lift_rank_eq_of_equiv_equiv i j hi hc end end Semiring section Ring variable [Ring R] [AddCommGroup M] [Module R M] [Ring R'] /-- If `M / R` and `M' / R'` are modules, `i : R' → R` is a map which sends non-zero elements to non-zero elements, `j : M →+ M'` is an injective group homomorphism, such that the scalar multiplications on `M` and `M'` are compatible, then the rank of `M / R` is smaller than or equal to the rank of `M' / R'`. As a special case, taking `R = R'` it is `LinearMap.lift_rank_le_of_injective`. -/ theorem lift_rank_le_of_injective_injective [AddCommGroup M'] [Module R' M'] (i : R' → R) (j : M →+ M') (hi : ∀ r, i r = 0 → r = 0) (hj : Injective j) (hc : ∀ (r : R') (m : M), j (i r • m) = r • j m) : lift.{v'} (Module.rank R M) ≀ lift.{v} (Module.rank R' M') := by simp_rw [Module.rank, lift_iSup (bddAbove_range _)] exact ciSup_mono' (bddAbove_range _) fun ⟹s, h⟩ ↩ ⟹⟹j '' s, LinearIndepOn.id_image <| h.linearIndependent.map_of_injective_injective i j hi (fun _ _ ↩ hj <| by rwa [j.map_zero]) hc⟩, lift_mk_le'.mpr ⟹(Equiv.Set.image j s hj).toEmbedding⟩⟩ /-- The same-universe version of `lift_rank_le_of_injective_injective`. -/ theorem rank_le_of_injective_injective [AddCommGroup M₁] [Module R' M₁] (i : R' → R) (j : M →+ M₁) (hi : ∀ r, i r = 0 → r = 0) (hj : Injective j) (hc : ∀ (r : R') (m : M), j (i r • m) = r • j m) : Module.rank R M ≀ Module.rank R' M₁ := by simpa only [lift_id] using lift_rank_le_of_injective_injective i j hi hj hc end Ring namespace Algebra variable {R : Type w} {S : Type v} [CommSemiring R] [Semiring S] [Algebra R S] {R' : Type w'} {S' : Type v'} [CommSemiring R'] [Semiring S'] [Algebra R' S'] /-- If `S / R` and `S' / R'` are algebras, `i : R' →+* R` and `j : S →+* S'` are injective ring homomorphisms, such that `R' → R → S → S'` and `R' → S'` commute, then the rank of `S / R` is smaller than or equal to the rank of `S' / R'`. -/ theorem lift_rank_le_of_injective_injective (i : R' →+* R) (j : S →+* S') (hi : Injective i) (hj : Injective j) (hc : (j.comp (algebraMap R S)).comp i = algebraMap R' S') : lift.{v'} (Module.rank R S) ≀ lift.{v} (Module.rank R' S') := by refine _root_.lift_rank_le_of_injective_injectiveₛ i j hi hj fun r _ ↩ ?_ have := congr($hc r) simp only [RingHom.coe_comp, comp_apply] at this simp_rw [smul_def, AddMonoidHom.coe_coe, map_mul, this] /-- If `S / R` and `S' / R'` are algebras, `i : R →+* R'` is a surjective ring homomorphism, `j : S →+* S'` is an injective ring homomorphism, such that `R → R' → S'` and `R → S → S'` commute, then the rank of `S / R` is smaller than or equal to the rank of `S' / R'`. -/ theorem lift_rank_le_of_surjective_injective (i : R →+* R') (j : S →+* S') (hi : Surjective i) (hj : Injective j) (hc : (algebraMap R' S').comp i = j.comp (algebraMap R S)) : lift.{v'} (Module.rank R S) ≀ lift.{v} (Module.rank R' S') := by refine _root_.lift_rank_le_of_surjective_injective i j hi hj fun r _ ↩ ?_ have := congr($hc r) simp only [RingHom.coe_comp, comp_apply] at this simp only [smul_def, AddMonoidHom.coe_coe, map_mul, ZeroHom.coe_coe, this] /-- If `S / R` and `S' / R'` are algebras, `i : R ≃+* R'` and `j : S ≃+* S'` are
ring isomorphisms, such that `R → R' → S'` and `R → S → S'` commute, then the rank of `S / R` is equal to the rank of `S' / R'`. -/ theorem lift_rank_eq_of_equiv_equiv (i : R ≃+* R') (j : S ≃+* S') (hc : (algebraMap R' S').comp i.toRingHom = j.toRingHom.comp (algebraMap R S)) :
Mathlib/LinearAlgebra/Dimension/Basic.lean
235
238
/- Copyright (c) 2022 Chris Birkbeck. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Birkbeck, David Loeffler -/ import Mathlib.Algebra.Module.Submodule.Basic import Mathlib.Analysis.Complex.UpperHalfPlane.Topology import Mathlib.Order.Filter.ZeroAndBoundedAtFilter /-! # Bounded at infinity For complex valued functions on the upper half plane, this file defines the filter `UpperHalfPlane.atImInfty` required for defining when functions are bounded at infinity and zero at infinity. Both of which are relevant for defining modular forms. -/ open Complex Filter open scoped Topology UpperHalfPlane noncomputable section namespace UpperHalfPlane /-- Filter for approaching `i∞`. -/ def atImInfty := Filter.atTop.comap UpperHalfPlane.im theorem atImInfty_basis : atImInfty.HasBasis (fun _ => True) fun i : ℝ => im ⁻¹' Set.Ici i := Filter.HasBasis.comap UpperHalfPlane.im Filter.atTop_basis theorem atImInfty_mem (S : Set ℍ) : S ∈ atImInfty ↔ ∃ A : ℝ, ∀ z : ℍ, A ≀ im z → z ∈ S := by simp only [atImInfty_basis.mem_iff, true_and]; rfl /-- A function `f : ℍ → α` is bounded at infinity if it is bounded along `atImInfty`. -/ def IsBoundedAtImInfty {α : Type*} [Norm α] (f : ℍ → α) : Prop := BoundedAtFilter atImInfty f /-- A function `f : ℍ → α` is zero at infinity it is zero along `atImInfty`. -/ def IsZeroAtImInfty {α : Type*} [Zero α] [TopologicalSpace α] (f : ℍ → α) : Prop := ZeroAtFilter atImInfty f theorem zero_form_isBoundedAtImInfty {α : Type*} [NormedField α] : IsBoundedAtImInfty (0 : ℍ → α) := const_boundedAtFilter atImInfty (0 : α) /-- Module of functions that are zero at infinity. -/ def zeroAtImInftySubmodule (α : Type*) [NormedField α] : Submodule α (ℍ → α) := zeroAtFilterSubmodule _ atImInfty /-- Subalgebra of functions that are bounded at infinity. -/ def boundedAtImInftySubalgebra (α : Type*) [NormedField α] : Subalgebra α (ℍ → α) := boundedFilterSubalgebra _ atImInfty theorem isBoundedAtImInfty_iff {α : Type*} [Norm α] {f : ℍ → α} : IsBoundedAtImInfty f ↔ ∃ M A : ℝ, ∀ z : ℍ, A ≀ im z → ‖f z‖ ≀ M := by simp [IsBoundedAtImInfty, BoundedAtFilter, Asymptotics.isBigO_iff, Filter.Eventually, atImInfty_mem] theorem isZeroAtImInfty_iff {α : Type*} [SeminormedAddGroup α] {f : ℍ → α} : IsZeroAtImInfty f ↔ ∀ ε : ℝ, 0 < ε → ∃ A : ℝ, ∀ z : ℍ, A ≀ im z → ‖f z‖ ≀ ε := (atImInfty_basis.tendsto_iff Metric.nhds_basis_closedBall).trans <| by simp theorem IsZeroAtImInfty.isBoundedAtImInfty {α : Type*} [SeminormedAddGroup α] {f : ℍ → α} (hf : IsZeroAtImInfty f) : IsBoundedAtImInfty f := hf.boundedAtFilter lemma tendsto_comap_im_ofComplex : Tendsto ofComplex (comap Complex.im atTop) atImInfty := by
simp only [atImInfty, tendsto_comap_iff, Function.comp_def] refine tendsto_comap.congr' ?_ filter_upwards [preimage_mem_comap (Ioi_mem_atTop 0)] with z hz simp only [ofComplex_apply_of_im_pos hz, ← UpperHalfPlane.coe_im, coe_mk_subtype]
Mathlib/Analysis/Complex/UpperHalfPlane/FunctionsBoundedAtInfty.lean
71
74
/- Copyright (c) 2022 Eric Rodriguez. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Rodriguez, Eric Wieser -/ import Mathlib.Data.List.Chain /-! # Destuttering of Lists This file proves theorems about `List.destutter` (in `Data.List.Defs`), which greedily removes all non-related items that are adjacent in a list, e.g. `[2, 2, 3, 3, 2].destutter (≠) = [2, 3, 2]`. Note that we make no guarantees of being the longest sublist with this property; e.g., `[123, 1, 2, 5, 543, 1000].destutter (<) = [123, 543, 1000]`, but a longer ascending chain could be `[1, 2, 5, 543, 1000]`. ## Main statements * `List.destutter_sublist`: `l.destutter` is a sublist of `l`. * `List.destutter_is_chain'`: `l.destutter` satisfies `Chain' R`. * Analogies of these theorems for `List.destutter'`, which is the `destutter` equivalent of `Chain`. ## Tags adjacent, chain, duplicates, remove, list, stutter, destutter -/ open Function variable {α β : Type*} (l l₁ l₂ : List α) (R : α → α → Prop) [DecidableRel R] {a b : α} variable {R₂ : β → β → Prop} [DecidableRel R₂] namespace List @[simp] theorem destutter'_nil : destutter' R a [] = [a] := rfl theorem destutter'_cons : (b :: l).destutter' R a = if R a b then a :: destutter' R b l else destutter' R a l := rfl variable {R} @[simp] theorem destutter'_cons_pos (h : R b a) : (a :: l).destutter' R b = b :: l.destutter' R a := by rw [destutter', if_pos h] @[simp] theorem destutter'_cons_neg (h : ¬R b a) : (a :: l).destutter' R b = l.destutter' R b := by rw [destutter', if_neg h] variable (R) @[simp] theorem destutter'_singleton : [b].destutter' R a = if R a b then [a, b] else [a] := by split_ifs with h <;> simp! [h] theorem destutter'_sublist (a) : l.destutter' R a <+ a :: l := by induction' l with b l hl generalizing a · simp rw [destutter'] split_ifs · exact Sublist.cons₂ a (hl b) · exact (hl a).trans ((l.sublist_cons_self b).cons_cons a) theorem mem_destutter' (a) : a ∈ l.destutter' R a := by induction' l with b l hl · simp rw [destutter'] split_ifs · simp · assumption theorem destutter'_is_chain : ∀ l : List α, ∀ {a b}, R a b → (l.destutter' R b).Chain R a | [], _, _, h => chain_singleton.mpr h | c :: l, a, b, h => by rw [destutter'] split_ifs with hbc · rw [chain_cons] exact ⟹h, destutter'_is_chain l hbc⟩ · exact destutter'_is_chain l h theorem destutter'_is_chain' (a) : (l.destutter' R a).Chain' R := by induction' l with b l hl generalizing a · simp rw [destutter'] split_ifs with h · exact destutter'_is_chain R l h · exact hl a theorem destutter'_of_chain (h : l.Chain R a) : l.destutter' R a = a :: l := by induction' l with b l hb generalizing a · simp obtain ⟹h, hc⟩ := chain_cons.mp h rw [l.destutter'_cons_pos h, hb hc] @[simp] theorem destutter'_eq_self_iff (a) : l.destutter' R a = a :: l ↔ l.Chain R a :=
⟹fun h => by suffices Chain' R (a::l) by assumption rw [← h] exact l.destutter'_is_chain' R a, destutter'_of_chain _ _⟩
Mathlib/Data/List/Destutter.lean
101
105
/- Copyright (c) 2018 Jan-David Salchow. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jan-David Salchow, Patrick Massot, Yury Kudryashov -/ import Mathlib.Topology.Defs.Sequences import Mathlib.Topology.UniformSpace.Cauchy /-! # Sequences in topological spaces In this file we prove theorems about relations between closure/compactness/continuity etc and their sequential counterparts. ## Main definitions The following notions are defined in `Topology/Defs/Sequences`. We build theory about these definitions here, so we remind the definitions. ### Set operation * `seqClosure s`: sequential closure of a set, the set of limits of sequences of points of `s`; ### Predicates * `IsSeqClosed s`: predicate saying that a set is sequentially closed, i.e., `seqClosure s ⊆ s`; * `SeqContinuous f`: predicate saying that a function is sequentially continuous, i.e., for any sequence `u : ℕ → X` that converges to a point `x`, the sequence `f ∘ u` converges to `f x`; * `IsSeqCompact s`: predicate saying that a set is sequentially compact, i.e., every sequence taking values in `s` has a converging subsequence. ### Type classes * `FrechetUrysohnSpace X`: a typeclass saying that a topological space is a *Fréchet-Urysohn space*, i.e., the sequential closure of any set is equal to its closure. * `SequentialSpace X`: a typeclass saying that a topological space is a *sequential space*, i.e., any sequentially closed set in this space is closed. This condition is weaker than being a Fréchet-Urysohn space. * `SeqCompactSpace X`: a typeclass saying that a topological space is sequentially compact, i.e., every sequence in `X` has a converging subsequence. ## Main results * `seqClosure_subset_closure`: closure of a set includes its sequential closure; * `IsClosed.isSeqClosed`: a closed set is sequentially closed; * `IsSeqClosed.seqClosure_eq`: sequential closure of a sequentially closed set `s` is equal to `s`; * `seqClosure_eq_closure`: in a Fréchet-Urysohn space, the sequential closure of a set is equal to its closure; * `tendsto_nhds_iff_seq_tendsto`, `FrechetUrysohnSpace.of_seq_tendsto_imp_tendsto`: a topological space is a Fréchet-Urysohn space if and only if sequential convergence implies convergence; * `FirstCountableTopology.frechetUrysohnSpace`: every topological space with first countable topology is a Fréchet-Urysohn space; * `FrechetUrysohnSpace.to_sequentialSpace`: every Fréchet-Urysohn space is a sequential space; * `IsSeqCompact.isCompact`: a sequentially compact set in a uniform space with countably generated uniformity is compact. ## Tags sequentially closed, sequentially compact, sequential space -/ open Bornology Filter Function Set TopologicalSpace Topology open scoped Uniformity variable {X Y : Type*} /-! ### Sequential closures, sequential continuity, and sequential spaces. -/ section TopologicalSpace variable [TopologicalSpace X] [TopologicalSpace Y] theorem subset_seqClosure {s : Set X} : s ⊆ seqClosure s := fun p hp => ⟹const ℕ p, fun _ => hp, tendsto_const_nhds⟩ /-- The sequential closure of a set is contained in the closure of that set. The converse is not true. -/ theorem seqClosure_subset_closure {s : Set X} : seqClosure s ⊆ closure s := fun _p ⟹_x, xM, xp⟩ => mem_closure_of_tendsto xp (univ_mem' xM) /-- The sequential closure of a sequentially closed set is the set itself. -/ theorem IsSeqClosed.seqClosure_eq {s : Set X} (hs : IsSeqClosed s) : seqClosure s = s := Subset.antisymm (fun _p ⟹_x, hx, hp⟩ => hs hx hp) subset_seqClosure /-- If a set is equal to its sequential closure, then it is sequentially closed. -/ theorem isSeqClosed_of_seqClosure_eq {s : Set X} (hs : seqClosure s = s) : IsSeqClosed s := fun x _p hxs hxp => hs ▾ ⟹x, hxs, hxp⟩ /-- A set is sequentially closed iff it is equal to its sequential closure. -/ theorem isSeqClosed_iff {s : Set X} : IsSeqClosed s ↔ seqClosure s = s := ⟹IsSeqClosed.seqClosure_eq, isSeqClosed_of_seqClosure_eq⟩ /-- A set is sequentially closed if it is closed. -/ protected theorem IsClosed.isSeqClosed {s : Set X} (hc : IsClosed s) : IsSeqClosed s := fun _u _x hu hx => hc.mem_of_tendsto hx (Eventually.of_forall hu) theorem seqClosure_eq_closure [FrechetUrysohnSpace X] (s : Set X) : seqClosure s = closure s := seqClosure_subset_closure.antisymm <| FrechetUrysohnSpace.closure_subset_seqClosure s /-- In a Fréchet-Urysohn space, a point belongs to the closure of a set iff it is a limit of a sequence taking values in this set. -/ theorem mem_closure_iff_seq_limit [FrechetUrysohnSpace X] {s : Set X} {a : X} : a ∈ closure s ↔ ∃ x : ℕ → X, (∀ n : ℕ, x n ∈ s) ∧ Tendsto x atTop (𝓝 a) := by rw [← seqClosure_eq_closure] rfl /-- If the domain of a function `f : α → β` is a Fréchet-Urysohn space, then convergence is equivalent to sequential convergence. See also `Filter.tendsto_iff_seq_tendsto` for a version that works for any pair of filters assuming that the filter in the domain is countably generated. This property is equivalent to the definition of `FrechetUrysohnSpace`, see `FrechetUrysohnSpace.of_seq_tendsto_imp_tendsto`. -/ theorem tendsto_nhds_iff_seq_tendsto [FrechetUrysohnSpace X] {f : X → Y} {a : X} {b : Y} : Tendsto f (𝓝 a) (𝓝 b) ↔ ∀ u : ℕ → X, Tendsto u atTop (𝓝 a) → Tendsto (f ∘ u) atTop (𝓝 b) := by refine ⟹fun hf u hu => hf.comp hu, fun h => ((nhds_basis_closeds _).tendsto_iff (nhds_basis_closeds _)).2 ?_⟩ rintro s ⟹hbs, hsc⟩ refine ⟹closure (f ⁻¹' s), ⟹mt ?_ hbs, isClosed_closure⟩, fun x => mt fun hx => subset_closure hx⟩ rw [← seqClosure_eq_closure] rintro ⟹u, hus, hu⟩ exact hsc.mem_of_tendsto (h u hu) (Eventually.of_forall hus) /-- An alternative construction for `FrechetUrysohnSpace`: if sequential convergence implies convergence, then the space is a Fréchet-Urysohn space. -/ theorem FrechetUrysohnSpace.of_seq_tendsto_imp_tendsto (h : ∀ (f : X → Prop) (a : X), (∀ u : ℕ → X, Tendsto u atTop (𝓝 a) → Tendsto (f ∘ u) atTop (𝓝 (f a))) → ContinuousAt f a) : FrechetUrysohnSpace X := by refine ⟹fun s x hcx => ?_⟩ by_cases hx : x ∈ s · exact subset_seqClosure hx · obtain ⟹u, hux, hus⟩ : ∃ u : ℕ → X, Tendsto u atTop (𝓝 x) ∧ ∃ᶠ x in atTop, u x ∈ s := by simpa only [ContinuousAt, hx, tendsto_nhds_true, (· ∘ ·), ← not_frequently, exists_prop, ← mem_closure_iff_frequently, hcx, imp_false, not_forall, not_not, not_false_eq_true, not_true_eq_false] using h (· ∉ s) x
rcases extraction_of_frequently_atTop hus with ⟚φ, φ_mono, hφ⟩ exact ⟹u ∘ φ, hφ, hux.comp φ_mono.tendsto_atTop⟩ -- see Note [lower instance priority] /-- Every first-countable space is a Fréchet-Urysohn space. -/ instance (priority := 100) FirstCountableTopology.frechetUrysohnSpace [FirstCountableTopology X] : FrechetUrysohnSpace X := FrechetUrysohnSpace.of_seq_tendsto_imp_tendsto fun _ _ => tendsto_iff_seq_tendsto.2 -- see Note [lower instance priority] /-- Every Fréchet-Urysohn space is a sequential space. -/ instance (priority := 100) FrechetUrysohnSpace.to_sequentialSpace [FrechetUrysohnSpace X] : SequentialSpace X :=
Mathlib/Topology/Sequences.lean
139
151
/- Copyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import Mathlib.Algebra.Order.Group.Unbundled.Int import Mathlib.Algebra.Order.Nonneg.Basic import Mathlib.Algebra.Order.Ring.Unbundled.Rat import Mathlib.Algebra.Ring.Rat import Mathlib.Data.Set.Operations import Mathlib.Order.Bounds.Defs import Mathlib.Order.GaloisConnection.Defs /-! # Nonnegative rationals This file defines the nonnegative rationals as a subtype of `Rat` and provides its basic algebraic order structure. Note that `NNRat` is not declared as a `Semifield` here. See `Mathlib.Algebra.Field.Rat` for that instance. We also define an instance `CanLift ℚ ℚ≥0`. This instance can be used by the `lift` tactic to replace `x : ℚ` and `hx : 0 ≀ x` in the proof context with `x : ℚ≥0` while replacing all occurrences of `x` with `↑x`. This tactic also works for a function `f : α → ℚ` with a hypothesis `hf : ∀ x, 0 ≀ f x`. ## Notation `ℚ≥0` is notation for `NNRat` in locale `NNRat`. ## Huge warning Whenever you state a lemma about the coercion `ℚ≥0 → ℚ`, check that Lean inserts `NNRat.cast`, not `Subtype.val`. Else your lemma will never apply. -/ assert_not_exists CompleteLattice OrderedCommMonoid library_note "specialised high priority simp lemma" /-- It sometimes happens that a `@[simp]` lemma declared early in the library can be proved by `simp` using later, more general simp lemmas. In that case, the following reasons might be arguments for the early lemma to be tagged `@[simp high]` (rather than `@[simp, nolint simpNF]` or un``@[simp]``ed): 1. There is a significant portion of the library which needs the early lemma to be available via `simp` and which doesn't have access to the more general lemmas. 2. The more general lemmas have more complicated typeclass assumptions, causing rewrites with them to be slower. -/ open Function instance Rat.instZeroLEOneClass : ZeroLEOneClass ℚ where zero_le_one := rfl instance Rat.instPosMulMono : PosMulMono ℚ where elim := fun r p q h => by simp only [mul_comm] simpa [sub_mul, sub_nonneg] using Rat.mul_nonneg (sub_nonneg.2 h) r.2 deriving instance CommSemiring for NNRat deriving instance LinearOrder for NNRat deriving instance Sub for NNRat deriving instance Inhabited for NNRat namespace NNRat variable {p q : ℚ≥0} instance instNontrivial : Nontrivial ℚ≥0 where exists_pair_ne := ⟹1, 0, by decide⟩ instance instOrderBot : OrderBot ℚ≥0 where bot := 0 bot_le q := q.2 @[simp] lemma val_eq_cast (q : ℚ≥0) : q.1 = q := rfl instance instCharZero : CharZero ℚ≥0 where cast_injective a b hab := by simpa using congr_arg num hab instance canLift : CanLift ℚ ℚ≥0 (↑) fun q ↩ 0 ≀ q where prf q hq := ⟹⟹q, hq⟩, rfl⟩ @[ext] theorem ext : (p : ℚ) = (q : ℚ) → p = q := Subtype.ext protected theorem coe_injective : Injective ((↑) : ℚ≥0 → ℚ) := Subtype.coe_injective -- See note [specialised high priority simp lemma] @[simp high, norm_cast] theorem coe_inj : (p : ℚ) = q ↔ p = q := Subtype.coe_inj theorem ne_iff {x y : ℚ≥0} : (x : ℚ) ≠ (y : ℚ) ↔ x ≠ y := NNRat.coe_inj.not -- TODO: We have to write `NNRat.cast` explicitly, else the statement picks up `Subtype.val` instead @[simp, norm_cast] lemma coe_mk (q : ℚ) (hq) : NNRat.cast ⟹q, hq⟩ = q := rfl lemma «forall» {p : ℚ≥0 → Prop} : (∀ q, p q) ↔ ∀ q hq, p ⟹q, hq⟩ := Subtype.forall lemma «exists» {p : ℚ≥0 → Prop} : (∃ q, p q) ↔ ∃ q hq, p ⟹q, hq⟩ := Subtype.exists /-- Reinterpret a rational number `q` as a non-negative rational number. Returns `0` if `q ≀ 0`. -/ def _root_.Rat.toNNRat (q : ℚ) : ℚ≥0 := ⟹max q 0, le_max_right _ _⟩ theorem _root_.Rat.coe_toNNRat (q : ℚ) (hq : 0 ≀ q) : (q.toNNRat : ℚ) = q := max_eq_left hq theorem _root_.Rat.le_coe_toNNRat (q : ℚ) : q ≀ q.toNNRat := le_max_left _ _ open Rat (toNNRat) @[simp] theorem coe_nonneg (q : ℚ≥0) : (0 : ℚ) ≀ q := q.2 @[simp, norm_cast] lemma coe_zero : ((0 : ℚ≥0) : ℚ) = 0 := rfl @[simp] lemma num_zero : num 0 = 0 := rfl @[simp] lemma den_zero : den 0 = 1 := rfl @[simp, norm_cast] lemma coe_one : ((1 : ℚ≥0) : ℚ) = 1 := rfl @[simp] lemma num_one : num 1 = 1 := rfl @[simp] lemma den_one : den 1 = 1 := rfl @[simp, norm_cast] theorem coe_add (p q : ℚ≥0) : ((p + q : ℚ≥0) : ℚ) = p + q := rfl @[simp, norm_cast] theorem coe_mul (p q : ℚ≥0) : ((p * q : ℚ≥0) : ℚ) = p * q := rfl @[simp, norm_cast] lemma coe_pow (q : ℚ≥0) (n : ℕ) : (↑(q ^ n) : ℚ) = (q : ℚ) ^ n := rfl @[simp] lemma num_pow (q : ℚ≥0) (n : ℕ) : (q ^ n).num = q.num ^ n := by simp [num, Int.natAbs_pow] @[simp] lemma den_pow (q : ℚ≥0) (n : ℕ) : (q ^ n).den = q.den ^ n := rfl @[simp, norm_cast] theorem coe_sub (h : q ≀ p) : ((p - q : ℚ≥0) : ℚ) = p - q := max_eq_left <| le_sub_comm.2 <| by rwa [sub_zero] -- See note [specialised high priority simp lemma] @[simp high] theorem coe_eq_zero : (q : ℚ) = 0 ↔ q = 0 := by norm_cast theorem coe_ne_zero : (q : ℚ) ≠ 0 ↔ q ≠ 0 := coe_eq_zero.not @[norm_cast] theorem coe_le_coe : (p : ℚ) ≀ q ↔ p ≀ q := Iff.rfl @[norm_cast] theorem coe_lt_coe : (p : ℚ) < q ↔ p < q := Iff.rfl @[norm_cast] theorem coe_pos : (0 : ℚ) < q ↔ 0 < q := Iff.rfl theorem coe_mono : Monotone ((↑) : ℚ≥0 → ℚ) := fun _ _ ↩ coe_le_coe.2 theorem toNNRat_mono : Monotone toNNRat := fun _ _ h ↩ max_le_max h le_rfl @[simp] theorem toNNRat_coe (q : ℚ≥0) : toNNRat q = q := ext <| max_eq_left q.2 @[simp] theorem toNNRat_coe_nat (n : ℕ) : toNNRat n = n := ext <| by simp only [Nat.cast_nonneg', Rat.coe_toNNRat]; rfl /-- `toNNRat` and `(↑) : ℚ≥0 → ℚ` form a Galois insertion. -/ protected def gi : GaloisInsertion toNNRat (↑) := GaloisInsertion.monotoneIntro coe_mono toNNRat_mono Rat.le_coe_toNNRat toNNRat_coe /-- Coercion `ℚ≥0 → ℚ` as a `RingHom`. -/ def coeHom : ℚ≥0 →+* ℚ where toFun := (↑) map_one' := coe_one map_mul' := coe_mul map_zero' := coe_zero map_add' := coe_add @[simp, norm_cast] lemma coe_natCast (n : ℕ) : (↑(↑n : ℚ≥0) : ℚ) = n := rfl @[simp] theorem mk_natCast (n : ℕ) : @Eq ℚ≥0 (⟹(n : ℚ), Nat.cast_nonneg' n⟩ : ℚ≥0) n := rfl @[simp] theorem coe_coeHom : ⇑coeHom = ((↑) : ℚ≥0 → ℚ) := rfl @[norm_cast] theorem nsmul_coe (q : ℚ≥0) (n : ℕ) : ↑(n • q) = n • (q : ℚ) := coeHom.toAddMonoidHom.map_nsmul _ _ theorem bddAbove_coe {s : Set ℚ≥0} : BddAbove ((↑) '' s : Set ℚ) ↔ BddAbove s := ⟹fun ⟹b, hb⟩ ↩ ⟹toNNRat b, fun ⟹y, _⟩ hys ↩ show y ≀ max b 0 from (hb <| Set.mem_image_of_mem _ hys).trans <| le_max_left _ _⟩, fun ⟹b, hb⟩ ↩ ⟹b, fun _ ⟹_, hx, Eq⟩ ↩ Eq ▾ hb hx⟩⟩ theorem bddBelow_coe (s : Set ℚ≥0) : BddBelow (((↑) : ℚ≥0 → ℚ) '' s) := ⟹0, fun _ ⟹q, _, h⟩ ↩ h ▾ q.2⟩ @[norm_cast] theorem coe_max (x y : ℚ≥0) : ((max x y : ℚ≥0) : ℚ) = max (x : ℚ) (y : ℚ) := coe_mono.map_max @[norm_cast] theorem coe_min (x y : ℚ≥0) : ((min x y : ℚ≥0) : ℚ) = min (x : ℚ) (y : ℚ) := coe_mono.map_min theorem sub_def (p q : ℚ≥0) : p - q = toNNRat (p - q) := rfl @[simp] theorem abs_coe (q : ℚ≥0) : |(q : ℚ)| = q := abs_of_nonneg q.2 -- See note [specialised high priority simp lemma] @[simp high] theorem nonpos_iff_eq_zero (q : ℚ≥0) : q ≀ 0 ↔ q = 0 := ⟹fun h => le_antisymm h q.2, fun h => h.symm ▾ q.2⟩ end NNRat open NNRat namespace Rat variable {p q : ℚ} @[simp] theorem toNNRat_zero : toNNRat 0 = 0 := rfl @[simp] theorem toNNRat_one : toNNRat 1 = 1 := rfl @[simp] theorem toNNRat_pos : 0 < toNNRat q ↔ 0 < q := by simp [toNNRat, ← coe_lt_coe] @[simp] theorem toNNRat_eq_zero : toNNRat q = 0 ↔ q ≀ 0 := by simpa [-toNNRat_pos] using (@toNNRat_pos q).not alias ⟹_, toNNRat_of_nonpos⟩ := toNNRat_eq_zero @[simp] theorem toNNRat_le_toNNRat_iff (hp : 0 ≀ p) : toNNRat q ≀ toNNRat p ↔ q ≀ p := by simp [← coe_le_coe, toNNRat, hp] @[simp] theorem toNNRat_lt_toNNRat_iff' : toNNRat q < toNNRat p ↔ q < p ∧ 0 < p := by simp [← coe_lt_coe, toNNRat, lt_irrefl] theorem toNNRat_lt_toNNRat_iff (h : 0 < p) : toNNRat q < toNNRat p ↔ q < p := toNNRat_lt_toNNRat_iff'.trans (and_iff_left h) theorem toNNRat_lt_toNNRat_iff_of_nonneg (hq : 0 ≀ q) : toNNRat q < toNNRat p ↔ q < p := toNNRat_lt_toNNRat_iff'.trans ⟹And.left, fun h ↩ ⟹h, hq.trans_lt h⟩⟩ @[simp] theorem toNNRat_add (hq : 0 ≀ q) (hp : 0 ≀ p) : toNNRat (q + p) = toNNRat q + toNNRat p := NNRat.ext <| by simp [toNNRat, hq, hp, add_nonneg] theorem toNNRat_add_le : toNNRat (q + p) ≀ toNNRat q + toNNRat p := coe_le_coe.1 <| max_le (add_le_add (le_max_left _ _) (le_max_left _ _)) <| coe_nonneg _ theorem toNNRat_le_iff_le_coe {p : ℚ≥0} : toNNRat q ≀ p ↔ q ≀ ↑p := NNRat.gi.gc q p theorem le_toNNRat_iff_coe_le {q : ℚ≥0} (hp : 0 ≀ p) : q ≀ toNNRat p ↔ ↑q ≀ p := by rw [← coe_le_coe, Rat.coe_toNNRat p hp] theorem le_toNNRat_iff_coe_le' {q : ℚ≥0} (hq : 0 < q) : q ≀ toNNRat p ↔ ↑q ≀ p := (le_or_lt 0 p).elim le_toNNRat_iff_coe_le fun hp ↩ by simp only [(hp.trans_le q.coe_nonneg).not_le, toNNRat_eq_zero.2 hp.le, hq.not_le] theorem toNNRat_lt_iff_lt_coe {p : ℚ≥0} (hq : 0 ≀ q) : toNNRat q < p ↔ q < ↑p := by rw [← coe_lt_coe, Rat.coe_toNNRat q hq] theorem lt_toNNRat_iff_coe_lt {q : ℚ≥0} : q < toNNRat p ↔ ↑q < p := NNRat.gi.gc.lt_iff_lt theorem toNNRat_mul (hp : 0 ≀ p) : toNNRat (p * q) = toNNRat p * toNNRat q := by rcases le_total 0 q with hq | hq · ext; simp [toNNRat, hp, hq, max_eq_left, mul_nonneg] · have hpq := mul_nonpos_of_nonneg_of_nonpos hp hq rw [toNNRat_eq_zero.2 hq, toNNRat_eq_zero.2 hpq, mul_zero] end Rat /-- The absolute value on `ℚ` as a map to `ℚ≥0`. -/ @[pp_nodot] def Rat.nnabs (x : ℚ) : ℚ≥0 := ⟹abs x, abs_nonneg x⟩ @[norm_cast, simp] theorem Rat.coe_nnabs (x : ℚ) : (Rat.nnabs x : ℚ) = abs x := rfl /-! ### Numerator and denominator -/ namespace NNRat variable {p q : ℚ≥0} @[norm_cast] lemma num_coe (q : ℚ≥0) : (q : ℚ).num = q.num := by simp only [num, Int.natCast_natAbs, Rat.num_nonneg, coe_nonneg, abs_of_nonneg] theorem natAbs_num_coe : (q : ℚ).num.natAbs = q.num := rfl @[norm_cast] lemma den_coe : (q : ℚ).den = q.den := rfl @[simp] lemma num_ne_zero : q.num ≠ 0 ↔ q ≠ 0 := by simp [num] @[simp] lemma num_pos : 0 < q.num ↔ 0 < q := by simpa [num, -nonpos_iff_eq_zero] using nonpos_iff_eq_zero _ |>.not.symm @[simp] lemma den_pos (q : ℚ≥0) : 0 < q.den := Rat.den_pos _ @[simp] lemma den_ne_zero (q : ℚ≥0) : q.den ≠ 0 := Rat.den_ne_zero _ lemma coprime_num_den (q : ℚ≥0) : q.num.Coprime q.den := by simpa [num, den] using Rat.reduced _ -- TODO: Rename `Rat.coe_nat_num`, `Rat.intCast_den`, `Rat.ofNat_num`, `Rat.ofNat_den` @[simp, norm_cast] lemma num_natCast (n : ℕ) : num n = n := rfl @[simp, norm_cast] lemma den_natCast (n : ℕ) : den n = 1 := rfl @[simp] lemma num_ofNat (n : ℕ) [n.AtLeastTwo] : num ofNat(n) = OfNat.ofNat n := rfl @[simp] lemma den_ofNat (n : ℕ) [n.AtLeastTwo] : den ofNat(n) = 1 := rfl theorem ext_num_den (hn : p.num = q.num) (hd : p.den = q.den) : p = q := by refine ext <| Rat.ext ?_ hd simpa [num_coe] theorem ext_num_den_iff : p = q ↔ p.num = q.num ∧ p.den = q.den := ⟹by rintro rfl; exact ⟹rfl, rfl⟩, fun h ↩ ext_num_den h.1 h.2⟩ /-- Form the quotient `n / d` where `n d : ℕ`. See also `Rat.divInt` and `mkRat`. -/ def divNat (n d : ℕ) : ℚ≥0 := ⟹.divInt n d, Rat.divInt_nonneg (Int.ofNat_zero_le n) (Int.ofNat_zero_le d)⟩ variable {n₁ n₂ d₁ d₂ : ℕ} @[simp, norm_cast] lemma coe_divNat (n d : ℕ) : (divNat n d : ℚ) = .divInt n d := rfl lemma mk_divInt (n d : ℕ) : ⟹.divInt n d, Rat.divInt_nonneg (Int.ofNat_zero_le n) (Int.ofNat_zero_le d)⟩ = divNat n d := rfl lemma divNat_inj (h₁ : d₁ ≠ 0) (h₂ : d₂ ≠ 0) : divNat n₁ d₁ = divNat n₂ d₂ ↔ n₁ * d₂ = n₂ * d₁ := by rw [← coe_inj]; simp [Rat.mkRat_eq_iff, h₁, h₂]; norm_cast @[simp] lemma divNat_zero (n : ℕ) : divNat n 0 = 0 := by simp [divNat]; rfl @[simp] lemma num_divNat_den (q : ℚ≥0) : divNat q.num q.den = q := ext <| by rw [← (q : ℚ).mkRat_num_den']; simp [num_coe, den_coe] lemma natCast_eq_divNat (n : ℕ) : (n : ℚ≥0) = divNat n 1 := (num_divNat_den _).symm lemma divNat_mul_divNat (n₁ n₂ : ℕ) {d₁ d₂} (hd₁ : d₁ ≠ 0) (hd₂ : d₂ ≠ 0) : divNat n₁ d₁ * divNat n₂ d₂ = divNat (n₁ * n₂) (d₁ * d₂) := by ext; push_cast; exact Rat.divInt_mul_divInt _ _ (mod_cast hd₁) (mod_cast hd₂) lemma divNat_mul_left {a : ℕ} (ha : a ≠ 0) (n d : ℕ) : divNat (a * n) (a * d) = divNat n d := by ext; push_cast; exact Rat.divInt_mul_left (mod_cast ha) lemma divNat_mul_right {a : ℕ} (ha : a ≠ 0) (n d : ℕ) : divNat (n * a) (d * a) = divNat n d := by ext; push_cast; exact Rat.divInt_mul_right (mod_cast ha) @[simp] lemma mul_den_eq_num (q : ℚ≥0) : q * q.den = q.num := by ext push_cast rw [← Int.cast_natCast, ← den_coe, ← Int.cast_natCast q.num, ← num_coe] exact Rat.mul_den_eq_num _ @[simp] lemma den_mul_eq_num (q : ℚ≥0) : q.den * q = q.num := by rw [mul_comm, mul_den_eq_num] /-- Define a (dependent) function or prove `∀ r : ℚ, p r` by dealing with nonnegative rational numbers of the form `n / d` with `d ≠ 0` and `n`, `d` coprime. -/ @[elab_as_elim] def numDenCasesOn.{u} {C : ℚ≥0 → Sort u} (q) (H : ∀ n d, d ≠ 0 → n.Coprime d → C (divNat n d)) : C q := by rw [← q.num_divNat_den]; exact H _ _ q.den_ne_zero q.coprime_num_den lemma add_def (q r : ℚ≥0) : q + r = divNat (q.num * r.den + r.num * q.den) (q.den * r.den) := by ext; simp [Rat.add_def', Rat.mkRat_eq_divInt, num_coe, den_coe] lemma mul_def (q r : ℚ≥0) : q * r = divNat (q.num * r.num) (q.den * r.den) := by ext; simp [Rat.mul_eq_mkRat, Rat.mkRat_eq_divInt, num_coe, den_coe] theorem lt_def {p q : ℚ≥0} : p < q ↔ p.num * q.den < q.num * p.den := by rw [← NNRat.coe_lt_coe, Rat.lt_def]; norm_cast theorem le_def {p q : ℚ≥0} : p ≀ q ↔ p.num * q.den ≀ q.num * p.den := by rw [← NNRat.coe_le_coe, Rat.le_def]; norm_cast
end NNRat
Mathlib/Data/NNRat/Defs.lean
406
407
/- Copyright (c) 2021 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying, Rémy Degenne -/ import Mathlib.MeasureTheory.Constructions.Cylinders import Mathlib.MeasureTheory.Function.ConditionalExpectation.Real import Mathlib.MeasureTheory.MeasurableSpace.PreorderRestrict /-! # Filtrations This file defines filtrations of a measurable space and σ-finite filtrations. ## Main definitions * `MeasureTheory.Filtration`: a filtration on a measurable space. That is, a monotone sequence of sub-σ-algebras. * `MeasureTheory.SigmaFiniteFiltration`: a filtration `f` is σ-finite with respect to a measure `ÎŒ` if for all `i`, `ÎŒ.trim (f.le i)` is σ-finite. * `MeasureTheory.Filtration.natural`: the smallest filtration that makes a process adapted. That notion `adapted` is not defined yet in this file. See `MeasureTheory.adapted`. ## Main results * `MeasureTheory.Filtration.instCompleteLattice`: filtrations are a complete lattice. ## Tags filtration, stochastic process -/ open Filter Order TopologicalSpace open scoped MeasureTheory NNReal ENNReal Topology namespace MeasureTheory /-- A `Filtration` on a measurable space `Ω` with σ-algebra `m` is a monotone sequence of sub-σ-algebras of `m`. -/ structure Filtration {Ω : Type*} (ι : Type*) [Preorder ι] (m : MeasurableSpace Ω) where /-- The sequence of sub-σ-algebras of `m` -/ seq : ι → MeasurableSpace Ω mono' : Monotone seq le' : ∀ i : ι, seq i ≀ m attribute [coe] Filtration.seq variable {Ω β ι : Type*} {m : MeasurableSpace Ω} instance [Preorder ι] : CoeFun (Filtration ι m) fun _ => ι → MeasurableSpace Ω := ⟹fun f => f.seq⟩ namespace Filtration variable [Preorder ι] protected theorem mono {i j : ι} (f : Filtration ι m) (hij : i ≀ j) : f i ≀ f j := f.mono' hij protected theorem le (f : Filtration ι m) (i : ι) : f i ≀ m := f.le' i @[ext] protected theorem ext {f g : Filtration ι m} (h : (f : ι → MeasurableSpace Ω) = g) : f = g := by cases f; cases g; congr variable (ι) in /-- The constant filtration which is equal to `m` for all `i : ι`. -/ def const (m' : MeasurableSpace Ω) (hm' : m' ≀ m) : Filtration ι m := ⟹fun _ => m', monotone_const, fun _ => hm'⟩ @[simp] theorem const_apply {m' : MeasurableSpace Ω} {hm' : m' ≀ m} (i : ι) : const ι m' hm' i = m' := rfl instance : Inhabited (Filtration ι m) := ⟹const ι m le_rfl⟩ instance : LE (Filtration ι m) := ⟹fun f g => ∀ i, f i ≀ g i⟩ instance : Bot (Filtration ι m) := ⟹const ι ⊥ bot_le⟩ instance : Top (Filtration ι m) := ⟹const ι m le_rfl⟩ instance : Max (Filtration ι m) := ⟹fun f g => { seq := fun i => f i ⊔ g i mono' := fun _ _ hij => sup_le ((f.mono hij).trans le_sup_left) ((g.mono hij).trans le_sup_right) le' := fun i => sup_le (f.le i) (g.le i) }⟩ @[norm_cast] theorem coeFn_sup {f g : Filtration ι m} : ⇑(f ⊔ g) = ⇑f ⊔ ⇑g := rfl instance : Min (Filtration ι m) := ⟹fun f g => { seq := fun i => f i ⊓ g i mono' := fun _ _ hij => le_inf (inf_le_left.trans (f.mono hij)) (inf_le_right.trans (g.mono hij)) le' := fun i => inf_le_left.trans (f.le i) }⟩ @[norm_cast] theorem coeFn_inf {f g : Filtration ι m} : ⇑(f ⊓ g) = ⇑f ⊓ ⇑g := rfl instance : SupSet (Filtration ι m) := ⟹fun s => { seq := fun i => sSup ((fun f : Filtration ι m => f i) '' s) mono' := fun i j hij => by refine sSup_le fun m' hm' => ?_ rw [Set.mem_image] at hm' obtain ⟹f, hf_mem, hfm'⟩ := hm' rw [← hfm'] refine (f.mono hij).trans ?_ have hfj_mem : f j ∈ (fun g : Filtration ι m => g j) '' s := ⟹f, hf_mem, rfl⟩ exact le_sSup hfj_mem le' := fun i => by refine sSup_le fun m' hm' => ?_ rw [Set.mem_image] at hm' obtain ⟹f, _, hfm'⟩ := hm' rw [← hfm'] exact f.le i }⟩ theorem sSup_def (s : Set (Filtration ι m)) (i : ι) : sSup s i = sSup ((fun f : Filtration ι m => f i) '' s) := rfl open scoped Classical in noncomputable instance : InfSet (Filtration ι m) := ⟹fun s => { seq := fun i => if Set.Nonempty s then sInf ((fun f : Filtration ι m => f i) '' s) else m mono' := fun i j hij => by by_cases h_nonempty : Set.Nonempty s swap; · simp only [h_nonempty, Set.image_nonempty, if_false, le_refl] simp only [h_nonempty, if_true, le_sInf_iff, Set.mem_image, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] refine fun f hf_mem => le_trans ?_ (f.mono hij) have hfi_mem : f i ∈ (fun g : Filtration ι m => g i) '' s := ⟹f, hf_mem, rfl⟩ exact sInf_le hfi_mem le' := fun i => by by_cases h_nonempty : Set.Nonempty s swap; · simp only [h_nonempty, if_false, le_refl] simp only [h_nonempty, if_true] obtain ⟹f, hf_mem⟩ := h_nonempty exact le_trans (sInf_le ⟹f, hf_mem, rfl⟩) (f.le i) }⟩ open scoped Classical in theorem sInf_def (s : Set (Filtration ι m)) (i : ι) : sInf s i = if Set.Nonempty s then sInf ((fun f : Filtration ι m => f i) '' s) else m := rfl noncomputable instance instCompleteLattice : CompleteLattice (Filtration ι m) where le := (· ≀ ·) le_refl _ _ := le_rfl le_trans _ _ _ h_fg h_gh i := (h_fg i).trans (h_gh i) le_antisymm _ _ h_fg h_gf := Filtration.ext <| funext fun i => (h_fg i).antisymm (h_gf i) sup := (· ⊔ ·) le_sup_left _ _ _ := le_sup_left le_sup_right _ _ _ := le_sup_right sup_le _ _ _ h_fh h_gh i := sup_le (h_fh i) (h_gh _) inf := (· ⊓ ·) inf_le_left _ _ _ := inf_le_left inf_le_right _ _ _ := inf_le_right le_inf _ _ _ h_fg h_fh i := le_inf (h_fg i) (h_fh i) sSup := sSup le_sSup _ f hf_mem _ := le_sSup ⟹f, hf_mem, rfl⟩ sSup_le s f h_forall i := sSup_le fun m' hm' => by obtain ⟹g, hg_mem, hfm'⟩ := hm' rw [← hfm'] exact h_forall g hg_mem i sInf := sInf sInf_le s f hf_mem i := by have hs : s.Nonempty := ⟹f, hf_mem⟩ simp only [sInf_def, hs, if_true] exact sInf_le ⟹f, hf_mem, rfl⟩ le_sInf s f h_forall i := by by_cases hs : s.Nonempty swap; · simp only [sInf_def, hs, if_false]; exact f.le i simp only [sInf_def, hs, if_true, le_sInf_iff, Set.mem_image, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] exact fun g hg_mem => h_forall g hg_mem i top := ⊀ bot := ⊥ le_top f i := f.le' i bot_le _ _ := bot_le end Filtration theorem measurableSet_of_filtration [Preorder ι] {f : Filtration ι m} {s : Set Ω} {i : ι} (hs : MeasurableSet[f i] s) : MeasurableSet[m] s := f.le i s hs /-- A measure is σ-finite with respect to filtration if it is σ-finite with respect to all the sub-σ-algebra of the filtration. -/ class SigmaFiniteFiltration [Preorder ι] (ÎŒ : Measure Ω) (f : Filtration ι m) : Prop where SigmaFinite : ∀ i : ι, SigmaFinite (ÎŒ.trim (f.le i)) instance sigmaFinite_of_sigmaFiniteFiltration [Preorder ι] (ÎŒ : Measure Ω) (f : Filtration ι m) [hf : SigmaFiniteFiltration ÎŒ f] (i : ι) : SigmaFinite (ÎŒ.trim (f.le i)) := hf.SigmaFinite _ instance (priority := 100) IsFiniteMeasure.sigmaFiniteFiltration [Preorder ι] (ÎŒ : Measure Ω) (f : Filtration ι m) [IsFiniteMeasure ÎŒ] : SigmaFiniteFiltration ÎŒ f := ⟹fun n => by infer_instance⟩ /-- Given an integrable function `g`, the conditional expectations of `g` with respect to a filtration is uniformly integrable. -/ theorem Integrable.uniformIntegrable_condExp_filtration [Preorder ι] {ÎŒ : Measure Ω} [IsFiniteMeasure ÎŒ] {f : Filtration ι m} {g : Ω → ℝ} (hg : Integrable g ÎŒ) : UniformIntegrable (fun i => ÎŒ[g|f i]) 1 ÎŒ := hg.uniformIntegrable_condExp f.le @[deprecated (since := "2025-01-21")] alias Integrable.uniformIntegrable_condexp_filtration := Integrable.uniformIntegrable_condExp_filtration theorem Filtration.condExp_condExp [Preorder ι] {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] (f : Ω → E) {ÎŒ : Measure Ω} (ℱ : Filtration ι m) {i j : ι} (hij : i ≀ j) [SigmaFinite (ÎŒ.trim (ℱ.le j))] : ÎŒ[ÎŒ[f|ℱ j]|ℱ i] =ᵐ[ÎŒ] ÎŒ[f|ℱ i] := condExp_condExp_of_le (ℱ.mono hij) (ℱ.le j) section OfSet variable [Preorder ι] /-- Given a sequence of measurable sets `(sₙ)`, `filtrationOfSet` is the smallest filtration such that `sₙ` is measurable with respect to the `n`-th sub-σ-algebra in `filtrationOfSet`. -/ def filtrationOfSet {s : ι → Set Ω} (hsm : ∀ i, MeasurableSet (s i)) : Filtration ι m where seq i := MeasurableSpace.generateFrom {t | ∃ j ≀ i, s j = t} mono' _ _ hnm := MeasurableSpace.generateFrom_mono fun _ ⟹k, hk₁, hk₂⟩ => ⟹k, hk₁.trans hnm, hk₂⟩ le' _ := MeasurableSpace.generateFrom_le fun _ ⟹k, _, hk₂⟩ => hk₂ ▾ hsm k theorem measurableSet_filtrationOfSet {s : ι → Set Ω} (hsm : ∀ i, MeasurableSet[m] (s i)) (i : ι) {j : ι} (hj : j ≀ i) : MeasurableSet[filtrationOfSet hsm i] (s j) := MeasurableSpace.measurableSet_generateFrom ⟹j, hj, rfl⟩ theorem measurableSet_filtrationOfSet' {s : ι → Set Ω} (hsm : ∀ n, MeasurableSet[m] (s n)) (i : ι) : MeasurableSet[filtrationOfSet hsm i] (s i) := measurableSet_filtrationOfSet hsm i le_rfl end OfSet namespace Filtration variable [TopologicalSpace β] [MetrizableSpace β] [mβ : MeasurableSpace β] [BorelSpace β] [Preorder ι] /-- Given a sequence of functions, the natural filtration is the smallest sequence of σ-algebras such that that sequence of functions is measurable with respect to the filtration. -/ def natural (u : ι → Ω → β) (hum : ∀ i, StronglyMeasurable (u i)) : Filtration ι m where seq i := ⹆ j ≀ i, MeasurableSpace.comap (u j) mβ mono' _ _ hij := biSup_mono fun _ => ge_trans hij le' i := by refine iSup₂_le ?_ rintro j _ s ⟹t, ht, rfl⟩ exact (hum j).measurable ht section open MeasurableSpace theorem filtrationOfSet_eq_natural [MulZeroOneClass β] [Nontrivial β] {s : ι → Set Ω} (hsm : ∀ i, MeasurableSet[m] (s i)) : filtrationOfSet hsm = natural (fun i => (s i).indicator (fun _ => 1 : Ω → β)) fun i => stronglyMeasurable_one.indicator (hsm i) := by simp only [filtrationOfSet, natural, measurableSpace_iSup_eq, exists_prop, mk.injEq] ext1 i refine le_antisymm (generateFrom_le ?_) (generateFrom_le ?_) · rintro _ ⟹j, hij, rfl⟩ refine measurableSet_generateFrom ⟹j, measurableSet_generateFrom ⟹hij, ?_⟩⟩ rw [comap_eq_generateFrom] refine measurableSet_generateFrom ⟹{1}, measurableSet_singleton 1, ?_⟩ ext x simp [Set.indicator_const_preimage_eq_union] · rintro t ⟹n, ht⟩ suffices MeasurableSpace.generateFrom {t | n ≀ i ∧ MeasurableSet[MeasurableSpace.comap ((s n).indicator (fun _ => 1 : Ω → β)) mβ] t} ≀ MeasurableSpace.generateFrom {t | ∃ (j : ι), j ≀ i ∧ s j = t} by exact this _ ht refine generateFrom_le ?_ rintro t ⟹hn, u, _, hu'⟩ obtain heq | heq | heq | heq := Set.indicator_const_preimage (s n) u (1 : β) on_goal 4 => rw [Set.mem_singleton_iff] at heq all_goals rw [heq] at hu'; rw [← hu'] exacts [MeasurableSet.univ, measurableSet_generateFrom ⟹n, hn, rfl⟩, MeasurableSet.compl (measurableSet_generateFrom ⟹n, hn, rfl⟩), measurableSet_empty _] end section Limit variable {E : Type*} [Zero E] [TopologicalSpace E] {ℱ : Filtration ι m} {f : ι → Ω → E} {ÎŒ : Measure Ω} open scoped Classical in /-- Given a process `f` and a filtration `ℱ`, if `f` converges to some `g` almost everywhere and `g` is `⹆ n, ℱ n`-measurable, then `limitProcess f ℱ ÎŒ` chooses said `g`, else it returns 0. This definition is used to phrase the a.e. martingale convergence theorem `Submartingale.ae_tendsto_limitProcess` where an L¹-bounded submartingale `f` adapted to `ℱ` converges to `limitProcess f ℱ ÎŒ` `ÎŒ`-almost everywhere. -/ noncomputable def limitProcess (f : ι → Ω → E) (ℱ : Filtration ι m) (ÎŒ : Measure Ω) := if h : ∃ g : Ω → E, StronglyMeasurable[⹆ n, ℱ n] g ∧ ∀ᵐ ω ∂Ό, Tendsto (fun n => f n ω) atTop (𝓝 (g ω)) then Classical.choose h else 0 theorem stronglyMeasurable_limitProcess : StronglyMeasurable[⹆ n, ℱ n] (limitProcess f ℱ ÎŒ) := by rw [limitProcess] split_ifs with h exacts [(Classical.choose_spec h).1, stronglyMeasurable_zero] theorem stronglyMeasurable_limit_process' : StronglyMeasurable[m] (limitProcess f ℱ ÎŒ) := stronglyMeasurable_limitProcess.mono (sSup_le fun _ ⟹_, hn⟩ => hn ▾ ℱ.le _) theorem memLp_limitProcess_of_eLpNorm_bdd {R : ℝ≥0} {p : ℝ≥0∞} {F : Type*} [NormedAddCommGroup F] {ℱ : Filtration ℕ m} {f : ℕ → Ω → F} (hfm : ∀ n, AEStronglyMeasurable (f n) ÎŒ) (hbdd : ∀ n, eLpNorm (f n) p ÎŒ ≀ R) : MemLp (limitProcess f ℱ ÎŒ) p ÎŒ := by rw [limitProcess] split_ifs with h · refine ⟹StronglyMeasurable.aestronglyMeasurable ((Classical.choose_spec h).1.mono (sSup_le fun m ⟹n, hn⟩ => hn ▾ ℱ.le _)), lt_of_le_of_lt (Lp.eLpNorm_lim_le_liminf_eLpNorm hfm _ (Classical.choose_spec h).2) (lt_of_le_of_lt ?_ (ENNReal.coe_lt_top : ↑R < ∞))⟩ simp_rw [liminf_eq, eventually_atTop] exact sSup_le fun b ⟹a, ha⟩ => (ha a le_rfl).trans (hbdd _) · exact MemLp.zero
@[deprecated (since := "2025-02-21")] alias memℒp_limitProcess_of_eLpNorm_bdd := memLp_limitProcess_of_eLpNorm_bdd end Limit section piLE /-! ### Filtration of the first events -/ open MeasurableSpace Preorder variable {X : ι → Type*} [∀ i, MeasurableSpace (X i)]
Mathlib/Probability/Process/Filtration.lean
338
349
/- 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.LinearAlgebra.Basis.Basic import Mathlib.LinearAlgebra.Basis.Submodule import Mathlib.LinearAlgebra.Dimension.Finrank import Mathlib.LinearAlgebra.InvariantBasisNumber /-! # Lemmas about rank and finrank in rings satisfying strong rank condition. ## Main statements For modules over rings satisfying the rank condition * `Basis.le_span`: the cardinality of a basis is bounded by the cardinality of any spanning set For modules over rings satisfying the strong rank condition * `linearIndependent_le_span`: For any linearly independent family `v : ι → M` and any finite spanning set `w : Set M`, the cardinality of `ι` is bounded by the cardinality of `w`. * `linearIndependent_le_basis`: If `b` is a basis for a module `M`, and `s` is a linearly independent set, then the cardinality of `s` is bounded by the cardinality of `b`. For modules over rings with invariant basis number (including all commutative rings and all noetherian rings) * `mk_eq_mk_of_basis`: the dimension theorem, any two bases of the same vector space have the same cardinality. ## Additional definition * `Algebra.IsQuadraticExtension`: An extension of rings `R ⊆ S` is quadratic if `S` is a free `R`-algebra of rank `2`. -/ noncomputable section universe u v w w' variable {R : Type u} {M : Type v} [Semiring R] [AddCommMonoid M] [Module R M] variable {ι : Type w} {ι' : Type w'} open Cardinal Basis Submodule Function Set Module attribute [local instance] nontrivial_of_invariantBasisNumber section InvariantBasisNumber variable [InvariantBasisNumber R] /-- The dimension theorem: if `v` and `v'` are two bases, their index types have the same cardinalities. -/ theorem mk_eq_mk_of_basis (v : Basis ι R M) (v' : Basis ι' R M) : Cardinal.lift.{w'} #ι = Cardinal.lift.{w} #ι' := by classical haveI := nontrivial_of_invariantBasisNumber R cases fintypeOrInfinite ι · -- `v` is a finite basis, so by `basis_finite_of_finite_spans` so is `v'`. -- haveI : Finite (range v) := Set.finite_range v haveI := basis_finite_of_finite_spans (Set.finite_range v) v.span_eq v' cases nonempty_fintype ι' -- We clean up a little: rw [Cardinal.mk_fintype, Cardinal.mk_fintype] simp only [Cardinal.lift_natCast, Nat.cast_inj] -- Now we can use invariant basis number to show they have the same cardinality. apply card_eq_of_linearEquiv R exact (Finsupp.linearEquivFunOnFinite R R ι).symm.trans v.repr.symm ≪≫ₗ v'.repr ≪≫ₗ Finsupp.linearEquivFunOnFinite R R ι' · -- `v` is an infinite basis, -- so by `infinite_basis_le_maximal_linearIndependent`, `v'` is at least as big, -- and then applying `infinite_basis_le_maximal_linearIndependent` again -- we see they have the same cardinality. have w₁ := infinite_basis_le_maximal_linearIndependent' v _ v'.linearIndependent v'.maximal rcases Cardinal.lift_mk_le'.mp w₁ with ⟹f⟩ haveI : Infinite ι' := Infinite.of_injective f f.2 have w₂ := infinite_basis_le_maximal_linearIndependent' v' _ v.linearIndependent v.maximal exact le_antisymm w₁ w₂ /-- Given two bases indexed by `ι` and `ι'` of an `R`-module, where `R` satisfies the invariant basis number property, an equiv `ι ≃ ι'`. -/ def Basis.indexEquiv (v : Basis ι R M) (v' : Basis ι' R M) : ι ≃ ι' := (Cardinal.lift_mk_eq'.1 <| mk_eq_mk_of_basis v v').some theorem mk_eq_mk_of_basis' {ι' : Type w} (v : Basis ι R M) (v' : Basis ι' R M) : #ι = #ι' := Cardinal.lift_inj.1 <| mk_eq_mk_of_basis v v' end InvariantBasisNumber section RankCondition variable [RankCondition R] /-- An auxiliary lemma for `Basis.le_span`. If `R` satisfies the rank condition, then for any finite basis `b : Basis ι R M`, and any finite spanning set `w : Set M`, the cardinality of `ι` is bounded by the cardinality of `w`. -/ theorem Basis.le_span'' {ι : Type*} [Fintype ι] (b : Basis ι R M) {w : Set M} [Fintype w] (s : span R w = ⊀) : Fintype.card ι ≀ Fintype.card w := by -- We construct a surjective linear map `(w → R) →ₗ[R] (ι → R)`, -- by expressing a linear combination in `w` as a linear combination in `ι`. fapply card_le_of_surjective' R · exact b.repr.toLinearMap.comp (Finsupp.linearCombination R (↑)) · apply Surjective.comp (g := b.repr.toLinearMap) · apply LinearEquiv.surjective rw [← LinearMap.range_eq_top, Finsupp.range_linearCombination] simpa using s /-- Another auxiliary lemma for `Basis.le_span`, which does not require assuming the basis is finite, but still assumes we have a finite spanning set. -/ theorem basis_le_span' {ι : Type*} (b : Basis ι R M) {w : Set M} [Fintype w] (s : span R w = ⊀) : #ι ≀ Fintype.card w := by haveI := nontrivial_of_invariantBasisNumber R haveI := basis_finite_of_finite_spans w.toFinite s b cases nonempty_fintype ι rw [Cardinal.mk_fintype ι] simp only [Nat.cast_le] exact Basis.le_span'' b s -- Note that if `R` satisfies the strong rank condition, -- this also follows from `linearIndependent_le_span` below. /-- If `R` satisfies the rank condition, then the cardinality of any basis is bounded by the cardinality of any spanning set. -/ theorem Basis.le_span {J : Set M} (v : Basis ι R M) (hJ : span R J = ⊀) : #(range v) ≀ #J := by haveI := nontrivial_of_invariantBasisNumber R cases fintypeOrInfinite J · rw [← Cardinal.lift_le, Cardinal.mk_range_eq_of_injective v.injective, Cardinal.mk_fintype J] convert Cardinal.lift_le.{v}.2 (basis_le_span' v hJ) simp · let S : J → Set ι := fun j => ↑(v.repr j).support let S' : J → Set M := fun j => v '' S j have hs : range v ⊆ ⋃ j, S' j := by intro b hb rcases mem_range.1 hb with ⟹i, hi⟩ have : span R J ≀ comap v.repr.toLinearMap (Finsupp.supported R R (⋃ j, S j)) := span_le.2 fun j hj x hx => ⟹_, ⟹⟹j, hj⟩, rfl⟩, hx⟩ rw [hJ] at this replace : v.repr (v i) ∈ Finsupp.supported R R (⋃ j, S j) := this trivial rw [v.repr_self, Finsupp.mem_supported, Finsupp.support_single_ne_zero _ one_ne_zero] at this · subst b rcases mem_iUnion.1 (this (Finset.mem_singleton_self _)) with ⟹j, hj⟩ exact mem_iUnion.2 ⟹j, (mem_image _ _ _).2 ⟹i, hj, rfl⟩⟩ refine le_of_not_lt fun IJ => ?_ suffices #(⋃ j, S' j) < #(range v) by exact not_le_of_lt this ⟹Set.embeddingOfSubset _ _ hs⟩ refine lt_of_le_of_lt (le_trans Cardinal.mk_iUnion_le_sum_mk (Cardinal.sum_le_sum _ (fun _ => ℵ₀) ?_)) ?_ · exact fun j => (Cardinal.lt_aleph0_of_finite _).le · simpa end RankCondition section StrongRankCondition variable [StrongRankCondition R] open Submodule Finsupp -- An auxiliary lemma for `linearIndependent_le_span'`, -- with the additional assumption that the linearly independent family is finite. theorem linearIndependent_le_span_aux' {ι : Type*} [Fintype ι] (v : ι → M) (i : LinearIndependent R v) (w : Set M) [Fintype w] (s : range v ≀ span R w) : Fintype.card ι ≀ Fintype.card w := by -- We construct an injective linear map `(ι → R) →ₗ[R] (w → R)`, -- by thinking of `f : ι → R` as a linear combination of the finite family `v`, -- and expressing that (using the axiom of choice) as a linear combination over `w`. -- We can do this linearly by constructing the map on a basis. fapply card_le_of_injective' R · apply Finsupp.linearCombination exact fun i => Span.repr R w ⟹v i, s (mem_range_self i)⟩ · intro f g h apply_fun linearCombination R ((↑) : w → M) at h simp only [linearCombination_linearCombination, Submodule.coe_mk, Span.finsupp_linearCombination_repr] at h exact i h /-- If `R` satisfies the strong rank condition, then any linearly independent family `v : ι → M` contained in the span of some finite `w : Set M`, is itself finite. -/ lemma LinearIndependent.finite_of_le_span_finite {ι : Type*} (v : ι → M) (i : LinearIndependent R v) (w : Set M) [Finite w] (s : range v ≀ span R w) : Finite ι := letI := Fintype.ofFinite w Fintype.finite <| fintypeOfFinsetCardLe (Fintype.card w) fun t => by let v' := fun x : (t : Set ι) => v x have i' : LinearIndependent R v' := i.comp _ Subtype.val_injective have s' : range v' ≀ span R w := (range_comp_subset_range _ _).trans s simpa using linearIndependent_le_span_aux' v' i' w s' /-- If `R` satisfies the strong rank condition, then for any linearly independent family `v : ι → M` contained in the span of some finite `w : Set M`, the cardinality of `ι` is bounded by the cardinality of `w`. -/ theorem linearIndependent_le_span' {ι : Type*} (v : ι → M) (i : LinearIndependent R v) (w : Set M) [Fintype w] (s : range v ≀ span R w) : #ι ≀ Fintype.card w := by haveI : Finite ι := i.finite_of_le_span_finite v w s letI := Fintype.ofFinite ι rw [Cardinal.mk_fintype] simp only [Nat.cast_le] exact linearIndependent_le_span_aux' v i w s /-- If `R` satisfies the strong rank condition, then for any linearly independent family `v : ι → M` and any finite spanning set `w : Set M`, the cardinality of `ι` is bounded by the cardinality of `w`. -/ theorem linearIndependent_le_span {ι : Type*} (v : ι → M) (i : LinearIndependent R v) (w : Set M) [Fintype w] (s : span R w = ⊀) : #ι ≀ Fintype.card w := by apply linearIndependent_le_span' v i w rw [s] exact le_top /-- A version of `linearIndependent_le_span` for `Finset`. -/ theorem linearIndependent_le_span_finset {ι : Type*} (v : ι → M) (i : LinearIndependent R v) (w : Finset M) (s : span R (w : Set M) = ⊀) : #ι ≀ w.card := by simpa only [Finset.coe_sort_coe, Fintype.card_coe] using linearIndependent_le_span v i w s /-- An auxiliary lemma for `linearIndependent_le_basis`: we handle the case where the basis `b` is infinite. -/ theorem linearIndependent_le_infinite_basis {ι : Type w} (b : Basis ι R M) [Infinite ι] {κ : Type w} (v : κ → M) (i : LinearIndependent R v) : #κ ≀ #ι := by classical by_contra h rw [not_le, ← Cardinal.mk_finset_of_infinite ι] at h let Ί := fun k : κ => (b.repr (v k)).support obtain ⟹s, w : Infinite ↑(Ί ⁻¹' {s})⟩ := Cardinal.exists_infinite_fiber Ί h (by infer_instance) let v' := fun k : Ί ⁻¹' {s} => v k have i' : LinearIndependent R v' := i.comp _ Subtype.val_injective have w' : Finite (Ί ⁻¹' {s}) := by apply i'.finite_of_le_span_finite v' (s.image b) rintro m ⟹⟹p, ⟹rfl⟩⟩, rfl⟩ simp only [SetLike.mem_coe, Subtype.coe_mk, Finset.coe_image] apply Basis.mem_span_repr_support exact w.false /-- Over any ring `R` satisfying the strong rank condition, if `b` is a basis for a module `M`, and `s` is a linearly independent set, then the cardinality of `s` is bounded by the cardinality of `b`. -/ theorem linearIndependent_le_basis {ι : Type w} (b : Basis ι R M) {κ : Type w} (v : κ → M) (i : LinearIndependent R v) : #κ ≀ #ι := by classical -- We split into cases depending on whether `ι` is infinite. cases fintypeOrInfinite ι · rw [Cardinal.mk_fintype ι] -- When `ι` is finite, we have `linearIndependent_le_span`, haveI : Nontrivial R := nontrivial_of_invariantBasisNumber R rw [Fintype.card_congr (Equiv.ofInjective b b.injective)] exact linearIndependent_le_span v i (range b) b.span_eq · -- and otherwise we have `linearIndependent_le_infinite_basis`. exact linearIndependent_le_infinite_basis b v i /-- `StrongRankCondition` implies that if there is an injective linear map `(α →₀ R) →ₗ[R] β →₀ R`, then the cardinal of `α` is smaller than or equal to the cardinal of `β`. -/ theorem card_le_of_injective'' {α : Type v} {β : Type v} (f : (α →₀ R) →ₗ[R] β →₀ R) (i : Injective f) : #α ≀ #β := by let b : Basis β R (β →₀ R) := ⟹1⟩ apply linearIndependent_le_basis b (fun (i : α) ↩ f (Finsupp.single i 1)) rw [LinearIndependent] have : (linearCombination R fun i ↩ f (Finsupp.single i 1)) = f := by ext a b; simp exact this.symm ▾ i /-- If `R` satisfies the strong rank condition, then for any linearly independent family `v : ι → M` and spanning set `w : Set M`, the cardinality of `ι` is bounded by the cardinality of `w`. -/ theorem linearIndependent_le_span'' {ι : Type v} {v : ι → M} (i : LinearIndependent R v) (w : Set M) (s : span R w = ⊀) : #ι ≀ #w := by fapply card_le_of_injective'' (R := R) · apply Finsupp.linearCombination exact fun i ↩ Span.repr R w ⟹v i, s ▾ trivial⟩ · intro f g h apply_fun linearCombination R ((↑) : w → M) at h simp only [linearCombination_linearCombination, Submodule.coe_mk, Span.finsupp_linearCombination_repr] at h exact i h /-- Let `R` satisfy the strong rank condition. If `m` elements of a free rank `n` `R`-module are linearly independent, then `m ≀ n`. -/ theorem Basis.card_le_card_of_linearIndependent_aux {R : Type*} [Semiring R] [StrongRankCondition R] (n : ℕ) {m : ℕ} (v : Fin m → Fin n → R) : LinearIndependent R v → m ≀ n := fun h => by simpa using linearIndependent_le_basis (Pi.basisFun R (Fin n)) v h -- When the basis is not infinite this need not be true! /-- Over any ring `R` satisfying the strong rank condition, if `b` is an infinite basis for a module `M`, then every maximal linearly independent set has the same cardinality as `b`. This proof (along with some of the lemmas above) comes from [Les familles libres maximales d'un module ont-elles le meme cardinal?][lazarus1973] -/ theorem maximal_linearIndependent_eq_infinite_basis {ι : Type w} (b : Basis ι R M) [Infinite ι] {κ : Type w} (v : κ → M) (i : LinearIndependent R v) (m : i.Maximal) : #κ = #ι := by apply le_antisymm · exact linearIndependent_le_basis b v i · haveI : Nontrivial R := nontrivial_of_invariantBasisNumber R exact infinite_basis_le_maximal_linearIndependent b v i m theorem Basis.mk_eq_rank'' {ι : Type v} (v : Basis ι R M) : #ι = Module.rank R M := by haveI := nontrivial_of_invariantBasisNumber R rw [Module.rank_def] apply le_antisymm · trans swap · apply le_ciSup (Cardinal.bddAbove_range _) exact ⟹Set.range v, by rw [LinearIndepOn] convert v.reindexRange.linearIndependent simp⟩ · exact (Cardinal.mk_range_eq v v.injective).ge · apply ciSup_le' rintro ⟹s, li⟩ apply linearIndependent_le_basis v _ li theorem Basis.mk_range_eq_rank (v : Basis ι R M) : #(range v) = Module.rank R M := v.reindexRange.mk_eq_rank'' /-- If a vector space has a finite basis, then its dimension (seen as a cardinal) is equal to the cardinality of the basis. -/ theorem rank_eq_card_basis {ι : Type w} [Fintype ι] (h : Basis ι R M) : Module.rank R M = Fintype.card ι := by classical haveI := nontrivial_of_invariantBasisNumber R rw [← h.mk_range_eq_rank, Cardinal.mk_fintype, Set.card_range_of_injective h.injective] theorem Basis.card_le_card_of_linearIndependent {ι : Type*} [Fintype ι] (b : Basis ι R M) {ι' : Type*} [Fintype ι'] {v : ι' → M} (hv : LinearIndependent R v) : Fintype.card ι' ≀ Fintype.card ι := by letI := nontrivial_of_invariantBasisNumber R simpa [rank_eq_card_basis b, Cardinal.mk_fintype] using hv.cardinal_lift_le_rank theorem Basis.card_le_card_of_submodule (N : Submodule R M) [Fintype ι] (b : Basis ι R M) [Fintype ι'] (b' : Basis ι' R N) : Fintype.card ι' ≀ Fintype.card ι := b.card_le_card_of_linearIndependent (b'.linearIndependent.map_injOn N.subtype N.injective_subtype.injOn) theorem Basis.card_le_card_of_le {N O : Submodule R M} (hNO : N ≀ O) [Fintype ι] (b : Basis ι R O) [Fintype ι'] (b' : Basis ι' R N) : Fintype.card ι' ≀ Fintype.card ι := b.card_le_card_of_linearIndependent (b'.linearIndependent.map_injOn (inclusion hNO) (N.inclusion_injective _).injOn) theorem Basis.mk_eq_rank (v : Basis ι R M) : Cardinal.lift.{v} #ι = Cardinal.lift.{w} (Module.rank R M) := by haveI := nontrivial_of_invariantBasisNumber R rw [← v.mk_range_eq_rank, Cardinal.mk_range_eq_of_injective v.injective] theorem Basis.mk_eq_rank'.{m} (v : Basis ι R M) : Cardinal.lift.{max v m} #ι = Cardinal.lift.{max w m} (Module.rank R M) := Cardinal.lift_umax_eq.{w, v, m}.mpr v.mk_eq_rank theorem rank_span {v : ι → M} (hv : LinearIndependent R v) : Module.rank R ↑(span R (range v)) = #(range v) := by haveI := nontrivial_of_invariantBasisNumber R rw [← Cardinal.lift_inj, ← (Basis.span hv).mk_eq_rank, Cardinal.mk_range_eq_of_injective (@LinearIndependent.injective ι R M v _ _ _ _ hv)] theorem rank_span_set {s : Set M} (hs : LinearIndepOn R id s) : Module.rank R ↑(span R s) = #s := by rw [← @setOf_mem_eq _ s, ← Subtype.range_coe_subtype] exact rank_span hs theorem toENat_rank_span_set {v : ι → M} {s : Set ι} (hs : LinearIndepOn R v s) : (Module.rank R <| span R <| v '' s).toENat = s.encard := by rw [image_eq_range, ← hs.injOn.encard_image, ← toENat_cardinalMk, image_eq_range, ← rank_span hs.linearIndependent] /-- An induction (and recursion) principle for proving results about all submodules of a fixed finite free module `M`. A property is true for all submodules of `M` if it satisfies the following "inductive step": the property is true for a submodule `N` if it's true for all submodules `N'` of `N` with the property that there exists `0 ≠ x ∈ N` such that the sum `N' + Rx` is direct. -/ def Submodule.inductionOnRank {R M} [Ring R] [StrongRankCondition R] [AddCommGroup M] [Module R M] [IsDomain R] [Finite ι] (b : Basis ι R M) (P : Submodule R M → Sort*) (ih : ∀ N : Submodule R M, (∀ N' ≀ N, ∀ x ∈ N, (∀ (c : R), ∀ y ∈ N', c • x + y = (0 : M) → c = 0) → P N') → P N) (N : Submodule R M) : P N := letI := Fintype.ofFinite ι Submodule.inductionOnRankAux b P ih (Fintype.card ι) N fun hs hli => by simpa using b.card_le_card_of_linearIndependent hli /-- If `S` a module-finite free `R`-algebra, then the `R`-rank of a nonzero `R`-free ideal `I` of `S` is the same as the rank of `S`. -/ theorem Ideal.rank_eq {R S : Type*} [CommRing R] [StrongRankCondition R] [Ring S] [IsDomain S] [Algebra R S] {n m : Type*} [Fintype n] [Fintype m] (b : Basis n R S) {I : Ideal S} (hI : I ≠ ⊥) (c : Basis m R I) : Fintype.card m = Fintype.card n := by obtain ⟹a, ha⟩ := Submodule.nonzero_mem_of_bot_lt (bot_lt_iff_ne_bot.mpr hI) have : LinearIndependent R fun i => b i • a := by have hb := b.linearIndependent rw [Fintype.linearIndependent_iff] at hb ⊢ intro g hg apply hb g simp only [← smul_assoc, ← Finset.sum_smul, smul_eq_zero] at hg exact hg.resolve_right ha exact le_antisymm (b.card_le_card_of_linearIndependent (c.linearIndependent.map' (Submodule.subtype I) ((LinearMap.ker_eq_bot (f := (Submodule.subtype I : I →ₗ[R] S))).mpr Subtype.coe_injective))) (c.card_le_card_of_linearIndependent this) namespace Module theorem finrank_eq_nat_card_basis (h : Basis ι R M) : finrank R M = Nat.card ι := by rw [Nat.card, ← toNat_lift.{v}, h.mk_eq_rank, toNat_lift, finrank] /-- If a vector space (or module) has a finite basis, then its dimension (or rank) is equal to the cardinality of the basis. -/ theorem finrank_eq_card_basis {ι : Type w} [Fintype ι] (h : Basis ι R M) : finrank R M = Fintype.card ι := finrank_eq_of_rank_eq (rank_eq_card_basis h) /-- If a free module is of finite rank, then the cardinality of any basis is equal to its `finrank`. -/ theorem mk_finrank_eq_card_basis [Module.Finite R M] {ι : Type w} (h : Basis ι R M) : (finrank R M : Cardinal.{w}) = #ι := by cases @nonempty_fintype _ (Module.Finite.finite_basis h) rw [Cardinal.mk_fintype, finrank_eq_card_basis h] /-- If a vector space (or module) has a finite basis, then its dimension (or rank) is equal to the cardinality of the basis. This lemma uses a `Finset` instead of indexed types. -/ theorem finrank_eq_card_finset_basis {ι : Type w} {b : Finset ι} (h : Basis b R M) : finrank R M = Finset.card b := by rw [finrank_eq_card_basis h, Fintype.card_coe] variable (R) @[simp] theorem rank_self : Module.rank R R = 1 := by rw [← Cardinal.lift_inj, ← (Basis.singleton PUnit R).mk_eq_rank, Cardinal.mk_punit] /-- A ring satisfying `StrongRankCondition` (such as a `DivisionRing`) is one-dimensional as a module over itself. -/ @[simp] theorem finrank_self : finrank R R = 1 := finrank_eq_of_rank_eq (by simp) /-- Given a basis of a ring over itself indexed by a type `ι`, then `ι` is `Unique`. -/ noncomputable def _root_.Basis.unique {ι : Type*} (b : Basis ι R R) : Unique ι := by have : Cardinal.mk ι = ↑(Module.finrank R R) := (Module.mk_finrank_eq_card_basis b).symm have : Subsingleton ι ∧ Nonempty ι := by simpa [Cardinal.eq_one_iff_unique] exact Nonempty.some ((unique_iff_subsingleton_and_nonempty _).2 this) variable (M) /-- The rank of a finite module is finite. -/ theorem rank_lt_aleph0 [Module.Finite R M] : Module.rank R M < ℵ₀ := by simp only [Module.rank_def] obtain ⟹S, hS⟩ := Module.finite_def.mp ‹_› refine (ciSup_le' fun i => ?_).trans_lt (nat_lt_aleph0 S.card)
exact linearIndependent_le_span_finset _ i.prop S hS noncomputable instance {R M : Type*} [DivisionRing R] [AddCommGroup M] [Module R M] {s t : Set M} [Module.Finite R (span R t)] (hs : LinearIndepOn R id s) (hst : s ⊆ t) : Fintype (hs.extend hst) := by
Mathlib/LinearAlgebra/Dimension/StrongRankCondition.lean
465
470
/- Copyright (c) 2022. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Yuma Mizuno, Oleksandr Manzyuk -/ import Mathlib.CategoryTheory.Monoidal.Category /-! # Monoidal composition `⊗≫` (composition up to associators) We provide `f ⊗≫ g`, the `monoidalComp` operation, which automatically inserts associators and unitors as needed to make the target of `f` match the source of `g`. ## Example Suppose we have a braiding morphism `R X Y : X ⊗ Y ⟶ Y ⊗ X` in a monoidal category, and that we want to define the morphism with the type `V₁ ⊗ V₂ ⊗ V₃ ⊗ V₄ ⊗ V₅ ⟶ V₁ ⊗ V₃ ⊗ V₂ ⊗ V₄ ⊗ V₅` that transposes the second and third components by `R V₂ V₃`. How to do this? The first guess would be to use the whiskering operators `◁` and `▷`, and define the morphism as `V₁ ◁ R V₂ V₃ ▷ V₄ ▷ V₅`. However, this morphism has the type `V₁ ⊗ ((V₂ ⊗ V₃) ⊗ V₄) ⊗ V₅ ⟶ V₁ ⊗ ((V₃ ⊗ V₂) ⊗ V₄) ⊗ V₅`, which is not what we need. We should insert suitable associators. The desired associators can, in principle, be defined by using the primitive three-components associator `α_ X Y Z : (X ⊗ Y) ⊗ Z ≅ X ⊗ (Y ⊗ Z)` as a building block, but writing down actual definitions are quite tedious, and we usually don't want to see them. The monoidal composition `⊗≫` is designed to solve such a problem. In this case, we can define the desired morphism as `𝟙 _ ⊗≫ V₁ ◁ R V₂ V₃ ▷ V₄ ▷ V₅ ⊗≫ 𝟙 _`, where the first and the second `𝟙 _` are completed as `𝟙 (V₁ ⊗ V₂ ⊗ V₃ ⊗ V₄ ⊗ V₅)` and `𝟙 (V₁ ⊗ V₃ ⊗ V₂ ⊗ V₄ ⊗ V₅)`, respectively. -/ universe v u open CategoryTheory MonoidalCategory namespace CategoryTheory variable {C : Type u} [Category.{v} C] open scoped MonoidalCategory /-- A typeclass carrying a choice of monoidal structural isomorphism between two objects. Used by the `⊗≫` monoidal composition operator, and the `coherence` tactic. -/ -- We could likely turn this into a `Prop` valued existential if that proves useful. class MonoidalCoherence (X Y : C) where /-- A monoidal structural isomorphism between two objects. -/ iso : X ≅ Y /-- Notation for identities up to unitors and associators. -/ scoped[CategoryTheory.MonoidalCategory] notation " ⊗𝟙 " => MonoidalCoherence.iso -- type as \ot 𝟙 /-- Construct an isomorphism between two objects in a monoidal category out of unitors and associators. -/ abbrev monoidalIso (X Y : C) [MonoidalCoherence X Y] : X ≅ Y := MonoidalCoherence.iso /-- Compose two morphisms in a monoidal category, inserting unitors and associators between as necessary. -/ def monoidalComp {W X Y Z : C} [MonoidalCoherence X Y] (f : W ⟶ X) (g : Y ⟶ Z) : W ⟶ Z := f ≫ ⊗𝟙.hom ≫ g @[inherit_doc monoidalComp] scoped[CategoryTheory.MonoidalCategory] infixr:80 " ⊗≫ " => monoidalComp -- type as \ot \gg /-- Compose two isomorphisms in a monoidal category, inserting unitors and associators between as necessary. -/ def monoidalIsoComp {W X Y Z : C} [MonoidalCoherence X Y] (f : W ≅ X) (g : Y ≅ Z) : W ≅ Z := f ≪≫ ⊗𝟙 ≪≫ g @[inherit_doc monoidalIsoComp] scoped[CategoryTheory.MonoidalCategory] infixr:80 " ≪⊗≫ " => monoidalIsoComp -- type as \ll \ot \gg namespace MonoidalCoherence variable [MonoidalCategory C] @[simps] instance refl (X : C) : MonoidalCoherence X X := ⟹Iso.refl _⟩ @[simps] instance whiskerLeft (X Y Z : C) [MonoidalCoherence Y Z] : MonoidalCoherence (X ⊗ Y) (X ⊗ Z) := ⟹whiskerLeftIso X ⊗𝟙⟩ @[simps] instance whiskerRight (X Y Z : C) [MonoidalCoherence X Y] : MonoidalCoherence (X ⊗ Z) (Y ⊗ Z) := ⟹whiskerRightIso ⊗𝟙 Z⟩ @[simps] instance tensor_right (X Y : C) [MonoidalCoherence (𝟙_ C) Y] : MonoidalCoherence X (X ⊗ Y) := ⟹(ρ_ X).symm ≪≫ (whiskerLeftIso X ⊗𝟙)⟩ @[simps] instance tensor_right' (X Y : C) [MonoidalCoherence Y (𝟙_ C)] : MonoidalCoherence (X ⊗ Y) X := ⟹whiskerLeftIso X ⊗𝟙 ≪≫ (ρ_ X)⟩ @[simps] instance left (X Y : C) [MonoidalCoherence X Y] : MonoidalCoherence (𝟙_ C ⊗ X) Y := ⟚λ_ X ≪≫ ⊗𝟙⟩ @[simps] instance left' (X Y : C) [MonoidalCoherence X Y] : MonoidalCoherence X (𝟙_ C ⊗ Y) := ⟚⊗𝟙 ≪≫ (λ_ Y).symm⟩ @[simps] instance right (X Y : C) [MonoidalCoherence X Y] : MonoidalCoherence (X ⊗ 𝟙_ C) Y := ⟚ρ_ X ≪≫ ⊗𝟙⟩ @[simps] instance right' (X Y : C) [MonoidalCoherence X Y] : MonoidalCoherence X (Y ⊗ 𝟙_ C) := ⟚⊗𝟙 ≪≫ (ρ_ Y).symm⟩ @[simps] instance assoc (X Y Z W : C) [MonoidalCoherence (X ⊗ (Y ⊗ Z)) W] : MonoidalCoherence ((X ⊗ Y) ⊗ Z) W := ⟚α_ X Y Z ≪≫ ⊗𝟙⟩ @[simps] instance assoc' (W X Y Z : C) [MonoidalCoherence W (X ⊗ (Y ⊗ Z))] : MonoidalCoherence W ((X ⊗ Y) ⊗ Z) := ⟚⊗𝟙 ≪≫ (α_ X Y Z).symm⟩ end MonoidalCoherence @[simp] lemma monoidalComp_refl {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) : f ⊗≫ g = f ≫ g := by simp [monoidalComp] end CategoryTheory
Mathlib/Tactic/CategoryTheory/MonoidalComp.lean
142
144
/- Copyright (c) 2018 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Simon Hudon -/ import Batteries.Data.List.Lemmas import Mathlib.Tactic.TypeStar /-! # The Following Are Equivalent This file allows to state that all propositions in a list are equivalent. It is used by `Mathlib.Tactic.Tfae`. `TFAE l` means `∀ x ∈ l, ∀ y ∈ l, x ↔ y`. This is equivalent to `Pairwise (↔) l`. -/ namespace List /-- TFAE: The Following (propositions) Are Equivalent. The `tfae_have` and `tfae_finish` tactics can be useful in proofs with `TFAE` goals. -/ def TFAE (l : List Prop) : Prop := ∀ x ∈ l, ∀ y ∈ l, x ↔ y theorem tfae_nil : TFAE [] := forall_mem_nil _ @[simp] theorem tfae_singleton (p) : TFAE [p] := by simp [TFAE, -eq_iff_iff] theorem tfae_cons_of_mem {a b} {l : List Prop} (h : b ∈ l) : TFAE (a :: l) ↔ (a ↔ b) ∧ TFAE l := ⟹fun H => ⟹H a (by simp) b (Mem.tail a h), fun _ hp _ hq => H _ (Mem.tail a hp) _ (Mem.tail a hq)⟩, by rintro ⟹ab, H⟩ p (_ | ⟹_, hp⟩) q (_ | ⟹_, hq⟩) · rfl · exact ab.trans (H _ h _ hq) · exact (ab.trans (H _ h _ hp)).symm · exact H _ hp _ hq⟩ theorem tfae_cons_cons {a b} {l : List Prop} : TFAE (a :: b :: l) ↔ (a ↔ b) ∧ TFAE (b :: l) := tfae_cons_of_mem (Mem.head _) @[simp] theorem tfae_cons_self {a} {l : List Prop} : TFAE (a :: a :: l) ↔ TFAE (a :: l) := by simp [tfae_cons_cons] theorem tfae_of_forall (b : Prop) (l : List Prop) (h : ∀ a ∈ l, a ↔ b) : TFAE l := fun _a₁ h₁ _a₂ h₂ => (h _ h₁).trans (h _ h₂).symm theorem tfae_of_cycle {a b} {l : List Prop} (h_chain : List.Chain (· → ·) a (b :: l)) (h_last : getLastD l b → a) : TFAE (a :: b :: l) := by induction l generalizing a b with
| nil => simp_all [tfae_cons_cons, iff_def] | cons c l IH =>
Mathlib/Data/List/TFAE.lean
56
57
/- Copyright (c) 2024 Brendan Murphy. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Brendan Murphy -/ import Mathlib.RingTheory.Regular.IsSMulRegular import Mathlib.RingTheory.Artinian.Module import Mathlib.RingTheory.Nakayama import Mathlib.Algebra.Equiv.TransferInstance import Mathlib.RingTheory.LocalRing.MaximalIdeal.Basic import Mathlib.RingTheory.Noetherian.Basic /-! # Regular sequences and weakly regular sequences The notion of a regular sequence is fundamental in commutative algebra. Properties of regular sequences encode information about singularities of a ring and regularity of a sequence can be tested homologically. However the notion of a regular sequence is only really sensible for Noetherian local rings. TODO: Koszul regular sequences, H_1-regular sequences, quasi-regular sequences, depth. ## Tags module, regular element, regular sequence, commutative algebra -/ universe u v open scoped Pointwise variable {R S M M₂ M₃ M₄ : Type*} namespace Ideal variable [Semiring R] [Semiring S] /-- The ideal generated by a list of elements. -/ abbrev ofList (rs : List R) := span { r | r ∈ rs } @[simp] lemma ofList_nil : (ofList [] : Ideal R) = ⊥ := have : { r | r ∈ [] } = ∅ := Set.eq_empty_of_forall_not_mem (fun _ => List.not_mem_nil) Eq.trans (congrArg span this) span_empty @[simp] lemma ofList_append (rs₁ rs₂ : List R) : ofList (rs₁ ++ rs₂) = ofList rs₁ ⊔ ofList rs₂ := have : { r | r ∈ rs₁ ++ rs₂ } = _ := Set.ext (fun _ => List.mem_append) Eq.trans (congrArg span this) (span_union _ _) lemma ofList_singleton (r : R) : ofList [r] = span {r} := congrArg span (Set.ext fun _ => List.mem_singleton) @[simp] lemma ofList_cons (r : R) (rs : List R) : ofList (r::rs) = span {r} ⊔ ofList rs := Eq.trans (ofList_append [r] rs) (congrArg (· ⊔ _) (ofList_singleton r)) @[simp] lemma map_ofList (f : R →+* S) (rs : List R) : map f (ofList rs) = ofList (rs.map f) := Eq.trans (map_span f { r | r ∈ rs }) <| congrArg span <| Set.ext (fun _ => List.mem_map.symm) lemma ofList_cons_smul {R} [CommSemiring R] (r : R) (rs : List R) {M} [AddCommMonoid M] [Module R M] (N : Submodule R M) : ofList (r :: rs) • N = r • N ⊔ ofList rs • N := by rw [ofList_cons, Submodule.sup_smul, Submodule.ideal_span_singleton_smul] end Ideal namespace Submodule lemma smul_top_le_comap_smul_top [Semiring R] [AddCommMonoid M] [AddCommMonoid M₂] [Module R M] [Module R M₂] (I : Ideal R) (f : M →ₗ[R] M₂) : I • ⊀ ≀ comap f (I • ⊀) := map_le_iff_le_comap.mp <| le_of_eq_of_le (map_smul'' _ _ _) <| smul_mono_right _ le_top variable (M) [CommRing R] [AddCommGroup M] [AddCommGroup M₂] [Module R M] [Module R M₂] (r : R) (rs : List R) /-- The equivalence between M â§ž (r₀, r₁, 
, rₙ)M and (M â§ž r₀M) â§ž (r₁, 
, rₙ) (M â§ž r₀M). -/ def quotOfListConsSMulTopEquivQuotSMulTopInner : (M â§ž (Ideal.ofList (r :: rs) • ⊀ : Submodule R M)) ≃ₗ[R] QuotSMulTop r M â§ž (Ideal.ofList rs • ⊀ : Submodule R (QuotSMulTop r M)) := quotEquivOfEq _ _ (Ideal.ofList_cons_smul r rs ⊀) ≪≫ₗ (quotientQuotientEquivQuotientSup (r • ⊀) (Ideal.ofList rs • ⊀)).symm ≪≫ₗ quotEquivOfEq _ _ (by rw [map_smul'', map_top, range_mkQ]) /-- The equivalence between M â§ž (r₀, r₁, 
, rₙ)M and (M â§ž (r₁, 
, rₙ)) â§ž r₀ (M â§ž (r₁, 
, rₙ)). -/ def quotOfListConsSMulTopEquivQuotSMulTopOuter : (M â§ž (Ideal.ofList (r :: rs) • ⊀ : Submodule R M)) ≃ₗ[R] QuotSMulTop r (M â§ž (Ideal.ofList rs • ⊀ : Submodule R M)) := quotEquivOfEq _ _ (Eq.trans (Ideal.ofList_cons_smul r rs ⊀) (sup_comm _ _)) ≪≫ₗ (quotientQuotientEquivQuotientSup (Ideal.ofList rs • ⊀) (r • ⊀)).symm ≪≫ₗ quotEquivOfEq _ _ (by rw [map_pointwise_smul, map_top, range_mkQ]) variable {M} lemma quotOfListConsSMulTopEquivQuotSMulTopInner_naturality (f : M →ₗ[R] M₂) : (quotOfListConsSMulTopEquivQuotSMulTopInner M₂ r rs).toLinearMap ∘ₗ mapQ _ _ _ (smul_top_le_comap_smul_top (Ideal.ofList (r :: rs)) f) = mapQ _ _ _ (smul_top_le_comap_smul_top _ (QuotSMulTop.map r f)) ∘ₗ (quotOfListConsSMulTopEquivQuotSMulTopInner M r rs).toLinearMap := quot_hom_ext _ _ _ fun _ => rfl lemma top_eq_ofList_cons_smul_iff : (⊀ : Submodule R M) = Ideal.ofList (r :: rs) • ⊀ ↔ (⊀ : Submodule R (QuotSMulTop r M)) = Ideal.ofList rs • ⊀ := by conv => congr <;> rw [eq_comm, ← subsingleton_quotient_iff_eq_top] exact (quotOfListConsSMulTopEquivQuotSMulTopInner M r rs).toEquiv.subsingleton_congr end Submodule namespace RingTheory.Sequence open scoped TensorProduct List open Function Submodule QuotSMulTop variable (S M) section Definitions /- In theory, regularity of `rs : List α` on `M` makes sense as soon as `[Monoid α]`, `[AddCommGroup M]`, and `[DistribMulAction α M]`. Instead of `Ideal.ofList (rs.take i) • (⊀ : Submodule R M)` we use `⹆ (j : Fin i), rs[j] • (⊀ : AddSubgroup M)`. However it's not clear that this is a useful generalization. If we add the assumption `[SMulCommClass α α M]` this is essentially the same as focusing on the commutative ring case, by passing to the monoid ring `â„€[abelianization of α]`. -/ variable [CommRing R] [AddCommGroup M] [Module R M] open Ideal /-- A sequence `[r₁, 
, rₙ]` is weakly regular on `M` iff `ráµ¢` is regular on `Mâ§ž(r₁, 
, rᵢ₋₁)M` for all `1 ≀ i ≀ n`. -/ @[mk_iff] structure IsWeaklyRegular (rs : List R) : Prop where regular_mod_prev : ∀ i (h : i < rs.length), IsSMulRegular (M â§ž (ofList (rs.take i) • ⊀ : Submodule R M)) rs[i] lemma isWeaklyRegular_iff_Fin (rs : List R) : IsWeaklyRegular M rs ↔ ∀ (i : Fin rs.length), IsSMulRegular (M â§ž (ofList (rs.take i) • ⊀ : Submodule R M)) rs[i] := Iff.trans (isWeaklyRegular_iff M rs) (Iff.symm Fin.forall_iff) /-- A weakly regular sequence `rs` on `M` is regular if also `M/rsM ≠ 0`. -/ @[mk_iff] structure IsRegular (rs : List R) : Prop extends IsWeaklyRegular M rs where top_ne_smul : (⊀ : Submodule R M) ≠ Ideal.ofList rs • ⊀ end Definitions section Congr variable {S M} [CommRing R] [CommRing S] [AddCommGroup M] [AddCommGroup M₂] [Module R M] [Module S M₂] {σ : R →+* S} {σ' : S →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ] open DistribMulAction AddSubgroup in private lemma _root_.AddHom.map_smul_top_toAddSubgroup_of_surjective {f : M →+ M₂} {as : List R} {bs : List S} (hf : Function.Surjective f) (h : List.Forall₂ (fun r s => ∀ x, f (r • x) = s • f x) as bs) : (Ideal.ofList as • ⊀ : Submodule R M).toAddSubgroup.map f = (Ideal.ofList bs • ⊀ : Submodule S M₂).toAddSubgroup := by induction h with | nil => convert AddSubgroup.map_bot f using 1 <;> rw [Ideal.ofList_nil, bot_smul, bot_toAddSubgroup] | @cons r s _ _ h _ ih => conv => congr <;> rw [Ideal.ofList_cons, sup_smul, sup_toAddSubgroup, ideal_span_singleton_smul, pointwise_smul_toAddSubgroup, top_toAddSubgroup, pointwise_smul_def] apply DFunLike.ext (f.comp (toAddMonoidEnd R M r)) ((toAddMonoidEnd S M₂ s).comp f) at h rw [AddSubgroup.map_sup, ih, map_map, h, ← map_map, map_top_of_surjective f hf] lemma _root_.AddEquiv.isWeaklyRegular_congr {e : M ≃+ M₂} {as bs} (h : List.Forall₂ (fun (r : R) (s : S) => ∀ x, e (r • x) = s • e x) as bs) : IsWeaklyRegular M as ↔ IsWeaklyRegular M₂ bs := by conv => congr <;> rw [isWeaklyRegular_iff_Fin] let e' i : (M â§ž (Ideal.ofList (as.take i) • ⊀ : Submodule R M)) ≃+ M₂ â§ž (Ideal.ofList (bs.take i) • ⊀ : Submodule S M₂) := QuotientAddGroup.congr _ _ e <| AddHom.map_smul_top_toAddSubgroup_of_surjective e.surjective <| List.forall₂_take i h refine (finCongr h.length_eq).forall_congr @fun _ => (e' _).isSMulRegular_congr ?_ exact (mkQ_surjective _).forall.mpr fun _ => congrArg (mkQ _) (h.get _ _ _) lemma _root_.LinearEquiv.isWeaklyRegular_congr' (e : M ≃ₛₗ[σ] M₂) (rs : List R) : IsWeaklyRegular M rs ↔ IsWeaklyRegular M₂ (rs.map σ) := e.toAddEquiv.isWeaklyRegular_congr <| List.forall₂_map_right_iff.mpr <| List.forall₂_same.mpr fun r _ x => e.map_smul' r x lemma _root_.LinearEquiv.isWeaklyRegular_congr [Module R M₂] (e : M ≃ₗ[R] M₂) (rs : List R) : IsWeaklyRegular M rs ↔ IsWeaklyRegular M₂ rs := Iff.trans (e.isWeaklyRegular_congr' rs) <| iff_of_eq <| congrArg _ rs.map_id lemma _root_.AddEquiv.isRegular_congr {e : M ≃+ M₂} {as bs} (h : List.Forall₂ (fun (r : R) (s : S) => ∀ x, e (r • x) = s • e x) as bs) : IsRegular M as ↔ IsRegular M₂ bs := by conv => congr <;> rw [isRegular_iff, ne_eq, eq_comm, ← subsingleton_quotient_iff_eq_top] let e' := QuotientAddGroup.congr _ _ e <| AddHom.map_smul_top_toAddSubgroup_of_surjective e.surjective h exact and_congr (e.isWeaklyRegular_congr h) e'.subsingleton_congr.not lemma _root_.LinearEquiv.isRegular_congr' (e : M ≃ₛₗ[σ] M₂) (rs : List R) : IsRegular M rs ↔ IsRegular M₂ (rs.map σ) := e.toAddEquiv.isRegular_congr <| List.forall₂_map_right_iff.mpr <| List.forall₂_same.mpr fun r _ x => e.map_smul' r x lemma _root_.LinearEquiv.isRegular_congr [Module R M₂] (e : M ≃ₗ[R] M₂) (rs : List R) : IsRegular M rs ↔ IsRegular M₂ rs := Iff.trans (e.isRegular_congr' rs) <| iff_of_eq <| congrArg _ rs.map_id end Congr lemma isWeaklyRegular_map_algebraMap_iff [CommRing R] [CommRing S] [Algebra R S] [AddCommGroup M] [Module R M] [Module S M] [IsScalarTower R S M] (rs : List R) : IsWeaklyRegular M (rs.map (algebraMap R S)) ↔ IsWeaklyRegular M rs := (AddEquiv.refl M).isWeaklyRegular_congr <| List.forall₂_map_left_iff.mpr <| List.forall₂_same.mpr fun r _ => algebraMap_smul S r variable [CommRing R] [AddCommGroup M] [AddCommGroup M₂] [AddCommGroup M₃] [AddCommGroup M₄] [Module R M] [Module R M₂] [Module R M₃] [Module R M₄] @[simp] lemma isWeaklyRegular_cons_iff (r : R) (rs : List R) : IsWeaklyRegular M (r :: rs) ↔ IsSMulRegular M r ∧ IsWeaklyRegular (QuotSMulTop r M) rs := have := Eq.trans (congrArg (· • ⊀) Ideal.ofList_nil) (bot_smul ⊀) let e i := quotOfListConsSMulTopEquivQuotSMulTopInner M r (rs.take i) Iff.trans (isWeaklyRegular_iff_Fin _ _) <| Iff.trans Fin.forall_iff_succ <| and_congr ((quotEquivOfEqBot _ this).isSMulRegular_congr r) <| Iff.trans (forall_congr' fun i => (e i).isSMulRegular_congr (rs.get i)) (isWeaklyRegular_iff_Fin _ _).symm lemma isWeaklyRegular_cons_iff' (r : R) (rs : List R) : IsWeaklyRegular M (r :: rs) ↔ IsSMulRegular M r ∧ IsWeaklyRegular (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r}))) := Iff.trans (isWeaklyRegular_cons_iff M r rs) <| and_congr_right' <| Iff.symm <| isWeaklyRegular_map_algebraMap_iff (R â§ž Ideal.span {r}) _ rs @[simp] lemma isRegular_cons_iff (r : R) (rs : List R) : IsRegular M (r :: rs) ↔ IsSMulRegular M r ∧ IsRegular (QuotSMulTop r M) rs := by rw [isRegular_iff, isRegular_iff, isWeaklyRegular_cons_iff M r rs, ne_eq, top_eq_ofList_cons_smul_iff, and_assoc] lemma isRegular_cons_iff' (r : R) (rs : List R) : IsRegular M (r :: rs) ↔ IsSMulRegular M r ∧ IsRegular (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r}))) := by conv => congr <;> rw [isRegular_iff, ne_eq] rw [isWeaklyRegular_cons_iff', ← restrictScalars_inj R (R â§ž _), ← Ideal.map_ofList, ← Ideal.Quotient.algebraMap_eq, Ideal.smul_restrictScalars, restrictScalars_top, top_eq_ofList_cons_smul_iff, and_assoc] variable {M} namespace IsWeaklyRegular variable (R M) in @[simp] lemma nil : IsWeaklyRegular M ([] : List R) := .mk (False.elim <| Nat.not_lt_zero · ·) lemma cons {r : R} {rs : List R} (h1 : IsSMulRegular M r) (h2 : IsWeaklyRegular (QuotSMulTop r M) rs) : IsWeaklyRegular M (r :: rs) := (isWeaklyRegular_cons_iff M r rs).mpr ⟹h1, h2⟩ lemma cons' {r : R} {rs : List R} (h1 : IsSMulRegular M r) (h2 : IsWeaklyRegular (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r})))) : IsWeaklyRegular M (r :: rs) := (isWeaklyRegular_cons_iff' M r rs).mpr ⟹h1, h2⟩ /-- Weakly regular sequences can be inductively characterized by: * The empty sequence is weakly regular on any module. * If `r` is regular on `M` and `rs` is a weakly regular sequence on `Mâ§žrM` then the sequence obtained from `rs` by prepending `r` is weakly regular on `M`. This is the induction principle produced by the inductive definition above. The motive will usually be valued in `Prop`, but `Sort*` works too. -/ @[induction_eliminator] def recIterModByRegular {motive : (M : Type v) → [AddCommGroup M] → [Module R M] → (rs : List R) → IsWeaklyRegular M rs → Sort*} (nil : (M : Type v) → [AddCommGroup M] → [Module R M] → motive M [] (nil R M)) (cons : {M : Type v} → [AddCommGroup M] → [Module R M] → (r : R) → (rs : List R) → (h1 : IsSMulRegular M r) → (h2 : IsWeaklyRegular (QuotSMulTop r M) rs) → (ih : motive (QuotSMulTop r M) rs h2) → motive M (r :: rs) (cons h1 h2)) : {M : Type v} → [AddCommGroup M] → [Module R M] → {rs : List R} → (h : IsWeaklyRegular M rs) → motive M rs h | M, _, _, [], _ => nil M | M, _, _, r :: rs, h => let ⟹h1, h2⟩ := (isWeaklyRegular_cons_iff M r rs).mp h cons r rs h1 h2 (recIterModByRegular nil cons h2) /-- A simplified version of `IsWeaklyRegular.recIterModByRegular` where the motive is not allowed to depend on the proof of `IsWeaklyRegular`. -/ def ndrecIterModByRegular {motive : (M : Type v) → [AddCommGroup M] → [Module R M] → (rs : List R) → Sort*} (nil : (M : Type v) → [AddCommGroup M] → [Module R M] → motive M []) (cons : {M : Type v} → [AddCommGroup M] → [Module R M] → (r : R) → (rs : List R) → IsSMulRegular M r → IsWeaklyRegular (QuotSMulTop r M) rs → motive (QuotSMulTop r M) rs → motive M (r :: rs)) {M} [AddCommGroup M] [Module R M] {rs} : IsWeaklyRegular M rs → motive M rs := recIterModByRegular (motive := fun M _ _ rs _ => motive M rs) nil cons /-- An alternate induction principle from `IsWeaklyRegular.recIterModByRegular` where we mod out by successive elements in both the module and the base ring. This is useful for propagating certain properties of the initial `M`, e.g. faithfulness or freeness, throughout the induction. -/ def recIterModByRegularWithRing {motive : (R : Type u) → [CommRing R] → (M : Type v) → [AddCommGroup M] → [Module R M] → (rs : List R) → IsWeaklyRegular M rs → Sort*} (nil : (R : Type u) → [CommRing R] → (M : Type v) → [AddCommGroup M] → [Module R M] → motive R M [] (nil R M)) (cons : {R : Type u} → [CommRing R] → {M : Type v} → [AddCommGroup M] → [Module R M] → (r : R) → (rs : List R) → (h1 : IsSMulRegular M r) → (h2 : IsWeaklyRegular (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r})))) → (ih : motive (R â§ž Ideal.span {r}) (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r}))) h2) → motive R M (r :: rs) (cons' h1 h2)) : {R : Type u} → [CommRing R] → {M : Type v} → [AddCommGroup M] → [Module R M] → {rs : List R} → (h : IsWeaklyRegular M rs) → motive R M rs h | R, _, M, _, _, [], _ => nil R M | _, _, M, _, _, r :: rs, h => let ⟹h1, h2⟩ := (isWeaklyRegular_cons_iff' M r rs).mp h cons r rs h1 h2 (recIterModByRegularWithRing nil cons h2) termination_by _ _ _ _ _ rs => List.length rs /-- A simplified version of `IsWeaklyRegular.recIterModByRegularWithRing` where the motive is not allowed to depend on the proof of `IsWeaklyRegular`. -/ def ndrecWithRing {motive : (R : Type u) → [CommRing R] → (M : Type v) → [AddCommGroup M] → [Module R M] → (rs : List R) → Sort*} (nil : (R : Type u) → [CommRing R] → (M : Type v) → [AddCommGroup M] → [Module R M] → motive R M []) (cons : {R : Type u} → [CommRing R] → {M : Type v} → [AddCommGroup M] → [Module R M] → (r : R) → (rs : List R) → IsSMulRegular M r → IsWeaklyRegular (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r}))) → motive (R â§ž Ideal.span {r}) (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r}))) → motive R M (r :: rs)) {R} [CommRing R] {M} [AddCommGroup M] [Module R M] {rs} : IsWeaklyRegular M rs → motive R M rs := recIterModByRegularWithRing (motive := fun R _ M _ _ rs _ => motive R M rs) nil cons end IsWeaklyRegular section variable (M) lemma isWeaklyRegular_singleton_iff (r : R) : IsWeaklyRegular M [r] ↔ IsSMulRegular M r := Iff.trans (isWeaklyRegular_cons_iff M r []) (and_iff_left (.nil R _)) lemma isWeaklyRegular_append_iff (rs₁ rs₂ : List R) : IsWeaklyRegular M (rs₁ ++ rs₂) ↔ IsWeaklyRegular M rs₁ ∧ IsWeaklyRegular (M â§ž (Ideal.ofList rs₁ • ⊀ : Submodule R M)) rs₂ := by induction rs₁ generalizing M with | nil => refine Iff.symm <| Iff.trans (and_iff_right (.nil R M)) ?_ refine (quotEquivOfEqBot _ ?_).isWeaklyRegular_congr rs₂ rw [Ideal.ofList_nil, bot_smul] | cons r rs₁ ih => let e := quotOfListConsSMulTopEquivQuotSMulTopInner M r rs₁ rw [List.cons_append, isWeaklyRegular_cons_iff, isWeaklyRegular_cons_iff, ih, ← and_assoc, ← e.isWeaklyRegular_congr rs₂] lemma isWeaklyRegular_append_iff' (rs₁ rs₂ : List R) : IsWeaklyRegular M (rs₁ ++ rs₂) ↔ IsWeaklyRegular M rs₁ ∧ IsWeaklyRegular (M â§ž (Ideal.ofList rs₁ • ⊀ : Submodule R M)) (rs₂.map (Ideal.Quotient.mk (Ideal.ofList rs₁))) := Iff.trans (isWeaklyRegular_append_iff M rs₁ rs₂) <| and_congr_right' <| Iff.symm <| isWeaklyRegular_map_algebraMap_iff (R â§ž Ideal.ofList rs₁) _ rs₂ end namespace IsRegular variable (R M) in lemma nil [Nontrivial M] : IsRegular M ([] : List R) where toIsWeaklyRegular := IsWeaklyRegular.nil R M top_ne_smul h := by rw [Ideal.ofList_nil, bot_smul, eq_comm, subsingleton_iff_bot_eq_top] at h exact not_subsingleton M ((Submodule.subsingleton_iff _).mp h) lemma cons {r : R} {rs : List R} (h1 : IsSMulRegular M r) (h2 : IsRegular (QuotSMulTop r M) rs) : IsRegular M (r :: rs) := (isRegular_cons_iff M r rs).mpr ⟹h1, h2⟩ lemma cons' {r : R} {rs : List R} (h1 : IsSMulRegular M r) (h2 : IsRegular (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r})))) : IsRegular M (r :: rs) := (isRegular_cons_iff' M r rs).mpr ⟹h1, h2⟩ /-- Regular sequences can be inductively characterized by: * The empty sequence is regular on any nonzero module. * If `r` is regular on `M` and `rs` is a regular sequence on `Mâ§žrM` then the sequence obtained from `rs` by prepending `r` is regular on `M`. This is the induction principle produced by the inductive definition above. The motive will usually be valued in `Prop`, but `Sort*` works too. -/ @[induction_eliminator] def recIterModByRegular {motive : (M : Type v) → [AddCommGroup M] → [Module R M] → (rs : List R) → IsRegular M rs → Sort*} (nil : (M : Type v) → [AddCommGroup M] → [Module R M] → [Nontrivial M] → motive M [] (nil R M)) (cons : {M : Type v} → [AddCommGroup M] → [Module R M] → (r : R) → (rs : List R) → (h1 : IsSMulRegular M r) → (h2 : IsRegular (QuotSMulTop r M) rs) → (ih : motive (QuotSMulTop r M) rs h2) → motive M (r :: rs) (cons h1 h2)) {M} [AddCommGroup M] [Module R M] {rs} (h : IsRegular M rs) : motive M rs h := h.toIsWeaklyRegular.recIterModByRegular (motive := fun N _ _ rs' h' => ∀ h'', motive N rs' ⟹h', h''⟩) (fun N _ _ h' => haveI := (nontrivial_iff R).mp (nontrivial_of_ne _ _ h'); nil N) (fun r rs' h1 h2 h3 h4 => have ⟹h5, h6⟩ := (isRegular_cons_iff _ _ _).mp ⟹h2.cons h1, h4⟩ cons r rs' h5 h6 (h3 h6.top_ne_smul)) h.top_ne_smul /-- A simplified version of `IsRegular.recIterModByRegular` where the motive is not allowed to depend on the proof of `IsRegular`. -/ def ndrecIterModByRegular {motive : (M : Type v) → [AddCommGroup M] → [Module R M] → (rs : List R) → Sort*} (nil : (M : Type v) → [AddCommGroup M] → [Module R M] → [Nontrivial M] → motive M []) (cons : {M : Type v} → [AddCommGroup M] → [Module R M] → (r : R) → (rs : List R) → IsSMulRegular M r → IsRegular (QuotSMulTop r M) rs → motive (QuotSMulTop r M) rs → motive M (r :: rs)) {M} [AddCommGroup M] [Module R M] {rs} : IsRegular M rs → motive M rs := recIterModByRegular (motive := fun M _ _ rs _ => motive M rs) nil cons /-- An alternate induction principle from `IsRegular.recIterModByRegular` where we mod out by successive elements in both the module and the base ring. This is useful for propagating certain properties of the initial `M`, e.g. faithfulness or freeness, throughout the induction. -/ def recIterModByRegularWithRing {motive : (R : Type u) → [CommRing R] → (M : Type v) → [AddCommGroup M] → [Module R M] → (rs : List R) → IsRegular M rs → Sort*} (nil : (R : Type u) → [CommRing R] → (M : Type v) → [AddCommGroup M] → [Module R M] → [Nontrivial M] → motive R M [] (nil R M)) (cons : {R : Type u} → [CommRing R] → {M : Type v} → [AddCommGroup M] → [Module R M] → (r : R) → (rs : List R) → (h1 : IsSMulRegular M r) → (h2 : IsRegular (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r})))) → (ih : motive (R â§ž Ideal.span {r}) (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r}))) h2) → motive R M (r :: rs) (cons' h1 h2)) {R} [CommRing R] {M} [AddCommGroup M] [Module R M] {rs} (h : IsRegular M rs) : motive R M rs h := h.toIsWeaklyRegular.recIterModByRegularWithRing (motive := fun R _ N _ _ rs' h' => ∀ h'', motive R N rs' ⟹h', h''⟩) (fun R _ N _ _ h' => haveI := (nontrivial_iff R).mp (nontrivial_of_ne _ _ h'); nil R N) (fun r rs' h1 h2 h3 h4 => have ⟹h5, h6⟩ := (isRegular_cons_iff' _ _ _).mp ⟹h2.cons' h1, h4⟩ cons r rs' h5 h6 <| h3 h6.top_ne_smul) h.top_ne_smul /-- A simplified version of `IsRegular.recIterModByRegularWithRing` where the motive is not allowed to depend on the proof of `IsRegular`. -/ def ndrecIterModByRegularWithRing {motive : (R : Type u) → [CommRing R] → (M : Type v) → [AddCommGroup M] → [Module R M] → (rs : List R) → Sort*} (nil : (R : Type u) → [CommRing R] → (M : Type v) → [AddCommGroup M] → [Module R M] → [Nontrivial M] → motive R M []) (cons : {R : Type u} → [CommRing R] → {M : Type v} → [AddCommGroup M] → [Module R M] → (r : R) → (rs : List R) → IsSMulRegular M r → IsRegular (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r}))) → motive (R â§ž Ideal.span {r}) (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r}))) → motive R M (r :: rs)) {R} [CommRing R] {M} [AddCommGroup M] [Module R M] {rs} : IsRegular M rs → motive R M rs := recIterModByRegularWithRing (motive := fun R _ M _ _ rs _ => motive R M rs) nil cons lemma quot_ofList_smul_nontrivial {rs : List R} (h : IsRegular M rs) (N : Submodule R M) : Nontrivial (M â§ž Ideal.ofList rs • N) := Submodule.Quotient.nontrivial_of_lt_top _ <| lt_of_le_of_lt (smul_mono_right _ le_top) h.top_ne_smul.symm.lt_top lemma nontrivial {rs : List R} (h : IsRegular M rs) : Nontrivial M := haveI := quot_ofList_smul_nontrivial h ⊀ (mkQ_surjective (Ideal.ofList rs • ⊀ : Submodule R M)).nontrivial end IsRegular lemma isRegular_iff_isWeaklyRegular_of_subset_jacobson_annihilator [Nontrivial M] [Module.Finite R M] {rs : List R} (h : ∀ r ∈ rs, r ∈ Ideal.jacobson (Module.annihilator R M)) : IsRegular M rs ↔ IsWeaklyRegular M rs := Iff.trans (isRegular_iff M rs) <| and_iff_left <| top_ne_ideal_smul_of_le_jacobson_annihilator <| Ideal.span_le.mpr h lemma _root_.IsLocalRing.isRegular_iff_isWeaklyRegular_of_subset_maximalIdeal [IsLocalRing R] [Nontrivial M] [Module.Finite R M] {rs : List R} (h : ∀ r ∈ rs, r ∈ IsLocalRing.maximalIdeal R) : IsRegular M rs ↔ IsWeaklyRegular M rs := have H h' := bot_ne_top.symm <| annihilator_eq_top_iff.mp <| Eq.trans annihilator_top h' isRegular_iff_isWeaklyRegular_of_subset_jacobson_annihilator fun r hr => IsLocalRing.jacobson_eq_maximalIdeal (Module.annihilator R M) H ▾ h r hr open IsWeaklyRegular IsArtinian in lemma eq_nil_of_isRegular_on_artinian [IsArtinian R M] : {rs : List R} → IsRegular M rs → rs = [] | [], _ => rfl | r :: rs, h => by rw [isRegular_iff, ne_comm, ← lt_top_iff_ne_top, Ideal.ofList_cons, sup_smul, ideal_span_singleton_smul, isWeaklyRegular_cons_iff] at h refine absurd ?_ (ne_of_lt (lt_of_le_of_lt le_sup_left h.right)) exact Eq.trans (Submodule.map_top _) <| LinearMap.range_eq_top.mpr <| surjective_of_injective_endomorphism (LinearMap.lsmul R M r) h.left.left lemma IsWeaklyRegular.isWeaklyRegular_lTensor [Module.Flat R M₂] {rs : List R} (h : IsWeaklyRegular M rs) : IsWeaklyRegular (M₂ ⊗[R] M) rs := by induction h with | nil N => exact nil R (M₂ ⊗[R] N) | @cons N _ _ r rs' h1 _ ih => let e := tensorQuotSMulTopEquivQuotSMulTop r M₂ N exact ((e.isWeaklyRegular_congr rs').mp ih).cons (h1.lTensor M₂) lemma IsWeaklyRegular.isWeaklyRegular_rTensor [Module.Flat R M₂] {rs : List R} (h : IsWeaklyRegular M rs) : IsWeaklyRegular (M ⊗[R] M₂) rs := by induction h with | nil N => exact nil R (N ⊗[R] M₂) | @cons N _ _ r rs' h1 _ ih => let e := quotSMulTopTensorEquivQuotSMulTop r M₂ N exact ((e.isWeaklyRegular_congr rs').mp ih).cons (h1.rTensor M₂) -- TODO: apply the above to localization and completion (Corollary 1.1.3 in B&H) lemma map_first_exact_on_four_term_right_exact_of_isSMulRegular_last {rs : List R} {f₁ : M →ₗ[R] M₂} {f₂ : M₂ →ₗ[R] M₃} {f₃ : M₃ →ₗ[R] M₄} (h₁₂ : Exact f₁ f₂) (h₂₃ : Exact f₂ f₃) (h₃ : Surjective f₃) (h₄ : IsWeaklyRegular M₄ rs) : Exact (mapQ _ _ _ (smul_top_le_comap_smul_top (Ideal.ofList rs) f₁)) (mapQ _ _ _ (smul_top_le_comap_smul_top (Ideal.ofList rs) f₂)) := by induction h₄ generalizing M M₂ M₃ with | nil => apply (Exact.iff_of_ladder_linearEquiv ?_ ?_).mp h₁₂ any_goals exact quotEquivOfEqBot _ <| Eq.trans (congrArg (· • ⊀) Ideal.ofList_nil) (bot_smul ⊀) all_goals exact quot_hom_ext _ _ _ fun _ => rfl | cons r rs h₄ _ ih => specialize ih (map_first_exact_on_four_term_exact_of_isSMulRegular_last h₁₂ h₂₃ h₄) (map_exact r h₂₃ h₃) (map_surjective r h₃) have H₁ := quotOfListConsSMulTopEquivQuotSMulTopInner_naturality r rs f₁ have H₂ := quotOfListConsSMulTopEquivQuotSMulTopInner_naturality r rs f₂ exact (Exact.iff_of_ladder_linearEquiv H₁.symm H₂.symm).mp ih -- todo: modding out a complex by a regular sequence (prop 1.1.5 in B&H) section Perm open LinearMap in private lemma IsWeaklyRegular.swap {a b : R} (h1 : IsWeaklyRegular M [a, b]) (h2 : torsionBy R M b = a • torsionBy R M b → torsionBy R M b = ⊥) : IsWeaklyRegular M [b, a] := by rw [isWeaklyRegular_cons_iff, isWeaklyRegular_singleton_iff] at h1 ⊢ obtain ⟹ha, hb⟩ := h1 rw [← isSMulRegular_iff_torsionBy_eq_bot] at h2 specialize h2 (le_antisymm ?_ (smul_le_self_of_tower a (torsionBy R M b))) · refine le_of_eq_of_le ?_ <| smul_top_inf_eq_smul_of_isSMulRegular_on_quot <| ha.of_injective _ <| ker_eq_bot.mp <| ker_liftQ_eq_bot' _ (lsmul R M b) rfl rw [← (isSMulRegular_on_quot_iff_lsmul_comap_eq _ _).mp hb] exact (inf_eq_right.mpr (ker_le_comap _)).symm · rwa [ha.isSMulRegular_on_quot_iff_smul_top_inf_eq_smul, inf_comm, smul_comm, ← h2.isSMulRegular_on_quot_iff_smul_top_inf_eq_smul, and_iff_left hb] -- TODO: Equivalence of permutability of regular sequences to regularity of -- subsequences and regularity on poly ring. See [07DW] in stacks project -- We need a theory of multivariate polynomial modules first -- This is needed due to a bug in the linter set_option linter.unusedVariables false in lemma IsWeaklyRegular.prototype_perm {rs : List R} (h : IsWeaklyRegular M rs) {rs'} (h'' : rs ~ rs') (h' : ∀ a b rs', (a :: b :: rs') <+~ rs → let K := torsionBy R (M â§ž (Ideal.ofList rs' • ⊀ : Submodule R M)) b K = a • K → K = ⊥) : IsWeaklyRegular M rs' := have H := LinearEquiv.isWeaklyRegular_congr <| quotEquivOfEqBot _ <| Eq.trans (congrArg (· • ⊀) Ideal.ofList_nil) (bot_smul ⊀) (H rs').mp <| (aux [] h'' (.refl rs) (h''.symm.subperm)) <| (H rs).mpr h where aux {rs₁ rs₂} (rs₀ : List R) (h₁₂ : rs₁ ~ rs₂) (H₁ : rs₀ ++ rs₁ <+~ rs) (H₃ : rs₀ ++ rs₂ <+~ rs) (h : IsWeaklyRegular (M â§ž (Ideal.ofList rs₀ • ⊀ : Submodule R M)) rs₁) : IsWeaklyRegular (M â§ž (Ideal.ofList rs₀ • ⊀ : Submodule R M)) rs₂ := by { induction h₁₂ generalizing rs₀ with | nil => exact .nil R _ | cons r _ ih => let e := quotOfListConsSMulTopEquivQuotSMulTopOuter M r rs₀ rw [isWeaklyRegular_cons_iff, ← e.isWeaklyRegular_congr] at h ⊢ refine h.imp_right (ih (r :: rs₀) ?_ ?_) <;> exact List.perm_middle.subperm_right.mp ‹_› | swap a b t => rw [show ∀ x y z, x :: y :: z = [x, y] ++ z from fun _ _ _ => rfl, isWeaklyRegular_append_iff] at h ⊢ have : Ideal.ofList [b, a] = Ideal.ofList [a, b] := congrArg Ideal.span <| Set.ext fun _ => (List.Perm.swap a b []).mem_iff rw [(quotEquivOfEq _ _ (congrArg₂ _ this rfl)).isWeaklyRegular_congr] at h rw [List.append_cons, List.append_cons, List.append_assoc _ [b] [a]] at H₁ apply (List.sublist_append_left (rs₀ ++ [b, a]) _).subperm.trans at H₁ apply List.perm_append_comm.subperm.trans at H₁ exact h.imp_left (swap · (h' b a rs₀ H₁)) | trans h₁₂ _ ih₁₂ ih₂₃ => have H₂ := (h₁₂.append_left rs₀).subperm_right.mp H₁ exact ih₂₃ rs₀ H₂ H₃ (ih₁₂ rs₀ H₁ H₂ h) } -- putting `{rs' : List R}` and `h2` after `h3` would be better for partial -- application, but this argument order seems nicer overall lemma IsWeaklyRegular.of_perm_of_subset_jacobson_annihilator [IsNoetherian R M] {rs rs' : List R} (h1 : IsWeaklyRegular M rs) (h2 : List.Perm rs rs') (h3 : ∀ r ∈ rs, r ∈ (Module.annihilator R M).jacobson) : IsWeaklyRegular M rs' := h1.prototype_perm h2 fun r _ _ h h' => eq_bot_of_eq_pointwise_smul_of_mem_jacobson_annihilator (IsNoetherian.noetherian _) h' (Ideal.jacobson_mono (le_trans -- The named argument `(R := R)` below isn't necessary, but -- typechecking is much slower without it (LinearMap.annihilator_le_of_surjective (R := R) _ (mkQ_surjective _)) (LinearMap.annihilator_le_of_injective _ (injective_subtype _))) (h3 r (h.subset List.mem_cons_self))) end Perm lemma IsRegular.of_perm_of_subset_jacobson_annihilator [IsNoetherian R M] {rs rs' : List R} (h1 : IsRegular M rs) (h2 : List.Perm rs rs') (h3 : ∀ r ∈ rs, r ∈ (Module.annihilator R M).jacobson) : IsRegular M rs' := ⟹h1.toIsWeaklyRegular.of_perm_of_subset_jacobson_annihilator h2 h3, letI := h1.nontrivial top_ne_ideal_smul_of_le_jacobson_annihilator <| Ideal.span_le.mpr (h3 · <| h2.mem_iff.mpr ·)⟩ lemma _root_.IsLocalRing.isWeaklyRegular_of_perm_of_subset_maximalIdeal [IsLocalRing R] [IsNoetherian R M] {rs rs' : List R} (h1 : IsWeaklyRegular M rs) (h2 : List.Perm rs rs')
(h3 : ∀ r ∈ rs, r ∈ IsLocalRing.maximalIdeal R) : IsWeaklyRegular M rs' := IsWeaklyRegular.of_perm_of_subset_jacobson_annihilator h1 h2 fun r hr => IsLocalRing.maximalIdeal_le_jacobson _ (h3 r hr) lemma _root_.IsLocalRing.isRegular_of_perm [IsLocalRing R] [IsNoetherian R M] {rs rs' : List R} (h1 : IsRegular M rs) (h2 : List.Perm rs rs') : IsRegular M rs' := by obtain ⟹h3, h4⟩ := h1 refine ⟹IsLocalRing.isWeaklyRegular_of_perm_of_subset_maximalIdeal h3 h2 ?_, ?_⟩ · intro x (h6 : x ∈ { r | r ∈ rs })
Mathlib/RingTheory/Regular/RegularSequence.lean
661
670
/- 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
Mathlib/Algebra/Lie/IdealOperations.lean
127
127
/- Copyright (c) 2023 Chris Birkbeck. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Birkbeck, Ruben Van de Velde -/ import Mathlib.Analysis.Calculus.ContDiff.Operations import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Shift import Mathlib.Analysis.Calculus.IteratedDeriv.Defs /-! # One-dimensional iterated derivatives This file contains a number of further results on `iteratedDerivWithin` that need more imports than are available in `Mathlib/Analysis/Calculus/IteratedDeriv/Defs.lean`. -/ section one_dimensional variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {R : Type*} [Semiring R] [Module R F] [SMulCommClass 𝕜 R F] [ContinuousConstSMul R F] {n : ℕ} {x : 𝕜} {s : Set 𝕜} (hx : x ∈ s) (h : UniqueDiffOn 𝕜 s) {f g : 𝕜 → F} section theorem iteratedDerivWithin_congr (hfg : Set.EqOn f g s) : Set.EqOn (iteratedDerivWithin n f s) (iteratedDerivWithin n g s) s := by induction n generalizing f g with | zero => rwa [iteratedDerivWithin_zero] | succ n IH => intro y hy rw [iteratedDerivWithin_succ, iteratedDerivWithin_succ] exact derivWithin_congr (IH hfg) (IH hfg hy) include h hx in theorem iteratedDerivWithin_add (hf : ContDiffWithinAt 𝕜 n f s x) (hg : ContDiffWithinAt 𝕜 n g s x) : iteratedDerivWithin n (f + g) s x = iteratedDerivWithin n f s x + iteratedDerivWithin n g s x := by simp_rw [iteratedDerivWithin, iteratedFDerivWithin_add_apply hf hg h hx, ContinuousMultilinearMap.add_apply] theorem iteratedDerivWithin_const_add (hn : 0 < n) (c : F) : iteratedDerivWithin n (fun z => c + f z) s x = iteratedDerivWithin n f s x := by obtain ⟹n, rfl⟩ := n.exists_eq_succ_of_ne_zero hn.ne' rw [iteratedDerivWithin_succ', iteratedDerivWithin_succ'] congr with y exact derivWithin_const_add _ theorem iteratedDerivWithin_const_sub (hn : 0 < n) (c : F) : iteratedDerivWithin n (fun z => c - f z) s x = iteratedDerivWithin n (fun z => -f z) s x := by obtain ⟹n, rfl⟩ := n.exists_eq_succ_of_ne_zero hn.ne' rw [iteratedDerivWithin_succ', iteratedDerivWithin_succ'] congr with y rw [derivWithin.neg] exact derivWithin_const_sub _ @[deprecated (since := "2024-12-10")] alias iteratedDerivWithin_const_neg := iteratedDerivWithin_const_sub include h hx in theorem iteratedDerivWithin_const_smul (c : R) (hf : ContDiffWithinAt 𝕜 n f s x) : iteratedDerivWithin n (c • f) s x = c • iteratedDerivWithin n f s x := by simp_rw [iteratedDerivWithin] rw [iteratedFDerivWithin_const_smul_apply hf h hx] simp only [ContinuousMultilinearMap.smul_apply] include h hx in theorem iteratedDerivWithin_const_mul (c : 𝕜) {f : 𝕜 → 𝕜} (hf : ContDiffWithinAt 𝕜 n f s x) : iteratedDerivWithin n (fun z => c * f z) s x = c * iteratedDerivWithin n f s x := by simpa using iteratedDerivWithin_const_smul (F := 𝕜) hx h c hf variable (f) in omit h hx in theorem iteratedDerivWithin_neg : iteratedDerivWithin n (-f) s x = -iteratedDerivWithin n f s x := by induction n generalizing x with | zero => simp | succ n IH => simp only [iteratedDerivWithin_succ, derivWithin_neg] rw [← derivWithin.neg] congr with y exact IH variable (f) in theorem iteratedDerivWithin_neg' : iteratedDerivWithin n (fun z => -f z) s x = -iteratedDerivWithin n f s x := iteratedDerivWithin_neg f include h hx theorem iteratedDerivWithin_sub (hf : ContDiffWithinAt 𝕜 n f s x) (hg : ContDiffWithinAt 𝕜 n g s x) : iteratedDerivWithin n (f - g) s x = iteratedDerivWithin n f s x - iteratedDerivWithin n g s x := by rw [sub_eq_add_neg, sub_eq_add_neg, Pi.neg_def, iteratedDerivWithin_add hx h hf hg.neg, iteratedDerivWithin_neg'] theorem iteratedDerivWithin_comp_const_smul (hf : ContDiffOn 𝕜 n f s) (c : 𝕜)
(hs : Set.MapsTo (c * ·) s s) : iteratedDerivWithin n (fun x => f (c * x)) s x = c ^ n • iteratedDerivWithin n f s (c * x) := by induction n generalizing x with
Mathlib/Analysis/Calculus/IteratedDeriv/Lemmas.lean
102
104
/- Copyright (c) 2020 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.RingTheory.IsTensorProduct /-! # Base change of polynomial algebras Given `[CommSemiring R] [Semiring A] [Algebra R A]` we show `A[X] ≃ₐ[R] (A ⊗[R] R[X])`. -/ -- This file should not become entangled with `RingTheory/MatrixAlgebra`. assert_not_exists Matrix universe u v w open Polynomial TensorProduct open Algebra.TensorProduct (algHomOfLinearMapTensorProduct includeLeft) noncomputable section variable (R A : Type*) variable [CommSemiring R] variable [Semiring A] [Algebra R A] namespace PolyEquivTensor /-- (Implementation detail). The function underlying `A ⊗[R] R[X] →ₐ[R] A[X]`, as a bilinear function of two arguments. -/ def toFunBilinear : A →ₗ[A] R[X] →ₗ[R] A[X] := LinearMap.toSpanSingleton A _ (aeval (Polynomial.X : A[X])).toLinearMap theorem toFunBilinear_apply_apply (a : A) (p : R[X]) : toFunBilinear R A a p = a • (aeval X) p := rfl @[simp] theorem toFunBilinear_apply_eq_smul (a : A) (p : R[X]) : toFunBilinear R A a p = a • p.map (algebraMap R A) := rfl theorem toFunBilinear_apply_eq_sum (a : A) (p : R[X]) : toFunBilinear R A a p = p.sum fun n r ↩ monomial n (a * algebraMap R A r) := by conv_lhs => rw [toFunBilinear_apply_eq_smul, ← p.sum_monomial_eq, sum, Polynomial.map_sum] simp [Finset.smul_sum, sum, ← smul_eq_mul] /-- (Implementation detail). The function underlying `A ⊗[R] R[X] →ₐ[R] A[X]`, as a linear map. -/ def toFunLinear : A ⊗[R] R[X] →ₗ[R] A[X] := TensorProduct.lift (toFunBilinear R A) @[simp] theorem toFunLinear_tmul_apply (a : A) (p : R[X]) : toFunLinear R A (a ⊗ₜ[R] p) = toFunBilinear R A a p := rfl -- We apparently need to provide the decidable instance here -- in order to successfully rewrite by this lemma. theorem toFunLinear_mul_tmul_mul_aux_1 (p : R[X]) (k : ℕ) (h : Decidable ¬p.coeff k = 0) (a : A) : ite (¬coeff p k = 0) (a * (algebraMap R A) (coeff p k)) 0 = a * (algebraMap R A) (coeff p k) := by classical split_ifs <;> simp [*] theorem toFunLinear_mul_tmul_mul_aux_2 (k : ℕ) (a₁ a₂ : A) (p₁ p₂ : R[X]) : a₁ * a₂ * (algebraMap R A) ((p₁ * p₂).coeff k) = (Finset.antidiagonal k).sum fun x => a₁ * (algebraMap R A) (coeff p₁ x.1) * (a₂ * (algebraMap R A) (coeff p₂ x.2)) := by simp_rw [mul_assoc, Algebra.commutes, ← Finset.mul_sum, mul_assoc, ← Finset.mul_sum] congr simp_rw [Algebra.commutes (coeff p₂ _), coeff_mul, map_sum, RingHom.map_mul] theorem toFunLinear_mul_tmul_mul (a₁ a₂ : A) (p₁ p₂ : R[X]) : (toFunLinear R A) ((a₁ * a₂) ⊗ₜ[R] (p₁ * p₂)) = (toFunLinear R A) (a₁ ⊗ₜ[R] p₁) * (toFunLinear R A) (a₂ ⊗ₜ[R] p₂) := by classical simp only [toFunLinear_tmul_apply, toFunBilinear_apply_eq_sum] ext k simp_rw [coeff_sum, coeff_monomial, sum_def, Finset.sum_ite_eq', mem_support_iff, Ne] conv_rhs => rw [coeff_mul] simp_rw [finset_sum_coeff, coeff_monomial, Finset.sum_ite_eq', mem_support_iff, Ne, mul_ite, mul_zero, ite_mul, zero_mul] simp_rw [← ite_zero_mul (¬coeff p₁ _ = 0) (a₁ * (algebraMap R A) (coeff p₁ _))] simp_rw [← mul_ite_zero (¬coeff p₂ _ = 0) _ (_ * _)] simp_rw [toFunLinear_mul_tmul_mul_aux_1, toFunLinear_mul_tmul_mul_aux_2] theorem toFunLinear_one_tmul_one : toFunLinear R A (1 ⊗ₜ[R] 1) = 1 := by rw [toFunLinear_tmul_apply, toFunBilinear_apply_apply, Polynomial.aeval_one, one_smul] /-- (Implementation detail). The algebra homomorphism `A ⊗[R] R[X] →ₐ[R] A[X]`. -/ def toFunAlgHom : A ⊗[R] R[X] →ₐ[R] A[X] := algHomOfLinearMapTensorProduct (toFunLinear R A) (toFunLinear_mul_tmul_mul R A) (toFunLinear_one_tmul_one R A) @[simp] theorem toFunAlgHom_apply_tmul_eq_smul (a : A) (p : R[X]) : toFunAlgHom R A (a ⊗ₜ[R] p) = a • p.map (algebraMap R A) := rfl theorem toFunAlgHom_apply_tmul (a : A) (p : R[X]) : toFunAlgHom R A (a ⊗ₜ[R] p) = p.sum fun n r => monomial n (a * (algebraMap R A) r) := toFunBilinear_apply_eq_sum R A _ _ /-- (Implementation detail.) The bare function `A[X] → A ⊗[R] R[X]`. (We don't need to show that it's an algebra map, thankfully --- just that it's an inverse.) -/ def invFun (p : A[X]) : A ⊗[R] R[X] := p.eval₂ (includeLeft : A →ₐ[R] A ⊗[R] R[X]) ((1 : A) ⊗ₜ[R] (X : R[X])) @[simp] theorem invFun_add {p q} : invFun R A (p + q) = invFun R A p + invFun R A q := by simp only [invFun, eval₂_add] theorem invFun_monomial (n : ℕ) (a : A) : invFun R A (monomial n a) = (a ⊗ₜ[R] 1) * 1 ⊗ₜ[R] X ^ n := eval₂_monomial _ _ theorem left_inv (x : A ⊗ R[X]) : invFun R A ((toFunAlgHom R A) x) = x := by refine TensorProduct.induction_on x ?_ ?_ ?_ · simp [invFun] · intro a p dsimp only [invFun] rw [toFunAlgHom_apply_tmul, eval₂_sum] simp_rw [eval₂_monomial, AlgHom.coe_toRingHom, Algebra.TensorProduct.tmul_pow, one_pow, Algebra.TensorProduct.includeLeft_apply, Algebra.TensorProduct.tmul_mul_tmul, mul_one, one_mul, ← Algebra.commutes, ← Algebra.smul_def, smul_tmul, sum_def, ← tmul_sum] conv_rhs => rw [← sum_C_mul_X_pow_eq p] simp only [Algebra.smul_def] rfl · intro p q hp hq simp only [map_add, invFun_add, hp, hq] theorem right_inv (x : A[X]) : (toFunAlgHom R A) (invFun R A x) = x := by refine Polynomial.induction_on' x ?_ ?_ · intro p q hp hq simp only [invFun_add, map_add, hp, hq] · intro n a rw [invFun_monomial, Algebra.TensorProduct.tmul_pow, one_pow, Algebra.TensorProduct.tmul_mul_tmul, mul_one, one_mul, toFunAlgHom_apply_tmul, X_pow_eq_monomial, sum_monomial_index] <;> simp /-- (Implementation detail) The equivalence, ignoring the algebra structure, `(A ⊗[R] R[X]) ≃ A[X]`. -/ def equiv : A ⊗[R] R[X] ≃ A[X] where toFun := toFunAlgHom R A invFun := invFun R A left_inv := left_inv R A right_inv := right_inv R A end PolyEquivTensor open PolyEquivTensor /-- The `R`-algebra isomorphism `A[X] ≃ₐ[R] (A ⊗[R] R[X])`. -/ def polyEquivTensor : A[X] ≃ₐ[R] A ⊗[R] R[X] := AlgEquiv.symm { PolyEquivTensor.toFunAlgHom R A, PolyEquivTensor.equiv R A with } @[simp] theorem polyEquivTensor_apply (p : A[X]) : polyEquivTensor R A p = p.eval₂ (includeLeft : A →ₐ[R] A ⊗[R] R[X]) ((1 : A) ⊗ₜ[R] (X : R[X])) := rfl @[simp] theorem polyEquivTensor_symm_apply_tmul_eq_smul (a : A) (p : R[X]) : (polyEquivTensor R A).symm (a ⊗ₜ p) = a • p.map (algebraMap R A) := rfl theorem polyEquivTensor_symm_apply_tmul (a : A) (p : R[X]) : (polyEquivTensor R A).symm (a ⊗ₜ p) = p.sum fun n r => monomial n (a * algebraMap R A r) := toFunAlgHom_apply_tmul _ _ _ _ section variable (A : Type*) [CommSemiring A] [Algebra R A] /-- The `A`-algebra isomorphism `A[X] ≃ₐ[A] A ⊗[R] R[X]` (when `A` is commutative). -/ def polyEquivTensor' : A[X] ≃ₐ[A] A ⊗[R] R[X] where __ := polyEquivTensor R A commutes' a := by simp /-- `polyEquivTensor' R A` is the same as `polyEquivTensor R A` as a function. -/ @[simp] theorem coe_polyEquivTensor' : ⇑(polyEquivTensor' R A) = polyEquivTensor R A := rfl @[simp] theorem coe_polyEquivTensor'_symm : ⇑(polyEquivTensor' R A).symm = (polyEquivTensor R A).symm := rfl end /-- If `A` is an `R`-algebra, then `A[X]` is an `R[X]` algebra. This gives a diamond for `Algebra R[X] R[X][X]`, so this is not a global instance. -/ @[reducible] def Polynomial.algebra : Algebra R[X] A[X] := (mapRingHom (algebraMap R A)).toAlgebra' fun _ _ ↩ by ext; rw [coeff_mul, ← Finset.Nat.sum_antidiagonal_swap, coeff_mul]; simp [Algebra.commutes] attribute [local instance] Polynomial.algebra @[simp] theorem Polynomial.algebraMap_def : algebraMap R[X] A[X] = mapRingHom (algebraMap R A) := rfl instance : IsScalarTower R R[X] A[X] := .of_algebraMap_eq' (mapRingHom_comp_C _).symm instance [FaithfulSMul R A] : FaithfulSMul R[X] A[X] := (faithfulSMul_iff_algebraMap_injective ..).mpr (map_injective _ <| FaithfulSMul.algebraMap_injective ..) variable {S : Type*} [CommSemiring S] [Algebra R S] instance : Algebra.IsPushout R S R[X] S[X] where out := .of_equiv (polyEquivTensor' R S).symm fun _ ↩ (polyEquivTensor_symm_apply_tmul_eq_smul ..).trans <| one_smul .. instance : Algebra.IsPushout R R[X] S S[X] := .symm inferInstance
Mathlib/RingTheory/PolynomialAlgebra.lean
307
314
/- Copyright (c) 2023 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.Group.PUnit import Mathlib.Algebra.Group.Subgroup.Ker import Mathlib.Algebra.Group.Submonoid.Membership import Mathlib.GroupTheory.Congruence.Basic /-! # Coproduct (free product) of two monoids or groups In this file we define `Monoid.Coprod M N` (notation: `M ∗ N`) to be the coproduct (a.k.a. free product) of two monoids. The same type is used for the coproduct of two monoids and for the coproduct of two groups. The coproduct `M ∗ N` has the following universal property: for any monoid `P` and homomorphisms `f : M →* P`, `g : N →* P`, there exists a unique homomorphism `fg : M ∗ N →* P` such that `fg ∘ Monoid.Coprod.inl = f` and `fg ∘ Monoid.Coprod.inr = g`, where `Monoid.Coprod.inl : M →* M ∗ N` and `Monoid.Coprod.inr : N →* M ∗ N` are canonical embeddings. This homomorphism `fg` is given by `Monoid.Coprod.lift f g`. We also define some homomorphisms and isomorphisms about `M ∗ N`, and provide additive versions of all definitions and theorems. ## Main definitions ### Types * `Monoid.Coprod M N` (a.k.a. `M ∗ N`): the free product (a.k.a. coproduct) of two monoids `M` and `N`. * `AddMonoid.Coprod M N` (no notation): the additive version of `Monoid.Coprod`. In other sections, we only list multiplicative definitions. ### Instances * `MulOneClass`, `Monoid`, and `Group` structures on the coproduct `M ∗ N`. ### Monoid homomorphisms * `Monoid.Coprod.mk`: the projection `FreeMonoid (M ⊕ N) →* M ∗ N`. * `Monoid.Coprod.inl`, `Monoid.Coprod.inr`: canonical embeddings `M →* M ∗ N` and `N →* M ∗ N`. * `Monoid.Coprod.lift`: construct a monoid homomorphism `M ∗ N →* P` from homomorphisms `M →* P` and `N →* P`; see also `Monoid.Coprod.liftEquiv`. * `Monoid.Coprod.clift`: a constructor for homomorphisms `M ∗ N →* P` that allows the user to control the computational behavior. * `Monoid.Coprod.map`: combine two homomorphisms `f : M →* N` and `g : M' →* N'` into `M ∗ M' →* N ∗ N'`. * `Monoid.Coprod.swap`: the natural homomorphism `M ∗ N →* N ∗ M`. * `Monoid.Coprod.fst`, `Monoid.Coprod.snd`, and `Monoid.Coprod.toProd`: natural projections `M ∗ N →* M`, `M ∗ N →* N`, and `M ∗ N →* M × N`. ### Monoid isomorphisms * `MulEquiv.coprodCongr`: a `MulEquiv` version of `Monoid.Coprod.map`. * `MulEquiv.coprodComm`: a `MulEquiv` version of `Monoid.Coprod.swap`. * `MulEquiv.coprodAssoc`: associativity of the coproduct. * `MulEquiv.coprodPUnit`, `MulEquiv.punitCoprod`: free product by `PUnit` on the left or on the right is isomorphic to the original monoid. ## Main results The universal property of the coproduct is given by the definition `Monoid.Coprod.lift` and the lemma `Monoid.Coprod.lift_unique`. We also prove a slightly more general extensionality lemma `Monoid.Coprod.hom_ext` for homomorphisms `M ∗ N →* P` and prove lots of basic lemmas like `Monoid.Coprod.fst_comp_inl`. ## Implementation details The definition of the coproduct of an indexed family of monoids is formalized in `Monoid.CoprodI`. While mathematically `M ∗ N` is a particular case of the coproduct of an indexed family of monoids, it is easier to build API from scratch instead of using something like ``` def Monoid.Coprod M N := Monoid.CoprodI ![M, N] ``` or ``` def Monoid.Coprod M N := Monoid.CoprodI (fun b : Bool => cond b M N) ``` There are several reasons to build an API from scratch. - API about `Con` makes it easy to define the required type and prove the universal property, so there is little overhead compared to transferring API from `Monoid.CoprodI`. - If `M` and `N` live in different universes, then the definition has to add `ULift`s; this makes it harder to transfer API and definitions. - As of now, we have no way to automatically build an instance of `(k : Fin 2) → Monoid (![M, N] k)` from `[Monoid M]` and `[Monoid N]`, not even speaking about more advanced typeclass assumptions that involve both `M` and `N`. - Using a list of `M ⊕ N` instead of, e.g., a list of `Σ k : Fin 2, ![M, N] k` as the underlying type makes it possible to write computationally effective code (though this point is not tested yet). ## TODO - Prove `Monoid.CoprodI (f : Fin 2 → Type*) ≃* f 0 ∗ f 1` and `Monoid.CoprodI (f : Bool → Type*) ≃* f false ∗ f true`. ## Tags group, monoid, coproduct, free product -/ assert_not_exists MonoidWithZero open FreeMonoid Function List Set namespace Monoid /-- The minimal congruence relation `c` on `FreeMonoid (M ⊕ N)` such that `FreeMonoid.of ∘ Sum.inl` and `FreeMonoid.of ∘ Sum.inr` are monoid homomorphisms to the quotient by `c`. -/ @[to_additive "The minimal additive congruence relation `c` on `FreeAddMonoid (M ⊕ N)` such that `FreeAddMonoid.of ∘ Sum.inl` and `FreeAddMonoid.of ∘ Sum.inr` are additive monoid homomorphisms to the quotient by `c`."] def coprodCon (M N : Type*) [MulOneClass M] [MulOneClass N] : Con (FreeMonoid (M ⊕ N)) := sInf {c | (∀ x y : M, c (of (Sum.inl (x * y))) (of (Sum.inl x) * of (Sum.inl y))) ∧ (∀ x y : N, c (of (Sum.inr (x * y))) (of (Sum.inr x) * of (Sum.inr y))) ∧ c (of <| Sum.inl 1) 1 ∧ c (of <| Sum.inr 1) 1} /-- Coproduct of two monoids or groups. -/ @[to_additive "Coproduct of two additive monoids or groups."] def Coprod (M N : Type*) [MulOneClass M] [MulOneClass N] := (coprodCon M N).Quotient namespace Coprod @[inherit_doc] scoped infix:30 " ∗ " => Coprod section MulOneClass variable {M N M' N' P : Type*} [MulOneClass M] [MulOneClass N] [MulOneClass M'] [MulOneClass N'] [MulOneClass P] @[to_additive] protected instance : MulOneClass (M ∗ N) := Con.mulOneClass _ /-- The natural projection `FreeMonoid (M ⊕ N) →* M ∗ N`. -/ @[to_additive "The natural projection `FreeAddMonoid (M ⊕ N) →+ AddMonoid.Coprod M N`."] def mk : FreeMonoid (M ⊕ N) →* M ∗ N := Con.mk' _ @[to_additive (attr := simp)] theorem con_ker_mk : Con.ker mk = coprodCon M N := Con.mk'_ker _ @[to_additive] theorem mk_surjective : Surjective (@mk M N _ _) := Quot.mk_surjective @[to_additive (attr := simp)] theorem mrange_mk : MonoidHom.mrange (@mk M N _ _) = ⊀ := Con.mrange_mk' @[to_additive] theorem mk_eq_mk {w₁ w₂ : FreeMonoid (M ⊕ N)} : mk w₁ = mk w₂ ↔ coprodCon M N w₁ w₂ := Con.eq _ /-- The natural embedding `M →* M ∗ N`. -/ @[to_additive "The natural embedding `M →+ AddMonoid.Coprod M N`."] def inl : M →* M ∗ N where toFun := fun x => mk (of (.inl x)) map_one' := mk_eq_mk.2 fun _c hc => hc.2.2.1 map_mul' := fun x y => mk_eq_mk.2 fun _c hc => hc.1 x y /-- The natural embedding `N →* M ∗ N`. -/ @[to_additive "The natural embedding `N →+ AddMonoid.Coprod M N`."] def inr : N →* M ∗ N where toFun := fun x => mk (of (.inr x)) map_one' := mk_eq_mk.2 fun _c hc => hc.2.2.2 map_mul' := fun x y => mk_eq_mk.2 fun _c hc => hc.2.1 x y @[to_additive (attr := simp)] theorem mk_of_inl (x : M) : (mk (of (.inl x)) : M ∗ N) = inl x := rfl @[to_additive (attr := simp)] theorem mk_of_inr (x : N) : (mk (of (.inr x)) : M ∗ N) = inr x := rfl @[to_additive (attr := elab_as_elim)] theorem induction_on' {C : M ∗ N → Prop} (m : M ∗ N) (one : C 1) (inl_mul : ∀ m x, C x → C (inl m * x)) (inr_mul : ∀ n x, C x → C (inr n * x)) : C m := by rcases mk_surjective m with ⟹x, rfl⟩ induction x using FreeMonoid.inductionOn' with | one => exact one | mul_of x xs ih => cases x with | inl m => simpa using inl_mul m _ ih | inr n => simpa using inr_mul n _ ih @[to_additive (attr := elab_as_elim)] theorem induction_on {C : M ∗ N → Prop} (m : M ∗ N) (inl : ∀ m, C (inl m)) (inr : ∀ n, C (inr n)) (mul : ∀ x y, C x → C y → C (x * y)) : C m := induction_on' m (by simpa using inl 1) (fun _ _ ↩ mul _ _ (inl _)) fun _ _ ↩ mul _ _ (inr _) /-- Lift a monoid homomorphism `FreeMonoid (M ⊕ N) →* P` satisfying additional properties to `M ∗ N →* P`. In many cases, `Coprod.lift` is more convenient. Compared to `Coprod.lift`, this definition allows a user to provide a custom computational behavior. Also, it only needs `MulOneclass` assumptions while `Coprod.lift` needs a `Monoid` structure. -/ @[to_additive "Lift an additive monoid homomorphism `FreeAddMonoid (M ⊕ N) →+ P` satisfying additional properties to `AddMonoid.Coprod M N →+ P`. Compared to `AddMonoid.Coprod.lift`, this definition allows a user to provide a custom computational behavior. Also, it only needs `AddZeroclass` assumptions while `AddMonoid.Coprod.lift` needs an `AddMonoid` structure. "] def clift (f : FreeMonoid (M ⊕ N) →* P) (hM₁ : f (of (.inl 1)) = 1) (hN₁ : f (of (.inr 1)) = 1) (hM : ∀ x y, f (of (.inl (x * y))) = f (of (.inl x) * of (.inl y))) (hN : ∀ x y, f (of (.inr (x * y))) = f (of (.inr x) * of (.inr y))) : M ∗ N →* P := Con.lift _ f <| sInf_le ⟹hM, hN, hM₁.trans (map_one f).symm, hN₁.trans (map_one f).symm⟩ @[to_additive (attr := simp)] theorem clift_apply_inl (f : FreeMonoid (M ⊕ N) →* P) (hM₁ hN₁ hM hN) (x : M) : clift f hM₁ hN₁ hM hN (inl x) = f (of (.inl x)) := rfl @[to_additive (attr := simp)] theorem clift_apply_inr (f : FreeMonoid (M ⊕ N) →* P) (hM₁ hN₁ hM hN) (x : N) : clift f hM₁ hN₁ hM hN (inr x) = f (of (.inr x)) := rfl @[to_additive (attr := simp)] theorem clift_apply_mk (f : FreeMonoid (M ⊕ N) →* P) (hM₁ hN₁ hM hN w) : clift f hM₁ hN₁ hM hN (mk w) = f w := rfl @[to_additive (attr := simp)] theorem clift_comp_mk (f : FreeMonoid (M ⊕ N) →* P) (hM₁ hN₁ hM hN) : (clift f hM₁ hN₁ hM hN).comp mk = f := DFunLike.ext' rfl @[to_additive (attr := simp)] theorem mclosure_range_inl_union_inr : Submonoid.closure (range (inl : M →* M ∗ N) ∪ range (inr : N →* M ∗ N)) = ⊀ := by rw [← mrange_mk, MonoidHom.mrange_eq_map, ← closure_range_of, MonoidHom.map_mclosure, ← range_comp, Sum.range_eq]; rfl @[to_additive (attr := simp)] theorem mrange_inl_sup_mrange_inr : MonoidHom.mrange (inl : M →* M ∗ N) ⊔ MonoidHom.mrange (inr : N →* M ∗ N) = ⊀ := by rw [← mclosure_range_inl_union_inr, Submonoid.closure_union, ← MonoidHom.coe_mrange, ← MonoidHom.coe_mrange, Submonoid.closure_eq, Submonoid.closure_eq] @[to_additive] theorem codisjoint_mrange_inl_mrange_inr : Codisjoint (MonoidHom.mrange (inl : M →* M ∗ N)) (MonoidHom.mrange inr) := codisjoint_iff.2 mrange_inl_sup_mrange_inr @[to_additive] theorem mrange_eq (f : M ∗ N →* P) : MonoidHom.mrange f = MonoidHom.mrange (f.comp inl) ⊔ MonoidHom.mrange (f.comp inr) := by rw [MonoidHom.mrange_eq_map, ← mrange_inl_sup_mrange_inr, Submonoid.map_sup, MonoidHom.map_mrange, MonoidHom.map_mrange] /-- Extensionality lemma for monoid homomorphisms `M ∗ N →* P`. If two homomorphisms agree on the ranges of `Monoid.Coprod.inl` and `Monoid.Coprod.inr`, then they are equal. -/ @[to_additive (attr := ext 1100) "Extensionality lemma for additive monoid homomorphisms `AddMonoid.Coprod M N →+ P`. If two homomorphisms agree on the ranges of `AddMonoid.Coprod.inl` and `AddMonoid.Coprod.inr`, then they are equal."] theorem hom_ext {f g : M ∗ N →* P} (h₁ : f.comp inl = g.comp inl) (h₂ : f.comp inr = g.comp inr) : f = g := MonoidHom.eq_of_eqOn_denseM mclosure_range_inl_union_inr <| eqOn_union.2 ⟹eqOn_range.2 <| DFunLike.ext'_iff.1 h₁, eqOn_range.2 <| DFunLike.ext'_iff.1 h₂⟩ @[to_additive (attr := simp)] theorem clift_mk : clift (mk : FreeMonoid (M ⊕ N) →* M ∗ N) (map_one inl) (map_one inr) (map_mul inl) (map_mul inr) = .id _ := hom_ext rfl rfl /-- Map `M ∗ N` to `M' ∗ N'` by applying `Sum.map f g` to each element of the underlying list. -/ @[to_additive "Map `AddMonoid.Coprod M N` to `AddMonoid.Coprod M' N'` by applying `Sum.map f g` to each element of the underlying list."] def map (f : M →* M') (g : N →* N') : M ∗ N →* M' ∗ N' := clift (mk.comp <| FreeMonoid.map <| Sum.map f g) (by simp only [MonoidHom.comp_apply, map_of, Sum.map_inl, map_one, mk_of_inl]) (by simp only [MonoidHom.comp_apply, map_of, Sum.map_inr, map_one, mk_of_inr]) (fun x y => by simp only [MonoidHom.comp_apply, map_of, Sum.map_inl, map_mul, mk_of_inl]) fun x y => by simp only [MonoidHom.comp_apply, map_of, Sum.map_inr, map_mul, mk_of_inr] @[to_additive (attr := simp)] theorem map_mk_ofList (f : M →* M') (g : N →* N') (l : List (M ⊕ N)) : map f g (mk (ofList l)) = mk (ofList (l.map (Sum.map f g))) := rfl @[to_additive (attr := simp)] theorem map_apply_inl (f : M →* M') (g : N →* N') (x : M) : map f g (inl x) = inl (f x) := rfl @[to_additive (attr := simp)] theorem map_apply_inr (f : M →* M') (g : N →* N') (x : N) : map f g (inr x) = inr (g x) := rfl @[to_additive (attr := simp)] theorem map_comp_inl (f : M →* M') (g : N →* N') : (map f g).comp inl = inl.comp f := rfl @[to_additive (attr := simp)] theorem map_comp_inr (f : M →* M') (g : N →* N') : (map f g).comp inr = inr.comp g := rfl @[to_additive (attr := simp)] theorem map_id_id : map (.id M) (.id N) = .id (M ∗ N) := hom_ext rfl rfl @[to_additive] theorem map_comp_map {M'' N''} [MulOneClass M''] [MulOneClass N''] (f' : M' →* M'') (g' : N' →* N'') (f : M →* M') (g : N →* N') : (map f' g').comp (map f g) = map (f'.comp f) (g'.comp g) := hom_ext rfl rfl @[to_additive] theorem map_map {M'' N''} [MulOneClass M''] [MulOneClass N''] (f' : M' →* M'') (g' : N' →* N'') (f : M →* M') (g : N →* N') (x : M ∗ N) : map f' g' (map f g x) = map (f'.comp f) (g'.comp g) x := DFunLike.congr_fun (map_comp_map f' g' f g) x variable (M N) /-- Map `M ∗ N` to `N ∗ M` by applying `Sum.swap` to each element of the underlying list. See also `MulEquiv.coprodComm` for a `MulEquiv` version. -/ @[to_additive "Map `AddMonoid.Coprod M N` to `AddMonoid.Coprod N M` by applying `Sum.swap` to each element of the underlying list. See also `AddEquiv.coprodComm` for an `AddEquiv` version."] def swap : M ∗ N →* N ∗ M := clift (mk.comp <| FreeMonoid.map Sum.swap) (by simp only [MonoidHom.comp_apply, map_of, Sum.swap_inl, mk_of_inr, map_one]) (by simp only [MonoidHom.comp_apply, map_of, Sum.swap_inr, mk_of_inl, map_one]) (fun x y => by simp only [MonoidHom.comp_apply, map_of, Sum.swap_inl, mk_of_inr, map_mul]) (fun x y => by simp only [MonoidHom.comp_apply, map_of, Sum.swap_inr, mk_of_inl, map_mul]) @[to_additive (attr := simp)] theorem swap_comp_swap : (swap M N).comp (swap N M) = .id _ := hom_ext rfl rfl variable {M N} @[to_additive (attr := simp)] theorem swap_swap (x : M ∗ N) : swap N M (swap M N x) = x := DFunLike.congr_fun (swap_comp_swap _ _) x @[to_additive] theorem swap_comp_map (f : M →* M') (g : N →* N') : (swap M' N').comp (map f g) = (map g f).comp (swap M N) := hom_ext rfl rfl @[to_additive] theorem swap_map (f : M →* M') (g : N →* N') (x : M ∗ N) : swap M' N' (map f g x) = map g f (swap M N x) := DFunLike.congr_fun (swap_comp_map f g) x @[to_additive (attr := simp)] theorem swap_comp_inl : (swap M N).comp inl = inr := rfl @[to_additive (attr := simp)] theorem swap_inl (x : M) : swap M N (inl x) = inr x := rfl @[to_additive (attr := simp)] theorem swap_comp_inr : (swap M N).comp inr = inl := rfl @[to_additive (attr := simp)] theorem swap_inr (x : N) : swap M N (inr x) = inl x := rfl @[to_additive] theorem swap_injective : Injective (swap M N) := LeftInverse.injective swap_swap @[to_additive (attr := simp)] theorem swap_inj {x y : M ∗ N} : swap M N x = swap M N y ↔ x = y := swap_injective.eq_iff @[to_additive (attr := simp)] theorem swap_eq_one {x : M ∗ N} : swap M N x = 1 ↔ x = 1 := swap_injective.eq_iff' (map_one _) @[to_additive] theorem swap_surjective : Surjective (swap M N) := LeftInverse.surjective swap_swap @[to_additive] theorem swap_bijective : Bijective (swap M N) := ⟹swap_injective, swap_surjective⟩ @[to_additive (attr := simp)] theorem mker_swap : MonoidHom.mker (swap M N) = ⊥ := Submonoid.ext fun _ ↩ swap_eq_one @[to_additive (attr := simp)] theorem mrange_swap : MonoidHom.mrange (swap M N) = ⊀ := MonoidHom.mrange_eq_top_of_surjective _ swap_surjective end MulOneClass section Lift variable {M N P : Type*} [MulOneClass M] [MulOneClass N] [Monoid P] /-- Lift a pair of monoid homomorphisms `f : M →* P`, `g : N →* P` to a monoid homomorphism `M ∗ N →* P`. See also `Coprod.clift` for a version that allows custom computational behavior and works for a `MulOneClass` codomain. -/ @[to_additive "Lift a pair of additive monoid homomorphisms `f : M →+ P`, `g : N →+ P` to an additive monoid homomorphism `AddMonoid.Coprod M N →+ P`. See also `AddMonoid.Coprod.clift` for a version that allows custom computational behavior and works for an `AddZeroClass` codomain."] def lift (f : M →* P) (g : N →* P) : (M ∗ N) →* P := clift (FreeMonoid.lift <| Sum.elim f g) (map_one f) (map_one g) (map_mul f) (map_mul g) @[to_additive (attr := simp)] theorem lift_apply_mk (f : M →* P) (g : N →* P) (x : FreeMonoid (M ⊕ N)) : lift f g (mk x) = FreeMonoid.lift (Sum.elim f g) x := rfl @[to_additive (attr := simp)] theorem lift_apply_inl (f : M →* P) (g : N →* P) (x : M) : lift f g (inl x) = f x := rfl @[to_additive] theorem lift_unique {f : M →* P} {g : N →* P} {fg : M ∗ N →* P} (h₁ : fg.comp inl = f) (h₂ : fg.comp inr = g) : fg = lift f g := hom_ext h₁ h₂ @[to_additive (attr := simp)] theorem lift_comp_inl (f : M →* P) (g : N →* P) : (lift f g).comp inl = f := rfl @[to_additive (attr := simp)] theorem lift_apply_inr (f : M →* P) (g : N →* P) (x : N) : lift f g (inr x) = g x := rfl @[to_additive (attr := simp)] theorem lift_comp_inr (f : M →* P) (g : N →* P) : (lift f g).comp inr = g := rfl @[to_additive (attr := simp)] theorem lift_comp_swap (f : M →* P) (g : N →* P) : (lift f g).comp (swap N M) = lift g f := hom_ext rfl rfl @[to_additive (attr := simp)] theorem lift_swap (f : M →* P) (g : N →* P) (x : N ∗ M) : lift f g (swap N M x) = lift g f x := DFunLike.congr_fun (lift_comp_swap f g) x @[to_additive] theorem comp_lift {P' : Type*} [Monoid P'] (f : P →* P') (g₁ : M →* P) (g₂ : N →* P) : f.comp (lift g₁ g₂) = lift (f.comp g₁) (f.comp g₂) := hom_ext (by rw [MonoidHom.comp_assoc, lift_comp_inl, lift_comp_inl]) <| by rw [MonoidHom.comp_assoc, lift_comp_inr, lift_comp_inr] /-- `Coprod.lift` as an equivalence. -/ @[to_additive "`AddMonoid.Coprod.lift` as an equivalence."] def liftEquiv : (M →* P) × (N →* P) ≃ (M ∗ N →* P) where toFun fg := lift fg.1 fg.2 invFun f := (f.comp inl, f.comp inr) left_inv _ := rfl right_inv _ := Eq.symm <| lift_unique rfl rfl @[to_additive (attr := simp)] theorem mrange_lift (f : M →* P) (g : N →* P) : MonoidHom.mrange (lift f g) = MonoidHom.mrange f ⊔ MonoidHom.mrange g := by simp [mrange_eq] end Lift section ToProd variable {M N : Type*} [Monoid M] [Monoid N] @[to_additive] instance : Monoid (M ∗ N) := { mul_assoc := (Con.monoid _).mul_assoc one_mul := (Con.monoid _).one_mul mul_one := (Con.monoid _).mul_one } /-- The natural projection `M ∗ N →* M`. -/ @[to_additive "The natural projection `AddMonoid.Coprod M N →+ M`."] def fst : M ∗ N →* M := lift (.id M) 1 /-- The natural projection `M ∗ N →* N`. -/ @[to_additive "The natural projection `AddMonoid.Coprod M N →+ N`."] def snd : M ∗ N →* N := lift 1 (.id N) /-- The natural projection `M ∗ N →* M × N`. -/ @[to_additive toProd "The natural projection `AddMonoid.Coprod M N →+ M × N`."] def toProd : M ∗ N →* M × N := lift (.inl _ _) (.inr _ _) @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.toSum := AddMonoid.Coprod.toProd @[to_additive (attr := simp)] theorem fst_comp_inl : (fst : M ∗ N →* M).comp inl = .id _ := rfl @[to_additive (attr := simp)] theorem fst_apply_inl (x : M) : fst (inl x : M ∗ N) = x := rfl @[to_additive (attr := simp)] theorem fst_comp_inr : (fst : M ∗ N →* M).comp inr = 1 := rfl @[to_additive (attr := simp)] theorem fst_apply_inr (x : N) : fst (inr x : M ∗ N) = 1 := rfl @[to_additive (attr := simp)] theorem snd_comp_inl : (snd : M ∗ N →* N).comp inl = 1 := rfl @[to_additive (attr := simp)] theorem snd_apply_inl (x : M) : snd (inl x : M ∗ N) = 1 := rfl @[to_additive (attr := simp)] theorem snd_comp_inr : (snd : M ∗ N →* N).comp inr = .id _ := rfl @[to_additive (attr := simp)] theorem snd_apply_inr (x : N) : snd (inr x : M ∗ N) = x := rfl @[to_additive (attr := simp) toProd_comp_inl] theorem toProd_comp_inl : (toProd : M ∗ N →* M × N).comp inl = .inl _ _ := rfl @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.toSum_comp_inl := AddMonoid.Coprod.toProd_comp_inl @[to_additive (attr := simp) toProd_comp_inr] theorem toProd_comp_inr : (toProd : M ∗ N →* M × N).comp inr = .inr _ _ := rfl @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.toSum_comp_inr := AddMonoid.Coprod.toProd_comp_inr @[to_additive (attr := simp) toProd_apply_inl] theorem toProd_apply_inl (x : M) : toProd (inl x : M ∗ N) = (x, 1) := rfl @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.toSum_apply_inl := AddMonoid.Coprod.toProd_apply_inl @[to_additive (attr := simp) toProd_apply_inr] theorem toProd_apply_inr (x : N) : toProd (inr x : M ∗ N) = (1, x) := rfl @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.toSum_apply_inr := AddMonoid.Coprod.toProd_apply_inr @[to_additive (attr := simp) fst_prod_snd] theorem fst_prod_snd : (fst : M ∗ N →* M).prod snd = toProd := by ext1 <;> rfl @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.fst_sum_snd := AddMonoid.Coprod.fst_prod_snd @[to_additive (attr := simp) prod_mk_fst_snd] theorem prod_mk_fst_snd (x : M ∗ N) : (fst x, snd x) = toProd x := by rw [← fst_prod_snd, MonoidHom.prod_apply] @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.sum_mk_fst_snd := AddMonoid.Coprod.prod_mk_fst_snd @[to_additive (attr := simp) fst_comp_toProd] theorem fst_comp_toProd : (MonoidHom.fst M N).comp toProd = fst := by rw [← fst_prod_snd, MonoidHom.fst_comp_prod] @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.fst_comp_toSum := AddMonoid.Coprod.fst_comp_toProd @[to_additive (attr := simp) fst_toProd] theorem fst_toProd (x : M ∗ N) : (toProd x).1 = fst x := by rw [← fst_comp_toProd]; rfl @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.fst_toSum := AddMonoid.Coprod.fst_toProd @[to_additive (attr := simp) snd_comp_toProd] theorem snd_comp_toProd : (MonoidHom.snd M N).comp toProd = snd := by rw [← fst_prod_snd, MonoidHom.snd_comp_prod] @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.snd_comp_toSum := AddMonoid.Coprod.snd_comp_toProd @[to_additive (attr := simp) snd_toProd] theorem snd_toProd (x : M ∗ N) : (toProd x).2 = snd x := by rw [← snd_comp_toProd]; rfl @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.snd_toSum := AddMonoid.Coprod.snd_toProd @[to_additive (attr := simp)] theorem fst_comp_swap : fst.comp (swap M N) = snd := lift_comp_swap _ _ @[to_additive (attr := simp)] theorem fst_swap (x : M ∗ N) : fst (swap M N x) = snd x := lift_swap _ _ _ @[to_additive (attr := simp)] theorem snd_comp_swap : snd.comp (swap M N) = fst := lift_comp_swap _ _ @[to_additive (attr := simp)] theorem snd_swap (x : M ∗ N) : snd (swap M N x) = fst x := lift_swap _ _ _ @[to_additive (attr := simp)] theorem lift_inr_inl : lift (inr : M →* N ∗ M) inl = swap M N := hom_ext rfl rfl @[to_additive (attr := simp)] theorem lift_inl_inr : lift (inl : M →* M ∗ N) inr = .id _ := hom_ext rfl rfl @[to_additive] theorem inl_injective : Injective (inl : M →* M ∗ N) := LeftInverse.injective fst_apply_inl @[to_additive] theorem inr_injective : Injective (inr : N →* M ∗ N) := LeftInverse.injective snd_apply_inr @[to_additive] theorem fst_surjective : Surjective (fst : M ∗ N →* M) := LeftInverse.surjective fst_apply_inl @[to_additive] theorem snd_surjective : Surjective (snd : M ∗ N →* N) := LeftInverse.surjective snd_apply_inr @[to_additive toProd_surjective] theorem toProd_surjective : Surjective (toProd : M ∗ N →* M × N) := fun x => ⟹inl x.1 * inr x.2, by rw [map_mul, toProd_apply_inl, toProd_apply_inr, Prod.fst_mul_snd]⟩ @[deprecated (since := "2025-03-11")] alias _root_.AddMonoid.Coprod.toSum_surjective := AddMonoid.Coprod.toProd_surjective end ToProd section Group variable {G H : Type*} [Group G] [Group H] @[to_additive] theorem mk_of_inv_mul : ∀ x : G ⊕ H, mk (of (x.map Inv.inv Inv.inv)) * mk (of x) = 1 | Sum.inl _ => map_mul_eq_one inl (inv_mul_cancel _) | Sum.inr _ => map_mul_eq_one inr (inv_mul_cancel _) @[to_additive] theorem con_inv_mul_cancel (x : FreeMonoid (G ⊕ H)) : coprodCon G H (ofList (x.toList.map (Sum.map Inv.inv Inv.inv)).reverse * x) 1 := by rw [← mk_eq_mk, map_mul, map_one] induction x using FreeMonoid.inductionOn' with | one => simp | mul_of x xs ihx => simp only [toList_of_mul, map_cons, reverse_cons, ofList_append, map_mul, ihx, ofList_singleton] rwa [mul_assoc, ← mul_assoc (mk (of _)), mk_of_inv_mul, one_mul] @[to_additive]
instance : Inv (G ∗ H) where inv := Quotient.map' (fun w => ofList (w.toList.map (Sum.map Inv.inv Inv.inv)).reverse) fun _ _ ↩ (coprodCon G H).map_of_mul_left_rel_one _ con_inv_mul_cancel
Mathlib/GroupTheory/Coprod/Basic.lean
621
623
/- Copyright (c) 2019 Rohan Mitta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rohan Mitta, Kevin Buzzard, Alistair Tucker, Johannes Hölzl, Yury Kudryashov -/ import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.Data.Setoid.Basic import Mathlib.Dynamics.FixedPoints.Topology import Mathlib.Topology.MetricSpace.Lipschitz /-! # Contracting maps A Lipschitz continuous self-map with Lipschitz constant `K < 1` is called a *contracting map*. In this file we prove the Banach fixed point theorem, some explicit estimates on the rate of convergence, and some properties of the map sending a contracting map to its fixed point. ## Main definitions * `ContractingWith K f` : a Lipschitz continuous self-map with `K < 1`; * `efixedPoint` : given a contracting map `f` on a complete emetric space and a point `x` such that `edist x (f x) ≠ ∞`, `efixedPoint f hf x hx` is the unique fixed point of `f` in `EMetric.ball x ∞`; * `fixedPoint` : the unique fixed point of a contracting map on a complete nonempty metric space. ## Tags contracting map, fixed point, Banach fixed point theorem -/ open NNReal Topology ENNReal Filter Function variable {α : Type*} /-- A map is said to be `ContractingWith K`, if `K < 1` and `f` is `LipschitzWith K`. -/ def ContractingWith [EMetricSpace α] (K : ℝ≥0) (f : α → α) := K < 1 ∧ LipschitzWith K f namespace ContractingWith variable [EMetricSpace α] {K : ℝ≥0} {f : α → α} open EMetric Set theorem toLipschitzWith (hf : ContractingWith K f) : LipschitzWith K f := hf.2 theorem one_sub_K_pos' (hf : ContractingWith K f) : (0 : ℝ≥0∞) < 1 - K := by simp [hf.1] theorem one_sub_K_ne_zero (hf : ContractingWith K f) : (1 : ℝ≥0∞) - K ≠ 0 := ne_of_gt hf.one_sub_K_pos' theorem one_sub_K_ne_top : (1 : ℝ≥0∞) - K ≠ ∞ := by norm_cast exact ENNReal.coe_ne_top theorem edist_inequality (hf : ContractingWith K f) {x y} (h : edist x y ≠ ∞) : edist x y ≀ (edist x (f x) + edist y (f y)) / (1 - K) := suffices edist x y ≀ edist x (f x) + edist y (f y) + K * edist x y by rwa [ENNReal.le_div_iff_mul_le (Or.inl hf.one_sub_K_ne_zero) (Or.inl one_sub_K_ne_top), mul_comm, ENNReal.sub_mul fun _ _ ↩ h, one_mul, tsub_le_iff_right] calc
edist x y ≀ edist x (f x) + edist (f x) (f y) + edist (f y) y := edist_triangle4 _ _ _ _ _ = edist x (f x) + edist y (f y) + edist (f x) (f y) := by rw [edist_comm y, add_right_comm] _ ≀ edist x (f x) + edist y (f y) + K * edist x y := add_le_add le_rfl (hf.2 _ _)
Mathlib/Topology/MetricSpace/Contracting.lean
62
64
/- 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
Mathlib/Data/Set/Prod.lean
111
113
/- Copyright (c) 2023 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.Deriv.Add import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Slope /-! # Line derivatives We define the line derivative of a function `f : E → F`, at a point `x : E` along a vector `v : E`, as the element `f' : F` such that `f (x + t • v) = f x + t • f' + o (t)` as `t` tends to `0` in the scalar field `𝕜`, if it exists. It is denoted by `lineDeriv 𝕜 f x v`. This notion is generally less well behaved than the full Fréchet derivative (for instance, the composition of functions which are line-differentiable is not line-differentiable in general). The Fréchet derivative should therefore be favored over this one in general, although the line derivative may sometimes prove handy. The line derivative in direction `v` is also called the Gateaux derivative in direction `v`, although the term "Gateaux derivative" is sometimes reserved for the situation where there is such a derivative in all directions, for the map `v ↩ lineDeriv 𝕜 f x v` (which doesn't have to be linear in general). ## Main definition and results We mimic the definitions and statements for the Fréchet derivative and the one-dimensional derivative. We define in particular the following objects: * `LineDifferentiableWithinAt 𝕜 f s x v` * `LineDifferentiableAt 𝕜 f x v` * `HasLineDerivWithinAt 𝕜 f f' s x v` * `HasLineDerivAt 𝕜 f s x v` * `lineDerivWithin 𝕜 f s x v` * `lineDeriv 𝕜 f x v` and develop about them a basic API inspired by the one for the Fréchet derivative. We depart from the Fréchet derivative in two places, as the dependence of the following predicates on the direction would make them barely usable: * We do not define an analogue of the predicate `UniqueDiffOn`; * We do not define `LineDifferentiableOn` nor `LineDifferentiable`. -/ noncomputable section open scoped Topology Filter ENNReal NNReal open Filter Asymptotics Set variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] section Module /-! Results that do not rely on a topological structure on `E` -/ variable (𝕜) variable {E : Type*} [AddCommGroup E] [Module 𝕜 E] /-- `f` has the derivative `f'` at the point `x` along the direction `v` in the set `s`. That is, `f (x + t v) = f x + t • f' + o (t)` when `t` tends to `0` and `x + t v ∈ s`. Note that this definition is less well behaved than the total Fréchet derivative, which should generally be favored over this one. -/ def HasLineDerivWithinAt (f : E → F) (f' : F) (s : Set E) (x : E) (v : E) := HasDerivWithinAt (fun t ↩ f (x + t • v)) f' ((fun t ↩ x + t • v) ⁻¹' s) (0 : 𝕜) /-- `f` has the derivative `f'` at the point `x` along the direction `v`. That is, `f (x + t v) = f x + t • f' + o (t)` when `t` tends to `0`. Note that this definition is less well behaved than the total Fréchet derivative, which should generally be favored over this one. -/ def HasLineDerivAt (f : E → F) (f' : F) (x : E) (v : E) := HasDerivAt (fun t ↩ f (x + t • v)) f' (0 : 𝕜) /-- `f` is line-differentiable at the point `x` in the direction `v` in the set `s` if there exists `f'` such that `f (x + t v) = f x + t • f' + o (t)` when `t` tends to `0` and `x + t v ∈ s`. -/ def LineDifferentiableWithinAt (f : E → F) (s : Set E) (x : E) (v : E) : Prop := DifferentiableWithinAt 𝕜 (fun t ↩ f (x + t • v)) ((fun t ↩ x + t • v) ⁻¹' s) (0 : 𝕜) /-- `f` is line-differentiable at the point `x` in the direction `v` if there exists `f'` such that `f (x + t v) = f x + t • f' + o (t)` when `t` tends to `0`. -/ def LineDifferentiableAt (f : E → F) (x : E) (v : E) : Prop := DifferentiableAt 𝕜 (fun t ↩ f (x + t • v)) (0 : 𝕜) /-- Line derivative of `f` at the point `x` in the direction `v` within the set `s`, if it exists. Zero otherwise. If the line derivative exists (i.e., `∃ f', HasLineDerivWithinAt 𝕜 f f' s x v`), then `f (x + t v) = f x + t lineDerivWithin 𝕜 f s x v + o (t)` when `t` tends to `0` and `x + t v ∈ s`. -/ def lineDerivWithin (f : E → F) (s : Set E) (x : E) (v : E) : F := derivWithin (fun t ↩ f (x + t • v)) ((fun t ↩ x + t • v) ⁻¹' s) (0 : 𝕜) /-- Line derivative of `f` at the point `x` in the direction `v`, if it exists. Zero otherwise. If the line derivative exists (i.e., `∃ f', HasLineDerivAt 𝕜 f f' x v`), then `f (x + t v) = f x + t lineDeriv 𝕜 f x v + o (t)` when `t` tends to `0`. -/ def lineDeriv (f : E → F) (x : E) (v : E) : F := deriv (fun t ↩ f (x + t • v)) (0 : 𝕜) variable {𝕜} variable {f f₁ : E → F} {f' f₀' f₁' : F} {s t : Set E} {x v : E} lemma HasLineDerivWithinAt.mono (hf : HasLineDerivWithinAt 𝕜 f f' s x v) (hst : t ⊆ s) : HasLineDerivWithinAt 𝕜 f f' t x v := HasDerivWithinAt.mono hf (preimage_mono hst) lemma HasLineDerivAt.hasLineDerivWithinAt (hf : HasLineDerivAt 𝕜 f f' x v) (s : Set E) : HasLineDerivWithinAt 𝕜 f f' s x v := HasDerivAt.hasDerivWithinAt hf lemma HasLineDerivWithinAt.lineDifferentiableWithinAt (hf : HasLineDerivWithinAt 𝕜 f f' s x v) : LineDifferentiableWithinAt 𝕜 f s x v := HasDerivWithinAt.differentiableWithinAt hf theorem HasLineDerivAt.lineDifferentiableAt (hf : HasLineDerivAt 𝕜 f f' x v) : LineDifferentiableAt 𝕜 f x v := HasDerivAt.differentiableAt hf theorem LineDifferentiableWithinAt.hasLineDerivWithinAt (h : LineDifferentiableWithinAt 𝕜 f s x v) : HasLineDerivWithinAt 𝕜 f (lineDerivWithin 𝕜 f s x v) s x v := DifferentiableWithinAt.hasDerivWithinAt h theorem LineDifferentiableAt.hasLineDerivAt (h : LineDifferentiableAt 𝕜 f x v) : HasLineDerivAt 𝕜 f (lineDeriv 𝕜 f x v) x v := DifferentiableAt.hasDerivAt h @[simp] lemma hasLineDerivWithinAt_univ : HasLineDerivWithinAt 𝕜 f f' univ x v ↔ HasLineDerivAt 𝕜 f f' x v := by simp only [HasLineDerivWithinAt, HasLineDerivAt, preimage_univ, hasDerivWithinAt_univ] theorem lineDerivWithin_zero_of_not_lineDifferentiableWithinAt (h : ¬LineDifferentiableWithinAt 𝕜 f s x v) : lineDerivWithin 𝕜 f s x v = 0 := derivWithin_zero_of_not_differentiableWithinAt h theorem lineDeriv_zero_of_not_lineDifferentiableAt (h : ¬LineDifferentiableAt 𝕜 f x v) : lineDeriv 𝕜 f x v = 0 := deriv_zero_of_not_differentiableAt h
theorem hasLineDerivAt_iff_isLittleO_nhds_zero : HasLineDerivAt 𝕜 f f' x v ↔ (fun t : 𝕜 => f (x + t • v) - f x - t • f') =o[𝓝 0] fun t => t := by simp only [HasLineDerivAt, hasDerivAt_iff_isLittleO_nhds_zero, zero_add, zero_smul, add_zero]
Mathlib/Analysis/Calculus/LineDeriv/Basic.lean
147
150
/- Copyright (c) 2020 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser, Utensil Song -/ import Mathlib.Algebra.RingQuot import Mathlib.LinearAlgebra.TensorAlgebra.Basic import Mathlib.LinearAlgebra.QuadraticForm.Isometry import Mathlib.LinearAlgebra.QuadraticForm.IsometryEquiv /-! # Clifford Algebras We construct the Clifford algebra of a module `M` over a commutative ring `R`, equipped with a quadratic form `Q`. ## Notation The Clifford algebra of the `R`-module `M` equipped with a quadratic form `Q` is an `R`-algebra denoted `CliffordAlgebra Q`. Given a linear morphism `f : M → A` from a module `M` to another `R`-algebra `A`, such that `cond : ∀ m, f m * f m = algebraMap _ _ (Q m)`, there is a (unique) lift of `f` to an `R`-algebra morphism from `CliffordAlgebra Q` to `A`, which is denoted `CliffordAlgebra.lift Q f cond`. The canonical linear map `M → CliffordAlgebra Q` is denoted `CliffordAlgebra.ι Q`. ## Theorems The main theorems proved ensure that `CliffordAlgebra Q` satisfies the universal property of the Clifford algebra. 1. `ι_comp_lift` is the fact that the composition of `ι Q` with `lift Q f cond` agrees with `f`. 2. `lift_unique` ensures the uniqueness of `lift Q f cond` with respect to 1. ## Implementation details The Clifford algebra of `M` is constructed as a quotient of the tensor algebra, as follows. 1. We define a relation `CliffordAlgebra.Rel Q` on `TensorAlgebra R M`. This is the smallest relation which identifies squares of elements of `M` with `Q m`. 2. The Clifford algebra is the quotient of the tensor algebra by this relation. This file is almost identical to `Mathlib/LinearAlgebra/ExteriorAlgebra/Basic.lean`. -/ variable {R : Type*} [CommRing R] variable {M : Type*} [AddCommGroup M] [Module R M] variable (Q : QuadraticForm R M) namespace CliffordAlgebra open TensorAlgebra /-- `Rel` relates each `ι m * ι m`, for `m : M`, with `Q m`. The Clifford algebra of `M` is defined as the quotient modulo this relation. -/ inductive Rel : TensorAlgebra R M → TensorAlgebra R M → Prop | of (m : M) : Rel (ι R m * ι R m) (algebraMap R _ (Q m)) end CliffordAlgebra /-- The Clifford algebra of an `R`-module `M` equipped with a quadratic_form `Q`. -/ def CliffordAlgebra := RingQuot (CliffordAlgebra.Rel Q) namespace CliffordAlgebra -- The `Inhabited, Semiring, Algebra` instances should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 instance instInhabited : Inhabited (CliffordAlgebra Q) := RingQuot.instInhabited _ instance instRing : Ring (CliffordAlgebra Q) := RingQuot.instRing _ instance (priority := 900) instAlgebra' {R A M} [CommSemiring R] [AddCommGroup M] [CommRing A] [Algebra R A] [Module R M] [Module A M] (Q : QuadraticForm A M) [IsScalarTower R A M] : Algebra R (CliffordAlgebra Q) := RingQuot.instAlgebra _ -- verify there are no diamonds -- but doesn't work at `reducible_and_instances` https://github.com/leanprover-community/mathlib4/issues/10906 example : (Semiring.toNatAlgebra : Algebra ℕ (CliffordAlgebra Q)) = instAlgebra' _ := rfl -- but doesn't work at `reducible_and_instances` https://github.com/leanprover-community/mathlib4/issues/10906 example : (Ring.toIntAlgebra _ : Algebra â„€ (CliffordAlgebra Q)) = instAlgebra' _ := rfl -- shortcut instance, as the other instance is slow instance instAlgebra : Algebra R (CliffordAlgebra Q) := instAlgebra' _ instance {R S A M} [CommSemiring R] [CommSemiring S] [AddCommGroup M] [CommRing A] [Algebra R A] [Algebra S A] [Module R M] [Module S M] [Module A M] (Q : QuadraticForm A M) [IsScalarTower R A M] [IsScalarTower S A M] : SMulCommClass R S (CliffordAlgebra Q) := RingQuot.instSMulCommClass _ instance {R S A M} [CommSemiring R] [CommSemiring S] [AddCommGroup M] [CommRing A] [SMul R S] [Algebra R A] [Algebra S A] [Module R M] [Module S M] [Module A M] [IsScalarTower R A M] [IsScalarTower S A M] [IsScalarTower R S A] (Q : QuadraticForm A M) : IsScalarTower R S (CliffordAlgebra Q) := RingQuot.instIsScalarTower _ /-- The canonical linear map `M →ₗ[R] CliffordAlgebra Q`. -/ def ι : M →ₗ[R] CliffordAlgebra Q := (RingQuot.mkAlgHom R _).toLinearMap.comp (TensorAlgebra.ι R) /-- As well as being linear, `ι Q` squares to the quadratic form -/ @[simp] theorem ι_sq_scalar (m : M) : ι Q m * ι Q m = algebraMap R _ (Q m) := by rw [ι] erw [LinearMap.comp_apply] rw [AlgHom.toLinearMap_apply, ← map_mul (RingQuot.mkAlgHom R (Rel Q)), RingQuot.mkAlgHom_rel R (Rel.of m), AlgHom.commutes] rfl variable {Q} {A : Type*} [Semiring A] [Algebra R A] @[simp] theorem comp_ι_sq_scalar (g : CliffordAlgebra Q →ₐ[R] A) (m : M) : g (ι Q m) * g (ι Q m) = algebraMap _ _ (Q m) := by rw [← map_mul, ι_sq_scalar, AlgHom.commutes] variable (Q) in /-- Given a linear map `f : M →ₗ[R] A` into an `R`-algebra `A`, which satisfies the condition: `cond : ∀ m : M, f m * f m = Q(m)`, this is the canonical lift of `f` to a morphism of `R`-algebras from `CliffordAlgebra Q` to `A`. -/ @[simps symm_apply] def lift : { f : M →ₗ[R] A // ∀ m, f m * f m = algebraMap _ _ (Q m) } ≃ (CliffordAlgebra Q →ₐ[R] A) where toFun f := RingQuot.liftAlgHom R ⟹TensorAlgebra.lift R (f : M →ₗ[R] A), fun x y (h : Rel Q x y) => by induction h rw [AlgHom.commutes, map_mul, TensorAlgebra.lift_ι_apply, f.prop]⟩ invFun F := ⟹F.toLinearMap.comp (ι Q), fun m => by rw [LinearMap.comp_apply, AlgHom.toLinearMap_apply, comp_ι_sq_scalar]⟩ left_inv f := by ext x exact (RingQuot.liftAlgHom_mkAlgHom_apply _ _ _ _).trans (TensorAlgebra.lift_ι_apply _ x) right_inv F := RingQuot.ringQuot_ext' _ _ _ <| TensorAlgebra.hom_ext <| LinearMap.ext fun x ↩ (RingQuot.liftAlgHom_mkAlgHom_apply _ _ _ _).trans (TensorAlgebra.lift_ι_apply _ _) @[simp] theorem ι_comp_lift (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = algebraMap _ _ (Q m)) : (lift Q ⟹f, cond⟩).toLinearMap.comp (ι Q) = f := Subtype.mk_eq_mk.mp <| (lift Q).symm_apply_apply ⟹f, cond⟩ @[simp] theorem lift_ι_apply (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = algebraMap _ _ (Q m)) (x) : lift Q ⟹f, cond⟩ (ι Q x) = f x := (LinearMap.ext_iff.mp <| ι_comp_lift f cond) x @[simp] theorem lift_unique (f : M →ₗ[R] A) (cond : ∀ m : M, f m * f m = algebraMap _ _ (Q m)) (g : CliffordAlgebra Q →ₐ[R] A) : g.toLinearMap.comp (ι Q) = f ↔ g = lift Q ⟹f, cond⟩ := by convert (lift Q : _ ≃ (CliffordAlgebra Q →ₐ[R] A)).symm_apply_eq rw [lift_symm_apply, Subtype.mk_eq_mk] @[simp] theorem lift_comp_ι (g : CliffordAlgebra Q →ₐ[R] A) : lift Q ⟹g.toLinearMap.comp (ι Q), comp_ι_sq_scalar _⟩ = g := by exact (lift Q : _ ≃ (CliffordAlgebra Q →ₐ[R] A)).apply_symm_apply g /-- See note [partially-applied ext lemmas]. -/ @[ext high] theorem hom_ext {A : Type*} [Semiring A] [Algebra R A] {f g : CliffordAlgebra Q →ₐ[R] A} : f.toLinearMap.comp (ι Q) = g.toLinearMap.comp (ι Q) → f = g := by intro h apply (lift Q).symm.injective rw [lift_symm_apply, lift_symm_apply] simp only [h] -- This proof closely follows `TensorAlgebra.induction` /-- If `C` holds for the `algebraMap` of `r : R` into `CliffordAlgebra Q`, the `ι` of `x : M`, and is preserved under addition and multiplication, then it holds for all of `CliffordAlgebra Q`. See also the stronger `CliffordAlgebra.left_induction` and `CliffordAlgebra.right_induction`. -/ @[elab_as_elim] theorem induction {C : CliffordAlgebra Q → Prop} (algebraMap : ∀ r, C (algebraMap R (CliffordAlgebra Q) r)) (ι : ∀ x, C (ι Q x)) (mul : ∀ a b, C a → C b → C (a * b)) (add : ∀ a b, C a → C b → C (a + b)) (a : CliffordAlgebra Q) : C a := by -- the arguments are enough to construct a subalgebra, and a mapping into it from M let s : Subalgebra R (CliffordAlgebra Q) := { carrier := C mul_mem' := @mul add_mem' := @add algebraMap_mem' := algebraMap } let of : { f : M →ₗ[R] s // ∀ m, f m * f m = _root_.algebraMap _ _ (Q m) } := ⟹(CliffordAlgebra.ι Q).codRestrict (Subalgebra.toSubmodule s) ι, fun m => Subtype.eq <| ι_sq_scalar Q m⟩ -- the mapping through the subalgebra is the identity have of_id : s.val.comp (lift Q of) = AlgHom.id R (CliffordAlgebra Q) := by ext x simp [of] -- porting note: `simp` should fire with the following lemma automatically have := LinearMap.codRestrict_apply s.toSubmodule (CliffordAlgebra.ι Q) x (h := ι) exact this -- finding a proof is finding an element of the subalgebra rw [← AlgHom.id_apply (R := R) a, ← of_id] exact (lift Q of a).prop theorem mul_add_swap_eq_polar_of_forall_mul_self_eq {A : Type*} [Ring A] [Algebra R A] (f : M →ₗ[R] A) (hf : ∀ x, f x * f x = algebraMap _ _ (Q x)) (a b : M) : f a * f b + f b * f a = algebraMap R _ (QuadraticMap.polar Q a b) := calc f a * f b + f b * f a = f (a + b) * f (a + b) - f a * f a - f b * f b := by rw [f.map_add, mul_add, add_mul, add_mul]; abel _ = algebraMap R _ (Q (a + b)) - algebraMap R _ (Q a) - algebraMap R _ (Q b) := by rw [hf, hf, hf] _ = algebraMap R _ (Q (a + b) - Q a - Q b) := by rw [← RingHom.map_sub, ← RingHom.map_sub] _ = algebraMap R _ (QuadraticMap.polar Q a b) := rfl /-- An alternative way to provide the argument to `CliffordAlgebra.lift` when `2` is invertible. To show a function squares to the quadratic form, it suffices to show that `f x * f y + f y * f x = algebraMap _ _ (polar Q x y)` -/ theorem forall_mul_self_eq_iff {A : Type*} [Ring A] [Algebra R A] (h2 : IsUnit (2 : A)) (f : M →ₗ[R] A) : (∀ x, f x * f x = algebraMap _ _ (Q x)) ↔ (LinearMap.mul R A).compl₂ f ∘ₗ f + (LinearMap.mul R A).flip.compl₂ f ∘ₗ f = Q.polarBilin.compr₂ (Algebra.linearMap R A) := by simp_rw [DFunLike.ext_iff] refine ⟹mul_add_swap_eq_polar_of_forall_mul_self_eq _, fun h x => ?_⟩ change ∀ x y : M, f x * f y + f y * f x = algebraMap R A (QuadraticMap.polar Q x y) at h apply h2.mul_left_cancel rw [two_mul, two_mul, h x x, QuadraticMap.polar_self, two_smul, map_add] /-- The symmetric product of vectors is a scalar -/ theorem ι_mul_ι_add_swap (a b : M) : ι Q a * ι Q b + ι Q b * ι Q a = algebraMap R _ (QuadraticMap.polar Q a b) := mul_add_swap_eq_polar_of_forall_mul_self_eq _ (ι_sq_scalar _) _ _ theorem ι_mul_ι_comm (a b : M) : ι Q a * ι Q b = algebraMap R _ (QuadraticMap.polar Q a b) - ι Q b * ι Q a := eq_sub_of_add_eq (ι_mul_ι_add_swap a b) section isOrtho @[simp] theorem ι_mul_ι_add_swap_of_isOrtho {a b : M} (h : Q.IsOrtho a b) : ι Q a * ι Q b + ι Q b * ι Q a = 0 := by rw [ι_mul_ι_add_swap, h.polar_eq_zero] simp theorem ι_mul_ι_comm_of_isOrtho {a b : M} (h : Q.IsOrtho a b) : ι Q a * ι Q b = -(ι Q b * ι Q a) := eq_neg_of_add_eq_zero_left <| ι_mul_ι_add_swap_of_isOrtho h theorem mul_ι_mul_ι_of_isOrtho (x : CliffordAlgebra Q) {a b : M} (h : Q.IsOrtho a b) : x * ι Q a * ι Q b = -(x * ι Q b * ι Q a) := by rw [mul_assoc, ι_mul_ι_comm_of_isOrtho h, mul_neg, mul_assoc] theorem ι_mul_ι_mul_of_isOrtho (x : CliffordAlgebra Q) {a b : M} (h : Q.IsOrtho a b) : ι Q a * (ι Q b * x) = -(ι Q b * (ι Q a * x)) := by rw [← mul_assoc, ι_mul_ι_comm_of_isOrtho h, neg_mul, mul_assoc] end isOrtho /-- $aba$ is a vector. -/ theorem ι_mul_ι_mul_ι (a b : M) : ι Q a * ι Q b * ι Q a = ι Q (QuadraticMap.polar Q a b • a - Q a • b) := by rw [ι_mul_ι_comm, sub_mul, mul_assoc, ι_sq_scalar, ← Algebra.smul_def, ← Algebra.commutes, ← Algebra.smul_def, ← map_smul, ← map_smul, ← map_sub] @[simp] theorem ι_range_map_lift (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = algebraMap _ _ (Q m)) : (LinearMap.range (ι Q)).map (lift Q ⟹f, cond⟩).toLinearMap = LinearMap.range f := by rw [← LinearMap.range_comp, ι_comp_lift] section Map variable {M₁ M₂ M₃ : Type*} variable [AddCommGroup M₁] [AddCommGroup M₂] [AddCommGroup M₃] variable [Module R M₁] [Module R M₂] [Module R M₃] variable {Q₁ : QuadraticForm R M₁} {Q₂ : QuadraticForm R M₂} {Q₃ : QuadraticForm R M₃} /-- Any linear map that preserves the quadratic form lifts to an `AlgHom` between algebras. See `CliffordAlgebra.equivOfIsometry` for the case when `f` is a `QuadraticForm.IsometryEquiv`. -/ def map (f : Q₁ →qáµ¢ Q₂) : CliffordAlgebra Q₁ →ₐ[R] CliffordAlgebra Q₂ := CliffordAlgebra.lift Q₁ ⟚ι Q₂ ∘ₗ f.toLinearMap, fun m => (ι_sq_scalar _ _).trans <| RingHom.congr_arg _ <| f.map_app m⟩
@[simp] theorem map_comp_ι (f : Q₁ →qᵢ Q₂) : (map f).toLinearMap ∘ₗ ι Q₁ = ι Q₂ ∘ₗ f.toLinearMap := ι_comp_lift _ _
Mathlib/LinearAlgebra/CliffordAlgebra/Basic.lean
292
295
/- Copyright (c) 2024 Thomas Browning, Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning, Junyan Xu -/ import Mathlib.Algebra.Group.Subgroup.Ker import Mathlib.GroupTheory.GroupAction.Basic import Mathlib.GroupTheory.GroupAction.FixedPoints import Mathlib.GroupTheory.Perm.Support import Mathlib.Data.Set.Finite.Basic /-! # Subgroups generated by transpositions This file studies subgroups generated by transpositions. ## Main results - `swap_mem_closure_isSwap` : If a subgroup is generated by transpositions, then a transposition `swap x y` lies in the subgroup if and only if `x` lies in the same orbit as `y`. - `mem_closure_isSwap` : If a subgroup is generated by transpositions, then a permutation `f` lies in the subgroup if and only if `f` has finite support and `f x` always lies in the same orbit as `x`. -/ open Equiv List MulAction Pointwise Set Subgroup variable {G α : Type*} [Group G] [MulAction G α] /-- If the support of each element in a generating set of a permutation group is finite, then the support of every element in the group is finite. -/ theorem finite_compl_fixedBy_closure_iff {S : Set G} : (∀ g ∈ closure S, (fixedBy α g)ᶜ.Finite) ↔ ∀ g ∈ S, (fixedBy α g)ᶜ.Finite := ⟹fun h g hg ↩ h g (subset_closure hg), fun h g hg ↩ by refine closure_induction h (by simp) (fun g g' _ _ hg hg' ↩ (hg.union hg').subset ?_)
(by simp) hg simp_rw [← compl_inter, compl_subset_compl, fixedBy_mul]⟩
Mathlib/GroupTheory/Perm/ClosureSwap.lean
37
39
/- Copyright (c) 2020 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Andrew Yang -/ import Mathlib.CategoryTheory.Monoidal.Functor /-! # Endofunctors as a monoidal category. We give the monoidal category structure on `C ⥀ C`, and show that when `C` itself is monoidal, it embeds via a monoidal functor into `C ⥀ C`. ## TODO Can we use this to show coherence results, e.g. a cheap proof that `λ_ (𝟙_ C) = ρ_ (𝟙_ C)`? I suspect this is harder than is usually made out. -/ universe v u namespace CategoryTheory open Functor.LaxMonoidal Functor.OplaxMonoidal Functor.Monoidal variable (C : Type u) [Category.{v} C] /-- The category of endofunctors of any category is a monoidal category, with tensor product given by composition of functors (and horizontal composition of natural transformations). -/ def endofunctorMonoidalCategory : MonoidalCategory (C ⥀ C) where tensorObj F G := F ⋙ G whiskerLeft X _ _ F := whiskerLeft X F whiskerRight F X := whiskerRight F X tensorHom α β := α ◫ β tensorUnit := 𝟭 C associator F G H := Functor.associator F G H leftUnitor F := Functor.leftUnitor F rightUnitor F := Functor.rightUnitor F open CategoryTheory.MonoidalCategory attribute [local instance] endofunctorMonoidalCategory @[simp] theorem endofunctorMonoidalCategory_tensorUnit_obj (X : C) : (𝟙_ (C ⥀ C)).obj X = X := rfl @[simp] theorem endofunctorMonoidalCategory_tensorUnit_map {X Y : C} (f : X ⟶ Y) : (𝟙_ (C ⥀ C)).map f = f := rfl @[simp] theorem endofunctorMonoidalCategory_tensorObj_obj (F G : C ⥀ C) (X : C) : (F ⊗ G).obj X = G.obj (F.obj X) := rfl @[simp] theorem endofunctorMonoidalCategory_tensorObj_map (F G : C ⥀ C) {X Y : C} (f : X ⟶ Y) : (F ⊗ G).map f = G.map (F.map f) := rfl @[simp] theorem endofunctorMonoidalCategory_tensorMap_app {F G H K : C ⥀ C} {α : F ⟶ G} {β : H ⟶ K} (X : C) : (α ⊗ β).app X = β.app (F.obj X) ≫ K.map (α.app X) := rfl @[simp] theorem endofunctorMonoidalCategory_whiskerLeft_app {F H K : C ⥀ C} {β : H ⟶ K} (X : C) : (F ◁ β).app X = β.app (F.obj X) := rfl @[simp] theorem endofunctorMonoidalCategory_whiskerRight_app {F G H : C ⥀ C} {α : F ⟶ G} (X : C) : (α ▷ H).app X = H.map (α.app X) := rfl @[simp] theorem endofunctorMonoidalCategory_associator_hom_app (F G H : C ⥀ C) (X : C) : (α_ F G H).hom.app X = 𝟙 _ := rfl @[simp] theorem endofunctorMonoidalCategory_associator_inv_app (F G H : C ⥀ C) (X : C) : (α_ F G H).inv.app X = 𝟙 _ := rfl @[simp] theorem endofunctorMonoidalCategory_leftUnitor_hom_app (F : C ⥀ C) (X : C) : (λ_ F).hom.app X = 𝟙 _ := rfl @[simp] theorem endofunctorMonoidalCategory_leftUnitor_inv_app (F : C ⥀ C) (X : C) : (λ_ F).inv.app X = 𝟙 _ := rfl @[simp] theorem endofunctorMonoidalCategory_rightUnitor_hom_app (F : C ⥀ C) (X : C) : (ρ_ F).hom.app X = 𝟙 _ := rfl @[simp] theorem endofunctorMonoidalCategory_rightUnitor_inv_app (F : C ⥀ C) (X : C) : (ρ_ F).inv.app X = 𝟙 _ := rfl namespace MonoidalCategory variable [MonoidalCategory C] /-- Tensoring on the right gives a monoidal functor from `C` into endofunctors of `C`. -/ instance : (tensoringRight C).Monoidal := Functor.CoreMonoidal.toMonoidal { εIso := (rightUnitorNatIso C).symm ÎŒIso := fun X Y => (isoWhiskerRight (curriedAssociatorNatIso C) ((evaluation C (C ⥀ C)).obj X ⋙ (evaluation C C).obj Y)) } @[simp] lemma tensoringRight_ε : ε (tensoringRight C) = (rightUnitorNatIso C).inv := rfl @[simp] lemma tensoringRight_η : η (tensoringRight C) = (rightUnitorNatIso C).hom := rfl @[simp] lemma tensoringRight_ÎŒ (X Y : C) (Z : C) : (ÎŒ (tensoringRight C) X Y).app Z = (α_ Z X Y).hom := rfl @[simp] lemma tensoringRight_ÎŽ (X Y : C) (Z : C) : (ÎŽ (tensoringRight C) X Y).app Z = (α_ Z X Y).inv := rfl end MonoidalCategory variable {C} variable {M : Type*} [Category M] [MonoidalCategory M] (F : M ⥀ (C ⥀ C)) @[reassoc (attr := simp)] theorem ÎŒ_ÎŽ_app (i j : M) (X : C) [F.Monoidal] : (ÎŒ F i j).app X ≫ (ÎŽ F i j).app X = 𝟙 _ := (ÎŒIso F i j).hom_inv_id_app X @[reassoc (attr := simp)] theorem ÎŽ_ÎŒ_app (i j : M) (X : C) [F.Monoidal] : (ÎŽ F i j).app X ≫ (ÎŒ F i j).app X = 𝟙 _ := (ÎŒIso F i j).inv_hom_id_app X @[reassoc (attr := simp)] theorem ε_η_app (X : C) [F.Monoidal] : (ε F).app X ≫ (η F).app X = 𝟙 _ := (εIso F).hom_inv_id_app X @[reassoc (attr := simp)] theorem η_ε_app (X : C) [F.Monoidal] : (η F).app X ≫ (ε F).app X = 𝟙 _ := (εIso F).inv_hom_id_app X @[reassoc (attr := simp)] theorem ε_naturality {X Y : C} (f : X ⟶ Y) [F.LaxMonoidal] : (ε F).app X ≫ (F.obj (𝟙_ M)).map f = f ≫ (ε F).app Y := ((ε F).naturality f).symm @[reassoc (attr := simp)] theorem η_naturality {X Y : C} (f : X ⟶ Y) [F.OplaxMonoidal]: (η F).app X ≫ (𝟙_ (C ⥀ C)).map f = (η F).app X ≫ f := by simp @[reassoc (attr := simp)] theorem ÎŒ_naturality {m n : M} {X Y : C} (f : X ⟶ Y) [F.LaxMonoidal] : (F.obj n).map ((F.obj m).map f) ≫ (ÎŒ F m n).app Y = (ÎŒ F m n).app X ≫ (F.obj _).map f := (ÎŒ F m n).naturality f -- This is a simp lemma in the reverse direction via `NatTrans.naturality`. @[reassoc] theorem ÎŽ_naturality {m n : M} {X Y : C} (f : X ⟶ Y) [F.OplaxMonoidal]: (ÎŽ F m n).app X ≫ (F.obj n).map ((F.obj m).map f) = (F.obj _).map f ≫ (ÎŽ F m n).app Y := by simp -- This is not a simp lemma since it could be proved by the lemmas later. @[reassoc] theorem ÎŒ_naturality₂ {m n m' n' : M} (f : m ⟶ m') (g : n ⟶ n') (X : C) [F.LaxMonoidal] : (F.map g).app ((F.obj m).obj X) ≫ (F.obj n').map ((F.map f).app X) ≫ (ÎŒ F m' n').app X = (ÎŒ F m n).app X ≫ (F.map (f ⊗ g)).app X := by have := congr_app (ÎŒ_natural F f g) X dsimp at this simpa using this @[reassoc (attr := simp)] theorem ÎŒ_naturalityₗ {m n m' : M} (f : m ⟶ m') (X : C) [F.LaxMonoidal]: (F.obj n).map ((F.map f).app X) ≫ (ÎŒ F m' n).app X = (ÎŒ F m n).app X ≫ (F.map (f ▷ n)).app X := by rw [← tensorHom_id, ← ÎŒ_naturality₂ F f (𝟙 n) X] simp @[reassoc (attr := simp)] theorem ÎŒ_naturalityáµ£ {m n n' : M} (g : n ⟶ n') (X : C) [F.LaxMonoidal] : (F.map g).app ((F.obj m).obj X) ≫ (ÎŒ F m n').app X = (ÎŒ F m n).app X ≫ (F.map (m ◁ g)).app X := by rw [← id_tensorHom, ← ÎŒ_naturality₂ F (𝟙 m) g X] simp @[reassoc (attr := simp)] theorem ÎŽ_naturalityₗ {m n m' : M} (f : m ⟶ m') (X : C) [F.OplaxMonoidal] : (ÎŽ F m n).app X ≫ (F.obj n).map ((F.map f).app X) = (F.map (f ▷ n)).app X ≫ (ÎŽ F m' n).app X := congr_app (ÎŽ_natural_left F f n) X @[reassoc (attr := simp)] theorem ÎŽ_naturalityáµ£ {m n n' : M} (g : n ⟶ n') (X : C) [F.OplaxMonoidal]: (ÎŽ F m n).app X ≫ (F.map g).app ((F.obj m).obj X) = (F.map (m ◁ g)).app X ≫ (ÎŽ F m n').app X := congr_app (ÎŽ_natural_right F m g) X @[reassoc] theorem left_unitality_app (n : M) (X : C) [F.LaxMonoidal]: (F.obj n).map ((ε F).app X) ≫ (ÎŒ F (𝟙_ M) n).app X ≫ (F.map (λ_ n).hom).app X = 𝟙 _ := congr_app (left_unitality F n).symm X @[simp, reassoc] theorem obj_ε_app (n : M) (X : C) [F.Monoidal]: (F.obj n).map ((ε F).app X) = (F.map (λ_ n).inv).app X ≫ (ÎŽ F (𝟙_ M) n).app X := by rw [map_leftUnitor_inv] dsimp simp only [Category.id_comp, Category.assoc, ÎŒ_ÎŽ_app, endofunctorMonoidalCategory_tensorObj_obj, Category.comp_id] @[simp, reassoc] theorem obj_η_app (n : M) (X : C) [F.Monoidal] : (F.obj n).map ((η F).app X) = (ÎŒ F (𝟙_ M) n).app X ≫ (F.map (λ_ n).hom).app X := by rw [← cancel_mono ((F.obj n).map ((ε F).app X)), ← Functor.map_comp] simp @[reassoc] theorem right_unitality_app (n : M) (X : C) [F.Monoidal] : (ε F).app ((F.obj n).obj X) ≫ (ÎŒ F n (𝟙_ M)).app X ≫ (F.map (ρ_ n).hom).app X = 𝟙 _ := congr_app (Functor.LaxMonoidal.right_unitality F n).symm X @[simp] theorem ε_app_obj (n : M) (X : C) [F.Monoidal] : (ε F).app ((F.obj n).obj X) = (F.map (ρ_ n).inv).app X ≫ (ÎŽ F n (𝟙_ M)).app X := by rw [map_rightUnitor_inv] dsimp simp only [Category.id_comp, Category.assoc, ÎŒ_ÎŽ_app, endofunctorMonoidalCategory_tensorObj_obj, Category.comp_id] @[simp] theorem η_app_obj (n : M) (X : C) [F.Monoidal] : (η F).app ((F.obj n).obj X) = (ÎŒ F n (𝟙_ M)).app X ≫ (F.map (ρ_ n).hom).app X := by rw [map_rightUnitor] dsimp simp only [Category.comp_id, ÎŒ_ÎŽ_app_assoc] @[reassoc] theorem associativity_app (m₁ m₂ m₃ : M) (X : C) [F.LaxMonoidal] : (F.obj m₃).map ((ÎŒ F m₁ m₂).app X) ≫ (ÎŒ F (m₁ ⊗ m₂) m₃).app X ≫ (F.map (α_ m₁ m₂ m₃).hom).app X =
(ÎŒ F m₂ m₃).app ((F.obj m₁).obj X) ≫ (ÎŒ F m₁ (m₂ ⊗ m₃)).app X := by have := congr_app (associativity F m₁ m₂ m₃) X dsimp at this simpa using this
Mathlib/CategoryTheory/Monoidal/End.lean
235
238
/- Copyright (c) 2023 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Lorenzo Luccioli, Rémy Degenne, Alexander Bentkamp -/ import Mathlib.Analysis.SpecialFunctions.Gaussian.FourierTransform import Mathlib.Probability.Moments.ComplexMGF /-! # Gaussian distributions over ℝ We define a Gaussian measure over the reals. ## Main definitions * `gaussianPDFReal`: the function `ÎŒ v x ↩ (1 / (sqrt (2 * pi * v))) * exp (- (x - ÎŒ)^2 / (2 * v))`, which is the probability density function of a Gaussian distribution with mean `ÎŒ` and variance `v` (when `v ≠ 0`). * `gaussianPDF`: `ℝ≥0∞`-valued pdf, `gaussianPDF ÎŒ v x = ENNReal.ofReal (gaussianPDFReal ÎŒ v x)`. * `gaussianReal`: a Gaussian measure on `ℝ`, parametrized by its mean `ÎŒ` and variance `v`. If `v = 0`, this is `dirac ÎŒ`, otherwise it is defined as the measure with density `gaussianPDF ÎŒ v` with respect to the Lebesgue measure. ## Main results * `gaussianReal_add_const`: if `X` is a random variable with Gaussian distribution with mean `ÎŒ` and variance `v`, then `X + y` is Gaussian with mean `ÎŒ + y` and variance `v`. * `gaussianReal_const_mul`: if `X` is a random variable with Gaussian distribution with mean `ÎŒ` and variance `v`, then `c * X` is Gaussian with mean `c * ÎŒ` and variance `c^2 * v`. -/ open scoped ENNReal NNReal Real Complex open MeasureTheory namespace ProbabilityTheory section GaussianPDF /-- Probability density function of the gaussian distribution with mean `ÎŒ` and variance `v`. -/ noncomputable def gaussianPDFReal (ÎŒ : ℝ) (v : ℝ≥0) (x : ℝ) : ℝ := (√(2 * π * v))⁻¹ * rexp (- (x - ÎŒ)^2 / (2 * v)) lemma gaussianPDFReal_def (ÎŒ : ℝ) (v : ℝ≥0) : gaussianPDFReal ÎŒ v = fun x ↩ (Real.sqrt (2 * π * v))⁻¹ * rexp (- (x - ÎŒ)^2 / (2 * v)) := rfl @[simp] lemma gaussianPDFReal_zero_var (m : ℝ) : gaussianPDFReal m 0 = 0 := by ext1 x simp [gaussianPDFReal] /-- The gaussian pdf is positive when the variance is not zero. -/ lemma gaussianPDFReal_pos (ÎŒ : ℝ) (v : ℝ≥0) (x : ℝ) (hv : v ≠ 0) : 0 < gaussianPDFReal ÎŒ v x := by rw [gaussianPDFReal] positivity /-- The gaussian pdf is nonnegative. -/ lemma gaussianPDFReal_nonneg (ÎŒ : ℝ) (v : ℝ≥0) (x : ℝ) : 0 ≀ gaussianPDFReal ÎŒ v x := by rw [gaussianPDFReal] positivity /-- The gaussian pdf is measurable. -/ lemma measurable_gaussianPDFReal (ÎŒ : ℝ) (v : ℝ≥0) : Measurable (gaussianPDFReal ÎŒ v) := (((measurable_id.add_const _).pow_const _).neg.div_const _).exp.const_mul _ /-- The gaussian pdf is strongly measurable. -/ lemma stronglyMeasurable_gaussianPDFReal (ÎŒ : ℝ) (v : ℝ≥0) : StronglyMeasurable (gaussianPDFReal ÎŒ v) := (measurable_gaussianPDFReal ÎŒ v).stronglyMeasurable @[fun_prop] lemma integrable_gaussianPDFReal (ÎŒ : ℝ) (v : ℝ≥0) : Integrable (gaussianPDFReal ÎŒ v) := by rw [gaussianPDFReal_def] by_cases hv : v = 0 · simp [hv] let g : ℝ → ℝ := fun x ↩ (√(2 * π * v))⁻¹ * rexp (- x ^ 2 / (2 * v)) have hg : Integrable g := by suffices g = fun x ↩ (√(2 * π * v))⁻¹ * rexp (- (2 * v)⁻¹ * x ^ 2) by rw [this] refine (integrable_exp_neg_mul_sq ?_).const_mul (√(2 * π * v))⁻¹ simp [lt_of_le_of_ne (zero_le _) (Ne.symm hv)] ext x simp only [g, zero_lt_two, mul_nonneg_iff_of_pos_left, NNReal.zero_le_coe, Real.sqrt_mul', mul_inv_rev, NNReal.coe_mul, NNReal.coe_inv, NNReal.coe_ofNat, neg_mul, mul_eq_mul_left_iff, Real.exp_eq_exp, mul_eq_zero, inv_eq_zero, Real.sqrt_eq_zero, NNReal.coe_eq_zero, hv, false_or] rw [mul_comm] left field_simp exact Integrable.comp_sub_right hg ÎŒ /-- The gaussian distribution pdf integrates to 1 when the variance is not zero. -/ lemma lintegral_gaussianPDFReal_eq_one (ÎŒ : ℝ) {v : ℝ≥0} (h : v ≠ 0) : ∫⁻ x, ENNReal.ofReal (gaussianPDFReal ÎŒ v x) = 1 := by rw [← ENNReal.toReal_eq_one_iff] have hfm : AEStronglyMeasurable (gaussianPDFReal ÎŒ v) volume := (stronglyMeasurable_gaussianPDFReal ÎŒ v).aestronglyMeasurable have hf : 0 ≀ₐₛ gaussianPDFReal ÎŒ v := ae_of_all _ (gaussianPDFReal_nonneg ÎŒ v) rw [← integral_eq_lintegral_of_nonneg_ae hf hfm] simp only [gaussianPDFReal, zero_lt_two, mul_nonneg_iff_of_pos_right, one_div, Nat.cast_ofNat, integral_const_mul] rw [integral_sub_right_eq_self (ÎŒ := volume) (fun a ↩ rexp (-a ^ 2 / ((2 : ℝ) * v))) ÎŒ] simp only [zero_lt_two, mul_nonneg_iff_of_pos_right, div_eq_inv_mul, mul_inv_rev, mul_neg] simp_rw [← neg_mul] rw [neg_mul, integral_gaussian, ← Real.sqrt_inv, ← Real.sqrt_mul] · field_simp ring · positivity
/-- The gaussian distribution pdf integrates to 1 when the variance is not zero. -/ lemma integral_gaussianPDFReal_eq_one (ÎŒ : ℝ) {v : ℝ≥0} (hv : v ≠ 0) : ∫ x, gaussianPDFReal ÎŒ v x = 1 := by have h := lintegral_gaussianPDFReal_eq_one ÎŒ hv rw [← ofReal_integral_eq_lintegral_ofReal (integrable_gaussianPDFReal _ _) (ae_of_all _ (gaussianPDFReal_nonneg _ _)), ← ENNReal.ofReal_one] at h rwa [← ENNReal.ofReal_eq_ofReal_iff (integral_nonneg (gaussianPDFReal_nonneg _ _)) zero_le_one]
Mathlib/Probability/Distributions/Gaussian.lean
115
121
/- 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⟩ 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 /-- If `f` is a monomorphism, the pushforward-pullback adjunction on sieves is coreflective. -/ def galoisCoinsertionOfMono (f : Y ⟶ X) [Mono f] : GaloisCoinsertion (Sieve.pushforward f) (Sieve.pullback f) := by apply (galoisConnection f).toGaloisCoinsertion rintro S Z g ⟹g₁, hf, hg₁⟩ rw [cancel_mono f] at hf rwa [← hf] /-- If `f` is a split epi, the pushforward-pullback adjunction on sieves is reflective. -/ def galoisInsertionOfIsSplitEpi (f : Y ⟶ X) [IsSplitEpi f] : GaloisInsertion (Sieve.pushforward f) (Sieve.pullback f) := by apply (galoisConnection f).toGaloisInsertion intro S Z g hg exact ⟹g ≫ section_ f, by simpa⟩ theorem pullbackArrows_comm [HasPullbacks C] {X Y : C} (f : Y ⟶ X) (R : Presieve X) : Sieve.generate (R.pullbackArrows f) = (Sieve.generate R).pullback f := by ext W g constructor · rintro ⟹_, h, k, ⟹W, g, hg⟩, rfl⟩ rw [Sieve.pullback_apply, assoc, ← pullback.condition, ← assoc] exact Sieve.downward_closed _ (by exact Sieve.le_generate R W hg) (h ≫ pullback.fst g f) · rintro ⟹W, h, k, hk, comm⟩ exact ⟹_, _, _, Presieve.pullbackArrows.mk _ _ hk, pullback.lift_snd _ _ comm⟩ section Functor variable {E : Type u₃} [Category.{v₃} E] (G : D ⥀ E) /-- If `R` is a sieve, then the `CategoryTheory.Presieve.functorPullback` of `R` is actually a sieve. -/ @[simps] def functorPullback (R : Sieve (F.obj X)) : Sieve X where arrows := Presieve.functorPullback F R downward_closed := by intro _ _ f hf g unfold Presieve.functorPullback rw [F.map_comp] exact R.downward_closed hf (F.map g) @[simp] theorem functorPullback_arrows (R : Sieve (F.obj X)) : (R.functorPullback F).arrows = R.arrows.functorPullback F := rfl @[simp] theorem functorPullback_id (R : Sieve X) : R.functorPullback (𝟭 _) = R := by ext rfl theorem functorPullback_comp (R : Sieve ((F ⋙ G).obj X)) : R.functorPullback (F ⋙ G) = (R.functorPullback G).functorPullback F := by ext rfl theorem functorPushforward_extend_eq {R : Presieve X} : (generate R).arrows.functorPushforward F = R.functorPushforward F := by funext Y ext f constructor
· rintro ⟹X', g, f', ⟹X'', g', f'', h₁, rfl⟩, rfl⟩ exact ⟹X'', f'', f' ≫ F.map g', h₁, by simp⟩ · rintro ⟹X', g, f', h₁, h₂⟩
Mathlib/CategoryTheory/Sites/Sieves.lean
667
669
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Equivalence /-! # 2-commutative squares of functors Similarly as `CommSq.lean` defines the notion of commutative squares, this file introduces the notion of 2-commutative squares of functors. If `T : C₁ ⥀ C₂`, `L : C₁ ⥀ C₃`, `R : C₂ ⥀ C₄`, `B : C₃ ⥀ C₄` are functors, then `[CatCommSq T L R B]` contains the datum of an isomorphism `T ⋙ R ≅ L ⋙ B`. Future work: using this notion in the development of the localization of categories (e.g. localization of adjunctions). -/ namespace CategoryTheory open Category variable {C₁ C₂ C₃ C₄ C₅ C₆ : Type*} [Category C₁] [Category C₂] [Category C₃] [Category C₄] [Category C₅] [Category C₆] (T : C₁ ⥀ C₂) (L : C₁ ⥀ C₃) (R : C₂ ⥀ C₄) (B : C₃ ⥀ C₄) /-- `CatCommSq T L R B` expresses that there is a 2-commutative square of functors, where the functors `T`, `L`, `R` and `B` are respectively the left, top, right and bottom functors of the square. -/ @[ext] class CatCommSq where /-- the isomorphism corresponding to a 2-commutative diagram -/ iso' : T ⋙ R ≅ L ⋙ B namespace CatCommSq /-- Assuming `[CatCommSq T L R B]`, `iso T L R B` is the isomorphism `T ⋙ R ≅ L ⋙ B` given by the 2-commutative square. -/ -- This only exists to change the explicitness of the binders of the `iso'` field. abbrev iso [h : CatCommSq T L R B] : T ⋙ R ≅ L ⋙ B := h.iso' /-- Horizontal composition of 2-commutative squares -/ @[simps! iso'_hom_app iso'_inv_app] def hComp (T₁ : C₁ ⥀ C₂) (T₂ : C₂ ⥀ C₃) (V₁ : C₁ ⥀ C₄) (V₂ : C₂ ⥀ C₅) (V₃ : C₃ ⥀ C₆) (B₁ : C₄ ⥀ C₅) (B₂ : C₅ ⥀ C₆) [CatCommSq T₁ V₁ V₂ B₁] [CatCommSq T₂ V₂ V₃ B₂] : CatCommSq (T₁ ⋙ T₂) V₁ V₃ (B₁ ⋙ B₂) where iso' := Functor.associator _ _ _ ≪≫ isoWhiskerLeft T₁ (iso T₂ V₂ V₃ B₂) ≪≫ (Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (iso T₁ V₁ V₂ B₁) B₂ ≪≫ Functor.associator _ _ _ /-- Vertical composition of 2-commutative squares -/ @[simps! iso'_hom_app iso'_inv_app] def vComp (L₁ : C₁ ⥀ C₂) (L₂ : C₂ ⥀ C₃) (H₁ : C₁ ⥀ C₄) (H₂ : C₂ ⥀ C₅) (H₃ : C₃ ⥀ C₆) (R₁ : C₄ ⥀ C₅) (R₂ : C₅ ⥀ C₆) [CatCommSq H₁ L₁ R₁ H₂] [CatCommSq H₂ L₂ R₂ H₃] : CatCommSq H₁ (L₁ ⋙ L₂) (R₁ ⋙ R₂) H₃ where iso' := (Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (iso H₁ L₁ R₁ H₂) R₂ ≪≫ Functor.associator _ _ _ ≪≫ isoWhiskerLeft L₁ (iso H₂ L₂ R₂ H₃) ≪≫ (Functor.associator _ _ _).symm section variable (T : C₁ ≌ C₂) (L : C₁ ⥀ C₃) (R : C₂ ⥀ C₄) (B : C₃ ≌ C₄) /-- Horizontal inverse of a 2-commutative square -/ @[simps! iso'_hom_app iso'_inv_app] def hInv (_ : CatCommSq T.functor L R B.functor) : CatCommSq T.inverse R L B.inverse where iso' := isoWhiskerLeft _ (L.rightUnitor.symm ≪≫ isoWhiskerLeft L B.unitIso ≪≫ (Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (iso T.functor L R B.functor).symm B.inverse ≪≫ Functor.associator _ _ _ ) ≪≫ (Functor.associator _ _ _).symm ≪≫ isoWhiskerRight T.counitIso _ ≪≫ Functor.leftUnitor _
lemma hInv_hInv (h : CatCommSq T.functor L R B.functor) : hInv T.symm R L B.symm (hInv T L R B h) = h := by ext X rw [← cancel_mono (B.functor.map (L.map (T.unitIso.hom.app X)))] rw [← Functor.comp_map] erw [← h.iso'.hom.naturality (T.unitIso.hom.app X)] rw [hInv_iso'_hom_app] simp only [Equivalence.symm_functor] rw [hInv_iso'_inv_app] dsimp
Mathlib/CategoryTheory/CatCommSq.lean
75
85
/- 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] 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] theorem whisker_assoc_symm (X : C) {Y Y' : C} (f : Y ⟶ Y') (Z : C) : X ◁ f ▷ Z = (α_ X Y Z).inv ≫ (X ◁ f) ▷ Z ≫ (α_ X Y' Z).hom := by simp @[reassoc] theorem associator_naturality_right (X Y : C) {Z Z' : C} (f : Z ⟶ Z') : (X ⊗ Y) ◁ f ≫ (α_ X Y Z').hom = (α_ X Y Z).hom ≫ X ◁ Y ◁ f := by simp @[reassoc] theorem associator_inv_naturality_right (X Y : C) {Z Z' : C} (f : Z ⟶ Z') : X ◁ Y ◁ f ≫ (α_ X Y Z').inv = (α_ X Y Z).inv ≫ (X ⊗ Y) ◁ f := by simp @[reassoc] theorem tensor_whiskerLeft_symm (X Y : C) {Z Z' : C} (f : Z ⟶ Z') : X ◁ Y ◁ f = (α_ X Y Z).inv ≫ (X ⊗ Y) ◁ f ≫ (α_ X Y Z').hom := by simp @[reassoc] theorem leftUnitor_inv_naturality {X Y : C} (f : X ⟶ Y) : f ≫ (λ_ Y).inv = (λ_ X).inv ≫ _ ◁ f := by simp @[reassoc] theorem id_whiskerLeft_symm {X X' : C} (f : X ⟶ X') : f = (λ_ X).inv ≫ 𝟙_ C ◁ f ≫ (λ_ X').hom := by simp only [id_whiskerLeft, assoc, inv_hom_id, comp_id, inv_hom_id_assoc] @[reassoc] theorem rightUnitor_inv_naturality {X X' : C} (f : X ⟶ X') : f ≫ (ρ_ X').inv = (ρ_ X).inv ≫ f ▷ _ := by simp @[reassoc] theorem whiskerRight_id_symm {X Y : C} (f : X ⟶ Y) : f = (ρ_ X).inv ≫ f ▷ 𝟙_ C ≫ (ρ_ Y).hom := by simp theorem whiskerLeft_iff {X Y : C} (f g : X ⟶ Y) : 𝟙_ C ◁ f = 𝟙_ C ◁ g ↔ f = g := by simp theorem whiskerRight_iff {X Y : C} (f g : X ⟶ Y) : f ▷ 𝟙_ C = g ▷ 𝟙_ C ↔ f = g := by simp /-! The lemmas in the next section are true by coherence, but we prove them directly as they are used in proving the coherence theorem. -/ section @[reassoc (attr := simp)] theorem pentagon_inv : W ◁ (α_ X Y Z).inv ≫ (α_ W (X ⊗ Y) Z).inv ≫ (α_ W X Y).inv ▷ Z = (α_ W X (Y ⊗ Z)).inv ≫ (α_ (W ⊗ X) Y Z).inv := eq_of_inv_eq_inv (by simp)
@[reassoc (attr := simp)] theorem pentagon_inv_inv_hom_hom_inv :
Mathlib/CategoryTheory/Monoidal/Category.lean
504
505
/- Copyright (c) 2024 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.Group.Action.Pi import Mathlib.Algebra.Group.End import Mathlib.Algebra.Module.NatInt import Mathlib.Algebra.Order.Archimedean.Basic /-! # Maps (semi)conjugating a shift to a shift Denote by $S^1$ the unit circle `UnitAddCircle`. A common way to study a self-map $f\colon S^1\to S^1$ of degree `1` is to lift it to a map $\tilde f\colon \mathbb R\to \mathbb R$ such that $\tilde f(x + 1) = \tilde f(x)+1$ for all `x`. In this file we define a structure and a typeclass for bundled maps satisfying `f (x + a) = f x + b`. We use parameters `a` and `b` instead of `1` to accommodate for two use cases: - maps between circles of different lengths; - self-maps $f\colon S^1\to S^1$ of degree other than one, including orientation-reversing maps. -/ assert_not_exists Finset open Function Set /-- A bundled map `f : G → H` such that `f (x + a) = f x + b` for all `x`, denoted as `f: G →+c[a, b] H`. One can think about `f` as a lift to `G` of a map between two `AddCircle`s. -/ structure AddConstMap (G H : Type*) [Add G] [Add H] (a : G) (b : H) where /-- The underlying function of an `AddConstMap`. Use automatic coercion to function instead. -/ protected toFun : G → H /-- An `AddConstMap` satisfies `f (x + a) = f x + b`. Use `map_add_const` instead. -/ map_add_const' (x : G) : toFun (x + a) = toFun x + b @[inherit_doc] scoped [AddConstMap] notation:25 G " →+c[" a ", " b "] " H => AddConstMap G H a b /-- Typeclass for maps satisfying `f (x + a) = f x + b`. Note that `a` and `b` are `outParam`s, so one should not add instances like `[AddConstMapClass F G H a b] : AddConstMapClass F G H (-a) (-b)`. -/ class AddConstMapClass (F : Type*) (G H : outParam Type*) [Add G] [Add H] (a : outParam G) (b : outParam H) [FunLike F G H] : Prop where /-- A map of `AddConstMapClass` class semiconjugates shift by `a` to the shift by `b`: `∀ x, f (x + a) = f x + b`. -/ map_add_const (f : F) (x : G) : f (x + a) = f x + b namespace AddConstMapClass /-! ### Properties of `AddConstMapClass` maps In this section we prove properties like `f (x + n • a) = f x + n • b`. -/ scoped [AddConstMapClass] attribute [simp] map_add_const variable {F G H : Type*} [FunLike F G H] {a : G} {b : H} protected theorem semiconj [Add G] [Add H] [AddConstMapClass F G H a b] (f : F) : Semiconj f (· + a) (· + b) := map_add_const f @[scoped simp] theorem map_add_nsmul [AddMonoid G] [AddMonoid H] [AddConstMapClass F G H a b] (f : F) (x : G) (n : ℕ) : f (x + n • a) = f x + n • b := by simpa using (AddConstMapClass.semiconj f).iterate_right n x @[scoped simp] theorem map_add_nat' [AddMonoidWithOne G] [AddMonoid H] [AddConstMapClass F G H 1 b] (f : F) (x : G) (n : ℕ) : f (x + n) = f x + n • b := by simp [← map_add_nsmul] theorem map_add_one [AddMonoidWithOne G] [Add H] [AddConstMapClass F G H 1 b] (f : F) (x : G) : f (x + 1) = f x + b := map_add_const f x @[scoped simp] theorem map_add_ofNat' [AddMonoidWithOne G] [AddMonoid H] [AddConstMapClass F G H 1 b] (f : F) (x : G) (n : ℕ) [n.AtLeastTwo] : f (x + ofNat(n)) = f x + (ofNat(n) : ℕ) • b := map_add_nat' f x n theorem map_add_nat [AddMonoidWithOne G] [AddMonoidWithOne H] [AddConstMapClass F G H 1 1] (f : F) (x : G) (n : ℕ) : f (x + n) = f x + n := by simp theorem map_add_ofNat [AddMonoidWithOne G] [AddMonoidWithOne H] [AddConstMapClass F G H 1 1] (f : F) (x : G) (n : ℕ) [n.AtLeastTwo] : f (x + ofNat(n)) = f x + ofNat(n) := map_add_nat f x n @[scoped simp] theorem map_const [AddZeroClass G] [Add H] [AddConstMapClass F G H a b] (f : F) : f a = f 0 + b := by simpa using map_add_const f 0 theorem map_one [AddZeroClass G] [One G] [Add H] [AddConstMapClass F G H 1 b] (f : F) : f 1 = f 0 + b := map_const f @[scoped simp] theorem map_nsmul_const [AddMonoid G] [AddMonoid H] [AddConstMapClass F G H a b] (f : F) (n : ℕ) : f (n • a) = f 0 + n • b := by simpa using map_add_nsmul f 0 n @[scoped simp] theorem map_nat' [AddMonoidWithOne G] [AddMonoid H] [AddConstMapClass F G H 1 b] (f : F) (n : ℕ) : f n = f 0 + n • b := by simpa using map_add_nat' f 0 n theorem map_ofNat' [AddMonoidWithOne G] [AddMonoid H] [AddConstMapClass F G H 1 b] (f : F) (n : ℕ) [n.AtLeastTwo] : f (ofNat(n)) = f 0 + (ofNat(n) : ℕ) • b := map_nat' f n theorem map_nat [AddMonoidWithOne G] [AddMonoidWithOne H] [AddConstMapClass F G H 1 1] (f : F) (n : ℕ) : f n = f 0 + n := by simp theorem map_ofNat [AddMonoidWithOne G] [AddMonoidWithOne H] [AddConstMapClass F G H 1 1] (f : F) (n : ℕ) [n.AtLeastTwo] : f ofNat(n) = f 0 + ofNat(n) := map_nat f n @[scoped simp] theorem map_const_add [AddCommMagma G] [Add H] [AddConstMapClass F G H a b] (f : F) (x : G) : f (a + x) = f x + b := by rw [add_comm, map_add_const] theorem map_one_add [AddCommMonoidWithOne G] [Add H] [AddConstMapClass F G H 1 b] (f : F) (x : G) : f (1 + x) = f x + b := map_const_add f x @[scoped simp] theorem map_nsmul_add [AddCommMonoid G] [AddMonoid H] [AddConstMapClass F G H a b] (f : F) (n : ℕ) (x : G) : f (n • a + x) = f x + n • b := by rw [add_comm, map_add_nsmul] @[scoped simp] theorem map_nat_add' [AddCommMonoidWithOne G] [AddMonoid H] [AddConstMapClass F G H 1 b] (f : F) (n : ℕ) (x : G) : f (↑n + x) = f x + n • b := by simpa using map_nsmul_add f n x theorem map_ofNat_add' [AddCommMonoidWithOne G] [AddMonoid H] [AddConstMapClass F G H 1 b] (f : F) (n : ℕ) [n.AtLeastTwo] (x : G) : f (ofNat(n) + x) = f x + ofNat(n) • b := map_nat_add' f n x theorem map_nat_add [AddCommMonoidWithOne G] [AddMonoidWithOne H] [AddConstMapClass F G H 1 1] (f : F) (n : ℕ) (x : G) : f (↑n + x) = f x + n := by simp theorem map_ofNat_add [AddCommMonoidWithOne G] [AddMonoidWithOne H] [AddConstMapClass F G H 1 1] (f : F) (n : ℕ) [n.AtLeastTwo] (x : G) : f (ofNat(n) + x) = f x + ofNat(n) := map_nat_add f n x @[scoped simp] theorem map_sub_nsmul [AddGroup G] [AddGroup H] [AddConstMapClass F G H a b] (f : F) (x : G) (n : ℕ) : f (x - n • a) = f x - n • b := by conv_rhs => rw [← sub_add_cancel x (n • a), map_add_nsmul, add_sub_cancel_right] @[scoped simp] theorem map_sub_const [AddGroup G] [AddGroup H] [AddConstMapClass F G H a b] (f : F) (x : G) : f (x - a) = f x - b := by simpa using map_sub_nsmul f x 1 theorem map_sub_one [AddGroup G] [One G] [AddGroup H] [AddConstMapClass F G H 1 b] (f : F) (x : G) : f (x - 1) = f x - b := map_sub_const f x @[scoped simp] theorem map_sub_nat' [AddGroupWithOne G] [AddGroup H] [AddConstMapClass F G H 1 b] (f : F) (x : G) (n : ℕ) : f (x - n) = f x - n • b := by simpa using map_sub_nsmul f x n @[scoped simp] theorem map_sub_ofNat' [AddGroupWithOne G] [AddGroup H] [AddConstMapClass F G H 1 b] (f : F) (x : G) (n : ℕ) [n.AtLeastTwo] : f (x - ofNat(n)) = f x - ofNat(n) • b := map_sub_nat' f x n @[scoped simp] theorem map_add_zsmul [AddGroup G] [AddGroup H] [AddConstMapClass F G H a b] (f : F) (x : G) : ∀ n : â„€, f (x + n • a) = f x + n • b | (n : ℕ) => by simp | .negSucc n => by simp [← sub_eq_add_neg] @[scoped simp] theorem map_zsmul_const [AddGroup G] [AddGroup H] [AddConstMapClass F G H a b] (f : F) (n : â„€) : f (n • a) = f 0 + n • b := by simpa using map_add_zsmul f 0 n @[scoped simp] theorem map_add_int' [AddGroupWithOne G] [AddGroup H] [AddConstMapClass F G H 1 b] (f : F) (x : G) (n : â„€) : f (x + n) = f x + n • b := by rw [← map_add_zsmul f x n, zsmul_one] theorem map_add_int [AddGroupWithOne G] [AddGroupWithOne H] [AddConstMapClass F G H 1 1] (f : F) (x : G) (n : â„€) : f (x + n) = f x + n := by simp @[scoped simp] theorem map_sub_zsmul [AddGroup G] [AddGroup H] [AddConstMapClass F G H a b] (f : F) (x : G) (n : â„€) : f (x - n • a) = f x - n • b := by simpa [sub_eq_add_neg] using map_add_zsmul f x (-n) @[scoped simp] theorem map_sub_int' [AddGroupWithOne G] [AddGroup H] [AddConstMapClass F G H 1 b] (f : F) (x : G) (n : â„€) : f (x - n) = f x - n • b := by rw [← map_sub_zsmul, zsmul_one]
theorem map_sub_int [AddGroupWithOne G] [AddGroupWithOne H] [AddConstMapClass F G H 1 1]
Mathlib/Algebra/AddConstMap/Basic.lean
214
215
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Kexing Ying, Eric Wieser -/ import Mathlib.Data.Finset.Sym import Mathlib.LinearAlgebra.BilinearMap import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas import Mathlib.LinearAlgebra.Matrix.Determinant.Basic import Mathlib.LinearAlgebra.Matrix.SesquilinearForm import Mathlib.LinearAlgebra.Matrix.Symmetric /-! # Quadratic maps This file defines quadratic maps on an `R`-module `M`, taking values in an `R`-module `N`. An `N`-valued quadratic map on a module `M` over a commutative ring `R` is a map `Q : M → N` such that: * `QuadraticMap.map_smul`: `Q (a • x) = (a * a) • Q x` * `QuadraticMap.polar_add_left`, `QuadraticMap.polar_add_right`, `QuadraticMap.polar_smul_left`, `QuadraticMap.polar_smul_right`: the map `QuadraticMap.polar Q := fun x y ↩ Q (x + y) - Q x - Q y` is bilinear. This notion generalizes to commutative semirings using the approach in [izhakian2016][] which requires that there be a (possibly non-unique) companion bilinear map `B` such that `∀ x y, Q (x + y) = Q x + Q y + B x y`. Over a ring, this `B` is precisely `QuadraticMap.polar Q`. To build a `QuadraticMap` from the `polar` axioms, use `QuadraticMap.ofPolar`. Quadratic maps come with a scalar multiplication, `(a • Q) x = a • Q x`, and composition with linear maps `f`, `Q.comp f x = Q (f x)`. ## Main definitions * `QuadraticMap.ofPolar`: a more familiar constructor that works on rings * `QuadraticMap.associated`: associated bilinear map * `QuadraticMap.PosDef`: positive definite quadratic maps * `QuadraticMap.Anisotropic`: anisotropic quadratic maps * `QuadraticMap.discr`: discriminant of a quadratic map * `QuadraticMap.IsOrtho`: orthogonality of vectors with respect to a quadratic map. ## Main statements * `QuadraticMap.associated_left_inverse`, * `QuadraticMap.associated_rightInverse`: in a commutative ring where 2 has an inverse, there is a correspondence between quadratic maps and symmetric bilinear forms * `LinearMap.BilinForm.exists_orthogonal_basis`: There exists an orthogonal basis with respect to any nondegenerate, symmetric bilinear map `B`. ## Notation In this file, the variable `R` is used when a `CommSemiring` structure is available. The variable `S` is used when `R` itself has a `•` action. ## Implementation notes While the definition and many results make sense if we drop commutativity assumptions, the correct definition of a quadratic maps in the noncommutative setting would require substantial refactors from the current version, such that $Q(rm) = rQ(m)r^*$ for some suitable conjugation $r^*$. The [Zulip thread](https://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/Quadratic.20Maps/near/395529867) has some further discussion. ## References * https://en.wikipedia.org/wiki/Quadratic_form * https://en.wikipedia.org/wiki/Discriminant#Quadratic_forms ## Tags quadratic map, homogeneous polynomial, quadratic polynomial -/ universe u v w variable {S T : Type*} variable {R : Type*} {M N P A : Type*} open LinearMap (BilinMap BilinForm) section Polar variable [CommRing R] [AddCommGroup M] [AddCommGroup N] namespace QuadraticMap /-- Up to a factor 2, `Q.polar` is the associated bilinear map for a quadratic map `Q`. Source of this name: https://en.wikipedia.org/wiki/Quadratic_form#Generalization -/ def polar (f : M → N) (x y : M) := f (x + y) - f x - f y protected theorem map_add (f : M → N) (x y : M) : f (x + y) = f x + f y + polar f x y := by rw [polar] abel theorem polar_add (f g : M → N) (x y : M) : polar (f + g) x y = polar f x y + polar g x y := by simp only [polar, Pi.add_apply] abel theorem polar_neg (f : M → N) (x y : M) : polar (-f) x y = -polar f x y := by simp only [polar, Pi.neg_apply, sub_eq_add_neg, neg_add] theorem polar_smul [Monoid S] [DistribMulAction S N] (f : M → N) (s : S) (x y : M) : polar (s • f) x y = s • polar f x y := by simp only [polar, Pi.smul_apply, smul_sub] theorem polar_comm (f : M → N) (x y : M) : polar f x y = polar f y x := by rw [polar, polar, add_comm, sub_sub, sub_sub, add_comm (f x) (f y)] /-- Auxiliary lemma to express bilinearity of `QuadraticMap.polar` without subtraction. -/ theorem polar_add_left_iff {f : M → N} {x x' y : M} : polar f (x + x') y = polar f x y + polar f x' y ↔ f (x + x' + y) + (f x + f x' + f y) = f (x + x') + f (x' + y) + f (y + x) := by simp only [← add_assoc] simp only [polar, sub_eq_iff_eq_add, eq_sub_iff_add_eq, sub_add_eq_add_sub, add_sub] simp only [add_right_comm _ (f y) _, add_right_comm _ (f x') (f x)] rw [add_comm y x, add_right_comm _ _ (f (x + y)), add_comm _ (f (x + y)), add_right_comm (f (x + y)), add_left_inj] theorem polar_comp {F : Type*} [AddCommGroup S] [FunLike F N S] [AddMonoidHomClass F N S] (f : M → N) (g : F) (x y : M) : polar (g ∘ f) x y = g (polar f x y) := by simp only [polar, Pi.smul_apply, Function.comp_apply, map_sub] /-- `QuadraticMap.polar` as a function from `Sym2`. -/ def polarSym2 (f : M → N) : Sym2 M → N := Sym2.lift ⟹polar f, polar_comm _⟩ @[simp] lemma polarSym2_sym2Mk (f : M → N) (xy : M × M) : polarSym2 f (.mk xy) = polar f xy.1 xy.2 := rfl end QuadraticMap end Polar /-- A quadratic map on a module. For a more familiar constructor when `R` is a ring, see `QuadraticMap.ofPolar`. -/ structure QuadraticMap (R : Type u) (M : Type v) (N : Type w) [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] where toFun : M → N toFun_smul : ∀ (a : R) (x : M), toFun (a • x) = (a * a) • toFun x exists_companion' : ∃ B : BilinMap R M N, ∀ x y, toFun (x + y) = toFun x + toFun y + B x y section QuadraticForm variable (R : Type u) (M : Type v) [CommSemiring R] [AddCommMonoid M] [Module R M] /-- A quadratic form on a module. -/ abbrev QuadraticForm : Type _ := QuadraticMap R M R end QuadraticForm namespace QuadraticMap section DFunLike variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] variable {Q Q' : QuadraticMap R M N} instance instFunLike : FunLike (QuadraticMap R M N) M N where coe := toFun coe_injective' x y h := by cases x; cases y; congr variable (Q) /-- The `simp` normal form for a quadratic map is `DFunLike.coe`, not `toFun`. -/ @[simp] theorem toFun_eq_coe : Q.toFun = ⇑Q := rfl -- this must come after the coe_to_fun definition initialize_simps_projections QuadraticMap (toFun → apply) variable {Q} @[ext] theorem ext (H : ∀ x : M, Q x = Q' x) : Q = Q' := DFunLike.ext _ _ H theorem congr_fun (h : Q = Q') (x : M) : Q x = Q' x := DFunLike.congr_fun h _ /-- Copy of a `QuadraticMap` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (Q : QuadraticMap R M N) (Q' : M → N) (h : Q' = ⇑Q) : QuadraticMap R M N where toFun := Q' toFun_smul := h.symm ▾ Q.toFun_smul exists_companion' := h.symm ▾ Q.exists_companion' @[simp] theorem coe_copy (Q : QuadraticMap R M N) (Q' : M → N) (h : Q' = ⇑Q) : ⇑(Q.copy Q' h) = Q' := rfl theorem copy_eq (Q : QuadraticMap R M N) (Q' : M → N) (h : Q' = ⇑Q) : Q.copy Q' h = Q := DFunLike.ext' h end DFunLike section CommSemiring variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] variable (Q : QuadraticMap R M N) protected theorem map_smul (a : R) (x : M) : Q (a • x) = (a * a) • Q x := Q.toFun_smul a x theorem exists_companion : ∃ B : BilinMap R M N, ∀ x y, Q (x + y) = Q x + Q y + B x y := Q.exists_companion' theorem map_add_add_add_map (x y z : M) : Q (x + y + z) + (Q x + Q y + Q z) = Q (x + y) + Q (y + z) + Q (z + x) := by obtain ⟹B, h⟩ := Q.exists_companion rw [add_comm z x] simp only [h, LinearMap.map_add₂] abel theorem map_add_self (x : M) : Q (x + x) = 4 • Q x := by rw [← two_smul R x, Q.map_smul, ← Nat.cast_smul_eq_nsmul R] norm_num -- not @[simp] because it is superseded by `ZeroHomClass.map_zero` protected theorem map_zero : Q 0 = 0 := by rw [← @zero_smul R _ _ _ _ (0 : M), Q.map_smul, zero_mul, zero_smul] instance zeroHomClass : ZeroHomClass (QuadraticMap R M N) M N := { QuadraticMap.instFunLike (R := R) (M := M) (N := N) with map_zero := QuadraticMap.map_zero } theorem map_smul_of_tower [CommSemiring S] [Algebra S R] [SMul S M] [IsScalarTower S R M] [Module S N] [IsScalarTower S R N] (a : S) (x : M) : Q (a • x) = (a * a) • Q x := by rw [← IsScalarTower.algebraMap_smul R a x, Q.map_smul, ← RingHom.map_mul, algebraMap_smul] end CommSemiring section CommRing variable [CommRing R] [AddCommGroup M] [AddCommGroup N] variable [Module R M] [Module R N] (Q : QuadraticMap R M N) @[simp] protected theorem map_neg (x : M) : Q (-x) = Q x := by rw [← @neg_one_smul R _ _ _ _ x, Q.map_smul, neg_one_mul, neg_neg, one_smul] protected theorem map_sub (x y : M) : Q (x - y) = Q (y - x) := by rw [← neg_sub, Q.map_neg] @[simp] theorem polar_zero_left (y : M) : polar Q 0 y = 0 := by simp only [polar, zero_add, QuadraticMap.map_zero, sub_zero, sub_self] @[simp] theorem polar_add_left (x x' y : M) : polar Q (x + x') y = polar Q x y + polar Q x' y := polar_add_left_iff.mpr <| Q.map_add_add_add_map x x' y @[simp] theorem polar_smul_left (a : R) (x y : M) : polar Q (a • x) y = a • polar Q x y := by obtain ⟹B, h⟩ := Q.exists_companion simp_rw [polar, h, Q.map_smul, LinearMap.map_smul₂, sub_sub, add_sub_cancel_left] @[simp] theorem polar_neg_left (x y : M) : polar Q (-x) y = -polar Q x y := by rw [← neg_one_smul R x, polar_smul_left, neg_one_smul] @[simp] theorem polar_sub_left (x x' y : M) : polar Q (x - x') y = polar Q x y - polar Q x' y := by rw [sub_eq_add_neg, sub_eq_add_neg, polar_add_left, polar_neg_left] @[simp] theorem polar_zero_right (y : M) : polar Q y 0 = 0 := by simp only [add_zero, polar, QuadraticMap.map_zero, sub_self] @[simp] theorem polar_add_right (x y y' : M) : polar Q x (y + y') = polar Q x y + polar Q x y' := by rw [polar_comm Q x, polar_comm Q x, polar_comm Q x, polar_add_left] @[simp] theorem polar_smul_right (a : R) (x y : M) : polar Q x (a • y) = a • polar Q x y := by rw [polar_comm Q x, polar_comm Q x, polar_smul_left] @[simp] theorem polar_neg_right (x y : M) : polar Q x (-y) = -polar Q x y := by rw [← neg_one_smul R y, polar_smul_right, neg_one_smul] @[simp] theorem polar_sub_right (x y y' : M) : polar Q x (y - y') = polar Q x y - polar Q x y' := by rw [sub_eq_add_neg, sub_eq_add_neg, polar_add_right, polar_neg_right] @[simp] theorem polar_self (x : M) : polar Q x x = 2 • Q x := by rw [polar, map_add_self, sub_sub, sub_eq_iff_eq_add, ← two_smul ℕ, ← two_smul ℕ, ← mul_smul] norm_num /-- `QuadraticMap.polar` as a bilinear map -/ @[simps!] def polarBilin : BilinMap R M N := LinearMap.mk₂ R (polar Q) (polar_add_left Q) (polar_smul_left Q) (polar_add_right Q) (polar_smul_right Q) lemma polarSym2_map_smul {ι} (Q : QuadraticMap R M N) (g : ι → M) (l : ι → R) (p : Sym2 ι) : polarSym2 Q (p.map (l • g)) = (p.map l).mul • polarSym2 Q (p.map g) := by obtain ⟹_, _⟩ := p; simp [← smul_assoc, mul_comm] variable [CommSemiring S] [Algebra S R] [Module S M] [IsScalarTower S R M] [Module S N] [IsScalarTower S R N] @[simp] theorem polar_smul_left_of_tower (a : S) (x y : M) : polar Q (a • x) y = a • polar Q x y := by rw [← IsScalarTower.algebraMap_smul R a x, polar_smul_left, algebraMap_smul] @[simp] theorem polar_smul_right_of_tower (a : S) (x y : M) : polar Q x (a • y) = a • polar Q x y := by rw [← IsScalarTower.algebraMap_smul R a y, polar_smul_right, algebraMap_smul] /-- An alternative constructor to `QuadraticMap.mk`, for rings where `polar` can be used. -/ @[simps] def ofPolar (toFun : M → N) (toFun_smul : ∀ (a : R) (x : M), toFun (a • x) = (a * a) • toFun x) (polar_add_left : ∀ x x' y : M, polar toFun (x + x') y = polar toFun x y + polar toFun x' y) (polar_smul_left : ∀ (a : R) (x y : M), polar toFun (a • x) y = a • polar toFun x y) : QuadraticMap R M N := { toFun toFun_smul exists_companion' := ⟹LinearMap.mk₂ R (polar toFun) (polar_add_left) (polar_smul_left) (fun x _ _ ↩ by simp_rw [polar_comm _ x, polar_add_left]) (fun _ _ _ ↩ by rw [polar_comm, polar_smul_left, polar_comm]), fun _ _ ↩ by simp only [LinearMap.mk₂_apply] rw [polar, sub_sub, add_sub_cancel]⟩ } /-- In a ring the companion bilinear form is unique and equal to `QuadraticMap.polar`. -/ theorem choose_exists_companion : Q.exists_companion.choose = polarBilin Q := LinearMap.ext₂ fun x y => by rw [polarBilin_apply_apply, polar, Q.exists_companion.choose_spec, sub_sub, add_sub_cancel_left] protected theorem map_sum {ι} [DecidableEq ι] (Q : QuadraticMap R M N) (s : Finset ι) (f : ι → M) : Q (∑ i ∈ s, f i) = ∑ i ∈ s, Q (f i) + ∑ ij ∈ s.sym2 with ¬ ij.IsDiag, polarSym2 Q (ij.map f) := by induction s using Finset.cons_induction with | empty => simp | cons a s ha ih => simp_rw [Finset.sum_cons, QuadraticMap.map_add, ih, add_assoc, Finset.sym2_cons, Finset.sum_filter, Finset.sum_disjUnion, Finset.sum_map, Finset.sum_cons, Sym2.mkEmbedding_apply, Sym2.isDiag_iff_proj_eq, not_true, if_false, zero_add, Sym2.map_pair_eq, polarSym2_sym2Mk, ← polarBilin_apply_apply, _root_.map_sum, polarBilin_apply_apply] congr 2 rw [add_comm] congr! with i hi rw [if_pos (ne_of_mem_of_not_mem hi ha).symm] protected theorem map_sum' {ι} (Q : QuadraticMap R M N) (s : Finset ι) (f : ι → M) : Q (∑ i ∈ s, f i) = ∑ ij ∈ s.sym2, polarSym2 Q (ij.map f) - ∑ i ∈ s, Q (f i) := by induction s using Finset.cons_induction with | empty => simp | cons a s ha ih => simp_rw [Finset.sum_cons, QuadraticMap.map_add Q, ih, add_assoc, Finset.sym2_cons, Finset.sum_disjUnion, Finset.sum_map, Finset.sum_cons, Sym2.mkEmbedding_apply, Sym2.map_pair_eq, polarSym2_sym2Mk, ← polarBilin_apply_apply, _root_.map_sum, polarBilin_apply_apply, polar_self] abel_nf end CommRing section SemiringOperators variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] section SMul variable [Monoid S] [Monoid T] [DistribMulAction S N] [DistribMulAction T N] variable [SMulCommClass S R N] [SMulCommClass T R N] /-- `QuadraticMap R M N` inherits the scalar action from any algebra over `R`. This provides an `R`-action via `Algebra.id`. -/ instance : SMul S (QuadraticMap R M N) := ⟹fun a Q => { toFun := a • ⇑Q toFun_smul := fun b x => by rw [Pi.smul_apply, Q.map_smul, Pi.smul_apply, smul_comm] exists_companion' := let ⟹B, h⟩ := Q.exists_companion letI := SMulCommClass.symm S R N ⟹a • B, by simp [h]⟩ }⟩ @[simp] theorem coeFn_smul (a : S) (Q : QuadraticMap R M N) : ⇑(a • Q) = a • ⇑Q := rfl @[simp] theorem smul_apply (a : S) (Q : QuadraticMap R M N) (x : M) : (a • Q) x = a • Q x := rfl instance [SMulCommClass S T N] : SMulCommClass S T (QuadraticMap R M N) where smul_comm _s _t _q := ext fun _ => smul_comm _ _ _ instance [SMul S T] [IsScalarTower S T N] : IsScalarTower S T (QuadraticMap R M N) where smul_assoc _s _t _q := ext fun _ => smul_assoc _ _ _ end SMul instance : Zero (QuadraticMap R M N) := ⟹{ toFun := fun _ => 0 toFun_smul := fun a _ => by simp only [smul_zero] exists_companion' := ⟹0, fun _ _ => by simp only [add_zero, LinearMap.zero_apply]⟩ }⟩ @[simp] theorem coeFn_zero : ⇑(0 : QuadraticMap R M N) = 0 := rfl @[simp] theorem zero_apply (x : M) : (0 : QuadraticMap R M N) x = 0 := rfl instance : Inhabited (QuadraticMap R M N) := ⟹0⟩ instance : Add (QuadraticMap R M N) := ⟹fun Q Q' => { toFun := Q + Q' toFun_smul := fun a x => by simp only [Pi.add_apply, smul_add, QuadraticMap.map_smul] exists_companion' := let ⟹B, h⟩ := Q.exists_companion let ⟹B', h'⟩ := Q'.exists_companion ⟹B + B', fun x y => by simp_rw [Pi.add_apply, h, h', LinearMap.add_apply, add_add_add_comm]⟩ }⟩ @[simp] theorem coeFn_add (Q Q' : QuadraticMap R M N) : ⇑(Q + Q') = Q + Q' := rfl @[simp] theorem add_apply (Q Q' : QuadraticMap R M N) (x : M) : (Q + Q') x = Q x + Q' x := rfl instance : AddCommMonoid (QuadraticMap R M N) := DFunLike.coe_injective.addCommMonoid _ coeFn_zero coeFn_add fun _ _ => coeFn_smul _ _ /-- `@CoeFn (QuadraticMap R M)` as an `AddMonoidHom`. This API mirrors `AddMonoidHom.coeFn`. -/ @[simps apply] def coeFnAddMonoidHom : QuadraticMap R M N →+ M → N where toFun := DFunLike.coe map_zero' := coeFn_zero map_add' := coeFn_add /-- Evaluation on a particular element of the module `M` is an additive map on quadratic maps. -/ @[simps! apply] def evalAddMonoidHom (m : M) : QuadraticMap R M N →+ N := (Pi.evalAddMonoidHom _ m).comp coeFnAddMonoidHom section Sum @[simp] theorem coeFn_sum {ι : Type*} (Q : ι → QuadraticMap R M N) (s : Finset ι) : ⇑(∑ i ∈ s, Q i) = ∑ i ∈ s, ⇑(Q i) := map_sum coeFnAddMonoidHom Q s @[simp] theorem sum_apply {ι : Type*} (Q : ι → QuadraticMap R M N) (s : Finset ι) (x : M) : (∑ i ∈ s, Q i) x = ∑ i ∈ s, Q i x := map_sum (evalAddMonoidHom x : _ →+ N) Q s end Sum instance [Monoid S] [DistribMulAction S N] [SMulCommClass S R N] : DistribMulAction S (QuadraticMap R M N) where mul_smul a b Q := ext fun x => by simp only [smul_apply, mul_smul] one_smul Q := ext fun x => by simp only [QuadraticMap.smul_apply, one_smul] smul_add a Q Q' := by ext simp only [add_apply, smul_apply, smul_add] smul_zero a := by ext simp only [zero_apply, smul_apply, smul_zero] instance [Semiring S] [Module S N] [SMulCommClass S R N] : Module S (QuadraticMap R M N) where zero_smul Q := by ext simp only [zero_apply, smul_apply, zero_smul] add_smul a b Q := by ext simp only [add_apply, smul_apply, add_smul] end SemiringOperators section RingOperators variable [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] instance : Neg (QuadraticMap R M N) := ⟹fun Q => { toFun := -Q toFun_smul := fun a x => by simp only [Pi.neg_apply, Q.map_smul, smul_neg] exists_companion' := let ⟹B, h⟩ := Q.exists_companion ⟹-B, fun x y => by simp_rw [Pi.neg_apply, h, LinearMap.neg_apply, neg_add]⟩ }⟩ @[simp] theorem coeFn_neg (Q : QuadraticMap R M N) : ⇑(-Q) = -Q := rfl @[simp] theorem neg_apply (Q : QuadraticMap R M N) (x : M) : (-Q) x = -Q x := rfl instance : Sub (QuadraticMap R M N) := ⟹fun Q Q' => (Q + -Q').copy (Q - Q') (sub_eq_add_neg _ _)⟩ @[simp] theorem coeFn_sub (Q Q' : QuadraticMap R M N) : ⇑(Q - Q') = Q - Q' := rfl @[simp] theorem sub_apply (Q Q' : QuadraticMap R M N) (x : M) : (Q - Q') x = Q x - Q' x := rfl instance : AddCommGroup (QuadraticMap R M N) := DFunLike.coe_injective.addCommGroup _ coeFn_zero coeFn_add coeFn_neg coeFn_sub (fun _ _ => coeFn_smul _ _) fun _ _ => coeFn_smul _ _ end RingOperators section restrictScalars variable [CommSemiring R] [CommSemiring S] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] [Module S M] [Module S N] [Algebra S R] variable [IsScalarTower S R M] [IsScalarTower S R N] /-- If `Q : M → N` is a quadratic map of `R`-modules and `R` is an `S`-algebra, then the restriction of scalars is a quadratic map of `S`-modules. -/ @[simps!] def restrictScalars (Q : QuadraticMap R M N) : QuadraticMap S M N where toFun x := Q x toFun_smul a x := by simp [map_smul_of_tower] exists_companion' := let ⟹B, h⟩ := Q.exists_companion ⟹B.restrictScalars₁₂ (S := R) (R' := S) (S' := S), fun x y => by simp only [LinearMap.restrictScalars₁₂_apply_apply, h]⟩ end restrictScalars section Comp variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] variable [AddCommMonoid P] [Module R P] /-- Compose the quadratic map with a linear function on the right. -/ def comp (Q : QuadraticMap R N P) (f : M →ₗ[R] N) : QuadraticMap R M P where toFun x := Q (f x) toFun_smul a x := by simp only [Q.map_smul, map_smul] exists_companion' := let ⟹B, h⟩ := Q.exists_companion ⟹B.compl₁₂ f f, fun x y => by simp_rw [f.map_add]; exact h (f x) (f y)⟩ @[simp] theorem comp_apply (Q : QuadraticMap R N P) (f : M →ₗ[R] N) (x : M) : (Q.comp f) x = Q (f x) := rfl /-- Compose a quadratic map with a linear function on the left. -/ @[simps +simpRhs] def _root_.LinearMap.compQuadraticMap (f : N →ₗ[R] P) (Q : QuadraticMap R M N) : QuadraticMap R M P where toFun x := f (Q x) toFun_smul b x := by simp only [Q.map_smul, map_smul] exists_companion' := let ⟹B, h⟩ := Q.exists_companion ⟹B.compr₂ f, fun x y => by simp only [h, map_add, LinearMap.compr₂_apply]⟩ /-- Compose a quadratic map with a linear function on the left. -/ @[simps! +simpRhs] def _root_.LinearMap.compQuadraticMap' [CommSemiring S] [Algebra S R] [Module S N] [Module S M] [IsScalarTower S R N] [IsScalarTower S R M] [Module S P] (f : N →ₗ[S] P) (Q : QuadraticMap R M N) : QuadraticMap S M P := _root_.LinearMap.compQuadraticMap f Q.restrictScalars /-- When `N` and `P` are equivalent, quadratic maps on `M` into `N` are equivalent to quadratic maps on `M` into `P`. See `LinearMap.BilinMap.congr₂` for the bilinear map version. -/ @[simps] def _root_.LinearEquiv.congrQuadraticMap (e : N ≃ₗ[R] P) : QuadraticMap R M N ≃ₗ[R] QuadraticMap R M P where toFun Q := e.compQuadraticMap Q invFun Q := e.symm.compQuadraticMap Q left_inv _ := ext fun _ => e.symm_apply_apply _ right_inv _ := ext fun _ => e.apply_symm_apply _ map_add' _ _ := ext fun _ => map_add e _ _ map_smul' _ _ := ext fun _ => e.map_smul _ _ @[simp] theorem _root_.LinearEquiv.congrQuadraticMap_refl : LinearEquiv.congrQuadraticMap (.refl R N) = .refl R (QuadraticMap R M N) := rfl @[simp] theorem _root_.LinearEquiv.congrQuadraticMap_symm (e : N ≃ₗ[R] P) : (LinearEquiv.congrQuadraticMap e (M := M)).symm = e.symm.congrQuadraticMap := rfl end Comp section NonUnitalNonAssocSemiring variable [CommSemiring R] [NonUnitalNonAssocSemiring A] [AddCommMonoid M] [Module R M] variable [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] /-- The product of linear maps into an `R`-algebra is a quadratic map. -/ def linMulLin (f g : M →ₗ[R] A) : QuadraticMap R M A where toFun := f * g toFun_smul a x := by rw [Pi.mul_apply, Pi.mul_apply, LinearMap.map_smulₛₗ, RingHom.id_apply, LinearMap.map_smulₛₗ, RingHom.id_apply, smul_mul_assoc, mul_smul_comm, ← smul_assoc, smul_eq_mul] exists_companion' := ⟹(LinearMap.mul R A).compl₁₂ f g + (LinearMap.mul R A).flip.compl₁₂ g f, fun x y => by simp only [Pi.mul_apply, map_add, left_distrib, right_distrib, LinearMap.add_apply, LinearMap.compl₁₂_apply, LinearMap.mul_apply', LinearMap.flip_apply] abel_nf⟩ @[simp] theorem linMulLin_apply (f g : M →ₗ[R] A) (x) : linMulLin f g x = f x * g x := rfl @[simp] theorem add_linMulLin (f g h : M →ₗ[R] A) : linMulLin (f + g) h = linMulLin f h + linMulLin g h := ext fun _ => add_mul _ _ _ @[simp] theorem linMulLin_add (f g h : M →ₗ[R] A) : linMulLin f (g + h) = linMulLin f g + linMulLin f h := ext fun _ => mul_add _ _ _ variable {N' : Type*} [AddCommMonoid N'] [Module R N'] @[simp] theorem linMulLin_comp (f g : M →ₗ[R] A) (h : N' →ₗ[R] M) : (linMulLin f g).comp h = linMulLin (f.comp h) (g.comp h) := rfl variable {n : Type*} /-- `sq` is the quadratic map sending the vector `x : A` to `x * x` -/ @[simps!] def sq : QuadraticMap R A A := linMulLin LinearMap.id LinearMap.id /-- `proj i j` is the quadratic map sending the vector `x : n → R` to `x i * x j` -/ def proj (i j : n) : QuadraticMap R (n → A) A := linMulLin (@LinearMap.proj _ _ _ (fun _ => A) _ _ i) (@LinearMap.proj _ _ _ (fun _ => A) _ _ j) @[simp] theorem proj_apply (i j : n) (x : n → A) : proj (R := R) i j x = x i * x j := rfl end NonUnitalNonAssocSemiring end QuadraticMap /-! ### Associated bilinear maps If multiplication by 2 is invertible on the target module `N` of `QuadraticMap R M N`, then there is a linear bijection `QuadraticMap.associated` between quadratic maps `Q` over `R` from `M` to `N` and symmetric bilinear maps `B : M →ₗ[R] M →ₗ[R] → N` such that `BilinMap.toQuadraticMap B = Q` (see `QuadraticMap.associated_rightInverse`). The associated bilinear map is half `Q.polarBilin` (see `QuadraticMap.two_nsmul_associated`); this is where the invertibility condition comes from. We spell the condition as `[Invertible (2 : Module.End R N)]`. Note that this makes the bijection available in more cases than the simpler condition `Invertible (2 : R)`, e.g., when `R = â„€` and `N = ℝ`. -/ namespace LinearMap namespace BilinMap open QuadraticMap open LinearMap (BilinMap) section Semiring variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] variable {N' : Type*} [AddCommMonoid N'] [Module R N'] /-- A bilinear map gives a quadratic map by applying the argument twice. -/ def toQuadraticMap (B : BilinMap R M N) : QuadraticMap R M N where toFun x := B x x toFun_smul a x := by simp only [map_smul, LinearMap.smul_apply, smul_smul] exists_companion' := ⟹B + LinearMap.flip B, fun x y => by simp [add_add_add_comm, add_comm]⟩ @[simp] theorem toQuadraticMap_apply (B : BilinMap R M N) (x : M) : B.toQuadraticMap x = B x x := rfl theorem toQuadraticMap_comp_same (B : BilinMap R M N) (f : N' →ₗ[R] M) : BilinMap.toQuadraticMap (B.compl₁₂ f f) = B.toQuadraticMap.comp f := rfl section variable (R M) @[simp] theorem toQuadraticMap_zero : (0 : BilinMap R M N).toQuadraticMap = 0 := rfl end @[simp] theorem toQuadraticMap_add (B₁ B₂ : BilinMap R M N) : (B₁ + B₂).toQuadraticMap = B₁.toQuadraticMap + B₂.toQuadraticMap := rfl @[simp] theorem toQuadraticMap_smul [Monoid S] [DistribMulAction S N] [SMulCommClass S R N] [SMulCommClass R S N] (a : S) (B : BilinMap R M N) : (a • B).toQuadraticMap = a • B.toQuadraticMap := rfl section variable (S R M) /-- `LinearMap.BilinMap.toQuadraticMap` as an additive homomorphism -/ @[simps] def toQuadraticMapAddMonoidHom : (BilinMap R M N) →+ QuadraticMap R M N where toFun := toQuadraticMap map_zero' := toQuadraticMap_zero _ _ map_add' := toQuadraticMap_add /-- `LinearMap.BilinMap.toQuadraticMap` as a linear map -/ @[simps!] def toQuadraticMapLinearMap [Semiring S] [Module S N] [SMulCommClass S R N] [SMulCommClass R S N] : (BilinMap R M N) →ₗ[S] QuadraticMap R M N where toFun := toQuadraticMap map_smul' := toQuadraticMap_smul map_add' := toQuadraticMap_add end @[simp] theorem toQuadraticMap_list_sum (B : List (BilinMap R M N)) : B.sum.toQuadraticMap = (B.map toQuadraticMap).sum := map_list_sum (toQuadraticMapAddMonoidHom R M) B @[simp] theorem toQuadraticMap_multiset_sum (B : Multiset (BilinMap R M N)) : B.sum.toQuadraticMap = (B.map toQuadraticMap).sum := map_multiset_sum (toQuadraticMapAddMonoidHom R M) B @[simp] theorem toQuadraticMap_sum {ι : Type*} (s : Finset ι) (B : ι → (BilinMap R M N)) : (∑ i ∈ s, B i).toQuadraticMap = ∑ i ∈ s, (B i).toQuadraticMap := map_sum (toQuadraticMapAddMonoidHom R M) B s @[simp] theorem toQuadraticMap_eq_zero {B : BilinMap R M N} : B.toQuadraticMap = 0 ↔ B.IsAlt := QuadraticMap.ext_iff end Semiring section Ring variable [CommRing R] [AddCommGroup M] [AddCommGroup N] [Module R M] [Module R N] variable {B : BilinMap R M N} @[simp] theorem toQuadraticMap_neg (B : BilinMap R M N) : (-B).toQuadraticMap = -B.toQuadraticMap := rfl @[simp] theorem toQuadraticMap_sub (B₁ B₂ : BilinMap R M N) : (B₁ - B₂).toQuadraticMap = B₁.toQuadraticMap - B₂.toQuadraticMap := rfl theorem polar_toQuadraticMap (x y : M) : polar (toQuadraticMap B) x y = B x y + B y x := by simp only [polar, toQuadraticMap_apply, map_add, add_apply, add_assoc, add_comm (B y x) _, add_sub_cancel_left, sub_eq_add_neg _ (B y y), add_neg_cancel_left] theorem polarBilin_toQuadraticMap : polarBilin (toQuadraticMap B) = B + flip B := LinearMap.ext₂ polar_toQuadraticMap @[simp] theorem _root_.QuadraticMap.toQuadraticMap_polarBilin (Q : QuadraticMap R M N) : toQuadraticMap (polarBilin Q) = 2 • Q := QuadraticMap.ext fun x => (polar_self _ x).trans <| by simp theorem _root_.QuadraticMap.polarBilin_injective (h : IsUnit (2 : R)) : Function.Injective (polarBilin : QuadraticMap R M N → _) := by intro Q₁ Q₂ h₁₂ apply h.smul_left_cancel.mp rw [show (2 : R) = (2 : ℕ) by rfl] simp_rw [Nat.cast_smul_eq_nsmul R, ← QuadraticMap.toQuadraticMap_polarBilin] exact congrArg toQuadraticMap h₁₂ section variable {N' : Type*} [AddCommGroup N'] [Module R N'] theorem _root_.QuadraticMap.polarBilin_comp (Q : QuadraticMap R N' N) (f : M →ₗ[R] N') : polarBilin (Q.comp f) = LinearMap.compl₁₂ (polarBilin Q) f f := LinearMap.ext₂ <| fun x y => by simp [polar] end variable {N' : Type*} [AddCommGroup N'] theorem _root_.LinearMap.compQuadraticMap_polar [CommSemiring S] [Algebra S R] [Module S N] [Module S N'] [IsScalarTower S R N] [Module S M] [IsScalarTower S R M] (f : N →ₗ[S] N') (Q : QuadraticMap R M N) (x y : M) : polar (f.compQuadraticMap' Q) x y = f (polar Q x y) := by simp [polar] variable [Module R N'] theorem _root_.LinearMap.compQuadraticMap_polarBilin (f : N →ₗ[R] N') (Q : QuadraticMap R M N) : (f.compQuadraticMap' Q).polarBilin = Q.polarBilin.compr₂ f := by ext rw [polarBilin_apply_apply, compr₂_apply, polarBilin_apply_apply, LinearMap.compQuadraticMap_polar] end Ring end BilinMap end LinearMap namespace QuadraticMap open LinearMap (BilinMap) section variable [Semiring R] [AddCommMonoid M] [Module R M] instance : SMulCommClass R (Submonoid.center R) M where smul_comm r r' m := by simp_rw [Submonoid.smul_def, smul_smul, (Set.mem_center_iff.1 r'.prop).1] /-- If `2` is invertible in `R`, then it is also invertible in `End R M`. -/ instance [Invertible (2 : R)] : Invertible (2 : Module.End R M) where invOf := (⟹⅟2, Set.invOf_mem_center (Set.ofNat_mem_center _ _)⟩ : Submonoid.center R) • (1 : Module.End R M) invOf_mul_self := by ext m dsimp [Submonoid.smul_def] rw [← ofNat_smul_eq_nsmul R, invOf_smul_smul (2 : R) m] mul_invOf_self := by ext m dsimp [Submonoid.smul_def] rw [← ofNat_smul_eq_nsmul R, smul_invOf_smul (2 : R) m] /-- If `2` is invertible in `R`, then applying the inverse of `2` in `End R M` to an element of `M` is the same as multiplying by the inverse of `2` in `R`. -/ @[simp] lemma half_moduleEnd_apply_eq_half_smul [Invertible (2 : R)] (x : M) : ⅟ (2 : Module.End R M) x = ⅟ (2 : R) • x := rfl end section AssociatedHom variable [CommRing R] [AddCommGroup M] [Module R M] variable [AddCommGroup N] [Module R N] variable (S) [CommSemiring S] [Algebra S R] [Module S N] [IsScalarTower S R N] -- the requirement that multiplication by `2` is invertible on the target module `N` variable [Invertible (2 : Module.End R N)] /-- `associatedHom` is the map that sends a quadratic map on a module `M` over `R` to its associated symmetric bilinear map. As provided here, this has the structure of an `S`-linear map where `S` is a commutative ring and `R` is an `S`-algebra. Over a commutative ring, use `QuadraticMap.associated`, which gives an `R`-linear map. Over a general ring with no nontrivial distinguished commutative subring, use `QuadraticMap.associated'`, which gives an additive homomorphism (or more precisely a `â„€`-linear map.) -/ def associatedHom : QuadraticMap R M N →ₗ[S] (BilinMap R M N) where toFun Q := ⅟ (2 : Module.End R N) • polarBilin Q map_add' _ _ := LinearMap.ext₂ fun _ _ ↩ by simp [polar_add] map_smul' _ _ := LinearMap.ext₂ fun _ _ ↩ by simp [polar_smul] variable (Q : QuadraticMap R M N) @[simp] theorem associated_apply (x y : M) : associatedHom S Q x y = ⅟ (2 : Module.End R N) • (Q (x + y) - Q x - Q y) := rfl /-- Twice the associated bilinear map of `Q` is the same as the polar of `Q`. -/ @[simp] theorem two_nsmul_associated : 2 • associatedHom S Q = Q.polarBilin := by ext dsimp rw [← LinearMap.smul_apply, nsmul_eq_mul, Nat.cast_ofNat, mul_invOf_self', Module.End.one_apply, polar] theorem associated_isSymm (Q : QuadraticMap R M N) (x y : M) : associatedHom S Q x y = associatedHom S Q y x := by simp only [associated_apply, sub_eq_add_neg, add_assoc, add_comm, add_left_comm] theorem _root_.QuadraticForm.associated_isSymm (Q : QuadraticForm R M) [Invertible (2 : R)] : (associatedHom S Q).IsSymm := QuadraticMap.associated_isSymm S Q /-- A version of `QuadraticMap.associated_isSymm` for general targets (using `flip` because `IsSymm` does not apply here). -/ lemma associated_flip : (associatedHom S Q).flip = associatedHom S Q := by ext simp only [LinearMap.flip_apply, associated_apply, add_comm, sub_eq_add_neg, add_left_comm, add_assoc] @[simp] theorem associated_comp {N' : Type*} [AddCommGroup N'] [Module R N'] (f : N' →ₗ[R] M) : associatedHom S (Q.comp f) = (associatedHom S Q).compl₁₂ f f := by ext simp only [associated_apply, comp_apply, map_add, LinearMap.compl₁₂_apply] theorem associated_toQuadraticMap (B : BilinMap R M N) (x y : M) : associatedHom S B.toQuadraticMap x y = ⅟ (2 : Module.End R N) • (B x y + B y x) := by simp only [associated_apply, BilinMap.toQuadraticMap_apply, map_add, LinearMap.add_apply, Module.End.smul_def, map_sub] abel_nf theorem associated_left_inverse {B₁ : BilinMap R M N} (h : ∀ x y, B₁ x y = B₁ y x) : associatedHom S B₁.toQuadraticMap = B₁ := LinearMap.ext₂ fun x y ↩ by rw [associated_toQuadraticMap, ← h x y, ← two_smul R, invOf_smul_eq_iff, two_smul, two_smul] /-- A version of `QuadraticMap.associated_left_inverse` for general targets. -/ lemma associated_left_inverse' {B₁ : BilinMap R M N} (hB₁ : B₁.flip = B₁) : associatedHom S B₁.toQuadraticMap = B₁ := by ext _ y rw [associated_toQuadraticMap, ← LinearMap.flip_apply _ y, hB₁, invOf_smul_eq_iff, two_smul] theorem associated_eq_self_apply (x : M) : associatedHom S Q x x = Q x := by rw [associated_apply, map_add_self, ← three_add_one_eq_four, ← two_add_one_eq_three, add_smul, add_smul, one_smul, add_sub_cancel_right, add_sub_cancel_right, two_smul, ← two_smul R, invOf_smul_eq_iff, two_smul, two_smul] theorem toQuadraticMap_associated : (associatedHom S Q).toQuadraticMap = Q := QuadraticMap.ext <| associated_eq_self_apply S Q -- note: usually `rightInverse` lemmas are named the other way around, but this is consistent -- with historical naming in this file. theorem associated_rightInverse : Function.RightInverse (associatedHom S) (BilinMap.toQuadraticMap : _ → QuadraticMap R M N) := toQuadraticMap_associated S /-- `associated'` is the `â„€`-linear map that sends a quadratic form on a module `M` over `R` to its associated symmetric bilinear form. -/ abbrev associated' : QuadraticMap R M N →ₗ[â„€] BilinMap R M N := associatedHom â„€ /-- Symmetric bilinear forms can be lifted to quadratic forms -/ instance canLift [Invertible (2 : R)] : CanLift (BilinMap R M R) (QuadraticForm R M) (associatedHom ℕ) LinearMap.IsSymm where prf B hB := ⟹B.toQuadraticMap, associated_left_inverse _ hB⟩ /-- Symmetric bilinear maps can be lifted to quadratic maps -/ instance canLift' : CanLift (BilinMap R M N) (QuadraticMap R M N) (associatedHom ℕ) fun B ↩ B.flip = B where prf B hB := ⟹B.toQuadraticMap, associated_left_inverse' _ hB⟩ /-- There exists a non-null vector with respect to any quadratic form `Q` whose associated bilinear form is non-zero, i.e. there exists `x` such that `Q x ≠ 0`. -/ theorem exists_quadraticMap_ne_zero {Q : QuadraticMap R M N} -- Porting note: added implicit argument (hB₁ : associated' (N := N) Q ≠ 0) : ∃ x, Q x ≠ 0 := by rw [← not_forall] intro h apply hB₁ rw [(QuadraticMap.ext h : Q = 0), LinearMap.map_zero] end AssociatedHom section Associated variable [CommSemiring S] [CommRing R] [AddCommGroup M] [Algebra S R] [Module R M] variable [AddCommGroup N] [Module R N] [Module S N] [IsScalarTower S R N] variable [Invertible (2 : Module.End R N)] -- Note: When possible, rather than writing lemmas about `associated`, write a lemma applying to -- the more general `associatedHom` and place it in the previous section. /-- `associated` is the linear map that sends a quadratic map over a commutative ring to its associated symmetric bilinear map. -/ abbrev associated : QuadraticMap R M N →ₗ[R] BilinMap R M N := associatedHom R variable (S) in theorem coe_associatedHom : ⇑(associatedHom S : QuadraticMap R M N →ₗ[S] BilinMap R M N) = associated := rfl open LinearMap in @[simp] theorem associated_linMulLin [Invertible (2 : R)] (f g : M →ₗ[R] R) : associated (R := R) (N := R) (linMulLin f g) = ⅟ (2 : R) • ((mul R R).compl₁₂ f g + (mul R R).compl₁₂ g f) := by ext simp only [associated_apply, linMulLin_apply, map_add, smul_add, LinearMap.add_apply, LinearMap.smul_apply, compl₁₂_apply, mul_apply', smul_eq_mul, invOf_smul_eq_iff] simp only [smul_add, Module.End.smul_def, Module.End.ofNat_apply, nsmul_eq_mul, Nat.cast_ofNat, mul_invOf_cancel_left'] ring_nf open LinearMap in @[simp] lemma associated_sq [Invertible (2 : R)] : associated (R := R) sq = mul R R := (associated_linMulLin (id) (id)).trans <| by simp only [smul_add, invOf_two_smul_add_invOf_two_smul]; rfl end Associated section IsOrtho /-! ### Orthogonality -/ section CommSemiring variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] {Q : QuadraticMap R M N} /-- The proposition that two elements of a quadratic map space are orthogonal. -/ def IsOrtho (Q : QuadraticMap R M N) (x y : M) : Prop := Q (x + y) = Q x + Q y theorem isOrtho_def {Q : QuadraticMap R M N} {x y : M} : Q.IsOrtho x y ↔ Q (x + y) = Q x + Q y := Iff.rfl theorem IsOrtho.all (x y : M) : IsOrtho (0 : QuadraticMap R M N) x y := (zero_add _).symm theorem IsOrtho.zero_left (x : M) : IsOrtho Q (0 : M) x := by simp [isOrtho_def] theorem IsOrtho.zero_right (x : M) : IsOrtho Q x (0 : M) := by simp [isOrtho_def] theorem ne_zero_of_not_isOrtho_self {Q : QuadraticMap R M N} (x : M) (hx₁ : ¬Q.IsOrtho x x) : x ≠ 0 := fun hx₂ => hx₁ (hx₂.symm ▾ .zero_left _) theorem isOrtho_comm {x y : M} : IsOrtho Q x y ↔ IsOrtho Q y x := by simp_rw [isOrtho_def, add_comm] alias ⟹IsOrtho.symm, _⟩ := isOrtho_comm theorem _root_.LinearMap.BilinForm.toQuadraticMap_isOrtho [IsCancelAdd R] [NoZeroDivisors R] [CharZero R] {B : BilinMap R M R} {x y : M} (h : B.IsSymm) : B.toQuadraticMap.IsOrtho x y ↔ B.IsOrtho x y := by letI : AddCancelMonoid R := { ‹IsCancelAdd R›, (inferInstanceAs <| AddCommMonoid R) with } simp_rw [isOrtho_def, LinearMap.isOrtho_def, B.toQuadraticMap_apply, map_add, LinearMap.add_apply, add_comm _ (B y y), add_add_add_comm _ _ (B y y), add_comm (B y y)] rw [add_eq_left (a := B x x + B y y), ← h, RingHom.id_apply, add_self_eq_zero] end CommSemiring section CommRing variable [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] {Q : QuadraticMap R M N} @[simp] theorem isOrtho_polarBilin {x y : M} : Q.polarBilin.IsOrtho x y ↔ IsOrtho Q x y := by simp_rw [isOrtho_def, LinearMap.isOrtho_def, polarBilin_apply_apply, polar, sub_sub, sub_eq_zero] theorem IsOrtho.polar_eq_zero {x y : M} (h : IsOrtho Q x y) : polar Q x y = 0 := isOrtho_polarBilin.mpr h @[simp] theorem associated_isOrtho [Invertible (2 : R)] {x y : M} : Q.associated.IsOrtho x y ↔ Q.IsOrtho x y := by simp_rw [isOrtho_def, LinearMap.isOrtho_def, associated_apply, invOf_smul_eq_iff, smul_zero, sub_sub, sub_eq_zero] end CommRing end IsOrtho section Anisotropic section Semiring variable [CommSemiring R] [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N] /-- An anisotropic quadratic map is zero only on zero vectors. -/ def Anisotropic (Q : QuadraticMap R M N) : Prop := ∀ x, Q x = 0 → x = 0 theorem not_anisotropic_iff_exists (Q : QuadraticMap R M N) : ¬Anisotropic Q ↔ ∃ x, x ≠ 0 ∧ Q x = 0 := by simp only [Anisotropic, not_forall, exists_prop, and_comm] theorem Anisotropic.eq_zero_iff {Q : QuadraticMap R M N} (h : Anisotropic Q) {x : M} : Q x = 0 ↔ x = 0 := ⟹h x, fun h => h.symm ▾ map_zero Q⟩ end Semiring section Ring variable [CommRing R] [AddCommGroup M] [Module R M] /-- The associated bilinear form of an anisotropic quadratic form is nondegenerate. -/ theorem separatingLeft_of_anisotropic [Invertible (2 : R)] (Q : QuadraticMap R M R) (hB : Q.Anisotropic) : -- Porting note: added implicit argument (QuadraticMap.associated' (N := R) Q).SeparatingLeft := fun x hx ↩ hB _ <| by rw [← hx x] exact (associated_eq_self_apply _ _ x).symm end Ring end Anisotropic section PosDef variable {R₂ : Type u} [CommSemiring R₂] [AddCommMonoid M] [Module R₂ M] variable [PartialOrder N] [AddCommMonoid N] [Module R₂ N] variable {Q₂ : QuadraticMap R₂ M N} /-- A positive definite quadratic form is positive on nonzero vectors. -/ def PosDef (Q₂ : QuadraticMap R₂ M N) : Prop :=
∀ x, x ≠ 0 → 0 < Q₂ x theorem PosDef.smul {R} [CommSemiring R] [PartialOrder R]
Mathlib/LinearAlgebra/QuadraticForm/Basic.lean
1,125
1,128
/- 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.Data.Finset.NAry import Mathlib.Data.Finset.Slice import Mathlib.Data.Set.Sups /-! # Set family operations This file defines a few binary operations on `Finset α` for use in set family combinatorics. ## Main declarations * `Finset.sups s t`: Finset of elements of the form `a ⊔ b` where `a ∈ s`, `b ∈ t`. * `Finset.infs s t`: Finset of elements of the form `a ⊓ b` where `a ∈ s`, `b ∈ t`. * `Finset.disjSups s t`: Finset of elements of the form `a ⊔ b` where `a ∈ s`, `b ∈ t` and `a` and `b` are disjoint. * `Finset.diffs`: Finset of elements of the form `a \ b` where `a ∈ s`, `b ∈ t`. * `Finset.compls`: Finset of elements of the form `aᶜ` where `a ∈ s`. ## Notation We define the following notation in locale `FinsetFamily`: * `s ⊻ t` for `Finset.sups` * `s ⊌ t` for `Finset.infs` * `s ○ t` for `Finset.disjSups s t` * `s \\ t` for `Finset.diffs` * `sᶜˢ` for `Finset.compls` ## References [B. Bollobás, *Combinatorics*][bollobas1986] -/ open Function open SetFamily variable {F α β : Type*} namespace Finset section Sups variable [DecidableEq α] [DecidableEq β] variable [SemilatticeSup α] [SemilatticeSup β] [FunLike F α β] [SupHomClass F α β] variable (s s₁ s₂ t t₁ t₂ u v : Finset α) /-- `s ⊻ t` is the finset of elements of the form `a ⊔ b` where `a ∈ s`, `b ∈ t`. -/ protected def hasSups : HasSups (Finset α) := ⟹image₂ (· ⊔ ·)⟩ scoped[FinsetFamily] attribute [instance] Finset.hasSups open FinsetFamily variable {s t} {a b c : α} @[simp] theorem mem_sups : c ∈ s ⊻ t ↔ ∃ a ∈ s, ∃ b ∈ t, a ⊔ b = c := by simp [(· ⊻ ·)] variable (s t) @[simp, norm_cast] theorem coe_sups : (↑(s ⊻ t) : Set α) = ↑s ⊻ ↑t := coe_image₂ _ _ _ theorem card_sups_le : #(s ⊻ t) ≀ #s * #t := card_image₂_le _ _ _ theorem card_sups_iff : #(s ⊻ t) = #s * #t ↔ (s ×ˢ t : Set (α × α)).InjOn fun x => x.1 ⊔ x.2 := card_image₂_iff variable {s s₁ s₂ t t₁ t₂ u} theorem sup_mem_sups : a ∈ s → b ∈ t → a ⊔ b ∈ s ⊻ t := mem_image₂_of_mem theorem sups_subset : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ ⊻ t₁ ⊆ s₂ ⊻ t₂ := image₂_subset theorem sups_subset_left : t₁ ⊆ t₂ → s ⊻ t₁ ⊆ s ⊻ t₂ := image₂_subset_left theorem sups_subset_right : s₁ ⊆ s₂ → s₁ ⊻ t ⊆ s₂ ⊻ t := image₂_subset_right lemma image_subset_sups_left : b ∈ t → s.image (· ⊔ b) ⊆ s ⊻ t := image_subset_image₂_left lemma image_subset_sups_right : a ∈ s → t.image (a ⊔ ·) ⊆ s ⊻ t := image_subset_image₂_right theorem forall_sups_iff {p : α → Prop} : (∀ c ∈ s ⊻ t, p c) ↔ ∀ a ∈ s, ∀ b ∈ t, p (a ⊔ b) := forall_mem_image₂ @[simp] theorem sups_subset_iff : s ⊻ t ⊆ u ↔ ∀ a ∈ s, ∀ b ∈ t, a ⊔ b ∈ u := image₂_subset_iff @[simp] theorem sups_nonempty : (s ⊻ t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := image₂_nonempty_iff @[aesop safe apply (rule_sets := [finsetNonempty])] protected theorem Nonempty.sups : s.Nonempty → t.Nonempty → (s ⊻ t).Nonempty := Nonempty.image₂ theorem Nonempty.of_sups_left : (s ⊻ t).Nonempty → s.Nonempty := Nonempty.of_image₂_left theorem Nonempty.of_sups_right : (s ⊻ t).Nonempty → t.Nonempty := Nonempty.of_image₂_right @[simp] theorem empty_sups : ∅ ⊻ t = ∅ := image₂_empty_left @[simp] theorem sups_empty : s ⊻ ∅ = ∅ := image₂_empty_right @[simp] theorem sups_eq_empty : s ⊻ t = ∅ ↔ s = ∅ √ t = ∅ := image₂_eq_empty_iff @[simp] lemma singleton_sups : {a} ⊻ t = t.image (a ⊔ ·) := image₂_singleton_left @[simp] lemma sups_singleton : s ⊻ {b} = s.image (· ⊔ b) := image₂_singleton_right theorem singleton_sups_singleton : ({a} ⊻ {b} : Finset α) = {a ⊔ b} := image₂_singleton theorem sups_union_left : (s₁ ∪ s₂) ⊻ t = s₁ ⊻ t ∪ s₂ ⊻ t := image₂_union_left theorem sups_union_right : s ⊻ (t₁ ∪ t₂) = s ⊻ t₁ ∪ s ⊻ t₂ := image₂_union_right theorem sups_inter_subset_left : (s₁ ∩ s₂) ⊻ t ⊆ s₁ ⊻ t ∩ s₂ ⊻ t := image₂_inter_subset_left theorem sups_inter_subset_right : s ⊻ (t₁ ∩ t₂) ⊆ s ⊻ t₁ ∩ s ⊻ t₂ := image₂_inter_subset_right theorem subset_sups {s t : Set α} : ↑u ⊆ s ⊻ t → ∃ s' t' : Finset α, ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ s' ⊻ t' := subset_set_image₂ lemma image_sups (f : F) (s t : Finset α) : image f (s ⊻ t) = image f s ⊻ image f t := image_image₂_distrib <| map_sup f lemma map_sups (f : F) (hf) (s t : Finset α) : map ⟹f, hf⟩ (s ⊻ t) = map ⟹f, hf⟩ s ⊻ map ⟹f, hf⟩ t := by simpa [map_eq_image] using image_sups f s t lemma subset_sups_self : s ⊆ s ⊻ s := fun _a ha ↩ mem_sups.2 ⟹_, ha, _, ha, sup_idem _⟩ lemma sups_subset_self : s ⊻ s ⊆ s ↔ SupClosed (s : Set α) := sups_subset_iff @[simp] lemma sups_eq_self : s ⊻ s = s ↔ SupClosed (s : Set α) := by simp [← coe_inj] @[simp] lemma univ_sups_univ [Fintype α] : (univ : Finset α) ⊻ univ = univ := by simp lemma filter_sups_le [DecidableLE α] (s t : Finset α) (a : α) : {b ∈ s ⊻ t | b ≀ a} = {b ∈ s | b ≀ a} ⊻ {b ∈ t | b ≀ a} := by simp only [← coe_inj, coe_filter, coe_sups, ← mem_coe, Set.sep_sups_le] variable (s t u) lemma biUnion_image_sup_left : s.biUnion (fun a ↩ t.image (a ⊔ ·)) = s ⊻ t := biUnion_image_left lemma biUnion_image_sup_right : t.biUnion (fun b ↩ s.image (· ⊔ b)) = s ⊻ t := biUnion_image_right theorem image_sup_product (s t : Finset α) : (s ×ˢ t).image (uncurry (· ⊔ ·)) = s ⊻ t := image_uncurry_product _ _ _ theorem sups_assoc : s ⊻ t ⊻ u = s ⊻ (t ⊻ u) := image₂_assoc sup_assoc theorem sups_comm : s ⊻ t = t ⊻ s := image₂_comm sup_comm theorem sups_left_comm : s ⊻ (t ⊻ u) = t ⊻ (s ⊻ u) := image₂_left_comm sup_left_comm theorem sups_right_comm : s ⊻ t ⊻ u = s ⊻ u ⊻ t := image₂_right_comm sup_right_comm theorem sups_sups_sups_comm : s ⊻ t ⊻ (u ⊻ v) = s ⊻ u ⊻ (t ⊻ v) := image₂_image₂_image₂_comm sup_sup_sup_comm end Sups section Infs variable [DecidableEq α] [DecidableEq β] variable [SemilatticeInf α] [SemilatticeInf β] [FunLike F α β] [InfHomClass F α β] variable (s s₁ s₂ t t₁ t₂ u v : Finset α) /-- `s ⊌ t` is the finset of elements of the form `a ⊓ b` where `a ∈ s`, `b ∈ t`. -/ protected def hasInfs : HasInfs (Finset α) := ⟹image₂ (· ⊓ ·)⟩ scoped[FinsetFamily] attribute [instance] Finset.hasInfs open FinsetFamily variable {s t} {a b c : α} @[simp] theorem mem_infs : c ∈ s ⊌ t ↔ ∃ a ∈ s, ∃ b ∈ t, a ⊓ b = c := by simp [(· ⊌ ·)] variable (s t) @[simp, norm_cast] theorem coe_infs : (↑(s ⊌ t) : Set α) = ↑s ⊌ ↑t := coe_image₂ _ _ _ theorem card_infs_le : #(s ⊌ t) ≀ #s * #t := card_image₂_le _ _ _ theorem card_infs_iff : #(s ⊌ t) = #s * #t ↔ (s ×ˢ t : Set (α × α)).InjOn fun x => x.1 ⊓ x.2 := card_image₂_iff variable {s s₁ s₂ t t₁ t₂ u} theorem inf_mem_infs : a ∈ s → b ∈ t → a ⊓ b ∈ s ⊌ t := mem_image₂_of_mem theorem infs_subset : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ ⊌ t₁ ⊆ s₂ ⊌ t₂ := image₂_subset theorem infs_subset_left : t₁ ⊆ t₂ → s ⊌ t₁ ⊆ s ⊌ t₂ := image₂_subset_left theorem infs_subset_right : s₁ ⊆ s₂ → s₁ ⊌ t ⊆ s₂ ⊌ t := image₂_subset_right lemma image_subset_infs_left : b ∈ t → s.image (· ⊓ b) ⊆ s ⊌ t := image_subset_image₂_left lemma image_subset_infs_right : a ∈ s → t.image (a ⊓ ·) ⊆ s ⊌ t := image_subset_image₂_right theorem forall_infs_iff {p : α → Prop} : (∀ c ∈ s ⊌ t, p c) ↔ ∀ a ∈ s, ∀ b ∈ t, p (a ⊓ b) := forall_mem_image₂ @[simp] theorem infs_subset_iff : s ⊌ t ⊆ u ↔ ∀ a ∈ s, ∀ b ∈ t, a ⊓ b ∈ u := image₂_subset_iff @[simp] theorem infs_nonempty : (s ⊌ t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := image₂_nonempty_iff @[aesop safe apply (rule_sets := [finsetNonempty])] protected theorem Nonempty.infs : s.Nonempty → t.Nonempty → (s ⊌ t).Nonempty := Nonempty.image₂ theorem Nonempty.of_infs_left : (s ⊌ t).Nonempty → s.Nonempty := Nonempty.of_image₂_left theorem Nonempty.of_infs_right : (s ⊌ t).Nonempty → t.Nonempty := Nonempty.of_image₂_right @[simp] theorem empty_infs : ∅ ⊌ t = ∅ := image₂_empty_left @[simp] theorem infs_empty : s ⊌ ∅ = ∅ := image₂_empty_right @[simp] theorem infs_eq_empty : s ⊌ t = ∅ ↔ s = ∅ √ t = ∅ := image₂_eq_empty_iff @[simp] lemma singleton_infs : {a} ⊌ t = t.image (a ⊓ ·) := image₂_singleton_left @[simp] lemma infs_singleton : s ⊌ {b} = s.image (· ⊓ b) := image₂_singleton_right theorem singleton_infs_singleton : ({a} ⊌ {b} : Finset α) = {a ⊓ b} := image₂_singleton theorem infs_union_left : (s₁ ∪ s₂) ⊌ t = s₁ ⊌ t ∪ s₂ ⊌ t := image₂_union_left theorem infs_union_right : s ⊌ (t₁ ∪ t₂) = s ⊌ t₁ ∪ s ⊌ t₂ := image₂_union_right theorem infs_inter_subset_left : (s₁ ∩ s₂) ⊌ t ⊆ s₁ ⊌ t ∩ s₂ ⊌ t := image₂_inter_subset_left theorem infs_inter_subset_right : s ⊌ (t₁ ∩ t₂) ⊆ s ⊌ t₁ ∩ s ⊌ t₂ := image₂_inter_subset_right theorem subset_infs {s t : Set α} : ↑u ⊆ s ⊌ t → ∃ s' t' : Finset α, ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ s' ⊌ t' := subset_set_image₂ lemma image_infs (f : F) (s t : Finset α) : image f (s ⊌ t) = image f s ⊌ image f t := image_image₂_distrib <| map_inf f lemma map_infs (f : F) (hf) (s t : Finset α) : map ⟹f, hf⟩ (s ⊌ t) = map ⟹f, hf⟩ s ⊌ map ⟹f, hf⟩ t := by simpa [map_eq_image] using image_infs f s t lemma subset_infs_self : s ⊆ s ⊌ s := fun _a ha ↩ mem_infs.2 ⟹_, ha, _, ha, inf_idem _⟩ lemma infs_self_subset : s ⊌ s ⊆ s ↔ InfClosed (s : Set α) := infs_subset_iff @[simp] lemma infs_self : s ⊌ s = s ↔ InfClosed (s : Set α) := by simp [← coe_inj] @[simp] lemma univ_infs_univ [Fintype α] : (univ : Finset α) ⊌ univ = univ := by simp lemma filter_infs_le [DecidableLE α] (s t : Finset α) (a : α) : {b ∈ s ⊌ t | a ≀ b} = {b ∈ s | a ≀ b} ⊌ {b ∈ t | a ≀ b} := by simp only [← coe_inj, coe_filter, coe_infs, ← mem_coe, Set.sep_infs_le] variable (s t u) lemma biUnion_image_inf_left : s.biUnion (fun a ↩ t.image (a ⊓ ·)) = s ⊌ t := biUnion_image_left lemma biUnion_image_inf_right : t.biUnion (fun b ↩ s.image (· ⊓ b)) = s ⊌ t := biUnion_image_right theorem image_inf_product (s t : Finset α) : (s ×ˢ t).image (uncurry (· ⊓ ·)) = s ⊌ t := image_uncurry_product _ _ _ theorem infs_assoc : s ⊌ t ⊌ u = s ⊌ (t ⊌ u) := image₂_assoc inf_assoc theorem infs_comm : s ⊌ t = t ⊌ s := image₂_comm inf_comm theorem infs_left_comm : s ⊌ (t ⊌ u) = t ⊌ (s ⊌ u) := image₂_left_comm inf_left_comm theorem infs_right_comm : s ⊌ t ⊌ u = s ⊌ u ⊌ t := image₂_right_comm inf_right_comm theorem infs_infs_infs_comm : s ⊌ t ⊌ (u ⊌ v) = s ⊌ u ⊌ (t ⊌ v) := image₂_image₂_image₂_comm inf_inf_inf_comm end Infs open FinsetFamily section DistribLattice variable [DecidableEq α] variable [DistribLattice α] (s t u : Finset α) theorem sups_infs_subset_left : s ⊻ t ⊌ u ⊆ (s ⊻ t) ⊌ (s ⊻ u) := image₂_distrib_subset_left sup_inf_left theorem sups_infs_subset_right : t ⊌ u ⊻ s ⊆ (t ⊻ s) ⊌ (u ⊻ s) := image₂_distrib_subset_right sup_inf_right theorem infs_sups_subset_left : s ⊌ (t ⊻ u) ⊆ s ⊌ t ⊻ s ⊌ u := image₂_distrib_subset_left inf_sup_left theorem infs_sups_subset_right : (t ⊻ u) ⊌ s ⊆ t ⊌ s ⊻ u ⊌ s := image₂_distrib_subset_right inf_sup_right end DistribLattice section Finset variable [DecidableEq α] variable {𝒜 ℬ : Finset (Finset α)} {s t : Finset α} @[simp] lemma powerset_union (s t : Finset α) : (s ∪ t).powerset = s.powerset ⊻ t.powerset := by ext u simp only [mem_sups, mem_powerset, le_eq_subset, sup_eq_union] refine ⟹fun h ↩ ⟹_, inter_subset_left (s₂ := u), _, inter_subset_left (s₂ := u), ?_⟩, ?_⟩ · rwa [← union_inter_distrib_right, inter_eq_right] · rintro ⟹v, hv, w, hw, rfl⟩ exact union_subset_union hv hw @[simp] lemma powerset_inter (s t : Finset α) : (s ∩ t).powerset = s.powerset ⊌ t.powerset := by ext u simp only [mem_infs, mem_powerset, le_eq_subset, inf_eq_inter] refine ⟹fun h ↩ ⟹_, inter_subset_left (s₂ := u), _, inter_subset_left (s₂ := u), ?_⟩, ?_⟩ · rwa [← inter_inter_distrib_right, inter_eq_right] · rintro ⟹v, hv, w, hw, rfl⟩ exact inter_subset_inter hv hw @[simp] lemma powerset_sups_powerset_self (s : Finset α) : s.powerset ⊻ s.powerset = s.powerset := by simp [← powerset_union] @[simp] lemma powerset_infs_powerset_self (s : Finset α) : s.powerset ⊌ s.powerset = s.powerset := by simp [← powerset_inter] lemma union_mem_sups : s ∈ 𝒜 → t ∈ ℬ → s ∪ t ∈ 𝒜 ⊻ ℬ := sup_mem_sups lemma inter_mem_infs : s ∈ 𝒜 → t ∈ ℬ → s ∩ t ∈ 𝒜 ⊌ ℬ := inf_mem_infs end Finset section DisjSups variable [DecidableEq α] variable [SemilatticeSup α] [OrderBot α] [DecidableRel (α := α) Disjoint] (s s₁ s₂ t t₁ t₂ u : Finset α) /-- The finset of elements of the form `a ⊔ b` where `a ∈ s`, `b ∈ t` and `a` and `b` are disjoint. -/ def disjSups : Finset α := {ab ∈ s ×ˢ t | Disjoint ab.1 ab.2}.image fun ab => ab.1 ⊔ ab.2 @[inherit_doc] scoped[FinsetFamily] infixl:74 " ○ " => Finset.disjSups open FinsetFamily variable {s t u} {a b c : α} @[simp] theorem mem_disjSups : c ∈ s ○ t ↔ ∃ a ∈ s, ∃ b ∈ t, Disjoint a b ∧ a ⊔ b = c := by simp [disjSups, and_assoc] theorem disjSups_subset_sups : s ○ t ⊆ s ⊻ t := by simp_rw [subset_iff, mem_sups, mem_disjSups] exact fun c ⟹a, b, ha, hb, _, hc⟩ => ⟹a, b, ha, hb, hc⟩ variable (s t) theorem card_disjSups_le : #(s ○ t) ≀ #s * #t := (card_le_card disjSups_subset_sups).trans <| card_sups_le _ _ variable {s s₁ s₂ t t₁ t₂} theorem disjSups_subset (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : s₁ ○ t₁ ⊆ s₂ ○ t₂ := image_subset_image <| filter_subset_filter _ <| product_subset_product hs ht theorem disjSups_subset_left (ht : t₁ ⊆ t₂) : s ○ t₁ ⊆ s ○ t₂ := disjSups_subset Subset.rfl ht theorem disjSups_subset_right (hs : s₁ ⊆ s₂) : s₁ ○ t ⊆ s₂ ○ t := disjSups_subset hs Subset.rfl theorem forall_disjSups_iff {p : α → Prop} : (∀ c ∈ s ○ t, p c) ↔ ∀ a ∈ s, ∀ b ∈ t, Disjoint a b → p (a ⊔ b) := by simp_rw [mem_disjSups] refine ⟹fun h a ha b hb hab => h _ ⟹_, ha, _, hb, hab, rfl⟩, ?_⟩ rintro h _ ⟹a, ha, b, hb, hab, rfl⟩ exact h _ ha _ hb hab @[simp] theorem disjSups_subset_iff : s ○ t ⊆ u ↔ ∀ a ∈ s, ∀ b ∈ t, Disjoint a b → a ⊔ b ∈ u := forall_disjSups_iff theorem Nonempty.of_disjSups_left : (s ○ t).Nonempty → s.Nonempty := by simp_rw [Finset.Nonempty, mem_disjSups] exact fun ⟹_, a, ha, _⟩ => ⟹a, ha⟩ theorem Nonempty.of_disjSups_right : (s ○ t).Nonempty → t.Nonempty := by simp_rw [Finset.Nonempty, mem_disjSups] exact fun ⟹_, _, _, b, hb, _⟩ => ⟹b, hb⟩ @[simp] theorem disjSups_empty_left : ∅ ○ t = ∅ := by simp [disjSups] @[simp] theorem disjSups_empty_right : s ○ ∅ = ∅ := by simp [disjSups] theorem disjSups_singleton : ({a} ○ {b} : Finset α) = if Disjoint a b then {a ⊔ b} else ∅ := by split_ifs with h <;> simp [disjSups, filter_singleton, h] theorem disjSups_union_left : (s₁ ∪ s₂) ○ t = s₁ ○ t ∪ s₂ ○ t := by simp [disjSups, filter_union, image_union] theorem disjSups_union_right : s ○ (t₁ ∪ t₂) = s ○ t₁ ∪ s ○ t₂ := by simp [disjSups, filter_union, image_union] theorem disjSups_inter_subset_left : (s₁ ∩ s₂) ○ t ⊆ s₁ ○ t ∩ s₂ ○ t := by simpa only [disjSups, inter_product, filter_inter_distrib] using image_inter_subset _ _ _ theorem disjSups_inter_subset_right : s ○ (t₁ ∩ t₂) ⊆ s ○ t₁ ∩ s ○ t₂ := by simpa only [disjSups, product_inter, filter_inter_distrib] using image_inter_subset _ _ _ variable (s t) theorem disjSups_comm : s ○ t = t ○ s := by aesop (add simp disjoint_comm, simp sup_comm) instance : @Std.Commutative (Finset α) (· ○ ·) := ⟹disjSups_comm⟩ end DisjSups open FinsetFamily section DistribLattice variable [DecidableEq α] variable [DistribLattice α] [OrderBot α] [DecidableRel (α := α) Disjoint] (s t u v : Finset α) theorem disjSups_assoc : ∀ s t u : Finset α, s ○ t ○ u = s ○ (t ○ u) := by refine (associative_of_commutative_of_le inferInstance ?_).assoc simp only [le_eq_subset, disjSups_subset_iff, mem_disjSups] rintro s t u _ ⟹a, ha, b, hb, hab, rfl⟩ c hc habc rw [disjoint_sup_left] at habc exact ⟹a, ha, _, ⟹b, hb, c, hc, habc.2, rfl⟩, hab.sup_right habc.1, (sup_assoc ..).symm⟩ instance : @Std.Associative (Finset α) (· ○ ·) := ⟹disjSups_assoc⟩ theorem disjSups_left_comm : s ○ (t ○ u) = t ○ (s ○ u) := by simp_rw [← disjSups_assoc, disjSups_comm s] theorem disjSups_right_comm : s ○ t ○ u = s ○ u ○ t := by simp_rw [disjSups_assoc, disjSups_comm] theorem disjSups_disjSups_disjSups_comm : s ○ t ○ (u ○ v) = s ○ u ○ (t ○ v) := by simp_rw [← disjSups_assoc, disjSups_right_comm] end DistribLattice section Diffs variable [DecidableEq α] variable [GeneralizedBooleanAlgebra α] (s s₁ s₂ t t₁ t₂ u : Finset α) /-- `s \\ t` is the finset of elements of the form `a \ b` where `a ∈ s`, `b ∈ t`. -/ def diffs : Finset α → Finset α → Finset α := image₂ (· \ ·) @[inherit_doc] scoped[FinsetFamily] infixl:74 " \\\\ " => Finset.diffs -- This notation is meant to have higher precedence than `\` and `⊓`, but still within the -- realm of other binary notation open FinsetFamily variable {s t} {a b c : α} @[simp] lemma mem_diffs : c ∈ s \\ t ↔ ∃ a ∈ s, ∃ b ∈ t, a \ b = c := by simp [(· \\ ·)] variable (s t) @[simp, norm_cast] lemma coe_diffs : (↑(s \\ t) : Set α) = Set.image2 (· \ ·) s t := coe_image₂ _ _ _ lemma card_diffs_le : #(s \\ t) ≀ #s * #t := card_image₂_le _ _ _ lemma card_diffs_iff : #(s \\ t) = #s * #t ↔ (s ×ˢ t : Set (α × α)).InjOn fun x ↩ x.1 \ x.2 := card_image₂_iff variable {s s₁ s₂ t t₁ t₂ u} lemma sdiff_mem_diffs : a ∈ s → b ∈ t → a \ b ∈ s \\ t := mem_image₂_of_mem lemma diffs_subset : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ \\ t₁ ⊆ s₂ \\ t₂ := image₂_subset lemma diffs_subset_left : t₁ ⊆ t₂ → s \\ t₁ ⊆ s \\ t₂ := image₂_subset_left lemma diffs_subset_right : s₁ ⊆ s₂ → s₁ \\ t ⊆ s₂ \\ t := image₂_subset_right lemma image_subset_diffs_left : b ∈ t → s.image (· \ b) ⊆ s \\ t := image_subset_image₂_left lemma image_subset_diffs_right : a ∈ s → t.image (a \ ·) ⊆ s \\ t := image_subset_image₂_right lemma forall_mem_diffs {p : α → Prop} : (∀ c ∈ s \\ t, p c) ↔ ∀ a ∈ s, ∀ b ∈ t, p (a \ b) := forall_mem_image₂ @[simp] lemma diffs_subset_iff : s \\ t ⊆ u ↔ ∀ a ∈ s, ∀ b ∈ t, a \ b ∈ u := image₂_subset_iff @[simp] lemma diffs_nonempty : (s \\ t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := image₂_nonempty_iff @[aesop safe apply (rule_sets := [finsetNonempty])] protected lemma Nonempty.diffs : s.Nonempty → t.Nonempty → (s \\ t).Nonempty := Nonempty.image₂ lemma Nonempty.of_diffs_left : (s \\ t).Nonempty → s.Nonempty := Nonempty.of_image₂_left lemma Nonempty.of_diffs_right : (s \\ t).Nonempty → t.Nonempty := Nonempty.of_image₂_right @[simp] lemma empty_diffs : ∅ \\ t = ∅ := image₂_empty_left @[simp] lemma diffs_empty : s \\ ∅ = ∅ := image₂_empty_right @[simp] lemma diffs_eq_empty : s \\ t = ∅ ↔ s = ∅ √ t = ∅ := image₂_eq_empty_iff @[simp] lemma singleton_diffs : {a} \\ t = t.image (a \ ·) := image₂_singleton_left @[simp] lemma diffs_singleton : s \\ {b} = s.image (· \ b) := image₂_singleton_right lemma singleton_diffs_singleton : ({a} \\ {b} : Finset α) = {a \ b} := image₂_singleton lemma diffs_union_left : (s₁ ∪ s₂) \\ t = s₁ \\ t ∪ s₂ \\ t := image₂_union_left lemma diffs_union_right : s \\ (t₁ ∪ t₂) = s \\ t₁ ∪ s \\ t₂ := image₂_union_right lemma diffs_inter_subset_left : (s₁ ∩ s₂) \\ t ⊆ s₁ \\ t ∩ s₂ \\ t := image₂_inter_subset_left lemma diffs_inter_subset_right : s \\ (t₁ ∩ t₂) ⊆ s \\ t₁ ∩ s \\ t₂ := image₂_inter_subset_right lemma subset_diffs {s t : Set α} : ↑u ⊆ Set.image2 (· \ ·) s t → ∃ s' t' : Finset α, ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ s' \\ t' := subset_set_image₂ variable (s t u) lemma biUnion_image_sdiff_left : s.biUnion (fun a ↩ t.image (a \ ·)) = s \\ t := biUnion_image_left lemma biUnion_image_sdiff_right : t.biUnion (fun b ↩ s.image (· \ b)) = s \\ t := biUnion_image_right lemma image_sdiff_product (s t : Finset α) : (s ×ˢ t).image (uncurry (· \ ·)) = s \\ t := image_uncurry_product _ _ _ lemma diffs_right_comm : s \\ t \\ u = s \\ u \\ t := image₂_right_comm sdiff_right_comm end Diffs section Compls variable [BooleanAlgebra α] (s s₁ s₂ t : Finset α) /-- `sᶜˢ` is the finset of elements of the form `aᶜ` where `a ∈ s`. -/ def compls : Finset α → Finset α := map ⟹compl, compl_injective⟩ @[inherit_doc] scoped[FinsetFamily] postfix:max "ᶜˢ" => Finset.compls open FinsetFamily variable {s t} {a : α}
@[simp] lemma mem_compls : a ∈ sᶜˢ ↔ aᶜ ∈ s := by
Mathlib/Data/Finset/Sups.lean
598
599
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl -/ import Mathlib.MeasureTheory.Integral.Lebesgue.Basic import Mathlib.MeasureTheory.Integral.Lebesgue.Countable import Mathlib.MeasureTheory.Integral.Lebesgue.MeasurePreserving import Mathlib.MeasureTheory.Integral.Lebesgue.Norm deprecated_module (since := "2025-04-13")
Mathlib/MeasureTheory/Integral/Lebesgue.lean
231
247
/- Copyright (c) 2022 Rémi Bottinelli. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémi Bottinelli, Junyan Xu -/ import Mathlib.Algebra.Group.Subgroup.Defs import Mathlib.CategoryTheory.Groupoid.VertexGroup import Mathlib.CategoryTheory.Groupoid.Basic import Mathlib.CategoryTheory.Groupoid import Mathlib.Data.Set.Lattice /-! # Subgroupoid This file defines subgroupoids as `structure`s containing the subsets of arrows and their stability under composition and inversion. Also defined are: * containment of subgroupoids is a complete lattice; * images and preimages of subgroupoids under a functor; * the notion of normality of subgroupoids and its stability under intersection and preimage; * compatibility of the above with `CategoryTheory.Groupoid.vertexGroup`. ## Main definitions Given a type `C` with associated `groupoid C` instance. * `CategoryTheory.Subgroupoid C` is the type of subgroupoids of `C` * `CategoryTheory.Subgroupoid.IsNormal` is the property that the subgroupoid is stable under conjugation by arbitrary arrows, _and_ that all identity arrows are contained in the subgroupoid. * `CategoryTheory.Subgroupoid.comap` is the "preimage" map of subgroupoids along a functor. * `CategoryTheory.Subgroupoid.map` is the "image" map of subgroupoids along a functor _injective on objects_. * `CategoryTheory.Subgroupoid.vertexSubgroup` is the subgroup of the *vertex group* at a given vertex `v`, assuming `v` is contained in the `CategoryTheory.Subgroupoid` (meaning, by definition, that the arrow `𝟙 v` is contained in the subgroupoid). ## Implementation details The structure of this file is copied from/inspired by `Mathlib/GroupTheory/Subgroup/Basic.lean` and `Mathlib/Combinatorics/SimpleGraph/Subgraph.lean`. ## TODO * Equivalent inductive characterization of generated (normal) subgroupoids. * Characterization of normal subgroupoids as kernels. * Prove that `CategoryTheory.Subgroupoid.full` and `CategoryTheory.Subgroupoid.disconnect` preserve intersections (and `CategoryTheory.Subgroupoid.disconnect` also unions) ## Tags category theory, groupoid, subgroupoid -/ namespace CategoryTheory open Set Groupoid universe u v variable {C : Type u} [Groupoid C] /-- A sugroupoid of `C` consists of a choice of arrows for each pair of vertices, closed under composition and inverses. -/ @[ext] structure Subgroupoid (C : Type u) [Groupoid C] where /-- The arrow choice for each pair of vertices -/ arrows : ∀ c d : C, Set (c ⟶ d) protected inv : ∀ {c d} {p : c ⟶ d}, p ∈ arrows c d → Groupoid.inv p ∈ arrows d c protected mul : ∀ {c d e} {p}, p ∈ arrows c d → ∀ {q}, q ∈ arrows d e → p ≫ q ∈ arrows c e namespace Subgroupoid variable (S : Subgroupoid C) theorem inv_mem_iff {c d : C} (f : c ⟶ d) : Groupoid.inv f ∈ S.arrows d c ↔ f ∈ S.arrows c d := by constructor · intro h simpa only [inv_eq_inv, IsIso.inv_inv] using S.inv h · apply S.inv theorem mul_mem_cancel_left {c d e : C} {f : c ⟶ d} {g : d ⟶ e} (hf : f ∈ S.arrows c d) : f ≫ g ∈ S.arrows c e ↔ g ∈ S.arrows d e := by constructor · rintro h suffices Groupoid.inv f ≫ f ≫ g ∈ S.arrows d e by simpa only [inv_eq_inv, IsIso.inv_hom_id_assoc] using this apply S.mul (S.inv hf) h · apply S.mul hf theorem mul_mem_cancel_right {c d e : C} {f : c ⟶ d} {g : d ⟶ e} (hg : g ∈ S.arrows d e) : f ≫ g ∈ S.arrows c e ↔ f ∈ S.arrows c d := by constructor · rintro h suffices (f ≫ g) ≫ Groupoid.inv g ∈ S.arrows c d by simpa only [inv_eq_inv, IsIso.hom_inv_id, Category.comp_id, Category.assoc] using this apply S.mul h (S.inv hg) · exact fun hf => S.mul hf hg /-- The vertices of `C` on which `S` has non-trivial isotropy -/ def objs : Set C := {c : C | (S.arrows c c).Nonempty} theorem mem_objs_of_src {c d : C} {f : c ⟶ d} (h : f ∈ S.arrows c d) : c ∈ S.objs := ⟹f ≫ Groupoid.inv f, S.mul h (S.inv h)⟩ theorem mem_objs_of_tgt {c d : C} {f : c ⟶ d} (h : f ∈ S.arrows c d) : d ∈ S.objs := ⟹Groupoid.inv f ≫ f, S.mul (S.inv h) h⟩ theorem id_mem_of_nonempty_isotropy (c : C) : c ∈ objs S → 𝟙 c ∈ S.arrows c c := by rintro ⟚γ, hγ⟩ convert S.mul hγ (S.inv hγ) simp only [inv_eq_inv, IsIso.hom_inv_id] theorem id_mem_of_src {c d : C} {f : c ⟶ d} (h : f ∈ S.arrows c d) : 𝟙 c ∈ S.arrows c c := id_mem_of_nonempty_isotropy S c (mem_objs_of_src S h) theorem id_mem_of_tgt {c d : C} {f : c ⟶ d} (h : f ∈ S.arrows c d) : 𝟙 d ∈ S.arrows d d := id_mem_of_nonempty_isotropy S d (mem_objs_of_tgt S h) /-- A subgroupoid seen as a quiver on vertex set `C` -/ def asWideQuiver : Quiver C := ⟹fun c d => Subtype <| S.arrows c d⟩ /-- The coercion of a subgroupoid as a groupoid -/ @[simps comp_coe, simps -isSimp inv_coe] instance coe : Groupoid S.objs where Hom a b := S.arrows a.val b.val id a := ⟚𝟙 a.val, id_mem_of_nonempty_isotropy S a.val a.prop⟩ comp p q := ⟹p.val ≫ q.val, S.mul p.prop q.prop⟩ inv p := ⟹Groupoid.inv p.val, S.inv p.prop⟩ @[simp] theorem coe_inv_coe' {c d : S.objs} (p : c ⟶ d) : (CategoryTheory.inv p).val = CategoryTheory.inv p.val := by simp only [← inv_eq_inv, coe_inv_coe] /-- The embedding of the coerced subgroupoid to its parent -/ def hom : S.objs ⥀ C where obj c := c.val map f := f.val map_id _ := rfl map_comp _ _ := rfl theorem hom.inj_on_objects : Function.Injective (hom S).obj := by rintro ⟹c, hc⟩ ⟹d, hd⟩ hcd simp only [Subtype.mk_eq_mk]; exact hcd theorem hom.faithful : ∀ c d, Function.Injective fun f : c ⟶ d => (hom S).map f := by rintro ⟹c, hc⟩ ⟹d, hd⟩ ⟹f, hf⟩ ⟹g, hg⟩ hfg; exact Subtype.eq hfg /-- The subgroup of the vertex group at `c` given by the subgroupoid -/ def vertexSubgroup {c : C} (hc : c ∈ S.objs) : Subgroup (c ⟶ c) where carrier := S.arrows c c mul_mem' hf hg := S.mul hf hg one_mem' := id_mem_of_nonempty_isotropy _ _ hc inv_mem' hf := S.inv hf /-- The set of all arrows of a subgroupoid, as a set in `Σ c d : C, c ⟶ d`. -/ @[coe] def toSet (S : Subgroupoid C) : Set (Σ c d : C, c ⟶ d) := {F | F.2.2 ∈ S.arrows F.1 F.2.1} instance : SetLike (Subgroupoid C) (Σ c d : C, c ⟶ d) where coe := toSet coe_injective' := fun ⟹S, _, _⟩ ⟹T, _, _⟩ h => by ext c d f; apply Set.ext_iff.1 h ⟹c, d, f⟩ theorem mem_iff (S : Subgroupoid C) (F : Σ c d, c ⟶ d) : F ∈ S ↔ F.2.2 ∈ S.arrows F.1 F.2.1 := Iff.rfl theorem le_iff (S T : Subgroupoid C) : S ≀ T ↔ ∀ {c d}, S.arrows c d ⊆ T.arrows c d := by rw [SetLike.le_def, Sigma.forall]; exact forall_congr' fun c => Sigma.forall instance : Top (Subgroupoid C) := ⟹{ arrows := fun _ _ => Set.univ mul := by intros; trivial inv := by intros; trivial }⟩ theorem mem_top {c d : C} (f : c ⟶ d) : f ∈ (⊀ : Subgroupoid C).arrows c d := trivial theorem mem_top_objs (c : C) : c ∈ (⊀ : Subgroupoid C).objs := by dsimp [Top.top, objs] simp only [univ_nonempty] instance : Bot (Subgroupoid C) := ⟹{ arrows := fun _ _ => ∅ mul := False.elim inv := False.elim }⟩ instance : Inhabited (Subgroupoid C) := ⟚⊀⟩ instance : Min (Subgroupoid C) := ⟹fun S T => { arrows := fun c d => S.arrows c d ∩ T.arrows c d inv := fun hp ↩ ⟹S.inv hp.1, T.inv hp.2⟩ mul := fun hp _ hq ↩ ⟹S.mul hp.1 hq.1, T.mul hp.2 hq.2⟩ }⟩ instance : InfSet (Subgroupoid C) := ⟹fun s => { arrows := fun c d => ⋂ S ∈ s, Subgroupoid.arrows S c d inv := fun hp ↩ by rw [mem_iInter₂] at hp ⊢; exact fun S hS => S.inv (hp S hS) mul := fun hp _ hq ↩ by rw [mem_iInter₂] at hp hq ⊢ exact fun S hS => S.mul (hp S hS) (hq S hS) }⟩ theorem mem_sInf_arrows {s : Set (Subgroupoid C)} {c d : C} {p : c ⟶ d} : p ∈ (sInf s).arrows c d ↔ ∀ S ∈ s, p ∈ S.arrows c d := mem_iInter₂ theorem mem_sInf {s : Set (Subgroupoid C)} {p : Σ c d : C, c ⟶ d} : p ∈ sInf s ↔ ∀ S ∈ s, p ∈ S := mem_sInf_arrows instance : CompleteLattice (Subgroupoid C) := { completeLatticeOfInf (Subgroupoid C) (by refine fun s => ⟹fun S Ss F => ?_, fun T Tl F fT => ?_⟩ <;> simp only [mem_sInf] exacts [fun hp => hp S Ss, fun S Ss => Tl Ss fT]) with bot := ⊥ bot_le := fun _ => empty_subset _ top := ⊀ le_top := fun _ => subset_univ _ inf := (· ⊓ ·) le_inf := fun _ _ _ RS RT _ pR => ⟹RS pR, RT pR⟩ inf_le_left := fun _ _ _ => And.left inf_le_right := fun _ _ _ => And.right } theorem le_objs {S T : Subgroupoid C} (h : S ≀ T) : S.objs ⊆ T.objs := fun s ⟚γ, hγ⟩ => ⟚γ, @h ⟹s, s, γ⟩ hγ⟩ /-- The functor associated to the embedding of subgroupoids -/ def inclusion {S T : Subgroupoid C} (h : S ≀ T) : S.objs ⥀ T.objs where obj s := ⟹s.val, le_objs h s.prop⟩ map f := ⟹f.val, @h ⟹_, _, f.val⟩ f.prop⟩ map_id _ := rfl map_comp _ _ := rfl theorem inclusion_inj_on_objects {S T : Subgroupoid C} (h : S ≀ T) : Function.Injective (inclusion h).obj := fun ⟹s, hs⟩ ⟹t, ht⟩ => by simpa only [inclusion, Subtype.mk_eq_mk] using id theorem inclusion_faithful {S T : Subgroupoid C} (h : S ≀ T) (s t : S.objs) : Function.Injective fun f : s ⟶ t => (inclusion h).map f := fun ⟹f, hf⟩ ⟹g, hg⟩ => by -- Porting note: was `...; simpa only [Subtype.mk_eq_mk] using id` dsimp only [inclusion]; rw [Subtype.mk_eq_mk, Subtype.mk_eq_mk]; exact id theorem inclusion_refl {S : Subgroupoid C} : inclusion (le_refl S) = 𝟭 S.objs := Functor.hext (fun _ => rfl) fun _ _ _ => HEq.refl _ theorem inclusion_trans {R S T : Subgroupoid C} (k : R ≀ S) (h : S ≀ T) : inclusion (k.trans h) = inclusion k ⋙ inclusion h := rfl theorem inclusion_comp_embedding {S T : Subgroupoid C} (h : S ≀ T) : inclusion h ⋙ T.hom = S.hom := rfl /-- The family of arrows of the discrete groupoid -/ inductive Discrete.Arrows : ∀ c d : C, (c ⟶ d) → Prop | id (c : C) : Discrete.Arrows c c (𝟙 c) /-- The only arrows of the discrete groupoid are the identity arrows. -/ def discrete : Subgroupoid C where arrows c d := {p | Discrete.Arrows c d p} inv := by rintro _ _ _ ⟚⟩; simp only [inv_eq_inv, IsIso.inv_id]; constructor mul := by rintro _ _ _ _ ⟚⟩ _ ⟚⟩; rw [Category.comp_id]; constructor theorem mem_discrete_iff {c d : C} (f : c ⟶ d) : f ∈ discrete.arrows c d ↔ ∃ h : c = d, f = eqToHom h := ⟹by rintro ⟚⟩; exact ⟹rfl, rfl⟩, by rintro ⟹rfl, rfl⟩; constructor⟩ /-- A subgroupoid is wide if its carrier set is all of `C`. -/ structure IsWide : Prop where wide : ∀ c, 𝟙 c ∈ S.arrows c c theorem isWide_iff_objs_eq_univ : S.IsWide ↔ S.objs = Set.univ := by constructor · rintro h ext x; constructor <;> simp only [top_eq_univ, mem_univ, imp_true_iff, forall_true_left] apply mem_objs_of_src S (h.wide x) · rintro h refine ⟹fun c => ?_⟩ obtain ⟚γ, γS⟩ := (le_of_eq h.symm : ⊀ ⊆ S.objs) (Set.mem_univ c) exact id_mem_of_src S γS theorem IsWide.id_mem {S : Subgroupoid C} (Sw : S.IsWide) (c : C) : 𝟙 c ∈ S.arrows c c := Sw.wide c theorem IsWide.eqToHom_mem {S : Subgroupoid C} (Sw : S.IsWide) {c d : C} (h : c = d) : eqToHom h ∈ S.arrows c d := by cases h; simp only [eqToHom_refl]; apply Sw.id_mem c /-- A subgroupoid is normal if it is wide and satisfies the expected stability under conjugacy. -/ structure IsNormal : Prop extends IsWide S where conj : ∀ {c d} (p : c ⟶ d) {γ : c ⟶ c}, γ ∈ S.arrows c c → Groupoid.inv p ≫ γ ≫ p ∈ S.arrows d d theorem IsNormal.conj' {S : Subgroupoid C} (Sn : IsNormal S) : ∀ {c d} (p : d ⟶ c) {γ : c ⟶ c}, γ ∈ S.arrows c c → p ≫ γ ≫ Groupoid.inv p ∈ S.arrows d d := fun p γ hs => by convert Sn.conj (Groupoid.inv p) hs; simp theorem IsNormal.conjugation_bij (Sn : IsNormal S) {c d} (p : c ⟶ d) : Set.BijOn (fun γ : c ⟶ c => Groupoid.inv p ≫ γ ≫ p) (S.arrows c c) (S.arrows d d) := by refine ⟹fun γ γS => Sn.conj p γS, fun γ₁ _ γ₂ _ h => ?_, fun ÎŽ ÎŽS => ⟹p ≫ ÎŽ ≫ Groupoid.inv p, Sn.conj' p ÎŽS, ?_⟩⟩ · simpa only [inv_eq_inv, Category.assoc, IsIso.hom_inv_id, Category.comp_id, IsIso.hom_inv_id_assoc] using p ≫= h =≫ inv p · simp only [inv_eq_inv, Category.assoc, IsIso.inv_hom_id, Category.comp_id, IsIso.inv_hom_id_assoc] theorem top_isNormal : IsNormal (⊀ : Subgroupoid C) := { wide := fun _ => trivial conj := fun _ _ _ => trivial } theorem sInf_isNormal (s : Set <| Subgroupoid C) (sn : ∀ S ∈ s, IsNormal S) : IsNormal (sInf s) := { wide := by simp_rw [sInf, mem_iInter₂]; exact fun c S Ss => (sn S Ss).wide c conj := by simp_rw [sInf, mem_iInter₂]; exact fun p γ hγ S Ss => (sn S Ss).conj p (hγ S Ss) } theorem discrete_isNormal : (@discrete C _).IsNormal := { wide := fun c => by constructor conj := fun f γ hγ => by cases hγ simp only [inv_eq_inv, Category.id_comp, IsIso.inv_hom_id]; constructor } theorem IsNormal.vertexSubgroup (Sn : IsNormal S) (c : C) (cS : c ∈ S.objs) : (S.vertexSubgroup cS).Normal where conj_mem x hx y := by rw [mul_assoc]; exact Sn.conj' y hx section GeneratedSubgroupoid -- TODO: proof that generated is just "words in X" and generatedNormal is similarly variable (X : ∀ c d : C, Set (c ⟶ d)) /-- The subgropoid generated by the set of arrows `X` -/ def generated : Subgroupoid C := sInf {S : Subgroupoid C | ∀ c d, X c d ⊆ S.arrows c d} theorem subset_generated (c d : C) : X c d ⊆ (generated X).arrows c d := by dsimp only [generated, sInf] simp only [subset_iInter₂_iff] exact fun S hS f fS => hS _ _ fS /-- The normal sugroupoid generated by the set of arrows `X` -/ def generatedNormal : Subgroupoid C := sInf {S : Subgroupoid C | (∀ c d, X c d ⊆ S.arrows c d) ∧ S.IsNormal} theorem generated_le_generatedNormal : generated X ≀ generatedNormal X := by apply @sInf_le_sInf (Subgroupoid C) _ exact fun S ⟹h, _⟩ => h theorem generatedNormal_isNormal : (generatedNormal X).IsNormal := sInf_isNormal _ fun _ h => h.right theorem IsNormal.generatedNormal_le {S : Subgroupoid C} (Sn : S.IsNormal) : generatedNormal X ≀ S ↔ ∀ c d, X c d ⊆ S.arrows c d := by constructor · rintro h c d have h' := generated_le_generatedNormal X rw [le_iff] at h h' exact ((subset_generated X c d).trans (@h' c d)).trans (@h c d) · rintro h apply @sInf_le (Subgroupoid C) _ exact ⟹h, Sn⟩ end GeneratedSubgroupoid section Hom variable {D : Type*} [Groupoid D] (φ : C ⥀ D) /-- A functor between groupoid defines a map of subgroupoids in the reverse direction by taking preimages. -/ def comap (S : Subgroupoid D) : Subgroupoid C where arrows c d := {f : c ⟶ d | φ.map f ∈ S.arrows (φ.obj c) (φ.obj d)} inv hp := by rw [mem_setOf, inv_eq_inv, φ.map_inv, ← inv_eq_inv]; exact S.inv hp mul := by intros simp only [mem_setOf, Functor.map_comp] apply S.mul <;> assumption theorem comap_mono (S T : Subgroupoid D) : S ≀ T → comap φ S ≀ comap φ T := fun ST _ => @ST ⟹_, _, _⟩ theorem isNormal_comap {S : Subgroupoid D} (Sn : IsNormal S) : IsNormal (comap φ S) where wide c := by rw [comap, mem_setOf, Functor.map_id]; apply Sn.wide conj f γ hγ := by simp_rw [inv_eq_inv f, comap, mem_setOf, Functor.map_comp, Functor.map_inv, ← inv_eq_inv] exact Sn.conj _ hγ @[simp] theorem comap_comp {E : Type*} [Groupoid E] (ψ : D ⥀ E) : comap (φ ⋙ ψ) = comap φ ∘ comap ψ := rfl /-- The kernel of a functor between subgroupoid is the preimage. -/ def ker : Subgroupoid C := comap φ discrete theorem mem_ker_iff {c d : C} (f : c ⟶ d) : f ∈ (ker φ).arrows c d ↔ ∃ h : φ.obj c = φ.obj d, φ.map f = eqToHom h := mem_discrete_iff (φ.map f) theorem ker_isNormal : (ker φ).IsNormal := isNormal_comap φ discrete_isNormal @[simp] theorem ker_comp {E : Type*} [Groupoid E] (ψ : D ⥀ E) : ker (φ ⋙ ψ) = comap φ (ker ψ) := rfl /-- The family of arrows of the image of a subgroupoid under a functor injective on objects -/ inductive Map.Arrows (hφ : Function.Injective φ.obj) (S : Subgroupoid C) : ∀ c d : D, (c ⟶ d) → Prop | im {c d : C} (f : c ⟶ d) (hf : f ∈ S.arrows c d) : Map.Arrows hφ S (φ.obj c) (φ.obj d) (φ.map f) theorem Map.arrows_iff (hφ : Function.Injective φ.obj) (S : Subgroupoid C) {c d : D} (f : c ⟶ d) : Map.Arrows φ hφ S c d f ↔ ∃ (a b : C) (g : a ⟶ b) (ha : φ.obj a = c) (hb : φ.obj b = d) (_hg : g ∈ S.arrows a b), f = eqToHom ha.symm ≫ φ.map g ≫ eqToHom hb := by constructor · rintro ⟹g, hg⟩; exact ⟹_, _, g, rfl, rfl, hg, eq_conj_eqToHom _⟩ · rintro ⟹a, b, g, rfl, rfl, hg, rfl⟩; rw [← eq_conj_eqToHom]; constructor; exact hg /-- The "forward" image of a subgroupoid under a functor injective on objects -/ def map (hφ : Function.Injective φ.obj) (S : Subgroupoid C) : Subgroupoid D where arrows c d := {x | Map.Arrows φ hφ S c d x} inv := by rintro _ _ _ ⟚⟩ rw [inv_eq_inv, ← Functor.map_inv, ← inv_eq_inv] constructor; apply S.inv; assumption mul := by rintro _ _ _ _ ⟹f, hf⟩ q hq obtain ⟹c₃, c₄, g, he, rfl, hg, gq⟩ := (Map.arrows_iff φ hφ S q).mp hq cases hφ he; rw [gq, ← eq_conj_eqToHom, ← φ.map_comp] constructor; exact S.mul hf hg theorem mem_map_iff (hφ : Function.Injective φ.obj) (S : Subgroupoid C) {c d : D} (f : c ⟶ d) : f ∈ (map φ hφ S).arrows c d ↔ ∃ (a b : C) (g : a ⟶ b) (ha : φ.obj a = c) (hb : φ.obj b = d) (_hg : g ∈ S.arrows a b), f = eqToHom ha.symm ≫ φ.map g ≫ eqToHom hb := Map.arrows_iff φ hφ S f theorem galoisConnection_map_comap (hφ : Function.Injective φ.obj) : GaloisConnection (map φ hφ) (comap φ) := by rintro S T; simp_rw [le_iff]; constructor · exact fun h c d f fS => h (Map.Arrows.im f fS) · rintro h _ _ g ⟹a, gφS⟩ exact h gφS theorem map_mono (hφ : Function.Injective φ.obj) (S T : Subgroupoid C) : S ≀ T → map φ hφ S ≀ map φ hφ T := fun h => (galoisConnection_map_comap φ hφ).monotone_l h theorem le_comap_map (hφ : Function.Injective φ.obj) (S : Subgroupoid C) : S ≀ comap φ (map φ hφ S) := (galoisConnection_map_comap φ hφ).le_u_l S theorem map_comap_le (hφ : Function.Injective φ.obj) (T : Subgroupoid D) : map φ hφ (comap φ T) ≀ T := (galoisConnection_map_comap φ hφ).l_u_le T theorem map_le_iff_le_comap (hφ : Function.Injective φ.obj) (S : Subgroupoid C) (T : Subgroupoid D) : map φ hφ S ≀ T ↔ S ≀ comap φ T := (galoisConnection_map_comap φ hφ).le_iff_le theorem mem_map_objs_iff (hφ : Function.Injective φ.obj) (d : D) : d ∈ (map φ hφ S).objs ↔ ∃ c ∈ S.objs, φ.obj c = d := by dsimp [objs, map] constructor · rintro ⟹f, hf⟩ change Map.Arrows φ hφ S d d f at hf; rw [Map.arrows_iff] at hf obtain ⟹c, d, g, ec, ed, eg, gS, eg⟩ := hf exact ⟹c, ⟹mem_objs_of_src S eg, ec⟩⟩ · rintro ⟹c, ⟚γ, γS⟩, rfl⟩ exact ⟚φ.map γ, ⟚γ, γS⟩⟩ @[simp] theorem map_objs_eq (hφ : Function.Injective φ.obj) : (map φ hφ S).objs = φ.obj '' S.objs := by ext x; convert mem_map_objs_iff S φ hφ x /-- The image of a functor injective on objects -/ def im (hφ : Function.Injective φ.obj) := map φ hφ ⊀ theorem mem_im_iff (hφ : Function.Injective φ.obj) {c d : D} (f : c ⟶ d) : f ∈ (im φ hφ).arrows c d ↔ ∃ (a b : C) (g : a ⟶ b) (ha : φ.obj a = c) (hb : φ.obj b = d), f = eqToHom ha.symm ≫ φ.map g ≫ eqToHom hb := by convert Map.arrows_iff φ hφ ⊀ f; simp only [Top.top, mem_univ, exists_true_left] theorem mem_im_objs_iff (hφ : Function.Injective φ.obj) (d : D) : d ∈ (im φ hφ).objs ↔ ∃ c : C, φ.obj c = d := by simp only [im, mem_map_objs_iff, mem_top_objs, true_and] theorem obj_surjective_of_im_eq_top (hφ : Function.Injective φ.obj) (hφ' : im φ hφ = ⊀) : Function.Surjective φ.obj := by rintro d rw [← mem_im_objs_iff, hφ'] apply mem_top_objs theorem isNormal_map (hφ : Function.Injective φ.obj) (hφ' : im φ hφ = ⊀) (Sn : S.IsNormal) : (map φ hφ S).IsNormal := { wide := fun d => by obtain ⟹c, rfl⟩ := obj_surjective_of_im_eq_top φ hφ hφ' d change Map.Arrows φ hφ S _ _ (𝟙 _); rw [← Functor.map_id] constructor; exact Sn.wide c conj := fun {d d'} g ÎŽ hÎŽ => by rw [mem_map_iff] at hÎŽ obtain ⟹c, c', γ, cd, cd', γS, hγ⟩ := hÎŽ; subst_vars; cases hφ cd' have : d' ∈ (im φ hφ).objs := by rw [hφ']; apply mem_top_objs rw [mem_im_objs_iff] at this obtain ⟹c', rfl⟩ := this have : g ∈ (im φ hφ).arrows (φ.obj c) (φ.obj c') := by rw [hφ']; trivial rw [mem_im_iff] at this obtain ⟹b, b', f, hb, hb', _, hf⟩ := this; cases hφ hb; cases hφ hb' change Map.Arrows φ hφ S (φ.obj c') (φ.obj c') _ simp only [eqToHom_refl, Category.comp_id, Category.id_comp, inv_eq_inv] suffices Map.Arrows φ hφ S (φ.obj c') (φ.obj c') (φ.map <| Groupoid.inv f ≫ γ ≫ f) by simp only [inv_eq_inv, Functor.map_comp, Functor.map_inv] at this; exact this constructor; apply Sn.conj f γS } end Hom section Thin /-- A subgroupoid is thin (`CategoryTheory.Subgroupoid.IsThin`) if it has at most one arrow between any two vertices. -/ abbrev IsThin := Quiver.IsThin S.objs nonrec theorem isThin_iff : S.IsThin ↔ ∀ c : S.objs, Subsingleton (S.arrows c c) := isThin_iff _ end Thin section Disconnected /-- A subgroupoid `IsTotallyDisconnected` if it has only isotropy arrows. -/ nonrec abbrev IsTotallyDisconnected := IsTotallyDisconnected S.objs theorem isTotallyDisconnected_iff : S.IsTotallyDisconnected ↔ ∀ c d, (S.arrows c d).Nonempty → c = d := by constructor · rintro h c d ⟹f, fS⟩ exact congr_arg Subtype.val <| h ⟹c, mem_objs_of_src S fS⟩ ⟹d, mem_objs_of_tgt S fS⟩ ⟹f, fS⟩ · rintro h ⟹c, hc⟩ ⟹d, hd⟩ ⟹f, fS⟩ simp only [Subtype.mk_eq_mk] exact h c d ⟹f, fS⟩ /-- The isotropy subgroupoid of `S` -/ def disconnect : Subgroupoid C where arrows c d := {f | c = d ∧ f ∈ S.arrows c d} inv := by rintro _ _ _ ⟹rfl, h⟩; exact ⟹rfl, S.inv h⟩ mul := by rintro _ _ _ _ ⟹rfl, h⟩ _ ⟹rfl, h'⟩; exact ⟹rfl, S.mul h h'⟩ theorem disconnect_le : S.disconnect ≀ S := by rw [le_iff]; rintro _ _ _ ⟚⟩; assumption theorem disconnect_normal (Sn : S.IsNormal) : S.disconnect.IsNormal := { wide := fun c => ⟹rfl, Sn.wide c⟩ conj := fun _ _ ⟹_, h'⟩ => ⟹rfl, Sn.conj _ h'⟩ } @[simp] theorem mem_disconnect_objs_iff {c : C} : c ∈ S.disconnect.objs ↔ c ∈ S.objs := ⟹fun ⟚γ, _, γS⟩ => ⟚γ, γS⟩, fun ⟚γ, γS⟩ => ⟚γ, rfl, γS⟩⟩ theorem disconnect_objs : S.disconnect.objs = S.objs := Set.ext fun _ ↩ mem_disconnect_objs_iff _
theorem disconnect_isTotallyDisconnected : S.disconnect.IsTotallyDisconnected := by rw [isTotallyDisconnected_iff]; exact fun c d ⟹_, h, _⟩ => h end Disconnected
Mathlib/CategoryTheory/Groupoid/Subgroupoid.lean
565
569
/- Copyright (c) 2021 Alex Kontorovich and Heather Macbeth and Marc Masdeu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alex Kontorovich, Heather Macbeth, Marc Masdeu -/ import Mathlib.Analysis.Complex.UpperHalfPlane.Basic import Mathlib.LinearAlgebra.GeneralLinearGroup import Mathlib.LinearAlgebra.Matrix.GeneralLinearGroup.Basic import Mathlib.Topology.Instances.Matrix import Mathlib.Topology.Algebra.Module.FiniteDimension import Mathlib.Topology.Instances.ZMultiples /-! # The action of the modular group SL(2, â„€) on the upper half-plane We define the action of `SL(2,â„€)` on `ℍ` (via restriction of the `SL(2,ℝ)` action in `Analysis.Complex.UpperHalfPlane`). We then define the standard fundamental domain (`ModularGroup.fd`, `𝒟`) for this action and show (`ModularGroup.exists_smul_mem_fd`) that any point in `ℍ` can be moved inside `𝒟`. ## Main definitions The standard (closed) fundamental domain of the action of `SL(2,â„€)` on `ℍ`, denoted `𝒟`: `fd := {z | 1 ≀ (z : ℂ).normSq ∧ |z.re| ≀ (1 : ℝ) / 2}` The standard open fundamental domain of the action of `SL(2,â„€)` on `ℍ`, denoted `𝒟ᵒ`: `fdo := {z | 1 < (z : ℂ).normSq ∧ |z.re| < (1 : ℝ) / 2}` These notations are localized in the `Modular` locale and can be enabled via `open scoped Modular`. ## Main results Any `z : ℍ` can be moved to `𝒟` by an element of `SL(2,â„€)`: `exists_smul_mem_fd (z : ℍ) : ∃ g : SL(2,â„€), g • z ∈ 𝒟` If both `z` and `γ • z` are in the open domain `𝒟ᵒ` then `z = γ • z`: `eq_smul_self_of_mem_fdo_mem_fdo {z : ℍ} {g : SL(2,â„€)} (hz : z ∈ 𝒟ᵒ) (hg : g • z ∈ 𝒟ᵒ) : z = g • z` # Discussion Standard proofs make use of the identity `g • z = a / c - 1 / (c (cz + d))` for `g = [[a, b], [c, d]]` in `SL(2)`, but this requires separate handling of whether `c = 0`. Instead, our proof makes use of the following perhaps novel identity (see `ModularGroup.smul_eq_lcRow0_add`): `g • z = (a c + b d) / (c^2 + d^2) + (d z - c) / ((c^2 + d^2) (c z + d))` where there is no issue of division by zero. Another feature is that we delay until the very end the consideration of special matrices `T=[[1,1],[0,1]]` (see `ModularGroup.T`) and `S=[[0,-1],[1,0]]` (see `ModularGroup.S`), by instead using abstract theory on the properness of certain maps (phrased in terms of the filters `Filter.cocompact`, `Filter.cofinite`, etc) to deduce existence theorems, first to prove the existence of `g` maximizing `(g•z).im` (see `ModularGroup.exists_max_im`), and then among those, to minimize `|(g•z).re|` (see `ModularGroup.exists_row_one_eq_and_min_re`). -/ open Complex hiding abs_two open Matrix hiding mul_smul open Matrix.SpecialLinearGroup UpperHalfPlane ModularGroup Topology noncomputable section open scoped ComplexConjugate MatrixGroups namespace ModularGroup variable {g : SL(2, â„€)} (z : ℍ) section BottomRow /-- The two numbers `c`, `d` in the "bottom_row" of `g=[[*,*],[c,d]]` in `SL(2, â„€)` are coprime. -/ theorem bottom_row_coprime {R : Type*} [CommRing R] (g : SL(2, R)) : IsCoprime ((↑g : Matrix (Fin 2) (Fin 2) R) 1 0) ((↑g : Matrix (Fin 2) (Fin 2) R) 1 1) := by use -(↑g : Matrix (Fin 2) (Fin 2) R) 0 1, (↑g : Matrix (Fin 2) (Fin 2) R) 0 0 rw [add_comm, neg_mul, ← sub_eq_add_neg, ← det_fin_two] exact g.det_coe /-- Every pair `![c, d]` of coprime integers is the "bottom_row" of some element `g=[[*,*],[c,d]]` of `SL(2,â„€)`. -/ theorem bottom_row_surj {R : Type*} [CommRing R] : Set.SurjOn (fun g : SL(2, R) => (↑g : Matrix (Fin 2) (Fin 2) R) 1) Set.univ {cd | IsCoprime (cd 0) (cd 1)} := by rintro cd ⟹b₀, a, gcd_eqn⟩ let A := of ![![a, -b₀], cd] have det_A_1 : det A = 1 := by convert gcd_eqn rw [det_fin_two] simp [A, (by ring : a * cd 1 + b₀ * cd 0 = b₀ * cd 0 + a * cd 1)] refine ⟹⟹A, det_A_1⟩, Set.mem_univ _, ?_⟩ ext; simp [A] end BottomRow section TendstoLemmas open Filter ContinuousLinearMap attribute [local simp] ContinuousLinearMap.coe_smul /-- The function `(c,d) → |cz+d|^2` is proper, that is, preimages of bounded-above sets are finite. -/ theorem tendsto_normSq_coprime_pair : Filter.Tendsto (fun p : Fin 2 → â„€ => normSq ((p 0 : ℂ) * z + p 1)) cofinite atTop := by -- using this instance rather than the automatic `Function.module` makes unification issues in -- `LinearEquiv.isClosedEmbedding_of_injective` less bad later in the proof. letI : Module ℝ (Fin 2 → ℝ) := NormedSpace.toModule let π₀ : (Fin 2 → ℝ) →ₗ[ℝ] ℝ := LinearMap.proj 0 let π₁ : (Fin 2 → ℝ) →ₗ[ℝ] ℝ := LinearMap.proj 1 let f : (Fin 2 → ℝ) →ₗ[ℝ] ℂ := π₀.smulRight (z : ℂ) + π₁.smulRight 1 have f_def : ⇑f = fun p : Fin 2 → ℝ => (p 0 : ℂ) * ↑z + p 1 := by ext1 dsimp only [π₀, π₁, f, LinearMap.coe_proj, real_smul, LinearMap.coe_smulRight, LinearMap.add_apply] rw [mul_one] have : (fun p : Fin 2 → â„€ => normSq ((p 0 : ℂ) * ↑z + ↑(p 1))) = normSq ∘ f ∘ fun p : Fin 2 → â„€ => ((↑) : â„€ → ℝ) ∘ p := by ext1 rw [f_def] dsimp only [Function.comp_def] rw [ofReal_intCast, ofReal_intCast] rw [this] have hf : LinearMap.ker f = ⊥ := by let g : ℂ →ₗ[ℝ] Fin 2 → ℝ := LinearMap.pi ![imLm, imLm.comp ((z : ℂ) • ((conjAe : ℂ →ₐ[ℝ] ℂ) : ℂ →ₗ[ℝ] ℂ))] suffices ((z : ℂ).im⁻¹ • g).comp f = LinearMap.id by exact LinearMap.ker_eq_bot_of_inverse this apply LinearMap.ext intro c have hz : (z : ℂ).im ≠ 0 := z.2.ne' rw [LinearMap.comp_apply, LinearMap.smul_apply, LinearMap.id_apply] ext i dsimp only [Pi.smul_apply, LinearMap.pi_apply, smul_eq_mul] fin_cases i · show (z : ℂ).im⁻¹ * (f c).im = c 0 rw [f_def, add_im, im_ofReal_mul, ofReal_im, add_zero, mul_left_comm, inv_mul_cancel₀ hz, mul_one] · show (z : ℂ).im⁻¹ * ((z : ℂ) * conj (f c)).im = c 1 rw [f_def, RingHom.map_add, RingHom.map_mul, mul_add, mul_left_comm, mul_conj, conj_ofReal, conj_ofReal, ← ofReal_mul, add_im, ofReal_im, zero_add, inv_mul_eq_iff_eq_mul₀ hz] simp only [ofReal_im, ofReal_re, mul_im, zero_add, mul_zero] have hf' : IsClosedEmbedding f := f.isClosedEmbedding_of_injective hf have h₂ : Tendsto (fun p : Fin 2 → â„€ => ((↑) : â„€ → ℝ) ∘ p) cofinite (cocompact _) := by convert Tendsto.pi_map_coprodáµ¢ fun _ => Int.tendsto_coe_cofinite · rw [coprodáµ¢_cofinite] · rw [coprodáµ¢_cocompact] exact tendsto_normSq_cocompact_atTop.comp (hf'.tendsto_cocompact.comp h₂) /-- Given `coprime_pair` `p=(c,d)`, the matrix `[[a,b],[*,*]]` is sent to `a*c+b*d`. This is the linear map version of this operation. -/ def lcRow0 (p : Fin 2 → â„€) : Matrix (Fin 2) (Fin 2) ℝ →ₗ[ℝ] ℝ := ((p 0 : ℝ) • LinearMap.proj (0 : Fin 2) + (p 1 : ℝ) • LinearMap.proj (1 : Fin 2) : (Fin 2 → ℝ) →ₗ[ℝ] ℝ).comp (LinearMap.proj 0) @[simp] theorem lcRow0_apply (p : Fin 2 → â„€) (g : Matrix (Fin 2) (Fin 2) ℝ) : lcRow0 p g = p 0 * g 0 0 + p 1 * g 0 1 := rfl /-- Linear map sending the matrix [a, b; c, d] to the matrix [ac₀ + bd₀, - ad₀ + bc₀; c, d], for some fixed `(c₀, d₀)`. -/ @[simps!] def lcRow0Extend {cd : Fin 2 → â„€} (hcd : IsCoprime (cd 0) (cd 1)) : Matrix (Fin 2) (Fin 2) ℝ ≃ₗ[ℝ] Matrix (Fin 2) (Fin 2) ℝ := LinearEquiv.piCongrRight ![by refine LinearMap.GeneralLinearGroup.generalLinearEquiv ℝ (Fin 2 → ℝ) (GeneralLinearGroup.toLin (planeConformalMatrix (cd 0 : ℝ) (-(cd 1 : ℝ)) ?_)) norm_cast rw [neg_sq] exact hcd.sq_add_sq_ne_zero, LinearEquiv.refl ℝ (Fin 2 → ℝ)] /-- The map `lcRow0` is proper, that is, preimages of cocompact sets are finite in `[[* , *], [c, d]]`. -/ theorem tendsto_lcRow0 {cd : Fin 2 → â„€} (hcd : IsCoprime (cd 0) (cd 1)) : Tendsto (fun g : { g : SL(2, â„€) // g 1 = cd } => lcRow0 cd ↑(↑g : SL(2, ℝ))) cofinite (cocompact ℝ) := by let mB : ℝ → Matrix (Fin 2) (Fin 2) ℝ := fun t => of ![![t, (-(1 : â„€) : ℝ)], (↑) ∘ cd] have hmB : Continuous mB := by refine continuous_matrix ?_ simp only [mB, Fin.forall_fin_two, continuous_const, continuous_id', of_apply, cons_val_zero, cons_val_one, and_self_iff] refine Filter.Tendsto.of_tendsto_comp ?_ (comap_cocompact_le hmB) let f₁ : SL(2, â„€) → Matrix (Fin 2) (Fin 2) ℝ := fun g => Matrix.map (↑g : Matrix _ _ â„€) ((↑) : â„€ → ℝ) have cocompact_ℝ_to_cofinite_â„€_matrix : Tendsto (fun m : Matrix (Fin 2) (Fin 2) â„€ => Matrix.map m ((↑) : â„€ → ℝ)) cofinite (cocompact _) := by simpa only [coprodáµ¢_cofinite, coprodáµ¢_cocompact] using Tendsto.pi_map_coprodáµ¢ fun _ : Fin 2 => Tendsto.pi_map_coprodáµ¢ fun _ : Fin 2 => Int.tendsto_coe_cofinite have hf₁ : Tendsto f₁ cofinite (cocompact _) := cocompact_ℝ_to_cofinite_â„€_matrix.comp Subtype.coe_injective.tendsto_cofinite have hf₂ : IsClosedEmbedding (lcRow0Extend hcd) := (lcRow0Extend hcd).toContinuousLinearEquiv.toHomeomorph.isClosedEmbedding convert hf₂.tendsto_cocompact.comp (hf₁.comp Subtype.coe_injective.tendsto_cofinite) using 1 ext ⟹g, rfl⟩ i j : 3 fin_cases i <;> [fin_cases j; skip] -- the following are proved by `simp`, but it is replaced by `simp only` to avoid timeouts. · simp only [Fin.isValue, Int.cast_one, map_apply_coe, RingHom.mapMatrix_apply, Int.coe_castRingHom, lcRow0_apply, map_apply, Fin.zero_eta, id_eq, Function.comp_apply, of_apply, cons_val', cons_val_zero, empty_val', cons_val_fin_one, lcRow0Extend_apply, LinearMap.GeneralLinearGroup.coeFn_generalLinearEquiv, GeneralLinearGroup.coe_toLin, val_planeConformalMatrix, neg_neg, mulVecLin_apply, mulVec, dotProduct, Fin.sum_univ_two, cons_val_one, head_cons, mB, f₁] · convert congr_arg (fun n : â„€ => (-n : ℝ)) g.det_coe.symm using 1 simp only [Fin.zero_eta, id_eq, Function.comp_apply, lcRow0Extend_apply, cons_val_zero, LinearMap.GeneralLinearGroup.coeFn_generalLinearEquiv, GeneralLinearGroup.coe_toLin, mulVecLin_apply, mulVec, dotProduct, det_fin_two, f₁] simp only [Fin.isValue, Fin.mk_one, val_planeConformalMatrix, neg_neg, of_apply, cons_val', empty_val', cons_val_fin_one, cons_val_one, head_fin_const, map_apply, Fin.sum_univ_two, cons_val_zero, neg_mul, head_cons, Int.cast_sub, Int.cast_mul, neg_sub] ring · rfl /-- This replaces `(g•z).re = a/c + *` in the standard theory with the following novel identity: `g • z = (a c + b d) / (c^2 + d^2) + (d z - c) / ((c^2 + d^2) (c z + d))` which does not need to be decomposed depending on whether `c = 0`. -/ theorem smul_eq_lcRow0_add {p : Fin 2 → â„€} (hp : IsCoprime (p 0) (p 1)) (hg : g 1 = p) : ↑(g • z) = (lcRow0 p ↑(g : SL(2, ℝ)) : ℂ) / ((p 0 : ℂ) ^ 2 + (p 1 : ℂ) ^ 2) + ((p 1 : ℂ) * z - p 0) / (((p 0 : ℂ) ^ 2 + (p 1 : ℂ) ^ 2) * (p 0 * z + p 1)) := by have nonZ1 : (p 0 : ℂ) ^ 2 + (p 1 : ℂ) ^ 2 ≠ 0 := mod_cast hp.sq_add_sq_ne_zero have : ((↑) : â„€ → ℝ) ∘ p ≠ 0 := fun h => hp.ne_zero (by ext i; simpa using congr_fun h i) have nonZ2 : (p 0 : ℂ) * z + p 1 ≠ 0 := by simpa using linear_ne_zero _ z this field_simp [nonZ1, nonZ2, denom_ne_zero, num] rw [(by simp : (p 1 : ℂ) * z - p 0 = (p 1 * z - p 0) * ↑(Matrix.det (↑g : Matrix (Fin 2) (Fin 2) â„€)))] rw [← hg, det_fin_two] simp only [Int.coe_castRingHom, coe_matrix_coe, Int.cast_mul, ofReal_intCast, map_apply, denom, Int.cast_sub, coe_GLPos_coe_GL_coe_matrix, coe_apply_complex] ring theorem tendsto_abs_re_smul {p : Fin 2 → â„€} (hp : IsCoprime (p 0) (p 1)) : Tendsto (fun g : { g : SL(2, â„€) // g 1 = p } => |((g : SL(2, â„€)) • z).re|) cofinite atTop := by suffices Tendsto (fun g : (fun g : SL(2, â„€) => g 1) ⁻¹' {p} => ((g : SL(2, â„€)) • z).re) cofinite (cocompact ℝ) by exact tendsto_norm_cocompact_atTop.comp this have : ((p 0 : ℝ) ^ 2 + (p 1 : ℝ) ^ 2)⁻¹ ≠ 0 := by apply inv_ne_zero exact mod_cast hp.sq_add_sq_ne_zero let f := Homeomorph.mulRight₀ _ this let ff := Homeomorph.addRight (((p 1 : ℂ) * z - p 0) / (((p 0 : ℂ) ^ 2 + (p 1 : ℂ) ^ 2) * (p 0 * z + p 1))).re convert (f.trans ff).isClosedEmbedding.tendsto_cocompact.comp (tendsto_lcRow0 hp) with _ _ g
change ((g : SL(2, â„€)) • z).re = lcRow0 p ↑(↑g : SL(2, ℝ)) / ((p 0 : ℝ) ^ 2 + (p 1 : ℝ) ^ 2) + Complex.re (((p 1 : ℂ) * z - p 0) / (((p 0 : ℂ) ^ 2 + (p 1 : ℂ) ^ 2) * (p 0 * z + p 1))) exact mod_cast congr_arg Complex.re (smul_eq_lcRow0_add z hp g.2) end TendstoLemmas section FundamentalDomain attribute [local simp] UpperHalfPlane.coe_smul re_smul /-- For `z : ℍ`, there is a `g : SL(2,â„€)` maximizing `(g•z).im` -/ theorem exists_max_im : ∃ g : SL(2, â„€), ∀ g' : SL(2, â„€), (g' • z).im ≀ (g • z).im := by classical let s : Set (Fin 2 → â„€) := {cd | IsCoprime (cd 0) (cd 1)} have hs : s.Nonempty := ⟹![1, 1], isCoprime_one_left⟩ obtain ⟹p, hp_coprime, hp⟩ :=
Mathlib/NumberTheory/Modular.lean
258
276
/- 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] 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 unfold orderOf rw [← minimalPeriod_iterate_eq_div_gcd h, mul_left_iterate] @[to_additive] lemma orderOf_pow_of_dvd {x : G} {n : ℕ} (hn : n ≠ 0) (dvd : n ∣ orderOf x) : orderOf (x ^ n) = orderOf x / n := by rw [orderOf_pow' _ hn, Nat.gcd_eq_right dvd] @[to_additive] lemma orderOf_pow_orderOf_div {x : G} {n : ℕ} (hx : orderOf x ≠ 0) (hn : n ∣ orderOf x) : orderOf (x ^ (orderOf x / n)) = n := by rw [orderOf_pow_of_dvd _ (Nat.div_dvd_of_dvd hn), Nat.div_div_self hn hx] rw [← Nat.div_mul_cancel hn] at hx; exact left_ne_zero_of_mul hx variable (n) @[to_additive] protected lemma IsOfFinOrder.orderOf_pow (h : IsOfFinOrder x) : orderOf (x ^ n) = orderOf x / gcd (orderOf x) n := by unfold orderOf rw [← minimalPeriod_iterate_eq_div_gcd' h, mul_left_iterate] @[to_additive] lemma Nat.Coprime.orderOf_pow (h : (orderOf y).Coprime m) : orderOf (y ^ m) = orderOf y := by by_cases hg : IsOfFinOrder y · rw [hg.orderOf_pow y m , h.gcd_eq_one, Nat.div_one] · rw [m.coprime_zero_left.1 (orderOf_eq_zero hg ▾ h), pow_one] @[to_additive] lemma IsOfFinOrder.natCard_powers_le_orderOf (ha : IsOfFinOrder a) : Nat.card (powers a : Set G) ≀ orderOf a := by classical simpa [ha.powers_eq_image_range_orderOf, Finset.card_range, Nat.Iio_eq_range] using Finset.card_image_le (s := Finset.range (orderOf a)) @[to_additive] lemma IsOfFinOrder.finite_powers (ha : IsOfFinOrder a) : (powers a : Set G).Finite := by classical rw [ha.powers_eq_image_range_orderOf]; exact Finset.finite_toSet _ namespace Commute variable {x} @[to_additive] theorem orderOf_mul_dvd_lcm (h : Commute x y) : orderOf (x * y) ∣ Nat.lcm (orderOf x) (orderOf y) := by rw [orderOf, ← comp_mul_left] exact Function.Commute.minimalPeriod_of_comp_dvd_lcm h.function_commute_mul_left @[to_additive] theorem orderOf_dvd_lcm_mul (h : Commute x y): orderOf y ∣ Nat.lcm (orderOf x) (orderOf (x * y)) := by by_cases h0 : orderOf x = 0 · rw [h0, lcm_zero_left] apply dvd_zero conv_lhs => rw [← one_mul y, ← pow_orderOf_eq_one x, ← succ_pred_eq_of_pos (Nat.pos_of_ne_zero h0), _root_.pow_succ, mul_assoc] exact (((Commute.refl x).mul_right h).pow_left _).orderOf_mul_dvd_lcm.trans (lcm_dvd_iff.2 ⟹(orderOf_pow_dvd _).trans (dvd_lcm_left _ _), dvd_lcm_right _ _⟩) @[to_additive addOrderOf_add_dvd_mul_addOrderOf] theorem orderOf_mul_dvd_mul_orderOf (h : Commute x y): orderOf (x * y) ∣ orderOf x * orderOf y := dvd_trans h.orderOf_mul_dvd_lcm (lcm_dvd_mul _ _) @[to_additive addOrderOf_add_eq_mul_addOrderOf_of_coprime] theorem orderOf_mul_eq_mul_orderOf_of_coprime (h : Commute x y) (hco : (orderOf x).Coprime (orderOf y)) : orderOf (x * y) = orderOf x * orderOf y := by rw [orderOf, ← comp_mul_left] exact h.function_commute_mul_left.minimalPeriod_of_comp_eq_mul_of_coprime hco /-- Commuting elements of finite order are closed under multiplication. -/ @[to_additive "Commuting elements of finite additive order are closed under addition."] theorem isOfFinOrder_mul (h : Commute x y) (hx : IsOfFinOrder x) (hy : IsOfFinOrder y) : IsOfFinOrder (x * y) := orderOf_pos_iff.mp <| pos_of_dvd_of_pos h.orderOf_mul_dvd_mul_orderOf <| mul_pos hx.orderOf_pos hy.orderOf_pos /-- If each prime factor of `orderOf x` has higher multiplicity in `orderOf y`, and `x` commutes with `y`, then `x * y` has the same order as `y`. -/ @[to_additive addOrderOf_add_eq_right_of_forall_prime_mul_dvd "If each prime factor of `addOrderOf x` has higher multiplicity in `addOrderOf y`, and `x` commutes with `y`, then `x + y` has the same order as `y`."] theorem orderOf_mul_eq_right_of_forall_prime_mul_dvd (h : Commute x y) (hy : IsOfFinOrder y) (hdvd : ∀ p : ℕ, p.Prime → p ∣ orderOf x → p * orderOf x ∣ orderOf y) : orderOf (x * y) = orderOf y := by have hoy := hy.orderOf_pos have hxy := dvd_of_forall_prime_mul_dvd hdvd apply orderOf_eq_of_pow_and_pow_div_prime hoy <;> simp only [Ne, ← orderOf_dvd_iff_pow_eq_one] · exact h.orderOf_mul_dvd_lcm.trans (lcm_dvd hxy dvd_rfl) refine fun p hp hpy hd => hp.ne_one ?_ rw [← Nat.dvd_one, ← mul_dvd_mul_iff_right hoy.ne', one_mul, ← dvd_div_iff_mul_dvd hpy] refine (orderOf_dvd_lcm_mul h).trans (lcm_dvd ((dvd_div_iff_mul_dvd hpy).2 ?_) hd) by_cases h : p ∣ orderOf x exacts [hdvd p hp h, (hp.coprime_iff_not_dvd.2 h).mul_dvd_of_dvd_of_dvd hpy hxy] end Commute section PPrime variable {x n} {p : ℕ} [hp : Fact p.Prime] @[to_additive] theorem orderOf_eq_prime_iff : orderOf x = p ↔ x ^ p = 1 ∧ x ≠ 1 := by rw [orderOf, minimalPeriod_eq_prime_iff, isPeriodicPt_mul_iff_pow_eq_one, IsFixedPt, mul_one] /-- The backward direction of `orderOf_eq_prime_iff`. -/ @[to_additive "The backward direction of `addOrderOf_eq_prime_iff`."] theorem orderOf_eq_prime (hg : x ^ p = 1) (hg1 : x ≠ 1) : orderOf x = p := orderOf_eq_prime_iff.mpr ⟹hg, hg1⟩ @[to_additive addOrderOf_eq_prime_pow] theorem orderOf_eq_prime_pow (hnot : ¬x ^ p ^ n = 1) (hfin : x ^ p ^ (n + 1) = 1) : orderOf x = p ^ (n + 1) := by apply minimalPeriod_eq_prime_pow <;> rwa [isPeriodicPt_mul_iff_pow_eq_one] @[to_additive exists_addOrderOf_eq_prime_pow_iff] theorem exists_orderOf_eq_prime_pow_iff : (∃ k : ℕ, orderOf x = p ^ k) ↔ ∃ m : ℕ, x ^ (p : ℕ) ^ m = 1 := ⟹fun ⟹k, hk⟩ => ⟹k, by rw [← hk, pow_orderOf_eq_one]⟩, fun ⟹_, hm⟩ => by obtain ⟹k, _, hk⟩ := (Nat.dvd_prime_pow hp.elim).mp (orderOf_dvd_of_pow_eq_one hm) exact ⟹k, hk⟩⟩ end PPrime /-- The equivalence between `Fin (orderOf x)` and `Submonoid.powers x`, sending `i` to `x ^ i` -/ @[to_additive "The equivalence between `Fin (addOrderOf a)` and `AddSubmonoid.multiples a`, sending `i` to `i • a`"] noncomputable def finEquivPowers {x : G} (hx : IsOfFinOrder x) : Fin (orderOf x) ≃ powers x := Equiv.ofBijective (fun n ↩ ⟹x ^ (n : ℕ), ⟹n, rfl⟩⟩) ⟹fun ⟹_, h₁⟩ ⟹_, h₂⟩ ij ↩ Fin.ext (pow_injOn_Iio_orderOf h₁ h₂ (Subtype.mk_eq_mk.1 ij)), fun ⟹_, i, rfl⟩ ↩ ⟹⟹i % orderOf x, mod_lt _ hx.orderOf_pos⟩, Subtype.eq <| pow_mod_orderOf _ _⟩⟩ @[to_additive (attr := simp)] lemma finEquivPowers_apply {x : G} (hx : IsOfFinOrder x) {n : Fin (orderOf x)} : finEquivPowers hx n = ⟹x ^ (n : ℕ), n, rfl⟩ := rfl @[to_additive (attr := simp)] lemma finEquivPowers_symm_apply {x : G} (hx : IsOfFinOrder x) (n : ℕ) : (finEquivPowers hx).symm ⟹x ^ n, _, rfl⟩ = ⟹n % orderOf x, Nat.mod_lt _ hx.orderOf_pos⟩ := by rw [Equiv.symm_apply_eq, finEquivPowers_apply, Subtype.mk_eq_mk, ← pow_mod_orderOf, Fin.val_mk] variable {x n} (hx : IsOfFinOrder x) include hx @[to_additive] theorem IsOfFinOrder.pow_eq_pow_iff_modEq : x ^ n = x ^ m ↔ n ≡ m [MOD orderOf x] := by wlog hmn : m ≀ n generalizing m n · rw [eq_comm, ModEq.comm, this (le_of_not_le hmn)] obtain ⟹k, rfl⟩ := Nat.exists_eq_add_of_le hmn rw [pow_add, (hx.isUnit.pow _).mul_eq_left, pow_eq_one_iff_modEq] exact ⟹fun h ↩ Nat.ModEq.add_left _ h, fun h ↩ Nat.ModEq.add_left_cancel' _ h⟩ @[to_additive] lemma IsOfFinOrder.pow_inj_mod {n m : ℕ} : x ^ n = x ^ m ↔ n % orderOf x = m % orderOf x := hx.pow_eq_pow_iff_modEq end Monoid section CancelMonoid variable [LeftCancelMonoid G] {x y : G} {a : G} {m n : ℕ} @[to_additive] theorem pow_eq_pow_iff_modEq : x ^ n = x ^ m ↔ n ≡ m [MOD orderOf x] := by wlog hmn : m ≀ n generalizing m n · rw [eq_comm, ModEq.comm, this (le_of_not_le hmn)] obtain ⟹k, rfl⟩ := Nat.exists_eq_add_of_le hmn rw [← mul_one (x ^ m), pow_add, mul_left_cancel_iff, pow_eq_one_iff_modEq] exact ⟹fun h => Nat.ModEq.add_left _ h, fun h => Nat.ModEq.add_left_cancel' _ h⟩ @[to_additive (attr := simp)] lemma injective_pow_iff_not_isOfFinOrder : Injective (fun n : ℕ ↩ x ^ n) ↔ ¬IsOfFinOrder x := by refine ⟹fun h => not_isOfFinOrder_of_injective_pow h, fun h n m hnm => ?_⟩ rwa [pow_eq_pow_iff_modEq, orderOf_eq_zero_iff.mpr h, modEq_zero_iff] at hnm @[to_additive] lemma pow_inj_mod {n m : ℕ} : x ^ n = x ^ m ↔ n % orderOf x = m % orderOf x := pow_eq_pow_iff_modEq @[to_additive] theorem pow_inj_iff_of_orderOf_eq_zero (h : orderOf x = 0) {n m : ℕ} : x ^ n = x ^ m ↔ n = m := by rw [pow_eq_pow_iff_modEq, h, modEq_zero_iff] @[to_additive] theorem infinite_not_isOfFinOrder {x : G} (h : ¬IsOfFinOrder x) : { y : G | ¬IsOfFinOrder y }.Infinite := by let s := { n | 0 < n }.image fun n : ℕ => x ^ n have hs : s ⊆ { y : G | ¬IsOfFinOrder y } := by rintro - ⟹n, hn : 0 < n, rfl⟩ (contra : IsOfFinOrder (x ^ n)) apply h rw [isOfFinOrder_iff_pow_eq_one] at contra ⊢ obtain ⟹m, hm, hm'⟩ := contra exact ⟹n * m, mul_pos hn hm, by rwa [pow_mul]⟩ suffices s.Infinite by exact this.mono hs contrapose! h have : ¬Injective fun n : ℕ => x ^ n := by have := Set.not_injOn_infinite_finite_image (Set.Ioi_infinite 0) (Set.not_infinite.mp h) contrapose! this exact Set.injOn_of_injective this rwa [injective_pow_iff_not_isOfFinOrder, Classical.not_not] at this @[to_additive (attr := simp)] lemma finite_powers : (powers a : Set G).Finite ↔ IsOfFinOrder a := by refine ⟹fun h ↩ ?_, IsOfFinOrder.finite_powers⟩ obtain ⟹m, n, hmn, ha⟩ := h.exists_lt_map_eq_of_forall_mem (f := fun n : ℕ ↩ a ^ n) (fun n ↩ by simp [mem_powers_iff]) refine isOfFinOrder_iff_pow_eq_one.2 ⟹n - m, tsub_pos_iff_lt.2 hmn, ?_⟩ rw [← mul_left_cancel_iff (a := a ^ m), ← pow_add, add_tsub_cancel_of_le hmn.le, ha, mul_one] @[to_additive (attr := simp)] lemma infinite_powers : (powers a : Set G).Infinite ↔ ¬ IsOfFinOrder a := finite_powers.not /-- See also `orderOf_eq_card_powers`. -/ @[to_additive "See also `addOrder_eq_card_multiples`."] lemma Nat.card_submonoidPowers : Nat.card (powers a) = orderOf a := by classical by_cases ha : IsOfFinOrder a · exact (Nat.card_congr (finEquivPowers ha).symm).trans <| by simp · have := (infinite_powers.2 ha).to_subtype rw [orderOf_eq_zero ha, Nat.card_eq_zero_of_infinite] end CancelMonoid section Group
variable [Group G] {x y : G} {i : â„€}
Mathlib/GroupTheory/OrderOfElement.lean
580
581
/- 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.Combinatorics.SetFamily.Compression.Down import Mathlib.Data.Fintype.Powerset import Mathlib.Order.Interval.Finset.Nat import Mathlib.Algebra.BigOperators.Group.Finset.Basic /-! # Shattering families This file defines the shattering property and VC-dimension of set families. ## Main declarations * `Finset.Shatters`: The shattering property. * `Finset.shatterer`: The set family of sets shattered by a set family. * `Finset.vcDim`: The Vapnik-Chervonenkis dimension. ## TODO * Order-shattering * Strong shattering -/ open scoped FinsetFamily namespace Finset variable {α : Type*} [DecidableEq α] {𝒜 ℬ : Finset (Finset α)} {s t : Finset α} {a : α} /-- A set family `𝒜` shatters a set `s` if all subsets of `s` can be obtained as the intersection of `s` and some element of the set family, and we denote this `𝒜.Shatters s`. We also say that `s` is *traced* by `𝒜`. -/ def Shatters (𝒜 : Finset (Finset α)) (s : Finset α) : Prop := ∀ ⊃t⩄, t ⊆ s → ∃ u ∈ 𝒜, s ∩ u = t instance : DecidablePred 𝒜.Shatters := fun _s ↩ decidableForallOfDecidableSubsets lemma Shatters.exists_inter_eq_singleton (hs : Shatters 𝒜 s) (ha : a ∈ s) : ∃ t ∈ 𝒜, s ∩ t = {a} := hs <| singleton_subset_iff.2 ha lemma Shatters.mono_left (h : 𝒜 ⊆ ℬ) (h𝒜 : 𝒜.Shatters s) : ℬ.Shatters s := fun _t ht ↩ let ⟹u, hu, hut⟩ := h𝒜 ht; ⟹u, h hu, hut⟩ lemma Shatters.mono_right (h : t ⊆ s) (hs : 𝒜.Shatters s) : 𝒜.Shatters t := fun u hu ↩ by obtain ⟹v, hv, rfl⟩ := hs (hu.trans h); exact ⟹v, hv, inf_congr_right hu <| inf_le_of_left_le h⟩ lemma Shatters.exists_superset (h : 𝒜.Shatters s) : ∃ t ∈ 𝒜, s ⊆ t := let ⟹t, ht, hst⟩ := h Subset.rfl; ⟹t, ht, inter_eq_left.1 hst⟩ lemma shatters_of_forall_subset (h : ∀ t, t ⊆ s → t ∈ 𝒜) : 𝒜.Shatters s := fun t ht ↩ ⟹t, h _ ht, inter_eq_right.2 ht⟩ protected lemma Shatters.nonempty (h : 𝒜.Shatters s) : 𝒜.Nonempty := let ⟹t, ht, _⟩ := h Subset.rfl; ⟹t, ht⟩ @[simp] lemma shatters_empty : 𝒜.Shatters ∅ ↔ 𝒜.Nonempty := ⟹Shatters.nonempty, fun ⟹s, hs⟩ t ht ↩ ⟹s, hs, by rwa [empty_inter, eq_comm, ← subset_empty]⟩⟩ protected lemma Shatters.subset_iff (h : 𝒜.Shatters s) : t ⊆ s ↔ ∃ u ∈ 𝒜, s ∩ u = t := ⟹fun ht ↩ h ht, by rintro ⟹u, _, rfl⟩; exact inter_subset_left⟩ lemma shatters_iff : 𝒜.Shatters s ↔ 𝒜.image (fun t ↩ s ∩ t) = s.powerset := ⟹fun h ↩ by ext t; rw [mem_image, mem_powerset, h.subset_iff], fun h t ht ↩ by rwa [← mem_powerset, ← h, mem_image] at ht⟩ lemma univ_shatters [Fintype α] : univ.Shatters s := shatters_of_forall_subset fun _ _ ↩ mem_univ _
@[simp] lemma shatters_univ [Fintype α] : 𝒜.Shatters univ ↔ 𝒜 = univ := by rw [shatters_iff, powerset_univ]; simp_rw [univ_inter, image_id']
Mathlib/Combinatorics/SetFamily/Shatter.lean
71
72
/- 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 -/ import Batteries.Data.Nat.Gcd import Mathlib.Algebra.Group.Nat.Units import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Algebra.GroupWithZero.Nat /-! # Properties of `Nat.gcd`, `Nat.lcm`, and `Nat.Coprime` Definitions are provided in batteries. Generalizations of these are provided in a later file as `GCDMonoid.gcd` and `GCDMonoid.lcm`. Note that the global `IsCoprime` is not a straightforward generalization of `Nat.Coprime`, see `Nat.isCoprime_iff_coprime` for the connection between the two. Most of this file could be moved to batteries as well. -/ assert_not_exists OrderedCommMonoid namespace Nat variable {a a₁ a₂ b b₁ b₂ c : ℕ} /-! ### `gcd` -/ theorem gcd_greatest {a b d : ℕ} (hda : d ∣ a) (hdb : d ∣ b) (hd : ∀ e : ℕ, e ∣ a → e ∣ b → e ∣ d) : d = a.gcd b := (dvd_antisymm (hd _ (gcd_dvd_left a b) (gcd_dvd_right a b)) (dvd_gcd hda hdb)).symm /-! Lemmas where one argument consists of addition of a multiple of the other -/ @[simp] theorem pow_sub_one_mod_pow_sub_one (a b c : ℕ) : (a ^ c - 1) % (a ^ b - 1) = a ^ (c % b) - 1 := by rcases eq_zero_or_pos a with rfl | ha0 · simp [zero_pow_eq]; split_ifs <;> simp rcases Nat.eq_or_lt_of_le ha0 with rfl | ha1 · simp rcases eq_zero_or_pos b with rfl | hb0 · simp rcases lt_or_le c b with h | h · rw [mod_eq_of_lt, mod_eq_of_lt h] rwa [Nat.sub_lt_sub_iff_right (one_le_pow c a ha0), Nat.pow_lt_pow_iff_right ha1] · suffices a ^ (c - b + b) - 1 = a ^ (c - b) * (a ^ b - 1) + (a ^ (c - b) - 1) by rw [← Nat.sub_add_cancel h, add_mod_right, this, add_mod, mul_mod, mod_self, mul_zero, zero_mod, zero_add, mod_mod, pow_sub_one_mod_pow_sub_one] rw [← Nat.add_sub_assoc (one_le_pow (c - b) a ha0), ← mul_add_one, pow_add, Nat.sub_add_cancel (one_le_pow b a ha0)] @[simp] theorem pow_sub_one_gcd_pow_sub_one (a b c : ℕ) : gcd (a ^ b - 1) (a ^ c - 1) = a ^ gcd b c - 1 := by rcases eq_zero_or_pos b with rfl | hb · simp replace hb : c % b < b := mod_lt c hb rw [gcd_rec, pow_sub_one_mod_pow_sub_one, pow_sub_one_gcd_pow_sub_one, ← gcd_rec] /-! ### `lcm` -/ theorem lcm_dvd_mul (m n : ℕ) : lcm m n ∣ m * n := lcm_dvd (dvd_mul_right _ _) (dvd_mul_left _ _) theorem lcm_dvd_iff {m n k : ℕ} : lcm m n ∣ k ↔ m ∣ k ∧ n ∣ k := ⟹fun h => ⟹(dvd_lcm_left _ _).trans h, (dvd_lcm_right _ _).trans h⟩, and_imp.2 lcm_dvd⟩ theorem lcm_pos {m n : ℕ} : 0 < m → 0 < n → 0 < m.lcm n := by simp_rw [Nat.pos_iff_ne_zero] exact lcm_ne_zero theorem lcm_mul_left {m n k : ℕ} : (m * n).lcm (m * k) = m * n.lcm k := by apply dvd_antisymm · exact lcm_dvd (mul_dvd_mul_left m (dvd_lcm_left n k)) (mul_dvd_mul_left m (dvd_lcm_right n k)) · have h : m ∣ lcm (m * n) (m * k) := (dvd_mul_right m n).trans (dvd_lcm_left (m * n) (m * k)) rw [← dvd_div_iff_mul_dvd h, lcm_dvd_iff, dvd_div_iff_mul_dvd h, dvd_div_iff_mul_dvd h, ← lcm_dvd_iff] theorem lcm_mul_right {m n k : ℕ} : (m * n).lcm (k * n) = m.lcm k * n := by rw [mul_comm, mul_comm k n, lcm_mul_left, mul_comm] /-! ### `Coprime` See also `Nat.coprime_of_dvd` and `Nat.coprime_of_dvd'` to prove `Nat.Coprime m n`. -/ theorem Coprime.lcm_eq_mul {m n : ℕ} (h : Coprime m n) : lcm m n = m * n := by rw [← one_mul (lcm m n), ← h.gcd_eq_one, gcd_mul_lcm] theorem Coprime.symmetric : Symmetric Coprime := fun _ _ => Coprime.symm theorem Coprime.dvd_mul_right {m n k : ℕ} (H : Coprime k n) : k ∣ m * n ↔ k ∣ m := ⟹H.dvd_of_dvd_mul_right, fun h => dvd_mul_of_dvd_left h n⟩ theorem Coprime.dvd_mul_left {m n k : ℕ} (H : Coprime k m) : k ∣ m * n ↔ k ∣ n := ⟹H.dvd_of_dvd_mul_left, fun h => dvd_mul_of_dvd_right h m⟩ @[simp] theorem coprime_add_self_right {m n : ℕ} : Coprime m (n + m) ↔ Coprime m n := by rw [Coprime, Coprime, gcd_add_self_right] @[simp] theorem coprime_self_add_right {m n : ℕ} : Coprime m (m + n) ↔ Coprime m n := by rw [add_comm, coprime_add_self_right] @[simp] theorem coprime_add_self_left {m n : ℕ} : Coprime (m + n) n ↔ Coprime m n := by rw [Coprime, Coprime, gcd_add_self_left] @[simp] theorem coprime_self_add_left {m n : ℕ} : Coprime (m + n) m ↔ Coprime n m := by rw [Coprime, Coprime, gcd_self_add_left] @[simp] theorem coprime_add_mul_right_right (m n k : ℕ) : Coprime m (n + k * m) ↔ Coprime m n := by rw [Coprime, Coprime, gcd_add_mul_right_right] @[simp] theorem coprime_add_mul_left_right (m n k : ℕ) : Coprime m (n + m * k) ↔ Coprime m n := by rw [Coprime, Coprime, gcd_add_mul_left_right] @[simp] theorem coprime_mul_right_add_right (m n k : ℕ) : Coprime m (k * m + n) ↔ Coprime m n := by rw [Coprime, Coprime, gcd_mul_right_add_right] @[simp] theorem coprime_mul_left_add_right (m n k : ℕ) : Coprime m (m * k + n) ↔ Coprime m n := by rw [Coprime, Coprime, gcd_mul_left_add_right] @[simp] theorem coprime_add_mul_right_left (m n k : ℕ) : Coprime (m + k * n) n ↔ Coprime m n := by rw [Coprime, Coprime, gcd_add_mul_right_left] @[simp] theorem coprime_add_mul_left_left (m n k : ℕ) : Coprime (m + n * k) n ↔ Coprime m n := by
rw [Coprime, Coprime, gcd_add_mul_left_left]
Mathlib/Data/Nat/GCD/Basic.lean
140
141
/- Copyright (c) 2022 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Patrick Massot, Yury Kudryashov, Kevin H. Wilson, Heather Macbeth -/ import Mathlib.Order.Filter.Tendsto /-! # Product and coproduct filters In this file we define `Filter.prod f g` (notation: `f ×ˢ g`) and `Filter.coprod f g`. The product of two filters is the largest filter `l` such that `Filter.Tendsto Prod.fst l f` and `Filter.Tendsto Prod.snd l g`. ## Implementation details The product filter cannot be defined using the monad structure on filters. For example: ```lean F := do {x ← seq, y ← top, return (x, y)} G := do {y ← top, x ← seq, return (x, y)} ``` hence: ```lean s ∈ F ↔ ∃ n, [n..∞] × univ ⊆ s s ∈ G ↔ ∀ i:ℕ, ∃ n, [n..∞] × {i} ⊆ s ``` Now `⋃ i, [i..∞] × {i}` is in `G` but not in `F`. As product filter we want to have `F` as result. ## Notations * `f ×ˢ g` : `Filter.prod f g`, localized in `Filter`. -/ open Set open Filter namespace Filter variable {α β γ ÎŽ : Type*} {ι : Sort*} section Prod variable {s : Set α} {t : Set β} {f : Filter α} {g : Filter β} theorem prod_mem_prod (hs : s ∈ f) (ht : t ∈ g) : s ×ˢ t ∈ f ×ˢ g := inter_mem_inf (preimage_mem_comap hs) (preimage_mem_comap ht) theorem mem_prod_iff {s : Set (α × β)} {f : Filter α} {g : Filter β} : s ∈ f ×ˢ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ ×ˢ t₂ ⊆ s := by constructor · rintro ⟹t₁, ⟹s₁, hs₁, hts₁⟩, t₂, ⟹s₂, hs₂, hts₂⟩, rfl⟩ exact ⟹s₁, hs₁, s₂, hs₂, fun p ⟹h, h'⟩ => ⟹hts₁ h, hts₂ h'⟩⟩ · rintro ⟹t₁, ht₁, t₂, ht₂, h⟩ exact mem_inf_of_inter (preimage_mem_comap ht₁) (preimage_mem_comap ht₂) h @[simp] theorem compl_diagonal_mem_prod {l₁ l₂ : Filter α} : (diagonal α)ᶜ ∈ l₁ ×ˢ l₂ ↔ Disjoint l₁ l₂ := by simp only [mem_prod_iff, Filter.disjoint_iff, prod_subset_compl_diagonal_iff_disjoint] @[simp] theorem prod_mem_prod_iff [f.NeBot] [g.NeBot] : s ×ˢ t ∈ f ×ˢ g ↔ s ∈ f ∧ t ∈ g := ⟹fun h => let ⟹_s', hs', _t', ht', H⟩ := mem_prod_iff.1 h (prod_subset_prod_iff.1 H).elim (fun ⟹hs's, ht't⟩ => ⟹mem_of_superset hs' hs's, mem_of_superset ht' ht't⟩) fun h => h.elim (fun hs'e => absurd hs'e (nonempty_of_mem hs').ne_empty) fun ht'e => absurd ht'e (nonempty_of_mem ht').ne_empty, fun h => prod_mem_prod h.1 h.2⟩ theorem mem_prod_principal {s : Set (α × β)} : s ∈ f ×ˢ 𝓟 t ↔ { a | ∀ b ∈ t, (a, b) ∈ s } ∈ f := by rw [← @exists_mem_subset_iff _ f, mem_prod_iff] refine exists_congr fun u => Iff.rfl.and ⟹?_, fun h => ⟹t, mem_principal_self t, ?_⟩⟩ · rintro ⟹v, v_in, hv⟩ a a_in b b_in exact hv (mk_mem_prod a_in <| v_in b_in) · rintro ⟹x, y⟩ ⟹hx, hy⟩ exact h hx y hy theorem mem_prod_top {s : Set (α × β)} : s ∈ f ×ˢ (⊀ : Filter β) ↔ { a | ∀ b, (a, b) ∈ s } ∈ f := by rw [← principal_univ, mem_prod_principal] simp only [mem_univ, forall_true_left] theorem eventually_prod_principal_iff {p : α × β → Prop} {s : Set β} : (∀ᶠ x : α × β in f ×ˢ 𝓟 s, p x) ↔ ∀ᶠ x : α in f, ∀ y : β, y ∈ s → p (x, y) := by rw [eventually_iff, eventually_iff, mem_prod_principal] simp only [mem_setOf_eq] theorem comap_prod (f : α → β × γ) (b : Filter β) (c : Filter γ) : comap f (b ×ˢ c) = comap (Prod.fst ∘ f) b ⊓ comap (Prod.snd ∘ f) c := by rw [prod_eq_inf, comap_inf, Filter.comap_comap, Filter.comap_comap] theorem comap_prodMap_prod (f : α → β) (g : γ → ÎŽ) (lb : Filter β) (ld : Filter ÎŽ) : comap (Prod.map f g) (lb ×ˢ ld) = comap f lb ×ˢ comap g ld := by simp [prod_eq_inf, comap_comap, Function.comp_def] theorem prod_top : f ×ˢ (⊀ : Filter β) = f.comap Prod.fst := by rw [prod_eq_inf, comap_top, inf_top_eq] theorem top_prod : (⊀ : Filter α) ×ˢ g = g.comap Prod.snd := by rw [prod_eq_inf, comap_top, top_inf_eq] theorem sup_prod (f₁ f₂ : Filter α) (g : Filter β) : (f₁ ⊔ f₂) ×ˢ g = (f₁ ×ˢ g) ⊔ (f₂ ×ˢ g) := by simp only [prod_eq_inf, comap_sup, inf_sup_right] theorem prod_sup (f : Filter α) (g₁ g₂ : Filter β) : f ×ˢ (g₁ ⊔ g₂) = (f ×ˢ g₁) ⊔ (f ×ˢ g₂) := by simp only [prod_eq_inf, comap_sup, inf_sup_left] theorem eventually_prod_iff {p : α × β → Prop} : (∀ᶠ x in f ×ˢ g, p x) ↔ ∃ pa : α → Prop, (∀ᶠ x in f, pa x) ∧ ∃ pb : β → Prop, (∀ᶠ y in g, pb y) ∧ ∀ {x}, pa x → ∀ {y}, pb y → p (x, y) := by simpa only [Set.prod_subset_iff] using @mem_prod_iff α β p f g theorem tendsto_fst : Tendsto Prod.fst (f ×ˢ g) f := tendsto_inf_left tendsto_comap theorem tendsto_snd : Tendsto Prod.snd (f ×ˢ g) g := tendsto_inf_right tendsto_comap /-- If a function tends to a product `g ×ˢ h` of filters, then its first component tends to `g`. See also `Filter.Tendsto.fst_nhds` for the special case of converging to a point in a product of two topological spaces. -/ theorem Tendsto.fst {h : Filter γ} {m : α → β × γ} (H : Tendsto m f (g ×ˢ h)) : Tendsto (fun a ↩ (m a).1) f g := tendsto_fst.comp H /-- If a function tends to a product `g ×ˢ h` of filters, then its second component tends to `h`. See also `Filter.Tendsto.snd_nhds` for the special case of converging to a point in a product of two topological spaces. -/ theorem Tendsto.snd {h : Filter γ} {m : α → β × γ} (H : Tendsto m f (g ×ˢ h)) : Tendsto (fun a ↩ (m a).2) f h := tendsto_snd.comp H theorem Tendsto.prodMk {h : Filter γ} {m₁ : α → β} {m₂ : α → γ} (h₁ : Tendsto m₁ f g) (h₂ : Tendsto m₂ f h) : Tendsto (fun x => (m₁ x, m₂ x)) f (g ×ˢ h) := tendsto_inf.2 ⟹tendsto_comap_iff.2 h₁, tendsto_comap_iff.2 h₂⟩ @[deprecated (since := "2025-03-10")] alias Tendsto.prod_mk := Tendsto.prodMk theorem tendsto_prod_swap : Tendsto (Prod.swap : α × β → β × α) (f ×ˢ g) (g ×ˢ f) := tendsto_snd.prodMk tendsto_fst theorem Eventually.prod_inl {la : Filter α} {p : α → Prop} (h : ∀ᶠ x in la, p x) (lb : Filter β) : ∀ᶠ x in la ×ˢ lb, p (x : α × β).1 := tendsto_fst.eventually h theorem Eventually.prod_inr {lb : Filter β} {p : β → Prop} (h : ∀ᶠ x in lb, p x) (la : Filter α) : ∀ᶠ x in la ×ˢ lb, p (x : α × β).2 := tendsto_snd.eventually h theorem Eventually.prod_mk {la : Filter α} {pa : α → Prop} (ha : ∀ᶠ x in la, pa x) {lb : Filter β} {pb : β → Prop} (hb : ∀ᶠ y in lb, pb y) : ∀ᶠ p in la ×ˢ lb, pa (p : α × β).1 ∧ pb p.2 := (ha.prod_inl lb).and (hb.prod_inr la) theorem EventuallyEq.prodMap {ÎŽ} {la : Filter α} {fa ga : α → γ} (ha : fa =á¶ [la] ga) {lb : Filter β} {fb gb : β → ÎŽ} (hb : fb =á¶ [lb] gb) : Prod.map fa fb =á¶ [la ×ˢ lb] Prod.map ga gb := (Eventually.prod_mk ha hb).mono fun _ h => Prod.ext h.1 h.2 @[deprecated (since := "2025-03-10")] alias EventuallyEq.prod_map := EventuallyEq.prodMap theorem EventuallyLE.prodMap {ÎŽ} [LE γ] [LE ÎŽ] {la : Filter α} {fa ga : α → γ} (ha : fa ≀ᶠ[la] ga) {lb : Filter β} {fb gb : β → ÎŽ} (hb : fb ≀ᶠ[lb] gb) : Prod.map fa fb ≀ᶠ[la ×ˢ lb] Prod.map ga gb := Eventually.prod_mk ha hb @[deprecated (since := "2025-03-10")] alias EventuallyLE.prod_map := EventuallyLE.prodMap theorem Eventually.curry {la : Filter α} {lb : Filter β} {p : α × β → Prop} (h : ∀ᶠ x in la ×ˢ lb, p x) : ∀ᶠ x in la, ∀ᶠ y in lb, p (x, y) := by rcases eventually_prod_iff.1 h with ⟹pa, ha, pb, hb, h⟩ exact ha.mono fun a ha => hb.mono fun b hb => h ha hb protected lemma Frequently.uncurry {la : Filter α} {lb : Filter β} {p : α → β → Prop} (h : ∃ᶠ x in la, ∃ᶠ y in lb, p x y) : ∃ᶠ xy in la ×ˢ lb, p xy.1 xy.2 := mt (fun h ↩ by simpa only [not_frequently] using h.curry) h lemma Frequently.of_curry {la : Filter α} {lb : Filter β} {p : α × β → Prop} (h : ∃ᶠ x in la, ∃ᶠ y in lb, p (x, y)) : ∃ᶠ xy in la ×ˢ lb, p xy := h.uncurry /-- A fact that is eventually true about all pairs `l ×ˢ l` is eventually true about all diagonal pairs `(i, i)` -/ theorem Eventually.diag_of_prod {p : α × α → Prop} (h : ∀ᶠ i in f ×ˢ f, p i) : ∀ᶠ i in f, p (i, i) := by obtain ⟹t, ht, s, hs, hst⟩ := eventually_prod_iff.1 h apply (ht.and hs).mono fun x hx => hst hx.1 hx.2 theorem Eventually.diag_of_prod_left {f : Filter α} {g : Filter γ} {p : (α × α) × γ → Prop} : (∀ᶠ x in (f ×ˢ f) ×ˢ g, p x) → ∀ᶠ x : α × γ in f ×ˢ g, p ((x.1, x.1), x.2) := by intro h obtain ⟹t, ht, s, hs, hst⟩ := eventually_prod_iff.1 h exact (ht.diag_of_prod.prod_mk hs).mono fun x hx => by simp only [hst hx.1 hx.2] theorem Eventually.diag_of_prod_right {f : Filter α} {g : Filter γ} {p : α × γ × γ → Prop} : (∀ᶠ x in f ×ˢ (g ×ˢ g), p x) → ∀ᶠ x : α × γ in f ×ˢ g, p (x.1, x.2, x.2) := by intro h obtain ⟹t, ht, s, hs, hst⟩ := eventually_prod_iff.1 h exact (ht.prod_mk hs.diag_of_prod).mono fun x hx => by simp only [hst hx.1 hx.2] theorem tendsto_diag : Tendsto (fun i => (i, i)) f (f ×ˢ f) := tendsto_iff_eventually.mpr fun _ hpr => hpr.diag_of_prod theorem prod_iInf_left [Nonempty ι] {f : ι → Filter α} {g : Filter β} : (⹅ i, f i) ×ˢ g = ⹅ i, f i ×ˢ g := by simp only [prod_eq_inf, comap_iInf, iInf_inf] theorem prod_iInf_right [Nonempty ι] {f : Filter α} {g : ι → Filter β} : (f ×ˢ ⹅ i, g i) = ⹅ i, f ×ˢ g i := by simp only [prod_eq_inf, comap_iInf, inf_iInf] @[mono, gcongr] theorem prod_mono {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} (hf : f₁ ≀ f₂) (hg : g₁ ≀ g₂) : f₁ ×ˢ g₁ ≀ f₂ ×ˢ g₂ := inf_le_inf (comap_mono hf) (comap_mono hg) @[gcongr] theorem prod_mono_left (g : Filter β) {f₁ f₂ : Filter α} (hf : f₁ ≀ f₂) : f₁ ×ˢ g ≀ f₂ ×ˢ g := Filter.prod_mono hf rfl.le @[gcongr] theorem prod_mono_right (f : Filter α) {g₁ g₂ : Filter β} (hf : g₁ ≀ g₂) : f ×ˢ g₁ ≀ f ×ˢ g₂ := Filter.prod_mono rfl.le hf theorem prod_comap_comap_eq.{u, v, w, x} {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x} {f₁ : Filter α₁} {f₂ : Filter α₂} {m₁ : β₁ → α₁} {m₂ : β₂ → α₂} : comap m₁ f₁ ×ˢ comap m₂ f₂ = comap (fun p : β₁ × β₂ => (m₁ p.1, m₂ p.2)) (f₁ ×ˢ f₂) := by simp only [prod_eq_inf, comap_comap, comap_inf, Function.comp_def] theorem prod_comm' : f ×ˢ g = comap Prod.swap (g ×ˢ f) := by simp only [prod_eq_inf, comap_comap, Function.comp_def, inf_comm, Prod.swap, comap_inf] theorem prod_comm : f ×ˢ g = map (fun p : β × α => (p.2, p.1)) (g ×ˢ f) := by rw [prod_comm', ← map_swap_eq_comap_swap] rfl theorem mem_prod_iff_left {s : Set (α × β)} : s ∈ f ×ˢ g ↔ ∃ t ∈ f, ∀ᶠ y in g, ∀ x ∈ t, (x, y) ∈ s := by simp only [mem_prod_iff, prod_subset_iff] refine exists_congr fun _ => Iff.rfl.and <| Iff.trans ?_ exists_mem_subset_iff exact exists_congr fun _ => Iff.rfl.and forall₂_swap theorem mem_prod_iff_right {s : Set (α × β)} : s ∈ f ×ˢ g ↔ ∃ t ∈ g, ∀ᶠ x in f, ∀ y ∈ t, (x, y) ∈ s := by rw [prod_comm, mem_map, mem_prod_iff_left]; rfl @[simp] theorem map_fst_prod (f : Filter α) (g : Filter β) [NeBot g] : map Prod.fst (f ×ˢ g) = f := by ext s simp only [mem_map, mem_prod_iff_left, mem_preimage, eventually_const, ← subset_def, exists_mem_subset_iff] @[simp] theorem map_snd_prod (f : Filter α) (g : Filter β) [NeBot f] : map Prod.snd (f ×ˢ g) = g := by rw [prod_comm, map_map]; apply map_fst_prod @[simp] theorem prod_le_prod {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} [NeBot f₁] [NeBot g₁] : f₁ ×ˢ g₁ ≀ f₂ ×ˢ g₂ ↔ f₁ ≀ f₂ ∧ g₁ ≀ g₂ := ⟹fun h => ⟹map_fst_prod f₁ g₁ ▾ tendsto_fst.mono_left h, map_snd_prod f₁ g₁ ▾ tendsto_snd.mono_left h⟩, fun h => prod_mono h.1 h.2⟩ @[simp] theorem prod_inj {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} [NeBot f₁] [NeBot g₁] : f₁ ×ˢ g₁ = f₂ ×ˢ g₂ ↔ f₁ = f₂ ∧ g₁ = g₂ := by refine ⟹fun h => ?_, fun h => h.1 ▾ h.2 ▾ rfl⟩ have hle : f₁ ≀ f₂ ∧ g₁ ≀ g₂ := prod_le_prod.1 h.le haveI := neBot_of_le hle.1; haveI := neBot_of_le hle.2 exact ⟹hle.1.antisymm <| (prod_le_prod.1 h.ge).1, hle.2.antisymm <| (prod_le_prod.1 h.ge).2⟩ theorem eventually_swap_iff {p : α × β → Prop} : (∀ᶠ x : α × β in f ×ˢ g, p x) ↔ ∀ᶠ y : β × α in g ×ˢ f, p y.swap := by rw [prod_comm]; rfl theorem prod_assoc (f : Filter α) (g : Filter β) (h : Filter γ) : map (Equiv.prodAssoc α β γ) ((f ×ˢ g) ×ˢ h) = f ×ˢ (g ×ˢ h) := by simp_rw [← comap_equiv_symm, prod_eq_inf, comap_inf, comap_comap, inf_assoc, Function.comp_def, Equiv.prodAssoc_symm_apply] theorem prod_assoc_symm (f : Filter α) (g : Filter β) (h : Filter γ) : map (Equiv.prodAssoc α β γ).symm (f ×ˢ (g ×ˢ h)) = (f ×ˢ g) ×ˢ h := by simp_rw [map_equiv_symm, prod_eq_inf, comap_inf, comap_comap, inf_assoc, Function.comp_def, Equiv.prodAssoc_apply] theorem tendsto_prodAssoc {h : Filter γ} : Tendsto (Equiv.prodAssoc α β γ) ((f ×ˢ g) ×ˢ h) (f ×ˢ (g ×ˢ h)) := (prod_assoc f g h).le theorem tendsto_prodAssoc_symm {h : Filter γ} : Tendsto (Equiv.prodAssoc α β γ).symm (f ×ˢ (g ×ˢ h)) ((f ×ˢ g) ×ˢ h) := (prod_assoc_symm f g h).le /-- A useful lemma when dealing with uniformities. -/ theorem map_swap4_prod {h : Filter γ} {k : Filter ÎŽ} : map (fun p : (α × β) × γ × ÎŽ => ((p.1.1, p.2.1), (p.1.2, p.2.2))) ((f ×ˢ g) ×ˢ (h ×ˢ k)) = (f ×ˢ h) ×ˢ (g ×ˢ k) := by simp_rw [map_swap4_eq_comap, prod_eq_inf, comap_inf, comap_comap]; ac_rfl theorem tendsto_swap4_prod {h : Filter γ} {k : Filter ÎŽ} : Tendsto (fun p : (α × β) × γ × ÎŽ => ((p.1.1, p.2.1), (p.1.2, p.2.2))) ((f ×ˢ g) ×ˢ (h ×ˢ k)) ((f ×ˢ h) ×ˢ (g ×ˢ k)) := map_swap4_prod.le theorem prod_map_map_eq.{u, v, w, x} {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x} {f₁ : Filter α₁} {f₂ : Filter α₂} {m₁ : α₁ → β₁} {m₂ : α₂ → β₂} : map m₁ f₁ ×ˢ map m₂ f₂ = map (fun p : α₁ × α₂ => (m₁ p.1, m₂ p.2)) (f₁ ×ˢ f₂) := le_antisymm (fun s hs => let ⟹s₁, hs₁, s₂, hs₂, h⟩ := mem_prod_iff.mp hs mem_of_superset (prod_mem_prod (image_mem_map hs₁) (image_mem_map hs₂)) <| by rwa [prod_image_image_eq, image_subset_iff]) ((tendsto_map.comp tendsto_fst).prodMk (tendsto_map.comp tendsto_snd)) theorem prod_map_map_eq' {α₁ : Type*} {α₂ : Type*} {β₁ : Type*} {β₂ : Type*} (f : α₁ → α₂) (g : β₁ → β₂) (F : Filter α₁) (G : Filter β₁) : map f F ×ˢ map g G = map (Prod.map f g) (F ×ˢ G) := prod_map_map_eq theorem prod_map_left (f : α → β) (F : Filter α) (G : Filter γ) : map f F ×ˢ G = map (Prod.map f id) (F ×ˢ G) := by rw [← prod_map_map_eq', map_id] theorem prod_map_right (f : β → γ) (F : Filter α) (G : Filter β) : F ×ˢ map f G = map (Prod.map id f) (F ×ˢ G) := by rw [← prod_map_map_eq', map_id] theorem le_prod_map_fst_snd {f : Filter (α × β)} : f ≀ map Prod.fst f ×ˢ map Prod.snd f := le_inf le_comap_map le_comap_map theorem Tendsto.prodMap {ÎŽ : Type*} {f : α → γ} {g : β → ÎŽ} {a : Filter α} {b : Filter β} {c : Filter γ} {d : Filter ÎŽ} (hf : Tendsto f a c) (hg : Tendsto g b d) : Tendsto (Prod.map f g) (a ×ˢ b) (c ×ˢ d) := by rw [Tendsto, Prod.map_def, ← prod_map_map_eq] exact Filter.prod_mono hf hg @[deprecated (since := "2025-03-10")] alias Tendsto.prod_map := Tendsto.prodMap protected theorem map_prod (m : α × β → γ) (f : Filter α) (g : Filter β) : map m (f ×ˢ g) = (f.map fun a b => m (a, b)).seq g := by simp only [Filter.ext_iff, mem_map, mem_prod_iff, mem_map_seq_iff, exists_and_left] intro s constructor · exact fun ⟹t, ht, s, hs, h⟩ => ⟹s, hs, t, ht, fun x hx y hy => @h ⟹x, y⟩ ⟹hx, hy⟩⟩ · exact fun ⟹s, hs, t, ht, h⟩ => ⟹t, ht, s, hs, fun ⟹x, y⟩ ⟹hx, hy⟩ => h x hx y hy⟩ theorem prod_eq : f ×ˢ g = (f.map Prod.mk).seq g := f.map_prod id g theorem prod_inf_prod {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} : (f₁ ×ˢ g₁) ⊓ (f₂ ×ˢ g₂) = (f₁ ⊓ f₂) ×ˢ (g₁ ⊓ g₂) := by simp only [prod_eq_inf, comap_inf, inf_comm, inf_assoc, inf_left_comm] theorem inf_prod {f₁ f₂ : Filter α} : (f₁ ⊓ f₂) ×ˢ g = (f₁ ×ˢ g) ⊓ (f₂ ×ˢ g) := by rw [prod_inf_prod, inf_idem] theorem prod_inf {g₁ g₂ : Filter β} : f ×ˢ (g₁ ⊓ g₂) = (f ×ˢ g₁) ⊓ (f ×ˢ g₂) := by rw [prod_inf_prod, inf_idem] @[simp] theorem prod_principal_principal {s : Set α} {t : Set β} : 𝓟 s ×ˢ 𝓟 t = 𝓟 (s ×ˢ t) := by simp only [prod_eq_inf, comap_principal, principal_eq_iff_eq, comap_principal, inf_principal]; rfl @[simp] theorem pure_prod {a : α} {f : Filter β} : pure a ×ˢ f = map (Prod.mk a) f := by rw [prod_eq, map_pure, pure_seq_eq_map] theorem map_pure_prod (f : α → β → γ) (a : α) (B : Filter β) : map (Function.uncurry f) (pure a ×ˢ B) = map (f a) B := by rw [Filter.pure_prod]; rfl @[simp] theorem prod_pure {b : β} : f ×ˢ pure b = map (fun a => (a, b)) f := by rw [prod_eq, seq_pure, map_map]; rfl theorem prod_pure_pure {a : α} {b : β} : (pure a : Filter α) ×ˢ (pure b : Filter β) = pure (a, b) := by simp @[simp] theorem prod_eq_bot : f ×ˢ g = ⊥ ↔ f = ⊥ √ g = ⊥ := by simp_rw [← empty_mem_iff_bot, mem_prod_iff, subset_empty_iff, prod_eq_empty_iff, ← exists_prop, Subtype.exists', exists_or, exists_const, Subtype.exists, exists_prop, exists_eq_right] @[simp] theorem prod_bot : f ×ˢ (⊥ : Filter β) = ⊥ := prod_eq_bot.2 <| Or.inr rfl @[simp] theorem bot_prod : (⊥ : Filter α) ×ˢ g = ⊥ := prod_eq_bot.2 <| Or.inl rfl theorem prod_neBot : NeBot (f ×ˢ g) ↔ NeBot f ∧ NeBot g := by simp only [neBot_iff, Ne, prod_eq_bot, not_or] protected theorem NeBot.prod (hf : NeBot f) (hg : NeBot g) : NeBot (f ×ˢ g) := prod_neBot.2 ⟹hf, hg⟩ instance prod.instNeBot [hf : NeBot f] [hg : NeBot g] : NeBot (f ×ˢ g) := hf.prod hg @[simp] lemma disjoint_prod {f' : Filter α} {g' : Filter β} : Disjoint (f ×ˢ g) (f' ×ˢ g') ↔ Disjoint f f' √ Disjoint g g' := by simp only [disjoint_iff, prod_inf_prod, prod_eq_bot] /-- `p ∧ q` occurs frequently along the product of two filters iff both `p` and `q` occur frequently along the corresponding filters. -/ theorem frequently_prod_and {p : α → Prop} {q : β → Prop} : (∃ᶠ x in f ×ˢ g, p x.1 ∧ q x.2) ↔ (∃ᶠ a in f, p a) ∧ ∃ᶠ b in g, q b := by simp only [frequently_iff_neBot, ← prod_neBot, ← prod_inf_prod, prod_principal_principal] rfl theorem tendsto_prod_iff {f : α × β → γ} {x : Filter α} {y : Filter β} {z : Filter γ} : Tendsto f (x ×ˢ y) z ↔ ∀ W ∈ z, ∃ U ∈ x, ∃ V ∈ y, ∀ x y, x ∈ U → y ∈ V → f (x, y) ∈ W := by simp only [tendsto_def, mem_prod_iff, prod_sub_preimage_iff, exists_prop] theorem tendsto_prod_iff' {g' : Filter γ} {s : α → β × γ} : Tendsto s f (g ×ˢ g') ↔ Tendsto (fun n => (s n).1) f g ∧ Tendsto (fun n => (s n).2) f g' := by simp only [prod_eq_inf, tendsto_inf, tendsto_comap_iff, Function.comp_def] theorem le_prod {f : Filter (α × β)} {g : Filter α} {g' : Filter β} : (f ≀ g ×ˢ g') ↔ Tendsto Prod.fst f g ∧ Tendsto Prod.snd f g' := tendsto_prod_iff' end Prod /-! ### Coproducts of filters -/ section Coprod variable {f : Filter α} {g : Filter β} theorem coprod_eq_prod_top_sup_top_prod (f : Filter α) (g : Filter β) : Filter.coprod f g = f ×ˢ ⊀ ⊔ ⊀ ×ˢ g := by rw [prod_top, top_prod] rfl theorem mem_coprod_iff {s : Set (α × β)} {f : Filter α} {g : Filter β} : s ∈ f.coprod g ↔ (∃ t₁ ∈ f, Prod.fst ⁻¹' t₁ ⊆ s) ∧ ∃ t₂ ∈ g, Prod.snd ⁻¹' t₂ ⊆ s := by simp [Filter.coprod] @[simp] theorem bot_coprod (l : Filter β) : (⊥ : Filter α).coprod l = comap Prod.snd l := by simp [Filter.coprod] @[simp] theorem coprod_bot (l : Filter α) : l.coprod (⊥ : Filter β) = comap Prod.fst l := by simp [Filter.coprod] theorem bot_coprod_bot : (⊥ : Filter α).coprod (⊥ : Filter β) = ⊥ := by simp theorem compl_mem_coprod {s : Set (α × β)} {la : Filter α} {lb : Filter β} : sᶜ ∈ la.coprod lb ↔ (Prod.fst '' s)ᶜ ∈ la ∧ (Prod.snd '' s)ᶜ ∈ lb := by simp only [Filter.coprod, mem_sup, compl_mem_comap] @[mono] theorem coprod_mono {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} (hf : f₁ ≀ f₂) (hg : g₁ ≀ g₂) : f₁.coprod g₁ ≀ f₂.coprod g₂ := sup_le_sup (comap_mono hf) (comap_mono hg) theorem coprod_neBot_iff : (f.coprod g).NeBot ↔ f.NeBot ∧ Nonempty β √ Nonempty α ∧ g.NeBot := by simp [Filter.coprod] @[instance] theorem coprod_neBot_left [NeBot f] [Nonempty β] : (f.coprod g).NeBot := coprod_neBot_iff.2 (Or.inl ⟚‹_›, ‹_›⟩) @[instance] theorem coprod_neBot_right [NeBot g] [Nonempty α] : (f.coprod g).NeBot := coprod_neBot_iff.2 (Or.inr ⟚‹_›, ‹_›⟩) theorem coprod_inf_prod_le (f₁ f₂ : Filter α) (g₁ g₂ : Filter β) : f₁.coprod g₁ ⊓ f₂ ×ˢ g₂ ≀ f₁ ×ˢ g₂ ⊔ f₂ ×ˢ g₁ := calc f₁.coprod g₁ ⊓ f₂ ×ˢ g₂ _ = (f₁ ×ˢ ⊀ ⊔ ⊀ ×ˢ g₁) ⊓ f₂ ×ˢ g₂ := by rw [coprod_eq_prod_top_sup_top_prod] _ = f₁ ×ˢ ⊀ ⊓ f₂ ×ˢ g₂ ⊔ ⊀ ×ˢ g₁ ⊓ f₂ ×ˢ g₂ := inf_sup_right _ _ _ _ = (f₁ ⊓ f₂) ×ˢ g₂ ⊔ f₂ ×ˢ (g₁ ⊓ g₂) := by simp [prod_inf_prod] _ ≀ f₁ ×ˢ g₂ ⊔ f₂ ×ˢ g₁ := sup_le_sup (prod_mono inf_le_left le_rfl) (prod_mono le_rfl inf_le_left) theorem principal_coprod_principal (s : Set α) (t : Set β) : (𝓟 s).coprod (𝓟 t) = 𝓟 (sᶜ ×ˢ tᶜ)ᶜ := by rw [Filter.coprod, comap_principal, comap_principal, sup_principal, Set.prod_eq, compl_inter, preimage_compl, preimage_compl, compl_compl, compl_compl] -- this inequality can be strict; see `map_const_principal_coprod_map_id_principal` and -- `map_prodMap_const_id_principal_coprod_principal` below. theorem map_prodMap_coprod_le.{u, v, w, x} {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x} {f₁ : Filter α₁} {f₂ : Filter α₂} {m₁ : α₁ → β₁} {m₂ : α₂ → β₂} : map (Prod.map m₁ m₂) (f₁.coprod f₂) ≀ (map m₁ f₁).coprod (map m₂ f₂) := by intro s simp only [mem_map, mem_coprod_iff] rintro ⟹⟹u₁, hu₁, h₁⟩, u₂, hu₂, h₂⟩ refine ⟹⟹m₁ ⁻¹' u₁, hu₁, fun _ hx => h₁ ?_⟩, ⟹m₂ ⁻¹' u₂, hu₂, fun _ hx => h₂ ?_⟩⟩ <;> convert hx @[deprecated (since := "2025-03-10")] alias map_prod_map_coprod_le := map_prodMap_coprod_le /-- Characterization of the coproduct of the `Filter.map`s of two principal filters `𝓟 {a}` and `𝓟 {i}`, the first under the constant function `fun a => b` and the second under the identity function. Together with the next lemma, `map_prodMap_const_id_principal_coprod_principal`, this provides an example showing that the inequality in the lemma `map_prodMap_coprod_le` can be strict. -/ theorem map_const_principal_coprod_map_id_principal {α β ι : Type*} (a : α) (b : β) (i : ι) : (map (fun _ => b) (𝓟 {a})).coprod (map id (𝓟 {i})) = 𝓟 ((({b} : Set β) ×ˢ univ) ∪ (univ ×ˢ ({i} : Set ι))) := by simp only [map_principal, Filter.coprod, comap_principal, sup_principal, image_singleton, image_id, prod_univ, univ_prod, id] /-- Characterization of the `Filter.map` of the coproduct of two principal filters `𝓟 {a}` and `𝓟 {i}`, under the `Prod.map` of two functions, respectively the constant function `fun a => b` and the identity function. Together with the previous lemma, `map_const_principal_coprod_map_id_principal`, this provides an example showing that the inequality in the lemma `map_prodMap_coprod_le` can be strict. -/ theorem map_prodMap_const_id_principal_coprod_principal {α β ι : Type*} (a : α) (b : β) (i : ι) : map (Prod.map (fun _ : α => b) id) ((𝓟 {a}).coprod (𝓟 {i})) = 𝓟 (({b} : Set β) ×ˢ (univ : Set ι)) := by rw [principal_coprod_principal, map_principal] congr ext ⟹b', i'⟩ constructor · rintro ⟹⟹a'', i''⟩, _, h₂, h₃⟩ simp · rintro ⟹h₁, _⟩ use (a, i') simpa using h₁.symm @[deprecated (since := "2025-03-10")] alias map_prod_map_const_id_principal_coprod_principal := map_prodMap_const_id_principal_coprod_principal theorem Tendsto.prodMap_coprod {ÎŽ : Type*} {f : α → γ} {g : β → ÎŽ} {a : Filter α} {b : Filter β} {c : Filter γ} {d : Filter ÎŽ} (hf : Tendsto f a c) (hg : Tendsto g b d) : Tendsto (Prod.map f g) (a.coprod b) (c.coprod d) :=
map_prodMap_coprod_le.trans (coprod_mono hf hg)
Mathlib/Order/Filter/Prod.lean
537
538