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 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 Batteries.Data.Rat.Lemmas import Mathlib.Algebra.Group.Defs import Mathlib.Data.Rat.Init import Mathlib.Order.Basic import Mathlib.Tactic.Common import Mathlib.Data.Int.Init import Mathlib.Data.Nat.Basic /-! # Basics for the Rational Numbers ## Summary We define the integral domain structure on `ℚ` and prove basic lemmas about it. The definition of the field structure on `ℚ` will be done in `Mathlib.Data.Rat.Basic` once the `Field` class has been defined. ## Main Definitions - `Rat.divInt n d` constructs a rational number `q = n / d` from `n d : ℤ`. ## Notations - `/.` is infix notation for `Rat.divInt`. -/ -- TODO: If `Inv` was defined earlier than `Algebra.Group.Defs`, we could have -- assert_not_exists Monoid assert_not_exists MonoidWithZero Lattice PNat Nat.gcd_greatest open Function namespace Rat variable {q : ℚ} theorem pos (a : ℚ) : 0 < a.den := Nat.pos_of_ne_zero a.den_nz lemma mk'_num_den (q : ℚ) : mk' q.num q.den q.den_nz q.reduced = q := rfl @[simp] theorem ofInt_eq_cast (n : ℤ) : ofInt n = Int.cast n := rfl -- TODO: Replace `Rat.ofNat_num`/`Rat.ofNat_den` in Batteries @[simp] lemma num_ofNat (n : ℕ) : num ofNat(n) = ofNat(n) := rfl @[simp] lemma den_ofNat (n : ℕ) : den ofNat(n) = 1 := rfl @[simp, norm_cast] lemma num_natCast (n : ℕ) : num n = n := rfl @[simp, norm_cast] lemma den_natCast (n : ℕ) : den n = 1 := rfl -- TODO: Replace `intCast_num`/`intCast_den` the names in Batteries @[simp, norm_cast] lemma num_intCast (n : ℤ) : (n : ℚ).num = n := rfl @[simp, norm_cast] lemma den_intCast (n : ℤ) : (n : ℚ).den = 1 := rfl lemma intCast_injective : Injective (Int.cast : ℤ → ℚ) := fun _ _ ↦ congr_arg num lemma natCast_injective : Injective (Nat.cast : ℕ → ℚ) := intCast_injective.comp fun _ _ ↦ Int.natCast_inj.1 @[simp high, norm_cast] lemma natCast_inj {m n : ℕ} : (m : ℚ) = n ↔ m = n := natCast_injective.eq_iff @[simp high, norm_cast] lemma intCast_eq_zero {n : ℤ} : (n : ℚ) = 0 ↔ n = 0 := intCast_inj @[simp high, norm_cast] lemma natCast_eq_zero {n : ℕ} : (n : ℚ) = 0 ↔ n = 0 := natCast_inj @[simp high, norm_cast] lemma intCast_eq_one {n : ℤ} : (n : ℚ) = 1 ↔ n = 1 := intCast_inj @[simp high, norm_cast] lemma natCast_eq_one {n : ℕ} : (n : ℚ) = 1 ↔ n = 1 := natCast_inj lemma mkRat_eq_divInt (n d) : mkRat n d = n /. d := rfl @[simp] lemma mk'_zero (d) (h : d ≠ 0) (w) : mk' 0 d h w = 0 := by congr; simp_all @[simp] lemma num_eq_zero {q : ℚ} : q.num = 0 ↔ q = 0 := by induction q constructor · rintro rfl exact mk'_zero _ _ _ · exact congr_arg num lemma num_ne_zero {q : ℚ} : q.num ≠ 0 ↔ q ≠ 0 := num_eq_zero.not @[simp] lemma den_ne_zero (q : ℚ) : q.den ≠ 0 := q.den_pos.ne' @[simp] lemma num_nonneg : 0 ≤ q.num ↔ 0 ≤ q := by simp [Int.le_iff_lt_or_eq, instLE, Rat.blt, Int.not_lt]; tauto @[simp] theorem divInt_eq_zero {a b : ℤ} (b0 : b ≠ 0) : a /. b = 0 ↔ a = 0 := by rw [← zero_divInt b, divInt_eq_iff b0 b0, Int.zero_mul, Int.mul_eq_zero, or_iff_left b0] theorem divInt_ne_zero {a b : ℤ} (b0 : b ≠ 0) : a /. b ≠ 0 ↔ a ≠ 0 := (divInt_eq_zero b0).not -- TODO: this can move to Batteries theorem normalize_eq_mk' (n : Int) (d : Nat) (h : d ≠ 0) (c : Nat.gcd (Int.natAbs n) d = 1) : normalize n d h = mk' n d h c := (mk_eq_normalize ..).symm -- TODO: Rename `mkRat_num_den` in Batteries @[simp] alias mkRat_num_den' := mkRat_self -- TODO: Rename `Rat.divInt_self` to `Rat.num_divInt_den` in Batteries lemma num_divInt_den (q : ℚ) : q.num /. q.den = q := divInt_self _ lemma mk'_eq_divInt {n d h c} : (⟨n, d, h, c⟩ : ℚ) = n /. d := (num_divInt_den _).symm theorem intCast_eq_divInt (z : ℤ) : (z : ℚ) = z /. 1 := mk'_eq_divInt -- TODO: Rename `divInt_self` in Batteries to `num_divInt_den` @[simp] lemma divInt_self' {n : ℤ} (hn : n ≠ 0) : n /. n = 1 := by simpa using divInt_mul_right (n := 1) (d := 1) hn /-- Define a (dependent) function or prove `∀ r : ℚ, p r` by dealing with rational numbers of the form `n /. d` with `0 < d` and coprime `n`, `d`. -/ @[elab_as_elim] def numDenCasesOn.{u} {C : ℚ → Sort u} : ∀ (a : ℚ) (_ : ∀ n d, 0 < d → (Int.natAbs n).Coprime d → C (n /. d)), C a | ⟨n, d, h, c⟩, H => by rw [mk'_eq_divInt]; exact H n d (Nat.pos_of_ne_zero h) c /-- Define a (dependent) function or prove `∀ r : ℚ, p r` by dealing with rational numbers of the form `n /. d` with `d ≠ 0`. -/ @[elab_as_elim] def numDenCasesOn'.{u} {C : ℚ → Sort u} (a : ℚ) (H : ∀ (n : ℤ) (d : ℕ), d ≠ 0 → C (n /. d)) : C a := numDenCasesOn a fun n d h _ => H n d h.ne' /-- Define a (dependent) function or prove `∀ r : ℚ, p r` by dealing with rational numbers of the form `mk' n d` with `d ≠ 0`. -/ @[elab_as_elim] def numDenCasesOn''.{u} {C : ℚ → Sort u} (a : ℚ) (H : ∀ (n : ℤ) (d : ℕ) (nz red), C (mk' n d nz red)) : C a := numDenCasesOn a fun n d h h' ↦ by rw [← mk_eq_divInt _ _ h.ne' h']; exact H n d h.ne' _ theorem lift_binop_eq (f : ℚ → ℚ → ℚ) (f₁ : ℤ → ℤ → ℤ → ℤ → ℤ) (f₂ : ℤ → ℤ → ℤ → ℤ → ℤ) (fv : ∀ {n₁ d₁ h₁ c₁ n₂ d₂ h₂ c₂}, f ⟨n₁, d₁, h₁, c₁⟩ ⟨n₂, d₂, h₂, c₂⟩ = f₁ n₁ d₁ n₂ d₂ /. f₂ n₁ d₁ n₂ d₂) (f0 : ∀ {n₁ d₁ n₂ d₂}, d₁ ≠ 0 → d₂ ≠ 0 → f₂ n₁ d₁ n₂ d₂ ≠ 0) (a b c d : ℤ) (b0 : b ≠ 0) (d0 : d ≠ 0) (H : ∀ {n₁ d₁ n₂ d₂}, a * d₁ = n₁ * b → c * d₂ = n₂ * d → f₁ n₁ d₁ n₂ d₂ * f₂ a b c d = f₁ a b c d * f₂ n₁ d₁ n₂ d₂) : f (a /. b) (c /. d) = f₁ a b c d /. f₂ a b c d := by generalize ha : a /. b = x; obtain ⟨n₁, d₁, h₁, c₁⟩ := x; rw [mk'_eq_divInt] at ha generalize hc : c /. d = x; obtain ⟨n₂, d₂, h₂, c₂⟩ := x; rw [mk'_eq_divInt] at hc rw [fv] have d₁0 := Int.ofNat_ne_zero.2 h₁ have d₂0 := Int.ofNat_ne_zero.2 h₂ exact (divInt_eq_iff (f0 d₁0 d₂0) (f0 b0 d0)).2 (H ((divInt_eq_iff b0 d₁0).1 ha) ((divInt_eq_iff d0 d₂0).1 hc)) attribute [simp] divInt_add_divInt attribute [simp] neg_divInt lemma neg_def (q : ℚ) : -q = -q.num /. q.den := by rw [← neg_divInt, num_divInt_den] @[simp] lemma divInt_neg (n d : ℤ) : n /. -d = -n /. d := divInt_neg' .. attribute [simp] divInt_sub_divInt @[simp] lemma divInt_mul_divInt' (n₁ d₁ n₂ d₂ : ℤ) : (n₁ /. d₁) * (n₂ /. d₂) = (n₁ * n₂) /. (d₁ * d₂) := by obtain rfl | h₁ := eq_or_ne d₁ 0 · simp obtain rfl | h₂ := eq_or_ne d₂ 0 · simp exact divInt_mul_divInt _ _ h₁ h₂ attribute [simp] mkRat_mul_mkRat lemma mk'_mul_mk' (n₁ n₂ : ℤ) (d₁ d₂ : ℕ) (hd₁ hd₂ hnd₁ hnd₂) (h₁₂ : n₁.natAbs.Coprime d₂) (h₂₁ : n₂.natAbs.Coprime d₁) : mk' n₁ d₁ hd₁ hnd₁ * mk' n₂ d₂ hd₂ hnd₂ = mk' (n₁ * n₂) (d₁ * d₂) (Nat.mul_ne_zero hd₁ hd₂) (by rw [Int.natAbs_mul]; exact (hnd₁.mul h₂₁).mul_right (h₁₂.mul hnd₂)) := by rw [mul_def]; dsimp; simp [mk_eq_normalize] lemma mul_eq_mkRat (q r : ℚ) : q * r = mkRat (q.num * r.num) (q.den * r.den) := by rw [mul_def, normalize_eq_mkRat] -- TODO: Rename `divInt_eq_iff` in Batteries to `divInt_eq_divInt` alias divInt_eq_divInt := divInt_eq_iff instance instPowNat : Pow ℚ ℕ where pow q n := ⟨q.num ^ n, q.den ^ n, by simp [Nat.pow_eq_zero], by rw [Int.natAbs_pow]; exact q.reduced.pow _ _⟩ lemma pow_def (q : ℚ) (n : ℕ) : q ^ n = ⟨q.num ^ n, q.den ^ n, by simp [Nat.pow_eq_zero], by rw [Int.natAbs_pow]; exact q.reduced.pow _ _⟩ := rfl lemma pow_eq_mkRat (q : ℚ) (n : ℕ) : q ^ n = mkRat (q.num ^ n) (q.den ^ n) := by rw [pow_def, mk_eq_mkRat] lemma pow_eq_divInt (q : ℚ) (n : ℕ) : q ^ n = q.num ^ n /. q.den ^ n := by rw [pow_def, mk_eq_divInt, Int.natCast_pow] @[simp] lemma num_pow (q : ℚ) (n : ℕ) : (q ^ n).num = q.num ^ n := rfl @[simp] lemma den_pow (q : ℚ) (n : ℕ) : (q ^ n).den = q.den ^ n := rfl @[simp] lemma mk'_pow (num : ℤ) (den : ℕ) (hd hdn) (n : ℕ) : mk' num den hd hdn ^ n = mk' (num ^ n) (den ^ n) (by simp [Nat.pow_eq_zero, hd]) (by rw [Int.natAbs_pow]; exact hdn.pow _ _) := rfl instance : Inv ℚ := ⟨Rat.inv⟩ @[simp] lemma inv_divInt' (a b : ℤ) : (a /. b)⁻¹ = b /. a := inv_divInt .. @[simp] lemma inv_mkRat (a : ℤ) (b : ℕ) : (mkRat a b)⁻¹ = b /. a := by rw [mkRat_eq_divInt, inv_divInt'] lemma inv_def' (q : ℚ) : q⁻¹ = q.den /. q.num := by rw [← inv_divInt', num_divInt_den] @[simp] lemma divInt_div_divInt (n₁ d₁ n₂ d₂) : (n₁ /. d₁) / (n₂ /. d₂) = (n₁ * d₂) /. (d₁ * n₂) := by rw [div_def, inv_divInt, divInt_mul_divInt'] lemma div_def' (q r : ℚ) : q / r = (q.num * r.den) /. (q.den * r.num) := by rw [← divInt_div_divInt, num_divInt_den, num_divInt_den] variable (a b c : ℚ) protected lemma add_zero : a + 0 = a := by simp [add_def, normalize_eq_mkRat] protected lemma zero_add : 0 + a = a := by simp [add_def, normalize_eq_mkRat] protected lemma add_comm : a + b = b + a := by simp [add_def, Int.add_comm, Int.mul_comm, Nat.mul_comm] protected theorem add_assoc : a + b + c = a + (b + c) := numDenCasesOn' a fun n₁ d₁ h₁ ↦ numDenCasesOn' b fun n₂ d₂ h₂ ↦ numDenCasesOn' c fun n₃ d₃ h₃ ↦ by simp only [ne_eq, Int.natCast_eq_zero, h₁, not_false_eq_true, h₂, divInt_add_divInt, Int.mul_eq_zero, or_self, h₃] rw [Int.mul_assoc, Int.add_mul, Int.add_mul, Int.mul_assoc, Int.add_assoc] congr 2 ac_rfl protected lemma neg_add_cancel : -a + a = 0 := by simp [add_def, normalize_eq_mkRat, Int.neg_mul, Int.add_comm, ← Int.sub_eq_add_neg] @[simp] lemma divInt_one (n : ℤ) : n /. 1 = n := by simp [divInt, mkRat, normalize] @[simp] lemma mkRat_one (n : ℤ) : mkRat n 1 = n := by simp [mkRat_eq_divInt] lemma divInt_one_one : 1 /. 1 = 1 := by rw [divInt_one, intCast_one] protected theorem mul_assoc : a * b * c = a * (b * c) := numDenCasesOn' a fun n₁ d₁ h₁ => numDenCasesOn' b fun n₂ d₂ h₂ => numDenCasesOn' c fun n₃ d₃ h₃ => by simp [h₁, h₂, h₃, Int.mul_comm, Nat.mul_assoc, Int.mul_left_comm] protected theorem add_mul : (a + b) * c = a * c + b * c := numDenCasesOn' a fun n₁ d₁ h₁ ↦ numDenCasesOn' b fun n₂ d₂ h₂ ↦ numDenCasesOn' c fun n₃ d₃ h₃ ↦ by simp only [ne_eq, Int.natCast_eq_zero, h₁, not_false_eq_true, h₂, divInt_add_divInt, Int.mul_eq_zero, or_self, h₃, divInt_mul_divInt] rw [← divInt_mul_right (Int.natCast_ne_zero.2 h₃), Int.add_mul, Int.add_mul] ac_rfl protected theorem mul_add : a * (b + c) = a * b + a * c := by rw [Rat.mul_comm, Rat.add_mul, Rat.mul_comm, Rat.mul_comm c a] protected theorem zero_ne_one : 0 ≠ (1 : ℚ) := by rw [ne_comm, ← divInt_one_one, divInt_ne_zero] <;> omega attribute [simp] mkRat_eq_zero protected theorem mul_inv_cancel : a ≠ 0 → a * a⁻¹ = 1 := numDenCasesOn' a fun n d hd hn ↦ by simp only [divInt_ofNat, ne_eq, hd, not_false_eq_true, mkRat_eq_zero] at hn simp [-divInt_ofNat, mkRat_eq_divInt, Int.mul_comm, Int.mul_ne_zero hn (Int.ofNat_ne_zero.2 hd)] protected theorem inv_mul_cancel (h : a ≠ 0) : a⁻¹ * a = 1 := Eq.trans (Rat.mul_comm _ _) (Rat.mul_inv_cancel _ h) -- Extra instances to short-circuit type class resolution -- TODO(Mario): this instance slows down Mathlib.Data.Real.Basic instance nontrivial : Nontrivial ℚ where exists_pair_ne := ⟨1, 0, by decide⟩ /-! ### The rational numbers are a group -/ instance addCommGroup : AddCommGroup ℚ where zero := 0 add := (· + ·) neg := Neg.neg
zero_add := Rat.zero_add
Mathlib/Data/Rat/Defs.lean
292
292
/- 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.AlgebraicGeometry.Gluing import Mathlib.CategoryTheory.Limits.Opposites import Mathlib.AlgebraicGeometry.AffineScheme import Mathlib.CategoryTheory.Limits.Shapes.Diagonal import Mathlib.CategoryTheory.ChosenFiniteProducts.Over /-! # Fibred products of schemes In this file we construct the fibred product of schemes via gluing. We roughly follow [har77] Theorem 3.3. In particular, the main construction is to show that for an open cover `{ Uᵢ }` of `X`, if there exist fibred products `Uᵢ ×[Z] Y` for each `i`, then there exists a fibred product `X ×[Z] Y`. Then, for constructing the fibred product for arbitrary schemes `X, Y, Z`, we can use the construction to reduce to the case where `X, Y, Z` are all affine, where fibred products are constructed via tensor products. -/ universe v u noncomputable section open CategoryTheory CategoryTheory.Limits AlgebraicGeometry namespace AlgebraicGeometry.Scheme namespace Pullback variable {C : Type u} [Category.{v} C] variable {X Y Z : Scheme.{u}} (𝒰 : OpenCover.{u} X) (f : X ⟶ Z) (g : Y ⟶ Z) variable [∀ i, HasPullback (𝒰.map i ≫ f) g] /-- The intersection of `Uᵢ ×[Z] Y` and `Uⱼ ×[Z] Y` is given by (Uᵢ ×[Z] Y) ×[X] Uⱼ -/ def v (i j : 𝒰.J) : Scheme := pullback ((pullback.fst (𝒰.map i ≫ f) g) ≫ 𝒰.map i) (𝒰.map j) /-- The canonical transition map `(Uᵢ ×[Z] Y) ×[X] Uⱼ ⟶ (Uⱼ ×[Z] Y) ×[X] Uᵢ` given by the fact that pullbacks are associative and symmetric. -/ def t (i j : 𝒰.J) : v 𝒰 f g i j ⟶ v 𝒰 f g j i := by have : HasPullback (pullback.snd _ _ ≫ 𝒰.map i ≫ f) g := hasPullback_assoc_symm (𝒰.map j) (𝒰.map i) (𝒰.map i ≫ f) g have : HasPullback (pullback.snd _ _ ≫ 𝒰.map j ≫ f) g := hasPullback_assoc_symm (𝒰.map i) (𝒰.map j) (𝒰.map j ≫ f) g refine (pullbackSymmetry ..).hom ≫ (pullbackAssoc ..).inv ≫ ?_ refine ?_ ≫ (pullbackAssoc ..).hom ≫ (pullbackSymmetry ..).hom refine pullback.map _ _ _ _ (pullbackSymmetry _ _).hom (𝟙 _) (𝟙 _) ?_ ?_ · rw [pullbackSymmetry_hom_comp_snd_assoc, pullback.condition_assoc, Category.comp_id] · rw [Category.comp_id, Category.id_comp] @[simp, reassoc] theorem t_fst_fst (i j : 𝒰.J) : t 𝒰 f g i j ≫ pullback.fst _ _ ≫ pullback.fst _ _ = pullback.snd _ _ := by simp only [t, Category.assoc, pullbackSymmetry_hom_comp_fst_assoc, pullbackAssoc_hom_snd_fst, pullback.lift_fst_assoc, pullbackSymmetry_hom_comp_snd, pullbackAssoc_inv_fst_fst, pullbackSymmetry_hom_comp_fst] @[simp, reassoc] theorem t_fst_snd (i j : 𝒰.J) : t 𝒰 f g i j ≫ pullback.fst _ _ ≫ pullback.snd _ _ = pullback.fst _ _ ≫ pullback.snd _ _ := by simp only [t, Category.assoc, pullbackSymmetry_hom_comp_fst_assoc, pullbackAssoc_hom_snd_snd, pullback.lift_snd, Category.comp_id, pullbackAssoc_inv_snd, pullbackSymmetry_hom_comp_snd_assoc] @[simp, reassoc] theorem t_snd (i j : 𝒰.J) : t 𝒰 f g i j ≫ pullback.snd _ _ = pullback.fst _ _ ≫ pullback.fst _ _ := by simp only [t, Category.assoc, pullbackSymmetry_hom_comp_snd, pullbackAssoc_hom_fst, pullback.lift_fst_assoc, pullbackSymmetry_hom_comp_fst, pullbackAssoc_inv_fst_snd, pullbackSymmetry_hom_comp_snd_assoc] theorem t_id (i : 𝒰.J) : t 𝒰 f g i i = 𝟙 _ := by apply pullback.hom_ext <;> rw [Category.id_comp] · apply pullback.hom_ext · rw [← cancel_mono (𝒰.map i)]; simp only [pullback.condition, Category.assoc, t_fst_fst] · simp only [Category.assoc, t_fst_snd]
· rw [← cancel_mono (𝒰.map i)]; simp only [pullback.condition, t_snd, Category.assoc] /-- The inclusion map of `V i j = (Uᵢ ×[Z] Y) ×[X] Uⱼ ⟶ Uᵢ ×[Z] Y` -/ abbrev fV (i j : 𝒰.J) : v 𝒰 f g i j ⟶ pullback (𝒰.map i ≫ f) g := pullback.fst _ _
Mathlib/AlgebraicGeometry/Pullbacks.lean
84
89
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.Geometry.RingedSpace.PresheafedSpace import Mathlib.CategoryTheory.Limits.Final import Mathlib.Topology.Sheaves.Stalks /-! # Stalks for presheaved spaces This file lifts constructions of stalks and pushforwards of stalks to work with the category of presheafed spaces. Additionally, we prove that restriction of presheafed spaces does not change the stalks. -/ noncomputable section universe v u v' u' open Opposite CategoryTheory CategoryTheory.Category CategoryTheory.Functor CategoryTheory.Limits AlgebraicGeometry TopologicalSpace Topology variable {C : Type u} [Category.{v} C] [HasColimits C] -- Porting note: no tidy tactic -- attribute [local tidy] tactic.auto_cases_opens -- this could be replaced by -- attribute [local aesop safe cases (rule_sets := [CategoryTheory])] Opens -- but it doesn't appear to be needed here. open TopCat.Presheaf namespace AlgebraicGeometry.PresheafedSpace /-- A morphism of presheafed spaces induces a morphism of stalks. -/ def Hom.stalkMap {X Y : PresheafedSpace.{_, _, v} C} (α : Hom X Y) (x : X) : Y.presheaf.stalk (α.base x) ⟶ X.presheaf.stalk x := (stalkFunctor C (α.base x)).map α.c ≫ X.presheaf.stalkPushforward C α.base x @[elementwise, reassoc] theorem stalkMap_germ {X Y : PresheafedSpace.{_, _, v} C} (α : X ⟶ Y) (U : Opens Y) (x : X) (hx : α x ∈ U) : Y.presheaf.germ U (α x) hx ≫ α.stalkMap x = α.c.app (op U) ≫ X.presheaf.germ ((Opens.map α.base).obj U) x hx := by rw [Hom.stalkMap, stalkFunctor_map_germ_assoc, stalkPushforward_germ] section Restrict /-- For an open embedding `f : U ⟶ X` and a point `x : U`, we get an isomorphism between the stalk of `X` at `f x` and the stalk of the restriction of `X` along `f` at t `x`. -/ def restrictStalkIso {U : TopCat} (X : PresheafedSpace.{_, _, v} C) {f : U ⟶ (X : TopCat.{v})} (h : IsOpenEmbedding f) (x : U) : (X.restrict h).presheaf.stalk x ≅ X.presheaf.stalk (f x) := haveI := initial_of_adjunction (h.isOpenMap.adjunctionNhds x) Final.colimitIso (h.isOpenMap.functorNhds x).op ((OpenNhds.inclusion (f x)).op ⋙ X.presheaf) -- As a left adjoint, the functor `h.is_open_map.functor_nhds x` is initial. -- Typeclass resolution knows that the opposite of an initial functor is final. The result -- follows from the general fact that postcomposing with a final functor doesn't change colimits. -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11119): removed `simp` attribute, for left hand side is not in simple normal form. @[elementwise, reassoc] theorem restrictStalkIso_hom_eq_germ {U : TopCat} (X : PresheafedSpace.{_, _, v} C) {f : U ⟶ (X : TopCat.{v})} (h : IsOpenEmbedding f) (V : Opens U) (x : U) (hx : x ∈ V) : (X.restrict h).presheaf.germ _ x hx ≫ (restrictStalkIso X h x).hom = X.presheaf.germ (h.isOpenMap.functor.obj V) (f x) ⟨x, hx, rfl⟩ := colimit.ι_pre ((OpenNhds.inclusion (f x)).op ⋙ X.presheaf) (h.isOpenMap.functorNhds x).op (op ⟨V, hx⟩) -- We intentionally leave `simp` off the lemmas generated by `elementwise` and `reassoc`, -- as the simpNF linter claims they never apply. @[simp, elementwise, reassoc] theorem restrictStalkIso_inv_eq_germ {U : TopCat} (X : PresheafedSpace.{_, _, v} C) {f : U ⟶ (X : TopCat.{v})} (h : IsOpenEmbedding f) (V : Opens U) (x : U) (hx : x ∈ V) : X.presheaf.germ (h.isOpenMap.functor.obj V) (f x) ⟨x, hx, rfl⟩ ≫ (restrictStalkIso X h x).inv = (X.restrict h).presheaf.germ _ x hx := by rw [← restrictStalkIso_hom_eq_germ, Category.assoc, Iso.hom_inv_id, Category.comp_id] theorem restrictStalkIso_inv_eq_ofRestrict {U : TopCat} (X : PresheafedSpace.{_, _, v} C) {f : U ⟶ (X : TopCat.{v})} (h : IsOpenEmbedding f) (x : U) : (X.restrictStalkIso h x).inv = (X.ofRestrict h).stalkMap x := by -- We can't use `ext` here due to https://github.com/leanprover/std4/pull/159 refine colimit.hom_ext fun V => ?_ induction V with | op V => ?_ let i : (h.isOpenMap.functorNhds x).obj ((OpenNhds.map f x).obj V) ⟶ V := homOfLE (Set.image_preimage_subset f _) erw [Iso.comp_inv_eq, colimit.ι_map_assoc, colimit.ι_map_assoc, colimit.ι_pre] simp_rw [Category.assoc] erw [colimit.ι_pre ((OpenNhds.inclusion (f x)).op ⋙ X.presheaf) (h.isOpenMap.functorNhds x).op] erw [← X.presheaf.map_comp_assoc] exact (colimit.w ((OpenNhds.inclusion (f x)).op ⋙ X.presheaf) i.op).symm instance ofRestrict_stalkMap_isIso {U : TopCat} (X : PresheafedSpace.{_, _, v} C) {f : U ⟶ (X : TopCat.{v})} (h : IsOpenEmbedding f) (x : U) : IsIso ((X.ofRestrict h).stalkMap x) := by rw [← restrictStalkIso_inv_eq_ofRestrict]; infer_instance end Restrict namespace stalkMap @[simp] theorem id (X : PresheafedSpace.{_, _, v} C) (x : X) : (𝟙 X : X ⟶ X).stalkMap x = 𝟙 (X.presheaf.stalk x) := by dsimp [Hom.stalkMap] simp only [stalkPushforward.id] rw [← map_comp] convert (stalkFunctor C x).map_id X.presheaf ext simp only [id_c, id_comp, Pushforward.id_hom_app, op_obj, eqToHom_refl, map_id] rfl @[simp] theorem comp {X Y Z : PresheafedSpace.{_, _, v} C} (α : X ⟶ Y) (β : Y ⟶ Z) (x : X) : (α ≫ β).stalkMap x = (β.stalkMap (α.base x) : Z.presheaf.stalk (β.base (α.base x)) ⟶ Y.presheaf.stalk (α.base x)) ≫ (α.stalkMap x : Y.presheaf.stalk (α.base x) ⟶ X.presheaf.stalk x) := by dsimp [Hom.stalkMap, stalkFunctor, stalkPushforward] -- We can't use `ext` here due to https://github.com/leanprover/std4/pull/159 apply colimit.hom_ext rintro ⟨U, hU⟩ simp /-- If `α = β` and `x = x'`, we would like to say that `stalk_map α x = stalk_map β x'`. Unfortunately, this equality is not well-formed, as their types are not _definitionally_ the same. To get a proper congruence lemma, we therefore have to introduce these `eqToHom` arrows on either side of the equality. -/ theorem congr {X Y : PresheafedSpace.{_, _, v} C} (α β : X ⟶ Y) (h₁ : α = β) (x x' : X) (h₂ : x = x') : α.stalkMap x ≫ eqToHom (show X.presheaf.stalk x = X.presheaf.stalk x' by rw [h₂]) =
eqToHom (show Y.presheaf.stalk (α.base x) = Y.presheaf.stalk (β.base x') by rw [h₁, h₂]) ≫ β.stalkMap x' := by ext substs h₁ h₂ simp theorem congr_hom {X Y : PresheafedSpace.{_, _, v} C} (α β : X ⟶ Y) (h : α = β) (x : X) : α.stalkMap x = eqToHom (show Y.presheaf.stalk (α.base x) =
Mathlib/Geometry/RingedSpace/Stalks.lean
137
145
/- Copyright (c) 2022 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Heather Macbeth -/ import Mathlib.Algebra.MvPolynomial.Supported import Mathlib.RingTheory.WittVector.Truncated /-! # Leading terms of Witt vector multiplication The goal of this file is to study the leading terms of the formula for the `n+1`st coefficient of a product of Witt vectors `x` and `y` over a ring of characteristic `p`. We aim to isolate the `n+1`st coefficients of `x` and `y`, and express the rest of the product in terms of a function of the lower coefficients. For most of this file we work with terms of type `MvPolynomial (Fin 2 × ℕ) ℤ`. We will eventually evaluate them in `k`, but first we must take care of a calculation that needs to happen in characteristic 0. ## Main declarations * `WittVector.nth_mul_coeff`: expresses the coefficient of a product of Witt vectors in terms of the previous coefficients of the multiplicands. -/ noncomputable section namespace WittVector variable (p : ℕ) [hp : Fact p.Prime] variable {k : Type*} [CommRing k] local notation "𝕎" => WittVector p -- Porting note: new notation local notation "𝕄" => MvPolynomial (Fin 2 × ℕ) ℤ open Finset MvPolynomial /-- ``` (∑ i ∈ range n, (y.coeff i)^(p^(n-i)) * p^i.val) * (∑ i ∈ range n, (y.coeff i)^(p^(n-i)) * p^i.val) ``` -/ def wittPolyProd (n : ℕ) : 𝕄 := rename (Prod.mk (0 : Fin 2)) (wittPolynomial p ℤ n) * rename (Prod.mk (1 : Fin 2)) (wittPolynomial p ℤ n) theorem wittPolyProd_vars (n : ℕ) : (wittPolyProd p n).vars ⊆ univ ×ˢ range (n + 1) := by rw [wittPolyProd] apply Subset.trans (vars_mul _ _) refine union_subset ?_ ?_ <;> · refine Subset.trans (vars_rename _ _) ?_ simp [wittPolynomial_vars, image_subset_iff] /-- The "remainder term" of `WittVector.wittPolyProd`. See `mul_polyOfInterest_aux2`. -/ def wittPolyProdRemainder (n : ℕ) : 𝕄 := ∑ i ∈ range n, (p : 𝕄) ^ i * wittMul p i ^ p ^ (n - i) theorem wittPolyProdRemainder_vars (n : ℕ) : (wittPolyProdRemainder p n).vars ⊆ univ ×ˢ range n := by rw [wittPolyProdRemainder] refine Subset.trans (vars_sum_subset _ _) ?_ rw [biUnion_subset] intro x hx apply Subset.trans (vars_mul _ _) refine union_subset ?_ ?_ · apply Subset.trans (vars_pow _ _) have : (p : 𝕄) = C (p : ℤ) := by simp only [Int.cast_natCast, eq_intCast] rw [this, vars_C] apply empty_subset · apply Subset.trans (vars_pow _ _) apply Subset.trans (wittMul_vars _ _) apply product_subset_product (Subset.refl _) simp only [mem_range, range_subset] at hx ⊢ exact hx /-- `remainder p n` represents the remainder term from `mul_polyOfInterest_aux3`. `wittPolyProd p (n+1)` will have variables up to `n+1`, but `remainder` will only have variables up to `n`. -/ def remainder (n : ℕ) : 𝕄 := (∑ x ∈ range (n + 1), (rename (Prod.mk 0)) ((monomial (Finsupp.single x (p ^ (n + 1 - x)))) ((p : ℤ) ^ x))) * ∑ x ∈ range (n + 1), (rename (Prod.mk 1)) ((monomial (Finsupp.single x (p ^ (n + 1 - x)))) ((p : ℤ) ^ x)) theorem remainder_vars (n : ℕ) : (remainder p n).vars ⊆ univ ×ˢ range (n + 1) := by rw [remainder] apply Subset.trans (vars_mul _ _) refine union_subset ?_ ?_ <;> · refine Subset.trans (vars_sum_subset _ _) ?_ rw [biUnion_subset] intro x hx rw [rename_monomial, vars_monomial, Finsupp.mapDomain_single] · apply Subset.trans Finsupp.support_single_subset simpa using mem_range.mp hx · apply pow_ne_zero exact mod_cast hp.out.ne_zero /-- This is the polynomial whose degree we want to get a handle on. -/ def polyOfInterest (n : ℕ) : 𝕄 := wittMul p (n + 1) + (p : 𝕄) ^ (n + 1) * X (0, n + 1) * X (1, n + 1) - X (0, n + 1) * rename (Prod.mk (1 : Fin 2)) (wittPolynomial p ℤ (n + 1)) - X (1, n + 1) * rename (Prod.mk (0 : Fin 2)) (wittPolynomial p ℤ (n + 1)) theorem mul_polyOfInterest_aux1 (n : ℕ) : ∑ i ∈ range (n + 1), (p : 𝕄) ^ i * wittMul p i ^ p ^ (n - i) = wittPolyProd p n := by simp only [wittPolyProd] convert wittStructureInt_prop p (X (0 : Fin 2) * X 1) n using 1 · simp only [wittPolynomial, wittMul] rw [map_sum] congr 1 with i congr 1 have hsupp : (Finsupp.single i (p ^ (n - i))).support = {i} := by rw [Finsupp.support_eq_singleton] simp only [and_true, Finsupp.single_eq_same, eq_self_iff_true, Ne] exact pow_ne_zero _ hp.out.ne_zero simp only [bind₁_monomial, hsupp, Int.cast_natCast, prod_singleton, eq_intCast, Finsupp.single_eq_same, C_pow, mul_eq_mul_left_iff, eq_self_iff_true, Int.cast_pow] · simp only [map_mul, bind₁_X_right] theorem mul_polyOfInterest_aux2 (n : ℕ) : (p : 𝕄) ^ n * wittMul p n + wittPolyProdRemainder p n = wittPolyProd p n := by convert mul_polyOfInterest_aux1 p n rw [sum_range_succ, add_comm, Nat.sub_self, pow_zero, pow_one] rfl -- We redeclare `p` here to locally discard the unneeded `p.Prime` hypothesis. theorem mul_polyOfInterest_aux3 (p n : ℕ) : wittPolyProd p (n + 1) = -((p : 𝕄) ^ (n + 1) * X (0, n + 1)) * ((p : 𝕄) ^ (n + 1) * X (1, n + 1)) + (p : 𝕄) ^ (n + 1) * X (0, n + 1) * rename (Prod.mk (1 : Fin 2)) (wittPolynomial p ℤ (n + 1)) + (p : 𝕄) ^ (n + 1) * X (1, n + 1) * rename (Prod.mk (0 : Fin 2)) (wittPolynomial p ℤ (n + 1)) + remainder p n := by -- a useful auxiliary fact have mvpz : (p : 𝕄) ^ (n + 1) = MvPolynomial.C ((p : ℤ) ^ (n + 1)) := by norm_cast -- Porting note: the original proof applies `sum_range_succ` through a non-`conv` rewrite, -- but this does not work in Lean 4; the whole proof also times out very badly. The proof has been -- nearly totally rewritten here and now finishes quite fast. rw [wittPolyProd, wittPolynomial, map_sum, map_sum]
conv_lhs => arg 1 rw [sum_range_succ, ← C_mul_X_pow_eq_monomial, tsub_self, pow_zero, pow_one, map_mul, rename_C, rename_X, ← mvpz] conv_lhs => arg 2 rw [sum_range_succ, ← C_mul_X_pow_eq_monomial, tsub_self, pow_zero, pow_one, map_mul, rename_C, rename_X, ← mvpz] conv_rhs => enter [1, 1, 2, 2] rw [sum_range_succ, ← C_mul_X_pow_eq_monomial, tsub_self, pow_zero, pow_one, map_mul, rename_C, rename_X, ← mvpz] conv_rhs => enter [1, 2, 2] rw [sum_range_succ, ← C_mul_X_pow_eq_monomial, tsub_self, pow_zero, pow_one, map_mul, rename_C, rename_X, ← mvpz] simp only [add_mul, mul_add] rw [add_comm _ (remainder p n)] simp only [add_assoc] apply congrArg (Add.add _) ring theorem mul_polyOfInterest_aux4 (n : ℕ) : (p : 𝕄) ^ (n + 1) * wittMul p (n + 1) = -((p : 𝕄) ^ (n + 1) * X (0, n + 1)) * ((p : 𝕄) ^ (n + 1) * X (1, n + 1)) + (p : 𝕄) ^ (n + 1) * X (0, n + 1) * rename (Prod.mk (1 : Fin 2)) (wittPolynomial p ℤ (n + 1)) + (p : 𝕄) ^ (n + 1) * X (1, n + 1) * rename (Prod.mk (0 : Fin 2)) (wittPolynomial p ℤ (n + 1)) + (remainder p n - wittPolyProdRemainder p (n + 1)) := by rw [← add_sub_assoc, eq_sub_iff_add_eq, mul_polyOfInterest_aux2] exact mul_polyOfInterest_aux3 _ _ theorem mul_polyOfInterest_aux5 (n : ℕ) :
Mathlib/RingTheory/WittVector/MulCoeff.lean
145
176
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker -/ import Mathlib.Algebra.Group.Submonoid.Operations import Mathlib.Algebra.MonoidAlgebra.Defs import Mathlib.Algebra.Order.Monoid.Unbundled.WithTop import Mathlib.Algebra.Ring.Action.Rat import Mathlib.Data.Finset.Sort import Mathlib.Tactic.FastInstance /-! # Theory of univariate polynomials This file defines `Polynomial R`, the type of univariate polynomials over the semiring `R`, builds a semiring structure on it, and gives basic definitions that are expanded in other files in this directory. ## Main definitions * `monomial n a` is the polynomial `a X^n`. Note that `monomial n` is defined as an `R`-linear map. * `C a` is the constant polynomial `a`. Note that `C` is defined as a ring homomorphism. * `X` is the polynomial `X`, i.e., `monomial 1 1`. * `p.sum f` is `∑ n ∈ p.support, f n (p.coeff n)`, i.e., one sums the values of functions applied to coefficients of the polynomial `p`. * `p.erase n` is the polynomial `p` in which one removes the `c X^n` term. There are often two natural variants of lemmas involving sums, depending on whether one acts on the polynomials, or on the function. The naming convention is that one adds `index` when acting on the polynomials. For instance, * `sum_add_index` states that `(p + q).sum f = p.sum f + q.sum f`; * `sum_add` states that `p.sum (fun n x ↦ f n x + g n x) = p.sum f + p.sum g`. * Notation to refer to `Polynomial R`, as `R[X]` or `R[t]`. ## Implementation Polynomials are defined using `R[ℕ]`, where `R` is a semiring. The variable `X` commutes with every polynomial `p`: lemma `X_mul` proves the identity `X * p = p * X`. The relationship to `R[ℕ]` is through a structure to make polynomials irreducible from the point of view of the kernel. Most operations are irreducible since Lean can not compute anyway with `AddMonoidAlgebra`. There are two exceptions that we make semireducible: * The zero polynomial, so that its coefficients are definitionally equal to `0`. * The scalar action, to permit typeclass search to unfold it to resolve potential instance diamonds. The raw implementation of the equivalence between `R[X]` and `R[ℕ]` is done through `ofFinsupp` and `toFinsupp` (or, equivalently, `rcases p` when `p` is a polynomial gives an element `q` of `R[ℕ]`, and conversely `⟨q⟩` gives back `p`). The equivalence is also registered as a ring equiv in `Polynomial.toFinsuppIso`. These should in general not be used once the basic API for polynomials is constructed. -/ noncomputable section /-- `Polynomial R` is the type of univariate polynomials over `R`, denoted as `R[X]` within the `Polynomial` namespace. Polynomials should be seen as (semi-)rings with the additional constructor `X`. The embedding from `R` is called `C`. -/ structure Polynomial (R : Type*) [Semiring R] where ofFinsupp :: toFinsupp : AddMonoidAlgebra R ℕ @[inherit_doc] scoped[Polynomial] notation:9000 R "[X]" => Polynomial R open AddMonoidAlgebra Finset open Finsupp hiding single open Function hiding Commute namespace Polynomial universe u variable {R : Type u} {a b : R} {m n : ℕ} section Semiring variable [Semiring R] {p q : R[X]} theorem forall_iff_forall_finsupp (P : R[X] → Prop) : (∀ p, P p) ↔ ∀ q : R[ℕ], P ⟨q⟩ := ⟨fun h q => h ⟨q⟩, fun h ⟨p⟩ => h p⟩ theorem exists_iff_exists_finsupp (P : R[X] → Prop) : (∃ p, P p) ↔ ∃ q : R[ℕ], P ⟨q⟩ := ⟨fun ⟨⟨p⟩, hp⟩ => ⟨p, hp⟩, fun ⟨q, hq⟩ => ⟨⟨q⟩, hq⟩⟩ @[simp] theorem eta (f : R[X]) : Polynomial.ofFinsupp f.toFinsupp = f := by cases f; rfl /-! ### Conversions to and from `AddMonoidAlgebra` Since `R[X]` is not defeq to `R[ℕ]`, but instead is a structure wrapping it, we have to copy across all the arithmetic operators manually, along with the lemmas about how they unfold around `Polynomial.ofFinsupp` and `Polynomial.toFinsupp`. -/ section AddMonoidAlgebra private irreducible_def add : R[X] → R[X] → R[X] | ⟨a⟩, ⟨b⟩ => ⟨a + b⟩ private irreducible_def neg {R : Type u} [Ring R] : R[X] → R[X] | ⟨a⟩ => ⟨-a⟩ private irreducible_def mul : R[X] → R[X] → R[X] | ⟨a⟩, ⟨b⟩ => ⟨a * b⟩ instance zero : Zero R[X] := ⟨⟨0⟩⟩ instance one : One R[X] := ⟨⟨1⟩⟩ instance add' : Add R[X] := ⟨add⟩ instance neg' {R : Type u} [Ring R] : Neg R[X] := ⟨neg⟩ instance sub {R : Type u} [Ring R] : Sub R[X] := ⟨fun a b => a + -b⟩ instance mul' : Mul R[X] := ⟨mul⟩ -- If the private definitions are accidentally exposed, simplify them away. @[simp] theorem add_eq_add : add p q = p + q := rfl @[simp] theorem mul_eq_mul : mul p q = p * q := rfl instance instNSMul : SMul ℕ R[X] where smul r p := ⟨r • p.toFinsupp⟩ instance smulZeroClass {S : Type*} [SMulZeroClass S R] : SMulZeroClass S R[X] where smul r p := ⟨r • p.toFinsupp⟩ smul_zero a := congr_arg ofFinsupp (smul_zero a) instance {S : Type*} [Zero S] [SMulZeroClass S R] [NoZeroSMulDivisors S R] : NoZeroSMulDivisors S R[X] where eq_zero_or_eq_zero_of_smul_eq_zero eq := (eq_zero_or_eq_zero_of_smul_eq_zero <| congr_arg toFinsupp eq).imp id (congr_arg ofFinsupp) -- to avoid a bug in the `ring` tactic instance (priority := 1) pow : Pow R[X] ℕ where pow p n := npowRec n p @[simp] theorem ofFinsupp_zero : (⟨0⟩ : R[X]) = 0 := rfl @[simp] theorem ofFinsupp_one : (⟨1⟩ : R[X]) = 1 := rfl @[simp] theorem ofFinsupp_add {a b} : (⟨a + b⟩ : R[X]) = ⟨a⟩ + ⟨b⟩ := show _ = add _ _ by rw [add_def] @[simp] theorem ofFinsupp_neg {R : Type u} [Ring R] {a} : (⟨-a⟩ : R[X]) = -⟨a⟩ := show _ = neg _ by rw [neg_def] @[simp] theorem ofFinsupp_sub {R : Type u} [Ring R] {a b} : (⟨a - b⟩ : R[X]) = ⟨a⟩ - ⟨b⟩ := by rw [sub_eq_add_neg, ofFinsupp_add, ofFinsupp_neg] rfl @[simp] theorem ofFinsupp_mul (a b) : (⟨a * b⟩ : R[X]) = ⟨a⟩ * ⟨b⟩ := show _ = mul _ _ by rw [mul_def] @[simp] theorem ofFinsupp_nsmul (a : ℕ) (b) : (⟨a • b⟩ : R[X]) = (a • ⟨b⟩ : R[X]) := rfl @[simp] theorem ofFinsupp_smul {S : Type*} [SMulZeroClass S R] (a : S) (b) : (⟨a • b⟩ : R[X]) = (a • ⟨b⟩ : R[X]) := rfl @[simp] theorem ofFinsupp_pow (a) (n : ℕ) : (⟨a ^ n⟩ : R[X]) = ⟨a⟩ ^ n := by change _ = npowRec n _ induction n with | zero => simp [npowRec] | succ n n_ih => simp [npowRec, n_ih, pow_succ] @[simp] theorem toFinsupp_zero : (0 : R[X]).toFinsupp = 0 := rfl @[simp] theorem toFinsupp_one : (1 : R[X]).toFinsupp = 1 := rfl @[simp] theorem toFinsupp_add (a b : R[X]) : (a + b).toFinsupp = a.toFinsupp + b.toFinsupp := by cases a cases b rw [← ofFinsupp_add] @[simp] theorem toFinsupp_neg {R : Type u} [Ring R] (a : R[X]) : (-a).toFinsupp = -a.toFinsupp := by cases a rw [← ofFinsupp_neg] @[simp] theorem toFinsupp_sub {R : Type u} [Ring R] (a b : R[X]) : (a - b).toFinsupp = a.toFinsupp - b.toFinsupp := by rw [sub_eq_add_neg, ← toFinsupp_neg, ← toFinsupp_add] rfl @[simp] theorem toFinsupp_mul (a b : R[X]) : (a * b).toFinsupp = a.toFinsupp * b.toFinsupp := by cases a cases b rw [← ofFinsupp_mul] @[simp] theorem toFinsupp_nsmul (a : ℕ) (b : R[X]) : (a • b).toFinsupp = a • b.toFinsupp := rfl @[simp] theorem toFinsupp_smul {S : Type*} [SMulZeroClass S R] (a : S) (b : R[X]) : (a • b).toFinsupp = a • b.toFinsupp := rfl @[simp] theorem toFinsupp_pow (a : R[X]) (n : ℕ) : (a ^ n).toFinsupp = a.toFinsupp ^ n := by cases a rw [← ofFinsupp_pow] theorem _root_.IsSMulRegular.polynomial {S : Type*} [SMulZeroClass S R] {a : S} (ha : IsSMulRegular R a) : IsSMulRegular R[X] a | ⟨_x⟩, ⟨_y⟩, h => congr_arg _ <| ha.finsupp (Polynomial.ofFinsupp.inj h) theorem toFinsupp_injective : Function.Injective (toFinsupp : R[X] → AddMonoidAlgebra _ _) := fun ⟨_x⟩ ⟨_y⟩ => congr_arg _ @[simp] theorem toFinsupp_inj {a b : R[X]} : a.toFinsupp = b.toFinsupp ↔ a = b := toFinsupp_injective.eq_iff @[simp] theorem toFinsupp_eq_zero {a : R[X]} : a.toFinsupp = 0 ↔ a = 0 := by rw [← toFinsupp_zero, toFinsupp_inj] @[simp] theorem toFinsupp_eq_one {a : R[X]} : a.toFinsupp = 1 ↔ a = 1 := by rw [← toFinsupp_one, toFinsupp_inj] /-- A more convenient spelling of `Polynomial.ofFinsupp.injEq` in terms of `Iff`. -/ theorem ofFinsupp_inj {a b} : (⟨a⟩ : R[X]) = ⟨b⟩ ↔ a = b := iff_of_eq (ofFinsupp.injEq _ _) @[simp] theorem ofFinsupp_eq_zero {a} : (⟨a⟩ : R[X]) = 0 ↔ a = 0 := by rw [← ofFinsupp_zero, ofFinsupp_inj] @[simp] theorem ofFinsupp_eq_one {a} : (⟨a⟩ : R[X]) = 1 ↔ a = 1 := by rw [← ofFinsupp_one, ofFinsupp_inj] instance inhabited : Inhabited R[X] := ⟨0⟩ instance instNatCast : NatCast R[X] where natCast n := ofFinsupp n @[simp] theorem ofFinsupp_natCast (n : ℕ) : (⟨n⟩ : R[X]) = n := rfl @[simp] theorem toFinsupp_natCast (n : ℕ) : (n : R[X]).toFinsupp = n := rfl @[simp] theorem ofFinsupp_ofNat (n : ℕ) [n.AtLeastTwo] : (⟨ofNat(n)⟩ : R[X]) = ofNat(n) := rfl @[simp]
theorem toFinsupp_ofNat (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : R[X]).toFinsupp = ofNat(n) := rfl
Mathlib/Algebra/Polynomial/Basic.lean
281
282
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Batteries.Tactic.Alias import Mathlib.Tactic.TypeStar /-! # Boolean quantifiers This proves a few properties about `List.all` and `List.any`, which are the `Bool` universal and existential quantifiers. Their definitions are in core Lean. -/ variable {α : Type*} {p : α → Prop} [DecidablePred p] {l : List α} {a : α} namespace List theorem all_iff_forall_prop : (all l fun a => p a) ↔ ∀ a ∈ l, p a := by simp theorem any_iff_exists_prop : (any l fun a => p a) ↔ ∃ a ∈ l, p a := by simp theorem any_of_mem {p : α → Bool} (h₁ : a ∈ l) (h₂ : p a) : any l p := any_eq_true.2 ⟨_, h₁, h₂⟩ end List
Mathlib/Data/Bool/AllAny.lean
48
48
/- 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.RingTheory.Localization.Integer import Mathlib.RingTheory.Localization.Submodule /-! # Fractional ideals This file defines fractional ideals of an integral domain and proves basic facts about them. ## Main definitions Let `S` be a submonoid of an integral domain `R` and `P` the localization of `R` at `S`. * `IsFractional` defines which `R`-submodules of `P` are fractional ideals * `FractionalIdeal S P` is the type of fractional ideals in `P` * a coercion `coeIdeal : Ideal R → FractionalIdeal S P` * `CommSemiring (FractionalIdeal S P)` instance: the typical ideal operations generalized to fractional ideals * `Lattice (FractionalIdeal S P)` instance ## Main statements * `mul_left_mono` and `mul_right_mono` state that ideal multiplication is monotone * `mul_div_self_cancel_iff` states that `1 / I` is the inverse of `I` if one exists ## Implementation notes Fractional ideals are considered equal when they contain the same elements, independent of the denominator `a : R` such that `a I ⊆ R`. Thus, we define `FractionalIdeal` to be the subtype of the predicate `IsFractional`, instead of having `FractionalIdeal` be a structure of which `a` is a field. Most definitions in this file specialize operations from submodules to fractional ideals, proving that the result of this operation is fractional if the input is fractional. Exceptions to this rule are defining `(+) := (⊔)` and `⊥ := 0`, in order to re-use their respective proof terms. We can still use `simp` to show `↑I + ↑J = ↑(I + J)` and `↑⊥ = ↑0`. Many results in fact do not need that `P` is a localization, only that `P` is an `R`-algebra. We omit the `IsLocalization` parameter whenever this is practical. Similarly, we don't assume that the localization is a field until we need it to define ideal quotients. When this assumption is needed, we replace `S` with `R⁰`, making the localization a field. ## References * https://en.wikipedia.org/wiki/Fractional_ideal ## Tags fractional ideal, fractional ideals, invertible ideal -/ open IsLocalization Pointwise nonZeroDivisors section Defs variable {R : Type*} [CommRing R] {S : Submonoid R} {P : Type*} [CommRing P] variable [Algebra R P] variable (S) /-- A submodule `I` is a fractional ideal if `a I ⊆ R` for some `a ≠ 0`. -/ def IsFractional (I : Submodule R P) := ∃ a ∈ S, ∀ b ∈ I, IsInteger R (a • b) variable (P) /-- The fractional ideals of a domain `R` are ideals of `R` divided by some `a ∈ R`. More precisely, let `P` be a localization of `R` at some submonoid `S`, then a fractional ideal `I ⊆ P` is an `R`-submodule of `P`, such that there is a nonzero `a : R` with `a I ⊆ R`. -/ def FractionalIdeal := { I : Submodule R P // IsFractional S I } end Defs namespace FractionalIdeal open Set Submodule variable {R : Type*} [CommRing R] {S : Submonoid R} {P : Type*} [CommRing P] variable [Algebra R P] /-- Map a fractional ideal `I` to a submodule by forgetting that `∃ a, a I ⊆ R`. This implements the coercion `FractionalIdeal S P → Submodule R P`. -/ @[coe] def coeToSubmodule (I : FractionalIdeal S P) : Submodule R P := I.val /-- Map a fractional ideal `I` to a submodule by forgetting that `∃ a, a I ⊆ R`. This coercion is typically called `coeToSubmodule` in lemma names (or `coe` when the coercion is clear from the context), not to be confused with `IsLocalization.coeSubmodule : Ideal R → Submodule R P` (which we use to define `coe : Ideal R → FractionalIdeal S P`). -/ instance : CoeOut (FractionalIdeal S P) (Submodule R P) := ⟨coeToSubmodule⟩ protected theorem isFractional (I : FractionalIdeal S P) : IsFractional S (I : Submodule R P) := I.prop /-- An element of `S` such that `I.den • I = I.num`, see `FractionalIdeal.num` and `FractionalIdeal.den_mul_self_eq_num`. -/ noncomputable def den (I : FractionalIdeal S P) : S := ⟨I.2.choose, I.2.choose_spec.1⟩ /-- An ideal of `R` such that `I.den • I = I.num`, see `FractionalIdeal.den` and `FractionalIdeal.den_mul_self_eq_num`. -/ noncomputable def num (I : FractionalIdeal S P) : Ideal R := (I.den • (I : Submodule R P)).comap (Algebra.linearMap R P) theorem den_mul_self_eq_num (I : FractionalIdeal S P) : I.den • (I : Submodule R P) = Submodule.map (Algebra.linearMap R P) I.num := by rw [den, num, Submodule.map_comap_eq] refine (inf_of_le_right ?_).symm rintro _ ⟨a, ha, rfl⟩ exact I.2.choose_spec.2 a ha /-- The linear equivalence between the fractional ideal `I` and the integral ideal `I.num` defined by mapping `x` to `den I • x`. -/ noncomputable def equivNum [Nontrivial P] [NoZeroSMulDivisors R P] {I : FractionalIdeal S P} (h_nz : (I.den : R) ≠ 0) : I ≃ₗ[R] I.num := by refine LinearEquiv.trans (LinearEquiv.ofBijective ((DistribMulAction.toLinearMap R P I.den).restrict fun _ hx ↦ ?_) ⟨fun _ _ hxy ↦ ?_, fun ⟨y, hy⟩ ↦ ?_⟩) (Submodule.equivMapOfInjective (Algebra.linearMap R P) (FaithfulSMul.algebraMap_injective R P) (num I)).symm · rw [← den_mul_self_eq_num] exact Submodule.smul_mem_pointwise_smul _ _ _ hx · simp_rw [LinearMap.restrict_apply, DistribMulAction.toLinearMap_apply, Subtype.mk.injEq] at hxy rwa [Submonoid.smul_def, Submonoid.smul_def, smul_right_inj h_nz, SetCoe.ext_iff] at hxy · rw [← den_mul_self_eq_num] at hy obtain ⟨x, hx, hxy⟩ := hy exact ⟨⟨x, hx⟩, by simp_rw [LinearMap.restrict_apply, Subtype.ext_iff, ← hxy]; rfl⟩ section SetLike instance : SetLike (FractionalIdeal S P) P where coe I := ↑(I : Submodule R P) coe_injective' := SetLike.coe_injective.comp Subtype.coe_injective @[simp] theorem mem_coe {I : FractionalIdeal S P} {x : P} : x ∈ (I : Submodule R P) ↔ x ∈ I := Iff.rfl @[ext] theorem ext {I J : FractionalIdeal S P} : (∀ x, x ∈ I ↔ x ∈ J) → I = J := SetLike.ext @[simp] theorem equivNum_apply [Nontrivial P] [NoZeroSMulDivisors R P] {I : FractionalIdeal S P} (h_nz : (I.den : R) ≠ 0) (x : I) : algebraMap R P (equivNum h_nz x) = I.den • x := by change Algebra.linearMap R P _ = _ rw [equivNum, LinearEquiv.trans_apply, LinearEquiv.ofBijective_apply, LinearMap.restrict_apply, Submodule.map_equivMapOfInjective_symm_apply, Subtype.coe_mk, DistribMulAction.toLinearMap_apply] /-- Copy of a `FractionalIdeal` with a new underlying set equal to the old one. Useful to fix definitional equalities. -/ protected def copy (p : FractionalIdeal S P) (s : Set P) (hs : s = ↑p) : FractionalIdeal S P := ⟨Submodule.copy p s hs, by convert p.isFractional ext simp only [hs] rfl⟩ @[simp] theorem coe_copy (p : FractionalIdeal S P) (s : Set P) (hs : s = ↑p) : ↑(p.copy s hs) = s := rfl theorem coe_eq (p : FractionalIdeal S P) (s : Set P) (hs : s = ↑p) : p.copy s hs = p := SetLike.coe_injective hs end SetLike lemma zero_mem (I : FractionalIdeal S P) : 0 ∈ I := I.coeToSubmodule.zero_mem -- Porting note: this seems to be needed a lot more than in Lean 3 @[simp] theorem val_eq_coe (I : FractionalIdeal S P) : I.val = I := rfl -- Porting note: had to rephrase this to make it clear to `simp` what was going on. @[simp, norm_cast] theorem coe_mk (I : Submodule R P) (hI : IsFractional S I) : coeToSubmodule ⟨I, hI⟩ = I := rfl theorem coeToSet_coeToSubmodule (I : FractionalIdeal S P) : ((I : Submodule R P) : Set P) = I := rfl /-! Transfer instances from `Submodule R P` to `FractionalIdeal S P`. -/ instance (I : FractionalIdeal S P) : Module R I := Submodule.module (I : Submodule R P) theorem coeToSubmodule_injective : Function.Injective (fun (I : FractionalIdeal S P) ↦ (I : Submodule R P)) := Subtype.coe_injective theorem coeToSubmodule_inj {I J : FractionalIdeal S P} : (I : Submodule R P) = J ↔ I = J := coeToSubmodule_injective.eq_iff theorem isFractional_of_le_one (I : Submodule R P) (h : I ≤ 1) : IsFractional S I := by use 1, S.one_mem intro b hb rw [one_smul] obtain ⟨b', b'_mem, rfl⟩ := mem_one.mp (h hb) exact Set.mem_range_self b' theorem isFractional_of_le {I : Submodule R P} {J : FractionalIdeal S P} (hIJ : I ≤ J) : IsFractional S I := by obtain ⟨a, a_mem, ha⟩ := J.isFractional use a, a_mem intro b b_mem exact ha b (hIJ b_mem) /-- Map an ideal `I` to a fractional ideal by forgetting `I` is integral. This is the function that implements the coercion `Ideal R → FractionalIdeal S P`. -/ @[coe] def coeIdeal (I : Ideal R) : FractionalIdeal S P := ⟨coeSubmodule P I, isFractional_of_le_one _ <| by simpa using coeSubmodule_mono P (le_top : I ≤ ⊤)⟩ -- Is a `CoeTC` rather than `Coe` to speed up failing inference, see library note [use has_coe_t] /-- Map an ideal `I` to a fractional ideal by forgetting `I` is integral. This is a bundled version of `IsLocalization.coeSubmodule : Ideal R → Submodule R P`, which is not to be confused with the `coe : FractionalIdeal S P → Submodule R P`, also called `coeToSubmodule` in theorem names. This map is available as a ring hom, called `FractionalIdeal.coeIdealHom`. -/ instance : CoeTC (Ideal R) (FractionalIdeal S P) := ⟨fun I => coeIdeal I⟩ @[simp, norm_cast] theorem coe_coeIdeal (I : Ideal R) : ((I : FractionalIdeal S P) : Submodule R P) = coeSubmodule P I := rfl variable (S) @[simp] theorem mem_coeIdeal {x : P} {I : Ideal R} : x ∈ (I : FractionalIdeal S P) ↔ ∃ x', x' ∈ I ∧ algebraMap R P x' = x := mem_coeSubmodule _ _ theorem mem_coeIdeal_of_mem {x : R} {I : Ideal R} (hx : x ∈ I) : algebraMap R P x ∈ (I : FractionalIdeal S P) := (mem_coeIdeal S).mpr ⟨x, hx, rfl⟩ theorem coeIdeal_le_coeIdeal' [IsLocalization S P] (h : S ≤ nonZeroDivisors R) {I J : Ideal R} : (I : FractionalIdeal S P) ≤ J ↔ I ≤ J := coeSubmodule_le_coeSubmodule h @[simp] theorem coeIdeal_le_coeIdeal (K : Type*) [CommRing K] [Algebra R K] [IsFractionRing R K] {I J : Ideal R} : (I : FractionalIdeal R⁰ K) ≤ J ↔ I ≤ J := IsFractionRing.coeSubmodule_le_coeSubmodule instance : Zero (FractionalIdeal S P) := ⟨(0 : Ideal R)⟩ @[simp] theorem mem_zero_iff {x : P} : x ∈ (0 : FractionalIdeal S P) ↔ x = 0 := ⟨fun ⟨x', x'_mem_zero, x'_eq_x⟩ => by have x'_eq_zero : x' = 0 := x'_mem_zero simp [x'_eq_x.symm, x'_eq_zero], fun hx => ⟨0, rfl, by simp [hx]⟩⟩ variable {S} @[simp, norm_cast] theorem coe_zero : ↑(0 : FractionalIdeal S P) = (⊥ : Submodule R P) := Submodule.ext fun _ => mem_zero_iff S @[simp, norm_cast] theorem coeIdeal_bot : ((⊥ : Ideal R) : FractionalIdeal S P) = 0 := rfl section variable [loc : IsLocalization S P] variable (P) in @[simp] theorem exists_mem_algebraMap_eq {x : R} {I : Ideal R} (h : S ≤ nonZeroDivisors R) : (∃ x', x' ∈ I ∧ algebraMap R P x' = algebraMap R P x) ↔ x ∈ I := ⟨fun ⟨_, hx', Eq⟩ => IsLocalization.injective _ h Eq ▸ hx', fun h => ⟨x, h, rfl⟩⟩ theorem coeIdeal_injective' (h : S ≤ nonZeroDivisors R) : Function.Injective (fun (I : Ideal R) ↦ (I : FractionalIdeal S P)) := fun _ _ h' => ((coeIdeal_le_coeIdeal' S h).mp h'.le).antisymm ((coeIdeal_le_coeIdeal' S h).mp h'.ge) theorem coeIdeal_inj' (h : S ≤ nonZeroDivisors R) {I J : Ideal R} : (I : FractionalIdeal S P) = J ↔ I = J := (coeIdeal_injective' h).eq_iff -- Porting note: doesn't need to be @[simp] because it can be proved by coeIdeal_eq_zero theorem coeIdeal_eq_zero' {I : Ideal R} (h : S ≤ nonZeroDivisors R) : (I : FractionalIdeal S P) = 0 ↔ I = (⊥ : Ideal R) := coeIdeal_inj' h theorem coeIdeal_ne_zero' {I : Ideal R} (h : S ≤ nonZeroDivisors R) : (I : FractionalIdeal S P) ≠ 0 ↔ I ≠ (⊥ : Ideal R) := not_iff_not.mpr <| coeIdeal_eq_zero' h end theorem coeToSubmodule_eq_bot {I : FractionalIdeal S P} : (I : Submodule R P) = ⊥ ↔ I = 0 := ⟨fun h => coeToSubmodule_injective (by simp [h]), fun h => by simp [h]⟩ theorem coeToSubmodule_ne_bot {I : FractionalIdeal S P} : ↑I ≠ (⊥ : Submodule R P) ↔ I ≠ 0 := not_iff_not.mpr coeToSubmodule_eq_bot instance : Inhabited (FractionalIdeal S P) := ⟨0⟩ instance : One (FractionalIdeal S P) := ⟨(⊤ : Ideal R)⟩ theorem zero_of_num_eq_bot [NoZeroSMulDivisors R P] (hS : 0 ∉ S) {I : FractionalIdeal S P} (hI : I.num = ⊥) : I = 0 := by rw [← coeToSubmodule_eq_bot, eq_bot_iff] intro x hx suffices (den I : R) • x = 0 from (smul_eq_zero.mp this).resolve_left (ne_of_mem_of_not_mem (SetLike.coe_mem _) hS) have h_eq : I.den • (I : Submodule R P) = ⊥ := by rw [den_mul_self_eq_num, hI, Submodule.map_bot] exact (Submodule.eq_bot_iff _).mp h_eq (den I • x) ⟨x, hx, rfl⟩ theorem num_zero_eq (h_inj : Function.Injective (algebraMap R P)) : num (0 : FractionalIdeal S P) = 0 := by simpa [num, LinearMap.ker_eq_bot] using h_inj variable (S) @[simp, norm_cast] theorem coeIdeal_top : ((⊤ : Ideal R) : FractionalIdeal S P) = 1 := rfl theorem mem_one_iff {x : P} : x ∈ (1 : FractionalIdeal S P) ↔ ∃ x' : R, algebraMap R P x' = x := Iff.intro (fun ⟨x', _, h⟩ => ⟨x', h⟩) fun ⟨x', h⟩ => ⟨x', ⟨⟩, h⟩ theorem coe_mem_one (x : R) : algebraMap R P x ∈ (1 : FractionalIdeal S P) := (mem_one_iff S).mpr ⟨x, rfl⟩ theorem one_mem_one : (1 : P) ∈ (1 : FractionalIdeal S P) := (mem_one_iff S).mpr ⟨1, RingHom.map_one _⟩ variable {S} /-- `(1 : FractionalIdeal S P)` is defined as the R-submodule `f(R) ≤ P`. However, this is not definitionally equal to `1 : Submodule R P`, which is proved in the actual `simp` lemma `coe_one`. -/ theorem coe_one_eq_coeSubmodule_top : ↑(1 : FractionalIdeal S P) = coeSubmodule P (⊤ : Ideal R) := rfl @[simp, norm_cast] theorem coe_one : (↑(1 : FractionalIdeal S P) : Submodule R P) = 1 := by rw [coe_one_eq_coeSubmodule_top, coeSubmodule_top] section Lattice /-! ### `Lattice` section Defines the order on fractional ideals as inclusion of their underlying sets, and ports the lattice structure on submodules to fractional ideals. -/ @[simp] theorem coe_le_coe {I J : FractionalIdeal S P} : (I : Submodule R P) ≤ (J : Submodule R P) ↔ I ≤ J := Iff.rfl theorem zero_le (I : FractionalIdeal S P) : 0 ≤ I := by intro x hx -- Porting note: changed the proof from convert; simp into rw; exact rw [(mem_zero_iff _).mp hx] exact zero_mem I instance orderBot : OrderBot (FractionalIdeal S P) where bot := 0 bot_le := zero_le @[simp] theorem bot_eq_zero : (⊥ : FractionalIdeal S P) = 0 := rfl @[simp] theorem le_zero_iff {I : FractionalIdeal S P} : I ≤ 0 ↔ I = 0 := le_bot_iff theorem eq_zero_iff {I : FractionalIdeal S P} : I = 0 ↔ ∀ x ∈ I, x = (0 : P) := ⟨fun h x hx => by simpa [h, mem_zero_iff] using hx, fun h => le_bot_iff.mp fun x hx => (mem_zero_iff S).mpr (h x hx)⟩ theorem _root_.IsFractional.sup {I J : Submodule R P} : IsFractional S I → IsFractional S J → IsFractional S (I ⊔ J) | ⟨aI, haI, hI⟩, ⟨aJ, haJ, hJ⟩ => ⟨aI * aJ, S.mul_mem haI haJ, fun b hb => by rcases mem_sup.mp hb with ⟨bI, hbI, bJ, hbJ, rfl⟩ rw [smul_add] apply isInteger_add · rw [mul_smul, smul_comm] exact isInteger_smul (hI bI hbI) · rw [mul_smul] exact isInteger_smul (hJ bJ hbJ)⟩ theorem _root_.IsFractional.inf_right {I : Submodule R P} : IsFractional S I → ∀ J, IsFractional S (I ⊓ J) | ⟨aI, haI, hI⟩, J => ⟨aI, haI, fun b hb => by rcases mem_inf.mp hb with ⟨hbI, _⟩ exact hI b hbI⟩ instance : Min (FractionalIdeal S P) := ⟨fun I J => ⟨I ⊓ J, I.isFractional.inf_right J⟩⟩ @[simp, norm_cast] theorem coe_inf (I J : FractionalIdeal S P) : ↑(I ⊓ J) = (I ⊓ J : Submodule R P) := rfl instance : Max (FractionalIdeal S P) := ⟨fun I J => ⟨I ⊔ J, I.isFractional.sup J.isFractional⟩⟩ @[norm_cast] theorem coe_sup (I J : FractionalIdeal S P) : ↑(I ⊔ J) = (I ⊔ J : Submodule R P) := rfl instance lattice : Lattice (FractionalIdeal S P) := Function.Injective.lattice _ Subtype.coe_injective coe_sup coe_inf instance : SemilatticeSup (FractionalIdeal S P) := { FractionalIdeal.lattice with } end Lattice section Semiring instance : Add (FractionalIdeal S P) := ⟨(· ⊔ ·)⟩ @[simp] theorem sup_eq_add (I J : FractionalIdeal S P) : I ⊔ J = I + J := rfl @[simp, norm_cast] theorem coe_add (I J : FractionalIdeal S P) : (↑(I + J) : Submodule R P) = I + J := rfl theorem mem_add (I J : FractionalIdeal S P) (x : P) : x ∈ I + J ↔ ∃ i ∈ I, ∃ j ∈ J, i + j = x := by rw [← mem_coe, coe_add, Submodule.add_eq_sup]; exact Submodule.mem_sup @[simp, norm_cast] theorem coeIdeal_sup (I J : Ideal R) : ↑(I ⊔ J) = (I + J : FractionalIdeal S P) := coeToSubmodule_injective <| coeSubmodule_sup _ _ _ theorem _root_.IsFractional.nsmul {I : Submodule R P} : ∀ n : ℕ, IsFractional S I → IsFractional S (n • I : Submodule R P) | 0, _ => by rw [zero_smul] convert ((0 : Ideal R) : FractionalIdeal S P).isFractional simp | n + 1, h => by rw [succ_nsmul] exact (IsFractional.nsmul n h).sup h instance : SMul ℕ (FractionalIdeal S P) where smul n I := ⟨n • ↑I, I.isFractional.nsmul n⟩ @[norm_cast] theorem coe_nsmul (n : ℕ) (I : FractionalIdeal S P) : (↑(n • I) : Submodule R P) = n • (I : Submodule R P) := rfl theorem _root_.IsFractional.mul {I J : Submodule R P} : IsFractional S I → IsFractional S J → IsFractional S (I * J : Submodule R P) | ⟨aI, haI, hI⟩, ⟨aJ, haJ, hJ⟩ => ⟨aI * aJ, S.mul_mem haI haJ, fun b hb => by refine Submodule.mul_induction_on hb ?_ ?_ · intro m hm n hn obtain ⟨n', hn'⟩ := hJ n hn rw [mul_smul, mul_comm m, ← smul_mul_assoc, ← hn', ← Algebra.smul_def] apply hI exact Submodule.smul_mem _ _ hm · intro x y hx hy rw [smul_add] apply isInteger_add hx hy⟩ theorem _root_.IsFractional.pow {I : Submodule R P} (h : IsFractional S I) : ∀ n : ℕ, IsFractional S (I ^ n : Submodule R P) | 0 => isFractional_of_le_one _ (pow_zero _).le | n + 1 => (pow_succ I n).symm ▸ (IsFractional.pow h n).mul h /-- `FractionalIdeal.mul` is the product of two fractional ideals, used to define the `Mul` instance. This is only an auxiliary definition: the preferred way of writing `I.mul J` is `I * J`. Elaborated terms involving `FractionalIdeal` tend to grow quite large, so by making definitions irreducible, we hope to avoid deep unfolds. -/ irreducible_def mul (lemma := mul_def') (I J : FractionalIdeal S P) : FractionalIdeal S P := ⟨I * J, I.isFractional.mul J.isFractional⟩ -- local attribute [semireducible] mul instance : Mul (FractionalIdeal S P) := ⟨fun I J => mul I J⟩ @[simp] theorem mul_eq_mul (I J : FractionalIdeal S P) : mul I J = I * J := rfl theorem mul_def (I J : FractionalIdeal S P) : I * J = ⟨I * J, I.isFractional.mul J.isFractional⟩ := by simp only [← mul_eq_mul, mul_def'] @[simp, norm_cast] theorem coe_mul (I J : FractionalIdeal S P) : (↑(I * J) : Submodule R P) = I * J := by simp only [mul_def, coe_mk] @[simp, norm_cast] theorem coeIdeal_mul (I J : Ideal R) : (↑(I * J) : FractionalIdeal S P) = I * J := by simp only [mul_def] exact coeToSubmodule_injective (coeSubmodule_mul _ _ _) theorem mul_left_mono (I : FractionalIdeal S P) : Monotone (I * ·) := by intro J J' h simp only [mul_def] exact mul_le.mpr fun x hx y hy => mul_mem_mul hx (h hy) theorem mul_right_mono (I : FractionalIdeal S P) : Monotone fun J => J * I := by intro J J' h simp only [mul_def] exact mul_le.mpr fun x hx y hy => mul_mem_mul (h hx) hy theorem mul_mem_mul {I J : FractionalIdeal S P} {i j : P} (hi : i ∈ I) (hj : j ∈ J) : i * j ∈ I * J := by simp only [mul_def] exact Submodule.mul_mem_mul hi hj theorem mul_le {I J K : FractionalIdeal S P} : I * J ≤ K ↔ ∀ i ∈ I, ∀ j ∈ J, i * j ∈ K := by simp only [mul_def] exact Submodule.mul_le instance : Pow (FractionalIdeal S P) ℕ := ⟨fun I n => ⟨(I : Submodule R P) ^ n, I.isFractional.pow n⟩⟩ @[simp, norm_cast] theorem coe_pow (I : FractionalIdeal S P) (n : ℕ) : ↑(I ^ n) = (I : Submodule R P) ^ n := rfl @[elab_as_elim] protected theorem mul_induction_on {I J : FractionalIdeal S P} {C : P → Prop} {r : P} (hr : r ∈ I * J) (hm : ∀ i ∈ I, ∀ j ∈ J, C (i * j)) (ha : ∀ x y, C x → C y → C (x + y)) : C r := by simp only [mul_def] at hr exact Submodule.mul_induction_on hr hm ha instance : NatCast (FractionalIdeal S P) := ⟨Nat.unaryCast⟩ theorem coe_natCast (n : ℕ) : ((n : FractionalIdeal S P) : Submodule R P) = n := show ((n.unaryCast : FractionalIdeal S P) : Submodule R P) = n by induction n <;> simp [*, Nat.unaryCast] instance commSemiring : CommSemiring (FractionalIdeal S P) := Function.Injective.commSemiring _ Subtype.coe_injective coe_zero coe_one coe_add coe_mul (fun _ _ => coe_nsmul _ _) coe_pow coe_natCast end Semiring variable (S P) /-- `FractionalIdeal.coeToSubmodule` as a bundled `RingHom`. -/ @[simps] def coeSubmoduleHom : FractionalIdeal S P →+* Submodule R P where toFun := coeToSubmodule map_one' := coe_one map_mul' := coe_mul map_zero' := coe_zero (S := S) map_add' := coe_add variable {S P} section Order theorem add_le_add_left {I J : FractionalIdeal S P} (hIJ : I ≤ J) (J' : FractionalIdeal S P) : J' + I ≤ J' + J := sup_le_sup_left hIJ J' theorem mul_le_mul_left {I J : FractionalIdeal S P} (hIJ : I ≤ J) (J' : FractionalIdeal S P) : J' * I ≤ J' * J := mul_le.mpr fun _ hk _ hj => mul_mem_mul hk (hIJ hj) theorem le_self_mul_self {I : FractionalIdeal S P} (hI : 1 ≤ I) : I ≤ I * I := by convert mul_left_mono I hI exact (mul_one I).symm theorem mul_self_le_self {I : FractionalIdeal S P} (hI : I ≤ 1) : I * I ≤ I := by convert mul_left_mono I hI exact (mul_one I).symm theorem coeIdeal_le_one {I : Ideal R} : (I : FractionalIdeal S P) ≤ 1 := fun _ hx => let ⟨y, _, hy⟩ := (mem_coeIdeal S).mp hx (mem_one_iff S).mpr ⟨y, hy⟩ theorem le_one_iff_exists_coeIdeal {J : FractionalIdeal S P} : J ≤ (1 : FractionalIdeal S P) ↔ ∃ I : Ideal R, ↑I = J := by constructor · intro hJ refine ⟨⟨⟨⟨{ x : R | algebraMap R P x ∈ J }, ?_⟩, ?_⟩, ?_⟩, ?_⟩
· intro a b ha hb rw [mem_setOf, RingHom.map_add] exact J.val.add_mem ha hb · rw [mem_setOf, RingHom.map_zero] exact J.zero_mem
Mathlib/RingTheory/FractionalIdeal/Basic.lean
626
630
/- Copyright (c) 2022 Violeta Hernández Palacios. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Violeta Hernández Palacios -/ import Mathlib.SetTheory.Ordinal.Family import Mathlib.Tactic.Abel /-! # Natural operations on ordinals The goal of this file is to define natural addition and multiplication on ordinals, also known as the Hessenberg sum and product, and provide a basic API. The natural addition of two ordinals `a ♯ b` is recursively defined as the least ordinal greater than `a' ♯ b` and `a ♯ b'` for `a' < a` and `b' < b`. The natural multiplication `a ⨳ b` is likewise recursively defined as the least ordinal such that `a ⨳ b ♯ a' ⨳ b'` is greater than `a' ⨳ b ♯ a ⨳ b'` for any `a' < a` and `b' < b`. These operations form a rich algebraic structure: they're commutative, associative, preserve order, have the usual `0` and `1` from ordinals, and distribute over one another. Moreover, these operations are the addition and multiplication of ordinals when viewed as combinatorial `Game`s. This makes them particularly useful for game theory. Finally, both operations admit simple, intuitive descriptions in terms of the Cantor normal form. The natural addition of two ordinals corresponds to adding their Cantor normal forms as if they were polynomials in `ω`. Likewise, their natural multiplication corresponds to multiplying the Cantor normal forms as polynomials. ## Implementation notes Given the rich algebraic structure of these two operations, we choose to create a type synonym `NatOrdinal`, where we provide the appropriate instances. However, to avoid casting back and forth between both types, we attempt to prove and state most results on `Ordinal`. ## Todo - Prove the characterizations of natural addition and multiplication in terms of the Cantor normal form. -/ universe u v open Function Order Set noncomputable section /-! ### Basic casts between `Ordinal` and `NatOrdinal` -/ /-- A type synonym for ordinals with natural addition and multiplication. -/ def NatOrdinal : Type _ := Ordinal deriving Zero, Inhabited, One, WellFoundedRelation -- The `LinearOrder, `SuccOrder` instances should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 instance NatOrdinal.instLinearOrder : LinearOrder NatOrdinal := Ordinal.instLinearOrder instance NatOrdinal.instSuccOrder : SuccOrder NatOrdinal := Ordinal.instSuccOrder instance NatOrdinal.instOrderBot : OrderBot NatOrdinal := Ordinal.instOrderBot instance NatOrdinal.instNoMaxOrder : NoMaxOrder NatOrdinal := Ordinal.instNoMaxOrder instance NatOrdinal.instZeroLEOneClass : ZeroLEOneClass NatOrdinal := Ordinal.instZeroLEOneClass instance NatOrdinal.instNeZeroOne : NeZero (1 : NatOrdinal) := Ordinal.instNeZeroOne instance NatOrdinal.uncountable : Uncountable NatOrdinal := Ordinal.uncountable /-- The identity function between `Ordinal` and `NatOrdinal`. -/ @[match_pattern] def Ordinal.toNatOrdinal : Ordinal ≃o NatOrdinal := OrderIso.refl _ /-- The identity function between `NatOrdinal` and `Ordinal`. -/ @[match_pattern] def NatOrdinal.toOrdinal : NatOrdinal ≃o Ordinal := OrderIso.refl _ namespace NatOrdinal open Ordinal @[simp] theorem toOrdinal_symm_eq : NatOrdinal.toOrdinal.symm = Ordinal.toNatOrdinal := rfl @[simp] theorem toOrdinal_toNatOrdinal (a : NatOrdinal) : a.toOrdinal.toNatOrdinal = a := rfl theorem lt_wf : @WellFounded NatOrdinal (· < ·) := Ordinal.lt_wf instance : WellFoundedLT NatOrdinal := Ordinal.wellFoundedLT instance : ConditionallyCompleteLinearOrderBot NatOrdinal := WellFoundedLT.conditionallyCompleteLinearOrderBot _ @[simp] theorem bot_eq_zero : (⊥ : NatOrdinal) = 0 := rfl @[simp] theorem toOrdinal_zero : toOrdinal 0 = 0 := rfl @[simp] theorem toOrdinal_one : toOrdinal 1 = 1 := rfl @[simp] theorem toOrdinal_eq_zero {a} : toOrdinal a = 0 ↔ a = 0 := Iff.rfl @[simp] theorem toOrdinal_eq_one {a} : toOrdinal a = 1 ↔ a = 1 := Iff.rfl @[simp] theorem toOrdinal_max (a b : NatOrdinal) : toOrdinal (max a b) = max (toOrdinal a) (toOrdinal b) := rfl @[simp] theorem toOrdinal_min (a b : NatOrdinal) : toOrdinal (min a b) = min (toOrdinal a) (toOrdinal b) := rfl theorem succ_def (a : NatOrdinal) : succ a = toNatOrdinal (toOrdinal a + 1) := rfl @[simp] theorem zero_le (o : NatOrdinal) : 0 ≤ o := Ordinal.zero_le o theorem not_lt_zero (o : NatOrdinal) : ¬ o < 0 := Ordinal.not_lt_zero o @[simp] theorem lt_one_iff_zero {o : NatOrdinal} : o < 1 ↔ o = 0 := Ordinal.lt_one_iff_zero /-- A recursor for `NatOrdinal`. Use as `induction x`. -/ @[elab_as_elim, cases_eliminator, induction_eliminator] protected def rec {β : NatOrdinal → Sort*} (h : ∀ a, β (toNatOrdinal a)) : ∀ a, β a := fun a => h (toOrdinal a) /-- `Ordinal.induction` but for `NatOrdinal`. -/ theorem induction {p : NatOrdinal → Prop} : ∀ (i) (_ : ∀ j, (∀ k, k < j → p k) → p j), p i := Ordinal.induction instance small_Iio (a : NatOrdinal.{u}) : Small.{u} (Set.Iio a) := Ordinal.small_Iio a instance small_Iic (a : NatOrdinal.{u}) : Small.{u} (Set.Iic a) := Ordinal.small_Iic a instance small_Ico (a b : NatOrdinal.{u}) : Small.{u} (Set.Ico a b) := Ordinal.small_Ico a b instance small_Icc (a b : NatOrdinal.{u}) : Small.{u} (Set.Icc a b) := Ordinal.small_Icc a b instance small_Ioo (a b : NatOrdinal.{u}) : Small.{u} (Set.Ioo a b) := Ordinal.small_Ioo a b instance small_Ioc (a b : NatOrdinal.{u}) : Small.{u} (Set.Ioc a b) := Ordinal.small_Ioc a b end NatOrdinal namespace Ordinal variable {a b c : Ordinal.{u}} @[simp] theorem toNatOrdinal_symm_eq : toNatOrdinal.symm = NatOrdinal.toOrdinal := rfl @[simp] theorem toNatOrdinal_toOrdinal (a : Ordinal) : a.toNatOrdinal.toOrdinal = a := rfl @[simp] theorem toNatOrdinal_zero : toNatOrdinal 0 = 0 := rfl @[simp] theorem toNatOrdinal_one : toNatOrdinal 1 = 1 := rfl @[simp] theorem toNatOrdinal_eq_zero (a) : toNatOrdinal a = 0 ↔ a = 0 := Iff.rfl @[simp] theorem toNatOrdinal_eq_one (a) : toNatOrdinal a = 1 ↔ a = 1 := Iff.rfl @[simp] theorem toNatOrdinal_max (a b : Ordinal) : toNatOrdinal (max a b) = max (toNatOrdinal a) (toNatOrdinal b) := rfl @[simp] theorem toNatOrdinal_min (a b : Ordinal) : toNatOrdinal (min a b) = min (toNatOrdinal a) (toNatOrdinal b) := rfl /-! We place the definitions of `nadd` and `nmul` before actually developing their API, as this guarantees we only need to open the `NaturalOps` locale once. -/ /-- Natural addition on ordinals `a ♯ b`, also known as the Hessenberg sum, is recursively defined as the least ordinal greater than `a' ♯ b` and `a ♯ b'` for all `a' < a` and `b' < b`. In contrast to normal ordinal addition, it is commutative. Natural addition can equivalently be characterized as the ordinal resulting from adding up corresponding coefficients in the Cantor normal forms of `a` and `b`. -/ noncomputable def nadd (a b : Ordinal.{u}) : Ordinal.{u} := max (⨆ x : Iio a, succ (nadd x.1 b)) (⨆ x : Iio b, succ (nadd a x.1)) termination_by (a, b) decreasing_by all_goals cases x; decreasing_tactic @[inherit_doc] scoped[NaturalOps] infixl:65 " ♯ " => Ordinal.nadd open NaturalOps /-- Natural multiplication on ordinals `a ⨳ b`, also known as the Hessenberg product, is recursively defined as the least ordinal such that `a ⨳ b ♯ a' ⨳ b'` is greater than `a' ⨳ b ♯ a ⨳ b'` for all `a' < a` and `b < b'`. In contrast to normal ordinal multiplication, it is commutative and distributive (over natural addition). Natural multiplication can equivalently be characterized as the ordinal resulting from multiplying the Cantor normal forms of `a` and `b` as if they were polynomials in `ω`. Addition of exponents is done via natural addition. -/ noncomputable def nmul (a b : Ordinal.{u}) : Ordinal.{u} := sInf {c | ∀ a' < a, ∀ b' < b, nmul a' b ♯ nmul a b' < c ♯ nmul a' b'} termination_by (a, b) @[inherit_doc] scoped[NaturalOps] infixl:70 " ⨳ " => Ordinal.nmul /-! ### Natural addition -/ theorem lt_nadd_iff : a < b ♯ c ↔ (∃ b' < b, a ≤ b' ♯ c) ∨ ∃ c' < c, a ≤ b ♯ c' := by rw [nadd] simp [Ordinal.lt_iSup_iff] theorem nadd_le_iff : b ♯ c ≤ a ↔ (∀ b' < b, b' ♯ c < a) ∧ ∀ c' < c, b ♯ c' < a := by rw [← not_lt, lt_nadd_iff] simp theorem nadd_lt_nadd_left (h : b < c) (a) : a ♯ b < a ♯ c := lt_nadd_iff.2 (Or.inr ⟨b, h, le_rfl⟩) theorem nadd_lt_nadd_right (h : b < c) (a) : b ♯ a < c ♯ a := lt_nadd_iff.2 (Or.inl ⟨b, h, le_rfl⟩) theorem nadd_le_nadd_left (h : b ≤ c) (a) : a ♯ b ≤ a ♯ c := by rcases lt_or_eq_of_le h with (h | rfl) · exact (nadd_lt_nadd_left h a).le · exact le_rfl theorem nadd_le_nadd_right (h : b ≤ c) (a) : b ♯ a ≤ c ♯ a := by rcases lt_or_eq_of_le h with (h | rfl) · exact (nadd_lt_nadd_right h a).le · exact le_rfl variable (a b) theorem nadd_comm (a b) : a ♯ b = b ♯ a := by rw [nadd, nadd, max_comm] congr <;> ext x <;> cases x <;> apply congr_arg _ (nadd_comm _ _) termination_by (a, b) @[deprecated "blsub will soon be deprecated" (since := "2024-11-18")] theorem blsub_nadd_of_mono {f : ∀ c < a ♯ b, Ordinal.{max u v}} (hf : ∀ {i j} (hi hj), i ≤ j → f i hi ≤ f j hj) : blsub.{u,v} _ f = max (blsub.{u, v} a fun a' ha' => f (a' ♯ b) <| nadd_lt_nadd_right ha' b) (blsub.{u, v} b fun b' hb' => f (a ♯ b') <| nadd_lt_nadd_left hb' a) := by apply (blsub_le_iff.2 fun i h => _).antisymm (max_le _ _) · intro i h rcases lt_nadd_iff.1 h with (⟨a', ha', hi⟩ | ⟨b', hb', hi⟩) · exact lt_max_of_lt_left ((hf h (nadd_lt_nadd_right ha' b) hi).trans_lt (lt_blsub _ _ ha')) · exact lt_max_of_lt_right ((hf h (nadd_lt_nadd_left hb' a) hi).trans_lt (lt_blsub _ _ hb')) all_goals apply blsub_le_of_brange_subset.{u, u, v} rintro c ⟨d, hd, rfl⟩ apply mem_brange_self private theorem iSup_nadd_of_monotone {a b} (f : Ordinal.{u} → Ordinal.{u}) (h : Monotone f) : ⨆ x : Iio (a ♯ b), f x = max (⨆ a' : Iio a, f (a'.1 ♯ b)) (⨆ b' : Iio b, f (a ♯ b'.1)) := by apply (max_le _ _).antisymm' · rw [Ordinal.iSup_le_iff] rintro ⟨i, hi⟩ obtain ⟨x, hx, hi⟩ | ⟨x, hx, hi⟩ := lt_nadd_iff.1 hi · exact le_max_of_le_left ((h hi).trans <| Ordinal.le_iSup (fun x : Iio a ↦ _) ⟨x, hx⟩) · exact le_max_of_le_right ((h hi).trans <| Ordinal.le_iSup (fun x : Iio b ↦ _) ⟨x, hx⟩) all_goals apply csSup_le_csSup' (bddAbove_of_small _) rintro _ ⟨⟨c, hc⟩, rfl⟩ refine mem_range_self (⟨_, ?_⟩ : Iio _) apply_rules [nadd_lt_nadd_left, nadd_lt_nadd_right] theorem nadd_assoc (a b c) : a ♯ b ♯ c = a ♯ (b ♯ c) := by unfold nadd rw [iSup_nadd_of_monotone fun a' ↦ succ (a' ♯ c), iSup_nadd_of_monotone fun b' ↦ succ (a ♯ b'), max_assoc] · congr <;> ext x <;> cases x <;> apply congr_arg _ (nadd_assoc _ _ _) · exact succ_mono.comp fun x y h ↦ nadd_le_nadd_left h _ · exact succ_mono.comp fun x y h ↦ nadd_le_nadd_right h _ termination_by (a, b, c) @[simp] theorem nadd_zero (a : Ordinal) : a ♯ 0 = a := by rw [nadd, ciSup_of_empty fun _ : Iio 0 ↦ _, sup_bot_eq] convert iSup_succ a rename_i x cases x exact nadd_zero _ termination_by a @[simp] theorem zero_nadd : 0 ♯ a = a := by rw [nadd_comm, nadd_zero] @[simp] theorem nadd_one (a : Ordinal) : a ♯ 1 = succ a := by rw [nadd, ciSup_unique (s := fun _ : Iio 1 ↦ _), Iio_one_default_eq, nadd_zero, max_eq_right_iff, Ordinal.iSup_le_iff] rintro ⟨i, hi⟩ rwa [nadd_one, succ_le_succ_iff, succ_le_iff] termination_by a @[simp] theorem one_nadd : 1 ♯ a = succ a := by rw [nadd_comm, nadd_one] theorem nadd_succ : a ♯ succ b = succ (a ♯ b) := by rw [← nadd_one (a ♯ b), nadd_assoc, nadd_one] theorem succ_nadd : succ a ♯ b = succ (a ♯ b) := by rw [← one_nadd (a ♯ b), ← nadd_assoc, one_nadd] @[simp] theorem nadd_nat (n : ℕ) : a ♯ n = a + n := by induction' n with n hn · simp · rw [Nat.cast_succ, add_one_eq_succ, nadd_succ, add_succ, hn] @[simp] theorem nat_nadd (n : ℕ) : ↑n ♯ a = a + n := by rw [nadd_comm, nadd_nat] theorem add_le_nadd : a + b ≤ a ♯ b := by induction b using limitRecOn with | zero => simp | succ c h => rwa [add_succ, nadd_succ, succ_le_succ_iff] | isLimit c hc H => rw [(isNormal_add_right a).apply_of_isLimit hc, Ordinal.iSup_le_iff] rintro ⟨i, hi⟩ exact (H i hi).trans (nadd_le_nadd_left hi.le a) end Ordinal namespace NatOrdinal open Ordinal NaturalOps instance : Add NatOrdinal := ⟨nadd⟩ instance : SuccAddOrder NatOrdinal := ⟨fun x => (nadd_one x).symm⟩ theorem lt_add_iff {a b c : NatOrdinal} : a < b + c ↔ (∃ b' < b, a ≤ b' + c) ∨ ∃ c' < c, a ≤ b + c' := Ordinal.lt_nadd_iff theorem add_le_iff {a b c : NatOrdinal} : b + c ≤ a ↔ (∀ b' < b, b' + c < a) ∧ ∀ c' < c, b + c' < a := Ordinal.nadd_le_iff instance : AddLeftStrictMono NatOrdinal.{u} := ⟨fun a _ _ h => nadd_lt_nadd_left h a⟩ instance : AddLeftMono NatOrdinal.{u} := ⟨fun a _ _ h => nadd_le_nadd_left h a⟩ instance : AddLeftReflectLE NatOrdinal.{u} := ⟨fun a b c h => by by_contra! h' exact h.not_lt (add_lt_add_left h' a)⟩ instance : AddCommMonoid NatOrdinal := { add := (· + ·) add_assoc := nadd_assoc zero := 0 zero_add := zero_nadd add_zero := nadd_zero add_comm := nadd_comm nsmul := nsmulRec } instance : IsOrderedCancelAddMonoid NatOrdinal := { add_le_add_left := fun _ _ => add_le_add_left le_of_add_le_add_left := fun _ _ _ => le_of_add_le_add_left } instance : AddMonoidWithOne NatOrdinal := AddMonoidWithOne.unary @[simp] theorem toOrdinal_natCast (n : ℕ) : toOrdinal n = n := by induction' n with n hn · rfl · change (toOrdinal n) ♯ 1 = n + 1 rw [hn]; exact nadd_one n instance : CharZero NatOrdinal where cast_injective m n h := by apply_fun toOrdinal at h simpa using h end NatOrdinal open NatOrdinal open NaturalOps namespace Ordinal theorem nadd_eq_add (a b : Ordinal) : a ♯ b = toOrdinal (toNatOrdinal a + toNatOrdinal b) := rfl @[simp] theorem toNatOrdinal_natCast (n : ℕ) : toNatOrdinal n = n := by rw [← toOrdinal_natCast n] rfl theorem lt_of_nadd_lt_nadd_left : ∀ {a b c}, a ♯ b < a ♯ c → b < c := @lt_of_add_lt_add_left NatOrdinal _ _ _ theorem lt_of_nadd_lt_nadd_right : ∀ {a b c}, b ♯ a < c ♯ a → b < c := @lt_of_add_lt_add_right NatOrdinal _ _ _ theorem le_of_nadd_le_nadd_left : ∀ {a b c}, a ♯ b ≤ a ♯ c → b ≤ c := @le_of_add_le_add_left NatOrdinal _ _ _ theorem le_of_nadd_le_nadd_right : ∀ {a b c}, b ♯ a ≤ c ♯ a → b ≤ c := @le_of_add_le_add_right NatOrdinal _ _ _ @[simp] theorem nadd_lt_nadd_iff_left : ∀ (a) {b c}, a ♯ b < a ♯ c ↔ b < c := @add_lt_add_iff_left NatOrdinal _ _ _ _ @[simp] theorem nadd_lt_nadd_iff_right : ∀ (a) {b c}, b ♯ a < c ♯ a ↔ b < c := @add_lt_add_iff_right NatOrdinal _ _ _ _ @[simp] theorem nadd_le_nadd_iff_left : ∀ (a) {b c}, a ♯ b ≤ a ♯ c ↔ b ≤ c := @add_le_add_iff_left NatOrdinal _ _ _ _ @[simp] theorem nadd_le_nadd_iff_right : ∀ (a) {b c}, b ♯ a ≤ c ♯ a ↔ b ≤ c := @_root_.add_le_add_iff_right NatOrdinal _ _ _ _ theorem nadd_le_nadd : ∀ {a b c d}, a ≤ b → c ≤ d → a ♯ c ≤ b ♯ d := @add_le_add NatOrdinal _ _ _ _ theorem nadd_lt_nadd : ∀ {a b c d}, a < b → c < d → a ♯ c < b ♯ d := @add_lt_add NatOrdinal _ _ _ _ theorem nadd_lt_nadd_of_lt_of_le : ∀ {a b c d}, a < b → c ≤ d → a ♯ c < b ♯ d := @add_lt_add_of_lt_of_le NatOrdinal _ _ _ _ theorem nadd_lt_nadd_of_le_of_lt : ∀ {a b c d}, a ≤ b → c < d → a ♯ c < b ♯ d := @add_lt_add_of_le_of_lt NatOrdinal _ _ _ _ theorem nadd_left_cancel : ∀ {a b c}, a ♯ b = a ♯ c → b = c := @_root_.add_left_cancel NatOrdinal _ _ theorem nadd_right_cancel : ∀ {a b c}, a ♯ b = c ♯ b → a = c := @_root_.add_right_cancel NatOrdinal _ _ @[simp] theorem nadd_left_cancel_iff : ∀ {a b c}, a ♯ b = a ♯ c ↔ b = c := @add_left_cancel_iff NatOrdinal _ _ @[simp] theorem nadd_right_cancel_iff : ∀ {a b c}, b ♯ a = c ♯ a ↔ b = c := @add_right_cancel_iff NatOrdinal _ _ theorem le_nadd_self {a b} : a ≤ b ♯ a := by simpa using nadd_le_nadd_right (Ordinal.zero_le b) a theorem le_nadd_left {a b c} (h : a ≤ c) : a ≤ b ♯ c := le_nadd_self.trans (nadd_le_nadd_left h b) theorem le_self_nadd {a b} : a ≤ a ♯ b := by simpa using nadd_le_nadd_left (Ordinal.zero_le b) a theorem le_nadd_right {a b c} (h : a ≤ b) : a ≤ b ♯ c := le_self_nadd.trans (nadd_le_nadd_right h c) theorem nadd_left_comm : ∀ a b c, a ♯ (b ♯ c) = b ♯ (a ♯ c) := @add_left_comm NatOrdinal _ theorem nadd_right_comm : ∀ a b c, a ♯ b ♯ c = a ♯ c ♯ b := @add_right_comm NatOrdinal _ /-! ### Natural multiplication -/ variable {a b c d : Ordinal.{u}} @[deprecated "avoid using the definition of `nmul` directly" (since := "2024-11-19")] theorem nmul_def (a b : Ordinal) : a ⨳ b = sInf {c | ∀ a' < a, ∀ b' < b, a' ⨳ b ♯ a ⨳ b' < c ♯ a' ⨳ b'} := by rw [nmul] /-- The set in the definition of `nmul` is nonempty. -/ private theorem nmul_nonempty (a b : Ordinal.{u}) : {c : Ordinal.{u} | ∀ a' < a, ∀ b' < b, a' ⨳ b ♯ a ⨳ b' < c ♯ a' ⨳ b'}.Nonempty := by obtain ⟨c, hc⟩ : BddAbove ((fun x ↦ x.1 ⨳ b ♯ a ⨳ x.2) '' Set.Iio a ×ˢ Set.Iio b) := bddAbove_of_small _ exact ⟨_, fun x hx y hy ↦ (lt_succ_of_le <| hc <| Set.mem_image_of_mem _ <| Set.mk_mem_prod hx hy).trans_le le_self_nadd⟩ theorem nmul_nadd_lt {a' b' : Ordinal} (ha : a' < a) (hb : b' < b) : a' ⨳ b ♯ a ⨳ b' < a ⨳ b ♯ a' ⨳ b' := by conv_rhs => rw [nmul] exact csInf_mem (nmul_nonempty a b) a' ha b' hb theorem nmul_nadd_le {a' b' : Ordinal} (ha : a' ≤ a) (hb : b' ≤ b) : a' ⨳ b ♯ a ⨳ b' ≤ a ⨳ b ♯ a' ⨳ b' := by rcases lt_or_eq_of_le ha with (ha | rfl) · rcases lt_or_eq_of_le hb with (hb | rfl) · exact (nmul_nadd_lt ha hb).le · rw [nadd_comm] · exact le_rfl theorem lt_nmul_iff : c < a ⨳ b ↔ ∃ a' < a, ∃ b' < b, c ♯ a' ⨳ b' ≤ a' ⨳ b ♯ a ⨳ b' := by refine ⟨fun h => ?_, ?_⟩ · rw [nmul] at h simpa using not_mem_of_lt_csInf h ⟨0, fun _ _ => bot_le⟩ · rintro ⟨a', ha, b', hb, h⟩ have := h.trans_lt (nmul_nadd_lt ha hb) rwa [nadd_lt_nadd_iff_right] at this theorem nmul_le_iff : a ⨳ b ≤ c ↔ ∀ a' < a, ∀ b' < b, a' ⨳ b ♯ a ⨳ b' < c ♯ a' ⨳ b' := by rw [← not_iff_not]; simp [lt_nmul_iff] theorem nmul_comm (a b) : a ⨳ b = b ⨳ a := by rw [nmul, nmul] congr; ext x; constructor <;> intro H c hc d hd · rw [nadd_comm, ← nmul_comm, ← nmul_comm a, ← nmul_comm d] exact H _ hd _ hc · rw [nadd_comm, nmul_comm, nmul_comm c, nmul_comm c] exact H _ hd _ hc termination_by (a, b) @[simp] theorem nmul_zero (a) : a ⨳ 0 = 0 := by rw [← Ordinal.le_zero, nmul_le_iff] exact fun _ _ a ha => (Ordinal.not_lt_zero a ha).elim @[simp] theorem zero_nmul (a) : 0 ⨳ a = 0 := by rw [nmul_comm, nmul_zero] @[simp] theorem nmul_one (a : Ordinal) : a ⨳ 1 = a := by rw [nmul] convert csInf_Ici ext b refine ⟨fun H ↦ le_of_forall_lt (a := a) fun c hc ↦ ?_, fun ha c hc ↦ ?_⟩ -- Porting note: had to add arguments to `nmul_one` in the next two lines -- for the termination checker. · simpa [nmul_one c] using H c hc · simpa [nmul_one c] using hc.trans_le ha termination_by a @[simp] theorem one_nmul (a) : 1 ⨳ a = a := by rw [nmul_comm, nmul_one]
theorem nmul_lt_nmul_of_pos_left (h₁ : a < b) (h₂ : 0 < c) : c ⨳ a < c ⨳ b := lt_nmul_iff.2 ⟨0, h₂, a, h₁, by simp⟩ theorem nmul_lt_nmul_of_pos_right (h₁ : a < b) (h₂ : 0 < c) : a ⨳ c < b ⨳ c := lt_nmul_iff.2 ⟨a, h₁, 0, h₂, by simp⟩ theorem nmul_le_nmul_left (h : a ≤ b) (c) : c ⨳ a ≤ c ⨳ b := by
Mathlib/SetTheory/Ordinal/NaturalOps.lean
536
542
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad -/ import Mathlib.Logic.Basic import Mathlib.Logic.Function.Defs import Mathlib.Order.Defs.LinearOrder /-! # Booleans This file proves various trivial lemmas about booleans and their relation to decidable propositions. ## Tags bool, boolean, Bool, De Morgan -/ namespace Bool section /-! This section contains lemmas about booleans which were present in core Lean 3. The remainder of this file contains lemmas about booleans from mathlib 3. -/ theorem true_eq_false_eq_False : ¬true = false := by decide theorem false_eq_true_eq_False : ¬false = true := by decide theorem eq_false_eq_not_eq_true (b : Bool) : (¬b = true) = (b = false) := by simp theorem eq_true_eq_not_eq_false (b : Bool) : (¬b = false) = (b = true) := by simp theorem eq_false_of_not_eq_true {b : Bool} : ¬b = true → b = false := Eq.mp (eq_false_eq_not_eq_true b) theorem eq_true_of_not_eq_false {b : Bool} : ¬b = false → b = true := Eq.mp (eq_true_eq_not_eq_false b) theorem and_eq_true_eq_eq_true_and_eq_true (a b : Bool) : ((a && b) = true) = (a = true ∧ b = true) := by simp theorem or_eq_true_eq_eq_true_or_eq_true (a b : Bool) : ((a || b) = true) = (a = true ∨ b = true) := by simp theorem not_eq_true_eq_eq_false (a : Bool) : (not a = true) = (a = false) := by cases a <;> simp #adaptation_note /-- nightly-2024-03-05 this is no longer a simp lemma, as the LHS simplifies. -/ theorem and_eq_false_eq_eq_false_or_eq_false (a b : Bool) : ((a && b) = false) = (a = false ∨ b = false) := by cases a <;> cases b <;> simp theorem or_eq_false_eq_eq_false_and_eq_false (a b : Bool) : ((a || b) = false) = (a = false ∧ b = false) := by cases a <;> cases b <;> simp theorem not_eq_false_eq_eq_true (a : Bool) : (not a = false) = (a = true) := by cases a <;> simp theorem coe_false : ↑false = False := by simp theorem coe_true : ↑true = True := by simp theorem coe_sort_false : (false : Prop) = False := by simp theorem coe_sort_true : (true : Prop) = True := by simp theorem decide_iff (p : Prop) [d : Decidable p] : decide p = true ↔ p := by simp theorem decide_true {p : Prop} [Decidable p] : p → decide p := (decide_iff p).2 theorem of_decide_true {p : Prop} [Decidable p] : decide p → p := (decide_iff p).1 theorem bool_iff_false {b : Bool} : ¬b ↔ b = false := by cases b <;> decide theorem bool_eq_false {b : Bool} : ¬b → b = false := bool_iff_false.1 theorem decide_false_iff (p : Prop) {_ : Decidable p} : decide p = false ↔ ¬p := bool_iff_false.symm.trans (not_congr (decide_iff _)) theorem decide_false {p : Prop} [Decidable p] : ¬p → decide p = false := (decide_false_iff p).2 theorem of_decide_false {p : Prop} [Decidable p] : decide p = false → ¬p := (decide_false_iff p).1 theorem decide_congr {p q : Prop} [Decidable p] [Decidable q] (h : p ↔ q) : decide p = decide q := decide_eq_decide.mpr h theorem coe_xor_iff (a b : Bool) : xor a b ↔ Xor' (a = true) (b = true) := by cases a <;> cases b <;> decide end theorem dichotomy (b : Bool) : b = false ∨ b = true := by cases b <;> simp theorem not_ne_id : not ≠ id := fun h ↦ false_ne_true <| congrFun h true theorem or_inl {a b : Bool} (H : a) : a || b := by simp [H] theorem or_inr {a b : Bool} (H : b) : a || b := by cases a <;> simp [H] theorem and_elim_left : ∀ {a b : Bool}, a && b → a := by decide theorem and_intro : ∀ {a b : Bool}, a → b → a && b := by decide theorem and_elim_right : ∀ {a b : Bool}, a && b → b := by decide lemma eq_not_iff : ∀ {a b : Bool}, a = !b ↔ a ≠ b := by decide lemma not_eq_iff : ∀ {a b : Bool}, !a = b ↔ a ≠ b := by decide theorem ne_not {a b : Bool} : a ≠ !b ↔ a = b := not_eq_not lemma not_ne_self : ∀ b : Bool, (!b) ≠ b := by decide lemma self_ne_not : ∀ b : Bool, b ≠ !b := by decide lemma eq_or_eq_not : ∀ a b, a = b ∨ a = !b := by decide -- TODO naming issue: these two `not` are different. theorem not_iff_not : ∀ {b : Bool}, !b ↔ ¬b := by simp theorem eq_true_of_not_eq_false' {a : Bool} : !a = false → a = true := by cases a <;> decide theorem eq_false_of_not_eq_true' {a : Bool} : !a = true → a = false := by cases a <;> decide theorem bne_eq_xor : bne = xor := by funext a b; revert a b; decide attribute [simp] xor_assoc
Mathlib/Data/Bool/Basic.lean
141
141
/- 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.Order.CompleteLattice.Chain import Mathlib.Order.Minimal /-! # Zorn's lemmas This file proves several formulations of Zorn's Lemma. ## Variants The primary statement of Zorn's lemma is `exists_maximal_of_chains_bounded`. Then it is specialized to particular relations: * `(≤)` with `zorn_le` * `(⊆)` with `zorn_subset` * `(⊇)` with `zorn_superset` Lemma names carry modifiers: * `₀`: Quantifies over a set, as opposed to over a type. * `_nonempty`: Doesn't ask to prove that the empty chain is bounded and lets you give an element that will be smaller than the maximal element found (the maximal element is no smaller than any other element, but it can also be incomparable to some). ## How-to This file comes across as confusing to those who haven't yet used it, so here is a detailed walkthrough: 1. Know what relation on which type/set you're looking for. See Variants above. You can discharge some conditions to Zorn's lemma directly using a `_nonempty` variant. 2. Write down the definition of your type/set, put a `suffices ∃ m, ∀ a, m ≺ a → a ≺ m by ...` (or whatever you actually need) followed by an `apply some_version_of_zorn`. 3. Fill in the details. This is where you start talking about chains. A typical proof using Zorn could look like this ```lean lemma zorny_lemma : zorny_statement := by let s : Set α := {x | whatever x} suffices ∃ x ∈ s, ∀ y ∈ s, y ⊆ x → y = x by -- or with another operator xxx proof_post_zorn apply zorn_subset -- or another variant rintro c hcs hc obtain rfl | hcnemp := c.eq_empty_or_nonempty -- you might need to disjunct on c empty or not · exact ⟨edge_case_construction, proof_that_edge_case_construction_respects_whatever, proof_that_edge_case_construction_contains_all_stuff_in_c⟩ · exact ⟨construction, proof_that_construction_respects_whatever, proof_that_construction_contains_all_stuff_in_c⟩ ``` ## Notes Originally ported from Isabelle/HOL. The [original file](https://isabelle.in.tum.de/dist/library/HOL/HOL/Zorn.html) was written by Jacques D. Fleuriot, Tobias Nipkow, Christian Sternagel. -/ open Set variable {α β : Type*} {r : α → α → Prop} {c : Set α} /-- Local notation for the relation being considered. -/ local infixl:50 " ≺ " => r /-- **Zorn's lemma** If every chain has an upper bound, then there exists a maximal element. -/ theorem exists_maximal_of_chains_bounded (h : ∀ c, IsChain r c → ∃ ub, ∀ a ∈ c, a ≺ ub) (trans : ∀ {a b c}, a ≺ b → b ≺ c → a ≺ c) : ∃ m, ∀ a, m ≺ a → a ≺ m := have : ∃ ub, ∀ a ∈ maxChain r, a ≺ ub := h _ <| maxChain_spec.left let ⟨ub, (hub : ∀ a ∈ maxChain r, a ≺ ub)⟩ := this ⟨ub, fun a ha => have : IsChain r (insert a <| maxChain r) := maxChain_spec.1.insert fun b hb _ => Or.inr <| trans (hub b hb) ha hub a <| by rw [maxChain_spec.right this (subset_insert _ _)] exact mem_insert _ _⟩ /-- A variant of Zorn's lemma. If every nonempty chain of a nonempty type has an upper bound, then there is a maximal element. -/ theorem exists_maximal_of_nonempty_chains_bounded [Nonempty α] (h : ∀ c, IsChain r c → c.Nonempty → ∃ ub, ∀ a ∈ c, a ≺ ub) (trans : ∀ {a b c}, a ≺ b → b ≺ c → a ≺ c) : ∃ m, ∀ a, m ≺ a → a ≺ m := exists_maximal_of_chains_bounded (fun c hc => (eq_empty_or_nonempty c).elim (fun h => ⟨Classical.arbitrary α, fun x hx => (h ▸ hx : x ∈ (∅ : Set α)).elim⟩) (h c hc)) trans section Preorder variable [Preorder α] theorem zorn_le (h : ∀ c : Set α, IsChain (· ≤ ·) c → BddAbove c) : ∃ m : α, IsMax m := exists_maximal_of_chains_bounded h le_trans theorem zorn_le_nonempty [Nonempty α] (h : ∀ c : Set α, IsChain (· ≤ ·) c → c.Nonempty → BddAbove c) : ∃ m : α, IsMax m := exists_maximal_of_nonempty_chains_bounded h le_trans theorem zorn_le₀ (s : Set α) (ih : ∀ c ⊆ s, IsChain (· ≤ ·) c → ∃ ub ∈ s, ∀ z ∈ c, z ≤ ub) : ∃ m, Maximal (· ∈ s) m := let ⟨⟨m, hms⟩, h⟩ := @zorn_le s _ fun c hc => let ⟨ub, hubs, hub⟩ := ih (Subtype.val '' c) (fun _ ⟨⟨_, hx⟩, _, h⟩ => h ▸ hx) (by rintro _ ⟨p, hpc, rfl⟩ _ ⟨q, hqc, rfl⟩ hpq exact hc hpc hqc fun t => hpq (Subtype.ext_iff.1 t)) ⟨⟨ub, hubs⟩, fun ⟨_, _⟩ hc => hub _ ⟨_, hc, rfl⟩⟩ ⟨m, hms, fun z hzs hmz => @h ⟨z, hzs⟩ hmz⟩ theorem zorn_le_nonempty₀ (s : Set α) (ih : ∀ c ⊆ s, IsChain (· ≤ ·) c → ∀ y ∈ c, ∃ ub ∈ s, ∀ z ∈ c, z ≤ ub) (x : α) (hxs : x ∈ s) : ∃ m, x ≤ m ∧ Maximal (· ∈ s) m := by have H := zorn_le₀ ({ y ∈ s | x ≤ y }) fun c hcs hc => ?_ · rcases H with ⟨m, ⟨hms, hxm⟩, hm⟩ exact ⟨m, hxm, hms, fun z hzs hmz => @hm _ ⟨hzs, hxm.trans hmz⟩ hmz⟩ · rcases c.eq_empty_or_nonempty with (rfl | ⟨y, hy⟩) · exact ⟨x, ⟨hxs, le_rfl⟩, fun z => False.elim⟩ · rcases ih c (fun z hz => (hcs hz).1) hc y hy with ⟨z, hzs, hz⟩ exact ⟨z, ⟨hzs, (hcs hy).2.trans <| hz _ hy⟩, hz⟩ theorem zorn_le_nonempty_Ici₀ (a : α) (ih : ∀ c ⊆ Ici a, IsChain (· ≤ ·) c → ∀ y ∈ c, ∃ ub, ∀ z ∈ c, z ≤ ub) (x : α) (hax : a ≤ x) : ∃ m, x ≤ m ∧ IsMax m := by let ⟨m, hxm, ham, hm⟩ := zorn_le_nonempty₀ (Ici a) (fun c hca hc y hy ↦ ?_) x hax · exact ⟨m, hxm, fun z hmz => hm (ham.trans hmz) hmz⟩ · have ⟨ub, hub⟩ := ih c hca hc y hy exact ⟨ub, (hca hy).trans (hub y hy), hub⟩ end Preorder theorem zorn_subset (S : Set (Set α)) (h : ∀ c ⊆ S, IsChain (· ⊆ ·) c → ∃ ub ∈ S, ∀ s ∈ c, s ⊆ ub) : ∃ m, Maximal (· ∈ S) m := zorn_le₀ S h theorem zorn_subset_nonempty (S : Set (Set α))
(H : ∀ c ⊆ S, IsChain (· ⊆ ·) c → c.Nonempty → ∃ ub ∈ S, ∀ s ∈ c, s ⊆ ub) (x) (hx : x ∈ S) : ∃ m, x ⊆ m ∧ Maximal (· ∈ S) m := zorn_le_nonempty₀ _ (fun _ cS hc y yc => H _ cS hc ⟨y, yc⟩) _ hx theorem zorn_superset (S : Set (Set α)) (h : ∀ c ⊆ S, IsChain (· ⊆ ·) c → ∃ lb ∈ S, ∀ s ∈ c, lb ⊆ s) : ∃ m, Minimal (· ∈ S) m :=
Mathlib/Order/Zorn.lean
144
149
/- Copyright (c) 2020 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.RingTheory.Nilpotent.Basic import Mathlib.RingTheory.UniqueFactorizationDomain.GCDMonoid import Mathlib.RingTheory.UniqueFactorizationDomain.Multiplicity /-! # Squarefree elements of monoids An element of a monoid is squarefree when it is not divisible by any squares except the squares of units. Results about squarefree natural numbers are proved in `Data.Nat.Squarefree`. ## Main Definitions - `Squarefree r` indicates that `r` is only divisible by `x * x` if `x` is a unit. ## Main Results - `multiplicity.squarefree_iff_emultiplicity_le_one`: `x` is `Squarefree` iff for every `y`, either `emultiplicity y x ≤ 1` or `IsUnit y`. - `UniqueFactorizationMonoid.squarefree_iff_nodup_factors`: A nonzero element `x` of a unique factorization monoid is squarefree iff `factors x` has no duplicate factors. ## Tags squarefree, multiplicity -/ variable {R : Type*} /-- An element of a monoid is squarefree if the only squares that divide it are the squares of units. -/ def Squarefree [Monoid R] (r : R) : Prop := ∀ x : R, x * x ∣ r → IsUnit x theorem IsRelPrime.of_squarefree_mul [CommMonoid R] {m n : R} (h : Squarefree (m * n)) : IsRelPrime m n := fun c hca hcb ↦ h c (mul_dvd_mul hca hcb) @[simp] theorem IsUnit.squarefree [CommMonoid R] {x : R} (h : IsUnit x) : Squarefree x := fun _ hdvd => isUnit_of_mul_isUnit_left (isUnit_of_dvd_unit hdvd h) theorem squarefree_one [CommMonoid R] : Squarefree (1 : R) := isUnit_one.squarefree @[simp] theorem not_squarefree_zero [MonoidWithZero R] [Nontrivial R] : ¬Squarefree (0 : R) := by erw [not_forall] exact ⟨0, by simp⟩ theorem Squarefree.ne_zero [MonoidWithZero R] [Nontrivial R] {m : R} (hm : Squarefree (m : R)) : m ≠ 0 := by rintro rfl exact not_squarefree_zero hm @[simp] theorem Irreducible.squarefree [CommMonoid R] {x : R} (h : Irreducible x) : Squarefree x := by rintro y ⟨z, hz⟩ rw [mul_assoc] at hz rcases h.isUnit_or_isUnit hz with (hu | hu) · exact hu · apply isUnit_of_mul_isUnit_left hu
@[simp] theorem Prime.squarefree [CancelCommMonoidWithZero R] {x : R} (h : Prime x) : Squarefree x := h.irreducible.squarefree theorem Squarefree.of_mul_left [Monoid R] {m n : R} (hmn : Squarefree (m * n)) : Squarefree m := fun p hp => hmn p (dvd_mul_of_dvd_left hp n)
Mathlib/Algebra/Squarefree/Basic.lean
67
72
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.Algebra.Category.Ring.Basic import Mathlib.CategoryTheory.Limits.HasLimits /-! # The category of commutative rings has all colimits. This file uses a "pre-automated" approach, just as for `Mathlib/Algebra/Category/MonCat/Colimits.lean`. It is a very uniform approach, that conceivably could be synthesised directly by a tactic that analyses the shape of `CommRing` and `RingHom`. -/ universe u v open CategoryTheory Limits namespace RingCat.Colimits /-! We build the colimit of a diagram in `RingCat` by constructing the free ring on the disjoint union of all the rings in the diagram, then taking the quotient by the ring laws within each ring, and the identifications given by the morphisms in the diagram. -/ variable {J : Type v} [SmallCategory J] (F : J ⥤ RingCat.{v}) /-- An inductive type representing all ring expressions (without Relations) on a collection of types indexed by the objects of `J`. -/ inductive Prequotient -- There's always `of` | of : ∀ (j : J) (_ : F.obj j), Prequotient -- Then one generator for each operation | zero : Prequotient | one : Prequotient | neg : Prequotient → Prequotient | add : Prequotient → Prequotient → Prequotient | mul : Prequotient → Prequotient → Prequotient instance : Inhabited (Prequotient F) := ⟨Prequotient.zero⟩ open Prequotient /-- The Relation on `Prequotient` saying when two expressions are equal because of the ring laws, or because one element is mapped to another by a morphism in the diagram. -/ inductive Relation : Prequotient F → Prequotient F → Prop -- Make it an equivalence Relation: | refl : ∀ x, Relation x x | symm : ∀ (x y) (_ : Relation x y), Relation y x | trans : ∀ (x y z) (_ : Relation x y) (_ : Relation y z), Relation x z -- There's always a `map` Relation | map : ∀ (j j' : J) (f : j ⟶ j') (x : F.obj j), Relation (Prequotient.of j' (F.map f x)) (Prequotient.of j x) -- Then one Relation per operation, describing the interaction with `of` | zero : ∀ j, Relation (Prequotient.of j 0) zero | one : ∀ j, Relation (Prequotient.of j 1) one | neg : ∀ (j) (x : F.obj j), Relation (Prequotient.of j (-x)) (neg (Prequotient.of j x)) | add : ∀ (j) (x y : F.obj j), Relation (Prequotient.of j (x + y)) (add (Prequotient.of j x) (Prequotient.of j y)) | mul : ∀ (j) (x y : F.obj j), Relation (Prequotient.of j (x * y)) (mul (Prequotient.of j x) (Prequotient.of j y)) -- Then one Relation per argument of each operation | neg_1 : ∀ (x x') (_ : Relation x x'), Relation (neg x) (neg x') | add_1 : ∀ (x x' y) (_ : Relation x x'), Relation (add x y) (add x' y) | add_2 : ∀ (x y y') (_ : Relation y y'), Relation (add x y) (add x y') | mul_1 : ∀ (x x' y) (_ : Relation x x'), Relation (mul x y) (mul x' y) | mul_2 : ∀ (x y y') (_ : Relation y y'), Relation (mul x y) (mul x y') -- And one Relation per axiom | zero_add : ∀ x, Relation (add zero x) x | add_zero : ∀ x, Relation (add x zero) x | one_mul : ∀ x, Relation (mul one x) x | mul_one : ∀ x, Relation (mul x one) x | neg_add_cancel : ∀ x, Relation (add (neg x) x) zero | add_comm : ∀ x y, Relation (add x y) (add y x) | add_assoc : ∀ x y z, Relation (add (add x y) z) (add x (add y z)) | mul_assoc : ∀ x y z, Relation (mul (mul x y) z) (mul x (mul y z)) | left_distrib : ∀ x y z, Relation (mul x (add y z)) (add (mul x y) (mul x z)) | right_distrib : ∀ x y z, Relation (mul (add x y) z) (add (mul x z) (mul y z)) | zero_mul : ∀ x, Relation (mul zero x) zero | mul_zero : ∀ x, Relation (mul x zero) zero /-- The setoid corresponding to commutative expressions modulo monoid Relations and identifications. -/ def colimitSetoid : Setoid (Prequotient F) where r := Relation F iseqv := ⟨Relation.refl, Relation.symm _ _, Relation.trans _ _ _⟩ attribute [instance] colimitSetoid /-- The underlying type of the colimit of a diagram in `CommRingCat`. -/ def ColimitType : Type v := Quotient (colimitSetoid F) instance ColimitType.instZero : Zero (ColimitType F) where zero := Quotient.mk _ zero instance ColimitType.instAdd : Add (ColimitType F) where add := Quotient.map₂ add <| fun _x x' rx y _y' ry => Setoid.trans (Relation.add_1 _ _ y rx) (Relation.add_2 x' _ _ ry) instance ColimitType.instNeg : Neg (ColimitType F) where neg := Quotient.map neg Relation.neg_1 instance ColimitType.AddGroup : AddGroup (ColimitType F) where neg := Quotient.map neg Relation.neg_1 zero_add := Quotient.ind <| fun _ => Quotient.sound <| Relation.zero_add _ add_zero := Quotient.ind <| fun _ => Quotient.sound <| Relation.add_zero _ neg_add_cancel := Quotient.ind <| fun _ => Quotient.sound <| Relation.neg_add_cancel _ add_assoc := Quotient.ind <| fun _ => Quotient.ind₂ <| fun _ _ => Quotient.sound <| Relation.add_assoc _ _ _ nsmul := nsmulRec zsmul := zsmulRec instance InhabitedColimitType : Inhabited <| ColimitType F where default := 0 instance ColimitType.AddGroupWithOne : AddGroupWithOne (ColimitType F) := { ColimitType.AddGroup F with one := Quotient.mk _ one } instance : Ring (ColimitType.{v} F) := { ColimitType.AddGroupWithOne F with mul := Quot.map₂ Prequotient.mul Relation.mul_2 Relation.mul_1 one_mul := fun x => Quot.inductionOn x fun _ => Quot.sound <| Relation.one_mul _ mul_one := fun x => Quot.inductionOn x fun _ => Quot.sound <| Relation.mul_one _ add_comm := fun x y => Quot.induction_on₂ x y fun _ _ => Quot.sound <| Relation.add_comm _ _ mul_assoc := fun x y z => Quot.induction_on₃ x y z fun x y z => by simp only [(· * ·)] exact Quot.sound (Relation.mul_assoc _ _ _) mul_zero := fun x => Quot.inductionOn x fun _ => Quot.sound <| Relation.mul_zero _ zero_mul := fun x => Quot.inductionOn x fun _ => Quot.sound <| Relation.zero_mul _ left_distrib := fun x y z => Quot.induction_on₃ x y z fun x y z => by simp only [(· + ·), (· * ·), Add.add] exact Quot.sound (Relation.left_distrib _ _ _) right_distrib := fun x y z => Quot.induction_on₃ x y z fun x y z => by simp only [(· + ·), (· * ·), Add.add] exact Quot.sound (Relation.right_distrib _ _ _) } @[simp] theorem quot_zero : Quot.mk Setoid.r zero = (0 : ColimitType F) := rfl @[simp] theorem quot_one : Quot.mk Setoid.r one = (1 : ColimitType F) := rfl @[simp] theorem quot_neg (x : Prequotient F) : Quot.mk Setoid.r (neg x) = -(show ColimitType F from Quot.mk Setoid.r x) := rfl @[simp] theorem quot_add (x y) : Quot.mk Setoid.r (add x y) = (show ColimitType F from Quot.mk _ x) + (show ColimitType F from Quot.mk _ y) := rfl @[simp] theorem quot_mul (x y) : Quot.mk Setoid.r (mul x y) = (show ColimitType F from Quot.mk _ x) * (show ColimitType F from Quot.mk _ y) := rfl /-- The bundled ring giving the colimit of a diagram. -/ def colimit : RingCat := RingCat.of (ColimitType F) /-- The function from a given ring in the diagram to the colimit ring. -/ def coconeFun (j : J) (x : F.obj j) : ColimitType F := Quot.mk _ (Prequotient.of j x) /-- The ring homomorphism from a given ring in the diagram to the colimit ring. -/ def coconeMorphism (j : J) : F.obj j ⟶ colimit F := ofHom { toFun := coconeFun F j map_one' := by apply Quot.sound; apply Relation.one map_mul' := by intros; apply Quot.sound; apply Relation.mul map_zero' := by apply Quot.sound; apply Relation.zero map_add' := by intros; apply Quot.sound; apply Relation.add } @[simp] theorem cocone_naturality {j j' : J} (f : j ⟶ j') : F.map f ≫ coconeMorphism F j' = coconeMorphism F j := by ext apply Quot.sound apply Relation.map @[simp] theorem cocone_naturality_components (j j' : J) (f : j ⟶ j') (x : F.obj j) : (coconeMorphism F j') (F.map f x) = (coconeMorphism F j) x := by rw [← cocone_naturality F f, comp_apply] /-- The cocone over the proposed colimit ring. -/ def colimitCocone : Cocone F where pt := colimit F ι := { app := coconeMorphism F } /-- The function from the free ring on the diagram to the cone point of any other cocone. -/ @[simp] def descFunLift (s : Cocone F) : Prequotient F → s.pt | Prequotient.of j x => (s.ι.app j) x | zero => 0 | one => 1 | neg x => -descFunLift s x | add x y => descFunLift s x + descFunLift s y | mul x y => descFunLift s x * descFunLift s y /-- The function from the colimit ring to the cone point of any other cocone. -/ def descFun (s : Cocone F) : ColimitType F → s.pt := by fapply Quot.lift · exact descFunLift F s · intro x y r induction r with | refl => rfl | symm x y _ ih => exact ih.symm | trans x y z _ _ ih1 ih2 => exact ih1.trans ih2 | map j j' f x => exact RingHom.congr_fun (congrArg Hom.hom <| s.ι.naturality f) x | zero j => simp | one j => simp | neg j x => simp | add j x y => simp | mul j x y => simp | neg_1 x x' r ih => dsimp; rw [ih] | add_1 x x' y r ih => dsimp; rw [ih] | add_2 x y y' r ih => dsimp; rw [ih] | mul_1 x x' y r ih => dsimp; rw [ih] | mul_2 x y y' r ih => dsimp; rw [ih] | zero_add x => dsimp; rw [zero_add] | add_zero x => dsimp; rw [add_zero] | one_mul x => dsimp; rw [one_mul] | mul_one x => dsimp; rw [mul_one] | neg_add_cancel x => dsimp; rw [neg_add_cancel] | add_comm x y => dsimp; rw [add_comm] | add_assoc x y z => dsimp; rw [add_assoc] | mul_assoc x y z => dsimp; rw [mul_assoc] | left_distrib x y z => dsimp; rw [mul_add] | right_distrib x y z => dsimp; rw [add_mul] | zero_mul x => dsimp; rw [zero_mul]
| mul_zero x => dsimp; rw [mul_zero] /-- The ring homomorphism from the colimit ring to the cone point of any other
Mathlib/Algebra/Category/Ring/Colimits.lean
253
255
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl -/ import Mathlib.Algebra.Order.Group.Unbundled.Basic import Mathlib.Algebra.Order.Monoid.Defs import Mathlib.Algebra.Order.Sub.Defs import Mathlib.Util.AssertExists /-! # Ordered groups This file defines bundled ordered groups and develops a few basic results. ## Implementation details Unfortunately, the number of `'` appended to lemmas in this file may differ between the multiplicative and the additive version of a lemma. The reason is that we did not want to change existing names in the library. -/ /- `NeZero` theory should not be needed at this point in the ordered algebraic hierarchy. -/ assert_not_imported Mathlib.Algebra.NeZero open Function universe u variable {α : Type u} /-- An ordered additive commutative group is an additive commutative group with a partial order in which addition is strictly monotone. -/ @[deprecated "Use `[AddCommGroup α] [PartialOrder α] [IsOrderedAddMonoid α]` instead." (since := "2025-04-10")] structure OrderedAddCommGroup (α : Type u) extends AddCommGroup α, PartialOrder α where /-- Addition is monotone in an ordered additive commutative group. -/ protected add_le_add_left : ∀ a b : α, a ≤ b → ∀ c : α, c + a ≤ c + b set_option linter.existingAttributeWarning false in /-- An ordered commutative group is a commutative group with a partial order in which multiplication is strictly monotone. -/ @[to_additive, deprecated "Use `[CommGroup α] [PartialOrder α] [IsOrderedMonoid α]` instead." (since := "2025-04-10")] structure OrderedCommGroup (α : Type u) extends CommGroup α, PartialOrder α where /-- Multiplication is monotone in an ordered commutative group. -/ protected mul_le_mul_left : ∀ a b : α, a ≤ b → ∀ c : α, c * a ≤ c * b alias OrderedCommGroup.mul_lt_mul_left' := mul_lt_mul_left' attribute [to_additive OrderedAddCommGroup.add_lt_add_left] OrderedCommGroup.mul_lt_mul_left' alias OrderedCommGroup.le_of_mul_le_mul_left := le_of_mul_le_mul_left' attribute [to_additive] OrderedCommGroup.le_of_mul_le_mul_left alias OrderedCommGroup.lt_of_mul_lt_mul_left := lt_of_mul_lt_mul_left' attribute [to_additive] OrderedCommGroup.lt_of_mul_lt_mul_left -- See note [lower instance priority] @[to_additive IsOrderedAddMonoid.toIsOrderedCancelAddMonoid] instance (priority := 100) IsOrderedMonoid.toIsOrderedCancelMonoid [CommGroup α] [PartialOrder α] [IsOrderedMonoid α] : IsOrderedCancelMonoid α where le_of_mul_le_mul_left a b c bc := by simpa using mul_le_mul_left' bc a⁻¹ le_of_mul_le_mul_right a b c bc := by simpa using mul_le_mul_left' bc a⁻¹ /-! ### Linearly ordered commutative groups -/ set_option linter.deprecated false in /-- A linearly ordered additive commutative group is an additive commutative group with a linear order in which addition is monotone. -/ @[deprecated "Use `[AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α]` instead." (since := "2025-04-10")] structure LinearOrderedAddCommGroup (α : Type u) extends OrderedAddCommGroup α, LinearOrder α set_option linter.existingAttributeWarning false in set_option linter.deprecated false in /-- A linearly ordered commutative group is a commutative group with a linear order in which multiplication is monotone. -/ @[to_additive, deprecated "Use `[CommGroup α] [LinearOrder α] [IsOrderedMonoid α]` instead." (since := "2025-04-10")] structure LinearOrderedCommGroup (α : Type u) extends OrderedCommGroup α, LinearOrder α attribute [nolint docBlame] LinearOrderedCommGroup.toLinearOrder LinearOrderedAddCommGroup.toLinearOrder section LinearOrderedCommGroup variable [CommGroup α] [LinearOrder α] [IsOrderedMonoid α] {a : α} @[to_additive LinearOrderedAddCommGroup.add_lt_add_left] theorem LinearOrderedCommGroup.mul_lt_mul_left' (a b : α) (h : a < b) (c : α) : c * a < c * b := _root_.mul_lt_mul_left' h c @[to_additive eq_zero_of_neg_eq] theorem eq_one_of_inv_eq' (h : a⁻¹ = a) : a = 1 := match lt_trichotomy a 1 with | Or.inl h₁ => have : 1 < a := h ▸ one_lt_inv_of_inv h₁ absurd h₁ this.asymm | Or.inr (Or.inl h₁) => h₁ | Or.inr (Or.inr h₁) => have : a < 1 := h ▸ inv_lt_one'.mpr h₁ absurd h₁ this.asymm @[to_additive exists_zero_lt] theorem exists_one_lt' [Nontrivial α] : ∃ a : α, 1 < a := by obtain ⟨y, hy⟩ := Decidable.exists_ne (1 : α)
obtain h|h := hy.lt_or_lt · exact ⟨y⁻¹, one_lt_inv'.mpr h⟩
Mathlib/Algebra/Order/Group/Defs.lean
120
121
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Algebra.BigOperators.Fin import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Data.Finset.Sort /-! # Compositions A composition of a natural number `n` is a decomposition `n = i₀ + ... + i_{k-1}` of `n` into a sum of positive integers. Combinatorially, it corresponds to a decomposition of `{0, ..., n-1}` into non-empty blocks of consecutive integers, where the `iⱼ` are the lengths of the blocks. This notion is closely related to that of a partition of `n`, but in a composition of `n` the order of the `iⱼ`s matters. We implement two different structures covering these two viewpoints on compositions. The first one, made of a list of positive integers summing to `n`, is the main one and is called `Composition n`. The second one is useful for combinatorial arguments (for instance to show that the number of compositions of `n` is `2^(n-1)`). It is given by a subset of `{0, ..., n}` containing `0` and `n`, where the elements of the subset (other than `n`) correspond to the leftmost points of each block. The main API is built on `Composition n`, and we provide an equivalence between the two types. ## Main functions * `c : Composition n` is a structure, made of a list of integers which are all positive and add up to `n`. * `composition_card` states that the cardinality of `Composition n` is exactly `2^(n-1)`, which is proved by constructing an equiv with `CompositionAsSet n` (see below), which is itself in bijection with the subsets of `Fin (n-1)` (this holds even for `n = 0`, where `-` is nat subtraction). Let `c : Composition n` be a composition of `n`. Then * `c.blocks` is the list of blocks in `c`. * `c.length` is the number of blocks in the composition. * `c.blocksFun : Fin c.length → ℕ` is the realization of `c.blocks` as a function on `Fin c.length`. This is the main object when using compositions to understand the composition of analytic functions. * `c.sizeUpTo : ℕ → ℕ` is the sum of the size of the blocks up to `i`.; * `c.embedding i : Fin (c.blocksFun i) → Fin n` is the increasing embedding of the `i`-th block in `Fin n`; * `c.index j`, for `j : Fin n`, is the index of the block containing `j`. * `Composition.ones n` is the composition of `n` made of ones, i.e., `[1, ..., 1]`. * `Composition.single n (hn : 0 < n)` is the composition of `n` made of a single block of size `n`. Compositions can also be used to split lists. Let `l` be a list of length `n` and `c` a composition of `n`. * `l.splitWrtComposition c` is a list of lists, made of the slices of `l` corresponding to the blocks of `c`. * `join_splitWrtComposition` states that splitting a list and then joining it gives back the original list. * `splitWrtComposition_join` states that joining a list of lists, and then splitting it back according to the right composition, gives back the original list of lists. We turn to the second viewpoint on compositions, that we realize as a finset of `Fin (n+1)`. `c : CompositionAsSet n` is a structure made of a finset of `Fin (n+1)` called `c.boundaries` and proofs that it contains `0` and `n`. (Taking a finset of `Fin n` containing `0` would not make sense in the edge case `n = 0`, while the previous description works in all cases). The elements of this set (other than `n`) correspond to leftmost points of blocks. Thus, there is an equiv between `Composition n` and `CompositionAsSet n`. We only construct basic API on `CompositionAsSet` (notably `c.length` and `c.blocks`) to be able to construct this equiv, called `compositionEquiv n`. Since there is a straightforward equiv between `CompositionAsSet n` and finsets of `{1, ..., n-1}` (obtained by removing `0` and `n` from a `CompositionAsSet` and called `compositionAsSetEquiv n`), we deduce that `CompositionAsSet n` and `Composition n` are both fintypes of cardinality `2^(n - 1)` (see `compositionAsSet_card` and `composition_card`). ## Implementation details The main motivation for this structure and its API is in the construction of the composition of formal multilinear series, and the proof that the composition of analytic functions is analytic. The representation of a composition as a list is very handy as lists are very flexible and already have a well-developed API. ## Tags Composition, partition ## References <https://en.wikipedia.org/wiki/Composition_(combinatorics)> -/ assert_not_exists Field open List variable {n : ℕ} /-- A composition of `n` is a list of positive integers summing to `n`. -/ @[ext] structure Composition (n : ℕ) where /-- List of positive integers summing to `n` -/ blocks : List ℕ /-- Proof of positivity for `blocks` -/ blocks_pos : ∀ {i}, i ∈ blocks → 0 < i /-- Proof that `blocks` sums to `n` -/ blocks_sum : blocks.sum = n deriving DecidableEq attribute [simp] Composition.blocks_sum /-- Combinatorial viewpoint on a composition of `n`, by seeing it as non-empty blocks of consecutive integers in `{0, ..., n-1}`. We register every block by its left end-point, yielding a finset containing `0`. As this does not make sense for `n = 0`, we add `n` to this finset, and get a finset of `{0, ..., n}` containing `0` and `n`. This is the data in the structure `CompositionAsSet n`. -/ @[ext] structure CompositionAsSet (n : ℕ) where /-- Combinatorial viewpoint on a composition of `n` as consecutive integers `{0, ..., n-1}` -/ boundaries : Finset (Fin n.succ) /-- Proof that `0` is a member of `boundaries` -/ zero_mem : (0 : Fin n.succ) ∈ boundaries /-- Last element of the composition -/ getLast_mem : Fin.last n ∈ boundaries deriving DecidableEq instance {n : ℕ} : Inhabited (CompositionAsSet n) := ⟨⟨Finset.univ, Finset.mem_univ _, Finset.mem_univ _⟩⟩ attribute [simp] CompositionAsSet.zero_mem CompositionAsSet.getLast_mem /-! ### Compositions A composition of an integer `n` is a decomposition `n = i₀ + ... + i_{k-1}` of `n` into a sum of positive integers. -/ namespace Composition variable (c : Composition n) instance (n : ℕ) : ToString (Composition n) := ⟨fun c => toString c.blocks⟩ /-- The length of a composition, i.e., the number of blocks in the composition. -/ abbrev length : ℕ := c.blocks.length theorem blocks_length : c.blocks.length = c.length := rfl /-- The blocks of a composition, seen as a function on `Fin c.length`. When composing analytic functions using compositions, this is the main player. -/ def blocksFun : Fin c.length → ℕ := c.blocks.get @[simp] theorem ofFn_blocksFun : ofFn c.blocksFun = c.blocks := ofFn_get _ @[simp] theorem sum_blocksFun : ∑ i, c.blocksFun i = n := by conv_rhs => rw [← c.blocks_sum, ← ofFn_blocksFun, sum_ofFn] @[simp] theorem blocksFun_mem_blocks (i : Fin c.length) : c.blocksFun i ∈ c.blocks := get_mem _ _ theorem one_le_blocks {i : ℕ} (h : i ∈ c.blocks) : 1 ≤ i := c.blocks_pos h theorem blocks_le {i : ℕ} (h : i ∈ c.blocks) : i ≤ n := by rw [← c.blocks_sum] exact List.le_sum_of_mem h @[simp] theorem one_le_blocks' {i : ℕ} (h : i < c.length) : 1 ≤ c.blocks[i] := c.one_le_blocks (get_mem (blocks c) _) @[simp] theorem blocks_pos' (i : ℕ) (h : i < c.length) : 0 < c.blocks[i] := c.one_le_blocks' h @[simp] theorem one_le_blocksFun (i : Fin c.length) : 1 ≤ c.blocksFun i := c.one_le_blocks (c.blocksFun_mem_blocks i) @[simp] theorem blocksFun_le {n} (c : Composition n) (i : Fin c.length) : c.blocksFun i ≤ n := c.blocks_le <| getElem_mem _ @[simp] theorem length_le : c.length ≤ n := by conv_rhs => rw [← c.blocks_sum] exact length_le_sum_of_one_le _ fun i hi => c.one_le_blocks hi @[simp] theorem blocks_eq_nil : c.blocks = [] ↔ n = 0 := by constructor · intro h simpa using congr(List.sum $h) · rintro rfl rw [← length_eq_zero_iff, ← nonpos_iff_eq_zero] exact c.length_le protected theorem length_eq_zero : c.length = 0 ↔ n = 0 := by simp @[simp] theorem length_pos_iff : 0 < c.length ↔ 0 < n := by simp [pos_iff_ne_zero] alias ⟨_, length_pos_of_pos⟩ := length_pos_iff /-- The sum of the sizes of the blocks in a composition up to `i`. -/ def sizeUpTo (i : ℕ) : ℕ := (c.blocks.take i).sum @[simp] theorem sizeUpTo_zero : c.sizeUpTo 0 = 0 := by simp [sizeUpTo] theorem sizeUpTo_ofLength_le (i : ℕ) (h : c.length ≤ i) : c.sizeUpTo i = n := by dsimp [sizeUpTo] convert c.blocks_sum exact take_of_length_le h @[simp] theorem sizeUpTo_length : c.sizeUpTo c.length = n := c.sizeUpTo_ofLength_le c.length le_rfl theorem sizeUpTo_le (i : ℕ) : c.sizeUpTo i ≤ n := by conv_rhs => rw [← c.blocks_sum, ← sum_take_add_sum_drop _ i] exact Nat.le_add_right _ _ theorem sizeUpTo_succ {i : ℕ} (h : i < c.length) : c.sizeUpTo (i + 1) = c.sizeUpTo i + c.blocks[i] := by simp only [sizeUpTo] rw [sum_take_succ _ _ h] theorem sizeUpTo_succ' (i : Fin c.length) : c.sizeUpTo ((i : ℕ) + 1) = c.sizeUpTo i + c.blocksFun i := c.sizeUpTo_succ i.2 theorem sizeUpTo_strict_mono {i : ℕ} (h : i < c.length) : c.sizeUpTo i < c.sizeUpTo (i + 1) := by rw [c.sizeUpTo_succ h] simp theorem monotone_sizeUpTo : Monotone c.sizeUpTo := monotone_sum_take _ /-- The `i`-th boundary of a composition, i.e., the leftmost point of the `i`-th block. We include a virtual point at the right of the last block, to make for a nice equiv with `CompositionAsSet n`. -/ def boundary : Fin (c.length + 1) ↪o Fin (n + 1) := (OrderEmbedding.ofStrictMono fun i => ⟨c.sizeUpTo i, Nat.lt_succ_of_le (c.sizeUpTo_le i)⟩) <| Fin.strictMono_iff_lt_succ.2 fun ⟨_, hi⟩ => c.sizeUpTo_strict_mono hi @[simp] theorem boundary_zero : c.boundary 0 = 0 := by simp [boundary, Fin.ext_iff] @[simp] theorem boundary_last : c.boundary (Fin.last c.length) = Fin.last n := by simp [boundary, Fin.ext_iff] /-- The boundaries of a composition, i.e., the leftmost point of all the blocks. We include a virtual point at the right of the last block, to make for a nice equiv with `CompositionAsSet n`. -/ def boundaries : Finset (Fin (n + 1)) := Finset.univ.map c.boundary.toEmbedding theorem card_boundaries_eq_succ_length : c.boundaries.card = c.length + 1 := by simp [boundaries] /-- To `c : Composition n`, one can associate a `CompositionAsSet n` by registering the leftmost point of each block, and adding a virtual point at the right of the last block. -/ def toCompositionAsSet : CompositionAsSet n where boundaries := c.boundaries zero_mem := by simp only [boundaries, Finset.mem_univ, exists_prop_of_true, Finset.mem_map] exact ⟨0, And.intro True.intro rfl⟩ getLast_mem := by simp only [boundaries, Finset.mem_univ, exists_prop_of_true, Finset.mem_map] exact ⟨Fin.last c.length, And.intro True.intro c.boundary_last⟩ /-- The canonical increasing bijection between `Fin (c.length + 1)` and `c.boundaries` is exactly `c.boundary`. -/ theorem orderEmbOfFin_boundaries : c.boundaries.orderEmbOfFin c.card_boundaries_eq_succ_length = c.boundary := by refine (Finset.orderEmbOfFin_unique' _ ?_).symm exact fun i => (Finset.mem_map' _).2 (Finset.mem_univ _) /-- Embedding the `i`-th block of a composition (identified with `Fin (c.blocksFun i)`) into `Fin n` at the relevant position. -/ def embedding (i : Fin c.length) : Fin (c.blocksFun i) ↪o Fin n := (Fin.natAddOrderEmb <| c.sizeUpTo i).trans <| Fin.castLEOrderEmb <| calc c.sizeUpTo i + c.blocksFun i = c.sizeUpTo (i + 1) := (c.sizeUpTo_succ i.2).symm _ ≤ c.sizeUpTo c.length := monotone_sum_take _ i.2 _ = n := c.sizeUpTo_length @[simp] theorem coe_embedding (i : Fin c.length) (j : Fin (c.blocksFun i)) : (c.embedding i j : ℕ) = c.sizeUpTo i + j := rfl /-- `index_exists` asserts there is some `i` with `j < c.sizeUpTo (i+1)`. In the next definition `index` we use `Nat.find` to produce the minimal such index. -/ theorem index_exists {j : ℕ} (h : j < n) : ∃ i : ℕ, j < c.sizeUpTo (i + 1) ∧ i < c.length := by have n_pos : 0 < n := lt_of_le_of_lt (zero_le j) h have : 0 < c.blocks.sum := by rwa [← c.blocks_sum] at n_pos have length_pos : 0 < c.blocks.length := length_pos_of_sum_pos (blocks c) this refine ⟨c.length - 1, ?_, Nat.pred_lt (ne_of_gt length_pos)⟩ have : c.length - 1 + 1 = c.length := Nat.succ_pred_eq_of_pos length_pos simp [this, h] /-- `c.index j` is the index of the block in the composition `c` containing `j`. -/ def index (j : Fin n) : Fin c.length := ⟨Nat.find (c.index_exists j.2), (Nat.find_spec (c.index_exists j.2)).2⟩ theorem lt_sizeUpTo_index_succ (j : Fin n) : (j : ℕ) < c.sizeUpTo (c.index j).succ := (Nat.find_spec (c.index_exists j.2)).1 theorem sizeUpTo_index_le (j : Fin n) : c.sizeUpTo (c.index j) ≤ j := by by_contra H set i := c.index j push_neg at H have i_pos : (0 : ℕ) < i := by by_contra! i_pos revert H simp [nonpos_iff_eq_zero.1 i_pos, c.sizeUpTo_zero] let i₁ := (i : ℕ).pred have i₁_lt_i : i₁ < i := Nat.pred_lt (ne_of_gt i_pos) have i₁_succ : i₁ + 1 = i := Nat.succ_pred_eq_of_pos i_pos have := Nat.find_min (c.index_exists j.2) i₁_lt_i simp [lt_trans i₁_lt_i (c.index j).2, i₁_succ] at this exact Nat.lt_le_asymm H this /-- Mapping an element `j` of `Fin n` to the element in the block containing it, identified with `Fin (c.blocksFun (c.index j))` through the canonical increasing bijection. -/ def invEmbedding (j : Fin n) : Fin (c.blocksFun (c.index j)) := ⟨j - c.sizeUpTo (c.index j), by rw [tsub_lt_iff_right, add_comm, ← sizeUpTo_succ'] · exact lt_sizeUpTo_index_succ _ _ · exact sizeUpTo_index_le _ _⟩ @[simp] theorem coe_invEmbedding (j : Fin n) : (c.invEmbedding j : ℕ) = j - c.sizeUpTo (c.index j) := rfl theorem embedding_comp_inv (j : Fin n) : c.embedding (c.index j) (c.invEmbedding j) = j := by rw [Fin.ext_iff] apply add_tsub_cancel_of_le (c.sizeUpTo_index_le j) theorem mem_range_embedding_iff {j : Fin n} {i : Fin c.length} : j ∈ Set.range (c.embedding i) ↔ c.sizeUpTo i ≤ j ∧ (j : ℕ) < c.sizeUpTo (i : ℕ).succ := by constructor · intro h rcases Set.mem_range.2 h with ⟨k, hk⟩ rw [Fin.ext_iff] at hk dsimp at hk rw [← hk] simp [sizeUpTo_succ', k.is_lt] · intro h apply Set.mem_range.2 refine ⟨⟨j - c.sizeUpTo i, ?_⟩, ?_⟩ · rw [tsub_lt_iff_left, ← sizeUpTo_succ'] · exact h.2 · exact h.1 · rw [Fin.ext_iff] exact add_tsub_cancel_of_le h.1 /-- The embeddings of different blocks of a composition are disjoint. -/ theorem disjoint_range {i₁ i₂ : Fin c.length} (h : i₁ ≠ i₂) : Disjoint (Set.range (c.embedding i₁)) (Set.range (c.embedding i₂)) := by classical wlog h' : i₁ < i₂ · exact (this c h.symm (h.lt_or_lt.resolve_left h')).symm by_contra d obtain ⟨x, hx₁, hx₂⟩ : ∃ x : Fin n, x ∈ Set.range (c.embedding i₁) ∧ x ∈ Set.range (c.embedding i₂) := Set.not_disjoint_iff.1 d have A : (i₁ : ℕ).succ ≤ i₂ := Nat.succ_le_of_lt h' apply lt_irrefl (x : ℕ) calc (x : ℕ) < c.sizeUpTo (i₁ : ℕ).succ := (c.mem_range_embedding_iff.1 hx₁).2 _ ≤ c.sizeUpTo (i₂ : ℕ) := monotone_sum_take _ A _ ≤ x := (c.mem_range_embedding_iff.1 hx₂).1 theorem mem_range_embedding (j : Fin n) : j ∈ Set.range (c.embedding (c.index j)) := by have : c.embedding (c.index j) (c.invEmbedding j) ∈ Set.range (c.embedding (c.index j)) := Set.mem_range_self _ rwa [c.embedding_comp_inv j] at this theorem mem_range_embedding_iff' {j : Fin n} {i : Fin c.length} : j ∈ Set.range (c.embedding i) ↔ i = c.index j := by constructor · rw [← not_imp_not] intro h exact Set.disjoint_right.1 (c.disjoint_range h) (c.mem_range_embedding j) · intro h rw [h] exact c.mem_range_embedding j theorem index_embedding (i : Fin c.length) (j : Fin (c.blocksFun i)) : c.index (c.embedding i j) = i := by symm rw [← mem_range_embedding_iff'] apply Set.mem_range_self theorem invEmbedding_comp (i : Fin c.length) (j : Fin (c.blocksFun i)) : (c.invEmbedding (c.embedding i j) : ℕ) = j := by simp_rw [coe_invEmbedding, index_embedding, coe_embedding, add_tsub_cancel_left] /-- Equivalence between the disjoint union of the blocks (each of them seen as `Fin (c.blocksFun i)`) with `Fin n`. -/ def blocksFinEquiv : (Σi : Fin c.length, Fin (c.blocksFun i)) ≃ Fin n where toFun x := c.embedding x.1 x.2 invFun j := ⟨c.index j, c.invEmbedding j⟩ left_inv x := by rcases x with ⟨i, y⟩ dsimp congr; · exact c.index_embedding _ _ rw [Fin.heq_ext_iff] · exact c.invEmbedding_comp _ _ · rw [c.index_embedding] right_inv j := c.embedding_comp_inv j theorem blocksFun_congr {n₁ n₂ : ℕ} (c₁ : Composition n₁) (c₂ : Composition n₂) (i₁ : Fin c₁.length) (i₂ : Fin c₂.length) (hn : n₁ = n₂) (hc : c₁.blocks = c₂.blocks) (hi : (i₁ : ℕ) = i₂) : c₁.blocksFun i₁ = c₂.blocksFun i₂ := by cases hn rw [← Composition.ext_iff] at hc cases hc congr rwa [Fin.ext_iff] /-- Two compositions (possibly of different integers) coincide if and only if they have the same sequence of blocks. -/ theorem sigma_eq_iff_blocks_eq {c : Σ n, Composition n} {c' : Σ n, Composition n} : c = c' ↔ c.2.blocks = c'.2.blocks := by refine ⟨fun H => by rw [H], fun H => ?_⟩ rcases c with ⟨n, c⟩ rcases c' with ⟨n', c'⟩ have : n = n' := by rw [← c.blocks_sum, ← c'.blocks_sum, H] induction this congr ext1 exact H /-! ### The composition `Composition.ones` -/ /-- The composition made of blocks all of size `1`. -/ def ones (n : ℕ) : Composition n := ⟨replicate n (1 : ℕ), fun {i} hi => by simp [List.eq_of_mem_replicate hi], by simp⟩ instance {n : ℕ} : Inhabited (Composition n) := ⟨Composition.ones n⟩ @[simp] theorem ones_length (n : ℕ) : (ones n).length = n := List.length_replicate @[simp] theorem ones_blocks (n : ℕ) : (ones n).blocks = replicate n (1 : ℕ) := rfl @[simp] theorem ones_blocksFun (n : ℕ) (i : Fin (ones n).length) : (ones n).blocksFun i = 1 := by simp only [blocksFun, ones, get_eq_getElem, getElem_replicate] @[simp] theorem ones_sizeUpTo (n : ℕ) (i : ℕ) : (ones n).sizeUpTo i = min i n := by simp [sizeUpTo, ones_blocks, take_replicate] @[simp] theorem ones_embedding (i : Fin (ones n).length) (h : 0 < (ones n).blocksFun i) : (ones n).embedding i ⟨0, h⟩ = ⟨i, lt_of_lt_of_le i.2 (ones n).length_le⟩ := by ext simpa using i.2.le theorem eq_ones_iff {c : Composition n} : c = ones n ↔ ∀ i ∈ c.blocks, i = 1 := by constructor · rintro rfl exact fun i => eq_of_mem_replicate · intro H ext1 have A : c.blocks = replicate c.blocks.length 1 := eq_replicate_of_mem H have : c.blocks.length = n := by conv_rhs => rw [← c.blocks_sum, A] simp rw [A, this, ones_blocks] theorem ne_ones_iff {c : Composition n} : c ≠ ones n ↔ ∃ i ∈ c.blocks, 1 < i := by refine (not_congr eq_ones_iff).trans ?_ have : ∀ j ∈ c.blocks, j = 1 ↔ j ≤ 1 := fun j hj => by simp [le_antisymm_iff, c.one_le_blocks hj] simp +contextual [this] theorem eq_ones_iff_length {c : Composition n} : c = ones n ↔ c.length = n := by constructor · rintro rfl exact ones_length n · contrapose intro H length_n apply lt_irrefl n calc n = ∑ i : Fin c.length, 1 := by simp [length_n] _ < ∑ i : Fin c.length, c.blocksFun i := by { obtain ⟨i, hi, i_blocks⟩ : ∃ i ∈ c.blocks, 1 < i := ne_ones_iff.1 H rw [← ofFn_blocksFun, mem_ofFn' c.blocksFun, Set.mem_range] at hi obtain ⟨j : Fin c.length, hj : c.blocksFun j = i⟩ := hi rw [← hj] at i_blocks exact Finset.sum_lt_sum (fun i _ => one_le_blocksFun c i) ⟨j, Finset.mem_univ _, i_blocks⟩ } _ = n := c.sum_blocksFun theorem eq_ones_iff_le_length {c : Composition n} : c = ones n ↔ n ≤ c.length := by simp [eq_ones_iff_length, le_antisymm_iff, c.length_le] /-! ### The composition `Composition.single` -/ /-- The composition made of a single block of size `n`. -/ def single (n : ℕ) (h : 0 < n) : Composition n := ⟨[n], by simp [h], by simp⟩ @[simp] theorem single_length {n : ℕ} (h : 0 < n) : (single n h).length = 1 := rfl @[simp] theorem single_blocks {n : ℕ} (h : 0 < n) : (single n h).blocks = [n] := rfl @[simp] theorem single_blocksFun {n : ℕ} (h : 0 < n) (i : Fin (single n h).length) : (single n h).blocksFun i = n := by simp [blocksFun, single, blocks, i.2] @[simp] theorem single_embedding {n : ℕ} (h : 0 < n) (i : Fin n) : ((single n h).embedding (0 : Fin 1)) i = i := by ext simp theorem eq_single_iff_length {n : ℕ} (h : 0 < n) {c : Composition n} : c = single n h ↔ c.length = 1 := by constructor · intro H rw [H] exact single_length h · intro H ext1 have A : c.blocks.length = 1 := H ▸ c.blocks_length have B : c.blocks.sum = n := c.blocks_sum rw [eq_cons_of_length_one A] at B ⊢ simpa [single_blocks] using B theorem ne_single_iff {n : ℕ} (hn : 0 < n) {c : Composition n} : c ≠ single n hn ↔ ∀ i, c.blocksFun i < n := by rw [← not_iff_not] push_neg constructor · rintro rfl exact ⟨⟨0, by simp⟩, by simp⟩ · rintro ⟨i, hi⟩ rw [eq_single_iff_length] have : ∀ j : Fin c.length, j = i := by intro j
by_contra ji apply lt_irrefl (∑ k, c.blocksFun k)
Mathlib/Combinatorics/Enumerative/Composition.lean
566
567
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.CharP.Basic import Mathlib.Algebra.Module.End import Mathlib.Algebra.Ring.Prod import Mathlib.Data.Fintype.Units import Mathlib.GroupTheory.GroupAction.SubMulAction import Mathlib.GroupTheory.OrderOfElement import Mathlib.Tactic.FinCases /-! # Integers mod `n` Definition of the integers mod n, and the field structure on the integers mod p. ## Definitions * `ZMod n`, which is for integers modulo a nat `n : ℕ` * `val a` is defined as a natural number: - for `a : ZMod 0` it is the absolute value of `a` - for `a : ZMod n` with `0 < n` it is the least natural number in the equivalence class * A coercion `cast` is defined from `ZMod n` into any ring. This is a ring hom if the ring has characteristic dividing `n` -/ assert_not_exists Field Submodule TwoSidedIdeal open Function ZMod namespace ZMod /-- For non-zero `n : ℕ`, the ring `Fin n` is equivalent to `ZMod n`. -/ def finEquiv : ∀ (n : ℕ) [NeZero n], Fin n ≃+* ZMod n | 0, h => (h.ne _ rfl).elim | _ + 1, _ => .refl _ instance charZero : CharZero (ZMod 0) := inferInstanceAs (CharZero ℤ) /-- `val a` is a natural number defined as: - for `a : ZMod 0` it is the absolute value of `a` - for `a : ZMod n` with `0 < n` it is the least natural number in the equivalence class See `ZMod.valMinAbs` for a variant that takes values in the integers. -/ def val : ∀ {n : ℕ}, ZMod n → ℕ | 0 => Int.natAbs | n + 1 => ((↑) : Fin (n + 1) → ℕ) theorem val_lt {n : ℕ} [NeZero n] (a : ZMod n) : a.val < n := by cases n · cases NeZero.ne 0 rfl exact Fin.is_lt a theorem val_le {n : ℕ} [NeZero n] (a : ZMod n) : a.val ≤ n := a.val_lt.le @[simp] theorem val_zero : ∀ {n}, (0 : ZMod n).val = 0 | 0 => rfl | _ + 1 => rfl @[simp] theorem val_one' : (1 : ZMod 0).val = 1 := rfl @[simp] theorem val_neg' {n : ZMod 0} : (-n).val = n.val := Int.natAbs_neg n @[simp] theorem val_mul' {m n : ZMod 0} : (m * n).val = m.val * n.val := Int.natAbs_mul m n @[simp] theorem val_natCast (n a : ℕ) : (a : ZMod n).val = a % n := by cases n · rw [Nat.mod_zero] exact Int.natAbs_natCast a · apply Fin.val_natCast lemma val_natCast_of_lt {n a : ℕ} (h : a < n) : (a : ZMod n).val = a := by rwa [val_natCast, Nat.mod_eq_of_lt] lemma val_ofNat (n a : ℕ) [a.AtLeastTwo] : (ofNat(a) : ZMod n).val = ofNat(a) % n := val_natCast .. lemma val_ofNat_of_lt {n a : ℕ} [a.AtLeastTwo] (han : a < n) : (ofNat(a) : ZMod n).val = ofNat(a) := val_natCast_of_lt han theorem val_unit' {n : ZMod 0} : IsUnit n ↔ n.val = 1 := by simp only [val] rw [Int.isUnit_iff, Int.natAbs_eq_iff, Nat.cast_one] lemma eq_one_of_isUnit_natCast {n : ℕ} (h : IsUnit (n : ZMod 0)) : n = 1 := by rw [← Nat.mod_zero n, ← val_natCast, val_unit'.mp h] instance charP (n : ℕ) : CharP (ZMod n) n where cast_eq_zero_iff := by intro k rcases n with - | n · simp [zero_dvd_iff, Int.natCast_eq_zero] · exact Fin.natCast_eq_zero @[simp] theorem addOrderOf_one (n : ℕ) : addOrderOf (1 : ZMod n) = n := CharP.eq _ (CharP.addOrderOf_one _) (ZMod.charP n) /-- This lemma works in the case in which `ZMod n` is not infinite, i.e. `n ≠ 0`. The version where `a ≠ 0` is `addOrderOf_coe'`. -/ @[simp] theorem addOrderOf_coe (a : ℕ) {n : ℕ} (n0 : n ≠ 0) : addOrderOf (a : ZMod n) = n / n.gcd a := by rcases a with - | a · simp only [Nat.cast_zero, addOrderOf_zero, Nat.gcd_zero_right, Nat.pos_of_ne_zero n0, Nat.div_self] rw [← Nat.smul_one_eq_cast, addOrderOf_nsmul' _ a.succ_ne_zero, ZMod.addOrderOf_one] /-- This lemma works in the case in which `a ≠ 0`. The version where `ZMod n` is not infinite, i.e. `n ≠ 0`, is `addOrderOf_coe`. -/ @[simp] theorem addOrderOf_coe' {a : ℕ} (n : ℕ) (a0 : a ≠ 0) : addOrderOf (a : ZMod n) = n / n.gcd a := by rw [← Nat.smul_one_eq_cast, addOrderOf_nsmul' _ a0, ZMod.addOrderOf_one] /-- We have that `ringChar (ZMod n) = n`. -/ theorem ringChar_zmod_n (n : ℕ) : ringChar (ZMod n) = n := by rw [ringChar.eq_iff] exact ZMod.charP n theorem natCast_self (n : ℕ) : (n : ZMod n) = 0 := CharP.cast_eq_zero (ZMod n) n @[simp] theorem natCast_self' (n : ℕ) : (n + 1 : ZMod (n + 1)) = 0 := by rw [← Nat.cast_add_one, natCast_self (n + 1)] section UniversalProperty variable {n : ℕ} {R : Type*} section variable [AddGroupWithOne R] /-- Cast an integer modulo `n` to another semiring. This function is a morphism if the characteristic of `R` divides `n`. See `ZMod.castHom` for a bundled version. -/ def cast : ∀ {n : ℕ}, ZMod n → R | 0 => Int.cast | _ + 1 => fun i => i.val @[simp] theorem cast_zero : (cast (0 : ZMod n) : R) = 0 := by delta ZMod.cast cases n · exact Int.cast_zero · simp theorem cast_eq_val [NeZero n] (a : ZMod n) : (cast a : R) = a.val := by cases n · cases NeZero.ne 0 rfl rfl variable {S : Type*} [AddGroupWithOne S] @[simp] theorem _root_.Prod.fst_zmod_cast (a : ZMod n) : (cast a : R × S).fst = cast a := by cases n · rfl · simp [ZMod.cast] @[simp] theorem _root_.Prod.snd_zmod_cast (a : ZMod n) : (cast a : R × S).snd = cast a := by cases n · rfl · simp [ZMod.cast] end /-- So-named because the coercion is `Nat.cast` into `ZMod`. For `Nat.cast` into an arbitrary ring, see `ZMod.natCast_val`. -/ theorem natCast_zmod_val {n : ℕ} [NeZero n] (a : ZMod n) : (a.val : ZMod n) = a := by cases n · cases NeZero.ne 0 rfl · apply Fin.cast_val_eq_self theorem natCast_rightInverse [NeZero n] : Function.RightInverse val ((↑) : ℕ → ZMod n) := natCast_zmod_val theorem natCast_zmod_surjective [NeZero n] : Function.Surjective ((↑) : ℕ → ZMod n) := natCast_rightInverse.surjective /-- So-named because the outer coercion is `Int.cast` into `ZMod`. For `Int.cast` into an arbitrary ring, see `ZMod.intCast_cast`. -/ @[norm_cast] theorem intCast_zmod_cast (a : ZMod n) : ((cast a : ℤ) : ZMod n) = a := by cases n · simp [ZMod.cast, ZMod] · dsimp [ZMod.cast] rw [Int.cast_natCast, natCast_zmod_val] theorem intCast_rightInverse : Function.RightInverse (cast : ZMod n → ℤ) ((↑) : ℤ → ZMod n) := intCast_zmod_cast theorem intCast_surjective : Function.Surjective ((↑) : ℤ → ZMod n) := intCast_rightInverse.surjective lemma «forall» {P : ZMod n → Prop} : (∀ x, P x) ↔ ∀ x : ℤ, P x := intCast_surjective.forall lemma «exists» {P : ZMod n → Prop} : (∃ x, P x) ↔ ∃ x : ℤ, P x := intCast_surjective.exists theorem cast_id : ∀ (n) (i : ZMod n), (ZMod.cast i : ZMod n) = i | 0, _ => Int.cast_id | _ + 1, i => natCast_zmod_val i @[simp] theorem cast_id' : (ZMod.cast : ZMod n → ZMod n) = id := funext (cast_id n) variable (R) [Ring R] /-- The coercions are respectively `Nat.cast` and `ZMod.cast`. -/ @[simp] theorem natCast_comp_val [NeZero n] : ((↑) : ℕ → R) ∘ (val : ZMod n → ℕ) = cast := by cases n · cases NeZero.ne 0 rfl rfl /-- The coercions are respectively `Int.cast`, `ZMod.cast`, and `ZMod.cast`. -/ @[simp] theorem intCast_comp_cast : ((↑) : ℤ → R) ∘ (cast : ZMod n → ℤ) = cast := by cases n · exact congr_arg (Int.cast ∘ ·) ZMod.cast_id' · ext simp [ZMod, ZMod.cast] variable {R} @[simp] theorem natCast_val [NeZero n] (i : ZMod n) : (i.val : R) = cast i := congr_fun (natCast_comp_val R) i @[simp] theorem intCast_cast (i : ZMod n) : ((cast i : ℤ) : R) = cast i := congr_fun (intCast_comp_cast R) i theorem cast_add_eq_ite {n : ℕ} (a b : ZMod n) : (cast (a + b) : ℤ) = if (n : ℤ) ≤ cast a + cast b then (cast a + cast b - n : ℤ) else cast a + cast b := by rcases n with - | n · simp; rfl change Fin (n + 1) at a b change ((((a + b) : Fin (n + 1)) : ℕ) : ℤ) = if ((n + 1 : ℕ) : ℤ) ≤ (a : ℕ) + b then _ else _ simp only [Fin.val_add_eq_ite, Int.natCast_succ, Int.ofNat_le] norm_cast split_ifs with h · rw [Nat.cast_sub h] congr · rfl section CharDvd /-! If the characteristic of `R` divides `n`, then `cast` is a homomorphism. -/ variable {m : ℕ} [CharP R m] @[simp] theorem cast_one (h : m ∣ n) : (cast (1 : ZMod n) : R) = 1 := by rcases n with - | n · exact Int.cast_one show ((1 % (n + 1) : ℕ) : R) = 1 cases n · rw [Nat.dvd_one] at h subst m subsingleton [CharP.CharOne.subsingleton] rw [Nat.mod_eq_of_lt] · exact Nat.cast_one exact Nat.lt_of_sub_eq_succ rfl theorem cast_add (h : m ∣ n) (a b : ZMod n) : (cast (a + b : ZMod n) : R) = cast a + cast b := by cases n · apply Int.cast_add symm dsimp [ZMod, ZMod.cast, ZMod.val] rw [← Nat.cast_add, Fin.val_add, ← sub_eq_zero, ← Nat.cast_sub (Nat.mod_le _ _), @CharP.cast_eq_zero_iff R _ m] exact h.trans (Nat.dvd_sub_mod _) theorem cast_mul (h : m ∣ n) (a b : ZMod n) : (cast (a * b : ZMod n) : R) = cast a * cast b := by cases n · apply Int.cast_mul symm dsimp [ZMod, ZMod.cast, ZMod.val] rw [← Nat.cast_mul, Fin.val_mul, ← sub_eq_zero, ← Nat.cast_sub (Nat.mod_le _ _), @CharP.cast_eq_zero_iff R _ m] exact h.trans (Nat.dvd_sub_mod _) /-- The canonical ring homomorphism from `ZMod n` to a ring of characteristic dividing `n`. See also `ZMod.lift` for a generalized version working in `AddGroup`s. -/ def castHom (h : m ∣ n) (R : Type*) [Ring R] [CharP R m] : ZMod n →+* R where toFun := cast map_zero' := cast_zero map_one' := cast_one h map_add' := cast_add h map_mul' := cast_mul h @[simp] theorem castHom_apply {h : m ∣ n} (i : ZMod n) : castHom h R i = cast i := rfl @[simp] theorem cast_sub (h : m ∣ n) (a b : ZMod n) : (cast (a - b : ZMod n) : R) = cast a - cast b := (castHom h R).map_sub a b @[simp] theorem cast_neg (h : m ∣ n) (a : ZMod n) : (cast (-a : ZMod n) : R) = -(cast a) := (castHom h R).map_neg a @[simp] theorem cast_pow (h : m ∣ n) (a : ZMod n) (k : ℕ) : (cast (a ^ k : ZMod n) : R) = (cast a) ^ k := (castHom h R).map_pow a k @[simp, norm_cast] theorem cast_natCast (h : m ∣ n) (k : ℕ) : (cast (k : ZMod n) : R) = k := map_natCast (castHom h R) k @[simp, norm_cast] theorem cast_intCast (h : m ∣ n) (k : ℤ) : (cast (k : ZMod n) : R) = k := map_intCast (castHom h R) k end CharDvd section CharEq /-! Some specialised simp lemmas which apply when `R` has characteristic `n`. -/ variable [CharP R n] @[simp] theorem cast_one' : (cast (1 : ZMod n) : R) = 1 := cast_one dvd_rfl @[simp] theorem cast_add' (a b : ZMod n) : (cast (a + b : ZMod n) : R) = cast a + cast b := cast_add dvd_rfl a b @[simp] theorem cast_mul' (a b : ZMod n) : (cast (a * b : ZMod n) : R) = cast a * cast b := cast_mul dvd_rfl a b @[simp] theorem cast_sub' (a b : ZMod n) : (cast (a - b : ZMod n) : R) = cast a - cast b := cast_sub dvd_rfl a b @[simp] theorem cast_pow' (a : ZMod n) (k : ℕ) : (cast (a ^ k : ZMod n) : R) = (cast a : R) ^ k := cast_pow dvd_rfl a k @[simp, norm_cast] theorem cast_natCast' (k : ℕ) : (cast (k : ZMod n) : R) = k := cast_natCast dvd_rfl k @[simp, norm_cast] theorem cast_intCast' (k : ℤ) : (cast (k : ZMod n) : R) = k := cast_intCast dvd_rfl k variable (R) theorem castHom_injective : Function.Injective (ZMod.castHom (dvd_refl n) R) := by rw [injective_iff_map_eq_zero] intro x obtain ⟨k, rfl⟩ := ZMod.intCast_surjective x rw [map_intCast, CharP.intCast_eq_zero_iff R n, CharP.intCast_eq_zero_iff (ZMod n) n] exact id theorem castHom_bijective [Fintype R] (h : Fintype.card R = n) : Function.Bijective (ZMod.castHom (dvd_refl n) R) := by haveI : NeZero n := ⟨by intro hn rw [hn] at h exact (Fintype.card_eq_zero_iff.mp h).elim' 0⟩ rw [Fintype.bijective_iff_injective_and_card, ZMod.card, h, eq_self_iff_true, and_true] apply ZMod.castHom_injective /-- The unique ring isomorphism between `ZMod n` and a ring `R` of characteristic `n` and cardinality `n`. -/ noncomputable def ringEquiv [Fintype R] (h : Fintype.card R = n) : ZMod n ≃+* R := RingEquiv.ofBijective _ (ZMod.castHom_bijective R h) /-- The unique ring isomorphism between `ZMod p` and a ring `R` of cardinality a prime `p`. If you need any property of this isomorphism, first of all use `ringEquivOfPrime_eq_ringEquiv` below (after `have : CharP R p := ...`) and deduce it by the results about `ZMod.ringEquiv`. -/ noncomputable def ringEquivOfPrime [Fintype R] {p : ℕ} (hp : p.Prime) (hR : Fintype.card R = p) : ZMod p ≃+* R := have : Nontrivial R := Fintype.one_lt_card_iff_nontrivial.1 (hR ▸ hp.one_lt) -- The following line exists as `charP_of_card_eq_prime` in `Mathlib.Algebra.CharP.CharAndCard`. have : CharP R p := (CharP.charP_iff_prime_eq_zero hp).2 (hR ▸ Nat.cast_card_eq_zero R) ZMod.ringEquiv R hR @[simp] lemma ringEquivOfPrime_eq_ringEquiv [Fintype R] {p : ℕ} [CharP R p] (hp : p.Prime) (hR : Fintype.card R = p) : ringEquivOfPrime R hp hR = ringEquiv R hR := rfl /-- The identity between `ZMod m` and `ZMod n` when `m = n`, as a ring isomorphism. -/ def ringEquivCongr {m n : ℕ} (h : m = n) : ZMod m ≃+* ZMod n := by rcases m with - | m <;> rcases n with - | n · exact RingEquiv.refl _ · exfalso exact n.succ_ne_zero h.symm · exfalso exact m.succ_ne_zero h · exact { finCongr h with map_mul' := fun a b => by dsimp [ZMod] ext rw [Fin.coe_cast, Fin.coe_mul, Fin.coe_mul, Fin.coe_cast, Fin.coe_cast, ← h] map_add' := fun a b => by dsimp [ZMod] ext rw [Fin.coe_cast, Fin.val_add, Fin.val_add, Fin.coe_cast, Fin.coe_cast, ← h] } @[simp] lemma ringEquivCongr_refl (a : ℕ) : ringEquivCongr (rfl : a = a) = .refl _ := by cases a <;> rfl lemma ringEquivCongr_refl_apply {a : ℕ} (x : ZMod a) : ringEquivCongr rfl x = x := by rw [ringEquivCongr_refl] rfl lemma ringEquivCongr_symm {a b : ℕ} (hab : a = b) : (ringEquivCongr hab).symm = ringEquivCongr hab.symm := by subst hab cases a <;> rfl lemma ringEquivCongr_trans {a b c : ℕ} (hab : a = b) (hbc : b = c) : (ringEquivCongr hab).trans (ringEquivCongr hbc) = ringEquivCongr (hab.trans hbc) := by subst hab hbc cases a <;> rfl lemma ringEquivCongr_ringEquivCongr_apply {a b c : ℕ} (hab : a = b) (hbc : b = c) (x : ZMod a) : ringEquivCongr hbc (ringEquivCongr hab x) = ringEquivCongr (hab.trans hbc) x := by rw [← ringEquivCongr_trans hab hbc] rfl lemma ringEquivCongr_val {a b : ℕ} (h : a = b) (x : ZMod a) : ZMod.val ((ZMod.ringEquivCongr h) x) = ZMod.val x := by subst h cases a <;> rfl lemma ringEquivCongr_intCast {a b : ℕ} (h : a = b) (z : ℤ) : ZMod.ringEquivCongr h z = z := by subst h cases a <;> rfl end CharEq end UniversalProperty variable {m n : ℕ} @[simp] theorem val_eq_zero : ∀ {n : ℕ} (a : ZMod n), a.val = 0 ↔ a = 0 | 0, _ => Int.natAbs_eq_zero | n + 1, a => by rw [Fin.ext_iff] exact Iff.rfl theorem intCast_eq_intCast_iff (a b : ℤ) (c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a ≡ b [ZMOD c] := CharP.intCast_eq_intCast (ZMod c) c theorem intCast_eq_intCast_iff' (a b : ℤ) (c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a % c = b % c := ZMod.intCast_eq_intCast_iff a b c theorem val_intCast {n : ℕ} (a : ℤ) [NeZero n] : ↑(a : ZMod n).val = a % n := by have hle : (0 : ℤ) ≤ ↑(a : ZMod n).val := Int.natCast_nonneg _ have hlt : ↑(a : ZMod n).val < (n : ℤ) := Int.ofNat_lt.mpr (ZMod.val_lt a) refine (Int.emod_eq_of_lt hle hlt).symm.trans ?_ rw [← ZMod.intCast_eq_intCast_iff', Int.cast_natCast, ZMod.natCast_val, ZMod.cast_id] theorem natCast_eq_natCast_iff (a b c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a ≡ b [MOD c] := by simpa [Int.natCast_modEq_iff] using ZMod.intCast_eq_intCast_iff a b c theorem natCast_eq_natCast_iff' (a b c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a % c = b % c := ZMod.natCast_eq_natCast_iff a b c theorem intCast_zmod_eq_zero_iff_dvd (a : ℤ) (b : ℕ) : (a : ZMod b) = 0 ↔ (b : ℤ) ∣ a := by rw [← Int.cast_zero, ZMod.intCast_eq_intCast_iff, Int.modEq_zero_iff_dvd] theorem intCast_eq_intCast_iff_dvd_sub (a b : ℤ) (c : ℕ) : (a : ZMod c) = ↑b ↔ ↑c ∣ b - a := by rw [ZMod.intCast_eq_intCast_iff, Int.modEq_iff_dvd] theorem natCast_zmod_eq_zero_iff_dvd (a b : ℕ) : (a : ZMod b) = 0 ↔ b ∣ a := by rw [← Nat.cast_zero, ZMod.natCast_eq_natCast_iff, Nat.modEq_zero_iff_dvd] theorem coe_intCast (a : ℤ) : cast (a : ZMod n) = a % n := by cases n · rw [Int.ofNat_zero, Int.emod_zero, Int.cast_id]; rfl · rw [← val_intCast, val]; rfl lemma intCast_cast_add (x y : ZMod n) : (cast (x + y) : ℤ) = (cast x + cast y) % n := by rw [← ZMod.coe_intCast, Int.cast_add, ZMod.intCast_zmod_cast, ZMod.intCast_zmod_cast] lemma intCast_cast_mul (x y : ZMod n) : (cast (x * y) : ℤ) = cast x * cast y % n := by rw [← ZMod.coe_intCast, Int.cast_mul, ZMod.intCast_zmod_cast, ZMod.intCast_zmod_cast] lemma intCast_cast_sub (x y : ZMod n) : (cast (x - y) : ℤ) = (cast x - cast y) % n := by rw [← ZMod.coe_intCast, Int.cast_sub, ZMod.intCast_zmod_cast, ZMod.intCast_zmod_cast] lemma intCast_cast_neg (x : ZMod n) : (cast (-x) : ℤ) = -cast x % n := by rw [← ZMod.coe_intCast, Int.cast_neg, ZMod.intCast_zmod_cast] @[simp] theorem val_neg_one (n : ℕ) : (-1 : ZMod n.succ).val = n := by dsimp [val, Fin.coe_neg] cases n · simp [Nat.mod_one] · dsimp [ZMod, ZMod.cast] rw [Fin.coe_neg_one] /-- `-1 : ZMod n` lifts to `n - 1 : R`. This avoids the characteristic assumption in `cast_neg`. -/ theorem cast_neg_one {R : Type*} [Ring R] (n : ℕ) : cast (-1 : ZMod n) = (n - 1 : R) := by rcases n with - | n · dsimp [ZMod, ZMod.cast]; simp · rw [← natCast_val, val_neg_one, Nat.cast_succ, add_sub_cancel_right] theorem cast_sub_one {R : Type*} [Ring R] {n : ℕ} (k : ZMod n) : (cast (k - 1 : ZMod n) : R) = (if k = 0 then (n : R) else cast k) - 1 := by split_ifs with hk · rw [hk, zero_sub, ZMod.cast_neg_one] · cases n · dsimp [ZMod, ZMod.cast] rw [Int.cast_sub, Int.cast_one] · dsimp [ZMod, ZMod.cast, ZMod.val] rw [Fin.coe_sub_one, if_neg] · rw [Nat.cast_sub, Nat.cast_one] rwa [Fin.ext_iff, Fin.val_zero, ← Ne, ← Nat.one_le_iff_ne_zero] at hk · exact hk theorem natCast_eq_iff (p : ℕ) (n : ℕ) (z : ZMod p) [NeZero p] : ↑n = z ↔ ∃ k, n = z.val + p * k := by constructor · rintro rfl refine ⟨n / p, ?_⟩ rw [val_natCast, Nat.mod_add_div] · rintro ⟨k, rfl⟩ rw [Nat.cast_add, natCast_zmod_val, Nat.cast_mul, natCast_self, zero_mul, add_zero] theorem intCast_eq_iff (p : ℕ) (n : ℤ) (z : ZMod p) [NeZero p] : ↑n = z ↔ ∃ k, n = z.val + p * k := by constructor · rintro rfl refine ⟨n / p, ?_⟩ rw [val_intCast, Int.emod_add_ediv] · rintro ⟨k, rfl⟩ rw [Int.cast_add, Int.cast_mul, Int.cast_natCast, Int.cast_natCast, natCast_val, ZMod.natCast_self, zero_mul, add_zero, cast_id] @[push_cast, simp] theorem intCast_mod (a : ℤ) (b : ℕ) : ((a % b : ℤ) : ZMod b) = (a : ZMod b) := by rw [ZMod.intCast_eq_intCast_iff] apply Int.mod_modEq theorem ker_intCastAddHom (n : ℕ) : (Int.castAddHom (ZMod n)).ker = AddSubgroup.zmultiples (n : ℤ) := by ext rw [Int.mem_zmultiples_iff, AddMonoidHom.mem_ker, Int.coe_castAddHom, intCast_zmod_eq_zero_iff_dvd] theorem cast_injective_of_le {m n : ℕ} [nzm : NeZero m] (h : m ≤ n) : Function.Injective (@cast (ZMod n) _ m) := by cases m with | zero => cases nzm; simp_all | succ m => rintro ⟨x, hx⟩ ⟨y, hy⟩ f simp only [cast, val, natCast_eq_natCast_iff', Nat.mod_eq_of_lt (hx.trans_le h), Nat.mod_eq_of_lt (hy.trans_le h)] at f apply Fin.ext exact f theorem cast_zmod_eq_zero_iff_of_le {m n : ℕ} [NeZero m] (h : m ≤ n) (a : ZMod m) : (cast a : ZMod n) = 0 ↔ a = 0 := by rw [← ZMod.cast_zero (n := m)] exact Injective.eq_iff' (cast_injective_of_le h) rfl @[simp] theorem natCast_toNat (p : ℕ) : ∀ {z : ℤ} (_h : 0 ≤ z), (z.toNat : ZMod p) = z | (n : ℕ), _h => by simp only [Int.cast_natCast, Int.toNat_natCast] | Int.negSucc n, h => by simp at h theorem val_injective (n : ℕ) [NeZero n] : Function.Injective (val : ZMod n → ℕ) := by cases n · cases NeZero.ne 0 rfl intro a b h dsimp [ZMod] ext exact h theorem val_one_eq_one_mod (n : ℕ) : (1 : ZMod n).val = 1 % n := by rw [← Nat.cast_one, val_natCast] theorem val_two_eq_two_mod (n : ℕ) : (2 : ZMod n).val = 2 % n := by rw [← Nat.cast_two, val_natCast] theorem val_one (n : ℕ) [Fact (1 < n)] : (1 : ZMod n).val = 1 := by rw [val_one_eq_one_mod] exact Nat.mod_eq_of_lt Fact.out lemma val_one'' : ∀ {n}, n ≠ 1 → (1 : ZMod n).val = 1 | 0, _ => rfl | 1, hn => by cases hn rfl | n + 2, _ => haveI : Fact (1 < n + 2) := ⟨by simp⟩ ZMod.val_one _ theorem val_add {n : ℕ} [NeZero n] (a b : ZMod n) : (a + b).val = (a.val + b.val) % n := by cases n · cases NeZero.ne 0 rfl · apply Fin.val_add theorem val_add_of_lt {n : ℕ} {a b : ZMod n} (h : a.val + b.val < n) : (a + b).val = a.val + b.val := by have : NeZero n := by constructor; rintro rfl; simp at h rw [ZMod.val_add, Nat.mod_eq_of_lt h] theorem val_add_val_of_le {n : ℕ} [NeZero n] {a b : ZMod n} (h : n ≤ a.val + b.val) : a.val + b.val = (a + b).val + n := by rw [val_add, Nat.add_mod_add_of_le_add_mod, Nat.mod_eq_of_lt (val_lt _), Nat.mod_eq_of_lt (val_lt _)] rwa [Nat.mod_eq_of_lt (val_lt _), Nat.mod_eq_of_lt (val_lt _)] theorem val_add_of_le {n : ℕ} [NeZero n] {a b : ZMod n} (h : n ≤ a.val + b.val) : (a + b).val = a.val + b.val - n := by rw [val_add_val_of_le h] exact eq_tsub_of_add_eq rfl theorem val_add_le {n : ℕ} (a b : ZMod n) : (a + b).val ≤ a.val + b.val := by cases n · simpa [ZMod.val] using Int.natAbs_add_le _ _ · simpa [ZMod.val_add] using Nat.mod_le _ _ theorem val_mul {n : ℕ} (a b : ZMod n) : (a * b).val = a.val * b.val % n := by cases n · rw [Nat.mod_zero] apply Int.natAbs_mul · apply Fin.val_mul theorem val_mul_le {n : ℕ} (a b : ZMod n) : (a * b).val ≤ a.val * b.val := by rw [val_mul] apply Nat.mod_le theorem val_mul_of_lt {n : ℕ} {a b : ZMod n} (h : a.val * b.val < n) : (a * b).val = a.val * b.val := by rw [val_mul] apply Nat.mod_eq_of_lt h theorem val_mul_iff_lt {n : ℕ} [NeZero n] (a b : ZMod n) : (a * b).val = a.val * b.val ↔ a.val * b.val < n := by constructor <;> intro h · rw [← h]; apply ZMod.val_lt · apply ZMod.val_mul_of_lt h instance nontrivial (n : ℕ) [Fact (1 < n)] : Nontrivial (ZMod n) := ⟨⟨0, 1, fun h => zero_ne_one <| calc 0 = (0 : ZMod n).val := by rw [val_zero] _ = (1 : ZMod n).val := congr_arg ZMod.val h _ = 1 := val_one n ⟩⟩ instance nontrivial' : Nontrivial (ZMod 0) := by delta ZMod; infer_instance lemma one_eq_zero_iff {n : ℕ} : (1 : ZMod n) = 0 ↔ n = 1 := by rw [← Nat.cast_one, natCast_zmod_eq_zero_iff_dvd, Nat.dvd_one] /-- The inversion on `ZMod n`. It is setup in such a way that `a * a⁻¹` is equal to `gcd a.val n`. In particular, if `a` is coprime to `n`, and hence a unit, `a * a⁻¹ = 1`. -/ def inv : ∀ n : ℕ, ZMod n → ZMod n | 0, i => Int.sign i | n + 1, i => Nat.gcdA i.val (n + 1) instance (n : ℕ) : Inv (ZMod n) := ⟨inv n⟩ theorem inv_zero : ∀ n : ℕ, (0 : ZMod n)⁻¹ = 0 | 0 => Int.sign_zero | n + 1 => show (Nat.gcdA _ (n + 1) : ZMod (n + 1)) = 0 by rw [val_zero] unfold Nat.gcdA Nat.xgcd Nat.xgcdAux rfl theorem mul_inv_eq_gcd {n : ℕ} (a : ZMod n) : a * a⁻¹ = Nat.gcd a.val n := by rcases n with - | n · dsimp [ZMod] at a ⊢ calc _ = a * Int.sign a := rfl _ = a.natAbs := by rw [Int.mul_sign_self] _ = a.natAbs.gcd 0 := by rw [Nat.gcd_zero_right] · calc a * a⁻¹ = a * a⁻¹ + n.succ * Nat.gcdB (val a) n.succ := by rw [natCast_self, zero_mul, add_zero] _ = ↑(↑a.val * Nat.gcdA (val a) n.succ + n.succ * Nat.gcdB (val a) n.succ) := by push_cast rw [natCast_zmod_val] rfl _ = Nat.gcd a.val n.succ := by rw [← Nat.gcd_eq_gcd_ab a.val n.succ]; rfl @[simp] protected lemma inv_one (n : ℕ) : (1⁻¹ : ZMod n) = 1 := by obtain rfl | hn := eq_or_ne n 1 · exact Subsingleton.elim _ _ · simpa [ZMod.val_one'' hn] using mul_inv_eq_gcd (1 : ZMod n) @[simp] theorem natCast_mod (a : ℕ) (n : ℕ) : ((a % n : ℕ) : ZMod n) = a := by conv => rhs rw [← Nat.mod_add_div a n] simp theorem eq_iff_modEq_nat (n : ℕ) {a b : ℕ} : (a : ZMod n) = b ↔ a ≡ b [MOD n] := by cases n · simp [Nat.ModEq, Int.natCast_inj, Nat.mod_zero] · rw [Fin.ext_iff, Nat.ModEq, ← val_natCast, ← val_natCast] exact Iff.rfl theorem eq_zero_iff_even {n : ℕ} : (n : ZMod 2) = 0 ↔ Even n := (CharP.cast_eq_zero_iff (ZMod 2) 2 n).trans even_iff_two_dvd.symm theorem eq_one_iff_odd {n : ℕ} : (n : ZMod 2) = 1 ↔ Odd n := by rw [← @Nat.cast_one (ZMod 2), ZMod.eq_iff_modEq_nat, Nat.odd_iff, Nat.ModEq] theorem ne_zero_iff_odd {n : ℕ} : (n : ZMod 2) ≠ 0 ↔ Odd n := by constructor <;> · contrapose simp [eq_zero_iff_even] theorem coe_mul_inv_eq_one {n : ℕ} (x : ℕ) (h : Nat.Coprime x n) : ((x : ZMod n) * (x : ZMod n)⁻¹) = 1 := by rw [Nat.Coprime, Nat.gcd_comm, Nat.gcd_rec] at h rw [mul_inv_eq_gcd, val_natCast, h, Nat.cast_one] lemma mul_val_inv (hmn : m.Coprime n) : (m * (m⁻¹ : ZMod n).val : ZMod n) = 1 := by obtain rfl | hn := eq_or_ne n 0 · simp [m.coprime_zero_right.1 hmn] haveI : NeZero n := ⟨hn⟩ rw [ZMod.natCast_zmod_val, ZMod.coe_mul_inv_eq_one _ hmn] lemma val_inv_mul (hmn : m.Coprime n) : ((m⁻¹ : ZMod n).val * m : ZMod n) = 1 := by rw [mul_comm, mul_val_inv hmn] /-- `unitOfCoprime` makes an element of `(ZMod n)ˣ` given a natural number `x` and a proof that `x` is coprime to `n` -/ def unitOfCoprime {n : ℕ} (x : ℕ) (h : Nat.Coprime x n) : (ZMod n)ˣ := ⟨x, x⁻¹, coe_mul_inv_eq_one x h, by rw [mul_comm, coe_mul_inv_eq_one x h]⟩ @[simp] theorem coe_unitOfCoprime {n : ℕ} (x : ℕ) (h : Nat.Coprime x n) : (unitOfCoprime x h : ZMod n) = x := rfl theorem val_coe_unit_coprime {n : ℕ} (u : (ZMod n)ˣ) : Nat.Coprime (u : ZMod n).val n := by rcases n with - | n · rcases Int.units_eq_one_or u with (rfl | rfl) <;> simp apply Nat.coprime_of_mul_modEq_one ((u⁻¹ : Units (ZMod (n + 1))) : ZMod (n + 1)).val have := Units.ext_iff.1 (mul_inv_cancel u) rw [Units.val_one] at this rw [← eq_iff_modEq_nat, Nat.cast_one, ← this]; clear this rw [← natCast_zmod_val ((u * u⁻¹ : Units (ZMod (n + 1))) : ZMod (n + 1))] rw [Units.val_mul, val_mul, natCast_mod] lemma isUnit_iff_coprime (m n : ℕ) : IsUnit (m : ZMod n) ↔ m.Coprime n := by refine ⟨fun H ↦ ?_, fun H ↦ (unitOfCoprime m H).isUnit⟩ have H' := val_coe_unit_coprime H.unit rw [IsUnit.unit_spec, val_natCast, Nat.coprime_iff_gcd_eq_one] at H' rw [Nat.coprime_iff_gcd_eq_one, Nat.gcd_comm, ← H'] exact Nat.gcd_rec n m lemma isUnit_prime_iff_not_dvd {n p : ℕ} (hp : p.Prime) : IsUnit (p : ZMod n) ↔ ¬p ∣ n := by rw [isUnit_iff_coprime, Nat.Prime.coprime_iff_not_dvd hp] lemma isUnit_prime_of_not_dvd {n p : ℕ} (hp : p.Prime) (h : ¬ p ∣ n) : IsUnit (p : ZMod n) := (isUnit_prime_iff_not_dvd hp).mpr h @[simp] theorem inv_coe_unit {n : ℕ} (u : (ZMod n)ˣ) : (u : ZMod n)⁻¹ = (u⁻¹ : (ZMod n)ˣ) := by have := congr_arg ((↑) : ℕ → ZMod n) (val_coe_unit_coprime u) rw [← mul_inv_eq_gcd, Nat.cast_one] at this let u' : (ZMod n)ˣ := ⟨u, (u : ZMod n)⁻¹, this, by rwa [mul_comm]⟩ have h : u = u' := by apply Units.ext rfl rw [h] rfl theorem mul_inv_of_unit {n : ℕ} (a : ZMod n) (h : IsUnit a) : a * a⁻¹ = 1 := by rcases h with ⟨u, rfl⟩ rw [inv_coe_unit, u.mul_inv] theorem inv_mul_of_unit {n : ℕ} (a : ZMod n) (h : IsUnit a) : a⁻¹ * a = 1 := by rw [mul_comm, mul_inv_of_unit a h] -- TODO: If we changed `⁻¹` so that `ZMod n` is always a `DivisionMonoid`, -- then we could use the general lemma `inv_eq_of_mul_eq_one` protected theorem inv_eq_of_mul_eq_one (n : ℕ) (a b : ZMod n) (h : a * b = 1) : a⁻¹ = b := left_inv_eq_right_inv (inv_mul_of_unit a ⟨⟨a, b, h, mul_comm a b ▸ h⟩, rfl⟩) h lemma inv_mul_eq_one_of_isUnit {n : ℕ} {a : ZMod n} (ha : IsUnit a) (b : ZMod n) : a⁻¹ * b = 1 ↔ a = b := by -- ideally, this would be `ha.inv_mul_eq_one`, but `ZMod n` is not a `DivisionMonoid`... -- (see the "TODO" above) refine ⟨fun H ↦ ?_, fun H ↦ H ▸ a.inv_mul_of_unit ha⟩ apply_fun (a * ·) at H rwa [← mul_assoc, a.mul_inv_of_unit ha, one_mul, mul_one, eq_comm] at H -- TODO: this equivalence is true for `ZMod 0 = ℤ`, but needs to use different functions. /-- Equivalence between the units of `ZMod n` and the subtype of terms `x : ZMod n` for which `x.val` is coprime to `n` -/ def unitsEquivCoprime {n : ℕ} [NeZero n] : (ZMod n)ˣ ≃ { x : ZMod n // Nat.Coprime x.val n } where toFun x := ⟨x, val_coe_unit_coprime x⟩ invFun x := unitOfCoprime x.1.val x.2 left_inv := fun ⟨_, _, _, _⟩ => Units.ext (natCast_zmod_val _) right_inv := fun ⟨_, _⟩ => by simp /-- The **Chinese remainder theorem**. For a pair of coprime natural numbers, `m` and `n`, the rings `ZMod (m * n)` and `ZMod m × ZMod n` are isomorphic. See `Ideal.quotientInfRingEquivPiQuotient` for the Chinese remainder theorem for ideals in any ring. -/ def chineseRemainder {m n : ℕ} (h : m.Coprime n) : ZMod (m * n) ≃+* ZMod m × ZMod n := let to_fun : ZMod (m * n) → ZMod m × ZMod n := ZMod.castHom (show m.lcm n ∣ m * n by simp [Nat.lcm_dvd_iff]) (ZMod m × ZMod n) let inv_fun : ZMod m × ZMod n → ZMod (m * n) := fun x => if m * n = 0 then if m = 1 then cast (RingHom.snd _ (ZMod n) x) else cast (RingHom.fst (ZMod m) _ x) else Nat.chineseRemainder h x.1.val x.2.val have inv : Function.LeftInverse inv_fun to_fun ∧ Function.RightInverse inv_fun to_fun := if hmn0 : m * n = 0 then by rcases h.eq_of_mul_eq_zero hmn0 with (⟨rfl, rfl⟩ | ⟨rfl, rfl⟩) · constructor · intro x; rfl · rintro ⟨x, y⟩ fin_cases y simp [to_fun, inv_fun, castHom, Prod.ext_iff, eq_iff_true_of_subsingleton] · constructor · intro x; rfl · rintro ⟨x, y⟩ fin_cases x simp [to_fun, inv_fun, castHom, Prod.ext_iff, eq_iff_true_of_subsingleton] else by haveI : NeZero (m * n) := ⟨hmn0⟩ haveI : NeZero m := ⟨left_ne_zero_of_mul hmn0⟩ haveI : NeZero n := ⟨right_ne_zero_of_mul hmn0⟩ have left_inv : Function.LeftInverse inv_fun to_fun := by intro x dsimp only [to_fun, inv_fun, ZMod.castHom_apply] conv_rhs => rw [← ZMod.natCast_zmod_val x] rw [if_neg hmn0, ZMod.eq_iff_modEq_nat, ← Nat.modEq_and_modEq_iff_modEq_mul h, Prod.fst_zmod_cast, Prod.snd_zmod_cast] refine ⟨(Nat.chineseRemainder h (cast x : ZMod m).val (cast x : ZMod n).val).2.left.trans ?_, (Nat.chineseRemainder h (cast x : ZMod m).val (cast x : ZMod n).val).2.right.trans ?_⟩ · rw [← ZMod.eq_iff_modEq_nat, ZMod.natCast_zmod_val, ZMod.natCast_val] · rw [← ZMod.eq_iff_modEq_nat, ZMod.natCast_zmod_val, ZMod.natCast_val] exact ⟨left_inv, left_inv.rightInverse_of_card_le (by simp)⟩ { toFun := to_fun, invFun := inv_fun, map_mul' := RingHom.map_mul _ map_add' := RingHom.map_add _ left_inv := inv.1 right_inv := inv.2 } lemma subsingleton_iff {n : ℕ} : Subsingleton (ZMod n) ↔ n = 1 := by constructor · obtain (_ | _ | n) := n · simpa [ZMod] using not_subsingleton _ · simp [ZMod] · simpa [ZMod] using not_subsingleton _ · rintro rfl infer_instance lemma nontrivial_iff {n : ℕ} : Nontrivial (ZMod n) ↔ n ≠ 1 := by rw [← not_subsingleton_iff_nontrivial, subsingleton_iff] -- todo: this can be made a `Unique` instance. instance subsingleton_units : Subsingleton (ZMod 2)ˣ := ⟨by decide⟩ @[simp] theorem add_self_eq_zero_iff_eq_zero {n : ℕ} (hn : Odd n) {a : ZMod n} : a + a = 0 ↔ a = 0 := by rw [Nat.odd_iff, ← Nat.two_dvd_ne_zero, ← Nat.prime_two.coprime_iff_not_dvd] at hn rw [← mul_two, ← @Nat.cast_two (ZMod n), ← ZMod.coe_unitOfCoprime 2 hn, Units.mul_left_eq_zero] theorem ne_neg_self {n : ℕ} (hn : Odd n) {a : ZMod n} (ha : a ≠ 0) : a ≠ -a := by rwa [Ne, eq_neg_iff_add_eq_zero, add_self_eq_zero_iff_eq_zero hn] theorem neg_one_ne_one {n : ℕ} [Fact (2 < n)] : (-1 : ZMod n) ≠ 1 := CharP.neg_one_ne_one (ZMod n) n @[simp] theorem neg_eq_self_mod_two (a : ZMod 2) : -a = a := by fin_cases a <;> apply Fin.ext <;> simp [Fin.coe_neg, Int.natMod]; rfl @[simp] theorem natAbs_mod_two (a : ℤ) : (a.natAbs : ZMod 2) = a := by cases a · simp only [Int.natAbs_natCast, Int.cast_natCast, Int.ofNat_eq_coe] · simp only [neg_eq_self_mod_two, Nat.cast_succ, Int.natAbs, Int.cast_negSucc] theorem val_ne_zero {n : ℕ} (a : ZMod n) : a.val ≠ 0 ↔ a ≠ 0 := (val_eq_zero a).not theorem val_pos {n : ℕ} {a : ZMod n} : 0 < a.val ↔ a ≠ 0 := by simp [pos_iff_ne_zero] theorem val_eq_one : ∀ {n : ℕ} (_ : 1 < n) (a : ZMod n), a.val = 1 ↔ a = 1 | 0, hn, _ | 1, hn, _ => by simp at hn | n + 2, _, _ => by simp only [val, ZMod, Fin.ext_iff, Fin.val_one] theorem neg_eq_self_iff {n : ℕ} (a : ZMod n) : -a = a ↔ a = 0 ∨ 2 * a.val = n := by rw [neg_eq_iff_add_eq_zero, ← two_mul] cases n · rw [@mul_eq_zero ℤ, @mul_eq_zero ℕ, val_eq_zero] exact ⟨fun h => h.elim (by simp) Or.inl, fun h => Or.inr (h.elim id fun h => h.elim (by simp) id)⟩ conv_lhs => rw [← a.natCast_zmod_val, ← Nat.cast_two, ← Nat.cast_mul, natCast_zmod_eq_zero_iff_dvd] constructor · rintro ⟨m, he⟩ rcases m with - | m · rw [mul_zero, mul_eq_zero] at he rcases he with (⟨⟨⟩⟩ | he) exact Or.inl (a.val_eq_zero.1 he) cases m · right rwa [show 0 + 1 = 1 from rfl, mul_one] at he refine (a.val_lt.not_le <| Nat.le_of_mul_le_mul_left ?_ zero_lt_two).elim rw [he, mul_comm] apply Nat.mul_le_mul_left simp · rintro (rfl | h) · rw [val_zero, mul_zero] apply dvd_zero · rw [h] theorem val_cast_of_lt {n : ℕ} {a : ℕ} (h : a < n) : (a : ZMod n).val = a := by rw [val_natCast, Nat.mod_eq_of_lt h] theorem val_cast_zmod_lt {m : ℕ} [NeZero m] (n : ℕ) [NeZero n] (a : ZMod m) : (a.cast : ZMod n).val < m := by rcases m with (⟨⟩|⟨m⟩); · cases NeZero.ne 0 rfl by_cases h : m < n · rcases n with (⟨⟩|⟨n⟩); · simp at h rw [← natCast_val, val_cast_of_lt] · apply a.val_lt apply lt_of_le_of_lt (Nat.le_of_lt_succ (ZMod.val_lt a)) h · rw [not_lt] at h apply lt_of_lt_of_le (ZMod.val_lt _) (le_trans h (Nat.le_succ m)) theorem neg_val' {n : ℕ} [NeZero n] (a : ZMod n) : (-a).val = (n - a.val) % n := calc (-a).val = val (-a) % n := by rw [Nat.mod_eq_of_lt (-a).val_lt] _ = (n - val a) % n := Nat.ModEq.add_right_cancel' (val a) (by rw [Nat.ModEq, ← val_add, neg_add_cancel, tsub_add_cancel_of_le a.val_le, Nat.mod_self, val_zero]) theorem neg_val {n : ℕ} [NeZero n] (a : ZMod n) : (-a).val = if a = 0 then 0 else n - a.val := by rw [neg_val'] by_cases h : a = 0; · rw [if_pos h, h, val_zero, tsub_zero, Nat.mod_self] rw [if_neg h] apply Nat.mod_eq_of_lt apply Nat.sub_lt (NeZero.pos n) contrapose! h rwa [Nat.le_zero, val_eq_zero] at h theorem val_neg_of_ne_zero {n : ℕ} [nz : NeZero n] (a : ZMod n) [na : NeZero a] : (- a).val = n - a.val := by simp_all [neg_val a, na.out] theorem val_sub {n : ℕ} [NeZero n] {a b : ZMod n} (h : b.val ≤ a.val) : (a - b).val = a.val - b.val := by by_cases hb : b = 0 · cases hb; simp · have : NeZero b := ⟨hb⟩ rw [sub_eq_add_neg, val_add, val_neg_of_ne_zero, ← Nat.add_sub_assoc (le_of_lt (val_lt _)), add_comm, Nat.add_sub_assoc h, Nat.add_mod_left] apply Nat.mod_eq_of_lt (tsub_lt_of_lt (val_lt _)) theorem val_cast_eq_val_of_lt {m n : ℕ} [nzm : NeZero m] {a : ZMod m} (h : a.val < n) : (a.cast : ZMod n).val = a.val := by have nzn : NeZero n := by constructor; rintro rfl; simp at h cases m with | zero => cases nzm; simp_all | succ m => cases n with | zero => cases nzn; simp_all | succ n => exact Fin.val_cast_of_lt h theorem cast_cast_zmod_of_le {m n : ℕ} [hm : NeZero m] (h : m ≤ n) (a : ZMod m) : (cast (cast a : ZMod n) : ZMod m) = a := by have : NeZero n := ⟨((Nat.zero_lt_of_ne_zero hm.out).trans_le h).ne'⟩ rw [cast_eq_val, val_cast_eq_val_of_lt (a.val_lt.trans_le h), natCast_zmod_val] theorem val_pow {m n : ℕ} {a : ZMod n} [ilt : Fact (1 < n)] (h : a.val ^ m < n) : (a ^ m).val = a.val ^ m := by induction m with | zero => simp [ZMod.val_one] | succ m ih => have : a.val ^ m < n := by obtain rfl | ha := eq_or_ne a 0 · by_cases hm : m = 0 · cases hm; simp [ilt.out] · simp only [val_zero, ne_eq, hm, not_false_eq_true, zero_pow, Nat.zero_lt_of_lt h] · exact lt_of_le_of_lt (Nat.pow_le_pow_right (by rwa [gt_iff_lt, ZMod.val_pos]) (Nat.le_succ m)) h rw [pow_succ, ZMod.val_mul, ih this, ← pow_succ, Nat.mod_eq_of_lt h] theorem val_pow_le {m n : ℕ} [Fact (1 < n)] {a : ZMod n} : (a ^ m).val ≤ a.val ^ m := by induction m with | zero => simp [ZMod.val_one] | succ m ih => rw [pow_succ, pow_succ] apply le_trans (ZMod.val_mul_le _ _) apply Nat.mul_le_mul_right _ ih theorem natAbs_min_of_le_div_two (n : ℕ) (x y : ℤ) (he : (x : ZMod n) = y) (hl : x.natAbs ≤ n / 2) : x.natAbs ≤ y.natAbs := by rw [intCast_eq_intCast_iff_dvd_sub] at he obtain ⟨m, he⟩ := he rw [sub_eq_iff_eq_add] at he subst he obtain rfl | hm := eq_or_ne m 0 · rw [mul_zero, zero_add] apply hl.trans rw [← add_le_add_iff_right x.natAbs] refine le_trans (le_trans ((add_le_add_iff_left _).2 hl) ?_) (Int.natAbs_sub_le _ _) rw [add_sub_cancel_right, Int.natAbs_mul, Int.natAbs_natCast] refine le_trans ?_ (Nat.le_mul_of_pos_right _ <| Int.natAbs_pos.2 hm) rw [← mul_two]; apply Nat.div_mul_le_self end ZMod theorem RingHom.ext_zmod {n : ℕ} {R : Type*} [NonAssocSemiring R] (f g : ZMod n →+* R) : f = g := by ext a obtain ⟨k, rfl⟩ := ZMod.intCast_surjective a let φ : ℤ →+* R := f.comp (Int.castRingHom (ZMod n)) let ψ : ℤ →+* R := g.comp (Int.castRingHom (ZMod n)) show φ k = ψ k rw [φ.ext_int ψ] namespace ZMod variable {n : ℕ} {R : Type*} instance subsingleton_ringHom [Semiring R] : Subsingleton (ZMod n →+* R) := ⟨RingHom.ext_zmod⟩ instance subsingleton_ringEquiv [Semiring R] : Subsingleton (ZMod n ≃+* R) := ⟨fun f g => by rw [RingEquiv.coe_ringHom_inj_iff] apply RingHom.ext_zmod _ _⟩ @[simp] theorem ringHom_map_cast [NonAssocRing R] (f : R →+* ZMod n) (k : ZMod n) : f (cast k) = k := by cases n · dsimp [ZMod, ZMod.cast] at f k ⊢; simp · dsimp [ZMod.cast] rw [map_natCast, natCast_zmod_val] /-- Any ring homomorphism into `ZMod n` has a right inverse. -/ theorem ringHom_rightInverse [NonAssocRing R] (f : R →+* ZMod n) : Function.RightInverse (cast : ZMod n → R) f := ringHom_map_cast f /-- Any ring homomorphism into `ZMod n` is surjective. -/ theorem ringHom_surjective [NonAssocRing R] (f : R →+* ZMod n) : Function.Surjective f := (ringHom_rightInverse f).surjective @[simp] lemma castHom_self : ZMod.castHom dvd_rfl (ZMod n) = RingHom.id (ZMod n) := Subsingleton.elim _ _ @[simp] lemma castHom_comp {m d : ℕ} (hm : n ∣ m) (hd : m ∣ d) : (castHom hm (ZMod n)).comp (castHom hd (ZMod m)) = castHom (dvd_trans hm hd) (ZMod n) := RingHom.ext_zmod _ _ section lift variable (n) {A : Type*} [AddGroup A] /-- The map from `ZMod n` induced by `f : ℤ →+ A` that maps `n` to `0`. -/ def lift : { f : ℤ →+ A // f n = 0 } ≃ (ZMod n →+ A) := (Equiv.subtypeEquivRight <| by intro f rw [ker_intCastAddHom] constructor · rintro hf _ ⟨x, rfl⟩ simp only [f.map_zsmul, zsmul_zero, f.mem_ker, hf] · intro h exact h (AddSubgroup.mem_zmultiples _)).trans <| (Int.castAddHom (ZMod n)).liftOfRightInverse cast intCast_zmod_cast variable (f : { f : ℤ →+ A // f n = 0 }) @[simp] theorem lift_coe (x : ℤ) : lift n f (x : ZMod n) = f.val x := AddMonoidHom.liftOfRightInverse_comp_apply _ _ (fun _ => intCast_zmod_cast _) _ _ theorem lift_castAddHom (x : ℤ) : lift n f (Int.castAddHom (ZMod n) x) = f.1 x := AddMonoidHom.liftOfRightInverse_comp_apply _ _ (fun _ => intCast_zmod_cast _) _ _ @[simp] theorem lift_comp_coe : ZMod.lift n f ∘ ((↑) : ℤ → _) = f := funext <| lift_coe _ _ @[simp] theorem lift_comp_castAddHom : (ZMod.lift n f).comp (Int.castAddHom (ZMod n)) = f := AddMonoidHom.ext <| lift_castAddHom _ _ lemma lift_injective {f : {f : ℤ →+ A // f n = 0}} : Injective (lift n f) ↔ ∀ m, f.1 m = 0 → (m : ZMod n) = 0 := by simp only [← AddMonoidHom.ker_eq_bot_iff, eq_bot_iff, SetLike.le_def, ZMod.intCast_surjective.forall, ZMod.lift_coe, AddMonoidHom.mem_ker, AddSubgroup.mem_bot] end lift end ZMod /-! ### Groups of bounded torsion For `G` a group and `n` a natural number, `G` having torsion dividing `n` (`∀ x : G, n • x = 0`) can be derived from `Module R G` where `R` has characteristic dividing `n`. It is however painful to have the API for such groups `G` stated in this generality, as `R` does not appear anywhere in the lemmas' return type. Instead of writing the API in terms of a general `R`, we therefore specialise to the canonical ring of order `n`, namely `ZMod n`. This spelling `Module (ZMod n) G` has the extra advantage of providing the canonical action by `ZMod n`. It is however Type-valued, so we might want to acquire a Prop-valued version in the future. -/ section Module variable {n : ℕ} {S G : Type*} [AddCommGroup G] [SetLike S G] [AddSubgroupClass S G] {K : S} {x : G} section general variable [Module (ZMod n) G] {x : G} lemma zmod_smul_mem (hx : x ∈ K) : ∀ a : ZMod n, a • x ∈ K := by simpa [ZMod.forall, Int.cast_smul_eq_zsmul] using zsmul_mem hx /-- This cannot be made an instance because of the `[Module (ZMod n) G]` argument and the fact that `n` only appears in the second argument of `SMulMemClass`, which is an `OutParam`. -/ lemma smulMemClass : SMulMemClass S (ZMod n) G where smul_mem _ _ {_x} hx := zmod_smul_mem hx _ namespace AddSubgroupClass instance instZModSMul : SMul (ZMod n) K where smul a x := ⟨a • x, zmod_smul_mem x.2 _⟩ @[simp, norm_cast] lemma coe_zmod_smul (a : ZMod n) (x : K) : ↑(a • x) = (a • x : G) := rfl instance instZModModule : Module (ZMod n) K := Subtype.coe_injective.module _ (AddSubmonoidClass.subtype K) coe_zmod_smul end AddSubgroupClass variable (n) lemma ZModModule.char_nsmul_eq_zero (x : G) : n • x = 0 := by simp [← Nat.cast_smul_eq_nsmul (ZMod n)] variable (G) in lemma ZModModule.char_ne_one [Nontrivial G] : n ≠ 1 := by rintro rfl obtain ⟨x, hx⟩ := exists_ne (0 : G) exact hx <| by simpa using char_nsmul_eq_zero 1 x variable (G) in lemma ZModModule.two_le_char [NeZero n] [Nontrivial G] : 2 ≤ n := by have := NeZero.ne n have := char_ne_one n G omega lemma ZModModule.periodicPts_add_left [NeZero n] (x : G) : periodicPts (x + ·) = .univ := Set.eq_univ_of_forall fun y ↦ ⟨n, NeZero.pos n, by simpa [char_nsmul_eq_zero, IsPeriodicPt] using isFixedPt_id _⟩ end general section two variable [Module (ZMod 2) G] lemma ZModModule.add_self (x : G) : x + x = 0 := by simpa [two_nsmul] using char_nsmul_eq_zero 2 x lemma ZModModule.neg_eq_self (x : G) : -x = x := by simp [add_self, eq_comm, ← sub_eq_zero] lemma ZModModule.sub_eq_add (x y : G) : x - y = x + y := by simp [neg_eq_self, sub_eq_add_neg] lemma ZModModule.add_add_add_cancel (x y z : G) : (x + y) + (y + z) = x + z := by simpa [sub_eq_add] using sub_add_sub_cancel x y z end two end Module section AddGroup variable {α : Type*} [AddGroup α] {n : ℕ} @[simp] lemma nsmul_zmod_val_inv_nsmul (hn : (Nat.card α).Coprime n) (a : α) : n • (n⁻¹ : ZMod (Nat.card α)).val • a = a := by rw [← mul_nsmul', ← mod_natCard_nsmul, ← ZMod.val_natCast, Nat.cast_mul, ZMod.mul_val_inv hn.symm, ZMod.val_one_eq_one_mod, mod_natCard_nsmul, one_nsmul] @[simp] lemma zmod_val_inv_nsmul_nsmul (hn : (Nat.card α).Coprime n) (a : α) : (n⁻¹ : ZMod (Nat.card α)).val • n • a = a := by rw [nsmul_left_comm, nsmul_zmod_val_inv_nsmul hn] end AddGroup section Group variable {α : Type*} [Group α] {n : ℕ} -- TODO: Without the `existing`, `to_additive` chokes on `Inv (ZMod n)`. @[to_additive existing (attr := simp) nsmul_zmod_val_inv_nsmul] lemma pow_zmod_val_inv_pow (hn : (Nat.card α).Coprime n) (a : α) : (a ^ (n⁻¹ : ZMod (Nat.card α)).val) ^ n = a := by rw [← pow_mul', ← pow_mod_natCard, ← ZMod.val_natCast, Nat.cast_mul, ZMod.mul_val_inv hn.symm, ZMod.val_one_eq_one_mod, pow_mod_natCard, pow_one] @[to_additive existing (attr := simp) zmod_val_inv_nsmul_nsmul] lemma pow_pow_zmod_val_inv (hn : (Nat.card α).Coprime n) (a : α) : (a ^ n) ^ (n⁻¹ : ZMod (Nat.card α)).val = a := by rw [pow_right_comm, pow_zmod_val_inv_pow hn] end Group open ZMod /-- The range of `(m * · + k)` on natural numbers is the set of elements `≥ k` in the residue class of `k` mod `m`. -/ lemma Nat.range_mul_add (m k : ℕ) : Set.range (fun n : ℕ ↦ m * n + k) = {n : ℕ | (n : ZMod m) = k ∧ k ≤ n} := by ext n simp only [Set.mem_range, Set.mem_setOf_eq] conv => enter [1, 1, y]; rw [add_comm, eq_comm] refine ⟨fun ⟨a, ha⟩ ↦ ⟨?_, le_iff_exists_add.mpr ⟨_, ha⟩⟩, fun ⟨H₁, H₂⟩ ↦ ?_⟩ · simpa using congr_arg ((↑) : ℕ → ZMod m) ha · obtain ⟨a, ha⟩ := le_iff_exists_add.mp H₂ simp only [ha, Nat.cast_add, add_eq_left, ZMod.natCast_zmod_eq_zero_iff_dvd] at H₁ obtain ⟨b, rfl⟩ := H₁ exact ⟨b, ha⟩ /-- Equivalence between `ℕ` and `ZMod N × ℕ`, sending `n` to `(n mod N, n / N)`. -/ def Nat.residueClassesEquiv (N : ℕ) [NeZero N] : ℕ ≃ ZMod N × ℕ where toFun n := (↑n, n / N) invFun p := p.1.val + N * p.2 left_inv n := by simpa only [val_natCast] using mod_add_div n N right_inv p := by ext1 · simp only [add_comm p.1.val, cast_add, cast_mul, natCast_self, zero_mul, natCast_val, cast_id', id_eq, zero_add] · simp only [add_comm p.1.val, mul_add_div (NeZero.pos _), (Nat.div_eq_zero_iff).2 <| .inr p.1.val_lt, add_zero]
Mathlib/Data/ZMod/Basic.lean
1,309
1,313
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir -/ import Mathlib.Algebra.CharP.Defs import Mathlib.Algebra.Order.CauSeq.BigOperators import Mathlib.Algebra.Order.Star.Basic import Mathlib.Data.Complex.BigOperators import Mathlib.Data.Complex.Norm import Mathlib.Data.Nat.Choose.Sum /-! # Exponential Function This file contains the definitions of the real and complex exponential function. ## Main definitions * `Complex.exp`: The complex exponential function, defined via its Taylor series * `Real.exp`: The real exponential function, defined as the real part of the complex exponential -/ open CauSeq Finset IsAbsoluteValue open scoped ComplexConjugate namespace Complex theorem isCauSeq_norm_exp (z : ℂ) : IsCauSeq abs fun n => ∑ m ∈ range n, ‖z ^ m / m.factorial‖ := let ⟨n, hn⟩ := exists_nat_gt ‖z‖ have hn0 : (0 : ℝ) < n := lt_of_le_of_lt (norm_nonneg _) hn IsCauSeq.series_ratio_test n (‖z‖ / n) (div_nonneg (norm_nonneg _) (le_of_lt hn0)) (by rwa [div_lt_iff₀ hn0, one_mul]) fun m hm => by rw [abs_norm, abs_norm, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul, ← div_div, mul_div_assoc, mul_div_right_comm, Complex.norm_mul, Complex.norm_div, norm_natCast] gcongr exact le_trans hm (Nat.le_succ _) @[deprecated (since := "2025-02-16")] alias isCauSeq_abs_exp := isCauSeq_norm_exp noncomputable section theorem isCauSeq_exp (z : ℂ) : IsCauSeq (‖·‖) fun n => ∑ m ∈ range n, z ^ m / m.factorial := (isCauSeq_norm_exp z).of_abv /-- The Cauchy sequence consisting of partial sums of the Taylor series of the complex exponential function -/ @[pp_nodot] def exp' (z : ℂ) : CauSeq ℂ (‖·‖) := ⟨fun n => ∑ m ∈ range n, z ^ m / m.factorial, isCauSeq_exp z⟩ /-- The complex exponential function, defined via its Taylor series -/ @[pp_nodot] def exp (z : ℂ) : ℂ := CauSeq.lim (exp' z) /-- scoped notation for the complex exponential function -/ scoped notation "cexp" => Complex.exp end end Complex namespace Real open Complex noncomputable section /-- The real exponential function, defined as the real part of the complex exponential -/ @[pp_nodot] nonrec def exp (x : ℝ) : ℝ := (exp x).re /-- scoped notation for the real exponential function -/ scoped notation "rexp" => Real.exp end end Real namespace Complex variable (x y : ℂ) @[simp] theorem exp_zero : exp 0 = 1 := by rw [exp] refine lim_eq_of_equiv_const fun ε ε0 => ⟨1, fun j hj => ?_⟩ convert (config := .unfoldSameFun) ε0 -- ε0 : ε > 0 but goal is _ < ε rcases j with - | j · exact absurd hj (not_le_of_gt zero_lt_one) · dsimp [exp'] induction' j with j ih · dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl] · rw [← ih (by simp [Nat.succ_le_succ])] simp only [sum_range_succ, pow_succ] simp theorem exp_add : exp (x + y) = exp x * exp y := by have hj : ∀ j : ℕ, (∑ m ∈ range j, (x + y) ^ m / m.factorial) = ∑ i ∈ range j, ∑ k ∈ range (i + 1), x ^ k / k.factorial * (y ^ (i - k) / (i - k).factorial) := by intro j refine Finset.sum_congr rfl fun m _ => ?_ rw [add_pow, div_eq_mul_inv, sum_mul] refine Finset.sum_congr rfl fun I hi => ?_ have h₁ : (m.choose I : ℂ) ≠ 0 := Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi)))) have h₂ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi) rw [← h₂, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv] simp only [mul_left_comm (m.choose I : ℂ), mul_assoc, mul_left_comm (m.choose I : ℂ)⁻¹, mul_comm (m.choose I : ℂ)] rw [inv_mul_cancel₀ h₁] simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm] simp_rw [exp, exp', lim_mul_lim] apply (lim_eq_lim_of_equiv _).symm simp only [hj] exact cauchy_product (isCauSeq_norm_exp x) (isCauSeq_exp y) /-- the exponential function as a monoid hom from `Multiplicative ℂ` to `ℂ` -/ @[simps] noncomputable def expMonoidHom : MonoidHom (Multiplicative ℂ) ℂ := { toFun := fun z => exp z.toAdd, map_one' := by simp, map_mul' := by simp [exp_add] } theorem exp_list_sum (l : List ℂ) : exp l.sum = (l.map exp).prod := map_list_prod (M := Multiplicative ℂ) expMonoidHom l theorem exp_multiset_sum (s : Multiset ℂ) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative ℂ) ℂ _ _ expMonoidHom s theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℂ) : exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (β := Multiplicative ℂ) expMonoidHom f s lemma exp_nsmul (x : ℂ) (n : ℕ) : exp (n • x) = exp x ^ n := @MonoidHom.map_pow (Multiplicative ℂ) ℂ _ _ expMonoidHom _ _ theorem exp_nat_mul (x : ℂ) : ∀ n : ℕ, exp (n * x) = exp x ^ n | 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero] | Nat.succ n => by rw [pow_succ, Nat.cast_add_one, add_mul, exp_add, ← exp_nat_mul _ n, one_mul] @[simp] theorem exp_ne_zero : exp x ≠ 0 := fun h => zero_ne_one (α := ℂ) <| by rw [← exp_zero, ← add_neg_cancel x, exp_add, h]; simp theorem exp_neg : exp (-x) = (exp x)⁻¹ := by rw [← mul_right_inj' (exp_ne_zero x), ← exp_add]; simp [mul_inv_cancel₀ (exp_ne_zero x)] theorem exp_sub : exp (x - y) = exp x / exp y := by simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv] theorem exp_int_mul (z : ℂ) (n : ℤ) : Complex.exp (n * z) = Complex.exp z ^ n := by cases n · simp [exp_nat_mul] · simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul] @[simp] theorem exp_conj : exp (conj x) = conj (exp x) := by dsimp [exp] rw [← lim_conj] refine congr_arg CauSeq.lim (CauSeq.ext fun _ => ?_) dsimp [exp', Function.comp_def, cauSeqConj] rw [map_sum (starRingEnd _)] refine sum_congr rfl fun n _ => ?_ rw [map_div₀, map_pow, ← ofReal_natCast, conj_ofReal] @[simp] theorem ofReal_exp_ofReal_re (x : ℝ) : ((exp x).re : ℂ) = exp x := conj_eq_iff_re.1 <| by rw [← exp_conj, conj_ofReal] @[simp, norm_cast] theorem ofReal_exp (x : ℝ) : (Real.exp x : ℂ) = exp x := ofReal_exp_ofReal_re _ @[simp] theorem exp_ofReal_im (x : ℝ) : (exp x).im = 0 := by rw [← ofReal_exp_ofReal_re, ofReal_im] theorem exp_ofReal_re (x : ℝ) : (exp x).re = Real.exp x := rfl end Complex namespace Real open Complex variable (x y : ℝ) @[simp] theorem exp_zero : exp 0 = 1 := by simp [Real.exp] nonrec theorem exp_add : exp (x + y) = exp x * exp y := by simp [exp_add, exp] /-- the exponential function as a monoid hom from `Multiplicative ℝ` to `ℝ` -/ @[simps] noncomputable def expMonoidHom : MonoidHom (Multiplicative ℝ) ℝ := { toFun := fun x => exp x.toAdd, map_one' := by simp, map_mul' := by simp [exp_add] } theorem exp_list_sum (l : List ℝ) : exp l.sum = (l.map exp).prod := map_list_prod (M := Multiplicative ℝ) expMonoidHom l theorem exp_multiset_sum (s : Multiset ℝ) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative ℝ) ℝ _ _ expMonoidHom s theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℝ) : exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (β := Multiplicative ℝ) expMonoidHom f s lemma exp_nsmul (x : ℝ) (n : ℕ) : exp (n • x) = exp x ^ n := @MonoidHom.map_pow (Multiplicative ℝ) ℝ _ _ expMonoidHom _ _ nonrec theorem exp_nat_mul (x : ℝ) (n : ℕ) : exp (n * x) = exp x ^ n := ofReal_injective (by simp [exp_nat_mul]) @[simp] nonrec theorem exp_ne_zero : exp x ≠ 0 := fun h => exp_ne_zero x <| by rw [exp, ← ofReal_inj] at h; simp_all nonrec theorem exp_neg : exp (-x) = (exp x)⁻¹ := ofReal_injective <| by simp [exp_neg] theorem exp_sub : exp (x - y) = exp x / exp y := by simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv] open IsAbsoluteValue Nat theorem sum_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) (n : ℕ) : ∑ i ∈ range n, x ^ i / i ! ≤ exp x := calc ∑ i ∈ range n, x ^ i / i ! ≤ lim (⟨_, isCauSeq_re (exp' x)⟩ : CauSeq ℝ abs) := by refine le_lim (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp only [exp', const_apply, re_sum] norm_cast refine sum_le_sum_of_subset_of_nonneg (range_mono hj) fun _ _ _ ↦ ?_ positivity _ = exp x := by rw [exp, Complex.exp, ← cauSeqRe, lim_re] lemma pow_div_factorial_le_exp (hx : 0 ≤ x) (n : ℕ) : x ^ n / n ! ≤ exp x := calc x ^ n / n ! ≤ ∑ k ∈ range (n + 1), x ^ k / k ! := single_le_sum (f := fun k ↦ x ^ k / k !) (fun k _ ↦ by positivity) (self_mem_range_succ n) _ ≤ exp x := sum_le_exp_of_nonneg hx _ theorem quadratic_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : 1 + x + x ^ 2 / 2 ≤ exp x := calc 1 + x + x ^ 2 / 2 = ∑ i ∈ range 3, x ^ i / i ! := by simp only [sum_range_succ, range_one, sum_singleton, _root_.pow_zero, factorial, cast_one, ne_eq, one_ne_zero, not_false_eq_true, div_self, pow_one, mul_one, div_one, Nat.mul_one, cast_succ, add_right_inj] ring_nf _ ≤ exp x := sum_le_exp_of_nonneg hx 3 private theorem add_one_lt_exp_of_pos {x : ℝ} (hx : 0 < x) : x + 1 < exp x := (by nlinarith : x + 1 < 1 + x + x ^ 2 / 2).trans_le (quadratic_le_exp_of_nonneg hx.le) private theorem add_one_le_exp_of_nonneg {x : ℝ} (hx : 0 ≤ x) : x + 1 ≤ exp x := by rcases eq_or_lt_of_le hx with (rfl | h) · simp exact (add_one_lt_exp_of_pos h).le theorem one_le_exp {x : ℝ} (hx : 0 ≤ x) : 1 ≤ exp x := by linarith [add_one_le_exp_of_nonneg hx] @[bound] theorem exp_pos (x : ℝ) : 0 < exp x := (le_total 0 x).elim (lt_of_lt_of_le zero_lt_one ∘ one_le_exp) fun h => by rw [← neg_neg x, Real.exp_neg] exact inv_pos.2 (lt_of_lt_of_le zero_lt_one (one_le_exp (neg_nonneg.2 h))) @[bound] lemma exp_nonneg (x : ℝ) : 0 ≤ exp x := x.exp_pos.le @[simp] theorem abs_exp (x : ℝ) : |exp x| = exp x := abs_of_pos (exp_pos _) lemma exp_abs_le (x : ℝ) : exp |x| ≤ exp x + exp (-x) := by cases le_total x 0 <;> simp [abs_of_nonpos, abs_of_nonneg, exp_nonneg, *] @[mono] theorem exp_strictMono : StrictMono exp := fun x y h => by rw [← sub_add_cancel y x, Real.exp_add] exact (lt_mul_iff_one_lt_left (exp_pos _)).2 (lt_of_lt_of_le (by linarith) (add_one_le_exp_of_nonneg (by linarith))) @[gcongr] theorem exp_lt_exp_of_lt {x y : ℝ} (h : x < y) : exp x < exp y := exp_strictMono h @[mono] theorem exp_monotone : Monotone exp := exp_strictMono.monotone @[gcongr, bound] theorem exp_le_exp_of_le {x y : ℝ} (h : x ≤ y) : exp x ≤ exp y := exp_monotone h @[simp] theorem exp_lt_exp {x y : ℝ} : exp x < exp y ↔ x < y := exp_strictMono.lt_iff_lt @[simp] theorem exp_le_exp {x y : ℝ} : exp x ≤ exp y ↔ x ≤ y := exp_strictMono.le_iff_le theorem exp_injective : Function.Injective exp := exp_strictMono.injective @[simp] theorem exp_eq_exp {x y : ℝ} : exp x = exp y ↔ x = y := exp_injective.eq_iff @[simp] theorem exp_eq_one_iff : exp x = 1 ↔ x = 0 := exp_injective.eq_iff' exp_zero @[simp] theorem one_lt_exp_iff {x : ℝ} : 1 < exp x ↔ 0 < x := by rw [← exp_zero, exp_lt_exp] @[bound] private alias ⟨_, Bound.one_lt_exp_of_pos⟩ := one_lt_exp_iff @[simp] theorem exp_lt_one_iff {x : ℝ} : exp x < 1 ↔ x < 0 := by rw [← exp_zero, exp_lt_exp] @[simp] theorem exp_le_one_iff {x : ℝ} : exp x ≤ 1 ↔ x ≤ 0 := exp_zero ▸ exp_le_exp @[simp] theorem one_le_exp_iff {x : ℝ} : 1 ≤ exp x ↔ 0 ≤ x := exp_zero ▸ exp_le_exp end Real namespace Complex theorem sum_div_factorial_le {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α] (n j : ℕ) (hn : 0 < n) : (∑ m ∈ range j with n ≤ m, (1 / m.factorial : α)) ≤ n.succ / (n.factorial * n) := calc (∑ m ∈ range j with n ≤ m, (1 / m.factorial : α)) = ∑ m ∈ range (j - n), (1 / ((m + n).factorial : α)) := by refine sum_nbij' (· - n) (· + n) ?_ ?_ ?_ ?_ ?_ <;> simp +contextual [lt_tsub_iff_right, tsub_add_cancel_of_le] _ ≤ ∑ m ∈ range (j - n), ((n.factorial : α) * (n.succ : α) ^ m)⁻¹ := by simp_rw [one_div] gcongr rw [← Nat.cast_pow, ← Nat.cast_mul, Nat.cast_le, add_comm] exact Nat.factorial_mul_pow_le_factorial _ = (n.factorial : α)⁻¹ * ∑ m ∈ range (j - n), (n.succ : α)⁻¹ ^ m := by simp [mul_inv, ← mul_sum, ← sum_mul, mul_comm, inv_pow] _ = ((n.succ : α) - n.succ * (n.succ : α)⁻¹ ^ (j - n)) / (n.factorial * n) := by have h₁ : (n.succ : α) ≠ 1 := @Nat.cast_one α _ ▸ mt Nat.cast_inj.1 (mt Nat.succ.inj (pos_iff_ne_zero.1 hn)) have h₂ : (n.succ : α) ≠ 0 := by positivity have h₃ : (n.factorial * n : α) ≠ 0 := by positivity have h₄ : (n.succ - 1 : α) = n := by simp rw [geom_sum_inv h₁ h₂, eq_div_iff_mul_eq h₃, mul_comm _ (n.factorial * n : α), ← mul_assoc (n.factorial⁻¹ : α), ← mul_inv_rev, h₄, ← mul_assoc (n.factorial * n : α), mul_comm (n : α) n.factorial, mul_inv_cancel₀ h₃, one_mul, mul_comm] _ ≤ n.succ / (n.factorial * n : α) := by gcongr; apply sub_le_self; positivity theorem exp_bound {x : ℂ} (hx : ‖x‖ ≤ 1) {n : ℕ} (hn : 0 < n) : ‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹) := by rw [← lim_const (abv := norm) (∑ m ∈ range n, _), exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_norm] refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹) rw [sum_range_sub_sum_range hj] calc ‖∑ m ∈ range j with n ≤ m, (x ^ m / m.factorial : ℂ)‖ = ‖∑ m ∈ range j with n ≤ m, (x ^ n * (x ^ (m - n) / m.factorial) : ℂ)‖ := by refine congr_arg norm (sum_congr rfl fun m hm => ?_) rw [mem_filter, mem_range] at hm rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2] _ ≤ ∑ m ∈ range j with n ≤ m, ‖x ^ n * (x ^ (m - n) / m.factorial)‖ := IsAbsoluteValue.abv_sum norm .. _ ≤ ∑ m ∈ range j with n ≤ m, ‖x‖ ^ n * (1 / m.factorial) := by simp_rw [Complex.norm_mul, Complex.norm_pow, Complex.norm_div, norm_natCast] gcongr rw [Complex.norm_pow] exact pow_le_one₀ (norm_nonneg _) hx _ = ‖x‖ ^ n * ∑ m ∈ range j with n ≤ m, (1 / m.factorial : ℝ) := by simp [abs_mul, abv_pow abs, abs_div, ← mul_sum] _ ≤ ‖x‖ ^ n * (n.succ * (n.factorial * n : ℝ)⁻¹) := by gcongr exact sum_div_factorial_le _ _ hn theorem exp_bound' {x : ℂ} {n : ℕ} (hx : ‖x‖ / n.succ ≤ 1 / 2) : ‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n / n.factorial * 2 := by rw [← lim_const (abv := norm) (∑ m ∈ range n, _), exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_norm] refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n / n.factorial * 2 let k := j - n have hj : j = n + k := (add_tsub_cancel_of_le hj).symm rw [hj, sum_range_add_sub_sum_range] calc ‖∑ i ∈ range k, x ^ (n + i) / ((n + i).factorial : ℂ)‖ ≤ ∑ i ∈ range k, ‖x ^ (n + i) / ((n + i).factorial : ℂ)‖ := IsAbsoluteValue.abv_sum _ _ _ _ ≤ ∑ i ∈ range k, ‖x‖ ^ (n + i) / (n + i).factorial := by simp [norm_natCast, Complex.norm_pow] _ ≤ ∑ i ∈ range k, ‖x‖ ^ (n + i) / ((n.factorial : ℝ) * (n.succ : ℝ) ^ i) := ?_ _ = ∑ i ∈ range k, ‖x‖ ^ n / n.factorial * (‖x‖ ^ i / (n.succ : ℝ) ^ i) := ?_ _ ≤ ‖x‖ ^ n / ↑n.factorial * 2 := ?_ · gcongr exact mod_cast Nat.factorial_mul_pow_le_factorial · refine Finset.sum_congr rfl fun _ _ => ?_ simp only [pow_add, div_eq_inv_mul, mul_inv, mul_left_comm, mul_assoc] · rw [← mul_sum] gcongr simp_rw [← div_pow] rw [geom_sum_eq, div_le_iff_of_neg] · trans (-1 : ℝ) · linarith · simp only [neg_le_sub_iff_le_add, div_pow, Nat.cast_succ, le_add_iff_nonneg_left] positivity · linarith · linarith theorem norm_exp_sub_one_le {x : ℂ} (hx : ‖x‖ ≤ 1) : ‖exp x - 1‖ ≤ 2 * ‖x‖ := calc ‖exp x - 1‖ = ‖exp x - ∑ m ∈ range 1, x ^ m / m.factorial‖ := by simp [sum_range_succ] _ ≤ ‖x‖ ^ 1 * ((Nat.succ 1 : ℝ) * ((Nat.factorial 1) * (1 : ℕ) : ℝ)⁻¹) := (exp_bound hx (by decide)) _ = 2 * ‖x‖ := by simp [two_mul, mul_two, mul_add, mul_comm, add_mul, Nat.factorial] theorem norm_exp_sub_one_sub_id_le {x : ℂ} (hx : ‖x‖ ≤ 1) : ‖exp x - 1 - x‖ ≤ ‖x‖ ^ 2 := calc ‖exp x - 1 - x‖ = ‖exp x - ∑ m ∈ range 2, x ^ m / m.factorial‖ := by simp [sub_eq_add_neg, sum_range_succ_comm, add_assoc, Nat.factorial] _ ≤ ‖x‖ ^ 2 * ((Nat.succ 2 : ℝ) * (Nat.factorial 2 * (2 : ℕ) : ℝ)⁻¹) := (exp_bound hx (by decide)) _ ≤ ‖x‖ ^ 2 * 1 := by gcongr; norm_num [Nat.factorial] _ = ‖x‖ ^ 2 := by rw [mul_one] lemma norm_exp_sub_sum_le_exp_norm_sub_sum (x : ℂ) (n : ℕ) : ‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ Real.exp ‖x‖ - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by rw [← CauSeq.lim_const (abv := norm) (∑ m ∈ range n, _), Complex.exp, sub_eq_add_neg, ← CauSeq.lim_neg, CauSeq.lim_add, ← lim_norm] refine CauSeq.lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] calc ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ _ ≤ (∑ m ∈ range j, ‖x‖ ^ m / m.factorial) - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by rw [sum_range_sub_sum_range hj, sum_range_sub_sum_range hj] refine (IsAbsoluteValue.abv_sum norm ..).trans_eq ?_ congr with i simp [Complex.norm_pow] _ ≤ Real.exp ‖x‖ - ∑ m ∈ range n, ‖x‖ ^ m / m.factorial := by gcongr exact Real.sum_le_exp_of_nonneg (norm_nonneg _) _ lemma norm_exp_le_exp_norm (x : ℂ) : ‖exp x‖ ≤ Real.exp ‖x‖ := by convert norm_exp_sub_sum_le_exp_norm_sub_sum x 0 using 1 <;> simp lemma norm_exp_sub_sum_le_norm_mul_exp (x : ℂ) (n : ℕ) : ‖exp x - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ ‖x‖ ^ n * Real.exp ‖x‖ := by rw [← CauSeq.lim_const (abv := norm) (∑ m ∈ range n, _), Complex.exp, sub_eq_add_neg, ← CauSeq.lim_neg, CauSeq.lim_add, ← lim_norm] refine CauSeq.lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] show ‖(∑ m ∈ range j, x ^ m / m.factorial) - ∑ m ∈ range n, x ^ m / m.factorial‖ ≤ _ rw [sum_range_sub_sum_range hj] calc ‖∑ m ∈ range j with n ≤ m, (x ^ m / m.factorial : ℂ)‖ = ‖∑ m ∈ range j with n ≤ m, (x ^ n * (x ^ (m - n) / m.factorial) : ℂ)‖ := by refine congr_arg norm (sum_congr rfl fun m hm => ?_) rw [mem_filter, mem_range] at hm rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2] _ ≤ ∑ m ∈ range j with n ≤ m, ‖x ^ n * (x ^ (m - n) / m.factorial)‖ := IsAbsoluteValue.abv_sum norm .. _ ≤ ∑ m ∈ range j with n ≤ m, ‖x‖ ^ n * (‖x‖ ^ (m - n) / (m - n).factorial) := by simp_rw [Complex.norm_mul, Complex.norm_pow, Complex.norm_div, norm_natCast] gcongr with i hi · rw [Complex.norm_pow] · simp _ = ‖x‖ ^ n * ∑ m ∈ range j with n ≤ m, (‖x‖ ^ (m - n) / (m - n).factorial) := by rw [← mul_sum] _ = ‖x‖ ^ n * ∑ m ∈ range (j - n), (‖x‖ ^ m / m.factorial) := by congr 1 refine (sum_bij (fun m hm ↦ m + n) ?_ ?_ ?_ ?_).symm · intro a ha simp only [mem_filter, mem_range, le_add_iff_nonneg_left, zero_le, and_true] simp only [mem_range] at ha rwa [← lt_tsub_iff_right] · intro a ha b hb hab simpa using hab · intro b hb simp only [mem_range, exists_prop] simp only [mem_filter, mem_range] at hb refine ⟨b - n, ?_, ?_⟩ · rw [tsub_lt_tsub_iff_right hb.2] exact hb.1 · rw [tsub_add_cancel_of_le hb.2] · simp _ ≤ ‖x‖ ^ n * Real.exp ‖x‖ := by gcongr refine Real.sum_le_exp_of_nonneg ?_ _ exact norm_nonneg _ @[deprecated (since := "2025-02-16")] alias abs_exp_sub_one_le := norm_exp_sub_one_le @[deprecated (since := "2025-02-16")] alias abs_exp_sub_one_sub_id_le := norm_exp_sub_one_sub_id_le @[deprecated (since := "2025-02-16")] alias abs_exp_sub_sum_le_exp_abs_sub_sum := norm_exp_sub_sum_le_exp_norm_sub_sum @[deprecated (since := "2025-02-16")] alias abs_exp_le_exp_abs := norm_exp_le_exp_norm @[deprecated (since := "2025-02-16")] alias abs_exp_sub_sum_le_abs_mul_exp := norm_exp_sub_sum_le_norm_mul_exp end Complex namespace Real open Complex Finset nonrec theorem exp_bound {x : ℝ} (hx : |x| ≤ 1) {n : ℕ} (hn : 0 < n) : |exp x - ∑ m ∈ range n, x ^ m / m.factorial| ≤ |x| ^ n * (n.succ / (n.factorial * n)) := by have hxc : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx convert exp_bound hxc hn using 2 <;> norm_cast theorem exp_bound' {x : ℝ} (h1 : 0 ≤ x) (h2 : x ≤ 1) {n : ℕ} (hn : 0 < n) : Real.exp x ≤ (∑ m ∈ Finset.range n, x ^ m / m.factorial) + x ^ n * (n + 1) / (n.factorial * n) := by have h3 : |x| = x := by simpa have h4 : |x| ≤ 1 := by rwa [h3] have h' := Real.exp_bound h4 hn rw [h3] at h' have h'' := (abs_sub_le_iff.1 h').1 have t := sub_le_iff_le_add'.1 h'' simpa [mul_div_assoc] using t theorem abs_exp_sub_one_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1| ≤ 2 * |x| := by have : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx exact_mod_cast Complex.norm_exp_sub_one_le (x := x) this theorem abs_exp_sub_one_sub_id_le {x : ℝ} (hx : |x| ≤ 1) : |exp x - 1 - x| ≤ x ^ 2 := by rw [← sq_abs] have : ‖(x : ℂ)‖ ≤ 1 := mod_cast hx exact_mod_cast Complex.norm_exp_sub_one_sub_id_le this /-- A finite initial segment of the exponential series, followed by an arbitrary tail. For fixed `n` this is just a linear map wrt `r`, and each map is a simple linear function of the previous (see `expNear_succ`), with `expNear n x r ⟶ exp x` as `n ⟶ ∞`, for any `r`. -/ noncomputable def expNear (n : ℕ) (x r : ℝ) : ℝ := (∑ m ∈ range n, x ^ m / m.factorial) + x ^ n / n.factorial * r @[simp] theorem expNear_zero (x r) : expNear 0 x r = r := by simp [expNear] @[simp] theorem expNear_succ (n x r) : expNear (n + 1) x r = expNear n x (1 + x / (n + 1) * r) := by simp [expNear, range_succ, mul_add, add_left_comm, add_assoc, pow_succ, div_eq_mul_inv, mul_inv, Nat.factorial] ac_rfl theorem expNear_sub (n x r₁ r₂) : expNear n x r₁ - expNear n x r₂ = x ^ n / n.factorial * (r₁ - r₂) := by simp [expNear, mul_sub] theorem exp_approx_end (n m : ℕ) (x : ℝ) (e₁ : n + 1 = m) (h : |x| ≤ 1) : |exp x - expNear m x 0| ≤ |x| ^ m / m.factorial * ((m + 1) / m) := by simp only [expNear, mul_zero, add_zero] convert exp_bound (n := m) h ?_ using 1 · field_simp [mul_comm] · omega theorem exp_approx_succ {n} {x a₁ b₁ : ℝ} (m : ℕ) (e₁ : n + 1 = m) (a₂ b₂ : ℝ) (e : |1 + x / m * a₂ - a₁| ≤ b₁ - |x| / m * b₂) (h : |exp x - expNear m x a₂| ≤ |x| ^ m / m.factorial * b₂) : |exp x - expNear n x a₁| ≤ |x| ^ n / n.factorial * b₁ := by refine (abs_sub_le _ _ _).trans ((add_le_add_right h _).trans ?_) subst e₁; rw [expNear_succ, expNear_sub, abs_mul] convert mul_le_mul_of_nonneg_left (a := |x| ^ n / ↑(Nat.factorial n)) (le_sub_iff_add_le'.1 e) ?_ using 1 · simp [mul_add, pow_succ', div_eq_mul_inv, abs_mul, abs_inv, ← pow_abs, mul_inv, Nat.factorial] ac_rfl · simp [div_nonneg, abs_nonneg] theorem exp_approx_end' {n} {x a b : ℝ} (m : ℕ) (e₁ : n + 1 = m) (rm : ℝ) (er : ↑m = rm) (h : |x| ≤ 1) (e : |1 - a| ≤ b - |x| / rm * ((rm + 1) / rm)) : |exp x - expNear n x a| ≤ |x| ^ n / n.factorial * b := by subst er exact exp_approx_succ _ e₁ _ _ (by simpa using e) (exp_approx_end _ _ _ e₁ h) theorem exp_1_approx_succ_eq {n} {a₁ b₁ : ℝ} {m : ℕ} (en : n + 1 = m) {rm : ℝ} (er : ↑m = rm) (h : |exp 1 - expNear m 1 ((a₁ - 1) * rm)| ≤ |1| ^ m / m.factorial * (b₁ * rm)) : |exp 1 - expNear n 1 a₁| ≤ |1| ^ n / n.factorial * b₁ := by subst er refine exp_approx_succ _ en _ _ ?_ h field_simp [show (m : ℝ) ≠ 0 by norm_cast; omega] theorem exp_approx_start (x a b : ℝ) (h : |exp x - expNear 0 x a| ≤ |x| ^ 0 / Nat.factorial 0 * b) : |exp x - a| ≤ b := by simpa using h theorem exp_bound_div_one_sub_of_interval' {x : ℝ} (h1 : 0 < x) (h2 : x < 1) : Real.exp x < 1 / (1 - x) := by have H : 0 < 1 - (1 + x + x ^ 2) * (1 - x) := calc 0 < x ^ 3 := by positivity _ = 1 - (1 + x + x ^ 2) * (1 - x) := by ring calc exp x ≤ _ := exp_bound' h1.le h2.le zero_lt_three _ ≤ 1 + x + x ^ 2 := by -- Porting note: was `norm_num [Finset.sum] <;> nlinarith` -- This proof should be restored after the norm_num plugin for big operators is ported. -- (It may also need the positivity extensions in https://github.com/leanprover-community/mathlib4/pull/3907.) rw [show 3 = 1 + 1 + 1 from rfl] repeat rw [Finset.sum_range_succ] norm_num [Nat.factorial] nlinarith _ < 1 / (1 - x) := by rw [lt_div_iff₀] <;> nlinarith theorem exp_bound_div_one_sub_of_interval {x : ℝ} (h1 : 0 ≤ x) (h2 : x < 1) : Real.exp x ≤ 1 / (1 - x) := by rcases eq_or_lt_of_le h1 with (rfl | h1) · simp · exact (exp_bound_div_one_sub_of_interval' h1 h2).le theorem add_one_lt_exp {x : ℝ} (hx : x ≠ 0) : x + 1 < Real.exp x := by obtain hx | hx := hx.symm.lt_or_lt · exact add_one_lt_exp_of_pos hx obtain h' | h' := le_or_lt 1 (-x) · linarith [x.exp_pos] have hx' : 0 < x + 1 := by linarith simpa [add_comm, exp_neg, inv_lt_inv₀ (exp_pos _) hx'] using exp_bound_div_one_sub_of_interval' (neg_pos.2 hx) h' theorem add_one_le_exp (x : ℝ) : x + 1 ≤ Real.exp x := by obtain rfl | hx := eq_or_ne x 0 · simp · exact (add_one_lt_exp hx).le lemma one_sub_lt_exp_neg {x : ℝ} (hx : x ≠ 0) : 1 - x < exp (-x) := (sub_eq_neg_add _ _).trans_lt <| add_one_lt_exp <| neg_ne_zero.2 hx lemma one_sub_le_exp_neg (x : ℝ) : 1 - x ≤ exp (-x) := (sub_eq_neg_add _ _).trans_le <| add_one_le_exp _ theorem one_sub_div_pow_le_exp_neg {n : ℕ} {t : ℝ} (ht' : t ≤ n) : (1 - t / n) ^ n ≤ exp (-t) := by rcases eq_or_ne n 0 with (rfl | hn) · simp rwa [Nat.cast_zero] at ht' calc (1 - t / n) ^ n ≤ rexp (-(t / n)) ^ n := by gcongr · exact sub_nonneg.2 <| div_le_one_of_le₀ ht' n.cast_nonneg · exact one_sub_le_exp_neg _ _ = rexp (-t) := by rw [← Real.exp_nat_mul, mul_neg, mul_comm, div_mul_cancel₀]; positivity lemma le_inv_mul_exp (x : ℝ) {c : ℝ} (hc : 0 < c) : x ≤ c⁻¹ * exp (c * x) := by rw [le_inv_mul_iff₀ hc] calc c * x _ ≤ c * x + 1 := le_add_of_nonneg_right zero_le_one _ ≤ _ := Real.add_one_le_exp (c * x) end Real namespace Mathlib.Meta.Positivity open Lean.Meta Qq /-- Extension for the `positivity` tactic: `Real.exp` is always positive. -/ @[positivity Real.exp _] def evalExp : PositivityExt where eval {u α} _ _ e := do match u, α, e with | 0, ~q(ℝ), ~q(Real.exp $a) => assertInstancesCommute pure (.positive q(Real.exp_pos $a)) | _, _, _ => throwError "not Real.exp" end Mathlib.Meta.Positivity namespace Complex @[simp] theorem norm_exp_ofReal (x : ℝ) : ‖exp x‖ = Real.exp x := by rw [← ofReal_exp] exact Complex.norm_of_nonneg (le_of_lt (Real.exp_pos _)) @[deprecated (since := "2025-02-16")] alias abs_exp_ofReal := norm_exp_ofReal end Complex
Mathlib/Data/Complex/Exponential.lean
1,750
1,751
/- Copyright (c) 2018 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis -/ import Mathlib.Algebra.Polynomial.Identities import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.NumberTheory.Padics.PadicIntegers import Mathlib.Topology.Algebra.Polynomial import Mathlib.Topology.MetricSpace.CauSeqFilter /-! # Hensel's lemma on ℤ_p This file proves Hensel's lemma on ℤ_p, roughly following Keith Conrad's writeup: <http://www.math.uconn.edu/~kconrad/blurbs/gradnumthy/hensel.pdf> Hensel's lemma gives a simple condition for the existence of a root of a polynomial. The proof and motivation are described in the paper [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019]. ## References * <http://www.math.uconn.edu/~kconrad/blurbs/gradnumthy/hensel.pdf> * [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019] * <https://en.wikipedia.org/wiki/Hensel%27s_lemma> ## Tags p-adic, p adic, padic, p-adic integer -/ noncomputable section open Topology -- We begin with some general lemmas that are used below in the computation. theorem padic_polynomial_dist {p : ℕ} [Fact p.Prime] (F : Polynomial ℤ_[p]) (x y : ℤ_[p]) : ‖F.eval x - F.eval y‖ ≤ ‖x - y‖ := let ⟨z, hz⟩ := F.evalSubFactor x y calc ‖F.eval x - F.eval y‖ = ‖z‖ * ‖x - y‖ := by simp [hz] _ ≤ 1 * ‖x - y‖ := by gcongr; apply PadicInt.norm_le_one _ = ‖x - y‖ := by simp open Filter Metric private theorem comp_tendsto_lim {p : ℕ} [Fact p.Prime] {F : Polynomial ℤ_[p]} (ncs : CauSeq ℤ_[p] norm) : Tendsto (fun i => F.eval (ncs i)) atTop (𝓝 (F.eval ncs.lim)) := Filter.Tendsto.comp (@Polynomial.continuousAt _ _ _ _ F _) ncs.tendsto_limit section variable {p : ℕ} [Fact p.Prime] {ncs : CauSeq ℤ_[p] norm} {F : Polynomial ℤ_[p]} {a : ℤ_[p]} (ncs_der_val : ∀ n, ‖F.derivative.eval (ncs n)‖ = ‖F.derivative.eval a‖) private theorem ncs_tendsto_lim : Tendsto (fun i => ‖F.derivative.eval (ncs i)‖) atTop (𝓝 ‖F.derivative.eval ncs.lim‖) := Tendsto.comp (continuous_iff_continuousAt.1 continuous_norm _) (comp_tendsto_lim _) include ncs_der_val
private theorem ncs_tendsto_const : Tendsto (fun i => ‖F.derivative.eval (ncs i)‖) atTop (𝓝 ‖F.derivative.eval a‖) := by convert @tendsto_const_nhds ℝ _ ℕ _ _; rw [ncs_der_val]
Mathlib/NumberTheory/Padics/Hensel.lean
65
67
/- Copyright (c) 2024 Josha Dekker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Josha Dekker -/ import Mathlib.Order.Filter.Tendsto import Mathlib.Order.Filter.Finite import Mathlib.Order.Filter.CountableInter import Mathlib.SetTheory.Cardinal.Regular import Mathlib.Tactic.Linarith /-! # Filters with a cardinal intersection property In this file we define `CardinalInterFilter l c` to be the class of filters with the following property: for any collection of sets `s ∈ l` with cardinality strictly less than `c`, their intersection belongs to `l` as well. # Main results * `Filter.cardinalInterFilter_aleph0` establishes that every filter `l` is a `CardinalInterFilter l ℵ₀` * `CardinalInterFilter.toCountableInterFilter` establishes that every `CardinalInterFilter l c` with `c > ℵ₀` is a `CountableInterFilter`. * `CountableInterFilter.toCardinalInterFilter` establishes that every `CountableInterFilter l` is a `CardinalInterFilter l ℵ₁`. * `CardinalInterFilter.of_CardinalInterFilter_of_lt` establishes that we have `CardinalInterFilter l c` → `CardinalInterFilter l a` for all `a < c`. ## Tags filter, cardinal -/ open Set Filter Cardinal universe u variable {ι : Type u} {α β : Type u} {c : Cardinal.{u}} /-- A filter `l` has the cardinal `c` intersection property if for any collection of less than `c` sets `s ∈ l`, their intersection belongs to `l` as well. -/ class CardinalInterFilter (l : Filter α) (c : Cardinal.{u}) : Prop where /-- For a collection of sets `s ∈ l` with cardinality below c, their intersection belongs to `l` as well. -/ cardinal_sInter_mem : ∀ S : Set (Set α), (#S < c) → (∀ s ∈ S, s ∈ l) → ⋂₀ S ∈ l variable {l : Filter α} theorem cardinal_sInter_mem {S : Set (Set α)} [CardinalInterFilter l c] (hSc : #S < c) : ⋂₀ S ∈ l ↔ ∀ s ∈ S, s ∈ l := ⟨fun hS _s hs => mem_of_superset hS (sInter_subset_of_mem hs), CardinalInterFilter.cardinal_sInter_mem _ hSc⟩ /-- Every filter is a CardinalInterFilter with c = ℵ₀ -/ theorem _root_.Filter.cardinalInterFilter_aleph0 (l : Filter α) : CardinalInterFilter l ℵ₀ where cardinal_sInter_mem := by simp_all only [aleph_zero, lt_aleph0_iff_subtype_finite, setOf_mem_eq, sInter_mem, implies_true, forall_const] /-- Every CardinalInterFilter with c > ℵ₀ is a CountableInterFilter -/ theorem CardinalInterFilter.toCountableInterFilter (l : Filter α) [CardinalInterFilter l c] (hc : ℵ₀ < c) : CountableInterFilter l where countable_sInter_mem S hS a := CardinalInterFilter.cardinal_sInter_mem S (lt_of_le_of_lt (Set.Countable.le_aleph0 hS) hc) a /-- Every CountableInterFilter is a CardinalInterFilter with c = ℵ₁ -/ instance CountableInterFilter.toCardinalInterFilter (l : Filter α) [CountableInterFilter l] : CardinalInterFilter l ℵ₁ where cardinal_sInter_mem S hS a := CountableInterFilter.countable_sInter_mem S ((countable_iff_lt_aleph_one S).mpr hS) a theorem cardinalInterFilter_aleph_one_iff : CardinalInterFilter l ℵ₁ ↔ CountableInterFilter l := ⟨fun _ ↦ ⟨fun S h a ↦ CardinalInterFilter.cardinal_sInter_mem S ((countable_iff_lt_aleph_one S).1 h) a⟩, fun _ ↦ CountableInterFilter.toCardinalInterFilter l⟩ /-- Every CardinalInterFilter for some c also is a CardinalInterFilter for some a ≤ c -/ theorem CardinalInterFilter.of_cardinalInterFilter_of_le (l : Filter α) [CardinalInterFilter l c] {a : Cardinal.{u}} (hac : a ≤ c) : CardinalInterFilter l a where cardinal_sInter_mem S hS a := CardinalInterFilter.cardinal_sInter_mem S (lt_of_lt_of_le hS hac) a theorem CardinalInterFilter.of_cardinalInterFilter_of_lt (l : Filter α) [CardinalInterFilter l c] {a : Cardinal.{u}} (hac : a < c) : CardinalInterFilter l a := CardinalInterFilter.of_cardinalInterFilter_of_le l (hac.le) namespace Filter variable [CardinalInterFilter l c] theorem cardinal_iInter_mem {s : ι → Set α} (hic : #ι < c) : (⋂ i, s i) ∈ l ↔ ∀ i, s i ∈ l := by rw [← sInter_range _] apply (cardinal_sInter_mem (lt_of_le_of_lt Cardinal.mk_range_le hic)).trans exact forall_mem_range theorem cardinal_bInter_mem {S : Set ι} (hS : #S < c) {s : ∀ i ∈ S, Set α} : (⋂ i, ⋂ hi : i ∈ S, s i ‹_›) ∈ l ↔ ∀ i, ∀ hi : i ∈ S, s i ‹_› ∈ l := by rw [biInter_eq_iInter] exact (cardinal_iInter_mem hS).trans Subtype.forall theorem eventually_cardinal_forall {p : α → ι → Prop} (hic : #ι < c) : (∀ᶠ x in l, ∀ i, p x i) ↔ ∀ i, ∀ᶠ x in l, p x i := by simp only [Filter.Eventually, setOf_forall] exact cardinal_iInter_mem hic theorem eventually_cardinal_ball {S : Set ι} (hS : #S < c) {p : α → ∀ i ∈ S, Prop} : (∀ᶠ x in l, ∀ i hi, p x i hi) ↔ ∀ i hi, ∀ᶠ x in l, p x i hi := by simp only [Filter.Eventually, setOf_forall] exact cardinal_bInter_mem hS theorem EventuallyLE.cardinal_iUnion {s t : ι → Set α} (hic : #ι < c) (h : ∀ i, s i ≤ᶠ[l] t i) : ⋃ i, s i ≤ᶠ[l] ⋃ i, t i := ((eventually_cardinal_forall hic).2 h).mono fun _ hst hs => mem_iUnion.2 <| (mem_iUnion.1 hs).imp hst theorem EventuallyEq.cardinal_iUnion {s t : ι → Set α} (hic : #ι < c) (h : ∀ i, s i =ᶠ[l] t i) : ⋃ i, s i =ᶠ[l] ⋃ i, t i := (EventuallyLE.cardinal_iUnion hic fun i => (h i).le).antisymm (EventuallyLE.cardinal_iUnion hic fun i => (h i).symm.le) theorem EventuallyLE.cardinal_bUnion {S : Set ι} (hS : #S < c) {s t : ∀ i ∈ S, Set α} (h : ∀ i hi, s i hi ≤ᶠ[l] t i hi) : ⋃ i ∈ S, s i ‹_› ≤ᶠ[l] ⋃ i ∈ S, t i ‹_› := by simp only [biUnion_eq_iUnion] exact EventuallyLE.cardinal_iUnion hS fun i => h i i.2 theorem EventuallyEq.cardinal_bUnion {S : Set ι} (hS : #S < c) {s t : ∀ i ∈ S, Set α} (h : ∀ i hi, s i hi =ᶠ[l] t i hi) : ⋃ i ∈ S, s i ‹_› =ᶠ[l] ⋃ i ∈ S, t i ‹_› := (EventuallyLE.cardinal_bUnion hS fun i hi => (h i hi).le).antisymm (EventuallyLE.cardinal_bUnion hS fun i hi => (h i hi).symm.le) theorem EventuallyLE.cardinal_iInter {s t : ι → Set α} (hic : #ι < c) (h : ∀ i, s i ≤ᶠ[l] t i) : ⋂ i, s i ≤ᶠ[l] ⋂ i, t i := ((eventually_cardinal_forall hic).2 h).mono fun _ hst hs => mem_iInter.2 fun i => hst _ (mem_iInter.1 hs i) theorem EventuallyEq.cardinal_iInter {s t : ι → Set α} (hic : #ι < c) (h : ∀ i, s i =ᶠ[l] t i) : ⋂ i, s i =ᶠ[l] ⋂ i, t i := (EventuallyLE.cardinal_iInter hic fun i => (h i).le).antisymm (EventuallyLE.cardinal_iInter hic fun i => (h i).symm.le) theorem EventuallyLE.cardinal_bInter {S : Set ι} (hS : #S < c) {s t : ∀ i ∈ S, Set α} (h : ∀ i hi, s i hi ≤ᶠ[l] t i hi) : ⋂ i ∈ S, s i ‹_› ≤ᶠ[l] ⋂ i ∈ S, t i ‹_› := by simp only [biInter_eq_iInter] exact EventuallyLE.cardinal_iInter hS fun i => h i i.2 theorem EventuallyEq.cardinal_bInter {S : Set ι} (hS : #S < c) {s t : ∀ i ∈ S, Set α} (h : ∀ i hi, s i hi =ᶠ[l] t i hi) : ⋂ i ∈ S, s i ‹_› =ᶠ[l] ⋂ i ∈ S, t i ‹_› := (EventuallyLE.cardinal_bInter hS fun i hi => (h i hi).le).antisymm (EventuallyLE.cardinal_bInter hS fun i hi => (h i hi).symm.le) /-- Construct a filter with cardinal `c` intersection property. This constructor deduces `Filter.univ_sets` and `Filter.inter_sets` from the cardinal `c` intersection property. -/ def ofCardinalInter (l : Set (Set α)) (hc : 2 < c) (hl : ∀ S : Set (Set α), (#S < c) → S ⊆ l → ⋂₀ S ∈ l) (h_mono : ∀ s t, s ∈ l → s ⊆ t → t ∈ l) : Filter α where sets := l univ_sets := sInter_empty ▸ hl ∅ (mk_eq_zero (∅ : Set (Set α)) ▸ lt_trans zero_lt_two hc) (empty_subset _) sets_of_superset := h_mono _ _ inter_sets {s t} hs ht := sInter_pair s t ▸ by apply hl _ (?_) (insert_subset_iff.2 ⟨hs, singleton_subset_iff.2 ht⟩) have : #({s, t} : Set (Set α)) ≤ 2 := by calc _ ≤ #({t} : Set (Set α)) + 1 := Cardinal.mk_insert_le _ = 2 := by norm_num exact lt_of_le_of_lt this hc instance cardinalInter_ofCardinalInter (l : Set (Set α)) (hc : 2 < c) (hl : ∀ S : Set (Set α), (#S < c) → S ⊆ l → ⋂₀ S ∈ l) (h_mono : ∀ s t, s ∈ l → s ⊆ t → t ∈ l) : CardinalInterFilter (Filter.ofCardinalInter l hc hl h_mono) c := ⟨hl⟩ @[simp] theorem mem_ofCardinalInter {l : Set (Set α)} (hc : 2 < c) (hl : ∀ S : Set (Set α), (#S < c) → S ⊆ l → ⋂₀ S ∈ l) (h_mono : ∀ s t, s ∈ l → s ⊆ t → t ∈ l) {s : Set α} : s ∈ Filter.ofCardinalInter l hc hl h_mono ↔ s ∈ l := Iff.rfl /-- Construct a filter with cardinal `c` intersection property. Similarly to `Filter.comk`, a set belongs to this filter if its complement satisfies the property. Similarly to `Filter.ofCardinalInter`, this constructor deduces some properties from the cardinal `c` intersection property which becomes the cardinal `c` union property because we take complements of all sets. -/ def ofCardinalUnion (l : Set (Set α)) (hc : 2 < c) (hUnion : ∀ S : Set (Set α), (#S < c) → (∀ s ∈ S, s ∈ l) → ⋃₀ S ∈ l) (hmono : ∀ t ∈ l, ∀ s ⊆ t, s ∈ l) : Filter α := by refine .ofCardinalInter {s | sᶜ ∈ l} hc (fun S hSc hSp ↦ ?_) fun s t ht hsub ↦ ?_ · rw [mem_setOf_eq, compl_sInter] apply hUnion (compl '' S) (lt_of_le_of_lt mk_image_le hSc) intro s hs rw [mem_image] at hs rcases hs with ⟨t, ht, rfl⟩ apply hSp ht · rw [mem_setOf_eq] rw [← compl_subset_compl] at hsub exact hmono sᶜ ht tᶜ hsub instance cardinalInter_ofCardinalUnion (l : Set (Set α)) (hc : 2 < c) (h₁ h₂) : CardinalInterFilter (Filter.ofCardinalUnion l hc h₁ h₂) c := cardinalInter_ofCardinalInter .. @[simp] theorem mem_ofCardinalUnion {l : Set (Set α)} (hc : 2 < c) {hunion hmono s} : s ∈ ofCardinalUnion l hc hunion hmono ↔ l sᶜ := Iff.rfl instance cardinalInterFilter_principal (s : Set α) : CardinalInterFilter (𝓟 s) c := ⟨fun _ _ hS => subset_sInter hS⟩ instance cardinalInterFilter_bot : CardinalInterFilter (⊥ : Filter α) c := by rw [← principal_empty] apply cardinalInterFilter_principal instance cardinalInterFilter_top : CardinalInterFilter (⊤ : Filter α) c := by rw [← principal_univ] apply cardinalInterFilter_principal instance (l : Filter β) [CardinalInterFilter l c] (f : α → β) : CardinalInterFilter (comap f l) c := by refine ⟨fun S hSc hS => ?_⟩ choose! t htl ht using hS refine ⟨_, (cardinal_bInter_mem hSc).2 htl, ?_⟩ simpa [preimage_iInter] using iInter₂_mono ht instance (l : Filter α) [CardinalInterFilter l c] (f : α → β) : CardinalInterFilter (map f l) c := by refine ⟨fun S hSc hS => ?_⟩ simp only [mem_map, sInter_eq_biInter, preimage_iInter₂] at hS ⊢ exact (cardinal_bInter_mem hSc).2 hS /-- Infimum of two `CardinalInterFilter`s is a `CardinalInterFilter`. This is useful, e.g., to automatically get an instance for `residual α ⊓ 𝓟 s`. -/ instance cardinalInterFilter_inf_eq (l₁ l₂ : Filter α) [CardinalInterFilter l₁ c] [CardinalInterFilter l₂ c] : CardinalInterFilter (l₁ ⊓ l₂) c := by refine ⟨fun S hSc hS => ?_⟩ choose s hs t ht hst using hS replace hs : (⋂ i ∈ S, s i ‹_›) ∈ l₁ := (cardinal_bInter_mem hSc).2 hs replace ht : (⋂ i ∈ S, t i ‹_›) ∈ l₂ := (cardinal_bInter_mem hSc).2 ht refine mem_of_superset (inter_mem_inf hs ht) (subset_sInter fun i hi => ?_) rw [hst i hi] apply inter_subset_inter <;> exact iInter_subset_of_subset i (iInter_subset _ _) instance cardinalInterFilter_inf (l₁ l₂ : Filter α) {c₁ c₂ : Cardinal.{u}} [CardinalInterFilter l₁ c₁] [CardinalInterFilter l₂ c₂] : CardinalInterFilter (l₁ ⊓ l₂) (c₁ ⊓ c₂) := by have : CardinalInterFilter l₁ (c₁ ⊓ c₂) := CardinalInterFilter.of_cardinalInterFilter_of_le l₁ inf_le_left have : CardinalInterFilter l₂ (c₁ ⊓ c₂) := CardinalInterFilter.of_cardinalInterFilter_of_le l₂ inf_le_right exact cardinalInterFilter_inf_eq _ _ /-- Supremum of two `CardinalInterFilter`s is a `CardinalInterFilter`. -/ instance cardinalInterFilter_sup_eq (l₁ l₂ : Filter α) [CardinalInterFilter l₁ c] [CardinalInterFilter l₂ c] : CardinalInterFilter (l₁ ⊔ l₂) c := by refine ⟨fun S hSc hS => ⟨?_, ?_⟩⟩ <;> refine (cardinal_sInter_mem hSc).2 fun s hs => ?_ exacts [(hS s hs).1, (hS s hs).2] instance cardinalInterFilter_sup (l₁ l₂ : Filter α) {c₁ c₂ : Cardinal.{u}} [CardinalInterFilter l₁ c₁] [CardinalInterFilter l₂ c₂] : CardinalInterFilter (l₁ ⊔ l₂) (c₁ ⊓ c₂) := by have : CardinalInterFilter l₁ (c₁ ⊓ c₂) := CardinalInterFilter.of_cardinalInterFilter_of_le l₁ inf_le_left have : CardinalInterFilter l₂ (c₁ ⊓ c₂) := CardinalInterFilter.of_cardinalInterFilter_of_le l₂ inf_le_right exact cardinalInterFilter_sup_eq _ _ variable (g : Set (Set α)) /-- `Filter.CardinalGenerateSets c g` is the (sets of the) greatest `cardinalInterFilter c` containing `g`. -/ inductive CardinalGenerateSets : Set α → Prop | basic {s : Set α} : s ∈ g → CardinalGenerateSets s | univ : CardinalGenerateSets univ | superset {s t : Set α} : CardinalGenerateSets s → s ⊆ t → CardinalGenerateSets t | sInter {S : Set (Set α)} : (#S < c) → (∀ s ∈ S, CardinalGenerateSets s) → CardinalGenerateSets (⋂₀ S) /-- `Filter.cardinalGenerate c g` is the greatest `cardinalInterFilter c` containing `g`. -/ def cardinalGenerate (hc : 2 < c) : Filter α := ofCardinalInter (CardinalGenerateSets g) hc (fun _ => CardinalGenerateSets.sInter) fun _ _ => CardinalGenerateSets.superset lemma cardinalInter_ofCardinalGenerate (hc : 2 < c) : CardinalInterFilter (cardinalGenerate g hc) c := by delta cardinalGenerate apply cardinalInter_ofCardinalInter _ _ _ variable {g} /-- A set is in the `cardinalInterFilter` generated by `g` if and only if
it contains an intersection of `c` elements of `g`. -/ theorem mem_cardinaleGenerate_iff {s : Set α} {hreg : c.IsRegular} : s ∈ cardinalGenerate g (IsRegular.nat_lt hreg 2) ↔ ∃ S : Set (Set α), S ⊆ g ∧ (#S < c) ∧ ⋂₀ S ⊆ s := by constructor <;> intro h · induction h with | @basic s hs => refine ⟨{s}, singleton_subset_iff.mpr hs, ?_⟩ simpa [subset_refl] using IsRegular.nat_lt hreg 1 | univ => exact ⟨∅, ⟨empty_subset g, mk_eq_zero (∅ : Set <| Set α) ▸ IsRegular.nat_lt hreg 0, by simp⟩⟩ | superset _ _ ih => exact Exists.imp (by tauto) ih | @sInter S Sct _ ih => choose T Tg Tct hT using ih refine ⟨⋃ (s) (H : s ∈ S), T s H, by simpa, (Cardinal.card_biUnion_lt_iff_forall_of_isRegular hreg Sct).2 Tct, ?_⟩ apply subset_sInter apply fun s H => subset_trans (sInter_subset_sInter (subset_iUnion₂ s H)) (hT s H) rcases h with ⟨S, Sg, Sct, hS⟩
Mathlib/Order/Filter/CardinalInter.lean
299
317
/- 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.SetTheory.Cardinal.Cofinality import Mathlib.LinearAlgebra.FreeModule.Finite.Basic import Mathlib.LinearAlgebra.Dimension.StrongRankCondition import Mathlib.LinearAlgebra.Dimension.Constructions /-! # Conditions for rank to be finite Also contains characterization for when rank equals zero or rank equals one. -/ noncomputable section universe u v v' w variable {R : Type u} {M M₁ : Type v} {M' : Type v'} {ι : Type w} variable [Ring R] [AddCommGroup M] [AddCommGroup M'] [AddCommGroup M₁] variable [Module R M] [Module R M'] [Module R M₁] attribute [local instance] nontrivial_of_invariantBasisNumber open Basis Cardinal Function Module Set Submodule /-- If every finite set of linearly independent vectors has cardinality at most `n`, then the same is true for arbitrary sets of linearly independent vectors. -/ theorem linearIndependent_bounded_of_finset_linearIndependent_bounded {n : ℕ} (H : ∀ s : Finset M, (LinearIndependent R fun i : s => (i : M)) → s.card ≤ n) : ∀ s : Set M, LinearIndependent R ((↑) : s → M) → #s ≤ n := by intro s li apply Cardinal.card_le_of intro t rw [← Finset.card_map (Embedding.subtype s)] apply H apply linearIndependent_finset_map_embedding_subtype _ li theorem rank_le {n : ℕ} (H : ∀ s : Finset M, (LinearIndependent R fun i : s => (i : M)) → s.card ≤ n) : Module.rank R M ≤ n := by rw [Module.rank_def] apply ciSup_le' rintro ⟨s, li⟩ exact linearIndependent_bounded_of_finset_linearIndependent_bounded H _ li section RankZero /-- See `rank_zero_iff` for a stronger version with `NoZeroSMulDivisor R M`. -/ lemma rank_eq_zero_iff : Module.rank R M = 0 ↔ ∀ x : M, ∃ a : R, a ≠ 0 ∧ a • x = 0 := by nontriviality R constructor · contrapose! rintro ⟨x, hx⟩ rw [← Cardinal.one_le_iff_ne_zero] have : LinearIndependent R (fun _ : Unit ↦ x) := linearIndependent_iff.mpr (fun l hl ↦ Finsupp.unique_ext <| not_not.mp fun H ↦ hx _ H ((Finsupp.linearCombination_unique _ _ _).symm.trans hl)) simpa using this.cardinal_lift_le_rank · intro h rw [← le_zero_iff, Module.rank_def] apply ciSup_le' intro ⟨s, hs⟩ rw [nonpos_iff_eq_zero, Cardinal.mk_eq_zero_iff, ← not_nonempty_iff] rintro ⟨i : s⟩ obtain ⟨a, ha, ha'⟩ := h i apply ha simpa using DFunLike.congr_fun (linearIndependent_iff.mp hs (Finsupp.single i a) (by simpa)) i theorem rank_pos_of_free [Module.Free R M] [Nontrivial M] : 0 < Module.rank R M := have := Module.nontrivial R M (pos_of_ne_zero <| Cardinal.mk_ne_zero _).trans_le (Free.chooseBasis R M).linearIndependent.cardinal_le_rank variable [Nontrivial R] section variable [NoZeroSMulDivisors R M] theorem rank_zero_iff_forall_zero : Module.rank R M = 0 ↔ ∀ x : M, x = 0 := by simp_rw [rank_eq_zero_iff, smul_eq_zero, and_or_left, not_and_self_iff, false_or, exists_and_right, and_iff_right (exists_ne (0 : R))] /-- See `rank_subsingleton` for the reason that `Nontrivial R` is needed. Also see `rank_eq_zero_iff` for the version without `NoZeroSMulDivisor R M`. -/ theorem rank_zero_iff : Module.rank R M = 0 ↔ Subsingleton M := rank_zero_iff_forall_zero.trans (subsingleton_iff_forall_eq 0).symm theorem rank_pos_iff_exists_ne_zero : 0 < Module.rank R M ↔ ∃ x : M, x ≠ 0 := by rw [← not_iff_not] simpa using rank_zero_iff_forall_zero theorem rank_pos_iff_nontrivial : 0 < Module.rank R M ↔ Nontrivial M := rank_pos_iff_exists_ne_zero.trans (nontrivial_iff_exists_ne 0).symm theorem rank_pos [Nontrivial M] : 0 < Module.rank R M := rank_pos_iff_nontrivial.mpr ‹_› end variable (R M) /-- See `rank_subsingleton` that assumes `Subsingleton R` instead. -/ @[nontriviality] theorem rank_subsingleton' [Subsingleton M] : Module.rank R M = 0 := rank_eq_zero_iff.mpr fun _ ↦ ⟨1, one_ne_zero, Subsingleton.elim _ _⟩ @[simp] theorem rank_punit : Module.rank R PUnit = 0 := rank_subsingleton' _ _ @[simp] theorem rank_bot : Module.rank R (⊥ : Submodule R M) = 0 := rank_subsingleton' _ _ variable {R M} theorem exists_mem_ne_zero_of_rank_pos {s : Submodule R M} (h : 0 < Module.rank R s) : ∃ b : M, b ∈ s ∧ b ≠ 0 := exists_mem_ne_zero_of_ne_bot fun eq => by rw [eq, rank_bot] at h; exact lt_irrefl _ h end RankZero section Finite theorem Module.finite_of_rank_eq_nat [Module.Free R M] {n : ℕ} (h : Module.rank R M = n) : Module.Finite R M := by nontriviality R obtain ⟨⟨ι, b⟩⟩ := Module.Free.exists_basis (R := R) (M := M) have := mk_lt_aleph0_iff.mp <| b.linearIndependent.cardinal_le_rank |>.trans_eq h |>.trans_lt <| nat_lt_aleph0 n exact Module.Finite.of_basis b theorem Module.finite_of_rank_eq_zero [NoZeroSMulDivisors R M] (h : Module.rank R M = 0) : Module.Finite R M := by nontriviality R rw [rank_zero_iff] at h infer_instance theorem Module.finite_of_rank_eq_one [Module.Free R M] (h : Module.rank R M = 1) : Module.Finite R M := Module.finite_of_rank_eq_nat <| h.trans Nat.cast_one.symm section variable [StrongRankCondition R] /-- If a module has a finite dimension, all bases are indexed by a finite type. -/ theorem Basis.nonempty_fintype_index_of_rank_lt_aleph0 {ι : Type*} (b : Basis ι R M) (h : Module.rank R M < ℵ₀) : Nonempty (Fintype ι) := by rwa [← Cardinal.lift_lt, ← b.mk_eq_rank, Cardinal.lift_aleph0, Cardinal.lift_lt_aleph0, Cardinal.lt_aleph0_iff_fintype] at h /-- If a module has a finite dimension, all bases are indexed by a finite type. -/ noncomputable def Basis.fintypeIndexOfRankLtAleph0 {ι : Type*} (b : Basis ι R M) (h : Module.rank R M < ℵ₀) : Fintype ι := Classical.choice (b.nonempty_fintype_index_of_rank_lt_aleph0 h) /-- If a module has a finite dimension, all bases are indexed by a finite set. -/ theorem Basis.finite_index_of_rank_lt_aleph0 {ι : Type*} {s : Set ι} (b : Basis s R M) (h : Module.rank R M < ℵ₀) : s.Finite := finite_def.2 (b.nonempty_fintype_index_of_rank_lt_aleph0 h) end namespace LinearIndependent variable [StrongRankCondition R] theorem cardinalMk_le_finrank [Module.Finite R M] {ι : Type w} {b : ι → M} (h : LinearIndependent R b) : #ι ≤ finrank R M := by rw [← lift_le.{max v w}] simpa only [← finrank_eq_rank, lift_natCast, lift_le_nat_iff] using h.cardinal_lift_le_rank @[deprecated (since := "2024-11-10")] alias cardinal_mk_le_finrank := cardinalMk_le_finrank theorem fintype_card_le_finrank [Module.Finite R M] {ι : Type*} [Fintype ι] {b : ι → M} (h : LinearIndependent R b) : Fintype.card ι ≤ finrank R M := by simpa using h.cardinalMk_le_finrank theorem finset_card_le_finrank [Module.Finite R M] {b : Finset M} (h : LinearIndependent R (fun x => x : b → M)) : b.card ≤ finrank R M := by rw [← Fintype.card_coe] exact h.fintype_card_le_finrank theorem lt_aleph0_of_finite {ι : Type w} [Module.Finite R M] {v : ι → M} (h : LinearIndependent R v) : #ι < ℵ₀ := by apply Cardinal.lift_lt.1 apply lt_of_le_of_lt · apply h.cardinal_lift_le_rank · rw [← finrank_eq_rank, Cardinal.lift_aleph0, Cardinal.lift_natCast] apply Cardinal.nat_lt_aleph0 theorem finite [Module.Finite R M] {ι : Type*} {f : ι → M} (h : LinearIndependent R f) : Finite ι := Cardinal.lt_aleph0_iff_finite.1 <| h.lt_aleph0_of_finite theorem setFinite [Module.Finite R M] {b : Set M} (h : LinearIndependent R fun x : b => (x : M)) : b.Finite := Cardinal.lt_aleph0_iff_set_finite.mp h.lt_aleph0_of_finite end LinearIndependent lemma exists_set_linearIndependent_of_lt_rank {n : Cardinal} (hn : n < Module.rank R M) : ∃ s : Set M, #s = n ∧ LinearIndepOn R id s := by obtain ⟨⟨s, hs⟩, hs'⟩ := exists_lt_of_lt_ciSup' (hn.trans_eq (Module.rank_def R M)) obtain ⟨t, ht, ht'⟩ := le_mk_iff_exists_subset.mp hs'.le exact ⟨t, ht', hs.mono ht⟩ lemma exists_finset_linearIndependent_of_le_rank {n : ℕ} (hn : n ≤ Module.rank R M) : ∃ s : Finset M, s.card = n ∧ LinearIndepOn R id (s : Set M) := by have := nonempty_linearIndependent_set rcases hn.eq_or_lt with h | h · obtain ⟨⟨s, hs⟩, hs'⟩ := Cardinal.exists_eq_natCast_of_iSup_eq _ (Cardinal.bddAbove_range _) _ (h.trans (Module.rank_def R M)).symm have : Finite s := lt_aleph0_iff_finite.mp (hs' ▸ nat_lt_aleph0 n) cases nonempty_fintype s refine ⟨s.toFinset, by simpa using hs', by simpa⟩ · obtain ⟨s, hs, hs'⟩ := exists_set_linearIndependent_of_lt_rank h have : Finite s := lt_aleph0_iff_finite.mp (hs ▸ nat_lt_aleph0 n) cases nonempty_fintype s exact ⟨s.toFinset, by simpa using hs, by simpa⟩ lemma exists_linearIndependent_of_le_rank {n : ℕ} (hn : n ≤ Module.rank R M) : ∃ f : Fin n → M, LinearIndependent R f := have ⟨_, hs, hs'⟩ := exists_finset_linearIndependent_of_le_rank hn ⟨_, (linearIndependent_equiv (Finset.equivFinOfCardEq hs).symm).mpr hs'⟩ lemma natCast_le_rank_iff [Nontrivial R] {n : ℕ} : n ≤ Module.rank R M ↔ ∃ f : Fin n → M, LinearIndependent R f := ⟨exists_linearIndependent_of_le_rank, fun H ↦ by simpa using H.choose_spec.cardinal_lift_le_rank⟩ lemma natCast_le_rank_iff_finset [Nontrivial R] {n : ℕ} : n ≤ Module.rank R M ↔ ∃ s : Finset M, s.card = n ∧ LinearIndependent R ((↑) : s → M) := ⟨exists_finset_linearIndependent_of_le_rank, fun ⟨s, h₁, h₂⟩ ↦ by simpa [h₁] using h₂.cardinal_le_rank⟩ lemma exists_finset_linearIndependent_of_le_finrank {n : ℕ} (hn : n ≤ finrank R M) : ∃ s : Finset M, s.card = n ∧ LinearIndependent R ((↑) : s → M) := by by_cases h : finrank R M = 0 · rw [le_zero_iff.mp (hn.trans_eq h)] exact ⟨∅, rfl, by convert linearIndependent_empty R M using 2 <;> aesop⟩ exact exists_finset_linearIndependent_of_le_rank ((Nat.cast_le.mpr hn).trans_eq (cast_toNat_of_lt_aleph0 (toNat_ne_zero.mp h).2)) lemma exists_linearIndependent_of_le_finrank {n : ℕ} (hn : n ≤ finrank R M) : ∃ f : Fin n → M, LinearIndependent R f := have ⟨_, hs, hs'⟩ := exists_finset_linearIndependent_of_le_finrank hn ⟨_, (linearIndependent_equiv (Finset.equivFinOfCardEq hs).symm).mpr hs'⟩ variable [Module.Finite R M] [StrongRankCondition R] in theorem Module.Finite.not_linearIndependent_of_infinite {ι : Type*} [Infinite ι] (v : ι → M) : ¬LinearIndependent R v := mt LinearIndependent.finite <| @not_finite _ _ section variable [NoZeroSMulDivisors R M] theorem iSupIndep.subtype_ne_bot_le_rank [Nontrivial R] {V : ι → Submodule R M} (hV : iSupIndep V) : Cardinal.lift.{v} #{ i : ι // V i ≠ ⊥ } ≤ Cardinal.lift.{w} (Module.rank R M) := by set I := { i : ι // V i ≠ ⊥ } have hI : ∀ i : I, ∃ v ∈ V i, v ≠ (0 : M) := by intro i rw [← Submodule.ne_bot_iff] exact i.prop choose v hvV hv using hI have : LinearIndependent R v := (hV.comp Subtype.coe_injective).linearIndependent _ hvV hv exact this.cardinal_lift_le_rank @[deprecated (since := "2024-11-24")] alias CompleteLattice.Independent.subtype_ne_bot_le_rank := iSupIndep.subtype_ne_bot_le_rank variable [Module.Finite R M] [StrongRankCondition R] theorem iSupIndep.subtype_ne_bot_le_finrank_aux {p : ι → Submodule R M} (hp : iSupIndep p) : #{ i // p i ≠ ⊥ } ≤ (finrank R M : Cardinal.{w}) := by suffices Cardinal.lift.{v} #{ i // p i ≠ ⊥ } ≤ Cardinal.lift.{v} (finrank R M : Cardinal.{w}) by rwa [Cardinal.lift_le] at this calc Cardinal.lift.{v} #{ i // p i ≠ ⊥ } ≤ Cardinal.lift.{w} (Module.rank R M) := hp.subtype_ne_bot_le_rank _ = Cardinal.lift.{w} (finrank R M : Cardinal.{v}) := by rw [finrank_eq_rank] _ = Cardinal.lift.{v} (finrank R M : Cardinal.{w}) := by simp /-- If `p` is an independent family of submodules of a `R`-finite module `M`, then the number of nontrivial subspaces in the family `p` is finite. -/ noncomputable def iSupIndep.fintypeNeBotOfFiniteDimensional {p : ι → Submodule R M} (hp : iSupIndep p) : Fintype { i : ι // p i ≠ ⊥ } := by suffices #{ i // p i ≠ ⊥ } < (ℵ₀ : Cardinal.{w}) by rw [Cardinal.lt_aleph0_iff_fintype] at this exact this.some refine lt_of_le_of_lt hp.subtype_ne_bot_le_finrank_aux ?_ simp [Cardinal.nat_lt_aleph0] /-- If `p` is an independent family of submodules of a `R`-finite module `M`, then the number of nontrivial subspaces in the family `p` is bounded above by the dimension of `M`. Note that the `Fintype` hypothesis required here can be provided by `iSupIndep.fintypeNeBotOfFiniteDimensional`. -/ theorem iSupIndep.subtype_ne_bot_le_finrank {p : ι → Submodule R M} (hp : iSupIndep p) [Fintype { i // p i ≠ ⊥ }] : Fintype.card { i // p i ≠ ⊥ } ≤ finrank R M := by simpa using hp.subtype_ne_bot_le_finrank_aux end variable [Module.Finite R M] [StrongRankCondition R] section open Finset /-- If a finset has cardinality larger than the rank of a module, then there is a nontrivial linear relation amongst its elements. -/ theorem Module.exists_nontrivial_relation_of_finrank_lt_card {t : Finset M} (h : finrank R M < t.card) : ∃ f : M → R, ∑ e ∈ t, f e • e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by obtain ⟨g, sum, z, nonzero⟩ := Fintype.not_linearIndependent_iff.mp (mt LinearIndependent.finset_card_le_finrank h.not_le) refine ⟨Subtype.val.extend g 0, ?_, z, z.2, by rwa [Subtype.val_injective.extend_apply]⟩ rw [← Finset.sum_finset_coe]; convert sum; apply Subtype.val_injective.extend_apply /-- If a finset has cardinality larger than `finrank + 1`, then there is a nontrivial linear relation amongst its elements, such that the coefficients of the relation sum to zero. -/ theorem Module.exists_nontrivial_relation_sum_zero_of_finrank_succ_lt_card {t : Finset M} (h : finrank R M + 1 < t.card) : ∃ f : M → R, ∑ e ∈ t, f e • e = 0 ∧ ∑ e ∈ t, f e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by -- Pick an element x₀ ∈ t, obtain ⟨x₀, x₀_mem⟩ := card_pos.1 ((Nat.succ_pos _).trans h) -- and apply the previous lemma to the {xᵢ - x₀} let shift : M ↪ M := ⟨(· - x₀), sub_left_injective⟩ classical let t' := (t.erase x₀).map shift have h' : finrank R M < t'.card := by rw [card_map, card_erase_of_mem x₀_mem] exact Nat.lt_pred_iff.mpr h -- to obtain a function `g`. obtain ⟨g, gsum, x₁, x₁_mem, nz⟩ := exists_nontrivial_relation_of_finrank_lt_card h' -- Then obtain `f` by translating back by `x₀`, -- and setting the value of `f` at `x₀` to ensure `∑ e ∈ t, f e = 0`. let f : M → R := fun z ↦ if z = x₀ then -∑ z ∈ t.erase x₀, g (z - x₀) else g (z - x₀) refine ⟨f, ?_, ?_, ?_⟩ -- After this, it's a matter of verifying the properties, -- based on the corresponding properties for `g`. · rw [sum_map, Embedding.coeFn_mk] at gsum simp_rw [f, ← t.sum_erase_add _ x₀_mem, if_pos, neg_smul, sum_smul, ← sub_eq_add_neg, ← sum_sub_distrib, ← gsum, smul_sub] refine sum_congr rfl fun x x_mem ↦ ?_ rw [if_neg (mem_erase.mp x_mem).1] · simp_rw [f, ← t.sum_erase_add _ x₀_mem, if_pos, add_neg_eq_zero] exact sum_congr rfl fun x x_mem ↦ if_neg (mem_erase.mp x_mem).1 · obtain ⟨x₁, x₁_mem', rfl⟩ := Finset.mem_map.mp x₁_mem have := mem_erase.mp x₁_mem' exact ⟨x₁, by simpa only [f, Embedding.coeFn_mk, sub_add_cancel, this.2, true_and, if_neg this.1]⟩ end end Finite section FinrankZero section variable [Nontrivial R] /-- A (finite dimensional) space that is a subsingleton has zero `finrank`. -/ @[nontriviality] theorem Module.finrank_zero_of_subsingleton [Subsingleton M] : finrank R M = 0 := by rw [finrank, rank_subsingleton', map_zero] lemma LinearIndependent.finrank_eq_zero_of_infinite {ι} [Infinite ι] {v : ι → M} (hv : LinearIndependent R v) : finrank R M = 0 := toNat_eq_zero.mpr <| .inr hv.aleph0_le_rank
section variable [NoZeroSMulDivisors R M]
Mathlib/LinearAlgebra/Dimension/Finite.lean
382
384
/- Copyright (c) 2023 Jz Pan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jz Pan -/ import Mathlib.FieldTheory.SplittingField.Construction import Mathlib.FieldTheory.IsAlgClosed.AlgebraicClosure import Mathlib.FieldTheory.Separable import Mathlib.FieldTheory.Normal.Closure import Mathlib.RingTheory.AlgebraicIndependent.Adjoin import Mathlib.RingTheory.AlgebraicIndependent.TranscendenceBasis import Mathlib.RingTheory.Polynomial.SeparableDegree import Mathlib.RingTheory.Polynomial.UniqueFactorization /-! # Separable degree This file contains basics about the separable degree of a field extension. ## Main definitions - `Field.Emb F E`: the type of `F`-algebra homomorphisms from `E` to the algebraic closure of `E` (the algebraic closure of `F` is usually used in the literature, but our definition has the advantage that `Field.Emb F E` lies in the same universe as `E` rather than the maximum over `F` and `E`). Usually denoted by $\operatorname{Emb}_F(E)$ in textbooks. - `Field.finSepDegree F E`: the (finite) separable degree $[E:F]_s$ of an extension `E / F` of fields, defined to be the number of `F`-algebra homomorphisms from `E` to the algebraic closure of `E`, as a natural number. It is zero if `Field.Emb F E` is not finite. Note that if `E / F` is not algebraic, then this definition makes no mathematical sense. **Remark:** the `Cardinal`-valued, potentially infinite separable degree `Field.sepDegree F E` for a general algebraic extension `E / F` is defined to be the degree of `L / F`, where `L` is the separable closure of `F` in `E`, which is not defined in this file yet. Later we will show that (`Field.finSepDegree_eq`), if `Field.Emb F E` is finite, then these two definitions coincide. If `E / F` is algebraic with infinite separable degree, we have `#(Field.Emb F E) = 2 ^ Field.sepDegree F E` instead. (See `Field.Emb.cardinal_eq_two_pow_sepDegree` in another file.) For example, if $F = \mathbb{Q}$ and $E = \mathbb{Q}( \mu_{p^\infty} )$, then $\operatorname{Emb}_F (E)$ is in bijection with $\operatorname{Gal}(E/F)$, which is isomorphic to $\mathbb{Z}_p^\times$, which is uncountable, whereas $ [E:F] $ is countable. - `Polynomial.natSepDegree`: the separable degree of a polynomial is a natural number, defined to be the number of distinct roots of it over its splitting field. ## Main results - `Field.embEquivOfEquiv`, `Field.finSepDegree_eq_of_equiv`: a random bijection between `Field.Emb F E` and `Field.Emb F K` when `E` and `K` are isomorphic as `F`-algebras. In particular, they have the same cardinality (so their `Field.finSepDegree` are equal). - `Field.embEquivOfAdjoinSplits`, `Field.finSepDegree_eq_of_adjoin_splits`: a random bijection between `Field.Emb F E` and `E →ₐ[F] K` if `E = F(S)` such that every element `s` of `S` is integral (= algebraic) over `F` and whose minimal polynomial splits in `K`. In particular, they have the same cardinality. - `Field.embEquivOfIsAlgClosed`, `Field.finSepDegree_eq_of_isAlgClosed`: a random bijection between `Field.Emb F E` and `E →ₐ[F] K` when `E / F` is algebraic and `K / F` is algebraically closed. In particular, they have the same cardinality. - `Field.embProdEmbOfIsAlgebraic`, `Field.finSepDegree_mul_finSepDegree_of_isAlgebraic`: if `K / E / F` is a field extension tower, such that `K / E` is algebraic, then there is a non-canonical bijection `Field.Emb F E × Field.Emb E K ≃ Field.Emb F K`. In particular, the separable degrees satisfy the tower law: $[E:F]_s [K:E]_s = [K:F]_s$ (see also `Module.finrank_mul_finrank`). - `Field.infinite_emb_of_transcendental`: `Field.Emb` is infinite for transcendental extensions. - `Polynomial.natSepDegree_le_natDegree`: the separable degree of a polynomial is smaller than its degree. - `Polynomial.natSepDegree_eq_natDegree_iff`: the separable degree of a non-zero polynomial is equal to its degree if and only if it is separable. - `Polynomial.natSepDegree_eq_of_splits`: if a polynomial splits over `E`, then its separable degree is equal to the number of distinct roots of it over `E`. - `Polynomial.natSepDegree_eq_of_isAlgClosed`: the separable degree of a polynomial is equal to the number of distinct roots of it over any algebraically closed field. - `Polynomial.natSepDegree_expand`: if a field `F` is of exponential characteristic `q`, then `Polynomial.expand F (q ^ n) f` and `f` have the same separable degree. - `Polynomial.HasSeparableContraction.natSepDegree_eq`: if a polynomial has separable contraction, then its separable degree is equal to its separable contraction degree. - `Irreducible.natSepDegree_dvd_natDegree`: the separable degree of an irreducible polynomial divides its degree. - `IntermediateField.finSepDegree_adjoin_simple_eq_natSepDegree`: the separable degree of `F⟮α⟯ / F` is equal to the separable degree of the minimal polynomial of `α` over `F`. - `IntermediateField.finSepDegree_adjoin_simple_eq_finrank_iff`: if `α` is algebraic over `F`, then the separable degree of `F⟮α⟯ / F` is equal to the degree of `F⟮α⟯ / F` if and only if `α` is a separable element. - `Field.finSepDegree_dvd_finrank`: the separable degree of any field extension `E / F` divides the degree of `E / F`. - `Field.finSepDegree_le_finrank`: the separable degree of a finite extension `E / F` is smaller than the degree of `E / F`. - `Field.finSepDegree_eq_finrank_iff`: if `E / F` is a finite extension, then its separable degree is equal to its degree if and only if it is a separable extension. - `IntermediateField.isSeparable_adjoin_simple_iff_isSeparable`: `F⟮x⟯ / F` is a separable extension if and only if `x` is a separable element. - `Algebra.IsSeparable.trans`: if `E / F` and `K / E` are both separable, then `K / F` is also separable. ## Tags separable degree, degree, polynomial -/ open Module Polynomial IntermediateField Field noncomputable section universe u v w variable (F : Type u) (E : Type v) [Field F] [Field E] [Algebra F E] variable (K : Type w) [Field K] [Algebra F K] namespace Field /-- `Field.Emb F E` is the type of `F`-algebra homomorphisms from `E` to the algebraic closure of `E`. -/ abbrev Emb := E →ₐ[F] AlgebraicClosure E /-- If `E / F` is an algebraic extension, then the (finite) separable degree of `E / F` is the number of `F`-algebra homomorphisms from `E` to the algebraic closure of `E`, as a natural number. It is defined to be zero if there are infinitely many of them. Note that if `E / F` is not algebraic, then this definition makes no mathematical sense. -/ def finSepDegree : ℕ := Nat.card (Emb F E) instance instInhabitedEmb : Inhabited (Emb F E) := ⟨IsScalarTower.toAlgHom F E _⟩ instance instNeZeroFinSepDegree [FiniteDimensional F E] : NeZero (finSepDegree F E) := ⟨Nat.card_ne_zero.2 ⟨inferInstance, Fintype.finite <| minpoly.AlgHom.fintype _ _ _⟩⟩ /-- A random bijection between `Field.Emb F E` and `Field.Emb F K` when `E` and `K` are isomorphic as `F`-algebras. -/ def embEquivOfEquiv (i : E ≃ₐ[F] K) : Emb F E ≃ Emb F K := AlgEquiv.arrowCongr i <| AlgEquiv.symm <| by let _ : Algebra E K := i.toAlgHom.toRingHom.toAlgebra have : Algebra.IsAlgebraic E K := by constructor intro x have h := isAlgebraic_algebraMap (R := E) (A := K) (i.symm.toAlgHom x) rw [show ∀ y : E, (algebraMap E K) y = i.toAlgHom y from fun y ↦ rfl] at h simpa only [AlgEquiv.toAlgHom_eq_coe, AlgHom.coe_coe, AlgEquiv.apply_symm_apply] using h apply AlgEquiv.restrictScalars (R := F) (S := E) exact IsAlgClosure.equivOfAlgebraic E K (AlgebraicClosure K) (AlgebraicClosure E) /-- If `E` and `K` are isomorphic as `F`-algebras, then they have the same `Field.finSepDegree` over `F`. -/ theorem finSepDegree_eq_of_equiv (i : E ≃ₐ[F] K) : finSepDegree F E = finSepDegree F K := Nat.card_congr (embEquivOfEquiv F E K i) @[simp] theorem finSepDegree_self : finSepDegree F F = 1 := by have : Cardinal.mk (Emb F F) = 1 := le_antisymm (Cardinal.le_one_iff_subsingleton.2 AlgHom.subsingleton) (Cardinal.one_le_iff_ne_zero.2 <| Cardinal.mk_ne_zero _) rw [finSepDegree, Nat.card, this, Cardinal.one_toNat] end Field namespace IntermediateField @[simp] theorem finSepDegree_bot : finSepDegree F (⊥ : IntermediateField F E) = 1 := by rw [finSepDegree_eq_of_equiv _ _ _ (botEquiv F E), finSepDegree_self] section Tower variable {F} variable [Algebra E K] [IsScalarTower F E K] @[simp] theorem finSepDegree_bot' : finSepDegree F (⊥ : IntermediateField E K) = finSepDegree F E := finSepDegree_eq_of_equiv _ _ _ ((botEquiv E K).restrictScalars F) @[simp] theorem finSepDegree_top : finSepDegree F (⊤ : IntermediateField E K) = finSepDegree F K := finSepDegree_eq_of_equiv _ _ _ ((topEquiv (F := E) (E := K)).restrictScalars F) end Tower end IntermediateField namespace Field /-- A random bijection between `Field.Emb F E` and `E →ₐ[F] K` if `E = F(S)` such that every element `s` of `S` is integral (= algebraic) over `F` and whose minimal polynomial splits in `K`. Combined with `Field.instInhabitedEmb`, it can be viewed as a stronger version of `IntermediateField.nonempty_algHom_of_adjoin_splits`. -/ def embEquivOfAdjoinSplits {S : Set E} (hS : adjoin F S = ⊤) (hK : ∀ s ∈ S, IsIntegral F s ∧ Splits (algebraMap F K) (minpoly F s)) : Emb F E ≃ (E →ₐ[F] K) := have : Algebra.IsAlgebraic F (⊤ : IntermediateField F E) := (hS ▸ isAlgebraic_adjoin (S := S) fun x hx ↦ (hK x hx).1) have halg := (topEquiv (F := F) (E := E)).isAlgebraic Classical.choice <| Function.Embedding.antisymm (halg.algHomEmbeddingOfSplits (fun _ ↦ splits_of_mem_adjoin F E (S := S) hK (hS ▸ mem_top)) _) (halg.algHomEmbeddingOfSplits (fun _ ↦ IsAlgClosed.splits_codomain _) _) /-- The `Field.finSepDegree F E` is equal to the cardinality of `E →ₐ[F] K` if `E = F(S)` such that every element `s` of `S` is integral (= algebraic) over `F` and whose minimal polynomial splits in `K`. -/ theorem finSepDegree_eq_of_adjoin_splits {S : Set E} (hS : adjoin F S = ⊤) (hK : ∀ s ∈ S, IsIntegral F s ∧ Splits (algebraMap F K) (minpoly F s)) : finSepDegree F E = Nat.card (E →ₐ[F] K) := Nat.card_congr (embEquivOfAdjoinSplits F E K hS hK) /-- A random bijection between `Field.Emb F E` and `E →ₐ[F] K` when `E / F` is algebraic and `K / F` is algebraically closed. -/ def embEquivOfIsAlgClosed [Algebra.IsAlgebraic F E] [IsAlgClosed K] : Emb F E ≃ (E →ₐ[F] K) := embEquivOfAdjoinSplits F E K (adjoin_univ F E) fun s _ ↦ ⟨Algebra.IsIntegral.isIntegral s, IsAlgClosed.splits_codomain _⟩ /-- The `Field.finSepDegree F E` is equal to the cardinality of `E →ₐ[F] K` as a natural number, when `E / F` is algebraic and `K / F` is algebraically closed. -/ @[stacks 09HJ "We use `finSepDegree` to state a more general result."] theorem finSepDegree_eq_of_isAlgClosed [Algebra.IsAlgebraic F E] [IsAlgClosed K] : finSepDegree F E = Nat.card (E →ₐ[F] K) := Nat.card_congr (embEquivOfIsAlgClosed F E K) /-- If `K / E / F` is a field extension tower, such that `K / E` is algebraic, then there is a non-canonical bijection `Field.Emb F E × Field.Emb E K ≃ Field.Emb F K`. A corollary of `algHomEquivSigma`. -/ def embProdEmbOfIsAlgebraic [Algebra E K] [IsScalarTower F E K] [Algebra.IsAlgebraic E K] : Emb F E × Emb E K ≃ Emb F K := let e : ∀ f : E →ₐ[F] AlgebraicClosure K, @AlgHom E K _ _ _ _ _ f.toRingHom.toAlgebra ≃ Emb E K := fun f ↦ (@embEquivOfIsAlgClosed E K _ _ _ _ _ f.toRingHom.toAlgebra).symm (algHomEquivSigma (A := F) (B := E) (C := K) (D := AlgebraicClosure K) |>.trans (Equiv.sigmaEquivProdOfEquiv e) |>.trans <| Equiv.prodCongrLeft <| fun _ : Emb E K ↦ AlgEquiv.arrowCongr (@AlgEquiv.refl F E _ _ _) <| (IsAlgClosure.equivOfAlgebraic E K (AlgebraicClosure K) (AlgebraicClosure E)).restrictScalars F).symm /-- If the field extension `E / F` is transcendental, then `Field.Emb F E` is infinite. -/ instance infinite_emb_of_transcendental [H : Algebra.Transcendental F E] : Infinite (Emb F E) := by obtain ⟨ι, x, hx⟩ := exists_isTranscendenceBasis' F E have := hx.isAlgebraic_field rw [← (embProdEmbOfIsAlgebraic F (adjoin F (Set.range x)) E).infinite_iff] refine @Prod.infinite_of_left _ _ ?_ _ rw [← (embEquivOfEquiv _ _ _ hx.1.aevalEquivField).infinite_iff] obtain ⟨i⟩ := hx.nonempty_iff_transcendental.2 H let K := FractionRing (MvPolynomial ι F) let i1 := IsScalarTower.toAlgHom F (MvPolynomial ι F) (AlgebraicClosure K) have hi1 : Function.Injective i1 := by rw [IsScalarTower.coe_toAlgHom', IsScalarTower.algebraMap_eq _ K] exact (algebraMap K (AlgebraicClosure K)).injective.comp (IsFractionRing.injective _ _) let f (n : ℕ) : Emb F K := IsFractionRing.liftAlgHom (g := i1.comp <| MvPolynomial.aeval fun i : ι ↦ MvPolynomial.X i ^ (n + 1)) <| hi1.comp <| by simpa [algebraicIndependent_iff_injective_aeval] using MvPolynomial.algebraicIndependent_polynomial_aeval_X _ fun i : ι ↦ (Polynomial.transcendental_X F).pow n.succ_pos refine Infinite.of_injective f fun m n h ↦ ?_ replace h : (MvPolynomial.X i) ^ (m + 1) = (MvPolynomial.X i) ^ (n + 1) := hi1 <| by simpa [f, -map_pow] using congr($h (algebraMap _ K (MvPolynomial.X (R := F) i))) simpa using congr(MvPolynomial.totalDegree $h) /-- If the field extension `E / F` is transcendental, then `Field.finSepDegree F E = 0`, which actually means that `Field.Emb F E` is infinite (see `Field.infinite_emb_of_transcendental`). -/ theorem finSepDegree_eq_zero_of_transcendental [Algebra.Transcendental F E] : finSepDegree F E = 0 := Nat.card_eq_zero_of_infinite /-- If `K / E / F` is a field extension tower, such that `K / E` is algebraic, then their separable degrees satisfy the tower law $[E:F]_s [K:E]_s = [K:F]_s$. See also `Module.finrank_mul_finrank`. -/ @[stacks 09HK "Part 1, `finSepDegree` variant"] theorem finSepDegree_mul_finSepDegree_of_isAlgebraic [Algebra E K] [IsScalarTower F E K] [Algebra.IsAlgebraic E K] : finSepDegree F E * finSepDegree E K = finSepDegree F K := by simpa only [Nat.card_prod] using Nat.card_congr (embProdEmbOfIsAlgebraic F E K) end Field namespace Polynomial variable {F E} variable (f : F[X]) open Classical in /-- The separable degree `Polynomial.natSepDegree` of a polynomial is a natural number, defined to be the number of distinct roots of it over its splitting field. This is similar to `Polynomial.natDegree` but not to `Polynomial.degree`, namely, the separable degree of `0` is `0`, not negative infinity. -/ def natSepDegree : ℕ := (f.aroots f.SplittingField).toFinset.card /-- The separable degree of a polynomial is smaller than its degree. -/ theorem natSepDegree_le_natDegree : f.natSepDegree ≤ f.natDegree := by have := f.map (algebraMap F f.SplittingField) |>.card_roots' rw [← aroots_def, natDegree_map] at this classical exact (f.aroots f.SplittingField).toFinset_card_le.trans this @[simp] theorem natSepDegree_X_sub_C (x : F) : (X - C x).natSepDegree = 1 := by simp only [natSepDegree, aroots_X_sub_C, Multiset.toFinset_singleton, Finset.card_singleton] @[simp] theorem natSepDegree_X : (X : F[X]).natSepDegree = 1 := by simp only [natSepDegree, aroots_X, Multiset.toFinset_singleton, Finset.card_singleton] /-- A constant polynomial has zero separable degree. -/ theorem natSepDegree_eq_zero (h : f.natDegree = 0) : f.natSepDegree = 0 := by linarith only [natSepDegree_le_natDegree f, h] @[simp] theorem natSepDegree_C (x : F) : (C x).natSepDegree = 0 := natSepDegree_eq_zero _ (natDegree_C _) @[simp] theorem natSepDegree_zero : (0 : F[X]).natSepDegree = 0 := by rw [← C_0, natSepDegree_C] @[simp] theorem natSepDegree_one : (1 : F[X]).natSepDegree = 0 := by rw [← C_1, natSepDegree_C] /-- A non-constant polynomial has non-zero separable degree. -/ theorem natSepDegree_ne_zero (h : f.natDegree ≠ 0) : f.natSepDegree ≠ 0 := by rw [natSepDegree, ne_eq, Finset.card_eq_zero, ← ne_eq, ← Finset.nonempty_iff_ne_empty] use rootOfSplits _ (SplittingField.splits f) (ne_of_apply_ne _ h) classical rw [Multiset.mem_toFinset, mem_aroots] exact ⟨ne_of_apply_ne _ h, map_rootOfSplits _ (SplittingField.splits f) (ne_of_apply_ne _ h)⟩ /-- A polynomial has zero separable degree if and only if it is constant. -/ theorem natSepDegree_eq_zero_iff : f.natSepDegree = 0 ↔ f.natDegree = 0 := ⟨(natSepDegree_ne_zero f).mtr, natSepDegree_eq_zero f⟩ /-- A polynomial has non-zero separable degree if and only if it is non-constant. -/ theorem natSepDegree_ne_zero_iff : f.natSepDegree ≠ 0 ↔ f.natDegree ≠ 0 := Iff.not <| natSepDegree_eq_zero_iff f /-- The separable degree of a non-zero polynomial is equal to its degree if and only if it is separable. -/ theorem natSepDegree_eq_natDegree_iff (hf : f ≠ 0) : f.natSepDegree = f.natDegree ↔ f.Separable := by classical simp_rw [← card_rootSet_eq_natDegree_iff_of_splits hf (SplittingField.splits f), rootSet_def, Finset.coe_sort_coe, Fintype.card_coe] rfl /-- If a polynomial is separable, then its separable degree is equal to its degree. -/ theorem natSepDegree_eq_natDegree_of_separable (h : f.Separable) : f.natSepDegree = f.natDegree := (natSepDegree_eq_natDegree_iff f h.ne_zero).2 h variable {f} in /-- Same as `Polynomial.natSepDegree_eq_natDegree_of_separable`, but enables the use of dot notation. -/ theorem Separable.natSepDegree_eq_natDegree (h : f.Separable) : f.natSepDegree = f.natDegree := natSepDegree_eq_natDegree_of_separable f h /-- If a polynomial splits over `E`, then its separable degree is equal to the number of distinct roots of it over `E`. -/ theorem natSepDegree_eq_of_splits [DecidableEq E] (h : f.Splits (algebraMap F E)) : f.natSepDegree = (f.aroots E).toFinset.card := by classical rw [aroots, ← (SplittingField.lift f h).comp_algebraMap, ← map_map, roots_map _ ((splits_id_iff_splits _).mpr <| SplittingField.splits f), Multiset.toFinset_map, Finset.card_image_of_injective _ (RingHom.injective _), natSepDegree] variable (E) in /-- The separable degree of a polynomial is equal to the number of distinct roots of it over any algebraically closed field. -/ theorem natSepDegree_eq_of_isAlgClosed [DecidableEq E] [IsAlgClosed E] : f.natSepDegree = (f.aroots E).toFinset.card :=
natSepDegree_eq_of_splits f (IsAlgClosed.splits_codomain f) theorem natSepDegree_map (f : E[X]) (i : E →+* K) : (f.map i).natSepDegree = f.natSepDegree := by
Mathlib/FieldTheory/SeparableDegree.lean
378
380
/- 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]
Mathlib/Analysis/NormedSpace/OperatorNorm/Basic.lean
164
168
/- Copyright (c) 2019 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston, Bryan Gin-ge Chen -/ import Mathlib.Logic.Relation import Mathlib.Order.CompleteLattice.Basic import Mathlib.Order.GaloisConnection.Defs /-! # Equivalence relations This file defines the complete lattice of equivalence relations on a type, results about the inductively defined equivalence closure of a binary relation, and the analogues of some isomorphism theorems for quotients of arbitrary types. ## Implementation notes The complete lattice instance for equivalence relations could have been defined by lifting the Galois insertion of equivalence relations on α into binary relations on α, and then using `CompleteLattice.copy` to define a complete lattice instance with more appropriate definitional equalities (a similar example is `Filter.CompleteLattice` in `Mathlib/Order/Filter/Basic.lean`). This does not save space, however, and is less clear. Partitions are not defined as a separate structure here; users are encouraged to reason about them using the existing `Setoid` and its infrastructure. ## Tags setoid, equivalence, iseqv, relation, equivalence relation -/ attribute [refl, simp] Setoid.refl attribute [symm] Setoid.symm attribute [trans] Setoid.trans variable {α : Type*} {β : Type*} namespace Setoid attribute [ext] ext /-- Two equivalence relations are equal iff their underlying binary operations are equal. -/ theorem eq_iff_rel_eq {r₁ r₂ : Setoid α} : r₁ = r₂ ↔ ⇑r₁ = ⇑r₂ := ⟨fun h => h ▸ rfl, fun h => Setoid.ext fun _ _ => h ▸ Iff.rfl⟩ /-- Defining `≤` for equivalence relations. -/ instance : LE (Setoid α) := ⟨fun r s => ∀ ⦃x y⦄, r x y → s x y⟩ theorem le_def {r s : Setoid α} : r ≤ s ↔ ∀ {x y}, r x y → s x y := Iff.rfl @[refl] theorem refl' (r : Setoid α) (x) : r x x := r.iseqv.refl x @[symm] theorem symm' (r : Setoid α) : ∀ {x y}, r x y → r y x := r.iseqv.symm @[trans] theorem trans' (r : Setoid α) : ∀ {x y z}, r x y → r y z → r x z := r.iseqv.trans theorem comm' (s : Setoid α) {x y} : s x y ↔ s y x := ⟨s.symm', s.symm'⟩ open scoped Function -- required for scoped `on` notation /-- The kernel of a function is an equivalence relation. -/ def ker (f : α → β) : Setoid α := ⟨(· = ·) on f, eq_equivalence.comap f⟩ /-- The kernel of the quotient map induced by an equivalence relation r equals r. -/ @[simp] theorem ker_mk_eq (r : Setoid α) : ker (@Quotient.mk'' _ r) = r := ext fun _ _ => Quotient.eq theorem ker_apply_mk_out {f : α → β} (a : α) : f (⟦a⟧ : Quotient (Setoid.ker f)).out = f a := @Quotient.mk_out _ (Setoid.ker f) a theorem ker_def {f : α → β} {x y : α} : ker f x y ↔ f x = f y := Iff.rfl /-- Given types `α`, `β`, the product of two equivalence relations `r` on `α` and `s` on `β`: `(x₁, x₂), (y₁, y₂) ∈ α × β` are related by `r.prod s` iff `x₁` is related to `y₁` by `r` and `x₂` is related to `y₂` by `s`. -/ protected def prod (r : Setoid α) (s : Setoid β) : Setoid (α × β) where r x y := r x.1 y.1 ∧ s x.2 y.2 iseqv := ⟨fun x => ⟨r.refl' x.1, s.refl' x.2⟩, fun h => ⟨r.symm' h.1, s.symm' h.2⟩, fun h₁ h₂ => ⟨r.trans' h₁.1 h₂.1, s.trans' h₁.2 h₂.2⟩⟩ lemma prod_apply {r : Setoid α} {s : Setoid β} {x₁ x₂ : α} {y₁ y₂ : β} : @Setoid.r _ (r.prod s) (x₁, y₁) (x₂, y₂) ↔ (@Setoid.r _ r x₁ x₂ ∧ @Setoid.r _ s y₁ y₂) := Iff.rfl lemma piSetoid_apply {ι : Sort*} {α : ι → Sort*} {r : ∀ i, Setoid (α i)} {x y : ∀ i, α i} : @Setoid.r _ (@piSetoid _ _ r) x y ↔ ∀ i, @Setoid.r _ (r i) (x i) (y i) := Iff.rfl /-- A bijection between the product of two quotients and the quotient by the product of the equivalence relations. -/ @[simps] def prodQuotientEquiv (r : Setoid α) (s : Setoid β) : Quotient r × Quotient s ≃ Quotient (r.prod s) where toFun | (x, y) => Quotient.map₂ Prod.mk (fun _ _ hx _ _ hy ↦ ⟨hx, hy⟩) x y invFun q := Quotient.liftOn' q (fun xy ↦ (Quotient.mk'' xy.1, Quotient.mk'' xy.2)) fun x y hxy ↦ Prod.ext (by simpa using hxy.1) (by simpa using hxy.2) left_inv q := by rcases q with ⟨qa, qb⟩ exact Quotient.inductionOn₂' qa qb fun _ _ ↦ rfl right_inv q := by simp only refine Quotient.inductionOn' q fun _ ↦ rfl /-- A bijection between an indexed product of quotients and the quotient by the product of the equivalence relations. -/ @[simps] noncomputable def piQuotientEquiv {ι : Sort*} {α : ι → Sort*} (r : ∀ i, Setoid (α i)) : (∀ i, Quotient (r i)) ≃ Quotient (@piSetoid _ _ r) where toFun x := Quotient.mk'' fun i ↦ (x i).out invFun q := Quotient.liftOn' q (fun x i ↦ Quotient.mk'' (x i)) fun x y hxy ↦ by ext i simpa using hxy i left_inv q := by ext i simp right_inv q := by refine Quotient.inductionOn' q fun _ ↦ ?_ simp only [Quotient.liftOn'_mk'', Quotient.eq''] intro i change Setoid.r _ _ rw [← Quotient.eq''] simp /-- The infimum of two equivalence relations. -/ instance : Min (Setoid α) := ⟨fun r s => ⟨fun x y => r x y ∧ s x y, ⟨fun x => ⟨r.refl' x, s.refl' x⟩, fun h => ⟨r.symm' h.1, s.symm' h.2⟩, fun h1 h2 => ⟨r.trans' h1.1 h2.1, s.trans' h1.2 h2.2⟩⟩⟩⟩ /-- The infimum of 2 equivalence relations r and s is the same relation as the infimum of the underlying binary operations. -/ theorem inf_def {r s : Setoid α} : ⇑(r ⊓ s) = ⇑r ⊓ ⇑s := rfl theorem inf_iff_and {r s : Setoid α} {x y} : (r ⊓ s) x y ↔ r x y ∧ s x y := Iff.rfl /-- The infimum of a set of equivalence relations. -/ instance : InfSet (Setoid α) := ⟨fun S => { r := fun x y => ∀ r ∈ S, r x y iseqv := ⟨fun x r _ => r.refl' x, fun h r hr => r.symm' <| h r hr, fun h1 h2 r hr => r.trans' (h1 r hr) <| h2 r hr⟩ }⟩ /-- The underlying binary operation of the infimum of a set of equivalence relations is the infimum of the set's image under the map to the underlying binary operation. -/ theorem sInf_def {s : Set (Setoid α)} : ⇑(sInf s) = sInf ((⇑) '' s) := by ext simp only [sInf_image, iInf_apply, iInf_Prop_eq] rfl instance : PartialOrder (Setoid α) where le := (· ≤ ·) lt r s := r ≤ s ∧ ¬s ≤ r le_refl _ _ _ := id le_trans _ _ _ hr hs _ _ h := hs <| hr h lt_iff_le_not_le _ _ := Iff.rfl le_antisymm _ _ h1 h2 := Setoid.ext fun _ _ => ⟨fun h => h1 h, fun h => h2 h⟩ /-- The complete lattice of equivalence relations on a type, with bottom element `=` and top element the trivial equivalence relation. -/ instance completeLattice : CompleteLattice (Setoid α) := { (completeLatticeOfInf (Setoid α)) fun _ => ⟨fun _ hr _ _ h => h _ hr, fun _ hr _ _ h _ hr' => hr hr' h⟩ with inf := Min.min inf_le_left := fun _ _ _ _ h => h.1 inf_le_right := fun _ _ _ _ h => h.2 le_inf := fun _ _ _ h1 h2 _ _ h => ⟨h1 h, h2 h⟩ top := ⟨fun _ _ => True, ⟨fun _ => trivial, fun h => h, fun h1 _ => h1⟩⟩ le_top := fun _ _ _ _ => trivial bot := ⟨(· = ·), ⟨fun _ => rfl, fun h => h.symm, fun h1 h2 => h1.trans h2⟩⟩ bot_le := fun r x _ h => h ▸ r.2.1 x } @[simp] theorem top_def : ⇑(⊤ : Setoid α) = ⊤ := rfl @[simp] theorem bot_def : ⇑(⊥ : Setoid α) = (· = ·) := rfl theorem eq_top_iff {s : Setoid α} : s = (⊤ : Setoid α) ↔ ∀ x y : α, s x y := by rw [_root_.eq_top_iff, Setoid.le_def, Setoid.top_def] simp only [Pi.top_apply, Prop.top_eq_true, forall_true_left] lemma sInf_equiv {S : Set (Setoid α)} {x y : α} : letI := sInf S x ≈ y ↔ ∀ s ∈ S, s x y := Iff.rfl
lemma sInf_iff {S : Set (Setoid α)} {x y : α} : sInf S x y ↔ ∀ s ∈ S, s x y := Iff.rfl lemma quotient_mk_sInf_eq {S : Set (Setoid α)} {x y : α} :
Mathlib/Data/Setoid/Basic.lean
203
206
/- 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.Probability.Variance import Mathlib.MeasureTheory.Function.UniformIntegrable /-! # Identically distributed random variables Two random variables defined on two (possibly different) probability spaces but taking value in the same space are *identically distributed* if their distributions (i.e., the image probability measures on the target space) coincide. We define this concept and establish its basic properties in this file. ## Main definitions and results * `IdentDistrib f g μ ν` registers that the image of `μ` under `f` coincides with the image of `ν` under `g` (and that `f` and `g` are almost everywhere measurable, as otherwise the image measures don't make sense). The measures can be kept implicit as in `IdentDistrib f g` if the spaces are registered as measure spaces. * `IdentDistrib.comp`: being identically distributed is stable under composition with measurable maps. There are two main kinds of lemmas, under the assumption that `f` and `g` are identically distributed: lemmas saying that two quantities computed for `f` and `g` are the same, and lemmas saying that if `f` has some property then `g` also has it. The first kind is registered as `IdentDistrib.foo_fst`, the second one as `IdentDistrib.foo_snd` (in the latter case, to deduce a property of `f` from one of `g`, use `h.symm.foo_snd` where `h : IdentDistrib f g μ ν`). For instance: * `IdentDistrib.measure_mem_eq`: if `f` and `g` are identically distributed, then the probabilities that they belong to a given measurable set are the same. * `IdentDistrib.integral_eq`: if `f` and `g` are identically distributed, then their integrals are the same. * `IdentDistrib.variance_eq`: if `f` and `g` are identically distributed, then their variances are the same. * `IdentDistrib.aestronglyMeasurable_snd`: if `f` and `g` are identically distributed and `f` is almost everywhere strongly measurable, then so is `g`. * `IdentDistrib.memLp_snd`: if `f` and `g` are identically distributed and `f` belongs to `ℒp`, then so does `g`. We also register several dot notation shortcuts for convenience. For instance, if `h : IdentDistrib f g μ ν`, then `h.sq` states that `f^2` and `g^2` are identically distributed, and `h.norm` states that `‖f‖` and `‖g‖` are identically distributed, and so on. -/ open MeasureTheory Filter Finset noncomputable section open scoped Topology MeasureTheory ENNReal NNReal variable {α β γ δ : Type*} [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ] [MeasurableSpace δ] namespace ProbabilityTheory /-- Two functions defined on two (possibly different) measure spaces are identically distributed if their image measures coincide. This only makes sense when the functions are ae measurable (as otherwise the image measures are not defined), so we require this as well in the definition. -/ structure IdentDistrib (f : α → γ) (g : β → γ) (μ : Measure α := by volume_tac) (ν : Measure β := by volume_tac) : Prop where aemeasurable_fst : AEMeasurable f μ aemeasurable_snd : AEMeasurable g ν map_eq : Measure.map f μ = Measure.map g ν namespace IdentDistrib open TopologicalSpace variable {μ : Measure α} {ν : Measure β} {f : α → γ} {g : β → γ} protected theorem refl (hf : AEMeasurable f μ) : IdentDistrib f f μ μ := { aemeasurable_fst := hf aemeasurable_snd := hf map_eq := rfl } protected theorem symm (h : IdentDistrib f g μ ν) : IdentDistrib g f ν μ := { aemeasurable_fst := h.aemeasurable_snd aemeasurable_snd := h.aemeasurable_fst map_eq := h.map_eq.symm } protected theorem trans {ρ : Measure δ} {h : δ → γ} (h₁ : IdentDistrib f g μ ν) (h₂ : IdentDistrib g h ν ρ) : IdentDistrib f h μ ρ := { aemeasurable_fst := h₁.aemeasurable_fst aemeasurable_snd := h₂.aemeasurable_snd map_eq := h₁.map_eq.trans h₂.map_eq } protected theorem comp_of_aemeasurable {u : γ → δ} (h : IdentDistrib f g μ ν) (hu : AEMeasurable u (Measure.map f μ)) : IdentDistrib (u ∘ f) (u ∘ g) μ ν := { aemeasurable_fst := hu.comp_aemeasurable h.aemeasurable_fst aemeasurable_snd := by rw [h.map_eq] at hu; exact hu.comp_aemeasurable h.aemeasurable_snd map_eq := by rw [← AEMeasurable.map_map_of_aemeasurable hu h.aemeasurable_fst, ← AEMeasurable.map_map_of_aemeasurable _ h.aemeasurable_snd, h.map_eq] rwa [← h.map_eq] } protected theorem comp {u : γ → δ} (h : IdentDistrib f g μ ν) (hu : Measurable u) : IdentDistrib (u ∘ f) (u ∘ g) μ ν := h.comp_of_aemeasurable hu.aemeasurable protected theorem of_ae_eq {g : α → γ} (hf : AEMeasurable f μ) (heq : f =ᵐ[μ] g) : IdentDistrib f g μ μ := { aemeasurable_fst := hf aemeasurable_snd := hf.congr heq map_eq := Measure.map_congr heq } lemma _root_.MeasureTheory.AEMeasurable.identDistrib_mk (hf : AEMeasurable f μ) : IdentDistrib f (hf.mk f) μ μ := IdentDistrib.of_ae_eq hf hf.ae_eq_mk lemma _root_.MeasureTheory.AEStronglyMeasurable.identDistrib_mk [TopologicalSpace γ] [PseudoMetrizableSpace γ] [BorelSpace γ] (hf : AEStronglyMeasurable f μ) : IdentDistrib f (hf.mk f) μ μ := IdentDistrib.of_ae_eq hf.aemeasurable hf.ae_eq_mk theorem measure_mem_eq (h : IdentDistrib f g μ ν) {s : Set γ} (hs : MeasurableSet s) : μ (f ⁻¹' s) = ν (g ⁻¹' s) := by rw [← Measure.map_apply_of_aemeasurable h.aemeasurable_fst hs, ← Measure.map_apply_of_aemeasurable h.aemeasurable_snd hs, h.map_eq] alias measure_preimage_eq := measure_mem_eq theorem ae_snd (h : IdentDistrib f g μ ν) {p : γ → Prop} (pmeas : MeasurableSet {x | p x}) (hp : ∀ᵐ x ∂μ, p (f x)) : ∀ᵐ x ∂ν, p (g x) := by apply (ae_map_iff h.aemeasurable_snd pmeas).1 rw [← h.map_eq] exact (ae_map_iff h.aemeasurable_fst pmeas).2 hp theorem ae_mem_snd (h : IdentDistrib f g μ ν) {t : Set γ} (tmeas : MeasurableSet t) (ht : ∀ᵐ x ∂μ, f x ∈ t) : ∀ᵐ x ∂ν, g x ∈ t := h.ae_snd tmeas ht /-- In a second countable topology, the first function in an identically distributed pair is a.e. strongly measurable. So is the second function, but use `h.symm.aestronglyMeasurable_fst` as `h.aestronglyMeasurable_snd` has a different meaning. -/ theorem aestronglyMeasurable_fst [TopologicalSpace γ] [MetrizableSpace γ] [OpensMeasurableSpace γ] [SecondCountableTopology γ] (h : IdentDistrib f g μ ν) : AEStronglyMeasurable f μ := h.aemeasurable_fst.aestronglyMeasurable /-- If `f` and `g` are identically distributed and `f` is a.e. strongly measurable, so is `g`. -/ theorem aestronglyMeasurable_snd [TopologicalSpace γ] [MetrizableSpace γ] [BorelSpace γ] (h : IdentDistrib f g μ ν) (hf : AEStronglyMeasurable f μ) : AEStronglyMeasurable g ν := by refine aestronglyMeasurable_iff_aemeasurable_separable.2 ⟨h.aemeasurable_snd, ?_⟩ rcases (aestronglyMeasurable_iff_aemeasurable_separable.1 hf).2 with ⟨t, t_sep, ht⟩ refine ⟨closure t, t_sep.closure, ?_⟩ apply h.ae_mem_snd isClosed_closure.measurableSet filter_upwards [ht] with x hx using subset_closure hx theorem aestronglyMeasurable_iff [TopologicalSpace γ] [MetrizableSpace γ] [BorelSpace γ] (h : IdentDistrib f g μ ν) : AEStronglyMeasurable f μ ↔ AEStronglyMeasurable g ν := ⟨fun hf => h.aestronglyMeasurable_snd hf, fun hg => h.symm.aestronglyMeasurable_snd hg⟩ theorem essSup_eq [ConditionallyCompleteLinearOrder γ] [TopologicalSpace γ] [OpensMeasurableSpace γ] [OrderClosedTopology γ] (h : IdentDistrib f g μ ν) : essSup f μ = essSup g ν := by have I : ∀ a, μ {x : α | a < f x} = ν {x : β | a < g x} := fun a => h.measure_mem_eq measurableSet_Ioi simp_rw [essSup_eq_sInf, I] theorem lintegral_eq {f : α → ℝ≥0∞} {g : β → ℝ≥0∞} (h : IdentDistrib f g μ ν) : ∫⁻ x, f x ∂μ = ∫⁻ x, g x ∂ν := by change ∫⁻ x, id (f x) ∂μ = ∫⁻ x, id (g x) ∂ν rw [← lintegral_map' aemeasurable_id h.aemeasurable_fst, ← lintegral_map' aemeasurable_id h.aemeasurable_snd, h.map_eq] theorem integral_eq [NormedAddCommGroup γ] [NormedSpace ℝ γ] [BorelSpace γ] (h : IdentDistrib f g μ ν) : ∫ x, f x ∂μ = ∫ x, g x ∂ν := by by_cases hf : AEStronglyMeasurable f μ · have A : AEStronglyMeasurable id (Measure.map f μ) := by
rw [aestronglyMeasurable_iff_aemeasurable_separable] rcases (aestronglyMeasurable_iff_aemeasurable_separable.1 hf).2 with ⟨t, t_sep, ht⟩ refine ⟨aemeasurable_id, ⟨closure t, t_sep.closure, ?_⟩⟩ rw [ae_map_iff h.aemeasurable_fst] · filter_upwards [ht] with x hx using subset_closure hx
Mathlib/Probability/IdentDistrib.lean
176
180
/- 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.Complex.Asymptotics import Mathlib.Analysis.SpecificLimits.Normed import Mathlib.Data.Complex.Trigonometric /-! # Complex and real exponential In this file we prove continuity of `Complex.exp` and `Real.exp`. We also prove a few facts about limits of `Real.exp` at infinity. ## Tags exp -/ noncomputable section open Asymptotics Bornology Finset Filter Function Metric Set Topology open scoped Nat namespace Complex variable {z y x : ℝ} theorem exp_bound_sq (x z : ℂ) (hz : ‖z‖ ≤ 1) : ‖exp (x + z) - exp x - z • exp x‖ ≤ ‖exp x‖ * ‖z‖ ^ 2 := calc ‖exp (x + z) - exp x - z * exp x‖ = ‖exp x * (exp z - 1 - z)‖ := by congr rw [exp_add] ring _ = ‖exp x‖ * ‖exp z - 1 - z‖ := norm_mul _ _ _ ≤ ‖exp x‖ * ‖z‖ ^ 2 := mul_le_mul_of_nonneg_left (norm_exp_sub_one_sub_id_le hz) (norm_nonneg _) theorem locally_lipschitz_exp {r : ℝ} (hr_nonneg : 0 ≤ r) (hr_le : r ≤ 1) (x y : ℂ) (hyx : ‖y - x‖ < r) : ‖exp y - exp x‖ ≤ (1 + r) * ‖exp x‖ * ‖y - x‖ := by have hy_eq : y = x + (y - x) := by abel have hyx_sq_le : ‖y - x‖ ^ 2 ≤ r * ‖y - x‖ := by rw [pow_two] exact mul_le_mul hyx.le le_rfl (norm_nonneg _) hr_nonneg have h_sq : ∀ z, ‖z‖ ≤ 1 → ‖exp (x + z) - exp x‖ ≤ ‖z‖ * ‖exp x‖ + ‖exp x‖ * ‖z‖ ^ 2 := by intro z hz have : ‖exp (x + z) - exp x - z • exp x‖ ≤ ‖exp x‖ * ‖z‖ ^ 2 := exp_bound_sq x z hz rw [← sub_le_iff_le_add', ← norm_smul z] exact (norm_sub_norm_le _ _).trans this calc ‖exp y - exp x‖ = ‖exp (x + (y - x)) - exp x‖ := by nth_rw 1 [hy_eq] _ ≤ ‖y - x‖ * ‖exp x‖ + ‖exp x‖ * ‖y - x‖ ^ 2 := h_sq (y - x) (hyx.le.trans hr_le) _ ≤ ‖y - x‖ * ‖exp x‖ + ‖exp x‖ * (r * ‖y - x‖) := (add_le_add_left (mul_le_mul le_rfl hyx_sq_le (sq_nonneg _) (norm_nonneg _)) _) _ = (1 + r) * ‖exp x‖ * ‖y - x‖ := by ring -- Porting note: proof by term mode `locally_lipschitz_exp zero_le_one le_rfl x` -- doesn't work because `‖y - x‖` and `dist y x` don't unify @[continuity] theorem continuous_exp : Continuous exp := continuous_iff_continuousAt.mpr fun x => continuousAt_of_locally_lipschitz zero_lt_one (2 * ‖exp x‖) (fun y ↦ by convert locally_lipschitz_exp zero_le_one le_rfl x y using 2 congr ring) theorem continuousOn_exp {s : Set ℂ} : ContinuousOn exp s := continuous_exp.continuousOn lemma exp_sub_sum_range_isBigO_pow (n : ℕ) : (fun x ↦ exp x - ∑ i ∈ Finset.range n, x ^ i / i !) =O[𝓝 0] (· ^ n) := by rcases (zero_le n).eq_or_lt with rfl | hn · simpa using continuous_exp.continuousAt.norm.isBoundedUnder_le · refine .of_bound (n.succ / (n ! * n)) ?_ rw [NormedAddCommGroup.nhds_zero_basis_norm_lt.eventually_iff] refine ⟨1, one_pos, fun x hx ↦ ?_⟩ convert exp_bound hx.out.le hn using 1 field_simp [mul_comm] lemma exp_sub_sum_range_succ_isLittleO_pow (n : ℕ) : (fun x ↦ exp x - ∑ i ∈ Finset.range (n + 1), x ^ i / i !) =o[𝓝 0] (· ^ n) := (exp_sub_sum_range_isBigO_pow (n + 1)).trans_isLittleO <| isLittleO_pow_pow n.lt_succ_self end Complex section ComplexContinuousExpComp variable {α : Type*} open Complex theorem Filter.Tendsto.cexp {l : Filter α} {f : α → ℂ} {z : ℂ} (hf : Tendsto f l (𝓝 z)) : Tendsto (fun x => exp (f x)) l (𝓝 (exp z)) := (continuous_exp.tendsto _).comp hf variable [TopologicalSpace α] {f : α → ℂ} {s : Set α} {x : α} nonrec theorem ContinuousWithinAt.cexp (h : ContinuousWithinAt f s x) : ContinuousWithinAt (fun y => exp (f y)) s x := h.cexp @[fun_prop] nonrec theorem ContinuousAt.cexp (h : ContinuousAt f x) : ContinuousAt (fun y => exp (f y)) x := h.cexp @[fun_prop] theorem ContinuousOn.cexp (h : ContinuousOn f s) : ContinuousOn (fun y => exp (f y)) s := fun x hx => (h x hx).cexp @[fun_prop] theorem Continuous.cexp (h : Continuous f) : Continuous fun y => exp (f y) := continuous_iff_continuousAt.2 fun _ => h.continuousAt.cexp /-- The complex exponential function is uniformly continuous on left half planes. -/ lemma UniformContinuousOn.cexp (a : ℝ) : UniformContinuousOn exp {x : ℂ | x.re ≤ a} := by have : Continuous (cexp - 1) := Continuous.sub (Continuous.cexp continuous_id') continuous_one rw [Metric.uniformContinuousOn_iff, Metric.continuous_iff'] at * intro ε hε simp only [gt_iff_lt, Pi.sub_apply, Pi.one_apply, dist_sub_eq_dist_add_right, sub_add_cancel] at this have ha : 0 < ε / (2 * Real.exp a) := by positivity have H := this 0 (ε / (2 * Real.exp a)) ha rw [Metric.eventually_nhds_iff] at H obtain ⟨δ, hδ⟩ := H refine ⟨δ, hδ.1, ?_⟩ intros x _ y hy hxy have h3 := hδ.2 (y := x - y) (by simpa only [dist_zero_right] using hxy) rw [dist_eq_norm, exp_zero] at * have : cexp x - cexp y = cexp y * (cexp (x - y) - 1) := by rw [mul_sub_one, ← exp_add] ring_nf rw [this, mul_comm] have hya : ‖cexp y‖ ≤ Real.exp a := by simp only [norm_exp, Real.exp_le_exp] exact hy simp only [gt_iff_lt, dist_zero_right, Set.mem_setOf_eq, norm_mul, Complex.norm_exp] at * apply lt_of_le_of_lt (mul_le_mul h3.le hya (Real.exp_nonneg y.re) (le_of_lt ha)) have hrr : ε / (2 * a.exp) * a.exp = ε / 2 := by nth_rw 2 [mul_comm] field_simp [mul_assoc] rw [hrr] exact div_two_lt_of_pos hε @[deprecated (since := "2025-02-11")] alias UniformlyContinuousOn.cexp := UniformContinuousOn.cexp end ComplexContinuousExpComp namespace Real @[continuity] theorem continuous_exp : Continuous exp := Complex.continuous_re.comp Complex.continuous_ofReal.cexp theorem continuousOn_exp {s : Set ℝ} : ContinuousOn exp s := continuous_exp.continuousOn lemma exp_sub_sum_range_isBigO_pow (n : ℕ) : (fun x ↦ exp x - ∑ i ∈ Finset.range n, x ^ i / i !) =O[𝓝 0] (· ^ n) := by have := (Complex.exp_sub_sum_range_isBigO_pow n).comp_tendsto (Complex.continuous_ofReal.tendsto' 0 0 rfl) simp only [Function.comp_def] at this norm_cast at this lemma exp_sub_sum_range_succ_isLittleO_pow (n : ℕ) : (fun x ↦ exp x - ∑ i ∈ Finset.range (n + 1), x ^ i / i !) =o[𝓝 0] (· ^ n) := (exp_sub_sum_range_isBigO_pow (n + 1)).trans_isLittleO <| isLittleO_pow_pow n.lt_succ_self end Real section RealContinuousExpComp variable {α : Type*} open Real theorem Filter.Tendsto.rexp {l : Filter α} {f : α → ℝ} {z : ℝ} (hf : Tendsto f l (𝓝 z)) : Tendsto (fun x => exp (f x)) l (𝓝 (exp z)) := (continuous_exp.tendsto _).comp hf variable [TopologicalSpace α] {f : α → ℝ} {s : Set α} {x : α} nonrec theorem ContinuousWithinAt.rexp (h : ContinuousWithinAt f s x) : ContinuousWithinAt (fun y ↦ exp (f y)) s x := h.rexp @[fun_prop] nonrec theorem ContinuousAt.rexp (h : ContinuousAt f x) : ContinuousAt (fun y ↦ exp (f y)) x := h.rexp @[fun_prop] theorem ContinuousOn.rexp (h : ContinuousOn f s) : ContinuousOn (fun y ↦ exp (f y)) s := fun x hx ↦ (h x hx).rexp @[fun_prop] theorem Continuous.rexp (h : Continuous f) : Continuous fun y ↦ exp (f y) := continuous_iff_continuousAt.2 fun _ ↦ h.continuousAt.rexp end RealContinuousExpComp namespace Real variable {α : Type*} {x y z : ℝ} {l : Filter α} theorem exp_half (x : ℝ) : exp (x / 2) = √(exp x) := by rw [eq_comm, sqrt_eq_iff_eq_sq, sq, ← exp_add, add_halves] <;> exact (exp_pos _).le /-- The real exponential function tends to `+∞` at `+∞`. -/ theorem tendsto_exp_atTop : Tendsto exp atTop atTop := by have A : Tendsto (fun x : ℝ => x + 1) atTop atTop := tendsto_atTop_add_const_right atTop 1 tendsto_id have B : ∀ᶠ x in atTop, x + 1 ≤ exp x := eventually_atTop.2 ⟨0, fun x _ => add_one_le_exp x⟩ exact tendsto_atTop_mono' atTop B A /-- The real exponential function tends to `0` at `-∞` or, equivalently, `exp(-x)` tends to `0` at `+∞` -/ theorem tendsto_exp_neg_atTop_nhds_zero : Tendsto (fun x => exp (-x)) atTop (𝓝 0) := (tendsto_inv_atTop_zero.comp tendsto_exp_atTop).congr fun x => (exp_neg x).symm /-- The real exponential function tends to `1` at `0`. -/ theorem tendsto_exp_nhds_zero_nhds_one : Tendsto exp (𝓝 0) (𝓝 1) := by convert continuous_exp.tendsto 0 simp theorem tendsto_exp_atBot : Tendsto exp atBot (𝓝 0) := (tendsto_exp_neg_atTop_nhds_zero.comp tendsto_neg_atBot_atTop).congr fun x => congr_arg exp <| neg_neg x theorem tendsto_exp_atBot_nhdsGT : Tendsto exp atBot (𝓝[>] 0) := tendsto_inf.2 ⟨tendsto_exp_atBot, tendsto_principal.2 <| Eventually.of_forall exp_pos⟩ @[deprecated (since := "2024-12-22")] alias tendsto_exp_atBot_nhdsWithin := tendsto_exp_atBot_nhdsGT @[simp] theorem isBoundedUnder_ge_exp_comp (l : Filter α) (f : α → ℝ) : IsBoundedUnder (· ≥ ·) l fun x => exp (f x) := isBoundedUnder_of ⟨0, fun _ => (exp_pos _).le⟩ @[simp] theorem isBoundedUnder_le_exp_comp {f : α → ℝ} : (IsBoundedUnder (· ≤ ·) l fun x => exp (f x)) ↔ IsBoundedUnder (· ≤ ·) l f := exp_monotone.isBoundedUnder_le_comp_iff tendsto_exp_atTop /-- The function `exp(x)/x^n` tends to `+∞` at `+∞`, for any natural number `n` -/ theorem tendsto_exp_div_pow_atTop (n : ℕ) : Tendsto (fun x => exp x / x ^ n) atTop atTop := by refine (atTop_basis_Ioi.tendsto_iff (atTop_basis' 1)).2 fun C hC₁ => ?_ have hC₀ : 0 < C := zero_lt_one.trans_le hC₁ have : 0 < (exp 1 * C)⁻¹ := inv_pos.2 (mul_pos (exp_pos _) hC₀) obtain ⟨N, hN⟩ : ∃ N : ℕ, ∀ k ≥ N, (↑k : ℝ) ^ n / exp 1 ^ k < (exp 1 * C)⁻¹ := eventually_atTop.1 ((tendsto_pow_const_div_const_pow_of_one_lt n (one_lt_exp_iff.2 zero_lt_one)).eventually (gt_mem_nhds this)) simp only [← exp_nat_mul, mul_one, div_lt_iff₀, exp_pos, ← div_eq_inv_mul] at hN refine ⟨N, trivial, fun x hx => ?_⟩ rw [Set.mem_Ioi] at hx have hx₀ : 0 < x := (Nat.cast_nonneg N).trans_lt hx rw [Set.mem_Ici, le_div_iff₀ (pow_pos hx₀ _), ← le_div_iff₀' hC₀] calc x ^ n ≤ ⌈x⌉₊ ^ n := by gcongr; exact Nat.le_ceil _ _ ≤ exp ⌈x⌉₊ / (exp 1 * C) := mod_cast (hN _ (Nat.lt_ceil.2 hx).le).le _ ≤ exp (x + 1) / (exp 1 * C) := by gcongr; exact (Nat.ceil_lt_add_one hx₀.le).le _ = exp x / C := by rw [add_comm, exp_add, mul_div_mul_left _ _ (exp_pos _).ne'] /-- The function `x^n * exp(-x)` tends to `0` at `+∞`, for any natural number `n`. -/ theorem tendsto_pow_mul_exp_neg_atTop_nhds_zero (n : ℕ) : Tendsto (fun x => x ^ n * exp (-x)) atTop (𝓝 0) := (tendsto_inv_atTop_zero.comp (tendsto_exp_div_pow_atTop n)).congr fun x => by rw [comp_apply, inv_eq_one_div, div_div_eq_mul_div, one_mul, div_eq_mul_inv, exp_neg] /-- The function `(b * exp x + c) / (x ^ n)` tends to `+∞` at `+∞`, for any natural number `n` and any real numbers `b` and `c` such that `b` is positive. -/ theorem tendsto_mul_exp_add_div_pow_atTop (b c : ℝ) (n : ℕ) (hb : 0 < b) : Tendsto (fun x => (b * exp x + c) / x ^ n) atTop atTop := by rcases eq_or_ne n 0 with (rfl | hn) · simp only [pow_zero, div_one] exact (tendsto_exp_atTop.const_mul_atTop hb).atTop_add tendsto_const_nhds simp only [add_div, mul_div_assoc] exact ((tendsto_exp_div_pow_atTop n).const_mul_atTop hb).atTop_add (tendsto_const_nhds.div_atTop (tendsto_pow_atTop hn)) /-- The function `(x ^ n) / (b * exp x + c)` tends to `0` at `+∞`, for any natural number `n` and any real numbers `b` and `c` such that `b` is nonzero. -/ theorem tendsto_div_pow_mul_exp_add_atTop (b c : ℝ) (n : ℕ) (hb : 0 ≠ b) : Tendsto (fun x => x ^ n / (b * exp x + c)) atTop (𝓝 0) := by have H : ∀ d e, 0 < d → Tendsto (fun x : ℝ => x ^ n / (d * exp x + e)) atTop (𝓝 0) := by intro b' c' h convert (tendsto_mul_exp_add_div_pow_atTop b' c' n h).inv_tendsto_atTop using 1 ext x simp rcases lt_or_gt_of_ne hb with h | h · exact H b c h · convert (H (-b) (-c) (neg_pos.mpr h)).neg using 1 · ext x field_simp rw [← neg_add (b * exp x) c, neg_div_neg_eq] · rw [neg_zero] /-- `Real.exp` as an order isomorphism between `ℝ` and `(0, +∞)`. -/ def expOrderIso : ℝ ≃o Ioi (0 : ℝ) := StrictMono.orderIsoOfSurjective _ (exp_strictMono.codRestrict exp_pos) <| (continuous_exp.subtype_mk _).surjective (by rw [tendsto_Ioi_atTop]; simp only [tendsto_exp_atTop]) (by rw [tendsto_Ioi_atBot]; simp only [tendsto_exp_atBot_nhdsGT]) @[simp] theorem coe_expOrderIso_apply (x : ℝ) : (expOrderIso x : ℝ) = exp x := rfl @[simp] theorem coe_comp_expOrderIso : (↑) ∘ expOrderIso = exp := rfl @[simp] theorem range_exp : range exp = Set.Ioi 0 := by rw [← coe_comp_expOrderIso, range_comp, expOrderIso.range_eq, image_univ, Subtype.range_coe] @[simp] theorem map_exp_atTop : map exp atTop = atTop := by rw [← coe_comp_expOrderIso, ← Filter.map_map, OrderIso.map_atTop, map_val_Ioi_atTop] @[simp] theorem comap_exp_atTop : comap exp atTop = atTop := by rw [← map_exp_atTop, comap_map exp_injective, map_exp_atTop] @[simp] theorem tendsto_exp_comp_atTop {f : α → ℝ} : Tendsto (fun x => exp (f x)) l atTop ↔ Tendsto f l atTop := by simp_rw [← comp_apply (f := exp), ← tendsto_comap_iff, comap_exp_atTop] theorem tendsto_comp_exp_atTop {f : ℝ → α} : Tendsto (fun x => f (exp x)) atTop l ↔ Tendsto f atTop l := by simp_rw [← comp_apply (g := exp), ← tendsto_map'_iff, map_exp_atTop] @[simp] theorem map_exp_atBot : map exp atBot = 𝓝[>] 0 := by rw [← coe_comp_expOrderIso, ← Filter.map_map, expOrderIso.map_atBot, ← map_coe_Ioi_atBot] @[simp] theorem comap_exp_nhdsGT_zero : comap exp (𝓝[>] 0) = atBot := by rw [← map_exp_atBot, comap_map exp_injective] @[deprecated (since := "2024-12-22")] alias comap_exp_nhdsWithin_Ioi_zero := comap_exp_nhdsGT_zero theorem tendsto_comp_exp_atBot {f : ℝ → α} : Tendsto (fun x => f (exp x)) atBot l ↔ Tendsto f (𝓝[>] 0) l := by rw [← map_exp_atBot, tendsto_map'_iff] rfl @[simp] theorem comap_exp_nhds_zero : comap exp (𝓝 0) = atBot := (comap_nhdsWithin_range exp 0).symm.trans <| by simp @[simp] theorem tendsto_exp_comp_nhds_zero {f : α → ℝ} : Tendsto (fun x => exp (f x)) l (𝓝 0) ↔ Tendsto f l atBot := by simp_rw [← comp_apply (f := exp), ← tendsto_comap_iff, comap_exp_nhds_zero] theorem isOpenEmbedding_exp : IsOpenEmbedding exp := isOpen_Ioi.isOpenEmbedding_subtypeVal.comp expOrderIso.toHomeomorph.isOpenEmbedding @[simp] theorem map_exp_nhds (x : ℝ) : map exp (𝓝 x) = 𝓝 (exp x) := isOpenEmbedding_exp.map_nhds_eq x @[simp] theorem comap_exp_nhds_exp (x : ℝ) : comap exp (𝓝 (exp x)) = 𝓝 x := (isOpenEmbedding_exp.nhds_eq_comap x).symm theorem isLittleO_pow_exp_atTop {n : ℕ} : (fun x : ℝ => x ^ n) =o[atTop] Real.exp := by simpa [isLittleO_iff_tendsto fun x hx => ((exp_pos x).ne' hx).elim] using tendsto_div_pow_mul_exp_add_atTop 1 0 n zero_ne_one
@[simp] theorem isBigO_exp_comp_exp_comp {f g : α → ℝ} : ((fun x => exp (f x)) =O[l] fun x => exp (g x)) ↔ IsBoundedUnder (· ≤ ·) l (f - g) :=
Mathlib/Analysis/SpecialFunctions/Exp.lean
380
382
/- Copyright (c) 2022 Kalle Kytölä. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kalle Kytölä -/ import Mathlib.MeasureTheory.Integral.BoundedContinuousFunction import Mathlib.Topology.MetricSpace.ThickenedIndicator /-! # Spaces where indicators of closed sets have decreasing approximations by continuous functions In this file we define a typeclass `HasOuterApproxClosed` for topological spaces in which indicator functions of closed sets have sequences of bounded continuous functions approximating them from above. All pseudo-emetrizable spaces have this property, see `instHasOuterApproxClosed`. In spaces with the `HasOuterApproxClosed` property, finite Borel measures are uniquely characterized by the integrals of bounded continuous functions. Also weak convergence of finite measures and convergence in distribution for random variables behave somewhat well in spaces with this property. ## Main definitions * `HasOuterApproxClosed`: the typeclass for topological spaces in which indicator functions of closed sets have sequences of bounded continuous functions approximating them. * `IsClosed.apprSeq`: a (non-constructive) choice of an approximating sequence to the indicator function of a closed set. ## Main results * `instHasOuterApproxClosed`: Any pseudo-emetrizable space has the property `HasOuterApproxClosed`. * `tendsto_lintegral_apprSeq`: The integrals of the approximating functions to the indicator of a closed set tend to the measure of the set. * `ext_of_forall_lintegral_eq_of_IsFiniteMeasure`: Two finite measures are equal if the integrals of all bounded continuous functions with respect to both agree. -/ open BoundedContinuousFunction MeasureTheory Topology Metric Filter Set ENNReal NNReal open scoped Topology ENNReal NNReal BoundedContinuousFunction section auxiliary namespace MeasureTheory variable {Ω : Type*} [TopologicalSpace Ω] [MeasurableSpace Ω] [OpensMeasurableSpace Ω] /-- A bounded convergence theorem for a finite measure: If bounded continuous non-negative functions are uniformly bounded by a constant and tend to a limit, then their integrals against the finite measure tend to the integral of the limit. This formulation assumes: * the functions tend to a limit along a countably generated filter; * the limit is in the almost everywhere sense; * boundedness holds almost everywhere; * integration is `MeasureTheory.lintegral`, i.e., the functions and their integrals are `ℝ≥0∞`-valued. -/ theorem tendsto_lintegral_nn_filter_of_le_const {ι : Type*} {L : Filter ι} [L.IsCountablyGenerated] (μ : Measure Ω) [IsFiniteMeasure μ] {fs : ι → Ω →ᵇ ℝ≥0} {c : ℝ≥0} (fs_le_const : ∀ᶠ i in L, ∀ᵐ ω : Ω ∂μ, fs i ω ≤ c) {f : Ω → ℝ≥0} (fs_lim : ∀ᵐ ω : Ω ∂μ, Tendsto (fun i ↦ fs i ω) L (𝓝 (f ω))) : Tendsto (fun i ↦ ∫⁻ ω, fs i ω ∂μ) L (𝓝 (∫⁻ ω, f ω ∂μ)) := by refine tendsto_lintegral_filter_of_dominated_convergence (fun _ ↦ c) (Eventually.of_forall fun i ↦ (ENNReal.continuous_coe.comp (fs i).continuous).measurable) ?_ (@lintegral_const_lt_top _ _ μ _ _ (@ENNReal.coe_ne_top c)).ne ?_ · simpa only [Function.comp_apply, ENNReal.coe_le_coe] using fs_le_const · simpa only [Function.comp_apply, ENNReal.tendsto_coe] using fs_lim /-- If bounded continuous functions tend to the indicator of a measurable set and are uniformly bounded, then their integrals against a finite measure tend to the measure of the set. This formulation assumes: * the functions tend to a limit along a countably generated filter; * the limit is in the almost everywhere sense; * boundedness holds almost everywhere. -/ theorem measure_of_cont_bdd_of_tendsto_filter_indicator {ι : Type*} {L : Filter ι} [L.IsCountablyGenerated] (μ : Measure Ω) [IsFiniteMeasure μ] {c : ℝ≥0} {E : Set Ω} (E_mble : MeasurableSet E) (fs : ι → Ω →ᵇ ℝ≥0) (fs_bdd : ∀ᶠ i in L, ∀ᵐ ω : Ω ∂μ, fs i ω ≤ c) (fs_lim : ∀ᵐ ω ∂μ, Tendsto (fun i ↦ fs i ω) L (𝓝 (indicator E (fun _ ↦ (1 : ℝ≥0)) ω))) : Tendsto (fun n ↦ lintegral μ fun ω ↦ fs n ω) L (𝓝 (μ E)) := by convert tendsto_lintegral_nn_filter_of_le_const μ fs_bdd fs_lim have aux : ∀ ω, indicator E (fun _ ↦ (1 : ℝ≥0∞)) ω = ↑(indicator E (fun _ ↦ (1 : ℝ≥0)) ω) := fun ω ↦ by simp only [ENNReal.coe_indicator, ENNReal.coe_one] simp_rw [← aux, lintegral_indicator E_mble] simp only [lintegral_one, Measure.restrict_apply, MeasurableSet.univ, univ_inter] /-- If a sequence of bounded continuous functions tends to the indicator of a measurable set and the functions are uniformly bounded, then their integrals against a finite measure tend to the measure of the set. A similar result with more general assumptions is `MeasureTheory.measure_of_cont_bdd_of_tendsto_filter_indicator`. -/ theorem measure_of_cont_bdd_of_tendsto_indicator (μ : Measure Ω) [IsFiniteMeasure μ] {c : ℝ≥0} {E : Set Ω} (E_mble : MeasurableSet E) (fs : ℕ → Ω →ᵇ ℝ≥0) (fs_bdd : ∀ n ω, fs n ω ≤ c) (fs_lim : Tendsto (fun n ω ↦ fs n ω) atTop (𝓝 (indicator E fun _ ↦ (1 : ℝ≥0)))) : Tendsto (fun n ↦ lintegral μ fun ω ↦ fs n ω) atTop (𝓝 (μ E)) := by have fs_lim' : ∀ ω, Tendsto (fun n : ℕ ↦ (fs n ω : ℝ≥0)) atTop (𝓝 (indicator E (fun _ ↦ (1 : ℝ≥0)) ω)) := by rw [tendsto_pi_nhds] at fs_lim exact fun ω ↦ fs_lim ω apply measure_of_cont_bdd_of_tendsto_filter_indicator μ E_mble fs (Eventually.of_forall fun n ↦ Eventually.of_forall (fs_bdd n)) (Eventually.of_forall fs_lim') /-- The integrals of thickened indicators of a closed set against a finite measure tend to the measure of the closed set if the thickening radii tend to zero. -/ theorem tendsto_lintegral_thickenedIndicator_of_isClosed {Ω : Type*} [MeasurableSpace Ω] [PseudoEMetricSpace Ω] [OpensMeasurableSpace Ω] (μ : Measure Ω) [IsFiniteMeasure μ] {F : Set Ω} (F_closed : IsClosed F) {δs : ℕ → ℝ} (δs_pos : ∀ n, 0 < δs n)
(δs_lim : Tendsto δs atTop (𝓝 0)) : Tendsto (fun n ↦ lintegral μ fun ω ↦ (thickenedIndicator (δs_pos n) F ω : ℝ≥0∞)) atTop (𝓝 (μ F)) := by apply measure_of_cont_bdd_of_tendsto_indicator μ F_closed.measurableSet (fun n ↦ thickenedIndicator (δs_pos n) F) fun n ω ↦ thickenedIndicator_le_one (δs_pos n) F ω have key := thickenedIndicator_tendsto_indicator_closure δs_pos δs_lim F rwa [F_closed.closure_eq] at key end MeasureTheory -- namespace
Mathlib/MeasureTheory/Measure/HasOuterApproxClosed.lean
110
119
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Jeremy Avigad -/ import Mathlib.Algebra.Group.Basic import Mathlib.Algebra.Notation.Pi import Mathlib.Data.Set.Lattice import Mathlib.Order.Filter.Defs /-! # Theory of filters on sets A *filter* on a type `α` is a collection of sets of `α` which contains the whole `α`, is upwards-closed, and is stable under intersection. They are mostly used to abstract two related kinds of ideas: * *limits*, including finite or infinite limits of sequences, finite or infinite limits of functions at a point or at infinity, etc... * *things happening eventually*, including things happening for large enough `n : ℕ`, or near enough a point `x`, or for close enough pairs of points, or things happening almost everywhere in the sense of measure theory. Dually, filters can also express the idea of *things happening often*: for arbitrarily large `n`, or at a point in any neighborhood of given a point etc... ## Main definitions In this file, we endow `Filter α` it with a complete lattice structure. This structure is lifted from the lattice structure on `Set (Set X)` using the Galois insertion which maps a filter to its elements in one direction, and an arbitrary set of sets to the smallest filter containing it in the other direction. We also prove `Filter` is a monadic functor, with a push-forward operation `Filter.map` and a pull-back operation `Filter.comap` that form a Galois connections for the order on filters. The examples of filters appearing in the description of the two motivating ideas are: * `(Filter.atTop : Filter ℕ)` : made of sets of `ℕ` containing `{n | n ≥ N}` for some `N` * `𝓝 x` : made of neighborhoods of `x` in a topological space (defined in topology.basic) * `𝓤 X` : made of entourages of a uniform space (those space are generalizations of metric spaces defined in `Mathlib/Topology/UniformSpace/Basic.lean`) * `MeasureTheory.ae` : made of sets whose complement has zero measure with respect to `μ` (defined in `Mathlib/MeasureTheory/OuterMeasure/AE`) The predicate "happening eventually" is `Filter.Eventually`, and "happening often" is `Filter.Frequently`, whose definitions are immediate after `Filter` is defined (but they come rather late in this file in order to immediately relate them to the lattice structure). ## Notations * `∀ᶠ x in f, p x` : `f.Eventually p`; * `∃ᶠ x in f, p x` : `f.Frequently p`; * `f =ᶠ[l] g` : `∀ᶠ x in l, f x = g x`; * `f ≤ᶠ[l] g` : `∀ᶠ x in l, f x ≤ g x`; * `𝓟 s` : `Filter.Principal s`, localized in `Filter`. ## References * [N. Bourbaki, *General Topology*][bourbaki1966] Important note: Bourbaki requires that a filter on `X` cannot contain all sets of `X`, which we do *not* require. This gives `Filter X` better formal properties, in particular a bottom element `⊥` for its lattice structure, at the cost of including the assumption `[NeBot f]` in a number of lemmas and definitions. -/ assert_not_exists OrderedSemiring Fintype open Function Set Order open scoped symmDiff universe u v w x y namespace Filter variable {α : Type u} {f g : Filter α} {s t : Set α} instance inhabitedMem : Inhabited { s : Set α // s ∈ f } := ⟨⟨univ, f.univ_sets⟩⟩ theorem filter_eq_iff : f = g ↔ f.sets = g.sets := ⟨congr_arg _, filter_eq⟩ @[simp] theorem sets_subset_sets : f.sets ⊆ g.sets ↔ g ≤ f := .rfl @[simp] theorem sets_ssubset_sets : f.sets ⊂ g.sets ↔ g < f := .rfl /-- An extensionality lemma that is useful for filters with good lemmas about `sᶜ ∈ f` (e.g., `Filter.comap`, `Filter.coprod`, `Filter.Coprod`, `Filter.cofinite`). -/ protected theorem coext (h : ∀ s, sᶜ ∈ f ↔ sᶜ ∈ g) : f = g := Filter.ext <| compl_surjective.forall.2 h instance : Trans (· ⊇ ·) ((· ∈ ·) : Set α → Filter α → Prop) (· ∈ ·) where trans h₁ h₂ := mem_of_superset h₂ h₁ instance : Trans Membership.mem (· ⊆ ·) (Membership.mem : Filter α → Set α → Prop) where trans h₁ h₂ := mem_of_superset h₁ h₂ @[simp] theorem inter_mem_iff {s t : Set α} : s ∩ t ∈ f ↔ s ∈ f ∧ t ∈ f := ⟨fun h => ⟨mem_of_superset h inter_subset_left, mem_of_superset h inter_subset_right⟩, and_imp.2 inter_mem⟩ theorem diff_mem {s t : Set α} (hs : s ∈ f) (ht : tᶜ ∈ f) : s \ t ∈ f := inter_mem hs ht theorem congr_sets (h : { x | x ∈ s ↔ x ∈ t } ∈ f) : s ∈ f ↔ t ∈ f := ⟨fun hs => mp_mem hs (mem_of_superset h fun _ => Iff.mp), fun hs => mp_mem hs (mem_of_superset h fun _ => Iff.mpr)⟩ lemma copy_eq {S} (hmem : ∀ s, s ∈ S ↔ s ∈ f) : f.copy S hmem = f := Filter.ext hmem /-- Weaker version of `Filter.biInter_mem` that assumes `Subsingleton β` rather than `Finite β`. -/ theorem biInter_mem' {β : Type v} {s : β → Set α} {is : Set β} (hf : is.Subsingleton) : (⋂ i ∈ is, s i) ∈ f ↔ ∀ i ∈ is, s i ∈ f := by apply Subsingleton.induction_on hf <;> simp /-- Weaker version of `Filter.iInter_mem` that assumes `Subsingleton β` rather than `Finite β`. -/ theorem iInter_mem' {β : Sort v} {s : β → Set α} [Subsingleton β] : (⋂ i, s i) ∈ f ↔ ∀ i, s i ∈ f := by rw [← sInter_range, sInter_eq_biInter, biInter_mem' (subsingleton_range s), forall_mem_range] theorem exists_mem_subset_iff : (∃ t ∈ f, t ⊆ s) ↔ s ∈ f := ⟨fun ⟨_, ht, ts⟩ => mem_of_superset ht ts, fun hs => ⟨s, hs, Subset.rfl⟩⟩ theorem monotone_mem {f : Filter α} : Monotone fun s => s ∈ f := fun _ _ hst h => mem_of_superset h hst theorem exists_mem_and_iff {P : Set α → Prop} {Q : Set α → Prop} (hP : Antitone P) (hQ : Antitone Q) : ((∃ u ∈ f, P u) ∧ ∃ u ∈ f, Q u) ↔ ∃ u ∈ f, P u ∧ Q u := by constructor · rintro ⟨⟨u, huf, hPu⟩, v, hvf, hQv⟩ exact ⟨u ∩ v, inter_mem huf hvf, hP inter_subset_left hPu, hQ inter_subset_right hQv⟩ · rintro ⟨u, huf, hPu, hQu⟩ exact ⟨⟨u, huf, hPu⟩, u, huf, hQu⟩ theorem forall_in_swap {β : Type*} {p : Set α → β → Prop} : (∀ a ∈ f, ∀ (b), p a b) ↔ ∀ (b), ∀ a ∈ f, p a b := Set.forall_in_swap end Filter namespace Filter variable {α : Type u} {β : Type v} {γ : Type w} {δ : Type*} {ι : Sort x} theorem mem_principal_self (s : Set α) : s ∈ 𝓟 s := Subset.rfl section Lattice variable {f g : Filter α} {s t : Set α} protected theorem not_le : ¬f ≤ g ↔ ∃ s ∈ g, s ∉ f := by simp_rw [le_def, not_forall, exists_prop] /-- `GenerateSets g s`: `s` is in the filter closure of `g`. -/ inductive GenerateSets (g : Set (Set α)) : Set α → Prop | basic {s : Set α} : s ∈ g → GenerateSets g s | univ : GenerateSets g univ | superset {s t : Set α} : GenerateSets g s → s ⊆ t → GenerateSets g t | inter {s t : Set α} : GenerateSets g s → GenerateSets g t → GenerateSets g (s ∩ t) /-- `generate g` is the largest filter containing the sets `g`. -/ def generate (g : Set (Set α)) : Filter α where sets := {s | GenerateSets g s} univ_sets := GenerateSets.univ sets_of_superset := GenerateSets.superset inter_sets := GenerateSets.inter lemma mem_generate_of_mem {s : Set <| Set α} {U : Set α} (h : U ∈ s) : U ∈ generate s := GenerateSets.basic h theorem le_generate_iff {s : Set (Set α)} {f : Filter α} : f ≤ generate s ↔ s ⊆ f.sets := Iff.intro (fun h _ hu => h <| GenerateSets.basic <| hu) fun h _ hu => hu.recOn (fun h' => h h') univ_mem (fun _ hxy hx => mem_of_superset hx hxy) fun _ _ hx hy => inter_mem hx hy @[simp] lemma generate_singleton (s : Set α) : generate {s} = 𝓟 s := le_antisymm (fun _t ht ↦ mem_of_superset (mem_generate_of_mem <| mem_singleton _) ht) <| le_generate_iff.2 <| singleton_subset_iff.2 Subset.rfl /-- `mkOfClosure s hs` constructs a filter on `α` whose elements set is exactly `s : Set (Set α)`, provided one gives the assumption `hs : (generate s).sets = s`. -/ protected def mkOfClosure (s : Set (Set α)) (hs : (generate s).sets = s) : Filter α where sets := s univ_sets := hs ▸ univ_mem sets_of_superset := hs ▸ mem_of_superset inter_sets := hs ▸ inter_mem theorem mkOfClosure_sets {s : Set (Set α)} {hs : (generate s).sets = s} : Filter.mkOfClosure s hs = generate s := Filter.ext fun u => show u ∈ (Filter.mkOfClosure s hs).sets ↔ u ∈ (generate s).sets from hs.symm ▸ Iff.rfl /-- Galois insertion from sets of sets into filters. -/ def giGenerate (α : Type*) : @GaloisInsertion (Set (Set α)) (Filter α)ᵒᵈ _ _ Filter.generate Filter.sets where gc _ _ := le_generate_iff le_l_u _ _ h := GenerateSets.basic h choice s hs := Filter.mkOfClosure s (le_antisymm hs <| le_generate_iff.1 <| le_rfl) choice_eq _ _ := mkOfClosure_sets theorem mem_inf_iff {f g : Filter α} {s : Set α} : s ∈ f ⊓ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, s = t₁ ∩ t₂ := Iff.rfl theorem mem_inf_of_left {f g : Filter α} {s : Set α} (h : s ∈ f) : s ∈ f ⊓ g := ⟨s, h, univ, univ_mem, (inter_univ s).symm⟩ theorem mem_inf_of_right {f g : Filter α} {s : Set α} (h : s ∈ g) : s ∈ f ⊓ g := ⟨univ, univ_mem, s, h, (univ_inter s).symm⟩ theorem inter_mem_inf {α : Type u} {f g : Filter α} {s t : Set α} (hs : s ∈ f) (ht : t ∈ g) : s ∩ t ∈ f ⊓ g := ⟨s, hs, t, ht, rfl⟩ theorem mem_inf_of_inter {f g : Filter α} {s t u : Set α} (hs : s ∈ f) (ht : t ∈ g) (h : s ∩ t ⊆ u) : u ∈ f ⊓ g := mem_of_superset (inter_mem_inf hs ht) h theorem mem_inf_iff_superset {f g : Filter α} {s : Set α} : s ∈ f ⊓ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ ∩ t₂ ⊆ s := ⟨fun ⟨t₁, h₁, t₂, h₂, Eq⟩ => ⟨t₁, h₁, t₂, h₂, Eq ▸ Subset.rfl⟩, fun ⟨_, h₁, _, h₂, sub⟩ => mem_inf_of_inter h₁ h₂ sub⟩ section CompleteLattice /-- Complete lattice structure on `Filter α`. -/ instance instCompleteLatticeFilter : CompleteLattice (Filter α) where inf a b := min a b sup a b := max a b le_sup_left _ _ _ h := h.1 le_sup_right _ _ _ h := h.2 sup_le _ _ _ h₁ h₂ _ h := ⟨h₁ h, h₂ h⟩ inf_le_left _ _ _ := mem_inf_of_left inf_le_right _ _ _ := mem_inf_of_right le_inf := fun _ _ _ h₁ h₂ _s ⟨_a, ha, _b, hb, hs⟩ => hs.symm ▸ inter_mem (h₁ ha) (h₂ hb) le_sSup _ _ h₁ _ h₂ := h₂ h₁ sSup_le _ _ h₁ _ h₂ _ h₃ := h₁ _ h₃ h₂ sInf_le _ _ h₁ _ h₂ := by rw [← Filter.sSup_lowerBounds]; exact fun _ h₃ ↦ h₃ h₁ h₂ le_sInf _ _ h₁ _ h₂ := by rw [← Filter.sSup_lowerBounds] at h₂; exact h₂ h₁ le_top _ _ := univ_mem' bot_le _ _ _ := trivial instance : Inhabited (Filter α) := ⟨⊥⟩ end CompleteLattice theorem NeBot.ne {f : Filter α} (hf : NeBot f) : f ≠ ⊥ := hf.ne' @[simp] theorem not_neBot {f : Filter α} : ¬f.NeBot ↔ f = ⊥ := neBot_iff.not_left theorem NeBot.mono {f g : Filter α} (hf : NeBot f) (hg : f ≤ g) : NeBot g := ⟨ne_bot_of_le_ne_bot hf.1 hg⟩ theorem neBot_of_le {f g : Filter α} [hf : NeBot f] (hg : f ≤ g) : NeBot g := hf.mono hg @[simp] theorem sup_neBot {f g : Filter α} : NeBot (f ⊔ g) ↔ NeBot f ∨ NeBot g := by simp only [neBot_iff, not_and_or, Ne, sup_eq_bot_iff] theorem not_disjoint_self_iff : ¬Disjoint f f ↔ f.NeBot := by rw [disjoint_self, neBot_iff] theorem bot_sets_eq : (⊥ : Filter α).sets = univ := rfl /-- Either `f = ⊥` or `Filter.NeBot f`. This is a version of `eq_or_ne` that uses `Filter.NeBot` as the second alternative, to be used as an instance. -/ theorem eq_or_neBot (f : Filter α) : f = ⊥ ∨ NeBot f := (eq_or_ne f ⊥).imp_right NeBot.mk theorem sup_sets_eq {f g : Filter α} : (f ⊔ g).sets = f.sets ∩ g.sets := (giGenerate α).gc.u_inf theorem sSup_sets_eq {s : Set (Filter α)} : (sSup s).sets = ⋂ f ∈ s, (f : Filter α).sets := (giGenerate α).gc.u_sInf theorem iSup_sets_eq {f : ι → Filter α} : (iSup f).sets = ⋂ i, (f i).sets := (giGenerate α).gc.u_iInf theorem generate_empty : Filter.generate ∅ = (⊤ : Filter α) := (giGenerate α).gc.l_bot theorem generate_univ : Filter.generate univ = (⊥ : Filter α) := bot_unique fun _ _ => GenerateSets.basic (mem_univ _) theorem generate_union {s t : Set (Set α)} : Filter.generate (s ∪ t) = Filter.generate s ⊓ Filter.generate t := (giGenerate α).gc.l_sup theorem generate_iUnion {s : ι → Set (Set α)} : Filter.generate (⋃ i, s i) = ⨅ i, Filter.generate (s i) := (giGenerate α).gc.l_iSup @[simp] theorem mem_sup {f g : Filter α} {s : Set α} : s ∈ f ⊔ g ↔ s ∈ f ∧ s ∈ g := Iff.rfl theorem union_mem_sup {f g : Filter α} {s t : Set α} (hs : s ∈ f) (ht : t ∈ g) : s ∪ t ∈ f ⊔ g := ⟨mem_of_superset hs subset_union_left, mem_of_superset ht subset_union_right⟩ @[simp] theorem mem_iSup {x : Set α} {f : ι → Filter α} : x ∈ iSup f ↔ ∀ i, x ∈ f i := by simp only [← Filter.mem_sets, iSup_sets_eq, mem_iInter] @[simp] theorem iSup_neBot {f : ι → Filter α} : (⨆ i, f i).NeBot ↔ ∃ i, (f i).NeBot := by simp [neBot_iff] theorem iInf_eq_generate (s : ι → Filter α) : iInf s = generate (⋃ i, (s i).sets) := eq_of_forall_le_iff fun _ ↦ by simp [le_generate_iff] theorem mem_iInf_of_mem {f : ι → Filter α} (i : ι) {s} (hs : s ∈ f i) : s ∈ ⨅ i, f i := iInf_le f i hs @[simp] theorem le_principal_iff {s : Set α} {f : Filter α} : f ≤ 𝓟 s ↔ s ∈ f := ⟨fun h => h Subset.rfl, fun hs _ ht => mem_of_superset hs ht⟩ theorem Iic_principal (s : Set α) : Iic (𝓟 s) = { l | s ∈ l } := Set.ext fun _ => le_principal_iff theorem principal_mono {s t : Set α} : 𝓟 s ≤ 𝓟 t ↔ s ⊆ t := by simp only [le_principal_iff, mem_principal] @[gcongr] alias ⟨_, _root_.GCongr.filter_principal_mono⟩ := principal_mono @[mono] theorem monotone_principal : Monotone (𝓟 : Set α → Filter α) := fun _ _ => principal_mono.2 @[simp] theorem principal_eq_iff_eq {s t : Set α} : 𝓟 s = 𝓟 t ↔ s = t := by simp only [le_antisymm_iff, le_principal_iff, mem_principal]; rfl @[simp] theorem join_principal_eq_sSup {s : Set (Filter α)} : join (𝓟 s) = sSup s := rfl @[simp] theorem principal_univ : 𝓟 (univ : Set α) = ⊤ := top_unique <| by simp only [le_principal_iff, mem_top, eq_self_iff_true] @[simp] theorem principal_empty : 𝓟 (∅ : Set α) = ⊥ := bot_unique fun _ _ => empty_subset _ theorem generate_eq_biInf (S : Set (Set α)) : generate S = ⨅ s ∈ S, 𝓟 s := eq_of_forall_le_iff fun f => by simp [le_generate_iff, le_principal_iff, subset_def] /-! ### Lattice equations -/ theorem empty_mem_iff_bot {f : Filter α} : ∅ ∈ f ↔ f = ⊥ := ⟨fun h => bot_unique fun s _ => mem_of_superset h (empty_subset s), fun h => h.symm ▸ mem_bot⟩ theorem nonempty_of_mem {f : Filter α} [hf : NeBot f] {s : Set α} (hs : s ∈ f) : s.Nonempty := s.eq_empty_or_nonempty.elim (fun h => absurd hs (h.symm ▸ mt empty_mem_iff_bot.mp hf.1)) id theorem NeBot.nonempty_of_mem {f : Filter α} (hf : NeBot f) {s : Set α} (hs : s ∈ f) : s.Nonempty := @Filter.nonempty_of_mem α f hf s hs @[simp] theorem empty_not_mem (f : Filter α) [NeBot f] : ¬∅ ∈ f := fun h => (nonempty_of_mem h).ne_empty rfl theorem nonempty_of_neBot (f : Filter α) [NeBot f] : Nonempty α := nonempty_of_exists <| nonempty_of_mem (univ_mem : univ ∈ f) theorem compl_not_mem {f : Filter α} {s : Set α} [NeBot f] (h : s ∈ f) : sᶜ ∉ f := fun hsc => (nonempty_of_mem (inter_mem h hsc)).ne_empty <| inter_compl_self s theorem filter_eq_bot_of_isEmpty [IsEmpty α] (f : Filter α) : f = ⊥ := empty_mem_iff_bot.mp <| univ_mem' isEmptyElim protected lemma disjoint_iff {f g : Filter α} : Disjoint f g ↔ ∃ s ∈ f, ∃ t ∈ g, Disjoint s t := by simp only [disjoint_iff, ← empty_mem_iff_bot, mem_inf_iff, inf_eq_inter, bot_eq_empty, @eq_comm _ ∅] theorem disjoint_of_disjoint_of_mem {f g : Filter α} {s t : Set α} (h : Disjoint s t) (hs : s ∈ f) (ht : t ∈ g) : Disjoint f g := Filter.disjoint_iff.mpr ⟨s, hs, t, ht, h⟩ theorem NeBot.not_disjoint (hf : f.NeBot) (hs : s ∈ f) (ht : t ∈ f) : ¬Disjoint s t := fun h => not_disjoint_self_iff.2 hf <| Filter.disjoint_iff.2 ⟨s, hs, t, ht, h⟩ theorem inf_eq_bot_iff {f g : Filter α} : f ⊓ g = ⊥ ↔ ∃ U ∈ f, ∃ V ∈ g, U ∩ V = ∅ := by simp only [← disjoint_iff, Filter.disjoint_iff, Set.disjoint_iff_inter_eq_empty] /-- There is exactly one filter on an empty type. -/ instance unique [IsEmpty α] : Unique (Filter α) where default := ⊥ uniq := filter_eq_bot_of_isEmpty theorem NeBot.nonempty (f : Filter α) [hf : f.NeBot] : Nonempty α := not_isEmpty_iff.mp fun _ ↦ hf.ne (Subsingleton.elim _ _) /-- There are only two filters on a `Subsingleton`: `⊥` and `⊤`. If the type is empty, then they are equal. -/ theorem eq_top_of_neBot [Subsingleton α] (l : Filter α) [NeBot l] : l = ⊤ := by refine top_unique fun s hs => ?_ obtain rfl : s = univ := Subsingleton.eq_univ_of_nonempty (nonempty_of_mem hs) exact univ_mem theorem forall_mem_nonempty_iff_neBot {f : Filter α} : (∀ s : Set α, s ∈ f → s.Nonempty) ↔ NeBot f := ⟨fun h => ⟨fun hf => not_nonempty_empty (h ∅ <| hf.symm ▸ mem_bot)⟩, @nonempty_of_mem _ _⟩ instance instNeBotTop [Nonempty α] : NeBot (⊤ : Filter α) := forall_mem_nonempty_iff_neBot.1 fun s hs => by rwa [mem_top.1 hs, ← nonempty_iff_univ_nonempty] instance instNontrivialFilter [Nonempty α] : Nontrivial (Filter α) := ⟨⟨⊤, ⊥, instNeBotTop.ne⟩⟩ theorem nontrivial_iff_nonempty : Nontrivial (Filter α) ↔ Nonempty α := ⟨fun _ => by_contra fun h' => haveI := not_nonempty_iff.1 h' not_subsingleton (Filter α) inferInstance, @Filter.instNontrivialFilter α⟩ theorem eq_sInf_of_mem_iff_exists_mem {S : Set (Filter α)} {l : Filter α} (h : ∀ {s}, s ∈ l ↔ ∃ f ∈ S, s ∈ f) : l = sInf S := le_antisymm (le_sInf fun f hf _ hs => h.2 ⟨f, hf, hs⟩) fun _ hs => let ⟨_, hf, hs⟩ := h.1 hs; (sInf_le hf) hs theorem eq_iInf_of_mem_iff_exists_mem {f : ι → Filter α} {l : Filter α} (h : ∀ {s}, s ∈ l ↔ ∃ i, s ∈ f i) : l = iInf f := eq_sInf_of_mem_iff_exists_mem <| h.trans (exists_range_iff (p := (_ ∈ ·))).symm theorem eq_biInf_of_mem_iff_exists_mem {f : ι → Filter α} {p : ι → Prop} {l : Filter α} (h : ∀ {s}, s ∈ l ↔ ∃ i, p i ∧ s ∈ f i) : l = ⨅ (i) (_ : p i), f i := by rw [iInf_subtype'] exact eq_iInf_of_mem_iff_exists_mem fun {_} => by simp only [Subtype.exists, h, exists_prop] theorem iInf_sets_eq {f : ι → Filter α} (h : Directed (· ≥ ·) f) [ne : Nonempty ι] : (iInf f).sets = ⋃ i, (f i).sets := let ⟨i⟩ := ne let u := { sets := ⋃ i, (f i).sets univ_sets := mem_iUnion.2 ⟨i, univ_mem⟩ sets_of_superset := by simp only [mem_iUnion, exists_imp] exact fun i hx hxy => ⟨i, mem_of_superset hx hxy⟩ inter_sets := by simp only [mem_iUnion, exists_imp] intro x y a hx b hy rcases h a b with ⟨c, ha, hb⟩ exact ⟨c, inter_mem (ha hx) (hb hy)⟩ } have : u = iInf f := eq_iInf_of_mem_iff_exists_mem mem_iUnion congr_arg Filter.sets this.symm theorem mem_iInf_of_directed {f : ι → Filter α} (h : Directed (· ≥ ·) f) [Nonempty ι] (s) : s ∈ iInf f ↔ ∃ i, s ∈ f i := by simp only [← Filter.mem_sets, iInf_sets_eq h, mem_iUnion] theorem mem_biInf_of_directed {f : β → Filter α} {s : Set β} (h : DirectedOn (f ⁻¹'o (· ≥ ·)) s) (ne : s.Nonempty) {t : Set α} : (t ∈ ⨅ i ∈ s, f i) ↔ ∃ i ∈ s, t ∈ f i := by haveI := ne.to_subtype simp_rw [iInf_subtype', mem_iInf_of_directed h.directed_val, Subtype.exists, exists_prop] theorem biInf_sets_eq {f : β → Filter α} {s : Set β} (h : DirectedOn (f ⁻¹'o (· ≥ ·)) s) (ne : s.Nonempty) : (⨅ i ∈ s, f i).sets = ⋃ i ∈ s, (f i).sets := ext fun t => by simp [mem_biInf_of_directed h ne] @[simp] theorem sup_join {f₁ f₂ : Filter (Filter α)} : join f₁ ⊔ join f₂ = join (f₁ ⊔ f₂) := Filter.ext fun x => by simp only [mem_sup, mem_join] @[simp] theorem iSup_join {ι : Sort w} {f : ι → Filter (Filter α)} : ⨆ x, join (f x) = join (⨆ x, f x) := Filter.ext fun x => by simp only [mem_iSup, mem_join] instance : DistribLattice (Filter α) := { Filter.instCompleteLatticeFilter with le_sup_inf := by intro x y z s simp only [and_assoc, mem_inf_iff, mem_sup, exists_prop, exists_imp, and_imp] rintro hs t₁ ht₁ t₂ ht₂ rfl exact ⟨t₁, x.sets_of_superset hs inter_subset_left, ht₁, t₂, x.sets_of_superset hs inter_subset_right, ht₂, rfl⟩ } /-- If `f : ι → Filter α` is directed, `ι` is not empty, and `∀ i, f i ≠ ⊥`, then `iInf f ≠ ⊥`. See also `iInf_neBot_of_directed` for a version assuming `Nonempty α` instead of `Nonempty ι`. -/ theorem iInf_neBot_of_directed' {f : ι → Filter α} [Nonempty ι] (hd : Directed (· ≥ ·) f) : (∀ i, NeBot (f i)) → NeBot (iInf f) := not_imp_not.1 <| by simpa only [not_forall, not_neBot, ← empty_mem_iff_bot, mem_iInf_of_directed hd] using id /-- If `f : ι → Filter α` is directed, `α` is not empty, and `∀ i, f i ≠ ⊥`, then `iInf f ≠ ⊥`. See also `iInf_neBot_of_directed'` for a version assuming `Nonempty ι` instead of `Nonempty α`. -/ theorem iInf_neBot_of_directed {f : ι → Filter α} [hn : Nonempty α] (hd : Directed (· ≥ ·) f) (hb : ∀ i, NeBot (f i)) : NeBot (iInf f) := by cases isEmpty_or_nonempty ι · constructor simp [iInf_of_empty f, top_ne_bot] · exact iInf_neBot_of_directed' hd hb theorem sInf_neBot_of_directed' {s : Set (Filter α)} (hne : s.Nonempty) (hd : DirectedOn (· ≥ ·) s) (hbot : ⊥ ∉ s) : NeBot (sInf s) := (sInf_eq_iInf' s).symm ▸ @iInf_neBot_of_directed' _ _ _ hne.to_subtype hd.directed_val fun ⟨_, hf⟩ => ⟨ne_of_mem_of_not_mem hf hbot⟩ theorem sInf_neBot_of_directed [Nonempty α] {s : Set (Filter α)} (hd : DirectedOn (· ≥ ·) s) (hbot : ⊥ ∉ s) : NeBot (sInf s) := (sInf_eq_iInf' s).symm ▸ iInf_neBot_of_directed hd.directed_val fun ⟨_, hf⟩ => ⟨ne_of_mem_of_not_mem hf hbot⟩ theorem iInf_neBot_iff_of_directed' {f : ι → Filter α} [Nonempty ι] (hd : Directed (· ≥ ·) f) : NeBot (iInf f) ↔ ∀ i, NeBot (f i) := ⟨fun H i => H.mono (iInf_le _ i), iInf_neBot_of_directed' hd⟩ theorem iInf_neBot_iff_of_directed {f : ι → Filter α} [Nonempty α] (hd : Directed (· ≥ ·) f) : NeBot (iInf f) ↔ ∀ i, NeBot (f i) := ⟨fun H i => H.mono (iInf_le _ i), iInf_neBot_of_directed hd⟩ /-! #### `principal` equations -/ @[simp] theorem inf_principal {s t : Set α} : 𝓟 s ⊓ 𝓟 t = 𝓟 (s ∩ t) := le_antisymm (by simp only [le_principal_iff, mem_inf_iff]; exact ⟨s, Subset.rfl, t, Subset.rfl, rfl⟩) (by simp [le_inf_iff, inter_subset_left, inter_subset_right]) @[simp] theorem sup_principal {s t : Set α} : 𝓟 s ⊔ 𝓟 t = 𝓟 (s ∪ t) := Filter.ext fun u => by simp only [union_subset_iff, mem_sup, mem_principal] @[simp] theorem iSup_principal {ι : Sort w} {s : ι → Set α} : ⨆ x, 𝓟 (s x) = 𝓟 (⋃ i, s i) := Filter.ext fun x => by simp only [mem_iSup, mem_principal, iUnion_subset_iff] @[simp] theorem principal_eq_bot_iff {s : Set α} : 𝓟 s = ⊥ ↔ s = ∅ := empty_mem_iff_bot.symm.trans <| mem_principal.trans subset_empty_iff @[simp] theorem principal_neBot_iff {s : Set α} : NeBot (𝓟 s) ↔ s.Nonempty := neBot_iff.trans <| (not_congr principal_eq_bot_iff).trans nonempty_iff_ne_empty.symm alias ⟨_, _root_.Set.Nonempty.principal_neBot⟩ := principal_neBot_iff theorem isCompl_principal (s : Set α) : IsCompl (𝓟 s) (𝓟 sᶜ) := IsCompl.of_eq (by rw [inf_principal, inter_compl_self, principal_empty]) <| by rw [sup_principal, union_compl_self, principal_univ] theorem mem_inf_principal' {f : Filter α} {s t : Set α} : s ∈ f ⊓ 𝓟 t ↔ tᶜ ∪ s ∈ f := by simp only [← le_principal_iff, (isCompl_principal s).le_left_iff, disjoint_assoc, inf_principal, ← (isCompl_principal (t ∩ sᶜ)).le_right_iff, compl_inter, compl_compl] lemma mem_inf_principal {f : Filter α} {s t : Set α} : s ∈ f ⊓ 𝓟 t ↔ { x | x ∈ t → x ∈ s } ∈ f := by simp only [mem_inf_principal', imp_iff_not_or, setOf_or, compl_def, setOf_mem_eq] lemma iSup_inf_principal (f : ι → Filter α) (s : Set α) : ⨆ i, f i ⊓ 𝓟 s = (⨆ i, f i) ⊓ 𝓟 s := by ext simp only [mem_iSup, mem_inf_principal] theorem inf_principal_eq_bot {f : Filter α} {s : Set α} : f ⊓ 𝓟 s = ⊥ ↔ sᶜ ∈ f := by rw [← empty_mem_iff_bot, mem_inf_principal] simp only [mem_empty_iff_false, imp_false, compl_def] theorem mem_of_eq_bot {f : Filter α} {s : Set α} (h : f ⊓ 𝓟 sᶜ = ⊥) : s ∈ f := by rwa [inf_principal_eq_bot, compl_compl] at h theorem diff_mem_inf_principal_compl {f : Filter α} {s : Set α} (hs : s ∈ f) (t : Set α) : s \ t ∈ f ⊓ 𝓟 tᶜ := inter_mem_inf hs <| mem_principal_self tᶜ theorem principal_le_iff {s : Set α} {f : Filter α} : 𝓟 s ≤ f ↔ ∀ V ∈ f, s ⊆ V := by simp_rw [le_def, mem_principal] end Lattice @[mono, gcongr] theorem join_mono {f₁ f₂ : Filter (Filter α)} (h : f₁ ≤ f₂) : join f₁ ≤ join f₂ := fun _ hs => h hs /-! ### Eventually -/ theorem eventually_iff {f : Filter α} {P : α → Prop} : (∀ᶠ x in f, P x) ↔ { x | P x } ∈ f := Iff.rfl @[simp] theorem eventually_mem_set {s : Set α} {l : Filter α} : (∀ᶠ x in l, x ∈ s) ↔ s ∈ l := Iff.rfl protected theorem ext' {f₁ f₂ : Filter α} (h : ∀ p : α → Prop, (∀ᶠ x in f₁, p x) ↔ ∀ᶠ x in f₂, p x) : f₁ = f₂ := Filter.ext h theorem Eventually.filter_mono {f₁ f₂ : Filter α} (h : f₁ ≤ f₂) {p : α → Prop} (hp : ∀ᶠ x in f₂, p x) : ∀ᶠ x in f₁, p x := h hp theorem eventually_of_mem {f : Filter α} {P : α → Prop} {U : Set α} (hU : U ∈ f) (h : ∀ x ∈ U, P x) : ∀ᶠ x in f, P x := mem_of_superset hU h protected theorem Eventually.and {p q : α → Prop} {f : Filter α} : f.Eventually p → f.Eventually q → ∀ᶠ x in f, p x ∧ q x := inter_mem @[simp] theorem eventually_true (f : Filter α) : ∀ᶠ _ in f, True := univ_mem theorem Eventually.of_forall {p : α → Prop} {f : Filter α} (hp : ∀ x, p x) : ∀ᶠ x in f, p x := univ_mem' hp @[simp] theorem eventually_false_iff_eq_bot {f : Filter α} : (∀ᶠ _ in f, False) ↔ f = ⊥ := empty_mem_iff_bot @[simp] theorem eventually_const {f : Filter α} [t : NeBot f] {p : Prop} : (∀ᶠ _ in f, p) ↔ p := by by_cases h : p <;> simp [h, t.ne] theorem eventually_iff_exists_mem {p : α → Prop} {f : Filter α} : (∀ᶠ x in f, p x) ↔ ∃ v ∈ f, ∀ y ∈ v, p y := exists_mem_subset_iff.symm theorem Eventually.exists_mem {p : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) : ∃ v ∈ f, ∀ y ∈ v, p y := eventually_iff_exists_mem.1 hp theorem Eventually.mp {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) (hq : ∀ᶠ x in f, p x → q x) : ∀ᶠ x in f, q x := mp_mem hp hq theorem Eventually.mono {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) (hq : ∀ x, p x → q x) : ∀ᶠ x in f, q x := hp.mp (Eventually.of_forall hq) theorem forall_eventually_of_eventually_forall {f : Filter α} {p : α → β → Prop} (h : ∀ᶠ x in f, ∀ y, p x y) : ∀ y, ∀ᶠ x in f, p x y := fun y => h.mono fun _ h => h y @[simp] theorem eventually_and {p q : α → Prop} {f : Filter α} : (∀ᶠ x in f, p x ∧ q x) ↔ (∀ᶠ x in f, p x) ∧ ∀ᶠ x in f, q x := inter_mem_iff theorem Eventually.congr {f : Filter α} {p q : α → Prop} (h' : ∀ᶠ x in f, p x) (h : ∀ᶠ x in f, p x ↔ q x) : ∀ᶠ x in f, q x := h'.mp (h.mono fun _ hx => hx.mp) theorem eventually_congr {f : Filter α} {p q : α → Prop} (h : ∀ᶠ x in f, p x ↔ q x) : (∀ᶠ x in f, p x) ↔ ∀ᶠ x in f, q x := ⟨fun hp => hp.congr h, fun hq => hq.congr <| by simpa only [Iff.comm] using h⟩ @[simp] theorem eventually_or_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} : (∀ᶠ x in f, p ∨ q x) ↔ p ∨ ∀ᶠ x in f, q x := by_cases (fun h : p => by simp [h]) fun h => by simp [h] @[simp] theorem eventually_or_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} : (∀ᶠ x in f, p x ∨ q) ↔ (∀ᶠ x in f, p x) ∨ q := by simp only [@or_comm _ q, eventually_or_distrib_left] theorem eventually_imp_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} : (∀ᶠ x in f, p → q x) ↔ p → ∀ᶠ x in f, q x := by simp only [imp_iff_not_or, eventually_or_distrib_left] @[simp] theorem eventually_bot {p : α → Prop} : ∀ᶠ x in ⊥, p x := ⟨⟩ @[simp] theorem eventually_top {p : α → Prop} : (∀ᶠ x in ⊤, p x) ↔ ∀ x, p x := Iff.rfl @[simp] theorem eventually_sup {p : α → Prop} {f g : Filter α} : (∀ᶠ x in f ⊔ g, p x) ↔ (∀ᶠ x in f, p x) ∧ ∀ᶠ x in g, p x := Iff.rfl @[simp] theorem eventually_sSup {p : α → Prop} {fs : Set (Filter α)} : (∀ᶠ x in sSup fs, p x) ↔ ∀ f ∈ fs, ∀ᶠ x in f, p x := Iff.rfl @[simp] theorem eventually_iSup {p : α → Prop} {fs : ι → Filter α} : (∀ᶠ x in ⨆ b, fs b, p x) ↔ ∀ b, ∀ᶠ x in fs b, p x := mem_iSup @[simp] theorem eventually_principal {a : Set α} {p : α → Prop} : (∀ᶠ x in 𝓟 a, p x) ↔ ∀ x ∈ a, p x := Iff.rfl theorem Eventually.forall_mem {α : Type*} {f : Filter α} {s : Set α} {P : α → Prop} (hP : ∀ᶠ x in f, P x) (hf : 𝓟 s ≤ f) : ∀ x ∈ s, P x := Filter.eventually_principal.mp (hP.filter_mono hf) theorem eventually_inf {f g : Filter α} {p : α → Prop} : (∀ᶠ x in f ⊓ g, p x) ↔ ∃ s ∈ f, ∃ t ∈ g, ∀ x ∈ s ∩ t, p x := mem_inf_iff_superset theorem eventually_inf_principal {f : Filter α} {p : α → Prop} {s : Set α} : (∀ᶠ x in f ⊓ 𝓟 s, p x) ↔ ∀ᶠ x in f, x ∈ s → p x := mem_inf_principal theorem eventually_iff_all_subsets {f : Filter α} {p : α → Prop} : (∀ᶠ x in f, p x) ↔ ∀ (s : Set α), ∀ᶠ x in f, x ∈ s → p x where mp h _ := by filter_upwards [h] with _ pa _ using pa mpr h := by filter_upwards [h univ] with _ pa using pa (by simp) /-! ### Frequently -/ theorem Eventually.frequently {f : Filter α} [NeBot f] {p : α → Prop} (h : ∀ᶠ x in f, p x) : ∃ᶠ x in f, p x := compl_not_mem h theorem Frequently.of_forall {f : Filter α} [NeBot f] {p : α → Prop} (h : ∀ x, p x) : ∃ᶠ x in f, p x := Eventually.frequently (Eventually.of_forall h) theorem Frequently.mp {p q : α → Prop} {f : Filter α} (h : ∃ᶠ x in f, p x) (hpq : ∀ᶠ x in f, p x → q x) : ∃ᶠ x in f, q x := mt (fun hq => hq.mp <| hpq.mono fun _ => mt) h lemma frequently_congr {p q : α → Prop} {f : Filter α} (h : ∀ᶠ x in f, p x ↔ q x) : (∃ᶠ x in f, p x) ↔ ∃ᶠ x in f, q x := ⟨fun h' ↦ h'.mp (h.mono fun _ ↦ Iff.mp), fun h' ↦ h'.mp (h.mono fun _ ↦ Iff.mpr)⟩ theorem Frequently.filter_mono {p : α → Prop} {f g : Filter α} (h : ∃ᶠ x in f, p x) (hle : f ≤ g) : ∃ᶠ x in g, p x := mt (fun h' => h'.filter_mono hle) h theorem Frequently.mono {p q : α → Prop} {f : Filter α} (h : ∃ᶠ x in f, p x) (hpq : ∀ x, p x → q x) : ∃ᶠ x in f, q x := h.mp (Eventually.of_forall hpq) theorem Frequently.and_eventually {p q : α → Prop} {f : Filter α} (hp : ∃ᶠ x in f, p x) (hq : ∀ᶠ x in f, q x) : ∃ᶠ x in f, p x ∧ q x := by refine mt (fun h => hq.mp <| h.mono ?_) hp exact fun x hpq hq hp => hpq ⟨hp, hq⟩ theorem Eventually.and_frequently {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) (hq : ∃ᶠ x in f, q x) : ∃ᶠ x in f, p x ∧ q x := by simpa only [and_comm] using hq.and_eventually hp theorem Frequently.exists {p : α → Prop} {f : Filter α} (hp : ∃ᶠ x in f, p x) : ∃ x, p x := by by_contra H replace H : ∀ᶠ x in f, ¬p x := Eventually.of_forall (not_exists.1 H) exact hp H theorem Eventually.exists {p : α → Prop} {f : Filter α} [NeBot f] (hp : ∀ᶠ x in f, p x) : ∃ x, p x := hp.frequently.exists lemma frequently_iff_neBot {l : Filter α} {p : α → Prop} : (∃ᶠ x in l, p x) ↔ NeBot (l ⊓ 𝓟 {x | p x}) := by rw [neBot_iff, Ne, inf_principal_eq_bot]; rfl lemma frequently_mem_iff_neBot {l : Filter α} {s : Set α} : (∃ᶠ x in l, x ∈ s) ↔ NeBot (l ⊓ 𝓟 s) := frequently_iff_neBot theorem frequently_iff_forall_eventually_exists_and {p : α → Prop} {f : Filter α} : (∃ᶠ x in f, p x) ↔ ∀ {q : α → Prop}, (∀ᶠ x in f, q x) → ∃ x, p x ∧ q x := ⟨fun hp _ hq => (hp.and_eventually hq).exists, fun H hp => by simpa only [and_not_self_iff, exists_false] using H hp⟩ theorem frequently_iff {f : Filter α} {P : α → Prop} : (∃ᶠ x in f, P x) ↔ ∀ {U}, U ∈ f → ∃ x ∈ U, P x := by simp only [frequently_iff_forall_eventually_exists_and, @and_comm (P _)] rfl @[simp] theorem not_eventually {p : α → Prop} {f : Filter α} : (¬∀ᶠ x in f, p x) ↔ ∃ᶠ x in f, ¬p x := by simp [Filter.Frequently] @[simp] theorem not_frequently {p : α → Prop} {f : Filter α} : (¬∃ᶠ x in f, p x) ↔ ∀ᶠ x in f, ¬p x := by simp only [Filter.Frequently, not_not] @[simp] theorem frequently_true_iff_neBot (f : Filter α) : (∃ᶠ _ in f, True) ↔ NeBot f := by simp [frequently_iff_neBot] @[simp] theorem frequently_false (f : Filter α) : ¬∃ᶠ _ in f, False := by simp @[simp] theorem frequently_const {f : Filter α} [NeBot f] {p : Prop} : (∃ᶠ _ in f, p) ↔ p := by by_cases p <;> simp [*] @[simp] theorem frequently_or_distrib {f : Filter α} {p q : α → Prop} : (∃ᶠ x in f, p x ∨ q x) ↔ (∃ᶠ x in f, p x) ∨ ∃ᶠ x in f, q x := by simp only [Filter.Frequently, ← not_and_or, not_or, eventually_and] theorem frequently_or_distrib_left {f : Filter α} [NeBot f] {p : Prop} {q : α → Prop} : (∃ᶠ x in f, p ∨ q x) ↔ p ∨ ∃ᶠ x in f, q x := by simp theorem frequently_or_distrib_right {f : Filter α} [NeBot f] {p : α → Prop} {q : Prop} : (∃ᶠ x in f, p x ∨ q) ↔ (∃ᶠ x in f, p x) ∨ q := by simp theorem frequently_imp_distrib {f : Filter α} {p q : α → Prop} : (∃ᶠ x in f, p x → q x) ↔ (∀ᶠ x in f, p x) → ∃ᶠ x in f, q x := by simp [imp_iff_not_or] theorem frequently_imp_distrib_left {f : Filter α} [NeBot f] {p : Prop} {q : α → Prop} : (∃ᶠ x in f, p → q x) ↔ p → ∃ᶠ x in f, q x := by simp [frequently_imp_distrib] theorem frequently_imp_distrib_right {f : Filter α} [NeBot f] {p : α → Prop} {q : Prop} : (∃ᶠ x in f, p x → q) ↔ (∀ᶠ x in f, p x) → q := by simp only [frequently_imp_distrib, frequently_const] theorem eventually_imp_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} : (∀ᶠ x in f, p x → q) ↔ (∃ᶠ x in f, p x) → q := by simp only [imp_iff_not_or, eventually_or_distrib_right, not_frequently] @[simp] theorem frequently_and_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} : (∃ᶠ x in f, p ∧ q x) ↔ p ∧ ∃ᶠ x in f, q x := by simp only [Filter.Frequently, not_and, eventually_imp_distrib_left, Classical.not_imp] @[simp] theorem frequently_and_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} : (∃ᶠ x in f, p x ∧ q) ↔ (∃ᶠ x in f, p x) ∧ q := by simp only [@and_comm _ q, frequently_and_distrib_left] @[simp] theorem frequently_bot {p : α → Prop} : ¬∃ᶠ x in ⊥, p x := by simp @[simp] theorem frequently_top {p : α → Prop} : (∃ᶠ x in ⊤, p x) ↔ ∃ x, p x := by simp [Filter.Frequently] @[simp] theorem frequently_principal {a : Set α} {p : α → Prop} : (∃ᶠ x in 𝓟 a, p x) ↔ ∃ x ∈ a, p x := by simp [Filter.Frequently, not_forall] theorem frequently_inf_principal {f : Filter α} {s : Set α} {p : α → Prop} : (∃ᶠ x in f ⊓ 𝓟 s, p x) ↔ ∃ᶠ x in f, x ∈ s ∧ p x := by simp only [Filter.Frequently, eventually_inf_principal, not_and] alias ⟨Frequently.of_inf_principal, Frequently.inf_principal⟩ := frequently_inf_principal theorem frequently_sup {p : α → Prop} {f g : Filter α} : (∃ᶠ x in f ⊔ g, p x) ↔ (∃ᶠ x in f, p x) ∨ ∃ᶠ x in g, p x := by simp only [Filter.Frequently, eventually_sup, not_and_or] @[simp] theorem frequently_sSup {p : α → Prop} {fs : Set (Filter α)} : (∃ᶠ x in sSup fs, p x) ↔ ∃ f ∈ fs, ∃ᶠ x in f, p x := by simp only [Filter.Frequently, not_forall, eventually_sSup, exists_prop] @[simp] theorem frequently_iSup {p : α → Prop} {fs : β → Filter α} : (∃ᶠ x in ⨆ b, fs b, p x) ↔ ∃ b, ∃ᶠ x in fs b, p x := by simp only [Filter.Frequently, eventually_iSup, not_forall] theorem Eventually.choice {r : α → β → Prop} {l : Filter α} [l.NeBot] (h : ∀ᶠ x in l, ∃ y, r x y) : ∃ f : α → β, ∀ᶠ x in l, r x (f x) := by haveI : Nonempty β := let ⟨_, hx⟩ := h.exists; hx.nonempty choose! f hf using fun x (hx : ∃ y, r x y) => hx exact ⟨f, h.mono hf⟩ lemma skolem {ι : Type*} {α : ι → Type*} [∀ i, Nonempty (α i)] {P : ∀ i : ι, α i → Prop} {F : Filter ι} : (∀ᶠ i in F, ∃ b, P i b) ↔ ∃ b : (Π i, α i), ∀ᶠ i in F, P i (b i) := by classical refine ⟨fun H ↦ ?_, fun ⟨b, hb⟩ ↦ hb.mp (.of_forall fun x a ↦ ⟨_, a⟩)⟩ refine ⟨fun i ↦ if h : ∃ b, P i b then h.choose else Nonempty.some inferInstance, ?_⟩ filter_upwards [H] with i hi exact dif_pos hi ▸ hi.choose_spec /-! ### Relation “eventually equal” -/ section EventuallyEq variable {l : Filter α} {f g : α → β} theorem EventuallyEq.eventually (h : f =ᶠ[l] g) : ∀ᶠ x in l, f x = g x := h @[simp] lemma eventuallyEq_top : f =ᶠ[⊤] g ↔ f = g := by simp [EventuallyEq, funext_iff] theorem EventuallyEq.rw {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) (p : α → β → Prop) (hf : ∀ᶠ x in l, p x (f x)) : ∀ᶠ x in l, p x (g x) := hf.congr <| h.mono fun _ hx => hx ▸ Iff.rfl theorem eventuallyEq_set {s t : Set α} {l : Filter α} : s =ᶠ[l] t ↔ ∀ᶠ x in l, x ∈ s ↔ x ∈ t := eventually_congr <| Eventually.of_forall fun _ ↦ eq_iff_iff alias ⟨EventuallyEq.mem_iff, Eventually.set_eq⟩ := eventuallyEq_set @[simp] theorem eventuallyEq_univ {s : Set α} {l : Filter α} : s =ᶠ[l] univ ↔ s ∈ l := by simp [eventuallyEq_set] theorem EventuallyEq.exists_mem {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) : ∃ s ∈ l, EqOn f g s := Eventually.exists_mem h theorem eventuallyEq_of_mem {l : Filter α} {f g : α → β} {s : Set α} (hs : s ∈ l) (h : EqOn f g s) : f =ᶠ[l] g := eventually_of_mem hs h theorem eventuallyEq_iff_exists_mem {l : Filter α} {f g : α → β} : f =ᶠ[l] g ↔ ∃ s ∈ l, EqOn f g s := eventually_iff_exists_mem theorem EventuallyEq.filter_mono {l l' : Filter α} {f g : α → β} (h₁ : f =ᶠ[l] g) (h₂ : l' ≤ l) : f =ᶠ[l'] g := h₂ h₁ @[refl, simp] theorem EventuallyEq.refl (l : Filter α) (f : α → β) : f =ᶠ[l] f := Eventually.of_forall fun _ => rfl protected theorem EventuallyEq.rfl {l : Filter α} {f : α → β} : f =ᶠ[l] f := EventuallyEq.refl l f theorem EventuallyEq.of_eq {l : Filter α} {f g : α → β} (h : f = g) : f =ᶠ[l] g := h ▸ .rfl alias _root_.Eq.eventuallyEq := EventuallyEq.of_eq @[symm] theorem EventuallyEq.symm {f g : α → β} {l : Filter α} (H : f =ᶠ[l] g) : g =ᶠ[l] f := H.mono fun _ => Eq.symm lemma eventuallyEq_comm {f g : α → β} {l : Filter α} : f =ᶠ[l] g ↔ g =ᶠ[l] f := ⟨.symm, .symm⟩ @[trans] theorem EventuallyEq.trans {l : Filter α} {f g h : α → β} (H₁ : f =ᶠ[l] g) (H₂ : g =ᶠ[l] h) : f =ᶠ[l] h := H₂.rw (fun x y => f x = y) H₁ theorem EventuallyEq.congr_left {l : Filter α} {f g h : α → β} (H : f =ᶠ[l] g) : f =ᶠ[l] h ↔ g =ᶠ[l] h := ⟨H.symm.trans, H.trans⟩ theorem EventuallyEq.congr_right {l : Filter α} {f g h : α → β} (H : g =ᶠ[l] h) : f =ᶠ[l] g ↔ f =ᶠ[l] h := ⟨(·.trans H), (·.trans H.symm)⟩ instance {l : Filter α} : Trans ((· =ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· =ᶠ[l] ·) (· =ᶠ[l] ·) where trans := EventuallyEq.trans theorem EventuallyEq.prodMk {l} {f f' : α → β} (hf : f =ᶠ[l] f') {g g' : α → γ} (hg : g =ᶠ[l] g') : (fun x => (f x, g x)) =ᶠ[l] fun x => (f' x, g' x) := hf.mp <| hg.mono <| by intros simp only [*] @[deprecated (since := "2025-03-10")] alias EventuallyEq.prod_mk := EventuallyEq.prodMk -- See `EventuallyEq.comp_tendsto` further below for a similar statement w.r.t. -- composition on the right. theorem EventuallyEq.fun_comp {f g : α → β} {l : Filter α} (H : f =ᶠ[l] g) (h : β → γ) : h ∘ f =ᶠ[l] h ∘ g := H.mono fun _ hx => congr_arg h hx theorem EventuallyEq.comp₂ {δ} {f f' : α → β} {g g' : α → γ} {l} (Hf : f =ᶠ[l] f') (h : β → γ → δ) (Hg : g =ᶠ[l] g') : (fun x => h (f x) (g x)) =ᶠ[l] fun x => h (f' x) (g' x) := (Hf.prodMk Hg).fun_comp (uncurry h) @[to_additive] theorem EventuallyEq.mul [Mul β] {f f' g g' : α → β} {l : Filter α} (h : f =ᶠ[l] g) (h' : f' =ᶠ[l] g') : (fun x => f x * f' x) =ᶠ[l] fun x => g x * g' x := h.comp₂ (· * ·) h' @[to_additive const_smul] theorem EventuallyEq.pow_const {γ} [Pow β γ] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) (c : γ) : (fun x => f x ^ c) =ᶠ[l] fun x => g x ^ c := h.fun_comp (· ^ c) @[to_additive] theorem EventuallyEq.inv [Inv β] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) : (fun x => (f x)⁻¹) =ᶠ[l] fun x => (g x)⁻¹ := h.fun_comp Inv.inv @[to_additive] theorem EventuallyEq.div [Div β] {f f' g g' : α → β} {l : Filter α} (h : f =ᶠ[l] g) (h' : f' =ᶠ[l] g') : (fun x => f x / f' x) =ᶠ[l] fun x => g x / g' x := h.comp₂ (· / ·) h' attribute [to_additive] EventuallyEq.const_smul @[to_additive] theorem EventuallyEq.smul {𝕜} [SMul 𝕜 β] {l : Filter α} {f f' : α → 𝕜} {g g' : α → β} (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : (fun x => f x • g x) =ᶠ[l] fun x => f' x • g' x := hf.comp₂ (· • ·) hg theorem EventuallyEq.sup [Max β] {l : Filter α} {f f' g g' : α → β} (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : (fun x => f x ⊔ g x) =ᶠ[l] fun x => f' x ⊔ g' x := hf.comp₂ (· ⊔ ·) hg theorem EventuallyEq.inf [Min β] {l : Filter α} {f f' g g' : α → β} (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : (fun x => f x ⊓ g x) =ᶠ[l] fun x => f' x ⊓ g' x := hf.comp₂ (· ⊓ ·) hg theorem EventuallyEq.preimage {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) (s : Set β) : f ⁻¹' s =ᶠ[l] g ⁻¹' s := h.fun_comp s theorem EventuallyEq.inter {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') : (s ∩ s' : Set α) =ᶠ[l] (t ∩ t' : Set α) := h.comp₂ (· ∧ ·) h' theorem EventuallyEq.union {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') : (s ∪ s' : Set α) =ᶠ[l] (t ∪ t' : Set α) := h.comp₂ (· ∨ ·) h' theorem EventuallyEq.compl {s t : Set α} {l : Filter α} (h : s =ᶠ[l] t) : (sᶜ : Set α) =ᶠ[l] (tᶜ : Set α) := h.fun_comp Not theorem EventuallyEq.diff {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') : (s \ s' : Set α) =ᶠ[l] (t \ t' : Set α) := h.inter h'.compl protected theorem EventuallyEq.symmDiff {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') : (s ∆ s' : Set α) =ᶠ[l] (t ∆ t' : Set α) := (h.diff h').union (h'.diff h) theorem eventuallyEq_empty {s : Set α} {l : Filter α} : s =ᶠ[l] (∅ : Set α) ↔ ∀ᶠ x in l, x ∉ s := eventuallyEq_set.trans <| by simp theorem inter_eventuallyEq_left {s t : Set α} {l : Filter α} : (s ∩ t : Set α) =ᶠ[l] s ↔ ∀ᶠ x in l, x ∈ s → x ∈ t := by simp only [eventuallyEq_set, mem_inter_iff, and_iff_left_iff_imp] theorem inter_eventuallyEq_right {s t : Set α} {l : Filter α} : (s ∩ t : Set α) =ᶠ[l] t ↔ ∀ᶠ x in l, x ∈ t → x ∈ s := by rw [inter_comm, inter_eventuallyEq_left] @[simp] theorem eventuallyEq_principal {s : Set α} {f g : α → β} : f =ᶠ[𝓟 s] g ↔ EqOn f g s := Iff.rfl theorem eventuallyEq_inf_principal_iff {F : Filter α} {s : Set α} {f g : α → β} : f =ᶠ[F ⊓ 𝓟 s] g ↔ ∀ᶠ x in F, x ∈ s → f x = g x := eventually_inf_principal theorem EventuallyEq.sub_eq [AddGroup β] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) : f - g =ᶠ[l] 0 := by simpa using ((EventuallyEq.refl l f).sub h).symm theorem eventuallyEq_iff_sub [AddGroup β] {f g : α → β} {l : Filter α} : f =ᶠ[l] g ↔ f - g =ᶠ[l] 0 := ⟨fun h => h.sub_eq, fun h => by simpa using h.add (EventuallyEq.refl l g)⟩ theorem eventuallyEq_iff_all_subsets {f g : α → β} {l : Filter α} : f =ᶠ[l] g ↔ ∀ s : Set α, ∀ᶠ x in l, x ∈ s → f x = g x := eventually_iff_all_subsets section LE variable [LE β] {l : Filter α} theorem EventuallyLE.congr {f f' g g' : α → β} (H : f ≤ᶠ[l] g) (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : f' ≤ᶠ[l] g' := H.mp <| hg.mp <| hf.mono fun x hf hg H => by rwa [hf, hg] at H theorem eventuallyLE_congr {f f' g g' : α → β} (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : f ≤ᶠ[l] g ↔ f' ≤ᶠ[l] g' := ⟨fun H => H.congr hf hg, fun H => H.congr hf.symm hg.symm⟩ theorem eventuallyLE_iff_all_subsets {f g : α → β} {l : Filter α} : f ≤ᶠ[l] g ↔ ∀ s : Set α, ∀ᶠ x in l, x ∈ s → f x ≤ g x := eventually_iff_all_subsets end LE section Preorder variable [Preorder β] {l : Filter α} {f g h : α → β} theorem EventuallyEq.le (h : f =ᶠ[l] g) : f ≤ᶠ[l] g := h.mono fun _ => le_of_eq @[refl] theorem EventuallyLE.refl (l : Filter α) (f : α → β) : f ≤ᶠ[l] f := EventuallyEq.rfl.le theorem EventuallyLE.rfl : f ≤ᶠ[l] f := EventuallyLE.refl l f @[trans] theorem EventuallyLE.trans (H₁ : f ≤ᶠ[l] g) (H₂ : g ≤ᶠ[l] h) : f ≤ᶠ[l] h := H₂.mp <| H₁.mono fun _ => le_trans instance : Trans ((· ≤ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· ≤ᶠ[l] ·) (· ≤ᶠ[l] ·) where trans := EventuallyLE.trans @[trans] theorem EventuallyEq.trans_le (H₁ : f =ᶠ[l] g) (H₂ : g ≤ᶠ[l] h) : f ≤ᶠ[l] h := H₁.le.trans H₂ instance : Trans ((· =ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· ≤ᶠ[l] ·) (· ≤ᶠ[l] ·) where trans := EventuallyEq.trans_le @[trans] theorem EventuallyLE.trans_eq (H₁ : f ≤ᶠ[l] g) (H₂ : g =ᶠ[l] h) : f ≤ᶠ[l] h := H₁.trans H₂.le instance : Trans ((· ≤ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· =ᶠ[l] ·) (· ≤ᶠ[l] ·) where trans := EventuallyLE.trans_eq end Preorder variable {l : Filter α} theorem EventuallyLE.antisymm [PartialOrder β] {l : Filter α} {f g : α → β} (h₁ : f ≤ᶠ[l] g) (h₂ : g ≤ᶠ[l] f) : f =ᶠ[l] g := h₂.mp <| h₁.mono fun _ => le_antisymm theorem eventuallyLE_antisymm_iff [PartialOrder β] {l : Filter α} {f g : α → β} : f =ᶠ[l] g ↔ f ≤ᶠ[l] g ∧ g ≤ᶠ[l] f := by simp only [EventuallyEq, EventuallyLE, le_antisymm_iff, eventually_and] theorem EventuallyLE.le_iff_eq [PartialOrder β] {l : Filter α} {f g : α → β} (h : f ≤ᶠ[l] g) : g ≤ᶠ[l] f ↔ g =ᶠ[l] f := ⟨fun h' => h'.antisymm h, EventuallyEq.le⟩ theorem Eventually.ne_of_lt [Preorder β] {l : Filter α} {f g : α → β} (h : ∀ᶠ x in l, f x < g x) : ∀ᶠ x in l, f x ≠ g x := h.mono fun _ hx => hx.ne theorem Eventually.ne_top_of_lt [Preorder β] [OrderTop β] {l : Filter α} {f g : α → β} (h : ∀ᶠ x in l, f x < g x) : ∀ᶠ x in l, f x ≠ ⊤ := h.mono fun _ hx => hx.ne_top theorem Eventually.lt_top_of_ne [PartialOrder β] [OrderTop β] {l : Filter α} {f : α → β} (h : ∀ᶠ x in l, f x ≠ ⊤) : ∀ᶠ x in l, f x < ⊤ := h.mono fun _ hx => hx.lt_top theorem Eventually.lt_top_iff_ne_top [PartialOrder β] [OrderTop β] {l : Filter α} {f : α → β} : (∀ᶠ x in l, f x < ⊤) ↔ ∀ᶠ x in l, f x ≠ ⊤ := ⟨Eventually.ne_of_lt, Eventually.lt_top_of_ne⟩ @[mono] theorem EventuallyLE.inter {s t s' t' : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) (h' : s' ≤ᶠ[l] t') : (s ∩ s' : Set α) ≤ᶠ[l] (t ∩ t' : Set α) := h'.mp <| h.mono fun _ => And.imp @[mono] theorem EventuallyLE.union {s t s' t' : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) (h' : s' ≤ᶠ[l] t') : (s ∪ s' : Set α) ≤ᶠ[l] (t ∪ t' : Set α) := h'.mp <| h.mono fun _ => Or.imp @[mono] theorem EventuallyLE.compl {s t : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) : (tᶜ : Set α) ≤ᶠ[l] (sᶜ : Set α) := h.mono fun _ => mt @[mono] theorem EventuallyLE.diff {s t s' t' : Set α} {l : Filter α} (h : s ≤ᶠ[l] t) (h' : t' ≤ᶠ[l] s') : (s \ s' : Set α) ≤ᶠ[l] (t \ t' : Set α) := h.inter h'.compl theorem set_eventuallyLE_iff_mem_inf_principal {s t : Set α} {l : Filter α} : s ≤ᶠ[l] t ↔ t ∈ l ⊓ 𝓟 s := eventually_inf_principal.symm theorem set_eventuallyLE_iff_inf_principal_le {s t : Set α} {l : Filter α} : s ≤ᶠ[l] t ↔ l ⊓ 𝓟 s ≤ l ⊓ 𝓟 t := set_eventuallyLE_iff_mem_inf_principal.trans <| by simp only [le_inf_iff, inf_le_left, true_and, le_principal_iff] theorem set_eventuallyEq_iff_inf_principal {s t : Set α} {l : Filter α} : s =ᶠ[l] t ↔ l ⊓ 𝓟 s = l ⊓ 𝓟 t := by simp only [eventuallyLE_antisymm_iff, le_antisymm_iff, set_eventuallyLE_iff_inf_principal_le] theorem EventuallyLE.sup [SemilatticeSup β] {l : Filter α} {f₁ f₂ g₁ g₂ : α → β} (hf : f₁ ≤ᶠ[l] f₂) (hg : g₁ ≤ᶠ[l] g₂) : f₁ ⊔ g₁ ≤ᶠ[l] f₂ ⊔ g₂ := by filter_upwards [hf, hg] with x hfx hgx using sup_le_sup hfx hgx theorem EventuallyLE.sup_le [SemilatticeSup β] {l : Filter α} {f g h : α → β} (hf : f ≤ᶠ[l] h) (hg : g ≤ᶠ[l] h) : f ⊔ g ≤ᶠ[l] h := by filter_upwards [hf, hg] with x hfx hgx using _root_.sup_le hfx hgx theorem EventuallyLE.le_sup_of_le_left [SemilatticeSup β] {l : Filter α} {f g h : α → β} (hf : h ≤ᶠ[l] f) : h ≤ᶠ[l] f ⊔ g := hf.mono fun _ => _root_.le_sup_of_le_left theorem EventuallyLE.le_sup_of_le_right [SemilatticeSup β] {l : Filter α} {f g h : α → β} (hg : h ≤ᶠ[l] g) : h ≤ᶠ[l] f ⊔ g := hg.mono fun _ => _root_.le_sup_of_le_right theorem join_le {f : Filter (Filter α)} {l : Filter α} (h : ∀ᶠ m in f, m ≤ l) : join f ≤ l := fun _ hs => h.mono fun _ hm => hm hs end EventuallyEq end Filter open Filter theorem Set.EqOn.eventuallyEq {α β} {s : Set α} {f g : α → β} (h : EqOn f g s) : f =ᶠ[𝓟 s] g := h theorem Set.EqOn.eventuallyEq_of_mem {α β} {s : Set α} {l : Filter α} {f g : α → β} (h : EqOn f g s) (hl : s ∈ l) : f =ᶠ[l] g := h.eventuallyEq.filter_mono <| Filter.le_principal_iff.2 hl theorem HasSubset.Subset.eventuallyLE {α} {l : Filter α} {s t : Set α} (h : s ⊆ t) : s ≤ᶠ[l] t := Filter.Eventually.of_forall h variable {α β : Type*} {F : Filter α} {G : Filter β} namespace Filter lemma compl_mem_comk {p : Set α → Prop} {he hmono hunion s} : sᶜ ∈ comk p he hmono hunion ↔ p s := by simp end Filter
Mathlib/Order/Filter/Basic.lean
3,036
3,036
/- Copyright (c) 2022 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Data.DFinsupp.Interval import Mathlib.Data.DFinsupp.Multiset import Mathlib.Order.Interval.Finset.Nat import Mathlib.Data.Nat.Lattice /-! # Finite intervals of multisets This file provides the `LocallyFiniteOrder` instance for `Multiset α` and calculates the cardinality of its finite intervals. ## Implementation notes We implement the intervals via the intervals on `DFinsupp`, rather than via filtering `Multiset.Powerset`; this is because `(Multiset.replicate n x).Powerset` has `2^n` entries not `n+1` entries as it contains duplicates. We do not go via `Finsupp` as this would be noncomputable, and multisets are typically used computationally. -/ open Finset DFinsupp Function open Pointwise variable {α : Type*} namespace Multiset variable [DecidableEq α] (s t : Multiset α) instance instLocallyFiniteOrder : LocallyFiniteOrder (Multiset α) := LocallyFiniteOrder.ofIcc (Multiset α) (fun s t => (Finset.Icc (toDFinsupp s) (toDFinsupp t)).map Multiset.equivDFinsupp.toEquiv.symm.toEmbedding) fun s t x => by simp theorem Icc_eq : Finset.Icc s t = (Finset.Icc (toDFinsupp s) (toDFinsupp t)).map Multiset.equivDFinsupp.toEquiv.symm.toEmbedding := rfl theorem uIcc_eq : uIcc s t = (uIcc (toDFinsupp s) (toDFinsupp t)).map Multiset.equivDFinsupp.toEquiv.symm.toEmbedding := (Icc_eq _ _).trans <| by simp [uIcc] theorem card_Icc : #(Finset.Icc s t) = ∏ i ∈ s.toFinset ∪ t.toFinset, (t.count i + 1 - s.count i) := by simp_rw [Icc_eq, Finset.card_map, DFinsupp.card_Icc, Nat.card_Icc, Multiset.toDFinsupp_apply, toDFinsupp_support] theorem card_Ico : #(Finset.Ico s t) = ∏ i ∈ s.toFinset ∪ t.toFinset, (t.count i + 1 - s.count i) - 1 := by rw [Finset.card_Ico_eq_card_Icc_sub_one, card_Icc]
theorem card_Ioc : #(Finset.Ioc s t) = ∏ i ∈ s.toFinset ∪ t.toFinset, (t.count i + 1 - s.count i) - 1 := by rw [Finset.card_Ioc_eq_card_Icc_sub_one, card_Icc]
Mathlib/Data/Multiset/Interval.lean
62
64
/- 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 _ _ ?_) exact tendsto_natCast_atTop_atTop.const_mul_atTop (mul_pos pi_pos hT) /-- The series defining the theta function is summable if and only if `0 < im τ`. -/ lemma summable_jacobiTheta₂_term_iff (z τ : ℂ) : Summable (jacobiTheta₂_term · z τ) ↔ 0 < im τ := by -- NB. This is a statement of no great mathematical interest; it is included largely to avoid -- having to impose `0 < im τ` as a hypothesis on many later lemmas. refine Iff.symm ⟨fun hτ ↦ ?_, fun h ↦ ?_⟩ -- do quicker implication first! · refine (summable_pow_mul_jacobiTheta₂_term_bound |im z| hτ 0).of_norm_bounded _ ?_ simpa only [pow_zero, one_mul] using norm_jacobiTheta₂_term_le hτ le_rfl le_rfl · by_contra! hτ rcases lt_or_eq_of_le hτ with hτ | hτ · -- easy case `im τ < 0` suffices Tendsto (fun n : ℕ ↦ ‖jacobiTheta₂_term ↑n z τ‖) atTop atTop by replace h := (h.comp_injective (fun a b ↦ Int.ofNat_inj.mp)).tendsto_atTop_zero.norm exact atTop_neBot.ne (disjoint_self.mp <| h.disjoint (disjoint_nhds_atTop _) this) simp only [norm_zero, Function.comp_def, norm_jacobiTheta₂_term, Int.cast_natCast] conv => enter [1, n] rw [show -π * n ^ 2 * τ.im - 2 * π * n * z.im = n * (n * (-π * τ.im) - 2 * π * z.im) by ring] refine tendsto_exp_atTop.comp (tendsto_natCast_atTop_atTop.atTop_mul_atTop₀ ?_) exact tendsto_atTop_add_const_right _ _ (tendsto_natCast_atTop_atTop.atTop_mul_const (mul_pos_of_neg_of_neg (neg_lt_zero.mpr pi_pos) hτ)) · -- case im τ = 0: 3-way split according to `im z` simp_rw [← summable_norm_iff (E := ℂ), norm_jacobiTheta₂_term, hτ, mul_zero, zero_sub] at h rcases lt_trichotomy (im z) 0 with hz | hz | hz · replace h := (h.comp_injective (fun a b ↦ Int.ofNat_inj.mp)).tendsto_atTop_zero simp_rw [Function.comp_def, Int.cast_natCast] at h refine atTop_neBot.ne (disjoint_self.mp <| h.disjoint (disjoint_nhds_atTop 0) ?_) refine tendsto_exp_atTop.comp ?_ simp only [tendsto_neg_atTop_iff, mul_assoc] apply Filter.Tendsto.const_mul_atBot two_pos exact (tendsto_natCast_atTop_atTop.atTop_mul_const_of_neg hz).const_mul_atBot pi_pos · revert h simpa only [hz, mul_zero, neg_zero, Real.exp_zero, summable_const_iff] using one_ne_zero · have : ((-↑·) : ℕ → ℤ).Injective := fun _ _ ↦ by simp only [neg_inj, Nat.cast_inj, imp_self] replace h := (h.comp_injective this).tendsto_atTop_zero simp_rw [Function.comp_def, Int.cast_neg, Int.cast_natCast, mul_neg, neg_mul, neg_neg] at h refine atTop_neBot.ne (disjoint_self.mp <| h.disjoint (disjoint_nhds_atTop 0) ?_) exact tendsto_exp_atTop.comp ((tendsto_natCast_atTop_atTop.const_mul_atTop (mul_pos two_pos pi_pos)).atTop_mul_const hz) lemma norm_jacobiTheta₂_term_fderiv_le (n : ℤ) (z τ : ℂ) : ‖jacobiTheta₂_term_fderiv n z τ‖ ≤ 3 * π * |n| ^ 2 * ‖jacobiTheta₂_term n z τ‖ := by -- this is slow to elaborate so do it once and reuse: have hns (a : ℂ) (f : (ℂ × ℂ) →L[ℂ] ℂ) : ‖a • f‖ = ‖a‖ * ‖f‖ := norm_smul a f rw [jacobiTheta₂_term_fderiv, jacobiTheta₂_term, hns, mul_comm _ ‖cexp _‖, (by norm_num : (3 : ℝ) = 2 + 1), add_mul, add_mul] refine mul_le_mul_of_nonneg_left ((norm_add_le _ _).trans (add_le_add ?_ ?_)) (norm_nonneg _) · simp_rw [hns, norm_mul, ← ofReal_ofNat, ← ofReal_intCast, norm_real, norm_of_nonneg zero_le_two, Real.norm_of_nonneg pi_pos.le, norm_I, mul_one, Real.norm_eq_abs, Int.cast_abs, mul_assoc] refine mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left ?_ pi_pos.le) two_pos.le refine le_trans ?_ (?_ : |(n : ℝ)| ≤ |(n : ℝ)| ^ 2) · exact mul_le_of_le_one_right (abs_nonneg _) (ContinuousLinearMap.norm_fst_le ..) · exact_mod_cast Int.le_self_sq |n| · simp_rw [hns, norm_mul, one_mul, norm_I, mul_one, norm_real, norm_of_nonneg pi_pos.le, ← ofReal_intCast, ← ofReal_pow, norm_real, Real.norm_eq_abs, Int.cast_abs, abs_pow] apply mul_le_of_le_one_right (mul_nonneg pi_pos.le (pow_nonneg (abs_nonneg _) _)) exact ContinuousLinearMap.norm_snd_le .. lemma norm_jacobiTheta₂_term_fderiv_ge (n : ℤ) (z τ : ℂ) : π * |n| ^ 2 * ‖jacobiTheta₂_term n z τ‖ ≤ ‖jacobiTheta₂_term_fderiv n z τ‖ := by have : ‖(jacobiTheta₂_term_fderiv n z τ) (0, 1)‖ ≤ ‖jacobiTheta₂_term_fderiv n z τ‖ := by refine (ContinuousLinearMap.le_opNorm _ _).trans ?_ simp_rw [Prod.norm_def, norm_one, norm_zero, max_eq_right zero_le_one, mul_one, le_refl] refine le_trans ?_ this simp_rw [jacobiTheta₂_term_fderiv, jacobiTheta₂_term, ContinuousLinearMap.coe_smul', Pi.smul_apply, ContinuousLinearMap.add_apply, ContinuousLinearMap.coe_smul', ContinuousLinearMap.coe_fst', ContinuousLinearMap.coe_snd', Pi.smul_apply, smul_zero, zero_add, smul_eq_mul, mul_one, mul_comm _ ‖cexp _‖, norm_mul] refine mul_le_mul_of_nonneg_left (le_of_eq ?_) (norm_nonneg _) simp_rw [norm_real, norm_of_nonneg pi_pos.le, norm_I, mul_one, Int.cast_abs, ← norm_intCast, norm_pow] lemma summable_jacobiTheta₂_term_fderiv_iff (z τ : ℂ) : Summable (jacobiTheta₂_term_fderiv · z τ) ↔ 0 < im τ := by constructor · rw [← summable_jacobiTheta₂_term_iff (z := z)] intro h have := h.norm refine this.of_norm_bounded_eventually _ ?_ have : ∀ᶠ (n : ℤ) in cofinite, n ≠ 0 := Int.cofinite_eq ▸ (mem_sup.mpr ⟨eventually_ne_atBot 0, eventually_ne_atTop 0⟩) filter_upwards [this] with n hn refine le_trans ?_ (norm_jacobiTheta₂_term_fderiv_ge n z τ) apply le_mul_of_one_le_left (norm_nonneg _) refine one_le_pi_div_two.trans (mul_le_mul_of_nonneg_left ?_ pi_pos.le) refine (by norm_num : 2⁻¹ ≤ (1 : ℝ)).trans ?_ rw [one_le_sq_iff_one_le_abs, ← Int.cast_abs, abs_abs, ← Int.cast_one, Int.cast_le] exact Int.one_le_abs hn · intro hτ refine ((summable_pow_mul_jacobiTheta₂_term_bound |z.im| hτ 2).mul_left (3 * π)).of_norm_bounded _ (fun n ↦ ?_) refine (norm_jacobiTheta₂_term_fderiv_le n z τ).trans (?_ : 3 * π * |n| ^ 2 * ‖jacobiTheta₂_term n z τ‖ ≤ _) simp_rw [mul_assoc (3 * π)] refine mul_le_mul_of_nonneg_left ?_ (mul_pos (by norm_num : 0 < (3 : ℝ)) pi_pos).le refine mul_le_mul_of_nonneg_left ?_ (pow_nonneg (Int.cast_nonneg.mpr (abs_nonneg _)) _) exact norm_jacobiTheta₂_term_le hτ le_rfl le_rfl n lemma summable_jacobiTheta₂'_term_iff (z τ : ℂ) : Summable (jacobiTheta₂'_term · z τ) ↔ 0 < im τ := by constructor · rw [← summable_jacobiTheta₂_term_iff (z := z)] refine fun h ↦ (h.norm.mul_left (2 * π)⁻¹).of_norm_bounded_eventually _ ?_ have : ∀ᶠ (n : ℤ) in cofinite, n ≠ 0 := Int.cofinite_eq ▸ (mem_sup.mpr ⟨eventually_ne_atBot 0, eventually_ne_atTop 0⟩) filter_upwards [this] with n hn rw [jacobiTheta₂'_term, norm_mul, ← mul_assoc] refine le_mul_of_one_le_left (norm_nonneg _) ?_ simp_rw [norm_mul, norm_I, norm_real, mul_one, norm_of_nonneg pi_pos.le, ← ofReal_ofNat, norm_real, norm_of_nonneg two_pos.le, ← ofReal_intCast, norm_real, Real.norm_eq_abs, ← Int.cast_abs, ← mul_assoc _ (2 * π), inv_mul_cancel₀ (mul_pos two_pos pi_pos).ne', one_mul] rw [← Int.cast_one, Int.cast_le] exact Int.one_le_abs hn · refine fun hτ ↦ ((summable_pow_mul_jacobiTheta₂_term_bound |z.im| hτ 1).mul_left (2 * π)).of_norm_bounded _ (fun n ↦ ?_) rw [jacobiTheta₂'_term, norm_mul, ← mul_assoc, pow_one] refine mul_le_mul (le_of_eq ?_) (norm_jacobiTheta₂_term_le hτ le_rfl le_rfl n) (norm_nonneg _) (by positivity) simp_rw [norm_mul, Complex.norm_two, norm_I, Complex.norm_of_nonneg pi_pos.le, norm_intCast, mul_one, Int.cast_abs] end term_bounds /-! ## Definitions of the functions -/ /-- The two-variable Jacobi theta function, `θ z τ = ∑' (n : ℤ), cexp (2 * π * I * n * z + π * I * n ^ 2 * τ)`. -/ def jacobiTheta₂ (z τ : ℂ) : ℂ := ∑' n : ℤ, jacobiTheta₂_term n z τ /-- Fréchet derivative of the two-variable Jacobi theta function. -/ def jacobiTheta₂_fderiv (z τ : ℂ) : ℂ × ℂ →L[ℂ] ℂ := ∑' n : ℤ, jacobiTheta₂_term_fderiv n z τ /-- The `z`-derivative of the Jacobi theta function, `θ' z τ = ∑' (n : ℤ), 2 * π * I * n * cexp (2 * π * I * n * z + π * I * n ^ 2 * τ)`. -/ def jacobiTheta₂' (z τ : ℂ) := ∑' n : ℤ, jacobiTheta₂'_term n z τ lemma hasSum_jacobiTheta₂_term (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) : HasSum (fun n ↦ jacobiTheta₂_term n z τ) (jacobiTheta₂ z τ) := ((summable_jacobiTheta₂_term_iff z τ).mpr hτ).hasSum lemma hasSum_jacobiTheta₂_term_fderiv (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) : HasSum (fun n ↦ jacobiTheta₂_term_fderiv n z τ) (jacobiTheta₂_fderiv z τ) := ((summable_jacobiTheta₂_term_fderiv_iff z τ).mpr hτ).hasSum lemma hasSum_jacobiTheta₂'_term (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) : HasSum (fun n ↦ jacobiTheta₂'_term n z τ) (jacobiTheta₂' z τ) := ((summable_jacobiTheta₂'_term_iff z τ).mpr hτ).hasSum lemma jacobiTheta₂_undef (z : ℂ) {τ : ℂ} (hτ : im τ ≤ 0) : jacobiTheta₂ z τ = 0 := by apply tsum_eq_zero_of_not_summable rw [summable_jacobiTheta₂_term_iff] exact not_lt.mpr hτ lemma jacobiTheta₂_fderiv_undef (z : ℂ) {τ : ℂ} (hτ : im τ ≤ 0) : jacobiTheta₂_fderiv z τ = 0 := by apply tsum_eq_zero_of_not_summable rw [summable_jacobiTheta₂_term_fderiv_iff] exact not_lt.mpr hτ lemma jacobiTheta₂'_undef (z : ℂ) {τ : ℂ} (hτ : im τ ≤ 0) : jacobiTheta₂' z τ = 0 := by apply tsum_eq_zero_of_not_summable rw [summable_jacobiTheta₂'_term_iff] exact not_lt.mpr hτ /-! ## Derivatives and continuity -/ lemma hasFDerivAt_jacobiTheta₂ (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) : HasFDerivAt (fun p : ℂ × ℂ ↦ jacobiTheta₂ p.1 p.2) (jacobiTheta₂_fderiv z τ) (z, τ) := by obtain ⟨T, hT, hτ'⟩ := exists_between hτ obtain ⟨S, hz⟩ := exists_gt |im z| let V := {u | |im u| < S} ×ˢ {v | T < im v} have hVo : IsOpen V := by refine ((_root_.continuous_abs.comp continuous_im).isOpen_preimage _ isOpen_Iio).prod ?_ exact continuous_im.isOpen_preimage _ isOpen_Ioi have hVmem : (z, τ) ∈ V := ⟨hz, hτ'⟩ have hVp : IsPreconnected V := by refine (Convex.isPreconnected ?_).prod (convex_halfSpace_im_gt T).isPreconnected simpa only [abs_lt] using (convex_halfSpace_im_gt _).inter (convex_halfSpace_im_lt _) let f : ℤ → ℂ × ℂ → ℂ := fun n p ↦ jacobiTheta₂_term n p.1 p.2 let f' : ℤ → ℂ × ℂ → ℂ × ℂ →L[ℂ] ℂ := fun n p ↦ jacobiTheta₂_term_fderiv n p.1 p.2 have hf (n : ℤ) : ∀ p ∈ V, HasFDerivAt (f n) (f' n p) p := fun p _ ↦ hasFDerivAt_jacobiTheta₂_term n p.1 p.2 let u : ℤ → ℝ := fun n ↦ 3 * π * |n| ^ 2 * Real.exp (-π * (T * n ^ 2 - 2 * S * |n|)) have hu : ∀ (n : ℤ), ∀ x ∈ V, ‖f' n x‖ ≤ u n := by refine fun n p hp ↦ (norm_jacobiTheta₂_term_fderiv_le n p.1 p.2).trans ?_ refine mul_le_mul_of_nonneg_left ?_ (by positivity) exact norm_jacobiTheta₂_term_le hT (le_of_lt hp.1) (le_of_lt hp.2) n have hu_sum : Summable u := by simp_rw [u, mul_assoc (3 * π)] exact (summable_pow_mul_jacobiTheta₂_term_bound S hT 2).mul_left _ have hf_sum : Summable fun n : ℤ ↦ f n (z, τ) := by refine (summable_pow_mul_jacobiTheta₂_term_bound S hT 0).of_norm_bounded _ ?_ simpa only [pow_zero, one_mul] using norm_jacobiTheta₂_term_le hT hz.le hτ'.le simpa only [jacobiTheta₂, jacobiTheta₂_fderiv, f, f'] using hasFDerivAt_tsum_of_isPreconnected hu_sum hVo hVp hf hu hVmem hf_sum hVmem lemma continuousAt_jacobiTheta₂ (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) : ContinuousAt (fun p : ℂ × ℂ ↦ jacobiTheta₂ p.1 p.2) (z, τ) := (hasFDerivAt_jacobiTheta₂ z hτ).continuousAt /-- Differentiability of `Θ z τ` in `z`, for fixed `τ`. -/ lemma differentiableAt_jacobiTheta₂_fst (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) : DifferentiableAt ℂ (jacobiTheta₂ · τ) z := ((hasFDerivAt_jacobiTheta₂ z hτ).comp (𝕜 := ℂ) z (hasFDerivAt_prodMk_left z τ) :).differentiableAt /-- Differentiability of `Θ z τ` in `τ`, for fixed `z`. -/ lemma differentiableAt_jacobiTheta₂_snd (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) : DifferentiableAt ℂ (jacobiTheta₂ z) τ := ((hasFDerivAt_jacobiTheta₂ z hτ).comp τ (hasFDerivAt_prodMk_right z τ)).differentiableAt lemma hasDerivAt_jacobiTheta₂_fst (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) : HasDerivAt (jacobiTheta₂ · τ) (jacobiTheta₂' z τ) z := by -- This proof is annoyingly fiddly, because of the need to commute "evaluation at a point" -- through infinite sums of continuous linear maps. let eval_fst_CLM : (ℂ × ℂ →L[ℂ] ℂ) →L[ℂ] ℂ := { toFun := fun f ↦ f (1, 0) cont := continuous_id'.clm_apply continuous_const map_add' := by simp only [ContinuousLinearMap.add_apply, forall_const] map_smul' := by simp only [ContinuousLinearMap.coe_smul', Pi.smul_apply, smul_eq_mul, RingHom.id_apply, forall_const] } have step1 : HasSum (fun n ↦ (jacobiTheta₂_term_fderiv n z τ) (1, 0)) ((jacobiTheta₂_fderiv z τ) (1, 0)) := by apply eval_fst_CLM.hasSum (hasSum_jacobiTheta₂_term_fderiv z hτ) have step2 (n : ℤ) : (jacobiTheta₂_term_fderiv n z τ) (1, 0) = jacobiTheta₂'_term n z τ := by simp only [jacobiTheta₂_term_fderiv, smul_add, ContinuousLinearMap.add_apply, ContinuousLinearMap.coe_smul', ContinuousLinearMap.coe_fst', Pi.smul_apply, smul_eq_mul, mul_one, ContinuousLinearMap.coe_snd', mul_zero, add_zero, jacobiTheta₂'_term, jacobiTheta₂_term, mul_comm _ (cexp _)] rw [funext step2] at step1 #adaptation_note /-- https://github.com/leanprover/lean4/pull/6024 need `by exact` to bypass unification failure -/ have step3 : HasDerivAt (fun x ↦ jacobiTheta₂ x τ) ((jacobiTheta₂_fderiv z τ) (1, 0)) z := by exact ((hasFDerivAt_jacobiTheta₂ z hτ).comp z (hasFDerivAt_prodMk_left z τ)).hasDerivAt rwa [← step1.tsum_eq] at step3 lemma continuousAt_jacobiTheta₂' (z : ℂ) {τ : ℂ} (hτ : 0 < im τ) : ContinuousAt (fun p : ℂ × ℂ ↦ jacobiTheta₂' p.1 p.2) (z, τ) := by obtain ⟨T, hT, hτ'⟩ := exists_between hτ obtain ⟨S, hz⟩ := exists_gt |im z| let V := {u | |im u| < S} ×ˢ {v | T < im v} have hVo : IsOpen V := ((_root_.continuous_abs.comp continuous_im).isOpen_preimage _ isOpen_Iio).prod (continuous_im.isOpen_preimage _ isOpen_Ioi) refine ContinuousOn.continuousAt ?_ (hVo.mem_nhds ⟨hz, hτ'⟩) let u (n : ℤ) : ℝ := 2 * π * |n| * rexp (-π * (T * n ^ 2 - 2 * S * |n|)) have hu : Summable u := by simpa only [u, mul_assoc, pow_one] using (summable_pow_mul_jacobiTheta₂_term_bound S hT 1).mul_left (2 * π) refine continuousOn_tsum (fun n ↦ ?_) hu (fun n ⟨z', τ'⟩ ⟨hz', hτ'⟩ ↦ ?_) · apply Continuous.continuousOn unfold jacobiTheta₂'_term jacobiTheta₂_term fun_prop · exact norm_jacobiTheta₂'_term_le hT (le_of_lt hz') (le_of_lt hτ') n /-! ## Periodicity and conjugation -/ /-- The two-variable Jacobi theta function is periodic in `τ` with period 2. -/ lemma jacobiTheta₂_add_right (z τ : ℂ) : jacobiTheta₂ z (τ + 2) = jacobiTheta₂ z τ := by refine tsum_congr (fun n ↦ ?_) simp_rw [jacobiTheta₂_term, Complex.exp_add] suffices cexp (π * I * n ^ 2 * 2 : ℂ) = 1 by rw [mul_add, Complex.exp_add, this, mul_one] rw [(by push_cast; ring : (π * I * n ^ 2 * 2 : ℂ) = (n ^ 2 :) * (2 * π * I)), exp_int_mul, exp_two_pi_mul_I, one_zpow] /-- The two-variable Jacobi theta function is periodic in `z` with period 1. -/ lemma jacobiTheta₂_add_left (z τ : ℂ) : jacobiTheta₂ (z + 1) τ = jacobiTheta₂ z τ := by refine tsum_congr (fun n ↦ ?_) simp_rw [jacobiTheta₂_term, mul_add, Complex.exp_add, mul_one, mul_comm _ (n : ℂ), exp_int_mul_two_pi_mul_I, mul_one] /-- The two-variable Jacobi theta function is quasi-periodic in `z` with period `τ`. -/ lemma jacobiTheta₂_add_left' (z τ : ℂ) : jacobiTheta₂ (z + τ) τ = cexp (-π * I * (τ + 2 * z)) * jacobiTheta₂ z τ := by conv_rhs => rw [jacobiTheta₂, ← tsum_mul_left, ← (Equiv.addRight 1).tsum_eq] refine tsum_congr (fun n ↦ ?_) simp_rw [jacobiTheta₂_term, ← Complex.exp_add, Equiv.coe_addRight, Int.cast_add] ring_nf /-- The two-variable Jacobi theta function is even in `z`. -/ @[simp] lemma jacobiTheta₂_neg_left (z τ : ℂ) : jacobiTheta₂ (-z) τ = jacobiTheta₂ z τ := by conv_lhs => rw [jacobiTheta₂, ← Equiv.tsum_eq (Equiv.neg ℤ)] refine tsum_congr (fun n ↦ ?_) simp_rw [jacobiTheta₂_term, Equiv.neg_apply, Int.cast_neg, neg_sq, mul_assoc, neg_mul_neg] lemma jacobiTheta₂_conj (z τ : ℂ) : conj (jacobiTheta₂ z τ) = jacobiTheta₂ (conj z) (-conj τ) := by rw [← jacobiTheta₂_neg_left, jacobiTheta₂, conj_tsum] congr 2 with n simp only [jacobiTheta₂_term, mul_neg, ← exp_conj, map_add, map_neg, map_mul, map_ofNat, conj_ofReal, conj_I, map_intCast, neg_mul, neg_neg, map_pow] lemma jacobiTheta₂'_add_right (z τ : ℂ) : jacobiTheta₂' z (τ + 2) = jacobiTheta₂' z τ := by refine tsum_congr (fun n ↦ ?_) simp_rw [jacobiTheta₂'_term, jacobiTheta₂_term, Complex.exp_add] suffices cexp (π * I * n ^ 2 * 2 : ℂ) = 1 by rw [mul_add, Complex.exp_add, this, mul_one] rw [(by push_cast; ring : (π * I * n ^ 2 * 2 : ℂ) = (n ^ 2 :) * (2 * π * I)), exp_int_mul, exp_two_pi_mul_I, one_zpow] lemma jacobiTheta₂'_add_left (z τ : ℂ) : jacobiTheta₂' (z + 1) τ = jacobiTheta₂' z τ := by unfold jacobiTheta₂' jacobiTheta₂'_term jacobiTheta₂_term refine tsum_congr (fun n ↦ ?_) simp only [mul_add, Complex.exp_add, mul_one, mul_comm _ (n : ℂ), exp_int_mul_two_pi_mul_I, mul_one] lemma jacobiTheta₂'_add_left' (z τ : ℂ) : jacobiTheta₂' (z + τ) τ = cexp (-π * I * (τ + 2 * z)) * (jacobiTheta₂' z τ - 2 * π * I * jacobiTheta₂ z τ) := by rcases le_or_lt τ.im 0 with hτ | hτ · simp_rw [jacobiTheta₂_undef _ hτ, jacobiTheta₂'_undef _ hτ, mul_zero, sub_zero, mul_zero] have (n : ℤ) : jacobiTheta₂'_term n (z + τ) τ = cexp (-π * I * (τ + 2 * z)) * (jacobiTheta₂'_term (n + 1) z τ - 2 * π * I * jacobiTheta₂_term (n + 1) z τ) := by simp only [jacobiTheta₂'_term, jacobiTheta₂_term] conv_rhs => rw [← sub_mul, mul_comm, mul_assoc, ← Complex.exp_add, Int.cast_add, Int.cast_one, mul_add, mul_one, add_sub_cancel_right] congr 2 ring rw [jacobiTheta₂', funext this, tsum_mul_left, ← (Equiv.subRight (1 : ℤ)).tsum_eq] simp only [jacobiTheta₂, jacobiTheta₂', Equiv.subRight_apply, sub_add_cancel, (hasSum_jacobiTheta₂'_term z hτ).summable.tsum_sub ((hasSum_jacobiTheta₂_term z hτ).summable.mul_left _), tsum_mul_left] lemma jacobiTheta₂'_neg_left (z τ : ℂ) : jacobiTheta₂' (-z) τ = -jacobiTheta₂' z τ := by rw [jacobiTheta₂', jacobiTheta₂', ← tsum_neg, ← (Equiv.neg ℤ).tsum_eq] congr 1 with n simp only [jacobiTheta₂'_term, jacobiTheta₂_term] rw [Equiv.neg_apply, ← neg_mul] push_cast ring_nf lemma jacobiTheta₂'_conj (z τ : ℂ) : conj (jacobiTheta₂' z τ) = jacobiTheta₂' (conj z) (-conj τ) := by rw [← neg_inj, ← jacobiTheta₂'_neg_left, jacobiTheta₂', jacobiTheta₂', conj_tsum, ← tsum_neg] congr 1 with n simp_rw [jacobiTheta₂'_term, jacobiTheta₂_term, map_mul, ← Complex.exp_conj, map_add, map_mul, ← ofReal_intCast,← ofReal_ofNat, map_pow, conj_ofReal, conj_I] ring_nf /-! ## Functional equations -/ /-- The functional equation for the Jacobi theta function: `jacobiTheta₂ z τ` is an explicit factor times `jacobiTheta₂ (z / τ) (-1 / τ)`. This is the key lemma behind the proof of the functional equation for L-series of even Dirichlet characters. -/ theorem jacobiTheta₂_functional_equation (z τ : ℂ) : jacobiTheta₂ z τ = 1 / (-I * τ) ^ (1 / 2 : ℂ) * cexp (-π * I * z ^ 2 / τ) * jacobiTheta₂ (z / τ) (-1 / τ) := by rcases le_or_lt (im τ) 0 with hτ | hτ · have : (-1 / τ).im ≤ 0 := by rw [neg_div, neg_im, one_div, inv_im, neg_nonpos] exact div_nonneg (neg_nonneg.mpr hτ) (normSq_nonneg τ) rw [jacobiTheta₂_undef z hτ, jacobiTheta₂_undef _ this, mul_zero] unfold jacobiTheta₂ jacobiTheta₂_term have h0 : τ ≠ 0 := by contrapose! hτ; rw [hτ, zero_im] have h2 : 0 < (-I * τ).re := by simpa only [neg_mul, neg_re, mul_re, I_re, zero_mul, I_im, one_mul, zero_sub, neg_neg] using hτ calc _ = ∑' n : ℤ, cexp (-π * (-I * τ) * ↑n ^ 2 + 2 * π * (I * z) * ↑n) := tsum_congr (fun n ↦ by ring_nf) _ = 1 / (-I * τ) ^ (1 / 2 : ℂ) * ∑' (n : ℤ), cexp (-π / (-I * τ) * (n + I * (I * z)) ^ 2) := by rw [tsum_exp_neg_quadratic h2] _ = 1 / (-I * τ) ^ (1 / 2 : ℂ) * cexp (π * I * (-1 / τ) * z ^ 2) * ∑' (n : ℤ), cexp (2 * π * I * n * (z / τ) + π * I * n ^ 2 * (-1 / τ)) := by simp_rw [mul_assoc _ (cexp _), ← tsum_mul_left (a := cexp _), ← Complex.exp_add] congr 2 with n : 1; congr 1 field_simp [I_ne_zero] ring_nf simp_rw [I_sq, I_pow_four] ring_nf _ = _ := by congr 3 ring
/-- The functional equation for the derivative of the Jacobi theta function, relating `jacobiTheta₂' z τ` to `jacobiTheta₂' (z / τ) (-1 / τ)`. This is the key lemma behind the proof of the functional equation for L-series of odd Dirichlet characters. -/ theorem jacobiTheta₂'_functional_equation (z τ : ℂ) : jacobiTheta₂' z τ = 1 / (-I * τ) ^ (1 / 2 : ℂ) * cexp (-π * I * z ^ 2 / τ) / τ * (jacobiTheta₂' (z / τ) (-1 / τ) - 2 * π * I * z * jacobiTheta₂ (z / τ) (-1 / τ)) := by rcases le_or_lt (im τ) 0 with hτ | hτ · rw [jacobiTheta₂'_undef z hτ, jacobiTheta₂'_undef, jacobiTheta₂_undef, mul_zero, sub_zero, mul_zero] <;> rw [neg_div, neg_im, one_div, inv_im, neg_nonpos] <;> exact div_nonneg (neg_nonneg.mpr hτ) (normSq_nonneg τ) have hτ' : 0 < (-1 / τ).im := by rw [div_eq_mul_inv, neg_one_mul, neg_im, inv_im, neg_div, neg_neg] exact div_pos hτ (normSq_pos.mpr (fun h ↦ lt_irrefl 0 (zero_im ▸ h ▸ hτ))) have hj : HasDerivAt (fun w ↦ jacobiTheta₂ (w / τ) (-1 / τ)) ((1 / τ) * jacobiTheta₂' (z / τ) (-1 / τ)) z := by have := hasDerivAt_jacobiTheta₂_fst (z / τ) hτ' simpa only [mul_comm, one_div] using this.comp z (hasDerivAt_mul_const τ⁻¹) calc _ = deriv (jacobiTheta₂ · τ) z := (hasDerivAt_jacobiTheta₂_fst z hτ).deriv.symm _ = deriv (fun z ↦ 1 / (-I * τ) ^ (1 / 2 : ℂ) * cexp (-π * I * z ^ 2 / τ) * jacobiTheta₂ (z / τ) (-1 / τ)) z := by rw [funext (jacobiTheta₂_functional_equation · τ)] _ = 1 / (-I * τ) ^ (1 / 2 : ℂ) * deriv (fun z ↦ cexp (-π * I * z ^ 2 / τ) * jacobiTheta₂ (z / τ) (-1 / τ)) z := by simp_rw [mul_assoc, deriv_const_mul_field] _ = 1 / (-I * τ) ^ (1 / 2 : ℂ) * (deriv (fun z ↦ cexp (-π * I * z ^ 2 / τ)) z * jacobiTheta₂ (z / τ) (-1 / τ) + cexp (-π * I * z ^ 2 / τ) * deriv (fun z ↦ jacobiTheta₂ (z / τ) (-1 / τ)) z) := by rw [deriv_mul _ hj.differentiableAt] exact (((differentiableAt_pow 2).const_mul _).mul_const _).cexp _ = _ := by
Mathlib/NumberTheory/ModularForms/JacobiTheta/TwoVariable.lean
499
531
/- 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.Basic import Mathlib.Topology.Order.ProjIcc /-! # Inverse trigonometric functions. See also `Analysis.SpecialFunctions.Trigonometric.Arctan` for the inverse tan function. (This is delayed as it is easier to set up after developing complex trigonometric functions.) Basic inequalities on trigonometric functions. -/ noncomputable section open Topology Filter Set Filter Real namespace Real variable {x y : ℝ} /-- Inverse of the `sin` function, returns values in the range `-π / 2 ≤ arcsin x ≤ π / 2`. It defaults to `-π / 2` on `(-∞, -1)` and to `π / 2` to `(1, ∞)`. -/ @[pp_nodot] noncomputable def arcsin : ℝ → ℝ := Subtype.val ∘ IccExtend (neg_le_self zero_le_one) sinOrderIso.symm theorem arcsin_mem_Icc (x : ℝ) : arcsin x ∈ Icc (-(π / 2)) (π / 2) := Subtype.coe_prop _ @[simp] theorem range_arcsin : range arcsin = Icc (-(π / 2)) (π / 2) := by rw [arcsin, range_comp Subtype.val] simp [Icc] theorem arcsin_le_pi_div_two (x : ℝ) : arcsin x ≤ π / 2 := (arcsin_mem_Icc x).2 theorem neg_pi_div_two_le_arcsin (x : ℝ) : -(π / 2) ≤ arcsin x := (arcsin_mem_Icc x).1 theorem arcsin_projIcc (x : ℝ) : arcsin (projIcc (-1) 1 (neg_le_self zero_le_one) x) = arcsin x := by rw [arcsin, Function.comp_apply, IccExtend_val, Function.comp_apply, IccExtend, Function.comp_apply] theorem sin_arcsin' {x : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) : sin (arcsin x) = x := by simpa [arcsin, IccExtend_of_mem _ _ hx, -OrderIso.apply_symm_apply] using Subtype.ext_iff.1 (sinOrderIso.apply_symm_apply ⟨x, hx⟩) theorem sin_arcsin {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : sin (arcsin x) = x := sin_arcsin' ⟨hx₁, hx₂⟩ theorem arcsin_sin' {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : arcsin (sin x) = x := injOn_sin (arcsin_mem_Icc _) hx <| by rw [sin_arcsin (neg_one_le_sin _) (sin_le_one _)] theorem arcsin_sin {x : ℝ} (hx₁ : -(π / 2) ≤ x) (hx₂ : x ≤ π / 2) : arcsin (sin x) = x := arcsin_sin' ⟨hx₁, hx₂⟩ theorem strictMonoOn_arcsin : StrictMonoOn arcsin (Icc (-1) 1) := (Subtype.strictMono_coe _).comp_strictMonoOn <| sinOrderIso.symm.strictMono.strictMonoOn_IccExtend _ @[gcongr] theorem arcsin_lt_arcsin {x y : ℝ} (hx : -1 ≤ x) (hlt : x < y) (hy : y ≤ 1) : arcsin x < arcsin y := strictMonoOn_arcsin ⟨hx, hlt.le.trans hy⟩ ⟨hx.trans hlt.le, hy⟩ hlt theorem monotone_arcsin : Monotone arcsin := (Subtype.mono_coe _).comp <| sinOrderIso.symm.monotone.IccExtend _ @[gcongr] theorem arcsin_le_arcsin {x y : ℝ} (h : x ≤ y) : arcsin x ≤ arcsin y := monotone_arcsin h theorem injOn_arcsin : InjOn arcsin (Icc (-1) 1) := strictMonoOn_arcsin.injOn theorem arcsin_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) : arcsin x = arcsin y ↔ x = y := injOn_arcsin.eq_iff ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ @[continuity, fun_prop] theorem continuous_arcsin : Continuous arcsin := continuous_subtype_val.comp sinOrderIso.symm.continuous.Icc_extend' @[fun_prop] theorem continuousAt_arcsin {x : ℝ} : ContinuousAt arcsin x := continuous_arcsin.continuousAt theorem arcsin_eq_of_sin_eq {x y : ℝ} (h₁ : sin x = y) (h₂ : x ∈ Icc (-(π / 2)) (π / 2)) : arcsin y = x := by subst y exact injOn_sin (arcsin_mem_Icc _) h₂ (sin_arcsin' (sin_mem_Icc x)) @[simp] theorem arcsin_zero : arcsin 0 = 0 := arcsin_eq_of_sin_eq sin_zero ⟨neg_nonpos.2 pi_div_two_pos.le, pi_div_two_pos.le⟩ @[simp] theorem arcsin_one : arcsin 1 = π / 2 := arcsin_eq_of_sin_eq sin_pi_div_two <| right_mem_Icc.2 (neg_le_self pi_div_two_pos.le) theorem arcsin_of_one_le {x : ℝ} (hx : 1 ≤ x) : arcsin x = π / 2 := by
rw [← arcsin_projIcc, projIcc_of_right_le _ hx, Subtype.coe_mk, arcsin_one] theorem arcsin_neg_one : arcsin (-1) = -(π / 2) := arcsin_eq_of_sin_eq (by rw [sin_neg, sin_pi_div_two]) <|
Mathlib/Analysis/SpecialFunctions/Trigonometric/Inverse.lean
108
111
/- Copyright (c) 2021 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.Topology.Gluing import Mathlib.Geometry.RingedSpace.OpenImmersion import Mathlib.Geometry.RingedSpace.LocallyRingedSpace.HasColimits /-! # Gluing Structured spaces Given a family of gluing data of structured spaces (presheafed spaces, sheafed spaces, or locally ringed spaces), we may glue them together. The construction should be "sealed" and considered as a black box, while only using the API provided. ## Main definitions * `AlgebraicGeometry.PresheafedSpace.GlueData`: A structure containing the family of gluing data. * `CategoryTheory.GlueData.glued`: The glued presheafed space. This is defined as the multicoequalizer of `∐ V i j ⇉ ∐ U i`, so that the general colimit API can be used. * `CategoryTheory.GlueData.ι`: The immersion `ι i : U i ⟶ glued` for each `i : J`. ## Main results * `AlgebraicGeometry.PresheafedSpace.GlueData.ιIsOpenImmersion`: The map `ι i : U i ⟶ glued` is an open immersion for each `i : J`. * `AlgebraicGeometry.PresheafedSpace.GlueData.ι_jointly_surjective` : The underlying maps of `ι i : U i ⟶ glued` are jointly surjective. * `AlgebraicGeometry.PresheafedSpace.GlueData.vPullbackConeIsLimit` : `V i j` is the pullback (intersection) of `U i` and `U j` over the glued space. Analogous results are also provided for `SheafedSpace` and `LocallyRingedSpace`. ## Implementation details Almost the whole file is dedicated to showing that `ι i` is an open immersion. The fact that this is an open embedding of topological spaces follows from `Mathlib/Topology/Gluing.lean`, and it remains to construct `Γ(𝒪_{U_i}, U) ⟶ Γ(𝒪_X, ι i '' U)` for each `U ⊆ U i`. Since `Γ(𝒪_X, ι i '' U)` is the limit of `diagram_over_open`, the components of the structure sheafs of the spaces in the gluing diagram, we need to construct a map `ιInvApp_π_app : Γ(𝒪_{U_i}, U) ⟶ Γ(𝒪_V, U_V)` for each `V` in the gluing diagram. We will refer to ![this diagram](https://i.imgur.com/P0phrwr.png) in the following doc strings. The `X` is the glued space, and the dotted arrow is a partial inverse guaranteed by the fact that it is an open immersion. The map `Γ(𝒪_{U_i}, U) ⟶ Γ(𝒪_{U_j}, _)` is given by the composition of the red arrows, and the map `Γ(𝒪_{U_i}, U) ⟶ Γ(𝒪_{V_{jk}}, _)` is given by the composition of the blue arrows. To lift this into a map from `Γ(𝒪_X, ι i '' U)`, we also need to show that these commute with the maps in the diagram (the green arrows), which is just a lengthy diagram-chasing. -/ noncomputable section open TopologicalSpace CategoryTheory Opposite Topology open CategoryTheory.Limits AlgebraicGeometry.PresheafedSpace open AlgebraicGeometry.PresheafedSpace.IsOpenImmersion open CategoryTheory.GlueData namespace AlgebraicGeometry universe v u variable (C : Type u) [Category.{v} C] namespace PresheafedSpace /-- A family of gluing data consists of 1. An index type `J` 2. A presheafed space `U i` for each `i : J`. 3. A presheafed space `V i j` for each `i j : J`. (Note that this is `J × J → PresheafedSpace C` rather than `J → J → PresheafedSpace C` to connect to the limits library easier.) 4. An open immersion `f i j : V i j ⟶ U i` for each `i j : ι`. 5. A transition map `t i j : V i j ⟶ V j i` for each `i j : ι`. such that 6. `f i i` is an isomorphism. 7. `t i i` is the identity. 8. `V i j ×[U i] V i k ⟶ V i j ⟶ V j i` factors through `V j k ×[U j] V j i ⟶ V j i` via some `t' : V i j ×[U i] V i k ⟶ V j k ×[U j] V j i`. 9. `t' i j k ≫ t' j k i ≫ t' k i j = 𝟙 _`. We can then glue the spaces `U i` together by identifying `V i j` with `V j i`, such that the `U i`'s are open subspaces of the glued space. -/ structure GlueData extends CategoryTheory.GlueData (PresheafedSpace.{u, v, v} C) where f_open : ∀ i j, IsOpenImmersion (f i j) attribute [instance] GlueData.f_open namespace GlueData variable {C} variable (D : GlueData.{v, u} C) local notation "𝖣" => D.toGlueData local notation "π₁ " i ", " j ", " k => pullback.fst (D.f i j) (D.f i k) local notation "π₂ " i ", " j ", " k => pullback.snd (D.f i j) (D.f i k) set_option quotPrecheck false local notation "π₁⁻¹ " i ", " j ", " k => (PresheafedSpace.IsOpenImmersion.pullbackFstOfRight (D.f i j) (D.f i k)).invApp set_option quotPrecheck false local notation "π₂⁻¹ " i ", " j ", " k => (PresheafedSpace.IsOpenImmersion.pullbackSndOfLeft (D.f i j) (D.f i k)).invApp /-- The glue data of topological spaces associated to a family of glue data of PresheafedSpaces. -/ abbrev toTopGlueData : TopCat.GlueData := { f_open := fun i j => (D.f_open i j).base_open toGlueData := 𝖣.mapGlueData (forget C) } theorem ι_isOpenEmbedding [HasLimits C] (i : D.J) : IsOpenEmbedding (𝖣.ι i).base := by rw [← show _ = (𝖣.ι i).base from 𝖣.ι_gluedIso_inv (PresheafedSpace.forget _) _, TopCat.coe_comp] exact (TopCat.homeoOfIso (𝖣.gluedIso (PresheafedSpace.forget _)).symm).isOpenEmbedding.comp (D.toTopGlueData.ι_isOpenEmbedding i) theorem pullback_base (i j k : D.J) (S : Set (D.V (i, j)).carrier) : (π₂ i, j, k) '' ((π₁ i, j, k) ⁻¹' S) = D.f i k ⁻¹' (D.f i j '' S) := by have eq₁ : _ = (π₁ i, j, k).base := PreservesPullback.iso_hom_fst (forget C) _ _ have eq₂ : _ = (π₂ i, j, k).base := PreservesPullback.iso_hom_snd (forget C) _ _ rw [← eq₁, ← eq₂, TopCat.coe_comp, Set.image_comp, TopCat.coe_comp, Set.preimage_comp, Set.image_preimage_eq] · simp only [forget_obj, forget_map, TopCat.pullback_snd_image_fst_preimage] rw [← TopCat.epi_iff_surjective] infer_instance /-- The red and the blue arrows in ![this diagram](https://i.imgur.com/0GiBUh6.png) commute. -/ @[simp, reassoc] theorem f_invApp_f_app (i j k : D.J) (U : Opens (D.V (i, j)).carrier) : (D.f_open i j).invApp _ U ≫ (D.f i k).c.app _ = (π₁ i, j, k).c.app (op U) ≫ (π₂⁻¹ i, j, k) (unop _) ≫ (D.V _).presheaf.map (eqToHom (by delta IsOpenImmersion.opensFunctor dsimp only [Functor.op, IsOpenMap.functor, Opens.map, unop_op] congr apply pullback_base)) := by have := PresheafedSpace.congr_app (@pullback.condition _ _ _ _ _ (D.f i j) (D.f i k) _) dsimp only [comp_c_app] at this rw [← cancel_epi (inv ((D.f_open i j).invApp _ U)), IsIso.inv_hom_id_assoc, IsOpenImmersion.inv_invApp] simp_rw [Category.assoc] erw [(π₁ i, j, k).c.naturality_assoc, reassoc_of% this, ← Functor.map_comp_assoc, IsOpenImmersion.inv_naturality_assoc, IsOpenImmersion.app_invApp_assoc, ← (D.V (i, k)).presheaf.map_comp, ← (D.V (i, k)).presheaf.map_comp] -- Porting note: need to provide an explicit argument, otherwise Lean does not know which -- category we are talking about convert (Category.comp_id ((f D.toGlueData i k).c.app _)).symm erw [(D.V (i, k)).presheaf.map_id] rfl /-- We can prove the `eq` along with the lemma. Thus this is bundled together here, and the lemma itself is separated below. -/ theorem snd_invApp_t_app' (i j k : D.J) (U : Opens (pullback (D.f i j) (D.f i k)).carrier) : ∃ eq, (π₂⁻¹ i, j, k) U ≫ (D.t k i).c.app _ ≫ (D.V (k, i)).presheaf.map (eqToHom eq) = (D.t' k i j).c.app _ ≫ (π₁⁻¹ k, j, i) (unop _) := by fconstructor -- Porting note: I don't know what the magic was in Lean3 proof, it just skipped the proof of `eq` · delta IsOpenImmersion.opensFunctor dsimp only [Functor.op, Opens.map, IsOpenMap.functor, unop_op, Opens.coe_mk] congr have := (𝖣.t_fac k i j).symm rw [← IsIso.inv_comp_eq] at this replace this := (congr_arg ((PresheafedSpace.Hom.base ·)) this).symm replace this := congr_arg (TopCat.Hom.hom ·) this replace this := congr_arg (ContinuousMap.toFun ·) this dsimp at this rw [this, Set.image_comp, Set.image_comp, Set.preimage_image_eq] swap · refine Function.HasLeftInverse.injective ⟨(D.t i k).base, fun x => ?_⟩ rw [← ConcreteCategory.comp_apply, ← comp_base, D.t_inv, id_base, ConcreteCategory.id_apply] refine congr_arg (_ '' ·) ?_ refine congr_fun ?_ _ refine Set.image_eq_preimage_of_inverse ?_ ?_ · intro x rw [← ConcreteCategory.comp_apply, ← comp_base, IsIso.inv_hom_id, id_base, ConcreteCategory.id_apply] · intro x rw [← ConcreteCategory.comp_apply, ← comp_base, IsIso.hom_inv_id, id_base, ConcreteCategory.id_apply] · rw [← IsIso.eq_inv_comp, IsOpenImmersion.inv_invApp, Category.assoc, (D.t' k i j).c.naturality_assoc] simp_rw [← Category.assoc] dsimp rw [← comp_c_app, congr_app (D.t_fac k i j), comp_c_app] dsimp simp_rw [Category.assoc] rw [IsOpenImmersion.inv_naturality, IsOpenImmersion.inv_naturality_assoc, IsOpenImmersion.app_inv_app'_assoc] · simp_rw [← (𝖣.V (k, i)).presheaf.map_comp]; rfl rintro x ⟨y, -, eq⟩ replace eq := ConcreteCategory.congr_arg (𝖣.t i k).base eq change ((π₂ i, j, k) ≫ D.t i k).base y = (D.t k i ≫ D.t i k).base x at eq rw [𝖣.t_inv, id_base, TopCat.id_app] at eq subst eq use (inv (D.t' k i j)).base y change (inv (D.t' k i j) ≫ π₁ k, i, j).base y = _ congr 3 rw [IsIso.inv_comp_eq, 𝖣.t_fac_assoc, 𝖣.t_inv, Category.comp_id] /-- The red and the blue arrows in ![this diagram](https://i.imgur.com/q6X1GJ9.png) commute. -/ @[simp, reassoc] theorem snd_invApp_t_app (i j k : D.J) (U : Opens (pullback (D.f i j) (D.f i k)).carrier) : (π₂⁻¹ i, j, k) U ≫ (D.t k i).c.app _ = (D.t' k i j).c.app _ ≫ (π₁⁻¹ k, j, i) (unop _) ≫ (D.V (k, i)).presheaf.map (eqToHom (D.snd_invApp_t_app' i j k U).choose.symm) := by have e := (D.snd_invApp_t_app' i j k U).choose_spec replace e := reassoc_of% e rw [← e] simp [eqToHom_map] variable [HasLimits C] theorem ι_image_preimage_eq (i j : D.J) (U : Opens (D.U i).carrier) : (Opens.map (𝖣.ι j).base).obj ((D.ι_isOpenEmbedding i).isOpenMap.functor.obj U) = (opensFunctor (D.f j i)).obj ((Opens.map (𝖣.t j i).base).obj ((Opens.map (𝖣.f i j).base).obj U)) := by ext1 dsimp only [Opens.map_coe, IsOpenMap.coe_functor_obj] rw [← show _ = (𝖣.ι i).base from 𝖣.ι_gluedIso_inv (PresheafedSpace.forget _) i, ← show _ = (𝖣.ι j).base from 𝖣.ι_gluedIso_inv (PresheafedSpace.forget _) j] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11224): change `rw` to `erw` on `coe_comp` erw [TopCat.coe_comp, TopCat.coe_comp, TopCat.coe_comp] rw [Set.image_comp, Set.preimage_comp] erw [Set.preimage_image_eq] · refine Eq.trans (D.toTopGlueData.preimage_image_eq_image' _ _ _) ?_ dsimp rw [Set.image_comp] refine congr_arg (_ '' ·) ?_ rw [Set.eq_preimage_iff_image_eq, ← Set.image_comp] swap · exact CategoryTheory.ConcreteCategory.bijective_of_isIso (C := TopCat) _ change (D.t i j ≫ D.t j i).base '' _ = _ rw [𝖣.t_inv] simp · rw [← TopCat.coe_comp, ← TopCat.mono_iff_injective] infer_instance /-- (Implementation). The map `Γ(𝒪_{U_i}, U) ⟶ Γ(𝒪_{U_j}, 𝖣.ι j ⁻¹' (𝖣.ι i '' U))` -/ def opensImagePreimageMap (i j : D.J) (U : Opens (D.U i).carrier) : (D.U i).presheaf.obj (op U) ⟶ (D.U j).presheaf.obj (op <| (Opens.map (𝖣.ι j).base).obj ((D.ι_isOpenEmbedding i).isOpenMap.functor.obj U)) := (D.f i j).c.app (op U) ≫ (D.t j i).c.app _ ≫ (D.f_open j i).invApp _ (unop _) ≫ (𝖣.U j).presheaf.map (eqToHom (D.ι_image_preimage_eq i j U)).op theorem opensImagePreimageMap_app' (i j k : D.J) (U : Opens (D.U i).carrier) : ∃ eq, D.opensImagePreimageMap i j U ≫ (D.f j k).c.app _ = ((π₁ j, i, k) ≫ D.t j i ≫ D.f i j).c.app (op U) ≫ (π₂⁻¹ j, i, k) (unop _) ≫ (D.V (j, k)).presheaf.map (eqToHom eq) := by constructor · delta opensImagePreimageMap simp_rw [Category.assoc] rw [(D.f j k).c.naturality, f_invApp_f_app_assoc] · erw [← (D.V (j, k)).presheaf.map_comp] · simp_rw [← Category.assoc] erw [← comp_c_app, ← comp_c_app] · simp_rw [Category.assoc] dsimp only [Functor.op, unop_op, Quiver.Hom.unop_op] rw [eqToHom_map (Opens.map _), eqToHom_op, eqToHom_trans] congr /-- The red and the blue arrows in ![this diagram](https://i.imgur.com/mBzV1Rx.png) commute. -/ theorem opensImagePreimageMap_app (i j k : D.J) (U : Opens (D.U i).carrier) : D.opensImagePreimageMap i j U ≫ (D.f j k).c.app _ = ((π₁ j, i, k) ≫ D.t j i ≫ D.f i j).c.app (op U) ≫ (π₂⁻¹ j, i, k) (unop _) ≫ (D.V (j, k)).presheaf.map (eqToHom (opensImagePreimageMap_app' D i j k U).choose) := (opensImagePreimageMap_app' D i j k U).choose_spec -- This is proved separately since `reassoc` somehow timeouts. theorem opensImagePreimageMap_app_assoc (i j k : D.J) (U : Opens (D.U i).carrier) {X' : C} (f' : _ ⟶ X') : D.opensImagePreimageMap i j U ≫ (D.f j k).c.app _ ≫ f' = ((π₁ j, i, k) ≫ D.t j i ≫ D.f i j).c.app (op U) ≫ (π₂⁻¹ j, i, k) (unop _) ≫ (D.V (j, k)).presheaf.map (eqToHom (opensImagePreimageMap_app' D i j k U).choose) ≫ f' := by simpa only [Category.assoc] using congr_arg (· ≫ f') (opensImagePreimageMap_app D i j k U) /-- (Implementation) Given an open subset of one of the spaces `U ⊆ Uᵢ`, the sheaf component of the image `ι '' U` in the glued space is the limit of this diagram. -/ abbrev diagramOverOpen {i : D.J} (U : Opens (D.U i).carrier) : -- Porting note : ↓ these need to be explicit (WalkingMultispan (.prod D.J))ᵒᵖ ⥤ C := componentwiseDiagram 𝖣.diagram.multispan ((D.ι_isOpenEmbedding i).isOpenMap.functor.obj U) /-- (Implementation) The projection from the limit of `diagram_over_open` to a component of `D.U j`. -/ abbrev diagramOverOpenπ {i : D.J} (U : Opens (D.U i).carrier) (j : D.J) := limit.π (D.diagramOverOpen U) (op (WalkingMultispan.right j)) /-- (Implementation) We construct the map `Γ(𝒪_{U_i}, U) ⟶ Γ(𝒪_V, U_V)` for each `V` in the gluing diagram. We will lift these maps into `ιInvApp`. -/ def ιInvAppπApp {i : D.J} (U : Opens (D.U i).carrier) (j) : (𝖣.U i).presheaf.obj (op U) ⟶ (D.diagramOverOpen U).obj (op j) := by rcases j with (⟨j, k⟩ | j) · refine D.opensImagePreimageMap i j U ≫ (D.f j k).c.app _ ≫ (D.V (j, k)).presheaf.map (eqToHom ?_) rw [Functor.op_obj] congr 1; ext1 dsimp only [Functor.op_obj, Opens.map_coe, unop_op, IsOpenMap.coe_functor_obj] rw [Set.preimage_preimage] change (D.f j k ≫ 𝖣.ι j).base ⁻¹' _ = _ -- Porting note: used to be `congr 3` suffices D.f j k ≫ D.ι j = colimit.ι D.diagram.multispan (WalkingMultispan.left (j, k)) by rw [this] rfl exact colimit.w 𝖣.diagram.multispan (WalkingMultispan.Hom.fst (j, k)) · exact D.opensImagePreimageMap i j U set_option maxHeartbeats 600000 in -- Porting note: time out started in `erw [... congr_app (pullbackSymmetry_hom_comp_snd _ _)]` and -- the last congr has a very difficult `rfl : eqToHom _ ≫ eqToHom _ ≫ ... = eqToHom ... ` /-- (Implementation) The natural map `Γ(𝒪_{U_i}, U) ⟶ Γ(𝒪_X, 𝖣.ι i '' U)`. This forms the inverse of `(𝖣.ι i).c.app (op U)`. -/ def ιInvApp {i : D.J} (U : Opens (D.U i).carrier) : (D.U i).presheaf.obj (op U) ⟶ limit (D.diagramOverOpen U) := limit.lift (D.diagramOverOpen U) { pt := (D.U i).presheaf.obj (op U) π := { app := fun j => D.ιInvAppπApp U (unop j) naturality := fun {X Y} f' => by induction X with | op X => ?_ induction Y with | op Y => ?_ let f : Y ⟶ X := f'.unop; have : f' = f.op := rfl; clear_value f; subst this rcases f with (_ | ⟨j, k⟩ | ⟨j, k⟩) · simp · simp only [Functor.const_obj_obj, Functor.const_obj_map, Category.id_comp] congr 1 simp only [Functor.const_obj_obj, Functor.const_obj_map, Category.id_comp] -- It remains to show that the blue is equal to red + green in the original diagram. -- The proof strategy is illustrated in ![this diagram](https://i.imgur.com/mBzV1Rx.png) -- where we prove red = pink = light-blue = green = blue. change D.opensImagePreimageMap i j U ≫ (D.f j k).c.app _ ≫ (D.V (j, k)).presheaf.map (eqToHom _) = D.opensImagePreimageMap _ _ _ ≫ ((D.f k j).c.app _ ≫ (D.t j k).c.app _) ≫ (D.V (j, k)).presheaf.map (eqToHom _) rw [opensImagePreimageMap_app_assoc] simp_rw [Category.assoc] rw [opensImagePreimageMap_app_assoc, (D.t j k).c.naturality_assoc, snd_invApp_t_app_assoc, ← PresheafedSpace.comp_c_app_assoc] -- light-blue = green is relatively easy since the part that differs does not involve -- partial inverses. have : D.t' j k i ≫ (π₁ k, i, j) ≫ D.t k i ≫ 𝖣.f i k = (pullbackSymmetry _ _).hom ≫ (π₁ j, i, k) ≫ D.t j i ≫ D.f i j := by rw [← 𝖣.t_fac_assoc, 𝖣.t'_comp_eq_pullbackSymmetry_assoc, pullbackSymmetry_hom_comp_snd_assoc, pullback.condition, 𝖣.t_fac_assoc] rw [congr_app this, PresheafedSpace.comp_c_app_assoc (pullbackSymmetry _ _).hom] simp_rw [Category.assoc] congr 1 rw [← IsIso.eq_inv_comp, IsOpenImmersion.inv_invApp] simp_rw [Category.assoc] erw [NatTrans.naturality_assoc, ← PresheafedSpace.comp_c_app_assoc, congr_app (pullbackSymmetry_hom_comp_snd _ _)] simp_rw [Category.assoc] erw [IsOpenImmersion.inv_naturality_assoc, IsOpenImmersion.inv_naturality_assoc, IsOpenImmersion.inv_naturality_assoc, IsOpenImmersion.app_invApp_assoc] rw [← (D.V (j, k)).presheaf.map_comp] erw [← (D.V (j, k)).presheaf.map_comp] repeat rw [← (D.V (j, k)).presheaf.map_comp] rfl } } /-- `ιInvApp` is the left inverse of `D.ι i` on `U`. -/ theorem ιInvApp_π {i : D.J} (U : Opens (D.U i).carrier) : ∃ eq, D.ιInvApp U ≫ D.diagramOverOpenπ U i = (D.U i).presheaf.map (eqToHom eq) := by fconstructor -- Porting note: I don't know what the magic was in Lean3 proof, it just skipped the proof of `eq` · congr; ext1; change _ = _ ⁻¹' (_ '' _); ext1 x simp only [SetLike.mem_coe, unop_op, Set.mem_preimage, Set.mem_image] refine ⟨fun h => ⟨_, h, rfl⟩, ?_⟩ rintro ⟨y, h1, h2⟩ convert h1 using 1 delta ι Multicoequalizer.π at h2 apply_fun (D.ι _).base · exact h2.symm · have := D.ι_gluedIso_inv (PresheafedSpace.forget _) i dsimp at this rw [← this, TopCat.coe_comp] refine Function.Injective.comp ?_ (TopCat.GlueData.ι_injective D.toTopGlueData i) rw [← TopCat.mono_iff_injective] infer_instance delta ιInvApp rw [limit.lift_π] change D.opensImagePreimageMap i i U = _ dsimp [opensImagePreimageMap] rw [congr_app (D.t_id _), id_c_app, ← Functor.map_comp] erw [IsOpenImmersion.inv_naturality_assoc, IsOpenImmersion.app_inv_app'_assoc] · simp only [eqToHom_op, eqToHom_trans, eqToHom_map (Functor.op _), ← Functor.map_comp] rfl · rw [Set.range_eq_univ.mpr _] · simp · rw [← TopCat.epi_iff_surjective] infer_instance
/-- The `eqToHom` given by `ιInvApp_π`. -/ abbrev ιInvAppπEqMap {i : D.J} (U : Opens (D.U i).carrier) := (D.U i).presheaf.map (eqToIso (D.ιInvApp_π U).choose).inv /-- `ιInvApp` is the right inverse of `D.ι i` on `U`. -/ theorem π_ιInvApp_π (i j : D.J) (U : Opens (D.U i).carrier) : D.diagramOverOpenπ U i ≫ D.ιInvAppπEqMap U ≫ D.ιInvApp U ≫ D.diagramOverOpenπ U j = D.diagramOverOpenπ U j := by rw [← @cancel_mono (f := (componentwiseDiagram 𝖣.diagram.multispan _).map (Quiver.Hom.op (WalkingMultispan.Hom.snd (i, j))) ≫ 𝟙 _) ..] · simp_rw [Category.assoc] rw [limit.w_assoc] erw [limit.lift_π_assoc] rw [Category.comp_id, Category.comp_id] change _ ≫ _ ≫ (_ ≫ _) ≫ _ = _ rw [congr_app (D.t_id _), id_c_app] simp_rw [Category.assoc] rw [← Functor.map_comp_assoc] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11224): change `rw` to `erw` erw [IsOpenImmersion.inv_naturality_assoc] erw [IsOpenImmersion.app_invApp_assoc] iterate 3 rw [← Functor.map_comp_assoc] rw [NatTrans.naturality_assoc] erw [← (D.V (i, j)).presheaf.map_comp] convert limit.w (componentwiseDiagram 𝖣.diagram.multispan _) (Quiver.Hom.op (WalkingMultispan.Hom.fst (i, j))) · rw [Category.comp_id] apply (config := { allowSynthFailures := true }) mono_comp
Mathlib/Geometry/RingedSpace/PresheafedSpace/Gluing.lean
419
448
/- Copyright (c) 2024 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ import Mathlib.NumberTheory.DirichletCharacter.Bounds import Mathlib.NumberTheory.LSeries.Convolution import Mathlib.NumberTheory.LSeries.Deriv import Mathlib.NumberTheory.LSeries.RiemannZeta import Mathlib.NumberTheory.SumPrimeReciprocals import Mathlib.NumberTheory.VonMangoldt /-! # L-series of Dirichlet characters and arithmetic functions We collect some results on L-series of specific (arithmetic) functions, for example, the Möbius function `μ` or the von Mangoldt function `Λ`. In particular, we show that `L ↗Λ` is the negative of the logarithmic derivative of the Riemann zeta function on `re s > 1`; see `LSeries_vonMangoldt_eq_deriv_riemannZeta_div`. We also prove some general results on L-series associated to Dirichlet characters (i.e., Dirichlet L-series). For example, we show that the abscissa of absolute convergence equals `1` (see `DirichletCharacter.absicssaOfAbsConv`) and that the L-series does not vanish on the open half-plane `re s > 1` (see `DirichletCharacter.LSeries_ne_zero_of_one_lt_re`). We deduce results on the Riemann zeta function (which is `L 1` or `L ↗ζ` on `re s > 1`) as special cases. ## Tags Dirichlet L-series, Möbius function, von Mangoldt function, Riemann zeta function -/ open scoped LSeries.notation /-- `δ` is the function underlying the arithmetic function `1`. -/ lemma ArithmeticFunction.one_eq_delta : ↗(1 : ArithmeticFunction ℂ) = δ := by ext simp [one_apply, LSeries.delta] section Moebius /-! ### The L-series of the Möbius function We show that `L μ s` converges absolutely if and only if `re s > 1`. -/ namespace ArithmeticFunction open LSeries Nat Complex lemma not_LSeriesSummable_moebius_at_one : ¬ LSeriesSummable ↗μ 1 := by refine fun h ↦ not_summable_one_div_on_primes <| summable_ofReal.mp <| .of_neg ?_ refine (h.indicator {n | n.Prime}).congr fun n ↦ ?_ by_cases hn : n.Prime · simp [hn, hn.ne_zero, moebius_apply_prime hn, push_cast, neg_div] · simp [hn] /-- The L-series of the Möbius function converges absolutely at `s` if and only if `re s > 1`. -/ lemma LSeriesSummable_moebius_iff {s : ℂ} : LSeriesSummable ↗μ s ↔ 1 < s.re := by refine ⟨fun H ↦ ?_, LSeriesSummable_of_bounded_of_one_lt_re (m := 1) fun n _ ↦ ?_⟩ · by_contra! h exact not_LSeriesSummable_moebius_at_one <| LSeriesSummable.of_re_le_re (by simpa) H · norm_cast exact abs_moebius_le_one /-- The abscissa of absolute convergence of the L-series of the Möbius function is `1`. -/ lemma abscissaOfAbsConv_moebius : abscissaOfAbsConv ↗μ = 1 := by simpa [abscissaOfAbsConv, LSeriesSummable_moebius_iff, Set.Ioi_def, EReal.image_coe_Ioi] using csInf_Ioo <| EReal.coe_lt_top 1 end ArithmeticFunction end Moebius /-! ### L-series of Dirichlet characters -/ open Nat open scoped ArithmeticFunction.zeta in lemma ArithmeticFunction.const_one_eq_zeta {R : Type*} [AddMonoidWithOne R] {n : ℕ} (hn : n ≠ 0) : (1 : ℕ → R) n = (ζ ·) n := by simp [hn] lemma LSeries.one_convolution_eq_zeta_convolution {R : Type*} [Semiring R] (f : ℕ → R) : (1 : ℕ → R) ⍟ f = ((ArithmeticFunction.zeta ·) : ℕ → R) ⍟ f := convolution_congr ArithmeticFunction.const_one_eq_zeta fun _ ↦ rfl lemma LSeries.convolution_one_eq_convolution_zeta {R : Type*} [Semiring R] (f : ℕ → R) : f ⍟ (1 : ℕ → R) = f ⍟ ((ArithmeticFunction.zeta ·) : ℕ → R) := convolution_congr (fun _ ↦ rfl) ArithmeticFunction.const_one_eq_zeta /-- `χ₁` is (local) notation for the (necessarily trivial) Dirichlet character modulo `1`. -/ local notation (name := Dchar_one) "χ₁" => (1 : DirichletCharacter ℂ 1) namespace DirichletCharacter open ArithmeticFunction in /-- The arithmetic function associated to a Dirichlet character is multiplicative. -/ lemma isMultiplicative_toArithmeticFunction {N : ℕ} {R : Type*} [CommMonoidWithZero R] (χ : DirichletCharacter R N) : (toArithmeticFunction (χ ·)).IsMultiplicative := by refine IsMultiplicative.iff_ne_zero.mpr ⟨?_, fun {m} {n} hm hn _ ↦ ?_⟩ · simp [toArithmeticFunction] · simp [toArithmeticFunction, hm, hn] lemma apply_eq_toArithmeticFunction_apply {N : ℕ} {R : Type*} [CommMonoidWithZero R] (χ : DirichletCharacter R N) {n : ℕ} (hn : n ≠ 0) : χ n = toArithmeticFunction (χ ·) n := by simp [toArithmeticFunction, hn] open LSeries Nat Complex /-- Twisting by a Dirichlet character `χ` distributes over convolution. -/ lemma mul_convolution_distrib {R : Type*} [CommSemiring R] {n : ℕ} (χ : DirichletCharacter R n) (f g : ℕ → R) : (((χ ·) : ℕ → R) * f) ⍟ (((χ ·) : ℕ → R) * g) = ((χ ·) : ℕ → R) * (f ⍟ g) := by ext n simp only [Pi.mul_apply, LSeries.convolution_def, Finset.mul_sum] refine Finset.sum_congr rfl fun p hp ↦ ?_ rw [(mem_divisorsAntidiagonal.mp hp).1.symm, cast_mul, map_mul] exact mul_mul_mul_comm .. lemma mul_delta {n : ℕ} (χ : DirichletCharacter ℂ n) : ↗χ * δ = δ := LSeries.mul_delta <| by rw [cast_one, map_one] lemma delta_mul {n : ℕ} (χ : DirichletCharacter ℂ n) : δ * ↗χ = δ := mul_comm δ _ ▸ mul_delta .. open ArithmeticFunction in /-- The convolution of a Dirichlet character `χ` with the twist `χ * μ` is `δ`, the indicator function of `{1}`. -/ lemma convolution_mul_moebius {n : ℕ} (χ : DirichletCharacter ℂ n) : ↗χ ⍟ (↗χ * ↗μ) = δ := by have : (1 : ℕ → ℂ) ⍟ (μ ·) = δ := by rw [one_convolution_eq_zeta_convolution, ← one_eq_delta] simp_rw [← natCoe_apply, ← intCoe_apply, coe_mul, coe_zeta_mul_coe_moebius] nth_rewrite 1 [← mul_one ↗χ] simpa only [mul_convolution_distrib χ 1 ↗μ, this] using mul_delta _ /-- The Dirichlet character mod `0` corresponds to `δ`. -/ lemma modZero_eq_delta {χ : DirichletCharacter ℂ 0} : ↗χ = δ := by ext n rcases eq_or_ne n 0 with rfl | hn · simp_rw [cast_zero, χ.map_nonunit not_isUnit_zero, delta, reduceCtorEq, if_false] rcases eq_or_ne n 1 with rfl | hn' · simp [delta] have : ¬ IsUnit (n : ZMod 0) := fun h ↦ hn' <| ZMod.eq_one_of_isUnit_natCast h simp_all [χ.map_nonunit this, delta] /-- The Dirichlet character mod `1` corresponds to the constant function `1`. -/ lemma modOne_eq_one {R : Type*} [CommMonoidWithZero R] {χ : DirichletCharacter R 1} : ((χ ·) : ℕ → R) = 1 := by ext rw [χ.level_one, MulChar.one_apply (isUnit_of_subsingleton _), Pi.one_apply] lemma LSeries_modOne_eq : L ↗χ₁ = L 1 := congr_arg L modOne_eq_one /-- The L-series of a Dirichlet character mod `N > 0` does not converge absolutely at `s = 1`. -/ lemma not_LSeriesSummable_at_one {N : ℕ} (hN : N ≠ 0) (χ : DirichletCharacter ℂ N) : ¬ LSeriesSummable ↗χ 1 := by refine fun h ↦ (Real.not_summable_indicator_one_div_natCast hN 1) ?_ refine h.norm.of_nonneg_of_le (fun m ↦ Set.indicator_apply_nonneg (fun _ ↦ by positivity)) (fun n ↦ ?_) simp only [norm_term_eq, Set.indicator, Set.mem_setOf_eq] split_ifs with h₁ h₂ · simp [h₂] · simp [h₁, χ.map_one] all_goals positivity /-- The L-series of a Dirichlet character converges absolutely at `s` if `re s > 1`. -/ lemma LSeriesSummable_of_one_lt_re {N : ℕ} (χ : DirichletCharacter ℂ N) {s : ℂ} (hs : 1 < s.re) : LSeriesSummable ↗χ s := LSeriesSummable_of_bounded_of_one_lt_re (fun _ _ ↦ χ.norm_le_one _) hs /-- The L-series of a Dirichlet character mod `N > 0` converges absolutely at `s` if and only if `re s > 1`. -/ lemma LSeriesSummable_iff {N : ℕ} (hN : N ≠ 0) (χ : DirichletCharacter ℂ N) {s : ℂ} : LSeriesSummable ↗χ s ↔ 1 < s.re := by refine ⟨fun H ↦ ?_, LSeriesSummable_of_one_lt_re χ⟩ by_contra! h
exact not_LSeriesSummable_at_one hN χ <| LSeriesSummable.of_re_le_re (by simp [h]) H /-- The abscissa of absolute convergence of the L-series of a Dirichlet character mod `N > 0` is `1`. -/ lemma absicssaOfAbsConv_eq_one {N : ℕ} (hn : N ≠ 0) (χ : DirichletCharacter ℂ N) : abscissaOfAbsConv ↗χ = 1 := by simpa [abscissaOfAbsConv, LSeriesSummable_iff hn χ, Set.Ioi_def, EReal.image_coe_Ioi] using csInf_Ioo <| EReal.coe_lt_top 1
Mathlib/NumberTheory/LSeries/Dirichlet.lean
187
194
/- Copyright (c) 2022 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Asymptotics.Lemmas import Mathlib.Analysis.Normed.Module.Basic /-! # Asymptotic equivalence up to a constant In this file we define `Asymptotics.IsTheta l f g` (notation: `f =Θ[l] g`) as `f =O[l] g ∧ g =O[l] f`, then prove basic properties of this equivalence relation. -/ open Filter open Topology namespace Asymptotics variable {α : Type*} {β : Type*} {E : Type*} {F : Type*} {G : Type*} {E' : Type*} {F' : Type*} {G' : Type*} {E'' : Type*} {F'' : Type*} {G'' : Type*} {R : Type*} {R' : Type*} {𝕜 : Type*} {𝕜' : Type*} variable [Norm E] [Norm F] [Norm G] variable [SeminormedAddCommGroup E'] [SeminormedAddCommGroup F'] [SeminormedAddCommGroup G'] [NormedAddCommGroup E''] [NormedAddCommGroup F''] [NormedAddCommGroup G''] [SeminormedRing R] [SeminormedRing R'] variable [NormedField 𝕜] [NormedField 𝕜'] variable {c c' c₁ c₂ : ℝ} {f : α → E} {g : α → F} {k : α → G} variable {f' : α → E'} {g' : α → F'} {k' : α → G'} variable {f'' : α → E''} {g'' : α → F''} variable {l l' : Filter α} /-- We say that `f` is `Θ(g)` along a filter `l` (notation: `f =Θ[l] g`) if `f =O[l] g` and `g =O[l] f`. -/ def IsTheta (l : Filter α) (f : α → E) (g : α → F) : Prop := IsBigO l f g ∧ IsBigO l g f @[inherit_doc] notation:100 f " =Θ[" l "] " g:100 => IsTheta l f g theorem IsBigO.antisymm (h₁ : f =O[l] g) (h₂ : g =O[l] f) : f =Θ[l] g := ⟨h₁, h₂⟩ lemma IsTheta.isBigO (h : f =Θ[l] g) : f =O[l] g := h.1 lemma IsTheta.isBigO_symm (h : f =Θ[l] g) : g =O[l] f := h.2 @[refl] theorem isTheta_refl (f : α → E) (l : Filter α) : f =Θ[l] f := ⟨isBigO_refl _ _, isBigO_refl _ _⟩ theorem isTheta_rfl : f =Θ[l] f := isTheta_refl _ _ @[symm] nonrec theorem IsTheta.symm (h : f =Θ[l] g) : g =Θ[l] f := h.symm theorem isTheta_comm : f =Θ[l] g ↔ g =Θ[l] f := ⟨fun h ↦ h.symm, fun h ↦ h.symm⟩ @[trans] theorem IsTheta.trans {f : α → E} {g : α → F'} {k : α → G} (h₁ : f =Θ[l] g) (h₂ : g =Θ[l] k) : f =Θ[l] k := ⟨h₁.1.trans h₂.1, h₂.2.trans h₁.2⟩ instance : Trans (α := α → E) (β := α → F') (γ := α → G) (IsTheta l) (IsTheta l) (IsTheta l) := ⟨IsTheta.trans⟩ @[trans] theorem IsBigO.trans_isTheta {f : α → E} {g : α → F'} {k : α → G} (h₁ : f =O[l] g) (h₂ : g =Θ[l] k) : f =O[l] k := h₁.trans h₂.1 instance : Trans (α := α → E) (β := α → F') (γ := α → G) (IsBigO l) (IsTheta l) (IsBigO l) := ⟨IsBigO.trans_isTheta⟩ @[trans] theorem IsTheta.trans_isBigO {f : α → E} {g : α → F'} {k : α → G} (h₁ : f =Θ[l] g) (h₂ : g =O[l] k) : f =O[l] k := h₁.1.trans h₂ instance : Trans (α := α → E) (β := α → F') (γ := α → G) (IsTheta l) (IsBigO l) (IsBigO l) := ⟨IsTheta.trans_isBigO⟩ @[trans] theorem IsLittleO.trans_isTheta {f : α → E} {g : α → F} {k : α → G'} (h₁ : f =o[l] g) (h₂ : g =Θ[l] k) : f =o[l] k := h₁.trans_isBigO h₂.1 instance : Trans (α := α → E) (β := α → F') (γ := α → G') (IsLittleO l) (IsTheta l) (IsLittleO l) := ⟨IsLittleO.trans_isTheta⟩ @[trans] theorem IsTheta.trans_isLittleO {f : α → E} {g : α → F'} {k : α → G} (h₁ : f =Θ[l] g) (h₂ : g =o[l] k) : f =o[l] k := h₁.1.trans_isLittleO h₂ instance : Trans (α := α → E) (β := α → F') (γ := α → G) (IsTheta l) (IsLittleO l) (IsLittleO l) := ⟨IsTheta.trans_isLittleO⟩ @[trans] theorem IsTheta.trans_eventuallyEq {f : α → E} {g₁ g₂ : α → F} (h : f =Θ[l] g₁) (hg : g₁ =ᶠ[l] g₂) : f =Θ[l] g₂ := ⟨h.1.trans_eventuallyEq hg, hg.symm.trans_isBigO h.2⟩ instance : Trans (α := α → E) (β := α → F) (γ := α → F) (IsTheta l) (EventuallyEq l) (IsTheta l) := ⟨IsTheta.trans_eventuallyEq⟩ @[trans] theorem _root_.Filter.EventuallyEq.trans_isTheta {f₁ f₂ : α → E} {g : α → F} (hf : f₁ =ᶠ[l] f₂) (h : f₂ =Θ[l] g) : f₁ =Θ[l] g := ⟨hf.trans_isBigO h.1, h.2.trans_eventuallyEq hf.symm⟩ instance : Trans (α := α → E) (β := α → E) (γ := α → F) (EventuallyEq l) (IsTheta l) (IsTheta l) := ⟨EventuallyEq.trans_isTheta⟩ lemma _root_.Filter.EventuallyEq.isTheta {f g : α → E} (h : f =ᶠ[l] g) : f =Θ[l] g := h.trans_isTheta isTheta_rfl @[simp] theorem isTheta_bot : f =Θ[⊥] g := by simp [IsTheta] @[simp] theorem isTheta_norm_left : (fun x ↦ ‖f' x‖) =Θ[l] g ↔ f' =Θ[l] g := by simp [IsTheta] @[simp] theorem isTheta_norm_right : (f =Θ[l] fun x ↦ ‖g' x‖) ↔ f =Θ[l] g' := by simp [IsTheta] alias ⟨IsTheta.of_norm_left, IsTheta.norm_left⟩ := isTheta_norm_left alias ⟨IsTheta.of_norm_right, IsTheta.norm_right⟩ := isTheta_norm_right theorem IsTheta.of_norm_eventuallyEq_norm (h : (fun x ↦ ‖f x‖) =ᶠ[l] fun x ↦ ‖g x‖) : f =Θ[l] g := ⟨.of_bound' h.le, .of_bound' h.symm.le⟩ @[deprecated (since := "2025-01-03")] alias isTheta_of_norm_eventuallyEq := IsTheta.of_norm_eventuallyEq_norm theorem IsTheta.of_norm_eventuallyEq {g : α → ℝ} (h : (fun x ↦ ‖f' x‖) =ᶠ[l] g) : f' =Θ[l] g := of_norm_eventuallyEq_norm <| h.mono fun x hx ↦ by simp only [← hx, norm_norm] @[deprecated (since := "2025-01-03")] alias isTheta_of_norm_eventuallyEq' := IsTheta.of_norm_eventuallyEq theorem IsTheta.isLittleO_congr_left (h : f' =Θ[l] g') : f' =o[l] k ↔ g' =o[l] k := ⟨h.symm.trans_isLittleO, h.trans_isLittleO⟩ theorem IsTheta.isLittleO_congr_right (h : g' =Θ[l] k') : f =o[l] g' ↔ f =o[l] k' := ⟨fun H ↦ H.trans_isTheta h, fun H ↦ H.trans_isTheta h.symm⟩ theorem IsTheta.isBigO_congr_left (h : f' =Θ[l] g') : f' =O[l] k ↔ g' =O[l] k := ⟨h.symm.trans_isBigO, h.trans_isBigO⟩ theorem IsTheta.isBigO_congr_right (h : g' =Θ[l] k') : f =O[l] g' ↔ f =O[l] k' := ⟨fun H ↦ H.trans_isTheta h, fun H ↦ H.trans_isTheta h.symm⟩ lemma IsTheta.isTheta_congr_left (h : f' =Θ[l] g') : f' =Θ[l] k ↔ g' =Θ[l] k := h.isBigO_congr_left.and h.isBigO_congr_right lemma IsTheta.isTheta_congr_right (h : f' =Θ[l] g') : k =Θ[l] f' ↔ k =Θ[l] g' := h.isBigO_congr_right.and h.isBigO_congr_left theorem IsTheta.mono (h : f =Θ[l] g) (hl : l' ≤ l) : f =Θ[l'] g := ⟨h.1.mono hl, h.2.mono hl⟩ theorem IsTheta.sup (h : f' =Θ[l] g') (h' : f' =Θ[l'] g') : f' =Θ[l ⊔ l'] g' := ⟨h.1.sup h'.1, h.2.sup h'.2⟩ @[simp] theorem isTheta_sup : f' =Θ[l ⊔ l'] g' ↔ f' =Θ[l] g' ∧ f' =Θ[l'] g' := ⟨fun h ↦ ⟨h.mono le_sup_left, h.mono le_sup_right⟩, fun h ↦ h.1.sup h.2⟩ theorem IsTheta.eq_zero_iff (h : f'' =Θ[l] g'') : ∀ᶠ x in l, f'' x = 0 ↔ g'' x = 0 := h.1.eq_zero_imp.mp <| h.2.eq_zero_imp.mono fun _ ↦ Iff.intro theorem IsTheta.tendsto_zero_iff (h : f'' =Θ[l] g'') : Tendsto f'' l (𝓝 0) ↔ Tendsto g'' l (𝓝 0) := by simp only [← isLittleO_one_iff ℝ, h.isLittleO_congr_left] theorem IsTheta.tendsto_norm_atTop_iff (h : f' =Θ[l] g') : Tendsto (norm ∘ f') l atTop ↔ Tendsto (norm ∘ g') l atTop := by simp only [Function.comp_def, ← isLittleO_const_left_of_ne (one_ne_zero' ℝ), h.isLittleO_congr_right] theorem IsTheta.isBoundedUnder_le_iff (h : f' =Θ[l] g') : IsBoundedUnder (· ≤ ·) l (norm ∘ f') ↔ IsBoundedUnder (· ≤ ·) l (norm ∘ g') := by simp only [← isBigO_const_of_ne (one_ne_zero' ℝ), h.isBigO_congr_left] theorem IsTheta.smul [NormedSpace 𝕜 E'] [NormedSpace 𝕜' F'] {f₁ : α → 𝕜} {f₂ : α → 𝕜'} {g₁ : α → E'} {g₂ : α → F'} (hf : f₁ =Θ[l] f₂) (hg : g₁ =Θ[l] g₂) : (fun x ↦ f₁ x • g₁ x) =Θ[l] fun x ↦ f₂ x • g₂ x := ⟨hf.1.smul hg.1, hf.2.smul hg.2⟩ theorem IsTheta.mul {f₁ f₂ : α → 𝕜} {g₁ g₂ : α → 𝕜'} (h₁ : f₁ =Θ[l] g₁) (h₂ : f₂ =Θ[l] g₂) : (fun x ↦ f₁ x * f₂ x) =Θ[l] fun x ↦ g₁ x * g₂ x := h₁.smul h₂ theorem IsTheta.listProd {ι : Type*} {L : List ι} {f : ι → α → 𝕜} {g : ι → α → 𝕜'} (h : ∀ i ∈ L, f i =Θ[l] g i) : (fun x ↦ (L.map (f · x)).prod) =Θ[l] (fun x ↦ (L.map (g · x)).prod) := ⟨.listProd fun i hi ↦ (h i hi).isBigO, .listProd fun i hi ↦ (h i hi).symm.isBigO⟩ theorem IsTheta.multisetProd {ι : Type*} {s : Multiset ι} {f : ι → α → 𝕜} {g : ι → α → 𝕜'} (h : ∀ i ∈ s, f i =Θ[l] g i) : (fun x ↦ (s.map (f · x)).prod) =Θ[l] (fun x ↦ (s.map (g · x)).prod) := ⟨.multisetProd fun i hi ↦ (h i hi).isBigO, .multisetProd fun i hi ↦ (h i hi).symm.isBigO⟩ theorem IsTheta.finsetProd {ι : Type*} {s : Finset ι} {f : ι → α → 𝕜} {g : ι → α → 𝕜'} (h : ∀ i ∈ s, f i =Θ[l] g i) : (∏ i ∈ s, f i ·) =Θ[l] (∏ i ∈ s, g i ·) := ⟨.finsetProd fun i hi ↦ (h i hi).isBigO, .finsetProd fun i hi ↦ (h i hi).symm.isBigO⟩
theorem IsTheta.inv {f : α → 𝕜} {g : α → 𝕜'} (h : f =Θ[l] g) : (fun x ↦ (f x)⁻¹) =Θ[l] fun x ↦ (g x)⁻¹ := ⟨h.2.inv_rev h.1.eq_zero_imp, h.1.inv_rev h.2.eq_zero_imp⟩
Mathlib/Analysis/Asymptotics/Theta.lean
219
221
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Eric Wieser -/ import Mathlib.Data.Fin.Tuple.Basic /-! # Matrix and vector notation This file defines notation for vectors and matrices. Given `a b c d : α`, the notation allows us to write `![a, b, c, d] : Fin 4 → α`. Nesting vectors gives coefficients of a matrix, so `![![a, b], ![c, d]] : Fin 2 → Fin 2 → α`. In later files we introduce `!![a, b; c, d]` as notation for `Matrix.of ![![a, b], ![c, d]]`. ## Main definitions * `vecEmpty` is the empty vector (or `0` by `n` matrix) `![]` * `vecCons` prepends an entry to a vector, so `![a, b]` is `vecCons a (vecCons b vecEmpty)` ## Implementation notes The `simp` lemmas require that one of the arguments is of the form `vecCons _ _`. This ensures `simp` works with entries only when (some) entries are already given. In other words, this notation will only appear in the output of `simp` if it already appears in the input. ## Notations The main new notation is `![a, b]`, which gets expanded to `vecCons a (vecCons b vecEmpty)`. ## Examples Examples of usage can be found in the `MathlibTest/matrix.lean` file. -/ namespace Matrix universe u variable {α : Type u} section MatrixNotation /-- `![]` is the vector with no entries. -/ def vecEmpty : Fin 0 → α := Fin.elim0 /-- `vecCons h t` prepends an entry `h` to a vector `t`. The inverse functions are `vecHead` and `vecTail`. The notation `![a, b, ...]` expands to `vecCons a (vecCons b ...)`. -/ def vecCons {n : ℕ} (h : α) (t : Fin n → α) : Fin n.succ → α := Fin.cons h t /-- `![...]` notation is used to construct a vector `Fin n → α` using `Matrix.vecEmpty` and `Matrix.vecCons`. For instance, `![a, b, c] : Fin 3` is syntax for `vecCons a (vecCons b (vecCons c vecEmpty))`. Note that this should not be used as syntax for `Matrix` as it generates a term with the wrong type. The `!![a, b; c, d]` syntax (provided by `Matrix.matrixNotation`) should be used instead. -/ syntax (name := vecNotation) "![" term,* "]" : term macro_rules | `(![$term:term, $terms:term,*]) => `(vecCons $term ![$terms,*]) | `(![$term:term]) => `(vecCons $term ![]) | `(![]) => `(vecEmpty) /-- Unexpander for the `![x, y, ...]` notation. -/ @[app_unexpander vecCons] def vecConsUnexpander : Lean.PrettyPrinter.Unexpander | `($_ $term ![$term2, $terms,*]) => `(![$term, $term2, $terms,*]) | `($_ $term ![$term2]) => `(![$term, $term2]) | `($_ $term ![]) => `(![$term]) | _ => throw () /-- Unexpander for the `![]` notation. -/ @[app_unexpander vecEmpty] def vecEmptyUnexpander : Lean.PrettyPrinter.Unexpander | `($_:ident) => `(![]) | _ => throw () /-- `vecHead v` gives the first entry of the vector `v` -/ def vecHead {n : ℕ} (v : Fin n.succ → α) : α := v 0 /-- `vecTail v` gives a vector consisting of all entries of `v` except the first -/ def vecTail {n : ℕ} (v : Fin n.succ → α) : Fin n → α := v ∘ Fin.succ variable {m n : ℕ} /-- Use `![...]` notation for displaying a vector `Fin n → α`, for example: ``` #eval ![1, 2] + ![3, 4] -- ![4, 6] ``` -/ instance _root_.PiFin.hasRepr [Repr α] : Repr (Fin n → α) where reprPrec f _ := Std.Format.bracket "![" (Std.Format.joinSep ((List.finRange n).map fun n => repr (f n)) ("," ++ Std.Format.line)) "]" end MatrixNotation variable {m n o : ℕ} theorem empty_eq (v : Fin 0 → α) : v = ![] := Subsingleton.elim _ _ section Val @[simp] theorem head_fin_const (a : α) : (vecHead fun _ : Fin (n + 1) => a) = a := rfl @[simp] theorem cons_val_zero (x : α) (u : Fin m → α) : vecCons x u 0 = x := rfl theorem cons_val_zero' (h : 0 < m.succ) (x : α) (u : Fin m → α) : vecCons x u ⟨0, h⟩ = x := rfl @[simp] theorem cons_val_succ (x : α) (u : Fin m → α) (i : Fin m) : vecCons x u i.succ = u i := by simp [vecCons] @[simp] theorem cons_val_succ' {i : ℕ} (h : i.succ < m.succ) (x : α) (u : Fin m → α) : vecCons x u ⟨i.succ, h⟩ = u ⟨i, Nat.lt_of_succ_lt_succ h⟩ := by simp only [vecCons, Fin.cons, Fin.cases_succ'] section simprocs open Lean Qq /-- Parses a chain of `Matrix.vecCons` calls into elements, leaving everything else in the tail. `let ⟨xs, tailn, tail⟩ ← matchVecConsPrefix n e` decomposes `e : Fin n → _` in the form `vecCons x₀ <| ... <| vecCons xₙ <| tail` where `tail : Fin tailn → _`. -/ partial def matchVecConsPrefix (n : Q(Nat)) (e : Expr) : MetaM <| List Expr × Q(Nat) × Expr := do match_expr ← Meta.whnfR e with | Matrix.vecCons _ n x xs => do let (elems, n', tail) ← matchVecConsPrefix n xs return (x :: elems, n', tail) | _ => return ([], n, e) open Qq in /-- A simproc that handles terms of the form `Matrix.vecCons a f i` where `i` is a numeric literal. In practice, this is most effective at handling `![a, b, c] i`-style terms. -/ dsimproc cons_val (Matrix.vecCons _ _ _) := fun e => do let_expr Matrix.vecCons α en x xs' ei := ← Meta.whnfR e | return .continue let some i := ei.int? | return .continue let (xs, etailn, tail) ← matchVecConsPrefix en xs' let xs := x :: xs -- Determine if the tail is a numeral or only an offset. let (tailn, variadic, etailn) ← do let etailn_whnf : Q(ℕ) ← Meta.whnfD etailn if let Expr.lit (.natVal length) := etailn_whnf then pure (length, false, q(OfNat.ofNat $etailn_whnf)) else if let .some ((base : Q(ℕ)), offset) ← (Meta.isOffset? etailn_whnf).run then let offset_e : Q(ℕ) := mkNatLit offset pure (offset, true, q($base + $offset)) else pure (0, true, etailn) -- Wrap the index if possible, and abort if not let wrapped_i ← if variadic then -- can't wrap as we don't know the length unless 0 ≤ i ∧ i < xs.length + tailn do return .continue pure i.toNat else pure (i % (xs.length + tailn)).toNat if h : wrapped_i < xs.length then return .continue xs[wrapped_i] else -- Within the `tail` let _ ← synthInstanceQ q(NeZero $etailn) have i_lit : Q(ℕ) := mkRawNatLit (wrapped_i - xs.length) return .continue (.some <| .app tail q(OfNat.ofNat $i_lit : Fin $etailn)) end simprocs @[simp] theorem head_cons (x : α) (u : Fin m → α) : vecHead (vecCons x u) = x := rfl @[simp] theorem tail_cons (x : α) (u : Fin m → α) : vecTail (vecCons x u) = u := by ext simp [vecTail] theorem empty_val' {n' : Type*} (j : n') : (fun i => (![] : Fin 0 → n' → α) i j) = ![] := empty_eq _ @[simp] theorem cons_head_tail (u : Fin m.succ → α) : vecCons (vecHead u) (vecTail u) = u := Fin.cons_self_tail _ @[simp] theorem range_cons (x : α) (u : Fin n → α) : Set.range (vecCons x u) = {x} ∪ Set.range u := Set.ext fun y => by simp [Fin.exists_fin_succ, eq_comm] @[simp] theorem range_empty (u : Fin 0 → α) : Set.range u = ∅ := Set.range_eq_empty _ theorem range_cons_empty (x : α) (u : Fin 0 → α) : Set.range (Matrix.vecCons x u) = {x} := by rw [range_cons, range_empty, Set.union_empty] -- simp can prove this (up to commutativity) theorem range_cons_cons_empty (x y : α) (u : Fin 0 → α) : Set.range (vecCons x <| vecCons y u) = {x, y} := by rw [range_cons, range_cons_empty, Set.singleton_union] theorem vecCons_const (a : α) : (vecCons a fun _ : Fin n => a) = fun _ => a := funext <| Fin.forall_iff_succ.2 ⟨rfl, cons_val_succ _ _⟩ theorem vec_single_eq_const (a : α) : ![a] = fun _ => a := let _ : Unique (Fin 1) := inferInstance funext <| Unique.forall_iff.2 rfl /-- `![a, b, ...] 1` is equal to `b`. The simplifier needs a special lemma for length `≥ 2`, in addition to `cons_val_succ`, because `1 : Fin 1 = 0 : Fin 1`. -/ @[simp] theorem cons_val_one (x : α) (u : Fin m.succ → α) : vecCons x u 1 = u 0 := rfl theorem cons_val_two (x : α) (u : Fin m.succ.succ → α) : vecCons x u 2 = vecHead (vecTail u) := rfl lemma cons_val_three (x : α) (u : Fin m.succ.succ.succ → α) : vecCons x u 3 = vecHead (vecTail (vecTail u)) := rfl lemma cons_val_four (x : α) (u : Fin m.succ.succ.succ.succ → α) : vecCons x u 4 = vecHead (vecTail (vecTail (vecTail u))) := rfl @[simp] theorem cons_val_fin_one (x : α) (u : Fin 0 → α) : ∀ (i : Fin 1), vecCons x u i = x := by rw [Fin.forall_fin_one] rfl theorem cons_fin_one (x : α) (u : Fin 0 → α) : vecCons x u = fun _ => x := funext (cons_val_fin_one x u) open Lean Qq in /-- `mkVecLiteralQ ![x, y, z]` produces the term `q(![$x, $y, $z])`. -/ def _root_.PiFin.mkLiteralQ {u : Level} {α : Q(Type u)} {n : ℕ} (elems : Fin n → Q($α)) : Q(Fin $n → $α) := loop 0 (Nat.zero_le _) q(vecEmpty) where loop (i : ℕ) (hi : i ≤ n) (rest : Q(Fin $i → $α)) : let i' : Nat := i + 1; Q(Fin $(i') → $α) := if h : i < n then loop (i + 1) h q(vecCons $(elems (Fin.rev ⟨i, h⟩)) $rest) else rest attribute [nolint docBlame] _root_.PiFin.mkLiteralQ.loop open Lean Qq in protected instance _root_.PiFin.toExpr [ToLevel.{u}] [ToExpr α] (n : ℕ) : ToExpr (Fin n → α) := have lu := toLevel.{u} have eα : Q(Type $lu) := toTypeExpr α let toTypeExpr := q(Fin $n → $eα) { toTypeExpr, toExpr v := PiFin.mkLiteralQ fun i => show Q($eα) from toExpr (v i) } /-! ### `bit0` and `bit1` indices The following definitions and `simp` lemmas are used to allow numeral-indexed element of a vector given with matrix notation to be extracted by `simp` in Lean 3 (even when the numeral is larger than the number of elements in the vector, which is taken modulo that number of elements by virtue of the semantics of `bit0` and `bit1` and of addition on `Fin n`). -/ /-- `vecAppend ho u v` appends two vectors of lengths `m` and `n` to produce one of length `o = m + n`. This is a variant of `Fin.append` with an additional `ho` argument, which provides control of definitional equality for the vector length. This turns out to be helpful when providing simp lemmas to reduce `![a, b, c] n`, and also means that `vecAppend ho u v 0` is valid. `Fin.append u v 0` is not valid in this case because there is no `Zero (Fin (m + n))` instance. -/ def vecAppend {α : Type*} {o : ℕ} (ho : o = m + n) (u : Fin m → α) (v : Fin n → α) : Fin o → α := Fin.append u v ∘ Fin.cast ho theorem vecAppend_eq_ite {α : Type*} {o : ℕ} (ho : o = m + n) (u : Fin m → α) (v : Fin n → α) : vecAppend ho u v = fun i : Fin o => if h : (i : ℕ) < m then u ⟨i, h⟩ else v ⟨(i : ℕ) - m, by omega⟩ := by ext i rw [vecAppend, Fin.append, Function.comp_apply, Fin.addCases] congr with hi simp only [eq_rec_constant] rfl @[simp] theorem vecAppend_apply_zero {α : Type*} {o : ℕ} (ho : o + 1 = m + 1 + n) (u : Fin (m + 1) → α) (v : Fin n → α) : vecAppend ho u v 0 = u 0 := dif_pos _ @[simp] theorem empty_vecAppend (v : Fin n → α) : vecAppend n.zero_add.symm ![] v = v := by ext simp [vecAppend_eq_ite] @[simp] theorem cons_vecAppend (ho : o + 1 = m + 1 + n) (x : α) (u : Fin m → α) (v : Fin n → α) : vecAppend ho (vecCons x u) v = vecCons x (vecAppend (by omega) u v) := by ext i simp_rw [vecAppend_eq_ite] split_ifs with h · rcases i with ⟨⟨⟩ | i, hi⟩ · simp · simp only [Nat.add_lt_add_iff_right, Fin.val_mk] at h simp [h] · rcases i with ⟨⟨⟩ | i, hi⟩ · simp at h · rw [not_lt, Fin.val_mk, Nat.add_le_add_iff_right] at h simp [h, not_lt.2 h] /-- `vecAlt0 v` gives a vector with half the length of `v`, with only alternate elements (even-numbered). -/ def vecAlt0 (hm : m = n + n) (v : Fin m → α) (k : Fin n) : α := v ⟨(k : ℕ) + k, by omega⟩ /-- `vecAlt1 v` gives a vector with half the length of `v`, with only alternate elements (odd-numbered). -/ def vecAlt1 (hm : m = n + n) (v : Fin m → α) (k : Fin n) : α := v ⟨(k : ℕ) + k + 1, hm.symm ▸ Nat.add_succ_lt_add k.2 k.2⟩ section bits theorem vecAlt0_vecAppend (v : Fin n → α) : vecAlt0 rfl (vecAppend rfl v v) = v ∘ (fun n ↦ n + n) := by ext i simp_rw [Function.comp, vecAlt0, vecAppend_eq_ite] split_ifs with h <;> congr · rw [Fin.val_mk] at h exact (Nat.mod_eq_of_lt h).symm · rw [Fin.val_mk, not_lt] at h simp only [Fin.ext_iff, Fin.val_add, Fin.val_mk, Nat.mod_eq_sub_mod h] refine (Nat.mod_eq_of_lt ?_).symm
omega theorem vecAlt1_vecAppend (v : Fin (n + 1) → α) : vecAlt1 rfl (vecAppend rfl v v) = v ∘ (fun n ↦ (n + n) + 1) := by ext i simp_rw [Function.comp, vecAlt1, vecAppend_eq_ite] cases n with | zero => obtain ⟨i, hi⟩ := i simp only [Nat.zero_add, Nat.lt_one_iff] at hi; subst i; rfl | succ n => split_ifs with h <;> congr · simp [Nat.mod_eq_of_lt, h] · rw [Fin.val_mk, not_lt] at h simp only [Fin.ext_iff, Fin.val_add, Fin.val_mk, Nat.mod_add_mod, Fin.val_one,
Mathlib/Data/Fin/VecNotation.lean
350
364
/- Copyright (c) 2024 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.NumberTheory.LSeries.AbstractFuncEq import Mathlib.NumberTheory.ModularForms.JacobiTheta.Bounds import Mathlib.NumberTheory.LSeries.MellinEqDirichlet import Mathlib.NumberTheory.LSeries.Basic /-! # Odd Hurwitz zeta functions In this file we study the functions on `ℂ` which are the analytic continuation of the following series (convergent for `1 < re s`), where `a ∈ ℝ` is a parameter: `hurwitzZetaOdd a s = 1 / 2 * ∑' n : ℤ, sgn (n + a) / |n + a| ^ s` and `sinZeta a s = ∑' n : ℕ, sin (2 * π * a * n) / n ^ s`. The term for `n = -a` in the first sum is understood as 0 if `a` is an integer, as is the term for `n = 0` in the second sum (for all `a`). Note that these functions are differentiable everywhere, unlike their even counterparts which have poles. Of course, we cannot *define* these functions by the above formulae (since existence of the analytic continuation is not at all obvious); we in fact construct them as Mellin transforms of various versions of the Jacobi theta function. ## Main definitions and theorems * `completedHurwitzZetaOdd`: the completed Hurwitz zeta function * `completedSinZeta`: the completed cosine zeta function * `differentiable_completedHurwitzZetaOdd` and `differentiable_completedSinZeta`: differentiability on `ℂ` * `completedHurwitzZetaOdd_one_sub`: the functional equation `completedHurwitzZetaOdd a (1 - s) = completedSinZeta a s` * `hasSum_int_hurwitzZetaOdd` and `hasSum_nat_sinZeta`: relation between the zeta functions and corresponding Dirichlet series for `1 < re s` -/ noncomputable section open Complex hiding abs_of_nonneg open CharZero Filter Topology Asymptotics Real Set MeasureTheory open scoped ComplexConjugate namespace HurwitzZeta section kernel_defs /-! ## Definitions and elementary properties of kernels -/ /-- Variant of `jacobiTheta₂'` which we introduce to simplify some formulae. -/ def jacobiTheta₂'' (z τ : ℂ) : ℂ := cexp (π * I * z ^ 2 * τ) * (jacobiTheta₂' (z * τ) τ / (2 * π * I) + z * jacobiTheta₂ (z * τ) τ) lemma jacobiTheta₂''_conj (z τ : ℂ) : conj (jacobiTheta₂'' z τ) = jacobiTheta₂'' (conj z) (-conj τ) := by simp [jacobiTheta₂'', jacobiTheta₂'_conj, jacobiTheta₂_conj, ← exp_conj, map_ofNat, div_neg, neg_div, jacobiTheta₂'_neg_left] /-- Restatement of `jacobiTheta₂'_add_left'`: the function `jacobiTheta₂''` is 1-periodic in `z`. -/
lemma jacobiTheta₂''_add_left (z τ : ℂ) : jacobiTheta₂'' (z + 1) τ = jacobiTheta₂'' z τ := by simp only [jacobiTheta₂'', add_mul z 1, one_mul, jacobiTheta₂'_add_left', jacobiTheta₂_add_left'] generalize jacobiTheta₂ (z * τ) τ = J generalize jacobiTheta₂' (z * τ) τ = J' -- clear denominator simp_rw [div_add' _ _ _ two_pi_I_ne_zero, ← mul_div_assoc] refine congr_arg (· / (2 * π * I)) ?_ -- get all exponential terms to left rw [mul_left_comm _ (cexp _), ← mul_add, mul_assoc (cexp _), ← mul_add, ← mul_assoc (cexp _), ← Complex.exp_add] congrm (cexp ?_ * ?_) <;> ring
Mathlib/NumberTheory/LSeries/HurwitzZetaOdd.lean
66
77
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Sébastien Gouëzel, Rémy Degenne, David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.Pow.Complex import Qq /-! # Power function on `ℝ` We construct the power functions `x ^ y`, where `x` and `y` are real numbers. -/ noncomputable section open Real ComplexConjugate Finset Set /- ## Definitions -/ namespace Real variable {x y z : ℝ} /-- The real power function `x ^ y`, defined as the real part of the complex power function. For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`, one sets `0 ^ 0=1` and `0 ^ y=0` for `y ≠ 0`. For `x < 0`, the definition is somewhat arbitrary as it depends on the choice of a complex determination of the logarithm. With our conventions, it is equal to `exp (y log x) cos (π y)`. -/ noncomputable def rpow (x y : ℝ) := ((x : ℂ) ^ (y : ℂ)).re noncomputable instance : Pow ℝ ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x y : ℝ) : rpow x y = x ^ y := rfl theorem rpow_def (x y : ℝ) : x ^ y = ((x : ℂ) ^ (y : ℂ)).re := rfl theorem rpow_def_of_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) := by simp only [rpow_def, Complex.cpow_def]; split_ifs <;> simp_all [(Complex.ofReal_log hx).symm, -Complex.ofReal_mul, (Complex.ofReal_mul _ _).symm, Complex.exp_ofReal_re, Complex.ofReal_eq_zero] theorem rpow_def_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : x ^ y = exp (log x * y) := by rw [rpow_def_of_nonneg (le_of_lt hx), if_neg (ne_of_gt hx)] theorem exp_mul (x y : ℝ) : exp (x * y) = exp x ^ y := by rw [rpow_def_of_pos (exp_pos _), log_exp] @[simp, norm_cast] theorem rpow_intCast (x : ℝ) (n : ℤ) : x ^ (n : ℝ) = x ^ n := by simp only [rpow_def, ← Complex.ofReal_zpow, Complex.cpow_intCast, Complex.ofReal_intCast, Complex.ofReal_re] @[simp, norm_cast] theorem rpow_natCast (x : ℝ) (n : ℕ) : x ^ (n : ℝ) = x ^ n := by simpa using rpow_intCast x n @[simp] theorem exp_one_rpow (x : ℝ) : exp 1 ^ x = exp x := by rw [← exp_mul, one_mul] @[simp] lemma exp_one_pow (n : ℕ) : exp 1 ^ n = exp n := by rw [← rpow_natCast, exp_one_rpow] theorem rpow_eq_zero_iff_of_nonneg (hx : 0 ≤ x) : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 := by simp only [rpow_def_of_nonneg hx] split_ifs <;> simp [*, exp_ne_zero] @[simp] lemma rpow_eq_zero (hx : 0 ≤ x) (hy : y ≠ 0) : x ^ y = 0 ↔ x = 0 := by simp [rpow_eq_zero_iff_of_nonneg, *] @[simp] lemma rpow_ne_zero (hx : 0 ≤ x) (hy : y ≠ 0) : x ^ y ≠ 0 ↔ x ≠ 0 := Real.rpow_eq_zero hx hy |>.not open Real theorem rpow_def_of_neg {x : ℝ} (hx : x < 0) (y : ℝ) : x ^ y = exp (log x * y) * cos (y * π) := by rw [rpow_def, Complex.cpow_def, if_neg] · have : Complex.log x * y = ↑(log (-x) * y) + ↑(y * π) * Complex.I := by simp only [Complex.log, Complex.norm_real, norm_eq_abs, abs_of_neg hx, log_neg_eq_log, Complex.arg_ofReal_of_neg hx, Complex.ofReal_mul] ring rw [this, Complex.exp_add_mul_I, ← Complex.ofReal_exp, ← Complex.ofReal_cos, ← Complex.ofReal_sin, mul_add, ← Complex.ofReal_mul, ← mul_assoc, ← Complex.ofReal_mul, Complex.add_re, Complex.ofReal_re, Complex.mul_re, Complex.I_re, Complex.ofReal_im, Real.log_neg_eq_log] ring · rw [Complex.ofReal_eq_zero] exact ne_of_lt hx theorem rpow_def_of_nonpos {x : ℝ} (hx : x ≤ 0) (y : ℝ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) * cos (y * π) := by split_ifs with h <;> simp [rpow_def, *]; exact rpow_def_of_neg (lt_of_le_of_ne hx h) _ @[bound] theorem rpow_pos_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : 0 < x ^ y := by rw [rpow_def_of_pos hx]; apply exp_pos @[simp] theorem rpow_zero (x : ℝ) : x ^ (0 : ℝ) = 1 := by simp [rpow_def] theorem rpow_zero_pos (x : ℝ) : 0 < x ^ (0 : ℝ) := by simp @[simp] theorem zero_rpow {x : ℝ} (h : x ≠ 0) : (0 : ℝ) ^ x = 0 := by simp [rpow_def, *] theorem zero_rpow_eq_iff {x : ℝ} {a : ℝ} : 0 ^ x = a ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by constructor · intro hyp simp only [rpow_def, Complex.ofReal_zero] at hyp by_cases h : x = 0 · subst h simp only [Complex.one_re, Complex.ofReal_zero, Complex.cpow_zero] at hyp exact Or.inr ⟨rfl, hyp.symm⟩ · rw [Complex.zero_cpow (Complex.ofReal_ne_zero.mpr h)] at hyp exact Or.inl ⟨h, hyp.symm⟩ · rintro (⟨h, rfl⟩ | ⟨rfl, rfl⟩) · exact zero_rpow h · exact rpow_zero _ theorem eq_zero_rpow_iff {x : ℝ} {a : ℝ} : a = 0 ^ x ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by rw [← zero_rpow_eq_iff, eq_comm] @[simp] theorem rpow_one (x : ℝ) : x ^ (1 : ℝ) = x := by simp [rpow_def] @[simp] theorem one_rpow (x : ℝ) : (1 : ℝ) ^ x = 1 := by simp [rpow_def] theorem zero_rpow_le_one (x : ℝ) : (0 : ℝ) ^ x ≤ 1 := by by_cases h : x = 0 <;> simp [h, zero_le_one] theorem zero_rpow_nonneg (x : ℝ) : 0 ≤ (0 : ℝ) ^ x := by by_cases h : x = 0 <;> simp [h, zero_le_one] @[bound] theorem rpow_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : 0 ≤ x ^ y := by rw [rpow_def_of_nonneg hx]; split_ifs <;> simp only [zero_le_one, le_refl, le_of_lt (exp_pos _)] theorem abs_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≤ x) : |x ^ y| = |x| ^ y := by have h_rpow_nonneg : 0 ≤ x ^ y := Real.rpow_nonneg hx_nonneg _ rw [abs_eq_self.mpr hx_nonneg, abs_eq_self.mpr h_rpow_nonneg] @[bound] theorem abs_rpow_le_abs_rpow (x y : ℝ) : |x ^ y| ≤ |x| ^ y := by rcases le_or_lt 0 x with hx | hx · rw [abs_rpow_of_nonneg hx] · rw [abs_of_neg hx, rpow_def_of_neg hx, rpow_def_of_pos (neg_pos.2 hx), log_neg_eq_log, abs_mul, abs_of_pos (exp_pos _)] exact mul_le_of_le_one_right (exp_pos _).le (abs_cos_le_one _) theorem abs_rpow_le_exp_log_mul (x y : ℝ) : |x ^ y| ≤ exp (log x * y) := by refine (abs_rpow_le_abs_rpow x y).trans ?_ by_cases hx : x = 0 · by_cases hy : y = 0 <;> simp [hx, hy, zero_le_one] · rw [rpow_def_of_pos (abs_pos.2 hx), log_abs] lemma rpow_inv_log (hx₀ : 0 < x) (hx₁ : x ≠ 1) : x ^ (log x)⁻¹ = exp 1 := by rw [rpow_def_of_pos hx₀, mul_inv_cancel₀] exact log_ne_zero.2 ⟨hx₀.ne', hx₁, (hx₀.trans' <| by norm_num).ne'⟩ /-- See `Real.rpow_inv_log` for the equality when `x ≠ 1` is strictly positive. -/ lemma rpow_inv_log_le_exp_one : x ^ (log x)⁻¹ ≤ exp 1 := by calc _ ≤ |x ^ (log x)⁻¹| := le_abs_self _ _ ≤ |x| ^ (log x)⁻¹ := abs_rpow_le_abs_rpow .. rw [← log_abs] obtain hx | hx := (abs_nonneg x).eq_or_gt · simp [hx] · rw [rpow_def_of_pos hx] gcongr exact mul_inv_le_one theorem norm_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≤ x) : ‖x ^ y‖ = ‖x‖ ^ y := by simp_rw [Real.norm_eq_abs] exact abs_rpow_of_nonneg hx_nonneg variable {w x y z : ℝ} theorem rpow_add (hx : 0 < x) (y z : ℝ) : x ^ (y + z) = x ^ y * x ^ z := by simp only [rpow_def_of_pos hx, mul_add, exp_add] theorem rpow_add' (hx : 0 ≤ x) (h : y + z ≠ 0) : x ^ (y + z) = x ^ y * x ^ z := by rcases hx.eq_or_lt with (rfl | pos) · rw [zero_rpow h, zero_eq_mul] have : y ≠ 0 ∨ z ≠ 0 := not_and_or.1 fun ⟨hy, hz⟩ => h <| hy.symm ▸ hz.symm ▸ zero_add 0 exact this.imp zero_rpow zero_rpow · exact rpow_add pos _ _ /-- Variant of `Real.rpow_add'` that avoids having to prove `y + z = w` twice. -/ lemma rpow_of_add_eq (hx : 0 ≤ x) (hw : w ≠ 0) (h : y + z = w) : x ^ w = x ^ y * x ^ z := by rw [← h, rpow_add' hx]; rwa [h] theorem rpow_add_of_nonneg (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 ≤ z) : x ^ (y + z) = x ^ y * x ^ z := by rcases hy.eq_or_lt with (rfl | hy) · rw [zero_add, rpow_zero, one_mul] exact rpow_add' hx (ne_of_gt <| add_pos_of_pos_of_nonneg hy hz) /-- For `0 ≤ x`, the only problematic case in the equality `x ^ y * x ^ z = x ^ (y + z)` is for `x = 0` and `y + z = 0`, where the right hand side is `1` while the left hand side can vanish. The inequality is always true, though, and given in this lemma. -/ theorem le_rpow_add {x : ℝ} (hx : 0 ≤ x) (y z : ℝ) : x ^ y * x ^ z ≤ x ^ (y + z) := by rcases le_iff_eq_or_lt.1 hx with (H | pos) · by_cases h : y + z = 0 · simp only [H.symm, h, rpow_zero] calc (0 : ℝ) ^ y * 0 ^ z ≤ 1 * 1 := mul_le_mul (zero_rpow_le_one y) (zero_rpow_le_one z) (zero_rpow_nonneg z) zero_le_one _ = 1 := by simp · simp [rpow_add', ← H, h] · simp [rpow_add pos] theorem rpow_sum_of_pos {ι : Type*} {a : ℝ} (ha : 0 < a) (f : ι → ℝ) (s : Finset ι) : (a ^ ∑ x ∈ s, f x) = ∏ x ∈ s, a ^ f x := map_sum (⟨⟨fun (x : ℝ) => (a ^ x : ℝ), rpow_zero a⟩, rpow_add ha⟩ : ℝ →+ (Additive ℝ)) f s theorem rpow_sum_of_nonneg {ι : Type*} {a : ℝ} (ha : 0 ≤ a) {s : Finset ι} {f : ι → ℝ} (h : ∀ x ∈ s, 0 ≤ f x) : (a ^ ∑ x ∈ s, f x) = ∏ x ∈ s, a ^ f x := by induction' s using Finset.cons_induction with i s hi ihs · rw [sum_empty, Finset.prod_empty, rpow_zero] · rw [forall_mem_cons] at h rw [sum_cons, prod_cons, ← ihs h.2, rpow_add_of_nonneg ha h.1 (sum_nonneg h.2)] theorem rpow_neg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ := by simp only [rpow_def_of_nonneg hx]; split_ifs <;> simp_all [exp_neg] theorem rpow_sub {x : ℝ} (hx : 0 < x) (y z : ℝ) : x ^ (y - z) = x ^ y / x ^ z := by simp only [sub_eq_add_neg, rpow_add hx, rpow_neg (le_of_lt hx), div_eq_mul_inv] theorem rpow_sub' {x : ℝ} (hx : 0 ≤ x) {y z : ℝ} (h : y - z ≠ 0) : x ^ (y - z) = x ^ y / x ^ z := by simp only [sub_eq_add_neg] at h ⊢ simp only [rpow_add' hx h, rpow_neg hx, div_eq_mul_inv] protected theorem _root_.HasCompactSupport.rpow_const {α : Type*} [TopologicalSpace α] {f : α → ℝ} (hf : HasCompactSupport f) {r : ℝ} (hr : r ≠ 0) : HasCompactSupport (fun x ↦ f x ^ r) := hf.comp_left (g := (· ^ r)) (Real.zero_rpow hr) end Real /-! ## Comparing real and complex powers -/ namespace Complex theorem ofReal_cpow {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : ((x ^ y : ℝ) : ℂ) = (x : ℂ) ^ (y : ℂ) := by simp only [Real.rpow_def_of_nonneg hx, Complex.cpow_def, ofReal_eq_zero]; split_ifs <;> simp [Complex.ofReal_log hx] theorem ofReal_cpow_of_nonpos {x : ℝ} (hx : x ≤ 0) (y : ℂ) : (x : ℂ) ^ y = (-x : ℂ) ^ y * exp (π * I * y) := by rcases hx.eq_or_lt with (rfl | hlt) · rcases eq_or_ne y 0 with (rfl | hy) <;> simp [*] have hne : (x : ℂ) ≠ 0 := ofReal_ne_zero.mpr hlt.ne rw [cpow_def_of_ne_zero hne, cpow_def_of_ne_zero (neg_ne_zero.2 hne), ← exp_add, ← add_mul, log, log, norm_neg, arg_ofReal_of_neg hlt, ← ofReal_neg, arg_ofReal_of_nonneg (neg_nonneg.2 hx), ofReal_zero, zero_mul, add_zero] lemma cpow_ofReal (x : ℂ) (y : ℝ) : x ^ (y : ℂ) = ↑(‖x‖ ^ y) * (Real.cos (arg x * y) + Real.sin (arg x * y) * I) := by rcases eq_or_ne x 0 with rfl | hx · simp [ofReal_cpow le_rfl] · rw [cpow_def_of_ne_zero hx, exp_eq_exp_re_mul_sin_add_cos, mul_comm (log x)] norm_cast rw [re_ofReal_mul, im_ofReal_mul, log_re, log_im, mul_comm y, mul_comm y, Real.exp_mul, Real.exp_log] rwa [norm_pos_iff] lemma cpow_ofReal_re (x : ℂ) (y : ℝ) : (x ^ (y : ℂ)).re = ‖x‖ ^ y * Real.cos (arg x * y) := by rw [cpow_ofReal]; generalize arg x * y = z; simp [Real.cos] lemma cpow_ofReal_im (x : ℂ) (y : ℝ) : (x ^ (y : ℂ)).im = ‖x‖ ^ y * Real.sin (arg x * y) := by rw [cpow_ofReal]; generalize arg x * y = z; simp [Real.sin] theorem norm_cpow_of_ne_zero {z : ℂ} (hz : z ≠ 0) (w : ℂ) : ‖z ^ w‖ = ‖z‖ ^ w.re / Real.exp (arg z * im w) := by rw [cpow_def_of_ne_zero hz, norm_exp, mul_re, log_re, log_im, Real.exp_sub, Real.rpow_def_of_pos (norm_pos_iff.mpr hz)] theorem norm_cpow_of_imp {z w : ℂ} (h : z = 0 → w.re = 0 → w = 0) : ‖z ^ w‖ = ‖z‖ ^ w.re / Real.exp (arg z * im w) := by rcases ne_or_eq z 0 with (hz | rfl) <;> [exact norm_cpow_of_ne_zero hz w; rw [norm_zero]] rcases eq_or_ne w.re 0 with hw | hw · simp [hw, h rfl hw] · rw [Real.zero_rpow hw, zero_div, zero_cpow, norm_zero] exact ne_of_apply_ne re hw theorem norm_cpow_le (z w : ℂ) : ‖z ^ w‖ ≤ ‖z‖ ^ w.re / Real.exp (arg z * im w) := by by_cases h : z = 0 → w.re = 0 → w = 0 · exact (norm_cpow_of_imp h).le · push_neg at h simp [h] @[simp] theorem norm_cpow_real (x : ℂ) (y : ℝ) : ‖x ^ (y : ℂ)‖ = ‖x‖ ^ y := by rw [norm_cpow_of_imp] <;> simp @[simp] theorem norm_cpow_inv_nat (x : ℂ) (n : ℕ) : ‖x ^ (n⁻¹ : ℂ)‖ = ‖x‖ ^ (n⁻¹ : ℝ) := by rw [← norm_cpow_real]; simp theorem norm_cpow_eq_rpow_re_of_pos {x : ℝ} (hx : 0 < x) (y : ℂ) : ‖(x : ℂ) ^ y‖ = x ^ y.re := by rw [norm_cpow_of_ne_zero (ofReal_ne_zero.mpr hx.ne'), arg_ofReal_of_nonneg hx.le, zero_mul, Real.exp_zero, div_one, Complex.norm_of_nonneg hx.le] theorem norm_cpow_eq_rpow_re_of_nonneg {x : ℝ} (hx : 0 ≤ x) {y : ℂ} (hy : re y ≠ 0) : ‖(x : ℂ) ^ y‖ = x ^ re y := by rw [norm_cpow_of_imp] <;> simp [*, arg_ofReal_of_nonneg, abs_of_nonneg] @[deprecated (since := "2025-02-17")] alias abs_cpow_of_ne_zero := norm_cpow_of_ne_zero @[deprecated (since := "2025-02-17")] alias abs_cpow_of_imp := norm_cpow_of_imp @[deprecated (since := "2025-02-17")] alias abs_cpow_le := norm_cpow_le @[deprecated (since := "2025-02-17")] alias abs_cpow_real := norm_cpow_real @[deprecated (since := "2025-02-17")] alias abs_cpow_inv_nat := norm_cpow_inv_nat @[deprecated (since := "2025-02-17")] alias abs_cpow_eq_rpow_re_of_pos := norm_cpow_eq_rpow_re_of_pos @[deprecated (since := "2025-02-17")] alias abs_cpow_eq_rpow_re_of_nonneg := norm_cpow_eq_rpow_re_of_nonneg open Filter in lemma norm_ofReal_cpow_eventually_eq_atTop (c : ℂ) : (fun t : ℝ ↦ ‖(t : ℂ) ^ c‖) =ᶠ[atTop] fun t ↦ t ^ c.re := by filter_upwards [eventually_gt_atTop 0] with t ht rw [norm_cpow_eq_rpow_re_of_pos ht] lemma norm_natCast_cpow_of_re_ne_zero (n : ℕ) {s : ℂ} (hs : s.re ≠ 0) : ‖(n : ℂ) ^ s‖ = (n : ℝ) ^ (s.re) := by rw [← ofReal_natCast, norm_cpow_eq_rpow_re_of_nonneg n.cast_nonneg hs] lemma norm_natCast_cpow_of_pos {n : ℕ} (hn : 0 < n) (s : ℂ) : ‖(n : ℂ) ^ s‖ = (n : ℝ) ^ (s.re) := by rw [← ofReal_natCast, norm_cpow_eq_rpow_re_of_pos (Nat.cast_pos.mpr hn) _] lemma norm_natCast_cpow_pos_of_pos {n : ℕ} (hn : 0 < n) (s : ℂ) : 0 < ‖(n : ℂ) ^ s‖ := (norm_natCast_cpow_of_pos hn _).symm ▸ Real.rpow_pos_of_pos (Nat.cast_pos.mpr hn) _ theorem cpow_mul_ofReal_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) (z : ℂ) : (x : ℂ) ^ (↑y * z) = (↑(x ^ y) : ℂ) ^ z := by rw [cpow_mul, ofReal_cpow hx] · rw [← ofReal_log hx, ← ofReal_mul, ofReal_im, neg_lt_zero]; exact Real.pi_pos · rw [← ofReal_log hx, ← ofReal_mul, ofReal_im]; exact Real.pi_pos.le end Complex /-! ### Positivity extension -/
namespace Mathlib.Meta.Positivity open Lean Meta Qq
Mathlib/Analysis/SpecialFunctions/Pow/Real.lean
352
354
/- Copyright (c) 2023 Frédéric Dupuis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Frédéric Dupuis -/ import Mathlib.Analysis.Convex.SpecificFunctions.Basic import Mathlib.Analysis.SpecialFunctions.Pow.NNReal /-! # Convexity properties of `rpow` We prove basic convexity properties of the `rpow` function. The proofs are elementary and do not require calculus, and as such this file has only moderate dependencies. ## Main declarations * `NNReal.strictConcaveOn_rpow`, `Real.strictConcaveOn_rpow`: strict concavity of `fun x ↦ x ^ p` for p ∈ (0,1) * `NNReal.concaveOn_rpow`, `Real.concaveOn_rpow`: concavity of `fun x ↦ x ^ p` for p ∈ [0,1] Note that convexity for `p > 1` can be found in `Analysis.Convex.SpecificFunctions.Basic`, which requires slightly less imports. ## TODO * Prove convexity for negative powers. -/ open Set namespace NNReal lemma strictConcaveOn_rpow {p : ℝ} (hp₀ : 0 < p) (hp₁ : p < 1) : StrictConcaveOn ℝ≥0 univ fun x : ℝ≥0 ↦ x ^ p := by have hp₀' : 0 < 1 / p := div_pos zero_lt_one hp₀ have hp₁' : 1 < 1 / p := by rw [one_lt_div hp₀]; exact hp₁ let f := NNReal.orderIsoRpow (1 / p) hp₀' have h₁ : StrictConvexOn ℝ≥0 univ f := by refine ⟨convex_univ, fun x _ y _ hxy a b ha hb hab => ?_⟩ exact (strictConvexOn_rpow hp₁').2 x.2 y.2 (by simp [hxy]) ha hb (by simp; norm_cast) have h₂ : ∀ x, f.symm x = x ^ p := by simp [f, NNReal.orderIsoRpow_symm_eq] refine ⟨convex_univ, fun x mx y my hxy a b ha hb hab => ?_⟩ simp only [← h₂] exact (f.strictConcaveOn_symm h₁).2 mx my hxy ha hb hab lemma concaveOn_rpow {p : ℝ} (hp₀ : 0 ≤ p) (hp₁ : p ≤ 1) : ConcaveOn ℝ≥0 univ fun x : ℝ≥0 ↦ x ^ p := by rcases eq_or_lt_of_le hp₀ with (rfl | hp₀) · simpa only [rpow_zero] using concaveOn_const (c := 1) convex_univ rcases eq_or_lt_of_le hp₁ with (rfl | hp₁) · simpa only [rpow_one] using concaveOn_id convex_univ exact (strictConcaveOn_rpow hp₀ hp₁).concaveOn
lemma strictConcaveOn_sqrt : StrictConcaveOn ℝ≥0 univ NNReal.sqrt := by have : NNReal.sqrt = fun x : ℝ≥0 ↦ x ^ (1 / (2 : ℝ)) := by ext x; exact mod_cast NNReal.sqrt_eq_rpow x rw [this] exact strictConcaveOn_rpow (by positivity) (by linarith)
Mathlib/Analysis/Convex/SpecificFunctions/Pow.lean
55
59
/- Copyright (c) 2019 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Kim Morrison -/ import Mathlib.CategoryTheory.Limits.Shapes.FiniteLimits /-! # Filtered categories A category is filtered if every finite diagram admits a cocone. We give a simple characterisation of this condition as 1. for every pair of objects there exists another object "to the right", 2. for every pair of parallel morphisms there exists a morphism to the right so the compositions are equal, and 3. there exists some object. Filtered colimits are often better behaved than arbitrary colimits. See `CategoryTheory/Limits/Types` for some details. Filtered categories are nice because colimits indexed by filtered categories tend to be easier to describe than general colimits (and more often preserved by functors). In this file we show that any functor from a finite category to a filtered category admits a cocone: * `cocone_nonempty [FinCategory J] [IsFiltered C] (F : J ⥤ C) : Nonempty (Cocone F)` More generally, for any finite collection of objects and morphisms between them in a filtered category (even if not closed under composition) there exists some object `Z` receiving maps from all of them, so that all the triangles (one edge from the finite set, two from morphisms to `Z`) commute. This formulation is often more useful in practice and is available via `sup_exists`, which takes a finset of objects, and an indexed family (indexed by source and target) of finsets of morphisms. We also prove the converse of `cocone_nonempty` as `of_cocone_nonempty`. Furthermore, we give special support for two diagram categories: The `bowtie` and the `tulip`. This is because these shapes show up in the proofs that forgetful functors of algebraic categories (e.g. `MonCat`, `CommRingCat`, ...) preserve filtered colimits. All of the above API, except for the `bowtie` and the `tulip`, is also provided for cofiltered categories. ## See also In `CategoryTheory.Limits.FilteredColimitCommutesFiniteLimit` we show that filtered colimits commute with finite limits. There is another characterization of filtered categories, namely that whenever `F : J ⥤ C` is a functor from a finite category, there is `X : C` such that `Nonempty (limit (F.op ⋙ yoneda.obj X))`. This is shown in `CategoryTheory.Limits.Filtered`. -/ open Function -- declare the `v`'s first; see `CategoryTheory.Category` for an explanation universe w v v₁ v₂ u u₁ u₂ namespace CategoryTheory variable (C : Type u) [Category.{v} C] /-- A category `IsFilteredOrEmpty` if 1. for every pair of objects there exists another object "to the right", and 2. for every pair of parallel morphisms there exists a morphism to the right so the compositions are equal. -/ class IsFilteredOrEmpty : Prop where /-- for every pair of objects there exists another object "to the right" -/ cocone_objs : ∀ X Y : C, ∃ (Z : _) (_ : X ⟶ Z) (_ : Y ⟶ Z), True /-- for every pair of parallel morphisms there exists a morphism to the right so the compositions are equal -/ cocone_maps : ∀ ⦃X Y : C⦄ (f g : X ⟶ Y), ∃ (Z : _) (h : Y ⟶ Z), f ≫ h = g ≫ h /-- A category `IsFiltered` if 1. for every pair of objects there exists another object "to the right", 2. for every pair of parallel morphisms there exists a morphism to the right so the compositions are equal, and 3. there exists some object. -/ @[stacks 002V "They also define a diagram being filtered."] class IsFiltered : Prop extends IsFilteredOrEmpty C where /-- a filtered category must be non empty -/ -- This should be an instance but it causes significant slowdown [nonempty : Nonempty C] instance (priority := 100) isFilteredOrEmpty_of_semilatticeSup (α : Type u) [SemilatticeSup α] : IsFilteredOrEmpty α where cocone_objs X Y := ⟨X ⊔ Y, homOfLE le_sup_left, homOfLE le_sup_right, trivial⟩ cocone_maps X Y f g := ⟨Y, 𝟙 _, by subsingleton⟩ instance (priority := 100) isFiltered_of_semilatticeSup_nonempty (α : Type u) [SemilatticeSup α] [Nonempty α] : IsFiltered α where instance (priority := 100) isFilteredOrEmpty_of_directed_le (α : Type u) [Preorder α] [IsDirected α (· ≤ ·)] : IsFilteredOrEmpty α where cocone_objs X Y := let ⟨Z, h1, h2⟩ := exists_ge_ge X Y ⟨Z, homOfLE h1, homOfLE h2, trivial⟩ cocone_maps X Y f g := ⟨Y, 𝟙 _, by subsingleton⟩ instance (priority := 100) isFiltered_of_directed_le_nonempty (α : Type u) [Preorder α] [IsDirected α (· ≤ ·)] [Nonempty α] : IsFiltered α where -- Sanity checks example (α : Type u) [SemilatticeSup α] [OrderBot α] : IsFiltered α := by infer_instance example (α : Type u) [SemilatticeSup α] [OrderTop α] : IsFiltered α := by infer_instance instance : IsFiltered (Discrete PUnit) where cocone_objs X Y := ⟨⟨PUnit.unit⟩, ⟨⟨by trivial⟩⟩, ⟨⟨by subsingleton⟩⟩, trivial⟩ cocone_maps X Y f g := ⟨⟨PUnit.unit⟩, ⟨⟨by trivial⟩⟩, by subsingleton⟩ namespace IsFiltered section AllowEmpty variable {C} variable [IsFilteredOrEmpty C] /-- `max j j'` is an arbitrary choice of object to the right of both `j` and `j'`, whose existence is ensured by `IsFiltered`. -/ noncomputable def max (j j' : C) : C := (IsFilteredOrEmpty.cocone_objs j j').choose /-- `leftToMax j j'` is an arbitrary choice of morphism from `j` to `max j j'`, whose existence is ensured by `IsFiltered`. -/ noncomputable def leftToMax (j j' : C) : j ⟶ max j j' := (IsFilteredOrEmpty.cocone_objs j j').choose_spec.choose /-- `rightToMax j j'` is an arbitrary choice of morphism from `j'` to `max j j'`, whose existence is ensured by `IsFiltered`. -/ noncomputable def rightToMax (j j' : C) : j' ⟶ max j j' := (IsFilteredOrEmpty.cocone_objs j j').choose_spec.choose_spec.choose /-- `coeq f f'`, for morphisms `f f' : j ⟶ j'`, is an arbitrary choice of object which admits a morphism `coeqHom f f' : j' ⟶ coeq f f'` such that `coeq_condition : f ≫ coeqHom f f' = f' ≫ coeqHom f f'`. Its existence is ensured by `IsFiltered`. -/ noncomputable def coeq {j j' : C} (f f' : j ⟶ j') : C := (IsFilteredOrEmpty.cocone_maps f f').choose /-- `coeqHom f f'`, for morphisms `f f' : j ⟶ j'`, is an arbitrary choice of morphism `coeqHom f f' : j' ⟶ coeq f f'` such that `coeq_condition : f ≫ coeqHom f f' = f' ≫ coeqHom f f'`. Its existence is ensured by `IsFiltered`. -/ noncomputable def coeqHom {j j' : C} (f f' : j ⟶ j') : j' ⟶ coeq f f' := (IsFilteredOrEmpty.cocone_maps f f').choose_spec.choose -- Porting note: the simp tag has been removed as the linter complained /-- `coeq_condition f f'`, for morphisms `f f' : j ⟶ j'`, is the proof that `f ≫ coeqHom f f' = f' ≫ coeqHom f f'`. -/ @[reassoc] theorem coeq_condition {j j' : C} (f f' : j ⟶ j') : f ≫ coeqHom f f' = f' ≫ coeqHom f f' := (IsFilteredOrEmpty.cocone_maps f f').choose_spec.choose_spec end AllowEmpty end IsFiltered namespace IsFilteredOrEmpty open IsFiltered variable {C} variable [IsFilteredOrEmpty C] variable {D : Type u₁} [Category.{v₁} D] /-- If `C` is filtered or empty, and we have a functor `R : C ⥤ D` with a left adjoint, then `D` is filtered or empty. -/ theorem of_right_adjoint {L : D ⥤ C} {R : C ⥤ D} (h : L ⊣ R) : IsFilteredOrEmpty D := { cocone_objs := fun X Y => ⟨R.obj (max (L.obj X) (L.obj Y)), h.homEquiv _ _ (leftToMax _ _), h.homEquiv _ _ (rightToMax _ _), ⟨⟩⟩ cocone_maps := fun X Y f g => ⟨R.obj (coeq (L.map f) (L.map g)), h.homEquiv _ _ (coeqHom _ _), by rw [← h.homEquiv_naturality_left, ← h.homEquiv_naturality_left, coeq_condition]⟩ } /-- If `C` is filtered or empty, and we have a right adjoint functor `R : C ⥤ D`, then `D` is filtered or empty. -/ theorem of_isRightAdjoint (R : C ⥤ D) [R.IsRightAdjoint] : IsFilteredOrEmpty D := of_right_adjoint (Adjunction.ofIsRightAdjoint R) /-- Being filtered or empty is preserved by equivalence of categories. -/ theorem of_equivalence (h : C ≌ D) : IsFilteredOrEmpty D := of_right_adjoint h.symm.toAdjunction end IsFilteredOrEmpty namespace IsFiltered section Nonempty open CategoryTheory.Limits variable {C} variable [IsFiltered C] /-- Any finite collection of objects in a filtered category has an object "to the right". -/ theorem sup_objs_exists (O : Finset C) : ∃ S : C, ∀ {X}, X ∈ O → Nonempty (X ⟶ S) := by classical induction' O using Finset.induction with X O' nm h · exact ⟨Classical.choice IsFiltered.nonempty, by intro; simp⟩ · obtain ⟨S', w'⟩ := h use max X S' rintro Y mY obtain rfl | h := eq_or_ne Y X · exact ⟨leftToMax _ _⟩ · exact ⟨(w' (Finset.mem_of_mem_insert_of_ne mY h)).some ≫ rightToMax _ _⟩ variable (O : Finset C) (H : Finset (Σ' (X Y : C) (_ : X ∈ O) (_ : Y ∈ O), X ⟶ Y)) /-- Given any `Finset` of objects `{X, ...}` and indexed collection of `Finset`s of morphisms `{f, ...}` in `C`, there exists an object `S`, with a morphism `T X : X ⟶ S` from each `X`, such that the triangles commute: `f ≫ T Y = T X`, for `f : X ⟶ Y` in the `Finset`. -/ theorem sup_exists : ∃ (S : C) (T : ∀ {X : C}, X ∈ O → (X ⟶ S)), ∀ {X Y : C} (mX : X ∈ O) (mY : Y ∈ O) {f : X ⟶ Y}, (⟨X, Y, mX, mY, f⟩ : Σ' (X Y : C) (_ : X ∈ O) (_ : Y ∈ O), X ⟶ Y) ∈ H → f ≫ T mY = T mX := by classical induction' H using Finset.induction with h' H' nmf h'' · obtain ⟨S, f⟩ := sup_objs_exists O exact ⟨S, fun mX => (f mX).some, by rintro - - - - - ⟨⟩⟩ · obtain ⟨X, Y, mX, mY, f⟩ := h' obtain ⟨S', T', w'⟩ := h'' refine ⟨coeq (f ≫ T' mY) (T' mX), fun mZ => T' mZ ≫ coeqHom (f ≫ T' mY) (T' mX), ?_⟩ intro X' Y' mX' mY' f' mf' rw [← Category.assoc] by_cases h : X = X' ∧ Y = Y' · rcases h with ⟨rfl, rfl⟩ by_cases hf : f = f' · subst hf apply coeq_condition · rw [@w' _ _ mX mY f'] simp only [Finset.mem_insert, PSigma.mk.injEq, heq_eq_eq, true_and] at mf' rcases mf' with mf' | mf' · exfalso exact hf mf'.symm · exact mf' · rw [@w' _ _ mX' mY' f' _] apply Finset.mem_of_mem_insert_of_ne mf' contrapose! h obtain ⟨rfl, h⟩ := h trivial /-- An arbitrary choice of object "to the right" of a finite collection of objects `O` and morphisms `H`, making all the triangles commute. -/ noncomputable def sup : C := (sup_exists O H).choose /-- The morphisms to `sup O H`. -/ noncomputable def toSup {X : C} (m : X ∈ O) : X ⟶ sup O H := (sup_exists O H).choose_spec.choose m /-- The triangles of consisting of a morphism in `H` and the maps to `sup O H` commute. -/ theorem toSup_commutes {X Y : C} (mX : X ∈ O) (mY : Y ∈ O) {f : X ⟶ Y} (mf : (⟨X, Y, mX, mY, f⟩ : Σ' (X Y : C) (_ : X ∈ O) (_ : Y ∈ O), X ⟶ Y) ∈ H) : f ≫ toSup O H mY = toSup O H mX := (sup_exists O H).choose_spec.choose_spec mX mY mf variable {J : Type w} [SmallCategory J] [FinCategory J] /-- If we have `IsFiltered C`, then for any functor `F : J ⥤ C` with `FinCategory J`, there exists a cocone over `F`. -/ theorem cocone_nonempty (F : J ⥤ C) : Nonempty (Cocone F) := by classical let O := Finset.univ.image F.obj let H : Finset (Σ' (X Y : C) (_ : X ∈ O) (_ : Y ∈ O), X ⟶ Y) := Finset.univ.biUnion fun X : J => Finset.univ.biUnion fun Y : J => Finset.univ.image fun f : X ⟶ Y => ⟨F.obj X, F.obj Y, by simp [O], by simp [O], F.map f⟩ obtain ⟨Z, f, w⟩ := sup_exists O H refine ⟨⟨Z, ⟨fun X => f (by simp [O]), ?_⟩⟩⟩ intro j j' g dsimp simp only [Category.comp_id] apply w simp only [O, H, Finset.mem_biUnion, Finset.mem_univ, Finset.mem_image, PSigma.mk.injEq, true_and, exists_and_left] exact ⟨j, rfl, j', g, by simp⟩ /-- An arbitrary choice of cocone over `F : J ⥤ C`, for `FinCategory J` and `IsFiltered C`. -/ noncomputable def cocone (F : J ⥤ C) : Cocone F := (cocone_nonempty F).some variable {D : Type u₁} [Category.{v₁} D] /-- If `C` is filtered, and we have a functor `R : C ⥤ D` with a left adjoint, then `D` is filtered. -/ theorem of_right_adjoint {L : D ⥤ C} {R : C ⥤ D} (h : L ⊣ R) : IsFiltered D := { IsFilteredOrEmpty.of_right_adjoint h with nonempty := IsFiltered.nonempty.map R.obj } /-- If `C` is filtered, and we have a right adjoint functor `R : C ⥤ D`, then `D` is filtered. -/ theorem of_isRightAdjoint (R : C ⥤ D) [R.IsRightAdjoint] : IsFiltered D := of_right_adjoint (Adjunction.ofIsRightAdjoint R) /-- Being filtered is preserved by equivalence of categories. -/ theorem of_equivalence (h : C ≌ D) : IsFiltered D := of_right_adjoint h.symm.toAdjunction end Nonempty section OfCocone open CategoryTheory.Limits /-- If every finite diagram in `C` admits a cocone, then `C` is filtered. It is sufficient to verify this for diagrams whose shape lives in any one fixed universe. -/ theorem of_cocone_nonempty (h : ∀ {J : Type w} [SmallCategory J] [FinCategory J] (F : J ⥤ C), Nonempty (Cocone F)) : IsFiltered C := by have : Nonempty C := by obtain ⟨c⟩ := h (Functor.empty _) exact ⟨c.pt⟩ have : IsFilteredOrEmpty C := by refine ⟨?_, ?_⟩ · intros X Y obtain ⟨c⟩ := h (ULiftHom.down ⋙ ULift.downFunctor ⋙ pair X Y) exact ⟨c.pt, c.ι.app ⟨⟨WalkingPair.left⟩⟩, c.ι.app ⟨⟨WalkingPair.right⟩⟩, trivial⟩ · intros X Y f g obtain ⟨c⟩ := h (ULiftHom.down ⋙ ULift.downFunctor ⋙ parallelPair f g) refine ⟨c.pt, c.ι.app ⟨WalkingParallelPair.one⟩, ?_⟩ have h₁ := c.ι.naturality ⟨WalkingParallelPairHom.left⟩ have h₂ := c.ι.naturality ⟨WalkingParallelPairHom.right⟩ simp_all apply IsFiltered.mk theorem of_hasFiniteColimits [HasFiniteColimits C] : IsFiltered C := of_cocone_nonempty.{v} C fun F => ⟨colimit.cocone F⟩ theorem of_isTerminal {X : C} (h : IsTerminal X) : IsFiltered C := of_cocone_nonempty.{v} _ fun {_} _ _ _ => ⟨⟨X, ⟨fun _ => h.from _, fun _ _ _ => h.hom_ext _ _⟩⟩⟩ instance (priority := 100) of_hasTerminal [HasTerminal C] : IsFiltered C := of_isTerminal _ terminalIsTerminal /-- For every universe `w`, `C` is filtered if and only if every finite diagram in `C` with shape in `w` admits a cocone. -/ theorem iff_cocone_nonempty : IsFiltered C ↔ ∀ {J : Type w} [SmallCategory J] [FinCategory J] (F : J ⥤ C), Nonempty (Cocone F) := ⟨fun _ _ _ _ F => cocone_nonempty F, of_cocone_nonempty C⟩ end OfCocone section SpecialShapes variable {C} variable [IsFilteredOrEmpty C] /-- `max₃ j₁ j₂ j₃` is an arbitrary choice of object to the right of `j₁`, `j₂` and `j₃`, whose existence is ensured by `IsFiltered`. -/ noncomputable def max₃ (j₁ j₂ j₃ : C) : C := max (max j₁ j₂) j₃ /-- `firstToMax₃ j₁ j₂ j₃` is an arbitrary choice of morphism from `j₁` to `max₃ j₁ j₂ j₃`, whose existence is ensured by `IsFiltered`. -/ noncomputable def firstToMax₃ (j₁ j₂ j₃ : C) : j₁ ⟶ max₃ j₁ j₂ j₃ := leftToMax j₁ j₂ ≫ leftToMax (max j₁ j₂) j₃ /-- `secondToMax₃ j₁ j₂ j₃` is an arbitrary choice of morphism from `j₂` to `max₃ j₁ j₂ j₃`, whose existence is ensured by `IsFiltered`. -/ noncomputable def secondToMax₃ (j₁ j₂ j₃ : C) : j₂ ⟶ max₃ j₁ j₂ j₃ := rightToMax j₁ j₂ ≫ leftToMax (max j₁ j₂) j₃ /-- `thirdToMax₃ j₁ j₂ j₃` is an arbitrary choice of morphism from `j₃` to `max₃ j₁ j₂ j₃`, whose existence is ensured by `IsFiltered`. -/ noncomputable def thirdToMax₃ (j₁ j₂ j₃ : C) : j₃ ⟶ max₃ j₁ j₂ j₃ := rightToMax (max j₁ j₂) j₃ /-- `coeq₃ f g h`, for morphisms `f g h : j₁ ⟶ j₂`, is an arbitrary choice of object which admits a morphism `coeq₃Hom f g h : j₂ ⟶ coeq₃ f g h` such that `coeq₃_condition₁`, `coeq₃_condition₂` and `coeq₃_condition₃` are satisfied. Its existence is ensured by `IsFiltered`. -/ noncomputable def coeq₃ {j₁ j₂ : C} (f g h : j₁ ⟶ j₂) : C := coeq (coeqHom f g ≫ leftToMax (coeq f g) (coeq g h)) (coeqHom g h ≫ rightToMax (coeq f g) (coeq g h)) /-- `coeq₃Hom f g h`, for morphisms `f g h : j₁ ⟶ j₂`, is an arbitrary choice of morphism `j₂ ⟶ coeq₃ f g h` such that `coeq₃_condition₁`, `coeq₃_condition₂` and `coeq₃_condition₃` are satisfied. Its existence is ensured by `IsFiltered`. -/ noncomputable def coeq₃Hom {j₁ j₂ : C} (f g h : j₁ ⟶ j₂) : j₂ ⟶ coeq₃ f g h := coeqHom f g ≫ leftToMax (coeq f g) (coeq g h) ≫ coeqHom (coeqHom f g ≫ leftToMax (coeq f g) (coeq g h)) (coeqHom g h ≫ rightToMax (coeq f g) (coeq g h)) theorem coeq₃_condition₁ {j₁ j₂ : C} (f g h : j₁ ⟶ j₂) : f ≫ coeq₃Hom f g h = g ≫ coeq₃Hom f g h := by simp only [coeq₃Hom, ← Category.assoc, coeq_condition f g] theorem coeq₃_condition₂ {j₁ j₂ : C} (f g h : j₁ ⟶ j₂) : g ≫ coeq₃Hom f g h = h ≫ coeq₃Hom f g h := by dsimp [coeq₃Hom] slice_lhs 2 4 => rw [← Category.assoc, coeq_condition _ _] slice_rhs 2 4 => rw [← Category.assoc, coeq_condition _ _] slice_lhs 1 3 => rw [← Category.assoc, coeq_condition _ _] simp only [Category.assoc] theorem coeq₃_condition₃ {j₁ j₂ : C} (f g h : j₁ ⟶ j₂) : f ≫ coeq₃Hom f g h = h ≫ coeq₃Hom f g h := Eq.trans (coeq₃_condition₁ f g h) (coeq₃_condition₂ f g h) /-- For every span `j ⟵ i ⟶ j'`, there exists a cocone `j ⟶ k ⟵ j'` such that the square commutes. -/ theorem span {i j j' : C} (f : i ⟶ j) (f' : i ⟶ j') : ∃ (k : C) (g : j ⟶ k) (g' : j' ⟶ k), f ≫ g = f' ≫ g' := let ⟨K, G, G', _⟩ := IsFilteredOrEmpty.cocone_objs j j' let ⟨k, e, he⟩ := IsFilteredOrEmpty.cocone_maps (f ≫ G) (f' ≫ G') ⟨k, G ≫ e, G' ≫ e, by simpa only [← Category.assoc] ⟩ /-- Given a "bowtie" of morphisms ``` j₁ j₂ |\ /| | \/ | | /\ | |/ \∣ vv vv k₁ k₂ ``` in a filtered category, we can construct an object `s` and two morphisms from `k₁` and `k₂` to `s`, making the resulting squares commute. -/ theorem bowtie {j₁ j₂ k₁ k₂ : C} (f₁ : j₁ ⟶ k₁) (g₁ : j₁ ⟶ k₂) (f₂ : j₂ ⟶ k₁) (g₂ : j₂ ⟶ k₂) : ∃ (s : C) (α : k₁ ⟶ s) (β : k₂ ⟶ s), f₁ ≫ α = g₁ ≫ β ∧ f₂ ≫ α = g₂ ≫ β := by obtain ⟨t, k₁t, k₂t, ht⟩ := span f₁ g₁ obtain ⟨s, ts, hs⟩ := IsFilteredOrEmpty.cocone_maps (f₂ ≫ k₁t) (g₂ ≫ k₂t) simp_rw [Category.assoc] at hs exact ⟨s, k₁t ≫ ts, k₂t ≫ ts, by simp only [← Category.assoc, ht], hs⟩ /-- Given a "tulip" of morphisms ``` j₁ j₂ j₃ |\ / \ / | | \ / \ / | | vv vv | \ k₁ k₂ / \ / \ / \ /
\ / v v l
Mathlib/CategoryTheory/Filtered/Basic.lean
461
463
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Yourong Zang -/ import Mathlib.Analysis.Calculus.ContDiff.Operations import Mathlib.Analysis.Calculus.Deriv.Linear import Mathlib.Analysis.Complex.Basic /-! # Real differentiability of complex-differentiable functions `HasDerivAt.real_of_complex` expresses that, if a function on `ℂ` is differentiable (over `ℂ`), then its restriction to `ℝ` is differentiable over `ℝ`, with derivative the real part of the complex derivative. -/ assert_not_exists IsConformalMap Conformal section RealDerivOfComplex /-! ### Differentiability of the restriction to `ℝ` of complex functions -/ open Complex variable {e : ℂ → ℂ} {e' : ℂ} {z : ℝ} /-- If a complex function is differentiable at a real point, then the induced real function is also differentiable at this point, with a derivative equal to the real part of the complex derivative. -/ theorem HasStrictDerivAt.real_of_complex (h : HasStrictDerivAt e e' z) : HasStrictDerivAt (fun x : ℝ => (e x).re) e'.re z := by have A : HasStrictFDerivAt ((↑) : ℝ → ℂ) ofRealCLM z := ofRealCLM.hasStrictFDerivAt have B : HasStrictFDerivAt e ((ContinuousLinearMap.smulRight 1 e' : ℂ →L[ℂ] ℂ).restrictScalars ℝ) (ofRealCLM z) := h.hasStrictFDerivAt.restrictScalars ℝ have C : HasStrictFDerivAt re reCLM (e (ofRealCLM z)) := reCLM.hasStrictFDerivAt simpa using (C.comp z (B.comp z A)).hasStrictDerivAt /-- If a complex function `e` is differentiable at a real point, then the function `ℝ → ℝ` given by the real part of `e` is also differentiable at this point, with a derivative equal to the real part of the complex derivative. -/ theorem HasDerivAt.real_of_complex (h : HasDerivAt e e' z) : HasDerivAt (fun x : ℝ => (e x).re) e'.re z := by have A : HasFDerivAt ((↑) : ℝ → ℂ) ofRealCLM z := ofRealCLM.hasFDerivAt have B : HasFDerivAt e ((ContinuousLinearMap.smulRight 1 e' : ℂ →L[ℂ] ℂ).restrictScalars ℝ) (ofRealCLM z) := h.hasFDerivAt.restrictScalars ℝ have C : HasFDerivAt re reCLM (e (ofRealCLM z)) := reCLM.hasFDerivAt simpa using (C.comp z (B.comp z A)).hasDerivAt theorem ContDiffAt.real_of_complex {n : WithTop ℕ∞} (h : ContDiffAt ℂ n e z) : ContDiffAt ℝ n (fun x : ℝ => (e x).re) z := by have A : ContDiffAt ℝ n ((↑) : ℝ → ℂ) z := ofRealCLM.contDiff.contDiffAt have B : ContDiffAt ℝ n e z := h.restrict_scalars ℝ have C : ContDiffAt ℝ n re (e z) := reCLM.contDiff.contDiffAt exact C.comp z (B.comp z A) theorem ContDiff.real_of_complex {n : WithTop ℕ∞} (h : ContDiff ℂ n e) : ContDiff ℝ n fun x : ℝ => (e x).re := contDiff_iff_contDiffAt.2 fun _ => h.contDiffAt.real_of_complex variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] theorem HasStrictDerivAt.complexToReal_fderiv' {f : ℂ → E} {x : ℂ} {f' : E} (h : HasStrictDerivAt f f' x) : HasStrictFDerivAt f (reCLM.smulRight f' + I • imCLM.smulRight f') x := by
simpa only [Complex.restrictScalars_one_smulRight'] using h.hasStrictFDerivAt.restrictScalars ℝ theorem HasDerivAt.complexToReal_fderiv' {f : ℂ → E} {x : ℂ} {f' : E} (h : HasDerivAt f f' x) : HasFDerivAt f (reCLM.smulRight f' + I • imCLM.smulRight f') x := by simpa only [Complex.restrictScalars_one_smulRight'] using h.hasFDerivAt.restrictScalars ℝ theorem HasDerivWithinAt.complexToReal_fderiv' {f : ℂ → E} {s : Set ℂ} {x : ℂ} {f' : E} (h : HasDerivWithinAt f f' s x) : HasFDerivWithinAt f (reCLM.smulRight f' + I • imCLM.smulRight f') s x := by simpa only [Complex.restrictScalars_one_smulRight'] using h.hasFDerivWithinAt.restrictScalars ℝ theorem HasStrictDerivAt.complexToReal_fderiv {f : ℂ → ℂ} {f' x : ℂ} (h : HasStrictDerivAt f f' x) :
Mathlib/Analysis/Complex/RealDeriv.lean
68
81
/- 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.Max import Mathlib.Data.Fintype.EquivFin import Mathlib.Data.Multiset.Sort import Mathlib.Order.RelIso.Set /-! # Construct a sorted list from a finset. -/ namespace Finset open Multiset Nat variable {α β : Type*} /-! ### sort -/ section sort variable (r : α → α → Prop) [DecidableRel r] [IsTrans α r] [IsAntisymm α r] [IsTotal α r] /-- `sort s` constructs a sorted list from the unordered set `s`. (Uses merge sort algorithm.) -/ def sort (s : Finset α) : List α := Multiset.sort r s.1 @[simp] theorem sort_val (s : Finset α) : Multiset.sort r s.val = sort r s := rfl @[simp] theorem sort_mk {s : Multiset α} (h : s.Nodup) : sort r ⟨s, h⟩ = s.sort r := rfl @[simp] theorem sort_sorted (s : Finset α) : List.Sorted r (sort r s) := Multiset.sort_sorted _ _ @[simp] theorem sort_eq (s : Finset α) : ↑(sort r s) = s.1 := Multiset.sort_eq _ _ @[simp] theorem sort_nodup (s : Finset α) : (sort r s).Nodup := (by rw [sort_eq]; exact s.2 : @Multiset.Nodup α (sort r s)) @[simp] theorem sort_toFinset [DecidableEq α] (s : Finset α) : (sort r s).toFinset = s := List.toFinset_eq (sort_nodup r s) ▸ eq_of_veq (sort_eq r s) @[simp] theorem mem_sort {s : Finset α} {a : α} : a ∈ sort r s ↔ a ∈ s := Multiset.mem_sort _ @[simp] theorem length_sort {s : Finset α} : (sort r s).length = s.card := Multiset.length_sort _ @[simp] theorem sort_empty : sort r ∅ = [] := Multiset.sort_zero r @[simp] theorem sort_singleton (a : α) : sort r {a} = [a] := Multiset.sort_singleton r a theorem sort_cons {a : α} {s : Finset α} (h₁ : ∀ b ∈ s, r a b) (h₂ : a ∉ s) : sort r (cons a s h₂) = a :: sort r s := by rw [sort, cons_val, Multiset.sort_cons r a _ h₁, sort_val] theorem sort_insert [DecidableEq α] {a : α} {s : Finset α} (h₁ : ∀ b ∈ s, r a b) (h₂ : a ∉ s) : sort r (insert a s) = a :: sort r s := by rw [← cons_eq_insert _ _ h₂, sort_cons r h₁] @[simp] theorem sort_range (n : ℕ) : sort (· ≤ ·) (range n) = List.range n := Multiset.sort_range n open scoped List in theorem sort_perm_toList (s : Finset α) : sort r s ~ s.toList := by rw [← Multiset.coe_eq_coe] simp only [coe_toList, sort_eq] theorem _root_.List.toFinset_sort [DecidableEq α] {l : List α} (hl : l.Nodup) : sort r l.toFinset = l ↔ l.Sorted r := by refine ⟨?_, List.eq_of_perm_of_sorted ((sort_perm_toList r _).trans (List.toFinset_toList hl)) (sort_sorted r _)⟩ intro h rw [← h] exact sort_sorted r _ end sort section SortLinearOrder variable [LinearOrder α] theorem sort_sorted_lt (s : Finset α) : List.Sorted (· < ·) (sort (· ≤ ·) s) := (sort_sorted _ _).lt_of_le (sort_nodup _ _) theorem sort_sorted_gt (s : Finset α) : List.Sorted (· > ·) (sort (· ≥ ·) s) := (sort_sorted _ _).gt_of_ge (sort_nodup _ _) theorem sorted_zero_eq_min'_aux (s : Finset α) (h : 0 < (s.sort (· ≤ ·)).length) (H : s.Nonempty) : (s.sort (· ≤ ·)).get ⟨0, h⟩ = s.min' H := by let l := s.sort (· ≤ ·) apply le_antisymm · have : s.min' H ∈ l := (Finset.mem_sort (α := α) (· ≤ ·)).mpr (s.min'_mem H) obtain ⟨i, hi⟩ : ∃ i, l.get i = s.min' H := List.mem_iff_get.1 this rw [← hi] exact (s.sort_sorted (· ≤ ·)).rel_get_of_le (Nat.zero_le i) · have : l.get ⟨0, h⟩ ∈ s := (Finset.mem_sort (α := α) (· ≤ ·)).1 (List.get_mem l _) exact s.min'_le _ this theorem sorted_zero_eq_min' {s : Finset α} {h : 0 < (s.sort (· ≤ ·)).length} : (s.sort (· ≤ ·))[0] = s.min' (card_pos.1 <| by rwa [length_sort] at h) := sorted_zero_eq_min'_aux _ _ _ theorem min'_eq_sorted_zero {s : Finset α} {h : s.Nonempty} : s.min' h = (s.sort (· ≤ ·))[0]'(by rw [length_sort]; exact card_pos.2 h) := (sorted_zero_eq_min'_aux _ _ _).symm theorem sorted_last_eq_max'_aux (s : Finset α) (h : (s.sort (· ≤ ·)).length - 1 < (s.sort (· ≤ ·)).length) (H : s.Nonempty) : (s.sort (· ≤ ·))[(s.sort (· ≤ ·)).length - 1] = s.max' H := by let l := s.sort (· ≤ ·) apply le_antisymm
· have : l.get ⟨(s.sort (· ≤ ·)).length - 1, h⟩ ∈ s := (Finset.mem_sort (α := α) (· ≤ ·)).1 (List.get_mem l _) exact s.le_max' _ this · have : s.max' H ∈ l := (Finset.mem_sort (α := α) (· ≤ ·)).mpr (s.max'_mem H) obtain ⟨i, hi⟩ : ∃ i, l.get i = s.max' H := List.mem_iff_get.1 this
Mathlib/Data/Finset/Sort.lean
133
137
/- Copyright (c) 2022 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.MeasureTheory.Covering.DensityTheorem /-! # Liminf, limsup, and uniformly locally doubling measures. This file is a place to collect lemmas about liminf and limsup for subsets of a metric space carrying a uniformly locally doubling measure. ## Main results: * `blimsup_cthickening_mul_ae_eq`: the limsup of the closed thickening of a sequence of subsets of a metric space is unchanged almost everywhere for a uniformly locally doubling measure if the sequence of distances is multiplied by a positive scale factor. This is a generalisation of a result of Cassels, appearing as Lemma 9 on page 217 of [J.W.S. Cassels, *Some metrical theorems in Diophantine approximation. I*](cassels1950). * `blimsup_thickening_mul_ae_eq`: a variant of `blimsup_cthickening_mul_ae_eq` for thickenings rather than closed thickenings. -/ open Set Filter Metric MeasureTheory TopologicalSpace open scoped NNReal ENNReal Topology variable {α : Type*} variable [PseudoMetricSpace α] [SecondCountableTopology α] [MeasurableSpace α] [BorelSpace α] variable (μ : Measure α) [IsLocallyFiniteMeasure μ] [IsUnifLocDoublingMeasure μ] /-- This is really an auxiliary result en route to `blimsup_cthickening_ae_le_of_eventually_mul_le` (which is itself an auxiliary result en route to `blimsup_cthickening_mul_ae_eq`). NB: The `: Set α` type ascription is present because of https://github.com/leanprover-community/mathlib/issues/16932. -/ theorem blimsup_cthickening_ae_le_of_eventually_mul_le_aux (p : ℕ → Prop) {s : ℕ → Set α} (hs : ∀ i, IsClosed (s i)) {r₁ r₂ : ℕ → ℝ} (hr : Tendsto r₁ atTop (𝓝[>] 0)) (hrp : 0 ≤ r₁) {M : ℝ} (hM : 0 < M) (hM' : M < 1) (hMr : ∀ᶠ i in atTop, M * r₁ i ≤ r₂ i) : (blimsup (fun i => cthickening (r₁ i) (s i)) atTop p : Set α) ≤ᵐ[μ] (blimsup (fun i => cthickening (r₂ i) (s i)) atTop p : Set α) := by /- Sketch of proof: Assume that `p` is identically true for simplicity. Let `Y₁ i = cthickening (r₁ i) (s i)`, define `Y₂` similarly except using `r₂`, and let `(Z i) = ⋃_{j ≥ i} (Y₂ j)`. Our goal is equivalent to showing that `μ ((limsup Y₁) \ (Z i)) = 0` for all `i`. Assume for contradiction that `μ ((limsup Y₁) \ (Z i)) ≠ 0` for some `i` and let `W = (limsup Y₁) \ (Z i)`. Apply Lebesgue's density theorem to obtain a point `d` in `W` of density `1`. Since `d ∈ limsup Y₁`, there is a subsequence of `j ↦ Y₁ j`, indexed by `f 0 < f 1 < ...`, such that `d ∈ Y₁ (f j)` for all `j`. For each `j`, we may thus choose `w j ∈ s (f j)` such that `d ∈ B j`, where `B j = closedBall (w j) (r₁ (f j))`. Note that since `d` has density one, `μ (W ∩ (B j)) / μ (B j) → 1`. We obtain our contradiction by showing that there exists `η < 1` such that `μ (W ∩ (B j)) / μ (B j) ≤ η` for sufficiently large `j`. In fact we claim that `η = 1 - C⁻¹` is such a value where `C` is the scaling constant of `M⁻¹` for the uniformly locally doubling measure `μ`. To prove the claim, let `b j = closedBall (w j) (M * r₁ (f j))` and for given `j` consider the sets `b j` and `W ∩ (B j)`. These are both subsets of `B j` and are disjoint for large enough `j` since `M * r₁ j ≤ r₂ j` and thus `b j ⊆ Z i ⊆ Wᶜ`. We thus have: `μ (b j) + μ (W ∩ (B j)) ≤ μ (B j)`. Combining this with `μ (B j) ≤ C * μ (b j)` we obtain the required inequality. -/ set Y₁ : ℕ → Set α := fun i => cthickening (r₁ i) (s i) set Y₂ : ℕ → Set α := fun i => cthickening (r₂ i) (s i) let Z : ℕ → Set α := fun i => ⋃ (j) (_ : p j ∧ i ≤ j), Y₂ j suffices ∀ i, μ (atTop.blimsup Y₁ p \ Z i) = 0 by rwa [ae_le_set, @blimsup_eq_iInf_biSup_of_nat _ _ _ Y₂, iInf_eq_iInter, diff_iInter, measure_iUnion_null_iff] intros i set W := atTop.blimsup Y₁ p \ Z i by_contra contra obtain ⟨d, hd, hd'⟩ : ∃ d, d ∈ W ∧ ∀ {ι : Type _} {l : Filter ι} (w : ι → α) (δ : ι → ℝ), Tendsto δ l (𝓝[>] 0) → (∀ᶠ j in l, d ∈ closedBall (w j) (2 * δ j)) → Tendsto (fun j => μ (W ∩ closedBall (w j) (δ j)) / μ (closedBall (w j) (δ j))) l (𝓝 1) := Measure.exists_mem_of_measure_ne_zero_of_ae contra (IsUnifLocDoublingMeasure.ae_tendsto_measure_inter_div μ W 2) replace hd : d ∈ blimsup Y₁ atTop p := ((mem_diff _).mp hd).1 obtain ⟨f : ℕ → ℕ, hf⟩ := exists_forall_mem_of_hasBasis_mem_blimsup' atTop_basis hd simp only [forall_and] at hf obtain ⟨hf₀ : ∀ j, d ∈ cthickening (r₁ (f j)) (s (f j)), hf₁, hf₂ : ∀ j, j ≤ f j⟩ := hf have hf₃ : Tendsto f atTop atTop := tendsto_atTop_atTop.mpr fun j => ⟨f j, fun i hi => (hf₂ j).trans (hi.trans <| hf₂ i)⟩ replace hr : Tendsto (r₁ ∘ f) atTop (𝓝[>] 0) := hr.comp hf₃ replace hMr : ∀ᶠ j in atTop, M * r₁ (f j) ≤ r₂ (f j) := hf₃.eventually hMr replace hf₀ : ∀ j, ∃ w ∈ s (f j), d ∈ closedBall w (2 * r₁ (f j)) := by intro j specialize hrp (f j) rw [Pi.zero_apply] at hrp rcases eq_or_lt_of_le hrp with (hr0 | hrp') · specialize hf₀ j rw [← hr0, cthickening_zero, (hs (f j)).closure_eq] at hf₀ exact ⟨d, hf₀, by simp [← hr0]⟩ · simpa using mem_iUnion₂.mp (cthickening_subset_iUnion_closedBall_of_lt (s (f j)) (by positivity) (lt_two_mul_self hrp') (hf₀ j)) choose w hw hw' using hf₀ let C := IsUnifLocDoublingMeasure.scalingConstantOf μ M⁻¹ have hC : 0 < C := lt_of_lt_of_le zero_lt_one (IsUnifLocDoublingMeasure.one_le_scalingConstantOf μ M⁻¹) suffices ∃ η < (1 : ℝ≥0), ∀ᶠ j in atTop, μ (W ∩ closedBall (w j) (r₁ (f j))) / μ (closedBall (w j) (r₁ (f j))) ≤ η by obtain ⟨η, hη, hη'⟩ := this replace hη' : 1 ≤ η := by simpa only [ENNReal.one_le_coe_iff] using le_of_tendsto (hd' w (fun j => r₁ (f j)) hr <| Eventually.of_forall hw') hη' exact (lt_self_iff_false _).mp (lt_of_lt_of_le hη hη') refine ⟨1 - C⁻¹, tsub_lt_self zero_lt_one (inv_pos.mpr hC), ?_⟩ replace hC : C ≠ 0 := ne_of_gt hC let b : ℕ → Set α := fun j => closedBall (w j) (M * r₁ (f j)) let B : ℕ → Set α := fun j => closedBall (w j) (r₁ (f j)) have h₁ : ∀ j, b j ⊆ B j := fun j => closedBall_subset_closedBall (mul_le_of_le_one_left (hrp (f j)) hM'.le) have h₂ : ∀ j, W ∩ B j ⊆ B j := fun j => inter_subset_right have h₃ : ∀ᶠ j in atTop, Disjoint (b j) (W ∩ B j) := by apply hMr.mp rw [eventually_atTop] refine ⟨i, fun j hj hj' => Disjoint.inf_right (B j) <| Disjoint.inf_right' (blimsup Y₁ atTop p) ?_⟩ change Disjoint (b j) (Z i)ᶜ rw [disjoint_compl_right_iff_subset] refine (closedBall_subset_cthickening (hw j) (M * r₁ (f j))).trans ((cthickening_mono hj' _).trans fun a ha => ?_) simp only [Z, mem_iUnion, exists_prop] exact ⟨f j, ⟨hf₁ j, hj.le.trans (hf₂ j)⟩, ha⟩ have h₄ : ∀ᶠ j in atTop, μ (B j) ≤ C * μ (b j) := (hr.eventually (IsUnifLocDoublingMeasure.eventually_measure_le_scaling_constant_mul' μ M hM)).mono fun j hj => hj (w j) refine (h₃.and h₄).mono fun j hj₀ => ?_ change μ (W ∩ B j) / μ (B j) ≤ ↑(1 - C⁻¹) rcases eq_or_ne (μ (B j)) ∞ with (hB | hB); · simp [hB] apply ENNReal.div_le_of_le_mul rw [ENNReal.coe_sub, ENNReal.coe_one, ENNReal.sub_mul fun _ _ => hB, one_mul] replace hB : ↑C⁻¹ * μ (B j) ≠ ∞ := by refine ENNReal.mul_ne_top ?_ hB rwa [ENNReal.coe_inv hC, Ne, ENNReal.inv_eq_top, ENNReal.coe_eq_zero] obtain ⟨hj₁ : Disjoint (b j) (W ∩ B j), hj₂ : μ (B j) ≤ C * μ (b j)⟩ := hj₀ replace hj₂ : ↑C⁻¹ * μ (B j) ≤ μ (b j) := by rw [ENNReal.coe_inv hC, ← ENNReal.div_eq_inv_mul] exact ENNReal.div_le_of_le_mul' hj₂ have hj₃ : ↑C⁻¹ * μ (B j) + μ (W ∩ B j) ≤ μ (B j) := by refine le_trans (add_le_add_right hj₂ _) ?_ rw [← measure_union' hj₁ measurableSet_closedBall] exact measure_mono (union_subset (h₁ j) (h₂ j)) replace hj₃ := tsub_le_tsub_right hj₃ (↑C⁻¹ * μ (B j)) rwa [ENNReal.add_sub_cancel_left hB] at hj₃ /-- This is really an auxiliary result en route to `blimsup_cthickening_mul_ae_eq`. NB: The `: Set α` type ascription is present because of https://github.com/leanprover-community/mathlib/issues/16932. -/ theorem blimsup_cthickening_ae_le_of_eventually_mul_le (p : ℕ → Prop) {s : ℕ → Set α} {M : ℝ} (hM : 0 < M) {r₁ r₂ : ℕ → ℝ} (hr : Tendsto r₁ atTop (𝓝[>] 0)) (hMr : ∀ᶠ i in atTop, M * r₁ i ≤ r₂ i) : (blimsup (fun i => cthickening (r₁ i) (s i)) atTop p : Set α) ≤ᵐ[μ] (blimsup (fun i => cthickening (r₂ i) (s i)) atTop p : Set α) := by let R₁ i := max 0 (r₁ i) let R₂ i := max 0 (r₂ i) have hRp : 0 ≤ R₁ := fun i => le_max_left 0 (r₁ i) replace hMr : ∀ᶠ i in atTop, M * R₁ i ≤ R₂ i := by refine hMr.mono fun i hi ↦ ?_ rw [mul_max_of_nonneg _ _ hM.le, mul_zero] exact max_le_max (le_refl 0) hi simp_rw [← cthickening_max_zero (r₁ _), ← cthickening_max_zero (r₂ _)] rcases le_or_lt 1 M with hM' | hM' · apply HasSubset.Subset.eventuallyLE change _ ≤ _ refine mono_blimsup' (hMr.mono fun i hi _ => cthickening_mono ?_ (s i)) exact (le_mul_of_one_le_left (hRp i) hM').trans hi · simp only [← @cthickening_closure _ _ _ (s _)] have hs : ∀ i, IsClosed (closure (s i)) := fun i => isClosed_closure exact blimsup_cthickening_ae_le_of_eventually_mul_le_aux μ p hs (tendsto_nhds_max_right hr) hRp hM hM' hMr /-- Given a sequence of subsets `sᵢ` of a metric space, together with a sequence of radii `rᵢ` such that `rᵢ → 0`, the set of points which belong to infinitely many of the closed `rᵢ`-thickenings of `sᵢ` is unchanged almost everywhere for a uniformly locally doubling measure if the `rᵢ` are all scaled by a positive constant. This lemma is a generalisation of Lemma 9 appearing on page 217 of [J.W.S. Cassels, *Some metrical theorems in Diophantine approximation. I*](cassels1950). See also `blimsup_thickening_mul_ae_eq`. NB: The `: Set α` type ascription is present because of https://github.com/leanprover-community/mathlib/issues/16932. -/ theorem blimsup_cthickening_mul_ae_eq (p : ℕ → Prop) (s : ℕ → Set α) {M : ℝ} (hM : 0 < M) (r : ℕ → ℝ) (hr : Tendsto r atTop (𝓝 0)) : (blimsup (fun i => cthickening (M * r i) (s i)) atTop p : Set α) =ᵐ[μ] (blimsup (fun i => cthickening (r i) (s i)) atTop p : Set α) := by have : ∀ (p : ℕ → Prop) {r : ℕ → ℝ} (_ : Tendsto r atTop (𝓝[>] 0)), (blimsup (fun i => cthickening (M * r i) (s i)) atTop p : Set α) =ᵐ[μ] (blimsup (fun i => cthickening (r i) (s i)) atTop p : Set α) := by clear p hr r; intro p r hr have hr' : Tendsto (fun i => M * r i) atTop (𝓝[>] 0) := by convert TendstoNhdsWithinIoi.const_mul hM hr <;> simp only [mul_zero] refine eventuallyLE_antisymm_iff.mpr ⟨?_, ?_⟩ · exact blimsup_cthickening_ae_le_of_eventually_mul_le μ p (inv_pos.mpr hM) hr' (Eventually.of_forall fun i => by rw [inv_mul_cancel_left₀ hM.ne' (r i)]) · exact blimsup_cthickening_ae_le_of_eventually_mul_le μ p hM hr (Eventually.of_forall fun i => le_refl _) let r' : ℕ → ℝ := fun i => if 0 < r i then r i else 1 / ((i : ℝ) + 1) have hr' : Tendsto r' atTop (𝓝[>] 0) := by refine tendsto_nhdsWithin_iff.mpr ⟨Tendsto.if' hr tendsto_one_div_add_atTop_nhds_zero_nat, Eventually.of_forall fun i => ?_⟩ by_cases hi : 0 < r i · simp [r', hi] · simp only [r', hi, one_div, mem_Ioi, if_false, inv_pos]; positivity have h₀ : ∀ i, p i ∧ 0 < r i → cthickening (r i) (s i) = cthickening (r' i) (s i) := by rintro i ⟨-, hi⟩; congr! 1; change r i = ite (0 < r i) (r i) _; simp [hi] have h₁ : ∀ i, p i ∧ 0 < r i → cthickening (M * r i) (s i) = cthickening (M * r' i) (s i) := by rintro i ⟨-, hi⟩; simp only [r', hi, mul_ite, if_true] have h₂ : ∀ i, p i ∧ r i ≤ 0 → cthickening (M * r i) (s i) = cthickening (r i) (s i) := by rintro i ⟨-, hi⟩ have hi' : M * r i ≤ 0 := mul_nonpos_of_nonneg_of_nonpos hM.le hi rw [cthickening_of_nonpos hi, cthickening_of_nonpos hi'] have hp : p = fun i => p i ∧ 0 < r i ∨ p i ∧ r i ≤ 0 := by ext i; simp [← and_or_left, lt_or_le 0 (r i)] rw [hp, blimsup_or_eq_sup, blimsup_or_eq_sup] simp only [sup_eq_union] rw [blimsup_congr (Eventually.of_forall h₀), blimsup_congr (Eventually.of_forall h₁), blimsup_congr (Eventually.of_forall h₂)] exact ae_eq_set_union (this (fun i => p i ∧ 0 < r i) hr') (ae_eq_refl _) theorem blimsup_cthickening_ae_eq_blimsup_thickening {p : ℕ → Prop} {s : ℕ → Set α} {r : ℕ → ℝ} (hr : Tendsto r atTop (𝓝 0)) (hr' : ∀ᶠ i in atTop, p i → 0 < r i) : (blimsup (fun i => cthickening (r i) (s i)) atTop p : Set α) =ᵐ[μ] (blimsup (fun i => thickening (r i) (s i)) atTop p : Set α) := by refine eventuallyLE_antisymm_iff.mpr ⟨?_, HasSubset.Subset.eventuallyLE (?_ : _ ≤ _)⟩ · rw [eventuallyLE_congr (blimsup_cthickening_mul_ae_eq μ p s (one_half_pos (α := ℝ)) r hr).symm EventuallyEq.rfl] apply HasSubset.Subset.eventuallyLE change _ ≤ _ refine mono_blimsup' (hr'.mono fun i hi pi => cthickening_subset_thickening' (hi pi) ?_ (s i)) nlinarith [hi pi] · exact mono_blimsup fun i _ => thickening_subset_cthickening _ _ /-- An auxiliary result en route to `blimsup_thickening_mul_ae_eq`. -/ theorem blimsup_thickening_mul_ae_eq_aux (p : ℕ → Prop) (s : ℕ → Set α) {M : ℝ} (hM : 0 < M) (r : ℕ → ℝ) (hr : Tendsto r atTop (𝓝 0)) (hr' : ∀ᶠ i in atTop, p i → 0 < r i) : (blimsup (fun i => thickening (M * r i) (s i)) atTop p : Set α) =ᵐ[μ] (blimsup (fun i => thickening (r i) (s i)) atTop p : Set α) := by have h₁ := blimsup_cthickening_ae_eq_blimsup_thickening (s := s) μ hr hr'
have h₂ := blimsup_cthickening_mul_ae_eq μ p s hM r hr replace hr : Tendsto (fun i => M * r i) atTop (𝓝 0) := by convert hr.const_mul M; simp replace hr' : ∀ᶠ i in atTop, p i → 0 < M * r i := hr'.mono fun i hi hip ↦ mul_pos hM (hi hip) have h₃ := blimsup_cthickening_ae_eq_blimsup_thickening (s := s) μ hr hr' exact h₃.symm.trans (h₂.trans h₁) /-- Given a sequence of subsets `sᵢ` of a metric space, together with a sequence of radii `rᵢ` such that `rᵢ → 0`, the set of points which belong to infinitely many of the `rᵢ`-thickenings of `sᵢ` is unchanged almost everywhere for a uniformly locally doubling measure if the `rᵢ` are all scaled by a positive constant.
Mathlib/MeasureTheory/Covering/LiminfLimsup.lean
247
256
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Jeremy Avigad, Simon Hudon -/ import Mathlib.Algebra.Notation.Defs import Mathlib.Data.Set.Subsingleton import Mathlib.Logic.Equiv.Defs /-! # Partial values of a type This file defines `Part α`, the partial values of a type. `o : Part α` carries a proposition `o.Dom`, its domain, along with a function `get : o.Dom → α`, its value. The rule is then that every partial value has a value but, to access it, you need to provide a proof of the domain. `Part α` behaves the same as `Option α` except that `o : Option α` is decidably `none` or `some a` for some `a : α`, while the domain of `o : Part α` doesn't have to be decidable. That means you can translate back and forth between a partial value with a decidable domain and an option, and `Option α` and `Part α` are classically equivalent. In general, `Part α` is bigger than `Option α`. In current mathlib, `Part ℕ`, aka `PartENat`, is used to move decidability of the order to decidability of `PartENat.find` (which is the smallest natural satisfying a predicate, or `∞` if there's none). ## Main declarations `Option`-like declarations: * `Part.none`: The partial value whose domain is `False`. * `Part.some a`: The partial value whose domain is `True` and whose value is `a`. * `Part.ofOption`: Converts an `Option α` to a `Part α` by sending `none` to `none` and `some a` to `some a`. * `Part.toOption`: Converts a `Part α` with a decidable domain to an `Option α`. * `Part.equivOption`: Classical equivalence between `Part α` and `Option α`. Monadic structure: * `Part.bind`: `o.bind f` has value `(f (o.get _)).get _` (`f o` morally) and is defined when `o` and `f (o.get _)` are defined. * `Part.map`: Maps the value and keeps the same domain. Other: * `Part.restrict`: `Part.restrict p o` replaces the domain of `o : Part α` by `p : Prop` so long as `p → o.Dom`. * `Part.assert`: `assert p f` appends `p` to the domains of the values of a partial function. * `Part.unwrap`: Gets the value of a partial value regardless of its domain. Unsound. ## Notation For `a : α`, `o : Part α`, `a ∈ o` means that `o` is defined and equal to `a`. Formally, it means `o.Dom` and `o.get _ = a`. -/ assert_not_exists RelIso open Function /-- `Part α` is the type of "partial values" of type `α`. It is similar to `Option α` except the domain condition can be an arbitrary proposition, not necessarily decidable. -/ structure Part.{u} (α : Type u) : Type u where /-- The domain of a partial value -/ Dom : Prop /-- Extract a value from a partial value given a proof of `Dom` -/ get : Dom → α namespace Part variable {α : Type*} {β : Type*} {γ : Type*} /-- Convert a `Part α` with a decidable domain to an option -/ def toOption (o : Part α) [Decidable o.Dom] : Option α := if h : Dom o then some (o.get h) else none @[simp] lemma toOption_isSome (o : Part α) [Decidable o.Dom] : o.toOption.isSome ↔ o.Dom := by by_cases h : o.Dom <;> simp [h, toOption] @[simp] lemma toOption_eq_none (o : Part α) [Decidable o.Dom] : o.toOption = none ↔ ¬o.Dom := by by_cases h : o.Dom <;> simp [h, toOption] /-- `Part` extensionality -/ theorem ext' : ∀ {o p : Part α}, (o.Dom ↔ p.Dom) → (∀ h₁ h₂, o.get h₁ = p.get h₂) → o = p | ⟨od, o⟩, ⟨pd, p⟩, H1, H2 => by have t : od = pd := propext H1 cases t; rw [show o = p from funext fun p => H2 p p] /-- `Part` eta expansion -/ @[simp] theorem eta : ∀ o : Part α, (⟨o.Dom, fun h => o.get h⟩ : Part α) = o | ⟨_, _⟩ => rfl /-- `a ∈ o` means that `o` is defined and equal to `a` -/ protected def Mem (o : Part α) (a : α) : Prop := ∃ h, o.get h = a instance : Membership α (Part α) := ⟨Part.Mem⟩ theorem mem_eq (a : α) (o : Part α) : (a ∈ o) = ∃ h, o.get h = a := rfl theorem dom_iff_mem : ∀ {o : Part α}, o.Dom ↔ ∃ y, y ∈ o | ⟨_, f⟩ => ⟨fun h => ⟨f h, h, rfl⟩, fun ⟨_, h, rfl⟩ => h⟩ theorem get_mem {o : Part α} (h) : get o h ∈ o := ⟨_, rfl⟩ @[simp] theorem mem_mk_iff {p : Prop} {o : p → α} {a : α} : a ∈ Part.mk p o ↔ ∃ h, o h = a := Iff.rfl /-- `Part` extensionality -/ @[ext] theorem ext {o p : Part α} (H : ∀ a, a ∈ o ↔ a ∈ p) : o = p := (ext' ⟨fun h => ((H _).1 ⟨h, rfl⟩).fst, fun h => ((H _).2 ⟨h, rfl⟩).fst⟩) fun _ _ => ((H _).2 ⟨_, rfl⟩).snd /-- The `none` value in `Part` has a `False` domain and an empty function. -/ def none : Part α := ⟨False, False.rec⟩ instance : Inhabited (Part α) := ⟨none⟩ @[simp] theorem not_mem_none (a : α) : a ∉ @none α := fun h => h.fst /-- The `some a` value in `Part` has a `True` domain and the function returns `a`. -/ def some (a : α) : Part α := ⟨True, fun _ => a⟩ @[simp] theorem some_dom (a : α) : (some a).Dom := trivial theorem mem_unique : ∀ {a b : α} {o : Part α}, a ∈ o → b ∈ o → a = b | _, _, ⟨_, _⟩, ⟨_, rfl⟩, ⟨_, rfl⟩ => rfl theorem mem_right_unique : ∀ {a : α} {o p : Part α}, a ∈ o → a ∈ p → o = p | _, _, _, ⟨ho, _⟩, ⟨hp, _⟩ => ext' (iff_of_true ho hp) (by simp [*]) theorem Mem.left_unique : Relator.LeftUnique ((· ∈ ·) : α → Part α → Prop) := fun _ _ _ => mem_unique theorem Mem.right_unique : Relator.RightUnique ((· ∈ ·) : α → Part α → Prop) := fun _ _ _ => mem_right_unique theorem get_eq_of_mem {o : Part α} {a} (h : a ∈ o) (h') : get o h' = a := mem_unique ⟨_, rfl⟩ h protected theorem subsingleton (o : Part α) : Set.Subsingleton { a | a ∈ o } := fun _ ha _ hb => mem_unique ha hb @[simp] theorem get_some {a : α} (ha : (some a).Dom) : get (some a) ha = a := rfl theorem mem_some (a : α) : a ∈ some a := ⟨trivial, rfl⟩ @[simp] theorem mem_some_iff {a b} : b ∈ (some a : Part α) ↔ b = a := ⟨fun ⟨_, e⟩ => e.symm, fun e => ⟨trivial, e.symm⟩⟩ theorem eq_some_iff {a : α} {o : Part α} : o = some a ↔ a ∈ o := ⟨fun e => e.symm ▸ mem_some _, fun ⟨h, e⟩ => e ▸ ext' (iff_true_intro h) fun _ _ => rfl⟩ theorem eq_none_iff {o : Part α} : o = none ↔ ∀ a, a ∉ o := ⟨fun e => e.symm ▸ not_mem_none, fun h => ext (by simpa)⟩ theorem eq_none_iff' {o : Part α} : o = none ↔ ¬o.Dom := ⟨fun e => e.symm ▸ id, fun h => eq_none_iff.2 fun _ h' => h h'.fst⟩ @[simp] theorem not_none_dom : ¬(none : Part α).Dom := id @[simp] theorem some_ne_none (x : α) : some x ≠ none := by intro h exact true_ne_false (congr_arg Dom h) @[simp] theorem none_ne_some (x : α) : none ≠ some x := (some_ne_none x).symm theorem ne_none_iff {o : Part α} : o ≠ none ↔ ∃ x, o = some x := by constructor · rw [Ne, eq_none_iff', not_not] exact fun h => ⟨o.get h, eq_some_iff.2 (get_mem h)⟩ · rintro ⟨x, rfl⟩ apply some_ne_none theorem eq_none_or_eq_some (o : Part α) : o = none ∨ ∃ x, o = some x := or_iff_not_imp_left.2 ne_none_iff.1 theorem some_injective : Injective (@Part.some α) := fun _ _ h => congr_fun (eq_of_heq (Part.mk.inj h).2) trivial @[simp] theorem some_inj {a b : α} : Part.some a = some b ↔ a = b := some_injective.eq_iff @[simp] theorem some_get {a : Part α} (ha : a.Dom) : Part.some (Part.get a ha) = a := Eq.symm (eq_some_iff.2 ⟨ha, rfl⟩) theorem get_eq_iff_eq_some {a : Part α} {ha : a.Dom} {b : α} : a.get ha = b ↔ a = some b := ⟨fun h => by simp [h.symm], fun h => by simp [h]⟩ theorem get_eq_get_of_eq (a : Part α) (ha : a.Dom) {b : Part α} (h : a = b) : a.get ha = b.get (h ▸ ha) := by congr theorem get_eq_iff_mem {o : Part α} {a : α} (h : o.Dom) : o.get h = a ↔ a ∈ o := ⟨fun H => ⟨h, H⟩, fun ⟨_, H⟩ => H⟩ theorem eq_get_iff_mem {o : Part α} {a : α} (h : o.Dom) : a = o.get h ↔ a ∈ o := eq_comm.trans (get_eq_iff_mem h) @[simp] theorem none_toOption [Decidable (@none α).Dom] : (none : Part α).toOption = Option.none := dif_neg id @[simp] theorem some_toOption (a : α) [Decidable (some a).Dom] : (some a).toOption = Option.some a := dif_pos trivial instance noneDecidable : Decidable (@none α).Dom := instDecidableFalse instance someDecidable (a : α) : Decidable (some a).Dom := instDecidableTrue /-- Retrieves the value of `a : Part α` if it exists, and return the provided default value otherwise. -/ def getOrElse (a : Part α) [Decidable a.Dom] (d : α) := if ha : a.Dom then a.get ha else d theorem getOrElse_of_dom (a : Part α) (h : a.Dom) [Decidable a.Dom] (d : α) : getOrElse a d = a.get h := dif_pos h theorem getOrElse_of_not_dom (a : Part α) (h : ¬a.Dom) [Decidable a.Dom] (d : α) : getOrElse a d = d := dif_neg h @[simp] theorem getOrElse_none (d : α) [Decidable (none : Part α).Dom] : getOrElse none d = d := none.getOrElse_of_not_dom not_none_dom d @[simp] theorem getOrElse_some (a : α) (d : α) [Decidable (some a).Dom] : getOrElse (some a) d = a := (some a).getOrElse_of_dom (some_dom a) d -- `simp`-normal form is `toOption_eq_some_iff`. theorem mem_toOption {o : Part α} [Decidable o.Dom] {a : α} : a ∈ toOption o ↔ a ∈ o := by unfold toOption by_cases h : o.Dom <;> simp [h] · exact ⟨fun h => ⟨_, h⟩, fun ⟨_, h⟩ => h⟩ · exact mt Exists.fst h @[simp] theorem toOption_eq_some_iff {o : Part α} [Decidable o.Dom] {a : α} : toOption o = Option.some a ↔ a ∈ o := by rw [← Option.mem_def, mem_toOption] protected theorem Dom.toOption {o : Part α} [Decidable o.Dom] (h : o.Dom) : o.toOption = o.get h := dif_pos h theorem toOption_eq_none_iff {a : Part α} [Decidable a.Dom] : a.toOption = Option.none ↔ ¬a.Dom := Ne.dite_eq_right_iff fun _ => Option.some_ne_none _ @[simp] theorem elim_toOption {α β : Type*} (a : Part α) [Decidable a.Dom] (b : β) (f : α → β) : a.toOption.elim b f = if h : a.Dom then f (a.get h) else b := by split_ifs with h · rw [h.toOption] rfl · rw [Part.toOption_eq_none_iff.2 h] rfl /-- Converts an `Option α` into a `Part α`. -/ @[coe] def ofOption : Option α → Part α | Option.none => none | Option.some a => some a @[simp] theorem mem_ofOption {a : α} : ∀ {o : Option α}, a ∈ ofOption o ↔ a ∈ o | Option.none => ⟨fun h => h.fst.elim, fun h => Option.noConfusion h⟩ | Option.some _ => ⟨fun h => congr_arg Option.some h.snd, fun h => ⟨trivial, Option.some.inj h⟩⟩ @[simp] theorem ofOption_dom {α} : ∀ o : Option α, (ofOption o).Dom ↔ o.isSome | Option.none => by simp [ofOption, none] | Option.some a => by simp [ofOption] theorem ofOption_eq_get {α} (o : Option α) : ofOption o = ⟨_, @Option.get _ o⟩ := Part.ext' (ofOption_dom o) fun h₁ h₂ => by cases o · simp at h₂ · rfl instance : Coe (Option α) (Part α) := ⟨ofOption⟩ theorem mem_coe {a : α} {o : Option α} : a ∈ (o : Part α) ↔ a ∈ o := mem_ofOption @[simp] theorem coe_none : (@Option.none α : Part α) = none := rfl @[simp] theorem coe_some (a : α) : (Option.some a : Part α) = some a := rfl @[elab_as_elim] protected theorem induction_on {P : Part α → Prop} (a : Part α) (hnone : P none) (hsome : ∀ a : α, P (some a)) : P a := (Classical.em a.Dom).elim (fun h => Part.some_get h ▸ hsome _) fun h => (eq_none_iff'.2 h).symm ▸ hnone instance ofOptionDecidable : ∀ o : Option α, Decidable (ofOption o).Dom | Option.none => Part.noneDecidable | Option.some a => Part.someDecidable a @[simp] theorem to_ofOption (o : Option α) : toOption (ofOption o) = o := by cases o <;> rfl @[simp] theorem of_toOption (o : Part α) [Decidable o.Dom] : ofOption (toOption o) = o := ext fun _ => mem_ofOption.trans mem_toOption /-- `Part α` is (classically) equivalent to `Option α`. -/ noncomputable def equivOption : Part α ≃ Option α := haveI := Classical.dec ⟨fun o => toOption o, ofOption, fun o => of_toOption o, fun o => Eq.trans (by dsimp; congr) (to_ofOption o)⟩ /-- We give `Part α` the order where everything is greater than `none`. -/ instance : PartialOrder (Part α) where le x y := ∀ i, i ∈ x → i ∈ y le_refl _ _ := id le_trans _ _ _ f g _ := g _ ∘ f _ le_antisymm _ _ f g := Part.ext fun _ => ⟨f _, g _⟩ instance : OrderBot (Part α) where bot := none bot_le := by rintro x _ ⟨⟨_⟩, _⟩ theorem le_total_of_le_of_le {x y : Part α} (z : Part α) (hx : x ≤ z) (hy : y ≤ z) : x ≤ y ∨ y ≤ x := by rcases Part.eq_none_or_eq_some x with (h | ⟨b, h₀⟩) · rw [h] left apply OrderBot.bot_le _ right; intro b' h₁ rw [Part.eq_some_iff] at h₀ have hx := hx _ h₀; have hy := hy _ h₁ have hx := Part.mem_unique hx hy; subst hx exact h₀ /-- `assert p f` is a bind-like operation which appends an additional condition `p` to the domain and uses `f` to produce the value. -/ def assert (p : Prop) (f : p → Part α) : Part α := ⟨∃ h : p, (f h).Dom, fun ha => (f ha.fst).get ha.snd⟩ /-- The bind operation has value `g (f.get)`, and is defined when all the parts are defined. -/ protected def bind (f : Part α) (g : α → Part β) : Part β := assert (Dom f) fun b => g (f.get b) /-- The map operation for `Part` just maps the value and maintains the same domain. -/ @[simps] def map (f : α → β) (o : Part α) : Part β := ⟨o.Dom, f ∘ o.get⟩ theorem mem_map (f : α → β) {o : Part α} : ∀ {a}, a ∈ o → f a ∈ map f o | _, ⟨_, rfl⟩ => ⟨_, rfl⟩ @[simp] theorem mem_map_iff (f : α → β) {o : Part α} {b} : b ∈ map f o ↔ ∃ a ∈ o, f a = b := ⟨fun hb => match b, hb with | _, ⟨_, rfl⟩ => ⟨_, ⟨_, rfl⟩, rfl⟩, fun ⟨_, h₁, h₂⟩ => h₂ ▸ mem_map f h₁⟩ @[simp] theorem map_none (f : α → β) : map f none = none := eq_none_iff.2 fun a => by simp @[simp] theorem map_some (f : α → β) (a : α) : map f (some a) = some (f a) := eq_some_iff.2 <| mem_map f <| mem_some _ theorem mem_assert {p : Prop} {f : p → Part α} : ∀ {a} (h : p), a ∈ f h → a ∈ assert p f | _, x, ⟨h, rfl⟩ => ⟨⟨x, h⟩, rfl⟩ @[simp] theorem mem_assert_iff {p : Prop} {f : p → Part α} {a} : a ∈ assert p f ↔ ∃ h : p, a ∈ f h := ⟨fun ha => match a, ha with | _, ⟨_, rfl⟩ => ⟨_, ⟨_, rfl⟩⟩, fun ⟨_, h⟩ => mem_assert _ h⟩ theorem assert_pos {p : Prop} {f : p → Part α} (h : p) : assert p f = f h := by dsimp [assert] cases h' : f h simp only [h', mk.injEq, h, exists_prop_of_true, true_and] apply Function.hfunext · simp only [h, h', exists_prop_of_true] · simp theorem assert_neg {p : Prop} {f : p → Part α} (h : ¬p) : assert p f = none := by dsimp [assert, none]; congr · simp only [h, not_false_iff, exists_prop_of_false] · apply Function.hfunext · simp only [h, not_false_iff, exists_prop_of_false] simp at * theorem mem_bind {f : Part α} {g : α → Part β} : ∀ {a b}, a ∈ f → b ∈ g a → b ∈ f.bind g | _, _, ⟨h, rfl⟩, ⟨h₂, rfl⟩ => ⟨⟨h, h₂⟩, rfl⟩ @[simp] theorem mem_bind_iff {f : Part α} {g : α → Part β} {b} : b ∈ f.bind g ↔ ∃ a ∈ f, b ∈ g a := ⟨fun hb => match b, hb with | _, ⟨⟨_, _⟩, rfl⟩ => ⟨_, ⟨_, rfl⟩, ⟨_, rfl⟩⟩, fun ⟨_, h₁, h₂⟩ => mem_bind h₁ h₂⟩ protected theorem Dom.bind {o : Part α} (h : o.Dom) (f : α → Part β) : o.bind f = f (o.get h) := by ext b simp only [Part.mem_bind_iff, exists_prop] refine ⟨?_, fun hb => ⟨o.get h, Part.get_mem _, hb⟩⟩ rintro ⟨a, ha, hb⟩ rwa [Part.get_eq_of_mem ha] theorem Dom.of_bind {f : α → Part β} {a : Part α} (h : (a.bind f).Dom) : a.Dom := h.1 @[simp] theorem bind_none (f : α → Part β) : none.bind f = none := eq_none_iff.2 fun a => by simp @[simp] theorem bind_some (a : α) (f : α → Part β) : (some a).bind f = f a := ext <| by simp theorem bind_of_mem {o : Part α} {a : α} (h : a ∈ o) (f : α → Part β) : o.bind f = f a := by rw [eq_some_iff.2 h, bind_some] theorem bind_some_eq_map (f : α → β) (x : Part α) : x.bind (fun y => some (f y)) = map f x := ext <| by simp [eq_comm] theorem bind_toOption (f : α → Part β) (o : Part α) [Decidable o.Dom] [∀ a, Decidable (f a).Dom] [Decidable (o.bind f).Dom] : (o.bind f).toOption = o.toOption.elim Option.none fun a => (f a).toOption := by by_cases h : o.Dom · simp_rw [h.toOption, h.bind] rfl · rw [Part.toOption_eq_none_iff.2 h] exact Part.toOption_eq_none_iff.2 fun ho => h ho.of_bind theorem bind_assoc {γ} (f : Part α) (g : α → Part β) (k : β → Part γ) : (f.bind g).bind k = f.bind fun x => (g x).bind k := ext fun a => by simp only [mem_bind_iff] exact ⟨fun ⟨_, ⟨_, h₁, h₂⟩, h₃⟩ => ⟨_, h₁, _, h₂, h₃⟩, fun ⟨_, h₁, _, h₂, h₃⟩ => ⟨_, ⟨_, h₁, h₂⟩, h₃⟩⟩ @[simp] theorem bind_map {γ} (f : α → β) (x) (g : β → Part γ) : (map f x).bind g = x.bind fun y => g (f y) := by rw [← bind_some_eq_map, bind_assoc]; simp @[simp] theorem map_bind {γ} (f : α → Part β) (x : Part α) (g : β → γ) : map g (x.bind f) = x.bind fun y => map g (f y) := by rw [← bind_some_eq_map, bind_assoc]; simp [bind_some_eq_map] theorem map_map (g : β → γ) (f : α → β) (o : Part α) : map g (map f o) = map (g ∘ f) o := by simp [map, Function.comp_assoc] instance : Monad Part where pure := @some map := @map bind := @Part.bind instance : LawfulMonad Part where bind_pure_comp := @bind_some_eq_map id_map f := by cases f; rfl pure_bind := @bind_some bind_assoc := @bind_assoc map_const := by simp [Functor.mapConst, Functor.map] --Porting TODO : In Lean3 these were automatic by a tactic seqLeft_eq x y := ext' (by simp [SeqLeft.seqLeft, Part.bind, assert, Seq.seq, const, (· <$> ·), and_comm]) (fun _ _ => rfl) seqRight_eq x y := ext' (by simp [SeqRight.seqRight, Part.bind, assert, Seq.seq, const, (· <$> ·), and_comm]) (fun _ _ => rfl) pure_seq x y := ext' (by simp [Seq.seq, Part.bind, assert, (· <$> ·), pure]) (fun _ _ => rfl) bind_map x y := ext' (by simp [(· >>= ·), Part.bind, assert, Seq.seq, get, (· <$> ·)] ) (fun _ _ => rfl) theorem map_id' {f : α → α} (H : ∀ x : α, f x = x) (o) : map f o = o := by rw [show f = id from funext H]; exact id_map o @[simp] theorem bind_some_right (x : Part α) : x.bind some = x := by rw [bind_some_eq_map] simp [map_id'] @[simp] theorem pure_eq_some (a : α) : pure a = some a := rfl @[simp] theorem ret_eq_some (a : α) : (return a : Part α) = some a := rfl @[simp] theorem map_eq_map {α β} (f : α → β) (o : Part α) : f <$> o = map f o := rfl @[simp] theorem bind_eq_bind {α β} (f : Part α) (g : α → Part β) : f >>= g = f.bind g := rfl theorem bind_le {α} (x : Part α) (f : α → Part β) (y : Part β) : x >>= f ≤ y ↔ ∀ a, a ∈ x → f a ≤ y := by constructor <;> intro h · intro a h' b have h := h b simp only [and_imp, exists_prop, bind_eq_bind, mem_bind_iff, exists_imp] at h apply h _ h' · intro b h' simp only [exists_prop, bind_eq_bind, mem_bind_iff] at h' rcases h' with ⟨a, h₀, h₁⟩ apply h _ h₀ _ h₁ -- TODO: if `MonadFail` is defined, define the below instance. -- instance : MonadFail Part := -- { Part.monad with fail := fun _ _ => none } /-- `restrict p o h` replaces the domain of `o` with `p`, and is well defined when `p` implies `o` is defined. -/ def restrict (p : Prop) (o : Part α) (H : p → o.Dom) : Part α := ⟨p, fun h => o.get (H h)⟩ @[simp] theorem mem_restrict (p : Prop) (o : Part α) (h : p → o.Dom) (a : α) : a ∈ restrict p o h ↔ p ∧ a ∈ o := by dsimp [restrict, mem_eq]; constructor · rintro ⟨h₀, h₁⟩ exact ⟨h₀, ⟨_, h₁⟩⟩ rintro ⟨h₀, _, h₂⟩; exact ⟨h₀, h₂⟩ /-- `unwrap o` gets the value at `o`, ignoring the condition. This function is unsound. -/ unsafe def unwrap (o : Part α) : α := o.get lcProof theorem assert_defined {p : Prop} {f : p → Part α} : ∀ h : p, (f h).Dom → (assert p f).Dom := Exists.intro theorem bind_defined {f : Part α} {g : α → Part β} : ∀ h : f.Dom, (g (f.get h)).Dom → (f.bind g).Dom := assert_defined @[simp] theorem bind_dom {f : Part α} {g : α → Part β} : (f.bind g).Dom ↔ ∃ h : f.Dom, (g (f.get h)).Dom := Iff.rfl section Instances /-! We define several instances for constants and operations on `Part α` inherited from `α`. This section could be moved to a separate file to avoid the import of `Mathlib.Algebra.Group.Defs`. -/ @[to_additive] instance [One α] : One (Part α) where one := pure 1 @[to_additive] instance [Mul α] : Mul (Part α) where mul a b := (· * ·) <$> a <*> b @[to_additive] instance [Inv α] : Inv (Part α) where inv := map Inv.inv @[to_additive] instance [Div α] : Div (Part α) where div a b := (· / ·) <$> a <*> b instance [Mod α] : Mod (Part α) where mod a b := (· % ·) <$> a <*> b instance [Append α] : Append (Part α) where append a b := (· ++ ·) <$> a <*> b instance [Inter α] : Inter (Part α) where inter a b := (· ∩ ·) <$> a <*> b instance [Union α] : Union (Part α) where union a b := (· ∪ ·) <$> a <*> b instance [SDiff α] : SDiff (Part α) where sdiff a b := (· \ ·) <$> a <*> b section @[to_additive] theorem mul_def [Mul α] (a b : Part α) : a * b = bind a fun y ↦ map (y * ·) b := rfl @[to_additive] theorem one_def [One α] : (1 : Part α) = some 1 := rfl @[to_additive] theorem inv_def [Inv α] (a : Part α) : a⁻¹ = Part.map (· ⁻¹) a := rfl @[to_additive] theorem div_def [Div α] (a b : Part α) : a / b = bind a fun y => map (y / ·) b := rfl theorem mod_def [Mod α] (a b : Part α) : a % b = bind a fun y => map (y % ·) b := rfl theorem append_def [Append α] (a b : Part α) : a ++ b = bind a fun y => map (y ++ ·) b := rfl theorem inter_def [Inter α] (a b : Part α) : a ∩ b = bind a fun y => map (y ∩ ·) b := rfl theorem union_def [Union α] (a b : Part α) : a ∪ b = bind a fun y => map (y ∪ ·) b := rfl theorem sdiff_def [SDiff α] (a b : Part α) : a \ b = bind a fun y => map (y \ ·) b := rfl end @[to_additive] theorem one_mem_one [One α] : (1 : α) ∈ (1 : Part α) := ⟨trivial, rfl⟩ @[to_additive] theorem mul_mem_mul [Mul α] (a b : Part α) (ma mb : α) (ha : ma ∈ a) (hb : mb ∈ b) : ma * mb ∈ a * b := ⟨⟨ha.1, hb.1⟩, by simp only [← ha.2, ← hb.2]; rfl⟩ @[to_additive] theorem left_dom_of_mul_dom [Mul α] {a b : Part α} (hab : Dom (a * b)) : a.Dom := hab.1 @[to_additive] theorem right_dom_of_mul_dom [Mul α] {a b : Part α} (hab : Dom (a * b)) : b.Dom := hab.2 @[to_additive (attr := simp)] theorem mul_get_eq [Mul α] (a b : Part α) (hab : Dom (a * b)) : (a * b).get hab = a.get (left_dom_of_mul_dom hab) * b.get (right_dom_of_mul_dom hab) := rfl @[to_additive] theorem some_mul_some [Mul α] (a b : α) : some a * some b = some (a * b) := by simp [mul_def] @[to_additive] theorem inv_mem_inv [Inv α] (a : Part α) (ma : α) (ha : ma ∈ a) : ma⁻¹ ∈ a⁻¹ := by simp [inv_def]; aesop @[to_additive] theorem inv_some [Inv α] (a : α) : (some a)⁻¹ = some a⁻¹ := rfl @[to_additive] theorem div_mem_div [Div α] (a b : Part α) (ma mb : α) (ha : ma ∈ a) (hb : mb ∈ b) : ma / mb ∈ a / b := by simp [div_def]; aesop @[to_additive] theorem left_dom_of_div_dom [Div α] {a b : Part α} (hab : Dom (a / b)) : a.Dom := hab.1 @[to_additive] theorem right_dom_of_div_dom [Div α] {a b : Part α} (hab : Dom (a / b)) : b.Dom := hab.2 @[to_additive (attr := simp)] theorem div_get_eq [Div α] (a b : Part α) (hab : Dom (a / b)) : (a / b).get hab = a.get (left_dom_of_div_dom hab) / b.get (right_dom_of_div_dom hab) := by simp [div_def]; aesop @[to_additive] theorem some_div_some [Div α] (a b : α) : some a / some b = some (a / b) := by simp [div_def] theorem mod_mem_mod [Mod α] (a b : Part α) (ma mb : α) (ha : ma ∈ a) (hb : mb ∈ b) : ma % mb ∈ a % b := by simp [mod_def]; aesop theorem left_dom_of_mod_dom [Mod α] {a b : Part α} (hab : Dom (a % b)) : a.Dom := hab.1 theorem right_dom_of_mod_dom [Mod α] {a b : Part α} (hab : Dom (a % b)) : b.Dom := hab.2 @[simp] theorem mod_get_eq [Mod α] (a b : Part α) (hab : Dom (a % b)) : (a % b).get hab = a.get (left_dom_of_mod_dom hab) % b.get (right_dom_of_mod_dom hab) := by simp [mod_def]; aesop theorem some_mod_some [Mod α] (a b : α) : some a % some b = some (a % b) := by simp [mod_def] theorem append_mem_append [Append α] (a b : Part α) (ma mb : α) (ha : ma ∈ a) (hb : mb ∈ b) : ma ++ mb ∈ a ++ b := by simp [append_def]; aesop theorem left_dom_of_append_dom [Append α] {a b : Part α} (hab : Dom (a ++ b)) : a.Dom := hab.1 theorem right_dom_of_append_dom [Append α] {a b : Part α} (hab : Dom (a ++ b)) : b.Dom := hab.2 @[simp] theorem append_get_eq [Append α] (a b : Part α) (hab : Dom (a ++ b)) : (a ++ b).get hab = a.get (left_dom_of_append_dom hab) ++ b.get (right_dom_of_append_dom hab) := by simp [append_def]; aesop theorem some_append_some [Append α] (a b : α) : some a ++ some b = some (a ++ b) := by simp [append_def] theorem inter_mem_inter [Inter α] (a b : Part α) (ma mb : α) (ha : ma ∈ a) (hb : mb ∈ b) : ma ∩ mb ∈ a ∩ b := by simp [inter_def]; aesop theorem left_dom_of_inter_dom [Inter α] {a b : Part α} (hab : Dom (a ∩ b)) : a.Dom := hab.1 theorem right_dom_of_inter_dom [Inter α] {a b : Part α} (hab : Dom (a ∩ b)) : b.Dom := hab.2 @[simp] theorem inter_get_eq [Inter α] (a b : Part α) (hab : Dom (a ∩ b)) : (a ∩ b).get hab = a.get (left_dom_of_inter_dom hab) ∩ b.get (right_dom_of_inter_dom hab) := by simp [inter_def]; aesop theorem some_inter_some [Inter α] (a b : α) : some a ∩ some b = some (a ∩ b) := by simp [inter_def] theorem union_mem_union [Union α] (a b : Part α) (ma mb : α) (ha : ma ∈ a) (hb : mb ∈ b) : ma ∪ mb ∈ a ∪ b := by simp [union_def]; aesop theorem left_dom_of_union_dom [Union α] {a b : Part α} (hab : Dom (a ∪ b)) : a.Dom := hab.1 theorem right_dom_of_union_dom [Union α] {a b : Part α} (hab : Dom (a ∪ b)) : b.Dom := hab.2
@[simp] theorem union_get_eq [Union α] (a b : Part α) (hab : Dom (a ∪ b)) :
Mathlib/Data/Part.lean
719
720
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot, Yury Kudryashov, Rémy Degenne -/ import Mathlib.Algebra.Order.Group.Abs import Mathlib.Algebra.Order.Group.Basic import Mathlib.Algebra.Order.Ring.Defs import Mathlib.Order.Interval.Set.Basic import Mathlib.Logic.Pairwise /-! ### Lemmas about arithmetic operations and intervals. -/ variable {α : Type*} namespace Set section OrderedCommGroup variable [CommGroup α] [PartialOrder α] [IsOrderedMonoid α] {a c d : α} /-! `inv_mem_Ixx_iff`, `sub_mem_Ixx_iff` -/ @[to_additive] theorem inv_mem_Icc_iff : a⁻¹ ∈ Set.Icc c d ↔ a ∈ Set.Icc d⁻¹ c⁻¹ := and_comm.trans <| and_congr inv_le' le_inv' @[to_additive] theorem inv_mem_Ico_iff : a⁻¹ ∈ Set.Ico c d ↔ a ∈ Set.Ioc d⁻¹ c⁻¹ := and_comm.trans <| and_congr inv_lt' le_inv' @[to_additive] theorem inv_mem_Ioc_iff : a⁻¹ ∈ Set.Ioc c d ↔ a ∈ Set.Ico d⁻¹ c⁻¹ := and_comm.trans <| and_congr inv_le' lt_inv' @[to_additive] theorem inv_mem_Ioo_iff : a⁻¹ ∈ Set.Ioo c d ↔ a ∈ Set.Ioo d⁻¹ c⁻¹ := and_comm.trans <| and_congr inv_lt' lt_inv' end OrderedCommGroup section OrderedAddCommGroup variable [AddCommGroup α] [PartialOrder α] [IsOrderedAddMonoid α] {a b c d : α} /-! `add_mem_Ixx_iff_left` -/ theorem add_mem_Icc_iff_left : a + b ∈ Set.Icc c d ↔ a ∈ Set.Icc (c - b) (d - b) := (and_congr sub_le_iff_le_add le_sub_iff_add_le).symm theorem add_mem_Ico_iff_left : a + b ∈ Set.Ico c d ↔ a ∈ Set.Ico (c - b) (d - b) := (and_congr sub_le_iff_le_add lt_sub_iff_add_lt).symm theorem add_mem_Ioc_iff_left : a + b ∈ Set.Ioc c d ↔ a ∈ Set.Ioc (c - b) (d - b) := (and_congr sub_lt_iff_lt_add le_sub_iff_add_le).symm theorem add_mem_Ioo_iff_left : a + b ∈ Set.Ioo c d ↔ a ∈ Set.Ioo (c - b) (d - b) := (and_congr sub_lt_iff_lt_add lt_sub_iff_add_lt).symm /-! `add_mem_Ixx_iff_right` -/ theorem add_mem_Icc_iff_right : a + b ∈ Set.Icc c d ↔ b ∈ Set.Icc (c - a) (d - a) := (and_congr sub_le_iff_le_add' le_sub_iff_add_le').symm theorem add_mem_Ico_iff_right : a + b ∈ Set.Ico c d ↔ b ∈ Set.Ico (c - a) (d - a) := (and_congr sub_le_iff_le_add' lt_sub_iff_add_lt').symm theorem add_mem_Ioc_iff_right : a + b ∈ Set.Ioc c d ↔ b ∈ Set.Ioc (c - a) (d - a) := (and_congr sub_lt_iff_lt_add' le_sub_iff_add_le').symm theorem add_mem_Ioo_iff_right : a + b ∈ Set.Ioo c d ↔ b ∈ Set.Ioo (c - a) (d - a) := (and_congr sub_lt_iff_lt_add' lt_sub_iff_add_lt').symm /-! `sub_mem_Ixx_iff_left` -/ theorem sub_mem_Icc_iff_left : a - b ∈ Set.Icc c d ↔ a ∈ Set.Icc (c + b) (d + b) := and_congr le_sub_iff_add_le sub_le_iff_le_add theorem sub_mem_Ico_iff_left : a - b ∈ Set.Ico c d ↔ a ∈ Set.Ico (c + b) (d + b) := and_congr le_sub_iff_add_le sub_lt_iff_lt_add theorem sub_mem_Ioc_iff_left : a - b ∈ Set.Ioc c d ↔ a ∈ Set.Ioc (c + b) (d + b) := and_congr lt_sub_iff_add_lt sub_le_iff_le_add theorem sub_mem_Ioo_iff_left : a - b ∈ Set.Ioo c d ↔ a ∈ Set.Ioo (c + b) (d + b) := and_congr lt_sub_iff_add_lt sub_lt_iff_lt_add /-! `sub_mem_Ixx_iff_right` -/ theorem sub_mem_Icc_iff_right : a - b ∈ Set.Icc c d ↔ b ∈ Set.Icc (a - d) (a - c) := and_comm.trans <| and_congr sub_le_comm le_sub_comm theorem sub_mem_Ico_iff_right : a - b ∈ Set.Ico c d ↔ b ∈ Set.Ioc (a - d) (a - c) := and_comm.trans <| and_congr sub_lt_comm le_sub_comm theorem sub_mem_Ioc_iff_right : a - b ∈ Set.Ioc c d ↔ b ∈ Set.Ico (a - d) (a - c) := and_comm.trans <| and_congr sub_le_comm lt_sub_comm theorem sub_mem_Ioo_iff_right : a - b ∈ Set.Ioo c d ↔ b ∈ Set.Ioo (a - d) (a - c) := and_comm.trans <| and_congr sub_lt_comm lt_sub_comm -- I think that symmetric intervals deserve attention and API: they arise all the time, -- for instance when considering metric balls in `ℝ`. theorem mem_Icc_iff_abs_le {R : Type*} [AddCommGroup R] [LinearOrder R] [IsOrderedAddMonoid R] {x y z : R} : |x - y| ≤ z ↔ y ∈ Icc (x - z) (x + z) := abs_le.trans <| and_comm.trans <| and_congr sub_le_comm neg_le_sub_iff_le_add /-! `sub_mem_Ixx_zero_right` and `sub_mem_Ixx_zero_iff_right`; this specializes the previous lemmas to the case of reflecting the interval. -/ theorem sub_mem_Icc_zero_iff_right : b - a ∈ Icc 0 b ↔ a ∈ Icc 0 b := by simp only [sub_mem_Icc_iff_right, sub_self, sub_zero] theorem sub_mem_Ico_zero_iff_right : b - a ∈ Ico 0 b ↔ a ∈ Ioc 0 b := by simp only [sub_mem_Ico_iff_right, sub_self, sub_zero] theorem sub_mem_Ioc_zero_iff_right : b - a ∈ Ioc 0 b ↔ a ∈ Ico 0 b := by simp only [sub_mem_Ioc_iff_right, sub_self, sub_zero] theorem sub_mem_Ioo_zero_iff_right : b - a ∈ Ioo 0 b ↔ a ∈ Ioo 0 b := by simp only [sub_mem_Ioo_iff_right, sub_self, sub_zero] end OrderedAddCommGroup section LinearOrderedAddCommGroup variable [AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α] /-- If we remove a smaller interval from a larger, the result is nonempty -/ theorem nonempty_Ico_sdiff {x dx y dy : α} (h : dy < dx) (hx : 0 < dx) : Nonempty ↑(Ico x (x + dx) \ Ico y (y + dy)) := by rcases lt_or_le x y with h' | h' · use x simp [*, not_le.2 h'] · use max x (x + dy) simp [*, le_refl] end LinearOrderedAddCommGroup /-! ### Lemmas about disjointness of translates of intervals -/ open scoped Function -- required for scoped `on` notation section PairwiseDisjoint section OrderedCommGroup variable [CommGroup α] [PartialOrder α] [IsOrderedMonoid α] (a b : α)
@[to_additive] theorem pairwise_disjoint_Ioc_mul_zpow : Pairwise (Disjoint on fun n : ℤ => Ioc (a * b ^ n) (a * b ^ (n + 1))) := by simp +unfoldPartialApp only [Function.onFun] simp_rw [Set.disjoint_iff] intro m n hmn x hx
Mathlib/Algebra/Order/Interval/Set/Group.lean
151
157
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl, Yuyang Zhao -/ import Mathlib.Algebra.Order.Monoid.Unbundled.Basic import Mathlib.Algebra.Order.ZeroLEOne import Mathlib.Data.Nat.Cast.Defs /-! # Order of numerals in an `AddMonoidWithOne`. -/ variable {α : Type*} open Function lemma lt_add_one [One α] [AddZeroClass α] [PartialOrder α] [ZeroLEOneClass α] [NeZero (1 : α)] [AddLeftStrictMono α] (a : α) : a < a + 1 := lt_add_of_pos_right _ zero_lt_one lemma lt_one_add [One α] [AddZeroClass α] [PartialOrder α] [ZeroLEOneClass α] [NeZero (1 : α)] [AddRightStrictMono α] (a : α) : a < 1 + a := lt_add_of_pos_left _ zero_lt_one variable [AddMonoidWithOne α] lemma zero_le_two [Preorder α] [ZeroLEOneClass α] [AddLeftMono α] : (0 : α) ≤ 2 := by rw [← one_add_one_eq_two] exact add_nonneg zero_le_one zero_le_one lemma zero_le_three [Preorder α] [ZeroLEOneClass α] [AddLeftMono α] : (0 : α) ≤ 3 := by rw [← two_add_one_eq_three] exact add_nonneg zero_le_two zero_le_one lemma zero_le_four [Preorder α] [ZeroLEOneClass α] [AddLeftMono α] : (0 : α) ≤ 4 := by rw [← three_add_one_eq_four] exact add_nonneg zero_le_three zero_le_one lemma one_le_two [LE α] [ZeroLEOneClass α] [AddLeftMono α] : (1 : α) ≤ 2 := calc (1 : α) = 1 + 0 := (add_zero 1).symm _ ≤ 1 + 1 := add_le_add_left zero_le_one _ _ = 2 := one_add_one_eq_two lemma one_le_two' [LE α] [ZeroLEOneClass α] [AddRightMono α] : (1 : α) ≤ 2 := calc (1 : α) = 0 + 1 := (zero_add 1).symm _ ≤ 1 + 1 := add_le_add_right zero_le_one _ _ = 2 := one_add_one_eq_two section variable [PartialOrder α] [ZeroLEOneClass α] [NeZero (1 : α)] section variable [AddLeftMono α] /-- See `zero_lt_two'` for a version with the type explicit. -/ @[simp] lemma zero_lt_two : (0 : α) < 2 := zero_lt_one.trans_le one_le_two /-- See `zero_lt_three'` for a version with the type explicit. -/ @[simp] lemma zero_lt_three : (0 : α) < 3 := by rw [← two_add_one_eq_three] exact lt_add_of_lt_of_nonneg zero_lt_two zero_le_one /-- See `zero_lt_four'` for a version with the type explicit. -/ @[simp] lemma zero_lt_four : (0 : α) < 4 := by rw [← three_add_one_eq_four] exact lt_add_of_lt_of_nonneg zero_lt_three zero_le_one
variable (α) /-- See `zero_lt_two` for a version with the type implicit. -/ lemma zero_lt_two' : (0 : α) < 2 := zero_lt_two
Mathlib/Algebra/Order/Monoid/NatCast.lean
74
77
/- Copyright (c) 2020 Kevin Buzzard, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Bhavik Mehta -/ import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Products import Mathlib.CategoryTheory.Limits.Yoneda import Mathlib.CategoryTheory.Preadditive.FunctorCategory import Mathlib.CategoryTheory.Sites.SheafOfTypes import Mathlib.CategoryTheory.Sites.EqualizerSheafCondition import Mathlib.CategoryTheory.Limits.Constructions.EpiMono /-! # Sheaves taking values in a category If C is a category with a Grothendieck topology, we define the notion of a sheaf taking values in an arbitrary category `A`. We follow the definition in https://stacks.math.columbia.edu/tag/00VR, noting that the presheaf of sets "defined above" can be seen in the comments between tags 00VQ and 00VR on the page <https://stacks.math.columbia.edu/tag/00VL>. The advantage of this definition is that we need no assumptions whatsoever on `A` other than the assumption that the morphisms in `C` and `A` live in the same universe. * An `A`-valued presheaf `P : Cᵒᵖ ⥤ A` is defined to be a sheaf (for the topology `J`) iff for every `E : A`, the type-valued presheaves of sets given by sending `U : Cᵒᵖ` to `Hom_{A}(E, P U)` are all sheaves of sets, see `CategoryTheory.Presheaf.IsSheaf`. * When `A = Type`, this recovers the basic definition of sheaves of sets, see `CategoryTheory.isSheaf_iff_isSheaf_of_type`. * A alternate definition in terms of limits, unconditionally equivalent to the original one: see `CategoryTheory.Presheaf.isSheaf_iff_isLimit`. * An alternate definition when `C` is small, has pullbacks and `A` has products is given by an equalizer condition `CategoryTheory.Presheaf.IsSheaf'`. This is equivalent to the earlier definition, shown in `CategoryTheory.Presheaf.isSheaf_iff_isSheaf'`. * When `A = Type`, this is *definitionally* equal to the equalizer condition for presieves in `CategoryTheory.Sites.SheafOfTypes`. * When `A` has limits and there is a functor `s : A ⥤ Type` which is faithful, reflects isomorphisms and preserves limits, then `P : Cᵒᵖ ⥤ A` is a sheaf iff the underlying presheaf of types `P ⋙ s : Cᵒᵖ ⥤ Type` is a sheaf (`CategoryTheory.Presheaf.isSheaf_iff_isSheaf_forget`). Cf https://stacks.math.columbia.edu/tag/0073, which is a weaker version of this statement (it's only over spaces, not sites) and https://stacks.math.columbia.edu/tag/00YR (a), which additionally assumes filtered colimits. ## Implementation notes Occasionally we need to take a limit in `A` of a collection of morphisms of `C` indexed by a collection of objects in `C`. This turns out to force the morphisms of `A` to be in a sufficiently large universe. Rather than use `UnivLE` we prove some results for a category `A'` instead, whose morphism universe of `A'` is defined to be `max u₁ v₁`, where `u₁, v₁` are the universes for `C`. Perhaps after we get better at handling universe inequalities this can be changed. -/ universe w v₁ v₂ v₃ u₁ u₂ u₃ noncomputable section namespace CategoryTheory open Opposite CategoryTheory Category Limits Sieve namespace Presheaf variable {C : Type u₁} [Category.{v₁} C] variable {A : Type u₂} [Category.{v₂} A] variable (J : GrothendieckTopology C) -- We follow https://stacks.math.columbia.edu/tag/00VL definition 00VR /-- A sheaf of A is a presheaf P : Cᵒᵖ => A such that for every E : A, the presheaf of types given by sending U : C to Hom_{A}(E, P U) is a sheaf of types. -/ @[stacks 00VR] def IsSheaf (P : Cᵒᵖ ⥤ A) : Prop := ∀ E : A, Presieve.IsSheaf J (P ⋙ coyoneda.obj (op E)) /-- Condition that a presheaf with values in a concrete category is separated for a Grothendieck topology. -/ def IsSeparated (P : Cᵒᵖ ⥤ A) {FA : A → A → Type*} {CA : A → Type*} [∀ X Y, FunLike (FA X Y) (CA X) (CA Y)] [ConcreteCategory A FA] : Prop := ∀ (X : C) (S : Sieve X) (_ : S ∈ J X) (x y : ToType (P.obj (op X))), (∀ (Y : C) (f : Y ⟶ X) (_ : S f), P.map f.op x = P.map f.op y) → x = y section LimitSheafCondition open Presieve Presieve.FamilyOfElements Limits variable (P : Cᵒᵖ ⥤ A) {X : C} (S : Sieve X) (R : Presieve X) (E : Aᵒᵖ) /-- Given a sieve `S` on `X : C`, a presheaf `P : Cᵒᵖ ⥤ A`, and an object `E` of `A`, the cones over the natural diagram `S.arrows.diagram.op ⋙ P` associated to `S` and `P` with cone point `E` are in 1-1 correspondence with sieve_compatible family of elements for the sieve `S` and the presheaf of types `Hom (E, P -)`. -/ def conesEquivSieveCompatibleFamily : (S.arrows.diagram.op ⋙ P).cones.obj E ≃ { x : FamilyOfElements (P ⋙ coyoneda.obj E) (S : Presieve X) // x.SieveCompatible } where toFun π := ⟨fun _ f h => π.app (op ⟨Over.mk f, h⟩), fun X Y f g hf => by apply (id_comp _).symm.trans dsimp exact π.naturality (Quiver.Hom.op (Over.homMk _ (by rfl)))⟩ invFun x := { app := fun f => x.1 f.unop.1.hom f.unop.2 naturality := fun f f' g => by refine Eq.trans ?_ (x.2 f.unop.1.hom g.unop.left f.unop.2) dsimp rw [id_comp] convert rfl rw [Over.w] } left_inv _ := rfl right_inv _ := rfl variable {P S E} variable {x : FamilyOfElements (P ⋙ coyoneda.obj E) S.arrows} (hx : SieveCompatible x) /-- The cone corresponding to a sieve_compatible family of elements, dot notation enabled. -/ @[simp] def _root_.CategoryTheory.Presieve.FamilyOfElements.SieveCompatible.cone : Cone (S.arrows.diagram.op ⋙ P) where pt := E.unop π := (conesEquivSieveCompatibleFamily P S E).invFun ⟨x, hx⟩ /-- Cone morphisms from the cone corresponding to a sieve_compatible family to the natural cone associated to a sieve `S` and a presheaf `P` are in 1-1 correspondence with amalgamations of the family. -/ def homEquivAmalgamation : (hx.cone ⟶ P.mapCone S.arrows.cocone.op) ≃ { t // x.IsAmalgamation t } where toFun l := ⟨l.hom, fun _ f hf => l.w (op ⟨Over.mk f, hf⟩)⟩ invFun t := ⟨t.1, fun f => t.2 f.unop.1.hom f.unop.2⟩ left_inv _ := rfl right_inv _ := rfl variable (P S) /-- Given sieve `S` and presheaf `P : Cᵒᵖ ⥤ A`, their natural associated cone is a limit cone iff `Hom (E, P -)` is a sheaf of types for the sieve `S` and all `E : A`. -/ theorem isLimit_iff_isSheafFor : Nonempty (IsLimit (P.mapCone S.arrows.cocone.op)) ↔ ∀ E : Aᵒᵖ, IsSheafFor (P ⋙ coyoneda.obj E) S.arrows := by dsimp [IsSheafFor]; simp_rw [compatible_iff_sieveCompatible] rw [((Cone.isLimitEquivIsTerminal _).trans (isTerminalEquivUnique _ _)).nonempty_congr] rw [Classical.nonempty_pi]; constructor · intro hu E x hx specialize hu hx.cone rw [(homEquivAmalgamation hx).uniqueCongr.nonempty_congr] at hu exact (unique_subtype_iff_existsUnique _).1 hu · rintro h ⟨E, π⟩ let eqv := conesEquivSieveCompatibleFamily P S (op E) rw [← eqv.left_inv π] erw [(homEquivAmalgamation (eqv π).2).uniqueCongr.nonempty_congr] rw [unique_subtype_iff_existsUnique] exact h _ _ (eqv π).2 /-- Given sieve `S` and presheaf `P : Cᵒᵖ ⥤ A`, their natural associated cone admits at most one morphism from every cone in the same category (i.e. over the same diagram), iff `Hom (E, P -)`is separated for the sieve `S` and all `E : A`. -/ theorem subsingleton_iff_isSeparatedFor : (∀ c, Subsingleton (c ⟶ P.mapCone S.arrows.cocone.op)) ↔ ∀ E : Aᵒᵖ, IsSeparatedFor (P ⋙ coyoneda.obj E) S.arrows := by constructor · intro hs E x t₁ t₂ h₁ h₂ have hx := is_compatible_of_exists_amalgamation x ⟨t₁, h₁⟩ rw [compatible_iff_sieveCompatible] at hx specialize hs hx.cone rcases hs with ⟨hs⟩ simpa only [Subtype.mk.injEq] using (show Subtype.mk t₁ h₁ = ⟨t₂, h₂⟩ from (homEquivAmalgamation hx).symm.injective (hs _ _)) · rintro h ⟨E, π⟩ let eqv := conesEquivSieveCompatibleFamily P S (op E) constructor rw [← eqv.left_inv π] intro f₁ f₂ let eqv' := homEquivAmalgamation (eqv π).2 apply eqv'.injective ext apply h _ (eqv π).1 <;> exact (eqv' _).2 /-- A presheaf `P` is a sheaf for the Grothendieck topology `J` iff for every covering sieve `S` of `J`, the natural cone associated to `P` and `S` is a limit cone. -/ theorem isSheaf_iff_isLimit : IsSheaf J P ↔ ∀ ⦃X : C⦄ (S : Sieve X), S ∈ J X → Nonempty (IsLimit (P.mapCone S.arrows.cocone.op)) := ⟨fun h _ S hS => (isLimit_iff_isSheafFor P S).2 fun E => h E.unop S hS, fun h E _ S hS => (isLimit_iff_isSheafFor P S).1 (h S hS) (op E)⟩ /-- A presheaf `P` is separated for the Grothendieck topology `J` iff for every covering sieve `S` of `J`, the natural cone associated to `P` and `S` admits at most one morphism from every cone in the same category. -/ theorem isSeparated_iff_subsingleton : (∀ E : A, Presieve.IsSeparated J (P ⋙ coyoneda.obj (op E))) ↔ ∀ ⦃X : C⦄ (S : Sieve X), S ∈ J X → ∀ c, Subsingleton (c ⟶ P.mapCone S.arrows.cocone.op) := ⟨fun h _ S hS => (subsingleton_iff_isSeparatedFor P S).2 fun E => h E.unop S hS, fun h E _ S hS => (subsingleton_iff_isSeparatedFor P S).1 (h S hS) (op E)⟩ /-- Given presieve `R` and presheaf `P : Cᵒᵖ ⥤ A`, the natural cone associated to `P` and the sieve `Sieve.generate R` generated by `R` is a limit cone iff `Hom (E, P -)` is a sheaf of types for the presieve `R` and all `E : A`. -/ theorem isLimit_iff_isSheafFor_presieve : Nonempty (IsLimit (P.mapCone (generate R).arrows.cocone.op)) ↔ ∀ E : Aᵒᵖ, IsSheafFor (P ⋙ coyoneda.obj E) R := (isLimit_iff_isSheafFor P _).trans (forall_congr' fun _ => (isSheafFor_iff_generate _).symm) /-- A presheaf `P` is a sheaf for the Grothendieck topology generated by a pretopology `K` iff for every covering presieve `R` of `K`, the natural cone associated to `P` and `Sieve.generate R` is a limit cone. -/ theorem isSheaf_iff_isLimit_pretopology [HasPullbacks C] (K : Pretopology C) : IsSheaf (K.toGrothendieck C) P ↔ ∀ ⦃X : C⦄ (R : Presieve X), R ∈ K X → Nonempty (IsLimit (P.mapCone (generate R).arrows.cocone.op)) := by dsimp [IsSheaf] simp_rw [isSheaf_pretopology] exact ⟨fun h X R hR => (isLimit_iff_isSheafFor_presieve P R).2 fun E => h E.unop R hR, fun h E X R hR => (isLimit_iff_isSheafFor_presieve P R).1 (h R hR) (op E)⟩ end LimitSheafCondition variable {J} /-- This is a wrapper around `Presieve.IsSheafFor.amalgamate` to be used below. If `P`s a sheaf, `S` is a cover of `X`, and `x` is a collection of morphisms from `E` to `P` evaluated at terms in the cover which are compatible, then we can amalgamate the `x`s to obtain a single morphism `E ⟶ P.obj (op X)`. -/ def IsSheaf.amalgamate {A : Type u₂} [Category.{v₂} A] {E : A} {X : C} {P : Cᵒᵖ ⥤ A} (hP : Presheaf.IsSheaf J P) (S : J.Cover X) (x : ∀ I : S.Arrow, E ⟶ P.obj (op I.Y)) (hx : ∀ ⦃I₁ I₂ : S.Arrow⦄ (r : I₁.Relation I₂), x I₁ ≫ P.map r.g₁.op = x I₂ ≫ P.map r.g₂.op) : E ⟶ P.obj (op X) := (hP _ _ S.condition).amalgamate (fun Y f hf => x ⟨Y, f, hf⟩) fun _ _ _ _ _ _ _ h₁ h₂ w => @hx { hf := h₁, .. } { hf := h₂, .. } { w := w, .. } @[reassoc (attr := simp)] theorem IsSheaf.amalgamate_map {A : Type u₂} [Category.{v₂} A] {E : A} {X : C} {P : Cᵒᵖ ⥤ A} (hP : Presheaf.IsSheaf J P) (S : J.Cover X) (x : ∀ I : S.Arrow, E ⟶ P.obj (op I.Y)) (hx : ∀ ⦃I₁ I₂ : S.Arrow⦄ (r : I₁.Relation I₂), x I₁ ≫ P.map r.g₁.op = x I₂ ≫ P.map r.g₂.op) (I : S.Arrow) : hP.amalgamate S x hx ≫ P.map I.f.op = x _ := by apply (hP _ _ S.condition).valid_glue theorem IsSheaf.hom_ext {A : Type u₂} [Category.{v₂} A] {E : A} {X : C} {P : Cᵒᵖ ⥤ A} (hP : Presheaf.IsSheaf J P) (S : J.Cover X) (e₁ e₂ : E ⟶ P.obj (op X)) (h : ∀ I : S.Arrow, e₁ ≫ P.map I.f.op = e₂ ≫ P.map I.f.op) : e₁ = e₂ := (hP _ _ S.condition).isSeparatedFor.ext fun Y f hf => h ⟨Y, f, hf⟩ lemma IsSheaf.hom_ext_ofArrows {P : Cᵒᵖ ⥤ A} (hP : Presheaf.IsSheaf J P) {I : Type*} {S : C} {X : I → C} (f : ∀ i, X i ⟶ S) (hf : Sieve.ofArrows _ f ∈ J S) {E : A} {x y : E ⟶ P.obj (op S)} (h : ∀ i, x ≫ P.map (f i).op = y ≫ P.map (f i).op) : x = y := by apply hP.hom_ext ⟨_, hf⟩ rintro ⟨Z, _, _, g, _, ⟨i⟩, rfl⟩ dsimp rw [P.map_comp, reassoc_of% (h i)] section variable {P : Cᵒᵖ ⥤ A} (hP : Presheaf.IsSheaf J P) {I : Type*} {S : C} {X : I → C} (f : ∀ i, X i ⟶ S) (hf : Sieve.ofArrows _ f ∈ J S) {E : A} (x : ∀ i, E ⟶ P.obj (op (X i))) (hx : ∀ ⦃W : C⦄ ⦃i j : I⦄ (a : W ⟶ X i) (b : W ⟶ X j), a ≫ f i = b ≫ f j → x i ≫ P.map a.op = x j ≫ P.map b.op) include hP hf hx lemma IsSheaf.existsUnique_amalgamation_ofArrows : ∃! (g : E ⟶ P.obj (op S)), ∀ (i : I), g ≫ P.map (f i).op = x i := (Presieve.isSheafFor_arrows_iff _ _).1
((Presieve.isSheafFor_iff_generate _).2 (hP E _ hf)) x (fun _ _ _ _ _ w => hx _ _ w) @[deprecated (since := "2024-12-17")] alias IsSheaf.exists_unique_amalgamation_ofArrows := IsSheaf.existsUnique_amalgamation_ofArrows /-- If `P : Cᵒᵖ ⥤ A` is a sheaf and `f i : X i ⟶ S` is a covering family, then a morphism `E ⟶ P.obj (op S)` can be constructed from a compatible family of morphisms `x : E ⟶ P.obj (op (X i))`. -/ def IsSheaf.amalgamateOfArrows : E ⟶ P.obj (op S) :=
Mathlib/CategoryTheory/Sites/Sheaf.lean
266
274
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.WSeq.Basic import Mathlib.Data.WSeq.Defs import Mathlib.Data.WSeq.Productive import Mathlib.Data.WSeq.Relation deprecated_module (since := "2025-04-13")
Mathlib/Data/Seq/WSeq.lean
659
659
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.Order.Iterate import Mathlib.Order.SemiconjSup import Mathlib.Topology.Order.MonotoneContinuity import Mathlib.Algebra.CharP.Defs /-! # Translation number of a monotone real map that commutes with `x ↦ x + 1` Let `f : ℝ → ℝ` be a monotone map such that `f (x + 1) = f x + 1` for all `x`. Then the limit $$ \tau(f)=\lim_{n\to\infty}{f^n(x)-x}{n} $$ exists and does not depend on `x`. This number is called the *translation number* of `f`. Different authors use different notation for this number: `τ`, `ρ`, `rot`, etc In this file we define a structure `CircleDeg1Lift` for bundled maps with these properties, define translation number of `f : CircleDeg1Lift`, prove some estimates relating `f^n(x)-x` to `τ(f)`. In case of a continuous map `f` we also prove that `f` admits a point `x` such that `f^n(x)=x+m` if and only if `τ(f)=m/n`. Maps of this type naturally appear as lifts of orientation preserving circle homeomorphisms. More precisely, let `f` be an orientation preserving homeomorphism of the circle $S^1=ℝ/ℤ$, and consider a real number `a` such that `⟦a⟧ = f 0`, where `⟦⟧` means the natural projection `ℝ → ℝ/ℤ`. Then there exists a unique continuous function `F : ℝ → ℝ` such that `F 0 = a` and `⟦F x⟧ = f ⟦x⟧` for all `x` (this fact is not formalized yet). This function is strictly monotone, continuous, and satisfies `F (x + 1) = F x + 1`. The number `⟦τ F⟧ : ℝ / ℤ` is called the *rotation number* of `f`. It does not depend on the choice of `a`. ## Main definitions * `CircleDeg1Lift`: a monotone map `f : ℝ → ℝ` such that `f (x + 1) = f x + 1` for all `x`; the type `CircleDeg1Lift` is equipped with `Lattice` and `Monoid` structures; the multiplication is given by composition: `(f * g) x = f (g x)`. * `CircleDeg1Lift.translationNumber`: translation number of `f : CircleDeg1Lift`. ## Main statements We prove the following properties of `CircleDeg1Lift.translationNumber`. * `CircleDeg1Lift.translationNumber_eq_of_dist_bounded`: if the distance between `(f^n) 0` and `(g^n) 0` is bounded from above uniformly in `n : ℕ`, then `f` and `g` have equal translation numbers. * `CircleDeg1Lift.translationNumber_eq_of_semiconjBy`: if two `CircleDeg1Lift` maps `f`, `g` are semiconjugate by a `CircleDeg1Lift` map, then `τ f = τ g`. * `CircleDeg1Lift.translationNumber_units_inv`: if `f` is an invertible `CircleDeg1Lift` map (equivalently, `f` is a lift of an orientation-preserving circle homeomorphism), then the translation number of `f⁻¹` is the negative of the translation number of `f`. * `CircleDeg1Lift.translationNumber_mul_of_commute`: if `f` and `g` commute, then `τ (f * g) = τ f + τ g`. * `CircleDeg1Lift.translationNumber_eq_rat_iff`: the translation number of `f` is equal to a rational number `m / n` if and only if `(f^n) x = x + m` for some `x`. * `CircleDeg1Lift.semiconj_of_bijective_of_translationNumber_eq`: if `f` and `g` are two bijective `CircleDeg1Lift` maps and their translation numbers are equal, then these maps are semiconjugate to each other. * `CircleDeg1Lift.semiconj_of_group_action_of_forall_translationNumber_eq`: let `f₁` and `f₂` be two actions of a group `G` on the circle by degree 1 maps (formally, `f₁` and `f₂` are two homomorphisms from `G →* CircleDeg1Lift`). If the translation numbers of `f₁ g` and `f₂ g` are equal to each other for all `g : G`, then these two actions are semiconjugate by some `F : CircleDeg1Lift`. This is a version of Proposition 5.4 from [Étienne Ghys, Groupes d'homeomorphismes du cercle et cohomologie bornee][ghys87:groupes]. ## Notation We use a local notation `τ` for the translation number of `f : CircleDeg1Lift`. ## Implementation notes We define the translation number of `f : CircleDeg1Lift` to be the limit of the sequence `(f ^ (2 ^ n)) 0 / (2 ^ n)`, then prove that `((f ^ n) x - x) / n` tends to this number for any `x`. This way it is much easier to prove that the limit exists and basic properties of the limit. We define translation number for a wider class of maps `f : ℝ → ℝ` instead of lifts of orientation preserving circle homeomorphisms for two reasons: * non-strictly monotone circle self-maps with discontinuities naturally appear as Poincaré maps for some flows on the two-torus (e.g., one can take a constant flow and glue in a few Cherry cells); * definition and some basic properties still work for this class. ## References * [Étienne Ghys, Groupes d'homeomorphismes du cercle et cohomologie bornee][ghys87:groupes] ## TODO Here are some short-term goals. * Introduce a structure or a typeclass for lifts of circle homeomorphisms. We use `Units CircleDeg1Lift` for now, but it's better to have a dedicated type (or a typeclass?). * Prove that the `SemiconjBy` relation on circle homeomorphisms is an equivalence relation. * Introduce `ConditionallyCompleteLattice` structure, use it in the proof of `CircleDeg1Lift.semiconj_of_group_action_of_forall_translationNumber_eq`. * Prove that the orbits of the irrational rotation are dense in the circle. Deduce that a homeomorphism with an irrational rotation is semiconjugate to the corresponding irrational translation by a continuous `CircleDeg1Lift`. ## Tags circle homeomorphism, rotation number -/ open Filter Set Int Topology open Function hiding Commute /-! ### Definition and monoid structure -/ /-- A lift of a monotone degree one map `S¹ → S¹`. -/ structure CircleDeg1Lift : Type extends ℝ →o ℝ where map_add_one' : ∀ x, toFun (x + 1) = toFun x + 1 namespace CircleDeg1Lift instance : FunLike CircleDeg1Lift ℝ ℝ where coe f := f.toFun coe_injective' | ⟨⟨_, _⟩, _⟩, ⟨⟨_, _⟩, _⟩, rfl => rfl instance : OrderHomClass CircleDeg1Lift ℝ ℝ where map_rel f _ _ h := f.monotone' h @[simp] theorem coe_mk (f h) : ⇑(mk f h) = f := rfl variable (f g : CircleDeg1Lift) @[simp] theorem coe_toOrderHom : ⇑f.toOrderHom = f := rfl protected theorem monotone : Monotone f := f.monotone' @[mono] theorem mono {x y} (h : x ≤ y) : f x ≤ f y := f.monotone h theorem strictMono_iff_injective : StrictMono f ↔ Injective f := f.monotone.strictMono_iff_injective @[simp] theorem map_add_one : ∀ x, f (x + 1) = f x + 1 := f.map_add_one' @[simp] theorem map_one_add (x : ℝ) : f (1 + x) = 1 + f x := by rw [add_comm, map_add_one, add_comm 1] @[ext] theorem ext ⦃f g : CircleDeg1Lift⦄ (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h instance : Monoid CircleDeg1Lift where mul f g := { toOrderHom := f.1.comp g.1 map_add_one' := fun x => by simp [map_add_one] } one := ⟨.id, fun _ => rfl⟩ mul_one _ := rfl one_mul _ := rfl mul_assoc _ _ _ := DFunLike.coe_injective rfl instance : Inhabited CircleDeg1Lift := ⟨1⟩ @[simp] theorem coe_mul : ⇑(f * g) = f ∘ g := rfl theorem mul_apply (x) : (f * g) x = f (g x) := rfl @[simp] theorem coe_one : ⇑(1 : CircleDeg1Lift) = id := rfl instance unitsHasCoeToFun : CoeFun CircleDeg1Liftˣ fun _ => ℝ → ℝ := ⟨fun f => ⇑(f : CircleDeg1Lift)⟩ @[simp] theorem units_inv_apply_apply (f : CircleDeg1Liftˣ) (x : ℝ) : (f⁻¹ : CircleDeg1Liftˣ) (f x) = x := by simp only [← mul_apply, f.inv_mul, coe_one, id] @[simp] theorem units_apply_inv_apply (f : CircleDeg1Liftˣ) (x : ℝ) : f ((f⁻¹ : CircleDeg1Liftˣ) x) = x := by simp only [← mul_apply, f.mul_inv, coe_one, id] /-- If a lift of a circle map is bijective, then it is an order automorphism of the line. -/ def toOrderIso : CircleDeg1Liftˣ →* ℝ ≃o ℝ where toFun f := { toFun := f invFun := ⇑f⁻¹ left_inv := units_inv_apply_apply f right_inv := units_apply_inv_apply f map_rel_iff' := ⟨fun h => by simpa using mono (↑f⁻¹) h, mono f⟩ } map_one' := rfl map_mul' _ _ := rfl @[simp] theorem coe_toOrderIso (f : CircleDeg1Liftˣ) : ⇑(toOrderIso f) = f := rfl @[simp] theorem coe_toOrderIso_symm (f : CircleDeg1Liftˣ) : ⇑(toOrderIso f).symm = (f⁻¹ : CircleDeg1Liftˣ) := rfl @[simp] theorem coe_toOrderIso_inv (f : CircleDeg1Liftˣ) : ⇑(toOrderIso f)⁻¹ = (f⁻¹ : CircleDeg1Liftˣ) := rfl theorem isUnit_iff_bijective {f : CircleDeg1Lift} : IsUnit f ↔ Bijective f := ⟨fun ⟨u, h⟩ => h ▸ (toOrderIso u).bijective, fun h => Units.isUnit { val := f inv := { toFun := (Equiv.ofBijective f h).symm monotone' := fun x y hxy => (f.strictMono_iff_injective.2 h.1).le_iff_le.1 (by simp only [Equiv.ofBijective_apply_symm_apply f h, hxy]) map_add_one' := fun x => h.1 <| by simp only [Equiv.ofBijective_apply_symm_apply f, f.map_add_one] } val_inv := ext <| Equiv.ofBijective_apply_symm_apply f h inv_val := ext <| Equiv.ofBijective_symm_apply_apply f h }⟩ theorem coe_pow : ∀ n : ℕ, ⇑(f ^ n) = f^[n] | 0 => rfl | n + 1 => by ext x simp [coe_pow n, pow_succ] theorem semiconjBy_iff_semiconj {f g₁ g₂ : CircleDeg1Lift} : SemiconjBy f g₁ g₂ ↔ Semiconj f g₁ g₂ := CircleDeg1Lift.ext_iff theorem commute_iff_commute {f g : CircleDeg1Lift} : Commute f g ↔ Function.Commute f g := CircleDeg1Lift.ext_iff /-! ### Translate by a constant -/ /-- The map `y ↦ x + y` as a `CircleDeg1Lift`. More precisely, we define a homomorphism from `Multiplicative ℝ` to `CircleDeg1Liftˣ`, so the translation by `x` is `translation (Multiplicative.ofAdd x)`. -/ def translate : Multiplicative ℝ →* CircleDeg1Liftˣ := MonoidHom.toHomUnits <| { toFun := fun x => ⟨⟨fun y => x.toAdd + y, fun _ _ h => add_le_add_left h _⟩, fun _ => (add_assoc _ _ _).symm⟩ map_one' := ext <| zero_add map_mul' := fun _ _ => ext <| add_assoc _ _ } @[simp] theorem translate_apply (x y : ℝ) : translate (Multiplicative.ofAdd x) y = x + y := rfl @[simp] theorem translate_inv_apply (x y : ℝ) : (translate <| Multiplicative.ofAdd x)⁻¹ y = -x + y := rfl @[simp] theorem translate_zpow (x : ℝ) (n : ℤ) : translate (Multiplicative.ofAdd x) ^ n = translate (Multiplicative.ofAdd <| ↑n * x) := by simp only [← zsmul_eq_mul, ofAdd_zsmul, MonoidHom.map_zpow] @[simp] theorem translate_pow (x : ℝ) (n : ℕ) : translate (Multiplicative.ofAdd x) ^ n = translate (Multiplicative.ofAdd <| ↑n * x) := translate_zpow x n @[simp] theorem translate_iterate (x : ℝ) (n : ℕ) : (translate (Multiplicative.ofAdd x))^[n] = translate (Multiplicative.ofAdd <| ↑n * x) := by rw [← coe_pow, ← Units.val_pow_eq_pow_val, translate_pow] /-! ### Commutativity with integer translations In this section we prove that `f` commutes with translations by an integer number. First we formulate these statements (for a natural or an integer number, addition on the left or on the right, addition or subtraction) using `Function.Commute`, then reformulate as `simp` lemmas `map_int_add` etc. -/ theorem commute_nat_add (n : ℕ) : Function.Commute f (n + ·) := by simpa only [nsmul_one, add_left_iterate] using Function.Commute.iterate_right f.map_one_add n theorem commute_add_nat (n : ℕ) : Function.Commute f (· + n) := by simp only [add_comm _ (n : ℝ), f.commute_nat_add n] theorem commute_sub_nat (n : ℕ) : Function.Commute f (· - n) := by simpa only [sub_eq_add_neg] using (f.commute_add_nat n).inverses_right (Equiv.addRight _).right_inv (Equiv.addRight _).left_inv theorem commute_add_int : ∀ n : ℤ, Function.Commute f (· + n) | (n : ℕ) => f.commute_add_nat n | -[n+1] => by simpa [sub_eq_add_neg] using f.commute_sub_nat (n + 1) theorem commute_int_add (n : ℤ) : Function.Commute f (n + ·) := by simpa only [add_comm _ (n : ℝ)] using f.commute_add_int n theorem commute_sub_int (n : ℤ) : Function.Commute f (· - n) := by simpa only [sub_eq_add_neg] using (f.commute_add_int n).inverses_right (Equiv.addRight _).right_inv (Equiv.addRight _).left_inv @[simp] theorem map_int_add (m : ℤ) (x : ℝ) : f (m + x) = m + f x := f.commute_int_add m x @[simp] theorem map_add_int (x : ℝ) (m : ℤ) : f (x + m) = f x + m := f.commute_add_int m x @[simp] theorem map_sub_int (x : ℝ) (n : ℤ) : f (x - n) = f x - n := f.commute_sub_int n x @[simp] theorem map_add_nat (x : ℝ) (n : ℕ) : f (x + n) = f x + n := f.map_add_int x n @[simp] theorem map_nat_add (n : ℕ) (x : ℝ) : f (n + x) = n + f x := f.map_int_add n x @[simp] theorem map_sub_nat (x : ℝ) (n : ℕ) : f (x - n) = f x - n := f.map_sub_int x n theorem map_int_of_map_zero (n : ℤ) : f n = f 0 + n := by rw [← f.map_add_int, zero_add] @[simp] theorem map_fract_sub_fract_eq (x : ℝ) : f (fract x) - fract x = f x - x := by rw [Int.fract, f.map_sub_int, sub_sub_sub_cancel_right] /-! ### Pointwise order on circle maps -/ /-- Monotone circle maps form a lattice with respect to the pointwise order -/ noncomputable instance : Lattice CircleDeg1Lift where sup f g := { toFun := fun x => max (f x) (g x) monotone' := fun _ _ h => max_le_max (f.mono h) (g.mono h) -- TODO: generalize to `Monotone.max` map_add_one' := fun x => by simp [max_add_add_right] } le f g := ∀ x, f x ≤ g x le_refl f x := le_refl (f x) le_trans _ _ _ h₁₂ h₂₃ x := le_trans (h₁₂ x) (h₂₃ x) le_antisymm _ _ h₁₂ h₂₁ := ext fun x => le_antisymm (h₁₂ x) (h₂₁ x) le_sup_left f g x := le_max_left (f x) (g x) le_sup_right f g x := le_max_right (f x) (g x) sup_le _ _ _ h₁ h₂ x := max_le (h₁ x) (h₂ x) inf f g := { toFun := fun x => min (f x) (g x) monotone' := fun _ _ h => min_le_min (f.mono h) (g.mono h) map_add_one' := fun x => by simp [min_add_add_right] } inf_le_left f g x := min_le_left (f x) (g x) inf_le_right f g x := min_le_right (f x) (g x) le_inf _ _ _ h₂ h₃ x := le_min (h₂ x) (h₃ x) @[simp] theorem sup_apply (x : ℝ) : (f ⊔ g) x = max (f x) (g x) := rfl @[simp] theorem inf_apply (x : ℝ) : (f ⊓ g) x = min (f x) (g x) := rfl theorem iterate_monotone (n : ℕ) : Monotone fun f : CircleDeg1Lift => f^[n] := fun f _ h => f.monotone.iterate_le_of_le h _ theorem iterate_mono {f g : CircleDeg1Lift} (h : f ≤ g) (n : ℕ) : f^[n] ≤ g^[n] := iterate_monotone n h theorem pow_mono {f g : CircleDeg1Lift} (h : f ≤ g) (n : ℕ) : f ^ n ≤ g ^ n := fun x => by simp only [coe_pow, iterate_mono h n x] theorem pow_monotone (n : ℕ) : Monotone fun f : CircleDeg1Lift => f ^ n := fun _ _ h => pow_mono h n /-! ### Estimates on `(f * g) 0` We prove the estimates `f 0 + ⌊g 0⌋ ≤ f (g 0) ≤ f 0 + ⌈g 0⌉` and some corollaries with added/removed floors and ceils. We also prove that for two semiconjugate maps `g₁`, `g₂`, the distance between `g₁ 0` and `g₂ 0` is less than two. -/ theorem map_le_of_map_zero (x : ℝ) : f x ≤ f 0 + ⌈x⌉ := calc f x ≤ f ⌈x⌉ := f.monotone <| le_ceil _ _ = f 0 + ⌈x⌉ := f.map_int_of_map_zero _ theorem map_map_zero_le : f (g 0) ≤ f 0 + ⌈g 0⌉ := f.map_le_of_map_zero (g 0) theorem floor_map_map_zero_le : ⌊f (g 0)⌋ ≤ ⌊f 0⌋ + ⌈g 0⌉ := calc ⌊f (g 0)⌋ ≤ ⌊f 0 + ⌈g 0⌉⌋ := floor_mono <| f.map_map_zero_le g _ = ⌊f 0⌋ + ⌈g 0⌉ := floor_add_intCast _ _ theorem ceil_map_map_zero_le : ⌈f (g 0)⌉ ≤ ⌈f 0⌉ + ⌈g 0⌉ := calc ⌈f (g 0)⌉ ≤ ⌈f 0 + ⌈g 0⌉⌉ := ceil_mono <| f.map_map_zero_le g _ = ⌈f 0⌉ + ⌈g 0⌉ := ceil_add_intCast _ _ theorem map_map_zero_lt : f (g 0) < f 0 + g 0 + 1 := calc f (g 0) ≤ f 0 + ⌈g 0⌉ := f.map_map_zero_le g _ < f 0 + (g 0 + 1) := add_lt_add_left (ceil_lt_add_one _) _ _ = f 0 + g 0 + 1 := (add_assoc _ _ _).symm theorem le_map_of_map_zero (x : ℝ) : f 0 + ⌊x⌋ ≤ f x := calc f 0 + ⌊x⌋ = f ⌊x⌋ := (f.map_int_of_map_zero _).symm _ ≤ f x := f.monotone <| floor_le _ theorem le_map_map_zero : f 0 + ⌊g 0⌋ ≤ f (g 0) := f.le_map_of_map_zero (g 0) theorem le_floor_map_map_zero : ⌊f 0⌋ + ⌊g 0⌋ ≤ ⌊f (g 0)⌋ := calc ⌊f 0⌋ + ⌊g 0⌋ = ⌊f 0 + ⌊g 0⌋⌋ := (floor_add_intCast _ _).symm _ ≤ ⌊f (g 0)⌋ := floor_mono <| f.le_map_map_zero g theorem le_ceil_map_map_zero : ⌈f 0⌉ + ⌊g 0⌋ ≤ ⌈(f * g) 0⌉ := calc ⌈f 0⌉ + ⌊g 0⌋ = ⌈f 0 + ⌊g 0⌋⌉ := (ceil_add_intCast _ _).symm _ ≤ ⌈f (g 0)⌉ := ceil_mono <| f.le_map_map_zero g theorem lt_map_map_zero : f 0 + g 0 - 1 < f (g 0) := calc f 0 + g 0 - 1 = f 0 + (g 0 - 1) := add_sub_assoc _ _ _ _ < f 0 + ⌊g 0⌋ := add_lt_add_left (sub_one_lt_floor _) _ _ ≤ f (g 0) := f.le_map_map_zero g theorem dist_map_map_zero_lt : dist (f 0 + g 0) (f (g 0)) < 1 := by rw [dist_comm, Real.dist_eq, abs_lt, lt_sub_iff_add_lt', sub_lt_iff_lt_add', ← sub_eq_add_neg] exact ⟨f.lt_map_map_zero g, f.map_map_zero_lt g⟩ theorem dist_map_zero_lt_of_semiconj {f g₁ g₂ : CircleDeg1Lift} (h : Function.Semiconj f g₁ g₂) : dist (g₁ 0) (g₂ 0) < 2 := calc dist (g₁ 0) (g₂ 0) ≤ dist (g₁ 0) (f (g₁ 0) - f 0) + dist _ (g₂ 0) := dist_triangle _ _ _ _ = dist (f 0 + g₁ 0) (f (g₁ 0)) + dist (g₂ 0 + f 0) (g₂ (f 0)) := by simp only [h.eq, Real.dist_eq, sub_sub, add_comm (f 0), sub_sub_eq_add_sub, abs_sub_comm (g₂ (f 0))] _ < 1 + 1 := add_lt_add (f.dist_map_map_zero_lt g₁) (g₂.dist_map_map_zero_lt f) _ = 2 := one_add_one_eq_two theorem dist_map_zero_lt_of_semiconjBy {f g₁ g₂ : CircleDeg1Lift} (h : SemiconjBy f g₁ g₂) : dist (g₁ 0) (g₂ 0) < 2 := dist_map_zero_lt_of_semiconj <| semiconjBy_iff_semiconj.1 h /-! ### Limits at infinities and continuity -/ protected theorem tendsto_atBot : Tendsto f atBot atBot := tendsto_atBot_mono f.map_le_of_map_zero <| tendsto_atBot_add_const_left _ _ <| (tendsto_atBot_mono fun x => (ceil_lt_add_one x).le) <| tendsto_atBot_add_const_right _ _ tendsto_id protected theorem tendsto_atTop : Tendsto f atTop atTop := tendsto_atTop_mono f.le_map_of_map_zero <| tendsto_atTop_add_const_left _ _ <| (tendsto_atTop_mono fun x => (sub_one_lt_floor x).le) <| by simpa [sub_eq_add_neg] using tendsto_atTop_add_const_right _ _ tendsto_id theorem continuous_iff_surjective : Continuous f ↔ Function.Surjective f := ⟨fun h => h.surjective f.tendsto_atTop f.tendsto_atBot, f.monotone.continuous_of_surjective⟩ /-! ### Estimates on `(f^n) x` If we know that `f x` is `≤`/`<`/`≥`/`>`/`=` to `x + m`, then we have a similar estimate on `f^[n] x` and `x + n * m`. For `≤`, `≥`, and `=` we formulate both `of` (implication) and `iff` versions because implications work for `n = 0`. For `<` and `>` we formulate only `iff` versions. -/ theorem iterate_le_of_map_le_add_int {x : ℝ} {m : ℤ} (h : f x ≤ x + m) (n : ℕ) : f^[n] x ≤ x + n * m := by simpa only [nsmul_eq_mul, add_right_iterate] using (f.commute_add_int m).iterate_le_of_map_le f.monotone (monotone_id.add_const (m : ℝ)) h n theorem le_iterate_of_add_int_le_map {x : ℝ} {m : ℤ} (h : x + m ≤ f x) (n : ℕ) : x + n * m ≤ f^[n] x := by simpa only [nsmul_eq_mul, add_right_iterate] using (f.commute_add_int m).symm.iterate_le_of_map_le (monotone_id.add_const (m : ℝ)) f.monotone h n theorem iterate_eq_of_map_eq_add_int {x : ℝ} {m : ℤ} (h : f x = x + m) (n : ℕ) : f^[n] x = x + n * m := by simpa only [nsmul_eq_mul, add_right_iterate] using (f.commute_add_int m).iterate_eq_of_map_eq n h theorem iterate_pos_le_iff {x : ℝ} {m : ℤ} {n : ℕ} (hn : 0 < n) : f^[n] x ≤ x + n * m ↔ f x ≤ x + m := by simpa only [nsmul_eq_mul, add_right_iterate] using (f.commute_add_int m).iterate_pos_le_iff_map_le f.monotone (strictMono_id.add_const (m : ℝ)) hn theorem iterate_pos_lt_iff {x : ℝ} {m : ℤ} {n : ℕ} (hn : 0 < n) : f^[n] x < x + n * m ↔ f x < x + m := by simpa only [nsmul_eq_mul, add_right_iterate] using (f.commute_add_int m).iterate_pos_lt_iff_map_lt f.monotone (strictMono_id.add_const (m : ℝ)) hn theorem iterate_pos_eq_iff {x : ℝ} {m : ℤ} {n : ℕ} (hn : 0 < n) : f^[n] x = x + n * m ↔ f x = x + m := by simpa only [nsmul_eq_mul, add_right_iterate] using (f.commute_add_int m).iterate_pos_eq_iff_map_eq f.monotone (strictMono_id.add_const (m : ℝ)) hn theorem le_iterate_pos_iff {x : ℝ} {m : ℤ} {n : ℕ} (hn : 0 < n) : x + n * m ≤ f^[n] x ↔ x + m ≤ f x := by simpa only [not_lt] using not_congr (f.iterate_pos_lt_iff hn) theorem lt_iterate_pos_iff {x : ℝ} {m : ℤ} {n : ℕ} (hn : 0 < n) : x + n * m < f^[n] x ↔ x + m < f x := by simpa only [not_le] using not_congr (f.iterate_pos_le_iff hn) theorem mul_floor_map_zero_le_floor_iterate_zero (n : ℕ) : ↑n * ⌊f 0⌋ ≤ ⌊f^[n] 0⌋ := by rw [le_floor, Int.cast_mul, Int.cast_natCast, ← zero_add ((n : ℝ) * _)] apply le_iterate_of_add_int_le_map simp [floor_le] /-! ### Definition of translation number -/ noncomputable section /-- An auxiliary sequence used to define the translation number. -/ def transnumAuxSeq (n : ℕ) : ℝ := (f ^ (2 ^ n : ℕ)) 0 / 2 ^ n /-- The translation number of a `CircleDeg1Lift`, $τ(f)=\lim_{n→∞}\frac{f^n(x)-x}{n}$. We use an auxiliary sequence `\frac{f^{2^n}(0)}{2^n}` to define `τ(f)` because some proofs are simpler this way. -/ def translationNumber : ℝ := limUnder atTop f.transnumAuxSeq end -- TODO: choose two different symbols for `CircleDeg1Lift.translationNumber` and the future -- `circle_mono_homeo.rotation_number`, then make them `localized notation`s local notation "τ" => translationNumber theorem transnumAuxSeq_def : f.transnumAuxSeq = fun n : ℕ => (f ^ (2 ^ n : ℕ)) 0 / 2 ^ n := rfl theorem translationNumber_eq_of_tendsto_aux {τ' : ℝ} (h : Tendsto f.transnumAuxSeq atTop (𝓝 τ')) : τ f = τ' := h.limUnder_eq theorem translationNumber_eq_of_tendsto₀ {τ' : ℝ} (h : Tendsto (fun n : ℕ => f^[n] 0 / n) atTop (𝓝 τ')) : τ f = τ' := f.translationNumber_eq_of_tendsto_aux <| by simpa [Function.comp_def, transnumAuxSeq_def, coe_pow] using h.comp (Nat.tendsto_pow_atTop_atTop_of_one_lt one_lt_two) theorem translationNumber_eq_of_tendsto₀' {τ' : ℝ} (h : Tendsto (fun n : ℕ => f^[n + 1] 0 / (n + 1)) atTop (𝓝 τ')) : τ f = τ' := f.translationNumber_eq_of_tendsto₀ <| (tendsto_add_atTop_iff_nat 1).1 (mod_cast h) theorem transnumAuxSeq_zero : f.transnumAuxSeq 0 = f 0 := by simp [transnumAuxSeq] theorem transnumAuxSeq_dist_lt (n : ℕ) : dist (f.transnumAuxSeq n) (f.transnumAuxSeq (n + 1)) < 1 / 2 / 2 ^ n := by have : 0 < (2 ^ (n + 1) : ℝ) := pow_pos zero_lt_two _ rw [div_div, ← pow_succ', ← abs_of_pos this] calc _ = dist ((f ^ 2 ^ n) 0 + (f ^ 2 ^ n) 0) ((f ^ 2 ^ n) ((f ^ 2 ^ n) 0)) / |2 ^ (n + 1)| := by simp_rw [transnumAuxSeq, Real.dist_eq] rw [← abs_div, sub_div, pow_succ, pow_succ', ← two_mul, mul_div_mul_left _ _ (two_ne_zero' ℝ), pow_mul, sq, mul_apply] _ < _ := by gcongr; exact (f ^ 2 ^ n).dist_map_map_zero_lt (f ^ 2 ^ n) theorem tendsto_translationNumber_aux : Tendsto f.transnumAuxSeq atTop (𝓝 <| τ f) := (cauchySeq_of_le_geometric_two fun n => le_of_lt <| f.transnumAuxSeq_dist_lt n).tendsto_limUnder theorem dist_map_zero_translationNumber_le : dist (f 0) (τ f) ≤ 1 := f.transnumAuxSeq_zero ▸ dist_le_of_le_geometric_two_of_tendsto₀ (fun n => le_of_lt <| f.transnumAuxSeq_dist_lt n) f.tendsto_translationNumber_aux theorem tendsto_translationNumber_of_dist_bounded_aux (x : ℕ → ℝ) (C : ℝ) (H : ∀ n : ℕ, dist ((f ^ n) 0) (x n) ≤ C) : Tendsto (fun n : ℕ => x (2 ^ n) / 2 ^ n) atTop (𝓝 <| τ f) := by apply f.tendsto_translationNumber_aux.congr_dist (squeeze_zero (fun _ => dist_nonneg) _ _) · exact fun n => C / 2 ^ n · intro n have : 0 < (2 ^ n : ℝ) := pow_pos zero_lt_two _ convert (div_le_div_iff_of_pos_right this).2 (H (2 ^ n)) using 1 rw [transnumAuxSeq, Real.dist_eq, ← sub_div, abs_div, abs_of_pos this, Real.dist_eq] · exact mul_zero C ▸ tendsto_const_nhds.mul <| tendsto_inv_atTop_zero.comp <| tendsto_pow_atTop_atTop_of_one_lt one_lt_two theorem translationNumber_eq_of_dist_bounded {f g : CircleDeg1Lift} (C : ℝ) (H : ∀ n : ℕ, dist ((f ^ n) 0) ((g ^ n) 0) ≤ C) : τ f = τ g := Eq.symm <| g.translationNumber_eq_of_tendsto_aux <| f.tendsto_translationNumber_of_dist_bounded_aux (fun n ↦ (g ^ n) 0) C H @[simp] theorem translationNumber_one : τ 1 = 0 := translationNumber_eq_of_tendsto₀ _ <| by simp [tendsto_const_nhds] theorem translationNumber_eq_of_semiconjBy {f g₁ g₂ : CircleDeg1Lift} (H : SemiconjBy f g₁ g₂) : τ g₁ = τ g₂ := translationNumber_eq_of_dist_bounded 2 fun n => le_of_lt <| dist_map_zero_lt_of_semiconjBy <| H.pow_right n theorem translationNumber_eq_of_semiconj {f g₁ g₂ : CircleDeg1Lift} (H : Function.Semiconj f g₁ g₂) : τ g₁ = τ g₂ := translationNumber_eq_of_semiconjBy <| semiconjBy_iff_semiconj.2 H theorem translationNumber_mul_of_commute {f g : CircleDeg1Lift} (h : Commute f g) : τ (f * g) = τ f + τ g := by refine tendsto_nhds_unique ?_ (f.tendsto_translationNumber_aux.add g.tendsto_translationNumber_aux) simp only [transnumAuxSeq, ← add_div] refine (f * g).tendsto_translationNumber_of_dist_bounded_aux (fun n ↦ (f ^ n) 0 + (g ^ n) 0) 1 fun n ↦ ?_ rw [h.mul_pow, dist_comm] exact le_of_lt ((f ^ n).dist_map_map_zero_lt (g ^ n)) @[simp] theorem translationNumber_units_inv (f : CircleDeg1Liftˣ) : τ ↑f⁻¹ = -τ f := eq_neg_iff_add_eq_zero.2 <| by simp [← translationNumber_mul_of_commute (Commute.refl _).units_inv_left] @[simp] theorem translationNumber_pow : ∀ n : ℕ, τ (f ^ n) = n * τ f | 0 => by simp | n + 1 => by rw [pow_succ, translationNumber_mul_of_commute (Commute.pow_self f n), translationNumber_pow n, Nat.cast_add_one, add_mul, one_mul] @[simp] theorem translationNumber_zpow (f : CircleDeg1Liftˣ) : ∀ n : ℤ, τ (f ^ n : Units _) = n * τ f | (n : ℕ) => by simp [translationNumber_pow f n] | -[n+1] => by simp; ring @[simp] theorem translationNumber_conj_eq (f : CircleDeg1Liftˣ) (g : CircleDeg1Lift) : τ (↑f * g * ↑f⁻¹) = τ g := (translationNumber_eq_of_semiconjBy (f.mk_semiconjBy g)).symm @[simp] theorem translationNumber_conj_eq' (f : CircleDeg1Liftˣ) (g : CircleDeg1Lift) : τ (↑f⁻¹ * g * f) = τ g := translationNumber_conj_eq f⁻¹ g theorem dist_pow_map_zero_mul_translationNumber_le (n : ℕ) : dist ((f ^ n) 0) (n * f.translationNumber) ≤ 1 := f.translationNumber_pow n ▸ (f ^ n).dist_map_zero_translationNumber_le theorem tendsto_translation_number₀' : Tendsto (fun n : ℕ => (f ^ (n + 1) : CircleDeg1Lift) 0 / ((n : ℝ) + 1)) atTop (𝓝 <| τ f) := by refine tendsto_iff_dist_tendsto_zero.2 <| squeeze_zero (fun _ => dist_nonneg) (fun n => ?_) ((tendsto_const_div_atTop_nhds_zero_nat 1).comp (tendsto_add_atTop_nat 1)) dsimp have : (0 : ℝ) < n + 1 := n.cast_add_one_pos rw [Real.dist_eq, div_sub' (ne_of_gt this), abs_div, ← Real.dist_eq, abs_of_pos this, Nat.cast_add_one, div_le_div_iff_of_pos_right this, ← Nat.cast_add_one] apply dist_pow_map_zero_mul_translationNumber_le theorem tendsto_translation_number₀ : Tendsto (fun n : ℕ => (f ^ n) 0 / n) atTop (𝓝 <| τ f) := (tendsto_add_atTop_iff_nat 1).1 (mod_cast f.tendsto_translation_number₀') /-- For any `x : ℝ` the sequence $\frac{f^n(x)-x}{n}$ tends to the translation number of `f`. In particular, this limit does not depend on `x`. -/ theorem tendsto_translationNumber (x : ℝ) : Tendsto (fun n : ℕ => ((f ^ n) x - x) / n) atTop (𝓝 <| τ f) := by rw [← translationNumber_conj_eq' (translate <| Multiplicative.ofAdd x)] refine (tendsto_translation_number₀ _).congr fun n ↦ ?_ simp [sub_eq_neg_add, Units.conj_pow'] theorem tendsto_translation_number' (x : ℝ) : Tendsto (fun n : ℕ => ((f ^ (n + 1) : CircleDeg1Lift) x - x) / (n + 1)) atTop (𝓝 <| τ f) := mod_cast (tendsto_add_atTop_iff_nat 1).2 (f.tendsto_translationNumber x) theorem translationNumber_mono : Monotone τ := fun f g h => le_of_tendsto_of_tendsto' f.tendsto_translation_number₀ g.tendsto_translation_number₀ fun n => by gcongr; exact pow_mono h _ _ theorem translationNumber_translate (x : ℝ) : τ (translate <| Multiplicative.ofAdd x) = x := translationNumber_eq_of_tendsto₀' _ <| by simp only [translate_iterate, translate_apply, add_zero, Nat.cast_succ, mul_div_cancel_left₀ (M₀ := ℝ) _ (Nat.cast_add_one_ne_zero _), tendsto_const_nhds] theorem translationNumber_le_of_le_add {z : ℝ} (hz : ∀ x, f x ≤ x + z) : τ f ≤ z := translationNumber_translate z ▸ translationNumber_mono fun x => (hz x).trans_eq (add_comm _ _) theorem le_translationNumber_of_add_le {z : ℝ} (hz : ∀ x, x + z ≤ f x) : z ≤ τ f := translationNumber_translate z ▸ translationNumber_mono fun x => (add_comm _ _).trans_le (hz x) theorem translationNumber_le_of_le_add_int {x : ℝ} {m : ℤ} (h : f x ≤ x + m) : τ f ≤ m := le_of_tendsto' (f.tendsto_translation_number' x) fun n => (div_le_iff₀' (n.cast_add_one_pos : (0 : ℝ) < _)).mpr <| sub_le_iff_le_add'.2 <| (coe_pow f (n + 1)).symm ▸ @Nat.cast_add_one ℝ _ n ▸ f.iterate_le_of_map_le_add_int h (n + 1) theorem translationNumber_le_of_le_add_nat {x : ℝ} {m : ℕ} (h : f x ≤ x + m) : τ f ≤ m := @translationNumber_le_of_le_add_int f x m h theorem le_translationNumber_of_add_int_le {x : ℝ} {m : ℤ} (h : x + m ≤ f x) : ↑m ≤ τ f := ge_of_tendsto' (f.tendsto_translation_number' x) fun n => (le_div_iff₀ (n.cast_add_one_pos : (0 : ℝ) < _)).mpr <| le_sub_iff_add_le'.2 <| by simp only [coe_pow, mul_comm (m : ℝ), ← Nat.cast_add_one, f.le_iterate_of_add_int_le_map h] theorem le_translationNumber_of_add_nat_le {x : ℝ} {m : ℕ} (h : x + m ≤ f x) : ↑m ≤ τ f := @le_translationNumber_of_add_int_le f x m h /-- If `f x - x` is an integer number `m` for some point `x`, then `τ f = m`. On the circle this means that a map with a fixed point has rotation number zero. -/ theorem translationNumber_of_eq_add_int {x : ℝ} {m : ℤ} (h : f x = x + m) : τ f = m := le_antisymm (translationNumber_le_of_le_add_int f <| le_of_eq h) (le_translationNumber_of_add_int_le f <| le_of_eq h.symm) theorem floor_sub_le_translationNumber (x : ℝ) : ↑⌊f x - x⌋ ≤ τ f := le_translationNumber_of_add_int_le f <| le_sub_iff_add_le'.1 (floor_le <| f x - x) theorem translationNumber_le_ceil_sub (x : ℝ) : τ f ≤ ⌈f x - x⌉ := translationNumber_le_of_le_add_int f <| sub_le_iff_le_add'.1 (le_ceil <| f x - x)
theorem map_lt_of_translationNumber_lt_int {n : ℤ} (h : τ f < n) (x : ℝ) : f x < x + n := not_le.1 <| mt f.le_translationNumber_of_add_int_le <| not_le.2 h
Mathlib/Dynamics/Circle/RotationNumber/TranslationNumber.lean
737
739
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Algebra.BigOperators.Group.Finset.Powerset import Mathlib.Algebra.NoZeroSMulDivisors.Pi import Mathlib.Data.Finset.Sort import Mathlib.Data.Fintype.BigOperators import Mathlib.Data.Fintype.Powerset import Mathlib.LinearAlgebra.Pi import Mathlib.Logic.Equiv.Fintype import Mathlib.Tactic.Abel /-! # Multilinear maps We define multilinear maps as maps from `∀ (i : ι), M₁ i` to `M₂` which are linear in each coordinate. Here, `M₁ i` and `M₂` are modules over a ring `R`, and `ι` is an arbitrary type (although some statements will require it to be a fintype). This space, denoted by `MultilinearMap R M₁ M₂`, inherits a module structure by pointwise addition and multiplication. ## Main definitions * `MultilinearMap R M₁ M₂` is the space of multilinear maps from `∀ (i : ι), M₁ i` to `M₂`. * `f.map_update_smul` is the multiplicativity of the multilinear map `f` along each coordinate. * `f.map_update_add` is the additivity of the multilinear map `f` along each coordinate. * `f.map_smul_univ` expresses the multiplicativity of `f` over all coordinates at the same time, writing `f (fun i => c i • m i)` as `(∏ i, c i) • f m`. * `f.map_add_univ` expresses the additivity of `f` over all coordinates at the same time, writing `f (m + m')` as the sum over all subsets `s` of `ι` of `f (s.piecewise m m')`. * `f.map_sum` expresses `f (Σ_{j₁} g₁ j₁, ..., Σ_{jₙ} gₙ jₙ)` as the sum of `f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all possible functions. See `Mathlib.LinearAlgebra.Multilinear.Curry` for the currying of multilinear maps. ## Implementation notes Expressing that a map is linear along the `i`-th coordinate when all other coordinates are fixed can be done in two (equivalent) different ways: * fixing a vector `m : ∀ (j : ι - i), M₁ j.val`, and then choosing separately the `i`-th coordinate * fixing a vector `m : ∀j, M₁ j`, and then modifying its `i`-th coordinate The second way is more artificial as the value of `m` at `i` is not relevant, but it has the advantage of avoiding subtype inclusion issues. This is the definition we use, based on `Function.update` that allows to change the value of `m` at `i`. Note that the use of `Function.update` requires a `DecidableEq ι` term to appear somewhere in the statement of `MultilinearMap.map_update_add'` and `MultilinearMap.map_update_smul'`. Three possible choices are: 1. Requiring `DecidableEq ι` as an argument to `MultilinearMap` (as we did originally). 2. Using `Classical.decEq ι` in the statement of `map_add'` and `map_smul'`. 3. Quantifying over all possible `DecidableEq ι` instances in the statement of `map_add'` and `map_smul'`. Option 1 works fine, but puts unnecessary constraints on the user (the zero map certainly does not need decidability). Option 2 looks great at first, but in the common case when `ι = Fin n` it introduces non-defeq decidability instance diamonds within the context of proving `map_update_add'` and `map_update_smul'`, of the form `Fin.decidableEq n = Classical.decEq (Fin n)`. Option 3 of course does something similar, but of the form `Fin.decidableEq n = _inst`, which is much easier to clean up since `_inst` is a free variable and so the equality can just be substituted. -/ open Fin Function Finset Set universe uR uS uι v v' v₁ v₂ v₃ variable {R : Type uR} {S : Type uS} {ι : Type uι} {n : ℕ} {M : Fin n.succ → Type v} {M₁ : ι → Type v₁} {M₂ : Type v₂} {M₃ : Type v₃} {M' : Type v'} -- Don't generate injectivity lemmas, which the `simpNF` linter will time out on. set_option genInjectivity false in /-- Multilinear maps over the ring `R`, from `∀ i, M₁ i` to `M₂` where `M₁ i` and `M₂` are modules over `R`. -/ structure MultilinearMap (R : Type uR) {ι : Type uι} (M₁ : ι → Type v₁) (M₂ : Type v₂) [Semiring R] [∀ i, AddCommMonoid (M₁ i)] [AddCommMonoid M₂] [∀ i, Module R (M₁ i)] [Module R M₂] where /-- The underlying multivariate function of a multilinear map. -/ toFun : (∀ i, M₁ i) → M₂ /-- A multilinear map is additive in every argument. -/ map_update_add' : ∀ [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (x y : M₁ i), toFun (update m i (x + y)) = toFun (update m i x) + toFun (update m i y) /-- A multilinear map is compatible with scalar multiplication in every argument. -/ map_update_smul' : ∀ [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (c : R) (x : M₁ i), toFun (update m i (c • x)) = c • toFun (update m i x) namespace MultilinearMap section Semiring variable [Semiring R] [∀ i, AddCommMonoid (M i)] [∀ i, AddCommMonoid (M₁ i)] [AddCommMonoid M₂] [AddCommMonoid M₃] [AddCommMonoid M'] [∀ i, Module R (M i)] [∀ i, Module R (M₁ i)] [Module R M₂] [Module R M₃] [Module R M'] (f f' : MultilinearMap R M₁ M₂) instance : FunLike (MultilinearMap R M₁ M₂) (∀ i, M₁ i) M₂ where coe f := f.toFun coe_injective' f g h := by cases f; cases g; cases h; rfl initialize_simps_projections MultilinearMap (toFun → apply) /-- Constructor for `MultilinearMap R M₁ M₂` when the index type `ι` is already endowed with a `DecidableEq` instance. -/ @[simps] def mk' [DecidableEq ι] (f : (∀ i, M₁ i) → M₂) (h₁ : ∀ (m : ∀ i, M₁ i) (i : ι) (x y : M₁ i), f (update m i (x + y)) = f (update m i x) + f (update m i y) := by aesop) (h₂ : ∀ (m : ∀ i, M₁ i) (i : ι) (c : R) (x : M₁ i), f (update m i (c • x)) = c • f (update m i x) := by aesop) : MultilinearMap R M₁ M₂ where toFun := f map_update_add' m i x y := by convert h₁ m i x y map_update_smul' m i c x := by convert h₂ m i c x @[simp] theorem toFun_eq_coe : f.toFun = ⇑f := rfl @[simp] theorem coe_mk (f : (∀ i, M₁ i) → M₂) (h₁ h₂) : ⇑(⟨f, h₁, h₂⟩ : MultilinearMap R M₁ M₂) = f := rfl theorem congr_fun {f g : MultilinearMap R M₁ M₂} (h : f = g) (x : ∀ i, M₁ i) : f x = g x := DFunLike.congr_fun h x nonrec theorem congr_arg (f : MultilinearMap R M₁ M₂) {x y : ∀ i, M₁ i} (h : x = y) : f x = f y := DFunLike.congr_arg f h theorem coe_injective : Injective ((↑) : MultilinearMap R M₁ M₂ → (∀ i, M₁ i) → M₂) := DFunLike.coe_injective @[norm_cast] theorem coe_inj {f g : MultilinearMap R M₁ M₂} : (f : (∀ i, M₁ i) → M₂) = g ↔ f = g := DFunLike.coe_fn_eq @[ext] theorem ext {f f' : MultilinearMap R M₁ M₂} (H : ∀ x, f x = f' x) : f = f' := DFunLike.ext _ _ H @[simp] theorem mk_coe (f : MultilinearMap R M₁ M₂) (h₁ h₂) : (⟨f, h₁, h₂⟩ : MultilinearMap R M₁ M₂) = f := rfl @[simp] protected theorem map_update_add [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (x y : M₁ i) : f (update m i (x + y)) = f (update m i x) + f (update m i y) := f.map_update_add' m i x y @[deprecated (since := "2024-11-03")] protected alias map_add := MultilinearMap.map_update_add @[deprecated (since := "2024-11-03")] protected alias map_add' := MultilinearMap.map_update_add /-- Earlier, this name was used by what is now called `MultilinearMap.map_update_smul_left`. -/ @[simp] protected theorem map_update_smul [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) (c : R) (x : M₁ i) : f (update m i (c • x)) = c • f (update m i x) := f.map_update_smul' m i c x @[deprecated (since := "2024-11-03")] protected alias map_smul := MultilinearMap.map_update_smul @[deprecated (since := "2024-11-03")] protected alias map_smul' := MultilinearMap.map_update_smul theorem map_coord_zero {m : ∀ i, M₁ i} (i : ι) (h : m i = 0) : f m = 0 := by classical have : (0 : R) • (0 : M₁ i) = 0 := by simp rw [← update_eq_self i m, h, ← this, f.map_update_smul, zero_smul] @[simp] theorem map_update_zero [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) : f (update m i 0) = 0 := f.map_coord_zero i (update_self i 0 m) @[simp] theorem map_zero [Nonempty ι] : f 0 = 0 := by obtain ⟨i, _⟩ : ∃ i : ι, i ∈ Set.univ := Set.exists_mem_of_nonempty ι exact map_coord_zero f i rfl instance : Add (MultilinearMap R M₁ M₂) := ⟨fun f f' => ⟨fun x => f x + f' x, fun m i x y => by simp [add_left_comm, add_assoc], fun m i c x => by simp [smul_add]⟩⟩ @[simp] theorem add_apply (m : ∀ i, M₁ i) : (f + f') m = f m + f' m := rfl instance : Zero (MultilinearMap R M₁ M₂) := ⟨⟨fun _ => 0, fun _ _ _ _ => by simp, fun _ _ c _ => by simp⟩⟩ instance : Inhabited (MultilinearMap R M₁ M₂) := ⟨0⟩ @[simp] theorem zero_apply (m : ∀ i, M₁ i) : (0 : MultilinearMap R M₁ M₂) m = 0 := rfl section SMul variable [DistribSMul S M₂] [SMulCommClass R S M₂] instance : SMul S (MultilinearMap R M₁ M₂) := ⟨fun c f => ⟨fun m => c • f m, fun m i x y => by simp [smul_add], fun l i x d => by simp [← smul_comm x c (_ : M₂)]⟩⟩ @[simp] theorem smul_apply (f : MultilinearMap R M₁ M₂) (c : S) (m : ∀ i, M₁ i) : (c • f) m = c • f m := rfl theorem coe_smul (c : S) (f : MultilinearMap R M₁ M₂) : ⇑(c • f) = c • (⇑ f) := rfl end SMul instance addCommMonoid : AddCommMonoid (MultilinearMap R M₁ M₂) := coe_injective.addCommMonoid _ rfl (fun _ _ => rfl) fun _ _ => rfl /-- Coercion of a multilinear map to a function as an additive monoid homomorphism. -/ @[simps] def coeAddMonoidHom : MultilinearMap R M₁ M₂ →+ (((i : ι) → M₁ i) → M₂) where toFun := DFunLike.coe; map_zero' := rfl; map_add' _ _ := rfl @[simp] theorem coe_sum {α : Type*} (f : α → MultilinearMap R M₁ M₂) (s : Finset α) : ⇑(∑ a ∈ s, f a) = ∑ a ∈ s, ⇑(f a) := map_sum coeAddMonoidHom f s theorem sum_apply {α : Type*} (f : α → MultilinearMap R M₁ M₂) (m : ∀ i, M₁ i) {s : Finset α} : (∑ a ∈ s, f a) m = ∑ a ∈ s, f a m := by simp /-- If `f` is a multilinear map, then `f.toLinearMap m i` is the linear map obtained by fixing all coordinates but `i` equal to those of `m`, and varying the `i`-th coordinate. -/ @[simps] def toLinearMap [DecidableEq ι] (m : ∀ i, M₁ i) (i : ι) : M₁ i →ₗ[R] M₂ where toFun x := f (update m i x) map_add' x y := by simp map_smul' c x := by simp /-- The cartesian product of two multilinear maps, as a multilinear map. -/ @[simps] def prod (f : MultilinearMap R M₁ M₂) (g : MultilinearMap R M₁ M₃) : MultilinearMap R M₁ (M₂ × M₃) where toFun m := (f m, g m) map_update_add' m i x y := by simp map_update_smul' m i c x := by simp /-- Combine a family of multilinear maps with the same domain and codomains `M' i` into a multilinear map taking values in the space of functions `∀ i, M' i`. -/ @[simps] def pi {ι' : Type*} {M' : ι' → Type*} [∀ i, AddCommMonoid (M' i)] [∀ i, Module R (M' i)] (f : ∀ i, MultilinearMap R M₁ (M' i)) : MultilinearMap R M₁ (∀ i, M' i) where toFun m i := f i m map_update_add' _ _ _ _ := funext fun j => (f j).map_update_add _ _ _ _ map_update_smul' _ _ _ _ := funext fun j => (f j).map_update_smul _ _ _ _ section variable (R M₂ M₃) /-- Equivalence between linear maps `M₂ →ₗ[R] M₃` and one-multilinear maps. -/ @[simps] def ofSubsingleton [Subsingleton ι] (i : ι) : (M₂ →ₗ[R] M₃) ≃ MultilinearMap R (fun _ : ι ↦ M₂) M₃ where toFun f := { toFun := fun x ↦ f (x i) map_update_add' := by intros; simp [update_eq_const_of_subsingleton] map_update_smul' := by intros; simp [update_eq_const_of_subsingleton] } invFun f := { toFun := fun x ↦ f fun _ ↦ x map_add' := fun x y ↦ by simpa [update_eq_const_of_subsingleton] using f.map_update_add 0 i x y map_smul' := fun c x ↦ by simpa [update_eq_const_of_subsingleton] using f.map_update_smul 0 i c x } left_inv _ := rfl right_inv f := by ext x; refine congr_arg f ?_; exact (eq_const_of_subsingleton _ _).symm variable (M₁) {M₂} /-- The constant map is multilinear when `ι` is empty. -/ @[simps -fullyApplied] def constOfIsEmpty [IsEmpty ι] (m : M₂) : MultilinearMap R M₁ M₂ where toFun := Function.const _ m map_update_add' _ := isEmptyElim map_update_smul' _ := isEmptyElim end /-- Given a multilinear map `f` on `n` variables (parameterized by `Fin n`) and a subset `s` of `k` of these variables, one gets a new multilinear map on `Fin k` by varying these variables, and fixing the other ones equal to a given value `z`. It is denoted by `f.restr s hk z`, where `hk` is a proof that the cardinality of `s` is `k`. The implicit identification between `Fin k` and `s` that we use is the canonical (increasing) bijection. -/ def restr {k n : ℕ} (f : MultilinearMap R (fun _ : Fin n => M') M₂) (s : Finset (Fin n)) (hk : #s = k) (z : M') : MultilinearMap R (fun _ : Fin k => M') M₂ where toFun v := f fun j => if h : j ∈ s then v ((s.orderIsoOfFin hk).symm ⟨j, h⟩) else z /- Porting note: The proofs of the following two lemmas used to only use `erw` followed by `simp`, but it seems `erw` no longer unfolds or unifies well enough to work without more help. -/ map_update_add' v i x y := by erw [dite_comp_equiv_update (s.orderIsoOfFin hk).toEquiv, dite_comp_equiv_update (s.orderIsoOfFin hk).toEquiv, dite_comp_equiv_update (s.orderIsoOfFin hk).toEquiv] simp map_update_smul' v i c x := by erw [dite_comp_equiv_update (s.orderIsoOfFin hk).toEquiv, dite_comp_equiv_update (s.orderIsoOfFin hk).toEquiv] simp /-- In the specific case of multilinear maps on spaces indexed by `Fin (n+1)`, where one can build an element of `∀ (i : Fin (n+1)), M i` using `cons`, one can express directly the additivity of a multilinear map along the first variable. -/ theorem cons_add (f : MultilinearMap R M M₂) (m : ∀ i : Fin n, M i.succ) (x y : M 0) : f (cons (x + y) m) = f (cons x m) + f (cons y m) := by simp_rw [← update_cons_zero x m (x + y), f.map_update_add, update_cons_zero] /-- In the specific case of multilinear maps on spaces indexed by `Fin (n+1)`, where one can build an element of `∀ (i : Fin (n+1)), M i` using `cons`, one can express directly the multiplicativity of a multilinear map along the first variable. -/ theorem cons_smul (f : MultilinearMap R M M₂) (m : ∀ i : Fin n, M i.succ) (c : R) (x : M 0) : f (cons (c • x) m) = c • f (cons x m) := by simp_rw [← update_cons_zero x m (c • x), f.map_update_smul, update_cons_zero] /-- In the specific case of multilinear maps on spaces indexed by `Fin (n+1)`, where one can build an element of `∀ (i : Fin (n+1)), M i` using `snoc`, one can express directly the additivity of a multilinear map along the first variable. -/ theorem snoc_add (f : MultilinearMap R M M₂) (m : ∀ i : Fin n, M (castSucc i)) (x y : M (last n)) : f (snoc m (x + y)) = f (snoc m x) + f (snoc m y) := by simp_rw [← update_snoc_last x m (x + y), f.map_update_add, update_snoc_last] /-- In the specific case of multilinear maps on spaces indexed by `Fin (n+1)`, where one can build an element of `∀ (i : Fin (n+1)), M i` using `cons`, one can express directly the multiplicativity of a multilinear map along the first variable. -/ theorem snoc_smul (f : MultilinearMap R M M₂) (m : ∀ i : Fin n, M (castSucc i)) (c : R) (x : M (last n)) : f (snoc m (c • x)) = c • f (snoc m x) := by simp_rw [← update_snoc_last x m (c • x), f.map_update_smul, update_snoc_last] section variable {M₁' : ι → Type*} [∀ i, AddCommMonoid (M₁' i)] [∀ i, Module R (M₁' i)] variable {M₁'' : ι → Type*} [∀ i, AddCommMonoid (M₁'' i)] [∀ i, Module R (M₁'' i)] /-- If `g` is a multilinear map and `f` is a collection of linear maps, then `g (f₁ m₁, ..., fₙ mₙ)` is again a multilinear map, that we call `g.compLinearMap f`. -/ def compLinearMap (g : MultilinearMap R M₁' M₂) (f : ∀ i, M₁ i →ₗ[R] M₁' i) : MultilinearMap R M₁ M₂ where toFun m := g fun i => f i (m i) map_update_add' m i x y := by have : ∀ j z, f j (update m i z j) = update (fun k => f k (m k)) i (f i z) j := fun j z => Function.apply_update (fun k => f k) _ _ _ _ simp [this] map_update_smul' m i c x := by have : ∀ j z, f j (update m i z j) = update (fun k => f k (m k)) i (f i z) j := fun j z => Function.apply_update (fun k => f k) _ _ _ _ simp [this] @[simp] theorem compLinearMap_apply (g : MultilinearMap R M₁' M₂) (f : ∀ i, M₁ i →ₗ[R] M₁' i) (m : ∀ i, M₁ i) : g.compLinearMap f m = g fun i => f i (m i) := rfl /-- Composing a multilinear map twice with a linear map in each argument is the same as composing with their composition. -/ theorem compLinearMap_assoc (g : MultilinearMap R M₁'' M₂) (f₁ : ∀ i, M₁' i →ₗ[R] M₁'' i) (f₂ : ∀ i, M₁ i →ₗ[R] M₁' i) : (g.compLinearMap f₁).compLinearMap f₂ = g.compLinearMap fun i => f₁ i ∘ₗ f₂ i := rfl /-- Composing the zero multilinear map with a linear map in each argument. -/ @[simp] theorem zero_compLinearMap (f : ∀ i, M₁ i →ₗ[R] M₁' i) : (0 : MultilinearMap R M₁' M₂).compLinearMap f = 0 := ext fun _ => rfl /-- Composing a multilinear map with the identity linear map in each argument. -/ @[simp] theorem compLinearMap_id (g : MultilinearMap R M₁' M₂) : (g.compLinearMap fun _ => LinearMap.id) = g := ext fun _ => rfl /-- Composing with a family of surjective linear maps is injective. -/ theorem compLinearMap_injective (f : ∀ i, M₁ i →ₗ[R] M₁' i) (hf : ∀ i, Surjective (f i)) : Injective fun g : MultilinearMap R M₁' M₂ => g.compLinearMap f := fun g₁ g₂ h => ext fun x => by simpa [fun i => surjInv_eq (hf i)] using MultilinearMap.ext_iff.mp h fun i => surjInv (hf i) (x i) theorem compLinearMap_inj (f : ∀ i, M₁ i →ₗ[R] M₁' i) (hf : ∀ i, Surjective (f i)) (g₁ g₂ : MultilinearMap R M₁' M₂) : g₁.compLinearMap f = g₂.compLinearMap f ↔ g₁ = g₂ := (compLinearMap_injective _ hf).eq_iff /-- Composing a multilinear map with a linear equiv on each argument gives the zero map if and only if the multilinear map is the zero map. -/ @[simp] theorem comp_linearEquiv_eq_zero_iff (g : MultilinearMap R M₁' M₂) (f : ∀ i, M₁ i ≃ₗ[R] M₁' i) : (g.compLinearMap fun i => (f i : M₁ i →ₗ[R] M₁' i)) = 0 ↔ g = 0 := by set f' := fun i => (f i : M₁ i →ₗ[R] M₁' i) rw [← zero_compLinearMap f', compLinearMap_inj f' fun i => (f i).surjective] end /-- If one adds to a vector `m'` another vector `m`, but only for coordinates in a finset `t`, then the image under a multilinear map `f` is the sum of `f (s.piecewise m m')` along all subsets `s` of `t`. This is mainly an auxiliary statement to prove the result when `t = univ`, given in `map_add_univ`, although it can be useful in its own right as it does not require the index set `ι` to be finite. -/ theorem map_piecewise_add [DecidableEq ι] (m m' : ∀ i, M₁ i) (t : Finset ι) : f (t.piecewise (m + m') m') = ∑ s ∈ t.powerset, f (s.piecewise m m') := by revert m' refine Finset.induction_on t (by simp) ?_ intro i t hit Hrec m' have A : (insert i t).piecewise (m + m') m' = update (t.piecewise (m + m') m') i (m i + m' i) := t.piecewise_insert _ _ _ have B : update (t.piecewise (m + m') m') i (m' i) = t.piecewise (m + m') m' := by ext j by_cases h : j = i · rw [h] simp [hit] · simp [h] let m'' := update m' i (m i) have C : update (t.piecewise (m + m') m') i (m i) = t.piecewise (m + m'') m'' := by ext j by_cases h : j = i · rw [h] simp [m'', hit] · by_cases h' : j ∈ t <;> simp [m'', h, hit, h'] rw [A, f.map_update_add, B, C, Finset.sum_powerset_insert hit, Hrec, Hrec, add_comm (_ : M₂)] congr 1 refine Finset.sum_congr rfl fun s hs => ?_ have : (insert i s).piecewise m m' = s.piecewise m m'' := by ext j by_cases h : j = i · rw [h] simp [m'', Finset.not_mem_of_mem_powerset_of_not_mem hs hit] · by_cases h' : j ∈ s <;> simp [m'', h, h']
rw [this] /-- Additivity of a multilinear map along all coordinates at the same time, writing `f (m + m')` as the sum of `f (s.piecewise m m')` over all sets `s`. -/
Mathlib/LinearAlgebra/Multilinear/Basic.lean
437
440
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.Topology.MetricSpace.IsometricSMul /-! # Hausdorff distance The Hausdorff distance on subsets of a metric (or emetric) space. Given two subsets `s` and `t` of a metric space, their Hausdorff distance is the smallest `d` such that any point `s` is within `d` of a point in `t`, and conversely. This quantity is often infinite (think of `s` bounded and `t` unbounded), and therefore better expressed in the setting of emetric spaces. ## Main definitions This files introduces: * `EMetric.infEdist x s`, the infimum edistance of a point `x` to a set `s` in an emetric space * `EMetric.hausdorffEdist s t`, the Hausdorff edistance of two sets in an emetric space * Versions of these notions on metric spaces, called respectively `Metric.infDist` and `Metric.hausdorffDist` ## Main results * `infEdist_closure`: the edistance to a set and its closure coincide * `EMetric.mem_closure_iff_infEdist_zero`: a point `x` belongs to the closure of `s` iff `infEdist x s = 0` * `IsCompact.exists_infEdist_eq_edist`: if `s` is compact and non-empty, there exists a point `y` which attains this edistance * `IsOpen.exists_iUnion_isClosed`: every open set `U` can be written as the increasing union of countably many closed subsets of `U` * `hausdorffEdist_closure`: replacing a set by its closure does not change the Hausdorff edistance * `hausdorffEdist_zero_iff_closure_eq_closure`: two sets have Hausdorff edistance zero iff their closures coincide * the Hausdorff edistance is symmetric and satisfies the triangle inequality * in particular, closed sets in an emetric space are an emetric space (this is shown in `EMetricSpace.closeds.emetricspace`) * versions of these notions on metric spaces * `hausdorffEdist_ne_top_of_nonempty_of_bounded`: if two sets in a metric space are nonempty and bounded in a metric space, they are at finite Hausdorff edistance. ## Tags metric space, Hausdorff distance -/ noncomputable section open NNReal ENNReal Topology Set Filter Pointwise Bornology universe u v w variable {ι : Sort*} {α : Type u} {β : Type v} namespace EMetric section InfEdist variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] {x y : α} {s t : Set α} {Φ : α → β} /-! ### Distance of a point to a set as a function into `ℝ≥0∞`. -/ /-- The minimal edistance of a point to a set -/ def infEdist (x : α) (s : Set α) : ℝ≥0∞ := ⨅ y ∈ s, edist x y @[simp] theorem infEdist_empty : infEdist x ∅ = ∞ := iInf_emptyset theorem le_infEdist {d} : d ≤ infEdist x s ↔ ∀ y ∈ s, d ≤ edist x y := by simp only [infEdist, le_iInf_iff] /-- The edist to a union is the minimum of the edists -/ @[simp] theorem infEdist_union : infEdist x (s ∪ t) = infEdist x s ⊓ infEdist x t := iInf_union @[simp] theorem infEdist_iUnion (f : ι → Set α) (x : α) : infEdist x (⋃ i, f i) = ⨅ i, infEdist x (f i) := iInf_iUnion f _ lemma infEdist_biUnion {ι : Type*} (f : ι → Set α) (I : Set ι) (x : α) : infEdist x (⋃ i ∈ I, f i) = ⨅ i ∈ I, infEdist x (f i) := by simp only [infEdist_iUnion] /-- The edist to a singleton is the edistance to the single point of this singleton -/ @[simp] theorem infEdist_singleton : infEdist x {y} = edist x y := iInf_singleton /-- The edist to a set is bounded above by the edist to any of its points -/ theorem infEdist_le_edist_of_mem (h : y ∈ s) : infEdist x s ≤ edist x y := iInf₂_le y h /-- If a point `x` belongs to `s`, then its edist to `s` vanishes -/ theorem infEdist_zero_of_mem (h : x ∈ s) : infEdist x s = 0 := nonpos_iff_eq_zero.1 <| @edist_self _ _ x ▸ infEdist_le_edist_of_mem h /-- The edist is antitone with respect to inclusion. -/ theorem infEdist_anti (h : s ⊆ t) : infEdist x t ≤ infEdist x s := iInf_le_iInf_of_subset h /-- The edist to a set is `< r` iff there exists a point in the set at edistance `< r` -/ theorem infEdist_lt_iff {r : ℝ≥0∞} : infEdist x s < r ↔ ∃ y ∈ s, edist x y < r := by simp_rw [infEdist, iInf_lt_iff, exists_prop] /-- The edist of `x` to `s` is bounded by the sum of the edist of `y` to `s` and the edist from `x` to `y` -/ theorem infEdist_le_infEdist_add_edist : infEdist x s ≤ infEdist y s + edist x y := calc ⨅ z ∈ s, edist x z ≤ ⨅ z ∈ s, edist y z + edist x y := iInf₂_mono fun _ _ => (edist_triangle _ _ _).trans_eq (add_comm _ _) _ = (⨅ z ∈ s, edist y z) + edist x y := by simp only [ENNReal.iInf_add] theorem infEdist_le_edist_add_infEdist : infEdist x s ≤ edist x y + infEdist y s := by rw [add_comm] exact infEdist_le_infEdist_add_edist theorem edist_le_infEdist_add_ediam (hy : y ∈ s) : edist x y ≤ infEdist x s + diam s := by simp_rw [infEdist, ENNReal.iInf_add] refine le_iInf₂ fun i hi => ?_ calc edist x y ≤ edist x i + edist i y := edist_triangle _ _ _ _ ≤ edist x i + diam s := add_le_add le_rfl (edist_le_diam_of_mem hi hy) /-- The edist to a set depends continuously on the point -/ @[continuity] theorem continuous_infEdist : Continuous fun x => infEdist x s := continuous_of_le_add_edist 1 (by simp) <| by simp only [one_mul, infEdist_le_infEdist_add_edist, forall₂_true_iff] /-- The edist to a set and to its closure coincide -/ theorem infEdist_closure : infEdist x (closure s) = infEdist x s := by refine le_antisymm (infEdist_anti subset_closure) ?_ refine ENNReal.le_of_forall_pos_le_add fun ε εpos h => ?_ have ε0 : 0 < (ε / 2 : ℝ≥0∞) := by simpa [pos_iff_ne_zero] using εpos have : infEdist x (closure s) < infEdist x (closure s) + ε / 2 := ENNReal.lt_add_right h.ne ε0.ne' obtain ⟨y : α, ycs : y ∈ closure s, hy : edist x y < infEdist x (closure s) + ↑ε / 2⟩ := infEdist_lt_iff.mp this obtain ⟨z : α, zs : z ∈ s, dyz : edist y z < ↑ε / 2⟩ := EMetric.mem_closure_iff.1 ycs (ε / 2) ε0 calc infEdist x s ≤ edist x z := infEdist_le_edist_of_mem zs _ ≤ edist x y + edist y z := edist_triangle _ _ _ _ ≤ infEdist x (closure s) + ε / 2 + ε / 2 := add_le_add (le_of_lt hy) (le_of_lt dyz) _ = infEdist x (closure s) + ↑ε := by rw [add_assoc, ENNReal.add_halves] /-- A point belongs to the closure of `s` iff its infimum edistance to this set vanishes -/ theorem mem_closure_iff_infEdist_zero : x ∈ closure s ↔ infEdist x s = 0 := ⟨fun h => by rw [← infEdist_closure] exact infEdist_zero_of_mem h, fun h => EMetric.mem_closure_iff.2 fun ε εpos => infEdist_lt_iff.mp <| by rwa [h]⟩ /-- Given a closed set `s`, a point belongs to `s` iff its infimum edistance to this set vanishes -/ theorem mem_iff_infEdist_zero_of_closed (h : IsClosed s) : x ∈ s ↔ infEdist x s = 0 := by rw [← mem_closure_iff_infEdist_zero, h.closure_eq] /-- The infimum edistance of a point to a set is positive if and only if the point is not in the closure of the set. -/ theorem infEdist_pos_iff_not_mem_closure {x : α} {E : Set α} : 0 < infEdist x E ↔ x ∉ closure E := by rw [mem_closure_iff_infEdist_zero, pos_iff_ne_zero] theorem infEdist_closure_pos_iff_not_mem_closure {x : α} {E : Set α} : 0 < infEdist x (closure E) ↔ x ∉ closure E := by rw [infEdist_closure, infEdist_pos_iff_not_mem_closure] theorem exists_real_pos_lt_infEdist_of_not_mem_closure {x : α} {E : Set α} (h : x ∉ closure E) : ∃ ε : ℝ, 0 < ε ∧ ENNReal.ofReal ε < infEdist x E := by rw [← infEdist_pos_iff_not_mem_closure, ENNReal.lt_iff_exists_real_btwn] at h rcases h with ⟨ε, ⟨_, ⟨ε_pos, ε_lt⟩⟩⟩ exact ⟨ε, ⟨ENNReal.ofReal_pos.mp ε_pos, ε_lt⟩⟩ theorem disjoint_closedBall_of_lt_infEdist {r : ℝ≥0∞} (h : r < infEdist x s) : Disjoint (closedBall x r) s := by rw [disjoint_left] intro y hy h'y apply lt_irrefl (infEdist x s) calc infEdist x s ≤ edist x y := infEdist_le_edist_of_mem h'y _ ≤ r := by rwa [mem_closedBall, edist_comm] at hy _ < infEdist x s := h /-- The infimum edistance is invariant under isometries -/ theorem infEdist_image (hΦ : Isometry Φ) : infEdist (Φ x) (Φ '' t) = infEdist x t := by simp only [infEdist, iInf_image, hΦ.edist_eq] @[to_additive (attr := simp)] theorem infEdist_smul {M} [SMul M α] [IsIsometricSMul M α] (c : M) (x : α) (s : Set α) : infEdist (c • x) (c • s) = infEdist x s := infEdist_image (isometry_smul _ _) theorem _root_.IsOpen.exists_iUnion_isClosed {U : Set α} (hU : IsOpen U) : ∃ F : ℕ → Set α, (∀ n, IsClosed (F n)) ∧ (∀ n, F n ⊆ U) ∧ ⋃ n, F n = U ∧ Monotone F := by obtain ⟨a, a_pos, a_lt_one⟩ : ∃ a : ℝ≥0∞, 0 < a ∧ a < 1 := exists_between zero_lt_one let F := fun n : ℕ => (fun x => infEdist x Uᶜ) ⁻¹' Ici (a ^ n) have F_subset : ∀ n, F n ⊆ U := fun n x hx ↦ by by_contra h have : infEdist x Uᶜ ≠ 0 := ((ENNReal.pow_pos a_pos _).trans_le hx).ne' exact this (infEdist_zero_of_mem h) refine ⟨F, fun n => IsClosed.preimage continuous_infEdist isClosed_Ici, F_subset, ?_, ?_⟩ · show ⋃ n, F n = U refine Subset.antisymm (by simp only [iUnion_subset_iff, F_subset, forall_const]) fun x hx => ?_ have : ¬x ∈ Uᶜ := by simpa using hx rw [mem_iff_infEdist_zero_of_closed hU.isClosed_compl] at this have B : 0 < infEdist x Uᶜ := by simpa [pos_iff_ne_zero] using this have : Filter.Tendsto (fun n => a ^ n) atTop (𝓝 0) := ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one a_lt_one rcases ((tendsto_order.1 this).2 _ B).exists with ⟨n, hn⟩ simp only [mem_iUnion, mem_Ici, mem_preimage] exact ⟨n, hn.le⟩ show Monotone F intro m n hmn x hx simp only [F, mem_Ici, mem_preimage] at hx ⊢ apply le_trans (pow_le_pow_right_of_le_one' a_lt_one.le hmn) hx theorem _root_.IsCompact.exists_infEdist_eq_edist (hs : IsCompact s) (hne : s.Nonempty) (x : α) : ∃ y ∈ s, infEdist x s = edist x y := by have A : Continuous fun y => edist x y := continuous_const.edist continuous_id obtain ⟨y, ys, hy⟩ := hs.exists_isMinOn hne A.continuousOn exact ⟨y, ys, le_antisymm (infEdist_le_edist_of_mem ys) (by rwa [le_infEdist])⟩ theorem exists_pos_forall_lt_edist (hs : IsCompact s) (ht : IsClosed t) (hst : Disjoint s t) : ∃ r : ℝ≥0, 0 < r ∧ ∀ x ∈ s, ∀ y ∈ t, (r : ℝ≥0∞) < edist x y := by rcases s.eq_empty_or_nonempty with (rfl | hne) · use 1 simp obtain ⟨x, hx, h⟩ := hs.exists_isMinOn hne continuous_infEdist.continuousOn have : 0 < infEdist x t := pos_iff_ne_zero.2 fun H => hst.le_bot ⟨hx, (mem_iff_infEdist_zero_of_closed ht).mpr H⟩ rcases ENNReal.lt_iff_exists_nnreal_btwn.1 this with ⟨r, h₀, hr⟩ exact ⟨r, ENNReal.coe_pos.mp h₀, fun y hy z hz => hr.trans_le <| le_infEdist.1 (h hy) z hz⟩ end InfEdist /-! ### The Hausdorff distance as a function into `ℝ≥0∞`. -/ /-- The Hausdorff edistance between two sets is the smallest `r` such that each set is contained in the `r`-neighborhood of the other one -/ irreducible_def hausdorffEdist {α : Type u} [PseudoEMetricSpace α] (s t : Set α) : ℝ≥0∞ := (⨆ x ∈ s, infEdist x t) ⊔ ⨆ y ∈ t, infEdist y s section HausdorffEdist variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] {x : α} {s t u : Set α} {Φ : α → β} /-- The Hausdorff edistance of a set to itself vanishes. -/ @[simp] theorem hausdorffEdist_self : hausdorffEdist s s = 0 := by simp only [hausdorffEdist_def, sup_idem, ENNReal.iSup_eq_zero] exact fun x hx => infEdist_zero_of_mem hx /-- The Haudorff edistances of `s` to `t` and of `t` to `s` coincide. -/ theorem hausdorffEdist_comm : hausdorffEdist s t = hausdorffEdist t s := by simp only [hausdorffEdist_def]; apply sup_comm /-- Bounding the Hausdorff edistance by bounding the edistance of any point in each set to the other set -/ theorem hausdorffEdist_le_of_infEdist {r : ℝ≥0∞} (H1 : ∀ x ∈ s, infEdist x t ≤ r) (H2 : ∀ x ∈ t, infEdist x s ≤ r) : hausdorffEdist s t ≤ r := by simp only [hausdorffEdist_def, sup_le_iff, iSup_le_iff] exact ⟨H1, H2⟩ /-- Bounding the Hausdorff edistance by exhibiting, for any point in each set, another point in the other set at controlled distance -/ theorem hausdorffEdist_le_of_mem_edist {r : ℝ≥0∞} (H1 : ∀ x ∈ s, ∃ y ∈ t, edist x y ≤ r) (H2 : ∀ x ∈ t, ∃ y ∈ s, edist x y ≤ r) : hausdorffEdist s t ≤ r := by refine hausdorffEdist_le_of_infEdist (fun x xs ↦ ?_) (fun x xt ↦ ?_) · rcases H1 x xs with ⟨y, yt, hy⟩ exact le_trans (infEdist_le_edist_of_mem yt) hy · rcases H2 x xt with ⟨y, ys, hy⟩ exact le_trans (infEdist_le_edist_of_mem ys) hy /-- The distance to a set is controlled by the Hausdorff distance. -/ theorem infEdist_le_hausdorffEdist_of_mem (h : x ∈ s) : infEdist x t ≤ hausdorffEdist s t := by rw [hausdorffEdist_def] refine le_trans ?_ le_sup_left exact le_iSup₂ (α := ℝ≥0∞) x h /-- If the Hausdorff distance is `< r`, then any point in one of the sets has a corresponding point at distance `< r` in the other set. -/ theorem exists_edist_lt_of_hausdorffEdist_lt {r : ℝ≥0∞} (h : x ∈ s) (H : hausdorffEdist s t < r) : ∃ y ∈ t, edist x y < r := infEdist_lt_iff.mp <| calc infEdist x t ≤ hausdorffEdist s t := infEdist_le_hausdorffEdist_of_mem h _ < r := H /-- The distance from `x` to `s` or `t` is controlled in terms of the Hausdorff distance between `s` and `t`. -/ theorem infEdist_le_infEdist_add_hausdorffEdist : infEdist x t ≤ infEdist x s + hausdorffEdist s t := ENNReal.le_of_forall_pos_le_add fun ε εpos h => by have ε0 : (ε / 2 : ℝ≥0∞) ≠ 0 := by simpa [pos_iff_ne_zero] using εpos have : infEdist x s < infEdist x s + ε / 2 := ENNReal.lt_add_right (ENNReal.add_lt_top.1 h).1.ne ε0 obtain ⟨y : α, ys : y ∈ s, dxy : edist x y < infEdist x s + ↑ε / 2⟩ := infEdist_lt_iff.mp this have : hausdorffEdist s t < hausdorffEdist s t + ε / 2 := ENNReal.lt_add_right (ENNReal.add_lt_top.1 h).2.ne ε0 obtain ⟨z : α, zt : z ∈ t, dyz : edist y z < hausdorffEdist s t + ↑ε / 2⟩ := exists_edist_lt_of_hausdorffEdist_lt ys this calc infEdist x t ≤ edist x z := infEdist_le_edist_of_mem zt _ ≤ edist x y + edist y z := edist_triangle _ _ _ _ ≤ infEdist x s + ε / 2 + (hausdorffEdist s t + ε / 2) := add_le_add dxy.le dyz.le _ = infEdist x s + hausdorffEdist s t + ε := by simp [ENNReal.add_halves, add_comm, add_left_comm] /-- The Hausdorff edistance is invariant under isometries. -/ theorem hausdorffEdist_image (h : Isometry Φ) : hausdorffEdist (Φ '' s) (Φ '' t) = hausdorffEdist s t := by simp only [hausdorffEdist_def, iSup_image, infEdist_image h] /-- The Hausdorff distance is controlled by the diameter of the union. -/ theorem hausdorffEdist_le_ediam (hs : s.Nonempty) (ht : t.Nonempty) : hausdorffEdist s t ≤ diam (s ∪ t) := by rcases hs with ⟨x, xs⟩ rcases ht with ⟨y, yt⟩ refine hausdorffEdist_le_of_mem_edist ?_ ?_ · intro z hz exact ⟨y, yt, edist_le_diam_of_mem (subset_union_left hz) (subset_union_right yt)⟩ · intro z hz exact ⟨x, xs, edist_le_diam_of_mem (subset_union_right hz) (subset_union_left xs)⟩ /-- The Hausdorff distance satisfies the triangle inequality. -/ theorem hausdorffEdist_triangle : hausdorffEdist s u ≤ hausdorffEdist s t + hausdorffEdist t u := by rw [hausdorffEdist_def] simp only [sup_le_iff, iSup_le_iff] constructor · show ∀ x ∈ s, infEdist x u ≤ hausdorffEdist s t + hausdorffEdist t u exact fun x xs => calc infEdist x u ≤ infEdist x t + hausdorffEdist t u := infEdist_le_infEdist_add_hausdorffEdist _ ≤ hausdorffEdist s t + hausdorffEdist t u := add_le_add_right (infEdist_le_hausdorffEdist_of_mem xs) _ · show ∀ x ∈ u, infEdist x s ≤ hausdorffEdist s t + hausdorffEdist t u exact fun x xu => calc infEdist x s ≤ infEdist x t + hausdorffEdist t s := infEdist_le_infEdist_add_hausdorffEdist _ ≤ hausdorffEdist u t + hausdorffEdist t s := add_le_add_right (infEdist_le_hausdorffEdist_of_mem xu) _ _ = hausdorffEdist s t + hausdorffEdist t u := by simp [hausdorffEdist_comm, add_comm] /-- Two sets are at zero Hausdorff edistance if and only if they have the same closure. -/ theorem hausdorffEdist_zero_iff_closure_eq_closure : hausdorffEdist s t = 0 ↔ closure s = closure t := by simp only [hausdorffEdist_def, ENNReal.sup_eq_zero, ENNReal.iSup_eq_zero, ← subset_def, ← mem_closure_iff_infEdist_zero, subset_antisymm_iff, isClosed_closure.closure_subset_iff] /-- The Hausdorff edistance between a set and its closure vanishes. -/ @[simp] theorem hausdorffEdist_self_closure : hausdorffEdist s (closure s) = 0 := by rw [hausdorffEdist_zero_iff_closure_eq_closure, closure_closure] /-- Replacing a set by its closure does not change the Hausdorff edistance. -/ @[simp] theorem hausdorffEdist_closure₁ : hausdorffEdist (closure s) t = hausdorffEdist s t := by refine le_antisymm ?_ ?_ · calc _ ≤ hausdorffEdist (closure s) s + hausdorffEdist s t := hausdorffEdist_triangle _ = hausdorffEdist s t := by simp [hausdorffEdist_comm] · calc _ ≤ hausdorffEdist s (closure s) + hausdorffEdist (closure s) t := hausdorffEdist_triangle _ = hausdorffEdist (closure s) t := by simp /-- Replacing a set by its closure does not change the Hausdorff edistance. -/ @[simp] theorem hausdorffEdist_closure₂ : hausdorffEdist s (closure t) = hausdorffEdist s t := by simp [@hausdorffEdist_comm _ _ s _] /-- The Hausdorff edistance between sets or their closures is the same. -/ theorem hausdorffEdist_closure : hausdorffEdist (closure s) (closure t) = hausdorffEdist s t := by simp /-- Two closed sets are at zero Hausdorff edistance if and only if they coincide. -/ theorem hausdorffEdist_zero_iff_eq_of_closed (hs : IsClosed s) (ht : IsClosed t) : hausdorffEdist s t = 0 ↔ s = t := by rw [hausdorffEdist_zero_iff_closure_eq_closure, hs.closure_eq, ht.closure_eq] /-- The Haudorff edistance to the empty set is infinite. -/ theorem hausdorffEdist_empty (ne : s.Nonempty) : hausdorffEdist s ∅ = ∞ := by rcases ne with ⟨x, xs⟩ have : infEdist x ∅ ≤ hausdorffEdist s ∅ := infEdist_le_hausdorffEdist_of_mem xs simpa using this /-- If a set is at finite Hausdorff edistance of a nonempty set, it is nonempty. -/ theorem nonempty_of_hausdorffEdist_ne_top (hs : s.Nonempty) (fin : hausdorffEdist s t ≠ ⊤) : t.Nonempty := t.eq_empty_or_nonempty.resolve_left fun ht ↦ fin (ht.symm ▸ hausdorffEdist_empty hs) theorem empty_or_nonempty_of_hausdorffEdist_ne_top (fin : hausdorffEdist s t ≠ ⊤) : (s = ∅ ∧ t = ∅) ∨ (s.Nonempty ∧ t.Nonempty) := by rcases s.eq_empty_or_nonempty with hs | hs · rcases t.eq_empty_or_nonempty with ht | ht · exact Or.inl ⟨hs, ht⟩ · rw [hausdorffEdist_comm] at fin exact Or.inr ⟨nonempty_of_hausdorffEdist_ne_top ht fin, ht⟩ · exact Or.inr ⟨hs, nonempty_of_hausdorffEdist_ne_top hs fin⟩ end HausdorffEdist -- section end EMetric /-! Now, we turn to the same notions in metric spaces. To avoid the difficulties related to `sInf` and `sSup` on `ℝ` (which is only conditionally complete), we use the notions in `ℝ≥0∞` formulated in terms of the edistance, and coerce them to `ℝ`. Then their properties follow readily from the corresponding properties in `ℝ≥0∞`, modulo some tedious rewriting of inequalities from one to the other. -/ --namespace namespace Metric section variable [PseudoMetricSpace α] [PseudoMetricSpace β] {s t u : Set α} {x y : α} {Φ : α → β} open EMetric /-! ### Distance of a point to a set as a function into `ℝ`. -/ /-- The minimal distance of a point to a set -/ def infDist (x : α) (s : Set α) : ℝ := ENNReal.toReal (infEdist x s) theorem infDist_eq_iInf : infDist x s = ⨅ y : s, dist x y := by rw [infDist, infEdist, iInf_subtype', ENNReal.toReal_iInf] · simp only [dist_edist] · exact fun _ ↦ edist_ne_top _ _ /-- The minimal distance is always nonnegative -/ theorem infDist_nonneg : 0 ≤ infDist x s := toReal_nonneg /-- The minimal distance to the empty set is 0 (if you want to have the more reasonable value `∞` instead, use `EMetric.infEdist`, which takes values in `ℝ≥0∞`) -/ @[simp] theorem infDist_empty : infDist x ∅ = 0 := by simp [infDist] lemma isGLB_infDist (hs : s.Nonempty) : IsGLB ((dist x ·) '' s) (infDist x s) := by simpa [infDist_eq_iInf, sInf_image'] using isGLB_csInf (hs.image _) ⟨0, by simp [lowerBounds, dist_nonneg]⟩ /-- In a metric space, the minimal edistance to a nonempty set is finite. -/ theorem infEdist_ne_top (h : s.Nonempty) : infEdist x s ≠ ⊤ := by rcases h with ⟨y, hy⟩ exact ne_top_of_le_ne_top (edist_ne_top _ _) (infEdist_le_edist_of_mem hy) @[simp] theorem infEdist_eq_top_iff : infEdist x s = ∞ ↔ s = ∅ := by rcases s.eq_empty_or_nonempty with rfl | hs <;> simp [*, Nonempty.ne_empty, infEdist_ne_top] /-- The minimal distance of a point to a set containing it vanishes. -/ theorem infDist_zero_of_mem (h : x ∈ s) : infDist x s = 0 := by simp [infEdist_zero_of_mem h, infDist] /-- The minimal distance to a singleton is the distance to the unique point in this singleton. -/ @[simp] theorem infDist_singleton : infDist x {y} = dist x y := by simp [infDist, dist_edist] /-- The minimal distance to a set is bounded by the distance to any point in this set. -/ theorem infDist_le_dist_of_mem (h : y ∈ s) : infDist x s ≤ dist x y := by rw [dist_edist, infDist] exact ENNReal.toReal_mono (edist_ne_top _ _) (infEdist_le_edist_of_mem h) /-- The minimal distance is monotone with respect to inclusion. -/ theorem infDist_le_infDist_of_subset (h : s ⊆ t) (hs : s.Nonempty) : infDist x t ≤ infDist x s := ENNReal.toReal_mono (infEdist_ne_top hs) (infEdist_anti h) lemma le_infDist {r : ℝ} (hs : s.Nonempty) : r ≤ infDist x s ↔ ∀ ⦃y⦄, y ∈ s → r ≤ dist x y := by simp_rw [infDist, ← ENNReal.ofReal_le_iff_le_toReal (infEdist_ne_top hs), le_infEdist, ENNReal.ofReal_le_iff_le_toReal (edist_ne_top _ _), ← dist_edist] /-- The minimal distance to a set `s` is `< r` iff there exists a point in `s` at distance `< r`. -/ theorem infDist_lt_iff {r : ℝ} (hs : s.Nonempty) : infDist x s < r ↔ ∃ y ∈ s, dist x y < r := by simp [← not_le, le_infDist hs] /-- The minimal distance from `x` to `s` is bounded by the distance from `y` to `s`, modulo the distance between `x` and `y`. -/ theorem infDist_le_infDist_add_dist : infDist x s ≤ infDist y s + dist x y := by rw [infDist, infDist, dist_edist] refine ENNReal.toReal_le_add' infEdist_le_infEdist_add_edist ?_ (flip absurd (edist_ne_top _ _)) simp only [infEdist_eq_top_iff, imp_self] theorem not_mem_of_dist_lt_infDist (h : dist x y < infDist x s) : y ∉ s := fun hy => h.not_le <| infDist_le_dist_of_mem hy theorem disjoint_ball_infDist : Disjoint (ball x (infDist x s)) s := disjoint_left.2 fun _y hy => not_mem_of_dist_lt_infDist <| mem_ball'.1 hy theorem ball_infDist_subset_compl : ball x (infDist x s) ⊆ sᶜ := (disjoint_ball_infDist (s := s)).subset_compl_right theorem ball_infDist_compl_subset : ball x (infDist x sᶜ) ⊆ s := ball_infDist_subset_compl.trans_eq (compl_compl s) theorem disjoint_closedBall_of_lt_infDist {r : ℝ} (h : r < infDist x s) : Disjoint (closedBall x r) s := disjoint_ball_infDist.mono_left <| closedBall_subset_ball h theorem dist_le_infDist_add_diam (hs : IsBounded s) (hy : y ∈ s) : dist x y ≤ infDist x s + diam s := by rw [infDist, diam, dist_edist] exact toReal_le_add (edist_le_infEdist_add_ediam hy) (infEdist_ne_top ⟨y, hy⟩) hs.ediam_ne_top variable (s) /-- The minimal distance to a set is Lipschitz in point with constant 1 -/ theorem lipschitz_infDist_pt : LipschitzWith 1 (infDist · s) := LipschitzWith.of_le_add fun _ _ => infDist_le_infDist_add_dist /-- The minimal distance to a set is uniformly continuous in point -/ theorem uniformContinuous_infDist_pt : UniformContinuous (infDist · s) := (lipschitz_infDist_pt s).uniformContinuous /-- The minimal distance to a set is continuous in point -/ @[continuity] theorem continuous_infDist_pt : Continuous (infDist · s) := (uniformContinuous_infDist_pt s).continuous variable {s} /-- The minimal distances to a set and its closure coincide. -/ theorem infDist_closure : infDist x (closure s) = infDist x s := by simp [infDist, infEdist_closure] /-- If a point belongs to the closure of `s`, then its infimum distance to `s` equals zero. The converse is true provided that `s` is nonempty, see `Metric.mem_closure_iff_infDist_zero`. -/ theorem infDist_zero_of_mem_closure (hx : x ∈ closure s) : infDist x s = 0 := by rw [← infDist_closure] exact infDist_zero_of_mem hx /-- A point belongs to the closure of `s` iff its infimum distance to this set vanishes. -/ theorem mem_closure_iff_infDist_zero (h : s.Nonempty) : x ∈ closure s ↔ infDist x s = 0 := by simp [mem_closure_iff_infEdist_zero, infDist, ENNReal.toReal_eq_zero_iff, infEdist_ne_top h] theorem infDist_pos_iff_not_mem_closure (hs : s.Nonempty) : x ∉ closure s ↔ 0 < infDist x s := (mem_closure_iff_infDist_zero hs).not.trans infDist_nonneg.gt_iff_ne.symm /-- Given a closed set `s`, a point belongs to `s` iff its infimum distance to this set vanishes -/ theorem _root_.IsClosed.mem_iff_infDist_zero (h : IsClosed s) (hs : s.Nonempty) : x ∈ s ↔ infDist x s = 0 := by rw [← mem_closure_iff_infDist_zero hs, h.closure_eq] /-- Given a closed set `s`, a point belongs to `s` iff its infimum distance to this set vanishes. -/ theorem _root_.IsClosed.not_mem_iff_infDist_pos (h : IsClosed s) (hs : s.Nonempty) : x ∉ s ↔ 0 < infDist x s := by simp [h.mem_iff_infDist_zero hs, infDist_nonneg.gt_iff_ne] theorem continuousAt_inv_infDist_pt (h : x ∉ closure s) : ContinuousAt (fun x ↦ (infDist x s)⁻¹) x := by rcases s.eq_empty_or_nonempty with (rfl | hs) · simp only [infDist_empty, continuousAt_const] · refine (continuous_infDist_pt s).continuousAt.inv₀ ?_ rwa [Ne, ← mem_closure_iff_infDist_zero hs] /-- The infimum distance is invariant under isometries. -/ theorem infDist_image (hΦ : Isometry Φ) : infDist (Φ x) (Φ '' t) = infDist x t := by simp [infDist, infEdist_image hΦ] theorem infDist_inter_closedBall_of_mem (h : y ∈ s) : infDist x (s ∩ closedBall x (dist y x)) = infDist x s := by replace h : y ∈ s ∩ closedBall x (dist y x) := ⟨h, mem_closedBall.2 le_rfl⟩ refine le_antisymm ?_ (infDist_le_infDist_of_subset inter_subset_left ⟨y, h⟩) refine not_lt.1 fun hlt => ?_ rcases (infDist_lt_iff ⟨y, h.1⟩).mp hlt with ⟨z, hzs, hz⟩ rcases le_or_lt (dist z x) (dist y x) with hle | hlt · exact hz.not_le (infDist_le_dist_of_mem ⟨hzs, hle⟩) · rw [dist_comm z, dist_comm y] at hlt exact (hlt.trans hz).not_le (infDist_le_dist_of_mem h) theorem _root_.IsCompact.exists_infDist_eq_dist (h : IsCompact s) (hne : s.Nonempty) (x : α) : ∃ y ∈ s, infDist x s = dist x y := let ⟨y, hys, hy⟩ := h.exists_infEdist_eq_edist hne x ⟨y, hys, by rw [infDist, dist_edist, hy]⟩ theorem _root_.IsClosed.exists_infDist_eq_dist [ProperSpace α] (h : IsClosed s) (hne : s.Nonempty) (x : α) : ∃ y ∈ s, infDist x s = dist x y := by rcases hne with ⟨z, hz⟩ rw [← infDist_inter_closedBall_of_mem hz] set t := s ∩ closedBall x (dist z x) have htc : IsCompact t := (isCompact_closedBall x (dist z x)).inter_left h have htne : t.Nonempty := ⟨z, hz, mem_closedBall.2 le_rfl⟩ obtain ⟨y, ⟨hys, -⟩, hyd⟩ : ∃ y ∈ t, infDist x t = dist x y := htc.exists_infDist_eq_dist htne x exact ⟨y, hys, hyd⟩ theorem exists_mem_closure_infDist_eq_dist [ProperSpace α] (hne : s.Nonempty) (x : α) : ∃ y ∈ closure s, infDist x s = dist x y := by simpa only [infDist_closure] using isClosed_closure.exists_infDist_eq_dist hne.closure x /-! ### Distance of a point to a set as a function into `ℝ≥0`. -/ /-- The minimal distance of a point to a set as a `ℝ≥0` -/ def infNndist (x : α) (s : Set α) : ℝ≥0 := ENNReal.toNNReal (infEdist x s) @[simp] theorem coe_infNndist : (infNndist x s : ℝ) = infDist x s := rfl /-- The minimal distance to a set (as `ℝ≥0`) is Lipschitz in point with constant 1 -/ theorem lipschitz_infNndist_pt (s : Set α) : LipschitzWith 1 fun x => infNndist x s := LipschitzWith.of_le_add fun _ _ => infDist_le_infDist_add_dist /-- The minimal distance to a set (as `ℝ≥0`) is uniformly continuous in point -/ theorem uniformContinuous_infNndist_pt (s : Set α) : UniformContinuous fun x => infNndist x s := (lipschitz_infNndist_pt s).uniformContinuous /-- The minimal distance to a set (as `ℝ≥0`) is continuous in point -/ theorem continuous_infNndist_pt (s : Set α) : Continuous fun x => infNndist x s := (uniformContinuous_infNndist_pt s).continuous /-! ### The Hausdorff distance as a function into `ℝ`. -/ /-- The Hausdorff distance between two sets is the smallest nonnegative `r` such that each set is included in the `r`-neighborhood of the other. If there is no such `r`, it is defined to be `0`, arbitrarily. -/ def hausdorffDist (s t : Set α) : ℝ := ENNReal.toReal (hausdorffEdist s t) /-- The Hausdorff distance is nonnegative. -/ theorem hausdorffDist_nonneg : 0 ≤ hausdorffDist s t := by simp [hausdorffDist] /-- If two sets are nonempty and bounded in a metric space, they are at finite Hausdorff edistance. -/ theorem hausdorffEdist_ne_top_of_nonempty_of_bounded (hs : s.Nonempty) (ht : t.Nonempty) (bs : IsBounded s) (bt : IsBounded t) : hausdorffEdist s t ≠ ⊤ := by rcases hs with ⟨cs, hcs⟩ rcases ht with ⟨ct, hct⟩ rcases bs.subset_closedBall ct with ⟨rs, hrs⟩ rcases bt.subset_closedBall cs with ⟨rt, hrt⟩ have : hausdorffEdist s t ≤ ENNReal.ofReal (max rs rt) := by apply hausdorffEdist_le_of_mem_edist · intro x xs exists ct, hct have : dist x ct ≤ max rs rt := le_trans (hrs xs) (le_max_left _ _) rwa [edist_dist, ENNReal.ofReal_le_ofReal_iff] exact le_trans dist_nonneg this · intro x xt exists cs, hcs have : dist x cs ≤ max rs rt := le_trans (hrt xt) (le_max_right _ _) rwa [edist_dist, ENNReal.ofReal_le_ofReal_iff] exact le_trans dist_nonneg this exact ne_top_of_le_ne_top ENNReal.ofReal_ne_top this /-- The Hausdorff distance between a set and itself is zero. -/ @[simp] theorem hausdorffDist_self_zero : hausdorffDist s s = 0 := by simp [hausdorffDist] /-- The Hausdorff distances from `s` to `t` and from `t` to `s` coincide. -/ theorem hausdorffDist_comm : hausdorffDist s t = hausdorffDist t s := by simp [hausdorffDist, hausdorffEdist_comm] /-- The Hausdorff distance to the empty set vanishes (if you want to have the more reasonable value `∞` instead, use `EMetric.hausdorffEdist`, which takes values in `ℝ≥0∞`). -/ @[simp] theorem hausdorffDist_empty : hausdorffDist s ∅ = 0 := by rcases s.eq_empty_or_nonempty with h | h · simp [h] · simp [hausdorffDist, hausdorffEdist_empty h] /-- The Hausdorff distance to the empty set vanishes (if you want to have the more reasonable value `∞` instead, use `EMetric.hausdorffEdist`, which takes values in `ℝ≥0∞`). -/ @[simp] theorem hausdorffDist_empty' : hausdorffDist ∅ s = 0 := by simp [hausdorffDist_comm] /-- Bounding the Hausdorff distance by bounding the distance of any point in each set to the other set -/ theorem hausdorffDist_le_of_infDist {r : ℝ} (hr : 0 ≤ r) (H1 : ∀ x ∈ s, infDist x t ≤ r) (H2 : ∀ x ∈ t, infDist x s ≤ r) : hausdorffDist s t ≤ r := by rcases s.eq_empty_or_nonempty with hs | hs · rwa [hs, hausdorffDist_empty'] rcases t.eq_empty_or_nonempty with ht | ht · rwa [ht, hausdorffDist_empty] have : hausdorffEdist s t ≤ ENNReal.ofReal r := by apply hausdorffEdist_le_of_infEdist _ _ · simpa only [infDist, ← ENNReal.le_ofReal_iff_toReal_le (infEdist_ne_top ht) hr] using H1 · simpa only [infDist, ← ENNReal.le_ofReal_iff_toReal_le (infEdist_ne_top hs) hr] using H2 exact ENNReal.toReal_le_of_le_ofReal hr this /-- Bounding the Hausdorff distance by exhibiting, for any point in each set, another point in the other set at controlled distance -/ theorem hausdorffDist_le_of_mem_dist {r : ℝ} (hr : 0 ≤ r) (H1 : ∀ x ∈ s, ∃ y ∈ t, dist x y ≤ r) (H2 : ∀ x ∈ t, ∃ y ∈ s, dist x y ≤ r) : hausdorffDist s t ≤ r := by apply hausdorffDist_le_of_infDist hr · intro x xs rcases H1 x xs with ⟨y, yt, hy⟩ exact le_trans (infDist_le_dist_of_mem yt) hy · intro x xt rcases H2 x xt with ⟨y, ys, hy⟩ exact le_trans (infDist_le_dist_of_mem ys) hy /-- The Hausdorff distance is controlled by the diameter of the union. -/ theorem hausdorffDist_le_diam (hs : s.Nonempty) (bs : IsBounded s) (ht : t.Nonempty) (bt : IsBounded t) : hausdorffDist s t ≤ diam (s ∪ t) := by rcases hs with ⟨x, xs⟩ rcases ht with ⟨y, yt⟩ refine hausdorffDist_le_of_mem_dist diam_nonneg ?_ ?_ · exact fun z hz => ⟨y, yt, dist_le_diam_of_mem (bs.union bt) (subset_union_left hz) (subset_union_right yt)⟩ · exact fun z hz => ⟨x, xs, dist_le_diam_of_mem (bs.union bt) (subset_union_right hz) (subset_union_left xs)⟩ /-- The distance to a set is controlled by the Hausdorff distance. -/ theorem infDist_le_hausdorffDist_of_mem (hx : x ∈ s) (fin : hausdorffEdist s t ≠ ⊤) : infDist x t ≤ hausdorffDist s t := toReal_mono fin (infEdist_le_hausdorffEdist_of_mem hx) /-- If the Hausdorff distance is `< r`, any point in one of the sets is at distance `< r` of a point in the other set. -/ theorem exists_dist_lt_of_hausdorffDist_lt {r : ℝ} (h : x ∈ s) (H : hausdorffDist s t < r) (fin : hausdorffEdist s t ≠ ⊤) : ∃ y ∈ t, dist x y < r := by have r0 : 0 < r := lt_of_le_of_lt hausdorffDist_nonneg H have : hausdorffEdist s t < ENNReal.ofReal r := by rwa [hausdorffDist, ← ENNReal.toReal_ofReal (le_of_lt r0), ENNReal.toReal_lt_toReal fin ENNReal.ofReal_ne_top] at H rcases exists_edist_lt_of_hausdorffEdist_lt h this with ⟨y, hy, yr⟩ rw [edist_dist, ENNReal.ofReal_lt_ofReal_iff r0] at yr exact ⟨y, hy, yr⟩ /-- If the Hausdorff distance is `< r`, any point in one of the sets is at distance `< r` of a point in the other set. -/ theorem exists_dist_lt_of_hausdorffDist_lt' {r : ℝ} (h : y ∈ t) (H : hausdorffDist s t < r) (fin : hausdorffEdist s t ≠ ⊤) : ∃ x ∈ s, dist x y < r := by rw [hausdorffDist_comm] at H rw [hausdorffEdist_comm] at fin simpa [dist_comm] using exists_dist_lt_of_hausdorffDist_lt h H fin /-- The infimum distance to `s` and `t` are the same, up to the Hausdorff distance between `s` and `t` -/ theorem infDist_le_infDist_add_hausdorffDist (fin : hausdorffEdist s t ≠ ⊤) : infDist x t ≤ infDist x s + hausdorffDist s t := by refine toReal_le_add' infEdist_le_infEdist_add_hausdorffEdist (fun h ↦ ?_) (flip absurd fin) rw [infEdist_eq_top_iff, ← not_nonempty_iff_eq_empty] at h ⊢ rw [hausdorffEdist_comm] at fin exact mt (nonempty_of_hausdorffEdist_ne_top · fin) h /-- The Hausdorff distance is invariant under isometries. -/ theorem hausdorffDist_image (h : Isometry Φ) : hausdorffDist (Φ '' s) (Φ '' t) = hausdorffDist s t := by simp [hausdorffDist, hausdorffEdist_image h] /-- The Hausdorff distance satisfies the triangle inequality. -/ theorem hausdorffDist_triangle (fin : hausdorffEdist s t ≠ ⊤) : hausdorffDist s u ≤ hausdorffDist s t + hausdorffDist t u := by refine toReal_le_add' hausdorffEdist_triangle (flip absurd fin) (not_imp_not.1 fun h ↦ ?_) rw [hausdorffEdist_comm] at fin exact ne_top_of_le_ne_top (add_ne_top.2 ⟨fin, h⟩) hausdorffEdist_triangle /-- The Hausdorff distance satisfies the triangle inequality. -/ theorem hausdorffDist_triangle' (fin : hausdorffEdist t u ≠ ⊤) : hausdorffDist s u ≤ hausdorffDist s t + hausdorffDist t u := by rw [hausdorffEdist_comm] at fin have I : hausdorffDist u s ≤ hausdorffDist u t + hausdorffDist t s := hausdorffDist_triangle fin simpa [add_comm, hausdorffDist_comm] using I /-- The Hausdorff distance between a set and its closure vanishes. -/ @[simp] theorem hausdorffDist_self_closure : hausdorffDist s (closure s) = 0 := by simp [hausdorffDist] /-- Replacing a set by its closure does not change the Hausdorff distance. -/ @[simp] theorem hausdorffDist_closure₁ : hausdorffDist (closure s) t = hausdorffDist s t := by simp [hausdorffDist] /-- Replacing a set by its closure does not change the Hausdorff distance. -/ @[simp] theorem hausdorffDist_closure₂ : hausdorffDist s (closure t) = hausdorffDist s t := by simp [hausdorffDist] /-- The Hausdorff distances between two sets and their closures coincide. -/ theorem hausdorffDist_closure : hausdorffDist (closure s) (closure t) = hausdorffDist s t := by simp [hausdorffDist] /-- Two sets are at zero Hausdorff distance if and only if they have the same closures. -/ theorem hausdorffDist_zero_iff_closure_eq_closure (fin : hausdorffEdist s t ≠ ⊤) : hausdorffDist s t = 0 ↔ closure s = closure t := by simp [← hausdorffEdist_zero_iff_closure_eq_closure, hausdorffDist, ENNReal.toReal_eq_zero_iff, fin] /-- Two closed sets are at zero Hausdorff distance if and only if they coincide. -/ theorem _root_.IsClosed.hausdorffDist_zero_iff_eq (hs : IsClosed s) (ht : IsClosed t) (fin : hausdorffEdist s t ≠ ⊤) : hausdorffDist s t = 0 ↔ s = t := by simp [← hausdorffEdist_zero_iff_eq_of_closed hs ht, hausdorffDist, ENNReal.toReal_eq_zero_iff, fin] end end Metric
Mathlib/Topology/MetricSpace/HausdorffDistance.lean
815
823
/- Copyright (c) 2023 Xavier Roblot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Xavier Roblot -/ import Mathlib.Data.Complex.FiniteDimensional import Mathlib.MeasureTheory.Constructions.HaarToSphere import Mathlib.MeasureTheory.Integral.Gamma import Mathlib.MeasureTheory.Integral.Pi import Mathlib.Analysis.SpecialFunctions.Gaussian.GaussianIntegral /-! # Volume of balls Let `E` be a finite dimensional normed `ℝ`-vector space equipped with a Haar measure `μ`. We prove that `μ (Metric.ball 0 1) = (∫ (x : E), Real.exp (- ‖x‖ ^ p) ∂μ) / Real.Gamma (finrank ℝ E / p + 1)` for any real number `p` with `0 < p`, see `MeasureTheorymeasure_unitBall_eq_integral_div_gamma`. We also prove the corresponding result to compute `μ {x : E | g x < 1}` where `g : E → ℝ` is a function defining a norm on `E`, see `MeasureTheory.measure_lt_one_eq_integral_div_gamma`. Using these formulas, we compute the volume of the unit balls in several cases. * `MeasureTheory.volume_sum_rpow_lt` / `MeasureTheory.volume_sum_rpow_le`: volume of the open and closed balls for the norm `Lp` over a real finite dimensional vector space with `1 ≤ p`. These are computed as `volume {x : ι → ℝ | (∑ i, |x i| ^ p) ^ (1 / p) < r}` and `volume {x : ι → ℝ | (∑ i, |x i| ^ p) ^ (1 / p) ≤ r}` since the spaces `PiLp` do not have a `MeasureSpace` instance. * `Complex.volume_sum_rpow_lt_one` / `Complex.volume_sum_rpow_lt`: same as above but for complex finite dimensional vector space. * `EuclideanSpace.volume_ball` / `EuclideanSpace.volume_closedBall` : volume of open and closed balls in a finite dimensional Euclidean space. * `InnerProductSpace.volume_ball` / `InnerProductSpace.volume_closedBall`: volume of open and closed balls in a finite dimensional real inner product space. * `Complex.volume_ball` / `Complex.volume_closedBall`: volume of open and closed balls in `ℂ`. -/ section general_case open MeasureTheory MeasureTheory.Measure Module ENNReal theorem MeasureTheory.measure_unitBall_eq_integral_div_gamma {E : Type*} {p : ℝ} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] (μ : Measure E) [IsAddHaarMeasure μ] (hp : 0 < p) : μ (Metric.ball 0 1) = .ofReal ((∫ (x : E), Real.exp (- ‖x‖ ^ p) ∂μ) / Real.Gamma (finrank ℝ E / p + 1)) := by obtain hE | hE := subsingleton_or_nontrivial E · rw [(Metric.nonempty_ball.mpr zero_lt_one).eq_zero, ← setIntegral_univ, Set.univ_nonempty.eq_zero, integral_singleton, finrank_zero_of_subsingleton, Nat.cast_zero, zero_div, zero_add, Real.Gamma_one, div_one, norm_zero, Real.zero_rpow hp.ne', neg_zero, Real.exp_zero, smul_eq_mul, mul_one, measureReal_def, ofReal_toReal (measure_ne_top μ {0})] · have : (0 : ℝ) < finrank ℝ E := Nat.cast_pos.mpr finrank_pos have : ((∫ y in Set.Ioi (0 : ℝ), y ^ (finrank ℝ E - 1) • Real.exp (-y ^ p)) / Real.Gamma ((finrank ℝ E) / p + 1)) * (finrank ℝ E) = 1 := by simp_rw [← Real.rpow_natCast _ (finrank ℝ E - 1), smul_eq_mul, Nat.cast_sub finrank_pos, Nat.cast_one] rw [integral_rpow_mul_exp_neg_rpow hp (by linarith), sub_add_cancel, Real.Gamma_add_one (ne_of_gt (by positivity))] field_simp; ring rw [integral_fun_norm_addHaar μ (fun x => Real.exp (- x ^ p)), nsmul_eq_mul, smul_eq_mul, mul_div_assoc, mul_div_assoc, mul_comm, mul_assoc, this, mul_one, ofReal_measureReal _] exact ne_of_lt measure_ball_lt_top variable {E : Type*} [AddCommGroup E] [Module ℝ E] [FiniteDimensional ℝ E] [mE : MeasurableSpace E] [tE : TopologicalSpace E] [IsTopologicalAddGroup E] [BorelSpace E] [T2Space E] [ContinuousSMul ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] {g : E → ℝ} (h1 : g 0 = 0) (h2 : ∀ x, g (-x) = g x) (h3 : ∀ x y, g (x + y) ≤ g x + g y) (h4 : ∀ {x}, g x = 0 → x = 0) (h5 : ∀ r x, g (r • x) ≤ |r| * (g x)) include h1 h2 h3 h4 h5 theorem MeasureTheory.measure_lt_one_eq_integral_div_gamma {p : ℝ} (hp : 0 < p) : μ {x : E | g x < 1} = .ofReal ((∫ (x : E), Real.exp (- (g x) ^ p) ∂μ) / Real.Gamma (finrank ℝ E / p + 1)) := by -- We copy `E` to a new type `F` on which we will put the norm defined by `g` letI F : Type _ := E letI : NormedAddCommGroup F := { norm := g dist := fun x y => g (x - y) dist_self := by simp only [_root_.sub_self, h1, forall_const] dist_comm := fun _ _ => by rw [← h2, neg_sub] dist_triangle := fun x y z => by convert h3 (x - y) (y - z) using 1; simp [F] edist := fun x y => .ofReal (g (x - y)) edist_dist := fun _ _ => rfl eq_of_dist_eq_zero := by convert fun _ _ h => eq_of_sub_eq_zero (h4 h) } letI : NormedSpace ℝ F := { norm_smul_le := fun _ _ ↦ h5 _ _ } -- We put the new topology on F letI : TopologicalSpace F := UniformSpace.toTopologicalSpace letI : MeasurableSpace F := borel F have : BorelSpace F := { measurable_eq := rfl } -- The map between `E` and `F` as a continuous linear equivalence let φ := @LinearEquiv.toContinuousLinearEquiv ℝ _ E _ _ tE _ _ F _ _ _ _ _ _ _ _ _ (LinearEquiv.refl ℝ E : E ≃ₗ[ℝ] F) -- The measure `ν` is the measure on `F` defined by `μ` -- Since we have two different topologies, it is necessary to specify the topology of E let ν : Measure F := @Measure.map E F mE _ φ μ have : IsAddHaarMeasure ν := @ContinuousLinearEquiv.isAddHaarMeasure_map E F ℝ ℝ _ _ _ _ _ _ tE _ _ _ _ _ _ _ mE _ _ _ φ μ _ convert (measure_unitBall_eq_integral_div_gamma ν hp) using 1 · rw [@Measure.map_apply E F mE _ μ φ _ _ measurableSet_ball] · congr! simp_rw [Metric.ball, dist_zero_right] rfl · refine @Continuous.measurable E F tE mE _ _ _ _ φ ?_ exact @ContinuousLinearEquiv.continuous ℝ ℝ _ _ _ _ _ _ E tE _ F _ _ _ _ φ · -- The map between `E` and `F` as a measurable equivalence let ψ := @Homeomorph.toMeasurableEquiv E F tE mE _ _ _ _ (@ContinuousLinearEquiv.toHomeomorph ℝ ℝ _ _ _ _ _ _ E tE _ F _ _ _ _ φ) -- The map `ψ` is measure preserving by construction have : @MeasurePreserving E F mE _ ψ μ ν := @Measurable.measurePreserving E F mE _ ψ (@MeasurableEquiv.measurable E F mE _ ψ) _ rw [← this.integral_comp'] rfl theorem MeasureTheory.measure_le_eq_lt [Nontrivial E] (r : ℝ) : μ {x : E | g x ≤ r} = μ {x : E | g x < r} := by -- We copy `E` to a new type `F` on which we will put the norm defined by `g` letI F : Type _ := E letI : NormedAddCommGroup F := { norm := g dist := fun x y => g (x - y) dist_self := by simp only [_root_.sub_self, h1, forall_const] dist_comm := fun _ _ => by rw [← h2, neg_sub] dist_triangle := fun x y z => by convert h3 (x - y) (y - z) using 1; simp [F] edist := fun x y => .ofReal (g (x - y)) edist_dist := fun _ _ => rfl eq_of_dist_eq_zero := by convert fun _ _ h => eq_of_sub_eq_zero (h4 h) } letI : NormedSpace ℝ F := { norm_smul_le := fun _ _ ↦ h5 _ _ } -- We put the new topology on F letI : TopologicalSpace F := UniformSpace.toTopologicalSpace letI : MeasurableSpace F := borel F have : BorelSpace F := { measurable_eq := rfl } -- The map between `E` and `F` as a continuous linear equivalence let φ := @LinearEquiv.toContinuousLinearEquiv ℝ _ E _ _ tE _ _ F _ _ _ _ _ _ _ _ _ (LinearEquiv.refl ℝ E : E ≃ₗ[ℝ] F) -- The measure `ν` is the measure on `F` defined by `μ` -- Since we have two different topologies, it is necessary to specify the topology of E let ν : Measure F := @Measure.map E F mE _ φ μ have : IsAddHaarMeasure ν := @ContinuousLinearEquiv.isAddHaarMeasure_map E F ℝ ℝ _ _ _ _ _ _ tE _ _ _ _ _ _ _ mE _ _ _ φ μ _ convert addHaar_closedBall_eq_addHaar_ball ν 0 r using 1 · rw [@Measure.map_apply E F mE _ μ φ _ _ measurableSet_closedBall] · congr! simp_rw [Metric.closedBall, dist_zero_right] rfl · refine @Continuous.measurable E F tE mE _ _ _ _ φ ?_ exact @ContinuousLinearEquiv.continuous ℝ ℝ _ _ _ _ _ _ E tE _ F _ _ _ _ φ · rw [@Measure.map_apply E F mE _ μ φ _ _ measurableSet_ball] · congr! simp_rw [Metric.ball, dist_zero_right] rfl · refine @Continuous.measurable E F tE mE _ _ _ _ φ ?_ exact @ContinuousLinearEquiv.continuous ℝ ℝ _ _ _ _ _ _ E tE _ F _ _ _ _ φ end general_case section LpSpace open Real Fintype ENNReal Module MeasureTheory MeasureTheory.Measure variable (ι : Type*) [Fintype ι] {p : ℝ} theorem MeasureTheory.volume_sum_rpow_lt_one (hp : 1 ≤ p) : volume {x : ι → ℝ | ∑ i, |x i| ^ p < 1} = .ofReal ((2 * Gamma (1 / p + 1)) ^ card ι / Gamma (card ι / p + 1)) := by have h₁ : 0 < p := by linarith have h₂ : ∀ x : ι → ℝ, 0 ≤ ∑ i, |x i| ^ p := by refine fun _ => Finset.sum_nonneg' ?_ exact fun i => (fun _ => rpow_nonneg (abs_nonneg _) _) _ -- We collect facts about `Lp` norms that will be used in `measure_lt_one_eq_integral_div_gamma` have eq_norm := fun x : ι → ℝ => (PiLp.norm_eq_sum (p := .ofReal p) (f := x) ((toReal_ofReal (le_of_lt h₁)).symm ▸ h₁)) simp_rw [toReal_ofReal (le_of_lt h₁), Real.norm_eq_abs] at eq_norm have : Fact (1 ≤ ENNReal.ofReal p) := fact_iff.mpr (ofReal_one ▸ (ofReal_le_ofReal hp)) have nm_zero := norm_zero (E := PiLp (.ofReal p) (fun _ : ι => ℝ)) have eq_zero := fun x : ι → ℝ => norm_eq_zero (E := PiLp (.ofReal p) (fun _ : ι => ℝ)) (a := x) have nm_neg := fun x : ι → ℝ => norm_neg (E := PiLp (.ofReal p) (fun _ : ι => ℝ)) x have nm_add := fun x y : ι → ℝ => norm_add_le (E := PiLp (.ofReal p) (fun _ : ι => ℝ)) x y simp_rw [eq_norm] at eq_zero nm_zero nm_neg nm_add have nm_smul := fun (r : ℝ) (x : ι → ℝ) => norm_smul_le (β := PiLp (.ofReal p) (fun _ : ι => ℝ)) r x simp_rw [eq_norm, norm_eq_abs] at nm_smul -- We use `measure_lt_one_eq_integral_div_gamma` with `g` equals to the norm `L_p` convert (measure_lt_one_eq_integral_div_gamma (volume : Measure (ι → ℝ)) (g := fun x => (∑ i, |x i| ^ p) ^ (1 / p)) nm_zero nm_neg nm_add (eq_zero _).mp (fun r x => nm_smul r x) (by linarith : 0 < p)) using 4 · rw [rpow_lt_one_iff' _ (one_div_pos.mpr h₁)] exact Finset.sum_nonneg' (fun _ => rpow_nonneg (abs_nonneg _) _) · simp_rw [← rpow_mul (h₂ _), div_mul_cancel₀ _ (ne_of_gt h₁), Real.rpow_one, ← Finset.sum_neg_distrib, exp_sum] rw [integral_fintype_prod_eq_pow ι fun x : ℝ => exp (- |x| ^ p), integral_comp_abs (f := fun x => exp (- x ^ p)), integral_exp_neg_rpow h₁]
· rw [finrank_fintype_fun_eq_card] theorem MeasureTheory.volume_sum_rpow_lt [Nonempty ι] {p : ℝ} (hp : 1 ≤ p) (r : ℝ) : volume {x : ι → ℝ | (∑ i, |x i| ^ p) ^ (1 / p) < r} = (.ofReal r) ^ card ι * .ofReal ((2 * Gamma (1 / p + 1)) ^ card ι / Gamma (card ι / p + 1)) := by have h₁ (x : ι → ℝ) : 0 ≤ ∑ i, |x i| ^ p := by positivity have h₂ : ∀ x : ι → ℝ, 0 ≤ (∑ i, |x i| ^ p) ^ (1 / p) := fun x => rpow_nonneg (h₁ x) _ obtain hr | hr := le_or_lt r 0 · have : {x : ι → ℝ | (∑ i, |x i| ^ p) ^ (1 / p) < r} = ∅ := by ext x refine ⟨fun hx => ?_, fun hx => hx.elim⟩ exact not_le.mpr (lt_of_lt_of_le (Set.mem_setOf.mp hx) hr) (h₂ x) rw [this, measure_empty, ← zero_eq_ofReal.mpr hr, zero_pow Fin.pos'.ne', zero_mul] · rw [← volume_sum_rpow_lt_one _ hp, ← ofReal_pow (le_of_lt hr), ← finrank_pi ℝ] convert addHaar_smul_of_nonneg volume (le_of_lt hr) {x : ι → ℝ | ∑ i, |x i| ^ p < 1} using 2 simp_rw [← Set.preimage_smul_inv₀ (ne_of_gt hr), Set.preimage_setOf_eq, Pi.smul_apply, smul_eq_mul, abs_mul, mul_rpow (abs_nonneg _) (abs_nonneg _), abs_inv, inv_rpow (abs_nonneg _), ← Finset.mul_sum, abs_eq_self.mpr (le_of_lt hr), inv_mul_lt_iff₀ (rpow_pos_of_pos hr _), mul_one, ← rpow_lt_rpow_iff (rpow_nonneg (h₁ _) _) (le_of_lt hr) (by linarith : 0 < p), ← rpow_mul (h₁ _), div_mul_cancel₀ _ (ne_of_gt (by linarith) : p ≠ 0), Real.rpow_one]
Mathlib/MeasureTheory/Measure/Lebesgue/VolumeOfBalls.lean
198
218
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.FieldTheory.RatFunc.Defs import Mathlib.RingTheory.EuclideanDomain import Mathlib.RingTheory.Localization.FractionRing import Mathlib.RingTheory.Polynomial.Content /-! # The field structure of rational functions ## Main definitions Working with rational functions as polynomials: - `RatFunc.instField` provides a field structure You can use `IsFractionRing` API to treat `RatFunc` as the field of fractions of polynomials: * `algebraMap K[X] (RatFunc K)` maps polynomials to rational functions * `IsFractionRing.algEquiv` maps other fields of fractions of `K[X]` to `RatFunc K`, in particular: * `FractionRing.algEquiv K[X] (RatFunc K)` maps the generic field of fraction construction to `RatFunc K`. Combine this with `AlgEquiv.restrictScalars` to change the `FractionRing K[X] ≃ₐ[K[X]] RatFunc K` to `FractionRing K[X] ≃ₐ[K] RatFunc K`. Working with rational functions as fractions: - `RatFunc.num` and `RatFunc.denom` give the numerator and denominator. These values are chosen to be coprime and such that `RatFunc.denom` is monic. Lifting homomorphisms of polynomials to other types, by mapping and dividing, as long as the homomorphism retains the non-zero-divisor property: - `RatFunc.liftMonoidWithZeroHom` lifts a `K[X] →*₀ G₀` to a `RatFunc K →*₀ G₀`, where `[CommRing K] [CommGroupWithZero G₀]` - `RatFunc.liftRingHom` lifts a `K[X] →+* L` to a `RatFunc K →+* L`, where `[CommRing K] [Field L]` - `RatFunc.liftAlgHom` lifts a `K[X] →ₐ[S] L` to a `RatFunc K →ₐ[S] L`, where `[CommRing K] [Field L] [CommSemiring S] [Algebra S K[X]] [Algebra S L]` This is satisfied by injective homs. We also have lifting homomorphisms of polynomials to other polynomials, with the same condition on retaining the non-zero-divisor property across the map: - `RatFunc.map` lifts `K[X] →* R[X]` when `[CommRing K] [CommRing R]` - `RatFunc.mapRingHom` lifts `K[X] →+* R[X]` when `[CommRing K] [CommRing R]` - `RatFunc.mapAlgHom` lifts `K[X] →ₐ[S] R[X]` when `[CommRing K] [IsDomain K] [CommRing R] [IsDomain R]` -/ universe u v noncomputable section open scoped nonZeroDivisors Polynomial variable {K : Type u} namespace RatFunc section Field variable [CommRing K] /-- The zero rational function. -/ protected irreducible_def zero : RatFunc K := ⟨0⟩ instance : Zero (RatFunc K) := ⟨RatFunc.zero⟩ theorem ofFractionRing_zero : (ofFractionRing 0 : RatFunc K) = 0 := zero_def.symm /-- Addition of rational functions. -/ protected irreducible_def add : RatFunc K → RatFunc K → RatFunc K | ⟨p⟩, ⟨q⟩ => ⟨p + q⟩ instance : Add (RatFunc K) := ⟨RatFunc.add⟩ theorem ofFractionRing_add (p q : FractionRing K[X]) : ofFractionRing (p + q) = ofFractionRing p + ofFractionRing q := (add_def _ _).symm /-- Subtraction of rational functions. -/ protected irreducible_def sub : RatFunc K → RatFunc K → RatFunc K | ⟨p⟩, ⟨q⟩ => ⟨p - q⟩ instance : Sub (RatFunc K) := ⟨RatFunc.sub⟩ theorem ofFractionRing_sub (p q : FractionRing K[X]) : ofFractionRing (p - q) = ofFractionRing p - ofFractionRing q := (sub_def _ _).symm /-- Additive inverse of a rational function. -/ protected irreducible_def neg : RatFunc K → RatFunc K | ⟨p⟩ => ⟨-p⟩ instance : Neg (RatFunc K) := ⟨RatFunc.neg⟩ theorem ofFractionRing_neg (p : FractionRing K[X]) : ofFractionRing (-p) = -ofFractionRing p := (neg_def _).symm /-- The multiplicative unit of rational functions. -/ protected irreducible_def one : RatFunc K := ⟨1⟩ instance : One (RatFunc K) := ⟨RatFunc.one⟩ theorem ofFractionRing_one : (ofFractionRing 1 : RatFunc K) = 1 := one_def.symm /-- Multiplication of rational functions. -/ protected irreducible_def mul : RatFunc K → RatFunc K → RatFunc K | ⟨p⟩, ⟨q⟩ => ⟨p * q⟩ instance : Mul (RatFunc K) := ⟨RatFunc.mul⟩ theorem ofFractionRing_mul (p q : FractionRing K[X]) : ofFractionRing (p * q) = ofFractionRing p * ofFractionRing q := (mul_def _ _).symm section IsDomain variable [IsDomain K] /-- Division of rational functions. -/ protected irreducible_def div : RatFunc K → RatFunc K → RatFunc K | ⟨p⟩, ⟨q⟩ => ⟨p / q⟩ instance : Div (RatFunc K) := ⟨RatFunc.div⟩ theorem ofFractionRing_div (p q : FractionRing K[X]) : ofFractionRing (p / q) = ofFractionRing p / ofFractionRing q := (div_def _ _).symm /-- Multiplicative inverse of a rational function. -/ protected irreducible_def inv : RatFunc K → RatFunc K | ⟨p⟩ => ⟨p⁻¹⟩ instance : Inv (RatFunc K) := ⟨RatFunc.inv⟩ theorem ofFractionRing_inv (p : FractionRing K[X]) : ofFractionRing p⁻¹ = (ofFractionRing p)⁻¹ := (inv_def _).symm -- Auxiliary lemma for the `Field` instance theorem mul_inv_cancel : ∀ {p : RatFunc K}, p ≠ 0 → p * p⁻¹ = 1 | ⟨p⟩, h => by have : p ≠ 0 := fun hp => h <| by rw [hp, ofFractionRing_zero] simpa only [← ofFractionRing_inv, ← ofFractionRing_mul, ← ofFractionRing_one, ofFractionRing.injEq] using mul_inv_cancel₀ this end IsDomain section SMul variable {R : Type*} /-- Scalar multiplication of rational functions. -/ protected irreducible_def smul [SMul R (FractionRing K[X])] : R → RatFunc K → RatFunc K | r, ⟨p⟩ => ⟨r • p⟩ instance [SMul R (FractionRing K[X])] : SMul R (RatFunc K) := ⟨RatFunc.smul⟩ theorem ofFractionRing_smul [SMul R (FractionRing K[X])] (c : R) (p : FractionRing K[X]) : ofFractionRing (c • p) = c • ofFractionRing p := (smul_def _ _).symm theorem toFractionRing_smul [SMul R (FractionRing K[X])] (c : R) (p : RatFunc K) : toFractionRing (c • p) = c • toFractionRing p := by cases p rw [← ofFractionRing_smul] theorem smul_eq_C_smul (x : RatFunc K) (r : K) : r • x = Polynomial.C r • x := by obtain ⟨x⟩ := x induction x using Localization.induction_on rw [← ofFractionRing_smul, ← ofFractionRing_smul, Localization.smul_mk, Localization.smul_mk, smul_eq_mul, Polynomial.smul_eq_C_mul] section IsDomain variable [IsDomain K] variable [Monoid R] [DistribMulAction R K[X]] variable [IsScalarTower R K[X] K[X]] theorem mk_smul (c : R) (p q : K[X]) : RatFunc.mk (c • p) q = c • RatFunc.mk p q := by letI : SMulZeroClass R (FractionRing K[X]) := inferInstance by_cases hq : q = 0 · rw [hq, mk_zero, mk_zero, ← ofFractionRing_smul, smul_zero] · rw [mk_eq_localization_mk _ hq, mk_eq_localization_mk _ hq, ← Localization.smul_mk, ← ofFractionRing_smul] instance : IsScalarTower R K[X] (RatFunc K) := ⟨fun c p q => q.induction_on' fun q r _ => by rw [← mk_smul, smul_assoc, mk_smul, mk_smul]⟩ end IsDomain end SMul variable (K) instance [Subsingleton K] : Subsingleton (RatFunc K) := toFractionRing_injective.subsingleton instance : Inhabited (RatFunc K) := ⟨0⟩ instance instNontrivial [Nontrivial K] : Nontrivial (RatFunc K) := ofFractionRing_injective.nontrivial /-- `RatFunc K` is isomorphic to the field of fractions of `K[X]`, as rings. This is an auxiliary definition; `simp`-normal form is `IsLocalization.algEquiv`. -/ @[simps apply] def toFractionRingRingEquiv : RatFunc K ≃+* FractionRing K[X] where toFun := toFractionRing invFun := ofFractionRing left_inv := fun ⟨_⟩ => rfl right_inv _ := rfl map_add' := fun ⟨_⟩ ⟨_⟩ => by simp [← ofFractionRing_add] map_mul' := fun ⟨_⟩ ⟨_⟩ => by simp [← ofFractionRing_mul] end Field section TacticInterlude /-- Solve equations for `RatFunc K` by working in `FractionRing K[X]`. -/ macro "frac_tac" : tactic => `(tactic| · repeat (rintro (⟨⟩ : RatFunc _)) try simp only [← ofFractionRing_zero, ← ofFractionRing_add, ← ofFractionRing_sub, ← ofFractionRing_neg, ← ofFractionRing_one, ← ofFractionRing_mul, ← ofFractionRing_div, ← ofFractionRing_inv, add_assoc, zero_add, add_zero, mul_assoc, mul_zero, mul_one, mul_add, inv_zero, add_comm, add_left_comm, mul_comm, mul_left_comm, sub_eq_add_neg, div_eq_mul_inv, add_mul, zero_mul, one_mul, neg_mul, mul_neg, add_neg_cancel]) /-- Solve equations for `RatFunc K` by applying `RatFunc.induction_on`. -/ macro "smul_tac" : tactic => `(tactic| repeat (first | rintro (⟨⟩ : RatFunc _) | intro) <;> simp_rw [← ofFractionRing_smul] <;> simp only [add_comm, mul_comm, zero_smul, succ_nsmul, zsmul_eq_mul, mul_add, mul_one, mul_zero, neg_add, mul_neg, Int.cast_zero, Int.cast_add, Int.cast_one, Int.cast_negSucc, Int.cast_natCast, Nat.cast_succ, Localization.mk_zero, Localization.add_mk_self, Localization.neg_mk, ofFractionRing_zero, ← ofFractionRing_add, ← ofFractionRing_neg]) end TacticInterlude section CommRing variable (K) [CommRing K] /-- `RatFunc K` is a commutative monoid. This is an intermediate step on the way to the full instance `RatFunc.instCommRing`. -/ def instCommMonoid : CommMonoid (RatFunc K) where mul := (· * ·) mul_assoc := by frac_tac mul_comm := by frac_tac one := 1 one_mul := by frac_tac mul_one := by frac_tac npow := npowRec /-- `RatFunc K` is an additive commutative group. This is an intermediate step on the way to the full instance `RatFunc.instCommRing`. -/ def instAddCommGroup : AddCommGroup (RatFunc K) where add := (· + ·) add_assoc := by frac_tac add_comm := by frac_tac zero := 0 zero_add := by frac_tac add_zero := by frac_tac neg := Neg.neg neg_add_cancel := by frac_tac sub := Sub.sub sub_eq_add_neg := by frac_tac nsmul := (· • ·) nsmul_zero := by smul_tac nsmul_succ _ := by smul_tac zsmul := (· • ·) zsmul_zero' := by smul_tac zsmul_succ' _ := by smul_tac zsmul_neg' _ := by smul_tac instance instCommRing : CommRing (RatFunc K) := { instCommMonoid K, instAddCommGroup K with zero := 0 sub := Sub.sub zero_mul := by frac_tac mul_zero := by frac_tac left_distrib := by frac_tac right_distrib := by frac_tac one := 1 nsmul := (· • ·) zsmul := (· • ·) npow := npowRec } variable {K} section LiftHom open RatFunc variable {G₀ L R S F : Type*} [CommGroupWithZero G₀] [Field L] [CommRing R] [CommRing S] variable [FunLike F R[X] S[X]] open scoped Classical in /-- Lift a monoid homomorphism that maps polynomials `φ : R[X] →* S[X]` to a `RatFunc R →* RatFunc S`, on the condition that `φ` maps non zero divisors to non zero divisors, by mapping both the numerator and denominator and quotienting them. -/ def map [MonoidHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) : RatFunc R →* RatFunc S where toFun f := RatFunc.liftOn f (fun n d => if h : φ d ∈ S[X]⁰ then ofFractionRing (Localization.mk (φ n) ⟨φ d, h⟩) else 0) fun {p q p' q'} hq hq' h => by simp only [Submonoid.mem_comap.mp (hφ hq), Submonoid.mem_comap.mp (hφ hq'), dif_pos, ofFractionRing.injEq, Localization.mk_eq_mk_iff] refine Localization.r_of_eq ?_ simpa only [map_mul] using congr_arg φ h map_one' := by simp_rw [← ofFractionRing_one, ← Localization.mk_one, liftOn_ofFractionRing_mk, OneMemClass.coe_one, map_one, OneMemClass.one_mem, dite_true, ofFractionRing.injEq, Localization.mk_one, Localization.mk_eq_monoidOf_mk', Submonoid.LocalizationMap.mk'_self] map_mul' x y := by obtain ⟨x⟩ := x; obtain ⟨y⟩ := y induction' x using Localization.induction_on with pq induction' y using Localization.induction_on with p'q' obtain ⟨p, q⟩ := pq obtain ⟨p', q'⟩ := p'q' have hq : φ q ∈ S[X]⁰ := hφ q.prop have hq' : φ q' ∈ S[X]⁰ := hφ q'.prop have hqq' : φ ↑(q * q') ∈ S[X]⁰ := by simpa using Submonoid.mul_mem _ hq hq' simp_rw [← ofFractionRing_mul, Localization.mk_mul, liftOn_ofFractionRing_mk, dif_pos hq, dif_pos hq', dif_pos hqq', ← ofFractionRing_mul, Submonoid.coe_mul, map_mul, Localization.mk_mul, Submonoid.mk_mul_mk] theorem map_apply_ofFractionRing_mk [MonoidHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) (n : R[X]) (d : R[X]⁰) : map φ hφ (ofFractionRing (Localization.mk n d)) = ofFractionRing (Localization.mk (φ n) ⟨φ d, hφ d.prop⟩) := by simp only [map, MonoidHom.coe_mk, OneHom.coe_mk, liftOn_ofFractionRing_mk, Submonoid.mem_comap.mp (hφ d.2), ↓reduceDIte] theorem map_injective [MonoidHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) (hf : Function.Injective φ) : Function.Injective (map φ hφ) := by rintro ⟨x⟩ ⟨y⟩ h induction x using Localization.induction_on induction y using Localization.induction_on simpa only [map_apply_ofFractionRing_mk, ofFractionRing_injective.eq_iff, Localization.mk_eq_mk_iff, Localization.r_iff_exists, mul_cancel_left_coe_nonZeroDivisors, exists_const, ← map_mul, hf.eq_iff] using h /-- Lift a ring homomorphism that maps polynomials `φ : R[X] →+* S[X]` to a `RatFunc R →+* RatFunc S`, on the condition that `φ` maps non zero divisors to non zero divisors, by mapping both the numerator and denominator and quotienting them. -/ def mapRingHom [RingHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) : RatFunc R →+* RatFunc S := { map φ hφ with map_zero' := by simp_rw [MonoidHom.toFun_eq_coe, ← ofFractionRing_zero, ← Localization.mk_zero (1 : R[X]⁰), ← Localization.mk_zero (1 : S[X]⁰), map_apply_ofFractionRing_mk, map_zero, Localization.mk_eq_mk', IsLocalization.mk'_zero] map_add' := by rintro ⟨x⟩ ⟨y⟩ induction x using Localization.induction_on induction y using Localization.induction_on · simp only [← ofFractionRing_add, Localization.add_mk, map_add, map_mul, MonoidHom.toFun_eq_coe, map_apply_ofFractionRing_mk, Submonoid.coe_mul, -- We have to specify `S[X]⁰` to `mk_mul_mk`, otherwise it will try to rewrite -- the wrong occurrence. Submonoid.mk_mul_mk S[X]⁰] } theorem coe_mapRingHom_eq_coe_map [RingHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) : (mapRingHom φ hφ : RatFunc R → RatFunc S) = map φ hφ := rfl -- TODO: Generalize to `FunLike` classes, /-- Lift a monoid with zero homomorphism `R[X] →*₀ G₀` to a `RatFunc R →*₀ G₀` on the condition that `φ` maps non zero divisors to non zero divisors, by mapping both the numerator and denominator and quotienting them. -/ def liftMonoidWithZeroHom (φ : R[X] →*₀ G₀) (hφ : R[X]⁰ ≤ G₀⁰.comap φ) : RatFunc R →*₀ G₀ where toFun f := RatFunc.liftOn f (fun p q => φ p / φ q) fun {p q p' q'} hq hq' h => by cases subsingleton_or_nontrivial R · rw [Subsingleton.elim p q, Subsingleton.elim p' q, Subsingleton.elim q' q] rw [div_eq_div_iff, ← map_mul, mul_comm p, h, map_mul, mul_comm] <;> exact nonZeroDivisors.ne_zero (hφ ‹_›) map_one' := by simp_rw [← ofFractionRing_one, ← Localization.mk_one, liftOn_ofFractionRing_mk, OneMemClass.coe_one, map_one, div_one] map_mul' x y := by obtain ⟨x⟩ := x obtain ⟨y⟩ := y induction' x using Localization.induction_on with p q induction' y using Localization.induction_on with p' q' rw [← ofFractionRing_mul, Localization.mk_mul] simp only [liftOn_ofFractionRing_mk, div_mul_div_comm, map_mul, Submonoid.coe_mul] map_zero' := by simp_rw [← ofFractionRing_zero, ← Localization.mk_zero (1 : R[X]⁰), liftOn_ofFractionRing_mk, map_zero, zero_div] theorem liftMonoidWithZeroHom_apply_ofFractionRing_mk (φ : R[X] →*₀ G₀) (hφ : R[X]⁰ ≤ G₀⁰.comap φ) (n : R[X]) (d : R[X]⁰) : liftMonoidWithZeroHom φ hφ (ofFractionRing (Localization.mk n d)) = φ n / φ d := liftOn_ofFractionRing_mk _ _ _ _ theorem liftMonoidWithZeroHom_injective [Nontrivial R] (φ : R[X] →*₀ G₀) (hφ : Function.Injective φ) (hφ' : R[X]⁰ ≤ G₀⁰.comap φ := nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _ hφ) : Function.Injective (liftMonoidWithZeroHom φ hφ') := by rintro ⟨x⟩ ⟨y⟩ induction' x using Localization.induction_on with a induction' y using Localization.induction_on with a' simp_rw [liftMonoidWithZeroHom_apply_ofFractionRing_mk] intro h congr 1 refine Localization.mk_eq_mk_iff.mpr (Localization.r_of_eq (M := R[X]) ?_) have := mul_eq_mul_of_div_eq_div _ _ ?_ ?_ h · rwa [← map_mul, ← map_mul, hφ.eq_iff, mul_comm, mul_comm a'.fst] at this all_goals exact map_ne_zero_of_mem_nonZeroDivisors _ hφ (SetLike.coe_mem _) /-- Lift an injective ring homomorphism `R[X] →+* L` to a `RatFunc R →+* L` by mapping both the numerator and denominator and quotienting them. -/ def liftRingHom (φ : R[X] →+* L) (hφ : R[X]⁰ ≤ L⁰.comap φ) : RatFunc R →+* L := { liftMonoidWithZeroHom φ.toMonoidWithZeroHom hφ with map_add' := fun x y => by simp only [ZeroHom.toFun_eq_coe, MonoidWithZeroHom.toZeroHom_coe] cases subsingleton_or_nontrivial R · rw [Subsingleton.elim (x + y) y, Subsingleton.elim x 0, map_zero, zero_add] obtain ⟨x⟩ := x obtain ⟨y⟩ := y induction' x using Localization.induction_on with pq induction' y using Localization.induction_on with p'q' obtain ⟨p, q⟩ := pq obtain ⟨p', q'⟩ := p'q' rw [← ofFractionRing_add, Localization.add_mk] simp only [RingHom.toMonoidWithZeroHom_eq_coe, liftMonoidWithZeroHom_apply_ofFractionRing_mk] rw [div_add_div, div_eq_div_iff] · rw [mul_comm _ p, mul_comm _ p', mul_comm _ (φ p'), add_comm] simp only [map_add, map_mul, Submonoid.coe_mul] all_goals try simp only [← map_mul, ← Submonoid.coe_mul] exact nonZeroDivisors.ne_zero (hφ (SetLike.coe_mem _)) } theorem liftRingHom_apply_ofFractionRing_mk (φ : R[X] →+* L) (hφ : R[X]⁰ ≤ L⁰.comap φ) (n : R[X]) (d : R[X]⁰) : liftRingHom φ hφ (ofFractionRing (Localization.mk n d)) = φ n / φ d := liftMonoidWithZeroHom_apply_ofFractionRing_mk _ hφ _ _ theorem liftRingHom_injective [Nontrivial R] (φ : R[X] →+* L) (hφ : Function.Injective φ) (hφ' : R[X]⁰ ≤ L⁰.comap φ := nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _ hφ) : Function.Injective (liftRingHom φ hφ') := liftMonoidWithZeroHom_injective _ hφ end LiftHom variable (K) @[stacks 09FK] instance instField [IsDomain K] : Field (RatFunc K) where inv_zero := by frac_tac div := (· / ·) div_eq_mul_inv := by frac_tac mul_inv_cancel _ := mul_inv_cancel zpow := zpowRec nnqsmul := _ nnqsmul_def := fun _ _ => rfl qsmul := _ qsmul_def := fun _ _ => rfl section IsFractionRing /-! ### `RatFunc` as field of fractions of `Polynomial` -/ section IsDomain variable [IsDomain K] instance (R : Type*) [CommSemiring R] [Algebra R K[X]] : Algebra R (RatFunc K) where algebraMap := { toFun x := RatFunc.mk (algebraMap _ _ x) 1 map_add' x y := by simp only [mk_one', RingHom.map_add, ofFractionRing_add] map_mul' x y := by simp only [mk_one', RingHom.map_mul, ofFractionRing_mul] map_one' := by simp only [mk_one', RingHom.map_one, ofFractionRing_one] map_zero' := by simp only [mk_one', RingHom.map_zero, ofFractionRing_zero] } smul := (· • ·) smul_def' c x := by induction' x using RatFunc.induction_on' with p q hq rw [RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk, mk_one', ← mk_smul, mk_def_of_ne (c • p) hq, mk_def_of_ne p hq, ← ofFractionRing_mul, IsLocalization.mul_mk'_eq_mk'_of_mul, Algebra.smul_def] commutes' _ _ := mul_comm _ _ variable {K} /-- The coercion from polynomials to rational functions, implemented as the algebra map from a domain to its field of fractions -/ @[coe] def coePolynomial (P : Polynomial K) : RatFunc K := algebraMap _ _ P instance : Coe (Polynomial K) (RatFunc K) := ⟨coePolynomial⟩ theorem mk_one (x : K[X]) : RatFunc.mk x 1 = algebraMap _ _ x := rfl theorem ofFractionRing_algebraMap (x : K[X]) : ofFractionRing (algebraMap _ (FractionRing K[X]) x) = algebraMap _ _ x := by rw [← mk_one, mk_one'] @[simp] theorem mk_eq_div (p q : K[X]) : RatFunc.mk p q = algebraMap _ _ p / algebraMap _ _ q := by simp only [mk_eq_div', ofFractionRing_div, ofFractionRing_algebraMap] @[simp] theorem div_smul {R} [Monoid R] [DistribMulAction R K[X]] [IsScalarTower R K[X] K[X]] (c : R) (p q : K[X]) : algebraMap _ (RatFunc K) (c • p) / algebraMap _ _ q = c • (algebraMap _ _ p / algebraMap _ _ q) := by rw [← mk_eq_div, mk_smul, mk_eq_div] theorem algebraMap_apply {R : Type*} [CommSemiring R] [Algebra R K[X]] (x : R) : algebraMap R (RatFunc K) x = algebraMap _ _ (algebraMap R K[X] x) / algebraMap K[X] _ 1 := by rw [← mk_eq_div] rfl theorem map_apply_div_ne_zero {R F : Type*} [CommRing R] [IsDomain R] [FunLike F K[X] R[X]] [MonoidHomClass F K[X] R[X]] (φ : F) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) (p q : K[X]) (hq : q ≠ 0) : map φ hφ (algebraMap _ _ p / algebraMap _ _ q) = algebraMap _ _ (φ p) / algebraMap _ _ (φ q) := by have hq' : φ q ≠ 0 := nonZeroDivisors.ne_zero (hφ (mem_nonZeroDivisors_iff_ne_zero.mpr hq)) simp only [← mk_eq_div, mk_eq_localization_mk _ hq, map_apply_ofFractionRing_mk, mk_eq_localization_mk _ hq'] @[simp] theorem map_apply_div {R F : Type*} [CommRing R] [IsDomain R] [FunLike F K[X] R[X]] [MonoidWithZeroHomClass F K[X] R[X]] (φ : F) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) (p q : K[X]) : map φ hφ (algebraMap _ _ p / algebraMap _ _ q) = algebraMap _ _ (φ p) / algebraMap _ _ (φ q) := by rcases eq_or_ne q 0 with (rfl | hq) · have : (0 : RatFunc K) = algebraMap K[X] _ 0 / algebraMap K[X] _ 1 := by simp rw [map_zero, map_zero, map_zero, div_zero, div_zero, this, map_apply_div_ne_zero, map_one, map_one, div_one, map_zero, map_zero] exact one_ne_zero exact map_apply_div_ne_zero _ _ _ _ hq theorem liftMonoidWithZeroHom_apply_div {L : Type*} [CommGroupWithZero L] (φ : MonoidWithZeroHom K[X] L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (p q : K[X]) : liftMonoidWithZeroHom φ hφ (algebraMap _ _ p / algebraMap _ _ q) = φ p / φ q := by rcases eq_or_ne q 0 with (rfl | hq) · simp only [div_zero, map_zero] simp only [← mk_eq_div, mk_eq_localization_mk _ hq, liftMonoidWithZeroHom_apply_ofFractionRing_mk] @[simp] theorem liftMonoidWithZeroHom_apply_div' {L : Type*} [CommGroupWithZero L] (φ : MonoidWithZeroHom K[X] L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (p q : K[X]) : liftMonoidWithZeroHom φ hφ (algebraMap _ _ p) / liftMonoidWithZeroHom φ hφ (algebraMap _ _ q) = φ p / φ q := by rw [← map_div₀, liftMonoidWithZeroHom_apply_div] theorem liftRingHom_apply_div {L : Type*} [Field L] (φ : K[X] →+* L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (p q : K[X]) : liftRingHom φ hφ (algebraMap _ _ p / algebraMap _ _ q) = φ p / φ q := liftMonoidWithZeroHom_apply_div _ hφ _ _ @[simp] theorem liftRingHom_apply_div' {L : Type*} [Field L] (φ : K[X] →+* L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (p q : K[X]) : liftRingHom φ hφ (algebraMap _ _ p) / liftRingHom φ hφ (algebraMap _ _ q) = φ p / φ q := liftMonoidWithZeroHom_apply_div' _ hφ _ _ variable (K) theorem ofFractionRing_comp_algebraMap : ofFractionRing ∘ algebraMap K[X] (FractionRing K[X]) = algebraMap _ _ := funext ofFractionRing_algebraMap theorem algebraMap_injective : Function.Injective (algebraMap K[X] (RatFunc K)) := by rw [← ofFractionRing_comp_algebraMap] exact ofFractionRing_injective.comp (IsFractionRing.injective _ _) variable {K} section LiftAlgHom variable {L R S : Type*} [Field L] [CommRing R] [IsDomain R] [CommSemiring S] [Algebra S K[X]] [Algebra S L] [Algebra S R[X]] (φ : K[X] →ₐ[S] L) (hφ : K[X]⁰ ≤ L⁰.comap φ) /-- Lift an algebra homomorphism that maps polynomials `φ : K[X] →ₐ[S] R[X]` to a `RatFunc K →ₐ[S] RatFunc R`, on the condition that `φ` maps non zero divisors to non zero divisors, by mapping both the numerator and denominator and quotienting them. -/ def mapAlgHom (φ : K[X] →ₐ[S] R[X]) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) : RatFunc K →ₐ[S] RatFunc R := { mapRingHom φ hφ with commutes' := fun r => by simp_rw [RingHom.toFun_eq_coe, coe_mapRingHom_eq_coe_map, algebraMap_apply r, map_apply_div, map_one, AlgHom.commutes] } theorem coe_mapAlgHom_eq_coe_map (φ : K[X] →ₐ[S] R[X]) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) : (mapAlgHom φ hφ : RatFunc K → RatFunc R) = map φ hφ := rfl /-- Lift an injective algebra homomorphism `K[X] →ₐ[S] L` to a `RatFunc K →ₐ[S] L` by mapping both the numerator and denominator and quotienting them. -/ def liftAlgHom : RatFunc K →ₐ[S] L := { liftRingHom φ.toRingHom hφ with commutes' := fun r => by simp_rw [RingHom.toFun_eq_coe, AlgHom.toRingHom_eq_coe, algebraMap_apply r, liftRingHom_apply_div, AlgHom.coe_toRingHom, map_one, div_one, AlgHom.commutes] } theorem liftAlgHom_apply_ofFractionRing_mk (n : K[X]) (d : K[X]⁰) : liftAlgHom φ hφ (ofFractionRing (Localization.mk n d)) = φ n / φ d := liftMonoidWithZeroHom_apply_ofFractionRing_mk _ hφ _ _ theorem liftAlgHom_injective (φ : K[X] →ₐ[S] L) (hφ : Function.Injective φ) (hφ' : K[X]⁰ ≤ L⁰.comap φ := nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _ hφ) : Function.Injective (liftAlgHom φ hφ') := liftMonoidWithZeroHom_injective _ hφ @[simp] theorem liftAlgHom_apply_div' (p q : K[X]) : liftAlgHom φ hφ (algebraMap _ _ p) / liftAlgHom φ hφ (algebraMap _ _ q) = φ p / φ q := liftMonoidWithZeroHom_apply_div' _ hφ _ _ theorem liftAlgHom_apply_div (p q : K[X]) : liftAlgHom φ hφ (algebraMap _ _ p / algebraMap _ _ q) = φ p / φ q := liftMonoidWithZeroHom_apply_div _ hφ _ _ end LiftAlgHom variable (K) /-- `RatFunc K` is the field of fractions of the polynomials over `K`. -/ instance : IsFractionRing K[X] (RatFunc K) where map_units' y := by rw [← ofFractionRing_algebraMap] exact (toFractionRingRingEquiv K).symm.toRingHom.isUnit_map (IsLocalization.map_units _ y) exists_of_eq {x y} := by rw [← ofFractionRing_algebraMap, ← ofFractionRing_algebraMap] exact fun h ↦ IsLocalization.exists_of_eq ((toFractionRingRingEquiv K).symm.injective h) surj' := by rintro ⟨z⟩ convert IsLocalization.surj K[X]⁰ z simp only [← ofFractionRing_algebraMap, Function.comp_apply, ← ofFractionRing_mul, ofFractionRing.injEq] variable {K} theorem algebraMap_ne_zero {x : K[X]} (hx : x ≠ 0) : algebraMap K[X] (RatFunc K) x ≠ 0 := by simpa @[simp] theorem liftOn_div {P : Sort v} (p q : K[X]) (f : K[X] → K[X] → P) (f0 : ∀ p, f p 0 = f 0 1) (H' : ∀ {p q p' q'} (_hq : q ≠ 0) (_hq' : q' ≠ 0), q' * p = q * p' → f p q = f p' q') (H : ∀ {p q p' q'} (_hq : q ∈ K[X]⁰) (_hq' : q' ∈ K[X]⁰), q' * p = q * p' → f p q = f p' q' := fun {_ _ _ _} hq hq' h => H' (nonZeroDivisors.ne_zero hq) (nonZeroDivisors.ne_zero hq') h) : (RatFunc.liftOn (algebraMap _ (RatFunc K) p / algebraMap _ _ q)) f @H = f p q := by rw [← mk_eq_div, liftOn_mk _ _ f f0 @H'] @[simp] theorem liftOn'_div {P : Sort v} (p q : K[X]) (f : K[X] → K[X] → P) (f0 : ∀ p, f p 0 = f 0 1) (H) : (RatFunc.liftOn' (algebraMap _ (RatFunc K) p / algebraMap _ _ q)) f @H = f p q := by rw [RatFunc.liftOn', liftOn_div _ _ _ f0] apply liftOn_condition_of_liftOn'_condition H /-- Induction principle for `RatFunc K`: if `f p q : P (p / q)` for all `p q : K[X]`, then `P` holds on all elements of `RatFunc K`. See also `induction_on'`, which is a recursion principle defined in terms of `RatFunc.mk`. -/ protected theorem induction_on {P : RatFunc K → Prop} (x : RatFunc K) (f : ∀ (p q : K[X]) (_ : q ≠ 0), P (algebraMap _ (RatFunc K) p / algebraMap _ _ q)) : P x := x.induction_on' fun p q hq => by simpa using f p q hq theorem ofFractionRing_mk' (x : K[X]) (y : K[X]⁰) : ofFractionRing (IsLocalization.mk' _ x y) = IsLocalization.mk' (RatFunc K) x y := by rw [IsFractionRing.mk'_eq_div, IsFractionRing.mk'_eq_div, ← mk_eq_div', ← mk_eq_div] theorem mk_eq_mk' (f : Polynomial K) {g : Polynomial K} (hg : g ≠ 0) : RatFunc.mk f g = IsLocalization.mk' (RatFunc K) f ⟨g, mem_nonZeroDivisors_iff_ne_zero.2 hg⟩ := by simp only [mk_eq_div, IsFractionRing.mk'_eq_div] @[simp] theorem ofFractionRing_eq : (ofFractionRing : FractionRing K[X] → RatFunc K) = IsLocalization.algEquiv K[X]⁰ _ _ := funext fun x => Localization.induction_on x fun x => by simp only [Localization.mk_eq_mk'_apply, ofFractionRing_mk', IsLocalization.algEquiv_apply, IsLocalization.map_mk', RingHom.id_apply] @[simp] theorem toFractionRing_eq : (toFractionRing : RatFunc K → FractionRing K[X]) = IsLocalization.algEquiv K[X]⁰ _ _ := funext fun ⟨x⟩ => Localization.induction_on x fun x => by simp only [Localization.mk_eq_mk'_apply, ofFractionRing_mk', IsLocalization.algEquiv_apply, IsLocalization.map_mk', RingHom.id_apply] @[simp] theorem toFractionRingRingEquiv_symm_eq : (toFractionRingRingEquiv K).symm = (IsLocalization.algEquiv K[X]⁰ _ _).toRingEquiv := by ext x simp [toFractionRingRingEquiv, ofFractionRing_eq, AlgEquiv.coe_ringEquiv'] end IsDomain end IsFractionRing end CommRing section NumDenom /-! ### Numerator and denominator -/ open GCDMonoid Polynomial variable [Field K] open scoped Classical in /-- `RatFunc.numDenom` are numerator and denominator of a rational function over a field, normalized such that the denominator is monic. -/ def numDenom (x : RatFunc K) : K[X] × K[X] := x.liftOn' (fun p q => if q = 0 then ⟨0, 1⟩ else let r := gcd p q ⟨Polynomial.C (q / r).leadingCoeff⁻¹ * (p / r), Polynomial.C (q / r).leadingCoeff⁻¹ * (q / r)⟩) (by intros p q a hq ha dsimp rw [if_neg hq, if_neg (mul_ne_zero ha hq)] have ha' : a.leadingCoeff ≠ 0 := Polynomial.leadingCoeff_ne_zero.mpr ha have hainv : a.leadingCoeff⁻¹ ≠ 0 := inv_ne_zero ha' simp only [Prod.ext_iff, gcd_mul_left, normalize_apply a, Polynomial.coe_normUnit, mul_assoc, CommGroupWithZero.coe_normUnit _ ha'] have hdeg : (gcd p q).degree ≤ q.degree := degree_gcd_le_right _ hq have hdeg' : (Polynomial.C a.leadingCoeff⁻¹ * gcd p q).degree ≤ q.degree := by rw [Polynomial.degree_mul, Polynomial.degree_C hainv, zero_add] exact hdeg have hdivp : Polynomial.C a.leadingCoeff⁻¹ * gcd p q ∣ p := (C_mul_dvd hainv).mpr (gcd_dvd_left p q) have hdivq : Polynomial.C a.leadingCoeff⁻¹ * gcd p q ∣ q := (C_mul_dvd hainv).mpr (gcd_dvd_right p q) rw [EuclideanDomain.mul_div_mul_cancel ha hdivp, EuclideanDomain.mul_div_mul_cancel ha hdivq, leadingCoeff_div hdeg, leadingCoeff_div hdeg', Polynomial.leadingCoeff_mul, Polynomial.leadingCoeff_C, div_C_mul, div_C_mul, ← mul_assoc, ← Polynomial.C_mul, ← mul_assoc, ← Polynomial.C_mul] constructor <;> congr <;> rw [inv_div, mul_comm, mul_div_assoc, ← mul_assoc, inv_inv, mul_inv_cancel₀ ha', one_mul, inv_div]) open scoped Classical in @[simp] theorem numDenom_div (p : K[X]) {q : K[X]} (hq : q ≠ 0) : numDenom (algebraMap _ _ p / algebraMap _ _ q) = (Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q), Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (q / gcd p q)) := by rw [numDenom, liftOn'_div, if_neg hq] intro p rw [if_pos rfl, if_neg (one_ne_zero' K[X])] simp /-- `RatFunc.num` is the numerator of a rational function, normalized such that the denominator is monic. -/ def num (x : RatFunc K) : K[X] := x.numDenom.1 open scoped Classical in private theorem num_div' (p : K[X]) {q : K[X]} (hq : q ≠ 0) : num (algebraMap _ _ p / algebraMap _ _ q) = Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q) := by rw [num, numDenom_div _ hq] @[simp] theorem num_zero : num (0 : RatFunc K) = 0 := by convert num_div' (0 : K[X]) one_ne_zero <;> simp open scoped Classical in @[simp] theorem num_div (p q : K[X]) : num (algebraMap _ _ p / algebraMap _ _ q) = Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q) := by by_cases hq : q = 0 · simp [hq] · exact num_div' p hq @[simp] theorem num_one : num (1 : RatFunc K) = 1 := by convert num_div (1 : K[X]) 1 <;> simp @[simp] theorem num_algebraMap (p : K[X]) : num (algebraMap _ _ p) = p := by convert num_div p 1 <;> simp theorem num_div_dvd (p : K[X]) {q : K[X]} (hq : q ≠ 0) : num (algebraMap _ _ p / algebraMap _ _ q) ∣ p := by classical rw [num_div _ q, C_mul_dvd] · exact EuclideanDomain.div_dvd_of_dvd (gcd_dvd_left p q) · simpa only [Ne, inv_eq_zero, Polynomial.leadingCoeff_eq_zero] using right_div_gcd_ne_zero hq open scoped Classical in /-- A version of `num_div_dvd` with the LHS in simp normal form -/ @[simp] theorem num_div_dvd' (p : K[X]) {q : K[X]} (hq : q ≠ 0) : C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q) ∣ p := by simpa using num_div_dvd p hq /-- `RatFunc.denom` is the denominator of a rational function, normalized such that it is monic. -/ def denom (x : RatFunc K) : K[X] := x.numDenom.2 open scoped Classical in @[simp] theorem denom_div (p : K[X]) {q : K[X]} (hq : q ≠ 0) : denom (algebraMap _ _ p / algebraMap _ _ q) = Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (q / gcd p q) := by rw [denom, numDenom_div _ hq] theorem monic_denom (x : RatFunc K) : (denom x).Monic := by classical induction x using RatFunc.induction_on with | f p q hq => rw [denom_div p hq, mul_comm] exact Polynomial.monic_mul_leadingCoeff_inv (right_div_gcd_ne_zero hq) theorem denom_ne_zero (x : RatFunc K) : denom x ≠ 0 := (monic_denom x).ne_zero @[simp] theorem denom_zero : denom (0 : RatFunc K) = 1 := by convert denom_div (0 : K[X]) one_ne_zero <;> simp @[simp] theorem denom_one : denom (1 : RatFunc K) = 1 := by convert denom_div (1 : K[X]) one_ne_zero <;> simp @[simp] theorem denom_algebraMap (p : K[X]) : denom (algebraMap _ (RatFunc K) p) = 1 := by convert denom_div p one_ne_zero <;> simp @[simp] theorem denom_div_dvd (p q : K[X]) : denom (algebraMap _ _ p / algebraMap _ _ q) ∣ q := by classical by_cases hq : q = 0 · simp [hq] rw [denom_div _ hq, C_mul_dvd] · exact EuclideanDomain.div_dvd_of_dvd (gcd_dvd_right p q) · simpa only [Ne, inv_eq_zero, Polynomial.leadingCoeff_eq_zero] using right_div_gcd_ne_zero hq @[simp] theorem num_div_denom (x : RatFunc K) : algebraMap _ _ (num x) / algebraMap _ _ (denom x) = x := by classical induction' x using RatFunc.induction_on with p q hq have q_div_ne_zero : q / gcd p q ≠ 0 := right_div_gcd_ne_zero hq rw [num_div p q, denom_div p hq, RingHom.map_mul, RingHom.map_mul, mul_div_mul_left, div_eq_div_iff, ← RingHom.map_mul, ← RingHom.map_mul, mul_comm _ q, ← EuclideanDomain.mul_div_assoc, ← EuclideanDomain.mul_div_assoc, mul_comm] · apply gcd_dvd_right · apply gcd_dvd_left · exact algebraMap_ne_zero q_div_ne_zero · exact algebraMap_ne_zero hq · refine algebraMap_ne_zero (mt Polynomial.C_eq_zero.mp ?_) exact inv_ne_zero (Polynomial.leadingCoeff_ne_zero.mpr q_div_ne_zero) theorem isCoprime_num_denom (x : RatFunc K) : IsCoprime x.num x.denom := by classical induction' x using RatFunc.induction_on with p q hq rw [num_div, denom_div _ hq] exact (isCoprime_mul_unit_left ((leadingCoeff_ne_zero.2 <| right_div_gcd_ne_zero hq).isUnit.inv.map C) _ _).2 (isCoprime_div_gcd_div_gcd hq)
@[simp] theorem num_eq_zero_iff {x : RatFunc K} : num x = 0 ↔ x = 0 := ⟨fun h => by rw [← num_div_denom x, h, RingHom.map_zero, zero_div], fun h => h.symm ▸ num_zero⟩ theorem num_ne_zero {x : RatFunc K} (hx : x ≠ 0) : num x ≠ 0 := mt num_eq_zero_iff.mp hx theorem num_mul_eq_mul_denom_iff {x : RatFunc K} {p q : K[X]} (hq : q ≠ 0) :
Mathlib/FieldTheory/RatFunc/Basic.lean
894
901
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl, Patrick Massot -/ import Mathlib.Data.Set.Image import Mathlib.Data.SProd /-! # Sets in product and pi types This file proves basic properties of product of sets in `α × β` and in `Π i, α i`, and of the diagonal of a type. ## Main declarations This file contains basic results on the following notions, which are defined in `Set.Operations`. * `Set.prod`: Binary product of sets. For `s : Set α`, `t : Set β`, we have `s.prod t : Set (α × β)`. Denoted by `s ×ˢ t`. * `Set.diagonal`: Diagonal of a type. `Set.diagonal α = {(x, x) | x : α}`. * `Set.offDiag`: Off-diagonal. `s ×ˢ s` without the diagonal. * `Set.pi`: Arbitrary product of sets. -/ open Function namespace Set /-! ### Cartesian binary product of sets -/ section Prod variable {α β γ δ : Type*} {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {a : α} {b : β} theorem Subsingleton.prod (hs : s.Subsingleton) (ht : t.Subsingleton) : (s ×ˢ t).Subsingleton := fun _x hx _y hy ↦ Prod.ext (hs hx.1 hy.1) (ht hx.2 hy.2) noncomputable instance decidableMemProd [DecidablePred (· ∈ s)] [DecidablePred (· ∈ t)] : DecidablePred (· ∈ s ×ˢ t) := fun x => inferInstanceAs (Decidable (x.1 ∈ s ∧ x.2 ∈ t)) @[gcongr] theorem prod_mono (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : s₁ ×ˢ t₁ ⊆ s₂ ×ˢ t₂ := fun _ ⟨h₁, h₂⟩ => ⟨hs h₁, ht h₂⟩ @[gcongr] theorem prod_mono_left (hs : s₁ ⊆ s₂) : s₁ ×ˢ t ⊆ s₂ ×ˢ t := prod_mono hs Subset.rfl @[gcongr] theorem prod_mono_right (ht : t₁ ⊆ t₂) : s ×ˢ t₁ ⊆ s ×ˢ t₂ := prod_mono Subset.rfl ht @[simp] theorem prod_self_subset_prod_self : s₁ ×ˢ s₁ ⊆ s₂ ×ˢ s₂ ↔ s₁ ⊆ s₂ := ⟨fun h _ hx => (h (mk_mem_prod hx hx)).1, fun h _ hx => ⟨h hx.1, h hx.2⟩⟩ @[simp] theorem prod_self_ssubset_prod_self : s₁ ×ˢ s₁ ⊂ s₂ ×ˢ s₂ ↔ s₁ ⊂ s₂ := and_congr prod_self_subset_prod_self <| not_congr prod_self_subset_prod_self theorem prod_subset_iff {P : Set (α × β)} : s ×ˢ t ⊆ P ↔ ∀ x ∈ s, ∀ y ∈ t, (x, y) ∈ P := ⟨fun h _ hx _ hy => h (mk_mem_prod hx hy), fun h ⟨_, _⟩ hp => h _ hp.1 _ hp.2⟩ theorem forall_prod_set {p : α × β → Prop} : (∀ x ∈ s ×ˢ t, p x) ↔ ∀ x ∈ s, ∀ y ∈ t, p (x, y) := prod_subset_iff theorem exists_prod_set {p : α × β → Prop} : (∃ x ∈ s ×ˢ t, p x) ↔ ∃ x ∈ s, ∃ y ∈ t, p (x, y) := by simp [and_assoc] @[simp] theorem prod_empty : s ×ˢ (∅ : Set β) = ∅ := by ext exact iff_of_eq (and_false _) @[simp] theorem empty_prod : (∅ : Set α) ×ˢ t = ∅ := by ext exact iff_of_eq (false_and _) @[simp, mfld_simps] theorem univ_prod_univ : @univ α ×ˢ @univ β = univ := by ext exact iff_of_eq (true_and _) theorem univ_prod {t : Set β} : (univ : Set α) ×ˢ t = Prod.snd ⁻¹' t := by simp [prod_eq] theorem prod_univ {s : Set α} : s ×ˢ (univ : Set β) = Prod.fst ⁻¹' s := by simp [prod_eq] @[simp] lemma prod_eq_univ [Nonempty α] [Nonempty β] : s ×ˢ t = univ ↔ s = univ ∧ t = univ := by simp [eq_univ_iff_forall, forall_and] theorem singleton_prod : ({a} : Set α) ×ˢ t = Prod.mk a '' t := by ext ⟨x, y⟩ simp [and_left_comm, eq_comm] theorem prod_singleton : s ×ˢ ({b} : Set β) = (fun a => (a, b)) '' s := by ext ⟨x, y⟩ simp [and_left_comm, eq_comm] @[simp] theorem singleton_prod_singleton : ({a} : Set α) ×ˢ ({b} : Set β) = {(a, b)} := by ext ⟨c, d⟩; simp @[simp] theorem union_prod : (s₁ ∪ s₂) ×ˢ t = s₁ ×ˢ t ∪ s₂ ×ˢ t := by ext ⟨x, y⟩ simp [or_and_right] @[simp] theorem prod_union : s ×ˢ (t₁ ∪ t₂) = s ×ˢ t₁ ∪ s ×ˢ t₂ := by ext ⟨x, y⟩ simp [and_or_left] theorem inter_prod : (s₁ ∩ s₂) ×ˢ t = s₁ ×ˢ t ∩ s₂ ×ˢ t := by ext ⟨x, y⟩ simp only [← and_and_right, mem_inter_iff, mem_prod] theorem prod_inter : s ×ˢ (t₁ ∩ t₂) = s ×ˢ t₁ ∩ s ×ˢ t₂ := by ext ⟨x, y⟩ simp only [← and_and_left, mem_inter_iff, mem_prod] @[mfld_simps] theorem prod_inter_prod : s₁ ×ˢ t₁ ∩ s₂ ×ˢ t₂ = (s₁ ∩ s₂) ×ˢ (t₁ ∩ t₂) := by ext ⟨x, y⟩ simp [and_assoc, and_left_comm] lemma compl_prod_eq_union {α β : Type*} (s : Set α) (t : Set β) : (s ×ˢ t)ᶜ = (sᶜ ×ˢ univ) ∪ (univ ×ˢ tᶜ) := by ext p simp only [mem_compl_iff, mem_prod, not_and, mem_union, mem_univ, and_true, true_and] constructor <;> intro h · by_cases fst_in_s : p.fst ∈ s · exact Or.inr (h fst_in_s) · exact Or.inl fst_in_s · intro fst_in_s simpa only [fst_in_s, not_true, false_or] using h @[simp] theorem disjoint_prod : Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) ↔ Disjoint s₁ s₂ ∨ Disjoint t₁ t₂ := by simp_rw [disjoint_left, mem_prod, not_and_or, Prod.forall, and_imp, ← @forall_or_right α, ← @forall_or_left β, ← @forall_or_right (_ ∈ s₁), ← @forall_or_left (_ ∈ t₁)] theorem Disjoint.set_prod_left (hs : Disjoint s₁ s₂) (t₁ t₂ : Set β) : Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) := disjoint_left.2 fun ⟨_a, _b⟩ ⟨ha₁, _⟩ ⟨ha₂, _⟩ => disjoint_left.1 hs ha₁ ha₂ theorem Disjoint.set_prod_right (ht : Disjoint t₁ t₂) (s₁ s₂ : Set α) : Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) := disjoint_left.2 fun ⟨_a, _b⟩ ⟨_, hb₁⟩ ⟨_, hb₂⟩ => disjoint_left.1 ht hb₁ hb₂ theorem prodMap_image_prod (f : α → β) (g : γ → δ) (s : Set α) (t : Set γ) : (Prod.map f g) '' (s ×ˢ t) = (f '' s) ×ˢ (g '' t) := by ext aesop theorem insert_prod : insert a s ×ˢ t = Prod.mk a '' t ∪ s ×ˢ t := by simp only [insert_eq, union_prod, singleton_prod] theorem prod_insert : s ×ˢ insert b t = (fun a => (a, b)) '' s ∪ s ×ˢ t := by simp only [insert_eq, prod_union, prod_singleton] theorem prod_preimage_eq {f : γ → α} {g : δ → β} : (f ⁻¹' s) ×ˢ (g ⁻¹' t) = (fun p : γ × δ => (f p.1, g p.2)) ⁻¹' s ×ˢ t := rfl theorem prod_preimage_left {f : γ → α} : (f ⁻¹' s) ×ˢ t = (fun p : γ × β => (f p.1, p.2)) ⁻¹' s ×ˢ t := rfl theorem prod_preimage_right {g : δ → β} : s ×ˢ (g ⁻¹' t) = (fun p : α × δ => (p.1, g p.2)) ⁻¹' s ×ˢ t := rfl theorem preimage_prod_map_prod (f : α → β) (g : γ → δ) (s : Set β) (t : Set δ) : Prod.map f g ⁻¹' s ×ˢ t = (f ⁻¹' s) ×ˢ (g ⁻¹' t) := rfl theorem mk_preimage_prod (f : γ → α) (g : γ → β) : (fun x => (f x, g x)) ⁻¹' s ×ˢ t = f ⁻¹' s ∩ g ⁻¹' t := rfl @[simp] theorem mk_preimage_prod_left (hb : b ∈ t) : (fun a => (a, b)) ⁻¹' s ×ˢ t = s := by ext a simp [hb] @[simp] theorem mk_preimage_prod_right (ha : a ∈ s) : Prod.mk a ⁻¹' s ×ˢ t = t := by ext b simp [ha] @[simp] theorem mk_preimage_prod_left_eq_empty (hb : b ∉ t) : (fun a => (a, b)) ⁻¹' s ×ˢ t = ∅ := by ext a simp [hb] @[simp] theorem mk_preimage_prod_right_eq_empty (ha : a ∉ s) : Prod.mk a ⁻¹' s ×ˢ t = ∅ := by ext b simp [ha] theorem mk_preimage_prod_left_eq_if [DecidablePred (· ∈ t)] : (fun a => (a, b)) ⁻¹' s ×ˢ t = if b ∈ t then s else ∅ := by split_ifs with h <;> simp [h] theorem mk_preimage_prod_right_eq_if [DecidablePred (· ∈ s)] : Prod.mk a ⁻¹' s ×ˢ t = if a ∈ s then t else ∅ := by split_ifs with h <;> simp [h] theorem mk_preimage_prod_left_fn_eq_if [DecidablePred (· ∈ t)] (f : γ → α) : (fun a => (f a, b)) ⁻¹' s ×ˢ t = if b ∈ t then f ⁻¹' s else ∅ := by rw [← mk_preimage_prod_left_eq_if, prod_preimage_left, preimage_preimage] theorem mk_preimage_prod_right_fn_eq_if [DecidablePred (· ∈ s)] (g : δ → β) : (fun b => (a, g b)) ⁻¹' s ×ˢ t = if a ∈ s then g ⁻¹' t else ∅ := by rw [← mk_preimage_prod_right_eq_if, prod_preimage_right, preimage_preimage] @[simp] theorem preimage_swap_prod (s : Set α) (t : Set β) : Prod.swap ⁻¹' s ×ˢ t = t ×ˢ s := by ext ⟨x, y⟩ simp [and_comm] @[simp] theorem image_swap_prod (s : Set α) (t : Set β) : Prod.swap '' s ×ˢ t = t ×ˢ s := by rw [image_swap_eq_preimage_swap, preimage_swap_prod] theorem mapsTo_swap_prod (s : Set α) (t : Set β) : MapsTo Prod.swap (s ×ˢ t) (t ×ˢ s) := fun _ ⟨hx, hy⟩ ↦ ⟨hy, hx⟩ theorem prod_image_image_eq {m₁ : α → γ} {m₂ : β → δ} : (m₁ '' s) ×ˢ (m₂ '' t) = (fun p : α × β => (m₁ p.1, m₂ p.2)) '' s ×ˢ t := ext <| by simp [-exists_and_right, exists_and_right.symm, and_left_comm, and_assoc, and_comm] theorem prod_range_range_eq {m₁ : α → γ} {m₂ : β → δ} : range m₁ ×ˢ range m₂ = range fun p : α × β => (m₁ p.1, m₂ p.2) := ext <| by simp [range] @[simp, mfld_simps] theorem range_prodMap {m₁ : α → γ} {m₂ : β → δ} : range (Prod.map m₁ m₂) = range m₁ ×ˢ range m₂ := prod_range_range_eq.symm @[deprecated (since := "2025-04-10")] alias range_prod_map := range_prodMap theorem prod_range_univ_eq {m₁ : α → γ} : range m₁ ×ˢ (univ : Set β) = range fun p : α × β => (m₁ p.1, p.2) :=
ext <| by simp [range]
Mathlib/Data/Set/Prod.lean
248
249
/- Copyright (c) 2020 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Shing Tak Lam, Mario Carneiro -/ import Mathlib.Algebra.BigOperators.Intervals import Mathlib.Algebra.BigOperators.Ring.List import Mathlib.Data.Int.ModEq import Mathlib.Data.Nat.Bits import Mathlib.Data.Nat.Log import Mathlib.Data.List.Palindrome import Mathlib.Tactic.IntervalCases import Mathlib.Tactic.Linarith import Mathlib.Tactic.Ring /-! # Digits of a natural number This provides a basic API for extracting the digits of a natural number in a given base, and reconstructing numbers from their digits. We also prove some divisibility tests based on digits, in particular completing Theorem #85 from https://www.cs.ru.nl/~freek/100/. Also included is a bound on the length of `Nat.toDigits` from core. ## TODO A basic `norm_digits` tactic for proving goals of the form `Nat.digits a b = l` where `a` and `b` are numerals is not yet ported. -/ namespace Nat variable {n : ℕ} /-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/ def digitsAux0 : ℕ → List ℕ | 0 => [] | n + 1 => [n + 1] /-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/ def digitsAux1 (n : ℕ) : List ℕ := List.replicate n 1 /-- (Impl.) An auxiliary definition for `digits`, to help get the desired definitional unfolding. -/ def digitsAux (b : ℕ) (h : 2 ≤ b) : ℕ → List ℕ | 0 => [] | n + 1 => ((n + 1) % b) :: digitsAux b h ((n + 1) / b) decreasing_by exact Nat.div_lt_self (Nat.succ_pos _) h @[simp] theorem digitsAux_zero (b : ℕ) (h : 2 ≤ b) : digitsAux b h 0 = [] := by rw [digitsAux] theorem digitsAux_def (b : ℕ) (h : 2 ≤ b) (n : ℕ) (w : 0 < n) : digitsAux b h n = (n % b) :: digitsAux b h (n / b) := by cases n · cases w · rw [digitsAux] /-- `digits b n` gives the digits, in little-endian order, of a natural number `n` in a specified base `b`. In any base, we have `ofDigits b L = L.foldr (fun x y ↦ x + b * y) 0`. * For any `2 ≤ b`, we have `l < b` for any `l ∈ digits b n`, and the last digit is not zero. This uniquely specifies the behaviour of `digits b`. * For `b = 1`, we define `digits 1 n = List.replicate n 1`. * For `b = 0`, we define `digits 0 n = [n]`, except `digits 0 0 = []`. Note this differs from the existing `Nat.toDigits` in core, which is used for printing numerals. In particular, `Nat.toDigits b 0 = ['0']`, while `digits b 0 = []`. -/ def digits : ℕ → ℕ → List ℕ | 0 => digitsAux0 | 1 => digitsAux1 | b + 2 => digitsAux (b + 2) (by norm_num) @[simp] theorem digits_zero (b : ℕ) : digits b 0 = [] := by rcases b with (_ | ⟨_ | ⟨_⟩⟩) <;> simp [digits, digitsAux0, digitsAux1] theorem digits_zero_zero : digits 0 0 = [] := rfl @[simp] theorem digits_zero_succ (n : ℕ) : digits 0 n.succ = [n + 1] := rfl theorem digits_zero_succ' : ∀ {n : ℕ}, n ≠ 0 → digits 0 n = [n] | 0, h => (h rfl).elim | _ + 1, _ => rfl @[simp] theorem digits_one (n : ℕ) : digits 1 n = List.replicate n 1 := rfl -- no `@[simp]`: dsimp can prove this theorem digits_one_succ (n : ℕ) : digits 1 (n + 1) = 1 :: digits 1 n := rfl theorem digits_add_two_add_one (b n : ℕ) : digits (b + 2) (n + 1) = ((n + 1) % (b + 2)) :: digits (b + 2) ((n + 1) / (b + 2)) := by simp [digits, digitsAux_def] @[simp] lemma digits_of_two_le_of_pos {b : ℕ} (hb : 2 ≤ b) (hn : 0 < n) : Nat.digits b n = n % b :: Nat.digits b (n / b) := by rw [Nat.eq_add_of_sub_eq hb rfl, Nat.eq_add_of_sub_eq hn rfl, Nat.digits_add_two_add_one] theorem digits_def' : ∀ {b : ℕ} (_ : 1 < b) {n : ℕ} (_ : 0 < n), digits b n = (n % b) :: digits b (n / b) | 0, h => absurd h (by decide) | 1, h => absurd h (by decide) | b + 2, _ => digitsAux_def _ (by simp) _ @[simp] theorem digits_of_lt (b x : ℕ) (hx : x ≠ 0) (hxb : x < b) : digits b x = [x] := by rcases exists_eq_succ_of_ne_zero hx with ⟨x, rfl⟩ rcases Nat.exists_eq_add_of_le' ((Nat.le_add_left 1 x).trans_lt hxb) with ⟨b, rfl⟩ rw [digits_add_two_add_one, div_eq_of_lt hxb, digits_zero, mod_eq_of_lt hxb] theorem digits_add (b : ℕ) (h : 1 < b) (x y : ℕ) (hxb : x < b) (hxy : x ≠ 0 ∨ y ≠ 0) : digits b (x + b * y) = x :: digits b y := by rcases Nat.exists_eq_add_of_le' h with ⟨b, rfl : _ = _ + 2⟩ cases y · simp [hxb, hxy.resolve_right (absurd rfl)] dsimp [digits] rw [digitsAux_def] · congr · simp [Nat.add_mod, mod_eq_of_lt hxb] · simp [add_mul_div_left, div_eq_of_lt hxb] · apply Nat.succ_pos -- If we had a function converting a list into a polynomial, -- and appropriate lemmas about that function, -- we could rewrite this in terms of that. /-- `ofDigits b L` takes a list `L` of natural numbers, and interprets them as a number in semiring, as the little-endian digits in base `b`. -/ def ofDigits {α : Type*} [Semiring α] (b : α) : List ℕ → α | [] => 0 | h :: t => h + b * ofDigits b t theorem ofDigits_eq_foldr {α : Type*} [Semiring α] (b : α) (L : List ℕ) : ofDigits b L = List.foldr (fun x y => ↑x + b * y) 0 L := by induction' L with d L ih · rfl · dsimp [ofDigits] rw [ih] theorem ofDigits_eq_sum_mapIdx_aux (b : ℕ) (l : List ℕ) : (l.zipWith ((fun a i : ℕ => a * b ^ (i + 1))) (List.range l.length)).sum = b * (l.zipWith (fun a i => a * b ^ i) (List.range l.length)).sum := by suffices l.zipWith (fun a i : ℕ => a * b ^ (i + 1)) (List.range l.length) = l.zipWith (fun a i=> b * (a * b ^ i)) (List.range l.length) by simp [this] congr; ext; simp [pow_succ]; ring theorem ofDigits_eq_sum_mapIdx (b : ℕ) (L : List ℕ) : ofDigits b L = (L.mapIdx fun i a => a * b ^ i).sum := by rw [List.mapIdx_eq_zipIdx_map, List.zipIdx_eq_zip_range', List.map_zip_eq_zipWith, ofDigits_eq_foldr, ← List.range_eq_range'] induction' L with hd tl hl · simp · simpa [List.range_succ_eq_map, List.zipWith_map_right, ofDigits_eq_sum_mapIdx_aux] using Or.inl hl @[simp] theorem ofDigits_nil {b : ℕ} : ofDigits b [] = 0 := rfl @[simp] theorem ofDigits_singleton {b n : ℕ} : ofDigits b [n] = n := by simp [ofDigits] @[simp] theorem ofDigits_one_cons {α : Type*} [Semiring α] (h : ℕ) (L : List ℕ) : ofDigits (1 : α) (h :: L) = h + ofDigits 1 L := by simp [ofDigits] theorem ofDigits_cons {b hd} {tl : List ℕ} : ofDigits b (hd :: tl) = hd + b * ofDigits b tl := rfl theorem ofDigits_append {b : ℕ} {l1 l2 : List ℕ} : ofDigits b (l1 ++ l2) = ofDigits b l1 + b ^ l1.length * ofDigits b l2 := by induction' l1 with hd tl IH · simp [ofDigits] · rw [ofDigits, List.cons_append, ofDigits, IH, List.length_cons, pow_succ'] ring @[norm_cast] theorem coe_ofDigits (α : Type*) [Semiring α] (b : ℕ) (L : List ℕ) : ((ofDigits b L : ℕ) : α) = ofDigits (b : α) L := by induction' L with d L ih · simp [ofDigits] · dsimp [ofDigits]; push_cast; rw [ih] @[norm_cast] theorem coe_int_ofDigits (b : ℕ) (L : List ℕ) : ((ofDigits b L : ℕ) : ℤ) = ofDigits (b : ℤ) L := by induction' L with d L _ · rfl · dsimp [ofDigits]; push_cast; simp only theorem digits_zero_of_eq_zero {b : ℕ} (h : b ≠ 0) : ∀ {L : List ℕ} (_ : ofDigits b L = 0), ∀ l ∈ L, l = 0 | _ :: _, h0, _, List.Mem.head .. => Nat.eq_zero_of_add_eq_zero_right h0 | _ :: _, h0, _, List.Mem.tail _ hL => digits_zero_of_eq_zero h (mul_right_injective₀ h (Nat.eq_zero_of_add_eq_zero_left h0)) _ hL theorem digits_ofDigits (b : ℕ) (h : 1 < b) (L : List ℕ) (w₁ : ∀ l ∈ L, l < b) (w₂ : ∀ h : L ≠ [], L.getLast h ≠ 0) : digits b (ofDigits b L) = L := by induction' L with d L ih · dsimp [ofDigits] simp · dsimp [ofDigits] replace w₂ := w₂ (by simp) rw [digits_add b h] · rw [ih] · intro l m apply w₁ exact List.mem_cons_of_mem _ m · intro h rw [List.getLast_cons h] at w₂ convert w₂ · exact w₁ d List.mem_cons_self · by_cases h' : L = [] · rcases h' with rfl left simpa using w₂ · right contrapose! w₂ refine digits_zero_of_eq_zero h.ne_bot w₂ _ ?_ rw [List.getLast_cons h'] exact List.getLast_mem h' theorem ofDigits_digits (b n : ℕ) : ofDigits b (digits b n) = n := by rcases b with - | b · rcases n with - | n · rfl · simp · rcases b with - | b · induction' n with n ih · rfl · rw [Nat.zero_add] at ih ⊢ simp only [ih, add_comm 1, ofDigits_one_cons, Nat.cast_id, digits_one_succ] · induction n using Nat.strongRecOn with | ind n h => ?_ cases n · rw [digits_zero] rfl · simp only [Nat.succ_eq_add_one, digits_add_two_add_one] dsimp [ofDigits] rw [h _ (Nat.div_lt_self' _ b)] rw [Nat.mod_add_div] theorem ofDigits_one (L : List ℕ) : ofDigits 1 L = L.sum := by induction L with | nil => rfl | cons _ _ ih => simp [ofDigits, List.sum_cons, ih] /-! ### Properties This section contains various lemmas of properties relating to `digits` and `ofDigits`. -/ theorem digits_eq_nil_iff_eq_zero {b n : ℕ} : digits b n = [] ↔ n = 0 := by constructor · intro h have : ofDigits b (digits b n) = ofDigits b [] := by rw [h] convert this rw [ofDigits_digits] · rintro rfl simp theorem digits_ne_nil_iff_ne_zero {b n : ℕ} : digits b n ≠ [] ↔ n ≠ 0 := not_congr digits_eq_nil_iff_eq_zero theorem digits_eq_cons_digits_div {b n : ℕ} (h : 1 < b) (w : n ≠ 0) : digits b n = (n % b) :: digits b (n / b) := by rcases b with (_ | _ | b) · rw [digits_zero_succ' w, Nat.mod_zero, Nat.div_zero, Nat.digits_zero_zero] · norm_num at h rcases n with (_ | n) · norm_num at w · simp only [digits_add_two_add_one, ne_eq] theorem digits_getLast {b : ℕ} (m : ℕ) (h : 1 < b) (p q) : (digits b m).getLast p = (digits b (m / b)).getLast q := by by_cases hm : m = 0 · simp [hm] simp only [digits_eq_cons_digits_div h hm] rw [List.getLast_cons] theorem digits.injective (b : ℕ) : Function.Injective b.digits := Function.LeftInverse.injective (ofDigits_digits b) @[simp] theorem digits_inj_iff {b n m : ℕ} : b.digits n = b.digits m ↔ n = m := (digits.injective b).eq_iff theorem digits_len (b n : ℕ) (hb : 1 < b) (hn : n ≠ 0) : (b.digits n).length = b.log n + 1 := by induction' n using Nat.strong_induction_on with n IH rw [digits_eq_cons_digits_div hb hn, List.length] by_cases h : n / b = 0 · simp [IH, h] aesop · have : n / b < n := div_lt_self (Nat.pos_of_ne_zero hn) hb rw [IH _ this h, log_div_base, tsub_add_cancel_of_le] refine Nat.succ_le_of_lt (log_pos hb ?_) contrapose! h exact div_eq_of_lt h theorem getLast_digit_ne_zero (b : ℕ) {m : ℕ} (hm : m ≠ 0) : (digits b m).getLast (digits_ne_nil_iff_ne_zero.mpr hm) ≠ 0 := by rcases b with (_ | _ | b) · cases m · cases hm rfl · simp · cases m · cases hm rfl rename ℕ => m simp only [zero_add, digits_one, List.getLast_replicate_succ m 1] exact Nat.one_ne_zero revert hm induction m using Nat.strongRecOn with | ind n IH => ?_ intro hn by_cases hnb : n < b + 2 · simpa only [digits_of_lt (b + 2) n hn hnb] · rw [digits_getLast n (le_add_left 2 b)] refine IH _ (Nat.div_lt_self hn.bot_lt (one_lt_succ_succ b)) ?_ rw [← pos_iff_ne_zero] exact Nat.div_pos (le_of_not_lt hnb) (zero_lt_succ (succ b)) theorem mul_ofDigits (n : ℕ) {b : ℕ} {l : List ℕ} : n * ofDigits b l = ofDigits b (l.map (n * ·)) := by induction l with | nil => rfl | cons hd tl ih => rw [List.map_cons, ofDigits_cons, ofDigits_cons, ← ih] ring lemma ofDigits_inj_of_len_eq {b : ℕ} (hb : 1 < b) {L1 L2 : List ℕ} (len : L1.length = L2.length) (w1 : ∀ l ∈ L1, l < b) (w2 : ∀ l ∈ L2, l < b) (h : ofDigits b L1 = ofDigits b L2) : L1 = L2 := by induction' L1 with D L ih generalizing L2 · simp only [List.length_nil] at len exact (List.length_eq_zero_iff.mp len.symm).symm obtain ⟨d, l, rfl⟩ := List.exists_cons_of_length_eq_add_one len.symm simp only [List.length_cons, add_left_inj] at len simp only [ofDigits_cons] at h have eqd : D = d := by have H : (D + b * ofDigits b L) % b = (d + b * ofDigits b l) % b := by rw [h] simpa [mod_eq_of_lt (w2 d List.mem_cons_self), mod_eq_of_lt (w1 D List.mem_cons_self)] using H simp only [eqd, add_right_inj, mul_left_cancel_iff_of_pos (zero_lt_of_lt hb)] at h have := ih len (fun a ha ↦ w1 a <| List.mem_cons_of_mem D ha) (fun a ha ↦ w2 a <| List.mem_cons_of_mem d ha) h rw [eqd, this] /-- The addition of ofDigits of two lists is equal to ofDigits of digit-wise addition of them -/ theorem ofDigits_add_ofDigits_eq_ofDigits_zipWith_of_length_eq {b : ℕ} {l1 l2 : List ℕ} (h : l1.length = l2.length) : ofDigits b l1 + ofDigits b l2 = ofDigits b (l1.zipWith (· + ·) l2) := by induction l1 generalizing l2 with | nil => simp_all [eq_comm, List.length_eq_zero_iff, ofDigits] | cons hd₁ tl₁ ih₁ => induction l2 generalizing tl₁ with | nil => simp_all | cons hd₂ tl₂ ih₂ => simp_all only [List.length_cons, succ_eq_add_one, ofDigits_cons, add_left_inj, eq_comm, List.zipWith_cons_cons, add_eq] rw [← ih₁ h.symm, mul_add] ac_rfl /-- The digits in the base b+2 expansion of n are all less than b+2 -/ theorem digits_lt_base' {b m : ℕ} : ∀ {d}, d ∈ digits (b + 2) m → d < b + 2 := by induction m using Nat.strongRecOn with | ind n IH => ?_ intro d hd rcases n with - | n · rw [digits_zero] at hd cases hd -- base b+2 expansion of 0 has no digits rw [digits_add_two_add_one] at hd cases hd · exact n.succ.mod_lt (by linarith) · apply IH ((n + 1) / (b + 2)) · apply Nat.div_lt_self <;> omega · assumption /-- The digits in the base b expansion of n are all less than b, if b ≥ 2 -/ theorem digits_lt_base {b m d : ℕ} (hb : 1 < b) (hd : d ∈ digits b m) : d < b := by rcases b with (_ | _ | b) <;> try simp_all exact digits_lt_base' hd /-- an n-digit number in base b + 2 is less than (b + 2)^n -/ theorem ofDigits_lt_base_pow_length' {b : ℕ} {l : List ℕ} (hl : ∀ x ∈ l, x < b + 2) : ofDigits (b + 2) l < (b + 2) ^ l.length := by induction' l with hd tl IH · simp [ofDigits] · rw [ofDigits, List.length_cons, pow_succ] have : (ofDigits (b + 2) tl + 1) * (b + 2) ≤ (b + 2) ^ tl.length * (b + 2) := mul_le_mul (IH fun x hx => hl _ (List.mem_cons_of_mem _ hx)) (by rfl) (by simp only [zero_le]) (Nat.zero_le _) suffices ↑hd < b + 2 by linarith exact hl hd List.mem_cons_self /-- an n-digit number in base b is less than b^n if b > 1 -/ theorem ofDigits_lt_base_pow_length {b : ℕ} {l : List ℕ} (hb : 1 < b) (hl : ∀ x ∈ l, x < b) : ofDigits b l < b ^ l.length := by rcases b with (_ | _ | b) <;> try simp_all exact ofDigits_lt_base_pow_length' hl /-- Any number m is less than (b+2)^(number of digits in the base b + 2 representation of m) -/ theorem lt_base_pow_length_digits' {b m : ℕ} : m < (b + 2) ^ (digits (b + 2) m).length := by convert @ofDigits_lt_base_pow_length' b (digits (b + 2) m) fun _ => digits_lt_base' rw [ofDigits_digits (b + 2) m] /-- Any number m is less than b^(number of digits in the base b representation of m) -/ theorem lt_base_pow_length_digits {b m : ℕ} (hb : 1 < b) : m < b ^ (digits b m).length := by rcases b with (_ | _ | b) <;> try simp_all exact lt_base_pow_length_digits' theorem digits_base_pow_mul {b k m : ℕ} (hb : 1 < b) (hm : 0 < m) : digits b (b ^ k * m) = List.replicate k 0 ++ digits b m := by induction k generalizing m with | zero => simp | succ k ih => have hmb : 0 < m * b := lt_mul_of_lt_of_one_lt' hm hb let h1 := digits_def' hb hmb have h2 : m = m * b / b := Nat.eq_div_of_mul_eq_left (ne_zero_of_lt hb) rfl simp only [mul_mod_left, ← h2] at h1 rw [List.replicate_succ', List.append_assoc, List.singleton_append, ← h1, ← ih hmb] ring_nf theorem ofDigits_digits_append_digits {b m n : ℕ} : ofDigits b (digits b n ++ digits b m) = n + b ^ (digits b n).length * m := by rw [ofDigits_append, ofDigits_digits, ofDigits_digits] theorem digits_append_digits {b m n : ℕ} (hb : 0 < b) : digits b n ++ digits b m = digits b (n + b ^ (digits b n).length * m) := by rcases eq_or_lt_of_le (Nat.succ_le_of_lt hb) with (rfl | hb) · simp rw [← ofDigits_digits_append_digits] refine (digits_ofDigits b hb _ (fun l hl => ?_) (fun h_append => ?_)).symm · rcases (List.mem_append.mp hl) with (h | h) <;> exact digits_lt_base hb h · by_cases h : digits b m = [] · simp only [h, List.append_nil] at h_append ⊢ exact getLast_digit_ne_zero b <| digits_ne_nil_iff_ne_zero.mp h_append · exact (List.getLast_append_of_right_ne_nil _ _ h) ▸ (getLast_digit_ne_zero _ <| digits_ne_nil_iff_ne_zero.mp h)
theorem digits_append_zeroes_append_digits {b k m n : ℕ} (hb : 1 < b) (hm : 0 < m) : digits b n ++ List.replicate k 0 ++ digits b m =
Mathlib/Data/Nat/Digits.lean
453
455
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.Data.Set.Function import Mathlib.Logic.Pairwise import Mathlib.Logic.Relation /-! # Relations holding pairwise This file develops pairwise relations and defines pairwise disjoint indexed sets. We also prove many basic facts about `Pairwise`. It is possible that an intermediate file, with more imports than `Logic.Pairwise` but not importing `Data.Set.Function` would be appropriate to hold many of these basic facts. ## Main declarations * `Set.PairwiseDisjoint`: `s.PairwiseDisjoint f` states that images under `f` of distinct elements of `s` are either equal or `Disjoint`. ## Notes The spelling `s.PairwiseDisjoint id` is preferred over `s.Pairwise Disjoint` to permit dot notation on `Set.PairwiseDisjoint`, even though the latter unfolds to something nicer. -/ open Function Order Set variable {α β γ ι ι' : Type*} {r p : α → α → Prop} section Pairwise variable {f g : ι → α} {s t : Set α} {a b : α} theorem pairwise_on_bool (hr : Symmetric r) {a b : α} : Pairwise (r on fun c => cond c a b) ↔ r a b := by simpa [Pairwise, Function.onFun] using @hr a b theorem pairwise_disjoint_on_bool [PartialOrder α] [OrderBot α] {a b : α} : Pairwise (Disjoint on fun c => cond c a b) ↔ Disjoint a b := pairwise_on_bool Disjoint.symm theorem Symmetric.pairwise_on [LinearOrder ι] (hr : Symmetric r) (f : ι → α) : Pairwise (r on f) ↔ ∀ ⦃m n⦄, m < n → r (f m) (f n) := ⟨fun h _m _n hmn => h hmn.ne, fun h _m _n hmn => hmn.lt_or_lt.elim (@h _ _) fun h' => hr (h h')⟩ theorem pairwise_disjoint_on [PartialOrder α] [OrderBot α] [LinearOrder ι] (f : ι → α) : Pairwise (Disjoint on f) ↔ ∀ ⦃m n⦄, m < n → Disjoint (f m) (f n) := Symmetric.pairwise_on Disjoint.symm f theorem pairwise_disjoint_mono [PartialOrder α] [OrderBot α] (hs : Pairwise (Disjoint on f)) (h : g ≤ f) : Pairwise (Disjoint on g) := hs.mono fun i j hij => Disjoint.mono (h i) (h j) hij theorem Pairwise.disjoint_extend_bot [PartialOrder γ] [OrderBot γ] {e : α → β} {f : α → γ} (hf : Pairwise (Disjoint on f)) (he : FactorsThrough f e) : Pairwise (Disjoint on extend e f ⊥) := by intro b₁ b₂ hne rcases em (∃ a₁, e a₁ = b₁) with ⟨a₁, rfl⟩ | hb₁ · rcases em (∃ a₂, e a₂ = b₂) with ⟨a₂, rfl⟩ | hb₂ · simpa only [onFun, he.extend_apply] using hf (ne_of_apply_ne e hne) · simpa only [onFun, extend_apply' _ _ _ hb₂] using disjoint_bot_right · simpa only [onFun, extend_apply' _ _ _ hb₁] using disjoint_bot_left namespace Set theorem Pairwise.mono (h : t ⊆ s) (hs : s.Pairwise r) : t.Pairwise r := fun _x xt _y yt => hs (h xt) (h yt) theorem Pairwise.mono' (H : r ≤ p) (hr : s.Pairwise r) : s.Pairwise p := hr.imp H theorem pairwise_top (s : Set α) : s.Pairwise ⊤ := pairwise_of_forall s _ fun _ _ => trivial protected theorem Subsingleton.pairwise (h : s.Subsingleton) (r : α → α → Prop) : s.Pairwise r := fun _x hx _y hy hne => (hne (h hx hy)).elim @[simp] theorem pairwise_empty (r : α → α → Prop) : (∅ : Set α).Pairwise r := subsingleton_empty.pairwise r @[simp] theorem pairwise_singleton (a : α) (r : α → α → Prop) : Set.Pairwise {a} r := subsingleton_singleton.pairwise r theorem pairwise_iff_of_refl [IsRefl α r] : s.Pairwise r ↔ ∀ ⦃a⦄, a ∈ s → ∀ ⦃b⦄, b ∈ s → r a b := forall₄_congr fun _ _ _ _ => or_iff_not_imp_left.symm.trans <| or_iff_right_of_imp of_eq alias ⟨Pairwise.of_refl, _⟩ := pairwise_iff_of_refl theorem Nonempty.pairwise_iff_exists_forall [IsEquiv α r] {s : Set ι} (hs : s.Nonempty) : s.Pairwise (r on f) ↔ ∃ z, ∀ x ∈ s, r (f x) z := by constructor · rcases hs with ⟨y, hy⟩ refine fun H => ⟨f y, fun x hx => ?_⟩ rcases eq_or_ne x y with (rfl | hne) · apply IsRefl.refl · exact H hx hy hne · rintro ⟨z, hz⟩ x hx y hy _ exact @IsTrans.trans α r _ (f x) z (f y) (hz _ hx) (IsSymm.symm _ _ <| hz _ hy) /-- For a nonempty set `s`, a function `f` takes pairwise equal values on `s` if and only if for some `z` in the codomain, `f` takes value `z` on all `x ∈ s`. See also `Set.pairwise_eq_iff_exists_eq` for a version that assumes `[Nonempty ι]` instead of `Set.Nonempty s`. -/ theorem Nonempty.pairwise_eq_iff_exists_eq {s : Set α} (hs : s.Nonempty) {f : α → ι} : (s.Pairwise fun x y => f x = f y) ↔ ∃ z, ∀ x ∈ s, f x = z := hs.pairwise_iff_exists_forall theorem pairwise_iff_exists_forall [Nonempty ι] (s : Set α) (f : α → ι) {r : ι → ι → Prop} [IsEquiv ι r] : s.Pairwise (r on f) ↔ ∃ z, ∀ x ∈ s, r (f x) z := by rcases s.eq_empty_or_nonempty with (rfl | hne) · simp · exact hne.pairwise_iff_exists_forall /-- A function `f : α → ι` with nonempty codomain takes pairwise equal values on a set `s` if and only if for some `z` in the codomain, `f` takes value `z` on all `x ∈ s`. See also `Set.Nonempty.pairwise_eq_iff_exists_eq` for a version that assumes `Set.Nonempty s` instead of `[Nonempty ι]`. -/ theorem pairwise_eq_iff_exists_eq [Nonempty ι] (s : Set α) (f : α → ι) : (s.Pairwise fun x y => f x = f y) ↔ ∃ z, ∀ x ∈ s, f x = z := pairwise_iff_exists_forall s f theorem pairwise_union : (s ∪ t).Pairwise r ↔ s.Pairwise r ∧ t.Pairwise r ∧ ∀ a ∈ s, ∀ b ∈ t, a ≠ b → r a b ∧ r b a := by simp only [Set.Pairwise, mem_union, or_imp, forall_and] aesop theorem pairwise_union_of_symmetric (hr : Symmetric r) : (s ∪ t).Pairwise r ↔ s.Pairwise r ∧ t.Pairwise r ∧ ∀ a ∈ s, ∀ b ∈ t, a ≠ b → r a b := pairwise_union.trans <| by simp only [hr.iff, and_self_iff] theorem pairwise_insert : (insert a s).Pairwise r ↔ s.Pairwise r ∧ ∀ b ∈ s, a ≠ b → r a b ∧ r b a := by simp only [insert_eq, pairwise_union, pairwise_singleton, true_and, mem_singleton_iff, forall_eq] theorem pairwise_insert_of_not_mem (ha : a ∉ s) : (insert a s).Pairwise r ↔ s.Pairwise r ∧ ∀ b ∈ s, r a b ∧ r b a := pairwise_insert.trans <| and_congr_right' <| forall₂_congr fun b hb => by simp [(ne_of_mem_of_not_mem hb ha).symm] protected theorem Pairwise.insert (hs : s.Pairwise r) (h : ∀ b ∈ s, a ≠ b → r a b ∧ r b a) : (insert a s).Pairwise r := pairwise_insert.2 ⟨hs, h⟩ theorem Pairwise.insert_of_not_mem (ha : a ∉ s) (hs : s.Pairwise r) (h : ∀ b ∈ s, r a b ∧ r b a) : (insert a s).Pairwise r := (pairwise_insert_of_not_mem ha).2 ⟨hs, h⟩ theorem pairwise_insert_of_symmetric (hr : Symmetric r) : (insert a s).Pairwise r ↔ s.Pairwise r ∧ ∀ b ∈ s, a ≠ b → r a b := by simp only [pairwise_insert, hr.iff a, and_self_iff] theorem pairwise_insert_of_symmetric_of_not_mem (hr : Symmetric r) (ha : a ∉ s) : (insert a s).Pairwise r ↔ s.Pairwise r ∧ ∀ b ∈ s, r a b := by simp only [pairwise_insert_of_not_mem ha, hr.iff a, and_self_iff] theorem Pairwise.insert_of_symmetric (hs : s.Pairwise r) (hr : Symmetric r) (h : ∀ b ∈ s, a ≠ b → r a b) : (insert a s).Pairwise r := (pairwise_insert_of_symmetric hr).2 ⟨hs, h⟩ @[deprecated Pairwise.insert_of_symmetric (since := "2025-03-19")] theorem Pairwise.insert_of_symmetric_of_not_mem (hs : s.Pairwise r) (hr : Symmetric r) (ha : a ∉ s) (h : ∀ b ∈ s, r a b) : (insert a s).Pairwise r := (pairwise_insert_of_symmetric_of_not_mem hr ha).2 ⟨hs, h⟩ theorem pairwise_pair : Set.Pairwise {a, b} r ↔ a ≠ b → r a b ∧ r b a := by simp [pairwise_insert] theorem pairwise_pair_of_symmetric (hr : Symmetric r) : Set.Pairwise {a, b} r ↔ a ≠ b → r a b := by simp [pairwise_insert_of_symmetric hr] theorem pairwise_univ : (univ : Set α).Pairwise r ↔ Pairwise r := by
simp only [Set.Pairwise, Pairwise, mem_univ, forall_const] @[simp]
Mathlib/Data/Set/Pairwise/Basic.lean
178
180
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash, Eric Wieser -/ import Mathlib.Topology.Algebra.InfiniteSum.Basic import Mathlib.Topology.Algebra.Ring.Basic import Mathlib.Topology.Algebra.Star import Mathlib.LinearAlgebra.Matrix.NonsingularInverse import Mathlib.LinearAlgebra.Matrix.Trace /-! # Topological properties of matrices This file is a place to collect topological results about matrices. ## Main definitions: * `Matrix.topologicalRing`: square matrices form a topological ring ## Main results * Continuity: * `Continuous.matrix_det`: the determinant is continuous over a topological ring. * `Continuous.matrix_adjugate`: the adjugate is continuous over a topological ring. * Infinite sums * `Matrix.transpose_tsum`: transpose commutes with infinite sums * `Matrix.diagonal_tsum`: diagonal commutes with infinite sums * `Matrix.blockDiagonal_tsum`: block diagonal commutes with infinite sums * `Matrix.blockDiagonal'_tsum`: non-uniform block diagonal commutes with infinite sums -/ open Matrix variable {X α l m n p S R : Type*} {m' n' : l → Type*} instance [TopologicalSpace R] : TopologicalSpace (Matrix m n R) := Pi.topologicalSpace instance [TopologicalSpace R] [T2Space R] : T2Space (Matrix m n R) := Pi.t2Space /-! ### Lemmas about continuity of operations -/ section Continuity variable [TopologicalSpace X] [TopologicalSpace R] instance [SMul α R] [ContinuousConstSMul α R] : ContinuousConstSMul α (Matrix m n R) := inferInstanceAs (ContinuousConstSMul α (m → n → R)) instance [TopologicalSpace α] [SMul α R] [ContinuousSMul α R] : ContinuousSMul α (Matrix m n R) := inferInstanceAs (ContinuousSMul α (m → n → R)) instance [Add R] [ContinuousAdd R] : ContinuousAdd (Matrix m n R) := Pi.continuousAdd instance [Neg R] [ContinuousNeg R] : ContinuousNeg (Matrix m n R) := Pi.continuousNeg instance [AddGroup R] [IsTopologicalAddGroup R] : IsTopologicalAddGroup (Matrix m n R) := Pi.topologicalAddGroup /-- To show a function into matrices is continuous it suffices to show the coefficients of the resulting matrix are continuous -/ @[continuity] theorem continuous_matrix [TopologicalSpace α] {f : α → Matrix m n R} (h : ∀ i j, Continuous fun a => f a i j) : Continuous f := continuous_pi fun _ => continuous_pi fun _ => h _ _ theorem Continuous.matrix_elem {A : X → Matrix m n R} (hA : Continuous A) (i : m) (j : n) : Continuous fun x => A x i j := (continuous_apply_apply i j).comp hA @[continuity, fun_prop] theorem Continuous.matrix_map [TopologicalSpace S] {A : X → Matrix m n S} {f : S → R} (hA : Continuous A) (hf : Continuous f) : Continuous fun x => (A x).map f := continuous_matrix fun _ _ => hf.comp <| hA.matrix_elem _ _ @[continuity, fun_prop] theorem Continuous.matrix_transpose {A : X → Matrix m n R} (hA : Continuous A) : Continuous fun x => (A x)ᵀ := continuous_matrix fun i j => hA.matrix_elem j i @[continuity, fun_prop] theorem Continuous.matrix_conjTranspose [Star R] [ContinuousStar R] {A : X → Matrix m n R} (hA : Continuous A) : Continuous fun x => (A x)ᴴ := hA.matrix_transpose.matrix_map continuous_star instance [Star R] [ContinuousStar R] : ContinuousStar (Matrix m m R) := ⟨continuous_id.matrix_conjTranspose⟩ @[continuity, fun_prop] theorem Continuous.matrix_replicateCol {ι : Type*} {A : X → n → R} (hA : Continuous A) : Continuous fun x => replicateCol ι (A x) := continuous_matrix fun i _ => (continuous_apply i).comp hA @[deprecated (since := "2025-03-15")] alias Continuous.matrix_col := Continuous.matrix_replicateCol @[continuity, fun_prop] theorem Continuous.matrix_replicateRow {ι : Type*} {A : X → n → R} (hA : Continuous A) : Continuous fun x => replicateRow ι (A x) := continuous_matrix fun _ _ => (continuous_apply _).comp hA @[deprecated (since := "2025-03-15")] alias Continuous.matrix_row := Continuous.matrix_replicateRow @[continuity, fun_prop] theorem Continuous.matrix_diagonal [Zero R] [DecidableEq n] {A : X → n → R} (hA : Continuous A) : Continuous fun x => diagonal (A x) := continuous_matrix fun i _ => ((continuous_apply i).comp hA).if_const _ continuous_zero @[continuity, fun_prop] theorem Continuous.matrix_dotProduct [Fintype n] [Mul R] [AddCommMonoid R] [ContinuousAdd R] [ContinuousMul R] {A : X → n → R} {B : X → n → R} (hA : Continuous A) (hB : Continuous B) : Continuous fun x => dotProduct (A x) (B x) := continuous_finset_sum _ fun i _ => ((continuous_apply i).comp hA).mul ((continuous_apply i).comp hB) /-- For square matrices the usual `continuous_mul` can be used. -/ @[continuity, fun_prop] theorem Continuous.matrix_mul [Fintype n] [Mul R] [AddCommMonoid R] [ContinuousAdd R] [ContinuousMul R] {A : X → Matrix m n R} {B : X → Matrix n p R} (hA : Continuous A) (hB : Continuous B) : Continuous fun x => A x * B x := continuous_matrix fun _ _ => continuous_finset_sum _ fun _ _ => (hA.matrix_elem _ _).mul (hB.matrix_elem _ _) instance [Fintype n] [Mul R] [AddCommMonoid R] [ContinuousAdd R] [ContinuousMul R] : ContinuousMul (Matrix n n R) := ⟨continuous_fst.matrix_mul continuous_snd⟩ instance [Fintype n] [NonUnitalNonAssocSemiring R] [IsTopologicalSemiring R] : IsTopologicalSemiring (Matrix n n R) where instance Matrix.topologicalRing [Fintype n] [NonUnitalNonAssocRing R] [IsTopologicalRing R] : IsTopologicalRing (Matrix n n R) where @[continuity, fun_prop] theorem Continuous.matrix_vecMulVec [Mul R] [ContinuousMul R] {A : X → m → R} {B : X → n → R} (hA : Continuous A) (hB : Continuous B) : Continuous fun x => vecMulVec (A x) (B x) := continuous_matrix fun _ _ => ((continuous_apply _).comp hA).mul ((continuous_apply _).comp hB) @[continuity, fun_prop] theorem Continuous.matrix_mulVec [NonUnitalNonAssocSemiring R] [ContinuousAdd R] [ContinuousMul R] [Fintype n] {A : X → Matrix m n R} {B : X → n → R} (hA : Continuous A) (hB : Continuous B) : Continuous fun x => A x *ᵥ B x := continuous_pi fun i => ((continuous_apply i).comp hA).matrix_dotProduct hB @[continuity, fun_prop] theorem Continuous.matrix_vecMul [NonUnitalNonAssocSemiring R] [ContinuousAdd R] [ContinuousMul R] [Fintype m] {A : X → m → R} {B : X → Matrix m n R} (hA : Continuous A) (hB : Continuous B) : Continuous fun x => A x ᵥ* B x := continuous_pi fun _i => hA.matrix_dotProduct <| continuous_pi fun _j => hB.matrix_elem _ _ @[continuity, fun_prop] theorem Continuous.matrix_submatrix {A : X → Matrix l n R} (hA : Continuous A) (e₁ : m → l) (e₂ : p → n) : Continuous fun x => (A x).submatrix e₁ e₂ := continuous_matrix fun _i _j => hA.matrix_elem _ _ @[continuity, fun_prop] theorem Continuous.matrix_reindex {A : X → Matrix l n R} (hA : Continuous A) (e₁ : l ≃ m) (e₂ : n ≃ p) : Continuous fun x => reindex e₁ e₂ (A x) := hA.matrix_submatrix _ _ @[continuity, fun_prop] theorem Continuous.matrix_diag {A : X → Matrix n n R} (hA : Continuous A) : Continuous fun x => Matrix.diag (A x) := continuous_pi fun _ => hA.matrix_elem _ _ -- note this doesn't elaborate well from the above theorem continuous_matrix_diag : Continuous (Matrix.diag : Matrix n n R → n → R) := show Continuous fun x : Matrix n n R => Matrix.diag x from continuous_id.matrix_diag @[continuity, fun_prop] theorem Continuous.matrix_trace [Fintype n] [AddCommMonoid R] [ContinuousAdd R] {A : X → Matrix n n R} (hA : Continuous A) : Continuous fun x => trace (A x) := continuous_finset_sum _ fun _ _ => hA.matrix_elem _ _ @[continuity, fun_prop] theorem Continuous.matrix_det [Fintype n] [DecidableEq n] [CommRing R] [IsTopologicalRing R] {A : X → Matrix n n R} (hA : Continuous A) : Continuous fun x => (A x).det := by simp_rw [Matrix.det_apply] refine continuous_finset_sum _ fun l _ => Continuous.const_smul ?_ _ exact continuous_finset_prod _ fun l _ => hA.matrix_elem _ _ @[continuity, fun_prop] theorem Continuous.matrix_updateCol [DecidableEq n] (i : n) {A : X → Matrix m n R} {B : X → m → R} (hA : Continuous A) (hB : Continuous B) : Continuous fun x => (A x).updateCol i (B x) := continuous_matrix fun _j k => (continuous_apply k).comp <| ((continuous_apply _).comp hA).update i ((continuous_apply _).comp hB) @[deprecated (since := "2024-12-11")] alias Continuous.matrix_updateColumn := Continuous.matrix_updateCol @[continuity, fun_prop] theorem Continuous.matrix_updateRow [DecidableEq m] (i : m) {A : X → Matrix m n R} {B : X → n → R} (hA : Continuous A) (hB : Continuous B) : Continuous fun x => (A x).updateRow i (B x) := hA.update i hB @[continuity, fun_prop] theorem Continuous.matrix_cramer [Fintype n] [DecidableEq n] [CommRing R] [IsTopologicalRing R] {A : X → Matrix n n R} {B : X → n → R} (hA : Continuous A) (hB : Continuous B) : Continuous fun x => cramer (A x) (B x) := continuous_pi fun _ => (hA.matrix_updateCol _ hB).matrix_det @[continuity, fun_prop] theorem Continuous.matrix_adjugate [Fintype n] [DecidableEq n] [CommRing R] [IsTopologicalRing R] {A : X → Matrix n n R} (hA : Continuous A) : Continuous fun x => (A x).adjugate := continuous_matrix fun _j k => (hA.matrix_transpose.matrix_updateCol k continuous_const).matrix_det /-- When `Ring.inverse` is continuous at the determinant (such as in a `NormedRing`, or a topological field), so is `Matrix.inv`. -/ theorem continuousAt_matrix_inv [Fintype n] [DecidableEq n] [CommRing R] [IsTopologicalRing R] (A : Matrix n n R) (h : ContinuousAt Ring.inverse A.det) : ContinuousAt Inv.inv A := (h.comp continuous_id.matrix_det.continuousAt).smul continuous_id.matrix_adjugate.continuousAt -- lemmas about functions in `Data/Matrix/Block.lean` section BlockMatrices @[continuity, fun_prop] theorem Continuous.matrix_fromBlocks {A : X → Matrix n l R} {B : X → Matrix n m R} {C : X → Matrix p l R} {D : X → Matrix p m R} (hA : Continuous A) (hB : Continuous B) (hC : Continuous C) (hD : Continuous D) : Continuous fun x => Matrix.fromBlocks (A x) (B x) (C x) (D x) := continuous_matrix <| by rintro (i | i) (j | j) <;> refine Continuous.matrix_elem ?_ i j <;> assumption @[continuity, fun_prop] theorem Continuous.matrix_blockDiagonal [Zero R] [DecidableEq p] {A : X → p → Matrix m n R} (hA : Continuous A) : Continuous fun x => blockDiagonal (A x) := continuous_matrix fun ⟨i₁, i₂⟩ ⟨j₁, _j₂⟩ => (((continuous_apply i₂).comp hA).matrix_elem i₁ j₁).if_const _ continuous_zero @[continuity, fun_prop] theorem Continuous.matrix_blockDiag {A : X → Matrix (m × p) (n × p) R} (hA : Continuous A) : Continuous fun x => blockDiag (A x) := continuous_pi fun _i => continuous_matrix fun _j _k => hA.matrix_elem _ _ @[continuity, fun_prop] theorem Continuous.matrix_blockDiagonal' [Zero R] [DecidableEq l] {A : X → ∀ i, Matrix (m' i) (n' i) R} (hA : Continuous A) : Continuous fun x => blockDiagonal' (A x) := continuous_matrix fun ⟨i₁, i₂⟩ ⟨j₁, j₂⟩ => by dsimp only [blockDiagonal'_apply'] split_ifs with h · subst h exact ((continuous_apply i₁).comp hA).matrix_elem i₂ j₂ · exact continuous_const @[continuity, fun_prop] theorem Continuous.matrix_blockDiag' {A : X → Matrix (Σ i, m' i) (Σ i, n' i) R} (hA : Continuous A) : Continuous fun x => blockDiag' (A x) := continuous_pi fun _i => continuous_matrix fun _j _k => hA.matrix_elem _ _ end BlockMatrices end Continuity /-! ### Lemmas about infinite sums -/ section tsum variable [AddCommMonoid R] [TopologicalSpace R] theorem HasSum.matrix_transpose {f : X → Matrix m n R} {a : Matrix m n R} (hf : HasSum f a) : HasSum (fun x => (f x)ᵀ) aᵀ := (hf.map (Matrix.transposeAddEquiv m n R) continuous_id.matrix_transpose :) theorem Summable.matrix_transpose {f : X → Matrix m n R} (hf : Summable f) : Summable fun x => (f x)ᵀ := hf.hasSum.matrix_transpose.summable @[simp] theorem summable_matrix_transpose {f : X → Matrix m n R} : (Summable fun x => (f x)ᵀ) ↔ Summable f := Summable.map_iff_of_equiv (Matrix.transposeAddEquiv m n R) continuous_id.matrix_transpose continuous_id.matrix_transpose theorem Matrix.transpose_tsum [T2Space R] {f : X → Matrix m n R} : (∑' x, f x)ᵀ = ∑' x, (f x)ᵀ := by by_cases hf : Summable f · exact hf.hasSum.matrix_transpose.tsum_eq.symm · have hft := summable_matrix_transpose.not.mpr hf rw [tsum_eq_zero_of_not_summable hf, tsum_eq_zero_of_not_summable hft, transpose_zero] theorem HasSum.matrix_conjTranspose [StarAddMonoid R] [ContinuousStar R] {f : X → Matrix m n R} {a : Matrix m n R} (hf : HasSum f a) : HasSum (fun x => (f x)ᴴ) aᴴ := (hf.map (Matrix.conjTransposeAddEquiv m n R) continuous_id.matrix_conjTranspose :) theorem Summable.matrix_conjTranspose [StarAddMonoid R] [ContinuousStar R] {f : X → Matrix m n R} (hf : Summable f) : Summable fun x => (f x)ᴴ := hf.hasSum.matrix_conjTranspose.summable @[simp] theorem summable_matrix_conjTranspose [StarAddMonoid R] [ContinuousStar R] {f : X → Matrix m n R} : (Summable fun x => (f x)ᴴ) ↔ Summable f := Summable.map_iff_of_equiv (Matrix.conjTransposeAddEquiv m n R) continuous_id.matrix_conjTranspose continuous_id.matrix_conjTranspose theorem Matrix.conjTranspose_tsum [StarAddMonoid R] [ContinuousStar R] [T2Space R] {f : X → Matrix m n R} : (∑' x, f x)ᴴ = ∑' x, (f x)ᴴ := by by_cases hf : Summable f · exact hf.hasSum.matrix_conjTranspose.tsum_eq.symm · have hft := summable_matrix_conjTranspose.not.mpr hf rw [tsum_eq_zero_of_not_summable hf, tsum_eq_zero_of_not_summable hft, conjTranspose_zero] theorem HasSum.matrix_diagonal [DecidableEq n] {f : X → n → R} {a : n → R} (hf : HasSum f a) : HasSum (fun x => diagonal (f x)) (diagonal a) := hf.map (diagonalAddMonoidHom n R) continuous_id.matrix_diagonal theorem Summable.matrix_diagonal [DecidableEq n] {f : X → n → R} (hf : Summable f) : Summable fun x => diagonal (f x) := hf.hasSum.matrix_diagonal.summable @[simp] theorem summable_matrix_diagonal [DecidableEq n] {f : X → n → R} : (Summable fun x => diagonal (f x)) ↔ Summable f := Summable.map_iff_of_leftInverse (Matrix.diagonalAddMonoidHom n R) (Matrix.diagAddMonoidHom n R) continuous_id.matrix_diagonal continuous_matrix_diag fun A => diag_diagonal A theorem Matrix.diagonal_tsum [DecidableEq n] [T2Space R] {f : X → n → R} : diagonal (∑' x, f x) = ∑' x, diagonal (f x) := by by_cases hf : Summable f · exact hf.hasSum.matrix_diagonal.tsum_eq.symm · have hft := summable_matrix_diagonal.not.mpr hf rw [tsum_eq_zero_of_not_summable hf, tsum_eq_zero_of_not_summable hft] exact diagonal_zero theorem HasSum.matrix_diag {f : X → Matrix n n R} {a : Matrix n n R} (hf : HasSum f a) :
HasSum (fun x => diag (f x)) (diag a) := hf.map (diagAddMonoidHom n R) continuous_matrix_diag theorem Summable.matrix_diag {f : X → Matrix n n R} (hf : Summable f) : Summable fun x => diag (f x) := hf.hasSum.matrix_diag.summable
Mathlib/Topology/Instances/Matrix.lean
334
339
/- Copyright (c) 2021 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Riccardo Brasca -/ import Mathlib.Analysis.Normed.Module.Basic import Mathlib.Analysis.Normed.Group.Hom import Mathlib.RingTheory.Ideal.Quotient.Operations import Mathlib.Topology.MetricSpace.HausdorffDistance /-! # Quotients of seminormed groups For any `SeminormedAddCommGroup M` and any `S : AddSubgroup M`, we provide a `SeminormedAddCommGroup`, the group quotient `M ⧸ S`. If `S` is closed, we provide `NormedAddCommGroup (M ⧸ S)` (regardless of whether `M` itself is separated). The two main properties of these structures are the underlying topology is the quotient topology and the projection is a normed group homomorphism which is norm non-increasing (better, it has operator norm exactly one unless `S` is dense in `M`). The corresponding universal property is that every normed group hom defined on `M` which vanishes on `S` descends to a normed group hom defined on `M ⧸ S`. This file also introduces a predicate `IsQuotient` characterizing normed group homs that are isomorphic to the canonical projection onto a normed group quotient. In addition, this file also provides normed structures for quotients of modules by submodules, and of (commutative) rings by ideals. The `SeminormedAddCommGroup` and `NormedAddCommGroup` instances described above are transferred directly, but we also define instances of `NormedSpace`, `SeminormedCommRing`, `NormedCommRing` and `NormedAlgebra` under appropriate type class assumptions on the original space. Moreover, while `QuotientAddGroup.completeSpace` works out-of-the-box for quotients of `NormedAddCommGroup`s by `AddSubgroup`s, we need to transfer this instance in `Submodule.Quotient.completeSpace` so that it applies to these other quotients. ## Main definitions We use `M` and `N` to denote seminormed groups and `S : AddSubgroup M`. All the following definitions are in the `AddSubgroup` namespace. Hence we can access `AddSubgroup.normedMk S` as `S.normedMk`. * `seminormedAddCommGroupQuotient` : The seminormed group structure on the quotient by an additive subgroup. This is an instance so there is no need to explicitly use it. * `normedAddCommGroupQuotient` : The normed group structure on the quotient by a closed additive subgroup. This is an instance so there is no need to explicitly use it. * `normedMk S` : the normed group hom from `M` to `M ⧸ S`. * `lift S f hf`: implements the universal property of `M ⧸ S`. Here `(f : NormedAddGroupHom M N)`, `(hf : ∀ s ∈ S, f s = 0)` and `lift S f hf : NormedAddGroupHom (M ⧸ S) N`. * `IsQuotient`: given `f : NormedAddGroupHom M N`, `IsQuotient f` means `N` is isomorphic to a quotient of `M` by a subgroup, with projection `f`. Technically it asserts `f` is surjective and the norm of `f x` is the infimum of the norms of `x + m` for `m` in `f.ker`. ## Main results * `norm_normedMk` : the operator norm of the projection is `1` if the subspace is not dense. * `IsQuotient.norm_lift`: Provided `f : normed_hom M N` satisfies `IsQuotient f`, for every `n : N` and positive `ε`, there exists `m` such that `f m = n ∧ ‖m‖ < ‖n‖ + ε`. ## Implementation details For any `SeminormedAddCommGroup M` and any `S : AddSubgroup M` we define a norm on `M ⧸ S` by `‖x‖ = sInf (norm '' {m | mk' S m = x})`. This formula is really an implementation detail, it shouldn't be needed outside of this file setting up the theory. Since `M ⧸ S` is automatically a topological space (as any quotient of a topological space), one needs to be careful while defining the `SeminormedAddCommGroup` instance to avoid having two different topologies on this quotient. This is not purely a technological issue. Mathematically there is something to prove. The main point is proved in the auxiliary lemma `quotient_nhd_basis` that has no use beyond this verification and states that zero in the quotient admits as basis of neighborhoods in the quotient topology the sets `{x | ‖x‖ < ε}` for positive `ε`. Once this mathematical point is settled, we have two topologies that are propositionally equal. This is not good enough for the type class system. As usual we ensure *definitional* equality using forgetful inheritance, see Note [forgetful inheritance]. A (semi)-normed group structure includes a uniform space structure which includes a topological space structure, together with propositional fields asserting compatibility conditions. The usual way to define a `SeminormedAddCommGroup` is to let Lean build a uniform space structure using the provided norm, and then trivially build a proof that the norm and uniform structure are compatible. Here the uniform structure is provided using `IsTopologicalAddGroup.toUniformSpace` which uses the topological structure and the group structure to build the uniform structure. This uniform structure induces the correct topological structure by construction, but the fact that it is compatible with the norm is not obvious; this is where the mathematical content explained in the previous paragraph kicks in. -/ noncomputable section open Metric Set Topology NNReal namespace QuotientGroup variable {M : Type*} [SeminormedCommGroup M] {S : Subgroup M} {x : M ⧸ S} {m : M} {r ε : ℝ} @[to_additive add_norm_aux] private lemma norm_aux (x : M ⧸ S) : {m : M | (m : M ⧸ S) = x}.Nonempty := Quot.exists_rep x /-- The norm of `x` on the quotient by a subgroup `S` is defined as the infimum of the norm on `x * M`. -/ @[to_additive "The norm of `x` on the quotient by a subgroup `S` is defined as the infimum of the norm on `x + S`."] noncomputable def groupSeminorm : GroupSeminorm (M ⧸ S) where toFun x := infDist 1 {m : M | (m : M ⧸ S) = x} map_one' := infDist_zero_of_mem (by simpa using S.one_mem) mul_le' x y := by simp only [infDist_eq_iInf] have := (norm_aux x).to_subtype have := (norm_aux y).to_subtype refine le_ciInf_add_ciInf ?_ rintro ⟨a, rfl⟩ ⟨b, rfl⟩ refine ciInf_le_of_le ⟨0, forall_mem_range.2 fun _ ↦ dist_nonneg⟩ ⟨a * b, rfl⟩ ?_ simpa using norm_mul_le' _ _ inv' x := eq_of_forall_le_iff fun r ↦ by simp only [le_infDist (norm_aux _)] exact (Equiv.inv _).forall_congr (by simp [← inv_eq_iff_eq_inv]) /-- The norm of `x` on the quotient by a subgroup `S` is defined as the infimum of the norm on `x * S`. -/ @[to_additive "The norm of `x` on the quotient by a subgroup `S` is defined as the infimum of the norm on `x + S`."] noncomputable instance instNorm : Norm (M ⧸ S) where norm := groupSeminorm @[to_additive] lemma norm_eq_groupSeminorm (x : M ⧸ S) : ‖x‖ = groupSeminorm x := rfl @[to_additive] lemma norm_eq_infDist (x : M ⧸ S) : ‖x‖ = infDist 1 {m : M | (m : M ⧸ S) = x} := rfl @[to_additive] lemma le_norm_iff : r ≤ ‖x‖ ↔ ∀ m : M, ↑m = x → r ≤ ‖m‖ := by simp [norm_eq_infDist, le_infDist (norm_aux _)] @[to_additive] lemma norm_lt_iff : ‖x‖ < r ↔ ∃ m : M, ↑m = x ∧ ‖m‖ < r := by simp [norm_eq_infDist, infDist_lt_iff (norm_aux _)] @[to_additive] lemma nhds_one_hasBasis : (𝓝 (1 : M ⧸ S)).HasBasis (fun ε ↦ 0 < ε) fun ε ↦ {x | ‖x‖ < ε} := by have : ∀ ε : ℝ, mk '' ball (1 : M) ε = {x : M ⧸ S | ‖x‖ < ε} := by refine fun ε ↦ Set.ext <| forall_mk.2 fun x ↦ ?_ rw [ball_one_eq, mem_setOf_eq, norm_lt_iff, mem_image] exact exists_congr fun _ ↦ and_comm rw [← mk_one, nhds_eq, ← funext this] exact .map _ Metric.nhds_basis_ball /-- An alternative definition of the norm on the quotient group: the norm of `((x : M) : M ⧸ S)` is equal to the distance from `x` to `S`. -/ @[to_additive "An alternative definition of the norm on the quotient group: the norm of `((x : M) : M ⧸ S)` is equal to the distance from `x` to `S`."] lemma norm_mk (x : M) : ‖(x : M ⧸ S)‖ = infDist x S := by rw [norm_eq_infDist, ← infDist_image (IsometryEquiv.divLeft x).isometry, ← IsometryEquiv.preimage_symm] simp /-- The norm of the projection is smaller or equal to the norm of the original element. -/ @[to_additive "The norm of the projection is smaller or equal to the norm of the original element."] lemma norm_mk_le_norm : ‖(m : M ⧸ S)‖ ≤ ‖m‖ := (infDist_le_dist_of_mem (by simp)).trans_eq (dist_one_left _) /-- The norm of the image of `m : M` in the quotient by `S` is zero if and only if `m` belongs to the closure of `S`. -/ @[to_additive "The norm of the image of `m : M` in the quotient by `S` is zero if and only if `m` belongs to the closure of `S`."] lemma norm_mk_eq_zero_iff_mem_closure : ‖(m : M ⧸ S)‖ = 0 ↔ m ∈ closure (S : Set M) := by rw [norm_mk, ← mem_closure_iff_infDist_zero] exact ⟨1, S.one_mem⟩ /-- The norm of the image of `m : M` in the quotient by a closed subgroup `S` is zero if and only if `m ∈ S`. -/ @[to_additive "The norm of the image of `m : M` in the quotient by a closed subgroup `S` is zero if and only if `m ∈ S`."] lemma norm_mk_eq_zero [hS : IsClosed (S : Set M)] : ‖(m : M ⧸ S)‖ = 0 ↔ m ∈ S := by rw [norm_mk_eq_zero_iff_mem_closure, hS.closure_eq, SetLike.mem_coe] /-- For any `x : M ⧸ S` and any `0 < ε`, there is `m : M` such that `mk' S m = x` and `‖m‖ < ‖x‖ + ε`. -/ @[to_additive "For any `x : M ⧸ S` and any `0 < ε`, there is `m : M` such that `mk' S m = x` and `‖m‖ < ‖x‖ + ε`."] lemma exists_norm_mk_lt (x : M ⧸ S) (hε : 0 < ε) : ∃ m : M, m = x ∧ ‖m‖ < ‖x‖ + ε := norm_lt_iff.1 <| lt_add_of_pos_right _ hε /-- For any `m : M` and any `0 < ε`, there is `s ∈ S` such that `‖m * s‖ < ‖mk' S m‖ + ε`. -/ @[to_additive "For any `m : M` and any `0 < ε`, there is `s ∈ S` such that `‖m + s‖ < ‖mk' S m‖ + ε`."] lemma exists_norm_mul_lt (S : Subgroup M) (m : M) {ε : ℝ} (hε : 0 < ε) : ∃ s ∈ S, ‖m * s‖ < ‖mk' S m‖ + ε := by obtain ⟨n : M, hn, hn'⟩ := exists_norm_mk_lt (QuotientGroup.mk' S m) hε exact ⟨m⁻¹ * n, by simpa [eq_comm, QuotientGroup.eq] using hn, by simpa⟩ variable (S) in /-- The seminormed group structure on the quotient by a subgroup. -/ @[to_additive "The seminormed group structure on the quotient by an additive subgroup."] noncomputable instance instSeminormedCommGroup : SeminormedCommGroup (M ⧸ S) where toUniformSpace := IsTopologicalGroup.toUniformSpace (M ⧸ S) __ := groupSeminorm.toSeminormedCommGroup uniformity_dist := by rw [uniformity_eq_comap_nhds_one', (nhds_one_hasBasis.comap _).eq_biInf] simp only [dist, preimage_setOf_eq, norm_eq_groupSeminorm, map_div_rev] variable (S) in /-- The quotient in the category of normed groups. -/ @[to_additive "The quotient in the category of normed groups."] noncomputable instance instNormedCommGroup [hS : IsClosed (S : Set M)] : NormedCommGroup (M ⧸ S) where __ := MetricSpace.ofT0PseudoMetricSpace _ -- This is a sanity check left here on purpose to ensure that potential refactors won't destroy -- this important property. example : (instTopologicalSpaceQuotient : TopologicalSpace <| M ⧸ S) = (instSeminormedCommGroup S).toUniformSpace.toTopologicalSpace := rfl example [IsClosed (S : Set M)] : (instSeminormedCommGroup S) = NormedCommGroup.toSeminormedCommGroup := rfl end QuotientGroup open QuotientAddGroup Metric Set Topology NNReal variable {M N : Type*} [SeminormedAddCommGroup M] [SeminormedAddCommGroup N] /-- The definition of the norm on the quotient by an additive subgroup. -/ @[deprecated QuotientAddGroup.instNorm (since := "2025-02-02")] noncomputable def normOnQuotient (S : AddSubgroup M) : Norm (M ⧸ S) := inferInstance @[deprecated QuotientAddGroup.norm_eq_infDist (since := "2025-02-02")] theorem AddSubgroup.quotient_norm_eq {S : AddSubgroup M} (x : M ⧸ S) : ‖x‖ = sInf (norm '' { m : M | (m : M ⧸ S) = x }) := by simp only [norm_eq_infDist, infDist_eq_iInf, sInf_image', dist_zero_left] @[deprecated "Replaced by a private lemma" (since := "2025-02-02")] theorem image_norm_nonempty {S : AddSubgroup M} (x : M ⧸ S) : (norm '' { m | mk' S m = x }).Nonempty := .image _ <| Quot.exists_rep x @[deprecated norm_nonneg (since := "2025-02-02")] theorem bddBelow_image_norm (s : Set M) : BddBelow (norm '' s) := ⟨0, forall_mem_image.2 fun _ _ ↦ norm_nonneg _⟩ @[deprecated isGLB_infDist (since := "2025-02-02")] theorem isGLB_quotient_norm {S : AddSubgroup M} (x : M ⧸ S) : IsGLB (norm '' { m | mk' S m = x }) (‖x‖) := by simpa using isGLB_infDist (QuotientGroup.add_norm_aux x) (x := 0) /-- The norm on the quotient satisfies `‖-x‖ = ‖x‖`. -/ @[deprecated norm_neg (since := "2025-02-02")] theorem quotient_norm_neg {S : AddSubgroup M} (x : M ⧸ S) : ‖-x‖ = ‖x‖ := norm_neg _ @[deprecated norm_sub_rev (since := "2025-02-02")] theorem quotient_norm_sub_rev {S : AddSubgroup M} (x y : M ⧸ S) : ‖x - y‖ = ‖y - x‖ := norm_sub_rev .. /-- The norm of the projection is smaller or equal to the norm of the original element. -/ @[deprecated QuotientAddGroup.norm_mk_le_norm (since := "2025-02-02")] theorem quotient_norm_mk_le (S : AddSubgroup M) (m : M) : ‖mk' S m‖ ≤ ‖m‖ := norm_mk_le_norm /-- The norm of the projection is smaller or equal to the norm of the original element. -/ @[deprecated QuotientAddGroup.norm_mk_le_norm (since := "2025-02-02")] theorem quotient_norm_mk_le' (S : AddSubgroup M) (m : M) : ‖(m : M ⧸ S)‖ ≤ ‖m‖ := norm_mk_le_norm /-- The norm of the image under the natural morphism to the quotient. -/ theorem quotient_norm_mk_eq (S : AddSubgroup M) (m : M) : ‖mk' S m‖ = sInf ((‖m + ·‖) '' S) := by rw [mk'_apply, norm_mk, sInf_image', ← infDist_image isometry_neg, image_neg_eq_neg, neg_coe_set (H := S), infDist_eq_iInf] simp only [dist_eq_norm', sub_neg_eq_add, add_comm] /-- The quotient norm is nonnegative. -/ @[deprecated norm_nonneg (since := "2025-02-02")] theorem quotient_norm_nonneg (S : AddSubgroup M) (x : M ⧸ S) : 0 ≤ ‖x‖ := norm_nonneg _ /-- The quotient norm is nonnegative. -/ @[deprecated norm_nonneg (since := "2025-02-02")] theorem norm_mk_nonneg (S : AddSubgroup M) (m : M) : 0 ≤ ‖mk' S m‖ := norm_nonneg _ /-- The norm of the image of `m : M` in the quotient by `S` is zero if and only if `m` belongs to the closure of `S`. -/ @[deprecated QuotientAddGroup.norm_mk_eq_zero_iff_mem_closure (since := "2025-02-02")] theorem quotient_norm_eq_zero_iff (S : AddSubgroup M) (m : M) : ‖mk' S m‖ = 0 ↔ m ∈ closure (S : Set M) := norm_mk_eq_zero_iff_mem_closure /-- For any `x : M ⧸ S` and any `0 < ε`, there is `m : M` such that `mk' S m = x` and `‖m‖ < ‖x‖ + ε`. -/ @[deprecated QuotientAddGroup.exists_norm_mk_lt (since := "2025-02-02")] theorem norm_mk_lt {S : AddSubgroup M} (x : M ⧸ S) {ε : ℝ} (hε : 0 < ε) : ∃ m : M, mk' S m = x ∧ ‖m‖ < ‖x‖ + ε := exists_norm_mk_lt _ hε /-- For any `m : M` and any `0 < ε`, there is `s ∈ S` such that `‖m + s‖ < ‖mk' S m‖ + ε`. -/ @[deprecated QuotientAddGroup.exists_norm_add_lt (since := "2025-02-02")] theorem norm_mk_lt' (S : AddSubgroup M) (m : M) {ε : ℝ} (hε : 0 < ε) : ∃ s ∈ S, ‖m + s‖ < ‖mk' S m‖ + ε := exists_norm_add_lt _ _ hε /-- The quotient norm satisfies the triangle inequality. -/ theorem quotient_norm_add_le (S : AddSubgroup M) (x y : M ⧸ S) : ‖x + y‖ ≤ ‖x‖ + ‖y‖ := by rcases And.intro (mk_surjective x) (mk_surjective y) with ⟨⟨x, rfl⟩, ⟨y, rfl⟩⟩ simp only [← mk'_apply, ← map_add, quotient_norm_mk_eq, sInf_image'] refine le_ciInf_add_ciInf fun a b ↦ ?_ refine ciInf_le_of_le ⟨0, forall_mem_range.2 fun _ ↦ norm_nonneg _⟩ (a + b) ?_ exact (congr_arg norm (add_add_add_comm _ _ _ _)).trans_le (norm_add_le _ _) /-- The quotient norm of `0` is `0`. -/ @[deprecated norm_zero (since := "2025-02-02")] theorem norm_mk_zero (S : AddSubgroup M) : ‖(0 : M ⧸ S)‖ = 0 := norm_zero /-- If `(m : M)` has norm equal to `0` in `M ⧸ S` for a closed subgroup `S` of `M`, then `m ∈ S`. -/ @[deprecated QuotientAddGroup.norm_mk_eq_zero (since := "2025-02-02")] theorem norm_mk_eq_zero (S : AddSubgroup M) (hS : IsClosed (S : Set M)) (m : M) (h : ‖mk' S m‖ = 0) : m ∈ S := QuotientAddGroup.norm_mk_eq_zero.1 h @[deprecated QuotientAddGroup.nhds_zero_hasBasis (since := "2025-02-02")] theorem quotient_nhd_basis (S : AddSubgroup M) : (𝓝 (0 : M ⧸ S)).HasBasis (fun ε ↦ 0 < ε) fun ε ↦ { x | ‖x‖ < ε } := nhds_zero_hasBasis /-- The seminormed group structure on the quotient by an additive subgroup. -/ @[deprecated QuotientAddGroup.instSeminormedAddCommGroup (since := "2025-02-02")] noncomputable def AddSubgroup.seminormedAddCommGroupQuotient (S : AddSubgroup M) : SeminormedAddCommGroup (M ⧸ S) := inferInstance /-- The quotient in the category of normed groups. -/ @[deprecated QuotientAddGroup.instNormedAddCommGroup (since := "2025-02-02")] noncomputable instance AddSubgroup.normedAddCommGroupQuotient (S : AddSubgroup M) [IsClosed (S : Set M)] : NormedAddCommGroup (M ⧸ S) := inferInstance namespace AddSubgroup open NormedAddGroupHom /-- The morphism from a seminormed group to the quotient by a subgroup. -/ noncomputable def normedMk (S : AddSubgroup M) : NormedAddGroupHom M (M ⧸ S) where __ := QuotientAddGroup.mk' S bound' := ⟨1, fun m => by simpa [one_mul] using norm_mk_le_norm⟩ /-- `S.normedMk` agrees with `QuotientAddGroup.mk' S`. -/ @[simp] theorem normedMk.apply (S : AddSubgroup M) (m : M) : normedMk S m = QuotientAddGroup.mk' S m := rfl /-- `S.normedMk` is surjective. -/ theorem surjective_normedMk (S : AddSubgroup M) : Function.Surjective (normedMk S) := Quot.mk_surjective /-- The kernel of `S.normedMk` is `S`. -/ theorem ker_normedMk (S : AddSubgroup M) : S.normedMk.ker = S := QuotientAddGroup.ker_mk' _ /-- The operator norm of the projection is at most `1`. -/ theorem norm_normedMk_le (S : AddSubgroup M) : ‖S.normedMk‖ ≤ 1 := NormedAddGroupHom.opNorm_le_bound _ zero_le_one fun m => by simp [norm_mk_le_norm] theorem _root_.QuotientAddGroup.norm_lift_apply_le {S : AddSubgroup M} (f : NormedAddGroupHom M N) (hf : ∀ x ∈ S, f x = 0) (x : M ⧸ S) : ‖lift S f.toAddMonoidHom hf x‖ ≤ ‖f‖ * ‖x‖ := by cases (norm_nonneg f).eq_or_gt with | inl h => rcases mk_surjective x with ⟨x, rfl⟩ simpa [h] using le_opNorm f x | inr h => rw [← not_lt, ← lt_div_iff₀' h, norm_lt_iff] rintro ⟨x, rfl, hx⟩ exact ((lt_div_iff₀' h).1 hx).not_le (le_opNorm f x) /-- The operator norm of the projection is `1` if the subspace is not dense. -/ theorem norm_normedMk (S : AddSubgroup M) (h : (S.topologicalClosure : Set M) ≠ univ) : ‖S.normedMk‖ = 1 := by refine le_antisymm (norm_normedMk_le S) ?_ obtain ⟨x, hx⟩ : ∃ x : M, 0 < ‖(x : M ⧸ S)‖ := by refine (Set.nonempty_compl.2 h).imp fun x hx ↦ ?_ exact (norm_nonneg _).lt_of_ne' <| mt norm_mk_eq_zero_iff_mem_closure.1 hx refine (le_mul_iff_one_le_left hx).1 ?_ exact norm_lift_apply_le S.normedMk (fun x ↦ (eq_zero_iff x).2) x /-- The operator norm of the projection is `0` if the subspace is dense. -/ theorem norm_trivial_quotient_mk (S : AddSubgroup M) (h : (S.topologicalClosure : Set M) = Set.univ) : ‖S.normedMk‖ = 0 := by refine le_antisymm (opNorm_le_bound _ le_rfl fun x => ?_) (norm_nonneg _) have hker : x ∈ S.normedMk.ker.topologicalClosure := by rw [S.ker_normedMk, ← SetLike.mem_coe, h] trivial rw [ker_normedMk] at hker simp [norm_mk_eq_zero_iff_mem_closure.mpr hker] end AddSubgroup namespace NormedAddGroupHom /-- `IsQuotient f`, for `f : M ⟶ N` means that `N` is isomorphic to the quotient of `M` by the kernel of `f`. -/ structure IsQuotient (f : NormedAddGroupHom M N) : Prop where protected surjective : Function.Surjective f protected norm : ∀ x, ‖f x‖ = sInf ((fun m => ‖x + m‖) '' f.ker) /-- Given `f : NormedAddGroupHom M N` such that `f s = 0` for all `s ∈ S`, where, `S : AddSubgroup M` is closed, the induced morphism `NormedAddGroupHom (M ⧸ S) N`. -/ noncomputable def lift {N : Type*} [SeminormedAddCommGroup N] (S : AddSubgroup M) (f : NormedAddGroupHom M N) (hf : ∀ s ∈ S, f s = 0) : NormedAddGroupHom (M ⧸ S) N := { QuotientAddGroup.lift S f.toAddMonoidHom hf with bound' := ⟨‖f‖, norm_lift_apply_le f hf⟩ } theorem lift_mk {N : Type*} [SeminormedAddCommGroup N] (S : AddSubgroup M) (f : NormedAddGroupHom M N) (hf : ∀ s ∈ S, f s = 0) (m : M) : lift S f hf (S.normedMk m) = f m := rfl
theorem lift_unique {N : Type*} [SeminormedAddCommGroup N] (S : AddSubgroup M) (f : NormedAddGroupHom M N) (hf : ∀ s ∈ S, f s = 0) (g : NormedAddGroupHom (M ⧸ S) N) (h : g.comp S.normedMk = f) : g = lift S f hf := by ext x
Mathlib/Analysis/Normed/Group/Quotient.lean
412
416
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.MeasureTheory.Constructions.BorelSpace.Order import Mathlib.MeasureTheory.Measure.Count import Mathlib.Order.Filter.ENNReal import Mathlib.Probability.UniformOn /-! # Essential supremum and infimum We define the essential supremum and infimum of a function `f : α → β` with respect to a measure `μ` on `α`. The essential supremum is the infimum of the constants `c : β` such that `f x ≤ c` almost everywhere. TODO: The essential supremum of functions `α → ℝ≥0∞` is used in particular to define the norm in the `L∞` space (see `Mathlib.MeasureTheory.Function.LpSpace`). There is a different quantity which is sometimes also called essential supremum: the least upper-bound among measurable functions of a family of measurable functions (in an almost-everywhere sense). We do not define that quantity here, which is simply the supremum of a map with values in `α →ₘ[μ] β` (see `Mathlib.MeasureTheory.Function.AEEqFun`). ## Main definitions * `essSup f μ := (ae μ).limsup f` * `essInf f μ := (ae μ).liminf f` -/ open Filter MeasureTheory ProbabilityTheory Set TopologicalSpace open scoped ENNReal NNReal variable {α β : Type*} {m : MeasurableSpace α} {μ ν : Measure α} section ConditionallyCompleteLattice variable [ConditionallyCompleteLattice β] {f : α → β} /-- Essential supremum of `f` with respect to measure `μ`: the smallest `c : β` such that `f x ≤ c` a.e. -/ def essSup {_ : MeasurableSpace α} (f : α → β) (μ : Measure α) := (ae μ).limsup f /-- Essential infimum of `f` with respect to measure `μ`: the greatest `c : β` such that `c ≤ f x` a.e. -/ def essInf {_ : MeasurableSpace α} (f : α → β) (μ : Measure α) := (ae μ).liminf f theorem essSup_congr_ae {f g : α → β} (hfg : f =ᵐ[μ] g) : essSup f μ = essSup g μ := limsup_congr hfg theorem essInf_congr_ae {f g : α → β} (hfg : f =ᵐ[μ] g) : essInf f μ = essInf g μ := @essSup_congr_ae α βᵒᵈ _ _ _ _ _ hfg @[simp] theorem essSup_const' [NeZero μ] (c : β) : essSup (fun _ : α => c) μ = c := limsup_const _ @[simp] theorem essInf_const' [NeZero μ] (c : β) : essInf (fun _ : α => c) μ = c := liminf_const _ theorem essSup_const (c : β) (hμ : μ ≠ 0) : essSup (fun _ : α => c) μ = c := have := NeZero.mk hμ; essSup_const' _ theorem essInf_const (c : β) (hμ : μ ≠ 0) : essInf (fun _ : α => c) μ = c := have := NeZero.mk hμ; essInf_const' _ section SMul variable {R : Type*} [Zero R] [SMulWithZero R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] [NoZeroSMulDivisors R ℝ≥0∞] {c : R} @[simp] lemma essSup_smul_measure (hc : c ≠ 0) (f : α → β) : essSup f (c • μ) = essSup f μ := by simp_rw [essSup, Measure.ae_smul_measure_eq hc] end SMul variable [Nonempty α] lemma essSup_eq_ciSup (hμ : ∀ a, μ {a} ≠ 0) (hf : BddAbove (Set.range f)) : essSup f μ = ⨆ a, f a := by rw [essSup, ae_eq_top.2 hμ, limsup_top_eq_ciSup hf] lemma essInf_eq_ciInf (hμ : ∀ a, μ {a} ≠ 0) (hf : BddBelow (Set.range f)) : essInf f μ = ⨅ a, f a := by rw [essInf, ae_eq_top.2 hμ, liminf_top_eq_ciInf hf] variable [MeasurableSingletonClass α] @[simp] lemma essSup_count_eq_ciSup (hf : BddAbove (Set.range f)) : essSup f .count = ⨆ a, f a := essSup_eq_ciSup (by simp) hf @[simp] lemma essInf_count_eq_ciInf (hf : BddBelow (Set.range f)) : essInf f .count = ⨅ a, f a := essInf_eq_ciInf (by simp) hf @[simp] lemma essSup_uniformOn_eq_ciSup [Finite α] (hf : BddAbove (Set.range f)) : essSup f (uniformOn univ) = ⨆ a, f a := essSup_eq_ciSup (by simpa [uniformOn, cond_apply]) hf @[simp] lemma essInf_cond_count_eq_ciInf [Finite α] (hf : BddBelow (Set.range f)) : essInf f (uniformOn univ) = ⨅ a, f a := essInf_eq_ciInf (by simpa [uniformOn, cond_apply]) hf end ConditionallyCompleteLattice section ConditionallyCompleteLinearOrder variable [ConditionallyCompleteLinearOrder β] {x : β} {f : α → β} theorem essSup_eq_sInf {m : MeasurableSpace α} (μ : Measure α) (f : α → β) : essSup f μ = sInf { a | μ { x | a < f x } = 0 } := by dsimp [essSup, limsup, limsSup] simp only [eventually_map, ae_iff, not_le] theorem essInf_eq_sSup {m : MeasurableSpace α} (μ : Measure α) (f : α → β) : essInf f μ = sSup { a | μ { x | f x < a } = 0 } := by dsimp [essInf, liminf, limsInf] simp only [eventually_map, ae_iff, not_le] theorem ae_lt_of_essSup_lt (hx : essSup f μ < x) (hf : IsBoundedUnder (· ≤ ·) (ae μ) f := by isBoundedDefault) : ∀ᵐ y ∂μ, f y < x := eventually_lt_of_limsup_lt hx hf theorem ae_lt_of_lt_essInf (hx : x < essInf f μ) (hf : IsBoundedUnder (· ≥ ·) (ae μ) f := by isBoundedDefault) : ∀ᵐ y ∂μ, x < f y := eventually_lt_of_lt_liminf hx hf variable [TopologicalSpace β] [FirstCountableTopology β] [OrderTopology β] theorem ae_le_essSup (hf : IsBoundedUnder (· ≤ ·) (ae μ) f := by isBoundedDefault) : ∀ᵐ y ∂μ, f y ≤ essSup f μ := eventually_le_limsup hf theorem ae_essInf_le (hf : IsBoundedUnder (· ≥ ·) (ae μ) f := by isBoundedDefault) : ∀ᵐ y ∂μ, essInf f μ ≤ f y := eventually_liminf_le hf theorem meas_essSup_lt (hf : IsBoundedUnder (· ≤ ·) (ae μ) f := by isBoundedDefault) : μ { y | essSup f μ < f y } = 0 := by simp_rw [← not_le] exact ae_le_essSup hf theorem meas_lt_essInf (hf : IsBoundedUnder (· ≥ ·) (ae μ) f := by isBoundedDefault) : μ { y | f y < essInf f μ } = 0 := by simp_rw [← not_le] exact ae_essInf_le hf end ConditionallyCompleteLinearOrder section CompleteLattice variable [CompleteLattice β] @[simp] theorem essSup_measure_zero {m : MeasurableSpace α} {f : α → β} : essSup f (0 : Measure α) = ⊥ := le_bot_iff.mp (sInf_le (by simp [Set.mem_setOf_eq, EventuallyLE, ae_iff])) @[simp] theorem essInf_measure_zero {_ : MeasurableSpace α} {f : α → β} : essInf f (0 : Measure α) = ⊤ := @essSup_measure_zero α βᵒᵈ _ _ _ theorem essSup_mono_ae {f g : α → β} (hfg : f ≤ᵐ[μ] g) : essSup f μ ≤ essSup g μ := limsup_le_limsup hfg theorem essInf_mono_ae {f g : α → β} (hfg : f ≤ᵐ[μ] g) : essInf f μ ≤ essInf g μ := liminf_le_liminf hfg theorem essSup_le_of_ae_le {f : α → β} (c : β) (hf : f ≤ᵐ[μ] fun _ => c) : essSup f μ ≤ c := limsup_le_of_le (by isBoundedDefault) hf theorem le_essInf_of_ae_le {f : α → β} (c : β) (hf : (fun _ => c) ≤ᵐ[μ] f) : c ≤ essInf f μ := @essSup_le_of_ae_le α βᵒᵈ _ _ _ _ c hf theorem essSup_const_bot : essSup (fun _ : α => (⊥ : β)) μ = (⊥ : β) := limsup_const_bot theorem essInf_const_top : essInf (fun _ : α => (⊤ : β)) μ = (⊤ : β) := liminf_const_top theorem OrderIso.essSup_apply {m : MeasurableSpace α} {γ} [CompleteLattice γ] (f : α → β) (μ : Measure α) (g : β ≃o γ) : g (essSup f μ) = essSup (fun x => g (f x)) μ := by refine OrderIso.limsup_apply g ?_ ?_ ?_ ?_ all_goals isBoundedDefault theorem OrderIso.essInf_apply {_ : MeasurableSpace α} {γ} [CompleteLattice γ] (f : α → β) (μ : Measure α) (g : β ≃o γ) : g (essInf f μ) = essInf (fun x => g (f x)) μ := @OrderIso.essSup_apply α βᵒᵈ _ _ γᵒᵈ _ _ _ g.dual theorem essSup_mono_measure {f : α → β} (hμν : ν ≪ μ) : essSup f ν ≤ essSup f μ := by refine limsup_le_limsup_of_le (Measure.ae_le_iff_absolutelyContinuous.mpr hμν) ?_ ?_ all_goals isBoundedDefault theorem essSup_mono_measure' {α : Type*} {β : Type*} {_ : MeasurableSpace α} {μ ν : MeasureTheory.Measure α} [CompleteLattice β] {f : α → β} (hμν : ν ≤ μ) : essSup f ν ≤ essSup f μ := essSup_mono_measure (Measure.absolutelyContinuous_of_le hμν) theorem essInf_antitone_measure {f : α → β} (hμν : μ ≪ ν) : essInf f ν ≤ essInf f μ := by refine liminf_le_liminf_of_le (Measure.ae_le_iff_absolutelyContinuous.mpr hμν) ?_ ?_ all_goals isBoundedDefault lemma essSup_eq_iSup (hμ : ∀ a, μ {a} ≠ 0) (f : α → β) : essSup f μ = ⨆ i, f i := by rw [essSup, ae_eq_top.2 hμ, limsup_top_eq_iSup] lemma essInf_eq_iInf (hμ : ∀ a, μ {a} ≠ 0) (f : α → β) : essInf f μ = ⨅ i, f i := by rw [essInf, ae_eq_top.2 hμ, liminf_top_eq_iInf] @[simp] lemma essSup_count [MeasurableSingletonClass α] (f : α → β) : essSup f .count = ⨆ i, f i := essSup_eq_iSup (by simp) _ @[simp] lemma essInf_count [MeasurableSingletonClass α] (f : α → β) : essInf f .count = ⨅ i, f i := essInf_eq_iInf (by simp) _ section TopologicalSpace variable {γ : Type*} {mγ : MeasurableSpace γ} {f : α → γ} {g : γ → β}
theorem essSup_comp_le_essSup_map_measure (hf : AEMeasurable f μ) : essSup (g ∘ f) μ ≤ essSup g (Measure.map f μ) := by refine limsSup_le_limsSup_of_le ?_ rw [← Filter.map_map] exact Filter.map_mono (Measure.tendsto_ae_map hf)
Mathlib/MeasureTheory/Function/EssSup.lean
225
230
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Order.Ring.Nat import Mathlib.Logic.Encodable.Pi import Mathlib.Logic.Function.Iterate /-! # The primitive recursive functions The primitive recursive functions are the least collection of functions `ℕ → ℕ` which are closed under projections (using the `pair` pairing function), composition, zero, successor, and primitive recursion (i.e. `Nat.rec` where the motive is `C n := ℕ`). We can extend this definition to a large class of basic types by using canonical encodings of types as natural numbers (Gödel numbering), which we implement through the type class `Encodable`. (More precisely, we need that the composition of encode with decode yields a primitive recursive function, so we have the `Primcodable` type class for this.) In the above, the pairing function is primitive recursive by definition. This deviates from the textbook definition of primitive recursive functions, which instead work with *`n`-ary* functions. We formalize the textbook definition in `Nat.Primrec'`. `Nat.Primrec'.prim_iff` then proves it is equivalent to our chosen formulation. For more discussionn of this and other design choices in this formalization, see [carneiro2019]. ## Main definitions - `Nat.Primrec f`: `f` is primitive recursive, for functions `f : ℕ → ℕ` - `Primrec f`: `f` is primitive recursive, for functions between `Primcodable` types - `Primcodable α`: well-behaved encoding of `α` into `ℕ`, i.e. one such that roundtripping through the encoding functions adds no computational power ## References * [Mario Carneiro, *Formalizing computability theory via partial recursive functions*][carneiro2019] -/ open List (Vector) open Denumerable Encodable Function namespace Nat /-- Calls the given function on a pair of entries `n`, encoded via the pairing function. -/ @[simp, reducible] def unpaired {α} (f : ℕ → ℕ → α) (n : ℕ) : α := f n.unpair.1 n.unpair.2 /-- The primitive recursive functions `ℕ → ℕ`. -/ protected inductive Primrec : (ℕ → ℕ) → Prop | zero : Nat.Primrec fun _ => 0 | protected succ : Nat.Primrec succ | left : Nat.Primrec fun n => n.unpair.1 | right : Nat.Primrec fun n => n.unpair.2 | pair {f g} : Nat.Primrec f → Nat.Primrec g → Nat.Primrec fun n => pair (f n) (g n) | comp {f g} : Nat.Primrec f → Nat.Primrec g → Nat.Primrec fun n => f (g n) | prec {f g} : Nat.Primrec f → Nat.Primrec g → Nat.Primrec (unpaired fun z n => n.rec (f z) fun y IH => g <| pair z <| pair y IH) namespace Primrec theorem of_eq {f g : ℕ → ℕ} (hf : Nat.Primrec f) (H : ∀ n, f n = g n) : Nat.Primrec g := (funext H : f = g) ▸ hf theorem const : ∀ n : ℕ, Nat.Primrec fun _ => n | 0 => zero | n + 1 => Primrec.succ.comp (const n) protected theorem id : Nat.Primrec id := (left.pair right).of_eq fun n => by simp theorem prec1 {f} (m : ℕ) (hf : Nat.Primrec f) : Nat.Primrec fun n => n.rec m fun y IH => f <| Nat.pair y IH := ((prec (const m) (hf.comp right)).comp (zero.pair Primrec.id)).of_eq fun n => by simp theorem casesOn1 {f} (m : ℕ) (hf : Nat.Primrec f) : Nat.Primrec (Nat.casesOn · m f) := (prec1 m (hf.comp left)).of_eq <| by simp -- Porting note: `Nat.Primrec.casesOn` is already declared as a recursor. theorem casesOn' {f g} (hf : Nat.Primrec f) (hg : Nat.Primrec g) : Nat.Primrec (unpaired fun z n => n.casesOn (f z) fun y => g <| Nat.pair z y) := (prec hf (hg.comp (pair left (left.comp right)))).of_eq fun n => by simp protected theorem swap : Nat.Primrec (unpaired (swap Nat.pair)) := (pair right left).of_eq fun n => by simp theorem swap' {f} (hf : Nat.Primrec (unpaired f)) : Nat.Primrec (unpaired (swap f)) := (hf.comp .swap).of_eq fun n => by simp theorem pred : Nat.Primrec pred := (casesOn1 0 Primrec.id).of_eq fun n => by cases n <;> simp [*] theorem add : Nat.Primrec (unpaired (· + ·)) := (prec .id ((Primrec.succ.comp right).comp right)).of_eq fun p => by simp; induction p.unpair.2 <;> simp [*, Nat.add_assoc] theorem sub : Nat.Primrec (unpaired (· - ·)) := (prec .id ((pred.comp right).comp right)).of_eq fun p => by simp; induction p.unpair.2 <;> simp [*, Nat.sub_add_eq] theorem mul : Nat.Primrec (unpaired (· * ·)) := (prec zero (add.comp (pair left (right.comp right)))).of_eq fun p => by simp; induction p.unpair.2 <;> simp [*, mul_succ, add_comm _ (unpair p).fst] theorem pow : Nat.Primrec (unpaired (· ^ ·)) := (prec (const 1) (mul.comp (pair (right.comp right) left))).of_eq fun p => by simp; induction p.unpair.2 <;> simp [*, Nat.pow_succ] end Primrec end Nat /-- A `Primcodable` type is, essentially, an `Encodable` type for which the encode/decode functions are primitive recursive. However, such a definition is circular. Instead, we ask that the composition of `decode : ℕ → Option α` with `encode : Option α → ℕ` is primitive recursive. Said composition is the identity function, restricted to the image of `encode`. Thus, in a way, the added requirement ensures that no predicates can be smuggled in through a cunning choice of the subset of `ℕ` into which the type is encoded. -/ class Primcodable (α : Type*) extends Encodable α where -- Porting note: was `prim [] `. -- This means that `prim` does not take the type explicitly in Lean 4 prim : Nat.Primrec fun n => Encodable.encode (decode n) namespace Primcodable open Nat.Primrec instance (priority := 10) ofDenumerable (α) [Denumerable α] : Primcodable α := ⟨Nat.Primrec.succ.of_eq <| by simp⟩ /-- Builds a `Primcodable` instance from an equivalence to a `Primcodable` type. -/ def ofEquiv (α) {β} [Primcodable α] (e : β ≃ α) : Primcodable β := { __ := Encodable.ofEquiv α e prim := (@Primcodable.prim α _).of_eq fun n => by rw [decode_ofEquiv] cases (@decode α _ n) <;> simp [encode_ofEquiv] } instance empty : Primcodable Empty := ⟨zero⟩ instance unit : Primcodable PUnit := ⟨(casesOn1 1 zero).of_eq fun n => by cases n <;> simp⟩ instance option {α : Type*} [h : Primcodable α] : Primcodable (Option α) := ⟨(casesOn1 1 ((casesOn1 0 (.comp .succ .succ)).comp (@Primcodable.prim α _))).of_eq fun n => by cases n with | zero => rfl | succ n => rw [decode_option_succ] cases H : @decode α _ n <;> simp [H]⟩ instance bool : Primcodable Bool := ⟨(casesOn1 1 (casesOn1 2 zero)).of_eq fun n => match n with | 0 => rfl | 1 => rfl | (n + 2) => by rw [decode_ge_two] <;> simp⟩ end Primcodable /-- `Primrec f` means `f` is primitive recursive (after encoding its input and output as natural numbers). -/ def Primrec {α β} [Primcodable α] [Primcodable β] (f : α → β) : Prop := Nat.Primrec fun n => encode ((@decode α _ n).map f) namespace Primrec variable {α : Type*} {β : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable σ] open Nat.Primrec protected theorem encode : Primrec (@encode α _) := (@Primcodable.prim α _).of_eq fun n => by cases @decode α _ n <;> rfl protected theorem decode : Primrec (@decode α _) := Nat.Primrec.succ.comp (@Primcodable.prim α _) theorem dom_denumerable {α β} [Denumerable α] [Primcodable β] {f : α → β} : Primrec f ↔ Nat.Primrec fun n => encode (f (ofNat α n)) := ⟨fun h => (pred.comp h).of_eq fun n => by simp, fun h => (Nat.Primrec.succ.comp h).of_eq fun n => by simp⟩ theorem nat_iff {f : ℕ → ℕ} : Primrec f ↔ Nat.Primrec f := dom_denumerable theorem encdec : Primrec fun n => encode (@decode α _ n) := nat_iff.2 Primcodable.prim theorem option_some : Primrec (@some α) := ((casesOn1 0 (Nat.Primrec.succ.comp .succ)).comp (@Primcodable.prim α _)).of_eq fun n => by cases @decode α _ n <;> simp theorem of_eq {f g : α → σ} (hf : Primrec f) (H : ∀ n, f n = g n) : Primrec g := (funext H : f = g) ▸ hf theorem const (x : σ) : Primrec fun _ : α => x := ((casesOn1 0 (.const (encode x).succ)).comp (@Primcodable.prim α _)).of_eq fun n => by cases @decode α _ n <;> rfl protected theorem id : Primrec (@id α) := (@Primcodable.prim α).of_eq <| by simp theorem comp {f : β → σ} {g : α → β} (hf : Primrec f) (hg : Primrec g) : Primrec fun a => f (g a) := ((casesOn1 0 (.comp hf (pred.comp hg))).comp (@Primcodable.prim α _)).of_eq fun n => by cases @decode α _ n <;> simp [encodek] theorem succ : Primrec Nat.succ := nat_iff.2 Nat.Primrec.succ theorem pred : Primrec Nat.pred := nat_iff.2 Nat.Primrec.pred theorem encode_iff {f : α → σ} : (Primrec fun a => encode (f a)) ↔ Primrec f := ⟨fun h => Nat.Primrec.of_eq h fun n => by cases @decode α _ n <;> rfl, Primrec.encode.comp⟩ theorem ofNat_iff {α β} [Denumerable α] [Primcodable β] {f : α → β} : Primrec f ↔ Primrec fun n => f (ofNat α n) := dom_denumerable.trans <| nat_iff.symm.trans encode_iff protected theorem ofNat (α) [Denumerable α] : Primrec (ofNat α) := ofNat_iff.1 Primrec.id theorem option_some_iff {f : α → σ} : (Primrec fun a => some (f a)) ↔ Primrec f := ⟨fun h => encode_iff.1 <| pred.comp <| encode_iff.2 h, option_some.comp⟩ theorem of_equiv {β} {e : β ≃ α} : haveI := Primcodable.ofEquiv α e Primrec e := letI : Primcodable β := Primcodable.ofEquiv α e encode_iff.1 Primrec.encode theorem of_equiv_symm {β} {e : β ≃ α} : haveI := Primcodable.ofEquiv α e Primrec e.symm := letI := Primcodable.ofEquiv α e encode_iff.1 (show Primrec fun a => encode (e (e.symm a)) by simp [Primrec.encode]) theorem of_equiv_iff {β} (e : β ≃ α) {f : σ → β} : haveI := Primcodable.ofEquiv α e (Primrec fun a => e (f a)) ↔ Primrec f := letI := Primcodable.ofEquiv α e ⟨fun h => (of_equiv_symm.comp h).of_eq fun a => by simp, of_equiv.comp⟩ theorem of_equiv_symm_iff {β} (e : β ≃ α) {f : σ → α} : haveI := Primcodable.ofEquiv α e (Primrec fun a => e.symm (f a)) ↔ Primrec f := letI := Primcodable.ofEquiv α e ⟨fun h => (of_equiv.comp h).of_eq fun a => by simp, of_equiv_symm.comp⟩ end Primrec namespace Primcodable open Nat.Primrec instance prod {α β} [Primcodable α] [Primcodable β] : Primcodable (α × β) := ⟨((casesOn' zero ((casesOn' zero .succ).comp (pair right ((@Primcodable.prim β).comp left)))).comp (pair right ((@Primcodable.prim α).comp left))).of_eq fun n => by simp only [Nat.unpaired, Nat.unpair_pair, decode_prod_val] cases @decode α _ n.unpair.1; · simp cases @decode β _ n.unpair.2 <;> simp⟩ end Primcodable namespace Primrec variable {α : Type*} [Primcodable α] open Nat.Primrec theorem fst {α β} [Primcodable α] [Primcodable β] : Primrec (@Prod.fst α β) := ((casesOn' zero ((casesOn' zero (Nat.Primrec.succ.comp left)).comp (pair right ((@Primcodable.prim β).comp left)))).comp (pair right ((@Primcodable.prim α).comp left))).of_eq fun n => by simp only [Nat.unpaired, Nat.unpair_pair, decode_prod_val] cases @decode α _ n.unpair.1 <;> simp cases @decode β _ n.unpair.2 <;> simp theorem snd {α β} [Primcodable α] [Primcodable β] : Primrec (@Prod.snd α β) := ((casesOn' zero ((casesOn' zero (Nat.Primrec.succ.comp right)).comp (pair right ((@Primcodable.prim β).comp left)))).comp (pair right ((@Primcodable.prim α).comp left))).of_eq fun n => by simp only [Nat.unpaired, Nat.unpair_pair, decode_prod_val] cases @decode α _ n.unpair.1 <;> simp cases @decode β _ n.unpair.2 <;> simp theorem pair {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {f : α → β} {g : α → γ} (hf : Primrec f) (hg : Primrec g) : Primrec fun a => (f a, g a) := ((casesOn1 0 (Nat.Primrec.succ.comp <| .pair (Nat.Primrec.pred.comp hf) (Nat.Primrec.pred.comp hg))).comp (@Primcodable.prim α _)).of_eq fun n => by cases @decode α _ n <;> simp [encodek] theorem unpair : Primrec Nat.unpair := (pair (nat_iff.2 .left) (nat_iff.2 .right)).of_eq fun n => by simp theorem list_getElem?₁ : ∀ l : List α, Primrec (l[·]? : ℕ → Option α) | [] => dom_denumerable.2 zero | a :: l => dom_denumerable.2 <| (casesOn1 (encode a).succ <| dom_denumerable.1 <| list_getElem?₁ l).of_eq fun n => by cases n <;> simp @[deprecated (since := "2025-02-14")] alias list_get?₁ := list_getElem?₁ end Primrec /-- `Primrec₂ f` means `f` is a binary primitive recursive function. This is technically unnecessary since we can always curry all the arguments together, but there are enough natural two-arg functions that it is convenient to express this directly. -/ def Primrec₂ {α β σ} [Primcodable α] [Primcodable β] [Primcodable σ] (f : α → β → σ) := Primrec fun p : α × β => f p.1 p.2 /-- `PrimrecPred p` means `p : α → Prop` is a (decidable) primitive recursive predicate, which is to say that `decide ∘ p : α → Bool` is primitive recursive. -/ def PrimrecPred {α} [Primcodable α] (p : α → Prop) [DecidablePred p] := Primrec fun a => decide (p a) /-- `PrimrecRel p` means `p : α → β → Prop` is a (decidable) primitive recursive relation, which is to say that `decide ∘ p : α → β → Bool` is primitive recursive. -/ def PrimrecRel {α β} [Primcodable α] [Primcodable β] (s : α → β → Prop) [∀ a b, Decidable (s a b)] := Primrec₂ fun a b => decide (s a b) namespace Primrec₂ variable {α : Type*} {β : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable σ] theorem mk {f : α → β → σ} (hf : Primrec fun p : α × β => f p.1 p.2) : Primrec₂ f := hf theorem of_eq {f g : α → β → σ} (hg : Primrec₂ f) (H : ∀ a b, f a b = g a b) : Primrec₂ g := (by funext a b; apply H : f = g) ▸ hg theorem const (x : σ) : Primrec₂ fun (_ : α) (_ : β) => x := Primrec.const _ protected theorem pair : Primrec₂ (@Prod.mk α β) := Primrec.pair .fst .snd theorem left : Primrec₂ fun (a : α) (_ : β) => a := .fst theorem right : Primrec₂ fun (_ : α) (b : β) => b := .snd theorem natPair : Primrec₂ Nat.pair := by simp [Primrec₂, Primrec]; constructor theorem unpaired {f : ℕ → ℕ → α} : Primrec (Nat.unpaired f) ↔ Primrec₂ f := ⟨fun h => by simpa using h.comp natPair, fun h => h.comp Primrec.unpair⟩ theorem unpaired' {f : ℕ → ℕ → ℕ} : Nat.Primrec (Nat.unpaired f) ↔ Primrec₂ f := Primrec.nat_iff.symm.trans unpaired theorem encode_iff {f : α → β → σ} : (Primrec₂ fun a b => encode (f a b)) ↔ Primrec₂ f := Primrec.encode_iff theorem option_some_iff {f : α → β → σ} : (Primrec₂ fun a b => some (f a b)) ↔ Primrec₂ f := Primrec.option_some_iff theorem ofNat_iff {α β σ} [Denumerable α] [Denumerable β] [Primcodable σ] {f : α → β → σ} : Primrec₂ f ↔ Primrec₂ fun m n : ℕ => f (ofNat α m) (ofNat β n) := (Primrec.ofNat_iff.trans <| by simp).trans unpaired theorem uncurry {f : α → β → σ} : Primrec (Function.uncurry f) ↔ Primrec₂ f := by rw [show Function.uncurry f = fun p : α × β => f p.1 p.2 from funext fun ⟨a, b⟩ => rfl]; rfl theorem curry {f : α × β → σ} : Primrec₂ (Function.curry f) ↔ Primrec f := by rw [← uncurry, Function.uncurry_curry] end Primrec₂ section Comp variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable γ] [Primcodable δ] [Primcodable σ] theorem Primrec.comp₂ {f : γ → σ} {g : α → β → γ} (hf : Primrec f) (hg : Primrec₂ g) : Primrec₂ fun a b => f (g a b) := hf.comp hg theorem Primrec₂.comp {f : β → γ → σ} {g : α → β} {h : α → γ} (hf : Primrec₂ f) (hg : Primrec g) (hh : Primrec h) : Primrec fun a => f (g a) (h a) := Primrec.comp hf (hg.pair hh) theorem Primrec₂.comp₂ {f : γ → δ → σ} {g : α → β → γ} {h : α → β → δ} (hf : Primrec₂ f) (hg : Primrec₂ g) (hh : Primrec₂ h) : Primrec₂ fun a b => f (g a b) (h a b) := hf.comp hg hh theorem PrimrecPred.comp {p : β → Prop} [DecidablePred p] {f : α → β} : PrimrecPred p → Primrec f → PrimrecPred fun a => p (f a) := Primrec.comp theorem PrimrecRel.comp {R : β → γ → Prop} [∀ a b, Decidable (R a b)] {f : α → β} {g : α → γ} : PrimrecRel R → Primrec f → Primrec g → PrimrecPred fun a => R (f a) (g a) := Primrec₂.comp theorem PrimrecRel.comp₂ {R : γ → δ → Prop} [∀ a b, Decidable (R a b)] {f : α → β → γ} {g : α → β → δ} : PrimrecRel R → Primrec₂ f → Primrec₂ g → PrimrecRel fun a b => R (f a b) (g a b) := PrimrecRel.comp end Comp theorem PrimrecPred.of_eq {α} [Primcodable α] {p q : α → Prop} [DecidablePred p] [DecidablePred q] (hp : PrimrecPred p) (H : ∀ a, p a ↔ q a) : PrimrecPred q := Primrec.of_eq hp fun a => Bool.decide_congr (H a) theorem PrimrecRel.of_eq {α β} [Primcodable α] [Primcodable β] {r s : α → β → Prop} [∀ a b, Decidable (r a b)] [∀ a b, Decidable (s a b)] (hr : PrimrecRel r) (H : ∀ a b, r a b ↔ s a b) : PrimrecRel s := Primrec₂.of_eq hr fun a b => Bool.decide_congr (H a b) namespace Primrec₂ variable {α : Type*} {β : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable σ] open Nat.Primrec theorem swap {f : α → β → σ} (h : Primrec₂ f) : Primrec₂ (swap f) := h.comp₂ Primrec₂.right Primrec₂.left theorem nat_iff {f : α → β → σ} : Primrec₂ f ↔ Nat.Primrec (.unpaired fun m n => encode <| (@decode α _ m).bind fun a => (@decode β _ n).map (f a)) := by have : ∀ (a : Option α) (b : Option β), Option.map (fun p : α × β => f p.1 p.2) (Option.bind a fun a : α => Option.map (Prod.mk a) b) = Option.bind a fun a => Option.map (f a) b := fun a b => by cases a <;> cases b <;> rfl simp [Primrec₂, Primrec, this] theorem nat_iff' {f : α → β → σ} : Primrec₂ f ↔ Primrec₂ fun m n : ℕ => (@decode α _ m).bind fun a => Option.map (f a) (@decode β _ n) := nat_iff.trans <| unpaired'.trans encode_iff end Primrec₂ namespace Primrec variable {α : Type*} {β : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable σ] theorem to₂ {f : α × β → σ} (hf : Primrec f) : Primrec₂ fun a b => f (a, b) := hf.of_eq fun _ => rfl theorem nat_rec {f : α → β} {g : α → ℕ × β → β} (hf : Primrec f) (hg : Primrec₂ g) : Primrec₂ fun a (n : ℕ) => n.rec (motive := fun _ => β) (f a) fun n IH => g a (n, IH) := Primrec₂.nat_iff.2 <| ((Nat.Primrec.casesOn' .zero <| (Nat.Primrec.prec hf <| .comp hg <| Nat.Primrec.left.pair <| (Nat.Primrec.left.comp .right).pair <| Nat.Primrec.pred.comp <| Nat.Primrec.right.comp .right).comp <| Nat.Primrec.right.pair <| Nat.Primrec.right.comp Nat.Primrec.left).comp <| Nat.Primrec.id.pair <| (@Primcodable.prim α).comp Nat.Primrec.left).of_eq fun n => by simp only [Nat.unpaired, id_eq, Nat.unpair_pair, decode_prod_val, decode_nat, Option.some_bind, Option.map_map, Option.map_some'] rcases @decode α _ n.unpair.1 with - | a; · rfl simp only [Nat.pred_eq_sub_one, encode_some, Nat.succ_eq_add_one, encodek, Option.map_some', Option.some_bind, Option.map_map] induction' n.unpair.2 with m <;> simp [encodek] simp [*, encodek] theorem nat_rec' {f : α → ℕ} {g : α → β} {h : α → ℕ × β → β} (hf : Primrec f) (hg : Primrec g) (hh : Primrec₂ h) : Primrec fun a => (f a).rec (motive := fun _ => β) (g a) fun n IH => h a (n, IH) := (nat_rec hg hh).comp .id hf theorem nat_rec₁ {f : ℕ → α → α} (a : α) (hf : Primrec₂ f) : Primrec (Nat.rec a f) := nat_rec' .id (const a) <| comp₂ hf Primrec₂.right theorem nat_casesOn' {f : α → β} {g : α → ℕ → β} (hf : Primrec f) (hg : Primrec₂ g) : Primrec₂ fun a (n : ℕ) => (n.casesOn (f a) (g a) : β) := nat_rec hf <| hg.comp₂ Primrec₂.left <| comp₂ fst Primrec₂.right theorem nat_casesOn {f : α → ℕ} {g : α → β} {h : α → ℕ → β} (hf : Primrec f) (hg : Primrec g) (hh : Primrec₂ h) : Primrec fun a => ((f a).casesOn (g a) (h a) : β) := (nat_casesOn' hg hh).comp .id hf theorem nat_casesOn₁ {f : ℕ → α} (a : α) (hf : Primrec f) : Primrec (fun (n : ℕ) => (n.casesOn a f : α)) := nat_casesOn .id (const a) (comp₂ hf .right) theorem nat_iterate {f : α → ℕ} {g : α → β} {h : α → β → β} (hf : Primrec f) (hg : Primrec g) (hh : Primrec₂ h) : Primrec fun a => (h a)^[f a] (g a) := (nat_rec' hf hg (hh.comp₂ Primrec₂.left <| snd.comp₂ Primrec₂.right)).of_eq fun a => by induction f a <;> simp [*, -Function.iterate_succ, Function.iterate_succ'] theorem option_casesOn {o : α → Option β} {f : α → σ} {g : α → β → σ} (ho : Primrec o) (hf : Primrec f) (hg : Primrec₂ g) : @Primrec _ σ _ _ fun a => Option.casesOn (o a) (f a) (g a) := encode_iff.1 <| (nat_casesOn (encode_iff.2 ho) (encode_iff.2 hf) <| pred.comp₂ <| Primrec₂.encode_iff.2 <| (Primrec₂.nat_iff'.1 hg).comp₂ ((@Primrec.encode α _).comp fst).to₂ Primrec₂.right).of_eq fun a => by rcases o a with - | b <;> simp [encodek] theorem option_bind {f : α → Option β} {g : α → β → Option σ} (hf : Primrec f) (hg : Primrec₂ g) : Primrec fun a => (f a).bind (g a) := (option_casesOn hf (const none) hg).of_eq fun a => by cases f a <;> rfl theorem option_bind₁ {f : α → Option σ} (hf : Primrec f) : Primrec fun o => Option.bind o f := option_bind .id (hf.comp snd).to₂ theorem option_map {f : α → Option β} {g : α → β → σ} (hf : Primrec f) (hg : Primrec₂ g) : Primrec fun a => (f a).map (g a) := (option_bind hf (option_some.comp₂ hg)).of_eq fun x => by cases f x <;> rfl theorem option_map₁ {f : α → σ} (hf : Primrec f) : Primrec (Option.map f) := option_map .id (hf.comp snd).to₂ theorem option_iget [Inhabited α] : Primrec (@Option.iget α _) := (option_casesOn .id (const <| @default α _) .right).of_eq fun o => by cases o <;> rfl theorem option_isSome : Primrec (@Option.isSome α) := (option_casesOn .id (const false) (const true).to₂).of_eq fun o => by cases o <;> rfl theorem option_getD : Primrec₂ (@Option.getD α) := Primrec.of_eq (option_casesOn Primrec₂.left Primrec₂.right .right) fun ⟨o, a⟩ => by cases o <;> rfl theorem bind_decode_iff {f : α → β → Option σ} : (Primrec₂ fun a n => (@decode β _ n).bind (f a)) ↔ Primrec₂ f := ⟨fun h => by simpa [encodek] using h.comp fst ((@Primrec.encode β _).comp snd), fun h => option_bind (Primrec.decode.comp snd) <| h.comp (fst.comp fst) snd⟩ theorem map_decode_iff {f : α → β → σ} : (Primrec₂ fun a n => (@decode β _ n).map (f a)) ↔ Primrec₂ f := by simp only [Option.map_eq_bind] exact bind_decode_iff.trans Primrec₂.option_some_iff theorem nat_add : Primrec₂ ((· + ·) : ℕ → ℕ → ℕ) := Primrec₂.unpaired'.1 Nat.Primrec.add theorem nat_sub : Primrec₂ ((· - ·) : ℕ → ℕ → ℕ) := Primrec₂.unpaired'.1 Nat.Primrec.sub theorem nat_mul : Primrec₂ ((· * ·) : ℕ → ℕ → ℕ) := Primrec₂.unpaired'.1 Nat.Primrec.mul theorem cond {c : α → Bool} {f : α → σ} {g : α → σ} (hc : Primrec c) (hf : Primrec f) (hg : Primrec g) : Primrec fun a => bif (c a) then (f a) else (g a) := (nat_casesOn (encode_iff.2 hc) hg (hf.comp fst).to₂).of_eq fun a => by cases c a <;> rfl theorem ite {c : α → Prop} [DecidablePred c] {f : α → σ} {g : α → σ} (hc : PrimrecPred c) (hf : Primrec f) (hg : Primrec g) : Primrec fun a => if c a then f a else g a := by simpa [Bool.cond_decide] using cond hc hf hg theorem nat_le : PrimrecRel ((· ≤ ·) : ℕ → ℕ → Prop) := (nat_casesOn nat_sub (const true) (const false).to₂).of_eq fun p => by dsimp [swap] rcases e : p.1 - p.2 with - | n · simp [Nat.sub_eq_zero_iff_le.1 e] · simp [not_le.2 (Nat.lt_of_sub_eq_succ e)] theorem nat_min : Primrec₂ (@min ℕ _) := ite nat_le fst snd theorem nat_max : Primrec₂ (@max ℕ _) := ite (nat_le.comp fst snd) snd fst theorem dom_bool (f : Bool → α) : Primrec f := (cond .id (const (f true)) (const (f false))).of_eq fun b => by cases b <;> rfl theorem dom_bool₂ (f : Bool → Bool → α) : Primrec₂ f := (cond fst ((dom_bool (f true)).comp snd) ((dom_bool (f false)).comp snd)).of_eq fun ⟨a, b⟩ => by cases a <;> rfl protected theorem not : Primrec not := dom_bool _ protected theorem and : Primrec₂ and := dom_bool₂ _ protected theorem or : Primrec₂ or := dom_bool₂ _ theorem _root_.PrimrecPred.not {p : α → Prop} [DecidablePred p] (hp : PrimrecPred p) : PrimrecPred fun a => ¬p a := (Primrec.not.comp hp).of_eq fun n => by simp theorem _root_.PrimrecPred.and {p q : α → Prop} [DecidablePred p] [DecidablePred q] (hp : PrimrecPred p) (hq : PrimrecPred q) : PrimrecPred fun a => p a ∧ q a := (Primrec.and.comp hp hq).of_eq fun n => by simp theorem _root_.PrimrecPred.or {p q : α → Prop} [DecidablePred p] [DecidablePred q] (hp : PrimrecPred p) (hq : PrimrecPred q) : PrimrecPred fun a => p a ∨ q a := (Primrec.or.comp hp hq).of_eq fun n => by simp protected theorem beq [DecidableEq α] : Primrec₂ (@BEq.beq α _) := have : PrimrecRel fun a b : ℕ => a = b := (PrimrecPred.and nat_le nat_le.swap).of_eq fun a => by simp [le_antisymm_iff] (this.comp₂ (Primrec.encode.comp₂ Primrec₂.left) (Primrec.encode.comp₂ Primrec₂.right)).of_eq fun _ _ => encode_injective.eq_iff protected theorem eq [DecidableEq α] : PrimrecRel (@Eq α) := Primrec.beq theorem nat_lt : PrimrecRel ((· < ·) : ℕ → ℕ → Prop) := (nat_le.comp snd fst).not.of_eq fun p => by simp theorem option_guard {p : α → β → Prop} [∀ a b, Decidable (p a b)] (hp : PrimrecRel p) {f : α → β} (hf : Primrec f) : Primrec fun a => Option.guard (p a) (f a) := ite (hp.comp Primrec.id hf) (option_some_iff.2 hf) (const none) theorem option_orElse : Primrec₂ ((· <|> ·) : Option α → Option α → Option α) := (option_casesOn fst snd (fst.comp fst).to₂).of_eq fun ⟨o₁, o₂⟩ => by cases o₁ <;> cases o₂ <;> rfl protected theorem decode₂ : Primrec (decode₂ α) := option_bind .decode <| option_guard (Primrec.beq.comp₂ (by exact encode_iff.mpr snd) (by exact fst.comp fst)) snd theorem list_findIdx₁ {p : α → β → Bool} (hp : Primrec₂ p) : ∀ l : List β, Primrec fun a => l.findIdx (p a) | [] => const 0 | a :: l => (cond (hp.comp .id (const a)) (const 0) (succ.comp (list_findIdx₁ hp l))).of_eq fun n => by simp [List.findIdx_cons] theorem list_idxOf₁ [DecidableEq α] (l : List α) : Primrec fun a => l.idxOf a := list_findIdx₁ (.swap .beq) l @[deprecated (since := "2025-01-30")] alias list_indexOf₁ := list_idxOf₁ theorem dom_fintype [Finite α] (f : α → σ) : Primrec f := let ⟨l, _, m⟩ := Finite.exists_univ_list α option_some_iff.1 <| by haveI := decidableEqOfEncodable α refine ((list_getElem?₁ (l.map f)).comp (list_idxOf₁ l)).of_eq fun a => ?_ rw [List.getElem?_map, List.getElem?_idxOf (m a), Option.map_some'] -- Porting note: These are new lemmas -- I added it because it actually simplified the proofs -- and because I couldn't understand the original proof /-- A function is `PrimrecBounded` if its size is bounded by a primitive recursive function -/ def PrimrecBounded (f : α → β) : Prop := ∃ g : α → ℕ, Primrec g ∧ ∀ x, encode (f x) ≤ g x theorem nat_findGreatest {f : α → ℕ} {p : α → ℕ → Prop} [∀ x n, Decidable (p x n)] (hf : Primrec f) (hp : PrimrecRel p) : Primrec fun x => (f x).findGreatest (p x) := (nat_rec' (h := fun x nih => if p x (nih.1 + 1) then nih.1 + 1 else nih.2) hf (const 0) (ite (hp.comp fst (snd |> fst.comp |> succ.comp)) (snd |> fst.comp |> succ.comp) (snd.comp snd))).of_eq fun x => by induction f x <;> simp [Nat.findGreatest, *] /-- To show a function `f : α → ℕ` is primitive recursive, it is enough to show that the function is bounded by a primitive recursive function and that its graph is primitive recursive -/ theorem of_graph {f : α → ℕ} (h₁ : PrimrecBounded f) (h₂ : PrimrecRel fun a b => f a = b) : Primrec f := by rcases h₁ with ⟨g, pg, hg : ∀ x, f x ≤ g x⟩ refine (nat_findGreatest pg h₂).of_eq fun n => ?_ exact (Nat.findGreatest_spec (P := fun b => f n = b) (hg n) rfl).symm -- We show that division is primitive recursive by showing that the graph is theorem nat_div : Primrec₂ ((· / ·) : ℕ → ℕ → ℕ) := by refine of_graph ⟨_, fst, fun p => Nat.div_le_self _ _⟩ ?_ have : PrimrecRel fun (a : ℕ × ℕ) (b : ℕ) => (a.2 = 0 ∧ b = 0) ∨ (0 < a.2 ∧ b * a.2 ≤ a.1 ∧ a.1 < (b + 1) * a.2) := PrimrecPred.or (.and (const 0 |> Primrec.eq.comp (fst |> snd.comp)) (const 0 |> Primrec.eq.comp snd)) (.and (nat_lt.comp (const 0) (fst |> snd.comp)) <| .and (nat_le.comp (nat_mul.comp snd (fst |> snd.comp)) (fst |> fst.comp)) (nat_lt.comp (fst.comp fst) (nat_mul.comp (Primrec.succ.comp snd) (snd.comp fst)))) refine this.of_eq ?_ rintro ⟨a, k⟩ q if H : k = 0 then simp [H, eq_comm] else have : q * k ≤ a ∧ a < (q + 1) * k ↔ q = a / k := by rw [le_antisymm_iff, ← (@Nat.lt_succ _ q), Nat.le_div_iff_mul_le (Nat.pos_of_ne_zero H), Nat.div_lt_iff_lt_mul (Nat.pos_of_ne_zero H)] simpa [H, zero_lt_iff, eq_comm (b := q)] theorem nat_mod : Primrec₂ ((· % ·) : ℕ → ℕ → ℕ) := (nat_sub.comp fst (nat_mul.comp snd nat_div)).to₂.of_eq fun m n => by apply Nat.sub_eq_of_eq_add simp [add_comm (m % n), Nat.div_add_mod] theorem nat_bodd : Primrec Nat.bodd := (Primrec.beq.comp (nat_mod.comp .id (const 2)) (const 1)).of_eq fun n => by cases H : n.bodd <;> simp [Nat.mod_two_of_bodd, H] theorem nat_div2 : Primrec Nat.div2 := (nat_div.comp .id (const 2)).of_eq fun n => n.div2_val.symm theorem nat_double : Primrec (fun n : ℕ => 2 * n) := nat_mul.comp (const _) Primrec.id theorem nat_double_succ : Primrec (fun n : ℕ => 2 * n + 1) := nat_double |> Primrec.succ.comp end Primrec section variable {α : Type*} {β : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable σ] variable (H : Nat.Primrec fun n => Encodable.encode (@decode (List β) _ n)) open Primrec private def prim : Primcodable (List β) := ⟨H⟩ private theorem list_casesOn' {f : α → List β} {g : α → σ} {h : α → β × List β → σ} (hf : haveI := prim H; Primrec f) (hg : Primrec g) (hh : haveI := prim H; Primrec₂ h) : @Primrec _ σ _ _ fun a => List.casesOn (f a) (g a) fun b l => h a (b, l) := letI := prim H have : @Primrec _ (Option σ) _ _ fun a => (@decode (Option (β × List β)) _ (encode (f a))).map fun o => Option.casesOn o (g a) (h a) := ((@map_decode_iff _ (Option (β × List β)) _ _ _ _ _).2 <| to₂ <| option_casesOn snd (hg.comp fst) (hh.comp₂ (fst.comp₂ Primrec₂.left) Primrec₂.right)).comp .id (encode_iff.2 hf) option_some_iff.1 <| this.of_eq fun a => by rcases f a with - | ⟨b, l⟩ <;> simp [encodek] private theorem list_foldl' {f : α → List β} {g : α → σ} {h : α → σ × β → σ} (hf : haveI := prim H; Primrec f) (hg : Primrec g) (hh : haveI := prim H; Primrec₂ h) : Primrec fun a => (f a).foldl (fun s b => h a (s, b)) (g a) := by letI := prim H let G (a : α) (IH : σ × List β) : σ × List β := List.casesOn IH.2 IH fun b l => (h a (IH.1, b), l) have hG : Primrec₂ G := list_casesOn' H (snd.comp snd) snd <| to₂ <| pair (hh.comp (fst.comp fst) <| pair ((fst.comp snd).comp fst) (fst.comp snd)) (snd.comp snd) let F := fun (a : α) (n : ℕ) => (G a)^[n] (g a, f a) have hF : Primrec fun a => (F a (encode (f a))).1 := (fst.comp <| nat_iterate (encode_iff.2 hf) (pair hg hf) <| hG) suffices ∀ a n, F a n = (((f a).take n).foldl (fun s b => h a (s, b)) (g a), (f a).drop n) by refine hF.of_eq fun a => ?_ rw [this, List.take_of_length_le (length_le_encode _)] introv dsimp only [F] generalize f a = l generalize g a = x induction n generalizing l x with | zero => rfl | succ n IH => simp only [iterate_succ, comp_apply] rcases l with - | ⟨b, l⟩ <;> simp [G, IH] private theorem list_cons' : (haveI := prim H; Primrec₂ (@List.cons β)) := letI := prim H encode_iff.1 (succ.comp <| Primrec₂.natPair.comp (encode_iff.2 fst) (encode_iff.2 snd)) private theorem list_reverse' : haveI := prim H Primrec (@List.reverse β) := letI := prim H (list_foldl' H .id (const []) <| to₂ <| ((list_cons' H).comp snd fst).comp snd).of_eq (suffices ∀ l r, List.foldl (fun (s : List β) (b : β) => b :: s) r l = List.reverseAux l r from fun l => this l [] fun l => by induction l <;> simp [*, List.reverseAux]) end namespace Primcodable variable {α : Type*} {β : Type*} variable [Primcodable α] [Primcodable β] open Primrec instance sum : Primcodable (α ⊕ β) := ⟨Primrec.nat_iff.1 <| (encode_iff.2 (cond nat_bodd (((@Primrec.decode β _).comp nat_div2).option_map <| to₂ <| nat_double_succ.comp (Primrec.encode.comp snd)) (((@Primrec.decode α _).comp nat_div2).option_map <| to₂ <| nat_double.comp (Primrec.encode.comp snd)))).of_eq fun n => show _ = encode (decodeSum n) by simp only [decodeSum, Nat.boddDiv2_eq] cases Nat.bodd n <;> simp [decodeSum] · cases @decode α _ n.div2 <;> rfl · cases @decode β _ n.div2 <;> rfl⟩ instance list : Primcodable (List α) := ⟨letI H := @Primcodable.prim (List ℕ) _ have : Primrec₂ fun (a : α) (o : Option (List ℕ)) => o.map (List.cons (encode a)) := option_map snd <| (list_cons' H).comp ((@Primrec.encode α _).comp (fst.comp fst)) snd have : Primrec fun n => (ofNat (List ℕ) n).reverse.foldl (fun o m => (@decode α _ m).bind fun a => o.map (List.cons (encode a))) (some []) := list_foldl' H ((list_reverse' H).comp (.ofNat (List ℕ))) (const (some [])) (Primrec.comp₂ (bind_decode_iff.2 <| .swap this) Primrec₂.right) nat_iff.1 <| (encode_iff.2 this).of_eq fun n => by rw [List.foldl_reverse] apply Nat.case_strong_induction_on n; · simp intro n IH; simp rcases @decode α _ n.unpair.1 with - | a; · rfl simp only [decode_eq_ofNat, Option.some.injEq, Option.some_bind, Option.map_some'] suffices ∀ (o : Option (List ℕ)) (p), encode o = encode p → encode (Option.map (List.cons (encode a)) o) = encode (Option.map (List.cons a) p) from this _ _ (IH _ (Nat.unpair_right_le n)) intro o p IH cases o <;> cases p · rfl · injection IH · injection IH · exact congr_arg (fun k => (Nat.pair (encode a) k).succ.succ) (Nat.succ.inj IH)⟩ end Primcodable namespace Primrec variable {α : Type*} {β : Type*} {γ : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable γ] [Primcodable σ] theorem sumInl : Primrec (@Sum.inl α β) := encode_iff.1 <| nat_double.comp Primrec.encode theorem sumInr : Primrec (@Sum.inr α β) := encode_iff.1 <| nat_double_succ.comp Primrec.encode @[deprecated (since := "2025-02-21")] alias sum_inl := Primrec.sumInl @[deprecated (since := "2025-02-21")] alias sum_inr := Primrec.sumInr theorem sumCasesOn {f : α → β ⊕ γ} {g : α → β → σ} {h : α → γ → σ} (hf : Primrec f) (hg : Primrec₂ g) (hh : Primrec₂ h) : @Primrec _ σ _ _ fun a => Sum.casesOn (f a) (g a) (h a) := option_some_iff.1 <| (cond (nat_bodd.comp <| encode_iff.2 hf) (option_map (Primrec.decode.comp <| nat_div2.comp <| encode_iff.2 hf) hh) (option_map (Primrec.decode.comp <| nat_div2.comp <| encode_iff.2 hf) hg)).of_eq fun a => by rcases f a with b | c <;> simp [Nat.div2_val, encodek] @[deprecated (since := "2025-02-21")] alias sum_casesOn := Primrec.sumCasesOn theorem list_cons : Primrec₂ (@List.cons α) := list_cons' Primcodable.prim theorem list_casesOn {f : α → List β} {g : α → σ} {h : α → β × List β → σ} : Primrec f → Primrec g → Primrec₂ h → @Primrec _ σ _ _ fun a => List.casesOn (f a) (g a) fun b l => h a (b, l) := list_casesOn' Primcodable.prim theorem list_foldl {f : α → List β} {g : α → σ} {h : α → σ × β → σ} : Primrec f → Primrec g → Primrec₂ h → Primrec fun a => (f a).foldl (fun s b => h a (s, b)) (g a) := list_foldl' Primcodable.prim theorem list_reverse : Primrec (@List.reverse α) := list_reverse' Primcodable.prim theorem list_foldr {f : α → List β} {g : α → σ} {h : α → β × σ → σ} (hf : Primrec f) (hg : Primrec g) (hh : Primrec₂ h) : Primrec fun a => (f a).foldr (fun b s => h a (b, s)) (g a) := (list_foldl (list_reverse.comp hf) hg <| to₂ <| hh.comp fst <| (pair snd fst).comp snd).of_eq fun a => by simp [List.foldl_reverse] theorem list_head? : Primrec (@List.head? α) := (list_casesOn .id (const none) (option_some_iff.2 <| fst.comp snd).to₂).of_eq fun l => by cases l <;> rfl theorem list_headI [Inhabited α] : Primrec (@List.headI α _) := (option_iget.comp list_head?).of_eq fun l => l.head!_eq_head?.symm theorem list_tail : Primrec (@List.tail α) := (list_casesOn .id (const []) (snd.comp snd).to₂).of_eq fun l => by cases l <;> rfl theorem list_rec {f : α → List β} {g : α → σ} {h : α → β × List β × σ → σ} (hf : Primrec f) (hg : Primrec g) (hh : Primrec₂ h) : @Primrec _ σ _ _ fun a => List.recOn (f a) (g a) fun b l IH => h a (b, l, IH) := let F (a : α) := (f a).foldr (fun (b : β) (s : List β × σ) => (b :: s.1, h a (b, s))) ([], g a) have : Primrec F := list_foldr hf (pair (const []) hg) <| to₂ <| pair ((list_cons.comp fst (fst.comp snd)).comp snd) hh (snd.comp this).of_eq fun a => by suffices F a = (f a, List.recOn (f a) (g a) fun b l IH => h a (b, l, IH)) by rw [this] dsimp [F] induction' f a with b l IH <;> simp [*] theorem list_getElem? : Primrec₂ ((·[·]? : List α → ℕ → Option α)) := let F (l : List α) (n : ℕ) := l.foldl (fun (s : ℕ ⊕ α) (a : α) => Sum.casesOn s (@Nat.casesOn (fun _ => ℕ ⊕ α) · (Sum.inr a) Sum.inl) Sum.inr) (Sum.inl n) have hF : Primrec₂ F := (list_foldl fst (sumInl.comp snd) ((sumCasesOn fst (nat_casesOn snd (sumInr.comp <| snd.comp fst) (sumInl.comp snd).to₂).to₂ (sumInr.comp snd).to₂).comp snd).to₂).to₂ have : @Primrec _ (Option α) _ _ fun p : List α × ℕ => Sum.casesOn (F p.1 p.2) (fun _ => none) some := sumCasesOn hF (const none).to₂ (option_some.comp snd).to₂ this.to₂.of_eq fun l n => by dsimp; symm induction' l with a l IH generalizing n; · rfl rcases n with - | n · dsimp [F] clear IH induction' l with _ l IH <;> simp_all · simpa using IH .. @[deprecated (since := "2025-02-14")] alias list_get? := list_getElem? theorem list_getD (d : α) : Primrec₂ fun l n => List.getD l n d := by simp only [List.getD_eq_getElem?_getD] exact option_getD.comp₂ list_getElem? (const _) theorem list_getI [Inhabited α] : Primrec₂ (@List.getI α _) := list_getD _ theorem list_append : Primrec₂ ((· ++ ·) : List α → List α → List α) := (list_foldr fst snd <| to₂ <| comp (@list_cons α _) snd).to₂.of_eq fun l₁ l₂ => by induction l₁ <;> simp [*] theorem list_concat : Primrec₂ fun l (a : α) => l ++ [a] := list_append.comp fst (list_cons.comp snd (const [])) theorem list_map {f : α → List β} {g : α → β → σ} (hf : Primrec f) (hg : Primrec₂ g) : Primrec fun a => (f a).map (g a) := (list_foldr hf (const []) <| to₂ <| list_cons.comp (hg.comp fst (fst.comp snd)) (snd.comp snd)).of_eq fun a => by induction f a <;> simp [*] theorem list_range : Primrec List.range := (nat_rec' .id (const []) ((list_concat.comp snd fst).comp snd).to₂).of_eq fun n => by simp; induction n <;> simp [*, List.range_succ] theorem list_flatten : Primrec (@List.flatten α) := (list_foldr .id (const []) <| to₂ <| comp (@list_append α _) snd).of_eq fun l => by dsimp; induction l <;> simp [*] theorem list_flatMap {f : α → List β} {g : α → β → List σ} (hf : Primrec f) (hg : Primrec₂ g) : Primrec (fun a => (f a).flatMap (g a)) := list_flatten.comp (list_map hf hg) theorem optionToList : Primrec (Option.toList : Option α → List α) := (option_casesOn Primrec.id (const []) ((list_cons.comp Primrec.id (const [])).comp₂ Primrec₂.right)).of_eq (fun o => by rcases o <;> simp) theorem listFilterMap {f : α → List β} {g : α → β → Option σ} (hf : Primrec f) (hg : Primrec₂ g) : Primrec fun a => (f a).filterMap (g a) := (list_flatMap hf (comp₂ optionToList hg)).of_eq fun _ ↦ Eq.symm <| List.filterMap_eq_flatMap_toList _ _ theorem list_length : Primrec (@List.length α) := (list_foldr (@Primrec.id (List α) _) (const 0) <| to₂ <| (succ.comp <| snd.comp snd).to₂).of_eq fun l => by dsimp; induction l <;> simp [*] theorem list_findIdx {f : α → List β} {p : α → β → Bool} (hf : Primrec f) (hp : Primrec₂ p) : Primrec fun a => (f a).findIdx (p a) := (list_foldr hf (const 0) <| to₂ <| cond (hp.comp fst <| fst.comp snd) (const 0) (succ.comp <| snd.comp snd)).of_eq fun a => by dsimp; induction f a <;> simp [List.findIdx_cons, *] theorem list_idxOf [DecidableEq α] : Primrec₂ (@List.idxOf α _) := to₂ <| list_findIdx snd <| Primrec.beq.comp₂ snd.to₂ (fst.comp fst).to₂ @[deprecated (since := "2025-01-30")] alias list_indexOf := list_idxOf theorem nat_strong_rec (f : α → ℕ → σ) {g : α → List σ → Option σ} (hg : Primrec₂ g) (H : ∀ a n, g a ((List.range n).map (f a)) = some (f a n)) : Primrec₂ f := suffices Primrec₂ fun a n => (List.range n).map (f a) from Primrec₂.option_some_iff.1 <| (list_getElem?.comp (this.comp fst (succ.comp snd)) snd).to₂.of_eq fun a n => by simp [List.getElem?_range (Nat.lt_succ_self n)] Primrec₂.option_some_iff.1 <| (nat_rec (const (some [])) (to₂ <| option_bind (snd.comp snd) <| to₂ <| option_map (hg.comp (fst.comp fst) snd) (to₂ <| list_concat.comp (snd.comp fst) snd))).of_eq fun a n => by induction n with | zero => rfl | succ n IH => simp [IH, H, List.range_succ] theorem listLookup [DecidableEq α] : Primrec₂ (List.lookup : α → List (α × β) → Option β) := (to₂ <| list_rec snd (const none) <| to₂ <| cond (Primrec.beq.comp (fst.comp fst) (fst.comp <| fst.comp snd)) (option_some.comp <| snd.comp <| fst.comp snd) (snd.comp <| snd.comp snd)).of_eq fun a ps => by induction' ps with p ps ih <;> simp [List.lookup, *] cases ha : a == p.1 <;> simp [ha] theorem nat_omega_rec' (f : β → σ) {m : β → ℕ} {l : β → List β} {g : β → List σ → Option σ} (hm : Primrec m) (hl : Primrec l) (hg : Primrec₂ g) (Ord : ∀ b, ∀ b' ∈ l b, m b' < m b) (H : ∀ b, g b ((l b).map f) = some (f b)) : Primrec f := by haveI : DecidableEq β := Encodable.decidableEqOfEncodable β let mapGraph (M : List (β × σ)) (bs : List β) : List σ := bs.flatMap (Option.toList <| M.lookup ·) let bindList (b : β) : ℕ → List β := fun n ↦ n.rec [b] fun _ bs ↦ bs.flatMap l let graph (b : β) : ℕ → List (β × σ) := fun i ↦ i.rec [] fun i ih ↦ (bindList b (m b - i)).filterMap fun b' ↦ (g b' <| mapGraph ih (l b')).map (b', ·) have mapGraph_primrec : Primrec₂ mapGraph := to₂ <| list_flatMap snd <| optionToList.comp₂ <| listLookup.comp₂ .right (fst.comp₂ .left) have bindList_primrec : Primrec₂ (bindList) := nat_rec' snd (list_cons.comp fst (const [])) (to₂ <| list_flatMap (snd.comp snd) (hl.comp₂ .right)) have graph_primrec : Primrec₂ (graph) := to₂ <| nat_rec' snd (const []) <| to₂ <| listFilterMap (bindList_primrec.comp (fst.comp fst) (nat_sub.comp (hm.comp <| fst.comp fst) (fst.comp snd))) <| to₂ <| option_map (hg.comp snd (mapGraph_primrec.comp (snd.comp <| snd.comp fst) (hl.comp snd))) (Primrec₂.pair.comp₂ (snd.comp₂ .left) .right) have : Primrec (fun b => (graph b (m b + 1))[0]?.map Prod.snd) := option_map (list_getElem?.comp (graph_primrec.comp Primrec.id (succ.comp hm)) (const 0)) (snd.comp₂ Primrec₂.right) exact option_some_iff.mp <| this.of_eq <| fun b ↦ by have graph_eq_map_bindList (i : ℕ) (hi : i ≤ m b + 1) : graph b i = (bindList b (m b + 1 - i)).map fun x ↦ (x, f x) := by have bindList_eq_nil : bindList b (m b + 1) = [] := have bindList_m_lt (k : ℕ) : ∀ b' ∈ bindList b k, m b' < m b + 1 - k := by induction' k with k ih <;> simp [bindList] intro a₂ a₁ ha₁ ha₂ have : k ≤ m b := Nat.lt_succ.mp (by simpa using Nat.add_lt_of_lt_sub <| Nat.zero_lt_of_lt (ih a₁ ha₁)) have : m a₁ ≤ m b - k := Nat.lt_succ.mp (by rw [← Nat.succ_sub this]; simpa using ih a₁ ha₁) exact lt_of_lt_of_le (Ord a₁ a₂ ha₂) this List.eq_nil_iff_forall_not_mem.mpr (by intro b' ha'; by_contra; simpa using bindList_m_lt (m b + 1) b' ha') have mapGraph_graph {bs bs' : List β} (has : bs' ⊆ bs) : mapGraph (bs.map <| fun x => (x, f x)) bs' = bs'.map f := by induction' bs' with b bs' ih <;> simp [mapGraph] · have : b ∈ bs ∧ bs' ⊆ bs := by simpa using has rcases this with ⟨ha, has'⟩ simpa [List.lookup_graph f ha] using ih has' have graph_succ : ∀ i, graph b (i + 1) = (bindList b (m b - i)).filterMap fun b' => (g b' <| mapGraph (graph b i) (l b')).map (b', ·) := fun _ => rfl have bindList_succ : ∀ i, bindList b (i + 1) = (bindList b i).flatMap l := fun _ => rfl induction' i with i ih · symm; simpa [graph] using bindList_eq_nil · simp only [graph_succ, ih (Nat.le_of_lt hi), Nat.succ_sub (Nat.lt_succ.mp hi), Nat.succ_eq_add_one, bindList_succ, Nat.reduceSubDiff] apply List.filterMap_eq_map_iff_forall_eq_some.mpr intro b' ha'; simp; rw [mapGraph_graph] · exact H b' · exact (List.infix_flatMap_of_mem ha' l).subset simp [graph_eq_map_bindList (m b + 1) (Nat.le_refl _), bindList] theorem nat_omega_rec (f : α → β → σ) {m : α → β → ℕ} {l : α → β → List β} {g : α → β × List σ → Option σ} (hm : Primrec₂ m) (hl : Primrec₂ l) (hg : Primrec₂ g) (Ord : ∀ a b, ∀ b' ∈ l a b, m a b' < m a b) (H : ∀ a b, g a (b, (l a b).map (f a)) = some (f a b)) : Primrec₂ f := Primrec₂.uncurry.mp <| nat_omega_rec' (Function.uncurry f) (Primrec₂.uncurry.mpr hm) (list_map (hl.comp fst snd) (Primrec₂.pair.comp₂ (fst.comp₂ .left) .right)) (hg.comp₂ (fst.comp₂ .left) (Primrec₂.pair.comp₂ (snd.comp₂ .left) .right)) (by simpa using Ord) (by simpa [Function.comp] using H) end Primrec namespace Primcodable variable {α : Type*} [Primcodable α] open Primrec /-- A subtype of a primitive recursive predicate is `Primcodable`. -/ def subtype {p : α → Prop} [DecidablePred p] (hp : PrimrecPred p) : Primcodable (Subtype p) := ⟨have : Primrec fun n => (@decode α _ n).bind fun a => Option.guard p a := option_bind .decode (option_guard (hp.comp snd).to₂ snd) nat_iff.1 <| (encode_iff.2 this).of_eq fun n => show _ = encode ((@decode α _ n).bind fun _ => _) by rcases @decode α _ n with - | a; · rfl dsimp [Option.guard] by_cases h : p a <;> simp [h]; rfl⟩ instance fin {n} : Primcodable (Fin n) := @ofEquiv _ _ (subtype <| nat_lt.comp .id (const n)) Fin.equivSubtype instance vector {n} : Primcodable (List.Vector α n) := subtype ((@Primrec.eq ℕ _ _).comp list_length (const _)) instance finArrow {n} : Primcodable (Fin n → α) := ofEquiv _ (Equiv.vectorEquivFin _ _).symm section ULower attribute [local instance] Encodable.decidableRangeEncode Encodable.decidableEqOfEncodable theorem mem_range_encode : PrimrecPred (fun n => n ∈ Set.range (encode : α → ℕ)) := have : PrimrecPred fun n => Encodable.decode₂ α n ≠ none := .not (Primrec.eq.comp (.option_bind .decode (.ite (Primrec.eq.comp (Primrec.encode.comp .snd) .fst) (Primrec.option_some.comp .snd) (.const _))) (.const _)) this.of_eq fun _ => decode₂_ne_none_iff instance ulower : Primcodable (ULower α) := Primcodable.subtype mem_range_encode end ULower end Primcodable namespace Primrec variable {α : Type*} {β : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable σ] theorem subtype_val {p : α → Prop} [DecidablePred p] {hp : PrimrecPred p} : haveI := Primcodable.subtype hp Primrec (@Subtype.val α p) := by letI := Primcodable.subtype hp refine (@Primcodable.prim (Subtype p)).of_eq fun n => ?_ rcases @decode (Subtype p) _ n with (_ | ⟨a, h⟩) <;> rfl theorem subtype_val_iff {p : β → Prop} [DecidablePred p] {hp : PrimrecPred p} {f : α → Subtype p} : haveI := Primcodable.subtype hp (Primrec fun a => (f a).1) ↔ Primrec f := by letI := Primcodable.subtype hp refine ⟨fun h => ?_, fun hf => subtype_val.comp hf⟩ refine Nat.Primrec.of_eq h fun n => ?_ rcases @decode α _ n with - | a; · rfl simp; rfl theorem subtype_mk {p : β → Prop} [DecidablePred p] {hp : PrimrecPred p} {f : α → β} {h : ∀ a, p (f a)} (hf : Primrec f) : haveI := Primcodable.subtype hp Primrec fun a => @Subtype.mk β p (f a) (h a) := subtype_val_iff.1 hf theorem option_get {f : α → Option β} {h : ∀ a, (f a).isSome} : Primrec f → Primrec fun a => (f a).get (h a) := by intro hf refine (Nat.Primrec.pred.comp hf).of_eq fun n => ?_ generalize hx : @decode α _ n = x cases x <;> simp theorem ulower_down : Primrec (ULower.down : α → ULower α) := letI : ∀ a, Decidable (a ∈ Set.range (encode : α → ℕ)) := decidableRangeEncode _ subtype_mk .encode theorem ulower_up : Primrec (ULower.up : ULower α → α) := letI : ∀ a, Decidable (a ∈ Set.range (encode : α → ℕ)) := decidableRangeEncode _ option_get (Primrec.decode₂.comp subtype_val) theorem fin_val_iff {n} {f : α → Fin n} : (Primrec fun a => (f a).1) ↔ Primrec f := by letI : Primcodable { a // id a < n } := Primcodable.subtype (nat_lt.comp .id (const _)) exact (Iff.trans (by rfl) subtype_val_iff).trans (of_equiv_iff _) theorem fin_val {n} : Primrec (fun (i : Fin n) => (i : ℕ)) := fin_val_iff.2 .id theorem fin_succ {n} : Primrec (@Fin.succ n) := fin_val_iff.1 <| by simp [succ.comp fin_val] theorem vector_toList {n} : Primrec (@List.Vector.toList α n) := subtype_val theorem vector_toList_iff {n} {f : α → List.Vector β n} : (Primrec fun a => (f a).toList) ↔ Primrec f := subtype_val_iff theorem vector_cons {n} : Primrec₂ (@List.Vector.cons α n) := vector_toList_iff.1 <| by simpa using list_cons.comp fst (vector_toList_iff.2 snd) theorem vector_length {n} : Primrec (@List.Vector.length α n) := const _ theorem vector_head {n} : Primrec (@List.Vector.head α n) := option_some_iff.1 <| (list_head?.comp vector_toList).of_eq fun ⟨_ :: _, _⟩ => rfl theorem vector_tail {n} : Primrec (@List.Vector.tail α n) := vector_toList_iff.1 <| (list_tail.comp vector_toList).of_eq fun ⟨l, h⟩ => by cases l <;> rfl theorem vector_get {n} : Primrec₂ (@List.Vector.get α n) := option_some_iff.1 <| (list_getElem?.comp (vector_toList.comp fst) (fin_val.comp snd)).of_eq fun a => by simp [Vector.get_eq_get_toList] theorem list_ofFn : ∀ {n} {f : Fin n → α → σ}, (∀ i, Primrec (f i)) → Primrec fun a => List.ofFn fun i => f i a | 0, _, _ => by simp only [List.ofFn_zero]; exact const [] | n + 1, f, hf => by simpa [List.ofFn_succ] using list_cons.comp (hf 0) (list_ofFn fun i => hf i.succ) theorem vector_ofFn {n} {f : Fin n → α → σ} (hf : ∀ i, Primrec (f i)) : Primrec fun a => List.Vector.ofFn fun i => f i a := vector_toList_iff.1 <| by simp [list_ofFn hf] theorem vector_get' {n} : Primrec (@List.Vector.get α n) := of_equiv_symm theorem vector_ofFn' {n} : Primrec (@List.Vector.ofFn α n) := of_equiv theorem fin_app {n} : Primrec₂ (@id (Fin n → σ)) := (vector_get.comp (vector_ofFn'.comp fst) snd).of_eq fun ⟨v, i⟩ => by simp theorem fin_curry₁ {n} {f : Fin n → α → σ} : Primrec₂ f ↔ ∀ i, Primrec (f i) := ⟨fun h i => h.comp (const i) .id, fun h => (vector_get.comp ((vector_ofFn h).comp snd) fst).of_eq fun a => by simp⟩ theorem fin_curry {n} {f : α → Fin n → σ} : Primrec f ↔ Primrec₂ f := ⟨fun h => fin_app.comp (h.comp fst) snd, fun h => (vector_get'.comp (vector_ofFn fun i => show Primrec fun a => f a i from h.comp .id (const i))).of_eq fun a => by funext i; simp⟩ end Primrec namespace Nat open List.Vector /-- An alternative inductive definition of `Primrec` which does not use the pairing function on ℕ, and so has to work with n-ary functions on ℕ instead of unary functions. We prove that this is equivalent to the regular notion in `to_prim` and `of_prim`. -/ inductive Primrec' : ∀ {n}, (List.Vector ℕ n → ℕ) → Prop | zero : @Primrec' 0 fun _ => 0 | succ : @Primrec' 1 fun v => succ v.head | get {n} (i : Fin n) : Primrec' fun v => v.get i | comp {m n f} (g : Fin n → List.Vector ℕ m → ℕ) : Primrec' f → (∀ i, Primrec' (g i)) → Primrec' fun a => f (List.Vector.ofFn fun i => g i a) | prec {n f g} : @Primrec' n f → @Primrec' (n + 2) g → Primrec' fun v : List.Vector ℕ (n + 1) => v.head.rec (f v.tail) fun y IH => g (y ::ᵥ IH ::ᵥ v.tail) end Nat namespace Nat.Primrec' open List.Vector Primrec theorem to_prim {n f} (pf : @Nat.Primrec' n f) : Primrec f := by induction pf with | zero => exact .const 0 | succ => exact _root_.Primrec.succ.comp .vector_head | get i => exact Primrec.vector_get.comp .id (.const i) | comp _ _ _ hf hg => exact hf.comp (.vector_ofFn fun i => hg i) | @prec n f g _ _ hf hg => exact .nat_rec' .vector_head (hf.comp Primrec.vector_tail) (hg.comp <| Primrec.vector_cons.comp (Primrec.fst.comp .snd) <| Primrec.vector_cons.comp (Primrec.snd.comp .snd) <| (@Primrec.vector_tail _ _ (n + 1)).comp .fst).to₂ theorem of_eq {n} {f g : List.Vector ℕ n → ℕ} (hf : Primrec' f) (H : ∀ i, f i = g i) : Primrec' g := (funext H : f = g) ▸ hf theorem const {n} : ∀ m, @Primrec' n fun _ => m | 0 => zero.comp Fin.elim0 fun i => i.elim0 | m + 1 => succ.comp _ fun _ => const m theorem head {n : ℕ} : @Primrec' n.succ head := (get 0).of_eq fun v => by simp [get_zero] theorem tail {n f} (hf : @Primrec' n f) : @Primrec' n.succ fun v => f v.tail := (hf.comp _ fun i => @get _ i.succ).of_eq fun v => by rw [← ofFn_get v.tail]; congr; funext i; simp /-- A function from vectors to vectors is primitive recursive when all of its projections are. -/ def Vec {n m} (f : List.Vector ℕ n → List.Vector ℕ m) : Prop := ∀ i, Primrec' fun v => (f v).get i protected theorem nil {n} : @Vec n 0 fun _ => nil := fun i => i.elim0 protected theorem cons {n m f g} (hf : @Primrec' n f) (hg : @Vec n m g) : Vec fun v => f v ::ᵥ g v := fun i => Fin.cases (by simp [*]) (fun i => by simp [hg i]) i theorem idv {n} : @Vec n n id := get theorem comp' {n m f g} (hf : @Primrec' m f) (hg : @Vec n m g) : Primrec' fun v => f (g v) := (hf.comp _ hg).of_eq fun v => by simp theorem comp₁ (f : ℕ → ℕ) (hf : @Primrec' 1 fun v => f v.head) {n g} (hg : @Primrec' n g) : Primrec' fun v => f (g v) := hf.comp _ fun _ => hg theorem comp₂ (f : ℕ → ℕ → ℕ) (hf : @Primrec' 2 fun v => f v.head v.tail.head) {n g h} (hg : @Primrec' n g) (hh : @Primrec' n h) : Primrec' fun v => f (g v) (h v) := by simpa using hf.comp' (hg.cons <| hh.cons Primrec'.nil) theorem prec' {n f g h} (hf : @Primrec' n f) (hg : @Primrec' n g) (hh : @Primrec' (n + 2) h) : @Primrec' n fun v => (f v).rec (g v) fun y IH : ℕ => h (y ::ᵥ IH ::ᵥ v) := by simpa using comp' (prec hg hh) (hf.cons idv) theorem pred : @Primrec' 1 fun v => v.head.pred := (prec' head (const 0) head).of_eq fun v => by simp; cases v.head <;> rfl theorem add : @Primrec' 2 fun v => v.head + v.tail.head := (prec head (succ.comp₁ _ (tail head))).of_eq fun v => by simp; induction v.head <;> simp [*, Nat.succ_add] theorem sub : @Primrec' 2 fun v => v.head - v.tail.head := by have : @Primrec' 2 fun v ↦ (fun a b ↦ b - a) v.head v.tail.head := by refine (prec head (pred.comp₁ _ (tail head))).of_eq fun v => ?_ simp; induction v.head <;> simp [*, Nat.sub_add_eq] simpa using comp₂ (fun a b => b - a) this (tail head) head theorem mul : @Primrec' 2 fun v => v.head * v.tail.head := (prec (const 0) (tail (add.comp₂ _ (tail head) head))).of_eq fun v => by simp; induction v.head <;> simp [*, Nat.succ_mul]; rw [add_comm] theorem if_lt {n a b f g} (ha : @Primrec' n a) (hb : @Primrec' n b) (hf : @Primrec' n f) (hg : @Primrec' n g) : @Primrec' n fun v => if a v < b v then f v else g v := (prec' (sub.comp₂ _ hb ha) hg (tail <| tail hf)).of_eq fun v => by cases e : b v - a v · simp [not_lt.2 (Nat.sub_eq_zero_iff_le.mp e)] · simp [Nat.lt_of_sub_eq_succ e] theorem natPair : @Primrec' 2 fun v => v.head.pair v.tail.head := if_lt head (tail head) (add.comp₂ _ (tail <| mul.comp₂ _ head head) head) (add.comp₂ _ (add.comp₂ _ (mul.comp₂ _ head head) head) (tail head)) protected theorem encode : ∀ {n}, @Primrec' n encode | 0 => (const 0).of_eq fun v => by rw [v.eq_nil]; rfl | _ + 1 => (succ.comp₁ _ (natPair.comp₂ _ head (tail Primrec'.encode))).of_eq fun ⟨_ :: _, _⟩ => rfl theorem sqrt : @Primrec' 1 fun v => v.head.sqrt := by suffices H : ∀ n : ℕ, n.sqrt = n.rec 0 fun x y => if x.succ < y.succ * y.succ then y else y.succ by simp only [H, succ_eq_add_one] have := @prec' 1 _ _ (fun v => by have x := v.head; have y := v.tail.head exact if x.succ < y.succ * y.succ then y else y.succ) head (const 0) ?_ · exact this have x1 : @Primrec' 3 fun v => v.head.succ := succ.comp₁ _ head have y1 : @Primrec' 3 fun v => v.tail.head.succ := succ.comp₁ _ (tail head) exact if_lt x1 (mul.comp₂ _ y1 y1) (tail head) y1 introv; symm induction' n with n IH; · simp dsimp; rw [IH]; split_ifs with h · exact le_antisymm (Nat.sqrt_le_sqrt (Nat.le_succ _)) (Nat.lt_succ_iff.1 <| Nat.sqrt_lt.2 h) · exact Nat.eq_sqrt.2 ⟨not_lt.1 h, Nat.sqrt_lt.1 <| Nat.lt_succ_iff.2 <| Nat.sqrt_succ_le_succ_sqrt _⟩ theorem unpair₁ {n f} (hf : @Primrec' n f) : @Primrec' n fun v => (f v).unpair.1 := by have s := sqrt.comp₁ _ hf have fss := sub.comp₂ _ hf (mul.comp₂ _ s s) refine (if_lt fss s fss s).of_eq fun v => ?_ simp [Nat.unpair]; split_ifs <;> rfl theorem unpair₂ {n f} (hf : @Primrec' n f) : @Primrec' n fun v => (f v).unpair.2 := by have s := sqrt.comp₁ _ hf have fss := sub.comp₂ _ hf (mul.comp₂ _ s s) refine (if_lt fss s s (sub.comp₂ _ fss s)).of_eq fun v => ?_ simp [Nat.unpair]; split_ifs <;> rfl theorem of_prim {n f} : Primrec f → @Primrec' n f := suffices ∀ f, Nat.Primrec f → @Primrec' 1 fun v => f v.head from fun hf => (pred.comp₁ _ <| (this _ hf).comp₁ (fun m => Encodable.encode <| (@decode (List.Vector ℕ n) _ m).map f) Primrec'.encode).of_eq fun i => by simp [encodek]
fun f hf => by induction hf with | zero => exact const 0 | succ => exact succ | left => exact unpair₁ head
Mathlib/Computability/Primrec.lean
1,395
1,399
/- Copyright (c) 2020 Nicolò Cavalleri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nicolò Cavalleri, Sébastien Gouëzel, Heather Macbeth, Patrick Massot, Floris van Doorn -/ import Mathlib.Analysis.Normed.Operator.BoundedLinearMaps import Mathlib.Topology.FiberBundle.Basic /-! # Vector bundles In this file we define (topological) vector bundles. Let `B` be the base space, let `F` be a normed space over a normed field `R`, and let `E : B → Type*` be a `FiberBundle` with fiber `F`, in which, for each `x`, the fiber `E x` is a topological vector space over `R`. To have a vector bundle structure on `Bundle.TotalSpace F E`, one should additionally have the following properties: * The bundle trivializations in the trivialization atlas should be continuous linear equivs in the fibers; * For any two trivializations `e`, `e'` in the atlas the transition function considered as a map from `B` into `F →L[R] F` is continuous on `e.baseSet ∩ e'.baseSet` with respect to the operator norm topology on `F →L[R] F`. If these conditions are satisfied, we register the typeclass `VectorBundle R F E`. We define constructions on vector bundles like pullbacks and direct sums in other files. ## Main Definitions * `Trivialization.IsLinear`: a class stating that a trivialization is fiberwise linear on its base set. * `Trivialization.linearEquivAt` and `Trivialization.continuousLinearMapAt` are the (continuous) linear fiberwise equivalences a trivialization induces. * They have forward maps `Trivialization.linearMapAt` / `Trivialization.continuousLinearMapAt` and inverses `Trivialization.symmₗ` / `Trivialization.symmL`. Note that these are all defined everywhere, since they are extended using the zero function. * `Trivialization.coordChangeL` is the coordinate change induced by two trivializations. It only makes sense on the intersection of their base sets, but is extended outside it using the identity. * Given a continuous (semi)linear map between `E x` and `E' y` where `E` and `E'` are bundles over possibly different base sets, `ContinuousLinearMap.inCoordinates` turns this into a continuous (semi)linear map between the chosen fibers of those bundles. ## Implementation notes The implementation choices in the vector bundle definition are discussed in the "Implementation notes" section of `Mathlib.Topology.FiberBundle.Basic`. ## Tags Vector bundle -/ noncomputable section open Bundle Set Topology variable (R : Type*) {B : Type*} (F : Type*) (E : B → Type*) section TopologicalVectorSpace variable {F E} variable [Semiring R] [TopologicalSpace F] [TopologicalSpace B] /-- A mixin class for `Pretrivialization`, stating that a pretrivialization is fiberwise linear with respect to given module structures on its fibers and the model fiber. -/ protected class Pretrivialization.IsLinear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] (e : Pretrivialization F (π F E)) : Prop where linear : ∀ b ∈ e.baseSet, IsLinearMap R fun x : E b => (e ⟨b, x⟩).2 namespace Pretrivialization variable (e : Pretrivialization F (π F E)) {x : TotalSpace F E} {b : B} {y : E b} theorem linear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) : IsLinearMap R fun x : E b => (e ⟨b, x⟩).2 := Pretrivialization.IsLinear.linear b hb variable [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] /-- A fiberwise linear inverse to `e`. -/ @[simps!] protected def symmₗ (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) : F →ₗ[R] E b := by refine IsLinearMap.mk' (e.symm b) ?_ by_cases hb : b ∈ e.baseSet · exact (((e.linear R hb).mk' _).inverse (e.symm b) (e.symm_apply_apply_mk hb) fun v ↦ congr_arg Prod.snd <| e.apply_mk_symm hb v).isLinear · rw [e.coe_symm_of_not_mem hb] exact (0 : F →ₗ[R] E b).isLinear /-- A pretrivialization for a vector bundle defines linear equivalences between the fibers and the model space. -/ @[simps -fullyApplied] def linearEquivAt (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) (hb : b ∈ e.baseSet) : E b ≃ₗ[R] F where toFun y := (e ⟨b, y⟩).2 invFun := e.symm b left_inv := e.symm_apply_apply_mk hb right_inv v := by simp_rw [e.apply_mk_symm hb v] map_add' v w := (e.linear R hb).map_add v w map_smul' c v := (e.linear R hb).map_smul c v open Classical in /-- A fiberwise linear map equal to `e` on `e.baseSet`. -/ protected def linearMapAt (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) : E b →ₗ[R] F := if hb : b ∈ e.baseSet then e.linearEquivAt R b hb else 0 variable {R} open Classical in theorem coe_linearMapAt (e : Pretrivialization F (π F E)) [e.IsLinear R] (b : B) : ⇑(e.linearMapAt R b) = fun y => if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 := by rw [Pretrivialization.linearMapAt] split_ifs <;> rfl theorem coe_linearMapAt_of_mem (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) : ⇑(e.linearMapAt R b) = fun y => (e ⟨b, y⟩).2 := by simp_rw [coe_linearMapAt, if_pos hb] open Classical in theorem linearMapAt_apply (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (y : E b) : e.linearMapAt R b y = if b ∈ e.baseSet then (e ⟨b, y⟩).2 else 0 := by rw [coe_linearMapAt] theorem linearMapAt_def_of_mem (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) : e.linearMapAt R b = e.linearEquivAt R b hb := dif_pos hb theorem linearMapAt_def_of_not_mem (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∉ e.baseSet) : e.linearMapAt R b = 0 := dif_neg hb theorem linearMapAt_eq_zero (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∉ e.baseSet) : e.linearMapAt R b = 0 := dif_neg hb theorem symmₗ_linearMapAt (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) (y : E b) : e.symmₗ R b (e.linearMapAt R b y) = y := by rw [e.linearMapAt_def_of_mem hb] exact (e.linearEquivAt R b hb).left_inv y theorem linearMapAt_symmₗ (e : Pretrivialization F (π F E)) [e.IsLinear R] {b : B} (hb : b ∈ e.baseSet) (y : F) : e.linearMapAt R b (e.symmₗ R b y) = y := by rw [e.linearMapAt_def_of_mem hb] exact (e.linearEquivAt R b hb).right_inv y end Pretrivialization variable [TopologicalSpace (TotalSpace F E)] /-- A mixin class for `Trivialization`, stating that a trivialization is fiberwise linear with respect to given module structures on its fibers and the model fiber. -/ protected class Trivialization.IsLinear [AddCommMonoid F] [Module R F] [∀ x, AddCommMonoid (E x)] [∀ x, Module R (E x)] (e : Trivialization F (π F E)) : Prop where
linear : ∀ b ∈ e.baseSet, IsLinearMap R fun x : E b => (e ⟨b, x⟩).2 namespace Trivialization
Mathlib/Topology/VectorBundle/Basic.lean
157
160
/- Copyright (c) 2022 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.Data.Set.Finite.Lemmas import Mathlib.ModelTheory.Substructures /-! # Finitely Generated First-Order Structures This file defines what it means for a first-order (sub)structure to be finitely or countably generated, similarly to other finitely-generated objects in the algebra library. ## Main Definitions - `FirstOrder.Language.Substructure.FG` indicates that a substructure is finitely generated. - `FirstOrder.Language.Structure.FG` indicates that a structure is finitely generated. - `FirstOrder.Language.Substructure.CG` indicates that a substructure is countably generated. - `FirstOrder.Language.Structure.CG` indicates that a structure is countably generated. ## TODO Develop a more unified definition of finite generation using the theory of closure operators, or use this definition of finite generation to define the others. -/ open FirstOrder Set namespace FirstOrder namespace Language open Structure variable {L : Language} {M : Type*} [L.Structure M] namespace Substructure /-- A substructure of `M` is finitely generated if it is the closure of a finite subset of `M`. -/ def FG (N : L.Substructure M) : Prop := ∃ S : Finset M, closure L S = N theorem fg_def {N : L.Substructure M} : N.FG ↔ ∃ S : Set M, S.Finite ∧ closure L S = N := ⟨fun ⟨t, h⟩ => ⟨_, Finset.finite_toSet t, h⟩, by rintro ⟨t', h, rfl⟩ rcases Finite.exists_finset_coe h with ⟨t, rfl⟩ exact ⟨t, rfl⟩⟩ theorem fg_iff_exists_fin_generating_family {N : L.Substructure M} : N.FG ↔ ∃ (n : ℕ) (s : Fin n → M), closure L (range s) = N := by rw [fg_def] constructor · rintro ⟨S, Sfin, hS⟩ obtain ⟨n, f, rfl⟩ := Sfin.fin_embedding exact ⟨n, f, hS⟩ · rintro ⟨n, s, hs⟩ exact ⟨range s, finite_range s, hs⟩ theorem fg_bot : (⊥ : L.Substructure M).FG := ⟨∅, by rw [Finset.coe_empty, closure_empty]⟩ instance instInhabited_fg : Inhabited { S : L.Substructure M // S.FG } := ⟨⊥, fg_bot⟩ theorem fg_closure {s : Set M} (hs : s.Finite) : FG (closure L s) := ⟨hs.toFinset, by rw [hs.coe_toFinset]⟩ theorem fg_closure_singleton (x : M) : FG (closure L ({x} : Set M)) := fg_closure (finite_singleton x) theorem FG.sup {N₁ N₂ : L.Substructure M} (hN₁ : N₁.FG) (hN₂ : N₂.FG) : (N₁ ⊔ N₂).FG := let ⟨t₁, ht₁⟩ := fg_def.1 hN₁ let ⟨t₂, ht₂⟩ := fg_def.1 hN₂ fg_def.2 ⟨t₁ ∪ t₂, ht₁.1.union ht₂.1, by rw [closure_union, ht₁.2, ht₂.2]⟩ theorem FG.map {N : Type*} [L.Structure N] (f : M →[L] N) {s : L.Substructure M} (hs : s.FG) : (s.map f).FG := let ⟨t, ht⟩ := fg_def.1 hs fg_def.2 ⟨f '' t, ht.1.image _, by rw [closure_image, ht.2]⟩ theorem FG.of_map_embedding {N : Type*} [L.Structure N] (f : M ↪[L] N) {s : L.Substructure M} (hs : (s.map f.toHom).FG) : s.FG := by rcases hs with ⟨t, h⟩ rw [fg_def] refine ⟨f ⁻¹' t, t.finite_toSet.preimage f.injective.injOn, ?_⟩ have hf : Function.Injective f.toHom := f.injective refine map_injective_of_injective hf ?_ rw [← h, map_closure, Embedding.coe_toHom, image_preimage_eq_of_subset] intro x hx have h' := subset_closure (L := L) hx rw [h] at h' exact Hom.map_le_range h' theorem FG.of_finite {s : L.Substructure M} [h : Finite s] : s.FG := ⟨Set.Finite.toFinset h, by simp only [Finite.coe_toFinset, closure_eq]⟩ theorem FG.finite [L.IsRelational] {S : L.Substructure M} (h : S.FG) : Finite S := by obtain ⟨s, rfl⟩ := h have hs := s.finite_toSet rw [← closure_eq_of_isRelational L (s : Set M)] at hs exact hs theorem fg_iff_finite [L.IsRelational] {S : L.Substructure M} : S.FG ↔ Finite S := ⟨FG.finite, fun _ => FG.of_finite⟩ /-- A substructure of `M` is countably generated if it is the closure of a countable subset of `M`. -/ def CG (N : L.Substructure M) : Prop := ∃ S : Set M, S.Countable ∧ closure L S = N theorem cg_def {N : L.Substructure M} : N.CG ↔ ∃ S : Set M, S.Countable ∧ closure L S = N := Iff.refl _ theorem FG.cg {N : L.Substructure M} (h : N.FG) : N.CG := by obtain ⟨s, hf, rfl⟩ := fg_def.1 h exact ⟨s, hf.countable, rfl⟩ theorem cg_iff_empty_or_exists_nat_generating_family {N : L.Substructure M} : N.CG ↔ N = (∅ : Set M) ∨ ∃ s : ℕ → M, closure L (range s) = N := by rw [cg_def] constructor · rintro ⟨S, Scount, hS⟩ rcases eq_empty_or_nonempty (N : Set M) with h | h · exact Or.intro_left _ h obtain ⟨f, h'⟩ := (Scount.union (Set.countable_singleton h.some)).exists_eq_range (singleton_nonempty h.some).inr refine Or.intro_right _ ⟨f, ?_⟩ rw [← h', closure_union, hS, sup_eq_left, closure_le] exact singleton_subset_iff.2 h.some_mem · intro h rcases h with h | h · refine ⟨∅, countable_empty, closure_eq_of_le (empty_subset _) ?_⟩ rw [← SetLike.coe_subset_coe, h] exact empty_subset _ · obtain ⟨f, rfl⟩ := h exact ⟨range f, countable_range _, rfl⟩ theorem cg_bot : (⊥ : L.Substructure M).CG := fg_bot.cg theorem cg_closure {s : Set M} (hs : s.Countable) : CG (closure L s) := ⟨s, hs, rfl⟩ theorem cg_closure_singleton (x : M) : CG (closure L ({x} : Set M)) := (fg_closure_singleton x).cg theorem CG.sup {N₁ N₂ : L.Substructure M} (hN₁ : N₁.CG) (hN₂ : N₂.CG) : (N₁ ⊔ N₂).CG := let ⟨t₁, ht₁⟩ := cg_def.1 hN₁ let ⟨t₂, ht₂⟩ := cg_def.1 hN₂ cg_def.2 ⟨t₁ ∪ t₂, ht₁.1.union ht₂.1, by rw [closure_union, ht₁.2, ht₂.2]⟩ theorem CG.map {N : Type*} [L.Structure N] (f : M →[L] N) {s : L.Substructure M} (hs : s.CG) : (s.map f).CG := let ⟨t, ht⟩ := cg_def.1 hs cg_def.2 ⟨f '' t, ht.1.image _, by rw [closure_image, ht.2]⟩ theorem CG.of_map_embedding {N : Type*} [L.Structure N] (f : M ↪[L] N) {s : L.Substructure M} (hs : (s.map f.toHom).CG) : s.CG := by rcases hs with ⟨t, h1, h2⟩ rw [cg_def] refine ⟨f ⁻¹' t, h1.preimage f.injective, ?_⟩ have hf : Function.Injective f.toHom := f.injective refine map_injective_of_injective hf ?_ rw [← h2, map_closure, Embedding.coe_toHom, image_preimage_eq_of_subset] intro x hx have h' := subset_closure (L := L) hx rw [h2] at h' exact Hom.map_le_range h' theorem cg_iff_countable [Countable (Σ l, L.Functions l)] {s : L.Substructure M} : s.CG ↔ Countable s := by refine ⟨?_, fun h => ⟨s, h.to_set, s.closure_eq⟩⟩
rintro ⟨s, h, rfl⟩ exact h.substructure_closure L theorem cg_of_countable {s : L.Substructure M} [h : Countable s] : s.CG := ⟨s, h.to_set, s.closure_eq⟩
Mathlib/ModelTheory/FinitelyGenerated.lean
176
180
/- 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 _ _
Mathlib/Analysis/Seminorm.lean
1,079
1,087
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Order.Ring.Nat import Mathlib.Algebra.Ring.Int.Defs import Mathlib.Data.Nat.Bitwise import Mathlib.Data.Nat.Cast.Order.Basic import Mathlib.Data.Nat.PSub import Mathlib.Data.Nat.Size import Mathlib.Data.Num.Bitwise /-! # Properties of the binary representation of integers -/ open Int attribute [local simp] add_assoc namespace PosNum variable {α : Type*} @[simp, norm_cast] theorem cast_one [One α] [Add α] : ((1 : PosNum) : α) = 1 := rfl @[simp] theorem cast_one' [One α] [Add α] : (PosNum.one : α) = 1 := rfl @[simp, norm_cast] theorem cast_bit0 [One α] [Add α] (n : PosNum) : (n.bit0 : α) = (n : α) + n := rfl @[simp, norm_cast] theorem cast_bit1 [One α] [Add α] (n : PosNum) : (n.bit1 : α) = ((n : α) + n) + 1 := rfl @[simp, norm_cast] theorem cast_to_nat [AddMonoidWithOne α] : ∀ n : PosNum, ((n : ℕ) : α) = n | 1 => Nat.cast_one | bit0 p => by dsimp; rw [Nat.cast_add, p.cast_to_nat] | bit1 p => by dsimp; rw [Nat.cast_add, Nat.cast_add, Nat.cast_one, p.cast_to_nat] @[norm_cast] theorem to_nat_to_int (n : PosNum) : ((n : ℕ) : ℤ) = n := cast_to_nat _ @[simp, norm_cast] theorem cast_to_int [AddGroupWithOne α] (n : PosNum) : ((n : ℤ) : α) = n := by rw [← to_nat_to_int, Int.cast_natCast, cast_to_nat] theorem succ_to_nat : ∀ n, (succ n : ℕ) = n + 1 | 1 => rfl | bit0 _ => rfl | bit1 p => (congr_arg (fun n ↦ n + n) (succ_to_nat p)).trans <| show ↑p + 1 + ↑p + 1 = ↑p + ↑p + 1 + 1 by simp [add_left_comm] theorem one_add (n : PosNum) : 1 + n = succ n := by cases n <;> rfl theorem add_one (n : PosNum) : n + 1 = succ n := by cases n <;> rfl @[norm_cast] theorem add_to_nat : ∀ m n, ((m + n : PosNum) : ℕ) = m + n | 1, b => by rw [one_add b, succ_to_nat, add_comm, cast_one] | a, 1 => by rw [add_one a, succ_to_nat, cast_one] | bit0 a, bit0 b => (congr_arg (fun n ↦ n + n) (add_to_nat a b)).trans <| add_add_add_comm _ _ _ _ | bit0 a, bit1 b => (congr_arg (fun n ↦ (n + n) + 1) (add_to_nat a b)).trans <| show (a + b + (a + b) + 1 : ℕ) = a + a + (b + b + 1) by simp [add_left_comm] | bit1 a, bit0 b => (congr_arg (fun n ↦ (n + n) + 1) (add_to_nat a b)).trans <| show (a + b + (a + b) + 1 : ℕ) = a + a + 1 + (b + b) by simp [add_comm, add_left_comm] | bit1 a, bit1 b => show (succ (a + b) + succ (a + b) : ℕ) = a + a + 1 + (b + b + 1) by rw [succ_to_nat, add_to_nat a b]; simp [add_left_comm] theorem add_succ : ∀ m n : PosNum, m + succ n = succ (m + n) | 1, b => by simp [one_add] | bit0 a, 1 => congr_arg bit0 (add_one a) | bit1 a, 1 => congr_arg bit1 (add_one a) | bit0 _, bit0 _ => rfl | bit0 a, bit1 b => congr_arg bit0 (add_succ a b) | bit1 _, bit0 _ => rfl | bit1 a, bit1 b => congr_arg bit1 (add_succ a b) theorem bit0_of_bit0 : ∀ n, n + n = bit0 n | 1 => rfl | bit0 p => congr_arg bit0 (bit0_of_bit0 p) | bit1 p => show bit0 (succ (p + p)) = _ by rw [bit0_of_bit0 p, succ] theorem bit1_of_bit1 (n : PosNum) : (n + n) + 1 = bit1 n := show (n + n) + 1 = bit1 n by rw [add_one, bit0_of_bit0, succ] @[norm_cast] theorem mul_to_nat (m) : ∀ n, ((m * n : PosNum) : ℕ) = m * n | 1 => (mul_one _).symm | bit0 p => show (↑(m * p) + ↑(m * p) : ℕ) = ↑m * (p + p) by rw [mul_to_nat m p, left_distrib] | bit1 p => (add_to_nat (bit0 (m * p)) m).trans <| show (↑(m * p) + ↑(m * p) + ↑m : ℕ) = ↑m * (p + p) + m by rw [mul_to_nat m p, left_distrib] theorem to_nat_pos : ∀ n : PosNum, 0 < (n : ℕ) | 1 => Nat.zero_lt_one | bit0 p => let h := to_nat_pos p add_pos h h | bit1 _p => Nat.succ_pos _ theorem cmp_to_nat_lemma {m n : PosNum} : (m : ℕ) < n → (bit1 m : ℕ) < bit0 n := show (m : ℕ) < n → (m + m + 1 + 1 : ℕ) ≤ n + n by intro h; rw [Nat.add_right_comm m m 1, add_assoc]; exact Nat.add_le_add h h theorem cmp_swap (m) : ∀ n, (cmp m n).swap = cmp n m := by induction' m with m IH m IH <;> intro n <;> obtain - | n | n := n <;> unfold cmp <;> try { rfl } <;> rw [← IH] <;> cases cmp m n <;> rfl theorem cmp_to_nat : ∀ m n, (Ordering.casesOn (cmp m n) ((m : ℕ) < n) (m = n) ((n : ℕ) < m) : Prop) | 1, 1 => rfl | bit0 a, 1 => let h : (1 : ℕ) ≤ a := to_nat_pos a Nat.add_le_add h h | bit1 a, 1 => Nat.succ_lt_succ <| to_nat_pos <| bit0 a | 1, bit0 b => let h : (1 : ℕ) ≤ b := to_nat_pos b Nat.add_le_add h h | 1, bit1 b => Nat.succ_lt_succ <| to_nat_pos <| bit0 b | bit0 a, bit0 b => by dsimp [cmp] have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this · exact Nat.add_lt_add this this · rw [this] · exact Nat.add_lt_add this this | bit0 a, bit1 b => by dsimp [cmp] have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this · exact Nat.le_succ_of_le (Nat.add_lt_add this this) · rw [this] apply Nat.lt_succ_self · exact cmp_to_nat_lemma this | bit1 a, bit0 b => by dsimp [cmp] have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this · exact cmp_to_nat_lemma this · rw [this] apply Nat.lt_succ_self · exact Nat.le_succ_of_le (Nat.add_lt_add this this) | bit1 a, bit1 b => by dsimp [cmp] have := cmp_to_nat a b; revert this; cases cmp a b <;> dsimp <;> intro this · exact Nat.succ_lt_succ (Nat.add_lt_add this this) · rw [this] · exact Nat.succ_lt_succ (Nat.add_lt_add this this) @[norm_cast] theorem lt_to_nat {m n : PosNum} : (m : ℕ) < n ↔ m < n := show (m : ℕ) < n ↔ cmp m n = Ordering.lt from match cmp m n, cmp_to_nat m n with | Ordering.lt, h => by simp only at h; simp [h] | Ordering.eq, h => by simp only at h; simp [h, lt_irrefl] | Ordering.gt, h => by simp [not_lt_of_gt h] @[norm_cast] theorem le_to_nat {m n : PosNum} : (m : ℕ) ≤ n ↔ m ≤ n := by rw [← not_lt]; exact not_congr lt_to_nat end PosNum namespace Num variable {α : Type*} open PosNum theorem add_zero (n : Num) : n + 0 = n := by cases n <;> rfl theorem zero_add (n : Num) : 0 + n = n := by cases n <;> rfl theorem add_one : ∀ n : Num, n + 1 = succ n | 0 => rfl | pos p => by cases p <;> rfl theorem add_succ : ∀ m n : Num, m + succ n = succ (m + n) | 0, n => by simp [zero_add] | pos p, 0 => show pos (p + 1) = succ (pos p + 0) by rw [PosNum.add_one, add_zero, succ, succ'] | pos _, pos _ => congr_arg pos (PosNum.add_succ _ _) theorem bit0_of_bit0 : ∀ n : Num, n + n = n.bit0 | 0 => rfl | pos p => congr_arg pos p.bit0_of_bit0 theorem bit1_of_bit1 : ∀ n : Num, (n + n) + 1 = n.bit1 | 0 => rfl | pos p => congr_arg pos p.bit1_of_bit1 @[simp] theorem ofNat'_zero : Num.ofNat' 0 = 0 := by simp [Num.ofNat'] theorem ofNat'_bit (b n) : ofNat' (Nat.bit b n) = cond b Num.bit1 Num.bit0 (ofNat' n) := Nat.binaryRec_eq _ _ (.inl rfl) @[simp] theorem ofNat'_one : Num.ofNat' 1 = 1 := by erw [ofNat'_bit true 0, cond, ofNat'_zero]; rfl theorem bit1_succ : ∀ n : Num, n.bit1.succ = n.succ.bit0 | 0 => rfl | pos _n => rfl theorem ofNat'_succ : ∀ {n}, ofNat' (n + 1) = ofNat' n + 1 := @(Nat.binaryRec (by simp [zero_add]) fun b n ih => by cases b · erw [ofNat'_bit true n, ofNat'_bit] simp only [← bit1_of_bit1, ← bit0_of_bit0, cond] · rw [show n.bit true + 1 = (n + 1).bit false by simp [Nat.bit, mul_add], ofNat'_bit, ofNat'_bit, ih] simp only [cond, add_one, bit1_succ]) @[simp] theorem add_ofNat' (m n) : Num.ofNat' (m + n) = Num.ofNat' m + Num.ofNat' n := by induction n · simp only [Nat.add_zero, ofNat'_zero, add_zero] · simp only [Nat.add_succ, Nat.add_zero, ofNat'_succ, add_one, add_succ, *] @[simp, norm_cast] theorem cast_zero [Zero α] [One α] [Add α] : ((0 : Num) : α) = 0 := rfl @[simp] theorem cast_zero' [Zero α] [One α] [Add α] : (Num.zero : α) = 0 := rfl @[simp, norm_cast] theorem cast_one [Zero α] [One α] [Add α] : ((1 : Num) : α) = 1 := rfl @[simp] theorem cast_pos [Zero α] [One α] [Add α] (n : PosNum) : (Num.pos n : α) = n := rfl theorem succ'_to_nat : ∀ n, (succ' n : ℕ) = n + 1 | 0 => (Nat.zero_add _).symm | pos _p => PosNum.succ_to_nat _ theorem succ_to_nat (n) : (succ n : ℕ) = n + 1 := succ'_to_nat n @[simp, norm_cast] theorem cast_to_nat [AddMonoidWithOne α] : ∀ n : Num, ((n : ℕ) : α) = n | 0 => Nat.cast_zero | pos p => p.cast_to_nat @[norm_cast] theorem add_to_nat : ∀ m n, ((m + n : Num) : ℕ) = m + n | 0, 0 => rfl | 0, pos _q => (Nat.zero_add _).symm | pos _p, 0 => rfl | pos _p, pos _q => PosNum.add_to_nat _ _ @[norm_cast] theorem mul_to_nat : ∀ m n, ((m * n : Num) : ℕ) = m * n | 0, 0 => rfl | 0, pos _q => (zero_mul _).symm | pos _p, 0 => rfl | pos _p, pos _q => PosNum.mul_to_nat _ _ theorem cmp_to_nat : ∀ m n, (Ordering.casesOn (cmp m n) ((m : ℕ) < n) (m = n) ((n : ℕ) < m) : Prop) | 0, 0 => rfl | 0, pos _ => to_nat_pos _ | pos _, 0 => to_nat_pos _ | pos a, pos b => by have := PosNum.cmp_to_nat a b; revert this; dsimp [cmp]; cases PosNum.cmp a b exacts [id, congr_arg pos, id] @[norm_cast] theorem lt_to_nat {m n : Num} : (m : ℕ) < n ↔ m < n := show (m : ℕ) < n ↔ cmp m n = Ordering.lt from match cmp m n, cmp_to_nat m n with | Ordering.lt, h => by simp only at h; simp [h] | Ordering.eq, h => by simp only at h; simp [h, lt_irrefl] | Ordering.gt, h => by simp [not_lt_of_gt h] @[norm_cast] theorem le_to_nat {m n : Num} : (m : ℕ) ≤ n ↔ m ≤ n := by rw [← not_lt]; exact not_congr lt_to_nat end Num namespace PosNum @[simp] theorem of_to_nat' : ∀ n : PosNum, Num.ofNat' (n : ℕ) = Num.pos n | 1 => by erw [@Num.ofNat'_bit true 0, Num.ofNat'_zero]; rfl | bit0 p => by simpa only [Nat.bit_false, cond_false, two_mul, of_to_nat' p] using Num.ofNat'_bit false p | bit1 p => by simpa only [Nat.bit_true, cond_true, two_mul, of_to_nat' p] using Num.ofNat'_bit true p end PosNum namespace Num @[simp, norm_cast] theorem of_to_nat' : ∀ n : Num, Num.ofNat' (n : ℕ) = n | 0 => ofNat'_zero | pos p => p.of_to_nat' lemma toNat_injective : Function.Injective (castNum : Num → ℕ) := Function.LeftInverse.injective of_to_nat' @[norm_cast] theorem to_nat_inj {m n : Num} : (m : ℕ) = n ↔ m = n := toNat_injective.eq_iff /-- This tactic tries to turn an (in)equality about `Num`s to one about `Nat`s by rewriting. ```lean example (n : Num) (m : Num) : n ≤ n + m := by transfer_rw exact Nat.le_add_right _ _ ``` -/ scoped macro (name := transfer_rw) "transfer_rw" : tactic => `(tactic| (repeat first | rw [← to_nat_inj] | rw [← lt_to_nat] | rw [← le_to_nat] repeat first | rw [add_to_nat] | rw [mul_to_nat] | rw [cast_one] | rw [cast_zero])) /-- This tactic tries to prove (in)equalities about `Num`s by transferring them to the `Nat` world and then trying to call `simp`. ```lean example (n : Num) (m : Num) : n ≤ n + m := by transfer ``` -/ scoped macro (name := transfer) "transfer" : tactic => `(tactic| (intros; transfer_rw; try simp)) instance addMonoid : AddMonoid Num where add := (· + ·) zero := 0 zero_add := zero_add add_zero := add_zero add_assoc := by transfer nsmul := nsmulRec instance addMonoidWithOne : AddMonoidWithOne Num := { Num.addMonoid with natCast := Num.ofNat' one := 1 natCast_zero := ofNat'_zero natCast_succ := fun _ => ofNat'_succ } instance commSemiring : CommSemiring Num where __ := Num.addMonoid __ := Num.addMonoidWithOne mul := (· * ·) npow := @npowRec Num ⟨1⟩ ⟨(· * ·)⟩ mul_zero _ := by rw [← to_nat_inj, mul_to_nat, cast_zero, mul_zero] zero_mul _ := by rw [← to_nat_inj, mul_to_nat, cast_zero, zero_mul] mul_one _ := by rw [← to_nat_inj, mul_to_nat, cast_one, mul_one] one_mul _ := by rw [← to_nat_inj, mul_to_nat, cast_one, one_mul] add_comm _ _ := by simp_rw [← to_nat_inj, add_to_nat, add_comm] mul_comm _ _ := by simp_rw [← to_nat_inj, mul_to_nat, mul_comm] mul_assoc _ _ _ := by simp_rw [← to_nat_inj, mul_to_nat, mul_assoc] left_distrib _ _ _ := by simp only [← to_nat_inj, mul_to_nat, add_to_nat, mul_add] right_distrib _ _ _ := by simp only [← to_nat_inj, mul_to_nat, add_to_nat, add_mul] instance partialOrder : PartialOrder Num where lt_iff_le_not_le a b := by simp only [← lt_to_nat, ← le_to_nat, lt_iff_le_not_le] le_refl := by transfer le_trans a b c := by transfer_rw; apply le_trans le_antisymm a b := by transfer_rw; apply le_antisymm instance isOrderedCancelAddMonoid : IsOrderedCancelAddMonoid Num where add_le_add_left a b h c := by revert h; transfer_rw; exact fun h => add_le_add_left h c le_of_add_le_add_left a b c := show a + b ≤ a + c → b ≤ c by transfer_rw; apply le_of_add_le_add_left instance linearOrder : LinearOrder Num := { le_total := by intro a b transfer_rw apply le_total toDecidableLT := Num.decidableLT toDecidableLE := Num.decidableLE -- This is relying on an automatically generated instance name, -- generated in a `deriving` handler. -- See https://github.com/leanprover/lean4/issues/2343 toDecidableEq := instDecidableEqNum } instance isStrictOrderedRing : IsStrictOrderedRing Num := { zero_le_one := by decide mul_lt_mul_of_pos_left := by intro a b c transfer_rw apply mul_lt_mul_of_pos_left mul_lt_mul_of_pos_right := by intro a b c transfer_rw apply mul_lt_mul_of_pos_right exists_pair_ne := ⟨0, 1, by decide⟩ } @[norm_cast] theorem add_of_nat (m n) : ((m + n : ℕ) : Num) = m + n := add_ofNat' _ _ @[norm_cast] theorem to_nat_to_int (n : Num) : ((n : ℕ) : ℤ) = n := cast_to_nat _ @[simp, norm_cast] theorem cast_to_int {α} [AddGroupWithOne α] (n : Num) : ((n : ℤ) : α) = n := by rw [← to_nat_to_int, Int.cast_natCast, cast_to_nat] theorem to_of_nat : ∀ n : ℕ, ((n : Num) : ℕ) = n | 0 => by rw [Nat.cast_zero, cast_zero] | n + 1 => by rw [Nat.cast_succ, add_one, succ_to_nat, to_of_nat n] @[simp, norm_cast] theorem of_natCast {α} [AddMonoidWithOne α] (n : ℕ) : ((n : Num) : α) = n := by rw [← cast_to_nat, to_of_nat] @[norm_cast] theorem of_nat_inj {m n : ℕ} : (m : Num) = n ↔ m = n := ⟨fun h => Function.LeftInverse.injective to_of_nat h, congr_arg _⟩ -- The priority should be `high`er than `cast_to_nat`. @[simp high, norm_cast] theorem of_to_nat : ∀ n : Num, ((n : ℕ) : Num) = n := of_to_nat' @[norm_cast] theorem dvd_to_nat (m n : Num) : (m : ℕ) ∣ n ↔ m ∣ n := ⟨fun ⟨k, e⟩ => ⟨k, by rw [← of_to_nat n, e]; simp⟩, fun ⟨k, e⟩ => ⟨k, by simp [e, mul_to_nat]⟩⟩ end Num namespace PosNum variable {α : Type*} open Num -- The priority should be `high`er than `cast_to_nat`. @[simp high, norm_cast] theorem of_to_nat : ∀ n : PosNum, ((n : ℕ) : Num) = Num.pos n := of_to_nat' @[norm_cast] theorem to_nat_inj {m n : PosNum} : (m : ℕ) = n ↔ m = n := ⟨fun h => Num.pos.inj <| by rw [← PosNum.of_to_nat, ← PosNum.of_to_nat, h], congr_arg _⟩ theorem pred'_to_nat : ∀ n, (pred' n : ℕ) = Nat.pred n | 1 => rfl | bit0 n => have : Nat.succ ↑(pred' n) = ↑n := by rw [pred'_to_nat n, Nat.succ_pred_eq_of_pos (to_nat_pos n)] match (motive := ∀ k : Num, Nat.succ ↑k = ↑n → ↑(Num.casesOn k 1 bit1 : PosNum) = Nat.pred (n + n)) pred' n, this with | 0, (h : ((1 : Num) : ℕ) = n) => by rw [← to_nat_inj.1 h]; rfl | Num.pos p, (h : Nat.succ ↑p = n) => by rw [← h]; exact (Nat.succ_add p p).symm | bit1 _ => rfl @[simp] theorem pred'_succ' (n) : pred' (succ' n) = n := Num.to_nat_inj.1 <| by rw [pred'_to_nat, succ'_to_nat, Nat.add_one, Nat.pred_succ] @[simp] theorem succ'_pred' (n) : succ' (pred' n) = n := to_nat_inj.1 <| by rw [succ'_to_nat, pred'_to_nat, Nat.add_one, Nat.succ_pred_eq_of_pos (to_nat_pos _)] instance dvd : Dvd PosNum := ⟨fun m n => pos m ∣ pos n⟩ @[norm_cast] theorem dvd_to_nat {m n : PosNum} : (m : ℕ) ∣ n ↔ m ∣ n := Num.dvd_to_nat (pos m) (pos n) theorem size_to_nat : ∀ n, (size n : ℕ) = Nat.size n | 1 => Nat.size_one.symm | bit0 n => by rw [size, succ_to_nat, size_to_nat n, cast_bit0, ← two_mul] erw [@Nat.size_bit false n] have := to_nat_pos n dsimp [Nat.bit]; omega | bit1 n => by rw [size, succ_to_nat, size_to_nat n, cast_bit1, ← two_mul] erw [@Nat.size_bit true n] dsimp [Nat.bit]; omega theorem size_eq_natSize : ∀ n, (size n : ℕ) = natSize n | 1 => rfl | bit0 n => by rw [size, succ_to_nat, natSize, size_eq_natSize n] | bit1 n => by rw [size, succ_to_nat, natSize, size_eq_natSize n] theorem natSize_to_nat (n) : natSize n = Nat.size n := by rw [← size_eq_natSize, size_to_nat] theorem natSize_pos (n) : 0 < natSize n := by cases n <;> apply Nat.succ_pos /-- This tactic tries to turn an (in)equality about `PosNum`s to one about `Nat`s by rewriting. ```lean example (n : PosNum) (m : PosNum) : n ≤ n + m := by transfer_rw exact Nat.le_add_right _ _ ``` -/ scoped macro (name := transfer_rw) "transfer_rw" : tactic => `(tactic| (repeat first | rw [← to_nat_inj] | rw [← lt_to_nat] | rw [← le_to_nat] repeat first | rw [add_to_nat] | rw [mul_to_nat] | rw [cast_one] | rw [cast_zero])) /-- This tactic tries to prove (in)equalities about `PosNum`s by transferring them to the `Nat` world and then trying to call `simp`. ```lean example (n : PosNum) (m : PosNum) : n ≤ n + m := by transfer ``` -/ scoped macro (name := transfer) "transfer" : tactic => `(tactic| (intros; transfer_rw; try simp [add_comm, add_left_comm, mul_comm, mul_left_comm])) instance addCommSemigroup : AddCommSemigroup PosNum where add := (· + ·) add_assoc := by transfer add_comm := by transfer instance commMonoid : CommMonoid PosNum where mul := (· * ·) one := (1 : PosNum) npow := @npowRec PosNum ⟨1⟩ ⟨(· * ·)⟩ mul_assoc := by transfer one_mul := by transfer mul_one := by transfer mul_comm := by transfer instance distrib : Distrib PosNum where add := (· + ·) mul := (· * ·) left_distrib := by transfer; simp [mul_add] right_distrib := by transfer; simp [mul_add, mul_comm] instance linearOrder : LinearOrder PosNum where lt := (· < ·) lt_iff_le_not_le := by intro a b transfer_rw apply lt_iff_le_not_le le := (· ≤ ·) le_refl := by transfer le_trans := by intro a b c transfer_rw apply le_trans le_antisymm := by intro a b transfer_rw apply le_antisymm le_total := by intro a b transfer_rw apply le_total toDecidableLT := by infer_instance toDecidableLE := by infer_instance toDecidableEq := by infer_instance @[simp] theorem cast_to_num (n : PosNum) : ↑n = Num.pos n := by rw [← cast_to_nat, ← of_to_nat n] @[simp, norm_cast] theorem bit_to_nat (b n) : (bit b n : ℕ) = Nat.bit b n := by cases b <;> simp [bit, two_mul] @[simp, norm_cast] theorem cast_add [AddMonoidWithOne α] (m n) : ((m + n : PosNum) : α) = m + n := by rw [← cast_to_nat, add_to_nat, Nat.cast_add, cast_to_nat, cast_to_nat] @[simp 500, norm_cast] theorem cast_succ [AddMonoidWithOne α] (n : PosNum) : (succ n : α) = n + 1 := by rw [← add_one, cast_add, cast_one] @[simp, norm_cast] theorem cast_inj [AddMonoidWithOne α] [CharZero α] {m n : PosNum} : (m : α) = n ↔ m = n := by rw [← cast_to_nat m, ← cast_to_nat n, Nat.cast_inj, to_nat_inj] @[simp] theorem one_le_cast [Semiring α] [PartialOrder α] [IsStrictOrderedRing α] (n : PosNum) : (1 : α) ≤ n := by rw [← cast_to_nat, ← Nat.cast_one, Nat.cast_le (α := α)]; apply to_nat_pos @[simp] theorem cast_pos [Semiring α] [PartialOrder α] [IsStrictOrderedRing α] (n : PosNum) : 0 < (n : α) := lt_of_lt_of_le zero_lt_one (one_le_cast n) @[simp, norm_cast] theorem cast_mul [NonAssocSemiring α] (m n) : ((m * n : PosNum) : α) = m * n := by rw [← cast_to_nat, mul_to_nat, Nat.cast_mul, cast_to_nat, cast_to_nat] @[simp] theorem cmp_eq (m n) : cmp m n = Ordering.eq ↔ m = n := by have := cmp_to_nat m n -- Porting note: `cases` didn't rewrite at `this`, so `revert` & `intro` are required. revert this; cases cmp m n <;> intro this <;> simp at this ⊢ <;> try { exact this } <;> simp [show m ≠ n from fun e => by rw [e] at this;exact lt_irrefl _ this] @[simp, norm_cast] theorem cast_lt [Semiring α] [PartialOrder α] [IsStrictOrderedRing α] {m n : PosNum} : (m : α) < n ↔ m < n := by rw [← cast_to_nat m, ← cast_to_nat n, Nat.cast_lt (α := α), lt_to_nat] @[simp, norm_cast] theorem cast_le [Semiring α] [LinearOrder α] [IsStrictOrderedRing α] {m n : PosNum} : (m : α) ≤ n ↔ m ≤ n := by rw [← not_lt]; exact not_congr cast_lt end PosNum namespace Num variable {α : Type*} open PosNum theorem bit_to_nat (b n) : (bit b n : ℕ) = Nat.bit b n := by cases b <;> cases n <;> simp [bit, two_mul] <;> rfl theorem cast_succ' [AddMonoidWithOne α] (n) : (succ' n : α) = n + 1 := by rw [← PosNum.cast_to_nat, succ'_to_nat, Nat.cast_add_one, cast_to_nat] theorem cast_succ [AddMonoidWithOne α] (n) : (succ n : α) = n + 1 := cast_succ' n @[simp, norm_cast] theorem cast_add [AddMonoidWithOne α] (m n) : ((m + n : Num) : α) = m + n := by rw [← cast_to_nat, add_to_nat, Nat.cast_add, cast_to_nat, cast_to_nat] @[simp, norm_cast] theorem cast_bit0 [NonAssocSemiring α] (n : Num) : (n.bit0 : α) = 2 * (n : α) := by rw [← bit0_of_bit0, two_mul, cast_add] @[simp, norm_cast] theorem cast_bit1 [NonAssocSemiring α] (n : Num) : (n.bit1 : α) = 2 * (n : α) + 1 := by rw [← bit1_of_bit1, bit0_of_bit0, cast_add, cast_bit0]; rfl @[simp, norm_cast] theorem cast_mul [NonAssocSemiring α] : ∀ m n, ((m * n : Num) : α) = m * n | 0, 0 => (zero_mul _).symm | 0, pos _q => (zero_mul _).symm | pos _p, 0 => (mul_zero _).symm | pos _p, pos _q => PosNum.cast_mul _ _ theorem size_to_nat : ∀ n, (size n : ℕ) = Nat.size n | 0 => Nat.size_zero.symm | pos p => p.size_to_nat theorem size_eq_natSize : ∀ n, (size n : ℕ) = natSize n | 0 => rfl | pos p => p.size_eq_natSize theorem natSize_to_nat (n) : natSize n = Nat.size n := by rw [← size_eq_natSize, size_to_nat] @[simp 999] theorem ofNat'_eq : ∀ n, Num.ofNat' n = n := Nat.binaryRec (by simp) fun b n IH => by tauto theorem zneg_toZNum (n : Num) : -n.toZNum = n.toZNumNeg := by cases n <;> rfl theorem zneg_toZNumNeg (n : Num) : -n.toZNumNeg = n.toZNum := by cases n <;> rfl theorem toZNum_inj {m n : Num} : m.toZNum = n.toZNum ↔ m = n := ⟨fun h => by cases m <;> cases n <;> cases h <;> rfl, congr_arg _⟩ @[simp] theorem cast_toZNum [Zero α] [One α] [Add α] [Neg α] : ∀ n : Num, (n.toZNum : α) = n | 0 => rfl | Num.pos _p => rfl @[simp] theorem cast_toZNumNeg [SubtractionMonoid α] [One α] : ∀ n : Num, (n.toZNumNeg : α) = -n | 0 => neg_zero.symm | Num.pos _p => rfl @[simp] theorem add_toZNum (m n : Num) : Num.toZNum (m + n) = m.toZNum + n.toZNum := by cases m <;> cases n <;> rfl end Num namespace PosNum open Num theorem pred_to_nat {n : PosNum} (h : 1 < n) : (pred n : ℕ) = Nat.pred n := by unfold pred cases e : pred' n · have : (1 : ℕ) ≤ Nat.pred n := Nat.pred_le_pred ((@cast_lt ℕ _ _ _).2 h) rw [← pred'_to_nat, e] at this exact absurd this (by decide) · rw [← pred'_to_nat, e] rfl theorem sub'_one (a : PosNum) : sub' a 1 = (pred' a).toZNum := by cases a <;> rfl theorem one_sub' (a : PosNum) : sub' 1 a = (pred' a).toZNumNeg := by cases a <;> rfl theorem lt_iff_cmp {m n} : m < n ↔ cmp m n = Ordering.lt := Iff.rfl theorem le_iff_cmp {m n} : m ≤ n ↔ cmp m n ≠ Ordering.gt := not_congr <| lt_iff_cmp.trans <| by rw [← cmp_swap]; cases cmp m n <;> decide end PosNum namespace Num variable {α : Type*} open PosNum theorem pred_to_nat : ∀ n : Num, (pred n : ℕ) = Nat.pred n | 0 => rfl | pos p => by rw [pred, PosNum.pred'_to_nat]; rfl theorem ppred_to_nat : ∀ n : Num, (↑) <$> ppred n = Nat.ppred n | 0 => rfl | pos p => by rw [ppred, Option.map_some, Nat.ppred_eq_some.2] rw [PosNum.pred'_to_nat, Nat.succ_pred_eq_of_pos (PosNum.to_nat_pos _)] rfl theorem cmp_swap (m n) : (cmp m n).swap = cmp n m := by cases m <;> cases n <;> try { rfl }; apply PosNum.cmp_swap theorem cmp_eq (m n) : cmp m n = Ordering.eq ↔ m = n := by have := cmp_to_nat m n -- Porting note: `cases` didn't rewrite at `this`, so `revert` & `intro` are required. revert this; cases cmp m n <;> intro this <;> simp at this ⊢ <;> try { exact this } <;> simp [show m ≠ n from fun e => by rw [e] at this; exact lt_irrefl _ this] @[simp, norm_cast] theorem cast_lt [Semiring α] [PartialOrder α] [IsStrictOrderedRing α] {m n : Num} : (m : α) < n ↔ m < n := by rw [← cast_to_nat m, ← cast_to_nat n, Nat.cast_lt (α := α), lt_to_nat] @[simp, norm_cast] theorem cast_le [Semiring α] [LinearOrder α] [IsStrictOrderedRing α] {m n : Num} : (m : α) ≤ n ↔ m ≤ n := by rw [← not_lt]; exact not_congr cast_lt @[simp, norm_cast] theorem cast_inj [Semiring α] [PartialOrder α] [IsStrictOrderedRing α] {m n : Num} : (m : α) = n ↔ m = n := by rw [← cast_to_nat m, ← cast_to_nat n, Nat.cast_inj, to_nat_inj] theorem lt_iff_cmp {m n} : m < n ↔ cmp m n = Ordering.lt :=
Iff.rfl
Mathlib/Data/Num/Lemmas.lean
755
755
/- 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.Finsupp import Mathlib.Data.Finsupp.Order import Mathlib.Order.Interval.Finset.Basic /-! # Finite intervals of finitely supported functions This file provides the `LocallyFiniteOrder` instance for `ι →₀ α` when `α` itself is locally finite and calculates the cardinality of its finite intervals. ## Main declarations * `Finsupp.rangeSingleton`: Postcomposition with `Singleton.singleton` on `Finset` as a `Finsupp`. * `Finsupp.rangeIcc`: Postcomposition with `Finset.Icc` as a `Finsupp`. Both these definitions use the fact that `0 = {0}` to ensure that the resulting function is finitely supported. -/ noncomputable section open Finset Finsupp Function Pointwise variable {ι α : Type*} namespace Finsupp section RangeSingleton variable [Zero α] {f : ι →₀ α} {i : ι} {a : α} /-- Pointwise `Singleton.singleton` bundled as a `Finsupp`. -/ @[simps] def rangeSingleton (f : ι →₀ α) : ι →₀ Finset α where toFun i := {f i} support := f.support mem_support_toFun i := by rw [← not_iff_not, not_mem_support_iff, not_ne_iff] exact singleton_injective.eq_iff.symm theorem mem_rangeSingleton_apply_iff : a ∈ f.rangeSingleton i ↔ a = f i := mem_singleton end RangeSingleton section RangeIcc variable [Zero α] [PartialOrder α] [LocallyFiniteOrder α] [DecidableEq ι] variable {f g : ι →₀ α} {i : ι} {a : α} /-- Pointwise `Finset.Icc` bundled as a `Finsupp`. -/ @[simps toFun] def rangeIcc (f g : ι →₀ α) : ι →₀ Finset α where toFun i := Icc (f i) (g i) support := f.support ∪ g.support mem_support_toFun i := by rw [mem_union, ← not_iff_not, not_or, not_mem_support_iff, not_mem_support_iff, not_ne_iff] exact Icc_eq_singleton_iff.symm lemma coe_rangeIcc (f g : ι →₀ α) : rangeIcc f g i = Icc (f i) (g i) := rfl @[simp] theorem rangeIcc_support (f g : ι →₀ α) : (rangeIcc f g).support = f.support ∪ g.support := rfl theorem mem_rangeIcc_apply_iff : a ∈ f.rangeIcc g i ↔ f i ≤ a ∧ a ≤ g i := mem_Icc end RangeIcc section PartialOrder variable [PartialOrder α] [Zero α] [LocallyFiniteOrder α] [DecidableEq ι] [DecidableEq α] variable (f g : ι →₀ α) instance instLocallyFiniteOrder : LocallyFiniteOrder (ι →₀ α) := LocallyFiniteOrder.ofIcc (ι →₀ α) (fun f g => (f.support ∪ g.support).finsupp <| f.rangeIcc g) fun f g x => by refine (mem_finsupp_iff_of_support_subset <| Finset.subset_of_eq <| rangeIcc_support _ _).trans ?_ simp_rw [mem_rangeIcc_apply_iff] exact forall_and theorem Icc_eq : Icc f g = (f.support ∪ g.support).finsupp (f.rangeIcc g) := rfl theorem card_Icc : #(Icc f g) = ∏ i ∈ f.support ∪ g.support, #(Icc (f i) (g i)):= by simp_rw [Icc_eq, card_finsupp, coe_rangeIcc] theorem card_Ico : #(Ico f g) = ∏ i ∈ f.support ∪ g.support, #(Icc (f i) (g i)) - 1 := by rw [card_Ico_eq_card_Icc_sub_one, card_Icc] theorem card_Ioc : #(Ioc f g) = ∏ i ∈ f.support ∪ g.support, #(Icc (f i) (g i)) - 1 := by rw [card_Ioc_eq_card_Icc_sub_one, card_Icc] theorem card_Ioo : #(Ioo f g) = ∏ i ∈ f.support ∪ g.support, #(Icc (f i) (g i)) - 2 := by rw [card_Ioo_eq_card_Icc_sub_two, card_Icc] end PartialOrder section Lattice variable [Lattice α] [Zero α] [LocallyFiniteOrder α] (f g : ι →₀ α) open scoped Classical in theorem card_uIcc : #(uIcc f g) = ∏ i ∈ f.support ∪ g.support, #(uIcc (f i) (g i)) := by rw [← support_inf_union_support_sup]; exact card_Icc (_ : ι →₀ α) _ end Lattice section CanonicallyOrdered variable [AddCommMonoid α] [PartialOrder α] [CanonicallyOrderedAdd α] [LocallyFiniteOrder α]
variable [DecidableEq ι] [DecidableEq α] (f : ι →₀ α)
Mathlib/Data/Finsupp/Interval.lean
118
119
/- 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 -/ import Mathlib.Data.Matrix.Basic import Mathlib.Data.Matrix.Composition import Mathlib.Data.Matrix.ConjTranspose /-! # Block Matrices ## Main definitions * `Matrix.fromBlocks`: build a block matrix out of 4 blocks * `Matrix.toBlocks₁₁`, `Matrix.toBlocks₁₂`, `Matrix.toBlocks₂₁`, `Matrix.toBlocks₂₂`: extract each of the four blocks from `Matrix.fromBlocks`. * `Matrix.blockDiagonal`: block diagonal of equally sized blocks. On square blocks, this is a ring homomorphisms, `Matrix.blockDiagonalRingHom`. * `Matrix.blockDiag`: extract the blocks from the diagonal of a block diagonal matrix. * `Matrix.blockDiagonal'`: block diagonal of unequally sized blocks. On square blocks, this is a ring homomorphisms, `Matrix.blockDiagonal'RingHom`. * `Matrix.blockDiag'`: extract the blocks from the diagonal of a block diagonal matrix. -/ variable {l m n o p q : Type*} {m' n' p' : o → Type*} variable {R : Type*} {S : Type*} {α : Type*} {β : Type*} open Matrix namespace Matrix theorem dotProduct_block [Fintype m] [Fintype n] [Mul α] [AddCommMonoid α] (v w : m ⊕ n → α) : v ⬝ᵥ w = v ∘ Sum.inl ⬝ᵥ w ∘ Sum.inl + v ∘ Sum.inr ⬝ᵥ w ∘ Sum.inr := Fintype.sum_sum_type _ section BlockMatrices /-- We can form a single large matrix by flattening smaller 'block' matrices of compatible dimensions. -/ @[pp_nodot] def fromBlocks (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) : Matrix (n ⊕ o) (l ⊕ m) α := of <| Sum.elim (fun i => Sum.elim (A i) (B i)) (fun j => Sum.elim (C j) (D j)) @[simp] theorem fromBlocks_apply₁₁ (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (i : n) (j : l) : fromBlocks A B C D (Sum.inl i) (Sum.inl j) = A i j := rfl @[simp] theorem fromBlocks_apply₁₂ (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (i : n) (j : m) : fromBlocks A B C D (Sum.inl i) (Sum.inr j) = B i j := rfl @[simp] theorem fromBlocks_apply₂₁ (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (i : o) (j : l) : fromBlocks A B C D (Sum.inr i) (Sum.inl j) = C i j := rfl @[simp] theorem fromBlocks_apply₂₂ (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (i : o) (j : m) : fromBlocks A B C D (Sum.inr i) (Sum.inr j) = D i j := rfl /-- Given a matrix whose row and column indexes are sum types, we can extract the corresponding "top left" submatrix. -/ def toBlocks₁₁ (M : Matrix (n ⊕ o) (l ⊕ m) α) : Matrix n l α := of fun i j => M (Sum.inl i) (Sum.inl j) /-- Given a matrix whose row and column indexes are sum types, we can extract the corresponding "top right" submatrix. -/ def toBlocks₁₂ (M : Matrix (n ⊕ o) (l ⊕ m) α) : Matrix n m α := of fun i j => M (Sum.inl i) (Sum.inr j) /-- Given a matrix whose row and column indexes are sum types, we can extract the corresponding "bottom left" submatrix. -/ def toBlocks₂₁ (M : Matrix (n ⊕ o) (l ⊕ m) α) : Matrix o l α := of fun i j => M (Sum.inr i) (Sum.inl j) /-- Given a matrix whose row and column indexes are sum types, we can extract the corresponding "bottom right" submatrix. -/ def toBlocks₂₂ (M : Matrix (n ⊕ o) (l ⊕ m) α) : Matrix o m α := of fun i j => M (Sum.inr i) (Sum.inr j) theorem fromBlocks_toBlocks (M : Matrix (n ⊕ o) (l ⊕ m) α) : fromBlocks M.toBlocks₁₁ M.toBlocks₁₂ M.toBlocks₂₁ M.toBlocks₂₂ = M := by ext i j rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> rfl @[simp] theorem toBlocks_fromBlocks₁₁ (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) : (fromBlocks A B C D).toBlocks₁₁ = A := rfl @[simp] theorem toBlocks_fromBlocks₁₂ (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) : (fromBlocks A B C D).toBlocks₁₂ = B := rfl @[simp] theorem toBlocks_fromBlocks₂₁ (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) : (fromBlocks A B C D).toBlocks₂₁ = C := rfl @[simp] theorem toBlocks_fromBlocks₂₂ (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) : (fromBlocks A B C D).toBlocks₂₂ = D := rfl /-- Two block matrices are equal if their blocks are equal. -/ theorem ext_iff_blocks {A B : Matrix (n ⊕ o) (l ⊕ m) α} : A = B ↔ A.toBlocks₁₁ = B.toBlocks₁₁ ∧ A.toBlocks₁₂ = B.toBlocks₁₂ ∧ A.toBlocks₂₁ = B.toBlocks₂₁ ∧ A.toBlocks₂₂ = B.toBlocks₂₂ := ⟨fun h => h ▸ ⟨rfl, rfl, rfl, rfl⟩, fun ⟨h₁₁, h₁₂, h₂₁, h₂₂⟩ => by rw [← fromBlocks_toBlocks A, ← fromBlocks_toBlocks B, h₁₁, h₁₂, h₂₁, h₂₂]⟩ @[simp] theorem fromBlocks_inj {A : Matrix n l α} {B : Matrix n m α} {C : Matrix o l α} {D : Matrix o m α} {A' : Matrix n l α} {B' : Matrix n m α} {C' : Matrix o l α} {D' : Matrix o m α} : fromBlocks A B C D = fromBlocks A' B' C' D' ↔ A = A' ∧ B = B' ∧ C = C' ∧ D = D' := ext_iff_blocks theorem fromBlocks_map (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (f : α → β) : (fromBlocks A B C D).map f = fromBlocks (A.map f) (B.map f) (C.map f) (D.map f) := by ext i j; rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> simp [fromBlocks] theorem fromBlocks_transpose (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) : (fromBlocks A B C D)ᵀ = fromBlocks Aᵀ Cᵀ Bᵀ Dᵀ := by ext i j rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> simp [fromBlocks] theorem fromBlocks_conjTranspose [Star α] (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) : (fromBlocks A B C D)ᴴ = fromBlocks Aᴴ Cᴴ Bᴴ Dᴴ := by simp only [conjTranspose, fromBlocks_transpose, fromBlocks_map] @[simp] theorem fromBlocks_submatrix_sum_swap_left (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (f : p → l ⊕ m) : (fromBlocks A B C D).submatrix Sum.swap f = (fromBlocks C D A B).submatrix id f := by ext i j cases i <;> dsimp <;> cases f j <;> rfl @[simp] theorem fromBlocks_submatrix_sum_swap_right (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (f : p → n ⊕ o) : (fromBlocks A B C D).submatrix f Sum.swap = (fromBlocks B A D C).submatrix f id := by ext i j cases j <;> dsimp <;> cases f i <;> rfl theorem fromBlocks_submatrix_sum_swap_sum_swap {l m n o α : Type*} (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) : (fromBlocks A B C D).submatrix Sum.swap Sum.swap = fromBlocks D C B A := by simp /-- A 2x2 block matrix is block diagonal if the blocks outside of the diagonal vanish -/ def IsTwoBlockDiagonal [Zero α] (A : Matrix (n ⊕ o) (l ⊕ m) α) : Prop := toBlocks₁₂ A = 0 ∧ toBlocks₂₁ A = 0 /-- Let `p` pick out certain rows and `q` pick out certain columns of a matrix `M`. Then `toBlock M p q` is the corresponding block matrix. -/ def toBlock (M : Matrix m n α) (p : m → Prop) (q : n → Prop) : Matrix { a // p a } { a // q a } α := M.submatrix (↑) (↑) @[simp] theorem toBlock_apply (M : Matrix m n α) (p : m → Prop) (q : n → Prop) (i : { a // p a }) (j : { a // q a }) : toBlock M p q i j = M ↑i ↑j := rfl /-- Let `p` pick out certain rows and columns of a square matrix `M`. Then `toSquareBlockProp M p` is the corresponding block matrix. -/ def toSquareBlockProp (M : Matrix m m α) (p : m → Prop) : Matrix { a // p a } { a // p a } α := toBlock M _ _ theorem toSquareBlockProp_def (M : Matrix m m α) (p : m → Prop) : toSquareBlockProp M p = of (fun i j : { a // p a } => M ↑i ↑j) := rfl /-- Let `b` map rows and columns of a square matrix `M` to blocks. Then `toSquareBlock M b k` is the block `k` matrix. -/ def toSquareBlock (M : Matrix m m α) (b : m → β) (k : β) : Matrix { a // b a = k } { a // b a = k } α := toSquareBlockProp M _ theorem toSquareBlock_def (M : Matrix m m α) (b : m → β) (k : β) : toSquareBlock M b k = of (fun i j : { a // b a = k } => M ↑i ↑j) := rfl theorem fromBlocks_smul [SMul R α] (x : R) (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) : x • fromBlocks A B C D = fromBlocks (x • A) (x • B) (x • C) (x • D) := by ext i j; rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> simp [fromBlocks] theorem fromBlocks_neg [Neg R] (A : Matrix n l R) (B : Matrix n m R) (C : Matrix o l R) (D : Matrix o m R) : -fromBlocks A B C D = fromBlocks (-A) (-B) (-C) (-D) := by ext i j cases i <;> cases j <;> simp [fromBlocks] @[simp] theorem fromBlocks_zero [Zero α] : fromBlocks (0 : Matrix n l α) 0 0 (0 : Matrix o m α) = 0 := by ext i j rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> rfl theorem fromBlocks_add [Add α] (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (A' : Matrix n l α) (B' : Matrix n m α) (C' : Matrix o l α) (D' : Matrix o m α) : fromBlocks A B C D + fromBlocks A' B' C' D' = fromBlocks (A + A') (B + B') (C + C') (D + D') := by ext i j; rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> rfl theorem fromBlocks_multiply [Fintype l] [Fintype m] [NonUnitalNonAssocSemiring α] (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (A' : Matrix l p α) (B' : Matrix l q α) (C' : Matrix m p α) (D' : Matrix m q α) : fromBlocks A B C D * fromBlocks A' B' C' D' = fromBlocks (A * A' + B * C') (A * B' + B * D') (C * A' + D * C') (C * B' + D * D') := by ext i j rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> simp only [fromBlocks, mul_apply, of_apply, Sum.elim_inr, Fintype.sum_sum_type, Sum.elim_inl, add_apply] theorem fromBlocks_mulVec [Fintype l] [Fintype m] [NonUnitalNonAssocSemiring α] (A : Matrix n l α) (B : Matrix n m α) (C : Matrix o l α) (D : Matrix o m α) (x : l ⊕ m → α) : (fromBlocks A B C D) *ᵥ x = Sum.elim (A *ᵥ (x ∘ Sum.inl) + B *ᵥ (x ∘ Sum.inr))
(C *ᵥ (x ∘ Sum.inl) + D *ᵥ (x ∘ Sum.inr)) := by ext i cases i <;> simp [mulVec, dotProduct]
Mathlib/Data/Matrix/Block.lean
223
225
/- Copyright (c) 2022 Violeta Hernández Palacios. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Violeta Hernández Palacios -/ import Mathlib.SetTheory.Ordinal.FixedPoint /-! # Principal ordinals We define principal or indecomposable ordinals, and we prove the standard properties about them. ## Main definitions and results * `Principal`: A principal or indecomposable ordinal under some binary operation. We include 0 and any other typically excluded edge cases for simplicity. * `not_bddAbove_principal`: Principal ordinals (under any operation) are unbounded. * `principal_add_iff_zero_or_omega0_opow`: The main characterization theorem for additive principal ordinals. * `principal_mul_iff_le_two_or_omega0_opow_opow`: The main characterization theorem for multiplicative principal ordinals. ## TODO * Prove that exponential principal ordinals are 0, 1, 2, ω, or epsilon numbers, i.e. fixed points of `fun x ↦ ω ^ x`. -/ universe u open Order namespace Ordinal variable {a b c o : Ordinal.{u}} section Arbitrary variable {op : Ordinal → Ordinal → Ordinal} /-! ### Principal ordinals -/ /-- An ordinal `o` is said to be principal or indecomposable under an operation when the set of ordinals less than it is closed under that operation. In standard mathematical usage, this term is almost exclusively used for additive and multiplicative principal ordinals. For simplicity, we break usual convention and regard `0` as principal. -/ def Principal (op : Ordinal → Ordinal → Ordinal) (o : Ordinal) : Prop := ∀ ⦃a b⦄, a < o → b < o → op a b < o theorem principal_swap_iff : Principal (Function.swap op) o ↔ Principal op o := by constructor <;> exact fun h a b ha hb => h hb ha theorem not_principal_iff : ¬ Principal op o ↔ ∃ a < o, ∃ b < o, o ≤ op a b := by simp [Principal] theorem principal_iff_of_monotone (h₁ : ∀ a, Monotone (op a)) (h₂ : ∀ a, Monotone (Function.swap op a)) : Principal op o ↔ ∀ a < o, op a a < o := by use fun h a ha => h ha ha intro H a b ha hb obtain hab | hba := le_or_lt a b · exact (h₂ b hab).trans_lt <| H b hb · exact (h₁ a hba.le).trans_lt <| H a ha theorem not_principal_iff_of_monotone (h₁ : ∀ a, Monotone (op a)) (h₂ : ∀ a, Monotone (Function.swap op a)) : ¬ Principal op o ↔ ∃ a < o, o ≤ op a a := by simp [principal_iff_of_monotone h₁ h₂] theorem principal_zero : Principal op 0 := fun a _ h => (Ordinal.not_lt_zero a h).elim @[simp] theorem principal_one_iff : Principal op 1 ↔ op 0 0 = 0 := by refine ⟨fun h => ?_, fun h a b ha hb => ?_⟩ · rw [← lt_one_iff_zero] exact h zero_lt_one zero_lt_one · rwa [lt_one_iff_zero, ha, hb] at * theorem Principal.iterate_lt (hao : a < o) (ho : Principal op o) (n : ℕ) : (op a)^[n] a < o := by induction' n with n hn · rwa [Function.iterate_zero] · rw [Function.iterate_succ'] exact ho hao hn theorem op_eq_self_of_principal (hao : a < o) (H : IsNormal (op a)) (ho : Principal op o) (ho' : IsLimit o) : op a o = o := by apply H.le_apply.antisymm' rw [← IsNormal.bsup_eq.{u, u} H ho', bsup_le_iff] exact fun b hbo => (ho hao hbo).le theorem nfp_le_of_principal (hao : a < o) (ho : Principal op o) : nfp (op a) a ≤ o := nfp_le fun n => (ho.iterate_lt hao n).le end Arbitrary /-! ### Principal ordinals are unbounded -/ /-- We give an explicit construction for a principal ordinal larger or equal than `o`. -/ private theorem principal_nfp_iSup (op : Ordinal → Ordinal → Ordinal) (o : Ordinal) : Principal op (nfp (fun x ↦ ⨆ y : Set.Iio x ×ˢ Set.Iio x, succ (op y.1.1 y.1.2)) o) := by intro a b ha hb rw [lt_nfp_iff] at * obtain ⟨m, ha⟩ := ha obtain ⟨n, hb⟩ := hb obtain h | h := le_total ((fun x ↦ ⨆ y : Set.Iio x ×ˢ Set.Iio x, succ (op y.1.1 y.1.2))^[m] o) ((fun x ↦ ⨆ y : Set.Iio x ×ˢ Set.Iio x, succ (op y.1.1 y.1.2))^[n] o) · use n + 1 rw [Function.iterate_succ'] apply (lt_succ _).trans_le exact Ordinal.le_iSup (fun y : Set.Iio _ ×ˢ Set.Iio _ ↦ succ (op y.1.1 y.1.2)) ⟨_, Set.mk_mem_prod (ha.trans_le h) hb⟩ · use m + 1 rw [Function.iterate_succ'] apply (lt_succ _).trans_le exact Ordinal.le_iSup (fun y : Set.Iio _ ×ˢ Set.Iio _ ↦ succ (op y.1.1 y.1.2)) ⟨_, Set.mk_mem_prod ha (hb.trans_le h)⟩ /-- Principal ordinals under any operation are unbounded. -/ theorem not_bddAbove_principal (op : Ordinal → Ordinal → Ordinal) : ¬ BddAbove { o | Principal op o } := by rintro ⟨a, ha⟩ exact ((le_nfp _ _).trans (ha (principal_nfp_iSup op (succ a)))).not_lt (lt_succ a) /-! #### Additive principal ordinals -/ theorem principal_add_one : Principal (· + ·) 1 := principal_one_iff.2 <| zero_add 0 theorem principal_add_of_le_one (ho : o ≤ 1) : Principal (· + ·) o := by rcases le_one_iff.1 ho with (rfl | rfl) · exact principal_zero · exact principal_add_one theorem isLimit_of_principal_add (ho₁ : 1 < o) (ho : Principal (· + ·) o) : o.IsLimit := by rw [isLimit_iff, isSuccPrelimit_iff_succ_lt] exact ⟨ho₁.ne_bot, fun _ ha ↦ ho ha ho₁⟩ theorem principal_add_iff_add_left_eq_self : Principal (· + ·) o ↔ ∀ a < o, a + o = o := by refine ⟨fun ho a hao => ?_, fun h a b hao hbo => ?_⟩ · rcases lt_or_le 1 o with ho₁ | ho₁ · exact op_eq_self_of_principal hao (isNormal_add_right a) ho (isLimit_of_principal_add ho₁ ho) · rcases le_one_iff.1 ho₁ with (rfl | rfl) · exact (Ordinal.not_lt_zero a hao).elim · rw [lt_one_iff_zero] at hao rw [hao, zero_add] · rw [← h a hao] exact (isNormal_add_right a).strictMono hbo theorem exists_lt_add_of_not_principal_add (ha : ¬ Principal (· + ·) a) : ∃ b < a, ∃ c < a, b + c = a := by rw [not_principal_iff] at ha rcases ha with ⟨b, hb, c, hc, H⟩ refine ⟨b, hb, _, lt_of_le_of_ne (sub_le_self a b) fun hab => ?_, Ordinal.add_sub_cancel_of_le hb.le⟩ rw [← sub_le, hab] at H exact H.not_lt hc theorem principal_add_iff_add_lt_ne_self : Principal (· + ·) a ↔ ∀ b < a, ∀ c < a, b + c ≠ a := ⟨fun ha _ hb _ hc => (ha hb hc).ne, fun H => by by_contra! ha rcases exists_lt_add_of_not_principal_add ha with ⟨b, hb, c, hc, rfl⟩ exact (H b hb c hc).irrefl⟩ theorem principal_add_omega0 : Principal (· + ·) ω := principal_add_iff_add_left_eq_self.2 fun _ => add_omega0 theorem add_omega0_opow (h : a < ω ^ b) : a + ω ^ b = ω ^ b := by refine le_antisymm ?_ (le_add_left _ a) induction' b using limitRecOn with b _ b l IH · rw [opow_zero, ← succ_zero, lt_succ_iff, Ordinal.le_zero] at h rw [h, zero_add] · rw [opow_succ] at h rcases (lt_mul_of_limit isLimit_omega0).1 h with ⟨x, xo, ax⟩ apply (add_le_add_right ax.le _).trans rw [opow_succ, ← mul_add, add_omega0 xo] · rcases (lt_opow_of_limit omega0_ne_zero l).1 h with ⟨x, xb, ax⟩ apply (((isNormal_add_right a).trans <| isNormal_opow one_lt_omega0).limit_le l).2 intro y yb calc a + ω ^ y ≤ a + ω ^ max x y := add_le_add_left (opow_le_opow_right omega0_pos (le_max_right x y)) _ _ ≤ ω ^ max x y := IH _ (max_lt xb yb) <| ax.trans_le <| opow_le_opow_right omega0_pos <| le_max_left x y _ ≤ ω ^ b := opow_le_opow_right omega0_pos <| (max_lt xb yb).le theorem principal_add_omega0_opow (o : Ordinal) : Principal (· + ·) (ω ^ o) := principal_add_iff_add_left_eq_self.2 fun _ => add_omega0_opow /-- The main characterization theorem for additive principal ordinals. -/ theorem principal_add_iff_zero_or_omega0_opow : Principal (· + ·) o ↔ o = 0 ∨ o ∈ Set.range (ω ^ · : Ordinal → Ordinal) := by rcases eq_or_ne o 0 with (rfl | ho) · simp only [principal_zero, Or.inl] · rw [principal_add_iff_add_left_eq_self] simp only [ho, false_or] refine ⟨fun H => ⟨_, ((lt_or_eq_of_le (opow_log_le_self _ ho)).resolve_left fun h => ?_)⟩, fun ⟨b, e⟩ => e.symm ▸ fun a => add_omega0_opow⟩ have := H _ h have := lt_opow_succ_log_self one_lt_omega0 o rw [opow_succ, lt_mul_of_limit isLimit_omega0] at this rcases this with ⟨a, ao, h'⟩ rcases lt_omega0.1 ao with ⟨n, rfl⟩ clear ao revert h' apply not_lt_of_le suffices e : ω ^ log ω o * n + o = o by simpa only [e] using le_add_right (ω ^ log ω o * ↑n) o induction' n with n IH · simp [Nat.cast_zero, mul_zero, zero_add] · simp only [Nat.cast_succ, mul_add_one, add_assoc, this, IH] theorem principal_add_opow_of_principal_add {a} (ha : Principal (· + ·) a) (b : Ordinal) : Principal (· + ·) (a ^ b) := by rcases principal_add_iff_zero_or_omega0_opow.1 ha with (rfl | ⟨c, rfl⟩) · rcases eq_or_ne b 0 with (rfl | hb) · rw [opow_zero] exact principal_add_one · rwa [zero_opow hb] · rw [← opow_mul] exact principal_add_omega0_opow _ theorem add_absorp (h₁ : a < ω ^ b) (h₂ : ω ^ b ≤ c) : a + c = c := by rw [← Ordinal.add_sub_cancel_of_le h₂, ← add_assoc, add_omega0_opow h₁] theorem principal_add_mul_of_principal_add (a : Ordinal.{u}) {b : Ordinal.{u}} (hb₁ : b ≠ 1) (hb : Principal (· + ·) b) : Principal (· + ·) (a * b) := by rcases eq_zero_or_pos a with (rfl | _) · rw [zero_mul] exact principal_zero · rcases eq_zero_or_pos b with (rfl | hb₁') · rw [mul_zero] exact principal_zero · rw [← succ_le_iff, succ_zero] at hb₁' intro c d hc hd rw [lt_mul_of_limit (isLimit_of_principal_add (lt_of_le_of_ne hb₁' hb₁.symm) hb)] at * rcases hc with ⟨x, hx, hx'⟩ rcases hd with ⟨y, hy, hy'⟩ use x + y, hb hx hy rw [mul_add] exact Left.add_lt_add hx' hy' /-! #### Multiplicative principal ordinals -/ theorem principal_mul_one : Principal (· * ·) 1 := by rw [principal_one_iff] exact zero_mul _ theorem principal_mul_two : Principal (· * ·) 2 := by intro a b ha hb rw [← succ_one, lt_succ_iff] at * convert mul_le_mul' ha hb exact (mul_one 1).symm theorem principal_mul_of_le_two (ho : o ≤ 2) : Principal (· * ·) o := by rcases lt_or_eq_of_le ho with (ho | rfl) · rw [← succ_one, lt_succ_iff] at ho rcases lt_or_eq_of_le ho with (ho | rfl) · rw [lt_one_iff_zero.1 ho] exact principal_zero · exact principal_mul_one · exact principal_mul_two theorem principal_add_of_principal_mul (ho : Principal (· * ·) o) (ho₂ : o ≠ 2) : Principal (· + ·) o := by rcases lt_or_gt_of_ne ho₂ with ho₁ | ho₂ · replace ho₁ : o < succ 1 := by rwa [succ_one] rw [lt_succ_iff] at ho₁ exact principal_add_of_le_one ho₁ · refine fun a b hao hbo => lt_of_le_of_lt ?_ (ho (max_lt hao hbo) ho₂) dsimp only rw [← one_add_one_eq_two, mul_add, mul_one] exact add_le_add (le_max_left a b) (le_max_right a b) theorem isLimit_of_principal_mul (ho₂ : 2 < o) (ho : Principal (· * ·) o) : o.IsLimit := isLimit_of_principal_add ((lt_succ 1).trans (succ_one ▸ ho₂)) (principal_add_of_principal_mul ho (ne_of_gt ho₂)) theorem principal_mul_iff_mul_left_eq : Principal (· * ·) o ↔ ∀ a, 0 < a → a < o → a * o = o := by refine ⟨fun h a ha₀ hao => ?_, fun h a b hao hbo => ?_⟩ · rcases le_or_gt o 2 with ho | ho · convert one_mul o apply le_antisymm · rw [← lt_succ_iff, succ_one] exact hao.trans_le ho · rwa [← succ_le_iff, succ_zero] at ha₀ · exact op_eq_self_of_principal hao (isNormal_mul_right ha₀) h (isLimit_of_principal_mul ho h) · rcases eq_or_ne a 0 with (rfl | ha) · dsimp only; rwa [zero_mul] rw [← Ordinal.pos_iff_ne_zero] at ha rw [← h a ha hao] exact (isNormal_mul_right ha).strictMono hbo theorem principal_mul_omega0 : Principal (· * ·) ω := fun a b ha hb => match a, b, lt_omega0.1 ha, lt_omega0.1 hb with | _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by dsimp only; rw [← natCast_mul] apply nat_lt_omega0 theorem mul_omega0 (a0 : 0 < a) (ha : a < ω) : a * ω = ω := principal_mul_iff_mul_left_eq.1 principal_mul_omega0 a a0 ha theorem natCast_mul_omega0 {n : ℕ} (hn : 0 < n) : n * ω = ω := mul_omega0 (mod_cast hn) (nat_lt_omega0 n) theorem mul_lt_omega0_opow (c0 : 0 < c) (ha : a < ω ^ c) (hb : b < ω) : a * b < ω ^ c := by rcases zero_or_succ_or_limit c with (rfl | ⟨c, rfl⟩ | l) · exact (lt_irrefl _).elim c0 · rw [opow_succ] at ha obtain ⟨n, hn, an⟩ := ((isNormal_mul_right <| opow_pos _ omega0_pos).limit_lt isLimit_omega0).1 ha apply (mul_le_mul_right' (le_of_lt an) _).trans_lt rw [opow_succ, mul_assoc, mul_lt_mul_iff_left (opow_pos _ omega0_pos)] exact principal_mul_omega0 hn hb · rcases ((isNormal_opow one_lt_omega0).limit_lt l).1 ha with ⟨x, hx, ax⟩ refine (mul_le_mul' (le_of_lt ax) (le_of_lt hb)).trans_lt ?_ rw [← opow_succ, opow_lt_opow_iff_right one_lt_omega0] exact l.succ_lt hx theorem mul_omega0_opow_opow (a0 : 0 < a) (h : a < ω ^ ω ^ b) : a * ω ^ ω ^ b = ω ^ ω ^ b := by obtain rfl | b0 := eq_or_ne b 0 · rw [opow_zero, opow_one] at h ⊢ exact mul_omega0 a0 h · apply le_antisymm · obtain ⟨x, xb, ax⟩ := (lt_opow_of_limit omega0_ne_zero (isLimit_opow_left isLimit_omega0 b0)).1 h apply (mul_le_mul_right' (le_of_lt ax) _).trans rw [← opow_add, add_omega0_opow xb] · conv_lhs => rw [← one_mul (ω ^ _)] exact mul_le_mul_right' (one_le_iff_pos.2 a0) _ theorem principal_mul_omega0_opow_opow (o : Ordinal) : Principal (· * ·) (ω ^ ω ^ o) := principal_mul_iff_mul_left_eq.2 fun _ => mul_omega0_opow_opow theorem principal_add_of_principal_mul_opow (hb : 1 < b) (ho : Principal (· * ·) (b ^ o)) : Principal (· + ·) o := by intro x y hx hy have := ho ((opow_lt_opow_iff_right hb).2 hx) ((opow_lt_opow_iff_right hb).2 hy) dsimp only at * rwa [← opow_add, opow_lt_opow_iff_right hb] at this /-- The main characterization theorem for multiplicative principal ordinals. -/ theorem principal_mul_iff_le_two_or_omega0_opow_opow : Principal (· * ·) o ↔ o ≤ 2 ∨ o ∈ Set.range (ω ^ ω ^ · : Ordinal → Ordinal) := by refine ⟨fun ho => ?_, ?_⟩ · rcases le_or_lt o 2 with ho₂ | ho₂ · exact Or.inl ho₂ · rcases principal_add_iff_zero_or_omega0_opow.1 (principal_add_of_principal_mul ho ho₂.ne') with (rfl | ⟨a, rfl⟩) · exact (Ordinal.not_lt_zero 2 ho₂).elim · rcases principal_add_iff_zero_or_omega0_opow.1 (principal_add_of_principal_mul_opow one_lt_omega0 ho) with (rfl | ⟨b, rfl⟩) · simp · exact Or.inr ⟨b, rfl⟩ · rintro (ho₂ | ⟨a, rfl⟩) · exact principal_mul_of_le_two ho₂ · exact principal_mul_omega0_opow_opow a theorem mul_omega0_dvd (a0 : 0 < a) (ha : a < ω) : ∀ {b}, ω ∣ b → a * b = b | _, ⟨b, rfl⟩ => by rw [← mul_assoc, mul_omega0 a0 ha] theorem mul_eq_opow_log_succ (ha : a ≠ 0) (hb : Principal (· * ·) b) (hb₂ : 2 < b) : a * b = b ^ succ (log b a) := by apply le_antisymm · have hbl := isLimit_of_principal_mul hb₂ hb rw [← (isNormal_mul_right (Ordinal.pos_iff_ne_zero.2 ha)).bsup_eq hbl, bsup_le_iff] intro c hcb have hb₁ : 1 < b := one_lt_two.trans hb₂ have hbo₀ : b ^ log b a ≠ 0 := Ordinal.pos_iff_ne_zero.1 (opow_pos _ (zero_lt_one.trans hb₁)) apply (mul_le_mul_right' (le_of_lt (lt_mul_succ_div a hbo₀)) c).trans rw [mul_assoc, opow_succ] refine mul_le_mul_left' (hb (hbl.succ_lt ?_) hcb).le _ rw [div_lt hbo₀, ← opow_succ] exact lt_opow_succ_log_self hb₁ _
· rw [opow_succ] exact mul_le_mul_right' (opow_log_le_self b ha) b /-! #### Exponential principal ordinals -/ theorem principal_opow_omega0 : Principal (· ^ ·) ω := fun a b ha hb => match a, b, lt_omega0.1 ha, lt_omega0.1 hb with | _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by simp_rw [← natCast_opow] apply nat_lt_omega0 theorem opow_omega0 (a1 : 1 < a) (h : a < ω) : a ^ ω = ω := ((opow_le_of_limit (one_le_iff_ne_zero.1 <| le_of_lt a1) isLimit_omega0).2 fun _ hb => (principal_opow_omega0 h hb).le).antisymm (right_le_opow _ a1)
Mathlib/SetTheory/Ordinal/Principal.lean
378
393
/- Copyright (c) 2023 Scott Carnahan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Carnahan -/ import Mathlib.Algebra.Ring.Int.Defs import Mathlib.Data.Nat.Cast.Basic import Mathlib.Algebra.Group.Prod /-! # Typeclasses for power-associative structures In this file we define power-associativity for algebraic structures with a multiplication operation. The class is a Prop-valued mixin named `NatPowAssoc`. ## Results - `npow_add` a defining property: `x ^ (k + n) = x ^ k * x ^ n` - `npow_one` a defining property: `x ^ 1 = x` - `npow_assoc` strictly positive powers of an element have associative multiplication. - `npow_comm` `x ^ m * x ^ n = x ^ n * x ^ m` for strictly positive `m` and `n`. - `npow_mul` `x ^ (m * n) = (x ^ m) ^ n` for strictly positive `m` and `n`. - `npow_eq_pow` monoid exponentiation coincides with semigroup exponentiation. ## Instances We also produce the following instances: - `NatPowAssoc` for Monoids, Pi types and products. ## TODO * to_additive? -/ assert_not_exists DenselyOrdered variable {M : Type*} /-- A mixin for power-associative multiplication. -/ class NatPowAssoc (M : Type*) [MulOneClass M] [Pow M ℕ] : Prop where /-- Multiplication is power-associative. -/ protected npow_add : ∀ (k n : ℕ) (x : M), x ^ (k + n) = x ^ k * x ^ n /-- Exponent zero is one. -/ protected npow_zero : ∀ (x : M), x ^ 0 = 1 /-- Exponent one is identity. -/ protected npow_one : ∀ (x : M), x ^ 1 = x section MulOneClass variable [MulOneClass M] [Pow M ℕ] [NatPowAssoc M] theorem npow_add (k n : ℕ) (x : M) : x ^ (k + n) = x ^ k * x ^ n := NatPowAssoc.npow_add k n x @[simp] theorem npow_zero (x : M) : x ^ 0 = 1 := NatPowAssoc.npow_zero x @[simp] theorem npow_one (x : M) : x ^ 1 = x := NatPowAssoc.npow_one x theorem npow_mul_assoc (k m n : ℕ) (x : M) : (x ^ k * x ^ m) * x ^ n = x ^ k * (x ^ m * x ^ n) := by simp only [← npow_add, add_assoc] theorem npow_mul_comm (m n : ℕ) (x : M) : x ^ m * x ^ n = x ^ n * x ^ m := by simp only [← npow_add, add_comm] theorem npow_mul (x : M) (m n : ℕ) : x ^ (m * n) = (x ^ m) ^ n := by induction n with | zero => rw [npow_zero, Nat.mul_zero, npow_zero] | succ n ih => rw [mul_add, npow_add, ih, mul_one, npow_add, npow_one]
theorem npow_mul' (x : M) (m n : ℕ) : x ^ (m * n) = (x ^ n) ^ m := by rw [mul_comm] exact npow_mul x n m
Mathlib/Algebra/Group/NatPowAssoc.lean
77
79
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.MeasureTheory.Measure.Typeclasses.Finite import Mathlib.MeasureTheory.Measure.Typeclasses.NoAtoms import Mathlib.MeasureTheory.Measure.Typeclasses.Probability import Mathlib.MeasureTheory.Measure.Typeclasses.SFinite deprecated_module (since := "2025-04-13")
Mathlib/MeasureTheory/Measure/Typeclasses.lean
143
145
/- 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.AlgebraicGeometry.AffineScheme import Mathlib.AlgebraicGeometry.Pullbacks import Mathlib.AlgebraicGeometry.Limits import Mathlib.CategoryTheory.MorphismProperty.Limits import Mathlib.Data.List.TFAE /-! # Properties of morphisms between Schemes We provide the basic framework for talking about properties of morphisms between Schemes. A `MorphismProperty Scheme` is a predicate on morphisms between schemes. For properties local at the target, its behaviour is entirely determined by its definition on morphisms into affine schemes, which we call an `AffineTargetMorphismProperty`. In this file, we provide API lemmas for properties local at the target, and special support for those properties whose `AffineTargetMorphismProperty` takes on a more simple form. We also provide API lemmas for properties local at the target. The main interfaces of the API are the typeclasses `IsLocalAtTarget`, `IsLocalAtSource` and `HasAffineProperty`, which we describle in detail below. ## `IsLocalAtTarget` - `AlgebraicGeometry.IsLocalAtTarget`: We say that `IsLocalAtTarget P` for `P : MorphismProperty Scheme` if 1. `P` respects isomorphisms. 2. `P` holds for `f ∣_ U` for an open cover `U` of `Y` if and only if `P` holds for `f`. For a morphism property `P` local at the target and `f : X ⟶ Y`, we provide these API lemmas: - `AlgebraicGeometry.IsLocalAtTarget.of_isPullback`: `P` is preserved under pullback along open immersions. - `AlgebraicGeometry.IsLocalAtTarget.restrict`: `P f → P (f ∣_ U)` for an open `U` of `Y`. - `AlgebraicGeometry.IsLocalAtTarget.iff_of_iSup_eq_top`: `P f ↔ ∀ i, P (f ∣_ U i)` for a family `U i` of open sets covering `Y`. - `AlgebraicGeometry.IsLocalAtTarget.iff_of_openCover`: `P f ↔ ∀ i, P (𝒰.pullbackHom f i)` for `𝒰 : Y.openCover`. ## `IsLocalAtSource` - `AlgebraicGeometry.IsLocalAtSource`: We say that `IsLocalAtSource P` for `P : MorphismProperty Scheme` if 1. `P` respects isomorphisms. 2. `P` holds for `𝒰.map i ≫ f` for an open cover `𝒰` of `X` iff `P` holds for `f : X ⟶ Y`. For a morphism property `P` local at the source and `f : X ⟶ Y`, we provide these API lemmas: - `AlgebraicGeometry.IsLocalAtTarget.comp`: `P` is preserved under composition with open immersions at the source. - `AlgebraicGeometry.IsLocalAtTarget.iff_of_iSup_eq_top`: `P f ↔ ∀ i, P (U.ι ≫ f)` for a family `U i` of open sets covering `X`. - `AlgebraicGeometry.IsLocalAtTarget.iff_of_openCover`: `P f ↔ ∀ i, P (𝒰.map i ≫ f)` for `𝒰 : X.openCover`. - `AlgebraicGeometry.IsLocalAtTarget.of_isOpenImmersion`: If `P` contains identities then `P` holds for open immersions. ## `AffineTargetMorphismProperty` - `AlgebraicGeometry.AffineTargetMorphismProperty`: The type of predicates on `f : X ⟶ Y` with `Y` affine. - `AlgebraicGeometry.AffineTargetMorphismProperty.IsLocal`: We say that `P.IsLocal` if `P` satisfies the assumptions of the affine communication lemma (`AlgebraicGeometry.of_affine_open_cover`). That is, 1. `P` respects isomorphisms. 2. If `P` holds for `f : X ⟶ Y`, then `P` holds for `f ∣_ Y.basicOpen r` for any global section `r`. 3. If `P` holds for `f ∣_ Y.basicOpen r` for all `r` in a spanning set of the global sections, then `P` holds for `f`. ## `HasAffineProperty` - `AlgebraicGeometry.HasAffineProperty`: `HasAffineProperty P Q` is a type class asserting that `P` is local at the target, and over affine schemes, it is equivalent to `Q : AffineTargetMorphismProperty`. For `HasAffineProperty P Q` and `f : X ⟶ Y`, we provide these API lemmas: - `AlgebraicGeometry.HasAffineProperty.of_isPullback`: `P` is preserved under pullback along open immersions from affine schemes. - `AlgebraicGeometry.HasAffineProperty.restrict`: `P f → Q (f ∣_ U)` for affine `U` of `Y`. - `AlgebraicGeometry.HasAffineProperty.iff_of_iSup_eq_top`: `P f ↔ ∀ i, Q (f ∣_ U i)` for a family `U i` of affine open sets covering `Y`. - `AlgebraicGeometry.HasAffineProperty.iff_of_openCover`: `P f ↔ ∀ i, P (𝒰.pullbackHom f i)` for affine open covers `𝒰` of `Y`. - `AlgebraicGeometry.HasAffineProperty.isStableUnderBaseChange_mk`: If `Q` is stable under affine base change, then `P` is stable under arbitrary base change. -/ universe u v open TopologicalSpace CategoryTheory CategoryTheory.Limits Opposite noncomputable section namespace AlgebraicGeometry /-- We say that `P : MorphismProperty Scheme` is local at the target if 1. `P` respects isomorphisms. 2. `P` holds for `f ∣_ U` for an open cover `U` of `Y` if and only if `P` holds for `f`. Also see `IsLocalAtTarget.mk'` for a convenient constructor. -/ class IsLocalAtTarget (P : MorphismProperty Scheme) : Prop where /-- `P` respects isomorphisms. -/ respectsIso : P.RespectsIso := by infer_instance /-- `P` holds for `f ∣_ U` for an open cover `U` of `Y` if and only if `P` holds for `f`. -/ iff_of_openCover' : ∀ {X Y : Scheme.{u}} (f : X ⟶ Y) (𝒰 : Scheme.OpenCover.{u} Y), P f ↔ ∀ i, P (𝒰.pullbackHom f i) namespace IsLocalAtTarget attribute [instance] respectsIso /-- `P` is local at the target if 1. `P` respects isomorphisms. 2. If `P` holds for `f : X ⟶ Y`, then `P` holds for `f ∣_ U` for any `U`. 3. If `P` holds for `f ∣_ U` for an open cover `U` of `Y`, then `P` holds for `f`. -/ protected lemma mk' {P : MorphismProperty Scheme} [P.RespectsIso] (restrict : ∀ {X Y : Scheme} (f : X ⟶ Y) (U : Y.Opens), P f → P (f ∣_ U)) (of_sSup_eq_top : ∀ {X Y : Scheme.{u}} (f : X ⟶ Y) {ι : Type u} (U : ι → Y.Opens), iSup U = ⊤ → (∀ i, P (f ∣_ U i)) → P f) : IsLocalAtTarget P := by refine ⟨inferInstance, fun {X Y} f 𝒰 ↦ ⟨?_, fun H ↦ of_sSup_eq_top f _ 𝒰.iSup_opensRange ?_⟩⟩ · exact fun H i ↦ (P.arrow_mk_iso_iff (morphismRestrictOpensRange f _)).mp (restrict _ _ H) · exact fun i ↦ (P.arrow_mk_iso_iff (morphismRestrictOpensRange f _)).mpr (H i) /-- The intersection of two morphism properties that are local at the target is again local at the target. -/ instance inf (P Q : MorphismProperty Scheme) [IsLocalAtTarget P] [IsLocalAtTarget Q] : IsLocalAtTarget (P ⊓ Q) where iff_of_openCover' {_ _} f 𝒰 := ⟨fun h i ↦ ⟨(iff_of_openCover' f 𝒰).mp h.left i, (iff_of_openCover' f 𝒰).mp h.right i⟩, fun h ↦ ⟨(iff_of_openCover' f 𝒰).mpr (fun i ↦ (h i).left), (iff_of_openCover' f 𝒰).mpr (fun i ↦ (h i).right)⟩⟩ variable {P} [hP : IsLocalAtTarget P] {X Y : Scheme.{u}} {f : X ⟶ Y} (𝒰 : Y.OpenCover) lemma of_isPullback {UX UY : Scheme.{u}} {iY : UY ⟶ Y} [IsOpenImmersion iY] {iX : UX ⟶ X} {f' : UX ⟶ UY} (h : IsPullback iX f' f iY) (H : P f) : P f' := by rw [← P.cancel_left_of_respectsIso h.isoPullback.inv, h.isoPullback_inv_snd] exact (iff_of_openCover' f (Y.affineCover.add iY)).mp H .none theorem restrict (hf : P f) (U : Y.Opens) : P (f ∣_ U) := of_isPullback (isPullback_morphismRestrict f U).flip hf lemma of_iSup_eq_top {ι} (U : ι → Y.Opens) (hU : iSup U = ⊤) (H : ∀ i, P (f ∣_ U i)) : P f := by refine (IsLocalAtTarget.iff_of_openCover' f (Y.openCoverOfISupEqTop (s := Set.range U) Subtype.val (by ext; simp [← hU]))).mpr fun i ↦ ?_ obtain ⟨_, i, rfl⟩ := i refine (P.arrow_mk_iso_iff (morphismRestrictOpensRange f _)).mp ?_ show P (f ∣_ (U i).ι.opensRange) rw [Scheme.Opens.opensRange_ι] exact H i theorem iff_of_iSup_eq_top {ι} (U : ι → Y.Opens) (hU : iSup U = ⊤) : P f ↔ ∀ i, P (f ∣_ U i) := ⟨fun H _ ↦ restrict H _, of_iSup_eq_top U hU⟩ lemma of_openCover (H : ∀ i, P (𝒰.pullbackHom f i)) : P f := by apply of_iSup_eq_top (fun i ↦ (𝒰.map i).opensRange) 𝒰.iSup_opensRange exact fun i ↦ (P.arrow_mk_iso_iff (morphismRestrictOpensRange f _)).mpr (H i) theorem iff_of_openCover (𝒰 : Y.OpenCover) : P f ↔ ∀ i, P (𝒰.pullbackHom f i) := ⟨fun H _ ↦ of_isPullback (.of_hasPullback _ _) H, of_openCover _⟩ lemma of_range_subset_iSup [P.RespectsRight @IsOpenImmersion] {ι : Type*} (U : ι → Y.Opens) (H : Set.range f.base ⊆ (⨆ i, U i : Y.Opens)) (hf : ∀ i, P (f ∣_ U i)) : P f := by let g : X ⟶ (⨆ i, U i : Y.Opens) := IsOpenImmersion.lift (Scheme.Opens.ι _) f (by simpa using H) rw [← IsOpenImmersion.lift_fac (⨆ i, U i).ι f (by simpa using H)] apply MorphismProperty.RespectsRight.postcomp (Q := @IsOpenImmersion) _ inferInstance rw [IsLocalAtTarget.iff_of_iSup_eq_top (P := P) (U := fun i : ι ↦ (⨆ i, U i).ι ⁻¹ᵁ U i)] · intro i have heq : g ⁻¹ᵁ (⨆ i, U i).ι ⁻¹ᵁ U i = f ⁻¹ᵁ U i := by show (g ≫ (⨆ i, U i).ι) ⁻¹ᵁ U i = _ simp [g] let e : Arrow.mk (g ∣_ (⨆ i, U i).ι ⁻¹ᵁ U i) ≅ Arrow.mk (f ∣_ U i) := Arrow.isoMk (X.isoOfEq heq) (Scheme.Opens.isoOfLE (le_iSup U i)) <| by simp [← CategoryTheory.cancel_mono (U i).ι, g] rw [P.arrow_mk_iso_iff e] exact hf i apply (⨆ i, U i).ι.image_injective dsimp rw [Scheme.Hom.image_iSup, Scheme.Hom.image_top_eq_opensRange, Scheme.Opens.opensRange_ι] simp [Scheme.Hom.image_preimage_eq_opensRange_inter, le_iSup U] end IsLocalAtTarget /-- We say that `P : MorphismProperty Scheme` is local at the source if 1. `P` respects isomorphisms. 2. `P` holds for `𝒰.map i ≫ f` for an open cover `𝒰` of `X` iff `P` holds for `f : X ⟶ Y`. Also see `IsLocalAtSource.mk'` for a convenient constructor. -/ class IsLocalAtSource (P : MorphismProperty Scheme) : Prop where /-- `P` respects isomorphisms. -/ respectsIso : P.RespectsIso := by infer_instance /-- `P` holds for `f ∣_ U` for an open cover `U` of `Y` if and only if `P` holds for `f`. -/ iff_of_openCover' : ∀ {X Y : Scheme.{u}} (f : X ⟶ Y) (𝒰 : Scheme.OpenCover.{u} X), P f ↔ ∀ i, P (𝒰.map i ≫ f) namespace IsLocalAtSource attribute [instance] respectsIso /-- `P` is local at the source if 1. `P` respects isomorphisms. 2. If `P` holds for `f : X ⟶ Y`, then `P` holds for `U.ι ≫ f` for any `U`. 3. If `P` holds for `U.ι ≫ f` for an open cover `U` of `X`, then `P` holds for `f`. -/ protected lemma mk' {P : MorphismProperty Scheme} [P.RespectsIso] (restrict : ∀ {X Y : Scheme} (f : X ⟶ Y) (U : X.Opens), P f → P (U.ι ≫ f)) (of_sSup_eq_top : ∀ {X Y : Scheme.{u}} (f : X ⟶ Y) {ι : Type u} (U : ι → X.Opens), iSup U = ⊤ → (∀ i, P ((U i).ι ≫ f)) → P f) : IsLocalAtSource P := by refine ⟨inferInstance, fun {X Y} f 𝒰 ↦ ⟨fun H i ↦ ?_, fun H ↦ of_sSup_eq_top f _ 𝒰.iSup_opensRange fun i ↦ ?_⟩⟩ · rw [← IsOpenImmersion.isoOfRangeEq_hom_fac (𝒰.map i) (Scheme.Opens.ι _) (congr_arg Opens.carrier (𝒰.map i).opensRange.opensRange_ι.symm), Category.assoc, P.cancel_left_of_respectsIso] exact restrict _ _ H · rw [← IsOpenImmersion.isoOfRangeEq_inv_fac (𝒰.map i) (Scheme.Opens.ι _) (congr_arg Opens.carrier (𝒰.map i).opensRange.opensRange_ι.symm), Category.assoc, P.cancel_left_of_respectsIso] exact H _ /-- The intersection of two morphism properties that are local at the target is again local at the target. -/ instance inf (P Q : MorphismProperty Scheme) [IsLocalAtSource P] [IsLocalAtSource Q] : IsLocalAtSource (P ⊓ Q) where iff_of_openCover' {_ _} f 𝒰 := ⟨fun h i ↦ ⟨(iff_of_openCover' f 𝒰).mp h.left i, (iff_of_openCover' f 𝒰).mp h.right i⟩, fun h ↦ ⟨(iff_of_openCover' f 𝒰).mpr (fun i ↦ (h i).left), (iff_of_openCover' f 𝒰).mpr (fun i ↦ (h i).right)⟩⟩ variable {P} [IsLocalAtSource P] variable {X Y : Scheme.{u}} {f : X ⟶ Y} (𝒰 : X.OpenCover) lemma comp {UX : Scheme.{u}} (H : P f) (i : UX ⟶ X) [IsOpenImmersion i] : P (i ≫ f) := (iff_of_openCover' f (X.affineCover.add i)).mp H .none /-- If `P` is local at the source, then it respects composition on the left with open immersions. -/ instance respectsLeft_isOpenImmersion {P : MorphismProperty Scheme} [IsLocalAtSource P] : P.RespectsLeft @IsOpenImmersion where precomp i _ _ hf := IsLocalAtSource.comp hf i lemma of_iSup_eq_top {ι} (U : ι → X.Opens) (hU : iSup U = ⊤) (H : ∀ i, P ((U i).ι ≫ f)) : P f := by refine (iff_of_openCover' f (X.openCoverOfISupEqTop (s := Set.range U) Subtype.val (by ext; simp [← hU]))).mpr fun i ↦ ?_ obtain ⟨_, i, rfl⟩ := i exact H i theorem iff_of_iSup_eq_top {ι} (U : ι → X.Opens) (hU : iSup U = ⊤) : P f ↔ ∀ i, P ((U i).ι ≫ f) := ⟨fun H _ ↦ comp H _, of_iSup_eq_top U hU⟩ lemma of_openCover (H : ∀ i, P (𝒰.map i ≫ f)) : P f := by refine of_iSup_eq_top (fun i ↦ (𝒰.map i).opensRange) 𝒰.iSup_opensRange fun i ↦ ?_ rw [← IsOpenImmersion.isoOfRangeEq_inv_fac (𝒰.map i) (Scheme.Opens.ι _) (congr_arg Opens.carrier (𝒰.map i).opensRange.opensRange_ι.symm), Category.assoc, P.cancel_left_of_respectsIso] exact H i theorem iff_of_openCover : P f ↔ ∀ i, P (𝒰.map i ≫ f) := ⟨fun H _ ↦ comp H _, of_openCover _⟩ variable (f) in lemma of_isOpenImmersion [P.ContainsIdentities] [IsOpenImmersion f] : P f := Category.comp_id f ▸ comp (P.id_mem Y) f lemma isLocalAtTarget [P.IsMultiplicative] (hP : ∀ {X Y Z : Scheme.{u}} (f : X ⟶ Y) (g : Y ⟶ Z) [IsOpenImmersion g], P (f ≫ g) → P f) : IsLocalAtTarget P where iff_of_openCover' {X Y} f 𝒰 := by refine (iff_of_openCover (𝒰.pullbackCover f)).trans (forall_congr' fun i ↦ ?_) rw [← Scheme.Cover.pullbackHom_map] constructor · exact hP _ _ · exact fun H ↦ P.comp_mem _ _ H (of_isOpenImmersion _) lemma sigmaDesc {X : Scheme.{u}} {ι : Type v} [Small.{u} ι] {Y : ι → Scheme.{u}} {f : ∀ i, Y i ⟶ X} (hf : ∀ i, P (f i)) : P (Sigma.desc f) := by rw [IsLocalAtSource.iff_of_openCover (P := P) (sigmaOpenCover _)] exact fun i ↦ by simp [hf] section IsLocalAtSourceAndTarget /-- If `P` is local at the source and the target, then restriction on both source and target preserves `P`. -/ lemma resLE [IsLocalAtTarget P] {U : Y.Opens} {V : X.Opens} (e : V ≤ f ⁻¹ᵁ U) (hf : P f) : P (f.resLE U V e) := IsLocalAtSource.comp (IsLocalAtTarget.restrict hf U) _ /-- If `P` is local at the source, local at the target and is stable under post-composition with open immersions, then `P` can be checked locally around points. -/ lemma iff_exists_resLE [IsLocalAtTarget P] [P.RespectsRight @IsOpenImmersion] : P f ↔ ∀ x : X, ∃ (U : Y.Opens) (V : X.Opens) (_ : x ∈ V.1) (e : V ≤ f ⁻¹ᵁ U), P (f.resLE U V e) := by refine ⟨fun hf x ↦ ⟨⊤, ⊤, trivial, by simp, resLE _ hf⟩, fun hf ↦ ?_⟩ choose U V hxU e hf using hf rw [IsLocalAtSource.iff_of_iSup_eq_top (fun x : X ↦ V x) (P := P)]
· intro x rw [← Scheme.Hom.resLE_comp_ι _ (e x)] exact MorphismProperty.RespectsRight.postcomp (Q := @IsOpenImmersion) _ inferInstance _ (hf x) · rw [eq_top_iff] rintro x - simp only [Opens.coe_iSup, Set.mem_iUnion, SetLike.mem_coe] use x, hxU x end IsLocalAtSourceAndTarget end IsLocalAtSource
Mathlib/AlgebraicGeometry/Morphisms/Basic.lean
319
330
/- Copyright (c) 2022 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler, Yaël Dillies, Bhavik Mehta -/ import Mathlib.Analysis.Convex.SpecificFunctions.Deriv import Mathlib.Analysis.SpecialFunctions.Trigonometric.ArctanDeriv /-! # Polynomial bounds for trigonometric functions ## Main statements This file contains upper and lower bounds for real trigonometric functions in terms of polynomials. See `Trigonometric.Basic` for more elementary inequalities, establishing the ranges of these functions, and their monotonicity in suitable intervals. Here we prove the following: * `sin_lt`: for `x > 0` we have `sin x < x`. * `sin_gt_sub_cube`: For `0 < x ≤ 1` we have `x - x ^ 3 / 4 < sin x`. * `lt_tan`: for `0 < x < π/2` we have `x < tan x`. * `cos_le_one_div_sqrt_sq_add_one` and `cos_lt_one_div_sqrt_sq_add_one`: for `-3 * π / 2 ≤ x ≤ 3 * π / 2`, we have `cos x ≤ 1 / sqrt (x ^ 2 + 1)`, with strict inequality if `x ≠ 0`. (This bound is not quite optimal, but not far off) ## Tags sin, cos, tan, angle -/ open Set namespace Real variable {x : ℝ} /-- For 0 < x, we have sin x < x. -/ theorem sin_lt (h : 0 < x) : sin x < x := by rcases lt_or_le 1 x with h' | h' · exact (sin_le_one x).trans_lt h' have hx : |x| = x := abs_of_nonneg h.le have := le_of_abs_le (sin_bound <| show |x| ≤ 1 by rwa [hx]) rw [sub_le_iff_le_add', hx] at this apply this.trans_lt rw [sub_add, sub_lt_self_iff, sub_pos, div_eq_mul_inv (x ^ 3)] refine mul_lt_mul' ?_ (by norm_num) (by norm_num) (pow_pos h 3) apply pow_le_pow_of_le_one h.le h' norm_num lemma sin_le (hx : 0 ≤ x) : sin x ≤ x := by obtain rfl | hx := hx.eq_or_lt · simp · exact (sin_lt hx).le lemma lt_sin (hx : x < 0) : x < sin x := by simpa using sin_lt <| neg_pos.2 hx lemma le_sin (hx : x ≤ 0) : x ≤ sin x := by simpa using sin_le <| neg_nonneg.2 hx theorem lt_sin_mul {x : ℝ} (hx : 0 < x) (hx' : x < 1) : x < sin (π / 2 * x) := by simpa [mul_comm x] using strictConcaveOn_sin_Icc.2 ⟨le_rfl, pi_pos.le⟩ ⟨pi_div_two_pos.le, half_le_self pi_pos.le⟩ pi_div_two_pos.ne (sub_pos.2 hx') hx theorem le_sin_mul {x : ℝ} (hx : 0 ≤ x) (hx' : x ≤ 1) : x ≤ sin (π / 2 * x) := by simpa [mul_comm x] using strictConcaveOn_sin_Icc.concaveOn.2 ⟨le_rfl, pi_pos.le⟩ ⟨pi_div_two_pos.le, half_le_self pi_pos.le⟩ (sub_nonneg.2 hx') hx theorem mul_lt_sin {x : ℝ} (hx : 0 < x) (hx' : x < π / 2) : 2 / π * x < sin x := by rw [← inv_div] simpa [-inv_div, mul_inv_cancel_left₀ pi_div_two_pos.ne'] using @lt_sin_mul ((π / 2)⁻¹ * x) (mul_pos (inv_pos.2 pi_div_two_pos) hx) (by rwa [← div_eq_inv_mul, div_lt_one pi_div_two_pos]) /-- One half of **Jordan's inequality**. In the range `[0, π / 2]`, we have a linear lower bound on `sin`. The other half is given by `Real.sin_le`. -/ theorem mul_le_sin {x : ℝ} (hx : 0 ≤ x) (hx' : x ≤ π / 2) : 2 / π * x ≤ sin x := by rw [← inv_div] simpa [-inv_div, mul_inv_cancel_left₀ pi_div_two_pos.ne'] using @le_sin_mul ((π / 2)⁻¹ * x) (mul_nonneg (inv_nonneg.2 pi_div_two_pos.le) hx) (by rwa [← div_eq_inv_mul, div_le_one pi_div_two_pos]) /-- Half of **Jordan's inequality** for negative values. -/ lemma sin_le_mul (hx : -(π / 2) ≤ x) (hx₀ : x ≤ 0) : sin x ≤ 2 / π * x := by simpa using mul_le_sin (neg_nonneg.2 hx₀) (neg_le.2 hx) /-- Half of **Jordan's inequality** for absolute values. -/ lemma mul_abs_le_abs_sin (hx : |x| ≤ π / 2) : 2 / π * |x| ≤ |sin x| := by wlog hx₀ : 0 ≤ x case inr => simpa using this (by rwa [abs_neg]) <| neg_nonneg.2 <| le_of_not_le hx₀ rw [abs_of_nonneg hx₀] at hx ⊢ exact (mul_le_sin hx₀ hx).trans (le_abs_self _) lemma sin_sq_lt_sq (hx : x ≠ 0) : sin x ^ 2 < x ^ 2 := by wlog hx₀ : 0 < x case inr => simpa using this (neg_ne_zero.2 hx) <| neg_pos_of_neg <| hx.lt_of_le <| le_of_not_lt hx₀ rcases le_or_lt x 1 with hxπ | hxπ case inl => exact pow_lt_pow_left₀ (sin_lt hx₀) (sin_nonneg_of_nonneg_of_le_pi hx₀.le (by linarith [two_le_pi])) (by simp) case inr => exact (sin_sq_le_one _).trans_lt (by rwa [one_lt_sq_iff₀ hx₀.le]) lemma sin_sq_le_sq : sin x ^ 2 ≤ x ^ 2 := by rcases eq_or_ne x 0 with rfl | hx case inl => simp case inr => exact (sin_sq_lt_sq hx).le lemma abs_sin_lt_abs (hx : x ≠ 0) : |sin x| < |x| := sq_lt_sq.1 (sin_sq_lt_sq hx) lemma abs_sin_le_abs : |sin x| ≤ |x| := sq_le_sq.1 sin_sq_le_sq lemma one_sub_sq_div_two_lt_cos (hx : x ≠ 0) : 1 - x ^ 2 / 2 < cos x := by have := (sin_sq_lt_sq (by positivity)).trans_eq' (sin_sq_eq_half_sub (x / 2)).symm ring_nf at this linarith lemma one_sub_sq_div_two_le_cos : 1 - x ^ 2 / 2 ≤ cos x := by rcases eq_or_ne x 0 with rfl | hx case inl => simp case inr => exact (one_sub_sq_div_two_lt_cos hx).le /-- Half of **Jordan's inequality** for `cos`. -/ lemma one_sub_mul_le_cos (hx₀ : 0 ≤ x) (hx : x ≤ π / 2) : 1 - 2 / π * x ≤ cos x := by simpa [sin_pi_div_two_sub, mul_sub, div_mul_div_comm, mul_comm π, pi_pos.ne'] using mul_le_sin (x := π / 2 - x) (by simpa) (by simpa) /-- Half of **Jordan's inequality** for `cos` and negative values. -/ lemma one_add_mul_le_cos (hx₀ : -(π / 2) ≤ x) (hx : x ≤ 0) : 1 + 2 / π * x ≤ cos x := by simpa using one_sub_mul_le_cos (x := -x) (by linarith) (by linarith) lemma cos_le_one_sub_mul_cos_sq (hx : |x| ≤ π) : cos x ≤ 1 - 2 / π ^ 2 * x ^ 2 := by wlog hx₀ : 0 ≤ x case inr => simpa using this (by rwa [abs_neg]) <| neg_nonneg.2 <| le_of_not_le hx₀ rw [abs_of_nonneg hx₀] at hx have : x / π ≤ sin (x / 2) := by simpa using mul_le_sin (x := x / 2) (by positivity) (by linarith) have := (pow_le_pow_left₀ (by positivity) this 2).trans_eq (sin_sq_eq_half_sub _)
ring_nf at this ⊢ linarith /-- For 0 < x ≤ 1 we have x - x ^ 3 / 4 < sin x. This is also true for x > 1, but it's nontrivial for x just above 1. This inequality is not tight; the tighter inequality is sin x > x - x ^ 3 / 6 for all x > 0, but this inequality has a simpler proof. -/ theorem sin_gt_sub_cube {x : ℝ} (h : 0 < x) (h' : x ≤ 1) : x - x ^ 3 / 4 < sin x := by have hx : |x| = x := abs_of_nonneg h.le
Mathlib/Analysis/SpecialFunctions/Trigonometric/Bounds.lean
139
148
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.Algebra.Group.Pi.Basic import Mathlib.CategoryTheory.Limits.Shapes.Products import Mathlib.CategoryTheory.Limits.Shapes.Images import Mathlib.CategoryTheory.IsomorphismClasses import Mathlib.CategoryTheory.Limits.Shapes.ZeroObjects /-! # Zero morphisms and zero objects A category "has zero morphisms" if there is a designated "zero morphism" in each morphism space, and compositions of zero morphisms with anything give the zero morphism. (Notice this is extra structure, not merely a property.) A category "has a zero object" if it has an object which is both initial and terminal. Having a zero object provides zero morphisms, as the unique morphisms factoring through the zero object. ## References * https://en.wikipedia.org/wiki/Zero_morphism * [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2] -/ noncomputable section universe w v v' u u' open CategoryTheory open CategoryTheory.Category namespace CategoryTheory.Limits variable (C : Type u) [Category.{v} C] variable (D : Type u') [Category.{v'} D] /-- A category "has zero morphisms" if there is a designated "zero morphism" in each morphism space, and compositions of zero morphisms with anything give the zero morphism. -/ class HasZeroMorphisms where /-- Every morphism space has zero -/ [zero : ∀ X Y : C, Zero (X ⟶ Y)] /-- `f` composed with `0` is `0` -/ comp_zero : ∀ {X Y : C} (f : X ⟶ Y) (Z : C), f ≫ (0 : Y ⟶ Z) = (0 : X ⟶ Z) := by aesop_cat /-- `0` composed with `f` is `0` -/ zero_comp : ∀ (X : C) {Y Z : C} (f : Y ⟶ Z), (0 : X ⟶ Y) ≫ f = (0 : X ⟶ Z) := by aesop_cat attribute [instance] HasZeroMorphisms.zero variable {C} @[simp] theorem comp_zero [HasZeroMorphisms C] {X Y : C} {f : X ⟶ Y} {Z : C} : f ≫ (0 : Y ⟶ Z) = (0 : X ⟶ Z) := HasZeroMorphisms.comp_zero f Z @[simp] theorem zero_comp [HasZeroMorphisms C] {X : C} {Y Z : C} {f : Y ⟶ Z} : (0 : X ⟶ Y) ≫ f = (0 : X ⟶ Z) := HasZeroMorphisms.zero_comp X f instance hasZeroMorphismsPEmpty : HasZeroMorphisms (Discrete PEmpty) where zero := by aesop_cat instance hasZeroMorphismsPUnit : HasZeroMorphisms (Discrete PUnit) where zero X Y := by repeat (constructor) namespace HasZeroMorphisms /-- This lemma will be immediately superseded by `ext`, below. -/ private theorem ext_aux (I J : HasZeroMorphisms C) (w : ∀ X Y : C, (I.zero X Y).zero = (J.zero X Y).zero) : I = J := by have : I.zero = J.zero := by funext X Y specialize w X Y apply congrArg Zero.mk w cases I; cases J congr · apply proof_irrel_heq · apply proof_irrel_heq /-- If you're tempted to use this lemma "in the wild", you should probably carefully consider whether you've made a mistake in allowing two instances of `HasZeroMorphisms` to exist at all. See, particularly, the note on `zeroMorphismsOfZeroObject` below. -/ theorem ext (I J : HasZeroMorphisms C) : I = J := by apply ext_aux intro X Y have : (I.zero X Y).zero ≫ (J.zero Y Y).zero = (I.zero X Y).zero := by apply I.zero_comp X (J.zero Y Y).zero have that : (I.zero X Y).zero ≫ (J.zero Y Y).zero = (J.zero X Y).zero := by apply J.comp_zero (I.zero X Y).zero Y rw [← this, ← that] instance : Subsingleton (HasZeroMorphisms C) := ⟨ext⟩ end HasZeroMorphisms open Opposite HasZeroMorphisms instance hasZeroMorphismsOpposite [HasZeroMorphisms C] : HasZeroMorphisms Cᵒᵖ where zero X Y := ⟨(0 : unop Y ⟶ unop X).op⟩ comp_zero f Z := congr_arg Quiver.Hom.op (HasZeroMorphisms.zero_comp (unop Z) f.unop) zero_comp X {Y Z} (f : Y ⟶ Z) := congrArg Quiver.Hom.op (HasZeroMorphisms.comp_zero f.unop (unop X)) section variable [HasZeroMorphisms C] @[simp] lemma op_zero (X Y : C) : (0 : X ⟶ Y).op = 0 := rfl @[simp] lemma unop_zero (X Y : Cᵒᵖ) : (0 : X ⟶ Y).unop = 0 := rfl theorem zero_of_comp_mono {X Y Z : C} {f : X ⟶ Y} (g : Y ⟶ Z) [Mono g] (h : f ≫ g = 0) : f = 0 := by rw [← zero_comp, cancel_mono] at h exact h theorem zero_of_epi_comp {X Y Z : C} (f : X ⟶ Y) {g : Y ⟶ Z} [Epi f] (h : f ≫ g = 0) : g = 0 := by rw [← comp_zero, cancel_epi] at h exact h theorem eq_zero_of_image_eq_zero {X Y : C} {f : X ⟶ Y} [HasImage f] (w : image.ι f = 0) : f = 0 := by rw [← image.fac f, w, HasZeroMorphisms.comp_zero] theorem nonzero_image_of_nonzero {X Y : C} {f : X ⟶ Y} [HasImage f] (w : f ≠ 0) : image.ι f ≠ 0 := fun h => w (eq_zero_of_image_eq_zero h) end section variable [HasZeroMorphisms D] instance : HasZeroMorphisms (C ⥤ D) where zero F G := ⟨{ app := fun _ => 0 }⟩ comp_zero := fun η H => by ext X; dsimp; apply comp_zero zero_comp := fun F {G H} η => by ext X; dsimp; apply zero_comp @[simp] theorem zero_app (F G : C ⥤ D) (j : C) : (0 : F ⟶ G).app j = 0 := rfl end namespace IsZero variable [HasZeroMorphisms C] theorem eq_zero_of_src {X Y : C} (o : IsZero X) (f : X ⟶ Y) : f = 0 := o.eq_of_src _ _ theorem eq_zero_of_tgt {X Y : C} (o : IsZero Y) (f : X ⟶ Y) : f = 0 := o.eq_of_tgt _ _ theorem iff_id_eq_zero (X : C) : IsZero X ↔ 𝟙 X = 0 := ⟨fun h => h.eq_of_src _ _, fun h => ⟨fun Y => ⟨⟨⟨0⟩, fun f => by rw [← id_comp f, ← id_comp (0 : X ⟶ Y), h, zero_comp, zero_comp]; simp only⟩⟩, fun Y => ⟨⟨⟨0⟩, fun f => by rw [← comp_id f, ← comp_id (0 : Y ⟶ X), h, comp_zero, comp_zero]; simp only ⟩⟩⟩⟩ theorem of_mono_zero (X Y : C) [Mono (0 : X ⟶ Y)] : IsZero X := (iff_id_eq_zero X).mpr ((cancel_mono (0 : X ⟶ Y)).1 (by simp)) theorem of_epi_zero (X Y : C) [Epi (0 : X ⟶ Y)] : IsZero Y := (iff_id_eq_zero Y).mpr ((cancel_epi (0 : X ⟶ Y)).1 (by simp)) theorem of_mono_eq_zero {X Y : C} (f : X ⟶ Y) [Mono f] (h : f = 0) : IsZero X := by subst h apply of_mono_zero X Y theorem of_epi_eq_zero {X Y : C} (f : X ⟶ Y) [Epi f] (h : f = 0) : IsZero Y := by subst h apply of_epi_zero X Y theorem iff_isSplitMono_eq_zero {X Y : C} (f : X ⟶ Y) [IsSplitMono f] : IsZero X ↔ f = 0 := by rw [iff_id_eq_zero] constructor · intro h rw [← Category.id_comp f, h, zero_comp] · intro h rw [← IsSplitMono.id f] simp only [h, zero_comp] theorem iff_isSplitEpi_eq_zero {X Y : C} (f : X ⟶ Y) [IsSplitEpi f] : IsZero Y ↔ f = 0 := by rw [iff_id_eq_zero] constructor · intro h rw [← Category.comp_id f, h, comp_zero] · intro h rw [← IsSplitEpi.id f] simp [h] theorem of_mono {X Y : C} (f : X ⟶ Y) [Mono f] (i : IsZero Y) : IsZero X := by have hf := i.eq_zero_of_tgt f subst hf exact IsZero.of_mono_zero X Y theorem of_epi {X Y : C} (f : X ⟶ Y) [Epi f] (i : IsZero X) : IsZero Y := by have hf := i.eq_zero_of_src f subst hf exact IsZero.of_epi_zero X Y end IsZero /-- A category with a zero object has zero morphisms. It is rarely a good idea to use this. Many categories that have a zero object have zero morphisms for some other reason, for example from additivity. Library code that uses `zeroMorphismsOfZeroObject` will then be incompatible with these categories because the `HasZeroMorphisms` instances will not be definitionally equal. For this reason library code should generally ask for an instance of `HasZeroMorphisms` separately, even if it already asks for an instance of `HasZeroObjects`. -/ def IsZero.hasZeroMorphisms {O : C} (hO : IsZero O) : HasZeroMorphisms C where zero X Y := { zero := hO.from_ X ≫ hO.to_ Y } zero_comp X {Y Z} f := by change (hO.from_ X ≫ hO.to_ Y) ≫ f = hO.from_ X ≫ hO.to_ Z rw [Category.assoc] congr apply hO.eq_of_src comp_zero {X Y} f Z := by change f ≫ (hO.from_ Y ≫ hO.to_ Z) = hO.from_ X ≫ hO.to_ Z rw [← Category.assoc] congr apply hO.eq_of_tgt namespace HasZeroObject variable [HasZeroObject C] open ZeroObject /-- A category with a zero object has zero morphisms. It is rarely a good idea to use this. Many categories that have a zero object have zero morphisms for some other reason, for example from additivity. Library code that uses `zeroMorphismsOfZeroObject` will then be incompatible with these categories because the `has_zero_morphisms` instances will not be definitionally equal. For this reason library code should generally ask for an instance of `HasZeroMorphisms` separately, even if it already asks for an instance of `HasZeroObjects`. -/ def zeroMorphismsOfZeroObject : HasZeroMorphisms C where zero X _ := { zero := (default : X ⟶ 0) ≫ default } zero_comp X {Y Z} f := by change ((default : X ⟶ 0) ≫ default) ≫ f = (default : X ⟶ 0) ≫ default rw [Category.assoc] congr simp only [eq_iff_true_of_subsingleton] comp_zero {X Y} f Z := by change f ≫ (default : Y ⟶ 0) ≫ default = (default : X ⟶ 0) ≫ default rw [← Category.assoc] congr simp only [eq_iff_true_of_subsingleton] section HasZeroMorphisms variable [HasZeroMorphisms C] @[simp] theorem zeroIsoIsInitial_hom {X : C} (t : IsInitial X) : (zeroIsoIsInitial t).hom = 0 := by ext @[simp] theorem zeroIsoIsInitial_inv {X : C} (t : IsInitial X) : (zeroIsoIsInitial t).inv = 0 := by ext @[simp] theorem zeroIsoIsTerminal_hom {X : C} (t : IsTerminal X) : (zeroIsoIsTerminal t).hom = 0 := by ext @[simp] theorem zeroIsoIsTerminal_inv {X : C} (t : IsTerminal X) : (zeroIsoIsTerminal t).inv = 0 := by ext @[simp] theorem zeroIsoInitial_hom [HasInitial C] : zeroIsoInitial.hom = (0 : 0 ⟶ ⊥_ C) := by ext @[simp] theorem zeroIsoInitial_inv [HasInitial C] : zeroIsoInitial.inv = (0 : ⊥_ C ⟶ 0) := by ext @[simp] theorem zeroIsoTerminal_hom [HasTerminal C] : zeroIsoTerminal.hom = (0 : 0 ⟶ ⊤_ C) := by ext @[simp] theorem zeroIsoTerminal_inv [HasTerminal C] : zeroIsoTerminal.inv = (0 : ⊤_ C ⟶ 0) := by ext end HasZeroMorphisms open ZeroObject instance {B : Type*} [Category B] : HasZeroObject (B ⥤ C) := (((CategoryTheory.Functor.const B).obj (0 : C)).isZero fun _ => isZero_zero _).hasZeroObject end HasZeroObject open ZeroObject variable {D} @[simp] theorem IsZero.map [HasZeroObject D] [HasZeroMorphisms D] {F : C ⥤ D} (hF : IsZero F) {X Y : C} (f : X ⟶ Y) : F.map f = 0 := (hF.obj _).eq_of_src _ _ @[simp] theorem _root_.CategoryTheory.Functor.zero_obj [HasZeroObject D] (X : C) : IsZero ((0 : C ⥤ D).obj X) := (isZero_zero _).obj _ @[simp] theorem _root_.CategoryTheory.zero_map [HasZeroObject D] [HasZeroMorphisms D] {X Y : C} (f : X ⟶ Y) : (0 : C ⥤ D).map f = 0 := (isZero_zero _).map _ section variable [HasZeroObject C] [HasZeroMorphisms C] open ZeroObject @[simp] theorem id_zero : 𝟙 (0 : C) = (0 : (0 : C) ⟶ 0) := by apply HasZeroObject.from_zero_ext -- This can't be a `simp` lemma because the left hand side would be a metavariable. /-- An arrow ending in the zero object is zero -/ theorem zero_of_to_zero {X : C} (f : X ⟶ 0) : f = 0 := by ext theorem zero_of_target_iso_zero {X Y : C} (f : X ⟶ Y) (i : Y ≅ 0) : f = 0 := by have h : f = f ≫ i.hom ≫ 𝟙 0 ≫ i.inv := by simp only [Iso.hom_inv_id, id_comp, comp_id] simpa using h /-- An arrow starting at the zero object is zero -/ theorem zero_of_from_zero {X : C} (f : 0 ⟶ X) : f = 0 := by ext theorem zero_of_source_iso_zero {X Y : C} (f : X ⟶ Y) (i : X ≅ 0) : f = 0 := by have h : f = i.hom ≫ 𝟙 0 ≫ i.inv ≫ f := by simp only [Iso.hom_inv_id_assoc, id_comp, comp_id] simpa using h theorem zero_of_source_iso_zero' {X Y : C} (f : X ⟶ Y) (i : IsIsomorphic X 0) : f = 0 := zero_of_source_iso_zero f (Nonempty.some i) theorem zero_of_target_iso_zero' {X Y : C} (f : X ⟶ Y) (i : IsIsomorphic Y 0) : f = 0 := zero_of_target_iso_zero f (Nonempty.some i) theorem mono_of_source_iso_zero {X Y : C} (f : X ⟶ Y) (i : X ≅ 0) : Mono f := ⟨fun {Z} g h _ => by rw [zero_of_target_iso_zero g i, zero_of_target_iso_zero h i]⟩ theorem epi_of_target_iso_zero {X Y : C} (f : X ⟶ Y) (i : Y ≅ 0) : Epi f := ⟨fun {Z} g h _ => by rw [zero_of_source_iso_zero g i, zero_of_source_iso_zero h i]⟩ /-- An object `X` has `𝟙 X = 0` if and only if it is isomorphic to the zero object. Because `X ≅ 0` contains data (even if a subsingleton), we express this `↔` as an `≃`. -/ def idZeroEquivIsoZero (X : C) : 𝟙 X = 0 ≃ (X ≅ 0) where toFun h := { hom := 0 inv := 0 } invFun i := zero_of_target_iso_zero (𝟙 X) i left_inv := by aesop_cat right_inv := by aesop_cat @[simp] theorem idZeroEquivIsoZero_apply_hom (X : C) (h : 𝟙 X = 0) : ((idZeroEquivIsoZero X) h).hom = 0 := rfl @[simp] theorem idZeroEquivIsoZero_apply_inv (X : C) (h : 𝟙 X = 0) : ((idZeroEquivIsoZero X) h).inv = 0 := rfl /-- If `0 : X ⟶ Y` is a monomorphism, then `X ≅ 0`. -/ @[simps] def isoZeroOfMonoZero {X Y : C} (_ : Mono (0 : X ⟶ Y)) : X ≅ 0 where hom := 0 inv := 0 hom_inv_id := (cancel_mono (0 : X ⟶ Y)).mp (by simp)
/-- If `0 : X ⟶ Y` is an epimorphism, then `Y ≅ 0`. -/ @[simps]
Mathlib/CategoryTheory/Limits/Shapes/ZeroMorphisms.lean
381
383
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Logic.Equiv.PartialEquiv import Mathlib.Topology.Homeomorph.Lemmas import Mathlib.Topology.Sets.Opens /-! # Partial homeomorphisms This file defines homeomorphisms between open subsets of topological spaces. An element `e` of `PartialHomeomorph X Y` is an extension of `PartialEquiv X Y`, i.e., it is a pair of functions `e.toFun` and `e.invFun`, inverse of each other on the sets `e.source` and `e.target`. Additionally, we require that these sets are open, and that the functions are continuous on them. Equivalently, they are homeomorphisms there. As in equivs, we register a coercion to functions, and we use `e x` and `e.symm x` throughout instead of `e.toFun x` and `e.invFun x`. ## Main definitions * `Homeomorph.toPartialHomeomorph`: associating a partial homeomorphism to a homeomorphism, with `source = target = Set.univ`; * `PartialHomeomorph.symm`: the inverse of a partial homeomorphism * `PartialHomeomorph.trans`: the composition of two partial homeomorphisms * `PartialHomeomorph.refl`: the identity partial homeomorphism * `PartialHomeomorph.const`: a partial homeomorphism which is a constant map, whose source and target are necessarily singleton sets * `PartialHomeomorph.ofSet`: the identity on a set `s` * `PartialHomeomorph.restr s`: restrict a partial homeomorphism `e` to `e.source ∩ interior s` * `PartialHomeomorph.EqOnSource`: equivalence relation describing the "right" notion of equality for partial homeomorphisms * `PartialHomeomorph.prod`: the product of two partial homeomorphisms, as a partial homeomorphism on the product space * `PartialHomeomorph.pi`: the product of a finite family of partial homeomorphisms * `PartialHomeomorph.disjointUnion`: combine two partial homeomorphisms with disjoint sources and disjoint targets * `PartialHomeomorph.lift_openEmbedding`: extend a partial homeomorphism `X → Y` under an open embedding `X → X'`, to a partial homeomorphism `X' → Z`. (This is used to define the disjoint union of charted spaces.) ## Implementation notes Most statements are copied from their `PartialEquiv` versions, although some care is required especially when restricting to subsets, as these should be open subsets. For design notes, see `PartialEquiv.lean`. ### Local coding conventions If a lemma deals with the intersection of a set with either source or target of a `PartialEquiv`, then it should use `e.source ∩ s` or `e.target ∩ t`, not `s ∩ e.source` or `t ∩ e.target`. -/ open Function Set Filter Topology variable {X X' : Type*} {Y Y' : Type*} {Z Z' : Type*} [TopologicalSpace X] [TopologicalSpace X'] [TopologicalSpace Y] [TopologicalSpace Y'] [TopologicalSpace Z] [TopologicalSpace Z'] /-- Partial homeomorphisms, defined on open subsets of the space -/ structure PartialHomeomorph (X : Type*) (Y : Type*) [TopologicalSpace X] [TopologicalSpace Y] extends PartialEquiv X Y where open_source : IsOpen source open_target : IsOpen target continuousOn_toFun : ContinuousOn toFun source continuousOn_invFun : ContinuousOn invFun target namespace PartialHomeomorph variable (e : PartialHomeomorph X Y) /-! Basic properties; inverse (symm instance) -/ section Basic /-- Coercion of a partial homeomorphisms to a function. We don't use `e.toFun` because it is actually `e.toPartialEquiv.toFun`, so `simp` will apply lemmas about `toPartialEquiv`. While we may want to switch to this behavior later, doing it mid-port will break a lot of proofs. -/ @[coe] def toFun' : X → Y := e.toFun /-- Coercion of a `PartialHomeomorph` to function. Note that a `PartialHomeomorph` is not `DFunLike`. -/ instance : CoeFun (PartialHomeomorph X Y) fun _ => X → Y := ⟨fun e => e.toFun'⟩ /-- The inverse of a partial homeomorphism -/ @[symm] protected def symm : PartialHomeomorph Y X where toPartialEquiv := e.toPartialEquiv.symm open_source := e.open_target open_target := e.open_source continuousOn_toFun := e.continuousOn_invFun continuousOn_invFun := e.continuousOn_toFun /-- See Note [custom simps projection]. We need to specify this projection explicitly in this case, because it is a composition of multiple projections. -/ def Simps.apply (e : PartialHomeomorph X Y) : X → Y := e /-- See Note [custom simps projection] -/ def Simps.symm_apply (e : PartialHomeomorph X Y) : Y → X := e.symm initialize_simps_projections PartialHomeomorph (toFun → apply, invFun → symm_apply) protected theorem continuousOn : ContinuousOn e e.source := e.continuousOn_toFun theorem continuousOn_symm : ContinuousOn e.symm e.target := e.continuousOn_invFun @[simp, mfld_simps] theorem mk_coe (e : PartialEquiv X Y) (a b c d) : (PartialHomeomorph.mk e a b c d : X → Y) = e := rfl @[simp, mfld_simps] theorem mk_coe_symm (e : PartialEquiv X Y) (a b c d) : ((PartialHomeomorph.mk e a b c d).symm : Y → X) = e.symm := rfl theorem toPartialEquiv_injective : Injective (toPartialEquiv : PartialHomeomorph X Y → PartialEquiv X Y) | ⟨_, _, _, _, _⟩, ⟨_, _, _, _, _⟩, rfl => rfl /- Register a few simp lemmas to make sure that `simp` puts the application of a local homeomorphism in its normal form, i.e., in terms of its coercion to a function. -/ @[simp, mfld_simps] theorem toFun_eq_coe (e : PartialHomeomorph X Y) : e.toFun = e := rfl @[simp, mfld_simps] theorem invFun_eq_coe (e : PartialHomeomorph X Y) : e.invFun = e.symm := rfl @[simp, mfld_simps] theorem coe_coe : (e.toPartialEquiv : X → Y) = e := rfl @[simp, mfld_simps] theorem coe_coe_symm : (e.toPartialEquiv.symm : Y → X) = e.symm := rfl @[simp, mfld_simps] theorem map_source {x : X} (h : x ∈ e.source) : e x ∈ e.target := e.map_source' h /-- Variant of `map_source`, stated for images of subsets of `source`. -/ lemma map_source'' : e '' e.source ⊆ e.target := fun _ ⟨_, hx, hex⟩ ↦ mem_of_eq_of_mem (id hex.symm) (e.map_source' hx) @[simp, mfld_simps] theorem map_target {x : Y} (h : x ∈ e.target) : e.symm x ∈ e.source := e.map_target' h @[simp, mfld_simps] theorem left_inv {x : X} (h : x ∈ e.source) : e.symm (e x) = x := e.left_inv' h @[simp, mfld_simps] theorem right_inv {x : Y} (h : x ∈ e.target) : e (e.symm x) = x := e.right_inv' h theorem eq_symm_apply {x : X} {y : Y} (hx : x ∈ e.source) (hy : y ∈ e.target) : x = e.symm y ↔ e x = y := e.toPartialEquiv.eq_symm_apply hx hy protected theorem mapsTo : MapsTo e e.source e.target := fun _ => e.map_source protected theorem symm_mapsTo : MapsTo e.symm e.target e.source := e.symm.mapsTo protected theorem leftInvOn : LeftInvOn e.symm e e.source := fun _ => e.left_inv protected theorem rightInvOn : RightInvOn e.symm e e.target := fun _ => e.right_inv protected theorem invOn : InvOn e.symm e e.source e.target := ⟨e.leftInvOn, e.rightInvOn⟩ protected theorem injOn : InjOn e e.source := e.leftInvOn.injOn protected theorem bijOn : BijOn e e.source e.target := e.invOn.bijOn e.mapsTo e.symm_mapsTo protected theorem surjOn : SurjOn e e.source e.target := e.bijOn.surjOn end Basic /-- Interpret a `Homeomorph` as a `PartialHomeomorph` by restricting it to an open set `s` in the domain and to `t` in the codomain. -/ @[simps! -fullyApplied apply symm_apply toPartialEquiv, simps! -isSimp source target] def _root_.Homeomorph.toPartialHomeomorphOfImageEq (e : X ≃ₜ Y) (s : Set X) (hs : IsOpen s) (t : Set Y) (h : e '' s = t) : PartialHomeomorph X Y where toPartialEquiv := e.toPartialEquivOfImageEq s t h open_source := hs open_target := by simpa [← h] continuousOn_toFun := e.continuous.continuousOn continuousOn_invFun := e.symm.continuous.continuousOn /-- A homeomorphism induces a partial homeomorphism on the whole space -/ @[simps! (config := mfld_cfg)] def _root_.Homeomorph.toPartialHomeomorph (e : X ≃ₜ Y) : PartialHomeomorph X Y := e.toPartialHomeomorphOfImageEq univ isOpen_univ univ <| by rw [image_univ, e.surjective.range_eq] /-- Replace `toPartialEquiv` field to provide better definitional equalities. -/ def replaceEquiv (e : PartialHomeomorph X Y) (e' : PartialEquiv X Y) (h : e.toPartialEquiv = e') : PartialHomeomorph X Y where toPartialEquiv := e' open_source := h ▸ e.open_source open_target := h ▸ e.open_target continuousOn_toFun := h ▸ e.continuousOn_toFun continuousOn_invFun := h ▸ e.continuousOn_invFun theorem replaceEquiv_eq_self (e' : PartialEquiv X Y) (h : e.toPartialEquiv = e') : e.replaceEquiv e' h = e := by cases e subst e' rfl theorem source_preimage_target : e.source ⊆ e ⁻¹' e.target := e.mapsTo theorem eventually_left_inverse {x} (hx : x ∈ e.source) : ∀ᶠ y in 𝓝 x, e.symm (e y) = y := (e.open_source.eventually_mem hx).mono e.left_inv' theorem eventually_left_inverse' {x} (hx : x ∈ e.target) : ∀ᶠ y in 𝓝 (e.symm x), e.symm (e y) = y := e.eventually_left_inverse (e.map_target hx) theorem eventually_right_inverse {x} (hx : x ∈ e.target) : ∀ᶠ y in 𝓝 x, e (e.symm y) = y := (e.open_target.eventually_mem hx).mono e.right_inv' theorem eventually_right_inverse' {x} (hx : x ∈ e.source) : ∀ᶠ y in 𝓝 (e x), e (e.symm y) = y := e.eventually_right_inverse (e.map_source hx) theorem eventually_ne_nhdsWithin {x} (hx : x ∈ e.source) : ∀ᶠ x' in 𝓝[≠] x, e x' ≠ e x := eventually_nhdsWithin_iff.2 <| (e.eventually_left_inverse hx).mono fun x' hx' => mt fun h => by rw [mem_singleton_iff, ← e.left_inv hx, ← h, hx'] theorem nhdsWithin_source_inter {x} (hx : x ∈ e.source) (s : Set X) : 𝓝[e.source ∩ s] x = 𝓝[s] x := nhdsWithin_inter_of_mem (mem_nhdsWithin_of_mem_nhds <| IsOpen.mem_nhds e.open_source hx) theorem nhdsWithin_target_inter {x} (hx : x ∈ e.target) (s : Set Y) : 𝓝[e.target ∩ s] x = 𝓝[s] x := e.symm.nhdsWithin_source_inter hx s theorem image_eq_target_inter_inv_preimage {s : Set X} (h : s ⊆ e.source) : e '' s = e.target ∩ e.symm ⁻¹' s := e.toPartialEquiv.image_eq_target_inter_inv_preimage h theorem image_source_inter_eq' (s : Set X) : e '' (e.source ∩ s) = e.target ∩ e.symm ⁻¹' s := e.toPartialEquiv.image_source_inter_eq' s theorem image_source_inter_eq (s : Set X) : e '' (e.source ∩ s) = e.target ∩ e.symm ⁻¹' (e.source ∩ s) := e.toPartialEquiv.image_source_inter_eq s theorem symm_image_eq_source_inter_preimage {s : Set Y} (h : s ⊆ e.target) : e.symm '' s = e.source ∩ e ⁻¹' s := e.symm.image_eq_target_inter_inv_preimage h theorem symm_image_target_inter_eq (s : Set Y) : e.symm '' (e.target ∩ s) = e.source ∩ e ⁻¹' (e.target ∩ s) := e.symm.image_source_inter_eq _ theorem source_inter_preimage_inv_preimage (s : Set X) : e.source ∩ e ⁻¹' (e.symm ⁻¹' s) = e.source ∩ s := e.toPartialEquiv.source_inter_preimage_inv_preimage s theorem target_inter_inv_preimage_preimage (s : Set Y) : e.target ∩ e.symm ⁻¹' (e ⁻¹' s) = e.target ∩ s := e.symm.source_inter_preimage_inv_preimage _ theorem source_inter_preimage_target_inter (s : Set Y) : e.source ∩ e ⁻¹' (e.target ∩ s) = e.source ∩ e ⁻¹' s := e.toPartialEquiv.source_inter_preimage_target_inter s theorem image_source_eq_target : e '' e.source = e.target := e.toPartialEquiv.image_source_eq_target theorem symm_image_target_eq_source : e.symm '' e.target = e.source := e.symm.image_source_eq_target /-- Two partial homeomorphisms are equal when they have equal `toFun`, `invFun` and `source`. It is not sufficient to have equal `toFun` and `source`, as this only determines `invFun` on the target. This would only be true for a weaker notion of equality, arguably the right one, called `EqOnSource`. -/ @[ext] protected theorem ext (e' : PartialHomeomorph X Y) (h : ∀ x, e x = e' x) (hinv : ∀ x, e.symm x = e'.symm x) (hs : e.source = e'.source) : e = e' := toPartialEquiv_injective (PartialEquiv.ext h hinv hs) @[simp, mfld_simps] theorem symm_toPartialEquiv : e.symm.toPartialEquiv = e.toPartialEquiv.symm := rfl -- The following lemmas are already simp via `PartialEquiv` theorem symm_source : e.symm.source = e.target := rfl theorem symm_target : e.symm.target = e.source := rfl @[simp, mfld_simps] theorem symm_symm : e.symm.symm = e := rfl theorem symm_bijective : Function.Bijective (PartialHomeomorph.symm : PartialHomeomorph X Y → PartialHomeomorph Y X) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ /-- A partial homeomorphism is continuous at any point of its source -/ protected theorem continuousAt {x : X} (h : x ∈ e.source) : ContinuousAt e x := (e.continuousOn x h).continuousAt (e.open_source.mem_nhds h) /-- A partial homeomorphism inverse is continuous at any point of its target -/ theorem continuousAt_symm {x : Y} (h : x ∈ e.target) : ContinuousAt e.symm x := e.symm.continuousAt h theorem tendsto_symm {x} (hx : x ∈ e.source) : Tendsto e.symm (𝓝 (e x)) (𝓝 x) := by simpa only [ContinuousAt, e.left_inv hx] using e.continuousAt_symm (e.map_source hx) theorem map_nhds_eq {x} (hx : x ∈ e.source) : map e (𝓝 x) = 𝓝 (e x) := le_antisymm (e.continuousAt hx) <| le_map_of_right_inverse (e.eventually_right_inverse' hx) (e.tendsto_symm hx) theorem symm_map_nhds_eq {x} (hx : x ∈ e.source) : map e.symm (𝓝 (e x)) = 𝓝 x := (e.symm.map_nhds_eq <| e.map_source hx).trans <| by rw [e.left_inv hx] theorem image_mem_nhds {x} (hx : x ∈ e.source) {s : Set X} (hs : s ∈ 𝓝 x) : e '' s ∈ 𝓝 (e x) := e.map_nhds_eq hx ▸ Filter.image_mem_map hs theorem map_nhdsWithin_eq {x} (hx : x ∈ e.source) (s : Set X) : map e (𝓝[s] x) = 𝓝[e '' (e.source ∩ s)] e x := calc map e (𝓝[s] x) = map e (𝓝[e.source ∩ s] x) := congr_arg (map e) (e.nhdsWithin_source_inter hx _).symm _ = 𝓝[e '' (e.source ∩ s)] e x := (e.leftInvOn.mono inter_subset_left).map_nhdsWithin_eq (e.left_inv hx) (e.continuousAt_symm (e.map_source hx)).continuousWithinAt (e.continuousAt hx).continuousWithinAt theorem map_nhdsWithin_preimage_eq {x} (hx : x ∈ e.source) (s : Set Y) : map e (𝓝[e ⁻¹' s] x) = 𝓝[s] e x := by rw [e.map_nhdsWithin_eq hx, e.image_source_inter_eq', e.target_inter_inv_preimage_preimage, e.nhdsWithin_target_inter (e.map_source hx)] theorem eventually_nhds {x : X} (p : Y → Prop) (hx : x ∈ e.source) : (∀ᶠ y in 𝓝 (e x), p y) ↔ ∀ᶠ x in 𝓝 x, p (e x) := Iff.trans (by rw [e.map_nhds_eq hx]) eventually_map theorem eventually_nhds' {x : X} (p : X → Prop) (hx : x ∈ e.source) : (∀ᶠ y in 𝓝 (e x), p (e.symm y)) ↔ ∀ᶠ x in 𝓝 x, p x := by rw [e.eventually_nhds _ hx] refine eventually_congr ((e.eventually_left_inverse hx).mono fun y hy => ?_) rw [hy] theorem eventually_nhdsWithin {x : X} (p : Y → Prop) {s : Set X} (hx : x ∈ e.source) : (∀ᶠ y in 𝓝[e.symm ⁻¹' s] e x, p y) ↔ ∀ᶠ x in 𝓝[s] x, p (e x) := by refine Iff.trans ?_ eventually_map rw [e.map_nhdsWithin_eq hx, e.image_source_inter_eq', e.nhdsWithin_target_inter (e.mapsTo hx)] theorem eventually_nhdsWithin' {x : X} (p : X → Prop) {s : Set X} (hx : x ∈ e.source) : (∀ᶠ y in 𝓝[e.symm ⁻¹' s] e x, p (e.symm y)) ↔ ∀ᶠ x in 𝓝[s] x, p x := by rw [e.eventually_nhdsWithin _ hx] refine eventually_congr <| (eventually_nhdsWithin_of_eventually_nhds <| e.eventually_left_inverse hx).mono fun y hy => ?_ rw [hy] /-- This lemma is useful in the manifold library in the case that `e` is a chart. It states that locally around `e x` the set `e.symm ⁻¹' s` is the same as the set intersected with the target of `e` and some other neighborhood of `f x` (which will be the source of a chart on `Z`). -/ theorem preimage_eventuallyEq_target_inter_preimage_inter {e : PartialHomeomorph X Y} {s : Set X} {t : Set Z} {x : X} {f : X → Z} (hf : ContinuousWithinAt f s x) (hxe : x ∈ e.source) (ht : t ∈ 𝓝 (f x)) : e.symm ⁻¹' s =ᶠ[𝓝 (e x)] (e.target ∩ e.symm ⁻¹' (s ∩ f ⁻¹' t) : Set Y) := by rw [eventuallyEq_set, e.eventually_nhds _ hxe] filter_upwards [e.open_source.mem_nhds hxe, mem_nhdsWithin_iff_eventually.mp (hf.preimage_mem_nhdsWithin ht)] intro y hy hyu simp_rw [mem_inter_iff, mem_preimage, mem_inter_iff, e.mapsTo hy, true_and, iff_self_and, e.left_inv hy, iff_true_intro hyu] theorem isOpen_inter_preimage {s : Set Y} (hs : IsOpen s) : IsOpen (e.source ∩ e ⁻¹' s) := e.continuousOn.isOpen_inter_preimage e.open_source hs theorem isOpen_inter_preimage_symm {s : Set X} (hs : IsOpen s) : IsOpen (e.target ∩ e.symm ⁻¹' s) := e.symm.continuousOn.isOpen_inter_preimage e.open_target hs /-- A partial homeomorphism is an open map on its source: the image of an open subset of the source is open. -/ lemma isOpen_image_of_subset_source {s : Set X} (hs : IsOpen s) (hse : s ⊆ e.source) : IsOpen (e '' s) := by rw [(image_eq_target_inter_inv_preimage (e := e) hse)] exact e.continuousOn_invFun.isOpen_inter_preimage e.open_target hs /-- The image of the restriction of an open set to the source is open. -/ theorem isOpen_image_source_inter {s : Set X} (hs : IsOpen s) : IsOpen (e '' (e.source ∩ s)) := e.isOpen_image_of_subset_source (e.open_source.inter hs) inter_subset_left /-- The inverse of a partial homeomorphism `e` is an open map on `e.target`. -/ lemma isOpen_image_symm_of_subset_target {t : Set Y} (ht : IsOpen t) (hte : t ⊆ e.target) : IsOpen (e.symm '' t) := isOpen_image_of_subset_source e.symm ht (e.symm_source ▸ hte) lemma isOpen_symm_image_iff_of_subset_target {t : Set Y} (hs : t ⊆ e.target) : IsOpen (e.symm '' t) ↔ IsOpen t := by refine ⟨fun h ↦ ?_, fun h ↦ e.symm.isOpen_image_of_subset_source h hs⟩ have hs' : e.symm '' t ⊆ e.source := by rw [e.symm_image_eq_source_inter_preimage hs] apply Set.inter_subset_left rw [← e.image_symm_image_of_subset_target hs] exact e.isOpen_image_of_subset_source h hs' theorem isOpen_image_iff_of_subset_source {s : Set X} (hs : s ⊆ e.source) : IsOpen (e '' s) ↔ IsOpen s := by rw [← e.symm.isOpen_symm_image_iff_of_subset_target hs, e.symm_symm] section IsImage /-! ### `PartialHomeomorph.IsImage` relation We say that `t : Set Y` is an image of `s : Set X` under a partial homeomorphism `e` if any of the following equivalent conditions hold: * `e '' (e.source ∩ s) = e.target ∩ t`; * `e.source ∩ e ⁻¹ t = e.source ∩ s`; * `∀ x ∈ e.source, e x ∈ t ↔ x ∈ s` (this one is used in the definition). This definition is a restatement of `PartialEquiv.IsImage` for partial homeomorphisms. In this section we transfer API about `PartialEquiv.IsImage` to partial homeomorphisms and add a few `PartialHomeomorph`-specific lemmas like `PartialHomeomorph.IsImage.closure`. -/ /-- We say that `t : Set Y` is an image of `s : Set X` under a partial homeomorphism `e` if any of the following equivalent conditions hold: * `e '' (e.source ∩ s) = e.target ∩ t`; * `e.source ∩ e ⁻¹ t = e.source ∩ s`; * `∀ x ∈ e.source, e x ∈ t ↔ x ∈ s` (this one is used in the definition). -/ def IsImage (s : Set X) (t : Set Y) : Prop := ∀ ⦃x⦄, x ∈ e.source → (e x ∈ t ↔ x ∈ s) namespace IsImage variable {e} {s : Set X} {t : Set Y} {x : X} {y : Y} theorem toPartialEquiv (h : e.IsImage s t) : e.toPartialEquiv.IsImage s t := h theorem apply_mem_iff (h : e.IsImage s t) (hx : x ∈ e.source) : e x ∈ t ↔ x ∈ s := h hx protected theorem symm (h : e.IsImage s t) : e.symm.IsImage t s := h.toPartialEquiv.symm theorem symm_apply_mem_iff (h : e.IsImage s t) (hy : y ∈ e.target) : e.symm y ∈ s ↔ y ∈ t :=
h.symm hy @[simp] theorem symm_iff : e.symm.IsImage t s ↔ e.IsImage s t := ⟨fun h => h.symm, fun h => h.symm⟩
Mathlib/Topology/PartialHomeomorph.lean
464
469
/- Copyright (c) 2024 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ import Mathlib.Analysis.InnerProductSpace.Basic import Mathlib.Analysis.Normed.Ring.InfiniteSum import Mathlib.NumberTheory.ArithmeticFunction import Mathlib.NumberTheory.LSeries.Convergence /-! # Dirichlet convolution of sequences and products of L-series We define the *Dirichlet convolution* `f ⍟ g` of two sequences `f g : ℕ → R` with values in a semiring `R` by `(f ⍟ g) n = ∑ (k * m = n), f k * g m` when `n ≠ 0` and `(f ⍟ g) 0 = 0`. Technically, this is done by transporting the existing definition for `ArithmeticFunction R`; see `LSeries.convolution`. We show that these definitions agree (`LSeries.convolution_def`). We then consider the case `R = ℂ` and show that `L (f ⍟ g) = L f * L g` on the common domain of convergence of the L-series `L f` and `L g` of `f` and `g`; see `LSeries_convolution` and `LSeries_convolution'`. -/ open scoped LSeries.notation open Complex LSeries /-! ### Dirichlet convolution of two functions -/ open Nat /-- We turn any function `ℕ → R` into an `ArithmeticFunction R` by setting its value at `0` to be zero. -/ def toArithmeticFunction {R : Type*} [Zero R] (f : ℕ → R) : ArithmeticFunction R where toFun n := if n = 0 then 0 else f n map_zero' := rfl lemma toArithmeticFunction_congr {R : Type*} [Zero R] {f f' : ℕ → R} (h : ∀ {n}, n ≠ 0 → f n = f' n) : toArithmeticFunction f = toArithmeticFunction f' := by ext simp_all [toArithmeticFunction] /-- If we consider an arithmetic function just as a function and turn it back into an arithmetic function, it is the same as before. -/ @[simp] lemma ArithmeticFunction.toArithmeticFunction_eq_self {R : Type*} [Zero R] (f : ArithmeticFunction R) : toArithmeticFunction f = f := by ext n simp +contextual [toArithmeticFunction] /-- Dirichlet convolution of two sequences. We define this in terms of the already existing definition for arithmetic functions. -/ noncomputable def LSeries.convolution {R : Type*} [Semiring R] (f g : ℕ → R) : ℕ → R := ⇑(toArithmeticFunction f * toArithmeticFunction g) @[inherit_doc] scoped[LSeries.notation] infixl:70 " ⍟ " => LSeries.convolution lemma LSeries.convolution_congr {R : Type*} [Semiring R] {f f' g g' : ℕ → R} (hf : ∀ {n}, n ≠ 0 → f n = f' n) (hg : ∀ {n}, n ≠ 0 → g n = g' n) : f ⍟ g = f' ⍟ g' := by simp [convolution, toArithmeticFunction_congr hf, toArithmeticFunction_congr hg] /-- The product of two arithmetic functions defines the same function as the Dirichlet convolution of the functions defined by them. -/ lemma ArithmeticFunction.coe_mul {R : Type*} [Semiring R] (f g : ArithmeticFunction R) : f ⍟ g = ⇑(f * g) := by simp [convolution] namespace LSeries lemma convolution_def {R : Type*} [Semiring R] (f g : ℕ → R) : f ⍟ g = fun n ↦ ∑ p ∈ n.divisorsAntidiagonal, f p.1 * g p.2 := by
ext n simpa [convolution, toArithmeticFunction] using Finset.sum_congr rfl fun p hp ↦ by simp [ne_zero_of_mem_divisorsAntidiagonal hp] @[simp] lemma convolution_map_zero {R : Type*} [Semiring R] (f g : ℕ → R) : (f ⍟ g) 0 = 0 := by simp [convolution_def]
Mathlib/NumberTheory/LSeries/Convolution.lean
79
86
/- Copyright (c) 2019 Calle Sönne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Calle Sönne -/ import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic import Mathlib.Analysis.Normed.Group.AddCircle import Mathlib.Algebra.CharZero.Quotient import Mathlib.Topology.Instances.Sign /-! # The type of angles In this file we define `Real.Angle` to be the quotient group `ℝ/2πℤ` and prove a few simple lemmas about trigonometric functions and angles. -/ open Real noncomputable section namespace Real /-- The type of angles -/ def Angle : Type := AddCircle (2 * π) -- The `NormedAddCommGroup, Inhabited` instances should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 namespace Angle instance : NormedAddCommGroup Angle := inferInstanceAs (NormedAddCommGroup (AddCircle (2 * π))) instance : Inhabited Angle := inferInstanceAs (Inhabited (AddCircle (2 * π))) /-- The canonical map from `ℝ` to the quotient `Angle`. -/ @[coe] protected def coe (r : ℝ) : Angle := QuotientAddGroup.mk r instance : Coe ℝ Angle := ⟨Angle.coe⟩ instance : CircularOrder Real.Angle := QuotientAddGroup.circularOrder (hp' := ⟨by norm_num [pi_pos]⟩) @[continuity] theorem continuous_coe : Continuous ((↑) : ℝ → Angle) := continuous_quotient_mk' /-- Coercion `ℝ → Angle` as an additive homomorphism. -/ def coeHom : ℝ →+ Angle := QuotientAddGroup.mk' _ @[simp] theorem coe_coeHom : (coeHom : ℝ → Angle) = ((↑) : ℝ → Angle) := rfl /-- An induction principle to deduce results for `Angle` from those for `ℝ`, used with `induction θ using Real.Angle.induction_on`. -/ @[elab_as_elim] protected theorem induction_on {p : Angle → Prop} (θ : Angle) (h : ∀ x : ℝ, p x) : p θ := Quotient.inductionOn' θ h @[simp] theorem coe_zero : ↑(0 : ℝ) = (0 : Angle) := rfl @[simp] theorem coe_add (x y : ℝ) : ↑(x + y : ℝ) = (↑x + ↑y : Angle) := rfl @[simp] theorem coe_neg (x : ℝ) : ↑(-x : ℝ) = -(↑x : Angle) := rfl @[simp] theorem coe_sub (x y : ℝ) : ↑(x - y : ℝ) = (↑x - ↑y : Angle) := rfl theorem coe_nsmul (n : ℕ) (x : ℝ) : ↑(n • x : ℝ) = n • (↑x : Angle) := rfl theorem coe_zsmul (z : ℤ) (x : ℝ) : ↑(z • x : ℝ) = z • (↑x : Angle) := rfl theorem coe_eq_zero_iff {x : ℝ} : (x : Angle) = 0 ↔ ∃ n : ℤ, n • (2 * π) = x := AddCircle.coe_eq_zero_iff (2 * π) @[simp, norm_cast] theorem natCast_mul_eq_nsmul (x : ℝ) (n : ℕ) : ↑((n : ℝ) * x) = n • (↑x : Angle) := by simpa only [nsmul_eq_mul] using coeHom.map_nsmul x n @[simp, norm_cast] theorem intCast_mul_eq_zsmul (x : ℝ) (n : ℤ) : ↑((n : ℝ) * x : ℝ) = n • (↑x : Angle) := by simpa only [zsmul_eq_mul] using coeHom.map_zsmul x n theorem angle_eq_iff_two_pi_dvd_sub {ψ θ : ℝ} : (θ : Angle) = ψ ↔ ∃ k : ℤ, θ - ψ = 2 * π * k := by simp only [QuotientAddGroup.eq, AddSubgroup.zmultiples_eq_closure, AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm] rw [Angle.coe, Angle.coe, QuotientAddGroup.eq] simp only [AddSubgroup.zmultiples_eq_closure, AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm] @[simp] theorem coe_two_pi : ↑(2 * π : ℝ) = (0 : Angle) := angle_eq_iff_two_pi_dvd_sub.2 ⟨1, by rw [sub_zero, Int.cast_one, mul_one]⟩ @[simp] theorem neg_coe_pi : -(π : Angle) = π := by rw [← coe_neg, angle_eq_iff_two_pi_dvd_sub] use -1 simp [two_mul, sub_eq_add_neg] @[simp] theorem two_nsmul_coe_div_two (θ : ℝ) : (2 : ℕ) • (↑(θ / 2) : Angle) = θ := by rw [← coe_nsmul, two_nsmul, add_halves] @[simp] theorem two_zsmul_coe_div_two (θ : ℝ) : (2 : ℤ) • (↑(θ / 2) : Angle) = θ := by rw [← coe_zsmul, two_zsmul, add_halves] theorem two_nsmul_neg_pi_div_two : (2 : ℕ) • (↑(-π / 2) : Angle) = π := by rw [two_nsmul_coe_div_two, coe_neg, neg_coe_pi] theorem two_zsmul_neg_pi_div_two : (2 : ℤ) • (↑(-π / 2) : Angle) = π := by rw [two_zsmul, ← two_nsmul, two_nsmul_neg_pi_div_two] theorem sub_coe_pi_eq_add_coe_pi (θ : Angle) : θ - π = θ + π := by rw [sub_eq_add_neg, neg_coe_pi] @[simp] theorem two_nsmul_coe_pi : (2 : ℕ) • (π : Angle) = 0 := by simp [← natCast_mul_eq_nsmul] @[simp] theorem two_zsmul_coe_pi : (2 : ℤ) • (π : Angle) = 0 := by simp [← intCast_mul_eq_zsmul] @[simp] theorem coe_pi_add_coe_pi : (π : Real.Angle) + π = 0 := by rw [← two_nsmul, two_nsmul_coe_pi] theorem zsmul_eq_iff {ψ θ : Angle} {z : ℤ} (hz : z ≠ 0) : z • ψ = z • θ ↔ ∃ k : Fin z.natAbs, ψ = θ + (k : ℕ) • (2 * π / z : ℝ) := QuotientAddGroup.zmultiples_zsmul_eq_zsmul_iff hz theorem nsmul_eq_iff {ψ θ : Angle} {n : ℕ} (hz : n ≠ 0) : n • ψ = n • θ ↔ ∃ k : Fin n, ψ = θ + (k : ℕ) • (2 * π / n : ℝ) := QuotientAddGroup.zmultiples_nsmul_eq_nsmul_iff hz theorem two_zsmul_eq_iff {ψ θ : Angle} : (2 : ℤ) • ψ = (2 : ℤ) • θ ↔ ψ = θ ∨ ψ = θ + ↑π := by have : Int.natAbs 2 = 2 := rfl rw [zsmul_eq_iff two_ne_zero, this, Fin.exists_fin_two, Fin.val_zero, Fin.val_one, zero_smul, add_zero, one_smul, Int.cast_two, mul_div_cancel_left₀ (_ : ℝ) two_ne_zero] theorem two_nsmul_eq_iff {ψ θ : Angle} : (2 : ℕ) • ψ = (2 : ℕ) • θ ↔ ψ = θ ∨ ψ = θ + ↑π := by simp_rw [← natCast_zsmul, Nat.cast_ofNat, two_zsmul_eq_iff] theorem two_nsmul_eq_zero_iff {θ : Angle} : (2 : ℕ) • θ = 0 ↔ θ = 0 ∨ θ = π := by convert two_nsmul_eq_iff <;> simp theorem two_nsmul_ne_zero_iff {θ : Angle} : (2 : ℕ) • θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← two_nsmul_eq_zero_iff] theorem two_zsmul_eq_zero_iff {θ : Angle} : (2 : ℤ) • θ = 0 ↔ θ = 0 ∨ θ = π := by simp_rw [two_zsmul, ← two_nsmul, two_nsmul_eq_zero_iff] theorem two_zsmul_ne_zero_iff {θ : Angle} : (2 : ℤ) • θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← two_zsmul_eq_zero_iff] theorem eq_neg_self_iff {θ : Angle} : θ = -θ ↔ θ = 0 ∨ θ = π := by rw [← add_eq_zero_iff_eq_neg, ← two_nsmul, two_nsmul_eq_zero_iff] theorem ne_neg_self_iff {θ : Angle} : θ ≠ -θ ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← eq_neg_self_iff.not] theorem neg_eq_self_iff {θ : Angle} : -θ = θ ↔ θ = 0 ∨ θ = π := by rw [eq_comm, eq_neg_self_iff] theorem neg_ne_self_iff {θ : Angle} : -θ ≠ θ ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← neg_eq_self_iff.not] theorem two_nsmul_eq_pi_iff {θ : Angle} : (2 : ℕ) • θ = π ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by have h : (π : Angle) = ((2 : ℕ) • (π / 2 : ℝ):) := by rw [two_nsmul, add_halves] nth_rw 1 [h] rw [coe_nsmul, two_nsmul_eq_iff] -- Porting note: `congr` didn't simplify the goal of iff of `Or`s convert Iff.rfl rw [add_comm, ← coe_add, ← sub_eq_zero, ← coe_sub, neg_div, ← neg_sub, sub_neg_eq_add, add_assoc, add_halves, ← two_mul, coe_neg, coe_two_pi, neg_zero] theorem two_zsmul_eq_pi_iff {θ : Angle} : (2 : ℤ) • θ = π ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by rw [two_zsmul, ← two_nsmul, two_nsmul_eq_pi_iff] theorem cos_eq_iff_coe_eq_or_eq_neg {θ ψ : ℝ} : cos θ = cos ψ ↔ (θ : Angle) = ψ ∨ (θ : Angle) = -ψ := by constructor · intro Hcos rw [← sub_eq_zero, cos_sub_cos, mul_eq_zero, mul_eq_zero, neg_eq_zero, eq_false (two_ne_zero' ℝ), false_or, sin_eq_zero_iff, sin_eq_zero_iff] at Hcos rcases Hcos with (⟨n, hn⟩ | ⟨n, hn⟩) · right rw [eq_div_iff_mul_eq (two_ne_zero' ℝ), ← sub_eq_iff_eq_add] at hn rw [← hn, coe_sub, eq_neg_iff_add_eq_zero, sub_add_cancel, mul_assoc, intCast_mul_eq_zsmul, mul_comm, coe_two_pi, zsmul_zero] · left rw [eq_div_iff_mul_eq (two_ne_zero' ℝ), eq_sub_iff_add_eq] at hn rw [← hn, coe_add, mul_assoc, intCast_mul_eq_zsmul, mul_comm, coe_two_pi, zsmul_zero, zero_add] · rw [angle_eq_iff_two_pi_dvd_sub, ← coe_neg, angle_eq_iff_two_pi_dvd_sub] rintro (⟨k, H⟩ | ⟨k, H⟩) · rw [← sub_eq_zero, cos_sub_cos, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero] rw [← sub_eq_zero, cos_sub_cos, ← sub_neg_eq_add, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul] theorem sin_eq_iff_coe_eq_or_add_eq_pi {θ ψ : ℝ} : sin θ = sin ψ ↔ (θ : Angle) = ψ ∨ (θ : Angle) + ψ = π := by constructor · intro Hsin rw [← cos_pi_div_two_sub, ← cos_pi_div_two_sub] at Hsin rcases cos_eq_iff_coe_eq_or_eq_neg.mp Hsin with h | h · left rw [coe_sub, coe_sub] at h exact sub_right_inj.1 h right rw [coe_sub, coe_sub, eq_neg_iff_add_eq_zero, add_sub, sub_add_eq_add_sub, ← coe_add, add_halves, sub_sub, sub_eq_zero] at h exact h.symm · rw [angle_eq_iff_two_pi_dvd_sub, ← eq_sub_iff_add_eq, ← coe_sub, angle_eq_iff_two_pi_dvd_sub] rintro (⟨k, H⟩ | ⟨k, H⟩) · rw [← sub_eq_zero, sin_sub_sin, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul] have H' : θ + ψ = 2 * k * π + π := by rwa [← sub_add, sub_add_eq_add_sub, sub_eq_iff_eq_add, mul_assoc, mul_comm π _, ← mul_assoc] at H rw [← sub_eq_zero, sin_sub_sin, H', add_div, mul_assoc 2 _ π, mul_div_cancel_left₀ _ (two_ne_zero' ℝ), cos_add_pi_div_two, sin_int_mul_pi, neg_zero, mul_zero] theorem cos_sin_inj {θ ψ : ℝ} (Hcos : cos θ = cos ψ) (Hsin : sin θ = sin ψ) : (θ : Angle) = ψ := by rcases cos_eq_iff_coe_eq_or_eq_neg.mp Hcos with hc | hc; · exact hc rcases sin_eq_iff_coe_eq_or_add_eq_pi.mp Hsin with hs | hs; · exact hs rw [eq_neg_iff_add_eq_zero, hs] at hc obtain ⟨n, hn⟩ : ∃ n, n • _ = _ := QuotientAddGroup.leftRel_apply.mp (Quotient.exact' hc) rw [← neg_one_mul, add_zero, ← sub_eq_zero, zsmul_eq_mul, ← mul_assoc, ← sub_mul, mul_eq_zero, eq_false (ne_of_gt pi_pos), or_false, sub_neg_eq_add, ← Int.cast_zero, ← Int.cast_one, ← Int.cast_ofNat, ← Int.cast_mul, ← Int.cast_add, Int.cast_inj] at hn have : (n * 2 + 1) % (2 : ℤ) = 0 % (2 : ℤ) := congr_arg (· % (2 : ℤ)) hn rw [add_comm, Int.add_mul_emod_self_right] at this exact absurd this one_ne_zero /-- The sine of a `Real.Angle`. -/ def sin (θ : Angle) : ℝ := sin_periodic.lift θ @[simp] theorem sin_coe (x : ℝ) : sin (x : Angle) = Real.sin x := rfl @[continuity] theorem continuous_sin : Continuous sin := Real.continuous_sin.quotient_liftOn' _ /-- The cosine of a `Real.Angle`. -/ def cos (θ : Angle) : ℝ := cos_periodic.lift θ @[simp] theorem cos_coe (x : ℝ) : cos (x : Angle) = Real.cos x := rfl @[continuity] theorem continuous_cos : Continuous cos := Real.continuous_cos.quotient_liftOn' _ theorem cos_eq_real_cos_iff_eq_or_eq_neg {θ : Angle} {ψ : ℝ} : cos θ = Real.cos ψ ↔ θ = ψ ∨ θ = -ψ := by induction θ using Real.Angle.induction_on exact cos_eq_iff_coe_eq_or_eq_neg theorem cos_eq_iff_eq_or_eq_neg {θ ψ : Angle} : cos θ = cos ψ ↔ θ = ψ ∨ θ = -ψ := by induction ψ using Real.Angle.induction_on exact cos_eq_real_cos_iff_eq_or_eq_neg theorem sin_eq_real_sin_iff_eq_or_add_eq_pi {θ : Angle} {ψ : ℝ} : sin θ = Real.sin ψ ↔ θ = ψ ∨ θ + ψ = π := by induction θ using Real.Angle.induction_on exact sin_eq_iff_coe_eq_or_add_eq_pi theorem sin_eq_iff_eq_or_add_eq_pi {θ ψ : Angle} : sin θ = sin ψ ↔ θ = ψ ∨ θ + ψ = π := by induction ψ using Real.Angle.induction_on exact sin_eq_real_sin_iff_eq_or_add_eq_pi @[simp] theorem sin_zero : sin (0 : Angle) = 0 := by rw [← coe_zero, sin_coe, Real.sin_zero] theorem sin_coe_pi : sin (π : Angle) = 0 := by rw [sin_coe, Real.sin_pi] theorem sin_eq_zero_iff {θ : Angle} : sin θ = 0 ↔ θ = 0 ∨ θ = π := by nth_rw 1 [← sin_zero] rw [sin_eq_iff_eq_or_add_eq_pi] simp theorem sin_ne_zero_iff {θ : Angle} : sin θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by rw [← not_or, ← sin_eq_zero_iff] @[simp] theorem sin_neg (θ : Angle) : sin (-θ) = -sin θ := by induction θ using Real.Angle.induction_on exact Real.sin_neg _ theorem sin_antiperiodic : Function.Antiperiodic sin (π : Angle) := by intro θ induction θ using Real.Angle.induction_on exact Real.sin_antiperiodic _ @[simp] theorem sin_add_pi (θ : Angle) : sin (θ + π) = -sin θ := sin_antiperiodic θ @[simp] theorem sin_sub_pi (θ : Angle) : sin (θ - π) = -sin θ := sin_antiperiodic.sub_eq θ @[simp] theorem cos_zero : cos (0 : Angle) = 1 := by rw [← coe_zero, cos_coe, Real.cos_zero] theorem cos_coe_pi : cos (π : Angle) = -1 := by rw [cos_coe, Real.cos_pi] @[simp] theorem cos_neg (θ : Angle) : cos (-θ) = cos θ := by induction θ using Real.Angle.induction_on exact Real.cos_neg _ theorem cos_antiperiodic : Function.Antiperiodic cos (π : Angle) := by intro θ induction θ using Real.Angle.induction_on exact Real.cos_antiperiodic _ @[simp] theorem cos_add_pi (θ : Angle) : cos (θ + π) = -cos θ := cos_antiperiodic θ @[simp] theorem cos_sub_pi (θ : Angle) : cos (θ - π) = -cos θ := cos_antiperiodic.sub_eq θ theorem cos_eq_zero_iff {θ : Angle} : cos θ = 0 ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by rw [← cos_pi_div_two, ← cos_coe, cos_eq_iff_eq_or_eq_neg, ← coe_neg, ← neg_div] theorem sin_add (θ₁ θ₂ : Real.Angle) : sin (θ₁ + θ₂) = sin θ₁ * cos θ₂ + cos θ₁ * sin θ₂ := by induction θ₁ using Real.Angle.induction_on induction θ₂ using Real.Angle.induction_on exact Real.sin_add _ _ theorem cos_add (θ₁ θ₂ : Real.Angle) : cos (θ₁ + θ₂) = cos θ₁ * cos θ₂ - sin θ₁ * sin θ₂ := by induction θ₂ using Real.Angle.induction_on induction θ₁ using Real.Angle.induction_on exact Real.cos_add _ _ @[simp] theorem cos_sq_add_sin_sq (θ : Real.Angle) : cos θ ^ 2 + sin θ ^ 2 = 1 := by induction θ using Real.Angle.induction_on exact Real.cos_sq_add_sin_sq _ theorem sin_add_pi_div_two (θ : Angle) : sin (θ + ↑(π / 2)) = cos θ := by induction θ using Real.Angle.induction_on exact Real.sin_add_pi_div_two _ theorem sin_sub_pi_div_two (θ : Angle) : sin (θ - ↑(π / 2)) = -cos θ := by induction θ using Real.Angle.induction_on exact Real.sin_sub_pi_div_two _ theorem sin_pi_div_two_sub (θ : Angle) : sin (↑(π / 2) - θ) = cos θ := by induction θ using Real.Angle.induction_on exact Real.sin_pi_div_two_sub _ theorem cos_add_pi_div_two (θ : Angle) : cos (θ + ↑(π / 2)) = -sin θ := by induction θ using Real.Angle.induction_on exact Real.cos_add_pi_div_two _ theorem cos_sub_pi_div_two (θ : Angle) : cos (θ - ↑(π / 2)) = sin θ := by induction θ using Real.Angle.induction_on exact Real.cos_sub_pi_div_two _ theorem cos_pi_div_two_sub (θ : Angle) : cos (↑(π / 2) - θ) = sin θ := by induction θ using Real.Angle.induction_on exact Real.cos_pi_div_two_sub _ theorem abs_sin_eq_of_two_nsmul_eq {θ ψ : Angle} (h : (2 : ℕ) • θ = (2 : ℕ) • ψ) : |sin θ| = |sin ψ| := by rw [two_nsmul_eq_iff] at h rcases h with (rfl | rfl) · rfl · rw [sin_add_pi, abs_neg] theorem abs_sin_eq_of_two_zsmul_eq {θ ψ : Angle} (h : (2 : ℤ) • θ = (2 : ℤ) • ψ) : |sin θ| = |sin ψ| := by simp_rw [two_zsmul, ← two_nsmul] at h exact abs_sin_eq_of_two_nsmul_eq h theorem abs_cos_eq_of_two_nsmul_eq {θ ψ : Angle} (h : (2 : ℕ) • θ = (2 : ℕ) • ψ) : |cos θ| = |cos ψ| := by rw [two_nsmul_eq_iff] at h rcases h with (rfl | rfl) · rfl · rw [cos_add_pi, abs_neg] theorem abs_cos_eq_of_two_zsmul_eq {θ ψ : Angle} (h : (2 : ℤ) • θ = (2 : ℤ) • ψ) : |cos θ| = |cos ψ| := by simp_rw [two_zsmul, ← two_nsmul] at h exact abs_cos_eq_of_two_nsmul_eq h @[simp] theorem coe_toIcoMod (θ ψ : ℝ) : ↑(toIcoMod two_pi_pos ψ θ) = (θ : Angle) := by rw [angle_eq_iff_two_pi_dvd_sub] refine ⟨-toIcoDiv two_pi_pos ψ θ, ?_⟩ rw [toIcoMod_sub_self, zsmul_eq_mul, mul_comm] @[simp] theorem coe_toIocMod (θ ψ : ℝ) : ↑(toIocMod two_pi_pos ψ θ) = (θ : Angle) := by rw [angle_eq_iff_two_pi_dvd_sub] refine ⟨-toIocDiv two_pi_pos ψ θ, ?_⟩ rw [toIocMod_sub_self, zsmul_eq_mul, mul_comm] /-- Convert a `Real.Angle` to a real number in the interval `Ioc (-π) π`. -/ def toReal (θ : Angle) : ℝ := (toIocMod_periodic two_pi_pos (-π)).lift θ theorem toReal_coe (θ : ℝ) : (θ : Angle).toReal = toIocMod two_pi_pos (-π) θ := rfl theorem toReal_coe_eq_self_iff {θ : ℝ} : (θ : Angle).toReal = θ ↔ -π < θ ∧ θ ≤ π := by rw [toReal_coe, toIocMod_eq_self two_pi_pos] ring_nf rfl theorem toReal_coe_eq_self_iff_mem_Ioc {θ : ℝ} : (θ : Angle).toReal = θ ↔ θ ∈ Set.Ioc (-π) π := by rw [toReal_coe_eq_self_iff, ← Set.mem_Ioc] theorem toReal_injective : Function.Injective toReal := by intro θ ψ h induction θ using Real.Angle.induction_on induction ψ using Real.Angle.induction_on simpa [toReal_coe, toIocMod_eq_toIocMod, zsmul_eq_mul, mul_comm _ (2 * π), ← angle_eq_iff_two_pi_dvd_sub, eq_comm] using h @[simp] theorem toReal_inj {θ ψ : Angle} : θ.toReal = ψ.toReal ↔ θ = ψ := toReal_injective.eq_iff @[simp] theorem coe_toReal (θ : Angle) : (θ.toReal : Angle) = θ := by induction θ using Real.Angle.induction_on exact coe_toIocMod _ _ theorem neg_pi_lt_toReal (θ : Angle) : -π < θ.toReal := by induction θ using Real.Angle.induction_on exact left_lt_toIocMod _ _ _ theorem toReal_le_pi (θ : Angle) : θ.toReal ≤ π := by induction θ using Real.Angle.induction_on convert toIocMod_le_right two_pi_pos _ _ ring theorem abs_toReal_le_pi (θ : Angle) : |θ.toReal| ≤ π := abs_le.2 ⟨(neg_pi_lt_toReal _).le, toReal_le_pi _⟩ theorem toReal_mem_Ioc (θ : Angle) : θ.toReal ∈ Set.Ioc (-π) π := ⟨neg_pi_lt_toReal _, toReal_le_pi _⟩ @[simp] theorem toIocMod_toReal (θ : Angle) : toIocMod two_pi_pos (-π) θ.toReal = θ.toReal := by induction θ using Real.Angle.induction_on rw [toReal_coe] exact toIocMod_toIocMod _ _ _ _ @[simp] theorem toReal_zero : (0 : Angle).toReal = 0 := by rw [← coe_zero, toReal_coe_eq_self_iff] exact ⟨Left.neg_neg_iff.2 Real.pi_pos, Real.pi_pos.le⟩ @[simp] theorem toReal_eq_zero_iff {θ : Angle} : θ.toReal = 0 ↔ θ = 0 := by nth_rw 1 [← toReal_zero] exact toReal_inj @[simp] theorem toReal_pi : (π : Angle).toReal = π := by rw [toReal_coe_eq_self_iff] exact ⟨Left.neg_lt_self Real.pi_pos, le_refl _⟩ @[simp] theorem toReal_eq_pi_iff {θ : Angle} : θ.toReal = π ↔ θ = π := by rw [← toReal_inj, toReal_pi] theorem pi_ne_zero : (π : Angle) ≠ 0 := by rw [← toReal_injective.ne_iff, toReal_pi, toReal_zero] exact Real.pi_ne_zero @[simp] theorem toReal_pi_div_two : ((π / 2 : ℝ) : Angle).toReal = π / 2 := toReal_coe_eq_self_iff.2 <| by constructor <;> linarith [pi_pos] @[simp] theorem toReal_eq_pi_div_two_iff {θ : Angle} : θ.toReal = π / 2 ↔ θ = (π / 2 : ℝ) := by rw [← toReal_inj, toReal_pi_div_two] @[simp] theorem toReal_neg_pi_div_two : ((-π / 2 : ℝ) : Angle).toReal = -π / 2 := toReal_coe_eq_self_iff.2 <| by constructor <;> linarith [pi_pos] @[simp] theorem toReal_eq_neg_pi_div_two_iff {θ : Angle} : θ.toReal = -π / 2 ↔ θ = (-π / 2 : ℝ) := by rw [← toReal_inj, toReal_neg_pi_div_two] theorem pi_div_two_ne_zero : ((π / 2 : ℝ) : Angle) ≠ 0 := by rw [← toReal_injective.ne_iff, toReal_pi_div_two, toReal_zero] exact div_ne_zero Real.pi_ne_zero two_ne_zero theorem neg_pi_div_two_ne_zero : ((-π / 2 : ℝ) : Angle) ≠ 0 := by rw [← toReal_injective.ne_iff, toReal_neg_pi_div_two, toReal_zero] exact div_ne_zero (neg_ne_zero.2 Real.pi_ne_zero) two_ne_zero theorem abs_toReal_coe_eq_self_iff {θ : ℝ} : |(θ : Angle).toReal| = θ ↔ 0 ≤ θ ∧ θ ≤ π := ⟨fun h => h ▸ ⟨abs_nonneg _, abs_toReal_le_pi _⟩, fun h => (toReal_coe_eq_self_iff.2 ⟨(Left.neg_neg_iff.2 Real.pi_pos).trans_le h.1, h.2⟩).symm ▸ abs_eq_self.2 h.1⟩ theorem abs_toReal_neg_coe_eq_self_iff {θ : ℝ} : |(-θ : Angle).toReal| = θ ↔ 0 ≤ θ ∧ θ ≤ π := by refine ⟨fun h => h ▸ ⟨abs_nonneg _, abs_toReal_le_pi _⟩, fun h => ?_⟩ by_cases hnegpi : θ = π; · simp [hnegpi, Real.pi_pos.le] rw [← coe_neg, toReal_coe_eq_self_iff.2 ⟨neg_lt_neg (lt_of_le_of_ne h.2 hnegpi), (neg_nonpos.2 h.1).trans Real.pi_pos.le⟩, abs_neg, abs_eq_self.2 h.1] theorem abs_toReal_eq_pi_div_two_iff {θ : Angle} : |θ.toReal| = π / 2 ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by rw [abs_eq (div_nonneg Real.pi_pos.le two_pos.le), ← neg_div, toReal_eq_pi_div_two_iff, toReal_eq_neg_pi_div_two_iff] theorem nsmul_toReal_eq_mul {n : ℕ} (h : n ≠ 0) {θ : Angle} : (n • θ).toReal = n * θ.toReal ↔ θ.toReal ∈ Set.Ioc (-π / n) (π / n) := by nth_rw 1 [← coe_toReal θ] have h' : 0 < (n : ℝ) := mod_cast Nat.pos_of_ne_zero h rw [← coe_nsmul, nsmul_eq_mul, toReal_coe_eq_self_iff, Set.mem_Ioc, div_lt_iff₀' h', le_div_iff₀' h'] theorem two_nsmul_toReal_eq_two_mul {θ : Angle} : ((2 : ℕ) • θ).toReal = 2 * θ.toReal ↔ θ.toReal ∈ Set.Ioc (-π / 2) (π / 2) := mod_cast nsmul_toReal_eq_mul two_ne_zero theorem two_zsmul_toReal_eq_two_mul {θ : Angle} : ((2 : ℤ) • θ).toReal = 2 * θ.toReal ↔ θ.toReal ∈ Set.Ioc (-π / 2) (π / 2) := by rw [two_zsmul, ← two_nsmul, two_nsmul_toReal_eq_two_mul] theorem toReal_coe_eq_self_sub_two_mul_int_mul_pi_iff {θ : ℝ} {k : ℤ} : (θ : Angle).toReal = θ - 2 * k * π ↔ θ ∈ Set.Ioc ((2 * k - 1 : ℝ) * π) ((2 * k + 1) * π) := by rw [← sub_zero (θ : Angle), ← zsmul_zero k, ← coe_two_pi, ← coe_zsmul, ← coe_sub, zsmul_eq_mul, ← mul_assoc, mul_comm (k : ℝ), toReal_coe_eq_self_iff, Set.mem_Ioc] exact ⟨fun h => ⟨by linarith, by linarith⟩, fun h => ⟨by linarith, by linarith⟩⟩
theorem toReal_coe_eq_self_sub_two_pi_iff {θ : ℝ} : (θ : Angle).toReal = θ - 2 * π ↔ θ ∈ Set.Ioc π (3 * π) := by convert @toReal_coe_eq_self_sub_two_mul_int_mul_pi_iff θ 1 <;> norm_num
Mathlib/Analysis/SpecialFunctions/Trigonometric/Angle.lean
564
567
/- Copyright (c) 2021 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth, Eric Wieser -/ import Mathlib.Analysis.Normed.Lp.PiLp import Mathlib.Analysis.InnerProductSpace.PiL2 /-! # Matrices as a normed space In this file we provide the following non-instances for norms on matrices: * The elementwise norm: * `Matrix.seminormedAddCommGroup` * `Matrix.normedAddCommGroup` * `Matrix.normedSpace` * `Matrix.isBoundedSMul` * The Frobenius norm: * `Matrix.frobeniusSeminormedAddCommGroup` * `Matrix.frobeniusNormedAddCommGroup` * `Matrix.frobeniusNormedSpace` * `Matrix.frobeniusNormedRing` * `Matrix.frobeniusNormedAlgebra` * `Matrix.frobeniusIsBoundedSMul` * The $L^\infty$ operator norm: * `Matrix.linftyOpSeminormedAddCommGroup` * `Matrix.linftyOpNormedAddCommGroup` * `Matrix.linftyOpNormedSpace` * `Matrix.linftyOpIsBoundedSMul` * `Matrix.linftyOpNonUnitalSemiNormedRing` * `Matrix.linftyOpSemiNormedRing` * `Matrix.linftyOpNonUnitalNormedRing` * `Matrix.linftyOpNormedRing` * `Matrix.linftyOpNormedAlgebra` These are not declared as instances because there are several natural choices for defining the norm of a matrix. The norm induced by the identification of `Matrix m n 𝕜` with `EuclideanSpace n 𝕜 →L[𝕜] EuclideanSpace m 𝕜` (i.e., the ℓ² operator norm) can be found in `Analysis.CStarAlgebra.Matrix`. It is separated to avoid extraneous imports in this file. -/ noncomputable section open scoped NNReal Matrix namespace Matrix variable {R l m n α β ι : Type*} [Fintype l] [Fintype m] [Fintype n] [Unique ι] /-! ### The elementwise supremum norm -/ section LinfLinf section SeminormedAddCommGroup variable [SeminormedAddCommGroup α] [SeminormedAddCommGroup β] /-- Seminormed group instance (using sup norm of sup norm) for matrices over a seminormed group. Not declared as an instance because there are several natural choices for defining the norm of a matrix. -/ protected def seminormedAddCommGroup : SeminormedAddCommGroup (Matrix m n α) := Pi.seminormedAddCommGroup attribute [local instance] Matrix.seminormedAddCommGroup theorem norm_def (A : Matrix m n α) : ‖A‖ = ‖fun i j => A i j‖ := rfl /-- The norm of a matrix is the sup of the sup of the nnnorm of the entries -/ lemma norm_eq_sup_sup_nnnorm (A : Matrix m n α) : ‖A‖ = Finset.sup Finset.univ fun i ↦ Finset.sup Finset.univ fun j ↦ ‖A i j‖₊ := by simp_rw [Matrix.norm_def, Pi.norm_def, Pi.nnnorm_def] theorem nnnorm_def (A : Matrix m n α) : ‖A‖₊ = ‖fun i j => A i j‖₊ := rfl theorem norm_le_iff {r : ℝ} (hr : 0 ≤ r) {A : Matrix m n α} : ‖A‖ ≤ r ↔ ∀ i j, ‖A i j‖ ≤ r := by simp_rw [norm_def, pi_norm_le_iff_of_nonneg hr] theorem nnnorm_le_iff {r : ℝ≥0} {A : Matrix m n α} : ‖A‖₊ ≤ r ↔ ∀ i j, ‖A i j‖₊ ≤ r := by simp_rw [nnnorm_def, pi_nnnorm_le_iff] theorem norm_lt_iff {r : ℝ} (hr : 0 < r) {A : Matrix m n α} : ‖A‖ < r ↔ ∀ i j, ‖A i j‖ < r := by simp_rw [norm_def, pi_norm_lt_iff hr] theorem nnnorm_lt_iff {r : ℝ≥0} (hr : 0 < r) {A : Matrix m n α} : ‖A‖₊ < r ↔ ∀ i j, ‖A i j‖₊ < r := by simp_rw [nnnorm_def, pi_nnnorm_lt_iff hr] theorem norm_entry_le_entrywise_sup_norm (A : Matrix m n α) {i : m} {j : n} : ‖A i j‖ ≤ ‖A‖ := (norm_le_pi_norm (A i) j).trans (norm_le_pi_norm A i)
theorem nnnorm_entry_le_entrywise_sup_nnnorm (A : Matrix m n α) {i : m} {j : n} : ‖A i j‖₊ ≤ ‖A‖₊ := (nnnorm_le_pi_nnnorm (A i) j).trans (nnnorm_le_pi_nnnorm A i)
Mathlib/Analysis/Matrix.lean
100
102
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Patrick Massot, Kim Morrison -/ import Mathlib.CategoryTheory.Adjunction.Reflective import Mathlib.CategoryTheory.Monad.Limits import Mathlib.Topology.Category.TopCat.Basic import Mathlib.Topology.UniformSpace.Completion /-! # The category of uniform spaces We construct the category of uniform spaces, show that the complete separated uniform spaces form a reflective subcategory, and hence possess all limits that uniform spaces do. TODO: show that uniform spaces actually have all limits! -/ universe u open CategoryTheory /-- An object in the category of uniform spaces. -/ structure UniformSpaceCat : Type (u + 1) where /-- The underlying uniform space. -/ carrier : Type u [str : UniformSpace carrier] attribute [instance] UniformSpaceCat.str namespace UniformSpaceCat instance : CoeSort UniformSpaceCat Type* := ⟨carrier⟩ /-- Construct a bundled `UniformSpace` from the underlying type and the typeclass. -/ abbrev of (α : Type u) [UniformSpace α] : UniformSpaceCat where carrier := α /-- A bundled uniform continuous map. -/ @[ext] structure Hom (X Y : UniformSpaceCat) where /-- The underlying `UniformContinuous` function. -/ hom' : { f : X → Y // UniformContinuous f } instance : LargeCategory.{u} UniformSpaceCat.{u} where Hom := Hom id X := ⟨id, uniformContinuous_id⟩ comp f g := ⟨⟨g.hom'.val ∘ f.hom'.val, g.hom'.property.comp f.hom'.property⟩⟩ id_comp := by intros; apply Hom.ext; simp comp_id := by intros; apply Hom.ext; simp assoc := by intros; apply Hom.ext; ext; simp instance instFunLike (X Y : UniformSpaceCat) : FunLike { f : X → Y // UniformContinuous f } X Y where coe := Subtype.val coe_injective' _ _ h := Subtype.ext h instance : ConcreteCategory UniformSpaceCat ({ f : · → · // UniformContinuous f }) where hom f := f.hom' ofHom f := ⟨f⟩ /-- Turn a morphism in `UniformSpaceCat` back into a function which is `UniformContinuous`. -/ abbrev Hom.hom {X Y : UniformSpaceCat} (f : Hom X Y) := ConcreteCategory.hom (C := UniformSpaceCat) f /-- Typecheck a function which is `UniformContinuous` as a morphism in `UniformSpaceCat`. -/ abbrev ofHom {X Y : Type u} [UniformSpace X] [UniformSpace Y] (f : { f : X → Y // UniformContinuous f }) : of X ⟶ of Y := ConcreteCategory.ofHom f instance : Inhabited UniformSpaceCat := ⟨UniformSpaceCat.of Empty⟩ theorem coe_of (X : Type u) [UniformSpace X] : (of X : Type u) = X := rfl @[simp] theorem hom_comp {X Y Z : UniformSpaceCat} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).hom = ⟨g ∘ f, g.hom.prop.comp f.hom.prop⟩ := rfl @[simp] theorem hom_id (X : UniformSpaceCat) : (𝟙 X : X ⟶ X).hom = ⟨id, uniformContinuous_id⟩ := rfl @[simp] theorem hom_ofHom {X Y : Type u} [UniformSpace X] [UniformSpace Y] (f : { f : X → Y // UniformContinuous f }) : (ofHom f).hom = f := rfl theorem coe_comp {X Y Z : UniformSpaceCat} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g : X → Z) = g ∘ f := rfl theorem coe_id (X : UniformSpaceCat) : (𝟙 X : X → X) = id := rfl theorem coe_mk {X Y : UniformSpaceCat} (f : X → Y) (hf : UniformContinuous f) : (⟨f, hf⟩ : X ⟶ Y).hom = f := rfl @[ext] theorem hom_ext {X Y : UniformSpaceCat} {f g : X ⟶ Y} (h : (f : X → Y) = g) : f = g := Hom.ext (Subtype.ext h) /-- The forgetful functor from uniform spaces to topological spaces. -/ instance hasForgetToTop : HasForget₂ UniformSpaceCat.{u} TopCat.{u} where forget₂ := { obj := fun X => TopCat.of X map := fun f => TopCat.ofHom { toFun := f continuous_toFun := f.hom.property.continuous } } end UniformSpaceCat /-- A (bundled) complete separated uniform space. -/ structure CpltSepUniformSpace where /-- The underlying space -/ α : Type u [isUniformSpace : UniformSpace α] [isCompleteSpace : CompleteSpace α] [isT0 : T0Space α] namespace CpltSepUniformSpace instance : CoeSort CpltSepUniformSpace (Type u) := ⟨CpltSepUniformSpace.α⟩ attribute [instance] isUniformSpace isCompleteSpace isT0 /-- The function forgetting that a complete separated uniform spaces is complete and separated. -/ def toUniformSpace (X : CpltSepUniformSpace) : UniformSpaceCat := UniformSpaceCat.of X instance completeSpace (X : CpltSepUniformSpace) : CompleteSpace (toUniformSpace X).carrier := CpltSepUniformSpace.isCompleteSpace X instance t0Space (X : CpltSepUniformSpace) : T0Space (toUniformSpace X).carrier := CpltSepUniformSpace.isT0 X /-- Construct a bundled `UniformSpace` from the underlying type and the appropriate typeclasses. -/ def of (X : Type u) [UniformSpace X] [CompleteSpace X] [T0Space X] : CpltSepUniformSpace := ⟨X⟩ @[simp] theorem coe_of (X : Type u) [UniformSpace X] [CompleteSpace X] [T0Space X] : (of X : Type u) = X := rfl instance : Inhabited CpltSepUniformSpace := ⟨CpltSepUniformSpace.of Empty⟩ /-- The category instance on `CpltSepUniformSpace`. -/ instance category : LargeCategory CpltSepUniformSpace := InducedCategory.category toUniformSpace instance instFunLike (X Y : CpltSepUniformSpace) : FunLike { f : X → Y // UniformContinuous f } X Y where coe := Subtype.val coe_injective' _ _ h := Subtype.ext h /-- The concrete category instance on `CpltSepUniformSpace`. -/ instance concreteCategory : ConcreteCategory CpltSepUniformSpace ({ f : · → · // UniformContinuous f }) := InducedCategory.concreteCategory toUniformSpace instance hasForgetToUniformSpace : HasForget₂ CpltSepUniformSpace UniformSpaceCat := InducedCategory.hasForget₂ toUniformSpace @[simp] theorem hom_comp {X Y Z : CpltSepUniformSpace} (f : X ⟶ Y) (g : Y ⟶ Z) : ConcreteCategory.hom (f ≫ g) = ⟨g ∘ f, g.hom.prop.comp f.hom.prop⟩ := rfl @[simp] theorem hom_id (X : CpltSepUniformSpace) : ConcreteCategory.hom (𝟙 X : X ⟶ X) = ⟨id, uniformContinuous_id⟩ := rfl @[simp] theorem hom_ofHom {X Y : Type u} [UniformSpace X] [UniformSpace Y] (f : { f : X → Y // UniformContinuous f }) : (UniformSpaceCat.ofHom f).hom = f := rfl end CpltSepUniformSpace namespace UniformSpaceCat open UniformSpace open CpltSepUniformSpace /-- The functor turning uniform spaces into complete separated uniform spaces. -/ @[simps map] noncomputable def completionFunctor : UniformSpaceCat ⥤ CpltSepUniformSpace where obj X := CpltSepUniformSpace.of (Completion X) map f := ofHom ⟨Completion.map f.1, Completion.uniformContinuous_map⟩ map_id _ := hom_ext Completion.map_id map_comp f g := hom_ext (Completion.map_comp g.hom.property f.hom.property).symm /-- The inclusion of a uniform space into its completion. -/ def completionHom (X : UniformSpaceCat) : X ⟶ (forget₂ CpltSepUniformSpace UniformSpaceCat).obj (completionFunctor.obj X) where hom'.val := ((↑) : X → Completion X) hom'.property := Completion.uniformContinuous_coe X
@[simp] theorem completionHom_val (X : UniformSpaceCat) (x) : (completionHom X) x = (x : Completion X) := rfl /-- The mate of a morphism from a `UniformSpace` to a `CpltSepUniformSpace`. -/ noncomputable def extensionHom {X : UniformSpaceCat} {Y : CpltSepUniformSpace}
Mathlib/Topology/Category/UniformSpace.lean
210
215
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.Probability.Independence.Kernel import Mathlib.MeasureTheory.Constructions.Pi /-! # Independence of sets of sets and measure spaces (σ-algebras) * A family of sets of sets `π : ι → Set (Set Ω)` is independent with respect to a measure `μ` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ π i_1, ..., f i_n ∈ π i_n`, `μ (⋂ i in s, f i) = ∏ i ∈ s, μ (f i)`. It will be used for families of π-systems. * A family of measurable space structures (i.e. of σ-algebras) is independent with respect to a measure `μ` (typically defined on a finer σ-algebra) if the family of sets of measurable sets they define is independent. I.e., `m : ι → MeasurableSpace Ω` is independent with respect to a measure `μ` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ m i_1, ..., f i_n ∈ m i_n`, then `μ (⋂ i in s, f i) = ∏ i ∈ s, μ (f i)`. * Independence of sets (or events in probabilistic parlance) is defined as independence of the measurable space structures they generate: a set `s` generates the measurable space structure with measurable sets `∅, s, sᶜ, univ`. * Independence of functions (or random variables) is also defined as independence of the measurable space structures they generate: a function `f` for which we have a measurable space `m` on the codomain generates `MeasurableSpace.comap f m`. ## Main statements * `iIndepSets.iIndep`: if π-systems are independent as sets of sets, then the measurable space structures they generate are independent. * `IndepSets.indep`: variant with two π-systems. ## Implementation notes The definitions of independence in this file are a particular case of independence with respect to a kernel and a measure, as defined in the file `Kernel.lean`. We provide four definitions of independence: * `iIndepSets`: independence of a family of sets of sets `pi : ι → Set (Set Ω)`. This is meant to be used with π-systems. * `iIndep`: independence of a family of measurable space structures `m : ι → MeasurableSpace Ω`, * `iIndepSet`: independence of a family of sets `s : ι → Set Ω`, * `iIndepFun`: independence of a family of functions. For measurable spaces `m : Π (i : ι), MeasurableSpace (β i)`, we consider functions `f : Π (i : ι), Ω → β i`. Additionally, we provide four corresponding statements for two measurable space structures (resp. sets of sets, sets, functions) instead of a family. These properties are denoted by the same names as for a family, but without the starting `i`, for example `IndepFun` is the version of `iIndepFun` for two functions. The definition of independence for `iIndepSets` uses finite sets (`Finset`). See `ProbabilityTheory.Kernel.iIndepSets`. An alternative and equivalent way of defining independence would have been to use countable sets. Most of the definitions and lemmas in this file list all variables instead of using the `variable` keyword at the beginning of a section, for example `lemma Indep.symm {Ω} {m₁ m₂ : MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {μ : measure Ω} ...` . This is intentional, to be able to control the order of the `MeasurableSpace` variables. Indeed when defining `μ` in the example above, the measurable space used is the last one defined, here `{_mΩ : MeasurableSpace Ω}`, and not `m₁` or `m₂`. ## References * Williams, David. Probability with martingales. Cambridge university press, 1991. Part A, Chapter 4. -/ assert_not_exists MeasureTheory.Integrable open MeasureTheory MeasurableSpace Set open scoped MeasureTheory ENNReal namespace ProbabilityTheory variable {Ω ι β γ : Type*} {κ : ι → Type*} section Definitions /-- A family of sets of sets `π : ι → Set (Set Ω)` is independent with respect to a measure `μ` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ π i_1, ..., f i_n ∈ π i_n`, then `μ (⋂ i in s, f i) = ∏ i ∈ s, μ (f i) `. It will be used for families of pi_systems. -/ def iIndepSets {_mΩ : MeasurableSpace Ω} (π : ι → Set (Set Ω)) (μ : Measure Ω := by volume_tac) : Prop := Kernel.iIndepSets π (Kernel.const Unit μ) (Measure.dirac () : Measure Unit) /-- Two sets of sets `s₁, s₂` are independent with respect to a measure `μ` if for any sets `t₁ ∈ p₁, t₂ ∈ s₂`, then `μ (t₁ ∩ t₂) = μ (t₁) * μ (t₂)` -/ def IndepSets {_mΩ : MeasurableSpace Ω} (s1 s2 : Set (Set Ω)) (μ : Measure Ω := by volume_tac) : Prop := Kernel.IndepSets s1 s2 (Kernel.const Unit μ) (Measure.dirac () : Measure Unit) /-- A family of measurable space structures (i.e. of σ-algebras) is independent with respect to a measure `μ` (typically defined on a finer σ-algebra) if the family of sets of measurable sets they define is independent. `m : ι → MeasurableSpace Ω` is independent with respect to measure `μ` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ m i_1, ..., f i_n ∈ m i_n`, then `μ (⋂ i in s, f i) = ∏ i ∈ s, μ (f i)`. -/ def iIndep (m : ι → MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (μ : Measure Ω := by volume_tac) : Prop := Kernel.iIndep m (Kernel.const Unit μ) (Measure.dirac () : Measure Unit) /-- Two measurable space structures (or σ-algebras) `m₁, m₂` are independent with respect to a measure `μ` (defined on a third σ-algebra) if for any sets `t₁ ∈ m₁, t₂ ∈ m₂`, `μ (t₁ ∩ t₂) = μ (t₁) * μ (t₂)` -/ def Indep (m₁ m₂ : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (μ : Measure Ω := by volume_tac) : Prop := Kernel.Indep m₁ m₂ (Kernel.const Unit μ) (Measure.dirac () : Measure Unit) /-- A family of sets is independent if the family of measurable space structures they generate is independent. For a set `s`, the generated measurable space has measurable sets `∅, s, sᶜ, univ`. -/ def iIndepSet {_mΩ : MeasurableSpace Ω} (s : ι → Set Ω) (μ : Measure Ω := by volume_tac) : Prop := Kernel.iIndepSet s (Kernel.const Unit μ) (Measure.dirac () : Measure Unit) /-- Two sets are independent if the two measurable space structures they generate are independent. For a set `s`, the generated measurable space structure has measurable sets `∅, s, sᶜ, univ`. -/ def IndepSet {_mΩ : MeasurableSpace Ω} (s t : Set Ω) (μ : Measure Ω := by volume_tac) : Prop := Kernel.IndepSet s t (Kernel.const Unit μ) (Measure.dirac () : Measure Unit) /-- A family of functions defined on the same space `Ω` and taking values in possibly different spaces, each with a measurable space structure, is independent if the family of measurable space structures they generate on `Ω` is independent. For a function `g` with codomain having measurable space structure `m`, the generated measurable space structure is `MeasurableSpace.comap g m`. -/ def iIndepFun {_mΩ : MeasurableSpace Ω} {β : ι → Type*} [m : ∀ x : ι, MeasurableSpace (β x)] (f : ∀ x : ι, Ω → β x) (μ : Measure Ω := by volume_tac) : Prop := Kernel.iIndepFun f (Kernel.const Unit μ) (Measure.dirac () : Measure Unit) /-- Two functions are independent if the two measurable space structures they generate are independent. For a function `f` with codomain having measurable space structure `m`, the generated measurable space structure is `MeasurableSpace.comap f m`. -/ def IndepFun {β γ} {_mΩ : MeasurableSpace Ω} [MeasurableSpace β] [MeasurableSpace γ] (f : Ω → β) (g : Ω → γ) (μ : Measure Ω := by volume_tac) : Prop := Kernel.IndepFun f g (Kernel.const Unit μ) (Measure.dirac () : Measure Unit) end Definitions section Definition_lemmas variable {π : ι → Set (Set Ω)} {m : ι → MeasurableSpace Ω} {_ : MeasurableSpace Ω} {μ : Measure Ω} {S : Finset ι} {s : ι → Set Ω} lemma iIndepSets_iff (π : ι → Set (Set Ω)) (μ : Measure Ω) : iIndepSets π μ ↔ ∀ (s : Finset ι) {f : ι → Set Ω} (_H : ∀ i, i ∈ s → f i ∈ π i), μ (⋂ i ∈ s, f i) = ∏ i ∈ s, μ (f i) := by simp only [iIndepSets, Kernel.iIndepSets, ae_dirac_eq, Filter.eventually_pure, Kernel.const_apply] lemma iIndepSets.meas_biInter (h : iIndepSets π μ) (s : Finset ι) {f : ι → Set Ω} (hf : ∀ i, i ∈ s → f i ∈ π i) : μ (⋂ i ∈ s, f i) = ∏ i ∈ s, μ (f i) := (iIndepSets_iff _ _).1 h s hf lemma iIndepSets.isProbabilityMeasure (h : iIndepSets π μ) : IsProbabilityMeasure μ := ⟨by simpa using h ∅ (f := fun _ ↦ univ)⟩ lemma iIndepSets.meas_iInter [Fintype ι] (h : iIndepSets π μ) (hs : ∀ i, s i ∈ π i) : μ (⋂ i, s i) = ∏ i, μ (s i) := by simp [← h.meas_biInter _ fun _i _ ↦ hs _] lemma IndepSets_iff (s1 s2 : Set (Set Ω)) (μ : Measure Ω) : IndepSets s1 s2 μ ↔ ∀ t1 t2 : Set Ω, t1 ∈ s1 → t2 ∈ s2 → (μ (t1 ∩ t2) = μ t1 * μ t2) := by simp only [IndepSets, Kernel.IndepSets, ae_dirac_eq, Filter.eventually_pure, Kernel.const_apply] lemma iIndep_iff_iIndepSets (m : ι → MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (μ : Measure Ω) : iIndep m μ ↔ iIndepSets (fun x ↦ {s | MeasurableSet[m x] s}) μ := by simp only [iIndep, iIndepSets, Kernel.iIndep] lemma iIndep.iIndepSets' {m : ι → MeasurableSpace Ω} {_ : MeasurableSpace Ω} {μ : Measure Ω} (hμ : iIndep m μ) : iIndepSets (fun x ↦ {s | MeasurableSet[m x] s}) μ := (iIndep_iff_iIndepSets _ _).1 hμ lemma iIndep.isProbabilityMeasure (h : iIndep m μ) : IsProbabilityMeasure μ := h.iIndepSets'.isProbabilityMeasure lemma iIndep_iff (m : ι → MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (μ : Measure Ω) : iIndep m μ ↔ ∀ (s : Finset ι) {f : ι → Set Ω} (_H : ∀ i, i ∈ s → MeasurableSet[m i] (f i)), μ (⋂ i ∈ s, f i) = ∏ i ∈ s, μ (f i) := by simp only [iIndep_iff_iIndepSets, iIndepSets_iff]; rfl lemma iIndep.meas_biInter (hμ : iIndep m μ) (hs : ∀ i, i ∈ S → MeasurableSet[m i] (s i)) : μ (⋂ i ∈ S, s i) = ∏ i ∈ S, μ (s i) := (iIndep_iff _ _).1 hμ _ hs lemma iIndep.meas_iInter [Fintype ι] (hμ : iIndep m μ) (hs : ∀ i, MeasurableSet[m i] (s i)) : μ (⋂ i, s i) = ∏ i, μ (s i) := by simp [← hμ.meas_biInter fun _ _ ↦ hs _] lemma Indep_iff_IndepSets (m₁ m₂ : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (μ : Measure Ω) : Indep m₁ m₂ μ ↔ IndepSets {s | MeasurableSet[m₁] s} {s | MeasurableSet[m₂] s} μ := by simp only [Indep, IndepSets, Kernel.Indep] lemma Indep_iff (m₁ m₂ : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} (μ : Measure Ω) : Indep m₁ m₂ μ ↔ ∀ t1 t2, MeasurableSet[m₁] t1 → MeasurableSet[m₂] t2 → μ (t1 ∩ t2) = μ t1 * μ t2 := by rw [Indep_iff_IndepSets, IndepSets_iff]; rfl lemma iIndepSet_iff_iIndep (s : ι → Set Ω) (μ : Measure Ω) : iIndepSet s μ ↔ iIndep (fun i ↦ generateFrom {s i}) μ := by simp only [iIndepSet, iIndep, Kernel.iIndepSet] lemma iIndepSet.isProbabilityMeasure (h : iIndepSet s μ) : IsProbabilityMeasure μ := ((iIndepSet_iff_iIndep _ _).1 h).isProbabilityMeasure lemma iIndepSet_iff (s : ι → Set Ω) (μ : Measure Ω) : iIndepSet s μ ↔ ∀ (s' : Finset ι) {f : ι → Set Ω} (_H : ∀ i, i ∈ s' → MeasurableSet[generateFrom {s i}] (f i)), μ (⋂ i ∈ s', f i) = ∏ i ∈ s', μ (f i) := by simp only [iIndepSet_iff_iIndep, iIndep_iff] lemma IndepSet_iff_Indep (s t : Set Ω) (μ : Measure Ω) : IndepSet s t μ ↔ Indep (generateFrom {s}) (generateFrom {t}) μ := by simp only [IndepSet, Indep, Kernel.IndepSet] lemma IndepSet_iff (s t : Set Ω) (μ : Measure Ω) : IndepSet s t μ ↔ ∀ t1 t2, MeasurableSet[generateFrom {s}] t1 → MeasurableSet[generateFrom {t}] t2 → μ (t1 ∩ t2) = μ t1 * μ t2 := by simp only [IndepSet_iff_Indep, Indep_iff] lemma iIndepFun_iff_iIndep {β : ι → Type*} (m : ∀ x : ι, MeasurableSpace (β x)) (f : ∀ x : ι, Ω → β x) (μ : Measure Ω) : iIndepFun f μ ↔ iIndep (fun x ↦ (m x).comap (f x)) μ := by simp only [iIndepFun, iIndep, Kernel.iIndepFun] @[nontriviality, simp] lemma iIndepSets.of_subsingleton [Subsingleton ι] {m : ι → Set (Set Ω)} [IsProbabilityMeasure μ] : iIndepSets m μ := Kernel.iIndepSets.of_subsingleton @[nontriviality, simp] lemma iIndep.of_subsingleton [Subsingleton ι] {m : ι → MeasurableSpace Ω} [IsProbabilityMeasure μ] : iIndep m μ := Kernel.iIndep.of_subsingleton @[nontriviality, simp] lemma iIndepFun.of_subsingleton [Subsingleton ι] {β : ι → Type*} {m : ∀ i, MeasurableSpace (β i)} {f : ∀ i, Ω → β i} [IsProbabilityMeasure μ] : iIndepFun f μ := Kernel.iIndepFun.of_subsingleton protected lemma iIndepFun.iIndep {m : ∀ i, MeasurableSpace (κ i)} {f : ∀ x : ι, Ω → κ x} (hf : iIndepFun f μ) : iIndep (fun x ↦ (m x).comap (f x)) μ := hf lemma iIndepFun_iff {β : ι → Type*} (m : ∀ x : ι, MeasurableSpace (β x)) (f : ∀ x : ι, Ω → β x) (μ : Measure Ω) : iIndepFun f μ ↔ ∀ (s : Finset ι) {f' : ι → Set Ω} (_H : ∀ i, i ∈ s → MeasurableSet[(m i).comap (f i)] (f' i)), μ (⋂ i ∈ s, f' i) = ∏ i ∈ s, μ (f' i) := by simp only [iIndepFun_iff_iIndep, iIndep_iff] lemma iIndepFun.meas_biInter {m : ∀ i, MeasurableSpace (κ i)} {f : ∀ x : ι, Ω → κ x} (hf : iIndepFun f μ) (hs : ∀ i, i ∈ S → MeasurableSet[(m i).comap (f i)] (s i)) : μ (⋂ i ∈ S, s i) = ∏ i ∈ S, μ (s i) := hf.iIndep.meas_biInter hs lemma iIndepFun.meas_iInter [Fintype ι] {m : ∀ i, MeasurableSpace (κ i)} {f : ∀ x : ι, Ω → κ x} (hf : iIndepFun f μ) (hs : ∀ i, MeasurableSet[(m i).comap (f i)] (s i)) : μ (⋂ i, s i) = ∏ i, μ (s i) := hf.iIndep.meas_iInter hs lemma IndepFun_iff_Indep [mβ : MeasurableSpace β] [mγ : MeasurableSpace γ] (f : Ω → β) (g : Ω → γ) (μ : Measure Ω) : IndepFun f g μ ↔ Indep (MeasurableSpace.comap f mβ) (MeasurableSpace.comap g mγ) μ := by simp only [IndepFun, Indep, Kernel.IndepFun] lemma IndepFun_iff {β γ} [mβ : MeasurableSpace β] [mγ : MeasurableSpace γ] (f : Ω → β) (g : Ω → γ) (μ : Measure Ω) : IndepFun f g μ ↔ ∀ t1 t2, MeasurableSet[MeasurableSpace.comap f mβ] t1 → MeasurableSet[MeasurableSpace.comap g mγ] t2 → μ (t1 ∩ t2) = μ t1 * μ t2 := by rw [IndepFun_iff_Indep, Indep_iff] lemma IndepFun.meas_inter [mβ : MeasurableSpace β] [mγ : MeasurableSpace γ] {f : Ω → β} {g : Ω → γ} (hfg : IndepFun f g μ) {s t : Set Ω} (hs : MeasurableSet[mβ.comap f] s) (ht : MeasurableSet[mγ.comap g] t) : μ (s ∩ t) = μ s * μ t := (IndepFun_iff _ _ _).1 hfg _ _ hs ht end Definition_lemmas section Indep variable {m₁ m₂ m₃ : MeasurableSpace Ω} (m' : MeasurableSpace Ω) {_mΩ : MeasurableSpace Ω} {μ : Measure Ω} @[symm] theorem IndepSets.symm {s₁ s₂ : Set (Set Ω)} (h : IndepSets s₁ s₂ μ) : IndepSets s₂ s₁ μ := Kernel.IndepSets.symm h @[symm] theorem Indep.symm (h : Indep m₁ m₂ μ) : Indep m₂ m₁ μ := IndepSets.symm h theorem indep_bot_right [IsZeroOrProbabilityMeasure μ] : Indep m' ⊥ μ := Kernel.indep_bot_right m' theorem indep_bot_left [IsZeroOrProbabilityMeasure μ] : Indep ⊥ m' μ := (indep_bot_right m').symm theorem indepSet_empty_right [IsZeroOrProbabilityMeasure μ] (s : Set Ω) : IndepSet s ∅ μ := Kernel.indepSet_empty_right s theorem indepSet_empty_left [IsZeroOrProbabilityMeasure μ] (s : Set Ω) : IndepSet ∅ s μ := Kernel.indepSet_empty_left s theorem indepSets_of_indepSets_of_le_left {s₁ s₂ s₃ : Set (Set Ω)} (h_indep : IndepSets s₁ s₂ μ) (h31 : s₃ ⊆ s₁) : IndepSets s₃ s₂ μ := Kernel.indepSets_of_indepSets_of_le_left h_indep h31 theorem indepSets_of_indepSets_of_le_right {s₁ s₂ s₃ : Set (Set Ω)} (h_indep : IndepSets s₁ s₂ μ) (h32 : s₃ ⊆ s₂) : IndepSets s₁ s₃ μ := Kernel.indepSets_of_indepSets_of_le_right h_indep h32 theorem indep_of_indep_of_le_left (h_indep : Indep m₁ m₂ μ) (h31 : m₃ ≤ m₁) : Indep m₃ m₂ μ := Kernel.indep_of_indep_of_le_left h_indep h31 theorem indep_of_indep_of_le_right (h_indep : Indep m₁ m₂ μ) (h32 : m₃ ≤ m₂) : Indep m₁ m₃ μ := Kernel.indep_of_indep_of_le_right h_indep h32 theorem IndepSets.union {s₁ s₂ s' : Set (Set Ω)} (h₁ : IndepSets s₁ s' μ) (h₂ : IndepSets s₂ s' μ) : IndepSets (s₁ ∪ s₂) s' μ := Kernel.IndepSets.union h₁ h₂ @[simp] theorem IndepSets.union_iff {s₁ s₂ s' : Set (Set Ω)} : IndepSets (s₁ ∪ s₂) s' μ ↔ IndepSets s₁ s' μ ∧ IndepSets s₂ s' μ := Kernel.IndepSets.union_iff theorem IndepSets.iUnion {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} (hyp : ∀ n, IndepSets (s n) s' μ) : IndepSets (⋃ n, s n) s' μ := Kernel.IndepSets.iUnion hyp theorem IndepSets.bUnion {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {u : Set ι} (hyp : ∀ n ∈ u, IndepSets (s n) s' μ) : IndepSets (⋃ n ∈ u, s n) s' μ := Kernel.IndepSets.bUnion hyp theorem IndepSets.inter {s₁ s' : Set (Set Ω)} (s₂ : Set (Set Ω)) (h₁ : IndepSets s₁ s' μ) : IndepSets (s₁ ∩ s₂) s' μ := Kernel.IndepSets.inter s₂ h₁ theorem IndepSets.iInter {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} (h : ∃ n, IndepSets (s n) s' μ) : IndepSets (⋂ n, s n) s' μ := Kernel.IndepSets.iInter h theorem IndepSets.bInter {s : ι → Set (Set Ω)} {s' : Set (Set Ω)} {u : Set ι} (h : ∃ n ∈ u, IndepSets (s n) s' μ) : IndepSets (⋂ n ∈ u, s n) s' μ := Kernel.IndepSets.bInter h theorem indepSets_singleton_iff {s t : Set Ω} : IndepSets {s} {t} μ ↔ μ (s ∩ t) = μ s * μ t := by simp only [IndepSets, Kernel.indepSets_singleton_iff, ae_dirac_eq, Filter.eventually_pure, Kernel.const_apply] end Indep /-! ### Deducing `Indep` from `iIndep` -/ section FromIndepToIndep variable {m : ι → MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {μ : Measure Ω} theorem iIndepSets.indepSets {s : ι → Set (Set Ω)} (h_indep : iIndepSets s μ) {i j : ι} (hij : i ≠ j) : IndepSets (s i) (s j) μ := Kernel.iIndepSets.indepSets h_indep hij theorem iIndep.indep (h_indep : iIndep m μ) {i j : ι} (hij : i ≠ j) : Indep (m i) (m j) μ := Kernel.iIndep.indep h_indep hij theorem iIndepFun.indepFun {β : ι → Type*} {m : ∀ x, MeasurableSpace (β x)} {f : ∀ i, Ω → β i} (hf_Indep : iIndepFun f μ) {i j : ι} (hij : i ≠ j) : IndepFun (f i) (f j) μ := Kernel.iIndepFun.indepFun hf_Indep hij end FromIndepToIndep /-! ## π-system lemma Independence of measurable spaces is equivalent to independence of generating π-systems. -/ section FromMeasurableSpacesToSetsOfSets variable {m : ι → MeasurableSpace Ω} {_mΩ : MeasurableSpace Ω} {μ : Measure Ω} /-! ### Independence of measurable space structures implies independence of generating π-systems -/ theorem iIndep.iIndepSets {s : ι → Set (Set Ω)} (hms : ∀ n, m n = generateFrom (s n)) (h_indep : iIndep m μ) : iIndepSets s μ := Kernel.iIndep.iIndepSets hms h_indep theorem Indep.indepSets {s1 s2 : Set (Set Ω)} (h_indep : Indep (generateFrom s1) (generateFrom s2) μ) : IndepSets s1 s2 μ := Kernel.Indep.indepSets h_indep end FromMeasurableSpacesToSetsOfSets section FromPiSystemsToMeasurableSpaces variable {m : ι → MeasurableSpace Ω} {m1 m2 _mΩ : MeasurableSpace Ω} {μ : Measure Ω} /-! ### Independence of generating π-systems implies independence of measurable space structures -/ theorem IndepSets.indep [IsZeroOrProbabilityMeasure μ] {p1 p2 : Set (Set Ω)} (h1 : m1 ≤ _mΩ) (h2 : m2 ≤ _mΩ) (hp1 : IsPiSystem p1) (hp2 : IsPiSystem p2) (hpm1 : m1 = generateFrom p1) (hpm2 : m2 = generateFrom p2) (hyp : IndepSets p1 p2 μ) : Indep m1 m2 μ := Kernel.IndepSets.indep h1 h2 hp1 hp2 hpm1 hpm2 hyp theorem IndepSets.indep' [IsZeroOrProbabilityMeasure μ] {p1 p2 : Set (Set Ω)} (hp1m : ∀ s ∈ p1, MeasurableSet s) (hp2m : ∀ s ∈ p2, MeasurableSet s) (hp1 : IsPiSystem p1) (hp2 : IsPiSystem p2) (hyp : IndepSets p1 p2 μ) : Indep (generateFrom p1) (generateFrom p2) μ := Kernel.IndepSets.indep' hp1m hp2m hp1 hp2 hyp theorem indepSets_piiUnionInter_of_disjoint {s : ι → Set (Set Ω)} {S T : Set ι} (h_indep : iIndepSets s μ) (hST : Disjoint S T) : IndepSets (piiUnionInter s S) (piiUnionInter s T) μ := Kernel.indepSets_piiUnionInter_of_disjoint h_indep hST theorem iIndepSet.indep_generateFrom_of_disjoint {s : ι → Set Ω} (hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s μ) (S T : Set ι) (hST : Disjoint S T) : Indep (generateFrom { t | ∃ n ∈ S, s n = t }) (generateFrom { t | ∃ k ∈ T, s k = t }) μ := Kernel.iIndepSet.indep_generateFrom_of_disjoint hsm hs S T hST theorem indep_iSup_of_disjoint (h_le : ∀ i, m i ≤ _mΩ) (h_indep : iIndep m μ) {S T : Set ι} (hST : Disjoint S T) : Indep (⨆ i ∈ S, m i) (⨆ i ∈ T, m i) μ := Kernel.indep_iSup_of_disjoint h_le h_indep hST theorem indep_iSup_of_directed_le [IsZeroOrProbabilityMeasure μ] (h_indep : ∀ i, Indep (m i) m1 μ) (h_le : ∀ i, m i ≤ _mΩ) (h_le' : m1 ≤ _mΩ) (hm : Directed (· ≤ ·) m) : Indep (⨆ i, m i) m1 μ := Kernel.indep_iSup_of_directed_le h_indep h_le h_le' hm theorem iIndepSet.indep_generateFrom_lt [Preorder ι] {s : ι → Set Ω} (hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s μ) (i : ι) : Indep (generateFrom {s i}) (generateFrom { t | ∃ j < i, s j = t }) μ := Kernel.iIndepSet.indep_generateFrom_lt hsm hs i theorem iIndepSet.indep_generateFrom_le [Preorder ι] {s : ι → Set Ω} (hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s μ) (i : ι) {k : ι} (hk : i < k) : Indep (generateFrom {s k}) (generateFrom { t | ∃ j ≤ i, s j = t }) μ := Kernel.iIndepSet.indep_generateFrom_le hsm hs i hk theorem iIndepSet.indep_generateFrom_le_nat {s : ℕ → Set Ω} (hsm : ∀ n, MeasurableSet (s n)) (hs : iIndepSet s μ) (n : ℕ) : Indep (generateFrom {s (n + 1)}) (generateFrom { t | ∃ k ≤ n, s k = t }) μ := Kernel.iIndepSet.indep_generateFrom_le_nat hsm hs n theorem indep_iSup_of_monotone [SemilatticeSup ι] [IsZeroOrProbabilityMeasure μ] (h_indep : ∀ i, Indep (m i) m1 μ) (h_le : ∀ i, m i ≤ _mΩ) (h_le' : m1 ≤ _mΩ) (hm : Monotone m) : Indep (⨆ i, m i) m1 μ := Kernel.indep_iSup_of_monotone h_indep h_le h_le' hm theorem indep_iSup_of_antitone [SemilatticeInf ι] [IsZeroOrProbabilityMeasure μ] (h_indep : ∀ i, Indep (m i) m1 μ) (h_le : ∀ i, m i ≤ _mΩ) (h_le' : m1 ≤ _mΩ) (hm : Antitone m) : Indep (⨆ i, m i) m1 μ := Kernel.indep_iSup_of_antitone h_indep h_le h_le' hm theorem iIndepSets.piiUnionInter_of_not_mem {π : ι → Set (Set Ω)} {a : ι} {S : Finset ι} (hp_ind : iIndepSets π μ) (haS : a ∉ S) : IndepSets (piiUnionInter π S) (π a) μ := Kernel.iIndepSets.piiUnionInter_of_not_mem hp_ind haS /-- The measurable space structures generated by independent pi-systems are independent. -/ theorem iIndepSets.iIndep (h_le : ∀ i, m i ≤ _mΩ) (π : ι → Set (Set Ω)) (h_pi : ∀ n, IsPiSystem (π n)) (h_generate : ∀ i, m i = generateFrom (π i)) (h_ind : iIndepSets π μ) : iIndep m μ := Kernel.iIndepSets.iIndep m h_le π h_pi h_generate h_ind end FromPiSystemsToMeasurableSpaces section IndepSet /-! ### Independence of measurable sets We prove the following equivalences on `IndepSet`, for measurable sets `s, t`. * `IndepSet s t μ ↔ μ (s ∩ t) = μ s * μ t`, * `IndepSet s t μ ↔ IndepSets {s} {t} μ`. -/ variable {m₁ m₂ _mΩ : MeasurableSpace Ω} {μ : Measure Ω} {s t : Set Ω} (S T : Set (Set Ω)) theorem indepSet_iff_indepSets_singleton (hs_meas : MeasurableSet s) (ht_meas : MeasurableSet t) (μ : Measure Ω := by volume_tac) [IsZeroOrProbabilityMeasure μ] : IndepSet s t μ ↔ IndepSets {s} {t} μ := Kernel.indepSet_iff_indepSets_singleton hs_meas ht_meas _ _ theorem indepSet_iff_measure_inter_eq_mul (hs_meas : MeasurableSet s) (ht_meas : MeasurableSet t) (μ : Measure Ω := by volume_tac) [IsZeroOrProbabilityMeasure μ] : IndepSet s t μ ↔ μ (s ∩ t) = μ s * μ t := (indepSet_iff_indepSets_singleton hs_meas ht_meas μ).trans indepSets_singleton_iff lemma IndepSet.measure_inter_eq_mul {μ : Measure Ω} (h : IndepSet s t μ) : μ (s ∩ t) = μ s * μ t := by simpa using Kernel.IndepSet.measure_inter_eq_mul _ _ h theorem IndepSets.indepSet_of_mem (hs : s ∈ S) (ht : t ∈ T) (hs_meas : MeasurableSet s) (ht_meas : MeasurableSet t) (μ : Measure Ω := by volume_tac) [IsZeroOrProbabilityMeasure μ] (h_indep : IndepSets S T μ) : IndepSet s t μ := Kernel.IndepSets.indepSet_of_mem _ _ hs ht hs_meas ht_meas _ _ h_indep theorem Indep.indepSet_of_measurableSet (h_indep : Indep m₁ m₂ μ) {s t : Set Ω} (hs : MeasurableSet[m₁] s) (ht : MeasurableSet[m₂] t) : IndepSet s t μ := Kernel.Indep.indepSet_of_measurableSet h_indep hs ht theorem indep_iff_forall_indepSet (μ : Measure Ω) : Indep m₁ m₂ μ ↔ ∀ s t, MeasurableSet[m₁] s → MeasurableSet[m₂] t → IndepSet s t μ := Kernel.indep_iff_forall_indepSet m₁ m₂ _ _ theorem iIndep_comap_mem_iff {f : ι → Set Ω} : iIndep (fun i => MeasurableSpace.comap (· ∈ f i) ⊤) μ ↔ iIndepSet f μ := Kernel.iIndep_comap_mem_iff alias ⟨_, iIndepSet.iIndep_comap_mem⟩ := iIndep_comap_mem_iff theorem iIndepSets_singleton_iff {s : ι → Set Ω} : iIndepSets (fun i ↦ {s i}) μ ↔ ∀ t, μ (⋂ i ∈ t, s i) = ∏ i ∈ t, μ (s i) := by simp_rw [iIndepSets, Kernel.iIndepSets_singleton_iff, ae_dirac_eq, Filter.eventually_pure, Kernel.const_apply] theorem iIndepSet.meas_biInter {f : ι → Set Ω} (h : iIndepSet f μ) (s : Finset ι) : μ (⋂ i ∈ s, f i) = ∏ i ∈ s, μ (f i) := by simpa using Kernel.iIndepSet.meas_biInter h s theorem iIndepSet_iff_iIndepSets_singleton {f : ι → Set Ω} (hf : ∀ i, MeasurableSet (f i)) : iIndepSet f μ ↔ iIndepSets (fun i ↦ {f i}) μ := Kernel.iIndepSet_iff_iIndepSets_singleton hf theorem iIndepSet_iff_meas_biInter {f : ι → Set Ω} (hf : ∀ i, MeasurableSet (f i)) : iIndepSet f μ ↔ ∀ s, μ (⋂ i ∈ s, f i) = ∏ i ∈ s, μ (f i) := by simp_rw [iIndepSet, Kernel.iIndepSet_iff_meas_biInter hf, ae_dirac_eq, Filter.eventually_pure, Kernel.const_apply] theorem iIndepSets.iIndepSet_of_mem {π : ι → Set (Set Ω)} {f : ι → Set Ω} (hfπ : ∀ i, f i ∈ π i) (hf : ∀ i, MeasurableSet (f i)) (hπ : iIndepSets π μ) : iIndepSet f μ := Kernel.iIndepSets.iIndepSet_of_mem hfπ hf hπ end IndepSet section IndepFun /-! ### Independence of random variables -/ variable {β β' γ γ' : Type*} {_mΩ : MeasurableSpace Ω} {μ : Measure Ω} {f : Ω → β} {g : Ω → β'} theorem indepFun_iff_measure_inter_preimage_eq_mul {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'} : IndepFun f g μ ↔ ∀ s t, MeasurableSet s → MeasurableSet t → μ (f ⁻¹' s ∩ g ⁻¹' t) = μ (f ⁻¹' s) * μ (g ⁻¹' t) := by simp only [IndepFun, Kernel.indepFun_iff_measure_inter_preimage_eq_mul, ae_dirac_eq, Filter.eventually_pure, Kernel.const_apply] alias ⟨IndepFun.measure_inter_preimage_eq_mul, _⟩ := indepFun_iff_measure_inter_preimage_eq_mul theorem iIndepFun_iff_measure_inter_preimage_eq_mul {ι : Type*} {β : ι → Type*} {m : ∀ x, MeasurableSpace (β x)} {f : ∀ i, Ω → β i} : iIndepFun f μ ↔ ∀ (S : Finset ι) {sets : ∀ i : ι, Set (β i)} (_H : ∀ i, i ∈ S → MeasurableSet[m i] (sets i)), μ (⋂ i ∈ S, f i ⁻¹' sets i) = ∏ i ∈ S, μ (f i ⁻¹' sets i) := by simp only [iIndepFun, Kernel.iIndepFun_iff_measure_inter_preimage_eq_mul, ae_dirac_eq, Filter.eventually_pure, Kernel.const_apply] alias ⟨iIndepFun.measure_inter_preimage_eq_mul, _⟩ := iIndepFun_iff_measure_inter_preimage_eq_mul theorem iIndepFun.congr {β : ι → Type*} {mβ : ∀ i, MeasurableSpace (β i)} {f g : Π i, Ω → β i} (hf : iIndepFun f μ) (h : ∀ i, f i =ᵐ[μ] g i) : iIndepFun g μ := Kernel.iIndepFun.congr' hf (by simp [h]) nonrec lemma iIndepFun.comp {β γ : ι → Type*} {mβ : ∀ i, MeasurableSpace (β i)} {mγ : ∀ i, MeasurableSpace (γ i)} {f : ∀ i, Ω → β i} (h : iIndepFun f μ) (g : ∀ i, β i → γ i) (hg : ∀ i, Measurable (g i)) : iIndepFun (fun i ↦ g i ∘ f i) μ := h.comp _ hg nonrec lemma iIndepFun.comp₀ {β γ : ι → Type*} {mβ : ∀ i, MeasurableSpace (β i)} {mγ : ∀ i, MeasurableSpace (γ i)} {f : ∀ i, Ω → β i} (h : iIndepFun f μ) (g : ∀ i, β i → γ i) (hf : ∀ i, AEMeasurable (f i) μ) (hg : ∀ i, AEMeasurable (g i) (μ.map (f i))) : iIndepFun (fun i ↦ g i ∘ f i) μ := h.comp₀ _ (by simp [hf]) (by simp [hg]) theorem indepFun_iff_indepSet_preimage {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'} [IsZeroOrProbabilityMeasure μ] (hf : Measurable f) (hg : Measurable g) : IndepFun f g μ ↔ ∀ s t, MeasurableSet s → MeasurableSet t → IndepSet (f ⁻¹' s) (g ⁻¹' t) μ := by simp only [IndepFun, IndepSet, Kernel.indepFun_iff_indepSet_preimage hf hg, ae_dirac_eq, Filter.eventually_pure, Kernel.const_apply] theorem indepFun_iff_map_prod_eq_prod_map_map {mβ : MeasurableSpace β} {mβ' : MeasurableSpace β'} [IsFiniteMeasure μ] (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : IndepFun f g μ ↔ μ.map (fun ω ↦ (f ω, g ω)) = (μ.map f).prod (μ.map g) := by rw [indepFun_iff_measure_inter_preimage_eq_mul] have h₀ {s : Set β} {t : Set β'} (hs : MeasurableSet s) (ht : MeasurableSet t) : μ (f ⁻¹' s) * μ (g ⁻¹' t) = μ.map f s * μ.map g t ∧ μ (f ⁻¹' s ∩ g ⁻¹' t) = μ.map (fun ω ↦ (f ω, g ω)) (s ×ˢ t) := ⟨by rw [Measure.map_apply_of_aemeasurable hf hs, Measure.map_apply_of_aemeasurable hg ht], (Measure.map_apply_of_aemeasurable (hf.prodMk hg) (hs.prod ht)).symm⟩ constructor · refine fun h ↦ (Measure.prod_eq fun s t hs ht ↦ ?_).symm rw [← (h₀ hs ht).1, ← (h₀ hs ht).2, h s t hs ht] · intro h s t hs ht
rw [(h₀ hs ht).1, (h₀ hs ht).2, h, Measure.prod_prod] theorem iIndepFun_iff_map_fun_eq_pi_map [Fintype ι] {β : ι → Type*} {m : ∀ i, MeasurableSpace (β i)} {f : Π i, Ω → β i} [IsProbabilityMeasure μ] (hf : ∀ i, AEMeasurable (f i) μ) : iIndepFun f μ ↔ μ.map (fun ω i ↦ f i ω) = Measure.pi (fun i ↦ μ.map (f i)) := by classical
Mathlib/Probability/Independence/Basic.lean
616
622
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.FDeriv.Equiv /-! # Inverse function theorem - the easy half In this file we prove that `g' (f x) = (f' x)⁻¹` provided that `f` is strictly differentiable at `x`, `f' x ≠ 0`, and `g` is a local left inverse of `f` that is continuous at `f x`. This is the easy half of the inverse function theorem: the harder half states that `g` exists. For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of `Analysis/Calculus/Deriv/Basic`. ## Keywords derivative, inverse function -/ universe u v open scoped Topology open Filter Set variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {f : 𝕜 → F} variable {f' : F} variable {s : Set 𝕜} {x : 𝕜} {c : F} theorem HasStrictDerivAt.hasStrictFDerivAt_equiv {f : 𝕜 → 𝕜} {f' x : 𝕜} (hf : HasStrictDerivAt f f' x) (hf' : f' ≠ 0) : HasStrictFDerivAt f (ContinuousLinearEquiv.unitsEquivAut 𝕜 (Units.mk0 f' hf') : 𝕜 →L[𝕜] 𝕜) x := hf theorem HasDerivAt.hasFDerivAt_equiv {f : 𝕜 → 𝕜} {f' x : 𝕜} (hf : HasDerivAt f f' x) (hf' : f' ≠ 0) : HasFDerivAt f (ContinuousLinearEquiv.unitsEquivAut 𝕜 (Units.mk0 f' hf') : 𝕜 →L[𝕜] 𝕜) x := hf /-- If `f (g y) = y` for `y` in some neighborhood of `a`, `g` is continuous at `a`, and `f` has an invertible derivative `f'` at `g a` in the strict sense, then `g` has the derivative `f'⁻¹` at `a` in the strict sense. This is one of the easy parts of the inverse function theorem: it assumes that we already have an inverse function. -/ theorem HasStrictDerivAt.of_local_left_inverse {f g : 𝕜 → 𝕜} {f' a : 𝕜} (hg : ContinuousAt g a) (hf : HasStrictDerivAt f f' (g a)) (hf' : f' ≠ 0) (hfg : ∀ᶠ y in 𝓝 a, f (g y) = y) : HasStrictDerivAt g f'⁻¹ a := (hf.hasStrictFDerivAt_equiv hf').of_local_left_inverse hg hfg /-- If `f` is a partial homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has a nonzero derivative `f'` at `f.symm a` in the strict sense, then `f.symm` has the derivative `f'⁻¹` at `a` in the strict sense. This is one of the easy parts of the inverse function theorem: it assumes that we already have an inverse function. -/ theorem PartialHomeomorph.hasStrictDerivAt_symm (f : PartialHomeomorph 𝕜 𝕜) {a f' : 𝕜} (ha : a ∈ f.target) (hf' : f' ≠ 0) (htff' : HasStrictDerivAt f f' (f.symm a)) : HasStrictDerivAt f.symm f'⁻¹ a := htff'.of_local_left_inverse (f.symm.continuousAt ha) hf' (f.eventually_right_inverse ha) /-- If `f (g y) = y` for `y` in some neighborhood of `a`, `g` is continuous at `a`, and `f` has an invertible derivative `f'` at `g a`, then `g` has the derivative `f'⁻¹` at `a`. This is one of the easy parts of the inverse function theorem: it assumes that we already have an inverse function. -/ theorem HasDerivAt.of_local_left_inverse {f g : 𝕜 → 𝕜} {f' a : 𝕜} (hg : ContinuousAt g a) (hf : HasDerivAt f f' (g a)) (hf' : f' ≠ 0) (hfg : ∀ᶠ y in 𝓝 a, f (g y) = y) : HasDerivAt g f'⁻¹ a := (hf.hasFDerivAt_equiv hf').of_local_left_inverse hg hfg /-- If `f` is a partial homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has a nonzero derivative `f'` at `f.symm a`, then `f.symm` has the derivative `f'⁻¹` at `a`. This is one of the easy parts of the inverse function theorem: it assumes that we already have an inverse function. -/ theorem PartialHomeomorph.hasDerivAt_symm (f : PartialHomeomorph 𝕜 𝕜) {a f' : 𝕜} (ha : a ∈ f.target) (hf' : f' ≠ 0) (htff' : HasDerivAt f f' (f.symm a)) : HasDerivAt f.symm f'⁻¹ a := htff'.of_local_left_inverse (f.symm.continuousAt ha) hf' (f.eventually_right_inverse ha) theorem HasDerivWithinAt.eventually_ne (h : HasDerivWithinAt f f' s x) (hf' : f' ≠ 0) : ∀ᶠ z in 𝓝[s \ {x}] x, f z ≠ c := h.hasFDerivWithinAt.eventually_ne ⟨‖f'‖⁻¹, fun z => by field_simp [norm_smul, mt norm_eq_zero.1 hf']⟩ theorem HasDerivAt.eventually_ne (h : HasDerivAt f f' x) (hf' : f' ≠ 0) : ∀ᶠ z in 𝓝[≠] x, f z ≠ c := by simpa only [compl_eq_univ_diff] using (hasDerivWithinAt_univ.2 h).eventually_ne hf' theorem HasDerivAt.tendsto_nhdsNE (h : HasDerivAt f f' x) (hf' : f' ≠ 0) : Tendsto f (𝓝[≠] x) (𝓝[≠] f x) := tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ h.continuousAt.continuousWithinAt (h.eventually_ne hf') @[deprecated (since := "2025-03-02")] alias HasDerivAt.tendsto_punctured_nhds := HasDerivAt.tendsto_nhdsNE /-- If a function is equal to a constant at a set of points that accumulates to `x` in `s`, then its derivative within `s` at `x` equals zero, either because it has derivative zero or because it isn't differentiable at this point. -/ theorem derivWithin_zero_of_frequently_const {c} (h : ∃ᶠ y in 𝓝[s \ {x}] x, f y = c) : derivWithin f s x = 0 := by by_cases hf : DifferentiableWithinAt 𝕜 f s x · contrapose h rw [not_frequently]
exact hf.hasDerivWithinAt.eventually_ne h · exact derivWithin_zero_of_not_differentiableWithinAt hf /-- If a function is equal to a constant at a set of points that accumulates to `x`, then its derivative at `x` equals zero, either because it has derivative zero or because it isn't differentiable at this point. -/
Mathlib/Analysis/Calculus/Deriv/Inverse.lean
112
117
/- Copyright (c) 2023 Peter Nelson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Peter Nelson -/ import Mathlib.SetTheory.Cardinal.Finite import Mathlib.Data.Set.Finite.Powerset /-! # Noncomputable Set Cardinality We define the cardinality of set `s` as a term `Set.encard s : ℕ∞` and a term `Set.ncard s : ℕ`. The latter takes the junk value of zero if `s` is infinite. Both functions are noncomputable, and are defined in terms of `ENat.card` (which takes a type as its argument); this file can be seen as an API for the same function in the special case where the type is a coercion of a `Set`, allowing for smoother interactions with the `Set` API. `Set.encard` never takes junk values, so is more mathematically natural than `Set.ncard`, even though it takes values in a less convenient type. It is probably the right choice in settings where one is concerned with the cardinalities of sets that may or may not be infinite. `Set.ncard` has a nicer codomain, but when using it, `Set.Finite` hypotheses are normally needed to make sure its values are meaningful. More generally, `Set.ncard` is intended to be used over the obvious alternative `Finset.card` when finiteness is 'propositional' rather than 'structural'. When working with sets that are finite by virtue of their definition, then `Finset.card` probably makes more sense. One setting where `Set.ncard` works nicely is in a type `α` with `[Finite α]`, where every set is automatically finite. In this setting, we use default arguments and a simple tactic so that finiteness goals are discharged automatically in `Set.ncard` theorems. ## Main Definitions * `Set.encard s` is the cardinality of the set `s` as an extended natural number, with value `⊤` if `s` is infinite. * `Set.ncard s` is the cardinality of the set `s` as a natural number, provided `s` is Finite. If `s` is Infinite, then `Set.ncard s = 0`. * `toFinite_tac` is a tactic that tries to synthesize a `Set.Finite s` argument with `Set.toFinite`. This will work for `s : Set α` where there is a `Finite α` instance. ## Implementation Notes The theorems in this file are very similar to those in `Data.Finset.Card`, but with `Set` operations instead of `Finset`. We first prove all the theorems for `Set.encard`, and then derive most of the `Set.ncard` results as a consequence. Things are done this way to avoid reliance on the `Finset` API for theorems about infinite sets, and to allow for a refactor that removes or modifies `Set.ncard` in the future. Nearly all the theorems for `Set.ncard` require finiteness of one or more of their arguments. We provide this assumption with a default argument of the form `(hs : s.Finite := by toFinite_tac)`, where `toFinite_tac` will find an `s.Finite` term in the cases where `s` is a set in a `Finite` type. Often, where there are two set arguments `s` and `t`, the finiteness of one follows from the other in the context of the theorem, in which case we only include the ones that are needed, and derive the other inside the proof. A few of the theorems, such as `ncard_union_le` do not require finiteness arguments; they are true by coincidence due to junk values. -/ namespace Set variable {α β : Type*} {s t : Set α} /-- The cardinality of a set as a term in `ℕ∞` -/ noncomputable def encard (s : Set α) : ℕ∞ := ENat.card s @[simp] theorem encard_univ_coe (s : Set α) : encard (univ : Set s) = encard s := by rw [encard, encard, ENat.card_congr (Equiv.Set.univ ↑s)] theorem encard_univ (α : Type*) : encard (univ : Set α) = ENat.card α := by rw [encard, ENat.card_congr (Equiv.Set.univ α)] theorem Finite.encard_eq_coe_toFinset_card (h : s.Finite) : s.encard = h.toFinset.card := by have := h.fintype rw [encard, ENat.card_eq_coe_fintype_card, toFinite_toFinset, toFinset_card] theorem encard_eq_coe_toFinset_card (s : Set α) [Fintype s] : encard s = s.toFinset.card := by have h := toFinite s rw [h.encard_eq_coe_toFinset_card, toFinite_toFinset] @[simp] theorem toENat_cardinalMk (s : Set α) : (Cardinal.mk s).toENat = s.encard := rfl theorem toENat_cardinalMk_subtype (P : α → Prop) : (Cardinal.mk {x // P x}).toENat = {x | P x}.encard := rfl @[simp] theorem coe_fintypeCard (s : Set α) [Fintype s] : Fintype.card s = s.encard := by simp [encard_eq_coe_toFinset_card] @[simp, norm_cast] theorem encard_coe_eq_coe_finsetCard (s : Finset α) : encard (s : Set α) = s.card := by rw [Finite.encard_eq_coe_toFinset_card (Finset.finite_toSet s)]; simp @[simp] theorem Infinite.encard_eq {s : Set α} (h : s.Infinite) : s.encard = ⊤ := by have := h.to_subtype rw [encard, ENat.card_eq_top_of_infinite] @[simp] theorem encard_eq_zero : s.encard = 0 ↔ s = ∅ := by rw [encard, ENat.card_eq_zero_iff_empty, isEmpty_subtype, eq_empty_iff_forall_not_mem] @[simp] theorem encard_empty : (∅ : Set α).encard = 0 := by rw [encard_eq_zero] theorem nonempty_of_encard_ne_zero (h : s.encard ≠ 0) : s.Nonempty := by rwa [nonempty_iff_ne_empty, Ne, ← encard_eq_zero] theorem encard_ne_zero : s.encard ≠ 0 ↔ s.Nonempty := by rw [ne_eq, encard_eq_zero, nonempty_iff_ne_empty] @[simp] theorem encard_pos : 0 < s.encard ↔ s.Nonempty := by rw [pos_iff_ne_zero, encard_ne_zero] protected alias ⟨_, Nonempty.encard_pos⟩ := encard_pos @[simp] theorem encard_singleton (e : α) : ({e} : Set α).encard = 1 := by rw [encard, ENat.card_eq_coe_fintype_card, Fintype.card_ofSubsingleton, Nat.cast_one] theorem encard_union_eq (h : Disjoint s t) : (s ∪ t).encard = s.encard + t.encard := by classical simp [encard, ENat.card_congr (Equiv.Set.union h)] theorem encard_insert_of_not_mem {a : α} (has : a ∉ s) : (insert a s).encard = s.encard + 1 := by rw [← union_singleton, encard_union_eq (by simpa), encard_singleton] theorem Finite.encard_lt_top (h : s.Finite) : s.encard < ⊤ := by induction s, h using Set.Finite.induction_on with | empty => simp | insert hat _ ht' => rw [encard_insert_of_not_mem hat] exact lt_tsub_iff_right.1 ht' theorem Finite.encard_eq_coe (h : s.Finite) : s.encard = ENat.toNat s.encard := (ENat.coe_toNat h.encard_lt_top.ne).symm theorem Finite.exists_encard_eq_coe (h : s.Finite) : ∃ (n : ℕ), s.encard = n := ⟨_, h.encard_eq_coe⟩ @[simp] theorem encard_lt_top_iff : s.encard < ⊤ ↔ s.Finite := ⟨fun h ↦ by_contra fun h' ↦ h.ne (Infinite.encard_eq h'), Finite.encard_lt_top⟩ @[simp] theorem encard_eq_top_iff : s.encard = ⊤ ↔ s.Infinite := by rw [← not_iff_not, ← Ne, ← lt_top_iff_ne_top, encard_lt_top_iff, not_infinite] alias ⟨_, encard_eq_top⟩ := encard_eq_top_iff theorem encard_ne_top_iff : s.encard ≠ ⊤ ↔ s.Finite := by simp theorem finite_of_encard_le_coe {k : ℕ} (h : s.encard ≤ k) : s.Finite := by rw [← encard_lt_top_iff]; exact h.trans_lt (WithTop.coe_lt_top _) theorem finite_of_encard_eq_coe {k : ℕ} (h : s.encard = k) : s.Finite := finite_of_encard_le_coe h.le theorem encard_le_coe_iff {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ ∃ (n₀ : ℕ), s.encard = n₀ ∧ n₀ ≤ k := ⟨fun h ↦ ⟨finite_of_encard_le_coe h, by rwa [ENat.le_coe_iff] at h⟩, fun ⟨_,⟨n₀,hs, hle⟩⟩ ↦ by rwa [hs, Nat.cast_le]⟩ @[simp] theorem encard_prod : (s ×ˢ t).encard = s.encard * t.encard := by simp [Set.encard, ENat.card_congr (Equiv.Set.prod ..)] section Lattice theorem encard_le_encard (h : s ⊆ t) : s.encard ≤ t.encard := by rw [← union_diff_cancel h, encard_union_eq disjoint_sdiff_right]; exact le_self_add @[deprecated (since := "2025-01-05")] alias encard_le_card := encard_le_encard theorem encard_mono {α : Type*} : Monotone (encard : Set α → ℕ∞) := fun _ _ ↦ encard_le_encard theorem encard_diff_add_encard_of_subset (h : s ⊆ t) : (t \ s).encard + s.encard = t.encard := by rw [← encard_union_eq disjoint_sdiff_left, diff_union_self, union_eq_self_of_subset_right h] @[simp] theorem one_le_encard_iff_nonempty : 1 ≤ s.encard ↔ s.Nonempty := by rw [nonempty_iff_ne_empty, Ne, ← encard_eq_zero, ENat.one_le_iff_ne_zero] theorem encard_diff_add_encard_inter (s t : Set α) : (s \ t).encard + (s ∩ t).encard = s.encard := by rw [← encard_union_eq (disjoint_of_subset_right inter_subset_right disjoint_sdiff_left), diff_union_inter] theorem encard_union_add_encard_inter (s t : Set α) : (s ∪ t).encard + (s ∩ t).encard = s.encard + t.encard := by rw [← diff_union_self, encard_union_eq disjoint_sdiff_left, add_right_comm, encard_diff_add_encard_inter] theorem encard_eq_encard_iff_encard_diff_eq_encard_diff (h : (s ∩ t).Finite) : s.encard = t.encard ↔ (s \ t).encard = (t \ s).encard := by rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s, WithTop.add_right_inj h.encard_lt_top.ne] theorem encard_le_encard_iff_encard_diff_le_encard_diff (h : (s ∩ t).Finite) : s.encard ≤ t.encard ↔ (s \ t).encard ≤ (t \ s).encard := by rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s, WithTop.add_le_add_iff_right h.encard_lt_top.ne] theorem encard_lt_encard_iff_encard_diff_lt_encard_diff (h : (s ∩ t).Finite) : s.encard < t.encard ↔ (s \ t).encard < (t \ s).encard := by rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s, WithTop.add_lt_add_iff_right h.encard_lt_top.ne] theorem encard_union_le (s t : Set α) : (s ∪ t).encard ≤ s.encard + t.encard := by rw [← encard_union_add_encard_inter]; exact le_self_add theorem finite_iff_finite_of_encard_eq_encard (h : s.encard = t.encard) : s.Finite ↔ t.Finite := by rw [← encard_lt_top_iff, ← encard_lt_top_iff, h] theorem infinite_iff_infinite_of_encard_eq_encard (h : s.encard = t.encard) : s.Infinite ↔ t.Infinite := by rw [← encard_eq_top_iff, h, encard_eq_top_iff] theorem Finite.finite_of_encard_le {s : Set α} {t : Set β} (hs : s.Finite) (h : t.encard ≤ s.encard) : t.Finite := encard_lt_top_iff.1 (h.trans_lt hs.encard_lt_top) lemma Finite.eq_of_subset_of_encard_le' (ht : t.Finite) (hst : s ⊆ t) (hts : t.encard ≤ s.encard) : s = t := by rw [← zero_add (a := encard s), ← encard_diff_add_encard_of_subset hst] at hts have hdiff := WithTop.le_of_add_le_add_right (ht.subset hst).encard_lt_top.ne hts rw [nonpos_iff_eq_zero, encard_eq_zero, diff_eq_empty] at hdiff exact hst.antisymm hdiff theorem Finite.eq_of_subset_of_encard_le (hs : s.Finite) (hst : s ⊆ t) (hts : t.encard ≤ s.encard) : s = t := (hs.finite_of_encard_le hts).eq_of_subset_of_encard_le' hst hts theorem Finite.encard_lt_encard (hs : s.Finite) (h : s ⊂ t) : s.encard < t.encard := (encard_mono h.subset).lt_of_ne fun he ↦ h.ne (hs.eq_of_subset_of_encard_le h.subset he.symm.le) theorem encard_strictMono [Finite α] : StrictMono (encard : Set α → ℕ∞) := fun _ _ h ↦ (toFinite _).encard_lt_encard h theorem encard_diff_add_encard (s t : Set α) : (s \ t).encard + t.encard = (s ∪ t).encard := by rw [← encard_union_eq disjoint_sdiff_left, diff_union_self] theorem encard_le_encard_diff_add_encard (s t : Set α) : s.encard ≤ (s \ t).encard + t.encard := (encard_mono subset_union_left).trans_eq (encard_diff_add_encard _ _).symm theorem tsub_encard_le_encard_diff (s t : Set α) : s.encard - t.encard ≤ (s \ t).encard := by rw [tsub_le_iff_left, add_comm]; apply encard_le_encard_diff_add_encard theorem encard_add_encard_compl (s : Set α) : s.encard + sᶜ.encard = (univ : Set α).encard := by rw [← encard_union_eq disjoint_compl_right, union_compl_self] end Lattice section InsertErase variable {a b : α} theorem encard_insert_le (s : Set α) (x : α) : (insert x s).encard ≤ s.encard + 1 := by rw [← union_singleton, ← encard_singleton x]; apply encard_union_le theorem encard_singleton_inter (s : Set α) (x : α) : ({x} ∩ s).encard ≤ 1 := by rw [← encard_singleton x]; exact encard_le_encard inter_subset_left theorem encard_diff_singleton_add_one (h : a ∈ s) : (s \ {a}).encard + 1 = s.encard := by rw [← encard_insert_of_not_mem (fun h ↦ h.2 rfl), insert_diff_singleton, insert_eq_of_mem h] theorem encard_diff_singleton_of_mem (h : a ∈ s) : (s \ {a}).encard = s.encard - 1 := by rw [← encard_diff_singleton_add_one h, ← WithTop.add_right_inj WithTop.one_ne_top, tsub_add_cancel_of_le (self_le_add_left _ _)] theorem encard_tsub_one_le_encard_diff_singleton (s : Set α) (x : α) : s.encard - 1 ≤ (s \ {x}).encard := by rw [← encard_singleton x]; apply tsub_encard_le_encard_diff theorem encard_exchange (ha : a ∉ s) (hb : b ∈ s) : (insert a (s \ {b})).encard = s.encard := by rw [encard_insert_of_not_mem, encard_diff_singleton_add_one hb] simp_all only [not_true, mem_diff, mem_singleton_iff, false_and, not_false_eq_true] theorem encard_exchange' (ha : a ∉ s) (hb : b ∈ s) : (insert a s \ {b}).encard = s.encard := by rw [← insert_diff_singleton_comm (by rintro rfl; exact ha hb), encard_exchange ha hb] theorem encard_eq_add_one_iff {k : ℕ∞} : s.encard = k + 1 ↔ (∃ a t, ¬a ∈ t ∧ insert a t = s ∧ t.encard = k) := by refine ⟨fun h ↦ ?_, ?_⟩ · obtain ⟨a, ha⟩ := nonempty_of_encard_ne_zero (s := s) (by simp [h]) refine ⟨a, s \ {a}, fun h ↦ h.2 rfl, by rwa [insert_diff_singleton, insert_eq_of_mem], ?_⟩ rw [← WithTop.add_right_inj WithTop.one_ne_top, ← h, encard_diff_singleton_add_one ha] rintro ⟨a, t, h, rfl, rfl⟩ rw [encard_insert_of_not_mem h] /-- Every set is either empty, infinite, or can have its `encard` reduced by a removal. Intended for well-founded induction on the value of `encard`. -/ theorem eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt (s : Set α) : s = ∅ ∨ s.encard = ⊤ ∨ ∃ a ∈ s, (s \ {a}).encard < s.encard := by refine s.eq_empty_or_nonempty.elim Or.inl (Or.inr ∘ fun ⟨a,ha⟩ ↦ (s.finite_or_infinite.elim (fun hfin ↦ Or.inr ⟨a, ha, ?_⟩) (Or.inl ∘ Infinite.encard_eq))) rw [← encard_diff_singleton_add_one ha]; nth_rw 1 [← add_zero (encard _)] exact WithTop.add_lt_add_left hfin.diff.encard_lt_top.ne zero_lt_one end InsertErase section SmallSets theorem encard_pair {x y : α} (hne : x ≠ y) : ({x, y} : Set α).encard = 2 := by rw [encard_insert_of_not_mem (by simpa), ← one_add_one_eq_two, WithTop.add_right_inj WithTop.one_ne_top, encard_singleton] theorem encard_eq_one : s.encard = 1 ↔ ∃ x, s = {x} := by refine ⟨fun h ↦ ?_, fun ⟨x, hx⟩ ↦ by rw [hx, encard_singleton]⟩ obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp) exact ⟨x, ((finite_singleton x).eq_of_subset_of_encard_le (by simpa) (by simp [h])).symm⟩ theorem encard_le_one_iff_eq : s.encard ≤ 1 ↔ s = ∅ ∨ ∃ x, s = {x} := by rw [le_iff_lt_or_eq, lt_iff_not_le, ENat.one_le_iff_ne_zero, not_not, encard_eq_zero, encard_eq_one] theorem encard_le_one_iff : s.encard ≤ 1 ↔ ∀ a b, a ∈ s → b ∈ s → a = b := by rw [encard_le_one_iff_eq, or_iff_not_imp_left, ← Ne, ← nonempty_iff_ne_empty] refine ⟨fun h a b has hbs ↦ ?_, fun h ⟨x, hx⟩ ↦ ⟨x, ((singleton_subset_iff.2 hx).antisymm' (fun y hy ↦ h _ _ hy hx))⟩⟩ obtain ⟨x, rfl⟩ := h ⟨_, has⟩ rw [(has : a = x), (hbs : b = x)] theorem encard_le_one_iff_subsingleton : s.encard ≤ 1 ↔ s.Subsingleton := by rw [encard_le_one_iff, Set.Subsingleton] tauto theorem one_lt_encard_iff_nontrivial : 1 < s.encard ↔ s.Nontrivial := by rw [← not_iff_not, not_lt, Set.not_nontrivial_iff, ← encard_le_one_iff_subsingleton] theorem one_lt_encard_iff : 1 < s.encard ↔ ∃ a b, a ∈ s ∧ b ∈ s ∧ a ≠ b := by rw [← not_iff_not, not_exists, not_lt, encard_le_one_iff]; aesop theorem exists_ne_of_one_lt_encard (h : 1 < s.encard) (a : α) : ∃ b ∈ s, b ≠ a := by by_contra! h' obtain ⟨b, b', hb, hb', hne⟩ := one_lt_encard_iff.1 h apply hne rw [h' b hb, h' b' hb'] theorem encard_eq_two : s.encard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by refine ⟨fun h ↦ ?_, fun ⟨x, y, hne, hs⟩ ↦ by rw [hs, encard_pair hne]⟩ obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp) rw [← insert_eq_of_mem hx, ← insert_diff_singleton, encard_insert_of_not_mem (fun h ↦ h.2 rfl), ← one_add_one_eq_two, WithTop.add_right_inj (WithTop.one_ne_top), encard_eq_one] at h obtain ⟨y, h⟩ := h refine ⟨x, y, by rintro rfl; exact (h.symm.subset rfl).2 rfl, ?_⟩ rw [← h, insert_diff_singleton, insert_eq_of_mem hx] theorem encard_eq_three {α : Type u_1} {s : Set α} : encard s = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z} := by refine ⟨fun h ↦ ?_, fun ⟨x, y, z, hxy, hyz, hxz, hs⟩ ↦ ?_⟩ · obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp) rw [← insert_eq_of_mem hx, ← insert_diff_singleton, encard_insert_of_not_mem (fun h ↦ h.2 rfl), (by exact rfl : (3 : ℕ∞) = 2 + 1), WithTop.add_right_inj WithTop.one_ne_top, encard_eq_two] at h obtain ⟨y, z, hne, hs⟩ := h refine ⟨x, y, z, ?_, ?_, hne, ?_⟩ · rintro rfl; exact (hs.symm.subset (Or.inl rfl)).2 rfl · rintro rfl; exact (hs.symm.subset (Or.inr rfl)).2 rfl rw [← hs, insert_diff_singleton, insert_eq_of_mem hx] rw [hs, encard_insert_of_not_mem, encard_insert_of_not_mem, encard_singleton] <;> aesop theorem Nat.encard_range (k : ℕ) : {i | i < k}.encard = k := by convert encard_coe_eq_coe_finsetCard (Finset.range k) using 1 · rw [Finset.coe_range, Iio_def] rw [Finset.card_range] end SmallSets theorem Finite.eq_insert_of_subset_of_encard_eq_succ (hs : s.Finite) (h : s ⊆ t) (hst : t.encard = s.encard + 1) : ∃ a, t = insert a s := by rw [← encard_diff_add_encard_of_subset h, add_comm, WithTop.add_left_inj hs.encard_lt_top.ne, encard_eq_one] at hst obtain ⟨x, hx⟩ := hst; use x; rw [← diff_union_of_subset h, hx, singleton_union] theorem exists_subset_encard_eq {k : ℕ∞} (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.encard = k := by revert hk refine ENat.nat_induction k (fun _ ↦ ⟨∅, empty_subset _, by simp⟩) (fun n IH hle ↦ ?_) ?_ · obtain ⟨t₀, ht₀s, ht₀⟩ := IH (le_trans (by simp) hle) simp only [Nat.cast_succ] at * have hne : t₀ ≠ s := by rintro rfl; rw [ht₀, ← Nat.cast_one, ← Nat.cast_add, Nat.cast_le] at hle; simp at hle obtain ⟨x, hx⟩ := exists_of_ssubset (ht₀s.ssubset_of_ne hne) exact ⟨insert x t₀, insert_subset hx.1 ht₀s, by rw [encard_insert_of_not_mem hx.2, ht₀]⟩ simp only [top_le_iff, encard_eq_top_iff] exact fun _ hi ↦ ⟨s, Subset.rfl, hi⟩ theorem exists_superset_subset_encard_eq {k : ℕ∞} (hst : s ⊆ t) (hsk : s.encard ≤ k) (hkt : k ≤ t.encard) : ∃ r, s ⊆ r ∧ r ⊆ t ∧ r.encard = k := by obtain (hs | hs) := eq_or_ne s.encard ⊤ · rw [hs, top_le_iff] at hsk; subst hsk; exact ⟨s, Subset.rfl, hst, hs⟩ obtain ⟨k, rfl⟩ := exists_add_of_le hsk obtain ⟨k', hk'⟩ := exists_add_of_le hkt have hk : k ≤ encard (t \ s) := by rw [← encard_diff_add_encard_of_subset hst, add_comm] at hkt exact WithTop.le_of_add_le_add_right hs hkt obtain ⟨r', hr', rfl⟩ := exists_subset_encard_eq hk refine ⟨s ∪ r', subset_union_left, union_subset hst (hr'.trans diff_subset), ?_⟩ rw [encard_union_eq (disjoint_of_subset_right hr' disjoint_sdiff_right)] section Function variable {s : Set α} {t : Set β} {f : α → β} theorem InjOn.encard_image (h : InjOn f s) : (f '' s).encard = s.encard := by rw [encard, ENat.card_image_of_injOn h, encard] theorem encard_congr (e : s ≃ t) : s.encard = t.encard := by rw [← encard_univ_coe, ← encard_univ_coe t, encard_univ, encard_univ, ENat.card_congr e] theorem _root_.Function.Injective.encard_image (hf : f.Injective) (s : Set α) : (f '' s).encard = s.encard := hf.injOn.encard_image theorem _root_.Function.Embedding.encard_le (e : s ↪ t) : s.encard ≤ t.encard := by rw [← encard_univ_coe, ← e.injective.encard_image, ← Subtype.coe_injective.encard_image] exact encard_mono (by simp) theorem encard_image_le (f : α → β) (s : Set α) : (f '' s).encard ≤ s.encard := by obtain (h | h) := isEmpty_or_nonempty α · rw [s.eq_empty_of_isEmpty]; simp rw [← (f.invFunOn_injOn_image s).encard_image] apply encard_le_encard exact f.invFunOn_image_image_subset s theorem Finite.injOn_of_encard_image_eq (hs : s.Finite) (h : (f '' s).encard = s.encard) : InjOn f s := by obtain (h' | hne) := isEmpty_or_nonempty α · rw [s.eq_empty_of_isEmpty]; simp rw [← (f.invFunOn_injOn_image s).encard_image] at h rw [injOn_iff_invFunOn_image_image_eq_self] exact hs.eq_of_subset_of_encard_le' (f.invFunOn_image_image_subset s) h.symm.le theorem encard_preimage_of_injective_subset_range (hf : f.Injective) (ht : t ⊆ range f) : (f ⁻¹' t).encard = t.encard := by rw [← hf.encard_image, image_preimage_eq_inter_range, inter_eq_self_of_subset_left ht] lemma encard_preimage_of_bijective (hf : f.Bijective) (t : Set β) : (f ⁻¹' t).encard = t.encard := encard_preimage_of_injective_subset_range hf.injective (by simp [hf.surjective.range_eq]) theorem encard_le_encard_of_injOn (hf : MapsTo f s t) (f_inj : InjOn f s) : s.encard ≤ t.encard := by rw [← f_inj.encard_image]; apply encard_le_encard; rintro _ ⟨x, hx, rfl⟩; exact hf hx theorem Finite.exists_injOn_of_encard_le [Nonempty β] {s : Set α} {t : Set β} (hs : s.Finite) (hle : s.encard ≤ t.encard) : ∃ (f : α → β), s ⊆ f ⁻¹' t ∧ InjOn f s := by classical obtain (rfl | h | ⟨a, has, -⟩) := s.eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt · simp · exact (encard_ne_top_iff.mpr hs h).elim obtain ⟨b, hbt⟩ := encard_pos.1 ((encard_pos.2 ⟨_, has⟩).trans_le hle) have hle' : (s \ {a}).encard ≤ (t \ {b}).encard := by rwa [← WithTop.add_le_add_iff_right WithTop.one_ne_top, encard_diff_singleton_add_one has, encard_diff_singleton_add_one hbt] obtain ⟨f₀, hf₀s, hinj⟩ := exists_injOn_of_encard_le hs.diff hle' simp only [preimage_diff, subset_def, mem_diff, mem_singleton_iff, mem_preimage, and_imp] at hf₀s use Function.update f₀ a b rw [← insert_eq_of_mem has, ← insert_diff_singleton, injOn_insert (fun h ↦ h.2 rfl)] simp only [mem_diff, mem_singleton_iff, not_true, and_false, insert_diff_singleton, subset_def, mem_insert_iff, mem_preimage, ne_eq, Function.update_apply, forall_eq_or_imp, ite_true, and_imp, mem_image, ite_eq_left_iff, not_exists, not_and, not_forall, exists_prop, and_iff_right hbt] refine ⟨?_, ?_, fun x hxs hxa ↦ ⟨hxa, (hf₀s x hxs hxa).2⟩⟩ · rintro x hx; split_ifs with h · assumption · exact (hf₀s x hx h).1 exact InjOn.congr hinj (fun x ⟨_, hxa⟩ ↦ by rwa [Function.update_of_ne]) termination_by encard s theorem Finite.exists_bijOn_of_encard_eq [Nonempty β] (hs : s.Finite) (h : s.encard = t.encard) : ∃ (f : α → β), BijOn f s t := by obtain ⟨f, hf, hinj⟩ := hs.exists_injOn_of_encard_le h.le; use f convert hinj.bijOn_image rw [(hs.image f).eq_of_subset_of_encard_le (image_subset_iff.mpr hf) (h.symm.trans hinj.encard_image.symm).le] end Function section ncard open Nat /-- A tactic (for use in default params) that applies `Set.toFinite` to synthesize a `Set.Finite` term. -/ syntax "toFinite_tac" : tactic macro_rules | `(tactic| toFinite_tac) => `(tactic| apply Set.toFinite) /-- A tactic useful for transferring proofs for `encard` to their corresponding `card` statements -/ syntax "to_encard_tac" : tactic macro_rules | `(tactic| to_encard_tac) => `(tactic| simp only [← Nat.cast_le (α := ℕ∞), ← Nat.cast_inj (R := ℕ∞), Nat.cast_add, Nat.cast_one]) /-- The cardinality of `s : Set α` . Has the junk value `0` if `s` is infinite -/ noncomputable def ncard (s : Set α) : ℕ := ENat.toNat s.encard theorem ncard_def (s : Set α) : s.ncard = ENat.toNat s.encard := rfl theorem Finite.cast_ncard_eq (hs : s.Finite) : s.ncard = s.encard := by rwa [ncard, ENat.coe_toNat_eq_self, ne_eq, encard_eq_top_iff, Set.Infinite, not_not] lemma ncard_le_encard (s : Set α) : s.ncard ≤ s.encard := ENat.coe_toNat_le_self _
theorem Nat.card_coe_set_eq (s : Set α) : Nat.card s = s.ncard := by
Mathlib/Data/Set/Card.lean
506
507
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot, Yury Kudryashov, Rémy Degenne -/ import Mathlib.Data.Set.Subsingleton import Mathlib.Order.Interval.Set.Defs /-! # Intervals In any preorder, we define intervals (which on each side can be either infinite, open or closed) using the following naming conventions: - `i`: infinite - `o`: open - `c`: closed Each interval has the name `I` + letter for left side + letter for right side. For instance, `Ioc a b` denotes the interval `(a, b]`. The definitions can be found in `Mathlib.Order.Interval.Set.Defs`. This file contains basic facts on inclusion of and set operations on intervals (where the precise statements depend on the order's properties; statements requiring `LinearOrder` are in `Mathlib.Order.Interval.Set.LinearOrder`). TODO: This is just the beginning; a lot of rules are missing -/ assert_not_exists RelIso open Function open OrderDual (toDual ofDual) variable {α : Type*} namespace Set section Preorder variable [Preorder α] {a a₁ a₂ b b₁ b₂ c x : α} instance decidableMemIoo [Decidable (a < x ∧ x < b)] : Decidable (x ∈ Ioo a b) := by assumption instance decidableMemIco [Decidable (a ≤ x ∧ x < b)] : Decidable (x ∈ Ico a b) := by assumption instance decidableMemIio [Decidable (x < b)] : Decidable (x ∈ Iio b) := by assumption instance decidableMemIcc [Decidable (a ≤ x ∧ x ≤ b)] : Decidable (x ∈ Icc a b) := by assumption instance decidableMemIic [Decidable (x ≤ b)] : Decidable (x ∈ Iic b) := by assumption instance decidableMemIoc [Decidable (a < x ∧ x ≤ b)] : Decidable (x ∈ Ioc a b) := by assumption instance decidableMemIci [Decidable (a ≤ x)] : Decidable (x ∈ Ici a) := by assumption instance decidableMemIoi [Decidable (a < x)] : Decidable (x ∈ Ioi a) := by assumption theorem left_mem_Ioo : a ∈ Ioo a b ↔ False := by simp [lt_irrefl] theorem left_mem_Ico : a ∈ Ico a b ↔ a < b := by simp [le_refl] theorem left_mem_Icc : a ∈ Icc a b ↔ a ≤ b := by simp [le_refl] theorem left_mem_Ioc : a ∈ Ioc a b ↔ False := by simp [lt_irrefl] theorem left_mem_Ici : a ∈ Ici a := by simp theorem right_mem_Ioo : b ∈ Ioo a b ↔ False := by simp [lt_irrefl] theorem right_mem_Ico : b ∈ Ico a b ↔ False := by simp [lt_irrefl] theorem right_mem_Icc : b ∈ Icc a b ↔ a ≤ b := by simp [le_refl] theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b := by simp [le_refl] theorem right_mem_Iic : a ∈ Iic a := by simp @[simp] theorem Ici_toDual : Ici (toDual a) = ofDual ⁻¹' Iic a := rfl @[deprecated (since := "2025-03-20")] alias dual_Ici := Ici_toDual @[simp] theorem Iic_toDual : Iic (toDual a) = ofDual ⁻¹' Ici a := rfl @[deprecated (since := "2025-03-20")] alias dual_Iic := Iic_toDual @[simp] theorem Ioi_toDual : Ioi (toDual a) = ofDual ⁻¹' Iio a := rfl @[deprecated (since := "2025-03-20")] alias dual_Ioi := Ioi_toDual @[simp] theorem Iio_toDual : Iio (toDual a) = ofDual ⁻¹' Ioi a := rfl @[deprecated (since := "2025-03-20")] alias dual_Iio := Iio_toDual @[simp] theorem Icc_toDual : Icc (toDual a) (toDual b) = ofDual ⁻¹' Icc b a := Set.ext fun _ => and_comm @[deprecated (since := "2025-03-20")] alias dual_Icc := Icc_toDual @[simp] theorem Ioc_toDual : Ioc (toDual a) (toDual b) = ofDual ⁻¹' Ico b a := Set.ext fun _ => and_comm @[deprecated (since := "2025-03-20")] alias dual_Ioc := Ioc_toDual @[simp] theorem Ico_toDual : Ico (toDual a) (toDual b) = ofDual ⁻¹' Ioc b a := Set.ext fun _ => and_comm @[deprecated (since := "2025-03-20")] alias dual_Ico := Ico_toDual @[simp] theorem Ioo_toDual : Ioo (toDual a) (toDual b) = ofDual ⁻¹' Ioo b a := Set.ext fun _ => and_comm @[deprecated (since := "2025-03-20")] alias dual_Ioo := Ioo_toDual @[simp] theorem Ici_ofDual {x : αᵒᵈ} : Ici (ofDual x) = toDual ⁻¹' Iic x := rfl @[simp] theorem Iic_ofDual {x : αᵒᵈ} : Iic (ofDual x) = toDual ⁻¹' Ici x := rfl @[simp] theorem Ioi_ofDual {x : αᵒᵈ} : Ioi (ofDual x) = toDual ⁻¹' Iio x := rfl @[simp] theorem Iio_ofDual {x : αᵒᵈ} : Iio (ofDual x) = toDual ⁻¹' Ioi x := rfl @[simp] theorem Icc_ofDual {x y : αᵒᵈ} : Icc (ofDual y) (ofDual x) = toDual ⁻¹' Icc x y := Set.ext fun _ => and_comm @[simp] theorem Ico_ofDual {x y : αᵒᵈ} : Ico (ofDual y) (ofDual x) = toDual ⁻¹' Ioc x y := Set.ext fun _ => and_comm @[simp] theorem Ioc_ofDual {x y : αᵒᵈ} : Ioc (ofDual y) (ofDual x) = toDual ⁻¹' Ico x y := Set.ext fun _ => and_comm @[simp] theorem Ioo_ofDual {x y : αᵒᵈ} : Ioo (ofDual y) (ofDual x) = toDual ⁻¹' Ioo x y := Set.ext fun _ => and_comm @[simp] theorem nonempty_Icc : (Icc a b).Nonempty ↔ a ≤ b := ⟨fun ⟨_, hx⟩ => hx.1.trans hx.2, fun h => ⟨a, left_mem_Icc.2 h⟩⟩ @[simp] theorem nonempty_Ico : (Ico a b).Nonempty ↔ a < b := ⟨fun ⟨_, hx⟩ => hx.1.trans_lt hx.2, fun h => ⟨a, left_mem_Ico.2 h⟩⟩ @[simp] theorem nonempty_Ioc : (Ioc a b).Nonempty ↔ a < b := ⟨fun ⟨_, hx⟩ => hx.1.trans_le hx.2, fun h => ⟨b, right_mem_Ioc.2 h⟩⟩ @[simp] theorem nonempty_Ici : (Ici a).Nonempty := ⟨a, left_mem_Ici⟩ @[simp] theorem nonempty_Iic : (Iic a).Nonempty := ⟨a, right_mem_Iic⟩ @[simp] theorem nonempty_Ioo [DenselyOrdered α] : (Ioo a b).Nonempty ↔ a < b := ⟨fun ⟨_, ha, hb⟩ => ha.trans hb, exists_between⟩ @[simp] theorem nonempty_Ioi [NoMaxOrder α] : (Ioi a).Nonempty := exists_gt a @[simp] theorem nonempty_Iio [NoMinOrder α] : (Iio a).Nonempty := exists_lt a theorem nonempty_Icc_subtype (h : a ≤ b) : Nonempty (Icc a b) := Nonempty.to_subtype (nonempty_Icc.mpr h) theorem nonempty_Ico_subtype (h : a < b) : Nonempty (Ico a b) := Nonempty.to_subtype (nonempty_Ico.mpr h) theorem nonempty_Ioc_subtype (h : a < b) : Nonempty (Ioc a b) := Nonempty.to_subtype (nonempty_Ioc.mpr h) /-- An interval `Ici a` is nonempty. -/ instance nonempty_Ici_subtype : Nonempty (Ici a) := Nonempty.to_subtype nonempty_Ici /-- An interval `Iic a` is nonempty. -/ instance nonempty_Iic_subtype : Nonempty (Iic a) := Nonempty.to_subtype nonempty_Iic theorem nonempty_Ioo_subtype [DenselyOrdered α] (h : a < b) : Nonempty (Ioo a b) := Nonempty.to_subtype (nonempty_Ioo.mpr h) /-- In an order without maximal elements, the intervals `Ioi` are nonempty. -/ instance nonempty_Ioi_subtype [NoMaxOrder α] : Nonempty (Ioi a) := Nonempty.to_subtype nonempty_Ioi /-- In an order without minimal elements, the intervals `Iio` are nonempty. -/ instance nonempty_Iio_subtype [NoMinOrder α] : Nonempty (Iio a) := Nonempty.to_subtype nonempty_Iio instance [NoMinOrder α] : NoMinOrder (Iio a) := ⟨fun a => let ⟨b, hb⟩ := exists_lt (a : α) ⟨⟨b, lt_trans hb a.2⟩, hb⟩⟩ instance [NoMinOrder α] : NoMinOrder (Iic a) := ⟨fun a => let ⟨b, hb⟩ := exists_lt (a : α) ⟨⟨b, hb.le.trans a.2⟩, hb⟩⟩ instance [NoMaxOrder α] : NoMaxOrder (Ioi a) := OrderDual.noMaxOrder (α := Iio (toDual a)) instance [NoMaxOrder α] : NoMaxOrder (Ici a) := OrderDual.noMaxOrder (α := Iic (toDual a)) @[simp] theorem Icc_eq_empty (h : ¬a ≤ b) : Icc a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans hb) @[simp] theorem Ico_eq_empty (h : ¬a < b) : Ico a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans_lt hb) @[simp] theorem Ioc_eq_empty (h : ¬a < b) : Ioc a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans_le hb) @[simp] theorem Ioo_eq_empty (h : ¬a < b) : Ioo a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans hb) @[simp] theorem Icc_eq_empty_of_lt (h : b < a) : Icc a b = ∅ := Icc_eq_empty h.not_le @[simp] theorem Ico_eq_empty_of_le (h : b ≤ a) : Ico a b = ∅ := Ico_eq_empty h.not_lt @[simp] theorem Ioc_eq_empty_of_le (h : b ≤ a) : Ioc a b = ∅ := Ioc_eq_empty h.not_lt @[simp] theorem Ioo_eq_empty_of_le (h : b ≤ a) : Ioo a b = ∅ := Ioo_eq_empty h.not_lt theorem Ico_self (a : α) : Ico a a = ∅ := Ico_eq_empty <| lt_irrefl _ theorem Ioc_self (a : α) : Ioc a a = ∅ := Ioc_eq_empty <| lt_irrefl _ theorem Ioo_self (a : α) : Ioo a a = ∅ := Ioo_eq_empty <| lt_irrefl _ @[simp] theorem Ici_subset_Ici : Ici a ⊆ Ici b ↔ b ≤ a := ⟨fun h => h <| left_mem_Ici, fun h _ hx => h.trans hx⟩ @[gcongr] alias ⟨_, _root_.GCongr.Ici_subset_Ici_of_le⟩ := Ici_subset_Ici @[simp] theorem Ici_ssubset_Ici : Ici a ⊂ Ici b ↔ b < a where mp h := by obtain ⟨ab, c, cb, ac⟩ := ssubset_iff_exists.mp h exact lt_of_le_not_le (Ici_subset_Ici.mp ab) (fun h' ↦ ac (h'.trans cb)) mpr h := (ssubset_iff_of_subset (Ici_subset_Ici.mpr h.le)).mpr ⟨b, right_mem_Iic, fun h' => h.not_le h'⟩ @[gcongr] alias ⟨_, _root_.GCongr.Ici_ssubset_Ici_of_le⟩ := Ici_ssubset_Ici @[simp] theorem Iic_subset_Iic : Iic a ⊆ Iic b ↔ a ≤ b := @Ici_subset_Ici αᵒᵈ _ _ _ @[gcongr] alias ⟨_, _root_.GCongr.Iic_subset_Iic_of_le⟩ := Iic_subset_Iic @[simp] theorem Iic_ssubset_Iic : Iic a ⊂ Iic b ↔ a < b := @Ici_ssubset_Ici αᵒᵈ _ _ _ @[gcongr] alias ⟨_, _root_.GCongr.Iic_ssubset_Iic_of_le⟩ := Iic_ssubset_Iic @[simp] theorem Ici_subset_Ioi : Ici a ⊆ Ioi b ↔ b < a := ⟨fun h => h left_mem_Ici, fun h _ hx => h.trans_le hx⟩ @[simp] theorem Iic_subset_Iio : Iic a ⊆ Iio b ↔ a < b := ⟨fun h => h right_mem_Iic, fun h _ hx => lt_of_le_of_lt hx h⟩ @[gcongr] theorem Ioo_subset_Ioo (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Ioo a₁ b₁ ⊆ Ioo a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans_lt hx₁, hx₂.trans_le h₂⟩ @[gcongr] theorem Ioo_subset_Ioo_left (h : a₁ ≤ a₂) : Ioo a₂ b ⊆ Ioo a₁ b := Ioo_subset_Ioo h le_rfl @[gcongr] theorem Ioo_subset_Ioo_right (h : b₁ ≤ b₂) : Ioo a b₁ ⊆ Ioo a b₂ := Ioo_subset_Ioo le_rfl h @[gcongr] theorem Ico_subset_Ico (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Ico a₁ b₁ ⊆ Ico a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans hx₁, hx₂.trans_le h₂⟩ @[gcongr] theorem Ico_subset_Ico_left (h : a₁ ≤ a₂) : Ico a₂ b ⊆ Ico a₁ b := Ico_subset_Ico h le_rfl @[gcongr] theorem Ico_subset_Ico_right (h : b₁ ≤ b₂) : Ico a b₁ ⊆ Ico a b₂ := Ico_subset_Ico le_rfl h @[gcongr] theorem Icc_subset_Icc (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Icc a₁ b₁ ⊆ Icc a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans hx₁, le_trans hx₂ h₂⟩ @[gcongr] theorem Icc_subset_Icc_left (h : a₁ ≤ a₂) : Icc a₂ b ⊆ Icc a₁ b := Icc_subset_Icc h le_rfl @[gcongr] theorem Icc_subset_Icc_right (h : b₁ ≤ b₂) : Icc a b₁ ⊆ Icc a b₂ := Icc_subset_Icc le_rfl h theorem Icc_subset_Ioo (ha : a₂ < a₁) (hb : b₁ < b₂) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ := fun _ hx => ⟨ha.trans_le hx.1, hx.2.trans_lt hb⟩ theorem Icc_subset_Ici_self : Icc a b ⊆ Ici a := fun _ => And.left theorem Icc_subset_Iic_self : Icc a b ⊆ Iic b := fun _ => And.right theorem Ioc_subset_Iic_self : Ioc a b ⊆ Iic b := fun _ => And.right @[gcongr] theorem Ioc_subset_Ioc (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Ioc a₁ b₁ ⊆ Ioc a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans_lt hx₁, hx₂.trans h₂⟩ @[gcongr] theorem Ioc_subset_Ioc_left (h : a₁ ≤ a₂) : Ioc a₂ b ⊆ Ioc a₁ b := Ioc_subset_Ioc h le_rfl @[gcongr] theorem Ioc_subset_Ioc_right (h : b₁ ≤ b₂) : Ioc a b₁ ⊆ Ioc a b₂ := Ioc_subset_Ioc le_rfl h theorem Ico_subset_Ioo_left (h₁ : a₁ < a₂) : Ico a₂ b ⊆ Ioo a₁ b := fun _ => And.imp_left h₁.trans_le theorem Ioc_subset_Ioo_right (h : b₁ < b₂) : Ioc a b₁ ⊆ Ioo a b₂ := fun _ => And.imp_right fun h' => h'.trans_lt h theorem Icc_subset_Ico_right (h₁ : b₁ < b₂) : Icc a b₁ ⊆ Ico a b₂ := fun _ => And.imp_right fun h₂ => h₂.trans_lt h₁ theorem Ioo_subset_Ico_self : Ioo a b ⊆ Ico a b := fun _ => And.imp_left le_of_lt theorem Ioo_subset_Ioc_self : Ioo a b ⊆ Ioc a b := fun _ => And.imp_right le_of_lt theorem Ico_subset_Icc_self : Ico a b ⊆ Icc a b := fun _ => And.imp_right le_of_lt theorem Ioc_subset_Icc_self : Ioc a b ⊆ Icc a b := fun _ => And.imp_left le_of_lt theorem Ioo_subset_Icc_self : Ioo a b ⊆ Icc a b := Subset.trans Ioo_subset_Ico_self Ico_subset_Icc_self theorem Ico_subset_Iio_self : Ico a b ⊆ Iio b := fun _ => And.right theorem Ioo_subset_Iio_self : Ioo a b ⊆ Iio b := fun _ => And.right theorem Ioc_subset_Ioi_self : Ioc a b ⊆ Ioi a := fun _ => And.left theorem Ioo_subset_Ioi_self : Ioo a b ⊆ Ioi a := fun _ => And.left theorem Ioi_subset_Ici_self : Ioi a ⊆ Ici a := fun _ hx => le_of_lt hx theorem Iio_subset_Iic_self : Iio a ⊆ Iic a := fun _ hx => le_of_lt hx theorem Ico_subset_Ici_self : Ico a b ⊆ Ici a := fun _ => And.left theorem Ioi_ssubset_Ici_self : Ioi a ⊂ Ici a := ⟨Ioi_subset_Ici_self, fun h => lt_irrefl a (h le_rfl)⟩ theorem Iio_ssubset_Iic_self : Iio a ⊂ Iic a := @Ioi_ssubset_Ici_self αᵒᵈ _ _ theorem Icc_subset_Icc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Icc a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans hx, hx'.trans h'⟩⟩ theorem Icc_subset_Ioo_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ ↔ a₂ < a₁ ∧ b₁ < b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans_le hx, hx'.trans_lt h'⟩⟩ theorem Icc_subset_Ico_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ < b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans hx, hx'.trans_lt h'⟩⟩ theorem Icc_subset_Ioc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioc a₂ b₂ ↔ a₂ < a₁ ∧ b₁ ≤ b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans_le hx, hx'.trans h'⟩⟩ theorem Icc_subset_Iio_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Iio b₂ ↔ b₁ < b₂ := ⟨fun h => h ⟨h₁, le_rfl⟩, fun h _ ⟨_, hx'⟩ => hx'.trans_lt h⟩ theorem Icc_subset_Ioi_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioi a₂ ↔ a₂ < a₁ := ⟨fun h => h ⟨le_rfl, h₁⟩, fun h _ ⟨hx, _⟩ => h.trans_le hx⟩ theorem Icc_subset_Iic_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Iic b₂ ↔ b₁ ≤ b₂ := ⟨fun h => h ⟨h₁, le_rfl⟩, fun h _ ⟨_, hx'⟩ => hx'.trans h⟩ theorem Icc_subset_Ici_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ici a₂ ↔ a₂ ≤ a₁ := ⟨fun h => h ⟨le_rfl, h₁⟩, fun h _ ⟨hx, _⟩ => h.trans hx⟩ theorem Icc_ssubset_Icc_left (hI : a₂ ≤ b₂) (ha : a₂ < a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := (ssubset_iff_of_subset (Icc_subset_Icc (le_of_lt ha) hb)).mpr ⟨a₂, left_mem_Icc.mpr hI, not_and.mpr fun f _ => lt_irrefl a₂ (ha.trans_le f)⟩ theorem Icc_ssubset_Icc_right (hI : a₂ ≤ b₂) (ha : a₂ ≤ a₁) (hb : b₁ < b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := (ssubset_iff_of_subset (Icc_subset_Icc ha (le_of_lt hb))).mpr ⟨b₂, right_mem_Icc.mpr hI, fun f => lt_irrefl b₁ (hb.trans_le f.2)⟩ /-- If `a ≤ b`, then `(b, +∞) ⊆ (a, +∞)`. In preorders, this is just an implication. If you need the equivalence in linear orders, use `Ioi_subset_Ioi_iff`. -/ @[gcongr] theorem Ioi_subset_Ioi (h : a ≤ b) : Ioi b ⊆ Ioi a := fun _ hx => h.trans_lt hx /-- If `a < b`, then `(b, +∞) ⊂ (a, +∞)`. In preorders, this is just an implication. If you need the equivalence in linear orders, use `Ioi_ssubset_Ioi_iff`. -/ @[gcongr] theorem Ioi_ssubset_Ioi (h : a < b) : Ioi b ⊂ Ioi a := (ssubset_iff_of_subset (Ioi_subset_Ioi h.le)).mpr ⟨b, h, lt_irrefl b⟩ /-- If `a ≤ b`, then `(b, +∞) ⊆ [a, +∞)`. In preorders, this is just an implication. If you need the equivalence in dense linear orders, use `Ioi_subset_Ici_iff`. -/ theorem Ioi_subset_Ici (h : a ≤ b) : Ioi b ⊆ Ici a := Subset.trans (Ioi_subset_Ioi h) Ioi_subset_Ici_self /-- If `a ≤ b`, then `(-∞, a) ⊆ (-∞, b)`. In preorders, this is just an implication. If you need the equivalence in linear orders, use `Iio_subset_Iio_iff`. -/ @[gcongr] theorem Iio_subset_Iio (h : a ≤ b) : Iio a ⊆ Iio b := fun _ hx => lt_of_lt_of_le hx h /-- If `a < b`, then `(-∞, a) ⊂ (-∞, b)`. In preorders, this is just an implication. If you need the equivalence in linear orders, use `Iio_ssubset_Iio_iff`. -/ @[gcongr] theorem Iio_ssubset_Iio (h : a < b) : Iio a ⊂ Iio b := (ssubset_iff_of_subset (Iio_subset_Iio h.le)).mpr ⟨a, h, lt_irrefl a⟩ /-- If `a ≤ b`, then `(-∞, a) ⊆ (-∞, b]`. In preorders, this is just an implication. If you need the equivalence in dense linear orders, use `Iio_subset_Iic_iff`. -/ theorem Iio_subset_Iic (h : a ≤ b) : Iio a ⊆ Iic b := Subset.trans (Iio_subset_Iio h) Iio_subset_Iic_self theorem Ici_inter_Iic : Ici a ∩ Iic b = Icc a b := rfl theorem Ici_inter_Iio : Ici a ∩ Iio b = Ico a b := rfl theorem Ioi_inter_Iic : Ioi a ∩ Iic b = Ioc a b := rfl theorem Ioi_inter_Iio : Ioi a ∩ Iio b = Ioo a b := rfl theorem Iic_inter_Ici : Iic a ∩ Ici b = Icc b a := inter_comm _ _ theorem Iio_inter_Ici : Iio a ∩ Ici b = Ico b a := inter_comm _ _ theorem Iic_inter_Ioi : Iic a ∩ Ioi b = Ioc b a := inter_comm _ _ theorem Iio_inter_Ioi : Iio a ∩ Ioi b = Ioo b a := inter_comm _ _ theorem mem_Icc_of_Ioo (h : x ∈ Ioo a b) : x ∈ Icc a b := Ioo_subset_Icc_self h theorem mem_Ico_of_Ioo (h : x ∈ Ioo a b) : x ∈ Ico a b := Ioo_subset_Ico_self h theorem mem_Ioc_of_Ioo (h : x ∈ Ioo a b) : x ∈ Ioc a b := Ioo_subset_Ioc_self h theorem mem_Icc_of_Ico (h : x ∈ Ico a b) : x ∈ Icc a b := Ico_subset_Icc_self h theorem mem_Icc_of_Ioc (h : x ∈ Ioc a b) : x ∈ Icc a b := Ioc_subset_Icc_self h theorem mem_Ici_of_Ioi (h : x ∈ Ioi a) : x ∈ Ici a := Ioi_subset_Ici_self h theorem mem_Iic_of_Iio (h : x ∈ Iio a) : x ∈ Iic a := Iio_subset_Iic_self h theorem Icc_eq_empty_iff : Icc a b = ∅ ↔ ¬a ≤ b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Icc] theorem Ico_eq_empty_iff : Ico a b = ∅ ↔ ¬a < b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ico] theorem Ioc_eq_empty_iff : Ioc a b = ∅ ↔ ¬a < b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ioc] theorem Ioo_eq_empty_iff [DenselyOrdered α] : Ioo a b = ∅ ↔ ¬a < b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ioo] theorem _root_.IsTop.Iic_eq (h : IsTop a) : Iic a = univ := eq_univ_of_forall h theorem _root_.IsBot.Ici_eq (h : IsBot a) : Ici a = univ := eq_univ_of_forall h @[simp] theorem Ioi_eq_empty_iff : Ioi a = ∅ ↔ IsMax a := by simp only [isMax_iff_forall_not_lt, eq_empty_iff_forall_not_mem, mem_Ioi] @[simp] theorem Iio_eq_empty_iff : Iio a = ∅ ↔ IsMin a := Ioi_eq_empty_iff (α := αᵒᵈ) @[simp] alias ⟨_, _root_.IsMax.Ioi_eq⟩ := Ioi_eq_empty_iff @[simp] alias ⟨_, _root_.IsMin.Iio_eq⟩ := Iio_eq_empty_iff @[simp] lemma Iio_nonempty : (Iio a).Nonempty ↔ ¬ IsMin a := by simp [nonempty_iff_ne_empty] @[simp] lemma Ioi_nonempty : (Ioi a).Nonempty ↔ ¬ IsMax a := by simp [nonempty_iff_ne_empty] theorem Iic_inter_Ioc_of_le (h : a ≤ c) : Iic a ∩ Ioc b c = Ioc b a := ext fun _ => ⟨fun H => ⟨H.2.1, H.1⟩, fun H => ⟨H.2, H.1, H.2.trans h⟩⟩ theorem not_mem_Icc_of_lt (ha : c < a) : c ∉ Icc a b := fun h => ha.not_le h.1 theorem not_mem_Icc_of_gt (hb : b < c) : c ∉ Icc a b := fun h => hb.not_le h.2 theorem not_mem_Ico_of_lt (ha : c < a) : c ∉ Ico a b := fun h => ha.not_le h.1 theorem not_mem_Ioc_of_gt (hb : b < c) : c ∉ Ioc a b := fun h => hb.not_le h.2 theorem not_mem_Ioi_self : a ∉ Ioi a := lt_irrefl _ theorem not_mem_Iio_self : b ∉ Iio b := lt_irrefl _ theorem not_mem_Ioc_of_le (ha : c ≤ a) : c ∉ Ioc a b := fun h => lt_irrefl _ <| h.1.trans_le ha theorem not_mem_Ico_of_ge (hb : b ≤ c) : c ∉ Ico a b := fun h => lt_irrefl _ <| h.2.trans_le hb theorem not_mem_Ioo_of_le (ha : c ≤ a) : c ∉ Ioo a b := fun h => lt_irrefl _ <| h.1.trans_le ha theorem not_mem_Ioo_of_ge (hb : b ≤ c) : c ∉ Ioo a b := fun h => lt_irrefl _ <| h.2.trans_le hb section matched_intervals @[simp] theorem Icc_eq_Ioc_same_iff : Icc a b = Ioc a b ↔ ¬a ≤ b where mp h := by simpa using Set.ext_iff.mp h a mpr h := by rw [Icc_eq_empty h, Ioc_eq_empty (mt le_of_lt h)] @[simp] theorem Icc_eq_Ico_same_iff : Icc a b = Ico a b ↔ ¬a ≤ b where mp h := by simpa using Set.ext_iff.mp h b mpr h := by rw [Icc_eq_empty h, Ico_eq_empty (mt le_of_lt h)] @[simp] theorem Icc_eq_Ioo_same_iff : Icc a b = Ioo a b ↔ ¬a ≤ b where mp h := by simpa using Set.ext_iff.mp h b mpr h := by rw [Icc_eq_empty h, Ioo_eq_empty (mt le_of_lt h)] @[simp] theorem Ioc_eq_Ico_same_iff : Ioc a b = Ico a b ↔ ¬a < b where mp h := by simpa using Set.ext_iff.mp h a mpr h := by rw [Ioc_eq_empty h, Ico_eq_empty h] @[simp] theorem Ioo_eq_Ioc_same_iff : Ioo a b = Ioc a b ↔ ¬a < b where mp h := by simpa using Set.ext_iff.mp h b mpr h := by rw [Ioo_eq_empty h, Ioc_eq_empty h] @[simp] theorem Ioo_eq_Ico_same_iff : Ioo a b = Ico a b ↔ ¬a < b where mp h := by simpa using Set.ext_iff.mp h a mpr h := by rw [Ioo_eq_empty h, Ico_eq_empty h] -- Mirrored versions of the above for `simp`. @[simp] theorem Ioc_eq_Icc_same_iff : Ioc a b = Icc a b ↔ ¬a ≤ b := eq_comm.trans Icc_eq_Ioc_same_iff @[simp] theorem Ico_eq_Icc_same_iff : Ico a b = Icc a b ↔ ¬a ≤ b := eq_comm.trans Icc_eq_Ico_same_iff @[simp] theorem Ioo_eq_Icc_same_iff : Ioo a b = Icc a b ↔ ¬a ≤ b := eq_comm.trans Icc_eq_Ioo_same_iff @[simp] theorem Ico_eq_Ioc_same_iff : Ico a b = Ioc a b ↔ ¬a < b := eq_comm.trans Ioc_eq_Ico_same_iff @[simp] theorem Ioc_eq_Ioo_same_iff : Ioc a b = Ioo a b ↔ ¬a < b := eq_comm.trans Ioo_eq_Ioc_same_iff @[simp] theorem Ico_eq_Ioo_same_iff : Ico a b = Ioo a b ↔ ¬a < b := eq_comm.trans Ioo_eq_Ico_same_iff end matched_intervals end Preorder section PartialOrder variable [PartialOrder α] {a b c : α} @[simp] theorem Icc_self (a : α) : Icc a a = {a} := Set.ext <| by simp [Icc, le_antisymm_iff, and_comm] instance instIccUnique : Unique (Set.Icc a a) where default := ⟨a, by simp⟩ uniq y := Subtype.ext <| by simpa using y.2 @[simp] theorem Icc_eq_singleton_iff : Icc a b = {c} ↔ a = c ∧ b = c := by refine ⟨fun h => ?_, ?_⟩ · have hab : a ≤ b := nonempty_Icc.1 (h.symm.subst <| singleton_nonempty c) exact ⟨eq_of_mem_singleton <| h ▸ left_mem_Icc.2 hab, eq_of_mem_singleton <| h ▸ right_mem_Icc.2 hab⟩ · rintro ⟨rfl, rfl⟩ exact Icc_self _ lemma subsingleton_Icc_of_ge (hba : b ≤ a) : Set.Subsingleton (Icc a b) := fun _x ⟨hax, hxb⟩ _y ⟨hay, hyb⟩ ↦ le_antisymm (le_implies_le_of_le_of_le hxb hay hba) (le_implies_le_of_le_of_le hyb hax hba) @[simp] lemma subsingleton_Icc_iff {α : Type*} [LinearOrder α] {a b : α} : Set.Subsingleton (Icc a b) ↔ b ≤ a := by refine ⟨fun h ↦ ?_, subsingleton_Icc_of_ge⟩ contrapose! h simp only [gt_iff_lt, not_subsingleton_iff] exact ⟨a, ⟨le_refl _, h.le⟩, b, ⟨h.le, le_refl _⟩, h.ne⟩ @[simp] theorem Icc_diff_left : Icc a b \ {a} = Ioc a b := ext fun x => by simp [lt_iff_le_and_ne, eq_comm, and_right_comm] @[simp] theorem Icc_diff_right : Icc a b \ {b} = Ico a b := ext fun x => by simp [lt_iff_le_and_ne, and_assoc] @[simp] theorem Ico_diff_left : Ico a b \ {a} = Ioo a b := ext fun x => by simp [and_right_comm, ← lt_iff_le_and_ne, eq_comm] @[simp] theorem Ioc_diff_right : Ioc a b \ {b} = Ioo a b := ext fun x => by simp [and_assoc, ← lt_iff_le_and_ne] @[simp] theorem Icc_diff_both : Icc a b \ {a, b} = Ioo a b := by rw [insert_eq, ← diff_diff, Icc_diff_left, Ioc_diff_right] @[simp] theorem Ici_diff_left : Ici a \ {a} = Ioi a := ext fun x => by simp [lt_iff_le_and_ne, eq_comm] @[simp] theorem Iic_diff_right : Iic a \ {a} = Iio a := ext fun x => by simp [lt_iff_le_and_ne] @[simp] theorem Ico_diff_Ioo_same (h : a < b) : Ico a b \ Ioo a b = {a} := by rw [← Ico_diff_left, diff_diff_cancel_left (singleton_subset_iff.2 <| left_mem_Ico.2 h)] @[simp]
theorem Ioc_diff_Ioo_same (h : a < b) : Ioc a b \ Ioo a b = {b} := by rw [← Ioc_diff_right, diff_diff_cancel_left (singleton_subset_iff.2 <| right_mem_Ioc.2 h)]
Mathlib/Order/Interval/Set/Basic.lean
700
701
/- Copyright (c) 2022 Jujian Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jujian Zhang -/ import Mathlib.LinearAlgebra.LinearPMap import Mathlib.Algebra.Equiv.TransferInstance import Mathlib.Logic.Small.Basic import Mathlib.RingTheory.Ideal.Defs /-! # Injective modules ## Main definitions * `Module.Injective`: an `R`-module `Q` is injective if and only if every injective `R`-linear map descends to a linear map to `Q`, i.e. in the following diagram, if `f` is injective then there is an `R`-linear map `h : Y ⟶ Q` such that `g = h ∘ f` ``` X --- f ---> Y | | g v Q ``` * `Module.Baer`: an `R`-module `Q` satisfies Baer's criterion if any `R`-linear map from an `Ideal R` extends to an `R`-linear map `R ⟶ Q` ## Main statements * `Module.Baer.injective`: an `R`-module is injective if it is Baer. -/ assert_not_exists ModuleCat noncomputable section universe u v v' variable (R : Type u) [Ring R] (Q : Type v) [AddCommGroup Q] [Module R Q] /-- An `R`-module `Q` is injective if and only if every injective `R`-linear map descends to a linear map to `Q`, i.e. in the following diagram, if `f` is injective then there is an `R`-linear map `h : Y ⟶ Q` such that `g = h ∘ f` ``` X --- f ---> Y | | g v Q ``` -/ @[mk_iff] class Module.Injective : Prop where out : ∀ ⦃X Y : Type v⦄ [AddCommGroup X] [AddCommGroup Y] [Module R X] [Module R Y] (f : X →ₗ[R] Y) (_ : Function.Injective f) (g : X →ₗ[R] Q), ∃ h : Y →ₗ[R] Q, ∀ x, h (f x) = g x /-- An `R`-module `Q` satisfies Baer's criterion if any `R`-linear map from an `Ideal R` extends to an `R`-linear map `R ⟶ Q` -/ def Module.Baer : Prop := ∀ (I : Ideal R) (g : I →ₗ[R] Q), ∃ g' : R →ₗ[R] Q, ∀ (x : R) (mem : x ∈ I), g' x = g ⟨x, mem⟩ namespace Module.Baer variable {R Q} {M N : Type*} [AddCommGroup M] [AddCommGroup N] variable [Module R M] [Module R N] (i : M →ₗ[R] N) (f : M →ₗ[R] Q) lemma of_equiv (e : Q ≃ₗ[R] M) (h : Module.Baer R Q) : Module.Baer R M := fun I g ↦ have ⟨g', h'⟩ := h I (e.symm ∘ₗ g) ⟨e ∘ₗ g', by simpa [LinearEquiv.eq_symm_apply] using h'⟩ lemma congr (e : Q ≃ₗ[R] M) : Module.Baer R Q ↔ Module.Baer R M := ⟨of_equiv e, of_equiv e.symm⟩ /-- If we view `M` as a submodule of `N` via the injective linear map `i : M ↪ N`, then a submodule between `M` and `N` is a submodule `N'` of `N`. To prove Baer's criterion, we need to consider pairs of `(N', f')` such that `M ≤ N' ≤ N` and `f'` extends `f`. -/ structure ExtensionOf extends LinearPMap R N Q where le : LinearMap.range i ≤ domain is_extension : ∀ m : M, f m = toLinearPMap ⟨i m, le ⟨m, rfl⟩⟩ section Ext variable {i f} @[ext (iff := false)] theorem ExtensionOf.ext {a b : ExtensionOf i f} (domain_eq : a.domain = b.domain) (to_fun_eq : ∀ ⦃x : N⦄ ⦃ha : x ∈ a.domain⦄ ⦃hb : x ∈ b.domain⦄, a.toLinearPMap ⟨x, ha⟩ = b.toLinearPMap ⟨x, hb⟩) : a = b := by rcases a with ⟨a, a_le, e1⟩ rcases b with ⟨b, b_le, e2⟩ congr exact LinearPMap.ext domain_eq to_fun_eq /-- A dependent version of `ExtensionOf.ext` -/ theorem ExtensionOf.dExt {a b : ExtensionOf i f} (domain_eq : a.domain = b.domain) (to_fun_eq : ∀ ⦃x : a.domain⦄ ⦃y : b.domain⦄, (x : N) = y → a.toLinearPMap x = b.toLinearPMap y) : a = b := ext domain_eq fun _ _ _ ↦ to_fun_eq rfl theorem ExtensionOf.dExt_iff {a b : ExtensionOf i f} : a = b ↔ ∃ _ : a.domain = b.domain, ∀ ⦃x : a.domain⦄ ⦃y : b.domain⦄, (x : N) = y → a.toLinearPMap x = b.toLinearPMap y := ⟨fun r => r ▸ ⟨rfl, fun _ _ h => congr_arg a.toFun <| mod_cast h⟩, fun ⟨h1, h2⟩ => ExtensionOf.dExt h1 h2⟩ end Ext instance : Min (ExtensionOf i f) where min X1 X2 := { X1.toLinearPMap ⊓ X2.toLinearPMap with le := fun x hx => (by rcases hx with ⟨x, rfl⟩ refine ⟨X1.le (Set.mem_range_self _), X2.le (Set.mem_range_self _), ?_⟩ rw [← X1.is_extension x, ← X2.is_extension x] : x ∈ X1.toLinearPMap.eqLocus X2.toLinearPMap) is_extension := fun _ => X1.is_extension _ } instance : SemilatticeInf (ExtensionOf i f) := Function.Injective.semilatticeInf ExtensionOf.toLinearPMap (fun X Y h ↦ ExtensionOf.ext (by rw [h]) <| by rw [h] intros rfl) fun X Y ↦ LinearPMap.ext rfl fun x y h => by congr variable {i f} theorem chain_linearPMap_of_chain_extensionOf {c : Set (ExtensionOf i f)} (hchain : IsChain (· ≤ ·) c) : IsChain (· ≤ ·) <| (fun x : ExtensionOf i f => x.toLinearPMap) '' c := by rintro _ ⟨a, a_mem, rfl⟩ _ ⟨b, b_mem, rfl⟩ neq exact hchain a_mem b_mem (ne_of_apply_ne _ neq) /-- The maximal element of every nonempty chain of `extension_of i f`. -/ def ExtensionOf.max {c : Set (ExtensionOf i f)} (hchain : IsChain (· ≤ ·) c) (hnonempty : c.Nonempty) : ExtensionOf i f := { LinearPMap.sSup _ (IsChain.directedOn <| chain_linearPMap_of_chain_extensionOf hchain) with le := by refine le_trans hnonempty.some.le <| (LinearPMap.le_sSup _ <| (Set.mem_image _ _ _).mpr ⟨hnonempty.some, hnonempty.choose_spec, rfl⟩).1 is_extension := fun m => by refine Eq.trans (hnonempty.some.is_extension m) ?_ symm generalize_proofs _ _ h1 exact LinearPMap.sSup_apply (IsChain.directedOn <| chain_linearPMap_of_chain_extensionOf hchain) ((Set.mem_image _ _ _).mpr ⟨hnonempty.some, hnonempty.choose_spec, rfl⟩) ⟨i m, h1⟩ } theorem ExtensionOf.le_max {c : Set (ExtensionOf i f)} (hchain : IsChain (· ≤ ·) c) (hnonempty : c.Nonempty) (a : ExtensionOf i f) (ha : a ∈ c) : a ≤ ExtensionOf.max hchain hnonempty := LinearPMap.le_sSup (IsChain.directedOn <| chain_linearPMap_of_chain_extensionOf hchain) <| (Set.mem_image _ _ _).mpr ⟨a, ha, rfl⟩ variable (i f) [Fact <| Function.Injective i] instance ExtensionOf.inhabited : Inhabited (ExtensionOf i f) where default := { domain := LinearMap.range i toFun := { toFun := fun x => f x.2.choose map_add' := fun x y => by have eq1 : _ + _ = (x + y).1 := congr_arg₂ (· + ·) x.2.choose_spec y.2.choose_spec rw [← map_add, ← (x + y).2.choose_spec] at eq1 dsimp rw [← Fact.out (p := Function.Injective i) eq1, map_add] map_smul' := fun r x => by have eq1 : r • _ = (r • x).1 := congr_arg (r • ·) x.2.choose_spec rw [← LinearMap.map_smul, ← (r • x).2.choose_spec] at eq1 dsimp rw [← Fact.out (p := Function.Injective i) eq1, LinearMap.map_smul] } le := le_refl _ is_extension := fun m => by simp only [LinearPMap.mk_apply, LinearMap.coe_mk] dsimp apply congrArg exact Fact.out (p := Function.Injective i) (⟨i m, ⟨_, rfl⟩⟩ : LinearMap.range i).2.choose_spec.symm } /-- Since every nonempty chain has a maximal element, by Zorn's lemma, there is a maximal `extension_of i f`. -/ def extensionOfMax : ExtensionOf i f := (@zorn_le_nonempty (ExtensionOf i f) _ ⟨Inhabited.default⟩ fun _ hchain hnonempty => ⟨ExtensionOf.max hchain hnonempty, ExtensionOf.le_max hchain hnonempty⟩).choose theorem extensionOfMax_is_max : ∀ (a : ExtensionOf i f), extensionOfMax i f ≤ a → a = extensionOfMax i f := fun _ ↦ (@zorn_le_nonempty (ExtensionOf i f) _ ⟨Inhabited.default⟩ fun _ hchain hnonempty => ⟨ExtensionOf.max hchain hnonempty, ExtensionOf.le_max hchain hnonempty⟩).choose_spec.eq_of_ge -- Porting note: helper function. Lean looks for an instance of `Sup (Type u)` when the -- right hand side is substituted in directly abbrev supExtensionOfMaxSingleton (y : N) : Submodule R N := (extensionOfMax i f).domain ⊔ (Submodule.span R {y}) variable {f} private theorem extensionOfMax_adjoin.aux1 {y : N} (x : supExtensionOfMaxSingleton i f y) : ∃ (a : (extensionOfMax i f).domain) (b : R), x.1 = a.1 + b • y := by have mem1 : x.1 ∈ (_ : Set _) := x.2 rw [Submodule.coe_sup] at mem1 rcases mem1 with ⟨a, a_mem, b, b_mem : b ∈ (Submodule.span R _ : Submodule R N), eq1⟩ rw [Submodule.mem_span_singleton] at b_mem rcases b_mem with ⟨z, eq2⟩ exact ⟨⟨a, a_mem⟩, z, by rw [← eq1, ← eq2]⟩ /-- If `x ∈ M ⊔ ⟨y⟩`, then `x = m + r • y`, `fst` pick an arbitrary such `m`. -/ def ExtensionOfMaxAdjoin.fst {y : N} (x : supExtensionOfMaxSingleton i f y) : (extensionOfMax i f).domain := (extensionOfMax_adjoin.aux1 i x).choose /-- If `x ∈ M ⊔ ⟨y⟩`, then `x = m + r • y`, `snd` pick an arbitrary such `r`. -/ def ExtensionOfMaxAdjoin.snd {y : N} (x : supExtensionOfMaxSingleton i f y) : R := (extensionOfMax_adjoin.aux1 i x).choose_spec.choose theorem ExtensionOfMaxAdjoin.eqn {y : N} (x : supExtensionOfMaxSingleton i f y) : ↑x = ↑(ExtensionOfMaxAdjoin.fst i x) + ExtensionOfMaxAdjoin.snd i x • y := (extensionOfMax_adjoin.aux1 i x).choose_spec.choose_spec variable (f) -- TODO: refactor to use colon ideals? /-- The ideal `I = {r | r • y ∈ N}` -/ def ExtensionOfMaxAdjoin.ideal (y : N) : Ideal R := (extensionOfMax i f).domain.comap ((LinearMap.id : R →ₗ[R] R).smulRight y) /-- A linear map `I ⟶ Q` by `x ↦ f' (x • y)` where `f'` is the maximal extension -/ def ExtensionOfMaxAdjoin.idealTo (y : N) : ExtensionOfMaxAdjoin.ideal i f y →ₗ[R] Q where toFun (z : { x // x ∈ ideal i f y }) := (extensionOfMax i f).toLinearPMap ⟨(↑z : R) • y, z.prop⟩ map_add' (z1 z2 : { x // x ∈ ideal i f y }) := by simp_rw [← (extensionOfMax i f).toLinearPMap.map_add] congr apply add_smul map_smul' z1 (z2 : {x // x ∈ ideal i f y}) := by simp_rw [← (extensionOfMax i f).toLinearPMap.map_smul] congr 2 apply mul_smul /-- Since we assumed `Q` being Baer, the linear map `x ↦ f' (x • y) : I ⟶ Q` extends to `R ⟶ Q`, call this extended map `φ` -/ def ExtensionOfMaxAdjoin.extendIdealTo (h : Module.Baer R Q) (y : N) : R →ₗ[R] Q := (h (ExtensionOfMaxAdjoin.ideal i f y) (ExtensionOfMaxAdjoin.idealTo i f y)).choose theorem ExtensionOfMaxAdjoin.extendIdealTo_is_extension (h : Module.Baer R Q) (y : N) : ∀ (x : R) (mem : x ∈ ExtensionOfMaxAdjoin.ideal i f y), ExtensionOfMaxAdjoin.extendIdealTo i f h y x = ExtensionOfMaxAdjoin.idealTo i f y ⟨x, mem⟩ := (h (ExtensionOfMaxAdjoin.ideal i f y) (ExtensionOfMaxAdjoin.idealTo i f y)).choose_spec theorem ExtensionOfMaxAdjoin.extendIdealTo_wd' (h : Module.Baer R Q) {y : N} (r : R) (eq1 : r • y = 0) : ExtensionOfMaxAdjoin.extendIdealTo i f h y r = 0 := by have : r ∈ ideal i f y := by change (r • y) ∈ (extensionOfMax i f).toLinearPMap.domain rw [eq1] apply Submodule.zero_mem _ rw [ExtensionOfMaxAdjoin.extendIdealTo_is_extension i f h y r this] dsimp [ExtensionOfMaxAdjoin.idealTo] simp only [LinearMap.coe_mk, eq1, Subtype.coe_mk, ← ZeroMemClass.zero_def, (extensionOfMax i f).toLinearPMap.map_zero] theorem ExtensionOfMaxAdjoin.extendIdealTo_wd (h : Module.Baer R Q) {y : N} (r r' : R) (eq1 : r • y = r' • y) : ExtensionOfMaxAdjoin.extendIdealTo i f h y r = ExtensionOfMaxAdjoin.extendIdealTo i f h y r' := by rw [← sub_eq_zero, ← map_sub] convert ExtensionOfMaxAdjoin.extendIdealTo_wd' i f h (r - r') _ rw [sub_smul, sub_eq_zero, eq1] theorem ExtensionOfMaxAdjoin.extendIdealTo_eq (h : Module.Baer R Q) {y : N} (r : R) (hr : r • y ∈ (extensionOfMax i f).domain) : ExtensionOfMaxAdjoin.extendIdealTo i f h y r = (extensionOfMax i f).toLinearPMap ⟨r • y, hr⟩ := by simp only [ExtensionOfMaxAdjoin.extendIdealTo_is_extension i f h _ _ hr, ExtensionOfMaxAdjoin.idealTo, LinearMap.coe_mk, Subtype.coe_mk, AddHom.coe_mk] /-- We can finally define a linear map `M ⊔ ⟨y⟩ ⟶ Q` by `x + r • y ↦ f x + φ r` -/ def ExtensionOfMaxAdjoin.extensionToFun (h : Module.Baer R Q) {y : N} : supExtensionOfMaxSingleton i f y → Q := fun x => (extensionOfMax i f).toLinearPMap (ExtensionOfMaxAdjoin.fst i x) + ExtensionOfMaxAdjoin.extendIdealTo i f h y (ExtensionOfMaxAdjoin.snd i x) theorem ExtensionOfMaxAdjoin.extensionToFun_wd (h : Module.Baer R Q) {y : N} (x : supExtensionOfMaxSingleton i f y) (a : (extensionOfMax i f).domain) (r : R) (eq1 : ↑x = ↑a + r • y) : ExtensionOfMaxAdjoin.extensionToFun i f h x = (extensionOfMax i f).toLinearPMap a + ExtensionOfMaxAdjoin.extendIdealTo i f h y r := by obtain ⟨a, ha⟩ := a have eq2 : (ExtensionOfMaxAdjoin.fst i x - a : N) = (r - ExtensionOfMaxAdjoin.snd i x) • y := by change x = a + r • y at eq1 rwa [ExtensionOfMaxAdjoin.eqn, ← sub_eq_zero, ← sub_sub_sub_eq, sub_eq_zero, ← sub_smul] at eq1 have eq3 := ExtensionOfMaxAdjoin.extendIdealTo_eq i f h (r - ExtensionOfMaxAdjoin.snd i x) (by rw [← eq2]; exact Submodule.sub_mem _ (ExtensionOfMaxAdjoin.fst i x).2 ha) simp only [map_sub, sub_smul, sub_eq_iff_eq_add] at eq3 unfold ExtensionOfMaxAdjoin.extensionToFun rw [eq3, ← add_assoc, ← (extensionOfMax i f).toLinearPMap.map_add, AddMemClass.mk_add_mk] congr ext dsimp rw [Subtype.coe_mk, add_sub, ← eq1] exact eq_sub_of_add_eq (ExtensionOfMaxAdjoin.eqn i x).symm /-- The linear map `M ⊔ ⟨y⟩ ⟶ Q` by `x + r • y ↦ f x + φ r` is an extension of `f` -/ def extensionOfMaxAdjoin (h : Module.Baer R Q) (y : N) : ExtensionOf i f where domain := supExtensionOfMaxSingleton i f y -- (extensionOfMax i f).domain ⊔ Submodule.span R {y} le := le_trans (extensionOfMax i f).le le_sup_left toFun := { toFun := ExtensionOfMaxAdjoin.extensionToFun i f h map_add' := fun a b => by have eq1 : ↑a + ↑b = ↑(ExtensionOfMaxAdjoin.fst i a + ExtensionOfMaxAdjoin.fst i b) + (ExtensionOfMaxAdjoin.snd i a + ExtensionOfMaxAdjoin.snd i b) • y := by rw [ExtensionOfMaxAdjoin.eqn, ExtensionOfMaxAdjoin.eqn, add_smul, Submodule.coe_add] ac_rfl rw [ExtensionOfMaxAdjoin.extensionToFun_wd (y := y) i f h (a + b) _ _ eq1, LinearPMap.map_add, map_add] unfold ExtensionOfMaxAdjoin.extensionToFun abel map_smul' := fun r a => by dsimp have eq1 : r • (a : N) = ↑(r • ExtensionOfMaxAdjoin.fst i a) + (r • ExtensionOfMaxAdjoin.snd i a) • y := by rw [ExtensionOfMaxAdjoin.eqn, smul_add, smul_eq_mul, mul_smul] rfl rw [ExtensionOfMaxAdjoin.extensionToFun_wd i f h (r • a :) _ _ eq1, LinearMap.map_smul, LinearPMap.map_smul, ← smul_add] congr } is_extension m := by dsimp rw [(extensionOfMax i f).is_extension, ExtensionOfMaxAdjoin.extensionToFun_wd i f h _ ⟨i m, _⟩ 0 _, map_zero, add_zero] simp theorem extensionOfMax_le (h : Module.Baer R Q) {y : N} : extensionOfMax i f ≤ extensionOfMaxAdjoin i f h y := ⟨le_sup_left, fun x x' EQ => by symm change ExtensionOfMaxAdjoin.extensionToFun i f h _ = _ rw [ExtensionOfMaxAdjoin.extensionToFun_wd i f h x' x 0 (by simp [EQ]), map_zero, add_zero]⟩ theorem extensionOfMax_to_submodule_eq_top (h : Module.Baer R Q) : (extensionOfMax i f).domain = ⊤ := by refine Submodule.eq_top_iff'.mpr fun y => ?_ dsimp rw [← extensionOfMax_is_max i f _ (extensionOfMax_le i f h), extensionOfMaxAdjoin, Submodule.mem_sup] exact ⟨0, Submodule.zero_mem _, y, Submodule.mem_span_singleton_self _, zero_add _⟩ protected theorem extension_property (h : Module.Baer R Q) (f : M →ₗ[R] N) (hf : Function.Injective f) (g : M →ₗ[R] Q) : ∃ h, h ∘ₗ f = g := haveI : Fact (Function.Injective f) := ⟨hf⟩ Exists.intro { toFun := ((extensionOfMax f g).toLinearPMap ⟨·, (extensionOfMax_to_submodule_eq_top f g h).symm ▸ ⟨⟩⟩) map_add' := fun x y ↦ by rw [← LinearPMap.map_add]; congr map_smul' := fun r x ↦ by rw [← LinearPMap.map_smul]; dsimp } <| LinearMap.ext fun x ↦ ((extensionOfMax f g).is_extension x).symm theorem extension_property_addMonoidHom (h : Module.Baer ℤ Q) (f : M →+ N) (hf : Function.Injective f) (g : M →+ Q) : ∃ h : N →+ Q, h.comp f = g := have ⟨g', hg'⟩ := h.extension_property f.toIntLinearMap hf g.toIntLinearMap ⟨g', congr(LinearMap.toAddMonoidHom $hg')⟩ /-- **Baer's criterion** for injective module : a Baer module is an injective module, i.e. if every linear map from an ideal can be extended, then the module is injective. -/ protected theorem injective (h : Module.Baer R Q) : Module.Injective R Q where out X Y _ _ _ _ i hi f := by obtain ⟨h, H⟩ := Module.Baer.extension_property h i hi f exact ⟨h, DFunLike.congr_fun H⟩ protected theorem of_injective [Small.{v} R] (inj : Module.Injective R Q) : Module.Baer R Q := by intro I g let eI := Shrink.linearEquiv I R let eR := Shrink.linearEquiv R R obtain ⟨g', hg'⟩ := Module.Injective.out (eR.symm.toLinearMap ∘ₗ I.subtype ∘ₗ eI.toLinearMap) (eR.symm.injective.comp <| Subtype.val_injective.comp eI.injective) (g ∘ₗ eI.toLinearMap) exact ⟨g' ∘ₗ eR.symm.toLinearMap, fun x mx ↦ by simpa [eI, eR] using hg' (equivShrink I ⟨x, mx⟩)⟩ protected theorem iff_injective [Small.{v} R] : Module.Baer R Q ↔ Module.Injective R Q := ⟨Module.Baer.injective, Module.Baer.of_injective⟩ end Module.Baer section ULift variable {M : Type v} [AddCommGroup M] [Module R M] lemma Module.ulift_injective_of_injective [Small.{v} R] (inj : Module.Injective R M) : Module.Injective R (ULift.{v'} M) := Module.Baer.injective fun I g ↦ have ⟨g', hg'⟩ := Module.Baer.iff_injective.mpr inj I (ULift.moduleEquiv.toLinearMap ∘ₗ g) ⟨ULift.moduleEquiv.symm.toLinearMap ∘ₗ g', fun r hr ↦ ULift.ext _ _ <| hg' r hr⟩ lemma Module.injective_of_ulift_injective (inj : Module.Injective R (ULift.{v'} M)) : Module.Injective R M where out X Y _ _ _ _ f hf g := let eX := ULift.moduleEquiv.{_,_,v'} (R := R) (M := X) have ⟨g', hg'⟩ := inj.out (ULift.moduleEquiv.{_,_,v'}.symm.toLinearMap ∘ₗ f ∘ₗ eX.toLinearMap) (by exact ULift.moduleEquiv.symm.injective.comp <| hf.comp eX.injective) (ULift.moduleEquiv.symm.toLinearMap ∘ₗ g ∘ₗ eX.toLinearMap) ⟨ULift.moduleEquiv.toLinearMap ∘ₗ g' ∘ₗ ULift.moduleEquiv.symm.toLinearMap, fun x ↦ by exact congr(ULift.down $(hg' ⟨x⟩))⟩ variable (M) [Small.{v} R] lemma Module.injective_iff_ulift_injective : Module.Injective R M ↔ Module.Injective R (ULift.{v'} M) := ⟨Module.ulift_injective_of_injective R, Module.injective_of_ulift_injective R⟩ end ULift section lifting_property universe uR uM uP uP' variable (R : Type uR) [Ring R] [Small.{uM} R] variable (M : Type uM) [AddCommGroup M] [Module R M] [inj : Module.Injective R M] variable (P : Type uP) [AddCommGroup P] [Module R P] variable (P' : Type uP') [AddCommGroup P'] [Module R P'] lemma Module.Injective.extension_property (f : P →ₗ[R] P') (hf : Function.Injective f) (g : P →ₗ[R] M) : ∃ h : P' →ₗ[R] M, h ∘ₗ f = g := (Module.Baer.of_injective inj).extension_property f hf g end lifting_property
Mathlib/Algebra/Module/Injective.lean
486
495
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Aaron Anderson, Yakov Pechersky -/ import Mathlib.Data.Fintype.Card import Mathlib.Algebra.Group.Commute.Basic import Mathlib.Algebra.Group.End import Mathlib.Data.Finset.NoncommProd /-! # support of a permutation ## Main definitions In the following, `f g : Equiv.Perm α`. * `Equiv.Perm.Disjoint`: two permutations `f` and `g` are `Disjoint` if every element is fixed either by `f`, or by `g`. Equivalently, `f` and `g` are `Disjoint` iff their `support` are disjoint. * `Equiv.Perm.IsSwap`: `f = swap x y` for `x ≠ y`. * `Equiv.Perm.support`: the elements `x : α` that are not fixed by `f`. Assume `α` is a Fintype: * `Equiv.Perm.fixed_point_card_lt_of_ne_one f` says that `f` has strictly less than `Fintype.card α - 1` fixed points, unless `f = 1`. (Equivalently, `f.support` has at least 2 elements.) -/ open Equiv Finset Function namespace Equiv.Perm variable {α : Type*} section Disjoint /-- Two permutations `f` and `g` are `Disjoint` if their supports are disjoint, i.e., every element is fixed either by `f`, or by `g`. -/ def Disjoint (f g : Perm α) := ∀ x, f x = x ∨ g x = x variable {f g h : Perm α} @[symm] theorem Disjoint.symm : Disjoint f g → Disjoint g f := by simp only [Disjoint, or_comm, imp_self] theorem Disjoint.symmetric : Symmetric (@Disjoint α) := fun _ _ => Disjoint.symm instance : IsSymm (Perm α) Disjoint := ⟨Disjoint.symmetric⟩ theorem disjoint_comm : Disjoint f g ↔ Disjoint g f := ⟨Disjoint.symm, Disjoint.symm⟩ theorem Disjoint.commute (h : Disjoint f g) : Commute f g := Equiv.ext fun x => (h x).elim (fun hf => (h (g x)).elim (fun hg => by simp [mul_apply, hf, hg]) fun hg => by simp [mul_apply, hf, g.injective hg]) fun hg => (h (f x)).elim (fun hf => by simp [mul_apply, f.injective hf, hg]) fun hf => by simp [mul_apply, hf, hg] @[simp] theorem disjoint_one_left (f : Perm α) : Disjoint 1 f := fun _ => Or.inl rfl @[simp] theorem disjoint_one_right (f : Perm α) : Disjoint f 1 := fun _ => Or.inr rfl theorem disjoint_iff_eq_or_eq : Disjoint f g ↔ ∀ x : α, f x = x ∨ g x = x := Iff.rfl @[simp] theorem disjoint_refl_iff : Disjoint f f ↔ f = 1 := by refine ⟨fun h => ?_, fun h => h.symm ▸ disjoint_one_left 1⟩ ext x rcases h x with hx | hx <;> simp [hx] theorem Disjoint.inv_left (h : Disjoint f g) : Disjoint f⁻¹ g := by intro x rw [inv_eq_iff_eq, eq_comm] exact h x theorem Disjoint.inv_right (h : Disjoint f g) : Disjoint f g⁻¹ := h.symm.inv_left.symm @[simp] theorem disjoint_inv_left_iff : Disjoint f⁻¹ g ↔ Disjoint f g := by refine ⟨fun h => ?_, Disjoint.inv_left⟩ convert h.inv_left @[simp] theorem disjoint_inv_right_iff : Disjoint f g⁻¹ ↔ Disjoint f g := by rw [disjoint_comm, disjoint_inv_left_iff, disjoint_comm] theorem Disjoint.mul_left (H1 : Disjoint f h) (H2 : Disjoint g h) : Disjoint (f * g) h := fun x => by cases H1 x <;> cases H2 x <;> simp [*] theorem Disjoint.mul_right (H1 : Disjoint f g) (H2 : Disjoint f h) : Disjoint f (g * h) := by rw [disjoint_comm] exact H1.symm.mul_left H2.symm -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: make it `@[simp]` theorem disjoint_conj (h : Perm α) : Disjoint (h * f * h⁻¹) (h * g * h⁻¹) ↔ Disjoint f g := (h⁻¹).forall_congr fun {_} ↦ by simp only [mul_apply, eq_inv_iff_eq] theorem Disjoint.conj (H : Disjoint f g) (h : Perm α) : Disjoint (h * f * h⁻¹) (h * g * h⁻¹) := (disjoint_conj h).2 H theorem disjoint_prod_right (l : List (Perm α)) (h : ∀ g ∈ l, Disjoint f g) : Disjoint f l.prod := by induction' l with g l ih · exact disjoint_one_right _ · rw [List.prod_cons] exact (h _ List.mem_cons_self).mul_right (ih fun g hg => h g (List.mem_cons_of_mem _ hg)) theorem disjoint_noncommProd_right {ι : Type*} {k : ι → Perm α} {s : Finset ι} (hs : Set.Pairwise s fun i j ↦ Commute (k i) (k j)) (hg : ∀ i ∈ s, g.Disjoint (k i)) :
Disjoint g (s.noncommProd k (hs)) := noncommProd_induction s k hs g.Disjoint (fun _ _ ↦ Disjoint.mul_right) (disjoint_one_right g) hg
Mathlib/GroupTheory/Perm/Support.lean
124
125
/- 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]
Mathlib/Analysis/SpecialFunctions/Log/Basic.lean
114
115
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.Group.Units.Hom import Mathlib.Algebra.GroupWithZero.Commute import Mathlib.Algebra.GroupWithZero.Hom import Mathlib.Tactic.MinImports /-! # Further lemmas about units in a `MonoidWithZero` or a `GroupWithZero`. -/ assert_not_exists DenselyOrdered MulAction variable {M M₀ G₀ M₀' G₀' F F' : Type*} variable [MonoidWithZero M₀] section Monoid variable [Monoid M] [GroupWithZero G₀] lemma isLocalHom_of_exists_map_ne_one [FunLike F G₀ M] [MonoidHomClass F G₀ M] {f : F} (hf : ∃ x : G₀, f x ≠ 1) : IsLocalHom f where map_nonunit a h := by rcases eq_or_ne a 0 with (rfl | h) · obtain ⟨t, ht⟩ := hf refine (ht ?_).elim have := map_mul f t 0 rw [← one_mul (f (t * 0)), mul_zero] at this exact (h.mul_right_cancel this).symm · exact ⟨⟨a, a⁻¹, mul_inv_cancel₀ h, inv_mul_cancel₀ h⟩, rfl⟩ instance [GroupWithZero G₀] [FunLike F G₀ M₀] [MonoidWithZeroHomClass F G₀ M₀] [Nontrivial M₀] (f : F) : IsLocalHom f := isLocalHom_of_exists_map_ne_one ⟨0, by simp⟩ end Monoid section GroupWithZero namespace Commute variable [GroupWithZero G₀] {a b c d : G₀} /-- The `MonoidWithZero` version of `div_eq_div_iff_mul_eq_mul`. -/ protected lemma div_eq_div_iff (hbd : Commute b d) (hb : b ≠ 0) (hd : d ≠ 0) : a / b = c / d ↔ a * d = c * b := hbd.div_eq_div_iff_of_isUnit hb.isUnit hd.isUnit end Commute section MonoidWithZero variable [GroupWithZero G₀] [Nontrivial M₀] [MonoidWithZero M₀'] [FunLike F G₀ M₀] [MonoidWithZeroHomClass F G₀ M₀] [FunLike F' G₀ M₀'] (f : F) {a : G₀} theorem map_ne_zero : f a ≠ 0 ↔ a ≠ 0 := ⟨fun hfa ha => hfa <| ha.symm ▸ map_zero f, fun ha => ((IsUnit.mk0 a ha).map f).ne_zero⟩
@[simp] theorem map_eq_zero : f a = 0 ↔ a = 0 := not_iff_not.1 (map_ne_zero f) theorem eq_on_inv₀ [MonoidWithZeroHomClass F' G₀ M₀'] (f g : F') (h : f a = g a) :
Mathlib/Algebra/GroupWithZero/Units/Lemmas.lean
64
68
/- Copyright (c) 2024 David Kurniadi Angdinata. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Kurniadi Angdinata -/ import Mathlib.Data.Nat.EvenOddRec import Mathlib.Tactic.Linarith import Mathlib.Tactic.LinearCombination /-! # Elliptic divisibility sequences This file defines the type of an elliptic divisibility sequence (EDS) and a few examples. ## Mathematical background Let `R` be a commutative ring. An elliptic sequence is a sequence `W : ℤ → R` satisfying `W(m + n)W(m - n)W(r)² = W(m + r)W(m - r)W(n)² - W(n + r)W(n - r)W(m)²` for any `m, n, r ∈ ℤ`. A divisibility sequence is a sequence `W : ℤ → R` satisfying `W(m) ∣ W(n)` for any `m, n ∈ ℤ` such that `m ∣ n`. An elliptic divisibility sequence is simply a divisibility sequence that is elliptic. Some examples of EDSs include * the identity sequence, * certain terms of Lucas sequences, and * division polynomials of elliptic curves. ## Main definitions * `IsEllSequence`: a sequence indexed by integers is an elliptic sequence. * `IsDivSequence`: a sequence indexed by integers is a divisibility sequence. * `IsEllDivSequence`: a sequence indexed by integers is an EDS. * `preNormEDS'`: the auxiliary sequence for a normalised EDS indexed by `ℕ`. * `preNormEDS`: the auxiliary sequence for a normalised EDS indexed by `ℤ`. * `normEDS`: the canonical example of a normalised EDS indexed by `ℤ`. ## Main statements * TODO: prove that `normEDS` satisfies `IsEllDivSequence`. * TODO: prove that a normalised sequence satisfying `IsEllDivSequence` can be given by `normEDS`. ## Implementation notes The normalised EDS `normEDS b c d n` is defined in terms of the auxiliary sequence `preNormEDS (b ^ 4) c d n`, which are equal when `n` is odd, and which differ by a factor of `b` when `n` is even. This coincides with the definition in the references since both agree for `normEDS b c d 2` and for `normEDS b c d 4`, and the correct factors of `b` are removed in `normEDS b c d (2 * (m + 2) + 1)` and in `normEDS b c d (2 * (m + 3))`. One reason is to avoid the necessity for ring division by `b` in the inductive definition of `normEDS b c d (2 * (m + 3))`. The idea is that, it can be shown that `normEDS b c d (2 * (m + 3))` always contains a factor of `b`, so it is possible to remove a factor of `b` *a posteriori*, but stating this lemma requires first defining `normEDS b c d (2 * (m + 3))`, which requires having this factor of `b` *a priori*. Another reason is to allow the definition of univariate `n`-division polynomials of elliptic curves, omitting a factor of the bivariate `2`-division polynomial. ## References M Ward, *Memoir on Elliptic Divisibility Sequences* ## Tags elliptic, divisibility, sequence -/ universe u v variable {R : Type u} [CommRing R] section IsEllDivSequence variable (W : ℤ → R) /-- The proposition that a sequence indexed by integers is an elliptic sequence. -/ def IsEllSequence : Prop := ∀ m n r : ℤ, W (m + n) * W (m - n) * W r ^ 2 = W (m + r) * W (m - r) * W n ^ 2 - W (n + r) * W (n - r) * W m ^ 2 /-- The proposition that a sequence indexed by integers is a divisibility sequence. -/ def IsDivSequence : Prop := ∀ m n : ℕ, m ∣ n → W m ∣ W n /-- The proposition that a sequence indexed by integers is an EDS. -/ def IsEllDivSequence : Prop := IsEllSequence W ∧ IsDivSequence W lemma isEllSequence_id : IsEllSequence id := fun _ _ _ => by simp only [id_eq]; ring1 lemma isDivSequence_id : IsDivSequence id := fun _ _ => Int.ofNat_dvd.mpr /-- The identity sequence is an EDS. -/ theorem isEllDivSequence_id : IsEllDivSequence id := ⟨isEllSequence_id, isDivSequence_id⟩ variable {W} lemma IsEllSequence.smul (h : IsEllSequence W) (x : R) : IsEllSequence (x • W) := fun m n r => by linear_combination (norm := (simp only [Pi.smul_apply, smul_eq_mul]; ring1)) x ^ 4 * h m n r lemma IsDivSequence.smul (h : IsDivSequence W) (x : R) : IsDivSequence (x • W) := fun m n r => mul_dvd_mul_left x <| h m n r lemma IsEllDivSequence.smul (h : IsEllDivSequence W) (x : R) : IsEllDivSequence (x • W) := ⟨h.left.smul x, h.right.smul x⟩ end IsEllDivSequence /-- Strong recursion principle for a normalised EDS: if we have * `P 0`, `P 1`, `P 2`, `P 3`, and `P 4`, * for all `m : ℕ` we can prove `P (2 * (m + 3))` from `P k` for all `k < 2 * (m + 3)`, and * for all `m : ℕ` we can prove `P (2 * (m + 2) + 1)` from `P k` for all `k < 2 * (m + 2) + 1`, then we have `P n` for all `n : ℕ`. -/ @[elab_as_elim] noncomputable def normEDSRec' {P : ℕ → Sort u} (zero : P 0) (one : P 1) (two : P 2) (three : P 3) (four : P 4) (even : ∀ m : ℕ, (∀ k < 2 * (m + 3), P k) → P (2 * (m + 3))) (odd : ∀ m : ℕ, (∀ k < 2 * (m + 2) + 1, P k) → P (2 * (m + 2) + 1)) (n : ℕ) : P n := n.evenOddStrongRec (by rintro (_ | _ | _ | _) h; exacts [zero, two, four, even _ h]) (by rintro (_ | _ | _) h; exacts [one, three, odd _ h]) /-- Recursion principle for a normalised EDS: if we have * `P 0`, `P 1`, `P 2`, `P 3`, and `P 4`, * for all `m : ℕ` we can prove `P (2 * (m + 3))` from `P (m + 1)`, `P (m + 2)`, `P (m + 3)`, `P (m + 4)`, and `P (m + 5)`, and * for all `m : ℕ` we can prove `P (2 * (m + 2) + 1)` from `P (m + 1)`, `P (m + 2)`, `P (m + 3)`, and `P (m + 4)`, then we have `P n` for all `n : ℕ`. -/ @[elab_as_elim] noncomputable def normEDSRec {P : ℕ → Sort u} (zero : P 0) (one : P 1) (two : P 2) (three : P 3) (four : P 4) (even : ∀ m : ℕ, P (m + 1) → P (m + 2) → P (m + 3) → P (m + 4) → P (m + 5) → P (2 * (m + 3))) (odd : ∀ m : ℕ, P (m + 1) → P (m + 2) → P (m + 3) → P (m + 4) → P (2 * (m + 2) + 1)) (n : ℕ) : P n := normEDSRec' zero one two three four (fun _ ih => by apply even <;> exact ih _ <| by linarith only) (fun _ ih => by apply odd <;> exact ih _ <| by linarith only) n variable (b c d : R) section PreNormEDS /-- The auxiliary sequence for a normalised EDS `W : ℕ → R`, with initial values `W(0) = 0`, `W(1) = 1`, `W(2) = 1`, `W(3) = c`, and `W(4) = d` and extra parameter `b`. -/ def preNormEDS' (b c d : R) : ℕ → R | 0 => 0 | 1 => 1 | 2 => 1 | 3 => c | 4 => d | (n + 5) => let m := n / 2 have h4 : m + 4 < n + 5 := Nat.lt_succ.mpr <| add_le_add_right (n.div_le_self 2) 4 have h3 : m + 3 < n + 5 := (lt_add_one _).trans h4 have h2 : m + 2 < n + 5 := (lt_add_one _).trans h3 have _ : m + 1 < n + 5 := (lt_add_one _).trans h2 if hn : Even n then preNormEDS' b c d (m + 4) * preNormEDS' b c d (m + 2) ^ 3 * (if Even m then b else 1) - preNormEDS' b c d (m + 1) * preNormEDS' b c d (m + 3) ^ 3 * (if Even m then 1 else b) else have _ : m + 5 < n + 5 := add_lt_add_right (Nat.div_lt_self (Nat.not_even_iff_odd.1 hn).pos <| Nat.lt_succ_self 1) 5 preNormEDS' b c d (m + 2) ^ 2 * preNormEDS' b c d (m + 3) * preNormEDS' b c d (m + 5) - preNormEDS' b c d (m + 1) * preNormEDS' b c d (m + 3) * preNormEDS' b c d (m + 4) ^ 2 @[simp] lemma preNormEDS'_zero : preNormEDS' b c d 0 = 0 := by rw [preNormEDS'] @[simp] lemma preNormEDS'_one : preNormEDS' b c d 1 = 1 := by rw [preNormEDS'] @[simp] lemma preNormEDS'_two : preNormEDS' b c d 2 = 1 := by rw [preNormEDS'] @[simp] lemma preNormEDS'_three : preNormEDS' b c d 3 = c := by rw [preNormEDS'] @[simp] lemma preNormEDS'_four : preNormEDS' b c d 4 = d := by rw [preNormEDS'] lemma preNormEDS'_odd (m : ℕ) : preNormEDS' b c d (2 * (m + 2) + 1) = preNormEDS' b c d (m + 4) * preNormEDS' b c d (m + 2) ^ 3 * (if Even m then b else 1) - preNormEDS' b c d (m + 1) * preNormEDS' b c d (m + 3) ^ 3 * (if Even m then 1 else b) := by rw [show 2 * (m + 2) + 1 = 2 * m + 5 by rfl, preNormEDS', dif_pos <| even_two_mul _] simp only [m.mul_div_cancel_left two_pos] lemma preNormEDS'_even (m : ℕ) : preNormEDS' b c d (2 * (m + 3)) = preNormEDS' b c d (m + 2) ^ 2 * preNormEDS' b c d (m + 3) * preNormEDS' b c d (m + 5) - preNormEDS' b c d (m + 1) * preNormEDS' b c d (m + 3) * preNormEDS' b c d (m + 4) ^ 2 := by rw [show 2 * (m + 3) = 2 * m + 1 + 5 by rfl, preNormEDS', dif_neg m.not_even_two_mul_add_one] simp only [Nat.mul_add_div two_pos] rfl /-- The auxiliary sequence for a normalised EDS `W : ℤ → R`, with initial values `W(0) = 0`, `W(1) = 1`, `W(2) = 1`, `W(3) = c`, and `W(4) = d` and extra parameter `b`. This extends `preNormEDS'` by defining its values at negative integers. -/ def preNormEDS (n : ℤ) : R := n.sign * preNormEDS' b c d n.natAbs @[simp] lemma preNormEDS_ofNat (n : ℕ) : preNormEDS b c d n = preNormEDS' b c d n := by by_cases hn : n = 0 · rw [hn, preNormEDS, Nat.cast_zero, Int.sign_zero, Int.cast_zero, zero_mul, preNormEDS'_zero] · rw [preNormEDS, Int.sign_natCast_of_ne_zero hn, Int.cast_one, one_mul, Int.natAbs_cast] @[simp] lemma preNormEDS_zero : preNormEDS b c d 0 = 0 := by rw [← Nat.cast_zero, preNormEDS_ofNat, preNormEDS'_zero] @[simp] lemma preNormEDS_one : preNormEDS b c d 1 = 1 := by rw [← Nat.cast_one, preNormEDS_ofNat, preNormEDS'_one] @[simp] lemma preNormEDS_two : preNormEDS b c d 2 = 1 := by rw [← Nat.cast_two, preNormEDS_ofNat, preNormEDS'_two] @[simp] lemma preNormEDS_three : preNormEDS b c d 3 = c := by rw [← Nat.cast_three, preNormEDS_ofNat, preNormEDS'_three] @[simp] lemma preNormEDS_four : preNormEDS b c d 4 = d := by rw [← Nat.cast_four, preNormEDS_ofNat, preNormEDS'_four] lemma preNormEDS_even_ofNat (m : ℕ) : preNormEDS b c d (2 * (m + 3)) = preNormEDS b c d (m + 2) ^ 2 * preNormEDS b c d (m + 3) * preNormEDS b c d (m + 5) - preNormEDS b c d (m + 1) * preNormEDS b c d (m + 3) * preNormEDS b c d (m + 4) ^ 2 := by norm_cast simp only [preNormEDS_ofNat] exact preNormEDS'_even ..
lemma preNormEDS_odd_ofNat (m : ℕ) : preNormEDS b c d (2 * (m + 2) + 1) = preNormEDS b c d (m + 4) * preNormEDS b c d (m + 2) ^ 3 * (if Even m then b else 1) - preNormEDS b c d (m + 1) * preNormEDS b c d (m + 3) ^ 3 * (if Even m then 1 else b) := by
Mathlib/NumberTheory/EllipticDivisibilitySequence.lean
239
241
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Analytic.Uniqueness import Mathlib.Analysis.Calculus.DiffContOnCl import Mathlib.Analysis.Calculus.DSlope import Mathlib.Analysis.Calculus.FDeriv.Analytic import Mathlib.Analysis.Complex.ReImTopology import Mathlib.Data.Real.Cardinality import Mathlib.MeasureTheory.Integral.CircleIntegral import Mathlib.MeasureTheory.Integral.DivergenceTheorem import Mathlib.MeasureTheory.Measure.Lebesgue.Complex /-! # Cauchy integral formula In this file we prove the Cauchy-Goursat theorem and the Cauchy integral formula for integrals over circles. Most results are formulated for a function `f : ℂ → E` that takes values in a complex Banach space with second countable topology. ## Main statements In the following theorems, if the name ends with `off_countable`, then the actual theorem assumes differentiability at all but countably many points of the set mentioned below. * `Complex.integral_boundary_rect_of_hasFDerivAt_real_off_countable`: If a function `f : ℂ → E` is continuous on a closed rectangle and *real* differentiable on its interior, then its integral over the boundary of this rectangle is equal to the integral of `I • f' (x + y * I) 1 - f' (x + y * I) I` over the rectangle, where `f' z w : E` is the derivative of `f` at `z` in the direction `w` and `I = Complex.I` is the imaginary unit. * `Complex.integral_boundary_rect_eq_zero_of_differentiable_on_off_countable`: If a function `f : ℂ → E` is continuous on a closed rectangle and is *complex* differentiable on its interior, then its integral over the boundary of this rectangle is equal to zero. * `Complex.circleIntegral_sub_center_inv_smul_eq_of_differentiable_on_annulus_off_countable`: If a function `f : ℂ → E` is continuous on a closed annulus `{z | r ≤ |z - c| ≤ R}` and is complex differentiable on its interior `{z | r < |z - c| < R}`, then the integrals of `(z - c)⁻¹ • f z` over the outer boundary and over the inner boundary are equal. * `Complex.circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable_of_tendsto`, `Complex.circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable`: If a function `f : ℂ → E` is continuous on a punctured closed disc `{z | |z - c| ≤ R ∧ z ≠ c}`, is complex differentiable on the corresponding punctured open disc, and tends to `y` as `z → c`, `z ≠ c`, then the integral of `(z - c)⁻¹ • f z` over the circle `|z - c| = R` is equal to `2πiy`. In particular, if `f` is continuous on the whole closed disc and is complex differentiable on the corresponding open disc, then this integral is equal to `2πif(c)`. * `Complex.circleIntegral_sub_inv_smul_of_differentiable_on_off_countable`, `Complex.two_pi_I_inv_smul_circleIntegral_sub_inv_smul_of_differentiable_on_off_countable` **Cauchy integral formula**: if `f : ℂ → E` is continuous on a closed disc of radius `R` and is complex differentiable on the corresponding open disc, then for any `w` in the corresponding open disc the integral of `(z - w)⁻¹ • f z` over the boundary of the disc is equal to `2πif(w)`. Two versions of the lemma put the multiplier `2πi` at the different sides of the equality. * `Complex.hasFPowerSeriesOnBall_of_differentiable_off_countable`: If `f : ℂ → E` is continuous on a closed disc of positive radius and is complex differentiable on the corresponding open disc, then it is analytic on the corresponding open disc, and the coefficients of the power series are given by Cauchy integral formulas. * `DifferentiableOn.hasFPowerSeriesOnBall`: If `f : ℂ → E` is complex differentiable on a closed disc of positive radius, then it is analytic on the corresponding open disc, and the coefficients of the power series are given by Cauchy integral formulas. * `DifferentiableOn.analyticAt`, `Differentiable.analyticAt`: If `f : ℂ → E` is differentiable on a neighborhood of a point, then it is analytic at this point. In particular, if `f : ℂ → E` is differentiable on the whole `ℂ`, then it is analytic at every point `z : ℂ`. * `Differentiable.hasFPowerSeriesOnBall`: If `f : ℂ → E` is differentiable everywhere then the `cauchyPowerSeries f z R` is a formal power series representing `f` at `z` with infinite radius of convergence (this holds for any choice of `0 < R`). ## Implementation details The proof of the Cauchy integral formula in this file is based on a very general version of the divergence theorem, see `MeasureTheory.integral_divergence_of_hasFDerivWithinAt_off_countable` (a version for functions defined on `Fin (n + 1) → ℝ`), `MeasureTheory.integral_divergence_prod_Icc_of_hasFDerivWithinAt_off_countable_of_le`, and `MeasureTheory.integral2_divergence_prod_of_hasFDerivWithinAt_off_countable` (versions for functions defined on `ℝ × ℝ`). Usually, the divergence theorem is formulated for a $C^1$ smooth function. The theorems formulated above deal with a function that is * continuous on a closed box/rectangle; * differentiable at all but countably many points of its interior; * have divergence integrable over the closed box/rectangle. First, we reformulate the theorem for a *real*-differentiable map `ℂ → E`, and relate the integral of `f` over the boundary of a rectangle in `ℂ` to the integral of the derivative $\frac{\partial f}{\partial \bar z}$ over the interior of this box. In particular, for a *complex* differentiable function, the latter derivative is zero, hence the integral over the boundary of a rectangle is zero. Thus we get the Cauchy-Goursat theorem for a rectangle in `ℂ`. Next, we apply this theorem to the function $F(z)=f(c+e^{z})$ on the rectangle $[\ln r, \ln R]\times [0, 2\pi]$ to prove that $$ \oint_{|z-c|=r}\frac{f(z)\,dz}{z-c}=\oint_{|z-c|=R}\frac{f(z)\,dz}{z-c} $$ provided that `f` is continuous on the closed annulus `r ≤ |z - c| ≤ R` and is complex differentiable on its interior `r < |z - c| < R` (possibly, at all but countably many points). Here and below, we write $\frac{f(z)}{z-c}$ in the documentation while the actual lemmas use `(z - c)⁻¹ • f z` because `f z` belongs to some Banach space over `ℂ` and `f z / (z - c)` is undefined. Taking the limit of this equality as `r` tends to `𝓝[>] 0`, we prove $$ \oint_{|z-c|=R}\frac{f(z)\,dz}{z-c}=2\pi if(c) $$ provided that `f` is continuous on the closed disc `|z - c| ≤ R` and is differentiable at all but countably many points of its interior. This is the Cauchy integral formula for the center of a circle. In particular, if we apply this function to `F z = (z - c) • f z`, then we get $$ \oint_{|z-c|=R} f(z)\,dz=0. $$ In order to deduce the Cauchy integral formula for any point `w`, `|w - c| < R`, we consider the slope function `g : ℂ → E` given by `g z = (z - w)⁻¹ • (f z - f w)` if `z ≠ w` and `g w = f' w`. This function satisfies assumptions of the previous theorem, so we have $$ \oint_{|z-c|=R} \frac{f(z)\,dz}{z-w}=\oint_{|z-c|=R} \frac{f(w)\,dz}{z-w}= \left(\oint_{|z-c|=R} \frac{dz}{z-w}\right)f(w). $$ The latter integral was computed in `circleIntegral.integral_sub_inv_of_mem_ball` and is equal to `2 * π * Complex.I`. There is one more step in the actual proof. Since we allow `f` to be non-differentiable on a countable set `s`, we cannot immediately claim that `g` is continuous at `w` if `w ∈ s`. So, we use the proof outlined in the previous paragraph for `w ∉ s` (see `Complex.circleIntegral_sub_inv_smul_of_differentiable_on_off_countable_aux`), then use continuity of both sides of the formula and density of `sᶜ` to prove the formula for all points of the open ball, see `Complex.circleIntegral_sub_inv_smul_of_differentiable_on_off_countable`. Finally, we use the properties of the Cauchy integrals established elsewhere (see `hasFPowerSeriesOn_cauchy_integral`) and Cauchy integral formula to prove that the original function is analytic on the open ball. ## Tags Cauchy-Goursat theorem, Cauchy integral formula -/ open TopologicalSpace Set MeasureTheory intervalIntegral Metric Filter Function open scoped Interval Real NNReal ENNReal Topology noncomputable section universe u variable {E : Type u} [NormedAddCommGroup E] [NormedSpace ℂ E] namespace Complex /-- Suppose that a function `f : ℂ → E` is continuous on a closed rectangle with opposite corners at `z w : ℂ`, is *real* differentiable at all but countably many points of the corresponding open rectangle, and $\frac{\partial f}{\partial \bar z}$ is integrable on this rectangle. Then the integral of `f` over the boundary of the rectangle is equal to the integral of $2i\frac{\partial f}{\partial \bar z}=i\frac{\partial f}{\partial x}-\frac{\partial f}{\partial y}$ over the rectangle. -/ theorem integral_boundary_rect_of_hasFDerivAt_real_off_countable (f : ℂ → E) (f' : ℂ → ℂ →L[ℝ] E) (z w : ℂ) (s : Set ℂ) (hs : s.Countable) (Hc : ContinuousOn f ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) (Hd : ∀ x ∈ Ioo (min z.re w.re) (max z.re w.re) ×ℂ Ioo (min z.im w.im) (max z.im w.im) \ s, HasFDerivAt f (f' x) x) (Hi : IntegrableOn (fun z => I • f' z 1 - f' z I) ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) : (∫ x : ℝ in z.re..w.re, f (x + z.im * I)) - (∫ x : ℝ in z.re..w.re, f (x + w.im * I)) + I • (∫ y : ℝ in z.im..w.im, f (re w + y * I)) - I • ∫ y : ℝ in z.im..w.im, f (re z + y * I) = ∫ x : ℝ in z.re..w.re, ∫ y : ℝ in z.im..w.im, I • f' (x + y * I) 1 - f' (x + y * I) I := by set e : (ℝ × ℝ) ≃L[ℝ] ℂ := equivRealProdCLM.symm have he : ∀ x y : ℝ, ↑x + ↑y * I = e (x, y) := fun x y => (mk_eq_add_mul_I x y).symm have he₁ : e (1, 0) = 1 := rfl; have he₂ : e (0, 1) = I := rfl simp only [he] at * set F : ℝ × ℝ → E := f ∘ e set F' : ℝ × ℝ → ℝ × ℝ →L[ℝ] E := fun p => (f' (e p)).comp (e : ℝ × ℝ →L[ℝ] ℂ) have hF' : ∀ p : ℝ × ℝ, (-(I • F' p)) (1, 0) + F' p (0, 1) = -(I • f' (e p) 1 - f' (e p) I) := by rintro ⟨x, y⟩ simp only [F', ContinuousLinearMap.neg_apply, ContinuousLinearMap.smul_apply, ContinuousLinearMap.comp_apply, ContinuousLinearEquiv.coe_coe, he₁, he₂, neg_add_eq_sub, neg_sub] set R : Set (ℝ × ℝ) := [[z.re, w.re]] ×ˢ [[w.im, z.im]] set t : Set (ℝ × ℝ) := e ⁻¹' s rw [uIcc_comm z.im] at Hc Hi; rw [min_comm z.im, max_comm z.im] at Hd have hR : e ⁻¹' ([[z.re, w.re]] ×ℂ [[w.im, z.im]]) = R := rfl have htc : ContinuousOn F R := Hc.comp e.continuousOn hR.ge have htd : ∀ p ∈ Ioo (min z.re w.re) (max z.re w.re) ×ˢ Ioo (min w.im z.im) (max w.im z.im) \ t, HasFDerivAt F (F' p) p := fun p hp => (Hd (e p) hp).comp p e.hasFDerivAt simp_rw [← intervalIntegral.integral_smul, intervalIntegral.integral_symm w.im z.im, ← intervalIntegral.integral_neg, ← hF'] refine (integral2_divergence_prod_of_hasFDerivWithinAt_off_countable (fun p => -(I • F p)) F (fun p => -(I • F' p)) F' z.re w.im w.re z.im t (hs.preimage e.injective) (htc.const_smul _).neg htc (fun p hp => ((htd p hp).const_smul I).neg) htd ?_).symm rw [← (volume_preserving_equiv_real_prod.symm _).integrableOn_comp_preimage (MeasurableEquiv.measurableEmbedding _)] at Hi simpa only [hF'] using Hi.neg /-- Suppose that a function `f : ℂ → E` is continuous on a closed rectangle with opposite corners at `z w : ℂ`, is *real* differentiable on the corresponding open rectangle, and $\frac{\partial f}{\partial \bar z}$ is integrable on this rectangle. Then the integral of `f` over the boundary of the rectangle is equal to the integral of $2i\frac{\partial f}{\partial \bar z}=i\frac{\partial f}{\partial x}-\frac{\partial f}{\partial y}$ over the rectangle. -/ theorem integral_boundary_rect_of_continuousOn_of_hasFDerivAt_real (f : ℂ → E) (f' : ℂ → ℂ →L[ℝ] E) (z w : ℂ) (Hc : ContinuousOn f ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) (Hd : ∀ x ∈ Ioo (min z.re w.re) (max z.re w.re) ×ℂ Ioo (min z.im w.im) (max z.im w.im), HasFDerivAt f (f' x) x) (Hi : IntegrableOn (fun z => I • f' z 1 - f' z I) ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) : (∫ x : ℝ in z.re..w.re, f (x + z.im * I)) - (∫ x : ℝ in z.re..w.re, f (x + w.im * I)) + I • (∫ y : ℝ in z.im..w.im, f (re w + y * I)) - I • (∫ y : ℝ in z.im..w.im, f (re z + y * I)) = ∫ x : ℝ in z.re..w.re, ∫ y : ℝ in z.im..w.im, I • f' (x + y * I) 1 - f' (x + y * I) I := integral_boundary_rect_of_hasFDerivAt_real_off_countable f f' z w ∅ countable_empty Hc (fun x hx => Hd x hx.1) Hi /-- Suppose that a function `f : ℂ → E` is *real* differentiable on a closed rectangle with opposite corners at `z w : ℂ` and $\frac{\partial f}{\partial \bar z}$ is integrable on this rectangle. Then the integral of `f` over the boundary of the rectangle is equal to the integral of $2i\frac{\partial f}{\partial \bar z}=i\frac{\partial f}{\partial x}-\frac{\partial f}{\partial y}$ over the rectangle. -/ theorem integral_boundary_rect_of_differentiableOn_real (f : ℂ → E) (z w : ℂ) (Hd : DifferentiableOn ℝ f ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) (Hi : IntegrableOn (fun z => I • fderiv ℝ f z 1 - fderiv ℝ f z I) ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) : (∫ x : ℝ in z.re..w.re, f (x + z.im * I)) - (∫ x : ℝ in z.re..w.re, f (x + w.im * I)) + I • (∫ y : ℝ in z.im..w.im, f (re w + y * I)) - I • (∫ y : ℝ in z.im..w.im, f (re z + y * I)) = ∫ x : ℝ in z.re..w.re, ∫ y : ℝ in z.im..w.im, I • fderiv ℝ f (x + y * I) 1 - fderiv ℝ f (x + y * I) I := integral_boundary_rect_of_hasFDerivAt_real_off_countable f (fderiv ℝ f) z w ∅ countable_empty Hd.continuousOn (fun x hx => Hd.hasFDerivAt <| by simpa only [← mem_interior_iff_mem_nhds, interior_reProdIm, uIcc, interior_Icc] using hx.1) Hi /-- **Cauchy-Goursat theorem** for a rectangle: the integral of a complex differentiable function over the boundary of a rectangle equals zero. More precisely, if `f` is continuous on a closed rectangle and is complex differentiable at all but countably many points of the corresponding open rectangle, then its integral over the boundary of the rectangle equals zero. -/ theorem integral_boundary_rect_eq_zero_of_differentiable_on_off_countable (f : ℂ → E) (z w : ℂ) (s : Set ℂ) (hs : s.Countable) (Hc : ContinuousOn f ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) (Hd : ∀ x ∈ Ioo (min z.re w.re) (max z.re w.re) ×ℂ Ioo (min z.im w.im) (max z.im w.im) \ s, DifferentiableAt ℂ f x) : (∫ x : ℝ in z.re..w.re, f (x + z.im * I)) - (∫ x : ℝ in z.re..w.re, f (x + w.im * I)) + I • (∫ y : ℝ in z.im..w.im, f (re w + y * I)) - I • (∫ y : ℝ in z.im..w.im, f (re z + y * I)) = 0 := by refine (integral_boundary_rect_of_hasFDerivAt_real_off_countable f (fun z => (fderiv ℂ f z).restrictScalars ℝ) z w s hs Hc (fun x hx => (Hd x hx).hasFDerivAt.restrictScalars ℝ) ?_).trans ?_ <;> simp [← ContinuousLinearMap.map_smul] /-- **Cauchy-Goursat theorem for a rectangle**: the integral of a complex differentiable function over the boundary of a rectangle equals zero. More precisely, if `f` is continuous on a closed rectangle and is complex differentiable on the corresponding open rectangle, then its integral over the boundary of the rectangle equals zero. -/ theorem integral_boundary_rect_eq_zero_of_continuousOn_of_differentiableOn (f : ℂ → E) (z w : ℂ) (Hc : ContinuousOn f ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) (Hd : DifferentiableOn ℂ f (Ioo (min z.re w.re) (max z.re w.re) ×ℂ Ioo (min z.im w.im) (max z.im w.im))) : (∫ x : ℝ in z.re..w.re, f (x + z.im * I)) - (∫ x : ℝ in z.re..w.re, f (x + w.im * I)) + I • (∫ y : ℝ in z.im..w.im, f (re w + y * I)) - I • (∫ y : ℝ in z.im..w.im, f (re z + y * I)) = 0 := integral_boundary_rect_eq_zero_of_differentiable_on_off_countable f z w ∅ countable_empty Hc fun _x hx => Hd.differentiableAt <| (isOpen_Ioo.reProdIm isOpen_Ioo).mem_nhds hx.1 /-- **Cauchy-Goursat theorem** for a rectangle: the integral of a complex differentiable function over the boundary of a rectangle equals zero. More precisely, if `f` is complex differentiable on a closed rectangle, then its integral over the boundary of the rectangle equals zero. -/ theorem integral_boundary_rect_eq_zero_of_differentiableOn (f : ℂ → E) (z w : ℂ) (H : DifferentiableOn ℂ f ([[z.re, w.re]] ×ℂ [[z.im, w.im]])) : (∫ x : ℝ in z.re..w.re, f (x + z.im * I)) - (∫ x : ℝ in z.re..w.re, f (x + w.im * I)) + I • (∫ y : ℝ in z.im..w.im, f (re w + y * I)) - I • (∫ y : ℝ in z.im..w.im, f (re z + y * I)) = 0 := integral_boundary_rect_eq_zero_of_continuousOn_of_differentiableOn f z w H.continuousOn <| H.mono <| inter_subset_inter (preimage_mono Ioo_subset_Icc_self) (preimage_mono Ioo_subset_Icc_self) /-- If `f : ℂ → E` is continuous on the closed annulus `r ≤ ‖z - c‖ ≤ R`, `0 < r ≤ R`, and is complex differentiable at all but countably many points of its interior, then the integrals of `f z / (z - c)` (formally, `(z - c)⁻¹ • f z`) over the circles `‖z - c‖ = r` and `‖z - c‖ = R` are equal to each other. -/ theorem circleIntegral_sub_center_inv_smul_eq_of_differentiable_on_annulus_off_countable {c : ℂ} {r R : ℝ} (h0 : 0 < r) (hle : r ≤ R) {f : ℂ → E} {s : Set ℂ} (hs : s.Countable) (hc : ContinuousOn f (closedBall c R \ ball c r)) (hd : ∀ z ∈ (ball c R \ closedBall c r) \ s, DifferentiableAt ℂ f z) : (∮ z in C(c, R), (z - c)⁻¹ • f z) = ∮ z in C(c, r), (z - c)⁻¹ • f z := by /- We apply the previous lemma to `fun z ↦ f (c + exp z)` on the rectangle `[log r, log R] × [0, 2 * π]`. -/ set A := closedBall c R \ ball c r obtain ⟨a, rfl⟩ : ∃ a, Real.exp a = r := ⟨Real.log r, Real.exp_log h0⟩ obtain ⟨b, rfl⟩ : ∃ b, Real.exp b = R := ⟨Real.log R, Real.exp_log (h0.trans_le hle)⟩ rw [Real.exp_le_exp] at hle -- Unfold definition of `circleIntegral` and cancel some terms. suffices (∫ θ in (0)..2 * π, I • f (circleMap c (Real.exp b) θ)) = ∫ θ in (0)..2 * π, I • f (circleMap c (Real.exp a) θ) by simpa only [circleIntegral, add_sub_cancel_left, ofReal_exp, ← exp_add, smul_smul, ← div_eq_mul_inv, mul_div_cancel_left₀ _ (circleMap_ne_center (Real.exp_pos _).ne'), circleMap_sub_center, deriv_circleMap] set R := [[a, b]] ×ℂ [[0, 2 * π]] set g : ℂ → ℂ := (c + exp ·) have hdg : Differentiable ℂ g := differentiable_exp.const_add _ replace hs : (g ⁻¹' s).Countable := (hs.preimage (add_right_injective c)).preimage_cexp have h_maps : MapsTo g R A := by rintro z ⟨h, -⟩; simpa [g, A, dist_eq, norm_exp, hle] using h.symm replace hc : ContinuousOn (f ∘ g) R := hc.comp hdg.continuous.continuousOn h_maps replace hd : ∀ z ∈ Ioo (min a b) (max a b) ×ℂ Ioo (min 0 (2 * π)) (max 0 (2 * π)) \ g ⁻¹' s, DifferentiableAt ℂ (f ∘ g) z := by refine fun z hz => (hd (g z) ⟨?_, hz.2⟩).comp z (hdg _) simpa [g, dist_eq, norm_exp, hle, and_comm] using hz.1.1 simpa [g, circleMap, exp_periodic _, sub_eq_zero, ← exp_add] using integral_boundary_rect_eq_zero_of_differentiable_on_off_countable _ ⟨a, 0⟩ ⟨b, 2 * π⟩ _ hs hc hd /-- **Cauchy-Goursat theorem** for an annulus. If `f : ℂ → E` is continuous on the closed annulus `r ≤ ‖z - c‖ ≤ R`, `0 < r ≤ R`, and is complex differentiable at all but countably many points of its interior, then the integrals of `f` over the circles `‖z - c‖ = r` and `‖z - c‖ = R` are equal to each other. -/ theorem circleIntegral_eq_of_differentiable_on_annulus_off_countable {c : ℂ} {r R : ℝ} (h0 : 0 < r) (hle : r ≤ R) {f : ℂ → E} {s : Set ℂ} (hs : s.Countable) (hc : ContinuousOn f (closedBall c R \ ball c r)) (hd : ∀ z ∈ (ball c R \ closedBall c r) \ s, DifferentiableAt ℂ f z) : (∮ z in C(c, R), f z) = ∮ z in C(c, r), f z := calc (∮ z in C(c, R), f z) = ∮ z in C(c, R), (z - c)⁻¹ • (z - c) • f z := (circleIntegral.integral_sub_inv_smul_sub_smul _ _ _ _).symm _ = ∮ z in C(c, r), (z - c)⁻¹ • (z - c) • f z := (circleIntegral_sub_center_inv_smul_eq_of_differentiable_on_annulus_off_countable h0 hle hs ((continuousOn_id.sub continuousOn_const).smul hc) fun z hz => (differentiableAt_id.sub_const _).smul (hd z hz)) _ = ∮ z in C(c, r), f z := circleIntegral.integral_sub_inv_smul_sub_smul _ _ _ _ variable [CompleteSpace E] /-- **Cauchy integral formula** for the value at the center of a disc. If `f` is continuous on a punctured closed disc of radius `R`, is differentiable at all but countably many points of the interior of this disc, and has a limit `y` at the center of the disc, then the integral $\oint_{‖z-c‖=R} \frac{f(z)}{z-c}\,dz$ is equal to `2πiy`. -/ theorem circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable_of_tendsto {c : ℂ} {R : ℝ} (h0 : 0 < R) {f : ℂ → E} {y : E} {s : Set ℂ} (hs : s.Countable) (hc : ContinuousOn f (closedBall c R \ {c})) (hd : ∀ z ∈ (ball c R \ {c}) \ s, DifferentiableAt ℂ f z) (hy : Tendsto f (𝓝[{c}ᶜ] c) (𝓝 y)) : (∮ z in C(c, R), (z - c)⁻¹ • f z) = (2 * π * I : ℂ) • y := by rw [← sub_eq_zero, ← norm_le_zero_iff] refine le_of_forall_gt_imp_ge_of_dense fun ε ε0 => ?_ obtain ⟨δ, δ0, hδ⟩ : ∃ δ > (0 : ℝ), ∀ z ∈ closedBall c δ \ {c}, dist (f z) y < ε / (2 * π) := ((nhdsWithin_hasBasis nhds_basis_closedBall _).tendsto_iff nhds_basis_ball).1 hy _ (div_pos ε0 Real.two_pi_pos) obtain ⟨r, hr0, hrδ, hrR⟩ : ∃ r, 0 < r ∧ r ≤ δ ∧ r ≤ R := ⟨min δ R, lt_min δ0 h0, min_le_left _ _, min_le_right _ _⟩ have hsub : closedBall c R \ ball c r ⊆ closedBall c R \ {c} := diff_subset_diff_right (singleton_subset_iff.2 <| mem_ball_self hr0) have hsub' : ball c R \ closedBall c r ⊆ ball c R \ {c} := diff_subset_diff_right (singleton_subset_iff.2 <| mem_closedBall_self hr0.le) have hzne : ∀ z ∈ sphere c r, z ≠ c := fun z hz => ne_of_mem_of_not_mem hz fun h => hr0.ne' <| dist_self c ▸ Eq.symm h /- The integral `∮ z in C(c, r), f z / (z - c)` does not depend on `0 < r ≤ R` and tends to `2πIy` as `r → 0`. -/ calc ‖(∮ z in C(c, R), (z - c)⁻¹ • f z) - (2 * ↑π * I) • y‖ = ‖(∮ z in C(c, r), (z - c)⁻¹ • f z) - ∮ z in C(c, r), (z - c)⁻¹ • y‖ := by congr 2 · exact circleIntegral_sub_center_inv_smul_eq_of_differentiable_on_annulus_off_countable hr0 hrR hs (hc.mono hsub) fun z hz => hd z ⟨hsub' hz.1, hz.2⟩ · simp [hr0.ne'] _ = ‖∮ z in C(c, r), (z - c)⁻¹ • (f z - y)‖ := by simp only [smul_sub] have hc' : ContinuousOn (fun z => (z - c)⁻¹) (sphere c r) := (continuousOn_id.sub continuousOn_const).inv₀ fun z hz => sub_ne_zero.2 <| hzne _ hz rw [circleIntegral.integral_sub] <;> refine (hc'.smul ?_).circleIntegrable hr0.le · exact hc.mono <| subset_inter (sphere_subset_closedBall.trans <| closedBall_subset_closedBall hrR) hzne · exact continuousOn_const _ ≤ 2 * π * r * (r⁻¹ * (ε / (2 * π))) := by refine circleIntegral.norm_integral_le_of_norm_le_const hr0.le fun z hz => ?_ specialize hzne z hz rw [mem_sphere, dist_eq_norm] at hz rw [norm_smul, norm_inv, hz, ← dist_eq_norm] refine mul_le_mul_of_nonneg_left (hδ _ ⟨?_, hzne⟩).le (inv_nonneg.2 hr0.le) rwa [mem_closedBall_iff_norm, hz] _ = ε := by field_simp [hr0.ne', Real.two_pi_pos.ne']; ac_rfl /-- **Cauchy integral formula** for the value at the center of a disc. If `f : ℂ → E` is continuous on a closed disc of radius `R` and is complex differentiable at all but countably many points of its interior, then the integral $\oint_{|z-c|=R} \frac{f(z)}{z-c}\,dz$ is equal to `2πiy`. -/ theorem circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable {R : ℝ} (h0 : 0 < R) {f : ℂ → E} {c : ℂ} {s : Set ℂ} (hs : s.Countable) (hc : ContinuousOn f (closedBall c R)) (hd : ∀ z ∈ ball c R \ s, DifferentiableAt ℂ f z) : (∮ z in C(c, R), (z - c)⁻¹ • f z) = (2 * π * I : ℂ) • f c := circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable_of_tendsto h0 hs (hc.mono diff_subset) (fun z hz => hd z ⟨hz.1.1, hz.2⟩) (hc.continuousAt <| closedBall_mem_nhds _ h0).continuousWithinAt omit [CompleteSpace E] in /-- **Cauchy-Goursat theorem** for a disk: if `f : ℂ → E` is continuous on a closed disk `{z | ‖z - c‖ ≤ R}` and is complex differentiable at all but countably many points of its interior, then the integral $\oint_{|z-c|=R}f(z)\,dz$ equals zero. -/ theorem circleIntegral_eq_zero_of_differentiable_on_off_countable {R : ℝ} (h0 : 0 ≤ R) {f : ℂ → E} {c : ℂ} {s : Set ℂ} (hs : s.Countable) (hc : ContinuousOn f (closedBall c R)) (hd : ∀ z ∈ ball c R \ s, DifferentiableAt ℂ f z) : (∮ z in C(c, R), f z) = 0 := by wlog hE : CompleteSpace E generalizing · simp [circleIntegral, intervalIntegral, integral, hE] rcases h0.eq_or_lt with (rfl | h0); · apply circleIntegral.integral_radius_zero calc (∮ z in C(c, R), f z) = ∮ z in C(c, R), (z - c)⁻¹ • (z - c) • f z :=
(circleIntegral.integral_sub_inv_smul_sub_smul _ _ _ _).symm _ = (2 * ↑π * I : ℂ) • (c - c) • f c := (circleIntegral_sub_center_inv_smul_of_differentiable_on_off_countable h0 hs ((continuousOn_id.sub continuousOn_const).smul hc) fun z hz => (differentiableAt_id.sub_const _).smul (hd z hz)) _ = 0 := by rw [sub_self, zero_smul, smul_zero] /-- An auxiliary lemma for `Complex.circleIntegral_sub_inv_smul_of_differentiable_on_off_countable`. This lemma assumes `w ∉ s` while the main lemma drops this assumption. -/ theorem circleIntegral_sub_inv_smul_of_differentiable_on_off_countable_aux {R : ℝ} {c w : ℂ} {f : ℂ → E} {s : Set ℂ} (hs : s.Countable) (hw : w ∈ ball c R \ s)
Mathlib/Analysis/Complex/CauchyIntegral.lean
410
421
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.Group.Subgroup.Ker import Mathlib.Algebra.BigOperators.Group.List.Basic /-! # Free groups This file defines free groups over a type. Furthermore, it is shown that the free group construction is an instance of a monad. For the result that `FreeGroup` is the left adjoint to the forgetful functor from groups to types, see `Mathlib/Algebra/Category/Grp/Adjunctions.lean`. ## Main definitions * `FreeGroup`/`FreeAddGroup`: the free group (resp. free additive group) associated to a type `α` defined as the words over `a : α × Bool` modulo the relation `a * x * x⁻¹ * b = a * b`. * `FreeGroup.mk`/`FreeAddGroup.mk`: the canonical quotient map `List (α × Bool) → FreeGroup α`. * `FreeGroup.of`/`FreeAddGroup.of`: the canonical injection `α → FreeGroup α`. * `FreeGroup.lift f`/`FreeAddGroup.lift`: the canonical group homomorphism `FreeGroup α →* G` given a group `G` and a function `f : α → G`. ## Main statements * `FreeGroup.Red.church_rosser`/`FreeAddGroup.Red.church_rosser`: The Church-Rosser theorem for word reduction (also known as Newman's diamond lemma). * `FreeGroup.freeGroupUnitEquivInt`: The free group over the one-point type is isomorphic to the integers. * The free group construction is an instance of a monad. ## Implementation details First we introduce the one step reduction relation `FreeGroup.Red.Step`: `w * x * x⁻¹ * v ~> w * v`, its reflexive transitive closure `FreeGroup.Red.trans` and prove that its join is an equivalence relation. Then we introduce `FreeGroup α` as a quotient over `FreeGroup.Red.Step`. For the additive version we introduce the same relation under a different name so that we can distinguish the quotient types more easily. ## Tags free group, Newman's diamond lemma, Church-Rosser theorem -/ open Relation open scoped List universe u v w variable {α : Type u} attribute [local simp] List.append_eq_has_append -- Porting note: to_additive.map_namespace is not supported yet -- worked around it by putting a few extra manual mappings (but not too many all in all) -- run_cmd to_additive.map_namespace `FreeGroup `FreeAddGroup /-- Reduction step for the additive free group relation: `w + x + (-x) + v ~> w + v` -/ inductive FreeAddGroup.Red.Step : List (α × Bool) → List (α × Bool) → Prop | not {L₁ L₂ x b} : FreeAddGroup.Red.Step (L₁ ++ (x, b) :: (x, not b) :: L₂) (L₁ ++ L₂) attribute [simp] FreeAddGroup.Red.Step.not /-- Reduction step for the multiplicative free group relation: `w * x * x⁻¹ * v ~> w * v` -/ @[to_additive FreeAddGroup.Red.Step] inductive FreeGroup.Red.Step : List (α × Bool) → List (α × Bool) → Prop | not {L₁ L₂ x b} : FreeGroup.Red.Step (L₁ ++ (x, b) :: (x, not b) :: L₂) (L₁ ++ L₂) attribute [simp] FreeGroup.Red.Step.not namespace FreeGroup variable {L L₁ L₂ L₃ L₄ : List (α × Bool)} /-- Reflexive-transitive closure of `Red.Step` -/ @[to_additive FreeAddGroup.Red "Reflexive-transitive closure of `Red.Step`"] def Red : List (α × Bool) → List (α × Bool) → Prop := ReflTransGen Red.Step @[to_additive (attr := refl)] theorem Red.refl : Red L L := ReflTransGen.refl @[to_additive (attr := trans)] theorem Red.trans : Red L₁ L₂ → Red L₂ L₃ → Red L₁ L₃ := ReflTransGen.trans namespace Red /-- Predicate asserting that the word `w₁` can be reduced to `w₂` in one step, i.e. there are words `w₃ w₄` and letter `x` such that `w₁ = w₃xx⁻¹w₄` and `w₂ = w₃w₄` -/ @[to_additive "Predicate asserting that the word `w₁` can be reduced to `w₂` in one step, i.e. there are words `w₃ w₄` and letter `x` such that `w₁ = w₃ + x + (-x) + w₄` and `w₂ = w₃w₄`"] theorem Step.length : ∀ {L₁ L₂ : List (α × Bool)}, Step L₁ L₂ → L₂.length + 2 = L₁.length | _, _, @Red.Step.not _ L1 L2 x b => by rw [List.length_append, List.length_append]; rfl @[to_additive (attr := simp)] theorem Step.not_rev {x b} : Step (L₁ ++ (x, !b) :: (x, b) :: L₂) (L₁ ++ L₂) := by cases b <;> exact Step.not @[to_additive (attr := simp)] theorem Step.cons_not {x b} : Red.Step ((x, b) :: (x, !b) :: L) L := @Step.not _ [] _ _ _ @[to_additive (attr := simp)] theorem Step.cons_not_rev {x b} : Red.Step ((x, !b) :: (x, b) :: L) L := @Red.Step.not_rev _ [] _ _ _ @[to_additive] theorem Step.append_left : ∀ {L₁ L₂ L₃ : List (α × Bool)}, Step L₂ L₃ → Step (L₁ ++ L₂) (L₁ ++ L₃) | _, _, _, Red.Step.not => by rw [← List.append_assoc, ← List.append_assoc]; constructor @[to_additive] theorem Step.cons {x} (H : Red.Step L₁ L₂) : Red.Step (x :: L₁) (x :: L₂) := @Step.append_left _ [x] _ _ H @[to_additive] theorem Step.append_right : ∀ {L₁ L₂ L₃ : List (α × Bool)}, Step L₁ L₂ → Step (L₁ ++ L₃) (L₂ ++ L₃) | _, _, _, Red.Step.not => by simp @[to_additive] theorem not_step_nil : ¬Step [] L := by generalize h' : [] = L' intro h rcases h with - | ⟨L₁, L₂⟩ simp [List.nil_eq_append_iff] at h' @[to_additive] theorem Step.cons_left_iff {a : α} {b : Bool} : Step ((a, b) :: L₁) L₂ ↔ (∃ L, Step L₁ L ∧ L₂ = (a, b) :: L) ∨ L₁ = (a, ! b) :: L₂ := by constructor · generalize hL : ((a, b) :: L₁ : List _) = L rintro @⟨_ | ⟨p, s'⟩, e, a', b'⟩ <;> simp_all · rintro (⟨L, h, rfl⟩ | rfl) · exact Step.cons h · exact Step.cons_not @[to_additive] theorem not_step_singleton : ∀ {p : α × Bool}, ¬Step [p] L | (a, b) => by simp [Step.cons_left_iff, not_step_nil] @[to_additive] theorem Step.cons_cons_iff : ∀ {p : α × Bool}, Step (p :: L₁) (p :: L₂) ↔ Step L₁ L₂ := by simp +contextual [Step.cons_left_iff, iff_def, or_imp] @[to_additive] theorem Step.append_left_iff : ∀ L, Step (L ++ L₁) (L ++ L₂) ↔ Step L₁ L₂ | [] => by simp | p :: l => by simp [Step.append_left_iff l, Step.cons_cons_iff] @[to_additive] theorem Step.diamond_aux : ∀ {L₁ L₂ L₃ L₄ : List (α × Bool)} {x1 b1 x2 b2}, L₁ ++ (x1, b1) :: (x1, !b1) :: L₂ = L₃ ++ (x2, b2) :: (x2, !b2) :: L₄ → L₁ ++ L₂ = L₃ ++ L₄ ∨ ∃ L₅, Red.Step (L₁ ++ L₂) L₅ ∧ Red.Step (L₃ ++ L₄) L₅ | [], _, [], _, _, _, _, _, H => by injections; subst_vars; simp | [], _, [(x3, b3)], _, _, _, _, _, H => by injections; subst_vars; simp | [(x3, b3)], _, [], _, _, _, _, _, H => by injections; subst_vars; simp | [], _, (x3, b3) :: (x4, b4) :: tl, _, _, _, _, _, H => by injections; subst_vars; right; exact ⟨_, Red.Step.not, Red.Step.cons_not⟩ | (x3, b3) :: (x4, b4) :: tl, _, [], _, _, _, _, _, H => by injections; subst_vars; right; simpa using ⟨_, Red.Step.cons_not, Red.Step.not⟩ | (x3, b3) :: tl, _, (x4, b4) :: tl2, _, _, _, _, _, H => let ⟨H1, H2⟩ := List.cons.inj H match Step.diamond_aux H2 with | Or.inl H3 => Or.inl <| by simp [H1, H3] | Or.inr ⟨L₅, H3, H4⟩ => Or.inr ⟨_, Step.cons H3, by simpa [H1] using Step.cons H4⟩ @[to_additive] theorem Step.diamond : ∀ {L₁ L₂ L₃ L₄ : List (α × Bool)}, Red.Step L₁ L₃ → Red.Step L₂ L₄ → L₁ = L₂ → L₃ = L₄ ∨ ∃ L₅, Red.Step L₃ L₅ ∧ Red.Step L₄ L₅ | _, _, _, _, Red.Step.not, Red.Step.not, H => Step.diamond_aux H @[to_additive] theorem Step.to_red : Step L₁ L₂ → Red L₁ L₂ := ReflTransGen.single /-- **Church-Rosser theorem** for word reduction: If `w1 w2 w3` are words such that `w1` reduces to `w2` and `w3` respectively, then there is a word `w4` such that `w2` and `w3` reduce to `w4` respectively. This is also known as Newman's diamond lemma. -/ @[to_additive "**Church-Rosser theorem** for word reduction: If `w1 w2 w3` are words such that `w1` reduces to `w2` and `w3` respectively, then there is a word `w4` such that `w2` and `w3` reduce to `w4` respectively. This is also known as Newman's diamond lemma."] theorem church_rosser : Red L₁ L₂ → Red L₁ L₃ → Join Red L₂ L₃ := Relation.church_rosser fun _ b c hab hac => match b, c, Red.Step.diamond hab hac rfl with | b, _, Or.inl rfl => ⟨b, by rfl, by rfl⟩ | _, _, Or.inr ⟨d, hbd, hcd⟩ => ⟨d, ReflGen.single hbd, hcd.to_red⟩ @[to_additive] theorem cons_cons {p} : Red L₁ L₂ → Red (p :: L₁) (p :: L₂) := ReflTransGen.lift (List.cons p) fun _ _ => Step.cons @[to_additive] theorem cons_cons_iff (p) : Red (p :: L₁) (p :: L₂) ↔ Red L₁ L₂ := Iff.intro (by generalize eq₁ : (p :: L₁ : List _) = LL₁ generalize eq₂ : (p :: L₂ : List _) = LL₂ intro h induction h using Relation.ReflTransGen.head_induction_on generalizing L₁ L₂ with | refl => subst_vars cases eq₂ constructor | head h₁₂ h ih => subst_vars obtain ⟨a, b⟩ := p rw [Step.cons_left_iff] at h₁₂ rcases h₁₂ with (⟨L, h₁₂, rfl⟩ | rfl) · exact (ih rfl rfl).head h₁₂ · exact (cons_cons h).tail Step.cons_not_rev) cons_cons @[to_additive] theorem append_append_left_iff : ∀ L, Red (L ++ L₁) (L ++ L₂) ↔ Red L₁ L₂ | [] => Iff.rfl | p :: L => by simp [append_append_left_iff L, cons_cons_iff] @[to_additive] theorem append_append (h₁ : Red L₁ L₃) (h₂ : Red L₂ L₄) : Red (L₁ ++ L₂) (L₃ ++ L₄) := (h₁.lift (fun L => L ++ L₂) fun _ _ => Step.append_right).trans ((append_append_left_iff _).2 h₂) @[to_additive] theorem to_append_iff : Red L (L₁ ++ L₂) ↔ ∃ L₃ L₄, L = L₃ ++ L₄ ∧ Red L₃ L₁ ∧ Red L₄ L₂ := Iff.intro (by generalize eq : L₁ ++ L₂ = L₁₂ intro h induction h generalizing L₁ L₂ with | refl => exact ⟨_, _, eq.symm, by rfl, by rfl⟩ | tail hLL' h ih => obtain @⟨s, e, a, b⟩ := h rcases List.append_eq_append_iff.1 eq with (⟨s', rfl, rfl⟩ | ⟨e', rfl, rfl⟩) · have : L₁ ++ (s' ++ (a, b) :: (a, not b) :: e) = L₁ ++ s' ++ (a, b) :: (a, not b) :: e := by simp rcases ih this with ⟨w₁, w₂, rfl, h₁, h₂⟩ exact ⟨w₁, w₂, rfl, h₁, h₂.tail Step.not⟩ · have : s ++ (a, b) :: (a, not b) :: e' ++ L₂ = s ++ (a, b) :: (a, not b) :: (e' ++ L₂) := by simp rcases ih this with ⟨w₁, w₂, rfl, h₁, h₂⟩ exact ⟨w₁, w₂, rfl, h₁.tail Step.not, h₂⟩) fun ⟨_, _, Eq, h₃, h₄⟩ => Eq.symm ▸ append_append h₃ h₄ /-- The empty word `[]` only reduces to itself. -/ @[to_additive "The empty word `[]` only reduces to itself."] theorem nil_iff : Red [] L ↔ L = [] := reflTransGen_iff_eq fun _ => Red.not_step_nil /-- A letter only reduces to itself. -/ @[to_additive "A letter only reduces to itself."] theorem singleton_iff {x} : Red [x] L₁ ↔ L₁ = [x] := reflTransGen_iff_eq fun _ => not_step_singleton /-- If `x` is a letter and `w` is a word such that `xw` reduces to the empty word, then `w` reduces to `x⁻¹` -/ @[to_additive "If `x` is a letter and `w` is a word such that `x + w` reduces to the empty word, then `w` reduces to `-x`."] theorem cons_nil_iff_singleton {x b} : Red ((x, b) :: L) [] ↔ Red L [(x, not b)] := Iff.intro (fun h => by have h₁ : Red ((x, not b) :: (x, b) :: L) [(x, not b)] := cons_cons h have h₂ : Red ((x, not b) :: (x, b) :: L) L := ReflTransGen.single Step.cons_not_rev let ⟨L', h₁, h₂⟩ := church_rosser h₁ h₂ rw [singleton_iff] at h₁ subst L' assumption) fun h => (cons_cons h).tail Step.cons_not @[to_additive] theorem red_iff_irreducible {x1 b1 x2 b2} (h : (x1, b1) ≠ (x2, b2)) : Red [(x1, !b1), (x2, b2)] L ↔ L = [(x1, !b1), (x2, b2)] := by apply reflTransGen_iff_eq generalize eq : [(x1, not b1), (x2, b2)] = L' intro L h' cases h' simp only [List.cons_eq_append_iff, List.cons.injEq, Prod.mk.injEq, and_false, List.nil_eq_append_iff, exists_const, or_self, or_false, List.cons_ne_nil] at eq rcases eq with ⟨rfl, ⟨rfl, rfl⟩, ⟨rfl, rfl⟩, rfl⟩ simp at h /-- If `x` and `y` are distinct letters and `w₁ w₂` are words such that `xw₁` reduces to `yw₂`, then `w₁` reduces to `x⁻¹yw₂`. -/ @[to_additive "If `x` and `y` are distinct letters and `w₁ w₂` are words such that `x + w₁` reduces to `y + w₂`, then `w₁` reduces to `-x + y + w₂`."] theorem inv_of_red_of_ne {x1 b1 x2 b2} (H1 : (x1, b1) ≠ (x2, b2)) (H2 : Red ((x1, b1) :: L₁) ((x2, b2) :: L₂)) : Red L₁ ((x1, not b1) :: (x2, b2) :: L₂) := by have : Red ((x1, b1) :: L₁) ([(x2, b2)] ++ L₂) := H2 rcases to_append_iff.1 this with ⟨_ | ⟨p, L₃⟩, L₄, eq, h₁, h₂⟩ · simp [nil_iff] at h₁ · cases eq show Red (L₃ ++ L₄) ([(x1, not b1), (x2, b2)] ++ L₂) apply append_append _ h₂ have h₁ : Red ((x1, not b1) :: (x1, b1) :: L₃) [(x1, not b1), (x2, b2)] := cons_cons h₁ have h₂ : Red ((x1, not b1) :: (x1, b1) :: L₃) L₃ := Step.cons_not_rev.to_red rcases church_rosser h₁ h₂ with ⟨L', h₁, h₂⟩ rw [red_iff_irreducible H1] at h₁ rwa [h₁] at h₂ open List -- for <+ notation @[to_additive] theorem Step.sublist (H : Red.Step L₁ L₂) : L₂ <+ L₁ := by cases H; simp /-- If `w₁ w₂` are words such that `w₁` reduces to `w₂`, then `w₂` is a sublist of `w₁`. -/ @[to_additive "If `w₁ w₂` are words such that `w₁` reduces to `w₂`, then `w₂` is a sublist of `w₁`."] protected theorem sublist : Red L₁ L₂ → L₂ <+ L₁ := @reflTransGen_of_transitive_reflexive _ (fun a b => b <+ a) _ _ _ (fun l => List.Sublist.refl l) (fun _a _b _c hab hbc => List.Sublist.trans hbc hab) (fun _ _ => Red.Step.sublist) @[to_additive] theorem length_le (h : Red L₁ L₂) : L₂.length ≤ L₁.length := h.sublist.length_le @[to_additive] theorem sizeof_of_step : ∀ {L₁ L₂ : List (α × Bool)}, Step L₁ L₂ → sizeOf L₂ < sizeOf L₁ | _, _, @Step.not _ L1 L2 x b => by induction L1 with | nil => dsimp omega | cons hd tl ih => dsimp exact Nat.add_lt_add_left ih _ @[to_additive] theorem length (h : Red L₁ L₂) : ∃ n, L₁.length = L₂.length + 2 * n := by induction h with | refl => exact ⟨0, rfl⟩ | tail _h₁₂ h₂₃ ih => rcases ih with ⟨n, eq⟩ exists 1 + n simp [Nat.mul_add, eq, (Step.length h₂₃).symm, add_assoc] @[to_additive] theorem antisymm (h₁₂ : Red L₁ L₂) (h₂₁ : Red L₂ L₁) : L₁ = L₂ := h₂₁.sublist.antisymm h₁₂.sublist end Red @[to_additive FreeAddGroup.equivalence_join_red] theorem equivalence_join_red : Equivalence (Join (@Red α)) := equivalence_join_reflTransGen fun _ b c hab hac => match b, c, Red.Step.diamond hab hac rfl with | b, _, Or.inl rfl => ⟨b, by rfl, by rfl⟩ | _, _, Or.inr ⟨d, hbd, hcd⟩ => ⟨d, ReflGen.single hbd, ReflTransGen.single hcd⟩ @[to_additive FreeAddGroup.join_red_of_step] theorem join_red_of_step (h : Red.Step L₁ L₂) : Join Red L₁ L₂ := join_of_single reflexive_reflTransGen h.to_red @[to_additive FreeAddGroup.eqvGen_step_iff_join_red] theorem eqvGen_step_iff_join_red : EqvGen Red.Step L₁ L₂ ↔ Join Red L₁ L₂ := Iff.intro (fun h => have : EqvGen (Join Red) L₁ L₂ := h.mono fun _ _ => join_red_of_step equivalence_join_red.eqvGen_iff.1 this) (join_of_equivalence (Relation.EqvGen.is_equivalence _) fun _ _ => reflTransGen_of_equivalence (Relation.EqvGen.is_equivalence _) EqvGen.rel) end FreeGroup /-- If `α` is a type, then `FreeGroup α` is the free group generated by `α`. This is a group equipped with a function `FreeGroup.of : α → FreeGroup α` which has the following universal property: if `G` is any group, and `f : α → G` is any function, then this function is the composite of `FreeGroup.of` and a unique group homomorphism `FreeGroup.lift f : FreeGroup α →* G`. A typical element of `FreeGroup α` is a formal product of elements of `α` and their formal inverses, quotient by reduction. For example if `x` and `y` are terms of type `α` then `x⁻¹ * y * y * x * y⁻¹` is a "typical" element of `FreeGroup α`. In particular if `α` is empty then `FreeGroup α` is isomorphic to the trivial group, and if `α` has one term then `FreeGroup α` is isomorphic to `Multiplicative ℤ`. If `α` has two or more terms then `FreeGroup α` is not commutative. -/ @[to_additive " If `α` is a type, then `FreeAddGroup α` is the free additive group generated by `α`. This is a group equipped with a function `FreeAddGroup.of : α → FreeAddGroup α` which has the following universal property: if `G` is any group, and `f : α → G` is any function, then this function is the composite of `FreeAddGroup.of` and a unique group homomorphism `FreeAddGroup.lift f : FreeAddGroup α →+ G`. A typical element of `FreeAddGroup α` is a formal sum of elements of `α` and their formal inverses, quotient by reduction. For example if `x` and `y` are terms of type `α` then `-x + y + y + x + -y` is a \"typical\" element of `FreeAddGroup α`. In particular if `α` is empty then `FreeAddGroup α` is isomorphic to the trivial group, and if `α` has one term then `FreeAddGroup α` is isomorphic to `ℤ`. If `α` has two or more terms then `FreeAddGroup α` is not commutative. "] def FreeGroup (α : Type u) : Type u := Quot <| @FreeGroup.Red.Step α namespace FreeGroup variable {L L₁ L₂ L₃ L₄ : List (α × Bool)} /-- The canonical map from `List (α × Bool)` to the free group on `α`. -/ @[to_additive "The canonical map from `List (α × Bool)` to the free additive group on `α`."] def mk (L : List (α × Bool)) : FreeGroup α := Quot.mk Red.Step L @[to_additive (attr := simp)] theorem quot_mk_eq_mk : Quot.mk Red.Step L = mk L := rfl @[to_additive (attr := simp)] theorem quot_lift_mk (β : Type v) (f : List (α × Bool) → β) (H : ∀ L₁ L₂, Red.Step L₁ L₂ → f L₁ = f L₂) : Quot.lift f H (mk L) = f L := rfl @[to_additive (attr := simp)] theorem quot_liftOn_mk (β : Type v) (f : List (α × Bool) → β) (H : ∀ L₁ L₂, Red.Step L₁ L₂ → f L₁ = f L₂) : Quot.liftOn (mk L) f H = f L := rfl open scoped Relator in @[to_additive (attr := simp)] theorem quot_map_mk (β : Type v) (f : List (α × Bool) → List (β × Bool)) (H : (Red.Step ⇒ Red.Step) f f) : Quot.map f H (mk L) = mk (f L) := rfl @[to_additive] instance : One (FreeGroup α) := ⟨mk []⟩ @[to_additive] theorem one_eq_mk : (1 : FreeGroup α) = mk [] := rfl @[to_additive] instance : Inhabited (FreeGroup α) := ⟨1⟩ @[to_additive] instance [IsEmpty α] : Unique (FreeGroup α) := by unfold FreeGroup; infer_instance @[to_additive] instance : Mul (FreeGroup α) := ⟨fun x y => Quot.liftOn x (fun L₁ => Quot.liftOn y (fun L₂ => mk <| L₁ ++ L₂) fun _L₂ _L₃ H => Quot.sound <| Red.Step.append_left H) fun _L₁ _L₂ H => Quot.inductionOn y fun _L₃ => Quot.sound <| Red.Step.append_right H⟩ @[to_additive (attr := simp)] theorem mul_mk : mk L₁ * mk L₂ = mk (L₁ ++ L₂) := rfl /-- Transform a word representing a free group element into a word representing its inverse. -/ @[to_additive "Transform a word representing a free group element into a word representing its negative."] def invRev (w : List (α × Bool)) : List (α × Bool) := (List.map (fun g : α × Bool => (g.1, not g.2)) w).reverse @[to_additive (attr := simp)] theorem invRev_length : (invRev L₁).length = L₁.length := by simp [invRev] @[to_additive (attr := simp)] theorem invRev_invRev : invRev (invRev L₁) = L₁ := by simp [invRev, List.map_reverse, Function.comp_def] @[to_additive (attr := simp)] theorem invRev_empty : invRev ([] : List (α × Bool)) = [] := rfl @[to_additive (attr := simp)] theorem invRev_append : invRev (L₁ ++ L₂) = invRev L₂ ++ invRev L₁ := by simp [invRev] @[to_additive] theorem invRev_cons {a : (α × Bool)} : invRev (a :: L) = invRev L ++ invRev [a] := by simp [invRev] @[to_additive] theorem invRev_involutive : Function.Involutive (@invRev α) := fun _ => invRev_invRev @[to_additive] theorem invRev_injective : Function.Injective (@invRev α) := invRev_involutive.injective @[to_additive] theorem invRev_surjective : Function.Surjective (@invRev α) := invRev_involutive.surjective @[to_additive] theorem invRev_bijective : Function.Bijective (@invRev α) := invRev_involutive.bijective @[to_additive] instance : Inv (FreeGroup α) := ⟨Quot.map invRev (by intro a b h cases h simp [invRev])⟩ @[to_additive (attr := simp)] theorem inv_mk : (mk L)⁻¹ = mk (invRev L) := rfl @[to_additive] theorem Red.Step.invRev {L₁ L₂ : List (α × Bool)} (h : Red.Step L₁ L₂) : Red.Step (FreeGroup.invRev L₁) (FreeGroup.invRev L₂) := by obtain ⟨a, b, x, y⟩ := h simp [FreeGroup.invRev] @[to_additive] theorem Red.invRev {L₁ L₂ : List (α × Bool)} (h : Red L₁ L₂) : Red (invRev L₁) (invRev L₂) := Relation.ReflTransGen.lift _ (fun _a _b => Red.Step.invRev) h @[to_additive (attr := simp)] theorem Red.step_invRev_iff : Red.Step (FreeGroup.invRev L₁) (FreeGroup.invRev L₂) ↔ Red.Step L₁ L₂ := ⟨fun h => by simpa only [invRev_invRev] using h.invRev, fun h => h.invRev⟩ @[to_additive (attr := simp)] theorem red_invRev_iff : Red (invRev L₁) (invRev L₂) ↔ Red L₁ L₂ := ⟨fun h => by simpa only [invRev_invRev] using h.invRev, fun h => h.invRev⟩ @[to_additive] instance : Group (FreeGroup α) where mul := (· * ·) one := 1 inv := Inv.inv mul_assoc := by rintro ⟨L₁⟩ ⟨L₂⟩ ⟨L₃⟩; simp one_mul := by rintro ⟨L⟩; rfl mul_one := by rintro ⟨L⟩; simp [one_eq_mk] inv_mul_cancel := by rintro ⟨L⟩ exact List.recOn L rfl fun ⟨x, b⟩ tl ih => Eq.trans (Quot.sound <| by simp [invRev, one_eq_mk]) ih @[to_additive (attr := simp)] theorem pow_mk (n : ℕ) : mk L ^ n = mk (List.flatten <| List.replicate n L) := match n with | 0 => rfl | n + 1 => by rw [pow_succ', pow_mk, mul_mk, List.replicate_succ, List.flatten_cons] /-- `of` is the canonical injection from the type to the free group over that type by sending each element to the equivalence class of the letter that is the element. -/ @[to_additive "`of` is the canonical injection from the type to the free group over that type by sending each element to the equivalence class of the letter that is the element."] def of (x : α) : FreeGroup α := mk [(x, true)] @[to_additive] theorem Red.exact : mk L₁ = mk L₂ ↔ Join Red L₁ L₂ := calc mk L₁ = mk L₂ ↔ EqvGen Red.Step L₁ L₂ := Iff.intro Quot.eqvGen_exact Quot.eqvGen_sound _ ↔ Join Red L₁ L₂ := eqvGen_step_iff_join_red /-- The canonical map from the type to the free group is an injection. -/ @[to_additive "The canonical map from the type to the additive free group is an injection."] theorem of_injective : Function.Injective (@of α) := fun _ _ H => by let ⟨L₁, hx, hy⟩ := Red.exact.1 H simp [Red.singleton_iff] at hx hy; aesop section lift variable {β : Type v} [Group β] (f : α → β) {x y : FreeGroup α} /-- Given `f : α → β` with `β` a group, the canonical map `List (α × Bool) → β` -/ @[to_additive "Given `f : α → β` with `β` an additive group, the canonical map `List (α × Bool) → β`"] def Lift.aux : List (α × Bool) → β := fun L => List.prod <| L.map fun x => cond x.2 (f x.1) (f x.1)⁻¹ @[to_additive] theorem Red.Step.lift {f : α → β} (H : Red.Step L₁ L₂) : Lift.aux f L₁ = Lift.aux f L₂ := by obtain @⟨_, _, _, b⟩ := H; cases b <;> simp [Lift.aux] /-- If `β` is a group, then any function from `α` to `β` extends uniquely to a group homomorphism from the free group over `α` to `β` -/ @[to_additive (attr := simps symm_apply) "If `β` is an additive group, then any function from `α` to `β` extends uniquely to an additive group homomorphism from the free additive group over `α` to `β`"] def lift : (α → β) ≃ (FreeGroup α →* β) where toFun f := MonoidHom.mk' (Quot.lift (Lift.aux f) fun _ _ => Red.Step.lift) <| by rintro ⟨L₁⟩ ⟨L₂⟩; simp [Lift.aux] invFun g := g ∘ of left_inv f := List.prod_singleton right_inv g := MonoidHom.ext <| by rintro ⟨L⟩ exact List.recOn L (g.map_one.symm) (by rintro ⟨x, _ | _⟩ t (ih : _ = g (mk t)) · show _ = g ((of x)⁻¹ * mk t) simpa [Lift.aux] using ih · show _ = g (of x * mk t) simpa [Lift.aux] using ih) variable {f} @[to_additive (attr := simp)] theorem lift.mk : lift f (mk L) = List.prod (L.map fun x => cond x.2 (f x.1) (f x.1)⁻¹) := rfl @[to_additive (attr := simp)] theorem lift.of {x} : lift f (of x) = f x := List.prod_singleton @[to_additive] theorem lift.unique (g : FreeGroup α →* β) (hg : ∀ x, g (FreeGroup.of x) = f x) {x} : g x = FreeGroup.lift f x := DFunLike.congr_fun (lift.symm_apply_eq.mp (funext hg : g ∘ FreeGroup.of = f)) x /-- Two homomorphisms out of a free group are equal if they are equal on generators. See note [partially-applied ext lemmas]. -/ @[to_additive (attr := ext) "Two homomorphisms out of a free additive group are equal if they are equal on generators. See note [partially-applied ext lemmas]."] theorem ext_hom {G : Type*} [Group G] (f g : FreeGroup α →* G) (h : ∀ a, f (of a) = g (of a)) : f = g := lift.symm.injective <| funext h @[to_additive] theorem lift_of_eq_id (α) : lift of = MonoidHom.id (FreeGroup α) := lift.apply_symm_apply (MonoidHom.id _) @[to_additive] theorem lift.of_eq (x : FreeGroup α) : lift FreeGroup.of x = x := DFunLike.congr_fun (lift_of_eq_id α) x @[to_additive] theorem lift.range_le {s : Subgroup β} (H : Set.range f ⊆ s) : (lift f).range ≤ s := by rintro _ ⟨⟨L⟩, rfl⟩ exact List.recOn L s.one_mem fun ⟨x, b⟩ tl ih ↦ Bool.recOn b (by simpa using s.mul_mem (s.inv_mem <| H ⟨x, rfl⟩) ih) (by simpa using s.mul_mem (H ⟨x, rfl⟩) ih) @[to_additive] theorem lift.range_eq_closure : (lift f).range = Subgroup.closure (Set.range f) := by apply le_antisymm (lift.range_le Subgroup.subset_closure) rw [Subgroup.closure_le] rintro _ ⟨a, rfl⟩ exact ⟨FreeGroup.of a, by simp only [lift.of]⟩ /-- The generators of `FreeGroup α` generate `FreeGroup α`. That is, the subgroup closure of the set of generators equals `⊤`. -/ @[to_additive (attr := simp)] theorem closure_range_of (α) : Subgroup.closure (Set.range (FreeGroup.of : α → FreeGroup α)) = ⊤ := by rw [← lift.range_eq_closure, lift_of_eq_id] exact MonoidHom.range_eq_top.2 Function.surjective_id end lift section Map variable {β : Type v} (f : α → β) {x y : FreeGroup α} /-- Any function from `α` to `β` extends uniquely to a group homomorphism from the free group over `α` to the free group over `β`. -/ @[to_additive "Any function from `α` to `β` extends uniquely to an additive group homomorphism from the additive free group over `α` to the additive free group over `β`."] def map : FreeGroup α →* FreeGroup β := MonoidHom.mk' (Quot.map (List.map fun x => (f x.1, x.2)) fun L₁ L₂ H => by cases H; simp) (by rintro ⟨L₁⟩ ⟨L₂⟩; simp) variable {f} @[to_additive (attr := simp)] theorem map.mk : map f (mk L) = mk (L.map fun x => (f x.1, x.2)) := rfl @[to_additive (attr := simp)] theorem map.id (x : FreeGroup α) : map id x = x := by rcases x with ⟨L⟩; simp [List.map_id'] @[to_additive (attr := simp)] theorem map.id' (x : FreeGroup α) : map (fun z => z) x = x := map.id x @[to_additive] theorem map.comp {γ : Type w} (f : α → β) (g : β → γ) (x) : map g (map f x) = map (g ∘ f) x := by rcases x with ⟨L⟩; simp [Function.comp_def] @[to_additive (attr := simp)] theorem map.of {x} : map f (of x) = of (f x) := rfl @[to_additive] theorem map.unique (g : FreeGroup α →* FreeGroup β) (hg : ∀ x, g (FreeGroup.of x) = FreeGroup.of (f x)) : ∀ {x}, g x = map f x := by rintro ⟨L⟩ exact List.recOn L g.map_one fun ⟨x, b⟩ t (ih : g (FreeGroup.mk t) = map f (FreeGroup.mk t)) => Bool.recOn b (show g ((FreeGroup.of x)⁻¹ * FreeGroup.mk t) = FreeGroup.map f ((FreeGroup.of x)⁻¹ * FreeGroup.mk t) by simp [g.map_mul, g.map_inv, hg, ih]) (show g (FreeGroup.of x * FreeGroup.mk t) = FreeGroup.map f (FreeGroup.of x * FreeGroup.mk t) by simp [g.map_mul, hg, ih]) @[to_additive] theorem map_eq_lift : map f x = lift (of ∘ f) x := Eq.symm <| map.unique _ fun x => by simp /-- Equivalent types give rise to multiplicatively equivalent free groups. The converse can be found in `Mathlib.GroupTheory.FreeGroup.GeneratorEquiv`, as `Equiv.ofFreeGroupEquiv`. -/ @[to_additive (attr := simps apply) "Equivalent types give rise to additively equivalent additive free groups."] def freeGroupCongr {α β} (e : α ≃ β) : FreeGroup α ≃* FreeGroup β where toFun := map e invFun := map e.symm left_inv x := by simp [Function.comp, map.comp] right_inv x := by simp [Function.comp, map.comp] map_mul' := MonoidHom.map_mul _ @[to_additive (attr := simp)] theorem freeGroupCongr_refl : freeGroupCongr (Equiv.refl α) = MulEquiv.refl _ := MulEquiv.ext map.id @[to_additive (attr := simp)] theorem freeGroupCongr_symm {α β} (e : α ≃ β) : (freeGroupCongr e).symm = freeGroupCongr e.symm := rfl @[to_additive] theorem freeGroupCongr_trans {α β γ} (e : α ≃ β) (f : β ≃ γ) : (freeGroupCongr e).trans (freeGroupCongr f) = freeGroupCongr (e.trans f) := MulEquiv.ext <| map.comp _ _ end Map section Prod variable [Group α] (x y : FreeGroup α) /-- If `α` is a group, then any function from `α` to `α` extends uniquely to a homomorphism from the free group over `α` to `α`. This is the multiplicative version of `FreeGroup.sum`. -/ @[to_additive "If `α` is an additive group, then any function from `α` to `α` extends uniquely to an additive homomorphism from the additive free group over `α` to `α`."] def prod : FreeGroup α →* α := lift id variable {x y} @[to_additive (attr := simp)] theorem prod_mk : prod (mk L) = List.prod (L.map fun x => cond x.2 x.1 x.1⁻¹) := rfl @[to_additive (attr := simp)] theorem prod.of {x : α} : prod (of x) = x := lift.of @[to_additive] theorem prod.unique (g : FreeGroup α →* α) (hg : ∀ x, g (FreeGroup.of x) = x) {x} : g x = prod x := lift.unique g hg end Prod
@[to_additive] theorem lift_eq_prod_map {β : Type v} [Group β] {f : α → β} {x} : lift f x = prod (map f x) := by rw [← lift.unique (prod.comp (map f)) (by simp), MonoidHom.coe_comp, Function.comp_apply]
Mathlib/GroupTheory/FreeGroup/Basic.lean
776
780
/- 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
375
435
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Algebra.Order.Group.Pointwise.Interval import Mathlib.LinearAlgebra.BilinearMap import Mathlib.LinearAlgebra.Pi import Mathlib.LinearAlgebra.Prod import Mathlib.Tactic.Abel import Mathlib.Algebra.AddTorsor.Basic import Mathlib.LinearAlgebra.AffineSpace.Defs /-! # Affine maps This file defines affine maps. ## Main definitions * `AffineMap` is the type of affine maps between two affine spaces with the same ring `k`. Various basic examples of affine maps are defined, including `const`, `id`, `lineMap` and `homothety`. ## Notations * `P1 →ᵃ[k] P2` is a notation for `AffineMap k P1 P2`; * `AffineSpace V P`: a localized notation for `AddTorsor V P` defined in `LinearAlgebra.AffineSpace.Basic`. ## Implementation notes `outParam` is used in the definition of `[AddTorsor V P]` to make `V` an implicit argument (deduced from `P`) in most cases. As for modules, `k` is an explicit argument rather than implied by `P` or `V`. This file only provides purely algebraic definitions and results. Those depending on analysis or topology are defined elsewhere; see `Analysis.Normed.Affine.AddTorsor` and `Topology.Algebra.Affine`. ## References * https://en.wikipedia.org/wiki/Affine_space * https://en.wikipedia.org/wiki/Principal_homogeneous_space -/ open Affine /-- An `AffineMap k P1 P2` (notation: `P1 →ᵃ[k] P2`) is a map from `P1` to `P2` that induces a corresponding linear map from `V1` to `V2`. -/ structure AffineMap (k : Type*) {V1 : Type*} (P1 : Type*) {V2 : Type*} (P2 : Type*) [Ring k] [AddCommGroup V1] [Module k V1] [AffineSpace V1 P1] [AddCommGroup V2] [Module k V2] [AffineSpace V2 P2] where toFun : P1 → P2 linear : V1 →ₗ[k] V2 map_vadd' : ∀ (p : P1) (v : V1), toFun (v +ᵥ p) = linear v +ᵥ toFun p /-- An `AffineMap k P1 P2` (notation: `P1 →ᵃ[k] P2`) is a map from `P1` to `P2` that induces a corresponding linear map from `V1` to `V2`. -/ notation:25 P1 " →ᵃ[" k:25 "] " P2:0 => AffineMap k P1 P2 instance AffineMap.instFunLike (k : Type*) {V1 : Type*} (P1 : Type*) {V2 : Type*} (P2 : Type*) [Ring k] [AddCommGroup V1] [Module k V1] [AffineSpace V1 P1] [AddCommGroup V2] [Module k V2] [AffineSpace V2 P2] : FunLike (P1 →ᵃ[k] P2) P1 P2 where coe := AffineMap.toFun coe_injective' := fun ⟨f, f_linear, f_add⟩ ⟨g, g_linear, g_add⟩ => fun (h : f = g) => by obtain ⟨p⟩ := (AddTorsor.nonempty : Nonempty P1) congr with v apply vadd_right_cancel (f p) rw [← f_add, h, ← g_add] namespace LinearMap variable {k : Type*} {V₁ : Type*} {V₂ : Type*} [Ring k] [AddCommGroup V₁] [Module k V₁] [AddCommGroup V₂] [Module k V₂] (f : V₁ →ₗ[k] V₂) /-- Reinterpret a linear map as an affine map. -/ def toAffineMap : V₁ →ᵃ[k] V₂ where toFun := f linear := f map_vadd' p v := f.map_add v p @[simp] theorem coe_toAffineMap : ⇑f.toAffineMap = f := rfl @[simp] theorem toAffineMap_linear : f.toAffineMap.linear = f := rfl end LinearMap namespace AffineMap variable {k : Type*} {V1 : Type*} {P1 : Type*} {V2 : Type*} {P2 : Type*} {V3 : Type*} {P3 : Type*} {V4 : Type*} {P4 : Type*} [Ring k] [AddCommGroup V1] [Module k V1] [AffineSpace V1 P1] [AddCommGroup V2] [Module k V2] [AffineSpace V2 P2] [AddCommGroup V3] [Module k V3] [AffineSpace V3 P3] [AddCommGroup V4] [Module k V4] [AffineSpace V4 P4] /-- Constructing an affine map and coercing back to a function produces the same map. -/ @[simp] theorem coe_mk (f : P1 → P2) (linear add) : ((mk f linear add : P1 →ᵃ[k] P2) : P1 → P2) = f := rfl /-- `toFun` is the same as the result of coercing to a function. -/ @[simp] theorem toFun_eq_coe (f : P1 →ᵃ[k] P2) : f.toFun = ⇑f := rfl /-- An affine map on the result of adding a vector to a point produces the same result as the linear map applied to that vector, added to the affine map applied to that point. -/ @[simp] theorem map_vadd (f : P1 →ᵃ[k] P2) (p : P1) (v : V1) : f (v +ᵥ p) = f.linear v +ᵥ f p := f.map_vadd' p v /-- The linear map on the result of subtracting two points is the result of subtracting the result of the affine map on those two points. -/ @[simp] theorem linearMap_vsub (f : P1 →ᵃ[k] P2) (p1 p2 : P1) : f.linear (p1 -ᵥ p2) = f p1 -ᵥ f p2 := by conv_rhs => rw [← vsub_vadd p1 p2, map_vadd, vadd_vsub] /-- Two affine maps are equal if they coerce to the same function. -/ @[ext] theorem ext {f g : P1 →ᵃ[k] P2} (h : ∀ p, f p = g p) : f = g := DFunLike.ext _ _ h theorem coeFn_injective : @Function.Injective (P1 →ᵃ[k] P2) (P1 → P2) (⇑) := DFunLike.coe_injective protected theorem congr_arg (f : P1 →ᵃ[k] P2) {x y : P1} (h : x = y) : f x = f y := congr_arg _ h protected theorem congr_fun {f g : P1 →ᵃ[k] P2} (h : f = g) (x : P1) : f x = g x := h ▸ rfl /-- Two affine maps are equal if they have equal linear maps and are equal at some point. -/ theorem ext_linear {f g : P1 →ᵃ[k] P2} (h₁ : f.linear = g.linear) {p : P1} (h₂ : f p = g p) : f = g := by ext q have hgl : g.linear (q -ᵥ p) = toFun g ((q -ᵥ p) +ᵥ q) -ᵥ toFun g q := by simp have := f.map_vadd' q (q -ᵥ p) rw [h₁, hgl, toFun_eq_coe, map_vadd, linearMap_vsub, h₂] at this simpa /-- Two affine maps are equal if they have equal linear maps and are equal at some point. -/ theorem ext_linear_iff {f g : P1 →ᵃ[k] P2} : f = g ↔ (f.linear = g.linear) ∧ (∃ p, f p = g p) := ⟨fun h ↦ ⟨congrArg _ h, by inhabit P1; exact default, by rw [h]⟩, fun h ↦ Exists.casesOn h.2 fun _ hp ↦ ext_linear h.1 hp⟩ variable (k P1) /-- The constant function as an `AffineMap`. -/ def const (p : P2) : P1 →ᵃ[k] P2 where toFun := Function.const P1 p linear := 0 map_vadd' _ _ := letI : AddAction V2 P2 := inferInstance by simp @[simp] theorem coe_const (p : P2) : ⇑(const k P1 p) = Function.const P1 p := rfl @[simp] theorem const_apply (p : P2) (q : P1) : (const k P1 p) q = p := rfl @[simp] theorem const_linear (p : P2) : (const k P1 p).linear = 0 := rfl variable {k P1} theorem linear_eq_zero_iff_exists_const (f : P1 →ᵃ[k] P2) : f.linear = 0 ↔ ∃ q, f = const k P1 q := by refine ⟨fun h => ?_, fun h => ?_⟩ · use f (Classical.arbitrary P1) ext rw [coe_const, Function.const_apply, ← @vsub_eq_zero_iff_eq V2, ← f.linearMap_vsub, h, LinearMap.zero_apply] · rcases h with ⟨q, rfl⟩ exact const_linear k P1 q instance nonempty : Nonempty (P1 →ᵃ[k] P2) := (AddTorsor.nonempty : Nonempty P2).map <| const k P1 /-- Construct an affine map by verifying the relation between the map and its linear part at one base point. Namely, this function takes a map `f : P₁ → P₂`, a linear map `f' : V₁ →ₗ[k] V₂`, and a point `p` such that for any other point `p'` we have `f p' = f' (p' -ᵥ p) +ᵥ f p`. -/ def mk' (f : P1 → P2) (f' : V1 →ₗ[k] V2) (p : P1) (h : ∀ p' : P1, f p' = f' (p' -ᵥ p) +ᵥ f p) : P1 →ᵃ[k] P2 where toFun := f linear := f' map_vadd' p' v := by rw [h, h p', vadd_vsub_assoc, f'.map_add, vadd_vadd] @[simp] theorem coe_mk' (f : P1 → P2) (f' : V1 →ₗ[k] V2) (p h) : ⇑(mk' f f' p h) = f := rfl @[simp] theorem mk'_linear (f : P1 → P2) (f' : V1 →ₗ[k] V2) (p h) : (mk' f f' p h).linear = f' := rfl section SMul variable {R : Type*} [Monoid R] [DistribMulAction R V2] [SMulCommClass k R V2] /-- The space of affine maps to a module inherits an `R`-action from the action on its codomain. -/ instance mulAction : MulAction R (P1 →ᵃ[k] V2) where smul c f := ⟨c • ⇑f, c • f.linear, fun p v => by simp [smul_add]⟩ one_smul _ := ext fun _ => one_smul _ _ mul_smul _ _ _ := ext fun _ => mul_smul _ _ _ @[simp, norm_cast] theorem coe_smul (c : R) (f : P1 →ᵃ[k] V2) : ⇑(c • f) = c • ⇑f := rfl @[simp] theorem smul_linear (t : R) (f : P1 →ᵃ[k] V2) : (t • f).linear = t • f.linear := rfl instance isCentralScalar [DistribMulAction Rᵐᵒᵖ V2] [IsCentralScalar R V2] : IsCentralScalar R (P1 →ᵃ[k] V2) where op_smul_eq_smul _r _x := ext fun _ => op_smul_eq_smul _ _ end SMul instance : Zero (P1 →ᵃ[k] V2) where zero := ⟨0, 0, fun _ _ => (zero_vadd _ _).symm⟩ instance : Add (P1 →ᵃ[k] V2) where add f g := ⟨f + g, f.linear + g.linear, fun p v => by simp [add_add_add_comm]⟩ instance : Sub (P1 →ᵃ[k] V2) where sub f g := ⟨f - g, f.linear - g.linear, fun p v => by simp [sub_add_sub_comm]⟩ instance : Neg (P1 →ᵃ[k] V2) where neg f := ⟨-f, -f.linear, fun p v => by simp [add_comm, map_vadd f]⟩ @[simp, norm_cast] theorem coe_zero : ⇑(0 : P1 →ᵃ[k] V2) = 0 := rfl @[simp, norm_cast] theorem coe_add (f g : P1 →ᵃ[k] V2) : ⇑(f + g) = f + g := rfl @[simp, norm_cast] theorem coe_neg (f : P1 →ᵃ[k] V2) : ⇑(-f) = -f := rfl @[simp, norm_cast] theorem coe_sub (f g : P1 →ᵃ[k] V2) : ⇑(f - g) = f - g := rfl @[simp] theorem zero_linear : (0 : P1 →ᵃ[k] V2).linear = 0 := rfl @[simp] theorem add_linear (f g : P1 →ᵃ[k] V2) : (f + g).linear = f.linear + g.linear := rfl @[simp] theorem sub_linear (f g : P1 →ᵃ[k] V2) : (f - g).linear = f.linear - g.linear := rfl @[simp] theorem neg_linear (f : P1 →ᵃ[k] V2) : (-f).linear = -f.linear := rfl /-- The set of affine maps to a vector space is an additive commutative group. -/ instance : AddCommGroup (P1 →ᵃ[k] V2) := coeFn_injective.addCommGroup _ coe_zero coe_add coe_neg coe_sub (fun _ _ => coe_smul _ _) fun _ _ => coe_smul _ _ /-- The space of affine maps from `P1` to `P2` is an affine space over the space of affine maps from `P1` to the vector space `V2` corresponding to `P2`. -/ instance : AffineSpace (P1 →ᵃ[k] V2) (P1 →ᵃ[k] P2) where vadd f g := ⟨fun p => f p +ᵥ g p, f.linear + g.linear, fun p v => by simp [vadd_vadd, add_right_comm]⟩ zero_vadd f := ext fun p => zero_vadd _ (f p) add_vadd f₁ f₂ f₃ := ext fun p => add_vadd (f₁ p) (f₂ p) (f₃ p) vsub f g := ⟨fun p => f p -ᵥ g p, f.linear - g.linear, fun p v => by simp [vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, add_sub, sub_add_eq_add_sub]⟩ vsub_vadd' f g := ext fun p => vsub_vadd (f p) (g p) vadd_vsub' f g := ext fun p => vadd_vsub (f p) (g p) @[simp] theorem vadd_apply (f : P1 →ᵃ[k] V2) (g : P1 →ᵃ[k] P2) (p : P1) : (f +ᵥ g) p = f p +ᵥ g p := rfl @[simp] theorem vsub_apply (f g : P1 →ᵃ[k] P2) (p : P1) : (f -ᵥ g : P1 →ᵃ[k] V2) p = f p -ᵥ g p := rfl /-- `Prod.fst` as an `AffineMap`. -/ def fst : P1 × P2 →ᵃ[k] P1 where toFun := Prod.fst linear := LinearMap.fst k V1 V2 map_vadd' _ _ := rfl @[simp] theorem coe_fst : ⇑(fst : P1 × P2 →ᵃ[k] P1) = Prod.fst := rfl @[simp] theorem fst_linear : (fst : P1 × P2 →ᵃ[k] P1).linear = LinearMap.fst k V1 V2 := rfl /-- `Prod.snd` as an `AffineMap`. -/ def snd : P1 × P2 →ᵃ[k] P2 where toFun := Prod.snd linear := LinearMap.snd k V1 V2 map_vadd' _ _ := rfl @[simp] theorem coe_snd : ⇑(snd : P1 × P2 →ᵃ[k] P2) = Prod.snd := rfl @[simp] theorem snd_linear : (snd : P1 × P2 →ᵃ[k] P2).linear = LinearMap.snd k V1 V2 := rfl variable (k P1) /-- Identity map as an affine map. -/ nonrec def id : P1 →ᵃ[k] P1 where toFun := id linear := LinearMap.id map_vadd' _ _ := rfl /-- The identity affine map acts as the identity. -/ @[simp, norm_cast] theorem coe_id : ⇑(id k P1) = _root_.id := rfl @[simp] theorem id_linear : (id k P1).linear = LinearMap.id := rfl variable {P1} /-- The identity affine map acts as the identity. -/ theorem id_apply (p : P1) : id k P1 p = p := rfl variable {k} instance : Inhabited (P1 →ᵃ[k] P1) := ⟨id k P1⟩ /-- Composition of affine maps. -/ def comp (f : P2 →ᵃ[k] P3) (g : P1 →ᵃ[k] P2) : P1 →ᵃ[k] P3 where toFun := f ∘ g linear := f.linear.comp g.linear map_vadd' := by intro p v rw [Function.comp_apply, g.map_vadd, f.map_vadd] rfl /-- Composition of affine maps acts as applying the two functions. -/ @[simp] theorem coe_comp (f : P2 →ᵃ[k] P3) (g : P1 →ᵃ[k] P2) : ⇑(f.comp g) = f ∘ g := rfl /-- Composition of affine maps acts as applying the two functions. -/ theorem comp_apply (f : P2 →ᵃ[k] P3) (g : P1 →ᵃ[k] P2) (p : P1) : f.comp g p = f (g p) := rfl @[simp] theorem comp_id (f : P1 →ᵃ[k] P2) : f.comp (id k P1) = f := ext fun _ => rfl @[simp] theorem id_comp (f : P1 →ᵃ[k] P2) : (id k P2).comp f = f := ext fun _ => rfl theorem comp_assoc (f₃₄ : P3 →ᵃ[k] P4) (f₂₃ : P2 →ᵃ[k] P3) (f₁₂ : P1 →ᵃ[k] P2) : (f₃₄.comp f₂₃).comp f₁₂ = f₃₄.comp (f₂₃.comp f₁₂) := rfl instance : Monoid (P1 →ᵃ[k] P1) where one := id k P1 mul := comp one_mul := id_comp mul_one := comp_id mul_assoc := comp_assoc @[simp] theorem coe_mul (f g : P1 →ᵃ[k] P1) : ⇑(f * g) = f ∘ g := rfl @[simp] theorem coe_one : ⇑(1 : P1 →ᵃ[k] P1) = _root_.id := rfl /-- `AffineMap.linear` on endomorphisms is a `MonoidHom`. -/ @[simps] def linearHom : (P1 →ᵃ[k] P1) →* V1 →ₗ[k] V1 where toFun := linear map_one' := rfl map_mul' _ _ := rfl @[simp] theorem linear_injective_iff (f : P1 →ᵃ[k] P2) : Function.Injective f.linear ↔ Function.Injective f := by obtain ⟨p⟩ := (inferInstance : Nonempty P1) have h : ⇑f.linear = (Equiv.vaddConst (f p)).symm ∘ f ∘ Equiv.vaddConst p := by ext v simp [f.map_vadd, vadd_vsub_assoc] rw [h, Equiv.comp_injective, Equiv.injective_comp] @[simp] theorem linear_surjective_iff (f : P1 →ᵃ[k] P2) : Function.Surjective f.linear ↔ Function.Surjective f := by obtain ⟨p⟩ := (inferInstance : Nonempty P1) have h : ⇑f.linear = (Equiv.vaddConst (f p)).symm ∘ f ∘ Equiv.vaddConst p := by ext v simp [f.map_vadd, vadd_vsub_assoc] rw [h, Equiv.comp_surjective, Equiv.surjective_comp] @[simp] theorem linear_bijective_iff (f : P1 →ᵃ[k] P2) : Function.Bijective f.linear ↔ Function.Bijective f := and_congr f.linear_injective_iff f.linear_surjective_iff theorem image_vsub_image {s t : Set P1} (f : P1 →ᵃ[k] P2) : f '' s -ᵥ f '' t = f.linear '' (s -ᵥ t) := by ext v simp only [Set.mem_vsub, Set.mem_image, exists_exists_and_eq_and, exists_and_left, ← f.linearMap_vsub] constructor · rintro ⟨x, hx, y, hy, hv⟩ exact ⟨x -ᵥ y, ⟨x, hx, y, hy, rfl⟩, hv⟩ · rintro ⟨-, ⟨x, hx, y, hy, rfl⟩, rfl⟩ exact ⟨x, hx, y, hy, rfl⟩ /-! ### Definition of `AffineMap.lineMap` and lemmas about it -/ /-- The affine map from `k` to `P1` sending `0` to `p₀` and `1` to `p₁`. -/ def lineMap (p₀ p₁ : P1) : k →ᵃ[k] P1 := ((LinearMap.id : k →ₗ[k] k).smulRight (p₁ -ᵥ p₀)).toAffineMap +ᵥ const k k p₀ theorem coe_lineMap (p₀ p₁ : P1) : (lineMap p₀ p₁ : k → P1) = fun c => c • (p₁ -ᵥ p₀) +ᵥ p₀ := rfl theorem lineMap_apply (p₀ p₁ : P1) (c : k) : lineMap p₀ p₁ c = c • (p₁ -ᵥ p₀) +ᵥ p₀ := rfl theorem lineMap_apply_module' (p₀ p₁ : V1) (c : k) : lineMap p₀ p₁ c = c • (p₁ - p₀) + p₀ := rfl theorem lineMap_apply_module (p₀ p₁ : V1) (c : k) : lineMap p₀ p₁ c = (1 - c) • p₀ + c • p₁ := by simp [lineMap_apply_module', smul_sub, sub_smul]; abel theorem lineMap_apply_ring' (a b c : k) : lineMap a b c = c * (b - a) + a := rfl theorem lineMap_apply_ring (a b c : k) : lineMap a b c = (1 - c) * a + c * b := lineMap_apply_module a b c theorem lineMap_vadd_apply (p : P1) (v : V1) (c : k) : lineMap p (v +ᵥ p) c = c • v +ᵥ p := by rw [lineMap_apply, vadd_vsub] @[simp] theorem lineMap_linear (p₀ p₁ : P1) : (lineMap p₀ p₁ : k →ᵃ[k] P1).linear = LinearMap.id.smulRight (p₁ -ᵥ p₀) := add_zero _ theorem lineMap_same_apply (p : P1) (c : k) : lineMap p p c = p := by simp [lineMap_apply] @[simp] theorem lineMap_same (p : P1) : lineMap p p = const k k p := ext <| lineMap_same_apply p @[simp] theorem lineMap_apply_zero (p₀ p₁ : P1) : lineMap p₀ p₁ (0 : k) = p₀ := by simp [lineMap_apply] @[simp] theorem lineMap_apply_one (p₀ p₁ : P1) : lineMap p₀ p₁ (1 : k) = p₁ := by simp [lineMap_apply] @[simp] theorem lineMap_eq_lineMap_iff [NoZeroSMulDivisors k V1] {p₀ p₁ : P1} {c₁ c₂ : k} : lineMap p₀ p₁ c₁ = lineMap p₀ p₁ c₂ ↔ p₀ = p₁ ∨ c₁ = c₂ := by rw [lineMap_apply, lineMap_apply, ← @vsub_eq_zero_iff_eq V1, vadd_vsub_vadd_cancel_right, ← sub_smul, smul_eq_zero, sub_eq_zero, vsub_eq_zero_iff_eq, or_comm, eq_comm] @[simp] theorem lineMap_eq_left_iff [NoZeroSMulDivisors k V1] {p₀ p₁ : P1} {c : k} : lineMap p₀ p₁ c = p₀ ↔ p₀ = p₁ ∨ c = 0 := by rw [← @lineMap_eq_lineMap_iff k V1, lineMap_apply_zero] @[simp] theorem lineMap_eq_right_iff [NoZeroSMulDivisors k V1] {p₀ p₁ : P1} {c : k} : lineMap p₀ p₁ c = p₁ ↔ p₀ = p₁ ∨ c = 1 := by rw [← @lineMap_eq_lineMap_iff k V1, lineMap_apply_one] variable (k) in theorem lineMap_injective [NoZeroSMulDivisors k V1] {p₀ p₁ : P1} (h : p₀ ≠ p₁) : Function.Injective (lineMap p₀ p₁ : k → P1) := fun _c₁ _c₂ hc => (lineMap_eq_lineMap_iff.mp hc).resolve_left h @[simp] theorem apply_lineMap (f : P1 →ᵃ[k] P2) (p₀ p₁ : P1) (c : k) : f (lineMap p₀ p₁ c) = lineMap (f p₀) (f p₁) c := by simp [lineMap_apply] @[simp] theorem comp_lineMap (f : P1 →ᵃ[k] P2) (p₀ p₁ : P1) : f.comp (lineMap p₀ p₁) = lineMap (f p₀) (f p₁) := ext <| f.apply_lineMap p₀ p₁ @[simp] theorem fst_lineMap (p₀ p₁ : P1 × P2) (c : k) : (lineMap p₀ p₁ c).1 = lineMap p₀.1 p₁.1 c := fst.apply_lineMap p₀ p₁ c @[simp] theorem snd_lineMap (p₀ p₁ : P1 × P2) (c : k) : (lineMap p₀ p₁ c).2 = lineMap p₀.2 p₁.2 c := snd.apply_lineMap p₀ p₁ c theorem lineMap_symm (p₀ p₁ : P1) : lineMap p₀ p₁ = (lineMap p₁ p₀).comp (lineMap (1 : k) (0 : k)) := by rw [comp_lineMap] simp theorem lineMap_apply_one_sub (p₀ p₁ : P1) (c : k) : lineMap p₀ p₁ (1 - c) = lineMap p₁ p₀ c := by rw [lineMap_symm p₀, comp_apply] congr simp [lineMap_apply] @[simp] theorem lineMap_vsub_left (p₀ p₁ : P1) (c : k) : lineMap p₀ p₁ c -ᵥ p₀ = c • (p₁ -ᵥ p₀) := vadd_vsub _ _ @[simp] theorem left_vsub_lineMap (p₀ p₁ : P1) (c : k) : p₀ -ᵥ lineMap p₀ p₁ c = c • (p₀ -ᵥ p₁) := by rw [← neg_vsub_eq_vsub_rev, lineMap_vsub_left, ← smul_neg, neg_vsub_eq_vsub_rev] @[simp] theorem lineMap_vsub_right (p₀ p₁ : P1) (c : k) : lineMap p₀ p₁ c -ᵥ p₁ = (1 - c) • (p₀ -ᵥ p₁) := by rw [← lineMap_apply_one_sub, lineMap_vsub_left] @[simp] theorem right_vsub_lineMap (p₀ p₁ : P1) (c : k) : p₁ -ᵥ lineMap p₀ p₁ c = (1 - c) • (p₁ -ᵥ p₀) := by rw [← lineMap_apply_one_sub, left_vsub_lineMap] theorem lineMap_vadd_lineMap (v₁ v₂ : V1) (p₁ p₂ : P1) (c : k) : lineMap v₁ v₂ c +ᵥ lineMap p₁ p₂ c = lineMap (v₁ +ᵥ p₁) (v₂ +ᵥ p₂) c := ((fst : V1 × P1 →ᵃ[k] V1) +ᵥ (snd : V1 × P1 →ᵃ[k] P1)).apply_lineMap (v₁, p₁) (v₂, p₂) c theorem lineMap_vsub_lineMap (p₁ p₂ p₃ p₄ : P1) (c : k) : lineMap p₁ p₂ c -ᵥ lineMap p₃ p₄ c = lineMap (p₁ -ᵥ p₃) (p₂ -ᵥ p₄) c := ((fst : P1 × P1 →ᵃ[k] P1) -ᵥ (snd : P1 × P1 →ᵃ[k] P1)).apply_lineMap (_, _) (_, _) c @[simp] lemma lineMap_lineMap_right (p₀ p₁ : P1) (c d : k) :
lineMap p₀ (lineMap p₀ p₁ c) d = lineMap p₀ p₁ (d * c) := by simp [lineMap_apply, mul_smul]
Mathlib/LinearAlgebra/AffineSpace/AffineMap.lean
559
560
/- Copyright (c) 2019 Kevin Kappelmann. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Kappelmann -/ import Mathlib.Algebra.ContinuedFractions.Basic import Mathlib.Algebra.GroupWithZero.Basic /-! # Basic Translation Lemmas Between Functions Defined for Continued Fractions ## Summary Some simple translation lemmas between the different definitions of functions defined in `Algebra.ContinuedFractions.Basic`. -/ namespace GenContFract section General /-! ### Translations Between General Access Functions Here we give some basic translations that hold by definition between the various methods that allow us to access the numerators and denominators of a continued fraction. -/ variable {α : Type*} {g : GenContFract α} {n : ℕ} theorem terminatedAt_iff_s_terminatedAt : g.TerminatedAt n ↔ g.s.TerminatedAt n := by rfl theorem terminatedAt_iff_s_none : g.TerminatedAt n ↔ g.s.get? n = none := by rfl theorem partNum_none_iff_s_none : g.partNums.get? n = none ↔ g.s.get? n = none := by cases s_nth_eq : g.s.get? n <;> simp [partNums, s_nth_eq] theorem terminatedAt_iff_partNum_none : g.TerminatedAt n ↔ g.partNums.get? n = none := by rw [terminatedAt_iff_s_none, partNum_none_iff_s_none] theorem partDen_none_iff_s_none : g.partDens.get? n = none ↔ g.s.get? n = none := by cases s_nth_eq : g.s.get? n <;> simp [partDens, s_nth_eq] theorem terminatedAt_iff_partDen_none : g.TerminatedAt n ↔ g.partDens.get? n = none := by rw [terminatedAt_iff_s_none, partDen_none_iff_s_none] theorem partNum_eq_s_a {gp : Pair α} (s_nth_eq : g.s.get? n = some gp) : g.partNums.get? n = some gp.a := by simp [partNums, s_nth_eq] theorem partDen_eq_s_b {gp : Pair α} (s_nth_eq : g.s.get? n = some gp) : g.partDens.get? n = some gp.b := by simp [partDens, s_nth_eq] theorem exists_s_a_of_partNum {a : α} (nth_partNum_eq : g.partNums.get? n = some a) : ∃ gp, g.s.get? n = some gp ∧ gp.a = a := by simpa [partNums, Stream'.Seq.map_get?] using nth_partNum_eq theorem exists_s_b_of_partDen {b : α} (nth_partDen_eq : g.partDens.get? n = some b) : ∃ gp, g.s.get? n = some gp ∧ gp.b = b := by simpa [partDens, Stream'.Seq.map_get?] using nth_partDen_eq end General section WithDivisionRing /-! ### Translations Between Computational Functions Here we give some basic translations that hold by definition for the computational methods of a continued fraction. -/ variable {K : Type*} {g : GenContFract K} {n : ℕ} [DivisionRing K] theorem nth_cont_eq_succ_nth_contAux : g.conts n = g.contsAux (n + 1) := rfl theorem num_eq_conts_a : g.nums n = (g.conts n).a := rfl theorem den_eq_conts_b : g.dens n = (g.conts n).b := rfl theorem conv_eq_num_div_den : g.convs n = g.nums n / g.dens n := rfl theorem conv_eq_conts_a_div_conts_b : g.convs n = (g.conts n).a / (g.conts n).b := rfl theorem exists_conts_a_of_num {A : K} (nth_num_eq : g.nums n = A) : ∃ conts, g.conts n = conts ∧ conts.a = A := by simpa theorem exists_conts_b_of_den {B : K} (nth_denom_eq : g.dens n = B) : ∃ conts, g.conts n = conts ∧ conts.b = B := by simpa @[simp] theorem zeroth_contAux_eq_one_zero : g.contsAux 0 = ⟨1, 0⟩ := rfl @[simp] theorem first_contAux_eq_h_one : g.contsAux 1 = ⟨g.h, 1⟩ := rfl @[simp] theorem zeroth_cont_eq_h_one : g.conts 0 = ⟨g.h, 1⟩ := rfl @[simp] theorem zeroth_num_eq_h : g.nums 0 = g.h := rfl @[simp] theorem zeroth_den_eq_one : g.dens 0 = 1 := rfl @[simp] theorem zeroth_conv_eq_h : g.convs 0 = g.h := by simp [conv_eq_num_div_den, num_eq_conts_a, den_eq_conts_b, div_one] theorem second_contAux_eq {gp : Pair K} (zeroth_s_eq : g.s.get? 0 = some gp) : g.contsAux 2 = ⟨gp.b * g.h + gp.a, gp.b⟩ := by simp [zeroth_s_eq, contsAux, nextConts, nextDen, nextNum] theorem first_cont_eq {gp : Pair K} (zeroth_s_eq : g.s.get? 0 = some gp) : g.conts 1 = ⟨gp.b * g.h + gp.a, gp.b⟩ := by simp [nth_cont_eq_succ_nth_contAux, second_contAux_eq zeroth_s_eq] theorem first_num_eq {gp : Pair K} (zeroth_s_eq : g.s.get? 0 = some gp) : g.nums 1 = gp.b * g.h + gp.a := by simp [num_eq_conts_a, first_cont_eq zeroth_s_eq] theorem first_den_eq {gp : Pair K} (zeroth_s_eq : g.s.get? 0 = some gp) : g.dens 1 = gp.b := by simp [den_eq_conts_b, first_cont_eq zeroth_s_eq] @[simp] theorem zeroth_conv'Aux_eq_zero {s : Stream'.Seq <| Pair K} : convs'Aux s 0 = (0 : K) := rfl @[simp] theorem zeroth_conv'_eq_h : g.convs' 0 = g.h := by simp [convs'] theorem convs'Aux_succ_none {s : Stream'.Seq (Pair K)} (h : s.head = none) (n : ℕ) : convs'Aux s (n + 1) = 0 := by simp [convs'Aux, h] theorem convs'Aux_succ_some {s : Stream'.Seq (Pair K)} {p : Pair K} (h : s.head = some p) (n : ℕ) : convs'Aux s (n + 1) = p.a / (p.b + convs'Aux s.tail n) := by simp [convs'Aux, h] end WithDivisionRing end GenContFract
Mathlib/Algebra/ContinuedFractions/Translations.lean
180
181
/- Copyright (c) 2019 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ -- Some proofs and docs came from mathlib3 `src/algebra/commute.lean` (c) Neil Strickland import Mathlib.Algebra.Group.Defs import Mathlib.Order.Defs.Unbundled /-! # Semiconjugate elements of a semigroup ## Main definitions We say that `x` is semiconjugate to `y` by `a` (`SemiconjBy a x y`), if `a * x = y * a`. In this file we provide operations on `SemiconjBy _ _ _`. In the names of these operations, we treat `a` as the “left” argument, and both `x` and `y` as “right” arguments. This way most names in this file agree with the names of the corresponding lemmas for `Commute a b = SemiconjBy a b b`. As a side effect, some lemmas have only `_right` version. Lean does not immediately recognise these terms as equations, so for rewriting we need syntax like `rw [(h.pow_right 5).eq]` rather than just `rw [h.pow_right 5]`. This file provides only basic operations (`mul_left`, `mul_right`, `inv_right` etc). Other operations (`pow_right`, field inverse etc) are in the files that define corresponding notions. -/ assert_not_exists MonoidWithZero DenselyOrdered variable {S M G : Type*} /-- `x` is semiconjugate to `y` by `a`, if `a * x = y * a`. -/ @[to_additive "`x` is additive semiconjugate to `y` by `a` if `a + x = y + a`"] def SemiconjBy [Mul M] (a x y : M) : Prop := a * x = y * a namespace SemiconjBy /-- Equality behind `SemiconjBy a x y`; useful for rewriting. -/ @[to_additive "Equality behind `AddSemiconjBy a x y`; useful for rewriting."] protected theorem eq [Mul S] {a x y : S} (h : SemiconjBy a x y) : a * x = y * a := h section Semigroup variable [Semigroup S] {a b x y z x' y' : S} /-- If `a` semiconjugates `x` to `y` and `x'` to `y'`, then it semiconjugates `x * x'` to `y * y'`. -/ @[to_additive (attr := simp) "If `a` semiconjugates `x` to `y` and `x'` to `y'`, then it semiconjugates `x + x'` to `y + y'`."] theorem mul_right (h : SemiconjBy a x y) (h' : SemiconjBy a x' y') : SemiconjBy a (x * x') (y * y') := by unfold SemiconjBy -- TODO this could be done using `assoc_rw` if/when this is ported to mathlib4 rw [← mul_assoc, h.eq, mul_assoc, h'.eq, ← mul_assoc] /-- If `b` semiconjugates `x` to `y` and `a` semiconjugates `y` to `z`, then `a * b` semiconjugates `x` to `z`. -/ @[to_additive "If `b` semiconjugates `x` to `y` and `a` semiconjugates `y` to `z`, then `a + b` semiconjugates `x` to `z`."] theorem mul_left (ha : SemiconjBy a y z) (hb : SemiconjBy b x y) : SemiconjBy (a * b) x z := by unfold SemiconjBy rw [mul_assoc, hb.eq, ← mul_assoc, ha.eq, mul_assoc] /-- The relation “there exists an element that semiconjugates `a` to `b`” on a semigroup is transitive. -/ @[to_additive "The relation “there exists an element that semiconjugates `a` to `b`” on an additive semigroup is transitive."] protected theorem transitive : Transitive fun a b : S ↦ ∃ c, SemiconjBy c a b | _, _, _, ⟨x, hx⟩, ⟨y, hy⟩ => ⟨y * x, hy.mul_left hx⟩
end Semigroup
Mathlib/Algebra/Group/Semiconj/Defs.lean
74
76
/- Copyright (c) 2020 Devon Tuma. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Devon Tuma -/ import Mathlib.Probability.ProbabilityMassFunction.Basic /-! # Monad Operations for Probability Mass Functions This file constructs two operations on `PMF` that give it a monad structure. `pure a` is the distribution where a single value `a` has probability `1`. `bind pa pb : PMF β` is the distribution given by sampling `a : α` from `pa : PMF α`, and then sampling from `pb a : PMF β` to get a final result `b : β`. `bindOnSupport` generalizes `bind` to allow binding to a partial function, so that the second argument only needs to be defined on the support of the first argument. -/ noncomputable section variable {α β γ : Type*} open NNReal ENNReal open MeasureTheory namespace PMF section Pure open scoped Classical in /-- The pure `PMF` is the `PMF` where all the mass lies in one point. The value of `pure a` is `1` at `a` and `0` elsewhere. -/ def pure (a : α) : PMF α := ⟨fun a' => if a' = a then 1 else 0, hasSum_ite_eq _ _⟩ variable (a a' : α) open scoped Classical in @[simp] theorem pure_apply : pure a a' = if a' = a then 1 else 0 := rfl @[simp] theorem support_pure : (pure a).support = {a} := Set.ext fun a' => by simp [mem_support_iff] theorem mem_support_pure_iff : a' ∈ (pure a).support ↔ a' = a := by simp theorem pure_apply_self : pure a a = 1 := if_pos rfl theorem pure_apply_of_ne (h : a' ≠ a) : pure a a' = 0 := if_neg h instance [Inhabited α] : Inhabited (PMF α) := ⟨pure default⟩ section Measure variable (s : Set α) open scoped Classical in @[simp] theorem toOuterMeasure_pure_apply : (pure a).toOuterMeasure s = if a ∈ s then 1 else 0 := by refine (toOuterMeasure_apply (pure a) s).trans ?_ split_ifs with ha · refine (tsum_congr fun b => ?_).trans (tsum_ite_eq a 1) exact ite_eq_left_iff.2 fun hb => symm (ite_eq_right_iff.2 fun h => (hb <| h.symm ▸ ha).elim) · refine (tsum_congr fun b => ?_).trans tsum_zero exact ite_eq_right_iff.2 fun hb => ite_eq_right_iff.2 fun h => (ha <| h ▸ hb).elim variable [MeasurableSpace α] open scoped Classical in /-- The measure of a set under `pure a` is `1` for sets containing `a` and `0` otherwise. -/ @[simp] theorem toMeasure_pure_apply (hs : MeasurableSet s) : (pure a).toMeasure s = if a ∈ s then 1 else 0 := (toMeasure_apply_eq_toOuterMeasure_apply (pure a) s hs).trans (toOuterMeasure_pure_apply a s) theorem toMeasure_pure : (pure a).toMeasure = Measure.dirac a := Measure.ext fun s hs => by rw [toMeasure_pure_apply a s hs, Measure.dirac_apply' a hs]; rfl @[simp] theorem toPMF_dirac [Countable α] [h : MeasurableSingletonClass α] : (Measure.dirac a).toPMF = pure a := by rw [toPMF_eq_iff_toMeasure_eq, toMeasure_pure] end Measure end Pure section Bind /-- The monadic bind operation for `PMF`. -/ def bind (p : PMF α) (f : α → PMF β) : PMF β := ⟨fun b => ∑' a, p a * f a b, ENNReal.summable.hasSum_iff.2 (ENNReal.tsum_comm.trans <| by simp only [ENNReal.tsum_mul_left, tsum_coe, mul_one])⟩ variable (p : PMF α) (f : α → PMF β) (g : β → PMF γ) @[simp] theorem bind_apply (b : β) : p.bind f b = ∑' a, p a * f a b := rfl @[simp] theorem support_bind : (p.bind f).support = ⋃ a ∈ p.support, (f a).support := Set.ext fun b => by simp [mem_support_iff, ENNReal.tsum_eq_zero, not_or] theorem mem_support_bind_iff (b : β) : b ∈ (p.bind f).support ↔ ∃ a ∈ p.support, b ∈ (f a).support := by simp only [support_bind, Set.mem_iUnion, Set.mem_setOf_eq, exists_prop] @[simp] theorem pure_bind (a : α) (f : α → PMF β) : (pure a).bind f = f a := by classical have : ∀ b a', ite (a' = a) (f a' b) 0 = ite (a' = a) (f a b) 0 := fun b a' => by split_ifs with h <;> simp [h] ext b simp [this] @[simp] theorem bind_pure : p.bind pure = p := PMF.ext fun x => (bind_apply _ _ _).trans (_root_.trans (tsum_eq_single x fun y hy => by rw [pure_apply_of_ne _ _ hy.symm, mul_zero]) <| by rw [pure_apply_self, mul_one])
@[simp] theorem bind_const (p : PMF α) (q : PMF β) : (p.bind fun _ => q) = q := PMF.ext fun x => by rw [bind_apply, ENNReal.tsum_mul_right, tsum_coe, one_mul]
Mathlib/Probability/ProbabilityMassFunction/Monad.lean
132
136
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Topology.UniformSpace.Cauchy /-! # Uniform convergence A sequence of functions `Fₙ` (with values in a metric space) converges uniformly on a set `s` to a function `f` if, for all `ε > 0`, for all large enough `n`, one has for all `y ∈ s` the inequality `dist (f y, Fₙ y) < ε`. Under uniform convergence, many properties of the `Fₙ` pass to the limit, most notably continuity. We prove this in the file, defining the notion of uniform convergence in the more general setting of uniform spaces, and with respect to an arbitrary indexing set endowed with a filter (instead of just `ℕ` with `atTop`). ## Main results Let `α` be a topological space, `β` a uniform space, `Fₙ` and `f` be functions from `α` to `β` (where the index `n` belongs to an indexing type `ι` endowed with a filter `p`). * `TendstoUniformlyOn F f p s`: the fact that `Fₙ` converges uniformly to `f` on `s`. This means that, for any entourage `u` of the diagonal, for large enough `n` (with respect to `p`), one has `(f y, Fₙ y) ∈ u` for all `y ∈ s`. * `TendstoUniformly F f p`: same notion with `s = univ`. * `TendstoUniformlyOn.continuousOn`: a uniform limit on a set of functions which are continuous on this set is itself continuous on this set. * `TendstoUniformly.continuous`: a uniform limit of continuous functions is continuous. * `TendstoUniformlyOn.tendsto_comp`: If `Fₙ` tends uniformly to `f` on a set `s`, and `gₙ` tends to `x` within `s`, then `Fₙ gₙ` tends to `f x` if `f` is continuous at `x` within `s`. * `TendstoUniformly.tendsto_comp`: If `Fₙ` tends uniformly to `f`, and `gₙ` tends to `x`, then `Fₙ gₙ` tends to `f x`. Finally, we introduce the notion of a uniform Cauchy sequence, which is to uniform convergence what a Cauchy sequence is to the usual notion of convergence. ## Implementation notes We derive most of our initial results from an auxiliary definition `TendstoUniformlyOnFilter`. This definition in and of itself can sometimes be useful, e.g., when studying the local behavior of the `Fₙ` near a point, which would typically look like `TendstoUniformlyOnFilter F f p (𝓝 x)`. Still, while this may be the "correct" definition (see `tendstoUniformlyOn_iff_tendstoUniformlyOnFilter`), it is somewhat unwieldy to work with in practice. Thus, we provide the more traditional definition in `TendstoUniformlyOn`. ## Tags Uniform limit, uniform convergence, tends uniformly to -/ noncomputable section open Topology Uniformity Filter Set Uniform variable {α β γ ι : Type*} [UniformSpace β] variable {F : ι → α → β} {f : α → β} {s s' : Set α} {x : α} {p : Filter ι} {p' : Filter α} /-! ### Different notions of uniform convergence We define uniform convergence, on a set or in the whole space. -/ /-- A sequence of functions `Fₙ` converges uniformly on a filter `p'` to a limiting function `f` with respect to the filter `p` if, for any entourage of the diagonal `u`, one has `p ×ˢ p'`-eventually `(f x, Fₙ x) ∈ u`. -/ def TendstoUniformlyOnFilter (F : ι → α → β) (f : α → β) (p : Filter ι) (p' : Filter α) := ∀ u ∈ 𝓤 β, ∀ᶠ n : ι × α in p ×ˢ p', (f n.snd, F n.fst n.snd) ∈ u /-- A sequence of functions `Fₙ` converges uniformly on a filter `p'` to a limiting function `f` w.r.t. filter `p` iff the function `(n, x) ↦ (f x, Fₙ x)` converges along `p ×ˢ p'` to the uniformity. In other words: one knows nothing about the behavior of `x` in this limit besides it being in `p'`. -/ theorem tendstoUniformlyOnFilter_iff_tendsto : TendstoUniformlyOnFilter F f p p' ↔ Tendsto (fun q : ι × α => (f q.2, F q.1 q.2)) (p ×ˢ p') (𝓤 β) := Iff.rfl /-- A sequence of functions `Fₙ` converges uniformly on a set `s` to a limiting function `f` with respect to the filter `p` if, for any entourage of the diagonal `u`, one has `p`-eventually `(f x, Fₙ x) ∈ u` for all `x ∈ s`. -/ def TendstoUniformlyOn (F : ι → α → β) (f : α → β) (p : Filter ι) (s : Set α) := ∀ u ∈ 𝓤 β, ∀ᶠ n in p, ∀ x : α, x ∈ s → (f x, F n x) ∈ u theorem tendstoUniformlyOn_iff_tendstoUniformlyOnFilter : TendstoUniformlyOn F f p s ↔ TendstoUniformlyOnFilter F f p (𝓟 s) := by simp only [TendstoUniformlyOn, TendstoUniformlyOnFilter] apply forall₂_congr simp_rw [eventually_prod_principal_iff] simp alias ⟨TendstoUniformlyOn.tendstoUniformlyOnFilter, TendstoUniformlyOnFilter.tendstoUniformlyOn⟩ := tendstoUniformlyOn_iff_tendstoUniformlyOnFilter /-- A sequence of functions `Fₙ` converges uniformly on a set `s` to a limiting function `f` w.r.t. filter `p` iff the function `(n, x) ↦ (f x, Fₙ x)` converges along `p ×ˢ 𝓟 s` to the uniformity. In other words: one knows nothing about the behavior of `x` in this limit besides it being in `s`. -/ theorem tendstoUniformlyOn_iff_tendsto : TendstoUniformlyOn F f p s ↔ Tendsto (fun q : ι × α => (f q.2, F q.1 q.2)) (p ×ˢ 𝓟 s) (𝓤 β) := by simp [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter, tendstoUniformlyOnFilter_iff_tendsto] /-- A sequence of functions `Fₙ` converges uniformly to a limiting function `f` with respect to a filter `p` if, for any entourage of the diagonal `u`, one has `p`-eventually `(f x, Fₙ x) ∈ u` for all `x`. -/ def TendstoUniformly (F : ι → α → β) (f : α → β) (p : Filter ι) := ∀ u ∈ 𝓤 β, ∀ᶠ n in p, ∀ x : α, (f x, F n x) ∈ u theorem tendstoUniformlyOn_univ : TendstoUniformlyOn F f p univ ↔ TendstoUniformly F f p := by simp [TendstoUniformlyOn, TendstoUniformly] theorem tendstoUniformly_iff_tendstoUniformlyOnFilter : TendstoUniformly F f p ↔ TendstoUniformlyOnFilter F f p ⊤ := by rw [← tendstoUniformlyOn_univ, tendstoUniformlyOn_iff_tendstoUniformlyOnFilter, principal_univ] theorem TendstoUniformly.tendstoUniformlyOnFilter (h : TendstoUniformly F f p) : TendstoUniformlyOnFilter F f p ⊤ := by rwa [← tendstoUniformly_iff_tendstoUniformlyOnFilter] theorem tendstoUniformlyOn_iff_tendstoUniformly_comp_coe : TendstoUniformlyOn F f p s ↔ TendstoUniformly (fun i (x : s) => F i x) (f ∘ (↑)) p := forall₂_congr fun u _ => by simp /-- A sequence of functions `Fₙ` converges uniformly to a limiting function `f` w.r.t. filter `p` iff the function `(n, x) ↦ (f x, Fₙ x)` converges along `p ×ˢ ⊤` to the uniformity. In other words: one knows nothing about the behavior of `x` in this limit. -/ theorem tendstoUniformly_iff_tendsto : TendstoUniformly F f p ↔ Tendsto (fun q : ι × α => (f q.2, F q.1 q.2)) (p ×ˢ ⊤) (𝓤 β) := by simp [tendstoUniformly_iff_tendstoUniformlyOnFilter, tendstoUniformlyOnFilter_iff_tendsto] /-- Uniform convergence implies pointwise convergence. -/ theorem TendstoUniformlyOnFilter.tendsto_at (h : TendstoUniformlyOnFilter F f p p') (hx : 𝓟 {x} ≤ p') : Tendsto (fun n => F n x) p <| 𝓝 (f x) := by refine Uniform.tendsto_nhds_right.mpr fun u hu => mem_map.mpr ?_ filter_upwards [(h u hu).curry] intro i h simpa using h.filter_mono hx /-- Uniform convergence implies pointwise convergence. -/ theorem TendstoUniformlyOn.tendsto_at (h : TendstoUniformlyOn F f p s) (hx : x ∈ s) : Tendsto (fun n => F n x) p <| 𝓝 (f x) := h.tendstoUniformlyOnFilter.tendsto_at (le_principal_iff.mpr <| mem_principal.mpr <| singleton_subset_iff.mpr <| hx) /-- Uniform convergence implies pointwise convergence. -/ theorem TendstoUniformly.tendsto_at (h : TendstoUniformly F f p) (x : α) : Tendsto (fun n => F n x) p <| 𝓝 (f x) := h.tendstoUniformlyOnFilter.tendsto_at le_top theorem TendstoUniformlyOnFilter.mono_left {p'' : Filter ι} (h : TendstoUniformlyOnFilter F f p p') (hp : p'' ≤ p) : TendstoUniformlyOnFilter F f p'' p' := fun u hu => (h u hu).filter_mono (p'.prod_mono_left hp) theorem TendstoUniformlyOnFilter.mono_right {p'' : Filter α} (h : TendstoUniformlyOnFilter F f p p') (hp : p'' ≤ p') : TendstoUniformlyOnFilter F f p p'' := fun u hu => (h u hu).filter_mono (p.prod_mono_right hp) theorem TendstoUniformlyOn.mono (h : TendstoUniformlyOn F f p s) (h' : s' ⊆ s) : TendstoUniformlyOn F f p s' := tendstoUniformlyOn_iff_tendstoUniformlyOnFilter.mpr (h.tendstoUniformlyOnFilter.mono_right (le_principal_iff.mpr <| mem_principal.mpr h')) theorem TendstoUniformlyOnFilter.congr {F' : ι → α → β} (hf : TendstoUniformlyOnFilter F f p p') (hff' : ∀ᶠ n : ι × α in p ×ˢ p', F n.fst n.snd = F' n.fst n.snd) : TendstoUniformlyOnFilter F' f p p' := by refine fun u hu => ((hf u hu).and hff').mono fun n h => ?_ rw [← h.right] exact h.left theorem TendstoUniformlyOn.congr {F' : ι → α → β} (hf : TendstoUniformlyOn F f p s) (hff' : ∀ᶠ n in p, Set.EqOn (F n) (F' n) s) : TendstoUniformlyOn F' f p s := by rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter] at hf ⊢ refine hf.congr ?_ rw [eventually_iff] at hff' ⊢ simp only [Set.EqOn] at hff' simp only [mem_prod_principal, hff', mem_setOf_eq] lemma tendstoUniformly_congr {F' : ι → α → β} (hF : F =ᶠ[p] F') : TendstoUniformly F f p ↔ TendstoUniformly F' f p := by simp_rw [← tendstoUniformlyOn_univ] at * have HF := EventuallyEq.exists_mem hF exact ⟨fun h => h.congr (by aesop), fun h => h.congr (by simp_rw [eqOn_comm]; aesop)⟩ theorem TendstoUniformlyOn.congr_right {g : α → β} (hf : TendstoUniformlyOn F f p s) (hfg : EqOn f g s) : TendstoUniformlyOn F g p s := fun u hu => by filter_upwards [hf u hu] with i hi a ha using hfg ha ▸ hi a ha protected theorem TendstoUniformly.tendstoUniformlyOn (h : TendstoUniformly F f p) : TendstoUniformlyOn F f p s := (tendstoUniformlyOn_univ.2 h).mono (subset_univ s) /-- Composing on the right by a function preserves uniform convergence on a filter -/ theorem TendstoUniformlyOnFilter.comp (h : TendstoUniformlyOnFilter F f p p') (g : γ → α) : TendstoUniformlyOnFilter (fun n => F n ∘ g) (f ∘ g) p (p'.comap g) := by rw [tendstoUniformlyOnFilter_iff_tendsto] at h ⊢ exact h.comp (tendsto_id.prodMap tendsto_comap) /-- Composing on the right by a function preserves uniform convergence on a set -/ theorem TendstoUniformlyOn.comp (h : TendstoUniformlyOn F f p s) (g : γ → α) : TendstoUniformlyOn (fun n => F n ∘ g) (f ∘ g) p (g ⁻¹' s) := by rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter] at h ⊢ simpa [TendstoUniformlyOn, comap_principal] using TendstoUniformlyOnFilter.comp h g /-- Composing on the right by a function preserves uniform convergence -/ theorem TendstoUniformly.comp (h : TendstoUniformly F f p) (g : γ → α) : TendstoUniformly (fun n => F n ∘ g) (f ∘ g) p := by rw [tendstoUniformly_iff_tendstoUniformlyOnFilter] at h ⊢ simpa [principal_univ, comap_principal] using h.comp g /-- Composing on the left by a uniformly continuous function preserves uniform convergence on a filter -/ theorem UniformContinuous.comp_tendstoUniformlyOnFilter [UniformSpace γ] {g : β → γ} (hg : UniformContinuous g) (h : TendstoUniformlyOnFilter F f p p') : TendstoUniformlyOnFilter (fun i => g ∘ F i) (g ∘ f) p p' := fun _u hu => h _ (hg hu) /-- Composing on the left by a uniformly continuous function preserves uniform convergence on a set -/ theorem UniformContinuous.comp_tendstoUniformlyOn [UniformSpace γ] {g : β → γ} (hg : UniformContinuous g) (h : TendstoUniformlyOn F f p s) : TendstoUniformlyOn (fun i => g ∘ F i) (g ∘ f) p s := fun _u hu => h _ (hg hu) /-- Composing on the left by a uniformly continuous function preserves uniform convergence -/ theorem UniformContinuous.comp_tendstoUniformly [UniformSpace γ] {g : β → γ} (hg : UniformContinuous g) (h : TendstoUniformly F f p) : TendstoUniformly (fun i => g ∘ F i) (g ∘ f) p := fun _u hu => h _ (hg hu) theorem TendstoUniformlyOnFilter.prodMap {ι' α' β' : Type*} [UniformSpace β'] {F' : ι' → α' → β'} {f' : α' → β'} {q : Filter ι'} {q' : Filter α'} (h : TendstoUniformlyOnFilter F f p p') (h' : TendstoUniformlyOnFilter F' f' q q') : TendstoUniformlyOnFilter (fun i : ι × ι' => Prod.map (F i.1) (F' i.2)) (Prod.map f f') (p ×ˢ q) (p' ×ˢ q') := by rw [tendstoUniformlyOnFilter_iff_tendsto] at h h' ⊢ rw [uniformity_prod_eq_comap_prod, tendsto_comap_iff, ← map_swap4_prod, tendsto_map'_iff] simpa using h.prodMap h' @[deprecated (since := "2025-03-10")] alias TendstoUniformlyOnFilter.prod_map := TendstoUniformlyOnFilter.prodMap theorem TendstoUniformlyOn.prodMap {ι' α' β' : Type*} [UniformSpace β'] {F' : ι' → α' → β'} {f' : α' → β'} {p' : Filter ι'} {s' : Set α'} (h : TendstoUniformlyOn F f p s) (h' : TendstoUniformlyOn F' f' p' s') : TendstoUniformlyOn (fun i : ι × ι' => Prod.map (F i.1) (F' i.2)) (Prod.map f f') (p ×ˢ p') (s ×ˢ s') := by rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter] at h h' ⊢ simpa only [prod_principal_principal] using h.prodMap h' @[deprecated (since := "2025-03-10")] alias TendstoUniformlyOn.prod_map := TendstoUniformlyOn.prodMap theorem TendstoUniformly.prodMap {ι' α' β' : Type*} [UniformSpace β'] {F' : ι' → α' → β'} {f' : α' → β'} {p' : Filter ι'} (h : TendstoUniformly F f p) (h' : TendstoUniformly F' f' p') : TendstoUniformly (fun i : ι × ι' => Prod.map (F i.1) (F' i.2)) (Prod.map f f') (p ×ˢ p') := by rw [← tendstoUniformlyOn_univ, ← univ_prod_univ] at * exact h.prodMap h' @[deprecated (since := "2025-03-10")] alias TendstoUniformly.prod_map := TendstoUniformly.prodMap theorem TendstoUniformlyOnFilter.prodMk {ι' β' : Type*} [UniformSpace β'] {F' : ι' → α → β'} {f' : α → β'} {q : Filter ι'} (h : TendstoUniformlyOnFilter F f p p') (h' : TendstoUniformlyOnFilter F' f' q p') : TendstoUniformlyOnFilter (fun (i : ι × ι') a => (F i.1 a, F' i.2 a)) (fun a => (f a, f' a)) (p ×ˢ q) p' := fun u hu => ((h.prodMap h') u hu).diag_of_prod_right @[deprecated (since := "2025-03-10")] alias TendstoUniformlyOnFilter.prod := TendstoUniformlyOnFilter.prodMk protected theorem TendstoUniformlyOn.prodMk {ι' β' : Type*} [UniformSpace β'] {F' : ι' → α → β'} {f' : α → β'} {p' : Filter ι'} (h : TendstoUniformlyOn F f p s) (h' : TendstoUniformlyOn F' f' p' s) : TendstoUniformlyOn (fun (i : ι × ι') a => (F i.1 a, F' i.2 a)) (fun a => (f a, f' a)) (p ×ˢ p') s := (congr_arg _ s.inter_self).mp ((h.prodMap h').comp fun a => (a, a)) @[deprecated (since := "2025-03-10")] alias TendstoUniformlyOn.prod := TendstoUniformlyOn.prodMk theorem TendstoUniformly.prodMk {ι' β' : Type*} [UniformSpace β'] {F' : ι' → α → β'} {f' : α → β'} {p' : Filter ι'} (h : TendstoUniformly F f p) (h' : TendstoUniformly F' f' p') : TendstoUniformly (fun (i : ι × ι') a => (F i.1 a, F' i.2 a)) (fun a => (f a, f' a)) (p ×ˢ p') := (h.prodMap h').comp fun a => (a, a) @[deprecated (since := "2025-03-10")] alias TendstoUniformly.prod := TendstoUniformly.prodMk /-- Uniform convergence on a filter `p'` to a constant function is equivalent to convergence in `p ×ˢ p'`. -/ theorem tendsto_prod_filter_iff {c : β} : Tendsto (↿F) (p ×ˢ p') (𝓝 c) ↔ TendstoUniformlyOnFilter F (fun _ => c) p p' := by simp_rw [nhds_eq_comap_uniformity, tendsto_comap_iff] rfl /-- Uniform convergence on a set `s` to a constant function is equivalent to convergence in `p ×ˢ 𝓟 s`. -/ theorem tendsto_prod_principal_iff {c : β} : Tendsto (↿F) (p ×ˢ 𝓟 s) (𝓝 c) ↔ TendstoUniformlyOn F (fun _ => c) p s := by rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter] exact tendsto_prod_filter_iff /-- Uniform convergence to a constant function is equivalent to convergence in `p ×ˢ ⊤`. -/ theorem tendsto_prod_top_iff {c : β} : Tendsto (↿F) (p ×ˢ ⊤) (𝓝 c) ↔ TendstoUniformly F (fun _ => c) p := by rw [tendstoUniformly_iff_tendstoUniformlyOnFilter] exact tendsto_prod_filter_iff /-- Uniform convergence on the empty set is vacuously true -/ theorem tendstoUniformlyOn_empty : TendstoUniformlyOn F f p ∅ := fun u _ => by simp /-- Uniform convergence on a singleton is equivalent to regular convergence -/ theorem tendstoUniformlyOn_singleton_iff_tendsto : TendstoUniformlyOn F f p {x} ↔ Tendsto (fun n : ι => F n x) p (𝓝 (f x)) := by simp_rw [tendstoUniformlyOn_iff_tendsto, Uniform.tendsto_nhds_right, tendsto_def] exact forall₂_congr fun u _ => by simp [mem_prod_principal, preimage] /-- If a sequence `g` converges to some `b`, then the sequence of constant functions `fun n ↦ fun a ↦ g n` converges to the constant function `fun a ↦ b` on any set `s` -/ theorem Filter.Tendsto.tendstoUniformlyOnFilter_const {g : ι → β} {b : β} (hg : Tendsto g p (𝓝 b)) (p' : Filter α) : TendstoUniformlyOnFilter (fun n : ι => fun _ : α => g n) (fun _ : α => b) p p' := by simpa only [nhds_eq_comap_uniformity, tendsto_comap_iff] using hg.comp (tendsto_fst (g := p')) /-- If a sequence `g` converges to some `b`, then the sequence of constant functions `fun n ↦ fun a ↦ g n` converges to the constant function `fun a ↦ b` on any set `s` -/ theorem Filter.Tendsto.tendstoUniformlyOn_const {g : ι → β} {b : β} (hg : Tendsto g p (𝓝 b)) (s : Set α) : TendstoUniformlyOn (fun n : ι => fun _ : α => g n) (fun _ : α => b) p s := tendstoUniformlyOn_iff_tendstoUniformlyOnFilter.mpr (hg.tendstoUniformlyOnFilter_const (𝓟 s)) theorem UniformContinuousOn.tendstoUniformlyOn [UniformSpace α] [UniformSpace γ] {U : Set α} {V : Set β} {F : α → β → γ} (hF : UniformContinuousOn (↿F) (U ×ˢ V)) (hU : x ∈ U) : TendstoUniformlyOn F (F x) (𝓝[U] x) V := by set φ := fun q : α × β => ((x, q.2), q) rw [tendstoUniformlyOn_iff_tendsto] change Tendsto (Prod.map (↿F) ↿F ∘ φ) (𝓝[U] x ×ˢ 𝓟 V) (𝓤 γ) simp only [nhdsWithin, Filter.prod_eq_inf, comap_inf, inf_assoc, comap_principal, inf_principal] refine hF.comp (Tendsto.inf ?_ <| tendsto_principal_principal.2 fun x hx => ⟨⟨hU, hx.2⟩, hx⟩) simp only [uniformity_prod_eq_comap_prod, tendsto_comap_iff, (· ∘ ·), nhds_eq_comap_uniformity, comap_comap] exact tendsto_comap.prodMk (tendsto_diag_uniformity _ _) theorem UniformContinuousOn.tendstoUniformly [UniformSpace α] [UniformSpace γ] {U : Set α} (hU : U ∈ 𝓝 x) {F : α → β → γ} (hF : UniformContinuousOn (↿F) (U ×ˢ (univ : Set β))) : TendstoUniformly F (F x) (𝓝 x) := by simpa only [tendstoUniformlyOn_univ, nhdsWithin_eq_nhds.2 hU] using hF.tendstoUniformlyOn (mem_of_mem_nhds hU) theorem UniformContinuous₂.tendstoUniformly [UniformSpace α] [UniformSpace γ] {f : α → β → γ} (h : UniformContinuous₂ f) : TendstoUniformly f (f x) (𝓝 x) := UniformContinuousOn.tendstoUniformly univ_mem <| by rwa [univ_prod_univ, uniformContinuousOn_univ] /-- A sequence is uniformly Cauchy if eventually all of its pairwise differences are uniformly bounded -/ def UniformCauchySeqOnFilter (F : ι → α → β) (p : Filter ι) (p' : Filter α) : Prop := ∀ u ∈ 𝓤 β, ∀ᶠ m : (ι × ι) × α in (p ×ˢ p) ×ˢ p', (F m.fst.fst m.snd, F m.fst.snd m.snd) ∈ u /-- A sequence is uniformly Cauchy if eventually all of its pairwise differences are uniformly bounded -/ def UniformCauchySeqOn (F : ι → α → β) (p : Filter ι) (s : Set α) : Prop := ∀ u ∈ 𝓤 β, ∀ᶠ m : ι × ι in p ×ˢ p, ∀ x : α, x ∈ s → (F m.fst x, F m.snd x) ∈ u theorem uniformCauchySeqOn_iff_uniformCauchySeqOnFilter : UniformCauchySeqOn F p s ↔ UniformCauchySeqOnFilter F p (𝓟 s) := by simp only [UniformCauchySeqOn, UniformCauchySeqOnFilter] refine forall₂_congr fun u hu => ?_ rw [eventually_prod_principal_iff] theorem UniformCauchySeqOn.uniformCauchySeqOnFilter (hF : UniformCauchySeqOn F p s) : UniformCauchySeqOnFilter F p (𝓟 s) := by rwa [← uniformCauchySeqOn_iff_uniformCauchySeqOnFilter] /-- A sequence that converges uniformly is also uniformly Cauchy -/ theorem TendstoUniformlyOnFilter.uniformCauchySeqOnFilter (hF : TendstoUniformlyOnFilter F f p p') : UniformCauchySeqOnFilter F p p' := by intro u hu rcases comp_symm_of_uniformity hu with ⟨t, ht, htsymm, htmem⟩ have := tendsto_swap4_prod.eventually ((hF t ht).prod_mk (hF t ht)) apply this.diag_of_prod_right.mono simp only [and_imp, Prod.forall] intro n1 n2 x hl hr exact Set.mem_of_mem_of_subset (prodMk_mem_compRel (htsymm hl) hr) htmem /-- A sequence that converges uniformly is also uniformly Cauchy -/ theorem TendstoUniformlyOn.uniformCauchySeqOn (hF : TendstoUniformlyOn F f p s) : UniformCauchySeqOn F p s := uniformCauchySeqOn_iff_uniformCauchySeqOnFilter.mpr hF.tendstoUniformlyOnFilter.uniformCauchySeqOnFilter /-- A uniformly Cauchy sequence converges uniformly to its limit -/ theorem UniformCauchySeqOnFilter.tendstoUniformlyOnFilter_of_tendsto (hF : UniformCauchySeqOnFilter F p p') (hF' : ∀ᶠ x : α in p', Tendsto (fun n => F n x) p (𝓝 (f x))) : TendstoUniformlyOnFilter F f p p' := by rcases p.eq_or_neBot with rfl | _ · simp only [TendstoUniformlyOnFilter, bot_prod, eventually_bot, implies_true] -- Proof idea: |f_n(x) - f(x)| ≤ |f_n(x) - f_m(x)| + |f_m(x) - f(x)|. We choose `n` -- so that |f_n(x) - f_m(x)| is uniformly small across `s` whenever `m ≥ n`. Then for -- a fixed `x`, we choose `m` sufficiently large such that |f_m(x) - f(x)| is small. intro u hu rcases comp_symm_of_uniformity hu with ⟨t, ht, htsymm, htmem⟩ -- We will choose n, x, and m simultaneously. n and x come from hF. m comes from hF' -- But we need to promote hF' to the full product filter to use it have hmc : ∀ᶠ x in (p ×ˢ p) ×ˢ p', Tendsto (fun n : ι => F n x.snd) p (𝓝 (f x.snd)) := by rw [eventually_prod_iff] exact ⟨fun _ => True, by simp, _, hF', by simp⟩ -- To apply filter operations we'll need to do some order manipulation rw [Filter.eventually_swap_iff] have := tendsto_prodAssoc.eventually (tendsto_prod_swap.eventually ((hF t ht).and hmc)) apply this.curry.mono simp only [Equiv.prodAssoc_apply, eventually_and, eventually_const, Prod.snd_swap, Prod.fst_swap, and_imp, Prod.forall] -- Complete the proof intro x n hx hm' refine Set.mem_of_mem_of_subset (mem_compRel.mpr ?_) htmem rw [Uniform.tendsto_nhds_right] at hm' have := hx.and (hm' ht) obtain ⟨m, hm⟩ := this.exists exact ⟨F m x, ⟨hm.2, htsymm hm.1⟩⟩ /-- A uniformly Cauchy sequence converges uniformly to its limit -/ theorem UniformCauchySeqOn.tendstoUniformlyOn_of_tendsto (hF : UniformCauchySeqOn F p s) (hF' : ∀ x : α, x ∈ s → Tendsto (fun n => F n x) p (𝓝 (f x))) : TendstoUniformlyOn F f p s := tendstoUniformlyOn_iff_tendstoUniformlyOnFilter.mpr (hF.uniformCauchySeqOnFilter.tendstoUniformlyOnFilter_of_tendsto hF') theorem UniformCauchySeqOnFilter.mono_left {p'' : Filter ι} (hf : UniformCauchySeqOnFilter F p p') (hp : p'' ≤ p) : UniformCauchySeqOnFilter F p'' p' := by intro u hu have := (hf u hu).filter_mono (p'.prod_mono_left (Filter.prod_mono hp hp)) exact this.mono (by simp) theorem UniformCauchySeqOnFilter.mono_right {p'' : Filter α} (hf : UniformCauchySeqOnFilter F p p') (hp : p'' ≤ p') : UniformCauchySeqOnFilter F p p'' := fun u hu => have := (hf u hu).filter_mono ((p ×ˢ p).prod_mono_right hp) this.mono (by simp) theorem UniformCauchySeqOn.mono (hf : UniformCauchySeqOn F p s) (hss' : s' ⊆ s) : UniformCauchySeqOn F p s' := by rw [uniformCauchySeqOn_iff_uniformCauchySeqOnFilter] at hf ⊢ exact hf.mono_right (le_principal_iff.mpr <| mem_principal.mpr hss') /-- Composing on the right by a function preserves uniform Cauchy sequences -/ theorem UniformCauchySeqOnFilter.comp {γ : Type*} (hf : UniformCauchySeqOnFilter F p p') (g : γ → α) : UniformCauchySeqOnFilter (fun n => F n ∘ g) p (p'.comap g) := fun u hu => by obtain ⟨pa, hpa, pb, hpb, hpapb⟩ := eventually_prod_iff.mp (hf u hu) rw [eventually_prod_iff] refine ⟨pa, hpa, pb ∘ g, ?_, fun hx _ hy => hpapb hx hy⟩ exact eventually_comap.mpr (hpb.mono fun x hx y hy => by simp only [hx, hy, Function.comp_apply]) /-- Composing on the right by a function preserves uniform Cauchy sequences -/ theorem UniformCauchySeqOn.comp {γ : Type*} (hf : UniformCauchySeqOn F p s) (g : γ → α) : UniformCauchySeqOn (fun n => F n ∘ g) p (g ⁻¹' s) := by rw [uniformCauchySeqOn_iff_uniformCauchySeqOnFilter] at hf ⊢ simpa only [UniformCauchySeqOn, comap_principal] using hf.comp g /-- Composing on the left by a uniformly continuous function preserves uniform Cauchy sequences -/ theorem UniformContinuous.comp_uniformCauchySeqOn [UniformSpace γ] {g : β → γ} (hg : UniformContinuous g) (hf : UniformCauchySeqOn F p s) : UniformCauchySeqOn (fun n => g ∘ F n) p s := fun _u hu => hf _ (hg hu) theorem UniformCauchySeqOn.prodMap {ι' α' β' : Type*} [UniformSpace β'] {F' : ι' → α' → β'} {p' : Filter ι'} {s' : Set α'} (h : UniformCauchySeqOn F p s) (h' : UniformCauchySeqOn F' p' s') : UniformCauchySeqOn (fun i : ι × ι' => Prod.map (F i.1) (F' i.2)) (p ×ˢ p') (s ×ˢ s') := by intro u hu rw [uniformity_prod_eq_prod, mem_map, mem_prod_iff] at hu obtain ⟨v, hv, w, hw, hvw⟩ := hu simp_rw [mem_prod, and_imp, Prod.forall, Prod.map_apply] rw [← Set.image_subset_iff] at hvw apply (tendsto_swap4_prod.eventually ((h v hv).prod_mk (h' w hw))).mono intro x hx a b ha hb exact hvw ⟨_, mk_mem_prod (hx.1 a ha) (hx.2 b hb), rfl⟩ @[deprecated (since := "2025-03-10")] alias UniformCauchySeqOn.prod_map := UniformCauchySeqOn.prodMap theorem UniformCauchySeqOn.prod {ι' β' : Type*} [UniformSpace β'] {F' : ι' → α → β'} {p' : Filter ι'} (h : UniformCauchySeqOn F p s) (h' : UniformCauchySeqOn F' p' s) : UniformCauchySeqOn (fun (i : ι × ι') a => (F i.fst a, F' i.snd a)) (p ×ˢ p') s := (congr_arg _ s.inter_self).mp ((h.prodMap h').comp fun a => (a, a)) theorem UniformCauchySeqOn.prod' {β' : Type*} [UniformSpace β'] {F' : ι → α → β'} (h : UniformCauchySeqOn F p s) (h' : UniformCauchySeqOn F' p s) : UniformCauchySeqOn (fun (i : ι) a => (F i a, F' i a)) p s := fun u hu => have hh : Tendsto (fun x : ι => (x, x)) p (p ×ˢ p) := tendsto_diag (hh.prodMap hh).eventually ((h.prod h') u hu) /-- If a sequence of functions is uniformly Cauchy on a set, then the values at each point form a Cauchy sequence. -/ theorem UniformCauchySeqOn.cauchy_map [hp : NeBot p] (hf : UniformCauchySeqOn F p s) (hx : x ∈ s) : Cauchy (map (fun i => F i x) p) := by simp only [cauchy_map_iff, hp, true_and] intro u hu rw [mem_map] filter_upwards [hf u hu] with p hp using hp x hx /-- If a sequence of functions is uniformly Cauchy on a set, then the values at each point form a Cauchy sequence. See `UniformCauchSeqOn.cauchy_map` for the non-`atTop` case. -/ theorem UniformCauchySeqOn.cauchySeq [Nonempty ι] [SemilatticeSup ι] (hf : UniformCauchySeqOn F atTop s) (hx : x ∈ s) : CauchySeq fun i ↦ F i x := hf.cauchy_map (hp := atTop_neBot) hx section SeqTendsto theorem tendstoUniformlyOn_of_seq_tendstoUniformlyOn {l : Filter ι} [l.IsCountablyGenerated] (h : ∀ u : ℕ → ι, Tendsto u atTop l → TendstoUniformlyOn (fun n => F (u n)) f atTop s) : TendstoUniformlyOn F f l s := by rw [tendstoUniformlyOn_iff_tendsto, tendsto_iff_seq_tendsto] intro u hu rw [tendsto_prod_iff'] at hu specialize h (fun n => (u n).fst) hu.1 rw [tendstoUniformlyOn_iff_tendsto] at h exact h.comp (tendsto_id.prodMk hu.2) theorem TendstoUniformlyOn.seq_tendstoUniformlyOn {l : Filter ι} (h : TendstoUniformlyOn F f l s) (u : ℕ → ι) (hu : Tendsto u atTop l) : TendstoUniformlyOn (fun n => F (u n)) f atTop s := by rw [tendstoUniformlyOn_iff_tendsto] at h ⊢ exact h.comp ((hu.comp tendsto_fst).prodMk tendsto_snd) theorem tendstoUniformlyOn_iff_seq_tendstoUniformlyOn {l : Filter ι} [l.IsCountablyGenerated] : TendstoUniformlyOn F f l s ↔ ∀ u : ℕ → ι, Tendsto u atTop l → TendstoUniformlyOn (fun n => F (u n)) f atTop s := ⟨TendstoUniformlyOn.seq_tendstoUniformlyOn, tendstoUniformlyOn_of_seq_tendstoUniformlyOn⟩ theorem tendstoUniformly_iff_seq_tendstoUniformly {l : Filter ι} [l.IsCountablyGenerated] : TendstoUniformly F f l ↔ ∀ u : ℕ → ι, Tendsto u atTop l → TendstoUniformly (fun n => F (u n)) f atTop := by simp_rw [← tendstoUniformlyOn_univ] exact tendstoUniformlyOn_iff_seq_tendstoUniformlyOn end SeqTendsto section variable [NeBot p] {L : ι → β} {ℓ : β} theorem TendstoUniformlyOnFilter.tendsto_of_eventually_tendsto (h1 : TendstoUniformlyOnFilter F f p p') (h2 : ∀ᶠ i in p, Tendsto (F i) p' (𝓝 (L i))) (h3 : Tendsto L p (𝓝 ℓ)) : Tendsto f p' (𝓝 ℓ) := by rw [tendsto_nhds_left] intro s hs rw [mem_map, Set.preimage, ← eventually_iff] obtain ⟨t, ht, hts⟩ := comp3_mem_uniformity hs have p1 : ∀ᶠ i in p, (L i, ℓ) ∈ t := tendsto_nhds_left.mp h3 ht have p2 : ∀ᶠ i in p, ∀ᶠ x in p', (F i x, L i) ∈ t := by filter_upwards [h2] with i h2 using tendsto_nhds_left.mp h2 ht have p3 : ∀ᶠ i in p, ∀ᶠ x in p', (f x, F i x) ∈ t := (h1 t ht).curry obtain ⟨i, p4, p5, p6⟩ := (p1.and (p2.and p3)).exists filter_upwards [p5, p6] with x p5 p6 using hts ⟨F i x, p6, L i, p5, p4⟩ theorem TendstoUniformly.tendsto_of_eventually_tendsto (h1 : TendstoUniformly F f p) (h2 : ∀ᶠ i in p, Tendsto (F i) p' (𝓝 (L i))) (h3 : Tendsto L p (𝓝 ℓ)) : Tendsto f p' (𝓝 ℓ) := (h1.tendstoUniformlyOnFilter.mono_right le_top).tendsto_of_eventually_tendsto h2 h3 end
Mathlib/Topology/UniformSpace/UniformConvergence.lean
610
612
/- Copyright (c) 2022 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Topology.EMetricSpace.Paracompact import Mathlib.Topology.Instances.ENNReal.Lemmas import Mathlib.Analysis.Convex.PartitionOfUnity /-! # Lemmas about (e)metric spaces that need partition of unity The main lemma in this file (see `Metric.exists_continuous_real_forall_closedBall_subset`) says the following. Let `X` be a metric space. Let `K : ι → Set X` be a locally finite family of closed sets, let `U : ι → Set X` be a family of open sets such that `K i ⊆ U i` for all `i`. Then there exists a positive continuous function `δ : C(X, → ℝ)` such that for any `i` and `x ∈ K i`, we have `Metric.closedBall x (δ x) ⊆ U i`. We also formulate versions of this lemma for extended metric spaces and for different codomains (`ℝ`, `ℝ≥0`, and `ℝ≥0∞`). We also prove a few auxiliary lemmas to be used later in a proof of the smooth version of this lemma. ## Tags metric space, partition of unity, locally finite -/ open Topology ENNReal NNReal Filter Set Function TopologicalSpace variable {ι X : Type*} namespace EMetric variable [EMetricSpace X] {K : ι → Set X} {U : ι → Set X} /-- Let `K : ι → Set X` be a locally finite family of closed sets in an emetric space. Let `U : ι → Set X` be a family of open sets such that `K i ⊆ U i` for all `i`. Then for any point `x : X`, for sufficiently small `r : ℝ≥0∞` and for `y` sufficiently close to `x`, for all `i`, if `y ∈ K i`, then `EMetric.closedBall y r ⊆ U i`. -/ theorem eventually_nhds_zero_forall_closedBall_subset (hK : ∀ i, IsClosed (K i)) (hU : ∀ i, IsOpen (U i)) (hKU : ∀ i, K i ⊆ U i) (hfin : LocallyFinite K) (x : X) : ∀ᶠ p : ℝ≥0∞ × X in 𝓝 0 ×ˢ 𝓝 x, ∀ i, p.2 ∈ K i → closedBall p.2 p.1 ⊆ U i := by suffices ∀ i, x ∈ K i → ∀ᶠ p : ℝ≥0∞ × X in 𝓝 0 ×ˢ 𝓝 x, closedBall p.2 p.1 ⊆ U i by apply mp_mem ((eventually_all_finite (hfin.point_finite x)).2 this) (mp_mem (@tendsto_snd ℝ≥0∞ _ (𝓝 0) _ _ (hfin.iInter_compl_mem_nhds hK x)) _) apply univ_mem' rintro ⟨r, y⟩ hxy hyU i hi simp only [mem_iInter, mem_compl_iff, not_imp_not, mem_preimage] at hxy exact hyU _ (hxy _ hi) intro i hi rcases nhds_basis_closed_eball.mem_iff.1 ((hU i).mem_nhds <| hKU i hi) with ⟨R, hR₀, hR⟩ rcases ENNReal.lt_iff_exists_nnreal_btwn.mp hR₀ with ⟨r, hr₀, hrR⟩ filter_upwards [prod_mem_prod (eventually_lt_nhds hr₀) (closedBall_mem_nhds x (tsub_pos_iff_lt.2 hrR))] with p hp z hz apply hR calc edist z x ≤ edist z p.2 + edist p.2 x := edist_triangle _ _ _ _ ≤ p.1 + (R - p.1) := add_le_add hz <| le_trans hp.2 <| tsub_le_tsub_left hp.1.out.le _ _ = R := add_tsub_cancel_of_le (lt_trans (by exact hp.1) hrR).le theorem exists_forall_closedBall_subset_aux₁ (hK : ∀ i, IsClosed (K i)) (hU : ∀ i, IsOpen (U i)) (hKU : ∀ i, K i ⊆ U i) (hfin : LocallyFinite K) (x : X) : ∃ r : ℝ, ∀ᶠ y in 𝓝 x, r ∈ Ioi (0 : ℝ) ∩ ENNReal.ofReal ⁻¹' ⋂ (i) (_ : y ∈ K i), { r | closedBall y r ⊆ U i } := by have := (ENNReal.continuous_ofReal.tendsto' 0 0 ENNReal.ofReal_zero).eventually (eventually_nhds_zero_forall_closedBall_subset hK hU hKU hfin x).curry rcases this.exists_gt with ⟨r, hr0, hr⟩ refine ⟨r, hr.mono fun y hy => ⟨hr0, ?_⟩⟩ rwa [mem_preimage, mem_iInter₂] theorem exists_forall_closedBall_subset_aux₂ (y : X) : Convex ℝ (Ioi (0 : ℝ) ∩ ENNReal.ofReal ⁻¹' ⋂ (i) (_ : y ∈ K i), { r | closedBall y r ⊆ U i }) := (convex_Ioi _).inter <| OrdConnected.convex <| OrdConnected.preimage_ennreal_ofReal <| ordConnected_iInter fun i => ordConnected_iInter fun (_ : y ∈ K i) => ordConnected_setOf_closedBall_subset y (U i) /-- Let `X` be an extended metric space. Let `K : ι → Set X` be a locally finite family of closed sets, let `U : ι → Set X` be a family of open sets such that `K i ⊆ U i` for all `i`. Then there exists a positive continuous function `δ : C(X, ℝ)` such that for any `i` and `x ∈ K i`, we have `EMetric.closedBall x (ENNReal.ofReal (δ x)) ⊆ U i`. -/ theorem exists_continuous_real_forall_closedBall_subset (hK : ∀ i, IsClosed (K i)) (hU : ∀ i, IsOpen (U i)) (hKU : ∀ i, K i ⊆ U i) (hfin : LocallyFinite K) : ∃ δ : C(X, ℝ), (∀ x, 0 < δ x) ∧ ∀ (i), ∀ x ∈ K i, closedBall x (ENNReal.ofReal <| δ x) ⊆ U i := by simpa only [mem_inter_iff, forall_and, mem_preimage, mem_iInter, @forall_swap ι X] using exists_continuous_forall_mem_convex_of_local_const exists_forall_closedBall_subset_aux₂ (exists_forall_closedBall_subset_aux₁ hK hU hKU hfin) /-- Let `X` be an extended metric space. Let `K : ι → Set X` be a locally finite family of closed sets, let `U : ι → Set X` be a family of open sets such that `K i ⊆ U i` for all `i`. Then there exists a positive continuous function `δ : C(X, ℝ≥0)` such that for any `i` and `x ∈ K i`, we have `EMetric.closedBall x (δ x) ⊆ U i`. -/ theorem exists_continuous_nnreal_forall_closedBall_subset (hK : ∀ i, IsClosed (K i)) (hU : ∀ i, IsOpen (U i)) (hKU : ∀ i, K i ⊆ U i) (hfin : LocallyFinite K) : ∃ δ : C(X, ℝ≥0), (∀ x, 0 < δ x) ∧ ∀ (i), ∀ x ∈ K i, closedBall x (δ x) ⊆ U i := by rcases exists_continuous_real_forall_closedBall_subset hK hU hKU hfin with ⟨δ, hδ₀, hδ⟩ lift δ to C(X, ℝ≥0) using fun x => (hδ₀ x).le refine ⟨δ, hδ₀, fun i x hi => ?_⟩ simpa only [← ENNReal.ofReal_coe_nnreal] using hδ i x hi /-- Let `X` be an extended metric space. Let `K : ι → Set X` be a locally finite family of closed sets, let `U : ι → Set X` be a family of open sets such that `K i ⊆ U i` for all `i`. Then there exists a positive continuous function `δ : C(X, ℝ≥0∞)` such that for any `i` and `x ∈ K i`, we have `EMetric.closedBall x (δ x) ⊆ U i`. -/ theorem exists_continuous_eNNReal_forall_closedBall_subset (hK : ∀ i, IsClosed (K i)) (hU : ∀ i, IsOpen (U i)) (hKU : ∀ i, K i ⊆ U i) (hfin : LocallyFinite K) : ∃ δ : C(X, ℝ≥0∞), (∀ x, 0 < δ x) ∧ ∀ (i), ∀ x ∈ K i, closedBall x (δ x) ⊆ U i := let ⟨δ, hδ₀, hδ⟩ := exists_continuous_nnreal_forall_closedBall_subset hK hU hKU hfin ⟨ContinuousMap.comp ⟨Coe.coe, ENNReal.continuous_coe⟩ δ, fun x => ENNReal.coe_pos.2 (hδ₀ x), hδ⟩ end EMetric namespace Metric variable [MetricSpace X] {K : ι → Set X} {U : ι → Set X} /-- Let `X` be a metric space. Let `K : ι → Set X` be a locally finite family of closed sets, let `U : ι → Set X` be a family of open sets such that `K i ⊆ U i` for all `i`. Then there exists a positive continuous function `δ : C(X, ℝ≥0)` such that for any `i` and `x ∈ K i`, we have `Metric.closedBall x (δ x) ⊆ U i`. -/ theorem exists_continuous_nnreal_forall_closedBall_subset (hK : ∀ i, IsClosed (K i)) (hU : ∀ i, IsOpen (U i)) (hKU : ∀ i, K i ⊆ U i) (hfin : LocallyFinite K) : ∃ δ : C(X, ℝ≥0), (∀ x, 0 < δ x) ∧ ∀ (i), ∀ x ∈ K i, closedBall x (δ x) ⊆ U i := by rcases EMetric.exists_continuous_nnreal_forall_closedBall_subset hK hU hKU hfin with ⟨δ, hδ0, hδ⟩ refine ⟨δ, hδ0, fun i x hx => ?_⟩ rw [← emetric_closedBall_nnreal] exact hδ i x hx
/-- Let `X` be a metric space. Let `K : ι → Set X` be a locally finite family of closed sets, let `U : ι → Set X` be a family of open sets such that `K i ⊆ U i` for all `i`. Then there exists a positive continuous function `δ : C(X, ℝ)` such that for any `i` and `x ∈ K i`, we have `Metric.closedBall x (δ x) ⊆ U i`. -/ theorem exists_continuous_real_forall_closedBall_subset (hK : ∀ i, IsClosed (K i)) (hU : ∀ i, IsOpen (U i)) (hKU : ∀ i, K i ⊆ U i) (hfin : LocallyFinite K) : ∃ δ : C(X, ℝ), (∀ x, 0 < δ x) ∧ ∀ (i), ∀ x ∈ K i, closedBall x (δ x) ⊆ U i :=
Mathlib/Topology/MetricSpace/PartitionOfUnity.lean
130
136
/- Copyright (c) 2022 Antoine Labelle. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Antoine Labelle -/ import Mathlib.RepresentationTheory.Basic import Mathlib.RepresentationTheory.FDRep /-! # Subspace of invariants a group representation This file introduces the subspace of invariants of a group representation and proves basic results about it. The main tool used is the average of all elements of the group, seen as an element of `MonoidAlgebra k G`. The action of this special element gives a projection onto the subspace of invariants. In order for the definition of the average element to make sense, we need to assume for most of the results that the order of `G` is invertible in `k` (e. g. `k` has characteristic `0`). -/ suppress_compilation universe u open MonoidAlgebra open Representation namespace GroupAlgebra variable (k G : Type*) [CommSemiring k] [Group G] variable [Fintype G] [Invertible (Fintype.card G : k)] /-- The average of all elements of the group `G`, considered as an element of `MonoidAlgebra k G`. -/ noncomputable def average : MonoidAlgebra k G := ⅟ (Fintype.card G : k) • ∑ g : G, of k G g /-- `average k G` is invariant under left multiplication by elements of `G`. -/ @[simp] theorem mul_average_left (g : G) : ↑(Finsupp.single g 1) * average k G = average k G := by simp only [mul_one, Finset.mul_sum, Algebra.mul_smul_comm, average, MonoidAlgebra.of_apply, Finset.sum_congr, MonoidAlgebra.single_mul_single] set f : G → MonoidAlgebra k G := fun x => Finsupp.single x 1 show ⅟ (Fintype.card G : k) • ∑ x : G, f (g * x) = ⅟ (Fintype.card G : k) • ∑ x : G, f x rw [Function.Bijective.sum_comp (Group.mulLeft_bijective g) _] /-- `average k G` is invariant under right multiplication by elements of `G`. -/ @[simp] theorem mul_average_right (g : G) : average k G * ↑(Finsupp.single g 1) = average k G := by simp only [mul_one, Finset.sum_mul, Algebra.smul_mul_assoc, average, MonoidAlgebra.of_apply, Finset.sum_congr, MonoidAlgebra.single_mul_single] set f : G → MonoidAlgebra k G := fun x => Finsupp.single x 1 show ⅟ (Fintype.card G : k) • ∑ x : G, f (x * g) = ⅟ (Fintype.card G : k) • ∑ x : G, f x rw [Function.Bijective.sum_comp (Group.mulRight_bijective g) _] end GroupAlgebra namespace Representation section Invariants open GroupAlgebra variable {k G V : Type*} [CommSemiring k] [Group G] [AddCommMonoid V] [Module k V] variable (ρ : Representation k G V) /-- The subspace of invariants, consisting of the vectors fixed by all elements of `G`. -/ def invariants : Submodule k V where carrier := setOf fun v => ∀ g : G, ρ g v = v zero_mem' g := by simp only [map_zero] add_mem' hv hw g := by simp only [hv g, hw g, map_add] smul_mem' r v hv g := by simp only [hv g, LinearMap.map_smulₛₗ, RingHom.id_apply] @[simp] theorem mem_invariants (v : V) : v ∈ invariants ρ ↔ ∀ g : G, ρ g v = v := by rfl theorem invariants_eq_inter : (invariants ρ).carrier = ⋂ g : G, Function.fixedPoints (ρ g) := by ext; simp [Function.IsFixedPt] theorem invariants_eq_top [ρ.IsTrivial] : invariants ρ = ⊤ :=
eq_top_iff.2 (fun x _ g => ρ.isTrivial_apply g x)
Mathlib/RepresentationTheory/Invariants.lean
86
87
/- Copyright (c) 2023 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Algebra.Order.Monovary import Mathlib.Algebra.Order.Ring.Basic import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.FieldSimp /-! # Product of convex functions This file proves that the product of convex functions is convex, provided they monovary. As corollaries, we also prove that `x ↦ x ^ n` is convex * `Even.convexOn_pow`: for even `n : ℕ`. * `convexOn_pow`: over $[0, +∞)$ for `n : ℕ`. * `convexOn_zpow`: over $(0, +∞)$ For `n : ℤ`. -/ open Set variable {𝕜 E F : Type*} section LinearOrderedCommRing variable [CommRing 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [CommRing E] [LinearOrder E] [IsStrictOrderedRing E] [AddCommGroup F] [LinearOrder F] [IsOrderedAddMonoid F] [Module 𝕜 E] [Module 𝕜 F] [Module E F] [IsScalarTower 𝕜 E F] [SMulCommClass 𝕜 E F] [OrderedSMul 𝕜 F] [OrderedSMul E F] {s : Set 𝕜} {f : 𝕜 → E} {g : 𝕜 → F} lemma ConvexOn.smul' (hf : ConvexOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) (hf₀ : ∀ ⦃x⦄, x ∈ s → 0 ≤ f x) (hg₀ : ∀ ⦃x⦄, x ∈ s → 0 ≤ g x) (hfg : MonovaryOn f g s) : ConvexOn 𝕜 s (f • g) := by refine ⟨hf.1, fun x hx y hy a b ha hb hab ↦ ?_⟩ dsimp refine (smul_le_smul (hf.2 hx hy ha hb hab) (hg.2 hx hy ha hb hab) (hf₀ <| hf.1 hx hy ha hb hab) <| add_nonneg (smul_nonneg ha <| hg₀ hx) <| smul_nonneg hb <| hg₀ hy).trans ?_ calc _ = (a * a) • (f x • g x) + (b * b) • (f y • g y) + (a * b) • (f x • g y + f y • g x) := ?_ _ ≤ (a * a) • (f x • g x) + (b * b) • (f y • g y) + (a * b) • (f x • g x + f y • g y) := by gcongr _ + (a * b) • ?_; exact hfg.smul_add_smul_le_smul_add_smul hx hy _ = (a * (a + b)) • (f x • g x) + (b * (a + b)) • (f y • g y) := by simp only [mul_add, add_smul, smul_add, mul_comm _ a]; abel _ = _ := by simp_rw [hab, mul_one] simp only [mul_add, add_smul, smul_add] rw [← smul_smul_smul_comm a, ← smul_smul_smul_comm b, ← smul_smul_smul_comm a b, ← smul_smul_smul_comm b b, smul_eq_mul, smul_eq_mul, smul_eq_mul, smul_eq_mul, mul_comm b, add_comm _ ((b * b) • f y • g y), add_add_add_comm, add_comm ((a * b) • f y • g x)] lemma ConcaveOn.smul' [OrderedSMul 𝕜 E] (hf : ConcaveOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) (hf₀ : ∀ ⦃x⦄, x ∈ s → 0 ≤ f x) (hg₀ : ∀ ⦃x⦄, x ∈ s → 0 ≤ g x) (hfg : AntivaryOn f g s) : ConcaveOn 𝕜 s (f • g) := by refine ⟨hf.1, fun x hx y hy a b ha hb hab ↦ ?_⟩ dsimp refine (smul_le_smul (hf.2 hx hy ha hb hab) (hg.2 hx hy ha hb hab) (add_nonneg (smul_nonneg ha <| hf₀ hx) <| smul_nonneg hb <| hf₀ hy) (hg₀ <| hf.1 hx hy ha hb hab)).trans' ?_ calc a • f x • g x + b • f y • g y = (a * (a + b)) • (f x • g x) + (b * (a + b)) • (f y • g y) := by simp_rw [hab, mul_one] _ = (a * a) • (f x • g x) + (b * b) • (f y • g y) + (a * b) • (f x • g x + f y • g y) := by simp only [mul_add, add_smul, smul_add, mul_comm _ a]; abel _ ≤ (a * a) • (f x • g x) + (b * b) • (f y • g y) + (a * b) • (f x • g y + f y • g x) := by gcongr _ + (a * b) • ?_; exact hfg.smul_add_smul_le_smul_add_smul hx hy _ = _ := ?_ simp only [mul_add, add_smul, smul_add] rw [← smul_smul_smul_comm a, ← smul_smul_smul_comm b, ← smul_smul_smul_comm a b, ← smul_smul_smul_comm b b, smul_eq_mul, smul_eq_mul, smul_eq_mul, smul_eq_mul, mul_comm b a, add_comm ((a * b) • f x • g y), add_comm ((a * b) • f x • g y), add_add_add_comm] lemma ConvexOn.smul'' [OrderedSMul 𝕜 E] (hf : ConvexOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) (hf₀ : ∀ ⦃x⦄, x ∈ s → f x ≤ 0) (hg₀ : ∀ ⦃x⦄, x ∈ s → g x ≤ 0) (hfg : AntivaryOn f g s) : ConcaveOn 𝕜 s (f • g) := by rw [← neg_smul_neg] exact hf.neg.smul' hg.neg (fun x hx ↦ neg_nonneg.2 <| hf₀ hx) (fun x hx ↦ neg_nonneg.2 <| hg₀ hx) hfg.neg lemma ConcaveOn.smul'' (hf : ConcaveOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) (hf₀ : ∀ ⦃x⦄, x ∈ s → f x ≤ 0) (hg₀ : ∀ ⦃x⦄, x ∈ s → g x ≤ 0) (hfg : MonovaryOn f g s) : ConvexOn 𝕜 s (f • g) := by
rw [← neg_smul_neg] exact hf.neg.smul' hg.neg (fun x hx ↦ neg_nonneg.2 <| hf₀ hx) (fun x hx ↦ neg_nonneg.2 <| hg₀ hx) hfg.neg lemma ConvexOn.smul_concaveOn (hf : ConvexOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g)
Mathlib/Analysis/Convex/Mul.lean
81
85
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johan Commelin -/ import Mathlib.Algebra.Group.Equiv.Defs import Mathlib.Algebra.Group.WithOne.Defs import Mathlib.Algebra.GroupWithZero.Equiv import Mathlib.Algebra.GroupWithZero.Units.Basic import Mathlib.Data.Nat.Cast.Defs import Mathlib.Data.Option.Basic import Mathlib.Data.Option.NAry /-! # Adjoining a zero to a group This file proves that one can adjoin a new zero element to a group and get a group with zero. ## Main definitions * `WithZero.map'`: the `MonoidWithZero` homomorphism `WithZero α →* WithZero β` induced by a monoid homomorphism `f : α →* β`. -/ assert_not_exists DenselyOrdered namespace WithZero variable {α β γ : Type*} section One variable [One α] instance one : One (WithZero α) where __ := ‹One α› @[simp, norm_cast] lemma coe_one : ((1 : α) : WithZero α) = 1 := rfl end One section Mul variable [Mul α] instance instMulZeroClass : MulZeroClass (WithZero α) where mul := Option.map₂ (· * ·) zero_mul := Option.map₂_none_left (· * ·) mul_zero := Option.map₂_none_right (· * ·) @[simp, norm_cast] lemma coe_mul (a b : α) : (↑(a * b) : WithZero α) = a * b := rfl lemma unzero_mul {x y : WithZero α} (hxy : x * y ≠ 0) : unzero hxy = unzero (left_ne_zero_of_mul hxy) * unzero (right_ne_zero_of_mul hxy) := by simp only [← coe_inj, coe_mul, coe_unzero] instance instNoZeroDivisors : NoZeroDivisors (WithZero α) := ⟨Option.map₂_eq_none_iff.1⟩ end Mul instance instSemigroupWithZero [Semigroup α] : SemigroupWithZero (WithZero α) where mul_assoc _ _ _ := Option.map₂_assoc mul_assoc instance instCommSemigroup [CommSemigroup α] : CommSemigroup (WithZero α) where mul_comm _ _ := Option.map₂_comm mul_comm section MulOneClass variable [MulOneClass α] instance instMulZeroOneClass [MulOneClass α] : MulZeroOneClass (WithZero α) where one_mul := Option.map₂_left_identity one_mul mul_one := Option.map₂_right_identity mul_one /-- Coercion as a monoid hom. -/ @[simps apply] def coeMonoidHom : α →* WithZero α where toFun := (↑) map_one' := rfl map_mul' _ _ := rfl section lift variable [MulZeroOneClass β] -- See note [partially-applied ext lemmas] @[ext high] theorem monoidWithZeroHom_ext ⦃f g : WithZero α →*₀ β⦄ (h : f.toMonoidHom.comp coeMonoidHom = g.toMonoidHom.comp coeMonoidHom) : f = g := DFunLike.ext _ _ fun | 0 => (map_zero f).trans (map_zero g).symm | (g : α) => DFunLike.congr_fun h g /-- The (multiplicative) universal property of `WithZero`. -/ @[simps! symm_apply_apply] noncomputable nonrec def lift' : (α →* β) ≃ (WithZero α →*₀ β) where toFun f := { toFun := fun | 0 => 0 | (a : α) => f a map_zero' := rfl map_one' := map_one f map_mul' := fun | 0, _ => (zero_mul _).symm | (_ : α), 0 => (mul_zero _).symm | (_ : α), (_ : α) => map_mul f _ _ } invFun F := F.toMonoidHom.comp coeMonoidHom left_inv _ := rfl right_inv _ := monoidWithZeroHom_ext rfl lemma lift'_zero (f : α →* β) : lift' f (0 : WithZero α) = 0 := rfl @[simp] lemma lift'_coe (f : α →* β) (x : α) : lift' f (x : WithZero α) = f x := rfl lemma lift'_unique (f : WithZero α →*₀ β) : f = lift' (f.toMonoidHom.comp coeMonoidHom) := (lift'.apply_symm_apply f).symm end lift variable [MulOneClass β] [MulOneClass γ] /-- The `MonoidWithZero` homomorphism `WithZero α →* WithZero β` induced by a monoid homomorphism `f : α →* β`. -/ noncomputable def map' (f : α →* β) : WithZero α →*₀ WithZero β := lift' (coeMonoidHom.comp f) lemma map'_zero (f : α →* β) : map' f 0 = 0 := rfl @[simp] lemma map'_coe (f : α →* β) (x : α) : map' f (x : WithZero α) = f x := rfl @[simp] lemma map'_id : map' (MonoidHom.id β) = MonoidHom.id (WithZero β) := by ext x; induction x <;> rfl lemma map'_map' (f : α →* β) (g : β →* γ) (x) : map' g (map' f x) = map' (g.comp f) x := by
induction x <;> rfl @[simp]
Mathlib/Algebra/GroupWithZero/WithZero.lean
131
133
/- Copyright (c) 2022 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Order.Hom.Basic /-! # Bounded order homomorphisms This file defines (bounded) order homomorphisms. We use the `DFunLike` design, so each type of morphisms has a companion typeclass which is meant to be satisfied by itself and all stricter types. ## Types of morphisms * `TopHom`: Maps which preserve `⊤`. * `BotHom`: Maps which preserve `⊥`. * `BoundedOrderHom`: Bounded order homomorphisms. Monotone maps which preserve `⊤` and `⊥`. ## Typeclasses * `TopHomClass` * `BotHomClass` * `BoundedOrderHomClass` -/ open Function OrderDual variable {F α β γ δ : Type*} /-- The type of `⊤`-preserving functions from `α` to `β`. -/ structure TopHom (α β : Type*) [Top α] [Top β] where /-- The underlying function. The preferred spelling is `DFunLike.coe`. -/ toFun : α → β /-- The function preserves the top element. The preferred spelling is `map_top`. -/ map_top' : toFun ⊤ = ⊤ /-- The type of `⊥`-preserving functions from `α` to `β`. -/ structure BotHom (α β : Type*) [Bot α] [Bot β] where /-- The underlying function. The preferred spelling is `DFunLike.coe`. -/ toFun : α → β /-- The function preserves the bottom element. The preferred spelling is `map_bot`. -/ map_bot' : toFun ⊥ = ⊥ /-- The type of bounded order homomorphisms from `α` to `β`. -/ structure BoundedOrderHom (α β : Type*) [Preorder α] [Preorder β] [BoundedOrder α] [BoundedOrder β] extends OrderHom α β where /-- The function preserves the top element. The preferred spelling is `map_top`. -/ map_top' : toFun ⊤ = ⊤ /-- The function preserves the bottom element. The preferred spelling is `map_bot`. -/ map_bot' : toFun ⊥ = ⊥ section /-- `TopHomClass F α β` states that `F` is a type of `⊤`-preserving morphisms. You should extend this class when you extend `TopHom`. -/ class TopHomClass (F : Type*) (α β : outParam Type*) [Top α] [Top β] [FunLike F α β] : Prop where /-- A `TopHomClass` morphism preserves the top element. -/ map_top (f : F) : f ⊤ = ⊤ /-- `BotHomClass F α β` states that `F` is a type of `⊥`-preserving morphisms. You should extend this class when you extend `BotHom`. -/ class BotHomClass (F : Type*) (α β : outParam Type*) [Bot α] [Bot β] [FunLike F α β] : Prop where /-- A `BotHomClass` morphism preserves the bottom element. -/ map_bot (f : F) : f ⊥ = ⊥ /-- `BoundedOrderHomClass F α β` states that `F` is a type of bounded order morphisms. You should extend this class when you extend `BoundedOrderHom`. -/ class BoundedOrderHomClass (F α β : Type*) [LE α] [LE β] [BoundedOrder α] [BoundedOrder β] [FunLike F α β] : Prop extends RelHomClass F ((· ≤ ·) : α → α → Prop) ((· ≤ ·) : β → β → Prop) where /-- Morphisms preserve the top element. The preferred spelling is `_root_.map_top`. -/ map_top (f : F) : f ⊤ = ⊤ /-- Morphisms preserve the bottom element. The preferred spelling is `_root_.map_bot`. -/ map_bot (f : F) : f ⊥ = ⊥ end export TopHomClass (map_top) export BotHomClass (map_bot) attribute [simp] map_top map_bot section Hom variable [FunLike F α β] -- See note [lower instance priority] instance (priority := 100) BoundedOrderHomClass.toTopHomClass [LE α] [LE β] [BoundedOrder α] [BoundedOrder β] [BoundedOrderHomClass F α β] : TopHomClass F α β := { ‹BoundedOrderHomClass F α β› with } -- See note [lower instance priority] instance (priority := 100) BoundedOrderHomClass.toBotHomClass [LE α] [LE β] [BoundedOrder α] [BoundedOrder β] [BoundedOrderHomClass F α β] : BotHomClass F α β := { ‹BoundedOrderHomClass F α β› with } end Hom section Equiv variable [EquivLike F α β] -- See note [lower instance priority] instance (priority := 100) OrderIsoClass.toTopHomClass [LE α] [OrderTop α] [PartialOrder β] [OrderTop β] [OrderIsoClass F α β] : TopHomClass F α β := { show OrderHomClass F α β from inferInstance with map_top := fun f => top_le_iff.1 <| (map_inv_le_iff f).1 le_top } -- See note [lower instance priority] instance (priority := 100) OrderIsoClass.toBotHomClass [LE α] [OrderBot α] [PartialOrder β] [OrderBot β] [OrderIsoClass F α β] : BotHomClass F α β := { map_bot := fun f => le_bot_iff.1 <| (le_map_inv_iff f).1 bot_le } -- See note [lower instance priority] instance (priority := 100) OrderIsoClass.toBoundedOrderHomClass [LE α] [BoundedOrder α] [PartialOrder β] [BoundedOrder β] [OrderIsoClass F α β] : BoundedOrderHomClass F α β := { show OrderHomClass F α β from inferInstance, OrderIsoClass.toTopHomClass, OrderIsoClass.toBotHomClass with } @[simp] theorem map_eq_top_iff [LE α] [OrderTop α] [PartialOrder β] [OrderTop β] [OrderIsoClass F α β] (f : F) {a : α} : f a = ⊤ ↔ a = ⊤ := by rw [← map_top f, (EquivLike.injective f).eq_iff] @[simp] theorem map_eq_bot_iff [LE α] [OrderBot α] [PartialOrder β] [OrderBot β] [OrderIsoClass F α β] (f : F) {a : α} : f a = ⊥ ↔ a = ⊥ := by rw [← map_bot f, (EquivLike.injective f).eq_iff] end Equiv variable [FunLike F α β] /-- Turn an element of a type `F` satisfying `TopHomClass F α β` into an actual `TopHom`. This is declared as the default coercion from `F` to `TopHom α β`. -/ @[coe] def TopHomClass.toTopHom [Top α] [Top β] [TopHomClass F α β] (f : F) : TopHom α β := ⟨f, map_top f⟩ instance [Top α] [Top β] [TopHomClass F α β] : CoeTC F (TopHom α β) := ⟨TopHomClass.toTopHom⟩ /-- Turn an element of a type `F` satisfying `BotHomClass F α β` into an actual `BotHom`. This is declared as the default coercion from `F` to `BotHom α β`. -/ @[coe] def BotHomClass.toBotHom [Bot α] [Bot β] [BotHomClass F α β] (f : F) : BotHom α β := ⟨f, map_bot f⟩ instance [Bot α] [Bot β] [BotHomClass F α β] : CoeTC F (BotHom α β) := ⟨BotHomClass.toBotHom⟩ /-- Turn an element of a type `F` satisfying `BoundedOrderHomClass F α β` into an actual `BoundedOrderHom`. This is declared as the default coercion from `F` to `BoundedOrderHom α β`. -/ @[coe] def BoundedOrderHomClass.toBoundedOrderHom [Preorder α] [Preorder β] [BoundedOrder α] [BoundedOrder β] [BoundedOrderHomClass F α β] (f : F) : BoundedOrderHom α β := { (f : α →o β) with toFun := f, map_top' := map_top f, map_bot' := map_bot f } instance [Preorder α] [Preorder β] [BoundedOrder α] [BoundedOrder β] [BoundedOrderHomClass F α β] : CoeTC F (BoundedOrderHom α β) := ⟨BoundedOrderHomClass.toBoundedOrderHom⟩ /-! ### Top homomorphisms -/ namespace TopHom variable [Top α] section Top variable [Top β] [Top γ] [Top δ] instance : FunLike (TopHom α β) α β where coe := TopHom.toFun coe_injective' f g h := by cases f; cases g; congr instance : TopHomClass (TopHom α β) α β where map_top := TopHom.map_top' -- this must come after the coe_to_fun definition initialize_simps_projections TopHom (toFun → apply) @[ext] theorem ext {f g : TopHom α β} (h : ∀ a, f a = g a) : f = g := DFunLike.ext f g h /-- Copy of a `TopHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : TopHom α β) (f' : α → β) (h : f' = f) : TopHom α β where toFun := f' map_top' := h.symm ▸ f.map_top' @[simp] theorem coe_copy (f : TopHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : TopHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h instance : Inhabited (TopHom α β) := ⟨⟨fun _ => ⊤, rfl⟩⟩ variable (α) /-- `id` as a `TopHom`. -/ protected def id : TopHom α α := ⟨id, rfl⟩ @[simp, norm_cast] theorem coe_id : ⇑(TopHom.id α) = id := rfl variable {α} @[simp] theorem id_apply (a : α) : TopHom.id α a = a := rfl /-- Composition of `TopHom`s as a `TopHom`. -/ def comp (f : TopHom β γ) (g : TopHom α β) : TopHom α γ where toFun := f ∘ g map_top' := by rw [comp_apply, map_top, map_top] @[simp] theorem coe_comp (f : TopHom β γ) (g : TopHom α β) : (f.comp g : α → γ) = f ∘ g := rfl @[simp] theorem comp_apply (f : TopHom β γ) (g : TopHom α β) (a : α) : (f.comp g) a = f (g a) := rfl @[simp] theorem comp_assoc (f : TopHom γ δ) (g : TopHom β γ) (h : TopHom α β) : (f.comp g).comp h = f.comp (g.comp h) := rfl @[simp] theorem comp_id (f : TopHom α β) : f.comp (TopHom.id α) = f := TopHom.ext fun _ => rfl @[simp] theorem id_comp (f : TopHom α β) : (TopHom.id β).comp f = f := TopHom.ext fun _ => rfl @[simp] theorem cancel_right {g₁ g₂ : TopHom β γ} {f : TopHom α β} (hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h => TopHom.ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, congr_arg (fun g => comp g f)⟩ @[simp] theorem cancel_left {g : TopHom β γ} {f₁ f₂ : TopHom α β} (hg : Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h => TopHom.ext fun a => hg <| by rw [← TopHom.comp_apply, h, TopHom.comp_apply], congr_arg _⟩ end Top instance instLE [LE β] [Top β] : LE (TopHom α β) where le f g := (f : α → β) ≤ g instance [Preorder β] [Top β] : Preorder (TopHom α β) := Preorder.lift (DFunLike.coe : TopHom α β → α → β) instance [PartialOrder β] [Top β] : PartialOrder (TopHom α β) := PartialOrder.lift _ DFunLike.coe_injective section OrderTop variable [LE β] [OrderTop β] instance : OrderTop (TopHom α β) where top := ⟨⊤, rfl⟩ le_top := fun _ => @le_top (α → β) _ _ _ @[simp] theorem coe_top : ⇑(⊤ : TopHom α β) = ⊤ := rfl @[simp] theorem top_apply (a : α) : (⊤ : TopHom α β) a = ⊤ := rfl end OrderTop section SemilatticeInf variable [SemilatticeInf β] [OrderTop β] (f g : TopHom α β) instance : Min (TopHom α β) := ⟨fun f g => ⟨f ⊓ g, by rw [Pi.inf_apply, map_top, map_top, inf_top_eq]⟩⟩ instance : SemilatticeInf (TopHom α β) := (DFunLike.coe_injective.semilatticeInf _) fun _ _ => rfl @[simp] theorem coe_inf : ⇑(f ⊓ g) = ⇑f ⊓ ⇑g := rfl @[simp] theorem inf_apply (a : α) : (f ⊓ g) a = f a ⊓ g a := rfl end SemilatticeInf section SemilatticeSup variable [SemilatticeSup β] [OrderTop β] (f g : TopHom α β) instance : Max (TopHom α β) := ⟨fun f g => ⟨f ⊔ g, by rw [Pi.sup_apply, map_top, map_top, sup_top_eq]⟩⟩ instance : SemilatticeSup (TopHom α β) := (DFunLike.coe_injective.semilatticeSup _) fun _ _ => rfl @[simp] theorem coe_sup : ⇑(f ⊔ g) = ⇑f ⊔ ⇑g := rfl @[simp] theorem sup_apply (a : α) : (f ⊔ g) a = f a ⊔ g a := rfl end SemilatticeSup instance [Lattice β] [OrderTop β] : Lattice (TopHom α β) := DFunLike.coe_injective.lattice _ (fun _ _ => rfl) fun _ _ => rfl instance [DistribLattice β] [OrderTop β] : DistribLattice (TopHom α β) := DFunLike.coe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl end TopHom /-! ### Bot homomorphisms -/ namespace BotHom variable [Bot α] section Bot variable [Bot β] [Bot γ] [Bot δ] instance : FunLike (BotHom α β) α β where coe := BotHom.toFun coe_injective' f g h := by cases f; cases g; congr instance : BotHomClass (BotHom α β) α β where map_bot := BotHom.map_bot' -- this must come after the coe_to_fun definition initialize_simps_projections BotHom (toFun → apply) @[ext] theorem ext {f g : BotHom α β} (h : ∀ a, f a = g a) : f = g := DFunLike.ext f g h /-- Copy of a `BotHom` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (f : BotHom α β) (f' : α → β) (h : f' = f) : BotHom α β where toFun := f' map_bot' := h.symm ▸ f.map_bot' @[simp] theorem coe_copy (f : BotHom α β) (f' : α → β) (h : f' = f) : ⇑(f.copy f' h) = f' := rfl theorem copy_eq (f : BotHom α β) (f' : α → β) (h : f' = f) : f.copy f' h = f := DFunLike.ext' h instance : Inhabited (BotHom α β) := ⟨⟨fun _ => ⊥, rfl⟩⟩ variable (α) /-- `id` as a `BotHom`. -/ protected def id : BotHom α α := ⟨id, rfl⟩ @[simp, norm_cast] theorem coe_id : ⇑(BotHom.id α) = id := rfl variable {α} @[simp] theorem id_apply (a : α) : BotHom.id α a = a := rfl /-- Composition of `BotHom`s as a `BotHom`. -/ def comp (f : BotHom β γ) (g : BotHom α β) : BotHom α γ where toFun := f ∘ g map_bot' := by rw [comp_apply, map_bot, map_bot] @[simp] theorem coe_comp (f : BotHom β γ) (g : BotHom α β) : (f.comp g : α → γ) = f ∘ g := rfl @[simp] theorem comp_apply (f : BotHom β γ) (g : BotHom α β) (a : α) : (f.comp g) a = f (g a) := rfl @[simp] theorem comp_assoc (f : BotHom γ δ) (g : BotHom β γ) (h : BotHom α β) : (f.comp g).comp h = f.comp (g.comp h) := rfl @[simp] theorem comp_id (f : BotHom α β) : f.comp (BotHom.id α) = f := BotHom.ext fun _ => rfl @[simp] theorem id_comp (f : BotHom α β) : (BotHom.id β).comp f = f := BotHom.ext fun _ => rfl @[simp] theorem cancel_right {g₁ g₂ : BotHom β γ} {f : BotHom α β} (hf : Surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨fun h => BotHom.ext <| hf.forall.2 <| DFunLike.ext_iff.1 h, congr_arg (comp · f)⟩ @[simp] theorem cancel_left {g : BotHom β γ} {f₁ f₂ : BotHom α β} (hg : Injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨fun h => BotHom.ext fun a => hg <| by rw [← BotHom.comp_apply, h, BotHom.comp_apply], congr_arg _⟩ end Bot instance instLE [LE β] [Bot β] : LE (BotHom α β) where le f g := (f : α → β) ≤ g instance [Preorder β] [Bot β] : Preorder (BotHom α β) := Preorder.lift (DFunLike.coe : BotHom α β → α → β) instance [PartialOrder β] [Bot β] : PartialOrder (BotHom α β) := PartialOrder.lift _ DFunLike.coe_injective section OrderBot variable [LE β] [OrderBot β] instance : OrderBot (BotHom α β) where bot := ⟨⊥, rfl⟩ bot_le := fun _ => @bot_le (α → β) _ _ _ @[simp] theorem coe_bot : ⇑(⊥ : BotHom α β) = ⊥ := rfl @[simp] theorem bot_apply (a : α) : (⊥ : BotHom α β) a = ⊥ := rfl end OrderBot section SemilatticeInf variable [SemilatticeInf β] [OrderBot β] (f g : BotHom α β) instance : Min (BotHom α β) := ⟨fun f g => ⟨f ⊓ g, by rw [Pi.inf_apply, map_bot, map_bot, inf_bot_eq]⟩⟩ instance : SemilatticeInf (BotHom α β) := (DFunLike.coe_injective.semilatticeInf _) fun _ _ => rfl @[simp] theorem coe_inf : ⇑(f ⊓ g) = ⇑f ⊓ ⇑g := rfl @[simp] theorem inf_apply (a : α) : (f ⊓ g) a = f a ⊓ g a := rfl end SemilatticeInf section SemilatticeSup variable [SemilatticeSup β] [OrderBot β] (f g : BotHom α β) instance : Max (BotHom α β) := ⟨fun f g => ⟨f ⊔ g, by rw [Pi.sup_apply, map_bot, map_bot, sup_bot_eq]⟩⟩
instance : SemilatticeSup (BotHom α β) := (DFunLike.coe_injective.semilatticeSup _) fun _ _ => rfl @[simp]
Mathlib/Order/Hom/Bounded.lean
498
501
/- 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⟩ exact Quotient.sound (PathConnectedSpace.joined x y) · unfold ZerothHomotopy rintro ⟨h, h'⟩ exact ⟨(nonempty_quotient_iff _).mp h, fun x y => Quotient.exact <| Subsingleton.elim ⟦x⟧ ⟦y⟧⟩ namespace PathConnectedSpace variable [PathConnectedSpace X] /-- Use path-connectedness to build a path between two points. -/ def somePath (x y : X) : Path x y := Nonempty.some (joined x y) end PathConnectedSpace theorem pathConnectedSpace_iff_univ : PathConnectedSpace X ↔ IsPathConnected (univ : Set X) := by simp [pathConnectedSpace_iff, isPathConnected_iff, nonempty_iff_univ_nonempty] theorem isPathConnected_iff_pathConnectedSpace : IsPathConnected F ↔ PathConnectedSpace F := by rw [pathConnectedSpace_iff_univ, IsInducing.subtypeVal.isPathConnected_iff, image_univ, Subtype.range_val_subtype, setOf_mem_eq] theorem isPathConnected_univ [PathConnectedSpace X] : IsPathConnected (univ : Set X) := pathConnectedSpace_iff_univ.mp inferInstance theorem isPathConnected_range [PathConnectedSpace X] {f : X → Y} (hf : Continuous f) : IsPathConnected (range f) := by rw [← image_univ] exact isPathConnected_univ.image hf theorem Function.Surjective.pathConnectedSpace [PathConnectedSpace X] {f : X → Y} (hf : Surjective f) (hf' : Continuous f) : PathConnectedSpace Y := by rw [pathConnectedSpace_iff_univ, ← hf.range_eq] exact isPathConnected_range hf' instance Quotient.instPathConnectedSpace {s : Setoid X} [PathConnectedSpace X] : PathConnectedSpace (Quotient s) := Quotient.mk'_surjective.pathConnectedSpace continuous_coinduced_rng /-- This is a special case of `NormedSpace.instPathConnectedSpace` (and `IsTopologicalAddGroup.pathConnectedSpace`). It exists only to simplify dependencies. -/ instance Real.instPathConnectedSpace : PathConnectedSpace ℝ where joined x y := ⟨⟨⟨fun (t : I) ↦ (1 - t) * x + t * y, by fun_prop⟩, by simp, by simp⟩⟩ nonempty := inferInstance theorem pathConnectedSpace_iff_eq : PathConnectedSpace X ↔ ∃ x : X, pathComponent x = univ := by simp [pathConnectedSpace_iff_univ, isPathConnected_iff_eq] -- see Note [lower instance priority] instance (priority := 100) PathConnectedSpace.connectedSpace [PathConnectedSpace X] : ConnectedSpace X := by rw [connectedSpace_iff_connectedComponent] rcases isPathConnected_iff_eq.mp (pathConnectedSpace_iff_univ.mp ‹_›) with ⟨x, _x_in, hx⟩ use x rw [← univ_subset_iff] exact (by simpa using hx : pathComponent x = univ) ▸ pathComponent_subset_component x theorem IsPathConnected.isConnected (hF : IsPathConnected F) : IsConnected F := by rw [isConnected_iff_connectedSpace] rw [isPathConnected_iff_pathConnectedSpace] at hF exact @PathConnectedSpace.connectedSpace _ _ hF namespace PathConnectedSpace variable [PathConnectedSpace X] theorem exists_path_through_family {n : ℕ} (p : Fin (n + 1) → X) : ∃ γ : Path (p 0) (p n), ∀ i, p i ∈ range γ := by have : IsPathConnected (univ : Set X) := pathConnectedSpace_iff_univ.mp (by infer_instance) rcases this.exists_path_through_family p fun _i => True.intro with ⟨γ, -, h⟩ exact ⟨γ, h⟩ theorem exists_path_through_family' {n : ℕ} (p : Fin (n + 1) → X) : ∃ (γ : Path (p 0) (p n)) (t : Fin (n + 1) → I), ∀ i, γ (t i) = p i := by have : IsPathConnected (univ : Set X) := pathConnectedSpace_iff_univ.mp (by infer_instance) rcases this.exists_path_through_family' p fun _i => True.intro with ⟨γ, t, -, h⟩ exact ⟨γ, t, h⟩ end PathConnectedSpace
Mathlib/Topology/Connected/PathConnected.lean
876
880
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Algebra.ModEq import Mathlib.Algebra.Order.Archimedean.Basic import Mathlib.Algebra.Ring.Periodic import Mathlib.Data.Int.SuccPred import Mathlib.Order.Circular /-! # Reducing to an interval modulo its length This file defines operations that reduce a number (in an `Archimedean` `LinearOrderedAddCommGroup`) to a number in a given interval, modulo the length of that interval. ## Main definitions * `toIcoDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ico a (a + p)`. * `toIcoMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ico a (a + p)`. * `toIocDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ioc a (a + p)`. * `toIocMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ioc a (a + p)`. -/ assert_not_exists TwoSidedIdeal noncomputable section section LinearOrderedAddCommGroup variable {α : Type*} [AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α] [hα : Archimedean α] {p : α} (hp : 0 < p) {a b c : α} {n : ℤ} section include hp /-- The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ico a (a + p)`. -/ def toIcoDiv (a b : α) : ℤ := (existsUnique_sub_zsmul_mem_Ico hp b a).choose theorem sub_toIcoDiv_zsmul_mem_Ico (a b : α) : b - toIcoDiv hp a b • p ∈ Set.Ico a (a + p) := (existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.1 theorem toIcoDiv_eq_of_sub_zsmul_mem_Ico (h : b - n • p ∈ Set.Ico a (a + p)) : toIcoDiv hp a b = n := ((existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.2 _ h).symm /-- The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ioc a (a + p)`. -/ def toIocDiv (a b : α) : ℤ := (existsUnique_sub_zsmul_mem_Ioc hp b a).choose theorem sub_toIocDiv_zsmul_mem_Ioc (a b : α) : b - toIocDiv hp a b • p ∈ Set.Ioc a (a + p) := (existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.1 theorem toIocDiv_eq_of_sub_zsmul_mem_Ioc (h : b - n • p ∈ Set.Ioc a (a + p)) : toIocDiv hp a b = n := ((existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.2 _ h).symm /-- Reduce `b` to the interval `Ico a (a + p)`. -/ def toIcoMod (a b : α) : α := b - toIcoDiv hp a b • p /-- Reduce `b` to the interval `Ioc a (a + p)`. -/ def toIocMod (a b : α) : α := b - toIocDiv hp a b • p theorem toIcoMod_mem_Ico (a b : α) : toIcoMod hp a b ∈ Set.Ico a (a + p) := sub_toIcoDiv_zsmul_mem_Ico hp a b theorem toIcoMod_mem_Ico' (b : α) : toIcoMod hp 0 b ∈ Set.Ico 0 p := by convert toIcoMod_mem_Ico hp 0 b exact (zero_add p).symm theorem toIocMod_mem_Ioc (a b : α) : toIocMod hp a b ∈ Set.Ioc a (a + p) := sub_toIocDiv_zsmul_mem_Ioc hp a b theorem left_le_toIcoMod (a b : α) : a ≤ toIcoMod hp a b := (Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).1 theorem left_lt_toIocMod (a b : α) : a < toIocMod hp a b := (Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).1 theorem toIcoMod_lt_right (a b : α) : toIcoMod hp a b < a + p := (Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).2 theorem toIocMod_le_right (a b : α) : toIocMod hp a b ≤ a + p := (Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).2 @[simp] theorem self_sub_toIcoDiv_zsmul (a b : α) : b - toIcoDiv hp a b • p = toIcoMod hp a b := rfl @[simp] theorem self_sub_toIocDiv_zsmul (a b : α) : b - toIocDiv hp a b • p = toIocMod hp a b := rfl @[simp] theorem toIcoDiv_zsmul_sub_self (a b : α) : toIcoDiv hp a b • p - b = -toIcoMod hp a b := by rw [toIcoMod, neg_sub] @[simp] theorem toIocDiv_zsmul_sub_self (a b : α) : toIocDiv hp a b • p - b = -toIocMod hp a b := by rw [toIocMod, neg_sub] @[simp] theorem toIcoMod_sub_self (a b : α) : toIcoMod hp a b - b = -toIcoDiv hp a b • p := by rw [toIcoMod, sub_sub_cancel_left, neg_smul] @[simp] theorem toIocMod_sub_self (a b : α) : toIocMod hp a b - b = -toIocDiv hp a b • p := by rw [toIocMod, sub_sub_cancel_left, neg_smul] @[simp] theorem self_sub_toIcoMod (a b : α) : b - toIcoMod hp a b = toIcoDiv hp a b • p := by rw [toIcoMod, sub_sub_cancel] @[simp] theorem self_sub_toIocMod (a b : α) : b - toIocMod hp a b = toIocDiv hp a b • p := by rw [toIocMod, sub_sub_cancel] @[simp] theorem toIcoMod_add_toIcoDiv_zsmul (a b : α) : toIcoMod hp a b + toIcoDiv hp a b • p = b := by rw [toIcoMod, sub_add_cancel] @[simp] theorem toIocMod_add_toIocDiv_zsmul (a b : α) : toIocMod hp a b + toIocDiv hp a b • p = b := by rw [toIocMod, sub_add_cancel] @[simp] theorem toIcoDiv_zsmul_sub_toIcoMod (a b : α) : toIcoDiv hp a b • p + toIcoMod hp a b = b := by
rw [add_comm, toIcoMod_add_toIcoDiv_zsmul]
Mathlib/Algebra/Order/ToIntervalMod.lean
138
139
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Fin.Tuple.Basic /-! # Lists from functions Theorems and lemmas for dealing with `List.ofFn`, which converts a function on `Fin n` to a list of length `n`. ## Main Statements The main statements pertain to lists generated using `List.ofFn` - `List.get?_ofFn`, which tells us the nth element of such a list - `List.equivSigmaTuple`, which is an `Equiv` between lists and the functions that generate them via `List.ofFn`. -/ assert_not_exists Monoid universe u variable {α : Type u} open Nat namespace List theorem get_ofFn {n} (f : Fin n → α) (i) : get (ofFn f) i = f (Fin.cast (by simp) i) := by simp; congr @[deprecated (since := "2025-02-15")] alias get?_ofFn := List.getElem?_ofFn @[simp] theorem map_ofFn {β : Type*} {n : ℕ} (f : Fin n → α) (g : α → β) : map g (ofFn f) = ofFn (g ∘ f) := ext_get (by simp) fun i h h' => by simp @[congr] theorem ofFn_congr {m n : ℕ} (h : m = n) (f : Fin m → α) : ofFn f = ofFn fun i : Fin n => f (Fin.cast h.symm i) := by subst h simp_rw [Fin.cast_refl, id] theorem ofFn_succ' {n} (f : Fin (succ n) → α) : ofFn f = (ofFn fun i => f (Fin.castSucc i)).concat (f (Fin.last _)) := by induction' n with n IH · rw [ofFn_zero, concat_nil, ofFn_succ, ofFn_zero] rfl · rw [ofFn_succ, IH, ofFn_succ, concat_cons, Fin.castSucc_zero] congr /-- Note this matches the convention of `List.ofFn_succ'`, putting the `Fin m` elements first. -/ theorem ofFn_add {m n} (f : Fin (m + n) → α) : List.ofFn f = (List.ofFn fun i => f (Fin.castAdd n i)) ++ List.ofFn fun j => f (Fin.natAdd m j) := by induction' n with n IH · rw [ofFn_zero, append_nil, Fin.castAdd_zero, Fin.cast_refl] rfl · rw [ofFn_succ', ofFn_succ', IH, append_concat] rfl @[simp] theorem ofFn_fin_append {m n} (a : Fin m → α) (b : Fin n → α) : List.ofFn (Fin.append a b) = List.ofFn a ++ List.ofFn b := by simp_rw [ofFn_add, Fin.append_left, Fin.append_right] /-- This breaks a list of `m*n` items into `m` groups each containing `n` elements. -/ theorem ofFn_mul {m n} (f : Fin (m * n) → α) : List.ofFn f = List.flatten (List.ofFn fun i : Fin m => List.ofFn fun j : Fin n => f ⟨i * n + j, calc ↑i * n + j < (i + 1) * n := (Nat.add_lt_add_left j.prop _).trans_eq (by rw [Nat.add_mul, Nat.one_mul]) _ ≤ _ := Nat.mul_le_mul_right _ i.prop⟩) := by induction' m with m IH · simp [ofFn_zero, Nat.zero_mul, ofFn_zero, flatten] · simp_rw [ofFn_succ', succ_mul] simp [flatten_concat, ofFn_add, IH] rfl /-- This breaks a list of `m*n` items into `n` groups each containing `m` elements. -/ theorem ofFn_mul' {m n} (f : Fin (m * n) → α) : List.ofFn f = List.flatten (List.ofFn fun i : Fin n => List.ofFn fun j : Fin m => f ⟨m * i + j, calc m * i + j < m * (i + 1) := (Nat.add_lt_add_left j.prop _).trans_eq (by rw [Nat.mul_add, Nat.mul_one]) _ ≤ _ := Nat.mul_le_mul_left _ i.prop⟩) := by simp_rw [m.mul_comm, ofFn_mul, Fin.cast_mk] @[simp] theorem ofFn_get : ∀ l : List α, (ofFn (get l)) = l | [] => by rw [ofFn_zero] | a :: l => by rw [ofFn_succ] congr
exact ofFn_get l @[simp]
Mathlib/Data/List/OfFn.lean
99
101
/- Copyright (c) 2021 Bryan Gin-ge Chen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bryan Gin-ge Chen, Yury Kudryashov -/ import Mathlib.Algebra.Group.Hom.Defs /-! # Extensionality lemmas for monoid and group structures In this file we prove extensionality lemmas for `Monoid` and higher algebraic structures with one binary operation. Extensionality lemmas for structures that are lower in the hierarchy can be found in `Algebra.Group.Defs`. ## Implementation details To get equality of `npow` etc, we define a monoid homomorphism between two monoid structures on the same type, then apply lemmas like `MonoidHom.map_div`, `MonoidHom.map_pow` etc. To refer to the `*` operator of a particular instance `i`, we use `(letI := i; HMul.hMul : M → M → M)` instead of `i.mul` (which elaborates to `Mul.mul`), as the former uses `HMul.hMul` which is the canonical spelling. ## Tags monoid, group, extensionality -/ assert_not_exists MonoidWithZero DenselyOrdered open Function universe u @[to_additive (attr := ext)] theorem Monoid.ext {M : Type u} ⦃m₁ m₂ : Monoid M⦄ (h_mul : (letI := m₁; HMul.hMul : M → M → M) = (letI := m₂; HMul.hMul : M → M → M)) : m₁ = m₂ := by have : m₁.toMulOneClass = m₂.toMulOneClass := MulOneClass.ext h_mul have h₁ : m₁.one = m₂.one := congr_arg (·.one) this let f : @MonoidHom M M m₁.toMulOneClass m₂.toMulOneClass := @MonoidHom.mk _ _ (_) _ (@OneHom.mk _ _ (_) _ id h₁) (fun x y => congr_fun (congr_fun h_mul x) y) have : m₁.npow = m₂.npow := by ext n x exact @MonoidHom.map_pow M M m₁ m₂ f x n rcases m₁ with @⟨@⟨⟨_⟩⟩, ⟨_⟩⟩ rcases m₂ with @⟨@⟨⟨_⟩⟩, ⟨_⟩⟩ congr @[to_additive] theorem CommMonoid.toMonoid_injective {M : Type u} : Function.Injective (@CommMonoid.toMonoid M) := by rintro ⟨⟩ ⟨⟩ h congr @[to_additive (attr := ext)] theorem CommMonoid.ext {M : Type*} ⦃m₁ m₂ : CommMonoid M⦄ (h_mul : (letI := m₁; HMul.hMul : M → M → M) = (letI := m₂; HMul.hMul : M → M → M)) : m₁ = m₂ := CommMonoid.toMonoid_injective <| Monoid.ext h_mul @[to_additive] theorem LeftCancelMonoid.toMonoid_injective {M : Type u} : Function.Injective (@LeftCancelMonoid.toMonoid M) := by rintro @⟨@⟨⟩⟩ @⟨@⟨⟩⟩ h congr <;> injection h @[to_additive (attr := ext)] theorem LeftCancelMonoid.ext {M : Type u} ⦃m₁ m₂ : LeftCancelMonoid M⦄ (h_mul : (letI := m₁; HMul.hMul : M → M → M) = (letI := m₂; HMul.hMul : M → M → M)) : m₁ = m₂ :=
LeftCancelMonoid.toMonoid_injective <| Monoid.ext h_mul @[to_additive] theorem RightCancelMonoid.toMonoid_injective {M : Type u} :
Mathlib/Algebra/Group/Ext.lean
71
74