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) 2021 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Order.Lattice import Mathlib.Data.List.Sort import Mathlib.Logic.Equiv.Fin.Basic import Mathlib.Logic.Equiv.Functor import Mathlib.Data.Fintype.Pigeonhole import Mathlib.Order.RelSeries /-! # Jordan-Hölder Theorem This file proves the Jordan Hölder theorem for a `JordanHolderLattice`, a class also defined in this file. Examples of `JordanHolderLattice` include `Subgroup G` if `G` is a group, and `Submodule R M` if `M` is an `R`-module. Using this approach the theorem need not be proved separately for both groups and modules, the proof in this file can be applied to both. ## Main definitions The main definitions in this file are `JordanHolderLattice` and `CompositionSeries`, and the relation `Equivalent` on `CompositionSeries` A `JordanHolderLattice` is the class for which the Jordan Hölder theorem is proved. A Jordan Hölder lattice is a lattice equipped with a notion of maximality, `IsMaximal`, and a notion of isomorphism of pairs `Iso`. In the example of subgroups of a group, `IsMaximal H K` means that `H` is a maximal normal subgroup of `K`, and `Iso (H₁, K₁) (H₂, K₂)` means that the quotient `H₁ / K₁` is isomorphic to the quotient `H₂ / K₂`. `Iso` must be symmetric and transitive and must satisfy the second isomorphism theorem `Iso (H, H ⊔ K) (H ⊓ K, K)`. A `CompositionSeries X` is a finite nonempty series of elements of the lattice `X` such that each element is maximal inside the next. The length of a `CompositionSeries X` is one less than the number of elements in the series. Note that there is no stipulation that a series start from the bottom of the lattice and finish at the top. For a composition series `s`, `s.last` is the largest element of the series, and `s.head` is the least element. Two `CompositionSeries X`, `s₁` and `s₂` are equivalent if there is a bijection `e : Fin s₁.length ≃ Fin s₂.length` such that for any `i`, `Iso (s₁ i, s₁ i.succ) (s₂ (e i), s₂ (e i.succ))` ## Main theorems The main theorem is `CompositionSeries.jordan_holder`, which says that if two composition series have the same least element and the same largest element, then they are `Equivalent`. ## TODO Provide instances of `JordanHolderLattice` for subgroups, and potentially for modular lattices. It is not entirely clear how this should be done. Possibly there should be no global instances of `JordanHolderLattice`, and the instances should only be defined locally in order to prove the Jordan-Hölder theorem for modules/groups and the API should be transferred because many of the theorems in this file will have stronger versions for modules. There will also need to be an API for mapping composition series across homomorphisms. It is also probably possible to provide an instance of `JordanHolderLattice` for any `ModularLattice`, and in this case the Jordan-Hölder theorem will say that there is a well defined notion of length of a modular lattice. However an instance of `JordanHolderLattice` for a modular lattice will not be able to contain the correct notion of isomorphism for modules, so a separate instance for modules will still be required and this will clash with the instance for modular lattices, and so at least one of these instances should not be a global instance. > [!NOTE] > The previous paragraph indicates that the instance of `JordanHolderLattice` for submodules should > be obtained via `ModularLattice`. This is not the case in `mathlib4`. > See `JordanHolderModule.instJordanHolderLattice`. -/ universe u open Set RelSeries /-- A `JordanHolderLattice` is the class for which the Jordan Hölder theorem is proved. A Jordan Hölder lattice is a lattice equipped with a notion of maximality, `IsMaximal`, and a notion of isomorphism of pairs `Iso`. In the example of subgroups of a group, `IsMaximal H K` means that `H` is a maximal normal subgroup of `K`, and `Iso (H₁, K₁) (H₂, K₂)` means that the quotient `H₁ / K₁` is isomorphic to the quotient `H₂ / K₂`. `Iso` must be symmetric and transitive and must satisfy the second isomorphism theorem `Iso (H, H ⊔ K) (H ⊓ K, K)`. Examples include `Subgroup G` if `G` is a group, and `Submodule R M` if `M` is an `R`-module. -/ class JordanHolderLattice (X : Type u) [Lattice X] where IsMaximal : X → X → Prop lt_of_isMaximal : ∀ {x y}, IsMaximal x y → x < y sup_eq_of_isMaximal : ∀ {x y z}, IsMaximal x z → IsMaximal y z → x ≠ y → x ⊔ y = z isMaximal_inf_left_of_isMaximal_sup : ∀ {x y}, IsMaximal x (x ⊔ y) → IsMaximal y (x ⊔ y) → IsMaximal (x ⊓ y) x Iso : X × X → X × X → Prop iso_symm : ∀ {x y}, Iso x y → Iso y x iso_trans : ∀ {x y z}, Iso x y → Iso y z → Iso x z second_iso : ∀ {x y}, IsMaximal x (x ⊔ y) → Iso (x, x ⊔ y) (x ⊓ y, y) namespace JordanHolderLattice variable {X : Type u} [Lattice X] [JordanHolderLattice X] theorem isMaximal_inf_right_of_isMaximal_sup {x y : X} (hxz : IsMaximal x (x ⊔ y)) (hyz : IsMaximal y (x ⊔ y)) : IsMaximal (x ⊓ y) y := by rw [inf_comm] rw [sup_comm] at hxz hyz exact isMaximal_inf_left_of_isMaximal_sup hyz hxz theorem isMaximal_of_eq_inf (x b : X) {a y : X} (ha : x ⊓ y = a) (hxy : x ≠ y) (hxb : IsMaximal x b) (hyb : IsMaximal y b) : IsMaximal a y := by have hb : x ⊔ y = b := sup_eq_of_isMaximal hxb hyb hxy substs a b exact isMaximal_inf_right_of_isMaximal_sup hxb hyb theorem second_iso_of_eq {x y a b : X} (hm : IsMaximal x a) (ha : x ⊔ y = a) (hb : x ⊓ y = b) : Iso (x, a) (b, y) := by substs a b; exact second_iso hm theorem IsMaximal.iso_refl {x y : X} (h : IsMaximal x y) : Iso (x, y) (x, y) := second_iso_of_eq h (sup_eq_right.2 (le_of_lt (lt_of_isMaximal h))) (inf_eq_left.2 (le_of_lt (lt_of_isMaximal h))) end JordanHolderLattice open JordanHolderLattice attribute [symm] iso_symm attribute [trans] iso_trans /-- A `CompositionSeries X` is a finite nonempty series of elements of a `JordanHolderLattice` such that each element is maximal inside the next. The length of a `CompositionSeries X` is one less than the number of elements in the series. Note that there is no stipulation that a series start from the bottom of the lattice and finish at the top. For a composition series `s`, `s.last` is the largest element of the series, and `s.head` is the least element. -/ abbrev CompositionSeries (X : Type u) [Lattice X] [JordanHolderLattice X] : Type u := RelSeries (IsMaximal (X := X)) namespace CompositionSeries variable {X : Type u} [Lattice X] [JordanHolderLattice X] theorem lt_succ (s : CompositionSeries X) (i : Fin s.length) : s (Fin.castSucc i) < s (Fin.succ i) := lt_of_isMaximal (s.step _) protected theorem strictMono (s : CompositionSeries X) : StrictMono s := Fin.strictMono_iff_lt_succ.2 s.lt_succ protected theorem injective (s : CompositionSeries X) : Function.Injective s := s.strictMono.injective @[simp] protected theorem inj (s : CompositionSeries X) {i j : Fin s.length.succ} : s i = s j ↔ i = j := s.injective.eq_iff theorem total {s : CompositionSeries X} {x y : X} (hx : x ∈ s) (hy : y ∈ s) : x ≤ y ∨ y ≤ x := by rcases Set.mem_range.1 hx with ⟨i, rfl⟩ rcases Set.mem_range.1 hy with ⟨j, rfl⟩ rw [s.strictMono.le_iff_le, s.strictMono.le_iff_le] exact le_total i j theorem toList_sorted (s : CompositionSeries X) : s.toList.Sorted (· < ·) := List.pairwise_iff_get.2 fun i j h => by dsimp only [RelSeries.toList] rw [List.get_ofFn, List.get_ofFn] exact s.strictMono h theorem toList_nodup (s : CompositionSeries X) : s.toList.Nodup := s.toList_sorted.nodup /-- Two `CompositionSeries` are equal if they have the same elements. See also `ext_fun`. -/ @[ext] theorem ext {s₁ s₂ : CompositionSeries X} (h : ∀ x, x ∈ s₁ ↔ x ∈ s₂) : s₁ = s₂ := toList_injective <| List.eq_of_perm_of_sorted (by classical exact List.perm_of_nodup_nodup_toFinset_eq s₁.toList_nodup s₂.toList_nodup (Finset.ext <| by simpa only [List.mem_toFinset, RelSeries.mem_toList])) s₁.toList_sorted s₂.toList_sorted @[simp] theorem le_last {s : CompositionSeries X} (i : Fin (s.length + 1)) : s i ≤ s.last := s.strictMono.monotone (Fin.le_last _) theorem le_last_of_mem {s : CompositionSeries X} {x : X} (hx : x ∈ s) : x ≤ s.last := let ⟨_i, hi⟩ := Set.mem_range.2 hx hi ▸ le_last _ @[simp] theorem head_le {s : CompositionSeries X} (i : Fin (s.length + 1)) : s.head ≤ s i := s.strictMono.monotone (Fin.zero_le _) theorem head_le_of_mem {s : CompositionSeries X} {x : X} (hx : x ∈ s) : s.head ≤ x := let ⟨_i, hi⟩ := Set.mem_range.2 hx hi ▸ head_le _ theorem last_eraseLast_le (s : CompositionSeries X) : s.eraseLast.last ≤ s.last := by simp [eraseLast, last, s.strictMono.le_iff_le, Fin.le_iff_val_le_val] theorem mem_eraseLast_of_ne_of_mem {s : CompositionSeries X} {x : X} (hx : x ≠ s.last) (hxs : x ∈ s) : x ∈ s.eraseLast := by rcases hxs with ⟨i, rfl⟩ have hi : (i : ℕ) < (s.length - 1).succ := by conv_rhs => rw [← Nat.succ_sub (length_pos_of_nontrivial ⟨_, ⟨i, rfl⟩, _, s.last_mem, hx⟩), Nat.add_one_sub_one] exact lt_of_le_of_ne (Nat.le_of_lt_succ i.2) (by simpa [last, s.inj, Fin.ext_iff] using hx) refine ⟨Fin.castSucc (n := s.length + 1) i, ?_⟩ simp [Fin.ext_iff, Nat.mod_eq_of_lt hi] theorem mem_eraseLast {s : CompositionSeries X} {x : X} (h : 0 < s.length) : x ∈ s.eraseLast ↔ x ≠ s.last ∧ x ∈ s := by simp only [RelSeries.mem_def, eraseLast] constructor · rintro ⟨i, rfl⟩ have hi : (i : ℕ) < s.length := by conv_rhs => rw [← Nat.add_one_sub_one s.length, Nat.succ_sub h] exact i.2 simp [last, Fin.ext_iff, ne_of_lt hi, -Set.mem_range, Set.mem_range_self] · intro h exact mem_eraseLast_of_ne_of_mem h.1 h.2 theorem lt_last_of_mem_eraseLast {s : CompositionSeries X} {x : X} (h : 0 < s.length) (hx : x ∈ s.eraseLast) : x < s.last := lt_of_le_of_ne (le_last_of_mem ((mem_eraseLast h).1 hx).2) ((mem_eraseLast h).1 hx).1 theorem isMaximal_eraseLast_last {s : CompositionSeries X} (h : 0 < s.length) : IsMaximal s.eraseLast.last s.last := by have : s.length - 1 + 1 = s.length := by conv_rhs => rw [← Nat.add_one_sub_one s.length]; rw [Nat.succ_sub h] rw [last_eraseLast, last] convert s.step ⟨s.length - 1, by omega⟩; ext; simp [this] theorem eq_snoc_eraseLast {s : CompositionSeries X} (h : 0 < s.length) : s = snoc (eraseLast s) s.last (isMaximal_eraseLast_last h) := by ext x simp only [mem_snoc, mem_eraseLast h, ne_eq] by_cases h : x = s.last <;> simp [*, s.last_mem] @[simp] theorem snoc_eraseLast_last {s : CompositionSeries X} (h : IsMaximal s.eraseLast.last s.last) : s.eraseLast.snoc s.last h = s := have h : 0 < s.length := Nat.pos_of_ne_zero (fun hs => ne_of_gt (lt_of_isMaximal h) <| by simp [last, Fin.ext_iff, hs]) (eq_snoc_eraseLast h).symm /-- Two `CompositionSeries X`, `s₁` and `s₂` are equivalent if there is a bijection `e : Fin s₁.length ≃ Fin s₂.length` such that for any `i`, `Iso (s₁ i) (s₁ i.succ) (s₂ (e i), s₂ (e i.succ))` -/ def Equivalent (s₁ s₂ : CompositionSeries X) : Prop := ∃ f : Fin s₁.length ≃ Fin s₂.length, ∀ i : Fin s₁.length, Iso (s₁ (Fin.castSucc i), s₁ i.succ) (s₂ (Fin.castSucc (f i)), s₂ (Fin.succ (f i))) namespace Equivalent @[refl] theorem refl (s : CompositionSeries X) : Equivalent s s := ⟨Equiv.refl _, fun _ => (s.step _).iso_refl⟩ @[symm] theorem symm {s₁ s₂ : CompositionSeries X} (h : Equivalent s₁ s₂) : Equivalent s₂ s₁ := ⟨h.choose.symm, fun i => iso_symm (by simpa using h.choose_spec (h.choose.symm i))⟩ @[trans] theorem trans {s₁ s₂ s₃ : CompositionSeries X} (h₁ : Equivalent s₁ s₂) (h₂ : Equivalent s₂ s₃) : Equivalent s₁ s₃ := ⟨h₁.choose.trans h₂.choose, fun i => iso_trans (h₁.choose_spec i) (h₂.choose_spec (h₁.choose i))⟩ protected theorem smash {s₁ s₂ t₁ t₂ : CompositionSeries X} (hs : s₁.last = s₂.head) (ht : t₁.last = t₂.head) (h₁ : Equivalent s₁ t₁) (h₂ : Equivalent s₂ t₂) : Equivalent (smash s₁ s₂ hs) (smash t₁ t₂ ht) := let e : Fin (s₁.length + s₂.length) ≃ Fin (t₁.length + t₂.length) := calc Fin (s₁.length + s₂.length) ≃ (Fin s₁.length) ⊕ (Fin s₂.length) := finSumFinEquiv.symm _ ≃ (Fin t₁.length) ⊕ (Fin t₂.length) := Equiv.sumCongr h₁.choose h₂.choose _ ≃ Fin (t₁.length + t₂.length) := finSumFinEquiv ⟨e, by intro i refine Fin.addCases ?_ ?_ i · intro i simpa [e, smash_castAdd, smash_succ_castAdd] using h₁.choose_spec i · intro i simpa [e, smash_natAdd, smash_succ_natAdd] using h₂.choose_spec i⟩ protected theorem snoc {s₁ s₂ : CompositionSeries X} {x₁ x₂ : X} {hsat₁ : IsMaximal s₁.last x₁} {hsat₂ : IsMaximal s₂.last x₂} (hequiv : Equivalent s₁ s₂) (hlast : Iso (s₁.last, x₁) (s₂.last, x₂)) : Equivalent (s₁.snoc x₁ hsat₁) (s₂.snoc x₂ hsat₂) := let e : Fin s₁.length.succ ≃ Fin s₂.length.succ := calc Fin (s₁.length + 1) ≃ Option (Fin s₁.length) := finSuccEquivLast _ ≃ Option (Fin s₂.length) := Functor.mapEquiv Option hequiv.choose _ ≃ Fin (s₂.length + 1) := finSuccEquivLast.symm ⟨e, fun i => by refine Fin.lastCases ?_ ?_ i · simpa [e, apply_last] using hlast · intro i simpa [e, Fin.succ_castSucc] using hequiv.choose_spec i⟩ theorem length_eq {s₁ s₂ : CompositionSeries X} (h : Equivalent s₁ s₂) : s₁.length = s₂.length := by simpa using Fintype.card_congr h.choose theorem snoc_snoc_swap {s : CompositionSeries X} {x₁ x₂ y₁ y₂ : X} {hsat₁ : IsMaximal s.last x₁} {hsat₂ : IsMaximal s.last x₂} {hsaty₁ : IsMaximal (snoc s x₁ hsat₁).last y₁} {hsaty₂ : IsMaximal (snoc s x₂ hsat₂).last y₂} (hr₁ : Iso (s.last, x₁) (x₂, y₂)) (hr₂ : Iso (x₁, y₁) (s.last, x₂)) : Equivalent (snoc (snoc s x₁ hsat₁) y₁ hsaty₁) (snoc (snoc s x₂ hsat₂) y₂ hsaty₂) := let e : Fin (s.length + 1 + 1) ≃ Fin (s.length + 1 + 1) := Equiv.swap (Fin.last _) (Fin.castSucc (Fin.last _)) have h1 : ∀ {i : Fin s.length}, (Fin.castSucc (Fin.castSucc i)) ≠ (Fin.castSucc (Fin.last _)) := by simp have h2 : ∀ {i : Fin s.length}, (Fin.castSucc (Fin.castSucc i)) ≠ Fin.last _ := by simp ⟨e, by intro i dsimp only [e] refine Fin.lastCases ?_ (fun i => ?_) i · erw [Equiv.swap_apply_left, snoc_castSucc, show (snoc s x₁ hsat₁).toFun (Fin.last _) = x₁ from last_snoc _ _ _, Fin.succ_last, show ((s.snoc x₁ hsat₁).snoc y₁ hsaty₁).toFun (Fin.last _) = y₁ from last_snoc _ _ _, snoc_castSucc, snoc_castSucc, Fin.succ_castSucc, snoc_castSucc, Fin.succ_last, show (s.snoc _ hsat₂).toFun (Fin.last _) = x₂ from last_snoc _ _ _] exact hr₂ · refine Fin.lastCases ?_ (fun i => ?_) i · erw [Equiv.swap_apply_right, snoc_castSucc, snoc_castSucc, snoc_castSucc, Fin.succ_castSucc, snoc_castSucc, Fin.succ_last, last_snoc', last_snoc', last_snoc'] exact hr₁ · erw [Equiv.swap_apply_of_ne_of_ne h2 h1, snoc_castSucc, snoc_castSucc, snoc_castSucc, snoc_castSucc, Fin.succ_castSucc, snoc_castSucc, Fin.succ_castSucc, snoc_castSucc, snoc_castSucc, snoc_castSucc] exact (s.step i).iso_refl⟩ end Equivalent theorem length_eq_zero_of_head_eq_head_of_last_eq_last_of_length_eq_zero {s₁ s₂ : CompositionSeries X} (hb : s₁.head = s₂.head) (ht : s₁.last = s₂.last) (hs₁ : s₁.length = 0) : s₂.length = 0 := by have : Fin.last s₂.length = (0 : Fin s₂.length.succ) := s₂.injective (hb.symm.trans ((congr_arg s₁ (Fin.ext (by simp [hs₁]))).trans ht)).symm simpa [Fin.ext_iff] theorem length_pos_of_head_eq_head_of_last_eq_last_of_length_pos {s₁ s₂ : CompositionSeries X} (hb : s₁.head = s₂.head) (ht : s₁.last = s₂.last) : 0 < s₁.length → 0 < s₂.length := not_imp_not.1 (by simpa only [pos_iff_ne_zero, ne_eq, Decidable.not_not] using length_eq_zero_of_head_eq_head_of_last_eq_last_of_length_eq_zero hb.symm ht.symm) theorem eq_of_head_eq_head_of_last_eq_last_of_length_eq_zero {s₁ s₂ : CompositionSeries X} (hb : s₁.head = s₂.head) (ht : s₁.last = s₂.last) (hs₁0 : s₁.length = 0) : s₁ = s₂ := by have : ∀ x, x ∈ s₁ ↔ x = s₁.last := fun x => ⟨fun hx => subsingleton_of_length_eq_zero hs₁0 hx s₁.last_mem, fun hx => hx.symm ▸ s₁.last_mem⟩ have : ∀ x, x ∈ s₂ ↔ x = s₂.last := fun x => ⟨fun hx => subsingleton_of_length_eq_zero (length_eq_zero_of_head_eq_head_of_last_eq_last_of_length_eq_zero hb ht hs₁0) hx s₂.last_mem, fun hx => hx.symm ▸ s₂.last_mem⟩ ext simp [*]
/-- Given a `CompositionSeries`, `s`, and an element `x` such that `x` is maximal inside `s.last` there is a series, `t`, such that `t.last = x`, `t.head = s.head` and `snoc t s.last _` is equivalent to `s`. -/ theorem exists_last_eq_snoc_equivalent (s : CompositionSeries X) (x : X) (hm : IsMaximal x s.last) (hb : s.head ≤ x) : ∃ t : CompositionSeries X, t.head = s.head ∧ t.length + 1 = s.length ∧ ∃ htx : t.last = x, Equivalent s (snoc t s.last (show IsMaximal t.last _ from htx.symm ▸ hm)) := by induction' hn : s.length with n ih generalizing s x · exact (ne_of_gt (lt_of_le_of_lt hb (lt_of_isMaximal hm)) (subsingleton_of_length_eq_zero hn s.last_mem s.head_mem)).elim · have h0s : 0 < s.length := hn.symm ▸ Nat.succ_pos _
Mathlib/Order/JordanHolder.lean
360
375
/- Copyright (c) 2017 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Mario Carneiro -/ import Mathlib.Algebra.Ring.CharZero import Mathlib.Algebra.Star.Basic import Mathlib.Data.Real.Basic import Mathlib.Order.Interval.Set.UnorderedInterval import Mathlib.Tactic.Ring /-! # The complex numbers The complex numbers are modelled as ℝ^2 in the obvious way and it is shown that they form a field of characteristic zero. The result that the complex numbers are algebraically closed, see `FieldTheory.AlgebraicClosure`. -/ assert_not_exists Multiset Algebra open Set Function /-! ### Definition and basic arithmetic -/ /-- Complex numbers consist of two `Real`s: a real part `re` and an imaginary part `im`. -/ structure Complex : Type where /-- The real part of a complex number. -/ re : ℝ /-- The imaginary part of a complex number. -/ im : ℝ @[inherit_doc] notation "ℂ" => Complex namespace Complex open ComplexConjugate noncomputable instance : DecidableEq ℂ := Classical.decEq _ /-- The equivalence between the complex numbers and `ℝ × ℝ`. -/ @[simps apply] def equivRealProd : ℂ ≃ ℝ × ℝ where toFun z := ⟨z.re, z.im⟩ invFun p := ⟨p.1, p.2⟩ left_inv := fun ⟨_, _⟩ => rfl right_inv := fun ⟨_, _⟩ => rfl @[simp] theorem eta : ∀ z : ℂ, Complex.mk z.re z.im = z | ⟨_, _⟩ => rfl -- We only mark this lemma with `ext` *locally* to avoid it applying whenever terms of `ℂ` appear. theorem ext : ∀ {z w : ℂ}, z.re = w.re → z.im = w.im → z = w | ⟨_, _⟩, ⟨_, _⟩, rfl, rfl => rfl attribute [local ext] Complex.ext lemma «forall» {p : ℂ → Prop} : (∀ x, p x) ↔ ∀ a b, p ⟨a, b⟩ := by aesop lemma «exists» {p : ℂ → Prop} : (∃ x, p x) ↔ ∃ a b, p ⟨a, b⟩ := by aesop theorem re_surjective : Surjective re := fun x => ⟨⟨x, 0⟩, rfl⟩ theorem im_surjective : Surjective im := fun y => ⟨⟨0, y⟩, rfl⟩ @[simp] theorem range_re : range re = univ := re_surjective.range_eq @[simp] theorem range_im : range im = univ := im_surjective.range_eq /-- The natural inclusion of the real numbers into the complex numbers. -/ @[coe] def ofReal (r : ℝ) : ℂ := ⟨r, 0⟩ instance : Coe ℝ ℂ := ⟨ofReal⟩ @[simp, norm_cast] theorem ofReal_re (r : ℝ) : Complex.re (r : ℂ) = r := rfl @[simp, norm_cast] theorem ofReal_im (r : ℝ) : (r : ℂ).im = 0 := rfl theorem ofReal_def (r : ℝ) : (r : ℂ) = ⟨r, 0⟩ := rfl @[simp, norm_cast] theorem ofReal_inj {z w : ℝ} : (z : ℂ) = w ↔ z = w := ⟨congrArg re, by apply congrArg⟩ theorem ofReal_injective : Function.Injective ((↑) : ℝ → ℂ) := fun _ _ => congrArg re instance canLift : CanLift ℂ ℝ (↑) fun z => z.im = 0 where prf z hz := ⟨z.re, ext rfl hz.symm⟩ /-- The product of a set on the real axis and a set on the imaginary axis of the complex plane, denoted by `s ×ℂ t`. -/ def reProdIm (s t : Set ℝ) : Set ℂ := re ⁻¹' s ∩ im ⁻¹' t @[deprecated (since := "2024-12-03")] protected alias Set.reProdIm := reProdIm @[inherit_doc] infixl:72 " ×ℂ " => reProdIm theorem mem_reProdIm {z : ℂ} {s t : Set ℝ} : z ∈ s ×ℂ t ↔ z.re ∈ s ∧ z.im ∈ t := Iff.rfl instance : Zero ℂ := ⟨(0 : ℝ)⟩ instance : Inhabited ℂ := ⟨0⟩ @[simp] theorem zero_re : (0 : ℂ).re = 0 := rfl @[simp] theorem zero_im : (0 : ℂ).im = 0 := rfl @[simp, norm_cast] theorem ofReal_zero : ((0 : ℝ) : ℂ) = 0 := rfl @[simp] theorem ofReal_eq_zero {z : ℝ} : (z : ℂ) = 0 ↔ z = 0 := ofReal_inj theorem ofReal_ne_zero {z : ℝ} : (z : ℂ) ≠ 0 ↔ z ≠ 0 := not_congr ofReal_eq_zero instance : One ℂ := ⟨(1 : ℝ)⟩ @[simp] theorem one_re : (1 : ℂ).re = 1 := rfl @[simp] theorem one_im : (1 : ℂ).im = 0 := rfl @[simp, norm_cast] theorem ofReal_one : ((1 : ℝ) : ℂ) = 1 := rfl @[simp] theorem ofReal_eq_one {z : ℝ} : (z : ℂ) = 1 ↔ z = 1 := ofReal_inj theorem ofReal_ne_one {z : ℝ} : (z : ℂ) ≠ 1 ↔ z ≠ 1 := not_congr ofReal_eq_one instance : Add ℂ := ⟨fun z w => ⟨z.re + w.re, z.im + w.im⟩⟩ @[simp] theorem add_re (z w : ℂ) : (z + w).re = z.re + w.re := rfl @[simp] theorem add_im (z w : ℂ) : (z + w).im = z.im + w.im := rfl -- replaced by `re_ofNat` -- replaced by `im_ofNat` @[simp, norm_cast] theorem ofReal_add (r s : ℝ) : ((r + s : ℝ) : ℂ) = r + s := Complex.ext_iff.2 <| by simp [ofReal] -- replaced by `Complex.ofReal_ofNat` instance : Neg ℂ := ⟨fun z => ⟨-z.re, -z.im⟩⟩ @[simp] theorem neg_re (z : ℂ) : (-z).re = -z.re := rfl @[simp] theorem neg_im (z : ℂ) : (-z).im = -z.im := rfl @[simp, norm_cast] theorem ofReal_neg (r : ℝ) : ((-r : ℝ) : ℂ) = -r := Complex.ext_iff.2 <| by simp [ofReal] instance : Sub ℂ := ⟨fun z w => ⟨z.re - w.re, z.im - w.im⟩⟩ instance : Mul ℂ := ⟨fun z w => ⟨z.re * w.re - z.im * w.im, z.re * w.im + z.im * w.re⟩⟩ @[simp] theorem mul_re (z w : ℂ) : (z * w).re = z.re * w.re - z.im * w.im := rfl @[simp] theorem mul_im (z w : ℂ) : (z * w).im = z.re * w.im + z.im * w.re := rfl @[simp, norm_cast] theorem ofReal_mul (r s : ℝ) : ((r * s : ℝ) : ℂ) = r * s := Complex.ext_iff.2 <| by simp [ofReal] theorem re_ofReal_mul (r : ℝ) (z : ℂ) : (r * z).re = r * z.re := by simp [ofReal] theorem im_ofReal_mul (r : ℝ) (z : ℂ) : (r * z).im = r * z.im := by simp [ofReal] lemma re_mul_ofReal (z : ℂ) (r : ℝ) : (z * r).re = z.re * r := by simp [ofReal] lemma im_mul_ofReal (z : ℂ) (r : ℝ) : (z * r).im = z.im * r := by simp [ofReal] theorem ofReal_mul' (r : ℝ) (z : ℂ) : ↑r * z = ⟨r * z.re, r * z.im⟩ := ext (re_ofReal_mul _ _) (im_ofReal_mul _ _) /-! ### The imaginary unit, `I` -/ /-- The imaginary unit. -/ def I : ℂ := ⟨0, 1⟩ @[simp] theorem I_re : I.re = 0 := rfl @[simp] theorem I_im : I.im = 1 := rfl @[simp] theorem I_mul_I : I * I = -1 := Complex.ext_iff.2 <| by simp theorem I_mul (z : ℂ) : I * z = ⟨-z.im, z.re⟩ := Complex.ext_iff.2 <| by simp @[simp] lemma I_ne_zero : (I : ℂ) ≠ 0 := mt (congr_arg im) zero_ne_one.symm theorem mk_eq_add_mul_I (a b : ℝ) : Complex.mk a b = a + b * I := Complex.ext_iff.2 <| by simp [ofReal] @[simp] theorem re_add_im (z : ℂ) : (z.re : ℂ) + z.im * I = z := Complex.ext_iff.2 <| by simp [ofReal] theorem mul_I_re (z : ℂ) : (z * I).re = -z.im := by simp theorem mul_I_im (z : ℂ) : (z * I).im = z.re := by simp
theorem I_mul_re (z : ℂ) : (I * z).re = -z.im := by simp
Mathlib/Data/Complex/Basic.lean
261
261
/- Copyright (c) 2024 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.Cardinal.Arithmetic import Mathlib.SetTheory.Ordinal.Principal /-! # Ordinal arithmetic with cardinals This file collects results about the cardinality of different ordinal operations. -/ universe u v open Cardinal Ordinal Set /-! ### Cardinal operations with ordinal indices -/ namespace Cardinal /-- Bounds the cardinal of an ordinal-indexed union of sets. -/ lemma mk_iUnion_Ordinal_lift_le_of_le {β : Type v} {o : Ordinal.{u}} {c : Cardinal.{v}} (ho : lift.{v} o.card ≤ lift.{u} c) (hc : ℵ₀ ≤ c) (A : Ordinal → Set β) (hA : ∀ j < o, #(A j) ≤ c) : #(⋃ j < o, A j) ≤ c := by simp_rw [← mem_Iio, biUnion_eq_iUnion, iUnion, iSup, ← o.enumIsoToType.symm.surjective.range_comp] rw [← lift_le.{u}] apply ((mk_iUnion_le_lift _).trans _).trans_eq (mul_eq_self (aleph0_le_lift.2 hc)) rw [mk_toType] refine mul_le_mul' ho (ciSup_le' ?_) intro i simpa using hA _ (o.enumIsoToType.symm i).2 lemma mk_iUnion_Ordinal_le_of_le {β : Type*} {o : Ordinal} {c : Cardinal} (ho : o.card ≤ c) (hc : ℵ₀ ≤ c) (A : Ordinal → Set β) (hA : ∀ j < o, #(A j) ≤ c) : #(⋃ j < o, A j) ≤ c := by apply mk_iUnion_Ordinal_lift_le_of_le _ hc A hA rwa [Cardinal.lift_le] end Cardinal @[deprecated mk_iUnion_Ordinal_le_of_le (since := "2024-11-02")] alias Ordinal.Cardinal.mk_iUnion_Ordinal_le_of_le := mk_iUnion_Ordinal_le_of_le /-! ### Cardinality of ordinals -/ namespace Ordinal theorem lift_card_iSup_le_sum_card {ι : Type u} [Small.{v} ι] (f : ι → Ordinal.{v}) : Cardinal.lift.{u} (⨆ i, f i).card ≤ Cardinal.sum fun i ↦ (f i).card := by simp_rw [← mk_toType] rw [← mk_sigma, ← Cardinal.lift_id'.{v} #(Σ _, _), ← Cardinal.lift_umax.{v, u}] apply lift_mk_le_lift_mk_of_surjective (f := enumIsoToType _ ∘ (⟨(enumIsoToType _).symm ·.2, (mem_Iio.mp ((enumIsoToType _).symm _).2).trans_le (Ordinal.le_iSup _ _)⟩)) rw [EquivLike.comp_surjective] rintro ⟨x, hx⟩ obtain ⟨i, hi⟩ := Ordinal.lt_iSup_iff.mp hx exact ⟨⟨i, enumIsoToType _ ⟨x, hi⟩⟩, by simp⟩ theorem card_iSup_le_sum_card {ι : Type u} (f : ι → Ordinal.{max u v}) : (⨆ i, f i).card ≤ Cardinal.sum (fun i ↦ (f i).card) := by have := lift_card_iSup_le_sum_card f rwa [Cardinal.lift_id'] at this theorem card_iSup_Iio_le_sum_card {o : Ordinal.{u}} (f : Iio o → Ordinal.{max u v}) : (⨆ a : Iio o, f a).card ≤ Cardinal.sum fun i ↦ (f ((enumIsoToType o).symm i)).card := by apply le_of_eq_of_le (congr_arg _ _).symm (card_iSup_le_sum_card _) simpa using (enumIsoToType o).symm.iSup_comp (g := fun x ↦ f x) theorem card_iSup_Iio_le_card_mul_iSup {o : Ordinal.{u}} (f : Iio o → Ordinal.{max u v}) : (⨆ a : Iio o, f a).card ≤ Cardinal.lift.{v} o.card * ⨆ a : Iio o, (f a).card := by apply (card_iSup_Iio_le_sum_card f).trans convert ← sum_le_iSup_lift _ · exact mk_toType o · exact (enumIsoToType o).symm.iSup_comp (g := fun x ↦ (f x).card) theorem card_opow_le_of_omega0_le_left {a : Ordinal} (ha : ω ≤ a) (b : Ordinal) : (a ^ b).card ≤ max a.card b.card := by refine limitRecOn b ?_ ?_ ?_ · simpa using one_lt_omega0.le.trans ha · intro b IH rw [opow_succ, card_mul, card_succ, Cardinal.mul_eq_max_of_aleph0_le_right, max_comm] · apply (max_le_max_left _ IH).trans rw [← max_assoc, max_self] exact max_le_max_left _ le_self_add · rw [ne_eq, card_eq_zero, opow_eq_zero] rintro ⟨rfl, -⟩ cases omega0_pos.not_le ha · rwa [aleph0_le_card] · intro b hb IH rw [(isNormal_opow (one_lt_omega0.trans_le ha)).apply_of_isLimit hb] apply (card_iSup_Iio_le_card_mul_iSup _).trans rw [Cardinal.lift_id, Cardinal.mul_eq_max_of_aleph0_le_right, max_comm] · apply max_le _ (le_max_right _ _) apply ciSup_le' intro c exact (IH c.1 c.2).trans (max_le_max_left _ (card_le_card c.2.le)) · simpa using hb.pos.ne' · refine le_ciSup_of_le ?_ ⟨1, one_lt_omega0.trans_le <| omega0_le_of_isLimit hb⟩ ?_ · exact Cardinal.bddAbove_of_small _ · simpa theorem card_opow_le_of_omega0_le_right (a : Ordinal) {b : Ordinal} (hb : ω ≤ b) : (a ^ b).card ≤ max a.card b.card := by obtain ⟨n, rfl⟩ | ha := eq_nat_or_omega0_le a · apply (card_le_card <| opow_le_opow_left b (nat_lt_omega0 n).le).trans apply (card_opow_le_of_omega0_le_left le_rfl _).trans simp [hb] · exact card_opow_le_of_omega0_le_left ha b theorem card_opow_le (a b : Ordinal) : (a ^ b).card ≤ max ℵ₀ (max a.card b.card) := by obtain ⟨n, rfl⟩ | ha := eq_nat_or_omega0_le a · obtain ⟨m, rfl⟩ | hb := eq_nat_or_omega0_le b · rw [← natCast_opow, card_nat] exact le_max_of_le_left (nat_lt_aleph0 _).le · exact (card_opow_le_of_omega0_le_right _ hb).trans (le_max_right _ _) · exact (card_opow_le_of_omega0_le_left ha _).trans (le_max_right _ _) theorem card_opow_eq_of_omega0_le_left {a b : Ordinal} (ha : ω ≤ a) (hb : 0 < b) : (a ^ b).card = max a.card b.card := by apply (card_opow_le_of_omega0_le_left ha b).antisymm (max_le _ _) <;> apply card_le_card · exact left_le_opow a hb · exact right_le_opow b (one_lt_omega0.trans_le ha) theorem card_opow_eq_of_omega0_le_right {a b : Ordinal} (ha : 1 < a) (hb : ω ≤ b) : (a ^ b).card = max a.card b.card := by apply (card_opow_le_of_omega0_le_right a hb).antisymm (max_le _ _) <;> apply card_le_card · exact left_le_opow a (omega0_pos.trans_le hb) · exact right_le_opow b ha theorem card_omega0_opow {a : Ordinal} (h : a ≠ 0) : card (ω ^ a) = max ℵ₀ a.card := by rw [card_opow_eq_of_omega0_le_left le_rfl h.bot_lt, card_omega0] theorem card_opow_omega0 {a : Ordinal} (h : 1 < a) : card (a ^ ω) = max ℵ₀ a.card := by rw [card_opow_eq_of_omega0_le_right h le_rfl, card_omega0, max_comm] theorem principal_opow_omega (o : Ordinal) : Principal (· ^ ·) (ω_ o) := by obtain rfl | ho := Ordinal.eq_zero_or_pos o · rw [omega_zero] exact principal_opow_omega0 · intro a b ha hb rw [lt_omega_iff_card_lt] at ha hb ⊢ apply (card_opow_le a b).trans_lt (max_lt _ (max_lt ha hb)) rwa [← aleph_zero, aleph_lt_aleph] theorem IsInitial.principal_opow {o : Ordinal} (h : IsInitial o) (ho : ω ≤ o) : Principal (· ^ ·) o := by obtain ⟨a, rfl⟩ := mem_range_omega_iff.2 ⟨ho, h⟩ exact principal_opow_omega a theorem principal_opow_ord {c : Cardinal} (hc : ℵ₀ ≤ c) : Principal (· ^ ·) c.ord := by apply (isInitial_ord c).principal_opow rwa [omega0_le_ord] /-! ### Initial ordinals are principal -/ theorem principal_add_ord {c : Cardinal} (hc : ℵ₀ ≤ c) : Principal (· + ·) c.ord := by intro a b ha hb rw [lt_ord, card_add] at * exact add_lt_of_lt hc ha hb theorem IsInitial.principal_add {o : Ordinal} (h : IsInitial o) (ho : ω ≤ o) : Principal (· + ·) o := by rw [← h.ord_card] apply principal_add_ord rwa [aleph0_le_card] theorem principal_add_omega (o : Ordinal) : Principal (· + ·) (ω_ o) := (isInitial_omega o).principal_add (omega0_le_omega o) theorem principal_mul_ord {c : Cardinal} (hc : ℵ₀ ≤ c) : Principal (· * ·) c.ord := by intro a b ha hb rw [lt_ord, card_mul] at * exact mul_lt_of_lt hc ha hb theorem IsInitial.principal_mul {o : Ordinal} (h : IsInitial o) (ho : ω ≤ o) : Principal (· * ·) o := by rw [← h.ord_card] apply principal_mul_ord rwa [aleph0_le_card] theorem principal_mul_omega (o : Ordinal) : Principal (· * ·) (ω_ o) := (isInitial_omega o).principal_mul (omega0_le_omega o) @[deprecated principal_add_omega (since := "2024-11-08")] theorem _root_.Cardinal.principal_add_aleph (o : Ordinal) : Principal (· + ·) (ℵ_ o).ord := principal_add_ord <| aleph0_le_aleph o end Ordinal
Mathlib/SetTheory/Cardinal/Ordinal.lean
1,152
1,159
/- Copyright (c) 2022 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker -/ import Mathlib.Topology.UniformSpace.UniformConvergenceTopology /-! # Equicontinuity of a family of functions Let `X` be a topological space and `α` a `UniformSpace`. A family of functions `F : ι → X → α` is said to be *equicontinuous at a point `x₀ : X`* when, for any entourage `U` in `α`, there is a neighborhood `V` of `x₀` such that, for all `x ∈ V`, and *for all `i`*, `F i x` is `U`-close to `F i x₀`. In other words, one has `∀ U ∈ 𝓤 α, ∀ᶠ x in 𝓝 x₀, ∀ i, (F i x₀, F i x) ∈ U`. For maps between metric spaces, this corresponds to `∀ ε > 0, ∃ δ > 0, ∀ x, ∀ i, dist x₀ x < δ → dist (F i x₀) (F i x) < ε`. `F` is said to be *equicontinuous* if it is equicontinuous at each point. A closely related concept is that of ***uniform*** *equicontinuity* of a family of functions `F : ι → β → α` between uniform spaces, which means that, for any entourage `U` in `α`, there is an entourage `V` in `β` such that, if `x` and `y` are `V`-close, then *for all `i`*, `F i x` and `F i y` are `U`-close. In other words, one has `∀ U ∈ 𝓤 α, ∀ᶠ xy in 𝓤 β, ∀ i, (F i xy.1, F i xy.2) ∈ U`. For maps between metric spaces, this corresponds to `∀ ε > 0, ∃ δ > 0, ∀ x y, ∀ i, dist x y < δ → dist (F i x₀) (F i x) < ε`. ## Main definitions * `EquicontinuousAt`: equicontinuity of a family of functions at a point * `Equicontinuous`: equicontinuity of a family of functions on the whole domain * `UniformEquicontinuous`: uniform equicontinuity of a family of functions on the whole domain We also introduce relative versions, namely `EquicontinuousWithinAt`, `EquicontinuousOn` and `UniformEquicontinuousOn`, akin to `ContinuousWithinAt`, `ContinuousOn` and `UniformContinuousOn` respectively. ## Main statements * `equicontinuous_iff_continuous`: equicontinuity can be expressed as a simple continuity condition between well-chosen function spaces. This is really useful for building up the theory. * `Equicontinuous.closure`: if a set of functions is equicontinuous, its closure *for the topology of pointwise convergence* is also equicontinuous. ## Notations Throughout this file, we use : - `ι`, `κ` for indexing types - `X`, `Y`, `Z` for topological spaces - `α`, `β`, `γ` for uniform spaces ## Implementation details We choose to express equicontinuity as a properties of indexed families of functions rather than sets of functions for the following reasons: - it is really easy to express equicontinuity of `H : Set (X → α)` using our setup: it is just equicontinuity of the family `(↑) : ↥H → (X → α)`. On the other hand, going the other way around would require working with the range of the family, which is always annoying because it introduces useless existentials. - in most applications, one doesn't work with bare functions but with a more specific hom type `hom`. Equicontinuity of a set `H : Set hom` would then have to be expressed as equicontinuity of `coe_fn '' H`, which is super annoying to work with. This is much simpler with families, because equicontinuity of a family `𝓕 : ι → hom` would simply be expressed as equicontinuity of `coe_fn ∘ 𝓕`, which doesn't introduce any nasty existentials. To simplify statements, we do provide abbreviations `Set.EquicontinuousAt`, `Set.Equicontinuous` and `Set.UniformEquicontinuous` asserting the corresponding fact about the family `(↑) : ↥H → (X → α)` where `H : Set (X → α)`. Note however that these won't work for sets of hom types, and in that case one should go back to the family definition rather than using `Set.image`. ## References * [N. Bourbaki, *General Topology, Chapter X*][bourbaki1966] ## Tags equicontinuity, uniform convergence, ascoli -/ section open UniformSpace Filter Set Uniformity Topology UniformConvergence Function variable {ι κ X X' Y α α' β β' γ : Type*} [tX : TopologicalSpace X] [tY : TopologicalSpace Y] [uα : UniformSpace α] [uβ : UniformSpace β] [uγ : UniformSpace γ] /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous at `x₀ : X`* if, for all entourages `U ∈ 𝓤 α`, there is a neighborhood `V` of `x₀` such that, for all `x ∈ V` and for all `i : ι`, `F i x` is `U`-close to `F i x₀`. -/ def EquicontinuousAt (F : ι → X → α) (x₀ : X) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ x in 𝓝 x₀, ∀ i, (F i x₀, F i x) ∈ U /-- We say that a set `H : Set (X → α)` of functions is equicontinuous at a point if the family `(↑) : ↥H → (X → α)` is equicontinuous at that point. -/ protected abbrev Set.EquicontinuousAt (H : Set <| X → α) (x₀ : X) : Prop := EquicontinuousAt ((↑) : H → X → α) x₀ /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous at `x₀ : X` within `S : Set X`* if, for all entourages `U ∈ 𝓤 α`, there is a neighborhood `V` of `x₀` within `S` such that, for all `x ∈ V` and for all `i : ι`, `F i x` is `U`-close to `F i x₀`. -/ def EquicontinuousWithinAt (F : ι → X → α) (S : Set X) (x₀ : X) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ x in 𝓝[S] x₀, ∀ i, (F i x₀, F i x) ∈ U /-- We say that a set `H : Set (X → α)` of functions is equicontinuous at a point within a subset if the family `(↑) : ↥H → (X → α)` is equicontinuous at that point within that same subset. -/ protected abbrev Set.EquicontinuousWithinAt (H : Set <| X → α) (S : Set X) (x₀ : X) : Prop := EquicontinuousWithinAt ((↑) : H → X → α) S x₀ /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous* on all of `X` if it is equicontinuous at each point of `X`. -/ def Equicontinuous (F : ι → X → α) : Prop := ∀ x₀, EquicontinuousAt F x₀ /-- We say that a set `H : Set (X → α)` of functions is equicontinuous if the family `(↑) : ↥H → (X → α)` is equicontinuous. -/ protected abbrev Set.Equicontinuous (H : Set <| X → α) : Prop := Equicontinuous ((↑) : H → X → α) /-- A family `F : ι → X → α` of functions from a topological space to a uniform space is *equicontinuous on `S : Set X`* if it is equicontinuous *within `S`* at each point of `S`. -/ def EquicontinuousOn (F : ι → X → α) (S : Set X) : Prop := ∀ x₀ ∈ S, EquicontinuousWithinAt F S x₀ /-- We say that a set `H : Set (X → α)` of functions is equicontinuous on a subset if the family `(↑) : ↥H → (X → α)` is equicontinuous on that subset. -/ protected abbrev Set.EquicontinuousOn (H : Set <| X → α) (S : Set X) : Prop := EquicontinuousOn ((↑) : H → X → α) S /-- A family `F : ι → β → α` of functions between uniform spaces is *uniformly equicontinuous* if, for all entourages `U ∈ 𝓤 α`, there is an entourage `V ∈ 𝓤 β` such that, whenever `x` and `y` are `V`-close, we have that, *for all `i : ι`*, `F i x` is `U`-close to `F i y`. -/ def UniformEquicontinuous (F : ι → β → α) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ xy : β × β in 𝓤 β, ∀ i, (F i xy.1, F i xy.2) ∈ U /-- We say that a set `H : Set (X → α)` of functions is uniformly equicontinuous if the family `(↑) : ↥H → (X → α)` is uniformly equicontinuous. -/ protected abbrev Set.UniformEquicontinuous (H : Set <| β → α) : Prop := UniformEquicontinuous ((↑) : H → β → α) /-- A family `F : ι → β → α` of functions between uniform spaces is *uniformly equicontinuous on `S : Set β`* if, for all entourages `U ∈ 𝓤 α`, there is a relative entourage `V ∈ 𝓤 β ⊓ 𝓟 (S ×ˢ S)` such that, whenever `x` and `y` are `V`-close, we have that, *for all `i : ι`*, `F i x` is `U`-close to `F i y`. -/ def UniformEquicontinuousOn (F : ι → β → α) (S : Set β) : Prop := ∀ U ∈ 𝓤 α, ∀ᶠ xy : β × β in 𝓤 β ⊓ 𝓟 (S ×ˢ S), ∀ i, (F i xy.1, F i xy.2) ∈ U /-- We say that a set `H : Set (X → α)` of functions is uniformly equicontinuous on a subset if the family `(↑) : ↥H → (X → α)` is uniformly equicontinuous on that subset. -/ protected abbrev Set.UniformEquicontinuousOn (H : Set <| β → α) (S : Set β) : Prop := UniformEquicontinuousOn ((↑) : H → β → α) S lemma EquicontinuousAt.equicontinuousWithinAt {F : ι → X → α} {x₀ : X} (H : EquicontinuousAt F x₀) (S : Set X) : EquicontinuousWithinAt F S x₀ := fun U hU ↦ (H U hU).filter_mono inf_le_left lemma EquicontinuousWithinAt.mono {F : ι → X → α} {x₀ : X} {S T : Set X} (H : EquicontinuousWithinAt F T x₀) (hST : S ⊆ T) : EquicontinuousWithinAt F S x₀ := fun U hU ↦ (H U hU).filter_mono <| nhdsWithin_mono x₀ hST @[simp] lemma equicontinuousWithinAt_univ (F : ι → X → α) (x₀ : X) : EquicontinuousWithinAt F univ x₀ ↔ EquicontinuousAt F x₀ := by rw [EquicontinuousWithinAt, EquicontinuousAt, nhdsWithin_univ] lemma equicontinuousAt_restrict_iff (F : ι → X → α) {S : Set X} (x₀ : S) : EquicontinuousAt (S.restrict ∘ F) x₀ ↔ EquicontinuousWithinAt F S x₀ := by simp [EquicontinuousWithinAt, EquicontinuousAt, ← eventually_nhds_subtype_iff] lemma Equicontinuous.equicontinuousOn {F : ι → X → α} (H : Equicontinuous F) (S : Set X) : EquicontinuousOn F S := fun x _ ↦ (H x).equicontinuousWithinAt S lemma EquicontinuousOn.mono {F : ι → X → α} {S T : Set X} (H : EquicontinuousOn F T) (hST : S ⊆ T) : EquicontinuousOn F S := fun x hx ↦ (H x (hST hx)).mono hST lemma equicontinuousOn_univ (F : ι → X → α) : EquicontinuousOn F univ ↔ Equicontinuous F := by simp [EquicontinuousOn, Equicontinuous] lemma equicontinuous_restrict_iff (F : ι → X → α) {S : Set X} : Equicontinuous (S.restrict ∘ F) ↔ EquicontinuousOn F S := by simp [Equicontinuous, EquicontinuousOn, equicontinuousAt_restrict_iff] lemma UniformEquicontinuous.uniformEquicontinuousOn {F : ι → β → α} (H : UniformEquicontinuous F) (S : Set β) : UniformEquicontinuousOn F S := fun U hU ↦ (H U hU).filter_mono inf_le_left lemma UniformEquicontinuousOn.mono {F : ι → β → α} {S T : Set β} (H : UniformEquicontinuousOn F T) (hST : S ⊆ T) : UniformEquicontinuousOn F S := fun U hU ↦ (H U hU).filter_mono <| by gcongr lemma uniformEquicontinuousOn_univ (F : ι → β → α) : UniformEquicontinuousOn F univ ↔ UniformEquicontinuous F := by simp [UniformEquicontinuousOn, UniformEquicontinuous] lemma uniformEquicontinuous_restrict_iff (F : ι → β → α) {S : Set β} : UniformEquicontinuous (S.restrict ∘ F) ↔ UniformEquicontinuousOn F S := by rw [UniformEquicontinuous, UniformEquicontinuousOn] conv in _ ⊓ _ => rw [← Subtype.range_val (s := S), ← range_prodMap, ← map_comap] rfl /-! ### Empty index type -/ @[simp] lemma equicontinuousAt_empty [h : IsEmpty ι] (F : ι → X → α) (x₀ : X) : EquicontinuousAt F x₀ := fun _ _ ↦ Eventually.of_forall (fun _ ↦ h.elim) @[simp] lemma equicontinuousWithinAt_empty [h : IsEmpty ι] (F : ι → X → α) (S : Set X) (x₀ : X) : EquicontinuousWithinAt F S x₀ := fun _ _ ↦ Eventually.of_forall (fun _ ↦ h.elim) @[simp] lemma equicontinuous_empty [IsEmpty ι] (F : ι → X → α) : Equicontinuous F := equicontinuousAt_empty F @[simp] lemma equicontinuousOn_empty [IsEmpty ι] (F : ι → X → α) (S : Set X) : EquicontinuousOn F S := fun x₀ _ ↦ equicontinuousWithinAt_empty F S x₀ @[simp] lemma uniformEquicontinuous_empty [h : IsEmpty ι] (F : ι → β → α) : UniformEquicontinuous F := fun _ _ ↦ Eventually.of_forall (fun _ ↦ h.elim) @[simp] lemma uniformEquicontinuousOn_empty [h : IsEmpty ι] (F : ι → β → α) (S : Set β) : UniformEquicontinuousOn F S := fun _ _ ↦ Eventually.of_forall (fun _ ↦ h.elim) /-! ### Finite index type -/ theorem equicontinuousAt_finite [Finite ι] {F : ι → X → α} {x₀ : X} : EquicontinuousAt F x₀ ↔ ∀ i, ContinuousAt (F i) x₀ := by simp [EquicontinuousAt, ContinuousAt, (nhds_basis_uniformity' (𝓤 α).basis_sets).tendsto_right_iff, UniformSpace.ball, @forall_swap _ ι] theorem equicontinuousWithinAt_finite [Finite ι] {F : ι → X → α} {S : Set X} {x₀ : X} : EquicontinuousWithinAt F S x₀ ↔ ∀ i, ContinuousWithinAt (F i) S x₀ := by simp [EquicontinuousWithinAt, ContinuousWithinAt, (nhds_basis_uniformity' (𝓤 α).basis_sets).tendsto_right_iff, UniformSpace.ball, @forall_swap _ ι] theorem equicontinuous_finite [Finite ι] {F : ι → X → α} : Equicontinuous F ↔ ∀ i, Continuous (F i) := by simp only [Equicontinuous, equicontinuousAt_finite, continuous_iff_continuousAt, @forall_swap ι] theorem equicontinuousOn_finite [Finite ι] {F : ι → X → α} {S : Set X} : EquicontinuousOn F S ↔ ∀ i, ContinuousOn (F i) S := by simp only [EquicontinuousOn, equicontinuousWithinAt_finite, ContinuousOn, @forall_swap ι] theorem uniformEquicontinuous_finite [Finite ι] {F : ι → β → α} : UniformEquicontinuous F ↔ ∀ i, UniformContinuous (F i) := by simp only [UniformEquicontinuous, eventually_all, @forall_swap _ ι]; rfl theorem uniformEquicontinuousOn_finite [Finite ι] {F : ι → β → α} {S : Set β} : UniformEquicontinuousOn F S ↔ ∀ i, UniformContinuousOn (F i) S := by simp only [UniformEquicontinuousOn, eventually_all, @forall_swap _ ι]; rfl /-! ### Index type with a unique element -/ theorem equicontinuousAt_unique [Unique ι] {F : ι → X → α} {x : X} : EquicontinuousAt F x ↔ ContinuousAt (F default) x := equicontinuousAt_finite.trans Unique.forall_iff theorem equicontinuousWithinAt_unique [Unique ι] {F : ι → X → α} {S : Set X} {x : X} : EquicontinuousWithinAt F S x ↔ ContinuousWithinAt (F default) S x := equicontinuousWithinAt_finite.trans Unique.forall_iff theorem equicontinuous_unique [Unique ι] {F : ι → X → α} : Equicontinuous F ↔ Continuous (F default) := equicontinuous_finite.trans Unique.forall_iff theorem equicontinuousOn_unique [Unique ι] {F : ι → X → α} {S : Set X} : EquicontinuousOn F S ↔ ContinuousOn (F default) S := equicontinuousOn_finite.trans Unique.forall_iff theorem uniformEquicontinuous_unique [Unique ι] {F : ι → β → α} : UniformEquicontinuous F ↔ UniformContinuous (F default) := uniformEquicontinuous_finite.trans Unique.forall_iff theorem uniformEquicontinuousOn_unique [Unique ι] {F : ι → β → α} {S : Set β} : UniformEquicontinuousOn F S ↔ UniformContinuousOn (F default) S := uniformEquicontinuousOn_finite.trans Unique.forall_iff /-- Reformulation of equicontinuity at `x₀` within a set `S`, comparing two variables near `x₀` instead of comparing only one with `x₀`. -/ theorem equicontinuousWithinAt_iff_pair {F : ι → X → α} {S : Set X} {x₀ : X} (hx₀ : x₀ ∈ S) : EquicontinuousWithinAt F S x₀ ↔ ∀ U ∈ 𝓤 α, ∃ V ∈ 𝓝[S] x₀, ∀ x ∈ V, ∀ y ∈ V, ∀ i, (F i x, F i y) ∈ U := by constructor <;> intro H U hU · rcases comp_symm_mem_uniformity_sets hU with ⟨V, hV, hVsymm, hVU⟩ refine ⟨_, H V hV, fun x hx y hy i => hVU (prodMk_mem_compRel ?_ (hy i))⟩ exact hVsymm.mk_mem_comm.mp (hx i) · rcases H U hU with ⟨V, hV, hVU⟩ filter_upwards [hV] using fun x hx i => hVU x₀ (mem_of_mem_nhdsWithin hx₀ hV) x hx i /-- Reformulation of equicontinuity at `x₀` comparing two variables near `x₀` instead of comparing only one with `x₀`. -/ theorem equicontinuousAt_iff_pair {F : ι → X → α} {x₀ : X} : EquicontinuousAt F x₀ ↔ ∀ U ∈ 𝓤 α, ∃ V ∈ 𝓝 x₀, ∀ x ∈ V, ∀ y ∈ V, ∀ i, (F i x, F i y) ∈ U := by simp_rw [← equicontinuousWithinAt_univ, equicontinuousWithinAt_iff_pair (mem_univ x₀), nhdsWithin_univ] /-- Uniform equicontinuity implies equicontinuity. -/ theorem UniformEquicontinuous.equicontinuous {F : ι → β → α} (h : UniformEquicontinuous F) : Equicontinuous F := fun x₀ U hU ↦ mem_of_superset (ball_mem_nhds x₀ (h U hU)) fun _ hx i ↦ hx i /-- Uniform equicontinuity on a subset implies equicontinuity on that subset. -/ theorem UniformEquicontinuousOn.equicontinuousOn {F : ι → β → α} {S : Set β} (h : UniformEquicontinuousOn F S) : EquicontinuousOn F S := fun _ hx₀ U hU ↦ mem_of_superset (ball_mem_nhdsWithin hx₀ (h U hU)) fun _ hx i ↦ hx i /-- Each function of a family equicontinuous at `x₀` is continuous at `x₀`. -/ theorem EquicontinuousAt.continuousAt {F : ι → X → α} {x₀ : X} (h : EquicontinuousAt F x₀) (i : ι) : ContinuousAt (F i) x₀ := (UniformSpace.hasBasis_nhds _).tendsto_right_iff.2 fun U ⟨hU, _⟩ ↦ (h U hU).mono fun _x hx ↦ hx i /-- Each function of a family equicontinuous at `x₀` within `S` is continuous at `x₀` within `S`. -/ theorem EquicontinuousWithinAt.continuousWithinAt {F : ι → X → α} {S : Set X} {x₀ : X} (h : EquicontinuousWithinAt F S x₀) (i : ι) : ContinuousWithinAt (F i) S x₀ := (UniformSpace.hasBasis_nhds _).tendsto_right_iff.2 fun U ⟨hU, _⟩ ↦ (h U hU).mono fun _x hx ↦ hx i protected theorem Set.EquicontinuousAt.continuousAt_of_mem {H : Set <| X → α} {x₀ : X} (h : H.EquicontinuousAt x₀) {f : X → α} (hf : f ∈ H) : ContinuousAt f x₀ := h.continuousAt ⟨f, hf⟩ protected theorem Set.EquicontinuousWithinAt.continuousWithinAt_of_mem {H : Set <| X → α} {S : Set X} {x₀ : X} (h : H.EquicontinuousWithinAt S x₀) {f : X → α} (hf : f ∈ H) : ContinuousWithinAt f S x₀ := h.continuousWithinAt ⟨f, hf⟩ /-- Each function of an equicontinuous family is continuous. -/ theorem Equicontinuous.continuous {F : ι → X → α} (h : Equicontinuous F) (i : ι) : Continuous (F i) := continuous_iff_continuousAt.mpr fun x => (h x).continuousAt i /-- Each function of a family equicontinuous on `S` is continuous on `S`. -/ theorem EquicontinuousOn.continuousOn {F : ι → X → α} {S : Set X} (h : EquicontinuousOn F S) (i : ι) : ContinuousOn (F i) S := fun x hx ↦ (h x hx).continuousWithinAt i protected theorem Set.Equicontinuous.continuous_of_mem {H : Set <| X → α} (h : H.Equicontinuous) {f : X → α} (hf : f ∈ H) : Continuous f := h.continuous ⟨f, hf⟩ protected theorem Set.EquicontinuousOn.continuousOn_of_mem {H : Set <| X → α} {S : Set X} (h : H.EquicontinuousOn S) {f : X → α} (hf : f ∈ H) : ContinuousOn f S := h.continuousOn ⟨f, hf⟩ /-- Each function of a uniformly equicontinuous family is uniformly continuous. -/ theorem UniformEquicontinuous.uniformContinuous {F : ι → β → α} (h : UniformEquicontinuous F) (i : ι) : UniformContinuous (F i) := fun U hU => mem_map.mpr (mem_of_superset (h U hU) fun _ hxy => hxy i) /-- Each function of a family uniformly equicontinuous on `S` is uniformly continuous on `S`. -/ theorem UniformEquicontinuousOn.uniformContinuousOn {F : ι → β → α} {S : Set β} (h : UniformEquicontinuousOn F S) (i : ι) : UniformContinuousOn (F i) S := fun U hU => mem_map.mpr (mem_of_superset (h U hU) fun _ hxy => hxy i) protected theorem Set.UniformEquicontinuous.uniformContinuous_of_mem {H : Set <| β → α} (h : H.UniformEquicontinuous) {f : β → α} (hf : f ∈ H) : UniformContinuous f := h.uniformContinuous ⟨f, hf⟩ protected theorem Set.UniformEquicontinuousOn.uniformContinuousOn_of_mem {H : Set <| β → α} {S : Set β} (h : H.UniformEquicontinuousOn S) {f : β → α} (hf : f ∈ H) : UniformContinuousOn f S := h.uniformContinuousOn ⟨f, hf⟩ /-- Taking sub-families preserves equicontinuity at a point. -/ theorem EquicontinuousAt.comp {F : ι → X → α} {x₀ : X} (h : EquicontinuousAt F x₀) (u : κ → ι) : EquicontinuousAt (F ∘ u) x₀ := fun U hU => (h U hU).mono fun _ H k => H (u k) /-- Taking sub-families preserves equicontinuity at a point within a subset. -/ theorem EquicontinuousWithinAt.comp {F : ι → X → α} {S : Set X} {x₀ : X} (h : EquicontinuousWithinAt F S x₀) (u : κ → ι) : EquicontinuousWithinAt (F ∘ u) S x₀ := fun U hU ↦ (h U hU).mono fun _ H k => H (u k) protected theorem Set.EquicontinuousAt.mono {H H' : Set <| X → α} {x₀ : X} (h : H.EquicontinuousAt x₀) (hH : H' ⊆ H) : H'.EquicontinuousAt x₀ := h.comp (inclusion hH) protected theorem Set.EquicontinuousWithinAt.mono {H H' : Set <| X → α} {S : Set X} {x₀ : X} (h : H.EquicontinuousWithinAt S x₀) (hH : H' ⊆ H) : H'.EquicontinuousWithinAt S x₀ := h.comp (inclusion hH) /-- Taking sub-families preserves equicontinuity. -/ theorem Equicontinuous.comp {F : ι → X → α} (h : Equicontinuous F) (u : κ → ι) : Equicontinuous (F ∘ u) := fun x => (h x).comp u /-- Taking sub-families preserves equicontinuity on a subset. -/ theorem EquicontinuousOn.comp {F : ι → X → α} {S : Set X} (h : EquicontinuousOn F S) (u : κ → ι) : EquicontinuousOn (F ∘ u) S := fun x hx ↦ (h x hx).comp u protected theorem Set.Equicontinuous.mono {H H' : Set <| X → α} (h : H.Equicontinuous) (hH : H' ⊆ H) : H'.Equicontinuous := h.comp (inclusion hH) protected theorem Set.EquicontinuousOn.mono {H H' : Set <| X → α} {S : Set X} (h : H.EquicontinuousOn S) (hH : H' ⊆ H) : H'.EquicontinuousOn S := h.comp (inclusion hH) /-- Taking sub-families preserves uniform equicontinuity. -/ theorem UniformEquicontinuous.comp {F : ι → β → α} (h : UniformEquicontinuous F) (u : κ → ι) : UniformEquicontinuous (F ∘ u) := fun U hU => (h U hU).mono fun _ H k => H (u k) /-- Taking sub-families preserves uniform equicontinuity on a subset. -/ theorem UniformEquicontinuousOn.comp {F : ι → β → α} {S : Set β} (h : UniformEquicontinuousOn F S) (u : κ → ι) : UniformEquicontinuousOn (F ∘ u) S := fun U hU ↦ (h U hU).mono fun _ H k => H (u k) protected theorem Set.UniformEquicontinuous.mono {H H' : Set <| β → α} (h : H.UniformEquicontinuous) (hH : H' ⊆ H) : H'.UniformEquicontinuous := h.comp (inclusion hH) protected theorem Set.UniformEquicontinuousOn.mono {H H' : Set <| β → α} {S : Set β} (h : H.UniformEquicontinuousOn S) (hH : H' ⊆ H) : H'.UniformEquicontinuousOn S := h.comp (inclusion hH) /-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` iff `range 𝓕` is equicontinuous at `x₀`, i.e the family `(↑) : range F → X → α` is equicontinuous at `x₀`. -/ theorem equicontinuousAt_iff_range {F : ι → X → α} {x₀ : X} : EquicontinuousAt F x₀ ↔ EquicontinuousAt ((↑) : range F → X → α) x₀ := by simp only [EquicontinuousAt, forall_subtype_range_iff] /-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` within `S` iff `range 𝓕` is equicontinuous at `x₀` within `S`, i.e the family `(↑) : range F → X → α` is equicontinuous at `x₀` within `S`. -/ theorem equicontinuousWithinAt_iff_range {F : ι → X → α} {S : Set X} {x₀ : X} : EquicontinuousWithinAt F S x₀ ↔ EquicontinuousWithinAt ((↑) : range F → X → α) S x₀ := by simp only [EquicontinuousWithinAt, forall_subtype_range_iff] /-- A family `𝓕 : ι → X → α` is equicontinuous iff `range 𝓕` is equicontinuous, i.e the family `(↑) : range F → X → α` is equicontinuous. -/ theorem equicontinuous_iff_range {F : ι → X → α} : Equicontinuous F ↔ Equicontinuous ((↑) : range F → X → α) := forall_congr' fun _ => equicontinuousAt_iff_range /-- A family `𝓕 : ι → X → α` is equicontinuous on `S` iff `range 𝓕` is equicontinuous on `S`, i.e the family `(↑) : range F → X → α` is equicontinuous on `S`. -/ theorem equicontinuousOn_iff_range {F : ι → X → α} {S : Set X} : EquicontinuousOn F S ↔ EquicontinuousOn ((↑) : range F → X → α) S := forall_congr' fun _ ↦ forall_congr' fun _ ↦ equicontinuousWithinAt_iff_range /-- A family `𝓕 : ι → β → α` is uniformly equicontinuous iff `range 𝓕` is uniformly equicontinuous, i.e the family `(↑) : range F → β → α` is uniformly equicontinuous. -/ theorem uniformEquicontinuous_iff_range {F : ι → β → α} : UniformEquicontinuous F ↔ UniformEquicontinuous ((↑) : range F → β → α) := ⟨fun h => by rw [← comp_rangeSplitting F]; exact h.comp _, fun h => h.comp (rangeFactorization F)⟩ /-- A family `𝓕 : ι → β → α` is uniformly equicontinuous on `S` iff `range 𝓕` is uniformly equicontinuous on `S`, i.e the family `(↑) : range F → β → α` is uniformly equicontinuous on `S`. -/ theorem uniformEquicontinuousOn_iff_range {F : ι → β → α} {S : Set β} : UniformEquicontinuousOn F S ↔ UniformEquicontinuousOn ((↑) : range F → β → α) S := ⟨fun h => by rw [← comp_rangeSplitting F]; exact h.comp _, fun h => h.comp (rangeFactorization F)⟩ section open UniformFun /-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` iff the function `swap 𝓕 : X → ι → α` is continuous at `x₀` *when `ι → α` is equipped with the topology of uniform convergence*. This is very useful for developing the equicontinuity API, but it should not be used directly for other purposes. -/ theorem equicontinuousAt_iff_continuousAt {F : ι → X → α} {x₀ : X} : EquicontinuousAt F x₀ ↔ ContinuousAt (ofFun ∘ Function.swap F : X → ι →ᵤ α) x₀ := by rw [ContinuousAt, (UniformFun.hasBasis_nhds ι α _).tendsto_right_iff] rfl /-- A family `𝓕 : ι → X → α` is equicontinuous at `x₀` within `S` iff the function `swap 𝓕 : X → ι → α` is continuous at `x₀` within `S` *when `ι → α` is equipped with the topology of uniform convergence*. This is very useful for developing the equicontinuity API, but it should not be used directly for other purposes. -/ theorem equicontinuousWithinAt_iff_continuousWithinAt {F : ι → X → α} {S : Set X} {x₀ : X} : EquicontinuousWithinAt F S x₀ ↔ ContinuousWithinAt (ofFun ∘ Function.swap F : X → ι →ᵤ α) S x₀ := by rw [ContinuousWithinAt, (UniformFun.hasBasis_nhds ι α _).tendsto_right_iff] rfl /-- A family `𝓕 : ι → X → α` is equicontinuous iff the function `swap 𝓕 : X → ι → α` is continuous *when `ι → α` is equipped with the topology of uniform convergence*. This is very useful for developing the equicontinuity API, but it should not be used directly for other purposes. -/ theorem equicontinuous_iff_continuous {F : ι → X → α} : Equicontinuous F ↔ Continuous (ofFun ∘ Function.swap F : X → ι →ᵤ α) := by simp_rw [Equicontinuous, continuous_iff_continuousAt, equicontinuousAt_iff_continuousAt] /-- A family `𝓕 : ι → X → α` is equicontinuous on `S` iff the function `swap 𝓕 : X → ι → α` is continuous on `S` *when `ι → α` is equipped with the topology of uniform convergence*. This is very useful for developing the equicontinuity API, but it should not be used directly for other purposes. -/ theorem equicontinuousOn_iff_continuousOn {F : ι → X → α} {S : Set X} : EquicontinuousOn F S ↔ ContinuousOn (ofFun ∘ Function.swap F : X → ι →ᵤ α) S := by simp_rw [EquicontinuousOn, ContinuousOn, equicontinuousWithinAt_iff_continuousWithinAt] /-- A family `𝓕 : ι → β → α` is uniformly equicontinuous iff the function `swap 𝓕 : β → ι → α` is uniformly continuous *when `ι → α` is equipped with the uniform structure of uniform convergence*. This is very useful for developing the equicontinuity API, but it should not be used directly for other purposes. -/
theorem uniformEquicontinuous_iff_uniformContinuous {F : ι → β → α} : UniformEquicontinuous F ↔ UniformContinuous (ofFun ∘ Function.swap F : β → ι →ᵤ α) := by rw [UniformContinuous, (UniformFun.hasBasis_uniformity ι α).tendsto_right_iff] rfl
Mathlib/Topology/UniformSpace/Equicontinuity.lean
519
523
/- Copyright (c) 2017 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Keeley Hoek -/ import Mathlib.Algebra.NeZero import Mathlib.Data.Int.DivMod import Mathlib.Logic.Embedding.Basic import Mathlib.Logic.Equiv.Set import Mathlib.Tactic.Common import Mathlib.Tactic.Attr.Register /-! # The finite type with `n` elements `Fin n` is the type whose elements are natural numbers smaller than `n`. This file expands on the development in the core library. ## Main definitions ### Induction principles * `finZeroElim` : Elimination principle for the empty set `Fin 0`, generalizes `Fin.elim0`. Further definitions and eliminators can be found in `Init.Data.Fin.Lemmas` ### Embeddings and isomorphisms * `Fin.valEmbedding` : coercion to natural numbers as an `Embedding`; * `Fin.succEmb` : `Fin.succ` as an `Embedding`; * `Fin.castLEEmb h` : `Fin.castLE` as an `Embedding`, embed `Fin n` into `Fin m`, `h : n ≤ m`; * `finCongr` : `Fin.cast` as an `Equiv`, equivalence between `Fin n` and `Fin m` when `n = m`; * `Fin.castAddEmb m` : `Fin.castAdd` as an `Embedding`, embed `Fin n` into `Fin (n+m)`; * `Fin.castSuccEmb` : `Fin.castSucc` as an `Embedding`, embed `Fin n` into `Fin (n+1)`; * `Fin.addNatEmb m i` : `Fin.addNat` as an `Embedding`, add `m` on `i` on the right, generalizes `Fin.succ`; * `Fin.natAddEmb n i` : `Fin.natAdd` as an `Embedding`, adds `n` on `i` on the left; ### Other casts * `Fin.divNat i` : divides `i : Fin (m * n)` by `n`; * `Fin.modNat i` : takes the mod of `i : Fin (m * n)` by `n`; -/ assert_not_exists Monoid Finset open Fin Nat Function attribute [simp] Fin.succ_ne_zero Fin.castSucc_lt_last /-- Elimination principle for the empty set `Fin 0`, dependent version. -/ def finZeroElim {α : Fin 0 → Sort*} (x : Fin 0) : α x := x.elim0 namespace Fin @[simp] theorem mk_eq_one {n a : Nat} {ha : a < n + 2} : (⟨a, ha⟩ : Fin (n + 2)) = 1 ↔ a = 1 := mk.inj_iff @[simp] theorem one_eq_mk {n a : Nat} {ha : a < n + 2} : 1 = (⟨a, ha⟩ : Fin (n + 2)) ↔ a = 1 := by simp [eq_comm] instance {n : ℕ} : CanLift ℕ (Fin n) Fin.val (· < n) where prf k hk := ⟨⟨k, hk⟩, rfl⟩ /-- A dependent variant of `Fin.elim0`. -/ def rec0 {α : Fin 0 → Sort*} (i : Fin 0) : α i := absurd i.2 (Nat.not_lt_zero _) variable {n m : ℕ} --variable {a b : Fin n} -- this *really* breaks stuff theorem val_injective : Function.Injective (@Fin.val n) := @Fin.eq_of_val_eq n /-- If you actually have an element of `Fin n`, then the `n` is always positive -/ lemma size_positive : Fin n → 0 < n := Fin.pos lemma size_positive' [Nonempty (Fin n)] : 0 < n := ‹Nonempty (Fin n)›.elim Fin.pos protected theorem prop (a : Fin n) : a.val < n := a.2 lemma lt_last_iff_ne_last {a : Fin (n + 1)} : a < last n ↔ a ≠ last n := by simp [Fin.lt_iff_le_and_ne, le_last] lemma ne_zero_of_lt {a b : Fin (n + 1)} (hab : a < b) : b ≠ 0 := Fin.ne_of_gt <| Fin.lt_of_le_of_lt a.zero_le hab lemma ne_last_of_lt {a b : Fin (n + 1)} (hab : a < b) : a ≠ last n := Fin.ne_of_lt <| Fin.lt_of_lt_of_le hab b.le_last /-- Equivalence between `Fin n` and `{ i // i < n }`. -/ @[simps apply symm_apply] def equivSubtype : Fin n ≃ { i // i < n } where toFun a := ⟨a.1, a.2⟩ invFun a := ⟨a.1, a.2⟩ left_inv := fun ⟨_, _⟩ => rfl right_inv := fun ⟨_, _⟩ => rfl section coe /-! ### coercions and constructions -/ theorem val_eq_val (a b : Fin n) : (a : ℕ) = b ↔ a = b := Fin.ext_iff.symm theorem ne_iff_vne (a b : Fin n) : a ≠ b ↔ a.1 ≠ b.1 := Fin.ext_iff.not theorem mk_eq_mk {a h a' h'} : @mk n a h = @mk n a' h' ↔ a = a' := Fin.ext_iff -- syntactic tautologies now /-- Assume `k = l`. If two functions defined on `Fin k` and `Fin l` are equal on each element, then they coincide (in the heq sense). -/ protected theorem heq_fun_iff {α : Sort*} {k l : ℕ} (h : k = l) {f : Fin k → α} {g : Fin l → α} : HEq f g ↔ ∀ i : Fin k, f i = g ⟨(i : ℕ), h ▸ i.2⟩ := by subst h simp [funext_iff] /-- Assume `k = l` and `k' = l'`. If two functions `Fin k → Fin k' → α` and `Fin l → Fin l' → α` are equal on each pair, then they coincide (in the heq sense). -/ protected theorem heq_fun₂_iff {α : Sort*} {k l k' l' : ℕ} (h : k = l) (h' : k' = l') {f : Fin k → Fin k' → α} {g : Fin l → Fin l' → α} : HEq f g ↔ ∀ (i : Fin k) (j : Fin k'), f i j = g ⟨(i : ℕ), h ▸ i.2⟩ ⟨(j : ℕ), h' ▸ j.2⟩ := by subst h subst h' simp [funext_iff] /-- Two elements of `Fin k` and `Fin l` are heq iff their values in `ℕ` coincide. This requires `k = l`. For the left implication without this assumption, see `val_eq_val_of_heq`. -/ protected theorem heq_ext_iff {k l : ℕ} (h : k = l) {i : Fin k} {j : Fin l} : HEq i j ↔ (i : ℕ) = (j : ℕ) := by subst h simp [val_eq_val] end coe section Order /-! ### order -/ theorem le_iff_val_le_val {a b : Fin n} : a ≤ b ↔ (a : ℕ) ≤ b := Iff.rfl /-- `a < b` as natural numbers if and only if `a < b` in `Fin n`. -/ @[norm_cast, simp] theorem val_fin_lt {n : ℕ} {a b : Fin n} : (a : ℕ) < (b : ℕ) ↔ a < b := Iff.rfl /-- `a ≤ b` as natural numbers if and only if `a ≤ b` in `Fin n`. -/ @[norm_cast, simp] theorem val_fin_le {n : ℕ} {a b : Fin n} : (a : ℕ) ≤ (b : ℕ) ↔ a ≤ b := Iff.rfl theorem min_val {a : Fin n} : min (a : ℕ) n = a := by simp theorem max_val {a : Fin n} : max (a : ℕ) n = n := by simp /-- The inclusion map `Fin n → ℕ` is an embedding. -/ @[simps -fullyApplied apply] def valEmbedding : Fin n ↪ ℕ := ⟨val, val_injective⟩ @[simp] theorem equivSubtype_symm_trans_valEmbedding : equivSubtype.symm.toEmbedding.trans valEmbedding = Embedding.subtype (· < n) := rfl /-- Use the ordering on `Fin n` for checking recursive definitions. For example, the following definition is not accepted by the termination checker, unless we declare the `WellFoundedRelation` instance: ```lean def factorial {n : ℕ} : Fin n → ℕ | ⟨0, _⟩ := 1 | ⟨i + 1, hi⟩ := (i + 1) * factorial ⟨i, i.lt_succ_self.trans hi⟩ ``` -/ instance {n : ℕ} : WellFoundedRelation (Fin n) := measure (val : Fin n → ℕ) @[deprecated (since := "2025-02-24")] alias val_zero' := val_zero /-- `Fin.mk_zero` in `Lean` only applies in `Fin (n + 1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] theorem mk_zero' (n : ℕ) [NeZero n] : (⟨0, pos_of_neZero n⟩ : Fin n) = 0 := rfl /-- The `Fin.zero_le` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] protected theorem zero_le' [NeZero n] (a : Fin n) : 0 ≤ a := Nat.zero_le a.val @[simp, norm_cast] theorem val_eq_zero_iff [NeZero n] {a : Fin n} : a.val = 0 ↔ a = 0 := by rw [Fin.ext_iff, val_zero] theorem val_ne_zero_iff [NeZero n] {a : Fin n} : a.val ≠ 0 ↔ a ≠ 0 := val_eq_zero_iff.not @[simp, norm_cast] theorem val_pos_iff [NeZero n] {a : Fin n} : 0 < a.val ↔ 0 < a := by rw [← val_fin_lt, val_zero] /-- The `Fin.pos_iff_ne_zero` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ theorem pos_iff_ne_zero' [NeZero n] (a : Fin n) : 0 < a ↔ a ≠ 0 := by rw [← val_pos_iff, Nat.pos_iff_ne_zero, val_ne_zero_iff] @[simp] lemma cast_eq_self (a : Fin n) : a.cast rfl = a := rfl @[simp] theorem cast_eq_zero {k l : ℕ} [NeZero k] [NeZero l] (h : k = l) (x : Fin k) : Fin.cast h x = 0 ↔ x = 0 := by simp [← val_eq_zero_iff] lemma cast_injective {k l : ℕ} (h : k = l) : Injective (Fin.cast h) := fun a b hab ↦ by simpa [← val_eq_val] using hab theorem last_pos' [NeZero n] : 0 < last n := n.pos_of_neZero theorem one_lt_last [NeZero n] : 1 < last (n + 1) := by rw [lt_iff_val_lt_val, val_one, val_last, Nat.lt_add_left_iff_pos, Nat.pos_iff_ne_zero] exact NeZero.ne n end Order /-! ### Coercions to `ℤ` and the `fin_omega` tactic. -/ open Int theorem coe_int_sub_eq_ite {n : Nat} (u v : Fin n) : ((u - v : Fin n) : Int) = if v ≤ u then (u - v : Int) else (u - v : Int) + n := by rw [Fin.sub_def] split · rw [natCast_emod, Int.emod_eq_sub_self_emod, Int.emod_eq_of_lt] <;> omega · rw [natCast_emod, Int.emod_eq_of_lt] <;> omega theorem coe_int_sub_eq_mod {n : Nat} (u v : Fin n) : ((u - v : Fin n) : Int) = ((u : Int) - (v : Int)) % n := by rw [coe_int_sub_eq_ite] split · rw [Int.emod_eq_of_lt] <;> omega · rw [Int.emod_eq_add_self_emod, Int.emod_eq_of_lt] <;> omega theorem coe_int_add_eq_ite {n : Nat} (u v : Fin n) : ((u + v : Fin n) : Int) = if (u + v : ℕ) < n then (u + v : Int) else (u + v : Int) - n := by rw [Fin.add_def] split · rw [natCast_emod, Int.emod_eq_of_lt] <;> omega · rw [natCast_emod, Int.emod_eq_sub_self_emod, Int.emod_eq_of_lt] <;> omega theorem coe_int_add_eq_mod {n : Nat} (u v : Fin n) : ((u + v : Fin n) : Int) = ((u : Int) + (v : Int)) % n := by rw [coe_int_add_eq_ite] split · rw [Int.emod_eq_of_lt] <;> omega · rw [Int.emod_eq_sub_self_emod, Int.emod_eq_of_lt] <;> omega -- Write `a + b` as `if (a + b : ℕ) < n then (a + b : ℤ) else (a + b : ℤ) - n` and -- similarly `a - b` as `if (b : ℕ) ≤ a then (a - b : ℤ) else (a - b : ℤ) + n`. attribute [fin_omega] coe_int_sub_eq_ite coe_int_add_eq_ite -- Rewrite inequalities in `Fin` to inequalities in `ℕ` attribute [fin_omega] Fin.lt_iff_val_lt_val Fin.le_iff_val_le_val -- Rewrite `1 : Fin (n + 2)` to `1 : ℤ` attribute [fin_omega] val_one /-- Preprocessor for `omega` to handle inequalities in `Fin`. Note that this involves a lot of case splitting, so may be slow. -/ -- Further adjustment to the simp set can probably make this more powerful. -- Please experiment and PR updates! macro "fin_omega" : tactic => `(tactic| { try simp only [fin_omega, ← Int.ofNat_lt, ← Int.ofNat_le] at * omega }) section Add /-! ### addition, numerals, and coercion from Nat -/ @[simp] theorem val_one' (n : ℕ) [NeZero n] : ((1 : Fin n) : ℕ) = 1 % n := rfl @[deprecated val_one' (since := "2025-03-10")] theorem val_one'' {n : ℕ} : ((1 : Fin (n + 1)) : ℕ) = 1 % (n + 1) := rfl instance nontrivial {n : ℕ} : Nontrivial (Fin (n + 2)) where exists_pair_ne := ⟨0, 1, (ne_iff_vne 0 1).mpr (by simp [val_one, val_zero])⟩ theorem nontrivial_iff_two_le : Nontrivial (Fin n) ↔ 2 ≤ n := by rcases n with (_ | _ | n) <;> simp [Fin.nontrivial, not_nontrivial, Nat.succ_le_iff] section Monoid instance inhabitedFinOneAdd (n : ℕ) : Inhabited (Fin (1 + n)) := haveI : NeZero (1 + n) := by rw [Nat.add_comm]; infer_instance inferInstance @[simp] theorem default_eq_zero (n : ℕ) [NeZero n] : (default : Fin n) = 0 := rfl instance instNatCast [NeZero n] : NatCast (Fin n) where natCast i := Fin.ofNat' n i lemma natCast_def [NeZero n] (a : ℕ) : (a : Fin n) = ⟨a % n, mod_lt _ n.pos_of_neZero⟩ := rfl end Monoid theorem val_add_eq_ite {n : ℕ} (a b : Fin n) : (↑(a + b) : ℕ) = if n ≤ a + b then a + b - n else a + b := by rw [Fin.val_add, Nat.add_mod_eq_ite, Nat.mod_eq_of_lt (show ↑a < n from a.2), Nat.mod_eq_of_lt (show ↑b < n from b.2)] theorem val_add_eq_of_add_lt {n : ℕ} {a b : Fin n} (huv : a.val + b.val < n) : (a + b).val = a.val + b.val := by rw [val_add] simp [Nat.mod_eq_of_lt huv] lemma intCast_val_sub_eq_sub_add_ite {n : ℕ} (a b : Fin n) : ((a - b).val : ℤ) = a.val - b.val + if b ≤ a then 0 else n := by split <;> fin_omega lemma one_le_of_ne_zero {n : ℕ} [NeZero n] {k : Fin n} (hk : k ≠ 0) : 1 ≤ k := by obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (NeZero.ne n) cases n with | zero => simp only [Nat.reduceAdd, Fin.isValue, Fin.zero_le] | succ n => rwa [Fin.le_iff_val_le_val, Fin.val_one, Nat.one_le_iff_ne_zero, val_ne_zero_iff] lemma val_sub_one_of_ne_zero [NeZero n] {i : Fin n} (hi : i ≠ 0) : (i - 1).val = i - 1 := by obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (NeZero.ne n) rw [Fin.sub_val_of_le (one_le_of_ne_zero hi), Fin.val_one', Nat.mod_eq_of_lt (Nat.succ_le_iff.mpr (nontrivial_iff_two_le.mp <| nontrivial_of_ne i 0 hi))] section OfNatCoe @[simp] theorem ofNat'_eq_cast (n : ℕ) [NeZero n] (a : ℕ) : Fin.ofNat' n a = a := rfl @[simp] lemma val_natCast (a n : ℕ) [NeZero n] : (a : Fin n).val = a % n := rfl /-- Converting an in-range number to `Fin (n + 1)` produces a result whose value is the original number. -/ theorem val_cast_of_lt {n : ℕ} [NeZero n] {a : ℕ} (h : a < n) : (a : Fin n).val = a := Nat.mod_eq_of_lt h /-- If `n` is non-zero, converting the value of a `Fin n` to `Fin n` results in the same value. -/ @[simp, norm_cast] theorem cast_val_eq_self {n : ℕ} [NeZero n] (a : Fin n) : (a.val : Fin n) = a := Fin.ext <| val_cast_of_lt a.isLt -- This is a special case of `CharP.cast_eq_zero` that doesn't require typeclass search @[simp high] lemma natCast_self (n : ℕ) [NeZero n] : (n : Fin n) = 0 := by ext; simp @[simp] lemma natCast_eq_zero {a n : ℕ} [NeZero n] : (a : Fin n) = 0 ↔ n ∣ a := by simp [Fin.ext_iff, Nat.dvd_iff_mod_eq_zero] @[simp] theorem natCast_eq_last (n) : (n : Fin (n + 1)) = Fin.last n := by ext; simp theorem le_val_last (i : Fin (n + 1)) : i ≤ n := by rw [Fin.natCast_eq_last] exact Fin.le_last i variable {a b : ℕ} lemma natCast_le_natCast (han : a ≤ n) (hbn : b ≤ n) : (a : Fin (n + 1)) ≤ b ↔ a ≤ b := by rw [← Nat.lt_succ_iff] at han hbn simp [le_iff_val_le_val, -val_fin_le, Nat.mod_eq_of_lt, han, hbn] lemma natCast_lt_natCast (han : a ≤ n) (hbn : b ≤ n) : (a : Fin (n + 1)) < b ↔ a < b := by rw [← Nat.lt_succ_iff] at han hbn; simp [lt_iff_val_lt_val, Nat.mod_eq_of_lt, han, hbn] lemma natCast_mono (hbn : b ≤ n) (hab : a ≤ b) : (a : Fin (n + 1)) ≤ b := (natCast_le_natCast (hab.trans hbn) hbn).2 hab lemma natCast_strictMono (hbn : b ≤ n) (hab : a < b) : (a : Fin (n + 1)) < b := (natCast_lt_natCast (hab.le.trans hbn) hbn).2 hab end OfNatCoe end Add section Succ /-! ### succ and casts into larger Fin types -/ lemma succ_injective (n : ℕ) : Injective (@Fin.succ n) := fun a b ↦ by simp [Fin.ext_iff] /-- `Fin.succ` as an `Embedding` -/ def succEmb (n : ℕ) : Fin n ↪ Fin (n + 1) where toFun := succ inj' := succ_injective _ @[simp] theorem coe_succEmb : ⇑(succEmb n) = Fin.succ := rfl @[deprecated (since := "2025-04-12")] alias val_succEmb := coe_succEmb @[simp] theorem exists_succ_eq {x : Fin (n + 1)} : (∃ y, Fin.succ y = x) ↔ x ≠ 0 := ⟨fun ⟨_, hy⟩ => hy ▸ succ_ne_zero _, x.cases (fun h => h.irrefl.elim) (fun _ _ => ⟨_, rfl⟩)⟩ theorem exists_succ_eq_of_ne_zero {x : Fin (n + 1)} (h : x ≠ 0) : ∃ y, Fin.succ y = x := exists_succ_eq.mpr h @[simp] theorem succ_zero_eq_one' [NeZero n] : Fin.succ (0 : Fin n) = 1 := by cases n · exact (NeZero.ne 0 rfl).elim · rfl theorem one_pos' [NeZero n] : (0 : Fin (n + 1)) < 1 := succ_zero_eq_one' (n := n) ▸ succ_pos _ theorem zero_ne_one' [NeZero n] : (0 : Fin (n + 1)) ≠ 1 := Fin.ne_of_lt one_pos' /-- The `Fin.succ_one_eq_two` in `Lean` only applies in `Fin (n+2)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] theorem succ_one_eq_two' [NeZero n] : Fin.succ (1 : Fin (n + 1)) = 2 := by cases n · exact (NeZero.ne 0 rfl).elim · rfl -- Version of `succ_one_eq_two` to be used by `dsimp`. -- Note the `'` swapped around due to a move to std4. /-- The `Fin.le_zero_iff` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] theorem le_zero_iff' {n : ℕ} [NeZero n] {k : Fin n} : k ≤ 0 ↔ k = 0 := ⟨fun h => Fin.ext <| by rw [Nat.eq_zero_of_le_zero h]; rfl, by rintro rfl; exact Nat.le_refl _⟩ -- TODO: Move to Batteries @[simp] lemma castLE_inj {hmn : m ≤ n} {a b : Fin m} : castLE hmn a = castLE hmn b ↔ a = b := by simp [Fin.ext_iff] @[simp] lemma castAdd_inj {a b : Fin m} : castAdd n a = castAdd n b ↔ a = b := by simp [Fin.ext_iff] attribute [simp] castSucc_inj lemma castLE_injective (hmn : m ≤ n) : Injective (castLE hmn) := fun _ _ hab ↦ Fin.ext (congr_arg val hab :) lemma castAdd_injective (m n : ℕ) : Injective (@Fin.castAdd m n) := castLE_injective _ lemma castSucc_injective (n : ℕ) : Injective (@Fin.castSucc n) := castAdd_injective _ _ /-- `Fin.castLE` as an `Embedding`, `castLEEmb h i` embeds `i` into a larger `Fin` type. -/ @[simps apply] def castLEEmb (h : n ≤ m) : Fin n ↪ Fin m where toFun := castLE h inj' := castLE_injective _ @[simp, norm_cast] lemma coe_castLEEmb {m n} (hmn : m ≤ n) : castLEEmb hmn = castLE hmn := rfl /- The next proof can be golfed a lot using `Fintype.card`. It is written this way to define `ENat.card` and `Nat.card` without a `Fintype` dependency (not done yet). -/ lemma nonempty_embedding_iff : Nonempty (Fin n ↪ Fin m) ↔ n ≤ m := by refine ⟨fun h ↦ ?_, fun h ↦ ⟨castLEEmb h⟩⟩ induction n generalizing m with | zero => exact m.zero_le | succ n ihn => obtain ⟨e⟩ := h rcases exists_eq_succ_of_ne_zero (pos_iff_nonempty.2 (Nonempty.map e inferInstance)).ne' with ⟨m, rfl⟩ refine Nat.succ_le_succ <| ihn ⟨?_⟩ refine ⟨fun i ↦ (e.setValue 0 0 i.succ).pred (mt e.setValue_eq_iff.1 i.succ_ne_zero), fun i j h ↦ ?_⟩ simpa only [pred_inj, EmbeddingLike.apply_eq_iff_eq, succ_inj] using h lemma equiv_iff_eq : Nonempty (Fin m ≃ Fin n) ↔ m = n := ⟨fun ⟨e⟩ ↦ le_antisymm (nonempty_embedding_iff.1 ⟨e⟩) (nonempty_embedding_iff.1 ⟨e.symm⟩), fun h ↦ h ▸ ⟨.refl _⟩⟩ @[simp] lemma castLE_castSucc {n m} (i : Fin n) (h : n + 1 ≤ m) : i.castSucc.castLE h = i.castLE (Nat.le_of_succ_le h) := rfl @[simp] lemma castLE_comp_castSucc {n m} (h : n + 1 ≤ m) : Fin.castLE h ∘ Fin.castSucc = Fin.castLE (Nat.le_of_succ_le h) := rfl @[simp] lemma castLE_rfl (n : ℕ) : Fin.castLE (le_refl n) = id := rfl @[simp] theorem range_castLE {n k : ℕ} (h : n ≤ k) : Set.range (castLE h) = { i : Fin k | (i : ℕ) < n } := Set.ext fun x => ⟨fun ⟨y, hy⟩ => hy ▸ y.2, fun hx => ⟨⟨x, hx⟩, rfl⟩⟩ @[simp] theorem coe_of_injective_castLE_symm {n k : ℕ} (h : n ≤ k) (i : Fin k) (hi) : ((Equiv.ofInjective _ (castLE_injective h)).symm ⟨i, hi⟩ : ℕ) = i := by rw [← coe_castLE h] exact congr_arg Fin.val (Equiv.apply_ofInjective_symm _ _) theorem leftInverse_cast (eq : n = m) : LeftInverse (Fin.cast eq.symm) (Fin.cast eq) := fun _ => rfl theorem rightInverse_cast (eq : n = m) : RightInverse (Fin.cast eq.symm) (Fin.cast eq) := fun _ => rfl @[simp] theorem cast_inj (eq : n = m) {a b : Fin n} : a.cast eq = b.cast eq ↔ a = b := by simp [← val_inj] @[simp] theorem cast_lt_cast (eq : n = m) {a b : Fin n} : a.cast eq < b.cast eq ↔ a < b := Iff.rfl @[simp] theorem cast_le_cast (eq : n = m) {a b : Fin n} : a.cast eq ≤ b.cast eq ↔ a ≤ b := Iff.rfl /-- The 'identity' equivalence between `Fin m` and `Fin n` when `m = n`. -/ @[simps] def _root_.finCongr (eq : n = m) : Fin n ≃ Fin m where toFun := Fin.cast eq invFun := Fin.cast eq.symm left_inv := leftInverse_cast eq right_inv := rightInverse_cast eq @[simp] lemma _root_.finCongr_apply_mk (h : m = n) (k : ℕ) (hk : k < m) : finCongr h ⟨k, hk⟩ = ⟨k, h ▸ hk⟩ := rfl @[simp] lemma _root_.finCongr_refl (h : n = n := rfl) : finCongr h = Equiv.refl (Fin n) := by ext; simp @[simp] lemma _root_.finCongr_symm (h : m = n) : (finCongr h).symm = finCongr h.symm := rfl @[simp] lemma _root_.finCongr_apply_coe (h : m = n) (k : Fin m) : (finCongr h k : ℕ) = k := rfl lemma _root_.finCongr_symm_apply_coe (h : m = n) (k : Fin n) : ((finCongr h).symm k : ℕ) = k := rfl /-- While in many cases `finCongr` is better than `Equiv.cast`/`cast`, sometimes we want to apply a generic theorem about `cast`. -/ lemma _root_.finCongr_eq_equivCast (h : n = m) : finCongr h = .cast (h ▸ rfl) := by subst h; simp /-- While in many cases `Fin.cast` is better than `Equiv.cast`/`cast`, sometimes we want to apply a generic theorem about `cast`. -/ theorem cast_eq_cast (h : n = m) : (Fin.cast h : Fin n → Fin m) = _root_.cast (h ▸ rfl) := by subst h ext rfl /-- `Fin.castAdd` as an `Embedding`, `castAddEmb m i` embeds `i : Fin n` in `Fin (n+m)`. See also `Fin.natAddEmb` and `Fin.addNatEmb`. -/ def castAddEmb (m) : Fin n ↪ Fin (n + m) := castLEEmb (le_add_right n m) @[simp] lemma coe_castAddEmb (m) : (castAddEmb m : Fin n → Fin (n + m)) = castAdd m := rfl lemma castAddEmb_apply (m) (i : Fin n) : castAddEmb m i = castAdd m i := rfl /-- `Fin.castSucc` as an `Embedding`, `castSuccEmb i` embeds `i : Fin n` in `Fin (n+1)`. -/ def castSuccEmb : Fin n ↪ Fin (n + 1) := castAddEmb _ @[simp, norm_cast] lemma coe_castSuccEmb : (castSuccEmb : Fin n → Fin (n + 1)) = Fin.castSucc := rfl lemma castSuccEmb_apply (i : Fin n) : castSuccEmb i = i.castSucc := rfl theorem castSucc_le_succ {n} (i : Fin n) : i.castSucc ≤ i.succ := Nat.le_succ i @[simp] theorem castSucc_le_castSucc_iff {a b : Fin n} : castSucc a ≤ castSucc b ↔ a ≤ b := .rfl @[simp] theorem succ_le_castSucc_iff {a b : Fin n} : succ a ≤ castSucc b ↔ a < b := by rw [le_castSucc_iff, succ_lt_succ_iff] @[simp] theorem castSucc_lt_succ_iff {a b : Fin n} : castSucc a < succ b ↔ a ≤ b := by rw [castSucc_lt_iff_succ_le, succ_le_succ_iff] theorem le_of_castSucc_lt_of_succ_lt {a b : Fin (n + 1)} {i : Fin n} (hl : castSucc i < a) (hu : b < succ i) : b < a := by simp [Fin.lt_def, -val_fin_lt] at *; omega theorem castSucc_lt_or_lt_succ (p : Fin (n + 1)) (i : Fin n) : castSucc i < p ∨ p < i.succ := by simp [Fin.lt_def, -val_fin_lt]; omega theorem succ_le_or_le_castSucc (p : Fin (n + 1)) (i : Fin n) : succ i ≤ p ∨ p ≤ i.castSucc := by rw [le_castSucc_iff, ← castSucc_lt_iff_succ_le] exact p.castSucc_lt_or_lt_succ i theorem eq_castSucc_of_ne_last {x : Fin (n + 1)} (h : x ≠ (last _)) : ∃ y, Fin.castSucc y = x := exists_castSucc_eq.mpr h @[deprecated (since := "2025-02-06")] alias exists_castSucc_eq_of_ne_last := eq_castSucc_of_ne_last theorem forall_fin_succ' {P : Fin (n + 1) → Prop} : (∀ i, P i) ↔ (∀ i : Fin n, P i.castSucc) ∧ P (.last _) := ⟨fun H => ⟨fun _ => H _, H _⟩, fun ⟨H0, H1⟩ i => Fin.lastCases H1 H0 i⟩ -- to match `Fin.eq_zero_or_eq_succ` theorem eq_castSucc_or_eq_last {n : Nat} (i : Fin (n + 1)) : (∃ j : Fin n, i = j.castSucc) ∨ i = last n := i.lastCases (Or.inr rfl) (Or.inl ⟨·, rfl⟩) @[simp] theorem castSucc_ne_last {n : ℕ} (i : Fin n) : i.castSucc ≠ .last n := Fin.ne_of_lt i.castSucc_lt_last theorem exists_fin_succ' {P : Fin (n + 1) → Prop} : (∃ i, P i) ↔ (∃ i : Fin n, P i.castSucc) ∨ P (.last _) := ⟨fun ⟨i, h⟩ => Fin.lastCases Or.inr (fun i hi => Or.inl ⟨i, hi⟩) i h, fun h => h.elim (fun ⟨i, hi⟩ => ⟨i.castSucc, hi⟩) (fun h => ⟨.last _, h⟩)⟩ /-- The `Fin.castSucc_zero` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] theorem castSucc_zero' [NeZero n] : castSucc (0 : Fin n) = 0 := rfl @[simp] theorem castSucc_pos_iff [NeZero n] {i : Fin n} : 0 < castSucc i ↔ 0 < i := by simp [← val_pos_iff] /-- `castSucc i` is positive when `i` is positive. The `Fin.castSucc_pos` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ alias ⟨_, castSucc_pos'⟩ := castSucc_pos_iff /-- The `Fin.castSucc_eq_zero_iff` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] theorem castSucc_eq_zero_iff' [NeZero n] (a : Fin n) : castSucc a = 0 ↔ a = 0 := Fin.ext_iff.trans <| (Fin.ext_iff.trans <| by simp).symm /-- The `Fin.castSucc_ne_zero_iff` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ theorem castSucc_ne_zero_iff' [NeZero n] (a : Fin n) : castSucc a ≠ 0 ↔ a ≠ 0 := not_iff_not.mpr <| castSucc_eq_zero_iff' a theorem castSucc_ne_zero_of_lt {p i : Fin n} (h : p < i) : castSucc i ≠ 0 := by cases n · exact i.elim0 · rw [castSucc_ne_zero_iff', Ne, Fin.ext_iff] exact ((zero_le _).trans_lt h).ne' theorem succ_ne_last_iff (a : Fin (n + 1)) : succ a ≠ last (n + 1) ↔ a ≠ last n := not_iff_not.mpr <| succ_eq_last_succ theorem succ_ne_last_of_lt {p i : Fin n} (h : i < p) : succ i ≠ last n := by cases n · exact i.elim0 · rw [succ_ne_last_iff, Ne, Fin.ext_iff] exact ((le_last _).trans_lt' h).ne @[norm_cast, simp] theorem coe_eq_castSucc {a : Fin n} : (a : Fin (n + 1)) = castSucc a := by ext exact val_cast_of_lt (Nat.lt.step a.is_lt) theorem coe_succ_lt_iff_lt {n : ℕ} {j k : Fin n} : (j : Fin <| n + 1) < k ↔ j < k := by simp only [coe_eq_castSucc, castSucc_lt_castSucc_iff] @[simp] theorem range_castSucc {n : ℕ} : Set.range (castSucc : Fin n → Fin n.succ) = ({ i | (i : ℕ) < n } : Set (Fin n.succ)) := range_castLE (by omega) @[simp] theorem coe_of_injective_castSucc_symm {n : ℕ} (i : Fin n.succ) (hi) : ((Equiv.ofInjective castSucc (castSucc_injective _)).symm ⟨i, hi⟩ : ℕ) = i := by rw [← coe_castSucc] exact congr_arg val (Equiv.apply_ofInjective_symm _ _) /-- `Fin.addNat` as an `Embedding`, `addNatEmb m i` adds `m` to `i`, generalizes `Fin.succ`. -/ @[simps! apply] def addNatEmb (m) : Fin n ↪ Fin (n + m) where toFun := (addNat · m) inj' a b := by simp [Fin.ext_iff] /-- `Fin.natAdd` as an `Embedding`, `natAddEmb n i` adds `n` to `i` "on the left". -/ @[simps! apply] def natAddEmb (n) {m} : Fin m ↪ Fin (n + m) where toFun := natAdd n inj' a b := by simp [Fin.ext_iff] theorem castSucc_castAdd (i : Fin n) : castSucc (castAdd m i) = castAdd (m + 1) i := rfl theorem castSucc_natAdd (i : Fin m) : castSucc (natAdd n i) = natAdd n (castSucc i) := rfl theorem succ_castAdd (i : Fin n) : succ (castAdd m i) = if h : i.succ = last _ then natAdd n (0 : Fin (m + 1)) else castAdd (m + 1) ⟨i.1 + 1, lt_of_le_of_ne i.2 (Fin.val_ne_iff.mpr h)⟩ := by split_ifs with h exacts [Fin.ext (congr_arg Fin.val h :), rfl] theorem succ_natAdd (i : Fin m) : succ (natAdd n i) = natAdd n (succ i) := rfl end Succ section Pred /-! ### pred -/ theorem pred_one' [NeZero n] (h := (zero_ne_one' (n := n)).symm) : Fin.pred (1 : Fin (n + 1)) h = 0 := by simp_rw [Fin.ext_iff, coe_pred, val_one', val_zero, Nat.sub_eq_zero_iff_le, Nat.mod_le] theorem pred_last (h := Fin.ext_iff.not.2 last_pos'.ne') : pred (last (n + 1)) h = last n := by simp_rw [← succ_last, pred_succ] theorem pred_lt_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : pred i hi < j ↔ i < succ j := by rw [← succ_lt_succ_iff, succ_pred] theorem lt_pred_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : j < pred i hi ↔ succ j < i := by rw [← succ_lt_succ_iff, succ_pred] theorem pred_le_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : pred i hi ≤ j ↔ i ≤ succ j := by rw [← succ_le_succ_iff, succ_pred] theorem le_pred_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : j ≤ pred i hi ↔ succ j ≤ i := by rw [← succ_le_succ_iff, succ_pred] theorem castSucc_pred_eq_pred_castSucc {a : Fin (n + 1)} (ha : a ≠ 0) (ha' := castSucc_ne_zero_iff.mpr ha) : (a.pred ha).castSucc = (castSucc a).pred ha' := rfl theorem castSucc_pred_add_one_eq {a : Fin (n + 1)} (ha : a ≠ 0) : (a.pred ha).castSucc + 1 = a := by cases a using cases · exact (ha rfl).elim · rw [pred_succ, coeSucc_eq_succ] theorem le_pred_castSucc_iff {a b : Fin (n + 1)} (ha : castSucc a ≠ 0) : b ≤ (castSucc a).pred ha ↔ b < a := by rw [le_pred_iff, succ_le_castSucc_iff] theorem pred_castSucc_lt_iff {a b : Fin (n + 1)} (ha : castSucc a ≠ 0) : (castSucc a).pred ha < b ↔ a ≤ b := by rw [pred_lt_iff, castSucc_lt_succ_iff] theorem pred_castSucc_lt {a : Fin (n + 1)} (ha : castSucc a ≠ 0) : (castSucc a).pred ha < a := by rw [pred_castSucc_lt_iff, le_def] theorem le_castSucc_pred_iff {a b : Fin (n + 1)} (ha : a ≠ 0) : b ≤ castSucc (a.pred ha) ↔ b < a := by rw [castSucc_pred_eq_pred_castSucc, le_pred_castSucc_iff] theorem castSucc_pred_lt_iff {a b : Fin (n + 1)} (ha : a ≠ 0) : castSucc (a.pred ha) < b ↔ a ≤ b := by rw [castSucc_pred_eq_pred_castSucc, pred_castSucc_lt_iff] theorem castSucc_pred_lt {a : Fin (n + 1)} (ha : a ≠ 0) : castSucc (a.pred ha) < a := by rw [castSucc_pred_lt_iff, le_def] end Pred section CastPred /-- `castPred i` sends `i : Fin (n + 1)` to `Fin n` as long as i ≠ last n. -/ @[inline] def castPred (i : Fin (n + 1)) (h : i ≠ last n) : Fin n := castLT i (val_lt_last h) @[simp] lemma castLT_eq_castPred (i : Fin (n + 1)) (h : i < last _) (h' := Fin.ext_iff.not.2 h.ne) : castLT i h = castPred i h' := rfl @[simp] lemma coe_castPred (i : Fin (n + 1)) (h : i ≠ last _) : (castPred i h : ℕ) = i := rfl @[simp] theorem castPred_castSucc {i : Fin n} (h' := Fin.ext_iff.not.2 (castSucc_lt_last i).ne) : castPred (castSucc i) h' = i := rfl @[simp] theorem castSucc_castPred (i : Fin (n + 1)) (h : i ≠ last n) : castSucc (i.castPred h) = i := by rcases exists_castSucc_eq.mpr h with ⟨y, rfl⟩ rw [castPred_castSucc] theorem castPred_eq_iff_eq_castSucc (i : Fin (n + 1)) (hi : i ≠ last _) (j : Fin n) : castPred i hi = j ↔ i = castSucc j := ⟨fun h => by rw [← h, castSucc_castPred], fun h => by simp_rw [h, castPred_castSucc]⟩ @[simp] theorem castPred_mk (i : ℕ) (h₁ : i < n) (h₂ := h₁.trans (Nat.lt_succ_self _)) (h₃ : ⟨i, h₂⟩ ≠ last _ := (ne_iff_vne _ _).mpr (val_last _ ▸ h₁.ne)) : castPred ⟨i, h₂⟩ h₃ = ⟨i, h₁⟩ := rfl @[simp] theorem castPred_le_castPred_iff {i j : Fin (n + 1)} {hi : i ≠ last n} {hj : j ≠ last n} : castPred i hi ≤ castPred j hj ↔ i ≤ j := Iff.rfl /-- A version of the right-to-left implication of `castPred_le_castPred_iff` that deduces `i ≠ last n` from `i ≤ j` and `j ≠ last n`. -/ @[gcongr] theorem castPred_le_castPred {i j : Fin (n + 1)} (h : i ≤ j) (hj : j ≠ last n) : castPred i (by rw [← lt_last_iff_ne_last] at hj ⊢; exact Fin.lt_of_le_of_lt h hj) ≤ castPred j hj := h @[simp] theorem castPred_lt_castPred_iff {i j : Fin (n + 1)} {hi : i ≠ last n} {hj : j ≠ last n} : castPred i hi < castPred j hj ↔ i < j := Iff.rfl /-- A version of the right-to-left implication of `castPred_lt_castPred_iff` that deduces `i ≠ last n` from `i < j`. -/ @[gcongr] theorem castPred_lt_castPred {i j : Fin (n + 1)} (h : i < j) (hj : j ≠ last n) : castPred i (ne_last_of_lt h) < castPred j hj := h theorem castPred_lt_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) : castPred i hi < j ↔ i < castSucc j := by rw [← castSucc_lt_castSucc_iff, castSucc_castPred] theorem lt_castPred_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) : j < castPred i hi ↔ castSucc j < i := by rw [← castSucc_lt_castSucc_iff, castSucc_castPred] theorem castPred_le_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) : castPred i hi ≤ j ↔ i ≤ castSucc j := by rw [← castSucc_le_castSucc_iff, castSucc_castPred] theorem le_castPred_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) : j ≤ castPred i hi ↔ castSucc j ≤ i := by rw [← castSucc_le_castSucc_iff, castSucc_castPred] @[simp] theorem castPred_inj {i j : Fin (n + 1)} {hi : i ≠ last n} {hj : j ≠ last n} : castPred i hi = castPred j hj ↔ i = j := by simp_rw [Fin.ext_iff, le_antisymm_iff, ← le_def, castPred_le_castPred_iff] theorem castPred_zero' [NeZero n] (h := Fin.ext_iff.not.2 last_pos'.ne) : castPred (0 : Fin (n + 1)) h = 0 := rfl theorem castPred_zero (h := Fin.ext_iff.not.2 last_pos.ne) : castPred (0 : Fin (n + 2)) h = 0 := rfl @[simp] theorem castPred_eq_zero [NeZero n] {i : Fin (n + 1)} (h : i ≠ last n) : Fin.castPred i h = 0 ↔ i = 0 := by rw [← castPred_zero', castPred_inj] @[simp] theorem castPred_one [NeZero n] (h := Fin.ext_iff.not.2 one_lt_last.ne) : castPred (1 : Fin (n + 2)) h = 1 := by cases n · exact subsingleton_one.elim _ 1 · rfl theorem succ_castPred_eq_castPred_succ {a : Fin (n + 1)} (ha : a ≠ last n) (ha' := a.succ_ne_last_iff.mpr ha) : (a.castPred ha).succ = (succ a).castPred ha' := rfl theorem succ_castPred_eq_add_one {a : Fin (n + 1)} (ha : a ≠ last n) : (a.castPred ha).succ = a + 1 := by cases a using lastCases · exact (ha rfl).elim · rw [castPred_castSucc, coeSucc_eq_succ] theorem castpred_succ_le_iff {a b : Fin (n + 1)} (ha : succ a ≠ last (n + 1)) : (succ a).castPred ha ≤ b ↔ a < b := by rw [castPred_le_iff, succ_le_castSucc_iff] theorem lt_castPred_succ_iff {a b : Fin (n + 1)} (ha : succ a ≠ last (n + 1)) : b < (succ a).castPred ha ↔ b ≤ a := by rw [lt_castPred_iff, castSucc_lt_succ_iff] theorem lt_castPred_succ {a : Fin (n + 1)} (ha : succ a ≠ last (n + 1)) : a < (succ a).castPred ha := by rw [lt_castPred_succ_iff, le_def] theorem succ_castPred_le_iff {a b : Fin (n + 1)} (ha : a ≠ last n) : succ (a.castPred ha) ≤ b ↔ a < b := by rw [succ_castPred_eq_castPred_succ ha, castpred_succ_le_iff] theorem lt_succ_castPred_iff {a b : Fin (n + 1)} (ha : a ≠ last n) : b < succ (a.castPred ha) ↔ b ≤ a := by rw [succ_castPred_eq_castPred_succ ha, lt_castPred_succ_iff] theorem lt_succ_castPred {a : Fin (n + 1)} (ha : a ≠ last n) : a < succ (a.castPred ha) := by rw [lt_succ_castPred_iff, le_def] theorem castPred_le_pred_iff {a b : Fin (n + 1)} (ha : a ≠ last n) (hb : b ≠ 0) : castPred a ha ≤ pred b hb ↔ a < b := by rw [le_pred_iff, succ_castPred_le_iff] theorem pred_lt_castPred_iff {a b : Fin (n + 1)} (ha : a ≠ 0) (hb : b ≠ last n) : pred a ha < castPred b hb ↔ a ≤ b := by rw [lt_castPred_iff, castSucc_pred_lt_iff ha] theorem pred_lt_castPred {a : Fin (n + 1)} (h₁ : a ≠ 0) (h₂ : a ≠ last n) : pred a h₁ < castPred a h₂ := by rw [pred_lt_castPred_iff, le_def] end CastPred section SuccAbove variable {p : Fin (n + 1)} {i j : Fin n} /-- `succAbove p i` embeds `Fin n` into `Fin (n + 1)` with a hole around `p`. -/ def succAbove (p : Fin (n + 1)) (i : Fin n) : Fin (n + 1) := if castSucc i < p then i.castSucc else i.succ /-- Embedding `i : Fin n` into `Fin (n + 1)` with a hole around `p : Fin (n + 1)` embeds `i` by `castSucc` when the resulting `i.castSucc < p`. -/ lemma succAbove_of_castSucc_lt (p : Fin (n + 1)) (i : Fin n) (h : castSucc i < p) : p.succAbove i = castSucc i := if_pos h lemma succAbove_of_succ_le (p : Fin (n + 1)) (i : Fin n) (h : succ i ≤ p) : p.succAbove i = castSucc i := succAbove_of_castSucc_lt _ _ (castSucc_lt_iff_succ_le.mpr h) /-- Embedding `i : Fin n` into `Fin (n + 1)` with a hole around `p : Fin (n + 1)` embeds `i` by `succ` when the resulting `p < i.succ`. -/ lemma succAbove_of_le_castSucc (p : Fin (n + 1)) (i : Fin n) (h : p ≤ castSucc i) : p.succAbove i = i.succ := if_neg (Fin.not_lt.2 h) lemma succAbove_of_lt_succ (p : Fin (n + 1)) (i : Fin n) (h : p < succ i) : p.succAbove i = succ i := succAbove_of_le_castSucc _ _ (le_castSucc_iff.mpr h) lemma succAbove_succ_of_lt (p i : Fin n) (h : p < i) : succAbove p.succ i = i.succ := succAbove_of_lt_succ _ _ (succ_lt_succ_iff.mpr h) lemma succAbove_succ_of_le (p i : Fin n) (h : i ≤ p) : succAbove p.succ i = i.castSucc := succAbove_of_succ_le _ _ (succ_le_succ_iff.mpr h) @[simp] lemma succAbove_succ_self (j : Fin n) : j.succ.succAbove j = j.castSucc := succAbove_succ_of_le _ _ Fin.le_rfl lemma succAbove_castSucc_of_lt (p i : Fin n) (h : i < p) : succAbove p.castSucc i = i.castSucc := succAbove_of_castSucc_lt _ _ (castSucc_lt_castSucc_iff.2 h) lemma succAbove_castSucc_of_le (p i : Fin n) (h : p ≤ i) : succAbove p.castSucc i = i.succ := succAbove_of_le_castSucc _ _ (castSucc_le_castSucc_iff.2 h) @[simp] lemma succAbove_castSucc_self (j : Fin n) : succAbove j.castSucc j = j.succ := succAbove_castSucc_of_le _ _ Fin.le_rfl lemma succAbove_pred_of_lt (p i : Fin (n + 1)) (h : p < i) (hi := Fin.ne_of_gt <| Fin.lt_of_le_of_lt p.zero_le h) : succAbove p (i.pred hi) = i := by rw [succAbove_of_lt_succ _ _ (succ_pred _ _ ▸ h), succ_pred] lemma succAbove_pred_of_le (p i : Fin (n + 1)) (h : i ≤ p) (hi : i ≠ 0) : succAbove p (i.pred hi) = (i.pred hi).castSucc := succAbove_of_succ_le _ _ (succ_pred _ _ ▸ h) @[simp] lemma succAbove_pred_self (p : Fin (n + 1)) (h : p ≠ 0) : succAbove p (p.pred h) = (p.pred h).castSucc := succAbove_pred_of_le _ _ Fin.le_rfl h lemma succAbove_castPred_of_lt (p i : Fin (n + 1)) (h : i < p) (hi := Fin.ne_of_lt <| Nat.lt_of_lt_of_le h p.le_last) : succAbove p (i.castPred hi) = i := by rw [succAbove_of_castSucc_lt _ _ (castSucc_castPred _ _ ▸ h), castSucc_castPred] lemma succAbove_castPred_of_le (p i : Fin (n + 1)) (h : p ≤ i) (hi : i ≠ last n) : succAbove p (i.castPred hi) = (i.castPred hi).succ := succAbove_of_le_castSucc _ _ (castSucc_castPred _ _ ▸ h) lemma succAbove_castPred_self (p : Fin (n + 1)) (h : p ≠ last n) : succAbove p (p.castPred h) = (p.castPred h).succ := succAbove_castPred_of_le _ _ Fin.le_rfl h /-- Embedding `i : Fin n` into `Fin (n + 1)` with a hole around `p : Fin (n + 1)` never results in `p` itself -/ @[simp] lemma succAbove_ne (p : Fin (n + 1)) (i : Fin n) : p.succAbove i ≠ p := by rcases p.castSucc_lt_or_lt_succ i with (h | h) · rw [succAbove_of_castSucc_lt _ _ h] exact Fin.ne_of_lt h · rw [succAbove_of_lt_succ _ _ h] exact Fin.ne_of_gt h @[simp] lemma ne_succAbove (p : Fin (n + 1)) (i : Fin n) : p ≠ p.succAbove i := (succAbove_ne _ _).symm /-- Given a fixed pivot `p : Fin (n + 1)`, `p.succAbove` is injective. -/ lemma succAbove_right_injective : Injective p.succAbove := by rintro i j hij unfold succAbove at hij split_ifs at hij with hi hj hj · exact castSucc_injective _ hij · rw [hij] at hi cases hj <| Nat.lt_trans j.castSucc_lt_succ hi · rw [← hij] at hj cases hi <| Nat.lt_trans i.castSucc_lt_succ hj · exact succ_injective _ hij /-- Given a fixed pivot `p : Fin (n + 1)`, `p.succAbove` is injective. -/ lemma succAbove_right_inj : p.succAbove i = p.succAbove j ↔ i = j := succAbove_right_injective.eq_iff /-- `Fin.succAbove p` as an `Embedding`. -/ @[simps!] def succAboveEmb (p : Fin (n + 1)) : Fin n ↪ Fin (n + 1) := ⟨p.succAbove, succAbove_right_injective⟩ @[simp, norm_cast] lemma coe_succAboveEmb (p : Fin (n + 1)) : p.succAboveEmb = p.succAbove := rfl @[simp] lemma succAbove_ne_zero_zero [NeZero n] {a : Fin (n + 1)} (ha : a ≠ 0) : a.succAbove 0 = 0 := by rw [Fin.succAbove_of_castSucc_lt] · exact castSucc_zero' · exact Fin.pos_iff_ne_zero.2 ha lemma succAbove_eq_zero_iff [NeZero n] {a : Fin (n + 1)} {b : Fin n} (ha : a ≠ 0) : a.succAbove b = 0 ↔ b = 0 := by rw [← succAbove_ne_zero_zero ha, succAbove_right_inj] lemma succAbove_ne_zero [NeZero n] {a : Fin (n + 1)} {b : Fin n} (ha : a ≠ 0) (hb : b ≠ 0) : a.succAbove b ≠ 0 := mt (succAbove_eq_zero_iff ha).mp hb /-- Embedding `Fin n` into `Fin (n + 1)` with a hole around zero embeds by `succ`. -/ @[simp] lemma succAbove_zero : succAbove (0 : Fin (n + 1)) = Fin.succ := rfl lemma succAbove_zero_apply (i : Fin n) : succAbove 0 i = succ i := by rw [succAbove_zero] @[simp] lemma succAbove_ne_last_last {a : Fin (n + 2)} (h : a ≠ last (n + 1)) : a.succAbove (last n) = last (n + 1) := by rw [succAbove_of_lt_succ _ _ (succ_last _ ▸ lt_last_iff_ne_last.2 h), succ_last] lemma succAbove_eq_last_iff {a : Fin (n + 2)} {b : Fin (n + 1)} (ha : a ≠ last _) : a.succAbove b = last _ ↔ b = last _ := by rw [← succAbove_ne_last_last ha, succAbove_right_inj] lemma succAbove_ne_last {a : Fin (n + 2)} {b : Fin (n + 1)} (ha : a ≠ last _) (hb : b ≠ last _) : a.succAbove b ≠ last _ := mt (succAbove_eq_last_iff ha).mp hb /-- Embedding `Fin n` into `Fin (n + 1)` with a hole around `last n` embeds by `castSucc`. -/ @[simp] lemma succAbove_last : succAbove (last n) = castSucc := by ext; simp only [succAbove_of_castSucc_lt, castSucc_lt_last] lemma succAbove_last_apply (i : Fin n) : succAbove (last n) i = castSucc i := by rw [succAbove_last] /-- Embedding `i : Fin n` into `Fin (n + 1)` using a pivot `p` that is greater results in a value that is less than `p`. -/ lemma succAbove_lt_iff_castSucc_lt (p : Fin (n + 1)) (i : Fin n) : p.succAbove i < p ↔ castSucc i < p := by rcases castSucc_lt_or_lt_succ p i with H | H · rwa [iff_true_right H, succAbove_of_castSucc_lt _ _ H] · rw [castSucc_lt_iff_succ_le, iff_false_right (Fin.not_le.2 H), succAbove_of_lt_succ _ _ H] exact Fin.not_lt.2 <| Fin.le_of_lt H lemma succAbove_lt_iff_succ_le (p : Fin (n + 1)) (i : Fin n) : p.succAbove i < p ↔ succ i ≤ p := by rw [succAbove_lt_iff_castSucc_lt, castSucc_lt_iff_succ_le] /-- Embedding `i : Fin n` into `Fin (n + 1)` using a pivot `p` that is lesser results in a value that is greater than `p`. -/ lemma lt_succAbove_iff_le_castSucc (p : Fin (n + 1)) (i : Fin n) : p < p.succAbove i ↔ p ≤ castSucc i := by rcases castSucc_lt_or_lt_succ p i with H | H · rw [iff_false_right (Fin.not_le.2 H), succAbove_of_castSucc_lt _ _ H] exact Fin.not_lt.2 <| Fin.le_of_lt H · rwa [succAbove_of_lt_succ _ _ H, iff_true_left H, le_castSucc_iff] lemma lt_succAbove_iff_lt_castSucc (p : Fin (n + 1)) (i : Fin n) : p < p.succAbove i ↔ p < succ i := by rw [lt_succAbove_iff_le_castSucc, le_castSucc_iff] /-- Embedding a positive `Fin n` results in a positive `Fin (n + 1)` -/ lemma succAbove_pos [NeZero n] (p : Fin (n + 1)) (i : Fin n) (h : 0 < i) : 0 < p.succAbove i := by by_cases H : castSucc i < p · simpa [succAbove_of_castSucc_lt _ _ H] using castSucc_pos' h · simp [succAbove_of_le_castSucc _ _ (Fin.not_lt.1 H)] lemma castPred_succAbove (x : Fin n) (y : Fin (n + 1)) (h : castSucc x < y) (h' := Fin.ne_last_of_lt <| (succAbove_lt_iff_castSucc_lt ..).2 h) : (y.succAbove x).castPred h' = x := by rw [castPred_eq_iff_eq_castSucc, succAbove_of_castSucc_lt _ _ h] lemma pred_succAbove (x : Fin n) (y : Fin (n + 1)) (h : y ≤ castSucc x) (h' := Fin.ne_zero_of_lt <| (lt_succAbove_iff_le_castSucc ..).2 h) : (y.succAbove x).pred h' = x := by simp only [succAbove_of_le_castSucc _ _ h, pred_succ] lemma exists_succAbove_eq {x y : Fin (n + 1)} (h : x ≠ y) : ∃ z, y.succAbove z = x := by obtain hxy | hyx := Fin.lt_or_lt_of_ne h exacts [⟨_, succAbove_castPred_of_lt _ _ hxy⟩, ⟨_, succAbove_pred_of_lt _ _ hyx⟩] @[simp] lemma exists_succAbove_eq_iff {x y : Fin (n + 1)} : (∃ z, x.succAbove z = y) ↔ y ≠ x := ⟨by rintro ⟨y, rfl⟩; exact succAbove_ne _ _, exists_succAbove_eq⟩ /-- The range of `p.succAbove` is everything except `p`. -/ @[simp] lemma range_succAbove (p : Fin (n + 1)) : Set.range p.succAbove = {p}ᶜ := Set.ext fun _ => exists_succAbove_eq_iff @[simp] lemma range_succ (n : ℕ) : Set.range (Fin.succ : Fin n → Fin (n + 1)) = {0}ᶜ := by rw [← succAbove_zero]; exact range_succAbove (0 : Fin (n + 1)) /-- `succAbove` is injective at the pivot -/ lemma succAbove_left_injective : Injective (@succAbove n) := fun _ _ h => by simpa [range_succAbove] using congr_arg (fun f : Fin n → Fin (n + 1) => (Set.range f)ᶜ) h /-- `succAbove` is injective at the pivot -/ @[simp] lemma succAbove_left_inj {x y : Fin (n + 1)} : x.succAbove = y.succAbove ↔ x = y := succAbove_left_injective.eq_iff @[simp] lemma zero_succAbove {n : ℕ} (i : Fin n) : (0 : Fin (n + 1)).succAbove i = i.succ := rfl lemma succ_succAbove_zero {n : ℕ} [NeZero n] (i : Fin n) : succAbove i.succ 0 = 0 := by simp /-- `succ` commutes with `succAbove`. -/ @[simp] lemma succ_succAbove_succ {n : ℕ} (i : Fin (n + 1)) (j : Fin n) : i.succ.succAbove j.succ = (i.succAbove j).succ := by obtain h | h := i.lt_or_le (succ j) · rw [succAbove_of_lt_succ _ _ h, succAbove_succ_of_lt _ _ h] · rwa [succAbove_of_castSucc_lt _ _ h, succAbove_succ_of_le, succ_castSucc] /-- `castSucc` commutes with `succAbove`. -/ @[simp] lemma castSucc_succAbove_castSucc {n : ℕ} {i : Fin (n + 1)} {j : Fin n} : i.castSucc.succAbove j.castSucc = (i.succAbove j).castSucc := by rcases i.le_or_lt (castSucc j) with (h | h) · rw [succAbove_of_le_castSucc _ _ h, succAbove_castSucc_of_le _ _ h, succ_castSucc] · rw [succAbove_of_castSucc_lt _ _ h, succAbove_castSucc_of_lt _ _ h] /-- `pred` commutes with `succAbove`. -/ lemma pred_succAbove_pred {a : Fin (n + 2)} {b : Fin (n + 1)} (ha : a ≠ 0) (hb : b ≠ 0) (hk := succAbove_ne_zero ha hb) : (a.pred ha).succAbove (b.pred hb) = (a.succAbove b).pred hk := by simp_rw [← succ_inj (b := pred (succAbove a b) hk), ← succ_succAbove_succ, succ_pred] /-- `castPred` commutes with `succAbove`. -/ lemma castPred_succAbove_castPred {a : Fin (n + 2)} {b : Fin (n + 1)} (ha : a ≠ last (n + 1)) (hb : b ≠ last n) (hk := succAbove_ne_last ha hb) : (a.castPred ha).succAbove (b.castPred hb) = (a.succAbove b).castPred hk := by simp_rw [← castSucc_inj (b := (a.succAbove b).castPred hk), ← castSucc_succAbove_castSucc, castSucc_castPred] lemma one_succAbove_zero {n : ℕ} : (1 : Fin (n + 2)).succAbove 0 = 0 := by rfl /-- By moving `succ` to the outside of this expression, we create opportunities for further simplification using `succAbove_zero` or `succ_succAbove_zero`. -/ @[simp] lemma succ_succAbove_one {n : ℕ} [NeZero n] (i : Fin (n + 1)) : i.succ.succAbove 1 = (i.succAbove 0).succ := by rw [← succ_zero_eq_one']; convert succ_succAbove_succ i 0 @[simp] lemma one_succAbove_succ {n : ℕ} (j : Fin n) : (1 : Fin (n + 2)).succAbove j.succ = j.succ.succ := by have := succ_succAbove_succ 0 j; rwa [succ_zero_eq_one, zero_succAbove] at this @[simp] lemma one_succAbove_one {n : ℕ} : (1 : Fin (n + 3)).succAbove 1 = 2 := by simpa only [succ_zero_eq_one, val_zero, zero_succAbove, succ_one_eq_two] using succ_succAbove_succ (0 : Fin (n + 2)) (0 : Fin (n + 2)) end SuccAbove section PredAbove /-- `predAbove p i` surjects `i : Fin (n+1)` into `Fin n` by subtracting one if `p < i`. -/ def predAbove (p : Fin n) (i : Fin (n + 1)) : Fin n := if h : castSucc p < i then pred i (Fin.ne_zero_of_lt h) else castPred i (Fin.ne_of_lt <| Fin.lt_of_le_of_lt (Fin.not_lt.1 h) (castSucc_lt_last _)) lemma predAbove_of_le_castSucc (p : Fin n) (i : Fin (n + 1)) (h : i ≤ castSucc p) (hi := Fin.ne_of_lt <| Fin.lt_of_le_of_lt h <| castSucc_lt_last _) : p.predAbove i = i.castPred hi := dif_neg <| Fin.not_lt.2 h lemma predAbove_of_lt_succ (p : Fin n) (i : Fin (n + 1)) (h : i < succ p) (hi := Fin.ne_last_of_lt h) : p.predAbove i = i.castPred hi := predAbove_of_le_castSucc _ _ (le_castSucc_iff.mpr h) lemma predAbove_of_castSucc_lt (p : Fin n) (i : Fin (n + 1)) (h : castSucc p < i) (hi := Fin.ne_zero_of_lt h) : p.predAbove i = i.pred hi := dif_pos h lemma predAbove_of_succ_le (p : Fin n) (i : Fin (n + 1)) (h : succ p ≤ i) (hi := Fin.ne_of_gt <| Fin.lt_of_lt_of_le (succ_pos _) h) : p.predAbove i = i.pred hi := predAbove_of_castSucc_lt _ _ (castSucc_lt_iff_succ_le.mpr h) lemma predAbove_succ_of_lt (p i : Fin n) (h : i < p) (hi := succ_ne_last_of_lt h) : p.predAbove (succ i) = (i.succ).castPred hi := by rw [predAbove_of_lt_succ _ _ (succ_lt_succ_iff.mpr h)] lemma predAbove_succ_of_le (p i : Fin n) (h : p ≤ i) : p.predAbove (succ i) = i := by rw [predAbove_of_succ_le _ _ (succ_le_succ_iff.mpr h), pred_succ] @[simp] lemma predAbove_succ_self (p : Fin n) : p.predAbove (succ p) = p := predAbove_succ_of_le _ _ Fin.le_rfl lemma predAbove_castSucc_of_lt (p i : Fin n) (h : p < i) (hi := castSucc_ne_zero_of_lt h) : p.predAbove (castSucc i) = i.castSucc.pred hi := by rw [predAbove_of_castSucc_lt _ _ (castSucc_lt_castSucc_iff.2 h)] lemma predAbove_castSucc_of_le (p i : Fin n) (h : i ≤ p) : p.predAbove (castSucc i) = i := by rw [predAbove_of_le_castSucc _ _ (castSucc_le_castSucc_iff.mpr h), castPred_castSucc] @[simp] lemma predAbove_castSucc_self (p : Fin n) : p.predAbove (castSucc p) = p := predAbove_castSucc_of_le _ _ Fin.le_rfl lemma predAbove_pred_of_lt (p i : Fin (n + 1)) (h : i < p) (hp := Fin.ne_zero_of_lt h) (hi := Fin.ne_last_of_lt h) : (pred p hp).predAbove i = castPred i hi := by rw [predAbove_of_lt_succ _ _ (succ_pred _ _ ▸ h)] lemma predAbove_pred_of_le (p i : Fin (n + 1)) (h : p ≤ i) (hp : p ≠ 0) (hi := Fin.ne_of_gt <| Fin.lt_of_lt_of_le (Fin.pos_iff_ne_zero.2 hp) h) : (pred p hp).predAbove i = pred i hi := by rw [predAbove_of_succ_le _ _ (succ_pred _ _ ▸ h)] lemma predAbove_pred_self (p : Fin (n + 1)) (hp : p ≠ 0) : (pred p hp).predAbove p = pred p hp := predAbove_pred_of_le _ _ Fin.le_rfl hp lemma predAbove_castPred_of_lt (p i : Fin (n + 1)) (h : p < i) (hp := Fin.ne_last_of_lt h) (hi := Fin.ne_zero_of_lt h) : (castPred p hp).predAbove i = pred i hi := by rw [predAbove_of_castSucc_lt _ _ (castSucc_castPred _ _ ▸ h)] lemma predAbove_castPred_of_le (p i : Fin (n + 1)) (h : i ≤ p) (hp : p ≠ last n) (hi := Fin.ne_of_lt <| Fin.lt_of_le_of_lt h <| Fin.lt_last_iff_ne_last.2 hp) : (castPred p hp).predAbove i = castPred i hi := by rw [predAbove_of_le_castSucc _ _ (castSucc_castPred _ _ ▸ h)] lemma predAbove_castPred_self (p : Fin (n + 1)) (hp : p ≠ last n) : (castPred p hp).predAbove p = castPred p hp := predAbove_castPred_of_le _ _ Fin.le_rfl hp @[simp] lemma predAbove_right_zero [NeZero n] {i : Fin n} : predAbove (i : Fin n) 0 = 0 := by cases n · exact i.elim0 · rw [predAbove_of_le_castSucc _ _ (zero_le _), castPred_zero] lemma predAbove_zero_succ [NeZero n] {i : Fin n} : predAbove 0 i.succ = i := by rw [predAbove_succ_of_le _ _ (Fin.zero_le' _)] @[simp] lemma succ_predAbove_zero [NeZero n] {j : Fin (n + 1)} (h : j ≠ 0) : succ (predAbove 0 j) = j := by rcases exists_succ_eq_of_ne_zero h with ⟨k, rfl⟩ rw [predAbove_zero_succ] @[simp] lemma predAbove_zero_of_ne_zero [NeZero n] {i : Fin (n + 1)} (hi : i ≠ 0) : predAbove 0 i = i.pred hi := by obtain ⟨y, rfl⟩ := exists_succ_eq.2 hi; exact predAbove_zero_succ lemma predAbove_zero [NeZero n] {i : Fin (n + 1)} : predAbove (0 : Fin n) i = if hi : i = 0 then 0 else i.pred hi := by split_ifs with hi · rw [hi, predAbove_right_zero] · rw [predAbove_zero_of_ne_zero hi] @[simp] lemma predAbove_right_last {i : Fin (n + 1)} : predAbove i (last (n + 1)) = last n := by rw [predAbove_of_castSucc_lt _ _ (castSucc_lt_last _), pred_last] lemma predAbove_last_castSucc {i : Fin (n + 1)} : predAbove (last n) (i.castSucc) = i := by rw [predAbove_of_le_castSucc _ _ (castSucc_le_castSucc_iff.mpr (le_last _)), castPred_castSucc] @[simp] lemma predAbove_last_of_ne_last {i : Fin (n + 2)} (hi : i ≠ last (n + 1)) : predAbove (last n) i = castPred i hi := by rw [← exists_castSucc_eq] at hi rcases hi with ⟨y, rfl⟩ exact predAbove_last_castSucc lemma predAbove_last_apply {i : Fin (n + 2)} : predAbove (last n) i = if hi : i = last _ then last _ else i.castPred hi := by split_ifs with hi · rw [hi, predAbove_right_last] · rw [predAbove_last_of_ne_last hi] /-- Sending `Fin (n+1)` to `Fin n` by subtracting one from anything above `p` then back to `Fin (n+1)` with a gap around `p` is the identity away from `p`. -/ @[simp] lemma succAbove_predAbove {p : Fin n} {i : Fin (n + 1)} (h : i ≠ castSucc p) : p.castSucc.succAbove (p.predAbove i) = i := by obtain h | h := Fin.lt_or_lt_of_ne h · rw [predAbove_of_le_castSucc _ _ (Fin.le_of_lt h), succAbove_castPred_of_lt _ _ h] · rw [predAbove_of_castSucc_lt _ _ h, succAbove_pred_of_lt _ _ h] /-- Sending `Fin (n+1)` to `Fin n` by subtracting one from anything above `p` then back to `Fin (n+1)` with a gap around `p.succ` is the identity away from `p.succ`. -/ @[simp] lemma succ_succAbove_predAbove {n : ℕ} {p : Fin n} {i : Fin (n + 1)} (h : i ≠ p.succ) : p.succ.succAbove (p.predAbove i) = i := by obtain h | h := Fin.lt_or_lt_of_ne h · rw [predAbove_of_le_castSucc _ _ (le_castSucc_iff.2 h), succAbove_castPred_of_lt _ _ h] · rw [predAbove_of_castSucc_lt _ _ (Fin.lt_of_le_of_lt (p.castSucc_le_succ) h), succAbove_pred_of_lt _ _ h] /-- Sending `Fin n` into `Fin (n + 1)` with a gap at `p` then back to `Fin n` by subtracting one from anything above `p` is the identity. -/ @[simp] lemma predAbove_succAbove (p : Fin n) (i : Fin n) : p.predAbove ((castSucc p).succAbove i) = i := by obtain h | h := p.le_or_lt i · rw [succAbove_castSucc_of_le _ _ h, predAbove_succ_of_le _ _ h] · rw [succAbove_castSucc_of_lt _ _ h, predAbove_castSucc_of_le _ _ <| Fin.le_of_lt h] /-- `succ` commutes with `predAbove`. -/ @[simp] lemma succ_predAbove_succ (a : Fin n) (b : Fin (n + 1)) : a.succ.predAbove b.succ = (a.predAbove b).succ := by obtain h | h := Fin.le_or_lt (succ a) b · rw [predAbove_of_castSucc_lt _ _ h, predAbove_succ_of_le _ _ h, succ_pred] · rw [predAbove_of_lt_succ _ _ h, predAbove_succ_of_lt _ _ h, succ_castPred_eq_castPred_succ] /-- `castSucc` commutes with `predAbove`. -/ @[simp] lemma castSucc_predAbove_castSucc {n : ℕ} (a : Fin n) (b : Fin (n + 1)) : a.castSucc.predAbove b.castSucc = (a.predAbove b).castSucc := by obtain h | h := a.castSucc.lt_or_le b · rw [predAbove_of_castSucc_lt _ _ h, predAbove_castSucc_of_lt _ _ h, castSucc_pred_eq_pred_castSucc] · rw [predAbove_of_le_castSucc _ _ h, predAbove_castSucc_of_le _ _ h, castSucc_castPred] end PredAbove section DivMod /-- Compute `i / n`, where `n` is a `Nat` and inferred the type of `i`. -/ def divNat (i : Fin (m * n)) : Fin m := ⟨i / n, Nat.div_lt_of_lt_mul <| Nat.mul_comm m n ▸ i.prop⟩ @[simp] theorem coe_divNat (i : Fin (m * n)) : (i.divNat : ℕ) = i / n := rfl /-- Compute `i % n`, where `n` is a `Nat` and inferred the type of `i`. -/ def modNat (i : Fin (m * n)) : Fin n := ⟨i % n, Nat.mod_lt _ <| Nat.pos_of_mul_pos_left i.pos⟩ @[simp] theorem coe_modNat (i : Fin (m * n)) : (i.modNat : ℕ) = i % n := rfl theorem modNat_rev (i : Fin (m * n)) : i.rev.modNat = i.modNat.rev := by ext have H₁ : i % n + 1 ≤ n := i.modNat.is_lt have H₂ : i / n < m := i.divNat.is_lt simp only [coe_modNat, val_rev] calc (m * n - (i + 1)) % n = (m * n - ((i / n) * n + i % n + 1)) % n := by rw [Nat.div_add_mod'] _ = ((m - i / n - 1) * n + (n - (i % n + 1))) % n := by rw [Nat.mul_sub_right_distrib, Nat.one_mul, Nat.sub_add_sub_cancel _ H₁, Nat.mul_sub_right_distrib, Nat.sub_sub, Nat.add_assoc] exact Nat.le_mul_of_pos_left _ <| Nat.le_sub_of_add_le' H₂ _ = n - (i % n + 1) := by rw [Nat.mul_comm, Nat.mul_add_mod, Nat.mod_eq_of_lt]; exact i.modNat.rev.is_lt end DivMod section Rec /-! ### recursion and induction principles -/ end Rec open scoped Relator in theorem liftFun_iff_succ {α : Type*} (r : α → α → Prop) [IsTrans α r] {f : Fin (n + 1) → α} : ((· < ·) ⇒ r) f f ↔ ∀ i : Fin n, r (f (castSucc i)) (f i.succ) := by constructor · intro H i exact H i.castSucc_lt_succ · refine fun H i => Fin.induction (fun h ↦ ?_) ?_ · simp [le_def] at h · intro j ihj hij rw [← le_castSucc_iff] at hij obtain hij | hij := (le_def.1 hij).eq_or_lt · obtain rfl := Fin.ext hij exact H _ · exact _root_.trans (ihj hij) (H j) section AddGroup open Nat Int /-- Negation on `Fin n` -/ instance neg (n : ℕ) : Neg (Fin n) := ⟨fun a => ⟨(n - a) % n, Nat.mod_lt _ a.pos⟩⟩ theorem neg_def (a : Fin n) : -a = ⟨(n - a) % n, Nat.mod_lt _ a.pos⟩ := rfl protected theorem coe_neg (a : Fin n) : ((-a : Fin n) : ℕ) = (n - a) % n := rfl theorem eq_zero (n : Fin 1) : n = 0 := Subsingleton.elim _ _ lemma eq_one_of_ne_zero (i : Fin 2) (hi : i ≠ 0) : i = 1 := by fin_omega @[deprecated (since := "2025-04-27")] alias eq_one_of_neq_zero := eq_one_of_ne_zero @[simp] theorem coe_neg_one : ↑(-1 : Fin (n + 1)) = n := by cases n · simp rw [Fin.coe_neg, Fin.val_one, Nat.add_one_sub_one, Nat.mod_eq_of_lt] constructor theorem last_sub (i : Fin (n + 1)) : last n - i = Fin.rev i := Fin.ext <| by rw [coe_sub_iff_le.2 i.le_last, val_last, val_rev, Nat.succ_sub_succ_eq_sub] theorem add_one_le_of_lt {n : ℕ} {a b : Fin (n + 1)} (h : a < b) : a + 1 ≤ b := by cases n <;> fin_omega theorem exists_eq_add_of_le {n : ℕ} {a b : Fin n} (h : a ≤ b) : ∃ k ≤ b, b = a + k := by obtain ⟨k, hk⟩ : ∃ k : ℕ, (b : ℕ) = a + k := Nat.exists_eq_add_of_le h have hkb : k ≤ b := by omega refine ⟨⟨k, hkb.trans_lt b.is_lt⟩, hkb, ?_⟩ simp [Fin.ext_iff, Fin.val_add, ← hk, Nat.mod_eq_of_lt b.is_lt] theorem exists_eq_add_of_lt {n : ℕ} {a b : Fin (n + 1)} (h : a < b) : ∃ k < b, k + 1 ≤ b ∧ b = a + k + 1 := by cases n · omega obtain ⟨k, hk⟩ : ∃ k : ℕ, (b : ℕ) = a + k + 1 := Nat.exists_eq_add_of_lt h have hkb : k < b := by omega refine ⟨⟨k, hkb.trans b.is_lt⟩, hkb, by fin_omega, ?_⟩ simp [Fin.ext_iff, Fin.val_add, ← hk, Nat.mod_eq_of_lt b.is_lt] lemma pos_of_ne_zero {n : ℕ} {a : Fin (n + 1)} (h : a ≠ 0) : 0 < a := Nat.pos_of_ne_zero (val_ne_of_ne h) lemma sub_succ_le_sub_of_le {n : ℕ} {u v : Fin (n + 2)} (h : u < v) : v - (u + 1) < v - u := by fin_omega end AddGroup @[simp] theorem coe_natCast_eq_mod (m n : ℕ) [NeZero m] : ((n : Fin m) : ℕ) = n % m := rfl theorem coe_ofNat_eq_mod (m n : ℕ) [NeZero m] : ((ofNat(n) : Fin m) : ℕ) = ofNat(n) % m := rfl section Mul /-! ### mul -/ protected theorem mul_one' [NeZero n] (k : Fin n) : k * 1 = k := by rcases n with - | n · simp [eq_iff_true_of_subsingleton] cases n · simp [fin_one_eq_zero] simp [Fin.ext_iff, mul_def, mod_eq_of_lt (is_lt k)] protected theorem one_mul' [NeZero n] (k : Fin n) : (1 : Fin n) * k = k := by rw [Fin.mul_comm, Fin.mul_one'] protected theorem mul_zero' [NeZero n] (k : Fin n) : k * 0 = 0 := by simp [Fin.ext_iff, mul_def] protected theorem zero_mul' [NeZero n] (k : Fin n) : (0 : Fin n) * k = 0 := by simp [Fin.ext_iff, mul_def] end Mul end Fin
Mathlib/Data/Fin/Basic.lean
1,887
1,896
/- Copyright (c) 2021 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.Polynomial.BigOperators import Mathlib.Algebra.Polynomial.Derivative import Mathlib.Data.Nat.Choose.Cast import Mathlib.Data.Nat.Choose.Vandermonde import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Positivity /-! # Hasse derivative of polynomials The `k`th Hasse derivative of a polynomial `∑ a_i X^i` is `∑ (i.choose k) a_i X^(i-k)`. It is a variant of the usual derivative, and satisfies `k! * (hasseDeriv k f) = derivative^[k] f`. The main benefit is that is gives an atomic way of talking about expressions such as `(derivative^[k] f).eval r / k!`, that occur in Taylor expansions, for example. ## Main declarations In the following, we write `D k` for the `k`-th Hasse derivative `hasse_deriv k`. * `Polynomial.hasseDeriv`: the `k`-th Hasse derivative of a polynomial * `Polynomial.hasseDeriv_zero`: the `0`th Hasse derivative is the identity * `Polynomial.hasseDeriv_one`: the `1`st Hasse derivative is the usual derivative * `Polynomial.factorial_smul_hasseDeriv`: the identity `k! • (D k f) = derivative^[k] f` * `Polynomial.hasseDeriv_comp`: the identity `(D k).comp (D l) = (k+l).choose k • D (k+l)` * `Polynomial.hasseDeriv_mul`: the "Leibniz rule" `D k (f * g) = ∑ ij ∈ antidiagonal k, D ij.1 f * D ij.2 g` For the identity principle, see `Polynomial.eq_zero_of_hasseDeriv_eq_zero` in `Data/Polynomial/Taylor.lean`. ## Reference https://math.fontein.de/2009/08/12/the-hasse-derivative/ -/ noncomputable section namespace Polynomial open Nat Polynomial open Function variable {R : Type*} [Semiring R] (k : ℕ) (f : R[X]) /-- The `k`th Hasse derivative of a polynomial `∑ a_i X^i` is `∑ (i.choose k) a_i X^(i-k)`. It satisfies `k! * (hasse_deriv k f) = derivative^[k] f`. -/ def hasseDeriv (k : ℕ) : R[X] →ₗ[R] R[X] := lsum fun i => monomial (i - k) ∘ₗ DistribMulAction.toLinearMap R R (i.choose k) theorem hasseDeriv_apply : hasseDeriv k f = f.sum fun i r => monomial (i - k) (↑(i.choose k) * r) := by dsimp [hasseDeriv] congr; ext; congr apply nsmul_eq_mul theorem hasseDeriv_coeff (n : ℕ) : (hasseDeriv k f).coeff n = (n + k).choose k * f.coeff (n + k) := by rw [hasseDeriv_apply, coeff_sum, sum_def, Finset.sum_eq_single (n + k), coeff_monomial] · simp only [if_true, add_tsub_cancel_right, eq_self_iff_true] · intro i _hi hink rw [coeff_monomial] by_cases hik : i < k · simp only [Nat.choose_eq_zero_of_lt hik, ite_self, Nat.cast_zero, zero_mul] · push_neg at hik rw [if_neg] contrapose! hink exact (tsub_eq_iff_eq_add_of_le hik).mp hink · intro h simp only [not_mem_support_iff.mp h, monomial_zero_right, mul_zero, coeff_zero] theorem hasseDeriv_zero' : hasseDeriv 0 f = f := by simp only [hasseDeriv_apply, tsub_zero, Nat.choose_zero_right, Nat.cast_one, one_mul, sum_monomial_eq] @[simp] theorem hasseDeriv_zero : @hasseDeriv R _ 0 = LinearMap.id := LinearMap.ext <| hasseDeriv_zero' theorem hasseDeriv_eq_zero_of_lt_natDegree (p : R[X]) (n : ℕ) (h : p.natDegree < n) : hasseDeriv n p = 0 := by rw [hasseDeriv_apply, sum_def] refine Finset.sum_eq_zero fun x hx => ?_ simp [Nat.choose_eq_zero_of_lt ((le_natDegree_of_mem_supp _ hx).trans_lt h)] theorem hasseDeriv_one' : hasseDeriv 1 f = derivative f := by simp only [hasseDeriv_apply, derivative_apply, ← C_mul_X_pow_eq_monomial, Nat.choose_one_right, (Nat.cast_commute _ _).eq] @[simp] theorem hasseDeriv_one : @hasseDeriv R _ 1 = derivative := LinearMap.ext <| hasseDeriv_one'
@[simp] theorem hasseDeriv_monomial (n : ℕ) (r : R) :
Mathlib/Algebra/Polynomial/HasseDeriv.lean
100
102
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Heather Macbeth -/ import Mathlib.Analysis.InnerProductSpace.TwoDim import Mathlib.Geometry.Euclidean.Angle.Unoriented.Basic /-! # Oriented angles. This file defines oriented angles in real inner product spaces. ## Main definitions * `Orientation.oangle` is the oriented angle between two vectors with respect to an orientation. ## Implementation notes The definitions here use the `Real.angle` type, angles modulo `2 * π`. For some purposes, angles modulo `π` are more convenient, because results are true for such angles with less configuration dependence. Results that are only equalities modulo `π` can be represented modulo `2 * π` as equalities of `(2 : ℤ) • θ`. ## References * Evan Chen, Euclidean Geometry in Mathematical Olympiads. -/ noncomputable section open Module Complex open scoped Real RealInnerProductSpace ComplexConjugate namespace Orientation attribute [local instance] Complex.finrank_real_complex_fact variable {V V' : Type*} variable [NormedAddCommGroup V] [NormedAddCommGroup V'] variable [InnerProductSpace ℝ V] [InnerProductSpace ℝ V'] variable [Fact (finrank ℝ V = 2)] [Fact (finrank ℝ V' = 2)] (o : Orientation ℝ V (Fin 2)) local notation "ω" => o.areaForm /-- The oriented angle from `x` to `y`, modulo `2 * π`. If either vector is 0, this is 0. See `InnerProductGeometry.angle` for the corresponding unoriented angle definition. -/ def oangle (x y : V) : Real.Angle := Complex.arg (o.kahler x y) /-- Oriented angles are continuous when the vectors involved are nonzero. -/ @[fun_prop] theorem continuousAt_oangle {x : V × V} (hx1 : x.1 ≠ 0) (hx2 : x.2 ≠ 0) : ContinuousAt (fun y : V × V => o.oangle y.1 y.2) x := by refine (Complex.continuousAt_arg_coe_angle ?_).comp ?_ · exact o.kahler_ne_zero hx1 hx2 exact ((continuous_ofReal.comp continuous_inner).add ((continuous_ofReal.comp o.areaForm'.continuous₂).mul continuous_const)).continuousAt /-- If the first vector passed to `oangle` is 0, the result is 0. -/ @[simp] theorem oangle_zero_left (x : V) : o.oangle 0 x = 0 := by simp [oangle] /-- If the second vector passed to `oangle` is 0, the result is 0. -/ @[simp] theorem oangle_zero_right (x : V) : o.oangle x 0 = 0 := by simp [oangle] /-- If the two vectors passed to `oangle` are the same, the result is 0. -/ @[simp] theorem oangle_self (x : V) : o.oangle x x = 0 := by rw [oangle, kahler_apply_self, ← ofReal_pow] convert QuotientAddGroup.mk_zero (AddSubgroup.zmultiples (2 * π)) apply arg_ofReal_of_nonneg positivity /-- If the angle between two vectors is nonzero, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : x ≠ 0 := by rintro rfl; simp at h /-- If the angle between two vectors is nonzero, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : y ≠ 0 := by rintro rfl; simp at h /-- If the angle between two vectors is nonzero, the vectors are not equal. -/ theorem ne_of_oangle_ne_zero {x y : V} (h : o.oangle x y ≠ 0) : x ≠ y := by rintro rfl; simp at h /-- If the angle between two vectors is `π`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `π`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `π`, the vectors are not equal. -/ theorem ne_of_oangle_eq_pi {x y : V} (h : o.oangle x y = π) : x ≠ y := o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `π / 2`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `π / 2`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `π / 2`, the vectors are not equal. -/ theorem ne_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : x ≠ y := o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `-π / 2`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `-π / 2`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0) /-- If the angle between two vectors is `-π / 2`, the vectors are not equal. -/ theorem ne_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : x ≠ y := o.ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y ≠ 0) /-- If the sign of the angle between two vectors is nonzero, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : x ≠ 0 := o.left_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 /-- If the sign of the angle between two vectors is nonzero, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : y ≠ 0 := o.right_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 /-- If the sign of the angle between two vectors is nonzero, the vectors are not equal. -/ theorem ne_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign ≠ 0) : x ≠ y := o.ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 /-- If the sign of the angle between two vectors is positive, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x ≠ 0 := o.left_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) /-- If the sign of the angle between two vectors is positive, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : y ≠ 0 := o.right_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) /-- If the sign of the angle between two vectors is positive, the vectors are not equal. -/ theorem ne_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x ≠ y := o.ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) /-- If the sign of the angle between two vectors is negative, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x ≠ 0 := o.left_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) /-- If the sign of the angle between two vectors is negative, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : y ≠ 0 := o.right_ne_zero_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) /-- If the sign of the angle between two vectors is negative, the vectors are not equal. -/ theorem ne_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x ≠ y := o.ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (o.oangle x y).sign ≠ 0) /-- Swapping the two vectors passed to `oangle` negates the angle. -/ theorem oangle_rev (x y : V) : o.oangle y x = -o.oangle x y := by simp only [oangle, o.kahler_swap y x, Complex.arg_conj_coe_angle] /-- Adding the angles between two vectors in each order results in 0. -/ @[simp] theorem oangle_add_oangle_rev (x y : V) : o.oangle x y + o.oangle y x = 0 := by simp [o.oangle_rev y x] /-- Negating the first vector passed to `oangle` adds `π` to the angle. -/ theorem oangle_neg_left {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : o.oangle (-x) y = o.oangle x y + π := by simp only [oangle, map_neg] convert Complex.arg_neg_coe_angle _ exact o.kahler_ne_zero hx hy /-- Negating the second vector passed to `oangle` adds `π` to the angle. -/ theorem oangle_neg_right {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : o.oangle x (-y) = o.oangle x y + π := by simp only [oangle, map_neg] convert Complex.arg_neg_coe_angle _ exact o.kahler_ne_zero hx hy /-- Negating the first vector passed to `oangle` does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_neg_left (x y : V) : (2 : ℤ) • o.oangle (-x) y = (2 : ℤ) • o.oangle x y := by by_cases hx : x = 0 · simp [hx] · by_cases hy : y = 0 · simp [hy] · simp [o.oangle_neg_left hx hy] /-- Negating the second vector passed to `oangle` does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_neg_right (x y : V) : (2 : ℤ) • o.oangle x (-y) = (2 : ℤ) • o.oangle x y := by by_cases hx : x = 0 · simp [hx] · by_cases hy : y = 0 · simp [hy] · simp [o.oangle_neg_right hx hy] /-- Negating both vectors passed to `oangle` does not change the angle. -/ @[simp] theorem oangle_neg_neg (x y : V) : o.oangle (-x) (-y) = o.oangle x y := by simp [oangle] /-- Negating the first vector produces the same angle as negating the second vector. -/ theorem oangle_neg_left_eq_neg_right (x y : V) : o.oangle (-x) y = o.oangle x (-y) := by rw [← neg_neg y, oangle_neg_neg, neg_neg] /-- The angle between the negation of a nonzero vector and that vector is `π`. -/ @[simp] theorem oangle_neg_self_left {x : V} (hx : x ≠ 0) : o.oangle (-x) x = π := by simp [oangle_neg_left, hx] /-- The angle between a nonzero vector and its negation is `π`. -/ @[simp] theorem oangle_neg_self_right {x : V} (hx : x ≠ 0) : o.oangle x (-x) = π := by simp [oangle_neg_right, hx] /-- Twice the angle between the negation of a vector and that vector is 0. -/ theorem two_zsmul_oangle_neg_self_left (x : V) : (2 : ℤ) • o.oangle (-x) x = 0 := by by_cases hx : x = 0 <;> simp [hx] /-- Twice the angle between a vector and its negation is 0. -/ theorem two_zsmul_oangle_neg_self_right (x : V) : (2 : ℤ) • o.oangle x (-x) = 0 := by by_cases hx : x = 0 <;> simp [hx] /-- Adding the angles between two vectors in each order, with the first vector in each angle negated, results in 0. -/ @[simp] theorem oangle_add_oangle_rev_neg_left (x y : V) : o.oangle (-x) y + o.oangle (-y) x = 0 := by rw [oangle_neg_left_eq_neg_right, oangle_rev, neg_add_cancel] /-- Adding the angles between two vectors in each order, with the second vector in each angle negated, results in 0. -/ @[simp] theorem oangle_add_oangle_rev_neg_right (x y : V) : o.oangle x (-y) + o.oangle y (-x) = 0 := by rw [o.oangle_rev (-x), oangle_neg_left_eq_neg_right, add_neg_cancel] /-- Multiplying the first vector passed to `oangle` by a positive real does not change the angle. -/ @[simp] theorem oangle_smul_left_of_pos (x y : V) {r : ℝ} (hr : 0 < r) : o.oangle (r • x) y = o.oangle x y := by simp [oangle, Complex.arg_real_mul _ hr] /-- Multiplying the second vector passed to `oangle` by a positive real does not change the angle. -/ @[simp] theorem oangle_smul_right_of_pos (x y : V) {r : ℝ} (hr : 0 < r) : o.oangle x (r • y) = o.oangle x y := by simp [oangle, Complex.arg_real_mul _ hr] /-- Multiplying the first vector passed to `oangle` by a negative real produces the same angle as negating that vector. -/ @[simp] theorem oangle_smul_left_of_neg (x y : V) {r : ℝ} (hr : r < 0) : o.oangle (r • x) y = o.oangle (-x) y := by rw [← neg_neg r, neg_smul, ← smul_neg, o.oangle_smul_left_of_pos _ _ (neg_pos_of_neg hr)] /-- Multiplying the second vector passed to `oangle` by a negative real produces the same angle as negating that vector. -/ @[simp] theorem oangle_smul_right_of_neg (x y : V) {r : ℝ} (hr : r < 0) : o.oangle x (r • y) = o.oangle x (-y) := by rw [← neg_neg r, neg_smul, ← smul_neg, o.oangle_smul_right_of_pos _ _ (neg_pos_of_neg hr)] /-- The angle between a nonnegative multiple of a vector and that vector is 0. -/ @[simp] theorem oangle_smul_left_self_of_nonneg (x : V) {r : ℝ} (hr : 0 ≤ r) : o.oangle (r • x) x = 0 := by rcases hr.lt_or_eq with (h | h) · simp [h] · simp [h.symm] /-- The angle between a vector and a nonnegative multiple of that vector is 0. -/ @[simp] theorem oangle_smul_right_self_of_nonneg (x : V) {r : ℝ} (hr : 0 ≤ r) : o.oangle x (r • x) = 0 := by rcases hr.lt_or_eq with (h | h) · simp [h] · simp [h.symm] /-- The angle between two nonnegative multiples of the same vector is 0. -/ @[simp] theorem oangle_smul_smul_self_of_nonneg (x : V) {r₁ r₂ : ℝ} (hr₁ : 0 ≤ r₁) (hr₂ : 0 ≤ r₂) : o.oangle (r₁ • x) (r₂ • x) = 0 := by rcases hr₁.lt_or_eq with (h | h) · simp [h, hr₂] · simp [h.symm] /-- Multiplying the first vector passed to `oangle` by a nonzero real does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_smul_left_of_ne_zero (x y : V) {r : ℝ} (hr : r ≠ 0) : (2 : ℤ) • o.oangle (r • x) y = (2 : ℤ) • o.oangle x y := by rcases hr.lt_or_lt with (h | h) <;> simp [h] /-- Multiplying the second vector passed to `oangle` by a nonzero real does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_smul_right_of_ne_zero (x y : V) {r : ℝ} (hr : r ≠ 0) : (2 : ℤ) • o.oangle x (r • y) = (2 : ℤ) • o.oangle x y := by rcases hr.lt_or_lt with (h | h) <;> simp [h] /-- Twice the angle between a multiple of a vector and that vector is 0. -/ @[simp] theorem two_zsmul_oangle_smul_left_self (x : V) {r : ℝ} : (2 : ℤ) • o.oangle (r • x) x = 0 := by rcases lt_or_le r 0 with (h | h) <;> simp [h] /-- Twice the angle between a vector and a multiple of that vector is 0. -/ @[simp] theorem two_zsmul_oangle_smul_right_self (x : V) {r : ℝ} : (2 : ℤ) • o.oangle x (r • x) = 0 := by rcases lt_or_le r 0 with (h | h) <;> simp [h] /-- Twice the angle between two multiples of a vector is 0. -/ @[simp] theorem two_zsmul_oangle_smul_smul_self (x : V) {r₁ r₂ : ℝ} : (2 : ℤ) • o.oangle (r₁ • x) (r₂ • x) = 0 := by by_cases h : r₁ = 0 <;> simp [h] /-- If the spans of two vectors are equal, twice angles with those vectors on the left are equal. -/ theorem two_zsmul_oangle_left_of_span_eq {x y : V} (z : V) (h : (ℝ ∙ x) = ℝ ∙ y) : (2 : ℤ) • o.oangle x z = (2 : ℤ) • o.oangle y z := by rw [Submodule.span_singleton_eq_span_singleton] at h rcases h with ⟨r, rfl⟩ exact (o.two_zsmul_oangle_smul_left_of_ne_zero _ _ (Units.ne_zero _)).symm /-- If the spans of two vectors are equal, twice angles with those vectors on the right are equal. -/ theorem two_zsmul_oangle_right_of_span_eq (x : V) {y z : V} (h : (ℝ ∙ y) = ℝ ∙ z) : (2 : ℤ) • o.oangle x y = (2 : ℤ) • o.oangle x z := by rw [Submodule.span_singleton_eq_span_singleton] at h rcases h with ⟨r, rfl⟩ exact (o.two_zsmul_oangle_smul_right_of_ne_zero _ _ (Units.ne_zero _)).symm /-- If the spans of two pairs of vectors are equal, twice angles between those vectors are equal. -/ theorem two_zsmul_oangle_of_span_eq_of_span_eq {w x y z : V} (hwx : (ℝ ∙ w) = ℝ ∙ x) (hyz : (ℝ ∙ y) = ℝ ∙ z) : (2 : ℤ) • o.oangle w y = (2 : ℤ) • o.oangle x z := by rw [o.two_zsmul_oangle_left_of_span_eq y hwx, o.two_zsmul_oangle_right_of_span_eq x hyz] /-- The oriented angle between two vectors is zero if and only if the angle with the vectors swapped is zero. -/ theorem oangle_eq_zero_iff_oangle_rev_eq_zero {x y : V} : o.oangle x y = 0 ↔ o.oangle y x = 0 := by rw [oangle_rev, neg_eq_zero] /-- The oriented angle between two vectors is zero if and only if they are on the same ray. -/ theorem oangle_eq_zero_iff_sameRay {x y : V} : o.oangle x y = 0 ↔ SameRay ℝ x y := by rw [oangle, kahler_apply_apply, Complex.arg_coe_angle_eq_iff_eq_toReal, Real.Angle.toReal_zero, Complex.arg_eq_zero_iff] simpa using o.nonneg_inner_and_areaForm_eq_zero_iff_sameRay x y /-- The oriented angle between two vectors is `π` if and only if the angle with the vectors swapped is `π`. -/ theorem oangle_eq_pi_iff_oangle_rev_eq_pi {x y : V} : o.oangle x y = π ↔ o.oangle y x = π := by rw [oangle_rev, neg_eq_iff_eq_neg, Real.Angle.neg_coe_pi] /-- The oriented angle between two vectors is `π` if and only they are nonzero and the first is on the same ray as the negation of the second. -/ theorem oangle_eq_pi_iff_sameRay_neg {x y : V} : o.oangle x y = π ↔ x ≠ 0 ∧ y ≠ 0 ∧ SameRay ℝ x (-y) := by rw [← o.oangle_eq_zero_iff_sameRay] constructor · intro h by_cases hx : x = 0; · simp [hx, Real.Angle.pi_ne_zero.symm] at h by_cases hy : y = 0; · simp [hy, Real.Angle.pi_ne_zero.symm] at h refine ⟨hx, hy, ?_⟩ rw [o.oangle_neg_right hx hy, h, Real.Angle.coe_pi_add_coe_pi] · rintro ⟨hx, hy, h⟩ rwa [o.oangle_neg_right hx hy, ← Real.Angle.sub_coe_pi_eq_add_coe_pi, sub_eq_zero] at h /-- The oriented angle between two vectors is zero or `π` if and only if those two vectors are not linearly independent. -/ theorem oangle_eq_zero_or_eq_pi_iff_not_linearIndependent {x y : V} : o.oangle x y = 0 ∨ o.oangle x y = π ↔ ¬LinearIndependent ℝ ![x, y] := by rw [oangle_eq_zero_iff_sameRay, oangle_eq_pi_iff_sameRay_neg, sameRay_or_ne_zero_and_sameRay_neg_iff_not_linearIndependent] /-- The oriented angle between two vectors is zero or `π` if and only if the first vector is zero or the second is a multiple of the first. -/ theorem oangle_eq_zero_or_eq_pi_iff_right_eq_smul {x y : V} : o.oangle x y = 0 ∨ o.oangle x y = π ↔ x = 0 ∨ ∃ r : ℝ, y = r • x := by rw [oangle_eq_zero_iff_sameRay, oangle_eq_pi_iff_sameRay_neg] refine ⟨fun h => ?_, fun h => ?_⟩ · rcases h with (h | ⟨-, -, h⟩) · by_cases hx : x = 0; · simp [hx] obtain ⟨r, -, rfl⟩ := h.exists_nonneg_left hx exact Or.inr ⟨r, rfl⟩ · by_cases hx : x = 0; · simp [hx] obtain ⟨r, -, hy⟩ := h.exists_nonneg_left hx refine Or.inr ⟨-r, ?_⟩ simp [hy] · rcases h with (rfl | ⟨r, rfl⟩); · simp by_cases hx : x = 0; · simp [hx] rcases lt_trichotomy r 0 with (hr | hr | hr) · rw [← neg_smul] exact Or.inr ⟨hx, smul_ne_zero hr.ne hx, SameRay.sameRay_pos_smul_right x (Left.neg_pos_iff.2 hr)⟩ · simp [hr] · exact Or.inl (SameRay.sameRay_pos_smul_right x hr) /-- The oriented angle between two vectors is not zero or `π` if and only if those two vectors are linearly independent. -/ theorem oangle_ne_zero_and_ne_pi_iff_linearIndependent {x y : V} : o.oangle x y ≠ 0 ∧ o.oangle x y ≠ π ↔ LinearIndependent ℝ ![x, y] := by rw [← not_or, ← not_iff_not, Classical.not_not, oangle_eq_zero_or_eq_pi_iff_not_linearIndependent] /-- Two vectors are equal if and only if they have equal norms and zero angle between them. -/ theorem eq_iff_norm_eq_and_oangle_eq_zero (x y : V) : x = y ↔ ‖x‖ = ‖y‖ ∧ o.oangle x y = 0 := by rw [oangle_eq_zero_iff_sameRay] constructor · rintro rfl simp; rfl · rcases eq_or_ne y 0 with (rfl | hy) · simp rintro ⟨h₁, h₂⟩ obtain ⟨r, hr, rfl⟩ := h₂.exists_nonneg_right hy have : ‖y‖ ≠ 0 := by simpa using hy obtain rfl : r = 1 := by apply mul_right_cancel₀ this simpa [norm_smul, abs_of_nonneg hr] using h₁ simp /-- Two vectors with equal norms are equal if and only if they have zero angle between them. -/ theorem eq_iff_oangle_eq_zero_of_norm_eq {x y : V} (h : ‖x‖ = ‖y‖) : x = y ↔ o.oangle x y = 0 := ⟨fun he => ((o.eq_iff_norm_eq_and_oangle_eq_zero x y).1 he).2, fun ha => (o.eq_iff_norm_eq_and_oangle_eq_zero x y).2 ⟨h, ha⟩⟩ /-- Two vectors with zero angle between them are equal if and only if they have equal norms. -/ theorem eq_iff_norm_eq_of_oangle_eq_zero {x y : V} (h : o.oangle x y = 0) : x = y ↔ ‖x‖ = ‖y‖ := ⟨fun he => ((o.eq_iff_norm_eq_and_oangle_eq_zero x y).1 he).1, fun hn => (o.eq_iff_norm_eq_and_oangle_eq_zero x y).2 ⟨hn, h⟩⟩ /-- Given three nonzero vectors, the angle between the first and the second plus the angle between the second and the third equals the angle between the first and the third. -/ @[simp] theorem oangle_add {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle x y + o.oangle y z = o.oangle x z := by simp_rw [oangle] rw [← Complex.arg_mul_coe_angle, o.kahler_mul y x z] · congr 1 exact mod_cast Complex.arg_real_mul _ (by positivity : 0 < ‖y‖ ^ 2) · exact o.kahler_ne_zero hx hy · exact o.kahler_ne_zero hy hz /-- Given three nonzero vectors, the angle between the second and the third plus the angle between the first and the second equals the angle between the first and the third. -/ @[simp] theorem oangle_add_swap {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle y z + o.oangle x y = o.oangle x z := by rw [add_comm, o.oangle_add hx hy hz] /-- Given three nonzero vectors, the angle between the first and the third minus the angle between the first and the second equals the angle between the second and the third. -/ @[simp] theorem oangle_sub_left {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle x z - o.oangle x y = o.oangle y z := by rw [sub_eq_iff_eq_add, o.oangle_add_swap hx hy hz] /-- Given three nonzero vectors, the angle between the first and the third minus the angle between the second and the third equals the angle between the first and the second. -/ @[simp] theorem oangle_sub_right {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle x z - o.oangle y z = o.oangle x y := by rw [sub_eq_iff_eq_add, o.oangle_add hx hy hz] /-- Given three nonzero vectors, adding the angles between them in cyclic order results in 0. -/ @[simp] theorem oangle_add_cyc3 {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle x y + o.oangle y z + o.oangle z x = 0 := by simp [hx, hy, hz] /-- Given three nonzero vectors, adding the angles between them in cyclic order, with the first vector in each angle negated, results in π. If the vectors add to 0, this is a version of the sum of the angles of a triangle. -/ @[simp] theorem oangle_add_cyc3_neg_left {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle (-x) y + o.oangle (-y) z + o.oangle (-z) x = π := by rw [o.oangle_neg_left hx hy, o.oangle_neg_left hy hz, o.oangle_neg_left hz hx, show o.oangle x y + π + (o.oangle y z + π) + (o.oangle z x + π) = o.oangle x y + o.oangle y z + o.oangle z x + (π + π + π : Real.Angle) by abel, o.oangle_add_cyc3 hx hy hz, Real.Angle.coe_pi_add_coe_pi, zero_add, zero_add] /-- Given three nonzero vectors, adding the angles between them in cyclic order, with the second vector in each angle negated, results in π. If the vectors add to 0, this is a version of the sum of the angles of a triangle. -/ @[simp] theorem oangle_add_cyc3_neg_right {x y z : V} (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) : o.oangle x (-y) + o.oangle y (-z) + o.oangle z (-x) = π := by simp_rw [← oangle_neg_left_eq_neg_right, o.oangle_add_cyc3_neg_left hx hy hz] /-- Pons asinorum, oriented vector angle form. -/ theorem oangle_sub_eq_oangle_sub_rev_of_norm_eq {x y : V} (h : ‖x‖ = ‖y‖) : o.oangle x (x - y) = o.oangle (y - x) y := by simp [oangle, h] /-- The angle at the apex of an isosceles triangle is `π` minus twice a base angle, oriented vector angle form. -/ theorem oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq {x y : V} (hn : x ≠ y) (h : ‖x‖ = ‖y‖) : o.oangle y x = π - (2 : ℤ) • o.oangle (y - x) y := by rw [two_zsmul] nth_rw 1 [← o.oangle_sub_eq_oangle_sub_rev_of_norm_eq h] rw [eq_sub_iff_add_eq, ← oangle_neg_neg, ← add_assoc] have hy : y ≠ 0 := by rintro rfl rw [norm_zero, norm_eq_zero] at h exact hn h have hx : x ≠ 0 := norm_ne_zero_iff.1 (h.symm ▸ norm_ne_zero_iff.2 hy) convert o.oangle_add_cyc3_neg_right (neg_ne_zero.2 hy) hx (sub_ne_zero_of_ne hn.symm) using 1 simp /-- The angle between two vectors, with respect to an orientation given by `Orientation.map` with a linear isometric equivalence, equals the angle between those two vectors, transformed by the inverse of that equivalence, with respect to the original orientation. -/ @[simp] theorem oangle_map (x y : V') (f : V ≃ₗᵢ[ℝ] V') : (Orientation.map (Fin 2) f.toLinearEquiv o).oangle x y = o.oangle (f.symm x) (f.symm y) := by simp [oangle, o.kahler_map] @[simp] protected theorem _root_.Complex.oangle (w z : ℂ) : Complex.orientation.oangle w z = Complex.arg (conj w * z) := by simp [oangle, mul_comm z] /-- The oriented angle on an oriented real inner product space of dimension 2 can be evaluated in terms of a complex-number representation of the space. -/ theorem oangle_map_complex (f : V ≃ₗᵢ[ℝ] ℂ) (hf : Orientation.map (Fin 2) f.toLinearEquiv o = Complex.orientation) (x y : V) : o.oangle x y = Complex.arg (conj (f x) * f y) := by rw [← Complex.oangle, ← hf, o.oangle_map] iterate 2 rw [LinearIsometryEquiv.symm_apply_apply] /-- Negating the orientation negates the value of `oangle`. -/ theorem oangle_neg_orientation_eq_neg (x y : V) : (-o).oangle x y = -o.oangle x y := by simp [oangle] /-- The inner product of two vectors is the product of the norms and the cosine of the oriented angle between the vectors. -/ theorem inner_eq_norm_mul_norm_mul_cos_oangle (x y : V) : ⟪x, y⟫ = ‖x‖ * ‖y‖ * Real.Angle.cos (o.oangle x y) := by by_cases hx : x = 0; · simp [hx] by_cases hy : y = 0; · simp [hy] rw [oangle, Real.Angle.cos_coe, Complex.cos_arg, o.norm_kahler] · simp only [kahler_apply_apply, real_smul, add_re, ofReal_re, mul_re, I_re, ofReal_im] field_simp · exact o.kahler_ne_zero hx hy /-- The cosine of the oriented angle between two nonzero vectors is the inner product divided by the product of the norms. -/ theorem cos_oangle_eq_inner_div_norm_mul_norm {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : Real.Angle.cos (o.oangle x y) = ⟪x, y⟫ / (‖x‖ * ‖y‖) := by rw [o.inner_eq_norm_mul_norm_mul_cos_oangle] field_simp [norm_ne_zero_iff.2 hx, norm_ne_zero_iff.2 hy] /-- The cosine of the oriented angle between two nonzero vectors equals that of the unoriented angle. -/ theorem cos_oangle_eq_cos_angle {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : Real.Angle.cos (o.oangle x y) = Real.cos (InnerProductGeometry.angle x y) := by rw [o.cos_oangle_eq_inner_div_norm_mul_norm hx hy, InnerProductGeometry.cos_angle] /-- The oriented angle between two nonzero vectors is plus or minus the unoriented angle. -/ theorem oangle_eq_angle_or_eq_neg_angle {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : o.oangle x y = InnerProductGeometry.angle x y ∨ o.oangle x y = -InnerProductGeometry.angle x y := Real.Angle.cos_eq_real_cos_iff_eq_or_eq_neg.1 <| o.cos_oangle_eq_cos_angle hx hy /-- The unoriented angle between two nonzero vectors is the absolute value of the oriented angle, converted to a real. -/ theorem angle_eq_abs_oangle_toReal {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : InnerProductGeometry.angle x y = |(o.oangle x y).toReal| := by have h0 := InnerProductGeometry.angle_nonneg x y have hpi := InnerProductGeometry.angle_le_pi x y rcases o.oangle_eq_angle_or_eq_neg_angle hx hy with (h | h) · rw [h, eq_comm, Real.Angle.abs_toReal_coe_eq_self_iff] exact ⟨h0, hpi⟩ · rw [h, eq_comm, Real.Angle.abs_toReal_neg_coe_eq_self_iff] exact ⟨h0, hpi⟩ /-- If the sign of the oriented angle between two vectors is zero, either one of the vectors is zero or the unoriented angle is 0 or π. -/ theorem eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero {x y : V} (h : (o.oangle x y).sign = 0) : x = 0 ∨ y = 0 ∨ InnerProductGeometry.angle x y = 0 ∨ InnerProductGeometry.angle x y = π := by by_cases hx : x = 0; · simp [hx] by_cases hy : y = 0; · simp [hy] rw [o.angle_eq_abs_oangle_toReal hx hy] rw [Real.Angle.sign_eq_zero_iff] at h rcases h with (h | h) <;> simp [h, Real.pi_pos.le] /-- If two unoriented angles are equal, and the signs of the corresponding oriented angles are equal, then the oriented angles are equal (even in degenerate cases). -/ theorem oangle_eq_of_angle_eq_of_sign_eq {w x y z : V} (h : InnerProductGeometry.angle w x = InnerProductGeometry.angle y z) (hs : (o.oangle w x).sign = (o.oangle y z).sign) : o.oangle w x = o.oangle y z := by by_cases h0 : (w = 0 ∨ x = 0) ∨ y = 0 ∨ z = 0 · have hs' : (o.oangle w x).sign = 0 ∧ (o.oangle y z).sign = 0 := by rcases h0 with ((rfl | rfl) | rfl | rfl) · simpa using hs.symm · simpa using hs.symm · simpa using hs · simpa using hs rcases hs' with ⟨hswx, hsyz⟩ have h' : InnerProductGeometry.angle w x = π / 2 ∧ InnerProductGeometry.angle y z = π / 2 := by rcases h0 with ((rfl | rfl) | rfl | rfl) · simpa using h.symm · simpa using h.symm · simpa using h · simpa using h rcases h' with ⟨hwx, hyz⟩ have hpi : π / 2 ≠ π := by intro hpi rw [div_eq_iff, eq_comm, ← sub_eq_zero, mul_two, add_sub_cancel_right] at hpi · exact Real.pi_pos.ne.symm hpi · exact two_ne_zero have h0wx : w = 0 ∨ x = 0 := by have h0' := o.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero hswx simpa [hwx, Real.pi_pos.ne.symm, hpi] using h0' have h0yz : y = 0 ∨ z = 0 := by have h0' := o.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero hsyz simpa [hyz, Real.pi_pos.ne.symm, hpi] using h0' rcases h0wx with (h0wx | h0wx) <;> rcases h0yz with (h0yz | h0yz) <;> simp [h0wx, h0yz] · push_neg at h0 rw [Real.Angle.eq_iff_abs_toReal_eq_of_sign_eq hs] rwa [o.angle_eq_abs_oangle_toReal h0.1.1 h0.1.2, o.angle_eq_abs_oangle_toReal h0.2.1 h0.2.2] at h /-- If the signs of two oriented angles between nonzero vectors are equal, the oriented angles are equal if and only if the unoriented angles are equal. -/ theorem angle_eq_iff_oangle_eq_of_sign_eq {w x y z : V} (hw : w ≠ 0) (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) (hs : (o.oangle w x).sign = (o.oangle y z).sign) : InnerProductGeometry.angle w x = InnerProductGeometry.angle y z ↔ o.oangle w x = o.oangle y z := by refine ⟨fun h => o.oangle_eq_of_angle_eq_of_sign_eq h hs, fun h => ?_⟩ rw [o.angle_eq_abs_oangle_toReal hw hx, o.angle_eq_abs_oangle_toReal hy hz, h] /-- The oriented angle between two vectors equals the unoriented angle if the sign is positive. -/ theorem oangle_eq_angle_of_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : o.oangle x y = InnerProductGeometry.angle x y := by by_cases hx : x = 0; · exfalso; simp [hx] at h by_cases hy : y = 0; · exfalso; simp [hy] at h refine (o.oangle_eq_angle_or_eq_neg_angle hx hy).resolve_right ?_ intro hxy rw [hxy, Real.Angle.sign_neg, neg_eq_iff_eq_neg, ← SignType.neg_iff, ← not_le] at h exact h (Real.Angle.sign_coe_nonneg_of_nonneg_of_le_pi (InnerProductGeometry.angle_nonneg _ _) (InnerProductGeometry.angle_le_pi _ _)) /-- The oriented angle between two vectors equals minus the unoriented angle if the sign is negative. -/ theorem oangle_eq_neg_angle_of_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : o.oangle x y = -InnerProductGeometry.angle x y := by by_cases hx : x = 0; · exfalso; simp [hx] at h by_cases hy : y = 0; · exfalso; simp [hy] at h refine (o.oangle_eq_angle_or_eq_neg_angle hx hy).resolve_left ?_ intro hxy rw [hxy, ← SignType.neg_iff, ← not_le] at h exact h (Real.Angle.sign_coe_nonneg_of_nonneg_of_le_pi (InnerProductGeometry.angle_nonneg _ _) (InnerProductGeometry.angle_le_pi _ _)) /-- The oriented angle between two nonzero vectors is zero if and only if the unoriented angle is zero. -/ theorem oangle_eq_zero_iff_angle_eq_zero {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : o.oangle x y = 0 ↔ InnerProductGeometry.angle x y = 0 := by refine ⟨fun h => ?_, fun h => ?_⟩ · simpa [o.angle_eq_abs_oangle_toReal hx hy] · have ha := o.oangle_eq_angle_or_eq_neg_angle hx hy rw [h] at ha simpa using ha /-- The oriented angle between two vectors is `π` if and only if the unoriented angle is `π`. -/ theorem oangle_eq_pi_iff_angle_eq_pi {x y : V} : o.oangle x y = π ↔ InnerProductGeometry.angle x y = π := by by_cases hx : x = 0 · simp [hx, Real.Angle.pi_ne_zero.symm, div_eq_mul_inv, mul_right_eq_self₀, not_or, Real.pi_ne_zero] by_cases hy : y = 0 · simp [hy, Real.Angle.pi_ne_zero.symm, div_eq_mul_inv, mul_right_eq_self₀, not_or, Real.pi_ne_zero] refine ⟨fun h => ?_, fun h => ?_⟩ · rw [o.angle_eq_abs_oangle_toReal hx hy, h] simp [Real.pi_pos.le] · have ha := o.oangle_eq_angle_or_eq_neg_angle hx hy rw [h] at ha simpa using ha /-- One of two vectors is zero or the oriented angle between them is plus or minus `π / 2` if and only if the inner product of those vectors is zero. -/ theorem eq_zero_or_oangle_eq_iff_inner_eq_zero {x y : V} : x = 0 ∨ y = 0 ∨ o.oangle x y = (π / 2 : ℝ) ∨ o.oangle x y = (-π / 2 : ℝ) ↔ ⟪x, y⟫ = 0 := by by_cases hx : x = 0; · simp [hx] by_cases hy : y = 0; · simp [hy] rw [InnerProductGeometry.inner_eq_zero_iff_angle_eq_pi_div_two, or_iff_right hx, or_iff_right hy] refine ⟨fun h => ?_, fun h => ?_⟩ · rwa [o.angle_eq_abs_oangle_toReal hx hy, Real.Angle.abs_toReal_eq_pi_div_two_iff] · convert o.oangle_eq_angle_or_eq_neg_angle hx hy using 2 <;> rw [h] simp only [neg_div, Real.Angle.coe_neg] /-- If the oriented angle between two vectors is `π / 2`, the inner product of those vectors is zero. -/ theorem inner_eq_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : ⟪x, y⟫ = 0 := o.eq_zero_or_oangle_eq_iff_inner_eq_zero.1 <| Or.inr <| Or.inr <| Or.inl h /-- If the oriented angle between two vectors is `π / 2`, the inner product of those vectors (reversed) is zero. -/ theorem inner_rev_eq_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (π / 2 : ℝ)) : ⟪y, x⟫ = 0 := by rw [real_inner_comm, o.inner_eq_zero_of_oangle_eq_pi_div_two h] /-- If the oriented angle between two vectors is `-π / 2`, the inner product of those vectors is zero. -/ theorem inner_eq_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : ⟪x, y⟫ = 0 := o.eq_zero_or_oangle_eq_iff_inner_eq_zero.1 <| Or.inr <| Or.inr <| Or.inr h /-- If the oriented angle between two vectors is `-π / 2`, the inner product of those vectors (reversed) is zero. -/ theorem inner_rev_eq_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-π / 2 : ℝ)) : ⟪y, x⟫ = 0 := by rw [real_inner_comm, o.inner_eq_zero_of_oangle_eq_neg_pi_div_two h] /-- Negating the first vector passed to `oangle` negates the sign of the angle. -/ @[simp] theorem oangle_sign_neg_left (x y : V) : (o.oangle (-x) y).sign = -(o.oangle x y).sign := by by_cases hx : x = 0; · simp [hx] by_cases hy : y = 0; · simp [hy] rw [o.oangle_neg_left hx hy, Real.Angle.sign_add_pi] /-- Negating the second vector passed to `oangle` negates the sign of the angle. -/ @[simp] theorem oangle_sign_neg_right (x y : V) : (o.oangle x (-y)).sign = -(o.oangle x y).sign := by by_cases hx : x = 0; · simp [hx] by_cases hy : y = 0; · simp [hy] rw [o.oangle_neg_right hx hy, Real.Angle.sign_add_pi] /-- Multiplying the first vector passed to `oangle` by a real multiplies the sign of the angle by the sign of the real. -/ @[simp] theorem oangle_sign_smul_left (x y : V) (r : ℝ) : (o.oangle (r • x) y).sign = SignType.sign r * (o.oangle x y).sign := by rcases lt_trichotomy r 0 with (h | h | h) <;> simp [h] /-- Multiplying the second vector passed to `oangle` by a real multiplies the sign of the angle by the sign of the real. -/ @[simp] theorem oangle_sign_smul_right (x y : V) (r : ℝ) : (o.oangle x (r • y)).sign = SignType.sign r * (o.oangle x y).sign := by rcases lt_trichotomy r 0 with (h | h | h) <;> simp [h] /-- Auxiliary lemma for the proof of `oangle_sign_smul_add_right`; not intended to be used outside of that proof. -/ theorem oangle_smul_add_right_eq_zero_or_eq_pi_iff {x y : V} (r : ℝ) : o.oangle x (r • x + y) = 0 ∨ o.oangle x (r • x + y) = π ↔ o.oangle x y = 0 ∨ o.oangle x y = π := by simp_rw [oangle_eq_zero_or_eq_pi_iff_not_linearIndependent, Fintype.not_linearIndependent_iff, Fin.sum_univ_two, Fin.exists_fin_two] refine ⟨fun h => ?_, fun h => ?_⟩ · rcases h with ⟨m, h, hm⟩ change m 0 • x + m 1 • (r • x + y) = 0 at h refine ⟨![m 0 + m 1 * r, m 1], ?_⟩ change (m 0 + m 1 * r) • x + m 1 • y = 0 ∧ (m 0 + m 1 * r ≠ 0 ∨ m 1 ≠ 0) rw [smul_add, smul_smul, ← add_assoc, ← add_smul] at h refine ⟨h, not_and_or.1 fun h0 => ?_⟩ obtain ⟨h0, h1⟩ := h0 rw [h1] at h0 hm rw [zero_mul, add_zero] at h0 simp [h0] at hm · rcases h with ⟨m, h, hm⟩ change m 0 • x + m 1 • y = 0 at h refine ⟨![m 0 - m 1 * r, m 1], ?_⟩ change (m 0 - m 1 * r) • x + m 1 • (r • x + y) = 0 ∧ (m 0 - m 1 * r ≠ 0 ∨ m 1 ≠ 0) rw [sub_smul, smul_add, smul_smul, ← add_assoc, sub_add_cancel] refine ⟨h, not_and_or.1 fun h0 => ?_⟩ obtain ⟨h0, h1⟩ := h0 rw [h1] at h0 hm rw [zero_mul, sub_zero] at h0 simp [h0] at hm /-- Adding a multiple of the first vector passed to `oangle` to the second vector does not change the sign of the angle. -/ @[simp] theorem oangle_sign_smul_add_right (x y : V) (r : ℝ) : (o.oangle x (r • x + y)).sign = (o.oangle x y).sign := by by_cases h : o.oangle x y = 0 ∨ o.oangle x y = π · rwa [Real.Angle.sign_eq_zero_iff.2 h, Real.Angle.sign_eq_zero_iff, oangle_smul_add_right_eq_zero_or_eq_pi_iff] have h' : ∀ r' : ℝ, o.oangle x (r' • x + y) ≠ 0 ∧ o.oangle x (r' • x + y) ≠ π := by intro r' rwa [← o.oangle_smul_add_right_eq_zero_or_eq_pi_iff r', not_or] at h let s : Set (V × V) := (fun r' : ℝ => (x, r' • x + y)) '' Set.univ have hc : IsConnected s := isConnected_univ.image _ (by fun_prop) have hf : ContinuousOn (fun z : V × V => o.oangle z.1 z.2) s := by refine continuousOn_of_forall_continuousAt fun z hz => o.continuousAt_oangle ?_ ?_ all_goals simp_rw [s, Set.mem_image] at hz obtain ⟨r', -, rfl⟩ := hz simp only [Prod.fst, Prod.snd] intro hz · simpa [hz] using (h' 0).1 · simpa [hz] using (h' r').1 have hs : ∀ z : V × V, z ∈ s → o.oangle z.1 z.2 ≠ 0 ∧ o.oangle z.1 z.2 ≠ π := by intro z hz simp_rw [s, Set.mem_image] at hz obtain ⟨r', -, rfl⟩ := hz exact h' r' have hx : (x, y) ∈ s := by convert Set.mem_image_of_mem (fun r' : ℝ => (x, r' • x + y)) (Set.mem_univ 0) simp have hy : (x, r • x + y) ∈ s := Set.mem_image_of_mem _ (Set.mem_univ _) convert Real.Angle.sign_eq_of_continuousOn hc hf hs hx hy /-- Adding a multiple of the second vector passed to `oangle` to the first vector does not change the sign of the angle. -/ @[simp] theorem oangle_sign_add_smul_left (x y : V) (r : ℝ) : (o.oangle (x + r • y) y).sign = (o.oangle x y).sign := by simp_rw [o.oangle_rev y, Real.Angle.sign_neg, add_comm x, oangle_sign_smul_add_right] /-- Subtracting a multiple of the first vector passed to `oangle` from the second vector does not change the sign of the angle. -/ @[simp] theorem oangle_sign_sub_smul_right (x y : V) (r : ℝ) : (o.oangle x (y - r • x)).sign = (o.oangle x y).sign := by rw [sub_eq_add_neg, ← neg_smul, add_comm, oangle_sign_smul_add_right] /-- Subtracting a multiple of the second vector passed to `oangle` from the first vector does not change the sign of the angle. -/ @[simp] theorem oangle_sign_sub_smul_left (x y : V) (r : ℝ) : (o.oangle (x - r • y) y).sign = (o.oangle x y).sign := by rw [sub_eq_add_neg, ← neg_smul, oangle_sign_add_smul_left] /-- Adding the first vector passed to `oangle` to the second vector does not change the sign of the angle. -/ @[simp] theorem oangle_sign_add_right (x y : V) : (o.oangle x (x + y)).sign = (o.oangle x y).sign := by rw [← o.oangle_sign_smul_add_right x y 1, one_smul] /-- Adding the second vector passed to `oangle` to the first vector does not change the sign of the angle. -/ @[simp] theorem oangle_sign_add_left (x y : V) : (o.oangle (x + y) y).sign = (o.oangle x y).sign := by rw [← o.oangle_sign_add_smul_left x y 1, one_smul] /-- Subtracting the first vector passed to `oangle` from the second vector does not change the sign of the angle. -/ @[simp] theorem oangle_sign_sub_right (x y : V) : (o.oangle x (y - x)).sign = (o.oangle x y).sign := by rw [← o.oangle_sign_sub_smul_right x y 1, one_smul] /-- Subtracting the second vector passed to `oangle` from the first vector does not change the sign of the angle. -/ @[simp] theorem oangle_sign_sub_left (x y : V) : (o.oangle (x - y) y).sign = (o.oangle x y).sign := by rw [← o.oangle_sign_sub_smul_left x y 1, one_smul] /-- Subtracting the second vector passed to `oangle` from a multiple of the first vector negates the sign of the angle. -/ @[simp] theorem oangle_sign_smul_sub_right (x y : V) (r : ℝ) : (o.oangle x (r • x - y)).sign = -(o.oangle x y).sign := by rw [← oangle_sign_neg_right, sub_eq_add_neg, oangle_sign_smul_add_right] /-- Subtracting the first vector passed to `oangle` from a multiple of the second vector negates the sign of the angle. -/ @[simp] theorem oangle_sign_smul_sub_left (x y : V) (r : ℝ) : (o.oangle (r • y - x) y).sign = -(o.oangle x y).sign := by rw [← oangle_sign_neg_left, sub_eq_neg_add, oangle_sign_add_smul_left] /-- Subtracting the second vector passed to `oangle` from the first vector negates the sign of the angle. -/ theorem oangle_sign_sub_right_eq_neg (x y : V) : (o.oangle x (x - y)).sign = -(o.oangle x y).sign := by rw [← o.oangle_sign_smul_sub_right x y 1, one_smul] /-- Subtracting the first vector passed to `oangle` from the second vector negates the sign of the angle. -/ theorem oangle_sign_sub_left_eq_neg (x y : V) : (o.oangle (y - x) y).sign = -(o.oangle x y).sign := by rw [← o.oangle_sign_smul_sub_left x y 1, one_smul] /-- Subtracting the first vector passed to `oangle` from the second vector then swapping the vectors does not change the sign of the angle. -/ @[simp] theorem oangle_sign_sub_right_swap (x y : V) : (o.oangle y (y - x)).sign = (o.oangle x y).sign := by rw [oangle_sign_sub_right_eq_neg, o.oangle_rev y x, Real.Angle.sign_neg] /-- Subtracting the second vector passed to `oangle` from the first vector then swapping the vectors does not change the sign of the angle. -/ @[simp] theorem oangle_sign_sub_left_swap (x y : V) : (o.oangle (x - y) x).sign = (o.oangle x y).sign := by rw [oangle_sign_sub_left_eq_neg, o.oangle_rev y x, Real.Angle.sign_neg] /-- The sign of the angle between a vector, and a linear combination of that vector with a second vector, is the sign of the factor by which the second vector is multiplied in that combination multiplied by the sign of the angle between the two vectors. -/ theorem oangle_sign_smul_add_smul_right (x y : V) (r₁ r₂ : ℝ) : (o.oangle x (r₁ • x + r₂ • y)).sign = SignType.sign r₂ * (o.oangle x y).sign := by rw [← o.oangle_sign_smul_add_right x (r₁ • x + r₂ • y) (-r₁)] simp /-- The sign of the angle between a linear combination of two vectors and the second vector is the sign of the factor by which the first vector is multiplied in that combination multiplied by the sign of the angle between the two vectors. -/ theorem oangle_sign_smul_add_smul_left (x y : V) (r₁ r₂ : ℝ) : (o.oangle (r₁ • x + r₂ • y) y).sign = SignType.sign r₁ * (o.oangle x y).sign := by simp_rw [o.oangle_rev y, Real.Angle.sign_neg, add_comm (r₁ • x), oangle_sign_smul_add_smul_right, mul_neg] /-- The sign of the angle between two linear combinations of two vectors is the sign of the determinant of the factors in those combinations multiplied by the sign of the angle between the two vectors. -/ theorem oangle_sign_smul_add_smul_smul_add_smul (x y : V) (r₁ r₂ r₃ r₄ : ℝ) : (o.oangle (r₁ • x + r₂ • y) (r₃ • x + r₄ • y)).sign = SignType.sign (r₁ * r₄ - r₂ * r₃) * (o.oangle x y).sign := by by_cases hr₁ : r₁ = 0 · rw [hr₁, zero_smul, zero_mul, zero_add, zero_sub, Left.sign_neg, oangle_sign_smul_left, add_comm, oangle_sign_smul_add_smul_right, oangle_rev, Real.Angle.sign_neg, sign_mul, mul_neg, mul_neg, neg_mul, mul_assoc] · rw [← o.oangle_sign_smul_add_right (r₁ • x + r₂ • y) (r₃ • x + r₄ • y) (-r₃ / r₁), smul_add, smul_smul, smul_smul, div_mul_cancel₀ _ hr₁, neg_smul, ← add_assoc, add_comm (-(r₃ • x)), ← sub_eq_add_neg, sub_add_cancel, ← add_smul, oangle_sign_smul_right, oangle_sign_smul_add_smul_left, ← mul_assoc, ← sign_mul, add_mul, mul_assoc, mul_comm r₂ r₁, ← mul_assoc, div_mul_cancel₀ _ hr₁, add_comm, neg_mul, ← sub_eq_add_neg, mul_comm r₄, mul_comm r₃] /-- A base angle of an isosceles triangle is acute, oriented vector angle form. -/ theorem abs_oangle_sub_left_toReal_lt_pi_div_two {x y : V} (h : ‖x‖ = ‖y‖) : |(o.oangle (y - x) y).toReal| < π / 2 := by by_cases hn : x = y; · simp [hn, div_pos, Real.pi_pos] have hs : ((2 : ℤ) • o.oangle (y - x) y).sign = (o.oangle (y - x) y).sign := by conv_rhs => rw [oangle_sign_sub_left_swap] rw [o.oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq hn h, Real.Angle.sign_pi_sub] rw [Real.Angle.sign_two_zsmul_eq_sign_iff] at hs rcases hs with (hs | hs) · rw [oangle_eq_pi_iff_oangle_rev_eq_pi, oangle_eq_pi_iff_sameRay_neg, neg_sub] at hs rcases hs with ⟨hy, -, hr⟩ rw [← exists_nonneg_left_iff_sameRay hy] at hr rcases hr with ⟨r, hr0, hr⟩ rw [eq_sub_iff_add_eq] at hr nth_rw 2 [← one_smul ℝ y] at hr rw [← add_smul] at hr rw [← hr, norm_smul, Real.norm_eq_abs, abs_of_pos (Left.add_pos_of_nonneg_of_pos hr0 one_pos), mul_left_eq_self₀, or_iff_left (norm_ne_zero_iff.2 hy), add_eq_right] at h rw [h, zero_add, one_smul] at hr exact False.elim (hn hr.symm) · exact hs /-- A base angle of an isosceles triangle is acute, oriented vector angle form. -/ theorem abs_oangle_sub_right_toReal_lt_pi_div_two {x y : V} (h : ‖x‖ = ‖y‖) : |(o.oangle x (x - y)).toReal| < π / 2 := (o.oangle_sub_eq_oangle_sub_rev_of_norm_eq h).symm ▸ o.abs_oangle_sub_left_toReal_lt_pi_div_two h end Orientation
Mathlib/Geometry/Euclidean/Angle/Oriented/Basic.lean
1,006
1,008
/- Copyright (c) 2021 Yaël Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import Mathlib.Analysis.Convex.Topology import Mathlib.Analysis.NormedSpace.Pointwise import Mathlib.Analysis.Seminorm import Mathlib.Analysis.LocallyConvex.Bounded import Mathlib.Analysis.RCLike.Basic /-! # The Minkowski functional This file defines the Minkowski functional, aka gauge. The Minkowski functional of a set `s` is the function which associates each point to how much you need to scale `s` for `x` to be inside it. When `s` is symmetric, convex and absorbent, its gauge is a seminorm. Reciprocally, any seminorm arises as the gauge of some set, namely its unit ball. This induces the equivalence of seminorms and locally convex topological vector spaces. ## Main declarations For a real vector space, * `gauge`: Aka Minkowski functional. `gauge s x` is the least (actually, an infimum) `r` such that `x ∈ r • s`. * `gaugeSeminorm`: The Minkowski functional as a seminorm, when `s` is symmetric, convex and absorbent. ## References * [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966] ## Tags Minkowski functional, gauge -/ open NormedField Set open scoped Pointwise Topology NNReal noncomputable section variable {𝕜 E : Type*} section AddCommGroup variable [AddCommGroup E] [Module ℝ E] /-- The Minkowski functional. Given a set `s` in a real vector space, `gauge s` is the functional which sends `x : E` to the smallest `r : ℝ` such that `x` is in `s` scaled by `r`. -/ def gauge (s : Set E) (x : E) : ℝ := sInf { r : ℝ | 0 < r ∧ x ∈ r • s } variable {s t : Set E} {x : E} {a : ℝ} theorem gauge_def : gauge s x = sInf ({ r ∈ Set.Ioi (0 : ℝ) | x ∈ r • s }) := rfl /-- An alternative definition of the gauge using scalar multiplication on the element rather than on the set. -/ theorem gauge_def' : gauge s x = sInf {r ∈ Set.Ioi (0 : ℝ) | r⁻¹ • x ∈ s} := by congrm sInf {r | ?_} exact and_congr_right fun hr => mem_smul_set_iff_inv_smul_mem₀ hr.ne' _ _ private theorem gauge_set_bddBelow : BddBelow { r : ℝ | 0 < r ∧ x ∈ r • s } := ⟨0, fun _ hr => hr.1.le⟩ /-- If the given subset is `Absorbent` then the set we take an infimum over in `gauge` is nonempty, which is useful for proving many properties about the gauge. -/ theorem Absorbent.gauge_set_nonempty (absorbs : Absorbent ℝ s) : { r : ℝ | 0 < r ∧ x ∈ r • s }.Nonempty := let ⟨r, hr₁, hr₂⟩ := (absorbs x).exists_pos ⟨r, hr₁, hr₂ r (Real.norm_of_nonneg hr₁.le).ge rfl⟩ theorem gauge_mono (hs : Absorbent ℝ s) (h : s ⊆ t) : gauge t ≤ gauge s := fun _ => csInf_le_csInf gauge_set_bddBelow hs.gauge_set_nonempty fun _ hr => ⟨hr.1, smul_set_mono h hr.2⟩ theorem exists_lt_of_gauge_lt (absorbs : Absorbent ℝ s) (h : gauge s x < a) : ∃ b, 0 < b ∧ b < a ∧ x ∈ b • s := by obtain ⟨b, ⟨hb, hx⟩, hba⟩ := exists_lt_of_csInf_lt absorbs.gauge_set_nonempty h exact ⟨b, hb, hba, hx⟩ /-- The gauge evaluated at `0` is always zero (mathematically this requires `0` to be in the set `s` but, the real infimum of the empty set in Lean being defined as `0`, it holds unconditionally). -/ @[simp] theorem gauge_zero : gauge s 0 = 0 := by rw [gauge_def'] by_cases h : (0 : E) ∈ s · simp only [smul_zero, sep_true, h, csInf_Ioi] · simp only [smul_zero, sep_false, h, Real.sInf_empty] @[simp] theorem gauge_zero' : gauge (0 : Set E) = 0 := by ext x rw [gauge_def'] obtain rfl | hx := eq_or_ne x 0 · simp only [csInf_Ioi, mem_zero, Pi.zero_apply, eq_self_iff_true, sep_true, smul_zero] · simp only [mem_zero, Pi.zero_apply, inv_eq_zero, smul_eq_zero] convert Real.sInf_empty exact eq_empty_iff_forall_not_mem.2 fun r hr => hr.2.elim (ne_of_gt hr.1) hx @[simp] theorem gauge_empty : gauge (∅ : Set E) = 0 := by ext simp only [gauge_def', Real.sInf_empty, mem_empty_iff_false, Pi.zero_apply, sep_false] theorem gauge_of_subset_zero (h : s ⊆ 0) : gauge s = 0 := by obtain rfl | rfl := subset_singleton_iff_eq.1 h exacts [gauge_empty, gauge_zero'] /-- The gauge is always nonnegative. -/ theorem gauge_nonneg (x : E) : 0 ≤ gauge s x := Real.sInf_nonneg fun _ hx => hx.1.le theorem gauge_neg (symmetric : ∀ x ∈ s, -x ∈ s) (x : E) : gauge s (-x) = gauge s x := by have : ∀ x, -x ∈ s ↔ x ∈ s := fun x => ⟨fun h => by simpa using symmetric _ h, symmetric x⟩ simp_rw [gauge_def', smul_neg, this] theorem gauge_neg_set_neg (x : E) : gauge (-s) (-x) = gauge s x := by simp_rw [gauge_def', smul_neg, neg_mem_neg] theorem gauge_neg_set_eq_gauge_neg (x : E) : gauge (-s) x = gauge s (-x) := by rw [← gauge_neg_set_neg, neg_neg] theorem gauge_le_of_mem (ha : 0 ≤ a) (hx : x ∈ a • s) : gauge s x ≤ a := by obtain rfl | ha' := ha.eq_or_lt · rw [mem_singleton_iff.1 (zero_smul_set_subset _ hx), gauge_zero] · exact csInf_le gauge_set_bddBelow ⟨ha', hx⟩ theorem gauge_le_eq (hs₁ : Convex ℝ s) (hs₀ : (0 : E) ∈ s) (hs₂ : Absorbent ℝ s) (ha : 0 ≤ a) : { x | gauge s x ≤ a } = ⋂ (r : ℝ) (_ : a < r), r • s := by ext x simp_rw [Set.mem_iInter, Set.mem_setOf_eq] refine ⟨fun h r hr => ?_, fun h => le_of_forall_pos_lt_add fun ε hε => ?_⟩ · have hr' := ha.trans_lt hr rw [mem_smul_set_iff_inv_smul_mem₀ hr'.ne'] obtain ⟨δ, δ_pos, hδr, hδ⟩ := exists_lt_of_gauge_lt hs₂ (h.trans_lt hr) suffices (r⁻¹ * δ) • δ⁻¹ • x ∈ s by rwa [smul_smul, mul_inv_cancel_right₀ δ_pos.ne'] at this rw [mem_smul_set_iff_inv_smul_mem₀ δ_pos.ne'] at hδ refine hs₁.smul_mem_of_zero_mem hs₀ hδ ⟨by positivity, ?_⟩ rw [inv_mul_le_iff₀ hr', mul_one] exact hδr.le · have hε' := (lt_add_iff_pos_right a).2 (half_pos hε) exact (gauge_le_of_mem (ha.trans hε'.le) <| h _ hε').trans_lt (add_lt_add_left (half_lt_self hε) _) theorem gauge_lt_eq' (absorbs : Absorbent ℝ s) (a : ℝ) : { x | gauge s x < a } = ⋃ (r : ℝ) (_ : 0 < r) (_ : r < a), r • s := by ext simp_rw [mem_setOf, mem_iUnion, exists_prop] exact ⟨exists_lt_of_gauge_lt absorbs, fun ⟨r, hr₀, hr₁, hx⟩ => (gauge_le_of_mem hr₀.le hx).trans_lt hr₁⟩ theorem gauge_lt_eq (absorbs : Absorbent ℝ s) (a : ℝ) : { x | gauge s x < a } = ⋃ r ∈ Set.Ioo 0 (a : ℝ), r • s := by ext simp_rw [mem_setOf, mem_iUnion, exists_prop, mem_Ioo, and_assoc] exact ⟨exists_lt_of_gauge_lt absorbs, fun ⟨r, hr₀, hr₁, hx⟩ => (gauge_le_of_mem hr₀.le hx).trans_lt hr₁⟩ theorem mem_openSegment_of_gauge_lt_one (absorbs : Absorbent ℝ s) (hgauge : gauge s x < 1) : ∃ y ∈ s, x ∈ openSegment ℝ 0 y := by rcases exists_lt_of_gauge_lt absorbs hgauge with ⟨r, hr₀, hr₁, y, hy, rfl⟩ refine ⟨y, hy, 1 - r, r, ?_⟩ simp [*] theorem gauge_lt_one_subset_self (hs : Convex ℝ s) (h₀ : (0 : E) ∈ s) (absorbs : Absorbent ℝ s) : { x | gauge s x < 1 } ⊆ s := fun _x hx ↦ let ⟨_y, hys, hx⟩ := mem_openSegment_of_gauge_lt_one absorbs hx hs.openSegment_subset h₀ hys hx theorem gauge_le_one_of_mem {x : E} (hx : x ∈ s) : gauge s x ≤ 1 := gauge_le_of_mem zero_le_one <| by rwa [one_smul] /-- Gauge is subadditive. -/ theorem gauge_add_le (hs : Convex ℝ s) (absorbs : Absorbent ℝ s) (x y : E) : gauge s (x + y) ≤ gauge s x + gauge s y := by refine le_of_forall_pos_lt_add fun ε hε => ?_ obtain ⟨a, ha, ha', x, hx, rfl⟩ := exists_lt_of_gauge_lt absorbs (lt_add_of_pos_right (gauge s x) (half_pos hε)) obtain ⟨b, hb, hb', y, hy, rfl⟩ := exists_lt_of_gauge_lt absorbs (lt_add_of_pos_right (gauge s y) (half_pos hε)) calc gauge s (a • x + b • y) ≤ a + b := gauge_le_of_mem (by positivity) <| by rw [hs.add_smul ha.le hb.le] exact add_mem_add (smul_mem_smul_set hx) (smul_mem_smul_set hy) _ < gauge s (a • x) + gauge s (b • y) + ε := by linarith theorem self_subset_gauge_le_one : s ⊆ { x | gauge s x ≤ 1 } := fun _ => gauge_le_one_of_mem theorem Convex.gauge_le (hs : Convex ℝ s) (h₀ : (0 : E) ∈ s) (absorbs : Absorbent ℝ s) (a : ℝ) : Convex ℝ { x | gauge s x ≤ a } := by by_cases ha : 0 ≤ a · rw [gauge_le_eq hs h₀ absorbs ha] exact convex_iInter fun i => convex_iInter fun _ => hs.smul _ · convert convex_empty (𝕜 := ℝ) exact eq_empty_iff_forall_not_mem.2 fun x hx => ha <| (gauge_nonneg _).trans hx theorem Balanced.starConvex (hs : Balanced ℝ s) : StarConvex ℝ 0 s := starConvex_zero_iff.2 fun _ hx a ha₀ ha₁ => hs _ (by rwa [Real.norm_of_nonneg ha₀]) (smul_mem_smul_set hx) theorem le_gauge_of_not_mem (hs₀ : StarConvex ℝ 0 s) (hs₂ : Absorbs ℝ s {x}) (hx : x ∉ a • s) : a ≤ gauge s x := by rw [starConvex_zero_iff] at hs₀ obtain ⟨r, hr, h⟩ := hs₂.exists_pos refine le_csInf ⟨r, hr, singleton_subset_iff.1 <| h _ (Real.norm_of_nonneg hr.le).ge⟩ ?_ rintro b ⟨hb, x, hx', rfl⟩ refine not_lt.1 fun hba => hx ?_ have ha := hb.trans hba refine ⟨(a⁻¹ * b) • x, hs₀ hx' (by positivity) ?_, ?_⟩ · rw [← div_eq_inv_mul] exact div_le_one_of_le₀ hba.le ha.le · dsimp only rw [← mul_smul, mul_inv_cancel_left₀ ha.ne'] theorem one_le_gauge_of_not_mem (hs₁ : StarConvex ℝ 0 s) (hs₂ : Absorbs ℝ s {x}) (hx : x ∉ s) : 1 ≤ gauge s x := le_gauge_of_not_mem hs₁ hs₂ <| by rwa [one_smul] section LinearOrderedField variable {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α] [MulActionWithZero α ℝ] [OrderedSMul α ℝ] theorem gauge_smul_of_nonneg [MulActionWithZero α E] [IsScalarTower α ℝ (Set E)] {s : Set E} {a : α} (ha : 0 ≤ a) (x : E) : gauge s (a • x) = a • gauge s x := by obtain rfl | ha' := ha.eq_or_lt · rw [zero_smul, gauge_zero, zero_smul] rw [gauge_def', gauge_def', ← Real.sInf_smul_of_nonneg ha] congr 1 ext r simp_rw [Set.mem_smul_set, Set.mem_sep_iff] constructor · rintro ⟨hr, hx⟩ simp_rw [mem_Ioi] at hr ⊢ rw [← mem_smul_set_iff_inv_smul_mem₀ hr.ne'] at hx have := smul_pos (inv_pos.2 ha') hr refine ⟨a⁻¹ • r, ⟨this, ?_⟩, smul_inv_smul₀ ha'.ne' _⟩ rwa [← mem_smul_set_iff_inv_smul_mem₀ this.ne', smul_assoc, mem_smul_set_iff_inv_smul_mem₀ (inv_ne_zero ha'.ne'), inv_inv] · rintro ⟨r, ⟨hr, hx⟩, rfl⟩ rw [mem_Ioi] at hr ⊢ rw [← mem_smul_set_iff_inv_smul_mem₀ hr.ne'] at hx have := smul_pos ha' hr refine ⟨this, ?_⟩ rw [← mem_smul_set_iff_inv_smul_mem₀ this.ne', smul_assoc] exact smul_mem_smul_set hx theorem gauge_smul_left_of_nonneg [MulActionWithZero α E] [SMulCommClass α ℝ ℝ] [IsScalarTower α ℝ ℝ] [IsScalarTower α ℝ E] {s : Set E} {a : α} (ha : 0 ≤ a) : gauge (a • s) = a⁻¹ • gauge s := by obtain rfl | ha' := ha.eq_or_lt · rw [inv_zero, zero_smul, gauge_of_subset_zero (zero_smul_set_subset _)] ext x rw [gauge_def', Pi.smul_apply, gauge_def', ← Real.sInf_smul_of_nonneg (inv_nonneg.2 ha)] congr 1 ext r simp_rw [Set.mem_smul_set, Set.mem_sep_iff] constructor · rintro ⟨hr, y, hy, h⟩ simp_rw [mem_Ioi] at hr ⊢ refine ⟨a • r, ⟨smul_pos ha' hr, ?_⟩, inv_smul_smul₀ ha'.ne' _⟩ rwa [smul_inv₀, smul_assoc, ← h, inv_smul_smul₀ ha'.ne'] · rintro ⟨r, ⟨hr, hx⟩, rfl⟩ rw [mem_Ioi] at hr ⊢ refine ⟨smul_pos (inv_pos.2 ha') hr, r⁻¹ • x, hx, ?_⟩ rw [smul_inv₀, smul_assoc, inv_inv] theorem gauge_smul_left [Module α E] [SMulCommClass α ℝ ℝ] [IsScalarTower α ℝ ℝ] [IsScalarTower α ℝ E] {s : Set E} (symmetric : ∀ x ∈ s, -x ∈ s) (a : α) : gauge (a • s) = |a|⁻¹ • gauge s := by rw [← gauge_smul_left_of_nonneg (abs_nonneg a)] obtain h | h := abs_choice a · rw [h] · rw [h, Set.neg_smul_set, ← Set.smul_set_neg] -- Porting note: was congr apply congr_arg apply congr_arg ext y refine ⟨symmetric _, fun hy => ?_⟩ rw [← neg_neg y] exact symmetric _ hy end LinearOrderedField section RCLike variable [RCLike 𝕜] [Module 𝕜 E] [IsScalarTower ℝ 𝕜 E] theorem gauge_norm_smul (hs : Balanced 𝕜 s) (r : 𝕜) (x : E) : gauge s (‖r‖ • x) = gauge s (r • x) := by unfold gauge congr with θ rw [@RCLike.real_smul_eq_coe_smul 𝕜] refine and_congr_right fun hθ => (hs.smul _).smul_mem_iff ?_ rw [RCLike.norm_ofReal, abs_norm] /-- If `s` is balanced, then the Minkowski functional is ℂ-homogeneous. -/ theorem gauge_smul (hs : Balanced 𝕜 s) (r : 𝕜) (x : E) : gauge s (r • x) = ‖r‖ * gauge s x := by rw [← smul_eq_mul, ← gauge_smul_of_nonneg (norm_nonneg r), gauge_norm_smul hs] end RCLike open Filter section TopologicalSpace variable [TopologicalSpace E] theorem comap_gauge_nhds_zero_le (ha : Absorbent ℝ s) (hb : Bornology.IsVonNBounded ℝ s) : comap (gauge s) (𝓝 0) ≤ 𝓝 0 := fun u hu ↦ by rcases (hb hu).exists_pos with ⟨r, hr₀, hr⟩ filter_upwards [preimage_mem_comap (gt_mem_nhds (inv_pos.2 hr₀))] with x (hx : gauge s x < r⁻¹) rcases exists_lt_of_gauge_lt ha hx with ⟨c, hc₀, hcr, y, hy, rfl⟩ have hrc := (lt_inv_comm₀ hr₀ hc₀).2 hcr rcases hr c⁻¹ (hrc.le.trans (le_abs_self _)) hy with ⟨z, hz, rfl⟩ simpa only [smul_inv_smul₀ hc₀.ne'] variable [T1Space E] theorem gauge_eq_zero (hs : Absorbent ℝ s) (hb : Bornology.IsVonNBounded ℝ s) : gauge s x = 0 ↔ x = 0 := by refine ⟨fun h₀ ↦ by_contra fun (hne : x ≠ 0) ↦ ?_, fun h ↦ h.symm ▸ gauge_zero⟩ have : {x}ᶜ ∈ comap (gauge s) (𝓝 0) := comap_gauge_nhds_zero_le hs hb (isOpen_compl_singleton.mem_nhds hne.symm) rcases ((nhds_basis_zero_abs_lt _).comap _).mem_iff.1 this with ⟨r, hr₀, hr⟩ exact hr (by simpa [h₀]) rfl theorem gauge_pos (hs : Absorbent ℝ s) (hb : Bornology.IsVonNBounded ℝ s) : 0 < gauge s x ↔ x ≠ 0 := by simp only [(gauge_nonneg _).gt_iff_ne, Ne, gauge_eq_zero hs hb] end TopologicalSpace section ContinuousSMul variable [TopologicalSpace E] [ContinuousSMul ℝ E] open Filter in theorem interior_subset_gauge_lt_one (s : Set E) : interior s ⊆ { x | gauge s x < 1 } := by intro x hx have H₁ : Tendsto (fun r : ℝ ↦ r⁻¹ • x) (𝓝[<] 1) (𝓝 ((1 : ℝ)⁻¹ • x)) := ((tendsto_id.inv₀ one_ne_zero).smul tendsto_const_nhds).mono_left inf_le_left rw [inv_one, one_smul] at H₁ have H₂ : ∀ᶠ r in 𝓝[<] (1 : ℝ), x ∈ r • s ∧ 0 < r ∧ r < 1 := by filter_upwards [H₁ (mem_interior_iff_mem_nhds.1 hx), Ioo_mem_nhdsLT one_pos] with r h₁ h₂ exact ⟨(mem_smul_set_iff_inv_smul_mem₀ h₂.1.ne' _ _).2 h₁, h₂⟩ rcases H₂.exists with ⟨r, hxr, hr₀, hr₁⟩ exact (gauge_le_of_mem hr₀.le hxr).trans_lt hr₁ theorem gauge_lt_one_eq_self_of_isOpen (hs₁ : Convex ℝ s) (hs₀ : (0 : E) ∈ s) (hs₂ : IsOpen s) : { x | gauge s x < 1 } = s := by refine (gauge_lt_one_subset_self hs₁ ‹_› <| absorbent_nhds_zero <| hs₂.mem_nhds hs₀).antisymm ?_ convert interior_subset_gauge_lt_one s exact hs₂.interior_eq.symm theorem gauge_lt_one_of_mem_of_isOpen (hs₂ : IsOpen s) {x : E} (hx : x ∈ s) : gauge s x < 1 := interior_subset_gauge_lt_one s <| by rwa [hs₂.interior_eq] theorem gauge_lt_of_mem_smul (x : E) (ε : ℝ) (hε : 0 < ε) (hs₂ : IsOpen s) (hx : x ∈ ε • s) : gauge s x < ε := by have : ε⁻¹ • x ∈ s := by rwa [← mem_smul_set_iff_inv_smul_mem₀ hε.ne'] have h_gauge_lt := gauge_lt_one_of_mem_of_isOpen hs₂ this rwa [gauge_smul_of_nonneg (inv_nonneg.2 hε.le), smul_eq_mul, inv_mul_lt_iff₀ hε, mul_one] at h_gauge_lt theorem mem_closure_of_gauge_le_one (hc : Convex ℝ s) (hs₀ : 0 ∈ s) (ha : Absorbent ℝ s) (h : gauge s x ≤ 1) : x ∈ closure s := by have : ∀ᶠ r : ℝ in 𝓝[<] 1, r • x ∈ s := by filter_upwards [Ico_mem_nhdsLT one_pos] with r ⟨hr₀, hr₁⟩ apply gauge_lt_one_subset_self hc hs₀ ha rw [mem_setOf_eq, gauge_smul_of_nonneg hr₀] exact mul_lt_one_of_nonneg_of_lt_one_left hr₀ hr₁ h refine mem_closure_of_tendsto ?_ this exact Filter.Tendsto.mono_left (Continuous.tendsto' (by fun_prop) _ _ (one_smul _ _)) inf_le_left theorem mem_frontier_of_gauge_eq_one (hc : Convex ℝ s) (hs₀ : 0 ∈ s) (ha : Absorbent ℝ s) (h : gauge s x = 1) : x ∈ frontier s := ⟨mem_closure_of_gauge_le_one hc hs₀ ha h.le, fun h' ↦ (interior_subset_gauge_lt_one s h').out.ne h⟩ theorem tendsto_gauge_nhds_zero_nhdsGE (hs : s ∈ 𝓝 0) : Tendsto (gauge s) (𝓝 0) (𝓝[≥] 0) := by refine nhdsGE_basis_Icc.tendsto_right_iff.2 fun ε hε ↦ ?_ rw [← set_smul_mem_nhds_zero_iff hε.ne'] at hs filter_upwards [hs] with x hx exact ⟨gauge_nonneg _, gauge_le_of_mem hε.le hx⟩ @[deprecated (since := "2025-03-02")] alias tendsto_gauge_nhds_zero' := tendsto_gauge_nhds_zero_nhdsGE theorem tendsto_gauge_nhds_zero (hs : s ∈ 𝓝 0) : Tendsto (gauge s) (𝓝 0) (𝓝 0) := (tendsto_gauge_nhds_zero_nhdsGE hs).mono_right inf_le_left /-- If `s` is a neighborhood of the origin, then `gauge s` is continuous at the origin. See also `continuousAt_gauge`. -/ theorem continuousAt_gauge_zero (hs : s ∈ 𝓝 0) : ContinuousAt (gauge s) 0 := by rw [ContinuousAt, gauge_zero] exact tendsto_gauge_nhds_zero hs theorem comap_gauge_nhds_zero (hb : Bornology.IsVonNBounded ℝ s) (h₀ : s ∈ 𝓝 0) : comap (gauge s) (𝓝 0) = 𝓝 0 := (comap_gauge_nhds_zero_le (absorbent_nhds_zero h₀) hb).antisymm (tendsto_gauge_nhds_zero h₀).le_comap end ContinuousSMul section TopologicalVectorSpace open Filter variable [TopologicalSpace E] [IsTopologicalAddGroup E] [ContinuousSMul ℝ E] /-- If `s` is a convex neighborhood of the origin in a topological real vector space, then `gauge s` is continuous. If the ambient space is a normed space, then `gauge s` is Lipschitz continuous, see `Convex.lipschitz_gauge`. -/ theorem continuousAt_gauge (hc : Convex ℝ s) (hs₀ : s ∈ 𝓝 0) : ContinuousAt (gauge s) x := by have ha : Absorbent ℝ s := absorbent_nhds_zero hs₀ refine (nhds_basis_Icc_pos _).tendsto_right_iff.2 fun ε hε₀ ↦ ?_ rw [← map_add_left_nhds_zero, eventually_map] have : ε • s ∩ -(ε • s) ∈ 𝓝 0 := inter_mem ((set_smul_mem_nhds_zero_iff hε₀.ne').2 hs₀) (neg_mem_nhds_zero _ ((set_smul_mem_nhds_zero_iff hε₀.ne').2 hs₀)) filter_upwards [this] with y hy constructor · rw [sub_le_iff_le_add] calc gauge s x = gauge s (x + y + (-y)) := by simp _ ≤ gauge s (x + y) + gauge s (-y) := gauge_add_le hc ha _ _ _ ≤ gauge s (x + y) + ε := add_le_add_left (gauge_le_of_mem hε₀.le (mem_neg.1 hy.2)) _ · calc gauge s (x + y) ≤ gauge s x + gauge s y := gauge_add_le hc ha _ _ _ ≤ gauge s x + ε := add_le_add_left (gauge_le_of_mem hε₀.le hy.1) _
/-- If `s` is a convex neighborhood of the origin in a topological real vector space, then `gauge s` is continuous. If the ambient space is a normed space, then `gauge s` is Lipschitz continuous, see
Mathlib/Analysis/Convex/Gauge.lean
439
441
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Lie.Abelian import Mathlib.Algebra.Lie.BaseChange import Mathlib.Algebra.Lie.IdealOperations import Mathlib.Order.Hom.Basic import Mathlib.RingTheory.Flat.FaithfullyFlat.Basic /-! # Solvable Lie algebras Like groups, Lie algebras admit a natural concept of solvability. We define this here via the derived series and prove some related results. We also define the radical of a Lie algebra and prove that it is solvable when the Lie algebra is Noetherian. ## Main definitions * `LieAlgebra.derivedSeriesOfIdeal` * `LieAlgebra.derivedSeries` * `LieAlgebra.IsSolvable` * `LieAlgebra.isSolvableAdd` * `LieAlgebra.radical` * `LieAlgebra.radicalIsSolvable` * `LieAlgebra.derivedLengthOfIdeal` * `LieAlgebra.derivedLength` * `LieAlgebra.derivedAbelianOfIdeal` ## Tags lie algebra, derived series, derived length, solvable, radical -/ universe u v w w₁ w₂ variable (R : Type u) (L : Type v) (M : Type w) {L' : Type w₁} variable [CommRing R] [LieRing L] [LieAlgebra R L] [LieRing L'] [LieAlgebra R L'] variable (I J : LieIdeal R L) {f : L' →ₗ⁅R⁆ L} namespace LieAlgebra /-- A generalisation of the derived series of a Lie algebra, whose zeroth term is a specified ideal. It can be more convenient to work with this generalisation when considering the derived series of an ideal since it provides a type-theoretic expression of the fact that the terms of the ideal's derived series are also ideals of the enclosing algebra. See also `LieIdeal.derivedSeries_eq_derivedSeriesOfIdeal_comap` and `LieIdeal.derivedSeries_eq_derivedSeriesOfIdeal_map` below. -/ def derivedSeriesOfIdeal (k : ℕ) : LieIdeal R L → LieIdeal R L := (fun I => ⁅I, I⁆)^[k] @[simp] theorem derivedSeriesOfIdeal_zero : derivedSeriesOfIdeal R L 0 I = I := rfl @[simp] theorem derivedSeriesOfIdeal_succ (k : ℕ) : derivedSeriesOfIdeal R L (k + 1) I = ⁅derivedSeriesOfIdeal R L k I, derivedSeriesOfIdeal R L k I⁆ := Function.iterate_succ_apply' (fun I => ⁅I, I⁆) k I /-- The derived series of Lie ideals of a Lie algebra. -/ abbrev derivedSeries (k : ℕ) : LieIdeal R L := derivedSeriesOfIdeal R L k ⊤ theorem derivedSeries_def (k : ℕ) : derivedSeries R L k = derivedSeriesOfIdeal R L k ⊤ := rfl variable {R L} local notation "D" => derivedSeriesOfIdeal R L theorem derivedSeriesOfIdeal_add (k l : ℕ) : D (k + l) I = D k (D l I) := by induction k with | zero => rw [Nat.zero_add, derivedSeriesOfIdeal_zero] | succ k ih => rw [Nat.succ_add k l, derivedSeriesOfIdeal_succ, derivedSeriesOfIdeal_succ, ih] @[gcongr, mono] theorem derivedSeriesOfIdeal_le {I J : LieIdeal R L} {k l : ℕ} (h₁ : I ≤ J) (h₂ : l ≤ k) : D k I ≤ D l J := by revert l; induction' k with k ih <;> intro l h₂ · rw [le_zero_iff] at h₂; rw [h₂, derivedSeriesOfIdeal_zero]; exact h₁ · have h : l = k.succ ∨ l ≤ k := by rwa [le_iff_eq_or_lt, Nat.lt_succ_iff] at h₂ rcases h with h | h · rw [h, derivedSeriesOfIdeal_succ, derivedSeriesOfIdeal_succ] exact LieSubmodule.mono_lie (ih (le_refl k)) (ih (le_refl k)) · rw [derivedSeriesOfIdeal_succ]; exact le_trans (LieSubmodule.lie_le_left _ _) (ih h) theorem derivedSeriesOfIdeal_succ_le (k : ℕ) : D (k + 1) I ≤ D k I := derivedSeriesOfIdeal_le (le_refl I) k.le_succ theorem derivedSeriesOfIdeal_le_self (k : ℕ) : D k I ≤ I := derivedSeriesOfIdeal_le (le_refl I) (zero_le k) theorem derivedSeriesOfIdeal_mono {I J : LieIdeal R L} (h : I ≤ J) (k : ℕ) : D k I ≤ D k J := derivedSeriesOfIdeal_le h (le_refl k) theorem derivedSeriesOfIdeal_antitone {k l : ℕ} (h : l ≤ k) : D k I ≤ D l I := derivedSeriesOfIdeal_le (le_refl I) h theorem derivedSeriesOfIdeal_add_le_add (J : LieIdeal R L) (k l : ℕ) : D (k + l) (I + J) ≤ D k I + D l J := by let D₁ : LieIdeal R L →o LieIdeal R L := { toFun := fun I => ⁅I, I⁆ monotone' := fun I J h => LieSubmodule.mono_lie h h } have h₁ : ∀ I J : LieIdeal R L, D₁ (I ⊔ J) ≤ D₁ I ⊔ J := by simp [D₁, LieSubmodule.lie_le_right, LieSubmodule.lie_le_left, le_sup_of_le_right] rw [← D₁.iterate_sup_le_sup_iff] at h₁ exact h₁ k l I J theorem derivedSeries_of_bot_eq_bot (k : ℕ) : derivedSeriesOfIdeal R L k ⊥ = ⊥ := by
rw [eq_bot_iff]; exact derivedSeriesOfIdeal_le_self ⊥ k theorem abelian_iff_derived_one_eq_bot : IsLieAbelian I ↔ derivedSeriesOfIdeal R L 1 I = ⊥ := by rw [derivedSeriesOfIdeal_succ, derivedSeriesOfIdeal_zero, LieSubmodule.lie_abelian_iff_lie_self_eq_bot] theorem abelian_iff_derived_succ_eq_bot (I : LieIdeal R L) (k : ℕ) : IsLieAbelian (derivedSeriesOfIdeal R L k I) ↔ derivedSeriesOfIdeal R L (k + 1) I = ⊥ := by rw [add_comm, derivedSeriesOfIdeal_add I 1 k, abelian_iff_derived_one_eq_bot]
Mathlib/Algebra/Lie/Solvable.lean
116
124
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Alistair Tucker, Wen Yang -/ import Mathlib.Order.Interval.Set.Image import Mathlib.Order.CompleteLatticeIntervals import Mathlib.Topology.Order.DenselyOrdered import Mathlib.Topology.Order.Monotone import Mathlib.Topology.Connected.TotallyDisconnected /-! # Intermediate Value Theorem In this file we prove the Intermediate Value Theorem: if `f : α → β` is a function defined on a connected set `s` that takes both values `≤ a` and values `≥ a` on `s`, then it is equal to `a` at some point of `s`. We also prove that intervals in a dense conditionally complete order are preconnected and any preconnected set is an interval. Then we specialize IVT to functions continuous on intervals. ## Main results * `IsPreconnected_I??` : all intervals `I??` are preconnected, * `IsPreconnected.intermediate_value`, `intermediate_value_univ` : Intermediate Value Theorem for connected sets and connected spaces, respectively; * `intermediate_value_Icc`, `intermediate_value_Icc'`: Intermediate Value Theorem for functions on closed intervals. ### Miscellaneous facts * `IsClosed.Icc_subset_of_forall_mem_nhdsWithin` : “Continuous induction” principle; if `s ∩ [a, b]` is closed, `a ∈ s`, and for each `x ∈ [a, b) ∩ s` some of its right neighborhoods is included `s`, then `[a, b] ⊆ s`. * `IsClosed.Icc_subset_of_forall_exists_gt`, `IsClosed.mem_of_ge_of_forall_exists_gt` : two other versions of the “continuous induction” principle. * `ContinuousOn.StrictMonoOn_of_InjOn_Ioo` : Every continuous injective `f : (a, b) → δ` is strictly monotone or antitone (increasing or decreasing). ## Tags intermediate value theorem, connected space, connected set -/ open Filter OrderDual TopologicalSpace Function Set open scoped Topology Filter Interval universe u v /-! ### Intermediate value theorem on a (pre)connected space In this section we prove the following theorem (see `IsPreconnected.intermediate_value₂`): if `f` and `g` are two functions continuous on a preconnected set `s`, `f a ≤ g a` at some `a ∈ s` and `g b ≤ f b` at some `b ∈ s`, then `f c = g c` at some `c ∈ s`. We prove several versions of this statement, including the classical IVT that corresponds to a constant function `g`. -/ section variable {X : Type u} {α : Type v} [TopologicalSpace X] [LinearOrder α] [TopologicalSpace α] [OrderClosedTopology α] /-- Intermediate value theorem for two functions: if `f` and `g` are two continuous functions on a preconnected space and `f a ≤ g a` and `g b ≤ f b`, then for some `x` we have `f x = g x`. -/ theorem intermediate_value_univ₂ [PreconnectedSpace X] {a b : X} {f g : X → α} (hf : Continuous f) (hg : Continuous g) (ha : f a ≤ g a) (hb : g b ≤ f b) : ∃ x, f x = g x := by obtain ⟨x, _, hfg, hgf⟩ : (univ ∩ { x | f x ≤ g x ∧ g x ≤ f x }).Nonempty := isPreconnected_closed_iff.1 PreconnectedSpace.isPreconnected_univ _ _ (isClosed_le hf hg) (isClosed_le hg hf) (fun _ _ => le_total _ _) ⟨a, trivial, ha⟩ ⟨b, trivial, hb⟩ exact ⟨x, le_antisymm hfg hgf⟩ theorem intermediate_value_univ₂_eventually₁ [PreconnectedSpace X] {a : X} {l : Filter X} [NeBot l] {f g : X → α} (hf : Continuous f) (hg : Continuous g) (ha : f a ≤ g a) (he : g ≤ᶠ[l] f) : ∃ x, f x = g x := let ⟨_, h⟩ := he.exists; intermediate_value_univ₂ hf hg ha h theorem intermediate_value_univ₂_eventually₂ [PreconnectedSpace X] {l₁ l₂ : Filter X} [NeBot l₁] [NeBot l₂] {f g : X → α} (hf : Continuous f) (hg : Continuous g) (he₁ : f ≤ᶠ[l₁] g) (he₂ : g ≤ᶠ[l₂] f) : ∃ x, f x = g x := let ⟨_, h₁⟩ := he₁.exists let ⟨_, h₂⟩ := he₂.exists intermediate_value_univ₂ hf hg h₁ h₂ /-- Intermediate value theorem for two functions: if `f` and `g` are two functions continuous on a preconnected set `s` and for some `a b ∈ s` we have `f a ≤ g a` and `g b ≤ f b`, then for some `x ∈ s` we have `f x = g x`. -/ theorem IsPreconnected.intermediate_value₂ {s : Set X} (hs : IsPreconnected s) {a b : X} (ha : a ∈ s) (hb : b ∈ s) {f g : X → α} (hf : ContinuousOn f s) (hg : ContinuousOn g s) (ha' : f a ≤ g a) (hb' : g b ≤ f b) : ∃ x ∈ s, f x = g x := let ⟨x, hx⟩ := @intermediate_value_univ₂ s α _ _ _ _ (Subtype.preconnectedSpace hs) ⟨a, ha⟩ ⟨b, hb⟩ _ _ (continuousOn_iff_continuous_restrict.1 hf) (continuousOn_iff_continuous_restrict.1 hg) ha' hb' ⟨x, x.2, hx⟩ theorem IsPreconnected.intermediate_value₂_eventually₁ {s : Set X} (hs : IsPreconnected s) {a : X} {l : Filter X} (ha : a ∈ s) [NeBot l] (hl : l ≤ 𝓟 s) {f g : X → α} (hf : ContinuousOn f s) (hg : ContinuousOn g s) (ha' : f a ≤ g a) (he : g ≤ᶠ[l] f) : ∃ x ∈ s, f x = g x := by rw [continuousOn_iff_continuous_restrict] at hf hg obtain ⟨b, h⟩ := @intermediate_value_univ₂_eventually₁ _ _ _ _ _ _ (Subtype.preconnectedSpace hs) ⟨a, ha⟩ _ (comap_coe_neBot_of_le_principal hl) _ _ hf hg ha' (he.comap _) exact ⟨b, b.prop, h⟩ theorem IsPreconnected.intermediate_value₂_eventually₂ {s : Set X} (hs : IsPreconnected s) {l₁ l₂ : Filter X} [NeBot l₁] [NeBot l₂] (hl₁ : l₁ ≤ 𝓟 s) (hl₂ : l₂ ≤ 𝓟 s) {f g : X → α} (hf : ContinuousOn f s) (hg : ContinuousOn g s) (he₁ : f ≤ᶠ[l₁] g) (he₂ : g ≤ᶠ[l₂] f) : ∃ x ∈ s, f x = g x := by rw [continuousOn_iff_continuous_restrict] at hf hg obtain ⟨b, h⟩ := @intermediate_value_univ₂_eventually₂ _ _ _ _ _ _ (Subtype.preconnectedSpace hs) _ _ (comap_coe_neBot_of_le_principal hl₁) (comap_coe_neBot_of_le_principal hl₂) _ _ hf hg (he₁.comap _) (he₂.comap _) exact ⟨b, b.prop, h⟩ /-- **Intermediate Value Theorem** for continuous functions on connected sets. -/ theorem IsPreconnected.intermediate_value {s : Set X} (hs : IsPreconnected s) {a b : X} (ha : a ∈ s) (hb : b ∈ s) {f : X → α} (hf : ContinuousOn f s) : Icc (f a) (f b) ⊆ f '' s := fun _x hx => hs.intermediate_value₂ ha hb hf continuousOn_const hx.1 hx.2 theorem IsPreconnected.intermediate_value_Ico {s : Set X} (hs : IsPreconnected s) {a : X} {l : Filter X} (ha : a ∈ s) [NeBot l] (hl : l ≤ 𝓟 s) {f : X → α} (hf : ContinuousOn f s) {v : α} (ht : Tendsto f l (𝓝 v)) : Ico (f a) v ⊆ f '' s := fun _ h => hs.intermediate_value₂_eventually₁ ha hl hf continuousOn_const h.1 (ht.eventually_const_le h.2) theorem IsPreconnected.intermediate_value_Ioc {s : Set X} (hs : IsPreconnected s) {a : X} {l : Filter X} (ha : a ∈ s) [NeBot l] (hl : l ≤ 𝓟 s) {f : X → α} (hf : ContinuousOn f s) {v : α} (ht : Tendsto f l (𝓝 v)) : Ioc v (f a) ⊆ f '' s := fun _ h => (hs.intermediate_value₂_eventually₁ ha hl continuousOn_const hf h.2 (ht.eventually_le_const h.1)).imp fun _ h => h.imp_right Eq.symm theorem IsPreconnected.intermediate_value_Ioo {s : Set X} (hs : IsPreconnected s) {l₁ l₂ : Filter X} [NeBot l₁] [NeBot l₂] (hl₁ : l₁ ≤ 𝓟 s) (hl₂ : l₂ ≤ 𝓟 s) {f : X → α} (hf : ContinuousOn f s) {v₁ v₂ : α} (ht₁ : Tendsto f l₁ (𝓝 v₁)) (ht₂ : Tendsto f l₂ (𝓝 v₂)) : Ioo v₁ v₂ ⊆ f '' s := fun _ h => hs.intermediate_value₂_eventually₂ hl₁ hl₂ hf continuousOn_const (ht₁.eventually_le_const h.1) (ht₂.eventually_const_le h.2) theorem IsPreconnected.intermediate_value_Ici {s : Set X} (hs : IsPreconnected s) {a : X} {l : Filter X} (ha : a ∈ s) [NeBot l] (hl : l ≤ 𝓟 s) {f : X → α} (hf : ContinuousOn f s) (ht : Tendsto f l atTop) : Ici (f a) ⊆ f '' s := fun y h => hs.intermediate_value₂_eventually₁ ha hl hf continuousOn_const h (tendsto_atTop.1 ht y) theorem IsPreconnected.intermediate_value_Iic {s : Set X} (hs : IsPreconnected s) {a : X} {l : Filter X} (ha : a ∈ s) [NeBot l] (hl : l ≤ 𝓟 s) {f : X → α} (hf : ContinuousOn f s) (ht : Tendsto f l atBot) : Iic (f a) ⊆ f '' s := fun y h => (hs.intermediate_value₂_eventually₁ ha hl continuousOn_const hf h (tendsto_atBot.1 ht y)).imp fun _ h => h.imp_right Eq.symm theorem IsPreconnected.intermediate_value_Ioi {s : Set X} (hs : IsPreconnected s) {l₁ l₂ : Filter X} [NeBot l₁] [NeBot l₂] (hl₁ : l₁ ≤ 𝓟 s) (hl₂ : l₂ ≤ 𝓟 s) {f : X → α} (hf : ContinuousOn f s) {v : α} (ht₁ : Tendsto f l₁ (𝓝 v)) (ht₂ : Tendsto f l₂ atTop) : Ioi v ⊆ f '' s := fun y h => hs.intermediate_value₂_eventually₂ hl₁ hl₂ hf continuousOn_const (ht₁.eventually_le_const h) (ht₂.eventually_ge_atTop y) theorem IsPreconnected.intermediate_value_Iio {s : Set X} (hs : IsPreconnected s) {l₁ l₂ : Filter X} [NeBot l₁] [NeBot l₂] (hl₁ : l₁ ≤ 𝓟 s) (hl₂ : l₂ ≤ 𝓟 s) {f : X → α} (hf : ContinuousOn f s) {v : α} (ht₁ : Tendsto f l₁ atBot) (ht₂ : Tendsto f l₂ (𝓝 v)) : Iio v ⊆ f '' s := fun y h => hs.intermediate_value₂_eventually₂ hl₁ hl₂ hf continuousOn_const (ht₁.eventually_le_atBot y) (ht₂.eventually_const_le h) theorem IsPreconnected.intermediate_value_Iii {s : Set X} (hs : IsPreconnected s) {l₁ l₂ : Filter X} [NeBot l₁] [NeBot l₂] (hl₁ : l₁ ≤ 𝓟 s) (hl₂ : l₂ ≤ 𝓟 s) {f : X → α} (hf : ContinuousOn f s) (ht₁ : Tendsto f l₁ atBot) (ht₂ : Tendsto f l₂ atTop) : univ ⊆ f '' s := fun y _ => hs.intermediate_value₂_eventually₂ hl₁ hl₂ hf continuousOn_const (ht₁.eventually_le_atBot y) (ht₂.eventually_ge_atTop y) /-- **Intermediate Value Theorem** for continuous functions on connected spaces. -/ theorem intermediate_value_univ [PreconnectedSpace X] (a b : X) {f : X → α} (hf : Continuous f) : Icc (f a) (f b) ⊆ range f := fun _ hx => intermediate_value_univ₂ hf continuous_const hx.1 hx.2 /-- **Intermediate Value Theorem** for continuous functions on connected spaces. -/ theorem mem_range_of_exists_le_of_exists_ge [PreconnectedSpace X] {c : α} {f : X → α} (hf : Continuous f) (h₁ : ∃ a, f a ≤ c) (h₂ : ∃ b, c ≤ f b) : c ∈ range f := let ⟨a, ha⟩ := h₁; let ⟨b, hb⟩ := h₂; intermediate_value_univ a b hf ⟨ha, hb⟩ /-! ### (Pre)connected sets in a linear order In this section we prove the following results: * `IsPreconnected.ordConnected`: any preconnected set `s` in a linear order is `OrdConnected`, i.e. `a ∈ s` and `b ∈ s` imply `Icc a b ⊆ s`; * `IsPreconnected.mem_intervals`: any preconnected set `s` in a conditionally complete linear order is one of the intervals `Set.Icc`, `set.`Ico`, `set.Ioc`, `set.Ioo`, ``Set.Ici`, `Set.Iic`, `Set.Ioi`, `Set.Iio`; note that this is false for non-complete orders: e.g., in `ℝ \ {0}`, the set of positive numbers cannot be represented as `Set.Ioi _`. -/ /-- If a preconnected set contains endpoints of an interval, then it includes the whole interval. -/ theorem IsPreconnected.Icc_subset {s : Set α} (hs : IsPreconnected s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : Icc a b ⊆ s := by simpa only [image_id] using hs.intermediate_value ha hb continuousOn_id theorem IsPreconnected.ordConnected {s : Set α} (h : IsPreconnected s) : OrdConnected s := ⟨fun _ hx _ hy => h.Icc_subset hx hy⟩ /-- If a preconnected set contains endpoints of an interval, then it includes the whole interval. -/ theorem IsConnected.Icc_subset {s : Set α} (hs : IsConnected s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) : Icc a b ⊆ s := hs.2.Icc_subset ha hb /-- If preconnected set in a linear order space is unbounded below and above, then it is the whole space. -/ theorem IsPreconnected.eq_univ_of_unbounded {s : Set α} (hs : IsPreconnected s) (hb : ¬BddBelow s) (ha : ¬BddAbove s) : s = univ := by refine eq_univ_of_forall fun x => ?_ obtain ⟨y, ys, hy⟩ : ∃ y ∈ s, y < x := not_bddBelow_iff.1 hb x obtain ⟨z, zs, hz⟩ : ∃ z ∈ s, x < z := not_bddAbove_iff.1 ha x exact hs.Icc_subset ys zs ⟨le_of_lt hy, le_of_lt hz⟩ end variable {α : Type u} [ConditionallyCompleteLinearOrder α] [TopologicalSpace α] [OrderTopology α] /-- A bounded connected subset of a conditionally complete linear order includes the open interval `(Inf s, Sup s)`. -/ theorem IsConnected.Ioo_csInf_csSup_subset {s : Set α} (hs : IsConnected s) (hb : BddBelow s) (ha : BddAbove s) : Ioo (sInf s) (sSup s) ⊆ s := fun _x hx => let ⟨_y, ys, hy⟩ := (isGLB_lt_iff (isGLB_csInf hs.nonempty hb)).1 hx.1 let ⟨_z, zs, hz⟩ := (lt_isLUB_iff (isLUB_csSup hs.nonempty ha)).1 hx.2 hs.Icc_subset ys zs ⟨hy.le, hz.le⟩ theorem eq_Icc_csInf_csSup_of_connected_bdd_closed {s : Set α} (hc : IsConnected s) (hb : BddBelow s) (ha : BddAbove s) (hcl : IsClosed s) : s = Icc (sInf s) (sSup s) := (subset_Icc_csInf_csSup hb ha).antisymm <| hc.Icc_subset (hcl.csInf_mem hc.nonempty hb) (hcl.csSup_mem hc.nonempty ha) theorem IsPreconnected.Ioi_csInf_subset {s : Set α} (hs : IsPreconnected s) (hb : BddBelow s) (ha : ¬BddAbove s) : Ioi (sInf s) ⊆ s := fun x hx => have sne : s.Nonempty := nonempty_of_not_bddAbove ha let ⟨_y, ys, hy⟩ : ∃ y ∈ s, y < x := (isGLB_lt_iff (isGLB_csInf sne hb)).1 hx let ⟨_z, zs, hz⟩ : ∃ z ∈ s, x < z := not_bddAbove_iff.1 ha x hs.Icc_subset ys zs ⟨hy.le, hz.le⟩ theorem IsPreconnected.Iio_csSup_subset {s : Set α} (hs : IsPreconnected s) (hb : ¬BddBelow s) (ha : BddAbove s) : Iio (sSup s) ⊆ s := IsPreconnected.Ioi_csInf_subset (α := αᵒᵈ) hs ha hb /-- A preconnected set in a conditionally complete linear order is either one of the intervals `[Inf s, Sup s]`, `[Inf s, Sup s)`, `(Inf s, Sup s]`, `(Inf s, Sup s)`, `[Inf s, +∞)`, `(Inf s, +∞)`, `(-∞, Sup s]`, `(-∞, Sup s)`, `(-∞, +∞)`, or `∅`. The converse statement requires `α` to be densely ordered. -/ theorem IsPreconnected.mem_intervals {s : Set α} (hs : IsPreconnected s) : s ∈ ({Icc (sInf s) (sSup s), Ico (sInf s) (sSup s), Ioc (sInf s) (sSup s), Ioo (sInf s) (sSup s), Ici (sInf s), Ioi (sInf s), Iic (sSup s), Iio (sSup s), univ, ∅} : Set (Set α)) := by rcases s.eq_empty_or_nonempty with (rfl | hne) · apply_rules [Or.inr, mem_singleton] have hs' : IsConnected s := ⟨hne, hs⟩ by_cases hb : BddBelow s <;> by_cases ha : BddAbove s · refine mem_of_subset_of_mem ?_ <| mem_Icc_Ico_Ioc_Ioo_of_subset_of_subset (hs'.Ioo_csInf_csSup_subset hb ha) (subset_Icc_csInf_csSup hb ha) simp only [insert_subset_iff, mem_insert_iff, mem_singleton_iff, true_or, or_true, singleton_subset_iff, and_self] · refine Or.inr <| Or.inr <| Or.inr <| Or.inr ?_ rcases mem_Ici_Ioi_of_subset_of_subset (hs.Ioi_csInf_subset hb ha) fun x hx ↦ csInf_le hb hx with hs | hs · exact Or.inl hs · exact Or.inr (Or.inl hs) · iterate 6 apply Or.inr rcases mem_Iic_Iio_of_subset_of_subset (hs.Iio_csSup_subset hb ha) fun x hx ↦ le_csSup ha hx with hs | hs · exact Or.inl hs · exact Or.inr (Or.inl hs) · iterate 8 apply Or.inr exact Or.inl (hs.eq_univ_of_unbounded hb ha) /-- A preconnected set is either one of the intervals `Icc`, `Ico`, `Ioc`, `Ioo`, `Ici`, `Ioi`, `Iic`, `Iio`, or `univ`, or `∅`. The converse statement requires `α` to be densely ordered. Though one can represent `∅` as `(Inf ∅, Inf ∅)`, we include it into the list of possible cases to improve readability. -/ theorem setOf_isPreconnected_subset_of_ordered : { s : Set α | IsPreconnected s } ⊆ -- bounded intervals (range (uncurry Icc) ∪ range (uncurry Ico) ∪ range (uncurry Ioc) ∪ range (uncurry Ioo)) ∪ -- unbounded intervals and `univ` (range Ici ∪ range Ioi ∪ range Iic ∪ range Iio ∪ {univ, ∅}) := by intro s hs rcases hs.mem_intervals with (hs | hs | hs | hs | hs | hs | hs | hs | hs | hs) <;> rw [hs] <;> simp only [union_insert, union_singleton, mem_insert_iff, mem_union, mem_range, Prod.exists, uncurry_apply_pair, exists_apply_eq_apply, true_or, or_true, exists_apply_eq_apply2] /-! ### Intervals are connected In this section we prove that a closed interval (hence, any `OrdConnected` set) in a dense conditionally complete linear order is preconnected. -/ /-- A "continuous induction principle" for a closed interval: if a set `s` meets `[a, b]` on a closed subset, contains `a`, and the set `s ∩ [a, b)` has no maximal point, then `b ∈ s`. -/ theorem IsClosed.mem_of_ge_of_forall_exists_gt {a b : α} {s : Set α} (hs : IsClosed (s ∩ Icc a b)) (ha : a ∈ s) (hab : a ≤ b) (hgt : ∀ x ∈ s ∩ Ico a b, (s ∩ Ioc x b).Nonempty) : b ∈ s := by let S := s ∩ Icc a b replace ha : a ∈ S := ⟨ha, left_mem_Icc.2 hab⟩ have Sbd : BddAbove S := ⟨b, fun z hz => hz.2.2⟩ let c := sSup (s ∩ Icc a b) have c_mem : c ∈ S := hs.csSup_mem ⟨_, ha⟩ Sbd have c_le : c ≤ b := csSup_le ⟨_, ha⟩ fun x hx => hx.2.2 rcases eq_or_lt_of_le c_le with hc | hc · exact hc ▸ c_mem.1 exfalso rcases hgt c ⟨c_mem.1, c_mem.2.1, hc⟩ with ⟨x, xs, cx, xb⟩ exact not_lt_of_le (le_csSup Sbd ⟨xs, le_trans (le_csSup Sbd ha) (le_of_lt cx), xb⟩) cx /-- A "continuous induction principle" for a closed interval: if a set `s` meets `[a, b]` on a closed subset, contains `a`, and for any `a ≤ x < y ≤ b`, `x ∈ s`, the set `s ∩ (x, y]` is not empty, then `[a, b] ⊆ s`. -/ theorem IsClosed.Icc_subset_of_forall_exists_gt {a b : α} {s : Set α} (hs : IsClosed (s ∩ Icc a b)) (ha : a ∈ s) (hgt : ∀ x ∈ s ∩ Ico a b, ∀ y ∈ Ioi x, (s ∩ Ioc x y).Nonempty) : Icc a b ⊆ s := by intro y hy have : IsClosed (s ∩ Icc a y) := by suffices s ∩ Icc a y = s ∩ Icc a b ∩ Icc a y by rw [this] exact IsClosed.inter hs isClosed_Icc rw [inter_assoc] congr exact (inter_eq_self_of_subset_right <| Icc_subset_Icc_right hy.2).symm exact IsClosed.mem_of_ge_of_forall_exists_gt this ha hy.1 fun x hx => hgt x ⟨hx.1, Ico_subset_Ico_right hy.2 hx.2⟩ y hx.2.2 variable [DenselyOrdered α] {a b : α} /-- A "continuous induction principle" for a closed interval: if a set `s` meets `[a, b]` on a closed subset, contains `a`, and for any `x ∈ s ∩ [a, b)` the set `s` includes some open neighborhood of `x` within `(x, +∞)`, then `[a, b] ⊆ s`. -/ theorem IsClosed.Icc_subset_of_forall_mem_nhdsWithin {a b : α} {s : Set α} (hs : IsClosed (s ∩ Icc a b)) (ha : a ∈ s) (hgt : ∀ x ∈ s ∩ Ico a b, s ∈ 𝓝[>] x) : Icc a b ⊆ s := by apply hs.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxs, hxab⟩ y hyxb have : s ∩ Ioc x y ∈ 𝓝[>] x := inter_mem (hgt x ⟨hxs, hxab⟩) (Ioc_mem_nhdsGT hyxb) exact (nhdsGT_neBot_of_exists_gt ⟨b, hxab.2⟩).nonempty_of_mem this theorem isPreconnected_Icc_aux (x y : α) (s t : Set α) (hxy : x ≤ y) (hs : IsClosed s) (ht : IsClosed t) (hab : Icc a b ⊆ s ∪ t) (hx : x ∈ Icc a b ∩ s) (hy : y ∈ Icc a b ∩ t) : (Icc a b ∩ (s ∩ t)).Nonempty := by have xyab : Icc x y ⊆ Icc a b := Icc_subset_Icc hx.1.1 hy.1.2 by_contra hst suffices Icc x y ⊆ s from hst ⟨y, xyab <| right_mem_Icc.2 hxy, this <| right_mem_Icc.2 hxy, hy.2⟩ apply (IsClosed.inter hs isClosed_Icc).Icc_subset_of_forall_mem_nhdsWithin hx.2 rintro z ⟨zs, hz⟩ have zt : z ∈ tᶜ := fun zt => hst ⟨z, xyab <| Ico_subset_Icc_self hz, zs, zt⟩ have : tᶜ ∩ Ioc z y ∈ 𝓝[>] z := by rw [← nhdsWithin_Ioc_eq_nhdsGT hz.2] exact mem_nhdsWithin.2 ⟨tᶜ, ht.isOpen_compl, zt, Subset.rfl⟩ apply mem_of_superset this have : Ioc z y ⊆ s ∪ t := fun w hw => hab (xyab ⟨le_trans hz.1 (le_of_lt hw.1), hw.2⟩) exact fun w ⟨wt, wzy⟩ => (this wzy).elim id fun h => (wt h).elim /-- A closed interval in a densely ordered conditionally complete linear order is preconnected. -/ theorem isPreconnected_Icc : IsPreconnected (Icc a b) := isPreconnected_closed_iff.2 (by rintro s t hs ht hab ⟨x, hx⟩ ⟨y, hy⟩ -- This used to use `wlog`, but it was causing timeouts. rcases le_total x y with h | h · exact isPreconnected_Icc_aux x y s t h hs ht hab hx hy · rw [inter_comm s t] rw [union_comm s t] at hab exact isPreconnected_Icc_aux y x t s h ht hs hab hy hx)
theorem isPreconnected_uIcc : IsPreconnected ([[a, b]]) := isPreconnected_Icc theorem Set.OrdConnected.isPreconnected {s : Set α} (h : s.OrdConnected) : IsPreconnected s := isPreconnected_of_forall_pair fun x hx y hy => ⟨[[x, y]], h.uIcc_subset hx hy, left_mem_uIcc, right_mem_uIcc, isPreconnected_uIcc⟩ theorem isPreconnected_iff_ordConnected {s : Set α} : IsPreconnected s ↔ OrdConnected s :=
Mathlib/Topology/Order/IntermediateValue.lean
372
379
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Ring.Divisibility.Lemmas import Mathlib.Algebra.Lie.Nilpotent import Mathlib.Algebra.Lie.Engel import Mathlib.LinearAlgebra.Eigenspace.Pi import Mathlib.RingTheory.Artinian.Module import Mathlib.LinearAlgebra.Trace import Mathlib.LinearAlgebra.FreeModule.PID /-! # Weight spaces of Lie modules of nilpotent Lie algebras Just as a key tool when studying the behaviour of a linear operator is to decompose the space on which it acts into a sum of (generalised) eigenspaces, a key tool when studying a representation `M` of Lie algebra `L` is to decompose `M` into a sum of simultaneous eigenspaces of `x` as `x` ranges over `L`. These simultaneous generalised eigenspaces are known as the weight spaces of `M`. When `L` is nilpotent, it follows from the binomial theorem that weight spaces are Lie submodules. Basic definitions and properties of the above ideas are provided in this file. ## Main definitions * `LieModule.genWeightSpaceOf` * `LieModule.genWeightSpace` * `LieModule.Weight` * `LieModule.posFittingCompOf` * `LieModule.posFittingComp` * `LieModule.iSup_ucs_eq_genWeightSpace_zero` * `LieModule.iInf_lowerCentralSeries_eq_posFittingComp` * `LieModule.isCompl_genWeightSpace_zero_posFittingComp` * `LieModule.iSupIndep_genWeightSpace` * `LieModule.iSup_genWeightSpace_eq_top` ## References * [N. Bourbaki, *Lie Groups and Lie Algebras, Chapters 7--9*](bourbaki1975b) ## Tags lie character, eigenvalue, eigenspace, weight, weight vector, root, root vector -/ variable {K R L M : Type*} [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] namespace LieModule open Set Function TensorProduct LieModule variable (M) in /-- If `M` is a representation of a Lie algebra `L` and `χ : L → R` is a family of scalars, then `weightSpace M χ` is the intersection of the `χ x`-eigenspaces of the action of `x` on `M` as `x` ranges over `L`. -/ def weightSpace (χ : L → R) : LieSubmodule R L M where __ := ⨅ x : L, (toEnd R L M x).eigenspace (χ x) lie_mem {x m} hm := by simp_all [smul_comm (χ x)] lemma mem_weightSpace (χ : L → R) (m : M) : m ∈ weightSpace M χ ↔ ∀ x, ⁅x, m⁆ = χ x • m := by simp [weightSpace] section notation_genWeightSpaceOf /-- Until we define `LieModule.genWeightSpaceOf`, it is useful to have some notation as follows: -/ local notation3 "𝕎("M", " χ", " x")" => (toEnd R L M x).maxGenEigenspace χ /-- See also `bourbaki1975b` Chapter VII §1.1, Proposition 2 (ii). -/ protected theorem weight_vector_multiplication (M₁ M₂ M₃ : Type*) [AddCommGroup M₁] [Module R M₁] [LieRingModule L M₁] [LieModule R L M₁] [AddCommGroup M₂] [Module R M₂] [LieRingModule L M₂] [LieModule R L M₂] [AddCommGroup M₃] [Module R M₃] [LieRingModule L M₃] [LieModule R L M₃] (g : M₁ ⊗[R] M₂ →ₗ⁅R,L⁆ M₃) (χ₁ χ₂ : R) (x : L) : LinearMap.range ((g : M₁ ⊗[R] M₂ →ₗ[R] M₃).comp (mapIncl 𝕎(M₁, χ₁, x) 𝕎(M₂, χ₂, x))) ≤ 𝕎(M₃, χ₁ + χ₂, x) := by -- Unpack the statement of the goal. intro m₃ simp only [TensorProduct.mapIncl, LinearMap.mem_range, LinearMap.coe_comp, LieModuleHom.coe_toLinearMap, Function.comp_apply, Pi.add_apply, exists_imp, Module.End.mem_maxGenEigenspace] rintro t rfl -- Set up some notation. let F : Module.End R M₃ := toEnd R L M₃ x - (χ₁ + χ₂) • ↑1 -- The goal is linear in `t` so use induction to reduce to the case that `t` is a pure tensor. refine t.induction_on ?_ ?_ ?_ · use 0; simp only [LinearMap.map_zero, LieModuleHom.map_zero] swap · rintro t₁ t₂ ⟨k₁, hk₁⟩ ⟨k₂, hk₂⟩; use max k₁ k₂ simp only [LieModuleHom.map_add, LinearMap.map_add, Module.End.pow_map_zero_of_le (le_max_left k₁ k₂) hk₁, Module.End.pow_map_zero_of_le (le_max_right k₁ k₂) hk₂, add_zero] -- Now the main argument: pure tensors. rintro ⟨m₁, hm₁⟩ ⟨m₂, hm₂⟩ change ∃ k, (F ^ k) ((g : M₁ ⊗[R] M₂ →ₗ[R] M₃) (m₁ ⊗ₜ m₂)) = (0 : M₃) -- Eliminate `g` from the picture. let f₁ : Module.End R (M₁ ⊗[R] M₂) := (toEnd R L M₁ x - χ₁ • ↑1).rTensor M₂ let f₂ : Module.End R (M₁ ⊗[R] M₂) := (toEnd R L M₂ x - χ₂ • ↑1).lTensor M₁ have h_comm_square : F ∘ₗ ↑g = (g : M₁ ⊗[R] M₂ →ₗ[R] M₃).comp (f₁ + f₂) := by ext m₁ m₂ simp only [f₁, f₂, F, ← g.map_lie x (m₁ ⊗ₜ m₂), add_smul, sub_tmul, tmul_sub, smul_tmul, lie_tmul_right, tmul_smul, toEnd_apply_apply, LieModuleHom.map_smul, Module.End.one_apply, LieModuleHom.coe_toLinearMap, LinearMap.smul_apply, Function.comp_apply, LinearMap.coe_comp, LinearMap.rTensor_tmul, LieModuleHom.map_add, LinearMap.add_apply, LieModuleHom.map_sub, LinearMap.sub_apply, LinearMap.lTensor_tmul, AlgebraTensorModule.curry_apply, TensorProduct.curry_apply, LinearMap.toFun_eq_coe, LinearMap.coe_restrictScalars] abel rsuffices ⟨k, hk⟩ : ∃ k : ℕ, ((f₁ + f₂) ^ k) (m₁ ⊗ₜ m₂) = 0 · use k change (F ^ k) (g.toLinearMap (m₁ ⊗ₜ[R] m₂)) = 0 rw [← LinearMap.comp_apply, Module.End.commute_pow_left_of_commute h_comm_square, LinearMap.comp_apply, hk, LinearMap.map_zero] -- Unpack the information we have about `m₁`, `m₂`. simp only [Module.End.mem_maxGenEigenspace] at hm₁ hm₂ obtain ⟨k₁, hk₁⟩ := hm₁ obtain ⟨k₂, hk₂⟩ := hm₂ have hf₁ : (f₁ ^ k₁) (m₁ ⊗ₜ m₂) = 0 := by simp only [f₁, hk₁, zero_tmul, LinearMap.rTensor_tmul, LinearMap.rTensor_pow] have hf₂ : (f₂ ^ k₂) (m₁ ⊗ₜ m₂) = 0 := by simp only [f₂, hk₂, tmul_zero, LinearMap.lTensor_tmul, LinearMap.lTensor_pow] -- It's now just an application of the binomial theorem. use k₁ + k₂ - 1 have hf_comm : Commute f₁ f₂ := by ext m₁ m₂ simp only [f₁, f₂, Module.End.mul_apply, LinearMap.rTensor_tmul, LinearMap.lTensor_tmul, AlgebraTensorModule.curry_apply, LinearMap.toFun_eq_coe, LinearMap.lTensor_tmul, TensorProduct.curry_apply, LinearMap.coe_restrictScalars] rw [hf_comm.add_pow'] simp only [TensorProduct.mapIncl, Submodule.subtype_apply, Finset.sum_apply, Submodule.coe_mk, LinearMap.coeFn_sum, TensorProduct.map_tmul, LinearMap.smul_apply] -- The required sum is zero because each individual term is zero. apply Finset.sum_eq_zero rintro ⟨i, j⟩ hij -- Eliminate the binomial coefficients from the picture. suffices (f₁ ^ i * f₂ ^ j) (m₁ ⊗ₜ m₂) = 0 by rw [this]; apply smul_zero -- Finish off with appropriate case analysis. rcases Nat.le_or_le_of_add_eq_add_pred (Finset.mem_antidiagonal.mp hij) with hi | hj · rw [(hf_comm.pow_pow i j).eq, Module.End.mul_apply, Module.End.pow_map_zero_of_le hi hf₁, LinearMap.map_zero] · rw [Module.End.mul_apply, Module.End.pow_map_zero_of_le hj hf₂, LinearMap.map_zero] lemma lie_mem_maxGenEigenspace_toEnd {χ₁ χ₂ : R} {x y : L} {m : M} (hy : y ∈ 𝕎(L, χ₁, x)) (hm : m ∈ 𝕎(M, χ₂, x)) : ⁅y, m⁆ ∈ 𝕎(M, χ₁ + χ₂, x) := by apply LieModule.weight_vector_multiplication L M M (toModuleHom R L M) χ₁ χ₂ simp only [LieModuleHom.coe_toLinearMap, Function.comp_apply, LinearMap.coe_comp, TensorProduct.mapIncl, LinearMap.mem_range] use ⟨y, hy⟩ ⊗ₜ ⟨m, hm⟩ simp only [Submodule.subtype_apply, toModuleHom_apply, TensorProduct.map_tmul] variable (M) /-- If `M` is a representation of a nilpotent Lie algebra `L`, `χ` is a scalar, and `x : L`, then `genWeightSpaceOf M χ x` is the maximal generalized `χ`-eigenspace of the action of `x` on `M`. It is a Lie submodule because `L` is nilpotent. -/ def genWeightSpaceOf [LieRing.IsNilpotent L] (χ : R) (x : L) : LieSubmodule R L M := { 𝕎(M, χ, x) with lie_mem := by intro y m hm simp only [AddSubsemigroup.mem_carrier, AddSubmonoid.mem_toSubsemigroup, Submodule.mem_toAddSubmonoid] at hm ⊢ rw [← zero_add χ] exact lie_mem_maxGenEigenspace_toEnd (by simp) hm } end notation_genWeightSpaceOf variable (M) variable [LieRing.IsNilpotent L] theorem mem_genWeightSpaceOf (χ : R) (x : L) (m : M) : m ∈ genWeightSpaceOf M χ x ↔ ∃ k : ℕ, ((toEnd R L M x - χ • ↑1) ^ k) m = 0 := by simp [genWeightSpaceOf] theorem coe_genWeightSpaceOf_zero (x : L) : ↑(genWeightSpaceOf M (0 : R) x) = ⨆ k, LinearMap.ker (toEnd R L M x ^ k) := by simp [genWeightSpaceOf, ← Module.End.iSup_genEigenspace_eq] /-- If `M` is a representation of a nilpotent Lie algebra `L` and `χ : L → R` is a family of scalars, then `genWeightSpace M χ` is the intersection of the maximal generalized `χ x`-eigenspaces of the action of `x` on `M` as `x` ranges over `L`. It is a Lie submodule because `L` is nilpotent. -/ def genWeightSpace (χ : L → R) : LieSubmodule R L M := ⨅ x, genWeightSpaceOf M (χ x) x theorem mem_genWeightSpace (χ : L → R) (m : M) : m ∈ genWeightSpace M χ ↔ ∀ x, ∃ k : ℕ, ((toEnd R L M x - χ x • ↑1) ^ k) m = 0 := by simp [genWeightSpace, mem_genWeightSpaceOf] lemma genWeightSpace_le_genWeightSpaceOf (x : L) (χ : L → R) : genWeightSpace M χ ≤ genWeightSpaceOf M (χ x) x := iInf_le _ x lemma weightSpace_le_genWeightSpace (χ : L → R) : weightSpace M χ ≤ genWeightSpace M χ := by apply le_iInf intro x rw [← (LieSubmodule.toSubmodule_orderEmbedding R L M).le_iff_le] apply (iInf_le _ x).trans exact ((toEnd R L M x).genEigenspace (χ x)).monotone le_top variable (R L) in /-- A weight of a Lie module is a map `L → R` such that the corresponding weight space is non-trivial. -/ structure Weight where /-- The family of eigenvalues corresponding to a weight. -/ toFun : L → R genWeightSpace_ne_bot' : genWeightSpace M toFun ≠ ⊥ namespace Weight instance instFunLike : FunLike (Weight R L M) L R where coe χ := χ.1 coe_injective' χ₁ χ₂ h := by cases χ₁; cases χ₂; simp_all @[simp] lemma coe_weight_mk (χ : L → R) (h) : (↑(⟨χ, h⟩ : Weight R L M) : L → R) = χ := rfl lemma genWeightSpace_ne_bot (χ : Weight R L M) : genWeightSpace M χ ≠ ⊥ := χ.genWeightSpace_ne_bot' variable {M} @[ext] lemma ext {χ₁ χ₂ : Weight R L M} (h : ∀ x, χ₁ x = χ₂ x) : χ₁ = χ₂ := by obtain ⟨f₁, _⟩ := χ₁; obtain ⟨f₂, _⟩ := χ₂; aesop lemma ext_iff' {χ₁ χ₂ : Weight R L M} : (χ₁ : L → R) = χ₂ ↔ χ₁ = χ₂ := by simp lemma exists_ne_zero (χ : Weight R L M) : ∃ x ∈ genWeightSpace M χ, x ≠ 0 := by simpa [LieSubmodule.eq_bot_iff] using χ.genWeightSpace_ne_bot instance [Subsingleton M] : IsEmpty (Weight R L M) := ⟨fun h ↦ h.2 (Subsingleton.elim _ _)⟩ instance [Nontrivial (genWeightSpace M (0 : L → R))] : Zero (Weight R L M) := ⟨0, fun e ↦ not_nontrivial (⊥ : LieSubmodule R L M) (e ▸ ‹_›)⟩ @[simp] lemma coe_zero [Nontrivial (genWeightSpace M (0 : L → R))] : ((0 : Weight R L M) : L → R) = 0 := rfl lemma zero_apply [Nontrivial (genWeightSpace M (0 : L → R))] (x) : (0 : Weight R L M) x = 0 := rfl /-- The proposition that a weight of a Lie module is zero. We make this definition because we cannot define a `Zero (Weight R L M)` instance since the weight space of the zero function can be trivial. -/ def IsZero (χ : Weight R L M) := (χ : L → R) = 0 @[simp] lemma IsZero.eq {χ : Weight R L M} (hχ : χ.IsZero) : (χ : L → R) = 0 := hχ @[simp] lemma coe_eq_zero_iff (χ : Weight R L M) : (χ : L → R) = 0 ↔ χ.IsZero := Iff.rfl lemma isZero_iff_eq_zero [Nontrivial (genWeightSpace M (0 : L → R))] {χ : Weight R L M} : χ.IsZero ↔ χ = 0 := Weight.ext_iff' (χ₂ := 0) lemma isZero_zero [Nontrivial (genWeightSpace M (0 : L → R))] : IsZero (0 : Weight R L M) := rfl /-- The proposition that a weight of a Lie module is non-zero. -/ abbrev IsNonZero (χ : Weight R L M) := ¬ IsZero (χ : Weight R L M) lemma isNonZero_iff_ne_zero [Nontrivial (genWeightSpace M (0 : L → R))] {χ : Weight R L M} : χ.IsNonZero ↔ χ ≠ 0 := isZero_iff_eq_zero.not noncomputable instance : DecidablePred (IsNonZero (R := R) (L := L) (M := M)) := Classical.decPred _ variable (R L M) in /-- The set of weights is equivalent to a subtype. -/ def equivSetOf : Weight R L M ≃ {χ : L → R | genWeightSpace M χ ≠ ⊥} where toFun w := ⟨w.1, w.2⟩ invFun w := ⟨w.1, w.2⟩ left_inv w := by simp right_inv w := by simp lemma genWeightSpaceOf_ne_bot (χ : Weight R L M) (x : L) : genWeightSpaceOf M (χ x) x ≠ ⊥ := by have : ⨅ x, genWeightSpaceOf M (χ x) x ≠ ⊥ := χ.genWeightSpace_ne_bot contrapose! this rw [eq_bot_iff] exact le_of_le_of_eq (iInf_le _ _) this lemma hasEigenvalueAt (χ : Weight R L M) (x : L) : (toEnd R L M x).HasEigenvalue (χ x) := by obtain ⟨k : ℕ, hk : (toEnd R L M x).genEigenspace (χ x) k ≠ ⊥⟩ := by simpa [genWeightSpaceOf, ← Module.End.iSup_genEigenspace_eq] using χ.genWeightSpaceOf_ne_bot x exact Module.End.hasEigenvalue_of_hasGenEigenvalue hk lemma apply_eq_zero_of_isNilpotent [NoZeroSMulDivisors R M] [IsReduced R] (x : L) (h : _root_.IsNilpotent (toEnd R L M x)) (χ : Weight R L M) : χ x = 0 := ((χ.hasEigenvalueAt x).isNilpotent_of_isNilpotent h).eq_zero end Weight /-- See also the more useful form `LieModule.zero_genWeightSpace_eq_top_of_nilpotent`. -/ @[simp] theorem zero_genWeightSpace_eq_top_of_nilpotent' [IsNilpotent L M] : genWeightSpace M (0 : L → R) = ⊤ := by ext simp [genWeightSpace, genWeightSpaceOf] theorem coe_genWeightSpace_of_top (χ : L → R) : (genWeightSpace M (χ ∘ (⊤ : LieSubalgebra R L).incl) : Submodule R M) = genWeightSpace M χ := by ext m simp only [mem_genWeightSpace, LieSubmodule.mem_toSubmodule, Subtype.forall] apply forall_congr' simp @[simp] theorem zero_genWeightSpace_eq_top_of_nilpotent [IsNilpotent L M] : genWeightSpace M (0 : (⊤ : LieSubalgebra R L) → R) = ⊤ := by ext m simp only [mem_genWeightSpace, Pi.zero_apply, zero_smul, sub_zero, Subtype.forall, forall_true_left, LieSubalgebra.toEnd_mk, LieSubalgebra.mem_top, LieSubmodule.mem_top, iff_true] intro x obtain ⟨k, hk⟩ := exists_forall_pow_toEnd_eq_zero R L M exact ⟨k, by simp [hk x]⟩ theorem exists_genWeightSpace_le_ker_of_isNoetherian [IsNoetherian R M] (χ : L → R) (x : L) : ∃ k : ℕ, genWeightSpace M χ ≤ LinearMap.ker ((toEnd R L M x - algebraMap R _ (χ x)) ^ k) := by use (toEnd R L M x).maxGenEigenspaceIndex (χ x) intro m hm replace hm : m ∈ (toEnd R L M x).maxGenEigenspace (χ x) := genWeightSpace_le_genWeightSpaceOf M x χ hm rwa [Module.End.maxGenEigenspace_eq, Module.End.genEigenspace_nat] at hm variable (R) in theorem exists_genWeightSpace_zero_le_ker_of_isNoetherian [IsNoetherian R M] (x : L) : ∃ k : ℕ, genWeightSpace M (0 : L → R) ≤ LinearMap.ker (toEnd R L M x ^ k) := by simpa using exists_genWeightSpace_le_ker_of_isNoetherian M (0 : L → R) x lemma isNilpotent_toEnd_sub_algebraMap [IsNoetherian R M] (χ : L → R) (x : L) : _root_.IsNilpotent <| toEnd R L (genWeightSpace M χ) x - algebraMap R _ (χ x) := by have : toEnd R L (genWeightSpace M χ) x - algebraMap R _ (χ x) = (toEnd R L M x - algebraMap R _ (χ x)).restrict (fun m hm ↦ sub_mem (LieSubmodule.lie_mem _ hm) (Submodule.smul_mem _ _ hm)) := by rfl obtain ⟨k, hk⟩ := exists_genWeightSpace_le_ker_of_isNoetherian M χ x use k ext ⟨m, hm⟩ simp only [this, Module.End.pow_restrict _, LinearMap.zero_apply, ZeroMemClass.coe_zero, ZeroMemClass.coe_eq_zero] exact ZeroMemClass.coe_eq_zero.mp (hk hm) /-- A (nilpotent) Lie algebra acts nilpotently on the zero weight space of a Noetherian Lie module. -/ theorem isNilpotent_toEnd_genWeightSpace_zero [IsNoetherian R M] (x : L) : _root_.IsNilpotent <| toEnd R L (genWeightSpace M (0 : L → R)) x := by simpa using isNilpotent_toEnd_sub_algebraMap M (0 : L → R) x /-- By Engel's theorem, the zero weight space of a Noetherian Lie module is nilpotent. -/ instance [IsNoetherian R M] : IsNilpotent L (genWeightSpace M (0 : L → R)) := isNilpotent_iff_forall'.mpr <| isNilpotent_toEnd_genWeightSpace_zero M variable (R L) @[simp] lemma genWeightSpace_zero_normalizer_eq_self : (genWeightSpace M (0 : L → R)).normalizer = genWeightSpace M 0 := by refine le_antisymm ?_ (LieSubmodule.le_normalizer _) intro m hm rw [LieSubmodule.mem_normalizer] at hm simp only [mem_genWeightSpace, Pi.zero_apply, zero_smul, sub_zero] at hm ⊢ intro y obtain ⟨k, hk⟩ := hm y y use k + 1 simpa [pow_succ, Module.End.mul_eq_comp] lemma iSup_ucs_le_genWeightSpace_zero : ⨆ k, (⊥ : LieSubmodule R L M).ucs k ≤ genWeightSpace M (0 : L → R) := by simpa using LieSubmodule.ucs_le_of_normalizer_eq_self (genWeightSpace_zero_normalizer_eq_self R L M) /-- See also `LieModule.iInf_lowerCentralSeries_eq_posFittingComp`. -/ lemma iSup_ucs_eq_genWeightSpace_zero [IsNoetherian R M] : ⨆ k, (⊥ : LieSubmodule R L M).ucs k = genWeightSpace M (0 : L → R) := by obtain ⟨k, hk⟩ := (LieSubmodule.isNilpotent_iff_exists_self_le_ucs <| genWeightSpace M (0 : L → R)).mp inferInstance refine le_antisymm (iSup_ucs_le_genWeightSpace_zero R L M) (le_trans hk ?_) exact le_iSup (fun k ↦ (⊥ : LieSubmodule R L M).ucs k) k variable {L} /-- If `M` is a representation of a nilpotent Lie algebra `L`, and `x : L`, then `posFittingCompOf R M x` is the infimum of the decreasing system `range φₓ ⊇ range φₓ² ⊇ range φₓ³ ⊇ ⋯` where `φₓ : End R M := toEnd R L M x`. We call this the "positive Fitting component" because with appropriate assumptions (e.g., `R` is a field and `M` is finite-dimensional) `φₓ` induces the so-called Fitting decomposition: `M = M₀ ⊕ M₁` where `M₀ = genWeightSpaceOf M 0 x` and `M₁ = posFittingCompOf R M x`. It is a Lie submodule because `L` is nilpotent. -/ def posFittingCompOf (x : L) : LieSubmodule R L M := { toSubmodule := ⨅ k, LinearMap.range (toEnd R L M x ^ k) lie_mem := by set φ := toEnd R L M x intros y m hm simp only [AddSubsemigroup.mem_carrier, AddSubmonoid.mem_toSubsemigroup, Submodule.mem_toAddSubmonoid, Submodule.mem_iInf, LinearMap.mem_range] at hm ⊢ intro k obtain ⟨N, hN⟩ := LieAlgebra.nilpotent_ad_of_nilpotent_algebra R L obtain ⟨m, rfl⟩ := hm (N + k) let f₁ : Module.End R (L ⊗[R] M) := (LieAlgebra.ad R L x).rTensor M let f₂ : Module.End R (L ⊗[R] M) := φ.lTensor L replace hN : f₁ ^ N = 0 := by ext; simp [f₁, hN] have h₁ : Commute f₁ f₂ := by ext; simp [f₁, f₂] have h₂ : φ ∘ₗ toModuleHom R L M = toModuleHom R L M ∘ₗ (f₁ + f₂) := by ext; simp [φ, f₁, f₂] obtain ⟨q, hq⟩ := h₁.add_pow_dvd_pow_of_pow_eq_zero_right (N + k).le_succ hN use toModuleHom R L M (q (y ⊗ₜ m)) change (φ ^ k).comp ((toModuleHom R L M : L ⊗[R] M →ₗ[R] M)) _ = _ simp [φ, f₁, f₂, Module.End.commute_pow_left_of_commute h₂, LinearMap.comp_apply (g := (f₁ + f₂) ^ k), ← LinearMap.comp_apply (g := q), ← Module.End.mul_eq_comp, ← hq] } variable {M} in lemma mem_posFittingCompOf (x : L) (m : M) : m ∈ posFittingCompOf R M x ↔ ∀ (k : ℕ), ∃ n, (toEnd R L M x ^ k) n = m := by simp [posFittingCompOf] @[simp] lemma posFittingCompOf_le_lowerCentralSeries (x : L) (k : ℕ) : posFittingCompOf R M x ≤ lowerCentralSeries R L M k := by suffices ∀ m l, (toEnd R L M x ^ l) m ∈ lowerCentralSeries R L M l by intro m hm obtain ⟨n, rfl⟩ := (mem_posFittingCompOf R x m).mp hm k exact this n k intro m l induction l with | zero => simp | succ l ih => simp only [lowerCentralSeries_succ, pow_succ', Module.End.mul_apply] exact LieSubmodule.lie_mem_lie (LieSubmodule.mem_top x) ih @[simp] lemma posFittingCompOf_eq_bot_of_isNilpotent [IsNilpotent L M] (x : L) : posFittingCompOf R M x = ⊥ := by simp_rw [eq_bot_iff, ← iInf_lowerCentralSeries_eq_bot_of_isNilpotent, le_iInf_iff, posFittingCompOf_le_lowerCentralSeries, forall_const] variable (L)
/-- If `M` is a representation of a nilpotent Lie algebra `L` with coefficients in `R`, then `posFittingComp R L M` is the span of the positive Fitting components of the action of `x` on `M`, as `x` ranges over `L`. It is a Lie submodule because `L` is nilpotent. -/ def posFittingComp : LieSubmodule R L M := ⨆ x, posFittingCompOf R M x lemma mem_posFittingComp (m : M) : m ∈ posFittingComp R L M ↔ m ∈ ⨆ (x : L), posFittingCompOf R M x := by rfl lemma posFittingCompOf_le_posFittingComp (x : L) : posFittingCompOf R M x ≤ posFittingComp R L M := by rw [posFittingComp]; exact le_iSup (posFittingCompOf R M) x lemma posFittingComp_le_iInf_lowerCentralSeries : posFittingComp R L M ≤ ⨅ k, lowerCentralSeries R L M k := by simp [posFittingComp] /-- See also `LieModule.iSup_ucs_eq_genWeightSpace_zero`. -/
Mathlib/Algebra/Lie/Weights/Basic.lean
447
467
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Sébastien Gouëzel -/ import Mathlib.MeasureTheory.Measure.Haar.InnerProductSpace import Mathlib.MeasureTheory.Measure.Lebesgue.EqHaar import Mathlib.MeasureTheory.Integral.Bochner.Set /-! # Basic properties of Haar measures on real vector spaces -/ noncomputable section open Function Filter Inv MeasureTheory.Measure Module Set TopologicalSpace open scoped NNReal ENNReal Pointwise Topology namespace MeasureTheory namespace Measure /- The instance `MeasureTheory.Measure.IsAddHaarMeasure.noAtoms` applies in particular to show that an additive Haar measure on a nontrivial finite-dimensional real vector space has no atom. -/ example {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [Nontrivial E] [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] (μ : Measure E) [IsAddHaarMeasure μ] : NoAtoms μ := by infer_instance section LinearEquiv variable {𝕜 G H : Type*} [MeasurableSpace G] [MeasurableSpace H] [NontriviallyNormedField 𝕜] [TopologicalSpace G] [TopologicalSpace H] [AddCommGroup G] [AddCommGroup H] [IsTopologicalAddGroup G] [IsTopologicalAddGroup H] [Module 𝕜 G] [Module 𝕜 H] (μ : Measure G) [IsAddHaarMeasure μ] [BorelSpace G] [BorelSpace H] [CompleteSpace 𝕜] [T2Space G] [FiniteDimensional 𝕜 G] [ContinuousSMul 𝕜 G] [ContinuousSMul 𝕜 H] [T2Space H] instance MapLinearEquiv.isAddHaarMeasure (e : G ≃ₗ[𝕜] H) : IsAddHaarMeasure (μ.map e) := e.toContinuousLinearEquiv.isAddHaarMeasure_map _ end LinearEquiv section SeminormedGroup variable {G H : Type*} [MeasurableSpace G] [Group G] [TopologicalSpace G] [IsTopologicalGroup G] [BorelSpace G] [LocallyCompactSpace G] [MeasurableSpace H] [SeminormedGroup H] [OpensMeasurableSpace H] -- TODO: This could be streamlined by proving that inner regular measures always exist open Metric Bornology in @[to_additive] lemma _root_.MonoidHom.exists_nhds_isBounded (f : G →* H) (hf : Measurable f) (x : G) : ∃ s ∈ 𝓝 x, IsBounded (f '' s) := by let K : PositiveCompacts G := Classical.arbitrary _ obtain ⟨n, hn⟩ : ∃ n : ℕ, 0 < haar (interior K ∩ f ⁻¹' ball 1 n) := by by_contra! simp_rw [nonpos_iff_eq_zero, ← measure_iUnion_null_iff, ← inter_iUnion, ← preimage_iUnion, iUnion_ball_nat, preimage_univ, inter_univ] at this exact this.not_gt <| isOpen_interior.measure_pos _ K.interior_nonempty rw [← one_mul x, ← op_smul_eq_mul] refine ⟨_, smul_mem_nhds_smul _ <| div_mem_nhds_one_of_haar_pos_ne_top haar _ (isOpen_interior.measurableSet.inter <| hf measurableSet_ball) hn <| mt (measure_mono_top <| inter_subset_left.trans interior_subset) K.isCompact.measure_ne_top, ?_⟩ have : Bornology.IsBounded (f '' (interior K ∩ f ⁻¹' ball 1 n)) := isBounded_ball.subset <| (image_mono inter_subset_right).trans <| image_preimage_subset _ _ rw [image_op_smul_distrib, image_div] exact (this.div this).smul _ end SeminormedGroup /-- A Borel-measurable group hom from a locally compact normed group to a real normed space is continuous. -/ lemma AddMonoidHom.continuous_of_measurable {G H : Type*} [SeminormedAddCommGroup G] [MeasurableSpace G] [BorelSpace G] [LocallyCompactSpace G] [SeminormedAddCommGroup H] [MeasurableSpace H] [OpensMeasurableSpace H] [NormedSpace ℝ H] (f : G →+ H) (hf : Measurable f) : Continuous f := let ⟨_s, hs, hbdd⟩ := f.exists_nhds_isBounded hf 0; f.continuous_of_isBounded_nhds_zero hs hbdd variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] /-- The integral of `f (R • x)` with respect to an additive Haar measure is a multiple of the integral of `f`. The formula we give works even when `f` is not integrable or `R = 0` thanks to the convention that a non-integrable function has integral zero. -/ theorem integral_comp_smul (f : E → F) (R : ℝ) : ∫ x, f (R • x) ∂μ = |(R ^ finrank ℝ E)⁻¹| • ∫ x, f x ∂μ := by by_cases hF : CompleteSpace F; swap · simp [integral, hF] rcases eq_or_ne R 0 with (rfl | hR) · simp only [zero_smul, integral_const] rcases Nat.eq_zero_or_pos (finrank ℝ E) with (hE | hE) · have : Subsingleton E := finrank_zero_iff.1 hE have : f = fun _ => f 0 := by ext x; rw [Subsingleton.elim x 0] conv_rhs => rw [this]
simp only [hE, pow_zero, inv_one, abs_one, one_smul, integral_const] · have : Nontrivial E := finrank_pos_iff.1 hE simp [zero_pow hE.ne', measure_univ_of_isAddLeftInvariant, measureReal_def]
Mathlib/MeasureTheory/Measure/Haar/NormedSpace.lean
97
99
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Andrew Zipperer, Haitao Zhang, Minchao Wu, Yury Kudryashov -/ import Mathlib.Data.Set.Prod import Mathlib.Data.Set.Restrict /-! # Functions over sets This file contains basic results on the following predicates of functions and sets: * `Set.EqOn f₁ f₂ s` : functions `f₁` and `f₂` are equal at every point of `s`; * `Set.MapsTo f s t` : `f` sends every point of `s` to a point of `t`; * `Set.InjOn f s` : restriction of `f` to `s` is injective; * `Set.SurjOn f s t` : every point in `s` has a preimage in `s`; * `Set.BijOn f s t` : `f` is a bijection between `s` and `t`; * `Set.LeftInvOn f' f s` : for every `x ∈ s` we have `f' (f x) = x`; * `Set.RightInvOn f' f t` : for every `y ∈ t` we have `f (f' y) = y`; * `Set.InvOn f' f s t` : `f'` is a two-side inverse of `f` on `s` and `t`, i.e. we have `Set.LeftInvOn f' f s` and `Set.RightInvOn f' f t`. -/ variable {α β γ δ : Type*} {ι : Sort*} {π : α → Type*} open Equiv Equiv.Perm Function namespace Set /-! ### Equality on a set -/ section equality variable {s s₁ s₂ : Set α} {f₁ f₂ f₃ : α → β} {g : β → γ} {a : α} /-- This lemma exists for use by `aesop` as a forward rule. -/ @[aesop safe forward] lemma EqOn.eq_of_mem (h : s.EqOn f₁ f₂) (ha : a ∈ s) : f₁ a = f₂ a := h ha @[simp] theorem eqOn_empty (f₁ f₂ : α → β) : EqOn f₁ f₂ ∅ := fun _ => False.elim @[simp] theorem eqOn_singleton : Set.EqOn f₁ f₂ {a} ↔ f₁ a = f₂ a := by simp [Set.EqOn] @[simp] theorem eqOn_univ (f₁ f₂ : α → β) : EqOn f₁ f₂ univ ↔ f₁ = f₂ := by simp [EqOn, funext_iff] @[symm] theorem EqOn.symm (h : EqOn f₁ f₂ s) : EqOn f₂ f₁ s := fun _ hx => (h hx).symm theorem eqOn_comm : EqOn f₁ f₂ s ↔ EqOn f₂ f₁ s := ⟨EqOn.symm, EqOn.symm⟩ -- This can not be tagged as `@[refl]` with the current argument order. -- See note below at `EqOn.trans`. theorem eqOn_refl (f : α → β) (s : Set α) : EqOn f f s := fun _ _ => rfl -- Note: this was formerly tagged with `@[trans]`, and although the `trans` attribute accepted it -- the `trans` tactic could not use it. -- An update to the trans tactic coming in https://github.com/leanprover-community/mathlib4/pull/7014 will reject this attribute. -- It can be restored by changing the argument order from `EqOn f₁ f₂ s` to `EqOn s f₁ f₂`. -- This change will be made separately: [zulip](https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Reordering.20arguments.20of.20.60Set.2EEqOn.60/near/390467581). theorem EqOn.trans (h₁ : EqOn f₁ f₂ s) (h₂ : EqOn f₂ f₃ s) : EqOn f₁ f₃ s := fun _ hx => (h₁ hx).trans (h₂ hx) theorem EqOn.image_eq (heq : EqOn f₁ f₂ s) : f₁ '' s = f₂ '' s := image_congr heq /-- Variant of `EqOn.image_eq`, for one function being the identity. -/ theorem EqOn.image_eq_self {f : α → α} (h : Set.EqOn f id s) : f '' s = s := by rw [h.image_eq, image_id] theorem EqOn.inter_preimage_eq (heq : EqOn f₁ f₂ s) (t : Set β) : s ∩ f₁ ⁻¹' t = s ∩ f₂ ⁻¹' t := ext fun x => and_congr_right_iff.2 fun hx => by rw [mem_preimage, mem_preimage, heq hx] theorem EqOn.mono (hs : s₁ ⊆ s₂) (hf : EqOn f₁ f₂ s₂) : EqOn f₁ f₂ s₁ := fun _ hx => hf (hs hx) @[simp] theorem eqOn_union : EqOn f₁ f₂ (s₁ ∪ s₂) ↔ EqOn f₁ f₂ s₁ ∧ EqOn f₁ f₂ s₂ := forall₂_or_left theorem EqOn.union (h₁ : EqOn f₁ f₂ s₁) (h₂ : EqOn f₁ f₂ s₂) : EqOn f₁ f₂ (s₁ ∪ s₂) := eqOn_union.2 ⟨h₁, h₂⟩ theorem EqOn.comp_left (h : s.EqOn f₁ f₂) : s.EqOn (g ∘ f₁) (g ∘ f₂) := fun _ ha => congr_arg _ <| h ha @[simp] theorem eqOn_range {ι : Sort*} {f : ι → α} {g₁ g₂ : α → β} : EqOn g₁ g₂ (range f) ↔ g₁ ∘ f = g₂ ∘ f := forall_mem_range.trans <| funext_iff.symm alias ⟨EqOn.comp_eq, _⟩ := eqOn_range end equality variable {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {p : Set γ} {f f₁ f₂ : α → β} {g g₁ g₂ : β → γ} {f' f₁' f₂' : β → α} {g' : γ → β} {a : α} {b : β} section MapsTo theorem mapsTo' : MapsTo f s t ↔ f '' s ⊆ t := image_subset_iff.symm theorem mapsTo_prodMap_diagonal : MapsTo (Prod.map f f) (diagonal α) (diagonal β) := diagonal_subset_iff.2 fun _ => rfl @[deprecated (since := "2025-04-18")] alias mapsTo_prod_map_diagonal := mapsTo_prodMap_diagonal theorem MapsTo.subset_preimage (hf : MapsTo f s t) : s ⊆ f ⁻¹' t := hf theorem mapsTo_iff_subset_preimage : MapsTo f s t ↔ s ⊆ f ⁻¹' t := Iff.rfl @[simp] theorem mapsTo_singleton {x : α} : MapsTo f {x} t ↔ f x ∈ t := singleton_subset_iff theorem mapsTo_empty (f : α → β) (t : Set β) : MapsTo f ∅ t := empty_subset _ @[simp] theorem mapsTo_empty_iff : MapsTo f s ∅ ↔ s = ∅ := by simp [mapsTo', subset_empty_iff] /-- If `f` maps `s` to `t` and `s` is non-empty, `t` is non-empty. -/ theorem MapsTo.nonempty (h : MapsTo f s t) (hs : s.Nonempty) : t.Nonempty := (hs.image f).mono (mapsTo'.mp h) theorem MapsTo.image_subset (h : MapsTo f s t) : f '' s ⊆ t := mapsTo'.1 h theorem MapsTo.congr (h₁ : MapsTo f₁ s t) (h : EqOn f₁ f₂ s) : MapsTo f₂ s t := fun _ hx => h hx ▸ h₁ hx theorem EqOn.comp_right (hg : t.EqOn g₁ g₂) (hf : s.MapsTo f t) : s.EqOn (g₁ ∘ f) (g₂ ∘ f) := fun _ ha => hg <| hf ha theorem EqOn.mapsTo_iff (H : EqOn f₁ f₂ s) : MapsTo f₁ s t ↔ MapsTo f₂ s t := ⟨fun h => h.congr H, fun h => h.congr H.symm⟩ theorem MapsTo.comp (h₁ : MapsTo g t p) (h₂ : MapsTo f s t) : MapsTo (g ∘ f) s p := fun _ h => h₁ (h₂ h) theorem mapsTo_id (s : Set α) : MapsTo id s s := fun _ => id theorem MapsTo.iterate {f : α → α} {s : Set α} (h : MapsTo f s s) : ∀ n, MapsTo f^[n] s s | 0 => fun _ => id | n + 1 => (MapsTo.iterate h n).comp h theorem MapsTo.iterate_restrict {f : α → α} {s : Set α} (h : MapsTo f s s) (n : ℕ) : (h.restrict f s s)^[n] = (h.iterate n).restrict _ _ _ := by funext x rw [Subtype.ext_iff, MapsTo.val_restrict_apply] induction n generalizing x with | zero => rfl | succ n ihn => simp [Nat.iterate, ihn] lemma mapsTo_of_subsingleton' [Subsingleton β] (f : α → β) (h : s.Nonempty → t.Nonempty) : MapsTo f s t := fun a ha ↦ Subsingleton.mem_iff_nonempty.2 <| h ⟨a, ha⟩ lemma mapsTo_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : MapsTo f s s := mapsTo_of_subsingleton' _ id theorem MapsTo.mono (hf : MapsTo f s₁ t₁) (hs : s₂ ⊆ s₁) (ht : t₁ ⊆ t₂) : MapsTo f s₂ t₂ := fun _ hx => ht (hf <| hs hx) theorem MapsTo.mono_left (hf : MapsTo f s₁ t) (hs : s₂ ⊆ s₁) : MapsTo f s₂ t := fun _ hx => hf (hs hx) theorem MapsTo.mono_right (hf : MapsTo f s t₁) (ht : t₁ ⊆ t₂) : MapsTo f s t₂ := fun _ hx => ht (hf hx) theorem MapsTo.union_union (h₁ : MapsTo f s₁ t₁) (h₂ : MapsTo f s₂ t₂) : MapsTo f (s₁ ∪ s₂) (t₁ ∪ t₂) := fun _ hx => hx.elim (fun hx => Or.inl <| h₁ hx) fun hx => Or.inr <| h₂ hx theorem MapsTo.union (h₁ : MapsTo f s₁ t) (h₂ : MapsTo f s₂ t) : MapsTo f (s₁ ∪ s₂) t := union_self t ▸ h₁.union_union h₂ @[simp] theorem mapsTo_union : MapsTo f (s₁ ∪ s₂) t ↔ MapsTo f s₁ t ∧ MapsTo f s₂ t := ⟨fun h => ⟨h.mono subset_union_left (Subset.refl t), h.mono subset_union_right (Subset.refl t)⟩, fun h => h.1.union h.2⟩ theorem MapsTo.inter (h₁ : MapsTo f s t₁) (h₂ : MapsTo f s t₂) : MapsTo f s (t₁ ∩ t₂) := fun _ hx => ⟨h₁ hx, h₂ hx⟩ lemma MapsTo.insert (h : MapsTo f s t) (x : α) : MapsTo f (insert x s) (insert (f x) t) := by simpa [← singleton_union] using h.mono_right subset_union_right theorem MapsTo.inter_inter (h₁ : MapsTo f s₁ t₁) (h₂ : MapsTo f s₂ t₂) : MapsTo f (s₁ ∩ s₂) (t₁ ∩ t₂) := fun _ hx => ⟨h₁ hx.1, h₂ hx.2⟩ @[simp] theorem mapsTo_inter : MapsTo f s (t₁ ∩ t₂) ↔ MapsTo f s t₁ ∧ MapsTo f s t₂ := ⟨fun h => ⟨h.mono (Subset.refl s) inter_subset_left, h.mono (Subset.refl s) inter_subset_right⟩, fun h => h.1.inter h.2⟩ theorem mapsTo_univ (f : α → β) (s : Set α) : MapsTo f s univ := fun _ _ => trivial theorem mapsTo_range (f : α → β) (s : Set α) : MapsTo f s (range f) := (mapsTo_image f s).mono (Subset.refl s) (image_subset_range _ _) @[simp] theorem mapsTo_image_iff {f : α → β} {g : γ → α} {s : Set γ} {t : Set β} : MapsTo f (g '' s) t ↔ MapsTo (f ∘ g) s t := ⟨fun h c hc => h ⟨c, hc, rfl⟩, fun h _ ⟨_, hc⟩ => hc.2 ▸ h hc.1⟩ lemma MapsTo.comp_left (g : β → γ) (hf : MapsTo f s t) : MapsTo (g ∘ f) s (g '' t) := fun x hx ↦ ⟨f x, hf hx, rfl⟩ lemma MapsTo.comp_right {s : Set β} {t : Set γ} (hg : MapsTo g s t) (f : α → β) : MapsTo (g ∘ f) (f ⁻¹' s) t := fun _ hx ↦ hg hx @[simp] lemma mapsTo_univ_iff : MapsTo f univ t ↔ ∀ x, f x ∈ t := ⟨fun h _ => h (mem_univ _), fun h x _ => h x⟩ @[simp] lemma mapsTo_range_iff {g : ι → α} : MapsTo f (range g) t ↔ ∀ i, f (g i) ∈ t := forall_mem_range theorem MapsTo.mem_iff (h : MapsTo f s t) (hc : MapsTo f sᶜ tᶜ) {x} : f x ∈ t ↔ x ∈ s := ⟨fun ht => by_contra fun hs => hc hs ht, fun hx => h hx⟩ end MapsTo /-! ### Injectivity on a set -/ section injOn theorem Subsingleton.injOn (hs : s.Subsingleton) (f : α → β) : InjOn f s := fun _ hx _ hy _ => hs hx hy @[simp] theorem injOn_empty (f : α → β) : InjOn f ∅ := subsingleton_empty.injOn f @[simp] theorem injOn_singleton (f : α → β) (a : α) : InjOn f {a} := subsingleton_singleton.injOn f @[simp] lemma injOn_pair {b : α} : InjOn f {a, b} ↔ f a = f b → a = b := by unfold InjOn; aesop theorem InjOn.eq_iff {x y} (h : InjOn f s) (hx : x ∈ s) (hy : y ∈ s) : f x = f y ↔ x = y := ⟨h hx hy, fun h => h ▸ rfl⟩ theorem InjOn.ne_iff {x y} (h : InjOn f s) (hx : x ∈ s) (hy : y ∈ s) : f x ≠ f y ↔ x ≠ y := (h.eq_iff hx hy).not alias ⟨_, InjOn.ne⟩ := InjOn.ne_iff theorem InjOn.congr (h₁ : InjOn f₁ s) (h : EqOn f₁ f₂ s) : InjOn f₂ s := fun _ hx _ hy => h hx ▸ h hy ▸ h₁ hx hy theorem EqOn.injOn_iff (H : EqOn f₁ f₂ s) : InjOn f₁ s ↔ InjOn f₂ s := ⟨fun h => h.congr H, fun h => h.congr H.symm⟩ theorem InjOn.mono (h : s₁ ⊆ s₂) (ht : InjOn f s₂) : InjOn f s₁ := fun _ hx _ hy H => ht (h hx) (h hy) H theorem injOn_union (h : Disjoint s₁ s₂) : InjOn f (s₁ ∪ s₂) ↔ InjOn f s₁ ∧ InjOn f s₂ ∧ ∀ x ∈ s₁, ∀ y ∈ s₂, f x ≠ f y := by refine ⟨fun H => ⟨H.mono subset_union_left, H.mono subset_union_right, ?_⟩, ?_⟩ · intro x hx y hy hxy obtain rfl : x = y := H (Or.inl hx) (Or.inr hy) hxy exact h.le_bot ⟨hx, hy⟩ · rintro ⟨h₁, h₂, h₁₂⟩ rintro x (hx | hx) y (hy | hy) hxy exacts [h₁ hx hy hxy, (h₁₂ _ hx _ hy hxy).elim, (h₁₂ _ hy _ hx hxy.symm).elim, h₂ hx hy hxy] theorem injOn_insert {f : α → β} {s : Set α} {a : α} (has : a ∉ s) : Set.InjOn f (insert a s) ↔ Set.InjOn f s ∧ f a ∉ f '' s := by rw [← union_singleton, injOn_union (disjoint_singleton_right.2 has)] simp theorem injective_iff_injOn_univ : Injective f ↔ InjOn f univ := ⟨fun h _ _ _ _ hxy => h hxy, fun h _ _ heq => h trivial trivial heq⟩ theorem injOn_of_injective (h : Injective f) {s : Set α} : InjOn f s := fun _ _ _ _ hxy => h hxy alias _root_.Function.Injective.injOn := injOn_of_injective -- A specialization of `injOn_of_injective` for `Subtype.val`. theorem injOn_subtype_val {s : Set { x // p x }} : Set.InjOn Subtype.val s := Subtype.coe_injective.injOn lemma injOn_id (s : Set α) : InjOn id s := injective_id.injOn theorem InjOn.comp (hg : InjOn g t) (hf : InjOn f s) (h : MapsTo f s t) : InjOn (g ∘ f) s := fun _ hx _ hy heq => hf hx hy <| hg (h hx) (h hy) heq lemma InjOn.of_comp (h : InjOn (g ∘ f) s) : InjOn f s := fun _ hx _ hy heq ↦ h hx hy (by simp [heq]) lemma InjOn.image_of_comp (h : InjOn (g ∘ f) s) : InjOn g (f '' s) := forall_mem_image.2 fun _x hx ↦ forall_mem_image.2 fun _y hy heq ↦ congr_arg f <| h hx hy heq lemma InjOn.comp_iff (hf : InjOn f s) : InjOn (g ∘ f) s ↔ InjOn g (f '' s) := ⟨image_of_comp, fun h ↦ InjOn.comp h hf <| mapsTo_image f s⟩ lemma InjOn.iterate {f : α → α} {s : Set α} (h : InjOn f s) (hf : MapsTo f s s) : ∀ n, InjOn f^[n] s | 0 => injOn_id _ | (n + 1) => (h.iterate hf n).comp h hf lemma injOn_of_subsingleton [Subsingleton α] (f : α → β) (s : Set α) : InjOn f s := (injective_of_subsingleton _).injOn theorem _root_.Function.Injective.injOn_range (h : Injective (g ∘ f)) : InjOn g (range f) := by rintro _ ⟨x, rfl⟩ _ ⟨y, rfl⟩ H exact congr_arg f (h H) theorem _root_.Set.InjOn.injective_iff (s : Set β) (h : InjOn g s) (hs : range f ⊆ s) : Injective (g ∘ f) ↔ Injective f := ⟨(·.of_comp), fun h _ ↦ by aesop⟩ theorem exists_injOn_iff_injective [Nonempty β] : (∃ f : α → β, InjOn f s) ↔ ∃ f : s → β, Injective f := ⟨fun ⟨_, hf⟩ => ⟨_, hf.injective⟩, fun ⟨f, hf⟩ => by lift f to α → β using trivial exact ⟨f, injOn_iff_injective.2 hf⟩⟩ theorem injOn_preimage {B : Set (Set β)} (hB : B ⊆ 𝒫 range f) : InjOn (preimage f) B := fun _ hs _ ht hst => (preimage_eq_preimage' (hB hs) (hB ht)).1 hst theorem InjOn.mem_of_mem_image {x} (hf : InjOn f s) (hs : s₁ ⊆ s) (h : x ∈ s) (h₁ : f x ∈ f '' s₁) : x ∈ s₁ := let ⟨_, h', Eq⟩ := h₁ hf (hs h') h Eq ▸ h' theorem InjOn.mem_image_iff {x} (hf : InjOn f s) (hs : s₁ ⊆ s) (hx : x ∈ s) : f x ∈ f '' s₁ ↔ x ∈ s₁ := ⟨hf.mem_of_mem_image hs hx, mem_image_of_mem f⟩ theorem InjOn.preimage_image_inter (hf : InjOn f s) (hs : s₁ ⊆ s) : f ⁻¹' (f '' s₁) ∩ s = s₁ := ext fun _ => ⟨fun ⟨h₁, h₂⟩ => hf.mem_of_mem_image hs h₂ h₁, fun h => ⟨mem_image_of_mem _ h, hs h⟩⟩ theorem EqOn.cancel_left (h : s.EqOn (g ∘ f₁) (g ∘ f₂)) (hg : t.InjOn g) (hf₁ : s.MapsTo f₁ t) (hf₂ : s.MapsTo f₂ t) : s.EqOn f₁ f₂ := fun _ ha => hg (hf₁ ha) (hf₂ ha) (h ha) theorem InjOn.cancel_left (hg : t.InjOn g) (hf₁ : s.MapsTo f₁ t) (hf₂ : s.MapsTo f₂ t) : s.EqOn (g ∘ f₁) (g ∘ f₂) ↔ s.EqOn f₁ f₂ := ⟨fun h => h.cancel_left hg hf₁ hf₂, EqOn.comp_left⟩ lemma InjOn.image_inter {s t u : Set α} (hf : u.InjOn f) (hs : s ⊆ u) (ht : t ⊆ u) : f '' (s ∩ t) = f '' s ∩ f '' t := by apply Subset.antisymm (image_inter_subset _ _ _) intro x ⟨⟨y, ys, hy⟩, ⟨z, zt, hz⟩⟩ have : y = z := by apply hf (hs ys) (ht zt) rwa [← hz] at hy rw [← this] at zt exact ⟨y, ⟨ys, zt⟩, hy⟩ lemma InjOn.image (h : s.InjOn f) : s.powerset.InjOn (image f) := fun s₁ hs₁ s₂ hs₂ h' ↦ by rw [← h.preimage_image_inter hs₁, h', h.preimage_image_inter hs₂] theorem InjOn.image_eq_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) : f '' s₁ = f '' s₂ ↔ s₁ = s₂ := h.image.eq_iff h₁ h₂ lemma InjOn.image_subset_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) : f '' s₁ ⊆ f '' s₂ ↔ s₁ ⊆ s₂ := by refine ⟨fun h' ↦ ?_, image_subset _⟩ rw [← h.preimage_image_inter h₁, ← h.preimage_image_inter h₂] exact inter_subset_inter_left _ (preimage_mono h') lemma InjOn.image_ssubset_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) : f '' s₁ ⊂ f '' s₂ ↔ s₁ ⊂ s₂ := by simp_rw [ssubset_def, h.image_subset_image_iff h₁ h₂, h.image_subset_image_iff h₂ h₁] -- TODO: can this move to a better place? theorem _root_.Disjoint.image {s t u : Set α} {f : α → β} (h : Disjoint s t) (hf : u.InjOn f) (hs : s ⊆ u) (ht : t ⊆ u) : Disjoint (f '' s) (f '' t) := by rw [disjoint_iff_inter_eq_empty] at h ⊢ rw [← hf.image_inter hs ht, h, image_empty] lemma InjOn.image_diff {t : Set α} (h : s.InjOn f) : f '' (s \ t) = f '' s \ f '' (s ∩ t) := by refine subset_antisymm (subset_diff.2 ⟨image_subset f diff_subset, ?_⟩) (diff_subset_iff.2 (by rw [← image_union, inter_union_diff])) exact Disjoint.image disjoint_sdiff_inter h diff_subset inter_subset_left lemma InjOn.image_diff_subset {f : α → β} {t : Set α} (h : InjOn f s) (hst : t ⊆ s) : f '' (s \ t) = f '' s \ f '' t := by rw [h.image_diff, inter_eq_self_of_subset_right hst] alias image_diff_of_injOn := InjOn.image_diff_subset theorem InjOn.imageFactorization_injective (h : InjOn f s) : Injective (s.imageFactorization f) := fun ⟨x, hx⟩ ⟨y, hy⟩ h' ↦ by simpa [imageFactorization, h.eq_iff hx hy] using h' @[simp] theorem imageFactorization_injective_iff : Injective (s.imageFactorization f) ↔ InjOn f s := ⟨fun h x hx y hy _ ↦ by simpa using @h ⟨x, hx⟩ ⟨y, hy⟩ (by simpa [imageFactorization]), InjOn.imageFactorization_injective⟩ end injOn section graphOn variable {x : α × β} lemma graphOn_univ_inj {g : α → β} : univ.graphOn f = univ.graphOn g ↔ f = g := by simp lemma graphOn_univ_injective : Injective (univ.graphOn : (α → β) → Set (α × β)) := fun _f _g ↦ graphOn_univ_inj.1 lemma exists_eq_graphOn_image_fst [Nonempty β] {s : Set (α × β)} : (∃ f : α → β, s = graphOn f (Prod.fst '' s)) ↔ InjOn Prod.fst s := by refine ⟨?_, fun h ↦ ?_⟩ · rintro ⟨f, hf⟩ rw [hf] exact InjOn.image_of_comp <| injOn_id _ · have : ∀ x ∈ Prod.fst '' s, ∃ y, (x, y) ∈ s := forall_mem_image.2 fun (x, y) h ↦ ⟨y, h⟩ choose! f hf using this rw [forall_mem_image] at hf use f rw [graphOn, image_image, EqOn.image_eq_self] exact fun x hx ↦ h (hf hx) hx rfl lemma exists_eq_graphOn [Nonempty β] {s : Set (α × β)} : (∃ f t, s = graphOn f t) ↔ InjOn Prod.fst s := .trans ⟨fun ⟨f, t, hs⟩ ↦ ⟨f, by rw [hs, image_fst_graphOn]⟩, fun ⟨f, hf⟩ ↦ ⟨f, _, hf⟩⟩ exists_eq_graphOn_image_fst end graphOn /-! ### Surjectivity on a set -/ section surjOn theorem SurjOn.subset_range (h : SurjOn f s t) : t ⊆ range f := Subset.trans h <| image_subset_range f s theorem surjOn_iff_exists_map_subtype : SurjOn f s t ↔ ∃ (t' : Set β) (g : s → t'), t ⊆ t' ∧ Surjective g ∧ ∀ x : s, f x = g x := ⟨fun h => ⟨_, (mapsTo_image f s).restrict f s _, h, surjective_mapsTo_image_restrict _ _, fun _ => rfl⟩, fun ⟨t', g, htt', hg, hfg⟩ y hy => let ⟨x, hx⟩ := hg ⟨y, htt' hy⟩ ⟨x, x.2, by rw [hfg, hx, Subtype.coe_mk]⟩⟩ theorem surjOn_empty (f : α → β) (s : Set α) : SurjOn f s ∅ := empty_subset _ @[simp] theorem surjOn_empty_iff : SurjOn f ∅ t ↔ t = ∅ := by simp [SurjOn, subset_empty_iff] @[simp] lemma surjOn_singleton : SurjOn f s {b} ↔ b ∈ f '' s := singleton_subset_iff theorem surjOn_image (f : α → β) (s : Set α) : SurjOn f s (f '' s) := Subset.rfl theorem SurjOn.comap_nonempty (h : SurjOn f s t) (ht : t.Nonempty) : s.Nonempty := (ht.mono h).of_image theorem SurjOn.congr (h : SurjOn f₁ s t) (H : EqOn f₁ f₂ s) : SurjOn f₂ s t := by rwa [SurjOn, ← H.image_eq] theorem EqOn.surjOn_iff (h : EqOn f₁ f₂ s) : SurjOn f₁ s t ↔ SurjOn f₂ s t := ⟨fun H => H.congr h, fun H => H.congr h.symm⟩ theorem SurjOn.mono (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) (hf : SurjOn f s₁ t₂) : SurjOn f s₂ t₁ := Subset.trans ht <| Subset.trans hf <| image_subset _ hs theorem SurjOn.union (h₁ : SurjOn f s t₁) (h₂ : SurjOn f s t₂) : SurjOn f s (t₁ ∪ t₂) := fun _ hx => hx.elim (fun hx => h₁ hx) fun hx => h₂ hx theorem SurjOn.union_union (h₁ : SurjOn f s₁ t₁) (h₂ : SurjOn f s₂ t₂) : SurjOn f (s₁ ∪ s₂) (t₁ ∪ t₂) := (h₁.mono subset_union_left (Subset.refl _)).union (h₂.mono subset_union_right (Subset.refl _)) theorem SurjOn.inter_inter (h₁ : SurjOn f s₁ t₁) (h₂ : SurjOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) : SurjOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := by intro y hy rcases h₁ hy.1 with ⟨x₁, hx₁, rfl⟩ rcases h₂ hy.2 with ⟨x₂, hx₂, heq⟩ obtain rfl : x₁ = x₂ := h (Or.inl hx₁) (Or.inr hx₂) heq.symm exact mem_image_of_mem f ⟨hx₁, hx₂⟩ theorem SurjOn.inter (h₁ : SurjOn f s₁ t) (h₂ : SurjOn f s₂ t) (h : InjOn f (s₁ ∪ s₂)) : SurjOn f (s₁ ∩ s₂) t := inter_self t ▸ h₁.inter_inter h₂ h lemma surjOn_id (s : Set α) : SurjOn id s s := by simp [SurjOn] theorem SurjOn.comp (hg : SurjOn g t p) (hf : SurjOn f s t) : SurjOn (g ∘ f) s p := Subset.trans hg <| Subset.trans (image_subset g hf) <| image_comp g f s ▸ Subset.refl _ lemma SurjOn.of_comp (h : SurjOn (g ∘ f) s p) (hr : MapsTo f s t) : SurjOn g t p := by intro z hz obtain ⟨x, hx, rfl⟩ := h hz exact ⟨f x, hr hx, rfl⟩ lemma surjOn_comp_iff : SurjOn (g ∘ f) s p ↔ SurjOn g (f '' s) p := ⟨fun h ↦ h.of_comp <| mapsTo_image f s, fun h ↦ h.comp <| surjOn_image _ _⟩ lemma SurjOn.iterate {f : α → α} {s : Set α} (h : SurjOn f s s) : ∀ n, SurjOn f^[n] s s | 0 => surjOn_id _ | (n + 1) => (h.iterate n).comp h lemma SurjOn.comp_left (hf : SurjOn f s t) (g : β → γ) : SurjOn (g ∘ f) s (g '' t) := by rw [SurjOn, image_comp g f]; exact image_subset _ hf lemma SurjOn.comp_right {s : Set β} {t : Set γ} (hf : Surjective f) (hg : SurjOn g s t) : SurjOn (g ∘ f) (f ⁻¹' s) t := by rwa [SurjOn, image_comp g f, image_preimage_eq _ hf] lemma surjOn_of_subsingleton' [Subsingleton β] (f : α → β) (h : t.Nonempty → s.Nonempty) : SurjOn f s t := fun _ ha ↦ Subsingleton.mem_iff_nonempty.2 <| (h ⟨_, ha⟩).image _ lemma surjOn_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : SurjOn f s s := surjOn_of_subsingleton' _ id theorem surjective_iff_surjOn_univ : Surjective f ↔ SurjOn f univ univ := by simp [Surjective, SurjOn, subset_def] theorem SurjOn.image_eq_of_mapsTo (h₁ : SurjOn f s t) (h₂ : MapsTo f s t) : f '' s = t := eq_of_subset_of_subset h₂.image_subset h₁ theorem image_eq_iff_surjOn_mapsTo : f '' s = t ↔ s.SurjOn f t ∧ s.MapsTo f t := by refine ⟨?_, fun h => h.1.image_eq_of_mapsTo h.2⟩ rintro rfl exact ⟨s.surjOn_image f, s.mapsTo_image f⟩ lemma SurjOn.image_preimage (h : Set.SurjOn f s t) (ht : t₁ ⊆ t) : f '' (f ⁻¹' t₁) = t₁ := image_preimage_eq_iff.2 fun _ hx ↦ mem_range_of_mem_image f s <| h <| ht hx theorem SurjOn.mapsTo_compl (h : SurjOn f s t) (h' : Injective f) : MapsTo f sᶜ tᶜ := fun _ hs ht => let ⟨_, hx', HEq⟩ := h ht hs <| h' HEq ▸ hx' theorem MapsTo.surjOn_compl (h : MapsTo f s t) (h' : Surjective f) : SurjOn f sᶜ tᶜ := h'.forall.2 fun _ ht => (mem_image_of_mem _) fun hs => ht (h hs) theorem EqOn.cancel_right (hf : s.EqOn (g₁ ∘ f) (g₂ ∘ f)) (hf' : s.SurjOn f t) : t.EqOn g₁ g₂ := by intro b hb obtain ⟨a, ha, rfl⟩ := hf' hb exact hf ha theorem SurjOn.cancel_right (hf : s.SurjOn f t) (hf' : s.MapsTo f t) : s.EqOn (g₁ ∘ f) (g₂ ∘ f) ↔ t.EqOn g₁ g₂ := ⟨fun h => h.cancel_right hf, fun h => h.comp_right hf'⟩ theorem eqOn_comp_right_iff : s.EqOn (g₁ ∘ f) (g₂ ∘ f) ↔ (f '' s).EqOn g₁ g₂ := (s.surjOn_image f).cancel_right <| s.mapsTo_image f theorem SurjOn.forall {p : β → Prop} (hf : s.SurjOn f t) (hf' : s.MapsTo f t) : (∀ y ∈ t, p y) ↔ (∀ x ∈ s, p (f x)) := ⟨fun H x hx ↦ H (f x) (hf' hx), fun H _y hy ↦ let ⟨x, hx, hxy⟩ := hf hy; hxy ▸ H x hx⟩ end surjOn /-! ### Bijectivity -/ section bijOn theorem BijOn.mapsTo (h : BijOn f s t) : MapsTo f s t := h.left theorem BijOn.injOn (h : BijOn f s t) : InjOn f s := h.right.left theorem BijOn.surjOn (h : BijOn f s t) : SurjOn f s t := h.right.right theorem BijOn.mk (h₁ : MapsTo f s t) (h₂ : InjOn f s) (h₃ : SurjOn f s t) : BijOn f s t := ⟨h₁, h₂, h₃⟩ theorem bijOn_empty (f : α → β) : BijOn f ∅ ∅ := ⟨mapsTo_empty f ∅, injOn_empty f, surjOn_empty f ∅⟩ @[simp] theorem bijOn_empty_iff_left : BijOn f s ∅ ↔ s = ∅ := ⟨fun h ↦ by simpa using h.mapsTo, by rintro rfl; exact bijOn_empty f⟩ @[simp] theorem bijOn_empty_iff_right : BijOn f ∅ t ↔ t = ∅ := ⟨fun h ↦ by simpa using h.surjOn, by rintro rfl; exact bijOn_empty f⟩ @[simp] lemma bijOn_singleton : BijOn f {a} {b} ↔ f a = b := by simp [BijOn, eq_comm] theorem BijOn.inter_mapsTo (h₁ : BijOn f s₁ t₁) (h₂ : MapsTo f s₂ t₂) (h₃ : s₁ ∩ f ⁻¹' t₂ ⊆ s₂) : BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := ⟨h₁.mapsTo.inter_inter h₂, h₁.injOn.mono inter_subset_left, fun _ hy => let ⟨x, hx, hxy⟩ := h₁.surjOn hy.1 ⟨x, ⟨hx, h₃ ⟨hx, hxy.symm.subst hy.2⟩⟩, hxy⟩⟩ theorem MapsTo.inter_bijOn (h₁ : MapsTo f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h₃ : s₂ ∩ f ⁻¹' t₁ ⊆ s₁) : BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := inter_comm s₂ s₁ ▸ inter_comm t₂ t₁ ▸ h₂.inter_mapsTo h₁ h₃ theorem BijOn.inter (h₁ : BijOn f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) : BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := ⟨h₁.mapsTo.inter_inter h₂.mapsTo, h₁.injOn.mono inter_subset_left, h₁.surjOn.inter_inter h₂.surjOn h⟩ theorem BijOn.union (h₁ : BijOn f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) : BijOn f (s₁ ∪ s₂) (t₁ ∪ t₂) := ⟨h₁.mapsTo.union_union h₂.mapsTo, h, h₁.surjOn.union_union h₂.surjOn⟩ theorem BijOn.subset_range (h : BijOn f s t) : t ⊆ range f := h.surjOn.subset_range theorem InjOn.bijOn_image (h : InjOn f s) : BijOn f s (f '' s) := BijOn.mk (mapsTo_image f s) h (Subset.refl _) theorem BijOn.congr (h₁ : BijOn f₁ s t) (h : EqOn f₁ f₂ s) : BijOn f₂ s t := BijOn.mk (h₁.mapsTo.congr h) (h₁.injOn.congr h) (h₁.surjOn.congr h) theorem EqOn.bijOn_iff (H : EqOn f₁ f₂ s) : BijOn f₁ s t ↔ BijOn f₂ s t := ⟨fun h => h.congr H, fun h => h.congr H.symm⟩ theorem BijOn.image_eq (h : BijOn f s t) : f '' s = t := h.surjOn.image_eq_of_mapsTo h.mapsTo lemma BijOn.forall {p : β → Prop} (hf : BijOn f s t) : (∀ b ∈ t, p b) ↔ ∀ a ∈ s, p (f a) where mp h _ ha := h _ <| hf.mapsTo ha mpr h b hb := by obtain ⟨a, ha, rfl⟩ := hf.surjOn hb; exact h _ ha lemma BijOn.exists {p : β → Prop} (hf : BijOn f s t) : (∃ b ∈ t, p b) ↔ ∃ a ∈ s, p (f a) where mp := by rintro ⟨b, hb, h⟩; obtain ⟨a, ha, rfl⟩ := hf.surjOn hb; exact ⟨a, ha, h⟩ mpr := by rintro ⟨a, ha, h⟩; exact ⟨f a, hf.mapsTo ha, h⟩ lemma _root_.Equiv.image_eq_iff_bijOn (e : α ≃ β) : e '' s = t ↔ BijOn e s t := ⟨fun h ↦ ⟨(mapsTo_image e s).mono_right h.subset, e.injective.injOn, h ▸ surjOn_image e s⟩, BijOn.image_eq⟩ lemma bijOn_id (s : Set α) : BijOn id s s := ⟨s.mapsTo_id, s.injOn_id, s.surjOn_id⟩ theorem BijOn.comp (hg : BijOn g t p) (hf : BijOn f s t) : BijOn (g ∘ f) s p := BijOn.mk (hg.mapsTo.comp hf.mapsTo) (hg.injOn.comp hf.injOn hf.mapsTo) (hg.surjOn.comp hf.surjOn) /-- If `f : α → β` and `g : β → γ` and if `f` is injective on `s`, then `f ∘ g` is a bijection on `s` iff `g` is a bijection on `f '' s`. -/ theorem bijOn_comp_iff (hf : InjOn f s) : BijOn (g ∘ f) s p ↔ BijOn g (f '' s) p := by simp only [BijOn, InjOn.comp_iff, surjOn_comp_iff, mapsTo_image_iff, hf] /-- If we have a commutative square ``` α --f--> β | | p₁ p₂ | | \/ \/ γ --g--> δ ``` and `f` induces a bijection from `s : Set α` to `t : Set β`, then `g` induces a bijection from the image of `s` to the image of `t`, as long as `g` is is injective on the image of `s`. -/ theorem bijOn_image_image {p₁ : α → γ} {p₂ : β → δ} {g : γ → δ} (comm : ∀ a, p₂ (f a) = g (p₁ a)) (hbij : BijOn f s t) (hinj: InjOn g (p₁ '' s)) : BijOn g (p₁ '' s) (p₂ '' t) := by obtain ⟨h1, h2, h3⟩ := hbij refine ⟨?_, hinj, ?_⟩ · rintro _ ⟨a, ha, rfl⟩ exact ⟨f a, h1 ha, by rw [comm a]⟩ · rintro _ ⟨b, hb, rfl⟩ obtain ⟨a, ha, rfl⟩ := h3 hb rw [← image_comp, comm] exact ⟨a, ha, rfl⟩ lemma BijOn.iterate {f : α → α} {s : Set α} (h : BijOn f s s) : ∀ n, BijOn f^[n] s s | 0 => s.bijOn_id | (n + 1) => (h.iterate n).comp h lemma bijOn_of_subsingleton' [Subsingleton α] [Subsingleton β] (f : α → β) (h : s.Nonempty ↔ t.Nonempty) : BijOn f s t := ⟨mapsTo_of_subsingleton' _ h.1, injOn_of_subsingleton _ _, surjOn_of_subsingleton' _ h.2⟩ lemma bijOn_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : BijOn f s s := bijOn_of_subsingleton' _ Iff.rfl theorem BijOn.bijective (h : BijOn f s t) : Bijective (h.mapsTo.restrict f s t) := ⟨fun x y h' => Subtype.ext <| h.injOn x.2 y.2 <| Subtype.ext_iff.1 h', fun ⟨_, hy⟩ => let ⟨x, hx, hxy⟩ := h.surjOn hy ⟨⟨x, hx⟩, Subtype.eq hxy⟩⟩ theorem bijective_iff_bijOn_univ : Bijective f ↔ BijOn f univ univ := Iff.intro (fun h => let ⟨inj, surj⟩ := h ⟨mapsTo_univ f _, inj.injOn, Iff.mp surjective_iff_surjOn_univ surj⟩) fun h => let ⟨_map, inj, surj⟩ := h ⟨Iff.mpr injective_iff_injOn_univ inj, Iff.mpr surjective_iff_surjOn_univ surj⟩ alias ⟨_root_.Function.Bijective.bijOn_univ, _⟩ := bijective_iff_bijOn_univ theorem BijOn.compl (hst : BijOn f s t) (hf : Bijective f) : BijOn f sᶜ tᶜ := ⟨hst.surjOn.mapsTo_compl hf.1, hf.1.injOn, hst.mapsTo.surjOn_compl hf.2⟩ theorem BijOn.subset_right {r : Set β} (hf : BijOn f s t) (hrt : r ⊆ t) : BijOn f (s ∩ f ⁻¹' r) r := by refine ⟨inter_subset_right, hf.injOn.mono inter_subset_left, fun x hx ↦ ?_⟩ obtain ⟨y, hy, rfl⟩ := hf.surjOn (hrt hx) exact ⟨y, ⟨hy, hx⟩, rfl⟩ theorem BijOn.subset_left {r : Set α} (hf : BijOn f s t) (hrs : r ⊆ s) : BijOn f r (f '' r) := (hf.injOn.mono hrs).bijOn_image theorem BijOn.insert_iff (ha : a ∉ s) (hfa : f a ∉ t) : BijOn f (insert a s) (insert (f a) t) ↔ BijOn f s t where mp h := by have := congrArg (· \ {f a}) (image_insert_eq ▸ h.image_eq) simp only [mem_singleton_iff, insert_diff_of_mem] at this rw [diff_singleton_eq_self hfa, diff_singleton_eq_self] at this · exact ⟨by simp [← this, mapsTo'], h.injOn.mono (subset_insert ..), by simp [← this, surjOn_image]⟩ simp only [mem_image, not_exists, not_and] intro x hx rw [h.injOn.eq_iff (by simp [hx]) (by simp)] exact ha ∘ (· ▸ hx) mpr h := by repeat rw [insert_eq] refine (bijOn_singleton.mpr rfl).union h ?_ simp only [singleton_union, injOn_insert fun x ↦ (hfa (h.mapsTo x)), h.injOn, mem_image, not_exists, not_and, true_and] exact fun _ hx h₂ ↦ hfa (h₂ ▸ h.mapsTo hx) theorem BijOn.insert (h₁ : BijOn f s t) (h₂ : f a ∉ t) : BijOn f (insert a s) (insert (f a) t) := (insert_iff (h₂ <| h₁.mapsTo ·) h₂).mpr h₁ theorem BijOn.sdiff_singleton (h₁ : BijOn f s t) (h₂ : a ∈ s) : BijOn f (s \ {a}) (t \ {f a}) := by convert h₁.subset_left diff_subset simp [h₁.injOn.image_diff, h₁.image_eq, h₂, inter_eq_self_of_subset_right] end bijOn /-! ### left inverse -/ namespace LeftInvOn theorem eqOn (h : LeftInvOn f' f s) : EqOn (f' ∘ f) id s := h theorem eq (h : LeftInvOn f' f s) {x} (hx : x ∈ s) : f' (f x) = x := h hx theorem congr_left (h₁ : LeftInvOn f₁' f s) {t : Set β} (h₁' : MapsTo f s t) (heq : EqOn f₁' f₂' t) : LeftInvOn f₂' f s := fun _ hx => heq (h₁' hx) ▸ h₁ hx theorem congr_right (h₁ : LeftInvOn f₁' f₁ s) (heq : EqOn f₁ f₂ s) : LeftInvOn f₁' f₂ s := fun _ hx => heq hx ▸ h₁ hx theorem injOn (h : LeftInvOn f₁' f s) : InjOn f s := fun x₁ h₁ x₂ h₂ heq => calc x₁ = f₁' (f x₁) := Eq.symm <| h h₁ _ = f₁' (f x₂) := congr_arg f₁' heq _ = x₂ := h h₂ theorem surjOn (h : LeftInvOn f' f s) (hf : MapsTo f s t) : SurjOn f' t s := fun x hx => ⟨f x, hf hx, h hx⟩ theorem mapsTo (h : LeftInvOn f' f s) (hf : SurjOn f s t) : MapsTo f' t s := fun y hy => by let ⟨x, hs, hx⟩ := hf hy rwa [← hx, h hs] lemma _root_.Set.leftInvOn_id (s : Set α) : LeftInvOn id id s := fun _ _ ↦ rfl theorem comp (hf' : LeftInvOn f' f s) (hg' : LeftInvOn g' g t) (hf : MapsTo f s t) : LeftInvOn (f' ∘ g') (g ∘ f) s := fun x h => calc (f' ∘ g') ((g ∘ f) x) = f' (f x) := congr_arg f' (hg' (hf h)) _ = x := hf' h theorem mono (hf : LeftInvOn f' f s) (ht : s₁ ⊆ s) : LeftInvOn f' f s₁ := fun _ hx => hf (ht hx) theorem image_inter' (hf : LeftInvOn f' f s) : f '' (s₁ ∩ s) = f' ⁻¹' s₁ ∩ f '' s := by apply Subset.antisymm · rintro _ ⟨x, ⟨h₁, h⟩, rfl⟩ exact ⟨by rwa [mem_preimage, hf h], mem_image_of_mem _ h⟩ · rintro _ ⟨h₁, ⟨x, h, rfl⟩⟩ exact mem_image_of_mem _ ⟨by rwa [← hf h], h⟩ theorem image_inter (hf : LeftInvOn f' f s) : f '' (s₁ ∩ s) = f' ⁻¹' (s₁ ∩ s) ∩ f '' s := by rw [hf.image_inter'] refine Subset.antisymm ?_ (inter_subset_inter_left _ (preimage_mono inter_subset_left)) rintro _ ⟨h₁, x, hx, rfl⟩; exact ⟨⟨h₁, by rwa [hf hx]⟩, mem_image_of_mem _ hx⟩ theorem image_image (hf : LeftInvOn f' f s) : f' '' (f '' s) = s := by rw [Set.image_image, image_congr hf, image_id'] theorem image_image' (hf : LeftInvOn f' f s) (hs : s₁ ⊆ s) : f' '' (f '' s₁) = s₁ := (hf.mono hs).image_image end LeftInvOn /-! ### Right inverse -/ section RightInvOn namespace RightInvOn theorem eqOn (h : RightInvOn f' f t) : EqOn (f ∘ f') id t := h theorem eq (h : RightInvOn f' f t) {y} (hy : y ∈ t) : f (f' y) = y := h hy theorem _root_.Set.LeftInvOn.rightInvOn_image (h : LeftInvOn f' f s) : RightInvOn f' f (f '' s) := fun _y ⟨_x, hx, heq⟩ => heq ▸ (congr_arg f <| h.eq hx) theorem congr_left (h₁ : RightInvOn f₁' f t) (heq : EqOn f₁' f₂' t) : RightInvOn f₂' f t := h₁.congr_right heq theorem congr_right (h₁ : RightInvOn f' f₁ t) (hg : MapsTo f' t s) (heq : EqOn f₁ f₂ s) : RightInvOn f' f₂ t := LeftInvOn.congr_left h₁ hg heq theorem surjOn (hf : RightInvOn f' f t) (hf' : MapsTo f' t s) : SurjOn f s t := LeftInvOn.surjOn hf hf' theorem mapsTo (h : RightInvOn f' f t) (hf : SurjOn f' t s) : MapsTo f s t := LeftInvOn.mapsTo h hf lemma _root_.Set.rightInvOn_id (s : Set α) : RightInvOn id id s := fun _ _ ↦ rfl theorem comp (hf : RightInvOn f' f t) (hg : RightInvOn g' g p) (g'pt : MapsTo g' p t) : RightInvOn (f' ∘ g') (g ∘ f) p := LeftInvOn.comp hg hf g'pt theorem mono (hf : RightInvOn f' f t) (ht : t₁ ⊆ t) : RightInvOn f' f t₁ := LeftInvOn.mono hf ht end RightInvOn theorem InjOn.rightInvOn_of_leftInvOn (hf : InjOn f s) (hf' : LeftInvOn f f' t) (h₁ : MapsTo f s t) (h₂ : MapsTo f' t s) : RightInvOn f f' s := fun _ h => hf (h₂ <| h₁ h) h (hf' (h₁ h)) theorem eqOn_of_leftInvOn_of_rightInvOn (h₁ : LeftInvOn f₁' f s) (h₂ : RightInvOn f₂' f t) (h : MapsTo f₂' t s) : EqOn f₁' f₂' t := fun y hy => calc f₁' y = (f₁' ∘ f ∘ f₂') y := congr_arg f₁' (h₂ hy).symm _ = f₂' y := h₁ (h hy) theorem SurjOn.leftInvOn_of_rightInvOn (hf : SurjOn f s t) (hf' : RightInvOn f f' s) : LeftInvOn f f' t := fun y hy => by let ⟨x, hx, heq⟩ := hf hy rw [← heq, hf' hx] end RightInvOn /-! ### Two-side inverses -/ namespace InvOn lemma _root_.Set.invOn_id (s : Set α) : InvOn id id s s := ⟨s.leftInvOn_id, s.rightInvOn_id⟩ lemma comp (hf : InvOn f' f s t) (hg : InvOn g' g t p) (fst : MapsTo f s t) (g'pt : MapsTo g' p t) : InvOn (f' ∘ g') (g ∘ f) s p := ⟨hf.1.comp hg.1 fst, hf.2.comp hg.2 g'pt⟩ @[symm] theorem symm (h : InvOn f' f s t) : InvOn f f' t s := ⟨h.right, h.left⟩ theorem mono (h : InvOn f' f s t) (hs : s₁ ⊆ s) (ht : t₁ ⊆ t) : InvOn f' f s₁ t₁ := ⟨h.1.mono hs, h.2.mono ht⟩ /-- If functions `f'` and `f` are inverse on `s` and `t`, `f` maps `s` into `t`, and `f'` maps `t` into `s`, then `f` is a bijection between `s` and `t`. The `mapsTo` arguments can be deduced from `surjOn` statements using `LeftInvOn.mapsTo` and `RightInvOn.mapsTo`. -/ theorem bijOn (h : InvOn f' f s t) (hf : MapsTo f s t) (hf' : MapsTo f' t s) : BijOn f s t := ⟨hf, h.left.injOn, h.right.surjOn hf'⟩ end InvOn end Set /-! ### `invFunOn` is a left/right inverse -/ namespace Function variable {s : Set α} {f : α → β} {a : α} {b : β} /-- Construct the inverse for a function `f` on domain `s`. This function is a right inverse of `f` on `f '' s`. For a computable version, see `Function.Embedding.invOfMemRange`. -/ noncomputable def invFunOn [Nonempty α] (f : α → β) (s : Set α) (b : β) : α := open scoped Classical in if h : ∃ a, a ∈ s ∧ f a = b then Classical.choose h else Classical.choice ‹Nonempty α› variable [Nonempty α] theorem invFunOn_pos (h : ∃ a ∈ s, f a = b) : invFunOn f s b ∈ s ∧ f (invFunOn f s b) = b := by rw [invFunOn, dif_pos h] exact Classical.choose_spec h theorem invFunOn_mem (h : ∃ a ∈ s, f a = b) : invFunOn f s b ∈ s := (invFunOn_pos h).left theorem invFunOn_eq (h : ∃ a ∈ s, f a = b) : f (invFunOn f s b) = b := (invFunOn_pos h).right theorem invFunOn_neg (h : ¬∃ a ∈ s, f a = b) : invFunOn f s b = Classical.choice ‹Nonempty α› := by rw [invFunOn, dif_neg h] @[simp] theorem invFunOn_apply_mem (h : a ∈ s) : invFunOn f s (f a) ∈ s := invFunOn_mem ⟨a, h, rfl⟩ theorem invFunOn_apply_eq (h : a ∈ s) : f (invFunOn f s (f a)) = f a := invFunOn_eq ⟨a, h, rfl⟩ end Function open Function namespace Set variable {s s₁ s₂ : Set α} {t : Set β} {f : α → β} theorem InjOn.leftInvOn_invFunOn [Nonempty α] (h : InjOn f s) : LeftInvOn (invFunOn f s) f s := fun _a ha => h (invFunOn_apply_mem ha) ha (invFunOn_apply_eq ha) theorem InjOn.invFunOn_image [Nonempty α] (h : InjOn f s₂) (ht : s₁ ⊆ s₂) : invFunOn f s₂ '' (f '' s₁) = s₁ := h.leftInvOn_invFunOn.image_image' ht theorem _root_.Function.leftInvOn_invFunOn_of_subset_image_image [Nonempty α] (h : s ⊆ (invFunOn f s) '' (f '' s)) : LeftInvOn (invFunOn f s) f s := fun x hx ↦ by obtain ⟨-, ⟨x, hx', rfl⟩, rfl⟩ := h hx rw [invFunOn_apply_eq (f := f) hx'] theorem injOn_iff_invFunOn_image_image_eq_self [Nonempty α] : InjOn f s ↔ (invFunOn f s) '' (f '' s) = s := ⟨fun h ↦ h.invFunOn_image Subset.rfl, fun h ↦ (Function.leftInvOn_invFunOn_of_subset_image_image h.symm.subset).injOn⟩ theorem _root_.Function.invFunOn_injOn_image [Nonempty α] (f : α → β) (s : Set α) : Set.InjOn (invFunOn f s) (f '' s) := by rintro _ ⟨x, hx, rfl⟩ _ ⟨x', hx', rfl⟩ he rw [← invFunOn_apply_eq (f := f) hx, he, invFunOn_apply_eq (f := f) hx'] theorem _root_.Function.invFunOn_image_image_subset [Nonempty α] (f : α → β) (s : Set α) : (invFunOn f s) '' (f '' s) ⊆ s := by rintro _ ⟨_, ⟨x,hx,rfl⟩, rfl⟩; exact invFunOn_apply_mem hx theorem SurjOn.rightInvOn_invFunOn [Nonempty α] (h : SurjOn f s t) : RightInvOn (invFunOn f s) f t := fun _y hy => invFunOn_eq <| h hy theorem BijOn.invOn_invFunOn [Nonempty α] (h : BijOn f s t) : InvOn (invFunOn f s) f s t := ⟨h.injOn.leftInvOn_invFunOn, h.surjOn.rightInvOn_invFunOn⟩ theorem SurjOn.invOn_invFunOn [Nonempty α] (h : SurjOn f s t) : InvOn (invFunOn f s) f (invFunOn f s '' t) t := by refine ⟨?_, h.rightInvOn_invFunOn⟩ rintro _ ⟨y, hy, rfl⟩ rw [h.rightInvOn_invFunOn hy] theorem SurjOn.mapsTo_invFunOn [Nonempty α] (h : SurjOn f s t) : MapsTo (invFunOn f s) t s := fun _y hy => mem_preimage.2 <| invFunOn_mem <| h hy /-- This lemma is a special case of `rightInvOn_invFunOn.image_image'`; it may make more sense to use the other lemma directly in an application. -/ theorem SurjOn.image_invFunOn_image_of_subset [Nonempty α] {r : Set β} (hf : SurjOn f s t) (hrt : r ⊆ t) : f '' (f.invFunOn s '' r) = r := hf.rightInvOn_invFunOn.image_image' hrt /-- This lemma is a special case of `rightInvOn_invFunOn.image_image`; it may make more sense to use the other lemma directly in an application. -/ theorem SurjOn.image_invFunOn_image [Nonempty α] (hf : SurjOn f s t) : f '' (f.invFunOn s '' t) = t := hf.rightInvOn_invFunOn.image_image theorem SurjOn.bijOn_subset [Nonempty α] (h : SurjOn f s t) : BijOn f (invFunOn f s '' t) t := by refine h.invOn_invFunOn.bijOn ?_ (mapsTo_image _ _) rintro _ ⟨y, hy, rfl⟩ rwa [h.rightInvOn_invFunOn hy] theorem surjOn_iff_exists_bijOn_subset : SurjOn f s t ↔ ∃ s' ⊆ s, BijOn f s' t := by constructor · rcases eq_empty_or_nonempty t with (rfl | ht) · exact fun _ => ⟨∅, empty_subset _, bijOn_empty f⟩ · intro h haveI : Nonempty α := ⟨Classical.choose (h.comap_nonempty ht)⟩ exact ⟨_, h.mapsTo_invFunOn.image_subset, h.bijOn_subset⟩ · rintro ⟨s', hs', hfs'⟩ exact hfs'.surjOn.mono hs' (Subset.refl _) alias ⟨SurjOn.exists_bijOn_subset, _⟩ := Set.surjOn_iff_exists_bijOn_subset variable (f s) lemma exists_subset_bijOn : ∃ s' ⊆ s, BijOn f s' (f '' s) := surjOn_iff_exists_bijOn_subset.mp (surjOn_image f s) lemma exists_image_eq_and_injOn : ∃ u, f '' u = f '' s ∧ InjOn f u := let ⟨u, _, hfu⟩ := exists_subset_bijOn s f ⟨u, hfu.image_eq, hfu.injOn⟩ variable {f s} lemma exists_image_eq_injOn_of_subset_range (ht : t ⊆ range f) : ∃ s, f '' s = t ∧ InjOn f s := image_preimage_eq_of_subset ht ▸ exists_image_eq_and_injOn _ _ /-- If `f` maps `s` bijectively to `t` and a set `t'` is contained in the image of some `s₁ ⊇ s`, then `s₁` has a subset containing `s` that `f` maps bijectively to `t'`. -/ theorem BijOn.exists_extend_of_subset {t' : Set β} (h : BijOn f s t) (hss₁ : s ⊆ s₁) (htt' : t ⊆ t') (ht' : SurjOn f s₁ t') : ∃ s', s ⊆ s' ∧ s' ⊆ s₁ ∧ Set.BijOn f s' t' := by obtain ⟨r, hrss, hbij⟩ := exists_subset_bijOn ((s₁ ∩ f ⁻¹' t') \ f ⁻¹' t) f rw [image_diff_preimage, image_inter_preimage] at hbij refine ⟨s ∪ r, subset_union_left, ?_, ?_, ?_, fun y hyt' ↦ ?_⟩ · exact union_subset hss₁ <| hrss.trans <| diff_subset.trans inter_subset_left · rw [mapsTo', image_union, hbij.image_eq, h.image_eq, union_subset_iff] exact ⟨htt', diff_subset.trans inter_subset_right⟩ · rw [injOn_union, and_iff_right h.injOn, and_iff_right hbij.injOn] · refine fun x hxs y hyr hxy ↦ (hrss hyr).2 ?_ rw [← h.image_eq] exact ⟨x, hxs, hxy⟩ exact (subset_diff.1 hrss).2.symm.mono_left h.mapsTo rw [image_union, h.image_eq, hbij.image_eq, union_diff_self] exact .inr ⟨ht' hyt', hyt'⟩ /-- If `f` maps `s` bijectively to `t`, and `t'` is a superset of `t` contained in the range of `f`, then `f` maps some superset of `s` bijectively to `t'`. -/ theorem BijOn.exists_extend {t' : Set β} (h : BijOn f s t) (htt' : t ⊆ t') (ht' : t' ⊆ range f) : ∃ s', s ⊆ s' ∧ BijOn f s' t' := by simpa using h.exists_extend_of_subset (subset_univ s) htt' (by simpa [SurjOn]) theorem InjOn.exists_subset_injOn_subset_range_eq {r : Set α} (hinj : InjOn f r) (hrs : r ⊆ s) : ∃ u : Set α, r ⊆ u ∧ u ⊆ s ∧ f '' u = f '' s ∧ InjOn f u := by obtain ⟨u, hru, hus, h⟩ := hinj.bijOn_image.exists_extend_of_subset hrs (image_subset f hrs) Subset.rfl exact ⟨u, hru, hus, h.image_eq, h.injOn⟩ theorem preimage_invFun_of_mem [n : Nonempty α] {f : α → β} (hf : Injective f) {s : Set α} (h : Classical.choice n ∈ s) : invFun f ⁻¹' s = f '' s ∪ (range f)ᶜ := by ext x rcases em (x ∈ range f) with (⟨a, rfl⟩ | hx) · simp only [mem_preimage, mem_union, mem_compl_iff, mem_range_self, not_true, or_false, leftInverse_invFun hf _, hf.mem_set_image] · simp only [mem_preimage, invFun_neg hx, h, hx, mem_union, mem_compl_iff, not_false_iff, or_true] theorem preimage_invFun_of_not_mem [n : Nonempty α] {f : α → β} (hf : Injective f) {s : Set α} (h : Classical.choice n ∉ s) : invFun f ⁻¹' s = f '' s := by ext x rcases em (x ∈ range f) with (⟨a, rfl⟩ | hx) · rw [mem_preimage, leftInverse_invFun hf, hf.mem_set_image] · have : x ∉ f '' s := fun h' => hx (image_subset_range _ _ h') simp only [mem_preimage, invFun_neg hx, h, this] lemma BijOn.symm {g : β → α} (h : InvOn f g t s) (hf : BijOn f s t) : BijOn g t s := ⟨h.2.mapsTo hf.surjOn, h.1.injOn, h.2.surjOn hf.mapsTo⟩ lemma bijOn_comm {g : β → α} (h : InvOn f g t s) : BijOn f s t ↔ BijOn g t s := ⟨BijOn.symm h, BijOn.symm h.symm⟩ end Set namespace Function open Set variable {fa : α → α} {fb : β → β} {f : α → β} {g : β → γ} {s t : Set α} theorem Injective.comp_injOn (hg : Injective g) (hf : s.InjOn f) : s.InjOn (g ∘ f) := hg.injOn.comp hf (mapsTo_univ _ _) theorem Surjective.surjOn (hf : Surjective f) (s : Set β) : SurjOn f univ s := (surjective_iff_surjOn_univ.1 hf).mono (Subset.refl _) (subset_univ _) theorem LeftInverse.leftInvOn {g : β → α} (h : LeftInverse f g) (s : Set β) : LeftInvOn f g s := fun x _ => h x theorem RightInverse.rightInvOn {g : β → α} (h : RightInverse f g) (s : Set α) : RightInvOn f g s := fun x _ => h x theorem LeftInverse.rightInvOn_range {g : β → α} (h : LeftInverse f g) : RightInvOn f g (range g) := forall_mem_range.2 fun i => congr_arg g (h i) namespace Semiconj theorem mapsTo_image (h : Semiconj f fa fb) (ha : MapsTo fa s t) : MapsTo fb (f '' s) (f '' t) := fun _y ⟨x, hx, hy⟩ => hy ▸ ⟨fa x, ha hx, h x⟩ theorem mapsTo_image_right {t : Set β} (h : Semiconj f fa fb) (hst : MapsTo f s t) : MapsTo f (fa '' s) (fb '' t) := mapsTo_image_iff.2 fun x hx ↦ ⟨f x, hst hx, (h x).symm⟩ theorem mapsTo_range (h : Semiconj f fa fb) : MapsTo fb (range f) (range f) := fun _y ⟨x, hy⟩ => hy ▸ ⟨fa x, h x⟩ theorem surjOn_image (h : Semiconj f fa fb) (ha : SurjOn fa s t) : SurjOn fb (f '' s) (f '' t) := by rintro y ⟨x, hxt, rfl⟩ rcases ha hxt with ⟨x, hxs, rfl⟩ rw [h x] exact mem_image_of_mem _ (mem_image_of_mem _ hxs) theorem surjOn_range (h : Semiconj f fa fb) (ha : Surjective fa) : SurjOn fb (range f) (range f) := by rw [← image_univ] exact h.surjOn_image (ha.surjOn univ) theorem injOn_image (h : Semiconj f fa fb) (ha : InjOn fa s) (hf : InjOn f (fa '' s)) : InjOn fb (f '' s) := by rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩ H simp only [← h.eq] at H exact congr_arg f (ha hx hy <| hf (mem_image_of_mem fa hx) (mem_image_of_mem fa hy) H) theorem injOn_range (h : Semiconj f fa fb) (ha : Injective fa) (hf : InjOn f (range fa)) : InjOn fb (range f) := by rw [← image_univ] at * exact h.injOn_image ha.injOn hf theorem bijOn_image (h : Semiconj f fa fb) (ha : BijOn fa s t) (hf : InjOn f t) : BijOn fb (f '' s) (f '' t) := ⟨h.mapsTo_image ha.mapsTo, h.injOn_image ha.injOn (ha.image_eq.symm ▸ hf), h.surjOn_image ha.surjOn⟩ theorem bijOn_range (h : Semiconj f fa fb) (ha : Bijective fa) (hf : Injective f) : BijOn fb (range f) (range f) := by rw [← image_univ] exact h.bijOn_image (bijective_iff_bijOn_univ.1 ha) hf.injOn theorem mapsTo_preimage (h : Semiconj f fa fb) {s t : Set β} (hb : MapsTo fb s t) : MapsTo fa (f ⁻¹' s) (f ⁻¹' t) := fun x hx => by simp only [mem_preimage, h x, hb hx] theorem injOn_preimage (h : Semiconj f fa fb) {s : Set β} (hb : InjOn fb s) (hf : InjOn f (f ⁻¹' s)) : InjOn fa (f ⁻¹' s) := by intro x hx y hy H have := congr_arg f H rw [h.eq, h.eq] at this exact hf hx hy (hb hx hy this) end Semiconj theorem update_comp_eq_of_not_mem_range' {α : Sort*} {β : Type*} {γ : β → Sort*} [DecidableEq β] (g : ∀ b, γ b) {f : α → β} {i : β} (a : γ i) (h : i ∉ Set.range f) : (fun j => update g i a (f j)) = fun j => g (f j) := (update_comp_eq_of_forall_ne' _ _) fun x hx => h ⟨x, hx⟩ /-- Non-dependent version of `Function.update_comp_eq_of_not_mem_range'` -/ theorem update_comp_eq_of_not_mem_range {α : Sort*} {β : Type*} {γ : Sort*} [DecidableEq β] (g : β → γ) {f : α → β} {i : β} (a : γ) (h : i ∉ Set.range f) : update g i a ∘ f = g ∘ f := update_comp_eq_of_not_mem_range' g a h theorem insert_injOn (s : Set α) : sᶜ.InjOn fun a => insert a s := fun _a ha _ _ => (insert_inj ha).1 lemma apply_eq_of_range_eq_singleton {f : α → β} {b : β} (h : range f = {b}) (a : α) : f a = b := by simpa only [h, mem_singleton_iff] using mem_range_self (f := f) a end Function /-! ### Equivalences, permutations -/ namespace Set variable {p : β → Prop} [DecidablePred p] {f : α ≃ Subtype p} {g g₁ g₂ : Perm α} {s t : Set α} protected lemma MapsTo.extendDomain (h : MapsTo g s t) : MapsTo (g.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) := by rintro _ ⟨a, ha, rfl⟩; exact ⟨_, h ha, by simp_rw [Function.comp_apply, extendDomain_apply_image]⟩ protected lemma SurjOn.extendDomain (h : SurjOn g s t) : SurjOn (g.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) := by rintro _ ⟨a, ha, rfl⟩ obtain ⟨b, hb, rfl⟩ := h ha exact ⟨_, ⟨_, hb, rfl⟩, by simp_rw [Function.comp_apply, extendDomain_apply_image]⟩ protected lemma BijOn.extendDomain (h : BijOn g s t) : BijOn (g.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) := ⟨h.mapsTo.extendDomain, (g.extendDomain f).injective.injOn, h.surjOn.extendDomain⟩ protected lemma LeftInvOn.extendDomain (h : LeftInvOn g₁ g₂ s) : LeftInvOn (g₁.extendDomain f) (g₂.extendDomain f) ((↑) ∘ f '' s) := by rintro _ ⟨a, ha, rfl⟩; simp_rw [Function.comp_apply, extendDomain_apply_image, h ha] protected lemma RightInvOn.extendDomain (h : RightInvOn g₁ g₂ t) : RightInvOn (g₁.extendDomain f) (g₂.extendDomain f) ((↑) ∘ f '' t) := by rintro _ ⟨a, ha, rfl⟩; simp_rw [Function.comp_apply, extendDomain_apply_image, h ha] protected lemma InvOn.extendDomain (h : InvOn g₁ g₂ s t) : InvOn (g₁.extendDomain f) (g₂.extendDomain f) ((↑) ∘ f '' s) ((↑) ∘ f '' t) := ⟨h.1.extendDomain, h.2.extendDomain⟩ end Set namespace Set variable {α₁ α₂ β₁ β₂ : Type*} {s₁ : Set α₁} {s₂ : Set α₂} {t₁ : Set β₁} {t₂ : Set β₂} {f₁ : α₁ → β₁} {f₂ : α₂ → β₂} {g₁ : β₁ → α₁} {g₂ : β₂ → α₂} lemma InjOn.prodMap (h₁ : s₁.InjOn f₁) (h₂ : s₂.InjOn f₂) : (s₁ ×ˢ s₂).InjOn fun x ↦ (f₁ x.1, f₂ x.2) := fun x hx y hy ↦ by simp_rw [Prod.ext_iff]; exact And.imp (h₁ hx.1 hy.1) (h₂ hx.2 hy.2) lemma SurjOn.prodMap (h₁ : SurjOn f₁ s₁ t₁) (h₂ : SurjOn f₂ s₂ t₂) : SurjOn (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) := by rintro x hx obtain ⟨a₁, ha₁, hx₁⟩ := h₁ hx.1 obtain ⟨a₂, ha₂, hx₂⟩ := h₂ hx.2 exact ⟨(a₁, a₂), ⟨ha₁, ha₂⟩, Prod.ext hx₁ hx₂⟩ lemma MapsTo.prodMap (h₁ : MapsTo f₁ s₁ t₁) (h₂ : MapsTo f₂ s₂ t₂) : MapsTo (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) := fun _x hx ↦ ⟨h₁ hx.1, h₂ hx.2⟩ lemma BijOn.prodMap (h₁ : BijOn f₁ s₁ t₁) (h₂ : BijOn f₂ s₂ t₂) : BijOn (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) := ⟨h₁.mapsTo.prodMap h₂.mapsTo, h₁.injOn.prodMap h₂.injOn, h₁.surjOn.prodMap h₂.surjOn⟩ lemma LeftInvOn.prodMap (h₁ : LeftInvOn g₁ f₁ s₁) (h₂ : LeftInvOn g₂ f₂ s₂) : LeftInvOn (fun x ↦ (g₁ x.1, g₂ x.2)) (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) := fun _x hx ↦ Prod.ext (h₁ hx.1) (h₂ hx.2) lemma RightInvOn.prodMap (h₁ : RightInvOn g₁ f₁ t₁) (h₂ : RightInvOn g₂ f₂ t₂) : RightInvOn (fun x ↦ (g₁ x.1, g₂ x.2)) (fun x ↦ (f₁ x.1, f₂ x.2)) (t₁ ×ˢ t₂) := fun _x hx ↦ Prod.ext (h₁ hx.1) (h₂ hx.2) lemma InvOn.prodMap (h₁ : InvOn g₁ f₁ s₁ t₁) (h₂ : InvOn g₂ f₂ s₂ t₂) : InvOn (fun x ↦ (g₁ x.1, g₂ x.2)) (fun x ↦ (f₁ x.1, f₂ x.2)) (s₁ ×ˢ s₂) (t₁ ×ˢ t₂) := ⟨h₁.1.prodMap h₂.1, h₁.2.prodMap h₂.2⟩ end Set namespace Equiv open Set variable (e : α ≃ β) {s : Set α} {t : Set β} lemma bijOn' (h₁ : MapsTo e s t) (h₂ : MapsTo e.symm t s) : BijOn e s t := ⟨h₁, e.injective.injOn, fun b hb ↦ ⟨e.symm b, h₂ hb, apply_symm_apply _ _⟩⟩ protected lemma bijOn (h : ∀ a, e a ∈ t ↔ a ∈ s) : BijOn e s t := e.bijOn' (fun _ ↦ (h _).2) fun b hb ↦ (h _).1 <| by rwa [apply_symm_apply] lemma invOn : InvOn e e.symm t s := ⟨e.rightInverse_symm.leftInvOn _, e.leftInverse_symm.leftInvOn _⟩ lemma bijOn_image : BijOn e s (e '' s) := e.injective.injOn.bijOn_image lemma bijOn_symm_image : BijOn e.symm (e '' s) s := e.bijOn_image.symm e.invOn variable {e} @[simp] lemma bijOn_symm : BijOn e.symm t s ↔ BijOn e s t := bijOn_comm e.symm.invOn alias ⟨_root_.Set.BijOn.of_equiv_symm, _root_.Set.BijOn.equiv_symm⟩ := bijOn_symm variable [DecidableEq α] {a b : α} lemma bijOn_swap (ha : a ∈ s) (hb : b ∈ s) : BijOn (swap a b) s s := (swap a b).bijOn fun x ↦ by obtain rfl | hxa := eq_or_ne x a <;> obtain rfl | hxb := eq_or_ne x b <;> simp [*, swap_apply_of_ne_of_ne] end Equiv
Mathlib/Data/Set/Function.lean
1,720
1,726
/- Copyright (c) 2020 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import Mathlib.Algebra.Polynomial.Degree.Support import Mathlib.Data.ENat.Basic /-! # Trailing degree of univariate polynomials ## Main definitions * `trailingDegree p`: the multiplicity of `X` in the polynomial `p` * `natTrailingDegree`: a variant of `trailingDegree` that takes values in the natural numbers * `trailingCoeff`: the coefficient at index `natTrailingDegree p` Converts most results about `degree`, `natDegree` and `leadingCoeff` to results about the bottom end of a polynomial -/ noncomputable section open Function Polynomial Finsupp Finset open scoped Polynomial namespace Polynomial universe u v variable {R : Type u} {S : Type v} {a b : R} {n m : ℕ} section Semiring variable [Semiring R] {p q r : R[X]} /-- `trailingDegree p` is the multiplicity of `x` in the polynomial `p`, i.e. the smallest `X`-exponent in `p`. `trailingDegree p = some n` when `p ≠ 0` and `n` is the smallest power of `X` that appears in `p`, otherwise `trailingDegree 0 = ⊤`. -/ def trailingDegree (p : R[X]) : ℕ∞ := p.support.min theorem trailingDegree_lt_wf : WellFounded fun p q : R[X] => trailingDegree p < trailingDegree q := InvImage.wf trailingDegree wellFounded_lt /-- `natTrailingDegree p` forces `trailingDegree p` to `ℕ`, by defining `natTrailingDegree ⊤ = 0`. -/ def natTrailingDegree (p : R[X]) : ℕ := ENat.toNat (trailingDegree p) /-- `trailingCoeff p` gives the coefficient of the smallest power of `X` in `p`. -/ def trailingCoeff (p : R[X]) : R := coeff p (natTrailingDegree p) /-- a polynomial is `monic_at` if its trailing coefficient is 1 -/ def TrailingMonic (p : R[X]) := trailingCoeff p = (1 : R) theorem TrailingMonic.def : TrailingMonic p ↔ trailingCoeff p = 1 := Iff.rfl instance TrailingMonic.decidable [DecidableEq R] : Decidable (TrailingMonic p) := inferInstanceAs <| Decidable (trailingCoeff p = (1 : R)) @[simp] theorem TrailingMonic.trailingCoeff {p : R[X]} (hp : p.TrailingMonic) : trailingCoeff p = 1 := hp @[simp] theorem trailingDegree_zero : trailingDegree (0 : R[X]) = ⊤ := rfl @[simp] theorem trailingCoeff_zero : trailingCoeff (0 : R[X]) = 0 := rfl @[simp] theorem natTrailingDegree_zero : natTrailingDegree (0 : R[X]) = 0 := rfl @[simp] theorem trailingDegree_eq_top : trailingDegree p = ⊤ ↔ p = 0 := ⟨fun h => support_eq_empty.1 (Finset.min_eq_top.1 h), fun h => by simp [h]⟩ theorem trailingDegree_eq_natTrailingDegree (hp : p ≠ 0) : trailingDegree p = (natTrailingDegree p : ℕ∞) := .symm <| ENat.coe_toNat <| mt trailingDegree_eq_top.1 hp theorem trailingDegree_eq_iff_natTrailingDegree_eq {p : R[X]} {n : ℕ} (hp : p ≠ 0) : p.trailingDegree = n ↔ p.natTrailingDegree = n := by rw [trailingDegree_eq_natTrailingDegree hp, Nat.cast_inj] theorem trailingDegree_eq_iff_natTrailingDegree_eq_of_pos {p : R[X]} {n : ℕ} (hn : n ≠ 0) : p.trailingDegree = n ↔ p.natTrailingDegree = n := by rw [natTrailingDegree, ENat.toNat_eq_iff hn] theorem natTrailingDegree_eq_of_trailingDegree_eq_some {p : R[X]} {n : ℕ} (h : trailingDegree p = n) : natTrailingDegree p = n := by simp [natTrailingDegree, h] @[simp] theorem natTrailingDegree_le_trailingDegree : ↑(natTrailingDegree p) ≤ trailingDegree p := ENat.coe_toNat_le_self _ theorem natTrailingDegree_eq_of_trailingDegree_eq [Semiring S] {q : S[X]} (h : trailingDegree p = trailingDegree q) : natTrailingDegree p = natTrailingDegree q := by unfold natTrailingDegree rw [h] theorem trailingDegree_le_of_ne_zero (h : coeff p n ≠ 0) : trailingDegree p ≤ n := min_le (mem_support_iff.2 h) theorem natTrailingDegree_le_of_ne_zero (h : coeff p n ≠ 0) : natTrailingDegree p ≤ n := ENat.toNat_le_of_le_coe <| trailingDegree_le_of_ne_zero h @[simp] lemma coeff_natTrailingDegree_eq_zero : coeff p p.natTrailingDegree = 0 ↔ p = 0 := by constructor · rintro h by_contra hp obtain ⟨n, hpn, hn⟩ := by simpa using min_mem_image_coe <| support_nonempty.2 hp obtain rfl := (trailingDegree_eq_iff_natTrailingDegree_eq hp).1 hn.symm exact hpn h · rintro rfl simp lemma coeff_natTrailingDegree_ne_zero : coeff p p.natTrailingDegree ≠ 0 ↔ p ≠ 0 := coeff_natTrailingDegree_eq_zero.not @[simp] lemma trailingDegree_eq_zero : trailingDegree p = 0 ↔ coeff p 0 ≠ 0 := Finset.min_eq_bot.trans mem_support_iff @[simp] lemma natTrailingDegree_eq_zero : natTrailingDegree p = 0 ↔ p = 0 ∨ coeff p 0 ≠ 0 := by simp [natTrailingDegree, or_comm] lemma natTrailingDegree_ne_zero : natTrailingDegree p ≠ 0 ↔ p ≠ 0 ∧ coeff p 0 = 0 := natTrailingDegree_eq_zero.not.trans <| by rw [not_or, not_ne_iff] lemma trailingDegree_ne_zero : trailingDegree p ≠ 0 ↔ coeff p 0 = 0 := trailingDegree_eq_zero.not_left @[simp] theorem trailingDegree_le_trailingDegree (h : coeff q (natTrailingDegree p) ≠ 0) : trailingDegree q ≤ trailingDegree p := (trailingDegree_le_of_ne_zero h).trans natTrailingDegree_le_trailingDegree theorem trailingDegree_ne_of_natTrailingDegree_ne {n : ℕ} : p.natTrailingDegree ≠ n → trailingDegree p ≠ n := mt fun h => by rw [natTrailingDegree, h, ENat.toNat_coe] theorem natTrailingDegree_le_of_trailingDegree_le {n : ℕ} {hp : p ≠ 0} (H : (n : ℕ∞) ≤ trailingDegree p) : n ≤ natTrailingDegree p := by rwa [trailingDegree_eq_natTrailingDegree hp, Nat.cast_le] at H theorem natTrailingDegree_le_natTrailingDegree (hq : q ≠ 0) (hpq : p.trailingDegree ≤ q.trailingDegree) : p.natTrailingDegree ≤ q.natTrailingDegree := ENat.toNat_le_toNat hpq <| by simpa @[simp] theorem trailingDegree_monomial (ha : a ≠ 0) : trailingDegree (monomial n a) = n := by rw [trailingDegree, support_monomial n ha, min_singleton] rfl theorem natTrailingDegree_monomial (ha : a ≠ 0) : natTrailingDegree (monomial n a) = n := by rw [natTrailingDegree, trailingDegree_monomial ha] rfl theorem natTrailingDegree_monomial_le : natTrailingDegree (monomial n a) ≤ n := letI := Classical.decEq R if ha : a = 0 then by simp [ha] else (natTrailingDegree_monomial ha).le theorem le_trailingDegree_monomial : ↑n ≤ trailingDegree (monomial n a) := letI := Classical.decEq R if ha : a = 0 then by simp [ha] else (trailingDegree_monomial ha).ge @[simp] theorem trailingDegree_C (ha : a ≠ 0) : trailingDegree (C a) = (0 : ℕ∞) := trailingDegree_monomial ha theorem le_trailingDegree_C : (0 : ℕ∞) ≤ trailingDegree (C a) := le_trailingDegree_monomial theorem trailingDegree_one_le : (0 : ℕ∞) ≤ trailingDegree (1 : R[X]) := by rw [← C_1] exact le_trailingDegree_C @[simp] theorem natTrailingDegree_C (a : R) : natTrailingDegree (C a) = 0 := nonpos_iff_eq_zero.1 natTrailingDegree_monomial_le @[simp] theorem natTrailingDegree_one : natTrailingDegree (1 : R[X]) = 0 := natTrailingDegree_C 1 @[simp] theorem natTrailingDegree_natCast (n : ℕ) : natTrailingDegree (n : R[X]) = 0 := by simp only [← C_eq_natCast, natTrailingDegree_C] @[simp] theorem trailingDegree_C_mul_X_pow (n : ℕ) (ha : a ≠ 0) : trailingDegree (C a * X ^ n) = n := by rw [C_mul_X_pow_eq_monomial, trailingDegree_monomial ha] theorem le_trailingDegree_C_mul_X_pow (n : ℕ) (a : R) : (n : ℕ∞) ≤ trailingDegree (C a * X ^ n) := by rw [C_mul_X_pow_eq_monomial] exact le_trailingDegree_monomial theorem coeff_eq_zero_of_lt_trailingDegree (h : (n : ℕ∞) < trailingDegree p) : coeff p n = 0 := Classical.not_not.1 (mt trailingDegree_le_of_ne_zero (not_le_of_gt h)) theorem coeff_eq_zero_of_lt_natTrailingDegree {p : R[X]} {n : ℕ} (h : n < p.natTrailingDegree) : p.coeff n = 0 := by apply coeff_eq_zero_of_lt_trailingDegree by_cases hp : p = 0 · rw [hp, trailingDegree_zero] exact WithTop.coe_lt_top n · rw [trailingDegree_eq_natTrailingDegree hp] exact WithTop.coe_lt_coe.2 h @[simp] theorem coeff_natTrailingDegree_pred_eq_zero {p : R[X]} {hp : (0 : ℕ∞) < natTrailingDegree p} : p.coeff (p.natTrailingDegree - 1) = 0 := coeff_eq_zero_of_lt_natTrailingDegree <| Nat.sub_lt (WithTop.coe_pos.mp hp) Nat.one_pos theorem le_trailingDegree_X_pow (n : ℕ) : (n : ℕ∞) ≤ trailingDegree (X ^ n : R[X]) := by simpa only [C_1, one_mul] using le_trailingDegree_C_mul_X_pow n (1 : R) theorem le_trailingDegree_X : (1 : ℕ∞) ≤ trailingDegree (X : R[X]) := le_trailingDegree_monomial theorem natTrailingDegree_X_le : (X : R[X]).natTrailingDegree ≤ 1 := natTrailingDegree_monomial_le @[simp] theorem trailingCoeff_eq_zero : trailingCoeff p = 0 ↔ p = 0 := ⟨fun h => _root_.by_contradiction fun hp => mt mem_support_iff.1 (Classical.not_not.2 h) (mem_of_min (trailingDegree_eq_natTrailingDegree hp)), fun h => h.symm ▸ leadingCoeff_zero⟩ theorem trailingCoeff_nonzero_iff_nonzero : trailingCoeff p ≠ 0 ↔ p ≠ 0 := not_congr trailingCoeff_eq_zero theorem natTrailingDegree_mem_support_of_nonzero : p ≠ 0 → natTrailingDegree p ∈ p.support := mem_support_iff.mpr ∘ trailingCoeff_nonzero_iff_nonzero.mpr theorem natTrailingDegree_le_of_mem_supp (a : ℕ) : a ∈ p.support → natTrailingDegree p ≤ a := natTrailingDegree_le_of_ne_zero ∘ mem_support_iff.mp theorem natTrailingDegree_eq_support_min' (h : p ≠ 0) : natTrailingDegree p = p.support.min' (nonempty_support_iff.mpr h) := by rw [natTrailingDegree, trailingDegree, ← Finset.coe_min', ENat.some_eq_coe, ENat.toNat_coe] theorem le_natTrailingDegree (hp : p ≠ 0) (hn : ∀ m < n, p.coeff m = 0) : n ≤ p.natTrailingDegree := by
rw [natTrailingDegree_eq_support_min' hp] exact Finset.le_min' _ _ _ fun m hm => not_lt.1 fun hmn => mem_support_iff.1 hm <| hn _ hmn theorem natTrailingDegree_le_natDegree (p : R[X]) : p.natTrailingDegree ≤ p.natDegree := by by_cases hp : p = 0 · rw [hp, natDegree_zero, natTrailingDegree_zero] · exact le_natDegree_of_ne_zero (mt trailingCoeff_eq_zero.mp hp)
Mathlib/Algebra/Polynomial/Degree/TrailingDegree.lean
261
268
/- Copyright (c) 2022 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.Martingale.Basic /-! # Centering lemma for stochastic processes Any `ℕ`-indexed stochastic process which is adapted and integrable can be written as the sum of a martingale and a predictable process. This result is also known as **Doob's decomposition theorem**. From a process `f`, a filtration `ℱ` and a measure `μ`, we define two processes `martingalePart f ℱ μ` and `predictablePart f ℱ μ`. ## Main definitions * `MeasureTheory.predictablePart f ℱ μ`: a predictable process such that `f = predictablePart f ℱ μ + martingalePart f ℱ μ` * `MeasureTheory.martingalePart f ℱ μ`: a martingale such that `f = predictablePart f ℱ μ + martingalePart f ℱ μ` ## Main statements * `MeasureTheory.adapted_predictablePart`: `(fun n => predictablePart f ℱ μ (n+1))` is adapted. That is, `predictablePart` is predictable. * `MeasureTheory.martingale_martingalePart`: `martingalePart f ℱ μ` is a martingale. -/ open TopologicalSpace Filter open scoped NNReal ENNReal MeasureTheory ProbabilityTheory namespace MeasureTheory variable {Ω E : Type*} {m0 : MeasurableSpace Ω} {μ : Measure Ω} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {f : ℕ → Ω → E} {ℱ : Filtration ℕ m0} /-- Any `ℕ`-indexed stochastic process can be written as the sum of a martingale and a predictable process. This is the predictable process. See `martingalePart` for the martingale. -/ noncomputable def predictablePart {m0 : MeasurableSpace Ω} (f : ℕ → Ω → E) (ℱ : Filtration ℕ m0) (μ : Measure Ω) : ℕ → Ω → E := fun n => ∑ i ∈ Finset.range n, μ[f (i + 1) - f i|ℱ i] @[simp] theorem predictablePart_zero : predictablePart f ℱ μ 0 = 0 := by simp_rw [predictablePart, Finset.range_zero, Finset.sum_empty] theorem adapted_predictablePart : Adapted ℱ fun n => predictablePart f ℱ μ (n + 1) := fun _ => Finset.stronglyMeasurable_sum' _ fun _ hin => stronglyMeasurable_condExp.mono (ℱ.mono (Finset.mem_range_succ_iff.mp hin)) theorem adapted_predictablePart' : Adapted ℱ fun n => predictablePart f ℱ μ n := fun _ => Finset.stronglyMeasurable_sum' _ fun _ hin => stronglyMeasurable_condExp.mono (ℱ.mono (Finset.mem_range_le hin)) /-- Any `ℕ`-indexed stochastic process can be written as the sum of a martingale and a predictable process. This is the martingale. See `predictablePart` for the predictable process. -/ noncomputable def martingalePart {m0 : MeasurableSpace Ω} (f : ℕ → Ω → E) (ℱ : Filtration ℕ m0) (μ : Measure Ω) : ℕ → Ω → E := fun n => f n - predictablePart f ℱ μ n theorem martingalePart_add_predictablePart (ℱ : Filtration ℕ m0) (μ : Measure Ω) (f : ℕ → Ω → E) : martingalePart f ℱ μ + predictablePart f ℱ μ = f := sub_add_cancel _ _ theorem martingalePart_eq_sum : martingalePart f ℱ μ = fun n => f 0 + ∑ i ∈ Finset.range n, (f (i + 1) - f i - μ[f (i + 1) - f i|ℱ i]) := by unfold martingalePart predictablePart ext1 n rw [Finset.eq_sum_range_sub f n, ← add_sub, ← Finset.sum_sub_distrib] theorem adapted_martingalePart (hf : Adapted ℱ f) : Adapted ℱ (martingalePart f ℱ μ) := Adapted.sub hf adapted_predictablePart' theorem integrable_martingalePart (hf_int : ∀ n, Integrable (f n) μ) (n : ℕ) : Integrable (martingalePart f ℱ μ n) μ := by rw [martingalePart_eq_sum] fun_prop theorem martingale_martingalePart (hf : Adapted ℱ f) (hf_int : ∀ n, Integrable (f n) μ) [SigmaFiniteFiltration μ ℱ] : Martingale (martingalePart f ℱ μ) ℱ μ := by refine ⟨adapted_martingalePart hf, fun i j hij => ?_⟩ -- ⊢ μ[martingalePart f ℱ μ j | ℱ i] =ᵐ[μ] martingalePart f ℱ μ i have h_eq_sum : μ[martingalePart f ℱ μ j|ℱ i] =ᵐ[μ] f 0 + ∑ k ∈ Finset.range j, (μ[f (k + 1) - f k|ℱ i] - μ[μ[f (k + 1) - f k|ℱ k]|ℱ i]) := by rw [martingalePart_eq_sum] refine (condExp_add (hf_int 0) (by fun_prop) _).trans ?_ refine (EventuallyEq.rfl.add (condExp_finset_sum (fun i _ => by fun_prop) _)).trans ?_ refine EventuallyEq.add ?_ ?_ · rw [condExp_of_stronglyMeasurable (ℱ.le _) _ (hf_int 0)] · exact (hf 0).mono (ℱ.mono (zero_le i)) · exact eventuallyEq_sum fun k _ => condExp_sub (by fun_prop) integrable_condExp _ refine h_eq_sum.trans ?_ have h_ge : ∀ k, i ≤ k → μ[f (k + 1) - f k|ℱ i] - μ[μ[f (k + 1) - f k|ℱ k]|ℱ i] =ᵐ[μ] 0 := by intro k hk have : μ[μ[f (k + 1) - f k|ℱ k]|ℱ i] =ᵐ[μ] μ[f (k + 1) - f k|ℱ i] := condExp_condExp_of_le (ℱ.mono hk) (ℱ.le k) filter_upwards [this] with x hx rw [Pi.sub_apply, Pi.zero_apply, hx, sub_self] have h_lt : ∀ k, k < i → μ[f (k + 1) - f k|ℱ i] - μ[μ[f (k + 1) - f k|ℱ k]|ℱ i] =ᵐ[μ] f (k + 1) - f k - μ[f (k + 1) - f k|ℱ k] := by refine fun k hk => EventuallyEq.sub ?_ ?_ · rw [condExp_of_stronglyMeasurable] · exact ((hf (k + 1)).mono (ℱ.mono (Nat.succ_le_of_lt hk))).sub ((hf k).mono (ℱ.mono hk.le)) · exact (hf_int _).sub (hf_int _) · rw [condExp_of_stronglyMeasurable] · exact stronglyMeasurable_condExp.mono (ℱ.mono hk.le) · exact integrable_condExp rw [martingalePart_eq_sum] refine EventuallyEq.add EventuallyEq.rfl ?_ rw [← Finset.sum_range_add_sum_Ico _ hij, ← add_zero (∑ i ∈ Finset.range i, (f (i + 1) - f i - μ[f (i + 1) - f i|ℱ i]))] refine (eventuallyEq_sum fun k hk => h_lt k (Finset.mem_range.mp hk)).add ?_ refine (eventuallyEq_sum fun k hk => h_ge k (Finset.mem_Ico.mp hk).1).trans ?_ simp only [Finset.sum_const_zero, Pi.zero_apply] rfl -- The following two lemmas demonstrate the essential uniqueness of the decomposition theorem martingalePart_add_ae_eq [SigmaFiniteFiltration μ ℱ] {f g : ℕ → Ω → E} (hf : Martingale f ℱ μ) (hg : Adapted ℱ fun n => g (n + 1)) (hg0 : g 0 = 0) (hgint : ∀ n, Integrable (g n) μ) (n : ℕ) : martingalePart (f + g) ℱ μ n =ᵐ[μ] f n := by set h := f - martingalePart (f + g) ℱ μ with hhdef have hh : h = predictablePart (f + g) ℱ μ - g := by rw [hhdef, sub_eq_sub_iff_add_eq_add, add_comm (predictablePart (f + g) ℱ μ), martingalePart_add_predictablePart] have hhpred : Adapted ℱ fun n => h (n + 1) := by rw [hh] exact adapted_predictablePart.sub hg have hhmgle : Martingale h ℱ μ := hf.sub (martingale_martingalePart (hf.adapted.add <| Predictable.adapted hg <| hg0.symm ▸ stronglyMeasurable_zero) fun n => (hf.integrable n).add <| hgint n) refine (eventuallyEq_iff_sub.2 ?_).symm filter_upwards [hhmgle.eq_zero_of_predictable hhpred n] with ω hω unfold h at hω rw [Pi.sub_apply] at hω rw [hω, Pi.sub_apply, martingalePart] simp [hg0] theorem predictablePart_add_ae_eq [SigmaFiniteFiltration μ ℱ] {f g : ℕ → Ω → E} (hf : Martingale f ℱ μ) (hg : Adapted ℱ fun n => g (n + 1)) (hg0 : g 0 = 0) (hgint : ∀ n, Integrable (g n) μ) (n : ℕ) : predictablePart (f + g) ℱ μ n =ᵐ[μ] g n := by filter_upwards [martingalePart_add_ae_eq hf hg hg0 hgint n] with ω hω rw [← add_right_inj (f n ω)] conv_rhs => rw [← Pi.add_apply, ← Pi.add_apply, ← martingalePart_add_predictablePart ℱ μ (f + g)] rw [Pi.add_apply, Pi.add_apply, hω] section Difference theorem predictablePart_bdd_difference {R : ℝ≥0} {f : ℕ → Ω → ℝ} (ℱ : Filtration ℕ m0) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) : ∀ᵐ ω ∂μ, ∀ i, |predictablePart f ℱ μ (i + 1) ω - predictablePart f ℱ μ i ω| ≤ R := by simp_rw [predictablePart, Finset.sum_apply, Finset.sum_range_succ_sub_sum] exact ae_all_iff.2 fun i => ae_bdd_condExp_of_ae_bdd <| ae_all_iff.1 hbdd i theorem martingalePart_bdd_difference {R : ℝ≥0} {f : ℕ → Ω → ℝ} (ℱ : Filtration ℕ m0) (hbdd : ∀ᵐ ω ∂μ, ∀ i, |f (i + 1) ω - f i ω| ≤ R) : ∀ᵐ ω ∂μ, ∀ i, |martingalePart f ℱ μ (i + 1) ω - martingalePart f ℱ μ i ω| ≤ ↑(2 * R) := by filter_upwards [hbdd, predictablePart_bdd_difference ℱ hbdd] with ω hω₁ hω₂ i simp only [two_mul, martingalePart, Pi.sub_apply] have : |f (i + 1) ω - predictablePart f ℱ μ (i + 1) ω - (f i ω - predictablePart f ℱ μ i ω)| = |f (i + 1) ω - f i ω - (predictablePart f ℱ μ (i + 1) ω - predictablePart f ℱ μ i ω)| := by ring_nf -- `ring` suggests `ring_nf` despite proving the goal rw [this] exact (abs_sub _ _).trans (add_le_add (hω₁ i) (hω₂ i))
end Difference end MeasureTheory
Mathlib/Probability/Martingale/Centering.lean
167
171
/- 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.Countable import Mathlib.MeasureTheory.Measure.Decomposition.Exhaustion import Mathlib.MeasureTheory.Measure.Prod /-! # Measure with a given density with respect to another measure For a measure `μ` on `α` and a function `f : α → ℝ≥0∞`, we define a new measure `μ.withDensity f`. On a measurable set `s`, that measure has value `∫⁻ a in s, f a ∂μ`. An important result about `withDensity` is the Radon-Nikodym theorem. It states that, given measures `μ, ν`, if `HaveLebesgueDecomposition μ ν` then `μ` is absolutely continuous with respect to `ν` if and only if there exists a measurable function `f : α → ℝ≥0∞` such that `μ = ν.withDensity f`. See `MeasureTheory.Measure.absolutelyContinuous_iff_withDensity_rnDeriv_eq`. -/ open Set hiding restrict restrict_apply open Filter ENNReal NNReal MeasureTheory.Measure namespace MeasureTheory variable {α : Type*} {m0 : MeasurableSpace α} {μ : Measure α} /-- Given a measure `μ : Measure α` and a function `f : α → ℝ≥0∞`, `μ.withDensity f` is the measure such that for a measurable set `s` we have `μ.withDensity f s = ∫⁻ a in s, f a ∂μ`. -/ noncomputable def Measure.withDensity {m : MeasurableSpace α} (μ : Measure α) (f : α → ℝ≥0∞) : Measure α := Measure.ofMeasurable (fun s _ => ∫⁻ a in s, f a ∂μ) (by simp) fun _ hs hd => lintegral_iUnion hs hd _ @[simp] theorem withDensity_apply (f : α → ℝ≥0∞) {s : Set α} (hs : MeasurableSet s) : μ.withDensity f s = ∫⁻ a in s, f a ∂μ := Measure.ofMeasurable_apply s hs theorem withDensity_apply_le (f : α → ℝ≥0∞) (s : Set α) : ∫⁻ a in s, f a ∂μ ≤ μ.withDensity f s := by let t := toMeasurable (μ.withDensity f) s calc ∫⁻ a in s, f a ∂μ ≤ ∫⁻ a in t, f a ∂μ := lintegral_mono_set (subset_toMeasurable (withDensity μ f) s) _ = μ.withDensity f t := (withDensity_apply f (measurableSet_toMeasurable (withDensity μ f) s)).symm _ = μ.withDensity f s := measure_toMeasurable s /-! In the next theorem, the s-finiteness assumption is necessary. Here is a counterexample without this assumption. Let `α` be an uncountable space, let `x₀` be some fixed point, and consider the σ-algebra made of those sets which are countable and do not contain `x₀`, and of their complements. This is the σ-algebra generated by the sets `{x}` for `x ≠ x₀`. Define a measure equal to `+∞` on nonempty sets. Let `s = {x₀}` and `f` the indicator of `sᶜ`. Then * `∫⁻ a in s, f a ∂μ = 0`. Indeed, consider a simple function `g ≤ f`. It vanishes on `s`. Then `∫⁻ a in s, g a ∂μ = 0`. Taking the supremum over `g` gives the claim. * `μ.withDensity f s = +∞`. Indeed, this is the infimum of `μ.withDensity f t` over measurable sets `t` containing `s`. As `s` is not measurable, such a set `t` contains a point `x ≠ x₀`. Then `μ.withDensity f t ≥ μ.withDensity f {x} = ∫⁻ a in {x}, f a ∂μ = μ {x} = +∞`. One checks that `μ.withDensity f = μ`, while `μ.restrict s` gives zero mass to sets not containing `x₀`, and infinite mass to those that contain it. -/ theorem withDensity_apply' [SFinite μ] (f : α → ℝ≥0∞) (s : Set α) : μ.withDensity f s = ∫⁻ a in s, f a ∂μ := by apply le_antisymm ?_ (withDensity_apply_le f s) let t := toMeasurable μ s calc μ.withDensity f s ≤ μ.withDensity f t := measure_mono (subset_toMeasurable μ s) _ = ∫⁻ a in t, f a ∂μ := withDensity_apply f (measurableSet_toMeasurable μ s) _ = ∫⁻ a in s, f a ∂μ := by congr 1; exact restrict_toMeasurable_of_sFinite s @[simp] lemma withDensity_zero_left (f : α → ℝ≥0∞) : (0 : Measure α).withDensity f = 0 := by ext s hs rw [withDensity_apply _ hs] simp theorem withDensity_congr_ae {f g : α → ℝ≥0∞} (h : f =ᵐ[μ] g) : μ.withDensity f = μ.withDensity g := by refine Measure.ext fun s hs => ?_ rw [withDensity_apply _ hs, withDensity_apply _ hs] exact lintegral_congr_ae (ae_restrict_of_ae h) lemma withDensity_mono {f g : α → ℝ≥0∞} (hfg : f ≤ᵐ[μ] g) : μ.withDensity f ≤ μ.withDensity g := by refine le_iff.2 fun s hs ↦ ?_ rw [withDensity_apply _ hs, withDensity_apply _ hs] refine setLIntegral_mono_ae' hs ?_ filter_upwards [hfg] with x h_le using fun _ ↦ h_le theorem withDensity_add_left {f : α → ℝ≥0∞} (hf : Measurable f) (g : α → ℝ≥0∞) : μ.withDensity (f + g) = μ.withDensity f + μ.withDensity g := by refine Measure.ext fun s hs => ?_ rw [withDensity_apply _ hs, Measure.add_apply, withDensity_apply _ hs, withDensity_apply _ hs, ← lintegral_add_left hf] simp only [Pi.add_apply] theorem withDensity_add_right (f : α → ℝ≥0∞) {g : α → ℝ≥0∞} (hg : Measurable g) : μ.withDensity (f + g) = μ.withDensity f + μ.withDensity g := by simpa only [add_comm] using withDensity_add_left hg f theorem withDensity_add_measure {m : MeasurableSpace α} (μ ν : Measure α) (f : α → ℝ≥0∞) : (μ + ν).withDensity f = μ.withDensity f + ν.withDensity f := by ext1 s hs simp only [withDensity_apply f hs, restrict_add, lintegral_add_measure, Measure.add_apply] theorem withDensity_sum {ι : Type*} {m : MeasurableSpace α} (μ : ι → Measure α) (f : α → ℝ≥0∞) : (sum μ).withDensity f = sum fun n => (μ n).withDensity f := by ext1 s hs simp_rw [sum_apply _ hs, withDensity_apply f hs, restrict_sum μ hs, lintegral_sum_measure] theorem withDensity_smul (r : ℝ≥0∞) {f : α → ℝ≥0∞} (hf : Measurable f) : μ.withDensity (r • f) = r • μ.withDensity f := by refine Measure.ext fun s hs => ?_ rw [withDensity_apply _ hs, Measure.coe_smul, Pi.smul_apply, withDensity_apply _ hs, smul_eq_mul, ← lintegral_const_mul r hf] simp only [Pi.smul_apply, smul_eq_mul] theorem withDensity_smul' (r : ℝ≥0∞) (f : α → ℝ≥0∞) (hr : r ≠ ∞) : μ.withDensity (r • f) = r • μ.withDensity f := by refine Measure.ext fun s hs => ?_ rw [withDensity_apply _ hs, Measure.coe_smul, Pi.smul_apply, withDensity_apply _ hs, smul_eq_mul, ← lintegral_const_mul' r f hr] simp only [Pi.smul_apply, smul_eq_mul] theorem withDensity_smul_measure (r : ℝ≥0∞) (f : α → ℝ≥0∞) : (r • μ).withDensity f = r • μ.withDensity f := by ext s hs simp [withDensity_apply, hs] theorem isFiniteMeasure_withDensity {f : α → ℝ≥0∞} (hf : ∫⁻ a, f a ∂μ ≠ ∞) : IsFiniteMeasure (μ.withDensity f) := { measure_univ_lt_top := by rwa [withDensity_apply _ MeasurableSet.univ, Measure.restrict_univ, lt_top_iff_ne_top] } theorem withDensity_absolutelyContinuous {m : MeasurableSpace α} (μ : Measure α) (f : α → ℝ≥0∞) : μ.withDensity f ≪ μ := by refine AbsolutelyContinuous.mk fun s hs₁ hs₂ => ?_ rw [withDensity_apply _ hs₁] exact setLIntegral_measure_zero _ _ hs₂ @[simp] theorem withDensity_zero : μ.withDensity 0 = 0 := by ext1 s hs simp [withDensity_apply _ hs] @[simp] theorem withDensity_one : μ.withDensity 1 = μ := by ext1 s hs simp [withDensity_apply _ hs] @[simp] theorem withDensity_const (c : ℝ≥0∞) : μ.withDensity (fun _ ↦ c) = c • μ := by ext1 s hs simp [withDensity_apply _ hs] theorem withDensity_tsum {ι : Type*} [Countable ι] {f : ι → α → ℝ≥0∞} (h : ∀ i, Measurable (f i)) : μ.withDensity (∑' n, f n) = sum fun n => μ.withDensity (f n) := by ext1 s hs simp_rw [sum_apply _ hs, withDensity_apply _ hs] change ∫⁻ x in s, (∑' n, f n) x ∂μ = ∑' i, ∫⁻ x, f i x ∂μ.restrict s rw [← lintegral_tsum fun i => (h i).aemeasurable] exact lintegral_congr fun x => tsum_apply (Pi.summable.2 fun _ => ENNReal.summable) theorem withDensity_indicator {s : Set α} (hs : MeasurableSet s) (f : α → ℝ≥0∞) : μ.withDensity (s.indicator f) = (μ.restrict s).withDensity f := by ext1 t ht rw [withDensity_apply _ ht, lintegral_indicator hs, restrict_comm hs, ← withDensity_apply _ ht] theorem withDensity_indicator_one {s : Set α} (hs : MeasurableSet s) : μ.withDensity (s.indicator 1) = μ.restrict s := by rw [withDensity_indicator hs, withDensity_one] theorem withDensity_ofReal_mutuallySingular {f : α → ℝ} (hf : Measurable f) : (μ.withDensity fun x => ENNReal.ofReal <| f x) ⟂ₘ μ.withDensity fun x => ENNReal.ofReal <| -f x := by set S : Set α := { x | f x < 0 } have hS : MeasurableSet S := measurableSet_lt hf measurable_const refine ⟨S, hS, ?_, ?_⟩ · rw [withDensity_apply _ hS, lintegral_eq_zero_iff hf.ennreal_ofReal, EventuallyEq] exact (ae_restrict_mem hS).mono fun x hx => ENNReal.ofReal_eq_zero.2 (le_of_lt hx) · rw [withDensity_apply _ hS.compl, lintegral_eq_zero_iff hf.neg.ennreal_ofReal, EventuallyEq] exact (ae_restrict_mem hS.compl).mono fun x hx => ENNReal.ofReal_eq_zero.2 (not_lt.1 <| mt neg_pos.1 hx) theorem restrict_withDensity {s : Set α} (hs : MeasurableSet s) (f : α → ℝ≥0∞) : (μ.withDensity f).restrict s = (μ.restrict s).withDensity f := by ext1 t ht rw [restrict_apply ht, withDensity_apply _ ht, withDensity_apply _ (ht.inter hs), restrict_restrict ht] theorem restrict_withDensity' [SFinite μ] (s : Set α) (f : α → ℝ≥0∞) : (μ.withDensity f).restrict s = (μ.restrict s).withDensity f := by ext1 t ht rw [restrict_apply ht, withDensity_apply _ ht, withDensity_apply' _ (t ∩ s), restrict_restrict ht] lemma trim_withDensity {m m0 : MeasurableSpace α} {μ : Measure α} (hm : m ≤ m0) {f : α → ℝ≥0∞} (hf : Measurable[m] f) : (μ.withDensity f).trim hm = (μ.trim hm).withDensity f := by refine @Measure.ext _ m _ _ (fun s hs ↦ ?_) rw [withDensity_apply _ hs, restrict_trim _ _ hs, lintegral_trim _ hf, trim_measurableSet_eq _ hs, withDensity_apply _ (hm s hs)] lemma Measure.MutuallySingular.withDensity {ν : Measure α} {f : α → ℝ≥0∞} (h : μ ⟂ₘ ν) : μ.withDensity f ⟂ₘ ν := MutuallySingular.mono_ac h (withDensity_absolutelyContinuous _ _) AbsolutelyContinuous.rfl @[simp] theorem withDensity_eq_zero_iff {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) : μ.withDensity f = 0 ↔ f =ᵐ[μ] 0 := by rw [← measure_univ_eq_zero, withDensity_apply _ .univ, restrict_univ, lintegral_eq_zero_iff' hf] alias ⟨withDensity_eq_zero, _⟩ := withDensity_eq_zero_iff theorem withDensity_apply_eq_zero' {f : α → ℝ≥0∞} {s : Set α} (hf : AEMeasurable f μ) : μ.withDensity f s = 0 ↔ μ ({ x | f x ≠ 0 } ∩ s) = 0 := by constructor · intro hs let t := toMeasurable (μ.withDensity f) s apply measure_mono_null (inter_subset_inter_right _ (subset_toMeasurable (μ.withDensity f) s)) have A : μ.withDensity f t = 0 := by rw [measure_toMeasurable, hs] rw [withDensity_apply f (measurableSet_toMeasurable _ s), lintegral_eq_zero_iff' (AEMeasurable.restrict hf), EventuallyEq, ae_restrict_iff'₀, ae_iff] at A swap · simp only [measurableSet_toMeasurable, MeasurableSet.nullMeasurableSet] simp only [Pi.zero_apply, mem_setOf_eq, Filter.mem_mk] at A convert A using 2 ext x simp only [and_comm, exists_prop, mem_inter_iff, mem_setOf_eq, mem_compl_iff, not_forall] · intro hs let t := toMeasurable μ ({ x | f x ≠ 0 } ∩ s) have A : s ⊆ t ∪ { x | f x = 0 } := by intro x hx rcases eq_or_ne (f x) 0 with (fx | fx) · simp only [fx, mem_union, mem_setOf_eq, eq_self_iff_true, or_true] · left apply subset_toMeasurable _ _ exact ⟨fx, hx⟩ apply measure_mono_null A (measure_union_null _ _) · apply withDensity_absolutelyContinuous rwa [measure_toMeasurable] rcases hf with ⟨g, hg, hfg⟩ have t : {x | f x = 0} =ᵐ[μ.withDensity f] {x | g x = 0} := by apply withDensity_absolutelyContinuous filter_upwards [hfg] with a ha rw [eq_iff_iff] exact ⟨fun h ↦ by rw [h] at ha; exact ha.symm, fun h ↦ by rw [h] at ha; exact ha⟩ rw [measure_congr t, withDensity_congr_ae hfg] have M : MeasurableSet { x : α | g x = 0 } := hg (measurableSet_singleton _) rw [withDensity_apply _ M, lintegral_eq_zero_iff hg] filter_upwards [ae_restrict_mem M] simp only [imp_self, Pi.zero_apply, imp_true_iff] theorem withDensity_apply_eq_zero {f : α → ℝ≥0∞} {s : Set α} (hf : Measurable f) : μ.withDensity f s = 0 ↔ μ ({ x | f x ≠ 0 } ∩ s) = 0 := withDensity_apply_eq_zero' <| hf.aemeasurable theorem ae_withDensity_iff' {p : α → Prop} {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) : (∀ᵐ x ∂μ.withDensity f, p x) ↔ ∀ᵐ x ∂μ, f x ≠ 0 → p x := by rw [ae_iff, ae_iff, withDensity_apply_eq_zero' hf, iff_iff_eq] congr ext x simp only [exists_prop, mem_inter_iff, mem_setOf_eq, not_forall] theorem ae_withDensity_iff {p : α → Prop} {f : α → ℝ≥0∞} (hf : Measurable f) : (∀ᵐ x ∂μ.withDensity f, p x) ↔ ∀ᵐ x ∂μ, f x ≠ 0 → p x := ae_withDensity_iff' <| hf.aemeasurable theorem ae_withDensity_iff_ae_restrict' {p : α → Prop} {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) : (∀ᵐ x ∂μ.withDensity f, p x) ↔ ∀ᵐ x ∂μ.restrict { x | f x ≠ 0 }, p x := by rw [ae_withDensity_iff' hf, ae_restrict_iff'₀] · simp only [mem_setOf] · rcases hf with ⟨g, hg, hfg⟩ have nonneg_eq_ae : {x | g x ≠ 0} =ᵐ[μ] {x | f x ≠ 0} := by filter_upwards [hfg] with a ha simp only [eq_iff_iff] exact ⟨fun (h : g a ≠ 0) ↦ by rwa [← ha] at h, fun (h : f a ≠ 0) ↦ by rwa [ha] at h⟩ exact NullMeasurableSet.congr (MeasurableSet.nullMeasurableSet <| hg (measurableSet_singleton _)).compl nonneg_eq_ae theorem ae_withDensity_iff_ae_restrict {p : α → Prop} {f : α → ℝ≥0∞} (hf : Measurable f) : (∀ᵐ x ∂μ.withDensity f, p x) ↔ ∀ᵐ x ∂μ.restrict { x | f x ≠ 0 }, p x := ae_withDensity_iff_ae_restrict' <| hf.aemeasurable theorem aemeasurable_withDensity_ennreal_iff' {f : α → ℝ≥0} (hf : AEMeasurable f μ) {g : α → ℝ≥0∞} : AEMeasurable g (μ.withDensity fun x => (f x : ℝ≥0∞)) ↔ AEMeasurable (fun x => (f x : ℝ≥0∞) * g x) μ := by have t : ∃ f', Measurable f' ∧ f =ᵐ[μ] f' := hf rcases t with ⟨f', hf'_m, hf'_ae⟩ constructor · rintro ⟨g', g'meas, hg'⟩ have A : MeasurableSet {x | f' x ≠ 0} := hf'_m (measurableSet_singleton _).compl refine ⟨fun x => f' x * g' x, hf'_m.coe_nnreal_ennreal.smul g'meas, ?_⟩ apply ae_of_ae_restrict_of_ae_restrict_compl { x | f' x ≠ 0 } · rw [EventuallyEq, ae_withDensity_iff' hf.coe_nnreal_ennreal] at hg' rw [ae_restrict_iff' A] filter_upwards [hg', hf'_ae] with a ha h'a h_a_nonneg have : (f' a : ℝ≥0∞) ≠ 0 := by simpa only [Ne, ENNReal.coe_eq_zero] using h_a_nonneg rw [← h'a] at this ⊢ rw [ha this] · rw [ae_restrict_iff' A.compl] filter_upwards [hf'_ae] with a ha ha_null have ha_null : f' a = 0 := Function.nmem_support.mp ha_null rw [ha_null] at ha ⊢ rw [ha] simp only [ENNReal.coe_zero, zero_mul] · rintro ⟨g', g'meas, hg'⟩ refine ⟨fun x => ((f' x)⁻¹ : ℝ≥0∞) * g' x, hf'_m.coe_nnreal_ennreal.inv.smul g'meas, ?_⟩ rw [EventuallyEq, ae_withDensity_iff' hf.coe_nnreal_ennreal] filter_upwards [hg', hf'_ae] with a hfga hff'a h'a rw [hff'a] at hfga h'a rw [← hfga, ← mul_assoc, ENNReal.inv_mul_cancel h'a ENNReal.coe_ne_top, one_mul] theorem aemeasurable_withDensity_ennreal_iff {f : α → ℝ≥0} (hf : Measurable f) {g : α → ℝ≥0∞} : AEMeasurable g (μ.withDensity fun x => (f x : ℝ≥0∞)) ↔ AEMeasurable (fun x => (f x : ℝ≥0∞) * g x) μ := aemeasurable_withDensity_ennreal_iff' <| hf.aemeasurable open MeasureTheory.SimpleFunc /-- This is Exercise 1.2.1 from [tao2010]. It allows you to express integration of a measurable function with respect to `(μ.withDensity f)` as an integral with respect to `μ`, called the base measure. `μ` is often the Lebesgue measure, and in this circumstance `f` is the probability density function, and `(μ.withDensity f)` represents any continuous random variable as a probability measure, such as the uniform distribution between 0 and 1, the Gaussian distribution, the exponential distribution, the Beta distribution, or the Cauchy distribution (see Section 2.4 of [wasserman2004]). Thus, this method shows how to one can calculate expectations, variances, and other moments as a function of the probability density function. -/ theorem lintegral_withDensity_eq_lintegral_mul (μ : Measure α) {f : α → ℝ≥0∞} (h_mf : Measurable f) : ∀ {g : α → ℝ≥0∞}, Measurable g → ∫⁻ a, g a ∂μ.withDensity f = ∫⁻ a, (f * g) a ∂μ := by apply Measurable.ennreal_induction · intro c s h_ms simp [*, mul_comm _ c, ← indicator_mul_right] · intro g h _ h_mea_g _ h_ind_g h_ind_h simp [mul_add, *, Measurable.mul] · intro g h_mea_g h_mono_g h_ind have : Monotone fun n a => f a * g n a := fun m n hmn x => mul_le_mul_left' (h_mono_g hmn x) _ simp [lintegral_iSup, ENNReal.mul_iSup, h_mf.mul (h_mea_g _), *] theorem setLIntegral_withDensity_eq_setLIntegral_mul (μ : Measure α) {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) {s : Set α} (hs : MeasurableSet s) : ∫⁻ x in s, g x ∂μ.withDensity f = ∫⁻ x in s, (f * g) x ∂μ := by rw [restrict_withDensity hs, lintegral_withDensity_eq_lintegral_mul _ hf hg] /-- The Lebesgue integral of `g` with respect to the measure `μ.withDensity f` coincides with the integral of `f * g`. This version assumes that `g` is almost everywhere measurable. For a version without conditions on `g` but requiring that `f` is almost everywhere finite, see `lintegral_withDensity_eq_lintegral_mul_non_measurable` -/ theorem lintegral_withDensity_eq_lintegral_mul₀' {μ : Measure α} {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) {g : α → ℝ≥0∞} (hg : AEMeasurable g (μ.withDensity f)) : ∫⁻ a, g a ∂μ.withDensity f = ∫⁻ a, (f * g) a ∂μ := by let f' := hf.mk f have : μ.withDensity f = μ.withDensity f' := withDensity_congr_ae hf.ae_eq_mk rw [this] at hg ⊢ let g' := hg.mk g calc ∫⁻ a, g a ∂μ.withDensity f' = ∫⁻ a, g' a ∂μ.withDensity f' := lintegral_congr_ae hg.ae_eq_mk _ = ∫⁻ a, (f' * g') a ∂μ := (lintegral_withDensity_eq_lintegral_mul _ hf.measurable_mk hg.measurable_mk) _ = ∫⁻ a, (f' * g) a ∂μ := by apply lintegral_congr_ae apply ae_of_ae_restrict_of_ae_restrict_compl { x | f' x ≠ 0 } · have Z := hg.ae_eq_mk rw [EventuallyEq, ae_withDensity_iff_ae_restrict hf.measurable_mk] at Z filter_upwards [Z] intro x hx simp only [g', hx, Pi.mul_apply] · have M : MeasurableSet { x : α | f' x ≠ 0 }ᶜ := (hf.measurable_mk (measurableSet_singleton 0).compl).compl filter_upwards [ae_restrict_mem M] intro x hx simp only [Classical.not_not, mem_setOf_eq, mem_compl_iff] at hx simp only [hx, zero_mul, Pi.mul_apply] _ = ∫⁻ a : α, (f * g) a ∂μ := by apply lintegral_congr_ae filter_upwards [hf.ae_eq_mk] intro x hx simp only [f', hx, Pi.mul_apply] lemma setLIntegral_withDensity_eq_lintegral_mul₀' {μ : Measure α} {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) {g : α → ℝ≥0∞} (hg : AEMeasurable g (μ.withDensity f)) {s : Set α} (hs : MeasurableSet s) : ∫⁻ a in s, g a ∂μ.withDensity f = ∫⁻ a in s, (f * g) a ∂μ := by rw [restrict_withDensity hs, lintegral_withDensity_eq_lintegral_mul₀' hf.restrict] rw [← restrict_withDensity hs] exact hg.restrict theorem lintegral_withDensity_eq_lintegral_mul₀ {μ : Measure α} {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) {g : α → ℝ≥0∞} (hg : AEMeasurable g μ) : ∫⁻ a, g a ∂μ.withDensity f = ∫⁻ a, (f * g) a ∂μ := lintegral_withDensity_eq_lintegral_mul₀' hf (hg.mono' (withDensity_absolutelyContinuous μ f)) lemma setLIntegral_withDensity_eq_lintegral_mul₀ {μ : Measure α} {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) {g : α → ℝ≥0∞} (hg : AEMeasurable g μ) {s : Set α} (hs : MeasurableSet s) : ∫⁻ a in s, g a ∂μ.withDensity f = ∫⁻ a in s, (f * g) a ∂μ := setLIntegral_withDensity_eq_lintegral_mul₀' hf (hg.mono' (MeasureTheory.withDensity_absolutelyContinuous μ f)) hs theorem lintegral_withDensity_le_lintegral_mul (μ : Measure α) {f : α → ℝ≥0∞} (f_meas : Measurable f) (g : α → ℝ≥0∞) : (∫⁻ a, g a ∂μ.withDensity f) ≤ ∫⁻ a, (f * g) a ∂μ := by rw [← iSup_lintegral_measurable_le_eq_lintegral, ← iSup_lintegral_measurable_le_eq_lintegral] refine iSup₂_le fun i i_meas => iSup_le fun hi => ?_ have A : f * i ≤ f * g := fun x => mul_le_mul_left' (hi x) _ refine le_iSup₂_of_le (f * i) (f_meas.mul i_meas) ?_ exact le_iSup_of_le A (le_of_eq (lintegral_withDensity_eq_lintegral_mul _ f_meas i_meas)) theorem lintegral_withDensity_eq_lintegral_mul_non_measurable (μ : Measure α) {f : α → ℝ≥0∞} (f_meas : Measurable f) (hf : ∀ᵐ x ∂μ, f x < ∞) (g : α → ℝ≥0∞) : ∫⁻ a, g a ∂μ.withDensity f = ∫⁻ a, (f * g) a ∂μ := by refine le_antisymm (lintegral_withDensity_le_lintegral_mul μ f_meas g) ?_ rw [← iSup_lintegral_measurable_le_eq_lintegral, ← iSup_lintegral_measurable_le_eq_lintegral] refine iSup₂_le fun i i_meas => iSup_le fun hi => ?_ have A : (fun x => (f x)⁻¹ * i x) ≤ g := by intro x dsimp rw [mul_comm, ← div_eq_mul_inv] exact div_le_of_le_mul' (hi x) refine le_iSup_of_le (fun x => (f x)⁻¹ * i x) (le_iSup_of_le (f_meas.inv.mul i_meas) ?_) refine le_iSup_of_le A ?_ rw [lintegral_withDensity_eq_lintegral_mul _ f_meas (f_meas.inv.mul i_meas)] apply lintegral_mono_ae filter_upwards [hf] intro x h'x rcases eq_or_ne (f x) 0 with (hx | hx) · have := hi x simp only [hx, zero_mul, Pi.mul_apply, nonpos_iff_eq_zero] at this simp [this] · apply le_of_eq _ dsimp rw [← mul_assoc, ENNReal.mul_inv_cancel hx h'x.ne, one_mul] theorem setLIntegral_withDensity_eq_setLIntegral_mul_non_measurable (μ : Measure α) {f : α → ℝ≥0∞} (f_meas : Measurable f) (g : α → ℝ≥0∞) {s : Set α} (hs : MeasurableSet s) (hf : ∀ᵐ x ∂μ.restrict s, f x < ∞) : ∫⁻ a in s, g a ∂μ.withDensity f = ∫⁻ a in s, (f * g) a ∂μ := by rw [restrict_withDensity hs, lintegral_withDensity_eq_lintegral_mul_non_measurable _ f_meas hf] theorem lintegral_withDensity_eq_lintegral_mul_non_measurable₀ (μ : Measure α) {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) (h'f : ∀ᵐ x ∂μ, f x < ∞) (g : α → ℝ≥0∞) : ∫⁻ a, g a ∂μ.withDensity f = ∫⁻ a, (f * g) a ∂μ := by let f' := hf.mk f calc ∫⁻ a, g a ∂μ.withDensity f = ∫⁻ a, g a ∂μ.withDensity f' := by rw [withDensity_congr_ae hf.ae_eq_mk] _ = ∫⁻ a, (f' * g) a ∂μ := by apply lintegral_withDensity_eq_lintegral_mul_non_measurable _ hf.measurable_mk filter_upwards [h'f, hf.ae_eq_mk] intro x hx h'x rwa [← h'x] _ = ∫⁻ a, (f * g) a ∂μ := by apply lintegral_congr_ae filter_upwards [hf.ae_eq_mk] intro x hx simp only [f', hx, Pi.mul_apply] theorem setLIntegral_withDensity_eq_setLIntegral_mul_non_measurable₀ (μ : Measure α) {f : α → ℝ≥0∞} {s : Set α} (hf : AEMeasurable f (μ.restrict s)) (g : α → ℝ≥0∞) (hs : MeasurableSet s) (h'f : ∀ᵐ x ∂μ.restrict s, f x < ∞) : ∫⁻ a in s, g a ∂μ.withDensity f = ∫⁻ a in s, (f * g) a ∂μ := by rw [restrict_withDensity hs, lintegral_withDensity_eq_lintegral_mul_non_measurable₀ _ hf h'f] theorem setLIntegral_withDensity_eq_setLIntegral_mul_non_measurable₀' (μ : Measure α) [SFinite μ] {f : α → ℝ≥0∞} (s : Set α) (hf : AEMeasurable f (μ.restrict s)) (g : α → ℝ≥0∞) (h'f : ∀ᵐ x ∂μ.restrict s, f x < ∞) : ∫⁻ a in s, g a ∂μ.withDensity f = ∫⁻ a in s, (f * g) a ∂μ := by rw [restrict_withDensity' s, lintegral_withDensity_eq_lintegral_mul_non_measurable₀ _ hf h'f] theorem withDensity_mul₀ {μ : Measure α} {f g : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : μ.withDensity (f * g) = (μ.withDensity f).withDensity g := by ext1 s hs rw [withDensity_apply _ hs, withDensity_apply _ hs, restrict_withDensity hs, lintegral_withDensity_eq_lintegral_mul₀ hf.restrict hg.restrict] theorem withDensity_mul (μ : Measure α) {f g : α → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) : μ.withDensity (f * g) = (μ.withDensity f).withDensity g := withDensity_mul₀ hf.aemeasurable hg.aemeasurable lemma withDensity_inv_same_le {μ : Measure α} {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) : (μ.withDensity f).withDensity f⁻¹ ≤ μ := by change (μ.withDensity f).withDensity (fun x ↦ (f x)⁻¹) ≤ μ rw [← withDensity_mul₀ hf hf.inv] suffices (f * fun x ↦ (f x)⁻¹) ≤ᵐ[μ] 1 by refine (withDensity_mono this).trans ?_ rw [withDensity_one] filter_upwards with x simp only [Pi.mul_apply, Pi.one_apply] by_cases hx_top : f x = ∞ · simp only [hx_top, ENNReal.inv_top, mul_zero, zero_le] by_cases hx_zero : f x = 0 · simp only [hx_zero, ENNReal.inv_zero, zero_mul, zero_le] rw [ENNReal.mul_inv_cancel hx_zero hx_top] lemma withDensity_inv_same₀ {μ : Measure α} {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hf_ne_zero : ∀ᵐ x ∂μ, f x ≠ 0) (hf_ne_top : ∀ᵐ x ∂μ, f x ≠ ∞) : (μ.withDensity f).withDensity (fun x ↦ (f x)⁻¹) = μ := by rw [← withDensity_mul₀ hf hf.inv] suffices (f * fun x ↦ (f x)⁻¹) =ᵐ[μ] 1 by rw [withDensity_congr_ae this, withDensity_one] filter_upwards [hf_ne_zero, hf_ne_top] with x hf_ne_zero hf_ne_top simp only [Pi.mul_apply] rw [ENNReal.mul_inv_cancel hf_ne_zero hf_ne_top, Pi.one_apply] lemma withDensity_inv_same {μ : Measure α} {f : α → ℝ≥0∞} (hf : Measurable f) (hf_ne_zero : ∀ᵐ x ∂μ, f x ≠ 0) (hf_ne_top : ∀ᵐ x ∂μ, f x ≠ ∞) : (μ.withDensity f).withDensity (fun x ↦ (f x)⁻¹) = μ := withDensity_inv_same₀ hf.aemeasurable hf_ne_zero hf_ne_top /-- If `f` is almost everywhere positive, then `μ ≪ μ.withDensity f`. See also `withDensity_absolutelyContinuous` for the reverse direction, which always holds. -/ lemma withDensity_absolutelyContinuous' {μ : Measure α} {f : α → ℝ≥0∞} (hf : AEMeasurable f μ) (hf_ne_zero : ∀ᵐ x ∂μ, f x ≠ 0) : μ ≪ μ.withDensity f := by refine Measure.AbsolutelyContinuous.mk (fun s hs hμs ↦ ?_) rw [withDensity_apply _ hs, lintegral_eq_zero_iff' hf.restrict, ae_eq_restrict_iff_indicator_ae_eq hs, Set.indicator_zero', Filter.EventuallyEq, ae_iff] at hμs simp only [ae_iff, ne_eq, not_not] at hf_ne_zero simp only [Pi.zero_apply, Set.indicator_apply_eq_zero, not_forall, exists_prop] at hμs have hle : s ⊆ {a | a ∈ s ∧ ¬f a = 0} ∪ {a | f a = 0} := fun x hx ↦ or_iff_not_imp_right.mpr <| fun hnx ↦ ⟨hx, hnx⟩ exact measure_mono_null hle <| nonpos_iff_eq_zero.1 <| le_trans (measure_union_le _ _) <| hμs.symm ▸ zero_add _ |>.symm ▸ hf_ne_zero.le
theorem withDensity_ae_eq {β : Type} {f g : α → β} {d : α → ℝ≥0∞} (hd : AEMeasurable d μ) (h_ae_nonneg : ∀ᵐ x ∂μ, d x ≠ 0) : f =ᵐ[μ.withDensity d] g ↔ f =ᵐ[μ] g := Iff.intro (fun h ↦ Measure.AbsolutelyContinuous.ae_eq
Mathlib/MeasureTheory/Measure/WithDensity.lean
542
547
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot -/ import Mathlib.Algebra.Group.TypeTags.Basic import Mathlib.Data.Fin.VecNotation import Mathlib.Data.Finset.Piecewise import Mathlib.Order.Filter.Cofinite import Mathlib.Order.Filter.Curry import Mathlib.Topology.Constructions.SumProd import Mathlib.Topology.NhdsSet /-! # Constructions of new topological spaces from old ones This file constructs pi types, subtypes and quotients of topological spaces and sets up their basic theory, such as criteria for maps into or out of these constructions to be continuous; descriptions of the open sets, neighborhood filters, and generators of these constructions; and their behavior with respect to embeddings and other specific classes of maps. ## Implementation note The constructed topologies are defined using induced and coinduced topologies along with the complete lattice structure on topologies. Their universal properties (for example, a map `X → Y × Z` is continuous if and only if both projections `X → Y`, `X → Z` are) follow easily using order-theoretic descriptions of continuity. With more work we can also extract descriptions of the open sets, neighborhood filters and so on. ## Tags product, subspace, quotient space -/ noncomputable section open Topology TopologicalSpace Set Filter Function open scoped Set.Notation universe u v u' v' variable {X : Type u} {Y : Type v} {Z W ε ζ : Type*} section Constructions instance {r : X → X → Prop} [t : TopologicalSpace X] : TopologicalSpace (Quot r) := coinduced (Quot.mk r) t instance instTopologicalSpaceQuotient {s : Setoid X} [t : TopologicalSpace X] : TopologicalSpace (Quotient s) := coinduced Quotient.mk' t instance instTopologicalSpaceSigma {ι : Type*} {X : ι → Type v} [t₂ : ∀ i, TopologicalSpace (X i)] : TopologicalSpace (Sigma X) := ⨆ i, coinduced (Sigma.mk i) (t₂ i) instance Pi.topologicalSpace {ι : Type*} {Y : ι → Type v} [t₂ : (i : ι) → TopologicalSpace (Y i)] : TopologicalSpace ((i : ι) → Y i) := ⨅ i, induced (fun f => f i) (t₂ i) instance ULift.topologicalSpace [t : TopologicalSpace X] : TopologicalSpace (ULift.{v, u} X) := t.induced ULift.down /-! ### `Additive`, `Multiplicative` The topology on those type synonyms is inherited without change. -/ section variable [TopologicalSpace X] open Additive Multiplicative instance : TopologicalSpace (Additive X) := ‹TopologicalSpace X› instance : TopologicalSpace (Multiplicative X) := ‹TopologicalSpace X› instance [DiscreteTopology X] : DiscreteTopology (Additive X) := ‹DiscreteTopology X› instance [DiscreteTopology X] : DiscreteTopology (Multiplicative X) := ‹DiscreteTopology X› theorem continuous_ofMul : Continuous (ofMul : X → Additive X) := continuous_id theorem continuous_toMul : Continuous (toMul : Additive X → X) := continuous_id theorem continuous_ofAdd : Continuous (ofAdd : X → Multiplicative X) := continuous_id theorem continuous_toAdd : Continuous (toAdd : Multiplicative X → X) := continuous_id theorem isOpenMap_ofMul : IsOpenMap (ofMul : X → Additive X) := IsOpenMap.id theorem isOpenMap_toMul : IsOpenMap (toMul : Additive X → X) := IsOpenMap.id theorem isOpenMap_ofAdd : IsOpenMap (ofAdd : X → Multiplicative X) := IsOpenMap.id theorem isOpenMap_toAdd : IsOpenMap (toAdd : Multiplicative X → X) := IsOpenMap.id theorem isClosedMap_ofMul : IsClosedMap (ofMul : X → Additive X) := IsClosedMap.id theorem isClosedMap_toMul : IsClosedMap (toMul : Additive X → X) := IsClosedMap.id theorem isClosedMap_ofAdd : IsClosedMap (ofAdd : X → Multiplicative X) := IsClosedMap.id theorem isClosedMap_toAdd : IsClosedMap (toAdd : Multiplicative X → X) := IsClosedMap.id theorem nhds_ofMul (x : X) : 𝓝 (ofMul x) = map ofMul (𝓝 x) := rfl theorem nhds_ofAdd (x : X) : 𝓝 (ofAdd x) = map ofAdd (𝓝 x) := rfl theorem nhds_toMul (x : Additive X) : 𝓝 x.toMul = map toMul (𝓝 x) := rfl theorem nhds_toAdd (x : Multiplicative X) : 𝓝 x.toAdd = map toAdd (𝓝 x) := rfl end /-! ### Order dual The topology on this type synonym is inherited without change. -/ section variable [TopologicalSpace X] open OrderDual instance OrderDual.instTopologicalSpace : TopologicalSpace Xᵒᵈ := ‹_› instance OrderDual.instDiscreteTopology [DiscreteTopology X] : DiscreteTopology Xᵒᵈ := ‹_› theorem continuous_toDual : Continuous (toDual : X → Xᵒᵈ) := continuous_id theorem continuous_ofDual : Continuous (ofDual : Xᵒᵈ → X) := continuous_id theorem isOpenMap_toDual : IsOpenMap (toDual : X → Xᵒᵈ) := IsOpenMap.id theorem isOpenMap_ofDual : IsOpenMap (ofDual : Xᵒᵈ → X) := IsOpenMap.id theorem isClosedMap_toDual : IsClosedMap (toDual : X → Xᵒᵈ) := IsClosedMap.id theorem isClosedMap_ofDual : IsClosedMap (ofDual : Xᵒᵈ → X) := IsClosedMap.id theorem nhds_toDual (x : X) : 𝓝 (toDual x) = map toDual (𝓝 x) := rfl theorem nhds_ofDual (x : X) : 𝓝 (ofDual x) = map ofDual (𝓝 x) := rfl variable [Preorder X] {x : X} instance OrderDual.instNeBotNhdsWithinIoi [(𝓝[<] x).NeBot] : (𝓝[>] toDual x).NeBot := ‹_› instance OrderDual.instNeBotNhdsWithinIio [(𝓝[>] x).NeBot] : (𝓝[<] toDual x).NeBot := ‹_› end theorem Quotient.preimage_mem_nhds [TopologicalSpace X] [s : Setoid X] {V : Set <| Quotient s} {x : X} (hs : V ∈ 𝓝 (Quotient.mk' x)) : Quotient.mk' ⁻¹' V ∈ 𝓝 x := preimage_nhds_coinduced hs /-- The image of a dense set under `Quotient.mk'` is a dense set. -/ theorem Dense.quotient [Setoid X] [TopologicalSpace X] {s : Set X} (H : Dense s) : Dense (Quotient.mk' '' s) := Quotient.mk''_surjective.denseRange.dense_image continuous_coinduced_rng H /-- The composition of `Quotient.mk'` and a function with dense range has dense range. -/ theorem DenseRange.quotient [Setoid X] [TopologicalSpace X] {f : Y → X} (hf : DenseRange f) : DenseRange (Quotient.mk' ∘ f) := Quotient.mk''_surjective.denseRange.comp hf continuous_coinduced_rng theorem continuous_map_of_le {α : Type*} [TopologicalSpace α] {s t : Setoid α} (h : s ≤ t) : Continuous (Setoid.map_of_le h) := continuous_coinduced_rng theorem continuous_map_sInf {α : Type*} [TopologicalSpace α] {S : Set (Setoid α)} {s : Setoid α} (h : s ∈ S) : Continuous (Setoid.map_sInf h) := continuous_coinduced_rng instance {p : X → Prop} [TopologicalSpace X] [DiscreteTopology X] : DiscreteTopology (Subtype p) := ⟨bot_unique fun s _ => ⟨(↑) '' s, isOpen_discrete _, preimage_image_eq _ Subtype.val_injective⟩⟩ instance Sum.discreteTopology [TopologicalSpace X] [TopologicalSpace Y] [h : DiscreteTopology X] [hY : DiscreteTopology Y] : DiscreteTopology (X ⊕ Y) := ⟨sup_eq_bot_iff.2 <| by simp [h.eq_bot, hY.eq_bot]⟩ instance Sigma.discreteTopology {ι : Type*} {Y : ι → Type v} [∀ i, TopologicalSpace (Y i)] [h : ∀ i, DiscreteTopology (Y i)] : DiscreteTopology (Sigma Y) := ⟨iSup_eq_bot.2 fun _ => by simp only [(h _).eq_bot, coinduced_bot]⟩ @[simp] lemma comap_nhdsWithin_range {α β} [TopologicalSpace β] (f : α → β) (y : β) : comap f (𝓝[range f] y) = comap f (𝓝 y) := comap_inf_principal_range section Top variable [TopologicalSpace X] /- The 𝓝 filter and the subspace topology. -/ theorem mem_nhds_subtype (s : Set X) (x : { x // x ∈ s }) (t : Set { x // x ∈ s }) : t ∈ 𝓝 x ↔ ∃ u ∈ 𝓝 (x : X), Subtype.val ⁻¹' u ⊆ t := mem_nhds_induced _ x t theorem nhds_subtype (s : Set X) (x : { x // x ∈ s }) : 𝓝 x = comap (↑) (𝓝 (x : X)) := nhds_induced _ x lemma nhds_subtype_eq_comap_nhdsWithin (s : Set X) (x : { x // x ∈ s }) : 𝓝 x = comap (↑) (𝓝[s] (x : X)) := by rw [nhds_subtype, ← comap_nhdsWithin_range, Subtype.range_val] theorem nhdsWithin_subtype_eq_bot_iff {s t : Set X} {x : s} : 𝓝[((↑) : s → X) ⁻¹' t] x = ⊥ ↔ 𝓝[t] (x : X) ⊓ 𝓟 s = ⊥ := by rw [inf_principal_eq_bot_iff_comap, nhdsWithin, nhdsWithin, comap_inf, comap_principal, nhds_induced] theorem nhds_ne_subtype_eq_bot_iff {S : Set X} {x : S} : 𝓝[≠] x = ⊥ ↔ 𝓝[≠] (x : X) ⊓ 𝓟 S = ⊥ := by rw [← nhdsWithin_subtype_eq_bot_iff, preimage_compl, ← image_singleton, Subtype.coe_injective.preimage_image] theorem nhds_ne_subtype_neBot_iff {S : Set X} {x : S} : (𝓝[≠] x).NeBot ↔ (𝓝[≠] (x : X) ⊓ 𝓟 S).NeBot := by rw [neBot_iff, neBot_iff, not_iff_not, nhds_ne_subtype_eq_bot_iff] theorem discreteTopology_subtype_iff {S : Set X} : DiscreteTopology S ↔ ∀ x ∈ S, 𝓝[≠] x ⊓ 𝓟 S = ⊥ := by simp_rw [discreteTopology_iff_nhds_ne, SetCoe.forall', nhds_ne_subtype_eq_bot_iff] end Top /-- A type synonym equipped with the topology whose open sets are the empty set and the sets with finite complements. -/ def CofiniteTopology (X : Type*) := X namespace CofiniteTopology /-- The identity equivalence between `` and `CofiniteTopology `. -/ def of : X ≃ CofiniteTopology X := Equiv.refl X instance [Inhabited X] : Inhabited (CofiniteTopology X) where default := of default instance : TopologicalSpace (CofiniteTopology X) where IsOpen s := s.Nonempty → Set.Finite sᶜ isOpen_univ := by simp isOpen_inter s t := by rintro hs ht ⟨x, hxs, hxt⟩ rw [compl_inter] exact (hs ⟨x, hxs⟩).union (ht ⟨x, hxt⟩) isOpen_sUnion := by rintro s h ⟨x, t, hts, hzt⟩ rw [compl_sUnion] exact Finite.sInter (mem_image_of_mem _ hts) (h t hts ⟨x, hzt⟩) theorem isOpen_iff {s : Set (CofiniteTopology X)} : IsOpen s ↔ s.Nonempty → sᶜ.Finite := Iff.rfl theorem isOpen_iff' {s : Set (CofiniteTopology X)} : IsOpen s ↔ s = ∅ ∨ sᶜ.Finite := by simp only [isOpen_iff, nonempty_iff_ne_empty, or_iff_not_imp_left] theorem isClosed_iff {s : Set (CofiniteTopology X)} : IsClosed s ↔ s = univ ∨ s.Finite := by simp only [← isOpen_compl_iff, isOpen_iff', compl_compl, compl_empty_iff] theorem nhds_eq (x : CofiniteTopology X) : 𝓝 x = pure x ⊔ cofinite := by ext U rw [mem_nhds_iff] constructor · rintro ⟨V, hVU, V_op, haV⟩ exact mem_sup.mpr ⟨hVU haV, mem_of_superset (V_op ⟨_, haV⟩) hVU⟩ · rintro ⟨hU : x ∈ U, hU' : Uᶜ.Finite⟩ exact ⟨U, Subset.rfl, fun _ => hU', hU⟩ theorem mem_nhds_iff {x : CofiniteTopology X} {s : Set (CofiniteTopology X)} : s ∈ 𝓝 x ↔ x ∈ s ∧ sᶜ.Finite := by simp [nhds_eq] end CofiniteTopology end Constructions section Prod variable [TopologicalSpace X] [TopologicalSpace Y] theorem MapClusterPt.curry_prodMap {α β : Type*} {f : α → X} {g : β → Y} {la : Filter α} {lb : Filter β} {x : X} {y : Y} (hf : MapClusterPt x la f) (hg : MapClusterPt y lb g) : MapClusterPt (x, y) (la.curry lb) (.map f g) := by rw [mapClusterPt_iff_frequently] at hf hg rw [((𝓝 x).basis_sets.prod_nhds (𝓝 y).basis_sets).mapClusterPt_iff_frequently] rintro ⟨s, t⟩ ⟨hs, ht⟩ rw [frequently_curry_iff] exact (hf s hs).mono fun x hx ↦ (hg t ht).mono fun y hy ↦ ⟨hx, hy⟩ theorem MapClusterPt.prodMap {α β : Type*} {f : α → X} {g : β → Y} {la : Filter α} {lb : Filter β} {x : X} {y : Y} (hf : MapClusterPt x la f) (hg : MapClusterPt y lb g) : MapClusterPt (x, y) (la ×ˢ lb) (.map f g) := (hf.curry_prodMap hg).mono <| map_mono curry_le_prod end Prod section Bool lemma continuous_bool_rng [TopologicalSpace X] {f : X → Bool} (b : Bool) : Continuous f ↔ IsClopen (f ⁻¹' {b}) := by rw [continuous_discrete_rng, Bool.forall_bool' b, IsClopen, ← isOpen_compl_iff, ← preimage_compl, Bool.compl_singleton, and_comm] end Bool section Subtype variable [TopologicalSpace X] [TopologicalSpace Y] {p : X → Prop} lemma Topology.IsInducing.subtypeVal {t : Set Y} : IsInducing ((↑) : t → Y) := ⟨rfl⟩ @[deprecated (since := "2024-10-28")] alias inducing_subtype_val := IsInducing.subtypeVal lemma Topology.IsInducing.of_codRestrict {f : X → Y} {t : Set Y} (ht : ∀ x, f x ∈ t) (h : IsInducing (t.codRestrict f ht)) : IsInducing f := subtypeVal.comp h @[deprecated (since := "2024-10-28")] alias Inducing.of_codRestrict := IsInducing.of_codRestrict lemma Topology.IsEmbedding.subtypeVal : IsEmbedding ((↑) : Subtype p → X) := ⟨.subtypeVal, Subtype.coe_injective⟩ @[deprecated (since := "2024-10-26")] alias embedding_subtype_val := IsEmbedding.subtypeVal theorem Topology.IsClosedEmbedding.subtypeVal (h : IsClosed {a | p a}) : IsClosedEmbedding ((↑) : Subtype p → X) := ⟨.subtypeVal, by rwa [Subtype.range_coe_subtype]⟩ @[continuity, fun_prop] theorem continuous_subtype_val : Continuous (@Subtype.val X p) := continuous_induced_dom theorem Continuous.subtype_val {f : Y → Subtype p} (hf : Continuous f) : Continuous fun x => (f x : X) := continuous_subtype_val.comp hf theorem IsOpen.isOpenEmbedding_subtypeVal {s : Set X} (hs : IsOpen s) : IsOpenEmbedding ((↑) : s → X) := ⟨.subtypeVal, (@Subtype.range_coe _ s).symm ▸ hs⟩ theorem IsOpen.isOpenMap_subtype_val {s : Set X} (hs : IsOpen s) : IsOpenMap ((↑) : s → X) := hs.isOpenEmbedding_subtypeVal.isOpenMap theorem IsOpenMap.restrict {f : X → Y} (hf : IsOpenMap f) {s : Set X} (hs : IsOpen s) : IsOpenMap (s.restrict f) := hf.comp hs.isOpenMap_subtype_val lemma IsClosed.isClosedEmbedding_subtypeVal {s : Set X} (hs : IsClosed s) : IsClosedEmbedding ((↑) : s → X) := .subtypeVal hs theorem IsClosed.isClosedMap_subtype_val {s : Set X} (hs : IsClosed s) : IsClosedMap ((↑) : s → X) := hs.isClosedEmbedding_subtypeVal.isClosedMap @[continuity, fun_prop] theorem Continuous.subtype_mk {f : Y → X} (h : Continuous f) (hp : ∀ x, p (f x)) : Continuous fun x => (⟨f x, hp x⟩ : Subtype p) := continuous_induced_rng.2 h theorem Continuous.subtype_map {f : X → Y} (h : Continuous f) {q : Y → Prop} (hpq : ∀ x, p x → q (f x)) : Continuous (Subtype.map f hpq) := (h.comp continuous_subtype_val).subtype_mk _ theorem continuous_inclusion {s t : Set X} (h : s ⊆ t) : Continuous (inclusion h) := continuous_id.subtype_map h theorem continuousAt_subtype_val {p : X → Prop} {x : Subtype p} : ContinuousAt ((↑) : Subtype p → X) x := continuous_subtype_val.continuousAt theorem Subtype.dense_iff {s : Set X} {t : Set s} : Dense t ↔ s ⊆ closure ((↑) '' t) := by rw [IsInducing.subtypeVal.dense_iff, SetCoe.forall] rfl theorem map_nhds_subtype_val {s : Set X} (x : s) : map ((↑) : s → X) (𝓝 x) = 𝓝[s] ↑x := by rw [IsInducing.subtypeVal.map_nhds_eq, Subtype.range_val] theorem map_nhds_subtype_coe_eq_nhds {x : X} (hx : p x) (h : ∀ᶠ x in 𝓝 x, p x) : map ((↑) : Subtype p → X) (𝓝 ⟨x, hx⟩) = 𝓝 x := map_nhds_induced_of_mem <| by rw [Subtype.range_val]; exact h theorem nhds_subtype_eq_comap {x : X} {h : p x} : 𝓝 (⟨x, h⟩ : Subtype p) = comap (↑) (𝓝 x) := nhds_induced _ _ theorem tendsto_subtype_rng {Y : Type*} {p : X → Prop} {l : Filter Y} {f : Y → Subtype p} : ∀ {x : Subtype p}, Tendsto f l (𝓝 x) ↔ Tendsto (fun x => (f x : X)) l (𝓝 (x : X)) | ⟨a, ha⟩ => by rw [nhds_subtype_eq_comap, tendsto_comap_iff]; rfl theorem closure_subtype {x : { a // p a }} {s : Set { a // p a }} : x ∈ closure s ↔ (x : X) ∈ closure (((↑) : _ → X) '' s) := closure_induced @[simp] theorem continuousAt_codRestrict_iff {f : X → Y} {t : Set Y} (h1 : ∀ x, f x ∈ t) {x : X} : ContinuousAt (codRestrict f t h1) x ↔ ContinuousAt f x := IsInducing.subtypeVal.continuousAt_iff alias ⟨_, ContinuousAt.codRestrict⟩ := continuousAt_codRestrict_iff theorem ContinuousAt.restrict {f : X → Y} {s : Set X} {t : Set Y} (h1 : MapsTo f s t) {x : s} (h2 : ContinuousAt f x) : ContinuousAt (h1.restrict f s t) x := (h2.comp continuousAt_subtype_val).codRestrict _ theorem ContinuousAt.restrictPreimage {f : X → Y} {s : Set Y} {x : f ⁻¹' s} (h : ContinuousAt f x) : ContinuousAt (s.restrictPreimage f) x := h.restrict _ @[continuity, fun_prop] theorem Continuous.codRestrict {f : X → Y} {s : Set Y} (hf : Continuous f) (hs : ∀ a, f a ∈ s) : Continuous (s.codRestrict f hs) := hf.subtype_mk hs @[continuity, fun_prop] theorem Continuous.restrict {f : X → Y} {s : Set X} {t : Set Y} (h1 : MapsTo f s t) (h2 : Continuous f) : Continuous (h1.restrict f s t) := (h2.comp continuous_subtype_val).codRestrict _ @[continuity, fun_prop] theorem Continuous.restrictPreimage {f : X → Y} {s : Set Y} (h : Continuous f) : Continuous (s.restrictPreimage f) := h.restrict _ lemma Topology.IsEmbedding.restrict {f : X → Y} (hf : IsEmbedding f) {s : Set X} {t : Set Y} (H : s.MapsTo f t) : IsEmbedding H.restrict := .of_comp (hf.continuous.restrict H) continuous_subtype_val (hf.comp .subtypeVal) lemma Topology.IsOpenEmbedding.restrict {f : X → Y} (hf : IsOpenEmbedding f) {s : Set X} {t : Set Y} (H : s.MapsTo f t) (hs : IsOpen s) : IsOpenEmbedding H.restrict := ⟨hf.isEmbedding.restrict H, (by rw [MapsTo.range_restrict] exact continuous_subtype_val.1 _ (hf.isOpenMap _ hs))⟩ theorem Topology.IsInducing.codRestrict {e : X → Y} (he : IsInducing e) {s : Set Y} (hs : ∀ x, e x ∈ s) : IsInducing (codRestrict e s hs) := he.of_comp (he.continuous.codRestrict hs) continuous_subtype_val @[deprecated (since := "2024-10-28")] alias Inducing.codRestrict := IsInducing.codRestrict protected lemma Topology.IsEmbedding.codRestrict {e : X → Y} (he : IsEmbedding e) (s : Set Y) (hs : ∀ x, e x ∈ s) : IsEmbedding (codRestrict e s hs) := he.of_comp (he.continuous.codRestrict hs) continuous_subtype_val @[deprecated (since := "2024-10-26")] alias Embedding.codRestrict := IsEmbedding.codRestrict variable {s t : Set X} protected lemma Topology.IsEmbedding.inclusion (h : s ⊆ t) : IsEmbedding (inclusion h) := IsEmbedding.subtypeVal.codRestrict _ _ protected lemma Topology.IsOpenEmbedding.inclusion (hst : s ⊆ t) (hs : IsOpen (t ↓∩ s)) : IsOpenEmbedding (inclusion hst) where toIsEmbedding := .inclusion _ isOpen_range := by rwa [range_inclusion] protected lemma Topology.IsClosedEmbedding.inclusion (hst : s ⊆ t) (hs : IsClosed (t ↓∩ s)) : IsClosedEmbedding (inclusion hst) where toIsEmbedding := .inclusion _ isClosed_range := by rwa [range_inclusion] @[deprecated (since := "2024-10-26")] alias embedding_inclusion := IsEmbedding.inclusion /-- Let `s, t ⊆ X` be two subsets of a topological space `X`. If `t ⊆ s` and the topology induced by `X`on `s` is discrete, then also the topology induces on `t` is discrete. -/ theorem DiscreteTopology.of_subset {X : Type*} [TopologicalSpace X] {s t : Set X} (_ : DiscreteTopology s) (ts : t ⊆ s) : DiscreteTopology t := (IsEmbedding.inclusion ts).discreteTopology /-- Let `s` be a discrete subset of a topological space. Then the preimage of `s` by a continuous injective map is also discrete. -/ theorem DiscreteTopology.preimage_of_continuous_injective {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] (s : Set Y) [DiscreteTopology s] {f : X → Y} (hc : Continuous f) (hinj : Function.Injective f) : DiscreteTopology (f ⁻¹' s) := DiscreteTopology.of_continuous_injective (β := s) (Continuous.restrict (by exact fun _ x ↦ x) hc) ((MapsTo.restrict_inj _).mpr hinj.injOn) /-- If `f : X → Y` is a quotient map, then its restriction to the preimage of an open set is a quotient map too. -/ theorem Topology.IsQuotientMap.restrictPreimage_isOpen {f : X → Y} (hf : IsQuotientMap f) {s : Set Y} (hs : IsOpen s) : IsQuotientMap (s.restrictPreimage f) := by refine isQuotientMap_iff.2 ⟨hf.surjective.restrictPreimage _, fun U ↦ ?_⟩ rw [hs.isOpenEmbedding_subtypeVal.isOpen_iff_image_isOpen, ← hf.isOpen_preimage, (hs.preimage hf.continuous).isOpenEmbedding_subtypeVal.isOpen_iff_image_isOpen, image_val_preimage_restrictPreimage] @[deprecated (since := "2024-10-22")] alias QuotientMap.restrictPreimage_isOpen := IsQuotientMap.restrictPreimage_isOpen open scoped Set.Notation in lemma isClosed_preimage_val {s t : Set X} : IsClosed (s ↓∩ t) ↔ s ∩ closure (s ∩ t) ⊆ t := by rw [← closure_eq_iff_isClosed, IsEmbedding.subtypeVal.closure_eq_preimage_closure_image, ← Subtype.val_injective.image_injective.eq_iff, Subtype.image_preimage_coe, Subtype.image_preimage_coe, subset_antisymm_iff, and_iff_left, Set.subset_inter_iff, and_iff_right] exacts [Set.inter_subset_left, Set.subset_inter Set.inter_subset_left subset_closure] theorem frontier_inter_open_inter {s t : Set X} (ht : IsOpen t) : frontier (s ∩ t) ∩ t = frontier s ∩ t := by simp only [Set.inter_comm _ t, ← Subtype.preimage_coe_eq_preimage_coe_iff, ht.isOpenMap_subtype_val.preimage_frontier_eq_frontier_preimage continuous_subtype_val, Subtype.preimage_coe_self_inter] section SetNotation open scoped Set.Notation lemma IsOpen.preimage_val {s t : Set X} (ht : IsOpen t) : IsOpen (s ↓∩ t) := ht.preimage continuous_subtype_val lemma IsClosed.preimage_val {s t : Set X} (ht : IsClosed t) : IsClosed (s ↓∩ t) := ht.preimage continuous_subtype_val @[simp] lemma IsOpen.inter_preimage_val_iff {s t : Set X} (hs : IsOpen s) : IsOpen (s ↓∩ t) ↔ IsOpen (s ∩ t) := ⟨fun h ↦ by simpa using hs.isOpenMap_subtype_val _ h, fun h ↦ (Subtype.preimage_coe_self_inter _ _).symm ▸ h.preimage_val⟩ @[simp] lemma IsClosed.inter_preimage_val_iff {s t : Set X} (hs : IsClosed s) : IsClosed (s ↓∩ t) ↔ IsClosed (s ∩ t) := ⟨fun h ↦ by simpa using hs.isClosedMap_subtype_val _ h, fun h ↦ (Subtype.preimage_coe_self_inter _ _).symm ▸ h.preimage_val⟩ end SetNotation end Subtype section Quotient variable [TopologicalSpace X] [TopologicalSpace Y] variable {r : X → X → Prop} {s : Setoid X} theorem isQuotientMap_quot_mk : IsQuotientMap (@Quot.mk X r) := ⟨Quot.exists_rep, rfl⟩ @[deprecated (since := "2024-10-22")] alias quotientMap_quot_mk := isQuotientMap_quot_mk @[continuity, fun_prop] theorem continuous_quot_mk : Continuous (@Quot.mk X r) := continuous_coinduced_rng @[continuity, fun_prop] theorem continuous_quot_lift {f : X → Y} (hr : ∀ a b, r a b → f a = f b) (h : Continuous f) : Continuous (Quot.lift f hr : Quot r → Y) := continuous_coinduced_dom.2 h theorem isQuotientMap_quotient_mk' : IsQuotientMap (@Quotient.mk' X s) := isQuotientMap_quot_mk @[deprecated (since := "2024-10-22")] alias quotientMap_quotient_mk' := isQuotientMap_quotient_mk' theorem continuous_quotient_mk' : Continuous (@Quotient.mk' X s) := continuous_coinduced_rng theorem Continuous.quotient_lift {f : X → Y} (h : Continuous f) (hs : ∀ a b, a ≈ b → f a = f b) : Continuous (Quotient.lift f hs : Quotient s → Y) := continuous_coinduced_dom.2 h theorem Continuous.quotient_liftOn' {f : X → Y} (h : Continuous f) (hs : ∀ a b, s a b → f a = f b) : Continuous (fun x => Quotient.liftOn' x f hs : Quotient s → Y) := h.quotient_lift hs open scoped Relator in @[continuity, fun_prop] theorem Continuous.quotient_map' {t : Setoid Y} {f : X → Y} (hf : Continuous f) (H : (s.r ⇒ t.r) f f) : Continuous (Quotient.map' f H) := (continuous_quotient_mk'.comp hf).quotient_lift _ end Quotient section Pi variable {ι : Type*} {π : ι → Type*} {κ : Type*} [TopologicalSpace X] [T : ∀ i, TopologicalSpace (π i)] {f : X → ∀ i : ι, π i} theorem continuous_pi_iff : Continuous f ↔ ∀ i, Continuous fun a => f a i := by simp only [continuous_iInf_rng, continuous_induced_rng, comp_def] @[continuity, fun_prop] theorem continuous_pi (h : ∀ i, Continuous fun a => f a i) : Continuous f := continuous_pi_iff.2 h @[continuity, fun_prop] theorem continuous_apply (i : ι) : Continuous fun p : ∀ i, π i => p i := continuous_iInf_dom continuous_induced_dom @[continuity] theorem continuous_apply_apply {ρ : κ → ι → Type*} [∀ j i, TopologicalSpace (ρ j i)] (j : κ) (i : ι) : Continuous fun p : ∀ j, ∀ i, ρ j i => p j i := (continuous_apply i).comp (continuous_apply j) theorem continuousAt_apply (i : ι) (x : ∀ i, π i) : ContinuousAt (fun p : ∀ i, π i => p i) x := (continuous_apply i).continuousAt theorem Filter.Tendsto.apply_nhds {l : Filter Y} {f : Y → ∀ i, π i} {x : ∀ i, π i} (h : Tendsto f l (𝓝 x)) (i : ι) : Tendsto (fun a => f a i) l (𝓝 <| x i) := (continuousAt_apply i _).tendsto.comp h @[fun_prop] protected theorem Continuous.piMap {Y : ι → Type*} [∀ i, TopologicalSpace (Y i)] {f : ∀ i, π i → Y i} (hf : ∀ i, Continuous (f i)) : Continuous (Pi.map f) := continuous_pi fun i ↦ (hf i).comp (continuous_apply i) theorem nhds_pi {a : ∀ i, π i} : 𝓝 a = pi fun i => 𝓝 (a i) := by simp only [nhds_iInf, nhds_induced, Filter.pi] protected theorem IsOpenMap.piMap {Y : ι → Type*} [∀ i, TopologicalSpace (Y i)] {f : ∀ i, π i → Y i} (hfo : ∀ i, IsOpenMap (f i)) (hsurj : ∀ᶠ i in cofinite, Surjective (f i)) : IsOpenMap (Pi.map f) := by refine IsOpenMap.of_nhds_le fun x ↦ ?_ rw [nhds_pi, nhds_pi, map_piMap_pi hsurj] exact Filter.pi_mono fun i ↦ (hfo i).nhds_le _ protected theorem IsOpenQuotientMap.piMap {Y : ι → Type*} [∀ i, TopologicalSpace (Y i)] {f : ∀ i, π i → Y i} (hf : ∀ i, IsOpenQuotientMap (f i)) : IsOpenQuotientMap (Pi.map f) := ⟨.piMap fun i ↦ (hf i).1, .piMap fun i ↦ (hf i).2, .piMap (fun i ↦ (hf i).3) <| .of_forall fun i ↦ (hf i).1⟩ theorem tendsto_pi_nhds {f : Y → ∀ i, π i} {g : ∀ i, π i} {u : Filter Y} : Tendsto f u (𝓝 g) ↔ ∀ x, Tendsto (fun i => f i x) u (𝓝 (g x)) := by rw [nhds_pi, Filter.tendsto_pi] theorem continuousAt_pi {f : X → ∀ i, π i} {x : X} : ContinuousAt f x ↔ ∀ i, ContinuousAt (fun y => f y i) x := tendsto_pi_nhds @[fun_prop] theorem continuousAt_pi' {f : X → ∀ i, π i} {x : X} (hf : ∀ i, ContinuousAt (fun y => f y i) x) : ContinuousAt f x := continuousAt_pi.2 hf @[fun_prop] protected theorem ContinuousAt.piMap {Y : ι → Type*} [∀ i, TopologicalSpace (Y i)] {f : ∀ i, π i → Y i} {x : ∀ i, π i} (hf : ∀ i, ContinuousAt (f i) (x i)) : ContinuousAt (Pi.map f) x := continuousAt_pi.2 fun i ↦ (hf i).comp (continuousAt_apply i x) theorem Pi.continuous_precomp' {ι' : Type*} (φ : ι' → ι) : Continuous (fun (f : (∀ i, π i)) (j : ι') ↦ f (φ j)) := continuous_pi fun j ↦ continuous_apply (φ j) theorem Pi.continuous_precomp {ι' : Type*} (φ : ι' → ι) : Continuous (· ∘ φ : (ι → X) → (ι' → X)) := Pi.continuous_precomp' φ theorem Pi.continuous_postcomp' {X : ι → Type*} [∀ i, TopologicalSpace (X i)] {g : ∀ i, π i → X i} (hg : ∀ i, Continuous (g i)) : Continuous (fun (f : (∀ i, π i)) (i : ι) ↦ g i (f i)) := continuous_pi fun i ↦ (hg i).comp <| continuous_apply i theorem Pi.continuous_postcomp [TopologicalSpace Y] {g : X → Y} (hg : Continuous g) : Continuous (g ∘ · : (ι → X) → (ι → Y)) := Pi.continuous_postcomp' fun _ ↦ hg lemma Pi.induced_precomp' {ι' : Type*} (φ : ι' → ι) : induced (fun (f : (∀ i, π i)) (j : ι') ↦ f (φ j)) Pi.topologicalSpace = ⨅ i', induced (eval (φ i')) (T (φ i')) := by simp [Pi.topologicalSpace, induced_iInf, induced_compose, comp_def] lemma Pi.induced_precomp [TopologicalSpace Y] {ι' : Type*} (φ : ι' → ι) : induced (· ∘ φ) Pi.topologicalSpace = ⨅ i', induced (eval (φ i')) ‹TopologicalSpace Y› := induced_precomp' φ @[continuity, fun_prop] lemma Pi.continuous_restrict (S : Set ι) : Continuous (S.restrict : (∀ i : ι, π i) → (∀ i : S, π i)) := Pi.continuous_precomp' ((↑) : S → ι) @[continuity, fun_prop] lemma Pi.continuous_restrict₂ {s t : Set ι} (hst : s ⊆ t) : Continuous (restrict₂ (π := π) hst) := continuous_pi fun _ ↦ continuous_apply _ @[continuity, fun_prop] theorem Finset.continuous_restrict (s : Finset ι) : Continuous (s.restrict (π := π)) := continuous_pi fun _ ↦ continuous_apply _ @[continuity, fun_prop] theorem Finset.continuous_restrict₂ {s t : Finset ι} (hst : s ⊆ t) : Continuous (Finset.restrict₂ (π := π) hst) := continuous_pi fun _ ↦ continuous_apply _ variable [TopologicalSpace Z] @[continuity, fun_prop] theorem Pi.continuous_restrict_apply (s : Set X) {f : X → Z} (hf : Continuous f) : Continuous (s.restrict f) := hf.comp continuous_subtype_val @[continuity, fun_prop] theorem Pi.continuous_restrict₂_apply {s t : Set X} (hst : s ⊆ t) {f : t → Z} (hf : Continuous f) : Continuous (restrict₂ (π := fun _ ↦ Z) hst f) := hf.comp (continuous_inclusion hst) @[continuity, fun_prop] theorem Finset.continuous_restrict_apply (s : Finset X) {f : X → Z} (hf : Continuous f) : Continuous (s.restrict f) := hf.comp continuous_subtype_val @[continuity, fun_prop] theorem Finset.continuous_restrict₂_apply {s t : Finset X} (hst : s ⊆ t) {f : t → Z} (hf : Continuous f) : Continuous (restrict₂ (π := fun _ ↦ Z) hst f) := hf.comp (continuous_inclusion hst) lemma Pi.induced_restrict (S : Set ι) : induced (S.restrict) Pi.topologicalSpace = ⨅ i ∈ S, induced (eval i) (T i) := by simp +unfoldPartialApp [← iInf_subtype'', ← induced_precomp' ((↑) : S → ι), restrict] lemma Pi.induced_restrict_sUnion (𝔖 : Set (Set ι)) : induced (⋃₀ 𝔖).restrict (Pi.topologicalSpace (Y := fun i : (⋃₀ 𝔖) ↦ π i)) = ⨅ S ∈ 𝔖, induced S.restrict Pi.topologicalSpace := by simp_rw [Pi.induced_restrict, iInf_sUnion] theorem Filter.Tendsto.update [DecidableEq ι] {l : Filter Y} {f : Y → ∀ i, π i} {x : ∀ i, π i} (hf : Tendsto f l (𝓝 x)) (i : ι) {g : Y → π i} {xi : π i} (hg : Tendsto g l (𝓝 xi)) : Tendsto (fun a => update (f a) i (g a)) l (𝓝 <| update x i xi) := tendsto_pi_nhds.2 fun j => by rcases eq_or_ne j i with (rfl | hj) <;> simp [*, hf.apply_nhds] theorem ContinuousAt.update [DecidableEq ι] {x : X} (hf : ContinuousAt f x) (i : ι) {g : X → π i} (hg : ContinuousAt g x) : ContinuousAt (fun a => update (f a) i (g a)) x := hf.tendsto.update i hg theorem Continuous.update [DecidableEq ι] (hf : Continuous f) (i : ι) {g : X → π i} (hg : Continuous g) : Continuous fun a => update (f a) i (g a) := continuous_iff_continuousAt.2 fun _ => hf.continuousAt.update i hg.continuousAt /-- `Function.update f i x` is continuous in `(f, x)`. -/ @[continuity, fun_prop] theorem continuous_update [DecidableEq ι] (i : ι) : Continuous fun f : (∀ j, π j) × π i => update f.1 i f.2 := continuous_fst.update i continuous_snd /-- `Pi.mulSingle i x` is continuous in `x`. -/ @[to_additive (attr := continuity) "`Pi.single i x` is continuous in `x`."] theorem continuous_mulSingle [∀ i, One (π i)] [DecidableEq ι] (i : ι) : Continuous fun x => (Pi.mulSingle i x : ∀ i, π i) := continuous_const.update _ continuous_id section Fin variable {n : ℕ} {π : Fin (n + 1) → Type*} [∀ i, TopologicalSpace (π i)] theorem Filter.Tendsto.finCons {f : Y → π 0} {g : Y → ∀ j : Fin n, π j.succ} {l : Filter Y} {x : π 0} {y : ∀ j, π (Fin.succ j)} (hf : Tendsto f l (𝓝 x)) (hg : Tendsto g l (𝓝 y)) : Tendsto (fun a => Fin.cons (f a) (g a)) l (𝓝 <| Fin.cons x y) := tendsto_pi_nhds.2 fun j => Fin.cases (by simpa) (by simpa using tendsto_pi_nhds.1 hg) j theorem ContinuousAt.finCons {f : X → π 0} {g : X → ∀ j : Fin n, π (Fin.succ j)} {x : X} (hf : ContinuousAt f x) (hg : ContinuousAt g x) : ContinuousAt (fun a => Fin.cons (f a) (g a)) x := hf.tendsto.finCons hg theorem Continuous.finCons {f : X → π 0} {g : X → ∀ j : Fin n, π (Fin.succ j)} (hf : Continuous f) (hg : Continuous g) : Continuous fun a => Fin.cons (f a) (g a) := continuous_iff_continuousAt.2 fun _ => hf.continuousAt.finCons hg.continuousAt theorem Filter.Tendsto.matrixVecCons {f : Y → Z} {g : Y → Fin n → Z} {l : Filter Y} {x : Z} {y : Fin n → Z} (hf : Tendsto f l (𝓝 x)) (hg : Tendsto g l (𝓝 y)) : Tendsto (fun a => Matrix.vecCons (f a) (g a)) l (𝓝 <| Matrix.vecCons x y) := hf.finCons hg theorem ContinuousAt.matrixVecCons {f : X → Z} {g : X → Fin n → Z} {x : X} (hf : ContinuousAt f x) (hg : ContinuousAt g x) : ContinuousAt (fun a => Matrix.vecCons (f a) (g a)) x := hf.finCons hg theorem Continuous.matrixVecCons {f : X → Z} {g : X → Fin n → Z} (hf : Continuous f) (hg : Continuous g) : Continuous fun a => Matrix.vecCons (f a) (g a) := hf.finCons hg theorem Filter.Tendsto.finSnoc {f : Y → ∀ j : Fin n, π j.castSucc} {g : Y → π (Fin.last _)} {l : Filter Y} {x : ∀ j, π (Fin.castSucc j)} {y : π (Fin.last _)} (hf : Tendsto f l (𝓝 x)) (hg : Tendsto g l (𝓝 y)) : Tendsto (fun a => Fin.snoc (f a) (g a)) l (𝓝 <| Fin.snoc x y) := tendsto_pi_nhds.2 fun j => Fin.lastCases (by simpa) (by simpa using tendsto_pi_nhds.1 hf) j theorem ContinuousAt.finSnoc {f : X → ∀ j : Fin n, π j.castSucc} {g : X → π (Fin.last _)} {x : X} (hf : ContinuousAt f x) (hg : ContinuousAt g x) : ContinuousAt (fun a => Fin.snoc (f a) (g a)) x := hf.tendsto.finSnoc hg theorem Continuous.finSnoc {f : X → ∀ j : Fin n, π j.castSucc} {g : X → π (Fin.last _)} (hf : Continuous f) (hg : Continuous g) : Continuous fun a => Fin.snoc (f a) (g a) := continuous_iff_continuousAt.2 fun _ => hf.continuousAt.finSnoc hg.continuousAt theorem Filter.Tendsto.finInsertNth (i : Fin (n + 1)) {f : Y → π i} {g : Y → ∀ j : Fin n, π (i.succAbove j)} {l : Filter Y} {x : π i} {y : ∀ j, π (i.succAbove j)} (hf : Tendsto f l (𝓝 x)) (hg : Tendsto g l (𝓝 y)) : Tendsto (fun a => i.insertNth (f a) (g a)) l (𝓝 <| i.insertNth x y) := tendsto_pi_nhds.2 fun j => Fin.succAboveCases i (by simpa) (by simpa using tendsto_pi_nhds.1 hg) j @[deprecated (since := "2025-01-02")] alias Filter.Tendsto.fin_insertNth := Filter.Tendsto.finInsertNth theorem ContinuousAt.finInsertNth (i : Fin (n + 1)) {f : X → π i} {g : X → ∀ j : Fin n, π (i.succAbove j)} {x : X} (hf : ContinuousAt f x) (hg : ContinuousAt g x) : ContinuousAt (fun a => i.insertNth (f a) (g a)) x := hf.tendsto.finInsertNth i hg @[deprecated (since := "2025-01-02")] alias ContinuousAt.fin_insertNth := ContinuousAt.finInsertNth theorem Continuous.finInsertNth (i : Fin (n + 1)) {f : X → π i} {g : X → ∀ j : Fin n, π (i.succAbove j)} (hf : Continuous f) (hg : Continuous g) : Continuous fun a => i.insertNth (f a) (g a) := continuous_iff_continuousAt.2 fun _ => hf.continuousAt.finInsertNth i hg.continuousAt @[deprecated (since := "2025-01-02")] alias Continuous.fin_insertNth := Continuous.finInsertNth theorem Filter.Tendsto.finInit {f : Y → ∀ j : Fin (n + 1), π j} {l : Filter Y} {x : ∀ j, π j} (hg : Tendsto f l (𝓝 x)) : Tendsto (fun a ↦ Fin.init (f a)) l (𝓝 <| Fin.init x) := tendsto_pi_nhds.2 fun j ↦ apply_nhds hg j.castSucc @[fun_prop] theorem ContinuousAt.finInit {f : X → ∀ j : Fin (n + 1), π j} {x : X} (hf : ContinuousAt f x) : ContinuousAt (fun a ↦ Fin.init (f a)) x := hf.tendsto.finInit @[fun_prop] theorem Continuous.finInit {f : X → ∀ j : Fin (n + 1), π j} (hf : Continuous f) : Continuous fun a ↦ Fin.init (f a) := continuous_iff_continuousAt.2 fun _ ↦ hf.continuousAt.finInit theorem Filter.Tendsto.finTail {f : Y → ∀ j : Fin (n + 1), π j} {l : Filter Y} {x : ∀ j, π j} (hg : Tendsto f l (𝓝 x)) : Tendsto (fun a ↦ Fin.tail (f a)) l (𝓝 <| Fin.tail x) := tendsto_pi_nhds.2 fun j ↦ apply_nhds hg j.succ @[fun_prop] theorem ContinuousAt.finTail {f : X → ∀ j : Fin (n + 1), π j} {x : X} (hf : ContinuousAt f x) : ContinuousAt (fun a ↦ Fin.tail (f a)) x := hf.tendsto.finTail @[fun_prop] theorem Continuous.finTail {f : X → ∀ j : Fin (n + 1), π j} (hf : Continuous f) : Continuous fun a ↦ Fin.tail (f a) := continuous_iff_continuousAt.2 fun _ ↦ hf.continuousAt.finTail end Fin theorem isOpen_set_pi {i : Set ι} {s : ∀ a, Set (π a)} (hi : i.Finite) (hs : ∀ a ∈ i, IsOpen (s a)) : IsOpen (pi i s) := by rw [pi_def]; exact hi.isOpen_biInter fun a ha => (hs _ ha).preimage (continuous_apply _) theorem isOpen_pi_iff {s : Set (∀ a, π a)} : IsOpen s ↔ ∀ f, f ∈ s → ∃ (I : Finset ι) (u : ∀ a, Set (π a)), (∀ a, a ∈ I → IsOpen (u a) ∧ f a ∈ u a) ∧ (I : Set ι).pi u ⊆ s := by rw [isOpen_iff_nhds] simp_rw [le_principal_iff, nhds_pi, Filter.mem_pi', mem_nhds_iff] refine forall₂_congr fun a _ => ⟨?_, ?_⟩ · rintro ⟨I, t, ⟨h1, h2⟩⟩ refine ⟨I, fun a => eval a '' (I : Set ι).pi fun a => (h1 a).choose, fun i hi => ?_, ?_⟩ · simp_rw [eval_image_pi (Finset.mem_coe.mpr hi) (pi_nonempty_iff.mpr fun i => ⟨_, fun _ => (h1 i).choose_spec.2.2⟩)] exact (h1 i).choose_spec.2 · exact Subset.trans (pi_mono fun i hi => (eval_image_pi_subset hi).trans (h1 i).choose_spec.1) h2 · rintro ⟨I, t, ⟨h1, h2⟩⟩ classical refine ⟨I, fun a => ite (a ∈ I) (t a) univ, fun i => ?_, ?_⟩ · by_cases hi : i ∈ I · use t i simp_rw [if_pos hi] exact ⟨Subset.rfl, (h1 i) hi⟩ · use univ simp_rw [if_neg hi] exact ⟨Subset.rfl, isOpen_univ, mem_univ _⟩ · rw [← univ_pi_ite] simp only [← ite_and, ← Finset.mem_coe, and_self_iff, univ_pi_ite, h2] theorem isOpen_pi_iff' [Finite ι] {s : Set (∀ a, π a)} : IsOpen s ↔ ∀ f, f ∈ s → ∃ u : ∀ a, Set (π a), (∀ a, IsOpen (u a) ∧ f a ∈ u a) ∧ univ.pi u ⊆ s := by cases nonempty_fintype ι rw [isOpen_iff_nhds] simp_rw [le_principal_iff, nhds_pi, Filter.mem_pi', mem_nhds_iff] refine forall₂_congr fun a _ => ⟨?_, ?_⟩ · rintro ⟨I, t, ⟨h1, h2⟩⟩ refine ⟨fun i => (h1 i).choose, ⟨fun i => (h1 i).choose_spec.2, (pi_mono fun i _ => (h1 i).choose_spec.1).trans (Subset.trans ?_ h2)⟩⟩ rw [← pi_inter_compl (I : Set ι)] exact inter_subset_left · exact fun ⟨u, ⟨h1, _⟩⟩ => ⟨Finset.univ, u, ⟨fun i => ⟨u i, ⟨rfl.subset, h1 i⟩⟩, by rwa [Finset.coe_univ]⟩⟩ theorem isClosed_set_pi {i : Set ι} {s : ∀ a, Set (π a)} (hs : ∀ a ∈ i, IsClosed (s a)) : IsClosed (pi i s) := by rw [pi_def]; exact isClosed_biInter fun a ha => (hs _ ha).preimage (continuous_apply _) theorem mem_nhds_of_pi_mem_nhds {I : Set ι} {s : ∀ i, Set (π i)} (a : ∀ i, π i) (hs : I.pi s ∈ 𝓝 a) {i : ι} (hi : i ∈ I) : s i ∈ 𝓝 (a i) := by rw [nhds_pi] at hs; exact mem_of_pi_mem_pi hs hi theorem set_pi_mem_nhds {i : Set ι} {s : ∀ a, Set (π a)} {x : ∀ a, π a} (hi : i.Finite) (hs : ∀ a ∈ i, s a ∈ 𝓝 (x a)) : pi i s ∈ 𝓝 x := by rw [pi_def, biInter_mem hi] exact fun a ha => (continuous_apply a).continuousAt (hs a ha) theorem set_pi_mem_nhds_iff {I : Set ι} (hI : I.Finite) {s : ∀ i, Set (π i)} (a : ∀ i, π i) : I.pi s ∈ 𝓝 a ↔ ∀ i : ι, i ∈ I → s i ∈ 𝓝 (a i) := by rw [nhds_pi, pi_mem_pi_iff hI] theorem interior_pi_set {I : Set ι} (hI : I.Finite) {s : ∀ i, Set (π i)} : interior (pi I s) = I.pi fun i => interior (s i) := by ext a simp only [Set.mem_pi, mem_interior_iff_mem_nhds, set_pi_mem_nhds_iff hI] theorem exists_finset_piecewise_mem_of_mem_nhds [DecidableEq ι] {s : Set (∀ a, π a)} {x : ∀ a, π a} (hs : s ∈ 𝓝 x) (y : ∀ a, π a) : ∃ I : Finset ι, I.piecewise x y ∈ s := by simp only [nhds_pi, Filter.mem_pi'] at hs rcases hs with ⟨I, t, htx, hts⟩ refine ⟨I, hts fun i hi => ?_⟩ simpa [Finset.mem_coe.1 hi] using mem_of_mem_nhds (htx i) theorem pi_generateFrom_eq {π : ι → Type*} {g : ∀ a, Set (Set (π a))} : (@Pi.topologicalSpace ι π fun a => generateFrom (g a)) = generateFrom { t | ∃ (s : ∀ a, Set (π a)) (i : Finset ι), (∀ a ∈ i, s a ∈ g a) ∧ t = pi (↑i) s } := by refine le_antisymm ?_ ?_ · apply le_generateFrom rintro _ ⟨s, i, hi, rfl⟩ letI := fun a => generateFrom (g a) exact isOpen_set_pi i.finite_toSet (fun a ha => GenerateOpen.basic _ (hi a ha)) · classical refine le_iInf fun i => coinduced_le_iff_le_induced.1 <| le_generateFrom fun s hs => ?_ refine GenerateOpen.basic _ ⟨update (fun i => univ) i s, {i}, ?_⟩ simp [hs] theorem pi_eq_generateFrom : Pi.topologicalSpace = generateFrom { g | ∃ (s : ∀ a, Set (π a)) (i : Finset ι), (∀ a ∈ i, IsOpen (s a)) ∧ g = pi (↑i) s } := calc Pi.topologicalSpace _ = @Pi.topologicalSpace ι π fun _ => generateFrom { s | IsOpen s } := by simp only [generateFrom_setOf_isOpen] _ = _ := pi_generateFrom_eq theorem pi_generateFrom_eq_finite {π : ι → Type*} {g : ∀ a, Set (Set (π a))} [Finite ι] (hg : ∀ a, ⋃₀ g a = univ) : (@Pi.topologicalSpace ι π fun a => generateFrom (g a)) = generateFrom { t | ∃ s : ∀ a, Set (π a), (∀ a, s a ∈ g a) ∧ t = pi univ s } := by cases nonempty_fintype ι rw [pi_generateFrom_eq] refine le_antisymm (generateFrom_anti ?_) (le_generateFrom ?_) · exact fun s ⟨t, ht, Eq⟩ => ⟨t, Finset.univ, by simp [ht, Eq]⟩ · rintro s ⟨t, i, ht, rfl⟩ letI := generateFrom { t | ∃ s : ∀ a, Set (π a), (∀ a, s a ∈ g a) ∧ t = pi univ s } refine isOpen_iff_forall_mem_open.2 fun f hf => ?_ choose c hcg hfc using fun a => sUnion_eq_univ_iff.1 (hg a) (f a) refine ⟨pi i t ∩ pi ((↑i)ᶜ : Set ι) c, inter_subset_left, ?_, ⟨hf, fun a _ => hfc a⟩⟩ classical rw [← univ_pi_piecewise] refine GenerateOpen.basic _ ⟨_, fun a => ?_, rfl⟩ by_cases a ∈ i <;> simp [*] theorem induced_to_pi {X : Type*} (f : X → ∀ i, π i) : induced f Pi.topologicalSpace = ⨅ i, induced (f · i) inferInstance := by simp_rw [Pi.topologicalSpace, induced_iInf, induced_compose, Function.comp_def] /-- Suppose `π i` is a family of topological spaces indexed by `i : ι`, and `X` is a type endowed with a family of maps `f i : X → π i` for every `i : ι`, hence inducing a map `g : X → Π i, π i`. This lemma shows that infimum of the topologies on `X` induced by the `f i` as `i : ι` varies is simply the topology on `X` induced by `g : X → Π i, π i` where `Π i, π i` is endowed with the usual product topology. -/ theorem inducing_iInf_to_pi {X : Type*} (f : ∀ i, X → π i) : @IsInducing X (∀ i, π i) (⨅ i, induced (f i) inferInstance) _ fun x i => f i x := letI := ⨅ i, induced (f i) inferInstance; ⟨(induced_to_pi _).symm⟩ variable [Finite ι] [∀ i, DiscreteTopology (π i)] /-- A finite product of discrete spaces is discrete. -/ instance Pi.discreteTopology : DiscreteTopology (∀ i, π i) := singletons_open_iff_discrete.mp fun x => by rw [← univ_pi_singleton] exact isOpen_set_pi finite_univ fun i _ => (isOpen_discrete {x i}) end Pi section Sigma variable {ι κ : Type*} {σ : ι → Type*} {τ : κ → Type*} [∀ i, TopologicalSpace (σ i)] [∀ k, TopologicalSpace (τ k)] [TopologicalSpace X] @[continuity, fun_prop] theorem continuous_sigmaMk {i : ι} : Continuous (@Sigma.mk ι σ i) := continuous_iSup_rng continuous_coinduced_rng theorem isOpen_sigma_iff {s : Set (Sigma σ)} : IsOpen s ↔ ∀ i, IsOpen (Sigma.mk i ⁻¹' s) := by rw [isOpen_iSup_iff] rfl theorem isClosed_sigma_iff {s : Set (Sigma σ)} : IsClosed s ↔ ∀ i, IsClosed (Sigma.mk i ⁻¹' s) := by simp only [← isOpen_compl_iff, isOpen_sigma_iff, preimage_compl] theorem isOpenMap_sigmaMk {i : ι} : IsOpenMap (@Sigma.mk ι σ i) := by intro s hs rw [isOpen_sigma_iff] intro j rcases eq_or_ne j i with (rfl | hne) · rwa [preimage_image_eq _ sigma_mk_injective] · rw [preimage_image_sigmaMk_of_ne hne] exact isOpen_empty theorem isOpen_range_sigmaMk {i : ι} : IsOpen (range (@Sigma.mk ι σ i)) := isOpenMap_sigmaMk.isOpen_range theorem isClosedMap_sigmaMk {i : ι} : IsClosedMap (@Sigma.mk ι σ i) := by intro s hs rw [isClosed_sigma_iff] intro j rcases eq_or_ne j i with (rfl | hne) · rwa [preimage_image_eq _ sigma_mk_injective] · rw [preimage_image_sigmaMk_of_ne hne] exact isClosed_empty theorem isClosed_range_sigmaMk {i : ι} : IsClosed (range (@Sigma.mk ι σ i)) := isClosedMap_sigmaMk.isClosed_range lemma Topology.IsOpenEmbedding.sigmaMk {i : ι} : IsOpenEmbedding (@Sigma.mk ι σ i) := .of_continuous_injective_isOpenMap continuous_sigmaMk sigma_mk_injective isOpenMap_sigmaMk @[deprecated (since := "2024-10-30")] alias isOpenEmbedding_sigmaMk := IsOpenEmbedding.sigmaMk lemma Topology.IsClosedEmbedding.sigmaMk {i : ι} : IsClosedEmbedding (@Sigma.mk ι σ i) := .of_continuous_injective_isClosedMap continuous_sigmaMk sigma_mk_injective isClosedMap_sigmaMk @[deprecated (since := "2024-10-30")] alias isClosedEmbedding_sigmaMk := IsClosedEmbedding.sigmaMk lemma Topology.IsEmbedding.sigmaMk {i : ι} : IsEmbedding (@Sigma.mk ι σ i) := IsClosedEmbedding.sigmaMk.1 @[deprecated (since := "2024-10-26")] alias embedding_sigmaMk := IsEmbedding.sigmaMk theorem Sigma.nhds_mk (i : ι) (x : σ i) : 𝓝 (⟨i, x⟩ : Sigma σ) = Filter.map (Sigma.mk i) (𝓝 x) := (IsOpenEmbedding.sigmaMk.map_nhds_eq x).symm theorem Sigma.nhds_eq (x : Sigma σ) : 𝓝 x = Filter.map (Sigma.mk x.1) (𝓝 x.2) := by cases x apply Sigma.nhds_mk theorem comap_sigmaMk_nhds (i : ι) (x : σ i) : comap (Sigma.mk i) (𝓝 ⟨i, x⟩) = 𝓝 x := (IsEmbedding.sigmaMk.nhds_eq_comap _).symm theorem isOpen_sigma_fst_preimage (s : Set ι) : IsOpen (Sigma.fst ⁻¹' s : Set (Σ a, σ a)) := by rw [← biUnion_of_singleton s, preimage_iUnion₂] simp only [← range_sigmaMk] exact isOpen_biUnion fun _ _ => isOpen_range_sigmaMk /-- A map out of a sum type is continuous iff its restriction to each summand is. -/ @[simp] theorem continuous_sigma_iff {f : Sigma σ → X} : Continuous f ↔ ∀ i, Continuous fun a => f ⟨i, a⟩ := by delta instTopologicalSpaceSigma rw [continuous_iSup_dom] exact forall_congr' fun _ => continuous_coinduced_dom /-- A map out of a sum type is continuous if its restriction to each summand is. -/ @[continuity, fun_prop] theorem continuous_sigma {f : Sigma σ → X} (hf : ∀ i, Continuous fun a => f ⟨i, a⟩) : Continuous f := continuous_sigma_iff.2 hf /-- A map defined on a sigma type (a.k.a. the disjoint union of an indexed family of topological spaces) is inducing iff its restriction to each component is inducing and each the image of each component under `f` can be separated from the images of all other components by an open set. -/ theorem inducing_sigma {f : Sigma σ → X} : IsInducing f ↔ (∀ i, IsInducing (f ∘ Sigma.mk i)) ∧ (∀ i, ∃ U, IsOpen U ∧ ∀ x, f x ∈ U ↔ x.1 = i) := by refine ⟨fun h ↦ ⟨fun i ↦ h.comp IsEmbedding.sigmaMk.1, fun i ↦ ?_⟩, ?_⟩ · rcases h.isOpen_iff.1 (isOpen_range_sigmaMk (i := i)) with ⟨U, hUo, hU⟩ refine ⟨U, hUo, ?_⟩ simpa [Set.ext_iff] using hU · refine fun ⟨h₁, h₂⟩ ↦ isInducing_iff_nhds.2 fun ⟨i, x⟩ ↦ ?_ rw [Sigma.nhds_mk, (h₁ i).nhds_eq_comap, comp_apply, ← comap_comap, map_comap_of_mem] rcases h₂ i with ⟨U, hUo, hU⟩ filter_upwards [preimage_mem_comap <| hUo.mem_nhds <| (hU _).2 rfl] with y hy simpa [hU] using hy @[simp 1100] theorem continuous_sigma_map {f₁ : ι → κ} {f₂ : ∀ i, σ i → τ (f₁ i)} : Continuous (Sigma.map f₁ f₂) ↔ ∀ i, Continuous (f₂ i) := continuous_sigma_iff.trans <| by simp only [Sigma.map, IsEmbedding.sigmaMk.continuous_iff, comp_def] @[continuity, fun_prop] theorem Continuous.sigma_map {f₁ : ι → κ} {f₂ : ∀ i, σ i → τ (f₁ i)} (hf : ∀ i, Continuous (f₂ i)) : Continuous (Sigma.map f₁ f₂) := continuous_sigma_map.2 hf theorem isOpenMap_sigma {f : Sigma σ → X} : IsOpenMap f ↔ ∀ i, IsOpenMap fun a => f ⟨i, a⟩ := by simp only [isOpenMap_iff_nhds_le, Sigma.forall, Sigma.nhds_eq, map_map, comp_def] theorem isOpenMap_sigma_map {f₁ : ι → κ} {f₂ : ∀ i, σ i → τ (f₁ i)} : IsOpenMap (Sigma.map f₁ f₂) ↔ ∀ i, IsOpenMap (f₂ i) := isOpenMap_sigma.trans <| forall_congr' fun i => (@IsOpenEmbedding.sigmaMk _ _ _ (f₁ i)).isOpenMap_iff.symm lemma Topology.isInducing_sigmaMap {f₁ : ι → κ} {f₂ : ∀ i, σ i → τ (f₁ i)} (h₁ : Injective f₁) : IsInducing (Sigma.map f₁ f₂) ↔ ∀ i, IsInducing (f₂ i) := by simp only [isInducing_iff_nhds, Sigma.forall, Sigma.nhds_mk, Sigma.map_mk, ← map_sigma_mk_comap h₁, map_inj sigma_mk_injective] @[deprecated (since := "2024-10-28")] alias inducing_sigma_map := isInducing_sigmaMap lemma Topology.isEmbedding_sigmaMap {f₁ : ι → κ} {f₂ : ∀ i, σ i → τ (f₁ i)} (h : Injective f₁) : IsEmbedding (Sigma.map f₁ f₂) ↔ ∀ i, IsEmbedding (f₂ i) := by simp only [isEmbedding_iff, Injective.sigma_map, isInducing_sigmaMap h, forall_and, h.sigma_map_iff] @[deprecated (since := "2024-10-26")] alias embedding_sigma_map := isEmbedding_sigmaMap lemma Topology.isOpenEmbedding_sigmaMap {f₁ : ι → κ} {f₂ : ∀ i, σ i → τ (f₁ i)} (h : Injective f₁) : IsOpenEmbedding (Sigma.map f₁ f₂) ↔ ∀ i, IsOpenEmbedding (f₂ i) := by simp only [isOpenEmbedding_iff_isEmbedding_isOpenMap, isOpenMap_sigma_map, isEmbedding_sigmaMap h, forall_and] @[deprecated (since := "2024-10-30")] alias isOpenEmbedding_sigma_map := isOpenEmbedding_sigmaMap end Sigma section ULift theorem ULift.isOpen_iff [TopologicalSpace X] {s : Set (ULift.{v} X)} : IsOpen s ↔ IsOpen (ULift.up ⁻¹' s) := by rw [ULift.topologicalSpace, ← Equiv.ulift_apply, ← Equiv.ulift.coinduced_symm, ← isOpen_coinduced] theorem ULift.isClosed_iff [TopologicalSpace X] {s : Set (ULift.{v} X)} : IsClosed s ↔ IsClosed (ULift.up ⁻¹' s) := by rw [← isOpen_compl_iff, ← isOpen_compl_iff, isOpen_iff, preimage_compl] @[continuity, fun_prop] theorem continuous_uliftDown [TopologicalSpace X] : Continuous (ULift.down : ULift.{v, u} X → X) := continuous_induced_dom @[continuity, fun_prop] theorem continuous_uliftUp [TopologicalSpace X] : Continuous (ULift.up : X → ULift.{v, u} X) := continuous_induced_rng.2 continuous_id @[deprecated (since := "2025-02-10")] alias continuous_uLift_down := continuous_uliftDown @[deprecated (since := "2025-02-10")] alias continuous_uLift_up := continuous_uliftUp @[continuity, fun_prop] theorem continuous_uliftMap [TopologicalSpace X] [TopologicalSpace Y] (f : X → Y) (hf : Continuous f) : Continuous (ULift.map f : ULift.{u'} X → ULift.{v'} Y) := by change Continuous (ULift.up ∘ f ∘ ULift.down) fun_prop lemma Topology.IsEmbedding.uliftDown [TopologicalSpace X] : IsEmbedding (ULift.down : ULift.{v, u} X → X) := ⟨⟨rfl⟩, ULift.down_injective⟩ @[deprecated (since := "2024-10-26")] alias embedding_uLift_down := IsEmbedding.uliftDown lemma Topology.IsClosedEmbedding.uliftDown [TopologicalSpace X] : IsClosedEmbedding (ULift.down : ULift.{v, u} X → X) := ⟨.uliftDown, by simp only [ULift.down_surjective.range_eq, isClosed_univ]⟩ @[deprecated (since := "2024-10-30")] alias ULift.isClosedEmbedding_down := IsClosedEmbedding.uliftDown instance [TopologicalSpace X] [DiscreteTopology X] : DiscreteTopology (ULift X) := IsEmbedding.uliftDown.discreteTopology end ULift section Monad variable [TopologicalSpace X] {s : Set X} {t : Set s} theorem IsOpen.trans (ht : IsOpen t) (hs : IsOpen s) : IsOpen (t : Set X) := by rcases isOpen_induced_iff.mp ht with ⟨s', hs', rfl⟩ rw [Subtype.image_preimage_coe] exact hs.inter hs' theorem IsClosed.trans (ht : IsClosed t) (hs : IsClosed s) : IsClosed (t : Set X) := by rcases isClosed_induced_iff.mp ht with ⟨s', hs', rfl⟩ rw [Subtype.image_preimage_coe] exact hs.inter hs' end Monad section NhdsSet variable [TopologicalSpace X] [TopologicalSpace Y] {s : Set X} {t : Set Y} /-- The product of a neighborhood of `s` and a neighborhood of `t` is a neighborhood of `s ×ˢ t`, formulated in terms of a filter inequality. -/ theorem nhdsSet_prod_le (s : Set X) (t : Set Y) : 𝓝ˢ (s ×ˢ t) ≤ 𝓝ˢ s ×ˢ 𝓝ˢ t := ((hasBasis_nhdsSet _).prod (hasBasis_nhdsSet _)).ge_iff.2 fun (_u, _v) ⟨⟨huo, hsu⟩, hvo, htv⟩ ↦ (huo.prod hvo).mem_nhdsSet.2 <| prod_mono hsu htv theorem Filter.eventually_nhdsSet_prod_iff {p : X × Y → Prop} : (∀ᶠ q in 𝓝ˢ (s ×ˢ t), p q) ↔ ∀ x ∈ s, ∀ y ∈ t, ∃ px : X → Prop, (∀ᶠ x' in 𝓝 x, px x') ∧ ∃ py : Y → Prop, (∀ᶠ y' in 𝓝 y, py y') ∧ ∀ {x : X}, px x → ∀ {y : Y}, py y → p (x, y) := by simp_rw [eventually_nhdsSet_iff_forall, forall_prod_set, nhds_prod_eq, eventually_prod_iff] theorem Filter.Eventually.prod_nhdsSet {p : X × Y → Prop} {px : X → Prop} {py : Y → Prop} (hp : ∀ {x : X}, px x → ∀ {y : Y}, py y → p (x, y)) (hs : ∀ᶠ x in 𝓝ˢ s, px x) (ht : ∀ᶠ y in 𝓝ˢ t, py y) : ∀ᶠ q in 𝓝ˢ (s ×ˢ t), p q := nhdsSet_prod_le _ _ (mem_of_superset (prod_mem_prod hs ht) fun _ ⟨hx, hy⟩ ↦ hp hx hy) end NhdsSet
Mathlib/Topology/Constructions.lean
1,365
1,369
/- Copyright (c) 2020 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker -/ import Mathlib.Analysis.Calculus.Deriv.Inv import Mathlib.Analysis.Calculus.Deriv.MeanValue /-! # L'Hôpital's rule for 0/0 indeterminate forms In this file, we prove several forms of "L'Hôpital's rule" for computing 0/0 indeterminate forms. The proof of `HasDerivAt.lhopital_zero_right_on_Ioo` is based on the one given in the corresponding [Wikibooks](https://en.wikibooks.org/wiki/Calculus/L%27H%C3%B4pital%27s_Rule) chapter, and all other statements are derived from this one by composing by carefully chosen functions. Note that the filter `f'/g'` tends to isn't required to be one of `𝓝 a`, `atTop` or `atBot`. In fact, we give a slightly stronger statement by allowing it to be any filter on `ℝ`. Each statement is available in a `HasDerivAt` form and a `deriv` form, which is denoted by each statement being in either the `HasDerivAt` or the `deriv` namespace. ## Tags L'Hôpital's rule, L'Hopital's rule -/ open Filter Set open scoped Filter Topology Pointwise variable {a b : ℝ} {l : Filter ℝ} {f f' g g' : ℝ → ℝ} /-! ## Interval-based versions We start by proving statements where all conditions (derivability, `g' ≠ 0`) have to be satisfied on an explicitly-provided interval. -/ namespace HasDerivAt theorem lhopital_zero_right_on_Ioo (hab : a < b) (hff' : ∀ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : ∀ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hg' : ∀ x ∈ Ioo a b, g' x ≠ 0) (hfa : Tendsto f (𝓝[>] a) (𝓝 0)) (hga : Tendsto g (𝓝[>] a) (𝓝 0)) (hdiv : Tendsto (fun x => f' x / g' x) (𝓝[>] a) l) : Tendsto (fun x => f x / g x) (𝓝[>] a) l := by have sub : ∀ x ∈ Ioo a b, Ioo a x ⊆ Ioo a b := fun x hx => Ioo_subset_Ioo (le_refl a) (le_of_lt hx.2) have hg : ∀ x ∈ Ioo a b, g x ≠ 0 := by intro x hx h have : Tendsto g (𝓝[<] x) (𝓝 0) := by rw [← h, ← nhdsWithin_Ioo_eq_nhdsLT hx.1] exact ((hgg' x hx).continuousAt.continuousWithinAt.mono <| sub x hx).tendsto obtain ⟨y, hyx, hy⟩ : ∃ c ∈ Ioo a x, g' c = 0 := exists_hasDerivAt_eq_zero' hx.1 hga this fun y hy => hgg' y <| sub x hx hy exact hg' y (sub x hx hyx) hy have : ∀ x ∈ Ioo a b, ∃ c ∈ Ioo a x, f x * g' c = g x * f' c := by intro x hx rw [← sub_zero (f x), ← sub_zero (g x)] exact exists_ratio_hasDerivAt_eq_ratio_slope' g g' hx.1 f f' (fun y hy => hgg' y <| sub x hx hy) (fun y hy => hff' y <| sub x hx hy) hga hfa (tendsto_nhdsWithin_of_tendsto_nhds (hgg' x hx).continuousAt.tendsto) (tendsto_nhdsWithin_of_tendsto_nhds (hff' x hx).continuousAt.tendsto) choose! c hc using this have : ∀ x ∈ Ioo a b, ((fun x' => f' x' / g' x') ∘ c) x = f x / g x := by intro x hx rcases hc x hx with ⟨h₁, h₂⟩ field_simp [hg x hx, hg' (c x) ((sub x hx) h₁)] simp only [h₂] rw [mul_comm] have cmp : ∀ x ∈ Ioo a b, a < c x ∧ c x < x := fun x hx => (hc x hx).1 rw [← nhdsWithin_Ioo_eq_nhdsGT hab] apply tendsto_nhdsWithin_congr this apply hdiv.comp refine tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ (tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds (tendsto_nhdsWithin_of_tendsto_nhds tendsto_id) ?_ ?_) ?_ all_goals apply eventually_nhdsWithin_of_forall intro x hx have := cmp x hx try simp linarith [this] theorem lhopital_zero_right_on_Ico (hab : a < b) (hff' : ∀ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : ∀ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hcf : ContinuousOn f (Ico a b)) (hcg : ContinuousOn g (Ico a b)) (hg' : ∀ x ∈ Ioo a b, g' x ≠ 0) (hfa : f a = 0) (hga : g a = 0) (hdiv : Tendsto (fun x => f' x / g' x) (𝓝[>] a) l) : Tendsto (fun x => f x / g x) (𝓝[>] a) l := by refine lhopital_zero_right_on_Ioo hab hff' hgg' hg' ?_ ?_ hdiv · rw [← hfa, ← nhdsWithin_Ioo_eq_nhdsGT hab] exact ((hcf a <| left_mem_Ico.mpr hab).mono Ioo_subset_Ico_self).tendsto · rw [← hga, ← nhdsWithin_Ioo_eq_nhdsGT hab] exact ((hcg a <| left_mem_Ico.mpr hab).mono Ioo_subset_Ico_self).tendsto theorem lhopital_zero_left_on_Ioo (hab : a < b) (hff' : ∀ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : ∀ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hg' : ∀ x ∈ Ioo a b, g' x ≠ 0) (hfb : Tendsto f (𝓝[<] b) (𝓝 0)) (hgb : Tendsto g (𝓝[<] b) (𝓝 0)) (hdiv : Tendsto (fun x => f' x / g' x) (𝓝[<] b) l) : Tendsto (fun x => f x / g x) (𝓝[<] b) l := by -- Here, we essentially compose by `Neg.neg`. The following is mostly technical details. have hdnf : ∀ x ∈ -Ioo a b, HasDerivAt (f ∘ Neg.neg) (f' (-x) * -1) x := fun x hx => comp x (hff' (-x) hx) (hasDerivAt_neg x) have hdng : ∀ x ∈ -Ioo a b, HasDerivAt (g ∘ Neg.neg) (g' (-x) * -1) x := fun x hx => comp x (hgg' (-x) hx) (hasDerivAt_neg x) rw [neg_Ioo] at hdnf rw [neg_Ioo] at hdng have := lhopital_zero_right_on_Ioo (neg_lt_neg hab) hdnf hdng (by intro x hx h apply hg' _ (by rw [← neg_Ioo] at hx; exact hx) rwa [mul_comm, ← neg_eq_neg_one_mul, neg_eq_zero] at h) (hfb.comp tendsto_neg_nhdsGT_neg) (hgb.comp tendsto_neg_nhdsGT_neg) (by simp only [neg_div_neg_eq, mul_one, mul_neg] exact hdiv.comp tendsto_neg_nhdsGT_neg) have := this.comp tendsto_neg_nhdsLT unfold Function.comp at this simpa only [neg_neg] theorem lhopital_zero_left_on_Ioc (hab : a < b) (hff' : ∀ x ∈ Ioo a b, HasDerivAt f (f' x) x) (hgg' : ∀ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hcf : ContinuousOn f (Ioc a b)) (hcg : ContinuousOn g (Ioc a b)) (hg' : ∀ x ∈ Ioo a b, g' x ≠ 0) (hfb : f b = 0) (hgb : g b = 0) (hdiv : Tendsto (fun x => f' x / g' x) (𝓝[<] b) l) : Tendsto (fun x => f x / g x) (𝓝[<] b) l := by refine lhopital_zero_left_on_Ioo hab hff' hgg' hg' ?_ ?_ hdiv · rw [← hfb, ← nhdsWithin_Ioo_eq_nhdsLT hab] exact ((hcf b <| right_mem_Ioc.mpr hab).mono Ioo_subset_Ioc_self).tendsto · rw [← hgb, ← nhdsWithin_Ioo_eq_nhdsLT hab] exact ((hcg b <| right_mem_Ioc.mpr hab).mono Ioo_subset_Ioc_self).tendsto theorem lhopital_zero_atTop_on_Ioi (hff' : ∀ x ∈ Ioi a, HasDerivAt f (f' x) x) (hgg' : ∀ x ∈ Ioi a, HasDerivAt g (g' x) x) (hg' : ∀ x ∈ Ioi a, g' x ≠ 0) (hftop : Tendsto f atTop (𝓝 0)) (hgtop : Tendsto g atTop (𝓝 0)) (hdiv : Tendsto (fun x => f' x / g' x) atTop l) : Tendsto (fun x => f x / g x) atTop l := by obtain ⟨a', haa', ha'⟩ : ∃ a', a < a' ∧ 0 < a' := ⟨1 + max a 0, ⟨lt_of_le_of_lt (le_max_left a 0) (lt_one_add _), lt_of_le_of_lt (le_max_right a 0) (lt_one_add _)⟩⟩ have fact1 : ∀ x : ℝ, x ∈ Ioo 0 a'⁻¹ → x ≠ 0 := fun _ hx => (ne_of_lt hx.1).symm have fact2 (x) (hx : x ∈ Ioo 0 a'⁻¹) : a < x⁻¹ := lt_trans haa' ((lt_inv_comm₀ ha' hx.1).mpr hx.2) have hdnf : ∀ x ∈ Ioo 0 a'⁻¹, HasDerivAt (f ∘ Inv.inv) (f' x⁻¹ * -(x ^ 2)⁻¹) x := fun x hx => comp x (hff' x⁻¹ <| fact2 x hx) (hasDerivAt_inv <| fact1 x hx) have hdng : ∀ x ∈ Ioo 0 a'⁻¹, HasDerivAt (g ∘ Inv.inv) (g' x⁻¹ * -(x ^ 2)⁻¹) x := fun x hx => comp x (hgg' x⁻¹ <| fact2 x hx) (hasDerivAt_inv <| fact1 x hx) have := lhopital_zero_right_on_Ioo (inv_pos.mpr ha') hdnf hdng (by intro x hx refine mul_ne_zero ?_ (neg_ne_zero.mpr <| inv_ne_zero <| pow_ne_zero _ <| fact1 x hx) exact hg' _ (fact2 x hx)) (hftop.comp tendsto_inv_nhdsGT_zero) (hgtop.comp tendsto_inv_nhdsGT_zero) (by refine (tendsto_congr' ?_).mp (hdiv.comp tendsto_inv_nhdsGT_zero) filter_upwards [self_mem_nhdsWithin] with x (hx : 0 < x) simp only [Function.comp_def] rw [mul_div_mul_right] exact neg_ne_zero.mpr (by positivity)) have := this.comp tendsto_inv_atTop_nhdsGT_zero unfold Function.comp at this simpa only [inv_inv] theorem lhopital_zero_atBot_on_Iio (hff' : ∀ x ∈ Iio a, HasDerivAt f (f' x) x) (hgg' : ∀ x ∈ Iio a, HasDerivAt g (g' x) x) (hg' : ∀ x ∈ Iio a, g' x ≠ 0) (hfbot : Tendsto f atBot (𝓝 0)) (hgbot : Tendsto g atBot (𝓝 0)) (hdiv : Tendsto (fun x => f' x / g' x) atBot l) : Tendsto (fun x => f x / g x) atBot l := by -- Here, we essentially compose by `Neg.neg`. The following is mostly technical details. have hdnf : ∀ x ∈ -Iio a, HasDerivAt (f ∘ Neg.neg) (f' (-x) * -1) x := fun x hx => comp x (hff' (-x) hx) (hasDerivAt_neg x) have hdng : ∀ x ∈ -Iio a, HasDerivAt (g ∘ Neg.neg) (g' (-x) * -1) x := fun x hx => comp x (hgg' (-x) hx) (hasDerivAt_neg x) rw [neg_Iio] at hdnf rw [neg_Iio] at hdng have := lhopital_zero_atTop_on_Ioi hdnf hdng (by intro x hx h apply hg' _ (by rw [← neg_Iio] at hx; exact hx) rwa [mul_comm, ← neg_eq_neg_one_mul, neg_eq_zero] at h) (hfbot.comp tendsto_neg_atTop_atBot) (hgbot.comp tendsto_neg_atTop_atBot) (by simp only [mul_one, mul_neg, neg_div_neg_eq] exact (hdiv.comp tendsto_neg_atTop_atBot)) have := this.comp tendsto_neg_atBot_atTop unfold Function.comp at this simpa only [neg_neg] end HasDerivAt namespace deriv theorem lhopital_zero_right_on_Ioo (hab : a < b) (hdf : DifferentiableOn ℝ f (Ioo a b)) (hg' : ∀ x ∈ Ioo a b, deriv g x ≠ 0) (hfa : Tendsto f (𝓝[>] a) (𝓝 0)) (hga : Tendsto g (𝓝[>] a) (𝓝 0)) (hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) (𝓝[>] a) l) : Tendsto (fun x => f x / g x) (𝓝[>] a) l := by have hdf : ∀ x ∈ Ioo a b, DifferentiableAt ℝ f x := fun x hx => (hdf x hx).differentiableAt (Ioo_mem_nhds hx.1 hx.2) have hdg : ∀ x ∈ Ioo a b, DifferentiableAt ℝ g x := fun x hx => by_contradiction fun h => hg' x hx (deriv_zero_of_not_differentiableAt h) exact HasDerivAt.lhopital_zero_right_on_Ioo hab (fun x hx => (hdf x hx).hasDerivAt) (fun x hx => (hdg x hx).hasDerivAt) hg' hfa hga hdiv
theorem lhopital_zero_right_on_Ico (hab : a < b) (hdf : DifferentiableOn ℝ f (Ioo a b)) (hcf : ContinuousOn f (Ico a b)) (hcg : ContinuousOn g (Ico a b)) (hg' : ∀ x ∈ Ioo a b, (deriv g) x ≠ 0) (hfa : f a = 0) (hga : g a = 0) (hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) (𝓝[>] a) l) : Tendsto (fun x => f x / g x) (𝓝[>] a) l := by refine lhopital_zero_right_on_Ioo hab hdf hg' ?_ ?_ hdiv · rw [← hfa, ← nhdsWithin_Ioo_eq_nhdsGT hab] exact ((hcf a <| left_mem_Ico.mpr hab).mono Ioo_subset_Ico_self).tendsto · rw [← hga, ← nhdsWithin_Ioo_eq_nhdsGT hab] exact ((hcg a <| left_mem_Ico.mpr hab).mono Ioo_subset_Ico_self).tendsto
Mathlib/Analysis/Calculus/LHopital.lean
206
216
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Ring.Associated import Mathlib.Algebra.Star.Unitary import Mathlib.RingTheory.PrincipalIdealDomain import Mathlib.Tactic.Ring import Mathlib.Algebra.EuclideanDomain.Int /-! # ℤ[√d] The ring of integers adjoined with a square root of `d : ℤ`. After defining the norm, we show that it is a linearly ordered commutative ring, as well as an integral domain. We provide the universal property, that ring homomorphisms `ℤ√d →+* R` correspond to choices of square roots of `d` in `R`. -/ /-- The ring of integers adjoined with a square root of `d`. These have the form `a + b √d` where `a b : ℤ`. The components are called `re` and `im` by analogy to the negative `d` case. -/ @[ext] structure Zsqrtd (d : ℤ) where /-- Component of the integer not multiplied by `√d` -/ re : ℤ /-- Component of the integer multiplied by `√d` -/ im : ℤ deriving DecidableEq @[inherit_doc] prefix:100 "ℤ√" => Zsqrtd namespace Zsqrtd section variable {d : ℤ} /-- Convert an integer to a `ℤ√d` -/ def ofInt (n : ℤ) : ℤ√d := ⟨n, 0⟩ theorem ofInt_re (n : ℤ) : (ofInt n : ℤ√d).re = n := rfl theorem ofInt_im (n : ℤ) : (ofInt n : ℤ√d).im = 0 := rfl /-- The zero of the ring -/ instance : Zero (ℤ√d) := ⟨ofInt 0⟩ @[simp] theorem zero_re : (0 : ℤ√d).re = 0 := rfl @[simp] theorem zero_im : (0 : ℤ√d).im = 0 := rfl instance : Inhabited (ℤ√d) := ⟨0⟩ /-- The one of the ring -/ instance : One (ℤ√d) := ⟨ofInt 1⟩ @[simp] theorem one_re : (1 : ℤ√d).re = 1 := rfl @[simp] theorem one_im : (1 : ℤ√d).im = 0 := rfl /-- The representative of `√d` in the ring -/ def sqrtd : ℤ√d := ⟨0, 1⟩ @[simp] theorem sqrtd_re : (sqrtd : ℤ√d).re = 0 := rfl @[simp] theorem sqrtd_im : (sqrtd : ℤ√d).im = 1 := rfl /-- Addition of elements of `ℤ√d` -/ instance : Add (ℤ√d) := ⟨fun z w => ⟨z.1 + w.1, z.2 + w.2⟩⟩ @[simp] theorem add_def (x y x' y' : ℤ) : (⟨x, y⟩ + ⟨x', y'⟩ : ℤ√d) = ⟨x + x', y + y'⟩ := rfl @[simp] theorem add_re (z w : ℤ√d) : (z + w).re = z.re + w.re := rfl @[simp] theorem add_im (z w : ℤ√d) : (z + w).im = z.im + w.im := rfl /-- Negation in `ℤ√d` -/ instance : Neg (ℤ√d) := ⟨fun z => ⟨-z.1, -z.2⟩⟩ @[simp] theorem neg_re (z : ℤ√d) : (-z).re = -z.re := rfl @[simp] theorem neg_im (z : ℤ√d) : (-z).im = -z.im := rfl /-- Multiplication in `ℤ√d` -/ instance : Mul (ℤ√d) := ⟨fun z w => ⟨z.1 * w.1 + d * z.2 * w.2, z.1 * w.2 + z.2 * w.1⟩⟩ @[simp] theorem mul_re (z w : ℤ√d) : (z * w).re = z.re * w.re + d * z.im * w.im := rfl @[simp] theorem mul_im (z w : ℤ√d) : (z * w).im = z.re * w.im + z.im * w.re := rfl instance addCommGroup : AddCommGroup (ℤ√d) := by refine { add := (· + ·) zero := (0 : ℤ√d) sub := fun a b => a + -b neg := Neg.neg nsmul := @nsmulRec (ℤ√d) ⟨0⟩ ⟨(· + ·)⟩ zsmul := @zsmulRec (ℤ√d) ⟨0⟩ ⟨(· + ·)⟩ ⟨Neg.neg⟩ (@nsmulRec (ℤ√d) ⟨0⟩ ⟨(· + ·)⟩) add_assoc := ?_ zero_add := ?_ add_zero := ?_ neg_add_cancel := ?_ add_comm := ?_ } <;> intros <;> ext <;> simp [add_comm, add_left_comm] @[simp] theorem sub_re (z w : ℤ√d) : (z - w).re = z.re - w.re := rfl @[simp] theorem sub_im (z w : ℤ√d) : (z - w).im = z.im - w.im := rfl instance addGroupWithOne : AddGroupWithOne (ℤ√d) := { Zsqrtd.addCommGroup with natCast := fun n => ofInt n intCast := ofInt one := 1 } instance commRing : CommRing (ℤ√d) := by refine { Zsqrtd.addGroupWithOne with mul := (· * ·) npow := @npowRec (ℤ√d) ⟨1⟩ ⟨(· * ·)⟩, add_comm := ?_ left_distrib := ?_ right_distrib := ?_ zero_mul := ?_ mul_zero := ?_ mul_assoc := ?_ one_mul := ?_ mul_one := ?_ mul_comm := ?_ } <;> intros <;> ext <;> simp <;> ring instance : AddMonoid (ℤ√d) := by infer_instance instance : Monoid (ℤ√d) := by infer_instance instance : CommMonoid (ℤ√d) := by infer_instance instance : CommSemigroup (ℤ√d) := by infer_instance instance : Semigroup (ℤ√d) := by infer_instance instance : AddCommSemigroup (ℤ√d) := by infer_instance instance : AddSemigroup (ℤ√d) := by infer_instance instance : CommSemiring (ℤ√d) := by infer_instance instance : Semiring (ℤ√d) := by infer_instance instance : Ring (ℤ√d) := by infer_instance instance : Distrib (ℤ√d) := by infer_instance /-- Conjugation in `ℤ√d`. The conjugate of `a + b √d` is `a - b √d`. -/ instance : Star (ℤ√d) where star z := ⟨z.1, -z.2⟩ @[simp] theorem star_mk (x y : ℤ) : star (⟨x, y⟩ : ℤ√d) = ⟨x, -y⟩ := rfl @[simp] theorem star_re (z : ℤ√d) : (star z).re = z.re := rfl @[simp] theorem star_im (z : ℤ√d) : (star z).im = -z.im := rfl instance : StarRing (ℤ√d) where star_involutive _ := Zsqrtd.ext rfl (neg_neg _) star_mul a b := by ext <;> simp <;> ring star_add _ _ := Zsqrtd.ext rfl (neg_add _ _) -- Porting note: proof was `by decide` instance nontrivial : Nontrivial (ℤ√d) := ⟨⟨0, 1, Zsqrtd.ext_iff.not.mpr (by simp)⟩⟩ @[simp] theorem natCast_re (n : ℕ) : (n : ℤ√d).re = n := rfl @[simp] theorem ofNat_re (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℤ√d).re = n := rfl @[simp] theorem natCast_im (n : ℕ) : (n : ℤ√d).im = 0 := rfl @[simp] theorem ofNat_im (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℤ√d).im = 0 := rfl theorem natCast_val (n : ℕ) : (n : ℤ√d) = ⟨n, 0⟩ := rfl @[simp] theorem intCast_re (n : ℤ) : (n : ℤ√d).re = n := by cases n <;> rfl @[simp] theorem intCast_im (n : ℤ) : (n : ℤ√d).im = 0 := by cases n <;> rfl theorem intCast_val (n : ℤ) : (n : ℤ√d) = ⟨n, 0⟩ := by ext <;> simp instance : CharZero (ℤ√d) where cast_injective m n := by simp [Zsqrtd.ext_iff] @[simp] theorem ofInt_eq_intCast (n : ℤ) : (ofInt n : ℤ√d) = n := by ext <;> simp [ofInt_re, ofInt_im] @[simp] theorem nsmul_val (n : ℕ) (x y : ℤ) : (n : ℤ√d) * ⟨x, y⟩ = ⟨n * x, n * y⟩ := by ext <;> simp @[simp] theorem smul_val (n x y : ℤ) : (n : ℤ√d) * ⟨x, y⟩ = ⟨n * x, n * y⟩ := by ext <;> simp theorem smul_re (a : ℤ) (b : ℤ√d) : (↑a * b).re = a * b.re := by simp theorem smul_im (a : ℤ) (b : ℤ√d) : (↑a * b).im = a * b.im := by simp @[simp] theorem muld_val (x y : ℤ) : sqrtd (d := d) * ⟨x, y⟩ = ⟨d * y, x⟩ := by ext <;> simp @[simp] theorem dmuld : sqrtd (d := d) * sqrtd (d := d) = d := by ext <;> simp @[simp] theorem smuld_val (n x y : ℤ) : sqrtd * (n : ℤ√d) * ⟨x, y⟩ = ⟨d * n * y, n * x⟩ := by ext <;> simp theorem decompose {x y : ℤ} : (⟨x, y⟩ : ℤ√d) = x + sqrtd (d := d) * y := by ext <;> simp theorem mul_star {x y : ℤ} : (⟨x, y⟩ * star ⟨x, y⟩ : ℤ√d) = x * x - d * y * y := by ext <;> simp [sub_eq_add_neg, mul_comm] theorem intCast_dvd (z : ℤ) (a : ℤ√d) : ↑z ∣ a ↔ z ∣ a.re ∧ z ∣ a.im := by
constructor
Mathlib/NumberTheory/Zsqrtd/Basic.lean
287
287
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Johan Commelin -/ import Mathlib.CategoryTheory.Limits.Shapes.Terminal /-! # Zero objects 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; see `CategoryTheory.Limits.Shapes.ZeroMorphisms`. ## References * [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2] -/ noncomputable section universe v u v' u' open CategoryTheory open CategoryTheory.Category variable {C : Type u} [Category.{v} C] variable {D : Type u'} [Category.{v'} D] namespace CategoryTheory namespace Limits /-- An object `X` in a category is a *zero object* if for every object `Y` there is a unique morphism `to : X → Y` and a unique morphism `from : Y → X`. This is a characteristic predicate for `has_zero_object`. -/ structure IsZero (X : C) : Prop where /-- there are unique morphisms to the object -/ unique_to : ∀ Y, Nonempty (Unique (X ⟶ Y)) /-- there are unique morphisms from the object -/ unique_from : ∀ Y, Nonempty (Unique (Y ⟶ X)) namespace IsZero variable {X Y : C} -- Porting note: `to` is a reserved word, it was replaced by `to_` /-- If `h : IsZero X`, then `h.to_ Y` is a choice of unique morphism `X → Y`. -/ protected def to_ (h : IsZero X) (Y : C) : X ⟶ Y := @default _ <| (h.unique_to Y).some.toInhabited theorem eq_to (h : IsZero X) (f : X ⟶ Y) : f = h.to_ Y := @Unique.eq_default _ (id _) _ theorem to_eq (h : IsZero X) (f : X ⟶ Y) : h.to_ Y = f := (h.eq_to f).symm -- Porting note: `from` is a reserved word, it was replaced by `from_` /-- If `h : is_zero X`, then `h.from_ Y` is a choice of unique morphism `Y → X`. -/ protected def from_ (h : IsZero X) (Y : C) : Y ⟶ X := @default _ <| (h.unique_from Y).some.toInhabited theorem eq_from (h : IsZero X) (f : Y ⟶ X) : f = h.from_ Y := @Unique.eq_default _ (id _) _ theorem from_eq (h : IsZero X) (f : Y ⟶ X) : h.from_ Y = f := (h.eq_from f).symm theorem eq_of_src (hX : IsZero X) (f g : X ⟶ Y) : f = g := (hX.eq_to f).trans (hX.eq_to g).symm theorem eq_of_tgt (hX : IsZero X) (f g : Y ⟶ X) : f = g := (hX.eq_from f).trans (hX.eq_from g).symm lemma epi (h : IsZero X) {Y : C} (f : Y ⟶ X) : Epi f where left_cancellation _ _ _ := h.eq_of_src _ _ lemma mono (h : IsZero X) {Y : C} (f : X ⟶ Y) : Mono f where right_cancellation _ _ _ := h.eq_of_tgt _ _ /-- Any two zero objects are isomorphic. -/ def iso (hX : IsZero X) (hY : IsZero Y) : X ≅ Y where hom := hX.to_ Y inv := hX.from_ Y hom_inv_id := hX.eq_of_src _ _ inv_hom_id := hY.eq_of_src _ _ /-- A zero object is in particular initial. -/ protected def isInitial (hX : IsZero X) : IsInitial X := @IsInitial.ofUnique _ _ X fun Y => (hX.unique_to Y).some /-- A zero object is in particular terminal. -/ protected def isTerminal (hX : IsZero X) : IsTerminal X := @IsTerminal.ofUnique _ _ X fun Y => (hX.unique_from Y).some /-- The (unique) isomorphism between any initial object and the zero object. -/ def isoIsInitial (hX : IsZero X) (hY : IsInitial Y) : X ≅ Y := IsInitial.uniqueUpToIso hX.isInitial hY /-- The (unique) isomorphism between any terminal object and the zero object. -/ def isoIsTerminal (hX : IsZero X) (hY : IsTerminal Y) : X ≅ Y := IsTerminal.uniqueUpToIso hX.isTerminal hY theorem of_iso (hY : IsZero Y) (e : X ≅ Y) : IsZero X := by refine ⟨fun Z => ⟨⟨⟨e.hom ≫ hY.to_ Z⟩, fun f => ?_⟩⟩, fun Z => ⟨⟨⟨hY.from_ Z ≫ e.inv⟩, fun f => ?_⟩⟩⟩ · rw [← cancel_epi e.inv] apply hY.eq_of_src · rw [← cancel_mono e.hom] apply hY.eq_of_tgt theorem op (h : IsZero X) : IsZero (Opposite.op X) := ⟨fun Y => ⟨⟨⟨(h.from_ (Opposite.unop Y)).op⟩, fun _ => Quiver.Hom.unop_inj (h.eq_of_tgt _ _)⟩⟩,
fun Y => ⟨⟨⟨(h.to_ (Opposite.unop Y)).op⟩, fun _ => Quiver.Hom.unop_inj (h.eq_of_src _ _)⟩⟩⟩ theorem unop {X : Cᵒᵖ} (h : IsZero X) : IsZero (Opposite.unop X) := ⟨fun Y => ⟨⟨⟨(h.from_ (Opposite.op Y)).unop⟩, fun _ => Quiver.Hom.op_inj (h.eq_of_tgt _ _)⟩⟩, fun Y => ⟨⟨⟨(h.to_ (Opposite.op Y)).unop⟩, fun _ => Quiver.Hom.op_inj (h.eq_of_src _ _)⟩⟩⟩ end IsZero
Mathlib/CategoryTheory/Limits/Shapes/ZeroObjects.lean
117
123
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Multiset.ZeroCons /-! # Basic results on multisets -/ -- No algebra should be required assert_not_exists Monoid universe v open List Subtype Nat Function variable {α : Type*} {β : Type v} {γ : Type*} namespace Multiset /-! ### `Multiset.toList` -/ section ToList /-- Produces a list of the elements in the multiset using choice. -/ noncomputable def toList (s : Multiset α) := s.out @[simp, norm_cast] theorem coe_toList (s : Multiset α) : (s.toList : Multiset α) = s := s.out_eq' @[simp] theorem toList_eq_nil {s : Multiset α} : s.toList = [] ↔ s = 0 := by rw [← coe_eq_zero, coe_toList] theorem empty_toList {s : Multiset α} : s.toList.isEmpty ↔ s = 0 := by simp @[simp] theorem toList_zero : (Multiset.toList 0 : List α) = [] := toList_eq_nil.mpr rfl @[simp] theorem mem_toList {a : α} {s : Multiset α} : a ∈ s.toList ↔ a ∈ s := by rw [← mem_coe, coe_toList] @[simp] theorem toList_eq_singleton_iff {a : α} {m : Multiset α} : m.toList = [a] ↔ m = {a} := by rw [← perm_singleton, ← coe_eq_coe, coe_toList, coe_singleton] @[simp] theorem toList_singleton (a : α) : ({a} : Multiset α).toList = [a] := Multiset.toList_eq_singleton_iff.2 rfl @[simp] theorem length_toList (s : Multiset α) : s.toList.length = card s := by rw [← coe_card, coe_toList] end ToList /-! ### Induction principles -/ /-- The strong induction principle for multisets. -/ @[elab_as_elim] def strongInductionOn {p : Multiset α → Sort*} (s : Multiset α) (ih : ∀ s, (∀ t < s, p t) → p s) : p s := (ih s) fun t _h => strongInductionOn t ih termination_by card s decreasing_by exact card_lt_card _h theorem strongInductionOn_eq {p : Multiset α → Sort*} (s : Multiset α) (H) : @strongInductionOn _ p s H = H s fun t _h => @strongInductionOn _ p t H := by rw [strongInductionOn] @[elab_as_elim] theorem case_strongInductionOn {p : Multiset α → Prop} (s : Multiset α) (h₀ : p 0) (h₁ : ∀ a s, (∀ t ≤ s, p t) → p (a ::ₘ s)) : p s := Multiset.strongInductionOn s fun s => Multiset.induction_on s (fun _ => h₀) fun _a _s _ ih => (h₁ _ _) fun _t h => ih _ <| lt_of_le_of_lt h <| lt_cons_self _ _ /-- Suppose that, given that `p t` can be defined on all supersets of `s` of cardinality less than `n`, one knows how to define `p s`. Then one can inductively define `p s` for all multisets `s` of cardinality less than `n`, starting from multisets of card `n` and iterating. This can be used either to define data, or to prove properties. -/ def strongDownwardInduction {p : Multiset α → Sort*} {n : ℕ} (H : ∀ t₁, (∀ {t₂ : Multiset α}, card t₂ ≤ n → t₁ < t₂ → p t₂) → card t₁ ≤ n → p t₁) (s : Multiset α) : card s ≤ n → p s := H s fun {t} ht _h => strongDownwardInduction H t ht termination_by n - card s decreasing_by simp_wf; have := (card_lt_card _h); omega theorem strongDownwardInduction_eq {p : Multiset α → Sort*} {n : ℕ} (H : ∀ t₁, (∀ {t₂ : Multiset α}, card t₂ ≤ n → t₁ < t₂ → p t₂) → card t₁ ≤ n → p t₁) (s : Multiset α) : strongDownwardInduction H s = H s fun ht _hst => strongDownwardInduction H _ ht := by rw [strongDownwardInduction] /-- Analogue of `strongDownwardInduction` with order of arguments swapped. -/ @[elab_as_elim] def strongDownwardInductionOn {p : Multiset α → Sort*} {n : ℕ} : ∀ s : Multiset α, (∀ t₁, (∀ {t₂ : Multiset α}, card t₂ ≤ n → t₁ < t₂ → p t₂) → card t₁ ≤ n → p t₁) → card s ≤ n → p s := fun s H => strongDownwardInduction H s theorem strongDownwardInductionOn_eq {p : Multiset α → Sort*} (s : Multiset α) {n : ℕ} (H : ∀ t₁, (∀ {t₂ : Multiset α}, card t₂ ≤ n → t₁ < t₂ → p t₂) → card t₁ ≤ n → p t₁) : s.strongDownwardInductionOn H = H s fun {t} ht _h => t.strongDownwardInductionOn H ht := by dsimp only [strongDownwardInductionOn] rw [strongDownwardInduction] section Choose variable (p : α → Prop) [DecidablePred p] (l : Multiset α) /-- Given a proof `hp` that there exists a unique `a ∈ l` such that `p a`, `chooseX p l hp` returns that `a` together with proofs of `a ∈ l` and `p a`. -/ def chooseX : ∀ _hp : ∃! a, a ∈ l ∧ p a, { a // a ∈ l ∧ p a } := Quotient.recOn l (fun l' ex_unique => List.chooseX p l' (ExistsUnique.exists ex_unique)) (by intros a b _ funext hp suffices all_equal : ∀ x y : { t // t ∈ b ∧ p t }, x = y by apply all_equal rintro ⟨x, px⟩ ⟨y, py⟩ rcases hp with ⟨z, ⟨_z_mem_l, _pz⟩, z_unique⟩ congr calc x = z := z_unique x px _ = y := (z_unique y py).symm ) /-- Given a proof `hp` that there exists a unique `a ∈ l` such that `p a`, `choose p l hp` returns that `a`. -/ def choose (hp : ∃! a, a ∈ l ∧ p a) : α := chooseX p l hp theorem choose_spec (hp : ∃! a, a ∈ l ∧ p a) : choose p l hp ∈ l ∧ p (choose p l hp) := (chooseX p l hp).property theorem choose_mem (hp : ∃! a, a ∈ l ∧ p a) : choose p l hp ∈ l := (choose_spec _ _ _).1 theorem choose_property (hp : ∃! a, a ∈ l ∧ p a) : p (choose p l hp) := (choose_spec _ _ _).2 end Choose variable (α) in /-- The equivalence between lists and multisets of a subsingleton type. -/ def subsingletonEquiv [Subsingleton α] : List α ≃ Multiset α where toFun := ofList invFun := (Quot.lift id) fun (a b : List α) (h : a ~ b) => (List.ext_get h.length_eq) fun _ _ _ => Subsingleton.elim _ _ left_inv _ := rfl right_inv m := Quot.inductionOn m fun _ => rfl @[simp] theorem coe_subsingletonEquiv [Subsingleton α] : (subsingletonEquiv α : List α → Multiset α) = ofList := rfl section SizeOf set_option linter.deprecated false in @[deprecated "Deprecated without replacement." (since := "2025-02-07")] theorem sizeOf_lt_sizeOf_of_mem [SizeOf α] {x : α} {s : Multiset α} (hx : x ∈ s) : SizeOf.sizeOf x < SizeOf.sizeOf s := by induction s using Quot.inductionOn exact List.sizeOf_lt_sizeOf_of_mem hx end SizeOf end Multiset
Mathlib/Data/Multiset/Basic.lean
1,936
1,937
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad, Minchao Wu, Mario Carneiro -/ import Mathlib.Data.Finset.Attach import Mathlib.Data.Finset.Disjoint import Mathlib.Data.Finset.Erase import Mathlib.Data.Finset.Filter import Mathlib.Data.Finset.Range import Mathlib.Data.Finset.SDiff import Mathlib.Data.Multiset.Basic import Mathlib.Logic.Equiv.Set import Mathlib.Order.Directed import Mathlib.Order.Interval.Set.Defs import Mathlib.Data.Set.SymmDiff /-! # Basic lemmas on finite sets This file contains lemmas on the interaction of various definitions on the `Finset` type. For an explanation of `Finset` design decisions, please see `Mathlib/Data/Finset/Defs.lean`. ## Main declarations ### Main definitions * `Finset.choose`: Given a proof `h` of existence and uniqueness of a certain element satisfying a predicate, `choose s h` returns the element of `s` satisfying that predicate. ### Equivalences between finsets * The `Mathlib/Logic/Equiv/Defs.lean` file describes a general type of equivalence, so look in there for any lemmas. There is some API for rewriting sums and products from `s` to `t` given that `s ≃ t`. TODO: examples ## Tags finite sets, finset -/ -- Assert that we define `Finset` without the material on `List.sublists`. -- Note that we cannot use `List.sublists` itself as that is defined very early. assert_not_exists List.sublistsLen Multiset.powerset CompleteLattice Monoid open Multiset Subtype Function universe u variable {α : Type*} {β : Type*} {γ : Type*} namespace Finset -- TODO: these should be global attributes, but this will require fixing other files attribute [local trans] Subset.trans Superset.trans set_option linter.deprecated false in @[deprecated "Deprecated without replacement." (since := "2025-02-07")] theorem sizeOf_lt_sizeOf_of_mem [SizeOf α] {x : α} {s : Finset α} (hx : x ∈ s) : SizeOf.sizeOf x < SizeOf.sizeOf s := by cases s dsimp [SizeOf.sizeOf, SizeOf.sizeOf, Multiset.sizeOf] rw [Nat.add_comm] refine lt_trans ?_ (Nat.lt_succ_self _) exact Multiset.sizeOf_lt_sizeOf_of_mem hx /-! ### Lattice structure -/ section Lattice variable [DecidableEq α] {s s₁ s₂ t t₁ t₂ u v : Finset α} {a b : α} /-! #### union -/ @[simp] theorem disjUnion_eq_union (s t h) : @disjUnion α s t h = s ∪ t := ext fun a => by simp @[simp] theorem disjoint_union_left : Disjoint (s ∪ t) u ↔ Disjoint s u ∧ Disjoint t u := by simp only [disjoint_left, mem_union, or_imp, forall_and] @[simp] theorem disjoint_union_right : Disjoint s (t ∪ u) ↔ Disjoint s t ∧ Disjoint s u := by simp only [disjoint_right, mem_union, or_imp, forall_and] /-! #### inter -/ theorem not_disjoint_iff_nonempty_inter : ¬Disjoint s t ↔ (s ∩ t).Nonempty := not_disjoint_iff.trans <| by simp [Finset.Nonempty] alias ⟨_, Nonempty.not_disjoint⟩ := not_disjoint_iff_nonempty_inter theorem disjoint_or_nonempty_inter (s t : Finset α) : Disjoint s t ∨ (s ∩ t).Nonempty := by rw [← not_disjoint_iff_nonempty_inter] exact em _ omit [DecidableEq α] in theorem disjoint_of_subset_iff_left_eq_empty (h : s ⊆ t) : Disjoint s t ↔ s = ∅ := disjoint_of_le_iff_left_eq_bot h lemma pairwiseDisjoint_iff {ι : Type*} {s : Set ι} {f : ι → Finset α} : s.PairwiseDisjoint f ↔ ∀ ⦃i⦄, i ∈ s → ∀ ⦃j⦄, j ∈ s → (f i ∩ f j).Nonempty → i = j := by simp [Set.PairwiseDisjoint, Set.Pairwise, Function.onFun, not_imp_comm (a := _ = _), not_disjoint_iff_nonempty_inter] end Lattice instance isDirected_le : IsDirected (Finset α) (· ≤ ·) := by classical infer_instance instance isDirected_subset : IsDirected (Finset α) (· ⊆ ·) := isDirected_le /-! ### erase -/ section Erase variable [DecidableEq α] {s t u v : Finset α} {a b : α} @[simp] theorem erase_empty (a : α) : erase ∅ a = ∅ := rfl protected lemma Nontrivial.erase_nonempty (hs : s.Nontrivial) : (s.erase a).Nonempty := (hs.exists_ne a).imp <| by aesop @[simp] lemma erase_nonempty (ha : a ∈ s) : (s.erase a).Nonempty ↔ s.Nontrivial := by simp only [Finset.Nonempty, mem_erase, and_comm (b := _ ∈ _)] refine ⟨?_, fun hs ↦ hs.exists_ne a⟩ rintro ⟨b, hb, hba⟩ exact ⟨_, hb, _, ha, hba⟩ @[simp] theorem erase_singleton (a : α) : ({a} : Finset α).erase a = ∅ := by ext x simp @[simp] theorem erase_insert_eq_erase (s : Finset α) (a : α) : (insert a s).erase a = s.erase a := ext fun x => by simp +contextual only [mem_erase, mem_insert, and_congr_right_iff, false_or, iff_self, imp_true_iff] theorem erase_insert {a : α} {s : Finset α} (h : a ∉ s) : erase (insert a s) a = s := by rw [erase_insert_eq_erase, erase_eq_of_not_mem h] theorem erase_insert_of_ne {a b : α} {s : Finset α} (h : a ≠ b) : erase (insert a s) b = insert a (erase s b) := ext fun x => by have : x ≠ b ∧ x = a ↔ x = a := and_iff_right_of_imp fun hx => hx.symm ▸ h simp only [mem_erase, mem_insert, and_or_left, this] theorem erase_cons_of_ne {a b : α} {s : Finset α} (ha : a ∉ s) (hb : a ≠ b) : erase (cons a s ha) b = cons a (erase s b) fun h => ha <| erase_subset _ _ h := by simp only [cons_eq_insert, erase_insert_of_ne hb] @[simp] theorem insert_erase (h : a ∈ s) : insert a (erase s a) = s := ext fun x => by simp only [mem_insert, mem_erase, or_and_left, dec_em, true_and] apply or_iff_right_of_imp rintro rfl exact h lemma erase_eq_iff_eq_insert (hs : a ∈ s) (ht : a ∉ t) : erase s a = t ↔ s = insert a t := by aesop lemma insert_erase_invOn : Set.InvOn (insert a) (fun s ↦ erase s a) {s : Finset α | a ∈ s} {s : Finset α | a ∉ s} := ⟨fun _s ↦ insert_erase, fun _s ↦ erase_insert⟩ theorem erase_ssubset {a : α} {s : Finset α} (h : a ∈ s) : s.erase a ⊂ s := calc s.erase a ⊂ insert a (s.erase a) := ssubset_insert <| not_mem_erase _ _ _ = _ := insert_erase h theorem ssubset_iff_exists_subset_erase {s t : Finset α} : s ⊂ t ↔ ∃ a ∈ t, s ⊆ t.erase a := by refine ⟨fun h => ?_, fun ⟨a, ha, h⟩ => ssubset_of_subset_of_ssubset h <| erase_ssubset ha⟩ obtain ⟨a, ht, hs⟩ := not_subset.1 h.2 exact ⟨a, ht, subset_erase.2 ⟨h.1, hs⟩⟩ theorem erase_ssubset_insert (s : Finset α) (a : α) : s.erase a ⊂ insert a s := ssubset_iff_exists_subset_erase.2 ⟨a, mem_insert_self _ _, erase_subset_erase _ <| subset_insert _ _⟩ theorem erase_cons {s : Finset α} {a : α} (h : a ∉ s) : (s.cons a h).erase a = s := by rw [cons_eq_insert, erase_insert_eq_erase, erase_eq_of_not_mem h] theorem subset_insert_iff {a : α} {s t : Finset α} : s ⊆ insert a t ↔ erase s a ⊆ t := by simp only [subset_iff, or_iff_not_imp_left, mem_erase, mem_insert, and_imp] exact forall_congr' fun x => forall_swap theorem erase_insert_subset (a : α) (s : Finset α) : erase (insert a s) a ⊆ s := subset_insert_iff.1 <| Subset.rfl theorem insert_erase_subset (a : α) (s : Finset α) : s ⊆ insert a (erase s a) := subset_insert_iff.2 <| Subset.rfl theorem subset_insert_iff_of_not_mem (h : a ∉ s) : s ⊆ insert a t ↔ s ⊆ t := by rw [subset_insert_iff, erase_eq_of_not_mem h] theorem erase_subset_iff_of_mem (h : a ∈ t) : s.erase a ⊆ t ↔ s ⊆ t := by rw [← subset_insert_iff, insert_eq_of_mem h] theorem erase_injOn' (a : α) : { s : Finset α | a ∈ s }.InjOn fun s => erase s a := fun s hs t ht (h : s.erase a = _) => by rw [← insert_erase hs, ← insert_erase ht, h] end Erase lemma Nontrivial.exists_cons_eq {s : Finset α} (hs : s.Nontrivial) : ∃ t a ha b hb hab, (cons b t hb).cons a (mem_cons.not.2 <| not_or_intro hab ha) = s := by classical obtain ⟨a, ha, b, hb, hab⟩ := hs have : b ∈ s.erase a := mem_erase.2 ⟨hab.symm, hb⟩ refine ⟨(s.erase a).erase b, a, ?_, b, ?_, ?_, ?_⟩ <;> simp [insert_erase this, insert_erase ha, *] /-! ### sdiff -/ section Sdiff variable [DecidableEq α] {s t u v : Finset α} {a b : α} lemma erase_sdiff_erase (hab : a ≠ b) (hb : b ∈ s) : s.erase a \ s.erase b = {b} := by ext; aesop -- TODO: Do we want to delete this lemma and `Finset.disjUnion_singleton`, -- or instead add `Finset.union_singleton`/`Finset.singleton_union`? theorem sdiff_singleton_eq_erase (a : α) (s : Finset α) : s \ {a} = erase s a := by ext rw [mem_erase, mem_sdiff, mem_singleton, and_comm] -- This lemma matches `Finset.insert_eq` in functionality. theorem erase_eq (s : Finset α) (a : α) : s.erase a = s \ {a} := (sdiff_singleton_eq_erase _ _).symm theorem disjoint_erase_comm : Disjoint (s.erase a) t ↔ Disjoint s (t.erase a) := by simp_rw [erase_eq, disjoint_sdiff_comm] lemma disjoint_insert_erase (ha : a ∉ t) : Disjoint (s.erase a) (insert a t) ↔ Disjoint s t := by rw [disjoint_erase_comm, erase_insert ha] lemma disjoint_erase_insert (ha : a ∉ s) : Disjoint (insert a s) (t.erase a) ↔ Disjoint s t := by rw [← disjoint_erase_comm, erase_insert ha] theorem disjoint_of_erase_left (ha : a ∉ t) (hst : Disjoint (s.erase a) t) : Disjoint s t := by rw [← erase_insert ha, ← disjoint_erase_comm, disjoint_insert_right] exact ⟨not_mem_erase _ _, hst⟩ theorem disjoint_of_erase_right (ha : a ∉ s) (hst : Disjoint s (t.erase a)) : Disjoint s t := by rw [← erase_insert ha, disjoint_erase_comm, disjoint_insert_left] exact ⟨not_mem_erase _ _, hst⟩ theorem inter_erase (a : α) (s t : Finset α) : s ∩ t.erase a = (s ∩ t).erase a := by simp only [erase_eq, inter_sdiff_assoc] @[simp] theorem erase_inter (a : α) (s t : Finset α) : s.erase a ∩ t = (s ∩ t).erase a := by simpa only [inter_comm t] using inter_erase a t s theorem erase_sdiff_comm (s t : Finset α) (a : α) : s.erase a \ t = (s \ t).erase a := by simp_rw [erase_eq, sdiff_right_comm] theorem erase_inter_comm (s t : Finset α) (a : α) : s.erase a ∩ t = s ∩ t.erase a := by rw [erase_inter, inter_erase] theorem erase_union_distrib (s t : Finset α) (a : α) : (s ∪ t).erase a = s.erase a ∪ t.erase a := by simp_rw [erase_eq, union_sdiff_distrib] theorem insert_inter_distrib (s t : Finset α) (a : α) : insert a (s ∩ t) = insert a s ∩ insert a t := by simp_rw [insert_eq, union_inter_distrib_left] theorem erase_sdiff_distrib (s t : Finset α) (a : α) : (s \ t).erase a = s.erase a \ t.erase a := by simp_rw [erase_eq, sdiff_sdiff, sup_sdiff_eq_sup le_rfl, sup_comm] theorem erase_union_of_mem (ha : a ∈ t) (s : Finset α) : s.erase a ∪ t = s ∪ t := by rw [← insert_erase (mem_union_right s ha), erase_union_distrib, ← union_insert, insert_erase ha] theorem union_erase_of_mem (ha : a ∈ s) (t : Finset α) : s ∪ t.erase a = s ∪ t := by rw [← insert_erase (mem_union_left t ha), erase_union_distrib, ← insert_union, insert_erase ha] theorem sdiff_union_erase_cancel (hts : t ⊆ s) (ha : a ∈ t) : s \ t ∪ t.erase a = s.erase a := by simp_rw [erase_eq, sdiff_union_sdiff_cancel hts (singleton_subset_iff.2 ha)] theorem sdiff_insert (s t : Finset α) (x : α) : s \ insert x t = (s \ t).erase x := by simp_rw [← sdiff_singleton_eq_erase, insert_eq, sdiff_sdiff_left', sdiff_union_distrib, inter_comm] theorem sdiff_insert_insert_of_mem_of_not_mem {s t : Finset α} {x : α} (hxs : x ∈ s) (hxt : x ∉ t) : insert x (s \ insert x t) = s \ t := by rw [sdiff_insert, insert_erase (mem_sdiff.mpr ⟨hxs, hxt⟩)] theorem sdiff_erase (h : a ∈ s) : s \ t.erase a = insert a (s \ t) := by rw [← sdiff_singleton_eq_erase, sdiff_sdiff_eq_sdiff_union (singleton_subset_iff.2 h), insert_eq, union_comm] theorem sdiff_erase_self (ha : a ∈ s) : s \ s.erase a = {a} := by rw [sdiff_erase ha, Finset.sdiff_self, insert_empty_eq] theorem erase_eq_empty_iff (s : Finset α) (a : α) : s.erase a = ∅ ↔ s = ∅ ∨ s = {a} := by rw [← sdiff_singleton_eq_erase, sdiff_eq_empty_iff_subset, subset_singleton_iff] --TODO@Yaël: Kill lemmas duplicate with `BooleanAlgebra` theorem sdiff_disjoint : Disjoint (t \ s) s := disjoint_left.2 fun _a ha => (mem_sdiff.1 ha).2 theorem disjoint_sdiff : Disjoint s (t \ s) := sdiff_disjoint.symm theorem disjoint_sdiff_inter (s t : Finset α) : Disjoint (s \ t) (s ∩ t) := disjoint_of_subset_right inter_subset_right sdiff_disjoint end Sdiff /-! ### attach -/ @[simp] theorem attach_empty : attach (∅ : Finset α) = ∅ := rfl @[simp] theorem attach_nonempty_iff {s : Finset α} : s.attach.Nonempty ↔ s.Nonempty := by simp [Finset.Nonempty] @[aesop safe apply (rule_sets := [finsetNonempty])] protected alias ⟨_, Nonempty.attach⟩ := attach_nonempty_iff @[simp] theorem attach_eq_empty_iff {s : Finset α} : s.attach = ∅ ↔ s = ∅ := by simp [eq_empty_iff_forall_not_mem] /-! ### filter -/ section Filter variable (p q : α → Prop) [DecidablePred p] [DecidablePred q] {s t : Finset α} theorem filter_singleton (a : α) : filter p {a} = if p a then {a} else ∅ := by classical ext x simp only [mem_singleton, forall_eq, mem_filter] split_ifs with h <;> by_cases h' : x = a <;> simp [h, h'] theorem filter_cons_of_pos (a : α) (s : Finset α) (ha : a ∉ s) (hp : p a) : filter p (cons a s ha) = cons a (filter p s) ((mem_of_mem_filter _).mt ha) := eq_of_veq <| Multiset.filter_cons_of_pos s.val hp theorem filter_cons_of_neg (a : α) (s : Finset α) (ha : a ∉ s) (hp : ¬p a) : filter p (cons a s ha) = filter p s := eq_of_veq <| Multiset.filter_cons_of_neg s.val hp theorem disjoint_filter {s : Finset α} {p q : α → Prop} [DecidablePred p] [DecidablePred q] : Disjoint (s.filter p) (s.filter q) ↔ ∀ x ∈ s, p x → ¬q x := by constructor <;> simp +contextual [disjoint_left] theorem disjoint_filter_filter' (s t : Finset α) {p q : α → Prop} [DecidablePred p] [DecidablePred q] (h : Disjoint p q) : Disjoint (s.filter p) (t.filter q) := by simp_rw [disjoint_left, mem_filter] rintro a ⟨_, hp⟩ ⟨_, hq⟩ rw [Pi.disjoint_iff] at h simpa [hp, hq] using h a theorem disjoint_filter_filter_neg (s t : Finset α) (p : α → Prop) [DecidablePred p] [∀ x, Decidable (¬p x)] : Disjoint (s.filter p) (t.filter fun a => ¬p a) := disjoint_filter_filter' s t disjoint_compl_right theorem filter_disj_union (s : Finset α) (t : Finset α) (h : Disjoint s t) : filter p (disjUnion s t h) = (filter p s).disjUnion (filter p t) (disjoint_filter_filter h) := eq_of_veq <| Multiset.filter_add _ _ _ theorem filter_cons {a : α} (s : Finset α) (ha : a ∉ s) : filter p (cons a s ha) = if p a then cons a (filter p s) ((mem_of_mem_filter _).mt ha) else filter p s := by split_ifs with h · rw [filter_cons_of_pos _ _ _ ha h] · rw [filter_cons_of_neg _ _ _ ha h] section variable [DecidableEq α] theorem filter_union (s₁ s₂ : Finset α) : (s₁ ∪ s₂).filter p = s₁.filter p ∪ s₂.filter p := ext fun _ => by simp only [mem_filter, mem_union, or_and_right] theorem filter_union_right (s : Finset α) : s.filter p ∪ s.filter q = s.filter fun x => p x ∨ q x := ext fun x => by simp [mem_filter, mem_union, ← and_or_left] theorem filter_mem_eq_inter {s t : Finset α} [∀ i, Decidable (i ∈ t)] : (s.filter fun i => i ∈ t) = s ∩ t := ext fun i => by simp [mem_filter, mem_inter] theorem filter_inter_distrib (s t : Finset α) : (s ∩ t).filter p = s.filter p ∩ t.filter p := by ext simp [mem_filter, mem_inter, and_assoc] theorem filter_inter (s t : Finset α) : filter p s ∩ t = filter p (s ∩ t) := by ext simp only [mem_inter, mem_filter, and_right_comm] theorem inter_filter (s t : Finset α) : s ∩ filter p t = filter p (s ∩ t) := by rw [inter_comm, filter_inter, inter_comm] theorem filter_insert (a : α) (s : Finset α) : filter p (insert a s) = if p a then insert a (filter p s) else filter p s := by ext x split_ifs with h <;> by_cases h' : x = a <;> simp [h, h'] theorem filter_erase (a : α) (s : Finset α) : filter p (erase s a) = erase (filter p s) a := by ext x simp only [and_assoc, mem_filter, iff_self, mem_erase] theorem filter_or (s : Finset α) : (s.filter fun a => p a ∨ q a) = s.filter p ∪ s.filter q := ext fun _ => by simp [mem_filter, mem_union, and_or_left] theorem filter_and (s : Finset α) : (s.filter fun a => p a ∧ q a) = s.filter p ∩ s.filter q := ext fun _ => by simp [mem_filter, mem_inter, and_comm, and_left_comm, and_self_iff, and_assoc] theorem filter_not (s : Finset α) : (s.filter fun a => ¬p a) = s \ s.filter p := ext fun a => by simp only [Bool.decide_coe, Bool.not_eq_true', mem_filter, and_comm, mem_sdiff, not_and_or, Bool.not_eq_true, and_or_left, and_not_self, or_false] lemma filter_and_not (s : Finset α) (p q : α → Prop) [DecidablePred p] [DecidablePred q] : s.filter (fun a ↦ p a ∧ ¬ q a) = s.filter p \ s.filter q := by rw [filter_and, filter_not, ← inter_sdiff_assoc, inter_eq_left.2 (filter_subset _ _)] theorem sdiff_eq_filter (s₁ s₂ : Finset α) : s₁ \ s₂ = filter (· ∉ s₂) s₁ := ext fun _ => by simp [mem_sdiff, mem_filter] theorem subset_union_elim {s : Finset α} {t₁ t₂ : Set α} (h : ↑s ⊆ t₁ ∪ t₂) : ∃ s₁ s₂ : Finset α, s₁ ∪ s₂ = s ∧ ↑s₁ ⊆ t₁ ∧ ↑s₂ ⊆ t₂ \ t₁ := by classical refine ⟨s.filter (· ∈ t₁), s.filter (· ∉ t₁), ?_, ?_, ?_⟩ · simp [filter_union_right, em] · intro x simp · intro x simp only [not_not, coe_filter, Set.mem_setOf_eq, Set.mem_diff, and_imp] intro hx hx₂ exact ⟨Or.resolve_left (h hx) hx₂, hx₂⟩ -- This is not a good simp lemma, as it would prevent `Finset.mem_filter` from firing -- on, e.g. `x ∈ s.filter (Eq b)`. /-- After filtering out everything that does not equal a given value, at most that value remains. This is equivalent to `filter_eq'` with the equality the other way. -/ theorem filter_eq [DecidableEq β] (s : Finset β) (b : β) : s.filter (Eq b) = ite (b ∈ s) {b} ∅ := by split_ifs with h · ext simp only [mem_filter, mem_singleton, decide_eq_true_eq] refine ⟨fun h => h.2.symm, ?_⟩ rintro rfl exact ⟨h, rfl⟩ · ext simp only [mem_filter, not_and, iff_false, not_mem_empty, decide_eq_true_eq] rintro m rfl exact h m /-- After filtering out everything that does not equal a given value, at most that value remains. This is equivalent to `filter_eq` with the equality the other way. -/ theorem filter_eq' [DecidableEq β] (s : Finset β) (b : β) : (s.filter fun a => a = b) = ite (b ∈ s) {b} ∅ := _root_.trans (filter_congr fun _ _ => by simp_rw [@eq_comm _ b]) (filter_eq s b) theorem filter_ne [DecidableEq β] (s : Finset β) (b : β) : (s.filter fun a => b ≠ a) = s.erase b := by ext simp only [mem_filter, mem_erase, Ne, decide_not, Bool.not_eq_true', decide_eq_false_iff_not] tauto theorem filter_ne' [DecidableEq β] (s : Finset β) (b : β) : (s.filter fun a => a ≠ b) = s.erase b := _root_.trans (filter_congr fun _ _ => by simp_rw [@ne_comm _ b]) (filter_ne s b) theorem filter_union_filter_of_codisjoint (s : Finset α) (h : Codisjoint p q) : s.filter p ∪ s.filter q = s := (filter_or _ _ _).symm.trans <| filter_true_of_mem fun x _ => h.top_le x trivial theorem filter_union_filter_neg_eq [∀ x, Decidable (¬p x)] (s : Finset α) : (s.filter p ∪ s.filter fun a => ¬p a) = s := filter_union_filter_of_codisjoint _ _ _ <| @codisjoint_hnot_right _ _ p end end Filter /-! ### range -/ section Range open Nat variable {n m l : ℕ} @[simp] theorem range_filter_eq {n m : ℕ} : (range n).filter (· = m) = if m < n then {m} else ∅ := by convert filter_eq (range n) m using 2 · ext rw [eq_comm] · simp end Range end Finset /-! ### dedup on list and multiset -/ namespace Multiset variable [DecidableEq α] {s t : Multiset α} @[simp] theorem toFinset_add (s t : Multiset α) : toFinset (s + t) = toFinset s ∪ toFinset t := Finset.ext <| by simp @[simp] theorem toFinset_inter (s t : Multiset α) : toFinset (s ∩ t) = toFinset s ∩ toFinset t := Finset.ext <| by simp @[simp] theorem toFinset_union (s t : Multiset α) : (s ∪ t).toFinset = s.toFinset ∪ t.toFinset := by ext; simp @[simp] theorem toFinset_eq_empty {m : Multiset α} : m.toFinset = ∅ ↔ m = 0 := Finset.val_inj.symm.trans Multiset.dedup_eq_zero @[simp] theorem toFinset_nonempty : s.toFinset.Nonempty ↔ s ≠ 0 := by simp only [toFinset_eq_empty, Ne, Finset.nonempty_iff_ne_empty] @[aesop safe apply (rule_sets := [finsetNonempty])] protected alias ⟨_, Aesop.toFinset_nonempty_of_ne⟩ := toFinset_nonempty @[simp] theorem toFinset_filter (s : Multiset α) (p : α → Prop) [DecidablePred p] : Multiset.toFinset (s.filter p) = s.toFinset.filter p := by ext; simp end Multiset namespace List variable [DecidableEq α] {l l' : List α} {a : α} {f : α → β} {s : Finset α} {t : Set β} {t' : Finset β} @[simp] theorem toFinset_union (l l' : List α) : (l ∪ l').toFinset = l.toFinset ∪ l'.toFinset := by ext simp @[simp] theorem toFinset_inter (l l' : List α) : (l ∩ l').toFinset = l.toFinset ∩ l'.toFinset := by ext simp @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.toFinset_nonempty_of_ne⟩ := toFinset_nonempty_iff @[simp] theorem toFinset_filter (s : List α) (p : α → Bool) : (s.filter p).toFinset = s.toFinset.filter (p ·) := by ext; simp [List.mem_filter] end List namespace Finset section ToList @[simp] theorem toList_eq_nil {s : Finset α} : s.toList = [] ↔ s = ∅ := Multiset.toList_eq_nil.trans val_eq_zero theorem empty_toList {s : Finset α} : s.toList.isEmpty ↔ s = ∅ := by simp @[simp] theorem toList_empty : (∅ : Finset α).toList = [] := toList_eq_nil.mpr rfl theorem Nonempty.toList_ne_nil {s : Finset α} (hs : s.Nonempty) : s.toList ≠ [] := mt toList_eq_nil.mp hs.ne_empty theorem Nonempty.not_empty_toList {s : Finset α} (hs : s.Nonempty) : ¬s.toList.isEmpty := mt empty_toList.mp hs.ne_empty end ToList /-! ### choose -/ section Choose variable (p : α → Prop) [DecidablePred p] (l : Finset α) /-- Given a finset `l` and a predicate `p`, associate to a proof that there is a unique element of `l` satisfying `p` this unique element, as an element of the corresponding subtype. -/ def chooseX (hp : ∃! a, a ∈ l ∧ p a) : { a // a ∈ l ∧ p a } := Multiset.chooseX p l.val hp /-- Given a finset `l` and a predicate `p`, associate to a proof that there is a unique element of `l` satisfying `p` this unique element, as an element of the ambient type. -/ def choose (hp : ∃! a, a ∈ l ∧ p a) : α := chooseX p l hp theorem choose_spec (hp : ∃! a, a ∈ l ∧ p a) : choose p l hp ∈ l ∧ p (choose p l hp) := (chooseX p l hp).property theorem choose_mem (hp : ∃! a, a ∈ l ∧ p a) : choose p l hp ∈ l := (choose_spec _ _ _).1 theorem choose_property (hp : ∃! a, a ∈ l ∧ p a) : p (choose p l hp) := (choose_spec _ _ _).2 end Choose end Finset namespace Equiv variable [DecidableEq α] {s t : Finset α} open Finset /-- The disjoint union of finsets is a sum -/ def Finset.union (s t : Finset α) (h : Disjoint s t) : s ⊕ t ≃ (s ∪ t : Finset α) := Equiv.setCongr (coe_union _ _) |>.trans (Equiv.Set.union (disjoint_coe.mpr h)) |>.symm @[simp] theorem Finset.union_symm_inl (h : Disjoint s t) (x : s) : Equiv.Finset.union s t h (Sum.inl x) = ⟨x, Finset.mem_union.mpr <| Or.inl x.2⟩ := rfl @[simp] theorem Finset.union_symm_inr (h : Disjoint s t) (y : t) : Equiv.Finset.union s t h (Sum.inr y) = ⟨y, Finset.mem_union.mpr <| Or.inr y.2⟩ := rfl /-- The type of dependent functions on the disjoint union of finsets `s ∪ t` is equivalent to the type of pairs of functions on `s` and on `t`. This is similar to `Equiv.sumPiEquivProdPi`. -/ def piFinsetUnion {ι} [DecidableEq ι] (α : ι → Type*) {s t : Finset ι} (h : Disjoint s t) : ((∀ i : s, α i) × ∀ i : t, α i) ≃ ∀ i : (s ∪ t : Finset ι), α i := let e := Equiv.Finset.union s t h sumPiEquivProdPi (fun b ↦ α (e b)) |>.symm.trans (.piCongrLeft (fun i : ↥(s ∪ t) ↦ α i) e) /-- A finset is equivalent to its coercion as a set. -/ def _root_.Finset.equivToSet (s : Finset α) : s ≃ s.toSet where toFun a := ⟨a.1, mem_coe.2 a.2⟩ invFun a := ⟨a.1, mem_coe.1 a.2⟩ left_inv := fun _ ↦ rfl right_inv := fun _ ↦ rfl end Equiv namespace Multiset variable [DecidableEq α] @[simp] lemma toFinset_replicate (n : ℕ) (a : α) : (replicate n a).toFinset = if n = 0 then ∅ else {a} := by ext x simp only [mem_toFinset, Finset.mem_singleton, mem_replicate] split_ifs with hn <;> simp [hn] end Multiset
Mathlib/Data/Finset/Basic.lean
1,500
1,501
/- Copyright (c) 2022 Xavier Roblot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Xavier Roblot -/ import Mathlib.MeasureTheory.Group.GeometryOfNumbers import Mathlib.MeasureTheory.Measure.Lebesgue.VolumeOfBalls import Mathlib.NumberTheory.NumberField.CanonicalEmbedding.Basic import Mathlib.Analysis.SpecialFunctions.Gamma.BohrMollerup /-! # Convex Bodies The file contains the definitions of several convex bodies lying in the mixed space `ℝ^r₁ × ℂ^r₂` associated to a number field of signature `K` and proves several existence theorems by applying *Minkowski Convex Body Theorem* to those. ## Main definitions and results * `NumberField.mixedEmbedding.convexBodyLT`: The set of points `x` such that `‖x w‖ < f w` for all infinite places `w` with `f : InfinitePlace K → ℝ≥0`. * `NumberField.mixedEmbedding.convexBodySum`: The set of points `x` such that `∑ w real, ‖x w‖ + 2 * ∑ w complex, ‖x w‖ ≤ B` * `NumberField.mixedEmbedding.exists_ne_zero_mem_ideal_lt`: Let `I` be a fractional ideal of `K`. Assume that `f` is such that `minkowskiBound K I < volume (convexBodyLT K f)`, then there exists a nonzero algebraic number `a` in `I` such that `w a < f w` for all infinite places `w`. * `NumberField.mixedEmbedding.exists_ne_zero_mem_ideal_of_norm_le`: Let `I` be a fractional ideal of `K`. Assume that `B` is such that `minkowskiBound K I < volume (convexBodySum K B)` (see `convexBodySum_volume` for the computation of this volume), then there exists a nonzero algebraic number `a` in `I` such that `|Norm a| < (B / d) ^ d` where `d` is the degree of `K`. ## Tags number field, infinite places -/ variable (K : Type*) [Field K] namespace NumberField.mixedEmbedding open NumberField NumberField.InfinitePlace Module section convexBodyLT open Metric NNReal variable (f : InfinitePlace K → ℝ≥0) /-- The convex body defined by `f`: the set of points `x : E` such that `‖x w‖ < f w` for all infinite places `w`. -/ abbrev convexBodyLT : Set (mixedSpace K) := (Set.univ.pi (fun w : { w : InfinitePlace K // IsReal w } => ball 0 (f w))) ×ˢ (Set.univ.pi (fun w : { w : InfinitePlace K // IsComplex w } => ball 0 (f w))) theorem convexBodyLT_mem {x : K} : mixedEmbedding K x ∈ (convexBodyLT K f) ↔ ∀ w : InfinitePlace K, w x < f w := by simp_rw [mixedEmbedding, RingHom.prod_apply, Set.mem_prod, Set.mem_pi, Set.mem_univ, forall_true_left, mem_ball_zero_iff, Pi.ringHom_apply, ← Complex.norm_real, embedding_of_isReal_apply, Subtype.forall, ← forall₂_or_left, ← not_isReal_iff_isComplex, em, forall_true_left, norm_embedding_eq] theorem convexBodyLT_neg_mem (x : mixedSpace K) (hx : x ∈ (convexBodyLT K f)) : -x ∈ (convexBodyLT K f) := by simp only [Set.mem_prod, Prod.fst_neg, Set.mem_pi, Set.mem_univ, Pi.neg_apply, mem_ball_zero_iff, norm_neg, Real.norm_eq_abs, forall_true_left, Subtype.forall, Prod.snd_neg] at hx ⊢ exact hx theorem convexBodyLT_convex : Convex ℝ (convexBodyLT K f) := Convex.prod (convex_pi (fun _ _ => convex_ball _ _)) (convex_pi (fun _ _ => convex_ball _ _)) open Fintype MeasureTheory MeasureTheory.Measure ENNReal variable [NumberField K] /-- The fudge factor that appears in the formula for the volume of `convexBodyLT`. -/ noncomputable abbrev convexBodyLTFactor : ℝ≥0 := (2 : ℝ≥0) ^ nrRealPlaces K * NNReal.pi ^ nrComplexPlaces K theorem convexBodyLTFactor_ne_zero : convexBodyLTFactor K ≠ 0 := mul_ne_zero (pow_ne_zero _ two_ne_zero) (pow_ne_zero _ pi_ne_zero) theorem one_le_convexBodyLTFactor : 1 ≤ convexBodyLTFactor K := one_le_mul (one_le_pow₀ one_le_two) (one_le_pow₀ (one_le_two.trans Real.two_le_pi)) open scoped Classical in /-- The volume of `(ConvexBodyLt K f)` where `convexBodyLT K f` is the set of points `x` such that `‖x w‖ < f w` for all infinite places `w`. -/ theorem convexBodyLT_volume : volume (convexBodyLT K f) = (convexBodyLTFactor K) * ∏ w, (f w) ^ (mult w) := by calc _ = (∏ x : {w // InfinitePlace.IsReal w}, ENNReal.ofReal (2 * (f x.val))) * ∏ x : {w // InfinitePlace.IsComplex w}, ENNReal.ofReal (f x.val) ^ 2 * NNReal.pi := by simp_rw [volume_eq_prod, prod_prod, volume_pi, pi_pi, Real.volume_ball, Complex.volume_ball] _ = ((2 : ℝ≥0) ^ nrRealPlaces K * (∏ x : {w // InfinitePlace.IsReal w}, ENNReal.ofReal (f x.val))) * ((∏ x : {w // IsComplex w}, ENNReal.ofReal (f x.val) ^ 2) * NNReal.pi ^ nrComplexPlaces K) := by simp_rw [ofReal_mul (by norm_num : 0 ≤ (2 : ℝ)), Finset.prod_mul_distrib, Finset.prod_const, Finset.card_univ, ofReal_ofNat, ofReal_coe_nnreal, coe_ofNat] _ = (convexBodyLTFactor K) * ((∏ x : {w // InfinitePlace.IsReal w}, .ofReal (f x.val)) * (∏ x : {w // IsComplex w}, ENNReal.ofReal (f x.val) ^ 2)) := by simp_rw [convexBodyLTFactor, coe_mul, ENNReal.coe_pow] ring _ = (convexBodyLTFactor K) * ∏ w, (f w) ^ (mult w) := by simp_rw [prod_eq_prod_mul_prod, coe_mul, coe_finset_prod, mult_isReal, mult_isComplex, pow_one, ENNReal.coe_pow, ofReal_coe_nnreal] variable {f} /-- This is a technical result: quite often, we want to impose conditions at all infinite places but one and choose the value at the remaining place so that we can apply `exists_ne_zero_mem_ringOfIntegers_lt`. -/ theorem adjust_f {w₁ : InfinitePlace K} (B : ℝ≥0) (hf : ∀ w, w ≠ w₁ → f w ≠ 0) : ∃ g : InfinitePlace K → ℝ≥0, (∀ w, w ≠ w₁ → g w = f w) ∧ ∏ w, (g w) ^ mult w = B := by classical let S := ∏ w ∈ Finset.univ.erase w₁, (f w) ^ mult w refine ⟨Function.update f w₁ ((B * S⁻¹) ^ (mult w₁ : ℝ)⁻¹), ?_, ?_⟩ · exact fun w hw => Function.update_of_ne hw _ f · rw [← Finset.mul_prod_erase Finset.univ _ (Finset.mem_univ w₁), Function.update_self, Finset.prod_congr rfl fun w hw => by rw [Function.update_of_ne (Finset.ne_of_mem_erase hw)], ← NNReal.rpow_natCast, ← NNReal.rpow_mul, inv_mul_cancel₀, NNReal.rpow_one, mul_assoc, inv_mul_cancel₀, mul_one] · rw [Finset.prod_ne_zero_iff] exact fun w hw => pow_ne_zero _ (hf w (Finset.ne_of_mem_erase hw)) · rw [mult]; split_ifs <;> norm_num end convexBodyLT section convexBodyLT' open Metric ENNReal NNReal variable (f : InfinitePlace K → ℝ≥0) (w₀ : {w : InfinitePlace K // IsComplex w}) open scoped Classical in /-- A version of `convexBodyLT` with an additional condition at a fixed complex place. This is needed to ensure the element constructed is not real, see for example `exists_primitive_element_lt_of_isComplex`. -/ abbrev convexBodyLT' : Set (mixedSpace K) := (Set.univ.pi (fun w : { w : InfinitePlace K // IsReal w } ↦ ball 0 (f w))) ×ˢ (Set.univ.pi (fun w : { w : InfinitePlace K // IsComplex w } ↦ if w = w₀ then {x | |x.re| < 1 ∧ |x.im| < (f w : ℝ) ^ 2} else ball 0 (f w))) theorem convexBodyLT'_mem {x : K} : mixedEmbedding K x ∈ convexBodyLT' K f w₀ ↔ (∀ w : InfinitePlace K, w ≠ w₀ → w x < f w) ∧ |(w₀.val.embedding x).re| < 1 ∧ |(w₀.val.embedding x).im| < (f w₀ : ℝ) ^ 2 := by simp_rw [mixedEmbedding, RingHom.prod_apply, Set.mem_prod, Set.mem_pi, Set.mem_univ, forall_true_left, Pi.ringHom_apply, mem_ball_zero_iff, ← Complex.norm_real, embedding_of_isReal_apply, norm_embedding_eq, Subtype.forall] refine ⟨fun ⟨h₁, h₂⟩ ↦ ⟨fun w h_ne ↦ ?_, ?_⟩, fun ⟨h₁, h₂⟩ ↦ ⟨fun w hw ↦ ?_, fun w hw ↦ ?_⟩⟩ · by_cases hw : IsReal w · exact norm_embedding_eq w _ ▸ h₁ w hw · specialize h₂ w (not_isReal_iff_isComplex.mp hw) rw [apply_ite (w.embedding x ∈ ·), Set.mem_setOf_eq, mem_ball_zero_iff, norm_embedding_eq] at h₂ rwa [if_neg (by exact Subtype.coe_ne_coe.1 h_ne)] at h₂ · simpa [if_true] using h₂ w₀.val w₀.prop · exact h₁ w (ne_of_isReal_isComplex hw w₀.prop) · by_cases h_ne : w = w₀ · simpa [h_ne] · rw [if_neg (by exact Subtype.coe_ne_coe.1 h_ne)] rw [mem_ball_zero_iff, norm_embedding_eq] exact h₁ w h_ne theorem convexBodyLT'_neg_mem (x : mixedSpace K) (hx : x ∈ convexBodyLT' K f w₀) : -x ∈ convexBodyLT' K f w₀ := by simp only [Set.mem_prod, Set.mem_pi, Set.mem_univ, mem_ball, dist_zero_right, Real.norm_eq_abs, true_implies, Subtype.forall, Prod.fst_neg, Pi.neg_apply, norm_neg, Prod.snd_neg] at hx ⊢ convert hx using 3 split_ifs <;> simp theorem convexBodyLT'_convex : Convex ℝ (convexBodyLT' K f w₀) := by refine Convex.prod (convex_pi (fun _ _ => convex_ball _ _)) (convex_pi (fun _ _ => ?_)) split_ifs · simp_rw [abs_lt] refine Convex.inter ((convex_halfSpace_re_gt _).inter (convex_halfSpace_re_lt _)) ((convex_halfSpace_im_gt _).inter (convex_halfSpace_im_lt _)) · exact convex_ball _ _ open MeasureTheory MeasureTheory.Measure variable [NumberField K] /-- The fudge factor that appears in the formula for the volume of `convexBodyLT'`. -/ noncomputable abbrev convexBodyLT'Factor : ℝ≥0 := (2 : ℝ≥0) ^ (nrRealPlaces K + 2) * NNReal.pi ^ (nrComplexPlaces K - 1) theorem convexBodyLT'Factor_ne_zero : convexBodyLT'Factor K ≠ 0 := mul_ne_zero (pow_ne_zero _ two_ne_zero) (pow_ne_zero _ pi_ne_zero) theorem one_le_convexBodyLT'Factor : 1 ≤ convexBodyLT'Factor K := one_le_mul (one_le_pow₀ one_le_two) (one_le_pow₀ (one_le_two.trans Real.two_le_pi)) open scoped Classical in theorem convexBodyLT'_volume : volume (convexBodyLT' K f w₀) = convexBodyLT'Factor K * ∏ w, (f w) ^ (mult w) := by have vol_box : ∀ B : ℝ≥0, volume {x : ℂ | |x.re| < 1 ∧ |x.im| < B^2} = 4*B^2 := by intro B rw [← (Complex.volume_preserving_equiv_real_prod.symm).measure_preimage] · simp_rw [Set.preimage_setOf_eq, Complex.measurableEquivRealProd_symm_apply] rw [show {a : ℝ × ℝ | |a.1| < 1 ∧ |a.2| < B ^ 2} = Set.Ioo (-1 : ℝ) (1 : ℝ) ×ˢ Set.Ioo (- (B : ℝ) ^ 2) ((B : ℝ) ^ 2) by ext; simp_rw [Set.mem_setOf_eq, Set.mem_prod, Set.mem_Ioo, abs_lt]] simp_rw [volume_eq_prod, prod_prod, Real.volume_Ioo, sub_neg_eq_add, one_add_one_eq_two, ← two_mul, ofReal_mul zero_le_two, ofReal_pow (coe_nonneg B), ofReal_ofNat, ofReal_coe_nnreal, ← mul_assoc, show (2 : ℝ≥0∞) * 2 = 4 by norm_num] · refine (MeasurableSet.inter ?_ ?_).nullMeasurableSet · exact measurableSet_lt (measurable_norm.comp Complex.measurable_re) measurable_const · exact measurableSet_lt (measurable_norm.comp Complex.measurable_im) measurable_const calc _ = (∏ x : {w // InfinitePlace.IsReal w}, ENNReal.ofReal (2 * (f x.val))) * ((∏ x ∈ Finset.univ.erase w₀, ENNReal.ofReal (f x.val) ^ 2 * pi) * (4 * (f w₀) ^ 2)) := by simp_rw [volume_eq_prod, prod_prod, volume_pi, pi_pi, Real.volume_ball] rw [← Finset.prod_erase_mul _ _ (Finset.mem_univ w₀)] congr 2 · refine Finset.prod_congr rfl (fun w' hw' ↦ ?_) rw [if_neg (Finset.ne_of_mem_erase hw'), Complex.volume_ball] · simpa only [ite_true] using vol_box (f w₀) _ = ((2 : ℝ≥0) ^ nrRealPlaces K * (∏ x : {w // InfinitePlace.IsReal w}, ENNReal.ofReal (f x.val))) * ((∏ x ∈ Finset.univ.erase w₀, ENNReal.ofReal (f x.val) ^ 2) * ↑pi ^ (nrComplexPlaces K - 1) * (4 * (f w₀) ^ 2)) := by simp_rw [ofReal_mul (by norm_num : 0 ≤ (2 : ℝ)), Finset.prod_mul_distrib, Finset.prod_const, Finset.card_erase_of_mem (Finset.mem_univ _), Finset.card_univ, ofReal_ofNat, ofReal_coe_nnreal, coe_ofNat] _ = convexBodyLT'Factor K * (∏ x : {w // InfinitePlace.IsReal w}, ENNReal.ofReal (f x.val)) * (∏ x : {w // IsComplex w}, ENNReal.ofReal (f x.val) ^ 2) := by rw [show (4 : ℝ≥0∞) = (2 : ℝ≥0) ^ 2 by norm_num, convexBodyLT'Factor, pow_add, ← Finset.prod_erase_mul _ _ (Finset.mem_univ w₀), ofReal_coe_nnreal] simp_rw [coe_mul, ENNReal.coe_pow] ring _ = convexBodyLT'Factor K * ∏ w, (f w) ^ (mult w) := by simp_rw [prod_eq_prod_mul_prod, coe_mul, coe_finset_prod, mult_isReal, mult_isComplex, pow_one, ENNReal.coe_pow, ofReal_coe_nnreal, mul_assoc] end convexBodyLT' section convexBodySum open ENNReal MeasureTheory Fintype open scoped Real NNReal variable [NumberField K] (B : ℝ) variable {K} /-- The function that sends `x : mixedSpace K` to `∑ w, ‖x.1 w‖ + 2 * ∑ w, ‖x.2 w‖`. It defines a norm and it used to define `convexBodySum`. -/ noncomputable abbrev convexBodySumFun (x : mixedSpace K) : ℝ := ∑ w, mult w * normAtPlace w x theorem convexBodySumFun_apply (x : mixedSpace K) : convexBodySumFun x = ∑ w, mult w * normAtPlace w x := rfl open scoped Classical in theorem convexBodySumFun_apply' (x : mixedSpace K) : convexBodySumFun x = ∑ w, ‖x.1 w‖ + 2 * ∑ w, ‖x.2 w‖ := by simp_rw [convexBodySumFun_apply, sum_eq_sum_add_sum, mult_isReal, mult_isComplex, Nat.cast_one, one_mul, Nat.cast_ofNat, normAtPlace_apply_of_isReal (Subtype.prop _), normAtPlace_apply_of_isComplex (Subtype.prop _), Finset.mul_sum] theorem convexBodySumFun_nonneg (x : mixedSpace K) : 0 ≤ convexBodySumFun x := Finset.sum_nonneg (fun _ _ => mul_nonneg (Nat.cast_pos.mpr mult_pos).le (normAtPlace_nonneg _ _)) theorem convexBodySumFun_neg (x : mixedSpace K) : convexBodySumFun (- x) = convexBodySumFun x := by simp_rw [convexBodySumFun, normAtPlace_neg] theorem convexBodySumFun_add_le (x y : mixedSpace K) : convexBodySumFun (x + y) ≤ convexBodySumFun x + convexBodySumFun y := by simp_rw [convexBodySumFun, ← Finset.sum_add_distrib, ← mul_add] exact Finset.sum_le_sum fun _ _ ↦ mul_le_mul_of_nonneg_left (normAtPlace_add_le _ x y) (Nat.cast_pos.mpr mult_pos).le theorem convexBodySumFun_smul (c : ℝ) (x : mixedSpace K) : convexBodySumFun (c • x) = |c| * convexBodySumFun x := by simp_rw [convexBodySumFun, normAtPlace_smul, ← mul_assoc, mul_comm, Finset.mul_sum, mul_assoc] theorem convexBodySumFun_eq_zero_iff (x : mixedSpace K) : convexBodySumFun x = 0 ↔ x = 0 := by rw [← forall_normAtPlace_eq_zero_iff, convexBodySumFun, Finset.sum_eq_zero_iff_of_nonneg fun _ _ ↦ mul_nonneg (Nat.cast_pos.mpr mult_pos).le (normAtPlace_nonneg _ _)] conv => enter [1, w, hw] rw [mul_left_mem_nonZeroDivisors_eq_zero_iff (mem_nonZeroDivisors_iff_ne_zero.mpr <| Nat.cast_ne_zero.mpr mult_ne_zero)] simp_rw [Finset.mem_univ, true_implies] open scoped Classical in theorem norm_le_convexBodySumFun (x : mixedSpace K) : ‖x‖ ≤ convexBodySumFun x := by rw [norm_eq_sup'_normAtPlace] refine (Finset.sup'_le_iff _ _).mpr fun w _ ↦ ?_ rw [convexBodySumFun_apply, ← Finset.univ.add_sum_erase _ (Finset.mem_univ w)] refine le_add_of_le_of_nonneg ?_ ?_ · exact le_mul_of_one_le_left (normAtPlace_nonneg w x) one_le_mult · exact Finset.sum_nonneg (fun _ _ => mul_nonneg (Nat.cast_pos.mpr mult_pos).le (normAtPlace_nonneg _ _)) variable (K) theorem convexBodySumFun_continuous : Continuous (convexBodySumFun : mixedSpace K → ℝ) := by refine continuous_finset_sum Finset.univ fun w ↦ ?_ obtain hw | hw := isReal_or_isComplex w all_goals · simp only [normAtPlace_apply_of_isReal, normAtPlace_apply_of_isComplex, hw] fun_prop /-- The convex body equal to the set of points `x : mixedSpace K` such that `∑ w real, ‖x w‖ + 2 * ∑ w complex, ‖x w‖ ≤ B`. -/ abbrev convexBodySum : Set (mixedSpace K) := { x | convexBodySumFun x ≤ B } open scoped Classical in theorem convexBodySum_volume_eq_zero_of_le_zero {B} (hB : B ≤ 0) : volume (convexBodySum K B) = 0 := by obtain hB | hB := lt_or_eq_of_le hB · suffices convexBodySum K B = ∅ by rw [this, measure_empty] ext x refine ⟨fun hx => ?_, fun h => h.elim⟩ rw [Set.mem_setOf] at hx linarith [convexBodySumFun_nonneg x] · suffices convexBodySum K B = { 0 } by rw [this, measure_singleton] ext rw [convexBodySum, Set.mem_setOf_eq, Set.mem_singleton_iff, hB, ← convexBodySumFun_eq_zero_iff] exact (convexBodySumFun_nonneg _).le_iff_eq theorem convexBodySum_mem {x : K} : mixedEmbedding K x ∈ (convexBodySum K B) ↔ ∑ w : InfinitePlace K, (mult w) * w.val x ≤ B := by simp_rw [Set.mem_setOf_eq, convexBodySumFun, normAtPlace_apply] rfl theorem convexBodySum_neg_mem {x : mixedSpace K} (hx : x ∈ (convexBodySum K B)) : -x ∈ (convexBodySum K B) := by rw [Set.mem_setOf, convexBodySumFun_neg] exact hx theorem convexBodySum_convex : Convex ℝ (convexBodySum K B) := by refine Convex_subadditive_le (fun _ _ => convexBodySumFun_add_le _ _) (fun c x h => ?_) B convert le_of_eq (convexBodySumFun_smul c x) exact (abs_eq_self.mpr h).symm theorem convexBodySum_isBounded : Bornology.IsBounded (convexBodySum K B) := by classical refine Metric.isBounded_iff.mpr ⟨B + B, fun x hx y hy => ?_⟩ refine le_trans (norm_sub_le x y) (add_le_add ?_ ?_) · exact le_trans (norm_le_convexBodySumFun x) hx · exact le_trans (norm_le_convexBodySumFun y) hy theorem convexBodySum_compact : IsCompact (convexBodySum K B) := by classical rw [Metric.isCompact_iff_isClosed_bounded] refine ⟨?_, convexBodySum_isBounded K B⟩ convert IsClosed.preimage (convexBodySumFun_continuous K) (isClosed_Icc : IsClosed (Set.Icc 0 B)) ext simp [convexBodySumFun_nonneg] /-- The fudge factor that appears in the formula for the volume of `convexBodyLt`. -/ noncomputable abbrev convexBodySumFactor : ℝ≥0 := (2 : ℝ≥0) ^ nrRealPlaces K * (NNReal.pi / 2) ^ nrComplexPlaces K / (finrank ℚ K).factorial theorem convexBodySumFactor_ne_zero : convexBodySumFactor K ≠ 0 := by refine div_ne_zero ?_ <| Nat.cast_ne_zero.mpr (Nat.factorial_ne_zero _) exact mul_ne_zero (pow_ne_zero _ two_ne_zero) (pow_ne_zero _ (div_ne_zero NNReal.pi_ne_zero two_ne_zero)) open MeasureTheory MeasureTheory.Measure Real in open scoped Classical in theorem convexBodySum_volume : volume (convexBodySum K B) = (convexBodySumFactor K) * (.ofReal B) ^ (finrank ℚ K) := by obtain hB | hB := le_or_lt B 0 · rw [convexBodySum_volume_eq_zero_of_le_zero K hB, ofReal_eq_zero.mpr hB, zero_pow, mul_zero] exact finrank_pos.ne' · suffices volume (convexBodySum K 1) = (convexBodySumFactor K) by rw [mul_comm] convert addHaar_smul volume B (convexBodySum K 1) · simp_rw [← Set.preimage_smul_inv₀ (ne_of_gt hB), Set.preimage_setOf_eq, convexBodySumFun, normAtPlace_smul, abs_inv, abs_eq_self.mpr (le_of_lt hB), ← mul_assoc, mul_comm, mul_assoc, ← Finset.mul_sum, inv_mul_le_iff₀ hB, mul_one] · rw [abs_pow, ofReal_pow (abs_nonneg _), abs_eq_self.mpr (le_of_lt hB), mixedEmbedding.finrank] · exact this.symm rw [MeasureTheory.measure_le_eq_lt _ ((convexBodySumFun_eq_zero_iff 0).mpr rfl) convexBodySumFun_neg convexBodySumFun_add_le (fun hx => (convexBodySumFun_eq_zero_iff _).mp hx) (fun r x => le_of_eq (convexBodySumFun_smul r x))] rw [measure_lt_one_eq_integral_div_gamma (g := fun x : (mixedSpace K) => convexBodySumFun x) volume ((convexBodySumFun_eq_zero_iff 0).mpr rfl) convexBodySumFun_neg convexBodySumFun_add_le (fun hx => (convexBodySumFun_eq_zero_iff _).mp hx) (fun r x => le_of_eq (convexBodySumFun_smul r x)) zero_lt_one] simp_rw [mixedEmbedding.finrank, div_one, Gamma_nat_eq_factorial, ofReal_div_of_pos (Nat.cast_pos.mpr (Nat.factorial_pos _)), Real.rpow_one, ofReal_natCast] suffices ∫ x : mixedSpace K, exp (-convexBodySumFun x) = (2 : ℝ) ^ nrRealPlaces K * (π / 2) ^ nrComplexPlaces K by rw [this, convexBodySumFactor, ofReal_mul (by positivity), ofReal_pow zero_le_two, ofReal_pow (by positivity), ofReal_div_of_pos zero_lt_two, ofReal_ofNat, ← NNReal.coe_real_pi, ofReal_coe_nnreal, coe_div (Nat.cast_ne_zero.mpr (Nat.factorial_ne_zero _)), coe_mul, coe_pow, coe_pow, coe_ofNat, coe_div two_ne_zero, coe_ofNat, coe_natCast] calc _ = (∫ x : {w : InfinitePlace K // IsReal w} → ℝ, ∏ w, exp (- ‖x w‖)) * (∫ x : {w : InfinitePlace K // IsComplex w} → ℂ, ∏ w, exp (- 2 * ‖x w‖)) := by simp_rw [convexBodySumFun_apply', neg_add, ← neg_mul, Finset.mul_sum, ← Finset.sum_neg_distrib, exp_add, exp_sum, ← integral_prod_mul, volume_eq_prod] _ = (∫ x : ℝ, exp (-|x|)) ^ nrRealPlaces K * (∫ x : ℂ, Real.exp (-2 * ‖x‖)) ^ nrComplexPlaces K := by rw [integral_fintype_prod_eq_pow _ (fun x => exp (- ‖x‖)), integral_fintype_prod_eq_pow _ (fun x => exp (- 2 * ‖x‖))] simp_rw [norm_eq_abs] _ = (2 * Gamma (1 / 1 + 1)) ^ nrRealPlaces K * (π * (2 : ℝ) ^ (-(2 : ℝ) / 1) * Gamma (2 / 1 + 1)) ^ nrComplexPlaces K := by rw [integral_comp_abs (f := fun x => exp (- x)), ← integral_exp_neg_rpow zero_lt_one, ← Complex.integral_exp_neg_mul_rpow le_rfl zero_lt_two] simp_rw [Real.rpow_one] _ = (2 : ℝ) ^ nrRealPlaces K * (π / 2) ^ nrComplexPlaces K := by simp_rw [div_one, one_add_one_eq_two, Gamma_add_one two_ne_zero, Gamma_two, mul_one, mul_assoc, ← Real.rpow_add_one two_ne_zero, show (-2 : ℝ) + 1 = -1 by norm_num, Real.rpow_neg_one, div_eq_mul_inv] end convexBodySum section minkowski open MeasureTheory MeasureTheory.Measure Module ZSpan Real Submodule open scoped ENNReal NNReal nonZeroDivisors IntermediateField variable [NumberField K] (I : (FractionalIdeal (𝓞 K)⁰ K)ˣ) open scoped Classical in /-- The bound that appears in **Minkowski Convex Body theorem**, see `MeasureTheory.exists_ne_zero_mem_lattice_of_measure_mul_two_pow_lt_measure`. See `NumberField.mixedEmbedding.volume_fundamentalDomain_idealLatticeBasis_eq` and `NumberField.mixedEmbedding.volume_fundamentalDomain_latticeBasis` for the computation of `volume (fundamentalDomain (idealLatticeBasis K))`. -/ noncomputable def minkowskiBound : ℝ≥0∞ := volume (fundamentalDomain (fractionalIdealLatticeBasis K I)) * (2 : ℝ≥0∞) ^ (finrank ℝ (mixedSpace K)) open scoped Classical in theorem volume_fundamentalDomain_fractionalIdealLatticeBasis : volume (fundamentalDomain (fractionalIdealLatticeBasis K I)) = .ofReal (FractionalIdeal.absNorm I.1) * volume (fundamentalDomain (latticeBasis K)) := by let e : (Module.Free.ChooseBasisIndex ℤ I) ≃ (Module.Free.ChooseBasisIndex ℤ (𝓞 K)) := by refine Fintype.equivOfCardEq ?_ rw [← finrank_eq_card_chooseBasisIndex, ← finrank_eq_card_chooseBasisIndex, fractionalIdeal_rank] rw [← fundamentalDomain_reindex (fractionalIdealLatticeBasis K I) e, measure_fundamentalDomain ((fractionalIdealLatticeBasis K I).reindex e)] · rw [show (fractionalIdealLatticeBasis K I).reindex e = (mixedEmbedding K) ∘ (basisOfFractionalIdeal K I) ∘ e.symm by ext1; simp only [Basis.coe_reindex, Function.comp_apply, fractionalIdealLatticeBasis_apply]] rw [mixedEmbedding.det_basisOfFractionalIdeal_eq_norm] theorem minkowskiBound_lt_top : minkowskiBound K I < ⊤ := by classical -- FIXME: Make `finiteness` work here exact ENNReal.mul_lt_top (fundamentalDomain_isBounded _).measure_lt_top <| ENNReal.pow_lt_top ENNReal.ofNat_lt_top theorem minkowskiBound_pos : 0 < minkowskiBound K I := by classical refine zero_lt_iff.mpr (mul_ne_zero ?_ ?_) · exact ZSpan.measure_fundamentalDomain_ne_zero _ · exact ENNReal.pow_ne_zero two_ne_zero _ variable {f : InfinitePlace K → ℝ≥0} (I : (FractionalIdeal (𝓞 K)⁰ K)ˣ) open scoped Classical in /-- Let `I` be a fractional ideal of `K`. Assume that `f : InfinitePlace K → ℝ≥0` is such that `minkowskiBound K I < volume (convexBodyLT K f)` where `convexBodyLT K f` is the set of points `x` such that `‖x w‖ < f w` for all infinite places `w` (see `convexBodyLT_volume` for the computation of this volume), then there exists a nonzero algebraic number `a` in `I` such that `w a < f w` for all infinite places `w`. -/ theorem exists_ne_zero_mem_ideal_lt (h : minkowskiBound K I < volume (convexBodyLT K f)) : ∃ a ∈ (I : FractionalIdeal (𝓞 K)⁰ K), a ≠ 0 ∧ ∀ w : InfinitePlace K, w a < f w := by have h_fund := ZSpan.isAddFundamentalDomain' (fractionalIdealLatticeBasis K I) volume have : Countable (span ℤ (Set.range (fractionalIdealLatticeBasis K I))).toAddSubgroup := by change Countable (span ℤ (Set.range (fractionalIdealLatticeBasis K I))) infer_instance obtain ⟨⟨x, hx⟩, h_nz, h_mem⟩ := exists_ne_zero_mem_lattice_of_measure_mul_two_pow_lt_measure h_fund (convexBodyLT_neg_mem K f) (convexBodyLT_convex K f) h rw [mem_toAddSubgroup, mem_span_fractionalIdealLatticeBasis] at hx obtain ⟨a, ha, rfl⟩ := hx exact ⟨a, ha, by simpa using h_nz, (convexBodyLT_mem K f).mp h_mem⟩ open scoped Classical in /-- A version of `exists_ne_zero_mem_ideal_lt` where the absolute value of the real part of `a` is smaller than `1` at some fixed complex place. This is useful to ensure that `a` is not real. -/ theorem exists_ne_zero_mem_ideal_lt' (w₀ : {w : InfinitePlace K // IsComplex w}) (h : minkowskiBound K I < volume (convexBodyLT' K f w₀)) : ∃ a ∈ (I : FractionalIdeal (𝓞 K)⁰ K), a ≠ 0 ∧ (∀ w : InfinitePlace K, w ≠ w₀ → w a < f w) ∧ |(w₀.val.embedding a).re| < 1 ∧ |(w₀.val.embedding a).im| < (f w₀ : ℝ) ^ 2 := by have h_fund := ZSpan.isAddFundamentalDomain' (fractionalIdealLatticeBasis K I) volume have : Countable (span ℤ (Set.range (fractionalIdealLatticeBasis K I))).toAddSubgroup := by change Countable (span ℤ (Set.range (fractionalIdealLatticeBasis K I))) infer_instance obtain ⟨⟨x, hx⟩, h_nz, h_mem⟩ := exists_ne_zero_mem_lattice_of_measure_mul_two_pow_lt_measure h_fund (convexBodyLT'_neg_mem K f w₀) (convexBodyLT'_convex K f w₀) h rw [mem_toAddSubgroup, mem_span_fractionalIdealLatticeBasis] at hx obtain ⟨a, ha, rfl⟩ := hx exact ⟨a, ha, by simpa using h_nz, (convexBodyLT'_mem K f w₀).mp h_mem⟩ open scoped Classical in /-- A version of `exists_ne_zero_mem_ideal_lt` for the ring of integers of `K`. -/ theorem exists_ne_zero_mem_ringOfIntegers_lt (h : minkowskiBound K ↑1 < volume (convexBodyLT K f)) : ∃ a : 𝓞 K, a ≠ 0 ∧ ∀ w : InfinitePlace K, w a < f w := by obtain ⟨_, h_mem, h_nz, h_bd⟩ := exists_ne_zero_mem_ideal_lt K ↑1 h obtain ⟨a, rfl⟩ := (FractionalIdeal.mem_one_iff _).mp h_mem exact ⟨a, RingOfIntegers.coe_ne_zero_iff.mp h_nz, h_bd⟩ open scoped Classical in /-- A version of `exists_ne_zero_mem_ideal_lt'` for the ring of integers of `K`. -/ theorem exists_ne_zero_mem_ringOfIntegers_lt' (w₀ : {w : InfinitePlace K // IsComplex w}) (h : minkowskiBound K ↑1 < volume (convexBodyLT' K f w₀)) : ∃ a : 𝓞 K, a ≠ 0 ∧ (∀ w : InfinitePlace K, w ≠ w₀ → w a < f w) ∧ |(w₀.val.embedding a).re| < 1 ∧ |(w₀.val.embedding a).im| < (f w₀ : ℝ) ^ 2 := by obtain ⟨_, h_mem, h_nz, h_bd⟩ := exists_ne_zero_mem_ideal_lt' K ↑1 w₀ h obtain ⟨a, rfl⟩ := (FractionalIdeal.mem_one_iff _).mp h_mem exact ⟨a, RingOfIntegers.coe_ne_zero_iff.mp h_nz, h_bd⟩ theorem exists_primitive_element_lt_of_isReal {w₀ : InfinitePlace K} (hw₀ : IsReal w₀) {B : ℝ≥0} (hB : minkowskiBound K ↑1 < convexBodyLTFactor K * B) : ∃ a : 𝓞 K, ℚ⟮(a : K)⟯ = ⊤ ∧ ∀ w : InfinitePlace K, w a < max B 1 := by classical have : minkowskiBound K ↑1 < volume (convexBodyLT K (fun w ↦ if w = w₀ then B else 1)) := by rw [convexBodyLT_volume, ← Finset.prod_erase_mul _ _ (Finset.mem_univ w₀)] simp_rw [ite_pow, one_pow] rw [Finset.prod_ite_eq'] simp_rw [Finset.not_mem_erase, ite_false, mult, hw₀, ite_true, one_mul, pow_one] exact hB obtain ⟨a, h_nz, h_le⟩ := exists_ne_zero_mem_ringOfIntegers_lt K this refine ⟨a, ?_, fun w ↦ lt_of_lt_of_le (h_le w) ?_⟩ · exact is_primitive_element_of_infinitePlace_lt h_nz (fun w h_ne ↦ by convert (if_neg h_ne) ▸ h_le w) (Or.inl hw₀) · split_ifs <;> simp theorem exists_primitive_element_lt_of_isComplex {w₀ : InfinitePlace K} (hw₀ : IsComplex w₀)
{B : ℝ≥0} (hB : minkowskiBound K ↑1 < convexBodyLT'Factor K * B) : ∃ a : 𝓞 K, ℚ⟮(a : K)⟯ = ⊤ ∧ ∀ w : InfinitePlace K, w a < Real.sqrt (1 + B ^ 2) := by classical have : minkowskiBound K ↑1 < volume (convexBodyLT' K (fun w ↦ if w = w₀ then NNReal.sqrt B else 1) ⟨w₀, hw₀⟩) := by rw [convexBodyLT'_volume, ← Finset.prod_erase_mul _ _ (Finset.mem_univ w₀)] simp_rw [ite_pow, one_pow] rw [Finset.prod_ite_eq'] simp_rw [Finset.not_mem_erase, ite_false, mult, not_isReal_iff_isComplex.mpr hw₀, ite_true, ite_false, one_mul, NNReal.sq_sqrt] exact hB obtain ⟨a, h_nz, h_le, h_le₀⟩ := exists_ne_zero_mem_ringOfIntegers_lt' K ⟨w₀, hw₀⟩ this refine ⟨a, ?_, fun w ↦ ?_⟩ · exact is_primitive_element_of_infinitePlace_lt h_nz
Mathlib/NumberTheory/NumberField/CanonicalEmbedding/ConvexBody.lean
547
561
/- Copyright (c) 2022 Apurva Nakade. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Apurva Nakade -/ import Mathlib.Analysis.Convex.Cone.Closure import Mathlib.Analysis.InnerProductSpace.Adjoint /-! # Proper cones We define a *proper cone* as a closed, pointed cone. Proper cones are used in defining conic programs which generalize linear programs. A linear program is a conic program for the positive cone. We then prove Farkas' lemma for conic programs following the proof in the reference below. Farkas' lemma is equivalent to strong duality. So, once we have the definitions of conic and linear programs, the results from this file can be used to prove duality theorems. ## TODO The next steps are: - Add convex_cone_class that extends set_like and replace the below instance - Define primal and dual cone programs and prove weak duality. - Prove regular and strong duality for cone programs using Farkas' lemma (see reference). - Define linear programs and prove LP duality as a special case of cone duality. - Find a better reference (textbook instead of lecture notes). ## References - [B. Gartner and J. Matousek, Cone Programming][gartnerMatousek] -/ open ContinuousLinearMap Filter Set /-- A proper cone is a pointed cone `K` that is closed. Proper cones have the nice property that they are equal to their double dual, see `ProperCone.dual_dual`. This makes them useful for defining cone programs and proving duality theorems. -/ structure ProperCone (𝕜 : Type*) (E : Type*) [Semiring 𝕜] [PartialOrder 𝕜] [IsOrderedRing 𝕜] [AddCommMonoid E] [TopologicalSpace E] [Module 𝕜 E] extends Submodule {c : 𝕜 // 0 ≤ c} E where isClosed' : IsClosed (carrier : Set E) namespace ProperCone section Module variable {𝕜 : Type*} [Semiring 𝕜] [PartialOrder 𝕜] [IsOrderedRing 𝕜] variable {E : Type*} [AddCommMonoid E] [TopologicalSpace E] [Module 𝕜 E] /-- A `PointedCone` is defined as an alias of submodule. We replicate the abbreviation here and define `toPointedCone` as an alias of `toSubmodule`. -/ abbrev toPointedCone (C : ProperCone 𝕜 E) := C.toSubmodule attribute [coe] toPointedCone instance : Coe (ProperCone 𝕜 E) (PointedCone 𝕜 E) := ⟨toPointedCone⟩ theorem toPointedCone_injective : Function.Injective ((↑) : ProperCone 𝕜 E → PointedCone 𝕜 E) := fun S T h => by cases S; cases T; congr -- TODO: add `ConvexConeClass` that extends `SetLike` and replace the below instance instance : SetLike (ProperCone 𝕜 E) E where coe K := K.carrier coe_injective' _ _ h := ProperCone.toPointedCone_injective (SetLike.coe_injective h) @[ext] theorem ext {S T : ProperCone 𝕜 E} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h @[simp] theorem mem_coe {x : E} {K : ProperCone 𝕜 E} : x ∈ (K : PointedCone 𝕜 E) ↔ x ∈ K := Iff.rfl instance instZero (K : ProperCone 𝕜 E) : Zero K := PointedCone.instZero (K.toSubmodule) protected theorem nonempty (K : ProperCone 𝕜 E) : (K : Set E).Nonempty := ⟨0, by { simp_rw [SetLike.mem_coe, ← ProperCone.mem_coe, Submodule.zero_mem] }⟩ protected theorem isClosed (K : ProperCone 𝕜 E) : IsClosed (K : Set E) := K.isClosed' end Module section PositiveCone variable (𝕜 E) variable [Semiring 𝕜] [PartialOrder 𝕜] [IsOrderedRing 𝕜] [AddCommGroup E] [PartialOrder E] [IsOrderedAddMonoid E] [Module 𝕜 E] [OrderedSMul 𝕜 E] [TopologicalSpace E] [OrderClosedTopology E] /-- The positive cone is the proper cone formed by the set of nonnegative elements in an ordered module. -/ def positive : ProperCone 𝕜 E where toSubmodule := PointedCone.positive 𝕜 E isClosed' := isClosed_Ici @[simp] theorem mem_positive {x : E} : x ∈ positive 𝕜 E ↔ 0 ≤ x := Iff.rfl @[simp] theorem coe_positive : ↑(positive 𝕜 E) = ConvexCone.positive 𝕜 E := rfl end PositiveCone section Module variable {𝕜 : Type*} [Semiring 𝕜] [PartialOrder 𝕜] [IsOrderedRing 𝕜] variable {E : Type*} [AddCommMonoid E] [TopologicalSpace E] [T1Space E] [Module 𝕜 E] instance : Zero (ProperCone 𝕜 E) := ⟨{ toSubmodule := 0 isClosed' := isClosed_singleton }⟩ instance : Inhabited (ProperCone 𝕜 E) := ⟨0⟩ @[simp] theorem mem_zero (x : E) : x ∈ (0 : ProperCone 𝕜 E) ↔ x = 0 := Iff.rfl @[simp, norm_cast] theorem coe_zero : ↑(0 : ProperCone 𝕜 E) = (0 : ConvexCone 𝕜 E) := rfl theorem pointed_zero : ((0 : ProperCone 𝕜 E) : ConvexCone 𝕜 E).Pointed := by simp [ConvexCone.pointed_zero] end Module section InnerProductSpace variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] variable {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] variable {G : Type*} [NormedAddCommGroup G] [InnerProductSpace ℝ G] protected theorem pointed (K : ProperCone ℝ E) : (K : ConvexCone ℝ E).Pointed := (K : ConvexCone ℝ E).pointed_of_nonempty_of_isClosed K.nonempty K.isClosed /-- The closure of image of a proper cone under a continuous `ℝ`-linear map is a proper cone. We use continuous maps here so that the comap of f is also a map between proper cones. -/ noncomputable def map (f : E →L[ℝ] F) (K : ProperCone ℝ E) : ProperCone ℝ F where toSubmodule := PointedCone.closure (PointedCone.map (f : E →ₗ[ℝ] F) ↑K) isClosed' := isClosed_closure @[simp, norm_cast] theorem coe_map (f : E →L[ℝ] F) (K : ProperCone ℝ E) : ↑(K.map f) = (PointedCone.map (f : E →ₗ[ℝ] F) ↑K).closure := rfl @[simp] theorem mem_map {f : E →L[ℝ] F} {K : ProperCone ℝ E} {y : F} : y ∈ K.map f ↔ y ∈ (PointedCone.map (f : E →ₗ[ℝ] F) ↑K).closure := Iff.rfl @[simp] theorem map_id (K : ProperCone ℝ E) : K.map (ContinuousLinearMap.id ℝ E) = K := ProperCone.toPointedCone_injective <| by simpa using IsClosed.closure_eq K.isClosed /-- The inner dual cone of a proper cone is a proper cone. -/ def dual (K : ProperCone ℝ E) : ProperCone ℝ E where toSubmodule := PointedCone.dual (K : PointedCone ℝ E) isClosed' := isClosed_innerDualCone _ @[simp, norm_cast] theorem coe_dual (K : ProperCone ℝ E) : K.dual = (K : Set E).innerDualCone := rfl open scoped InnerProductSpace in @[simp] theorem mem_dual {K : ProperCone ℝ E} {y : E} : y ∈ dual K ↔ ∀ ⦃x⦄, x ∈ K → 0 ≤ ⟪x, y⟫_ℝ := by aesop /-- The preimage of a proper cone under a continuous `ℝ`-linear map is a proper cone. -/ noncomputable def comap (f : E →L[ℝ] F) (S : ProperCone ℝ F) : ProperCone ℝ E where toSubmodule := PointedCone.comap (f : E →ₗ[ℝ] F) S isClosed' := by rw [PointedCone.comap] apply IsClosed.preimage f.2 S.isClosed @[simp] theorem coe_comap (f : E →L[ℝ] F) (S : ProperCone ℝ F) : (S.comap f : Set E) = f ⁻¹' S := rfl @[simp] theorem comap_id (S : ConvexCone ℝ E) : S.comap LinearMap.id = S := SetLike.coe_injective preimage_id theorem comap_comap (g : F →L[ℝ] G) (f : E →L[ℝ] F) (S : ProperCone ℝ G) : (S.comap g).comap f = S.comap (g.comp f) := SetLike.coe_injective <| by congr @[simp] theorem mem_comap {f : E →L[ℝ] F} {S : ProperCone ℝ F} {x : E} : x ∈ S.comap f ↔ f x ∈ S := Iff.rfl end InnerProductSpace section CompleteSpace open scoped InnerProductSpace variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [CompleteSpace E] variable {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] [CompleteSpace F] /-- The dual of the dual of a proper cone is itself. -/ @[simp] theorem dual_dual (K : ProperCone ℝ E) : K.dual.dual = K := ProperCone.toPointedCone_injective <| PointedCone.toConvexCone_injective <| (K : ConvexCone ℝ E).innerDualCone_of_innerDualCone_eq_self K.nonempty K.isClosed /-- This is a relative version of `ConvexCone.hyperplane_separation_of_nonempty_of_isClosed_of_nmem`, which we recover by setting
`f` to be the identity map. This is also a geometric interpretation of the Farkas' lemma stated using proper cones. -/ theorem hyperplane_separation (K : ProperCone ℝ E) {f : E →L[ℝ] F} {b : F} :
Mathlib/Analysis/Convex/Cone/Proper.lean
215
217
/- 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.Data.List.Duplicate import Mathlib.Data.List.Sort /-! # Equivalence between `Fin (length l)` and elements of a list Given a list `l`, * if `l` has no duplicates, then `List.Nodup.getEquiv` is the equivalence between `Fin (length l)` and `{x // x ∈ l}` sending `i` to `⟨get l i, _⟩` with the inverse sending `⟨x, hx⟩` to `⟨indexOf x l, _⟩`; * if `l` has no duplicates and contains every element of a type `α`, then `List.Nodup.getEquivOfForallMemList` defines an equivalence between `Fin (length l)` and `α`; if `α` does not have decidable equality, then there is a bijection `List.Nodup.getBijectionOfForallMemList`; * if `l` is sorted w.r.t. `(<)`, then `List.Sorted.getIso` is the same bijection reinterpreted as an `OrderIso`. -/ namespace List variable {α : Type*} namespace Nodup /-- If `l` lists all the elements of `α` without duplicates, then `List.get` defines a bijection `Fin l.length → α`. See `List.Nodup.getEquivOfForallMemList` for a version giving an equivalence when there is decidable equality. -/ @[simps] def getBijectionOfForallMemList (l : List α) (nd : l.Nodup) (h : ∀ x : α, x ∈ l) : { f : Fin l.length → α // Function.Bijective f } := ⟨fun i => l.get i, fun _ _ h => nd.get_inj_iff.1 h, fun x => let ⟨i, hl⟩ := List.mem_iff_get.1 (h x) ⟨i, hl⟩⟩ variable [DecidableEq α] /-- If `l` has no duplicates, then `List.get` defines an equivalence between `Fin (length l)` and the set of elements of `l`. -/ @[simps] def getEquiv (l : List α) (H : Nodup l) : Fin (length l) ≃ { x // x ∈ l } where toFun i := ⟨get l i, get_mem _ _⟩ invFun x := ⟨idxOf (↑x) l, idxOf_lt_length_iff.2 x.2⟩ left_inv i := by simp only [List.get_idxOf, eq_self_iff_true, Fin.eta, Subtype.coe_mk, H] right_inv x := by simp /-- If `l` lists all the elements of `α` without duplicates, then `List.get` defines an equivalence between `Fin l.length` and `α`. See `List.Nodup.getBijectionOfForallMemList` for a version without decidable equality. -/ @[simps] def getEquivOfForallMemList (l : List α) (nd : l.Nodup) (h : ∀ x : α, x ∈ l) : Fin l.length ≃ α where toFun i := l.get i invFun a := ⟨_, idxOf_lt_length_iff.2 (h a)⟩ left_inv i := by simp [List.idxOf_getElem, nd] right_inv a := by simp end Nodup namespace Sorted variable [Preorder α] {l : List α} theorem get_mono (h : l.Sorted (· ≤ ·)) : Monotone l.get := fun _ _ => h.rel_get_of_le theorem get_strictMono (h : l.Sorted (· < ·)) : StrictMono l.get := fun _ _ => h.rel_get_of_lt variable [DecidableEq α] /-- If `l` is a list sorted w.r.t. `(<)`, then `List.get` defines an order isomorphism between `Fin (length l)` and the set of elements of `l`. -/ def getIso (l : List α) (H : Sorted (· < ·) l) : Fin (length l) ≃o { x // x ∈ l } where toEquiv := H.nodup.getEquiv l map_rel_iff' := H.get_strictMono.le_iff_le variable (H : Sorted (· < ·) l) {x : { x // x ∈ l }} {i : Fin l.length} @[simp] theorem coe_getIso_apply : (H.getIso l i : α) = get l i := rfl @[simp] theorem coe_getIso_symm_apply : ((H.getIso l).symm x : ℕ) = idxOf (↑x) l := rfl end Sorted section Sublist /-- If there is `f`, an order-preserving embedding of `ℕ` into `ℕ` such that any element of `l` found at index `ix` can be found at index `f ix` in `l'`, then `Sublist l l'`. -/ theorem sublist_of_orderEmbedding_getElem?_eq {l l' : List α} (f : ℕ ↪o ℕ) (hf : ∀ ix : ℕ, l[ix]? = l'[f ix]?) : l <+ l' := by induction' l with hd tl IH generalizing l' f · simp have : some hd = l'[f 0]? := by simpa using hf 0 rw [eq_comm, List.getElem?_eq_some_iff] at this obtain ⟨w, h⟩ := this let f' : ℕ ↪o ℕ := OrderEmbedding.ofMapLEIff (fun i => f (i + 1) - (f 0 + 1)) fun a b => by dsimp only rw [Nat.sub_le_sub_iff_right, OrderEmbedding.le_iff_le, Nat.succ_le_succ_iff] rw [Nat.succ_le_iff, OrderEmbedding.lt_iff_lt] exact b.succ_pos have : ∀ ix, tl[ix]? = (l'.drop (f 0 + 1))[f' ix]? := by intro ix rw [List.getElem?_drop, OrderEmbedding.coe_ofMapLEIff, Nat.add_sub_cancel', ← hf] simp only [getElem?_cons_succ] rw [Nat.succ_le_iff, OrderEmbedding.lt_iff_lt] exact ix.succ_pos rw [← List.take_append_drop (f 0 + 1) l', ← List.singleton_append] apply List.Sublist.append _ (IH _ this) rw [List.singleton_sublist, ← h, l'.getElem_take' _ (Nat.lt_succ_self _)] exact List.getElem_mem _ @[deprecated (since := "2025-02-15")] alias sublist_of_orderEmbedding_get?_eq := sublist_of_orderEmbedding_getElem?_eq /-- A `l : List α` is `Sublist l l'` for `l' : List α` iff there is `f`, an order-preserving embedding of `ℕ` into `ℕ` such that any element of `l` found at index `ix` can be found at index `f ix` in `l'`. -/ theorem sublist_iff_exists_orderEmbedding_getElem?_eq {l l' : List α} : l <+ l' ↔ ∃ f : ℕ ↪o ℕ, ∀ ix : ℕ, l[ix]? = l'[f ix]? := by constructor · intro H induction H with | slnil => simp | cons _ _ IH => obtain ⟨f, hf⟩ := IH refine ⟨f.trans (OrderEmbedding.ofStrictMono (· + 1) fun _ => by simp), ?_⟩ simpa using hf
| cons₂ _ _ IH => obtain ⟨f, hf⟩ := IH refine ⟨OrderEmbedding.ofMapLEIff (fun ix : ℕ => if ix = 0 then 0 else (f ix.pred).succ) ?_, ?_⟩ · rintro ⟨_ | a⟩ ⟨_ | b⟩ <;> simp [Nat.succ_le_succ_iff] · rintro ⟨_ | i⟩ · simp · simpa using hf _ · rintro ⟨f, hf⟩ exact sublist_of_orderEmbedding_getElem?_eq f hf @[deprecated (since := "2025-02-15")] alias sublist_iff_exists_orderEmbedding_get?_eq := sublist_iff_exists_orderEmbedding_getElem?_eq /-- A `l : List α` is `Sublist l l'` for `l' : List α` iff there is `f`, an order-preserving embedding of `Fin l.length` into `Fin l'.length` such that any element of `l` found at index `ix` can be found at index `f ix` in `l'`. -/
Mathlib/Data/List/NodupEquivFin.lean
147
164
/- 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.Lattice.Prod import Mathlib.Data.Finite.Prod import Mathlib.Data.Set.Lattice.Image /-! # N-ary images of finsets This file defines `Finset.image₂`, the binary image of finsets. This is the finset version of `Set.image2`. This is mostly useful to define pointwise operations. ## Notes This file is very similar to `Data.Set.NAry`, `Order.Filter.NAry` and `Data.Option.NAry`. Please keep them in sync. We do not define `Finset.image₃` as its only purpose would be to prove properties of `Finset.image₂` and `Set.image2` already fulfills this task. -/ open Function Set variable {α α' β β' γ γ' δ δ' ε ε' ζ ζ' ν : Type*} namespace Finset variable [DecidableEq α'] [DecidableEq β'] [DecidableEq γ] [DecidableEq γ'] [DecidableEq δ'] [DecidableEq ε] [DecidableEq ε'] {f f' : α → β → γ} {g g' : α → β → γ → δ} {s s' : Finset α} {t t' : Finset β} {u u' : Finset γ} {a a' : α} {b b' : β} {c : γ} /-- The image of a binary function `f : α → β → γ` as a function `Finset α → Finset β → Finset γ`. Mathematically this should be thought of as the image of the corresponding function `α × β → γ`. -/ def image₂ (f : α → β → γ) (s : Finset α) (t : Finset β) : Finset γ := (s ×ˢ t).image <| uncurry f @[simp] theorem mem_image₂ : c ∈ image₂ f s t ↔ ∃ a ∈ s, ∃ b ∈ t, f a b = c := by simp [image₂, and_assoc] @[simp, norm_cast] theorem coe_image₂ (f : α → β → γ) (s : Finset α) (t : Finset β) : (image₂ f s t : Set γ) = Set.image2 f s t := Set.ext fun _ => mem_image₂ theorem card_image₂_le (f : α → β → γ) (s : Finset α) (t : Finset β) : #(image₂ f s t) ≤ #s * #t := card_image_le.trans_eq <| card_product _ _ theorem card_image₂_iff : #(image₂ f s t) = #s * #t ↔ (s ×ˢ t : Set (α × β)).InjOn fun x => f x.1 x.2 := by rw [← card_product, ← coe_product] exact card_image_iff theorem card_image₂ (hf : Injective2 f) (s : Finset α) (t : Finset β) : #(image₂ f s t) = #s * #t := (card_image_of_injective _ hf.uncurry).trans <| card_product _ _ theorem mem_image₂_of_mem (ha : a ∈ s) (hb : b ∈ t) : f a b ∈ image₂ f s t := mem_image₂.2 ⟨a, ha, b, hb, rfl⟩ theorem mem_image₂_iff (hf : Injective2 f) : f a b ∈ image₂ f s t ↔ a ∈ s ∧ b ∈ t := by rw [← mem_coe, coe_image₂, mem_image2_iff hf, mem_coe, mem_coe] @[gcongr] theorem image₂_subset (hs : s ⊆ s') (ht : t ⊆ t') : image₂ f s t ⊆ image₂ f s' t' := by rw [← coe_subset, coe_image₂, coe_image₂] exact image2_subset hs ht @[gcongr] theorem image₂_subset_left (ht : t ⊆ t') : image₂ f s t ⊆ image₂ f s t' := image₂_subset Subset.rfl ht @[gcongr] theorem image₂_subset_right (hs : s ⊆ s') : image₂ f s t ⊆ image₂ f s' t := image₂_subset hs Subset.rfl theorem image_subset_image₂_left (hb : b ∈ t) : s.image (fun a => f a b) ⊆ image₂ f s t := image_subset_iff.2 fun _ ha => mem_image₂_of_mem ha hb theorem image_subset_image₂_right (ha : a ∈ s) : t.image (fun b => f a b) ⊆ image₂ f s t := image_subset_iff.2 fun _ => mem_image₂_of_mem ha lemma forall_mem_image₂ {p : γ → Prop} : (∀ z ∈ image₂ f s t, p z) ↔ ∀ x ∈ s, ∀ y ∈ t, p (f x y) := by simp_rw [← mem_coe, coe_image₂, forall_mem_image2] lemma exists_mem_image₂ {p : γ → Prop} : (∃ z ∈ image₂ f s t, p z) ↔ ∃ x ∈ s, ∃ y ∈ t, p (f x y) := by simp_rw [← mem_coe, coe_image₂, exists_mem_image2] @[deprecated (since := "2024-11-23")] alias forall_image₂_iff := forall_mem_image₂ @[simp] theorem image₂_subset_iff : image₂ f s t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, f x y ∈ u := forall_mem_image₂ theorem image₂_subset_iff_left : image₂ f s t ⊆ u ↔ ∀ a ∈ s, (t.image fun b => f a b) ⊆ u := by simp_rw [image₂_subset_iff, image_subset_iff] theorem image₂_subset_iff_right : image₂ f s t ⊆ u ↔ ∀ b ∈ t, (s.image fun a => f a b) ⊆ u := by simp_rw [image₂_subset_iff, image_subset_iff, @forall₂_swap α] @[simp] theorem image₂_nonempty_iff : (image₂ f s t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := by rw [← coe_nonempty, coe_image₂] exact image2_nonempty_iff @[aesop safe apply (rule_sets := [finsetNonempty])] theorem Nonempty.image₂ (hs : s.Nonempty) (ht : t.Nonempty) : (image₂ f s t).Nonempty := image₂_nonempty_iff.2 ⟨hs, ht⟩ theorem Nonempty.of_image₂_left (h : (s.image₂ f t).Nonempty) : s.Nonempty := (image₂_nonempty_iff.1 h).1 theorem Nonempty.of_image₂_right (h : (s.image₂ f t).Nonempty) : t.Nonempty := (image₂_nonempty_iff.1 h).2 @[simp] theorem image₂_empty_left : image₂ f ∅ t = ∅ := coe_injective <| by simp @[simp] theorem image₂_empty_right : image₂ f s ∅ = ∅ := coe_injective <| by simp @[simp] theorem image₂_eq_empty_iff : image₂ f s t = ∅ ↔ s = ∅ ∨ t = ∅ := by simp_rw [← not_nonempty_iff_eq_empty, image₂_nonempty_iff, not_and_or] @[simp] theorem image₂_singleton_left : image₂ f {a} t = t.image fun b => f a b := ext fun x => by simp @[simp] theorem image₂_singleton_right : image₂ f s {b} = s.image fun a => f a b := ext fun x => by simp theorem image₂_singleton_left' : image₂ f {a} t = t.image (f a) := image₂_singleton_left theorem image₂_singleton : image₂ f {a} {b} = {f a b} := by simp theorem image₂_union_left [DecidableEq α] : image₂ f (s ∪ s') t = image₂ f s t ∪ image₂ f s' t := coe_injective <| by push_cast exact image2_union_left theorem image₂_union_right [DecidableEq β] : image₂ f s (t ∪ t') = image₂ f s t ∪ image₂ f s t' := coe_injective <| by push_cast exact image2_union_right @[simp] theorem image₂_insert_left [DecidableEq α] : image₂ f (insert a s) t = (t.image fun b => f a b) ∪ image₂ f s t := coe_injective <| by push_cast exact image2_insert_left @[simp] theorem image₂_insert_right [DecidableEq β] : image₂ f s (insert b t) = (s.image fun a => f a b) ∪ image₂ f s t := coe_injective <| by push_cast exact image2_insert_right theorem image₂_inter_left [DecidableEq α] (hf : Injective2 f) : image₂ f (s ∩ s') t = image₂ f s t ∩ image₂ f s' t := coe_injective <| by push_cast exact image2_inter_left hf theorem image₂_inter_right [DecidableEq β] (hf : Injective2 f) : image₂ f s (t ∩ t') = image₂ f s t ∩ image₂ f s t' := coe_injective <| by push_cast exact image2_inter_right hf theorem image₂_inter_subset_left [DecidableEq α] : image₂ f (s ∩ s') t ⊆ image₂ f s t ∩ image₂ f s' t := coe_subset.1 <| by push_cast exact image2_inter_subset_left theorem image₂_inter_subset_right [DecidableEq β] : image₂ f s (t ∩ t') ⊆ image₂ f s t ∩ image₂ f s t' := coe_subset.1 <| by push_cast exact image2_inter_subset_right theorem image₂_congr (h : ∀ a ∈ s, ∀ b ∈ t, f a b = f' a b) : image₂ f s t = image₂ f' s t := coe_injective <| by push_cast exact image2_congr h /-- A common special case of `image₂_congr` -/ theorem image₂_congr' (h : ∀ a b, f a b = f' a b) : image₂ f s t = image₂ f' s t := image₂_congr fun a _ b _ => h a b variable (s t) theorem card_image₂_singleton_left (hf : Injective (f a)) : #(image₂ f {a} t) = #t := by rw [image₂_singleton_left, card_image_of_injective _ hf] theorem card_image₂_singleton_right (hf : Injective fun a => f a b) : #(image₂ f s {b}) = #s := by rw [image₂_singleton_right, card_image_of_injective _ hf] theorem image₂_singleton_inter [DecidableEq β] (t₁ t₂ : Finset β) (hf : Injective (f a)) : image₂ f {a} (t₁ ∩ t₂) = image₂ f {a} t₁ ∩ image₂ f {a} t₂ := by simp_rw [image₂_singleton_left, image_inter _ _ hf] theorem image₂_inter_singleton [DecidableEq α] (s₁ s₂ : Finset α) (hf : Injective fun a => f a b) : image₂ f (s₁ ∩ s₂) {b} = image₂ f s₁ {b} ∩ image₂ f s₂ {b} := by simp_rw [image₂_singleton_right, image_inter _ _ hf] theorem card_le_card_image₂_left {s : Finset α} (hs : s.Nonempty) (hf : ∀ a, Injective (f a)) : #t ≤ #(image₂ f s t) := by obtain ⟨a, ha⟩ := hs rw [← card_image₂_singleton_left _ (hf a)] exact card_le_card (image₂_subset_right <| singleton_subset_iff.2 ha) theorem card_le_card_image₂_right {t : Finset β} (ht : t.Nonempty) (hf : ∀ b, Injective fun a => f a b) : #s ≤ #(image₂ f s t) := by obtain ⟨b, hb⟩ := ht rw [← card_image₂_singleton_right _ (hf b)] exact card_le_card (image₂_subset_left <| singleton_subset_iff.2 hb) variable {s t} theorem biUnion_image_left : (s.biUnion fun a => t.image <| f a) = image₂ f s t := coe_injective <| by push_cast exact Set.iUnion_image_left _ theorem biUnion_image_right : (t.biUnion fun b => s.image fun a => f a b) = image₂ f s t := coe_injective <| by push_cast exact Set.iUnion_image_right _ /-! ### Algebraic replacement rules A collection of lemmas to transfer associativity, commutativity, distributivity, ... of operations to the associativity, commutativity, distributivity, ... of `Finset.image₂` of those operations. The proof pattern is `image₂_lemma operation_lemma`. For example, `image₂_comm mul_comm` proves that `image₂ (*) f g = image₂ (*) g f` in a `CommSemigroup`. -/ section variable [DecidableEq δ] theorem image_image₂ (f : α → β → γ) (g : γ → δ) : (image₂ f s t).image g = image₂ (fun a b => g (f a b)) s t := coe_injective <| by push_cast exact image_image2 _ _ theorem image₂_image_left (f : γ → β → δ) (g : α → γ) : image₂ f (s.image g) t = image₂ (fun a b => f (g a) b) s t := coe_injective <| by push_cast exact image2_image_left _ _ theorem image₂_image_right (f : α → γ → δ) (g : β → γ) : image₂ f s (t.image g) = image₂ (fun a b => f a (g b)) s t := coe_injective <| by push_cast exact image2_image_right _ _ @[simp] theorem image₂_mk_eq_product [DecidableEq α] [DecidableEq β] (s : Finset α) (t : Finset β) : image₂ Prod.mk s t = s ×ˢ t := by ext; simp [Prod.ext_iff] @[simp] theorem image₂_curry (f : α × β → γ) (s : Finset α) (t : Finset β) : image₂ (curry f) s t = (s ×ˢ t).image f := rfl @[simp] theorem image_uncurry_product (f : α → β → γ) (s : Finset α) (t : Finset β) : (s ×ˢ t).image (uncurry f) = image₂ f s t := rfl theorem image₂_swap (f : α → β → γ) (s : Finset α) (t : Finset β) : image₂ f s t = image₂ (fun a b => f b a) t s := coe_injective <| by push_cast exact image2_swap _ _ _ @[simp] theorem image₂_left [DecidableEq α] (h : t.Nonempty) : image₂ (fun x _ => x) s t = s := coe_injective <| by push_cast exact image2_left h @[simp] theorem image₂_right [DecidableEq β] (h : s.Nonempty) : image₂ (fun _ y => y) s t = t := coe_injective <| by push_cast exact image2_right h
theorem image₂_assoc {γ : Type*} {u : Finset γ} {f : δ → γ → ε} {g : α → β → δ} {f' : α → ε' → ε} {g' : β → γ → ε'} (h_assoc : ∀ a b c, f (g a b) c = f' a (g' b c)) : image₂ f (image₂ g s t) u = image₂ f' s (image₂ g' t u) := coe_injective <| by
Mathlib/Data/Finset/NAry.lean
305
309
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Localization.Bousfield import Mathlib.CategoryTheory.Sites.Sheafification /-! # The sheaf category as a localized category In this file, it is shown that the category of sheaves `Sheaf J A` is a localization of the category `Presheaf J A` with respect to the class `J.W` of morphisms of presheaves which become isomorphisms after applying the sheafification functor. -/ namespace CategoryTheory open Localization variable {C : Type*} [Category C] (J : GrothendieckTopology C) {A : Type*} [Category A] namespace GrothendieckTopology /-- The class of morphisms of presheaves which become isomorphisms after sheafification. (See `GrothendieckTopology.W_iff`.) -/ abbrev W : MorphismProperty (Cᵒᵖ ⥤ A) := LeftBousfield.W (Presheaf.IsSheaf J) variable (A) in
lemma W_eq_W_range_sheafToPresheaf_obj : J.W = LeftBousfield.W (· ∈ Set.range (sheafToPresheaf J A).obj) := by apply congr_arg ext P constructor · intro hP exact ⟨⟨P, hP⟩, rfl⟩ · rintro ⟨F, rfl⟩ exact F.cond
Mathlib/CategoryTheory/Sites/Localization.lean
31
39
/- Copyright (c) 2020 Patrick Stevens. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Stevens, Bolton Bailey -/ import Mathlib.Data.Nat.Choose.Factorization import Mathlib.NumberTheory.Primorial import Mathlib.Analysis.Convex.SpecificFunctions.Basic import Mathlib.Analysis.Convex.SpecificFunctions.Deriv import Mathlib.Tactic.NormNum.Prime /-! # Bertrand's Postulate This file contains a proof of Bertrand's postulate: That between any positive number and its double there is a prime. The proof follows the outline of the Erdős proof presented in "Proofs from THE BOOK": One considers the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various groups, then upper bounds the contribution of each group. This upper bounds the central binomial coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n` an explicit list of primes is provided which covers the remaining cases. As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from [Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`. ## References * [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs] * [S. Tochiori, _Considering the Proof of “There is a Prime between n and 2n”_][tochiori_bertrand] * [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic] ## Tags Bertrand, prime, binomial coefficients -/ section Real open Real namespace Bertrand /-- A refined version of the `Bertrand.main_inequality` below. This is not best possible: it actually holds for 464 ≤ x. -/ theorem real_main_inequality {x : ℝ} (x_large : (512 : ℝ) ≤ x) : x * (2 * x) ^ √(2 * x) * 4 ^ (2 * x / 3) ≤ 4 ^ x := by let f : ℝ → ℝ := fun x => log x + √(2 * x) * log (2 * x) - log 4 / 3 * x have hf' : ∀ x, 0 < x → 0 < x * (2 * x) ^ √(2 * x) / 4 ^ (x / 3) := fun x h => div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _) have hf : ∀ x, 0 < x → f x = log (x * (2 * x) ^ √(2 * x) / 4 ^ (x / 3)) := by intro x h5 have h6 := mul_pos (zero_lt_two' ℝ) h5 have h7 := rpow_pos_of_pos h6 (√(2 * x)) rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne', log_rpow h6, log_rpow zero_lt_four, ← mul_div_right_comm, ← mul_div, mul_comm x] have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) x_large rw [← div_le_one (rpow_pos_of_pos four_pos x), ← div_div_eq_mul_div, ← rpow_sub four_pos, ← mul_div 2 x, mul_div_left_comm, ← mul_one_sub, (by norm_num1 : (1 : ℝ) - 2 / 3 = 1 / 3), mul_one_div, ← log_nonpos_iff (hf' x h5).le, ← hf x h5] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11083): the proof was rewritten, because it was too slow have h : ConcaveOn ℝ (Set.Ioi 0.5) f := by apply ConcaveOn.sub · apply ConcaveOn.add · exact strictConcaveOn_log_Ioi.concaveOn.subset (Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5) convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap ((2 : ℝ) • LinearMap.id))) using 1 ext x simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply, LinearMap.id_coe, id_eq, smul_eq_mul] rw [← mul_lt_mul_left (two_pos)] norm_num1 rfl apply ConvexOn.smul · refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1) · exact convexOn_id (convex_Ioi (0.5 : ℝ)) suffices ∃ x1 x2, 0.5 < x1 ∧ x1 < x2 ∧ x2 ≤ x ∧ 0 ≤ f x1 ∧ f x2 ≤ 0 by obtain ⟨x1, x2, h1, h2, h0, h3, h4⟩ := this exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4 refine ⟨18, 512, by norm_num1, by norm_num1, x_large, ?_, ?_⟩ · have : √(2 * 18 : ℝ) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1) rw [hf _ (by norm_num1), log_nonneg_iff (by positivity), this, one_le_div (by norm_num1)] norm_num1 · have : √(2 * 512) = 32 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1) rw [hf _ (by norm_num1), log_nonpos_iff (hf' _ (by norm_num1)).le, this, div_le_one (by positivity)] conv in 512 => equals 2 ^ 9 => norm_num1 conv in 2 * 512 => equals 2 ^ 10 => norm_num1 conv in 32 => rw [← Nat.cast_ofNat] rw [rpow_natCast, ← pow_mul, ← pow_add] conv in 4 => equals 2 ^ (2 : ℝ) => rw [rpow_two]; norm_num1 rw [← rpow_mul, ← rpow_natCast] on_goal 1 => apply rpow_le_rpow_of_exponent_le all_goals norm_num1 end Bertrand end Real section Nat open Nat /-- The inequality which contradicts Bertrand's postulate, for large enough `n`. -/ theorem bertrand_main_inequality {n : ℕ} (n_large : 512 ≤ n) : n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) ≤ 4 ^ n := by rw [← @cast_le ℝ] simp only [cast_add, cast_one, cast_mul, cast_pow, ← Real.rpow_natCast] refine _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large)) gcongr · have n2_pos : 0 < 2 * n := by positivity exact mod_cast n2_pos · exact_mod_cast Real.nat_sqrt_le_real_sqrt · norm_num1 · exact cast_div_le.trans (by norm_cast) /-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime factorization of the central binomial coefficient only has factors at most `2 * n / 3 + 1`. -/ theorem centralBinom_factorization_small (n : ℕ) (n_large : 2 < n) (no_prime : ¬∃ p : ℕ, p.Prime ∧ n < p ∧ p ≤ 2 * n) : centralBinom n = ∏ p ∈ Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by refine (Eq.trans ?_ n.prod_pow_factorization_centralBinom).symm apply Finset.prod_subset · exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _) intro x hx h2x rw [Finset.mem_range, Nat.lt_succ_iff] at hx h2x rw [not_le, div_lt_iff_lt_mul three_pos, mul_comm x] at h2x replace no_prime := not_exists.mp no_prime x rw [← and_assoc, not_and', not_and_or, not_lt] at no_prime rcases no_prime hx with h | h · rw [factorization_eq_zero_of_non_prime n.centralBinom h, Nat.pow_zero] · rw [factorization_centralBinom_of_two_mul_self_lt_three_mul n_large h h2x, Nat.pow_zero] /-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate. The bound splits the prime factors of `centralBinom n` into those 1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime. 2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total. 3. Between `2 * n / 3` and `n`, which do not exist. 4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false. 5. Above `2 * n`, which do not exist. -/ theorem centralBinom_le_of_no_bertrand_prime (n : ℕ) (n_large : 2 < n) (no_prime : ¬∃ p : ℕ, Nat.Prime p ∧ n < p ∧ p ≤ 2 * n) : centralBinom n ≤ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) := by have n_pos : 0 < n := (Nat.zero_le _).trans_lt n_large have n2_pos : 1 ≤ 2 * n := mul_pos (zero_lt_two' ℕ) n_pos
let S := {p ∈ Finset.range (2 * n / 3 + 1) | Nat.Prime p} let f x := x ^ n.centralBinom.factorization x have : ∏ x ∈ S, f x = ∏ x ∈ Finset.range (2 * n / 3 + 1), f x := by refine Finset.prod_filter_of_ne fun p _ h => ?_ contrapose! h; dsimp only [f] rw [factorization_eq_zero_of_non_prime n.centralBinom h, _root_.pow_zero] rw [centralBinom_factorization_small n n_large no_prime, ← this, ← Finset.prod_filter_mul_prod_filter_not S (· ≤ sqrt (2 * n))] apply mul_le_mul' · refine (Finset.prod_le_prod' fun p _ => (?_ : f p ≤ 2 * n)).trans ?_ · exact pow_factorization_choose_le (mul_pos two_pos n_pos) have : (Finset.Icc 1 (sqrt (2 * n))).card = sqrt (2 * n) := by rw [card_Icc, Nat.add_sub_cancel] rw [Finset.prod_const] refine pow_right_mono₀ n2_pos ((Finset.card_le_card fun x hx => ?_).trans this.le) obtain ⟨h1, h2⟩ := Finset.mem_filter.1 hx exact Finset.mem_Icc.mpr ⟨(Finset.mem_filter.1 h1).2.one_lt.le, h2⟩ · refine le_trans ?_ (primorial_le_4_pow (2 * n / 3)) refine (Finset.prod_le_prod' fun p hp => (?_ : f p ≤ p)).trans ?_ · obtain ⟨h1, h2⟩ := Finset.mem_filter.1 hp refine (pow_right_mono₀ (Finset.mem_filter.1 h1).2.one_lt.le ?_).trans (pow_one p).le exact Nat.factorization_choose_le_one (sqrt_lt'.mp <| not_le.1 h2) refine Finset.prod_le_prod_of_subset_of_one_le' (Finset.filter_subset _ _) ?_ exact fun p hp _ => (Finset.mem_filter.1 hp).2.one_lt.le namespace Nat /-- Proves that **Bertrand's postulate** holds for all sufficiently large `n`. -/
Mathlib/NumberTheory/Bertrand.lean
155
182
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Lie.Solvable import Mathlib.Algebra.Lie.Quotient import Mathlib.Algebra.Lie.Normalizer import Mathlib.Algebra.Order.Archimedean.Basic import Mathlib.LinearAlgebra.Eigenspace.Basic import Mathlib.RingTheory.Artinian.Module import Mathlib.RingTheory.Nilpotent.Lemmas /-! # Nilpotent Lie algebras Like groups, Lie algebras admit a natural concept of nilpotency. More generally, any Lie module carries a natural concept of nilpotency. We define these here via the lower central series. ## Main definitions * `LieModule.lowerCentralSeries` * `LieModule.IsNilpotent` * `LieModule.maxNilpotentSubmodule` * `LieAlgebra.maxNilpotentIdeal` ## Tags lie algebra, lower central series, nilpotent, max nilpotent ideal -/ universe u v w w₁ w₂ section NilpotentModules variable {R : Type u} {L : Type v} {M : Type w} variable [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] variable [LieRingModule L M] variable (k : ℕ) (N : LieSubmodule R L M) namespace LieSubmodule /-- A generalisation of the lower central series. The zeroth term is a specified Lie submodule of a Lie module. In the case when we specify the top ideal `⊤` of the Lie algebra, regarded as a Lie module over itself, we get the usual lower central series of a Lie algebra. It can be more convenient to work with this generalisation when considering the lower central series of a Lie submodule, regarded as a Lie module in its own right, since it provides a type-theoretic expression of the fact that the terms of the Lie submodule's lower central series are also Lie submodules of the enclosing Lie module. See also `LieSubmodule.lowerCentralSeries_eq_lcs_comap` and `LieSubmodule.lowerCentralSeries_map_eq_lcs` below, as well as `LieSubmodule.ucs`. -/ def lcs : LieSubmodule R L M → LieSubmodule R L M := (fun N => ⁅(⊤ : LieIdeal R L), N⁆)^[k] @[simp] theorem lcs_zero (N : LieSubmodule R L M) : N.lcs 0 = N := rfl @[simp] theorem lcs_succ : N.lcs (k + 1) = ⁅(⊤ : LieIdeal R L), N.lcs k⁆ := Function.iterate_succ_apply' (fun N' => ⁅⊤, N'⁆) k N @[simp] lemma lcs_sup {N₁ N₂ : LieSubmodule R L M} {k : ℕ} : (N₁ ⊔ N₂).lcs k = N₁.lcs k ⊔ N₂.lcs k := by induction k with | zero => simp | succ k ih => simp only [LieSubmodule.lcs_succ, ih, LieSubmodule.lie_sup] end LieSubmodule namespace LieModule variable (R L M) /-- The lower central series of Lie submodules of a Lie module. -/ def lowerCentralSeries : LieSubmodule R L M := (⊤ : LieSubmodule R L M).lcs k @[simp] theorem lowerCentralSeries_zero : lowerCentralSeries R L M 0 = ⊤ := rfl @[simp] theorem lowerCentralSeries_succ : lowerCentralSeries R L M (k + 1) = ⁅(⊤ : LieIdeal R L), lowerCentralSeries R L M k⁆ := (⊤ : LieSubmodule R L M).lcs_succ k private theorem coe_lowerCentralSeries_eq_int_aux (R₁ R₂ L M : Type*) [CommRing R₁] [CommRing R₂] [AddCommGroup M] [LieRing L] [LieAlgebra R₁ L] [LieAlgebra R₂ L] [Module R₁ M] [Module R₂ M] [LieRingModule L M] [LieModule R₁ L M] (k : ℕ) : let I := lowerCentralSeries R₂ L M k; let S : Set M := {⁅a, b⁆ | (a : L) (b ∈ I)} (Submodule.span R₁ S : Set M) ≤ (Submodule.span R₂ S : Set M) := by intro I S x hx simp only [SetLike.mem_coe] at hx ⊢ induction hx using Submodule.closure_induction with | zero => exact Submodule.zero_mem _ | add y z hy₁ hz₁ hy₂ hz₂ => exact Submodule.add_mem _ hy₂ hz₂ | smul_mem c y hy => obtain ⟨a, b, hb, rfl⟩ := hy rw [← smul_lie] exact Submodule.subset_span ⟨c • a, b, hb, rfl⟩ theorem coe_lowerCentralSeries_eq_int [LieModule R L M] (k : ℕ) : (lowerCentralSeries R L M k : Set M) = (lowerCentralSeries ℤ L M k : Set M) := by rw [← LieSubmodule.coe_toSubmodule, ← LieSubmodule.coe_toSubmodule] induction k with | zero => rfl | succ k ih => rw [lowerCentralSeries_succ, lowerCentralSeries_succ] rw [LieSubmodule.lieIdeal_oper_eq_linear_span', LieSubmodule.lieIdeal_oper_eq_linear_span'] rw [Set.ext_iff] at ih simp only [SetLike.mem_coe, LieSubmodule.mem_toSubmodule] at ih simp only [LieSubmodule.mem_top, ih, true_and] apply le_antisymm · exact coe_lowerCentralSeries_eq_int_aux _ _ L M k · simp only [← ih] exact coe_lowerCentralSeries_eq_int_aux _ _ L M k end LieModule namespace LieSubmodule open LieModule theorem lcs_le_self : N.lcs k ≤ N := by induction k with | zero => simp | succ k ih => simp only [lcs_succ] exact (LieSubmodule.mono_lie_right ⊤ ih).trans (N.lie_le_right ⊤) variable [LieModule R L M] theorem lowerCentralSeries_eq_lcs_comap : lowerCentralSeries R L N k = (N.lcs k).comap N.incl := by induction k with | zero => simp | succ k ih => simp only [lcs_succ, lowerCentralSeries_succ] at ih ⊢ have : N.lcs k ≤ N.incl.range := by rw [N.range_incl] apply lcs_le_self rw [ih, LieSubmodule.comap_bracket_eq _ N.incl _ N.ker_incl this] theorem lowerCentralSeries_map_eq_lcs : (lowerCentralSeries R L N k).map N.incl = N.lcs k := by rw [lowerCentralSeries_eq_lcs_comap, LieSubmodule.map_comap_incl, inf_eq_right] apply lcs_le_self theorem lowerCentralSeries_eq_bot_iff_lcs_eq_bot: lowerCentralSeries R L N k = ⊥ ↔ lcs k N = ⊥ := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rw [← N.lowerCentralSeries_map_eq_lcs, ← LieModuleHom.le_ker_iff_map] simpa · rw [N.lowerCentralSeries_eq_lcs_comap, comap_incl_eq_bot] simp [h] end LieSubmodule namespace LieModule variable {M₂ : Type w₁} [AddCommGroup M₂] [Module R M₂] [LieRingModule L M₂] [LieModule R L M₂] variable (R L M) theorem antitone_lowerCentralSeries : Antitone <| lowerCentralSeries R L M := by intro l k induction k generalizing l with | zero => exact fun h ↦ (Nat.le_zero.mp h).symm ▸ le_rfl | succ k ih => intro h rcases Nat.of_le_succ h with (hk | hk) · rw [lowerCentralSeries_succ] exact (LieSubmodule.mono_lie_right ⊤ (ih hk)).trans (LieSubmodule.lie_le_right _ _) · exact hk.symm ▸ le_rfl theorem eventually_iInf_lowerCentralSeries_eq [IsArtinian R M] : ∀ᶠ l in Filter.atTop, ⨅ k, lowerCentralSeries R L M k = lowerCentralSeries R L M l := by have h_wf : WellFoundedGT (LieSubmodule R L M)ᵒᵈ := LieSubmodule.wellFoundedLT_of_isArtinian R L M obtain ⟨n, hn : ∀ m, n ≤ m → lowerCentralSeries R L M n = lowerCentralSeries R L M m⟩ := h_wf.monotone_chain_condition ⟨_, antitone_lowerCentralSeries R L M⟩ refine Filter.eventually_atTop.mpr ⟨n, fun l hl ↦ le_antisymm (iInf_le _ _) (le_iInf fun m ↦ ?_)⟩ rcases le_or_lt l m with h | h · rw [← hn _ hl, ← hn _ (hl.trans h)] · exact antitone_lowerCentralSeries R L M (le_of_lt h) theorem trivial_iff_lower_central_eq_bot : IsTrivial L M ↔ lowerCentralSeries R L M 1 = ⊥ := by constructor <;> intro h · simp · rw [LieSubmodule.eq_bot_iff] at h; apply IsTrivial.mk; intro x m; apply h apply LieSubmodule.subset_lieSpan simp only [LieSubmodule.top_coe, Subtype.exists, LieSubmodule.mem_top, exists_prop, true_and, Set.mem_setOf] exact ⟨x, m, rfl⟩ section variable [LieModule R L M] theorem iterate_toEnd_mem_lowerCentralSeries (x : L) (m : M) (k : ℕ) : (toEnd R L M x)^[k] m ∈ lowerCentralSeries R L M k := by induction k with | zero => simp only [Function.iterate_zero, lowerCentralSeries_zero, LieSubmodule.mem_top] | succ k ih => simp only [lowerCentralSeries_succ, Function.comp_apply, Function.iterate_succ', toEnd_apply_apply] exact LieSubmodule.lie_mem_lie (LieSubmodule.mem_top x) ih theorem iterate_toEnd_mem_lowerCentralSeries₂ (x y : L) (m : M) (k : ℕ) : (toEnd R L M x ∘ₗ toEnd R L M y)^[k] m ∈ lowerCentralSeries R L M (2 * k) := by induction k with | zero => simp | succ k ih => have hk : 2 * k.succ = (2 * k + 1) + 1 := rfl simp only [lowerCentralSeries_succ, Function.comp_apply, Function.iterate_succ', hk, toEnd_apply_apply, LinearMap.coe_comp, toEnd_apply_apply] refine LieSubmodule.lie_mem_lie (LieSubmodule.mem_top x) ?_ exact LieSubmodule.lie_mem_lie (LieSubmodule.mem_top y) ih variable {R L M} theorem map_lowerCentralSeries_le (f : M →ₗ⁅R,L⁆ M₂) : (lowerCentralSeries R L M k).map f ≤ lowerCentralSeries R L M₂ k := by induction k with | zero => simp only [lowerCentralSeries_zero, le_top] | succ k ih => simp only [LieModule.lowerCentralSeries_succ, LieSubmodule.map_bracket_eq] exact LieSubmodule.mono_lie_right ⊤ ih lemma map_lowerCentralSeries_eq {f : M →ₗ⁅R,L⁆ M₂} (hf : Function.Surjective f) : (lowerCentralSeries R L M k).map f = lowerCentralSeries R L M₂ k := by apply le_antisymm (map_lowerCentralSeries_le k f) induction k with | zero => rwa [lowerCentralSeries_zero, lowerCentralSeries_zero, top_le_iff, f.map_top, f.range_eq_top] | succ => simp only [lowerCentralSeries_succ, LieSubmodule.map_bracket_eq] apply LieSubmodule.mono_lie_right assumption end open LieAlgebra theorem derivedSeries_le_lowerCentralSeries (k : ℕ) : derivedSeries R L k ≤ lowerCentralSeries R L L k := by induction k with | zero => rw [derivedSeries_def, derivedSeriesOfIdeal_zero, lowerCentralSeries_zero] | succ k h => have h' : derivedSeries R L k ≤ ⊤ := by simp only [le_top] rw [derivedSeries_def, derivedSeriesOfIdeal_succ, lowerCentralSeries_succ] exact LieSubmodule.mono_lie h' h /-- A Lie module is nilpotent if its lower central series reaches 0 (in a finite number of steps). -/ @[mk_iff isNilpotent_iff_int] class IsNilpotent : Prop where mk_int :: nilpotent_int : ∃ k, lowerCentralSeries ℤ L M k = ⊥ section variable [LieModule R L M] /-- See also `LieModule.isNilpotent_iff_exists_ucs_eq_top`. -/ lemma isNilpotent_iff : IsNilpotent L M ↔ ∃ k, lowerCentralSeries R L M k = ⊥ := by simp [isNilpotent_iff_int, SetLike.ext'_iff, coe_lowerCentralSeries_eq_int R L M] lemma IsNilpotent.nilpotent [IsNilpotent L M] : ∃ k, lowerCentralSeries R L M k = ⊥ := (isNilpotent_iff R L M).mp ‹_› variable {R L} in lemma IsNilpotent.mk {k : ℕ} (h : lowerCentralSeries R L M k = ⊥) : IsNilpotent L M := (isNilpotent_iff R L M).mpr ⟨k, h⟩ @[deprecated IsNilpotent.nilpotent (since := "2025-01-07")] theorem exists_lowerCentralSeries_eq_bot_of_isNilpotent [IsNilpotent L M] : ∃ k, lowerCentralSeries R L M k = ⊥ := IsNilpotent.nilpotent R L M @[simp] lemma iInf_lowerCentralSeries_eq_bot_of_isNilpotent [IsNilpotent L M] : ⨅ k, lowerCentralSeries R L M k = ⊥ := by obtain ⟨k, hk⟩ := IsNilpotent.nilpotent R L M rw [eq_bot_iff, ← hk] exact iInf_le _ _ end section variable {R L M} variable [LieModule R L M] theorem _root_.LieSubmodule.isNilpotent_iff_exists_lcs_eq_bot (N : LieSubmodule R L M) : LieModule.IsNilpotent L N ↔ ∃ k, N.lcs k = ⊥ := by rw [isNilpotent_iff R L N] refine exists_congr fun k => ?_ rw [N.lowerCentralSeries_eq_lcs_comap k, LieSubmodule.comap_incl_eq_bot, inf_eq_right.mpr (N.lcs_le_self k)] variable (R L M) instance (priority := 100) trivialIsNilpotent [IsTrivial L M] : IsNilpotent L M := ⟨by use 1; simp⟩ instance instIsNilpotentSup (M₁ M₂ : LieSubmodule R L M) [IsNilpotent L M₁] [IsNilpotent L M₂] : IsNilpotent L (M₁ ⊔ M₂ : LieSubmodule R L M) := by obtain ⟨k, hk⟩ := IsNilpotent.nilpotent R L M₁ obtain ⟨l, hl⟩ := IsNilpotent.nilpotent R L M₂ let lcs_eq_bot {m n} (N : LieSubmodule R L M) (le : m ≤ n) (hn : lowerCentralSeries R L N m = ⊥) : lowerCentralSeries R L N n = ⊥ := by simpa [hn] using antitone_lowerCentralSeries R L N le have h₁ : lowerCentralSeries R L M₁ (k ⊔ l) = ⊥ := lcs_eq_bot M₁ (Nat.le_max_left k l) hk have h₂ : lowerCentralSeries R L M₂ (k ⊔ l) = ⊥ := lcs_eq_bot M₂ (Nat.le_max_right k l) hl refine (isNilpotent_iff R L (M₁ + M₂)).mpr ⟨k ⊔ l, ?_⟩ simp [LieSubmodule.add_eq_sup, (M₁ ⊔ M₂).lowerCentralSeries_eq_lcs_comap, LieSubmodule.lcs_sup, (M₁.lowerCentralSeries_eq_bot_iff_lcs_eq_bot (k ⊔ l)).1 h₁, (M₂.lowerCentralSeries_eq_bot_iff_lcs_eq_bot (k ⊔ l)).1 h₂, LieSubmodule.comap_incl_eq_bot] theorem exists_forall_pow_toEnd_eq_zero [IsNilpotent L M] : ∃ k : ℕ, ∀ x : L, toEnd R L M x ^ k = 0 := by obtain ⟨k, hM⟩ := IsNilpotent.nilpotent R L M use k intro x; ext m rw [Module.End.pow_apply, LinearMap.zero_apply, ← @LieSubmodule.mem_bot R L M, ← hM] exact iterate_toEnd_mem_lowerCentralSeries R L M x m k theorem isNilpotent_toEnd_of_isNilpotent [IsNilpotent L M] (x : L) : _root_.IsNilpotent (toEnd R L M x) := by change ∃ k, toEnd R L M x ^ k = 0 have := exists_forall_pow_toEnd_eq_zero R L M tauto theorem isNilpotent_toEnd_of_isNilpotent₂ [IsNilpotent L M] (x y : L) : _root_.IsNilpotent (toEnd R L M x ∘ₗ toEnd R L M y) := by obtain ⟨k, hM⟩ := IsNilpotent.nilpotent R L M replace hM : lowerCentralSeries R L M (2 * k) = ⊥ := by rw [eq_bot_iff, ← hM]; exact antitone_lowerCentralSeries R L M (by omega) use k ext m rw [Module.End.pow_apply, LinearMap.zero_apply, ← LieSubmodule.mem_bot (R := R) (L := L), ← hM] exact iterate_toEnd_mem_lowerCentralSeries₂ R L M x y m k @[simp] lemma maxGenEigenSpace_toEnd_eq_top [IsNilpotent L M] (x : L) : ((toEnd R L M x).maxGenEigenspace 0) = ⊤ := by ext m simp only [Module.End.mem_maxGenEigenspace, zero_smul, sub_zero, Submodule.mem_top, iff_true] obtain ⟨k, hk⟩ := exists_forall_pow_toEnd_eq_zero R L M exact ⟨k, by simp [hk x]⟩ /-- If the quotient of a Lie module `M` by a Lie submodule on which the Lie algebra acts trivially is nilpotent then `M` is nilpotent. This is essentially the Lie module equivalent of the fact that a central extension of nilpotent Lie algebras is nilpotent. See `LieAlgebra.nilpotent_of_nilpotent_quotient` below for the corresponding result for Lie algebras. -/ theorem nilpotentOfNilpotentQuotient {N : LieSubmodule R L M} (h₁ : N ≤ maxTrivSubmodule R L M) (h₂ : IsNilpotent L (M ⧸ N)) : IsNilpotent L M := by rw [isNilpotent_iff R L] at h₂ ⊢ obtain ⟨k, hk⟩ := h₂ use k + 1 simp only [lowerCentralSeries_succ] suffices lowerCentralSeries R L M k ≤ N by replace this := LieSubmodule.mono_lie_right ⊤ (le_trans this h₁) rwa [ideal_oper_maxTrivSubmodule_eq_bot, le_bot_iff] at this rw [← LieSubmodule.Quotient.map_mk'_eq_bot_le, ← le_bot_iff, ← hk] exact map_lowerCentralSeries_le k (LieSubmodule.Quotient.mk' N) theorem isNilpotent_quotient_iff : IsNilpotent L (M ⧸ N) ↔ ∃ k, lowerCentralSeries R L M k ≤ N := by rw [isNilpotent_iff R L] refine exists_congr fun k ↦ ?_ rw [← LieSubmodule.Quotient.map_mk'_eq_bot_le, map_lowerCentralSeries_eq k (LieSubmodule.Quotient.surjective_mk' N)] theorem iInf_lcs_le_of_isNilpotent_quot (h : IsNilpotent L (M ⧸ N)) : ⨅ k, lowerCentralSeries R L M k ≤ N := by obtain ⟨k, hk⟩ := (isNilpotent_quotient_iff R L M N).mp h exact iInf_le_of_le k hk end /-- Given a nilpotent Lie module `M` with lower central series `M = C₀ ≥ C₁ ≥ ⋯ ≥ Cₖ = ⊥`, this is the natural number `k` (the number of inclusions). For a non-nilpotent module, we use the junk value 0. -/ noncomputable def nilpotencyLength : ℕ := sInf {k | lowerCentralSeries ℤ L M k = ⊥} @[simp] theorem nilpotencyLength_eq_zero_iff [IsNilpotent L M] : nilpotencyLength L M = 0 ↔ Subsingleton M := by let s := {k | lowerCentralSeries ℤ L M k = ⊥} have hs : s.Nonempty := by obtain ⟨k, hk⟩ := IsNilpotent.nilpotent ℤ L M exact ⟨k, hk⟩ change sInf s = 0 ↔ _ rw [← LieSubmodule.subsingleton_iff ℤ L M, ← subsingleton_iff_bot_eq_top, ← lowerCentralSeries_zero, @eq_comm (LieSubmodule ℤ L M)] refine ⟨fun h => h ▸ Nat.sInf_mem hs, fun h => ?_⟩ rw [Nat.sInf_eq_zero] exact Or.inl h section variable [LieModule R L M] theorem nilpotencyLength_eq_succ_iff (k : ℕ) : nilpotencyLength L M = k + 1 ↔ lowerCentralSeries R L M (k + 1) = ⊥ ∧ lowerCentralSeries R L M k ≠ ⊥ := by have aux (k : ℕ) : lowerCentralSeries R L M k = ⊥ ↔ lowerCentralSeries ℤ L M k = ⊥ := by simp [SetLike.ext'_iff, coe_lowerCentralSeries_eq_int R L M] let s := {k | lowerCentralSeries ℤ L M k = ⊥} rw [aux, ne_eq, aux] change sInf s = k + 1 ↔ k + 1 ∈ s ∧ k ∉ s have hs : ∀ k₁ k₂, k₁ ≤ k₂ → k₁ ∈ s → k₂ ∈ s := by rintro k₁ k₂ h₁₂ (h₁ : lowerCentralSeries ℤ L M k₁ = ⊥) exact eq_bot_iff.mpr (h₁ ▸ antitone_lowerCentralSeries ℤ L M h₁₂) exact Nat.sInf_upward_closed_eq_succ_iff hs k @[simp] theorem nilpotencyLength_eq_one_iff [Nontrivial M] : nilpotencyLength L M = 1 ↔ IsTrivial L M := by rw [nilpotencyLength_eq_succ_iff ℤ, ← trivial_iff_lower_central_eq_bot] simp theorem isTrivial_of_nilpotencyLength_le_one [IsNilpotent L M] (h : nilpotencyLength L M ≤ 1) : IsTrivial L M := by nontriviality M rcases Nat.le_one_iff_eq_zero_or_eq_one.mp h with h | h · rw [nilpotencyLength_eq_zero_iff] at h; infer_instance · rwa [nilpotencyLength_eq_one_iff] at h end /-- Given a non-trivial nilpotent Lie module `M` with lower central series `M = C₀ ≥ C₁ ≥ ⋯ ≥ Cₖ = ⊥`, this is the `k-1`th term in the lower central series (the last non-trivial term). For a trivial or non-nilpotent module, this is the bottom submodule, `⊥`. -/ noncomputable def lowerCentralSeriesLast : LieSubmodule R L M := match nilpotencyLength L M with | 0 => ⊥ | k + 1 => lowerCentralSeries R L M k theorem lowerCentralSeriesLast_le_max_triv [LieModule R L M] : lowerCentralSeriesLast R L M ≤ maxTrivSubmodule R L M := by rw [lowerCentralSeriesLast] rcases h : nilpotencyLength L M with - | k · exact bot_le · rw [le_max_triv_iff_bracket_eq_bot] rw [nilpotencyLength_eq_succ_iff R, lowerCentralSeries_succ] at h exact h.1 theorem nontrivial_lowerCentralSeriesLast [LieModule R L M] [Nontrivial M] [IsNilpotent L M] : Nontrivial (lowerCentralSeriesLast R L M) := by rw [LieSubmodule.nontrivial_iff_ne_bot, lowerCentralSeriesLast] cases h : nilpotencyLength L M · rw [nilpotencyLength_eq_zero_iff, ← not_nontrivial_iff_subsingleton] at h contradiction · rw [nilpotencyLength_eq_succ_iff R] at h exact h.2 theorem lowerCentralSeriesLast_le_of_not_isTrivial [IsNilpotent L M] (h : ¬ IsTrivial L M) : lowerCentralSeriesLast R L M ≤ lowerCentralSeries R L M 1 := by rw [lowerCentralSeriesLast] replace h : 1 < nilpotencyLength L M := by by_contra contra have := isTrivial_of_nilpotencyLength_le_one L M (not_lt.mp contra) contradiction rcases hk : nilpotencyLength L M with - | k <;> rw [hk] at h · contradiction · exact antitone_lowerCentralSeries _ _ _ (Nat.lt_succ.mp h) variable [LieModule R L M] /-- For a nilpotent Lie module `M` of a Lie algebra `L`, the first term in the lower central series of `M` contains a non-zero element on which `L` acts trivially unless the entire action is trivial. Taking `M = L`, this provides a useful characterisation of Abelian-ness for nilpotent Lie algebras. -/ lemma disjoint_lowerCentralSeries_maxTrivSubmodule_iff [IsNilpotent L M] : Disjoint (lowerCentralSeries R L M 1) (maxTrivSubmodule R L M) ↔ IsTrivial L M := by refine ⟨fun h ↦ ?_, fun h ↦ by simp⟩ nontriviality M by_contra contra have : lowerCentralSeriesLast R L M ≤ lowerCentralSeries R L M 1 ⊓ maxTrivSubmodule R L M := le_inf_iff.mpr ⟨lowerCentralSeriesLast_le_of_not_isTrivial R L M contra, lowerCentralSeriesLast_le_max_triv R L M⟩ suffices ¬ Nontrivial (lowerCentralSeriesLast R L M) by exact this (nontrivial_lowerCentralSeriesLast R L M) rw [h.eq_bot, le_bot_iff] at this exact this ▸ not_nontrivial _ theorem nontrivial_max_triv_of_isNilpotent [Nontrivial M] [IsNilpotent L M] : Nontrivial (maxTrivSubmodule R L M) := Set.nontrivial_mono (lowerCentralSeriesLast_le_max_triv R L M) (nontrivial_lowerCentralSeriesLast R L M) @[simp] theorem coe_lcs_range_toEnd_eq (k : ℕ) : (lowerCentralSeries R (toEnd R L M).range M k : Submodule R M) = lowerCentralSeries R L M k := by induction k with | zero => simp | succ k ih => simp only [lowerCentralSeries_succ, LieSubmodule.lieIdeal_oper_eq_linear_span', ← (lowerCentralSeries R (toEnd R L M).range M k).mem_toSubmodule, ih] congr ext m
constructor · rintro ⟨⟨-, ⟨y, rfl⟩⟩, -, n, hn, rfl⟩ exact ⟨y, LieSubmodule.mem_top _, n, hn, rfl⟩ · rintro ⟨x, -, n, hn, rfl⟩
Mathlib/Algebra/Lie/Nilpotent.lean
515
518
/- Copyright (c) 2014 Parikshit Khanna. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro -/ import Mathlib.Control.Basic import Mathlib.Data.Nat.Basic import Mathlib.Data.Option.Basic import Mathlib.Data.List.Defs import Mathlib.Data.List.Monad import Mathlib.Logic.OpClass import Mathlib.Logic.Unique import Mathlib.Order.Basic import Mathlib.Tactic.Common /-! # Basic properties of lists -/ assert_not_exists GroupWithZero assert_not_exists Lattice assert_not_exists Prod.swap_eq_iff_eq_swap assert_not_exists Ring assert_not_exists Set.range open Function open Nat hiding one_pos namespace List universe u v w variable {ι : Type*} {α : Type u} {β : Type v} {γ : Type w} {l₁ l₂ : List α} /-- There is only one list of an empty type -/ instance uniqueOfIsEmpty [IsEmpty α] : Unique (List α) := { instInhabitedList with uniq := fun l => match l with | [] => rfl | a :: _ => isEmptyElim a } instance : Std.LawfulIdentity (α := List α) Append.append [] where left_id := nil_append right_id := append_nil instance : Std.Associative (α := List α) Append.append where assoc := append_assoc @[simp] theorem cons_injective {a : α} : Injective (cons a) := fun _ _ => tail_eq_of_cons_eq theorem singleton_injective : Injective fun a : α => [a] := fun _ _ h => (cons_eq_cons.1 h).1 theorem set_of_mem_cons (l : List α) (a : α) : { x | x ∈ a :: l } = insert a { x | x ∈ l } := Set.ext fun _ => mem_cons /-! ### mem -/ theorem _root_.Decidable.List.eq_or_ne_mem_of_mem [DecidableEq α] {a b : α} {l : List α} (h : a ∈ b :: l) : a = b ∨ a ≠ b ∧ a ∈ l := by by_cases hab : a = b · exact Or.inl hab · exact ((List.mem_cons.1 h).elim Or.inl (fun h => Or.inr ⟨hab, h⟩)) lemma mem_pair {a b c : α} : a ∈ [b, c] ↔ a = b ∨ a = c := by rw [mem_cons, mem_singleton] -- The simpNF linter says that the LHS can be simplified via `List.mem_map`. -- However this is a higher priority lemma. -- It seems the side condition `hf` is not applied by `simpNF`. -- https://github.com/leanprover/std4/issues/207 @[simp 1100, nolint simpNF] theorem mem_map_of_injective {f : α → β} (H : Injective f) {a : α} {l : List α} : f a ∈ map f l ↔ a ∈ l := ⟨fun m => let ⟨_, m', e⟩ := exists_of_mem_map m; H e ▸ m', mem_map_of_mem⟩ @[simp] theorem _root_.Function.Involutive.exists_mem_and_apply_eq_iff {f : α → α} (hf : Function.Involutive f) (x : α) (l : List α) : (∃ y : α, y ∈ l ∧ f y = x) ↔ f x ∈ l := ⟨by rintro ⟨y, h, rfl⟩; rwa [hf y], fun h => ⟨f x, h, hf _⟩⟩ theorem mem_map_of_involutive {f : α → α} (hf : Involutive f) {a : α} {l : List α} : a ∈ map f l ↔ f a ∈ l := by rw [mem_map, hf.exists_mem_and_apply_eq_iff] /-! ### length -/ alias ⟨_, length_pos_of_ne_nil⟩ := length_pos_iff theorem length_pos_iff_ne_nil {l : List α} : 0 < length l ↔ l ≠ [] := ⟨ne_nil_of_length_pos, length_pos_of_ne_nil⟩ theorem exists_of_length_succ {n} : ∀ l : List α, l.length = n + 1 → ∃ h t, l = h :: t | [], H => absurd H.symm <| succ_ne_zero n | h :: t, _ => ⟨h, t, rfl⟩ @[simp] lemma length_injective_iff : Injective (List.length : List α → ℕ) ↔ Subsingleton α := by constructor · intro h; refine ⟨fun x y => ?_⟩; (suffices [x] = [y] by simpa using this); apply h; rfl · intros hα l1 l2 hl induction l1 generalizing l2 <;> cases l2 · rfl · cases hl · cases hl · next ih _ _ => congr · subsingleton · apply ih; simpa using hl @[simp default+1] -- Raise priority above `length_injective_iff`. lemma length_injective [Subsingleton α] : Injective (length : List α → ℕ) := length_injective_iff.mpr inferInstance theorem length_eq_two {l : List α} : l.length = 2 ↔ ∃ a b, l = [a, b] := ⟨fun _ => let [a, b] := l; ⟨a, b, rfl⟩, fun ⟨_, _, e⟩ => e ▸ rfl⟩ theorem length_eq_three {l : List α} : l.length = 3 ↔ ∃ a b c, l = [a, b, c] := ⟨fun _ => let [a, b, c] := l; ⟨a, b, c, rfl⟩, fun ⟨_, _, _, e⟩ => e ▸ rfl⟩ /-! ### set-theoretic notation of lists -/ instance instSingletonList : Singleton α (List α) := ⟨fun x => [x]⟩ instance [DecidableEq α] : Insert α (List α) := ⟨List.insert⟩ instance [DecidableEq α] : LawfulSingleton α (List α) := { insert_empty_eq := fun x => show (if x ∈ ([] : List α) then [] else [x]) = [x] from if_neg not_mem_nil } theorem singleton_eq (x : α) : ({x} : List α) = [x] := rfl theorem insert_neg [DecidableEq α] {x : α} {l : List α} (h : x ∉ l) : Insert.insert x l = x :: l := insert_of_not_mem h theorem insert_pos [DecidableEq α] {x : α} {l : List α} (h : x ∈ l) : Insert.insert x l = l := insert_of_mem h theorem doubleton_eq [DecidableEq α] {x y : α} (h : x ≠ y) : ({x, y} : List α) = [x, y] := by rw [insert_neg, singleton_eq] rwa [singleton_eq, mem_singleton] /-! ### bounded quantifiers over lists -/ theorem forall_mem_of_forall_mem_cons {p : α → Prop} {a : α} {l : List α} (h : ∀ x ∈ a :: l, p x) : ∀ x ∈ l, p x := (forall_mem_cons.1 h).2 theorem exists_mem_cons_of {p : α → Prop} {a : α} (l : List α) (h : p a) : ∃ x ∈ a :: l, p x := ⟨a, mem_cons_self, h⟩ theorem exists_mem_cons_of_exists {p : α → Prop} {a : α} {l : List α} : (∃ x ∈ l, p x) → ∃ x ∈ a :: l, p x := fun ⟨x, xl, px⟩ => ⟨x, mem_cons_of_mem _ xl, px⟩ theorem or_exists_of_exists_mem_cons {p : α → Prop} {a : α} {l : List α} : (∃ x ∈ a :: l, p x) → p a ∨ ∃ x ∈ l, p x := fun ⟨x, xal, px⟩ => Or.elim (eq_or_mem_of_mem_cons xal) (fun h : x = a => by rw [← h]; left; exact px) fun h : x ∈ l => Or.inr ⟨x, h, px⟩ theorem exists_mem_cons_iff (p : α → Prop) (a : α) (l : List α) : (∃ x ∈ a :: l, p x) ↔ p a ∨ ∃ x ∈ l, p x := Iff.intro or_exists_of_exists_mem_cons fun h => Or.elim h (exists_mem_cons_of l) exists_mem_cons_of_exists /-! ### list subset -/ theorem cons_subset_of_subset_of_mem {a : α} {l m : List α} (ainm : a ∈ m) (lsubm : l ⊆ m) : a::l ⊆ m := cons_subset.2 ⟨ainm, lsubm⟩ theorem append_subset_of_subset_of_subset {l₁ l₂ l : List α} (l₁subl : l₁ ⊆ l) (l₂subl : l₂ ⊆ l) : l₁ ++ l₂ ⊆ l := fun _ h ↦ (mem_append.1 h).elim (@l₁subl _) (@l₂subl _) theorem map_subset_iff {l₁ l₂ : List α} (f : α → β) (h : Injective f) : map f l₁ ⊆ map f l₂ ↔ l₁ ⊆ l₂ := by refine ⟨?_, map_subset f⟩; intro h2 x hx rcases mem_map.1 (h2 (mem_map_of_mem hx)) with ⟨x', hx', hxx'⟩ cases h hxx'; exact hx' /-! ### append -/ theorem append_eq_has_append {L₁ L₂ : List α} : List.append L₁ L₂ = L₁ ++ L₂ := rfl theorem append_right_injective (s : List α) : Injective fun t ↦ s ++ t := fun _ _ ↦ append_cancel_left theorem append_left_injective (t : List α) : Injective fun s ↦ s ++ t := fun _ _ ↦ append_cancel_right /-! ### replicate -/ theorem eq_replicate_length {a : α} : ∀ {l : List α}, l = replicate l.length a ↔ ∀ b ∈ l, b = a | [] => by simp | (b :: l) => by simp [eq_replicate_length, replicate_succ] theorem replicate_add (m n) (a : α) : replicate (m + n) a = replicate m a ++ replicate n a := by rw [replicate_append_replicate] theorem replicate_subset_singleton (n) (a : α) : replicate n a ⊆ [a] := fun _ h => mem_singleton.2 (eq_of_mem_replicate h) theorem subset_singleton_iff {a : α} {L : List α} : L ⊆ [a] ↔ ∃ n, L = replicate n a := by simp only [eq_replicate_iff, subset_def, mem_singleton, exists_eq_left'] theorem replicate_right_injective {n : ℕ} (hn : n ≠ 0) : Injective (@replicate α n) := fun _ _ h => (eq_replicate_iff.1 h).2 _ <| mem_replicate.2 ⟨hn, rfl⟩ theorem replicate_right_inj {a b : α} {n : ℕ} (hn : n ≠ 0) : replicate n a = replicate n b ↔ a = b := (replicate_right_injective hn).eq_iff theorem replicate_right_inj' {a b : α} : ∀ {n}, replicate n a = replicate n b ↔ n = 0 ∨ a = b | 0 => by simp | n + 1 => (replicate_right_inj n.succ_ne_zero).trans <| by simp only [n.succ_ne_zero, false_or] theorem replicate_left_injective (a : α) : Injective (replicate · a) := LeftInverse.injective (length_replicate (n := ·)) theorem replicate_left_inj {a : α} {n m : ℕ} : replicate n a = replicate m a ↔ n = m := (replicate_left_injective a).eq_iff @[simp] theorem head?_flatten_replicate {n : ℕ} (h : n ≠ 0) (l : List α) : (List.replicate n l).flatten.head? = l.head? := by obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero h induction l <;> simp [replicate] @[simp] theorem getLast?_flatten_replicate {n : ℕ} (h : n ≠ 0) (l : List α) : (List.replicate n l).flatten.getLast? = l.getLast? := by rw [← List.head?_reverse, ← List.head?_reverse, List.reverse_flatten, List.map_replicate, List.reverse_replicate, head?_flatten_replicate h] /-! ### pure -/ theorem mem_pure (x y : α) : x ∈ (pure y : List α) ↔ x = y := by simp /-! ### bind -/ @[simp] theorem bind_eq_flatMap {α β} (f : α → List β) (l : List α) : l >>= f = l.flatMap f := rfl /-! ### concat -/ /-! ### reverse -/ theorem reverse_cons' (a : α) (l : List α) : reverse (a :: l) = concat (reverse l) a := by simp only [reverse_cons, concat_eq_append] theorem reverse_concat' (l : List α) (a : α) : (l ++ [a]).reverse = a :: l.reverse := by rw [reverse_append]; rfl @[simp] theorem reverse_singleton (a : α) : reverse [a] = [a] := rfl @[simp] theorem reverse_involutive : Involutive (@reverse α) := reverse_reverse @[simp] theorem reverse_injective : Injective (@reverse α) := reverse_involutive.injective theorem reverse_surjective : Surjective (@reverse α) := reverse_involutive.surjective theorem reverse_bijective : Bijective (@reverse α) := reverse_involutive.bijective theorem concat_eq_reverse_cons (a : α) (l : List α) : concat l a = reverse (a :: reverse l) := by simp only [concat_eq_append, reverse_cons, reverse_reverse] theorem map_reverseAux (f : α → β) (l₁ l₂ : List α) : map f (reverseAux l₁ l₂) = reverseAux (map f l₁) (map f l₂) := by simp only [reverseAux_eq, map_append, map_reverse] -- TODO: Rename `List.reverse_perm` to `List.reverse_perm_self` @[simp] lemma reverse_perm' : l₁.reverse ~ l₂ ↔ l₁ ~ l₂ where mp := l₁.reverse_perm.symm.trans mpr := l₁.reverse_perm.trans @[simp] lemma perm_reverse : l₁ ~ l₂.reverse ↔ l₁ ~ l₂ where mp hl := hl.trans l₂.reverse_perm mpr hl := hl.trans l₂.reverse_perm.symm /-! ### getLast -/ attribute [simp] getLast_cons theorem getLast_append_singleton {a : α} (l : List α) : getLast (l ++ [a]) (append_ne_nil_of_right_ne_nil l (cons_ne_nil a _)) = a := by simp [getLast_append] theorem getLast_append_of_right_ne_nil (l₁ l₂ : List α) (h : l₂ ≠ []) : getLast (l₁ ++ l₂) (append_ne_nil_of_right_ne_nil l₁ h) = getLast l₂ h := by induction l₁ with | nil => simp | cons _ _ ih => simp only [cons_append]; rw [List.getLast_cons]; exact ih @[deprecated (since := "2025-02-06")] alias getLast_append' := getLast_append_of_right_ne_nil theorem getLast_concat' {a : α} (l : List α) : getLast (concat l a) (by simp) = a := by simp @[simp] theorem getLast_singleton' (a : α) : getLast [a] (cons_ne_nil a []) = a := rfl @[simp] theorem getLast_cons_cons (a₁ a₂ : α) (l : List α) : getLast (a₁ :: a₂ :: l) (cons_ne_nil _ _) = getLast (a₂ :: l) (cons_ne_nil a₂ l) := rfl theorem dropLast_append_getLast : ∀ {l : List α} (h : l ≠ []), dropLast l ++ [getLast l h] = l | [], h => absurd rfl h | [_], _ => rfl | a :: b :: l, h => by rw [dropLast_cons₂, cons_append, getLast_cons (cons_ne_nil _ _)] congr exact dropLast_append_getLast (cons_ne_nil b l) theorem getLast_congr {l₁ l₂ : List α} (h₁ : l₁ ≠ []) (h₂ : l₂ ≠ []) (h₃ : l₁ = l₂) : getLast l₁ h₁ = getLast l₂ h₂ := by subst l₁; rfl theorem getLast_replicate_succ (m : ℕ) (a : α) : (replicate (m + 1) a).getLast (ne_nil_of_length_eq_add_one length_replicate) = a := by simp only [replicate_succ'] exact getLast_append_singleton _ @[deprecated (since := "2025-02-07")] alias getLast_filter' := getLast_filter_of_pos /-! ### getLast? -/ theorem mem_getLast?_eq_getLast : ∀ {l : List α} {x : α}, x ∈ l.getLast? → ∃ h, x = getLast l h | [], x, hx => False.elim <| by simp at hx | [a], x, hx => have : a = x := by simpa using hx this ▸ ⟨cons_ne_nil a [], rfl⟩ | a :: b :: l, x, hx => by rw [getLast?_cons_cons] at hx rcases mem_getLast?_eq_getLast hx with ⟨_, h₂⟩ use cons_ne_nil _ _ assumption theorem getLast?_eq_getLast_of_ne_nil : ∀ {l : List α} (h : l ≠ []), l.getLast? = some (l.getLast h) | [], h => (h rfl).elim | [_], _ => rfl | _ :: b :: l, _ => @getLast?_eq_getLast_of_ne_nil (b :: l) (cons_ne_nil _ _) theorem mem_getLast?_cons {x y : α} : ∀ {l : List α}, x ∈ l.getLast? → x ∈ (y :: l).getLast? | [], _ => by contradiction | _ :: _, h => h theorem dropLast_append_getLast? : ∀ {l : List α}, ∀ a ∈ l.getLast?, dropLast l ++ [a] = l | [], a, ha => (Option.not_mem_none a ha).elim | [a], _, rfl => rfl | a :: b :: l, c, hc => by rw [getLast?_cons_cons] at hc rw [dropLast_cons₂, cons_append, dropLast_append_getLast? _ hc] theorem getLastI_eq_getLast? [Inhabited α] : ∀ l : List α, l.getLastI = l.getLast?.iget | [] => by simp [getLastI, Inhabited.default] | [_] => rfl | [_, _] => rfl | [_, _, _] => rfl | _ :: _ :: c :: l => by simp [getLastI, getLastI_eq_getLast? (c :: l)] theorem getLast?_append_cons : ∀ (l₁ : List α) (a : α) (l₂ : List α), getLast? (l₁ ++ a :: l₂) = getLast? (a :: l₂) | [], _, _ => rfl | [_], _, _ => rfl | b :: c :: l₁, a, l₂ => by rw [cons_append, cons_append, getLast?_cons_cons, ← cons_append, getLast?_append_cons (c :: l₁)] theorem getLast?_append_of_ne_nil (l₁ : List α) : ∀ {l₂ : List α} (_ : l₂ ≠ []), getLast? (l₁ ++ l₂) = getLast? l₂ | [], hl₂ => by contradiction | b :: l₂, _ => getLast?_append_cons l₁ b l₂ theorem mem_getLast?_append_of_mem_getLast? {l₁ l₂ : List α} {x : α} (h : x ∈ l₂.getLast?) : x ∈ (l₁ ++ l₂).getLast? := by cases l₂ · contradiction · rw [List.getLast?_append_cons] exact h /-! ### head(!?) and tail -/ @[simp] theorem head!_nil [Inhabited α] : ([] : List α).head! = default := rfl @[simp] theorem head_cons_tail (x : List α) (h : x ≠ []) : x.head h :: x.tail = x := by cases x <;> simp at h ⊢ theorem head_eq_getElem_zero {l : List α} (hl : l ≠ []) : l.head hl = l[0]'(length_pos_iff.2 hl) := (getElem_zero _).symm theorem head!_eq_head? [Inhabited α] (l : List α) : head! l = (head? l).iget := by cases l <;> rfl theorem surjective_head! [Inhabited α] : Surjective (@head! α _) := fun x => ⟨[x], rfl⟩ theorem surjective_head? : Surjective (@head? α) := Option.forall.2 ⟨⟨[], rfl⟩, fun x => ⟨[x], rfl⟩⟩ theorem surjective_tail : Surjective (@tail α) | [] => ⟨[], rfl⟩ | a :: l => ⟨a :: a :: l, rfl⟩ theorem eq_cons_of_mem_head? {x : α} : ∀ {l : List α}, x ∈ l.head? → l = x :: tail l | [], h => (Option.not_mem_none _ h).elim | a :: l, h => by simp only [head?, Option.mem_def, Option.some_inj] at h exact h ▸ rfl @[simp] theorem head!_cons [Inhabited α] (a : α) (l : List α) : head! (a :: l) = a := rfl @[simp] theorem head!_append [Inhabited α] (t : List α) {s : List α} (h : s ≠ []) : head! (s ++ t) = head! s := by induction s · contradiction · rfl theorem mem_head?_append_of_mem_head? {s t : List α} {x : α} (h : x ∈ s.head?) : x ∈ (s ++ t).head? := by cases s · contradiction · exact h theorem head?_append_of_ne_nil : ∀ (l₁ : List α) {l₂ : List α} (_ : l₁ ≠ []), head? (l₁ ++ l₂) = head? l₁ | _ :: _, _, _ => rfl theorem tail_append_singleton_of_ne_nil {a : α} {l : List α} (h : l ≠ nil) : tail (l ++ [a]) = tail l ++ [a] := by induction l · contradiction · rw [tail, cons_append, tail] theorem cons_head?_tail : ∀ {l : List α} {a : α}, a ∈ head? l → a :: tail l = l | [], a, h => by contradiction | b :: l, a, h => by simp? at h says simp only [head?_cons, Option.mem_def, Option.some.injEq] at h simp [h] theorem head!_mem_head? [Inhabited α] : ∀ {l : List α}, l ≠ [] → head! l ∈ head? l | [], h => by contradiction | _ :: _, _ => rfl theorem cons_head!_tail [Inhabited α] {l : List α} (h : l ≠ []) : head! l :: tail l = l := cons_head?_tail (head!_mem_head? h) theorem head!_mem_self [Inhabited α] {l : List α} (h : l ≠ nil) : l.head! ∈ l := by have h' : l.head! ∈ l.head! :: l.tail := mem_cons_self rwa [cons_head!_tail h] at h' theorem get_eq_getElem? (l : List α) (i : Fin l.length) : l.get i = l[i]?.get (by simp [getElem?_eq_getElem]) := by simp @[deprecated (since := "2025-02-15")] alias get_eq_get? := get_eq_getElem? theorem exists_mem_iff_getElem {l : List α} {p : α → Prop} : (∃ x ∈ l, p x) ↔ ∃ (i : ℕ) (_ : i < l.length), p l[i] := by simp only [mem_iff_getElem] exact ⟨fun ⟨_x, ⟨i, hi, hix⟩, hxp⟩ ↦ ⟨i, hi, hix ▸ hxp⟩, fun ⟨i, hi, hp⟩ ↦ ⟨_, ⟨i, hi, rfl⟩, hp⟩⟩ theorem forall_mem_iff_getElem {l : List α} {p : α → Prop} : (∀ x ∈ l, p x) ↔ ∀ (i : ℕ) (_ : i < l.length), p l[i] := by simp [mem_iff_getElem, @forall_swap α] theorem get_tail (l : List α) (i) (h : i < l.tail.length) (h' : i + 1 < l.length := (by simp only [length_tail] at h; omega)) : l.tail.get ⟨i, h⟩ = l.get ⟨i + 1, h'⟩ := by cases l <;> [cases h; rfl] /-! ### sublists -/ attribute [refl] List.Sublist.refl theorem Sublist.cons_cons {l₁ l₂ : List α} (a : α) (s : l₁ <+ l₂) : a :: l₁ <+ a :: l₂ := Sublist.cons₂ _ s lemma cons_sublist_cons' {a b : α} : a :: l₁ <+ b :: l₂ ↔ a :: l₁ <+ l₂ ∨ a = b ∧ l₁ <+ l₂ := by constructor · rintro (_ | _) · exact Or.inl ‹_› · exact Or.inr ⟨rfl, ‹_›⟩ · rintro (h | ⟨rfl, h⟩) · exact h.cons _ · rwa [cons_sublist_cons] theorem sublist_cons_of_sublist (a : α) (h : l₁ <+ l₂) : l₁ <+ a :: l₂ := h.cons _ @[deprecated (since := "2025-02-07")] alias sublist_nil_iff_eq_nil := sublist_nil @[simp] lemma sublist_singleton {l : List α} {a : α} : l <+ [a] ↔ l = [] ∨ l = [a] := by constructor <;> rintro (_ | _) <;> aesop theorem Sublist.antisymm (s₁ : l₁ <+ l₂) (s₂ : l₂ <+ l₁) : l₁ = l₂ := s₁.eq_of_length_le s₂.length_le /-- If the first element of two lists are different, then a sublist relation can be reduced. -/ theorem Sublist.of_cons_of_ne {a b} (h₁ : a ≠ b) (h₂ : a :: l₁ <+ b :: l₂) : a :: l₁ <+ l₂ := match h₁, h₂ with | _, .cons _ h => h /-! ### indexOf -/ section IndexOf variable [DecidableEq α] theorem idxOf_cons_eq {a b : α} (l : List α) : b = a → idxOf a (b :: l) = 0 | e => by rw [← e]; exact idxOf_cons_self @[deprecated (since := "2025-01-30")] alias indexOf_cons_eq := idxOf_cons_eq @[simp] theorem idxOf_cons_ne {a b : α} (l : List α) : b ≠ a → idxOf a (b :: l) = succ (idxOf a l) | h => by simp only [idxOf_cons, Bool.cond_eq_ite, beq_iff_eq, if_neg h] @[deprecated (since := "2025-01-30")] alias indexOf_cons_ne := idxOf_cons_ne theorem idxOf_eq_length_iff {a : α} {l : List α} : idxOf a l = length l ↔ a ∉ l := by induction l with | nil => exact iff_of_true rfl not_mem_nil | cons b l ih => simp only [length, mem_cons, idxOf_cons, eq_comm] rw [cond_eq_if] split_ifs with h <;> simp at h · exact iff_of_false (by rintro ⟨⟩) fun H => H <| Or.inl h.symm · simp only [Ne.symm h, false_or] rw [← ih] exact succ_inj @[simp] theorem idxOf_of_not_mem {l : List α} {a : α} : a ∉ l → idxOf a l = length l := idxOf_eq_length_iff.2 @[deprecated (since := "2025-01-30")] alias indexOf_of_not_mem := idxOf_of_not_mem theorem idxOf_le_length {a : α} {l : List α} : idxOf a l ≤ length l := by induction l with | nil => rfl | cons b l ih => ?_ simp only [length, idxOf_cons, cond_eq_if, beq_iff_eq] by_cases h : b = a · rw [if_pos h]; exact Nat.zero_le _ · rw [if_neg h]; exact succ_le_succ ih @[deprecated (since := "2025-01-30")] alias indexOf_le_length := idxOf_le_length theorem idxOf_lt_length_iff {a} {l : List α} : idxOf a l < length l ↔ a ∈ l := ⟨fun h => Decidable.byContradiction fun al => Nat.ne_of_lt h <| idxOf_eq_length_iff.2 al, fun al => (lt_of_le_of_ne idxOf_le_length) fun h => idxOf_eq_length_iff.1 h al⟩ @[deprecated (since := "2025-01-30")] alias indexOf_lt_length_iff := idxOf_lt_length_iff theorem idxOf_append_of_mem {a : α} (h : a ∈ l₁) : idxOf a (l₁ ++ l₂) = idxOf a l₁ := by induction l₁ with | nil => exfalso exact not_mem_nil h | cons d₁ t₁ ih => rw [List.cons_append] by_cases hh : d₁ = a · iterate 2 rw [idxOf_cons_eq _ hh] rw [idxOf_cons_ne _ hh, idxOf_cons_ne _ hh, ih (mem_of_ne_of_mem (Ne.symm hh) h)] @[deprecated (since := "2025-01-30")] alias indexOf_append_of_mem := idxOf_append_of_mem theorem idxOf_append_of_not_mem {a : α} (h : a ∉ l₁) : idxOf a (l₁ ++ l₂) = l₁.length + idxOf a l₂ := by induction l₁ with | nil => rw [List.nil_append, List.length, Nat.zero_add] | cons d₁ t₁ ih => rw [List.cons_append, idxOf_cons_ne _ (ne_of_not_mem_cons h).symm, List.length, ih (not_mem_of_not_mem_cons h), Nat.succ_add] @[deprecated (since := "2025-01-30")] alias indexOf_append_of_not_mem := idxOf_append_of_not_mem end IndexOf /-! ### nth element -/ section deprecated @[simp] theorem getElem?_length (l : List α) : l[l.length]? = none := getElem?_eq_none le_rfl /-- A version of `getElem_map` that can be used for rewriting. -/ theorem getElem_map_rev (f : α → β) {l} {n : Nat} {h : n < l.length} : f l[n] = (map f l)[n]'((l.length_map f).symm ▸ h) := Eq.symm (getElem_map _) theorem get_length_sub_one {l : List α} (h : l.length - 1 < l.length) : l.get ⟨l.length - 1, h⟩ = l.getLast (by rintro rfl; exact Nat.lt_irrefl 0 h) := (getLast_eq_getElem _).symm theorem take_one_drop_eq_of_lt_length {l : List α} {n : ℕ} (h : n < l.length) : (l.drop n).take 1 = [l.get ⟨n, h⟩] := by rw [drop_eq_getElem_cons h, take, take] simp theorem ext_getElem?' {l₁ l₂ : List α} (h' : ∀ n < max l₁.length l₂.length, l₁[n]? = l₂[n]?) : l₁ = l₂ := by apply ext_getElem? intro n rcases Nat.lt_or_ge n <| max l₁.length l₂.length with hn | hn · exact h' n hn · simp_all [Nat.max_le, getElem?_eq_none] @[deprecated (since := "2025-02-15")] alias ext_get?' := ext_getElem?' @[deprecated (since := "2025-02-15")] alias ext_get?_iff := List.ext_getElem?_iff theorem ext_get_iff {l₁ l₂ : List α} : l₁ = l₂ ↔ l₁.length = l₂.length ∧ ∀ n h₁ h₂, get l₁ ⟨n, h₁⟩ = get l₂ ⟨n, h₂⟩ := by constructor · rintro rfl exact ⟨rfl, fun _ _ _ ↦ rfl⟩ · intro ⟨h₁, h₂⟩ exact ext_get h₁ h₂ theorem ext_getElem?_iff' {l₁ l₂ : List α} : l₁ = l₂ ↔ ∀ n < max l₁.length l₂.length, l₁[n]? = l₂[n]? := ⟨by rintro rfl _ _; rfl, ext_getElem?'⟩ @[deprecated (since := "2025-02-15")] alias ext_get?_iff' := ext_getElem?_iff' /-- If two lists `l₁` and `l₂` are the same length and `l₁[n]! = l₂[n]!` for all `n`, then the lists are equal. -/ theorem ext_getElem! [Inhabited α] (hl : length l₁ = length l₂) (h : ∀ n : ℕ, l₁[n]! = l₂[n]!) : l₁ = l₂ := ext_getElem hl fun n h₁ h₂ ↦ by simpa only [← getElem!_pos] using h n @[simp] theorem getElem_idxOf [DecidableEq α] {a : α} : ∀ {l : List α} (h : idxOf a l < l.length), l[idxOf a l] = a | b :: l, h => by by_cases h' : b = a <;> simp [h', if_pos, if_false, getElem_idxOf] @[deprecated (since := "2025-01-30")] alias getElem_indexOf := getElem_idxOf -- This is incorrectly named and should be `get_idxOf`; -- this already exists, so will require a deprecation dance. theorem idxOf_get [DecidableEq α] {a : α} {l : List α} (h) : get l ⟨idxOf a l, h⟩ = a := by simp @[deprecated (since := "2025-01-30")] alias indexOf_get := idxOf_get @[simp] theorem getElem?_idxOf [DecidableEq α] {a : α} {l : List α} (h : a ∈ l) : l[idxOf a l]? = some a := by rw [getElem?_eq_getElem, getElem_idxOf (idxOf_lt_length_iff.2 h)] @[deprecated (since := "2025-01-30")] alias getElem?_indexOf := getElem?_idxOf @[deprecated (since := "2025-02-15")] alias idxOf_get? := getElem?_idxOf @[deprecated (since := "2025-01-30")] alias indexOf_get? := getElem?_idxOf theorem idxOf_inj [DecidableEq α] {l : List α} {x y : α} (hx : x ∈ l) (hy : y ∈ l) : idxOf x l = idxOf y l ↔ x = y := ⟨fun h => by have x_eq_y : get l ⟨idxOf x l, idxOf_lt_length_iff.2 hx⟩ = get l ⟨idxOf y l, idxOf_lt_length_iff.2 hy⟩ := by simp only [h] simp only [idxOf_get] at x_eq_y; exact x_eq_y, fun h => by subst h; rfl⟩ @[deprecated (since := "2025-01-30")] alias indexOf_inj := idxOf_inj theorem get_reverse' (l : List α) (n) (hn') : l.reverse.get n = l.get ⟨l.length - 1 - n, hn'⟩ := by simp theorem eq_cons_of_length_one {l : List α} (h : l.length = 1) : l = [l.get ⟨0, by omega⟩] := by refine ext_get (by convert h) fun n h₁ h₂ => ?_ simp congr omega end deprecated @[simp] theorem getElem_set_of_ne {l : List α} {i j : ℕ} (h : i ≠ j) (a : α) (hj : j < (l.set i a).length) : (l.set i a)[j] = l[j]'(by simpa using hj) := by rw [← Option.some_inj, ← List.getElem?_eq_getElem, List.getElem?_set_ne h, List.getElem?_eq_getElem] /-! ### map -/ -- `List.map_const` (the version with `Function.const` instead of a lambda) is already tagged -- `simp` in Core -- TODO: Upstream the tagging to Core? attribute [simp] map_const' theorem flatMap_pure_eq_map (f : α → β) (l : List α) : l.flatMap (pure ∘ f) = map f l := .symm <| map_eq_flatMap .. theorem flatMap_congr {l : List α} {f g : α → List β} (h : ∀ x ∈ l, f x = g x) : l.flatMap f = l.flatMap g := (congr_arg List.flatten <| map_congr_left h :) theorem infix_flatMap_of_mem {a : α} {as : List α} (h : a ∈ as) (f : α → List α) : f a <:+: as.flatMap f := infix_of_mem_flatten (mem_map_of_mem h) @[simp] theorem map_eq_map {α β} (f : α → β) (l : List α) : f <$> l = map f l := rfl /-- A single `List.map` of a composition of functions is equal to composing a `List.map` with another `List.map`, fully applied. This is the reverse direction of `List.map_map`. -/ theorem comp_map (h : β → γ) (g : α → β) (l : List α) : map (h ∘ g) l = map h (map g l) := map_map.symm /-- Composing a `List.map` with another `List.map` is equal to a single `List.map` of composed functions. -/ @[simp] theorem map_comp_map (g : β → γ) (f : α → β) : map g ∘ map f = map (g ∘ f) := by ext l; rw [comp_map, Function.comp_apply] section map_bijectivity theorem _root_.Function.LeftInverse.list_map {f : α → β} {g : β → α} (h : LeftInverse f g) : LeftInverse (map f) (map g) | [] => by simp_rw [map_nil] | x :: xs => by simp_rw [map_cons, h x, h.list_map xs] nonrec theorem _root_.Function.RightInverse.list_map {f : α → β} {g : β → α} (h : RightInverse f g) : RightInverse (map f) (map g) := h.list_map nonrec theorem _root_.Function.Involutive.list_map {f : α → α} (h : Involutive f) : Involutive (map f) := Function.LeftInverse.list_map h @[simp] theorem map_leftInverse_iff {f : α → β} {g : β → α} : LeftInverse (map f) (map g) ↔ LeftInverse f g := ⟨fun h x => by injection h [x], (·.list_map)⟩ @[simp] theorem map_rightInverse_iff {f : α → β} {g : β → α} : RightInverse (map f) (map g) ↔ RightInverse f g := map_leftInverse_iff @[simp] theorem map_involutive_iff {f : α → α} : Involutive (map f) ↔ Involutive f := map_leftInverse_iff theorem _root_.Function.Injective.list_map {f : α → β} (h : Injective f) : Injective (map f) | [], [], _ => rfl | x :: xs, y :: ys, hxy => by injection hxy with hxy hxys rw [h hxy, h.list_map hxys] @[simp] theorem map_injective_iff {f : α → β} : Injective (map f) ↔ Injective f := by refine ⟨fun h x y hxy => ?_, (·.list_map)⟩ suffices [x] = [y] by simpa using this apply h simp [hxy] theorem _root_.Function.Surjective.list_map {f : α → β} (h : Surjective f) : Surjective (map f) := let ⟨_, h⟩ := h.hasRightInverse; h.list_map.surjective @[simp] theorem map_surjective_iff {f : α → β} : Surjective (map f) ↔ Surjective f := by refine ⟨fun h x => ?_, (·.list_map)⟩ let ⟨[y], hxy⟩ := h [x] exact ⟨_, List.singleton_injective hxy⟩ theorem _root_.Function.Bijective.list_map {f : α → β} (h : Bijective f) : Bijective (map f) := ⟨h.1.list_map, h.2.list_map⟩ @[simp] theorem map_bijective_iff {f : α → β} : Bijective (map f) ↔ Bijective f := by simp_rw [Function.Bijective, map_injective_iff, map_surjective_iff] end map_bijectivity theorem eq_of_mem_map_const {b₁ b₂ : β} {l : List α} (h : b₁ ∈ map (const α b₂) l) : b₁ = b₂ := by rw [map_const] at h; exact eq_of_mem_replicate h /-- `eq_nil_or_concat` in simp normal form -/ lemma eq_nil_or_concat' (l : List α) : l = [] ∨ ∃ L b, l = L ++ [b] := by simpa using l.eq_nil_or_concat /-! ### foldl, foldr -/ theorem foldl_ext (f g : α → β → α) (a : α) {l : List β} (H : ∀ a : α, ∀ b ∈ l, f a b = g a b) : foldl f a l = foldl g a l := by induction l generalizing a with | nil => rfl | cons hd tl ih => unfold foldl rw [ih _ fun a b bin => H a b <| mem_cons_of_mem _ bin, H a hd mem_cons_self] theorem foldr_ext (f g : α → β → β) (b : β) {l : List α} (H : ∀ a ∈ l, ∀ b : β, f a b = g a b) : foldr f b l = foldr g b l := by induction l with | nil => rfl | cons hd tl ih => ?_ simp only [mem_cons, or_imp, forall_and, forall_eq] at H simp only [foldr, ih H.2, H.1] theorem foldl_concat (f : β → α → β) (b : β) (x : α) (xs : List α) : List.foldl f b (xs ++ [x]) = f (List.foldl f b xs) x := by simp only [List.foldl_append, List.foldl] theorem foldr_concat (f : α → β → β) (b : β) (x : α) (xs : List α) : List.foldr f b (xs ++ [x]) = (List.foldr f (f x b) xs) := by simp only [List.foldr_append, List.foldr] theorem foldl_fixed' {f : α → β → α} {a : α} (hf : ∀ b, f a b = a) : ∀ l : List β, foldl f a l = a | [] => rfl | b :: l => by rw [foldl_cons, hf b, foldl_fixed' hf l] theorem foldr_fixed' {f : α → β → β} {b : β} (hf : ∀ a, f a b = b) : ∀ l : List α, foldr f b l = b | [] => rfl | a :: l => by rw [foldr_cons, foldr_fixed' hf l, hf a] @[simp] theorem foldl_fixed {a : α} : ∀ l : List β, foldl (fun a _ => a) a l = a := foldl_fixed' fun _ => rfl @[simp] theorem foldr_fixed {b : β} : ∀ l : List α, foldr (fun _ b => b) b l = b := foldr_fixed' fun _ => rfl @[deprecated foldr_cons_nil (since := "2025-02-10")] theorem foldr_eta (l : List α) : foldr cons [] l = l := foldr_cons_nil theorem reverse_foldl {l : List α} : reverse (foldl (fun t h => h :: t) [] l) = l := by simp theorem foldl_hom₂ (l : List ι) (f : α → β → γ) (op₁ : α → ι → α) (op₂ : β → ι → β) (op₃ : γ → ι → γ) (a : α) (b : β) (h : ∀ a b i, f (op₁ a i) (op₂ b i) = op₃ (f a b) i) : foldl op₃ (f a b) l = f (foldl op₁ a l) (foldl op₂ b l) := Eq.symm <| by revert a b induction l <;> intros <;> [rfl; simp only [*, foldl]] theorem foldr_hom₂ (l : List ι) (f : α → β → γ) (op₁ : ι → α → α) (op₂ : ι → β → β) (op₃ : ι → γ → γ) (a : α) (b : β) (h : ∀ a b i, f (op₁ i a) (op₂ i b) = op₃ i (f a b)) : foldr op₃ (f a b) l = f (foldr op₁ a l) (foldr op₂ b l) := by revert a induction l <;> intros <;> [rfl; simp only [*, foldr]] theorem injective_foldl_comp {l : List (α → α)} {f : α → α} (hl : ∀ f ∈ l, Function.Injective f) (hf : Function.Injective f) : Function.Injective (@List.foldl (α → α) (α → α) Function.comp f l) := by induction l generalizing f with | nil => exact hf | cons lh lt l_ih => apply l_ih fun _ h => hl _ (List.mem_cons_of_mem _ h) apply Function.Injective.comp hf apply hl _ mem_cons_self /-- Consider two lists `l₁` and `l₂` with designated elements `a₁` and `a₂` somewhere in them: `l₁ = x₁ ++ [a₁] ++ z₁` and `l₂ = x₂ ++ [a₂] ++ z₂`. Assume the designated element `a₂` is present in neither `x₁` nor `z₁`. We conclude that the lists are equal (`l₁ = l₂`) if and only if their respective parts are equal (`x₁ = x₂ ∧ a₁ = a₂ ∧ z₁ = z₂`). -/ lemma append_cons_inj_of_not_mem {x₁ x₂ z₁ z₂ : List α} {a₁ a₂ : α} (notin_x : a₂ ∉ x₁) (notin_z : a₂ ∉ z₁) : x₁ ++ a₁ :: z₁ = x₂ ++ a₂ :: z₂ ↔ x₁ = x₂ ∧ a₁ = a₂ ∧ z₁ = z₂ := by constructor · simp only [append_eq_append_iff, cons_eq_append_iff, cons_eq_cons] rintro (⟨c, rfl, ⟨rfl, rfl, rfl⟩ | ⟨d, rfl, rfl⟩⟩ | ⟨c, rfl, ⟨rfl, rfl, rfl⟩ | ⟨d, rfl, rfl⟩⟩) <;> simp_all · rintro ⟨rfl, rfl, rfl⟩ rfl section FoldlEqFoldr -- foldl and foldr coincide when f is commutative and associative variable {f : α → α → α} theorem foldl1_eq_foldr1 [hassoc : Std.Associative f] : ∀ a b l, foldl f a (l ++ [b]) = foldr f b (a :: l) | _, _, nil => rfl | a, b, c :: l => by simp only [cons_append, foldl_cons, foldr_cons, foldl1_eq_foldr1 _ _ l] rw [hassoc.assoc] theorem foldl_eq_of_comm_of_assoc [hcomm : Std.Commutative f] [hassoc : Std.Associative f] : ∀ a b l, foldl f a (b :: l) = f b (foldl f a l) | a, b, nil => hcomm.comm a b | a, b, c :: l => by simp only [foldl_cons] have : RightCommutative f := inferInstance rw [← foldl_eq_of_comm_of_assoc .., this.right_comm, foldl_cons] theorem foldl_eq_foldr [Std.Commutative f] [Std.Associative f] : ∀ a l, foldl f a l = foldr f a l | _, nil => rfl | a, b :: l => by simp only [foldr_cons, foldl_eq_of_comm_of_assoc] rw [foldl_eq_foldr a l] end FoldlEqFoldr section FoldlEqFoldlr' variable {f : α → β → α} variable (hf : ∀ a b c, f (f a b) c = f (f a c) b) include hf theorem foldl_eq_of_comm' : ∀ a b l, foldl f a (b :: l) = f (foldl f a l) b | _, _, [] => rfl | a, b, c :: l => by rw [foldl, foldl, foldl, ← foldl_eq_of_comm' .., foldl, hf] theorem foldl_eq_foldr' : ∀ a l, foldl f a l = foldr (flip f) a l | _, [] => rfl | a, b :: l => by rw [foldl_eq_of_comm' hf, foldr, foldl_eq_foldr' ..]; rfl end FoldlEqFoldlr' section FoldlEqFoldlr' variable {f : α → β → β} theorem foldr_eq_of_comm' (hf : ∀ a b c, f a (f b c) = f b (f a c)) : ∀ a b l, foldr f a (b :: l) = foldr f (f b a) l | _, _, [] => rfl | a, b, c :: l => by rw [foldr, foldr, foldr, hf, ← foldr_eq_of_comm' hf ..]; rfl end FoldlEqFoldlr' section variable {op : α → α → α} [ha : Std.Associative op] /-- Notation for `op a b`. -/ local notation a " ⋆ " b => op a b /-- Notation for `foldl op a l`. -/ local notation l " <*> " a => foldl op a l theorem foldl_op_eq_op_foldr_assoc : ∀ {l : List α} {a₁ a₂}, ((l <*> a₁) ⋆ a₂) = a₁ ⋆ l.foldr (· ⋆ ·) a₂ | [], _, _ => rfl | a :: l, a₁, a₂ => by simp only [foldl_cons, foldr_cons, foldl_assoc, ha.assoc]; rw [foldl_op_eq_op_foldr_assoc] variable [hc : Std.Commutative op] theorem foldl_assoc_comm_cons {l : List α} {a₁ a₂} : ((a₁ :: l) <*> a₂) = a₁ ⋆ l <*> a₂ := by rw [foldl_cons, hc.comm, foldl_assoc] end /-! ### foldlM, foldrM, mapM -/ section FoldlMFoldrM variable {m : Type v → Type w} [Monad m] variable [LawfulMonad m] theorem foldrM_eq_foldr (f : α → β → m β) (b l) : foldrM f b l = foldr (fun a mb => mb >>= f a) (pure b) l := by induction l <;> simp [*] theorem foldlM_eq_foldl (f : β → α → m β) (b l) : List.foldlM f b l = foldl (fun mb a => mb >>= fun b => f b a) (pure b) l := by suffices h : ∀ mb : m β, (mb >>= fun b => List.foldlM f b l) = foldl (fun mb a => mb >>= fun b => f b a) mb l by simp [← h (pure b)] induction l with | nil => intro; simp | cons _ _ l_ih => intro; simp only [List.foldlM, foldl, ← l_ih, functor_norm] end FoldlMFoldrM /-! ### intersperse -/ @[deprecated (since := "2025-02-07")] alias intersperse_singleton := intersperse_single @[deprecated (since := "2025-02-07")] alias intersperse_cons_cons := intersperse_cons₂ /-! ### map for partial functions -/ @[deprecated "Deprecated without replacement." (since := "2025-02-07")] theorem sizeOf_lt_sizeOf_of_mem [SizeOf α] {x : α} {l : List α} (hx : x ∈ l) : SizeOf.sizeOf x < SizeOf.sizeOf l := by induction l with | nil => ?_ | cons h t ih => ?_ <;> cases hx <;> rw [cons.sizeOf_spec] · omega · specialize ih ‹_› omega /-! ### filter -/ theorem length_eq_length_filter_add {l : List (α)} (f : α → Bool) : l.length = (l.filter f).length + (l.filter (! f ·)).length := by simp_rw [← List.countP_eq_length_filter, l.length_eq_countP_add_countP f, Bool.not_eq_true, Bool.decide_eq_false] /-! ### filterMap -/ theorem filterMap_eq_flatMap_toList (f : α → Option β) (l : List α) : l.filterMap f = l.flatMap fun a ↦ (f a).toList := by induction l with | nil => ?_ | cons a l ih => ?_ <;> simp [filterMap_cons] rcases f a <;> simp [ih] theorem filterMap_congr {f g : α → Option β} {l : List α} (h : ∀ x ∈ l, f x = g x) : l.filterMap f = l.filterMap g := by induction l <;> simp_all [filterMap_cons] theorem filterMap_eq_map_iff_forall_eq_some {f : α → Option β} {g : α → β} {l : List α} : l.filterMap f = l.map g ↔ ∀ x ∈ l, f x = some (g x) where mp := by induction l with | nil => simp | cons a l ih => ?_ rcases ha : f a with - | b <;> simp [ha, filterMap_cons] · intro h simpa [show (filterMap f l).length = l.length + 1 from by simp[h], Nat.add_one_le_iff] using List.length_filterMap_le f l · rintro rfl h exact ⟨rfl, ih h⟩ mpr h := Eq.trans (filterMap_congr <| by simpa) (congr_fun filterMap_eq_map _) /-! ### filter -/ section Filter variable {p : α → Bool} theorem filter_singleton {a : α} : [a].filter p = bif p a then [a] else [] := rfl theorem filter_eq_foldr (p : α → Bool) (l : List α) : filter p l = foldr (fun a out => bif p a then a :: out else out) [] l := by induction l <;> simp [*, filter]; rfl #adaptation_note /-- nightly-2024-07-27 This has to be temporarily renamed to avoid an unintentional collision. The prime should be removed at nightly-2024-07-27. -/ @[simp] theorem filter_subset' (l : List α) : filter p l ⊆ l := filter_sublist.subset theorem of_mem_filter {a : α} {l} (h : a ∈ filter p l) : p a := (mem_filter.1 h).2 theorem mem_of_mem_filter {a : α} {l} (h : a ∈ filter p l) : a ∈ l := filter_subset' l h theorem mem_filter_of_mem {a : α} {l} (h₁ : a ∈ l) (h₂ : p a) : a ∈ filter p l := mem_filter.2 ⟨h₁, h₂⟩ @[deprecated (since := "2025-02-07")] alias monotone_filter_left := filter_subset variable (p) theorem monotone_filter_right (l : List α) ⦃p q : α → Bool⦄ (h : ∀ a, p a → q a) : l.filter p <+ l.filter q := by induction l with | nil => rfl | cons hd tl IH => by_cases hp : p hd · rw [filter_cons_of_pos hp, filter_cons_of_pos (h _ hp)] exact IH.cons_cons hd · rw [filter_cons_of_neg hp] by_cases hq : q hd · rw [filter_cons_of_pos hq] exact sublist_cons_of_sublist hd IH · rw [filter_cons_of_neg hq] exact IH lemma map_filter {f : α → β} (hf : Injective f) (l : List α) [DecidablePred fun b => ∃ a, p a ∧ f a = b] : (l.filter p).map f = (l.map f).filter fun b => ∃ a, p a ∧ f a = b := by simp [comp_def, filter_map, hf.eq_iff] @[deprecated (since := "2025-02-07")] alias map_filter' := map_filter lemma filter_attach' (l : List α) (p : {a // a ∈ l} → Bool) [DecidableEq α] : l.attach.filter p = (l.filter fun x => ∃ h, p ⟨x, h⟩).attach.map (Subtype.map id fun _ => mem_of_mem_filter) := by classical refine map_injective_iff.2 Subtype.coe_injective ?_ simp [comp_def, map_filter _ Subtype.coe_injective] lemma filter_attach (l : List α) (p : α → Bool) : (l.attach.filter fun x => p x : List {x // x ∈ l}) = (l.filter p).attach.map (Subtype.map id fun _ => mem_of_mem_filter) := map_injective_iff.2 Subtype.coe_injective <| by simp_rw [map_map, comp_def, Subtype.map, id, ← Function.comp_apply (g := Subtype.val), ← filter_map, attach_map_subtype_val] lemma filter_comm (q) (l : List α) : filter p (filter q l) = filter q (filter p l) := by simp [Bool.and_comm] @[simp] theorem filter_true (l : List α) : filter (fun _ => true) l = l := by induction l <;> simp [*, filter] @[simp] theorem filter_false (l : List α) : filter (fun _ => false) l = [] := by induction l <;> simp [*, filter] end Filter /-! ### eraseP -/ section eraseP variable {p : α → Bool} @[simp] theorem length_eraseP_add_one {l : List α} {a} (al : a ∈ l) (pa : p a) : (l.eraseP p).length + 1 = l.length := by let ⟨_, l₁, l₂, _, _, h₁, h₂⟩ := exists_of_eraseP al pa rw [h₂, h₁, length_append, length_append] rfl end eraseP /-! ### erase -/ section Erase variable [DecidableEq α] @[simp] theorem length_erase_add_one {a : α} {l : List α} (h : a ∈ l) : (l.erase a).length + 1 = l.length := by rw [erase_eq_eraseP, length_eraseP_add_one h (decide_eq_true rfl)] theorem map_erase [DecidableEq β] {f : α → β} (finj : Injective f) {a : α} (l : List α) : map f (l.erase a) = (map f l).erase (f a) := by have this : (a == ·) = (f a == f ·) := by ext b; simp [beq_eq_decide, finj.eq_iff] rw [erase_eq_eraseP, erase_eq_eraseP, eraseP_map, this]; rfl theorem map_foldl_erase [DecidableEq β] {f : α → β} (finj : Injective f) {l₁ l₂ : List α} : map f (foldl List.erase l₁ l₂) = foldl (fun l a => l.erase (f a)) (map f l₁) l₂ := by induction l₂ generalizing l₁ <;> [rfl; simp only [foldl_cons, map_erase finj, *]] theorem erase_getElem [DecidableEq ι] {l : List ι} {i : ℕ} (hi : i < l.length) : Perm (l.erase l[i]) (l.eraseIdx i) := by induction l generalizing i with | nil => simp | cons a l IH => cases i with | zero => simp | succ i => have hi' : i < l.length := by simpa using hi if ha : a = l[i] then simpa [ha] using .trans (perm_cons_erase (getElem_mem _)) (.cons _ (IH hi')) else simpa [ha] using IH hi' theorem length_eraseIdx_add_one {l : List ι} {i : ℕ} (h : i < l.length) : (l.eraseIdx i).length + 1 = l.length := by rw [length_eraseIdx] split <;> omega end Erase /-! ### diff -/ section Diff variable [DecidableEq α] @[simp] theorem map_diff [DecidableEq β] {f : α → β} (finj : Injective f) {l₁ l₂ : List α} : map f (l₁.diff l₂) = (map f l₁).diff (map f l₂) := by simp only [diff_eq_foldl, foldl_map, map_foldl_erase finj] @[deprecated (since := "2025-04-10")] alias erase_diff_erase_sublist_of_sublist := Sublist.erase_diff_erase_sublist end Diff section Choose variable (p : α → Prop) [DecidablePred p] (l : List α) theorem choose_spec (hp : ∃ a, a ∈ l ∧ p a) : choose p l hp ∈ l ∧ p (choose p l hp) := (chooseX p l hp).property theorem choose_mem (hp : ∃ a, a ∈ l ∧ p a) : choose p l hp ∈ l := (choose_spec _ _ _).1 theorem choose_property (hp : ∃ a, a ∈ l ∧ p a) : p (choose p l hp) := (choose_spec _ _ _).2 end Choose /-! ### Forall -/ section Forall variable {p q : α → Prop} {l : List α} @[simp] theorem forall_cons (p : α → Prop) (x : α) : ∀ l : List α, Forall p (x :: l) ↔ p x ∧ Forall p l | [] => (and_iff_left_of_imp fun _ ↦ trivial).symm | _ :: _ => Iff.rfl @[simp] theorem forall_append {p : α → Prop} : ∀ {xs ys : List α}, Forall p (xs ++ ys) ↔ Forall p xs ∧ Forall p ys | [] => by simp | _ :: _ => by simp [forall_append, and_assoc] theorem forall_iff_forall_mem : ∀ {l : List α}, Forall p l ↔ ∀ x ∈ l, p x | [] => (iff_true_intro <| forall_mem_nil _).symm | x :: l => by rw [forall_mem_cons, forall_cons, forall_iff_forall_mem] theorem Forall.imp (h : ∀ x, p x → q x) : ∀ {l : List α}, Forall p l → Forall q l | [] => id | x :: l => by simp only [forall_cons, and_imp] rw [← and_imp] exact And.imp (h x) (Forall.imp h) @[simp] theorem forall_map_iff {p : β → Prop} (f : α → β) : Forall p (l.map f) ↔ Forall (p ∘ f) l := by induction l <;> simp [*] instance (p : α → Prop) [DecidablePred p] : DecidablePred (Forall p) := fun _ => decidable_of_iff' _ forall_iff_forall_mem end Forall /-! ### Miscellaneous lemmas -/ theorem get_attach (l : List α) (i) : (l.attach.get i).1 = l.get ⟨i, length_attach (l := l) ▸ i.2⟩ := by simp section Disjoint /-- The images of disjoint lists under a partially defined map are disjoint -/ theorem disjoint_pmap {p : α → Prop} {f : ∀ a : α, p a → β} {s t : List α} (hs : ∀ a ∈ s, p a) (ht : ∀ a ∈ t, p a) (hf : ∀ (a a' : α) (ha : p a) (ha' : p a'), f a ha = f a' ha' → a = a') (h : Disjoint s t) : Disjoint (s.pmap f hs) (t.pmap f ht) := by simp only [Disjoint, mem_pmap] rintro b ⟨a, ha, rfl⟩ ⟨a', ha', ha''⟩ apply h ha rwa [hf a a' (hs a ha) (ht a' ha') ha''.symm] /-- The images of disjoint lists under an injective map are disjoint -/ theorem disjoint_map {f : α → β} {s t : List α} (hf : Function.Injective f) (h : Disjoint s t) : Disjoint (s.map f) (t.map f) := by rw [← pmap_eq_map (fun _ _ ↦ trivial), ← pmap_eq_map (fun _ _ ↦ trivial)] exact disjoint_pmap _ _ (fun _ _ _ _ h' ↦ hf h') h alias Disjoint.map := disjoint_map theorem Disjoint.of_map {f : α → β} {s t : List α} (h : Disjoint (s.map f) (t.map f)) : Disjoint s t := fun _a has hat ↦ h (mem_map_of_mem has) (mem_map_of_mem hat) theorem Disjoint.map_iff {f : α → β} {s t : List α} (hf : Function.Injective f) : Disjoint (s.map f) (t.map f) ↔ Disjoint s t := ⟨fun h ↦ h.of_map, fun h ↦ h.map hf⟩ theorem Perm.disjoint_left {l₁ l₂ l : List α} (p : List.Perm l₁ l₂) : Disjoint l₁ l ↔ Disjoint l₂ l := by simp_rw [List.disjoint_left, p.mem_iff] theorem Perm.disjoint_right {l₁ l₂ l : List α} (p : List.Perm l₁ l₂) : Disjoint l l₁ ↔ Disjoint l l₂ := by simp_rw [List.disjoint_right, p.mem_iff] @[simp] theorem disjoint_reverse_left {l₁ l₂ : List α} : Disjoint l₁.reverse l₂ ↔ Disjoint l₁ l₂ := reverse_perm _ |>.disjoint_left @[simp] theorem disjoint_reverse_right {l₁ l₂ : List α} : Disjoint l₁ l₂.reverse ↔ Disjoint l₁ l₂ := reverse_perm _ |>.disjoint_right end Disjoint section lookup variable [BEq α] [LawfulBEq α] lemma lookup_graph (f : α → β) {a : α} {as : List α} (h : a ∈ as) : lookup a (as.map fun x => (x, f x)) = some (f a) := by induction as with | nil => exact (not_mem_nil h).elim | cons a' as ih => by_cases ha : a = a' · simp [ha, lookup_cons] · simpa [lookup_cons, beq_false_of_ne ha] using ih (List.mem_of_ne_of_mem ha h) end lookup section range' @[simp] lemma range'_0 (a b : ℕ) : range' a b 0 = replicate b a := by induction b with | zero => simp | succ b ih => simp [range'_succ, ih, replicate_succ] lemma left_le_of_mem_range' {a b s x : ℕ} (hx : x ∈ List.range' a b s) : a ≤ x := by obtain ⟨i, _, rfl⟩ := List.mem_range'.mp hx exact le_add_right a (s * i) end range' end List
Mathlib/Data/List/Basic.lean
1,866
1,868
/- 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.Enum import Mathlib.Tactic.TFAE import Mathlib.Topology.Order.Monotone /-! ### Topology of ordinals We prove some miscellaneous results involving the order topology of ordinals. ### Main results * `Ordinal.isClosed_iff_iSup` / `Ordinal.isClosed_iff_bsup`: A set of ordinals is closed iff it's closed under suprema. * `Ordinal.isNormal_iff_strictMono_and_continuous`: A characterization of normal ordinal functions. * `Ordinal.enumOrd_isNormal_iff_isClosed`: The function enumerating the ordinals of a set is normal iff the set is closed. -/ noncomputable section universe u v open Cardinal Order Topology namespace Ordinal variable {s : Set Ordinal.{u}} {a : Ordinal.{u}} instance : TopologicalSpace Ordinal.{u} := Preorder.topology Ordinal.{u} instance : OrderTopology Ordinal.{u} := ⟨rfl⟩ theorem isOpen_singleton_iff : IsOpen ({a} : Set Ordinal) ↔ ¬IsLimit a := by refine ⟨fun h ha => ?_, fun ha => ?_⟩ · obtain ⟨b, c, hbc, hbc'⟩ := (mem_nhds_iff_exists_Ioo_subset' ⟨0, ha.pos⟩ ⟨_, lt_succ a⟩).1 (h.mem_nhds rfl) have hba := ha.succ_lt hbc.1 exact hba.ne (hbc' ⟨lt_succ b, hba.trans hbc.2⟩) · rcases zero_or_succ_or_limit a with (rfl | ⟨b, rfl⟩ | ha') · rw [← bot_eq_zero, ← Set.Iic_bot, ← Iio_succ] exact isOpen_Iio · rw [← Set.Icc_self, Icc_succ_left, ← Ioo_succ_right] exact isOpen_Ioo · exact (ha ha').elim @[deprecated SuccOrder.nhdsGT (since := "2025-01-05")] protected theorem nhdsGT (a : Ordinal) : 𝓝[>] a = ⊥ := SuccOrder.nhdsGT @[deprecated (since := "2024-12-22")] alias nhds_right' := Ordinal.nhdsGT @[deprecated SuccOrder.nhdsLT_eq_nhdsNE (since := "2025-01-05")] theorem nhdsLT_eq_nhdsNE (a : Ordinal) : 𝓝[<] a = 𝓝[≠] a := SuccOrder.nhdsLT_eq_nhdsNE a @[deprecated (since := "2024-12-22")] alias nhds_left'_eq_nhds_ne := nhdsLT_eq_nhdsNE @[deprecated SuccOrder.nhdsLE_eq_nhds (since := "2025-01-05")] theorem nhdsLE_eq_nhds (a : Ordinal) : 𝓝[≤] a = 𝓝 a := SuccOrder.nhdsLE_eq_nhds a @[deprecated (since := "2024-12-22")] alias nhds_left_eq_nhds := nhdsLE_eq_nhds @[deprecated SuccOrder.hasBasis_nhds_Ioc_of_exists_lt (since := "2025-01-05")] theorem hasBasis_nhds_Ioc (h : a ≠ 0) : (𝓝 a).HasBasis (· < a) (Set.Ioc · a) := SuccOrder.hasBasis_nhds_Ioc_of_exists_lt ⟨0, Ordinal.pos_iff_ne_zero.2 h⟩ @[deprecated (since := "2024-12-22")] alias nhdsBasis_Ioc := hasBasis_nhds_Ioc -- todo: generalize to a `SuccOrder` theorem nhds_eq_pure : 𝓝 a = pure a ↔ ¬IsLimit a := (isOpen_singleton_iff_nhds_eq_pure _).symm.trans isOpen_singleton_iff -- todo: generalize `Ordinal.IsLimit` and this lemma to a `SuccOrder` theorem isOpen_iff : IsOpen s ↔ ∀ o ∈ s, IsLimit o → ∃ a < o, Set.Ioo a o ⊆ s := by refine isOpen_iff_mem_nhds.trans <| forall₂_congr fun o ho => ?_ by_cases ho' : IsLimit o · simp only [(SuccOrder.hasBasis_nhds_Ioc_of_exists_lt ⟨0, ho'.pos⟩).mem_iff, ho', true_implies] refine exists_congr fun a => and_congr_right fun ha => ?_ simp only [← Set.Ioo_insert_right ha, Set.insert_subset_iff, ho, true_and] · simp [nhds_eq_pure.2 ho', ho, ho'] open List Set in theorem mem_closure_tfae (a : Ordinal.{u}) (s : Set Ordinal) : TFAE [a ∈ closure s, a ∈ closure (s ∩ Iic a), (s ∩ Iic a).Nonempty ∧ sSup (s ∩ Iic a) = a, ∃ t, t ⊆ s ∧ t.Nonempty ∧ BddAbove t ∧ sSup t = a, ∃ (o : Ordinal.{u}), o ≠ 0 ∧ ∃ (f : ∀ x < o, Ordinal), (∀ x hx, f x hx ∈ s) ∧ bsup.{u, u} o f = a, ∃ (ι : Type u), Nonempty ι ∧ ∃ f : ι → Ordinal, (∀ i, f i ∈ s) ∧ ⨆ i, f i = a] := by tfae_have 1 → 2 := by simpa only [mem_closure_iff_nhdsWithin_neBot, inter_comm s, nhdsWithin_inter', SuccOrder.nhdsLE_eq_nhds] using id tfae_have 2 → 3 | h => by rcases (s ∩ Iic a).eq_empty_or_nonempty with he | hne · simp [he] at h · refine ⟨hne, (isLUB_of_mem_closure ?_ h).csSup_eq hne⟩ exact fun x hx => hx.2 tfae_have 3 → 4 | h => ⟨_, inter_subset_left, h.1, bddAbove_Iic.mono inter_subset_right, h.2⟩ tfae_have 4 → 5 := by rintro ⟨t, hts, hne, hbdd, rfl⟩ have hlub : IsLUB t (sSup t) := isLUB_csSup hne hbdd let ⟨y, hyt⟩ := hne classical refine ⟨succ (sSup t), succ_ne_zero _, fun x _ => if x ∈ t then x else y, fun x _ => ?_, ?_⟩ · simp only split_ifs with h <;> exact hts ‹_› · refine le_antisymm (bsup_le fun x _ => ?_) (csSup_le hne fun x hx => ?_) · split_ifs <;> exact hlub.1 ‹_› · refine (if_pos hx).symm.trans_le (le_bsup _ _ <| (hlub.1 hx).trans_lt (lt_succ _)) tfae_have 5 → 6 := by rintro ⟨o, h₀, f, hfs, rfl⟩ exact ⟨_, toType_nonempty_iff_ne_zero.2 h₀, familyOfBFamily o f, fun _ => hfs _ _, rfl⟩ tfae_have 6 → 1 := by rintro ⟨ι, hne, f, hfs, rfl⟩ exact closure_mono (range_subset_iff.2 hfs) <| csSup_mem_closure (range_nonempty f) (bddAbove_range.{u, u} f) tfae_finish theorem mem_closure_iff_iSup : a ∈ closure s ↔ ∃ (ι : Type u) (_ : Nonempty ι) (f : ι → Ordinal), (∀ i, f i ∈ s) ∧ ⨆ i, f i = a := by apply ((mem_closure_tfae a s).out 0 5).trans simp_rw [exists_prop] theorem mem_iff_iSup_of_isClosed (hs : IsClosed s) : a ∈ s ↔ ∃ (ι : Type u) (_hι : Nonempty ι) (f : ι → Ordinal), (∀ i, f i ∈ s) ∧ ⨆ i, f i = a := by rw [← mem_closure_iff_iSup, hs.closure_eq] theorem mem_closure_iff_bsup : a ∈ closure s ↔ ∃ (o : Ordinal) (_ho : o ≠ 0) (f : ∀ a < o, Ordinal), (∀ i hi, f i hi ∈ s) ∧ bsup.{u, u} o f = a := by apply ((mem_closure_tfae a s).out 0 4).trans simp_rw [exists_prop] theorem mem_closed_iff_bsup (hs : IsClosed s) : a ∈ s ↔ ∃ (o : Ordinal) (_ho : o ≠ 0) (f : ∀ a < o, Ordinal), (∀ i hi, f i hi ∈ s) ∧ bsup.{u, u} o f = a := by rw [← mem_closure_iff_bsup, hs.closure_eq]
theorem isClosed_iff_iSup : IsClosed s ↔ ∀ {ι : Type u}, Nonempty ι → ∀ f : ι → Ordinal, (∀ i, f i ∈ s) → ⨆ i, f i ∈ s := by use fun hs ι hι f hf => (mem_iff_iSup_of_isClosed hs).2 ⟨ι, hι, f, hf, rfl⟩ rw [← closure_subset_iff_isClosed] intro h x hx rcases mem_closure_iff_iSup.1 hx with ⟨ι, hι, f, hf, rfl⟩
Mathlib/SetTheory/Ordinal/Topology.lean
152
159
/- Copyright (c) 2021 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth, David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.ExpDeriv import Mathlib.Analysis.SpecialFunctions.Complex.Circle import Mathlib.Analysis.InnerProductSpace.l2Space import Mathlib.MeasureTheory.Function.ContinuousMapDense import Mathlib.MeasureTheory.Function.L2Space import Mathlib.MeasureTheory.Group.Integral import Mathlib.MeasureTheory.Integral.IntervalIntegral.Periodic import Mathlib.Topology.ContinuousMap.StoneWeierstrass import Mathlib.MeasureTheory.Integral.IntervalIntegral.IntegrationByParts /-! # Fourier analysis on the additive circle This file contains basic results on Fourier series for functions on the additive circle `AddCircle T = ℝ / ℤ • T`. ## Main definitions * `haarAddCircle`, Haar measure on `AddCircle T`, normalized to have total measure `1`. Note that this is not the same normalisation as the standard measure defined in `IntervalIntegral.Periodic`, so we do not declare it as a `MeasureSpace` instance, to avoid confusion. * for `n : ℤ`, `fourier n` is the monomial `fun x => exp (2 π i n x / T)`, bundled as a continuous map from `AddCircle T` to `ℂ`. * `fourierBasis` is the Hilbert basis of `Lp ℂ 2 haarAddCircle` given by the images of the monomials `fourier n`. * `fourierCoeff f n`, for `f : AddCircle T → E` (with `E` a complete normed `ℂ`-vector space), is the `n`-th Fourier coefficient of `f`, defined as an integral over `AddCircle T`. The lemma `fourierCoeff_eq_intervalIntegral` expresses this as an integral over `[a, a + T]` for any real `a`. * `fourierCoeffOn`, for `f : ℝ → E` and `a < b` reals, is the `n`-th Fourier coefficient of the unique periodic function of period `b - a` which agrees with `f` on `(a, b]`. The lemma `fourierCoeffOn_eq_integral` expresses this as an integral over `[a, b]`. ## Main statements The theorem `span_fourier_closure_eq_top` states that the span of the monomials `fourier n` is dense in `C(AddCircle T, ℂ)`, i.e. that its `Submodule.topologicalClosure` is `⊤`. This follows from the Stone-Weierstrass theorem after checking that the span is a subalgebra, is closed under conjugation, and separates points. Using this and general theory on approximation of Lᵖ functions by continuous functions, we deduce (`span_fourierLp_closure_eq_top`) that for any `1 ≤ p < ∞`, the span of the Fourier monomials is dense in the Lᵖ space of `AddCircle T`. For `p = 2` we show (`orthonormal_fourier`) that the monomials are also orthonormal, so they form a Hilbert basis for L², which is named as `fourierBasis`; in particular, for `L²` functions `f`, the Fourier series of `f` converges to `f` in the `L²` topology (`hasSum_fourier_series_L2`). Parseval's identity, `tsum_sq_fourierCoeff`, is a direct consequence. For continuous maps `f : AddCircle T → ℂ`, the theorem `hasSum_fourier_series_of_summable` states that if the sequence of Fourier coefficients of `f` is summable, then the Fourier series `∑ (i : ℤ), fourierCoeff f i * fourier i` converges to `f` in the uniform-convergence topology of `C(AddCircle T, ℂ)`. -/ noncomputable section open scoped ENNReal ComplexConjugate Real open TopologicalSpace ContinuousMap MeasureTheory MeasureTheory.Measure Algebra Submodule Set variable {T : ℝ} namespace AddCircle /-! ### Measure on `AddCircle T` In this file we use the Haar measure on `AddCircle T` normalised to have total measure 1 (which is **not** the same as the standard measure defined in `Topology.Instances.AddCircle`). -/ variable [hT : Fact (0 < T)] /-- Haar measure on the additive circle, normalised to have total measure 1. -/ def haarAddCircle : Measure (AddCircle T) := addHaarMeasure ⊤ -- The `IsAddHaarMeasure` instance should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 instance : IsAddHaarMeasure (@haarAddCircle T _) := Measure.isAddHaarMeasure_addHaarMeasure ⊤ instance : IsProbabilityMeasure (@haarAddCircle T _) := IsProbabilityMeasure.mk addHaarMeasure_self theorem volume_eq_smul_haarAddCircle : (volume : Measure (AddCircle T)) = ENNReal.ofReal T • (@haarAddCircle T _) := rfl end AddCircle open AddCircle section Monomials /-- The family of exponential monomials `fun x => exp (2 π i n x / T)`, parametrized by `n : ℤ` and considered as bundled continuous maps from `ℝ / ℤ • T` to `ℂ`. -/ def fourier (n : ℤ) : C(AddCircle T, ℂ) where toFun x := toCircle (n • x :) continuous_toFun := continuous_induced_dom.comp <| continuous_toCircle.comp <| continuous_zsmul _ @[simp] theorem fourier_apply {n : ℤ} {x : AddCircle T} : fourier n x = toCircle (n • x :) := rfl -- simp normal form is `fourier_coe_apply'` theorem fourier_coe_apply {n : ℤ} {x : ℝ} : fourier n (x : AddCircle T) = Complex.exp (2 * π * Complex.I * n * x / T) := by rw [fourier_apply, ← QuotientAddGroup.mk_zsmul, toCircle, Function.Periodic.lift_coe, Circle.coe_exp, Complex.ofReal_mul, Complex.ofReal_div, Complex.ofReal_mul, zsmul_eq_mul, Complex.ofReal_mul, Complex.ofReal_intCast] norm_num congr 1; ring @[simp] theorem fourier_coe_apply' {n : ℤ} {x : ℝ} : toCircle (n • (x : AddCircle T) :) = Complex.exp (2 * π * Complex.I * n * x / T) := by rw [← fourier_apply]; exact fourier_coe_apply -- simp normal form is `fourier_zero'` theorem fourier_zero {x : AddCircle T} : fourier 0 x = 1 := by induction x using QuotientAddGroup.induction_on simp only [fourier_coe_apply] norm_num theorem fourier_zero' {x : AddCircle T} : @toCircle T 0 = (1 : ℂ) := by have : fourier 0 x = @toCircle T 0 := by rw [fourier_apply, zero_smul] rw [← this]; exact fourier_zero -- simp normal form is *also* `fourier_zero'` theorem fourier_eval_zero (n : ℤ) : fourier n (0 : AddCircle T) = 1 := by rw [← QuotientAddGroup.mk_zero, fourier_coe_apply, Complex.ofReal_zero, mul_zero, zero_div, Complex.exp_zero] theorem fourier_one {x : AddCircle T} : fourier 1 x = toCircle x := by rw [fourier_apply, one_zsmul] -- simp normal form is `fourier_neg'` theorem fourier_neg {n : ℤ} {x : AddCircle T} : fourier (-n) x = conj (fourier n x) := by induction x using QuotientAddGroup.induction_on simp_rw [fourier_apply, toCircle] rw [← QuotientAddGroup.mk_zsmul, ← QuotientAddGroup.mk_zsmul] simp_rw [Function.Periodic.lift_coe, ← Circle.coe_inv_eq_conj, ← Circle.exp_neg, neg_smul, mul_neg] @[simp] theorem fourier_neg' {n : ℤ} {x : AddCircle T} : @toCircle T (-(n • x)) = conj (fourier n x) := by rw [← neg_smul, ← fourier_apply]; exact fourier_neg -- simp normal form is `fourier_add'` theorem fourier_add {m n : ℤ} {x : AddCircle T} : fourier (m+n) x = fourier m x * fourier n x := by simp_rw [fourier_apply, add_zsmul, toCircle_add, Circle.coe_mul] @[simp] theorem fourier_add' {m n : ℤ} {x : AddCircle T} : toCircle ((m + n) • x :) = fourier m x * fourier n x := by rw [← fourier_apply]; exact fourier_add theorem fourier_norm [Fact (0 < T)] (n : ℤ) : ‖@fourier T n‖ = 1 := by rw [ContinuousMap.norm_eq_iSup_norm] have : ∀ x : AddCircle T, ‖fourier n x‖ = 1 := fun x => Circle.norm_coe _ simp_rw [this] exact @ciSup_const _ _ _ Zero.instNonempty _ /-- For `n ≠ 0`, a translation by `T / 2 / n` negates the function `fourier n`. -/ theorem fourier_add_half_inv_index {n : ℤ} (hn : n ≠ 0) (hT : 0 < T) (x : AddCircle T) : @fourier T n (x + ↑(T / 2 / n)) = -fourier n x := by rw [fourier_apply, zsmul_add, ← QuotientAddGroup.mk_zsmul, toCircle_add, Metric.unitSphere.coe_mul] have : (n : ℂ) ≠ 0 := by simpa using hn have : (@toCircle T (n • (T / 2 / n) : ℝ) : ℂ) = -1 := by rw [zsmul_eq_mul, toCircle, Function.Periodic.lift_coe, Circle.coe_exp] replace hT := Complex.ofReal_ne_zero.mpr hT.ne' convert Complex.exp_pi_mul_I using 3 field_simp; ring rw [this]; simp /-- The star subalgebra of `C(AddCircle T, ℂ)` generated by `fourier n` for `n ∈ ℤ` . -/ def fourierSubalgebra : StarSubalgebra ℂ C(AddCircle T, ℂ) where toSubalgebra := Algebra.adjoin ℂ (range fourier) star_mem' := by show Algebra.adjoin ℂ (range (fourier (T := T))) ≤ star (Algebra.adjoin ℂ (range (fourier (T := T)))) refine adjoin_le ?_ rintro - ⟨n, rfl⟩ exact subset_adjoin ⟨-n, ext fun _ => fourier_neg⟩ /-- The star subalgebra of `C(AddCircle T, ℂ)` generated by `fourier n` for `n ∈ ℤ` is in fact the linear span of these functions. -/ theorem fourierSubalgebra_coe : Subalgebra.toSubmodule (@fourierSubalgebra T).toSubalgebra = span ℂ (range (@fourier T)) := by apply adjoin_eq_span_of_subset refine Subset.trans ?_ Submodule.subset_span intro x hx refine Submonoid.closure_induction (fun _ => id) ⟨0, ?_⟩ ?_ hx · ext1 z; exact fourier_zero · rintro - - - - ⟨m, rfl⟩ ⟨n, rfl⟩ refine ⟨m + n, ?_⟩ ext1 z exact fourier_add /- a post-port refactor made `fourierSubalgebra` into a `StarSubalgebra`, and eliminated `conjInvariantSubalgebra` entirely, making this lemma irrelevant. -/ variable [hT : Fact (0 < T)] /-- The subalgebra of `C(AddCircle T, ℂ)` generated by `fourier n` for `n ∈ ℤ` separates points. -/ theorem fourierSubalgebra_separatesPoints : (@fourierSubalgebra T).SeparatesPoints := by intro x y hxy refine ⟨_, ⟨fourier 1, subset_adjoin ⟨1, rfl⟩, rfl⟩, ?_⟩ dsimp only; rw [fourier_one, fourier_one] contrapose! hxy rw [Subtype.coe_inj] at hxy exact injective_toCircle hT.elim.ne' hxy /-- The subalgebra of `C(AddCircle T, ℂ)` generated by `fourier n` for `n ∈ ℤ` is dense. -/ theorem fourierSubalgebra_closure_eq_top : (@fourierSubalgebra T).topologicalClosure = ⊤ := ContinuousMap.starSubalgebra_topologicalClosure_eq_top_of_separatesPoints fourierSubalgebra fourierSubalgebra_separatesPoints /-- The linear span of the monomials `fourier n` is dense in `C(AddCircle T, ℂ)`. -/ theorem span_fourier_closure_eq_top : (span ℂ (range <| @fourier T)).topologicalClosure = ⊤ := by rw [← fourierSubalgebra_coe] exact congr_arg (Subalgebra.toSubmodule <| StarSubalgebra.toSubalgebra ·) fourierSubalgebra_closure_eq_top /-- The family of monomials `fourier n`, parametrized by `n : ℤ` and considered as elements of the `Lp` space of functions `AddCircle T → ℂ`. -/ abbrev fourierLp (p : ℝ≥0∞) [Fact (1 ≤ p)] (n : ℤ) : Lp ℂ p (@haarAddCircle T hT) := toLp (E := ℂ) p haarAddCircle ℂ (fourier n) theorem coeFn_fourierLp (p : ℝ≥0∞) [Fact (1 ≤ p)] (n : ℤ) : @fourierLp T hT p _ n =ᵐ[haarAddCircle] fourier n := coeFn_toLp haarAddCircle (fourier n) /-- For each `1 ≤ p < ∞`, the linear span of the monomials `fourier n` is dense in `Lp ℂ p haarAddCircle`. -/ theorem span_fourierLp_closure_eq_top {p : ℝ≥0∞} [Fact (1 ≤ p)] (hp : p ≠ ∞) : (span ℂ (range (@fourierLp T _ p _))).topologicalClosure = ⊤ := by convert (ContinuousMap.toLp_denseRange ℂ (@haarAddCircle T hT) ℂ hp).topologicalClosure_map_submodule span_fourier_closure_eq_top rw [map_span] unfold fourierLp rw [range_comp'] simp only [ContinuousLinearMap.coe_coe] /-- The monomials `fourier n` are an orthonormal set with respect to normalised Haar measure. -/ theorem orthonormal_fourier : Orthonormal ℂ (@fourierLp T _ 2 _) := by rw [orthonormal_iff_ite] intro i j rw [ContinuousMap.inner_toLp (@haarAddCircle T hT) (fourier i) (fourier j)] simp_rw [← fourier_neg, ← fourier_add] split_ifs with h · simp_rw [h, add_neg_cancel] have : ⇑(@fourier T 0) = (fun _ => 1 : AddCircle T → ℂ) := by ext1; exact fourier_zero rw [this, integral_const, measureReal_univ_eq_one, Complex.real_smul, Complex.ofReal_one, mul_one] have hij : j + -i ≠ 0 := by exact sub_ne_zero.mpr (Ne.symm h) convert integral_eq_zero_of_add_right_eq_neg (μ := haarAddCircle) (fourier_add_half_inv_index hij hT.elim) end Monomials section ScopeHT -- everything from here on needs `0 < T` variable [hT : Fact (0 < T)] section fourierCoeff variable {E : Type} [NormedAddCommGroup E] [NormedSpace ℂ E] /-- The `n`-th Fourier coefficient of a function `AddCircle T → E`, for `E` a complete normed `ℂ`-vector space, defined as the integral over `AddCircle T` of `fourier (-n) t • f t`. -/ def fourierCoeff (f : AddCircle T → E) (n : ℤ) : E := ∫ t : AddCircle T, fourier (-n) t • f t ∂haarAddCircle /-- The Fourier coefficients of a function on `AddCircle T` can be computed as an integral over `[a, a + T]`, for any real `a`. -/ theorem fourierCoeff_eq_intervalIntegral (f : AddCircle T → E) (n : ℤ) (a : ℝ) : fourierCoeff f n = (1 / T) • ∫ x in a..a + T, @fourier T (-n) x • f x := by have : ∀ x : ℝ, @fourier T (-n) x • f x = (fun z : AddCircle T => @fourier T (-n) z • f z) x := by intro x; rfl -- After https://github.com/leanprover/lean4/pull/3124, we need to add `singlePass := true` to avoid an infinite loop. simp_rw +singlePass [this] rw [fourierCoeff, AddCircle.intervalIntegral_preimage T a (fun z => _ • _), volume_eq_smul_haarAddCircle, integral_smul_measure, ENNReal.toReal_ofReal hT.out.le, ← smul_assoc, smul_eq_mul, one_div_mul_cancel hT.out.ne', one_smul] theorem fourierCoeff.const_smul (f : AddCircle T → E) (c : ℂ) (n : ℤ) : fourierCoeff (c • f :) n = c • fourierCoeff f n := by simp_rw [fourierCoeff, Pi.smul_apply, ← smul_assoc, smul_eq_mul, mul_comm, ← smul_eq_mul, smul_assoc, integral_smul] theorem fourierCoeff.const_mul (f : AddCircle T → ℂ) (c : ℂ) (n : ℤ) : fourierCoeff (fun x => c * f x) n = c * fourierCoeff f n := fourierCoeff.const_smul f c n /-- For a function on `ℝ`, the Fourier coefficients of `f` on `[a, b]` are defined as the Fourier coefficients of the unique periodic function agreeing with `f` on `Ioc a b`. -/ def fourierCoeffOn {a b : ℝ} (hab : a < b) (f : ℝ → E) (n : ℤ) : E := haveI := Fact.mk (by linarith : 0 < b - a) fourierCoeff (AddCircle.liftIoc (b - a) a f) n theorem fourierCoeffOn_eq_integral {a b : ℝ} (f : ℝ → E) (n : ℤ) (hab : a < b) : fourierCoeffOn hab f n = (1 / (b - a)) • ∫ x in a..b, fourier (-n) (x : AddCircle (b - a)) • f x := by haveI := Fact.mk (by linarith : 0 < b - a) rw [fourierCoeffOn, fourierCoeff_eq_intervalIntegral _ _ a, add_sub, add_sub_cancel_left] congr 1 simp_rw [intervalIntegral.integral_of_le hab.le] refine setIntegral_congr_fun measurableSet_Ioc fun x hx => ?_ rw [liftIoc_coe_apply] rwa [add_sub, add_sub_cancel_left] theorem fourierCoeffOn.const_smul {a b : ℝ} (f : ℝ → E) (c : ℂ) (n : ℤ) (hab : a < b) : fourierCoeffOn hab (c • f) n = c • fourierCoeffOn hab f n := by haveI := Fact.mk (by linarith : 0 < b - a) apply fourierCoeff.const_smul theorem fourierCoeffOn.const_mul {a b : ℝ} (f : ℝ → ℂ) (c : ℂ) (n : ℤ) (hab : a < b) : fourierCoeffOn hab (fun x => c * f x) n = c * fourierCoeffOn hab f n := fourierCoeffOn.const_smul _ _ _ _ theorem fourierCoeff_liftIoc_eq {a : ℝ} (f : ℝ → ℂ) (n : ℤ) : fourierCoeff (AddCircle.liftIoc T a f) n = fourierCoeffOn (lt_add_of_pos_right a hT.out) f n := by rw [fourierCoeffOn_eq_integral, fourierCoeff_eq_intervalIntegral, add_sub_cancel_left a T] · congr 1 refine intervalIntegral.integral_congr_ae (ae_of_all _ fun x hx => ?_) rw [liftIoc_coe_apply] rwa [uIoc_of_le (lt_add_of_pos_right a hT.out).le] at hx theorem fourierCoeff_liftIco_eq {a : ℝ} (f : ℝ → ℂ) (n : ℤ) : fourierCoeff (AddCircle.liftIco T a f) n =
fourierCoeffOn (lt_add_of_pos_right a hT.out) f n := by rw [fourierCoeffOn_eq_integral, fourierCoeff_eq_intervalIntegral _ _ a, add_sub_cancel_left a T] congr 1 simp_rw [intervalIntegral.integral_of_le (lt_add_of_pos_right a hT.out).le] iterate 2 rw [integral_Ioc_eq_integral_Ioo] refine setIntegral_congr_fun measurableSet_Ioo fun x hx => ?_ rw [liftIco_coe_apply (Ioo_subset_Ico_self hx)] end fourierCoeff
Mathlib/Analysis/Fourier/AddCircle.lean
344
353
/- 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.Topology.Homeomorph.Lemmas import Mathlib.Topology.Sets.Closeds /-! # Noetherian space A Noetherian space is a topological space that satisfies any of the following equivalent conditions: - `WellFounded ((· > ·) : TopologicalSpace.Opens α → TopologicalSpace.Opens α → Prop)` - `WellFounded ((· < ·) : TopologicalSpace.Closeds α → TopologicalSpace.Closeds α → Prop)` - `∀ s : Set α, IsCompact s` - `∀ s : TopologicalSpace.Opens α, IsCompact s` The first is chosen as the definition, and the equivalence is shown in `TopologicalSpace.noetherianSpace_TFAE`. Many examples of noetherian spaces come from algebraic topology. For example, the underlying space of a noetherian scheme (e.g., the spectrum of a noetherian ring) is noetherian. ## Main Results - `TopologicalSpace.NoetherianSpace.set`: Every subspace of a noetherian space is noetherian. - `TopologicalSpace.NoetherianSpace.isCompact`: Every set in a noetherian space is a compact set. - `TopologicalSpace.noetherianSpace_TFAE`: Describes the equivalent definitions of noetherian spaces. - `TopologicalSpace.NoetherianSpace.range`: The image of a noetherian space under a continuous map is noetherian. - `TopologicalSpace.NoetherianSpace.iUnion`: The finite union of noetherian spaces is noetherian. - `TopologicalSpace.NoetherianSpace.discrete`: A noetherian and Hausdorff space is discrete. - `TopologicalSpace.NoetherianSpace.exists_finset_irreducible`: Every closed subset of a noetherian space is a finite union of irreducible closed subsets. - `TopologicalSpace.NoetherianSpace.finite_irreducibleComponents`: The number of irreducible components of a noetherian space is finite. -/ open Topology variable (α β : Type*) [TopologicalSpace α] [TopologicalSpace β] namespace TopologicalSpace /-- Type class for noetherian spaces. It is defined to be spaces whose open sets satisfies ACC. -/ abbrev NoetherianSpace : Prop := WellFoundedGT (Opens α) theorem noetherianSpace_iff_opens : NoetherianSpace α ↔ ∀ s : Opens α, IsCompact (s : Set α) := by rw [NoetherianSpace, CompleteLattice.wellFoundedGT_iff_isSupFiniteCompact, CompleteLattice.isSupFiniteCompact_iff_all_elements_compact]
exact forall_congr' Opens.isCompactElement_iff instance (priority := 100) NoetherianSpace.compactSpace [h : NoetherianSpace α] : CompactSpace α := ⟨(noetherianSpace_iff_opens α).mp h ⊤⟩
Mathlib/Topology/NoetherianSpace.lean
53
56
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Johannes Hölzl -/ import Mathlib.Order.ConditionallyCompleteLattice.Basic import Mathlib.Order.RelIso.Basic /-! # Order continuity We say that a function is *left order continuous* if it sends all least upper bounds to least upper bounds. The order dual notion is called *right order continuity*. For monotone functions `ℝ → ℝ` these notions correspond to the usual left and right continuity. We prove some basic lemmas (`map_sup`, `map_sSup` etc) and prove that a `RelIso` is both left and right order continuous. -/ universe u v w x variable {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x} open Function OrderDual Set /-! ### Definitions -/ /-- A function `f` between preorders is left order continuous if it preserves all suprema. We define it using `IsLUB` instead of `sSup` so that the proof works both for complete lattices and conditionally complete lattices. -/ def LeftOrdContinuous [Preorder α] [Preorder β] (f : α → β) := ∀ ⦃s : Set α⦄ ⦃x⦄, IsLUB s x → IsLUB (f '' s) (f x) /-- A function `f` between preorders is right order continuous if it preserves all infima. We define it using `IsGLB` instead of `sInf` so that the proof works both for complete lattices and conditionally complete lattices. -/ def RightOrdContinuous [Preorder α] [Preorder β] (f : α → β) := ∀ ⦃s : Set α⦄ ⦃x⦄, IsGLB s x → IsGLB (f '' s) (f x) namespace LeftOrdContinuous section Preorder variable (α) [Preorder α] [Preorder β] [Preorder γ] {g : β → γ} {f : α → β} protected theorem id : LeftOrdContinuous (id : α → α) := fun s x h => by simpa only [image_id] using h variable {α} protected theorem rightOrdContinuous_dual : LeftOrdContinuous f → RightOrdContinuous (toDual ∘ f ∘ ofDual) := id @[deprecated (since := "2025-04-08")] protected alias order_dual := LeftOrdContinuous.rightOrdContinuous_dual theorem map_isGreatest (hf : LeftOrdContinuous f) {s : Set α} {x : α} (h : IsGreatest s x) : IsGreatest (f '' s) (f x) := ⟨mem_image_of_mem f h.1, (hf h.isLUB).1⟩ theorem mono (hf : LeftOrdContinuous f) : Monotone f := fun a₁ a₂ h => have : IsGreatest {a₁, a₂} a₂ := ⟨Or.inr rfl, by simp [*]⟩ (hf.map_isGreatest this).2 <| mem_image_of_mem _ (Or.inl rfl) theorem comp (hg : LeftOrdContinuous g) (hf : LeftOrdContinuous f) : LeftOrdContinuous (g ∘ f) := fun s x h => by simpa only [image_image] using hg (hf h) protected theorem iterate {f : α → α} (hf : LeftOrdContinuous f) (n : ℕ) : LeftOrdContinuous f^[n] :=
match n with | 0 => LeftOrdContinuous.id α
Mathlib/Order/OrdContinuous.lean
76
77
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.Data.Bool.Basic import Mathlib.Order.Monotone.Basic import Mathlib.Order.ULift import Mathlib.Tactic.GCongr.CoreAttrs /-! # (Semi-)lattices Semilattices are partially ordered sets with join (least upper bound, or `sup`) or meet (greatest lower bound, or `inf`) operations. Lattices are posets that are both join-semilattices and meet-semilattices. Distributive lattices are lattices which satisfy any of four equivalent distributivity properties, of `sup` over `inf`, on the left or on the right. ## Main declarations * `SemilatticeSup`: a type class for join semilattices * `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `⊔` is commutative, associative and idempotent. * `SemilatticeInf`: a type class for meet semilattices * `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `⊓` is commutative, associative and idempotent. * `Lattice`: a type class for lattices * `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `⊔` and `⊓` are commutative, associative and satisfy a pair of "absorption laws". * `DistribLattice`: a type class for distributive lattices. ## Notations * `a ⊔ b`: the supremum or join of `a` and `b` * `a ⊓ b`: the infimum or meet of `a` and `b` ## TODO * (Semi-)lattice homomorphisms * Alternative constructors for distributive lattices from the other distributive properties ## Tags semilattice, lattice -/ /-- See if the term is `a ⊂ b` and the goal is `a ⊆ b`. -/ @[gcongr_forward] def exactSubsetOfSSubset : Mathlib.Tactic.GCongr.ForwardExt where eval h goal := do goal.assignIfDefEq (← Lean.Meta.mkAppM ``subset_of_ssubset #[h]) universe u v w variable {α : Type u} {β : Type v} /-! ### Join-semilattices -/ -- TODO: automatic construction of dual definitions / theorems /-- A `SemilatticeSup` is a join-semilattice, that is, a partial order with a join (a.k.a. lub / least upper bound, sup / supremum) operation `⊔` which is the least element larger than both factors. -/ class SemilatticeSup (α : Type u) extends PartialOrder α where /-- The binary supremum, used to derive `Max α` -/ sup : α → α → α /-- The supremum is an upper bound on the first argument -/ protected le_sup_left : ∀ a b : α, a ≤ sup a b /-- The supremum is an upper bound on the second argument -/ protected le_sup_right : ∀ a b : α, b ≤ sup a b /-- The supremum is the *least* upper bound -/ protected sup_le : ∀ a b c : α, a ≤ c → b ≤ c → sup a b ≤ c instance SemilatticeSup.toMax [SemilatticeSup α] : Max α where max a b := SemilatticeSup.sup a b /-- A type with a commutative, associative and idempotent binary `sup` operation has the structure of a join-semilattice. The partial order is defined so that `a ≤ b` unfolds to `a ⊔ b = b`; cf. `sup_eq_right`. -/ def SemilatticeSup.mk' {α : Type*} [Max α] (sup_comm : ∀ a b : α, a ⊔ b = b ⊔ a) (sup_assoc : ∀ a b c : α, a ⊔ b ⊔ c = a ⊔ (b ⊔ c)) (sup_idem : ∀ a : α, a ⊔ a = a) : SemilatticeSup α where sup := (· ⊔ ·) le a b := a ⊔ b = b le_refl := sup_idem le_trans a b c hab hbc := by rw [← hbc, ← sup_assoc, hab] le_antisymm a b hab hba := by rwa [← hba, sup_comm] le_sup_left a b := by rw [← sup_assoc, sup_idem] le_sup_right a b := by rw [sup_comm, sup_assoc, sup_idem] sup_le a b c hac hbc := by rwa [sup_assoc, hbc] section SemilatticeSup variable [SemilatticeSup α] {a b c d : α} @[simp] theorem le_sup_left : a ≤ a ⊔ b := SemilatticeSup.le_sup_left a b @[simp] theorem le_sup_right : b ≤ a ⊔ b := SemilatticeSup.le_sup_right a b theorem le_sup_of_le_left (h : c ≤ a) : c ≤ a ⊔ b := le_trans h le_sup_left theorem le_sup_of_le_right (h : c ≤ b) : c ≤ a ⊔ b := le_trans h le_sup_right theorem lt_sup_of_lt_left (h : c < a) : c < a ⊔ b := h.trans_le le_sup_left theorem lt_sup_of_lt_right (h : c < b) : c < a ⊔ b := h.trans_le le_sup_right theorem sup_le : a ≤ c → b ≤ c → a ⊔ b ≤ c := SemilatticeSup.sup_le a b c @[simp] theorem sup_le_iff : a ⊔ b ≤ c ↔ a ≤ c ∧ b ≤ c := ⟨fun h : a ⊔ b ≤ c => ⟨le_trans le_sup_left h, le_trans le_sup_right h⟩, fun ⟨h₁, h₂⟩ => sup_le h₁ h₂⟩ @[simp] theorem sup_eq_left : a ⊔ b = a ↔ b ≤ a := le_antisymm_iff.trans <| by simp [le_rfl] @[simp] theorem sup_eq_right : a ⊔ b = b ↔ a ≤ b := le_antisymm_iff.trans <| by simp [le_rfl] @[simp] theorem left_eq_sup : a = a ⊔ b ↔ b ≤ a := eq_comm.trans sup_eq_left @[simp] theorem right_eq_sup : b = a ⊔ b ↔ a ≤ b := eq_comm.trans sup_eq_right alias ⟨_, sup_of_le_left⟩ := sup_eq_left alias ⟨le_of_sup_eq, sup_of_le_right⟩ := sup_eq_right attribute [simp] sup_of_le_left sup_of_le_right @[simp] theorem left_lt_sup : a < a ⊔ b ↔ ¬b ≤ a := le_sup_left.lt_iff_ne.trans <| not_congr left_eq_sup @[simp] theorem right_lt_sup : b < a ⊔ b ↔ ¬a ≤ b := le_sup_right.lt_iff_ne.trans <| not_congr right_eq_sup theorem left_or_right_lt_sup (h : a ≠ b) : a < a ⊔ b ∨ b < a ⊔ b := h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2 theorem le_iff_exists_sup : a ≤ b ↔ ∃ c, b = a ⊔ c := by constructor · intro h exact ⟨b, (sup_eq_right.mpr h).symm⟩ · rintro ⟨c, rfl : _ = _ ⊔ _⟩ exact le_sup_left @[gcongr] theorem sup_le_sup (h₁ : a ≤ b) (h₂ : c ≤ d) : a ⊔ c ≤ b ⊔ d := sup_le (le_sup_of_le_left h₁) (le_sup_of_le_right h₂) @[gcongr] theorem sup_le_sup_left (h₁ : a ≤ b) (c) : c ⊔ a ≤ c ⊔ b := sup_le_sup le_rfl h₁ @[gcongr] theorem sup_le_sup_right (h₁ : a ≤ b) (c) : a ⊔ c ≤ b ⊔ c := sup_le_sup h₁ le_rfl theorem sup_idem (a : α) : a ⊔ a = a := by simp instance : Std.IdempotentOp (α := α) (· ⊔ ·) := ⟨sup_idem⟩ theorem sup_comm (a b : α) : a ⊔ b = b ⊔ a := by apply le_antisymm <;> simp instance : Std.Commutative (α := α) (· ⊔ ·) := ⟨sup_comm⟩ theorem sup_assoc (a b c : α) : a ⊔ b ⊔ c = a ⊔ (b ⊔ c) := eq_of_forall_ge_iff fun x => by simp only [sup_le_iff]; rw [and_assoc] instance : Std.Associative (α := α) (· ⊔ ·) := ⟨sup_assoc⟩ theorem sup_left_right_swap (a b c : α) : a ⊔ b ⊔ c = c ⊔ b ⊔ a := by rw [sup_comm, sup_comm a, sup_assoc] theorem sup_left_idem (a b : α) : a ⊔ (a ⊔ b) = a ⊔ b := by simp theorem sup_right_idem (a b : α) : a ⊔ b ⊔ b = a ⊔ b := by simp theorem sup_left_comm (a b c : α) : a ⊔ (b ⊔ c) = b ⊔ (a ⊔ c) := by rw [← sup_assoc, ← sup_assoc, @sup_comm α _ a] theorem sup_right_comm (a b c : α) : a ⊔ b ⊔ c = a ⊔ c ⊔ b := by rw [sup_assoc, sup_assoc, sup_comm b] theorem sup_sup_sup_comm (a b c d : α) : a ⊔ b ⊔ (c ⊔ d) = a ⊔ c ⊔ (b ⊔ d) := by rw [sup_assoc, sup_left_comm b, ← sup_assoc] theorem sup_sup_distrib_left (a b c : α) : a ⊔ (b ⊔ c) = a ⊔ b ⊔ (a ⊔ c) := by rw [sup_sup_sup_comm, sup_idem] theorem sup_sup_distrib_right (a b c : α) : a ⊔ b ⊔ c = a ⊔ c ⊔ (b ⊔ c) := by rw [sup_sup_sup_comm, sup_idem] theorem sup_congr_left (hb : b ≤ a ⊔ c) (hc : c ≤ a ⊔ b) : a ⊔ b = a ⊔ c := (sup_le le_sup_left hb).antisymm <| sup_le le_sup_left hc theorem sup_congr_right (ha : a ≤ b ⊔ c) (hb : b ≤ a ⊔ c) : a ⊔ c = b ⊔ c := (sup_le ha le_sup_right).antisymm <| sup_le hb le_sup_right theorem sup_eq_sup_iff_left : a ⊔ b = a ⊔ c ↔ b ≤ a ⊔ c ∧ c ≤ a ⊔ b := ⟨fun h => ⟨h ▸ le_sup_right, h.symm ▸ le_sup_right⟩, fun h => sup_congr_left h.1 h.2⟩ theorem sup_eq_sup_iff_right : a ⊔ c = b ⊔ c ↔ a ≤ b ⊔ c ∧ b ≤ a ⊔ c := ⟨fun h => ⟨h ▸ le_sup_left, h.symm ▸ le_sup_left⟩, fun h => sup_congr_right h.1 h.2⟩ theorem Ne.lt_sup_or_lt_sup (hab : a ≠ b) : a < a ⊔ b ∨ b < a ⊔ b := hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2 /-- If `f` is monotone, `g` is antitone, and `f ≤ g`, then for all `a`, `b` we have `f a ≤ g b`. -/ theorem Monotone.forall_le_of_antitone {β : Type*} [Preorder β] {f g : α → β} (hf : Monotone f) (hg : Antitone g) (h : f ≤ g) (m n : α) : f m ≤ g n := calc f m ≤ f (m ⊔ n) := hf le_sup_left _ ≤ g (m ⊔ n) := h _ _ ≤ g n := hg le_sup_right theorem SemilatticeSup.ext_sup {α} {A B : SemilatticeSup α} (H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) (x y : α) : (haveI := A; x ⊔ y) = x ⊔ y := eq_of_forall_ge_iff fun c => by simp only [sup_le_iff]; rw [← H, @sup_le_iff α A, H, H] theorem SemilatticeSup.ext {α} {A B : SemilatticeSup α} (H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) : A = B := by cases A cases B cases PartialOrder.ext H congr ext; apply SemilatticeSup.ext_sup H theorem ite_le_sup (s s' : α) (P : Prop) [Decidable P] : ite P s s' ≤ s ⊔ s' := if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right
end SemilatticeSup
Mathlib/Order/Lattice.lean
257
258
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Mario Carneiro -/ import Mathlib.Algebra.Notation.Prod import Mathlib.Data.Nat.Sqrt import Mathlib.Data.Set.Lattice.Image /-! # Naturals pairing function This file defines a pairing function for the naturals as follows: ```text 0 1 4 9 16 2 3 5 10 17 6 7 8 11 18 12 13 14 15 19 20 21 22 23 24 ``` It has the advantage of being monotone in both directions and sending `⟦0, n^2 - 1⟧` to `⟦0, n - 1⟧²`. -/ assert_not_exists Monoid open Prod Decidable Function namespace Nat /-- Pairing function for the natural numbers. -/ @[pp_nodot] def pair (a b : ℕ) : ℕ := if a < b then b * b + a else a * a + a + b /-- Unpairing function for the natural numbers. -/ @[pp_nodot] def unpair (n : ℕ) : ℕ × ℕ := let s := sqrt n if n - s * s < s then (n - s * s, s) else (s, n - s * s - s) @[simp] theorem pair_unpair (n : ℕ) : pair (unpair n).1 (unpair n).2 = n := by dsimp only [unpair]; let s := sqrt n have sm : s * s + (n - s * s) = n := Nat.add_sub_cancel' (sqrt_le _) split_ifs with h · simp [s, pair, h, sm] · have hl : n - s * s - s ≤ s := Nat.sub_le_iff_le_add.2 (Nat.sub_le_iff_le_add'.2 <| by rw [← Nat.add_assoc]; apply sqrt_le_add) simp [s, pair, hl.not_lt, Nat.add_assoc, Nat.add_sub_cancel' (le_of_not_gt h), sm] theorem pair_unpair' {n a b} (H : unpair n = (a, b)) : pair a b = n := by simpa [H] using pair_unpair n @[simp] theorem unpair_pair (a b : ℕ) : unpair (pair a b) = (a, b) := by dsimp only [pair]; split_ifs with h · show unpair (b * b + a) = (a, b) have be : sqrt (b * b + a) = b := sqrt_add_eq _ (le_trans (le_of_lt h) (Nat.le_add_left _ _)) simp [unpair, be, Nat.add_sub_cancel_left, h]
· show unpair (a * a + a + b) = (a, b) have ae : sqrt (a * a + (a + b)) = a := by rw [sqrt_add_eq] exact Nat.add_le_add_left (le_of_not_gt h) _ simp [unpair, ae, Nat.not_lt_zero, Nat.add_assoc, Nat.add_sub_cancel_left] /-- An equivalence between `ℕ × ℕ` and `ℕ`. -/ @[simps -fullyApplied] def pairEquiv : ℕ × ℕ ≃ ℕ := ⟨uncurry pair, unpair, fun ⟨a, b⟩ => unpair_pair a b, pair_unpair⟩
Mathlib/Data/Nat/Pairing.lean
62
71
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Yury Kudryashov, Kim Morrison -/ import Mathlib.Algebra.Algebra.Equiv import Mathlib.Algebra.Algebra.NonUnitalHom import Mathlib.Algebra.Module.BigOperators import Mathlib.Algebra.MonoidAlgebra.MapDomain import Mathlib.Data.Finsupp.SMul import Mathlib.LinearAlgebra.Finsupp.SumProd /-! # Monoid algebras -/ noncomputable section open Finset open Finsupp hiding single mapDomain universe u₁ u₂ u₃ u₄ variable (k : Type u₁) (G : Type u₂) (H : Type*) {R : Type*} /-! ### Multiplicative monoids -/ namespace MonoidAlgebra variable {k G} /-! #### Non-unital, non-associative algebra structure -/ section NonUnitalNonAssocAlgebra variable (k) [Semiring k] [DistribSMul R k] [Mul G] variable {A : Type u₃} [NonUnitalNonAssocSemiring A] /-- A non_unital `k`-algebra homomorphism from `MonoidAlgebra k G` is uniquely defined by its values on the functions `single a 1`. -/ theorem nonUnitalAlgHom_ext [DistribMulAction k A] {φ₁ φ₂ : MonoidAlgebra k G →ₙₐ[k] A} (h : ∀ x, φ₁ (single x 1) = φ₂ (single x 1)) : φ₁ = φ₂ := NonUnitalAlgHom.to_distribMulActionHom_injective <| Finsupp.distribMulActionHom_ext' fun a => DistribMulActionHom.ext_ring (h a) /-- See note [partially-applied ext lemmas]. -/ @[ext high] theorem nonUnitalAlgHom_ext' [DistribMulAction k A] {φ₁ φ₂ : MonoidAlgebra k G →ₙₐ[k] A} (h : φ₁.toMulHom.comp (ofMagma k G) = φ₂.toMulHom.comp (ofMagma k G)) : φ₁ = φ₂ := nonUnitalAlgHom_ext k <| DFunLike.congr_fun h /-- The functor `G ↦ MonoidAlgebra k G`, from the category of magmas to the category of non-unital, non-associative algebras over `k` is adjoint to the forgetful functor in the other direction. -/ @[simps apply_apply symm_apply] def liftMagma [Module k A] [IsScalarTower k A A] [SMulCommClass k A A] : (G →ₙ* A) ≃ (MonoidAlgebra k G →ₙₐ[k] A) where toFun f := { liftAddHom fun x => (smulAddHom k A).flip (f x) with toFun := fun a => a.sum fun m t => t • f m map_smul' := fun t' a => by rw [Finsupp.smul_sum, sum_smul_index'] · simp_rw [smul_assoc, MonoidHom.id_apply] · intro m exact zero_smul k (f m) map_mul' := fun a₁ a₂ => by let g : G → k → A := fun m t => t • f m have h₁ : ∀ m, g m 0 = 0 := by intro m exact zero_smul k (f m) have h₂ : ∀ (m) (t₁ t₂ : k), g m (t₁ + t₂) = g m t₁ + g m t₂ := by intros rw [← add_smul] -- Porting note: `reducible` cannot be `local` so proof gets long. simp_rw [Finsupp.mul_sum, Finsupp.sum_mul, smul_mul_smul_comm, ← f.map_mul, mul_def, sum_comm a₂ a₁] rw [sum_sum_index h₁ h₂]; congr; ext rw [sum_sum_index h₁ h₂]; congr; ext rw [sum_single_index (h₁ _)] } invFun F := F.toMulHom.comp (ofMagma k G) left_inv f := by ext m simp only [NonUnitalAlgHom.coe_mk, ofMagma_apply, NonUnitalAlgHom.toMulHom_eq_coe, sum_single_index, Function.comp_apply, one_smul, zero_smul, MulHom.coe_comp, NonUnitalAlgHom.coe_to_mulHom] right_inv F := by ext m simp only [NonUnitalAlgHom.coe_mk, ofMagma_apply, NonUnitalAlgHom.toMulHom_eq_coe, sum_single_index, Function.comp_apply, one_smul, zero_smul, MulHom.coe_comp, NonUnitalAlgHom.coe_to_mulHom] end NonUnitalNonAssocAlgebra /-! #### Algebra structure -/ section Algebra /-- The instance `Algebra k (MonoidAlgebra A G)` whenever we have `Algebra k A`. In particular this provides the instance `Algebra k (MonoidAlgebra k G)`. -/ instance algebra {A : Type*} [CommSemiring k] [Semiring A] [Algebra k A] [Monoid G] : Algebra k (MonoidAlgebra A G) where algebraMap := singleOneRingHom.comp (algebraMap k A) smul_def' := fun r a => by ext rw [Finsupp.coe_smul] simp [single_one_mul_apply, Algebra.smul_def, Pi.smul_apply] commutes' := fun r f => by refine Finsupp.ext fun _ => ?_ simp [single_one_mul_apply, mul_single_one_apply, Algebra.commutes] /-- `Finsupp.single 1` as an `AlgHom` -/ @[simps! apply] def singleOneAlgHom {A : Type*} [CommSemiring k] [Semiring A] [Algebra k A] [Monoid G] : A →ₐ[k] MonoidAlgebra A G := { singleOneRingHom with commutes' := fun r => by ext simp rfl } @[simp] theorem coe_algebraMap {A : Type*} [CommSemiring k] [Semiring A] [Algebra k A] [Monoid G] : ⇑(algebraMap k (MonoidAlgebra A G)) = single 1 ∘ algebraMap k A := rfl theorem single_eq_algebraMap_mul_of [CommSemiring k] [Monoid G] (a : G) (b : k) : single a b = algebraMap k (MonoidAlgebra k G) b * of k G a := by simp theorem single_algebraMap_eq_algebraMap_mul_of {A : Type*} [CommSemiring k] [Semiring A] [Algebra k A] [Monoid G] (a : G) (b : k) : single a (algebraMap k A b) = algebraMap k (MonoidAlgebra A G) b * of A G a := by simp instance isLocalHom_singleOneAlgHom {A : Type*} [CommSemiring k] [Semiring A] [Algebra k A] [Monoid G] : IsLocalHom (singleOneAlgHom : A →ₐ[k] MonoidAlgebra A G) where map_nonunit := isLocalHom_singleOneRingHom.map_nonunit instance isLocalHom_algebraMap {A : Type*} [CommSemiring k] [Semiring A] [Algebra k A] [Monoid G] [IsLocalHom (algebraMap k A)] : IsLocalHom (algebraMap k (MonoidAlgebra A G)) where map_nonunit _ hx := .of_map _ _ <| isLocalHom_singleOneAlgHom (k := k).map_nonunit _ hx end Algebra section lift variable [CommSemiring k] [Monoid G] [Monoid H] variable {A : Type u₃} [Semiring A] [Algebra k A] {B : Type*} [Semiring B] [Algebra k B] /-- `liftNCRingHom` as an `AlgHom`, for when `f` is an `AlgHom` -/ def liftNCAlgHom (f : A →ₐ[k] B) (g : G →* B) (h_comm : ∀ x y, Commute (f x) (g y)) : MonoidAlgebra A G →ₐ[k] B := { liftNCRingHom (f : A →+* B) g h_comm with commutes' := by simp [liftNCRingHom] } /-- A `k`-algebra homomorphism from `MonoidAlgebra k G` is uniquely defined by its values on the functions `single a 1`. -/ theorem algHom_ext ⦃φ₁ φ₂ : MonoidAlgebra k G →ₐ[k] A⦄ (h : ∀ x, φ₁ (single x 1) = φ₂ (single x 1)) : φ₁ = φ₂ := AlgHom.toLinearMap_injective <| Finsupp.lhom_ext' fun a => LinearMap.ext_ring (h a) -- The priority must be `high`. /-- See note [partially-applied ext lemmas]. -/ @[ext high] theorem algHom_ext' ⦃φ₁ φ₂ : MonoidAlgebra k G →ₐ[k] A⦄ (h : (φ₁ : MonoidAlgebra k G →* A).comp (of k G) = (φ₂ : MonoidAlgebra k G →* A).comp (of k G)) : φ₁ = φ₂ := algHom_ext <| DFunLike.congr_fun h variable (k G A) /-- Any monoid homomorphism `G →* A` can be lifted to an algebra homomorphism `MonoidAlgebra k G →ₐ[k] A`. -/ def lift : (G →* A) ≃ (MonoidAlgebra k G →ₐ[k] A) where invFun f := (f : MonoidAlgebra k G →* A).comp (of k G) toFun F := liftNCAlgHom (Algebra.ofId k A) F fun _ _ => Algebra.commutes _ _ left_inv f := by ext simp [liftNCAlgHom, liftNCRingHom] right_inv F := by ext simp [liftNCAlgHom, liftNCRingHom] variable {k G H A} theorem lift_apply' (F : G →* A) (f : MonoidAlgebra k G) : lift k G A F f = f.sum fun a b => algebraMap k A b * F a := rfl theorem lift_apply (F : G →* A) (f : MonoidAlgebra k G) : lift k G A F f = f.sum fun a b => b • F a := by simp only [lift_apply', Algebra.smul_def] theorem lift_def (F : G →* A) : ⇑(lift k G A F) = liftNC ((algebraMap k A : k →+* A) : k →+ A) F := rfl @[simp] theorem lift_symm_apply (F : MonoidAlgebra k G →ₐ[k] A) (x : G) : (lift k G A).symm F x = F (single x 1) := rfl @[simp] theorem lift_single (F : G →* A) (a b) : lift k G A F (single a b) = b • F a := by rw [lift_def, liftNC_single, Algebra.smul_def, AddMonoidHom.coe_coe] theorem lift_of (F : G →* A) (x) : lift k G A F (of k G x) = F x := by simp theorem lift_unique' (F : MonoidAlgebra k G →ₐ[k] A) : F = lift k G A ((F : MonoidAlgebra k G →* A).comp (of k G)) := ((lift k G A).apply_symm_apply F).symm /-- Decomposition of a `k`-algebra homomorphism from `MonoidAlgebra k G` by its values on `F (single a 1)`. -/ theorem lift_unique (F : MonoidAlgebra k G →ₐ[k] A) (f : MonoidAlgebra k G) : F f = f.sum fun a b => b • F (single a 1) := by conv_lhs => rw [lift_unique' F] simp [lift_apply] /-- If `f : G → H` is a homomorphism between two magmas, then `Finsupp.mapDomain f` is a non-unital algebra homomorphism between their magma algebras. -/ @[simps apply] def mapDomainNonUnitalAlgHom (k A : Type*) [CommSemiring k] [Semiring A] [Algebra k A] {G H F : Type*} [Mul G] [Mul H] [FunLike F G H] [MulHomClass F G H] (f : F) : MonoidAlgebra A G →ₙₐ[k] MonoidAlgebra A H := { (Finsupp.mapDomain.addMonoidHom f : MonoidAlgebra A G →+ MonoidAlgebra A H) with map_mul' := fun x y => mapDomain_mul f x y map_smul' := fun r x => mapDomain_smul r x } variable (A) in theorem mapDomain_algebraMap {F : Type*} [FunLike F G H] [MonoidHomClass F G H] (f : F) (r : k) : mapDomain f (algebraMap k (MonoidAlgebra A G) r) = algebraMap k (MonoidAlgebra A H) r := by simp only [coe_algebraMap, mapDomain_single, map_one, (· ∘ ·)] /-- If `f : G → H` is a multiplicative homomorphism between two monoids, then `Finsupp.mapDomain f` is an algebra homomorphism between their monoid algebras. -/ @[simps!] def mapDomainAlgHom (k A : Type*) [CommSemiring k] [Semiring A] [Algebra k A] {H F : Type*} [Monoid H] [FunLike F G H] [MonoidHomClass F G H] (f : F) : MonoidAlgebra A G →ₐ[k] MonoidAlgebra A H := { mapDomainRingHom A f with commutes' := mapDomain_algebraMap A f } @[simp] lemma mapDomainAlgHom_id (k A) [CommSemiring k] [Semiring A] [Algebra k A] : mapDomainAlgHom k A (MonoidHom.id G) = AlgHom.id k (MonoidAlgebra A G) := by ext; simp [MonoidHom.id, ← Function.id_def] @[simp] lemma mapDomainAlgHom_comp (k A) {G₁ G₂ G₃} [CommSemiring k] [Semiring A] [Algebra k A] [Monoid G₁] [Monoid G₂] [Monoid G₃] (f : G₁ →* G₂) (g : G₂ →* G₃) : mapDomainAlgHom k A (g.comp f) = (mapDomainAlgHom k A g).comp (mapDomainAlgHom k A f) := by ext; simp [mapDomain_comp] variable (k A) /-- If `e : G ≃* H` is a multiplicative equivalence between two monoids, then `MonoidAlgebra.domCongr e` is an algebra equivalence between their monoid algebras. -/ def domCongr (e : G ≃* H) : MonoidAlgebra A G ≃ₐ[k] MonoidAlgebra A H := AlgEquiv.ofLinearEquiv (Finsupp.domLCongr e : (G →₀ A) ≃ₗ[k] (H →₀ A)) ((equivMapDomain_eq_mapDomain _ _).trans <| mapDomain_one e) (fun f g => (equivMapDomain_eq_mapDomain _ _).trans <| (mapDomain_mul e f g).trans <| congr_arg₂ _ (equivMapDomain_eq_mapDomain _ _).symm (equivMapDomain_eq_mapDomain _ _).symm) theorem domCongr_toAlgHom (e : G ≃* H) : (domCongr k A e).toAlgHom = mapDomainAlgHom k A e := AlgHom.ext fun _ => equivMapDomain_eq_mapDomain _ _ @[simp] theorem domCongr_apply (e : G ≃* H) (f : MonoidAlgebra A G) (h : H) : domCongr k A e f h = f (e.symm h) := rfl @[simp] theorem domCongr_support (e : G ≃* H) (f : MonoidAlgebra A G) : (domCongr k A e f).support = f.support.map e := rfl @[simp] theorem domCongr_single (e : G ≃* H) (g : G) (a : A) : domCongr k A e (single g a) = single (e g) a := Finsupp.equivMapDomain_single _ _ _ @[simp] theorem domCongr_refl : domCongr k A (MulEquiv.refl G) = AlgEquiv.refl := AlgEquiv.ext fun _ => Finsupp.ext fun _ => rfl @[simp] theorem domCongr_symm (e : G ≃* H) : (domCongr k A e).symm = domCongr k A e.symm := rfl end lift section variable (k) /-- When `V` is a `k[G]`-module, multiplication by a group element `g` is a `k`-linear map. -/ def GroupSMul.linearMap [Monoid G] [CommSemiring k] (V : Type u₃) [AddCommMonoid V] [Module k V] [Module (MonoidAlgebra k G) V] [IsScalarTower k (MonoidAlgebra k G) V] (g : G) : V →ₗ[k] V where toFun v := single g (1 : k) • v map_add' x y := smul_add (single g (1 : k)) x y map_smul' _c _x := smul_algebra_smul_comm _ _ _ @[simp] theorem GroupSMul.linearMap_apply [Monoid G] [CommSemiring k] (V : Type u₃) [AddCommMonoid V] [Module k V] [Module (MonoidAlgebra k G) V] [IsScalarTower k (MonoidAlgebra k G) V] (g : G) (v : V) : (GroupSMul.linearMap k V g) v = single g (1 : k) • v := rfl section variable {k} variable [Monoid G] [CommSemiring k] {V : Type u₃} {W : Type u₄} [AddCommMonoid V] [Module k V] [Module (MonoidAlgebra k G) V] [IsScalarTower k (MonoidAlgebra k G) V] [AddCommMonoid W] [Module k W] [Module (MonoidAlgebra k G) W] [IsScalarTower k (MonoidAlgebra k G) W] (f : V →ₗ[k] W) /-- Build a `k[G]`-linear map from a `k`-linear map and evidence that it is `G`-equivariant. -/ def equivariantOfLinearOfComm (h : ∀ (g : G) (v : V), f (single g (1 : k) • v) = single g (1 : k) • f v) : V →ₗ[MonoidAlgebra k G] W where toFun := f map_add' v v' := by simp map_smul' c v := by refine Finsupp.induction c ?_ ?_ · simp · intro g r c' _nm _nz w dsimp at * simp only [add_smul, f.map_add, w, add_left_inj, single_eq_algebraMap_mul_of, ← smul_smul] rw [algebraMap_smul (MonoidAlgebra k G) r, algebraMap_smul (MonoidAlgebra k G) r, f.map_smul, of_apply, h g v] variable (h : ∀ (g : G) (v : V), f (single g (1 : k) • v) = single g (1 : k) • f v) @[simp] theorem equivariantOfLinearOfComm_apply (v : V) : (equivariantOfLinearOfComm f h) v = f v := rfl end end end MonoidAlgebra namespace AddMonoidAlgebra variable {k G H} /-! #### Non-unital, non-associative algebra structure -/ section NonUnitalNonAssocAlgebra variable (k) [Semiring k] [DistribSMul R k] [Add G] variable {A : Type u₃} [NonUnitalNonAssocSemiring A] /-- A non_unital `k`-algebra homomorphism from `k[G]` is uniquely defined by its values on the functions `single a 1`. -/ theorem nonUnitalAlgHom_ext [DistribMulAction k A] {φ₁ φ₂ : k[G] →ₙₐ[k] A} (h : ∀ x, φ₁ (single x 1) = φ₂ (single x 1)) : φ₁ = φ₂ := @MonoidAlgebra.nonUnitalAlgHom_ext k (Multiplicative G) _ _ _ _ _ φ₁ φ₂ h /-- See note [partially-applied ext lemmas]. -/ @[ext high] theorem nonUnitalAlgHom_ext' [DistribMulAction k A] {φ₁ φ₂ : k[G] →ₙₐ[k] A} (h : φ₁.toMulHom.comp (ofMagma k G) = φ₂.toMulHom.comp (ofMagma k G)) : φ₁ = φ₂ := @MonoidAlgebra.nonUnitalAlgHom_ext' k (Multiplicative G) _ _ _ _ _ φ₁ φ₂ h /-- The functor `G ↦ k[G]`, from the category of magmas to the category of non-unital, non-associative algebras over `k` is adjoint to the forgetful functor in the other direction. -/ @[simps apply_apply symm_apply] def liftMagma [Module k A] [IsScalarTower k A A] [SMulCommClass k A A] : (Multiplicative G →ₙ* A) ≃ (k[G] →ₙₐ[k] A) := { (MonoidAlgebra.liftMagma k : (Multiplicative G →ₙ* A) ≃ (_ →ₙₐ[k] A)) with toFun := fun f => { (MonoidAlgebra.liftMagma k f :) with toFun := fun a => sum a fun m t => t • f (Multiplicative.ofAdd m) } invFun := fun F => F.toMulHom.comp (ofMagma k G) } end NonUnitalNonAssocAlgebra /-! #### Algebra structure -/ section Algebra /-- The instance `Algebra R k[G]` whenever we have `Algebra R k`. In particular this provides the instance `Algebra k k[G]`. -/ instance algebra [CommSemiring R] [Semiring k] [Algebra R k] [AddMonoid G] : Algebra R k[G] where algebraMap := singleZeroRingHom.comp (algebraMap R k) smul_def' := fun r a => by ext rw [Finsupp.coe_smul] simp [single_zero_mul_apply, Algebra.smul_def, Pi.smul_apply] commutes' := fun r f => by refine Finsupp.ext fun _ => ?_ simp [single_zero_mul_apply, mul_single_zero_apply, Algebra.commutes] /-- `Finsupp.single 0` as an `AlgHom` -/ @[simps! apply] def singleZeroAlgHom [CommSemiring R] [Semiring k] [Algebra R k] [AddMonoid G] : k →ₐ[R] k[G] := { singleZeroRingHom with commutes' := fun r => by ext simp rfl } @[simp] theorem coe_algebraMap [CommSemiring R] [Semiring k] [Algebra R k] [AddMonoid G] : (algebraMap R k[G] : R → k[G]) = single 0 ∘ algebraMap R k := rfl instance isLocalHom_singleZeroAlgHom [CommSemiring R] [Semiring k] [Algebra R k] [AddMonoid G] : IsLocalHom (singleZeroAlgHom : k →ₐ[R] k[G]) where map_nonunit := isLocalHom_singleZeroRingHom.map_nonunit instance isLocalHom_algebraMap [CommSemiring R] [Semiring k] [Algebra R k] [AddMonoid G] [IsLocalHom (algebraMap R k)] : IsLocalHom (algebraMap R k[G]) where map_nonunit _ hx := .of_map _ _ <| isLocalHom_singleZeroAlgHom (R := R).map_nonunit _ hx end Algebra section lift variable [CommSemiring k] [AddMonoid G] variable {A : Type u₃} [Semiring A] [Algebra k A] {B : Type*} [Semiring B] [Algebra k B] /-- `liftNCRingHom` as an `AlgHom`, for when `f` is an `AlgHom` -/ def liftNCAlgHom (f : A →ₐ[k] B) (g : Multiplicative G →* B) (h_comm : ∀ x y, Commute (f x) (g y)) : A[G] →ₐ[k] B := { liftNCRingHom (f : A →+* B) g h_comm with commutes' := by simp [liftNCRingHom] } /-- A `k`-algebra homomorphism from `k[G]` is uniquely defined by its values on the functions `single a 1`. -/ theorem algHom_ext ⦃φ₁ φ₂ : k[G] →ₐ[k] A⦄ (h : ∀ x, φ₁ (single x 1) = φ₂ (single x 1)) : φ₁ = φ₂ := @MonoidAlgebra.algHom_ext k (Multiplicative G) _ _ _ _ _ _ _ h /-- See note [partially-applied ext lemmas]. -/ @[ext high] theorem algHom_ext' ⦃φ₁ φ₂ : k[G] →ₐ[k] A⦄ (h : (φ₁ : k[G] →* A).comp (of k G) = (φ₂ : k[G] →* A).comp (of k G)) : φ₁ = φ₂ := algHom_ext <| DFunLike.congr_fun h variable (k G A) /-- Any monoid homomorphism `G →* A` can be lifted to an algebra homomorphism `k[G] →ₐ[k] A`. -/ def lift : (Multiplicative G →* A) ≃ (k[G] →ₐ[k] A) := { @MonoidAlgebra.lift k (Multiplicative G) _ _ A _ _ with invFun := fun f => (f : k[G] →* A).comp (of k G) toFun := fun F => { @MonoidAlgebra.lift k (Multiplicative G) _ _ A _ _ F with toFun := liftNCAlgHom (Algebra.ofId k A) F fun _ _ => Algebra.commutes _ _ } } variable {k G A} theorem lift_apply' (F : Multiplicative G →* A) (f : MonoidAlgebra k G) : lift k G A F f = f.sum fun a b => algebraMap k A b * F (Multiplicative.ofAdd a) := rfl theorem lift_apply (F : Multiplicative G →* A) (f : MonoidAlgebra k G) : lift k G A F f = f.sum fun a b => b • F (Multiplicative.ofAdd a) := by simp only [lift_apply', Algebra.smul_def] theorem lift_def (F : Multiplicative G →* A) : ⇑(lift k G A F) = liftNC ((algebraMap k A : k →+* A) : k →+ A) F := rfl @[simp] theorem lift_symm_apply (F : k[G] →ₐ[k] A) (x : Multiplicative G) : (lift k G A).symm F x = F (single x.toAdd 1) := rfl theorem lift_of (F : Multiplicative G →* A) (x : Multiplicative G) : lift k G A F (of k G x) = F x := MonoidAlgebra.lift_of F x @[simp] theorem lift_single (F : Multiplicative G →* A) (a b) : lift k G A F (single a b) = b • F (Multiplicative.ofAdd a) := MonoidAlgebra.lift_single F (.ofAdd a) b lemma lift_of' (F : Multiplicative G →* A) (x : G) : lift k G A F (of' k G x) = F (Multiplicative.ofAdd x) := lift_of F x theorem lift_unique' (F : k[G] →ₐ[k] A) : F = lift k G A ((F : k[G] →* A).comp (of k G)) := ((lift k G A).apply_symm_apply F).symm /-- Decomposition of a `k`-algebra homomorphism from `MonoidAlgebra k G` by its values on `F (single a 1)`. -/ theorem lift_unique (F : k[G] →ₐ[k] A) (f : MonoidAlgebra k G) : F f = f.sum fun a b => b • F (single a 1) := by conv_lhs => rw [lift_unique' F] simp [lift_apply] theorem algHom_ext_iff {φ₁ φ₂ : k[G] →ₐ[k] A} : (∀ x, φ₁ (Finsupp.single x 1) = φ₂ (Finsupp.single x 1)) ↔ φ₁ = φ₂ := ⟨fun h => algHom_ext h, by rintro rfl _; rfl⟩ end lift theorem mapDomain_algebraMap (A : Type*) {H F : Type*} [CommSemiring k] [Semiring A] [Algebra k A] [AddMonoid G] [AddMonoid H] [FunLike F G H] [AddMonoidHomClass F G H] (f : F) (r : k) : mapDomain f (algebraMap k A[G] r) = algebraMap k A[H] r := by simp only [Function.comp_apply, mapDomain_single, AddMonoidAlgebra.coe_algebraMap, map_zero] /-- If `f : G → H` is a homomorphism between two additive magmas, then `Finsupp.mapDomain f` is a non-unital algebra homomorphism between their additive magma algebras. -/ @[simps apply] def mapDomainNonUnitalAlgHom (k A : Type*) [CommSemiring k] [Semiring A] [Algebra k A] {G H F : Type*} [Add G] [Add H] [FunLike F G H] [AddHomClass F G H] (f : F) : A[G] →ₙₐ[k] A[H] := { (Finsupp.mapDomain.addMonoidHom f : MonoidAlgebra A G →+ MonoidAlgebra A H) with map_mul' := fun x y => mapDomain_mul f x y map_smul' := fun r x => mapDomain_smul r x } /-- If `f : G → H` is an additive homomorphism between two additive monoids, then `Finsupp.mapDomain f` is an algebra homomorphism between their add monoid algebras. -/ @[simps!] def mapDomainAlgHom (k A : Type*) [CommSemiring k] [Semiring A] [Algebra k A] [AddMonoid G] {H F : Type*} [AddMonoid H] [FunLike F G H] [AddMonoidHomClass F G H] (f : F) : A[G] →ₐ[k] A[H] := { mapDomainRingHom A f with commutes' := mapDomain_algebraMap A f } @[simp] lemma mapDomainAlgHom_id (k A) [CommSemiring k] [Semiring A] [Algebra k A] [AddMonoid G] : mapDomainAlgHom k A (AddMonoidHom.id G) = AlgHom.id k (AddMonoidAlgebra A G) := by ext; simp [AddMonoidHom.id, ← Function.id_def] @[simp] lemma mapDomainAlgHom_comp (k A) {G₁ G₂ G₃} [CommSemiring k] [Semiring A] [Algebra k A] [AddMonoid G₁] [AddMonoid G₂] [AddMonoid G₃] (f : G₁ →+ G₂) (g : G₂ →+ G₃) : mapDomainAlgHom k A (g.comp f) = (mapDomainAlgHom k A g).comp (mapDomainAlgHom k A f) := by ext; simp [mapDomain_comp] variable (k A) variable [CommSemiring k] [AddMonoid G] [AddMonoid H] [Semiring A] [Algebra k A] /-- If `e : G ≃* H` is a multiplicative equivalence between two monoids, then `AddMonoidAlgebra.domCongr e` is an algebra equivalence between their monoid algebras. -/ def domCongr (e : G ≃+ H) : A[G] ≃ₐ[k] A[H] := AlgEquiv.ofLinearEquiv (Finsupp.domLCongr e : (G →₀ A) ≃ₗ[k] (H →₀ A)) ((equivMapDomain_eq_mapDomain _ _).trans <| mapDomain_one e) (fun f g => (equivMapDomain_eq_mapDomain _ _).trans <| (mapDomain_mul e f g).trans <| congr_arg₂ _ (equivMapDomain_eq_mapDomain _ _).symm (equivMapDomain_eq_mapDomain _ _).symm) theorem domCongr_toAlgHom (e : G ≃+ H) : (domCongr k A e).toAlgHom = mapDomainAlgHom k A e := AlgHom.ext fun _ => equivMapDomain_eq_mapDomain _ _ @[simp] theorem domCongr_apply (e : G ≃+ H) (f : MonoidAlgebra A G) (h : H) : domCongr k A e f h = f (e.symm h) := rfl @[simp] theorem domCongr_support (e : G ≃+ H) (f : MonoidAlgebra A G) : (domCongr k A e f).support = f.support.map e := rfl @[simp] theorem domCongr_single (e : G ≃+ H) (g : G) (a : A) : domCongr k A e (single g a) = single (e g) a := Finsupp.equivMapDomain_single _ _ _ @[simp] theorem domCongr_refl : domCongr k A (AddEquiv.refl G) = AlgEquiv.refl := AlgEquiv.ext fun _ => Finsupp.ext fun _ => rfl @[simp] theorem domCongr_symm (e : G ≃+ H) : (domCongr k A e).symm = domCongr k A e.symm := rfl end AddMonoidAlgebra variable [CommSemiring R] /-- The algebra equivalence between `AddMonoidAlgebra` and `MonoidAlgebra` in terms of `Multiplicative`. -/ def AddMonoidAlgebra.toMultiplicativeAlgEquiv [Semiring k] [Algebra R k] [AddMonoid G] : AddMonoidAlgebra k G ≃ₐ[R] MonoidAlgebra k (Multiplicative G) := { AddMonoidAlgebra.toMultiplicative k G with commutes' := fun r => by simp [AddMonoidAlgebra.toMultiplicative] } /-- The algebra equivalence between `MonoidAlgebra` and `AddMonoidAlgebra` in terms of `Additive`. -/ def MonoidAlgebra.toAdditiveAlgEquiv [Semiring k] [Algebra R k] [Monoid G] : MonoidAlgebra k G ≃ₐ[R] AddMonoidAlgebra k (Additive G) := { MonoidAlgebra.toAdditive k G with commutes' := fun r => by simp [MonoidAlgebra.toAdditive] }
Mathlib/Algebra/MonoidAlgebra/Basic.lean
1,618
1,629
/- 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.Module.OrderedSMul import Mathlib.Algebra.Order.Module.Synonym import Mathlib.Algebra.Order.Monoid.Unbundled.MinMax import Mathlib.Order.Monotone.Monovary /-! # Monovarying functions and algebraic operations This file characterises the interaction of ordered algebraic structures with monovariance of functions. ## See also `Algebra.Order.Rearrangement` for the n-ary rearrangement inequality -/ variable {ι α β : Type*} /-! ### Algebraic operations on monovarying functions -/ section OrderedCommGroup section variable [CommGroup α] [PartialOrder α] [IsOrderedMonoid α] [PartialOrder β] {s : Set ι} {f f₁ f₂ : ι → α} {g : ι → β} @[to_additive (attr := simp)] lemma monovaryOn_inv_left : MonovaryOn f⁻¹ g s ↔ AntivaryOn f g s := by simp [MonovaryOn, AntivaryOn] @[to_additive (attr := simp)] lemma antivaryOn_inv_left : AntivaryOn f⁻¹ g s ↔ MonovaryOn f g s := by simp [MonovaryOn, AntivaryOn] @[to_additive (attr := simp)] lemma monovary_inv_left : Monovary f⁻¹ g ↔ Antivary f g := by simp [Monovary, Antivary] @[to_additive (attr := simp)] lemma antivary_inv_left : Antivary f⁻¹ g ↔ Monovary f g := by simp [Monovary, Antivary] @[to_additive] lemma MonovaryOn.mul_left (h₁ : MonovaryOn f₁ g s) (h₂ : MonovaryOn f₂ g s) : MonovaryOn (f₁ * f₂) g s := fun _i hi _j hj hij ↦ mul_le_mul' (h₁ hi hj hij) (h₂ hi hj hij) @[to_additive] lemma AntivaryOn.mul_left (h₁ : AntivaryOn f₁ g s) (h₂ : AntivaryOn f₂ g s) : AntivaryOn (f₁ * f₂) g s := fun _i hi _j hj hij ↦ mul_le_mul' (h₁ hi hj hij) (h₂ hi hj hij) @[to_additive] lemma MonovaryOn.div_left (h₁ : MonovaryOn f₁ g s) (h₂ : AntivaryOn f₂ g s) : MonovaryOn (f₁ / f₂) g s := fun _i hi _j hj hij ↦ div_le_div'' (h₁ hi hj hij) (h₂ hi hj hij) @[to_additive] lemma AntivaryOn.div_left (h₁ : AntivaryOn f₁ g s) (h₂ : MonovaryOn f₂ g s) : AntivaryOn (f₁ / f₂) g s := fun _i hi _j hj hij ↦ div_le_div'' (h₁ hi hj hij) (h₂ hi hj hij) @[to_additive] lemma MonovaryOn.pow_left (hfg : MonovaryOn f g s) (n : ℕ) :
MonovaryOn (f ^ n) g s := fun _i hi _j hj hij ↦ pow_le_pow_left' (hfg hi hj hij) _
Mathlib/Algebra/Order/Monovary.lean
59
60
/- Copyright (c) 2023 Jeremy Tan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Tan -/ import Mathlib.Combinatorics.SimpleGraph.Finite import Mathlib.Combinatorics.SimpleGraph.Maps import Mathlib.Combinatorics.SimpleGraph.Subgraph /-! # Local graph operations This file defines some single-graph operations that modify a finite number of vertices and proves basic theorems about them. When the graph itself has a finite number of vertices we also prove theorems about the number of edges in the modified graphs. ## Main definitions * `G.replaceVertex s t` is `G` with `t` replaced by a copy of `s`, removing the `s-t` edge if present. * `edge s t` is the graph with a single `s-t` edge. Adding this edge to a graph `G` is then `G ⊔ edge s t`. -/ open Finset namespace SimpleGraph variable {V : Type*} (G : SimpleGraph V) (s t : V) namespace Iso variable {G} {W : Type*} {G' : SimpleGraph W} (f : G ≃g G') include f in theorem card_edgeFinset_eq [Fintype G.edgeSet] [Fintype G'.edgeSet] : #G.edgeFinset = #G'.edgeFinset := by apply Finset.card_eq_of_equiv simp only [Set.mem_toFinset] exact f.mapEdgeSet end Iso section ReplaceVertex variable [DecidableEq V] /-- The graph formed by forgetting `t`'s neighbours and instead giving it those of `s`. The `s-t` edge is removed if present. -/ def replaceVertex : SimpleGraph V where Adj v w := if v = t then if w = t then False else G.Adj s w else if w = t then G.Adj v s else G.Adj v w symm v w := by dsimp only; split_ifs <;> simp [adj_comm] /-- There is never an `s-t` edge in `G.replaceVertex s t`. -/ lemma not_adj_replaceVertex_same : ¬(G.replaceVertex s t).Adj s t := by simp [replaceVertex] @[simp] lemma replaceVertex_self : G.replaceVertex s s = G := by ext; unfold replaceVertex; aesop (add simp or_iff_not_imp_left) variable {t} /-- Except possibly for `t`, the neighbours of `s` in `G.replaceVertex s t` are its neighbours in `G`. -/ lemma adj_replaceVertex_iff_of_ne_left {w : V} (hw : w ≠ t) : (G.replaceVertex s t).Adj s w ↔ G.Adj s w := by simp [replaceVertex, hw] /-- Except possibly for itself, the neighbours of `t` in `G.replaceVertex s t` are the neighbours of `s` in `G`. -/ lemma adj_replaceVertex_iff_of_ne_right {w : V} (hw : w ≠ t) : (G.replaceVertex s t).Adj t w ↔ G.Adj s w := by simp [replaceVertex, hw] /-- Adjacency in `G.replaceVertex s t` which does not involve `t` is the same as that of `G`. -/ lemma adj_replaceVertex_iff_of_ne {v w : V} (hv : v ≠ t) (hw : w ≠ t) : (G.replaceVertex s t).Adj v w ↔ G.Adj v w := by simp [replaceVertex, hv, hw] variable {s} theorem edgeSet_replaceVertex_of_not_adj (hn : ¬G.Adj s t) : (G.replaceVertex s t).edgeSet = G.edgeSet \ G.incidenceSet t ∪ (s(·, t)) '' (G.neighborSet s) := by ext e; refine e.inductionOn ?_ simp only [replaceVertex, mem_edgeSet, Set.mem_union, Set.mem_diff, mk'_mem_incidenceSet_iff] intros; split_ifs; exacts [by simp_all, by aesop, by rw [adj_comm]; aesop, by aesop] theorem edgeSet_replaceVertex_of_adj (ha : G.Adj s t) : (G.replaceVertex s t).edgeSet = (G.edgeSet \ G.incidenceSet t ∪ (s(·, t)) '' (G.neighborSet s)) \ {s(t, t)} := by ext e; refine e.inductionOn ?_ simp only [replaceVertex, mem_edgeSet, Set.mem_union, Set.mem_diff, mk'_mem_incidenceSet_iff] intros; split_ifs; exacts [by simp_all, by aesop, by rw [adj_comm]; aesop, by aesop] variable [Fintype V] [DecidableRel G.Adj] instance : DecidableRel (G.replaceVertex s t).Adj := by unfold replaceVertex; infer_instance theorem edgeFinset_replaceVertex_of_not_adj (hn : ¬G.Adj s t) : (G.replaceVertex s t).edgeFinset = G.edgeFinset \ G.incidenceFinset t ∪ (G.neighborFinset s).image (s(·, t)) := by simp only [incidenceFinset, neighborFinset, ← Set.toFinset_diff, ← Set.toFinset_image, ← Set.toFinset_union] exact Set.toFinset_congr (G.edgeSet_replaceVertex_of_not_adj hn) theorem edgeFinset_replaceVertex_of_adj (ha : G.Adj s t) : (G.replaceVertex s t).edgeFinset = (G.edgeFinset \ G.incidenceFinset t ∪ (G.neighborFinset s).image (s(·, t))) \ {s(t, t)} := by simp only [incidenceFinset, neighborFinset, ← Set.toFinset_diff, ← Set.toFinset_image, ← Set.toFinset_union, ← Set.toFinset_singleton] exact Set.toFinset_congr (G.edgeSet_replaceVertex_of_adj ha) lemma disjoint_sdiff_neighborFinset_image : Disjoint (G.edgeFinset \ G.incidenceFinset t) ((G.neighborFinset s).image (s(·, t))) := by rw [disjoint_iff_ne] intro e he have : t ∉ e := by rw [mem_sdiff, mem_incidenceFinset] at he obtain ⟨_, h⟩ := he contrapose! h simp_all [incidenceSet] aesop theorem card_edgeFinset_replaceVertex_of_not_adj (hn : ¬G.Adj s t) : #(G.replaceVertex s t).edgeFinset = #G.edgeFinset + G.degree s - G.degree t := by have inc : G.incidenceFinset t ⊆ G.edgeFinset := by simp [incidenceFinset, incidenceSet_subset] rw [G.edgeFinset_replaceVertex_of_not_adj hn, card_union_of_disjoint G.disjoint_sdiff_neighborFinset_image, card_sdiff inc, ← Nat.sub_add_comm <| card_le_card inc, card_incidenceFinset_eq_degree] congr 2 rw [card_image_of_injective, card_neighborFinset_eq_degree] unfold Function.Injective aesop theorem card_edgeFinset_replaceVertex_of_adj (ha : G.Adj s t) : #(G.replaceVertex s t).edgeFinset = #G.edgeFinset + G.degree s - G.degree t - 1 := by have inc : G.incidenceFinset t ⊆ G.edgeFinset := by simp [incidenceFinset, incidenceSet_subset] rw [G.edgeFinset_replaceVertex_of_adj ha, card_sdiff (by simp [ha]), card_union_of_disjoint G.disjoint_sdiff_neighborFinset_image, card_sdiff inc, ← Nat.sub_add_comm <| card_le_card inc, card_incidenceFinset_eq_degree] congr 2 rw [card_image_of_injective, card_neighborFinset_eq_degree] unfold Function.Injective aesop end ReplaceVertex section AddEdge /-- The graph with a single `s-t` edge. It is empty iff `s = t`. -/ def edge : SimpleGraph V := fromEdgeSet {s(s, t)} lemma edge_adj (v w : V) : (edge s t).Adj v w ↔ (v = s ∧ w = t ∨ v = t ∧ w = s) ∧ v ≠ w := by rw [edge, fromEdgeSet_adj, Set.mem_singleton_iff, Sym2.eq_iff] lemma adj_edge {v w : V} : (edge s t).Adj v w ↔ s(s, t) = s(v, w) ∧ v ≠ w := by simp only [edge_adj, ne_eq, Sym2.eq, Sym2.rel_iff', Prod.mk.injEq, Prod.swap_prod_mk, and_congr_left_iff] tauto lemma edge_comm : edge s t = edge t s := by rw [edge, edge, Sym2.eq_swap] variable [DecidableEq V] in instance : DecidableRel (edge s t).Adj := fun _ _ ↦ by rw [edge_adj]; infer_instance lemma edge_self_eq_bot : edge s s = ⊥ := by ext; rw [edge_adj]; aesop @[simp] lemma sup_edge_self : G ⊔ edge s s = G := by rw [edge_self_eq_bot, sup_of_le_left bot_le] lemma lt_sup_edge (hne : s ≠ t) (hn : ¬ G.Adj s t) : G < G ⊔ edge s t :=
left_lt_sup.2 fun h ↦ hn <| h <| (edge_adj ..).mpr ⟨Or.inl ⟨rfl, rfl⟩, hne⟩ variable {s t} lemma edge_edgeSet_of_ne (h : s ≠ t) : (edge s t).edgeSet = {s(s, t)} := by
Mathlib/Combinatorics/SimpleGraph/Operations.lean
171
175
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.Group.Indicator import Mathlib.Data.Int.Cast.Pi import Mathlib.Data.Nat.Cast.Basic import Mathlib.MeasureTheory.MeasurableSpace.Defs /-! # Measurable spaces and measurable functions This file provides properties of measurable spaces and the functions and isomorphisms between them. The definition of a measurable space is in `Mathlib/MeasureTheory/MeasurableSpace/Defs.lean`. A measurable space is a set equipped with a σ-algebra, a collection of subsets closed under complementation and countable union. A function between measurable spaces is measurable if the preimage of each measurable subset is measurable. σ-algebras on a fixed set `α` form a complete lattice. Here we order σ-algebras by writing `m₁ ≤ m₂` if every set which is `m₁`-measurable is also `m₂`-measurable (that is, `m₁` is a subset of `m₂`). In particular, any collection of subsets of `α` generates a smallest σ-algebra which contains all of them. A function `f : α → β` induces a Galois connection between the lattices of σ-algebras on `α` and `β`. ## Implementation notes Measurability of a function `f : α → β` between measurable spaces is defined in terms of the Galois connection induced by `f`. ## References * <https://en.wikipedia.org/wiki/Measurable_space> * <https://en.wikipedia.org/wiki/Sigma-algebra> * <https://en.wikipedia.org/wiki/Dynkin_system> ## Tags measurable space, σ-algebra, measurable function, dynkin system, π-λ theorem, π-system -/ open Set MeasureTheory universe uι variable {α β γ : Type*} {ι : Sort uι} {s : Set α} namespace MeasurableSpace section Functors variable {m m₁ m₂ : MeasurableSpace α} {m' : MeasurableSpace β} {f : α → β} {g : β → α} /-- The forward image of a measurable space under a function. `map f m` contains the sets `s : Set β` whose preimage under `f` is measurable. -/ protected def map (f : α → β) (m : MeasurableSpace α) : MeasurableSpace β where MeasurableSet' s := MeasurableSet[m] <| f ⁻¹' s measurableSet_empty := m.measurableSet_empty measurableSet_compl _ hs := m.measurableSet_compl _ hs measurableSet_iUnion f hf := by simpa only [preimage_iUnion] using m.measurableSet_iUnion _ hf lemma map_def {s : Set β} : MeasurableSet[m.map f] s ↔ MeasurableSet[m] (f ⁻¹' s) := Iff.rfl @[simp] theorem map_id : m.map id = m := MeasurableSpace.ext fun _ => Iff.rfl @[simp] theorem map_comp {f : α → β} {g : β → γ} : (m.map f).map g = m.map (g ∘ f) := MeasurableSpace.ext fun _ => Iff.rfl /-- The reverse image of a measurable space under a function. `comap f m` contains the sets `s : Set α` such that `s` is the `f`-preimage of a measurable set in `β`. -/ protected def comap (f : α → β) (m : MeasurableSpace β) : MeasurableSpace α where MeasurableSet' s := ∃ s', MeasurableSet[m] s' ∧ f ⁻¹' s' = s measurableSet_empty := ⟨∅, m.measurableSet_empty, rfl⟩ measurableSet_compl := fun _ ⟨s', h₁, h₂⟩ => ⟨s'ᶜ, m.measurableSet_compl _ h₁, h₂ ▸ rfl⟩ measurableSet_iUnion s hs := let ⟨s', hs'⟩ := Classical.axiom_of_choice hs ⟨⋃ i, s' i, m.measurableSet_iUnion _ fun i => (hs' i).left, by simp [hs']⟩ lemma measurableSet_comap {m : MeasurableSpace β} : MeasurableSet[m.comap f] s ↔ ∃ s', MeasurableSet[m] s' ∧ f ⁻¹' s' = s := .rfl theorem comap_eq_generateFrom (m : MeasurableSpace β) (f : α → β) : m.comap f = generateFrom { t | ∃ s, MeasurableSet s ∧ f ⁻¹' s = t } := (@generateFrom_measurableSet _ (.comap f m)).symm @[simp] theorem comap_id : m.comap id = m := MeasurableSpace.ext fun s => ⟨fun ⟨_, hs', h⟩ => h ▸ hs', fun h => ⟨s, h, rfl⟩⟩ @[simp] theorem comap_comp {f : β → α} {g : γ → β} : (m.comap f).comap g = m.comap (f ∘ g) := MeasurableSpace.ext fun _ => ⟨fun ⟨_, ⟨u, h, hu⟩, ht⟩ => ⟨u, h, ht ▸ hu ▸ rfl⟩, fun ⟨t, h, ht⟩ => ⟨f ⁻¹' t, ⟨_, h, rfl⟩, ht⟩⟩ theorem comap_le_iff_le_map {f : α → β} : m'.comap f ≤ m ↔ m' ≤ m.map f := ⟨fun h _s hs => h _ ⟨_, hs, rfl⟩, fun h _s ⟨_t, ht, heq⟩ => heq ▸ h _ ht⟩ theorem gc_comap_map (f : α → β) : GaloisConnection (MeasurableSpace.comap f) (MeasurableSpace.map f) := fun _ _ => comap_le_iff_le_map theorem map_mono (h : m₁ ≤ m₂) : m₁.map f ≤ m₂.map f := (gc_comap_map f).monotone_u h theorem monotone_map : Monotone (MeasurableSpace.map f) := fun _ _ => map_mono theorem comap_mono (h : m₁ ≤ m₂) : m₁.comap g ≤ m₂.comap g := (gc_comap_map g).monotone_l h theorem monotone_comap : Monotone (MeasurableSpace.comap g) := fun _ _ h => comap_mono h @[simp] theorem comap_bot : (⊥ : MeasurableSpace α).comap g = ⊥ := (gc_comap_map g).l_bot @[simp] theorem comap_sup : (m₁ ⊔ m₂).comap g = m₁.comap g ⊔ m₂.comap g := (gc_comap_map g).l_sup @[simp] theorem comap_iSup {m : ι → MeasurableSpace α} : (⨆ i, m i).comap g = ⨆ i, (m i).comap g := (gc_comap_map g).l_iSup @[simp] theorem map_top : (⊤ : MeasurableSpace α).map f = ⊤ := (gc_comap_map f).u_top @[simp] theorem map_inf : (m₁ ⊓ m₂).map f = m₁.map f ⊓ m₂.map f := (gc_comap_map f).u_inf @[simp] theorem map_iInf {m : ι → MeasurableSpace α} : (⨅ i, m i).map f = ⨅ i, (m i).map f := (gc_comap_map f).u_iInf theorem comap_map_le : (m.map f).comap f ≤ m := (gc_comap_map f).l_u_le _ theorem le_map_comap : m ≤ (m.comap g).map g := (gc_comap_map g).le_u_l _ end Functors @[simp] theorem map_const {m} (b : β) : MeasurableSpace.map (fun _a : α ↦ b) m = ⊤ := eq_top_iff.2 <| fun s _ ↦ by rw [map_def]; by_cases h : b ∈ s <;> simp [h] @[simp] theorem comap_const {m} (b : β) : MeasurableSpace.comap (fun _a : α => b) m = ⊥ := eq_bot_iff.2 <| by rintro _ ⟨s, -, rfl⟩; by_cases b ∈ s <;> simp [*] theorem comap_generateFrom {f : α → β} {s : Set (Set β)} : (generateFrom s).comap f = generateFrom (preimage f '' s) := le_antisymm (comap_le_iff_le_map.2 <| generateFrom_le fun _t hts => GenerateMeasurable.basic _ <| mem_image_of_mem _ <| hts) (generateFrom_le fun _t ⟨u, hu, Eq⟩ => Eq ▸ ⟨u, GenerateMeasurable.basic _ hu, rfl⟩) end MeasurableSpace section MeasurableFunctions open MeasurableSpace theorem measurable_iff_le_map {m₁ : MeasurableSpace α} {m₂ : MeasurableSpace β} {f : α → β} : Measurable f ↔ m₂ ≤ m₁.map f := Iff.rfl alias ⟨Measurable.le_map, Measurable.of_le_map⟩ := measurable_iff_le_map theorem measurable_iff_comap_le {m₁ : MeasurableSpace α} {m₂ : MeasurableSpace β} {f : α → β} : Measurable f ↔ m₂.comap f ≤ m₁ := comap_le_iff_le_map.symm alias ⟨Measurable.comap_le, Measurable.of_comap_le⟩ := measurable_iff_comap_le theorem comap_measurable {m : MeasurableSpace β} (f : α → β) : Measurable[m.comap f] f := fun s hs => ⟨s, hs, rfl⟩ theorem Measurable.mono {ma ma' : MeasurableSpace α} {mb mb' : MeasurableSpace β} {f : α → β} (hf : @Measurable α β ma mb f) (ha : ma ≤ ma') (hb : mb' ≤ mb) : @Measurable α β ma' mb' f := fun _t ht => ha _ <| hf <| hb _ ht lemma Measurable.iSup' {mα : ι → MeasurableSpace α} {_ : MeasurableSpace β} {f : α → β} (i₀ : ι) (h : Measurable[mα i₀] f) : Measurable[⨆ i, mα i] f := h.mono (le_iSup mα i₀) le_rfl lemma Measurable.sup_of_left {mα mα' : MeasurableSpace α} {_ : MeasurableSpace β} {f : α → β} (h : Measurable[mα] f) : Measurable[mα ⊔ mα'] f := h.mono le_sup_left le_rfl lemma Measurable.sup_of_right {mα mα' : MeasurableSpace α} {_ : MeasurableSpace β} {f : α → β} (h : Measurable[mα'] f) : Measurable[mα ⊔ mα'] f := h.mono le_sup_right le_rfl theorem measurable_id'' {m mα : MeasurableSpace α} (hm : m ≤ mα) : @Measurable α α mα m id := measurable_id.mono le_rfl hm @[measurability] theorem measurable_from_top [MeasurableSpace β] {f : α → β} : Measurable[⊤] f := fun _ _ => trivial theorem measurable_generateFrom [MeasurableSpace α] {s : Set (Set β)} {f : α → β} (h : ∀ t ∈ s, MeasurableSet (f ⁻¹' t)) : @Measurable _ _ _ (generateFrom s) f := Measurable.of_le_map <| generateFrom_le h variable {f g : α → β} section TypeclassMeasurableSpace variable [MeasurableSpace α] [MeasurableSpace β] @[nontriviality, measurability] theorem Subsingleton.measurable [Subsingleton α] : Measurable f := fun _ _ => @Subsingleton.measurableSet α _ _ _ @[nontriviality, measurability] theorem measurable_of_subsingleton_codomain [Subsingleton β] (f : α → β) : Measurable f := fun s _ => Subsingleton.set_cases MeasurableSet.empty MeasurableSet.univ s @[to_additive (attr := measurability, fun_prop)] theorem measurable_one [One α] : Measurable (1 : β → α) := @measurable_const _ _ _ _ 1 theorem measurable_of_empty [IsEmpty α] (f : α → β) : Measurable f := Subsingleton.measurable theorem measurable_of_empty_codomain [IsEmpty β] (f : α → β) : Measurable f := measurable_of_subsingleton_codomain f /-- A version of `measurable_const` that assumes `f x = f y` for all `x, y`. This version works for functions between empty types. -/ theorem measurable_const' {f : β → α} (hf : ∀ x y, f x = f y) : Measurable f := by nontriviality β inhabit β convert @measurable_const α β _ _ (f default) using 2 apply hf @[measurability] theorem measurable_natCast [NatCast α] (n : ℕ) : Measurable (n : β → α) := @measurable_const α _ _ _ n @[measurability] theorem measurable_intCast [IntCast α] (n : ℤ) : Measurable (n : β → α) := @measurable_const α _ _ _ n theorem measurable_of_countable [Countable α] [MeasurableSingletonClass α] (f : α → β) : Measurable f := fun s _ => (f ⁻¹' s).to_countable.measurableSet theorem measurable_of_finite [Finite α] [MeasurableSingletonClass α] (f : α → β) : Measurable f := measurable_of_countable f end TypeclassMeasurableSpace variable {m : MeasurableSpace α} @[measurability] theorem Measurable.iterate {f : α → α} (hf : Measurable f) : ∀ n, Measurable f^[n] | 0 => measurable_id | n + 1 => (Measurable.iterate hf n).comp hf variable {mβ : MeasurableSpace β} @[measurability] theorem measurableSet_preimage {t : Set β} (hf : Measurable f) (ht : MeasurableSet t) : MeasurableSet (f ⁻¹' t) := hf ht protected theorem MeasurableSet.preimage {t : Set β} (ht : MeasurableSet t) (hf : Measurable f) : MeasurableSet (f ⁻¹' t) := hf ht @[measurability, fun_prop] protected theorem Measurable.piecewise {_ : DecidablePred (· ∈ s)} (hs : MeasurableSet s) (hf : Measurable f) (hg : Measurable g) : Measurable (piecewise s f g) := by intro t ht rw [piecewise_preimage] exact hs.ite (hf ht) (hg ht) /-- This is slightly different from `Measurable.piecewise`. It can be used to show `Measurable (ite (x=0) 0 1)` by `exact Measurable.ite (measurableSet_singleton 0) measurable_const measurable_const`, but replacing `Measurable.ite` by `Measurable.piecewise` in that example proof does not work. -/ theorem Measurable.ite {p : α → Prop} {_ : DecidablePred p} (hp : MeasurableSet { a : α | p a }) (hf : Measurable f) (hg : Measurable g) : Measurable fun x => ite (p x) (f x) (g x) := Measurable.piecewise hp hf hg @[measurability, fun_prop] theorem Measurable.indicator [Zero β] (hf : Measurable f) (hs : MeasurableSet s) : Measurable (s.indicator f) := hf.piecewise hs measurable_const /-- The measurability of a set `A` is equivalent to the measurability of the indicator function which takes a constant value `b ≠ 0` on a set `A` and `0` elsewhere. -/ lemma measurable_indicator_const_iff [Zero β] [MeasurableSingletonClass β] (b : β) [NeZero b] : Measurable (s.indicator (fun (_ : α) ↦ b)) ↔ MeasurableSet s := by constructor <;> intro h · convert h (MeasurableSet.singleton (0 : β)).compl ext a simp [NeZero.ne b] · exact measurable_const.indicator h @[to_additive (attr := measurability)] theorem measurableSet_mulSupport [One β] [MeasurableSingletonClass β] (hf : Measurable f) : MeasurableSet (Function.mulSupport f) := hf (measurableSet_singleton 1).compl /-- If a function coincides with a measurable function outside of a countable set, it is measurable. -/ theorem Measurable.measurable_of_countable_ne [MeasurableSingletonClass α] (hf : Measurable f) (h : Set.Countable { x | f x ≠ g x }) : Measurable g := by intro t ht have : g ⁻¹' t = g ⁻¹' t ∩ { x | f x = g x }ᶜ ∪ g ⁻¹' t ∩ { x | f x = g x } := by simp [← inter_union_distrib_left] rw [this] refine (h.mono inter_subset_right).measurableSet.union ?_ have : g ⁻¹' t ∩ { x : α | f x = g x } = f ⁻¹' t ∩ { x : α | f x = g x } := by ext x simp +contextual rw [this] exact (hf ht).inter h.measurableSet.of_compl end MeasurableFunctions /-- We say that a collection of sets is countably spanning if a countable subset spans the whole type. This is a useful condition in various parts of measure theory. For example, it is a needed condition to show that the product of two collections generate the product sigma algebra, see `generateFrom_prod_eq`. -/ def IsCountablySpanning (C : Set (Set α)) : Prop := ∃ s : ℕ → Set α, (∀ n, s n ∈ C) ∧ ⋃ n, s n = univ theorem isCountablySpanning_measurableSet [MeasurableSpace α] : IsCountablySpanning { s : Set α | MeasurableSet s } := ⟨fun _ => univ, fun _ => MeasurableSet.univ, iUnion_const _⟩ /-- Rectangles of countably spanning sets are countably spanning. -/ lemma IsCountablySpanning.prod {C : Set (Set α)} {D : Set (Set β)} (hC : IsCountablySpanning C) (hD : IsCountablySpanning D) : IsCountablySpanning (image2 (· ×ˢ ·) C D) := by rcases hC, hD with ⟨⟨s, h1s, h2s⟩, t, h1t, h2t⟩ refine ⟨fun n => s n.unpair.1 ×ˢ t n.unpair.2, fun n => mem_image2_of_mem (h1s _) (h1t _), ?_⟩ rw [iUnion_unpair_prod, h2s, h2t, univ_prod_univ]
Mathlib/MeasureTheory/MeasurableSpace/Basic.lean
1,018
1,029
/- Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Robert Y. Lewis, Johannes Hölzl, Mario Carneiro, Sébastien Gouëzel -/ import Mathlib.Data.ENNReal.Real import Mathlib.Tactic.Bound.Attribute import Mathlib.Topology.Bornology.Basic import Mathlib.Topology.EMetricSpace.Defs import Mathlib.Topology.UniformSpace.Basic /-! ## Pseudo-metric spaces This file defines pseudo-metric spaces: these differ from metric spaces by not imposing the condition `dist x y = 0 → x = y`. Many definitions and theorems expected on (pseudo-)metric spaces are already introduced on uniform spaces and topological spaces. For example: open and closed sets, compactness, completeness, continuity and uniform continuity. ## Main definitions * `Dist α`: Endows a space `α` with a function `dist a b`. * `PseudoMetricSpace α`: A space endowed with a distance function, which can be zero even if the two elements are non-equal. * `Metric.ball x ε`: The set of all points `y` with `dist y x < ε`. * `Metric.Bounded s`: Whether a subset of a `PseudoMetricSpace` is bounded. * `MetricSpace α`: A `PseudoMetricSpace` with the guarantee `dist x y = 0 → x = y`. Additional useful definitions: * `nndist a b`: `dist` as a function to the non-negative reals. * `Metric.closedBall x ε`: The set of all points `y` with `dist y x ≤ ε`. * `Metric.sphere x ε`: The set of all points `y` with `dist y x = ε`. TODO (anyone): Add "Main results" section. ## Tags pseudo_metric, dist -/ assert_not_exists compactSpace_uniformity open Set Filter TopologicalSpace Bornology open scoped ENNReal NNReal Uniformity Topology universe u v w variable {α : Type u} {β : Type v} {X ι : Type*} theorem UniformSpace.ofDist_aux (ε : ℝ) (hε : 0 < ε) : ∃ δ > (0 : ℝ), ∀ x < δ, ∀ y < δ, x + y < ε := ⟨ε / 2, half_pos hε, fun _x hx _y hy => add_halves ε ▸ add_lt_add hx hy⟩ /-- Construct a uniform structure from a distance function and metric space axioms -/ def UniformSpace.ofDist (dist : α → α → ℝ) (dist_self : ∀ x : α, dist x x = 0) (dist_comm : ∀ x y : α, dist x y = dist y x) (dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) : UniformSpace α := .ofFun dist dist_self dist_comm dist_triangle ofDist_aux /-- Construct a bornology from a distance function and metric space axioms. -/ abbrev Bornology.ofDist {α : Type*} (dist : α → α → ℝ) (dist_comm : ∀ x y, dist x y = dist y x) (dist_triangle : ∀ x y z, dist x z ≤ dist x y + dist y z) : Bornology α := Bornology.ofBounded { s : Set α | ∃ C, ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → dist x y ≤ C } ⟨0, fun _ hx _ => hx.elim⟩ (fun _ ⟨c, hc⟩ _ h => ⟨c, fun _ hx _ hy => hc (h hx) (h hy)⟩) (fun s hs t ht => by rcases s.eq_empty_or_nonempty with rfl | ⟨x, hx⟩ · rwa [empty_union] rcases t.eq_empty_or_nonempty with rfl | ⟨y, hy⟩ · rwa [union_empty] rsuffices ⟨C, hC⟩ : ∃ C, ∀ z ∈ s ∪ t, dist x z ≤ C · refine ⟨C + C, fun a ha b hb => (dist_triangle a x b).trans ?_⟩ simpa only [dist_comm] using add_le_add (hC _ ha) (hC _ hb) rcases hs with ⟨Cs, hs⟩; rcases ht with ⟨Ct, ht⟩ refine ⟨max Cs (dist x y + Ct), fun z hz => hz.elim (fun hz => (hs hx hz).trans (le_max_left _ _)) (fun hz => (dist_triangle x y z).trans <| (add_le_add le_rfl (ht hy hz)).trans (le_max_right _ _))⟩) fun z => ⟨dist z z, forall_eq.2 <| forall_eq.2 le_rfl⟩ /-- The distance function (given an ambient metric space on `α`), which returns a nonnegative real number `dist x y` given `x y : α`. -/ @[ext] class Dist (α : Type*) where /-- Distance between two points -/ dist : α → α → ℝ export Dist (dist) -- the uniform structure and the emetric space structure are embedded in the metric space structure -- to avoid instance diamond issues. See Note [forgetful inheritance]. /-- This is an internal lemma used inside the default of `PseudoMetricSpace.edist`. -/ private theorem dist_nonneg' {α} {x y : α} (dist : α → α → ℝ) (dist_self : ∀ x : α, dist x x = 0) (dist_comm : ∀ x y : α, dist x y = dist y x) (dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) : 0 ≤ dist x y := have : 0 ≤ 2 * dist x y := calc 0 = dist x x := (dist_self _).symm _ ≤ dist x y + dist y x := dist_triangle _ _ _ _ = 2 * dist x y := by rw [two_mul, dist_comm] nonneg_of_mul_nonneg_right this two_pos /-- A pseudometric space is a type endowed with a `ℝ`-valued distance `dist` satisfying reflexivity `dist x x = 0`, commutativity `dist x y = dist y x`, and the triangle inequality `dist x z ≤ dist x y + dist y z`. Note that we do not require `dist x y = 0 → x = y`. See metric spaces (`MetricSpace`) for the similar class with that stronger assumption. Any pseudometric space is a topological space and a uniform space (see `TopologicalSpace`, `UniformSpace`), where the topology and uniformity come from the metric. Note that a T1 pseudometric space is just a metric space. We make the uniformity/topology part of the data instead of deriving it from the metric. This eg ensures that we do not get a diamond when doing `[PseudoMetricSpace α] [PseudoMetricSpace β] : TopologicalSpace (α × β)`: The product metric and product topology agree, but not definitionally so. See Note [forgetful inheritance]. -/ class PseudoMetricSpace (α : Type u) : Type u extends Dist α where dist_self : ∀ x : α, dist x x = 0 dist_comm : ∀ x y : α, dist x y = dist y x dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z /-- Extended distance between two points -/ edist : α → α → ℝ≥0∞ := fun x y => ENNReal.ofNNReal ⟨dist x y, dist_nonneg' _ ‹_› ‹_› ‹_›⟩ edist_dist : ∀ x y : α, edist x y = ENNReal.ofReal (dist x y) := by intros x y; exact ENNReal.coe_nnreal_eq _ toUniformSpace : UniformSpace α := .ofDist dist dist_self dist_comm dist_triangle uniformity_dist : 𝓤 α = ⨅ ε > 0, 𝓟 { p : α × α | dist p.1 p.2 < ε } := by intros; rfl toBornology : Bornology α := Bornology.ofDist dist dist_comm dist_triangle cobounded_sets : (Bornology.cobounded α).sets = { s | ∃ C : ℝ, ∀ x ∈ sᶜ, ∀ y ∈ sᶜ, dist x y ≤ C } := by intros; rfl /-- Two pseudo metric space structures with the same distance function coincide. -/ @[ext] theorem PseudoMetricSpace.ext {α : Type*} {m m' : PseudoMetricSpace α} (h : m.toDist = m'.toDist) : m = m' := by let d := m.toDist obtain ⟨_, _, _, _, hed, _, hU, _, hB⟩ := m let d' := m'.toDist obtain ⟨_, _, _, _, hed', _, hU', _, hB'⟩ := m' obtain rfl : d = d' := h congr · ext x y : 2 rw [hed, hed'] · exact UniformSpace.ext (hU.trans hU'.symm) · ext : 2 rw [← Filter.mem_sets, ← Filter.mem_sets, hB, hB'] variable [PseudoMetricSpace α] attribute [instance] PseudoMetricSpace.toUniformSpace PseudoMetricSpace.toBornology -- see Note [lower instance priority] instance (priority := 200) PseudoMetricSpace.toEDist : EDist α := ⟨PseudoMetricSpace.edist⟩ /-- Construct a pseudo-metric space structure whose underlying topological space structure (definitionally) agrees which a pre-existing topology which is compatible with a given distance function. -/ def PseudoMetricSpace.ofDistTopology {α : Type u} [TopologicalSpace α] (dist : α → α → ℝ) (dist_self : ∀ x : α, dist x x = 0) (dist_comm : ∀ x y : α, dist x y = dist y x) (dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) (H : ∀ s : Set α, IsOpen s ↔ ∀ x ∈ s, ∃ ε > 0, ∀ y, dist x y < ε → y ∈ s) : PseudoMetricSpace α := { dist := dist dist_self := dist_self dist_comm := dist_comm dist_triangle := dist_triangle toUniformSpace := (UniformSpace.ofDist dist dist_self dist_comm dist_triangle).replaceTopology <| TopologicalSpace.ext_iff.2 fun s ↦ (H s).trans <| forall₂_congr fun x _ ↦ ((UniformSpace.hasBasis_ofFun (exists_gt (0 : ℝ)) dist dist_self dist_comm dist_triangle UniformSpace.ofDist_aux).comap (Prod.mk x)).mem_iff.symm uniformity_dist := rfl toBornology := Bornology.ofDist dist dist_comm dist_triangle cobounded_sets := rfl } @[simp] theorem dist_self (x : α) : dist x x = 0 := PseudoMetricSpace.dist_self x theorem dist_comm (x y : α) : dist x y = dist y x := PseudoMetricSpace.dist_comm x y theorem edist_dist (x y : α) : edist x y = ENNReal.ofReal (dist x y) := PseudoMetricSpace.edist_dist x y @[bound] theorem dist_triangle (x y z : α) : dist x z ≤ dist x y + dist y z := PseudoMetricSpace.dist_triangle x y z theorem dist_triangle_left (x y z : α) : dist x y ≤ dist z x + dist z y := by rw [dist_comm z]; apply dist_triangle theorem dist_triangle_right (x y z : α) : dist x y ≤ dist x z + dist y z := by rw [dist_comm y]; apply dist_triangle theorem dist_triangle4 (x y z w : α) : dist x w ≤ dist x y + dist y z + dist z w := calc dist x w ≤ dist x z + dist z w := dist_triangle x z w _ ≤ dist x y + dist y z + dist z w := add_le_add_right (dist_triangle x y z) _ theorem dist_triangle4_left (x₁ y₁ x₂ y₂ : α) : dist x₂ y₂ ≤ dist x₁ y₁ + (dist x₁ x₂ + dist y₁ y₂) := by rw [add_left_comm, dist_comm x₁, ← add_assoc] apply dist_triangle4 theorem dist_triangle4_right (x₁ y₁ x₂ y₂ : α) : dist x₁ y₁ ≤ dist x₁ x₂ + dist y₁ y₂ + dist x₂ y₂ := by rw [add_right_comm, dist_comm y₁] apply dist_triangle4 theorem dist_triangle8 (a b c d e f g h : α) : dist a h ≤ dist a b + dist b c + dist c d + dist d e + dist e f + dist f g + dist g h := by apply le_trans (dist_triangle4 a f g h) apply add_le_add_right (add_le_add_right _ (dist f g)) (dist g h) apply le_trans (dist_triangle4 a d e f) apply add_le_add_right (add_le_add_right _ (dist d e)) (dist e f) exact dist_triangle4 a b c d theorem swap_dist : Function.swap (@dist α _) = dist := by funext x y; exact dist_comm _ _ theorem abs_dist_sub_le (x y z : α) : |dist x z - dist y z| ≤ dist x y := abs_sub_le_iff.2 ⟨sub_le_iff_le_add.2 (dist_triangle _ _ _), sub_le_iff_le_add.2 (dist_triangle_left _ _ _)⟩ @[bound] theorem dist_nonneg {x y : α} : 0 ≤ dist x y := dist_nonneg' dist dist_self dist_comm dist_triangle namespace Mathlib.Meta.Positivity open Lean Meta Qq Function /-- Extension for the `positivity` tactic: distances are nonnegative. -/ @[positivity Dist.dist _ _] def evalDist : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(@Dist.dist $β $inst $a $b) => let _inst ← synthInstanceQ q(PseudoMetricSpace $β) assertInstancesCommute pure (.nonnegative q(dist_nonneg)) | _, _, _ => throwError "not dist" end Mathlib.Meta.Positivity example {x y : α} : 0 ≤ dist x y := by positivity @[simp] theorem abs_dist {a b : α} : |dist a b| = dist a b := abs_of_nonneg dist_nonneg /-- A version of `Dist` that takes value in `ℝ≥0`. -/ class NNDist (α : Type*) where /-- Nonnegative distance between two points -/ nndist : α → α → ℝ≥0 export NNDist (nndist) -- see Note [lower instance priority] /-- Distance as a nonnegative real number. -/ instance (priority := 100) PseudoMetricSpace.toNNDist : NNDist α := ⟨fun a b => ⟨dist a b, dist_nonneg⟩⟩ /-- Express `dist` in terms of `nndist` -/ theorem dist_nndist (x y : α) : dist x y = nndist x y := rfl @[simp, norm_cast] theorem coe_nndist (x y : α) : ↑(nndist x y) = dist x y := rfl /-- Express `edist` in terms of `nndist` -/ theorem edist_nndist (x y : α) : edist x y = nndist x y := by rw [edist_dist, dist_nndist, ENNReal.ofReal_coe_nnreal] /-- Express `nndist` in terms of `edist` -/ theorem nndist_edist (x y : α) : nndist x y = (edist x y).toNNReal := by simp [edist_nndist] @[simp, norm_cast] theorem coe_nnreal_ennreal_nndist (x y : α) : ↑(nndist x y) = edist x y := (edist_nndist x y).symm @[simp, norm_cast] theorem edist_lt_coe {x y : α} {c : ℝ≥0} : edist x y < c ↔ nndist x y < c := by rw [edist_nndist, ENNReal.coe_lt_coe] @[simp, norm_cast] theorem edist_le_coe {x y : α} {c : ℝ≥0} : edist x y ≤ c ↔ nndist x y ≤ c := by rw [edist_nndist, ENNReal.coe_le_coe] /-- In a pseudometric space, the extended distance is always finite -/ theorem edist_lt_top {α : Type*} [PseudoMetricSpace α] (x y : α) : edist x y < ⊤ := (edist_dist x y).symm ▸ ENNReal.ofReal_lt_top /-- In a pseudometric space, the extended distance is always finite -/ theorem edist_ne_top (x y : α) : edist x y ≠ ⊤ := (edist_lt_top x y).ne /-- `nndist x x` vanishes -/ @[simp] theorem nndist_self (a : α) : nndist a a = 0 := NNReal.coe_eq_zero.1 (dist_self a) @[simp, norm_cast] theorem dist_lt_coe {x y : α} {c : ℝ≥0} : dist x y < c ↔ nndist x y < c := Iff.rfl @[simp, norm_cast] theorem dist_le_coe {x y : α} {c : ℝ≥0} : dist x y ≤ c ↔ nndist x y ≤ c := Iff.rfl @[simp] theorem edist_lt_ofReal {x y : α} {r : ℝ} : edist x y < ENNReal.ofReal r ↔ dist x y < r := by rw [edist_dist, ENNReal.ofReal_lt_ofReal_iff_of_nonneg dist_nonneg] @[simp] theorem edist_le_ofReal {x y : α} {r : ℝ} (hr : 0 ≤ r) : edist x y ≤ ENNReal.ofReal r ↔ dist x y ≤ r := by rw [edist_dist, ENNReal.ofReal_le_ofReal_iff hr] /-- Express `nndist` in terms of `dist` -/ theorem nndist_dist (x y : α) : nndist x y = Real.toNNReal (dist x y) := by rw [dist_nndist, Real.toNNReal_coe] theorem nndist_comm (x y : α) : nndist x y = nndist y x := NNReal.eq <| dist_comm x y /-- Triangle inequality for the nonnegative distance -/ theorem nndist_triangle (x y z : α) : nndist x z ≤ nndist x y + nndist y z := dist_triangle _ _ _ theorem nndist_triangle_left (x y z : α) : nndist x y ≤ nndist z x + nndist z y := dist_triangle_left _ _ _ theorem nndist_triangle_right (x y z : α) : nndist x y ≤ nndist x z + nndist y z := dist_triangle_right _ _ _ /-- Express `dist` in terms of `edist` -/ theorem dist_edist (x y : α) : dist x y = (edist x y).toReal := by rw [edist_dist, ENNReal.toReal_ofReal dist_nonneg] namespace Metric -- instantiate pseudometric space as a topology variable {x y z : α} {δ ε ε₁ ε₂ : ℝ} {s : Set α} /-- `ball x ε` is the set of all points `y` with `dist y x < ε` -/ def ball (x : α) (ε : ℝ) : Set α := { y | dist y x < ε } @[simp] theorem mem_ball : y ∈ ball x ε ↔ dist y x < ε := Iff.rfl theorem mem_ball' : y ∈ ball x ε ↔ dist x y < ε := by rw [dist_comm, mem_ball] theorem pos_of_mem_ball (hy : y ∈ ball x ε) : 0 < ε := dist_nonneg.trans_lt hy theorem mem_ball_self (h : 0 < ε) : x ∈ ball x ε := by rwa [mem_ball, dist_self] @[simp] theorem nonempty_ball : (ball x ε).Nonempty ↔ 0 < ε := ⟨fun ⟨_x, hx⟩ => pos_of_mem_ball hx, fun h => ⟨x, mem_ball_self h⟩⟩ @[simp] theorem ball_eq_empty : ball x ε = ∅ ↔ ε ≤ 0 := by rw [← not_nonempty_iff_eq_empty, nonempty_ball, not_lt] @[simp] theorem ball_zero : ball x 0 = ∅ := by rw [ball_eq_empty] /-- If a point belongs to an open ball, then there is a strictly smaller radius whose ball also contains it. See also `exists_lt_subset_ball`. -/ theorem exists_lt_mem_ball_of_mem_ball (h : x ∈ ball y ε) : ∃ ε' < ε, x ∈ ball y ε' := by simp only [mem_ball] at h ⊢ exact ⟨(dist x y + ε) / 2, by linarith, by linarith⟩ theorem ball_eq_ball (ε : ℝ) (x : α) : UniformSpace.ball x { p | dist p.2 p.1 < ε } = Metric.ball x ε := rfl theorem ball_eq_ball' (ε : ℝ) (x : α) : UniformSpace.ball x { p | dist p.1 p.2 < ε } = Metric.ball x ε := by ext simp [dist_comm, UniformSpace.ball] @[simp] theorem iUnion_ball_nat (x : α) : ⋃ n : ℕ, ball x n = univ := iUnion_eq_univ_iff.2 fun y => exists_nat_gt (dist y x) @[simp] theorem iUnion_ball_nat_succ (x : α) : ⋃ n : ℕ, ball x (n + 1) = univ := iUnion_eq_univ_iff.2 fun y => (exists_nat_gt (dist y x)).imp fun _ h => h.trans (lt_add_one _) /-- `closedBall x ε` is the set of all points `y` with `dist y x ≤ ε` -/ def closedBall (x : α) (ε : ℝ) := { y | dist y x ≤ ε } @[simp] theorem mem_closedBall : y ∈ closedBall x ε ↔ dist y x ≤ ε := Iff.rfl theorem mem_closedBall' : y ∈ closedBall x ε ↔ dist x y ≤ ε := by rw [dist_comm, mem_closedBall] /-- `sphere x ε` is the set of all points `y` with `dist y x = ε` -/ def sphere (x : α) (ε : ℝ) := { y | dist y x = ε } @[simp] theorem mem_sphere : y ∈ sphere x ε ↔ dist y x = ε := Iff.rfl theorem mem_sphere' : y ∈ sphere x ε ↔ dist x y = ε := by rw [dist_comm, mem_sphere] theorem ne_of_mem_sphere (h : y ∈ sphere x ε) (hε : ε ≠ 0) : y ≠ x := ne_of_mem_of_not_mem h <| by simpa using hε.symm theorem nonneg_of_mem_sphere (hy : y ∈ sphere x ε) : 0 ≤ ε := dist_nonneg.trans_eq hy @[simp] theorem sphere_eq_empty_of_neg (hε : ε < 0) : sphere x ε = ∅ := Set.eq_empty_iff_forall_not_mem.mpr fun _y hy => (nonneg_of_mem_sphere hy).not_lt hε theorem sphere_eq_empty_of_subsingleton [Subsingleton α] (hε : ε ≠ 0) : sphere x ε = ∅ := Set.eq_empty_iff_forall_not_mem.mpr fun _ h => ne_of_mem_sphere h hε (Subsingleton.elim _ _) instance sphere_isEmpty_of_subsingleton [Subsingleton α] [NeZero ε] : IsEmpty (sphere x ε) := by rw [sphere_eq_empty_of_subsingleton (NeZero.ne ε)]; infer_instance theorem closedBall_eq_singleton_of_subsingleton [Subsingleton α] (h : 0 ≤ ε) : closedBall x ε = {x} := by ext x' simpa [Subsingleton.allEq x x'] theorem ball_eq_singleton_of_subsingleton [Subsingleton α] (h : 0 < ε) : ball x ε = {x} := by ext x' simpa [Subsingleton.allEq x x'] theorem mem_closedBall_self (h : 0 ≤ ε) : x ∈ closedBall x ε := by rwa [mem_closedBall, dist_self] @[simp] theorem nonempty_closedBall : (closedBall x ε).Nonempty ↔ 0 ≤ ε := ⟨fun ⟨_x, hx⟩ => dist_nonneg.trans hx, fun h => ⟨x, mem_closedBall_self h⟩⟩ @[simp] theorem closedBall_eq_empty : closedBall x ε = ∅ ↔ ε < 0 := by rw [← not_nonempty_iff_eq_empty, nonempty_closedBall, not_le] /-- Closed balls and spheres coincide when the radius is non-positive -/ theorem closedBall_eq_sphere_of_nonpos (hε : ε ≤ 0) : closedBall x ε = sphere x ε := Set.ext fun _ => (hε.trans dist_nonneg).le_iff_eq theorem ball_subset_closedBall : ball x ε ⊆ closedBall x ε := fun _y hy => mem_closedBall.2 (le_of_lt hy) theorem sphere_subset_closedBall : sphere x ε ⊆ closedBall x ε := fun _ => le_of_eq lemma sphere_subset_ball {r R : ℝ} (h : r < R) : sphere x r ⊆ ball x R := fun _x hx ↦ (mem_sphere.1 hx).trans_lt h theorem closedBall_disjoint_ball (h : δ + ε ≤ dist x y) : Disjoint (closedBall x δ) (ball y ε) := Set.disjoint_left.mpr fun _a ha1 ha2 => (h.trans <| dist_triangle_left _ _ _).not_lt <| add_lt_add_of_le_of_lt ha1 ha2 theorem ball_disjoint_closedBall (h : δ + ε ≤ dist x y) : Disjoint (ball x δ) (closedBall y ε) := (closedBall_disjoint_ball <| by rwa [add_comm, dist_comm]).symm theorem ball_disjoint_ball (h : δ + ε ≤ dist x y) : Disjoint (ball x δ) (ball y ε) := (closedBall_disjoint_ball h).mono_left ball_subset_closedBall theorem closedBall_disjoint_closedBall (h : δ + ε < dist x y) : Disjoint (closedBall x δ) (closedBall y ε) := Set.disjoint_left.mpr fun _a ha1 ha2 => h.not_le <| (dist_triangle_left _ _ _).trans <| add_le_add ha1 ha2 theorem sphere_disjoint_ball : Disjoint (sphere x ε) (ball x ε) := Set.disjoint_left.mpr fun _y hy₁ hy₂ => absurd hy₁ <| ne_of_lt hy₂ @[simp] theorem ball_union_sphere : ball x ε ∪ sphere x ε = closedBall x ε := Set.ext fun _y => (@le_iff_lt_or_eq ℝ _ _ _).symm @[simp] theorem sphere_union_ball : sphere x ε ∪ ball x ε = closedBall x ε := by rw [union_comm, ball_union_sphere] @[simp] theorem closedBall_diff_sphere : closedBall x ε \ sphere x ε = ball x ε := by
rw [← ball_union_sphere, Set.union_diff_cancel_right sphere_disjoint_ball.symm.le_bot]
Mathlib/Topology/MetricSpace/Pseudo/Defs.lean
484
485
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker -/ import Mathlib.Algebra.Polynomial.Degree.Domain import Mathlib.Algebra.Polynomial.Degree.Support import Mathlib.Algebra.Polynomial.Eval.Coeff import Mathlib.GroupTheory.GroupAction.Ring /-! # The derivative map on polynomials ## Main definitions * `Polynomial.derivative`: The formal derivative of polynomials, expressed as a linear map. * `Polynomial.derivativeFinsupp`: Iterated derivatives as a finite support function. -/ noncomputable section open Finset open Polynomial open scoped Nat namespace Polynomial universe u v w y z variable {R : Type u} {S : Type v} {T : Type w} {ι : Type y} {A : Type z} {a b : R} {n : ℕ} section Derivative section Semiring variable [Semiring R] /-- `derivative p` is the formal derivative of the polynomial `p` -/ def derivative : R[X] →ₗ[R] R[X] where toFun p := p.sum fun n a => C (a * n) * X ^ (n - 1) map_add' p q := by rw [sum_add_index] <;> simp only [add_mul, forall_const, RingHom.map_add, eq_self_iff_true, zero_mul, RingHom.map_zero] map_smul' a p := by dsimp; rw [sum_smul_index] <;> simp only [mul_sum, ← C_mul', mul_assoc, coeff_C_mul, RingHom.map_mul, forall_const, zero_mul, RingHom.map_zero, sum] theorem derivative_apply (p : R[X]) : derivative p = p.sum fun n a => C (a * n) * X ^ (n - 1) := rfl theorem coeff_derivative (p : R[X]) (n : ℕ) : coeff (derivative p) n = coeff p (n + 1) * (n + 1) := by rw [derivative_apply] simp only [coeff_X_pow, coeff_sum, coeff_C_mul] rw [sum, Finset.sum_eq_single (n + 1)] · simp only [Nat.add_succ_sub_one, add_zero, mul_one, if_true, eq_self_iff_true]; norm_cast · intro b cases b · intros rw [Nat.cast_zero, mul_zero, zero_mul] · intro _ H rw [Nat.add_one_sub_one, if_neg (mt (congr_arg Nat.succ) H.symm), mul_zero] · rw [if_pos (add_tsub_cancel_right n 1).symm, mul_one, Nat.cast_add, Nat.cast_one, mem_support_iff] intro h push_neg at h simp [h] @[simp] theorem derivative_zero : derivative (0 : R[X]) = 0 := derivative.map_zero theorem iterate_derivative_zero {k : ℕ} : derivative^[k] (0 : R[X]) = 0 := iterate_map_zero derivative k theorem derivative_monomial (a : R) (n : ℕ) : derivative (monomial n a) = monomial (n - 1) (a * n) := by rw [derivative_apply, sum_monomial_index, C_mul_X_pow_eq_monomial] simp @[simp] theorem derivative_monomial_succ (a : R) (n : ℕ) : derivative (monomial (n + 1) a) = monomial n (a * (n + 1)) := by rw [derivative_monomial, add_tsub_cancel_right, Nat.cast_add, Nat.cast_one] theorem derivative_C_mul_X (a : R) : derivative (C a * X) = C a := by simp [C_mul_X_eq_monomial, derivative_monomial, Nat.cast_one, mul_one] theorem derivative_C_mul_X_pow (a : R) (n : ℕ) : derivative (C a * X ^ n) = C (a * n) * X ^ (n - 1) := by rw [C_mul_X_pow_eq_monomial, C_mul_X_pow_eq_monomial, derivative_monomial] theorem derivative_C_mul_X_sq (a : R) : derivative (C a * X ^ 2) = C (a * 2) * X := by rw [derivative_C_mul_X_pow, Nat.cast_two, pow_one] theorem derivative_X_pow (n : ℕ) : derivative (X ^ n : R[X]) = C (n : R) * X ^ (n - 1) := by convert derivative_C_mul_X_pow (1 : R) n <;> simp @[simp] theorem derivative_X_pow_succ (n : ℕ) : derivative (X ^ (n + 1) : R[X]) = C (n + 1 : R) * X ^ n := by simp [derivative_X_pow] theorem derivative_X_sq : derivative (X ^ 2 : R[X]) = C 2 * X := by rw [derivative_X_pow, Nat.cast_two, pow_one] @[simp] theorem derivative_C {a : R} : derivative (C a) = 0 := by simp [derivative_apply] theorem derivative_of_natDegree_zero {p : R[X]} (hp : p.natDegree = 0) : derivative p = 0 := by rw [eq_C_of_natDegree_eq_zero hp, derivative_C] @[simp] theorem derivative_X : derivative (X : R[X]) = 1 := (derivative_monomial _ _).trans <| by simp @[simp] theorem derivative_one : derivative (1 : R[X]) = 0 := derivative_C @[simp] theorem derivative_add {f g : R[X]} : derivative (f + g) = derivative f + derivative g := derivative.map_add f g theorem derivative_X_add_C (c : R) : derivative (X + C c) = 1 := by rw [derivative_add, derivative_X, derivative_C, add_zero] theorem derivative_sum {s : Finset ι} {f : ι → R[X]} : derivative (∑ b ∈ s, f b) = ∑ b ∈ s, derivative (f b) := map_sum .. theorem iterate_derivative_sum (k : ℕ) (s : Finset ι) (f : ι → R[X]) : derivative^[k] (∑ b ∈ s, f b) = ∑ b ∈ s, derivative^[k] (f b) := by simp_rw [← Module.End.pow_apply, map_sum] theorem derivative_smul {S : Type*} [SMulZeroClass S R] [IsScalarTower S R R] (s : S) (p : R[X]) : derivative (s • p) = s • derivative p := derivative.map_smul_of_tower s p @[simp] theorem iterate_derivative_smul {S : Type*} [SMulZeroClass S R] [IsScalarTower S R R] (s : S) (p : R[X]) (k : ℕ) : derivative^[k] (s • p) = s • derivative^[k] p := by induction k generalizing p with | zero => simp | succ k ih => simp [ih] @[simp] theorem iterate_derivative_C_mul (a : R) (p : R[X]) (k : ℕ) : derivative^[k] (C a * p) = C a * derivative^[k] p := by simp_rw [← smul_eq_C_mul, iterate_derivative_smul] theorem derivative_C_mul (a : R) (p : R[X]) : derivative (C a * p) = C a * derivative p := iterate_derivative_C_mul _ _ 1 theorem of_mem_support_derivative {p : R[X]} {n : ℕ} (h : n ∈ p.derivative.support) : n + 1 ∈ p.support := mem_support_iff.2 fun h1 : p.coeff (n + 1) = 0 => mem_support_iff.1 h <| show p.derivative.coeff n = 0 by rw [coeff_derivative, h1, zero_mul] theorem degree_derivative_lt {p : R[X]} (hp : p ≠ 0) : p.derivative.degree < p.degree := (Finset.sup_lt_iff <| bot_lt_iff_ne_bot.2 <| mt degree_eq_bot.1 hp).2 fun n hp => lt_of_lt_of_le (WithBot.coe_lt_coe.2 n.lt_succ_self) <| Finset.le_sup <| of_mem_support_derivative hp theorem degree_derivative_le {p : R[X]} : p.derivative.degree ≤ p.degree := letI := Classical.decEq R if H : p = 0 then le_of_eq <| by rw [H, derivative_zero] else (degree_derivative_lt H).le theorem natDegree_derivative_lt {p : R[X]} (hp : p.natDegree ≠ 0) : p.derivative.natDegree < p.natDegree := by rcases eq_or_ne (derivative p) 0 with hp' | hp' · rw [hp', Polynomial.natDegree_zero] exact hp.bot_lt · rw [natDegree_lt_natDegree_iff hp'] exact degree_derivative_lt fun h => hp (h.symm ▸ natDegree_zero) theorem natDegree_derivative_le (p : R[X]) : p.derivative.natDegree ≤ p.natDegree - 1 := by by_cases p0 : p.natDegree = 0 · simp [p0, derivative_of_natDegree_zero] · exact Nat.le_sub_one_of_lt (natDegree_derivative_lt p0) theorem natDegree_iterate_derivative (p : R[X]) (k : ℕ) : (derivative^[k] p).natDegree ≤ p.natDegree - k := by induction k with | zero => rw [Function.iterate_zero_apply, Nat.sub_zero] | succ d hd => rw [Function.iterate_succ_apply', Nat.sub_succ'] exact (natDegree_derivative_le _).trans <| Nat.sub_le_sub_right hd 1 @[simp] theorem derivative_natCast {n : ℕ} : derivative (n : R[X]) = 0 := by rw [← map_natCast C n] exact derivative_C @[simp] theorem derivative_ofNat (n : ℕ) [n.AtLeastTwo] : derivative (ofNat(n) : R[X]) = 0 := derivative_natCast theorem iterate_derivative_eq_zero {p : R[X]} {x : ℕ} (hx : p.natDegree < x) : Polynomial.derivative^[x] p = 0 := by induction' h : p.natDegree using Nat.strong_induction_on with _ ih generalizing p x subst h obtain ⟨t, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (pos_of_gt hx).ne' rw [Function.iterate_succ_apply] by_cases hp : p.natDegree = 0 · rw [derivative_of_natDegree_zero hp, iterate_derivative_zero] have := natDegree_derivative_lt hp exact ih _ this (this.trans_le <| Nat.le_of_lt_succ hx) rfl @[simp] theorem iterate_derivative_C {k} (h : 0 < k) : derivative^[k] (C a : R[X]) = 0 := iterate_derivative_eq_zero <| (natDegree_C _).trans_lt h @[simp] theorem iterate_derivative_one {k} (h : 0 < k) : derivative^[k] (1 : R[X]) = 0 := iterate_derivative_C h @[simp] theorem iterate_derivative_X {k} (h : 1 < k) : derivative^[k] (X : R[X]) = 0 := iterate_derivative_eq_zero <| natDegree_X_le.trans_lt h theorem natDegree_eq_zero_of_derivative_eq_zero [NoZeroSMulDivisors ℕ R] {f : R[X]} (h : derivative f = 0) : f.natDegree = 0 := by rcases eq_or_ne f 0 with (rfl | hf) · exact natDegree_zero rw [natDegree_eq_zero_iff_degree_le_zero] by_contra! f_nat_degree_pos rw [← natDegree_pos_iff_degree_pos] at f_nat_degree_pos let m := f.natDegree - 1 have hm : m + 1 = f.natDegree := tsub_add_cancel_of_le f_nat_degree_pos have h2 := coeff_derivative f m rw [Polynomial.ext_iff] at h rw [h m, coeff_zero, ← Nat.cast_add_one, ← nsmul_eq_mul', eq_comm, smul_eq_zero] at h2 replace h2 := h2.resolve_left m.succ_ne_zero rw [hm, ← leadingCoeff, leadingCoeff_eq_zero] at h2 exact hf h2 theorem eq_C_of_derivative_eq_zero [NoZeroSMulDivisors ℕ R] {f : R[X]} (h : derivative f = 0) : f = C (f.coeff 0) := eq_C_of_natDegree_eq_zero <| natDegree_eq_zero_of_derivative_eq_zero h @[simp] theorem derivative_mul {f g : R[X]} : derivative (f * g) = derivative f * g + f * derivative g := by induction f using Polynomial.induction_on' with | add => simp only [add_mul, map_add, add_assoc, add_left_comm, *] | monomial m a => ?_ induction g using Polynomial.induction_on' with | add => simp only [mul_add, map_add, add_assoc, add_left_comm, *] | monomial n b => ?_ simp only [monomial_mul_monomial, derivative_monomial] simp only [mul_assoc, (Nat.cast_commute _ _).eq, Nat.cast_add, mul_add, map_add] cases m with | zero => simp only [zero_add, Nat.cast_zero, mul_zero, map_zero] | succ m => cases n with | zero => simp only [add_zero, Nat.cast_zero, mul_zero, map_zero] | succ n => simp only [Nat.add_succ_sub_one, add_tsub_cancel_right] rw [add_assoc, add_comm n 1] theorem derivative_eval (p : R[X]) (x : R) : p.derivative.eval x = p.sum fun n a => a * n * x ^ (n - 1) := by simp_rw [derivative_apply, eval_sum, eval_mul_X_pow, eval_C] @[simp] theorem derivative_map [Semiring S] (p : R[X]) (f : R →+* S) : derivative (p.map f) = p.derivative.map f := by let n := max p.natDegree (map f p).natDegree rw [derivative_apply, derivative_apply] rw [sum_over_range' _ _ (n + 1) ((le_max_left _ _).trans_lt (lt_add_one _))] on_goal 1 => rw [sum_over_range' _ _ (n + 1) ((le_max_right _ _).trans_lt (lt_add_one _))] · simp only [Polynomial.map_sum, Polynomial.map_mul, Polynomial.map_C, map_mul, coeff_map, map_natCast, Polynomial.map_natCast, Polynomial.map_pow, map_X] all_goals intro n; rw [zero_mul, C_0, zero_mul] @[simp] theorem iterate_derivative_map [Semiring S] (p : R[X]) (f : R →+* S) (k : ℕ) : Polynomial.derivative^[k] (p.map f) = (Polynomial.derivative^[k] p).map f := by induction' k with k ih generalizing p · simp · simp only [ih, Function.iterate_succ, Polynomial.derivative_map, Function.comp_apply]
theorem derivative_natCast_mul {n : ℕ} {f : R[X]} : derivative ((n : R[X]) * f) = n * derivative f := by simp @[simp] theorem iterate_derivative_natCast_mul {n k : ℕ} {f : R[X]} : derivative^[k] ((n : R[X]) * f) = n * derivative^[k] f := by induction' k with k ih generalizing f <;> simp [*] theorem mem_support_derivative [NoZeroSMulDivisors ℕ R] (p : R[X]) (n : ℕ) : n ∈ (derivative p).support ↔ n + 1 ∈ p.support := by suffices ¬p.coeff (n + 1) * (n + 1 : ℕ) = 0 ↔ coeff p (n + 1) ≠ 0 by simpa only [mem_support_iff, coeff_derivative, Ne, Nat.cast_succ] rw [← nsmul_eq_mul', smul_eq_zero] simp only [Nat.succ_ne_zero, false_or]
Mathlib/Algebra/Polynomial/Derivative.lean
288
304
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Robert Y. Lewis -/ import Mathlib.RingTheory.WittVector.StructurePolynomial /-! # Witt vectors In this file we define the type of `p`-typical Witt vectors and ring operations on it. The ring axioms are verified in `Mathlib/RingTheory/WittVector/Basic.lean`. For a fixed commutative ring `R` and prime `p`, a Witt vector `x : 𝕎 R` is an infinite sequence `ℕ → R` of elements of `R`. However, the ring operations `+` and `*` are not defined in the obvious component-wise way. Instead, these operations are defined via certain polynomials using the machinery in `Mathlib/RingTheory/WittVector/StructurePolynomial.lean`. The `n`th value of the sum of two Witt vectors can depend on the `0`-th through `n`th values of the summands. This effectively simulates a “carrying” operation. ## Main definitions * `WittVector p R`: the type of `p`-typical Witt vectors with coefficients in `R`. * `WittVector.coeff x n`: projects the `n`th value of the Witt vector `x`. ## Notation We use notation `𝕎 R`, entered `\bbW`, for the Witt vectors over `R`. ## References * [Hazewinkel, *Witt Vectors*][Haze09] * [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21] -/ noncomputable section /-- `WittVector p R` is the ring of `p`-typical Witt vectors over the commutative ring `R`, where `p` is a prime number. If `p` is invertible in `R`, this ring is isomorphic to `ℕ → R` (the product of `ℕ` copies of `R`). If `R` is a ring of characteristic `p`, then `WittVector p R` is a ring of characteristic `0`. The canonical example is `WittVector p (ZMod p)`, which is isomorphic to the `p`-adic integers `ℤ_[p]`. -/ structure WittVector (p : ℕ) (R : Type*) where mk' :: /-- `x.coeff n` is the `n`th coefficient of the Witt vector `x`. This concept does not have a standard name in the literature. -/ coeff : ℕ → R -- Porting note: added to make the `p` argument explicit /-- Construct a Witt vector `mk p x : 𝕎 R` from a sequence `x` of elements of `R`. -/ def WittVector.mk (p : ℕ) {R : Type*} (coeff : ℕ → R) : WittVector p R := mk' coeff variable {p : ℕ} /- We cannot make this `localized` notation, because the `p` on the RHS doesn't occur on the left Hiding the `p` in the notation is very convenient, so we opt for repeating the `local notation` in other files that use Witt vectors. -/ local notation "𝕎" => WittVector p -- type as `\bbW` namespace WittVector variable {R : Type*} @[ext] theorem ext {x y : 𝕎 R} (h : ∀ n, x.coeff n = y.coeff n) : x = y := by cases x cases y simp only at h simp [funext_iff, h] variable (p) theorem coeff_mk (x : ℕ → R) : (mk p x).coeff = x := rfl /- These instances are not needed for the rest of the development, but it is interesting to establish early on that `WittVector p` is a lawful functor. -/ instance : Functor (WittVector p) where map f v := mk p (f ∘ v.coeff) mapConst a _ := mk p fun _ => a instance : LawfulFunctor (WittVector p) where map_const := rfl -- Porting note: no longer needs to deconstruct `v` to conclude `{coeff := v.coeff} = v` id_map _ := rfl comp_map _ _ _ := rfl variable [hp : Fact p.Prime] [CommRing R] open MvPolynomial section RingOperations /-- The polynomials used for defining the element `0` of the ring of Witt vectors. -/ def wittZero : ℕ → MvPolynomial (Fin 0 × ℕ) ℤ := wittStructureInt p 0 /-- The polynomials used for defining the element `1` of the ring of Witt vectors. -/ def wittOne : ℕ → MvPolynomial (Fin 0 × ℕ) ℤ := wittStructureInt p 1 /-- The polynomials used for defining the addition of the ring of Witt vectors. -/ def wittAdd : ℕ → MvPolynomial (Fin 2 × ℕ) ℤ := wittStructureInt p (X 0 + X 1) /-- The polynomials used for defining repeated addition of the ring of Witt vectors. -/ def wittNSMul (n : ℕ) : ℕ → MvPolynomial (Fin 1 × ℕ) ℤ := wittStructureInt p (n • X (0 : (Fin 1))) /-- The polynomials used for defining repeated addition of the ring of Witt vectors. -/ def wittZSMul (n : ℤ) : ℕ → MvPolynomial (Fin 1 × ℕ) ℤ := wittStructureInt p (n • X (0 : (Fin 1))) /-- The polynomials used for describing the subtraction of the ring of Witt vectors. -/ def wittSub : ℕ → MvPolynomial (Fin 2 × ℕ) ℤ := wittStructureInt p (X 0 - X 1) /-- The polynomials used for defining the multiplication of the ring of Witt vectors. -/ def wittMul : ℕ → MvPolynomial (Fin 2 × ℕ) ℤ := wittStructureInt p (X 0 * X 1) /-- The polynomials used for defining the negation of the ring of Witt vectors. -/ def wittNeg : ℕ → MvPolynomial (Fin 1 × ℕ) ℤ := wittStructureInt p (-X 0) /-- The polynomials used for defining repeated addition of the ring of Witt vectors. -/ def wittPow (n : ℕ) : ℕ → MvPolynomial (Fin 1 × ℕ) ℤ := wittStructureInt p (X 0 ^ n) variable {p} /-- An auxiliary definition used in `WittVector.eval`. Evaluates a polynomial whose variables come from the disjoint union of `k` copies of `ℕ`, with a curried evaluation `x`. This can be defined more generally but we use only a specific instance here. -/ def peval {k : ℕ} (φ : MvPolynomial (Fin k × ℕ) ℤ) (x : Fin k → ℕ → R) : R := aeval (Function.uncurry x) φ /-- Let `φ` be a family of polynomials, indexed by natural numbers, whose variables come from the disjoint union of `k` copies of `ℕ`, and let `xᵢ` be a Witt vector for `0 ≤ i < k`. `eval φ x` evaluates `φ` mapping the variable `X_(i, n)` to the `n`th coefficient of `xᵢ`. Instantiating `φ` with certain polynomials defined in `Mathlib/RingTheory/WittVector/StructurePolynomial.lean` establishes the ring operations on `𝕎 R`. For example, `WittVector.wittAdd` is such a `φ` with `k = 2`; evaluating this at `(x₀, x₁)` gives us the sum of two Witt vectors `x₀ + x₁`. -/ def eval {k : ℕ} (φ : ℕ → MvPolynomial (Fin k × ℕ) ℤ) (x : Fin k → 𝕎 R) : 𝕎 R := mk p fun n => peval (φ n) fun i => (x i).coeff instance : Zero (𝕎 R) := ⟨eval (wittZero p) ![]⟩ instance : Inhabited (𝕎 R) := ⟨0⟩ instance : One (𝕎 R) := ⟨eval (wittOne p) ![]⟩ instance : Add (𝕎 R) := ⟨fun x y => eval (wittAdd p) ![x, y]⟩ instance : Sub (𝕎 R) := ⟨fun x y => eval (wittSub p) ![x, y]⟩ instance hasNatScalar : SMul ℕ (𝕎 R) := ⟨fun n x => eval (wittNSMul p n) ![x]⟩ instance hasIntScalar : SMul ℤ (𝕎 R) := ⟨fun n x => eval (wittZSMul p n) ![x]⟩ instance : Mul (𝕎 R) := ⟨fun x y => eval (wittMul p) ![x, y]⟩ instance : Neg (𝕎 R) := ⟨fun x => eval (wittNeg p) ![x]⟩ instance hasNatPow : Pow (𝕎 R) ℕ := ⟨fun x n => eval (wittPow p n) ![x]⟩ instance : NatCast (𝕎 R) := ⟨Nat.unaryCast⟩ instance : IntCast (𝕎 R) := ⟨Int.castDef⟩ end RingOperations section WittStructureSimplifications @[simp] theorem wittZero_eq_zero (n : ℕ) : wittZero p n = 0 := by apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective simp only [wittZero, wittStructureRat, bind₁, aeval_zero', constantCoeff_xInTermsOfW, map_zero, map_wittStructureInt] @[simp] theorem wittOne_zero_eq_one : wittOne p 0 = 1 := by apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective simp only [wittOne, wittStructureRat, xInTermsOfW_zero, map_one, bind₁_X_right, map_wittStructureInt] @[simp] theorem wittOne_pos_eq_zero (n : ℕ) (hn : 0 < n) : wittOne p n = 0 := by apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective simp only [wittOne, wittStructureRat, RingHom.map_zero, map_one, RingHom.map_one, map_wittStructureInt] induction n using Nat.strong_induction_on with | h n IH => ?_ rw [xInTermsOfW_eq] simp only [map_mul, map_sub, map_sum, map_pow, bind₁_X_right, bind₁_C_right] rw [sub_mul, one_mul] rw [Finset.sum_eq_single 0] · simp only [invOf_eq_inv, one_mul, inv_pow, tsub_zero, RingHom.map_one, pow_zero] simp only [one_pow, one_mul, xInTermsOfW_zero, sub_self, bind₁_X_right] · intro i hin hi0 rw [Finset.mem_range] at hin rw [IH _ hin (Nat.pos_of_ne_zero hi0), zero_pow (pow_ne_zero _ hp.1.ne_zero), mul_zero] · rw [Finset.mem_range]; intro; contradiction @[simp] theorem wittAdd_zero : wittAdd p 0 = X (0, 0) + X (1, 0) := by apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective simp only [wittAdd, wittStructureRat, map_add, rename_X, xInTermsOfW_zero, map_X, wittPolynomial_zero, bind₁_X_right, map_wittStructureInt] @[simp] theorem wittSub_zero : wittSub p 0 = X (0, 0) - X (1, 0) := by apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective simp only [wittSub, wittStructureRat, map_sub, rename_X, xInTermsOfW_zero, map_X, wittPolynomial_zero, bind₁_X_right, map_wittStructureInt] @[simp] theorem wittMul_zero : wittMul p 0 = X (0, 0) * X (1, 0) := by apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective simp only [wittMul, wittStructureRat, rename_X, xInTermsOfW_zero, map_X, wittPolynomial_zero, map_mul, bind₁_X_right, map_wittStructureInt] @[simp] theorem wittNeg_zero : wittNeg p 0 = -X (0, 0) := by apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective simp only [wittNeg, wittStructureRat, rename_X, xInTermsOfW_zero, map_X, wittPolynomial_zero, map_neg, bind₁_X_right, map_wittStructureInt] @[simp] theorem constantCoeff_wittAdd (n : ℕ) : constantCoeff (wittAdd p n) = 0 := by apply constantCoeff_wittStructureInt p _ _ n simp only [add_zero, RingHom.map_add, constantCoeff_X] @[simp] theorem constantCoeff_wittSub (n : ℕ) : constantCoeff (wittSub p n) = 0 := by apply constantCoeff_wittStructureInt p _ _ n simp only [sub_zero, RingHom.map_sub, constantCoeff_X] @[simp] theorem constantCoeff_wittMul (n : ℕ) : constantCoeff (wittMul p n) = 0 := by apply constantCoeff_wittStructureInt p _ _ n simp only [mul_zero, RingHom.map_mul, constantCoeff_X] @[simp] theorem constantCoeff_wittNeg (n : ℕ) : constantCoeff (wittNeg p n) = 0 := by apply constantCoeff_wittStructureInt p _ _ n simp only [neg_zero, RingHom.map_neg, constantCoeff_X] @[simp] theorem constantCoeff_wittNSMul (m : ℕ) (n : ℕ) : constantCoeff (wittNSMul p m n) = 0 := by apply constantCoeff_wittStructureInt p _ _ n simp only [smul_zero, map_nsmul, constantCoeff_X] @[simp] theorem constantCoeff_wittZSMul (z : ℤ) (n : ℕ) : constantCoeff (wittZSMul p z n) = 0 := by apply constantCoeff_wittStructureInt p _ _ n simp only [smul_zero, map_zsmul, constantCoeff_X] end WittStructureSimplifications section Coeff variable (R) @[simp] theorem zero_coeff (n : ℕ) : (0 : 𝕎 R).coeff n = 0 := show (aeval _ (wittZero p n) : R) = 0 by simp only [wittZero_eq_zero, map_zero] @[simp] theorem one_coeff_zero : (1 : 𝕎 R).coeff 0 = 1 := show (aeval _ (wittOne p 0) : R) = 1 by simp only [wittOne_zero_eq_one, map_one] @[simp] theorem one_coeff_eq_of_pos (n : ℕ) (hn : 0 < n) : coeff (1 : 𝕎 R) n = 0 := show (aeval _ (wittOne p n) : R) = 0 by simp only [hn, wittOne_pos_eq_zero, map_zero] variable {p R} @[simp] theorem v2_coeff {p' R'} (x y : WittVector p' R') (i : Fin 2) : (![x, y] i).coeff = ![x.coeff, y.coeff] i := by fin_cases i <;> simp -- Porting note: the lemmas below needed `coeff_mk` added to the `simp` calls theorem add_coeff (x y : 𝕎 R) (n : ℕ) : (x + y).coeff n = peval (wittAdd p n) ![x.coeff, y.coeff] := by simp [(· + ·), Add.add, eval, coeff_mk] theorem sub_coeff (x y : 𝕎 R) (n : ℕ) : (x - y).coeff n = peval (wittSub p n) ![x.coeff, y.coeff] := by simp [(· - ·), Sub.sub, eval, coeff_mk] theorem mul_coeff (x y : 𝕎 R) (n : ℕ) : (x * y).coeff n = peval (wittMul p n) ![x.coeff, y.coeff] := by simp [(· * ·), Mul.mul, eval, coeff_mk] theorem neg_coeff (x : 𝕎 R) (n : ℕ) : (-x).coeff n = peval (wittNeg p n) ![x.coeff] := by simp [Neg.neg, eval, Matrix.cons_fin_one, coeff_mk] theorem nsmul_coeff (m : ℕ) (x : 𝕎 R) (n : ℕ) : (m • x).coeff n = peval (wittNSMul p m n) ![x.coeff] := by simp [(· • ·), SMul.smul, eval, Matrix.cons_fin_one, coeff_mk] theorem zsmul_coeff (m : ℤ) (x : 𝕎 R) (n : ℕ) : (m • x).coeff n = peval (wittZSMul p m n) ![x.coeff] := by simp [(· • ·), SMul.smul, eval, Matrix.cons_fin_one, coeff_mk] theorem pow_coeff (m : ℕ) (x : 𝕎 R) (n : ℕ) : (x ^ m).coeff n = peval (wittPow p m n) ![x.coeff] := by simp [(· ^ ·), Pow.pow, eval, Matrix.cons_fin_one, coeff_mk] theorem add_coeff_zero (x y : 𝕎 R) : (x + y).coeff 0 = x.coeff 0 + y.coeff 0 := by simp [add_coeff, peval, Function.uncurry] theorem mul_coeff_zero (x y : 𝕎 R) : (x * y).coeff 0 = x.coeff 0 * y.coeff 0 := by simp [mul_coeff, peval, Function.uncurry] end Coeff theorem wittAdd_vars (n : ℕ) : (wittAdd p n).vars ⊆ Finset.univ ×ˢ Finset.range (n + 1) :=
wittStructureInt_vars _ _ _
Mathlib/RingTheory/WittVector/Defs.lean
345
346
/- 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, Yury Kudryashov, David Loeffler -/ import Mathlib.Analysis.Convex.Slope import Mathlib.Analysis.Calculus.Deriv.MeanValue /-! # Convexity of functions and derivatives Here we relate convexity of functions `ℝ → ℝ` to properties of their derivatives. ## Main results * `MonotoneOn.convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `ConvexOn.monotoneOn_deriv`: if a function is convex and differentiable, then its derivative is monotone. -/ open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Topology NNReal /-! ## Monotonicity of `f'` implies convexity of `f` -/ /-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is differentiable on its interior, and `f'` is monotone on the interior, then `f` is convex on `D`. -/ theorem MonotoneOn.convexOn_of_deriv {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : DifferentiableOn ℝ f (interior D)) (hf'_mono : MonotoneOn (deriv f) (interior D)) : ConvexOn ℝ D f := convexOn_of_slope_mono_adjacent hD (by intro x y z hx hz hxy hyz -- First we prove some trivial inclusions have hxzD : Icc x z ⊆ D := hD.ordConnected.out hx hz have hxyD : Icc x y ⊆ D := (Icc_subset_Icc_right hyz.le).trans hxzD have hxyD' : Ioo x y ⊆ interior D := subset_sUnion_of_mem ⟨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyD⟩ have hyzD : Icc y z ⊆ D := (Icc_subset_Icc_left hxy.le).trans hxzD have hyzD' : Ioo y z ⊆ interior D := subset_sUnion_of_mem ⟨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzD⟩ -- Then we apply MVT to both `[x, y]` and `[y, z]` obtain ⟨a, ⟨hxa, hay⟩, ha⟩ : ∃ a ∈ Ioo x y, deriv f a = (f y - f x) / (y - x) := exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD') obtain ⟨b, ⟨hyb, hbz⟩, hb⟩ : ∃ b ∈ Ioo y z, deriv f b = (f z - f y) / (z - y) := exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD') rw [← ha, ← hb] exact hf'_mono (hxyD' ⟨hxa, hay⟩) (hyzD' ⟨hyb, hbz⟩) (hay.trans hyb).le) /-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is differentiable on its interior, and `f'` is antitone on the interior, then `f` is concave on `D`. -/ theorem AntitoneOn.concaveOn_of_deriv {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : DifferentiableOn ℝ f (interior D)) (h_anti : AntitoneOn (deriv f) (interior D)) : ConcaveOn ℝ D f := haveI : MonotoneOn (deriv (-f)) (interior D) := by simpa only [← deriv.neg] using h_anti.neg neg_convexOn_iff.mp (this.convexOn_of_deriv hD hf.neg hf'.neg) theorem StrictMonoOn.exists_slope_lt_deriv_aux {x y : ℝ} {f : ℝ → ℝ} (hf : ContinuousOn f (Icc x y)) (hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : ∀ w ∈ Ioo x y, deriv f w ≠ 0) : ∃ a ∈ Ioo x y, (f y - f x) / (y - x) < deriv f a := by have A : DifferentiableOn ℝ f (Ioo x y) := fun w wmem => (differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt obtain ⟨a, ⟨hxa, hay⟩, ha⟩ : ∃ a ∈ Ioo x y, deriv f a = (f y - f x) / (y - x) := exists_deriv_eq_slope f hxy hf A rcases nonempty_Ioo.2 hay with ⟨b, ⟨hab, hby⟩⟩ refine ⟨b, ⟨hxa.trans hab, hby⟩, ?_⟩ rw [← ha] exact hf'_mono ⟨hxa, hay⟩ ⟨hxa.trans hab, hby⟩ hab theorem StrictMonoOn.exists_slope_lt_deriv {x y : ℝ} {f : ℝ → ℝ} (hf : ContinuousOn f (Icc x y)) (hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) : ∃ a ∈ Ioo x y, (f y - f x) / (y - x) < deriv f a := by by_cases h : ∀ w ∈ Ioo x y, deriv f w ≠ 0 · apply StrictMonoOn.exists_slope_lt_deriv_aux hf hxy hf'_mono h · push_neg at h rcases h with ⟨w, ⟨hxw, hwy⟩, hw⟩ obtain ⟨a, ⟨hxa, haw⟩, ha⟩ : ∃ a ∈ Ioo x w, (f w - f x) / (w - x) < deriv f a := by apply StrictMonoOn.exists_slope_lt_deriv_aux _ hxw _ _ · exact hf.mono (Icc_subset_Icc le_rfl hwy.le) · exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le) · intro z hz rw [← hw] apply ne_of_lt exact hf'_mono ⟨hz.1, hz.2.trans hwy⟩ ⟨hxw, hwy⟩ hz.2 obtain ⟨b, ⟨hwb, hby⟩, hb⟩ : ∃ b ∈ Ioo w y, (f y - f w) / (y - w) < deriv f b := by apply StrictMonoOn.exists_slope_lt_deriv_aux _ hwy _ _ · refine hf.mono (Icc_subset_Icc hxw.le le_rfl) · exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl) · intro z hz rw [← hw] apply ne_of_gt exact hf'_mono ⟨hxw, hwy⟩ ⟨hxw.trans hz.1, hz.2⟩ hz.1 refine ⟨b, ⟨hxw.trans hwb, hby⟩, ?_⟩ simp only [div_lt_iff₀, hxy, hxw, hwy, sub_pos] at ha hb ⊢ have : deriv f a * (w - x) < deriv f b * (w - x) := by apply mul_lt_mul _ le_rfl (sub_pos.2 hxw) _ · exact hf'_mono ⟨hxa, haw.trans hwy⟩ ⟨hxw.trans hwb, hby⟩ (haw.trans hwb) · rw [← hw] exact (hf'_mono ⟨hxw, hwy⟩ ⟨hxw.trans hwb, hby⟩ hwb).le linarith theorem StrictMonoOn.exists_deriv_lt_slope_aux {x y : ℝ} {f : ℝ → ℝ} (hf : ContinuousOn f (Icc x y)) (hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) (h : ∀ w ∈ Ioo x y, deriv f w ≠ 0) : ∃ a ∈ Ioo x y, deriv f a < (f y - f x) / (y - x) := by have A : DifferentiableOn ℝ f (Ioo x y) := fun w wmem => (differentiableAt_of_deriv_ne_zero (h w wmem)).differentiableWithinAt obtain ⟨a, ⟨hxa, hay⟩, ha⟩ : ∃ a ∈ Ioo x y, deriv f a = (f y - f x) / (y - x) := exists_deriv_eq_slope f hxy hf A rcases nonempty_Ioo.2 hxa with ⟨b, ⟨hxb, hba⟩⟩ refine ⟨b, ⟨hxb, hba.trans hay⟩, ?_⟩ rw [← ha] exact hf'_mono ⟨hxb, hba.trans hay⟩ ⟨hxa, hay⟩ hba theorem StrictMonoOn.exists_deriv_lt_slope {x y : ℝ} {f : ℝ → ℝ} (hf : ContinuousOn f (Icc x y)) (hxy : x < y) (hf'_mono : StrictMonoOn (deriv f) (Ioo x y)) : ∃ a ∈ Ioo x y, deriv f a < (f y - f x) / (y - x) := by by_cases h : ∀ w ∈ Ioo x y, deriv f w ≠ 0 · apply StrictMonoOn.exists_deriv_lt_slope_aux hf hxy hf'_mono h · push_neg at h rcases h with ⟨w, ⟨hxw, hwy⟩, hw⟩ obtain ⟨a, ⟨hxa, haw⟩, ha⟩ : ∃ a ∈ Ioo x w, deriv f a < (f w - f x) / (w - x) := by apply StrictMonoOn.exists_deriv_lt_slope_aux _ hxw _ _ · exact hf.mono (Icc_subset_Icc le_rfl hwy.le) · exact hf'_mono.mono (Ioo_subset_Ioo le_rfl hwy.le) · intro z hz rw [← hw] apply ne_of_lt exact hf'_mono ⟨hz.1, hz.2.trans hwy⟩ ⟨hxw, hwy⟩ hz.2 obtain ⟨b, ⟨hwb, hby⟩, hb⟩ : ∃ b ∈ Ioo w y, deriv f b < (f y - f w) / (y - w) := by apply StrictMonoOn.exists_deriv_lt_slope_aux _ hwy _ _ · refine hf.mono (Icc_subset_Icc hxw.le le_rfl) · exact hf'_mono.mono (Ioo_subset_Ioo hxw.le le_rfl) · intro z hz rw [← hw] apply ne_of_gt exact hf'_mono ⟨hxw, hwy⟩ ⟨hxw.trans hz.1, hz.2⟩ hz.1 refine ⟨a, ⟨hxa, haw.trans hwy⟩, ?_⟩ simp only [lt_div_iff₀, hxy, hxw, hwy, sub_pos] at ha hb ⊢ have : deriv f a * (y - w) < deriv f b * (y - w) := by apply mul_lt_mul _ le_rfl (sub_pos.2 hwy) _ · exact hf'_mono ⟨hxa, haw.trans hwy⟩ ⟨hxw.trans hwb, hby⟩ (haw.trans hwb) · rw [← hw] exact (hf'_mono ⟨hxw, hwy⟩ ⟨hxw.trans hwb, hby⟩ hwb).le linarith /-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, and `f'` is strictly monotone on the interior, then `f` is strictly convex on `D`. Note that we don't require differentiability, since it is guaranteed at all but at most one point by the strict monotonicity of `f'`. -/ theorem StrictMonoOn.strictConvexOn_of_deriv {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : StrictMonoOn (deriv f) (interior D)) : StrictConvexOn ℝ D f := strictConvexOn_of_slope_strict_mono_adjacent hD fun {x y z} hx hz hxy hyz => by -- First we prove some trivial inclusions have hxzD : Icc x z ⊆ D := hD.ordConnected.out hx hz have hxyD : Icc x y ⊆ D := (Icc_subset_Icc_right hyz.le).trans hxzD have hxyD' : Ioo x y ⊆ interior D := subset_sUnion_of_mem ⟨isOpen_Ioo, Ioo_subset_Icc_self.trans hxyD⟩ have hyzD : Icc y z ⊆ D := (Icc_subset_Icc_left hxy.le).trans hxzD have hyzD' : Ioo y z ⊆ interior D := subset_sUnion_of_mem ⟨isOpen_Ioo, Ioo_subset_Icc_self.trans hyzD⟩ -- Then we get points `a` and `b` in each interval `[x, y]` and `[y, z]` where the derivatives -- can be compared to the slopes between `x, y` and `y, z` respectively. obtain ⟨a, ⟨hxa, hay⟩, ha⟩ : ∃ a ∈ Ioo x y, (f y - f x) / (y - x) < deriv f a := StrictMonoOn.exists_slope_lt_deriv (hf.mono hxyD) hxy (hf'.mono hxyD') obtain ⟨b, ⟨hyb, hbz⟩, hb⟩ : ∃ b ∈ Ioo y z, deriv f b < (f z - f y) / (z - y) := StrictMonoOn.exists_deriv_lt_slope (hf.mono hyzD) hyz (hf'.mono hyzD') apply ha.trans (lt_trans _ hb) exact hf' (hxyD' ⟨hxa, hay⟩) (hyzD' ⟨hyb, hbz⟩) (hay.trans hyb) /-- If a function `f` is continuous on a convex set `D ⊆ ℝ` and `f'` is strictly antitone on the interior, then `f` is strictly concave on `D`. Note that we don't require differentiability, since it is guaranteed at all but at most one point by the strict antitonicity of `f'`. -/ theorem StrictAntiOn.strictConcaveOn_of_deriv {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (h_anti : StrictAntiOn (deriv f) (interior D)) : StrictConcaveOn ℝ D f := have : StrictMonoOn (deriv (-f)) (interior D) := by simpa only [← deriv.neg] using h_anti.neg neg_neg f ▸ (this.strictConvexOn_of_deriv hD hf.neg).neg /-- If a function `f` is differentiable and `f'` is monotone on `ℝ` then `f` is convex. -/ theorem Monotone.convexOn_univ_of_deriv {f : ℝ → ℝ} (hf : Differentiable ℝ f) (hf'_mono : Monotone (deriv f)) : ConvexOn ℝ univ f := (hf'_mono.monotoneOn _).convexOn_of_deriv convex_univ hf.continuous.continuousOn hf.differentiableOn /-- If a function `f` is differentiable and `f'` is antitone on `ℝ` then `f` is concave. -/ theorem Antitone.concaveOn_univ_of_deriv {f : ℝ → ℝ} (hf : Differentiable ℝ f) (hf'_anti : Antitone (deriv f)) : ConcaveOn ℝ univ f := (hf'_anti.antitoneOn _).concaveOn_of_deriv convex_univ hf.continuous.continuousOn hf.differentiableOn /-- If a function `f` is continuous and `f'` is strictly monotone on `ℝ` then `f` is strictly convex. Note that we don't require differentiability, since it is guaranteed at all but at most one point by the strict monotonicity of `f'`. -/ theorem StrictMono.strictConvexOn_univ_of_deriv {f : ℝ → ℝ} (hf : Continuous f) (hf'_mono : StrictMono (deriv f)) : StrictConvexOn ℝ univ f := (hf'_mono.strictMonoOn _).strictConvexOn_of_deriv convex_univ hf.continuousOn /-- If a function `f` is continuous and `f'` is strictly antitone on `ℝ` then `f` is strictly concave. Note that we don't require differentiability, since it is guaranteed at all but at most one point by the strict antitonicity of `f'`. -/ theorem StrictAnti.strictConcaveOn_univ_of_deriv {f : ℝ → ℝ} (hf : Continuous f) (hf'_anti : StrictAnti (deriv f)) : StrictConcaveOn ℝ univ f := (hf'_anti.strictAntiOn _).strictConcaveOn_of_deriv convex_univ hf.continuousOn /-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is twice differentiable on its interior, and `f''` is nonnegative on the interior, then `f` is convex on `D`. -/ theorem convexOn_of_deriv2_nonneg {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : DifferentiableOn ℝ f (interior D)) (hf'' : DifferentiableOn ℝ (deriv f) (interior D)) (hf''_nonneg : ∀ x ∈ interior D, 0 ≤ deriv^[2] f x) : ConvexOn ℝ D f := (monotoneOn_of_deriv_nonneg hD.interior hf''.continuousOn (by rwa [interior_interior]) <| by rwa [interior_interior]).convexOn_of_deriv hD hf hf' /-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is twice differentiable on its interior, and `f''` is nonpositive on the interior, then `f` is concave on `D`. -/ theorem concaveOn_of_deriv2_nonpos {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : DifferentiableOn ℝ f (interior D)) (hf'' : DifferentiableOn ℝ (deriv f) (interior D)) (hf''_nonpos : ∀ x ∈ interior D, deriv^[2] f x ≤ 0) : ConcaveOn ℝ D f := (antitoneOn_of_deriv_nonpos hD.interior hf''.continuousOn (by rwa [interior_interior]) <| by rwa [interior_interior]).concaveOn_of_deriv hD hf hf' /-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is twice differentiable on its interior, and `f''` is nonnegative on the interior, then `f` is convex on `D`. -/ lemma convexOn_of_hasDerivWithinAt2_nonneg {D : Set ℝ} (hD : Convex ℝ D) {f f' f'' : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : ∀ x ∈ interior D, HasDerivWithinAt f (f' x) (interior D) x) (hf'' : ∀ x ∈ interior D, HasDerivWithinAt f' (f'' x) (interior D) x) (hf''₀ : ∀ x ∈ interior D, 0 ≤ f'' x) : ConvexOn ℝ D f := by have : (interior D).EqOn (deriv f) f' := deriv_eqOn isOpen_interior hf' refine convexOn_of_deriv2_nonneg hD hf (fun x hx ↦ (hf' _ hx).differentiableWithinAt) ?_ ?_ · rw [differentiableOn_congr this] exact fun x hx ↦ (hf'' _ hx).differentiableWithinAt · rintro x hx convert hf''₀ _ hx using 1 dsimp rw [deriv_eqOn isOpen_interior (fun y hy ↦ ?_) hx] exact (hf'' _ hy).congr this <| by rw [this hy] /-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is twice differentiable on its interior, and `f''` is nonpositive on the interior, then `f` is concave on `D`. -/ lemma concaveOn_of_hasDerivWithinAt2_nonpos {D : Set ℝ} (hD : Convex ℝ D) {f f' f'' : ℝ → ℝ} (hf : ContinuousOn f D) (hf' : ∀ x ∈ interior D, HasDerivWithinAt f (f' x) (interior D) x) (hf'' : ∀ x ∈ interior D, HasDerivWithinAt f' (f'' x) (interior D) x) (hf''₀ : ∀ x ∈ interior D, f'' x ≤ 0) : ConcaveOn ℝ D f := by have : (interior D).EqOn (deriv f) f' := deriv_eqOn isOpen_interior hf' refine concaveOn_of_deriv2_nonpos hD hf (fun x hx ↦ (hf' _ hx).differentiableWithinAt) ?_ ?_ · rw [differentiableOn_congr this] exact fun x hx ↦ (hf'' _ hx).differentiableWithinAt · rintro x hx convert hf''₀ _ hx using 1 dsimp rw [deriv_eqOn isOpen_interior (fun y hy ↦ ?_) hx] exact (hf'' _ hy).congr this <| by rw [this hy] /-- If a function `f` is continuous on a convex set `D ⊆ ℝ` and `f''` is strictly positive on the interior, then `f` is strictly convex on `D`. Note that we don't require twice differentiability explicitly as it is already implied by the second derivative being strictly positive, except at at most one point. -/ theorem strictConvexOn_of_deriv2_pos {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf'' : ∀ x ∈ interior D, 0 < (deriv^[2] f) x) : StrictConvexOn ℝ D f := ((strictMonoOn_of_deriv_pos hD.interior fun z hz => (differentiableAt_of_deriv_ne_zero (hf'' z hz).ne').differentiableWithinAt.continuousWithinAt) <| by rwa [interior_interior]).strictConvexOn_of_deriv hD hf /-- If a function `f` is continuous on a convex set `D ⊆ ℝ` and `f''` is strictly negative on the interior, then `f` is strictly concave on `D`. Note that we don't require twice differentiability explicitly as it already implied by the second derivative being strictly negative, except at at most one point. -/ theorem strictConcaveOn_of_deriv2_neg {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf'' : ∀ x ∈ interior D, deriv^[2] f x < 0) : StrictConcaveOn ℝ D f := ((strictAntiOn_of_deriv_neg hD.interior fun z hz => (differentiableAt_of_deriv_ne_zero (hf'' z hz).ne).differentiableWithinAt.continuousWithinAt) <| by rwa [interior_interior]).strictConcaveOn_of_deriv hD hf /-- If a function `f` is twice differentiable on an open convex set `D ⊆ ℝ` and `f''` is nonnegative on `D`, then `f` is convex on `D`. -/ theorem convexOn_of_deriv2_nonneg' {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf' : DifferentiableOn ℝ f D) (hf'' : DifferentiableOn ℝ (deriv f) D) (hf''_nonneg : ∀ x ∈ D, 0 ≤ (deriv^[2] f) x) : ConvexOn ℝ D f := convexOn_of_deriv2_nonneg hD hf'.continuousOn (hf'.mono interior_subset) (hf''.mono interior_subset) fun x hx => hf''_nonneg x (interior_subset hx) /-- If a function `f` is twice differentiable on an open convex set `D ⊆ ℝ` and `f''` is nonpositive on `D`, then `f` is concave on `D`. -/ theorem concaveOn_of_deriv2_nonpos' {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf' : DifferentiableOn ℝ f D) (hf'' : DifferentiableOn ℝ (deriv f) D) (hf''_nonpos : ∀ x ∈ D, deriv^[2] f x ≤ 0) : ConcaveOn ℝ D f := concaveOn_of_deriv2_nonpos hD hf'.continuousOn (hf'.mono interior_subset) (hf''.mono interior_subset) fun x hx => hf''_nonpos x (interior_subset hx) /-- If a function `f` is continuous on a convex set `D ⊆ ℝ` and `f''` is strictly positive on `D`, then `f` is strictly convex on `D`. Note that we don't require twice differentiability explicitly as it is already implied by the second derivative being strictly positive, except at at most one point. -/ theorem strictConvexOn_of_deriv2_pos' {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf'' : ∀ x ∈ D, 0 < (deriv^[2] f) x) : StrictConvexOn ℝ D f := strictConvexOn_of_deriv2_pos hD hf fun x hx => hf'' x (interior_subset hx) /-- If a function `f` is continuous on a convex set `D ⊆ ℝ` and `f''` is strictly negative on `D`, then `f` is strictly concave on `D`. Note that we don't require twice differentiability explicitly as it is already implied by the second derivative being strictly negative, except at at most one point. -/ theorem strictConcaveOn_of_deriv2_neg' {D : Set ℝ} (hD : Convex ℝ D) {f : ℝ → ℝ} (hf : ContinuousOn f D) (hf'' : ∀ x ∈ D, deriv^[2] f x < 0) : StrictConcaveOn ℝ D f := strictConcaveOn_of_deriv2_neg hD hf fun x hx => hf'' x (interior_subset hx) /-- If a function `f` is twice differentiable on `ℝ`, and `f''` is nonnegative on `ℝ`, then `f` is convex on `ℝ`. -/ theorem convexOn_univ_of_deriv2_nonneg {f : ℝ → ℝ} (hf' : Differentiable ℝ f) (hf'' : Differentiable ℝ (deriv f)) (hf''_nonneg : ∀ x, 0 ≤ (deriv^[2] f) x) : ConvexOn ℝ univ f := convexOn_of_deriv2_nonneg' convex_univ hf'.differentiableOn hf''.differentiableOn fun x _ => hf''_nonneg x /-- If a function `f` is twice differentiable on `ℝ`, and `f''` is nonpositive on `ℝ`, then `f` is concave on `ℝ`. -/ theorem concaveOn_univ_of_deriv2_nonpos {f : ℝ → ℝ} (hf' : Differentiable ℝ f) (hf'' : Differentiable ℝ (deriv f)) (hf''_nonpos : ∀ x, deriv^[2] f x ≤ 0) : ConcaveOn ℝ univ f := concaveOn_of_deriv2_nonpos' convex_univ hf'.differentiableOn hf''.differentiableOn fun x _ => hf''_nonpos x /-- If a function `f` is continuous on `ℝ`, and `f''` is strictly positive on `ℝ`, then `f` is strictly convex on `ℝ`. Note that we don't require twice differentiability explicitly as it is already implied by the second derivative being strictly positive, except at at most one point. -/ theorem strictConvexOn_univ_of_deriv2_pos {f : ℝ → ℝ} (hf : Continuous f) (hf'' : ∀ x, 0 < (deriv^[2] f) x) : StrictConvexOn ℝ univ f := strictConvexOn_of_deriv2_pos' convex_univ hf.continuousOn fun x _ => hf'' x /-- If a function `f` is continuous on `ℝ`, and `f''` is strictly negative on `ℝ`, then `f` is strictly concave on `ℝ`. Note that we don't require twice differentiability explicitly as it is already implied by the second derivative being strictly negative, except at at most one point. -/ theorem strictConcaveOn_univ_of_deriv2_neg {f : ℝ → ℝ} (hf : Continuous f) (hf'' : ∀ x, deriv^[2] f x < 0) : StrictConcaveOn ℝ univ f := strictConcaveOn_of_deriv2_neg' convex_univ hf.continuousOn fun x _ => hf'' x /-! ## Convexity of `f` implies monotonicity of `f'` In this section we prove inequalities relating derivatives of convex functions to slopes of secant lines, and deduce that if `f` is convex then its derivative is monotone (and similarly for strict convexity / strict monotonicity). -/ section slope variable {𝕜 : Type*} [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] {s : Set 𝕜} {f : 𝕜 → 𝕜} {x : 𝕜} /-- If `f : 𝕜 → 𝕜` is convex on `s`, then for any point `x ∈ s` the slope of the secant line of `f` through `x` is monotone on `s \ {x}`. -/ lemma ConvexOn.slope_mono (hfc : ConvexOn 𝕜 s f) (hx : x ∈ s) : MonotoneOn (slope f x) (s \ {x}) := (slope_fun_def_field f _).symm ▸ fun _ hy _ hz hz' ↦ hfc.secant_mono hx (mem_of_mem_diff hy) (mem_of_mem_diff hz) (not_mem_of_mem_diff hy :) (not_mem_of_mem_diff hz :) hz' lemma ConvexOn.monotoneOn_slope_gt (hfc : ConvexOn 𝕜 s f) (hxs : x ∈ s) : MonotoneOn (slope f x) {y ∈ s | x < y} := (hfc.slope_mono hxs).mono fun _ ⟨h1, h2⟩ ↦ ⟨h1, h2.ne'⟩ lemma ConvexOn.monotoneOn_slope_lt (hfc : ConvexOn 𝕜 s f) (hxs : x ∈ s) : MonotoneOn (slope f x) {y ∈ s | y < x} := (hfc.slope_mono hxs).mono fun _ ⟨h1, h2⟩ ↦ ⟨h1, h2.ne⟩ /-- If `f : 𝕜 → 𝕜` is concave on `s`, then for any point `x ∈ s` the slope of the secant line of `f` through `x` is antitone on `s \ {x}`. -/ lemma ConcaveOn.slope_anti (hfc : ConcaveOn 𝕜 s f) (hx : x ∈ s) : AntitoneOn (slope f x) (s \ {x}) := by rw [← neg_neg f, slope_neg_fun] exact (ConvexOn.slope_mono hfc.neg hx).neg lemma ConcaveOn.antitoneOn_slope_gt (hfc : ConcaveOn 𝕜 s f) (hxs : x ∈ s) : AntitoneOn (slope f x) {y ∈ s | x < y} := (hfc.slope_anti hxs).mono fun _ ⟨h1, h2⟩ ↦ ⟨h1, h2.ne'⟩ lemma ConcaveOn.antitoneOn_slope_lt (hfc : ConcaveOn 𝕜 s f) (hxs : x ∈ s) : AntitoneOn (slope f x) {y ∈ s | y < x} := (hfc.slope_anti hxs).mono fun _ ⟨h1, h2⟩ ↦ ⟨h1, h2.ne⟩ variable [TopologicalSpace 𝕜] [OrderTopology 𝕜] lemma bddBelow_slope_lt_of_mem_interior (hfc : ConvexOn 𝕜 s f) (hxs : x ∈ interior s) : BddBelow (slope f x '' {y ∈ s | x < y}) := by obtain ⟨y, hyx, hys⟩ : ∃ y, y < x ∧ y ∈ s := Eventually.exists_lt (mem_interior_iff_mem_nhds.mp hxs) refine bddBelow_iff_subset_Ici.mpr ⟨slope f x y, fun y' ⟨z, hz, hz'⟩ ↦ ?_⟩ simp_rw [mem_Ici, ← hz'] refine hfc.slope_mono (interior_subset hxs) ?_ ?_ (hyx.trans hz.2).le · simp [hys, hyx.ne] · simp [hz.2.ne', hz.1] lemma bddAbove_slope_gt_of_mem_interior (hfc : ConvexOn 𝕜 s f) (hxs : x ∈ interior s) : BddAbove (slope f x '' {y ∈ s | y < x}) := by obtain ⟨y, hyx, hys⟩ : ∃ y, x < y ∧ y ∈ s := Eventually.exists_gt (mem_interior_iff_mem_nhds.mp hxs) refine bddAbove_iff_subset_Iic.mpr ⟨slope f x y, fun y' ⟨z, hz, hz'⟩ ↦ ?_⟩ simp_rw [mem_Iic, ← hz'] refine hfc.slope_mono (interior_subset hxs) ?_ ?_ (hz.2.trans hyx).le · simp [hz.2.ne, hz.1] · simp [hys, hyx.ne'] end slope namespace ConvexOn variable {S : Set ℝ} {f : ℝ → ℝ} {x y f' : ℝ} section Interior /-! ### Left and right derivative of a convex function in the interior of the set -/ lemma hasDerivWithinAt_sInf_slope_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) : HasDerivWithinAt f (sInf (slope f x '' {y ∈ S | x < y})) (Ioi x) x := by have hxs' := hxs rw [mem_interior_iff_mem_nhds, mem_nhds_iff_exists_Ioo_subset] at hxs' obtain ⟨a, b, hxab, habs⟩ := hxs' simp_rw [hasDerivWithinAt_iff_tendsto_slope] simp only [mem_Ioi, lt_self_iff_false, not_false_eq_true, diff_singleton_eq_self] have h : Ioo x b ⊆ {y | y ∈ S ∧ x < y} := fun z hz ↦ ⟨habs ⟨hxab.1.trans hz.1, hz.2⟩, hz.1⟩ have h_Ioo : Tendsto (slope f x) (𝓝[>] x) (𝓝 (sInf (slope f x '' Ioo x b))) := ((monotoneOn_slope_gt hfc (habs hxab)).mono h).tendsto_nhdsWithin_Ioo_right (by simpa using hxab.2) ((bddBelow_slope_lt_of_mem_interior hfc hxs).mono (image_subset _ h)) suffices sInf (slope f x '' Ioo x b) = sInf (slope f x '' {y ∈ S | x < y}) by rwa [← this] apply (monotoneOn_slope_gt hfc (habs hxab)).csInf_eq_of_subset_of_forall_exists_le (bddBelow_slope_lt_of_mem_interior hfc hxs) h ?_ rintro y ⟨hyS, hxy⟩ obtain ⟨z, hxz, hzy⟩ := exists_between (lt_min hxab.2 hxy) exact ⟨z, ⟨hxz, hzy.trans_le (min_le_left _ _)⟩, hzy.le.trans (min_le_right _ _)⟩ lemma hasDerivWithinAt_sSup_slope_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) : HasDerivWithinAt f (sSup (slope f x '' {y ∈ S | y < x})) (Iio x) x := by have hxs' := hxs rw [mem_interior_iff_mem_nhds, mem_nhds_iff_exists_Ioo_subset] at hxs' obtain ⟨a, b, hxab, habs⟩ := hxs' simp_rw [hasDerivWithinAt_iff_tendsto_slope] simp only [mem_Iio, lt_self_iff_false, not_false_eq_true, diff_singleton_eq_self] have h : Ioo a x ⊆ {y | y ∈ S ∧ y < x} := fun z hz ↦ ⟨habs ⟨hz.1, hz.2.trans hxab.2⟩, hz.2⟩ have h_Ioo : Tendsto (slope f x) (𝓝[<] x) (𝓝 (sSup (slope f x '' Ioo a x))) := ((monotoneOn_slope_lt hfc (habs hxab)).mono h).tendsto_nhdsWithin_Ioo_left (by simpa using hxab.1) ((bddAbove_slope_gt_of_mem_interior hfc hxs).mono (image_subset _ h)) suffices sSup (slope f x '' Ioo a x) = sSup (slope f x '' {y ∈ S | y < x}) by rwa [← this] apply (monotoneOn_slope_lt hfc (habs hxab)).csSup_eq_of_subset_of_forall_exists_le (bddAbove_slope_gt_of_mem_interior hfc hxs) h ?_ rintro y ⟨hyS, hyx⟩ obtain ⟨z, hyz, hzx⟩ := exists_between (max_lt hxab.1 hyx) exact ⟨z, ⟨(le_max_left _ _).trans_lt hyz, hzx⟩, (le_max_right _ _).trans hyz.le⟩ lemma differentiableWithinAt_Ioi_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) : DifferentiableWithinAt ℝ f (Ioi x) x := (hfc.hasDerivWithinAt_sInf_slope_of_mem_interior hxs).differentiableWithinAt lemma differentiableWithinAt_Iio_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) : DifferentiableWithinAt ℝ f (Iio x) x := (hfc.hasDerivWithinAt_sSup_slope_of_mem_interior hxs).differentiableWithinAt lemma hasDerivWithinAt_rightDeriv_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) : HasDerivWithinAt f (derivWithin f (Ioi x) x) (Ioi x) x := (hfc.differentiableWithinAt_Ioi_of_mem_interior hxs).hasDerivWithinAt lemma hasDerivWithinAt_leftDeriv_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) : HasDerivWithinAt f (derivWithin f (Iio x) x) (Iio x) x := (hfc.differentiableWithinAt_Iio_of_mem_interior hxs).hasDerivWithinAt lemma rightDeriv_eq_sInf_slope_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) : derivWithin f (Ioi x) x = sInf (slope f x '' {y | y ∈ S ∧ x < y}) := (hfc.hasDerivWithinAt_sInf_slope_of_mem_interior hxs).derivWithin (uniqueDiffWithinAt_Ioi x) lemma leftDeriv_eq_sSup_slope_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) : derivWithin f (Iio x) x = sSup (slope f x '' {y | y ∈ S ∧ y < x}) := (hfc.hasDerivWithinAt_sSup_slope_of_mem_interior hxs).derivWithin (uniqueDiffWithinAt_Iio x) lemma monotoneOn_rightDeriv (hfc : ConvexOn ℝ S f) : MonotoneOn (fun x ↦ derivWithin f (Ioi x) x) (interior S) := by intro x hxs y hys hxy rcases eq_or_lt_of_le hxy with rfl | hxy; · rfl simp_rw [hfc.rightDeriv_eq_sInf_slope_of_mem_interior hxs, hfc.rightDeriv_eq_sInf_slope_of_mem_interior hys] refine csInf_le_of_le (b := slope f x y) (bddBelow_slope_lt_of_mem_interior hfc hxs) ⟨y, by simp only [mem_setOf_eq, hxy, and_true]; exact interior_subset hys⟩ (le_csInf ?_ ?_) · have hys' := hys rw [mem_interior_iff_mem_nhds, mem_nhds_iff_exists_Ioo_subset] at hys' obtain ⟨a, b, hxab, habs⟩ := hys' rw [image_nonempty] obtain ⟨z, hxz, hzb⟩ := exists_between hxab.2 exact ⟨z, habs ⟨hxab.1.trans hxz, hzb⟩, hxz⟩ · rintro _ ⟨z, ⟨hzs, hyz : y < z⟩, rfl⟩ rw [slope_comm] exact slope_mono hfc (interior_subset hys) ⟨interior_subset hxs, hxy.ne⟩ ⟨hzs, hyz.ne'⟩ (hxy.trans hyz).le lemma monotoneOn_leftDeriv (hfc : ConvexOn ℝ S f) : MonotoneOn (fun x ↦ derivWithin f (Iio x) x) (interior S) := by intro x hxs y hys hxy rcases eq_or_lt_of_le hxy with rfl | hxy; · rfl simp_rw [hfc.leftDeriv_eq_sSup_slope_of_mem_interior hxs, hfc.leftDeriv_eq_sSup_slope_of_mem_interior hys] refine le_csSup_of_le (b := slope f x y) (bddAbove_slope_gt_of_mem_interior hfc hys) ⟨x, by simp only [slope_comm, mem_setOf_eq, hxy, and_true]; exact interior_subset hxs⟩ (csSup_le ?_ ?_) · have hxs' := hxs rw [mem_interior_iff_mem_nhds, mem_nhds_iff_exists_Ioo_subset] at hxs' obtain ⟨a, b, hxab, habs⟩ := hxs' rw [image_nonempty] obtain ⟨z, hxz, hzb⟩ := exists_between hxab.1 exact ⟨z, habs ⟨hxz, hzb.trans hxab.2⟩, hzb⟩ · rintro _ ⟨z, ⟨hzs, hyz : z < x⟩, rfl⟩ exact slope_mono hfc (interior_subset hxs) ⟨hzs, hyz.ne⟩ ⟨interior_subset hys, hxy.ne'⟩ (hyz.trans hxy).le lemma leftDeriv_le_rightDeriv_of_mem_interior (hfc : ConvexOn ℝ S f) (hxs : x ∈ interior S) : derivWithin f (Iio x) x ≤ derivWithin f (Ioi x) x := by have hxs' := hxs rw [mem_interior_iff_mem_nhds, mem_nhds_iff_exists_Ioo_subset] at hxs' obtain ⟨a, b, hxab, habs⟩ := hxs' rw [hfc.rightDeriv_eq_sInf_slope_of_mem_interior hxs, hfc.leftDeriv_eq_sSup_slope_of_mem_interior hxs] refine csSup_le ?_ ?_ · rw [image_nonempty] obtain ⟨z, haz, hzx⟩ := exists_between hxab.1 exact ⟨z, habs ⟨haz, hzx.trans hxab.2⟩, hzx⟩ rintro _ ⟨z, ⟨hzs, hzx⟩, rfl⟩ refine le_csInf ?_ ?_ · rw [image_nonempty] obtain ⟨z, hxz, hzb⟩ := exists_between hxab.2 exact ⟨z, habs ⟨hxab.1.trans hxz, hzb⟩, hxz⟩ rintro _ ⟨y, ⟨hys, hxy⟩, rfl⟩ exact slope_mono hfc (interior_subset hxs) ⟨hzs, hzx.ne⟩ ⟨hys, hxy.ne'⟩ (hzx.trans hxy).le end Interior section left /-! ### Convex functions, derivative at left endpoint of secant -/ /-- If `f : ℝ → ℝ` is convex on `S` and right-differentiable at `x ∈ S`, then the slope of any secant line with left endpoint at `x` is bounded below by the right derivative of `f` at `x`. -/ lemma le_slope_of_hasDerivWithinAt_Ioi (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' (Ioi x) x) : f' ≤ slope f x y := by apply le_of_tendsto <| (hasDerivWithinAt_iff_tendsto_slope' not_mem_Ioi_self).mp hf' simp_rw [eventually_nhdsWithin_iff, slope_def_field] filter_upwards [eventually_lt_nhds hxy] with t ht (ht' : x < t) refine hfc.secant_mono hx (?_ : t ∈ S) hy ht'.ne' hxy.ne' ht.le exact hfc.1.ordConnected.out hx hy ⟨ht'.le, ht.le⟩ /-- Reformulation of `ConvexOn.le_slope_of_hasDerivWithinAt_Ioi` using `derivWithin`. -/ lemma rightDeriv_le_slope (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableWithinAt ℝ f (Ioi x) x) : derivWithin f (Ioi x) x ≤ slope f x y := le_slope_of_hasDerivWithinAt_Ioi hfc hx hy hxy hfd.hasDerivWithinAt @[deprecated (since := "2025-01-26")] alias right_deriv_le_slope := rightDeriv_le_slope lemma rightDeriv_le_slope_of_mem_interior (hfc : ConvexOn ℝ S f) {y : ℝ} (hxs : x ∈ interior S) (hys : y ∈ S) (hxy : x < y) : derivWithin f (Ioi x) x ≤ slope f x y := rightDeriv_le_slope hfc (interior_subset hxs) hys hxy (differentiableWithinAt_Ioi_of_mem_interior hfc hxs) /-- If `f : ℝ → ℝ` is convex on `S` and differentiable within `S` at `x`, then the slope of any secant line with left endpoint at `x` is bounded below by the derivative of `f` within `S` at `x`. This is fractionally weaker than `ConvexOn.le_slope_of_hasDerivWithinAt_Ioi` but simpler to apply under a `DifferentiableOn S` hypothesis. -/ lemma le_slope_of_hasDerivWithinAt (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' S x) : f' ≤ slope f x y := hfc.le_slope_of_hasDerivWithinAt_Ioi hx hy hxy <| hf'.mono_of_mem_nhdsWithin <| hfc.1.ordConnected.mem_nhdsGT hx hy hxy /-- Reformulation of `ConvexOn.le_slope_of_hasDerivWithinAt` using `derivWithin`. -/ lemma derivWithin_le_slope (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableWithinAt ℝ f S x) : derivWithin f S x ≤ slope f x y := le_slope_of_hasDerivWithinAt hfc hx hy hxy hfd.hasDerivWithinAt /-- If `f : ℝ → ℝ` is convex on `S` and differentiable at `x ∈ S`, then the slope of any secant line with left endpoint at `x` is bounded below by the derivative of `f` at `x`. -/ lemma le_slope_of_hasDerivAt (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (ha : HasDerivAt f f' x) : f' ≤ slope f x y := hfc.le_slope_of_hasDerivWithinAt_Ioi hx hy hxy ha.hasDerivWithinAt /-- Reformulation of `ConvexOn.le_slope_of_hasDerivAt` using `deriv` -/ lemma deriv_le_slope (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableAt ℝ f x) : deriv f x ≤ slope f x y := le_slope_of_hasDerivAt hfc hx hy hxy hfd.hasDerivAt end left section right /-! ### Convex functions, derivative at right endpoint of secant -/ /-- If `f : ℝ → ℝ` is convex on `S` and left-differentiable at `y ∈ S`, then the slope of any secant line with right endpoint at `y` is bounded above by the left derivative of `f` at `y`. -/ lemma slope_le_of_hasDerivWithinAt_Iio (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' (Iio y) y) : slope f x y ≤ f' := by apply ge_of_tendsto <| (hasDerivWithinAt_iff_tendsto_slope' not_mem_Iio_self).mp hf' simp_rw [eventually_nhdsWithin_iff, slope_comm f x y, slope_def_field] filter_upwards [eventually_gt_nhds hxy] with t ht (ht' : t < y) refine hfc.secant_mono hy hx (?_ : t ∈ S) hxy.ne ht'.ne ht.le exact hfc.1.ordConnected.out hx hy ⟨ht.le, ht'.le⟩ /-- Reformulation of `ConvexOn.slope_le_of_hasDerivWithinAt_Iio` using `derivWithin`. -/ lemma slope_le_leftDeriv (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableWithinAt ℝ f (Iio y) y) : slope f x y ≤ derivWithin f (Iio y) y := hfc.slope_le_of_hasDerivWithinAt_Iio hx hy hxy hfd.hasDerivWithinAt @[deprecated (since := "2025-01-26")] alias slope_le_left_deriv := slope_le_leftDeriv lemma slope_le_leftDeriv_of_mem_interior (hfc : ConvexOn ℝ S f) (hys : x ∈ S) (hxs : y ∈ interior S) (hxy : x < y) : slope f x y ≤ derivWithin f (Iio y) y := slope_le_leftDeriv hfc hys (interior_subset hxs) hxy (differentiableWithinAt_Iio_of_mem_interior hfc hxs) /-- If `f : ℝ → ℝ` is convex on `S` and differentiable within `S` at `y`, then the slope of any secant line with right endpoint at `y` is bounded above by the derivative of `f` within `S` at `y`. This is fractionally weaker than `ConvexOn.slope_le_of_hasDerivWithinAt_Iio` but simpler to apply under a `DifferentiableOn S` hypothesis. -/ lemma slope_le_of_hasDerivWithinAt (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' S y) : slope f x y ≤ f' := hfc.slope_le_of_hasDerivWithinAt_Iio hx hy hxy <| hf'.mono_of_mem_nhdsWithin <| hfc.1.ordConnected.mem_nhdsLT hx hy hxy /-- Reformulation of `ConvexOn.slope_le_of_hasDerivWithinAt` using `derivWithin`. -/ lemma slope_le_derivWithin (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableWithinAt ℝ f S y) : slope f x y ≤ derivWithin f S y := hfc.slope_le_of_hasDerivWithinAt hx hy hxy hfd.hasDerivWithinAt /-- If `f : ℝ → ℝ` is convex on `S` and differentiable at `y ∈ S`, then the slope of any secant line with right endpoint at `y` is bounded above by the derivative of `f` at `y`. -/ lemma slope_le_of_hasDerivAt (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivAt f f' y) : slope f x y ≤ f' := hfc.slope_le_of_hasDerivWithinAt_Iio hx hy hxy hf'.hasDerivWithinAt /-- Reformulation of `ConvexOn.slope_le_of_hasDerivAt` using `deriv`. -/ lemma slope_le_deriv (hfc : ConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableAt ℝ f y) : slope f x y ≤ deriv f y := hfc.slope_le_of_hasDerivAt hx hy hxy hfd.hasDerivAt end right /-! ### Convex functions, monotonicity of derivative -/ /-- If `f` is convex on `S` and differentiable on `S`, then its derivative within `S` is monotone on `S`. -/ lemma monotoneOn_derivWithin (hfc : ConvexOn ℝ S f) (hfd : DifferentiableOn ℝ f S) : MonotoneOn (derivWithin f S) S := by intro x hx y hy hxy rcases eq_or_lt_of_le hxy with rfl | hxy' · rfl exact (hfc.derivWithin_le_slope hx hy hxy' (hfd x hx)).trans (hfc.slope_le_derivWithin hx hy hxy' (hfd y hy)) /-- If `f` is convex on `S` and differentiable at all points of `S`, then its derivative is monotone on `S`. -/ theorem monotoneOn_deriv (hfc : ConvexOn ℝ S f) (hfd : ∀ x ∈ S, DifferentiableAt ℝ f x) : MonotoneOn (deriv f) S := by intro x hx y hy hxy rcases eq_or_lt_of_le hxy with rfl | hxy' · rfl exact (hfc.deriv_le_slope hx hy hxy' (hfd x hx)).trans (hfc.slope_le_deriv hx hy hxy' (hfd y hy)) lemma isMinOn_of_leftDeriv_nonpos_of_rightDeriv_nonneg (hf : ConvexOn ℝ S f) (hx : x ∈ interior S) (hf_ld : derivWithin f (Iio x) x ≤ 0) (hf_rd : 0 ≤ derivWithin f (Ioi x) x) : IsMinOn f S x := by intro y hy rcases lt_trichotomy x y with hxy | h_eq | hyx · suffices 0 ≤ slope f x y by simp only [slope_def_field, div_nonneg_iff, sub_nonneg, tsub_le_iff_right, zero_add, not_le.mpr hxy, and_false, or_false] at this exact this.1 exact hf_rd.trans <| rightDeriv_le_slope_of_mem_interior hf hx hy hxy · simp [h_eq] · suffices slope f x y ≤ 0 by simp only [slope_def_field, div_nonpos_iff, sub_nonneg, tsub_le_iff_right, zero_add, not_le.mpr hyx, and_false, or_false] at this exact this.1 rw [slope_comm] exact (slope_le_leftDeriv_of_mem_interior hf hy hx hyx).trans hf_ld lemma isMinOn_of_rightDeriv_eq_zero (hf : ConvexOn ℝ S f) (hx : x ∈ interior S) (hf_rd : derivWithin f (Ioi x) x = 0) : IsMinOn f S x := by refine hf.isMinOn_of_leftDeriv_nonpos_of_rightDeriv_nonneg hx ?_ hf_rd.symm.le exact (hf.leftDeriv_le_rightDeriv_of_mem_interior hx).trans_eq hf_rd lemma isMinOn_of_leftDeriv_eq_zero (hf : ConvexOn ℝ S f) (hx : x ∈ interior S) (hf_ld : derivWithin f (Iio x) x = 0) : IsMinOn f S x := by refine hf.isMinOn_of_leftDeriv_nonpos_of_rightDeriv_nonneg hx hf_ld.le ?_ exact hf_ld.symm.le.trans (hf.leftDeriv_le_rightDeriv_of_mem_interior hx) end ConvexOn namespace StrictConvexOn variable {S : Set ℝ} {f : ℝ → ℝ} {x y f' : ℝ} section left /-! ### Strict convex functions, derivative at left endpoint of secant -/ /-- If `f : ℝ → ℝ` is strictly convex on `S` and right-differentiable at `x ∈ S`, then the slope of any secant line with left endpoint at `x` is strictly greater than the right derivative of `f` at `x`. -/ lemma lt_slope_of_hasDerivWithinAt_Ioi (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' (Ioi x) x) : f' < slope f x y := by obtain ⟨u, hxu, huy⟩ := exists_between hxy have hu : u ∈ S := hfc.1.ordConnected.out hx hy ⟨hxu.le, huy.le⟩ have := hfc.secant_strict_mono hx hu hy hxu.ne' hxy.ne' huy simp only [← slope_def_field] at this exact (hfc.convexOn.le_slope_of_hasDerivWithinAt_Ioi hx hu hxu hf').trans_lt this lemma rightDeriv_lt_slope (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableWithinAt ℝ f (Ioi x) x) : derivWithin f (Ioi x) x < slope f x y := hfc.lt_slope_of_hasDerivWithinAt_Ioi hx hy hxy hfd.hasDerivWithinAt @[deprecated (since := "2025-01-26")] alias right_deriv_lt_slope := rightDeriv_lt_slope /-- If `f : ℝ → ℝ` is strictly convex on `S` and differentiable within `S` at `x ∈ S`, then the slope of any secant line with left endpoint at `x` is strictly greater than the derivative of `f` within `S` at `x`. This is fractionally weaker than `StrictConvexOn.lt_slope_of_hasDerivWithinAt_Ioi` but simpler to apply under a `DifferentiableOn S` hypothesis. -/ lemma lt_slope_of_hasDerivWithinAt (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' S x) : f' < slope f x y := hfc.lt_slope_of_hasDerivWithinAt_Ioi hx hy hxy <| hf'.mono_of_mem_nhdsWithin <| hfc.1.ordConnected.mem_nhdsGT hx hy hxy lemma derivWithin_lt_slope (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableWithinAt ℝ f S x) : derivWithin f S x < slope f x y := hfc.lt_slope_of_hasDerivWithinAt hx hy hxy hfd.hasDerivWithinAt /-- If `f : ℝ → ℝ` is strictly convex on `S` and differentiable at `x ∈ S`, then the slope of any secant line with left endpoint at `x` is strictly greater than the derivative of `f` at `x`. -/ lemma lt_slope_of_hasDerivAt (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivAt f f' x) : f' < slope f x y := hfc.lt_slope_of_hasDerivWithinAt_Ioi hx hy hxy hf'.hasDerivWithinAt lemma deriv_lt_slope (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableAt ℝ f x) : deriv f x < slope f x y := hfc.lt_slope_of_hasDerivAt hx hy hxy hfd.hasDerivAt end left section right /-! ### Strict convex functions, derivative at right endpoint of secant -/ /-- If `f : ℝ → ℝ` is strictly convex on `S` and differentiable at `y ∈ S`, then the slope of any secant line with right endpoint at `y` is strictly less than the left derivative at `y`. -/ lemma slope_lt_of_hasDerivWithinAt_Iio (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' (Iio y) y) : slope f x y < f' := by obtain ⟨u, hxu, huy⟩ := exists_between hxy have hu : u ∈ S := hfc.1.ordConnected.out hx hy ⟨hxu.le, huy.le⟩ have := hfc.secant_strict_mono hy hx hu hxy.ne huy.ne hxu simp_rw [← slope_def_field, slope_comm _ y] at this exact this.trans_le <| hfc.convexOn.slope_le_of_hasDerivWithinAt_Iio hu hy huy hf' lemma slope_lt_leftDeriv (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableWithinAt ℝ f (Iio y) y) : slope f x y < derivWithin f (Iio y) y := hfc.slope_lt_of_hasDerivWithinAt_Iio hx hy hxy hfd.hasDerivWithinAt @[deprecated (since := "2025-01-26")] alias slope_lt_left_deriv := slope_lt_leftDeriv /-- If `f : ℝ → ℝ` is strictly convex on `S` and differentiable within `S` at `y ∈ S`, then the slope of any secant line with right endpoint at `y` is strictly less than the derivative of `f` within `S` at `y`. This is fractionally weaker than `StrictConvexOn.slope_lt_of_hasDerivWithinAt_Iio` but simpler to apply under a `DifferentiableOn S` hypothesis. -/ lemma slope_lt_of_hasDerivWithinAt (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivWithinAt f f' S y) : slope f x y < f' := hfc.slope_lt_of_hasDerivWithinAt_Iio hx hy hxy <| hf'.mono_of_mem_nhdsWithin <| hfc.1.ordConnected.mem_nhdsLT hx hy hxy lemma slope_lt_derivWithin (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableWithinAt ℝ f S y) : slope f x y < derivWithin f S y := hfc.slope_lt_of_hasDerivWithinAt hx hy hxy hfd.hasDerivWithinAt /-- If `f : ℝ → ℝ` is strictly convex on `S` and differentiable at `y ∈ S`, then the slope of any secant line with right endpoint at `y` is strictly less than the derivative of `f` at `y`. -/ lemma slope_lt_of_hasDerivAt (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hf' : HasDerivAt f f' y) : slope f x y < f' := hfc.slope_lt_of_hasDerivWithinAt_Iio hx hy hxy hf'.hasDerivWithinAt lemma slope_lt_deriv (hfc : StrictConvexOn ℝ S f) (hx : x ∈ S) (hy : y ∈ S) (hxy : x < y) (hfd : DifferentiableAt ℝ f y) : slope f x y < deriv f y := hfc.slope_lt_of_hasDerivAt hx hy hxy hfd.hasDerivAt end right /-! ### Strict convex functions, strict monotonicity of derivative -/ /-- If `f` is convex on `S` and differentiable on `S`, then its derivative within `S` is monotone on `S`. -/ lemma strictMonoOn_derivWithin (hfc : StrictConvexOn ℝ S f) (hfd : DifferentiableOn ℝ f S) : StrictMonoOn (derivWithin f S) S := by intro x hx y hy hxy exact (hfc.derivWithin_lt_slope hx hy hxy (hfd x hx)).trans (hfc.slope_lt_derivWithin hx hy hxy (hfd y hy)) /-- If `f` is convex on `S` and differentiable at all points of `S`, then its derivative is monotone on `S`. -/ lemma strictMonoOn_deriv (hfc : StrictConvexOn ℝ S f) (hfd : ∀ x ∈ S, DifferentiableAt ℝ f x) : StrictMonoOn (deriv f) S := by intro x hx y hy hxy exact (hfc.deriv_lt_slope hx hy hxy (hfd x hx)).trans (hfc.slope_lt_deriv hx hy hxy (hfd y hy)) end StrictConvexOn
section MirrorImage variable {S : Set ℝ} {f : ℝ → ℝ} {x y f' : ℝ} namespace ConcaveOn
Mathlib/Analysis/Convex/Deriv.lean
862
866
/- 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.MeasurableSpace.MeasurablyGenerated import Mathlib.MeasureTheory.Measure.NullMeasurable import Mathlib.Order.Interval.Set.Monotone /-! # Measure spaces The definition of a measure and a measure space are in `MeasureTheory.MeasureSpaceDef`, with only a few basic properties. This file provides many more properties of these objects. This separation allows the measurability tactic to import only the file `MeasureSpaceDef`, and to be available in `MeasureSpace` (through `MeasurableSpace`). Given a measurable space `α`, a measure on `α` is a function that sends measurable sets to the extended nonnegative reals that satisfies the following conditions: 1. `μ ∅ = 0`; 2. `μ` is countably additive. This means that the measure of a countable union of pairwise disjoint sets is equal to the measure of the individual sets. Every measure can be canonically extended to an outer measure, so that it assigns values to all subsets, not just the measurable subsets. On the other hand, a measure that is countably additive on measurable sets can be restricted to measurable sets to obtain a measure. In this file a measure is defined to be an outer measure that is countably additive on measurable sets, with the additional assumption that the outer measure is the canonical extension of the restricted measure. Measures on `α` form a complete lattice, and are closed under scalar multiplication with `ℝ≥0∞`. Given a measure, the null sets are the sets where `μ s = 0`, where `μ` denotes the corresponding outer measure (so `s` might not be measurable). We can then define the completion of `μ` as the measure on the least `σ`-algebra that also contains all null sets, by defining the measure to be `0` on the null sets. ## Main statements * `completion` is the completion of a measure to all null measurable sets. * `Measure.ofMeasurable` and `OuterMeasure.toMeasure` are two important ways to define a measure. ## Implementation notes Given `μ : Measure α`, `μ s` is the value of the *outer measure* applied to `s`. This conveniently allows us to apply the measure to sets without proving that they are measurable. We get countable subadditivity for all sets, but only countable additivity for measurable sets. You often don't want to define a measure via its constructor. Two ways that are sometimes more convenient: * `Measure.ofMeasurable` is a way to define a measure by only giving its value on measurable sets and proving the properties (1) and (2) mentioned above. * `OuterMeasure.toMeasure` is a way of obtaining a measure from an outer measure by showing that all measurable sets in the measurable space are Carathéodory measurable. To prove that two measures are equal, there are multiple options: * `ext`: two measures are equal if they are equal on all measurable sets. * `ext_of_generateFrom_of_iUnion`: two measures are equal if they are equal on a π-system generating the measurable sets, if the π-system contains a spanning increasing sequence of sets where the measures take finite value (in particular the measures are σ-finite). This is a special case of the more general `ext_of_generateFrom_of_cover` * `ext_of_generate_finite`: two finite measures are equal if they are equal on a π-system generating the measurable sets. This is a special case of `ext_of_generateFrom_of_iUnion` using `C ∪ {univ}`, but is easier to work with. A `MeasureSpace` is a class that is a measurable space with a canonical measure. The measure is denoted `volume`. ## References * <https://en.wikipedia.org/wiki/Measure_(mathematics)> * <https://en.wikipedia.org/wiki/Complete_measure> * <https://en.wikipedia.org/wiki/Almost_everywhere> ## Tags measure, almost everywhere, measure space, completion, null set, null measurable set -/ noncomputable section open Set open Filter hiding map open Function MeasurableSpace Topology Filter ENNReal NNReal Interval MeasureTheory open scoped symmDiff variable {α β γ δ ι R R' : Type*} namespace MeasureTheory section variable {m : MeasurableSpace α} {μ μ₁ μ₂ : Measure α} {s s₁ s₂ t : Set α} instance ae_isMeasurablyGenerated : IsMeasurablyGenerated (ae μ) := ⟨fun _s hs => let ⟨t, hst, htm, htμ⟩ := exists_measurable_superset_of_null hs ⟨tᶜ, compl_mem_ae_iff.2 htμ, htm.compl, compl_subset_comm.1 hst⟩⟩ /-- See also `MeasureTheory.ae_restrict_uIoc_iff`. -/ theorem ae_uIoc_iff [LinearOrder α] {a b : α} {P : α → Prop} : (∀ᵐ x ∂μ, x ∈ Ι a b → P x) ↔ (∀ᵐ x ∂μ, x ∈ Ioc a b → P x) ∧ ∀ᵐ x ∂μ, x ∈ Ioc b a → P x := by simp only [uIoc_eq_union, mem_union, or_imp, eventually_and] theorem measure_union (hd : Disjoint s₁ s₂) (h : MeasurableSet s₂) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ := measure_union₀ h.nullMeasurableSet hd.aedisjoint theorem measure_union' (hd : Disjoint s₁ s₂) (h : MeasurableSet s₁) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ := measure_union₀' h.nullMeasurableSet hd.aedisjoint theorem measure_inter_add_diff (s : Set α) (ht : MeasurableSet t) : μ (s ∩ t) + μ (s \ t) = μ s := measure_inter_add_diff₀ _ ht.nullMeasurableSet theorem measure_diff_add_inter (s : Set α) (ht : MeasurableSet t) : μ (s \ t) + μ (s ∩ t) = μ s := (add_comm _ _).trans (measure_inter_add_diff s ht) theorem measure_diff_eq_top (hs : μ s = ∞) (ht : μ t ≠ ∞) : μ (s \ t) = ∞ := by contrapose! hs exact ((measure_mono (subset_diff_union s t)).trans_lt ((measure_union_le _ _).trans_lt (ENNReal.add_lt_top.2 ⟨hs.lt_top, ht.lt_top⟩))).ne theorem measure_union_add_inter (s : Set α) (ht : MeasurableSet t) : μ (s ∪ t) + μ (s ∩ t) = μ s + μ t := by rw [← measure_inter_add_diff (s ∪ t) ht, Set.union_inter_cancel_right, union_diff_right, ← measure_inter_add_diff s ht] ac_rfl theorem measure_union_add_inter' (hs : MeasurableSet s) (t : Set α) : μ (s ∪ t) + μ (s ∩ t) = μ s + μ t := by rw [union_comm, inter_comm, measure_union_add_inter t hs, add_comm] lemma measure_symmDiff_eq (hs : NullMeasurableSet s μ) (ht : NullMeasurableSet t μ) : μ (s ∆ t) = μ (s \ t) + μ (t \ s) := by simpa only [symmDiff_def, sup_eq_union] using measure_union₀ (ht.diff hs) disjoint_sdiff_sdiff.aedisjoint lemma measure_symmDiff_le (s t u : Set α) : μ (s ∆ u) ≤ μ (s ∆ t) + μ (t ∆ u) := le_trans (μ.mono <| symmDiff_triangle s t u) (measure_union_le (s ∆ t) (t ∆ u)) theorem measure_symmDiff_eq_top (hs : μ s ≠ ∞) (ht : μ t = ∞) : μ (s ∆ t) = ∞ := measure_mono_top subset_union_right (measure_diff_eq_top ht hs) theorem measure_add_measure_compl (h : MeasurableSet s) : μ s + μ sᶜ = μ univ := measure_add_measure_compl₀ h.nullMeasurableSet theorem measure_biUnion₀ {s : Set β} {f : β → Set α} (hs : s.Countable) (hd : s.Pairwise (AEDisjoint μ on f)) (h : ∀ b ∈ s, NullMeasurableSet (f b) μ) : μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) := by haveI := hs.toEncodable rw [biUnion_eq_iUnion] exact measure_iUnion₀ (hd.on_injective Subtype.coe_injective fun x => x.2) fun x => h x x.2 theorem measure_biUnion {s : Set β} {f : β → Set α} (hs : s.Countable) (hd : s.PairwiseDisjoint f) (h : ∀ b ∈ s, MeasurableSet (f b)) : μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) := measure_biUnion₀ hs hd.aedisjoint fun b hb => (h b hb).nullMeasurableSet theorem measure_sUnion₀ {S : Set (Set α)} (hs : S.Countable) (hd : S.Pairwise (AEDisjoint μ)) (h : ∀ s ∈ S, NullMeasurableSet s μ) : μ (⋃₀ S) = ∑' s : S, μ s := by rw [sUnion_eq_biUnion, measure_biUnion₀ hs hd h] theorem measure_sUnion {S : Set (Set α)} (hs : S.Countable) (hd : S.Pairwise Disjoint) (h : ∀ s ∈ S, MeasurableSet s) : μ (⋃₀ S) = ∑' s : S, μ s := by rw [sUnion_eq_biUnion, measure_biUnion hs hd h] theorem measure_biUnion_finset₀ {s : Finset ι} {f : ι → Set α} (hd : Set.Pairwise (↑s) (AEDisjoint μ on f)) (hm : ∀ b ∈ s, NullMeasurableSet (f b) μ) : μ (⋃ b ∈ s, f b) = ∑ p ∈ s, μ (f p) := by rw [← Finset.sum_attach, Finset.attach_eq_univ, ← tsum_fintype] exact measure_biUnion₀ s.countable_toSet hd hm theorem measure_biUnion_finset {s : Finset ι} {f : ι → Set α} (hd : PairwiseDisjoint (↑s) f) (hm : ∀ b ∈ s, MeasurableSet (f b)) : μ (⋃ b ∈ s, f b) = ∑ p ∈ s, μ (f p) := measure_biUnion_finset₀ hd.aedisjoint fun b hb => (hm b hb).nullMeasurableSet /-- The measure of an a.e. disjoint union (even uncountable) of null-measurable sets is at least the sum of the measures of the sets. -/ theorem tsum_meas_le_meas_iUnion_of_disjoint₀ {ι : Type*} {_ : MeasurableSpace α} (μ : Measure α) {As : ι → Set α} (As_mble : ∀ i : ι, NullMeasurableSet (As i) μ) (As_disj : Pairwise (AEDisjoint μ on As)) : (∑' i, μ (As i)) ≤ μ (⋃ i, As i) := by rw [ENNReal.tsum_eq_iSup_sum, iSup_le_iff] intro s simp only [← measure_biUnion_finset₀ (fun _i _hi _j _hj hij => As_disj hij) fun i _ => As_mble i] gcongr exact iUnion_subset fun _ ↦ Subset.rfl /-- The measure of a disjoint union (even uncountable) of measurable sets is at least the sum of the measures of the sets. -/ theorem tsum_meas_le_meas_iUnion_of_disjoint {ι : Type*} {_ : MeasurableSpace α} (μ : Measure α) {As : ι → Set α} (As_mble : ∀ i : ι, MeasurableSet (As i)) (As_disj : Pairwise (Disjoint on As)) : (∑' i, μ (As i)) ≤ μ (⋃ i, As i) := tsum_meas_le_meas_iUnion_of_disjoint₀ μ (fun i ↦ (As_mble i).nullMeasurableSet) (fun _ _ h ↦ Disjoint.aedisjoint (As_disj h)) /-- If `s` is a countable set, then the measure of its preimage can be found as the sum of measures of the fibers `f ⁻¹' {y}`. -/ theorem tsum_measure_preimage_singleton {s : Set β} (hs : s.Countable) {f : α → β} (hf : ∀ y ∈ s, MeasurableSet (f ⁻¹' {y})) : (∑' b : s, μ (f ⁻¹' {↑b})) = μ (f ⁻¹' s) := by rw [← Set.biUnion_preimage_singleton, measure_biUnion hs (pairwiseDisjoint_fiber f s) hf] lemma measure_preimage_eq_zero_iff_of_countable {s : Set β} {f : α → β} (hs : s.Countable) : μ (f ⁻¹' s) = 0 ↔ ∀ x ∈ s, μ (f ⁻¹' {x}) = 0 := by rw [← biUnion_preimage_singleton, measure_biUnion_null_iff hs] /-- If `s` is a `Finset`, then the measure of its preimage can be found as the sum of measures of the fibers `f ⁻¹' {y}`. -/ theorem sum_measure_preimage_singleton (s : Finset β) {f : α → β} (hf : ∀ y ∈ s, MeasurableSet (f ⁻¹' {y})) : (∑ b ∈ s, μ (f ⁻¹' {b})) = μ (f ⁻¹' ↑s) := by simp only [← measure_biUnion_finset (pairwiseDisjoint_fiber f s) hf, Finset.set_biUnion_preimage_singleton] @[simp] lemma sum_measure_singleton {s : Finset α} [MeasurableSingletonClass α] : ∑ x ∈ s, μ {x} = μ s := by trans ∑ x ∈ s, μ (id ⁻¹' {x}) · simp rw [sum_measure_preimage_singleton] · simp · simp theorem measure_diff_null' (h : μ (s₁ ∩ s₂) = 0) : μ (s₁ \ s₂) = μ s₁ := measure_congr <| diff_ae_eq_self.2 h theorem measure_add_diff (hs : NullMeasurableSet s μ) (t : Set α) : μ s + μ (t \ s) = μ (s ∪ t) := by rw [← measure_union₀' hs disjoint_sdiff_right.aedisjoint, union_diff_self] theorem measure_diff' (s : Set α) (hm : NullMeasurableSet t μ) (h_fin : μ t ≠ ∞) : μ (s \ t) = μ (s ∪ t) - μ t := ENNReal.eq_sub_of_add_eq h_fin <| by rw [add_comm, measure_add_diff hm, union_comm] theorem measure_diff (h : s₂ ⊆ s₁) (h₂ : NullMeasurableSet s₂ μ) (h_fin : μ s₂ ≠ ∞) : μ (s₁ \ s₂) = μ s₁ - μ s₂ := by rw [measure_diff' _ h₂ h_fin, union_eq_self_of_subset_right h] theorem le_measure_diff : μ s₁ - μ s₂ ≤ μ (s₁ \ s₂) := tsub_le_iff_left.2 <| (measure_le_inter_add_diff μ s₁ s₂).trans <| by gcongr; apply inter_subset_right /-- If the measure of the symmetric difference of two sets is finite, then one has infinite measure if and only if the other one does. -/ theorem measure_eq_top_iff_of_symmDiff (hμst : μ (s ∆ t) ≠ ∞) : μ s = ∞ ↔ μ t = ∞ := by suffices h : ∀ u v, μ (u ∆ v) ≠ ∞ → μ u = ∞ → μ v = ∞ from ⟨h s t hμst, h t s (symmDiff_comm s t ▸ hμst)⟩ intro u v hμuv hμu by_contra! hμv apply hμuv rw [Set.symmDiff_def, eq_top_iff] calc ∞ = μ u - μ v := by rw [ENNReal.sub_eq_top_iff.2 ⟨hμu, hμv⟩] _ ≤ μ (u \ v) := le_measure_diff _ ≤ μ (u \ v ∪ v \ u) := measure_mono subset_union_left /-- If the measure of the symmetric difference of two sets is finite, then one has finite measure if and only if the other one does. -/ theorem measure_ne_top_iff_of_symmDiff (hμst : μ (s ∆ t) ≠ ∞) : μ s ≠ ∞ ↔ μ t ≠ ∞ := (measure_eq_top_iff_of_symmDiff hμst).ne theorem measure_diff_lt_of_lt_add (hs : NullMeasurableSet s μ) (hst : s ⊆ t) (hs' : μ s ≠ ∞) {ε : ℝ≥0∞} (h : μ t < μ s + ε) : μ (t \ s) < ε := by rw [measure_diff hst hs hs']; rw [add_comm] at h exact ENNReal.sub_lt_of_lt_add (measure_mono hst) h theorem measure_diff_le_iff_le_add (hs : NullMeasurableSet s μ) (hst : s ⊆ t) (hs' : μ s ≠ ∞) {ε : ℝ≥0∞} : μ (t \ s) ≤ ε ↔ μ t ≤ μ s + ε := by rw [measure_diff hst hs hs', tsub_le_iff_left] theorem measure_eq_measure_of_null_diff {s t : Set α} (hst : s ⊆ t) (h_nulldiff : μ (t \ s) = 0) : μ s = μ t := measure_congr <| EventuallyLE.antisymm (HasSubset.Subset.eventuallyLE hst) (ae_le_set.mpr h_nulldiff) theorem measure_eq_measure_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₁ = μ s₂ ∧ μ s₂ = μ s₃ := by have le12 : μ s₁ ≤ μ s₂ := measure_mono h12 have le23 : μ s₂ ≤ μ s₃ := measure_mono h23 have key : μ s₃ ≤ μ s₁ := calc μ s₃ = μ (s₃ \ s₁ ∪ s₁) := by rw [diff_union_of_subset (h12.trans h23)] _ ≤ μ (s₃ \ s₁) + μ s₁ := measure_union_le _ _ _ = μ s₁ := by simp only [h_nulldiff, zero_add] exact ⟨le12.antisymm (le23.trans key), le23.antisymm (key.trans le12)⟩ theorem measure_eq_measure_smaller_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₁ = μ s₂ := (measure_eq_measure_of_between_null_diff h12 h23 h_nulldiff).1 theorem measure_eq_measure_larger_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₂ = μ s₃ := (measure_eq_measure_of_between_null_diff h12 h23 h_nulldiff).2 lemma measure_compl₀ (h : NullMeasurableSet s μ) (hs : μ s ≠ ∞) : μ sᶜ = μ Set.univ - μ s := by rw [← measure_add_measure_compl₀ h, ENNReal.add_sub_cancel_left hs] theorem measure_compl (h₁ : MeasurableSet s) (h_fin : μ s ≠ ∞) : μ sᶜ = μ univ - μ s := measure_compl₀ h₁.nullMeasurableSet h_fin lemma measure_inter_conull' (ht : μ (s \ t) = 0) : μ (s ∩ t) = μ s := by rw [← diff_compl, measure_diff_null']; rwa [← diff_eq] lemma measure_inter_conull (ht : μ tᶜ = 0) : μ (s ∩ t) = μ s := by rw [← diff_compl, measure_diff_null ht] @[simp] theorem union_ae_eq_left_iff_ae_subset : (s ∪ t : Set α) =ᵐ[μ] s ↔ t ≤ᵐ[μ] s := by rw [ae_le_set] refine ⟨fun h => by simpa only [union_diff_left] using (ae_eq_set.mp h).1, fun h => eventuallyLE_antisymm_iff.mpr ⟨by rwa [ae_le_set, union_diff_left], HasSubset.Subset.eventuallyLE subset_union_left⟩⟩ @[simp] theorem union_ae_eq_right_iff_ae_subset : (s ∪ t : Set α) =ᵐ[μ] t ↔ s ≤ᵐ[μ] t := by rw [union_comm, union_ae_eq_left_iff_ae_subset] theorem ae_eq_of_ae_subset_of_measure_ge (h₁ : s ≤ᵐ[μ] t) (h₂ : μ t ≤ μ s) (hsm : NullMeasurableSet s μ) (ht : μ t ≠ ∞) : s =ᵐ[μ] t := by refine eventuallyLE_antisymm_iff.mpr ⟨h₁, ae_le_set.mpr ?_⟩ replace h₂ : μ t = μ s := h₂.antisymm (measure_mono_ae h₁) replace ht : μ s ≠ ∞ := h₂ ▸ ht rw [measure_diff' t hsm ht, measure_congr (union_ae_eq_left_iff_ae_subset.mpr h₁), h₂, tsub_self] /-- If `s ⊆ t`, `μ t ≤ μ s`, `μ t ≠ ∞`, and `s` is measurable, then `s =ᵐ[μ] t`. -/ theorem ae_eq_of_subset_of_measure_ge (h₁ : s ⊆ t) (h₂ : μ t ≤ μ s) (hsm : NullMeasurableSet s μ) (ht : μ t ≠ ∞) : s =ᵐ[μ] t := ae_eq_of_ae_subset_of_measure_ge (HasSubset.Subset.eventuallyLE h₁) h₂ hsm ht theorem measure_iUnion_congr_of_subset {ι : Sort*} [Countable ι] {s : ι → Set α} {t : ι → Set α} (hsub : ∀ i, s i ⊆ t i) (h_le : ∀ i, μ (t i) ≤ μ (s i)) : μ (⋃ i, s i) = μ (⋃ i, t i) := by refine le_antisymm (by gcongr; apply hsub) ?_ rcases Classical.em (∃ i, μ (t i) = ∞) with (⟨i, hi⟩ | htop)
· calc μ (⋃ i, t i) ≤ ∞ := le_top _ ≤ μ (s i) := hi ▸ h_le i _ ≤ μ (⋃ i, s i) := measure_mono <| subset_iUnion _ _ push_neg at htop set M := toMeasurable μ
Mathlib/MeasureTheory/Measure/MeasureSpace.lean
333
338
/- Copyright (c) 2019 Gabriel Ebner. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Gabriel Ebner, Sébastien Gouëzel, Yury Kudryashov, Yuyang Zhao -/ import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.Analysis.Calculus.FDeriv.Comp import Mathlib.Analysis.Calculus.FDeriv.RestrictScalars /-! # One-dimensional derivatives of compositions of functions In this file we prove the chain rule for the following cases: * `HasDerivAt.comp` etc: `f : 𝕜' → 𝕜'` composed with `g : 𝕜 → 𝕜'`; * `HasDerivAt.scomp` etc: `f : 𝕜' → E` composed with `g : 𝕜 → 𝕜'`; * `HasFDerivAt.comp_hasDerivAt` etc: `f : E → F` composed with `g : 𝕜 → E`; Here `𝕜` is the base normed field, `E` and `F` are normed spaces over `𝕜` and `𝕜'` is an algebra over `𝕜` (e.g., `𝕜'=𝕜` or `𝕜=ℝ`, `𝕜'=ℂ`). We also give versions with the `of_eq` suffix, which require an equality proof instead of definitional equality of the different points used in the composition. These versions are often more flexible to use. For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of `analysis/calculus/deriv/basic`. ## Keywords derivative, chain rule -/ universe u v w open scoped Topology Filter ENNReal open Filter Asymptotics Set open ContinuousLinearMap (smulRight smulRight_one_eq_iff) variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {f : 𝕜 → F} variable {f' : F} variable {x : 𝕜} variable {s : Set 𝕜} variable {L : Filter 𝕜} section Composition /-! ### Derivative of the composition of a vector function and a scalar function We use `scomp` in lemmas on composition of vector valued and scalar valued functions, and `comp` in lemmas on composition of scalar valued functions, in analogy for `smul` and `mul` (and also because the `comp` version with the shorter name will show up much more often in applications). The formula for the derivative involves `smul` in `scomp` lemmas, which can be reduced to usual multiplication in `comp` lemmas. -/ /- For composition lemmas, we put x explicit to help the elaborator, as otherwise Lean tends to get confused since there are too many possibilities for composition -/ variable {𝕜' : Type*} [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] [NormedSpace 𝕜' F] [IsScalarTower 𝕜 𝕜' F] {s' t' : Set 𝕜'} {h : 𝕜 → 𝕜'} {h₂ : 𝕜' → 𝕜'} {h' h₂' : 𝕜'} {g₁ : 𝕜' → F} {g₁' : F} {L' : Filter 𝕜'} {y : 𝕜'} (x) theorem HasDerivAtFilter.scomp (hg : HasDerivAtFilter g₁ g₁' (h x) L') (hh : HasDerivAtFilter h h' x L) (hL : Tendsto h L L') : HasDerivAtFilter (g₁ ∘ h) (h' • g₁') x L := by simpa using ((hg.restrictScalars 𝕜).comp x hh hL).hasDerivAtFilter theorem HasDerivAtFilter.scomp_of_eq (hg : HasDerivAtFilter g₁ g₁' y L') (hh : HasDerivAtFilter h h' x L) (hy : y = h x) (hL : Tendsto h L L') : HasDerivAtFilter (g₁ ∘ h) (h' • g₁') x L := by rw [hy] at hg; exact hg.scomp x hh hL theorem HasDerivWithinAt.scomp_hasDerivAt (hg : HasDerivWithinAt g₁ g₁' s' (h x)) (hh : HasDerivAt h h' x) (hs : ∀ x, h x ∈ s') : HasDerivAt (g₁ ∘ h) (h' • g₁') x := hg.scomp x hh <| tendsto_inf.2 ⟨hh.continuousAt, tendsto_principal.2 <| Eventually.of_forall hs⟩ theorem HasDerivWithinAt.scomp_hasDerivAt_of_eq (hg : HasDerivWithinAt g₁ g₁' s' y) (hh : HasDerivAt h h' x) (hs : ∀ x, h x ∈ s') (hy : y = h x) : HasDerivAt (g₁ ∘ h) (h' • g₁') x := by rw [hy] at hg; exact hg.scomp_hasDerivAt x hh hs nonrec theorem HasDerivWithinAt.scomp (hg : HasDerivWithinAt g₁ g₁' t' (h x)) (hh : HasDerivWithinAt h h' s x) (hst : MapsTo h s t') : HasDerivWithinAt (g₁ ∘ h) (h' • g₁') s x := hg.scomp x hh <| hh.continuousWithinAt.tendsto_nhdsWithin hst theorem HasDerivWithinAt.scomp_of_eq (hg : HasDerivWithinAt g₁ g₁' t' y) (hh : HasDerivWithinAt h h' s x) (hst : MapsTo h s t') (hy : y = h x) : HasDerivWithinAt (g₁ ∘ h) (h' • g₁') s x := by rw [hy] at hg; exact hg.scomp x hh hst /-- The chain rule. -/ nonrec theorem HasDerivAt.scomp (hg : HasDerivAt g₁ g₁' (h x)) (hh : HasDerivAt h h' x) : HasDerivAt (g₁ ∘ h) (h' • g₁') x := hg.scomp x hh hh.continuousAt /-- The chain rule. -/ theorem HasDerivAt.scomp_of_eq (hg : HasDerivAt g₁ g₁' y) (hh : HasDerivAt h h' x) (hy : y = h x) : HasDerivAt (g₁ ∘ h) (h' • g₁') x := by rw [hy] at hg; exact hg.scomp x hh theorem HasStrictDerivAt.scomp (hg : HasStrictDerivAt g₁ g₁' (h x)) (hh : HasStrictDerivAt h h' x) : HasStrictDerivAt (g₁ ∘ h) (h' • g₁') x := by simpa using ((hg.restrictScalars 𝕜).comp x hh).hasStrictDerivAt theorem HasStrictDerivAt.scomp_of_eq (hg : HasStrictDerivAt g₁ g₁' y) (hh : HasStrictDerivAt h h' x) (hy : y = h x) : HasStrictDerivAt (g₁ ∘ h) (h' • g₁') x := by rw [hy] at hg; exact hg.scomp x hh theorem HasDerivAt.scomp_hasDerivWithinAt (hg : HasDerivAt g₁ g₁' (h x)) (hh : HasDerivWithinAt h h' s x) : HasDerivWithinAt (g₁ ∘ h) (h' • g₁') s x := HasDerivWithinAt.scomp x hg.hasDerivWithinAt hh (mapsTo_univ _ _) theorem HasDerivAt.scomp_hasDerivWithinAt_of_eq (hg : HasDerivAt g₁ g₁' y) (hh : HasDerivWithinAt h h' s x) (hy : y = h x) : HasDerivWithinAt (g₁ ∘ h) (h' • g₁') s x := by rw [hy] at hg; exact hg.scomp_hasDerivWithinAt x hh theorem derivWithin.scomp (hg : DifferentiableWithinAt 𝕜' g₁ t' (h x)) (hh : DifferentiableWithinAt 𝕜 h s x) (hs : MapsTo h s t') : derivWithin (g₁ ∘ h) s x = derivWithin h s x • derivWithin g₁ t' (h x) := by by_cases hsx : UniqueDiffWithinAt 𝕜 s x · exact (HasDerivWithinAt.scomp x hg.hasDerivWithinAt hh.hasDerivWithinAt hs).derivWithin hsx · simp [derivWithin_zero_of_not_uniqueDiffWithinAt hsx] theorem derivWithin.scomp_of_eq (hg : DifferentiableWithinAt 𝕜' g₁ t' y) (hh : DifferentiableWithinAt 𝕜 h s x) (hs : MapsTo h s t') (hy : y = h x) : derivWithin (g₁ ∘ h) s x = derivWithin h s x • derivWithin g₁ t' (h x) := by rw [hy] at hg; exact derivWithin.scomp x hg hh hs theorem deriv.scomp (hg : DifferentiableAt 𝕜' g₁ (h x)) (hh : DifferentiableAt 𝕜 h x) : deriv (g₁ ∘ h) x = deriv h x • deriv g₁ (h x) := (HasDerivAt.scomp x hg.hasDerivAt hh.hasDerivAt).deriv theorem deriv.scomp_of_eq (hg : DifferentiableAt 𝕜' g₁ y) (hh : DifferentiableAt 𝕜 h x) (hy : y = h x) : deriv (g₁ ∘ h) x = deriv h x • deriv g₁ (h x) := by rw [hy] at hg; exact deriv.scomp x hg hh /-! ### Derivative of the composition of a scalar and vector functions -/ theorem HasDerivAtFilter.comp_hasFDerivAtFilter {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x) {L'' : Filter E} (hh₂ : HasDerivAtFilter h₂ h₂' (f x) L') (hf : HasFDerivAtFilter f f' x L'') (hL : Tendsto f L'' L') : HasFDerivAtFilter (h₂ ∘ f) (h₂' • f') x L'' := by convert (hh₂.restrictScalars 𝕜).comp x hf hL ext x simp [mul_comm] theorem HasDerivAtFilter.comp_hasFDerivAtFilter_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x) {L'' : Filter E} (hh₂ : HasDerivAtFilter h₂ h₂' y L') (hf : HasFDerivAtFilter f f' x L'') (hL : Tendsto f L'' L') (hy : y = f x) : HasFDerivAtFilter (h₂ ∘ f) (h₂' • f') x L'' := by rw [hy] at hh₂; exact hh₂.comp_hasFDerivAtFilter x hf hL theorem HasStrictDerivAt.comp_hasStrictFDerivAt {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x) (hh : HasStrictDerivAt h₂ h₂' (f x)) (hf : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (h₂ ∘ f) (h₂' • f') x := by rw [HasStrictDerivAt] at hh convert (hh.restrictScalars 𝕜).comp x hf ext x simp [mul_comm] theorem HasStrictDerivAt.comp_hasStrictFDerivAt_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x) (hh : HasStrictDerivAt h₂ h₂' y) (hf : HasStrictFDerivAt f f' x) (hy : y = f x) : HasStrictFDerivAt (h₂ ∘ f) (h₂' • f') x := by rw [hy] at hh; exact hh.comp_hasStrictFDerivAt x hf theorem HasDerivAt.comp_hasFDerivAt {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x) (hh : HasDerivAt h₂ h₂' (f x)) (hf : HasFDerivAt f f' x) : HasFDerivAt (h₂ ∘ f) (h₂' • f') x := hh.comp_hasFDerivAtFilter x hf hf.continuousAt theorem HasDerivAt.comp_hasFDerivAt_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} (x) (hh : HasDerivAt h₂ h₂' y) (hf : HasFDerivAt f f' x) (hy : y = f x) : HasFDerivAt (h₂ ∘ f) (h₂' • f') x := by rw [hy] at hh; exact hh.comp_hasFDerivAt x hf theorem HasDerivAt.comp_hasFDerivWithinAt {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} {s} (x) (hh : HasDerivAt h₂ h₂' (f x)) (hf : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (h₂ ∘ f) (h₂' • f') s x := hh.comp_hasFDerivAtFilter x hf hf.continuousWithinAt theorem HasDerivAt.comp_hasFDerivWithinAt_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} {s} (x) (hh : HasDerivAt h₂ h₂' y) (hf : HasFDerivWithinAt f f' s x) (hy : y = f x) : HasFDerivWithinAt (h₂ ∘ f) (h₂' • f') s x := by rw [hy] at hh; exact hh.comp_hasFDerivWithinAt x hf theorem HasDerivWithinAt.comp_hasFDerivWithinAt {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} {s t} (x) (hh : HasDerivWithinAt h₂ h₂' t (f x)) (hf : HasFDerivWithinAt f f' s x) (hst : MapsTo f s t) : HasFDerivWithinAt (h₂ ∘ f) (h₂' • f') s x := hh.comp_hasFDerivAtFilter x hf <| hf.continuousWithinAt.tendsto_nhdsWithin hst theorem HasDerivWithinAt.comp_hasFDerivWithinAt_of_eq {f : E → 𝕜'} {f' : E →L[𝕜] 𝕜'} {s t} (x) (hh : HasDerivWithinAt h₂ h₂' t y) (hf : HasFDerivWithinAt f f' s x) (hst : MapsTo f s t) (hy : y = f x) : HasFDerivWithinAt (h₂ ∘ f) (h₂' • f') s x := by rw [hy] at hh; exact hh.comp_hasFDerivWithinAt x hf hst /-! ### Derivative of the composition of two scalar functions -/ theorem HasDerivAtFilter.comp (hh₂ : HasDerivAtFilter h₂ h₂' (h x) L') (hh : HasDerivAtFilter h h' x L) (hL : Tendsto h L L') : HasDerivAtFilter (h₂ ∘ h) (h₂' * h') x L := by rw [mul_comm] exact hh₂.scomp x hh hL theorem HasDerivAtFilter.comp_of_eq (hh₂ : HasDerivAtFilter h₂ h₂' y L') (hh : HasDerivAtFilter h h' x L) (hL : Tendsto h L L') (hy : y = h x) : HasDerivAtFilter (h₂ ∘ h) (h₂' * h') x L := by rw [hy] at hh₂; exact hh₂.comp x hh hL theorem HasDerivWithinAt.comp (hh₂ : HasDerivWithinAt h₂ h₂' s' (h x)) (hh : HasDerivWithinAt h h' s x) (hst : MapsTo h s s') : HasDerivWithinAt (h₂ ∘ h) (h₂' * h') s x := by rw [mul_comm] exact hh₂.scomp x hh hst theorem HasDerivWithinAt.comp_of_eq (hh₂ : HasDerivWithinAt h₂ h₂' s' y) (hh : HasDerivWithinAt h h' s x) (hst : MapsTo h s s') (hy : y = h x) : HasDerivWithinAt (h₂ ∘ h) (h₂' * h') s x := by rw [hy] at hh₂; exact hh₂.comp x hh hst /-- The chain rule. Note that the function `h₂` is a function on an algebra. If you are looking for the chain rule with `h₂` taking values in a vector space, use `HasDerivAt.scomp`. -/ nonrec theorem HasDerivAt.comp (hh₂ : HasDerivAt h₂ h₂' (h x)) (hh : HasDerivAt h h' x) : HasDerivAt (h₂ ∘ h) (h₂' * h') x := hh₂.comp x hh hh.continuousAt /-- The chain rule. Note that the function `h₂` is a function on an algebra. If you are looking for the chain rule with `h₂` taking values in a vector space, use `HasDerivAt.scomp_of_eq`. -/ theorem HasDerivAt.comp_of_eq (hh₂ : HasDerivAt h₂ h₂' y) (hh : HasDerivAt h h' x) (hy : y = h x) : HasDerivAt (h₂ ∘ h) (h₂' * h') x := by rw [hy] at hh₂; exact hh₂.comp x hh theorem HasStrictDerivAt.comp (hh₂ : HasStrictDerivAt h₂ h₂' (h x)) (hh : HasStrictDerivAt h h' x) : HasStrictDerivAt (h₂ ∘ h) (h₂' * h') x := by rw [mul_comm] exact hh₂.scomp x hh theorem HasStrictDerivAt.comp_of_eq (hh₂ : HasStrictDerivAt h₂ h₂' y) (hh : HasStrictDerivAt h h' x) (hy : y = h x) : HasStrictDerivAt (h₂ ∘ h) (h₂' * h') x := by rw [hy] at hh₂; exact hh₂.comp x hh theorem HasDerivAt.comp_hasDerivWithinAt (hh₂ : HasDerivAt h₂ h₂' (h x)) (hh : HasDerivWithinAt h h' s x) : HasDerivWithinAt (h₂ ∘ h) (h₂' * h') s x := hh₂.hasDerivWithinAt.comp x hh (mapsTo_univ _ _) theorem HasDerivAt.comp_hasDerivWithinAt_of_eq (hh₂ : HasDerivAt h₂ h₂' y) (hh : HasDerivWithinAt h h' s x) (hy : y = h x) : HasDerivWithinAt (h₂ ∘ h) (h₂' * h') s x := by rw [hy] at hh₂; exact hh₂.comp_hasDerivWithinAt x hh theorem derivWithin_comp (hh₂ : DifferentiableWithinAt 𝕜' h₂ s' (h x)) (hh : DifferentiableWithinAt 𝕜 h s x) (hs : MapsTo h s s') : derivWithin (h₂ ∘ h) s x = derivWithin h₂ s' (h x) * derivWithin h s x := by by_cases hsx : UniqueDiffWithinAt 𝕜 s x · exact (hh₂.hasDerivWithinAt.comp x hh.hasDerivWithinAt hs).derivWithin hsx · simp [derivWithin_zero_of_not_uniqueDiffWithinAt hsx] @[deprecated (since := "2024-10-31")] alias derivWithin.comp := derivWithin_comp theorem derivWithin_comp_of_eq (hh₂ : DifferentiableWithinAt 𝕜' h₂ s' y) (hh : DifferentiableWithinAt 𝕜 h s x) (hs : MapsTo h s s') (hy : h x = y) : derivWithin (h₂ ∘ h) s x = derivWithin h₂ s' (h x) * derivWithin h s x := by subst hy; exact derivWithin_comp x hh₂ hh hs @[deprecated (since := "2024-10-31")] alias derivWithin.comp_of_eq := derivWithin_comp_of_eq theorem deriv_comp (hh₂ : DifferentiableAt 𝕜' h₂ (h x)) (hh : DifferentiableAt 𝕜 h x) : deriv (h₂ ∘ h) x = deriv h₂ (h x) * deriv h x := (hh₂.hasDerivAt.comp x hh.hasDerivAt).deriv @[deprecated (since := "2024-10-31")] alias deriv.comp := deriv_comp theorem deriv_comp_of_eq (hh₂ : DifferentiableAt 𝕜' h₂ y) (hh : DifferentiableAt 𝕜 h x) (hy : h x = y) : deriv (h₂ ∘ h) x = deriv h₂ (h x) * deriv h x := by subst hy; exact deriv_comp x hh₂ hh @[deprecated (since := "2024-10-31")] alias deriv.comp_of_eq := deriv_comp_of_eq protected nonrec theorem HasDerivAtFilter.iterate {f : 𝕜 → 𝕜} {f' : 𝕜} (hf : HasDerivAtFilter f f' x L) (hL : Tendsto f L L) (hx : f x = x) (n : ℕ) : HasDerivAtFilter f^[n] (f' ^ n) x L := by have := hf.iterate hL hx n rwa [ContinuousLinearMap.smulRight_one_pow] at this protected nonrec theorem HasDerivAt.iterate {f : 𝕜 → 𝕜} {f' : 𝕜} (hf : HasDerivAt f f' x) (hx : f x = x) (n : ℕ) : HasDerivAt f^[n] (f' ^ n) x := hf.iterate _ (have := hf.tendsto_nhds le_rfl; by rwa [hx] at this) hx n protected theorem HasDerivWithinAt.iterate {f : 𝕜 → 𝕜} {f' : 𝕜} (hf : HasDerivWithinAt f f' s x) (hx : f x = x) (hs : MapsTo f s s) (n : ℕ) : HasDerivWithinAt f^[n] (f' ^ n) s x := by have := HasFDerivWithinAt.iterate hf hx hs n rwa [ContinuousLinearMap.smulRight_one_pow] at this protected nonrec theorem HasStrictDerivAt.iterate {f : 𝕜 → 𝕜} {f' : 𝕜} (hf : HasStrictDerivAt f f' x) (hx : f x = x) (n : ℕ) : HasStrictDerivAt f^[n] (f' ^ n) x := by have := hf.iterate hx n rwa [ContinuousLinearMap.smulRight_one_pow] at this end Composition section CompositionVector /-! ### Derivative of the composition of a function between vector spaces and a function on `𝕜` -/ open ContinuousLinearMap variable {l : F → E} {l' : F →L[𝕜] E} {y : F} variable (x) /-- The composition `l ∘ f` where `l : F → E` and `f : 𝕜 → F`, has a derivative within a set equal to the Fréchet derivative of `l` applied to the derivative of `f`. -/ theorem HasFDerivWithinAt.comp_hasDerivWithinAt {t : Set F} (hl : HasFDerivWithinAt l l' t (f x)) (hf : HasDerivWithinAt f f' s x) (hst : MapsTo f s t) : HasDerivWithinAt (l ∘ f) (l' f') s x := by simpa only [one_apply, one_smul, smulRight_apply, coe_comp', (· ∘ ·)] using (hl.comp x hf.hasFDerivWithinAt hst).hasDerivWithinAt /-- The composition `l ∘ f` where `l : F → E` and `f : 𝕜 → F`, has a derivative within a set equal to the Fréchet derivative of `l` applied to the derivative of `f`. -/ theorem HasFDerivWithinAt.comp_hasDerivWithinAt_of_eq {t : Set F} (hl : HasFDerivWithinAt l l' t y) (hf : HasDerivWithinAt f f' s x) (hst : MapsTo f s t) (hy : y = f x) : HasDerivWithinAt (l ∘ f) (l' f') s x := by rw [hy] at hl; exact hl.comp_hasDerivWithinAt x hf hst theorem HasFDerivAt.comp_hasDerivWithinAt (hl : HasFDerivAt l l' (f x)) (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (l ∘ f) (l' f') s x := hl.hasFDerivWithinAt.comp_hasDerivWithinAt x hf (mapsTo_univ _ _) theorem HasFDerivAt.comp_hasDerivWithinAt_of_eq (hl : HasFDerivAt l l' y) (hf : HasDerivWithinAt f f' s x) (hy : y = f x) : HasDerivWithinAt (l ∘ f) (l' f') s x := by rw [hy] at hl; exact hl.comp_hasDerivWithinAt x hf /-- The composition `l ∘ f` where `l : F → E` and `f : 𝕜 → F`, has a derivative equal to the Fréchet derivative of `l` applied to the derivative of `f`. -/ theorem HasFDerivAt.comp_hasDerivAt (hl : HasFDerivAt l l' (f x)) (hf : HasDerivAt f f' x) : HasDerivAt (l ∘ f) (l' f') x := hasDerivWithinAt_univ.mp <| hl.comp_hasDerivWithinAt x hf.hasDerivWithinAt /-- The composition `l ∘ f` where `l : F → E` and `f : 𝕜 → F`, has a derivative equal to the Fréchet derivative of `l` applied to the derivative of `f`. -/ theorem HasFDerivAt.comp_hasDerivAt_of_eq (hl : HasFDerivAt l l' y) (hf : HasDerivAt f f' x) (hy : y = f x) : HasDerivAt (l ∘ f) (l' f') x := by rw [hy] at hl; exact hl.comp_hasDerivAt x hf theorem HasStrictFDerivAt.comp_hasStrictDerivAt (hl : HasStrictFDerivAt l l' (f x)) (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (l ∘ f) (l' f') x := by simpa only [one_apply, one_smul, smulRight_apply, coe_comp', (· ∘ ·)] using (hl.comp x hf.hasStrictFDerivAt).hasStrictDerivAt theorem HasStrictFDerivAt.comp_hasStrictDerivAt_of_eq (hl : HasStrictFDerivAt l l' y) (hf : HasStrictDerivAt f f' x) (hy : y = f x) : HasStrictDerivAt (l ∘ f) (l' f') x := by rw [hy] at hl; exact hl.comp_hasStrictDerivAt x hf theorem fderivWithin_comp_derivWithin {t : Set F} (hl : DifferentiableWithinAt 𝕜 l t (f x)) (hf : DifferentiableWithinAt 𝕜 f s x) (hs : MapsTo f s t) : derivWithin (l ∘ f) s x = (fderivWithin 𝕜 l t (f x) : F → E) (derivWithin f s x) := by by_cases hsx : UniqueDiffWithinAt 𝕜 s x · exact (hl.hasFDerivWithinAt.comp_hasDerivWithinAt x hf.hasDerivWithinAt hs).derivWithin hsx · simp [derivWithin_zero_of_not_uniqueDiffWithinAt hsx] @[deprecated (since := "2024-10-31")] alias fderivWithin.comp_derivWithin := fderivWithin_comp_derivWithin theorem fderivWithin_comp_derivWithin_of_eq {t : Set F} (hl : DifferentiableWithinAt 𝕜 l t y) (hf : DifferentiableWithinAt 𝕜 f s x) (hs : MapsTo f s t) (hy : y = f x) : derivWithin (l ∘ f) s x = (fderivWithin 𝕜 l t (f x) : F → E) (derivWithin f s x) := by rw [hy] at hl; exact fderivWithin_comp_derivWithin x hl hf hs
@[deprecated (since := "2024-10-31")] alias fderivWithin.comp_derivWithin_of_eq := fderivWithin_comp_derivWithin_of_eq
Mathlib/Analysis/Calculus/Deriv/Comp.lean
393
396
/- Copyright (c) 2021 Yuma Mizuno. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yuma Mizuno -/ import Mathlib.CategoryTheory.NatIso /-! # Bicategories In this file we define typeclass for bicategories. A bicategory `B` consists of * objects `a : B`, * 1-morphisms `f : a ⟶ b` between objects `a b : B`, and * 2-morphisms `η : f ⟶ g` between 1-morphisms `f g : a ⟶ b` between objects `a b : B`. We use `u`, `v`, and `w` as the universe variables for objects, 1-morphisms, and 2-morphisms, respectively. A typeclass for bicategories extends `CategoryTheory.CategoryStruct` typeclass. This means that we have * a composition `f ≫ g : a ⟶ c` for each 1-morphisms `f : a ⟶ b` and `g : b ⟶ c`, and * an identity `𝟙 a : a ⟶ a` for each object `a : B`. For each object `a b : B`, the collection of 1-morphisms `a ⟶ b` has a category structure. The 2-morphisms in the bicategory are implemented as the morphisms in this family of categories. The composition of 1-morphisms is in fact an object part of a functor `(a ⟶ b) ⥤ (b ⟶ c) ⥤ (a ⟶ c)`. The definition of bicategories in this file does not require this functor directly. Instead, it requires the whiskering functions. For a 1-morphism `f : a ⟶ b` and a 2-morphism `η : g ⟶ h` between 1-morphisms `g h : b ⟶ c`, there is a 2-morphism `whiskerLeft f η : f ≫ g ⟶ f ≫ h`. Similarly, for a 2-morphism `η : f ⟶ g` between 1-morphisms `f g : a ⟶ b` and a 1-morphism `f : b ⟶ c`, there is a 2-morphism `whiskerRight η h : f ≫ h ⟶ g ≫ h`. These satisfy the exchange law `whiskerLeft f θ ≫ whiskerRight η i = whiskerRight η h ≫ whiskerLeft g θ`, which is required as an axiom in the definition here. -/ namespace CategoryTheory universe w v u open Category Iso -- intended to be used with explicit universe parameters /-- In a bicategory, we can compose the 1-morphisms `f : a ⟶ b` and `g : b ⟶ c` to obtain a 1-morphism `f ≫ g : a ⟶ c`. This composition does not need to be strictly associative, but there is a specified associator, `α_ f g h : (f ≫ g) ≫ h ≅ f ≫ (g ≫ h)`. There is an identity 1-morphism `𝟙 a : a ⟶ a`, with specified left and right unitor isomorphisms `λ_ f : 𝟙 a ≫ f ≅ f` and `ρ_ f : f ≫ 𝟙 a ≅ f`. These associators and unitors satisfy the pentagon and triangle equations. See https://ncatlab.org/nlab/show/bicategory. -/ @[nolint checkUnivs] class Bicategory (B : Type u) extends CategoryStruct.{v} B where /-- The category structure on the collection of 1-morphisms -/ homCategory : ∀ a b : B, Category.{w} (a ⟶ b) := by infer_instance /-- Left whiskering for morphisms -/ whiskerLeft {a b c : B} (f : a ⟶ b) {g h : b ⟶ c} (η : g ⟶ h) : f ≫ g ⟶ f ≫ h /-- Right whiskering for morphisms -/ whiskerRight {a b c : B} {f g : a ⟶ b} (η : f ⟶ g) (h : b ⟶ c) : f ≫ h ⟶ g ≫ h /-- The associator isomorphism: `(f ≫ g) ≫ h ≅ f ≫ g ≫ h` -/ associator {a b c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) : (f ≫ g) ≫ h ≅ f ≫ g ≫ h /-- The left unitor: `𝟙 a ≫ f ≅ f` -/ leftUnitor {a b : B} (f : a ⟶ b) : 𝟙 a ≫ f ≅ f /-- The right unitor: `f ≫ 𝟙 b ≅ f` -/ rightUnitor {a b : B} (f : a ⟶ b) : f ≫ 𝟙 b ≅ f -- axioms for left whiskering: whiskerLeft_id : ∀ {a b c} (f : a ⟶ b) (g : b ⟶ c), whiskerLeft f (𝟙 g) = 𝟙 (f ≫ g) := by aesop_cat whiskerLeft_comp : ∀ {a b c} (f : a ⟶ b) {g h i : b ⟶ c} (η : g ⟶ h) (θ : h ⟶ i), whiskerLeft f (η ≫ θ) = whiskerLeft f η ≫ whiskerLeft f θ := by aesop_cat id_whiskerLeft : ∀ {a b} {f g : a ⟶ b} (η : f ⟶ g), whiskerLeft (𝟙 a) η = (leftUnitor f).hom ≫ η ≫ (leftUnitor g).inv := by aesop_cat comp_whiskerLeft : ∀ {a b c d} (f : a ⟶ b) (g : b ⟶ c) {h h' : c ⟶ d} (η : h ⟶ h'), whiskerLeft (f ≫ g) η = (associator f g h).hom ≫ whiskerLeft f (whiskerLeft g η) ≫ (associator f g h').inv := by aesop_cat -- axioms for right whiskering: id_whiskerRight : ∀ {a b c} (f : a ⟶ b) (g : b ⟶ c), whiskerRight (𝟙 f) g = 𝟙 (f ≫ g) := by aesop_cat comp_whiskerRight : ∀ {a b c} {f g h : a ⟶ b} (η : f ⟶ g) (θ : g ⟶ h) (i : b ⟶ c), whiskerRight (η ≫ θ) i = whiskerRight η i ≫ whiskerRight θ i := by aesop_cat whiskerRight_id : ∀ {a b} {f g : a ⟶ b} (η : f ⟶ g), whiskerRight η (𝟙 b) = (rightUnitor f).hom ≫ η ≫ (rightUnitor g).inv := by aesop_cat whiskerRight_comp : ∀ {a b c d} {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c) (h : c ⟶ d), whiskerRight η (g ≫ h) = (associator f g h).inv ≫ whiskerRight (whiskerRight η g) h ≫ (associator f' g h).hom := by aesop_cat -- associativity of whiskerings: whisker_assoc : ∀ {a b c d} (f : a ⟶ b) {g g' : b ⟶ c} (η : g ⟶ g') (h : c ⟶ d), whiskerRight (whiskerLeft f η) h = (associator f g h).hom ≫ whiskerLeft f (whiskerRight η h) ≫ (associator f g' h).inv := by aesop_cat -- exchange law of left and right whiskerings: whisker_exchange : ∀ {a b c} {f g : a ⟶ b} {h i : b ⟶ c} (η : f ⟶ g) (θ : h ⟶ i), whiskerLeft f θ ≫ whiskerRight η i = whiskerRight η h ≫ whiskerLeft g θ := by aesop_cat -- pentagon identity: pentagon : ∀ {a b c d e} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e), whiskerRight (associator f g h).hom i ≫ (associator f (g ≫ h) i).hom ≫ whiskerLeft f (associator g h i).hom = (associator (f ≫ g) h i).hom ≫ (associator f g (h ≫ i)).hom := by aesop_cat -- triangle identity: triangle : ∀ {a b c} (f : a ⟶ b) (g : b ⟶ c), (associator f (𝟙 b) g).hom ≫ whiskerLeft f (leftUnitor g).hom = whiskerRight (rightUnitor f).hom g := by aesop_cat namespace Bicategory @[inherit_doc] scoped infixr:81 " ◁ " => Bicategory.whiskerLeft @[inherit_doc] scoped infixl:81 " ▷ " => Bicategory.whiskerRight @[inherit_doc] scoped notation "α_" => Bicategory.associator @[inherit_doc] scoped notation "λ_" => Bicategory.leftUnitor @[inherit_doc] scoped notation "ρ_" => Bicategory.rightUnitor /-! ### Simp-normal form for 2-morphisms Rewriting involving associators and unitors could be very complicated. We try to ease this complexity by putting carefully chosen simp lemmas that rewrite any 2-morphisms into simp-normal form defined below. Rewriting into simp-normal form is also useful when applying (forthcoming) `coherence` tactic. The simp-normal form of 2-morphisms is defined to be an expression that has the minimal number of parentheses. More precisely, 1. it is a composition of 2-morphisms like `η₁ ≫ η₂ ≫ η₃ ≫ η₄ ≫ η₅` such that each `ηᵢ` is either a structural 2-morphisms (2-morphisms made up only of identities, associators, unitors) or non-structural 2-morphisms, and 2. each non-structural 2-morphism in the composition is of the form `f₁ ◁ f₂ ◁ f₃ ◁ η ▷ f₄ ▷ f₅`, where each `fᵢ` is a 1-morphism that is not the identity or a composite and `η` is a non-structural 2-morphisms that is also not the identity or a composite. Note that `f₁ ◁ f₂ ◁ f₃ ◁ η ▷ f₄ ▷ f₅` is actually `f₁ ◁ (f₂ ◁ (f₃ ◁ ((η ▷ f₄) ▷ f₅)))`. -/ attribute [instance] homCategory attribute [reassoc] whiskerLeft_comp id_whiskerLeft comp_whiskerLeft comp_whiskerRight whiskerRight_id whiskerRight_comp whisker_assoc whisker_exchange attribute [reassoc (attr := simp)] pentagon triangle /- The following simp attributes are put in order to rewrite any 2-morphisms into normal forms. There are associators and unitors in the RHS in the several simp lemmas here (e.g. `id_whiskerLeft`), which at first glance look more complicated than the LHS, but they will be eventually reduced by the pentagon or the triangle identities, and more generally, (forthcoming) `coherence` tactic. -/ attribute [simp] whiskerLeft_id whiskerLeft_comp id_whiskerLeft comp_whiskerLeft id_whiskerRight comp_whiskerRight whiskerRight_id whiskerRight_comp whisker_assoc variable {B : Type u} [Bicategory.{w, v} B] {a b c d e : B} @[reassoc (attr := simp)] theorem whiskerLeft_hom_inv (f : a ⟶ b) {g h : b ⟶ c} (η : g ≅ h) : f ◁ η.hom ≫ f ◁ η.inv = 𝟙 (f ≫ g) := by rw [← whiskerLeft_comp, hom_inv_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem hom_inv_whiskerRight {f g : a ⟶ b} (η : f ≅ g) (h : b ⟶ c) : η.hom ▷ h ≫ η.inv ▷ h = 𝟙 (f ≫ h) := by rw [← comp_whiskerRight, hom_inv_id, id_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_inv_hom (f : a ⟶ b) {g h : b ⟶ c} (η : g ≅ h) : f ◁ η.inv ≫ f ◁ η.hom = 𝟙 (f ≫ h) := by rw [← whiskerLeft_comp, inv_hom_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem inv_hom_whiskerRight {f g : a ⟶ b} (η : f ≅ g) (h : b ⟶ c) : η.inv ▷ h ≫ η.hom ▷ h = 𝟙 (g ≫ h) := by rw [← comp_whiskerRight, inv_hom_id, id_whiskerRight] /-- The left whiskering of a 2-isomorphism is a 2-isomorphism. -/ @[simps] def whiskerLeftIso (f : a ⟶ b) {g h : b ⟶ c} (η : g ≅ h) : f ≫ g ≅ f ≫ h where hom := f ◁ η.hom inv := f ◁ η.inv instance whiskerLeft_isIso (f : a ⟶ b) {g h : b ⟶ c} (η : g ⟶ h) [IsIso η] : IsIso (f ◁ η) := (whiskerLeftIso f (asIso η)).isIso_hom @[simp] theorem inv_whiskerLeft (f : a ⟶ b) {g h : b ⟶ c} (η : g ⟶ h) [IsIso η] : inv (f ◁ η) = f ◁ inv η := by apply IsIso.inv_eq_of_hom_inv_id simp only [← whiskerLeft_comp, whiskerLeft_id, IsIso.hom_inv_id] /-- The right whiskering of a 2-isomorphism is a 2-isomorphism. -/ @[simps!] def whiskerRightIso {f g : a ⟶ b} (η : f ≅ g) (h : b ⟶ c) : f ≫ h ≅ g ≫ h where hom := η.hom ▷ h inv := η.inv ▷ h instance whiskerRight_isIso {f g : a ⟶ b} (η : f ⟶ g) (h : b ⟶ c) [IsIso η] : IsIso (η ▷ h) := (whiskerRightIso (asIso η) h).isIso_hom @[simp] theorem inv_whiskerRight {f g : a ⟶ b} (η : f ⟶ g) (h : b ⟶ c) [IsIso η] : inv (η ▷ h) = inv η ▷ h := by apply IsIso.inv_eq_of_hom_inv_id simp only [← comp_whiskerRight, id_whiskerRight, IsIso.hom_inv_id] @[reassoc (attr := simp)] theorem pentagon_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : f ◁ (α_ g h i).inv ≫ (α_ f (g ≫ h) i).inv ≫ (α_ f g h).inv ▷ i = (α_ f g (h ≫ i)).inv ≫ (α_ (f ≫ g) h i).inv := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_inv_inv_hom_hom_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ f (g ≫ h) i).inv ≫ (α_ f g h).inv ▷ i ≫ (α_ (f ≫ g) h i).hom = f ◁ (α_ g h i).hom ≫ (α_ f g (h ≫ i)).inv := by rw [← cancel_epi (f ◁ (α_ g h i).inv), ← cancel_mono (α_ (f ≫ g) h i).inv] simp @[reassoc (attr := simp)] theorem pentagon_inv_hom_hom_hom_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ (f ≫ g) h i).inv ≫ (α_ f g h).hom ▷ i ≫ (α_ f (g ≫ h) i).hom = (α_ f g (h ≫ i)).hom ≫ f ◁ (α_ g h i).inv := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_hom_inv_inv_inv_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : f ◁ (α_ g h i).hom ≫ (α_ f g (h ≫ i)).inv ≫ (α_ (f ≫ g) h i).inv = (α_ f (g ≫ h) i).inv ≫ (α_ f g h).inv ▷ i := by simp [← cancel_epi (f ◁ (α_ g h i).inv)] @[reassoc (attr := simp)] theorem pentagon_hom_hom_inv_hom_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ (f ≫ g) h i).hom ≫ (α_ f g (h ≫ i)).hom ≫ f ◁ (α_ g h i).inv = (α_ f g h).hom ▷ i ≫ (α_ f (g ≫ h) i).hom := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_hom_inv_inv_inv_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ f g (h ≫ i)).hom ≫ f ◁ (α_ g h i).inv ≫ (α_ f (g ≫ h) i).inv = (α_ (f ≫ g) h i).inv ≫ (α_ f g h).hom ▷ i := by rw [← cancel_epi (α_ f g (h ≫ i)).inv, ← cancel_mono ((α_ f g h).inv ▷ i)] simp @[reassoc (attr := simp)] theorem pentagon_hom_hom_inv_inv_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ f (g ≫ h) i).hom ≫ f ◁ (α_ g h i).hom ≫ (α_ f g (h ≫ i)).inv = (α_ f g h).inv ▷ i ≫ (α_ (f ≫ g) h i).hom := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_inv_hom_hom_hom_hom (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ f g h).inv ▷ i ≫ (α_ (f ≫ g) h i).hom ≫ (α_ f g (h ≫ i)).hom = (α_ f (g ≫ h) i).hom ≫ f ◁ (α_ g h i).hom := by simp [← cancel_epi ((α_ f g h).hom ▷ i)] @[reassoc (attr := simp)] theorem pentagon_inv_inv_hom_inv_inv (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d) (i : d ⟶ e) : (α_ f g (h ≫ i)).inv ≫ (α_ (f ≫ g) h i).inv ≫ (α_ f g h).hom ▷ i = f ◁ (α_ g h i).inv ≫ (α_ f (g ≫ h) i).inv := eq_of_inv_eq_inv (by simp) theorem triangle_assoc_comp_left (f : a ⟶ b) (g : b ⟶ c) : (α_ f (𝟙 b) g).hom ≫ f ◁ (λ_ g).hom = (ρ_ f).hom ▷ g := triangle f g @[reassoc (attr := simp)] theorem triangle_assoc_comp_right (f : a ⟶ b) (g : b ⟶ c) : (α_ f (𝟙 b) g).inv ≫ (ρ_ f).hom ▷ g = f ◁ (λ_ g).hom := by rw [← triangle, inv_hom_id_assoc] @[reassoc (attr := simp)] theorem triangle_assoc_comp_right_inv (f : a ⟶ b) (g : b ⟶ c) : (ρ_ f).inv ▷ g ≫ (α_ f (𝟙 b) g).hom = f ◁ (λ_ g).inv := by simp [← cancel_mono (f ◁ (λ_ g).hom)] @[reassoc (attr := simp)] theorem triangle_assoc_comp_left_inv (f : a ⟶ b) (g : b ⟶ c) : f ◁ (λ_ g).inv ≫ (α_ f (𝟙 b) g).inv = (ρ_ f).inv ▷ g := by simp [← cancel_mono ((ρ_ f).hom ▷ g)] @[reassoc] theorem associator_naturality_left {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c) (h : c ⟶ d) : η ▷ g ▷ h ≫ (α_ f' g h).hom = (α_ f g h).hom ≫ η ▷ (g ≫ h) := by simp @[reassoc] theorem associator_inv_naturality_left {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c) (h : c ⟶ d) : η ▷ (g ≫ h) ≫ (α_ f' g h).inv = (α_ f g h).inv ≫ η ▷ g ▷ h := by simp @[reassoc] theorem whiskerRight_comp_symm {f f' : a ⟶ b} (η : f ⟶ f') (g : b ⟶ c) (h : c ⟶ d) : η ▷ g ▷ h = (α_ f g h).hom ≫ η ▷ (g ≫ h) ≫ (α_ f' g h).inv := by simp @[reassoc] theorem associator_naturality_middle (f : a ⟶ b) {g g' : b ⟶ c} (η : g ⟶ g') (h : c ⟶ d) : (f ◁ η) ▷ h ≫ (α_ f g' h).hom = (α_ f g h).hom ≫ f ◁ η ▷ h := by simp @[reassoc] theorem associator_inv_naturality_middle (f : a ⟶ b) {g g' : b ⟶ c} (η : g ⟶ g') (h : c ⟶ d) : f ◁ η ▷ h ≫ (α_ f g' h).inv = (α_ f g h).inv ≫ (f ◁ η) ▷ h := by simp @[reassoc] theorem whisker_assoc_symm (f : a ⟶ b) {g g' : b ⟶ c} (η : g ⟶ g') (h : c ⟶ d) : f ◁ η ▷ h = (α_ f g h).inv ≫ (f ◁ η) ▷ h ≫ (α_ f g' h).hom := by simp @[reassoc] theorem associator_naturality_right (f : a ⟶ b) (g : b ⟶ c) {h h' : c ⟶ d} (η : h ⟶ h') : (f ≫ g) ◁ η ≫ (α_ f g h').hom = (α_ f g h).hom ≫ f ◁ g ◁ η := by simp @[reassoc] theorem associator_inv_naturality_right (f : a ⟶ b) (g : b ⟶ c) {h h' : c ⟶ d} (η : h ⟶ h') : f ◁ g ◁ η ≫ (α_ f g h').inv = (α_ f g h).inv ≫ (f ≫ g) ◁ η := by simp @[reassoc] theorem comp_whiskerLeft_symm (f : a ⟶ b) (g : b ⟶ c) {h h' : c ⟶ d} (η : h ⟶ h') : f ◁ g ◁ η = (α_ f g h).inv ≫ (f ≫ g) ◁ η ≫ (α_ f g h').hom := by simp @[reassoc] theorem leftUnitor_naturality {f g : a ⟶ b} (η : f ⟶ g) : 𝟙 a ◁ η ≫ (λ_ g).hom = (λ_ f).hom ≫ η := by simp @[reassoc] theorem leftUnitor_inv_naturality {f g : a ⟶ b} (η : f ⟶ g) : η ≫ (λ_ g).inv = (λ_ f).inv ≫ 𝟙 a ◁ η := by simp theorem id_whiskerLeft_symm {f g : a ⟶ b} (η : f ⟶ g) : η = (λ_ f).inv ≫ 𝟙 a ◁ η ≫ (λ_ g).hom := by simp @[reassoc] theorem rightUnitor_naturality {f g : a ⟶ b} (η : f ⟶ g) : η ▷ 𝟙 b ≫ (ρ_ g).hom = (ρ_ f).hom ≫ η := by simp @[reassoc] theorem rightUnitor_inv_naturality {f g : a ⟶ b} (η : f ⟶ g) : η ≫ (ρ_ g).inv = (ρ_ f).inv ≫ η ▷ 𝟙 b := by simp theorem whiskerRight_id_symm {f g : a ⟶ b} (η : f ⟶ g) : η = (ρ_ f).inv ≫ η ▷ 𝟙 b ≫ (ρ_ g).hom := by simp theorem whiskerLeft_iff {f g : a ⟶ b} (η θ : f ⟶ g) : 𝟙 a ◁ η = 𝟙 a ◁ θ ↔ η = θ := by simp theorem whiskerRight_iff {f g : a ⟶ b} (η θ : f ⟶ g) : η ▷ 𝟙 b = θ ▷ 𝟙 b ↔ η = θ := by simp /-- We state it as a simp lemma, which is regarded as an involved version of `id_whiskerRight f g : 𝟙 f ▷ g = 𝟙 (f ≫ g)`. -/ @[reassoc, simp] theorem leftUnitor_whiskerRight (f : a ⟶ b) (g : b ⟶ c) : (λ_ f).hom ▷ g = (α_ (𝟙 a) f g).hom ≫ (λ_ (f ≫ g)).hom := by rw [← whiskerLeft_iff, whiskerLeft_comp, ← cancel_epi (α_ _ _ _).hom, ← cancel_epi ((α_ _ _ _).hom ▷ _), pentagon_assoc, triangle, ← associator_naturality_middle, ← comp_whiskerRight_assoc, triangle, associator_naturality_left] @[reassoc, simp] theorem leftUnitor_inv_whiskerRight (f : a ⟶ b) (g : b ⟶ c) : (λ_ f).inv ▷ g = (λ_ (f ≫ g)).inv ≫ (α_ (𝟙 a) f g).inv := eq_of_inv_eq_inv (by simp) @[reassoc, simp] theorem whiskerLeft_rightUnitor (f : a ⟶ b) (g : b ⟶ c) : f ◁ (ρ_ g).hom = (α_ f g (𝟙 c)).inv ≫ (ρ_ (f ≫ g)).hom := by rw [← whiskerRight_iff, comp_whiskerRight, ← cancel_epi (α_ _ _ _).inv, ← cancel_epi (f ◁ (α_ _ _ _).inv), pentagon_inv_assoc, triangle_assoc_comp_right, ← associator_inv_naturality_middle, ← whiskerLeft_comp_assoc, triangle_assoc_comp_right, associator_inv_naturality_right] @[reassoc, simp] theorem whiskerLeft_rightUnitor_inv (f : a ⟶ b) (g : b ⟶ c) : f ◁ (ρ_ g).inv = (ρ_ (f ≫ g)).inv ≫ (α_ f g (𝟙 c)).hom := eq_of_inv_eq_inv (by simp) /- It is not so obvious whether `leftUnitor_whiskerRight` or `leftUnitor_comp` should be a simp lemma. Our choice is the former. One reason is that the latter yields the following loop: [id_whiskerLeft] : 𝟙 a ◁ (ρ_ f).hom ==> (λ_ (f ≫ 𝟙 b)).hom ≫ (ρ_ f).hom ≫ (λ_ f).inv [leftUnitor_comp] : (λ_ (f ≫ 𝟙 b)).hom ==> (α_ (𝟙 a) f (𝟙 b)).inv ≫ (λ_ f).hom ▷ 𝟙 b [whiskerRight_id] : (λ_ f).hom ▷ 𝟙 b ==> (ρ_ (𝟙 a ≫ f)).hom ≫ (λ_ f).hom ≫ (ρ_ f).inv [rightUnitor_comp] : (ρ_ (𝟙 a ≫ f)).hom ==> (α_ (𝟙 a) f (𝟙 b)).hom ≫ 𝟙 a ◁ (ρ_ f).hom -/ @[reassoc] theorem leftUnitor_comp (f : a ⟶ b) (g : b ⟶ c) : (λ_ (f ≫ g)).hom = (α_ (𝟙 a) f g).inv ≫ (λ_ f).hom ▷ g := by simp @[reassoc]
theorem leftUnitor_comp_inv (f : a ⟶ b) (g : b ⟶ c) : (λ_ (f ≫ g)).inv = (λ_ f).inv ▷ g ≫ (α_ (𝟙 a) f g).hom := by simp
Mathlib/CategoryTheory/Bicategory/Basic.lean
399
400
/- 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⟩
Mathlib/Order/Interval/Set/Basic.lean
191
191
/- Copyright (c) 2021 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.Data.Prod.Lex import Mathlib.Data.Sigma.Lex import Mathlib.Order.RelIso.Set import Mathlib.Order.WellQuasiOrder import Mathlib.Tactic.TFAE /-! # Well-founded sets This file introduces versions of `WellFounded` and `WellQuasiOrdered` for sets. ## Main Definitions * `Set.WellFoundedOn s r` indicates that the relation `r` is well-founded when restricted to the set `s`. * `Set.IsWF s` indicates that `<` is well-founded when restricted to `s`. * `Set.PartiallyWellOrderedOn s r` indicates that the relation `r` is partially well-ordered (also known as well quasi-ordered) when restricted to the set `s`. * `Set.IsPWO s` indicates that any infinite sequence of elements in `s` contains an infinite monotone subsequence. Note that this is equivalent to containing only two comparable elements. ## Main Results * Higman's Lemma, `Set.PartiallyWellOrderedOn.partiallyWellOrderedOn_sublistForall₂`, shows that if `r` is partially well-ordered on `s`, then `List.SublistForall₂` is partially well-ordered on the set of lists of elements of `s`. The result was originally published by Higman, but this proof more closely follows Nash-Williams. * `Set.wellFoundedOn_iff` relates `well_founded_on` to the well-foundedness of a relation on the original type, to avoid dealing with subtypes. * `Set.IsWF.mono` shows that a subset of a well-founded subset is well-founded. * `Set.IsWF.union` shows that the union of two well-founded subsets is well-founded. * `Finset.isWF` shows that all `Finset`s are well-founded. ## TODO * Prove that `s` is partial well ordered iff it has no infinite descending chain or antichain. * Rename `Set.PartiallyWellOrderedOn` to `Set.WellQuasiOrderedOn` and `Set.IsPWO` to `Set.IsWQO`. ## References * [Higman, *Ordering by Divisibility in Abstract Algebras*][Higman52] * [Nash-Williams, *On Well-Quasi-Ordering Finite Trees*][Nash-Williams63] -/ assert_not_exists OrderedSemiring open scoped Function -- required for scoped `on` notation variable {ι α β γ : Type*} {π : ι → Type*} namespace Set /-! ### Relations well-founded on sets -/ /-- `s.WellFoundedOn r` indicates that the relation `r` is `WellFounded` when restricted to `s`. -/ def WellFoundedOn (s : Set α) (r : α → α → Prop) : Prop := WellFounded (Subrel r (· ∈ s)) @[simp] theorem wellFoundedOn_empty (r : α → α → Prop) : WellFoundedOn ∅ r := wellFounded_of_isEmpty _ section WellFoundedOn variable {r r' : α → α → Prop} section AnyRel variable {f : β → α} {s t : Set α} {x y : α} theorem wellFoundedOn_iff : s.WellFoundedOn r ↔ WellFounded fun a b : α => r a b ∧ a ∈ s ∧ b ∈ s := by have f : RelEmbedding (Subrel r (· ∈ s)) fun a b : α => r a b ∧ a ∈ s ∧ b ∈ s := ⟨⟨(↑), Subtype.coe_injective⟩, by simp⟩ refine ⟨fun h => ?_, f.wellFounded⟩ rw [WellFounded.wellFounded_iff_has_min] intro t ht by_cases hst : (s ∩ t).Nonempty · rw [← Subtype.preimage_coe_nonempty] at hst rcases h.has_min (Subtype.val ⁻¹' t) hst with ⟨⟨m, ms⟩, mt, hm⟩ exact ⟨m, mt, fun x xt ⟨xm, xs, _⟩ => hm ⟨x, xs⟩ xt xm⟩ · rcases ht with ⟨m, mt⟩ exact ⟨m, mt, fun x _ ⟨_, _, ms⟩ => hst ⟨m, ⟨ms, mt⟩⟩⟩ @[simp] theorem wellFoundedOn_univ : (univ : Set α).WellFoundedOn r ↔ WellFounded r := by simp [wellFoundedOn_iff] theorem _root_.WellFounded.wellFoundedOn : WellFounded r → s.WellFoundedOn r := InvImage.wf _ @[simp] theorem wellFoundedOn_range : (range f).WellFoundedOn r ↔ WellFounded (r on f) := by let f' : β → range f := fun c => ⟨f c, c, rfl⟩ refine ⟨fun h => (InvImage.wf f' h).mono fun c c' => id, fun h => ⟨?_⟩⟩ rintro ⟨_, c, rfl⟩ refine Acc.of_downward_closed f' ?_ _ ?_ · rintro _ ⟨_, c', rfl⟩ - exact ⟨c', rfl⟩ · exact h.apply _ @[simp] theorem wellFoundedOn_image {s : Set β} : (f '' s).WellFoundedOn r ↔ s.WellFoundedOn (r on f) := by rw [image_eq_range]; exact wellFoundedOn_range namespace WellFoundedOn protected theorem induction (hs : s.WellFoundedOn r) (hx : x ∈ s) {P : α → Prop} (hP : ∀ y ∈ s, (∀ z ∈ s, r z y → P z) → P y) : P x := by let Q : s → Prop := fun y => P y change Q ⟨x, hx⟩ refine WellFounded.induction hs ⟨x, hx⟩ ?_ simpa only [Subtype.forall] protected theorem mono (h : t.WellFoundedOn r') (hle : r ≤ r') (hst : s ⊆ t) : s.WellFoundedOn r := by rw [wellFoundedOn_iff] at * exact Subrelation.wf (fun xy => ⟨hle _ _ xy.1, hst xy.2.1, hst xy.2.2⟩) h theorem mono' (h : ∀ (a) (_ : a ∈ s) (b) (_ : b ∈ s), r' a b → r a b) : s.WellFoundedOn r → s.WellFoundedOn r' := Subrelation.wf @fun a b => h _ a.2 _ b.2 theorem subset (h : t.WellFoundedOn r) (hst : s ⊆ t) : s.WellFoundedOn r := h.mono le_rfl hst open Relation open List in /-- `a` is accessible under the relation `r` iff `r` is well-founded on the downward transitive closure of `a` under `r` (including `a` or not). -/ theorem acc_iff_wellFoundedOn {α} {r : α → α → Prop} {a : α} : TFAE [Acc r a, WellFoundedOn { b | ReflTransGen r b a } r, WellFoundedOn { b | TransGen r b a } r] := by tfae_have 1 → 2 := by refine fun h => ⟨fun b => InvImage.accessible Subtype.val ?_⟩ rw [← acc_transGen_iff] at h ⊢ obtain h' | h' := reflTransGen_iff_eq_or_transGen.1 b.2 · rwa [h'] at h · exact h.inv h' tfae_have 2 → 3 := fun h => h.subset fun _ => TransGen.to_reflTransGen tfae_have 3 → 1 := by refine fun h => Acc.intro _ (fun b hb => (h.apply ⟨b, .single hb⟩).of_fibration Subtype.val ?_) exact fun ⟨c, hc⟩ d h => ⟨⟨d, .head h hc⟩, h, rfl⟩ tfae_finish end WellFoundedOn end AnyRel section IsStrictOrder variable [IsStrictOrder α r] {s t : Set α} instance IsStrictOrder.subset : IsStrictOrder α fun a b : α => r a b ∧ a ∈ s ∧ b ∈ s where toIsIrrefl := ⟨fun a con => irrefl_of r a con.1⟩ toIsTrans := ⟨fun _ _ _ ab bc => ⟨trans_of r ab.1 bc.1, ab.2.1, bc.2.2⟩⟩ theorem wellFoundedOn_iff_no_descending_seq : s.WellFoundedOn r ↔ ∀ f : ((· > ·) : ℕ → ℕ → Prop) ↪r r, ¬∀ n, f n ∈ s := by simp only [wellFoundedOn_iff, RelEmbedding.wellFounded_iff_no_descending_seq, ← not_exists, ← not_nonempty_iff, not_iff_not] constructor · rintro ⟨⟨f, hf⟩⟩ have H : ∀ n, f n ∈ s := fun n => (hf.2 n.lt_succ_self).2.2 refine ⟨⟨f, ?_⟩, H⟩ simpa only [H, and_true] using @hf · rintro ⟨⟨f, hf⟩, hfs : ∀ n, f n ∈ s⟩ refine ⟨⟨f, ?_⟩⟩ simpa only [hfs, and_true] using @hf theorem WellFoundedOn.union (hs : s.WellFoundedOn r) (ht : t.WellFoundedOn r) : (s ∪ t).WellFoundedOn r := by rw [wellFoundedOn_iff_no_descending_seq] at * rintro f hf rcases Nat.exists_subseq_of_forall_mem_union f hf with ⟨g, hg | hg⟩ exacts [hs (g.dual.ltEmbedding.trans f) hg, ht (g.dual.ltEmbedding.trans f) hg] @[simp] theorem wellFoundedOn_union : (s ∪ t).WellFoundedOn r ↔ s.WellFoundedOn r ∧ t.WellFoundedOn r := ⟨fun h => ⟨h.subset subset_union_left, h.subset subset_union_right⟩, fun h => h.1.union h.2⟩ end IsStrictOrder end WellFoundedOn /-! ### Sets well-founded w.r.t. the strict inequality -/ section LT variable [LT α] {s t : Set α} /-- `s.IsWF` indicates that `<` is well-founded when restricted to `s`. -/ def IsWF (s : Set α) : Prop := WellFoundedOn s (· < ·) @[simp] theorem isWF_empty : IsWF (∅ : Set α) := wellFounded_of_isEmpty _ theorem IsWF.mono (h : IsWF t) (st : s ⊆ t) : IsWF s := h.subset st theorem isWF_univ_iff : IsWF (univ : Set α) ↔ WellFoundedLT α := by simp [IsWF, wellFoundedOn_iff, isWellFounded_iff] theorem IsWF.of_wellFoundedLT [h : WellFoundedLT α] (s : Set α) : s.IsWF := (Set.isWF_univ_iff.2 h).mono s.subset_univ @[deprecated IsWF.of_wellFoundedLT (since := "2025-01-16")] theorem _root_.WellFounded.isWF (h : WellFounded ((· < ·) : α → α → Prop)) (s : Set α) : s.IsWF := have : WellFoundedLT α := ⟨h⟩ .of_wellFoundedLT s end LT section Preorder variable [Preorder α] {s t : Set α} {a : α} protected nonrec theorem IsWF.union (hs : IsWF s) (ht : IsWF t) : IsWF (s ∪ t) := hs.union ht @[simp] theorem isWF_union : IsWF (s ∪ t) ↔ IsWF s ∧ IsWF t := wellFoundedOn_union end Preorder section Preorder variable [Preorder α] {s t : Set α} {a : α} theorem isWF_iff_no_descending_seq : IsWF s ↔ ∀ f : ℕ → α, StrictAnti f → ¬∀ n, f (OrderDual.toDual n) ∈ s := wellFoundedOn_iff_no_descending_seq.trans ⟨fun H f hf => H ⟨⟨f, hf.injective⟩, hf.lt_iff_lt⟩, fun H f => H f fun _ _ => f.map_rel_iff.2⟩ end Preorder /-! ### Partially well-ordered sets -/ /-- `s.PartiallyWellOrderedOn r` indicates that the relation `r` is `WellQuasiOrdered` when restricted to `s`. A set is partially well-ordered by a relation `r` when any infinite sequence contains two elements where the first is related to the second by `r`. Equivalently, any antichain (see `IsAntichain`) is finite, see `Set.partiallyWellOrderedOn_iff_finite_antichains`. TODO: rename this to `WellQuasiOrderedOn` to match `WellQuasiOrdered`. -/ def PartiallyWellOrderedOn (s : Set α) (r : α → α → Prop) : Prop := WellQuasiOrdered (Subrel r (· ∈ s)) section PartiallyWellOrderedOn variable {r : α → α → Prop} {r' : β → β → Prop} {f : α → β} {s : Set α} {t : Set α} {a : α} theorem PartiallyWellOrderedOn.exists_lt (hs : s.PartiallyWellOrderedOn r) {f : ℕ → α} (hf : ∀ n, f n ∈ s) : ∃ m n, m < n ∧ r (f m) (f n) := hs fun n ↦ ⟨_, hf n⟩ theorem partiallyWellOrderedOn_iff_exists_lt : s.PartiallyWellOrderedOn r ↔ ∀ f : ℕ → α, (∀ n, f n ∈ s) → ∃ m n, m < n ∧ r (f m) (f n) := ⟨PartiallyWellOrderedOn.exists_lt, fun hf f ↦ hf _ fun n ↦ (f n).2⟩ theorem PartiallyWellOrderedOn.mono (ht : t.PartiallyWellOrderedOn r) (h : s ⊆ t) : s.PartiallyWellOrderedOn r := fun f ↦ ht (Set.inclusion h ∘ f) @[simp] theorem partiallyWellOrderedOn_empty (r : α → α → Prop) : PartiallyWellOrderedOn ∅ r := wellQuasiOrdered_of_isEmpty _ theorem PartiallyWellOrderedOn.union (hs : s.PartiallyWellOrderedOn r) (ht : t.PartiallyWellOrderedOn r) : (s ∪ t).PartiallyWellOrderedOn r := by intro f obtain ⟨g, hgs | hgt⟩ := Nat.exists_subseq_of_forall_mem_union _ fun x ↦ (f x).2 · rcases hs.exists_lt hgs with ⟨m, n, hlt, hr⟩ exact ⟨g m, g n, g.strictMono hlt, hr⟩ · rcases ht.exists_lt hgt with ⟨m, n, hlt, hr⟩ exact ⟨g m, g n, g.strictMono hlt, hr⟩ @[simp] theorem partiallyWellOrderedOn_union : (s ∪ t).PartiallyWellOrderedOn r ↔ s.PartiallyWellOrderedOn r ∧ t.PartiallyWellOrderedOn r := ⟨fun h ↦ ⟨h.mono subset_union_left, h.mono subset_union_right⟩, fun h ↦ h.1.union h.2⟩ theorem PartiallyWellOrderedOn.image_of_monotone_on (hs : s.PartiallyWellOrderedOn r) (hf : ∀ a₁ ∈ s, ∀ a₂ ∈ s, r a₁ a₂ → r' (f a₁) (f a₂)) : (f '' s).PartiallyWellOrderedOn r' := by rw [partiallyWellOrderedOn_iff_exists_lt] at * intro g' hg' choose g hgs heq using hg' obtain rfl : f ∘ g = g' := funext heq obtain ⟨m, n, hlt, hmn⟩ := hs g hgs exact ⟨m, n, hlt, hf _ (hgs m) _ (hgs n) hmn⟩ -- TODO: prove this in terms of `IsAntichain.finite_of_wellQuasiOrdered` theorem _root_.IsAntichain.finite_of_partiallyWellOrderedOn (ha : IsAntichain r s) (hp : s.PartiallyWellOrderedOn r) : s.Finite := by refine not_infinite.1 fun hi => ?_ obtain ⟨m, n, hmn, h⟩ := hp (hi.natEmbedding _) exact hmn.ne ((hi.natEmbedding _).injective <| Subtype.val_injective <| ha.eq (hi.natEmbedding _ m).2 (hi.natEmbedding _ n).2 h) section IsRefl variable [IsRefl α r] protected theorem Finite.partiallyWellOrderedOn (hs : s.Finite) : s.PartiallyWellOrderedOn r := hs.to_subtype.wellQuasiOrdered _ theorem _root_.IsAntichain.partiallyWellOrderedOn_iff (hs : IsAntichain r s) : s.PartiallyWellOrderedOn r ↔ s.Finite := ⟨hs.finite_of_partiallyWellOrderedOn, Finite.partiallyWellOrderedOn⟩ @[simp] theorem partiallyWellOrderedOn_singleton (a : α) : PartiallyWellOrderedOn {a} r := (finite_singleton a).partiallyWellOrderedOn @[nontriviality] theorem Subsingleton.partiallyWellOrderedOn (hs : s.Subsingleton) : PartiallyWellOrderedOn s r := hs.finite.partiallyWellOrderedOn @[simp] theorem partiallyWellOrderedOn_insert : PartiallyWellOrderedOn (insert a s) r ↔ PartiallyWellOrderedOn s r := by simp only [← singleton_union, partiallyWellOrderedOn_union, partiallyWellOrderedOn_singleton, true_and] protected theorem PartiallyWellOrderedOn.insert (h : PartiallyWellOrderedOn s r) (a : α) : PartiallyWellOrderedOn (insert a s) r := partiallyWellOrderedOn_insert.2 h theorem partiallyWellOrderedOn_iff_finite_antichains [IsSymm α r] : s.PartiallyWellOrderedOn r ↔ ∀ t, t ⊆ s → IsAntichain r t → t.Finite := by refine ⟨fun h t ht hrt => hrt.finite_of_partiallyWellOrderedOn (h.mono ht), ?_⟩ rw [partiallyWellOrderedOn_iff_exists_lt] intro hs f hf by_contra! H refine infinite_range_of_injective (fun m n hmn => ?_) (hs _ (range_subset_iff.2 hf) ?_) · obtain h | h | h := lt_trichotomy m n · refine (H _ _ h ?_).elim rw [hmn] exact refl _ · exact h · refine (H _ _ h ?_).elim rw [hmn] exact refl _ rintro _ ⟨m, hm, rfl⟩ _ ⟨n, hn, rfl⟩ hmn obtain h | h := (ne_of_apply_ne _ hmn).lt_or_lt · exact H _ _ h · exact mt symm (H _ _ h) end IsRefl section IsPreorder variable [IsPreorder α r] theorem PartiallyWellOrderedOn.exists_monotone_subseq (h : s.PartiallyWellOrderedOn r) {f : ℕ → α} (hf : ∀ n, f n ∈ s) : ∃ g : ℕ ↪o ℕ, ∀ m n : ℕ, m ≤ n → r (f (g m)) (f (g n)) := WellQuasiOrdered.exists_monotone_subseq h fun n ↦ ⟨_, hf n⟩ theorem partiallyWellOrderedOn_iff_exists_monotone_subseq : s.PartiallyWellOrderedOn r ↔ ∀ f : ℕ → α, (∀ n, f n ∈ s) → ∃ g : ℕ ↪o ℕ, ∀ m n : ℕ, m ≤ n → r (f (g m)) (f (g n)) := by use PartiallyWellOrderedOn.exists_monotone_subseq rw [PartiallyWellOrderedOn, wellQuasiOrdered_iff_exists_monotone_subseq] exact fun H f ↦ H _ fun n ↦ (f n).2 protected theorem PartiallyWellOrderedOn.prod {t : Set β} (hs : PartiallyWellOrderedOn s r) (ht : PartiallyWellOrderedOn t r') : PartiallyWellOrderedOn (s ×ˢ t) fun x y : α × β => r x.1 y.1 ∧ r' x.2 y.2 := by rw [partiallyWellOrderedOn_iff_exists_lt] intro f hf obtain ⟨g₁, h₁⟩ := hs.exists_monotone_subseq fun n => (hf n).1 obtain ⟨m, n, hlt, hle⟩ := ht.exists_lt fun n => (hf _).2 exact ⟨g₁ m, g₁ n, g₁.strictMono hlt, h₁ _ _ hlt.le, hle⟩ theorem PartiallyWellOrderedOn.wellFoundedOn (h : s.PartiallyWellOrderedOn r) : s.WellFoundedOn fun a b => r a b ∧ ¬ r b a := h.wellFounded end IsPreorder end PartiallyWellOrderedOn section IsPWO variable [Preorder α] [Preorder β] {s t : Set α} /-- A subset of a preorder is partially well-ordered when any infinite sequence contains a monotone subsequence of length 2 (or equivalently, an infinite monotone subsequence). -/ def IsPWO (s : Set α) : Prop := PartiallyWellOrderedOn s (· ≤ ·) nonrec theorem IsPWO.mono (ht : t.IsPWO) : s ⊆ t → s.IsPWO := ht.mono nonrec theorem IsPWO.exists_monotone_subseq (h : s.IsPWO) {f : ℕ → α} (hf : ∀ n, f n ∈ s) : ∃ g : ℕ ↪o ℕ, Monotone (f ∘ g) := h.exists_monotone_subseq hf theorem isPWO_iff_exists_monotone_subseq : s.IsPWO ↔ ∀ f : ℕ → α, (∀ n, f n ∈ s) → ∃ g : ℕ ↪o ℕ, Monotone (f ∘ g) := partiallyWellOrderedOn_iff_exists_monotone_subseq protected theorem IsPWO.isWF (h : s.IsPWO) : s.IsWF := by simpa only [← lt_iff_le_not_le] using h.wellFoundedOn nonrec theorem IsPWO.prod {t : Set β} (hs : s.IsPWO) (ht : t.IsPWO) : IsPWO (s ×ˢ t) := hs.prod ht theorem IsPWO.image_of_monotoneOn (hs : s.IsPWO) {f : α → β} (hf : MonotoneOn f s) : IsPWO (f '' s) := hs.image_of_monotone_on hf theorem IsPWO.image_of_monotone (hs : s.IsPWO) {f : α → β} (hf : Monotone f) : IsPWO (f '' s) := hs.image_of_monotone_on (hf.monotoneOn _) protected nonrec theorem IsPWO.union (hs : IsPWO s) (ht : IsPWO t) : IsPWO (s ∪ t) := hs.union ht @[simp] theorem isPWO_union : IsPWO (s ∪ t) ↔ IsPWO s ∧ IsPWO t := partiallyWellOrderedOn_union protected theorem Finite.isPWO (hs : s.Finite) : IsPWO s := hs.partiallyWellOrderedOn @[simp] theorem isPWO_of_finite [Finite α] : s.IsPWO := s.toFinite.isPWO @[simp] theorem isPWO_singleton (a : α) : IsPWO ({a} : Set α) := (finite_singleton a).isPWO @[simp] theorem isPWO_empty : IsPWO (∅ : Set α) := finite_empty.isPWO protected theorem Subsingleton.isPWO (hs : s.Subsingleton) : IsPWO s := hs.finite.isPWO @[simp] theorem isPWO_insert {a} : IsPWO (insert a s) ↔ IsPWO s := by simp only [← singleton_union, isPWO_union, isPWO_singleton, true_and] protected theorem IsPWO.insert (h : IsPWO s) (a : α) : IsPWO (insert a s) := isPWO_insert.2 h protected theorem Finite.isWF (hs : s.Finite) : IsWF s := hs.isPWO.isWF @[simp] theorem isWF_singleton {a : α} : IsWF ({a} : Set α) := (finite_singleton a).isWF protected theorem Subsingleton.isWF (hs : s.Subsingleton) : IsWF s := hs.isPWO.isWF @[simp] theorem isWF_insert {a} : IsWF (insert a s) ↔ IsWF s := by simp only [← singleton_union, isWF_union, isWF_singleton, true_and] protected theorem IsWF.insert (h : IsWF s) (a : α) : IsWF (insert a s) := isWF_insert.2 h end IsPWO section WellFoundedOn variable {r : α → α → Prop} [IsStrictOrder α r] {s : Set α} {a : α} protected theorem Finite.wellFoundedOn (hs : s.Finite) : s.WellFoundedOn r := letI := partialOrderOfSO r hs.isWF @[simp] theorem wellFoundedOn_singleton : WellFoundedOn ({a} : Set α) r := (finite_singleton a).wellFoundedOn protected theorem Subsingleton.wellFoundedOn (hs : s.Subsingleton) : s.WellFoundedOn r := hs.finite.wellFoundedOn @[simp] theorem wellFoundedOn_insert : WellFoundedOn (insert a s) r ↔ WellFoundedOn s r := by simp only [← singleton_union, wellFoundedOn_union, wellFoundedOn_singleton, true_and] @[simp] theorem wellFoundedOn_sdiff_singleton : WellFoundedOn (s \ {a}) r ↔ WellFoundedOn s r := by simp only [← wellFoundedOn_insert (a := a), insert_diff_singleton, mem_insert_iff, true_or, insert_eq_of_mem] protected theorem WellFoundedOn.insert (h : WellFoundedOn s r) (a : α) : WellFoundedOn (insert a s) r := wellFoundedOn_insert.2 h protected theorem WellFoundedOn.sdiff_singleton (h : WellFoundedOn s r) (a : α) : WellFoundedOn (s \ {a}) r := wellFoundedOn_sdiff_singleton.2 h lemma WellFoundedOn.mapsTo {α β : Type*} {r : α → α → Prop} (f : β → α) {s : Set α} {t : Set β} (h : MapsTo f t s) (hw : s.WellFoundedOn r) : t.WellFoundedOn (r on f) := by exact InvImage.wf (fun x : t ↦ ⟨f x, h x.prop⟩) hw end WellFoundedOn section LinearOrder variable [LinearOrder α] {s : Set α} /-- In a linear order, the predicates `Set.IsPWO` and `Set.IsWF` are equivalent. -/ theorem isPWO_iff_isWF : s.IsPWO ↔ s.IsWF := by change WellQuasiOrdered (· ≤ ·) ↔ WellFounded (· < ·) rw [← wellQuasiOrderedLE_def, ← isWellFounded_iff, wellQuasiOrderedLE_iff_wellFoundedLT] alias ⟨_, IsWF.isPWO⟩ := isPWO_iff_isWF @[deprecated isPWO_iff_isWF (since := "2025-01-21")] theorem isWF_iff_isPWO : s.IsWF ↔ s.IsPWO := isPWO_iff_isWF.symm /-- If `α` is a linear order with well-founded `<`, then any set in it is a partially well-ordered set. Note this does not hold without the linearity assumption. -/ lemma IsPWO.of_linearOrder [WellFoundedLT α] (s : Set α) : s.IsPWO := (IsWF.of_wellFoundedLT s).isPWO end LinearOrder end Set namespace Finset variable {r : α → α → Prop} @[simp] protected theorem partiallyWellOrderedOn [IsRefl α r] (s : Finset α) : (s : Set α).PartiallyWellOrderedOn r := s.finite_toSet.partiallyWellOrderedOn @[simp] protected theorem isPWO [Preorder α] (s : Finset α) : Set.IsPWO (↑s : Set α) := s.partiallyWellOrderedOn @[simp]
protected theorem isWF [Preorder α] (s : Finset α) : Set.IsWF (↑s : Set α) := s.finite_toSet.isWF
Mathlib/Order/WellFoundedSet.lean
538
539
/- Copyright (c) 2020 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser, Utensil Song -/ import Mathlib.Algebra.RingQuot import Mathlib.LinearAlgebra.TensorAlgebra.Basic import Mathlib.LinearAlgebra.QuadraticForm.Isometry import Mathlib.LinearAlgebra.QuadraticForm.IsometryEquiv /-! # Clifford Algebras We construct the Clifford algebra of a module `M` over a commutative ring `R`, equipped with a quadratic form `Q`. ## Notation The Clifford algebra of the `R`-module `M` equipped with a quadratic form `Q` is an `R`-algebra denoted `CliffordAlgebra Q`. Given a linear morphism `f : M → A` from a module `M` to another `R`-algebra `A`, such that `cond : ∀ m, f m * f m = algebraMap _ _ (Q m)`, there is a (unique) lift of `f` to an `R`-algebra morphism from `CliffordAlgebra Q` to `A`, which is denoted `CliffordAlgebra.lift Q f cond`. The canonical linear map `M → CliffordAlgebra Q` is denoted `CliffordAlgebra.ι Q`. ## Theorems The main theorems proved ensure that `CliffordAlgebra Q` satisfies the universal property of the Clifford algebra. 1. `ι_comp_lift` is the fact that the composition of `ι Q` with `lift Q f cond` agrees with `f`. 2. `lift_unique` ensures the uniqueness of `lift Q f cond` with respect to 1. ## Implementation details The Clifford algebra of `M` is constructed as a quotient of the tensor algebra, as follows. 1. We define a relation `CliffordAlgebra.Rel Q` on `TensorAlgebra R M`. This is the smallest relation which identifies squares of elements of `M` with `Q m`. 2. The Clifford algebra is the quotient of the tensor algebra by this relation. This file is almost identical to `Mathlib/LinearAlgebra/ExteriorAlgebra/Basic.lean`. -/ variable {R : Type*} [CommRing R] variable {M : Type*} [AddCommGroup M] [Module R M] variable (Q : QuadraticForm R M) namespace CliffordAlgebra open TensorAlgebra /-- `Rel` relates each `ι m * ι m`, for `m : M`, with `Q m`. The Clifford algebra of `M` is defined as the quotient modulo this relation. -/ inductive Rel : TensorAlgebra R M → TensorAlgebra R M → Prop | of (m : M) : Rel (ι R m * ι R m) (algebraMap R _ (Q m)) end CliffordAlgebra /-- The Clifford algebra of an `R`-module `M` equipped with a quadratic_form `Q`. -/ def CliffordAlgebra := RingQuot (CliffordAlgebra.Rel Q) namespace CliffordAlgebra -- The `Inhabited, Semiring, Algebra` instances should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 instance instInhabited : Inhabited (CliffordAlgebra Q) := RingQuot.instInhabited _ instance instRing : Ring (CliffordAlgebra Q) := RingQuot.instRing _ instance (priority := 900) instAlgebra' {R A M} [CommSemiring R] [AddCommGroup M] [CommRing A] [Algebra R A] [Module R M] [Module A M] (Q : QuadraticForm A M) [IsScalarTower R A M] : Algebra R (CliffordAlgebra Q) := RingQuot.instAlgebra _ -- verify there are no diamonds -- but doesn't work at `reducible_and_instances` https://github.com/leanprover-community/mathlib4/issues/10906 example : (Semiring.toNatAlgebra : Algebra ℕ (CliffordAlgebra Q)) = instAlgebra' _ := rfl -- but doesn't work at `reducible_and_instances` https://github.com/leanprover-community/mathlib4/issues/10906 example : (Ring.toIntAlgebra _ : Algebra ℤ (CliffordAlgebra Q)) = instAlgebra' _ := rfl -- shortcut instance, as the other instance is slow instance instAlgebra : Algebra R (CliffordAlgebra Q) := instAlgebra' _ instance {R S A M} [CommSemiring R] [CommSemiring S] [AddCommGroup M] [CommRing A] [Algebra R A] [Algebra S A] [Module R M] [Module S M] [Module A M] (Q : QuadraticForm A M) [IsScalarTower R A M] [IsScalarTower S A M] : SMulCommClass R S (CliffordAlgebra Q) := RingQuot.instSMulCommClass _ instance {R S A M} [CommSemiring R] [CommSemiring S] [AddCommGroup M] [CommRing A] [SMul R S] [Algebra R A] [Algebra S A] [Module R M] [Module S M] [Module A M] [IsScalarTower R A M] [IsScalarTower S A M] [IsScalarTower R S A] (Q : QuadraticForm A M) : IsScalarTower R S (CliffordAlgebra Q) := RingQuot.instIsScalarTower _ /-- The canonical linear map `M →ₗ[R] CliffordAlgebra Q`. -/ def ι : M →ₗ[R] CliffordAlgebra Q := (RingQuot.mkAlgHom R _).toLinearMap.comp (TensorAlgebra.ι R) /-- As well as being linear, `ι Q` squares to the quadratic form -/ @[simp] theorem ι_sq_scalar (m : M) : ι Q m * ι Q m = algebraMap R _ (Q m) := by rw [ι] erw [LinearMap.comp_apply] rw [AlgHom.toLinearMap_apply, ← map_mul (RingQuot.mkAlgHom R (Rel Q)), RingQuot.mkAlgHom_rel R (Rel.of m), AlgHom.commutes] rfl variable {Q} {A : Type*} [Semiring A] [Algebra R A] @[simp] theorem comp_ι_sq_scalar (g : CliffordAlgebra Q →ₐ[R] A) (m : M) : g (ι Q m) * g (ι Q m) = algebraMap _ _ (Q m) := by rw [← map_mul, ι_sq_scalar, AlgHom.commutes] variable (Q) in /-- Given a linear map `f : M →ₗ[R] A` into an `R`-algebra `A`, which satisfies the condition: `cond : ∀ m : M, f m * f m = Q(m)`, this is the canonical lift of `f` to a morphism of `R`-algebras from `CliffordAlgebra Q` to `A`. -/ @[simps symm_apply] def lift : { f : M →ₗ[R] A // ∀ m, f m * f m = algebraMap _ _ (Q m) } ≃ (CliffordAlgebra Q →ₐ[R] A) where toFun f := RingQuot.liftAlgHom R ⟨TensorAlgebra.lift R (f : M →ₗ[R] A), fun x y (h : Rel Q x y) => by induction h rw [AlgHom.commutes, map_mul, TensorAlgebra.lift_ι_apply, f.prop]⟩ invFun F := ⟨F.toLinearMap.comp (ι Q), fun m => by rw [LinearMap.comp_apply, AlgHom.toLinearMap_apply, comp_ι_sq_scalar]⟩ left_inv f := by ext x exact (RingQuot.liftAlgHom_mkAlgHom_apply _ _ _ _).trans (TensorAlgebra.lift_ι_apply _ x) right_inv F := RingQuot.ringQuot_ext' _ _ _ <| TensorAlgebra.hom_ext <| LinearMap.ext fun x ↦ (RingQuot.liftAlgHom_mkAlgHom_apply _ _ _ _).trans (TensorAlgebra.lift_ι_apply _ _) @[simp] theorem ι_comp_lift (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = algebraMap _ _ (Q m)) : (lift Q ⟨f, cond⟩).toLinearMap.comp (ι Q) = f := Subtype.mk_eq_mk.mp <| (lift Q).symm_apply_apply ⟨f, cond⟩ @[simp] theorem lift_ι_apply (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = algebraMap _ _ (Q m)) (x) : lift Q ⟨f, cond⟩ (ι Q x) = f x := (LinearMap.ext_iff.mp <| ι_comp_lift f cond) x @[simp] theorem lift_unique (f : M →ₗ[R] A) (cond : ∀ m : M, f m * f m = algebraMap _ _ (Q m)) (g : CliffordAlgebra Q →ₐ[R] A) : g.toLinearMap.comp (ι Q) = f ↔ g = lift Q ⟨f, cond⟩ := by convert (lift Q : _ ≃ (CliffordAlgebra Q →ₐ[R] A)).symm_apply_eq rw [lift_symm_apply, Subtype.mk_eq_mk] @[simp] theorem lift_comp_ι (g : CliffordAlgebra Q →ₐ[R] A) : lift Q ⟨g.toLinearMap.comp (ι Q), comp_ι_sq_scalar _⟩ = g := by exact (lift Q : _ ≃ (CliffordAlgebra Q →ₐ[R] A)).apply_symm_apply g /-- See note [partially-applied ext lemmas]. -/ @[ext high] theorem hom_ext {A : Type*} [Semiring A] [Algebra R A] {f g : CliffordAlgebra Q →ₐ[R] A} : f.toLinearMap.comp (ι Q) = g.toLinearMap.comp (ι Q) → f = g := by intro h apply (lift Q).symm.injective rw [lift_symm_apply, lift_symm_apply] simp only [h] -- This proof closely follows `TensorAlgebra.induction` /-- If `C` holds for the `algebraMap` of `r : R` into `CliffordAlgebra Q`, the `ι` of `x : M`, and is preserved under addition and multiplication, then it holds for all of `CliffordAlgebra Q`. See also the stronger `CliffordAlgebra.left_induction` and `CliffordAlgebra.right_induction`. -/ @[elab_as_elim] theorem induction {C : CliffordAlgebra Q → Prop} (algebraMap : ∀ r, C (algebraMap R (CliffordAlgebra Q) r)) (ι : ∀ x, C (ι Q x)) (mul : ∀ a b, C a → C b → C (a * b)) (add : ∀ a b, C a → C b → C (a + b)) (a : CliffordAlgebra Q) : C a := by -- the arguments are enough to construct a subalgebra, and a mapping into it from M let s : Subalgebra R (CliffordAlgebra Q) := { carrier := C mul_mem' := @mul add_mem' := @add algebraMap_mem' := algebraMap } let of : { f : M →ₗ[R] s // ∀ m, f m * f m = _root_.algebraMap _ _ (Q m) } := ⟨(CliffordAlgebra.ι Q).codRestrict (Subalgebra.toSubmodule s) ι, fun m => Subtype.eq <| ι_sq_scalar Q m⟩ -- the mapping through the subalgebra is the identity have of_id : s.val.comp (lift Q of) = AlgHom.id R (CliffordAlgebra Q) := by ext x simp [of] -- porting note: `simp` should fire with the following lemma automatically have := LinearMap.codRestrict_apply s.toSubmodule (CliffordAlgebra.ι Q) x (h := ι) exact this -- finding a proof is finding an element of the subalgebra rw [← AlgHom.id_apply (R := R) a, ← of_id] exact (lift Q of a).prop theorem mul_add_swap_eq_polar_of_forall_mul_self_eq {A : Type*} [Ring A] [Algebra R A] (f : M →ₗ[R] A) (hf : ∀ x, f x * f x = algebraMap _ _ (Q x)) (a b : M) : f a * f b + f b * f a = algebraMap R _ (QuadraticMap.polar Q a b) := calc f a * f b + f b * f a = f (a + b) * f (a + b) - f a * f a - f b * f b := by rw [f.map_add, mul_add, add_mul, add_mul]; abel _ = algebraMap R _ (Q (a + b)) - algebraMap R _ (Q a) - algebraMap R _ (Q b) := by rw [hf, hf, hf] _ = algebraMap R _ (Q (a + b) - Q a - Q b) := by rw [← RingHom.map_sub, ← RingHom.map_sub] _ = algebraMap R _ (QuadraticMap.polar Q a b) := rfl /-- An alternative way to provide the argument to `CliffordAlgebra.lift` when `2` is invertible. To show a function squares to the quadratic form, it suffices to show that `f x * f y + f y * f x = algebraMap _ _ (polar Q x y)` -/ theorem forall_mul_self_eq_iff {A : Type*} [Ring A] [Algebra R A] (h2 : IsUnit (2 : A)) (f : M →ₗ[R] A) : (∀ x, f x * f x = algebraMap _ _ (Q x)) ↔ (LinearMap.mul R A).compl₂ f ∘ₗ f + (LinearMap.mul R A).flip.compl₂ f ∘ₗ f = Q.polarBilin.compr₂ (Algebra.linearMap R A) := by simp_rw [DFunLike.ext_iff] refine ⟨mul_add_swap_eq_polar_of_forall_mul_self_eq _, fun h x => ?_⟩ change ∀ x y : M, f x * f y + f y * f x = algebraMap R A (QuadraticMap.polar Q x y) at h apply h2.mul_left_cancel rw [two_mul, two_mul, h x x, QuadraticMap.polar_self, two_smul, map_add] /-- The symmetric product of vectors is a scalar -/ theorem ι_mul_ι_add_swap (a b : M) : ι Q a * ι Q b + ι Q b * ι Q a = algebraMap R _ (QuadraticMap.polar Q a b) := mul_add_swap_eq_polar_of_forall_mul_self_eq _ (ι_sq_scalar _) _ _ theorem ι_mul_ι_comm (a b : M) : ι Q a * ι Q b = algebraMap R _ (QuadraticMap.polar Q a b) - ι Q b * ι Q a := eq_sub_of_add_eq (ι_mul_ι_add_swap a b) section isOrtho @[simp] theorem ι_mul_ι_add_swap_of_isOrtho {a b : M} (h : Q.IsOrtho a b) : ι Q a * ι Q b + ι Q b * ι Q a = 0 := by rw [ι_mul_ι_add_swap, h.polar_eq_zero] simp theorem ι_mul_ι_comm_of_isOrtho {a b : M} (h : Q.IsOrtho a b) : ι Q a * ι Q b = -(ι Q b * ι Q a) := eq_neg_of_add_eq_zero_left <| ι_mul_ι_add_swap_of_isOrtho h theorem mul_ι_mul_ι_of_isOrtho (x : CliffordAlgebra Q) {a b : M} (h : Q.IsOrtho a b) : x * ι Q a * ι Q b = -(x * ι Q b * ι Q a) := by rw [mul_assoc, ι_mul_ι_comm_of_isOrtho h, mul_neg, mul_assoc] theorem ι_mul_ι_mul_of_isOrtho (x : CliffordAlgebra Q) {a b : M} (h : Q.IsOrtho a b) : ι Q a * (ι Q b * x) = -(ι Q b * (ι Q a * x)) := by rw [← mul_assoc, ι_mul_ι_comm_of_isOrtho h, neg_mul, mul_assoc] end isOrtho /-- $aba$ is a vector. -/ theorem ι_mul_ι_mul_ι (a b : M) : ι Q a * ι Q b * ι Q a = ι Q (QuadraticMap.polar Q a b • a - Q a • b) := by rw [ι_mul_ι_comm, sub_mul, mul_assoc, ι_sq_scalar, ← Algebra.smul_def, ← Algebra.commutes, ← Algebra.smul_def, ← map_smul, ← map_smul, ← map_sub] @[simp] theorem ι_range_map_lift (f : M →ₗ[R] A) (cond : ∀ m, f m * f m = algebraMap _ _ (Q m)) : (LinearMap.range (ι Q)).map (lift Q ⟨f, cond⟩).toLinearMap = LinearMap.range f := by rw [← LinearMap.range_comp, ι_comp_lift] section Map variable {M₁ M₂ M₃ : Type*} variable [AddCommGroup M₁] [AddCommGroup M₂] [AddCommGroup M₃]
variable [Module R M₁] [Module R M₂] [Module R M₃] variable {Q₁ : QuadraticForm R M₁} {Q₂ : QuadraticForm R M₂} {Q₃ : QuadraticForm R M₃}
Mathlib/LinearAlgebra/CliffordAlgebra/Basic.lean
281
283
/- 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.BigOperators.Group.Finset.Indicator import Mathlib.Algebra.Module.BigOperators import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace.Basic import Mathlib.LinearAlgebra.Finsupp.LinearCombination import Mathlib.Tactic.FinCases /-! # Affine combinations of points This file defines affine combinations of points. ## Main definitions * `weightedVSubOfPoint` is a general weighted combination of subtractions with an explicit base point, yielding a vector. * `weightedVSub` uses an arbitrary choice of base point and is intended to be used when the sum of weights is 0, in which case the result is independent of the choice of base point. * `affineCombination` adds the weighted combination to the arbitrary base point, yielding a point rather than a vector, and is intended to be used when the sum of weights is 1, in which case the result is independent of the choice of base point. These definitions are for sums over a `Finset`; versions for a `Fintype` may be obtained using `Finset.univ`, while versions for a `Finsupp` may be obtained using `Finsupp.support`. ## References * https://en.wikipedia.org/wiki/Affine_space -/ noncomputable section open Affine namespace Finset theorem univ_fin2 : (univ : Finset (Fin 2)) = {0, 1} := by ext x fin_cases x <;> simp variable {k : Type*} {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] variable [S : AffineSpace V P] variable {ι : Type*} (s : Finset ι) variable {ι₂ : Type*} (s₂ : Finset ι₂) /-- A weighted sum of the results of subtracting a base point from the given points, as a linear map on the weights. The main cases of interest are where the sum of the weights is 0, in which case the sum is independent of the choice of base point, and where the sum of the weights is 1, in which case the sum added to the base point is independent of the choice of base point. -/ def weightedVSubOfPoint (p : ι → P) (b : P) : (ι → k) →ₗ[k] V := ∑ i ∈ s, (LinearMap.proj i : (ι → k) →ₗ[k] k).smulRight (p i -ᵥ b) @[simp] theorem weightedVSubOfPoint_apply (w : ι → k) (p : ι → P) (b : P) : s.weightedVSubOfPoint p b w = ∑ i ∈ s, w i • (p i -ᵥ b) := by simp [weightedVSubOfPoint, LinearMap.sum_apply] /-- The value of `weightedVSubOfPoint`, where the given points are equal. -/ @[simp (high)] theorem weightedVSubOfPoint_apply_const (w : ι → k) (p : P) (b : P) : s.weightedVSubOfPoint (fun _ => p) b w = (∑ i ∈ s, w i) • (p -ᵥ b) := by rw [weightedVSubOfPoint_apply, sum_smul] lemma weightedVSubOfPoint_vadd (s : Finset ι) (w : ι → k) (p : ι → P) (b : P) (v : V) : s.weightedVSubOfPoint (v +ᵥ p) b w = s.weightedVSubOfPoint p (-v +ᵥ b) w := by simp [vadd_vsub_assoc, vsub_vadd_eq_vsub_sub, add_comm] lemma weightedVSubOfPoint_smul {G : Type*} [Group G] [DistribMulAction G V] [SMulCommClass G k V] (s : Finset ι) (w : ι → k) (p : ι → V) (b : V) (a : G) : s.weightedVSubOfPoint (a • p) b w = a • s.weightedVSubOfPoint p (a⁻¹ • b) w := by simp [smul_sum, smul_sub, smul_comm a (w _)] /-- `weightedVSubOfPoint` gives equal results for two families of weights and two families of points that are equal on `s`. -/ theorem weightedVSubOfPoint_congr {w₁ w₂ : ι → k} (hw : ∀ i ∈ s, w₁ i = w₂ i) {p₁ p₂ : ι → P} (hp : ∀ i ∈ s, p₁ i = p₂ i) (b : P) : s.weightedVSubOfPoint p₁ b w₁ = s.weightedVSubOfPoint p₂ b w₂ := by simp_rw [weightedVSubOfPoint_apply] refine sum_congr rfl fun i hi => ?_ rw [hw i hi, hp i hi] /-- Given a family of points, if we use a member of the family as a base point, the `weightedVSubOfPoint` does not depend on the value of the weights at this point. -/ theorem weightedVSubOfPoint_eq_of_weights_eq (p : ι → P) (j : ι) (w₁ w₂ : ι → k) (hw : ∀ i, i ≠ j → w₁ i = w₂ i) : s.weightedVSubOfPoint p (p j) w₁ = s.weightedVSubOfPoint p (p j) w₂ := by simp only [Finset.weightedVSubOfPoint_apply] congr ext i rcases eq_or_ne i j with h | h · simp [h] · simp [hw i h] /-- The weighted sum is independent of the base point when the sum of the weights is 0. -/ theorem weightedVSubOfPoint_eq_of_sum_eq_zero (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 0) (b₁ b₂ : P) : s.weightedVSubOfPoint p b₁ w = s.weightedVSubOfPoint p b₂ w := by apply eq_of_sub_eq_zero rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← sum_sub_distrib] conv_lhs => congr · skip · ext rw [← smul_sub, vsub_sub_vsub_cancel_left] rw [← sum_smul, h, zero_smul] /-- The weighted sum, added to the base point, is independent of the base point when the sum of the weights is 1. -/ theorem weightedVSubOfPoint_vadd_eq_of_sum_eq_one (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 1) (b₁ b₂ : P) : s.weightedVSubOfPoint p b₁ w +ᵥ b₁ = s.weightedVSubOfPoint p b₂ w +ᵥ b₂ := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← @vsub_eq_zero_iff_eq V, vadd_vsub_assoc, vsub_vadd_eq_vsub_sub, ← add_sub_assoc, add_comm, add_sub_assoc, ← sum_sub_distrib] conv_lhs => congr · skip · congr · skip · ext rw [← smul_sub, vsub_sub_vsub_cancel_left] rw [← sum_smul, h, one_smul, vsub_add_vsub_cancel, vsub_self] /-- The weighted sum is unaffected by removing the base point, if present, from the set of points. -/ @[simp (high)] theorem weightedVSubOfPoint_erase [DecidableEq ι] (w : ι → k) (p : ι → P) (i : ι) : (s.erase i).weightedVSubOfPoint p (p i) w = s.weightedVSubOfPoint p (p i) w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply] apply sum_erase rw [vsub_self, smul_zero] /-- The weighted sum is unaffected by adding the base point, whether or not present, to the set of points. -/ @[simp (high)] theorem weightedVSubOfPoint_insert [DecidableEq ι] (w : ι → k) (p : ι → P) (i : ι) : (insert i s).weightedVSubOfPoint p (p i) w = s.weightedVSubOfPoint p (p i) w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply] apply sum_insert_zero rw [vsub_self, smul_zero] /-- The weighted sum is unaffected by changing the weights to the corresponding indicator function and adding points to the set. -/ theorem weightedVSubOfPoint_indicator_subset (w : ι → k) (p : ι → P) (b : P) {s₁ s₂ : Finset ι} (h : s₁ ⊆ s₂) : s₁.weightedVSubOfPoint p b w = s₂.weightedVSubOfPoint p b (Set.indicator (↑s₁) w) := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply] exact Eq.symm <| sum_indicator_subset_of_eq_zero w (fun i wi => wi • (p i -ᵥ b : V)) h fun i => zero_smul k _ /-- A weighted sum, over the image of an embedding, equals a weighted sum with the same points and weights over the original `Finset`. -/ theorem weightedVSubOfPoint_map (e : ι₂ ↪ ι) (w : ι → k) (p : ι → P) (b : P) : (s₂.map e).weightedVSubOfPoint p b w = s₂.weightedVSubOfPoint (p ∘ e) b (w ∘ e) := by simp_rw [weightedVSubOfPoint_apply] exact Finset.sum_map _ _ _ /-- A weighted sum of pairwise subtractions, expressed as a subtraction of two `weightedVSubOfPoint` expressions. -/ theorem sum_smul_vsub_eq_weightedVSubOfPoint_sub (w : ι → k) (p₁ p₂ : ι → P) (b : P) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂ i)) = s.weightedVSubOfPoint p₁ b w - s.weightedVSubOfPoint p₂ b w := by simp_rw [weightedVSubOfPoint_apply, ← sum_sub_distrib, ← smul_sub, vsub_sub_vsub_cancel_right] /-- A weighted sum of pairwise subtractions, where the point on the right is constant, expressed as a subtraction involving a `weightedVSubOfPoint` expression. -/ theorem sum_smul_vsub_const_eq_weightedVSubOfPoint_sub (w : ι → k) (p₁ : ι → P) (p₂ b : P) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂)) = s.weightedVSubOfPoint p₁ b w - (∑ i ∈ s, w i) • (p₂ -ᵥ b) := by rw [sum_smul_vsub_eq_weightedVSubOfPoint_sub, weightedVSubOfPoint_apply_const] /-- A weighted sum of pairwise subtractions, where the point on the left is constant, expressed as a subtraction involving a `weightedVSubOfPoint` expression. -/ theorem sum_smul_const_vsub_eq_sub_weightedVSubOfPoint (w : ι → k) (p₂ : ι → P) (p₁ b : P) : (∑ i ∈ s, w i • (p₁ -ᵥ p₂ i)) = (∑ i ∈ s, w i) • (p₁ -ᵥ b) - s.weightedVSubOfPoint p₂ b w := by rw [sum_smul_vsub_eq_weightedVSubOfPoint_sub, weightedVSubOfPoint_apply_const] /-- A weighted sum may be split into such sums over two subsets. -/ theorem weightedVSubOfPoint_sdiff [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) (b : P) : (s \ s₂).weightedVSubOfPoint p b w + s₂.weightedVSubOfPoint p b w = s.weightedVSubOfPoint p b w := by simp_rw [weightedVSubOfPoint_apply, sum_sdiff h] /-- A weighted sum may be split into a subtraction of such sums over two subsets. -/ theorem weightedVSubOfPoint_sdiff_sub [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) (b : P) : (s \ s₂).weightedVSubOfPoint p b w - s₂.weightedVSubOfPoint p b (-w) = s.weightedVSubOfPoint p b w := by rw [map_neg, sub_neg_eq_add, s.weightedVSubOfPoint_sdiff h] /-- A weighted sum over `s.subtype pred` equals one over `{x ∈ s | pred x}`. -/ theorem weightedVSubOfPoint_subtype_eq_filter (w : ι → k) (p : ι → P) (b : P) (pred : ι → Prop) [DecidablePred pred] : ((s.subtype pred).weightedVSubOfPoint (fun i => p i) b fun i => w i) = {x ∈ s | pred x}.weightedVSubOfPoint p b w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← sum_subtype_eq_sum_filter] /-- A weighted sum over `{x ∈ s | pred x}` equals one over `s` if all the weights at indices in `s` not satisfying `pred` are zero. -/ theorem weightedVSubOfPoint_filter_of_ne (w : ι → k) (p : ι → P) (b : P) {pred : ι → Prop} [DecidablePred pred] (h : ∀ i ∈ s, w i ≠ 0 → pred i) : {x ∈ s | pred x}.weightedVSubOfPoint p b w = s.weightedVSubOfPoint p b w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, sum_filter_of_ne] intro i hi hne refine h i hi ?_ intro hw simp [hw] at hne /-- A constant multiplier of the weights in `weightedVSubOfPoint` may be moved outside the sum. -/ theorem weightedVSubOfPoint_const_smul (w : ι → k) (p : ι → P) (b : P) (c : k) : s.weightedVSubOfPoint p b (c • w) = c • s.weightedVSubOfPoint p b w := by simp_rw [weightedVSubOfPoint_apply, smul_sum, Pi.smul_apply, smul_smul, smul_eq_mul] /-- A weighted sum of the results of subtracting a default base point from the given points, as a linear map on the weights. This is intended to be used when the sum of the weights is 0; that condition is specified as a hypothesis on those lemmas that require it. -/ def weightedVSub (p : ι → P) : (ι → k) →ₗ[k] V := s.weightedVSubOfPoint p (Classical.choice S.nonempty) /-- Applying `weightedVSub` with given weights. This is for the case where a result involving a default base point is OK (for example, when that base point will cancel out later); a more typical use case for `weightedVSub` would involve selecting a preferred base point with `weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero` and then using `weightedVSubOfPoint_apply`. -/ theorem weightedVSub_apply (w : ι → k) (p : ι → P) : s.weightedVSub p w = ∑ i ∈ s, w i • (p i -ᵥ Classical.choice S.nonempty) := by simp [weightedVSub, LinearMap.sum_apply] /-- `weightedVSub` gives the sum of the results of subtracting any base point, when the sum of the weights is 0. -/ theorem weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 0) (b : P) : s.weightedVSub p w = s.weightedVSubOfPoint p b w := s.weightedVSubOfPoint_eq_of_sum_eq_zero w p h _ _ /-- The value of `weightedVSub`, where the given points are equal and the sum of the weights is 0. -/ @[simp] theorem weightedVSub_apply_const (w : ι → k) (p : P) (h : ∑ i ∈ s, w i = 0) : s.weightedVSub (fun _ => p) w = 0 := by rw [weightedVSub, weightedVSubOfPoint_apply_const, h, zero_smul] /-- The `weightedVSub` for an empty set is 0. -/ @[simp] theorem weightedVSub_empty (w : ι → k) (p : ι → P) : (∅ : Finset ι).weightedVSub p w = (0 : V) := by simp [weightedVSub_apply] lemma weightedVSub_vadd {s : Finset ι} {w : ι → k} (h : ∑ i ∈ s, w i = 0) (p : ι → P) (v : V) : s.weightedVSub (v +ᵥ p) w = s.weightedVSub p w := by rw [weightedVSub, weightedVSubOfPoint_vadd, weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero _ _ _ h] lemma weightedVSub_smul {G : Type*} [Group G] [DistribMulAction G V] [SMulCommClass G k V] {s : Finset ι} {w : ι → k} (h : ∑ i ∈ s, w i = 0) (p : ι → V) (a : G) : s.weightedVSub (a • p) w = a • s.weightedVSub p w := by rw [weightedVSub, weightedVSubOfPoint_smul, weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero _ _ _ h] /-- `weightedVSub` gives equal results for two families of weights and two families of points that are equal on `s`. -/ theorem weightedVSub_congr {w₁ w₂ : ι → k} (hw : ∀ i ∈ s, w₁ i = w₂ i) {p₁ p₂ : ι → P} (hp : ∀ i ∈ s, p₁ i = p₂ i) : s.weightedVSub p₁ w₁ = s.weightedVSub p₂ w₂ := s.weightedVSubOfPoint_congr hw hp _ /-- The weighted sum is unaffected by changing the weights to the corresponding indicator function and adding points to the set. -/ theorem weightedVSub_indicator_subset (w : ι → k) (p : ι → P) {s₁ s₂ : Finset ι} (h : s₁ ⊆ s₂) : s₁.weightedVSub p w = s₂.weightedVSub p (Set.indicator (↑s₁) w) := weightedVSubOfPoint_indicator_subset _ _ _ h /-- A weighted subtraction, over the image of an embedding, equals a weighted subtraction with the same points and weights over the original `Finset`. -/ theorem weightedVSub_map (e : ι₂ ↪ ι) (w : ι → k) (p : ι → P) : (s₂.map e).weightedVSub p w = s₂.weightedVSub (p ∘ e) (w ∘ e) := s₂.weightedVSubOfPoint_map _ _ _ _ /-- A weighted sum of pairwise subtractions, expressed as a subtraction of two `weightedVSub` expressions. -/ theorem sum_smul_vsub_eq_weightedVSub_sub (w : ι → k) (p₁ p₂ : ι → P) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂ i)) = s.weightedVSub p₁ w - s.weightedVSub p₂ w := s.sum_smul_vsub_eq_weightedVSubOfPoint_sub _ _ _ _ /-- A weighted sum of pairwise subtractions, where the point on the right is constant and the sum of the weights is 0. -/ theorem sum_smul_vsub_const_eq_weightedVSub (w : ι → k) (p₁ : ι → P) (p₂ : P) (h : ∑ i ∈ s, w i = 0) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂)) = s.weightedVSub p₁ w := by rw [sum_smul_vsub_eq_weightedVSub_sub, s.weightedVSub_apply_const _ _ h, sub_zero] /-- A weighted sum of pairwise subtractions, where the point on the left is constant and the sum of the weights is 0. -/ theorem sum_smul_const_vsub_eq_neg_weightedVSub (w : ι → k) (p₂ : ι → P) (p₁ : P) (h : ∑ i ∈ s, w i = 0) : (∑ i ∈ s, w i • (p₁ -ᵥ p₂ i)) = -s.weightedVSub p₂ w := by rw [sum_smul_vsub_eq_weightedVSub_sub, s.weightedVSub_apply_const _ _ h, zero_sub] /-- A weighted sum may be split into such sums over two subsets. -/ theorem weightedVSub_sdiff [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) : (s \ s₂).weightedVSub p w + s₂.weightedVSub p w = s.weightedVSub p w := s.weightedVSubOfPoint_sdiff h _ _ _ /-- A weighted sum may be split into a subtraction of such sums over two subsets. -/ theorem weightedVSub_sdiff_sub [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) : (s \ s₂).weightedVSub p w - s₂.weightedVSub p (-w) = s.weightedVSub p w := s.weightedVSubOfPoint_sdiff_sub h _ _ _ /-- A weighted sum over `s.subtype pred` equals one over `{x ∈ s | pred x}`. -/ theorem weightedVSub_subtype_eq_filter (w : ι → k) (p : ι → P) (pred : ι → Prop) [DecidablePred pred] : ((s.subtype pred).weightedVSub (fun i => p i) fun i => w i) = {x ∈ s | pred x}.weightedVSub p w := s.weightedVSubOfPoint_subtype_eq_filter _ _ _ _ /-- A weighted sum over `{x ∈ s | pred x}` equals one over `s` if all the weights at indices in `s` not satisfying `pred` are zero. -/ theorem weightedVSub_filter_of_ne (w : ι → k) (p : ι → P) {pred : ι → Prop} [DecidablePred pred] (h : ∀ i ∈ s, w i ≠ 0 → pred i) : {x ∈ s | pred x}.weightedVSub p w = s.weightedVSub p w := s.weightedVSubOfPoint_filter_of_ne _ _ _ h /-- A constant multiplier of the weights in `weightedVSub_of` may be moved outside the sum. -/ theorem weightedVSub_const_smul (w : ι → k) (p : ι → P) (c : k) : s.weightedVSub p (c • w) = c • s.weightedVSub p w := s.weightedVSubOfPoint_const_smul _ _ _ _ instance : AffineSpace (ι → k) (ι → k) := Pi.instAddTorsor variable (k) /-- A weighted sum of the results of subtracting a default base point from the given points, added to that base point, as an affine map on the weights. This is intended to be used when the sum of the weights is 1, in which case it is an affine combination (barycenter) of the points with the given weights; that condition is specified as a hypothesis on those lemmas that require it. -/ def affineCombination (p : ι → P) : (ι → k) →ᵃ[k] P where toFun w := s.weightedVSubOfPoint p (Classical.choice S.nonempty) w +ᵥ Classical.choice S.nonempty linear := s.weightedVSub p map_vadd' w₁ w₂ := by simp_rw [vadd_vadd, weightedVSub, vadd_eq_add, LinearMap.map_add] /-- The linear map corresponding to `affineCombination` is `weightedVSub`. -/ @[simp] theorem affineCombination_linear (p : ι → P) : (s.affineCombination k p).linear = s.weightedVSub p := rfl variable {k} /-- Applying `affineCombination` with given weights. This is for the case where a result involving a default base point is OK (for example, when that base point will cancel out later); a more typical use case for `affineCombination` would involve selecting a preferred base point with `affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one` and then using `weightedVSubOfPoint_apply`. -/ theorem affineCombination_apply (w : ι → k) (p : ι → P) : (s.affineCombination k p) w = s.weightedVSubOfPoint p (Classical.choice S.nonempty) w +ᵥ Classical.choice S.nonempty := rfl /-- The value of `affineCombination`, where the given points are equal. -/ @[simp] theorem affineCombination_apply_const (w : ι → k) (p : P) (h : ∑ i ∈ s, w i = 1) : s.affineCombination k (fun _ => p) w = p := by rw [affineCombination_apply, s.weightedVSubOfPoint_apply_const, h, one_smul, vsub_vadd] /-- `affineCombination` gives equal results for two families of weights and two families of points that are equal on `s`. -/ theorem affineCombination_congr {w₁ w₂ : ι → k} (hw : ∀ i ∈ s, w₁ i = w₂ i) {p₁ p₂ : ι → P} (hp : ∀ i ∈ s, p₁ i = p₂ i) : s.affineCombination k p₁ w₁ = s.affineCombination k p₂ w₂ := by simp_rw [affineCombination_apply, s.weightedVSubOfPoint_congr hw hp] /-- `affineCombination` gives the sum with any base point, when the sum of the weights is 1. -/ theorem affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 1) (b : P) : s.affineCombination k p w = s.weightedVSubOfPoint p b w +ᵥ b := s.weightedVSubOfPoint_vadd_eq_of_sum_eq_one w p h _ _ /-- Adding a `weightedVSub` to an `affineCombination`. -/ theorem weightedVSub_vadd_affineCombination (w₁ w₂ : ι → k) (p : ι → P) : s.weightedVSub p w₁ +ᵥ s.affineCombination k p w₂ = s.affineCombination k p (w₁ + w₂) := by rw [← vadd_eq_add, AffineMap.map_vadd, affineCombination_linear] /-- Subtracting two `affineCombination`s. -/ theorem affineCombination_vsub (w₁ w₂ : ι → k) (p : ι → P) : s.affineCombination k p w₁ -ᵥ s.affineCombination k p w₂ = s.weightedVSub p (w₁ - w₂) := by rw [← AffineMap.linearMap_vsub, affineCombination_linear, vsub_eq_sub] theorem attach_affineCombination_of_injective [DecidableEq P] (s : Finset P) (w : P → k) (f : s → P) (hf : Function.Injective f) : s.attach.affineCombination k f (w ∘ f) = (image f univ).affineCombination k id w := by simp only [affineCombination, weightedVSubOfPoint_apply, id, vadd_right_cancel_iff, Function.comp_apply, AffineMap.coe_mk] let g₁ : s → V := fun i => w (f i) • (f i -ᵥ Classical.choice S.nonempty) let g₂ : P → V := fun i => w i • (i -ᵥ Classical.choice S.nonempty) change univ.sum g₁ = (image f univ).sum g₂ have hgf : g₁ = g₂ ∘ f := by ext simp [g₁, g₂] rw [hgf, sum_image] · simp only [g₁, g₂,Function.comp_apply] · exact fun _ _ _ _ hxy => hf hxy theorem attach_affineCombination_coe (s : Finset P) (w : P → k) : s.attach.affineCombination k ((↑) : s → P) (w ∘ (↑)) = s.affineCombination k id w := by classical rw [attach_affineCombination_of_injective s w ((↑) : s → P) Subtype.coe_injective, univ_eq_attach, attach_image_val] /-- Viewing a module as an affine space modelled on itself, a `weightedVSub` is just a linear combination. -/ @[simp] theorem weightedVSub_eq_linear_combination {ι} (s : Finset ι) {w : ι → k} {p : ι → V} (hw : s.sum w = 0) : s.weightedVSub p w = ∑ i ∈ s, w i • p i := by simp [s.weightedVSub_apply, vsub_eq_sub, smul_sub, ← Finset.sum_smul, hw] /-- Viewing a module as an affine space modelled on itself, affine combinations are just linear combinations. -/ @[simp] theorem affineCombination_eq_linear_combination (s : Finset ι) (p : ι → V) (w : ι → k) (hw : ∑ i ∈ s, w i = 1) : s.affineCombination k p w = ∑ i ∈ s, w i • p i := by simp [s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w p hw 0] /-- An `affineCombination` equals a point if that point is in the set and has weight 1 and the other points in the set have weight 0. -/ @[simp] theorem affineCombination_of_eq_one_of_eq_zero (w : ι → k) (p : ι → P) {i : ι} (his : i ∈ s) (hwi : w i = 1) (hw0 : ∀ i2 ∈ s, i2 ≠ i → w i2 = 0) : s.affineCombination k p w = p i := by have h1 : ∑ i ∈ s, w i = 1 := hwi ▸ sum_eq_single i hw0 fun h => False.elim (h his) rw [s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w p h1 (p i), weightedVSubOfPoint_apply] convert zero_vadd V (p i) refine sum_eq_zero ?_ intro i2 hi2 by_cases h : i2 = i · simp [h] · simp [hw0 i2 hi2 h] /-- An affine combination is unaffected by changing the weights to the corresponding indicator function and adding points to the set. -/ theorem affineCombination_indicator_subset (w : ι → k) (p : ι → P) {s₁ s₂ : Finset ι} (h : s₁ ⊆ s₂) : s₁.affineCombination k p w = s₂.affineCombination k p (Set.indicator (↑s₁) w) := by rw [affineCombination_apply, affineCombination_apply, weightedVSubOfPoint_indicator_subset _ _ _ h] /-- An affine combination, over the image of an embedding, equals an affine combination with the same points and weights over the original `Finset`. -/ theorem affineCombination_map (e : ι₂ ↪ ι) (w : ι → k) (p : ι → P) : (s₂.map e).affineCombination k p w = s₂.affineCombination k (p ∘ e) (w ∘ e) := by simp_rw [affineCombination_apply, weightedVSubOfPoint_map] /-- A weighted sum of pairwise subtractions, expressed as a subtraction of two `affineCombination` expressions. -/ theorem sum_smul_vsub_eq_affineCombination_vsub (w : ι → k) (p₁ p₂ : ι → P) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂ i)) = s.affineCombination k p₁ w -ᵥ s.affineCombination k p₂ w := by simp_rw [affineCombination_apply, vadd_vsub_vadd_cancel_right] exact s.sum_smul_vsub_eq_weightedVSubOfPoint_sub _ _ _ _ /-- A weighted sum of pairwise subtractions, where the point on the right is constant and the sum of the weights is 1. -/ theorem sum_smul_vsub_const_eq_affineCombination_vsub (w : ι → k) (p₁ : ι → P) (p₂ : P) (h : ∑ i ∈ s, w i = 1) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂)) = s.affineCombination k p₁ w -ᵥ p₂ := by rw [sum_smul_vsub_eq_affineCombination_vsub, affineCombination_apply_const _ _ _ h] /-- A weighted sum of pairwise subtractions, where the point on the left is constant and the sum of the weights is 1. -/ theorem sum_smul_const_vsub_eq_vsub_affineCombination (w : ι → k) (p₂ : ι → P) (p₁ : P) (h : ∑ i ∈ s, w i = 1) : (∑ i ∈ s, w i • (p₁ -ᵥ p₂ i)) = p₁ -ᵥ s.affineCombination k p₂ w := by rw [sum_smul_vsub_eq_affineCombination_vsub, affineCombination_apply_const _ _ _ h] /-- A weighted sum may be split into a subtraction of affine combinations over two subsets. -/ theorem affineCombination_sdiff_sub [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) : (s \ s₂).affineCombination k p w -ᵥ s₂.affineCombination k p (-w) = s.weightedVSub p w := by simp_rw [affineCombination_apply, vadd_vsub_vadd_cancel_right] exact s.weightedVSub_sdiff_sub h _ _ /-- If a weighted sum is zero and one of the weights is `-1`, the corresponding point is the affine combination of the other points with the given weights. -/ theorem affineCombination_eq_of_weightedVSub_eq_zero_of_eq_neg_one {w : ι → k} {p : ι → P} (hw : s.weightedVSub p w = (0 : V)) {i : ι} [DecidablePred (· ≠ i)] (his : i ∈ s) (hwi : w i = -1) : {x ∈ s | x ≠ i}.affineCombination k p w = p i := by classical rw [← @vsub_eq_zero_iff_eq V, ← hw, ← s.affineCombination_sdiff_sub (singleton_subset_iff.2 his), sdiff_singleton_eq_erase, ← filter_ne'] congr refine (affineCombination_of_eq_one_of_eq_zero _ _ _ (mem_singleton_self _) ?_ ?_).symm · simp [hwi] · simp /-- An affine combination over `s.subtype pred` equals one over `{x ∈ s | pred x}`. -/ theorem affineCombination_subtype_eq_filter (w : ι → k) (p : ι → P) (pred : ι → Prop) [DecidablePred pred] : ((s.subtype pred).affineCombination k (fun i => p i) fun i => w i) = {x ∈ s | pred x}.affineCombination k p w := by rw [affineCombination_apply, affineCombination_apply, weightedVSubOfPoint_subtype_eq_filter] /-- An affine combination over `{x ∈ s | pred x}` equals one over `s` if all the weights at indices in `s` not satisfying `pred` are zero. -/ theorem affineCombination_filter_of_ne (w : ι → k) (p : ι → P) {pred : ι → Prop} [DecidablePred pred] (h : ∀ i ∈ s, w i ≠ 0 → pred i) : {x ∈ s | pred x}.affineCombination k p w = s.affineCombination k p w := by rw [affineCombination_apply, affineCombination_apply, s.weightedVSubOfPoint_filter_of_ne _ _ _ h] /-- Suppose an indexed family of points is given, along with a subset of the index type. A vector can be expressed as `weightedVSubOfPoint` using a `Finset` lying within that subset and with a given sum of weights if and only if it can be expressed as `weightedVSubOfPoint` with that sum of weights for the corresponding indexed family whose index type is the subtype corresponding to that subset. -/ theorem eq_weightedVSubOfPoint_subset_iff_eq_weightedVSubOfPoint_subtype {v : V} {x : k} {s : Set ι} {p : ι → P} {b : P} : (∃ fs : Finset ι, ↑fs ⊆ s ∧ ∃ w : ι → k, ∑ i ∈ fs, w i = x ∧ v = fs.weightedVSubOfPoint p b w) ↔ ∃ (fs : Finset s) (w : s → k), ∑ i ∈ fs, w i = x ∧ v = fs.weightedVSubOfPoint (fun i : s => p i) b w := by classical simp_rw [weightedVSubOfPoint_apply] constructor · rintro ⟨fs, hfs, w, rfl, rfl⟩ exact ⟨fs.subtype s, fun i => w i, sum_subtype_of_mem _ hfs, (sum_subtype_of_mem _ hfs).symm⟩ · rintro ⟨fs, w, rfl, rfl⟩ refine ⟨fs.map (Function.Embedding.subtype _), map_subtype_subset _, fun i => if h : i ∈ s then w ⟨i, h⟩ else 0, ?_, ?_⟩ <;> simp variable (k) /-- Suppose an indexed family of points is given, along with a subset of the index type. A vector can be expressed as `weightedVSub` using a `Finset` lying within that subset and with sum of weights 0 if and only if it can be expressed as `weightedVSub` with sum of weights 0 for the corresponding indexed family whose index type is the subtype corresponding to that subset. -/ theorem eq_weightedVSub_subset_iff_eq_weightedVSub_subtype {v : V} {s : Set ι} {p : ι → P} : (∃ fs : Finset ι, ↑fs ⊆ s ∧ ∃ w : ι → k, ∑ i ∈ fs, w i = 0 ∧ v = fs.weightedVSub p w) ↔ ∃ (fs : Finset s) (w : s → k), ∑ i ∈ fs, w i = 0 ∧ v = fs.weightedVSub (fun i : s => p i) w := eq_weightedVSubOfPoint_subset_iff_eq_weightedVSubOfPoint_subtype variable (V) /-- Suppose an indexed family of points is given, along with a subset of the index type. A point can be expressed as an `affineCombination` using a `Finset` lying within that subset and with sum of weights 1 if and only if it can be expressed an `affineCombination` with sum of weights 1 for the corresponding indexed family whose index type is the subtype corresponding to that subset. -/ theorem eq_affineCombination_subset_iff_eq_affineCombination_subtype {p0 : P} {s : Set ι} {p : ι → P} : (∃ fs : Finset ι, ↑fs ⊆ s ∧ ∃ w : ι → k, ∑ i ∈ fs, w i = 1 ∧ p0 = fs.affineCombination k p w) ↔ ∃ (fs : Finset s) (w : s → k), ∑ i ∈ fs, w i = 1 ∧ p0 = fs.affineCombination k (fun i : s => p i) w := by simp_rw [affineCombination_apply, eq_vadd_iff_vsub_eq] exact eq_weightedVSubOfPoint_subset_iff_eq_weightedVSubOfPoint_subtype variable {k V} /-- Affine maps commute with affine combinations. -/ theorem map_affineCombination {V₂ P₂ : Type*} [AddCommGroup V₂] [Module k V₂] [AffineSpace V₂ P₂] (p : ι → P) (w : ι → k) (hw : s.sum w = 1) (f : P →ᵃ[k] P₂) : f (s.affineCombination k p w) = s.affineCombination k (f ∘ p) w := by have b := Classical.choice (inferInstance : AffineSpace V P).nonempty have b₂ := Classical.choice (inferInstance : AffineSpace V₂ P₂).nonempty rw [s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w p hw b, s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w (f ∘ p) hw b₂, ← s.weightedVSubOfPoint_vadd_eq_of_sum_eq_one w (f ∘ p) hw (f b) b₂] simp only [weightedVSubOfPoint_apply, RingHom.id_apply, AffineMap.map_vadd, LinearMap.map_smulₛₗ, AffineMap.linearMap_vsub, map_sum, Function.comp_apply] /-- The value of `affineCombination`, where the given points take only two values. -/ lemma affineCombination_apply_eq_lineMap_sum [DecidableEq ι] (w : ι → k) (p : ι → P) (p₁ p₂ : P) (s' : Finset ι) (h : ∑ i ∈ s, w i = 1) (hp₂ : ∀ i ∈ s ∩ s', p i = p₂) (hp₁ : ∀ i ∈ s \ s', p i = p₁) : s.affineCombination k p w = AffineMap.lineMap p₁ p₂ (∑ i ∈ s ∩ s', w i) := by rw [s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w p h p₁, weightedVSubOfPoint_apply, ← s.sum_inter_add_sum_diff s', AffineMap.lineMap_apply, vadd_right_cancel_iff, sum_smul] convert add_zero _ with i hi · convert Finset.sum_const_zero with i hi simp [hp₁ i hi] · exact (hp₂ i hi).symm variable (k) /-- Weights for expressing a single point as an affine combination. -/ def affineCombinationSingleWeights [DecidableEq ι] (i : ι) : ι → k := Pi.single i 1 @[simp] theorem affineCombinationSingleWeights_apply_self [DecidableEq ι] (i : ι) : affineCombinationSingleWeights k i i = 1 := Pi.single_eq_same _ _ @[simp] theorem affineCombinationSingleWeights_apply_of_ne [DecidableEq ι] {i j : ι} (h : j ≠ i) : affineCombinationSingleWeights k i j = 0 := Pi.single_eq_of_ne h _ @[simp] theorem sum_affineCombinationSingleWeights [DecidableEq ι] {i : ι} (h : i ∈ s) : ∑ j ∈ s, affineCombinationSingleWeights k i j = 1 := by rw [← affineCombinationSingleWeights_apply_self k i] exact sum_eq_single_of_mem i h fun j _ hj => affineCombinationSingleWeights_apply_of_ne k hj /-- Weights for expressing the subtraction of two points as a `weightedVSub`. -/ def weightedVSubVSubWeights [DecidableEq ι] (i j : ι) : ι → k := affineCombinationSingleWeights k i - affineCombinationSingleWeights k j @[simp] theorem weightedVSubVSubWeights_self [DecidableEq ι] (i : ι) : weightedVSubVSubWeights k i i = 0 := by simp [weightedVSubVSubWeights] @[simp] theorem weightedVSubVSubWeights_apply_left [DecidableEq ι] {i j : ι} (h : i ≠ j) : weightedVSubVSubWeights k i j i = 1 := by simp [weightedVSubVSubWeights, h] @[simp] theorem weightedVSubVSubWeights_apply_right [DecidableEq ι] {i j : ι} (h : i ≠ j) : weightedVSubVSubWeights k i j j = -1 := by simp [weightedVSubVSubWeights, h.symm] @[simp] theorem weightedVSubVSubWeights_apply_of_ne [DecidableEq ι] {i j t : ι} (hi : t ≠ i) (hj : t ≠ j) : weightedVSubVSubWeights k i j t = 0 := by simp [weightedVSubVSubWeights, hi, hj] @[simp] theorem sum_weightedVSubVSubWeights [DecidableEq ι] {i j : ι} (hi : i ∈ s) (hj : j ∈ s) : ∑ t ∈ s, weightedVSubVSubWeights k i j t = 0 := by simp_rw [weightedVSubVSubWeights, Pi.sub_apply, sum_sub_distrib] simp [hi, hj] variable {k} /-- Weights for expressing `lineMap` as an affine combination. -/ def affineCombinationLineMapWeights [DecidableEq ι] (i j : ι) (c : k) : ι → k := c • weightedVSubVSubWeights k j i + affineCombinationSingleWeights k i @[simp] theorem affineCombinationLineMapWeights_self [DecidableEq ι] (i : ι) (c : k) : affineCombinationLineMapWeights i i c = affineCombinationSingleWeights k i := by simp [affineCombinationLineMapWeights] @[simp] theorem affineCombinationLineMapWeights_apply_left [DecidableEq ι] {i j : ι} (h : i ≠ j) (c : k) : affineCombinationLineMapWeights i j c i = 1 - c := by simp [affineCombinationLineMapWeights, h.symm, sub_eq_neg_add] @[simp] theorem affineCombinationLineMapWeights_apply_right [DecidableEq ι] {i j : ι} (h : i ≠ j) (c : k) : affineCombinationLineMapWeights i j c j = c := by simp [affineCombinationLineMapWeights, h.symm] @[simp] theorem affineCombinationLineMapWeights_apply_of_ne [DecidableEq ι] {i j t : ι} (hi : t ≠ i) (hj : t ≠ j) (c : k) : affineCombinationLineMapWeights i j c t = 0 := by simp [affineCombinationLineMapWeights, hi, hj] @[simp] theorem sum_affineCombinationLineMapWeights [DecidableEq ι] {i j : ι} (hi : i ∈ s) (hj : j ∈ s) (c : k) : ∑ t ∈ s, affineCombinationLineMapWeights i j c t = 1 := by simp_rw [affineCombinationLineMapWeights, Pi.add_apply, sum_add_distrib] simp [hi, hj, ← mul_sum] variable (k) /-- An affine combination with `affineCombinationSingleWeights` gives the specified point. -/ @[simp] theorem affineCombination_affineCombinationSingleWeights [DecidableEq ι] (p : ι → P) {i : ι} (hi : i ∈ s) : s.affineCombination k p (affineCombinationSingleWeights k i) = p i := by refine s.affineCombination_of_eq_one_of_eq_zero _ _ hi (by simp) ?_ rintro j - hj simp [hj] /-- A weighted subtraction with `weightedVSubVSubWeights` gives the result of subtracting the specified points. -/ @[simp] theorem weightedVSub_weightedVSubVSubWeights [DecidableEq ι] (p : ι → P) {i j : ι} (hi : i ∈ s) (hj : j ∈ s) : s.weightedVSub p (weightedVSubVSubWeights k i j) = p i -ᵥ p j := by rw [weightedVSubVSubWeights, ← affineCombination_vsub, s.affineCombination_affineCombinationSingleWeights k p hi, s.affineCombination_affineCombinationSingleWeights k p hj] variable {k} /-- An affine combination with `affineCombinationLineMapWeights` gives the result of `line_map`. -/ @[simp] theorem affineCombination_affineCombinationLineMapWeights [DecidableEq ι] (p : ι → P) {i j : ι} (hi : i ∈ s) (hj : j ∈ s) (c : k) : s.affineCombination k p (affineCombinationLineMapWeights i j c) = AffineMap.lineMap (p i) (p j) c := by rw [affineCombinationLineMapWeights, ← weightedVSub_vadd_affineCombination, weightedVSub_const_smul, s.affineCombination_affineCombinationSingleWeights k p hi, s.weightedVSub_weightedVSubVSubWeights k p hj hi, AffineMap.lineMap_apply] end Finset namespace Finset variable (k : Type*) {V : Type*} {P : Type*} [DivisionRing k] [AddCommGroup V] [Module k V] variable [AffineSpace V P] {ι : Type*} (s : Finset ι) {ι₂ : Type*} (s₂ : Finset ι₂) /-- The weights for the centroid of some points. -/ def centroidWeights : ι → k := Function.const ι (#s : k)⁻¹ /-- `centroidWeights` at any point. -/ @[simp] theorem centroidWeights_apply (i : ι) : s.centroidWeights k i = (#s : k)⁻¹ := rfl /-- `centroidWeights` equals a constant function. -/ theorem centroidWeights_eq_const : s.centroidWeights k = Function.const ι (#s : k)⁻¹ := rfl
variable {k} in /-- The weights in the centroid sum to 1, if the number of points, converted to `k`, is not zero. -/ theorem sum_centroidWeights_eq_one_of_cast_card_ne_zero (h : (#s : k) ≠ 0) : ∑ i ∈ s, s.centroidWeights k i = 1 := by simp [h]
Mathlib/LinearAlgebra/AffineSpace/Combination.lean
738
742
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Mario Carneiro -/ import Mathlib.Data.Bool.Basic import Mathlib.Data.FunLike.Equiv import Mathlib.Data.Quot import Mathlib.Data.Subtype import Mathlib.Logic.Unique import Mathlib.Tactic.Conv import Mathlib.Tactic.Simps.Basic import Mathlib.Tactic.Substs /-! # Equivalence between types In this file we define two types: * `Equiv α β` a.k.a. `α ≃ β`: a bijective map `α → β` bundled with its inverse map; we use this (and not equality!) to express that various `Type`s or `Sort`s are equivalent. * `Equiv.Perm α`: the group of permutations `α ≃ α`. More lemmas about `Equiv.Perm` can be found in `Mathlib.GroupTheory.Perm`. Then we define * canonical isomorphisms between various types: e.g., - `Equiv.refl α` is the identity map interpreted as `α ≃ α`; * operations on equivalences: e.g., - `Equiv.symm e : β ≃ α` is the inverse of `e : α ≃ β`; - `Equiv.trans e₁ e₂ : α ≃ γ` is the composition of `e₁ : α ≃ β` and `e₂ : β ≃ γ` (note the order of the arguments!); * definitions that transfer some instances along an equivalence. By convention, we transfer instances from right to left. - `Equiv.inhabited` takes `e : α ≃ β` and `[Inhabited β]` and returns `Inhabited α`; - `Equiv.unique` takes `e : α ≃ β` and `[Unique β]` and returns `Unique α`; - `Equiv.decidableEq` takes `e : α ≃ β` and `[DecidableEq β]` and returns `DecidableEq α`. More definitions of this kind can be found in other files. E.g., `Mathlib.Algebra.Equiv.TransferInstance` does it for many algebraic type classes like `Group`, `Module`, etc. Many more such isomorphisms and operations are defined in `Mathlib.Logic.Equiv.Basic`. ## Tags equivalence, congruence, bijective map -/ open Function universe u v w z variable {α : Sort u} {β : Sort v} {γ : Sort w} /-- `α ≃ β` is the type of functions from `α → β` with a two-sided inverse. -/ structure Equiv (α : Sort*) (β : Sort _) where protected toFun : α → β protected invFun : β → α protected left_inv : LeftInverse invFun toFun protected right_inv : RightInverse invFun toFun @[inherit_doc] infixl:25 " ≃ " => Equiv /-- Turn an element of a type `F` satisfying `EquivLike F α β` into an actual `Equiv`. This is declared as the default coercion from `F` to `α ≃ β`. -/ @[coe] def EquivLike.toEquiv {F} [EquivLike F α β] (f : F) : α ≃ β where toFun := f invFun := EquivLike.inv f left_inv := EquivLike.left_inv f right_inv := EquivLike.right_inv f /-- Any type satisfying `EquivLike` can be cast into `Equiv` via `EquivLike.toEquiv`. -/ instance {F} [EquivLike F α β] : CoeTC F (α ≃ β) := ⟨EquivLike.toEquiv⟩ /-- `Perm α` is the type of bijections from `α` to itself. -/ abbrev Equiv.Perm (α : Sort*) := Equiv α α namespace Equiv instance : EquivLike (α ≃ β) α β where coe := Equiv.toFun inv := Equiv.invFun left_inv := Equiv.left_inv right_inv := Equiv.right_inv coe_injective' e₁ e₂ h₁ h₂ := by cases e₁; cases e₂; congr /-- Helper instance when inference gets stuck on following the normal chain `EquivLike → FunLike`. TODO: this instance doesn't appear to be necessary: remove it (after benchmarking?) -/ instance : FunLike (α ≃ β) α β where coe := Equiv.toFun coe_injective' := DFunLike.coe_injective @[simp, norm_cast] lemma _root_.EquivLike.coe_coe {F} [EquivLike F α β] (e : F) : ((e : α ≃ β) : α → β) = e := rfl @[simp] theorem coe_fn_mk (f : α → β) (g l r) : (Equiv.mk f g l r : α → β) = f := rfl /-- The map `(r ≃ s) → (r → s)` is injective. -/ theorem coe_fn_injective : @Function.Injective (α ≃ β) (α → β) (fun e => e) := DFunLike.coe_injective' protected theorem coe_inj {e₁ e₂ : α ≃ β} : (e₁ : α → β) = e₂ ↔ e₁ = e₂ := @DFunLike.coe_fn_eq _ _ _ _ e₁ e₂ @[ext] theorem ext {f g : Equiv α β} (H : ∀ x, f x = g x) : f = g := DFunLike.ext f g H protected theorem congr_arg {f : Equiv α β} {x x' : α} : x = x' → f x = f x' := DFunLike.congr_arg f protected theorem congr_fun {f g : Equiv α β} (h : f = g) (x : α) : f x = g x := DFunLike.congr_fun h x @[ext] theorem Perm.ext {σ τ : Equiv.Perm α} (H : ∀ x, σ x = τ x) : σ = τ := Equiv.ext H protected theorem Perm.congr_arg {f : Equiv.Perm α} {x x' : α} : x = x' → f x = f x' := Equiv.congr_arg protected theorem Perm.congr_fun {f g : Equiv.Perm α} (h : f = g) (x : α) : f x = g x := Equiv.congr_fun h x /-- Any type is equivalent to itself. -/ @[refl] protected def refl (α : Sort*) : α ≃ α := ⟨id, id, fun _ => rfl, fun _ => rfl⟩ instance inhabited' : Inhabited (α ≃ α) := ⟨Equiv.refl α⟩ /-- Inverse of an equivalence `e : α ≃ β`. -/ @[symm] protected def symm (e : α ≃ β) : β ≃ α := ⟨e.invFun, e.toFun, e.right_inv, e.left_inv⟩ /-- See Note [custom simps projection] -/ def Simps.symm_apply (e : α ≃ β) : β → α := e.symm initialize_simps_projections Equiv (toFun → apply, invFun → symm_apply) /-- Restatement of `Equiv.left_inv` in terms of `Function.LeftInverse`. -/ theorem left_inv' (e : α ≃ β) : Function.LeftInverse e.symm e := e.left_inv /-- Restatement of `Equiv.right_inv` in terms of `Function.RightInverse`. -/ theorem right_inv' (e : α ≃ β) : Function.RightInverse e.symm e := e.right_inv /-- Composition of equivalences `e₁ : α ≃ β` and `e₂ : β ≃ γ`. -/ @[trans] protected def trans (e₁ : α ≃ β) (e₂ : β ≃ γ) : α ≃ γ := ⟨e₂ ∘ e₁, e₁.symm ∘ e₂.symm, e₂.left_inv.comp e₁.left_inv, e₂.right_inv.comp e₁.right_inv⟩ @[simps] instance : Trans Equiv Equiv Equiv where trans := Equiv.trans @[simp, mfld_simps] theorem toFun_as_coe (e : α ≃ β) : e.toFun = e := rfl @[simp, mfld_simps] theorem invFun_as_coe (e : α ≃ β) : e.invFun = e.symm := rfl protected theorem injective (e : α ≃ β) : Injective e := EquivLike.injective e protected theorem surjective (e : α ≃ β) : Surjective e := EquivLike.surjective e protected theorem bijective (e : α ≃ β) : Bijective e := EquivLike.bijective e protected theorem subsingleton (e : α ≃ β) [Subsingleton β] : Subsingleton α := e.injective.subsingleton protected theorem subsingleton.symm (e : α ≃ β) [Subsingleton α] : Subsingleton β := e.symm.injective.subsingleton theorem subsingleton_congr (e : α ≃ β) : Subsingleton α ↔ Subsingleton β := ⟨fun _ => e.symm.subsingleton, fun _ => e.subsingleton⟩ instance equiv_subsingleton_cod [Subsingleton β] : Subsingleton (α ≃ β) := ⟨fun _ _ => Equiv.ext fun _ => Subsingleton.elim _ _⟩ instance equiv_subsingleton_dom [Subsingleton α] : Subsingleton (α ≃ β) := ⟨fun f _ => Equiv.ext fun _ => @Subsingleton.elim _ (Equiv.subsingleton.symm f) _ _⟩ instance permUnique [Subsingleton α] : Unique (Perm α) := uniqueOfSubsingleton (Equiv.refl α) theorem Perm.subsingleton_eq_refl [Subsingleton α] (e : Perm α) : e = Equiv.refl α := Subsingleton.elim _ _ protected theorem nontrivial {α β} (e : α ≃ β) [Nontrivial β] : Nontrivial α := e.surjective.nontrivial theorem nontrivial_congr {α β} (e : α ≃ β) : Nontrivial α ↔ Nontrivial β := ⟨fun _ ↦ e.symm.nontrivial, fun _ ↦ e.nontrivial⟩ /-- Transfer `DecidableEq` across an equivalence. -/ protected def decidableEq (e : α ≃ β) [DecidableEq β] : DecidableEq α := e.injective.decidableEq theorem nonempty_congr (e : α ≃ β) : Nonempty α ↔ Nonempty β := Nonempty.congr e e.symm protected theorem nonempty (e : α ≃ β) [Nonempty β] : Nonempty α := e.nonempty_congr.mpr ‹_› /-- If `α ≃ β` and `β` is inhabited, then so is `α`. -/ protected def inhabited [Inhabited β] (e : α ≃ β) : Inhabited α := ⟨e.symm default⟩ /-- If `α ≃ β` and `β` is a singleton type, then so is `α`. -/ protected def unique [Unique β] (e : α ≃ β) : Unique α := e.symm.surjective.unique /-- Equivalence between equal types. -/ protected def cast {α β : Sort _} (h : α = β) : α ≃ β := ⟨cast h, cast h.symm, fun _ => by cases h; rfl, fun _ => by cases h; rfl⟩ @[simp] theorem coe_fn_symm_mk (f : α → β) (g l r) : ((Equiv.mk f g l r).symm : β → α) = g := rfl @[simp] theorem coe_refl : (Equiv.refl α : α → α) = id := rfl /-- This cannot be a `simp` lemmas as it incorrectly matches against `e : α ≃ synonym α`, when `synonym α` is semireducible. This makes a mess of `Multiplicative.ofAdd` etc. -/ theorem Perm.coe_subsingleton {α : Type*} [Subsingleton α] (e : Perm α) : (e : α → α) = id := by rw [Perm.subsingleton_eq_refl e, coe_refl] @[simp] theorem refl_apply (x : α) : Equiv.refl α x = x := rfl @[simp] theorem coe_trans (f : α ≃ β) (g : β ≃ γ) : (f.trans g : α → γ) = g ∘ f := rfl @[simp] theorem trans_apply (f : α ≃ β) (g : β ≃ γ) (a : α) : (f.trans g) a = g (f a) := rfl @[simp] theorem apply_symm_apply (e : α ≃ β) (x : β) : e (e.symm x) = x := e.right_inv x @[simp] theorem symm_apply_apply (e : α ≃ β) (x : α) : e.symm (e x) = x := e.left_inv x @[simp] theorem symm_comp_self (e : α ≃ β) : e.symm ∘ e = id := funext e.symm_apply_apply @[simp] theorem self_comp_symm (e : α ≃ β) : e ∘ e.symm = id := funext e.apply_symm_apply @[simp] lemma _root_.EquivLike.apply_coe_symm_apply {F} [EquivLike F α β] (e : F) (x : β) : e ((e : α ≃ β).symm x) = x := (e : α ≃ β).apply_symm_apply x @[simp] lemma _root_.EquivLike.coe_symm_apply_apply {F} [EquivLike F α β] (e : F) (x : α) : (e : α ≃ β).symm (e x) = x := (e : α ≃ β).symm_apply_apply x @[simp] lemma _root_.EquivLike.coe_symm_comp_self {F} [EquivLike F α β] (e : F) : (e : α ≃ β).symm ∘ e = id := (e : α ≃ β).symm_comp_self @[simp] lemma _root_.EquivLike.self_comp_coe_symm {F} [EquivLike F α β] (e : F) : e ∘ (e : α ≃ β).symm = id := (e : α ≃ β).self_comp_symm @[simp] theorem symm_trans_apply (f : α ≃ β) (g : β ≃ γ) (a : γ) : (f.trans g).symm a = f.symm (g.symm a) := rfl theorem symm_symm_apply (f : α ≃ β) (b : α) : f.symm.symm b = f b := rfl theorem apply_eq_iff_eq (f : α ≃ β) {x y : α} : f x = f y ↔ x = y := EquivLike.apply_eq_iff_eq f theorem apply_eq_iff_eq_symm_apply {x : α} {y : β} (f : α ≃ β) : f x = y ↔ x = f.symm y := by conv_lhs => rw [← apply_symm_apply f y] rw [apply_eq_iff_eq] @[simp] theorem cast_apply {α β} (h : α = β) (x : α) : Equiv.cast h x = cast h x := rfl @[simp] theorem cast_symm {α β} (h : α = β) : (Equiv.cast h).symm = Equiv.cast h.symm := rfl @[simp] theorem cast_refl {α} (h : α = α := rfl) : Equiv.cast h = Equiv.refl α := rfl @[simp] theorem cast_trans {α β γ} (h : α = β) (h2 : β = γ) : (Equiv.cast h).trans (Equiv.cast h2) = Equiv.cast (h.trans h2) := ext fun x => by substs h h2; rfl theorem cast_eq_iff_heq {α β} (h : α = β) {a : α} {b : β} : Equiv.cast h a = b ↔ HEq a b := by subst h; simp [coe_refl] theorem symm_apply_eq {α β} (e : α ≃ β) {x y} : e.symm x = y ↔ x = e y := ⟨fun H => by simp [H.symm], fun H => by simp [H]⟩ theorem eq_symm_apply {α β} (e : α ≃ β) {x y} : y = e.symm x ↔ e y = x := (eq_comm.trans e.symm_apply_eq).trans eq_comm @[simp] theorem symm_symm (e : α ≃ β) : e.symm.symm = e := rfl theorem symm_bijective : Function.Bijective (Equiv.symm : (α ≃ β) → β ≃ α) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ @[simp] theorem trans_refl (e : α ≃ β) : e.trans (Equiv.refl β) = e := by cases e; rfl @[simp] theorem refl_symm : (Equiv.refl α).symm = Equiv.refl α := rfl @[simp] theorem refl_trans (e : α ≃ β) : (Equiv.refl α).trans e = e := by cases e; rfl @[simp] theorem symm_trans_self (e : α ≃ β) : e.symm.trans e = Equiv.refl β := ext <| by simp @[simp] theorem self_trans_symm (e : α ≃ β) : e.trans e.symm = Equiv.refl α := ext <| by simp theorem trans_assoc {δ} (ab : α ≃ β) (bc : β ≃ γ) (cd : γ ≃ δ) : (ab.trans bc).trans cd = ab.trans (bc.trans cd) := Equiv.ext fun _ => rfl theorem leftInverse_symm (f : Equiv α β) : LeftInverse f.symm f := f.left_inv theorem rightInverse_symm (f : Equiv α β) : Function.RightInverse f.symm f := f.right_inv theorem injective_comp (e : α ≃ β) (f : β → γ) : Injective (f ∘ e) ↔ Injective f := EquivLike.injective_comp e f theorem comp_injective (f : α → β) (e : β ≃ γ) : Injective (e ∘ f) ↔ Injective f := EquivLike.comp_injective f e theorem surjective_comp (e : α ≃ β) (f : β → γ) : Surjective (f ∘ e) ↔ Surjective f := EquivLike.surjective_comp e f theorem comp_surjective (f : α → β) (e : β ≃ γ) : Surjective (e ∘ f) ↔ Surjective f := EquivLike.comp_surjective f e theorem bijective_comp (e : α ≃ β) (f : β → γ) : Bijective (f ∘ e) ↔ Bijective f := EquivLike.bijective_comp e f theorem comp_bijective (f : α → β) (e : β ≃ γ) : Bijective (e ∘ f) ↔ Bijective f := EquivLike.comp_bijective f e /-- If `α` is equivalent to `β` and `γ` is equivalent to `δ`, then the type of equivalences `α ≃ γ` is equivalent to the type of equivalences `β ≃ δ`. -/ def equivCongr {δ : Sort*} (ab : α ≃ β) (cd : γ ≃ δ) : (α ≃ γ) ≃ (β ≃ δ) where toFun ac := (ab.symm.trans ac).trans cd invFun bd := ab.trans <| bd.trans <| cd.symm left_inv ac := by ext x; simp only [trans_apply, comp_apply, symm_apply_apply] right_inv ac := by ext x; simp only [trans_apply, comp_apply, apply_symm_apply] @[simp] theorem equivCongr_refl {α β} : (Equiv.refl α).equivCongr (Equiv.refl β) = Equiv.refl (α ≃ β) := by ext; rfl @[simp] theorem equivCongr_symm {δ} (ab : α ≃ β) (cd : γ ≃ δ) : (ab.equivCongr cd).symm = ab.symm.equivCongr cd.symm := by ext; rfl @[simp] theorem equivCongr_trans {δ ε ζ} (ab : α ≃ β) (de : δ ≃ ε) (bc : β ≃ γ) (ef : ε ≃ ζ) : (ab.equivCongr de).trans (bc.equivCongr ef) = (ab.trans bc).equivCongr (de.trans ef) := by ext; rfl @[simp] theorem equivCongr_refl_left {α β γ} (bg : β ≃ γ) (e : α ≃ β) : (Equiv.refl α).equivCongr bg e = e.trans bg := rfl @[simp] theorem equivCongr_refl_right {α β} (ab e : α ≃ β) : ab.equivCongr (Equiv.refl β) e = ab.symm.trans e := rfl @[simp] theorem equivCongr_apply_apply {δ} (ab : α ≃ β) (cd : γ ≃ δ) (e : α ≃ γ) (x) : ab.equivCongr cd e x = cd (e (ab.symm x)) := rfl section permCongr variable {α' β' : Type*} (e : α' ≃ β') /-- If `α` is equivalent to `β`, then `Perm α` is equivalent to `Perm β`. -/ def permCongr : Perm α' ≃ Perm β' := equivCongr e e theorem permCongr_def (p : Equiv.Perm α') : e.permCongr p = (e.symm.trans p).trans e := rfl @[simp] theorem permCongr_refl : e.permCongr (Equiv.refl _) = Equiv.refl _ := by simp [permCongr_def] @[simp] theorem permCongr_symm : e.permCongr.symm = e.symm.permCongr := rfl @[simp] theorem permCongr_apply (p : Equiv.Perm α') (x) : e.permCongr p x = e (p (e.symm x)) := rfl theorem permCongr_symm_apply (p : Equiv.Perm β') (x) : e.permCongr.symm p x = e.symm (p (e x)) := rfl theorem permCongr_trans (p p' : Equiv.Perm α') : (e.permCongr p).trans (e.permCongr p') = e.permCongr (p.trans p') := by ext; simp only [trans_apply, comp_apply, permCongr_apply, symm_apply_apply] end permCongr /-- Two empty types are equivalent. -/ def equivOfIsEmpty (α β : Sort*) [IsEmpty α] [IsEmpty β] : α ≃ β := ⟨isEmptyElim, isEmptyElim, isEmptyElim, isEmptyElim⟩ /-- If `α` is an empty type, then it is equivalent to the `Empty` type. -/ def equivEmpty (α : Sort u) [IsEmpty α] : α ≃ Empty := equivOfIsEmpty α _ /-- If `α` is an empty type, then it is equivalent to the `PEmpty` type in any universe. -/ def equivPEmpty (α : Sort v) [IsEmpty α] : α ≃ PEmpty.{u} := equivOfIsEmpty α _ /-- `α` is equivalent to an empty type iff `α` is empty. -/ def equivEmptyEquiv (α : Sort u) : α ≃ Empty ≃ IsEmpty α := ⟨fun e => Function.isEmpty e, @equivEmpty α, fun e => ext fun x => (e x).elim, fun _ => rfl⟩ /-- The `Sort` of proofs of a false proposition is equivalent to `PEmpty`. -/ def propEquivPEmpty {p : Prop} (h : ¬p) : p ≃ PEmpty := @equivPEmpty p <| IsEmpty.prop_iff.2 h /-- If both `α` and `β` have a unique element, then `α ≃ β`. -/ def ofUnique (α β : Sort _) [Unique.{u} α] [Unique.{v} β] : α ≃ β where toFun := default invFun := default left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ @[deprecated (since := "2024-12-26")] alias equivOfUnique := ofUnique /-- If `α` has a unique element, then it is equivalent to any `PUnit`. -/ def equivPUnit (α : Sort u) [Unique α] : α ≃ PUnit.{v} := ofUnique α _ /-- The `Sort` of proofs of a true proposition is equivalent to `PUnit`. -/ def propEquivPUnit {p : Prop} (h : p) : p ≃ PUnit.{0} := @equivPUnit p <| uniqueProp h /-- `ULift α` is equivalent to `α`. -/ @[simps -fullyApplied apply] protected def ulift {α : Type v} : ULift.{u} α ≃ α := ⟨ULift.down, ULift.up, ULift.up_down, ULift.down_up.{v, u}⟩ /-- `PLift α` is equivalent to `α`. -/ @[simps -fullyApplied apply] protected def plift : PLift α ≃ α := ⟨PLift.down, PLift.up, PLift.up_down, PLift.down_up⟩ /-- equivalence of propositions is the same as iff -/ def ofIff {P Q : Prop} (h : P ↔ Q) : P ≃ Q := ⟨h.mp, h.mpr, fun _ => rfl, fun _ => rfl⟩ /-- If `α₁` is equivalent to `α₂` and `β₁` is equivalent to `β₂`, then the type of maps `α₁ → β₁` is equivalent to the type of maps `α₂ → β₂`. -/ @[simps apply] def arrowCongr {α₁ β₁ α₂ β₂ : Sort*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) : (α₁ → β₁) ≃ (α₂ → β₂) where toFun f := e₂ ∘ f ∘ e₁.symm invFun f := e₂.symm ∘ f ∘ e₁ left_inv f := funext fun x => by simp only [comp_apply, symm_apply_apply] right_inv f := funext fun x => by simp only [comp_apply, apply_symm_apply] theorem arrowCongr_comp {α₁ β₁ γ₁ α₂ β₂ γ₂ : Sort*} (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) (ec : γ₁ ≃ γ₂) (f : α₁ → β₁) (g : β₁ → γ₁) : arrowCongr ea ec (g ∘ f) = arrowCongr eb ec g ∘ arrowCongr ea eb f := by ext; simp only [comp, arrowCongr_apply, eb.symm_apply_apply] @[simp] theorem arrowCongr_refl {α β : Sort*} : arrowCongr (Equiv.refl α) (Equiv.refl β) = Equiv.refl (α → β) := rfl @[simp] theorem arrowCongr_trans {α₁ α₂ α₃ β₁ β₂ β₃ : Sort*} (e₁ : α₁ ≃ α₂) (e₁' : β₁ ≃ β₂) (e₂ : α₂ ≃ α₃) (e₂' : β₂ ≃ β₃) : arrowCongr (e₁.trans e₂) (e₁'.trans e₂') = (arrowCongr e₁ e₁').trans (arrowCongr e₂ e₂') := rfl @[simp] theorem arrowCongr_symm {α₁ α₂ β₁ β₂ : Sort*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) : (arrowCongr e₁ e₂).symm = arrowCongr e₁.symm e₂.symm := rfl /-- A version of `Equiv.arrowCongr` in `Type`, rather than `Sort`. The `equiv_rw` tactic is not able to use the default `Sort` level `Equiv.arrowCongr`, because Lean's universe rules will not unify `?l_1` with `imax (1 ?m_1)`. -/ @[simps! apply] def arrowCongr' {α₁ β₁ α₂ β₂ : Type*} (hα : α₁ ≃ α₂) (hβ : β₁ ≃ β₂) : (α₁ → β₁) ≃ (α₂ → β₂) := Equiv.arrowCongr hα hβ @[simp] theorem arrowCongr'_refl {α β : Type*} : arrowCongr' (Equiv.refl α) (Equiv.refl β) = Equiv.refl (α → β) := rfl @[simp] theorem arrowCongr'_trans {α₁ α₂ β₁ β₂ α₃ β₃ : Type*} (e₁ : α₁ ≃ α₂) (e₁' : β₁ ≃ β₂) (e₂ : α₂ ≃ α₃) (e₂' : β₂ ≃ β₃) : arrowCongr' (e₁.trans e₂) (e₁'.trans e₂') = (arrowCongr' e₁ e₁').trans (arrowCongr' e₂ e₂') := rfl @[simp] theorem arrowCongr'_symm {α₁ α₂ β₁ β₂ : Type*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) : (arrowCongr' e₁ e₂).symm = arrowCongr' e₁.symm e₂.symm := rfl /-- Conjugate a map `f : α → α` by an equivalence `α ≃ β`. -/ @[simps! apply] def conj (e : α ≃ β) : (α → α) ≃ (β → β) := arrowCongr e e @[simp] theorem conj_refl : conj (Equiv.refl α) = Equiv.refl (α → α) := rfl @[simp] theorem conj_symm (e : α ≃ β) : e.conj.symm = e.symm.conj := rfl @[simp] theorem conj_trans (e₁ : α ≃ β) (e₂ : β ≃ γ) : (e₁.trans e₂).conj = e₁.conj.trans e₂.conj := rfl -- This should not be a simp lemma as long as `(∘)` is reducible: -- when `(∘)` is reducible, Lean can unify `f₁ ∘ f₂` with any `g` using -- `f₁ := g` and `f₂ := fun x ↦ x`. This causes nontermination. theorem conj_comp (e : α ≃ β) (f₁ f₂ : α → α) : e.conj (f₁ ∘ f₂) = e.conj f₁ ∘ e.conj f₂ := by apply arrowCongr_comp theorem eq_comp_symm {α β γ} (e : α ≃ β) (f : β → γ) (g : α → γ) : f = g ∘ e.symm ↔ f ∘ e = g := (e.arrowCongr (Equiv.refl γ)).symm_apply_eq.symm theorem comp_symm_eq {α β γ} (e : α ≃ β) (f : β → γ) (g : α → γ) : g ∘ e.symm = f ↔ g = f ∘ e := (e.arrowCongr (Equiv.refl γ)).eq_symm_apply.symm theorem eq_symm_comp {α β γ} (e : α ≃ β) (f : γ → α) (g : γ → β) : f = e.symm ∘ g ↔ e ∘ f = g := ((Equiv.refl γ).arrowCongr e).eq_symm_apply theorem symm_comp_eq {α β γ} (e : α ≃ β) (f : γ → α) (g : γ → β) : e.symm ∘ g = f ↔ g = e ∘ f := ((Equiv.refl γ).arrowCongr e).symm_apply_eq theorem trans_eq_refl_iff_eq_symm {f : α ≃ β} {g : β ≃ α} : f.trans g = Equiv.refl α ↔ f = g.symm := by rw [← Equiv.coe_inj, coe_trans, coe_refl, ← eq_symm_comp, comp_id, Equiv.coe_inj] theorem trans_eq_refl_iff_symm_eq {f : α ≃ β} {g : β ≃ α} : f.trans g = Equiv.refl α ↔ f.symm = g := by rw [trans_eq_refl_iff_eq_symm] exact ⟨fun h ↦ h ▸ rfl, fun h ↦ h ▸ rfl⟩ theorem eq_symm_iff_trans_eq_refl {f : α ≃ β} {g : β ≃ α} : f = g.symm ↔ f.trans g = Equiv.refl α := trans_eq_refl_iff_eq_symm.symm theorem symm_eq_iff_trans_eq_refl {f : α ≃ β} {g : β ≃ α} : f.symm = g ↔ f.trans g = Equiv.refl α := trans_eq_refl_iff_symm_eq.symm /-- `PUnit` sorts in any two universes are equivalent. -/ def punitEquivPUnit : PUnit.{v} ≃ PUnit.{w} := ⟨fun _ => .unit, fun _ => .unit, fun ⟨⟩ => rfl, fun ⟨⟩ => rfl⟩ /-- `Prop` is noncomputably equivalent to `Bool`. -/ noncomputable def propEquivBool : Prop ≃ Bool where toFun p := @decide p (Classical.propDecidable _) invFun b := b left_inv p := by simp [@Bool.decide_iff p (Classical.propDecidable _)] right_inv b := by cases b <;> simp section /-- The sort of maps to `PUnit.{v}` is equivalent to `PUnit.{w}`. -/ def arrowPUnitEquivPUnit (α : Sort*) : (α → PUnit.{v}) ≃ PUnit.{w} := ⟨fun _ => .unit, fun _ _ => .unit, fun _ => rfl, fun _ => rfl⟩ /-- The equivalence `(∀ i, β i) ≃ β ⋆` when the domain of `β` only contains `⋆` -/ @[simps -fullyApplied] def piUnique [Unique α] (β : α → Sort*) : (∀ i, β i) ≃ β default where toFun f := f default invFun := uniqueElim left_inv f := by ext i; cases Unique.eq_default i; rfl right_inv _ := rfl /-- If `α` has a unique term, then the type of function `α → β` is equivalent to `β`. -/ @[simps! -fullyApplied apply symm_apply] def funUnique (α β) [Unique.{u} α] : (α → β) ≃ β := piUnique _ /-- The sort of maps from `PUnit` is equivalent to the codomain. -/ def punitArrowEquiv (α : Sort*) : (PUnit.{u} → α) ≃ α := funUnique PUnit.{u} α /-- The sort of maps from `True` is equivalent to the codomain. -/ def trueArrowEquiv (α : Sort*) : (True → α) ≃ α := funUnique _ _ /-- The sort of maps from a type that `IsEmpty` is equivalent to `PUnit`. -/ def arrowPUnitOfIsEmpty (α β : Sort*) [IsEmpty α] : (α → β) ≃ PUnit.{u} where toFun _ := PUnit.unit invFun _ := isEmptyElim left_inv _ := funext isEmptyElim right_inv _ := rfl /-- The sort of maps from `Empty` is equivalent to `PUnit`. -/ def emptyArrowEquivPUnit (α : Sort*) : (Empty → α) ≃ PUnit.{u} := arrowPUnitOfIsEmpty _ _ /-- The sort of maps from `PEmpty` is equivalent to `PUnit`. -/ def pemptyArrowEquivPUnit (α : Sort*) : (PEmpty → α) ≃ PUnit.{u} := arrowPUnitOfIsEmpty _ _ /-- The sort of maps from `False` is equivalent to `PUnit`. -/ def falseArrowEquivPUnit (α : Sort*) : (False → α) ≃ PUnit.{u} := arrowPUnitOfIsEmpty _ _ end section /-- A `PSigma`-type is equivalent to the corresponding `Sigma`-type. -/ @[simps apply symm_apply] def psigmaEquivSigma {α} (β : α → Type*) : (Σ' i, β i) ≃ Σ i, β i where toFun a := ⟨a.1, a.2⟩ invFun a := ⟨a.1, a.2⟩ left_inv _ := rfl right_inv _ := rfl /-- A `PSigma`-type is equivalent to the corresponding `Sigma`-type. -/ @[simps apply symm_apply] def psigmaEquivSigmaPLift {α} (β : α → Sort*) : (Σ' i, β i) ≃ Σ i : PLift α, PLift (β i.down) where toFun a := ⟨PLift.up a.1, PLift.up a.2⟩ invFun a := ⟨a.1.down, a.2.down⟩ left_inv _ := rfl right_inv _ := rfl /-- A family of equivalences `Π a, β₁ a ≃ β₂ a` generates an equivalence between `Σ' a, β₁ a` and `Σ' a, β₂ a`. -/ @[simps apply] def psigmaCongrRight {β₁ β₂ : α → Sort*} (F : ∀ a, β₁ a ≃ β₂ a) : (Σ' a, β₁ a) ≃ Σ' a, β₂ a where toFun a := ⟨a.1, F a.1 a.2⟩ invFun a := ⟨a.1, (F a.1).symm a.2⟩ left_inv | ⟨a, b⟩ => congr_arg (PSigma.mk a) <| symm_apply_apply (F a) b right_inv | ⟨a, b⟩ => congr_arg (PSigma.mk a) <| apply_symm_apply (F a) b theorem psigmaCongrRight_trans {α} {β₁ β₂ β₃ : α → Sort*} (F : ∀ a, β₁ a ≃ β₂ a) (G : ∀ a, β₂ a ≃ β₃ a) : (psigmaCongrRight F).trans (psigmaCongrRight G) = psigmaCongrRight fun a => (F a).trans (G a) := rfl theorem psigmaCongrRight_symm {α} {β₁ β₂ : α → Sort*} (F : ∀ a, β₁ a ≃ β₂ a) : (psigmaCongrRight F).symm = psigmaCongrRight fun a => (F a).symm := rfl @[simp] theorem psigmaCongrRight_refl {α} {β : α → Sort*} : (psigmaCongrRight fun a => Equiv.refl (β a)) = Equiv.refl (Σ' a, β a) := rfl /-- A family of equivalences `Π a, β₁ a ≃ β₂ a` generates an equivalence between `Σ a, β₁ a` and `Σ a, β₂ a`. -/ @[simps apply] def sigmaCongrRight {α} {β₁ β₂ : α → Type*} (F : ∀ a, β₁ a ≃ β₂ a) : (Σ a, β₁ a) ≃ Σ a, β₂ a where toFun a := ⟨a.1, F a.1 a.2⟩ invFun a := ⟨a.1, (F a.1).symm a.2⟩ left_inv | ⟨a, b⟩ => congr_arg (Sigma.mk a) <| symm_apply_apply (F a) b right_inv | ⟨a, b⟩ => congr_arg (Sigma.mk a) <| apply_symm_apply (F a) b theorem sigmaCongrRight_trans {α} {β₁ β₂ β₃ : α → Type*} (F : ∀ a, β₁ a ≃ β₂ a) (G : ∀ a, β₂ a ≃ β₃ a) : (sigmaCongrRight F).trans (sigmaCongrRight G) = sigmaCongrRight fun a => (F a).trans (G a) := rfl theorem sigmaCongrRight_symm {α} {β₁ β₂ : α → Type*} (F : ∀ a, β₁ a ≃ β₂ a) : (sigmaCongrRight F).symm = sigmaCongrRight fun a => (F a).symm := rfl @[simp] theorem sigmaCongrRight_refl {α} {β : α → Type*} : (sigmaCongrRight fun a => Equiv.refl (β a)) = Equiv.refl (Σ a, β a) := rfl /-- A `PSigma` with `Prop` fibers is equivalent to the subtype. -/ def psigmaEquivSubtype {α : Type v} (P : α → Prop) : (Σ' i, P i) ≃ Subtype P where toFun x := ⟨x.1, x.2⟩ invFun x := ⟨x.1, x.2⟩ left_inv _ := rfl right_inv _ := rfl /-- A `Sigma` with `PLift` fibers is equivalent to the subtype. -/ def sigmaPLiftEquivSubtype {α : Type v} (P : α → Prop) : (Σ i, PLift (P i)) ≃ Subtype P := ((psigmaEquivSigma _).symm.trans (psigmaCongrRight fun _ => Equiv.plift)).trans (psigmaEquivSubtype P) /-- A `Sigma` with `fun i ↦ ULift (PLift (P i))` fibers is equivalent to `{ x // P x }`. Variant of `sigmaPLiftEquivSubtype`. -/ def sigmaULiftPLiftEquivSubtype {α : Type v} (P : α → Prop) : (Σ i, ULift (PLift (P i))) ≃ Subtype P := (sigmaCongrRight fun _ => Equiv.ulift).trans (sigmaPLiftEquivSubtype P) namespace Perm /-- A family of permutations `Π a, Perm (β a)` generates a permutation `Perm (Σ a, β₁ a)`. -/ abbrev sigmaCongrRight {α} {β : α → Sort _} (F : ∀ a, Perm (β a)) : Perm (Σ a, β a) := Equiv.sigmaCongrRight F @[simp] theorem sigmaCongrRight_trans {α} {β : α → Sort _} (F : ∀ a, Perm (β a)) (G : ∀ a, Perm (β a)) : (sigmaCongrRight F).trans (sigmaCongrRight G) = sigmaCongrRight fun a => (F a).trans (G a) := Equiv.sigmaCongrRight_trans F G @[simp] theorem sigmaCongrRight_symm {α} {β : α → Sort _} (F : ∀ a, Perm (β a)) : (sigmaCongrRight F).symm = sigmaCongrRight fun a => (F a).symm := Equiv.sigmaCongrRight_symm F @[simp] theorem sigmaCongrRight_refl {α} {β : α → Sort _} : (sigmaCongrRight fun a => Equiv.refl (β a)) = Equiv.refl (Σ a, β a) := Equiv.sigmaCongrRight_refl end Perm /-- An equivalence `f : α₁ ≃ α₂` generates an equivalence between `Σ a, β (f a)` and `Σ a, β a`. -/ @[simps apply] def sigmaCongrLeft {α₁ α₂ : Type*} {β : α₂ → Sort _} (e : α₁ ≃ α₂) : (Σ a : α₁, β (e a)) ≃ Σ a : α₂, β a where toFun a := ⟨e a.1, a.2⟩ invFun a := ⟨e.symm a.1, (e.right_inv' a.1).symm ▸ a.2⟩ left_inv := fun ⟨a, b⟩ => by simp right_inv := fun ⟨a, b⟩ => by simp /-- Transporting a sigma type through an equivalence of the base -/ def sigmaCongrLeft' {α₁ α₂} {β : α₁ → Sort _} (f : α₁ ≃ α₂) : (Σ a : α₁, β a) ≃ Σ a : α₂, β (f.symm a) := (sigmaCongrLeft f.symm).symm /-- Transporting a sigma type through an equivalence of the base and a family of equivalences of matching fibers -/ def sigmaCongr {α₁ α₂} {β₁ : α₁ → Sort _} {β₂ : α₂ → Sort _} (f : α₁ ≃ α₂) (F : ∀ a, β₁ a ≃ β₂ (f a)) : Sigma β₁ ≃ Sigma β₂ := (sigmaCongrRight F).trans (sigmaCongrLeft f) /-- `Sigma` type with a constant fiber is equivalent to the product. -/ @[simps (config := { attrs := [`mfld_simps] }) apply symm_apply] def sigmaEquivProd (α β : Type*) : (Σ _ : α, β) ≃ α × β := ⟨fun a => ⟨a.1, a.2⟩, fun a => ⟨a.1, a.2⟩, fun ⟨_, _⟩ => rfl, fun ⟨_, _⟩ => rfl⟩ /-- If each fiber of a `Sigma` type is equivalent to a fixed type, then the sigma type is equivalent to the product. -/ def sigmaEquivProdOfEquiv {α β} {β₁ : α → Sort _} (F : ∀ a, β₁ a ≃ β) : Sigma β₁ ≃ α × β := (sigmaCongrRight F).trans (sigmaEquivProd α β) /-- The dependent product of types is associative up to an equivalence. -/ def sigmaAssoc {α : Type*} {β : α → Type*} (γ : ∀ a : α, β a → Type*) : (Σ ab : Σ a : α, β a, γ ab.1 ab.2) ≃ Σ a : α, Σ b : β a, γ a b where toFun x := ⟨x.1.1, ⟨x.1.2, x.2⟩⟩ invFun x := ⟨⟨x.1, x.2.1⟩, x.2.2⟩ left_inv _ := rfl right_inv _ := rfl /-- The dependent product of sorts is associative up to an equivalence. -/ def pSigmaAssoc {α : Sort*} {β : α → Sort*} (γ : ∀ a : α, β a → Sort*) : (Σ' ab : Σ' a : α, β a, γ ab.1 ab.2) ≃ Σ' a : α, Σ' b : β a, γ a b where toFun x := ⟨x.1.1, ⟨x.1.2, x.2⟩⟩ invFun x := ⟨⟨x.1, x.2.1⟩, x.2.2⟩ left_inv _ := rfl right_inv _ := rfl end variable {p : α → Prop} {q : β → Prop} (e : α ≃ β) protected lemma forall_congr_right : (∀ a, q (e a)) ↔ ∀ b, q b := ⟨fun h a ↦ by simpa using h (e.symm a), fun h _ ↦ h _⟩ protected lemma forall_congr_left : (∀ a, p a) ↔ ∀ b, p (e.symm b) := e.symm.forall_congr_right.symm protected lemma forall_congr (h : ∀ a, p a ↔ q (e a)) : (∀ a, p a) ↔ ∀ b, q b := e.forall_congr_left.trans (by simp [h]) protected lemma forall_congr' (h : ∀ b, p (e.symm b) ↔ q b) : (∀ a, p a) ↔ ∀ b, q b := e.forall_congr_left.trans (by simp [h]) protected lemma exists_congr_right : (∃ a, q (e a)) ↔ ∃ b, q b := ⟨fun ⟨_, h⟩ ↦ ⟨_, h⟩, fun ⟨a, h⟩ ↦ ⟨e.symm a, by simpa using h⟩⟩ protected lemma exists_congr_left : (∃ a, p a) ↔ ∃ b, p (e.symm b) := e.symm.exists_congr_right.symm protected lemma exists_congr (h : ∀ a, p a ↔ q (e a)) : (∃ a, p a) ↔ ∃ b, q b := e.exists_congr_left.trans <| by simp [h] protected lemma exists_congr' (h : ∀ b, p (e.symm b) ↔ q b) : (∃ a, p a) ↔ ∃ b, q b := e.exists_congr_left.trans <| by simp [h] protected lemma existsUnique_congr_right : (∃! a, q (e a)) ↔ ∃! b, q b := e.exists_congr <| by simpa using fun _ _ ↦ e.forall_congr (by simp) protected lemma existsUnique_congr_left : (∃! a, p a) ↔ ∃! b, p (e.symm b) := e.symm.existsUnique_congr_right.symm protected lemma existsUnique_congr (h : ∀ a, p a ↔ q (e a)) : (∃! a, p a) ↔ ∃! b, q b := e.existsUnique_congr_left.trans <| by simp [h] protected lemma existsUnique_congr' (h : ∀ b, p (e.symm b) ↔ q b) : (∃! a, p a) ↔ ∃! b, q b := e.existsUnique_congr_left.trans <| by simp [h] -- We next build some higher arity versions of `Equiv.forall_congr`. -- Although they appear to just be repeated applications of `Equiv.forall_congr`, -- unification of metavariables works better with these versions. -- In particular, they are necessary in `equiv_rw`. -- (Stopping at ternary functions seems reasonable: at least in 1-categorical mathematics, -- it's rare to have axioms involving more than 3 elements at once.) protected theorem forall₂_congr {α₁ α₂ β₁ β₂ : Sort*} {p : α₁ → β₁ → Prop} {q : α₂ → β₂ → Prop} (eα : α₁ ≃ α₂) (eβ : β₁ ≃ β₂) (h : ∀ {x y}, p x y ↔ q (eα x) (eβ y)) : (∀ x y, p x y) ↔ ∀ x y, q x y := eα.forall_congr fun _ ↦ eβ.forall_congr <| @h _ protected theorem forall₂_congr' {α₁ α₂ β₁ β₂ : Sort*} {p : α₁ → β₁ → Prop} {q : α₂ → β₂ → Prop} (eα : α₁ ≃ α₂) (eβ : β₁ ≃ β₂) (h : ∀ {x y}, p (eα.symm x) (eβ.symm y) ↔ q x y) : (∀ x y, p x y) ↔ ∀ x y, q x y := (Equiv.forall₂_congr eα.symm eβ.symm h.symm).symm protected theorem forall₃_congr {α₁ α₂ β₁ β₂ γ₁ γ₂ : Sort*} {p : α₁ → β₁ → γ₁ → Prop} {q : α₂ → β₂ → γ₂ → Prop} (eα : α₁ ≃ α₂) (eβ : β₁ ≃ β₂) (eγ : γ₁ ≃ γ₂) (h : ∀ {x y z}, p x y z ↔ q (eα x) (eβ y) (eγ z)) : (∀ x y z, p x y z) ↔ ∀ x y z, q x y z := Equiv.forall₂_congr _ _ <| Equiv.forall_congr _ <| @h _ _ protected theorem forall₃_congr' {α₁ α₂ β₁ β₂ γ₁ γ₂ : Sort*} {p : α₁ → β₁ → γ₁ → Prop} {q : α₂ → β₂ → γ₂ → Prop} (eα : α₁ ≃ α₂) (eβ : β₁ ≃ β₂) (eγ : γ₁ ≃ γ₂) (h : ∀ {x y z}, p (eα.symm x) (eβ.symm y) (eγ.symm z) ↔ q x y z) : (∀ x y z, p x y z) ↔ ∀ x y z, q x y z := (Equiv.forall₃_congr eα.symm eβ.symm eγ.symm h.symm).symm /-- If `f` is a bijective function, then its domain is equivalent to its codomain. -/ @[simps apply] noncomputable def ofBijective (f : α → β) (hf : Bijective f) : α ≃ β where toFun := f invFun := surjInv hf.surjective left_inv := leftInverse_surjInv hf right_inv := rightInverse_surjInv _ lemma ofBijective_apply_symm_apply (f : α → β) (hf : Bijective f) (x : β) : f ((ofBijective f hf).symm x) = x := (ofBijective f hf).apply_symm_apply x @[simp] lemma ofBijective_symm_apply_apply (f : α → β) (hf : Bijective f) (x : α) : (ofBijective f hf).symm (f x) = x := (ofBijective f hf).symm_apply_apply x end Equiv namespace Quot /-- An equivalence `e : α ≃ β` generates an equivalence between quotient spaces, if `ra a₁ a₂ ↔ rb (e a₁) (e a₂)`. -/ protected def congr {ra : α → α → Prop} {rb : β → β → Prop} (e : α ≃ β) (eq : ∀ a₁ a₂, ra a₁ a₂ ↔ rb (e a₁) (e a₂)) : Quot ra ≃ Quot rb where toFun := Quot.map e fun a₁ a₂ => (eq a₁ a₂).1 invFun := Quot.map e.symm fun b₁ b₂ h => (eq (e.symm b₁) (e.symm b₂)).2 ((e.apply_symm_apply b₁).symm ▸ (e.apply_symm_apply b₂).symm ▸ h) left_inv := by rintro ⟨a⟩; simp only [Quot.map, Equiv.symm_apply_apply] right_inv := by rintro ⟨a⟩; simp only [Quot.map, Equiv.apply_symm_apply] @[simp] theorem congr_mk {ra : α → α → Prop} {rb : β → β → Prop} (e : α ≃ β) (eq : ∀ a₁ a₂ : α, ra a₁ a₂ ↔ rb (e a₁) (e a₂)) (a : α) : Quot.congr e eq (Quot.mk ra a) = Quot.mk rb (e a) := rfl /-- Quotients are congruent on equivalences under equality of their relation. An alternative is just to use rewriting with `eq`, but then computational proofs get stuck. -/ protected def congrRight {r r' : α → α → Prop} (eq : ∀ a₁ a₂, r a₁ a₂ ↔ r' a₁ a₂) : Quot r ≃ Quot r' := Quot.congr (Equiv.refl α) eq /-- An equivalence `e : α ≃ β` generates an equivalence between the quotient space of `α` by a relation `ra` and the quotient space of `β` by the image of this relation under `e`. -/ protected def congrLeft {r : α → α → Prop} (e : α ≃ β) : Quot r ≃ Quot fun b b' => r (e.symm b) (e.symm b') := Quot.congr e fun _ _ => by simp only [e.symm_apply_apply] end Quot namespace Quotient /-- An equivalence `e : α ≃ β` generates an equivalence between quotient spaces, if `ra a₁ a₂ ↔ rb (e a₁) (e a₂)`. -/ protected def congr {ra : Setoid α} {rb : Setoid β} (e : α ≃ β) (eq : ∀ a₁ a₂, ra a₁ a₂ ↔ rb (e a₁) (e a₂)) : Quotient ra ≃ Quotient rb := Quot.congr e eq @[simp] theorem congr_mk {ra : Setoid α} {rb : Setoid β} (e : α ≃ β) (eq : ∀ a₁ a₂ : α, ra a₁ a₂ ↔ rb (e a₁) (e a₂)) (a : α) : Quotient.congr e eq (Quotient.mk ra a) = Quotient.mk rb (e a) := rfl /-- Quotients are congruent on equivalences under equality of their relation. An alternative is just to use rewriting with `eq`, but then computational proofs get stuck. -/ protected def congrRight {r r' : Setoid α} (eq : ∀ a₁ a₂, r a₁ a₂ ↔ r' a₁ a₂) : Quotient r ≃ Quotient r' := Quot.congrRight eq end Quotient /-- Equivalence between `Fin 0` and `Empty`. -/ def finZeroEquiv : Fin 0 ≃ Empty := .equivEmpty _ /-- Equivalence between `Fin 0` and `PEmpty`. -/ def finZeroEquiv' : Fin 0 ≃ PEmpty.{u} := .equivPEmpty _ /-- Equivalence between `Fin 1` and `Unit`. -/ def finOneEquiv : Fin 1 ≃ Unit := .equivPUnit _ /-- Equivalence between `Fin 2` and `Bool`. -/ def finTwoEquiv : Fin 2 ≃ Bool where toFun i := i == 1 invFun b := bif b then 1 else 0 left_inv i := match i with | 0 => by simp | 1 => by simp right_inv b := by cases b <;> simp
namespace Equiv
Mathlib/Logic/Equiv/Defs.lean
868
869
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.CategoryTheory.Sites.Pretopology import Mathlib.CategoryTheory.Sites.IsSheafFor /-! # Sheaves of types on a Grothendieck topology Defines the notion of a sheaf of types (usually called a sheaf of sets by mathematicians) on a category equipped with a Grothendieck topology, as well as a range of equivalent conditions useful in different situations. In `Mathlib/CategoryTheory/Sites/IsSheafFor.lean` it is defined what it means for a presheaf to be a sheaf *for* a particular sieve. Given a Grothendieck topology `J`, `P` is a sheaf if it is a sheaf for every sieve in the topology. See `IsSheaf`. In the case where the topology is generated by a basis, it suffices to check `P` is a sheaf for every presieve in the pretopology. See `isSheaf_pretopology`. We also provide equivalent conditions to satisfy alternate definitions given in the literature. * Stacks: In `Equalizer.Presieve.sheaf_condition`, the sheaf condition at a presieve is shown to be equivalent to that of https://stacks.math.columbia.edu/tag/00VM (and combined with `isSheaf_pretopology`, this shows the notions of `IsSheaf` are exactly equivalent.) The condition of https://stacks.math.columbia.edu/tag/00Z8 is virtually identical to the statement of `isSheafFor_iff_yonedaSheafCondition` (since the bijection described there carries the same information as the unique existence.) * Maclane-Moerdijk [MM92]: Using `compatible_iff_sieveCompatible`, the definitions of `IsSheaf` are equivalent. There are also alternate definitions given: - Sheaf for a pretopology (Prop 1): `isSheaf_pretopology` combined with `pullbackCompatible_iff`. - Sheaf for a pretopology as equalizer (Prop 1, bis): `Equalizer.Presieve.sheaf_condition` combined with the previous. ## References * [MM92]: *Sheaves in geometry and logic*, Saunders MacLane, and Ieke Moerdijk: Chapter III, Section 4. * [Elephant]: *Sketches of an Elephant*, P. T. Johnstone: C2.1. * https://stacks.math.columbia.edu/tag/00VL (sheaves on a pretopology or site) * https://stacks.math.columbia.edu/tag/00ZB (sheaves on a topology) -/ universe w w' v u namespace CategoryTheory open Opposite CategoryTheory Category Limits Sieve namespace Presieve variable {C : Type u} [Category.{v} C] variable {P : Cᵒᵖ ⥤ Type w} variable {X : C} variable (J J₂ : GrothendieckTopology C) /-- A presheaf is separated for a topology if it is separated for every sieve in the topology. -/ def IsSeparated (P : Cᵒᵖ ⥤ Type w) : Prop := ∀ {X} (S : Sieve X), S ∈ J X → IsSeparatedFor P (S : Presieve X) /-- A presheaf is a sheaf for a topology if it is a sheaf for every sieve in the topology. If the given topology is given by a pretopology, `isSheaf_pretopology` shows it suffices to check the sheaf condition at presieves in the pretopology. -/ def IsSheaf (P : Cᵒᵖ ⥤ Type w) : Prop := ∀ ⦃X⦄ (S : Sieve X), S ∈ J X → IsSheafFor P (S : Presieve X) theorem IsSheaf.isSheafFor {P : Cᵒᵖ ⥤ Type w} (hp : IsSheaf J P) (R : Presieve X) (hr : generate R ∈ J X) : IsSheafFor P R := (isSheafFor_iff_generate R).2 <| hp _ hr theorem isSheaf_of_le (P : Cᵒᵖ ⥤ Type w) {J₁ J₂ : GrothendieckTopology C} : J₁ ≤ J₂ → IsSheaf J₂ P → IsSheaf J₁ P := fun h t _ S hS => t S (h _ hS) theorem isSeparated_of_isSheaf (P : Cᵒᵖ ⥤ Type w) (h : IsSheaf J P) : IsSeparated J P := fun S hS => (h S hS).isSeparatedFor section variable {J} {P₁ : Cᵒᵖ ⥤ Type w} {P₂ : Cᵒᵖ ⥤ Type w'} (e : ∀ ⦃X : C⦄, P₁.obj (op X) ≃ P₂.obj (op X)) (he : ∀ ⦃X Y : C⦄ (f : X ⟶ Y) (x : P₁.obj (op Y)), e (P₁.map f.op x) = P₂.map f.op (e x)) include he in lemma isSheaf_of_nat_equiv (hP₁ : Presieve.IsSheaf J P₁) : Presieve.IsSheaf J P₂ := fun _ R hR ↦ isSheafFor_of_nat_equiv e he (hP₁ R hR) include he in lemma isSheaf_iff_of_nat_equiv : Presieve.IsSheaf J P₁ ↔ Presieve.IsSheaf J P₂ := ⟨fun hP₁ ↦ isSheaf_of_nat_equiv e he hP₁, fun hP₂ ↦ isSheaf_of_nat_equiv (fun _ ↦ (@e _).symm) (fun X Y f x ↦ by obtain ⟨y, rfl⟩ := e.surjective x refine e.injective ?_
simp only [Equiv.apply_symm_apply, Equiv.symm_apply_apply, he]) hP₂⟩ end /-- The property of being a sheaf is preserved by isomorphism. -/ theorem isSheaf_iso {P' : Cᵒᵖ ⥤ Type w} (i : P ≅ P') (h : IsSheaf J P) : IsSheaf J P' := fun _ S hS => isSheafFor_iso i (h S hS) theorem isSheaf_of_yoneda {P : Cᵒᵖ ⥤ Type v} (h : ∀ {X} (S : Sieve X), S ∈ J X → YonedaSheafCondition P S) : IsSheaf J P := fun _ _ hS => isSheafFor_iff_yonedaSheafCondition.2 (h _ hS) /-- For a topology generated by a basis, it suffices to check the sheaf condition on the basis presieves only.
Mathlib/CategoryTheory/Sites/SheafOfTypes.lean
105
118
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura -/ import Batteries.Tactic.Congr import Mathlib.Data.Option.Basic import Mathlib.Data.Prod.Basic import Mathlib.Data.Set.Subsingleton import Mathlib.Data.Set.SymmDiff import Mathlib.Data.Set.Inclusion /-! # Images and preimages of sets ## Main definitions * `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β. * `range f : Set β` : the image of `univ` under `f`. Also works for `{p : Prop} (f : p → α)` (unlike `image`) ## Notation * `f ⁻¹' t` for `Set.preimage f t` * `f '' s` for `Set.image f s` ## Tags set, sets, image, preimage, pre-image, range -/ assert_not_exists WithTop OrderIso universe u v open Function Set namespace Set variable {α β γ : Type*} {ι : Sort*} /-! ### Inverse image -/ section Preimage variable {f : α → β} {g : β → γ} @[simp] theorem preimage_empty : f ⁻¹' ∅ = ∅ := rfl theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by congr with x simp [h] @[gcongr] theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx @[simp, mfld_simps] theorem preimage_univ : f ⁻¹' univ = univ := rfl theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ := subset_univ _ @[simp, mfld_simps] theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t := rfl @[simp] theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t := rfl @[simp] theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ := rfl @[simp] theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t := rfl open scoped symmDiff in @[simp] lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) := rfl @[simp] theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) : f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) := rfl @[simp] theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } := rfl @[simp] theorem preimage_id_eq : preimage (id : α → α) = id := rfl @[mfld_simps] theorem preimage_id {s : Set α} : id ⁻¹' s = s := rfl @[simp, mfld_simps] theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s := rfl @[simp] theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ := eq_univ_of_forall fun _ => h @[simp] theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ := eq_empty_of_subset_empty fun _ hx => h hx theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] : (fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by split_ifs with hb exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb] /-- If preimage of each singleton under `f : α → β` is either empty or the whole type, then `f` is a constant. -/ lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β} (hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf' · exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩ · have : ∀ x b, f x ≠ b := fun x b ↦ eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩ theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) := rfl theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g := rfl theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by induction n with | zero => simp | succ n ih => rw [iterate_succ, iterate_succ', preimage_comp_eq, ih] theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} : f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s := preimage_comp.symm theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} : s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t := ⟨fun s_eq x h => by rw [s_eq] simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩ theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) : s.Nonempty := let ⟨x, hx⟩ := hf ⟨f x, hx⟩ @[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp @[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v) (H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by ext ⟨x, x_in_s⟩ constructor · intro x_in_u x_in_v exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩ · intro hx exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx' lemma preimage_subset {s t} (hs : s ⊆ f '' t) (hf : Set.InjOn f (f ⁻¹' s)) : f ⁻¹' s ⊆ t := by rintro a ha obtain ⟨b, hb, hba⟩ := hs ha rwa [hf ha _ hba.symm] simpa [hba] end Preimage /-! ### Image of a set under a function -/ section Image variable {f : α → β} {s t : Set α} theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s := rfl theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} : f a ∈ f '' s ↔ a ∈ s := ⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩ lemma preimage_subset_of_surjOn {t : Set β} (hf : Injective f) (h : SurjOn f s t) : f ⁻¹' t ⊆ s := fun _ hx ↦ hf.mem_set_image.1 <| h hx theorem forall_mem_image {f : α → β} {s : Set α} {p : β → Prop} : (∀ y ∈ f '' s, p y) ↔ ∀ ⦃x⦄, x ∈ s → p (f x) := by simp theorem exists_mem_image {f : α → β} {s : Set α} {p : β → Prop} : (∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp @[congr] theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by aesop /-- A common special case of `image_congr` -/ theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s := image_congr fun x _ => h x @[gcongr] lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha) theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) := by aesop theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp /-- A variant of `image_comp`, useful for rewriting -/ theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s := (image_comp g f s).symm theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ} (h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by simp_rw [image_image, h_comm] theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β} (h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ => image_comm h theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) : Function.Commute (image f) (image g) := Function.Semiconj.set_image h /-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in terms of `≤`. -/ @[gcongr] theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by simp only [subset_def, mem_image] exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩ /-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/ lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _ theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t := ext fun x => ⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine ⟨_, ?_, rfl⟩ · exact mem_union_left t h · exact mem_union_right s h⟩ @[simp] theorem image_empty (f : α → β) : f '' ∅ = ∅ := by ext simp theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t := subset_inter (image_subset _ inter_subset_left) (image_subset _ inter_subset_right) theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) : f '' (s ∩ t) = f '' s ∩ f '' t := (image_inter_subset _ _ _).antisymm fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦ have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*]) ⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩ theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t := image_inter_on fun _ _ _ _ h => H h theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ := eq_univ_of_forall <| by simpa [image] @[simp] theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by ext simp [image, eq_comm] @[simp] theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} := ext fun _ => ⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h => (eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩ @[simp, mfld_simps] theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by simp only [eq_empty_iff_forall_not_mem] exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩ theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) : HasCompl.compl ⁻¹' S = HasCompl.compl '' S := Set.ext fun x => ⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h => Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩ theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) : t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by simp [← preimage_compl_eq_image_compl] @[simp] theorem image_id_eq : image (id : α → α) = id := by ext; simp /-- A variant of `image_id` -/ @[simp] theorem image_id' (s : Set α) : (fun x => x) '' s = s := by ext simp theorem image_id (s : Set α) : id '' s = s := by simp lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by induction n with | zero => simp | succ n ih => rw [iterate_succ', iterate_succ', ← ih, image_comp_eq] theorem compl_compl_image [BooleanAlgebra α] (S : Set α) : HasCompl.compl '' (HasCompl.compl '' S) = S := by rw [← image_comp, compl_comp_compl, image_id] theorem image_insert_eq {f : α → β} {a : α} {s : Set α} : f '' insert a s = insert (f a) (f '' s) := by ext simp [and_or_left, exists_or, eq_comm, or_comm, and_comm] theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by simp only [image_insert_eq, image_singleton] theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) : f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s) theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) : f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩ theorem range_inter_ssubset_iff_preimage_ssubset {f : α → β} {S S' : Set β} : range f ∩ S ⊂ range f ∩ S' ↔ f ⁻¹' S ⊂ f ⁻¹' S' := by simp only [Set.ssubset_iff_exists] apply and_congr ?_ (by aesop) constructor all_goals intro r x hx simp_all only [subset_inter_iff, inter_subset_left, true_and, mem_preimage, mem_inter_iff, mem_range, true_and] aesop theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f) (h₂ : RightInverse g f) : image f = preimage g := funext fun s => Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s) theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f) (h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by rw [image_eq_preimage_of_inverse h₁ h₂]; rfl theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ := Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H] theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ := compl_subset_iff_union.2 <| by rw [← image_union] simp [image_univ_of_surjective H] theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ := Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2) theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by rw [diff_subset_iff, ← image_union, union_diff_self] exact image_subset f subset_union_right open scoped symmDiff in theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t := (union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans (superset_of_eq (image_union _ _ _)) theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t := Subset.antisymm (Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf) (subset_image_diff f s t) open scoped symmDiff in theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by simp_rw [Set.symmDiff_def, image_union, image_diff hf] theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty | ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩ theorem Nonempty.of_image {f : α → β} {s : Set α} : (f '' s).Nonempty → s.Nonempty | ⟨_, x, hx, _⟩ => ⟨x, hx⟩ @[simp] theorem image_nonempty {f : α → β} {s : Set α} : (f '' s).Nonempty ↔ s.Nonempty := ⟨Nonempty.of_image, fun h => h.image f⟩ theorem Nonempty.preimage {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : Surjective f) : (f ⁻¹' s).Nonempty := let ⟨y, hy⟩ := hs let ⟨x, hx⟩ := hf y ⟨x, mem_preimage.2 <| hx.symm ▸ hy⟩ instance (f : α → β) (s : Set α) [Nonempty s] : Nonempty (f '' s) := (Set.Nonempty.image f .of_subtype).to_subtype /-- image and preimage are a Galois connection -/ @[simp] theorem image_subset_iff {s : Set α} {t : Set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t := forall_mem_image theorem image_preimage_subset (f : α → β) (s : Set β) : f '' (f ⁻¹' s) ⊆ s := image_subset_iff.2 Subset.rfl theorem subset_preimage_image (f : α → β) (s : Set α) : s ⊆ f ⁻¹' (f '' s) := fun _ => mem_image_of_mem f theorem preimage_image_univ {f : α → β} : f ⁻¹' (f '' univ) = univ := Subset.antisymm (fun _ _ => trivial) (subset_preimage_image f univ) @[simp] theorem preimage_image_eq {f : α → β} (s : Set α) (h : Injective f) : f ⁻¹' (f '' s) = s := Subset.antisymm (fun _ ⟨_, hy, e⟩ => h e ▸ hy) (subset_preimage_image f s) @[simp] theorem image_preimage_eq {f : α → β} (s : Set β) (h : Surjective f) : f '' (f ⁻¹' s) = s := Subset.antisymm (image_preimage_subset f s) fun x hx => let ⟨y, e⟩ := h x ⟨y, (e.symm ▸ hx : f y ∈ s), e⟩ @[simp] theorem Nonempty.subset_preimage_const {s : Set α} (hs : Set.Nonempty s) (t : Set β) (a : β) : s ⊆ (fun _ => a) ⁻¹' t ↔ a ∈ t := by rw [← image_subset_iff, hs.image_const, singleton_subset_iff] -- Note defeq abuse identifying `preimage` with function composition in the following two proofs. @[simp] theorem preimage_injective : Injective (preimage f) ↔ Surjective f := injective_comp_right_iff_surjective @[simp] theorem preimage_surjective : Surjective (preimage f) ↔ Injective f := surjective_comp_right_iff_injective @[simp] theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t := (preimage_injective.mpr hf).eq_iff theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) : f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by apply Subset.antisymm · calc f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ f '' (f ⁻¹' t) := image_inter_subset _ _ _ _ ⊆ f '' s ∩ t := inter_subset_inter_right _ (image_preimage_subset f t) · rintro _ ⟨⟨x, h', rfl⟩, h⟩ exact ⟨x, ⟨h', h⟩, rfl⟩ theorem image_preimage_inter (f : α → β) (s : Set α) (t : Set β) : f '' (f ⁻¹' t ∩ s) = t ∩ f '' s := by simp only [inter_comm, image_inter_preimage] @[simp] theorem image_inter_nonempty_iff {f : α → β} {s : Set α} {t : Set β} : (f '' s ∩ t).Nonempty ↔ (s ∩ f ⁻¹' t).Nonempty := by rw [← image_inter_preimage, image_nonempty] theorem image_diff_preimage {f : α → β} {s : Set α} {t : Set β} : f '' (s \ f ⁻¹' t) = f '' s \ t := by simp_rw [diff_eq, ← preimage_compl, image_inter_preimage] theorem compl_image : image (compl : Set α → Set α) = preimage compl := image_eq_preimage_of_inverse compl_compl compl_compl theorem compl_image_set_of {p : Set α → Prop} : compl '' { s | p s } = { s | p sᶜ } := congr_fun compl_image p theorem inter_preimage_subset (s : Set α) (t : Set β) (f : α → β) : s ∩ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∩ t) := fun _ h => ⟨mem_image_of_mem _ h.left, h.right⟩ theorem union_preimage_subset (s : Set α) (t : Set β) (f : α → β) : s ∪ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∪ t) := fun _ h => Or.elim h (fun l => Or.inl <| mem_image_of_mem _ l) fun r => Or.inr r theorem subset_image_union (f : α → β) (s : Set α) (t : Set β) : f '' (s ∪ f ⁻¹' t) ⊆ f '' s ∪ t := image_subset_iff.2 (union_preimage_subset _ _ _) theorem preimage_subset_iff {A : Set α} {B : Set β} {f : α → β} : f ⁻¹' B ⊆ A ↔ ∀ a : α, f a ∈ B → a ∈ A := Iff.rfl theorem image_eq_image {f : α → β} (hf : Injective f) : f '' s = f '' t ↔ s = t := Iff.symm <| (Iff.intro fun eq => eq ▸ rfl) fun eq => by rw [← preimage_image_eq s hf, ← preimage_image_eq t hf, eq] theorem subset_image_iff {t : Set β} : t ⊆ f '' s ↔ ∃ u, u ⊆ s ∧ f '' u = t := by refine ⟨fun h ↦ ⟨f ⁻¹' t ∩ s, inter_subset_right, ?_⟩, fun ⟨u, hu, hu'⟩ ↦ hu'.symm ▸ image_mono hu⟩ rwa [image_preimage_inter, inter_eq_left] @[simp] lemma exists_subset_image_iff {p : Set β → Prop} : (∃ t ⊆ f '' s, p t) ↔ ∃ t ⊆ s, p (f '' t) := by simp [subset_image_iff] @[simp] lemma forall_subset_image_iff {p : Set β → Prop} : (∀ t ⊆ f '' s, p t) ↔ ∀ t ⊆ s, p (f '' t) := by simp [subset_image_iff] theorem image_subset_image_iff {f : α → β} (hf : Injective f) : f '' s ⊆ f '' t ↔ s ⊆ t := by refine Iff.symm <| (Iff.intro (image_subset f)) fun h => ?_ rw [← preimage_image_eq s hf, ← preimage_image_eq t hf] exact preimage_mono h theorem prod_quotient_preimage_eq_image [s : Setoid α] (g : Quotient s → β) {h : α → β} (Hh : h = g ∘ Quotient.mk'') (r : Set (β × β)) : { x : Quotient s × Quotient s | (g x.1, g x.2) ∈ r } = (fun a : α × α => (⟦a.1⟧, ⟦a.2⟧)) '' ((fun a : α × α => (h a.1, h a.2)) ⁻¹' r) := Hh.symm ▸ Set.ext fun ⟨a₁, a₂⟩ => ⟨Quot.induction_on₂ a₁ a₂ fun a₁ a₂ h => ⟨(a₁, a₂), h, rfl⟩, fun ⟨⟨b₁, b₂⟩, h₁, h₂⟩ => show (g a₁, g a₂) ∈ r from have h₃ : ⟦b₁⟧ = a₁ ∧ ⟦b₂⟧ = a₂ := Prod.ext_iff.1 h₂ h₃.1 ▸ h₃.2 ▸ h₁⟩ theorem exists_image_iff (f : α → β) (x : Set α) (P : β → Prop) : (∃ a : f '' x, P a) ↔ ∃ a : x, P (f a) := ⟨fun ⟨a, h⟩ => ⟨⟨_, a.prop.choose_spec.1⟩, a.prop.choose_spec.2.symm ▸ h⟩, fun ⟨a, h⟩ => ⟨⟨_, _, a.prop, rfl⟩, h⟩⟩ theorem imageFactorization_eq {f : α → β} {s : Set α} : Subtype.val ∘ imageFactorization f s = f ∘ Subtype.val := funext fun _ => rfl theorem surjective_onto_image {f : α → β} {s : Set α} : Surjective (imageFactorization f s) := fun ⟨_, ⟨a, ha, rfl⟩⟩ => ⟨⟨a, ha⟩, rfl⟩ /-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect. -/ theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s := by ext i obtain hi | hi := eq_or_ne (σ i) i · refine ⟨?_, fun h => ⟨i, h, hi⟩⟩ rintro ⟨j, hj, h⟩ rwa [σ.injective (hi.trans h.symm)] · refine iff_of_true ⟨σ.symm i, hs fun h => hi ?_, σ.apply_symm_apply _⟩ (hs hi) convert congr_arg σ h <;> exact (σ.apply_symm_apply _).symm end Image /-! ### Lemmas about the powerset and image. -/ /-- The powerset of `{a} ∪ s` is `𝒫 s` together with `{a} ∪ t` for each `t ∈ 𝒫 s`. -/ theorem powerset_insert (s : Set α) (a : α) : 𝒫 insert a s = 𝒫 s ∪ insert a '' 𝒫 s := by ext t simp_rw [mem_union, mem_image, mem_powerset_iff] constructor · intro h by_cases hs : a ∈ t · right refine ⟨t \ {a}, ?_, ?_⟩ · rw [diff_singleton_subset_iff] assumption · rw [insert_diff_singleton, insert_eq_of_mem hs] · left exact (subset_insert_iff_of_not_mem hs).mp h · rintro (h | ⟨s', h₁, rfl⟩) · exact subset_trans h (subset_insert a s) · exact insert_subset_insert h₁ /-! ### Lemmas about range of a function. -/ section Range variable {f : ι → α} {s t : Set α} theorem forall_mem_range {p : α → Prop} : (∀ a ∈ range f, p a) ↔ ∀ i, p (f i) := by simp theorem forall_subtype_range_iff {p : range f → Prop} : (∀ a : range f, p a) ↔ ∀ i, p ⟨f i, mem_range_self _⟩ := ⟨fun H _ => H _, fun H ⟨y, i, hi⟩ => by subst hi apply H⟩ theorem exists_range_iff {p : α → Prop} : (∃ a ∈ range f, p a) ↔ ∃ i, p (f i) := by simp theorem exists_subtype_range_iff {p : range f → Prop} : (∃ a : range f, p a) ↔ ∃ i, p ⟨f i, mem_range_self _⟩ := ⟨fun ⟨⟨a, i, hi⟩, ha⟩ => by subst a exact ⟨i, ha⟩, fun ⟨_, hi⟩ => ⟨_, hi⟩⟩ theorem range_eq_univ : range f = univ ↔ Surjective f := eq_univ_iff_forall @[deprecated (since := "2024-11-11")] alias range_iff_surjective := range_eq_univ alias ⟨_, _root_.Function.Surjective.range_eq⟩ := range_eq_univ @[simp] theorem subset_range_of_surjective {f : α → β} (h : Surjective f) (s : Set β) : s ⊆ range f := Surjective.range_eq h ▸ subset_univ s @[simp] theorem image_univ {f : α → β} : f '' univ = range f := by ext simp [image, range] lemma image_compl_eq_range_diff_image {f : α → β} (hf : Injective f) (s : Set α) : f '' sᶜ = range f \ f '' s := by rw [← image_univ, ← image_diff hf, compl_eq_univ_diff] /-- Alias of `Set.image_compl_eq_range_sdiff_image`. -/ lemma range_diff_image {f : α → β} (hf : Injective f) (s : Set α) : range f \ f '' s = f '' sᶜ := by rw [image_compl_eq_range_diff_image hf] @[simp] theorem preimage_eq_univ_iff {f : α → β} {s} : f ⁻¹' s = univ ↔ range f ⊆ s := by rw [← univ_subset_iff, ← image_subset_iff, image_univ] theorem image_subset_range (f : α → β) (s) : f '' s ⊆ range f := by rw [← image_univ]; exact image_subset _ (subset_univ _) theorem mem_range_of_mem_image (f : α → β) (s) {x : β} (h : x ∈ f '' s) : x ∈ range f := image_subset_range f s h theorem _root_.Nat.mem_range_succ (i : ℕ) : i ∈ range Nat.succ ↔ 0 < i := ⟨by rintro ⟨n, rfl⟩ exact Nat.succ_pos n, fun h => ⟨_, Nat.succ_pred_eq_of_pos h⟩⟩ theorem Nonempty.preimage' {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : s ⊆ range f) : (f ⁻¹' s).Nonempty := let ⟨_, hy⟩ := hs let ⟨x, hx⟩ := hf hy ⟨x, Set.mem_preimage.2 <| hx.symm ▸ hy⟩ theorem range_comp (g : α → β) (f : ι → α) : range (g ∘ f) = g '' range f := by aesop /-- Variant of `range_comp` using a lambda instead of function composition. -/ theorem range_comp' (g : α → β) (f : ι → α) : range (fun x => g (f x)) = g '' range f := range_comp g f theorem range_subset_iff : range f ⊆ s ↔ ∀ y, f y ∈ s := forall_mem_range theorem range_subset_range_iff_exists_comp {f : α → γ} {g : β → γ} : range f ⊆ range g ↔ ∃ h : α → β, f = g ∘ h := by simp only [range_subset_iff, mem_range, Classical.skolem, funext_iff, (· ∘ ·), eq_comm] theorem range_eq_iff (f : α → β) (s : Set β) : range f = s ↔ (∀ a, f a ∈ s) ∧ ∀ b ∈ s, ∃ a, f a = b := by rw [← range_subset_iff] exact le_antisymm_iff theorem range_comp_subset_range (f : α → β) (g : β → γ) : range (g ∘ f) ⊆ range g := by rw [range_comp]; apply image_subset_range theorem range_nonempty_iff_nonempty : (range f).Nonempty ↔ Nonempty ι := ⟨fun ⟨_, x, _⟩ => ⟨x⟩, fun ⟨x⟩ => ⟨f x, mem_range_self x⟩⟩ theorem range_nonempty [h : Nonempty ι] (f : ι → α) : (range f).Nonempty := range_nonempty_iff_nonempty.2 h @[simp] theorem range_eq_empty_iff {f : ι → α} : range f = ∅ ↔ IsEmpty ι := by rw [← not_nonempty_iff, ← range_nonempty_iff_nonempty, not_nonempty_iff_eq_empty] theorem range_eq_empty [IsEmpty ι] (f : ι → α) : range f = ∅ := range_eq_empty_iff.2 ‹_› instance instNonemptyRange [Nonempty ι] (f : ι → α) : Nonempty (range f) := (range_nonempty f).to_subtype @[simp] theorem image_union_image_compl_eq_range (f : α → β) : f '' s ∪ f '' sᶜ = range f := by rw [← image_union, ← image_univ, ← union_compl_self] theorem insert_image_compl_eq_range (f : α → β) (x : α) : insert (f x) (f '' {x}ᶜ) = range f := by rw [← image_insert_eq, insert_eq, union_compl_self, image_univ] theorem image_preimage_eq_range_inter {f : α → β} {t : Set β} : f '' (f ⁻¹' t) = range f ∩ t := ext fun x => ⟨fun ⟨_, hx, HEq⟩ => HEq ▸ ⟨mem_range_self _, hx⟩, fun ⟨⟨y, h_eq⟩, hx⟩ => h_eq ▸ mem_image_of_mem f <| show y ∈ f ⁻¹' t by rw [preimage, mem_setOf, h_eq]; exact hx⟩ theorem image_preimage_eq_inter_range {f : α → β} {t : Set β} : f '' (f ⁻¹' t) = t ∩ range f := by rw [image_preimage_eq_range_inter, inter_comm] theorem image_preimage_eq_of_subset {f : α → β} {s : Set β} (hs : s ⊆ range f) : f '' (f ⁻¹' s) = s := by rw [image_preimage_eq_range_inter, inter_eq_self_of_subset_right hs] theorem image_preimage_eq_iff {f : α → β} {s : Set β} : f '' (f ⁻¹' s) = s ↔ s ⊆ range f := ⟨by intro h rw [← h] apply image_subset_range, image_preimage_eq_of_subset⟩ theorem subset_range_iff_exists_image_eq {f : α → β} {s : Set β} : s ⊆ range f ↔ ∃ t, f '' t = s := ⟨fun h => ⟨_, image_preimage_eq_iff.2 h⟩, fun ⟨_, ht⟩ => ht ▸ image_subset_range _ _⟩ theorem range_image (f : α → β) : range (image f) = 𝒫 range f := ext fun _ => subset_range_iff_exists_image_eq.symm @[simp] theorem exists_subset_range_and_iff {f : α → β} {p : Set β → Prop} : (∃ s, s ⊆ range f ∧ p s) ↔ ∃ s, p (f '' s) := by rw [← exists_range_iff, range_image]; rfl @[simp] theorem forall_subset_range_iff {f : α → β} {p : Set β → Prop} : (∀ s, s ⊆ range f → p s) ↔ ∀ s, p (f '' s) := by rw [← forall_mem_range, range_image]; simp only [mem_powerset_iff] @[simp] theorem preimage_subset_preimage_iff {s t : Set α} {f : β → α} (hs : s ⊆ range f) : f ⁻¹' s ⊆ f ⁻¹' t ↔ s ⊆ t := by constructor · intro h x hx rcases hs hx with ⟨y, rfl⟩ exact h hx intro h x; apply h theorem preimage_eq_preimage' {s t : Set α} {f : β → α} (hs : s ⊆ range f) (ht : t ⊆ range f) : f ⁻¹' s = f ⁻¹' t ↔ s = t := by constructor · intro h apply Subset.antisymm · rw [← preimage_subset_preimage_iff hs, h] · rw [← preimage_subset_preimage_iff ht, h] rintro rfl; rfl -- Not `@[simp]` since `simp` can prove this. theorem preimage_inter_range {f : α → β} {s : Set β} : f ⁻¹' (s ∩ range f) = f ⁻¹' s := Set.ext fun x => and_iff_left ⟨x, rfl⟩ -- Not `@[simp]` since `simp` can prove this. theorem preimage_range_inter {f : α → β} {s : Set β} : f ⁻¹' (range f ∩ s) = f ⁻¹' s := by rw [inter_comm, preimage_inter_range] theorem preimage_image_preimage {f : α → β} {s : Set β} : f ⁻¹' (f '' (f ⁻¹' s)) = f ⁻¹' s := by rw [image_preimage_eq_range_inter, preimage_range_inter] @[simp, mfld_simps] theorem range_id : range (@id α) = univ := range_eq_univ.2 surjective_id @[simp, mfld_simps] theorem range_id' : (range fun x : α => x) = univ := range_id @[simp] theorem _root_.Prod.range_fst [Nonempty β] : range (Prod.fst : α × β → α) = univ := Prod.fst_surjective.range_eq @[simp] theorem _root_.Prod.range_snd [Nonempty α] : range (Prod.snd : α × β → β) = univ := Prod.snd_surjective.range_eq @[simp] theorem range_eval {α : ι → Sort _} [∀ i, Nonempty (α i)] (i : ι) : range (eval i : (∀ i, α i) → α i) = univ := (surjective_eval i).range_eq theorem range_inl : range (@Sum.inl α β) = {x | Sum.isLeft x} := by ext (_|_) <;> simp theorem range_inr : range (@Sum.inr α β) = {x | Sum.isRight x} := by ext (_|_) <;> simp theorem isCompl_range_inl_range_inr : IsCompl (range <| @Sum.inl α β) (range Sum.inr) := IsCompl.of_le (by rintro y ⟨⟨x₁, rfl⟩, ⟨x₂, h⟩⟩ exact Sum.noConfusion h) (by rintro (x | y) - <;> [left; right] <;> exact mem_range_self _) @[simp] theorem range_inl_union_range_inr : range (Sum.inl : α → α ⊕ β) ∪ range Sum.inr = univ := isCompl_range_inl_range_inr.sup_eq_top @[simp] theorem range_inl_inter_range_inr : range (Sum.inl : α → α ⊕ β) ∩ range Sum.inr = ∅ := isCompl_range_inl_range_inr.inf_eq_bot @[simp] theorem range_inr_union_range_inl : range (Sum.inr : β → α ⊕ β) ∪ range Sum.inl = univ := isCompl_range_inl_range_inr.symm.sup_eq_top @[simp] theorem range_inr_inter_range_inl : range (Sum.inr : β → α ⊕ β) ∩ range Sum.inl = ∅ := isCompl_range_inl_range_inr.symm.inf_eq_bot @[simp] theorem preimage_inl_image_inr (s : Set β) : Sum.inl ⁻¹' (@Sum.inr α β '' s) = ∅ := by ext simp @[simp] theorem preimage_inr_image_inl (s : Set α) : Sum.inr ⁻¹' (@Sum.inl α β '' s) = ∅ := by ext simp @[simp] theorem preimage_inl_range_inr : Sum.inl ⁻¹' range (Sum.inr : β → α ⊕ β) = ∅ := by rw [← image_univ, preimage_inl_image_inr] @[simp] theorem preimage_inr_range_inl : Sum.inr ⁻¹' range (Sum.inl : α → α ⊕ β) = ∅ := by rw [← image_univ, preimage_inr_image_inl] @[simp] theorem compl_range_inl : (range (Sum.inl : α → α ⊕ β))ᶜ = range (Sum.inr : β → α ⊕ β) := IsCompl.compl_eq isCompl_range_inl_range_inr @[simp] theorem compl_range_inr : (range (Sum.inr : β → α ⊕ β))ᶜ = range (Sum.inl : α → α ⊕ β) := IsCompl.compl_eq isCompl_range_inl_range_inr.symm theorem image_preimage_inl_union_image_preimage_inr (s : Set (α ⊕ β)) : Sum.inl '' (Sum.inl ⁻¹' s) ∪ Sum.inr '' (Sum.inr ⁻¹' s) = s := by rw [image_preimage_eq_inter_range, image_preimage_eq_inter_range, ← inter_union_distrib_left, range_inl_union_range_inr, inter_univ] @[simp] theorem range_quot_mk (r : α → α → Prop) : range (Quot.mk r) = univ := Quot.mk_surjective.range_eq @[simp] theorem range_quot_lift {r : ι → ι → Prop} (hf : ∀ x y, r x y → f x = f y) : range (Quot.lift f hf) = range f := ext fun _ => Quot.mk_surjective.exists @[simp] theorem range_quotient_mk {s : Setoid α} : range (Quotient.mk s) = univ := range_quot_mk _ @[simp] theorem range_quotient_lift [s : Setoid ι] (hf) : range (Quotient.lift f hf : Quotient s → α) = range f := range_quot_lift _ @[simp] theorem range_quotient_mk' {s : Setoid α} : range (Quotient.mk' : α → Quotient s) = univ := range_quot_mk _ lemma Quotient.range_mk'' {sa : Setoid α} : range (Quotient.mk'' (s₁ := sa)) = univ := range_quotient_mk @[simp] theorem range_quotient_lift_on' {s : Setoid ι} (hf) : (range fun x : Quotient s => Quotient.liftOn' x f hf) = range f := range_quot_lift _ instance canLift (c) (p) [CanLift α β c p] : CanLift (Set α) (Set β) (c '' ·) fun s => ∀ x ∈ s, p x where prf _ hs := subset_range_iff_exists_image_eq.mp fun x hx => CanLift.prf _ (hs x hx) theorem range_const_subset {c : α} : (range fun _ : ι => c) ⊆ {c} := range_subset_iff.2 fun _ => rfl @[simp] theorem range_const : ∀ [Nonempty ι] {c : α}, (range fun _ : ι => c) = {c} | ⟨x⟩, _ => (Subset.antisymm range_const_subset) fun _ hy => (mem_singleton_iff.1 hy).symm ▸ mem_range_self x theorem range_subtype_map {p : α → Prop} {q : β → Prop} (f : α → β) (h : ∀ x, p x → q (f x)) : range (Subtype.map f h) = (↑) ⁻¹' (f '' { x | p x }) := by ext ⟨x, hx⟩ simp_rw [mem_preimage, mem_range, mem_image, Subtype.exists, Subtype.map] simp only [Subtype.mk.injEq, exists_prop, mem_setOf_eq] theorem image_swap_eq_preimage_swap : image (@Prod.swap α β) = preimage Prod.swap := image_eq_preimage_of_inverse Prod.swap_leftInverse Prod.swap_rightInverse theorem preimage_singleton_nonempty {f : α → β} {y : β} : (f ⁻¹' {y}).Nonempty ↔ y ∈ range f := Iff.rfl theorem preimage_singleton_eq_empty {f : α → β} {y : β} : f ⁻¹' {y} = ∅ ↔ y ∉ range f := not_nonempty_iff_eq_empty.symm.trans preimage_singleton_nonempty.not theorem range_subset_singleton {f : ι → α} {x : α} : range f ⊆ {x} ↔ f = const ι x := by simp [range_subset_iff, funext_iff, mem_singleton] theorem image_compl_preimage {f : α → β} {s : Set β} : f '' (f ⁻¹' s)ᶜ = range f \ s := by rw [compl_eq_univ_diff, image_diff_preimage, image_univ] theorem rangeFactorization_eq {f : ι → β} : Subtype.val ∘ rangeFactorization f = f := funext fun _ => rfl @[simp] theorem rangeFactorization_coe (f : ι → β) (a : ι) : (rangeFactorization f a : β) = f a := rfl @[simp] theorem coe_comp_rangeFactorization (f : ι → β) : (↑) ∘ rangeFactorization f = f := rfl theorem surjective_onto_range : Surjective (rangeFactorization f) := fun ⟨_, ⟨i, rfl⟩⟩ => ⟨i, rfl⟩ theorem image_eq_range (f : α → β) (s : Set α) : f '' s = range fun x : s => f x := by ext constructor · rintro ⟨x, h1, h2⟩ exact ⟨⟨x, h1⟩, h2⟩ · rintro ⟨⟨x, h1⟩, h2⟩ exact ⟨x, h1, h2⟩ theorem _root_.Sum.range_eq (f : α ⊕ β → γ) : range f = range (f ∘ Sum.inl) ∪ range (f ∘ Sum.inr) := ext fun _ => Sum.exists @[simp] theorem Sum.elim_range (f : α → γ) (g : β → γ) : range (Sum.elim f g) = range f ∪ range g := Sum.range_eq _ theorem range_ite_subset' {p : Prop} [Decidable p] {f g : α → β} : range (if p then f else g) ⊆ range f ∪ range g := by by_cases h : p · rw [if_pos h] exact subset_union_left · rw [if_neg h] exact subset_union_right
theorem range_ite_subset {p : α → Prop} [DecidablePred p] {f g : α → β} : (range fun x => if p x then f x else g x) ⊆ range f ∪ range g := by
Mathlib/Data/Set/Image.lean
922
924
/- Copyright (c) 2021 Vladimir Goryachev. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Vladimir Goryachev, Kyle Miller, Kim Morrison, Eric Rodriguez -/ import Mathlib.Algebra.Group.Nat.Range import Mathlib.Data.Set.Finite.Basic /-! # Counting on ℕ This file defines the `count` function, which gives, for any predicate on the natural numbers, "how many numbers under `k` satisfy this predicate?". We then prove several expected lemmas about `count`, relating it to the cardinality of other objects, and helping to evaluate it for specific `k`. -/ assert_not_imported Mathlib.Dynamics.FixedPoints.Basic assert_not_exists Ring open Finset namespace Nat variable (p : ℕ → Prop) section Count variable [DecidablePred p] /-- Count the number of naturals `k < n` satisfying `p k`. -/ def count (n : ℕ) : ℕ := (List.range n).countP p @[simp] theorem count_zero : count p 0 = 0 := by
rw [count, List.range_zero, List.countP, List.countP.go]
Mathlib/Data/Nat/Count.lean
38
39
/- Copyright (c) 2020 Kexing Ying and Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying, Kevin Buzzard, Yury Kudryashov -/ import Mathlib.Algebra.BigOperators.GroupWithZero.Finset import Mathlib.Algebra.BigOperators.Pi import Mathlib.Algebra.Group.FiniteSupport import Mathlib.Algebra.NoZeroSMulDivisors.Basic import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Algebra.Order.Ring.Defs import Mathlib.Data.Set.Finite.Lattice import Mathlib.Data.Set.Subsingleton /-! # Finite products and sums over types and sets We define products and sums over types and subsets of types, with no finiteness hypotheses. All infinite products and sums are defined to be junk values (i.e. one or zero). This approach is sometimes easier to use than `Finset.sum`, when issues arise with `Finset` and `Fintype` being data. ## Main definitions We use the following variables: * `α`, `β` - types with no structure; * `s`, `t` - sets * `M`, `N` - additive or multiplicative commutative monoids * `f`, `g` - functions Definitions in this file: * `finsum f : M` : the sum of `f x` as `x` ranges over the support of `f`, if it's finite. Zero otherwise. * `finprod f : M` : the product of `f x` as `x` ranges over the multiplicative support of `f`, if it's finite. One otherwise. ## Notation * `∑ᶠ i, f i` and `∑ᶠ i : α, f i` for `finsum f` * `∏ᶠ i, f i` and `∏ᶠ i : α, f i` for `finprod f` This notation works for functions `f : p → M`, where `p : Prop`, so the following works: * `∑ᶠ i ∈ s, f i`, where `f : α → M`, `s : Set α` : sum over the set `s`; * `∑ᶠ n < 5, f n`, where `f : ℕ → M` : same as `f 0 + f 1 + f 2 + f 3 + f 4`; * `∏ᶠ (n >= -2) (hn : n < 3), f n`, where `f : ℤ → M` : same as `f (-2) * f (-1) * f 0 * f 1 * f 2`. ## Implementation notes `finsum` and `finprod` is "yet another way of doing finite sums and products in Lean". However experiments in the wild (e.g. with matroids) indicate that it is a helpful approach in settings where the user is not interested in computability and wants to do reasoning without running into typeclass diamonds caused by the constructive finiteness used in definitions such as `Finset` and `Fintype`. By sticking solely to `Set.Finite` we avoid these problems. We are aware that there are other solutions but for beginner mathematicians this approach is easier in practice. Another application is the construction of a partition of unity from a collection of “bump” function. In this case the finite set depends on the point and it's convenient to have a definition that does not mention the set explicitly. The first arguments in all definitions and lemmas is the codomain of the function of the big operator. This is necessary for the heuristic in `@[to_additive]`. See the documentation of `to_additive.attr` for more information. We did not add `IsFinite (X : Type) : Prop`, because it is simply `Nonempty (Fintype X)`. ## Tags finsum, finprod, finite sum, finite product -/ open Function Set /-! ### Definition and relation to `Finset.sum` and `Finset.prod` -/ -- Porting note: Used to be section Sort section sort variable {G M N : Type*} {α β ι : Sort*} [CommMonoid M] [CommMonoid N] section /- Note: we use classical logic only for these definitions, to ensure that we do not write lemmas with `Classical.dec` in their statement. -/ open Classical in /-- Sum of `f x` as `x` ranges over the elements of the support of `f`, if it's finite. Zero otherwise. -/ noncomputable irreducible_def finsum (lemma := finsum_def') [AddCommMonoid M] (f : α → M) : M := if h : (support (f ∘ PLift.down)).Finite then ∑ i ∈ h.toFinset, f i.down else 0 open Classical in /-- Product of `f x` as `x` ranges over the elements of the multiplicative support of `f`, if it's finite. One otherwise. -/ @[to_additive existing] noncomputable irreducible_def finprod (lemma := finprod_def') (f : α → M) : M := if h : (mulSupport (f ∘ PLift.down)).Finite then ∏ i ∈ h.toFinset, f i.down else 1 attribute [to_additive existing] finprod_def' end open Batteries.ExtendedBinder /-- `∑ᶠ x, f x` is notation for `finsum f`. It is the sum of `f x`, where `x` ranges over the support of `f`, if it's finite, zero otherwise. Taking the sum over multiple arguments or conditions is possible, e.g. `∏ᶠ (x) (y), f x y` and `∏ᶠ (x) (h: x ∈ s), f x` -/ notation3"∑ᶠ "(...)", "r:67:(scoped f => finsum f) => r /-- `∏ᶠ x, f x` is notation for `finprod f`. It is the product of `f x`, where `x` ranges over the multiplicative support of `f`, if it's finite, one otherwise. Taking the product over multiple arguments or conditions is possible, e.g. `∏ᶠ (x) (y), f x y` and `∏ᶠ (x) (h: x ∈ s), f x` -/ notation3"∏ᶠ "(...)", "r:67:(scoped f => finprod f) => r -- Porting note: The following ports the lean3 notation for this file, but is currently very fickle. -- syntax (name := bigfinsum) "∑ᶠ" extBinders ", " term:67 : term -- macro_rules (kind := bigfinsum) -- | `(∑ᶠ $x:ident, $p) => `(finsum (fun $x:ident ↦ $p)) -- | `(∑ᶠ $x:ident : $t, $p) => `(finsum (fun $x:ident : $t ↦ $p)) -- | `(∑ᶠ $x:ident $b:binderPred, $p) => -- `(finsum fun $x => (finsum (α := satisfies_binder_pred% $x $b) (fun _ => $p))) -- | `(∑ᶠ ($x:ident) ($h:ident : $t), $p) => -- `(finsum fun ($x) => finsum (α := $t) (fun $h => $p)) -- | `(∑ᶠ ($x:ident : $_) ($h:ident : $t), $p) => -- `(finsum fun ($x) => finsum (α := $t) (fun $h => $p)) -- | `(∑ᶠ ($x:ident) ($y:ident), $p) => -- `(finsum fun $x => (finsum fun $y => $p)) -- | `(∑ᶠ ($x:ident) ($y:ident) ($h:ident : $t), $p) => -- `(finsum fun $x => (finsum fun $y => (finsum (α := $t) fun $h => $p))) -- | `(∑ᶠ ($x:ident) ($y:ident) ($z:ident), $p) => -- `(finsum fun $x => (finsum fun $y => (finsum fun $z => $p))) -- | `(∑ᶠ ($x:ident) ($y:ident) ($z:ident) ($h:ident : $t), $p) => -- `(finsum fun $x => (finsum fun $y => (finsum fun $z => (finsum (α := $t) fun $h => $p)))) -- -- -- syntax (name := bigfinprod) "∏ᶠ " extBinders ", " term:67 : term -- macro_rules (kind := bigfinprod) -- | `(∏ᶠ $x:ident, $p) => `(finprod (fun $x:ident ↦ $p)) -- | `(∏ᶠ $x:ident : $t, $p) => `(finprod (fun $x:ident : $t ↦ $p)) -- | `(∏ᶠ $x:ident $b:binderPred, $p) => -- `(finprod fun $x => (finprod (α := satisfies_binder_pred% $x $b) (fun _ => $p))) -- | `(∏ᶠ ($x:ident) ($h:ident : $t), $p) => -- `(finprod fun ($x) => finprod (α := $t) (fun $h => $p)) -- | `(∏ᶠ ($x:ident : $_) ($h:ident : $t), $p) => -- `(finprod fun ($x) => finprod (α := $t) (fun $h => $p)) -- | `(∏ᶠ ($x:ident) ($y:ident), $p) => -- `(finprod fun $x => (finprod fun $y => $p)) -- | `(∏ᶠ ($x:ident) ($y:ident) ($h:ident : $t), $p) => -- `(finprod fun $x => (finprod fun $y => (finprod (α := $t) fun $h => $p))) -- | `(∏ᶠ ($x:ident) ($y:ident) ($z:ident), $p) => -- `(finprod fun $x => (finprod fun $y => (finprod fun $z => $p))) -- | `(∏ᶠ ($x:ident) ($y:ident) ($z:ident) ($h:ident : $t), $p) => -- `(finprod fun $x => (finprod fun $y => (finprod fun $z => -- (finprod (α := $t) fun $h => $p)))) @[to_additive] theorem finprod_eq_prod_plift_of_mulSupport_toFinset_subset {f : α → M} (hf : (mulSupport (f ∘ PLift.down)).Finite) {s : Finset (PLift α)} (hs : hf.toFinset ⊆ s) : ∏ᶠ i, f i = ∏ i ∈ s, f i.down := by rw [finprod, dif_pos] refine Finset.prod_subset hs fun x _ hxf => ?_ rwa [hf.mem_toFinset, nmem_mulSupport] at hxf @[to_additive] theorem finprod_eq_prod_plift_of_mulSupport_subset {f : α → M} {s : Finset (PLift α)} (hs : mulSupport (f ∘ PLift.down) ⊆ s) : ∏ᶠ i, f i = ∏ i ∈ s, f i.down := finprod_eq_prod_plift_of_mulSupport_toFinset_subset (s.finite_toSet.subset hs) fun x hx => by rw [Finite.mem_toFinset] at hx exact hs hx @[to_additive (attr := simp)] theorem finprod_one : (∏ᶠ _ : α, (1 : M)) = 1 := by have : (mulSupport fun x : PLift α => (fun _ => 1 : α → M) x.down) ⊆ (∅ : Finset (PLift α)) := fun x h => by simp at h rw [finprod_eq_prod_plift_of_mulSupport_subset this, Finset.prod_empty] @[to_additive] theorem finprod_of_isEmpty [IsEmpty α] (f : α → M) : ∏ᶠ i, f i = 1 := by rw [← finprod_one] congr simp [eq_iff_true_of_subsingleton] @[to_additive (attr := simp)] theorem finprod_false (f : False → M) : ∏ᶠ i, f i = 1 := finprod_of_isEmpty _ @[to_additive] theorem finprod_eq_single (f : α → M) (a : α) (ha : ∀ x, x ≠ a → f x = 1) : ∏ᶠ x, f x = f a := by have : mulSupport (f ∘ PLift.down) ⊆ ({PLift.up a} : Finset (PLift α)) := by intro x contrapose simpa [PLift.eq_up_iff_down_eq] using ha x.down rw [finprod_eq_prod_plift_of_mulSupport_subset this, Finset.prod_singleton] @[to_additive] theorem finprod_unique [Unique α] (f : α → M) : ∏ᶠ i, f i = f default := finprod_eq_single f default fun _x hx => (hx <| Unique.eq_default _).elim @[to_additive (attr := simp)] theorem finprod_true (f : True → M) : ∏ᶠ i, f i = f trivial := @finprod_unique M True _ ⟨⟨trivial⟩, fun _ => rfl⟩ f @[to_additive] theorem finprod_eq_dif {p : Prop} [Decidable p] (f : p → M) : ∏ᶠ i, f i = if h : p then f h else 1 := by split_ifs with h · haveI : Unique p := ⟨⟨h⟩, fun _ => rfl⟩ exact finprod_unique f · haveI : IsEmpty p := ⟨h⟩ exact finprod_of_isEmpty f @[to_additive] theorem finprod_eq_if {p : Prop} [Decidable p] {x : M} : ∏ᶠ _ : p, x = if p then x else 1 := finprod_eq_dif fun _ => x @[to_additive] theorem finprod_congr {f g : α → M} (h : ∀ x, f x = g x) : finprod f = finprod g := congr_arg _ <| funext h @[to_additive (attr := congr)] theorem finprod_congr_Prop {p q : Prop} {f : p → M} {g : q → M} (hpq : p = q) (hfg : ∀ h : q, f (hpq.mpr h) = g h) : finprod f = finprod g := by subst q exact finprod_congr hfg /-- To prove a property of a finite product, it suffices to prove that the property is multiplicative and holds on the factors. -/ @[to_additive "To prove a property of a finite sum, it suffices to prove that the property is additive and holds on the summands."] theorem finprod_induction {f : α → M} (p : M → Prop) (hp₀ : p 1) (hp₁ : ∀ x y, p x → p y → p (x * y)) (hp₂ : ∀ i, p (f i)) : p (∏ᶠ i, f i) := by rw [finprod] split_ifs exacts [Finset.prod_induction _ _ hp₁ hp₀ fun i _ => hp₂ _, hp₀] theorem finprod_nonneg {R : Type*} [CommSemiring R] [PartialOrder R] [IsOrderedRing R] {f : α → R} (hf : ∀ x, 0 ≤ f x) : 0 ≤ ∏ᶠ x, f x := finprod_induction (fun x => 0 ≤ x) zero_le_one (fun _ _ => mul_nonneg) hf @[to_additive finsum_nonneg] theorem one_le_finprod' {M : Type*} [CommMonoid M] [PartialOrder M] [IsOrderedMonoid M] {f : α → M} (hf : ∀ i, 1 ≤ f i) : 1 ≤ ∏ᶠ i, f i := finprod_induction _ le_rfl (fun _ _ => one_le_mul) hf @[to_additive] theorem MonoidHom.map_finprod_plift (f : M →* N) (g : α → M) (h : (mulSupport <| g ∘ PLift.down).Finite) : f (∏ᶠ x, g x) = ∏ᶠ x, f (g x) := by rw [finprod_eq_prod_plift_of_mulSupport_subset h.coe_toFinset.ge, finprod_eq_prod_plift_of_mulSupport_subset, map_prod] rw [h.coe_toFinset] exact mulSupport_comp_subset f.map_one (g ∘ PLift.down) @[to_additive] theorem MonoidHom.map_finprod_Prop {p : Prop} (f : M →* N) (g : p → M) : f (∏ᶠ x, g x) = ∏ᶠ x, f (g x) := f.map_finprod_plift g (Set.toFinite _) @[to_additive] theorem MonoidHom.map_finprod_of_preimage_one (f : M →* N) (hf : ∀ x, f x = 1 → x = 1) (g : α → M) : f (∏ᶠ i, g i) = ∏ᶠ i, f (g i) := by by_cases hg : (mulSupport <| g ∘ PLift.down).Finite; · exact f.map_finprod_plift g hg rw [finprod, dif_neg, f.map_one, finprod, dif_neg] exacts [Infinite.mono (fun x hx => mt (hf (g x.down)) hx) hg, hg] @[to_additive] theorem MonoidHom.map_finprod_of_injective (g : M →* N) (hg : Injective g) (f : α → M) : g (∏ᶠ i, f i) = ∏ᶠ i, g (f i) := g.map_finprod_of_preimage_one (fun _ => (hg.eq_iff' g.map_one).mp) f @[to_additive] theorem MulEquiv.map_finprod (g : M ≃* N) (f : α → M) : g (∏ᶠ i, f i) = ∏ᶠ i, g (f i) := g.toMonoidHom.map_finprod_of_injective (EquivLike.injective g) f @[to_additive] theorem MulEquivClass.map_finprod {F : Type*} [EquivLike F M N] [MulEquivClass F M N] (g : F) (f : α → M) : g (∏ᶠ i, f i) = ∏ᶠ i, g (f i) := MulEquiv.map_finprod (MulEquivClass.toMulEquiv g) f /-- The `NoZeroSMulDivisors` makes sure that the result holds even when the support of `f` is infinite. For a more usual version assuming `(support f).Finite` instead, see `finsum_smul'`. -/ theorem finsum_smul {R M : Type*} [Ring R] [AddCommGroup M] [Module R M] [NoZeroSMulDivisors R M] (f : ι → R) (x : M) : (∑ᶠ i, f i) • x = ∑ᶠ i, f i • x := by rcases eq_or_ne x 0 with (rfl | hx) · simp · exact ((smulAddHom R M).flip x).map_finsum_of_injective (smul_left_injective R hx) _ /-- The `NoZeroSMulDivisors` makes sure that the result holds even when the support of `f` is infinite. For a more usual version assuming `(support f).Finite` instead, see `smul_finsum'`. -/ theorem smul_finsum {R M : Type*} [Semiring R] [AddCommGroup M] [Module R M] [NoZeroSMulDivisors R M] (c : R) (f : ι → M) : (c • ∑ᶠ i, f i) = ∑ᶠ i, c • f i := by rcases eq_or_ne c 0 with (rfl | hc) · simp · exact (smulAddHom R M c).map_finsum_of_injective (smul_right_injective M hc) _ @[to_additive] theorem finprod_inv_distrib [DivisionCommMonoid G] (f : α → G) : (∏ᶠ x, (f x)⁻¹) = (∏ᶠ x, f x)⁻¹ := ((MulEquiv.inv G).map_finprod f).symm end sort -- Porting note: Used to be section Type section type variable {α β ι G M N : Type*} [CommMonoid M] [CommMonoid N] @[to_additive] theorem finprod_eq_mulIndicator_apply (s : Set α) (f : α → M) (a : α) : ∏ᶠ _ : a ∈ s, f a = mulIndicator s f a := by classical convert finprod_eq_if (M := M) (p := a ∈ s) (x := f a) @[to_additive (attr := simp)] theorem finprod_apply_ne_one (f : α → M) (a : α) : ∏ᶠ _ : f a ≠ 1, f a = f a := by rw [← mem_mulSupport, finprod_eq_mulIndicator_apply, mulIndicator_mulSupport] @[to_additive] theorem finprod_mem_def (s : Set α) (f : α → M) : ∏ᶠ a ∈ s, f a = ∏ᶠ a, mulIndicator s f a := finprod_congr <| finprod_eq_mulIndicator_apply s f @[to_additive] lemma finprod_mem_mulSupport (f : α → M) : ∏ᶠ a ∈ mulSupport f, f a = ∏ᶠ a, f a := by rw [finprod_mem_def, mulIndicator_mulSupport] @[to_additive] theorem finprod_eq_prod_of_mulSupport_subset (f : α → M) {s : Finset α} (h : mulSupport f ⊆ s) : ∏ᶠ i, f i = ∏ i ∈ s, f i := by have A : mulSupport (f ∘ PLift.down) = Equiv.plift.symm '' mulSupport f := by rw [mulSupport_comp_eq_preimage] exact (Equiv.plift.symm.image_eq_preimage _).symm have : mulSupport (f ∘ PLift.down) ⊆ s.map Equiv.plift.symm.toEmbedding := by rw [A, Finset.coe_map] exact image_subset _ h rw [finprod_eq_prod_plift_of_mulSupport_subset this] simp only [Finset.prod_map, Equiv.coe_toEmbedding] congr @[to_additive] theorem finprod_eq_prod_of_mulSupport_toFinset_subset (f : α → M) (hf : (mulSupport f).Finite) {s : Finset α} (h : hf.toFinset ⊆ s) : ∏ᶠ i, f i = ∏ i ∈ s, f i := finprod_eq_prod_of_mulSupport_subset _ fun _ hx => h <| hf.mem_toFinset.2 hx @[to_additive] theorem finprod_eq_finset_prod_of_mulSupport_subset (f : α → M) {s : Finset α} (h : mulSupport f ⊆ (s : Set α)) : ∏ᶠ i, f i = ∏ i ∈ s, f i := haveI h' : (s.finite_toSet.subset h).toFinset ⊆ s := by simpa [← Finset.coe_subset, Set.coe_toFinset] finprod_eq_prod_of_mulSupport_toFinset_subset _ _ h' @[to_additive] theorem finprod_def (f : α → M) [Decidable (mulSupport f).Finite] : ∏ᶠ i : α, f i = if h : (mulSupport f).Finite then ∏ i ∈ h.toFinset, f i else 1 := by split_ifs with h · exact finprod_eq_prod_of_mulSupport_toFinset_subset _ h (Finset.Subset.refl _) · rw [finprod, dif_neg] rw [mulSupport_comp_eq_preimage] exact mt (fun hf => hf.of_preimage Equiv.plift.surjective) h @[to_additive] theorem finprod_of_infinite_mulSupport {f : α → M} (hf : (mulSupport f).Infinite) : ∏ᶠ i, f i = 1 := by classical rw [finprod_def, dif_neg hf] @[to_additive] theorem finprod_eq_prod (f : α → M) (hf : (mulSupport f).Finite) : ∏ᶠ i : α, f i = ∏ i ∈ hf.toFinset, f i := by classical rw [finprod_def, dif_pos hf] @[to_additive] theorem finprod_eq_prod_of_fintype [Fintype α] (f : α → M) : ∏ᶠ i : α, f i = ∏ i, f i := finprod_eq_prod_of_mulSupport_toFinset_subset _ (Set.toFinite _) <| Finset.subset_univ _ @[to_additive] theorem map_finset_prod {α F : Type*} [Fintype α] [EquivLike F M N] [MulEquivClass F M N] (f : F) (g : α → M) : f (∏ i : α, g i) = ∏ i : α, f (g i) := by simp [← finprod_eq_prod_of_fintype, MulEquivClass.map_finprod] @[to_additive] theorem finprod_cond_eq_prod_of_cond_iff (f : α → M) {p : α → Prop} {t : Finset α} (h : ∀ {x}, f x ≠ 1 → (p x ↔ x ∈ t)) : (∏ᶠ (i) (_ : p i), f i) = ∏ i ∈ t, f i := by set s := { x | p x } change ∏ᶠ (i : α) (_ : i ∈ s), f i = ∏ i ∈ t, f i have : mulSupport (s.mulIndicator f) ⊆ t := by rw [Set.mulSupport_mulIndicator] intro x hx exact (h hx.2).1 hx.1 rw [finprod_mem_def, finprod_eq_prod_of_mulSupport_subset _ this] refine Finset.prod_congr rfl fun x hx => mulIndicator_apply_eq_self.2 fun hxs => ?_ contrapose! hxs exact (h hxs).2 hx @[to_additive] theorem finprod_cond_ne (f : α → M) (a : α) [DecidableEq α] (hf : (mulSupport f).Finite) : (∏ᶠ (i) (_ : i ≠ a), f i) = ∏ i ∈ hf.toFinset.erase a, f i := by apply finprod_cond_eq_prod_of_cond_iff intro x hx rw [Finset.mem_erase, Finite.mem_toFinset, mem_mulSupport] exact ⟨fun h => And.intro h hx, fun h => h.1⟩ @[to_additive] theorem finprod_mem_eq_prod_of_inter_mulSupport_eq (f : α → M) {s : Set α} {t : Finset α} (h : s ∩ mulSupport f = t.toSet ∩ mulSupport f) : ∏ᶠ i ∈ s, f i = ∏ i ∈ t, f i := finprod_cond_eq_prod_of_cond_iff _ <| by intro x hxf rw [← mem_mulSupport] at hxf refine ⟨fun hx => ?_, fun hx => ?_⟩ · refine ((mem_inter_iff x t (mulSupport f)).mp ?_).1 rw [← Set.ext_iff.mp h x, mem_inter_iff] exact ⟨hx, hxf⟩ · refine ((mem_inter_iff x s (mulSupport f)).mp ?_).1 rw [Set.ext_iff.mp h x, mem_inter_iff] exact ⟨hx, hxf⟩ @[to_additive] theorem finprod_mem_eq_prod_of_subset (f : α → M) {s : Set α} {t : Finset α} (h₁ : s ∩ mulSupport f ⊆ t) (h₂ : ↑t ⊆ s) : ∏ᶠ i ∈ s, f i = ∏ i ∈ t, f i := finprod_cond_eq_prod_of_cond_iff _ fun hx => ⟨fun h => h₁ ⟨h, hx⟩, fun h => h₂ h⟩ @[to_additive] theorem finprod_mem_eq_prod (f : α → M) {s : Set α} (hf : (s ∩ mulSupport f).Finite) : ∏ᶠ i ∈ s, f i = ∏ i ∈ hf.toFinset, f i := finprod_mem_eq_prod_of_inter_mulSupport_eq _ <| by simp [inter_assoc] @[to_additive] theorem finprod_mem_eq_prod_filter (f : α → M) (s : Set α) [DecidablePred (· ∈ s)] (hf : (mulSupport f).Finite) : ∏ᶠ i ∈ s, f i = ∏ i ∈ hf.toFinset with i ∈ s, f i := finprod_mem_eq_prod_of_inter_mulSupport_eq _ <| by ext x simp [and_comm] @[to_additive] theorem finprod_mem_eq_toFinset_prod (f : α → M) (s : Set α) [Fintype s] : ∏ᶠ i ∈ s, f i = ∏ i ∈ s.toFinset, f i := finprod_mem_eq_prod_of_inter_mulSupport_eq _ <| by simp_rw [coe_toFinset s] @[to_additive] theorem finprod_mem_eq_finite_toFinset_prod (f : α → M) {s : Set α} (hs : s.Finite) : ∏ᶠ i ∈ s, f i = ∏ i ∈ hs.toFinset, f i := finprod_mem_eq_prod_of_inter_mulSupport_eq _ <| by rw [hs.coe_toFinset] @[to_additive] theorem finprod_mem_finset_eq_prod (f : α → M) (s : Finset α) : ∏ᶠ i ∈ s, f i = ∏ i ∈ s, f i := finprod_mem_eq_prod_of_inter_mulSupport_eq _ rfl @[to_additive] theorem finprod_mem_coe_finset (f : α → M) (s : Finset α) : (∏ᶠ i ∈ (s : Set α), f i) = ∏ i ∈ s, f i := finprod_mem_eq_prod_of_inter_mulSupport_eq _ rfl @[to_additive] theorem finprod_mem_eq_one_of_infinite {f : α → M} {s : Set α} (hs : (s ∩ mulSupport f).Infinite) : ∏ᶠ i ∈ s, f i = 1 := by rw [finprod_mem_def] apply finprod_of_infinite_mulSupport rwa [← mulSupport_mulIndicator] at hs @[to_additive] theorem finprod_mem_eq_one_of_forall_eq_one {f : α → M} {s : Set α} (h : ∀ x ∈ s, f x = 1) : ∏ᶠ i ∈ s, f i = 1 := by simp +contextual [h] @[to_additive] theorem finprod_mem_inter_mulSupport (f : α → M) (s : Set α) : ∏ᶠ i ∈ s ∩ mulSupport f, f i = ∏ᶠ i ∈ s, f i := by rw [finprod_mem_def, finprod_mem_def, mulIndicator_inter_mulSupport] @[to_additive] theorem finprod_mem_inter_mulSupport_eq (f : α → M) (s t : Set α) (h : s ∩ mulSupport f = t ∩ mulSupport f) : ∏ᶠ i ∈ s, f i = ∏ᶠ i ∈ t, f i := by rw [← finprod_mem_inter_mulSupport, h, finprod_mem_inter_mulSupport] @[to_additive] theorem finprod_mem_inter_mulSupport_eq' (f : α → M) (s t : Set α) (h : ∀ x ∈ mulSupport f, x ∈ s ↔ x ∈ t) : ∏ᶠ i ∈ s, f i = ∏ᶠ i ∈ t, f i := by apply finprod_mem_inter_mulSupport_eq ext x exact and_congr_left (h x) @[to_additive] theorem finprod_mem_univ (f : α → M) : ∏ᶠ i ∈ @Set.univ α, f i = ∏ᶠ i : α, f i := finprod_congr fun _ => finprod_true _ variable {f g : α → M} {a b : α} {s t : Set α} @[to_additive] theorem finprod_mem_congr (h₀ : s = t) (h₁ : ∀ x ∈ t, f x = g x) : ∏ᶠ i ∈ s, f i = ∏ᶠ i ∈ t, g i := h₀.symm ▸ finprod_congr fun i => finprod_congr_Prop rfl (h₁ i) @[to_additive] theorem finprod_eq_one_of_forall_eq_one {f : α → M} (h : ∀ x, f x = 1) : ∏ᶠ i, f i = 1 := by simp +contextual [h] @[to_additive finsum_pos'] theorem one_lt_finprod' {M : Type*} [CommMonoid M] [PartialOrder M] [IsOrderedCancelMonoid M] {f : ι → M} (h : ∀ i, 1 ≤ f i) (h' : ∃ i, 1 < f i) (hf : (mulSupport f).Finite) : 1 < ∏ᶠ i, f i := by rcases h' with ⟨i, hi⟩ rw [finprod_eq_prod _ hf] refine Finset.one_lt_prod' (fun i _ ↦ h i) ⟨i, ?_, hi⟩ simpa only [Finite.mem_toFinset, mem_mulSupport] using ne_of_gt hi /-! ### Distributivity w.r.t. addition, subtraction, and (scalar) multiplication -/ /-- If the multiplicative supports of `f` and `g` are finite, then the product of `f i * g i` equals the product of `f i` multiplied by the product of `g i`. -/ @[to_additive "If the additive supports of `f` and `g` are finite, then the sum of `f i + g i` equals the sum of `f i` plus the sum of `g i`."] theorem finprod_mul_distrib (hf : (mulSupport f).Finite) (hg : (mulSupport g).Finite) : ∏ᶠ i, f i * g i = (∏ᶠ i, f i) * ∏ᶠ i, g i := by classical rw [finprod_eq_prod_of_mulSupport_toFinset_subset f hf Finset.subset_union_left, finprod_eq_prod_of_mulSupport_toFinset_subset g hg Finset.subset_union_right, ← Finset.prod_mul_distrib] refine finprod_eq_prod_of_mulSupport_subset _ ?_ simp only [Finset.coe_union, Finite.coe_toFinset, mulSupport_subset_iff, mem_union, mem_mulSupport] intro x contrapose! rintro ⟨hf, hg⟩ simp [hf, hg] /-- If the multiplicative supports of `f` and `g` are finite, then the product of `f i / g i` equals the product of `f i` divided by the product of `g i`. -/ @[to_additive "If the additive supports of `f` and `g` are finite, then the sum of `f i - g i` equals the sum of `f i` minus the sum of `g i`."] theorem finprod_div_distrib [DivisionCommMonoid G] {f g : α → G} (hf : (mulSupport f).Finite) (hg : (mulSupport g).Finite) : ∏ᶠ i, f i / g i = (∏ᶠ i, f i) / ∏ᶠ i, g i := by simp only [div_eq_mul_inv, finprod_mul_distrib hf ((mulSupport_inv g).symm.rec hg), finprod_inv_distrib] /-- A more general version of `finprod_mem_mul_distrib` that only requires `s ∩ mulSupport f` and `s ∩ mulSupport g` rather than `s` to be finite. -/ @[to_additive "A more general version of `finsum_mem_add_distrib` that only requires `s ∩ support f` and `s ∩ support g` rather than `s` to be finite."] theorem finprod_mem_mul_distrib' (hf : (s ∩ mulSupport f).Finite) (hg : (s ∩ mulSupport g).Finite) : ∏ᶠ i ∈ s, f i * g i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ s, g i := by rw [← mulSupport_mulIndicator] at hf hg simp only [finprod_mem_def, mulIndicator_mul, finprod_mul_distrib hf hg] /-- The product of the constant function `1` over any set equals `1`. -/ @[to_additive "The sum of the constant function `0` over any set equals `0`."] theorem finprod_mem_one (s : Set α) : (∏ᶠ i ∈ s, (1 : M)) = 1 := by simp /-- If a function `f` equals `1` on a set `s`, then the product of `f i` over `i ∈ s` equals `1`. -/ @[to_additive "If a function `f` equals `0` on a set `s`, then the product of `f i` over `i ∈ s` equals `0`."] theorem finprod_mem_of_eqOn_one (hf : s.EqOn f 1) : ∏ᶠ i ∈ s, f i = 1 := by rw [← finprod_mem_one s] exact finprod_mem_congr rfl hf /-- If the product of `f i` over `i ∈ s` is not equal to `1`, then there is some `x ∈ s` such that `f x ≠ 1`. -/ @[to_additive "If the product of `f i` over `i ∈ s` is not equal to `0`, then there is some `x ∈ s` such that `f x ≠ 0`."] theorem exists_ne_one_of_finprod_mem_ne_one (h : ∏ᶠ i ∈ s, f i ≠ 1) : ∃ x ∈ s, f x ≠ 1 := by by_contra! h' exact h (finprod_mem_of_eqOn_one h') /-- Given a finite set `s`, the product of `f i * g i` over `i ∈ s` equals the product of `f i` over `i ∈ s` times the product of `g i` over `i ∈ s`. -/ @[to_additive "Given a finite set `s`, the sum of `f i + g i` over `i ∈ s` equals the sum of `f i` over `i ∈ s` plus the sum of `g i` over `i ∈ s`."] theorem finprod_mem_mul_distrib (hs : s.Finite) : ∏ᶠ i ∈ s, f i * g i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ s, g i := finprod_mem_mul_distrib' (hs.inter_of_left _) (hs.inter_of_left _) @[to_additive] theorem MonoidHom.map_finprod {f : α → M} (g : M →* N) (hf : (mulSupport f).Finite) : g (∏ᶠ i, f i) = ∏ᶠ i, g (f i) := g.map_finprod_plift f <| hf.preimage Equiv.plift.injective.injOn @[to_additive] theorem finprod_pow (hf : (mulSupport f).Finite) (n : ℕ) : (∏ᶠ i, f i) ^ n = ∏ᶠ i, f i ^ n := (powMonoidHom n).map_finprod hf /-- See also `finsum_smul` for a version that works even when the support of `f` is not finite, but with slightly stronger typeclass requirements. -/ theorem finsum_smul' {R M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] {f : ι → R} (hf : (support f).Finite) (x : M) : (∑ᶠ i, f i) • x = ∑ᶠ i, f i • x := ((smulAddHom R M).flip x).map_finsum hf /-- See also `smul_finsum` for a version that works even when the support of `f` is not finite, but with slightly stronger typeclass requirements. -/ theorem smul_finsum' {R M : Type*} [Monoid R] [AddCommMonoid M] [DistribMulAction R M] (c : R) {f : ι → M} (hf : (support f).Finite) : (c • ∑ᶠ i, f i) = ∑ᶠ i, c • f i := (DistribMulAction.toAddMonoidHom M c).map_finsum hf /-- A more general version of `MonoidHom.map_finprod_mem` that requires `s ∩ mulSupport f` rather than `s` to be finite. -/ @[to_additive "A more general version of `AddMonoidHom.map_finsum_mem` that requires `s ∩ support f` rather than `s` to be finite."] theorem MonoidHom.map_finprod_mem' {f : α → M} (g : M →* N) (h₀ : (s ∩ mulSupport f).Finite) : g (∏ᶠ j ∈ s, f j) = ∏ᶠ i ∈ s, g (f i) := by rw [g.map_finprod] · simp only [g.map_finprod_Prop] · simpa only [finprod_eq_mulIndicator_apply, mulSupport_mulIndicator] /-- Given a monoid homomorphism `g : M →* N` and a function `f : α → M`, the value of `g` at the product of `f i` over `i ∈ s` equals the product of `g (f i)` over `s`. -/ @[to_additive "Given an additive monoid homomorphism `g : M →* N` and a function `f : α → M`, the value of `g` at the sum of `f i` over `i ∈ s` equals the sum of `g (f i)` over `s`."] theorem MonoidHom.map_finprod_mem (f : α → M) (g : M →* N) (hs : s.Finite) : g (∏ᶠ j ∈ s, f j) = ∏ᶠ i ∈ s, g (f i) := g.map_finprod_mem' (hs.inter_of_left _) @[to_additive] theorem MulEquiv.map_finprod_mem (g : M ≃* N) (f : α → M) {s : Set α} (hs : s.Finite) : g (∏ᶠ i ∈ s, f i) = ∏ᶠ i ∈ s, g (f i) := g.toMonoidHom.map_finprod_mem f hs @[to_additive] theorem finprod_mem_inv_distrib [DivisionCommMonoid G] (f : α → G) (hs : s.Finite) : (∏ᶠ x ∈ s, (f x)⁻¹) = (∏ᶠ x ∈ s, f x)⁻¹ := ((MulEquiv.inv G).map_finprod_mem f hs).symm /-- Given a finite set `s`, the product of `f i / g i` over `i ∈ s` equals the product of `f i` over `i ∈ s` divided by the product of `g i` over `i ∈ s`. -/ @[to_additive "Given a finite set `s`, the sum of `f i / g i` over `i ∈ s` equals the sum of `f i` over `i ∈ s` minus the sum of `g i` over `i ∈ s`."] theorem finprod_mem_div_distrib [DivisionCommMonoid G] (f g : α → G) (hs : s.Finite) : ∏ᶠ i ∈ s, f i / g i = (∏ᶠ i ∈ s, f i) / ∏ᶠ i ∈ s, g i := by simp only [div_eq_mul_inv, finprod_mem_mul_distrib hs, finprod_mem_inv_distrib g hs] /-! ### `∏ᶠ x ∈ s, f x` and set operations -/ /-- The product of any function over an empty set is `1`. -/ @[to_additive "The sum of any function over an empty set is `0`."] theorem finprod_mem_empty : (∏ᶠ i ∈ (∅ : Set α), f i) = 1 := by simp /-- A set `s` is nonempty if the product of some function over `s` is not equal to `1`. -/ @[to_additive "A set `s` is nonempty if the sum of some function over `s` is not equal to `0`."] theorem nonempty_of_finprod_mem_ne_one (h : ∏ᶠ i ∈ s, f i ≠ 1) : s.Nonempty := nonempty_iff_ne_empty.2 fun h' => h <| h'.symm ▸ finprod_mem_empty /-- Given finite sets `s` and `t`, the product of `f i` over `i ∈ s ∪ t` times the product of `f i` over `i ∈ s ∩ t` equals the product of `f i` over `i ∈ s` times the product of `f i` over `i ∈ t`. -/ @[to_additive "Given finite sets `s` and `t`, the sum of `f i` over `i ∈ s ∪ t` plus the sum of `f i` over `i ∈ s ∩ t` equals the sum of `f i` over `i ∈ s` plus the sum of `f i` over `i ∈ t`."] theorem finprod_mem_union_inter (hs : s.Finite) (ht : t.Finite) : ((∏ᶠ i ∈ s ∪ t, f i) * ∏ᶠ i ∈ s ∩ t, f i) = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i := by lift s to Finset α using hs; lift t to Finset α using ht classical rw [← Finset.coe_union, ← Finset.coe_inter] simp only [finprod_mem_coe_finset, Finset.prod_union_inter] /-- A more general version of `finprod_mem_union_inter` that requires `s ∩ mulSupport f` and `t ∩ mulSupport f` rather than `s` and `t` to be finite. -/ @[to_additive "A more general version of `finsum_mem_union_inter` that requires `s ∩ support f` and `t ∩ support f` rather than `s` and `t` to be finite."] theorem finprod_mem_union_inter' (hs : (s ∩ mulSupport f).Finite) (ht : (t ∩ mulSupport f).Finite) : ((∏ᶠ i ∈ s ∪ t, f i) * ∏ᶠ i ∈ s ∩ t, f i) = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i := by rw [← finprod_mem_inter_mulSupport f s, ← finprod_mem_inter_mulSupport f t, ← finprod_mem_union_inter hs ht, ← union_inter_distrib_right, finprod_mem_inter_mulSupport, ← finprod_mem_inter_mulSupport f (s ∩ t)] congr 2 rw [inter_left_comm, inter_assoc, inter_assoc, inter_self, inter_left_comm] /-- A more general version of `finprod_mem_union` that requires `s ∩ mulSupport f` and `t ∩ mulSupport f` rather than `s` and `t` to be finite. -/ @[to_additive "A more general version of `finsum_mem_union` that requires `s ∩ support f` and `t ∩ support f` rather than `s` and `t` to be finite."] theorem finprod_mem_union' (hst : Disjoint s t) (hs : (s ∩ mulSupport f).Finite) (ht : (t ∩ mulSupport f).Finite) : ∏ᶠ i ∈ s ∪ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i := by rw [← finprod_mem_union_inter' hs ht, disjoint_iff_inter_eq_empty.1 hst, finprod_mem_empty, mul_one] /-- Given two finite disjoint sets `s` and `t`, the product of `f i` over `i ∈ s ∪ t` equals the product of `f i` over `i ∈ s` times the product of `f i` over `i ∈ t`. -/ @[to_additive "Given two finite disjoint sets `s` and `t`, the sum of `f i` over `i ∈ s ∪ t` equals the sum of `f i` over `i ∈ s` plus the sum of `f i` over `i ∈ t`."] theorem finprod_mem_union (hst : Disjoint s t) (hs : s.Finite) (ht : t.Finite) : ∏ᶠ i ∈ s ∪ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i := finprod_mem_union' hst (hs.inter_of_left _) (ht.inter_of_left _) /-- A more general version of `finprod_mem_union'` that requires `s ∩ mulSupport f` and `t ∩ mulSupport f` rather than `s` and `t` to be disjoint -/ @[to_additive "A more general version of `finsum_mem_union'` that requires `s ∩ support f` and `t ∩ support f` rather than `s` and `t` to be disjoint"] theorem finprod_mem_union'' (hst : Disjoint (s ∩ mulSupport f) (t ∩ mulSupport f)) (hs : (s ∩ mulSupport f).Finite) (ht : (t ∩ mulSupport f).Finite) : ∏ᶠ i ∈ s ∪ t, f i = (∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t, f i := by rw [← finprod_mem_inter_mulSupport f s, ← finprod_mem_inter_mulSupport f t, ← finprod_mem_union hst hs ht, ← union_inter_distrib_right, finprod_mem_inter_mulSupport] /-- The product of `f i` over `i ∈ {a}` equals `f a`. -/ @[to_additive "The sum of `f i` over `i ∈ {a}` equals `f a`."] theorem finprod_mem_singleton : (∏ᶠ i ∈ ({a} : Set α), f i) = f a := by rw [← Finset.coe_singleton, finprod_mem_coe_finset, Finset.prod_singleton] @[to_additive (attr := simp)] theorem finprod_cond_eq_left : (∏ᶠ (i) (_ : i = a), f i) = f a := finprod_mem_singleton @[to_additive (attr := simp)] theorem finprod_cond_eq_right : (∏ᶠ (i) (_ : a = i), f i) = f a := by simp [@eq_comm _ a] /-- A more general version of `finprod_mem_insert` that requires `s ∩ mulSupport f` rather than `s` to be finite. -/ @[to_additive "A more general version of `finsum_mem_insert` that requires `s ∩ support f` rather than `s` to be finite."] theorem finprod_mem_insert' (f : α → M) (h : a ∉ s) (hs : (s ∩ mulSupport f).Finite) : ∏ᶠ i ∈ insert a s, f i = f a * ∏ᶠ i ∈ s, f i := by rw [insert_eq, finprod_mem_union' _ _ hs, finprod_mem_singleton] · rwa [disjoint_singleton_left] · exact (finite_singleton a).inter_of_left _ /-- Given a finite set `s` and an element `a ∉ s`, the product of `f i` over `i ∈ insert a s` equals `f a` times the product of `f i` over `i ∈ s`. -/ @[to_additive "Given a finite set `s` and an element `a ∉ s`, the sum of `f i` over `i ∈ insert a s` equals `f a` plus the sum of `f i` over `i ∈ s`."] theorem finprod_mem_insert (f : α → M) (h : a ∉ s) (hs : s.Finite) : ∏ᶠ i ∈ insert a s, f i = f a * ∏ᶠ i ∈ s, f i := finprod_mem_insert' f h <| hs.inter_of_left _ /-- If `f a = 1` when `a ∉ s`, then the product of `f i` over `i ∈ insert a s` equals the product of `f i` over `i ∈ s`. -/ @[to_additive "If `f a = 0` when `a ∉ s`, then the sum of `f i` over `i ∈ insert a s` equals the sum of `f i` over `i ∈ s`."] theorem finprod_mem_insert_of_eq_one_if_not_mem (h : a ∉ s → f a = 1) : ∏ᶠ i ∈ insert a s, f i = ∏ᶠ i ∈ s, f i := by refine finprod_mem_inter_mulSupport_eq' _ _ _ fun x hx => ⟨?_, Or.inr⟩ rintro (rfl | hxs) exacts [not_imp_comm.1 h hx, hxs] /-- If `f a = 1`, then the product of `f i` over `i ∈ insert a s` equals the product of `f i` over `i ∈ s`. -/ @[to_additive "If `f a = 0`, then the sum of `f i` over `i ∈ insert a s` equals the sum of `f i` over `i ∈ s`."] theorem finprod_mem_insert_one (h : f a = 1) : ∏ᶠ i ∈ insert a s, f i = ∏ᶠ i ∈ s, f i := finprod_mem_insert_of_eq_one_if_not_mem fun _ => h /-- If the multiplicative support of `f` is finite, then for every `x` in the domain of `f`, `f x` divides `finprod f`. -/ theorem finprod_mem_dvd {f : α → N} (a : α) (hf : (mulSupport f).Finite) : f a ∣ finprod f := by by_cases ha : a ∈ mulSupport f · rw [finprod_eq_prod_of_mulSupport_toFinset_subset f hf (Set.Subset.refl _)] exact Finset.dvd_prod_of_mem f ((Finite.mem_toFinset hf).mpr ha) · rw [nmem_mulSupport.mp ha] exact one_dvd (finprod f) /-- The product of `f i` over `i ∈ {a, b}`, `a ≠ b`, is equal to `f a * f b`. -/ @[to_additive "The sum of `f i` over `i ∈ {a, b}`, `a ≠ b`, is equal to `f a + f b`."] theorem finprod_mem_pair (h : a ≠ b) : (∏ᶠ i ∈ ({a, b} : Set α), f i) = f a * f b := by rw [finprod_mem_insert, finprod_mem_singleton] exacts [h, finite_singleton b] /-- The product of `f y` over `y ∈ g '' s` equals the product of `f (g i)` over `s` provided that `g` is injective on `s ∩ mulSupport (f ∘ g)`. -/ @[to_additive "The sum of `f y` over `y ∈ g '' s` equals the sum of `f (g i)` over `s` provided that `g` is injective on `s ∩ support (f ∘ g)`."] theorem finprod_mem_image' {s : Set β} {g : β → α} (hg : (s ∩ mulSupport (f ∘ g)).InjOn g) : ∏ᶠ i ∈ g '' s, f i = ∏ᶠ j ∈ s, f (g j) := by classical by_cases hs : (s ∩ mulSupport (f ∘ g)).Finite · have hg : ∀ x ∈ hs.toFinset, ∀ y ∈ hs.toFinset, g x = g y → x = y := by simpa only [hs.mem_toFinset] have := finprod_mem_eq_prod (comp f g) hs unfold Function.comp at this rw [this, ← Finset.prod_image hg] refine finprod_mem_eq_prod_of_inter_mulSupport_eq f ?_ rw [Finset.coe_image, hs.coe_toFinset, ← image_inter_mulSupport_eq, inter_assoc, inter_self] · unfold Function.comp at hs rw [finprod_mem_eq_one_of_infinite hs, finprod_mem_eq_one_of_infinite] rwa [image_inter_mulSupport_eq, infinite_image_iff hg] /-- The product of `f y` over `y ∈ g '' s` equals the product of `f (g i)` over `s` provided that `g` is injective on `s`. -/ @[to_additive "The sum of `f y` over `y ∈ g '' s` equals the sum of `f (g i)` over `s` provided that `g` is injective on `s`."] theorem finprod_mem_image {s : Set β} {g : β → α} (hg : s.InjOn g) : ∏ᶠ i ∈ g '' s, f i = ∏ᶠ j ∈ s, f (g j) := finprod_mem_image' <| hg.mono inter_subset_left /-- The product of `f y` over `y ∈ Set.range g` equals the product of `f (g i)` over all `i` provided that `g` is injective on `mulSupport (f ∘ g)`. -/ @[to_additive "The sum of `f y` over `y ∈ Set.range g` equals the sum of `f (g i)` over all `i` provided that `g` is injective on `support (f ∘ g)`."] theorem finprod_mem_range' {g : β → α} (hg : (mulSupport (f ∘ g)).InjOn g) : ∏ᶠ i ∈ range g, f i = ∏ᶠ j, f (g j) := by rw [← image_univ, finprod_mem_image', finprod_mem_univ] rwa [univ_inter] /-- The product of `f y` over `y ∈ Set.range g` equals the product of `f (g i)` over all `i` provided that `g` is injective. -/ @[to_additive "The sum of `f y` over `y ∈ Set.range g` equals the sum of `f (g i)` over all `i` provided that `g` is injective."] theorem finprod_mem_range {g : β → α} (hg : Injective g) : ∏ᶠ i ∈ range g, f i = ∏ᶠ j, f (g j) := finprod_mem_range' hg.injOn /-- See also `Finset.prod_bij`. -/ @[to_additive "See also `Finset.sum_bij`."] theorem finprod_mem_eq_of_bijOn {s : Set α} {t : Set β} {f : α → M} {g : β → M} (e : α → β) (he₀ : s.BijOn e t) (he₁ : ∀ x ∈ s, f x = g (e x)) : ∏ᶠ i ∈ s, f i = ∏ᶠ j ∈ t, g j := by rw [← Set.BijOn.image_eq he₀, finprod_mem_image he₀.2.1] exact finprod_mem_congr rfl he₁ /-- See `finprod_comp`, `Fintype.prod_bijective` and `Finset.prod_bij`. -/ @[to_additive "See `finsum_comp`, `Fintype.sum_bijective` and `Finset.sum_bij`."] theorem finprod_eq_of_bijective {f : α → M} {g : β → M} (e : α → β) (he₀ : Bijective e) (he₁ : ∀ x, f x = g (e x)) : ∏ᶠ i, f i = ∏ᶠ j, g j := by rw [← finprod_mem_univ f, ← finprod_mem_univ g] exact finprod_mem_eq_of_bijOn _ (bijective_iff_bijOn_univ.mp he₀) fun x _ => he₁ x /-- See also `finprod_eq_of_bijective`, `Fintype.prod_bijective` and `Finset.prod_bij`. -/ @[to_additive "See also `finsum_eq_of_bijective`, `Fintype.sum_bijective` and `Finset.sum_bij`."] theorem finprod_comp {g : β → M} (e : α → β) (he₀ : Function.Bijective e) : (∏ᶠ i, g (e i)) = ∏ᶠ j, g j := finprod_eq_of_bijective e he₀ fun _ => rfl @[to_additive] theorem finprod_comp_equiv (e : α ≃ β) {f : β → M} : (∏ᶠ i, f (e i)) = ∏ᶠ i', f i' := finprod_comp e e.bijective @[to_additive] theorem finprod_set_coe_eq_finprod_mem (s : Set α) : ∏ᶠ j : s, f j = ∏ᶠ i ∈ s, f i := by rw [← finprod_mem_range, Subtype.range_coe] exact Subtype.coe_injective @[to_additive] theorem finprod_subtype_eq_finprod_cond (p : α → Prop) : ∏ᶠ j : Subtype p, f j = ∏ᶠ (i) (_ : p i), f i := finprod_set_coe_eq_finprod_mem { i | p i } @[to_additive] theorem finprod_mem_inter_mul_diff' (t : Set α) (h : (s ∩ mulSupport f).Finite) : ((∏ᶠ i ∈ s ∩ t, f i) * ∏ᶠ i ∈ s \ t, f i) = ∏ᶠ i ∈ s, f i := by rw [← finprod_mem_union', inter_union_diff] · rw [disjoint_iff_inf_le] exact fun x hx => hx.2.2 hx.1.2 exacts [h.subset fun x hx => ⟨hx.1.1, hx.2⟩, h.subset fun x hx => ⟨hx.1.1, hx.2⟩] @[to_additive] theorem finprod_mem_inter_mul_diff (t : Set α) (h : s.Finite) : ((∏ᶠ i ∈ s ∩ t, f i) * ∏ᶠ i ∈ s \ t, f i) = ∏ᶠ i ∈ s, f i := finprod_mem_inter_mul_diff' _ <| h.inter_of_left _ /-- A more general version of `finprod_mem_mul_diff` that requires `t ∩ mulSupport f` rather than `t` to be finite. -/ @[to_additive "A more general version of `finsum_mem_add_diff` that requires `t ∩ support f` rather than `t` to be finite."] theorem finprod_mem_mul_diff' (hst : s ⊆ t) (ht : (t ∩ mulSupport f).Finite) : ((∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t \ s, f i) = ∏ᶠ i ∈ t, f i := by rw [← finprod_mem_inter_mul_diff' _ ht, inter_eq_self_of_subset_right hst] /-- Given a finite set `t` and a subset `s` of `t`, the product of `f i` over `i ∈ s` times the product of `f i` over `t \ s` equals the product of `f i` over `i ∈ t`. -/ @[to_additive "Given a finite set `t` and a subset `s` of `t`, the sum of `f i` over `i ∈ s` plus the sum of `f i` over `t \\ s` equals the sum of `f i` over `i ∈ t`."] theorem finprod_mem_mul_diff (hst : s ⊆ t) (ht : t.Finite) : ((∏ᶠ i ∈ s, f i) * ∏ᶠ i ∈ t \ s, f i) = ∏ᶠ i ∈ t, f i := finprod_mem_mul_diff' hst (ht.inter_of_left _) /-- Given a family of pairwise disjoint finite sets `t i` indexed by a finite type, the product of `f a` over the union `⋃ i, t i` is equal to the product over all indexes `i` of the products of `f a` over `a ∈ t i`. -/ @[to_additive "Given a family of pairwise disjoint finite sets `t i` indexed by a finite type, the sum of `f a` over the union `⋃ i, t i` is equal to the sum over all indexes `i` of the sums of `f a` over `a ∈ t i`."] theorem finprod_mem_iUnion [Finite ι] {t : ι → Set α} (h : Pairwise (Disjoint on t)) (ht : ∀ i, (t i).Finite) : ∏ᶠ a ∈ ⋃ i : ι, t i, f a = ∏ᶠ i, ∏ᶠ a ∈ t i, f a := by cases nonempty_fintype ι lift t to ι → Finset α using ht classical rw [← biUnion_univ, ← Finset.coe_univ, ← Finset.coe_biUnion, finprod_mem_coe_finset, Finset.prod_biUnion] · simp only [finprod_mem_coe_finset, finprod_eq_prod_of_fintype] · exact fun x _ y _ hxy => Finset.disjoint_coe.1 (h hxy) /-- Given a family of sets `t : ι → Set α`, a finite set `I` in the index type such that all sets `t i`, `i ∈ I`, are finite, if all `t i`, `i ∈ I`, are pairwise disjoint, then the product of `f a` over `a ∈ ⋃ i ∈ I, t i` is equal to the product over `i ∈ I` of the products of `f a` over `a ∈ t i`. -/ @[to_additive "Given a family of sets `t : ι → Set α`, a finite set `I` in the index type such that all sets `t i`, `i ∈ I`, are finite, if all `t i`, `i ∈ I`, are pairwise disjoint, then the sum of `f a` over `a ∈ ⋃ i ∈ I, t i` is equal to the sum over `i ∈ I` of the sums of `f a` over `a ∈ t i`."] theorem finprod_mem_biUnion {I : Set ι} {t : ι → Set α} (h : I.PairwiseDisjoint t) (hI : I.Finite) (ht : ∀ i ∈ I, (t i).Finite) : ∏ᶠ a ∈ ⋃ x ∈ I, t x, f a = ∏ᶠ i ∈ I, ∏ᶠ j ∈ t i, f j := by haveI := hI.fintype rw [biUnion_eq_iUnion, finprod_mem_iUnion, ← finprod_set_coe_eq_finprod_mem] exacts [fun x y hxy => h x.2 y.2 (Subtype.coe_injective.ne hxy), fun b => ht b b.2] /-- If `t` is a finite set of pairwise disjoint finite sets, then the product of `f a`
over `a ∈ ⋃₀ t` is the product over `s ∈ t` of the products of `f a` over `a ∈ s`. -/ @[to_additive "If `t` is a finite set of pairwise disjoint finite sets, then the sum of `f a` over `a ∈ ⋃₀ t` is the sum over `s ∈ t` of the sums of `f a` over `a ∈ s`."] theorem finprod_mem_sUnion {t : Set (Set α)} (h : t.PairwiseDisjoint id) (ht₀ : t.Finite) (ht₁ : ∀ x ∈ t, Set.Finite x) : ∏ᶠ a ∈ ⋃₀ t, f a = ∏ᶠ s ∈ t, ∏ᶠ a ∈ s, f a := by rw [Set.sUnion_eq_biUnion] exact finprod_mem_biUnion h ht₀ ht₁ @[to_additive] lemma finprod_option {f : Option α → M} (hf : (mulSupport (f ∘ some)).Finite) : ∏ᶠ o, f o = f none * ∏ᶠ a, f (some a) := by replace hf : (mulSupport f).Finite := by simpa [finite_option] convert finprod_mem_insert' f (show none ∉ Set.range Option.some by aesop)
Mathlib/Algebra/BigOperators/Finprod.lean
933
946
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Yury Kudryashov -/ import Mathlib.Algebra.Group.Commute.Defs import Mathlib.Algebra.Opposites import Mathlib.Tactic.Spread /-! # Definitions of group actions This file defines a hierarchy of group action type-classes on top of the previously defined notation classes `SMul` and its additive version `VAdd`: * `MulAction M α` and its additive version `AddAction G P` are typeclasses used for actions of multiplicative and additive monoids and groups; they extend notation classes `SMul` and `VAdd` that are defined in `Algebra.Group.Defs`; * `DistribMulAction M A` is a typeclass for an action of a multiplicative monoid on an additive monoid such that `a • (b + c) = a • b + a • c` and `a • 0 = 0`. The hierarchy is extended further by `Module`, defined elsewhere. Also provided are typeclasses regarding the interaction of different group actions, * `SMulCommClass M N α` and its additive version `VAddCommClass M N α`; * `IsScalarTower M N α` and its additive version `VAddAssocClass M N α`; * `IsCentralScalar M α` and its additive version `IsCentralVAdd M N α`. ## Notation - `a • b` is used as notation for `SMul.smul a b`. - `a +ᵥ b` is used as notation for `VAdd.vadd a b`. ## Implementation details This file should avoid depending on other parts of `GroupTheory`, to avoid import cycles. More sophisticated lemmas belong in `GroupTheory.GroupAction`. ## Tags group action -/ assert_not_exists MonoidWithZero open Function (Injective Surjective) variable {M N G H α β γ δ : Type*} -- see Note [lower instance priority] /-- See also `Monoid.toMulAction` and `MulZeroClass.toSMulWithZero`. -/ @[to_additive "See also `AddMonoid.toAddAction`"] instance (priority := 910) Mul.toSMul (α : Type*) [Mul α] : SMul α α := ⟨(· * ·)⟩ /-- Like `Mul.toSMul`, but multiplies on the right. See also `Monoid.toOppositeMulAction` and `MonoidWithZero.toOppositeMulActionWithZero`. -/ @[to_additive "Like `Add.toVAdd`, but adds on the right. See also `AddMonoid.toOppositeAddAction`."] instance (priority := 910) Mul.toSMulMulOpposite (α : Type*) [Mul α] : SMul αᵐᵒᵖ α where smul a b := b * a.unop @[to_additive (attr := simp)] lemma smul_eq_mul {α : Type*} [Mul α] (a b : α) : a • b = a * b := rfl @[to_additive] lemma op_smul_eq_mul {α : Type*} [Mul α] (a b : α) : MulOpposite.op a • b = b * a := rfl @[to_additive (attr := simp)] lemma MulOpposite.smul_eq_mul_unop [Mul α] (a : αᵐᵒᵖ) (b : α) : a • b = b * a.unop := rfl /-- Type class for additive monoid actions. -/ class AddAction (G : Type*) (P : Type*) [AddMonoid G] extends VAdd G P where /-- Zero is a neutral element for `+ᵥ` -/ protected zero_vadd : ∀ p : P, (0 : G) +ᵥ p = p /-- Associativity of `+` and `+ᵥ` -/ add_vadd : ∀ (g₁ g₂ : G) (p : P), (g₁ + g₂) +ᵥ p = g₁ +ᵥ g₂ +ᵥ p /-- Typeclass for multiplicative actions by monoids. This generalizes group actions. -/ @[to_additive (attr := ext)] class MulAction (α : Type*) (β : Type*) [Monoid α] extends SMul α β where /-- One is the neutral element for `•` -/ protected one_smul : ∀ b : β, (1 : α) • b = b /-- Associativity of `•` and `*` -/ mul_smul : ∀ (x y : α) (b : β), (x * y) • b = x • y • b /-! ### Scalar tower and commuting actions -/ /-- A typeclass mixin saying that two additive actions on the same space commute. -/ class VAddCommClass (M N α : Type*) [VAdd M α] [VAdd N α] : Prop where /-- `+ᵥ` is left commutative -/ vadd_comm : ∀ (m : M) (n : N) (a : α), m +ᵥ (n +ᵥ a) = n +ᵥ (m +ᵥ a) /-- A typeclass mixin saying that two multiplicative actions on the same space commute. -/ @[to_additive] class SMulCommClass (M N α : Type*) [SMul M α] [SMul N α] : Prop where /-- `•` is left commutative -/ smul_comm : ∀ (m : M) (n : N) (a : α), m • n • a = n • m • a export MulAction (mul_smul) export AddAction (add_vadd) export SMulCommClass (smul_comm) export VAddCommClass (vadd_comm) library_note "bundled maps over different rings"/-- Frequently, we find ourselves wanting to express a bilinear map `M →ₗ[R] N →ₗ[R] P` or an equivalence between maps `(M →ₗ[R] N) ≃ₗ[R] (M' →ₗ[R] N')` where the maps have an associated ring `R`. Unfortunately, using definitions like these requires that `R` satisfy `CommSemiring R`, and not just `Semiring R`. Using `M →ₗ[R] N →+ P` and `(M →ₗ[R] N) ≃+ (M' →ₗ[R] N')` avoids this problem, but throws away structure that is useful for when we _do_ have a commutative (semi)ring. To avoid making this compromise, we instead state these definitions as `M →ₗ[R] N →ₗ[S] P` or `(M →ₗ[R] N) ≃ₗ[S] (M' →ₗ[R] N')` and require `SMulCommClass S R` on the appropriate modules. When the caller has `CommSemiring R`, they can set `S = R` and `smulCommClass_self` will populate the instance. If the caller only has `Semiring R` they can still set either `R = ℕ` or `S = ℕ`, and `AddCommMonoid.nat_smulCommClass` or `AddCommMonoid.nat_smulCommClass'` will populate the typeclass, which is still sufficient to recover a `≃+` or `→+` structure. An example of where this is used is `LinearMap.prod_equiv`. -/ /-- Commutativity of actions is a symmetric relation. This lemma can't be an instance because this would cause a loop in the instance search graph. -/ @[to_additive] lemma SMulCommClass.symm (M N α : Type*) [SMul M α] [SMul N α] [SMulCommClass M N α] : SMulCommClass N M α where smul_comm a' a b := (smul_comm a a' b).symm /-- Commutativity of additive actions is a symmetric relation. This lemma can't be an instance because this would cause a loop in the instance search graph. -/ add_decl_doc VAddCommClass.symm @[to_additive] lemma Function.Injective.smulCommClass [SMul M α] [SMul N α] [SMul M β] [SMul N β] [SMulCommClass M N β] {f : α → β} (hf : Injective f) (h₁ : ∀ (c : M) x, f (c • x) = c • f x) (h₂ : ∀ (c : N) x, f (c • x) = c • f x) : SMulCommClass M N α where smul_comm c₁ c₂ x := hf <| by simp only [h₁, h₂, smul_comm c₁ c₂ (f x)] @[to_additive] lemma Function.Surjective.smulCommClass [SMul M α] [SMul N α] [SMul M β] [SMul N β] [SMulCommClass M N α] {f : α → β} (hf : Surjective f) (h₁ : ∀ (c : M) x, f (c • x) = c • f x) (h₂ : ∀ (c : N) x, f (c • x) = c • f x) : SMulCommClass M N β where smul_comm c₁ c₂ := hf.forall.2 fun x ↦ by simp only [← h₁, ← h₂, smul_comm c₁ c₂ x] @[to_additive] instance smulCommClass_self (M α : Type*) [CommMonoid M] [MulAction M α] : SMulCommClass M M α where smul_comm a a' b := by rw [← mul_smul, mul_comm, mul_smul] /-- An instance of `VAddAssocClass M N α` states that the additive action of `M` on `α` is determined by the additive actions of `M` on `N` and `N` on `α`. -/ class VAddAssocClass (M N α : Type*) [VAdd M N] [VAdd N α] [VAdd M α] : Prop where /-- Associativity of `+ᵥ` -/ vadd_assoc : ∀ (x : M) (y : N) (z : α), (x +ᵥ y) +ᵥ z = x +ᵥ y +ᵥ z /-- An instance of `IsScalarTower M N α` states that the multiplicative action of `M` on `α` is determined by the multiplicative actions of `M` on `N` and `N` on `α`. -/ @[to_additive] class IsScalarTower (M N α : Type*) [SMul M N] [SMul N α] [SMul M α] : Prop where /-- Associativity of `•` -/ smul_assoc : ∀ (x : M) (y : N) (z : α), (x • y) • z = x • y • z @[to_additive (attr := simp)] lemma smul_assoc {M N} [SMul M N] [SMul N α] [SMul M α] [IsScalarTower M N α] (x : M) (y : N) (z : α) : (x • y) • z = x • y • z := IsScalarTower.smul_assoc x y z @[to_additive] instance Semigroup.isScalarTower [Semigroup α] : IsScalarTower α α α := ⟨mul_assoc⟩ /-- A typeclass indicating that the right (aka `AddOpposite`) and left actions by `M` on `α` are equal, that is that `M` acts centrally on `α`. This can be thought of as a version of commutativity for `+ᵥ`. -/ class IsCentralVAdd (M α : Type*) [VAdd M α] [VAdd Mᵃᵒᵖ α] : Prop where /-- The right and left actions of `M` on `α` are equal. -/ op_vadd_eq_vadd : ∀ (m : M) (a : α), AddOpposite.op m +ᵥ a = m +ᵥ a /-- A typeclass indicating that the right (aka `MulOpposite`) and left actions by `M` on `α` are equal, that is that `M` acts centrally on `α`. This can be thought of as a version of commutativity for `•`. -/ @[to_additive] class IsCentralScalar (M α : Type*) [SMul M α] [SMul Mᵐᵒᵖ α] : Prop where /-- The right and left actions of `M` on `α` are equal. -/ op_smul_eq_smul : ∀ (m : M) (a : α), MulOpposite.op m • a = m • a @[to_additive] lemma IsCentralScalar.unop_smul_eq_smul {M α : Type*} [SMul M α] [SMul Mᵐᵒᵖ α] [IsCentralScalar M α] (m : Mᵐᵒᵖ) (a : α) : MulOpposite.unop m • a = m • a := by induction m; exact (IsCentralScalar.op_smul_eq_smul _ a).symm export IsCentralVAdd (op_vadd_eq_vadd unop_vadd_eq_vadd) export IsCentralScalar (op_smul_eq_smul unop_smul_eq_smul) attribute [simp] IsCentralScalar.op_smul_eq_smul -- these instances are very low priority, as there is usually a faster way to find these instances @[to_additive] instance (priority := 50) SMulCommClass.op_left [SMul M α] [SMul Mᵐᵒᵖ α] [IsCentralScalar M α] [SMul N α] [SMulCommClass M N α] : SMulCommClass Mᵐᵒᵖ N α := ⟨fun m n a ↦ by rw [← unop_smul_eq_smul m (n • a), ← unop_smul_eq_smul m a, smul_comm]⟩ @[to_additive] instance (priority := 50) SMulCommClass.op_right [SMul M α] [SMul N α] [SMul Nᵐᵒᵖ α] [IsCentralScalar N α] [SMulCommClass M N α] : SMulCommClass M Nᵐᵒᵖ α := ⟨fun m n a ↦ by rw [← unop_smul_eq_smul n (m • a), ← unop_smul_eq_smul n a, smul_comm]⟩ @[to_additive] instance (priority := 50) IsScalarTower.op_left [SMul M α] [SMul Mᵐᵒᵖ α] [IsCentralScalar M α] [SMul M N] [SMul Mᵐᵒᵖ N] [IsCentralScalar M N] [SMul N α] [IsScalarTower M N α] : IsScalarTower Mᵐᵒᵖ N α where smul_assoc m n a := by rw [← unop_smul_eq_smul m (n • a), ← unop_smul_eq_smul m n, smul_assoc] @[to_additive] instance (priority := 50) IsScalarTower.op_right [SMul M α] [SMul M N] [SMul N α] [SMul Nᵐᵒᵖ α] [IsCentralScalar N α] [IsScalarTower M N α] : IsScalarTower M Nᵐᵒᵖ α where smul_assoc m n a := by rw [← unop_smul_eq_smul n a, ← unop_smul_eq_smul (m • n) a, MulOpposite.unop_smul, smul_assoc] namespace SMul variable [SMul M α] /-- Auxiliary definition for `SMul.comp`, `MulAction.compHom`, `DistribMulAction.compHom`, `Module.compHom`, etc. -/ @[to_additive (attr := simp) " Auxiliary definition for `VAdd.comp`, `AddAction.compHom`, etc. "] def comp.smul (g : N → M) (n : N) (a : α) : α := g n • a variable (α) /-- An action of `M` on `α` and a function `N → M` induces an action of `N` on `α`. -/ -- See note [reducible non-instances] -- Since this is reducible, we make sure to go via -- `SMul.comp.smul` to prevent typeclass inference unfolding too far @[to_additive "An additive action of `M` on `α` and a function `N → M` induces an additive action of `N` on `α`."] abbrev comp (g : N → M) : SMul N α where smul := SMul.comp.smul g variable {α} /-- Given a tower of scalar actions `M → α → β`, if we use `SMul.comp` to pull back both of `M`'s actions by a map `g : N → M`, then we obtain a new tower of scalar actions `N → α → β`. This cannot be an instance because it can cause infinite loops whenever the `SMul` arguments are still metavariables. -/ @[to_additive "Given a tower of additive actions `M → α → β`, if we use `SMul.comp` to pull back both of `M`'s actions by a map `g : N → M`, then we obtain a new tower of scalar actions `N → α → β`. This cannot be an instance because it can cause infinite loops whenever the `SMul` arguments are still metavariables."] lemma comp.isScalarTower [SMul M β] [SMul α β] [IsScalarTower M α β] (g : N → M) : by haveI := comp α g; haveI := comp β g; exact IsScalarTower N α β where __ := comp α g __ := comp β g smul_assoc n := smul_assoc (g n) /-- This cannot be an instance because it can cause infinite loops whenever the `SMul` arguments are still metavariables. -/ @[to_additive "This cannot be an instance because it can cause infinite loops whenever the `VAdd` arguments are still metavariables."] lemma comp.smulCommClass [SMul β α] [SMulCommClass M β α] (g : N → M) : haveI := comp α g SMulCommClass N β α where __ := comp α g smul_comm n := smul_comm (g n) /-- This cannot be an instance because it can cause infinite loops whenever the `SMul` arguments are still metavariables. -/ @[to_additive "This cannot be an instance because it can cause infinite loops whenever the `VAdd` arguments are still metavariables."] lemma comp.smulCommClass' [SMul β α] [SMulCommClass β M α] (g : N → M) : haveI := comp α g SMulCommClass β N α where __ := comp α g smul_comm _ n := smul_comm _ (g n) end SMul section /-- Note that the `SMulCommClass α β β` typeclass argument is usually satisfied by `Algebra α β`. -/ @[to_additive] lemma mul_smul_comm [Mul β] [SMul α β] [SMulCommClass α β β] (s : α) (x y : β) : x * s • y = s • (x * y) := (smul_comm s x y).symm /-- Note that the `IsScalarTower α β β` typeclass argument is usually satisfied by `Algebra α β`. -/ @[to_additive] lemma smul_mul_assoc [Mul β] [SMul α β] [IsScalarTower α β β] (r : α) (x y : β) : r • x * y = r • (x * y) := smul_assoc r x y /-- Note that the `IsScalarTower α β β` typeclass argument is usually satisfied by `Algebra α β`. -/ @[to_additive] lemma smul_div_assoc [DivInvMonoid β] [SMul α β] [IsScalarTower α β β] (r : α) (x y : β) : r • x / y = r • (x / y) := by simp [div_eq_mul_inv, smul_mul_assoc] @[to_additive] lemma smul_smul_smul_comm [SMul α β] [SMul α γ] [SMul β δ] [SMul α δ] [SMul γ δ] [IsScalarTower α β δ] [IsScalarTower α γ δ] [SMulCommClass β γ δ] (a : α) (b : β) (c : γ) (d : δ) : (a • b) • c • d = (a • c) • b • d := by rw [smul_assoc, smul_assoc, smul_comm b] /-- Note that the `IsScalarTower α β β` and `SMulCommClass α β β` typeclass arguments are usually satisfied by `Algebra α β`. -/ @[to_additive] lemma smul_mul_smul_comm [Mul α] [Mul β] [SMul α β] [IsScalarTower α β β] [IsScalarTower α α β] [SMulCommClass α β β] (a : α) (b : β) (c : α) (d : β) : (a • b) * (c • d) = (a * c) • (b * d) := by have : SMulCommClass β α β := .symm ..; exact smul_smul_smul_comm a b c d @[to_additive] alias smul_mul_smul := smul_mul_smul_comm /-- Note that the `IsScalarTower α β β` and `SMulCommClass α β β` typeclass arguments are usually satisfied by `Algebra α β`. -/ @[to_additive] lemma mul_smul_mul_comm [Mul α] [Mul β] [SMul α β] [IsScalarTower α β β] [IsScalarTower α α β] [SMulCommClass α β β] (a b : α) (c d : β) : (a * b) • (c * d) = (a • c) * (b • d) := smul_smul_smul_comm a b c d variable [SMul M α] @[to_additive] lemma Commute.smul_right [Mul α] [SMulCommClass M α α] [IsScalarTower M α α] {a b : α} (h : Commute a b) (r : M) : Commute a (r • b) := (mul_smul_comm _ _ _).trans ((congr_arg _ h).trans <| (smul_mul_assoc _ _ _).symm) @[to_additive] lemma Commute.smul_left [Mul α] [SMulCommClass M α α] [IsScalarTower M α α] {a b : α} (h : Commute a b) (r : M) : Commute (r • a) b := (h.symm.smul_right r).symm end section variable [Monoid M] [MulAction M α] {a : M} @[to_additive] lemma smul_smul (a₁ a₂ : M) (b : α) : a₁ • a₂ • b = (a₁ * a₂) • b := (mul_smul _ _ _).symm variable (M) @[to_additive (attr := simp)] lemma one_smul (b : α) : (1 : M) • b = b := MulAction.one_smul _ /-- `SMul` version of `one_mul_eq_id` -/ @[to_additive "`VAdd` version of `zero_add_eq_id`"] lemma one_smul_eq_id : (((1 : M) • ·) : α → α) = id := funext <| one_smul _ /-- `SMul` version of `comp_mul_left` -/ @[to_additive "`VAdd` version of `comp_add_left`"] lemma comp_smul_left (a₁ a₂ : M) : (a₁ • ·) ∘ (a₂ • ·) = (((a₁ * a₂) • ·) : α → α) := funext fun _ ↦ (mul_smul _ _ _).symm variable {M} @[to_additive (attr := simp)] theorem smul_iterate (a : M) : ∀ n : ℕ, (a • · : α → α)^[n] = (a ^ n • ·) | 0 => by simp [funext_iff] | n + 1 => by ext; simp [smul_iterate, pow_succ, smul_smul] @[to_additive] lemma smul_iterate_apply (a : M) (n : ℕ) (x : α) : (a • ·)^[n] x = a ^ n • x := by rw [smul_iterate] /-- Pullback a multiplicative action along an injective map respecting `•`. See note [reducible non-instances]. -/ @[to_additive "Pullback an additive action along an injective map respecting `+ᵥ`."] protected abbrev Function.Injective.mulAction [SMul M β] (f : β → α) (hf : Injective f) (smul : ∀ (c : M) (x), f (c • x) = c • f x) : MulAction M β where smul := (· • ·) one_smul x := hf <| (smul _ _).trans <| one_smul _ (f x) mul_smul c₁ c₂ x := hf <| by simp only [smul, mul_smul] /-- Pushforward a multiplicative action along a surjective map respecting `•`. See note [reducible non-instances]. -/ @[to_additive "Pushforward an additive action along a surjective map respecting `+ᵥ`."] protected abbrev Function.Surjective.mulAction [SMul M β] (f : α → β) (hf : Surjective f) (smul : ∀ (c : M) (x), f (c • x) = c • f x) : MulAction M β where smul := (· • ·) one_smul := by simp [hf.forall, ← smul] mul_smul := by simp [hf.forall, ← smul, mul_smul] section variable (M) /-- The regular action of a monoid on itself by left multiplication. This is promoted to a module by `Semiring.toModule`. -/ -- see Note [lower instance priority] @[to_additive "The regular action of a monoid on itself by left addition. This is promoted to an `AddTorsor` by `addGroup_is_addTorsor`."] instance (priority := 910) Monoid.toMulAction : MulAction M M where smul := (· * ·) one_smul := one_mul mul_smul := mul_assoc @[to_additive] instance IsScalarTower.left : IsScalarTower M M α where smul_assoc x y z := mul_smul x y z variable {M} section Monoid variable [Monoid N] [MulAction M N] [IsScalarTower M N N] [SMulCommClass M N N] lemma smul_pow (r : M) (x : N) : ∀ n, (r • x) ^ n = r ^ n • x ^ n | 0 => by simp | n + 1 => by rw [pow_succ', smul_pow _ _ n, smul_mul_smul_comm, ← pow_succ', ← pow_succ'] end Monoid section Group variable [Group G] [MulAction G α] {g : G} {a b : α} @[to_additive (attr := simp)] lemma inv_smul_smul (g : G) (a : α) : g⁻¹ • g • a = a := by rw [smul_smul, inv_mul_cancel, one_smul] @[to_additive (attr := simp)] lemma smul_inv_smul (g : G) (a : α) : g • g⁻¹ • a = a := by rw [smul_smul, mul_inv_cancel, one_smul] @[to_additive] lemma inv_smul_eq_iff : g⁻¹ • a = b ↔ a = g • b := ⟨fun h ↦ by rw [← h, smul_inv_smul], fun h ↦ by rw [h, inv_smul_smul]⟩ @[to_additive] lemma eq_inv_smul_iff : a = g⁻¹ • b ↔ g • a = b := ⟨fun h ↦ by rw [h, smul_inv_smul], fun h ↦ by rw [← h, inv_smul_smul]⟩ section Mul variable [Mul H] [MulAction G H] [SMulCommClass G H H] [IsScalarTower G H H] {a b : H} @[simp] lemma Commute.smul_right_iff : Commute a (g • b) ↔ Commute a b := ⟨fun h ↦ inv_smul_smul g b ▸ h.smul_right g⁻¹, fun h ↦ h.smul_right g⟩ @[simp] lemma Commute.smul_left_iff : Commute (g • a) b ↔ Commute a b := by rw [Commute.symm_iff, Commute.smul_right_iff, Commute.symm_iff] end Mul variable [Group H] [MulAction G H] [SMulCommClass G H H] [IsScalarTower G H H] lemma smul_inv (g : G) (a : H) : (g • a)⁻¹ = g⁻¹ • a⁻¹ := inv_eq_of_mul_eq_one_right <| by rw [smul_mul_smul_comm, mul_inv_cancel, mul_inv_cancel, one_smul] lemma smul_zpow (g : G) (a : H) (n : ℤ) : (g • a) ^ n = g ^ n • a ^ n := by cases n <;> simp [smul_pow, smul_inv] end Group end lemma SMulCommClass.of_commMonoid (A B G : Type*) [CommMonoid G] [SMul A G] [SMul B G] [IsScalarTower A G G] [IsScalarTower B G G] : SMulCommClass A B G where smul_comm r s x := by rw [← one_smul G (s • x), ← smul_assoc, ← one_smul G x, ← smul_assoc s 1 x, smul_comm, smul_assoc, one_smul, smul_assoc, one_smul] end section CompatibleScalar @[to_additive] lemma smul_one_smul {M} (N) [Monoid N] [SMul M N] [MulAction N α] [SMul M α] [IsScalarTower M N α] (x : M) (y : α) : (x • (1 : N)) • y = x • y := by rw [smul_assoc, one_smul] @[to_additive (attr := simp)] lemma smul_one_mul {M N} [MulOneClass N] [SMul M N] [IsScalarTower M N N] (x : M) (y : N) : x • (1 : N) * y = x • y := by rw [smul_mul_assoc, one_mul] @[to_additive (attr := simp)] lemma mul_smul_one {M N} [MulOneClass N] [SMul M N] [SMulCommClass M N N] (x : M) (y : N) : y * x • (1 : N) = x • y := by rw [← smul_eq_mul, ← smul_comm, smul_eq_mul, mul_one] @[to_additive] lemma IsScalarTower.of_smul_one_mul {M N} [Monoid N] [SMul M N] (h : ∀ (x : M) (y : N), x • (1 : N) * y = x • y) : IsScalarTower M N N := ⟨fun x y z ↦ by rw [← h, smul_eq_mul, mul_assoc, h, smul_eq_mul]⟩ @[to_additive] lemma SMulCommClass.of_mul_smul_one {M N} [Monoid N] [SMul M N] (H : ∀ (x : M) (y : N), y * x • (1 : N) = x • y) : SMulCommClass M N N := ⟨fun x y z ↦ by rw [← H x z, smul_eq_mul, ← H, smul_eq_mul, mul_assoc]⟩ end CompatibleScalar /-- Typeclass for multiplicative actions on multiplicative structures. This generalizes conjugation actions. -/ @[ext] class MulDistribMulAction (M N : Type*) [Monoid M] [Monoid N] extends MulAction M N where /-- Distributivity of `•` across `*` -/ smul_mul : ∀ (r : M) (x y : N), r • (x * y) = r • x * r • y /-- Multiplying `1` by a scalar gives `1` -/ smul_one : ∀ r : M, r • (1 : N) = 1 export MulDistribMulAction (smul_one) section MulDistribMulAction variable [Monoid M] [Monoid N] [MulDistribMulAction M N] lemma smul_mul' (a : M) (b₁ b₂ : N) : a • (b₁ * b₂) = a • b₁ * a • b₂ := MulDistribMulAction.smul_mul .. end MulDistribMulAction
Mathlib/Algebra/Group/Action/Defs.lean
637
640
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson -/ import Mathlib.Topology.Category.CompHausLike.EffectiveEpi import Mathlib.Topology.Category.LightProfinite.Limits /-! # Effective epimorphisms in `LightProfinite` This file proves that `EffectiveEpi` and `Surjective` are equivalent in `LightProfinite`. As a consequence we deduce from the material in `Mathlib.Topology.Category.CompHausLike.EffectiveEpi` that `LightProfinite` is `Preregular` and `Precoherent`. -/ universe u open CategoryTheory Limits CompHausLike namespace LightProfinite theorem effectiveEpi_iff_surjective {X Y : LightProfinite.{u}} (f : X ⟶ Y) : EffectiveEpi f ↔ Function.Surjective f := by refine ⟨fun h ↦ ?_, fun h ↦ ⟨⟨effectiveEpiStruct f h⟩⟩⟩ rw [← epi_iff_surjective] infer_instance instance : Preregular LightProfinite.{u} := by apply CompHausLike.preregular intro _ _ f exact (effectiveEpi_iff_surjective f).mp example : Precoherent LightProfinite.{u} := inferInstance end LightProfinite
Mathlib/Topology/Category/LightProfinite/EffectiveEpi.lean
54
58
/- 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) = Y.presheaf.stalk (β.base x) by rw [h]) ≫ β.stalkMap x := by rw [← stalkMap.congr α β h x x rfl, eqToHom_refl, Category.comp_id] theorem congr_point {X Y : PresheafedSpace.{_, _, v} C}
(α : X ⟶ Y) (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]) ≫ α.stalkMap x' := by rw [stalkMap.congr α α rfl x x' h] instance isIso {X Y : PresheafedSpace.{_, _, v} C} (α : X ⟶ Y) [IsIso α] (x : X) : IsIso (α.stalkMap x) where out := by let β : Y ⟶ X := CategoryTheory.inv α have h_eq : (α ≫ β).base x = x := by rw [IsIso.hom_inv_id α, id_base, TopCat.id_app] -- Intuitively, the inverse of the stalk map of `α` at `x` should just be the stalk map of `β` -- at `α x`. Unfortunately, we have a problem with dependent type theory here: Because `x`
Mathlib/Geometry/RingedSpace/Stalks.lean
150
162
/- Copyright (c) 2015 Nathaniel Thomas. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.GroupWithZero.Action.Defs import Mathlib.Algebra.Ring.Defs /-! # Modules over a ring In this file we define * `Module R M` : an additive commutative monoid `M` is a `Module` over a `Semiring R` if for `r : R` and `x : M` their "scalar multiplication" `r • x : M` is defined, and the operation `•` satisfies some natural associativity and distributivity axioms similar to those on a ring. ## Implementation notes In typical mathematical usage, our definition of `Module` corresponds to "semimodule", and the word "module" is reserved for `Module R M` where `R` is a `Ring` and `M` an `AddCommGroup`. If `R` is a `Field` and `M` an `AddCommGroup`, `M` would be called an `R`-vector space. Since those assumptions can be made by changing the typeclasses applied to `R` and `M`, without changing the axioms in `Module`, mathlib calls everything a `Module`. In older versions of mathlib3, we had separate abbreviations for semimodules and vector spaces. This caused inference issues in some cases, while not providing any real advantages, so we decided to use a canonical `Module` typeclass throughout. ## Tags semimodule, module, vector space -/ assert_not_exists Field Invertible Pi.single_smul₀ RingHom Set.indicator Multiset Units open Function Set universe u v variable {R S M M₂ : Type*} /-- A module is a generalization of vector spaces to a scalar semiring. It consists of a scalar semiring `R` and an additive monoid of "vectors" `M`, connected by a "scalar multiplication" operation `r • x : M` (where `r : R` and `x : M`) with some natural associativity and distributivity axioms similar to those on a ring. -/ @[ext] class Module (R : Type u) (M : Type v) [Semiring R] [AddCommMonoid M] extends DistribMulAction R M where /-- Scalar multiplication distributes over addition from the right. -/ protected add_smul : ∀ (r s : R) (x : M), (r + s) • x = r • x + s • x /-- Scalar multiplication by zero gives zero. -/ protected zero_smul : ∀ x : M, (0 : R) • x = 0 section AddCommMonoid variable [Semiring R] [AddCommMonoid M] [Module R M] (r s : R) (x : M) -- see Note [lower instance priority] /-- A module over a semiring automatically inherits a `MulActionWithZero` structure. -/ instance (priority := 100) Module.toMulActionWithZero {R M} {_ : Semiring R} {_ : AddCommMonoid M} [Module R M] : MulActionWithZero R M := { (inferInstance : MulAction R M) with smul_zero := smul_zero zero_smul := Module.zero_smul } theorem add_smul : (r + s) • x = r • x + s • x := Module.add_smul r s x theorem Convex.combo_self {a b : R} (h : a + b = 1) (x : M) : a • x + b • x = x := by rw [← add_smul, h, one_smul] variable (R) theorem two_smul : (2 : R) • x = x + x := by rw [← one_add_one_eq_two, add_smul, one_smul] /-- Pullback a `Module` structure along an injective additive monoid homomorphism. See note [reducible non-instances]. -/ protected abbrev Function.Injective.module [AddCommMonoid M₂] [SMul R M₂] (f : M₂ →+ M) (hf : Injective f) (smul : ∀ (c : R) (x), f (c • x) = c • f x) : Module R M₂ := { hf.distribMulAction f smul with add_smul := fun c₁ c₂ x => hf <| by simp only [smul, f.map_add, add_smul] zero_smul := fun x => hf <| by simp only [smul, zero_smul, f.map_zero] } /-- Pushforward a `Module` structure along a surjective additive monoid homomorphism. See note [reducible non-instances]. -/ protected abbrev Function.Surjective.module [AddCommMonoid M₂] [SMul R M₂] (f : M →+ M₂) (hf : Surjective f) (smul : ∀ (c : R) (x), f (c • x) = c • f x) : Module R M₂ := { toDistribMulAction := hf.distribMulAction f smul add_smul := fun c₁ c₂ x => by rcases hf x with ⟨x, rfl⟩ simp only [add_smul, ← smul, ← f.map_add] zero_smul := fun x => by rcases hf x with ⟨x, rfl⟩ rw [← f.map_zero, ← smul, zero_smul] } variable {R} theorem Module.eq_zero_of_zero_eq_one (zero_eq_one : (0 : R) = 1) : x = 0 := by rw [← one_smul R x, ← zero_eq_one, zero_smul] @[simp] theorem smul_add_one_sub_smul {R : Type*} [Ring R] [Module R M] {r : R} {m : M} : r • m + (1 - r) • m = m := by rw [← add_smul, add_sub_cancel, one_smul] end AddCommMonoid section AddCommGroup variable [Semiring R] [AddCommGroup M] theorem Convex.combo_eq_smul_sub_add [Module R M] {x y : M} {a b : R} (h : a + b = 1) : a • x + b • y = b • (y - x) + x := calc a • x + b • y = b • y - b • x + (a • x + b • x) := by rw [sub_add_add_cancel, add_comm] _ = b • (y - x) + x := by rw [smul_sub, Convex.combo_self h] end AddCommGroup -- We'll later use this to show `Module ℕ M` and `Module ℤ M` are subsingletons. /-- A variant of `Module.ext` that's convenient for term-mode. -/ theorem Module.ext' {R : Type*} [Semiring R] {M : Type*} [AddCommMonoid M] (P Q : Module R M) (w : ∀ (r : R) (m : M), (haveI := P; r • m) = (haveI := Q; r • m)) : P = Q := by ext exact w _ _ section Module variable [Ring R] [AddCommGroup M] [Module R M] (r : R) (x : M) @[simp] theorem neg_smul : -r • x = -(r • x) := eq_neg_of_add_eq_zero_left <| by rw [← add_smul, neg_add_cancel, zero_smul] theorem neg_smul_neg : -r • -x = r • x := by rw [neg_smul, smul_neg, neg_neg] variable (R) theorem neg_one_smul (x : M) : (-1 : R) • x = -x := by simp variable {R} theorem sub_smul (r s : R) (y : M) : (r - s) • y = r • y - s • y := by simp [add_smul, sub_eq_add_neg] end Module /-- A module over a `Subsingleton` semiring is a `Subsingleton`. We cannot register this as an instance because Lean has no way to guess `R`. -/ protected theorem Module.subsingleton (R M : Type*) [MonoidWithZero R] [Subsingleton R] [Zero M] [MulActionWithZero R M] : Subsingleton M := MulActionWithZero.subsingleton R M /-- A semiring is `Nontrivial` provided that there exists a nontrivial module over this semiring. -/ protected theorem Module.nontrivial (R M : Type*) [MonoidWithZero R] [Nontrivial M] [Zero M] [MulActionWithZero R M] : Nontrivial R := MulActionWithZero.nontrivial R M -- see Note [lower instance priority] instance (priority := 910) Semiring.toModule [Semiring R] : Module R R where smul_add := mul_add add_smul := add_mul zero_smul := zero_mul smul_zero := mul_zero instance [NonUnitalNonAssocSemiring R] : DistribSMul R R where smul_add := left_distrib
Mathlib/Algebra/Module/Defs.lean
415
416
/- Copyright (c) 2021 Justus Springer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Justus Springer -/ import Mathlib.CategoryTheory.Sites.Spaces import Mathlib.Topology.Sheaves.Sheaf import Mathlib.CategoryTheory.Sites.DenseSubsite.Basic /-! # Coverings and sieves; from sheaves on sites and sheaves on spaces In this file, we connect coverings in a topological space to sieves in the associated Grothendieck topology, in preparation of connecting the sheaf condition on sites to the various sheaf conditions on spaces. We also specialize results about sheaves on sites to sheaves on spaces; we show that the inclusion functor from a topological basis to `TopologicalSpace.Opens` is cover dense, that open maps induce cover preserving functors, and that open embeddings induce continuous functors. -/ noncomputable section open CategoryTheory TopologicalSpace Topology universe w v u namespace TopCat.Presheaf variable {X : TopCat.{w}} /-- Given a presieve `R` on `U`, we obtain a covering family of open sets in `X`, by taking as index type the type of dependent pairs `(V, f)`, where `f : V ⟶ U` is in `R`. -/ def coveringOfPresieve (U : Opens X) (R : Presieve U) : (ΣV, { f : V ⟶ U // R f }) → Opens X := fun f => f.1 @[simp] theorem coveringOfPresieve_apply (U : Opens X) (R : Presieve U) (f : Σ V, { f : V ⟶ U // R f }) : coveringOfPresieve U R f = f.1 := rfl namespace coveringOfPresieve variable (U : Opens X) (R : Presieve U) /-- If `R` is a presieve in the grothendieck topology on `Opens X`, the covering family associated to `R` really is _covering_, i.e. the union of all open sets equals `U`. -/ theorem iSup_eq_of_mem_grothendieck (hR : Sieve.generate R ∈ Opens.grothendieckTopology X U) : iSup (coveringOfPresieve U R) = U := by apply le_antisymm · refine iSup_le ?_ intro f exact f.2.1.le intro x hxU rw [Opens.coe_iSup, Set.mem_iUnion] obtain ⟨V, iVU, ⟨W, iVW, iWU, hiWU, -⟩, hxV⟩ := hR x hxU exact ⟨⟨W, ⟨iWU, hiWU⟩⟩, iVW.le hxV⟩ end coveringOfPresieve /-- Given a family of opens `U : ι → Opens X` and any open `Y : Opens X`, we obtain a presieve on `Y` by declaring that a morphism `f : V ⟶ Y` is a member of the presieve if and only if there exists an index `i : ι` such that `V = U i`. -/ def presieveOfCoveringAux {ι : Type v} (U : ι → Opens X) (Y : Opens X) : Presieve Y := fun V _ => ∃ i, V = U i /-- Take `Y` to be `iSup U` and obtain a presieve over `iSup U`. -/ def presieveOfCovering {ι : Type v} (U : ι → Opens X) : Presieve (iSup U) := presieveOfCoveringAux U (iSup U) /-- Given a presieve `R` on `Y`, if we take its associated family of opens via `coveringOfPresieve` (which may not cover `Y` if `R` is not covering), and take the presieve on `Y` associated to the family of opens via `presieveOfCoveringAux`, then we get back the original presieve `R`. -/ @[simp] theorem covering_presieve_eq_self {Y : Opens X} (R : Presieve Y) : presieveOfCoveringAux (coveringOfPresieve Y R) Y = R := by funext Z ext f exact ⟨fun ⟨⟨_, f', h⟩, rfl⟩ => by rwa [Subsingleton.elim f f'], fun h => ⟨⟨Z, f, h⟩, rfl⟩⟩ namespace presieveOfCovering variable {ι : Type v} (U : ι → Opens X) /-- The sieve generated by `presieveOfCovering U` is a member of the grothendieck topology. -/ theorem mem_grothendieckTopology : Sieve.generate (presieveOfCovering U) ∈ Opens.grothendieckTopology X (iSup U) := by intro x hx obtain ⟨i, hxi⟩ := Opens.mem_iSup.mp hx exact ⟨U i, Opens.leSupr U i, ⟨U i, 𝟙 _, Opens.leSupr U i, ⟨i, rfl⟩, Category.id_comp _⟩, hxi⟩ /-- An index `i : ι` can be turned into a dependent pair `(V, f)`, where `V` is an open set and `f : V ⟶ iSup U` is a member of `presieveOfCovering U f`. -/ def homOfIndex (i : ι) : ΣV, { f : V ⟶ iSup U // presieveOfCovering U f } := ⟨U i, Opens.leSupr U i, i, rfl⟩ /-- By using the axiom of choice, a dependent pair `(V, f)` where `f : V ⟶ iSup U` is a member of `presieveOfCovering U f` can be turned into an index `i : ι`, such that `V = U i`. -/ def indexOfHom (f : Σ V, { f : V ⟶ iSup U // presieveOfCovering U f }) : ι := f.2.2.choose theorem indexOfHom_spec (f : Σ V, { f : V ⟶ iSup U // presieveOfCovering U f }) : f.1 = U (indexOfHom U f) := f.2.2.choose_spec end presieveOfCovering end TopCat.Presheaf namespace TopCat.Opens variable {X : TopCat} {ι : Type*} theorem coverDense_iff_isBasis [Category ι] (B : ι ⥤ Opens X) : B.IsCoverDense (Opens.grothendieckTopology X) ↔ Opens.IsBasis (Set.range B.obj) := by rw [Opens.isBasis_iff_nbhd] constructor · intro hd U x hx; rcases hd.1 U x hx with ⟨V, f, ⟨i, f₁, f₂, _⟩, hV⟩ exact ⟨B.obj i, ⟨i, rfl⟩, f₁.le hV, f₂.le⟩ intro hb; constructor; intro U x hx; rcases hb hx with ⟨_, ⟨i, rfl⟩, hx, hi⟩ exact ⟨B.obj i, ⟨⟨hi⟩⟩, ⟨⟨i, 𝟙 _, ⟨⟨hi⟩⟩, rfl⟩⟩, hx⟩ theorem coverDense_inducedFunctor {B : ι → Opens X} (h : Opens.IsBasis (Set.range B)) : (inducedFunctor B).IsCoverDense (Opens.grothendieckTopology X) := (coverDense_iff_isBasis _).2 h end TopCat.Opens section IsOpenEmbedding open TopCat.Presheaf Opposite variable {C : Type u} [Category.{v} C] variable {X Y : TopCat.{w}} {f : X ⟶ Y} {F : Y.Presheaf C} theorem Topology.IsOpenEmbedding.compatiblePreserving (hf : IsOpenEmbedding f) : CompatiblePreserving (Opens.grothendieckTopology Y) hf.isOpenMap.functor := by haveI : Mono f := (TopCat.mono_iff_injective f).mpr hf.injective apply compatiblePreservingOfDownwardsClosed intro U V i refine ⟨(Opens.map f).obj V, eqToIso <| Opens.ext <| Set.image_preimage_eq_of_subset fun x h ↦ ?_⟩ obtain ⟨_, _, rfl⟩ := i.le h exact ⟨_, rfl⟩ theorem IsOpenMap.coverPreserving (hf : IsOpenMap f) : CoverPreserving (Opens.grothendieckTopology X) (Opens.grothendieckTopology Y) hf.functor := by constructor rintro U S hU _ ⟨x, hx, rfl⟩ obtain ⟨V, i, hV, hxV⟩ := hU x hx exact ⟨_, hf.functor.map i, ⟨_, i, 𝟙 _, hV, rfl⟩, Set.mem_image_of_mem f hxV⟩
lemma Topology.IsOpenEmbedding.functor_isContinuous (h : IsOpenEmbedding f) : h.isOpenMap.functor.IsContinuous (Opens.grothendieckTopology X) (Opens.grothendieckTopology Y) := by apply Functor.isContinuous_of_coverPreserving · exact h.compatiblePreserving · exact h.isOpenMap.coverPreserving
Mathlib/Topology/Sheaves/SheafCondition/Sites.lean
161
168
/- Copyright (c) 2019 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Lu-Ming Zhang -/ import Mathlib.Data.Matrix.Invertible import Mathlib.Data.Matrix.Kronecker import Mathlib.LinearAlgebra.FiniteDimensional.Basic import Mathlib.LinearAlgebra.Matrix.Adjugate import Mathlib.LinearAlgebra.Matrix.SemiringInverse import Mathlib.LinearAlgebra.Matrix.ToLin import Mathlib.LinearAlgebra.Matrix.Trace /-! # Nonsingular inverses In this file, we define an inverse for square matrices of invertible determinant. For matrices that are not square or not of full rank, there is a more general notion of pseudoinverses which we do not consider here. The definition of inverse used in this file is the adjugate divided by the determinant. We show that dividing the adjugate by `det A` (if possible), giving a matrix `A⁻¹` (`nonsing_inv`), will result in a multiplicative inverse to `A`. Note that there are at least three different inverses in mathlib: * `A⁻¹` (`Inv.inv`): alone, this satisfies no properties, although it is usually used in conjunction with `Group` or `GroupWithZero`. On matrices, this is defined to be zero when no inverse exists. * `⅟A` (`invOf`): this is only available in the presence of `[Invertible A]`, which guarantees an inverse exists. * `Ring.inverse A`: this is defined on any `MonoidWithZero`, and just like `⁻¹` on matrices, is defined to be zero when no inverse exists. We start by working with `Invertible`, and show the main results: * `Matrix.invertibleOfDetInvertible` * `Matrix.detInvertibleOfInvertible` * `Matrix.isUnit_iff_isUnit_det` * `Matrix.mul_eq_one_comm` After this we define `Matrix.inv` and show it matches `⅟A` and `Ring.inverse A`. The rest of the results in the file are then about `A⁻¹` ## References * https://en.wikipedia.org/wiki/Cramer's_rule#Finding_inverse_matrix ## Tags matrix inverse, cramer, cramer's rule, adjugate -/ namespace Matrix universe u u' v variable {l : Type*} {m : Type u} {n : Type u'} {α : Type v} open Matrix Equiv Equiv.Perm Finset /-! ### Matrices are `Invertible` iff their determinants are -/ section Invertible variable [Fintype n] [DecidableEq n] [CommRing α] variable (A : Matrix n n α) (B : Matrix n n α) /-- If `A.det` has a constructive inverse, produce one for `A`. -/ def invertibleOfDetInvertible [Invertible A.det] : Invertible A where invOf := ⅟ A.det • A.adjugate mul_invOf_self := by rw [mul_smul_comm, mul_adjugate, smul_smul, invOf_mul_self, one_smul] invOf_mul_self := by rw [smul_mul_assoc, adjugate_mul, smul_smul, invOf_mul_self, one_smul] theorem invOf_eq [Invertible A.det] [Invertible A] : ⅟ A = ⅟ A.det • A.adjugate := by letI := invertibleOfDetInvertible A convert (rfl : ⅟ A = _) /-- `A.det` is invertible if `A` has a left inverse. -/ def detInvertibleOfLeftInverse (h : B * A = 1) : Invertible A.det where invOf := B.det mul_invOf_self := by rw [mul_comm, ← det_mul, h, det_one] invOf_mul_self := by rw [← det_mul, h, det_one] /-- `A.det` is invertible if `A` has a right inverse. -/ def detInvertibleOfRightInverse (h : A * B = 1) : Invertible A.det where invOf := B.det mul_invOf_self := by rw [← det_mul, h, det_one] invOf_mul_self := by rw [mul_comm, ← det_mul, h, det_one] /-- If `A` has a constructive inverse, produce one for `A.det`. -/ def detInvertibleOfInvertible [Invertible A] : Invertible A.det := detInvertibleOfLeftInverse A (⅟ A) (invOf_mul_self _) theorem det_invOf [Invertible A] [Invertible A.det] : (⅟ A).det = ⅟ A.det := by letI := detInvertibleOfInvertible A convert (rfl : _ = ⅟ A.det) /-- Together `Matrix.detInvertibleOfInvertible` and `Matrix.invertibleOfDetInvertible` form an equivalence, although both sides of the equiv are subsingleton anyway. -/ @[simps] def invertibleEquivDetInvertible : Invertible A ≃ Invertible A.det where toFun := @detInvertibleOfInvertible _ _ _ _ _ A invFun := @invertibleOfDetInvertible _ _ _ _ _ A left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ /-- Given a proof that `A.det` has a constructive inverse, lift `A` to `(Matrix n n α)ˣ` -/ def unitOfDetInvertible [Invertible A.det] : (Matrix n n α)ˣ := @unitOfInvertible _ _ A (invertibleOfDetInvertible A) /-- When lowered to a prop, `Matrix.invertibleEquivDetInvertible` forms an `iff`. -/ theorem isUnit_iff_isUnit_det : IsUnit A ↔ IsUnit A.det := by simp only [← nonempty_invertible_iff_isUnit, (invertibleEquivDetInvertible A).nonempty_congr] @[simp] theorem isUnits_det_units (A : (Matrix n n α)ˣ) : IsUnit (A : Matrix n n α).det := isUnit_iff_isUnit_det _ |>.mp A.isUnit /-! #### Variants of the statements above with `IsUnit` -/ theorem isUnit_det_of_invertible [Invertible A] : IsUnit A.det := @isUnit_of_invertible _ _ _ (detInvertibleOfInvertible A) variable {A B} theorem isUnit_det_of_left_inverse (h : B * A = 1) : IsUnit A.det := @isUnit_of_invertible _ _ _ (detInvertibleOfLeftInverse _ _ h) theorem isUnit_det_of_right_inverse (h : A * B = 1) : IsUnit A.det := @isUnit_of_invertible _ _ _ (detInvertibleOfRightInverse _ _ h) theorem det_ne_zero_of_left_inverse [Nontrivial α] (h : B * A = 1) : A.det ≠ 0 := (isUnit_det_of_left_inverse h).ne_zero theorem det_ne_zero_of_right_inverse [Nontrivial α] (h : A * B = 1) : A.det ≠ 0 := (isUnit_det_of_right_inverse h).ne_zero end Invertible section Inv variable [Fintype n] [DecidableEq n] [CommRing α] variable (A : Matrix n n α) (B : Matrix n n α) theorem isUnit_det_transpose (h : IsUnit A.det) : IsUnit Aᵀ.det := by rw [det_transpose] exact h /-! ### A noncomputable `Inv` instance -/ /-- The inverse of a square matrix, when it is invertible (and zero otherwise). -/ noncomputable instance inv : Inv (Matrix n n α) := ⟨fun A => Ring.inverse A.det • A.adjugate⟩ theorem inv_def (A : Matrix n n α) : A⁻¹ = Ring.inverse A.det • A.adjugate := rfl theorem nonsing_inv_apply_not_isUnit (h : ¬IsUnit A.det) : A⁻¹ = 0 := by rw [inv_def, Ring.inverse_non_unit _ h, zero_smul] theorem nonsing_inv_apply (h : IsUnit A.det) : A⁻¹ = (↑h.unit⁻¹ : α) • A.adjugate := by rw [inv_def, ← Ring.inverse_unit h.unit, IsUnit.unit_spec] /-- The nonsingular inverse is the same as `invOf` when `A` is invertible. -/ @[simp] theorem invOf_eq_nonsing_inv [Invertible A] : ⅟ A = A⁻¹ := by letI := detInvertibleOfInvertible A rw [inv_def, Ring.inverse_invertible, invOf_eq] /-- Coercing the result of `Units.instInv` is the same as coercing first and applying the nonsingular inverse. -/ @[simp, norm_cast] theorem coe_units_inv (A : (Matrix n n α)ˣ) : ↑A⁻¹ = (A⁻¹ : Matrix n n α) := by letI := A.invertible rw [← invOf_eq_nonsing_inv, invOf_units] /-- The nonsingular inverse is the same as the general `Ring.inverse`. -/ theorem nonsing_inv_eq_ringInverse : A⁻¹ = Ring.inverse A := by by_cases h_det : IsUnit A.det · cases (A.isUnit_iff_isUnit_det.mpr h_det).nonempty_invertible rw [← invOf_eq_nonsing_inv, Ring.inverse_invertible] · have h := mt A.isUnit_iff_isUnit_det.mp h_det rw [Ring.inverse_non_unit _ h, nonsing_inv_apply_not_isUnit A h_det] @[deprecated (since := "2025-04-22")] alias nonsing_inv_eq_ring_inverse := nonsing_inv_eq_ringInverse theorem transpose_nonsing_inv : A⁻¹ᵀ = Aᵀ⁻¹ := by rw [inv_def, inv_def, transpose_smul, det_transpose, adjugate_transpose] theorem conjTranspose_nonsing_inv [StarRing α] : A⁻¹ᴴ = Aᴴ⁻¹ := by rw [inv_def, inv_def, conjTranspose_smul, det_conjTranspose, adjugate_conjTranspose, Ring.inverse_star] /-- The `nonsing_inv` of `A` is a right inverse. -/ @[simp] theorem mul_nonsing_inv (h : IsUnit A.det) : A * A⁻¹ = 1 := by cases (A.isUnit_iff_isUnit_det.mpr h).nonempty_invertible rw [← invOf_eq_nonsing_inv, mul_invOf_self] /-- The `nonsing_inv` of `A` is a left inverse. -/ @[simp] theorem nonsing_inv_mul (h : IsUnit A.det) : A⁻¹ * A = 1 := by cases (A.isUnit_iff_isUnit_det.mpr h).nonempty_invertible rw [← invOf_eq_nonsing_inv, invOf_mul_self] instance [Invertible A] : Invertible A⁻¹ := by rw [← invOf_eq_nonsing_inv] infer_instance @[simp] theorem inv_inv_of_invertible [Invertible A] : A⁻¹⁻¹ = A := by simp only [← invOf_eq_nonsing_inv, invOf_invOf] @[simp] theorem mul_nonsing_inv_cancel_right (B : Matrix m n α) (h : IsUnit A.det) : B * A * A⁻¹ = B := by simp [Matrix.mul_assoc, mul_nonsing_inv A h] @[simp] theorem mul_nonsing_inv_cancel_left (B : Matrix n m α) (h : IsUnit A.det) : A * (A⁻¹ * B) = B := by simp [← Matrix.mul_assoc, mul_nonsing_inv A h] @[simp] theorem nonsing_inv_mul_cancel_right (B : Matrix m n α) (h : IsUnit A.det) : B * A⁻¹ * A = B := by simp [Matrix.mul_assoc, nonsing_inv_mul A h] @[simp] theorem nonsing_inv_mul_cancel_left (B : Matrix n m α) (h : IsUnit A.det) : A⁻¹ * (A * B) = B := by simp [← Matrix.mul_assoc, nonsing_inv_mul A h] @[simp] theorem mul_inv_of_invertible [Invertible A] : A * A⁻¹ = 1 := mul_nonsing_inv A (isUnit_det_of_invertible A) @[simp] theorem inv_mul_of_invertible [Invertible A] : A⁻¹ * A = 1 := nonsing_inv_mul A (isUnit_det_of_invertible A) @[simp] theorem mul_inv_cancel_right_of_invertible (B : Matrix m n α) [Invertible A] : B * A * A⁻¹ = B := mul_nonsing_inv_cancel_right A B (isUnit_det_of_invertible A) @[simp] theorem mul_inv_cancel_left_of_invertible (B : Matrix n m α) [Invertible A] : A * (A⁻¹ * B) = B := mul_nonsing_inv_cancel_left A B (isUnit_det_of_invertible A) @[simp] theorem inv_mul_cancel_right_of_invertible (B : Matrix m n α) [Invertible A] : B * A⁻¹ * A = B := nonsing_inv_mul_cancel_right A B (isUnit_det_of_invertible A) @[simp] theorem inv_mul_cancel_left_of_invertible (B : Matrix n m α) [Invertible A] : A⁻¹ * (A * B) = B := nonsing_inv_mul_cancel_left A B (isUnit_det_of_invertible A) theorem inv_mul_eq_iff_eq_mul_of_invertible (A B C : Matrix n n α) [Invertible A] : A⁻¹ * B = C ↔ B = A * C := ⟨fun h => by rw [← h, mul_inv_cancel_left_of_invertible], fun h => by rw [h, inv_mul_cancel_left_of_invertible]⟩ theorem mul_inv_eq_iff_eq_mul_of_invertible (A B C : Matrix n n α) [Invertible A] : B * A⁻¹ = C ↔ B = C * A := ⟨fun h => by rw [← h, inv_mul_cancel_right_of_invertible], fun h => by rw [h, mul_inv_cancel_right_of_invertible]⟩ lemma inv_mulVec_eq_vec {A : Matrix n n α} [Invertible A] {u v : n → α} (hM : u = A.mulVec v) : A⁻¹.mulVec u = v := by rw [hM, Matrix.mulVec_mulVec, Matrix.inv_mul_of_invertible, Matrix.one_mulVec] lemma mul_right_injective_of_invertible [Invertible A] : Function.Injective (fun (x : Matrix n m α) => A * x) := fun _ _ h => by simpa only [inv_mul_cancel_left_of_invertible] using congr_arg (A⁻¹ * ·) h lemma mul_left_injective_of_invertible [Invertible A] : Function.Injective (fun (x : Matrix m n α) => x * A) := fun a x hax => by simpa only [mul_inv_cancel_right_of_invertible] using congr_arg (· * A⁻¹) hax lemma mul_right_inj_of_invertible [Invertible A] {x y : Matrix n m α} : A * x = A * y ↔ x = y := (mul_right_injective_of_invertible A).eq_iff lemma mul_left_inj_of_invertible [Invertible A] {x y : Matrix m n α} : x * A = y * A ↔ x = y := (mul_left_injective_of_invertible A).eq_iff end Inv section InjectiveMul variable [Fintype n] [Fintype m] [DecidableEq m] [CommRing α] lemma mul_left_injective_of_inv (A : Matrix m n α) (B : Matrix n m α) (h : A * B = 1) : Function.Injective (fun x : Matrix l m α => x * A) := fun _ _ g => by simpa only [Matrix.mul_assoc, Matrix.mul_one, h] using congr_arg (· * B) g lemma mul_right_injective_of_inv (A : Matrix m n α) (B : Matrix n m α) (h : A * B = 1) : Function.Injective (fun x : Matrix m l α => B * x) := fun _ _ g => by simpa only [← Matrix.mul_assoc, Matrix.one_mul, h] using congr_arg (A * ·) g end InjectiveMul section vecMul section Semiring variable {R : Type*} [Semiring R] theorem vecMul_surjective_iff_exists_left_inverse [DecidableEq n] [Fintype m] [Finite n] {A : Matrix m n R} : Function.Surjective A.vecMul ↔ ∃ B : Matrix n m R, B * A = 1 := by cases nonempty_fintype n refine ⟨fun h ↦ ?_, fun ⟨B, hBA⟩ y ↦ ⟨y ᵥ* B, by simp [hBA]⟩⟩ choose rows hrows using (h <| Pi.single · 1) refine ⟨Matrix.of rows, Matrix.ext fun i j => ?_⟩ rw [mul_apply_eq_vecMul, one_eq_pi_single, ← hrows] rfl theorem mulVec_surjective_iff_exists_right_inverse [DecidableEq m] [Finite m] [Fintype n] {A : Matrix m n R} : Function.Surjective A.mulVec ↔ ∃ B : Matrix n m R, A * B = 1 := by cases nonempty_fintype m refine ⟨fun h ↦ ?_, fun ⟨B, hBA⟩ y ↦ ⟨B *ᵥ y, by simp [hBA]⟩⟩ choose cols hcols using (h <| Pi.single · 1) refine ⟨(Matrix.of cols)ᵀ, Matrix.ext fun i j ↦ ?_⟩ rw [one_eq_pi_single, Pi.single_comm, ← hcols j] rfl end Semiring variable [DecidableEq m] {R K : Type*} [CommRing R] [Field K] [Fintype m] theorem vecMul_surjective_iff_isUnit {A : Matrix m m R} : Function.Surjective A.vecMul ↔ IsUnit A := by rw [vecMul_surjective_iff_exists_left_inverse, exists_left_inverse_iff_isUnit] theorem mulVec_surjective_iff_isUnit {A : Matrix m m R} : Function.Surjective A.mulVec ↔ IsUnit A := by rw [mulVec_surjective_iff_exists_right_inverse, exists_right_inverse_iff_isUnit] theorem vecMul_injective_iff_isUnit {A : Matrix m m K} : Function.Injective A.vecMul ↔ IsUnit A := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rw [← vecMul_surjective_iff_isUnit] exact LinearMap.surjective_of_injective (f := A.vecMulLinear) h change Function.Injective A.vecMulLinear rw [← LinearMap.ker_eq_bot, LinearMap.ker_eq_bot'] intro c hc replace h := h.invertible simpa using congr_arg A⁻¹.vecMulLinear hc theorem mulVec_injective_iff_isUnit {A : Matrix m m K} : Function.Injective A.mulVec ↔ IsUnit A := by rw [← isUnit_transpose, ← vecMul_injective_iff_isUnit] simp_rw [vecMul_transpose] theorem linearIndependent_rows_iff_isUnit {A : Matrix m m K} : LinearIndependent K A.row ↔ IsUnit A := by rw [← col_transpose, ← mulVec_injective_iff, ← coe_mulVecLin, mulVecLin_transpose, ← vecMul_injective_iff_isUnit, coe_vecMulLinear] theorem linearIndependent_cols_iff_isUnit {A : Matrix m m K} : LinearIndependent K A.col ↔ IsUnit A := by rw [← row_transpose, linearIndependent_rows_iff_isUnit, isUnit_transpose] theorem vecMul_surjective_of_invertible (A : Matrix m m R) [Invertible A] : Function.Surjective A.vecMul := vecMul_surjective_iff_isUnit.2 <| isUnit_of_invertible A theorem mulVec_surjective_of_invertible (A : Matrix m m R) [Invertible A] : Function.Surjective A.mulVec := mulVec_surjective_iff_isUnit.2 <| isUnit_of_invertible A theorem vecMul_injective_of_invertible (A : Matrix m m K) [Invertible A] : Function.Injective A.vecMul := vecMul_injective_iff_isUnit.2 <| isUnit_of_invertible A theorem mulVec_injective_of_invertible (A : Matrix m m K) [Invertible A] : Function.Injective A.mulVec := mulVec_injective_iff_isUnit.2 <| isUnit_of_invertible A theorem linearIndependent_rows_of_invertible (A : Matrix m m K) [Invertible A] : LinearIndependent K A.row := linearIndependent_rows_iff_isUnit.2 <| isUnit_of_invertible A theorem linearIndependent_cols_of_invertible (A : Matrix m m K) [Invertible A] : LinearIndependent K A.col := linearIndependent_cols_iff_isUnit.2 <| isUnit_of_invertible A end vecMul variable [Fintype n] [DecidableEq n] [CommRing α] variable (A : Matrix n n α) (B : Matrix n n α) theorem nonsing_inv_cancel_or_zero : A⁻¹ * A = 1 ∧ A * A⁻¹ = 1 ∨ A⁻¹ = 0 := by by_cases h : IsUnit A.det · exact Or.inl ⟨nonsing_inv_mul _ h, mul_nonsing_inv _ h⟩ · exact Or.inr (nonsing_inv_apply_not_isUnit _ h) theorem det_nonsing_inv_mul_det (h : IsUnit A.det) : A⁻¹.det * A.det = 1 := by rw [← det_mul, A.nonsing_inv_mul h, det_one] @[simp] theorem det_nonsing_inv : A⁻¹.det = Ring.inverse A.det := by by_cases h : IsUnit A.det · cases h.nonempty_invertible letI := invertibleOfDetInvertible A rw [Ring.inverse_invertible, ← invOf_eq_nonsing_inv, det_invOf] cases isEmpty_or_nonempty n · rw [det_isEmpty, det_isEmpty, Ring.inverse_one] · rw [Ring.inverse_non_unit _ h, nonsing_inv_apply_not_isUnit _ h, det_zero ‹_›] theorem isUnit_nonsing_inv_det (h : IsUnit A.det) : IsUnit A⁻¹.det := isUnit_of_mul_eq_one _ _ (A.det_nonsing_inv_mul_det h) @[simp] theorem nonsing_inv_nonsing_inv (h : IsUnit A.det) : A⁻¹⁻¹ = A := calc A⁻¹⁻¹ = 1 * A⁻¹⁻¹ := by rw [Matrix.one_mul] _ = A * A⁻¹ * A⁻¹⁻¹ := by rw [A.mul_nonsing_inv h] _ = A := by rw [Matrix.mul_assoc, A⁻¹.mul_nonsing_inv (A.isUnit_nonsing_inv_det h), Matrix.mul_one] theorem isUnit_nonsing_inv_det_iff {A : Matrix n n α} : IsUnit A⁻¹.det ↔ IsUnit A.det := by rw [Matrix.det_nonsing_inv, isUnit_ringInverse] @[simp] theorem isUnit_nonsing_inv_iff {A : Matrix n n α} : IsUnit A⁻¹ ↔ IsUnit A := by simp_rw [isUnit_iff_isUnit_det, isUnit_nonsing_inv_det_iff] -- `IsUnit.invertible` lifts the proposition `IsUnit A` to a constructive inverse of `A`. /-- A version of `Matrix.invertibleOfDetInvertible` with the inverse defeq to `A⁻¹` that is therefore noncomputable. -/ noncomputable def invertibleOfIsUnitDet (h : IsUnit A.det) : Invertible A := ⟨A⁻¹, nonsing_inv_mul A h, mul_nonsing_inv A h⟩ /-- A version of `Matrix.unitOfDetInvertible` with the inverse defeq to `A⁻¹` that is therefore noncomputable. -/ noncomputable def nonsingInvUnit (h : IsUnit A.det) : (Matrix n n α)ˣ := @unitOfInvertible _ _ _ (invertibleOfIsUnitDet A h) theorem unitOfDetInvertible_eq_nonsingInvUnit [Invertible A.det] : unitOfDetInvertible A = nonsingInvUnit A (isUnit_of_invertible _) := by ext rfl variable {A} {B} /-- If matrix A is left invertible, then its inverse equals its left inverse. -/ theorem inv_eq_left_inv (h : B * A = 1) : A⁻¹ = B := letI := invertibleOfLeftInverse _ _ h invOf_eq_nonsing_inv A ▸ invOf_eq_left_inv h /-- If matrix A is right invertible, then its inverse equals its right inverse. -/ theorem inv_eq_right_inv (h : A * B = 1) : A⁻¹ = B := inv_eq_left_inv (mul_eq_one_comm.2 h) section InvEqInv variable {C : Matrix n n α} /-- The left inverse of matrix A is unique when existing. -/ theorem left_inv_eq_left_inv (h : B * A = 1) (g : C * A = 1) : B = C := by rw [← inv_eq_left_inv h, ← inv_eq_left_inv g] /-- The right inverse of matrix A is unique when existing. -/ theorem right_inv_eq_right_inv (h : A * B = 1) (g : A * C = 1) : B = C := by rw [← inv_eq_right_inv h, ← inv_eq_right_inv g] /-- The right inverse of matrix A equals the left inverse of A when they exist. -/ theorem right_inv_eq_left_inv (h : A * B = 1) (g : C * A = 1) : B = C := by rw [← inv_eq_right_inv h, ← inv_eq_left_inv g] theorem inv_inj (h : A⁻¹ = B⁻¹) (h' : IsUnit A.det) : A = B := by refine left_inv_eq_left_inv (mul_nonsing_inv _ h') ?_ rw [h] refine mul_nonsing_inv _ ?_ rwa [← isUnit_nonsing_inv_det_iff, ← h, isUnit_nonsing_inv_det_iff] end InvEqInv variable (A) @[simp] theorem inv_zero : (0 : Matrix n n α)⁻¹ = 0 := by rcases subsingleton_or_nontrivial α with ht | ht · simp [eq_iff_true_of_subsingleton] rcases (Fintype.card n).zero_le.eq_or_lt with hc | hc · rw [eq_comm, Fintype.card_eq_zero_iff] at hc haveI := hc ext i exact (IsEmpty.false i).elim · have hn : Nonempty n := Fintype.card_pos_iff.mp hc refine nonsing_inv_apply_not_isUnit _ ?_ simp [hn] noncomputable instance : InvOneClass (Matrix n n α) := { Matrix.one, Matrix.inv with inv_one := inv_eq_left_inv (by simp) } theorem inv_smul (k : α) [Invertible k] (h : IsUnit A.det) : (k • A)⁻¹ = ⅟ k • A⁻¹ := inv_eq_left_inv (by simp [h, smul_smul]) theorem inv_smul' (k : αˣ) (h : IsUnit A.det) : (k • A)⁻¹ = k⁻¹ • A⁻¹ := inv_eq_left_inv (by simp [h, smul_smul]) theorem inv_adjugate (A : Matrix n n α) (h : IsUnit A.det) : (adjugate A)⁻¹ = h.unit⁻¹ • A := by refine inv_eq_left_inv ?_ rw [smul_mul, mul_adjugate, Units.smul_def, smul_smul, h.val_inv_mul, one_smul] section Diagonal /-- `diagonal v` is invertible if `v` is -/ def diagonalInvertible {α} [NonAssocSemiring α] (v : n → α) [Invertible v] : Invertible (diagonal v) := Invertible.map (diagonalRingHom n α) v theorem invOf_diagonal_eq {α} [Semiring α] (v : n → α) [Invertible v] [Invertible (diagonal v)] : ⅟ (diagonal v) = diagonal (⅟ v) := by rw [@Invertible.congr _ _ _ _ _ (diagonalInvertible v) rfl] rfl /-- `v` is invertible if `diagonal v` is -/ def invertibleOfDiagonalInvertible (v : n → α) [Invertible (diagonal v)] : Invertible v where invOf := diag (⅟ (diagonal v)) invOf_mul_self := funext fun i => by letI : Invertible (diagonal v).det := detInvertibleOfInvertible _ rw [invOf_eq, diag_smul, adjugate_diagonal, diag_diagonal] dsimp rw [mul_assoc, prod_erase_mul _ _ (Finset.mem_univ _), ← det_diagonal] exact mul_invOf_self _ mul_invOf_self := funext fun i => by letI : Invertible (diagonal v).det := detInvertibleOfInvertible _ rw [invOf_eq, diag_smul, adjugate_diagonal, diag_diagonal] dsimp rw [mul_left_comm, mul_prod_erase _ _ (Finset.mem_univ _), ← det_diagonal] exact mul_invOf_self _ /-- Together `Matrix.diagonalInvertible` and `Matrix.invertibleOfDiagonalInvertible` form an equivalence, although both sides of the equiv are subsingleton anyway. -/ @[simps] def diagonalInvertibleEquivInvertible (v : n → α) : Invertible (diagonal v) ≃ Invertible v where toFun := @invertibleOfDiagonalInvertible _ _ _ _ _ _ invFun := @diagonalInvertible _ _ _ _ _ _ left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ /-- When lowered to a prop, `Matrix.diagonalInvertibleEquivInvertible` forms an `iff`. -/ @[simp] theorem isUnit_diagonal {v : n → α} : IsUnit (diagonal v) ↔ IsUnit v := by simp only [← nonempty_invertible_iff_isUnit, (diagonalInvertibleEquivInvertible v).nonempty_congr] theorem inv_diagonal (v : n → α) : (diagonal v)⁻¹ = diagonal (Ring.inverse v) := by rw [nonsing_inv_eq_ringInverse] by_cases h : IsUnit v · have := isUnit_diagonal.mpr h cases this.nonempty_invertible cases h.nonempty_invertible rw [Ring.inverse_invertible, Ring.inverse_invertible, invOf_diagonal_eq] · have := isUnit_diagonal.not.mpr h rw [Ring.inverse_non_unit _ h, Pi.zero_def, diagonal_zero, Ring.inverse_non_unit _ this] end Diagonal /-- The inverse of a 1×1 or 0×0 matrix is always diagonal. While we could write this as `of fun _ _ => Ring.inverse (A default default)` on the RHS, this is less useful because: * It wouldn't work for 0×0 matrices. * More things are true about diagonal matrices than constant matrices, and so more lemmas exist. `Matrix.diagonal_unique` can be used to reach this form, while `Ring.inverse_eq_inv` can be used to replace `Ring.inverse` with `⁻¹`. -/ @[simp] theorem inv_subsingleton [Subsingleton m] [Fintype m] [DecidableEq m] (A : Matrix m m α) : A⁻¹ = diagonal fun i => Ring.inverse (A i i) := by rw [inv_def, adjugate_subsingleton, smul_one_eq_diagonal] congr! with i exact det_eq_elem_of_subsingleton _ _ section Woodbury variable [Fintype m] [DecidableEq m] variable (A : Matrix n n α) (U : Matrix n m α) (C : Matrix m m α) (V : Matrix m n α) /-- The **Woodbury Identity** (`⁻¹` version). -/ theorem add_mul_mul_inv_eq_sub (hA : IsUnit A) (hC : IsUnit C) (hAC : IsUnit (C⁻¹ + V * A⁻¹ * U)) : (A + U * C * V)⁻¹ = A⁻¹ - A⁻¹ * U * (C⁻¹ + V * A⁻¹ * U)⁻¹ * V * A⁻¹ := by obtain ⟨_⟩ := hA.nonempty_invertible obtain ⟨_⟩ := hC.nonempty_invertible obtain ⟨iAC⟩ := hAC.nonempty_invertible simp only [← invOf_eq_nonsing_inv] at iAC letI := invertibleAddMulMul A U C V simp only [← invOf_eq_nonsing_inv] apply invOf_add_mul_mul end Woodbury @[simp] theorem inv_inv_inv (A : Matrix n n α) : A⁻¹⁻¹⁻¹ = A⁻¹ := by by_cases h : IsUnit A.det
· rw [nonsing_inv_nonsing_inv _ h] · simp [nonsing_inv_apply_not_isUnit _ h] /-- The `Matrix` version of `inv_add_inv'` -/ theorem inv_add_inv {A B : Matrix n n α} (h : IsUnit A ↔ IsUnit B) :
Mathlib/LinearAlgebra/Matrix/NonsingularInverse.lean
609
613
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Shift.Basic import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor /-! Sequences of functors from a category equipped with a shift Let `F : C ⥤ A` be a functor from a category `C` that is equipped with a shift by an additive monoid `M`. In this file, we define a typeclass `F.ShiftSequence M` which includes the data of a sequence of functors `F.shift a : C ⥤ A` for all `a : A`. For each `a : A`, we have an isomorphism `F.isoShift a : shiftFunctor C a ⋙ F ≅ F.shift a` which satisfies some coherence relations. This allows to state results (e.g. the long exact sequence of an homology functor (TODO)) using functors `F.shift a` rather than `shiftFunctor C a ⋙ F`. The reason for this design is that we can often choose functors `F.shift a` that have better definitional properties than `shiftFunctor C a ⋙ F`. For example, if `C` is the derived category (TODO) of an abelian category `A` and `F` is the homology functor in degree `0`, then for any `n : ℤ`, we may choose `F.shift n` to be the homology functor in degree `n`. -/ open CategoryTheory Category ZeroObject Limits variable {C A : Type*} [Category C] [Category A] (F : C ⥤ A) (M : Type*) [AddMonoid M] [HasShift C M] {G : Type*} [AddGroup G] [HasShift C G] namespace CategoryTheory namespace Functor /-- A shift sequence for a functor `F : C ⥤ A` when `C` is equipped with a shift by a monoid `M` involves a sequence of functor `sequence n : C ⥤ A` for all `n : M` which behave like `shiftFunctor C n ⋙ F`. -/ class ShiftSequence where /-- a sequence of functors -/ sequence : M → C ⥤ A /-- `sequence 0` identifies to the given functor -/ isoZero : sequence 0 ≅ F /-- compatibility isomorphism with the shift -/ shiftIso (n a a' : M) (ha' : n + a = a') : shiftFunctor C n ⋙ sequence a ≅ sequence a' shiftIso_zero (a : M) : shiftIso 0 a a (zero_add a) = isoWhiskerRight (shiftFunctorZero C M) _ ≪≫ leftUnitor _ shiftIso_add : ∀ (n m a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a''), shiftIso (m + n) a a'' (by rw [add_assoc, ha', ha'']) = isoWhiskerRight (shiftFunctorAdd C m n) _ ≪≫ Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ (shiftIso n a a' ha') ≪≫ shiftIso m a' a'' ha'' /-- The tautological shift sequence on a functor. -/ noncomputable def ShiftSequence.tautological : ShiftSequence F M where sequence n := shiftFunctor C n ⋙ F isoZero := isoWhiskerRight (shiftFunctorZero C M) F ≪≫ F.rightUnitor shiftIso n a a' ha' := (Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (shiftFunctorAdd' C n a a' ha').symm _ shiftIso_zero a := by rw [shiftFunctorAdd'_zero_add] aesop_cat shiftIso_add n m a a' a'' ha' ha'' := by ext X dsimp simp only [id_comp, ← Functor.map_comp] congr simpa only [← cancel_epi ((shiftFunctor C a).map ((shiftFunctorAdd C m n).hom.app X)), shiftFunctorAdd'_eq_shiftFunctorAdd, ← Functor.map_comp_assoc, Iso.hom_inv_id_app, Functor.map_id, id_comp] using shiftFunctorAdd'_assoc_inv_app m n a (m+n) a' a'' rfl ha' (by rw [← ha'', ← ha', add_assoc]) X section variable {M} variable [F.ShiftSequence M] /-- The shifted functors given by the shift sequence. -/ def shift (n : M) : C ⥤ A := ShiftSequence.sequence F n /-- Compatibility isomorphism `shiftFunctor C n ⋙ F.shift a ≅ F.shift a'` when `n + a = a'`. -/ def shiftIso (n a a' : M) (ha' : n + a = a') : shiftFunctor C n ⋙ F.shift a ≅ F.shift a' := ShiftSequence.shiftIso n a a' ha' @[reassoc (attr := simp)] lemma shiftIso_hom_naturality {X Y : C} (n a a' : M) (ha' : n + a = a') (f : X ⟶ Y) : (shift F a).map (f⟦n⟧') ≫ (shiftIso F n a a' ha').hom.app Y = (shiftIso F n a a' ha').hom.app X ≫ (shift F a').map f := (F.shiftIso n a a' ha').hom.naturality f @[reassoc] lemma shiftIso_inv_naturality {X Y : C} (n a a' : M) (ha' : n + a = a') (f : X ⟶ Y) : (shift F a').map f ≫ (shiftIso F n a a' ha').inv.app Y = (shiftIso F n a a' ha').inv.app X ≫ (shift F a).map (f⟦n⟧') := by simp variable (M) in /-- The canonical isomorphism `F.shift 0 ≅ F`. -/ def isoShiftZero : F.shift (0 : M) ≅ F := ShiftSequence.isoZero /-- The canonical isomorphism `shiftFunctor C n ⋙ F ≅ F.shift n`. -/ def isoShift (n : M) : shiftFunctor C n ⋙ F ≅ F.shift n := isoWhiskerLeft _ (F.isoShiftZero M).symm ≪≫ F.shiftIso _ _ _ (add_zero n) @[reassoc] lemma isoShift_hom_naturality (n : M) {X Y : C} (f : X ⟶ Y) : F.map (f⟦n⟧') ≫ (F.isoShift n).hom.app Y = (F.isoShift n).hom.app X ≫ (F.shift n).map f := (F.isoShift n).hom.naturality f attribute [simp] isoShift_hom_naturality @[reassoc] lemma isoShift_inv_naturality (n : M) {X Y : C} (f : X ⟶ Y) : (F.shift n).map f ≫ (F.isoShift n).inv.app Y = (F.isoShift n).inv.app X ≫ F.map (f⟦n⟧') := (F.isoShift n).inv.naturality f lemma shiftIso_zero (a : M) : F.shiftIso 0 a a (zero_add a) = isoWhiskerRight (shiftFunctorZero C M) _ ≪≫ leftUnitor _ := ShiftSequence.shiftIso_zero a @[simp] lemma shiftIso_zero_hom_app (a : M) (X : C) : (F.shiftIso 0 a a (zero_add a)).hom.app X = (shift F a).map ((shiftFunctorZero C M).hom.app X) := by simp [F.shiftIso_zero a] @[simp] lemma shiftIso_zero_inv_app (a : M) (X : C) : (F.shiftIso 0 a a (zero_add a)).inv.app X = (shift F a).map ((shiftFunctorZero C M).inv.app X) := by simp [F.shiftIso_zero a] lemma shiftIso_add (n m a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a'') : F.shiftIso (m + n) a a'' (by rw [add_assoc, ha', ha'']) = isoWhiskerRight (shiftFunctorAdd C m n) _ ≪≫ Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ (F.shiftIso n a a' ha') ≪≫ F.shiftIso m a' a'' ha'' := ShiftSequence.shiftIso_add _ _ _ _ _ _ _ lemma shiftIso_add_hom_app (n m a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a'') (X : C) : (F.shiftIso (m + n) a a'' (by rw [add_assoc, ha', ha''])).hom.app X = (shift F a).map ((shiftFunctorAdd C m n).hom.app X) ≫ (shiftIso F n a a' ha').hom.app ((shiftFunctor C m).obj X) ≫ (shiftIso F m a' a'' ha'').hom.app X := by simp [F.shiftIso_add n m a a' a'' ha' ha''] lemma shiftIso_add_inv_app (n m a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a'') (X : C) : (F.shiftIso (m + n) a a'' (by rw [add_assoc, ha', ha''])).inv.app X = (shiftIso F m a' a'' ha'').inv.app X ≫ (shiftIso F n a a' ha').inv.app ((shiftFunctor C m).obj X) ≫ (shift F a).map ((shiftFunctorAdd C m n).inv.app X) := by simp [F.shiftIso_add n m a a' a'' ha' ha''] lemma shiftIso_add' (n m mn : M) (hnm : m + n = mn) (a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a'') : F.shiftIso mn a a'' (by rw [← hnm, ← ha'', ← ha', add_assoc]) = isoWhiskerRight (shiftFunctorAdd' C m n _ hnm) _ ≪≫ Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ (F.shiftIso n a a' ha') ≪≫ F.shiftIso m a' a'' ha'' := by subst hnm rw [shiftFunctorAdd'_eq_shiftFunctorAdd, shiftIso_add] lemma shiftIso_add'_hom_app (n m mn : M) (hnm : m + n = mn) (a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a'') (X : C) : (F.shiftIso mn a a'' (by rw [← hnm, ← ha'', ← ha', add_assoc])).hom.app X = (shift F a).map ((shiftFunctorAdd' C m n mn hnm).hom.app X) ≫ (shiftIso F n a a' ha').hom.app ((shiftFunctor C m).obj X) ≫ (shiftIso F m a' a'' ha'').hom.app X := by simp [F.shiftIso_add' n m mn hnm a a' a'' ha' ha''] lemma shiftIso_add'_inv_app (n m mn : M) (hnm : m + n = mn) (a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a'') (X : C) : (F.shiftIso mn a a'' (by rw [← hnm, ← ha'', ← ha', add_assoc])).inv.app X = (shiftIso F m a' a'' ha'').inv.app X ≫
(shiftIso F n a a' ha').inv.app ((shiftFunctor C m).obj X) ≫ (shift F a).map ((shiftFunctorAdd' C m n mn hnm).inv.app X) := by simp [F.shiftIso_add' n m mn hnm a a' a'' ha' ha''] @[reassoc] lemma shiftIso_hom_app_comp (n m mn : M) (hnm : m + n = mn) (a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a'') (X : C) :
Mathlib/CategoryTheory/Shift/ShiftSequence.lean
178
184
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Shift.Basic import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor /-! Sequences of functors from a category equipped with a shift Let `F : C ⥤ A` be a functor from a category `C` that is equipped with a shift by an additive monoid `M`. In this file, we define a typeclass `F.ShiftSequence M` which includes the data of a sequence of functors `F.shift a : C ⥤ A` for all `a : A`. For each `a : A`, we have an isomorphism `F.isoShift a : shiftFunctor C a ⋙ F ≅ F.shift a` which satisfies some coherence relations. This allows to state results (e.g. the long exact sequence of an homology functor (TODO)) using functors `F.shift a` rather than `shiftFunctor C a ⋙ F`. The reason for this design is that we can often choose functors `F.shift a` that have better definitional properties than `shiftFunctor C a ⋙ F`. For example, if `C` is the derived category (TODO) of an abelian category `A` and `F` is the homology functor in degree `0`, then for any `n : ℤ`, we may choose `F.shift n` to be the homology functor in degree `n`. -/ open CategoryTheory Category ZeroObject Limits variable {C A : Type*} [Category C] [Category A] (F : C ⥤ A) (M : Type*) [AddMonoid M] [HasShift C M] {G : Type*} [AddGroup G] [HasShift C G] namespace CategoryTheory namespace Functor /-- A shift sequence for a functor `F : C ⥤ A` when `C` is equipped with a shift by a monoid `M` involves a sequence of functor `sequence n : C ⥤ A` for all `n : M` which behave like `shiftFunctor C n ⋙ F`. -/ class ShiftSequence where /-- a sequence of functors -/ sequence : M → C ⥤ A /-- `sequence 0` identifies to the given functor -/ isoZero : sequence 0 ≅ F /-- compatibility isomorphism with the shift -/ shiftIso (n a a' : M) (ha' : n + a = a') : shiftFunctor C n ⋙ sequence a ≅ sequence a' shiftIso_zero (a : M) : shiftIso 0 a a (zero_add a) = isoWhiskerRight (shiftFunctorZero C M) _ ≪≫ leftUnitor _ shiftIso_add : ∀ (n m a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a''), shiftIso (m + n) a a'' (by rw [add_assoc, ha', ha'']) = isoWhiskerRight (shiftFunctorAdd C m n) _ ≪≫ Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ (shiftIso n a a' ha') ≪≫ shiftIso m a' a'' ha'' /-- The tautological shift sequence on a functor. -/ noncomputable def ShiftSequence.tautological : ShiftSequence F M where sequence n := shiftFunctor C n ⋙ F isoZero := isoWhiskerRight (shiftFunctorZero C M) F ≪≫ F.rightUnitor shiftIso n a a' ha' := (Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (shiftFunctorAdd' C n a a' ha').symm _ shiftIso_zero a := by rw [shiftFunctorAdd'_zero_add] aesop_cat shiftIso_add n m a a' a'' ha' ha'' := by ext X dsimp simp only [id_comp, ← Functor.map_comp] congr simpa only [← cancel_epi ((shiftFunctor C a).map ((shiftFunctorAdd C m n).hom.app X)), shiftFunctorAdd'_eq_shiftFunctorAdd, ← Functor.map_comp_assoc, Iso.hom_inv_id_app, Functor.map_id, id_comp] using shiftFunctorAdd'_assoc_inv_app m n a (m+n) a' a'' rfl ha' (by rw [← ha'', ← ha', add_assoc]) X section variable {M} variable [F.ShiftSequence M] /-- The shifted functors given by the shift sequence. -/ def shift (n : M) : C ⥤ A := ShiftSequence.sequence F n /-- Compatibility isomorphism `shiftFunctor C n ⋙ F.shift a ≅ F.shift a'` when `n + a = a'`. -/ def shiftIso (n a a' : M) (ha' : n + a = a') : shiftFunctor C n ⋙ F.shift a ≅ F.shift a' := ShiftSequence.shiftIso n a a' ha' @[reassoc (attr := simp)] lemma shiftIso_hom_naturality {X Y : C} (n a a' : M) (ha' : n + a = a') (f : X ⟶ Y) : (shift F a).map (f⟦n⟧') ≫ (shiftIso F n a a' ha').hom.app Y = (shiftIso F n a a' ha').hom.app X ≫ (shift F a').map f := (F.shiftIso n a a' ha').hom.naturality f @[reassoc] lemma shiftIso_inv_naturality {X Y : C} (n a a' : M) (ha' : n + a = a') (f : X ⟶ Y) : (shift F a').map f ≫ (shiftIso F n a a' ha').inv.app Y = (shiftIso F n a a' ha').inv.app X ≫ (shift F a).map (f⟦n⟧') := by simp variable (M) in /-- The canonical isomorphism `F.shift 0 ≅ F`. -/ def isoShiftZero : F.shift (0 : M) ≅ F := ShiftSequence.isoZero /-- The canonical isomorphism `shiftFunctor C n ⋙ F ≅ F.shift n`. -/ def isoShift (n : M) : shiftFunctor C n ⋙ F ≅ F.shift n := isoWhiskerLeft _ (F.isoShiftZero M).symm ≪≫ F.shiftIso _ _ _ (add_zero n) @[reassoc] lemma isoShift_hom_naturality (n : M) {X Y : C} (f : X ⟶ Y) : F.map (f⟦n⟧') ≫ (F.isoShift n).hom.app Y = (F.isoShift n).hom.app X ≫ (F.shift n).map f := (F.isoShift n).hom.naturality f attribute [simp] isoShift_hom_naturality @[reassoc] lemma isoShift_inv_naturality (n : M) {X Y : C} (f : X ⟶ Y) : (F.shift n).map f ≫ (F.isoShift n).inv.app Y = (F.isoShift n).inv.app X ≫ F.map (f⟦n⟧') := (F.isoShift n).inv.naturality f lemma shiftIso_zero (a : M) : F.shiftIso 0 a a (zero_add a) = isoWhiskerRight (shiftFunctorZero C M) _ ≪≫ leftUnitor _ := ShiftSequence.shiftIso_zero a @[simp] lemma shiftIso_zero_hom_app (a : M) (X : C) : (F.shiftIso 0 a a (zero_add a)).hom.app X = (shift F a).map ((shiftFunctorZero C M).hom.app X) := by simp [F.shiftIso_zero a] @[simp] lemma shiftIso_zero_inv_app (a : M) (X : C) : (F.shiftIso 0 a a (zero_add a)).inv.app X = (shift F a).map ((shiftFunctorZero C M).inv.app X) := by simp [F.shiftIso_zero a] lemma shiftIso_add (n m a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a'') : F.shiftIso (m + n) a a'' (by rw [add_assoc, ha', ha'']) = isoWhiskerRight (shiftFunctorAdd C m n) _ ≪≫ Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ (F.shiftIso n a a' ha') ≪≫ F.shiftIso m a' a'' ha'' :=
ShiftSequence.shiftIso_add _ _ _ _ _ _ _ lemma shiftIso_add_hom_app (n m a a' a'' : M) (ha' : n + a = a') (ha'' : m + a' = a'') (X : C) : (F.shiftIso (m + n) a a'' (by rw [add_assoc, ha', ha''])).hom.app X = (shift F a).map ((shiftFunctorAdd C m n).hom.app X) ≫
Mathlib/CategoryTheory/Shift/ShiftSequence.lean
142
146
/- 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.Computability.AkraBazzi.GrowsPolynomially import Mathlib.Analysis.Calculus.Deriv.Inv import Mathlib.Analysis.SpecialFunctions.Pow.Deriv /-! # Divide-and-conquer recurrences and the Akra-Bazzi theorem A divide-and-conquer recurrence is a function `T : ℕ → ℝ` that satisfies a recurrence relation of the form `T(n) = ∑_{i=0}^{k-1} a_i T(r_i(n)) + g(n)` for large enough `n`, where `r_i(n)` is some function where `‖r_i(n) - b_i n‖ ∈ o(n / (log n)^2)` for every `i`, the `a_i`'s are some positive coefficients, and the `b_i`'s are reals `∈ (0,1)`. (Note that this can be improved to `O(n / (log n)^(1+ε))`, this is left as future work.) These recurrences arise mainly in the analysis of divide-and-conquer algorithms such as mergesort or Strassen's algorithm for matrix multiplication. This class of algorithms works by dividing an instance of the problem of size `n`, into `k` smaller instances, where the `i`'th instance is of size roughly `b_i n`, and calling itself recursively on those smaller instances. `T(n)` then represents the running time of the algorithm, and `g(n)` represents the running time required to actually divide up the instance and process the answers that come out of the recursive calls. Since virtually all such algorithms produce instances that are only approximately of size `b_i n` (they have to round up or down at the very least), we allow the instance sizes to be given by some function `r_i(n)` that approximates `b_i n`. The Akra-Bazzi theorem gives the asymptotic order of such a recurrence: it states that `T(n) ∈ Θ(n^p (1 + ∑_{u=0}^{n-1} g(n) / u^{p+1}))`, where `p` is the unique real number such that `∑ a_i b_i^p = 1`. ## Main definitions and results * `AkraBazziRecurrence T g a b r`: the predicate stating that `T : ℕ → ℝ` satisfies an Akra-Bazzi recurrence with parameters `g`, `a`, `b` and `r` as above. * `GrowsPolynomially`: The growth condition that `g` must satisfy for the theorem to apply. It roughly states that `c₁ g(n) ≤ g(u) ≤ c₂ g(n)`, for u between b*n and n for any constant `b ∈ (0,1)`. * `sumTransform`: The transformation which turns a function `g` into `n^p * ∑ u ∈ Finset.Ico n₀ n, g u / u^(p+1)`. * `asympBound`: The asymptotic bound satisfied by an Akra-Bazzi recurrence, namely `n^p (1 + ∑ g(u) / u^(p+1))` * `isTheta_asympBound`: The main result stating that `T(n) ∈ Θ(n^p (1 + ∑_{u=0}^{n-1} g(n) / u^{p+1}))` ## Implementation Note that the original version of the theorem has an integral rather than a sum in the above expression, and first considers the `T : ℝ → ℝ` case before moving on to `ℕ → ℝ`. We prove the above version with a sum, as it is simpler and more relevant for algorithms. ## TODO * Specialize this theorem to the very common case where the recurrence is of the form `T(n) = ℓT(r_i(n)) + g(n)` where `g(n) ∈ Θ(n^t)` for some `t`. (This is often called the "master theorem" in the literature.) * Add the original version of the theorem with an integral instead of a sum. ## References * Mohamad Akra and Louay Bazzi, On the solution of linear recurrence equations * Tom Leighton, Notes on better master theorems for divide-and-conquer recurrences * Manuel Eberl, Asymptotic reasoning in a proof assistant -/ open Finset Real Filter Asymptotics open scoped Topology /-! #### Definition of Akra-Bazzi recurrences This section defines the predicate `AkraBazziRecurrence T g a b r` which states that `T` satisfies the recurrence `T(n) = ∑_{i=0}^{k-1} a_i T(r_i(n)) + g(n)` with appropriate conditions on the various parameters. -/ /-- An Akra-Bazzi recurrence is a function that satisfies the recurrence `T n = (∑ i, a i * T (r i n)) + g n`. -/ structure AkraBazziRecurrence {α : Type*} [Fintype α] [Nonempty α] (T : ℕ → ℝ) (g : ℝ → ℝ) (a : α → ℝ) (b : α → ℝ) (r : α → ℕ → ℕ) where /-- Point below which the recurrence is in the base case -/ n₀ : ℕ /-- `n₀` is always `> 0` -/ n₀_gt_zero : 0 < n₀ /-- The `a`'s are nonzero -/ a_pos : ∀ i, 0 < a i /-- The `b`'s are nonzero -/ b_pos : ∀ i, 0 < b i /-- The b's are less than 1 -/ b_lt_one : ∀ i, b i < 1 /-- `g` is nonnegative -/ g_nonneg : ∀ x ≥ 0, 0 ≤ g x /-- `g` grows polynomially -/ g_grows_poly : AkraBazziRecurrence.GrowsPolynomially g /-- The actual recurrence -/ h_rec (n : ℕ) (hn₀ : n₀ ≤ n) : T n = (∑ i, a i * T (r i n)) + g n /-- Base case: `T(n) > 0` whenever `n < n₀` -/ T_gt_zero' (n : ℕ) (hn : n < n₀) : 0 < T n /-- The `r`'s always reduce `n` -/ r_lt_n : ∀ i n, n₀ ≤ n → r i n < n /-- The `r`'s approximate the `b`'s -/ dist_r_b : ∀ i, (fun n => (r i n : ℝ) - b i * n) =o[atTop] fun n => n / (log n) ^ 2 namespace AkraBazziRecurrence section min_max variable {α : Type*} [Finite α] [Nonempty α] /-- Smallest `b i` -/ noncomputable def min_bi (b : α → ℝ) : α := Classical.choose <| Finite.exists_min b /-- Largest `b i` -/ noncomputable def max_bi (b : α → ℝ) : α := Classical.choose <| Finite.exists_max b @[aesop safe apply] lemma min_bi_le {b : α → ℝ} (i : α) : b (min_bi b) ≤ b i := Classical.choose_spec (Finite.exists_min b) i @[aesop safe apply] lemma max_bi_le {b : α → ℝ} (i : α) : b i ≤ b (max_bi b) := Classical.choose_spec (Finite.exists_max b) i end min_max lemma isLittleO_self_div_log_id : (fun (n : ℕ) => n / log n ^ 2) =o[atTop] (fun (n : ℕ) => (n : ℝ)) := by calc (fun (n : ℕ) => (n : ℝ) / log n ^ 2) = fun (n : ℕ) => (n : ℝ) * ((log n) ^ 2)⁻¹ := by simp_rw [div_eq_mul_inv] _ =o[atTop] fun (n : ℕ) => (n : ℝ) * 1⁻¹ := by refine IsBigO.mul_isLittleO (isBigO_refl _ _) ?_ refine IsLittleO.inv_rev ?main ?zero case zero => simp case main => calc _ = (fun (_ : ℕ) => ((1 : ℝ) ^ 2)) := by simp _ =o[atTop] (fun (n : ℕ) => (log n)^2) := IsLittleO.pow (IsLittleO.natCast_atTop <| isLittleO_const_log_atTop) (by norm_num) _ = (fun (n : ℕ) => (n : ℝ)) := by ext; simp variable {α : Type*} [Fintype α] {T : ℕ → ℝ} {g : ℝ → ℝ} {a b : α → ℝ} {r : α → ℕ → ℕ} variable [Nonempty α] (R : AkraBazziRecurrence T g a b r) section include R lemma dist_r_b' : ∀ᶠ n in atTop, ∀ i, ‖(r i n : ℝ) - b i * n‖ ≤ n / log n ^ 2 := by rw [Filter.eventually_all] intro i simpa using IsLittleO.eventuallyLE (R.dist_r_b i) lemma eventually_b_le_r : ∀ᶠ (n : ℕ) in atTop, ∀ i, (b i : ℝ) * n - (n / log n ^ 2) ≤ r i n := by filter_upwards [R.dist_r_b'] with n hn intro i have h₁ : 0 ≤ b i := le_of_lt <| R.b_pos _ rw [sub_le_iff_le_add, add_comm, ← sub_le_iff_le_add] calc (b i : ℝ) * n - r i n = ‖b i * n‖ - ‖(r i n : ℝ)‖ := by simp only [norm_mul, RCLike.norm_natCast, sub_left_inj, Nat.cast_eq_zero, Real.norm_of_nonneg h₁] _ ≤ ‖(b i * n : ℝ) - r i n‖ := norm_sub_norm_le _ _ _ = ‖(r i n : ℝ) - b i * n‖ := norm_sub_rev _ _ _ ≤ n / log n ^ 2 := hn i lemma eventually_r_le_b : ∀ᶠ (n : ℕ) in atTop, ∀ i, r i n ≤ (b i : ℝ) * n + (n / log n ^ 2) := by filter_upwards [R.dist_r_b'] with n hn intro i calc r i n = b i * n + (r i n - b i * n) := by ring _ ≤ b i * n + ‖r i n - b i * n‖ := by gcongr; exact Real.le_norm_self _ _ ≤ b i * n + n / log n ^ 2 := by gcongr; exact hn i lemma eventually_r_lt_n : ∀ᶠ (n : ℕ) in atTop, ∀ i, r i n < n := by filter_upwards [eventually_ge_atTop R.n₀] with n hn exact fun i => R.r_lt_n i n hn lemma eventually_bi_mul_le_r : ∀ᶠ (n : ℕ) in atTop, ∀ i, (b (min_bi b) / 2) * n ≤ r i n := by have gt_zero : 0 < b (min_bi b) := R.b_pos (min_bi b) have hlo := isLittleO_self_div_log_id rw [Asymptotics.isLittleO_iff] at hlo have hlo' := hlo (by positivity : 0 < b (min_bi b) / 2) filter_upwards [hlo', R.eventually_b_le_r] with n hn hn' intro i simp only [Real.norm_of_nonneg (by positivity : 0 ≤ (n : ℝ))] at hn calc b (min_bi b) / 2 * n = b (min_bi b) * n - b (min_bi b) / 2 * n := by ring _ ≤ b (min_bi b) * n - ‖n / log n ^ 2‖ := by gcongr _ ≤ b i * n - ‖n / log n ^ 2‖ := by gcongr; aesop _ = b i * n - n / log n ^ 2 := by congr exact Real.norm_of_nonneg <| by positivity _ ≤ r i n := hn' i lemma bi_min_div_two_lt_one : b (min_bi b) / 2 < 1 := by have gt_zero : 0 < b (min_bi b) := R.b_pos (min_bi b) calc b (min_bi b) / 2 < b (min_bi b) := by aesop (add safe apply div_two_lt_of_pos) _ < 1 := R.b_lt_one _ lemma bi_min_div_two_pos : 0 < b (min_bi b) / 2 := div_pos (R.b_pos _) (by norm_num) lemma exists_eventually_const_mul_le_r : ∃ c ∈ Set.Ioo (0 : ℝ) 1, ∀ᶠ (n : ℕ) in atTop, ∀ i, c * n ≤ r i n := by have gt_zero : 0 < b (min_bi b) := R.b_pos (min_bi b) exact ⟨b (min_bi b) / 2, ⟨⟨by positivity, R.bi_min_div_two_lt_one⟩, R.eventually_bi_mul_le_r⟩⟩ lemma eventually_r_ge (C : ℝ) : ∀ᶠ (n : ℕ) in atTop, ∀ i, C ≤ r i n := by obtain ⟨c, hc_mem, hc⟩ := R.exists_eventually_const_mul_le_r filter_upwards [eventually_ge_atTop ⌈C / c⌉₊, hc] with n hn₁ hn₂ have h₁ := hc_mem.1 intro i calc C = c * (C / c) := by rw [← mul_div_assoc] exact (mul_div_cancel_left₀ _ (by positivity)).symm _ ≤ c * ⌈C / c⌉₊ := by gcongr; simp [Nat.le_ceil] _ ≤ c * n := by gcongr _ ≤ r i n := hn₂ i lemma tendsto_atTop_r (i : α) : Tendsto (r i) atTop atTop := by rw [tendsto_atTop] intro b have := R.eventually_r_ge b rw [Filter.eventually_all] at this exact_mod_cast this i lemma tendsto_atTop_r_real (i : α) : Tendsto (fun n => (r i n : ℝ)) atTop atTop := Tendsto.comp tendsto_natCast_atTop_atTop (R.tendsto_atTop_r i) lemma exists_eventually_r_le_const_mul : ∃ c ∈ Set.Ioo (0 : ℝ) 1, ∀ᶠ (n : ℕ) in atTop, ∀ i, r i n ≤ c * n := by let c := b (max_bi b) + (1 - b (max_bi b)) / 2 have h_max_bi_pos : 0 < b (max_bi b) := R.b_pos _ have h_max_bi_lt_one : 0 < 1 - b (max_bi b) := by have : b (max_bi b) < 1 := R.b_lt_one _ linarith have hc_pos : 0 < c := by positivity have h₁ : 0 < (1 - b (max_bi b)) / 2 := by positivity have hc_lt_one : c < 1 := calc b (max_bi b) + (1 - b (max_bi b)) / 2 = b (max_bi b) * (1 / 2) + 1 / 2 := by ring _ < 1 * (1 / 2) + 1 / 2 := by gcongr exact R.b_lt_one _ _ = 1 := by norm_num refine ⟨c, ⟨hc_pos, hc_lt_one⟩, ?_⟩ have hlo := isLittleO_self_div_log_id rw [Asymptotics.isLittleO_iff] at hlo have hlo' := hlo h₁ filter_upwards [hlo', R.eventually_r_le_b] with n hn hn' intro i rw [Real.norm_of_nonneg (by positivity)] at hn simp only [Real.norm_of_nonneg (by positivity : 0 ≤ (n : ℝ))] at hn calc r i n ≤ b i * n + n / log n ^ 2 := by exact hn' i _ ≤ b i * n + (1 - b (max_bi b)) / 2 * n := by gcongr _ = (b i + (1 - b (max_bi b)) / 2) * n := by ring _ ≤ (b (max_bi b) + (1 - b (max_bi b)) / 2) * n := by gcongr; exact max_bi_le _ lemma eventually_r_pos : ∀ᶠ (n : ℕ) in atTop, ∀ i, 0 < r i n := by rw [Filter.eventually_all] exact fun i => (R.tendsto_atTop_r i).eventually_gt_atTop 0 lemma eventually_log_b_mul_pos : ∀ᶠ (n : ℕ) in atTop, ∀ i, 0 < log (b i * n) := by rw [Filter.eventually_all] intro i have h : Tendsto (fun (n : ℕ) => log (b i * n)) atTop atTop := Tendsto.comp tendsto_log_atTop <| Tendsto.const_mul_atTop (b_pos R i) tendsto_natCast_atTop_atTop exact h.eventually_gt_atTop 0 @[aesop safe apply] lemma T_pos (n : ℕ) : 0 < T n := by induction n using Nat.strongRecOn with | ind n h_ind => cases lt_or_le n R.n₀ with | inl hn => exact R.T_gt_zero' n hn -- n < R.n₀ | inr hn => -- R.n₀ ≤ n rw [R.h_rec n hn] have := R.g_nonneg refine add_pos_of_pos_of_nonneg (Finset.sum_pos ?sum_elems univ_nonempty) (by aesop) exact fun i _ => mul_pos (R.a_pos i) <| h_ind _ (R.r_lt_n i _ hn) @[aesop safe apply] lemma T_nonneg (n : ℕ) : 0 ≤ T n := le_of_lt <| R.T_pos n end /-! #### Smoothing function We define `ε` as the "smoothing function" `fun n => 1 / log n`, which will be used in the form of a factor of `1 ± ε n` needed to make the induction step go through. This is its own definition to make it easier to switch to a different smoothing function. For example, choosing `1 / log n ^ δ` for a suitable choice of `δ` leads to a slightly tighter theorem at the price of a more complicated proof. This part of the file then proves several properties of this function that will be needed later in the proof. -/ /-- The "smoothing function" is defined as `1 / log n`. This is defined as an `ℝ → ℝ` function as opposed to `ℕ → ℝ` since this is more convenient for the proof, where we need to e.g. take derivatives. -/ noncomputable def smoothingFn (n : ℝ) : ℝ := 1 / log n local notation "ε" => smoothingFn lemma one_add_smoothingFn_le_two {x : ℝ} (hx : exp 1 ≤ x) : 1 + ε x ≤ 2 := by simp only [smoothingFn, ← one_add_one_eq_two] gcongr have : 1 < x := by calc 1 = exp 0 := by simp _ < exp 1 := by simp _ ≤ x := hx rw [div_le_one (log_pos this)] calc 1 = log (exp 1) := by simp _ ≤ log x := log_le_log (exp_pos _) hx lemma isLittleO_smoothingFn_one : ε =o[atTop] (fun _ => (1 : ℝ)) := by unfold smoothingFn refine isLittleO_of_tendsto (fun _ h => False.elim <| one_ne_zero h) ?_ simp only [one_div, div_one] exact Tendsto.inv_tendsto_atTop Real.tendsto_log_atTop lemma isEquivalent_one_add_smoothingFn_one : (fun x => 1 + ε x) ~[atTop] (fun _ => (1 : ℝ)) := IsEquivalent.add_isLittleO IsEquivalent.refl isLittleO_smoothingFn_one lemma isEquivalent_one_sub_smoothingFn_one : (fun x => 1 - ε x) ~[atTop] (fun _ => (1 : ℝ)) := IsEquivalent.sub_isLittleO IsEquivalent.refl isLittleO_smoothingFn_one lemma growsPolynomially_one_sub_smoothingFn : GrowsPolynomially fun x => 1 - ε x := GrowsPolynomially.of_isEquivalent_const isEquivalent_one_sub_smoothingFn_one lemma growsPolynomially_one_add_smoothingFn : GrowsPolynomially fun x => 1 + ε x := GrowsPolynomially.of_isEquivalent_const isEquivalent_one_add_smoothingFn_one lemma eventually_one_sub_smoothingFn_gt_const_real (c : ℝ) (hc : c < 1) : ∀ᶠ (x : ℝ) in atTop, c < 1 - ε x := by have h₁ : Tendsto (fun x => 1 - ε x) atTop (𝓝 1) := by rw [← isEquivalent_const_iff_tendsto one_ne_zero] exact isEquivalent_one_sub_smoothingFn_one rw [tendsto_order] at h₁ exact h₁.1 c hc lemma eventually_one_sub_smoothingFn_gt_const (c : ℝ) (hc : c < 1) : ∀ᶠ (n : ℕ) in atTop, c < 1 - ε n := Eventually.natCast_atTop (p := fun n => c < 1 - ε n) <| eventually_one_sub_smoothingFn_gt_const_real c hc lemma eventually_one_sub_smoothingFn_pos_real : ∀ᶠ (x : ℝ) in atTop, 0 < 1 - ε x := eventually_one_sub_smoothingFn_gt_const_real 0 zero_lt_one lemma eventually_one_sub_smoothingFn_pos : ∀ᶠ (n : ℕ) in atTop, 0 < 1 - ε n := (eventually_one_sub_smoothingFn_pos_real).natCast_atTop lemma eventually_one_sub_smoothingFn_nonneg : ∀ᶠ (n : ℕ) in atTop, 0 ≤ 1 - ε n := by filter_upwards [eventually_one_sub_smoothingFn_pos] with n hn; exact le_of_lt hn
include R in lemma eventually_one_sub_smoothingFn_r_pos : ∀ᶠ (n : ℕ) in atTop, ∀ i, 0 < 1 - ε (r i n) := by rw [Filter.eventually_all] exact fun i => (R.tendsto_atTop_r_real i).eventually eventually_one_sub_smoothingFn_pos_real
Mathlib/Computability/AkraBazzi/AkraBazzi.lean
355
360
/- Copyright (c) 2021 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Algebra.Group.Embedding import Mathlib.Order.Interval.Multiset /-! # Finite intervals of naturals This file proves that `ℕ` is a `LocallyFiniteOrder` and calculates the cardinality of its intervals as finsets and fintypes. ## TODO Some lemmas can be generalized using `OrderedGroup`, `CanonicallyOrderedMul` or `SuccOrder` and subsequently be moved upstream to `Order.Interval.Finset`. -/ assert_not_exists Ring open Finset Nat variable (a b c : ℕ) namespace Nat instance instLocallyFiniteOrder : LocallyFiniteOrder ℕ where finsetIcc a b := ⟨List.range' a (b + 1 - a), List.nodup_range'⟩ finsetIco a b := ⟨List.range' a (b - a), List.nodup_range'⟩ finsetIoc a b := ⟨List.range' (a + 1) (b - a), List.nodup_range'⟩ finsetIoo a b := ⟨List.range' (a + 1) (b - a - 1), List.nodup_range'⟩ finset_mem_Icc a b x := by rw [Finset.mem_mk, Multiset.mem_coe, List.mem_range'_1]; omega finset_mem_Ico a b x := by rw [Finset.mem_mk, Multiset.mem_coe, List.mem_range'_1]; omega finset_mem_Ioc a b x := by rw [Finset.mem_mk, Multiset.mem_coe, List.mem_range'_1]; omega finset_mem_Ioo a b x := by rw [Finset.mem_mk, Multiset.mem_coe, List.mem_range'_1]; omega theorem Icc_eq_range' : Icc a b = ⟨List.range' a (b + 1 - a), List.nodup_range'⟩ := rfl theorem Ico_eq_range' : Ico a b = ⟨List.range' a (b - a), List.nodup_range'⟩ := rfl theorem Ioc_eq_range' : Ioc a b = ⟨List.range' (a + 1) (b - a), List.nodup_range'⟩ := rfl theorem Ioo_eq_range' : Ioo a b = ⟨List.range' (a + 1) (b - a - 1), List.nodup_range'⟩ := rfl theorem uIcc_eq_range' : uIcc a b = ⟨List.range' (min a b) (max a b + 1 - min a b), List.nodup_range'⟩ := rfl theorem Iio_eq_range : Iio = range := by ext b x rw [mem_Iio, mem_range] @[simp] theorem Ico_zero_eq_range : Ico 0 = range := by rw [← Nat.bot_eq_zero, ← Iio_eq_Ico, Iio_eq_range] lemma range_eq_Icc_zero_sub_one (n : ℕ) (hn : n ≠ 0) : range n = Icc 0 (n - 1) := by ext b simp_all only [mem_Icc, zero_le, true_and, mem_range] exact lt_iff_le_pred (zero_lt_of_ne_zero hn) theorem _root_.Finset.range_eq_Ico : range = Ico 0 :=
Ico_zero_eq_range.symm
Mathlib/Order/Interval/Finset/Nat.lean
67
67
/- Copyright (c) 2022 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.LinearAlgebra.CliffordAlgebra.Conjugation import Mathlib.LinearAlgebra.CliffordAlgebra.Fold import Mathlib.LinearAlgebra.ExteriorAlgebra.Basic import Mathlib.LinearAlgebra.Dual.Defs /-! # Contraction in Clifford Algebras This file contains some of the results from [grinberg_clifford_2016][]. The key result is `CliffordAlgebra.equivExterior`. ## Main definitions * `CliffordAlgebra.contractLeft`: contract a multivector by a `Module.Dual R M` on the left. * `CliffordAlgebra.contractRight`: contract a multivector by a `Module.Dual R M` on the right. * `CliffordAlgebra.changeForm`: convert between two algebras of different quadratic form, sending vectors to vectors. The difference of the quadratic forms must be a bilinear form. * `CliffordAlgebra.equivExterior`: in characteristic not-two, the `CliffordAlgebra Q` is isomorphic as a module to the exterior algebra. ## Implementation notes This file somewhat follows [grinberg_clifford_2016][], although we are missing some of the induction principles needed to prove many of the results. Here, we avoid the quotient-based approach described in [grinberg_clifford_2016][], instead directly constructing our objects using the universal property. Note that [grinberg_clifford_2016][] concludes that its contents are not novel, and are in fact just a rehash of parts of [bourbaki2007][]; we should at some point consider swapping our references to refer to the latter. Within this file, we use the local notation * `x ⌊ d` for `contractRight x d` * `d ⌋ x` for `contractLeft d x` -/ open LinearMap (BilinMap BilinForm) universe u1 u2 u3 variable {R : Type u1} [CommRing R] variable {M : Type u2} [AddCommGroup M] [Module R M] variable (Q : QuadraticForm R M) namespace CliffordAlgebra section contractLeft variable (d d' : Module.Dual R M) /-- Auxiliary construction for `CliffordAlgebra.contractLeft` -/ @[simps!] def contractLeftAux (d : Module.Dual R M) : M →ₗ[R] CliffordAlgebra Q × CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q := haveI v_mul := (Algebra.lmul R (CliffordAlgebra Q)).toLinearMap ∘ₗ ι Q d.smulRight (LinearMap.fst _ (CliffordAlgebra Q) (CliffordAlgebra Q)) - v_mul.compl₂ (LinearMap.snd _ (CliffordAlgebra Q) _) theorem contractLeftAux_contractLeftAux (v : M) (x : CliffordAlgebra Q) (fx : CliffordAlgebra Q) : contractLeftAux Q d v (ι Q v * x, contractLeftAux Q d v (x, fx)) = Q v • fx := by simp only [contractLeftAux_apply_apply] rw [mul_sub, ← mul_assoc, ι_sq_scalar, ← Algebra.smul_def, ← sub_add, mul_smul_comm, sub_self, zero_add] variable {Q} /-- Contract an element of the clifford algebra with an element `d : Module.Dual R M` from the left. Note that $v ⌋ x$ is spelt `contractLeft (Q.associated v) x`. This includes [grinberg_clifford_2016][] Theorem 10.75 -/ def contractLeft : Module.Dual R M →ₗ[R] CliffordAlgebra Q →ₗ[R] CliffordAlgebra Q where toFun d := foldr' Q (contractLeftAux Q d) (contractLeftAux_contractLeftAux Q d) 0 map_add' d₁ d₂ := LinearMap.ext fun x => by rw [LinearMap.add_apply] induction x using CliffordAlgebra.left_induction with | algebraMap => simp_rw [foldr'_algebraMap, smul_zero, zero_add] | add _ _ hx hy => rw [map_add, map_add, map_add, add_add_add_comm, hx, hy] | ι_mul _ _ hx => rw [foldr'_ι_mul, foldr'_ι_mul, foldr'_ι_mul, hx] dsimp only [contractLeftAux_apply_apply] rw [sub_add_sub_comm, mul_add, LinearMap.add_apply, add_smul] map_smul' c d := LinearMap.ext fun x => by rw [LinearMap.smul_apply, RingHom.id_apply] induction x using CliffordAlgebra.left_induction with | algebraMap => simp_rw [foldr'_algebraMap, smul_zero] | add _ _ hx hy => rw [map_add, map_add, smul_add, hx, hy] | ι_mul _ _ hx => rw [foldr'_ι_mul, foldr'_ι_mul, hx] dsimp only [contractLeftAux_apply_apply] rw [LinearMap.smul_apply, smul_assoc, mul_smul_comm, smul_sub] /-- Contract an element of the clifford algebra with an element `d : Module.Dual R M` from the right. Note that $x ⌊ v$ is spelt `contractRight x (Q.associated v)`. This includes [grinberg_clifford_2016][] Theorem 16.75 -/ def contractRight : CliffordAlgebra Q →ₗ[R] Module.Dual R M →ₗ[R] CliffordAlgebra Q := LinearMap.flip (LinearMap.compl₂ (LinearMap.compr₂ contractLeft reverse) reverse) theorem contractRight_eq (x : CliffordAlgebra Q) : contractRight (Q := Q) x d = reverse (contractLeft (R := R) (M := M) d <| reverse x) := rfl local infixl:70 "⌋" => contractLeft (R := R) (M := M) local infixl:70 "⌊" => contractRight (R := R) (M := M) (Q := Q) /-- This is [grinberg_clifford_2016][] Theorem 6 -/ theorem contractLeft_ι_mul (a : M) (b : CliffordAlgebra Q) : d⌋(ι Q a * b) = d a • b - ι Q a * (d⌋b) := by -- Porting note: Lean cannot figure out anymore the third argument refine foldr'_ι_mul _ _ ?_ _ _ _ exact fun m x fx ↦ contractLeftAux_contractLeftAux Q d m x fx /-- This is [grinberg_clifford_2016][] Theorem 12 -/ theorem contractRight_mul_ι (a : M) (b : CliffordAlgebra Q) : b * ι Q a⌊d = d a • b - b⌊d * ι Q a := by rw [contractRight_eq, reverse.map_mul, reverse_ι, contractLeft_ι_mul, map_sub, map_smul, reverse_reverse, reverse.map_mul, reverse_ι, contractRight_eq] theorem contractLeft_algebraMap_mul (r : R) (b : CliffordAlgebra Q) : d⌋(algebraMap _ _ r * b) = algebraMap _ _ r * (d⌋b) := by rw [← Algebra.smul_def, map_smul, Algebra.smul_def] theorem contractLeft_mul_algebraMap (a : CliffordAlgebra Q) (r : R) : d⌋(a * algebraMap _ _ r) = d⌋a * algebraMap _ _ r := by rw [← Algebra.commutes, contractLeft_algebraMap_mul, Algebra.commutes] theorem contractRight_algebraMap_mul (r : R) (b : CliffordAlgebra Q) : algebraMap _ _ r * b⌊d = algebraMap _ _ r * (b⌊d) := by rw [← Algebra.smul_def, LinearMap.map_smul₂, Algebra.smul_def] theorem contractRight_mul_algebraMap (a : CliffordAlgebra Q) (r : R) : a * algebraMap _ _ r⌊d = a⌊d * algebraMap _ _ r := by rw [← Algebra.commutes, contractRight_algebraMap_mul, Algebra.commutes] variable (Q) @[simp] theorem contractLeft_ι (x : M) : d⌋ι Q x = algebraMap R _ (d x) := by -- Porting note: Lean cannot figure out anymore the third argument refine (foldr'_ι _ _ ?_ _ _).trans <| by simp_rw [contractLeftAux_apply_apply, mul_zero, sub_zero, Algebra.algebraMap_eq_smul_one] exact fun m x fx ↦ contractLeftAux_contractLeftAux Q d m x fx @[simp] theorem contractRight_ι (x : M) : ι Q x⌊d = algebraMap R _ (d x) := by
rw [contractRight_eq, reverse_ι, contractLeft_ι, reverse.commutes] @[simp]
Mathlib/LinearAlgebra/CliffordAlgebra/Contraction.lean
159
161
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Yaël Dillies -/ import Mathlib.Order.Cover import Mathlib.Order.Interval.Finset.Defs /-! # Intervals as finsets This file provides basic results about all the `Finset.Ixx`, which are defined in `Order.Interval.Finset.Defs`. In addition, it shows that in a locally finite order `≤` and `<` are the transitive closures of, respectively, `⩿` and `⋖`, which then leads to a characterization of monotone and strictly functions whose domain is a locally finite order. In particular, this file proves: * `le_iff_transGen_wcovBy`: `≤` is the transitive closure of `⩿` * `lt_iff_transGen_covBy`: `<` is the transitive closure of `⋖` * `monotone_iff_forall_wcovBy`: Characterization of monotone functions * `strictMono_iff_forall_covBy`: Characterization of strictly monotone functions ## TODO This file was originally only about `Finset.Ico a b` where `a b : ℕ`. No care has yet been taken to generalize these lemmas properly and many lemmas about `Icc`, `Ioc`, `Ioo` are missing. In general, what's to do is taking the lemmas in `Data.X.Intervals` and abstract away the concrete structure. Complete the API. See https://github.com/leanprover-community/mathlib/pull/14448#discussion_r906109235 for some ideas. -/ assert_not_exists MonoidWithZero Finset.sum open Function OrderDual open FinsetInterval variable {ι α : Type*} {a a₁ a₂ b b₁ b₂ c x : α} namespace Finset section Preorder variable [Preorder α] section LocallyFiniteOrder variable [LocallyFiniteOrder α] @[simp] theorem nonempty_Icc : (Icc a b).Nonempty ↔ a ≤ b := by rw [← coe_nonempty, coe_Icc, Set.nonempty_Icc] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Icc_of_le⟩ := nonempty_Icc @[simp] theorem nonempty_Ico : (Ico a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ico, Set.nonempty_Ico] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Ico_of_lt⟩ := nonempty_Ico @[simp] theorem nonempty_Ioc : (Ioc a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ioc, Set.nonempty_Ioc] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Ioc_of_lt⟩ := nonempty_Ioc -- TODO: This is nonsense. A locally finite order is never densely ordered @[simp] theorem nonempty_Ioo [DenselyOrdered α] : (Ioo a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ioo, Set.nonempty_Ioo] @[simp] theorem Icc_eq_empty_iff : Icc a b = ∅ ↔ ¬a ≤ b := by rw [← coe_eq_empty, coe_Icc, Set.Icc_eq_empty_iff] @[simp] theorem Ico_eq_empty_iff : Ico a b = ∅ ↔ ¬a < b := by rw [← coe_eq_empty, coe_Ico, Set.Ico_eq_empty_iff] @[simp] theorem Ioc_eq_empty_iff : Ioc a b = ∅ ↔ ¬a < b := by rw [← coe_eq_empty, coe_Ioc, Set.Ioc_eq_empty_iff] -- TODO: This is nonsense. A locally finite order is never densely ordered @[simp] theorem Ioo_eq_empty_iff [DenselyOrdered α] : Ioo a b = ∅ ↔ ¬a < b := by rw [← coe_eq_empty, coe_Ioo, Set.Ioo_eq_empty_iff] alias ⟨_, Icc_eq_empty⟩ := Icc_eq_empty_iff alias ⟨_, Ico_eq_empty⟩ := Ico_eq_empty_iff alias ⟨_, Ioc_eq_empty⟩ := Ioc_eq_empty_iff @[simp] theorem Ioo_eq_empty (h : ¬a < b) : Ioo a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ hx => h ((mem_Ioo.1 hx).1.trans (mem_Ioo.1 hx).2) @[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 left_mem_Icc : a ∈ Icc a b ↔ a ≤ b := by simp only [mem_Icc, true_and, le_rfl] theorem left_mem_Ico : a ∈ Ico a b ↔ a < b := by simp only [mem_Ico, true_and, le_refl] theorem right_mem_Icc : b ∈ Icc a b ↔ a ≤ b := by simp only [mem_Icc, and_true, le_rfl] theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b := by simp only [mem_Ioc, and_true, le_rfl] theorem left_not_mem_Ioc : a ∉ Ioc a b := fun h => lt_irrefl _ (mem_Ioc.1 h).1 theorem left_not_mem_Ioo : a ∉ Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).1 theorem right_not_mem_Ico : b ∉ Ico a b := fun h => lt_irrefl _ (mem_Ico.1 h).2 theorem right_not_mem_Ioo : b ∉ Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).2 @[gcongr] theorem Icc_subset_Icc (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊆ Icc a₂ b₂ := by simpa [← coe_subset] using Set.Icc_subset_Icc ha hb @[gcongr] theorem Ico_subset_Ico (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ico a₁ b₁ ⊆ Ico a₂ b₂ := by simpa [← coe_subset] using Set.Ico_subset_Ico ha hb @[gcongr] theorem Ioc_subset_Ioc (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ioc a₁ b₁ ⊆ Ioc a₂ b₂ := by simpa [← coe_subset] using Set.Ioc_subset_Ioc ha hb @[gcongr] theorem Ioo_subset_Ioo (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ioo a₁ b₁ ⊆ Ioo a₂ b₂ := by simpa [← coe_subset] using Set.Ioo_subset_Ioo ha hb @[gcongr] theorem Icc_subset_Icc_left (h : a₁ ≤ a₂) : Icc a₂ b ⊆ Icc a₁ b := Icc_subset_Icc h le_rfl @[gcongr] theorem Ico_subset_Ico_left (h : a₁ ≤ a₂) : Ico a₂ b ⊆ Ico a₁ b := Ico_subset_Ico h le_rfl @[gcongr] theorem Ioc_subset_Ioc_left (h : a₁ ≤ a₂) : Ioc a₂ b ⊆ Ioc a₁ b := Ioc_subset_Ioc h le_rfl @[gcongr] theorem Ioo_subset_Ioo_left (h : a₁ ≤ a₂) : Ioo a₂ b ⊆ Ioo a₁ b := Ioo_subset_Ioo h le_rfl @[gcongr] theorem Icc_subset_Icc_right (h : b₁ ≤ b₂) : Icc a b₁ ⊆ Icc a b₂ := Icc_subset_Icc le_rfl h @[gcongr] theorem Ico_subset_Ico_right (h : b₁ ≤ b₂) : Ico a b₁ ⊆ Ico a b₂ := Ico_subset_Ico le_rfl h @[gcongr] theorem Ioc_subset_Ioc_right (h : b₁ ≤ b₂) : Ioc a b₁ ⊆ Ioc a b₂ := Ioc_subset_Ioc le_rfl h @[gcongr] theorem Ioo_subset_Ioo_right (h : b₁ ≤ b₂) : Ioo a b₁ ⊆ Ioo a b₂ := Ioo_subset_Ioo le_rfl h theorem Ico_subset_Ioo_left (h : a₁ < a₂) : Ico a₂ b ⊆ Ioo a₁ b := by rw [← coe_subset, coe_Ico, coe_Ioo] exact Set.Ico_subset_Ioo_left h theorem Ioc_subset_Ioo_right (h : b₁ < b₂) : Ioc a b₁ ⊆ Ioo a b₂ := by rw [← coe_subset, coe_Ioc, coe_Ioo] exact Set.Ioc_subset_Ioo_right h theorem Icc_subset_Ico_right (h : b₁ < b₂) : Icc a b₁ ⊆ Ico a b₂ := by rw [← coe_subset, coe_Icc, coe_Ico] exact Set.Icc_subset_Ico_right h theorem Ioo_subset_Ico_self : Ioo a b ⊆ Ico a b := by rw [← coe_subset, coe_Ioo, coe_Ico] exact Set.Ioo_subset_Ico_self theorem Ioo_subset_Ioc_self : Ioo a b ⊆ Ioc a b := by rw [← coe_subset, coe_Ioo, coe_Ioc] exact Set.Ioo_subset_Ioc_self theorem Ico_subset_Icc_self : Ico a b ⊆ Icc a b := by rw [← coe_subset, coe_Ico, coe_Icc] exact Set.Ico_subset_Icc_self theorem Ioc_subset_Icc_self : Ioc a b ⊆ Icc a b := by rw [← coe_subset, coe_Ioc, coe_Icc] exact Set.Ioc_subset_Icc_self theorem Ioo_subset_Icc_self : Ioo a b ⊆ Icc a b := Ioo_subset_Ico_self.trans Ico_subset_Icc_self theorem Icc_subset_Icc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Icc a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := by rw [← coe_subset, coe_Icc, coe_Icc, Set.Icc_subset_Icc_iff h₁] theorem Icc_subset_Ioo_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ ↔ a₂ < a₁ ∧ b₁ < b₂ := by rw [← coe_subset, coe_Icc, coe_Ioo, Set.Icc_subset_Ioo_iff h₁] theorem Icc_subset_Ico_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ < b₂ := by rw [← coe_subset, coe_Icc, coe_Ico, Set.Icc_subset_Ico_iff h₁] theorem Icc_subset_Ioc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioc a₂ b₂ ↔ a₂ < a₁ ∧ b₁ ≤ b₂ := (Icc_subset_Ico_iff h₁.dual).trans and_comm --TODO: `Ico_subset_Ioo_iff`, `Ioc_subset_Ioo_iff` theorem Icc_ssubset_Icc_left (hI : a₂ ≤ b₂) (ha : a₂ < a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := by rw [← coe_ssubset, coe_Icc, coe_Icc] exact Set.Icc_ssubset_Icc_left hI ha hb theorem Icc_ssubset_Icc_right (hI : a₂ ≤ b₂) (ha : a₂ ≤ a₁) (hb : b₁ < b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := by rw [← coe_ssubset, coe_Icc, coe_Icc] exact Set.Icc_ssubset_Icc_right hI ha hb @[simp] theorem Ioc_disjoint_Ioc_of_le {d : α} (hbc : b ≤ c) : Disjoint (Ioc a b) (Ioc c d) := disjoint_left.2 fun _ h1 h2 ↦ not_and_of_not_left _ ((mem_Ioc.1 h1).2.trans hbc).not_lt (mem_Ioc.1 h2) variable (a) theorem Ico_self : Ico a a = ∅ := Ico_eq_empty <| lt_irrefl _ theorem Ioc_self : Ioc a a = ∅ := Ioc_eq_empty <| lt_irrefl _ theorem Ioo_self : Ioo a a = ∅ := Ioo_eq_empty <| lt_irrefl _ variable {a} /-- A set with upper and lower bounds in a locally finite order is a fintype -/ def _root_.Set.fintypeOfMemBounds {s : Set α} [DecidablePred (· ∈ s)] (ha : a ∈ lowerBounds s) (hb : b ∈ upperBounds s) : Fintype s := Set.fintypeSubset (Set.Icc a b) fun _ hx => ⟨ha hx, hb hx⟩ section Filter theorem Ico_filter_lt_of_le_left [DecidablePred (· < c)] (hca : c ≤ a) : {x ∈ Ico a b | x < c} = ∅ := filter_false_of_mem fun _ hx => (hca.trans (mem_Ico.1 hx).1).not_lt theorem Ico_filter_lt_of_right_le [DecidablePred (· < c)] (hbc : b ≤ c) : {x ∈ Ico a b | x < c} = Ico a b := filter_true_of_mem fun _ hx => (mem_Ico.1 hx).2.trans_le hbc theorem Ico_filter_lt_of_le_right [DecidablePred (· < c)] (hcb : c ≤ b) : {x ∈ Ico a b | x < c} = Ico a c := by ext x rw [mem_filter, mem_Ico, mem_Ico, and_right_comm] exact and_iff_left_of_imp fun h => h.2.trans_le hcb theorem Ico_filter_le_of_le_left {a b c : α} [DecidablePred (c ≤ ·)] (hca : c ≤ a) : {x ∈ Ico a b | c ≤ x} = Ico a b := filter_true_of_mem fun _ hx => hca.trans (mem_Ico.1 hx).1 theorem Ico_filter_le_of_right_le {a b : α} [DecidablePred (b ≤ ·)] : {x ∈ Ico a b | b ≤ x} = ∅ := filter_false_of_mem fun _ hx => (mem_Ico.1 hx).2.not_le theorem Ico_filter_le_of_left_le {a b c : α} [DecidablePred (c ≤ ·)] (hac : a ≤ c) : {x ∈ Ico a b | c ≤ x} = Ico c b := by ext x rw [mem_filter, mem_Ico, mem_Ico, and_comm, and_left_comm] exact and_iff_right_of_imp fun h => hac.trans h.1 theorem Icc_filter_lt_of_lt_right {a b c : α} [DecidablePred (· < c)] (h : b < c) : {x ∈ Icc a b | x < c} = Icc a b := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Icc.1 hx).2 h theorem Ioc_filter_lt_of_lt_right {a b c : α} [DecidablePred (· < c)] (h : b < c) : {x ∈ Ioc a b | x < c} = Ioc a b := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Ioc.1 hx).2 h theorem Iic_filter_lt_of_lt_right {α} [Preorder α] [LocallyFiniteOrderBot α] {a c : α} [DecidablePred (· < c)] (h : a < c) : {x ∈ Iic a | x < c} = Iic a := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Iic.1 hx) h variable (a b) [Fintype α] theorem filter_lt_lt_eq_Ioo [DecidablePred fun j => a < j ∧ j < b] : ({j | a < j ∧ j < b} : Finset _) = Ioo a b := by ext; simp theorem filter_lt_le_eq_Ioc [DecidablePred fun j => a < j ∧ j ≤ b] : ({j | a < j ∧ j ≤ b} : Finset _) = Ioc a b := by ext; simp theorem filter_le_lt_eq_Ico [DecidablePred fun j => a ≤ j ∧ j < b] : ({j | a ≤ j ∧ j < b} : Finset _) = Ico a b := by ext; simp theorem filter_le_le_eq_Icc [DecidablePred fun j => a ≤ j ∧ j ≤ b] : ({j | a ≤ j ∧ j ≤ b} : Finset _) = Icc a b := by ext; simp end Filter end LocallyFiniteOrder section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop α] @[simp] theorem Ioi_eq_empty : Ioi a = ∅ ↔ IsMax a := by rw [← coe_eq_empty, coe_Ioi, Set.Ioi_eq_empty_iff] @[simp] alias ⟨_, _root_.IsMax.finsetIoi_eq⟩ := Ioi_eq_empty @[simp] lemma Ioi_nonempty : (Ioi a).Nonempty ↔ ¬ IsMax a := by simp [nonempty_iff_ne_empty] theorem Ioi_top [OrderTop α] : Ioi (⊤ : α) = ∅ := Ioi_eq_empty.mpr isMax_top @[simp] theorem Ici_bot [OrderBot α] [Fintype α] : Ici (⊥ : α) = univ := by ext a; simp only [mem_Ici, bot_le, mem_univ] @[simp, aesop safe apply (rule_sets := [finsetNonempty])] lemma nonempty_Ici : (Ici a).Nonempty := ⟨a, mem_Ici.2 le_rfl⟩ lemma nonempty_Ioi : (Ioi a).Nonempty ↔ ¬ IsMax a := by simp [Finset.Nonempty] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Ioi_of_not_isMax⟩ := nonempty_Ioi @[simp] theorem Ici_subset_Ici : Ici a ⊆ Ici b ↔ b ≤ a := by simp [← coe_subset] @[gcongr] alias ⟨_, _root_.GCongr.Finset.Ici_subset_Ici⟩ := Ici_subset_Ici @[simp] theorem Ici_ssubset_Ici : Ici a ⊂ Ici b ↔ b < a := by simp [← coe_ssubset] @[gcongr] alias ⟨_, _root_.GCongr.Finset.Ici_ssubset_Ici⟩ := Ici_ssubset_Ici @[gcongr] theorem Ioi_subset_Ioi (h : a ≤ b) : Ioi b ⊆ Ioi a := by simpa [← coe_subset] using Set.Ioi_subset_Ioi h @[gcongr] theorem Ioi_ssubset_Ioi (h : a < b) : Ioi b ⊂ Ioi a := by simpa [← coe_ssubset] using Set.Ioi_ssubset_Ioi h variable [LocallyFiniteOrder α] theorem Icc_subset_Ici_self : Icc a b ⊆ Ici a := by simpa [← coe_subset] using Set.Icc_subset_Ici_self theorem Ico_subset_Ici_self : Ico a b ⊆ Ici a := by simpa [← coe_subset] using Set.Ico_subset_Ici_self theorem Ioc_subset_Ioi_self : Ioc a b ⊆ Ioi a := by simpa [← coe_subset] using Set.Ioc_subset_Ioi_self theorem Ioo_subset_Ioi_self : Ioo a b ⊆ Ioi a := by simpa [← coe_subset] using Set.Ioo_subset_Ioi_self theorem Ioc_subset_Ici_self : Ioc a b ⊆ Ici a := Ioc_subset_Icc_self.trans Icc_subset_Ici_self theorem Ioo_subset_Ici_self : Ioo a b ⊆ Ici a := Ioo_subset_Ico_self.trans Ico_subset_Ici_self end LocallyFiniteOrderTop section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot α] @[simp] theorem Iio_eq_empty : Iio a = ∅ ↔ IsMin a := Ioi_eq_empty (α := αᵒᵈ) @[simp] alias ⟨_, _root_.IsMin.finsetIio_eq⟩ := Iio_eq_empty @[simp] lemma Iio_nonempty : (Iio a).Nonempty ↔ ¬ IsMin a := by simp [nonempty_iff_ne_empty] theorem Iio_bot [OrderBot α] : Iio (⊥ : α) = ∅ := Iio_eq_empty.mpr isMin_bot @[simp] theorem Iic_top [OrderTop α] [Fintype α] : Iic (⊤ : α) = univ := by ext a; simp only [mem_Iic, le_top, mem_univ] @[simp, aesop safe apply (rule_sets := [finsetNonempty])] lemma nonempty_Iic : (Iic a).Nonempty := ⟨a, mem_Iic.2 le_rfl⟩ lemma nonempty_Iio : (Iio a).Nonempty ↔ ¬ IsMin a := by simp [Finset.Nonempty] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Iio_of_not_isMin⟩ := nonempty_Iio @[simp] theorem Iic_subset_Iic : Iic a ⊆ Iic b ↔ a ≤ b := by simp [← coe_subset] @[gcongr] alias ⟨_, _root_.GCongr.Finset.Iic_subset_Iic⟩ := Iic_subset_Iic @[simp] theorem Iic_ssubset_Iic : Iic a ⊂ Iic b ↔ a < b := by simp [← coe_ssubset] @[gcongr] alias ⟨_, _root_.GCongr.Finset.Iic_ssubset_Iic⟩ := Iic_ssubset_Iic @[gcongr] theorem Iio_subset_Iio (h : a ≤ b) : Iio a ⊆ Iio b := by simpa [← coe_subset] using Set.Iio_subset_Iio h @[gcongr] theorem Iio_ssubset_Iio (h : a < b) : Iio a ⊂ Iio b := by simpa [← coe_ssubset] using Set.Iio_ssubset_Iio h variable [LocallyFiniteOrder α] theorem Icc_subset_Iic_self : Icc a b ⊆ Iic b := by simpa [← coe_subset] using Set.Icc_subset_Iic_self theorem Ioc_subset_Iic_self : Ioc a b ⊆ Iic b := by simpa [← coe_subset] using Set.Ioc_subset_Iic_self theorem Ico_subset_Iio_self : Ico a b ⊆ Iio b := by simpa [← coe_subset] using Set.Ico_subset_Iio_self theorem Ioo_subset_Iio_self : Ioo a b ⊆ Iio b := by simpa [← coe_subset] using Set.Ioo_subset_Iio_self theorem Ico_subset_Iic_self : Ico a b ⊆ Iic b := Ico_subset_Icc_self.trans Icc_subset_Iic_self theorem Ioo_subset_Iic_self : Ioo a b ⊆ Iic b := Ioo_subset_Ioc_self.trans Ioc_subset_Iic_self theorem Iic_disjoint_Ioc (h : a ≤ b) : Disjoint (Iic a) (Ioc b c) := disjoint_left.2 fun _ hax hbcx ↦ (mem_Iic.1 hax).not_lt <| lt_of_le_of_lt h (mem_Ioc.1 hbcx).1 /-- An equivalence between `Finset.Iic a` and `Set.Iic a`. -/ def _root_.Equiv.IicFinsetSet (a : α) : Iic a ≃ Set.Iic a where toFun b := ⟨b.1, coe_Iic a ▸ mem_coe.2 b.2⟩ invFun b := ⟨b.1, by rw [← mem_coe, coe_Iic a]; exact b.2⟩ left_inv := fun _ ↦ rfl right_inv := fun _ ↦ rfl end LocallyFiniteOrderBot section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop α] {a : α} theorem Ioi_subset_Ici_self : Ioi a ⊆ Ici a := by simpa [← coe_subset] using Set.Ioi_subset_Ici_self theorem _root_.BddBelow.finite {s : Set α} (hs : BddBelow s) : s.Finite := let ⟨a, ha⟩ := hs (Ici a).finite_toSet.subset fun _ hx => mem_Ici.2 <| ha hx theorem _root_.Set.Infinite.not_bddBelow {s : Set α} : s.Infinite → ¬BddBelow s := mt BddBelow.finite variable [Fintype α] theorem filter_lt_eq_Ioi [DecidablePred (a < ·)] : ({x | a < x} : Finset _) = Ioi a := by ext; simp theorem filter_le_eq_Ici [DecidablePred (a ≤ ·)] : ({x | a ≤ x} : Finset _) = Ici a := by ext; simp end LocallyFiniteOrderTop section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot α] {a : α} theorem Iio_subset_Iic_self : Iio a ⊆ Iic a := by simpa [← coe_subset] using Set.Iio_subset_Iic_self theorem _root_.BddAbove.finite {s : Set α} (hs : BddAbove s) : s.Finite := hs.dual.finite theorem _root_.Set.Infinite.not_bddAbove {s : Set α} : s.Infinite → ¬BddAbove s := mt BddAbove.finite variable [Fintype α] theorem filter_gt_eq_Iio [DecidablePred (· < a)] : ({x | x < a} : Finset _) = Iio a := by ext; simp theorem filter_ge_eq_Iic [DecidablePred (· ≤ a)] : ({x | x ≤ a} : Finset _) = Iic a := by ext; simp end LocallyFiniteOrderBot section LocallyFiniteOrder variable [LocallyFiniteOrder α] @[simp] theorem Icc_bot [OrderBot α] : Icc (⊥ : α) a = Iic a := rfl @[simp] theorem Icc_top [OrderTop α] : Icc a (⊤ : α) = Ici a := rfl @[simp] theorem Ico_bot [OrderBot α] : Ico (⊥ : α) a = Iio a := rfl @[simp] theorem Ioc_top [OrderTop α] : Ioc a (⊤ : α) = Ioi a := rfl theorem Icc_bot_top [BoundedOrder α] [Fintype α] : Icc (⊥ : α) (⊤ : α) = univ := by rw [Icc_bot, Iic_top] end LocallyFiniteOrder variable [LocallyFiniteOrderTop α] [LocallyFiniteOrderBot α] theorem disjoint_Ioi_Iio (a : α) : Disjoint (Ioi a) (Iio a) := disjoint_left.2 fun _ hab hba => (mem_Ioi.1 hab).not_lt <| mem_Iio.1 hba end Preorder section PartialOrder variable [PartialOrder α] [LocallyFiniteOrder α] {a b c : α} @[simp] theorem Icc_self (a : α) : Icc a a = {a} := by rw [← coe_eq_singleton, coe_Icc, Set.Icc_self] @[simp] theorem Icc_eq_singleton_iff : Icc a b = {c} ↔ a = c ∧ b = c := by rw [← coe_eq_singleton, coe_Icc, Set.Icc_eq_singleton_iff] theorem Ico_disjoint_Ico_consecutive (a b c : α) : Disjoint (Ico a b) (Ico b c) := disjoint_left.2 fun _ hab hbc => (mem_Ico.mp hab).2.not_le (mem_Ico.mp hbc).1 @[simp] theorem Ici_top [OrderTop α] : Ici (⊤ : α) = {⊤} := Icc_eq_singleton_iff.2 ⟨rfl, rfl⟩ @[simp] theorem Iic_bot [OrderBot α] : Iic (⊥ : α) = {⊥} := Icc_eq_singleton_iff.2 ⟨rfl, rfl⟩ section DecidableEq variable [DecidableEq α] @[simp] theorem Icc_erase_left (a b : α) : (Icc a b).erase a = Ioc a b := by simp [← coe_inj] @[simp] theorem Icc_erase_right (a b : α) : (Icc a b).erase b = Ico a b := by simp [← coe_inj] @[simp] theorem Ico_erase_left (a b : α) : (Ico a b).erase a = Ioo a b := by simp [← coe_inj] @[simp] theorem Ioc_erase_right (a b : α) : (Ioc a b).erase b = Ioo a b := by simp [← coe_inj] @[simp] theorem Icc_diff_both (a b : α) : Icc a b \ {a, b} = Ioo a b := by simp [← coe_inj] @[simp] theorem Ico_insert_right (h : a ≤ b) : insert b (Ico a b) = Icc a b := by rw [← coe_inj, coe_insert, coe_Icc, coe_Ico, Set.insert_eq, Set.union_comm, Set.Ico_union_right h] @[simp] theorem Ioc_insert_left (h : a ≤ b) : insert a (Ioc a b) = Icc a b := by rw [← coe_inj, coe_insert, coe_Ioc, coe_Icc, Set.insert_eq, Set.union_comm, Set.Ioc_union_left h] @[simp] theorem Ioo_insert_left (h : a < b) : insert a (Ioo a b) = Ico a b := by rw [← coe_inj, coe_insert, coe_Ioo, coe_Ico, Set.insert_eq, Set.union_comm, Set.Ioo_union_left h] @[simp] theorem Ioo_insert_right (h : a < b) : insert b (Ioo a b) = Ioc a b := by rw [← coe_inj, coe_insert, coe_Ioo, coe_Ioc, Set.insert_eq, Set.union_comm, Set.Ioo_union_right h] @[simp] theorem Icc_diff_Ico_self (h : a ≤ b) : Icc a b \ Ico a b = {b} := by simp [← coe_inj, h] @[simp] theorem Icc_diff_Ioc_self (h : a ≤ b) : Icc a b \ Ioc a b = {a} := by simp [← coe_inj, h] @[simp] theorem Icc_diff_Ioo_self (h : a ≤ b) : Icc a b \ Ioo a b = {a, b} := by simp [← coe_inj, h] @[simp] theorem Ico_diff_Ioo_self (h : a < b) : Ico a b \ Ioo a b = {a} := by simp [← coe_inj, h] @[simp] theorem Ioc_diff_Ioo_self (h : a < b) : Ioc a b \ Ioo a b = {b} := by simp [← coe_inj, h] @[simp] theorem Ico_inter_Ico_consecutive (a b c : α) : Ico a b ∩ Ico b c = ∅ := (Ico_disjoint_Ico_consecutive a b c).eq_bot end DecidableEq -- Those lemmas are purposefully the other way around /-- `Finset.cons` version of `Finset.Ico_insert_right`. -/ theorem Icc_eq_cons_Ico (h : a ≤ b) : Icc a b = (Ico a b).cons b right_not_mem_Ico := by classical rw [cons_eq_insert, Ico_insert_right h] /-- `Finset.cons` version of `Finset.Ioc_insert_left`. -/ theorem Icc_eq_cons_Ioc (h : a ≤ b) : Icc a b = (Ioc a b).cons a left_not_mem_Ioc := by classical rw [cons_eq_insert, Ioc_insert_left h] /-- `Finset.cons` version of `Finset.Ioo_insert_right`. -/ theorem Ioc_eq_cons_Ioo (h : a < b) : Ioc a b = (Ioo a b).cons b right_not_mem_Ioo := by classical rw [cons_eq_insert, Ioo_insert_right h] /-- `Finset.cons` version of `Finset.Ioo_insert_left`. -/ theorem Ico_eq_cons_Ioo (h : a < b) : Ico a b = (Ioo a b).cons a left_not_mem_Ioo := by classical rw [cons_eq_insert, Ioo_insert_left h] theorem Ico_filter_le_left {a b : α} [DecidablePred (· ≤ a)] (hab : a < b) : {x ∈ Ico a b | x ≤ a} = {a} := by ext x rw [mem_filter, mem_Ico, mem_singleton, and_right_comm, ← le_antisymm_iff, eq_comm] exact and_iff_left_of_imp fun h => h.le.trans_lt hab theorem card_Ico_eq_card_Icc_sub_one (a b : α) : #(Ico a b) = #(Icc a b) - 1 := by classical by_cases h : a ≤ b · rw [Icc_eq_cons_Ico h, card_cons] exact (Nat.add_sub_cancel _ _).symm · rw [Ico_eq_empty fun h' => h h'.le, Icc_eq_empty h, card_empty, Nat.zero_sub] theorem card_Ioc_eq_card_Icc_sub_one (a b : α) : #(Ioc a b) = #(Icc a b) - 1 := @card_Ico_eq_card_Icc_sub_one αᵒᵈ _ _ _ _ theorem card_Ioo_eq_card_Ico_sub_one (a b : α) : #(Ioo a b) = #(Ico a b) - 1 := by classical by_cases h : a < b · rw [Ico_eq_cons_Ioo h, card_cons] exact (Nat.add_sub_cancel _ _).symm · rw [Ioo_eq_empty h, Ico_eq_empty h, card_empty, Nat.zero_sub] theorem card_Ioo_eq_card_Ioc_sub_one (a b : α) : #(Ioo a b) = #(Ioc a b) - 1 := @card_Ioo_eq_card_Ico_sub_one αᵒᵈ _ _ _ _ theorem card_Ioo_eq_card_Icc_sub_two (a b : α) : #(Ioo a b) = #(Icc a b) - 2 := by rw [card_Ioo_eq_card_Ico_sub_one, card_Ico_eq_card_Icc_sub_one] rfl end PartialOrder section Prod variable {β : Type*} section sectL lemma uIcc_map_sectL [Lattice α] [Lattice β] [LocallyFiniteOrder α] [LocallyFiniteOrder β] [DecidableLE (α × β)] (a b : α) (c : β) : (uIcc a b).map (.sectL _ c) = uIcc (a, c) (b, c) := by aesop (add safe forward [le_antisymm]) variable [Preorder α] [PartialOrder β] [LocallyFiniteOrder α] [LocallyFiniteOrder β] [DecidableLE (α × β)] (a b : α) (c : β) lemma Icc_map_sectL : (Icc a b).map (.sectL _ c) = Icc (a, c) (b, c) := by aesop (add safe forward [le_antisymm]) lemma Ioc_map_sectL : (Ioc a b).map (.sectL _ c) = Ioc (a, c) (b, c) := by aesop (add safe forward [le_antisymm, le_of_lt]) lemma Ico_map_sectL : (Ico a b).map (.sectL _ c) = Ico (a, c) (b, c) := by aesop (add safe forward [le_antisymm, le_of_lt]) lemma Ioo_map_sectL : (Ioo a b).map (.sectL _ c) = Ioo (a, c) (b, c) := by aesop (add safe forward [le_antisymm, le_of_lt]) end sectL section sectR lemma uIcc_map_sectR [Lattice α] [Lattice β] [LocallyFiniteOrder α] [LocallyFiniteOrder β] [DecidableLE (α × β)] (c : α) (a b : β) : (uIcc a b).map (.sectR c _) = uIcc (c, a) (c, b) := by aesop (add safe forward [le_antisymm]) variable [PartialOrder α] [Preorder β] [LocallyFiniteOrder α] [LocallyFiniteOrder β] [DecidableLE (α × β)] (c : α) (a b : β) lemma Icc_map_sectR : (Icc a b).map (.sectR c _) = Icc (c, a) (c, b) := by aesop (add safe forward [le_antisymm]) lemma Ioc_map_sectR : (Ioc a b).map (.sectR c _) = Ioc (c, a) (c, b) := by aesop (add safe forward [le_antisymm, le_of_lt]) lemma Ico_map_sectR : (Ico a b).map (.sectR c _) = Ico (c, a) (c, b) := by aesop (add safe forward [le_antisymm, le_of_lt]) lemma Ioo_map_sectR : (Ioo a b).map (.sectR c _) = Ioo (c, a) (c, b) := by aesop (add safe forward [le_antisymm, le_of_lt]) end sectR end Prod section BoundedPartialOrder variable [PartialOrder α] section OrderTop variable [LocallyFiniteOrderTop α] @[simp] theorem Ici_erase [DecidableEq α] (a : α) : (Ici a).erase a = Ioi a := by ext simp_rw [Finset.mem_erase, mem_Ici, mem_Ioi, lt_iff_le_and_ne, and_comm, ne_comm] @[simp] theorem Ioi_insert [DecidableEq α] (a : α) : insert a (Ioi a) = Ici a := by ext simp_rw [Finset.mem_insert, mem_Ici, mem_Ioi, le_iff_lt_or_eq, or_comm, eq_comm] theorem not_mem_Ioi_self {b : α} : b ∉ Ioi b := fun h => lt_irrefl _ (mem_Ioi.1 h) -- Purposefully written the other way around /-- `Finset.cons` version of `Finset.Ioi_insert`. -/ theorem Ici_eq_cons_Ioi (a : α) : Ici a = (Ioi a).cons a not_mem_Ioi_self := by classical rw [cons_eq_insert, Ioi_insert] theorem card_Ioi_eq_card_Ici_sub_one (a : α) : #(Ioi a) = #(Ici a) - 1 := by rw [Ici_eq_cons_Ioi, card_cons, Nat.add_sub_cancel_right] end OrderTop section OrderBot variable [LocallyFiniteOrderBot α] @[simp] theorem Iic_erase [DecidableEq α] (b : α) : (Iic b).erase b = Iio b := by ext simp_rw [Finset.mem_erase, mem_Iic, mem_Iio, lt_iff_le_and_ne, and_comm] @[simp] theorem Iio_insert [DecidableEq α] (b : α) : insert b (Iio b) = Iic b := by ext simp_rw [Finset.mem_insert, mem_Iic, mem_Iio, le_iff_lt_or_eq, or_comm] theorem not_mem_Iio_self {b : α} : b ∉ Iio b := fun h => lt_irrefl _ (mem_Iio.1 h) -- Purposefully written the other way around /-- `Finset.cons` version of `Finset.Iio_insert`. -/ theorem Iic_eq_cons_Iio (b : α) : Iic b = (Iio b).cons b not_mem_Iio_self := by classical rw [cons_eq_insert, Iio_insert] theorem card_Iio_eq_card_Iic_sub_one (a : α) : #(Iio a) = #(Iic a) - 1 := by rw [Iic_eq_cons_Iio, card_cons, Nat.add_sub_cancel_right] end OrderBot end BoundedPartialOrder section SemilatticeSup variable [SemilatticeSup α] [LocallyFiniteOrderBot α] -- TODO: Why does `id_eq` simplify the LHS here but not the LHS of `Finset.sup_Iic`? lemma sup'_Iic (a : α) : (Iic a).sup' nonempty_Iic id = a := le_antisymm (sup'_le _ _ fun _ ↦ mem_Iic.1) <| le_sup' (f := id) <| mem_Iic.2 <| le_refl a @[simp] lemma sup_Iic [OrderBot α] (a : α) : (Iic a).sup id = a := le_antisymm (Finset.sup_le fun _ ↦ mem_Iic.1) <| le_sup (f := id) <| mem_Iic.2 <| le_refl a lemma image_subset_Iic_sup [OrderBot α] [DecidableEq α] (f : ι → α) (s : Finset ι) : s.image f ⊆ Iic (s.sup f) := by refine fun i hi ↦ mem_Iic.2 ?_ obtain ⟨j, hj, rfl⟩ := mem_image.1 hi exact le_sup hj lemma subset_Iic_sup_id [OrderBot α] (s : Finset α) : s ⊆ Iic (s.sup id) := fun _ h ↦ mem_Iic.2 <| le_sup (f := id) h end SemilatticeSup section SemilatticeInf variable [SemilatticeInf α] [LocallyFiniteOrderTop α] lemma inf'_Ici (a : α) : (Ici a).inf' nonempty_Ici id = a := ge_antisymm (le_inf' _ _ fun _ ↦ mem_Ici.1) <| inf'_le (f := id) <| mem_Ici.2 <| le_refl a @[simp] lemma inf_Ici [OrderTop α] (a : α) : (Ici a).inf id = a := le_antisymm (inf_le (f := id) <| mem_Ici.2 <| le_refl a) <| Finset.le_inf fun _ ↦ mem_Ici.1 end SemilatticeInf section LinearOrder variable [LinearOrder α] section LocallyFiniteOrder variable [LocallyFiniteOrder α] theorem Ico_subset_Ico_iff {a₁ b₁ a₂ b₂ : α} (h : a₁ < b₁) : Ico a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := by rw [← coe_subset, coe_Ico, coe_Ico, Set.Ico_subset_Ico_iff h] theorem Ico_union_Ico_eq_Ico {a b c : α} (hab : a ≤ b) (hbc : b ≤ c) : Ico a b ∪ Ico b c = Ico a c := by rw [← coe_inj, coe_union, coe_Ico, coe_Ico, coe_Ico, Set.Ico_union_Ico_eq_Ico hab hbc] @[simp] theorem Ioc_union_Ioc_eq_Ioc {a b c : α} (h₁ : a ≤ b) (h₂ : b ≤ c) : Ioc a b ∪ Ioc b c = Ioc a c := by rw [← coe_inj, coe_union, coe_Ioc, coe_Ioc, coe_Ioc, Set.Ioc_union_Ioc_eq_Ioc h₁ h₂] theorem Ico_subset_Ico_union_Ico {a b c : α} : Ico a c ⊆ Ico a b ∪ Ico b c := by rw [← coe_subset, coe_union, coe_Ico, coe_Ico, coe_Ico] exact Set.Ico_subset_Ico_union_Ico theorem Ico_union_Ico' {a b c d : α} (hcb : c ≤ b) (had : a ≤ d) : Ico a b ∪ Ico c d = Ico (min a c) (max b d) := by rw [← coe_inj, coe_union, coe_Ico, coe_Ico, coe_Ico, Set.Ico_union_Ico' hcb had] theorem Ico_union_Ico {a b c d : α} (h₁ : min a b ≤ max c d) (h₂ : min c d ≤ max a b) : Ico a b ∪ Ico c d = Ico (min a c) (max b d) := by rw [← coe_inj, coe_union, coe_Ico, coe_Ico, coe_Ico, Set.Ico_union_Ico h₁ h₂] theorem Ico_inter_Ico {a b c d : α} : Ico a b ∩ Ico c d = Ico (max a c) (min b d) := by rw [← coe_inj, coe_inter, coe_Ico, coe_Ico, coe_Ico, Set.Ico_inter_Ico] theorem Ioc_inter_Ioc {a b c d : α} : Ioc a b ∩ Ioc c d = Ioc (max a c) (min b d) := by rw [← coe_inj] push_cast exact Set.Ioc_inter_Ioc @[simp] theorem Ico_filter_lt (a b c : α) : {x ∈ Ico a b | x < c} = Ico a (min b c) := by cases le_total b c with | inl h => rw [Ico_filter_lt_of_right_le h, min_eq_left h] | inr h => rw [Ico_filter_lt_of_le_right h, min_eq_right h] @[simp] theorem Ico_filter_le (a b c : α) : {x ∈ Ico a b | c ≤ x} = Ico (max a c) b := by cases le_total a c with | inl h => rw [Ico_filter_le_of_left_le h, max_eq_right h] | inr h => rw [Ico_filter_le_of_le_left h, max_eq_left h] @[simp] theorem Ioo_filter_lt (a b c : α) : {x ∈ Ioo a b | x < c} = Ioo a (min b c) := by ext simp [and_assoc] @[simp] theorem Iio_filter_lt {α} [LinearOrder α] [LocallyFiniteOrderBot α] (a b : α) : {x ∈ Iio a | x < b} = Iio (min a b) := by ext simp [and_assoc] @[simp] theorem Ico_diff_Ico_left (a b c : α) : Ico a b \ Ico a c = Ico (max a c) b := by cases le_total a c with | inl h => ext x rw [mem_sdiff, mem_Ico, mem_Ico, mem_Ico, max_eq_right h, and_right_comm, not_and, not_lt] exact and_congr_left' ⟨fun hx => hx.2 hx.1, fun hx => ⟨h.trans hx, fun _ => hx⟩⟩ | inr h => rw [Ico_eq_empty_of_le h, sdiff_empty, max_eq_left h] @[simp] theorem Ico_diff_Ico_right (a b c : α) : Ico a b \ Ico c b = Ico a (min b c) := by cases le_total b c with | inl h => rw [Ico_eq_empty_of_le h, sdiff_empty, min_eq_left h] | inr h => ext x rw [mem_sdiff, mem_Ico, mem_Ico, mem_Ico, min_eq_right h, and_assoc, not_and', not_le] exact and_congr_right' ⟨fun hx => hx.2 hx.1, fun hx => ⟨hx.trans_le h, fun _ => hx⟩⟩ @[simp] theorem Ioc_disjoint_Ioc : Disjoint (Ioc a₁ a₂) (Ioc b₁ b₂) ↔ min a₂ b₂ ≤ max a₁ b₁ := by simp_rw [disjoint_iff_inter_eq_empty, Ioc_inter_Ioc, Ioc_eq_empty_iff, not_lt] section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot α] theorem Iic_diff_Ioc : Iic b \ Ioc a b = Iic (a ⊓ b) := by rw [← coe_inj] push_cast exact Set.Iic_diff_Ioc theorem Iic_diff_Ioc_self_of_le (hab : a ≤ b) : Iic b \ Ioc a b = Iic a := by rw [Iic_diff_Ioc, min_eq_left hab] theorem Iic_union_Ioc_eq_Iic (h : a ≤ b) : Iic a ∪ Ioc a b = Iic b := by rw [← coe_inj] push_cast exact Set.Iic_union_Ioc_eq_Iic h end LocallyFiniteOrderBot end LocallyFiniteOrder section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot α] {s : Set α} theorem _root_.Set.Infinite.exists_gt (hs : s.Infinite) : ∀ a, ∃ b ∈ s, a < b := not_bddAbove_iff.1 hs.not_bddAbove theorem _root_.Set.infinite_iff_exists_gt [Nonempty α] : s.Infinite ↔ ∀ a, ∃ b ∈ s, a < b := ⟨Set.Infinite.exists_gt, Set.infinite_of_forall_exists_gt⟩ end LocallyFiniteOrderBot section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop α] {s : Set α} theorem _root_.Set.Infinite.exists_lt (hs : s.Infinite) : ∀ a, ∃ b ∈ s, b < a := not_bddBelow_iff.1 hs.not_bddBelow theorem _root_.Set.infinite_iff_exists_lt [Nonempty α] : s.Infinite ↔ ∀ a, ∃ b ∈ s, b < a := ⟨Set.Infinite.exists_lt, Set.infinite_of_forall_exists_lt⟩ end LocallyFiniteOrderTop variable [Fintype α] [LocallyFiniteOrderTop α] [LocallyFiniteOrderBot α] theorem Ioi_disjUnion_Iio (a : α) : (Ioi a).disjUnion (Iio a) (disjoint_Ioi_Iio a) = ({a} : Finset α)ᶜ := by ext simp [eq_comm] end LinearOrder section Lattice variable [Lattice α] [LocallyFiniteOrder α] {a a₁ a₂ b b₁ b₂ x : α} theorem uIcc_toDual (a b : α) : [[toDual a, toDual b]] = [[a, b]].map toDual.toEmbedding := Icc_toDual (a ⊔ b) (a ⊓ b) @[simp] theorem uIcc_of_le (h : a ≤ b) : [[a, b]] = Icc a b := by rw [uIcc, inf_eq_left.2 h, sup_eq_right.2 h] @[simp] theorem uIcc_of_ge (h : b ≤ a) : [[a, b]] = Icc b a := by rw [uIcc, inf_eq_right.2 h, sup_eq_left.2 h] theorem uIcc_comm (a b : α) : [[a, b]] = [[b, a]] := by rw [uIcc, uIcc, inf_comm, sup_comm] theorem uIcc_self : [[a, a]] = {a} := by simp [uIcc] @[simp] theorem nonempty_uIcc : Finset.Nonempty [[a, b]] := nonempty_Icc.2 inf_le_sup theorem Icc_subset_uIcc : Icc a b ⊆ [[a, b]] := Icc_subset_Icc inf_le_left le_sup_right theorem Icc_subset_uIcc' : Icc b a ⊆ [[a, b]] := Icc_subset_Icc inf_le_right le_sup_left theorem left_mem_uIcc : a ∈ [[a, b]] := mem_Icc.2 ⟨inf_le_left, le_sup_left⟩ theorem right_mem_uIcc : b ∈ [[a, b]] := mem_Icc.2 ⟨inf_le_right, le_sup_right⟩ theorem mem_uIcc_of_le (ha : a ≤ x) (hb : x ≤ b) : x ∈ [[a, b]] := Icc_subset_uIcc <| mem_Icc.2 ⟨ha, hb⟩ theorem mem_uIcc_of_ge (hb : b ≤ x) (ha : x ≤ a) : x ∈ [[a, b]] := Icc_subset_uIcc' <| mem_Icc.2 ⟨hb, ha⟩ theorem uIcc_subset_uIcc (h₁ : a₁ ∈ [[a₂, b₂]]) (h₂ : b₁ ∈ [[a₂, b₂]]) : [[a₁, b₁]] ⊆ [[a₂, b₂]] := by rw [mem_uIcc] at h₁ h₂ exact Icc_subset_Icc (_root_.le_inf h₁.1 h₂.1) (_root_.sup_le h₁.2 h₂.2) theorem uIcc_subset_Icc (ha : a₁ ∈ Icc a₂ b₂) (hb : b₁ ∈ Icc a₂ b₂) : [[a₁, b₁]] ⊆ Icc a₂ b₂ := by rw [mem_Icc] at ha hb exact Icc_subset_Icc (_root_.le_inf ha.1 hb.1) (_root_.sup_le ha.2 hb.2) theorem uIcc_subset_uIcc_iff_mem : [[a₁, b₁]] ⊆ [[a₂, b₂]] ↔ a₁ ∈ [[a₂, b₂]] ∧ b₁ ∈ [[a₂, b₂]] := ⟨fun h => ⟨h left_mem_uIcc, h right_mem_uIcc⟩, fun h => uIcc_subset_uIcc h.1 h.2⟩
theorem uIcc_subset_uIcc_iff_le' : [[a₁, b₁]] ⊆ [[a₂, b₂]] ↔ a₂ ⊓ b₂ ≤ a₁ ⊓ b₁ ∧ a₁ ⊔ b₁ ≤ a₂ ⊔ b₂ :=
Mathlib/Order/Interval/Finset/Basic.lean
1,000
1,002
/- Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Robert Y. Lewis, Johannes Hölzl, Mario Carneiro, Sébastien Gouëzel -/ import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Order.Interval.Finset.Nat import Mathlib.Topology.EMetricSpace.Defs import Mathlib.Topology.UniformSpace.Compact import Mathlib.Topology.UniformSpace.LocallyUniformConvergence import Mathlib.Topology.UniformSpace.UniformEmbedding /-! # Extended metric spaces Further results about extended metric spaces. -/ open Set Filter universe u v w variable {α : Type u} {β : Type v} {X : Type*} open scoped Uniformity Topology NNReal ENNReal Pointwise variable [PseudoEMetricSpace α] /-- The triangle (polygon) inequality for sequences of points; `Finset.Ico` version. -/ theorem edist_le_Ico_sum_edist (f : ℕ → α) {m n} (h : m ≤ n) : edist (f m) (f n) ≤ ∑ i ∈ Finset.Ico m n, edist (f i) (f (i + 1)) := by induction n, h using Nat.le_induction with | base => rw [Finset.Ico_self, Finset.sum_empty, edist_self] | succ n hle ihn => calc edist (f m) (f (n + 1)) ≤ edist (f m) (f n) + edist (f n) (f (n + 1)) := edist_triangle _ _ _ _ ≤ (∑ i ∈ Finset.Ico m n, _) + _ := add_le_add ihn le_rfl _ = ∑ i ∈ Finset.Ico m (n + 1), _ := by { rw [Nat.Ico_succ_right_eq_insert_Ico hle, Finset.sum_insert, add_comm]; simp } /-- The triangle (polygon) inequality for sequences of points; `Finset.range` version. -/ theorem edist_le_range_sum_edist (f : ℕ → α) (n : ℕ) : edist (f 0) (f n) ≤ ∑ i ∈ Finset.range n, edist (f i) (f (i + 1)) := Nat.Ico_zero_eq_range ▸ edist_le_Ico_sum_edist f (Nat.zero_le n) /-- A version of `edist_le_Ico_sum_edist` with each intermediate distance replaced with an upper estimate. -/ theorem edist_le_Ico_sum_of_edist_le {f : ℕ → α} {m n} (hmn : m ≤ n) {d : ℕ → ℝ≥0∞} (hd : ∀ {k}, m ≤ k → k < n → edist (f k) (f (k + 1)) ≤ d k) : edist (f m) (f n) ≤ ∑ i ∈ Finset.Ico m n, d i := le_trans (edist_le_Ico_sum_edist f hmn) <| Finset.sum_le_sum fun _k hk => hd (Finset.mem_Ico.1 hk).1 (Finset.mem_Ico.1 hk).2 /-- A version of `edist_le_range_sum_edist` with each intermediate distance replaced with an upper estimate. -/ theorem edist_le_range_sum_of_edist_le {f : ℕ → α} (n : ℕ) {d : ℕ → ℝ≥0∞} (hd : ∀ {k}, k < n → edist (f k) (f (k + 1)) ≤ d k) : edist (f 0) (f n) ≤ ∑ i ∈ Finset.range n, d i := Nat.Ico_zero_eq_range ▸ edist_le_Ico_sum_of_edist_le (zero_le n) fun _ => hd namespace EMetric theorem isUniformInducing_iff [PseudoEMetricSpace β] {f : α → β} : IsUniformInducing f ↔ UniformContinuous f ∧ ∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, edist (f a) (f b) < ε → edist a b < δ := isUniformInducing_iff'.trans <| Iff.rfl.and <| ((uniformity_basis_edist.comap _).le_basis_iff uniformity_basis_edist).trans <| by simp only [subset_def, Prod.forall]; rfl /-- ε-δ characterization of uniform embeddings on pseudoemetric spaces -/ nonrec theorem isUniformEmbedding_iff [PseudoEMetricSpace β] {f : α → β} : IsUniformEmbedding f ↔ Function.Injective f ∧ UniformContinuous f ∧ ∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, edist (f a) (f b) < ε → edist a b < δ := (isUniformEmbedding_iff _).trans <| and_comm.trans <| Iff.rfl.and isUniformInducing_iff /-- If a map between pseudoemetric spaces is a uniform embedding then the edistance between `f x` and `f y` is controlled in terms of the distance between `x` and `y`. In fact, this lemma holds for a `IsUniformInducing` map. TODO: generalize? -/ theorem controlled_of_isUniformEmbedding [PseudoEMetricSpace β] {f : α → β} (h : IsUniformEmbedding f) : (∀ ε > 0, ∃ δ > 0, ∀ {a b : α}, edist a b < δ → edist (f a) (f b) < ε) ∧ ∀ δ > 0, ∃ ε > 0, ∀ {a b : α}, edist (f a) (f b) < ε → edist a b < δ := ⟨uniformContinuous_iff.1 h.uniformContinuous, (isUniformEmbedding_iff.1 h).2.2⟩ /-- ε-δ characterization of Cauchy sequences on pseudoemetric spaces -/ protected theorem cauchy_iff {f : Filter α} : Cauchy f ↔ f ≠ ⊥ ∧ ∀ ε > 0, ∃ t ∈ f, ∀ x, x ∈ t → ∀ y, y ∈ t → edist x y < ε := by rw [← neBot_iff]; exact uniformity_basis_edist.cauchy_iff /-- A very useful criterion to show that a space is complete is to show that all sequences which satisfy a bound of the form `edist (u n) (u m) < B N` for all `n m ≥ N` are converging. This is often applied for `B N = 2^{-N}`, i.e., with a very fast convergence to `0`, which makes it possible to use arguments of converging series, while this is impossible to do in general for arbitrary Cauchy sequences. -/ theorem complete_of_convergent_controlled_sequences (B : ℕ → ℝ≥0∞) (hB : ∀ n, 0 < B n) (H : ∀ u : ℕ → α, (∀ N n m : ℕ, N ≤ n → N ≤ m → edist (u n) (u m) < B N) → ∃ x, Tendsto u atTop (𝓝 x)) : CompleteSpace α := UniformSpace.complete_of_convergent_controlled_sequences (fun n => { p : α × α | edist p.1 p.2 < B n }) (fun n => edist_mem_uniformity <| hB n) H /-- A sequentially complete pseudoemetric space is complete. -/ theorem complete_of_cauchySeq_tendsto : (∀ u : ℕ → α, CauchySeq u → ∃ a, Tendsto u atTop (𝓝 a)) → CompleteSpace α := UniformSpace.complete_of_cauchySeq_tendsto /-- Expressing locally uniform convergence on a set using `edist`. -/ theorem tendstoLocallyUniformlyOn_iff {ι : Type*} [TopologicalSpace β] {F : ι → β → α} {f : β → α} {p : Filter ι} {s : Set β} : TendstoLocallyUniformlyOn F f p s ↔ ∀ ε > 0, ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, ∀ᶠ n in p, ∀ y ∈ t, edist (f y) (F n y) < ε := by refine ⟨fun H ε hε => H _ (edist_mem_uniformity hε), fun H u hu x hx => ?_⟩ rcases mem_uniformity_edist.1 hu with ⟨ε, εpos, hε⟩ rcases H ε εpos x hx with ⟨t, ht, Ht⟩ exact ⟨t, ht, Ht.mono fun n hs x hx => hε (hs x hx)⟩ /-- Expressing uniform convergence on a set using `edist`. -/ theorem tendstoUniformlyOn_iff {ι : Type*} {F : ι → β → α} {f : β → α} {p : Filter ι} {s : Set β} : TendstoUniformlyOn F f p s ↔ ∀ ε > 0, ∀ᶠ n in p, ∀ x ∈ s, edist (f x) (F n x) < ε := by refine ⟨fun H ε hε => H _ (edist_mem_uniformity hε), fun H u hu => ?_⟩ rcases mem_uniformity_edist.1 hu with ⟨ε, εpos, hε⟩ exact (H ε εpos).mono fun n hs x hx => hε (hs x hx) /-- Expressing locally uniform convergence using `edist`. -/ theorem tendstoLocallyUniformly_iff {ι : Type*} [TopologicalSpace β] {F : ι → β → α} {f : β → α} {p : Filter ι} : TendstoLocallyUniformly F f p ↔ ∀ ε > 0, ∀ x : β, ∃ t ∈ 𝓝 x, ∀ᶠ n in p, ∀ y ∈ t, edist (f y) (F n y) < ε := by simp only [← tendstoLocallyUniformlyOn_univ, tendstoLocallyUniformlyOn_iff, mem_univ, forall_const, exists_prop, nhdsWithin_univ] /-- Expressing uniform convergence using `edist`. -/ theorem tendstoUniformly_iff {ι : Type*} {F : ι → β → α} {f : β → α} {p : Filter ι} : TendstoUniformly F f p ↔ ∀ ε > 0, ∀ᶠ n in p, ∀ x, edist (f x) (F n x) < ε := by simp only [← tendstoUniformlyOn_univ, tendstoUniformlyOn_iff, mem_univ, forall_const] end EMetric open EMetric namespace EMetric variable {x y z : α} {ε ε₁ ε₂ : ℝ≥0∞} {s t : Set α} theorem inseparable_iff : Inseparable x y ↔ edist x y = 0 := by simp [inseparable_iff_mem_closure, mem_closure_iff, edist_comm, forall_lt_iff_le'] alias ⟨_root_.Inseparable.edist_eq_zero, _⟩ := EMetric.inseparable_iff -- see Note [nolint_ge] /-- In a pseudoemetric space, Cauchy sequences are characterized by the fact that, eventually, the pseudoedistance between its elements is arbitrarily small -/ theorem cauchySeq_iff [Nonempty β] [SemilatticeSup β] {u : β → α} : CauchySeq u ↔ ∀ ε > 0, ∃ N, ∀ m, N ≤ m → ∀ n, N ≤ n → edist (u m) (u n) < ε := uniformity_basis_edist.cauchySeq_iff /-- A variation around the emetric characterization of Cauchy sequences -/ theorem cauchySeq_iff' [Nonempty β] [SemilatticeSup β] {u : β → α} : CauchySeq u ↔ ∀ ε > (0 : ℝ≥0∞), ∃ N, ∀ n ≥ N, edist (u n) (u N) < ε := uniformity_basis_edist.cauchySeq_iff' /-- A variation of the emetric characterization of Cauchy sequences that deals with `ℝ≥0` upper bounds. -/ theorem cauchySeq_iff_NNReal [Nonempty β] [SemilatticeSup β] {u : β → α} : CauchySeq u ↔ ∀ ε : ℝ≥0, 0 < ε → ∃ N, ∀ n, N ≤ n → edist (u n) (u N) < ε := uniformity_basis_edist_nnreal.cauchySeq_iff' theorem totallyBounded_iff {s : Set α} : TotallyBounded s ↔ ∀ ε > 0, ∃ t : Set α, t.Finite ∧ s ⊆ ⋃ y ∈ t, ball y ε := ⟨fun H _ε ε0 => H _ (edist_mem_uniformity ε0), fun H _r ru => let ⟨ε, ε0, hε⟩ := mem_uniformity_edist.1 ru let ⟨t, ft, h⟩ := H ε ε0 ⟨t, ft, h.trans <| iUnion₂_mono fun _ _ _ => hε⟩⟩ theorem totallyBounded_iff' {s : Set α} : TotallyBounded s ↔ ∀ ε > 0, ∃ t, t ⊆ s ∧ Set.Finite t ∧ s ⊆ ⋃ y ∈ t, ball y ε := ⟨fun H _ε ε0 => (totallyBounded_iff_subset.1 H) _ (edist_mem_uniformity ε0), fun H _r ru => let ⟨ε, ε0, hε⟩ := mem_uniformity_edist.1 ru let ⟨t, _, ft, h⟩ := H ε ε0 ⟨t, ft, h.trans <| iUnion₂_mono fun _ _ _ => hε⟩⟩ section Compact -- TODO: generalize to metrizable spaces /-- A compact set in a pseudo emetric space is separable, i.e., it is a subset of the closure of a countable set. -/ theorem subset_countable_closure_of_compact {s : Set α} (hs : IsCompact s) : ∃ t, t ⊆ s ∧ t.Countable ∧ s ⊆ closure t := by refine subset_countable_closure_of_almost_dense_set s fun ε hε => ?_ rcases totallyBounded_iff'.1 hs.totallyBounded ε hε with ⟨t, -, htf, hst⟩ exact ⟨t, htf.countable, hst.trans <| iUnion₂_mono fun _ _ => ball_subset_closedBall⟩ end Compact section SecondCountable open TopologicalSpace variable (α) in /-- A sigma compact pseudo emetric space has second countable topology. -/ instance (priority := 90) secondCountable_of_sigmaCompact [SigmaCompactSpace α] : SecondCountableTopology α := by suffices SeparableSpace α by exact UniformSpace.secondCountable_of_separable α choose T _ hTc hsubT using fun n => subset_countable_closure_of_compact (isCompact_compactCovering α n) refine ⟨⟨⋃ n, T n, countable_iUnion hTc, fun x => ?_⟩⟩ rcases iUnion_eq_univ_iff.1 (iUnion_compactCovering α) x with ⟨n, hn⟩ exact closure_mono (subset_iUnion _ n) (hsubT _ hn) theorem secondCountable_of_almost_dense_set (hs : ∀ ε > 0, ∃ t : Set α, t.Countable ∧ ⋃ x ∈ t, closedBall x ε = univ) : SecondCountableTopology α := by suffices SeparableSpace α from UniformSpace.secondCountable_of_separable α have : ∀ ε > 0, ∃ t : Set α, Set.Countable t ∧ univ ⊆ ⋃ x ∈ t, closedBall x ε := by simpa only [univ_subset_iff] using hs rcases subset_countable_closure_of_almost_dense_set (univ : Set α) this with ⟨t, -, htc, ht⟩ exact ⟨⟨t, htc, fun x => ht (mem_univ x)⟩⟩ end SecondCountable end EMetric variable {γ : Type w} [EMetricSpace γ] -- see Note [lower instance priority] /-- An emetric space is separated -/ instance (priority := 100) EMetricSpace.instT0Space : T0Space γ where t0 _ _ h := eq_of_edist_eq_zero <| inseparable_iff.1 h /-- A map between emetric spaces is a uniform embedding if and only if the edistance between `f x` and `f y` is controlled in terms of the distance between `x` and `y` and conversely. -/ theorem EMetric.isUniformEmbedding_iff' [PseudoEMetricSpace β] {f : γ → β} : IsUniformEmbedding f ↔ (∀ ε > 0, ∃ δ > 0, ∀ {a b : γ}, edist a b < δ → edist (f a) (f b) < ε) ∧ ∀ δ > 0, ∃ ε > 0, ∀ {a b : γ}, edist (f a) (f b) < ε → edist a b < δ := by rw [isUniformEmbedding_iff_isUniformInducing, isUniformInducing_iff, uniformContinuous_iff] /-- If a `PseudoEMetricSpace` is a T₀ space, then it is an `EMetricSpace`. -/ -- TODO: make it an instance? abbrev EMetricSpace.ofT0PseudoEMetricSpace (α : Type*) [PseudoEMetricSpace α] [T0Space α] : EMetricSpace α := { ‹PseudoEMetricSpace α› with eq_of_edist_eq_zero := fun h => (EMetric.inseparable_iff.2 h).eq } /-- The product of two emetric spaces, with the max distance, is an extended metric spaces. We make sure that the uniform structure thus constructed is the one corresponding to the product of uniform spaces, to avoid diamond problems. -/ instance Prod.emetricSpaceMax [EMetricSpace β] : EMetricSpace (γ × β) := .ofT0PseudoEMetricSpace _ namespace EMetric /-- A compact set in an emetric space is separable, i.e., it is the closure of a countable set. -/ theorem countable_closure_of_compact {s : Set γ} (hs : IsCompact s) : ∃ t, t ⊆ s ∧ t.Countable ∧ s = closure t := by rcases subset_countable_closure_of_compact hs with ⟨t, hts, htc, hsub⟩ exact ⟨t, hts, htc, hsub.antisymm (closure_minimal hts hs.isClosed)⟩ end EMetric /-! ### Separation quotient -/ instance [PseudoEMetricSpace X] : EDist (SeparationQuotient X) where edist := SeparationQuotient.lift₂ edist fun _ _ _ _ hx hy => edist_congr (EMetric.inseparable_iff.1 hx) (EMetric.inseparable_iff.1 hy) @[simp] theorem SeparationQuotient.edist_mk [PseudoEMetricSpace X] (x y : X) : edist (mk x) (mk y) = edist x y := rfl open SeparationQuotient in instance [PseudoEMetricSpace X] : EMetricSpace (SeparationQuotient X) := @EMetricSpace.ofT0PseudoEMetricSpace (SeparationQuotient X) { edist_self := surjective_mk.forall.2 edist_self, edist_comm := surjective_mk.forall₂.2 edist_comm, edist_triangle := surjective_mk.forall₃.2 edist_triangle, toUniformSpace := inferInstance, uniformity_edist := comap_injective (surjective_mk.prodMap surjective_mk) <| by simp [comap_mk_uniformity, PseudoEMetricSpace.uniformity_edist] } _ namespace TopologicalSpace section Compact open Topology /-- If a set `s` is separable in a (pseudo extended) metric space, then it admits a countable dense subset. This is not obvious, as the countable set whose closure covers `s` given by the definition of separability does not need in general to be contained in `s`. -/ theorem IsSeparable.exists_countable_dense_subset {s : Set α} (hs : IsSeparable s) : ∃ t, t ⊆ s ∧ t.Countable ∧ s ⊆ closure t := by have : ∀ ε > 0, ∃ t : Set α, t.Countable ∧ s ⊆ ⋃ x ∈ t, closedBall x ε := fun ε ε0 => by rcases hs with ⟨t, htc, hst⟩ refine ⟨t, htc, hst.trans fun x hx => ?_⟩ rcases mem_closure_iff.1 hx ε ε0 with ⟨y, hyt, hxy⟩ exact mem_iUnion₂.2 ⟨y, hyt, mem_closedBall.2 hxy.le⟩ exact subset_countable_closure_of_almost_dense_set _ this /-- If a set `s` is separable, then the corresponding subtype is separable in a (pseudo extended) metric space. This is not obvious, as the countable set whose closure covers `s` does not need in general to be contained in `s`. -/ theorem IsSeparable.separableSpace {s : Set α} (hs : IsSeparable s) : SeparableSpace s := by rcases hs.exists_countable_dense_subset with ⟨t, hts, htc, hst⟩ lift t to Set s using hts refine ⟨⟨t, countable_of_injective_of_countable_image Subtype.coe_injective.injOn htc, ?_⟩⟩ rwa [IsInducing.subtypeVal.dense_iff, Subtype.forall] end Compact end TopologicalSpace section LebesgueNumberLemma variable {s : Set α} theorem lebesgue_number_lemma_of_emetric {ι : Sort*} {c : ι → Set α} (hs : IsCompact s) (hc₁ : ∀ i, IsOpen (c i)) (hc₂ : s ⊆ ⋃ i, c i) : ∃ δ > 0, ∀ x ∈ s, ∃ i, ball x δ ⊆ c i := by simpa only [ball, UniformSpace.ball, preimage_setOf_eq, edist_comm] using uniformity_basis_edist.lebesgue_number_lemma hs hc₁ hc₂ theorem lebesgue_number_lemma_of_emetric_nhds' {c : (x : α) → x ∈ s → Set α} (hs : IsCompact s) (hc : ∀ x hx, c x hx ∈ 𝓝 x) : ∃ δ > 0, ∀ x ∈ s, ∃ y : s, ball x δ ⊆ c y y.2 := by simpa only [ball, UniformSpace.ball, preimage_setOf_eq, edist_comm] using uniformity_basis_edist.lebesgue_number_lemma_nhds' hs hc theorem lebesgue_number_lemma_of_emetric_nhds {c : α → Set α} (hs : IsCompact s) (hc : ∀ x ∈ s, c x ∈ 𝓝 x) : ∃ δ > 0, ∀ x ∈ s, ∃ y, ball x δ ⊆ c y := by simpa only [ball, UniformSpace.ball, preimage_setOf_eq, edist_comm] using uniformity_basis_edist.lebesgue_number_lemma_nhds hs hc theorem lebesgue_number_lemma_of_emetric_nhdsWithin' {c : (x : α) → x ∈ s → Set α} (hs : IsCompact s) (hc : ∀ x hx, c x hx ∈ 𝓝[s] x) : ∃ δ > 0, ∀ x ∈ s, ∃ y : s, ball x δ ∩ s ⊆ c y y.2 := by simpa only [ball, UniformSpace.ball, preimage_setOf_eq, edist_comm] using uniformity_basis_edist.lebesgue_number_lemma_nhdsWithin' hs hc theorem lebesgue_number_lemma_of_emetric_nhdsWithin {c : α → Set α} (hs : IsCompact s) (hc : ∀ x ∈ s, c x ∈ 𝓝[s] x) : ∃ δ > 0, ∀ x ∈ s, ∃ y, ball x δ ∩ s ⊆ c y := by simpa only [ball, UniformSpace.ball, preimage_setOf_eq, edist_comm] using uniformity_basis_edist.lebesgue_number_lemma_nhdsWithin hs hc theorem lebesgue_number_lemma_of_emetric_sUnion {c : Set (Set α)} (hs : IsCompact s) (hc₁ : ∀ t ∈ c, IsOpen t) (hc₂ : s ⊆ ⋃₀ c) : ∃ δ > 0, ∀ x ∈ s, ∃ t ∈ c, ball x δ ⊆ t := by rw [sUnion_eq_iUnion] at hc₂; simpa using lebesgue_number_lemma_of_emetric hs (by simpa) hc₂ end LebesgueNumberLemma
Mathlib/Topology/EMetricSpace/Basic.lean
997
999
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Judith Ludwig, Christian Merten -/ import Mathlib.Algebra.GeomSum import Mathlib.LinearAlgebra.SModEq import Mathlib.RingTheory.Jacobson.Ideal import Mathlib.RingTheory.Ideal.Quotient.PowTransition /-! # Completion of a module with respect to an ideal. In this file we define the notions of Hausdorff, precomplete, and complete for an `R`-module `M` with respect to an ideal `I`: ## Main definitions - `IsHausdorff I M`: this says that the intersection of `I^n M` is `0`. - `IsPrecomplete I M`: this says that every Cauchy sequence converges. - `IsAdicComplete I M`: this says that `M` is Hausdorff and precomplete. - `Hausdorffification I M`: this is the universal Hausdorff module with a map from `M`. - `AdicCompletion I M`: if `I` is finitely generated, then this is the universal complete module (TODO) with a map from `M`. This map is injective iff `M` is Hausdorff and surjective iff `M` is precomplete. -/ suppress_compilation open Submodule variable {R S T : Type*} [CommRing R] (I : Ideal R) variable (M : Type*) [AddCommGroup M] [Module R M] variable {N : Type*} [AddCommGroup N] [Module R N] /-- A module `M` is Hausdorff with respect to an ideal `I` if `⋂ I^n M = 0`. -/ class IsHausdorff : Prop where haus' : ∀ x : M, (∀ n : ℕ, x ≡ 0 [SMOD (I ^ n • ⊤ : Submodule R M)]) → x = 0 /-- A module `M` is precomplete with respect to an ideal `I` if every Cauchy sequence converges. -/ class IsPrecomplete : Prop where prec' : ∀ f : ℕ → M, (∀ {m n}, m ≤ n → f m ≡ f n [SMOD (I ^ m • ⊤ : Submodule R M)]) → ∃ L : M, ∀ n, f n ≡ L [SMOD (I ^ n • ⊤ : Submodule R M)] /-- A module `M` is `I`-adically complete if it is Hausdorff and precomplete. -/ class IsAdicComplete : Prop extends IsHausdorff I M, IsPrecomplete I M variable {I M} theorem IsHausdorff.haus (_ : IsHausdorff I M) : ∀ x : M, (∀ n : ℕ, x ≡ 0 [SMOD (I ^ n • ⊤ : Submodule R M)]) → x = 0 := IsHausdorff.haus' theorem isHausdorff_iff : IsHausdorff I M ↔ ∀ x : M, (∀ n : ℕ, x ≡ 0 [SMOD (I ^ n • ⊤ : Submodule R M)]) → x = 0 := ⟨IsHausdorff.haus, fun h => ⟨h⟩⟩ theorem IsHausdorff.eq_iff_smodEq [IsHausdorff I M] {x y : M} : x = y ↔ ∀ n, x ≡ y [SMOD (I ^ n • ⊤ : Submodule R M)] := by refine ⟨fun h _ ↦ h ▸ rfl, fun h ↦ ?_⟩ rw [← sub_eq_zero] apply IsHausdorff.haus' (I := I) (x - y) simpa [SModEq.sub_mem] using h theorem IsPrecomplete.prec (_ : IsPrecomplete I M) {f : ℕ → M} : (∀ {m n}, m ≤ n → f m ≡ f n [SMOD (I ^ m • ⊤ : Submodule R M)]) → ∃ L : M, ∀ n, f n ≡ L [SMOD (I ^ n • ⊤ : Submodule R M)] := IsPrecomplete.prec' _ theorem isPrecomplete_iff : IsPrecomplete I M ↔ ∀ f : ℕ → M, (∀ {m n}, m ≤ n → f m ≡ f n [SMOD (I ^ m • ⊤ : Submodule R M)]) → ∃ L : M, ∀ n, f n ≡ L [SMOD (I ^ n • ⊤ : Submodule R M)] := ⟨fun h => h.1, fun h => ⟨h⟩⟩ variable (I M) /-- The Hausdorffification of a module with respect to an ideal. -/ abbrev Hausdorffification : Type _ := M ⧸ (⨅ n : ℕ, I ^ n • ⊤ : Submodule R M) /-- The canonical linear map `M ⧸ (I ^ n • ⊤) →ₗ[R] M ⧸ (I ^ m • ⊤)` for `m ≤ n` used to define `AdicCompletion`. -/ abbrev AdicCompletion.transitionMap {m n : ℕ} (hmn : m ≤ n) := factorPow I M hmn /-- The completion of a module with respect to an ideal. This is Hausdorff but not necessarily complete: a classical sufficient condition for completeness is that `M` be finitely generated [Stacks, 0G1Q]. -/ def AdicCompletion : Type _ := { f : ∀ n : ℕ, M ⧸ (I ^ n • ⊤ : Submodule R M) // ∀ {m n} (hmn : m ≤ n), AdicCompletion.transitionMap I M hmn (f n) = f m } namespace IsHausdorff instance bot : IsHausdorff (⊥ : Ideal R) M := ⟨fun x hx => by simpa only [pow_one ⊥, bot_smul, SModEq.bot] using hx 1⟩ variable {M} in protected theorem subsingleton (h : IsHausdorff (⊤ : Ideal R) M) : Subsingleton M := ⟨fun x y => eq_of_sub_eq_zero <| h.haus (x - y) fun n => by rw [Ideal.top_pow, top_smul] exact SModEq.top⟩ instance (priority := 100) of_subsingleton [Subsingleton M] : IsHausdorff I M := ⟨fun _ _ => Subsingleton.elim _ _⟩ variable {I M} theorem iInf_pow_smul (h : IsHausdorff I M) : (⨅ n : ℕ, I ^ n • ⊤ : Submodule R M) = ⊥ := eq_bot_iff.2 fun x hx => (mem_bot _).2 <| h.haus x fun n => SModEq.zero.2 <| (mem_iInf fun n : ℕ => I ^ n • ⊤).1 hx n end IsHausdorff namespace Hausdorffification /-- The canonical linear map to the Hausdorffification. -/ def of : M →ₗ[R] Hausdorffification I M := mkQ _ variable {I M} @[elab_as_elim] theorem induction_on {C : Hausdorffification I M → Prop} (x : Hausdorffification I M) (ih : ∀ x, C (of I M x)) : C x := Quotient.inductionOn' x ih variable (I M) instance : IsHausdorff I (Hausdorffification I M) := ⟨fun x => Quotient.inductionOn' x fun x hx => (Quotient.mk_eq_zero _).2 <| (mem_iInf _).2 fun n => by have := comap_map_mkQ (⨅ n : ℕ, I ^ n • ⊤ : Submodule R M) (I ^ n • ⊤) simp only [sup_of_le_right (iInf_le (fun n => (I ^ n • ⊤ : Submodule R M)) n)] at this rw [← this, map_smul'', mem_comap, Submodule.map_top, range_mkQ, ← SModEq.zero] exact hx n⟩ variable {M} [h : IsHausdorff I N] /-- Universal property of Hausdorffification: any linear map to a Hausdorff module extends to a unique map from the Hausdorffification. -/ def lift (f : M →ₗ[R] N) : Hausdorffification I M →ₗ[R] N := liftQ _ f <| map_le_iff_le_comap.1 <| h.iInf_pow_smul ▸ le_iInf fun n => le_trans (map_mono <| iInf_le _ n) <| by rw [map_smul''] exact smul_mono le_rfl le_top theorem lift_of (f : M →ₗ[R] N) (x : M) : lift I f (of I M x) = f x := rfl theorem lift_comp_of (f : M →ₗ[R] N) : (lift I f).comp (of I M) = f := LinearMap.ext fun _ => rfl /-- Uniqueness of lift. -/ theorem lift_eq (f : M →ₗ[R] N) (g : Hausdorffification I M →ₗ[R] N) (hg : g.comp (of I M) = f) : g = lift I f := LinearMap.ext fun x => induction_on x fun x => by rw [lift_of, ← hg, LinearMap.comp_apply] end Hausdorffification namespace IsPrecomplete instance bot : IsPrecomplete (⊥ : Ideal R) M := by refine ⟨fun f hf => ⟨f 1, fun n => ?_⟩⟩ rcases n with - | n · rw [pow_zero, Ideal.one_eq_top, top_smul] exact SModEq.top specialize hf (Nat.le_add_left 1 n) rw [pow_one, bot_smul, SModEq.bot] at hf; rw [hf] instance top : IsPrecomplete (⊤ : Ideal R) M := ⟨fun f _ => ⟨0, fun n => by rw [Ideal.top_pow, top_smul] exact SModEq.top⟩⟩ instance (priority := 100) of_subsingleton [Subsingleton M] : IsPrecomplete I M := ⟨fun f _ => ⟨0, fun n => by rw [Subsingleton.elim (f n) 0]⟩⟩ end IsPrecomplete namespace AdicCompletion /-- `AdicCompletion` is the submodule of compatible families in `∀ n : ℕ, M ⧸ (I ^ n • ⊤)`. -/ def submodule : Submodule R (∀ n : ℕ, M ⧸ (I ^ n • ⊤ : Submodule R M)) where carrier := { f | ∀ {m n} (hmn : m ≤ n), AdicCompletion.transitionMap I M hmn (f n) = f m } zero_mem' hmn := by rw [Pi.zero_apply, Pi.zero_apply, LinearMap.map_zero] add_mem' hf hg m n hmn := by rw [Pi.add_apply, Pi.add_apply, LinearMap.map_add, hf hmn, hg hmn] smul_mem' c f hf m n hmn := by rw [Pi.smul_apply, Pi.smul_apply, LinearMap.map_smul, hf hmn] instance : Zero (AdicCompletion I M) where zero := ⟨0, by simp⟩ instance : Add (AdicCompletion I M) where add x y := ⟨x.val + y.val, by simp [x.property, y.property]⟩ instance : Neg (AdicCompletion I M) where neg x := ⟨- x.val, by simp [x.property]⟩ instance : Sub (AdicCompletion I M) where sub x y := ⟨x.val - y.val, by simp [x.property, y.property]⟩ instance instSMul [SMul S R] [SMul S M] [IsScalarTower S R M] : SMul S (AdicCompletion I M) where smul r x := ⟨r • x.val, by simp [x.property]⟩ @[simp, norm_cast] lemma val_zero : (0 : AdicCompletion I M).val = 0 := rfl lemma val_zero_apply (n : ℕ) : (0 : AdicCompletion I M).val n = 0 := rfl variable {I M} @[simp, norm_cast] lemma val_add (f g : AdicCompletion I M) : (f + g).val = f.val + g.val := rfl @[simp, norm_cast] lemma val_sub (f g : AdicCompletion I M) : (f - g).val = f.val - g.val := rfl @[simp, norm_cast] lemma val_neg (f : AdicCompletion I M) : (-f).val = -f.val := rfl lemma val_add_apply (f g : AdicCompletion I M) (n : ℕ) : (f + g).val n = f.val n + g.val n := rfl lemma val_sub_apply (f g : AdicCompletion I M) (n : ℕ) : (f - g).val n = f.val n - g.val n := rfl lemma val_neg_apply (f : AdicCompletion I M) (n : ℕ) : (-f).val n = -f.val n := rfl /- No `simp` attribute, since it causes `simp` unification timeouts when considering the `Module (AdicCompletion I R) (AdicCompletion I M)` instance (see `AdicCompletion/Algebra`). -/ @[norm_cast] lemma val_smul [SMul S R] [SMul S M] [IsScalarTower S R M] (s : S) (f : AdicCompletion I M) : (s • f).val = s • f.val := rfl lemma val_smul_apply [SMul S R] [SMul S M] [IsScalarTower S R M] (s : S) (f : AdicCompletion I M) (n : ℕ) : (s • f).val n = s • f.val n := rfl @[ext] lemma ext {x y : AdicCompletion I M} (h : ∀ n, x.val n = y.val n) : x = y := Subtype.eq <| funext h variable (I M) instance : AddCommGroup (AdicCompletion I M) := let f : AdicCompletion I M → ∀ n, M ⧸ (I ^ n • ⊤ : Submodule R M) := Subtype.val Subtype.val_injective.addCommGroup f rfl val_add val_neg val_sub (fun _ _ ↦ val_smul ..) (fun _ _ ↦ val_smul ..) instance [Semiring S] [SMul S R] [Module S M] [IsScalarTower S R M] : Module S (AdicCompletion I M) := let f : AdicCompletion I M →+ ∀ n, M ⧸ (I ^ n • ⊤ : Submodule R M) := { toFun := Subtype.val, map_zero' := rfl, map_add' := fun _ _ ↦ rfl } Subtype.val_injective.module S f val_smul instance instIsScalarTower [SMul S T] [SMul S R] [SMul T R] [SMul S M] [SMul T M] [IsScalarTower S R M] [IsScalarTower T R M] [IsScalarTower S T M] : IsScalarTower S T (AdicCompletion I M) where smul_assoc s t f := by ext; simp [val_smul] instance instSMulCommClass [SMul S R] [SMul T R] [SMul S M] [SMul T M] [IsScalarTower S R M] [IsScalarTower T R M] [SMulCommClass S T M] : SMulCommClass S T (AdicCompletion I M) where smul_comm s t f := by ext; simp [val_smul, smul_comm] instance instIsCentralScalar [SMul S R] [SMul Sᵐᵒᵖ R] [SMul S M] [SMul Sᵐᵒᵖ M] [IsScalarTower S R M] [IsScalarTower Sᵐᵒᵖ R M] [IsCentralScalar S M] : IsCentralScalar S (AdicCompletion I M) where op_smul_eq_smul s f := by ext; simp [val_smul, op_smul_eq_smul] /-- The canonical inclusion from the completion to the product. -/ @[simps] def incl : AdicCompletion I M →ₗ[R] (∀ n, M ⧸ (I ^ n • ⊤ : Submodule R M)) where toFun x := x.val map_add' _ _ := rfl map_smul' _ _ := rfl variable {I M} @[simp, norm_cast] lemma val_sum {ι : Type*} (s : Finset ι) (f : ι → AdicCompletion I M) : (∑ i ∈ s, f i).val = ∑ i ∈ s, (f i).val := by simp_rw [← funext (incl_apply _ _ _), map_sum] lemma val_sum_apply {ι : Type*} (s : Finset ι) (f : ι → AdicCompletion I M) (n : ℕ) : (∑ i ∈ s, f i).val n = ∑ i ∈ s, (f i).val n := by simp variable (I M) /-- The canonical linear map to the completion. -/ def of : M →ₗ[R] AdicCompletion I M where toFun x := ⟨fun n => mkQ (I ^ n • ⊤ : Submodule R M) x, fun _ => rfl⟩ map_add' _ _ := rfl map_smul' _ _ := rfl @[simp] theorem of_apply (x : M) (n : ℕ) : (of I M x).1 n = mkQ (I ^ n • ⊤ : Submodule R M) x := rfl /-- Linearly evaluating a sequence in the completion at a given input. -/ def eval (n : ℕ) : AdicCompletion I M →ₗ[R] M ⧸ (I ^ n • ⊤ : Submodule R M) where toFun f := f.1 n map_add' _ _ := rfl map_smul' _ _ := rfl @[simp] theorem coe_eval (n : ℕ) : (eval I M n : AdicCompletion I M → M ⧸ (I ^ n • ⊤ : Submodule R M)) = fun f => f.1 n := rfl theorem eval_apply (n : ℕ) (f : AdicCompletion I M) : eval I M n f = f.1 n := rfl theorem eval_of (n : ℕ) (x : M) : eval I M n (of I M x) = mkQ (I ^ n • ⊤ : Submodule R M) x := rfl @[simp] theorem eval_comp_of (n : ℕ) : (eval I M n).comp (of I M) = mkQ _ := rfl theorem eval_surjective (n : ℕ) : Function.Surjective (eval I M n) := fun x ↦ Quotient.inductionOn' x fun x ↦ ⟨of I M x, rfl⟩ @[simp] theorem range_eval (n : ℕ) : LinearMap.range (eval I M n) = ⊤ := LinearMap.range_eq_top.2 (eval_surjective I M n) variable {I M} variable (I M) instance : IsHausdorff I (AdicCompletion I M) where haus' x h := ext fun n ↦ by refine smul_induction_on (SModEq.zero.1 <| h n) (fun r hr x _ ↦ ?_) (fun x y hx hy ↦ ?_) · simp only [val_smul_apply, val_zero] exact Quotient.inductionOn' (x.val n) (fun a ↦ SModEq.zero.2 <| smul_mem_smul hr mem_top) · simp only [val_add_apply, hx, val_zero_apply, hy, add_zero] @[simp] theorem transitionMap_comp_eval_apply {m n : ℕ} (hmn : m ≤ n) (x : AdicCompletion I M) : transitionMap I M hmn (x.val n) = x.val m := x.property hmn @[simp] theorem transitionMap_comp_eval {m n : ℕ} (hmn : m ≤ n) : transitionMap I M hmn ∘ₗ eval I M n = eval I M m := by ext x simp /-- A sequence `ℕ → M` is an `I`-adic Cauchy sequence if for every `m ≤ n`, `f m ≡ f n` modulo `I ^ m • ⊤`. -/ def IsAdicCauchy (f : ℕ → M) : Prop := ∀ {m n}, m ≤ n → f m ≡ f n [SMOD (I ^ m • ⊤ : Submodule R M)] /-- The type of `I`-adic Cauchy sequences. -/ def AdicCauchySequence : Type _ := { f : ℕ → M // IsAdicCauchy I M f } namespace AdicCauchySequence /-- The type of `I`-adic cauchy sequences is a submodule of the product `ℕ → M`. -/ def submodule : Submodule R (ℕ → M) where carrier := { f | IsAdicCauchy I M f } add_mem' := by intro f g hf hg m n hmn exact SModEq.add (hf hmn) (hg hmn) zero_mem' := by intro _ _ _ rfl smul_mem' := by intro r f hf m n hmn exact SModEq.smul (hf hmn) r instance : Zero (AdicCauchySequence I M) where zero := ⟨0, fun _ ↦ rfl⟩ instance : Add (AdicCauchySequence I M) where add x y := ⟨x.val + y.val, fun hmn ↦ SModEq.add (x.property hmn) (y.property hmn)⟩ instance : Neg (AdicCauchySequence I M) where neg x := ⟨- x.val, fun hmn ↦ SModEq.neg (x.property hmn)⟩ instance : Sub (AdicCauchySequence I M) where sub x y := ⟨x.val - y.val, fun hmn ↦ SModEq.sub (x.property hmn) (y.property hmn)⟩ instance : SMul ℕ (AdicCauchySequence I M) where smul n x := ⟨n • x.val, fun hmn ↦ SModEq.nsmul (x.property hmn) n⟩ instance : SMul ℤ (AdicCauchySequence I M) where smul n x := ⟨n • x.val, fun hmn ↦ SModEq.zsmul (x.property hmn) n⟩ instance : AddCommGroup (AdicCauchySequence I M) := by let f : AdicCauchySequence I M → (ℕ → M) := Subtype.val apply Subtype.val_injective.addCommGroup f rfl (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) instance : SMul R (AdicCauchySequence I M) where smul r x := ⟨r • x.val, fun hmn ↦ SModEq.smul (x.property hmn) r⟩ instance : Module R (AdicCauchySequence I M) := let f : AdicCauchySequence I M →+ (ℕ → M) := { toFun := Subtype.val, map_zero' := rfl, map_add' := fun _ _ ↦ rfl } Subtype.val_injective.module R f (fun _ _ ↦ rfl) instance : CoeFun (AdicCauchySequence I M) (fun _ ↦ ℕ → M) where coe f := f.val @[simp] theorem zero_apply (n : ℕ) : (0 : AdicCauchySequence I M) n = 0 := rfl variable {I M} @[simp] theorem add_apply (n : ℕ) (f g : AdicCauchySequence I M) : (f + g) n = f n + g n := rfl @[simp] theorem sub_apply (n : ℕ) (f g : AdicCauchySequence I M) : (f - g) n = f n - g n := rfl @[simp] theorem smul_apply (n : ℕ) (r : R) (f : AdicCauchySequence I M) : (r • f) n = r • f n := rfl @[ext] theorem ext {x y : AdicCauchySequence I M} (h : ∀ n, x n = y n) : x = y := Subtype.eq <| funext h /-- The defining property of an adic cauchy sequence unwrapped. -/ theorem mk_eq_mk {m n : ℕ} (hmn : m ≤ n) (f : AdicCauchySequence I M) : Submodule.Quotient.mk (p := (I ^ m • ⊤ : Submodule R M)) (f n) = Submodule.Quotient.mk (p := (I ^ m • ⊤ : Submodule R M)) (f m) := (f.property hmn).symm end AdicCauchySequence /-- The `I`-adic cauchy condition can be checked on successive `n`. -/ theorem isAdicCauchy_iff (f : ℕ → M) : IsAdicCauchy I M f ↔ ∀ n, f n ≡ f (n + 1) [SMOD (I ^ n • ⊤ : Submodule R M)] := by constructor · intro h n exact h (Nat.le_succ n)
· intro h m n hmn induction n, hmn using Nat.le_induction with | base => rfl | succ n hmn ih => trans · exact ih · refine SModEq.mono (smul_mono (Ideal.pow_le_pow_right hmn) (by rfl)) (h n) /-- Construct `I`-adic cauchy sequence from sequence satisfying the successive cauchy condition. -/
Mathlib/RingTheory/AdicCompletion/Basic.lean
438
446
/- 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⟩
Mathlib/Order/Zorn.lean
114
125
/- Copyright (c) 2022 Alex Kontorovich and Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alex Kontorovich, Heather Macbeth -/ import Mathlib.Algebra.Group.Opposite import Mathlib.MeasureTheory.Constructions.Polish.Basic import Mathlib.MeasureTheory.Group.FundamentalDomain import Mathlib.MeasureTheory.Integral.DominatedConvergence import Mathlib.MeasureTheory.Measure.Haar.Basic /-! # Haar quotient measure In this file, we consider properties of fundamental domains and measures for the action of a subgroup `Γ` of a topological group `G` on `G` itself. Let `μ` be a measure on `G ⧸ Γ`. ## Main results * `MeasureTheory.QuotientMeasureEqMeasurePreimage.smulInvariantMeasure_quotient`: If `μ` satisfies `QuotientMeasureEqMeasurePreimage` relative to a both left- and right-invariant measure on `G`, then it is a `G` invariant measure on `G ⧸ Γ`. The next two results assume that `Γ` is normal, and that `G` is equipped with a left- and right-invariant measure. * `MeasureTheory.QuotientMeasureEqMeasurePreimage.mulInvariantMeasure_quotient`: If `μ` satisfies `QuotientMeasureEqMeasurePreimage`, then `μ` is a left-invariant measure. * `MeasureTheory.leftInvariantIsQuotientMeasureEqMeasurePreimage`: If `μ` is left-invariant, and the action of `Γ` on `G` has finite covolume, and `μ` satisfies the right scaling condition, then it satisfies `QuotientMeasureEqMeasurePreimage`. This is a converse to `MeasureTheory.QuotientMeasureEqMeasurePreimage.mulInvariantMeasure_quotient`. The last result assumes that `G` is locally compact, that `Γ` is countable and normal, that its action on `G` has a fundamental domain, and that `μ` is a finite measure. We also assume that `G` is equipped with a sigma-finite Haar measure. * `MeasureTheory.QuotientMeasureEqMeasurePreimage.haarMeasure_quotient`: If `μ` satisfies `QuotientMeasureEqMeasurePreimage`, then it is itself Haar. This is a variant of `MeasureTheory.QuotientMeasureEqMeasurePreimage.mulInvariantMeasure_quotient`. Note that a group `G` with Haar measure that is both left and right invariant is called **unimodular**. -/ open Set MeasureTheory TopologicalSpace MeasureTheory.Measure open scoped Pointwise NNReal ENNReal section /-- Measurability of the action of the topological group `G` on the left-coset space `G / Γ`. -/ @[to_additive "Measurability of the action of the additive topological group `G` on the left-coset space `G / Γ`."] instance QuotientGroup.measurableSMul {G : Type*} [Group G] {Γ : Subgroup G} [MeasurableSpace G] [TopologicalSpace G] [IsTopologicalGroup G] [BorelSpace G] [BorelSpace (G ⧸ Γ)] : MeasurableSMul G (G ⧸ Γ) where measurable_const_smul g := (continuous_const_smul g).measurable measurable_smul_const _ := (continuous_id.smul continuous_const).measurable end section smulInvariantMeasure variable {G : Type*} [Group G] [MeasurableSpace G] (ν : Measure G) {Γ : Subgroup G} {μ : Measure (G ⧸ Γ)} [QuotientMeasureEqMeasurePreimage ν μ] /-- Given a subgroup `Γ` of a topological group `G` with measure `ν`, and a measure 'μ' on the quotient `G ⧸ Γ` satisfying `QuotientMeasureEqMeasurePreimage`, the restriction of `ν` to a fundamental domain is measure-preserving with respect to `μ`. -/ @[to_additive] theorem measurePreserving_quotientGroup_mk_of_QuotientMeasureEqMeasurePreimage {𝓕 : Set G} (h𝓕 : IsFundamentalDomain Γ.op 𝓕 ν) (μ : Measure (G ⧸ Γ)) [QuotientMeasureEqMeasurePreimage ν μ] : MeasurePreserving (@QuotientGroup.mk G _ Γ) (ν.restrict 𝓕) μ := h𝓕.measurePreserving_quotient_mk μ local notation "π" => @QuotientGroup.mk G _ Γ variable [TopologicalSpace G] [IsTopologicalGroup G] [BorelSpace G] [PolishSpace G] [T2Space (G ⧸ Γ)] [SecondCountableTopology (G ⧸ Γ)] /-- If `μ` satisfies `QuotientMeasureEqMeasurePreimage` relative to a both left- and right- invariant measure `ν` on `G`, then it is a `G` invariant measure on `G ⧸ Γ`. -/ @[to_additive] lemma MeasureTheory.QuotientMeasureEqMeasurePreimage.smulInvariantMeasure_quotient [IsMulLeftInvariant ν] [hasFun : HasFundamentalDomain Γ.op G ν] : SMulInvariantMeasure G (G ⧸ Γ) μ where measure_preimage_smul g A hA := by have meas_π : Measurable π := continuous_quotient_mk'.measurable obtain ⟨𝓕, h𝓕⟩ := hasFun.ExistsIsFundamentalDomain have h𝓕_translate_fundom : IsFundamentalDomain Γ.op (g • 𝓕) ν := h𝓕.smul_of_comm g -- TODO: why `rw` fails with both of these rewrites? erw [h𝓕.projection_respects_measure_apply (μ := μ) (meas_π (measurableSet_preimage (measurable_const_smul g) hA)), h𝓕_translate_fundom.projection_respects_measure_apply (μ := μ) hA] change ν ((π ⁻¹' _) ∩ _) = ν ((π ⁻¹' _) ∩ _) set π_preA := π ⁻¹' A have : π ⁻¹' ((fun x : G ⧸ Γ => g • x) ⁻¹' A) = (g * ·) ⁻¹' π_preA := by ext1; simp [π_preA] rw [this] have : ν ((g * ·) ⁻¹' π_preA ∩ 𝓕) = ν (π_preA ∩ (g⁻¹ * ·) ⁻¹' 𝓕) := by trans ν ((g * ·) ⁻¹' (π_preA ∩ (g⁻¹ * ·) ⁻¹' 𝓕)) · rw [preimage_inter] congr 2 simp [Set.preimage] rw [measure_preimage_mul] rw [this, ← preimage_smul_inv]; rfl end smulInvariantMeasure section normal variable {G : Type*} [Group G] [MeasurableSpace G] [TopologicalSpace G] [IsTopologicalGroup G] [BorelSpace G] [PolishSpace G] {Γ : Subgroup G} [Subgroup.Normal Γ] [T2Space (G ⧸ Γ)] [SecondCountableTopology (G ⧸ Γ)] {μ : Measure (G ⧸ Γ)} section mulInvariantMeasure variable (ν : Measure G) [IsMulLeftInvariant ν] /-- If `μ` on `G ⧸ Γ` satisfies `QuotientMeasureEqMeasurePreimage` relative to a both left- and right-invariant measure on `G` and `Γ` is a normal subgroup, then `μ` is a left-invariant measure. -/ @[to_additive "If `μ` on `G ⧸ Γ` satisfies `AddQuotientMeasureEqMeasurePreimage` relative to a both left- and right-invariant measure on `G` and `Γ` is a normal subgroup, then `μ` is a left-invariant measure."] lemma MeasureTheory.QuotientMeasureEqMeasurePreimage.mulInvariantMeasure_quotient [hasFun : HasFundamentalDomain Γ.op G ν] [QuotientMeasureEqMeasurePreimage ν μ] : μ.IsMulLeftInvariant where map_mul_left_eq_self x := by ext A hA obtain ⟨x₁, h⟩ := @Quotient.exists_rep _ (QuotientGroup.leftRel Γ) x convert measure_preimage_smul μ x₁ A using 1 · rw [← h, Measure.map_apply (measurable_const_mul _) hA] simp [← MulAction.Quotient.coe_smul_out, ← Quotient.mk''_eq_mk] exact smulInvariantMeasure_quotient ν variable [Countable Γ] [IsMulRightInvariant ν] [SigmaFinite ν] [IsMulLeftInvariant μ] [SigmaFinite μ] local notation "π" => @QuotientGroup.mk G _ Γ /-- Assume that a measure `μ` is `IsMulLeftInvariant`, that the action of `Γ` on `G` has a measurable fundamental domain `s` with positive finite volume, and that there is a single measurable set `V ⊆ G ⧸ Γ` along which the pullback of `μ` and `ν` agree (so the scaling is right). Then `μ` satisfies `QuotientMeasureEqMeasurePreimage`. The main tool of the proof is the uniqueness of left invariant measures, if normalized by a single positive finite-measured set. -/ @[to_additive "Assume that a measure `μ` is `IsAddLeftInvariant`, that the action of `Γ` on `G` has a measurable fundamental domain `s` with positive finite volume, and that there is a single measurable set `V ⊆ G ⧸ Γ` along which the pullback of `μ` and `ν` agree (so the scaling is right). Then `μ` satisfies `AddQuotientMeasureEqMeasurePreimage`. The main tool of the proof is the uniqueness of left invariant measures, if normalized by a single positive finite-measured set."] theorem MeasureTheory.Measure.IsMulLeftInvariant.quotientMeasureEqMeasurePreimage_of_set {s : Set G} (fund_dom_s : IsFundamentalDomain Γ.op s ν) {V : Set (G ⧸ Γ)} (meas_V : MeasurableSet V) (neZeroV : μ V ≠ 0) (hV : μ V = ν (π ⁻¹' V ∩ s)) (neTopV : μ V ≠ ⊤) : QuotientMeasureEqMeasurePreimage ν μ := by apply fund_dom_s.quotientMeasureEqMeasurePreimage ext U _ have meas_π : Measurable (QuotientGroup.mk : G → G ⧸ Γ) := continuous_quotient_mk'.measurable let μ' : Measure (G ⧸ Γ) := (ν.restrict s).map π haveI has_fund : HasFundamentalDomain Γ.op G ν := ⟨⟨s, fund_dom_s⟩⟩ have i : QuotientMeasureEqMeasurePreimage ν μ' := fund_dom_s.quotientMeasureEqMeasurePreimage_quotientMeasure have : μ'.IsMulLeftInvariant := MeasureTheory.QuotientMeasureEqMeasurePreimage.mulInvariantMeasure_quotient ν suffices μ = μ' by rw [this] rfl have : SigmaFinite μ' := i.sigmaFiniteQuotient rw [measure_eq_div_smul μ' μ neZeroV neTopV, hV] symm suffices (μ' V / ν (QuotientGroup.mk ⁻¹' V ∩ s)) = 1 by rw [this, one_smul] rw [Measure.map_apply meas_π meas_V, Measure.restrict_apply] · convert ENNReal.div_self .. · exact trans hV.symm neZeroV · exact trans hV.symm neTopV exact measurableSet_quotient.mp meas_V /-- If a measure `μ` is left-invariant and satisfies the right scaling condition, then it satisfies `QuotientMeasureEqMeasurePreimage`. -/ @[to_additive "If a measure `μ` is left-invariant and satisfies the right scaling condition, then it satisfies `AddQuotientMeasureEqMeasurePreimage`."] theorem MeasureTheory.leftInvariantIsQuotientMeasureEqMeasurePreimage [IsFiniteMeasure μ] [hasFun : HasFundamentalDomain Γ.op G ν] (h : covolume Γ.op G ν = μ univ) : QuotientMeasureEqMeasurePreimage ν μ := by obtain ⟨s, fund_dom_s⟩ := hasFun.ExistsIsFundamentalDomain have finiteCovol : μ univ < ⊤ := measure_lt_top μ univ rw [fund_dom_s.covolume_eq_volume] at h by_cases meas_s_ne_zero : ν s = 0 · convert fund_dom_s.quotientMeasureEqMeasurePreimage_of_zero meas_s_ne_zero rw [← @measure_univ_eq_zero, ← h, meas_s_ne_zero] apply IsMulLeftInvariant.quotientMeasureEqMeasurePreimage_of_set (fund_dom_s := fund_dom_s) (meas_V := MeasurableSet.univ) · rw [← h] exact meas_s_ne_zero · rw [← h] simp · rw [← h] convert finiteCovol.ne end mulInvariantMeasure section haarMeasure variable [Countable Γ] (ν : Measure G) [IsHaarMeasure ν] [IsMulRightInvariant ν] local notation "π" => @QuotientGroup.mk G _ Γ /-- If a measure `μ` on the quotient `G ⧸ Γ` of a group `G` by a discrete normal subgroup `Γ` having fundamental domain, satisfies `QuotientMeasureEqMeasurePreimage` relative to a standardized choice of Haar measure on `G`, and assuming `μ` is finite, then `μ` is itself Haar. TODO: Is it possible to drop the assumption that `μ` is finite? -/ @[to_additive "If a measure `μ` on the quotient `G ⧸ Γ` of an additive group `G` by a discrete normal subgroup `Γ` having fundamental domain, satisfies `AddQuotientMeasureEqMeasurePreimage` relative to a standardized choice of Haar measure on `G`, and assuming `μ` is finite, then `μ` is itself Haar."] theorem MeasureTheory.QuotientMeasureEqMeasurePreimage.haarMeasure_quotient [LocallyCompactSpace G] [QuotientMeasureEqMeasurePreimage ν μ] [i : HasFundamentalDomain Γ.op G ν] [IsFiniteMeasure μ] : IsHaarMeasure μ := by obtain ⟨K⟩ := PositiveCompacts.nonempty' (α := G) let K' : PositiveCompacts (G ⧸ Γ) := K.map π QuotientGroup.continuous_mk QuotientGroup.isOpenMap_coe haveI : IsMulLeftInvariant μ := MeasureTheory.QuotientMeasureEqMeasurePreimage.mulInvariantMeasure_quotient ν rw [haarMeasure_unique μ K'] have finiteCovol : covolume Γ.op G ν ≠ ⊤ := ne_top_of_lt <| QuotientMeasureEqMeasurePreimage.covolume_ne_top μ (ν := ν) obtain ⟨s, fund_dom_s⟩ := i rw [fund_dom_s.covolume_eq_volume] at finiteCovol -- TODO: why `rw` fails? erw [fund_dom_s.projection_respects_measure_apply μ K'.isCompact.measurableSet] apply IsHaarMeasure.smul · intro h haveI i' : IsOpenPosMeasure (ν : Measure G) := inferInstance apply IsOpenPosMeasure.open_pos (interior K) (μ := ν) (self := i') · exact isOpen_interior · exact K.interior_nonempty rw [← le_zero_iff, ← fund_dom_s.measure_zero_of_invariant _ (fun g ↦ QuotientGroup.sound _ _ g) h] apply measure_mono refine interior_subset.trans ?_ rw [QuotientGroup.coe_mk'] show (K : Set G) ⊆ π ⁻¹' (π '' K) exact subset_preimage_image π K · show ν (π ⁻¹' (π '' K) ∩ s) ≠ ⊤ apply ne_of_lt refine lt_of_le_of_lt ?_ finiteCovol.lt_top apply measure_mono exact inter_subset_right variable [SigmaFinite ν] /-- Given a normal subgroup `Γ` of a topological group `G` with Haar measure `μ`, which is also right-invariant, and a finite volume fundamental domain `𝓕`, the quotient map to `G ⧸ Γ`, properly normalized, satisfies `QuotientMeasureEqMeasurePreimage`. -/ @[to_additive "Given a normal subgroup `Γ` of an additive topological group `G` with Haar measure `μ`, which is also right-invariant, and a finite volume fundamental domain `𝓕`, the quotient map to `G ⧸ Γ`, properly normalized, satisfies `AddQuotientMeasureEqMeasurePreimage`."] theorem IsFundamentalDomain.QuotientMeasureEqMeasurePreimage_HaarMeasure {𝓕 : Set G} (h𝓕 : IsFundamentalDomain Γ.op 𝓕 ν) [IsMulLeftInvariant μ] [SigmaFinite μ]
{V : Set (G ⧸ Γ)} (hV : (interior V).Nonempty) (meas_V : MeasurableSet V) (hμK : μ V = ν ((π ⁻¹' V) ∩ 𝓕)) (neTopV : μ V ≠ ⊤) : QuotientMeasureEqMeasurePreimage ν μ := by apply IsMulLeftInvariant.quotientMeasureEqMeasurePreimage_of_set (fund_dom_s := h𝓕) (meas_V := meas_V) · rw [hμK] intro c_eq_zero apply IsOpenPosMeasure.open_pos (interior (π ⁻¹' V)) (μ := ν) · simp · apply Set.Nonempty.mono (preimage_interior_subset_interior_preimage continuous_coinduced_rng) apply hV.preimage' simp · apply measure_mono_null (h := interior_subset) apply h𝓕.measure_zero_of_invariant (ht := fun g ↦ QuotientGroup.sound _ _ g) exact c_eq_zero · exact hμK · exact neTopV variable (K : PositiveCompacts (G ⧸ Γ))
Mathlib/MeasureTheory/Measure/Haar/Quotient.lean
266
284
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Floris van Doorn -/ import Mathlib.Data.Countable.Small import Mathlib.Data.Fintype.BigOperators import Mathlib.Data.Fintype.Powerset import Mathlib.Data.Nat.Cast.Order.Basic import Mathlib.Data.Set.Countable import Mathlib.Logic.Equiv.Fin.Basic import Mathlib.Logic.Small.Set import Mathlib.Logic.UnivLE import Mathlib.SetTheory.Cardinal.Order /-! # Basic results on cardinal numbers We provide a collection of basic results on cardinal numbers, in particular focussing on finite/countable/small types and sets. ## Main definitions * `Cardinal.powerlt a b` or `a ^< b` is defined as the supremum of `a ^ c` for `c < b`. ## References * <https://en.wikipedia.org/wiki/Cardinal_number> ## Tags cardinal number, cardinal arithmetic, cardinal exponentiation, aleph, Cantor's theorem, König's theorem, Konig's theorem -/ assert_not_exists Field open List (Vector) open Function Order Set noncomputable section universe u v w v' w' variable {α β : Type u} namespace Cardinal /-! ### Lifting cardinals to a higher universe -/ @[simp] lemma mk_preimage_down {s : Set α} : #(ULift.down.{v} ⁻¹' s) = lift.{v} (#s) := by rw [← mk_uLift, Cardinal.eq] constructor let f : ULift.down ⁻¹' s → ULift s := fun x ↦ ULift.up (restrictPreimage s ULift.down x) have : Function.Bijective f := ULift.up_bijective.comp (restrictPreimage_bijective _ (ULift.down_bijective)) exact Equiv.ofBijective f this -- `simp` can't figure out universe levels: normal form is `lift_mk_shrink'`. theorem lift_mk_shrink (α : Type u) [Small.{v} α] : Cardinal.lift.{max u w} #(Shrink.{v} α) = Cardinal.lift.{max v w} #α := lift_mk_eq.2 ⟨(equivShrink α).symm⟩ @[simp] theorem lift_mk_shrink' (α : Type u) [Small.{v} α] : Cardinal.lift.{u} #(Shrink.{v} α) = Cardinal.lift.{v} #α := lift_mk_shrink.{u, v, 0} α @[simp] theorem lift_mk_shrink'' (α : Type max u v) [Small.{v} α] : Cardinal.lift.{u} #(Shrink.{v} α) = #α := by rw [← lift_umax, lift_mk_shrink.{max u v, v, 0} α, ← lift_umax, lift_id] theorem prod_eq_of_fintype {α : Type u} [h : Fintype α] (f : α → Cardinal.{v}) : prod f = Cardinal.lift.{u} (∏ i, f i) := by revert f refine Fintype.induction_empty_option ?_ ?_ ?_ α (h_fintype := h) · intro α β hβ e h f letI := Fintype.ofEquiv β e.symm rw [← e.prod_comp f, ← h] exact mk_congr (e.piCongrLeft _).symm · intro f rw [Fintype.univ_pempty, Finset.prod_empty, lift_one, Cardinal.prod, mk_eq_one] · intro α hα h f rw [Cardinal.prod, mk_congr Equiv.piOptionEquivProd, mk_prod, lift_umax.{v, u}, mk_out, ← Cardinal.prod, lift_prod, Fintype.prod_option, lift_mul, ← h fun a => f (some a)] simp only [lift_id] /-! ### Basic cardinals -/ theorem le_one_iff_subsingleton {α : Type u} : #α ≤ 1 ↔ Subsingleton α := ⟨fun ⟨f⟩ => ⟨fun _ _ => f.injective (Subsingleton.elim _ _)⟩, fun ⟨h⟩ => ⟨fun _ => ULift.up 0, fun _ _ _ => h _ _⟩⟩ @[simp] theorem mk_le_one_iff_set_subsingleton {s : Set α} : #s ≤ 1 ↔ s.Subsingleton := le_one_iff_subsingleton.trans s.subsingleton_coe alias ⟨_, _root_.Set.Subsingleton.cardinalMk_le_one⟩ := mk_le_one_iff_set_subsingleton @[deprecated (since := "2024-11-10")] alias _root_.Set.Subsingleton.cardinal_mk_le_one := Set.Subsingleton.cardinalMk_le_one private theorem cast_succ (n : ℕ) : ((n + 1 : ℕ) : Cardinal.{u}) = n + 1 := by change #(ULift.{u} _) = #(ULift.{u} _) + 1 rw [← mk_option] simp /-! ### Order properties -/ theorem one_lt_iff_nontrivial {α : Type u} : 1 < #α ↔ Nontrivial α := by rw [← not_le, le_one_iff_subsingleton, ← not_nontrivial_iff_subsingleton, Classical.not_not] lemma sInf_eq_zero_iff {s : Set Cardinal} : sInf s = 0 ↔ s = ∅ ∨ ∃ a ∈ s, a = 0 := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rcases s.eq_empty_or_nonempty with rfl | hne · exact Or.inl rfl · exact Or.inr ⟨sInf s, csInf_mem hne, h⟩ · rcases h with rfl | ⟨a, ha, rfl⟩ · exact Cardinal.sInf_empty · exact eq_bot_iff.2 (csInf_le' ha) lemma iInf_eq_zero_iff {ι : Sort*} {f : ι → Cardinal} : (⨅ i, f i) = 0 ↔ IsEmpty ι ∨ ∃ i, f i = 0 := by simp [iInf, sInf_eq_zero_iff] /-- A variant of `ciSup_of_empty` but with `0` on the RHS for convenience -/ protected theorem iSup_of_empty {ι} (f : ι → Cardinal) [IsEmpty ι] : iSup f = 0 := ciSup_of_empty f @[simp] theorem lift_sInf (s : Set Cardinal) : lift.{u, v} (sInf s) = sInf (lift.{u, v} '' s) := by rcases eq_empty_or_nonempty s with (rfl | hs) · simp · exact lift_monotone.map_csInf hs @[simp] theorem lift_iInf {ι} (f : ι → Cardinal) : lift.{u, v} (iInf f) = ⨅ i, lift.{u, v} (f i) := by unfold iInf convert lift_sInf (range f) simp_rw [← comp_apply (f := lift), range_comp] end Cardinal /-! ### Small sets of cardinals -/ namespace Cardinal instance small_Iic (a : Cardinal.{u}) : Small.{u} (Iic a) := by rw [← mk_out a] apply @small_of_surjective (Set a.out) (Iic #a.out) _ fun x => ⟨#x, mk_set_le x⟩ rintro ⟨x, hx⟩ simpa using le_mk_iff_exists_set.1 hx instance small_Iio (a : Cardinal.{u}) : Small.{u} (Iio a) := small_subset Iio_subset_Iic_self instance small_Icc (a b : Cardinal.{u}) : Small.{u} (Icc a b) := small_subset Icc_subset_Iic_self instance small_Ico (a b : Cardinal.{u}) : Small.{u} (Ico a b) := small_subset Ico_subset_Iio_self instance small_Ioc (a b : Cardinal.{u}) : Small.{u} (Ioc a b) := small_subset Ioc_subset_Iic_self instance small_Ioo (a b : Cardinal.{u}) : Small.{u} (Ioo a b) := small_subset Ioo_subset_Iio_self /-- A set of cardinals is bounded above iff it's small, i.e. it corresponds to a usual ZFC set. -/ theorem bddAbove_iff_small {s : Set Cardinal.{u}} : BddAbove s ↔ Small.{u} s := ⟨fun ⟨a, ha⟩ => @small_subset _ (Iic a) s (fun _ h => ha h) _, by rintro ⟨ι, ⟨e⟩⟩ use sum.{u, u} fun x ↦ e.symm x intro a ha simpa using le_sum (fun x ↦ e.symm x) (e ⟨a, ha⟩)⟩ theorem bddAbove_of_small (s : Set Cardinal.{u}) [h : Small.{u} s] : BddAbove s := bddAbove_iff_small.2 h theorem bddAbove_range {ι : Type*} [Small.{u} ι] (f : ι → Cardinal.{u}) : BddAbove (Set.range f) := bddAbove_of_small _ theorem bddAbove_image (f : Cardinal.{u} → Cardinal.{max u v}) {s : Set Cardinal.{u}} (hs : BddAbove s) : BddAbove (f '' s) := by rw [bddAbove_iff_small] at hs ⊢ exact small_lift _ theorem bddAbove_range_comp {ι : Type u} {f : ι → Cardinal.{v}} (hf : BddAbove (range f)) (g : Cardinal.{v} → Cardinal.{max v w}) : BddAbove (range (g ∘ f)) := by rw [range_comp] exact bddAbove_image g hf /-- The type of cardinals in universe `u` is not `Small.{u}`. This is a version of the Burali-Forti paradox. -/ theorem _root_.not_small_cardinal : ¬ Small.{u} Cardinal.{max u v} := by intro h have := small_lift.{_, v} Cardinal.{max u v} rw [← small_univ_iff, ← bddAbove_iff_small] at this exact not_bddAbove_univ this instance uncountable : Uncountable Cardinal.{u} := Uncountable.of_not_small not_small_cardinal.{u} /-! ### Bounds on suprema -/ theorem sum_le_iSup_lift {ι : Type u} (f : ι → Cardinal.{max u v}) : sum f ≤ Cardinal.lift #ι * iSup f := by rw [← (iSup f).lift_id, ← lift_umax, lift_umax.{max u v, u}, ← sum_const] exact sum_le_sum _ _ (le_ciSup <| bddAbove_of_small _) theorem sum_le_iSup {ι : Type u} (f : ι → Cardinal.{u}) : sum f ≤ #ι * iSup f := by rw [← lift_id #ι] exact sum_le_iSup_lift f /-- The lift of a supremum is the supremum of the lifts. -/ theorem lift_sSup {s : Set Cardinal} (hs : BddAbove s) : lift.{u} (sSup s) = sSup (lift.{u} '' s) := by apply ((le_csSup_iff' (bddAbove_image.{_,u} _ hs)).2 fun c hc => _).antisymm (csSup_le' _) · intro c hc by_contra h obtain ⟨d, rfl⟩ := Cardinal.mem_range_lift_of_le (not_le.1 h).le simp_rw [lift_le] at h hc rw [csSup_le_iff' hs] at h exact h fun a ha => lift_le.1 <| hc (mem_image_of_mem _ ha) · rintro i ⟨j, hj, rfl⟩ exact lift_le.2 (le_csSup hs hj) /-- The lift of a supremum is the supremum of the lifts. -/ theorem lift_iSup {ι : Type v} {f : ι → Cardinal.{w}} (hf : BddAbove (range f)) : lift.{u} (iSup f) = ⨆ i, lift.{u} (f i) := by rw [iSup, iSup, lift_sSup hf, ← range_comp] simp [Function.comp_def] /-- To prove that the lift of a supremum is bounded by some cardinal `t`, it suffices to show that the lift of each cardinal is bounded by `t`. -/ theorem lift_iSup_le {ι : Type v} {f : ι → Cardinal.{w}} {t : Cardinal} (hf : BddAbove (range f)) (w : ∀ i, lift.{u} (f i) ≤ t) : lift.{u} (iSup f) ≤ t := by rw [lift_iSup hf] exact ciSup_le' w @[simp] theorem lift_iSup_le_iff {ι : Type v} {f : ι → Cardinal.{w}} (hf : BddAbove (range f)) {t : Cardinal} : lift.{u} (iSup f) ≤ t ↔ ∀ i, lift.{u} (f i) ≤ t := by rw [lift_iSup hf] exact ciSup_le_iff' (bddAbove_range_comp.{_,_,u} hf _) /-- To prove an inequality between the lifts to a common universe of two different supremums, it suffices to show that the lift of each cardinal from the smaller supremum if bounded by the lift of some cardinal from the larger supremum. -/ theorem lift_iSup_le_lift_iSup {ι : Type v} {ι' : Type v'} {f : ι → Cardinal.{w}} {f' : ι' → Cardinal.{w'}} (hf : BddAbove (range f)) (hf' : BddAbove (range f')) {g : ι → ι'} (h : ∀ i, lift.{w'} (f i) ≤ lift.{w} (f' (g i))) : lift.{w'} (iSup f) ≤ lift.{w} (iSup f') := by rw [lift_iSup hf, lift_iSup hf'] exact ciSup_mono' (bddAbove_range_comp.{_,_,w} hf' _) fun i => ⟨_, h i⟩ /-- A variant of `lift_iSup_le_lift_iSup` with universes specialized via `w = v` and `w' = v'`. This is sometimes necessary to avoid universe unification issues. -/ theorem lift_iSup_le_lift_iSup' {ι : Type v} {ι' : Type v'} {f : ι → Cardinal.{v}} {f' : ι' → Cardinal.{v'}} (hf : BddAbove (range f)) (hf' : BddAbove (range f')) (g : ι → ι') (h : ∀ i, lift.{v'} (f i) ≤ lift.{v} (f' (g i))) : lift.{v'} (iSup f) ≤ lift.{v} (iSup f') := lift_iSup_le_lift_iSup hf hf' h /-! ### Properties about the cast from `ℕ` -/ theorem mk_finset_of_fintype [Fintype α] : #(Finset α) = 2 ^ Fintype.card α := by simp [Pow.pow] @[norm_cast] theorem nat_succ (n : ℕ) : (n.succ : Cardinal) = succ ↑n := by rw [Nat.cast_succ] refine (add_one_le_succ _).antisymm (succ_le_of_lt ?_) rw [← Nat.cast_succ] exact Nat.cast_lt.2 (Nat.lt_succ_self _) lemma succ_natCast (n : ℕ) : Order.succ (n : Cardinal) = n + 1 := by rw [← Cardinal.nat_succ] norm_cast lemma natCast_add_one_le_iff {n : ℕ} {c : Cardinal} : n + 1 ≤ c ↔ n < c := by rw [← Order.succ_le_iff, Cardinal.succ_natCast] lemma two_le_iff_one_lt {c : Cardinal} : 2 ≤ c ↔ 1 < c := by convert natCast_add_one_le_iff norm_cast @[simp] theorem succ_zero : succ (0 : Cardinal) = 1 := by norm_cast -- This works generally to prove inequalities between numeric cardinals. theorem one_lt_two : (1 : Cardinal) < 2 := by norm_cast theorem exists_finset_le_card (α : Type*) (n : ℕ) (h : n ≤ #α) : ∃ s : Finset α, n ≤ s.card := by obtain hα|hα := finite_or_infinite α · let hα := Fintype.ofFinite α use Finset.univ simpa only [mk_fintype, Nat.cast_le] using h · obtain ⟨s, hs⟩ := Infinite.exists_subset_card_eq α n exact ⟨s, hs.ge⟩ theorem card_le_of {α : Type u} {n : ℕ} (H : ∀ s : Finset α, s.card ≤ n) : #α ≤ n := by contrapose! H apply exists_finset_le_card α (n+1) simpa only [nat_succ, succ_le_iff] using H theorem cantor' (a) {b : Cardinal} (hb : 1 < b) : a < b ^ a := by rw [← succ_le_iff, (by norm_cast : succ (1 : Cardinal) = 2)] at hb exact (cantor a).trans_le (power_le_power_right hb) theorem one_le_iff_pos {c : Cardinal} : 1 ≤ c ↔ 0 < c := by rw [← succ_zero, succ_le_iff] theorem one_le_iff_ne_zero {c : Cardinal} : 1 ≤ c ↔ c ≠ 0 := by rw [one_le_iff_pos, pos_iff_ne_zero] @[simp] theorem lt_one_iff_zero {c : Cardinal} : c < 1 ↔ c = 0 := by simpa using lt_succ_bot_iff (a := c) /-! ### Properties about `aleph0` -/ theorem nat_lt_aleph0 (n : ℕ) : (n : Cardinal.{u}) < ℵ₀ := succ_le_iff.1 (by rw [← nat_succ, ← lift_mk_fin, aleph0, lift_mk_le.{u}] exact ⟨⟨(↑), fun a b => Fin.ext⟩⟩) @[simp] theorem one_lt_aleph0 : 1 < ℵ₀ := by simpa using nat_lt_aleph0 1 @[simp] theorem one_le_aleph0 : 1 ≤ ℵ₀ := one_lt_aleph0.le theorem lt_aleph0 {c : Cardinal} : c < ℵ₀ ↔ ∃ n : ℕ, c = n := ⟨fun h => by rcases lt_lift_iff.1 h with ⟨c, h', rfl⟩ rcases le_mk_iff_exists_set.1 h'.1 with ⟨S, rfl⟩ suffices S.Finite by lift S to Finset ℕ using this simp contrapose! h' haveI := Infinite.to_subtype h' exact ⟨Infinite.natEmbedding S⟩, fun ⟨_, e⟩ => e.symm ▸ nat_lt_aleph0 _⟩ lemma succ_eq_of_lt_aleph0 {c : Cardinal} (h : c < ℵ₀) : Order.succ c = c + 1 := by obtain ⟨n, hn⟩ := Cardinal.lt_aleph0.mp h rw [hn, succ_natCast] theorem aleph0_le {c : Cardinal} : ℵ₀ ≤ c ↔ ∀ n : ℕ, ↑n ≤ c := ⟨fun h _ => (nat_lt_aleph0 _).le.trans h, fun h => le_of_not_lt fun hn => by rcases lt_aleph0.1 hn with ⟨n, rfl⟩ exact (Nat.lt_succ_self _).not_le (Nat.cast_le.1 (h (n + 1)))⟩ theorem isSuccPrelimit_aleph0 : IsSuccPrelimit ℵ₀ := isSuccPrelimit_of_succ_lt fun a ha => by rcases lt_aleph0.1 ha with ⟨n, rfl⟩ rw [← nat_succ] apply nat_lt_aleph0 theorem isSuccLimit_aleph0 : IsSuccLimit ℵ₀ := by rw [Cardinal.isSuccLimit_iff] exact ⟨aleph0_ne_zero, isSuccPrelimit_aleph0⟩ lemma not_isSuccLimit_natCast : (n : ℕ) → ¬ IsSuccLimit (n : Cardinal.{u}) | 0, e => e.1 isMin_bot | Nat.succ n, e => Order.not_isSuccPrelimit_succ _ (nat_succ n ▸ e.2) theorem not_isSuccLimit_of_lt_aleph0 {c : Cardinal} (h : c < ℵ₀) : ¬ IsSuccLimit c := by obtain ⟨n, rfl⟩ := lt_aleph0.1 h exact not_isSuccLimit_natCast n theorem aleph0_le_of_isSuccLimit {c : Cardinal} (h : IsSuccLimit c) : ℵ₀ ≤ c := by contrapose! h exact not_isSuccLimit_of_lt_aleph0 h theorem isStrongLimit_aleph0 : IsStrongLimit ℵ₀ := by refine ⟨aleph0_ne_zero, fun x hx ↦ ?_⟩ obtain ⟨n, rfl⟩ := lt_aleph0.1 hx exact_mod_cast nat_lt_aleph0 _ theorem IsStrongLimit.aleph0_le {c} (H : IsStrongLimit c) : ℵ₀ ≤ c := aleph0_le_of_isSuccLimit H.isSuccLimit lemma exists_eq_natCast_of_iSup_eq {ι : Type u} [Nonempty ι] (f : ι → Cardinal.{v}) (hf : BddAbove (range f)) (n : ℕ) (h : ⨆ i, f i = n) : ∃ i, f i = n := exists_eq_of_iSup_eq_of_not_isSuccLimit.{u, v} f hf (not_isSuccLimit_natCast n) h @[simp] theorem range_natCast : range ((↑) : ℕ → Cardinal) = Iio ℵ₀ := ext fun x => by simp only [mem_Iio, mem_range, eq_comm, lt_aleph0] theorem mk_eq_nat_iff {α : Type u} {n : ℕ} : #α = n ↔ Nonempty (α ≃ Fin n) := by rw [← lift_mk_fin, ← lift_uzero #α, lift_mk_eq'] theorem lt_aleph0_iff_finite {α : Type u} : #α < ℵ₀ ↔ Finite α := by simp only [lt_aleph0, mk_eq_nat_iff, finite_iff_exists_equiv_fin] theorem lt_aleph0_iff_fintype {α : Type u} : #α < ℵ₀ ↔ Nonempty (Fintype α) := lt_aleph0_iff_finite.trans (finite_iff_nonempty_fintype _) theorem lt_aleph0_of_finite (α : Type u) [Finite α] : #α < ℵ₀ := lt_aleph0_iff_finite.2 ‹_› theorem lt_aleph0_iff_set_finite {S : Set α} : #S < ℵ₀ ↔ S.Finite := lt_aleph0_iff_finite.trans finite_coe_iff alias ⟨_, _root_.Set.Finite.lt_aleph0⟩ := lt_aleph0_iff_set_finite @[simp] theorem lt_aleph0_iff_subtype_finite {p : α → Prop} : #{ x // p x } < ℵ₀ ↔ { x | p x }.Finite := lt_aleph0_iff_set_finite theorem mk_le_aleph0_iff : #α ≤ ℵ₀ ↔ Countable α := by rw [countable_iff_nonempty_embedding, aleph0, ← lift_uzero #α, lift_mk_le'] @[simp] theorem mk_le_aleph0 [Countable α] : #α ≤ ℵ₀ := mk_le_aleph0_iff.mpr ‹_› theorem le_aleph0_iff_set_countable {s : Set α} : #s ≤ ℵ₀ ↔ s.Countable := mk_le_aleph0_iff alias ⟨_, _root_.Set.Countable.le_aleph0⟩ := le_aleph0_iff_set_countable @[simp] theorem le_aleph0_iff_subtype_countable {p : α → Prop} : #{ x // p x } ≤ ℵ₀ ↔ { x | p x }.Countable := le_aleph0_iff_set_countable theorem aleph0_lt_mk_iff : ℵ₀ < #α ↔ Uncountable α := by rw [← not_le, ← not_countable_iff, not_iff_not, mk_le_aleph0_iff] @[simp] theorem aleph0_lt_mk [Uncountable α] : ℵ₀ < #α := aleph0_lt_mk_iff.mpr ‹_› instance canLiftCardinalNat : CanLift Cardinal ℕ (↑) fun x => x < ℵ₀ := ⟨fun _ hx => let ⟨n, hn⟩ := lt_aleph0.mp hx ⟨n, hn.symm⟩⟩ theorem add_lt_aleph0 {a b : Cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a + b < ℵ₀ := match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with | _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [← Nat.cast_add]; apply nat_lt_aleph0 theorem add_lt_aleph0_iff {a b : Cardinal} : a + b < ℵ₀ ↔ a < ℵ₀ ∧ b < ℵ₀ := ⟨fun h => ⟨(self_le_add_right _ _).trans_lt h, (self_le_add_left _ _).trans_lt h⟩, fun ⟨h1, h2⟩ => add_lt_aleph0 h1 h2⟩ theorem aleph0_le_add_iff {a b : Cardinal} : ℵ₀ ≤ a + b ↔ ℵ₀ ≤ a ∨ ℵ₀ ≤ b := by simp only [← not_lt, add_lt_aleph0_iff, not_and_or] /-- See also `Cardinal.nsmul_lt_aleph0_iff_of_ne_zero` if you already have `n ≠ 0`. -/ theorem nsmul_lt_aleph0_iff {n : ℕ} {a : Cardinal} : n • a < ℵ₀ ↔ n = 0 ∨ a < ℵ₀ := by cases n with | zero => simpa using nat_lt_aleph0 0 | succ n => simp only [Nat.succ_ne_zero, false_or] induction' n with n ih · simp rw [succ_nsmul, add_lt_aleph0_iff, ih, and_self_iff] /-- See also `Cardinal.nsmul_lt_aleph0_iff` for a hypothesis-free version. -/ theorem nsmul_lt_aleph0_iff_of_ne_zero {n : ℕ} {a : Cardinal} (h : n ≠ 0) : n • a < ℵ₀ ↔ a < ℵ₀ := nsmul_lt_aleph0_iff.trans <| or_iff_right h theorem mul_lt_aleph0 {a b : Cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a * b < ℵ₀ := match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with | _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [← Nat.cast_mul]; apply nat_lt_aleph0 theorem mul_lt_aleph0_iff {a b : Cardinal} : a * b < ℵ₀ ↔ a = 0 ∨ b = 0 ∨ a < ℵ₀ ∧ b < ℵ₀ := by refine ⟨fun h => ?_, ?_⟩ · by_cases ha : a = 0 · exact Or.inl ha right by_cases hb : b = 0 · exact Or.inl hb right rw [← Ne, ← one_le_iff_ne_zero] at ha hb constructor · rw [← mul_one a] exact (mul_le_mul' le_rfl hb).trans_lt h · rw [← one_mul b] exact (mul_le_mul' ha le_rfl).trans_lt h rintro (rfl | rfl | ⟨ha, hb⟩) <;> simp only [*, mul_lt_aleph0, aleph0_pos, zero_mul, mul_zero] /-- See also `Cardinal.aleph0_le_mul_iff`. -/ theorem aleph0_le_mul_iff {a b : Cardinal} : ℵ₀ ≤ a * b ↔ a ≠ 0 ∧ b ≠ 0 ∧ (ℵ₀ ≤ a ∨ ℵ₀ ≤ b) := by let h := (@mul_lt_aleph0_iff a b).not rwa [not_lt, not_or, not_or, not_and_or, not_lt, not_lt] at h /-- See also `Cardinal.aleph0_le_mul_iff'`. -/ theorem aleph0_le_mul_iff' {a b : Cardinal.{u}} : ℵ₀ ≤ a * b ↔ a ≠ 0 ∧ ℵ₀ ≤ b ∨ ℵ₀ ≤ a ∧ b ≠ 0 := by have : ∀ {a : Cardinal.{u}}, ℵ₀ ≤ a → a ≠ 0 := fun a => ne_bot_of_le_ne_bot aleph0_ne_zero a simp only [aleph0_le_mul_iff, and_or_left, and_iff_right_of_imp this, @and_left_comm (a ≠ 0)] simp only [and_comm, or_comm] theorem mul_lt_aleph0_iff_of_ne_zero {a b : Cardinal} (ha : a ≠ 0) (hb : b ≠ 0) : a * b < ℵ₀ ↔ a < ℵ₀ ∧ b < ℵ₀ := by simp [mul_lt_aleph0_iff, ha, hb] theorem power_lt_aleph0 {a b : Cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a ^ b < ℵ₀ := match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with | _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [power_natCast, ← Nat.cast_pow]; apply nat_lt_aleph0 theorem eq_one_iff_unique {α : Type*} : #α = 1 ↔ Subsingleton α ∧ Nonempty α := calc #α = 1 ↔ #α ≤ 1 ∧ 1 ≤ #α := le_antisymm_iff _ ↔ Subsingleton α ∧ Nonempty α := le_one_iff_subsingleton.and (one_le_iff_ne_zero.trans mk_ne_zero_iff) theorem infinite_iff {α : Type u} : Infinite α ↔ ℵ₀ ≤ #α := by rw [← not_lt, lt_aleph0_iff_finite, not_finite_iff_infinite] lemma aleph0_le_mk_iff : ℵ₀ ≤ #α ↔ Infinite α := infinite_iff.symm lemma mk_lt_aleph0_iff : #α < ℵ₀ ↔ Finite α := by simp [← not_le, aleph0_le_mk_iff] @[simp] lemma mk_lt_aleph0 [Finite α] : #α < ℵ₀ := mk_lt_aleph0_iff.2 ‹_› @[simp] theorem aleph0_le_mk (α : Type u) [Infinite α] : ℵ₀ ≤ #α := infinite_iff.1 ‹_› @[simp] theorem mk_eq_aleph0 (α : Type*) [Countable α] [Infinite α] : #α = ℵ₀ := mk_le_aleph0.antisymm <| aleph0_le_mk _ theorem denumerable_iff {α : Type u} : Nonempty (Denumerable α) ↔ #α = ℵ₀ := ⟨fun ⟨h⟩ => mk_congr ((@Denumerable.eqv α h).trans Equiv.ulift.symm), fun h => by obtain ⟨f⟩ := Quotient.exact h exact ⟨Denumerable.mk' <| f.trans Equiv.ulift⟩⟩ theorem mk_denumerable (α : Type u) [Denumerable α] : #α = ℵ₀ := denumerable_iff.1 ⟨‹_›⟩ theorem _root_.Set.countable_infinite_iff_nonempty_denumerable {α : Type*} {s : Set α} : s.Countable ∧ s.Infinite ↔ Nonempty (Denumerable s) := by rw [nonempty_denumerable_iff, ← Set.infinite_coe_iff, countable_coe_iff] @[simp] theorem aleph0_add_aleph0 : ℵ₀ + ℵ₀ = ℵ₀ := mk_denumerable _ theorem aleph0_mul_aleph0 : ℵ₀ * ℵ₀ = ℵ₀ := mk_denumerable _ @[simp] theorem nat_mul_aleph0 {n : ℕ} (hn : n ≠ 0) : ↑n * ℵ₀ = ℵ₀ := le_antisymm (lift_mk_fin n ▸ mk_le_aleph0) <| le_mul_of_one_le_left (zero_le _) <| by rwa [← Nat.cast_one, Nat.cast_le, Nat.one_le_iff_ne_zero] @[simp] theorem aleph0_mul_nat {n : ℕ} (hn : n ≠ 0) : ℵ₀ * n = ℵ₀ := by rw [mul_comm, nat_mul_aleph0 hn] @[simp] theorem ofNat_mul_aleph0 {n : ℕ} [Nat.AtLeastTwo n] : ofNat(n) * ℵ₀ = ℵ₀ := nat_mul_aleph0 (NeZero.ne n) @[simp] theorem aleph0_mul_ofNat {n : ℕ} [Nat.AtLeastTwo n] : ℵ₀ * ofNat(n) = ℵ₀ := aleph0_mul_nat (NeZero.ne n) @[simp] theorem add_le_aleph0 {c₁ c₂ : Cardinal} : c₁ + c₂ ≤ ℵ₀ ↔ c₁ ≤ ℵ₀ ∧ c₂ ≤ ℵ₀ := ⟨fun h => ⟨le_self_add.trans h, le_add_self.trans h⟩, fun h => aleph0_add_aleph0 ▸ add_le_add h.1 h.2⟩ @[simp] theorem aleph0_add_nat (n : ℕ) : ℵ₀ + n = ℵ₀ := (add_le_aleph0.2 ⟨le_rfl, (nat_lt_aleph0 n).le⟩).antisymm le_self_add @[simp] theorem nat_add_aleph0 (n : ℕ) : ↑n + ℵ₀ = ℵ₀ := by rw [add_comm, aleph0_add_nat] @[simp] theorem ofNat_add_aleph0 {n : ℕ} [Nat.AtLeastTwo n] : ofNat(n) + ℵ₀ = ℵ₀ := nat_add_aleph0 n @[simp] theorem aleph0_add_ofNat {n : ℕ} [Nat.AtLeastTwo n] : ℵ₀ + ofNat(n) = ℵ₀ := aleph0_add_nat n theorem exists_nat_eq_of_le_nat {c : Cardinal} {n : ℕ} (h : c ≤ n) : ∃ m, m ≤ n ∧ c = m := by lift c to ℕ using h.trans_lt (nat_lt_aleph0 _) exact ⟨c, mod_cast h, rfl⟩ theorem mk_int : #ℤ = ℵ₀ := mk_denumerable ℤ theorem mk_pnat : #ℕ+ = ℵ₀ := mk_denumerable ℕ+ @[deprecated (since := "2025-04-27")] alias mk_pNat := mk_pnat /-! ### Cardinalities of basic sets and types -/ @[simp] theorem mk_additive : #(Additive α) = #α := rfl @[simp] theorem mk_multiplicative : #(Multiplicative α) = #α := rfl @[to_additive (attr := simp)] theorem mk_mulOpposite : #(MulOpposite α) = #α := mk_congr MulOpposite.opEquiv.symm theorem mk_singleton {α : Type u} (x : α) : #({x} : Set α) = 1 := mk_eq_one _ @[simp] theorem mk_vector (α : Type u) (n : ℕ) : #(List.Vector α n) = #α ^ n := (mk_congr (Equiv.vectorEquivFin α n)).trans <| by simp theorem mk_list_eq_sum_pow (α : Type u) : #(List α) = sum fun n : ℕ => #α ^ n := calc #(List α) = #(Σn, List.Vector α n) := mk_congr (Equiv.sigmaFiberEquiv List.length).symm _ = sum fun n : ℕ => #α ^ n := by simp theorem mk_quot_le {α : Type u} {r : α → α → Prop} : #(Quot r) ≤ #α := mk_le_of_surjective Quot.exists_rep theorem mk_quotient_le {α : Type u} {s : Setoid α} : #(Quotient s) ≤ #α := mk_quot_le theorem mk_subtype_le_of_subset {α : Type u} {p q : α → Prop} (h : ∀ ⦃x⦄, p x → q x) : #(Subtype p) ≤ #(Subtype q) := ⟨Embedding.subtypeMap (Embedding.refl α) h⟩ theorem mk_emptyCollection (α : Type u) : #(∅ : Set α) = 0 := mk_eq_zero _ theorem mk_emptyCollection_iff {α : Type u} {s : Set α} : #s = 0 ↔ s = ∅ := by constructor · intro h rw [mk_eq_zero_iff] at h exact eq_empty_iff_forall_not_mem.2 fun x hx => h.elim' ⟨x, hx⟩ · rintro rfl exact mk_emptyCollection _ @[simp] theorem mk_univ {α : Type u} : #(@univ α) = #α := mk_congr (Equiv.Set.univ α) @[simp] lemma mk_setProd {α β : Type u} (s : Set α) (t : Set β) : #(s ×ˢ t) = #s * #t := by rw [mul_def, mk_congr (Equiv.Set.prod ..)] theorem mk_image_le {α β : Type u} {f : α → β} {s : Set α} : #(f '' s) ≤ #s := mk_le_of_surjective surjective_onto_image lemma mk_image2_le {α β γ : Type u} {f : α → β → γ} {s : Set α} {t : Set β} : #(image2 f s t) ≤ #s * #t := by rw [← image_uncurry_prod, ← mk_setProd] exact mk_image_le theorem mk_image_le_lift {α : Type u} {β : Type v} {f : α → β} {s : Set α} : lift.{u} #(f '' s) ≤ lift.{v} #s := lift_mk_le.{0}.mpr ⟨Embedding.ofSurjective _ surjective_onto_image⟩ theorem mk_range_le {α β : Type u} {f : α → β} : #(range f) ≤ #α := mk_le_of_surjective surjective_onto_range theorem mk_range_le_lift {α : Type u} {β : Type v} {f : α → β} : lift.{u} #(range f) ≤ lift.{v} #α := lift_mk_le.{0}.mpr ⟨Embedding.ofSurjective _ surjective_onto_range⟩ theorem mk_range_eq (f : α → β) (h : Injective f) : #(range f) = #α := mk_congr (Equiv.ofInjective f h).symm theorem mk_range_eq_lift {α : Type u} {β : Type v} {f : α → β} (hf : Injective f) : lift.{max u w} #(range f) = lift.{max v w} #α := lift_mk_eq.{v,u,w}.mpr ⟨(Equiv.ofInjective f hf).symm⟩ theorem mk_range_eq_of_injective {α : Type u} {β : Type v} {f : α → β} (hf : Injective f) : lift.{u} #(range f) = lift.{v} #α := lift_mk_eq'.mpr ⟨(Equiv.ofInjective f hf).symm⟩ lemma lift_mk_le_lift_mk_of_injective {α : Type u} {β : Type v} {f : α → β} (hf : Injective f) : Cardinal.lift.{v} (#α) ≤ Cardinal.lift.{u} (#β) := by rw [← Cardinal.mk_range_eq_of_injective hf] exact Cardinal.lift_le.2 (Cardinal.mk_set_le _) lemma lift_mk_le_lift_mk_of_surjective {α : Type u} {β : Type v} {f : α → β} (hf : Surjective f) : Cardinal.lift.{u} (#β) ≤ Cardinal.lift.{v} (#α) := lift_mk_le_lift_mk_of_injective (injective_surjInv hf) theorem mk_image_eq_of_injOn {α β : Type u} (f : α → β) (s : Set α) (h : InjOn f s) : #(f '' s) = #s := mk_congr (Equiv.Set.imageOfInjOn f s h).symm theorem mk_image_eq_of_injOn_lift {α : Type u} {β : Type v} (f : α → β) (s : Set α) (h : InjOn f s) : lift.{u} #(f '' s) = lift.{v} #s := lift_mk_eq.{v, u, 0}.mpr ⟨(Equiv.Set.imageOfInjOn f s h).symm⟩ theorem mk_image_eq {α β : Type u} {f : α → β} {s : Set α} (hf : Injective f) : #(f '' s) = #s := mk_image_eq_of_injOn _ _ hf.injOn theorem mk_image_eq_lift {α : Type u} {β : Type v} (f : α → β) (s : Set α) (h : Injective f) : lift.{u} #(f '' s) = lift.{v} #s := mk_image_eq_of_injOn_lift _ _ h.injOn @[simp] theorem mk_image_embedding_lift {β : Type v} (f : α ↪ β) (s : Set α) : lift.{u} #(f '' s) = lift.{v} #s := mk_image_eq_lift _ _ f.injective @[simp] theorem mk_image_embedding (f : α ↪ β) (s : Set α) : #(f '' s) = #s := by simpa using mk_image_embedding_lift f s theorem mk_iUnion_le_sum_mk {α ι : Type u} {f : ι → Set α} : #(⋃ i, f i) ≤ sum fun i => #(f i) := calc #(⋃ i, f i) ≤ #(Σi, f i) := mk_le_of_surjective (Set.sigmaToiUnion_surjective f) _ = sum fun i => #(f i) := mk_sigma _ theorem mk_iUnion_le_sum_mk_lift {α : Type u} {ι : Type v} {f : ι → Set α} : lift.{v} #(⋃ i, f i) ≤ sum fun i => #(f i) := calc lift.{v} #(⋃ i, f i) ≤ #(Σi, f i) := mk_le_of_surjective <| ULift.up_surjective.comp (Set.sigmaToiUnion_surjective f) _ = sum fun i => #(f i) := mk_sigma _ theorem mk_iUnion_eq_sum_mk {α ι : Type u} {f : ι → Set α} (h : Pairwise (Disjoint on f)) : #(⋃ i, f i) = sum fun i => #(f i) := calc #(⋃ i, f i) = #(Σi, f i) := mk_congr (Set.unionEqSigmaOfDisjoint h) _ = sum fun i => #(f i) := mk_sigma _ theorem mk_iUnion_eq_sum_mk_lift {α : Type u} {ι : Type v} {f : ι → Set α} (h : Pairwise (Disjoint on f)) : lift.{v} #(⋃ i, f i) = sum fun i => #(f i) := calc lift.{v} #(⋃ i, f i) = #(Σi, f i) := mk_congr <| .trans Equiv.ulift (Set.unionEqSigmaOfDisjoint h) _ = sum fun i => #(f i) := mk_sigma _ theorem mk_iUnion_le {α ι : Type u} (f : ι → Set α) : #(⋃ i, f i) ≤ #ι * ⨆ i, #(f i) := mk_iUnion_le_sum_mk.trans (sum_le_iSup _) theorem mk_iUnion_le_lift {α : Type u} {ι : Type v} (f : ι → Set α) : lift.{v} #(⋃ i, f i) ≤ lift.{u} #ι * ⨆ i, lift.{v} #(f i) := by refine mk_iUnion_le_sum_mk_lift.trans <| Eq.trans_le ?_ (sum_le_iSup_lift _) rw [← lift_sum, lift_id'.{_,u}] theorem mk_sUnion_le {α : Type u} (A : Set (Set α)) : #(⋃₀ A) ≤ #A * ⨆ s : A, #s := by rw [sUnion_eq_iUnion] apply mk_iUnion_le theorem mk_biUnion_le {ι α : Type u} (A : ι → Set α) (s : Set ι) : #(⋃ x ∈ s, A x) ≤ #s * ⨆ x : s, #(A x.1) := by rw [biUnion_eq_iUnion] apply mk_iUnion_le theorem mk_biUnion_le_lift {α : Type u} {ι : Type v} (A : ι → Set α) (s : Set ι) : lift.{v} #(⋃ x ∈ s, A x) ≤ lift.{u} #s * ⨆ x : s, lift.{v} #(A x.1) := by rw [biUnion_eq_iUnion] apply mk_iUnion_le_lift theorem finset_card_lt_aleph0 (s : Finset α) : #(↑s : Set α) < ℵ₀ := lt_aleph0_of_finite _ theorem mk_set_eq_nat_iff_finset {α} {s : Set α} {n : ℕ} : #s = n ↔ ∃ t : Finset α, (t : Set α) = s ∧ t.card = n := by constructor · intro h lift s to Finset α using lt_aleph0_iff_set_finite.1 (h.symm ▸ nat_lt_aleph0 n) simpa using h · rintro ⟨t, rfl, rfl⟩ exact mk_coe_finset theorem mk_eq_nat_iff_finset {n : ℕ} : #α = n ↔ ∃ t : Finset α, (t : Set α) = univ ∧ t.card = n := by rw [← mk_univ, mk_set_eq_nat_iff_finset] theorem mk_eq_nat_iff_fintype {n : ℕ} : #α = n ↔ ∃ h : Fintype α, @Fintype.card α h = n := by rw [mk_eq_nat_iff_finset] constructor · rintro ⟨t, ht, hn⟩ exact ⟨⟨t, eq_univ_iff_forall.1 ht⟩, hn⟩ · rintro ⟨⟨t, ht⟩, hn⟩ exact ⟨t, eq_univ_iff_forall.2 ht, hn⟩ theorem mk_union_add_mk_inter {α : Type u} {S T : Set α} : #(S ∪ T : Set α) + #(S ∩ T : Set α) = #S + #T := by classical exact Quot.sound ⟨Equiv.Set.unionSumInter S T⟩ /-- The cardinality of a union is at most the sum of the cardinalities of the two sets. -/ theorem mk_union_le {α : Type u} (S T : Set α) : #(S ∪ T : Set α) ≤ #S + #T := @mk_union_add_mk_inter α S T ▸ self_le_add_right #(S ∪ T : Set α) #(S ∩ T : Set α) theorem mk_union_of_disjoint {α : Type u} {S T : Set α} (H : Disjoint S T) : #(S ∪ T : Set α) = #S + #T := by classical exact Quot.sound ⟨Equiv.Set.union H⟩ theorem mk_insert {α : Type u} {s : Set α} {a : α} (h : a ∉ s) : #(insert a s : Set α) = #s + 1 := by rw [← union_singleton, mk_union_of_disjoint, mk_singleton] simpa theorem mk_insert_le {α : Type u} {s : Set α} {a : α} : #(insert a s : Set α) ≤ #s + 1 := by by_cases h : a ∈ s · simp only [insert_eq_of_mem h, self_le_add_right] · rw [mk_insert h] theorem mk_sum_compl {α} (s : Set α) : #s + #(sᶜ : Set α) = #α := by classical exact mk_congr (Equiv.Set.sumCompl s) theorem mk_le_mk_of_subset {α} {s t : Set α} (h : s ⊆ t) : #s ≤ #t := ⟨Set.embeddingOfSubset s t h⟩ theorem mk_le_iff_forall_finset_subset_card_le {α : Type u} {n : ℕ} {t : Set α} : #t ≤ n ↔ ∀ s : Finset α, (s : Set α) ⊆ t → s.card ≤ n := by refine ⟨fun H s hs ↦ by simpa using (mk_le_mk_of_subset hs).trans H, fun H ↦ ?_⟩ apply card_le_of (fun s ↦ ?_) classical let u : Finset α := s.image Subtype.val have : u.card = s.card := Finset.card_image_of_injOn Subtype.coe_injective.injOn rw [← this] apply H simp only [u, Finset.coe_image, image_subset_iff, Subtype.coe_preimage_self, subset_univ] theorem mk_subtype_mono {p q : α → Prop} (h : ∀ x, p x → q x) : #{ x // p x } ≤ #{ x // q x } := ⟨embeddingOfSubset _ _ h⟩ theorem le_mk_diff_add_mk (S T : Set α) : #S ≤ #(S \ T : Set α) + #T := (mk_le_mk_of_subset <| subset_diff_union _ _).trans <| mk_union_le _ _ theorem mk_diff_add_mk {S T : Set α} (h : T ⊆ S) : #(S \ T : Set α) + #T = #S := by refine (mk_union_of_disjoint <| ?_).symm.trans <| by rw [diff_union_of_subset h] exact disjoint_sdiff_self_left theorem mk_union_le_aleph0 {α} {P Q : Set α} : #(P ∪ Q : Set α) ≤ ℵ₀ ↔ #P ≤ ℵ₀ ∧ #Q ≤ ℵ₀ := by simp only [le_aleph0_iff_subtype_countable, mem_union, setOf_mem_eq, Set.union_def, ← countable_union] theorem mk_sep (s : Set α) (t : α → Prop) : #({ x ∈ s | t x } : Set α) = #{ x : s | t x.1 } := mk_congr (Equiv.Set.sep s t) theorem mk_preimage_of_injective_lift {α : Type u} {β : Type v} (f : α → β) (s : Set β) (h : Injective f) : lift.{v} #(f ⁻¹' s) ≤ lift.{u} #s := by rw [lift_mk_le.{0}] -- Porting note: Needed to insert `mem_preimage.mp` below use Subtype.coind (fun x => f x.1) fun x => mem_preimage.mp x.2 apply Subtype.coind_injective; exact h.comp Subtype.val_injective theorem mk_preimage_of_subset_range_lift {α : Type u} {β : Type v} (f : α → β) (s : Set β) (h : s ⊆ range f) : lift.{u} #s ≤ lift.{v} #(f ⁻¹' s) := by rw [← image_preimage_eq_iff] at h nth_rewrite 1 [← h] apply mk_image_le_lift theorem mk_preimage_of_injective_of_subset_range_lift {β : Type v} (f : α → β) (s : Set β) (h : Injective f) (h2 : s ⊆ range f) : lift.{v} #(f ⁻¹' s) = lift.{u} #s := le_antisymm (mk_preimage_of_injective_lift f s h) (mk_preimage_of_subset_range_lift f s h2) theorem mk_preimage_of_injective_of_subset_range (f : α → β) (s : Set β) (h : Injective f) (h2 : s ⊆ range f) : #(f ⁻¹' s) = #s := by convert mk_preimage_of_injective_of_subset_range_lift.{u, u} f s h h2 using 1 <;> rw [lift_id] @[simp] theorem mk_preimage_equiv_lift {β : Type v} (f : α ≃ β) (s : Set β) : lift.{v} #(f ⁻¹' s) = lift.{u} #s := by apply mk_preimage_of_injective_of_subset_range_lift _ _ f.injective rw [f.range_eq_univ] exact fun _ _ ↦ ⟨⟩ @[simp] theorem mk_preimage_equiv (f : α ≃ β) (s : Set β) : #(f ⁻¹' s) = #s := by simpa using mk_preimage_equiv_lift f s theorem mk_preimage_of_injective (f : α → β) (s : Set β) (h : Injective f) : #(f ⁻¹' s) ≤ #s := by rw [← lift_id #(↑(f ⁻¹' s)), ← lift_id #(↑s)] exact mk_preimage_of_injective_lift f s h theorem mk_preimage_of_subset_range (f : α → β) (s : Set β) (h : s ⊆ range f) : #s ≤ #(f ⁻¹' s) := by rw [← lift_id #(↑(f ⁻¹' s)), ← lift_id #(↑s)] exact mk_preimage_of_subset_range_lift f s h theorem mk_subset_ge_of_subset_image_lift {α : Type u} {β : Type v} (f : α → β) {s : Set α} {t : Set β} (h : t ⊆ f '' s) : lift.{u} #t ≤ lift.{v} #({ x ∈ s | f x ∈ t } : Set α) := by rw [image_eq_range] at h convert mk_preimage_of_subset_range_lift _ _ h using 1 rw [mk_sep] rfl theorem mk_subset_ge_of_subset_image (f : α → β) {s : Set α} {t : Set β} (h : t ⊆ f '' s) : #t ≤ #({ x ∈ s | f x ∈ t } : Set α) := by rw [image_eq_range] at h convert mk_preimage_of_subset_range _ _ h using 1 rw [mk_sep] rfl theorem le_mk_iff_exists_subset {c : Cardinal} {α : Type u} {s : Set α} : c ≤ #s ↔ ∃ p : Set α, p ⊆ s ∧ #p = c := by rw [le_mk_iff_exists_set, ← Subtype.exists_set_subtype] apply exists_congr; intro t; rw [mk_image_eq]; apply Subtype.val_injective @[simp] theorem mk_range_inl {α : Type u} {β : Type v} : #(range (@Sum.inl α β)) = lift.{v} #α := by rw [← lift_id'.{u, v} #_, (Equiv.Set.rangeInl α β).lift_cardinal_eq, lift_umax.{u, v}] @[simp] theorem mk_range_inr {α : Type u} {β : Type v} : #(range (@Sum.inr α β)) = lift.{u} #β := by rw [← lift_id'.{v, u} #_, (Equiv.Set.rangeInr α β).lift_cardinal_eq, lift_umax.{v, u}] theorem two_le_iff : (2 : Cardinal) ≤ #α ↔ ∃ x y : α, x ≠ y := by rw [← Nat.cast_two, nat_succ, succ_le_iff, Nat.cast_one, one_lt_iff_nontrivial, nontrivial_iff] theorem two_le_iff' (x : α) : (2 : Cardinal) ≤ #α ↔ ∃ y : α, y ≠ x := by rw [two_le_iff, ← nontrivial_iff, nontrivial_iff_exists_ne x] theorem mk_eq_two_iff : #α = 2 ↔ ∃ x y : α, x ≠ y ∧ ({x, y} : Set α) = univ := by classical simp only [← @Nat.cast_two Cardinal, mk_eq_nat_iff_finset, Finset.card_eq_two] constructor · rintro ⟨t, ht, x, y, hne, rfl⟩ exact ⟨x, y, hne, by simpa using ht⟩ · rintro ⟨x, y, hne, h⟩ exact ⟨{x, y}, by simpa using h, x, y, hne, rfl⟩ theorem mk_eq_two_iff' (x : α) : #α = 2 ↔ ∃! y, y ≠ x := by rw [mk_eq_two_iff]; constructor · rintro ⟨a, b, hne, h⟩ simp only [eq_univ_iff_forall, mem_insert_iff, mem_singleton_iff] at h rcases h x with (rfl | rfl) exacts [⟨b, hne.symm, fun z => (h z).resolve_left⟩, ⟨a, hne, fun z => (h z).resolve_right⟩] · rintro ⟨y, hne, hy⟩ exact ⟨x, y, hne.symm, eq_univ_of_forall fun z => or_iff_not_imp_left.2 (hy z)⟩ theorem exists_not_mem_of_length_lt {α : Type*} (l : List α) (h : ↑l.length < #α) : ∃ z : α, z ∉ l := by classical contrapose! h calc #α = #(Set.univ : Set α) := mk_univ.symm _ ≤ #l.toFinset := mk_le_mk_of_subset fun x _ => List.mem_toFinset.mpr (h x) _ = l.toFinset.card := Cardinal.mk_coe_finset _ ≤ l.length := Nat.cast_le.mpr (List.toFinset_card_le l) theorem three_le {α : Type*} (h : 3 ≤ #α) (x : α) (y : α) : ∃ z : α, z ≠ x ∧ z ≠ y := by have : ↑(3 : ℕ) ≤ #α := by simpa using h have : ↑(2 : ℕ) < #α := by rwa [← succ_le_iff, ← Cardinal.nat_succ] have := exists_not_mem_of_length_lt [x, y] this simpa [not_or] using this /-! ### `powerlt` operation -/ /-- The function `a ^< b`, defined as the supremum of `a ^ c` for `c < b`. -/ def powerlt (a b : Cardinal.{u}) : Cardinal.{u} := ⨆ c : Iio b, a ^ (c : Cardinal) @[inherit_doc] infixl:80 " ^< " => powerlt theorem le_powerlt {b c : Cardinal.{u}} (a) (h : c < b) : (a^c) ≤ a ^< b := by refine le_ciSup (f := fun y : Iio b => a ^ (y : Cardinal)) ?_ ⟨c, h⟩ rw [← image_eq_range] exact bddAbove_image.{u, u} _ bddAbove_Iio theorem powerlt_le {a b c : Cardinal.{u}} : a ^< b ≤ c ↔ ∀ x < b, a ^ x ≤ c := by rw [powerlt, ciSup_le_iff'] · simp · rw [← image_eq_range] exact bddAbove_image.{u, u} _ bddAbove_Iio theorem powerlt_le_powerlt_left {a b c : Cardinal} (h : b ≤ c) : a ^< b ≤ a ^< c := powerlt_le.2 fun _ hx => le_powerlt a <| hx.trans_le h theorem powerlt_mono_left (a) : Monotone fun c => a ^< c := fun _ _ => powerlt_le_powerlt_left theorem powerlt_succ {a b : Cardinal} (h : a ≠ 0) : a ^< succ b = a ^ b := (powerlt_le.2 fun _ h' => power_le_power_left h <| le_of_lt_succ h').antisymm <| le_powerlt a (lt_succ b) theorem powerlt_min {a b c : Cardinal} : a ^< min b c = min (a ^< b) (a ^< c) := (powerlt_mono_left a).map_min theorem powerlt_max {a b c : Cardinal} : a ^< max b c = max (a ^< b) (a ^< c) := (powerlt_mono_left a).map_max theorem zero_powerlt {a : Cardinal} (h : a ≠ 0) : 0 ^< a = 1 := by apply (powerlt_le.2 fun c _ => zero_power_le _).antisymm rw [← power_zero] exact le_powerlt 0 (pos_iff_ne_zero.2 h) @[simp] theorem powerlt_zero {a : Cardinal} : a ^< 0 = 0 := by convert Cardinal.iSup_of_empty _ exact Subtype.isEmpty_of_false fun x => mem_Iio.not.mpr (Cardinal.zero_le x).not_lt end Cardinal
Mathlib/SetTheory/Cardinal/Basic.lean
1,526
1,530
/- 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.BigOperators.Group.Finset.Indicator import Mathlib.Algebra.Module.BigOperators import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace.Basic import Mathlib.LinearAlgebra.Finsupp.LinearCombination import Mathlib.Tactic.FinCases /-! # Affine combinations of points This file defines affine combinations of points. ## Main definitions * `weightedVSubOfPoint` is a general weighted combination of subtractions with an explicit base point, yielding a vector. * `weightedVSub` uses an arbitrary choice of base point and is intended to be used when the sum of weights is 0, in which case the result is independent of the choice of base point. * `affineCombination` adds the weighted combination to the arbitrary base point, yielding a point rather than a vector, and is intended to be used when the sum of weights is 1, in which case the result is independent of the choice of base point. These definitions are for sums over a `Finset`; versions for a `Fintype` may be obtained using `Finset.univ`, while versions for a `Finsupp` may be obtained using `Finsupp.support`. ## References * https://en.wikipedia.org/wiki/Affine_space -/ noncomputable section open Affine namespace Finset theorem univ_fin2 : (univ : Finset (Fin 2)) = {0, 1} := by ext x fin_cases x <;> simp variable {k : Type*} {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] variable [S : AffineSpace V P] variable {ι : Type*} (s : Finset ι) variable {ι₂ : Type*} (s₂ : Finset ι₂) /-- A weighted sum of the results of subtracting a base point from the given points, as a linear map on the weights. The main cases of interest are where the sum of the weights is 0, in which case the sum is independent of the choice of base point, and where the sum of the weights is 1, in which case the sum added to the base point is independent of the choice of base point. -/ def weightedVSubOfPoint (p : ι → P) (b : P) : (ι → k) →ₗ[k] V := ∑ i ∈ s, (LinearMap.proj i : (ι → k) →ₗ[k] k).smulRight (p i -ᵥ b) @[simp] theorem weightedVSubOfPoint_apply (w : ι → k) (p : ι → P) (b : P) : s.weightedVSubOfPoint p b w = ∑ i ∈ s, w i • (p i -ᵥ b) := by simp [weightedVSubOfPoint, LinearMap.sum_apply] /-- The value of `weightedVSubOfPoint`, where the given points are equal. -/ @[simp (high)] theorem weightedVSubOfPoint_apply_const (w : ι → k) (p : P) (b : P) : s.weightedVSubOfPoint (fun _ => p) b w = (∑ i ∈ s, w i) • (p -ᵥ b) := by rw [weightedVSubOfPoint_apply, sum_smul] lemma weightedVSubOfPoint_vadd (s : Finset ι) (w : ι → k) (p : ι → P) (b : P) (v : V) : s.weightedVSubOfPoint (v +ᵥ p) b w = s.weightedVSubOfPoint p (-v +ᵥ b) w := by simp [vadd_vsub_assoc, vsub_vadd_eq_vsub_sub, add_comm] lemma weightedVSubOfPoint_smul {G : Type*} [Group G] [DistribMulAction G V] [SMulCommClass G k V] (s : Finset ι) (w : ι → k) (p : ι → V) (b : V) (a : G) : s.weightedVSubOfPoint (a • p) b w = a • s.weightedVSubOfPoint p (a⁻¹ • b) w := by simp [smul_sum, smul_sub, smul_comm a (w _)] /-- `weightedVSubOfPoint` gives equal results for two families of weights and two families of points that are equal on `s`. -/ theorem weightedVSubOfPoint_congr {w₁ w₂ : ι → k} (hw : ∀ i ∈ s, w₁ i = w₂ i) {p₁ p₂ : ι → P} (hp : ∀ i ∈ s, p₁ i = p₂ i) (b : P) : s.weightedVSubOfPoint p₁ b w₁ = s.weightedVSubOfPoint p₂ b w₂ := by simp_rw [weightedVSubOfPoint_apply] refine sum_congr rfl fun i hi => ?_ rw [hw i hi, hp i hi] /-- Given a family of points, if we use a member of the family as a base point, the `weightedVSubOfPoint` does not depend on the value of the weights at this point. -/ theorem weightedVSubOfPoint_eq_of_weights_eq (p : ι → P) (j : ι) (w₁ w₂ : ι → k) (hw : ∀ i, i ≠ j → w₁ i = w₂ i) : s.weightedVSubOfPoint p (p j) w₁ = s.weightedVSubOfPoint p (p j) w₂ := by simp only [Finset.weightedVSubOfPoint_apply] congr ext i rcases eq_or_ne i j with h | h · simp [h] · simp [hw i h] /-- The weighted sum is independent of the base point when the sum of the weights is 0. -/ theorem weightedVSubOfPoint_eq_of_sum_eq_zero (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 0) (b₁ b₂ : P) : s.weightedVSubOfPoint p b₁ w = s.weightedVSubOfPoint p b₂ w := by apply eq_of_sub_eq_zero rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← sum_sub_distrib] conv_lhs => congr · skip · ext rw [← smul_sub, vsub_sub_vsub_cancel_left] rw [← sum_smul, h, zero_smul] /-- The weighted sum, added to the base point, is independent of the base point when the sum of the weights is 1. -/ theorem weightedVSubOfPoint_vadd_eq_of_sum_eq_one (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 1) (b₁ b₂ : P) : s.weightedVSubOfPoint p b₁ w +ᵥ b₁ = s.weightedVSubOfPoint p b₂ w +ᵥ b₂ := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← @vsub_eq_zero_iff_eq V, vadd_vsub_assoc, vsub_vadd_eq_vsub_sub, ← add_sub_assoc, add_comm, add_sub_assoc, ← sum_sub_distrib] conv_lhs => congr · skip · congr · skip · ext rw [← smul_sub, vsub_sub_vsub_cancel_left] rw [← sum_smul, h, one_smul, vsub_add_vsub_cancel, vsub_self] /-- The weighted sum is unaffected by removing the base point, if present, from the set of points. -/ @[simp (high)] theorem weightedVSubOfPoint_erase [DecidableEq ι] (w : ι → k) (p : ι → P) (i : ι) : (s.erase i).weightedVSubOfPoint p (p i) w = s.weightedVSubOfPoint p (p i) w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply] apply sum_erase rw [vsub_self, smul_zero] /-- The weighted sum is unaffected by adding the base point, whether or not present, to the set of points. -/ @[simp (high)] theorem weightedVSubOfPoint_insert [DecidableEq ι] (w : ι → k) (p : ι → P) (i : ι) : (insert i s).weightedVSubOfPoint p (p i) w = s.weightedVSubOfPoint p (p i) w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply] apply sum_insert_zero rw [vsub_self, smul_zero] /-- The weighted sum is unaffected by changing the weights to the corresponding indicator function and adding points to the set. -/ theorem weightedVSubOfPoint_indicator_subset (w : ι → k) (p : ι → P) (b : P) {s₁ s₂ : Finset ι} (h : s₁ ⊆ s₂) : s₁.weightedVSubOfPoint p b w = s₂.weightedVSubOfPoint p b (Set.indicator (↑s₁) w) := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply] exact Eq.symm <| sum_indicator_subset_of_eq_zero w (fun i wi => wi • (p i -ᵥ b : V)) h fun i => zero_smul k _ /-- A weighted sum, over the image of an embedding, equals a weighted sum with the same points and weights over the original `Finset`. -/ theorem weightedVSubOfPoint_map (e : ι₂ ↪ ι) (w : ι → k) (p : ι → P) (b : P) : (s₂.map e).weightedVSubOfPoint p b w = s₂.weightedVSubOfPoint (p ∘ e) b (w ∘ e) := by simp_rw [weightedVSubOfPoint_apply] exact Finset.sum_map _ _ _ /-- A weighted sum of pairwise subtractions, expressed as a subtraction of two `weightedVSubOfPoint` expressions. -/ theorem sum_smul_vsub_eq_weightedVSubOfPoint_sub (w : ι → k) (p₁ p₂ : ι → P) (b : P) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂ i)) = s.weightedVSubOfPoint p₁ b w - s.weightedVSubOfPoint p₂ b w := by simp_rw [weightedVSubOfPoint_apply, ← sum_sub_distrib, ← smul_sub, vsub_sub_vsub_cancel_right] /-- A weighted sum of pairwise subtractions, where the point on the right is constant, expressed as a subtraction involving a `weightedVSubOfPoint` expression. -/ theorem sum_smul_vsub_const_eq_weightedVSubOfPoint_sub (w : ι → k) (p₁ : ι → P) (p₂ b : P) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂)) = s.weightedVSubOfPoint p₁ b w - (∑ i ∈ s, w i) • (p₂ -ᵥ b) := by rw [sum_smul_vsub_eq_weightedVSubOfPoint_sub, weightedVSubOfPoint_apply_const] /-- A weighted sum of pairwise subtractions, where the point on the left is constant, expressed as a subtraction involving a `weightedVSubOfPoint` expression. -/ theorem sum_smul_const_vsub_eq_sub_weightedVSubOfPoint (w : ι → k) (p₂ : ι → P) (p₁ b : P) : (∑ i ∈ s, w i • (p₁ -ᵥ p₂ i)) = (∑ i ∈ s, w i) • (p₁ -ᵥ b) - s.weightedVSubOfPoint p₂ b w := by rw [sum_smul_vsub_eq_weightedVSubOfPoint_sub, weightedVSubOfPoint_apply_const] /-- A weighted sum may be split into such sums over two subsets. -/ theorem weightedVSubOfPoint_sdiff [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) (b : P) : (s \ s₂).weightedVSubOfPoint p b w + s₂.weightedVSubOfPoint p b w = s.weightedVSubOfPoint p b w := by simp_rw [weightedVSubOfPoint_apply, sum_sdiff h] /-- A weighted sum may be split into a subtraction of such sums over two subsets. -/ theorem weightedVSubOfPoint_sdiff_sub [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) (b : P) : (s \ s₂).weightedVSubOfPoint p b w - s₂.weightedVSubOfPoint p b (-w) = s.weightedVSubOfPoint p b w := by rw [map_neg, sub_neg_eq_add, s.weightedVSubOfPoint_sdiff h] /-- A weighted sum over `s.subtype pred` equals one over `{x ∈ s | pred x}`. -/ theorem weightedVSubOfPoint_subtype_eq_filter (w : ι → k) (p : ι → P) (b : P) (pred : ι → Prop) [DecidablePred pred] : ((s.subtype pred).weightedVSubOfPoint (fun i => p i) b fun i => w i) = {x ∈ s | pred x}.weightedVSubOfPoint p b w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← sum_subtype_eq_sum_filter] /-- A weighted sum over `{x ∈ s | pred x}` equals one over `s` if all the weights at indices in `s` not satisfying `pred` are zero. -/ theorem weightedVSubOfPoint_filter_of_ne (w : ι → k) (p : ι → P) (b : P) {pred : ι → Prop} [DecidablePred pred] (h : ∀ i ∈ s, w i ≠ 0 → pred i) : {x ∈ s | pred x}.weightedVSubOfPoint p b w = s.weightedVSubOfPoint p b w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, sum_filter_of_ne] intro i hi hne refine h i hi ?_ intro hw simp [hw] at hne /-- A constant multiplier of the weights in `weightedVSubOfPoint` may be moved outside the sum. -/ theorem weightedVSubOfPoint_const_smul (w : ι → k) (p : ι → P) (b : P) (c : k) : s.weightedVSubOfPoint p b (c • w) = c • s.weightedVSubOfPoint p b w := by simp_rw [weightedVSubOfPoint_apply, smul_sum, Pi.smul_apply, smul_smul, smul_eq_mul] /-- A weighted sum of the results of subtracting a default base point from the given points, as a linear map on the weights. This is intended to be used when the sum of the weights is 0; that condition is specified as a hypothesis on those lemmas that require it. -/ def weightedVSub (p : ι → P) : (ι → k) →ₗ[k] V := s.weightedVSubOfPoint p (Classical.choice S.nonempty) /-- Applying `weightedVSub` with given weights. This is for the case where a result involving a default base point is OK (for example, when that base point will cancel out later); a more typical use case for `weightedVSub` would involve selecting a preferred base point with `weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero` and then using `weightedVSubOfPoint_apply`. -/ theorem weightedVSub_apply (w : ι → k) (p : ι → P) : s.weightedVSub p w = ∑ i ∈ s, w i • (p i -ᵥ Classical.choice S.nonempty) := by simp [weightedVSub, LinearMap.sum_apply] /-- `weightedVSub` gives the sum of the results of subtracting any base point, when the sum of the weights is 0. -/ theorem weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero (w : ι → k) (p : ι → P) (h : ∑ i ∈ s, w i = 0) (b : P) : s.weightedVSub p w = s.weightedVSubOfPoint p b w := s.weightedVSubOfPoint_eq_of_sum_eq_zero w p h _ _ /-- The value of `weightedVSub`, where the given points are equal and the sum of the weights is 0. -/ @[simp] theorem weightedVSub_apply_const (w : ι → k) (p : P) (h : ∑ i ∈ s, w i = 0) : s.weightedVSub (fun _ => p) w = 0 := by rw [weightedVSub, weightedVSubOfPoint_apply_const, h, zero_smul] /-- The `weightedVSub` for an empty set is 0. -/ @[simp] theorem weightedVSub_empty (w : ι → k) (p : ι → P) : (∅ : Finset ι).weightedVSub p w = (0 : V) := by simp [weightedVSub_apply] lemma weightedVSub_vadd {s : Finset ι} {w : ι → k} (h : ∑ i ∈ s, w i = 0) (p : ι → P) (v : V) : s.weightedVSub (v +ᵥ p) w = s.weightedVSub p w := by rw [weightedVSub, weightedVSubOfPoint_vadd, weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero _ _ _ h] lemma weightedVSub_smul {G : Type*} [Group G] [DistribMulAction G V] [SMulCommClass G k V] {s : Finset ι} {w : ι → k} (h : ∑ i ∈ s, w i = 0) (p : ι → V) (a : G) : s.weightedVSub (a • p) w = a • s.weightedVSub p w := by rw [weightedVSub, weightedVSubOfPoint_smul, weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero _ _ _ h] /-- `weightedVSub` gives equal results for two families of weights and two families of points that are equal on `s`. -/ theorem weightedVSub_congr {w₁ w₂ : ι → k} (hw : ∀ i ∈ s, w₁ i = w₂ i) {p₁ p₂ : ι → P} (hp : ∀ i ∈ s, p₁ i = p₂ i) : s.weightedVSub p₁ w₁ = s.weightedVSub p₂ w₂ := s.weightedVSubOfPoint_congr hw hp _ /-- The weighted sum is unaffected by changing the weights to the corresponding indicator function and adding points to the set. -/ theorem weightedVSub_indicator_subset (w : ι → k) (p : ι → P) {s₁ s₂ : Finset ι} (h : s₁ ⊆ s₂) : s₁.weightedVSub p w = s₂.weightedVSub p (Set.indicator (↑s₁) w) := weightedVSubOfPoint_indicator_subset _ _ _ h /-- A weighted subtraction, over the image of an embedding, equals a weighted subtraction with the same points and weights over the original `Finset`. -/ theorem weightedVSub_map (e : ι₂ ↪ ι) (w : ι → k) (p : ι → P) : (s₂.map e).weightedVSub p w = s₂.weightedVSub (p ∘ e) (w ∘ e) := s₂.weightedVSubOfPoint_map _ _ _ _ /-- A weighted sum of pairwise subtractions, expressed as a subtraction of two `weightedVSub` expressions. -/ theorem sum_smul_vsub_eq_weightedVSub_sub (w : ι → k) (p₁ p₂ : ι → P) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂ i)) = s.weightedVSub p₁ w - s.weightedVSub p₂ w := s.sum_smul_vsub_eq_weightedVSubOfPoint_sub _ _ _ _ /-- A weighted sum of pairwise subtractions, where the point on the right is constant and the sum of the weights is 0. -/ theorem sum_smul_vsub_const_eq_weightedVSub (w : ι → k) (p₁ : ι → P) (p₂ : P) (h : ∑ i ∈ s, w i = 0) : (∑ i ∈ s, w i • (p₁ i -ᵥ p₂)) = s.weightedVSub p₁ w := by rw [sum_smul_vsub_eq_weightedVSub_sub, s.weightedVSub_apply_const _ _ h, sub_zero] /-- A weighted sum of pairwise subtractions, where the point on the left is constant and the sum of the weights is 0. -/ theorem sum_smul_const_vsub_eq_neg_weightedVSub (w : ι → k) (p₂ : ι → P) (p₁ : P) (h : ∑ i ∈ s, w i = 0) : (∑ i ∈ s, w i • (p₁ -ᵥ p₂ i)) = -s.weightedVSub p₂ w := by rw [sum_smul_vsub_eq_weightedVSub_sub, s.weightedVSub_apply_const _ _ h, zero_sub] /-- A weighted sum may be split into such sums over two subsets. -/ theorem weightedVSub_sdiff [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) : (s \ s₂).weightedVSub p w + s₂.weightedVSub p w = s.weightedVSub p w := s.weightedVSubOfPoint_sdiff h _ _ _ /-- A weighted sum may be split into a subtraction of such sums over two subsets. -/ theorem weightedVSub_sdiff_sub [DecidableEq ι] {s₂ : Finset ι} (h : s₂ ⊆ s) (w : ι → k) (p : ι → P) : (s \ s₂).weightedVSub p w - s₂.weightedVSub p (-w) = s.weightedVSub p w := s.weightedVSubOfPoint_sdiff_sub h _ _ _
/-- A weighted sum over `s.subtype pred` equals one over `{x ∈ s | pred x}`. -/ theorem weightedVSub_subtype_eq_filter (w : ι → k) (p : ι → P) (pred : ι → Prop)
Mathlib/LinearAlgebra/AffineSpace/Combination.lean
320
322
/- Copyright (c) 2020 Nicolò Cavalleri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nicolò Cavalleri, Andrew Yang -/ import Mathlib.RingTheory.Derivation.ToSquareZero import Mathlib.RingTheory.Ideal.Cotangent import Mathlib.RingTheory.IsTensorProduct import Mathlib.RingTheory.EssentialFiniteness import Mathlib.Algebra.Exact import Mathlib.LinearAlgebra.TensorProduct.RightExactness /-! # The module of kaehler differentials ## Main results - `KaehlerDifferential`: The module of kaehler differentials. For an `R`-algebra `S`, we provide the notation `Ω[S⁄R]` for `KaehlerDifferential R S`. Note that the slash is `\textfractionsolidus`. - `KaehlerDifferential.D`: The derivation into the module of kaehler differentials. - `KaehlerDifferential.span_range_derivation`: The image of `D` spans `Ω[S⁄R]` as an `S`-module. - `KaehlerDifferential.linearMapEquivDerivation`: The isomorphism `Hom_R(Ω[S⁄R], M) ≃ₗ[S] Der_R(S, M)`. - `KaehlerDifferential.quotKerTotalEquiv`: An alternative description of `Ω[S⁄R]` as `S` copies of `S` with kernel (`KaehlerDifferential.kerTotal`) generated by the relations: 1. `dx + dy = d(x + y)` 2. `x dy + y dx = d(x * y)` 3. `dr = 0` for `r ∈ R` - `KaehlerDifferential.map`: Given a map between the arrows `R →+* A` and `S →+* B`, we have an `A`-linear map `Ω[A⁄R] → Ω[B⁄S]`. - `KaehlerDifferential.map_surjective`: The sequence `Ω[B⁄R] → Ω[B⁄A] → 0` is exact. - `KaehlerDifferential.exact_mapBaseChange_map`: The sequence `B ⊗[A] Ω[A⁄R] → Ω[B⁄R] → Ω[B⁄A]` is exact. - `KaehlerDifferential.exact_kerCotangentToTensor_mapBaseChange`: If `A → B` is surjective with kernel `I`, then the sequence `I/I² → B ⊗[A] Ω[A⁄R] → Ω[B⁄R]` is exact. - `KaehlerDifferential.mapBaseChange_surjective`: If `A → B` is surjective, then the sequence `B ⊗[A] Ω[A⁄R] → Ω[B⁄R] → 0` is exact. ## Future project - Define the `IsKaehlerDifferential` predicate. -/ suppress_compilation section KaehlerDifferential open scoped TensorProduct open Algebra Finsupp universe u v variable (R : Type u) (S : Type v) [CommRing R] [CommRing S] [Algebra R S] /-- The kernel of the multiplication map `S ⊗[R] S →ₐ[R] S`. -/ abbrev KaehlerDifferential.ideal : Ideal (S ⊗[R] S) := RingHom.ker (TensorProduct.lmul' R : S ⊗[R] S →ₐ[R] S) variable {S} theorem KaehlerDifferential.one_smul_sub_smul_one_mem_ideal (a : S) : (1 : S) ⊗ₜ[R] a - a ⊗ₜ[R] (1 : S) ∈ KaehlerDifferential.ideal R S := by simp [RingHom.mem_ker] variable {R} variable {M : Type*} [AddCommGroup M] [Module R M] [Module S M] [IsScalarTower R S M] /-- For a `R`-derivation `S → M`, this is the map `S ⊗[R] S →ₗ[S] M` sending `s ⊗ₜ t ↦ s • D t`. -/ def Derivation.tensorProductTo (D : Derivation R S M) : S ⊗[R] S →ₗ[S] M := TensorProduct.AlgebraTensorModule.lift ((LinearMap.lsmul S (S →ₗ[R] M)).flip D.toLinearMap) theorem Derivation.tensorProductTo_tmul (D : Derivation R S M) (s t : S) : D.tensorProductTo (s ⊗ₜ t) = s • D t := rfl theorem Derivation.tensorProductTo_mul (D : Derivation R S M) (x y : S ⊗[R] S) : D.tensorProductTo (x * y) = TensorProduct.lmul' (S := S) R x • D.tensorProductTo y + TensorProduct.lmul' (S := S) R y • D.tensorProductTo x := by refine TensorProduct.induction_on x ?_ ?_ ?_ · rw [zero_mul, map_zero, map_zero, zero_smul, smul_zero, add_zero] swap · intro x₁ y₁ h₁ h₂ rw [add_mul, map_add, map_add, map_add, add_smul, smul_add, h₁, h₂, add_add_add_comm] intro x₁ x₂ refine TensorProduct.induction_on y ?_ ?_ ?_ · rw [mul_zero, map_zero, map_zero, zero_smul, smul_zero, add_zero] swap · intro x₁ y₁ h₁ h₂ rw [mul_add, map_add, map_add, map_add, add_smul, smul_add, h₁, h₂, add_add_add_comm] intro x y simp only [TensorProduct.tmul_mul_tmul, Derivation.tensorProductTo, TensorProduct.AlgebraTensorModule.lift_apply, TensorProduct.lift.tmul', TensorProduct.lmul'_apply_tmul] dsimp rw [D.leibniz] simp only [smul_smul, smul_add, mul_comm (x * y) x₁, mul_right_comm x₁ x₂, ← mul_assoc] variable (R S) /-- The kernel of `S ⊗[R] S →ₐ[R] S` is generated by `1 ⊗ s - s ⊗ 1` as a `S`-module. -/ theorem KaehlerDifferential.submodule_span_range_eq_ideal : Submodule.span S (Set.range fun s : S => (1 : S) ⊗ₜ[R] s - s ⊗ₜ[R] (1 : S)) = (KaehlerDifferential.ideal R S).restrictScalars S := by apply le_antisymm · rw [Submodule.span_le] rintro _ ⟨s, rfl⟩ exact KaehlerDifferential.one_smul_sub_smul_one_mem_ideal _ _ · rintro x (hx : _ = _) have : x - TensorProduct.lmul' (S := S) R x ⊗ₜ[R] (1 : S) = x := by rw [hx, TensorProduct.zero_tmul, sub_zero] rw [← this] clear this hx refine TensorProduct.induction_on x ?_ ?_ ?_ · rw [map_zero, TensorProduct.zero_tmul, sub_zero]; exact zero_mem _ · intro x y have : x ⊗ₜ[R] y - (x * y) ⊗ₜ[R] (1 : S) = x • ((1 : S) ⊗ₜ y - y ⊗ₜ (1 : S)) := by simp_rw [smul_sub, TensorProduct.smul_tmul', smul_eq_mul, mul_one] rw [TensorProduct.lmul'_apply_tmul, this] refine Submodule.smul_mem _ x ?_ apply Submodule.subset_span exact Set.mem_range_self y · intro x y hx hy rw [map_add, TensorProduct.add_tmul, ← sub_add_sub_comm] exact add_mem hx hy theorem KaehlerDifferential.span_range_eq_ideal : Ideal.span (Set.range fun s : S => (1 : S) ⊗ₜ[R] s - s ⊗ₜ[R] (1 : S)) = KaehlerDifferential.ideal R S := by apply le_antisymm · rw [Ideal.span_le] rintro _ ⟨s, rfl⟩ exact KaehlerDifferential.one_smul_sub_smul_one_mem_ideal _ _ · change (KaehlerDifferential.ideal R S).restrictScalars S ≤ (Ideal.span _).restrictScalars S rw [← KaehlerDifferential.submodule_span_range_eq_ideal, Ideal.span] conv_rhs => rw [← Submodule.span_span_of_tower S] exact Submodule.subset_span /-- The module of Kähler differentials (Kahler differentials, Kaehler differentials). This is implemented as `I / I ^ 2` with `I` the kernel of the multiplication map `S ⊗[R] S →ₐ[R] S`. To view elements as a linear combination of the form `s • D s'`, use `KaehlerDifferential.tensorProductTo_surjective` and `Derivation.tensorProductTo_tmul`. We also provide the notation `Ω[S⁄R]` for `KaehlerDifferential R S`. Note that the slash is `\textfractionsolidus`. -/ def KaehlerDifferential : Type v := (KaehlerDifferential.ideal R S).Cotangent instance : AddCommGroup (KaehlerDifferential R S) := inferInstanceAs <| AddCommGroup (KaehlerDifferential.ideal R S).Cotangent instance KaehlerDifferential.module : Module (S ⊗[R] S) (KaehlerDifferential R S) := Ideal.Cotangent.moduleOfTower _ @[inherit_doc KaehlerDifferential] notation:100 "Ω[" S "⁄" R "]" => KaehlerDifferential R S instance : Nonempty (Ω[S⁄R]) := ⟨0⟩ instance KaehlerDifferential.module' {R' : Type*} [CommRing R'] [Algebra R' S] [SMulCommClass R R' S] : Module R' (Ω[S⁄R]) := Submodule.Quotient.module' _ instance : IsScalarTower S (S ⊗[R] S) (Ω[S⁄R]) := Ideal.Cotangent.isScalarTower _ instance KaehlerDifferential.isScalarTower_of_tower {R₁ R₂ : Type*} [CommRing R₁] [CommRing R₂] [Algebra R₁ S] [Algebra R₂ S] [SMul R₁ R₂] [SMulCommClass R R₁ S] [SMulCommClass R R₂ S] [IsScalarTower R₁ R₂ S] : IsScalarTower R₁ R₂ (Ω[S⁄R]) := Submodule.Quotient.isScalarTower _ _ instance KaehlerDifferential.isScalarTower' : IsScalarTower R (S ⊗[R] S) (Ω[S⁄R]) := Submodule.Quotient.isScalarTower _ _ /-- The quotient map `I → Ω[S⁄R]` with `I` being the kernel of `S ⊗[R] S → S`. -/ def KaehlerDifferential.fromIdeal : KaehlerDifferential.ideal R S →ₗ[S ⊗[R] S] Ω[S⁄R] := (KaehlerDifferential.ideal R S).toCotangent /-- (Implementation) The underlying linear map of the derivation into `Ω[S⁄R]`. -/ def KaehlerDifferential.DLinearMap : S →ₗ[R] Ω[S⁄R] := ((KaehlerDifferential.fromIdeal R S).restrictScalars R).comp ((TensorProduct.includeRight.toLinearMap - TensorProduct.includeLeft.toLinearMap : S →ₗ[R] S ⊗[R] S).codRestrict ((KaehlerDifferential.ideal R S).restrictScalars R) (KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R) : _ →ₗ[R] _) theorem KaehlerDifferential.DLinearMap_apply (s : S) : KaehlerDifferential.DLinearMap R S s = (KaehlerDifferential.ideal R S).toCotangent ⟨1 ⊗ₜ s - s ⊗ₜ 1, KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R s⟩ := rfl /-- The universal derivation into `Ω[S⁄R]`. -/ def KaehlerDifferential.D : Derivation R S (Ω[S⁄R]) := { toLinearMap := KaehlerDifferential.DLinearMap R S map_one_eq_zero' := by dsimp [KaehlerDifferential.DLinearMap_apply, Ideal.toCotangent_apply] congr rw [sub_self] leibniz' := fun a b => by have : LinearMap.CompatibleSMul { x // x ∈ ideal R S } (Ω[S⁄R]) S (S ⊗[R] S) := inferInstance dsimp [KaehlerDifferential.DLinearMap_apply] rw [← LinearMap.map_smul_of_tower (ideal R S).toCotangent, ← LinearMap.map_smul_of_tower (ideal R S).toCotangent, ← map_add (ideal R S).toCotangent, Ideal.toCotangent_eq, pow_two] convert Submodule.mul_mem_mul (KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R a :) (KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R b :) using 1 simp only [AddSubgroupClass.coe_sub, Submodule.coe_add, Submodule.coe_mk, TensorProduct.tmul_mul_tmul, mul_sub, sub_mul, mul_comm b, Submodule.coe_smul_of_tower, smul_sub, TensorProduct.smul_tmul', smul_eq_mul, mul_one] ring_nf } theorem KaehlerDifferential.D_apply (s : S) : KaehlerDifferential.D R S s = (KaehlerDifferential.ideal R S).toCotangent ⟨1 ⊗ₜ s - s ⊗ₜ 1, KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R s⟩ := rfl theorem KaehlerDifferential.span_range_derivation : Submodule.span S (Set.range <| KaehlerDifferential.D R S) = ⊤ := by rw [_root_.eq_top_iff] rintro x - obtain ⟨⟨x, hx⟩, rfl⟩ := Ideal.toCotangent_surjective _ x have : x ∈ (KaehlerDifferential.ideal R S).restrictScalars S := hx rw [← KaehlerDifferential.submodule_span_range_eq_ideal] at this suffices ∃ hx, (KaehlerDifferential.ideal R S).toCotangent ⟨x, hx⟩ ∈ Submodule.span S (Set.range <| KaehlerDifferential.D R S) by exact this.choose_spec refine Submodule.span_induction ?_ ?_ ?_ ?_ this · rintro _ ⟨x, rfl⟩ refine ⟨KaehlerDifferential.one_smul_sub_smul_one_mem_ideal R x, ?_⟩ apply Submodule.subset_span exact ⟨x, KaehlerDifferential.DLinearMap_apply R S x⟩ · exact ⟨zero_mem _, Submodule.zero_mem _⟩ · rintro x y - - ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩; exact ⟨add_mem hx₁ hy₁, Submodule.add_mem _ hx₂ hy₂⟩ · rintro r x - ⟨hx₁, hx₂⟩ exact ⟨((KaehlerDifferential.ideal R S).restrictScalars S).smul_mem r hx₁, Submodule.smul_mem _ r hx₂⟩ /-- `Ω[S⁄R]` is trivial if `R → S` is surjective. Also see `Algebra.FormallyUnramified.iff_subsingleton_kaehlerDifferential`. -/ lemma KaehlerDifferential.subsingleton_of_surjective (h : Function.Surjective (algebraMap R S)) : Subsingleton (Ω[S⁄R]) := by suffices (⊤ : Submodule S (Ω[S⁄R])) ≤ ⊥ from (subsingleton_iff_forall_eq 0).mpr fun y ↦ this trivial rw [← KaehlerDifferential.span_range_derivation, Submodule.span_le] rintro _ ⟨x, rfl⟩; obtain ⟨x, rfl⟩ := h x; simp variable {R S} /-- The linear map from `Ω[S⁄R]`, associated with a derivation. -/ def Derivation.liftKaehlerDifferential (D : Derivation R S M) : Ω[S⁄R] →ₗ[S] M := by refine LinearMap.comp ((((KaehlerDifferential.ideal R S) • (⊤ : Submodule (S ⊗[R] S) (KaehlerDifferential.ideal R S))).restrictScalars S).liftQ ?_ ?_) (Submodule.Quotient.restrictScalarsEquiv S _).symm.toLinearMap · exact D.tensorProductTo.comp ((KaehlerDifferential.ideal R S).subtype.restrictScalars S) · intro x hx rw [LinearMap.mem_ker] refine Submodule.smul_induction_on ((Submodule.restrictScalars_mem _ _ _).mp hx) ?_ ?_ · rintro x hx y - rw [RingHom.mem_ker] at hx dsimp rw [Derivation.tensorProductTo_mul, hx, y.prop, zero_smul, zero_smul, zero_add] · intro x y ex ey; rw [map_add, ex, ey, zero_add] theorem Derivation.liftKaehlerDifferential_apply (D : Derivation R S M) (x) : D.liftKaehlerDifferential ((KaehlerDifferential.ideal R S).toCotangent x) = D.tensorProductTo x := rfl theorem Derivation.liftKaehlerDifferential_comp (D : Derivation R S M) : D.liftKaehlerDifferential.compDer (KaehlerDifferential.D R S) = D := by ext a dsimp [KaehlerDifferential.D_apply] refine (D.liftKaehlerDifferential_apply _).trans ?_ rw [Subtype.coe_mk, map_sub, Derivation.tensorProductTo_tmul, Derivation.tensorProductTo_tmul, one_smul, D.map_one_eq_zero, smul_zero, sub_zero] @[simp] theorem Derivation.liftKaehlerDifferential_comp_D (D' : Derivation R S M) (x : S) : D'.liftKaehlerDifferential (KaehlerDifferential.D R S x) = D' x := Derivation.congr_fun D'.liftKaehlerDifferential_comp x @[ext] theorem Derivation.liftKaehlerDifferential_unique (f f' : Ω[S⁄R] →ₗ[S] M) (hf : f.compDer (KaehlerDifferential.D R S) = f'.compDer (KaehlerDifferential.D R S)) : f = f' := by apply LinearMap.ext intro x have : x ∈ Submodule.span S (Set.range <| KaehlerDifferential.D R S) := by rw [KaehlerDifferential.span_range_derivation]; trivial refine Submodule.span_induction ?_ ?_ ?_ ?_ this · rintro _ ⟨x, rfl⟩; exact congr_arg (fun D : Derivation R S M => D x) hf · rw [map_zero, map_zero] · intro x y _ _ hx hy; rw [map_add, map_add, hx, hy] · intro a x _ e; simp [e] variable (R S) theorem Derivation.liftKaehlerDifferential_D : (KaehlerDifferential.D R S).liftKaehlerDifferential = LinearMap.id := Derivation.liftKaehlerDifferential_unique _ _ (KaehlerDifferential.D R S).liftKaehlerDifferential_comp variable {R S} theorem KaehlerDifferential.D_tensorProductTo (x : KaehlerDifferential.ideal R S) : (KaehlerDifferential.D R S).tensorProductTo x = (KaehlerDifferential.ideal R S).toCotangent x := by rw [← Derivation.liftKaehlerDifferential_apply, Derivation.liftKaehlerDifferential_D] rfl variable (R S) theorem KaehlerDifferential.tensorProductTo_surjective : Function.Surjective (KaehlerDifferential.D R S).tensorProductTo := by intro x; obtain ⟨x, rfl⟩ := (KaehlerDifferential.ideal R S).toCotangent_surjective x exact ⟨x, KaehlerDifferential.D_tensorProductTo x⟩ /-- The `S`-linear maps from `Ω[S⁄R]` to `M` are (`S`-linearly) equivalent to `R`-derivations from `S` to `M`. -/ @[simps! symm_apply apply_apply] def KaehlerDifferential.linearMapEquivDerivation : (Ω[S⁄R] →ₗ[S] M) ≃ₗ[S] Derivation R S M := { Derivation.llcomp.flip <| KaehlerDifferential.D R S with invFun := Derivation.liftKaehlerDifferential left_inv := fun _ => Derivation.liftKaehlerDifferential_unique _ _ (Derivation.liftKaehlerDifferential_comp _) right_inv := Derivation.liftKaehlerDifferential_comp } /-- The quotient ring of `S ⊗ S ⧸ J ^ 2` by `Ω[S⁄R]` is isomorphic to `S`. -/ def KaehlerDifferential.quotientCotangentIdealRingEquiv : (S ⊗ S ⧸ KaehlerDifferential.ideal R S ^ 2) ⧸ (KaehlerDifferential.ideal R S).cotangentIdeal ≃+* S := by have : Function.RightInverse (TensorProduct.includeLeft (R := R) (S := R) (A := S) (B := S)) (↑(TensorProduct.lmul' R : S ⊗[R] S →ₐ[R] S) : S ⊗[R] S →+* S) := by intro x; rw [AlgHom.coe_toRingHom, ← AlgHom.comp_apply, TensorProduct.lmul'_comp_includeLeft] rfl refine (Ideal.quotCotangent _).trans ?_ refine (Ideal.quotEquivOfEq ?_).trans (RingHom.quotientKerEquivOfRightInverse this) ext; rfl /-- The quotient ring of `S ⊗ S ⧸ J ^ 2` by `Ω[S⁄R]` is isomorphic to `S` as an `S`-algebra. -/ def KaehlerDifferential.quotientCotangentIdeal : ((S ⊗ S ⧸ KaehlerDifferential.ideal R S ^ 2) ⧸ (KaehlerDifferential.ideal R S).cotangentIdeal) ≃ₐ[S] S := { KaehlerDifferential.quotientCotangentIdealRingEquiv R S with commutes' := (KaehlerDifferential.quotientCotangentIdealRingEquiv R S).apply_symm_apply }
theorem KaehlerDifferential.End_equiv_aux (f : S →ₐ[R] S ⊗ S ⧸ KaehlerDifferential.ideal R S ^ 2) : (Ideal.Quotient.mkₐ R (KaehlerDifferential.ideal R S).cotangentIdeal).comp f = IsScalarTower.toAlgHom R S _ ↔ (TensorProduct.lmul' R : S ⊗[R] S →ₐ[R] S).kerSquareLift.comp f = AlgHom.id R S := by
Mathlib/RingTheory/Kaehler/Basic.lean
351
354
/- Copyright (c) 2022 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.Algebra.Order.Ring.Nat import Mathlib.Order.Nat import Mathlib.Data.Nat.Prime.Basic /-! # Prime powers This file deals with prime powers: numbers which are positive integer powers of a single prime. -/ assert_not_exists Nat.divisors variable {R : Type*} [CommMonoidWithZero R] (n p : R) (k : ℕ) /-- `n` is a prime power if there is a prime `p` and a positive natural `k` such that `n` can be written as `p^k`. -/ def IsPrimePow : Prop := ∃ (p : R) (k : ℕ), Prime p ∧ 0 < k ∧ p ^ k = n theorem isPrimePow_def : IsPrimePow n ↔ ∃ (p : R) (k : ℕ), Prime p ∧ 0 < k ∧ p ^ k = n := Iff.rfl /-- An equivalent definition for prime powers: `n` is a prime power iff there is a prime `p` and a natural `k` such that `n` can be written as `p^(k+1)`. -/ theorem isPrimePow_iff_pow_succ : IsPrimePow n ↔ ∃ (p : R) (k : ℕ), Prime p ∧ p ^ (k + 1) = n := (isPrimePow_def _).trans ⟨fun ⟨p, k, hp, hk, hn⟩ => ⟨p, k - 1, hp, by rwa [Nat.sub_add_cancel hk]⟩, fun ⟨_, _, hp, hn⟩ => ⟨_, _, hp, Nat.succ_pos', hn⟩⟩ theorem not_isPrimePow_zero [NoZeroDivisors R] : ¬IsPrimePow (0 : R) := by simp only [isPrimePow_def, not_exists, not_and', and_imp] intro x n _hn hx rw [pow_eq_zero hx] simp theorem IsPrimePow.not_unit {n : R} (h : IsPrimePow n) : ¬IsUnit n := let ⟨_p, _k, hp, hk, hn⟩ := h hn ▸ (isUnit_pow_iff hk.ne').not.mpr hp.not_unit theorem IsUnit.not_isPrimePow {n : R} (h : IsUnit n) : ¬IsPrimePow n := fun h' => h'.not_unit h theorem not_isPrimePow_one : ¬IsPrimePow (1 : R) := isUnit_one.not_isPrimePow theorem Prime.isPrimePow {p : R} (hp : Prime p) : IsPrimePow p := ⟨p, 1, hp, zero_lt_one, by simp⟩ theorem IsPrimePow.pow {n : R} (hn : IsPrimePow n) {k : ℕ} (hk : k ≠ 0) : IsPrimePow (n ^ k) := let ⟨p, k', hp, hk', hn⟩ := hn ⟨p, k * k', hp, mul_pos hk.bot_lt hk', by rw [pow_mul', hn]⟩ theorem IsPrimePow.ne_zero [NoZeroDivisors R] {n : R} (h : IsPrimePow n) : n ≠ 0 := fun t => not_isPrimePow_zero (t ▸ h) theorem IsPrimePow.ne_one {n : R} (h : IsPrimePow n) : n ≠ 1 := fun t => not_isPrimePow_one (t ▸ h) section Nat theorem isPrimePow_nat_iff (n : ℕ) : IsPrimePow n ↔ ∃ p k : ℕ, Nat.Prime p ∧ 0 < k ∧ p ^ k = n := by simp only [isPrimePow_def, Nat.prime_iff] theorem Nat.Prime.isPrimePow {p : ℕ} (hp : p.Prime) : IsPrimePow p := _root_.Prime.isPrimePow (prime_iff.mp hp) theorem isPrimePow_nat_iff_bounded (n : ℕ) : IsPrimePow n ↔ ∃ p : ℕ, p ≤ n ∧ ∃ k : ℕ, k ≤ n ∧ p.Prime ∧ 0 < k ∧ p ^ k = n := by rw [isPrimePow_nat_iff] refine Iff.symm ⟨fun ⟨p, _, k, _, hp, hk, hn⟩ => ⟨p, k, hp, hk, hn⟩, ?_⟩ rintro ⟨p, k, hp, hk, rfl⟩ refine ⟨p, ?_, k, (Nat.lt_pow_self hp.one_lt).le, hp, hk, rfl⟩ conv => { lhs; rw [← (pow_one p)] } exact Nat.pow_le_pow_right hp.one_lt.le hk instance {n : ℕ} : Decidable (IsPrimePow n) := decidable_of_iff' _ (isPrimePow_nat_iff_bounded n) theorem IsPrimePow.dvd {n m : ℕ} (hn : IsPrimePow n) (hm : m ∣ n) (hm₁ : m ≠ 1) : IsPrimePow m := by rw [isPrimePow_nat_iff] at hn ⊢
rcases hn with ⟨p, k, hp, _hk, rfl⟩ obtain ⟨i, hik, rfl⟩ := (Nat.dvd_prime_pow hp).1 hm refine ⟨p, i, hp, ?_, rfl⟩ apply Nat.pos_of_ne_zero rintro rfl simp only [pow_zero, ne_eq, not_true_eq_false] at hm₁ theorem IsPrimePow.two_le : ∀ {n : ℕ}, IsPrimePow n → 2 ≤ n
Mathlib/Algebra/IsPrimePow.lean
84
91
/- Copyright (c) 2021 Frédéric Dupuis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Frédéric Dupuis -/ import Mathlib.Algebra.Group.Subgroup.Defs import Mathlib.Algebra.Module.Defs import Mathlib.Algebra.Star.Pi import Mathlib.Algebra.Star.Rat /-! # Self-adjoint, skew-adjoint and normal elements of a star additive group This file defines `selfAdjoint R` (resp. `skewAdjoint R`), where `R` is a star additive group, as the additive subgroup containing the elements that satisfy `star x = x` (resp. `star x = -x`). This includes, for instance, (skew-)Hermitian operators on Hilbert spaces. We also define `IsStarNormal R`, a `Prop` that states that an element `x` satisfies `star x * x = x * star x`. ## Implementation notes * When `R` is a `StarModule R₂ R`, then `selfAdjoint R` has a natural `Module (selfAdjoint R₂) (selfAdjoint R)` structure. However, doing this literally would be undesirable since in the main case of interest (`R₂ = ℂ`) we want `Module ℝ (selfAdjoint R)` and not `Module (selfAdjoint ℂ) (selfAdjoint R)`. We solve this issue by adding the typeclass `[TrivialStar R₃]`, of which `ℝ` is an instance (registered in `Data/Real/Basic`), and then add a `[Module R₃ (selfAdjoint R)]` instance whenever we have `[Module R₃ R] [TrivialStar R₃]`. (Another approach would have been to define `[StarInvariantScalars R₃ R]` to express the fact that `star (x • v) = x • star v`, but this typeclass would have the disadvantage of taking two type arguments.) ## TODO * Define `IsSkewAdjoint` to match `IsSelfAdjoint`. * Define `fun z x => z * x * star z` (i.e. conjugation by `z`) as a monoid action of `R` on `R` (similar to the existing `ConjAct` for groups), and then state the fact that `selfAdjoint R` is invariant under it. -/ open Function variable {R A : Type*} /-- An element is self-adjoint if it is equal to its star. -/ def IsSelfAdjoint [Star R] (x : R) : Prop := star x = x /-- An element of a star monoid is normal if it commutes with its adjoint. -/ @[mk_iff] class IsStarNormal [Mul R] [Star R] (x : R) : Prop where /-- A normal element of a star monoid commutes with its adjoint. -/ star_comm_self : Commute (star x) x export IsStarNormal (star_comm_self) theorem star_comm_self' [Mul R] [Star R] (x : R) [IsStarNormal x] : star x * x = x * star x := IsStarNormal.star_comm_self namespace IsSelfAdjoint -- named to match `Commute.allₓ` /-- All elements are self-adjoint when `star` is trivial. -/ theorem all [Star R] [TrivialStar R] (r : R) : IsSelfAdjoint r := star_trivial _ theorem star_eq [Star R] {x : R} (hx : IsSelfAdjoint x) : star x = x := hx theorem _root_.isSelfAdjoint_iff [Star R] {x : R} : IsSelfAdjoint x ↔ star x = x := Iff.rfl @[simp] theorem star_iff [InvolutiveStar R] {x : R} : IsSelfAdjoint (star x) ↔ IsSelfAdjoint x := by simpa only [IsSelfAdjoint, star_star] using eq_comm @[simp] theorem star_mul_self [Mul R] [StarMul R] (x : R) : IsSelfAdjoint (star x * x) := by simp only [IsSelfAdjoint, star_mul, star_star] @[simp] theorem mul_star_self [Mul R] [StarMul R] (x : R) : IsSelfAdjoint (x * star x) := by simpa only [star_star] using star_mul_self (star x) /-- Self-adjoint elements commute if and only if their product is self-adjoint. -/ lemma commute_iff {R : Type*} [Mul R] [StarMul R] {x y : R} (hx : IsSelfAdjoint x) (hy : IsSelfAdjoint y) : Commute x y ↔ IsSelfAdjoint (x * y) := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rw [isSelfAdjoint_iff, star_mul, hx.star_eq, hy.star_eq, h.eq] · simpa only [star_mul, hx.star_eq, hy.star_eq] using h.symm /-- Functions in a `StarHomClass` preserve self-adjoint elements. -/ @[aesop 10% apply] theorem map {F R S : Type*} [Star R] [Star S] [FunLike F R S] [StarHomClass F R S] {x : R} (hx : IsSelfAdjoint x) (f : F) : IsSelfAdjoint (f x) := show star (f x) = f x from map_star f x ▸ congr_arg f hx /- note: this lemma is *not* marked as `simp` so that Lean doesn't look for a `[TrivialStar R]` instance every time it sees `⊢ IsSelfAdjoint (f x)`, which will likely occur relatively often. -/ theorem _root_.isSelfAdjoint_map {F R S : Type*} [Star R] [Star S] [FunLike F R S] [StarHomClass F R S] [TrivialStar R] (f : F) (x : R) : IsSelfAdjoint (f x) := (IsSelfAdjoint.all x).map f section AddMonoid variable [AddMonoid R] [StarAddMonoid R] variable (R) in @[simp] protected theorem zero : IsSelfAdjoint (0 : R) := star_zero R @[aesop 90% apply] theorem add {x y : R} (hx : IsSelfAdjoint x) (hy : IsSelfAdjoint y) : IsSelfAdjoint (x + y) := by simp only [isSelfAdjoint_iff, star_add, hx.star_eq, hy.star_eq] end AddMonoid section AddGroup variable [AddGroup R] [StarAddMonoid R] @[aesop safe apply] theorem neg {x : R} (hx : IsSelfAdjoint x) : IsSelfAdjoint (-x) := by simp only [isSelfAdjoint_iff, star_neg, hx.star_eq] @[aesop 90% apply] theorem sub {x y : R} (hx : IsSelfAdjoint x) (hy : IsSelfAdjoint y) : IsSelfAdjoint (x - y) := by simp only [isSelfAdjoint_iff, star_sub, hx.star_eq, hy.star_eq] end AddGroup section AddCommMonoid variable [AddCommMonoid R] [StarAddMonoid R] @[simp] theorem add_star_self (x : R) : IsSelfAdjoint (x + star x) := by simp only [isSelfAdjoint_iff, add_comm, star_add, star_star] @[simp] theorem star_add_self (x : R) : IsSelfAdjoint (star x + x) := by simp only [isSelfAdjoint_iff, add_comm, star_add, star_star] end AddCommMonoid section Semigroup variable [Semigroup R] [StarMul R] @[aesop safe apply] theorem conjugate {x : R} (hx : IsSelfAdjoint x) (z : R) : IsSelfAdjoint (z * x * star z) := by simp only [isSelfAdjoint_iff, star_mul, star_star, mul_assoc, hx.star_eq] @[aesop safe apply] theorem conjugate' {x : R} (hx : IsSelfAdjoint x) (z : R) : IsSelfAdjoint (star z * x * z) := by simp only [isSelfAdjoint_iff, star_mul, star_star, mul_assoc, hx.star_eq] @[aesop 90% apply] theorem conjugate_self {x : R} (hx : IsSelfAdjoint x) {z : R} (hz : IsSelfAdjoint z) : IsSelfAdjoint (z * x * z) := by nth_rewrite 2 [← hz]; exact conjugate hx z @[aesop 10% apply] theorem isStarNormal {x : R} (hx : IsSelfAdjoint x) : IsStarNormal x := ⟨by simp only [Commute, SemiconjBy, hx.star_eq]⟩ end Semigroup section MulOneClass variable [MulOneClass R] [StarMul R] variable (R) @[simp] protected theorem one : IsSelfAdjoint (1 : R) := star_one R end MulOneClass section Monoid variable [Monoid R] [StarMul R] @[aesop safe apply] theorem pow {x : R} (hx : IsSelfAdjoint x) (n : ℕ) : IsSelfAdjoint (x ^ n) := by simp only [isSelfAdjoint_iff, star_pow, hx.star_eq] end Monoid section Semiring variable [Semiring R] [StarRing R] @[simp] protected theorem natCast (n : ℕ) : IsSelfAdjoint (n : R) := star_natCast _ @[simp] protected theorem ofNat (n : ℕ) [n.AtLeastTwo] : IsSelfAdjoint (ofNat(n) : R) := .natCast n end Semiring section CommSemigroup variable [CommSemigroup R] [StarMul R] theorem mul {x y : R} (hx : IsSelfAdjoint x) (hy : IsSelfAdjoint y) : IsSelfAdjoint (x * y) := by simp only [isSelfAdjoint_iff, star_mul', hx.star_eq, hy.star_eq] end CommSemigroup section CommSemiring variable {α : Type*} [CommSemiring α] [StarRing α] {a : α} open scoped ComplexConjugate lemma conj_eq (ha : IsSelfAdjoint a) : conj a = a := ha.star_eq end CommSemiring section Ring variable [Ring R] [StarRing R] @[simp] protected theorem intCast (z : ℤ) : IsSelfAdjoint (z : R) := star_intCast _ end Ring section Group variable [Group R] [StarMul R] @[aesop safe apply] theorem inv {x : R} (hx : IsSelfAdjoint x) : IsSelfAdjoint x⁻¹ := by simp only [isSelfAdjoint_iff, star_inv, hx.star_eq] @[aesop safe apply] theorem zpow {x : R} (hx : IsSelfAdjoint x) (n : ℤ) : IsSelfAdjoint (x ^ n) := by simp only [isSelfAdjoint_iff, star_zpow, hx.star_eq] end Group section GroupWithZero variable [GroupWithZero R] [StarMul R] @[aesop safe apply] theorem inv₀ {x : R} (hx : IsSelfAdjoint x) : IsSelfAdjoint x⁻¹ := by simp only [isSelfAdjoint_iff, star_inv₀, hx.star_eq] @[aesop safe apply] theorem zpow₀ {x : R} (hx : IsSelfAdjoint x) (n : ℤ) : IsSelfAdjoint (x ^ n) := by simp only [isSelfAdjoint_iff, star_zpow₀, hx.star_eq] end GroupWithZero @[simp] protected lemma nnratCast [DivisionSemiring R] [StarRing R] (q : ℚ≥0) : IsSelfAdjoint (q : R) := star_nnratCast _ section DivisionRing variable [DivisionRing R] [StarRing R] @[simp] protected theorem ratCast (x : ℚ) : IsSelfAdjoint (x : R) := star_ratCast _ end DivisionRing section Semifield variable [Semifield R] [StarRing R] theorem div {x y : R} (hx : IsSelfAdjoint x) (hy : IsSelfAdjoint y) : IsSelfAdjoint (x / y) := by simp only [isSelfAdjoint_iff, star_div₀, hx.star_eq, hy.star_eq] end Semifield section SMul @[aesop safe apply] theorem smul [Star R] [Star A] [SMul R A] [StarModule R A] {r : R} (hr : IsSelfAdjoint r) {x : A} (hx : IsSelfAdjoint x) : IsSelfAdjoint (r • x) := by simp only [isSelfAdjoint_iff, star_smul, hr.star_eq, hx.star_eq] theorem smul_iff [Monoid R] [StarMul R] [Star A] [MulAction R A] [StarModule R A] {r : R} (hr : IsSelfAdjoint r) (hu : IsUnit r) {x : A} : IsSelfAdjoint (r • x) ↔ IsSelfAdjoint x := by refine ⟨fun hrx ↦ ?_, .smul hr⟩ lift r to Rˣ using hu rw [← inv_smul_smul r x] replace hr : IsSelfAdjoint r := Units.ext hr.star_eq exact hr.inv.smul hrx end SMul end IsSelfAdjoint variable (R)
/-- The self-adjoint elements of a star additive group, as an additive subgroup. -/
Mathlib/Algebra/Star/SelfAdjoint.lean
304
305
/- Copyright (c) 2019 Sébastien Gouëzel. 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, Yury Kudryashov, Frédéric Dupuis, Heather Macbeth -/ import Mathlib.Algebra.Module.Opposite import Mathlib.Topology.Algebra.Group.Quotient import Mathlib.Topology.Algebra.Ring.Basic import Mathlib.Topology.UniformSpace.UniformEmbedding import Mathlib.LinearAlgebra.Finsupp.LinearCombination import Mathlib.LinearAlgebra.Pi import Mathlib.LinearAlgebra.Quotient.Defs /-! # Theory of topological modules We use the class `ContinuousSMul` for topological (semi) modules and topological vector spaces. -/ assert_not_exists Star.star open LinearMap (ker range) open Topology Filter Pointwise universe u v w u' section variable {R : Type*} {M : Type*} [Ring R] [TopologicalSpace R] [TopologicalSpace M] [AddCommGroup M] [Module R M] theorem ContinuousSMul.of_nhds_zero [IsTopologicalRing R] [IsTopologicalAddGroup M] (hmul : Tendsto (fun p : R × M => p.1 • p.2) (𝓝 0 ×ˢ 𝓝 0) (𝓝 0)) (hmulleft : ∀ m : M, Tendsto (fun a : R => a • m) (𝓝 0) (𝓝 0)) (hmulright : ∀ a : R, Tendsto (fun m : M => a • m) (𝓝 0) (𝓝 0)) : ContinuousSMul R M where continuous_smul := by rw [← nhds_prod_eq] at hmul refine continuous_of_continuousAt_zero₂ (AddMonoidHom.smul : R →+ M →+ M) ?_ ?_ ?_ <;> simpa [ContinuousAt] variable (R M) in omit [TopologicalSpace R] in /-- A topological module over a ring has continuous negation. This cannot be an instance, because it would cause search for `[Module ?R M]` with unknown `R`. -/ theorem ContinuousNeg.of_continuousConstSMul [ContinuousConstSMul R M] : ContinuousNeg M where continuous_neg := by simpa using continuous_const_smul (T := M) (-1 : R) end section variable {R : Type*} {M : Type*} [Ring R] [TopologicalSpace R] [TopologicalSpace M] [AddCommGroup M] [ContinuousAdd M] [Module R M] [ContinuousSMul R M] /-- If `M` is a topological module over `R` and `0` is a limit of invertible elements of `R`, then `⊤` is the only submodule of `M` with a nonempty interior. This is the case, e.g., if `R` is a nontrivially normed field. -/ theorem Submodule.eq_top_of_nonempty_interior' [NeBot (𝓝[{ x : R | IsUnit x }] 0)] (s : Submodule R M) (hs : (interior (s : Set M)).Nonempty) : s = ⊤ := by rcases hs with ⟨y, hy⟩ refine Submodule.eq_top_iff'.2 fun x => ?_ rw [mem_interior_iff_mem_nhds] at hy have : Tendsto (fun c : R => y + c • x) (𝓝[{ x : R | IsUnit x }] 0) (𝓝 (y + (0 : R) • x)) := tendsto_const_nhds.add ((tendsto_nhdsWithin_of_tendsto_nhds tendsto_id).smul tendsto_const_nhds) rw [zero_smul, add_zero] at this obtain ⟨_, hu : y + _ • _ ∈ s, u, rfl⟩ := nonempty_of_mem (inter_mem (Filter.mem_map.1 (this hy)) self_mem_nhdsWithin) have hy' : y ∈ ↑s := mem_of_mem_nhds hy rwa [s.add_mem_iff_right hy', ← Units.smul_def, s.smul_mem_iff' u] at hu variable (R M) /-- Let `R` be a topological ring such that zero is not an isolated point (e.g., a nontrivially normed field, see `NormedField.punctured_nhds_neBot`). Let `M` be a nontrivial module over `R` such that `c • x = 0` implies `c = 0 ∨ x = 0`. Then `M` has no isolated points. We formulate this using `NeBot (𝓝[≠] x)`. This lemma is not an instance because Lean would need to find `[ContinuousSMul ?m_1 M]` with unknown `?m_1`. We register this as an instance for `R = ℝ` in `Real.punctured_nhds_module_neBot`. One can also use `haveI := Module.punctured_nhds_neBot R M` in a proof. -/ theorem Module.punctured_nhds_neBot [Nontrivial M] [NeBot (𝓝[≠] (0 : R))] [NoZeroSMulDivisors R M] (x : M) : NeBot (𝓝[≠] x) := by rcases exists_ne (0 : M) with ⟨y, hy⟩ suffices Tendsto (fun c : R => x + c • y) (𝓝[≠] 0) (𝓝[≠] x) from this.neBot refine Tendsto.inf ?_ (tendsto_principal_principal.2 <| ?_) · convert tendsto_const_nhds.add ((@tendsto_id R _).smul_const y) rw [zero_smul, add_zero] · intro c hc simpa [hy] using hc end section LatticeOps variable {R M₁ M₂ : Type*} [SMul R M₁] [SMul R M₂] [u : TopologicalSpace R] {t : TopologicalSpace M₂} [ContinuousSMul R M₂] {F : Type*} [FunLike F M₁ M₂] [MulActionHomClass F R M₁ M₂] (f : F) theorem continuousSMul_induced : @ContinuousSMul R M₁ _ u (t.induced f) := let _ : TopologicalSpace M₁ := t.induced f IsInducing.continuousSMul ⟨rfl⟩ continuous_id (map_smul f _ _) end LatticeOps /-- The span of a separable subset with respect to a separable scalar ring is again separable. -/ lemma TopologicalSpace.IsSeparable.span {R M : Type*} [AddCommMonoid M] [Semiring R] [Module R M] [TopologicalSpace M] [TopologicalSpace R] [SeparableSpace R] [ContinuousAdd M] [ContinuousSMul R M] {s : Set M} (hs : IsSeparable s) : IsSeparable (Submodule.span R s : Set M) := by rw [Submodule.span_eq_iUnion_nat] refine .iUnion fun n ↦ .image ?_ ?_ · have : IsSeparable {f : Fin n → R × M | ∀ (i : Fin n), f i ∈ Set.univ ×ˢ s} := by apply isSeparable_pi (fun i ↦ .prod (.of_separableSpace Set.univ) hs) rwa [Set.univ_prod] at this · apply continuous_finset_sum _ (fun i _ ↦ ?_) exact (continuous_fst.comp (continuous_apply i)).smul (continuous_snd.comp (continuous_apply i)) namespace Submodule instance topologicalAddGroup {R M : Type*} [Ring R] [AddCommGroup M] [Module R M] [TopologicalSpace M] [IsTopologicalAddGroup M] (S : Submodule R M) : IsTopologicalAddGroup S := inferInstanceAs (IsTopologicalAddGroup S.toAddSubgroup) end Submodule section closure variable {R : Type u} {M : Type v} [Semiring R] [TopologicalSpace M] [AddCommMonoid M] [Module R M] [ContinuousConstSMul R M] theorem Submodule.mapsTo_smul_closure (s : Submodule R M) (c : R) : Set.MapsTo (c • ·) (closure s : Set M) (closure s) := have : Set.MapsTo (c • ·) (s : Set M) s := fun _ h ↦ s.smul_mem c h this.closure (continuous_const_smul c) theorem Submodule.smul_closure_subset (s : Submodule R M) (c : R) : c • closure (s : Set M) ⊆ closure (s : Set M) := (s.mapsTo_smul_closure c).image_subset variable [ContinuousAdd M] /-- The (topological-space) closure of a submodule of a topological `R`-module `M` is itself a submodule. -/ def Submodule.topologicalClosure (s : Submodule R M) : Submodule R M := { s.toAddSubmonoid.topologicalClosure with smul_mem' := s.mapsTo_smul_closure } @[simp, norm_cast] theorem Submodule.topologicalClosure_coe (s : Submodule R M) : (s.topologicalClosure : Set M) = closure (s : Set M) := rfl theorem Submodule.le_topologicalClosure (s : Submodule R M) : s ≤ s.topologicalClosure := subset_closure theorem Submodule.closure_subset_topologicalClosure_span (s : Set M) : closure s ⊆ (span R s).topologicalClosure := by rw [Submodule.topologicalClosure_coe] exact closure_mono subset_span theorem Submodule.isClosed_topologicalClosure (s : Submodule R M) : IsClosed (s.topologicalClosure : Set M) := isClosed_closure theorem Submodule.topologicalClosure_minimal (s : Submodule R M) {t : Submodule R M} (h : s ≤ t) (ht : IsClosed (t : Set M)) : s.topologicalClosure ≤ t := closure_minimal h ht theorem Submodule.topologicalClosure_mono {s : Submodule R M} {t : Submodule R M} (h : s ≤ t) : s.topologicalClosure ≤ t.topologicalClosure := closure_mono h /-- The topological closure of a closed submodule `s` is equal to `s`. -/ theorem IsClosed.submodule_topologicalClosure_eq {s : Submodule R M} (hs : IsClosed (s : Set M)) : s.topologicalClosure = s := SetLike.ext' hs.closure_eq /-- A subspace is dense iff its topological closure is the entire space. -/ theorem Submodule.dense_iff_topologicalClosure_eq_top {s : Submodule R M} : Dense (s : Set M) ↔ s.topologicalClosure = ⊤ := by rw [← SetLike.coe_set_eq, dense_iff_closure_eq] simp instance Submodule.topologicalClosure.completeSpace {M' : Type*} [AddCommMonoid M'] [Module R M'] [UniformSpace M'] [ContinuousAdd M'] [ContinuousConstSMul R M'] [CompleteSpace M'] (U : Submodule R M') : CompleteSpace U.topologicalClosure := isClosed_closure.completeSpace_coe /-- A maximal proper subspace of a topological module (i.e a `Submodule` satisfying `IsCoatom`) is either closed or dense. -/ theorem Submodule.isClosed_or_dense_of_isCoatom (s : Submodule R M) (hs : IsCoatom s) : IsClosed (s : Set M) ∨ Dense (s : Set M) := by refine (hs.le_iff.mp s.le_topologicalClosure).symm.imp ?_ dense_iff_topologicalClosure_eq_top.mpr exact fun h ↦ h ▸ isClosed_closure end closure namespace Submodule variable {ι R : Type*} {M : ι → Type*} [Semiring R] [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)] [∀ i, TopologicalSpace (M i)] [DecidableEq ι] /-- If `s i` is a family of submodules, each is in its module, then the closure of their span in the indexed product of the modules is the product of their closures. In case of a finite index type, this statement immediately follows from `Submodule.iSup_map_single`. However, the statement is true for an infinite index type as well. -/ theorem closure_coe_iSup_map_single (s : ∀ i, Submodule R (M i)) : closure (↑(⨆ i, (s i).map (LinearMap.single R M i)) : Set (∀ i, M i)) = Set.univ.pi fun i ↦ closure (s i) := by rw [← closure_pi_set] refine (closure_mono ?_).antisymm <| closure_minimal ?_ isClosed_closure · exact SetLike.coe_mono <| iSup_map_single_le · simp only [Set.subset_def, mem_closure_iff] intro x hx U hU hxU rcases isOpen_pi_iff.mp hU x hxU with ⟨t, V, hV, hVU⟩ refine ⟨∑ i ∈ t, Pi.single i (x i), hVU ?_, ?_⟩ · simp_all [Finset.sum_pi_single] · exact sum_mem fun i hi ↦ mem_iSup_of_mem i <| mem_map_of_mem <| hx _ <| Set.mem_univ _ /-- If `s i` is a family of submodules, each is in its module, then the closure of their span in the indexed product of the modules is the product of their closures. In case of a finite index type, this statement immediately follows from `Submodule.iSup_map_single`. However, the statement is true for an infinite index type as well. This version is stated in terms of `Submodule.topologicalClosure`, thus assumes that `M i`s are topological modules over `R`. However, the statement is true without assuming continuity of the operations, see `Submodule.closure_coe_iSup_map_single` above. -/ theorem topologicalClosure_iSup_map_single [∀ i, ContinuousAdd (M i)] [∀ i, ContinuousConstSMul R (M i)] (s : ∀ i, Submodule R (M i)) : topologicalClosure (⨆ i, (s i).map (LinearMap.single R M i)) = pi Set.univ fun i ↦ (s i).topologicalClosure := SetLike.coe_injective <| closure_coe_iSup_map_single _ end Submodule section Pi theorem LinearMap.continuous_on_pi {ι : Type*} {R : Type*} {M : Type*} [Finite ι] [Semiring R] [TopologicalSpace R] [AddCommMonoid M] [Module R M] [TopologicalSpace M] [ContinuousAdd M] [ContinuousSMul R M] (f : (ι → R) →ₗ[R] M) : Continuous f := by cases nonempty_fintype ι classical -- for the proof, write `f` in the standard basis, and use that each coordinate is a continuous -- function. have : (f : (ι → R) → M) = fun x => ∑ i : ι, x i • f fun j => if i = j then 1 else 0 := by ext x exact f.pi_apply_eq_sum_univ x rw [this] refine continuous_finset_sum _ fun i _ => ?_ exact (continuous_apply i).smul continuous_const end Pi section PointwiseLimits variable {M₁ M₂ α R S : Type*} [TopologicalSpace M₂] [T2Space M₂] [Semiring R] [Semiring S] [AddCommMonoid M₁] [AddCommMonoid M₂] [Module R M₁] [Module S M₂] [ContinuousConstSMul S M₂] variable [ContinuousAdd M₂] {σ : R →+* S} {l : Filter α} /-- Constructs a bundled linear map from a function and a proof that this function belongs to the closure of the set of linear maps. -/ @[simps -fullyApplied] def linearMapOfMemClosureRangeCoe (f : M₁ → M₂) (hf : f ∈ closure (Set.range ((↑) : (M₁ →ₛₗ[σ] M₂) → M₁ → M₂))) : M₁ →ₛₗ[σ] M₂ := { addMonoidHomOfMemClosureRangeCoe f hf with map_smul' := (isClosed_setOf_map_smul M₁ M₂ σ).closure_subset_iff.2 (Set.range_subset_iff.2 LinearMap.map_smulₛₗ) hf } /-- Construct a bundled linear map from a pointwise limit of linear maps -/ @[simps! -fullyApplied] def linearMapOfTendsto (f : M₁ → M₂) (g : α → M₁ →ₛₗ[σ] M₂) [l.NeBot] (h : Tendsto (fun a x => g a x) l (𝓝 f)) : M₁ →ₛₗ[σ] M₂ := linearMapOfMemClosureRangeCoe f <| mem_closure_of_tendsto h <| Eventually.of_forall fun _ => Set.mem_range_self _ variable (M₁ M₂ σ) theorem LinearMap.isClosed_range_coe : IsClosed (Set.range ((↑) : (M₁ →ₛₗ[σ] M₂) → M₁ → M₂)) := isClosed_of_closure_subset fun f hf => ⟨linearMapOfMemClosureRangeCoe f hf, rfl⟩ end PointwiseLimits section Quotient namespace Submodule variable {R M : Type*} [Ring R] [AddCommGroup M] [Module R M] [TopologicalSpace M] (S : Submodule R M) instance _root_.QuotientModule.Quotient.topologicalSpace : TopologicalSpace (M ⧸ S) := inferInstanceAs (TopologicalSpace (Quotient S.quotientRel)) theorem isOpenMap_mkQ [ContinuousAdd M] : IsOpenMap S.mkQ := QuotientAddGroup.isOpenMap_coe theorem isOpenQuotientMap_mkQ [ContinuousAdd M] : IsOpenQuotientMap S.mkQ := QuotientAddGroup.isOpenQuotientMap_mk instance topologicalAddGroup_quotient [IsTopologicalAddGroup M] : IsTopologicalAddGroup (M ⧸ S) := inferInstanceAs <| IsTopologicalAddGroup (M ⧸ S.toAddSubgroup) instance continuousSMul_quotient [TopologicalSpace R] [IsTopologicalAddGroup M] [ContinuousSMul R M] : ContinuousSMul R (M ⧸ S) where continuous_smul := by rw [← (IsOpenQuotientMap.id.prodMap S.isOpenQuotientMap_mkQ).continuous_comp_iff] exact continuous_quot_mk.comp continuous_smul instance t3_quotient_of_isClosed [IsTopologicalAddGroup M] [IsClosed (S : Set M)] : T3Space (M ⧸ S) := letI : IsClosed (S.toAddSubgroup : Set M) := ‹_› QuotientAddGroup.instT3Space S.toAddSubgroup end Submodule end Quotient
Mathlib/Topology/Algebra/Module/Basic.lean
1,530
1,535
/- Copyright (c) 2018 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Johannes Hölzl, Yaël Dillies -/ import Mathlib.Algebra.Group.PUnit import Mathlib.Algebra.Group.ULift import Mathlib.Analysis.Normed.Group.Basic /-! # Product of normed groups and other constructions This file constructs the infinity norm on finite products of normed groups and provides instances for type synonyms. -/ open NNReal variable {ι E F : Type*} {G : ι → Type*} /-! ### `PUnit` -/ namespace PUnit instance normedAddCommGroup : NormedAddCommGroup PUnit where norm := Function.const _ 0 dist_eq _ _ := rfl @[simp] lemma norm_eq_zero (x : PUnit) : ‖x‖ = 0 := rfl end PUnit /-! ### `ULift` -/ namespace ULift section Norm variable [Norm E] instance norm : Norm (ULift E) where norm x := ‖x.down‖ lemma norm_def (x : ULift E) : ‖x‖ = ‖x.down‖ := rfl @[simp] lemma norm_up (x : E) : ‖ULift.up x‖ = ‖x‖ := rfl @[simp] lemma norm_down (x : ULift E) : ‖x.down‖ = ‖x‖ := rfl end Norm section NNNorm variable [NNNorm E] instance nnnorm : NNNorm (ULift E) where nnnorm x := ‖x.down‖₊ lemma nnnorm_def (x : ULift E) : ‖x‖₊ = ‖x.down‖₊ := rfl @[simp] lemma nnnorm_up (x : E) : ‖ULift.up x‖₊ = ‖x‖₊ := rfl @[simp] lemma nnnorm_down (x : ULift E) : ‖x.down‖₊ = ‖x‖₊ := rfl end NNNorm @[to_additive] instance seminormedGroup [SeminormedGroup E] : SeminormedGroup (ULift E) := SeminormedGroup.induced _ _ { toFun := ULift.down, map_one' := rfl, map_mul' := fun _ _ => rfl : ULift E →* E } @[to_additive] instance seminormedCommGroup [SeminormedCommGroup E] : SeminormedCommGroup (ULift E) := SeminormedCommGroup.induced _ _ { toFun := ULift.down, map_one' := rfl, map_mul' := fun _ _ => rfl : ULift E →* E } @[to_additive] instance normedGroup [NormedGroup E] : NormedGroup (ULift E) := NormedGroup.induced _ _ { toFun := ULift.down, map_one' := rfl, map_mul' := fun _ _ => rfl : ULift E →* E } down_injective @[to_additive] instance normedCommGroup [NormedCommGroup E] : NormedCommGroup (ULift E) := NormedCommGroup.induced _ _ { toFun := ULift.down, map_one' := rfl, map_mul' := fun _ _ => rfl : ULift E →* E } down_injective end ULift /-! ### `Additive`, `Multiplicative` -/ section AdditiveMultiplicative open Additive Multiplicative section Norm variable [Norm E] instance Additive.toNorm : Norm (Additive E) := ‹Norm E› instance Multiplicative.toNorm : Norm (Multiplicative E) := ‹Norm E› @[simp] lemma norm_toMul (x : Additive E) : ‖(x.toMul : E)‖ = ‖x‖ := rfl @[simp] lemma norm_ofMul (x : E) : ‖ofMul x‖ = ‖x‖ := rfl @[simp] lemma norm_toAdd (x : Multiplicative E) : ‖(x.toAdd : E)‖ = ‖x‖ := rfl @[simp] lemma norm_ofAdd (x : E) : ‖ofAdd x‖ = ‖x‖ := rfl end Norm section NNNorm variable [NNNorm E] instance Additive.toNNNorm : NNNorm (Additive E) := ‹NNNorm E› instance Multiplicative.toNNNorm : NNNorm (Multiplicative E) := ‹NNNorm E› @[simp] lemma nnnorm_toMul (x : Additive E) : ‖(x.toMul : E)‖₊ = ‖x‖₊ := rfl @[simp] lemma nnnorm_ofMul (x : E) : ‖ofMul x‖₊ = ‖x‖₊ := rfl @[simp] lemma nnnorm_toAdd (x : Multiplicative E) : ‖(x.toAdd : E)‖₊ = ‖x‖₊ := rfl @[simp] lemma nnnorm_ofAdd (x : E) : ‖ofAdd x‖₊ = ‖x‖₊ := rfl end NNNorm instance Additive.seminormedAddGroup [SeminormedGroup E] : SeminormedAddGroup (Additive E) where dist_eq x y := dist_eq_norm_div x.toMul y.toMul instance Multiplicative.seminormedGroup [SeminormedAddGroup E] : SeminormedGroup (Multiplicative E) where dist_eq x y := dist_eq_norm_sub x.toAdd y.toAdd instance Additive.seminormedCommGroup [SeminormedCommGroup E] : SeminormedAddCommGroup (Additive E) := { Additive.seminormedAddGroup with add_comm := add_comm } instance Multiplicative.seminormedAddCommGroup [SeminormedAddCommGroup E] : SeminormedCommGroup (Multiplicative E) := { Multiplicative.seminormedGroup with mul_comm := mul_comm } instance Additive.normedAddGroup [NormedGroup E] : NormedAddGroup (Additive E) := { Additive.seminormedAddGroup with eq_of_dist_eq_zero := eq_of_dist_eq_zero } instance Multiplicative.normedGroup [NormedAddGroup E] : NormedGroup (Multiplicative E) := { Multiplicative.seminormedGroup with eq_of_dist_eq_zero := eq_of_dist_eq_zero } instance Additive.normedAddCommGroup [NormedCommGroup E] : NormedAddCommGroup (Additive E) := { Additive.seminormedAddGroup with add_comm := add_comm eq_of_dist_eq_zero := eq_of_dist_eq_zero } instance Multiplicative.normedCommGroup [NormedAddCommGroup E] : NormedCommGroup (Multiplicative E) := { Multiplicative.seminormedGroup with mul_comm := mul_comm eq_of_dist_eq_zero := eq_of_dist_eq_zero } end AdditiveMultiplicative /-! ### Order dual -/ section OrderDual open OrderDual section Norm variable [Norm E] instance OrderDual.toNorm : Norm Eᵒᵈ := ‹Norm E› @[simp] lemma norm_toDual (x : E) : ‖toDual x‖ = ‖x‖ := rfl @[simp] lemma norm_ofDual (x : Eᵒᵈ) : ‖ofDual x‖ = ‖x‖ := rfl end Norm section NNNorm variable [NNNorm E] instance OrderDual.toNNNorm : NNNorm Eᵒᵈ := ‹NNNorm E› @[simp] lemma nnnorm_toDual (x : E) : ‖toDual x‖₊ = ‖x‖₊ := rfl @[simp] lemma nnnorm_ofDual (x : Eᵒᵈ) : ‖ofDual x‖₊ = ‖x‖₊ := rfl end NNNorm namespace OrderDual -- See note [lower instance priority] @[to_additive] instance (priority := 100) seminormedGroup [SeminormedGroup E] : SeminormedGroup Eᵒᵈ := ‹SeminormedGroup E› -- See note [lower instance priority] @[to_additive] instance (priority := 100) seminormedCommGroup [SeminormedCommGroup E] : SeminormedCommGroup Eᵒᵈ := ‹SeminormedCommGroup E› -- See note [lower instance priority] @[to_additive] instance (priority := 100) normedGroup [NormedGroup E] : NormedGroup Eᵒᵈ := ‹NormedGroup E› -- See note [lower instance priority] @[to_additive] instance (priority := 100) normedCommGroup [NormedCommGroup E] : NormedCommGroup Eᵒᵈ := ‹NormedCommGroup E› end OrderDual end OrderDual /-! ### Binary product of normed groups -/ section Norm variable [Norm E] [Norm F] {x : E × F} {r : ℝ} instance Prod.toNorm : Norm (E × F) where norm x := ‖x.1‖ ⊔ ‖x.2‖ lemma Prod.norm_def (x : E × F) : ‖x‖ = max ‖x.1‖ ‖x.2‖ := rfl @[simp] lemma Prod.norm_mk (x : E) (y : F) : ‖(x, y)‖ = max ‖x‖ ‖y‖ := rfl lemma norm_fst_le (x : E × F) : ‖x.1‖ ≤ ‖x‖ := le_max_left _ _ lemma norm_snd_le (x : E × F) : ‖x.2‖ ≤ ‖x‖ := le_max_right _ _ lemma norm_prod_le_iff : ‖x‖ ≤ r ↔ ‖x.1‖ ≤ r ∧ ‖x.2‖ ≤ r := max_le_iff end Norm section SeminormedGroup variable [SeminormedGroup E] [SeminormedGroup F] /-- Product of seminormed groups, using the sup norm. -/ @[to_additive "Product of seminormed groups, using the sup norm."] instance Prod.seminormedGroup : SeminormedGroup (E × F) where dist_eq x y := by simp only [Prod.norm_def, Prod.dist_eq, dist_eq_norm_div, Prod.fst_div, Prod.snd_div] /-- Multiplicative version of `Prod.nnnorm_def`. Earlier, this names was used for the additive version. -/ @[to_additive Prod.nnnorm_def] lemma Prod.nnnorm_def' (x : E × F) : ‖x‖₊ = max ‖x.1‖₊ ‖x.2‖₊ := rfl @[deprecated (since := "2025-01-02")] alias Prod.nnorm_def := Prod.nnnorm_def' /-- Multiplicative version of `Prod.nnnorm_mk`. -/ @[to_additive (attr := simp) Prod.nnnorm_mk] lemma Prod.nnnorm_mk' (x : E) (y : F) : ‖(x, y)‖₊ = max ‖x‖₊ ‖y‖₊ := rfl end SeminormedGroup namespace Prod /-- Product of seminormed groups, using the sup norm. -/ @[to_additive "Product of seminormed groups, using the sup norm."] instance seminormedCommGroup [SeminormedCommGroup E] [SeminormedCommGroup F] : SeminormedCommGroup (E × F) := { Prod.seminormedGroup with mul_comm := mul_comm } /-- Product of normed groups, using the sup norm. -/ @[to_additive "Product of normed groups, using the sup norm."] instance normedGroup [NormedGroup E] [NormedGroup F] : NormedGroup (E × F) := { Prod.seminormedGroup with eq_of_dist_eq_zero := eq_of_dist_eq_zero } /-- Product of normed groups, using the sup norm. -/ @[to_additive "Product of normed groups, using the sup norm."] instance normedCommGroup [NormedCommGroup E] [NormedCommGroup F] : NormedCommGroup (E × F) := { Prod.seminormedGroup with mul_comm := mul_comm eq_of_dist_eq_zero := eq_of_dist_eq_zero } end Prod /-! ### Finite product of normed groups -/ section Pi variable [Fintype ι] section SeminormedGroup variable [∀ i, SeminormedGroup (G i)] [SeminormedGroup E] (f : ∀ i, G i) {x : ∀ i, G i} {r : ℝ} /-- Finite product of seminormed groups, using the sup norm. -/ @[to_additive "Finite product of seminormed groups, using the sup norm."] instance Pi.seminormedGroup : SeminormedGroup (∀ i, G i) where norm f := ↑(Finset.univ.sup fun b => ‖f b‖₊) dist_eq x y := congr_arg (toReal : ℝ≥0 → ℝ) <| congr_arg (Finset.sup Finset.univ) <| funext fun a => show nndist (x a) (y a) = ‖x a / y a‖₊ from nndist_eq_nnnorm_div (x a) (y a) @[to_additive Pi.norm_def] lemma Pi.norm_def' : ‖f‖ = ↑(Finset.univ.sup fun b => ‖f b‖₊) := rfl @[to_additive Pi.nnnorm_def] lemma Pi.nnnorm_def' : ‖f‖₊ = Finset.univ.sup fun b => ‖f b‖₊ := Subtype.eta _ _ /-- The seminorm of an element in a product space is `≤ r` if and only if the norm of each component is. -/ @[to_additive pi_norm_le_iff_of_nonneg "The seminorm of an element in a product space is `≤ r` if and only if the norm of each component is."] lemma pi_norm_le_iff_of_nonneg' (hr : 0 ≤ r) : ‖x‖ ≤ r ↔ ∀ i, ‖x i‖ ≤ r := by simp only [← dist_one_right, dist_pi_le_iff hr, Pi.one_apply] @[to_additive pi_nnnorm_le_iff] lemma pi_nnnorm_le_iff' {r : ℝ≥0} : ‖x‖₊ ≤ r ↔ ∀ i, ‖x i‖₊ ≤ r := pi_norm_le_iff_of_nonneg' r.coe_nonneg @[to_additive pi_norm_le_iff_of_nonempty] lemma pi_norm_le_iff_of_nonempty' [Nonempty ι] : ‖f‖ ≤ r ↔ ∀ b, ‖f b‖ ≤ r := by by_cases hr : 0 ≤ r · exact pi_norm_le_iff_of_nonneg' hr · exact iff_of_false (fun h => hr <| (norm_nonneg' _).trans h) fun h => hr <| (norm_nonneg' _).trans <| h <| Classical.arbitrary _ /-- The seminorm of an element in a product space is `< r` if and only if the norm of each component is. -/ @[to_additive pi_norm_lt_iff "The seminorm of an element in a product space is `< r` if and only if the norm of each component is."] lemma pi_norm_lt_iff' (hr : 0 < r) : ‖x‖ < r ↔ ∀ i, ‖x i‖ < r := by simp only [← dist_one_right, dist_pi_lt_iff hr, Pi.one_apply] @[to_additive pi_nnnorm_lt_iff] lemma pi_nnnorm_lt_iff' {r : ℝ≥0} (hr : 0 < r) : ‖x‖₊ < r ↔ ∀ i, ‖x i‖₊ < r := pi_norm_lt_iff' hr @[to_additive norm_le_pi_norm] lemma norm_le_pi_norm' (i : ι) : ‖f i‖ ≤ ‖f‖ := (pi_norm_le_iff_of_nonneg' <| norm_nonneg' _).1 le_rfl i @[to_additive nnnorm_le_pi_nnnorm] lemma nnnorm_le_pi_nnnorm' (i : ι) : ‖f i‖₊ ≤ ‖f‖₊ := norm_le_pi_norm' _ i @[to_additive pi_norm_const_le] lemma pi_norm_const_le' (a : E) : ‖fun _ : ι => a‖ ≤ ‖a‖ := (pi_norm_le_iff_of_nonneg' <| norm_nonneg' _).2 fun _ => le_rfl @[to_additive pi_nnnorm_const_le] lemma pi_nnnorm_const_le' (a : E) : ‖fun _ : ι => a‖₊ ≤ ‖a‖₊ := pi_norm_const_le' _ @[to_additive (attr := simp) pi_norm_const] lemma pi_norm_const' [Nonempty ι] (a : E) : ‖fun _i : ι => a‖ = ‖a‖ := by simpa only [← dist_one_right] using dist_pi_const a 1 @[to_additive (attr := simp) pi_nnnorm_const] lemma pi_nnnorm_const' [Nonempty ι] (a : E) : ‖fun _i : ι => a‖₊ = ‖a‖₊ :=
NNReal.eq <| pi_norm_const' a /-- The $L^1$ norm is less than the $L^\infty$ norm scaled by the cardinality. -/ @[to_additive Pi.sum_norm_apply_le_norm "The $L^1$ norm is less than the $L^\\infty$ norm scaled by the cardinality."] lemma Pi.sum_norm_apply_le_norm' : ∑ i, ‖f i‖ ≤ Fintype.card ι • ‖f‖ :=
Mathlib/Analysis/Normed/Group/Constructions.lean
363
368
/- Copyright (c) 2022 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.Analysis.SpecialFunctions.Log.Basic import Mathlib.Data.Nat.Cast.Field import Mathlib.NumberTheory.ArithmeticFunction /-! # The von Mangoldt Function In this file we define the von Mangoldt function: the function on natural numbers that returns `log p` if the input can be expressed as `p^k` for a prime `p`. ## Main Results The main definition for this file is - `ArithmeticFunction.vonMangoldt`: The von Mangoldt function `Λ`. We then prove the classical summation property of the von Mangoldt function in `ArithmeticFunction.vonMangoldt_sum`, that `∑ i ∈ n.divisors, Λ i = Real.log n`, and use this to deduce alternative expressions for the von Mangoldt function via Möbius inversion, see `ArithmeticFunction.sum_moebius_mul_log_eq`. ## Notation We use the standard notation `Λ` to represent the von Mangoldt function. It is accessible in the locales `ArithmeticFunction` (like the notations for other arithmetic functions) and also in the locale `ArithmeticFunction.vonMangoldt`. -/ namespace ArithmeticFunction open Finset Nat open scoped ArithmeticFunction /-- `log` as an arithmetic function `ℕ → ℝ`. Note this is in the `ArithmeticFunction` namespace to indicate that it is bundled as an `ArithmeticFunction` rather than being the usual real logarithm. -/ noncomputable def log : ArithmeticFunction ℝ := ⟨fun n => Real.log n, by simp⟩ @[simp] theorem log_apply {n : ℕ} : log n = Real.log n := rfl /-- The `vonMangoldt` function is the function on natural numbers that returns `log p` if the input can be expressed as `p^k` for a prime `p`. In the case when `n` is a prime power, `Nat.minFac` will give the appropriate prime, as it is the smallest prime factor. In the `ArithmeticFunction` locale, we have the notation `Λ` for this function. This is also available in the `ArithmeticFunction.vonMangoldt` locale, allowing for selective access to the notation. -/ noncomputable def vonMangoldt : ArithmeticFunction ℝ := ⟨fun n => if IsPrimePow n then Real.log (minFac n) else 0, if_neg not_isPrimePow_zero⟩ @[inherit_doc] scoped[ArithmeticFunction] notation "Λ" => ArithmeticFunction.vonMangoldt @[inherit_doc] scoped[ArithmeticFunction.vonMangoldt] notation "Λ" => ArithmeticFunction.vonMangoldt theorem vonMangoldt_apply {n : ℕ} : Λ n = if IsPrimePow n then Real.log (minFac n) else 0 := rfl @[simp] theorem vonMangoldt_apply_one : Λ 1 = 0 := by simp [vonMangoldt_apply] @[simp] theorem vonMangoldt_nonneg {n : ℕ} : 0 ≤ Λ n := by rw [vonMangoldt_apply] split_ifs · exact Real.log_nonneg (one_le_cast.2 (Nat.minFac_pos n)) rfl theorem vonMangoldt_apply_pow {n k : ℕ} (hk : k ≠ 0) : Λ (n ^ k) = Λ n := by simp only [vonMangoldt_apply, isPrimePow_pow_iff hk, pow_minFac hk] theorem vonMangoldt_apply_prime {p : ℕ} (hp : p.Prime) : Λ p = Real.log p := by rw [vonMangoldt_apply, Prime.minFac_eq hp, if_pos hp.prime.isPrimePow] theorem vonMangoldt_ne_zero_iff {n : ℕ} : Λ n ≠ 0 ↔ IsPrimePow n := by rcases eq_or_ne n 1 with (rfl | hn); · simp [not_isPrimePow_one] exact (Real.log_pos (one_lt_cast.2 (minFac_prime hn).one_lt)).ne'.ite_ne_right_iff theorem vonMangoldt_pos_iff {n : ℕ} : 0 < Λ n ↔ IsPrimePow n := vonMangoldt_nonneg.lt_iff_ne.trans (ne_comm.trans vonMangoldt_ne_zero_iff) theorem vonMangoldt_eq_zero_iff {n : ℕ} : Λ n = 0 ↔ ¬IsPrimePow n := vonMangoldt_ne_zero_iff.not_right theorem vonMangoldt_sum {n : ℕ} : ∑ i ∈ n.divisors, Λ i = Real.log n := by refine recOnPrimeCoprime ?_ ?_ ?_ n · simp · intro p k hp rw [sum_divisors_prime_pow hp, cast_pow, Real.log_pow, Finset.sum_range_succ', Nat.pow_zero, vonMangoldt_apply_one] simp [vonMangoldt_apply_pow (Nat.succ_ne_zero _), vonMangoldt_apply_prime hp] intro a b ha' hb' hab ha hb simp only [vonMangoldt_apply, ← sum_filter] at ha hb ⊢ rw [mul_divisors_filter_prime_pow hab, filter_union, sum_union (disjoint_divisors_filter_isPrimePow hab), ha, hb, Nat.cast_mul, Real.log_mul (cast_ne_zero.2 (pos_of_gt ha').ne') (cast_ne_zero.2 (pos_of_gt hb').ne')]
@[simp] theorem vonMangoldt_mul_zeta : Λ * ζ = log := by ext n; rw [coe_mul_zeta_apply, vonMangoldt_sum]; rfl @[simp] theorem zeta_mul_vonMangoldt : (ζ : ArithmeticFunction ℝ) * Λ = log := by rw [mul_comm]; simp @[simp] theorem log_mul_moebius_eq_vonMangoldt : log * μ = Λ := by rw [← vonMangoldt_mul_zeta, mul_assoc, coe_zeta_mul_coe_moebius, mul_one] @[simp]
Mathlib/NumberTheory/VonMangoldt.lean
111
122
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Ken Lee, Chris Hughes -/ import Mathlib.Algebra.Group.Action.Units import Mathlib.Algebra.Group.Nat.Units import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Algebra.Ring.Divisibility.Basic import Mathlib.Algebra.Ring.Hom.Defs import Mathlib.Logic.Basic import Mathlib.Tactic.Ring /-! # Coprime elements of a ring or monoid ## Main definition * `IsCoprime x y`: that `x` and `y` are coprime, defined to be the existence of `a` and `b` such that `a * x + b * y = 1`. Note that elements with no common divisors (`IsRelPrime`) are not necessarily coprime, e.g., the multivariate polynomials `x₁` and `x₂` are not coprime. The two notions are equivalent in Bézout rings, see `isRelPrime_iff_isCoprime`. This file also contains lemmas about `IsRelPrime` parallel to `IsCoprime`. See also `RingTheory.Coprime.Lemmas` for further development of coprime elements. -/ universe u v section CommSemiring variable {R : Type u} [CommSemiring R] (x y z : R) /-- The proposition that `x` and `y` are coprime, defined to be the existence of `a` and `b` such that `a * x + b * y = 1`. Note that elements with no common divisors are not necessarily coprime, e.g., the multivariate polynomials `x₁` and `x₂` are not coprime. -/ def IsCoprime : Prop := ∃ a b, a * x + b * y = 1 variable {x y z} @[symm] theorem IsCoprime.symm (H : IsCoprime x y) : IsCoprime y x := let ⟨a, b, H⟩ := H ⟨b, a, by rw [add_comm, H]⟩ theorem isCoprime_comm : IsCoprime x y ↔ IsCoprime y x := ⟨IsCoprime.symm, IsCoprime.symm⟩ theorem isCoprime_self : IsCoprime x x ↔ IsUnit x := ⟨fun ⟨a, b, h⟩ => isUnit_of_mul_eq_one x (a + b) <| by rwa [mul_comm, add_mul], fun h => let ⟨b, hb⟩ := isUnit_iff_exists_inv'.1 h ⟨b, 0, by rwa [zero_mul, add_zero]⟩⟩ theorem isCoprime_zero_left : IsCoprime 0 x ↔ IsUnit x := ⟨fun ⟨a, b, H⟩ => isUnit_of_mul_eq_one x b <| by rwa [mul_zero, zero_add, mul_comm] at H, fun H => let ⟨b, hb⟩ := isUnit_iff_exists_inv'.1 H ⟨1, b, by rwa [one_mul, zero_add]⟩⟩ theorem isCoprime_zero_right : IsCoprime x 0 ↔ IsUnit x := isCoprime_comm.trans isCoprime_zero_left theorem not_isCoprime_zero_zero [Nontrivial R] : ¬IsCoprime (0 : R) 0 := mt isCoprime_zero_right.mp not_isUnit_zero lemma IsCoprime.intCast {R : Type*} [CommRing R] {a b : ℤ} (h : IsCoprime a b) : IsCoprime (a : R) (b : R) := by rcases h with ⟨u, v, H⟩ use u, v rw_mod_cast [H] exact Int.cast_one /-- If a 2-vector `p` satisfies `IsCoprime (p 0) (p 1)`, then `p ≠ 0`. -/ theorem IsCoprime.ne_zero [Nontrivial R] {p : Fin 2 → R} (h : IsCoprime (p 0) (p 1)) : p ≠ 0 := by rintro rfl exact not_isCoprime_zero_zero h theorem IsCoprime.ne_zero_or_ne_zero [Nontrivial R] (h : IsCoprime x y) : x ≠ 0 ∨ y ≠ 0 := by apply not_or_of_imp rintro rfl rfl exact not_isCoprime_zero_zero h theorem isCoprime_one_left : IsCoprime 1 x := ⟨1, 0, by rw [one_mul, zero_mul, add_zero]⟩ theorem isCoprime_one_right : IsCoprime x 1 := ⟨0, 1, by rw [one_mul, zero_mul, zero_add]⟩ theorem IsCoprime.dvd_of_dvd_mul_right (H1 : IsCoprime x z) (H2 : x ∣ y * z) : x ∣ y := by let ⟨a, b, H⟩ := H1 rw [← mul_one y, ← H, mul_add, ← mul_assoc, mul_left_comm] exact dvd_add (dvd_mul_left _ _) (H2.mul_left _) theorem IsCoprime.dvd_of_dvd_mul_left (H1 : IsCoprime x y) (H2 : x ∣ y * z) : x ∣ z := by let ⟨a, b, H⟩ := H1 rw [← one_mul z, ← H, add_mul, mul_right_comm, mul_assoc b] exact dvd_add (dvd_mul_left _ _) (H2.mul_left _) theorem IsCoprime.mul_left (H1 : IsCoprime x z) (H2 : IsCoprime y z) : IsCoprime (x * y) z := let ⟨a, b, h1⟩ := H1 let ⟨c, d, h2⟩ := H2 ⟨a * c, a * x * d + b * c * y + b * d * z, calc a * c * (x * y) + (a * x * d + b * c * y + b * d * z) * z _ = (a * x + b * z) * (c * y + d * z) := by ring _ = 1 := by rw [h1, h2, mul_one] ⟩ theorem IsCoprime.mul_right (H1 : IsCoprime x y) (H2 : IsCoprime x z) : IsCoprime x (y * z) := by rw [isCoprime_comm] at H1 H2 ⊢ exact H1.mul_left H2 theorem IsCoprime.mul_dvd (H : IsCoprime x y) (H1 : x ∣ z) (H2 : y ∣ z) : x * y ∣ z := by obtain ⟨a, b, h⟩ := H rw [← mul_one z, ← h, mul_add] apply dvd_add · rw [mul_comm z, mul_assoc] exact (mul_dvd_mul_left _ H2).mul_left _ · rw [mul_comm b, ← mul_assoc] exact (mul_dvd_mul_right H1 _).mul_right _ theorem IsCoprime.of_mul_left_left (H : IsCoprime (x * y) z) : IsCoprime x z := let ⟨a, b, h⟩ := H ⟨a * y, b, by rwa [mul_right_comm, mul_assoc]⟩ theorem IsCoprime.of_mul_left_right (H : IsCoprime (x * y) z) : IsCoprime y z := by rw [mul_comm] at H exact H.of_mul_left_left theorem IsCoprime.of_mul_right_left (H : IsCoprime x (y * z)) : IsCoprime x y := by rw [isCoprime_comm] at H ⊢ exact H.of_mul_left_left theorem IsCoprime.of_mul_right_right (H : IsCoprime x (y * z)) : IsCoprime x z := by rw [mul_comm] at H exact H.of_mul_right_left
theorem IsCoprime.mul_left_iff : IsCoprime (x * y) z ↔ IsCoprime x z ∧ IsCoprime y z := ⟨fun H => ⟨H.of_mul_left_left, H.of_mul_left_right⟩, fun ⟨H1, H2⟩ => H1.mul_left H2⟩
Mathlib/RingTheory/Coprime/Basic.lean
139
141
/- Copyright (c) 2021 Shing Tak Lam. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Shing Tak Lam -/ import Mathlib.Topology.Homotopy.Basic import Mathlib.Topology.Connected.PathConnected import Mathlib.Analysis.Convex.Basic /-! # Homotopy between paths In this file, we define a `Homotopy` between two `Path`s. In addition, we define a relation `Homotopic` on `Path`s, and prove that it is an equivalence relation. ## Definitions * `Path.Homotopy p₀ p₁` is the type of homotopies between paths `p₀` and `p₁` * `Path.Homotopy.refl p` is the constant homotopy between `p` and itself * `Path.Homotopy.symm F` is the `Path.Homotopy p₁ p₀` defined by reversing the homotopy * `Path.Homotopy.trans F G`, where `F : Path.Homotopy p₀ p₁`, `G : Path.Homotopy p₁ p₂` is the `Path.Homotopy p₀ p₂` defined by putting the first homotopy on `[0, 1/2]` and the second on `[1/2, 1]` * `Path.Homotopy.hcomp F G`, where `F : Path.Homotopy p₀ q₀` and `G : Path.Homotopy p₁ q₁` is a `Path.Homotopy (p₀.trans p₁) (q₀.trans q₁)` * `Path.Homotopic p₀ p₁` is the relation saying that there is a homotopy between `p₀` and `p₁` * `Path.Homotopic.setoid x₀ x₁` is the setoid on `Path`s from `Path.Homotopic` * `Path.Homotopic.Quotient x₀ x₁` is the quotient type from `Path x₀ x₀` by `Path.Homotopic.setoid` -/ universe u v variable {X : Type u} {Y : Type v} [TopologicalSpace X] [TopologicalSpace Y] variable {x₀ x₁ x₂ x₃ : X} noncomputable section open unitInterval namespace Path /-- The type of homotopies between two paths. -/ abbrev Homotopy (p₀ p₁ : Path x₀ x₁) := ContinuousMap.HomotopyRel p₀.toContinuousMap p₁.toContinuousMap {0, 1} namespace Homotopy section variable {p₀ p₁ : Path x₀ x₁} theorem coeFn_injective : @Function.Injective (Homotopy p₀ p₁) (I × I → X) (⇑) := DFunLike.coe_injective @[simp] theorem source (F : Homotopy p₀ p₁) (t : I) : F (t, 0) = x₀ := calc F (t, 0) = p₀ 0 := ContinuousMap.HomotopyRel.eq_fst _ _ (.inl rfl) _ = x₀ := p₀.source @[simp] theorem target (F : Homotopy p₀ p₁) (t : I) : F (t, 1) = x₁ := calc F (t, 1) = p₀ 1 := ContinuousMap.HomotopyRel.eq_fst _ _ (.inr rfl) _ = x₁ := p₀.target /-- Evaluating a path homotopy at an intermediate point, giving us a `Path`. -/ def eval (F : Homotopy p₀ p₁) (t : I) : Path x₀ x₁ where toFun := F.toHomotopy.curry t source' := by simp target' := by simp @[simp] theorem eval_zero (F : Homotopy p₀ p₁) : F.eval 0 = p₀ := by ext t simp [eval] @[simp] theorem eval_one (F : Homotopy p₀ p₁) : F.eval 1 = p₁ := by ext t simp [eval] end section variable {p₀ p₁ p₂ : Path x₀ x₁} /-- Given a path `p`, we can define a `Homotopy p p` by `F (t, x) = p x`. -/ @[simps!] def refl (p : Path x₀ x₁) : Homotopy p p := ContinuousMap.HomotopyRel.refl p.toContinuousMap {0, 1} /-- Given a `Homotopy p₀ p₁`, we can define a `Homotopy p₁ p₀` by reversing the homotopy. -/ @[simps!] def symm (F : Homotopy p₀ p₁) : Homotopy p₁ p₀ := ContinuousMap.HomotopyRel.symm F @[simp] theorem symm_symm (F : Homotopy p₀ p₁) : F.symm.symm = F := ContinuousMap.HomotopyRel.symm_symm F theorem symm_bijective : Function.Bijective (Homotopy.symm : Homotopy p₀ p₁ → Homotopy p₁ p₀) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ /-- Given `Homotopy p₀ p₁` and `Homotopy p₁ p₂`, we can define a `Homotopy p₀ p₂` by putting the first homotopy on `[0, 1/2]` and the second on `[1/2, 1]`. -/ def trans (F : Homotopy p₀ p₁) (G : Homotopy p₁ p₂) : Homotopy p₀ p₂ := ContinuousMap.HomotopyRel.trans F G theorem trans_apply (F : Homotopy p₀ p₁) (G : Homotopy p₁ p₂) (x : I × I) : (F.trans G) x = if h : (x.1 : ℝ) ≤ 1 / 2 then F (⟨2 * x.1, (unitInterval.mul_pos_mem_iff zero_lt_two).2 ⟨x.1.2.1, h⟩⟩, x.2) else G (⟨2 * x.1 - 1, unitInterval.two_mul_sub_one_mem_iff.2 ⟨(not_le.1 h).le, x.1.2.2⟩⟩, x.2) := ContinuousMap.HomotopyRel.trans_apply _ _ _ theorem symm_trans (F : Homotopy p₀ p₁) (G : Homotopy p₁ p₂) : (F.trans G).symm = G.symm.trans F.symm := ContinuousMap.HomotopyRel.symm_trans _ _ /-- Casting a `Homotopy p₀ p₁` to a `Homotopy q₀ q₁` where `p₀ = q₀` and `p₁ = q₁`. -/ @[simps!] def cast {p₀ p₁ q₀ q₁ : Path x₀ x₁} (F : Homotopy p₀ p₁) (h₀ : p₀ = q₀) (h₁ : p₁ = q₁) : Homotopy q₀ q₁ := ContinuousMap.HomotopyRel.cast F (congr_arg _ h₀) (congr_arg _ h₁) end section variable {p₀ q₀ : Path x₀ x₁} {p₁ q₁ : Path x₁ x₂} /-- Suppose `p₀` and `q₀` are paths from `x₀` to `x₁`, `p₁` and `q₁` are paths from `x₁` to `x₂`. Furthermore, suppose `F : Homotopy p₀ q₀` and `G : Homotopy p₁ q₁`. Then we can define a homotopy from `p₀.trans p₁` to `q₀.trans q₁`. -/ def hcomp (F : Homotopy p₀ q₀) (G : Homotopy p₁ q₁) : Homotopy (p₀.trans p₁) (q₀.trans q₁) where toFun x := if (x.2 : ℝ) ≤ 1 / 2 then (F.eval x.1).extend (2 * x.2) else (G.eval x.1).extend (2 * x.2 - 1) continuous_toFun := continuous_if_le (continuous_induced_dom.comp continuous_snd) continuous_const (F.toHomotopy.continuous.comp (by continuity)).continuousOn (G.toHomotopy.continuous.comp (by continuity)).continuousOn fun x hx => by norm_num [hx] map_zero_left x := by simp [Path.trans] map_one_left x := by simp [Path.trans] prop' x t ht := by rcases ht with ht | ht · norm_num [ht] · rw [Set.mem_singleton_iff] at ht norm_num [ht] theorem hcomp_apply (F : Homotopy p₀ q₀) (G : Homotopy p₁ q₁) (x : I × I) : F.hcomp G x = if h : (x.2 : ℝ) ≤ 1 / 2 then F.eval x.1 ⟨2 * x.2, (unitInterval.mul_pos_mem_iff zero_lt_two).2 ⟨x.2.2.1, h⟩⟩ else G.eval x.1 ⟨2 * x.2 - 1, unitInterval.two_mul_sub_one_mem_iff.2 ⟨(not_le.1 h).le, x.2.2.2⟩⟩ := show ite _ _ _ = _ by split_ifs <;> exact Path.extend_extends _ _ theorem hcomp_half (F : Homotopy p₀ q₀) (G : Homotopy p₁ q₁) (t : I) : F.hcomp G (t, ⟨1 / 2, by norm_num, by norm_num⟩) = x₁ := show ite _ _ _ = _ by norm_num end /-- Suppose `p` is a path, then we have a homotopy from `p` to `p.reparam f` by the convexity of `I`.
-/ def reparam (p : Path x₀ x₁) (f : I → I) (hf : Continuous f) (hf₀ : f 0 = 0) (hf₁ : f 1 = 1) : Homotopy p (p.reparam f hf hf₀ hf₁) where toFun x := p ⟨σ x.1 * x.2 + x.1 * f x.2, show (σ x.1 : ℝ) • (x.2 : ℝ) + (x.1 : ℝ) • (f x.2 : ℝ) ∈ I from convex_Icc _ _ x.2.2 (f x.2).2 (by unit_interval) (by unit_interval) (by simp)⟩ map_zero_left x := by norm_num map_one_left x := by norm_num
Mathlib/Topology/Homotopy/Path.lean
176
183
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Manuel Candales -/ import Mathlib.Geometry.Euclidean.Angle.Oriented.Affine import Mathlib.Geometry.Euclidean.Angle.Unoriented.Affine import Mathlib.Tactic.IntervalCases /-! # Triangles This file proves basic geometrical results about distances and angles in (possibly degenerate) triangles in real inner product spaces and Euclidean affine spaces. More specialized results, and results developed for simplices in general rather than just for triangles, are in separate files. Definitions and results that make sense in more general affine spaces rather than just in the Euclidean case go under `LinearAlgebra.AffineSpace`. ## Implementation notes Results in this file are generally given in a form with only those non-degeneracy conditions needed for the particular result, rather than requiring affine independence of the points of a triangle unnecessarily. ## References * https://en.wikipedia.org/wiki/Law_of_cosines * https://en.wikipedia.org/wiki/Pons_asinorum * https://en.wikipedia.org/wiki/Sum_of_angles_of_a_triangle -/ noncomputable section open scoped CharZero Real RealInnerProductSpace namespace InnerProductGeometry /-! ### Geometrical results on triangles in real inner product spaces This section develops some results on (possibly degenerate) triangles in real inner product spaces, where those definitions and results can most conveniently be developed in terms of vectors and then used to deduce corresponding results for Euclidean affine spaces. -/ variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] /-- **Law of cosines** (cosine rule), vector angle form. -/ theorem norm_sub_sq_eq_norm_sq_add_norm_sq_sub_two_mul_norm_mul_norm_mul_cos_angle (x y : V) : ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ - 2 * ‖x‖ * ‖y‖ * Real.cos (angle x y) := by rw [show 2 * ‖x‖ * ‖y‖ * Real.cos (angle x y) = 2 * (Real.cos (angle x y) * (‖x‖ * ‖y‖)) by ring, cos_angle_mul_norm_mul_norm, ← real_inner_self_eq_norm_mul_norm, ← real_inner_self_eq_norm_mul_norm, ← real_inner_self_eq_norm_mul_norm, real_inner_sub_sub_self, sub_add_eq_add_sub] /-- **Pons asinorum**, vector angle form. -/ theorem angle_sub_eq_angle_sub_rev_of_norm_eq {x y : V} (h : ‖x‖ = ‖y‖) : angle x (x - y) = angle y (y - x) := by refine Real.injOn_cos ⟨angle_nonneg _ _, angle_le_pi _ _⟩ ⟨angle_nonneg _ _, angle_le_pi _ _⟩ ?_ rw [cos_angle, cos_angle, h, ← neg_sub, norm_neg, neg_sub, inner_sub_right, inner_sub_right, real_inner_self_eq_norm_mul_norm, real_inner_self_eq_norm_mul_norm, h, real_inner_comm x y] /-- **Converse of pons asinorum**, vector angle form. -/ theorem norm_eq_of_angle_sub_eq_angle_sub_rev_of_angle_ne_pi {x y : V} (h : angle x (x - y) = angle y (y - x)) (hpi : angle x y ≠ π) : ‖x‖ = ‖y‖ := by replace h := Real.arccos_injOn (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x (x - y))) (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one y (y - x))) h by_cases hxy : x = y · rw [hxy] · rw [← norm_neg (y - x), neg_sub, mul_comm, mul_comm ‖y‖, div_eq_mul_inv, div_eq_mul_inv, mul_inv_rev, mul_inv_rev, ← mul_assoc, ← mul_assoc] at h replace h := mul_right_cancel₀ (inv_ne_zero fun hz => hxy (eq_of_sub_eq_zero (norm_eq_zero.1 hz))) h rw [inner_sub_right, inner_sub_right, real_inner_comm x y, real_inner_self_eq_norm_mul_norm, real_inner_self_eq_norm_mul_norm, mul_sub_right_distrib, mul_sub_right_distrib, mul_self_mul_inv, mul_self_mul_inv, sub_eq_sub_iff_sub_eq_sub, ← mul_sub_left_distrib] at h by_cases hx0 : x = 0 · rw [hx0, norm_zero, inner_zero_left, zero_mul, zero_sub, neg_eq_zero] at h rw [hx0, norm_zero, h] · by_cases hy0 : y = 0 · rw [hy0, norm_zero, inner_zero_right, zero_mul, sub_zero] at h rw [hy0, norm_zero, h] · rw [inv_sub_inv (fun hz => hx0 (norm_eq_zero.1 hz)) fun hz => hy0 (norm_eq_zero.1 hz), ← neg_sub, ← mul_div_assoc, mul_comm, mul_div_assoc, ← mul_neg_one] at h symm by_contra hyx replace h := (mul_left_cancel₀ (sub_ne_zero_of_ne hyx) h).symm rw [real_inner_div_norm_mul_norm_eq_neg_one_iff, ← angle_eq_pi_iff] at h exact hpi h /-- The cosine of the sum of two angles in a possibly degenerate triangle (where two given sides are nonzero), vector angle form. -/ theorem cos_angle_sub_add_angle_sub_rev_eq_neg_cos_angle {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : Real.cos (angle x (x - y) + angle y (y - x)) = -Real.cos (angle x y) := by by_cases hxy : x = y · rw [hxy, angle_self hy] simp · rw [Real.cos_add, cos_angle, cos_angle, cos_angle] have hxn : ‖x‖ ≠ 0 := fun h => hx (norm_eq_zero.1 h) have hyn : ‖y‖ ≠ 0 := fun h => hy (norm_eq_zero.1 h) have hxyn : ‖x - y‖ ≠ 0 := fun h => hxy (eq_of_sub_eq_zero (norm_eq_zero.1 h)) apply mul_right_cancel₀ hxn apply mul_right_cancel₀ hyn apply mul_right_cancel₀ hxyn apply mul_right_cancel₀ hxyn have H1 : Real.sin (angle x (x - y)) * Real.sin (angle y (y - x)) * ‖x‖ * ‖y‖ * ‖x - y‖ * ‖x - y‖ = Real.sin (angle x (x - y)) * (‖x‖ * ‖x - y‖) * (Real.sin (angle y (y - x)) * (‖y‖ * ‖x - y‖)) := by ring have H2 : ⟪x, x⟫ * (⟪x, x⟫ - ⟪x, y⟫ - (⟪x, y⟫ - ⟪y, y⟫)) - (⟪x, x⟫ - ⟪x, y⟫) * (⟪x, x⟫ - ⟪x, y⟫) = ⟪x, x⟫ * ⟪y, y⟫ - ⟪x, y⟫ * ⟪x, y⟫ := by ring have H3 : ⟪y, y⟫ * (⟪y, y⟫ - ⟪x, y⟫ - (⟪x, y⟫ - ⟪x, x⟫)) - (⟪y, y⟫ - ⟪x, y⟫) * (⟪y, y⟫ - ⟪x, y⟫) = ⟪x, x⟫ * ⟪y, y⟫ - ⟪x, y⟫ * ⟪x, y⟫ := by ring rw [mul_sub_right_distrib, mul_sub_right_distrib, mul_sub_right_distrib, mul_sub_right_distrib, H1, sin_angle_mul_norm_mul_norm, norm_sub_rev x y, sin_angle_mul_norm_mul_norm, norm_sub_rev y x, inner_sub_left, inner_sub_left, inner_sub_right, inner_sub_right, inner_sub_right, inner_sub_right, real_inner_comm x y, H2, H3, Real.mul_self_sqrt (sub_nonneg_of_le (real_inner_mul_inner_self_le x y)), real_inner_self_eq_norm_mul_norm, real_inner_self_eq_norm_mul_norm, real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two] -- TODO(https://github.com/leanprover-community/mathlib4/issues/15486): used to be `field_simp [hxn, hyn, hxyn]`, but was really slow -- replaced by `simp only ...` to speed up. Reinstate `field_simp` once it is faster. simp (disch := field_simp_discharge) only [sub_div', div_div, mul_div_assoc', div_mul_eq_mul_div, div_sub', neg_div', neg_sub, eq_div_iff, div_eq_iff] ring /-- The sine of the sum of two angles in a possibly degenerate triangle (where two given sides are nonzero), vector angle form. -/ theorem sin_angle_sub_add_angle_sub_rev_eq_sin_angle {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : Real.sin (angle x (x - y) + angle y (y - x)) = Real.sin (angle x y) := by by_cases hxy : x = y · rw [hxy, angle_self hy] simp · rw [Real.sin_add, cos_angle, cos_angle] have hxn : ‖x‖ ≠ 0 := fun h => hx (norm_eq_zero.1 h) have hyn : ‖y‖ ≠ 0 := fun h => hy (norm_eq_zero.1 h) have hxyn : ‖x - y‖ ≠ 0 := fun h => hxy (eq_of_sub_eq_zero (norm_eq_zero.1 h)) apply mul_right_cancel₀ hxn apply mul_right_cancel₀ hyn apply mul_right_cancel₀ hxyn apply mul_right_cancel₀ hxyn have H1 : Real.sin (angle x (x - y)) * (⟪y, y - x⟫ / (‖y‖ * ‖y - x‖)) * ‖x‖ * ‖y‖ * ‖x - y‖ = Real.sin (angle x (x - y)) * (‖x‖ * ‖x - y‖) * (⟪y, y - x⟫ / (‖y‖ * ‖y - x‖)) * ‖y‖ := by ring have H2 : ⟪x, x - y⟫ / (‖x‖ * ‖y - x‖) * Real.sin (angle y (y - x)) * ‖x‖ * ‖y‖ * ‖y - x‖ = ⟪x, x - y⟫ / (‖x‖ * ‖y - x‖) * (Real.sin (angle y (y - x)) * (‖y‖ * ‖y - x‖)) * ‖x‖ := by ring have H3 : ⟪x, x⟫ * (⟪x, x⟫ - ⟪x, y⟫ - (⟪x, y⟫ - ⟪y, y⟫)) - (⟪x, x⟫ - ⟪x, y⟫) * (⟪x, x⟫ - ⟪x, y⟫) = ⟪x, x⟫ * ⟪y, y⟫ - ⟪x, y⟫ * ⟪x, y⟫ := by ring have H4 : ⟪y, y⟫ * (⟪y, y⟫ - ⟪x, y⟫ - (⟪x, y⟫ - ⟪x, x⟫)) - (⟪y, y⟫ - ⟪x, y⟫) * (⟪y, y⟫ - ⟪x, y⟫) = ⟪x, x⟫ * ⟪y, y⟫ - ⟪x, y⟫ * ⟪x, y⟫ := by ring rw [right_distrib, right_distrib, right_distrib, right_distrib, H1, sin_angle_mul_norm_mul_norm, norm_sub_rev x y, H2, sin_angle_mul_norm_mul_norm, norm_sub_rev y x, mul_assoc (Real.sin (angle x y)), sin_angle_mul_norm_mul_norm, inner_sub_left, inner_sub_left, inner_sub_right, inner_sub_right, inner_sub_right, inner_sub_right, real_inner_comm x y, H3, H4, real_inner_self_eq_norm_mul_norm, real_inner_self_eq_norm_mul_norm, real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two] -- TODO(https://github.com/leanprover-community/mathlib4/issues/15486): used to be `field_simp [hxn, hyn, hxyn]`, but was really slow -- replaced by `simp only ...` to speed up. Reinstate `field_simp` once it is faster. simp (disch := field_simp_discharge) only [mul_div_assoc', div_mul_eq_mul_div, div_div, sub_div', Real.sqrt_div', Real.sqrt_mul_self, add_div', div_add', eq_div_iff, div_eq_iff] ring /-- The cosine of the sum of the angles of a possibly degenerate triangle (where two given sides are nonzero), vector angle form. -/ theorem cos_angle_add_angle_sub_add_angle_sub_eq_neg_one {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : Real.cos (angle x y + angle x (x - y) + angle y (y - x)) = -1 := by rw [add_assoc, Real.cos_add, cos_angle_sub_add_angle_sub_rev_eq_neg_cos_angle hx hy, sin_angle_sub_add_angle_sub_rev_eq_sin_angle hx hy, mul_neg, ← neg_add', add_comm, ← sq, ← sq, Real.sin_sq_add_cos_sq] /-- The sine of the sum of the angles of a possibly degenerate triangle (where two given sides are nonzero), vector angle form. -/ theorem sin_angle_add_angle_sub_add_angle_sub_eq_zero {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : Real.sin (angle x y + angle x (x - y) + angle y (y - x)) = 0 := by rw [add_assoc, Real.sin_add, cos_angle_sub_add_angle_sub_rev_eq_neg_cos_angle hx hy, sin_angle_sub_add_angle_sub_rev_eq_sin_angle hx hy] ring /-- The sum of the angles of a possibly degenerate triangle (where the two given sides are nonzero), vector angle form. -/ theorem angle_add_angle_sub_add_angle_sub_eq_pi {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) : angle x y + angle x (x - y) + angle y (y - x) = π := by have hcos := cos_angle_add_angle_sub_add_angle_sub_eq_neg_one hx hy have hsin := sin_angle_add_angle_sub_add_angle_sub_eq_zero hx hy rw [Real.sin_eq_zero_iff] at hsin obtain ⟨n, hn⟩ := hsin symm at hn have h0 : 0 ≤ angle x y + angle x (x - y) + angle y (y - x) := add_nonneg (add_nonneg (angle_nonneg _ _) (angle_nonneg _ _)) (angle_nonneg _ _) have h3lt : angle x y + angle x (x - y) + angle y (y - x) < π + π + π := by by_contra hnlt have hxy : angle x y = π := by by_contra hxy exact hnlt (add_lt_add_of_lt_of_le (add_lt_add_of_lt_of_le (lt_of_le_of_ne (angle_le_pi _ _) hxy) (angle_le_pi _ _)) (angle_le_pi _ _)) rw [hxy] at hnlt rw [angle_eq_pi_iff] at hxy rcases hxy with ⟨hx, ⟨r, ⟨hr, hxr⟩⟩⟩ rw [hxr, ← one_smul ℝ x, ← mul_smul, mul_one, ← sub_smul, one_smul, sub_eq_add_neg, angle_smul_right_of_pos _ _ (add_pos zero_lt_one (neg_pos_of_neg hr)), angle_self hx, add_zero] at hnlt apply hnlt rw [add_assoc] exact add_lt_add_left (lt_of_le_of_lt (angle_le_pi _ _) (lt_add_of_pos_right π Real.pi_pos)) _ have hn0 : 0 ≤ n := by rw [hn, mul_nonneg_iff_left_nonneg_of_pos Real.pi_pos] at h0 norm_cast at h0 have hn3 : n < 3 := by rw [hn, show π + π + π = 3 * π by ring] at h3lt replace h3lt := lt_of_mul_lt_mul_right h3lt (le_of_lt Real.pi_pos) norm_cast at h3lt interval_cases n · simp [hn] at hcos · norm_num [hn] · simp [hn] at hcos end InnerProductGeometry namespace EuclideanGeometry /-! ### Geometrical results on triangles in Euclidean affine spaces This section develops some geometrical definitions and results on (possibly degenerate) triangles in Euclidean affine spaces. -/ open InnerProductGeometry open scoped EuclideanGeometry variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] /-- **Law of cosines** (cosine rule), angle-at-point form. -/ theorem dist_sq_eq_dist_sq_add_dist_sq_sub_two_mul_dist_mul_dist_mul_cos_angle (p₁ p₂ p₃ : P) : dist p₁ p₃ * dist p₁ p₃ = dist p₁ p₂ * dist p₁ p₂ + dist p₃ p₂ * dist p₃ p₂ - 2 * dist p₁ p₂ * dist p₃ p₂ * Real.cos (∠ p₁ p₂ p₃) := by rw [dist_eq_norm_vsub V p₁ p₃, dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub V p₃ p₂] unfold angle convert norm_sub_sq_eq_norm_sq_add_norm_sq_sub_two_mul_norm_mul_norm_mul_cos_angle (p₁ -ᵥ p₂ : V) (p₃ -ᵥ p₂ : V) · exact (vsub_sub_vsub_cancel_right p₁ p₃ p₂).symm · exact (vsub_sub_vsub_cancel_right p₁ p₃ p₂).symm alias law_cos := dist_sq_eq_dist_sq_add_dist_sq_sub_two_mul_dist_mul_dist_mul_cos_angle
/-- **Isosceles Triangle Theorem**: Pons asinorum, angle-at-point form. -/ theorem angle_eq_angle_of_dist_eq {p₁ p₂ p₃ : P} (h : dist p₁ p₂ = dist p₁ p₃) : ∠ p₁ p₂ p₃ = ∠ p₁ p₃ p₂ := by rw [dist_eq_norm_vsub V p₁ p₂, dist_eq_norm_vsub V p₁ p₃] at h unfold angle convert angle_sub_eq_angle_sub_rev_of_norm_eq h · exact (vsub_sub_vsub_cancel_left p₃ p₂ p₁).symm · exact (vsub_sub_vsub_cancel_left p₂ p₃ p₁).symm
Mathlib/Geometry/Euclidean/Triangle.lean
264
272
/- Copyright (c) 2021 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth, David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.ExpDeriv import Mathlib.Analysis.SpecialFunctions.Complex.Circle import Mathlib.Analysis.InnerProductSpace.l2Space import Mathlib.MeasureTheory.Function.ContinuousMapDense import Mathlib.MeasureTheory.Function.L2Space import Mathlib.MeasureTheory.Group.Integral import Mathlib.MeasureTheory.Integral.IntervalIntegral.Periodic import Mathlib.Topology.ContinuousMap.StoneWeierstrass import Mathlib.MeasureTheory.Integral.IntervalIntegral.IntegrationByParts /-! # Fourier analysis on the additive circle This file contains basic results on Fourier series for functions on the additive circle `AddCircle T = ℝ / ℤ • T`. ## Main definitions * `haarAddCircle`, Haar measure on `AddCircle T`, normalized to have total measure `1`. Note that this is not the same normalisation as the standard measure defined in `IntervalIntegral.Periodic`, so we do not declare it as a `MeasureSpace` instance, to avoid confusion. * for `n : ℤ`, `fourier n` is the monomial `fun x => exp (2 π i n x / T)`, bundled as a continuous map from `AddCircle T` to `ℂ`. * `fourierBasis` is the Hilbert basis of `Lp ℂ 2 haarAddCircle` given by the images of the monomials `fourier n`. * `fourierCoeff f n`, for `f : AddCircle T → E` (with `E` a complete normed `ℂ`-vector space), is the `n`-th Fourier coefficient of `f`, defined as an integral over `AddCircle T`. The lemma `fourierCoeff_eq_intervalIntegral` expresses this as an integral over `[a, a + T]` for any real `a`. * `fourierCoeffOn`, for `f : ℝ → E` and `a < b` reals, is the `n`-th Fourier coefficient of the unique periodic function of period `b - a` which agrees with `f` on `(a, b]`. The lemma `fourierCoeffOn_eq_integral` expresses this as an integral over `[a, b]`. ## Main statements The theorem `span_fourier_closure_eq_top` states that the span of the monomials `fourier n` is dense in `C(AddCircle T, ℂ)`, i.e. that its `Submodule.topologicalClosure` is `⊤`. This follows from the Stone-Weierstrass theorem after checking that the span is a subalgebra, is closed under conjugation, and separates points. Using this and general theory on approximation of Lᵖ functions by continuous functions, we deduce (`span_fourierLp_closure_eq_top`) that for any `1 ≤ p < ∞`, the span of the Fourier monomials is dense in the Lᵖ space of `AddCircle T`. For `p = 2` we show (`orthonormal_fourier`) that the monomials are also orthonormal, so they form a Hilbert basis for L², which is named as `fourierBasis`; in particular, for `L²` functions `f`, the Fourier series of `f` converges to `f` in the `L²` topology (`hasSum_fourier_series_L2`). Parseval's identity, `tsum_sq_fourierCoeff`, is a direct consequence. For continuous maps `f : AddCircle T → ℂ`, the theorem `hasSum_fourier_series_of_summable` states that if the sequence of Fourier coefficients of `f` is summable, then the Fourier series `∑ (i : ℤ), fourierCoeff f i * fourier i` converges to `f` in the uniform-convergence topology of `C(AddCircle T, ℂ)`. -/ noncomputable section open scoped ENNReal ComplexConjugate Real open TopologicalSpace ContinuousMap MeasureTheory MeasureTheory.Measure Algebra Submodule Set variable {T : ℝ} namespace AddCircle /-! ### Measure on `AddCircle T` In this file we use the Haar measure on `AddCircle T` normalised to have total measure 1 (which is **not** the same as the standard measure defined in `Topology.Instances.AddCircle`). -/ variable [hT : Fact (0 < T)] /-- Haar measure on the additive circle, normalised to have total measure 1. -/ def haarAddCircle : Measure (AddCircle T) := addHaarMeasure ⊤ -- The `IsAddHaarMeasure` instance should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 instance : IsAddHaarMeasure (@haarAddCircle T _) := Measure.isAddHaarMeasure_addHaarMeasure ⊤ instance : IsProbabilityMeasure (@haarAddCircle T _) := IsProbabilityMeasure.mk addHaarMeasure_self theorem volume_eq_smul_haarAddCircle : (volume : Measure (AddCircle T)) = ENNReal.ofReal T • (@haarAddCircle T _) := rfl end AddCircle open AddCircle section Monomials /-- The family of exponential monomials `fun x => exp (2 π i n x / T)`, parametrized by `n : ℤ` and considered as bundled continuous maps from `ℝ / ℤ • T` to `ℂ`. -/ def fourier (n : ℤ) : C(AddCircle T, ℂ) where toFun x := toCircle (n • x :) continuous_toFun := continuous_induced_dom.comp <| continuous_toCircle.comp <| continuous_zsmul _ @[simp] theorem fourier_apply {n : ℤ} {x : AddCircle T} : fourier n x = toCircle (n • x :) := rfl -- simp normal form is `fourier_coe_apply'` theorem fourier_coe_apply {n : ℤ} {x : ℝ} : fourier n (x : AddCircle T) = Complex.exp (2 * π * Complex.I * n * x / T) := by rw [fourier_apply, ← QuotientAddGroup.mk_zsmul, toCircle, Function.Periodic.lift_coe, Circle.coe_exp, Complex.ofReal_mul, Complex.ofReal_div, Complex.ofReal_mul, zsmul_eq_mul, Complex.ofReal_mul, Complex.ofReal_intCast] norm_num congr 1; ring @[simp] theorem fourier_coe_apply' {n : ℤ} {x : ℝ} : toCircle (n • (x : AddCircle T) :) = Complex.exp (2 * π * Complex.I * n * x / T) := by rw [← fourier_apply]; exact fourier_coe_apply -- simp normal form is `fourier_zero'` theorem fourier_zero {x : AddCircle T} : fourier 0 x = 1 := by induction x using QuotientAddGroup.induction_on simp only [fourier_coe_apply] norm_num theorem fourier_zero' {x : AddCircle T} : @toCircle T 0 = (1 : ℂ) := by have : fourier 0 x = @toCircle T 0 := by rw [fourier_apply, zero_smul] rw [← this]; exact fourier_zero -- simp normal form is *also* `fourier_zero'` theorem fourier_eval_zero (n : ℤ) : fourier n (0 : AddCircle T) = 1 := by rw [← QuotientAddGroup.mk_zero, fourier_coe_apply, Complex.ofReal_zero, mul_zero, zero_div, Complex.exp_zero] theorem fourier_one {x : AddCircle T} : fourier 1 x = toCircle x := by rw [fourier_apply, one_zsmul] -- simp normal form is `fourier_neg'` theorem fourier_neg {n : ℤ} {x : AddCircle T} : fourier (-n) x = conj (fourier n x) := by induction x using QuotientAddGroup.induction_on simp_rw [fourier_apply, toCircle] rw [← QuotientAddGroup.mk_zsmul, ← QuotientAddGroup.mk_zsmul] simp_rw [Function.Periodic.lift_coe, ← Circle.coe_inv_eq_conj, ← Circle.exp_neg, neg_smul, mul_neg] @[simp] theorem fourier_neg' {n : ℤ} {x : AddCircle T} : @toCircle T (-(n • x)) = conj (fourier n x) := by rw [← neg_smul, ← fourier_apply]; exact fourier_neg -- simp normal form is `fourier_add'` theorem fourier_add {m n : ℤ} {x : AddCircle T} : fourier (m+n) x = fourier m x * fourier n x := by simp_rw [fourier_apply, add_zsmul, toCircle_add, Circle.coe_mul] @[simp] theorem fourier_add' {m n : ℤ} {x : AddCircle T} : toCircle ((m + n) • x :) = fourier m x * fourier n x := by rw [← fourier_apply]; exact fourier_add theorem fourier_norm [Fact (0 < T)] (n : ℤ) : ‖@fourier T n‖ = 1 := by rw [ContinuousMap.norm_eq_iSup_norm] have : ∀ x : AddCircle T, ‖fourier n x‖ = 1 := fun x => Circle.norm_coe _ simp_rw [this] exact @ciSup_const _ _ _ Zero.instNonempty _ /-- For `n ≠ 0`, a translation by `T / 2 / n` negates the function `fourier n`. -/ theorem fourier_add_half_inv_index {n : ℤ} (hn : n ≠ 0) (hT : 0 < T) (x : AddCircle T) : @fourier T n (x + ↑(T / 2 / n)) = -fourier n x := by rw [fourier_apply, zsmul_add, ← QuotientAddGroup.mk_zsmul, toCircle_add, Metric.unitSphere.coe_mul] have : (n : ℂ) ≠ 0 := by simpa using hn have : (@toCircle T (n • (T / 2 / n) : ℝ) : ℂ) = -1 := by rw [zsmul_eq_mul, toCircle, Function.Periodic.lift_coe, Circle.coe_exp] replace hT := Complex.ofReal_ne_zero.mpr hT.ne' convert Complex.exp_pi_mul_I using 3 field_simp; ring rw [this]; simp /-- The star subalgebra of `C(AddCircle T, ℂ)` generated by `fourier n` for `n ∈ ℤ` . -/ def fourierSubalgebra : StarSubalgebra ℂ C(AddCircle T, ℂ) where toSubalgebra := Algebra.adjoin ℂ (range fourier) star_mem' := by show Algebra.adjoin ℂ (range (fourier (T := T))) ≤ star (Algebra.adjoin ℂ (range (fourier (T := T)))) refine adjoin_le ?_ rintro - ⟨n, rfl⟩ exact subset_adjoin ⟨-n, ext fun _ => fourier_neg⟩ /-- The star subalgebra of `C(AddCircle T, ℂ)` generated by `fourier n` for `n ∈ ℤ` is in fact the linear span of these functions. -/ theorem fourierSubalgebra_coe : Subalgebra.toSubmodule (@fourierSubalgebra T).toSubalgebra = span ℂ (range (@fourier T)) := by apply adjoin_eq_span_of_subset refine Subset.trans ?_ Submodule.subset_span intro x hx refine Submonoid.closure_induction (fun _ => id) ⟨0, ?_⟩ ?_ hx · ext1 z; exact fourier_zero · rintro - - - - ⟨m, rfl⟩ ⟨n, rfl⟩ refine ⟨m + n, ?_⟩ ext1 z exact fourier_add /- a post-port refactor made `fourierSubalgebra` into a `StarSubalgebra`, and eliminated `conjInvariantSubalgebra` entirely, making this lemma irrelevant. -/ variable [hT : Fact (0 < T)] /-- The subalgebra of `C(AddCircle T, ℂ)` generated by `fourier n` for `n ∈ ℤ` separates points. -/ theorem fourierSubalgebra_separatesPoints : (@fourierSubalgebra T).SeparatesPoints := by intro x y hxy refine ⟨_, ⟨fourier 1, subset_adjoin ⟨1, rfl⟩, rfl⟩, ?_⟩ dsimp only; rw [fourier_one, fourier_one] contrapose! hxy rw [Subtype.coe_inj] at hxy exact injective_toCircle hT.elim.ne' hxy /-- The subalgebra of `C(AddCircle T, ℂ)` generated by `fourier n` for `n ∈ ℤ` is dense. -/ theorem fourierSubalgebra_closure_eq_top : (@fourierSubalgebra T).topologicalClosure = ⊤ := ContinuousMap.starSubalgebra_topologicalClosure_eq_top_of_separatesPoints fourierSubalgebra fourierSubalgebra_separatesPoints /-- The linear span of the monomials `fourier n` is dense in `C(AddCircle T, ℂ)`. -/ theorem span_fourier_closure_eq_top : (span ℂ (range <| @fourier T)).topologicalClosure = ⊤ := by rw [← fourierSubalgebra_coe] exact congr_arg (Subalgebra.toSubmodule <| StarSubalgebra.toSubalgebra ·) fourierSubalgebra_closure_eq_top /-- The family of monomials `fourier n`, parametrized by `n : ℤ` and considered as elements of the `Lp` space of functions `AddCircle T → ℂ`. -/ abbrev fourierLp (p : ℝ≥0∞) [Fact (1 ≤ p)] (n : ℤ) : Lp ℂ p (@haarAddCircle T hT) := toLp (E := ℂ) p haarAddCircle ℂ (fourier n) theorem coeFn_fourierLp (p : ℝ≥0∞) [Fact (1 ≤ p)] (n : ℤ) : @fourierLp T hT p _ n =ᵐ[haarAddCircle] fourier n := coeFn_toLp haarAddCircle (fourier n) /-- For each `1 ≤ p < ∞`, the linear span of the monomials `fourier n` is dense in `Lp ℂ p haarAddCircle`. -/ theorem span_fourierLp_closure_eq_top {p : ℝ≥0∞} [Fact (1 ≤ p)] (hp : p ≠ ∞) : (span ℂ (range (@fourierLp T _ p _))).topologicalClosure = ⊤ := by convert (ContinuousMap.toLp_denseRange ℂ (@haarAddCircle T hT) ℂ hp).topologicalClosure_map_submodule span_fourier_closure_eq_top rw [map_span] unfold fourierLp rw [range_comp'] simp only [ContinuousLinearMap.coe_coe] /-- The monomials `fourier n` are an orthonormal set with respect to normalised Haar measure. -/ theorem orthonormal_fourier : Orthonormal ℂ (@fourierLp T _ 2 _) := by rw [orthonormal_iff_ite] intro i j rw [ContinuousMap.inner_toLp (@haarAddCircle T hT) (fourier i) (fourier j)] simp_rw [← fourier_neg, ← fourier_add] split_ifs with h · simp_rw [h, add_neg_cancel] have : ⇑(@fourier T 0) = (fun _ => 1 : AddCircle T → ℂ) := by ext1; exact fourier_zero rw [this, integral_const, measureReal_univ_eq_one, Complex.real_smul, Complex.ofReal_one, mul_one] have hij : j + -i ≠ 0 := by exact sub_ne_zero.mpr (Ne.symm h) convert integral_eq_zero_of_add_right_eq_neg (μ := haarAddCircle) (fourier_add_half_inv_index hij hT.elim) end Monomials section ScopeHT -- everything from here on needs `0 < T` variable [hT : Fact (0 < T)] section fourierCoeff variable {E : Type} [NormedAddCommGroup E] [NormedSpace ℂ E] /-- The `n`-th Fourier coefficient of a function `AddCircle T → E`, for `E` a complete normed `ℂ`-vector space, defined as the integral over `AddCircle T` of `fourier (-n) t • f t`. -/ def fourierCoeff (f : AddCircle T → E) (n : ℤ) : E := ∫ t : AddCircle T, fourier (-n) t • f t ∂haarAddCircle /-- The Fourier coefficients of a function on `AddCircle T` can be computed as an integral over `[a, a + T]`, for any real `a`. -/ theorem fourierCoeff_eq_intervalIntegral (f : AddCircle T → E) (n : ℤ) (a : ℝ) : fourierCoeff f n = (1 / T) • ∫ x in a..a + T, @fourier T (-n) x • f x := by have : ∀ x : ℝ, @fourier T (-n) x • f x = (fun z : AddCircle T => @fourier T (-n) z • f z) x := by intro x; rfl -- After https://github.com/leanprover/lean4/pull/3124, we need to add `singlePass := true` to avoid an infinite loop. simp_rw +singlePass [this] rw [fourierCoeff, AddCircle.intervalIntegral_preimage T a (fun z => _ • _), volume_eq_smul_haarAddCircle, integral_smul_measure, ENNReal.toReal_ofReal hT.out.le, ← smul_assoc, smul_eq_mul, one_div_mul_cancel hT.out.ne', one_smul] theorem fourierCoeff.const_smul (f : AddCircle T → E) (c : ℂ) (n : ℤ) : fourierCoeff (c • f :) n = c • fourierCoeff f n := by simp_rw [fourierCoeff, Pi.smul_apply, ← smul_assoc, smul_eq_mul, mul_comm, ← smul_eq_mul, smul_assoc, integral_smul] theorem fourierCoeff.const_mul (f : AddCircle T → ℂ) (c : ℂ) (n : ℤ) : fourierCoeff (fun x => c * f x) n = c * fourierCoeff f n := fourierCoeff.const_smul f c n /-- For a function on `ℝ`, the Fourier coefficients of `f` on `[a, b]` are defined as the Fourier coefficients of the unique periodic function agreeing with `f` on `Ioc a b`. -/ def fourierCoeffOn {a b : ℝ} (hab : a < b) (f : ℝ → E) (n : ℤ) : E := haveI := Fact.mk (by linarith : 0 < b - a) fourierCoeff (AddCircle.liftIoc (b - a) a f) n theorem fourierCoeffOn_eq_integral {a b : ℝ} (f : ℝ → E) (n : ℤ) (hab : a < b) : fourierCoeffOn hab f n = (1 / (b - a)) • ∫ x in a..b, fourier (-n) (x : AddCircle (b - a)) • f x := by haveI := Fact.mk (by linarith : 0 < b - a) rw [fourierCoeffOn, fourierCoeff_eq_intervalIntegral _ _ a, add_sub, add_sub_cancel_left] congr 1 simp_rw [intervalIntegral.integral_of_le hab.le] refine setIntegral_congr_fun measurableSet_Ioc fun x hx => ?_ rw [liftIoc_coe_apply] rwa [add_sub, add_sub_cancel_left] theorem fourierCoeffOn.const_smul {a b : ℝ} (f : ℝ → E) (c : ℂ) (n : ℤ) (hab : a < b) : fourierCoeffOn hab (c • f) n = c • fourierCoeffOn hab f n := by haveI := Fact.mk (by linarith : 0 < b - a) apply fourierCoeff.const_smul theorem fourierCoeffOn.const_mul {a b : ℝ} (f : ℝ → ℂ) (c : ℂ) (n : ℤ) (hab : a < b) : fourierCoeffOn hab (fun x => c * f x) n = c * fourierCoeffOn hab f n := fourierCoeffOn.const_smul _ _ _ _ theorem fourierCoeff_liftIoc_eq {a : ℝ} (f : ℝ → ℂ) (n : ℤ) : fourierCoeff (AddCircle.liftIoc T a f) n = fourierCoeffOn (lt_add_of_pos_right a hT.out) f n := by rw [fourierCoeffOn_eq_integral, fourierCoeff_eq_intervalIntegral, add_sub_cancel_left a T] · congr 1 refine intervalIntegral.integral_congr_ae (ae_of_all _ fun x hx => ?_) rw [liftIoc_coe_apply] rwa [uIoc_of_le (lt_add_of_pos_right a hT.out).le] at hx theorem fourierCoeff_liftIco_eq {a : ℝ} (f : ℝ → ℂ) (n : ℤ) : fourierCoeff (AddCircle.liftIco T a f) n = fourierCoeffOn (lt_add_of_pos_right a hT.out) f n := by rw [fourierCoeffOn_eq_integral, fourierCoeff_eq_intervalIntegral _ _ a, add_sub_cancel_left a T] congr 1 simp_rw [intervalIntegral.integral_of_le (lt_add_of_pos_right a hT.out).le] iterate 2 rw [integral_Ioc_eq_integral_Ioo] refine setIntegral_congr_fun measurableSet_Ioo fun x hx => ?_ rw [liftIco_coe_apply (Ioo_subset_Ico_self hx)] end fourierCoeff section FourierL2 /-- We define `fourierBasis` to be a `ℤ`-indexed Hilbert basis for `Lp ℂ 2 haarAddCircle`, which by definition is an isometric isomorphism from `Lp ℂ 2 haarAddCircle` to `ℓ²(ℤ, ℂ)`. -/ def fourierBasis : HilbertBasis ℤ ℂ (Lp ℂ 2 <| @haarAddCircle T hT) := HilbertBasis.mk orthonormal_fourier (span_fourierLp_closure_eq_top (by norm_num)).ge /-- The elements of the Hilbert basis `fourierBasis` are the functions `fourierLp 2`, i.e. the monomials `fourier n` on the circle considered as elements of `L²`. -/ @[simp] theorem coe_fourierBasis : ⇑(@fourierBasis T hT) = @fourierLp T hT 2 _ := HilbertBasis.coe_mk _ _ /-- Under the isometric isomorphism `fourierBasis` from `Lp ℂ 2 haarAddCircle` to `ℓ²(ℤ, ℂ)`, the `i`-th coefficient is `fourierCoeff f i`, i.e., the integral over `AddCircle T` of `fun t => fourier (-i) t * f t` with respect to the Haar measure of total mass 1. -/ theorem fourierBasis_repr (f : Lp ℂ 2 <| @haarAddCircle T hT) (i : ℤ) : fourierBasis.repr f i = fourierCoeff f i := by trans ∫ t : AddCircle T, conj ((@fourierLp T hT 2 _ i : AddCircle T → ℂ) t) * f t ∂haarAddCircle · rw [fourierBasis.repr_apply_apply f i, MeasureTheory.L2.inner_def, coe_fourierBasis] simp only [RCLike.inner_apply'] · apply integral_congr_ae filter_upwards [coeFn_fourierLp 2 i] with _ ht rw [ht, ← fourier_neg, smul_eq_mul] /-- The Fourier series of an `L2` function `f` sums to `f`, in the `L²` space of `AddCircle T`. -/ theorem hasSum_fourier_series_L2 (f : Lp ℂ 2 <| @haarAddCircle T hT) : HasSum (fun i => fourierCoeff f i • fourierLp 2 i) f := by simp_rw [← fourierBasis_repr]; rw [← coe_fourierBasis] exact HilbertBasis.hasSum_repr fourierBasis f /-- **Parseval's identity**: for an `L²` function `f` on `AddCircle T`, the sum of the squared norms of the Fourier coefficients equals the `L²` norm of `f`. -/ theorem tsum_sq_fourierCoeff (f : Lp ℂ 2 <| @haarAddCircle T hT) : ∑' i : ℤ, ‖fourierCoeff f i‖ ^ 2 = ∫ t : AddCircle T, ‖f t‖ ^ 2 ∂haarAddCircle := by simp_rw [← fourierBasis_repr] have H₁ : ‖fourierBasis.repr f‖ ^ 2 = ∑' i, ‖fourierBasis.repr f i‖ ^ 2 := by apply_mod_cast lp.norm_rpow_eq_tsum ?_ (fourierBasis.repr f) norm_num have H₂ : ‖fourierBasis.repr f‖ ^ 2 = ‖f‖ ^ 2 := by simp have H₃ := congr_arg RCLike.re (@L2.inner_def (AddCircle T) ℂ ℂ _ _ _ _ _ f f) rw [← integral_re] at H₃ · simp only [← norm_sq_eq_re_inner] at H₃ rw [← H₁, H₂, H₃] · exact L2.integrable_inner f f end FourierL2 section Convergence variable (f : C(AddCircle T, ℂ)) theorem fourierCoeff_toLp (n : ℤ) : fourierCoeff (toLp (E := ℂ) 2 haarAddCircle ℂ f) n = fourierCoeff f n := integral_congr_ae (Filter.EventuallyEq.mul (Filter.Eventually.of_forall (by tauto)) (ContinuousMap.coeFn_toAEEqFun haarAddCircle f)) variable {f} /-- If the sequence of Fourier coefficients of `f` is summable, then the Fourier series converges uniformly to `f`. -/ theorem hasSum_fourier_series_of_summable (h : Summable (fourierCoeff f)) : HasSum (fun i => fourierCoeff f i • fourier i) f := by have sum_L2 := hasSum_fourier_series_L2 (toLp (E := ℂ) 2 haarAddCircle ℂ f) simp_rw [fourierCoeff_toLp] at sum_L2
refine ContinuousMap.hasSum_of_hasSum_Lp (.of_norm ?_) sum_L2 simp_rw [norm_smul, fourier_norm, mul_one] exact h.norm
Mathlib/Analysis/Fourier/AddCircle.lean
419
422
/- 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⟩ · exact ⟨y, h⟩ -- see Note [lower instance priority] @[to_additive] instance (priority := 100) LinearOrderedCommGroup.to_noMaxOrder [Nontrivial α] : NoMaxOrder α := ⟨by obtain ⟨y, hy⟩ : ∃ a : α, 1 < a := exists_one_lt' exact fun a => ⟨a * y, lt_mul_of_one_lt_right' a hy⟩⟩ -- see Note [lower instance priority] @[to_additive] instance (priority := 100) LinearOrderedCommGroup.to_noMinOrder [Nontrivial α] : NoMinOrder α := ⟨by obtain ⟨y, hy⟩ : ∃ a : α, 1 < a := exists_one_lt' exact fun a => ⟨a / y, (div_lt_self_iff a).mpr hy⟩⟩ @[to_additive (attr := simp)] theorem inv_le_self_iff : a⁻¹ ≤ a ↔ 1 ≤ a := by simp [inv_le_iff_one_le_mul'] @[to_additive (attr := simp)] theorem inv_lt_self_iff : a⁻¹ < a ↔ 1 < a := by simp [inv_lt_iff_one_lt_mul] @[to_additive (attr := simp)] theorem le_inv_self_iff : a ≤ a⁻¹ ↔ a ≤ 1 := by simp [← not_iff_not] @[to_additive (attr := simp)] theorem lt_inv_self_iff : a < a⁻¹ ↔ a < 1 := by simp [← not_iff_not] end LinearOrderedCommGroup section NormNumLemmas /- The following lemmas are stated so that the `norm_num` tactic can use them with the expected signatures. -/ variable [CommGroup α] [PartialOrder α] [IsOrderedMonoid α] {a b : α} @[to_additive (attr := gcongr) neg_le_neg] theorem inv_le_inv' : a ≤ b → b⁻¹ ≤ a⁻¹ := inv_le_inv_iff.mpr @[to_additive (attr := gcongr) neg_lt_neg] theorem inv_lt_inv' : a < b → b⁻¹ < a⁻¹ := inv_lt_inv_iff.mpr -- The additive version is also a `linarith` lemma. @[to_additive] theorem inv_lt_one_of_one_lt : 1 < a → a⁻¹ < 1 := inv_lt_one_iff_one_lt.mpr -- The additive version is also a `linarith` lemma. @[to_additive] theorem inv_le_one_of_one_le : 1 ≤ a → a⁻¹ ≤ 1 := inv_le_one'.mpr @[to_additive neg_nonneg_of_nonpos] theorem one_le_inv_of_le_one : a ≤ 1 → 1 ≤ a⁻¹ := one_le_inv'.mpr end NormNumLemmas
Mathlib/Algebra/Order/Group/Defs.lean
360
361
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Oliver Nash -/ import Mathlib.Data.Finset.Card import Mathlib.Data.Finset.Union /-! # Finsets in product types This file defines finset constructions on the product type `α × β`. Beware not to confuse with the `Finset.prod` operation which computes the multiplicative product. ## Main declarations * `Finset.product`: Turns `s : Finset α`, `t : Finset β` into their product in `Finset (α × β)`. * `Finset.diag`: For `s : Finset α`, `s.diag` is the `Finset (α × α)` of pairs `(a, a)` with `a ∈ s`. * `Finset.offDiag`: For `s : Finset α`, `s.offDiag` is the `Finset (α × α)` of pairs `(a, b)` with `a, b ∈ s` and `a ≠ b`. -/ assert_not_exists MonoidWithZero open Multiset variable {α β γ : Type*} namespace Finset /-! ### prod -/ section Prod variable {s s' : Finset α} {t t' : Finset β} {a : α} {b : β} /-- `product s t` is the set of pairs `(a, b)` such that `a ∈ s` and `b ∈ t`. -/ protected def product (s : Finset α) (t : Finset β) : Finset (α × β) := ⟨_, s.nodup.product t.nodup⟩ instance instSProd : SProd (Finset α) (Finset β) (Finset (α × β)) where sprod := Finset.product @[simp] theorem product_eq_sprod : Finset.product s t = s ×ˢ t := rfl @[simp] theorem product_val : (s ×ˢ t).1 = s.1 ×ˢ t.1 := rfl @[simp] theorem mem_product {p : α × β} : p ∈ s ×ˢ t ↔ p.1 ∈ s ∧ p.2 ∈ t := Multiset.mem_product theorem mk_mem_product (ha : a ∈ s) (hb : b ∈ t) : (a, b) ∈ s ×ˢ t := mem_product.2 ⟨ha, hb⟩ @[simp, norm_cast] theorem coe_product (s : Finset α) (t : Finset β) : (↑(s ×ˢ t) : Set (α × β)) = (s : Set α) ×ˢ t := Set.ext fun _ => Finset.mem_product theorem subset_product_image_fst [DecidableEq α] : (s ×ˢ t).image Prod.fst ⊆ s := fun i => by simp +contextual [mem_image] theorem subset_product_image_snd [DecidableEq β] : (s ×ˢ t).image Prod.snd ⊆ t := fun i => by simp +contextual [mem_image] theorem product_image_fst [DecidableEq α] (ht : t.Nonempty) : (s ×ˢ t).image Prod.fst = s := by ext i simp [mem_image, ht.exists_mem] theorem product_image_snd [DecidableEq β] (ht : s.Nonempty) : (s ×ˢ t).image Prod.snd = t := by ext i simp [mem_image, ht.exists_mem] theorem subset_product [DecidableEq α] [DecidableEq β] {s : Finset (α × β)} : s ⊆ s.image Prod.fst ×ˢ s.image Prod.snd := fun _ hp => mem_product.2 ⟨mem_image_of_mem _ hp, mem_image_of_mem _ hp⟩ @[gcongr] theorem product_subset_product (hs : s ⊆ s') (ht : t ⊆ t') : s ×ˢ t ⊆ s' ×ˢ t' := fun ⟨_, _⟩ h => mem_product.2 ⟨hs (mem_product.1 h).1, ht (mem_product.1 h).2⟩ @[gcongr] theorem product_subset_product_left (hs : s ⊆ s') : s ×ˢ t ⊆ s' ×ˢ t := product_subset_product hs (Subset.refl _) @[gcongr] theorem product_subset_product_right (ht : t ⊆ t') : s ×ˢ t ⊆ s ×ˢ t' := product_subset_product (Subset.refl _) ht theorem prodMap_image_product {δ : Type*} [DecidableEq β] [DecidableEq δ] (f : α → β) (g : γ → δ) (s : Finset α) (t : Finset γ) : (s ×ˢ t).image (Prod.map f g) = s.image f ×ˢ t.image g := mod_cast Set.prodMap_image_prod f g s t theorem prodMap_map_product {δ : Type*} (f : α ↪ β) (g : γ ↪ δ) (s : Finset α) (t : Finset γ) : (s ×ˢ t).map (f.prodMap g) = s.map f ×ˢ t.map g := by simpa [← coe_inj] using Set.prodMap_image_prod f g s t theorem map_swap_product (s : Finset α) (t : Finset β) : (t ×ˢ s).map ⟨Prod.swap, Prod.swap_injective⟩ = s ×ˢ t := coe_injective <| by push_cast exact Set.image_swap_prod _ _ @[simp] theorem image_swap_product [DecidableEq (α × β)] (s : Finset α) (t : Finset β) : (t ×ˢ s).image Prod.swap = s ×ˢ t := coe_injective <| by push_cast exact Set.image_swap_prod _ _ theorem product_eq_biUnion [DecidableEq (α × β)] (s : Finset α) (t : Finset β) : s ×ˢ t = s.biUnion fun a => t.image fun b => (a, b) := ext fun ⟨x, y⟩ => by simp only [mem_product, mem_biUnion, mem_image, exists_prop, Prod.mk_inj, and_left_comm, exists_and_left, exists_eq_right, exists_eq_left] theorem product_eq_biUnion_right [DecidableEq (α × β)] (s : Finset α) (t : Finset β) : s ×ˢ t = t.biUnion fun b => s.image fun a => (a, b) := ext fun ⟨x, y⟩ => by simp only [mem_product, mem_biUnion, mem_image, exists_prop, Prod.mk_inj, and_left_comm, exists_and_left, exists_eq_right, exists_eq_left] /-- See also `Finset.sup_product_left`. -/ @[simp] theorem product_biUnion [DecidableEq γ] (s : Finset α) (t : Finset β) (f : α × β → Finset γ) : (s ×ˢ t).biUnion f = s.biUnion fun a => t.biUnion fun b => f (a, b) := by classical simp_rw [product_eq_biUnion, biUnion_biUnion, image_biUnion] @[simp] theorem card_product (s : Finset α) (t : Finset β) : card (s ×ˢ t) = card s * card t := Multiset.card_product _ _ /-- The product of two Finsets is nontrivial iff both are nonempty at least one of them is nontrivial. -/ lemma nontrivial_prod_iff : (s ×ˢ t).Nontrivial ↔ s.Nonempty ∧ t.Nonempty ∧ (s.Nontrivial ∨ t.Nontrivial) := by simp_rw [← card_pos, ← one_lt_card_iff_nontrivial, card_product]; apply Nat.one_lt_mul_iff theorem filter_product (p : α → Prop) (q : β → Prop) [DecidablePred p] [DecidablePred q] : ((s ×ˢ t).filter fun x : α × β => p x.1 ∧ q x.2) = s.filter p ×ˢ t.filter q := by ext ⟨a, b⟩ simp [mem_filter, mem_product, decide_eq_true_eq, and_comm, and_left_comm, and_assoc] theorem filter_product_left (p : α → Prop) [DecidablePred p] : ((s ×ˢ t).filter fun x : α × β => p x.1) = s.filter p ×ˢ t := by simpa using filter_product p fun _ => true theorem filter_product_right (q : β → Prop) [DecidablePred q] : ((s ×ˢ t).filter fun x : α × β => q x.2) = s ×ˢ t.filter q := by simpa using filter_product (fun _ : α => true) q theorem filter_product_card (s : Finset α) (t : Finset β) (p : α → Prop) (q : β → Prop) [DecidablePred p] [DecidablePred q] : ((s ×ˢ t).filter fun x : α × β => (p x.1) = (q x.2)).card = (s.filter p).card * (t.filter q).card + (s.filter (¬ p ·)).card * (t.filter (¬ q ·)).card := by classical rw [← card_product, ← card_product, ← filter_product, ← filter_product, ← card_union_of_disjoint] · apply congr_arg ext ⟨a, b⟩ simp only [filter_union_right, mem_filter, mem_product]
constructor <;> intro h <;> use h.1 · simp only [h.2, Function.comp_apply, Decidable.em, and_self] · revert h simp only [Function.comp_apply, and_imp] rintro _ _ (_|_) <;> simp [*] · apply Finset.disjoint_filter_filter' exact (disjoint_compl_right.inf_left _).inf_right _ @[simp] theorem empty_product (t : Finset β) : (∅ : Finset α) ×ˢ t = ∅ := rfl @[simp] theorem product_empty (s : Finset α) : s ×ˢ (∅ : Finset β) = ∅ := eq_empty_of_forall_not_mem fun _ h => not_mem_empty _ (Finset.mem_product.1 h).2 @[aesop safe apply (rule_sets := [finsetNonempty])]
Mathlib/Data/Finset/Prod.lean
169
185
/- Copyright (c) 2023 Ziyu Wang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ziyu Wang, Chenyi Li, Sébastien Gouëzel, Penghao Yu, Zhipeng Cao -/ import Mathlib.Analysis.InnerProductSpace.Dual import Mathlib.Analysis.Calculus.FDeriv.Basic import Mathlib.Analysis.Calculus.Deriv.Basic /-! # Gradient ## Main Definitions Let `f` be a function from a Hilbert Space `F` to `𝕜` (`𝕜` is `ℝ` or `ℂ`) , `x` be a point in `F` and `f'` be a vector in F. Then `HasGradientWithinAt f f' s x` says that `f` has a gradient `f'` at `x`, where the domain of interest is restricted to `s`. We also have `HasGradientAt f f' x := HasGradientWithinAt f f' x univ` ## Main results This file contains the following parts of gradient. * the definition of gradient. * the theorems translating between `HasGradientAtFilter` and `HasFDerivAtFilter`, `HasGradientWithinAt` and `HasFDerivWithinAt`, `HasGradientAt` and `HasFDerivAt`, `Gradient` and `fderiv`. * theorems the Uniqueness of Gradient. * the theorems translating between `HasGradientAtFilter` and `HasDerivAtFilter`, `HasGradientAt` and `HasDerivAt`, `Gradient` and `deriv` when `F = 𝕜`. * the theorems about the congruence of the gradient. * the theorems about the gradient of constant function. * the theorems about the continuity of a function admitting a gradient. -/ open Topology InnerProductSpace Set noncomputable section variable {𝕜 F : Type*} [RCLike 𝕜] variable [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] [CompleteSpace F] variable {f : F → 𝕜} {f' x : F} /-- A function `f` has the gradient `f'` as derivative along the filter `L` if `f x' = f x + ⟨f', x' - x⟩ + o (x' - x)` when `x'` converges along the filter `L`. -/ def HasGradientAtFilter (f : F → 𝕜) (f' x : F) (L : Filter F) := HasFDerivAtFilter f (toDual 𝕜 F f') x L /-- `f` has the gradient `f'` at the point `x` within the subset `s` if `f x' = f x + ⟨f', x' - x⟩ + o (x' - x)` where `x'` converges to `x` inside `s`. -/ def HasGradientWithinAt (f : F → 𝕜) (f' : F) (s : Set F) (x : F) := HasGradientAtFilter f f' x (𝓝[s] x) /-- `f` has the gradient `f'` at the point `x` if `f x' = f x + ⟨f', x' - x⟩ + o (x' - x)` where `x'` converges to `x`. -/ def HasGradientAt (f : F → 𝕜) (f' x : F) := HasGradientAtFilter f f' x (𝓝 x) /-- Gradient of `f` at the point `x` within the set `s`, if it exists. Zero otherwise. If the derivative exists (i.e., `∃ f', HasGradientWithinAt f f' s x`), then `f x' = f x + ⟨f', x' - x⟩ + o (x' - x)` where `x'` converges to `x` inside `s`. -/ def gradientWithin (f : F → 𝕜) (s : Set F) (x : F) : F := (toDual 𝕜 F).symm (fderivWithin 𝕜 f s x) /-- Gradient of `f` at the point `x`, if it exists. Zero otherwise. Denoted as `∇` within the Gradient namespace. If the derivative exists (i.e., `∃ f', HasGradientAt f f' x`), then `f x' = f x + ⟨f', x' - x⟩ + o (x' - x)` where `x'` converges to `x`. -/ def gradient (f : F → 𝕜) (x : F) : F := (toDual 𝕜 F).symm (fderiv 𝕜 f x) @[inherit_doc] scoped[Gradient] notation "∇" => gradient local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y open scoped Gradient variable {s : Set F} {L : Filter F} theorem hasGradientWithinAt_iff_hasFDerivWithinAt {s : Set F} : HasGradientWithinAt f f' s x ↔ HasFDerivWithinAt f (toDual 𝕜 F f') s x := Iff.rfl theorem hasFDerivWithinAt_iff_hasGradientWithinAt {frechet : F →L[𝕜] 𝕜} {s : Set F} : HasFDerivWithinAt f frechet s x ↔ HasGradientWithinAt f ((toDual 𝕜 F).symm frechet) s x := by rw [hasGradientWithinAt_iff_hasFDerivWithinAt, (toDual 𝕜 F).apply_symm_apply frechet] theorem hasGradientAt_iff_hasFDerivAt : HasGradientAt f f' x ↔ HasFDerivAt f (toDual 𝕜 F f') x := Iff.rfl theorem hasFDerivAt_iff_hasGradientAt {frechet : F →L[𝕜] 𝕜} : HasFDerivAt f frechet x ↔ HasGradientAt f ((toDual 𝕜 F).symm frechet) x := by rw [hasGradientAt_iff_hasFDerivAt, (toDual 𝕜 F).apply_symm_apply frechet] alias ⟨HasGradientWithinAt.hasFDerivWithinAt, _⟩ := hasGradientWithinAt_iff_hasFDerivWithinAt alias ⟨HasFDerivWithinAt.hasGradientWithinAt, _⟩ := hasFDerivWithinAt_iff_hasGradientWithinAt alias ⟨HasGradientAt.hasFDerivAt, _⟩ := hasGradientAt_iff_hasFDerivAt alias ⟨HasFDerivAt.hasGradientAt, _⟩ := hasFDerivAt_iff_hasGradientAt theorem gradient_eq_zero_of_not_differentiableAt (h : ¬DifferentiableAt 𝕜 f x) : ∇ f x = 0 := by rw [gradient, fderiv_zero_of_not_differentiableAt h, map_zero] theorem HasGradientAt.unique {gradf gradg : F} (hf : HasGradientAt f gradf x) (hg : HasGradientAt f gradg x) : gradf = gradg := (toDual 𝕜 F).injective (hf.hasFDerivAt.unique hg.hasFDerivAt) theorem DifferentiableAt.hasGradientAt (h : DifferentiableAt 𝕜 f x) : HasGradientAt f (∇ f x) x := by rw [hasGradientAt_iff_hasFDerivAt, gradient, (toDual 𝕜 F).apply_symm_apply (fderiv 𝕜 f x)] exact h.hasFDerivAt theorem HasGradientAt.differentiableAt (h : HasGradientAt f f' x) : DifferentiableAt 𝕜 f x := h.hasFDerivAt.differentiableAt theorem DifferentiableWithinAt.hasGradientWithinAt (h : DifferentiableWithinAt 𝕜 f s x) : HasGradientWithinAt f (gradientWithin f s x) s x := by rw [hasGradientWithinAt_iff_hasFDerivWithinAt, gradientWithin, (toDual 𝕜 F).apply_symm_apply (fderivWithin 𝕜 f s x)] exact h.hasFDerivWithinAt theorem HasGradientWithinAt.differentiableWithinAt (h : HasGradientWithinAt f f' s x) : DifferentiableWithinAt 𝕜 f s x := h.hasFDerivWithinAt.differentiableWithinAt @[simp] theorem hasGradientWithinAt_univ : HasGradientWithinAt f f' univ x ↔ HasGradientAt f f' x := by rw [hasGradientWithinAt_iff_hasFDerivWithinAt, hasGradientAt_iff_hasFDerivAt] exact hasFDerivWithinAt_univ theorem DifferentiableOn.hasGradientAt (h : DifferentiableOn 𝕜 f s) (hs : s ∈ 𝓝 x) : HasGradientAt f (∇ f x) x := (h.hasFDerivAt hs).hasGradientAt theorem HasGradientAt.gradient (h : HasGradientAt f f' x) : ∇ f x = f' := h.differentiableAt.hasGradientAt.unique h theorem gradient_eq {f' : F → F} (h : ∀ x, HasGradientAt f (f' x) x) : ∇ f = f' := funext fun x => (h x).gradient section OneDimension variable {g : 𝕜 → 𝕜} {g' u : 𝕜} {L' : Filter 𝕜} theorem HasGradientAtFilter.hasDerivAtFilter (h : HasGradientAtFilter g g' u L') : HasDerivAtFilter g (starRingEnd 𝕜 g') u L' := by have : ContinuousLinearMap.smulRight (1 : 𝕜 →L[𝕜] 𝕜) (starRingEnd 𝕜 g') = (toDual 𝕜 𝕜) g' := by ext; simp rwa [HasDerivAtFilter, this] theorem HasDerivAtFilter.hasGradientAtFilter (h : HasDerivAtFilter g g' u L') : HasGradientAtFilter g (starRingEnd 𝕜 g') u L' := by have : ContinuousLinearMap.smulRight (1 : 𝕜 →L[𝕜] 𝕜) g' = (toDual 𝕜 𝕜) (starRingEnd 𝕜 g') := by ext; simp rwa [HasGradientAtFilter, ← this] theorem HasGradientAt.hasDerivAt (h : HasGradientAt g g' u) : HasDerivAt g (starRingEnd 𝕜 g') u := by rw [hasGradientAt_iff_hasFDerivAt, hasFDerivAt_iff_hasDerivAt] at h simpa using h theorem HasDerivAt.hasGradientAt (h : HasDerivAt g g' u) : HasGradientAt g (starRingEnd 𝕜 g') u := by rw [hasGradientAt_iff_hasFDerivAt, hasFDerivAt_iff_hasDerivAt] simpa theorem gradient_eq_deriv : ∇ g u = starRingEnd 𝕜 (deriv g u) := by by_cases h : DifferentiableAt 𝕜 g u · rw [h.hasGradientAt.hasDerivAt.deriv, RCLike.conj_conj] · rw [gradient_eq_zero_of_not_differentiableAt h, deriv_zero_of_not_differentiableAt h, map_zero] end OneDimension section OneDimensionReal variable {g : ℝ → ℝ} {g' u : ℝ} {L' : Filter ℝ} theorem HasGradientAtFilter.hasDerivAtFilter' (h : HasGradientAtFilter g g' u L') : HasDerivAtFilter g g' u L' := h.hasDerivAtFilter theorem HasDerivAtFilter.hasGradientAtFilter' (h : HasDerivAtFilter g g' u L') : HasGradientAtFilter g g' u L' := h.hasGradientAtFilter theorem HasGradientAt.hasDerivAt' (h : HasGradientAt g g' u) : HasDerivAt g g' u := h.hasDerivAt theorem HasDerivAt.hasGradientAt' (h : HasDerivAt g g' u) : HasGradientAt g g' u := h.hasGradientAt theorem gradient_eq_deriv' : ∇ g u = deriv g u := gradient_eq_deriv end OneDimensionReal open Filter section GradientProperties theorem hasGradientAtFilter_iff_isLittleO : HasGradientAtFilter f f' x L ↔ (fun x' : F => f x' - f x - ⟪f', x' - x⟫) =o[L] fun x' => x' - x := hasFDerivAtFilter_iff_isLittleO .. theorem hasGradientWithinAt_iff_isLittleO : HasGradientWithinAt f f' s x ↔ (fun x' : F => f x' - f x - ⟪f', x' - x⟫) =o[𝓝[s] x] fun x' => x' - x := hasGradientAtFilter_iff_isLittleO theorem hasGradientWithinAt_iff_tendsto : HasGradientWithinAt f f' s x ↔ Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - ⟪f', x' - x⟫‖) (𝓝[s] x) (𝓝 0) := hasFDerivAtFilter_iff_tendsto theorem hasGradientAt_iff_isLittleO : HasGradientAt f f' x ↔ (fun x' : F => f x' - f x - ⟪f', x' - x⟫) =o[𝓝 x] fun x' => x' - x := hasGradientAtFilter_iff_isLittleO theorem hasGradientAt_iff_tendsto : HasGradientAt f f' x ↔ Tendsto (fun x' => ‖x' - x‖⁻¹ * ‖f x' - f x - ⟪f', x' - x⟫‖) (𝓝 x) (𝓝 0) := hasFDerivAtFilter_iff_tendsto theorem HasGradientAtFilter.isBigO_sub (h : HasGradientAtFilter f f' x L) : (fun x' => f x' - f x) =O[L] fun x' => x' - x := HasFDerivAtFilter.isBigO_sub h theorem hasGradientWithinAt_congr_set' {s t : Set F} (y : F) (h : s =ᶠ[𝓝[{y}ᶜ] x] t) : HasGradientWithinAt f f' s x ↔ HasGradientWithinAt f f' t x := hasFDerivWithinAt_congr_set' y h theorem hasGradientWithinAt_congr_set {s t : Set F} (h : s =ᶠ[𝓝 x] t) : HasGradientWithinAt f f' s x ↔ HasGradientWithinAt f f' t x := hasFDerivWithinAt_congr_set h theorem hasGradientAt_iff_isLittleO_nhds_zero : HasGradientAt f f' x ↔ (fun h => f (x + h) - f x - ⟪f', h⟫) =o[𝓝 0] fun h => h := hasFDerivAt_iff_isLittleO_nhds_zero end GradientProperties section congr /-! ### Congruence properties of the Gradient -/ variable {f₀ f₁ : F → 𝕜} {f₀' f₁' : F} {t : Set F} theorem Filter.EventuallyEq.hasGradientAtFilter_iff (h₀ : f₀ =ᶠ[L] f₁) (hx : f₀ x = f₁ x) (h₁ : f₀' = f₁') : HasGradientAtFilter f₀ f₀' x L ↔ HasGradientAtFilter f₁ f₁' x L := h₀.hasFDerivAtFilter_iff hx (by simp [h₁])
theorem HasGradientAtFilter.congr_of_eventuallyEq (h : HasGradientAtFilter f f' x L) (hL : f₁ =ᶠ[L] f) (hx : f₁ x = f x) : HasGradientAtFilter f₁ f' x L := by
Mathlib/Analysis/Calculus/Gradient/Basic.lean
261
263
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Mario Carneiro -/ import Mathlib.Data.Bool.Basic import Mathlib.Data.FunLike.Equiv import Mathlib.Data.Quot import Mathlib.Data.Subtype import Mathlib.Logic.Unique import Mathlib.Tactic.Conv import Mathlib.Tactic.Simps.Basic import Mathlib.Tactic.Substs /-! # Equivalence between types In this file we define two types: * `Equiv α β` a.k.a. `α ≃ β`: a bijective map `α → β` bundled with its inverse map; we use this (and not equality!) to express that various `Type`s or `Sort`s are equivalent. * `Equiv.Perm α`: the group of permutations `α ≃ α`. More lemmas about `Equiv.Perm` can be found in `Mathlib.GroupTheory.Perm`. Then we define * canonical isomorphisms between various types: e.g., - `Equiv.refl α` is the identity map interpreted as `α ≃ α`; * operations on equivalences: e.g., - `Equiv.symm e : β ≃ α` is the inverse of `e : α ≃ β`; - `Equiv.trans e₁ e₂ : α ≃ γ` is the composition of `e₁ : α ≃ β` and `e₂ : β ≃ γ` (note the order of the arguments!); * definitions that transfer some instances along an equivalence. By convention, we transfer instances from right to left. - `Equiv.inhabited` takes `e : α ≃ β` and `[Inhabited β]` and returns `Inhabited α`; - `Equiv.unique` takes `e : α ≃ β` and `[Unique β]` and returns `Unique α`; - `Equiv.decidableEq` takes `e : α ≃ β` and `[DecidableEq β]` and returns `DecidableEq α`. More definitions of this kind can be found in other files. E.g., `Mathlib.Algebra.Equiv.TransferInstance` does it for many algebraic type classes like `Group`, `Module`, etc. Many more such isomorphisms and operations are defined in `Mathlib.Logic.Equiv.Basic`. ## Tags equivalence, congruence, bijective map -/ open Function universe u v w z variable {α : Sort u} {β : Sort v} {γ : Sort w} /-- `α ≃ β` is the type of functions from `α → β` with a two-sided inverse. -/ structure Equiv (α : Sort*) (β : Sort _) where protected toFun : α → β protected invFun : β → α protected left_inv : LeftInverse invFun toFun protected right_inv : RightInverse invFun toFun @[inherit_doc] infixl:25 " ≃ " => Equiv /-- Turn an element of a type `F` satisfying `EquivLike F α β` into an actual `Equiv`. This is declared as the default coercion from `F` to `α ≃ β`. -/ @[coe] def EquivLike.toEquiv {F} [EquivLike F α β] (f : F) : α ≃ β where toFun := f invFun := EquivLike.inv f left_inv := EquivLike.left_inv f right_inv := EquivLike.right_inv f /-- Any type satisfying `EquivLike` can be cast into `Equiv` via `EquivLike.toEquiv`. -/ instance {F} [EquivLike F α β] : CoeTC F (α ≃ β) := ⟨EquivLike.toEquiv⟩ /-- `Perm α` is the type of bijections from `α` to itself. -/ abbrev Equiv.Perm (α : Sort*) := Equiv α α namespace Equiv instance : EquivLike (α ≃ β) α β where coe := Equiv.toFun inv := Equiv.invFun left_inv := Equiv.left_inv right_inv := Equiv.right_inv coe_injective' e₁ e₂ h₁ h₂ := by cases e₁; cases e₂; congr /-- Helper instance when inference gets stuck on following the normal chain `EquivLike → FunLike`. TODO: this instance doesn't appear to be necessary: remove it (after benchmarking?) -/ instance : FunLike (α ≃ β) α β where coe := Equiv.toFun coe_injective' := DFunLike.coe_injective @[simp, norm_cast] lemma _root_.EquivLike.coe_coe {F} [EquivLike F α β] (e : F) : ((e : α ≃ β) : α → β) = e := rfl @[simp] theorem coe_fn_mk (f : α → β) (g l r) : (Equiv.mk f g l r : α → β) = f := rfl /-- The map `(r ≃ s) → (r → s)` is injective. -/ theorem coe_fn_injective : @Function.Injective (α ≃ β) (α → β) (fun e => e) := DFunLike.coe_injective' protected theorem coe_inj {e₁ e₂ : α ≃ β} : (e₁ : α → β) = e₂ ↔ e₁ = e₂ := @DFunLike.coe_fn_eq _ _ _ _ e₁ e₂ @[ext] theorem ext {f g : Equiv α β} (H : ∀ x, f x = g x) : f = g := DFunLike.ext f g H protected theorem congr_arg {f : Equiv α β} {x x' : α} : x = x' → f x = f x' := DFunLike.congr_arg f protected theorem congr_fun {f g : Equiv α β} (h : f = g) (x : α) : f x = g x := DFunLike.congr_fun h x @[ext] theorem Perm.ext {σ τ : Equiv.Perm α} (H : ∀ x, σ x = τ x) : σ = τ := Equiv.ext H protected theorem Perm.congr_arg {f : Equiv.Perm α} {x x' : α} : x = x' → f x = f x' := Equiv.congr_arg protected theorem Perm.congr_fun {f g : Equiv.Perm α} (h : f = g) (x : α) : f x = g x := Equiv.congr_fun h x /-- Any type is equivalent to itself. -/ @[refl] protected def refl (α : Sort*) : α ≃ α := ⟨id, id, fun _ => rfl, fun _ => rfl⟩ instance inhabited' : Inhabited (α ≃ α) := ⟨Equiv.refl α⟩ /-- Inverse of an equivalence `e : α ≃ β`. -/ @[symm] protected def symm (e : α ≃ β) : β ≃ α := ⟨e.invFun, e.toFun, e.right_inv, e.left_inv⟩ /-- See Note [custom simps projection] -/ def Simps.symm_apply (e : α ≃ β) : β → α := e.symm initialize_simps_projections Equiv (toFun → apply, invFun → symm_apply) /-- Restatement of `Equiv.left_inv` in terms of `Function.LeftInverse`. -/ theorem left_inv' (e : α ≃ β) : Function.LeftInverse e.symm e := e.left_inv /-- Restatement of `Equiv.right_inv` in terms of `Function.RightInverse`. -/ theorem right_inv' (e : α ≃ β) : Function.RightInverse e.symm e := e.right_inv /-- Composition of equivalences `e₁ : α ≃ β` and `e₂ : β ≃ γ`. -/ @[trans] protected def trans (e₁ : α ≃ β) (e₂ : β ≃ γ) : α ≃ γ := ⟨e₂ ∘ e₁, e₁.symm ∘ e₂.symm, e₂.left_inv.comp e₁.left_inv, e₂.right_inv.comp e₁.right_inv⟩ @[simps] instance : Trans Equiv Equiv Equiv where trans := Equiv.trans @[simp, mfld_simps] theorem toFun_as_coe (e : α ≃ β) : e.toFun = e := rfl @[simp, mfld_simps] theorem invFun_as_coe (e : α ≃ β) : e.invFun = e.symm := rfl protected theorem injective (e : α ≃ β) : Injective e := EquivLike.injective e protected theorem surjective (e : α ≃ β) : Surjective e := EquivLike.surjective e protected theorem bijective (e : α ≃ β) : Bijective e := EquivLike.bijective e protected theorem subsingleton (e : α ≃ β) [Subsingleton β] : Subsingleton α := e.injective.subsingleton protected theorem subsingleton.symm (e : α ≃ β) [Subsingleton α] : Subsingleton β := e.symm.injective.subsingleton theorem subsingleton_congr (e : α ≃ β) : Subsingleton α ↔ Subsingleton β := ⟨fun _ => e.symm.subsingleton, fun _ => e.subsingleton⟩ instance equiv_subsingleton_cod [Subsingleton β] : Subsingleton (α ≃ β) := ⟨fun _ _ => Equiv.ext fun _ => Subsingleton.elim _ _⟩ instance equiv_subsingleton_dom [Subsingleton α] : Subsingleton (α ≃ β) := ⟨fun f _ => Equiv.ext fun _ => @Subsingleton.elim _ (Equiv.subsingleton.symm f) _ _⟩ instance permUnique [Subsingleton α] : Unique (Perm α) := uniqueOfSubsingleton (Equiv.refl α) theorem Perm.subsingleton_eq_refl [Subsingleton α] (e : Perm α) : e = Equiv.refl α := Subsingleton.elim _ _ protected theorem nontrivial {α β} (e : α ≃ β) [Nontrivial β] : Nontrivial α := e.surjective.nontrivial theorem nontrivial_congr {α β} (e : α ≃ β) : Nontrivial α ↔ Nontrivial β := ⟨fun _ ↦ e.symm.nontrivial, fun _ ↦ e.nontrivial⟩ /-- Transfer `DecidableEq` across an equivalence. -/ protected def decidableEq (e : α ≃ β) [DecidableEq β] : DecidableEq α := e.injective.decidableEq theorem nonempty_congr (e : α ≃ β) : Nonempty α ↔ Nonempty β := Nonempty.congr e e.symm protected theorem nonempty (e : α ≃ β) [Nonempty β] : Nonempty α := e.nonempty_congr.mpr ‹_› /-- If `α ≃ β` and `β` is inhabited, then so is `α`. -/ protected def inhabited [Inhabited β] (e : α ≃ β) : Inhabited α := ⟨e.symm default⟩ /-- If `α ≃ β` and `β` is a singleton type, then so is `α`. -/ protected def unique [Unique β] (e : α ≃ β) : Unique α := e.symm.surjective.unique /-- Equivalence between equal types. -/ protected def cast {α β : Sort _} (h : α = β) : α ≃ β := ⟨cast h, cast h.symm, fun _ => by cases h; rfl, fun _ => by cases h; rfl⟩ @[simp] theorem coe_fn_symm_mk (f : α → β) (g l r) : ((Equiv.mk f g l r).symm : β → α) = g := rfl @[simp] theorem coe_refl : (Equiv.refl α : α → α) = id := rfl /-- This cannot be a `simp` lemmas as it incorrectly matches against `e : α ≃ synonym α`, when `synonym α` is semireducible. This makes a mess of `Multiplicative.ofAdd` etc. -/ theorem Perm.coe_subsingleton {α : Type*} [Subsingleton α] (e : Perm α) : (e : α → α) = id := by rw [Perm.subsingleton_eq_refl e, coe_refl] @[simp] theorem refl_apply (x : α) : Equiv.refl α x = x := rfl @[simp] theorem coe_trans (f : α ≃ β) (g : β ≃ γ) : (f.trans g : α → γ) = g ∘ f := rfl @[simp] theorem trans_apply (f : α ≃ β) (g : β ≃ γ) (a : α) : (f.trans g) a = g (f a) := rfl @[simp] theorem apply_symm_apply (e : α ≃ β) (x : β) : e (e.symm x) = x := e.right_inv x @[simp] theorem symm_apply_apply (e : α ≃ β) (x : α) : e.symm (e x) = x := e.left_inv x @[simp] theorem symm_comp_self (e : α ≃ β) : e.symm ∘ e = id := funext e.symm_apply_apply @[simp] theorem self_comp_symm (e : α ≃ β) : e ∘ e.symm = id := funext e.apply_symm_apply @[simp] lemma _root_.EquivLike.apply_coe_symm_apply {F} [EquivLike F α β] (e : F) (x : β) : e ((e : α ≃ β).symm x) = x := (e : α ≃ β).apply_symm_apply x @[simp] lemma _root_.EquivLike.coe_symm_apply_apply {F} [EquivLike F α β] (e : F) (x : α) : (e : α ≃ β).symm (e x) = x := (e : α ≃ β).symm_apply_apply x @[simp] lemma _root_.EquivLike.coe_symm_comp_self {F} [EquivLike F α β] (e : F) : (e : α ≃ β).symm ∘ e = id := (e : α ≃ β).symm_comp_self @[simp] lemma _root_.EquivLike.self_comp_coe_symm {F} [EquivLike F α β] (e : F) : e ∘ (e : α ≃ β).symm = id := (e : α ≃ β).self_comp_symm @[simp] theorem symm_trans_apply (f : α ≃ β) (g : β ≃ γ) (a : γ) : (f.trans g).symm a = f.symm (g.symm a) := rfl theorem symm_symm_apply (f : α ≃ β) (b : α) : f.symm.symm b = f b := rfl theorem apply_eq_iff_eq (f : α ≃ β) {x y : α} : f x = f y ↔ x = y := EquivLike.apply_eq_iff_eq f theorem apply_eq_iff_eq_symm_apply {x : α} {y : β} (f : α ≃ β) : f x = y ↔ x = f.symm y := by conv_lhs => rw [← apply_symm_apply f y] rw [apply_eq_iff_eq] @[simp] theorem cast_apply {α β} (h : α = β) (x : α) : Equiv.cast h x = cast h x := rfl @[simp] theorem cast_symm {α β} (h : α = β) : (Equiv.cast h).symm = Equiv.cast h.symm := rfl @[simp] theorem cast_refl {α} (h : α = α := rfl) : Equiv.cast h = Equiv.refl α := rfl @[simp] theorem cast_trans {α β γ} (h : α = β) (h2 : β = γ) : (Equiv.cast h).trans (Equiv.cast h2) = Equiv.cast (h.trans h2) := ext fun x => by substs h h2; rfl theorem cast_eq_iff_heq {α β} (h : α = β) {a : α} {b : β} : Equiv.cast h a = b ↔ HEq a b := by subst h; simp [coe_refl] theorem symm_apply_eq {α β} (e : α ≃ β) {x y} : e.symm x = y ↔ x = e y := ⟨fun H => by simp [H.symm], fun H => by simp [H]⟩ theorem eq_symm_apply {α β} (e : α ≃ β) {x y} : y = e.symm x ↔ e y = x := (eq_comm.trans e.symm_apply_eq).trans eq_comm @[simp] theorem symm_symm (e : α ≃ β) : e.symm.symm = e := rfl theorem symm_bijective : Function.Bijective (Equiv.symm : (α ≃ β) → β ≃ α) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ @[simp] theorem trans_refl (e : α ≃ β) : e.trans (Equiv.refl β) = e := by cases e; rfl @[simp] theorem refl_symm : (Equiv.refl α).symm = Equiv.refl α := rfl @[simp] theorem refl_trans (e : α ≃ β) : (Equiv.refl α).trans e = e := by cases e; rfl @[simp] theorem symm_trans_self (e : α ≃ β) : e.symm.trans e = Equiv.refl β := ext <| by simp @[simp] theorem self_trans_symm (e : α ≃ β) : e.trans e.symm = Equiv.refl α := ext <| by simp theorem trans_assoc {δ} (ab : α ≃ β) (bc : β ≃ γ) (cd : γ ≃ δ) : (ab.trans bc).trans cd = ab.trans (bc.trans cd) := Equiv.ext fun _ => rfl theorem leftInverse_symm (f : Equiv α β) : LeftInverse f.symm f := f.left_inv theorem rightInverse_symm (f : Equiv α β) : Function.RightInverse f.symm f := f.right_inv theorem injective_comp (e : α ≃ β) (f : β → γ) : Injective (f ∘ e) ↔ Injective f := EquivLike.injective_comp e f theorem comp_injective (f : α → β) (e : β ≃ γ) : Injective (e ∘ f) ↔ Injective f := EquivLike.comp_injective f e theorem surjective_comp (e : α ≃ β) (f : β → γ) : Surjective (f ∘ e) ↔ Surjective f := EquivLike.surjective_comp e f theorem comp_surjective (f : α → β) (e : β ≃ γ) : Surjective (e ∘ f) ↔ Surjective f := EquivLike.comp_surjective f e theorem bijective_comp (e : α ≃ β) (f : β → γ) : Bijective (f ∘ e) ↔ Bijective f := EquivLike.bijective_comp e f theorem comp_bijective (f : α → β) (e : β ≃ γ) : Bijective (e ∘ f) ↔ Bijective f := EquivLike.comp_bijective f e /-- If `α` is equivalent to `β` and `γ` is equivalent to `δ`, then the type of equivalences `α ≃ γ` is equivalent to the type of equivalences `β ≃ δ`. -/ def equivCongr {δ : Sort*} (ab : α ≃ β) (cd : γ ≃ δ) : (α ≃ γ) ≃ (β ≃ δ) where toFun ac := (ab.symm.trans ac).trans cd invFun bd := ab.trans <| bd.trans <| cd.symm left_inv ac := by ext x; simp only [trans_apply, comp_apply, symm_apply_apply] right_inv ac := by ext x; simp only [trans_apply, comp_apply, apply_symm_apply] @[simp] theorem equivCongr_refl {α β} : (Equiv.refl α).equivCongr (Equiv.refl β) = Equiv.refl (α ≃ β) := by ext; rfl @[simp] theorem equivCongr_symm {δ} (ab : α ≃ β) (cd : γ ≃ δ) : (ab.equivCongr cd).symm = ab.symm.equivCongr cd.symm := by ext; rfl @[simp] theorem equivCongr_trans {δ ε ζ} (ab : α ≃ β) (de : δ ≃ ε) (bc : β ≃ γ) (ef : ε ≃ ζ) : (ab.equivCongr de).trans (bc.equivCongr ef) = (ab.trans bc).equivCongr (de.trans ef) := by ext; rfl @[simp] theorem equivCongr_refl_left {α β γ} (bg : β ≃ γ) (e : α ≃ β) : (Equiv.refl α).equivCongr bg e = e.trans bg := rfl
Mathlib/Logic/Equiv/Defs.lean
350
350
/- Copyright (c) 2019 Jan-David Salchow. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jan-David Salchow, Sébastien Gouëzel, Jean Lo -/ import Mathlib.Analysis.NormedSpace.OperatorNorm.Bilinear import Mathlib.Analysis.NormedSpace.OperatorNorm.NNNorm import Mathlib.Analysis.Normed.Module.Span /-! # Operator norm for maps on normed spaces This file contains statements about operator norm for which it really matters that the underlying space has a norm (rather than just a seminorm). -/ suppress_compilation open Topology open scoped NNReal -- the `ₗ` subscript variables are for special cases about linear (as opposed to semilinear) maps variable {𝕜 𝕜₂ 𝕜₃ E F Fₗ G : Type*} section Normed variable [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedAddCommGroup G] [NormedAddCommGroup Fₗ] open Metric ContinuousLinearMap section variable [NontriviallyNormedField 𝕜] [NontriviallyNormedField 𝕜₂] [NontriviallyNormedField 𝕜₃] [NormedSpace 𝕜 E] [NormedSpace 𝕜₂ F] [NormedSpace 𝕜₃ G] [NormedSpace 𝕜 Fₗ] {σ₁₂ : 𝕜 →+* 𝕜₂} {σ₂₃ : 𝕜₂ →+* 𝕜₃} (f : E →SL[σ₁₂] F) namespace LinearMap theorem bound_of_shell [RingHomIsometric σ₁₂] (f : E →ₛₗ[σ₁₂] F) {ε C : ℝ} (ε_pos : 0 < ε) {c : 𝕜} (hc : 1 < ‖c‖) (hf : ∀ x, ε / ‖c‖ ≤ ‖x‖ → ‖x‖ < ε → ‖f x‖ ≤ C * ‖x‖) (x : E) : ‖f x‖ ≤ C * ‖x‖ := by by_cases hx : x = 0; · simp [hx] exact SemilinearMapClass.bound_of_shell_semi_normed f ε_pos hc hf (norm_ne_zero_iff.2 hx) /-- `LinearMap.bound_of_ball_bound'` is a version of this lemma over a field satisfying `RCLike` that produces a concrete bound. -/ theorem bound_of_ball_bound {r : ℝ} (r_pos : 0 < r) (c : ℝ) (f : E →ₗ[𝕜] Fₗ) (h : ∀ z ∈ Metric.ball (0 : E) r, ‖f z‖ ≤ c) : ∃ C, ∀ z : E, ‖f z‖ ≤ C * ‖z‖ := by obtain ⟨k, hk⟩ := @NontriviallyNormedField.non_trivial 𝕜 _ use c * (‖k‖ / r) intro z refine bound_of_shell _ r_pos hk (fun x hko hxo => ?_) _ calc ‖f x‖ ≤ c := h _ (mem_ball_zero_iff.mpr hxo) _ ≤ c * (‖x‖ * ‖k‖ / r) := le_mul_of_one_le_right ?_ ?_ _ = _ := by ring · exact le_trans (norm_nonneg _) (h 0 (by simp [r_pos])) · rw [div_le_iff₀ (zero_lt_one.trans hk)] at hko exact (one_le_div r_pos).mpr hko theorem antilipschitz_of_comap_nhds_le [h : RingHomIsometric σ₁₂] (f : E →ₛₗ[σ₁₂] F) (hf : (𝓝 0).comap f ≤ 𝓝 0) : ∃ K, AntilipschitzWith K f := by rcases ((nhds_basis_ball.comap _).le_basis_iff nhds_basis_ball).1 hf 1 one_pos with ⟨ε, ε0, hε⟩
simp only [Set.subset_def, Set.mem_preimage, mem_ball_zero_iff] at hε lift ε to ℝ≥0 using ε0.le rcases NormedField.exists_one_lt_norm 𝕜 with ⟨c, hc⟩ refine ⟨ε⁻¹ * ‖c‖₊, AddMonoidHomClass.antilipschitz_of_bound f fun x => ?_⟩ by_cases hx : f x = 0 · rw [← hx] at hf obtain rfl : x = 0 := Specializes.eq (specializes_iff_pure.2 <| ((Filter.tendsto_pure_pure _ _).mono_right (pure_le_nhds _)).le_comap.trans hf) exact norm_zero.trans_le (mul_nonneg (NNReal.coe_nonneg _) (norm_nonneg _)) have hc₀ : c ≠ 0 := norm_pos_iff.1 (one_pos.trans hc) rw [← h.1] at hc rcases rescale_to_shell_zpow hc ε0 hx with ⟨n, -, hlt, -, hle⟩ simp only [← map_zpow₀, h.1, ← map_smulₛₗ] at hlt hle calc ‖x‖ = ‖c ^ n‖⁻¹ * ‖c ^ n • x‖ := by rwa [← norm_inv, ← norm_smul, inv_smul_smul₀ (zpow_ne_zero _ _)] _ ≤ ‖c ^ n‖⁻¹ * 1 := (mul_le_mul_of_nonneg_left (hε _ hlt).le (inv_nonneg.2 (norm_nonneg _))) _ ≤ ε⁻¹ * ‖c‖ * ‖f x‖ := by rwa [mul_one] end LinearMap
Mathlib/Analysis/NormedSpace/OperatorNorm/NormedSpace.lean
67
87
/- 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.Order.Bounds.Basic /-! # Intervals in Lattices In this file, we provide instances of lattice structures on intervals within lattices. Some of them depend on the order of the endpoints of the interval, and thus are not made global instances. These are probably not all of the lattice instances that could be placed on these intervals, but more can be added easily along the same lines when needed. ## Main definitions In the following, `*` can represent either `c`, `o`, or `i`. * `Set.Ic*.orderBot` * `Set.Ii*.semillaticeInf` * `Set.I*c.orderTop` * `Set.I*c.semillaticeInf` * `Set.I**.lattice` * `Set.Iic.boundedOrder`, within an `OrderBot` * `Set.Ici.boundedOrder`, within an `OrderTop` -/ variable {α : Type*} namespace Set namespace Ico instance semilatticeInf [SemilatticeInf α] {a b : α} : SemilatticeInf (Ico a b) := Subtype.semilatticeInf fun _ _ hx hy => ⟨le_inf hx.1 hy.1, lt_of_le_of_lt inf_le_left hx.2⟩ /-- `Ico a b` has a bottom element whenever `a < b`. -/ protected abbrev orderBot [PartialOrder α] {a b : α} (h : a < b) : OrderBot (Ico a b) := (isLeast_Ico h).orderBot end Ico namespace Iio instance semilatticeInf [SemilatticeInf α] {a : α} : SemilatticeInf (Iio a) := Subtype.semilatticeInf fun _ _ hx _ => lt_of_le_of_lt inf_le_left hx end Iio namespace Ioc instance semilatticeSup [SemilatticeSup α] {a b : α} : SemilatticeSup (Ioc a b) := Subtype.semilatticeSup fun _ _ hx hy => ⟨lt_of_lt_of_le hx.1 le_sup_left, sup_le hx.2 hy.2⟩ /-- `Ioc a b` has a top element whenever `a < b`. -/ protected abbrev orderTop [PartialOrder α] {a b : α} (h : a < b) : OrderTop (Ioc a b) := (isGreatest_Ioc h).orderTop end Ioc namespace Ioi instance semilatticeSup [SemilatticeSup α] {a : α} : SemilatticeSup (Ioi a) := Subtype.semilatticeSup fun _ _ hx _ => lt_of_lt_of_le hx le_sup_left end Ioi namespace Iic variable {a : α} instance semilatticeInf [SemilatticeInf α] : SemilatticeInf (Iic a) := Subtype.semilatticeInf fun _ _ hx _ => le_trans inf_le_left hx @[simp, norm_cast] protected lemma coe_inf [SemilatticeInf α] {x y : Iic a} : (↑(x ⊓ y) : α) = (x : α) ⊓ (y : α) := rfl instance semilatticeSup [SemilatticeSup α] : SemilatticeSup (Iic a) := Subtype.semilatticeSup fun _ _ hx hy => sup_le hx hy @[simp, norm_cast] protected lemma coe_sup [SemilatticeSup α] {x y : Iic a} : (↑(x ⊔ y) : α) = (x : α) ⊔ (y : α) := rfl instance [Lattice α] : Lattice (Iic a) := { Iic.semilatticeInf, Iic.semilatticeSup with } instance orderTop [Preorder α] : OrderTop (Iic a) where top := ⟨a, le_refl a⟩ le_top x := x.prop @[simp] theorem coe_top [Preorder α] : (⊤ : Iic a) = a := rfl protected lemma eq_top_iff [Preorder α] {x : Iic a} : x = ⊤ ↔ (x : α) = a := by simp [Subtype.ext_iff] instance orderBot [Preorder α] [OrderBot α] : OrderBot (Iic a) where bot := ⟨⊥, bot_le⟩ bot_le := fun ⟨_, _⟩ => Subtype.mk_le_mk.2 bot_le @[simp] theorem coe_bot [Preorder α] [OrderBot α] : (⊥ : Iic a) = (⊥ : α) := rfl instance [Preorder α] [OrderBot α] : BoundedOrder (Iic a) := { Iic.orderTop, Iic.orderBot with } protected lemma disjoint_iff [SemilatticeInf α] [OrderBot α] {x y : Iic a} : Disjoint x y ↔ Disjoint (x : α) (y : α) := by simp [_root_.disjoint_iff, Subtype.ext_iff] protected lemma codisjoint_iff [SemilatticeSup α] {x y : Iic a} : Codisjoint x y ↔ (x : α) ⊔ (y : α) = a := by
simpa only [_root_.codisjoint_iff] using Iic.eq_top_iff protected lemma isCompl_iff [Lattice α] [OrderBot α] {x y : Iic a} :
Mathlib/Order/LatticeIntervals.lean
123
125
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Bhavik Mehta -/ import Mathlib.CategoryTheory.Monad.Basic import Mathlib.CategoryTheory.Adjunction.Basic import Mathlib.CategoryTheory.Functor.EpiMono /-! # Eilenberg-Moore (co)algebras for a (co)monad This file defines Eilenberg-Moore (co)algebras for a (co)monad, and provides the category instance for them. Further it defines the adjoint pair of free and forgetful functors, respectively from and to the original category, as well as the adjoint pair of forgetful and cofree functors, respectively from and to the original category. ## References * [Riehl, *Category theory in context*, Section 5.2.4][riehl2017] -/ namespace CategoryTheory open Category universe v₁ u₁ -- morphism levels before object levels. See note [category_theory universes]. variable {C : Type u₁} [Category.{v₁} C] namespace Monad /-- An Eilenberg-Moore algebra for a monad `T`. cf Definition 5.2.3 in [Riehl][riehl2017]. -/ structure Algebra (T : Monad C) : Type max u₁ v₁ where /-- The underlying object associated to an algebra. -/ A : C /-- The structure morphism associated to an algebra. -/ a : (T : C ⥤ C).obj A ⟶ A /-- The unit axiom associated to an algebra. -/ unit : T.η.app A ≫ a = 𝟙 A := by aesop_cat /-- The associativity axiom associated to an algebra. -/ assoc : T.μ.app A ≫ a = (T : C ⥤ C).map a ≫ a := by aesop_cat attribute [reassoc] Algebra.unit Algebra.assoc namespace Algebra variable {T : Monad C} /-- A morphism of Eilenberg–Moore algebras for the monad `T`. -/ @[ext] structure Hom (A B : Algebra T) where /-- The underlying morphism associated to a morphism of algebras. -/ f : A.A ⟶ B.A /-- Compatibility with the structure morphism, for a morphism of algebras. -/ h : (T : C ⥤ C).map f ≫ B.a = A.a ≫ f := by aesop_cat -- Porting note: no need to restate axioms in lean4. --restate_axiom hom.h attribute [reassoc (attr := simp)] Hom.h namespace Hom /-- The identity homomorphism for an Eilenberg–Moore algebra. -/ def id (A : Algebra T) : Hom A A where f := 𝟙 A.A instance (A : Algebra T) : Inhabited (Hom A A) := ⟨{ f := 𝟙 _ }⟩ /-- Composition of Eilenberg–Moore algebra homomorphisms. -/ def comp {P Q R : Algebra T} (f : Hom P Q) (g : Hom Q R) : Hom P R where f := f.f ≫ g.f end Hom instance : CategoryStruct (Algebra T) where Hom := Hom id := Hom.id comp := @Hom.comp _ _ _ -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): Adding this `ext` lemma to help automation below. @[ext] lemma Hom.ext' (X Y : Algebra T) (f g : X ⟶ Y) (h : f.f = g.f) : f = g := Hom.ext h @[simp] theorem comp_eq_comp {A A' A'' : Algebra T} (f : A ⟶ A') (g : A' ⟶ A'') : Algebra.Hom.comp f g = f ≫ g := rfl @[simp] theorem id_eq_id (A : Algebra T) : Algebra.Hom.id A = 𝟙 A := rfl @[simp] theorem id_f (A : Algebra T) : (𝟙 A : A ⟶ A).f = 𝟙 A.A := rfl @[simp] theorem comp_f {A A' A'' : Algebra T} (f : A ⟶ A') (g : A' ⟶ A'') : (f ≫ g).f = f.f ≫ g.f := rfl /-- The category of Eilenberg-Moore algebras for a monad. cf Definition 5.2.4 in [Riehl][riehl2017]. -/ instance eilenbergMoore : Category (Algebra T) where /-- To construct an isomorphism of algebras, it suffices to give an isomorphism of the carriers which commutes with the structure morphisms. -/ @[simps] def isoMk {A B : Algebra T} (h : A.A ≅ B.A) (w : (T : C ⥤ C).map h.hom ≫ B.a = A.a ≫ h.hom := by aesop_cat) : A ≅ B where hom := { f := h.hom } inv := { f := h.inv h := by rw [h.eq_comp_inv, Category.assoc, ← w, ← Functor.map_comp_assoc] simp } end Algebra variable (T : Monad C) /-- The forgetful functor from the Eilenberg-Moore category, forgetting the algebraic structure. -/ @[simps] def forget : Algebra T ⥤ C where obj A := A.A map f := f.f /-- The free functor from the Eilenberg-Moore category, constructing an algebra for any object. -/ @[simps] def free : C ⥤ Algebra T where obj X := { A := T.obj X a := T.μ.app X assoc := (T.assoc _).symm } map f := { f := T.map f h := T.μ.naturality _ } instance [Inhabited C] : Inhabited (Algebra T) := ⟨(free T).obj default⟩ -- The other two `simps` projection lemmas can be derived from these two, so `simp_nf` complains if -- those are added too /-- The adjunction between the free and forgetful constructions for Eilenberg-Moore algebras for a monad. cf Lemma 5.2.8 of [Riehl][riehl2017]. -/ @[simps! unit counit] def adj : T.free ⊣ T.forget := Adjunction.mkOfHomEquiv { homEquiv := fun X Y => { toFun := fun f => T.η.app X ≫ f.f invFun := fun f => { f := T.map f ≫ Y.a h := by dsimp simp [← Y.assoc, ← T.μ.naturality_assoc] } left_inv := fun f => by ext dsimp simp right_inv := fun f => by dsimp only [forget_obj] rw [← T.η.naturality_assoc, Y.unit] apply Category.comp_id } } /-- Given an algebra morphism whose carrier part is an isomorphism, we get an algebra isomorphism. -/ theorem algebra_iso_of_iso {A B : Algebra T} (f : A ⟶ B) [IsIso f.f] : IsIso f := ⟨⟨{ f := inv f.f h := by rw [IsIso.eq_comp_inv f.f, Category.assoc, ← f.h] simp }, by aesop_cat⟩⟩ instance forget_reflects_iso : T.forget.ReflectsIsomorphisms where -- Porting note: Is this the right approach to introduce instances? reflects {_ _} f := fun [IsIso f.f] => algebra_iso_of_iso T f instance forget_faithful : T.forget.Faithful where /-- Given an algebra morphism whose carrier part is an epimorphism, we get an algebra epimorphism. -/ theorem algebra_epi_of_epi {X Y : Algebra T} (f : X ⟶ Y) [h : Epi f.f] : Epi f := (forget T).epi_of_epi_map h /-- Given an algebra morphism whose carrier part is a monomorphism, we get an algebra monomorphism. -/ theorem algebra_mono_of_mono {X Y : Algebra T} (f : X ⟶ Y) [h : Mono f.f] : Mono f := (forget T).mono_of_mono_map h instance : T.forget.IsRightAdjoint := ⟨T.free, ⟨T.adj⟩⟩ /-- Given a monad morphism from `T₂` to `T₁`, we get a functor from the algebras of `T₁` to algebras of `T₂`. -/ @[simps] def algebraFunctorOfMonadHom {T₁ T₂ : Monad C} (h : T₂ ⟶ T₁) : Algebra T₁ ⥤ Algebra T₂ where obj A := { A := A.A a := h.app A.A ≫ A.a unit := by dsimp simp [A.unit] assoc := by dsimp simp [A.assoc] } map f := { f := f.f } /-- The identity monad morphism induces the identity functor from the category of algebras to itself. -/ -- Porting note: `semireducible -> default` @[simps (config := { rhsMd := .default })] def algebraFunctorOfMonadHomId {T₁ : Monad C} : algebraFunctorOfMonadHom (𝟙 T₁) ≅ 𝟭 _ := NatIso.ofComponents fun X => Algebra.isoMk (Iso.refl _) /-- A composition of monad morphisms gives the composition of corresponding functors. -/ @[simps (config := { rhsMd := .default })] def algebraFunctorOfMonadHomComp {T₁ T₂ T₃ : Monad C} (f : T₁ ⟶ T₂) (g : T₂ ⟶ T₃) : algebraFunctorOfMonadHom (f ≫ g) ≅ algebraFunctorOfMonadHom g ⋙ algebraFunctorOfMonadHom f := NatIso.ofComponents fun X => Algebra.isoMk (Iso.refl _) /-- If `f` and `g` are two equal morphisms of monads, then the functors of algebras induced by them are isomorphic. We define it like this as opposed to using `eqToIso` so that the components are nicer to prove lemmas about. -/ @[simps (config := { rhsMd := .default })] def algebraFunctorOfMonadHomEq {T₁ T₂ : Monad C} {f g : T₁ ⟶ T₂} (h : f = g) : algebraFunctorOfMonadHom f ≅ algebraFunctorOfMonadHom g := NatIso.ofComponents fun X => Algebra.isoMk (Iso.refl _) /-- Isomorphic monads give equivalent categories of algebras. Furthermore, they are equivalent as categories over `C`, that is, we have `algebraEquivOfIsoMonads h ⋙ forget = forget`. -/ @[simps] def algebraEquivOfIsoMonads {T₁ T₂ : Monad C} (h : T₁ ≅ T₂) : Algebra T₁ ≌ Algebra T₂ where functor := algebraFunctorOfMonadHom h.inv inverse := algebraFunctorOfMonadHom h.hom unitIso := algebraFunctorOfMonadHomId.symm ≪≫ algebraFunctorOfMonadHomEq (by simp) ≪≫ algebraFunctorOfMonadHomComp _ _ counitIso := (algebraFunctorOfMonadHomComp _ _).symm ≪≫ algebraFunctorOfMonadHomEq (by simp) ≪≫ algebraFunctorOfMonadHomId @[simp] theorem algebra_equiv_of_iso_monads_comp_forget {T₁ T₂ : Monad C} (h : T₁ ⟶ T₂) : algebraFunctorOfMonadHom h ⋙ forget _ = forget _ := rfl end Monad namespace Comonad /-- An Eilenberg-Moore coalgebra for a comonad `T`. -/ structure Coalgebra (G : Comonad C) : Type max u₁ v₁ where /-- The underlying object associated to a coalgebra. -/ A : C /-- The structure morphism associated to a coalgebra. -/ a : A ⟶ (G : C ⥤ C).obj A /-- The counit axiom associated to a coalgebra. -/ counit : a ≫ G.ε.app A = 𝟙 A := by aesop_cat /-- The coassociativity axiom associated to a coalgebra. -/ coassoc : a ≫ G.δ.app A = a ≫ G.map a := by aesop_cat -- Porting note: no need to restate axioms in lean4. --restate_axiom coalgebra.counit' --restate_axiom coalgebra.coassoc' attribute [reassoc] Coalgebra.counit Coalgebra.coassoc namespace Coalgebra variable {G : Comonad C} /-- A morphism of Eilenberg-Moore coalgebras for the comonad `G`. -/ @[ext] structure Hom (A B : Coalgebra G) where /-- The underlying morphism associated to a morphism of coalgebras. -/ f : A.A ⟶ B.A /-- Compatibility with the structure morphism, for a morphism of coalgebras. -/ h : A.a ≫ (G : C ⥤ C).map f = f ≫ B.a := by aesop_cat -- Porting note: no need to restate axioms in lean4. --restate_axiom hom.h attribute [reassoc (attr := simp)] Hom.h namespace Hom /-- The identity homomorphism for an Eilenberg–Moore coalgebra. -/ def id (A : Coalgebra G) : Hom A A where f := 𝟙 A.A /-- Composition of Eilenberg–Moore coalgebra homomorphisms. -/ def comp {P Q R : Coalgebra G} (f : Hom P Q) (g : Hom Q R) : Hom P R where f := f.f ≫ g.f end Hom /-- The category of Eilenberg-Moore coalgebras for a comonad. -/ instance : CategoryStruct (Coalgebra G) where Hom := Hom id := Hom.id comp := @Hom.comp _ _ _ -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): Adding `ext` lemma to help automation below. @[ext] lemma Hom.ext' (X Y : Coalgebra G) (f g : X ⟶ Y) (h : f.f = g.f) : f = g := Hom.ext h @[simp] theorem comp_eq_comp {A A' A'' : Coalgebra G} (f : A ⟶ A') (g : A' ⟶ A'') : Coalgebra.Hom.comp f g = f ≫ g := rfl @[simp] theorem id_eq_id (A : Coalgebra G) : Coalgebra.Hom.id A = 𝟙 A := rfl @[simp] theorem id_f (A : Coalgebra G) : (𝟙 A : A ⟶ A).f = 𝟙 A.A := rfl @[simp] theorem comp_f {A A' A'' : Coalgebra G} (f : A ⟶ A') (g : A' ⟶ A'') : (f ≫ g).f = f.f ≫ g.f := rfl /-- The category of Eilenberg-Moore coalgebras for a comonad. -/ instance eilenbergMoore : Category (Coalgebra G) where /-- To construct an isomorphism of coalgebras, it suffices to give an isomorphism of the carriers which commutes with the structure morphisms. -/ @[simps] def isoMk {A B : Coalgebra G} (h : A.A ≅ B.A) (w : A.a ≫ (G : C ⥤ C).map h.hom = h.hom ≫ B.a := by aesop_cat) : A ≅ B where hom := { f := h.hom } inv := { f := h.inv h := by rw [h.eq_inv_comp, ← reassoc_of% w, ← Functor.map_comp] simp } end Coalgebra variable (G : Comonad C) /-- The forgetful functor from the Eilenberg-Moore category, forgetting the coalgebraic structure. -/ @[simps] def forget : Coalgebra G ⥤ C where obj A := A.A map f := f.f /-- The cofree functor from the Eilenberg-Moore category, constructing a coalgebra for any object. -/ @[simps] def cofree : C ⥤ Coalgebra G where obj X := { A := G.obj X a := G.δ.app X coassoc := (G.coassoc _).symm } map f := { f := G.map f h := (G.δ.naturality _).symm } -- The other two `simps` projection lemmas can be derived from these two, so `simp_nf` complains if -- those are added too /-- The adjunction between the cofree and forgetful constructions for Eilenberg-Moore coalgebras for a comonad. -/ @[simps! unit counit] def adj : G.forget ⊣ G.cofree := Adjunction.mkOfHomEquiv { homEquiv := fun X Y => { toFun := fun f => { f := X.a ≫ G.map f h := by dsimp simp [← Coalgebra.coassoc_assoc] } invFun := fun g => g.f ≫ G.ε.app Y left_inv := fun f => by dsimp rw [Category.assoc, G.ε.naturality, Functor.id_map, X.counit_assoc] right_inv := fun g => by ext1; dsimp rw [Functor.map_comp, g.h_assoc, cofree_obj_a, Comonad.right_counit] apply comp_id } } /-- Given a coalgebra morphism whose carrier part is an isomorphism, we get a coalgebra isomorphism. -/ theorem coalgebra_iso_of_iso {A B : Coalgebra G} (f : A ⟶ B) [IsIso f.f] : IsIso f := ⟨⟨{ f := inv f.f h := by rw [IsIso.eq_inv_comp f.f, ← f.h_assoc] simp }, by aesop_cat⟩⟩ instance forget_reflects_iso : G.forget.ReflectsIsomorphisms where -- Porting note: Is this the right approach to introduce instances? reflects {_ _} f := fun [IsIso f.f] => coalgebra_iso_of_iso G f instance forget_faithful : (forget G).Faithful where /-- Given a coalgebra morphism whose carrier part is an epimorphism, we get an algebra epimorphism. -/ theorem algebra_epi_of_epi {X Y : Coalgebra G} (f : X ⟶ Y) [h : Epi f.f] : Epi f := (forget G).epi_of_epi_map h /-- Given a coalgebra morphism whose carrier part is a monomorphism, we get an algebra monomorphism. -/ theorem algebra_mono_of_mono {X Y : Coalgebra G} (f : X ⟶ Y) [h : Mono f.f] : Mono f := (forget G).mono_of_mono_map h instance : G.forget.IsLeftAdjoint := ⟨_, ⟨G.adj⟩⟩ end Comonad end CategoryTheory
Mathlib/CategoryTheory/Monad/Algebra.lean
470
475
/- 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.Field.Basic import Mathlib.Algebra.NoZeroSMulDivisors.Basic import Mathlib.Data.Int.ModEq import Mathlib.GroupTheory.QuotientGroup.Defs import Mathlib.Algebra.Group.Subgroup.ZPowers.Basic /-! # Equality modulo an element This file defines equality modulo an element in a commutative group. ## Main definitions * `a ≡ b [PMOD p]`: `a` and `b` are congruent modulo `p`. ## See also `SModEq` is a generalisation to arbitrary submodules. ## TODO Delete `Int.ModEq` in favour of `AddCommGroup.ModEq`. Generalise `SModEq` to `AddSubgroup` and redefine `AddCommGroup.ModEq` using it. Once this is done, we can rename `AddCommGroup.ModEq` to `AddSubgroup.ModEq` and multiplicativise it. Longer term, we could generalise to submonoids and also unify with `Nat.ModEq`. -/ namespace AddCommGroup variable {α : Type*} section AddCommGroup variable [AddCommGroup α] {p a a₁ a₂ b b₁ b₂ c : α} {n : ℕ} {z : ℤ} /-- `a ≡ b [PMOD p]` means that `b` is congruent to `a` modulo `p`. Equivalently (as shown in `Algebra.Order.ToIntervalMod`), `b` does not lie in the open interval `(a, a + p)` modulo `p`, or `toIcoMod hp a` disagrees with `toIocMod hp a` at `b`, or `toIcoDiv hp a` disagrees with `toIocDiv hp a` at `b`. -/ def ModEq (p a b : α) : Prop := ∃ z : ℤ, b - a = z • p @[inherit_doc] notation:50 a " ≡ " b " [PMOD " p "]" => ModEq p a b @[refl, simp] theorem modEq_refl (a : α) : a ≡ a [PMOD p] := ⟨0, by simp⟩ theorem modEq_rfl : a ≡ a [PMOD p] := modEq_refl _ theorem modEq_comm : a ≡ b [PMOD p] ↔ b ≡ a [PMOD p] := (Equiv.neg _).exists_congr_left.trans <| by simp [ModEq, ← neg_eq_iff_eq_neg] alias ⟨ModEq.symm, _⟩ := modEq_comm attribute [symm] ModEq.symm @[trans] theorem ModEq.trans : a ≡ b [PMOD p] → b ≡ c [PMOD p] → a ≡ c [PMOD p] := fun ⟨m, hm⟩ ⟨n, hn⟩ => ⟨m + n, by simp [add_smul, ← hm, ← hn]⟩ instance : IsRefl _ (ModEq p) := ⟨modEq_refl⟩ @[simp] theorem neg_modEq_neg : -a ≡ -b [PMOD p] ↔ a ≡ b [PMOD p] := modEq_comm.trans <| by simp [ModEq, neg_add_eq_sub] alias ⟨ModEq.of_neg, ModEq.neg⟩ := neg_modEq_neg @[simp] theorem modEq_neg : a ≡ b [PMOD -p] ↔ a ≡ b [PMOD p] := modEq_comm.trans <| by simp [ModEq, ← neg_eq_iff_eq_neg] alias ⟨ModEq.of_neg', ModEq.neg'⟩ := modEq_neg theorem modEq_sub (a b : α) : a ≡ b [PMOD b - a] := ⟨1, (one_smul _ _).symm⟩ @[simp] theorem modEq_zero : a ≡ b [PMOD 0] ↔ a = b := by simp [ModEq, sub_eq_zero, eq_comm] @[simp] theorem self_modEq_zero : p ≡ 0 [PMOD p] := ⟨-1, by simp⟩ @[simp] theorem zsmul_modEq_zero (z : ℤ) : z • p ≡ 0 [PMOD p] := ⟨-z, by simp⟩ theorem add_zsmul_modEq (z : ℤ) : a + z • p ≡ a [PMOD p] := ⟨-z, by simp⟩ theorem zsmul_add_modEq (z : ℤ) : z • p + a ≡ a [PMOD p] := ⟨-z, by simp [← sub_sub]⟩
theorem add_nsmul_modEq (n : ℕ) : a + n • p ≡ a [PMOD p] := ⟨-n, by simp⟩
Mathlib/Algebra/ModEq.lean
106
107
/- 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]
Mathlib/CategoryTheory/Limits/Shapes/ZeroMorphisms.lean
201
202
/- Copyright (c) 2020 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Kim Morrison, Ainsley Pahljina -/ import Mathlib.RingTheory.Fintype import Mathlib.Tactic.NormNum import Mathlib.Tactic.Ring import Mathlib.Tactic.Zify /-! # The Lucas-Lehmer test for Mersenne primes. We define `lucasLehmerResidue : Π p : ℕ, ZMod (2^p - 1)`, and prove `lucasLehmerResidue p = 0 → Prime (mersenne p)`. We construct a `norm_num` extension to calculate this residue to certify primality of Mersenne primes using `lucas_lehmer_sufficiency`. ## TODO - Show reverse implication. - Speed up the calculations using `n ≡ (n % 2^p) + (n / 2^p) [MOD 2^p - 1]`. - Find some bigger primes! ## History This development began as a student project by Ainsley Pahljina, and was then cleaned up for mathlib by Kim Morrison. The tactic for certified computation of Lucas-Lehmer residues was provided by Mario Carneiro. This tactic was ported by Thomas Murrills to Lean 4, and then it was converted to a `norm_num` extension and made to use kernel reductions by Kyle Miller. -/ assert_not_exists TwoSidedIdeal /-- The Mersenne numbers, 2^p - 1. -/ def mersenne (p : ℕ) : ℕ := 2 ^ p - 1 theorem strictMono_mersenne : StrictMono mersenne := fun m n h ↦ (Nat.sub_lt_sub_iff_right <| Nat.one_le_pow _ _ two_pos).2 <| by gcongr; norm_num1 @[simp] theorem mersenne_lt_mersenne {p q : ℕ} : mersenne p < mersenne q ↔ p < q := strictMono_mersenne.lt_iff_lt @[gcongr] protected alias ⟨_, GCongr.mersenne_lt_mersenne⟩ := mersenne_lt_mersenne @[simp] theorem mersenne_le_mersenne {p q : ℕ} : mersenne p ≤ mersenne q ↔ p ≤ q := strictMono_mersenne.le_iff_le @[gcongr] protected alias ⟨_, GCongr.mersenne_le_mersenne⟩ := mersenne_le_mersenne @[simp] theorem mersenne_zero : mersenne 0 = 0 := rfl @[simp] lemma mersenne_odd : ∀ {p : ℕ}, Odd (mersenne p) ↔ p ≠ 0 | 0 => by simp | p + 1 => by simpa using Nat.Even.sub_odd (one_le_pow₀ one_le_two) (even_two.pow_of_ne_zero p.succ_ne_zero) odd_one @[simp] theorem mersenne_pos {p : ℕ} : 0 < mersenne p ↔ 0 < p := mersenne_lt_mersenne (p := 0) namespace Mathlib.Meta.Positivity open Lean Meta Qq Function alias ⟨_, mersenne_pos_of_pos⟩ := mersenne_pos /-- Extension for the `positivity` tactic: `mersenne`. -/ @[positivity mersenne _] def evalMersenne : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℕ), ~q(mersenne $a) => let ra ← core q(inferInstance) q(inferInstance) a assertInstancesCommute match ra with | .positive pa => pure (.positive q(mersenne_pos_of_pos $pa)) | _ => pure (.nonnegative q(Nat.zero_le (mersenne $a))) | _, _, _ => throwError "not mersenne" end Mathlib.Meta.Positivity @[simp] theorem one_lt_mersenne {p : ℕ} : 1 < mersenne p ↔ 1 < p := mersenne_lt_mersenne (p := 1) @[simp] theorem succ_mersenne (k : ℕ) : mersenne k + 1 = 2 ^ k := by rw [mersenne, tsub_add_cancel_of_le] exact one_le_pow₀ (by norm_num) namespace LucasLehmer open Nat /-! We now define three(!) different versions of the recurrence `s (i+1) = (s i)^2 - 2`. These versions take values either in `ℤ`, in `ZMod (2^p - 1)`, or in `ℤ` but applying `% (2^p - 1)` at each step. They are each useful at different points in the proof, so we take a moment setting up the lemmas relating them. -/ /-- The recurrence `s (i+1) = (s i)^2 - 2` in `ℤ`. -/ def s : ℕ → ℤ | 0 => 4 | i + 1 => s i ^ 2 - 2 /-- The recurrence `s (i+1) = (s i)^2 - 2` in `ZMod (2^p - 1)`. -/ def sZMod (p : ℕ) : ℕ → ZMod (2 ^ p - 1) | 0 => 4 | i + 1 => sZMod p i ^ 2 - 2 /-- The recurrence `s (i+1) = ((s i)^2 - 2) % (2^p - 1)` in `ℤ`. -/ def sMod (p : ℕ) : ℕ → ℤ | 0 => 4 % (2 ^ p - 1) | i + 1 => (sMod p i ^ 2 - 2) % (2 ^ p - 1) theorem mersenne_int_pos {p : ℕ} (hp : p ≠ 0) : (0 : ℤ) < 2 ^ p - 1 := sub_pos.2 <| mod_cast Nat.one_lt_two_pow hp theorem mersenne_int_ne_zero (p : ℕ) (hp : p ≠ 0) : (2 ^ p - 1 : ℤ) ≠ 0 := (mersenne_int_pos hp).ne' theorem sMod_nonneg (p : ℕ) (hp : p ≠ 0) (i : ℕ) : 0 ≤ sMod p i := by cases i <;> dsimp [sMod] · exact sup_eq_right.mp rfl · apply Int.emod_nonneg exact mersenne_int_ne_zero p hp theorem sMod_mod (p i : ℕ) : sMod p i % (2 ^ p - 1) = sMod p i := by cases i <;> simp [sMod] theorem sMod_lt (p : ℕ) (hp : p ≠ 0) (i : ℕ) : sMod p i < 2 ^ p - 1 := by rw [← sMod_mod] refine (Int.emod_lt_abs _ (mersenne_int_ne_zero p hp)).trans_eq ?_ exact abs_of_nonneg (mersenne_int_pos hp).le theorem sZMod_eq_s (p' : ℕ) (i : ℕ) : sZMod (p' + 2) i = (s i : ZMod (2 ^ (p' + 2) - 1)) := by induction i with | zero => dsimp [s, sZMod]; norm_num | succ i ih => push_cast [s, sZMod, ih]; rfl -- These next two don't make good `norm_cast` lemmas. theorem Int.natCast_pow_pred (b p : ℕ) (w : 0 < b) : ((b ^ p - 1 : ℕ) : ℤ) = (b : ℤ) ^ p - 1 := by have : 1 ≤ b ^ p := Nat.one_le_pow p b w norm_cast theorem Int.coe_nat_two_pow_pred (p : ℕ) : ((2 ^ p - 1 : ℕ) : ℤ) = (2 ^ p - 1 : ℤ) := Int.natCast_pow_pred 2 p (by decide) theorem sZMod_eq_sMod (p : ℕ) (i : ℕ) : sZMod p i = (sMod p i : ZMod (2 ^ p - 1)) := by induction i <;> push_cast [← Int.coe_nat_two_pow_pred p, sMod, sZMod, *] <;> rfl /-- The Lucas-Lehmer residue is `s p (p-2)` in `ZMod (2^p - 1)`. -/
def lucasLehmerResidue (p : ℕ) : ZMod (2 ^ p - 1) := sZMod p (p - 2)
Mathlib/NumberTheory/LucasLehmer.lean
162
164
/- Copyright (c) 2021 Benjamin Davidson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Benjamin Davidson -/ import Mathlib.Analysis.SpecialFunctions.Log.NegMulLog import Mathlib.Analysis.SpecialFunctions.NonIntegrable import Mathlib.Analysis.SpecialFunctions.Pow.Deriv import Mathlib.Analysis.SpecialFunctions.Trigonometric.ArctanDeriv import Mathlib.MeasureTheory.Integral.IntervalIntegral.IntegrationByParts /-! # Integration of specific interval integrals This file contains proofs of the integrals of various specific functions. This includes: * Integrals of simple functions, such as `id`, `pow`, `inv`, `exp`, `log` * Integrals of some trigonometric functions, such as `sin`, `cos`, `1 / (1 + x^2)` * The integral of `cos x ^ 2 - sin x ^ 2` * Reduction formulae for the integrals of `sin x ^ n` and `cos x ^ n` for `n ≥ 2` * The computation of `∫ x in 0..π, sin x ^ n` as a product for even and odd `n` (used in proving the Wallis product for pi) * Integrals of the form `sin x ^ m * cos x ^ n` With these lemmas, many simple integrals can be computed by `simp` or `norm_num`. This file also contains some facts about the interval integrability of specific functions. This file is still being developed. ## Tags integrate, integration, integrable, integrability -/ open Real Set Finset open scoped Real Interval variable {a b : ℝ} (n : ℕ) namespace intervalIntegral open MeasureTheory variable {f : ℝ → ℝ} {μ : Measure ℝ} [IsLocallyFiniteMeasure μ] (c d : ℝ) /-! ### Interval integrability -/ @[simp] theorem intervalIntegrable_pow : IntervalIntegrable (fun x => x ^ n) μ a b := (continuous_pow n).intervalIntegrable a b theorem intervalIntegrable_zpow {n : ℤ} (h : 0 ≤ n ∨ (0 : ℝ) ∉ [[a, b]]) : IntervalIntegrable (fun x => x ^ n) μ a b := (continuousOn_id.zpow₀ n fun _ hx => h.symm.imp (ne_of_mem_of_not_mem hx) id).intervalIntegrable /-- See `intervalIntegrable_rpow'` for a version with a weaker hypothesis on `r`, but assuming the measure is volume. -/ theorem intervalIntegrable_rpow {r : ℝ} (h : 0 ≤ r ∨ (0 : ℝ) ∉ [[a, b]]) : IntervalIntegrable (fun x => x ^ r) μ a b := (continuousOn_id.rpow_const fun _ hx => h.symm.imp (ne_of_mem_of_not_mem hx) id).intervalIntegrable /-- See `intervalIntegrable_rpow` for a version applying to any locally finite measure, but with a stronger hypothesis on `r`. -/ theorem intervalIntegrable_rpow' {r : ℝ} (h : -1 < r) : IntervalIntegrable (fun x => x ^ r) volume a b := by suffices ∀ c : ℝ, IntervalIntegrable (fun x => x ^ r) volume 0 c by exact IntervalIntegrable.trans (this a).symm (this b) have : ∀ c : ℝ, 0 ≤ c → IntervalIntegrable (fun x => x ^ r) volume 0 c := by intro c hc rw [intervalIntegrable_iff, uIoc_of_le hc] have hderiv : ∀ x ∈ Ioo 0 c, HasDerivAt (fun x : ℝ => x ^ (r + 1) / (r + 1)) (x ^ r) x := by intro x hx convert (Real.hasDerivAt_rpow_const (p := r + 1) (Or.inl hx.1.ne')).div_const (r + 1) using 1 field_simp [(by linarith : r + 1 ≠ 0)] apply integrableOn_deriv_of_nonneg _ hderiv · intro x hx; apply rpow_nonneg hx.1.le · refine (continuousOn_id.rpow_const ?_).div_const _; intro x _; right; linarith intro c; rcases le_total 0 c with (hc | hc) · exact this c hc · rw [IntervalIntegrable.iff_comp_neg, neg_zero] have m := (this (-c) (by linarith)).smul (cos (r * π)) rw [intervalIntegrable_iff] at m ⊢ refine m.congr_fun ?_ measurableSet_Ioc; intro x hx rw [uIoc_of_le (by linarith : 0 ≤ -c)] at hx simp only [Pi.smul_apply, Algebra.id.smul_eq_mul, log_neg_eq_log, mul_comm, rpow_def_of_pos hx.1, rpow_def_of_neg (by linarith [hx.1] : -x < 0)] /-- The power function `x ↦ x^s` is integrable on `(0, t)` iff `-1 < s`. -/ lemma integrableOn_Ioo_rpow_iff {s t : ℝ} (ht : 0 < t) : IntegrableOn (fun x ↦ x ^ s) (Ioo (0 : ℝ) t) ↔ -1 < s := by refine ⟨fun h ↦ ?_, fun h ↦ by simpa [intervalIntegrable_iff_integrableOn_Ioo_of_le ht.le] using intervalIntegrable_rpow' h (a := 0) (b := t)⟩ contrapose! h intro H have I : 0 < min 1 t := lt_min zero_lt_one ht have H' : IntegrableOn (fun x ↦ x ^ s) (Ioo 0 (min 1 t)) := H.mono (Set.Ioo_subset_Ioo le_rfl (min_le_right _ _)) le_rfl have : IntegrableOn (fun x ↦ x⁻¹) (Ioo 0 (min 1 t)) := by apply H'.mono' measurable_inv.aestronglyMeasurable filter_upwards [ae_restrict_mem measurableSet_Ioo] with x hx simp only [norm_inv, Real.norm_eq_abs, abs_of_nonneg (le_of_lt hx.1)] rwa [← Real.rpow_neg_one x, Real.rpow_le_rpow_left_iff_of_base_lt_one hx.1] exact lt_of_lt_of_le hx.2 (min_le_left _ _) have : IntervalIntegrable (fun x ↦ x⁻¹) volume 0 (min 1 t) := by rwa [intervalIntegrable_iff_integrableOn_Ioo_of_le I.le] simp [intervalIntegrable_inv_iff, I.ne] at this /-- See `intervalIntegrable_cpow'` for a version with a weaker hypothesis on `r`, but assuming the measure is volume. -/ theorem intervalIntegrable_cpow {r : ℂ} (h : 0 ≤ r.re ∨ (0 : ℝ) ∉ [[a, b]]) : IntervalIntegrable (fun x : ℝ => (x : ℂ) ^ r) μ a b := by by_cases h2 : (0 : ℝ) ∉ [[a, b]] · -- Easy case #1: 0 ∉ [a, b] -- use continuity. refine (continuousOn_of_forall_continuousAt fun x hx => ?_).intervalIntegrable exact Complex.continuousAt_ofReal_cpow_const _ _ (Or.inr <| ne_of_mem_of_not_mem hx h2) rw [eq_false h2, or_false] at h rcases lt_or_eq_of_le h with (h' | h') · -- Easy case #2: 0 < re r -- again use continuity exact (Complex.continuous_ofReal_cpow_const h').intervalIntegrable _ _ -- Now the hard case: re r = 0 and 0 is in the interval. refine (IntervalIntegrable.intervalIntegrable_norm_iff ?_).mp ?_ · refine (measurable_of_continuousOn_compl_singleton (0 : ℝ) ?_).aestronglyMeasurable exact continuousOn_of_forall_continuousAt fun x hx => Complex.continuousAt_ofReal_cpow_const x r (Or.inr hx) -- reduce to case of integral over `[0, c]` suffices ∀ c : ℝ, IntervalIntegrable (fun x : ℝ => ‖(x : ℂ) ^ r‖) μ 0 c from (this a).symm.trans (this b) intro c rcases le_or_lt 0 c with (hc | hc) · -- case `0 ≤ c`: integrand is identically 1 have : IntervalIntegrable (fun _ => 1 : ℝ → ℝ) μ 0 c := intervalIntegrable_const rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hc] at this ⊢ refine IntegrableOn.congr_fun this (fun x hx => ?_) measurableSet_Ioc dsimp only rw [Complex.norm_cpow_eq_rpow_re_of_pos hx.1, ← h', rpow_zero] · -- case `c < 0`: integrand is identically constant, *except* at `x = 0` if `r ≠ 0`. apply IntervalIntegrable.symm rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hc.le] rw [← Ioo_union_right hc, integrableOn_union, and_comm]; constructor · refine integrableOn_singleton_iff.mpr (Or.inr ?_) exact isFiniteMeasureOnCompacts_of_isLocallyFiniteMeasure.lt_top_of_isCompact isCompact_singleton · have : ∀ x : ℝ, x ∈ Ioo c 0 → ‖Complex.exp (↑π * Complex.I * r)‖ = ‖(x : ℂ) ^ r‖ := by intro x hx rw [Complex.ofReal_cpow_of_nonpos hx.2.le, norm_mul, ← Complex.ofReal_neg, Complex.norm_cpow_eq_rpow_re_of_pos (neg_pos.mpr hx.2), ← h', rpow_zero, one_mul] refine IntegrableOn.congr_fun ?_ this measurableSet_Ioo rw [integrableOn_const] refine Or.inr ((measure_mono Set.Ioo_subset_Icc_self).trans_lt ?_) exact isFiniteMeasureOnCompacts_of_isLocallyFiniteMeasure.lt_top_of_isCompact isCompact_Icc /-- See `intervalIntegrable_cpow` for a version applying to any locally finite measure, but with a stronger hypothesis on `r`. -/ theorem intervalIntegrable_cpow' {r : ℂ} (h : -1 < r.re) : IntervalIntegrable (fun x : ℝ => (x : ℂ) ^ r) volume a b := by suffices ∀ c : ℝ, IntervalIntegrable (fun x => (x : ℂ) ^ r) volume 0 c by exact IntervalIntegrable.trans (this a).symm (this b) have : ∀ c : ℝ, 0 ≤ c → IntervalIntegrable (fun x => (x : ℂ) ^ r) volume 0 c := by intro c hc rw [← IntervalIntegrable.intervalIntegrable_norm_iff] · rw [intervalIntegrable_iff] apply IntegrableOn.congr_fun · rw [← intervalIntegrable_iff]; exact intervalIntegral.intervalIntegrable_rpow' h · intro x hx rw [uIoc_of_le hc] at hx dsimp only rw [Complex.norm_cpow_eq_rpow_re_of_pos hx.1] · exact measurableSet_uIoc · refine ContinuousOn.aestronglyMeasurable ?_ measurableSet_uIoc refine continuousOn_of_forall_continuousAt fun x hx => ?_ rw [uIoc_of_le hc] at hx refine (continuousAt_cpow_const (Or.inl ?_)).comp Complex.continuous_ofReal.continuousAt rw [Complex.ofReal_re] exact hx.1 intro c; rcases le_total 0 c with (hc | hc) · exact this c hc · rw [IntervalIntegrable.iff_comp_neg, neg_zero] have m := (this (-c) (by linarith)).const_mul (Complex.exp (π * Complex.I * r)) rw [intervalIntegrable_iff, uIoc_of_le (by linarith : 0 ≤ -c)] at m ⊢ refine m.congr_fun (fun x hx => ?_) measurableSet_Ioc dsimp only have : -x ≤ 0 := by linarith [hx.1] rw [Complex.ofReal_cpow_of_nonpos this, mul_comm] simp /-- The complex power function `x ↦ x^s` is integrable on `(0, t)` iff `-1 < s.re`. -/ theorem integrableOn_Ioo_cpow_iff {s : ℂ} {t : ℝ} (ht : 0 < t) : IntegrableOn (fun x : ℝ ↦ (x : ℂ) ^ s) (Ioo (0 : ℝ) t) ↔ -1 < s.re := by refine ⟨fun h ↦ ?_, fun h ↦ by simpa [intervalIntegrable_iff_integrableOn_Ioo_of_le ht.le] using intervalIntegrable_cpow' h (a := 0) (b := t)⟩ have B : IntegrableOn (fun a ↦ a ^ s.re) (Ioo 0 t) := by apply (integrableOn_congr_fun _ measurableSet_Ioo).1 h.norm intro a ha simp [Complex.norm_cpow_eq_rpow_re_of_pos ha.1] rwa [integrableOn_Ioo_rpow_iff ht] at B @[simp] theorem intervalIntegrable_id : IntervalIntegrable (fun x => x) μ a b := continuous_id.intervalIntegrable a b theorem intervalIntegrable_const : IntervalIntegrable (fun _ => c) μ a b := continuous_const.intervalIntegrable a b theorem intervalIntegrable_one_div (h : ∀ x : ℝ, x ∈ [[a, b]] → f x ≠ 0) (hf : ContinuousOn f [[a, b]]) : IntervalIntegrable (fun x => 1 / f x) μ a b := (continuousOn_const.div hf h).intervalIntegrable @[simp] theorem intervalIntegrable_inv (h : ∀ x : ℝ, x ∈ [[a, b]] → f x ≠ 0) (hf : ContinuousOn f [[a, b]]) : IntervalIntegrable (fun x => (f x)⁻¹) μ a b := by simpa only [one_div] using intervalIntegrable_one_div h hf @[simp] theorem intervalIntegrable_exp : IntervalIntegrable exp μ a b := continuous_exp.intervalIntegrable a b @[simp] theorem _root_.IntervalIntegrable.log (hf : ContinuousOn f [[a, b]]) (h : ∀ x : ℝ, x ∈ [[a, b]] → f x ≠ 0) : IntervalIntegrable (fun x => log (f x)) μ a b := (ContinuousOn.log hf h).intervalIntegrable /-- See `intervalIntegrable_log'` for a version without any hypothesis on the interval, but assuming the measure is volume. -/ @[simp] theorem intervalIntegrable_log (h : (0 : ℝ) ∉ [[a, b]]) : IntervalIntegrable log μ a b := IntervalIntegrable.log continuousOn_id fun _ hx => ne_of_mem_of_not_mem hx h /-- The real logarithm is interval integrable (with respect to the volume measure) on every interval. See `intervalIntegrable_log` for a version applying to any locally finite measure, but with an additional hypothesis on the interval. -/ @[simp] theorem intervalIntegrable_log' : IntervalIntegrable log volume a b := by -- Log is even, so it suffices to consider the case 0 < a and b = 0 apply intervalIntegrable_of_even (log_neg_eq_log · |>.symm) intro x hx -- Split integral apply IntervalIntegrable.trans (b := 1) · -- Show integrability on [0…1] using non-negativity of the derivative rw [← neg_neg log] apply IntervalIntegrable.neg apply intervalIntegrable_deriv_of_nonneg (g := fun x ↦ -(x * log x - x)) · exact (continuous_mul_log.continuousOn.sub continuous_id.continuousOn).neg · intro s ⟨hs, _⟩ norm_num at * simpa using (hasDerivAt_id s).sub (hasDerivAt_mul_log hs.ne.symm) · intro s ⟨hs₁, hs₂⟩ norm_num at * exact (log_nonpos_iff hs₁.le).mpr hs₂.le · -- Show integrability on [1…t] by continuity apply ContinuousOn.intervalIntegrable apply Real.continuousOn_log.mono apply Set.not_mem_uIcc_of_lt zero_lt_one at hx simpa @[simp] theorem intervalIntegrable_sin : IntervalIntegrable sin μ a b := continuous_sin.intervalIntegrable a b @[simp] theorem intervalIntegrable_cos : IntervalIntegrable cos μ a b := continuous_cos.intervalIntegrable a b theorem intervalIntegrable_one_div_one_add_sq : IntervalIntegrable (fun x : ℝ => 1 / (↑1 + x ^ 2)) μ a b := by refine (continuous_const.div ?_ fun x => ?_).intervalIntegrable a b · fun_prop · nlinarith @[simp] theorem intervalIntegrable_inv_one_add_sq : IntervalIntegrable (fun x : ℝ => (↑1 + x ^ 2)⁻¹) μ a b := by field_simp; exact mod_cast intervalIntegrable_one_div_one_add_sq /-! ### Integrals of the form `c * ∫ x in a..b, f (c * x + d)` -/ section @[simp] theorem mul_integral_comp_mul_right : (c * ∫ x in a..b, f (x * c)) = ∫ x in a * c..b * c, f x := smul_integral_comp_mul_right f c @[simp] theorem mul_integral_comp_mul_left : (c * ∫ x in a..b, f (c * x)) = ∫ x in c * a..c * b, f x := smul_integral_comp_mul_left f c @[simp] theorem inv_mul_integral_comp_div : (c⁻¹ * ∫ x in a..b, f (x / c)) = ∫ x in a / c..b / c, f x := inv_smul_integral_comp_div f c @[simp] theorem mul_integral_comp_mul_add : (c * ∫ x in a..b, f (c * x + d)) = ∫ x in c * a + d..c * b + d, f x := smul_integral_comp_mul_add f c d @[simp] theorem mul_integral_comp_add_mul : (c * ∫ x in a..b, f (d + c * x)) = ∫ x in d + c * a..d + c * b, f x := smul_integral_comp_add_mul f c d @[simp] theorem inv_mul_integral_comp_div_add : (c⁻¹ * ∫ x in a..b, f (x / c + d)) = ∫ x in a / c + d..b / c + d, f x := inv_smul_integral_comp_div_add f c d @[simp] theorem inv_mul_integral_comp_add_div : (c⁻¹ * ∫ x in a..b, f (d + x / c)) = ∫ x in d + a / c..d + b / c, f x := inv_smul_integral_comp_add_div f c d @[simp] theorem mul_integral_comp_mul_sub : (c * ∫ x in a..b, f (c * x - d)) = ∫ x in c * a - d..c * b - d, f x := smul_integral_comp_mul_sub f c d @[simp] theorem mul_integral_comp_sub_mul : (c * ∫ x in a..b, f (d - c * x)) = ∫ x in d - c * b..d - c * a, f x := smul_integral_comp_sub_mul f c d @[simp] theorem inv_mul_integral_comp_div_sub : (c⁻¹ * ∫ x in a..b, f (x / c - d)) = ∫ x in a / c - d..b / c - d, f x := inv_smul_integral_comp_div_sub f c d @[simp] theorem inv_mul_integral_comp_sub_div : (c⁻¹ * ∫ x in a..b, f (d - x / c)) = ∫ x in d - b / c..d - a / c, f x := inv_smul_integral_comp_sub_div f c d end end intervalIntegral open intervalIntegral /-! ### Integrals of simple functions -/ theorem integral_cpow {r : ℂ} (h : -1 < r.re ∨ r ≠ -1 ∧ (0 : ℝ) ∉ [[a, b]]) : (∫ x : ℝ in a..b, (x : ℂ) ^ r) = ((b : ℂ) ^ (r + 1) - (a : ℂ) ^ (r + 1)) / (r + 1) := by rw [sub_div] have hr : r + 1 ≠ 0 := by rcases h with h | h · apply_fun Complex.re rw [Complex.add_re, Complex.one_re, Complex.zero_re, Ne, add_eq_zero_iff_eq_neg] exact h.ne' · rw [Ne, ← add_eq_zero_iff_eq_neg] at h; exact h.1 by_cases hab : (0 : ℝ) ∉ [[a, b]] · apply integral_eq_sub_of_hasDerivAt (fun x hx => ?_) (intervalIntegrable_cpow (r := r) <| Or.inr hab) refine hasDerivAt_ofReal_cpow_const' (ne_of_mem_of_not_mem hx hab) ?_ contrapose! hr; rwa [add_eq_zero_iff_eq_neg] replace h : -1 < r.re := by tauto suffices ∀ c : ℝ, (∫ x : ℝ in (0)..c, (x : ℂ) ^ r) = (c : ℂ) ^ (r + 1) / (r + 1) - (0 : ℂ) ^ (r + 1) / (r + 1) by rw [← integral_add_adjacent_intervals (@intervalIntegrable_cpow' a 0 r h) (@intervalIntegrable_cpow' 0 b r h), integral_symm, this a, this b, Complex.zero_cpow hr] ring intro c apply integral_eq_sub_of_hasDeriv_right · refine ((Complex.continuous_ofReal_cpow_const ?_).div_const _).continuousOn rwa [Complex.add_re, Complex.one_re, ← neg_lt_iff_pos_add] · refine fun x hx => (hasDerivAt_ofReal_cpow_const' ?_ ?_).hasDerivWithinAt · rcases le_total c 0 with (hc | hc) · rw [max_eq_left hc] at hx; exact hx.2.ne · rw [min_eq_left hc] at hx; exact hx.1.ne' · contrapose! hr; rw [hr]; ring · exact intervalIntegrable_cpow' h theorem integral_rpow {r : ℝ} (h : -1 < r ∨ r ≠ -1 ∧ (0 : ℝ) ∉ [[a, b]]) : ∫ x in a..b, x ^ r = (b ^ (r + 1) - a ^ (r + 1)) / (r + 1) := by have h' : -1 < (r : ℂ).re ∨ (r : ℂ) ≠ -1 ∧ (0 : ℝ) ∉ [[a, b]] := by cases h · left; rwa [Complex.ofReal_re] · right; rwa [← Complex.ofReal_one, ← Complex.ofReal_neg, Ne, Complex.ofReal_inj] have : (∫ x in a..b, (x : ℂ) ^ (r : ℂ)) = ((b : ℂ) ^ (r + 1 : ℂ) - (a : ℂ) ^ (r + 1 : ℂ)) / (r + 1) := integral_cpow h' apply_fun Complex.re at this; convert this · simp_rw [intervalIntegral_eq_integral_uIoc, Complex.real_smul, Complex.re_ofReal_mul, rpow_def, ← RCLike.re_eq_complex_re, smul_eq_mul] rw [integral_re] refine intervalIntegrable_iff.mp ?_ rcases h' with h' | h' · exact intervalIntegrable_cpow' h' · exact intervalIntegrable_cpow (Or.inr h'.2) · rw [(by push_cast; rfl : (r : ℂ) + 1 = ((r + 1 : ℝ) : ℂ))] simp_rw [div_eq_inv_mul, ← Complex.ofReal_inv, Complex.re_ofReal_mul, Complex.sub_re, rpow_def] theorem integral_zpow {n : ℤ} (h : 0 ≤ n ∨ n ≠ -1 ∧ (0 : ℝ) ∉ [[a, b]]) : ∫ x in a..b, x ^ n = (b ^ (n + 1) - a ^ (n + 1)) / (n + 1) := by replace h : -1 < (n : ℝ) ∨ (n : ℝ) ≠ -1 ∧ (0 : ℝ) ∉ [[a, b]] := mod_cast h exact mod_cast integral_rpow h @[simp] theorem integral_pow : ∫ x in a..b, x ^ n = (b ^ (n + 1) - a ^ (n + 1)) / (n + 1) := by simpa only [← Int.natCast_succ, zpow_natCast] using integral_zpow (Or.inl n.cast_nonneg) /-- Integral of `|x - a| ^ n` over `Ι a b`. This integral appears in the proof of the Picard-Lindelöf/Cauchy-Lipschitz theorem. -/ theorem integral_pow_abs_sub_uIoc : ∫ x in Ι a b, |x - a| ^ n = |b - a| ^ (n + 1) / (n + 1) := by rcases le_or_lt a b with hab | hab · calc ∫ x in Ι a b, |x - a| ^ n = ∫ x in a..b, |x - a| ^ n := by rw [uIoc_of_le hab, ← integral_of_le hab] _ = ∫ x in (0)..(b - a), x ^ n := by simp only [integral_comp_sub_right fun x => |x| ^ n, sub_self] refine integral_congr fun x hx => congr_arg₂ Pow.pow (abs_of_nonneg <| ?_) rfl rw [uIcc_of_le (sub_nonneg.2 hab)] at hx exact hx.1 _ = |b - a| ^ (n + 1) / (n + 1) := by simp [abs_of_nonneg (sub_nonneg.2 hab)] · calc ∫ x in Ι a b, |x - a| ^ n = ∫ x in b..a, |x - a| ^ n := by rw [uIoc_of_ge hab.le, ← integral_of_le hab.le] _ = ∫ x in b - a..0, (-x) ^ n := by simp only [integral_comp_sub_right fun x => |x| ^ n, sub_self] refine integral_congr fun x hx => congr_arg₂ Pow.pow (abs_of_nonpos <| ?_) rfl rw [uIcc_of_le (sub_nonpos.2 hab.le)] at hx exact hx.2 _ = |b - a| ^ (n + 1) / (n + 1) := by simp [integral_comp_neg fun x => x ^ n, abs_of_neg (sub_neg.2 hab)] @[simp] theorem integral_id : ∫ x in a..b, x = (b ^ 2 - a ^ 2) / 2 := by have := @integral_pow a b 1 norm_num at this exact this theorem integral_one : (∫ _ in a..b, (1 : ℝ)) = b - a := by simp only [mul_one, smul_eq_mul, integral_const] theorem integral_const_on_unit_interval : ∫ _ in a..a + 1, b = b := by simp @[simp] theorem integral_inv (h : (0 : ℝ) ∉ [[a, b]]) : ∫ x in a..b, x⁻¹ = log (b / a) := by have h' := fun x (hx : x ∈ [[a, b]]) => ne_of_mem_of_not_mem hx h rw [integral_deriv_eq_sub' _ deriv_log' (fun x hx => differentiableAt_log (h' x hx)) (continuousOn_inv₀.mono <| subset_compl_singleton_iff.mpr h), log_div (h' b right_mem_uIcc) (h' a left_mem_uIcc)] @[simp] theorem integral_inv_of_pos (ha : 0 < a) (hb : 0 < b) : ∫ x in a..b, x⁻¹ = log (b / a) := integral_inv <| not_mem_uIcc_of_lt ha hb @[simp] theorem integral_inv_of_neg (ha : a < 0) (hb : b < 0) : ∫ x in a..b, x⁻¹ = log (b / a) := integral_inv <| not_mem_uIcc_of_gt ha hb theorem integral_one_div (h : (0 : ℝ) ∉ [[a, b]]) : ∫ x : ℝ in a..b, 1 / x = log (b / a) := by simp only [one_div, integral_inv h] theorem integral_one_div_of_pos (ha : 0 < a) (hb : 0 < b) : ∫ x : ℝ in a..b, 1 / x = log (b / a) := by simp only [one_div, integral_inv_of_pos ha hb] theorem integral_one_div_of_neg (ha : a < 0) (hb : b < 0) : ∫ x : ℝ in a..b, 1 / x = log (b / a) := by simp only [one_div, integral_inv_of_neg ha hb] @[simp] theorem integral_exp : ∫ x in a..b, exp x = exp b - exp a := by rw [integral_deriv_eq_sub'] · simp · exact fun _ _ => differentiableAt_exp · exact continuousOn_exp theorem integral_exp_mul_complex {c : ℂ} (hc : c ≠ 0) : (∫ x in a..b, Complex.exp (c * x)) = (Complex.exp (c * b) - Complex.exp (c * a)) / c := by have D : ∀ x : ℝ, HasDerivAt (fun y : ℝ => Complex.exp (c * y) / c) (Complex.exp (c * x)) x := by intro x conv => congr rw [← mul_div_cancel_right₀ (Complex.exp (c * x)) hc] apply ((Complex.hasDerivAt_exp _).comp x _).div_const c simpa only [mul_one] using ((hasDerivAt_id (x : ℂ)).const_mul _).comp_ofReal rw [integral_deriv_eq_sub' _ (funext fun x => (D x).deriv) fun x _ => (D x).differentiableAt] · ring · fun_prop /-- Helper lemma for `integral_log`: case where `a = 0` and `b` is positive. -/ lemma integral_log_from_zero_of_pos (ht : 0 < b) : ∫ s in (0)..b, log s = b * log b - b := by -- Compute the integral by giving a primitive and considering it limit as x approaches 0 from the -- right. The following lines were suggested by Gareth Ma on Zulip. rw [integral_eq_sub_of_hasDerivAt_of_tendsto (f := fun x ↦ x * log x - x) (fa := 0) (fb := b * log b - b) (hint := intervalIntegrable_log')] · abel · exact ht · intro s ⟨hs, _ ⟩ simpa using (hasDerivAt_mul_log hs.ne.symm).sub (hasDerivAt_id s) · simpa [mul_comm] using ((tendsto_log_mul_rpow_nhdsGT_zero zero_lt_one).sub (tendsto_nhdsWithin_of_tendsto_nhds Filter.tendsto_id)) · exact tendsto_nhdsWithin_of_tendsto_nhds (ContinuousAt.tendsto (by fun_prop)) /-- Helper lemma for `integral_log`: case where `a = 0`. -/ lemma integral_log_from_zero {b : ℝ} : ∫ s in (0)..b, log s = b * log b - b := by rcases lt_trichotomy b 0 with h | h | h · -- If t is negative, use that log is an even function to reduce to the positive case. conv => arg 1; arg 1; intro t; rw [← log_neg_eq_log] rw [intervalIntegral.integral_comp_neg, intervalIntegral.integral_symm, neg_zero, integral_log_from_zero_of_pos (Left.neg_pos_iff.mpr h), log_neg_eq_log] ring · simp [h] · exact integral_log_from_zero_of_pos h @[simp] theorem integral_log : ∫ s in a..b, log s = b * log b - a * log a - b + a := by rw [← intervalIntegral.integral_add_adjacent_intervals (b := 0)] · rw [intervalIntegral.integral_symm, integral_log_from_zero, integral_log_from_zero] ring all_goals exact intervalIntegrable_log' @[deprecated (since := "2025-01-12")] alias integral_log_of_pos := integral_log @[deprecated (since := "2025-01-12")] alias integral_log_of_neg := integral_log @[simp] theorem integral_sin : ∫ x in a..b, sin x = cos a - cos b := by rw [integral_deriv_eq_sub' fun x => -cos x] · ring · norm_num · simp only [differentiableAt_neg_iff, differentiableAt_cos, implies_true] · exact continuousOn_sin @[simp] theorem integral_cos : ∫ x in a..b, cos x = sin b - sin a := by rw [integral_deriv_eq_sub'] · norm_num · simp only [differentiableAt_sin, implies_true] · exact continuousOn_cos theorem integral_cos_mul_complex {z : ℂ} (hz : z ≠ 0) (a b : ℝ) : (∫ x in a..b, Complex.cos (z * x)) = Complex.sin (z * b) / z - Complex.sin (z * a) / z := by apply integral_eq_sub_of_hasDerivAt swap · apply Continuous.intervalIntegrable exact Complex.continuous_cos.comp (continuous_const.mul Complex.continuous_ofReal) intro x _ have a := Complex.hasDerivAt_sin (↑x * z) have b : HasDerivAt (fun y => y * z : ℂ → ℂ) z ↑x := hasDerivAt_mul_const _ have c : HasDerivAt (Complex.sin ∘ fun y : ℂ => (y * z)) _ ↑x := HasDerivAt.comp (𝕜 := ℂ) x a b have d := HasDerivAt.comp_ofReal (c.div_const z) simp only [mul_comm] at d convert d using 1 conv_rhs => arg 1; rw [mul_comm] rw [mul_div_cancel_right₀ _ hz] theorem integral_cos_sq_sub_sin_sq : ∫ x in a..b, cos x ^ 2 - sin x ^ 2 = sin b * cos b - sin a * cos a := by simpa only [sq, sub_eq_add_neg, neg_mul_eq_mul_neg] using integral_deriv_mul_eq_sub (fun x _ => hasDerivAt_sin x) (fun x _ => hasDerivAt_cos x) continuousOn_cos.intervalIntegrable continuousOn_sin.neg.intervalIntegrable theorem integral_one_div_one_add_sq : (∫ x : ℝ in a..b, ↑1 / (↑1 + x ^ 2)) = arctan b - arctan a := by refine integral_deriv_eq_sub' _ Real.deriv_arctan (fun _ _ => differentiableAt_arctan _) (continuous_const.div ?_ fun x => ?_).continuousOn · fun_prop · nlinarith @[simp] theorem integral_inv_one_add_sq : (∫ x : ℝ in a..b, (↑1 + x ^ 2)⁻¹) = arctan b - arctan a := by simp only [← one_div, integral_one_div_one_add_sq] section RpowCpow open Complex theorem integral_mul_cpow_one_add_sq {t : ℂ} (ht : t ≠ -1) : (∫ x : ℝ in a..b, (x : ℂ) * ((1 : ℂ) + ↑x ^ 2) ^ t) = ((1 : ℂ) + (b : ℂ) ^ 2) ^ (t + 1) / (2 * (t + ↑1)) - ((1 : ℂ) + (a : ℂ) ^ 2) ^ (t + 1) / (2 * (t + ↑1)) := by have : t + 1 ≠ 0 := by contrapose! ht; rwa [add_eq_zero_iff_eq_neg] at ht apply integral_eq_sub_of_hasDerivAt · intro x _ have f : HasDerivAt (fun y : ℂ => 1 + y ^ 2) (2 * x : ℂ) x := by convert (hasDerivAt_pow 2 (x : ℂ)).const_add 1 simp have g : ∀ {z : ℂ}, 0 < z.re → HasDerivAt (fun z => z ^ (t + 1) / (2 * (t + 1))) (z ^ t / 2) z := by intro z hz convert (HasDerivAt.cpow_const (c := t + 1) (hasDerivAt_id _) (Or.inl hz)).div_const (2 * (t + 1)) using 1 field_simp ring convert (HasDerivAt.comp (↑x) (g _) f).comp_ofReal using 1 · field_simp; ring · exact mod_cast add_pos_of_pos_of_nonneg zero_lt_one (sq_nonneg x) · apply Continuous.intervalIntegrable refine continuous_ofReal.mul ?_ apply Continuous.cpow · exact continuous_const.add (continuous_ofReal.pow 2) · exact continuous_const · intro a norm_cast exact ofReal_mem_slitPlane.2 <| add_pos_of_pos_of_nonneg one_pos <| sq_nonneg a theorem integral_mul_rpow_one_add_sq {t : ℝ} (ht : t ≠ -1) : (∫ x : ℝ in a..b, x * (↑1 + x ^ 2) ^ t) = (↑1 + b ^ 2) ^ (t + 1) / (↑2 * (t + ↑1)) - (↑1 + a ^ 2) ^ (t + 1) / (↑2 * (t + ↑1)) := by have : ∀ x s : ℝ, (((↑1 + x ^ 2) ^ s : ℝ) : ℂ) = (1 + (x : ℂ) ^ 2) ^ (s : ℂ) := by intro x s norm_cast rw [ofReal_cpow, ofReal_add, ofReal_pow, ofReal_one] exact add_nonneg zero_le_one (sq_nonneg x) rw [← ofReal_inj] convert integral_mul_cpow_one_add_sq (_ : (t : ℂ) ≠ -1) · rw [← intervalIntegral.integral_ofReal] congr with x : 1 rw [ofReal_mul, this x t] · simp_rw [ofReal_sub, ofReal_div, this a (t + 1), this b (t + 1)] push_cast; rfl · rw [← ofReal_one, ← ofReal_neg, Ne, ofReal_inj] exact ht end RpowCpow open Nat /-! ### Integral of `sin x ^ n` -/ theorem integral_sin_pow_aux : (∫ x in a..b, sin x ^ (n + 2)) = (sin a ^ (n + 1) * cos a - sin b ^ (n + 1) * cos b + (↑n + 1) * ∫ x in a..b, sin x ^ n) - (↑n + 1) * ∫ x in a..b, sin x ^ (n + 2) := by let C := sin a ^ (n + 1) * cos a - sin b ^ (n + 1) * cos b have h : ∀ α β γ : ℝ, β * α * γ * α = β * (α * α * γ) := fun α β γ => by ring have hu : ∀ x ∈ [[a, b]], HasDerivAt (fun y => sin y ^ (n + 1)) ((n + 1 : ℕ) * cos x * sin x ^ n) x := fun x _ => by simpa only [mul_right_comm] using (hasDerivAt_sin x).pow (n + 1) have hv : ∀ x ∈ [[a, b]], HasDerivAt (-cos) (sin x) x := fun x _ => by simpa only [neg_neg] using (hasDerivAt_cos x).neg have H := integral_mul_deriv_eq_deriv_mul hu hv ?_ ?_ · calc (∫ x in a..b, sin x ^ (n + 2)) = ∫ x in a..b, sin x ^ (n + 1) * sin x := by simp only [_root_.pow_succ] _ = C + (↑n + 1) * ∫ x in a..b, cos x ^ 2 * sin x ^ n := by simp [H, h, sq]; ring _ = C + (↑n + 1) * ∫ x in a..b, sin x ^ n - sin x ^ (n + 2) := by simp [cos_sq', sub_mul, ← pow_add, add_comm] _ = (C + (↑n + 1) * ∫ x in a..b, sin x ^ n) - (↑n + 1) * ∫ x in a..b, sin x ^ (n + 2) := by rw [integral_sub, mul_sub, add_sub_assoc] <;> apply Continuous.intervalIntegrable <;> fun_prop all_goals apply Continuous.intervalIntegrable; fun_prop /-- The reduction formula for the integral of `sin x ^ n` for any natural `n ≥ 2`. -/ theorem integral_sin_pow : (∫ x in a..b, sin x ^ (n + 2)) = (sin a ^ (n + 1) * cos a - sin b ^ (n + 1) * cos b) / (n + 2) + (n + 1) / (n + 2) * ∫ x in a..b, sin x ^ n := by field_simp convert eq_sub_iff_add_eq.mp (integral_sin_pow_aux n) using 1 ring @[simp] theorem integral_sin_sq : ∫ x in a..b, sin x ^ 2 = (sin a * cos a - sin b * cos b + b - a) / 2 := by field_simp [integral_sin_pow, add_sub_assoc] theorem integral_sin_pow_odd : (∫ x in (0)..π, sin x ^ (2 * n + 1)) = 2 * ∏ i ∈ range n, (2 * (i : ℝ) + 2) / (2 * i + 3) := by induction' n with k ih; · norm_num rw [prod_range_succ_comm, mul_left_comm, ← ih, mul_succ, integral_sin_pow] norm_cast simp [-cast_add, field_simps] theorem integral_sin_pow_even : (∫ x in (0)..π, sin x ^ (2 * n)) = π * ∏ i ∈ range n, (2 * (i : ℝ) + 1) / (2 * i + 2) := by induction' n with k ih; · simp rw [prod_range_succ_comm, mul_left_comm, ← ih, mul_succ, integral_sin_pow] norm_cast simp [-cast_add, field_simps] theorem integral_sin_pow_pos : 0 < ∫ x in (0)..π, sin x ^ n := by rcases even_or_odd' n with ⟨k, rfl | rfl⟩ <;> simp only [integral_sin_pow_even, integral_sin_pow_odd] <;> refine mul_pos (by norm_num [pi_pos]) (prod_pos fun n _ => div_pos ?_ ?_) <;> norm_cast <;> omega theorem integral_sin_pow_succ_le : (∫ x in (0)..π, sin x ^ (n + 1)) ≤ ∫ x in (0)..π, sin x ^ n := by let H x h := pow_le_pow_of_le_one (sin_nonneg_of_mem_Icc h) (sin_le_one x) (n.le_add_right 1) refine integral_mono_on pi_pos.le ?_ ?_ H <;> exact (continuous_sin.pow _).intervalIntegrable 0 π theorem integral_sin_pow_antitone : Antitone fun n : ℕ => ∫ x in (0)..π, sin x ^ n := antitone_nat_of_succ_le integral_sin_pow_succ_le
/-! ### Integral of `cos x ^ n` -/ theorem integral_cos_pow_aux : (∫ x in a..b, cos x ^ (n + 2)) = (cos b ^ (n + 1) * sin b - cos a ^ (n + 1) * sin a + (n + 1) * ∫ x in a..b, cos x ^ n) -
Mathlib/Analysis/SpecialFunctions/Integrals.lean
689
694
/- 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.Lattice.Prod import Mathlib.Data.Finite.Prod import Mathlib.Data.Set.Lattice.Image /-! # N-ary images of finsets This file defines `Finset.image₂`, the binary image of finsets. This is the finset version of `Set.image2`. This is mostly useful to define pointwise operations. ## Notes This file is very similar to `Data.Set.NAry`, `Order.Filter.NAry` and `Data.Option.NAry`. Please keep them in sync. We do not define `Finset.image₃` as its only purpose would be to prove properties of `Finset.image₂` and `Set.image2` already fulfills this task. -/ open Function Set variable {α α' β β' γ γ' δ δ' ε ε' ζ ζ' ν : Type*} namespace Finset variable [DecidableEq α'] [DecidableEq β'] [DecidableEq γ] [DecidableEq γ'] [DecidableEq δ'] [DecidableEq ε] [DecidableEq ε'] {f f' : α → β → γ} {g g' : α → β → γ → δ} {s s' : Finset α} {t t' : Finset β} {u u' : Finset γ} {a a' : α} {b b' : β} {c : γ} /-- The image of a binary function `f : α → β → γ` as a function `Finset α → Finset β → Finset γ`. Mathematically this should be thought of as the image of the corresponding function `α × β → γ`. -/ def image₂ (f : α → β → γ) (s : Finset α) (t : Finset β) : Finset γ := (s ×ˢ t).image <| uncurry f @[simp] theorem mem_image₂ : c ∈ image₂ f s t ↔ ∃ a ∈ s, ∃ b ∈ t, f a b = c := by simp [image₂, and_assoc] @[simp, norm_cast] theorem coe_image₂ (f : α → β → γ) (s : Finset α) (t : Finset β) : (image₂ f s t : Set γ) = Set.image2 f s t := Set.ext fun _ => mem_image₂ theorem card_image₂_le (f : α → β → γ) (s : Finset α) (t : Finset β) : #(image₂ f s t) ≤ #s * #t := card_image_le.trans_eq <| card_product _ _ theorem card_image₂_iff : #(image₂ f s t) = #s * #t ↔ (s ×ˢ t : Set (α × β)).InjOn fun x => f x.1 x.2 := by rw [← card_product, ← coe_product] exact card_image_iff theorem card_image₂ (hf : Injective2 f) (s : Finset α) (t : Finset β) : #(image₂ f s t) = #s * #t := (card_image_of_injective _ hf.uncurry).trans <| card_product _ _ theorem mem_image₂_of_mem (ha : a ∈ s) (hb : b ∈ t) : f a b ∈ image₂ f s t := mem_image₂.2 ⟨a, ha, b, hb, rfl⟩ theorem mem_image₂_iff (hf : Injective2 f) : f a b ∈ image₂ f s t ↔ a ∈ s ∧ b ∈ t := by rw [← mem_coe, coe_image₂, mem_image2_iff hf, mem_coe, mem_coe] @[gcongr] theorem image₂_subset (hs : s ⊆ s') (ht : t ⊆ t') : image₂ f s t ⊆ image₂ f s' t' := by rw [← coe_subset, coe_image₂, coe_image₂] exact image2_subset hs ht @[gcongr] theorem image₂_subset_left (ht : t ⊆ t') : image₂ f s t ⊆ image₂ f s t' := image₂_subset Subset.rfl ht @[gcongr] theorem image₂_subset_right (hs : s ⊆ s') : image₂ f s t ⊆ image₂ f s' t := image₂_subset hs Subset.rfl theorem image_subset_image₂_left (hb : b ∈ t) : s.image (fun a => f a b) ⊆ image₂ f s t := image_subset_iff.2 fun _ ha => mem_image₂_of_mem ha hb theorem image_subset_image₂_right (ha : a ∈ s) : t.image (fun b => f a b) ⊆ image₂ f s t := image_subset_iff.2 fun _ => mem_image₂_of_mem ha lemma forall_mem_image₂ {p : γ → Prop} : (∀ z ∈ image₂ f s t, p z) ↔ ∀ x ∈ s, ∀ y ∈ t, p (f x y) := by simp_rw [← mem_coe, coe_image₂, forall_mem_image2] lemma exists_mem_image₂ {p : γ → Prop} : (∃ z ∈ image₂ f s t, p z) ↔ ∃ x ∈ s, ∃ y ∈ t, p (f x y) := by simp_rw [← mem_coe, coe_image₂, exists_mem_image2] @[deprecated (since := "2024-11-23")] alias forall_image₂_iff := forall_mem_image₂ @[simp] theorem image₂_subset_iff : image₂ f s t ⊆ u ↔ ∀ x ∈ s, ∀ y ∈ t, f x y ∈ u := forall_mem_image₂ theorem image₂_subset_iff_left : image₂ f s t ⊆ u ↔ ∀ a ∈ s, (t.image fun b => f a b) ⊆ u := by simp_rw [image₂_subset_iff, image_subset_iff] theorem image₂_subset_iff_right : image₂ f s t ⊆ u ↔ ∀ b ∈ t, (s.image fun a => f a b) ⊆ u := by simp_rw [image₂_subset_iff, image_subset_iff, @forall₂_swap α] @[simp] theorem image₂_nonempty_iff : (image₂ f s t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := by rw [← coe_nonempty, coe_image₂] exact image2_nonempty_iff @[aesop safe apply (rule_sets := [finsetNonempty])] theorem Nonempty.image₂ (hs : s.Nonempty) (ht : t.Nonempty) : (image₂ f s t).Nonempty := image₂_nonempty_iff.2 ⟨hs, ht⟩ theorem Nonempty.of_image₂_left (h : (s.image₂ f t).Nonempty) : s.Nonempty := (image₂_nonempty_iff.1 h).1 theorem Nonempty.of_image₂_right (h : (s.image₂ f t).Nonempty) : t.Nonempty := (image₂_nonempty_iff.1 h).2 @[simp] theorem image₂_empty_left : image₂ f ∅ t = ∅ := coe_injective <| by simp @[simp] theorem image₂_empty_right : image₂ f s ∅ = ∅ := coe_injective <| by simp @[simp] theorem image₂_eq_empty_iff : image₂ f s t = ∅ ↔ s = ∅ ∨ t = ∅ := by simp_rw [← not_nonempty_iff_eq_empty, image₂_nonempty_iff, not_and_or] @[simp] theorem image₂_singleton_left : image₂ f {a} t = t.image fun b => f a b := ext fun x => by simp @[simp] theorem image₂_singleton_right : image₂ f s {b} = s.image fun a => f a b := ext fun x => by simp theorem image₂_singleton_left' : image₂ f {a} t = t.image (f a) := image₂_singleton_left theorem image₂_singleton : image₂ f {a} {b} = {f a b} := by simp theorem image₂_union_left [DecidableEq α] : image₂ f (s ∪ s') t = image₂ f s t ∪ image₂ f s' t := coe_injective <| by push_cast exact image2_union_left theorem image₂_union_right [DecidableEq β] : image₂ f s (t ∪ t') = image₂ f s t ∪ image₂ f s t' := coe_injective <| by push_cast exact image2_union_right @[simp] theorem image₂_insert_left [DecidableEq α] : image₂ f (insert a s) t = (t.image fun b => f a b) ∪ image₂ f s t := coe_injective <| by push_cast exact image2_insert_left @[simp] theorem image₂_insert_right [DecidableEq β] : image₂ f s (insert b t) = (s.image fun a => f a b) ∪ image₂ f s t := coe_injective <| by push_cast exact image2_insert_right theorem image₂_inter_left [DecidableEq α] (hf : Injective2 f) : image₂ f (s ∩ s') t = image₂ f s t ∩ image₂ f s' t := coe_injective <| by push_cast exact image2_inter_left hf theorem image₂_inter_right [DecidableEq β] (hf : Injective2 f) : image₂ f s (t ∩ t') = image₂ f s t ∩ image₂ f s t' := coe_injective <| by push_cast exact image2_inter_right hf theorem image₂_inter_subset_left [DecidableEq α] : image₂ f (s ∩ s') t ⊆ image₂ f s t ∩ image₂ f s' t := coe_subset.1 <| by push_cast exact image2_inter_subset_left theorem image₂_inter_subset_right [DecidableEq β] : image₂ f s (t ∩ t') ⊆ image₂ f s t ∩ image₂ f s t' := coe_subset.1 <| by push_cast exact image2_inter_subset_right theorem image₂_congr (h : ∀ a ∈ s, ∀ b ∈ t, f a b = f' a b) : image₂ f s t = image₂ f' s t := coe_injective <| by push_cast exact image2_congr h /-- A common special case of `image₂_congr` -/ theorem image₂_congr' (h : ∀ a b, f a b = f' a b) : image₂ f s t = image₂ f' s t := image₂_congr fun a _ b _ => h a b variable (s t) theorem card_image₂_singleton_left (hf : Injective (f a)) : #(image₂ f {a} t) = #t := by rw [image₂_singleton_left, card_image_of_injective _ hf] theorem card_image₂_singleton_right (hf : Injective fun a => f a b) : #(image₂ f s {b}) = #s := by rw [image₂_singleton_right, card_image_of_injective _ hf] theorem image₂_singleton_inter [DecidableEq β] (t₁ t₂ : Finset β) (hf : Injective (f a)) : image₂ f {a} (t₁ ∩ t₂) = image₂ f {a} t₁ ∩ image₂ f {a} t₂ := by simp_rw [image₂_singleton_left, image_inter _ _ hf] theorem image₂_inter_singleton [DecidableEq α] (s₁ s₂ : Finset α) (hf : Injective fun a => f a b) : image₂ f (s₁ ∩ s₂) {b} = image₂ f s₁ {b} ∩ image₂ f s₂ {b} := by simp_rw [image₂_singleton_right, image_inter _ _ hf] theorem card_le_card_image₂_left {s : Finset α} (hs : s.Nonempty) (hf : ∀ a, Injective (f a)) : #t ≤ #(image₂ f s t) := by obtain ⟨a, ha⟩ := hs rw [← card_image₂_singleton_left _ (hf a)] exact card_le_card (image₂_subset_right <| singleton_subset_iff.2 ha) theorem card_le_card_image₂_right {t : Finset β} (ht : t.Nonempty) (hf : ∀ b, Injective fun a => f a b) : #s ≤ #(image₂ f s t) := by obtain ⟨b, hb⟩ := ht rw [← card_image₂_singleton_right _ (hf b)] exact card_le_card (image₂_subset_left <| singleton_subset_iff.2 hb) variable {s t} theorem biUnion_image_left : (s.biUnion fun a => t.image <| f a) = image₂ f s t := coe_injective <| by push_cast exact Set.iUnion_image_left _ theorem biUnion_image_right : (t.biUnion fun b => s.image fun a => f a b) = image₂ f s t := coe_injective <| by push_cast exact Set.iUnion_image_right _ /-! ### Algebraic replacement rules A collection of lemmas to transfer associativity, commutativity, distributivity, ... of operations to the associativity, commutativity, distributivity, ... of `Finset.image₂` of those operations. The proof pattern is `image₂_lemma operation_lemma`. For example, `image₂_comm mul_comm` proves that `image₂ (*) f g = image₂ (*) g f` in a `CommSemigroup`. -/ section variable [DecidableEq δ] theorem image_image₂ (f : α → β → γ) (g : γ → δ) : (image₂ f s t).image g = image₂ (fun a b => g (f a b)) s t := coe_injective <| by push_cast exact image_image2 _ _ theorem image₂_image_left (f : γ → β → δ) (g : α → γ) : image₂ f (s.image g) t = image₂ (fun a b => f (g a) b) s t := coe_injective <| by push_cast exact image2_image_left _ _ theorem image₂_image_right (f : α → γ → δ) (g : β → γ) : image₂ f s (t.image g) = image₂ (fun a b => f a (g b)) s t := coe_injective <| by push_cast exact image2_image_right _ _ @[simp] theorem image₂_mk_eq_product [DecidableEq α] [DecidableEq β] (s : Finset α) (t : Finset β) : image₂ Prod.mk s t = s ×ˢ t := by ext; simp [Prod.ext_iff] @[simp] theorem image₂_curry (f : α × β → γ) (s : Finset α) (t : Finset β) : image₂ (curry f) s t = (s ×ˢ t).image f := rfl @[simp] theorem image_uncurry_product (f : α → β → γ) (s : Finset α) (t : Finset β) : (s ×ˢ t).image (uncurry f) = image₂ f s t := rfl theorem image₂_swap (f : α → β → γ) (s : Finset α) (t : Finset β) : image₂ f s t = image₂ (fun a b => f b a) t s := coe_injective <| by push_cast exact image2_swap _ _ _ @[simp] theorem image₂_left [DecidableEq α] (h : t.Nonempty) : image₂ (fun x _ => x) s t = s := coe_injective <| by push_cast exact image2_left h @[simp] theorem image₂_right [DecidableEq β] (h : s.Nonempty) : image₂ (fun _ y => y) s t = t := coe_injective <| by push_cast exact image2_right h theorem image₂_assoc {γ : Type*} {u : Finset γ} {f : δ → γ → ε} {g : α → β → δ} {f' : α → ε' → ε} {g' : β → γ → ε'} (h_assoc : ∀ a b c, f (g a b) c = f' a (g' b c)) : image₂ f (image₂ g s t) u = image₂ f' s (image₂ g' t u) := coe_injective <| by push_cast exact image2_assoc h_assoc theorem image₂_comm {g : β → α → γ} (h_comm : ∀ a b, f a b = g b a) : image₂ f s t = image₂ g t s := (image₂_swap _ _ _).trans <| by simp_rw [h_comm] theorem image₂_left_comm {γ : Type*} {u : Finset γ} {f : α → δ → ε} {g : β → γ → δ} {f' : α → γ → δ'} {g' : β → δ' → ε} (h_left_comm : ∀ a b c, f a (g b c) = g' b (f' a c)) : image₂ f s (image₂ g t u) = image₂ g' t (image₂ f' s u) := coe_injective <| by push_cast exact image2_left_comm h_left_comm theorem image₂_right_comm {γ : Type*} {u : Finset γ} {f : δ → γ → ε} {g : α → β → δ} {f' : α → γ → δ'} {g' : δ' → β → ε} (h_right_comm : ∀ a b c, f (g a b) c = g' (f' a c) b) : image₂ f (image₂ g s t) u = image₂ g' (image₂ f' s u) t := coe_injective <| by push_cast exact image2_right_comm h_right_comm theorem image₂_image₂_image₂_comm {γ δ : Type*} {u : Finset γ} {v : Finset δ} [DecidableEq ζ] [DecidableEq ζ'] [DecidableEq ν] {f : ε → ζ → ν} {g : α → β → ε} {h : γ → δ → ζ} {f' : ε' → ζ' → ν} {g' : α → γ → ε'} {h' : β → δ → ζ'} (h_comm : ∀ a b c d, f (g a b) (h c d) = f' (g' a c) (h' b d)) : image₂ f (image₂ g s t) (image₂ h u v) = image₂ f' (image₂ g' s u) (image₂ h' t v) := coe_injective <| by push_cast exact image2_image2_image2_comm h_comm theorem image_image₂_distrib {g : γ → δ} {f' : α' → β' → δ} {g₁ : α → α'} {g₂ : β → β'} (h_distrib : ∀ a b, g (f a b) = f' (g₁ a) (g₂ b)) : (image₂ f s t).image g = image₂ f' (s.image g₁) (t.image g₂) := coe_injective <| by push_cast exact image_image2_distrib h_distrib /-- Symmetric statement to `Finset.image₂_image_left_comm`. -/ theorem image_image₂_distrib_left {g : γ → δ} {f' : α' → β → δ} {g' : α → α'} (h_distrib : ∀ a b, g (f a b) = f' (g' a) b) : (image₂ f s t).image g = image₂ f' (s.image g') t := coe_injective <| by push_cast exact image_image2_distrib_left h_distrib /-- Symmetric statement to `Finset.image_image₂_right_comm`. -/ theorem image_image₂_distrib_right {g : γ → δ} {f' : α → β' → δ} {g' : β → β'} (h_distrib : ∀ a b, g (f a b) = f' a (g' b)) : (image₂ f s t).image g = image₂ f' s (t.image g') := coe_injective <| by push_cast exact image_image2_distrib_right h_distrib /-- Symmetric statement to `Finset.image_image₂_distrib_left`. -/ theorem image₂_image_left_comm {f : α' → β → γ} {g : α → α'} {f' : α → β → δ} {g' : δ → γ} (h_left_comm : ∀ a b, f (g a) b = g' (f' a b)) : image₂ f (s.image g) t = (image₂ f' s t).image g' := (image_image₂_distrib_left fun a b => (h_left_comm a b).symm).symm /-- Symmetric statement to `Finset.image_image₂_distrib_right`. -/ theorem image_image₂_right_comm {f : α → β' → γ} {g : β → β'} {f' : α → β → δ} {g' : δ → γ} (h_right_comm : ∀ a b, f a (g b) = g' (f' a b)) : image₂ f s (t.image g) = (image₂ f' s t).image g' := (image_image₂_distrib_right fun a b => (h_right_comm a b).symm).symm /-- The other direction does not hold because of the `s`-`s` cross terms on the RHS. -/ theorem image₂_distrib_subset_left {γ : Type*} {u : Finset γ} {f : α → δ → ε} {g : β → γ → δ} {f₁ : α → β → β'} {f₂ : α → γ → γ'} {g' : β' → γ' → ε} (h_distrib : ∀ a b c, f a (g b c) = g' (f₁ a b) (f₂ a c)) : image₂ f s (image₂ g t u) ⊆ image₂ g' (image₂ f₁ s t) (image₂ f₂ s u) := coe_subset.1 <| by push_cast exact Set.image2_distrib_subset_left h_distrib /-- The other direction does not hold because of the `u`-`u` cross terms on the RHS. -/ theorem image₂_distrib_subset_right {γ : Type*} {u : Finset γ} {f : δ → γ → ε} {g : α → β → δ} {f₁ : α → γ → α'} {f₂ : β → γ → β'} {g' : α' → β' → ε} (h_distrib : ∀ a b c, f (g a b) c = g' (f₁ a c) (f₂ b c)) : image₂ f (image₂ g s t) u ⊆ image₂ g' (image₂ f₁ s u) (image₂ f₂ t u) := coe_subset.1 <| by push_cast exact Set.image2_distrib_subset_right h_distrib theorem image_image₂_antidistrib {g : γ → δ} {f' : β' → α' → δ} {g₁ : β → β'} {g₂ : α → α'} (h_antidistrib : ∀ a b, g (f a b) = f' (g₁ b) (g₂ a)) : (image₂ f s t).image g = image₂ f' (t.image g₁) (s.image g₂) := by rw [image₂_swap f] exact image_image₂_distrib fun _ _ => h_antidistrib _ _ /-- Symmetric statement to `Finset.image₂_image_left_anticomm`. -/ theorem image_image₂_antidistrib_left {g : γ → δ} {f' : β' → α → δ} {g' : β → β'} (h_antidistrib : ∀ a b, g (f a b) = f' (g' b) a) : (image₂ f s t).image g = image₂ f' (t.image g') s := coe_injective <| by push_cast exact image_image2_antidistrib_left h_antidistrib /-- Symmetric statement to `Finset.image_image₂_right_anticomm`. -/ theorem image_image₂_antidistrib_right {g : γ → δ} {f' : β → α' → δ} {g' : α → α'} (h_antidistrib : ∀ a b, g (f a b) = f' b (g' a)) : (image₂ f s t).image g = image₂ f' t (s.image g') := coe_injective <| by push_cast exact image_image2_antidistrib_right h_antidistrib /-- Symmetric statement to `Finset.image_image₂_antidistrib_left`. -/ theorem image₂_image_left_anticomm {f : α' → β → γ} {g : α → α'} {f' : β → α → δ} {g' : δ → γ} (h_left_anticomm : ∀ a b, f (g a) b = g' (f' b a)) : image₂ f (s.image g) t = (image₂ f' t s).image g' := (image_image₂_antidistrib_left fun a b => (h_left_anticomm b a).symm).symm /-- Symmetric statement to `Finset.image_image₂_antidistrib_right`. -/ theorem image_image₂_right_anticomm {f : α → β' → γ} {g : β → β'} {f' : β → α → δ} {g' : δ → γ} (h_right_anticomm : ∀ a b, f a (g b) = g' (f' b a)) : image₂ f s (t.image g) = (image₂ f' t s).image g' := (image_image₂_antidistrib_right fun a b => (h_right_anticomm b a).symm).symm /-- If `a` is a left identity for `f : α → β → β`, then `{a}` is a left identity for `Finset.image₂ f`. -/ theorem image₂_left_identity {f : α → γ → γ} {a : α} (h : ∀ b, f a b = b) (t : Finset γ) : image₂ f {a} t = t := coe_injective <| by rw [coe_image₂, coe_singleton, Set.image2_left_identity h] /-- If `b` is a right identity for `f : α → β → α`, then `{b}` is a right identity for `Finset.image₂ f`. -/ theorem image₂_right_identity {f : γ → β → γ} {b : β} (h : ∀ a, f a b = a) (s : Finset γ) : image₂ f s {b} = s := by rw [image₂_singleton_right, funext h, image_id'] /-- If each partial application of `f` is injective, and images of `s` under those partial applications are disjoint (but not necessarily distinct!), then the size of `t` divides the size of `Finset.image₂ f s t`. -/ theorem card_dvd_card_image₂_right (hf : ∀ a ∈ s, Injective (f a)) (hs : ((fun a => t.image <| f a) '' s).PairwiseDisjoint id) : #t ∣ #(image₂ f s t) := by classical induction' s using Finset.induction with a s _ ih · simp specialize ih (forall_of_forall_insert hf) (hs.subset <| Set.image_subset _ <| coe_subset.2 <| subset_insert _ _) rw [image₂_insert_left] by_cases h : Disjoint (image (f a) t) (image₂ f s t) · rw [card_union_of_disjoint h] exact Nat.dvd_add (card_image_of_injective _ <| hf _ <| mem_insert_self _ _).symm.dvd ih simp_rw [← biUnion_image_left, disjoint_biUnion_right, not_forall] at h obtain ⟨b, hb, h⟩ := h rwa [union_eq_right.2] exact (hs.eq (Set.mem_image_of_mem _ <| mem_insert_self _ _) (Set.mem_image_of_mem _ <| mem_insert_of_mem hb) h).trans_subset (image_subset_image₂_right hb) /-- If each partial application of `f` is injective, and images of `t` under those partial applications are disjoint (but not necessarily distinct!), then the size of `s` divides the size of `Finset.image₂ f s t`. -/ theorem card_dvd_card_image₂_left (hf : ∀ b ∈ t, Injective fun a => f a b) (ht : ((fun b => s.image fun a => f a b) '' t).PairwiseDisjoint id) : #s ∣ #(image₂ f s t) := by rw [← image₂_swap]; exact card_dvd_card_image₂_right hf ht /-- If a `Finset` is a subset of the image of two `Set`s under a binary operation, then it is a subset of the `Finset.image₂` of two `Finset` subsets of these `Set`s. -/ theorem subset_set_image₂ {s : Set α} {t : Set β} (hu : ↑u ⊆ image2 f s t) : ∃ (s' : Finset α) (t' : Finset β), ↑s' ⊆ s ∧ ↑t' ⊆ t ∧ u ⊆ image₂ f s' t' := by rw [← Set.image_prod, subset_set_image_iff] at hu rcases hu with ⟨u, hu, rfl⟩ classical use u.image Prod.fst, u.image Prod.snd simp only [coe_image, Set.image_subset_iff, image₂_image_left, image₂_image_right, image_subset_iff] exact ⟨fun _ h ↦ (hu h).1, fun _ h ↦ (hu h).2, fun x hx ↦ mem_image₂_of_mem hx hx⟩ end section UnionInter variable [DecidableEq α] [DecidableEq β] theorem image₂_inter_union_subset_union : image₂ f (s ∩ s') (t ∪ t') ⊆ image₂ f s t ∪ image₂ f s' t' := coe_subset.1 <| by push_cast exact Set.image2_inter_union_subset_union theorem image₂_union_inter_subset_union : image₂ f (s ∪ s') (t ∩ t') ⊆ image₂ f s t ∪ image₂ f s' t' := coe_subset.1 <| by push_cast exact Set.image2_union_inter_subset_union theorem image₂_inter_union_subset {f : α → α → β} {s t : Finset α} (hf : ∀ a b, f a b = f b a) : image₂ f (s ∩ t) (s ∪ t) ⊆ image₂ f s t := coe_subset.1 <| by push_cast exact image2_inter_union_subset hf theorem image₂_union_inter_subset {f : α → α → β} {s t : Finset α} (hf : ∀ a b, f a b = f b a) : image₂ f (s ∪ t) (s ∩ t) ⊆ image₂ f s t := coe_subset.1 <| by push_cast exact image2_union_inter_subset hf end UnionInter section SemilatticeSup variable [SemilatticeSup δ] @[simp (default + 1)] -- otherwise `simp` doesn't use `forall_mem_image₂` lemma sup'_image₂_le {g : γ → δ} {a : δ} (h : (image₂ f s t).Nonempty) : sup' (image₂ f s t) h g ≤ a ↔ ∀ x ∈ s, ∀ y ∈ t, g (f x y) ≤ a := by rw [sup'_le_iff, forall_mem_image₂] lemma sup'_image₂_left (g : γ → δ) (h : (image₂ f s t).Nonempty) : sup' (image₂ f s t) h g = sup' s h.of_image₂_left fun x ↦ sup' t h.of_image₂_right (g <| f x ·) := by simp only [image₂, sup'_image, sup'_product_left]; rfl lemma sup'_image₂_right (g : γ → δ) (h : (image₂ f s t).Nonempty) : sup' (image₂ f s t) h g = sup' t h.of_image₂_right fun y ↦ sup' s h.of_image₂_left (g <| f · y) := by simp only [image₂, sup'_image, sup'_product_right]; rfl variable [OrderBot δ] @[simp (default + 1)] -- otherwise `simp` doesn't use `forall_mem_image₂` lemma sup_image₂_le {g : γ → δ} {a : δ} : sup (image₂ f s t) g ≤ a ↔ ∀ x ∈ s, ∀ y ∈ t, g (f x y) ≤ a := by rw [Finset.sup_le_iff, forall_mem_image₂] variable (s t) lemma sup_image₂_left (g : γ → δ) : sup (image₂ f s t) g = sup s fun x ↦ sup t (g <| f x ·) := by simp only [image₂, sup_image, sup_product_left]; rfl lemma sup_image₂_right (g : γ → δ) : sup (image₂ f s t) g = sup t fun y ↦ sup s (g <| f · y) := by simp only [image₂, sup_image, sup_product_right]; rfl end SemilatticeSup section SemilatticeInf variable [SemilatticeInf δ] @[simp (default + 1)] -- otherwise `simp` doesn't use `forall_mem_image₂` lemma le_inf'_image₂ {g : γ → δ} {a : δ} (h : (image₂ f s t).Nonempty) : a ≤ inf' (image₂ f s t) h g ↔ ∀ x ∈ s, ∀ y ∈ t, a ≤ g (f x y) := by rw [le_inf'_iff, forall_mem_image₂] lemma inf'_image₂_left (g : γ → δ) (h : (image₂ f s t).Nonempty) : inf' (image₂ f s t) h g = inf' s h.of_image₂_left fun x ↦ inf' t h.of_image₂_right (g <| f x ·) := sup'_image₂_left (δ := δᵒᵈ) g h lemma inf'_image₂_right (g : γ → δ) (h : (image₂ f s t).Nonempty) :
inf' (image₂ f s t) h g = inf' t h.of_image₂_right fun y ↦ inf' s h.of_image₂_left (g <| f · y) := sup'_image₂_right (δ := δᵒᵈ) g h variable [OrderTop δ]
Mathlib/Data/Finset/NAry.lean
559
563
/- Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Robert Y. Lewis, Johannes Hölzl, Mario Carneiro, Sébastien Gouëzel -/ import Mathlib.Data.ENNReal.Real import Mathlib.Tactic.Bound.Attribute import Mathlib.Topology.Bornology.Basic import Mathlib.Topology.EMetricSpace.Defs import Mathlib.Topology.UniformSpace.Basic /-! ## Pseudo-metric spaces This file defines pseudo-metric spaces: these differ from metric spaces by not imposing the condition `dist x y = 0 → x = y`. Many definitions and theorems expected on (pseudo-)metric spaces are already introduced on uniform spaces and topological spaces. For example: open and closed sets, compactness, completeness, continuity and uniform continuity. ## Main definitions * `Dist α`: Endows a space `α` with a function `dist a b`. * `PseudoMetricSpace α`: A space endowed with a distance function, which can be zero even if the two elements are non-equal. * `Metric.ball x ε`: The set of all points `y` with `dist y x < ε`. * `Metric.Bounded s`: Whether a subset of a `PseudoMetricSpace` is bounded. * `MetricSpace α`: A `PseudoMetricSpace` with the guarantee `dist x y = 0 → x = y`. Additional useful definitions: * `nndist a b`: `dist` as a function to the non-negative reals. * `Metric.closedBall x ε`: The set of all points `y` with `dist y x ≤ ε`. * `Metric.sphere x ε`: The set of all points `y` with `dist y x = ε`. TODO (anyone): Add "Main results" section. ## Tags pseudo_metric, dist -/ assert_not_exists compactSpace_uniformity open Set Filter TopologicalSpace Bornology open scoped ENNReal NNReal Uniformity Topology universe u v w variable {α : Type u} {β : Type v} {X ι : Type*} theorem UniformSpace.ofDist_aux (ε : ℝ) (hε : 0 < ε) : ∃ δ > (0 : ℝ), ∀ x < δ, ∀ y < δ, x + y < ε := ⟨ε / 2, half_pos hε, fun _x hx _y hy => add_halves ε ▸ add_lt_add hx hy⟩ /-- Construct a uniform structure from a distance function and metric space axioms -/ def UniformSpace.ofDist (dist : α → α → ℝ) (dist_self : ∀ x : α, dist x x = 0) (dist_comm : ∀ x y : α, dist x y = dist y x) (dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) : UniformSpace α := .ofFun dist dist_self dist_comm dist_triangle ofDist_aux /-- Construct a bornology from a distance function and metric space axioms. -/ abbrev Bornology.ofDist {α : Type*} (dist : α → α → ℝ) (dist_comm : ∀ x y, dist x y = dist y x) (dist_triangle : ∀ x y z, dist x z ≤ dist x y + dist y z) : Bornology α := Bornology.ofBounded { s : Set α | ∃ C, ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → dist x y ≤ C } ⟨0, fun _ hx _ => hx.elim⟩ (fun _ ⟨c, hc⟩ _ h => ⟨c, fun _ hx _ hy => hc (h hx) (h hy)⟩) (fun s hs t ht => by rcases s.eq_empty_or_nonempty with rfl | ⟨x, hx⟩ · rwa [empty_union] rcases t.eq_empty_or_nonempty with rfl | ⟨y, hy⟩ · rwa [union_empty] rsuffices ⟨C, hC⟩ : ∃ C, ∀ z ∈ s ∪ t, dist x z ≤ C · refine ⟨C + C, fun a ha b hb => (dist_triangle a x b).trans ?_⟩ simpa only [dist_comm] using add_le_add (hC _ ha) (hC _ hb) rcases hs with ⟨Cs, hs⟩; rcases ht with ⟨Ct, ht⟩ refine ⟨max Cs (dist x y + Ct), fun z hz => hz.elim (fun hz => (hs hx hz).trans (le_max_left _ _)) (fun hz => (dist_triangle x y z).trans <| (add_le_add le_rfl (ht hy hz)).trans (le_max_right _ _))⟩) fun z => ⟨dist z z, forall_eq.2 <| forall_eq.2 le_rfl⟩ /-- The distance function (given an ambient metric space on `α`), which returns a nonnegative real number `dist x y` given `x y : α`. -/ @[ext] class Dist (α : Type*) where /-- Distance between two points -/ dist : α → α → ℝ export Dist (dist) -- the uniform structure and the emetric space structure are embedded in the metric space structure -- to avoid instance diamond issues. See Note [forgetful inheritance]. /-- This is an internal lemma used inside the default of `PseudoMetricSpace.edist`. -/ private theorem dist_nonneg' {α} {x y : α} (dist : α → α → ℝ) (dist_self : ∀ x : α, dist x x = 0) (dist_comm : ∀ x y : α, dist x y = dist y x) (dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) : 0 ≤ dist x y := have : 0 ≤ 2 * dist x y := calc 0 = dist x x := (dist_self _).symm _ ≤ dist x y + dist y x := dist_triangle _ _ _ _ = 2 * dist x y := by rw [two_mul, dist_comm] nonneg_of_mul_nonneg_right this two_pos /-- A pseudometric space is a type endowed with a `ℝ`-valued distance `dist` satisfying reflexivity `dist x x = 0`, commutativity `dist x y = dist y x`, and the triangle inequality `dist x z ≤ dist x y + dist y z`. Note that we do not require `dist x y = 0 → x = y`. See metric spaces (`MetricSpace`) for the similar class with that stronger assumption. Any pseudometric space is a topological space and a uniform space (see `TopologicalSpace`, `UniformSpace`), where the topology and uniformity come from the metric. Note that a T1 pseudometric space is just a metric space. We make the uniformity/topology part of the data instead of deriving it from the metric. This eg ensures that we do not get a diamond when doing `[PseudoMetricSpace α] [PseudoMetricSpace β] : TopologicalSpace (α × β)`: The product metric and product topology agree, but not definitionally so. See Note [forgetful inheritance]. -/ class PseudoMetricSpace (α : Type u) : Type u extends Dist α where dist_self : ∀ x : α, dist x x = 0 dist_comm : ∀ x y : α, dist x y = dist y x dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z /-- Extended distance between two points -/ edist : α → α → ℝ≥0∞ := fun x y => ENNReal.ofNNReal ⟨dist x y, dist_nonneg' _ ‹_› ‹_› ‹_›⟩ edist_dist : ∀ x y : α, edist x y = ENNReal.ofReal (dist x y) := by intros x y; exact ENNReal.coe_nnreal_eq _ toUniformSpace : UniformSpace α := .ofDist dist dist_self dist_comm dist_triangle uniformity_dist : 𝓤 α = ⨅ ε > 0, 𝓟 { p : α × α | dist p.1 p.2 < ε } := by intros; rfl toBornology : Bornology α := Bornology.ofDist dist dist_comm dist_triangle cobounded_sets : (Bornology.cobounded α).sets = { s | ∃ C : ℝ, ∀ x ∈ sᶜ, ∀ y ∈ sᶜ, dist x y ≤ C } := by intros; rfl /-- Two pseudo metric space structures with the same distance function coincide. -/ @[ext] theorem PseudoMetricSpace.ext {α : Type*} {m m' : PseudoMetricSpace α} (h : m.toDist = m'.toDist) : m = m' := by let d := m.toDist obtain ⟨_, _, _, _, hed, _, hU, _, hB⟩ := m let d' := m'.toDist obtain ⟨_, _, _, _, hed', _, hU', _, hB'⟩ := m' obtain rfl : d = d' := h congr · ext x y : 2 rw [hed, hed'] · exact UniformSpace.ext (hU.trans hU'.symm) · ext : 2 rw [← Filter.mem_sets, ← Filter.mem_sets, hB, hB'] variable [PseudoMetricSpace α] attribute [instance] PseudoMetricSpace.toUniformSpace PseudoMetricSpace.toBornology -- see Note [lower instance priority] instance (priority := 200) PseudoMetricSpace.toEDist : EDist α := ⟨PseudoMetricSpace.edist⟩ /-- Construct a pseudo-metric space structure whose underlying topological space structure (definitionally) agrees which a pre-existing topology which is compatible with a given distance function. -/ def PseudoMetricSpace.ofDistTopology {α : Type u} [TopologicalSpace α] (dist : α → α → ℝ) (dist_self : ∀ x : α, dist x x = 0) (dist_comm : ∀ x y : α, dist x y = dist y x) (dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z) (H : ∀ s : Set α, IsOpen s ↔ ∀ x ∈ s, ∃ ε > 0, ∀ y, dist x y < ε → y ∈ s) : PseudoMetricSpace α := { dist := dist dist_self := dist_self dist_comm := dist_comm dist_triangle := dist_triangle toUniformSpace := (UniformSpace.ofDist dist dist_self dist_comm dist_triangle).replaceTopology <| TopologicalSpace.ext_iff.2 fun s ↦ (H s).trans <| forall₂_congr fun x _ ↦ ((UniformSpace.hasBasis_ofFun (exists_gt (0 : ℝ)) dist dist_self dist_comm dist_triangle UniformSpace.ofDist_aux).comap (Prod.mk x)).mem_iff.symm uniformity_dist := rfl toBornology := Bornology.ofDist dist dist_comm dist_triangle cobounded_sets := rfl } @[simp] theorem dist_self (x : α) : dist x x = 0 := PseudoMetricSpace.dist_self x theorem dist_comm (x y : α) : dist x y = dist y x := PseudoMetricSpace.dist_comm x y theorem edist_dist (x y : α) : edist x y = ENNReal.ofReal (dist x y) := PseudoMetricSpace.edist_dist x y @[bound] theorem dist_triangle (x y z : α) : dist x z ≤ dist x y + dist y z := PseudoMetricSpace.dist_triangle x y z theorem dist_triangle_left (x y z : α) : dist x y ≤ dist z x + dist z y := by rw [dist_comm z]; apply dist_triangle theorem dist_triangle_right (x y z : α) : dist x y ≤ dist x z + dist y z := by rw [dist_comm y]; apply dist_triangle theorem dist_triangle4 (x y z w : α) : dist x w ≤ dist x y + dist y z + dist z w := calc dist x w ≤ dist x z + dist z w := dist_triangle x z w _ ≤ dist x y + dist y z + dist z w := add_le_add_right (dist_triangle x y z) _ theorem dist_triangle4_left (x₁ y₁ x₂ y₂ : α) : dist x₂ y₂ ≤ dist x₁ y₁ + (dist x₁ x₂ + dist y₁ y₂) := by rw [add_left_comm, dist_comm x₁, ← add_assoc] apply dist_triangle4 theorem dist_triangle4_right (x₁ y₁ x₂ y₂ : α) : dist x₁ y₁ ≤ dist x₁ x₂ + dist y₁ y₂ + dist x₂ y₂ := by rw [add_right_comm, dist_comm y₁] apply dist_triangle4 theorem dist_triangle8 (a b c d e f g h : α) : dist a h ≤ dist a b + dist b c + dist c d + dist d e + dist e f + dist f g + dist g h := by apply le_trans (dist_triangle4 a f g h) apply add_le_add_right (add_le_add_right _ (dist f g)) (dist g h) apply le_trans (dist_triangle4 a d e f) apply add_le_add_right (add_le_add_right _ (dist d e)) (dist e f) exact dist_triangle4 a b c d theorem swap_dist : Function.swap (@dist α _) = dist := by funext x y; exact dist_comm _ _ theorem abs_dist_sub_le (x y z : α) : |dist x z - dist y z| ≤ dist x y := abs_sub_le_iff.2 ⟨sub_le_iff_le_add.2 (dist_triangle _ _ _), sub_le_iff_le_add.2 (dist_triangle_left _ _ _)⟩ @[bound] theorem dist_nonneg {x y : α} : 0 ≤ dist x y := dist_nonneg' dist dist_self dist_comm dist_triangle namespace Mathlib.Meta.Positivity open Lean Meta Qq Function /-- Extension for the `positivity` tactic: distances are nonnegative. -/ @[positivity Dist.dist _ _] def evalDist : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(@Dist.dist $β $inst $a $b) => let _inst ← synthInstanceQ q(PseudoMetricSpace $β) assertInstancesCommute pure (.nonnegative q(dist_nonneg)) | _, _, _ => throwError "not dist" end Mathlib.Meta.Positivity example {x y : α} : 0 ≤ dist x y := by positivity @[simp] theorem abs_dist {a b : α} : |dist a b| = dist a b := abs_of_nonneg dist_nonneg /-- A version of `Dist` that takes value in `ℝ≥0`. -/ class NNDist (α : Type*) where /-- Nonnegative distance between two points -/ nndist : α → α → ℝ≥0 export NNDist (nndist) -- see Note [lower instance priority] /-- Distance as a nonnegative real number. -/ instance (priority := 100) PseudoMetricSpace.toNNDist : NNDist α := ⟨fun a b => ⟨dist a b, dist_nonneg⟩⟩ /-- Express `dist` in terms of `nndist` -/ theorem dist_nndist (x y : α) : dist x y = nndist x y := rfl @[simp, norm_cast] theorem coe_nndist (x y : α) : ↑(nndist x y) = dist x y := rfl /-- Express `edist` in terms of `nndist` -/ theorem edist_nndist (x y : α) : edist x y = nndist x y := by rw [edist_dist, dist_nndist, ENNReal.ofReal_coe_nnreal] /-- Express `nndist` in terms of `edist` -/ theorem nndist_edist (x y : α) : nndist x y = (edist x y).toNNReal := by simp [edist_nndist] @[simp, norm_cast] theorem coe_nnreal_ennreal_nndist (x y : α) : ↑(nndist x y) = edist x y := (edist_nndist x y).symm @[simp, norm_cast] theorem edist_lt_coe {x y : α} {c : ℝ≥0} : edist x y < c ↔ nndist x y < c := by rw [edist_nndist, ENNReal.coe_lt_coe] @[simp, norm_cast] theorem edist_le_coe {x y : α} {c : ℝ≥0} : edist x y ≤ c ↔ nndist x y ≤ c := by rw [edist_nndist, ENNReal.coe_le_coe] /-- In a pseudometric space, the extended distance is always finite -/ theorem edist_lt_top {α : Type*} [PseudoMetricSpace α] (x y : α) : edist x y < ⊤ := (edist_dist x y).symm ▸ ENNReal.ofReal_lt_top /-- In a pseudometric space, the extended distance is always finite -/ theorem edist_ne_top (x y : α) : edist x y ≠ ⊤ := (edist_lt_top x y).ne /-- `nndist x x` vanishes -/ @[simp] theorem nndist_self (a : α) : nndist a a = 0 := NNReal.coe_eq_zero.1 (dist_self a) @[simp, norm_cast] theorem dist_lt_coe {x y : α} {c : ℝ≥0} : dist x y < c ↔ nndist x y < c := Iff.rfl @[simp, norm_cast] theorem dist_le_coe {x y : α} {c : ℝ≥0} : dist x y ≤ c ↔ nndist x y ≤ c := Iff.rfl @[simp] theorem edist_lt_ofReal {x y : α} {r : ℝ} : edist x y < ENNReal.ofReal r ↔ dist x y < r := by rw [edist_dist, ENNReal.ofReal_lt_ofReal_iff_of_nonneg dist_nonneg] @[simp] theorem edist_le_ofReal {x y : α} {r : ℝ} (hr : 0 ≤ r) : edist x y ≤ ENNReal.ofReal r ↔ dist x y ≤ r := by rw [edist_dist, ENNReal.ofReal_le_ofReal_iff hr] /-- Express `nndist` in terms of `dist` -/ theorem nndist_dist (x y : α) : nndist x y = Real.toNNReal (dist x y) := by rw [dist_nndist, Real.toNNReal_coe] theorem nndist_comm (x y : α) : nndist x y = nndist y x := NNReal.eq <| dist_comm x y /-- Triangle inequality for the nonnegative distance -/ theorem nndist_triangle (x y z : α) : nndist x z ≤ nndist x y + nndist y z := dist_triangle _ _ _ theorem nndist_triangle_left (x y z : α) : nndist x y ≤ nndist z x + nndist z y := dist_triangle_left _ _ _ theorem nndist_triangle_right (x y z : α) : nndist x y ≤ nndist x z + nndist y z := dist_triangle_right _ _ _ /-- Express `dist` in terms of `edist` -/ theorem dist_edist (x y : α) : dist x y = (edist x y).toReal := by rw [edist_dist, ENNReal.toReal_ofReal dist_nonneg] namespace Metric -- instantiate pseudometric space as a topology variable {x y z : α} {δ ε ε₁ ε₂ : ℝ} {s : Set α} /-- `ball x ε` is the set of all points `y` with `dist y x < ε` -/ def ball (x : α) (ε : ℝ) : Set α := { y | dist y x < ε } @[simp] theorem mem_ball : y ∈ ball x ε ↔ dist y x < ε := Iff.rfl theorem mem_ball' : y ∈ ball x ε ↔ dist x y < ε := by rw [dist_comm, mem_ball] theorem pos_of_mem_ball (hy : y ∈ ball x ε) : 0 < ε := dist_nonneg.trans_lt hy theorem mem_ball_self (h : 0 < ε) : x ∈ ball x ε := by rwa [mem_ball, dist_self] @[simp] theorem nonempty_ball : (ball x ε).Nonempty ↔ 0 < ε := ⟨fun ⟨_x, hx⟩ => pos_of_mem_ball hx, fun h => ⟨x, mem_ball_self h⟩⟩ @[simp] theorem ball_eq_empty : ball x ε = ∅ ↔ ε ≤ 0 := by rw [← not_nonempty_iff_eq_empty, nonempty_ball, not_lt] @[simp] theorem ball_zero : ball x 0 = ∅ := by rw [ball_eq_empty] /-- If a point belongs to an open ball, then there is a strictly smaller radius whose ball also contains it. See also `exists_lt_subset_ball`. -/ theorem exists_lt_mem_ball_of_mem_ball (h : x ∈ ball y ε) : ∃ ε' < ε, x ∈ ball y ε' := by simp only [mem_ball] at h ⊢ exact ⟨(dist x y + ε) / 2, by linarith, by linarith⟩ theorem ball_eq_ball (ε : ℝ) (x : α) : UniformSpace.ball x { p | dist p.2 p.1 < ε } = Metric.ball x ε := rfl theorem ball_eq_ball' (ε : ℝ) (x : α) : UniformSpace.ball x { p | dist p.1 p.2 < ε } = Metric.ball x ε := by ext simp [dist_comm, UniformSpace.ball] @[simp] theorem iUnion_ball_nat (x : α) : ⋃ n : ℕ, ball x n = univ := iUnion_eq_univ_iff.2 fun y => exists_nat_gt (dist y x) @[simp] theorem iUnion_ball_nat_succ (x : α) : ⋃ n : ℕ, ball x (n + 1) = univ := iUnion_eq_univ_iff.2 fun y => (exists_nat_gt (dist y x)).imp fun _ h => h.trans (lt_add_one _) /-- `closedBall x ε` is the set of all points `y` with `dist y x ≤ ε` -/ def closedBall (x : α) (ε : ℝ) := { y | dist y x ≤ ε } @[simp] theorem mem_closedBall : y ∈ closedBall x ε ↔ dist y x ≤ ε := Iff.rfl theorem mem_closedBall' : y ∈ closedBall x ε ↔ dist x y ≤ ε := by rw [dist_comm, mem_closedBall] /-- `sphere x ε` is the set of all points `y` with `dist y x = ε` -/ def sphere (x : α) (ε : ℝ) := { y | dist y x = ε } @[simp] theorem mem_sphere : y ∈ sphere x ε ↔ dist y x = ε := Iff.rfl theorem mem_sphere' : y ∈ sphere x ε ↔ dist x y = ε := by rw [dist_comm, mem_sphere] theorem ne_of_mem_sphere (h : y ∈ sphere x ε) (hε : ε ≠ 0) : y ≠ x := ne_of_mem_of_not_mem h <| by simpa using hε.symm theorem nonneg_of_mem_sphere (hy : y ∈ sphere x ε) : 0 ≤ ε := dist_nonneg.trans_eq hy @[simp] theorem sphere_eq_empty_of_neg (hε : ε < 0) : sphere x ε = ∅ := Set.eq_empty_iff_forall_not_mem.mpr fun _y hy => (nonneg_of_mem_sphere hy).not_lt hε theorem sphere_eq_empty_of_subsingleton [Subsingleton α] (hε : ε ≠ 0) : sphere x ε = ∅ := Set.eq_empty_iff_forall_not_mem.mpr fun _ h => ne_of_mem_sphere h hε (Subsingleton.elim _ _) instance sphere_isEmpty_of_subsingleton [Subsingleton α] [NeZero ε] : IsEmpty (sphere x ε) := by rw [sphere_eq_empty_of_subsingleton (NeZero.ne ε)]; infer_instance theorem closedBall_eq_singleton_of_subsingleton [Subsingleton α] (h : 0 ≤ ε) : closedBall x ε = {x} := by ext x' simpa [Subsingleton.allEq x x'] theorem ball_eq_singleton_of_subsingleton [Subsingleton α] (h : 0 < ε) : ball x ε = {x} := by ext x' simpa [Subsingleton.allEq x x'] theorem mem_closedBall_self (h : 0 ≤ ε) : x ∈ closedBall x ε := by rwa [mem_closedBall, dist_self] @[simp] theorem nonempty_closedBall : (closedBall x ε).Nonempty ↔ 0 ≤ ε := ⟨fun ⟨_x, hx⟩ => dist_nonneg.trans hx, fun h => ⟨x, mem_closedBall_self h⟩⟩ @[simp] theorem closedBall_eq_empty : closedBall x ε = ∅ ↔ ε < 0 := by rw [← not_nonempty_iff_eq_empty, nonempty_closedBall, not_le] /-- Closed balls and spheres coincide when the radius is non-positive -/ theorem closedBall_eq_sphere_of_nonpos (hε : ε ≤ 0) : closedBall x ε = sphere x ε := Set.ext fun _ => (hε.trans dist_nonneg).le_iff_eq theorem ball_subset_closedBall : ball x ε ⊆ closedBall x ε := fun _y hy => mem_closedBall.2 (le_of_lt hy) theorem sphere_subset_closedBall : sphere x ε ⊆ closedBall x ε := fun _ => le_of_eq lemma sphere_subset_ball {r R : ℝ} (h : r < R) : sphere x r ⊆ ball x R := fun _x hx ↦ (mem_sphere.1 hx).trans_lt h theorem closedBall_disjoint_ball (h : δ + ε ≤ dist x y) : Disjoint (closedBall x δ) (ball y ε) := Set.disjoint_left.mpr fun _a ha1 ha2 => (h.trans <| dist_triangle_left _ _ _).not_lt <| add_lt_add_of_le_of_lt ha1 ha2 theorem ball_disjoint_closedBall (h : δ + ε ≤ dist x y) : Disjoint (ball x δ) (closedBall y ε) := (closedBall_disjoint_ball <| by rwa [add_comm, dist_comm]).symm theorem ball_disjoint_ball (h : δ + ε ≤ dist x y) : Disjoint (ball x δ) (ball y ε) := (closedBall_disjoint_ball h).mono_left ball_subset_closedBall theorem closedBall_disjoint_closedBall (h : δ + ε < dist x y) : Disjoint (closedBall x δ) (closedBall y ε) := Set.disjoint_left.mpr fun _a ha1 ha2 => h.not_le <| (dist_triangle_left _ _ _).trans <| add_le_add ha1 ha2 theorem sphere_disjoint_ball : Disjoint (sphere x ε) (ball x ε) := Set.disjoint_left.mpr fun _y hy₁ hy₂ => absurd hy₁ <| ne_of_lt hy₂ @[simp] theorem ball_union_sphere : ball x ε ∪ sphere x ε = closedBall x ε := Set.ext fun _y => (@le_iff_lt_or_eq ℝ _ _ _).symm @[simp] theorem sphere_union_ball : sphere x ε ∪ ball x ε = closedBall x ε := by rw [union_comm, ball_union_sphere] @[simp] theorem closedBall_diff_sphere : closedBall x ε \ sphere x ε = ball x ε := by rw [← ball_union_sphere, Set.union_diff_cancel_right sphere_disjoint_ball.symm.le_bot] @[simp] theorem closedBall_diff_ball : closedBall x ε \ ball x ε = sphere x ε := by rw [← ball_union_sphere, Set.union_diff_cancel_left sphere_disjoint_ball.symm.le_bot] theorem mem_ball_comm : x ∈ ball y ε ↔ y ∈ ball x ε := by rw [mem_ball', mem_ball] theorem mem_closedBall_comm : x ∈ closedBall y ε ↔ y ∈ closedBall x ε := by rw [mem_closedBall', mem_closedBall] theorem mem_sphere_comm : x ∈ sphere y ε ↔ y ∈ sphere x ε := by rw [mem_sphere', mem_sphere] @[gcongr] theorem ball_subset_ball (h : ε₁ ≤ ε₂) : ball x ε₁ ⊆ ball x ε₂ := fun _y yx => lt_of_lt_of_le (mem_ball.1 yx) h theorem closedBall_eq_bInter_ball : closedBall x ε = ⋂ δ > ε, ball x δ := by ext y; rw [mem_closedBall, ← forall_lt_iff_le', mem_iInter₂]; rfl theorem ball_subset_ball' (h : ε₁ + dist x y ≤ ε₂) : ball x ε₁ ⊆ ball y ε₂ := fun z hz => calc dist z y ≤ dist z x + dist x y := dist_triangle _ _ _ _ < ε₁ + dist x y := add_lt_add_right (mem_ball.1 hz) _ _ ≤ ε₂ := h @[gcongr] theorem closedBall_subset_closedBall (h : ε₁ ≤ ε₂) : closedBall x ε₁ ⊆ closedBall x ε₂ := fun _y (yx : _ ≤ ε₁) => le_trans yx h theorem closedBall_subset_closedBall' (h : ε₁ + dist x y ≤ ε₂) : closedBall x ε₁ ⊆ closedBall y ε₂ := fun z hz => calc dist z y ≤ dist z x + dist x y := dist_triangle _ _ _ _ ≤ ε₁ + dist x y := add_le_add_right (mem_closedBall.1 hz) _ _ ≤ ε₂ := h theorem closedBall_subset_ball (h : ε₁ < ε₂) : closedBall x ε₁ ⊆ ball x ε₂ := fun y (yh : dist y x ≤ ε₁) => lt_of_le_of_lt yh h theorem closedBall_subset_ball' (h : ε₁ + dist x y < ε₂) : closedBall x ε₁ ⊆ ball y ε₂ := fun z hz => calc dist z y ≤ dist z x + dist x y := dist_triangle _ _ _ _ ≤ ε₁ + dist x y := add_le_add_right (mem_closedBall.1 hz) _ _ < ε₂ := h theorem dist_le_add_of_nonempty_closedBall_inter_closedBall (h : (closedBall x ε₁ ∩ closedBall y ε₂).Nonempty) : dist x y ≤ ε₁ + ε₂ := let ⟨z, hz⟩ := h calc dist x y ≤ dist z x + dist z y := dist_triangle_left _ _ _ _ ≤ ε₁ + ε₂ := add_le_add hz.1 hz.2 theorem dist_lt_add_of_nonempty_closedBall_inter_ball (h : (closedBall x ε₁ ∩ ball y ε₂).Nonempty) : dist x y < ε₁ + ε₂ := let ⟨z, hz⟩ := h calc dist x y ≤ dist z x + dist z y := dist_triangle_left _ _ _ _ < ε₁ + ε₂ := add_lt_add_of_le_of_lt hz.1 hz.2 theorem dist_lt_add_of_nonempty_ball_inter_closedBall (h : (ball x ε₁ ∩ closedBall y ε₂).Nonempty) : dist x y < ε₁ + ε₂ := by rw [inter_comm] at h rw [add_comm, dist_comm] exact dist_lt_add_of_nonempty_closedBall_inter_ball h theorem dist_lt_add_of_nonempty_ball_inter_ball (h : (ball x ε₁ ∩ ball y ε₂).Nonempty) : dist x y < ε₁ + ε₂ := dist_lt_add_of_nonempty_closedBall_inter_ball <| h.mono (inter_subset_inter ball_subset_closedBall Subset.rfl) @[simp] theorem iUnion_closedBall_nat (x : α) : ⋃ n : ℕ, closedBall x n = univ := iUnion_eq_univ_iff.2 fun y => exists_nat_ge (dist y x) theorem iUnion_inter_closedBall_nat (s : Set α) (x : α) : ⋃ n : ℕ, s ∩ closedBall x n = s := by rw [← inter_iUnion, iUnion_closedBall_nat, inter_univ] theorem ball_subset (h : dist x y ≤ ε₂ - ε₁) : ball x ε₁ ⊆ ball y ε₂ := fun z zx => by rw [← add_sub_cancel ε₁ ε₂] exact lt_of_le_of_lt (dist_triangle z x y) (add_lt_add_of_lt_of_le zx h) theorem ball_half_subset (y) (h : y ∈ ball x (ε / 2)) : ball y (ε / 2) ⊆ ball x ε := ball_subset <| by rw [sub_self_div_two]; exact le_of_lt h theorem exists_ball_subset_ball (h : y ∈ ball x ε) : ∃ ε' > 0, ball y ε' ⊆ ball x ε := ⟨_, sub_pos.2 h, ball_subset <| by rw [sub_sub_self]⟩ /-- If a property holds for all points in closed balls of arbitrarily large radii, then it holds for all points. -/ theorem forall_of_forall_mem_closedBall (p : α → Prop) (x : α) (H : ∃ᶠ R : ℝ in atTop, ∀ y ∈ closedBall x R, p y) (y : α) : p y := by obtain ⟨R, hR, h⟩ : ∃ R ≥ dist y x, ∀ z : α, z ∈ closedBall x R → p z := frequently_iff.1 H (Ici_mem_atTop (dist y x)) exact h _ hR /-- If a property holds for all points in balls of arbitrarily large radii, then it holds for all points. -/ theorem forall_of_forall_mem_ball (p : α → Prop) (x : α) (H : ∃ᶠ R : ℝ in atTop, ∀ y ∈ ball x R, p y) (y : α) : p y := by obtain ⟨R, hR, h⟩ : ∃ R > dist y x, ∀ z : α, z ∈ ball x R → p z := frequently_iff.1 H (Ioi_mem_atTop (dist y x)) exact h _ hR theorem isBounded_iff {s : Set α} : IsBounded s ↔ ∃ C : ℝ, ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → dist x y ≤ C := by rw [isBounded_def, ← Filter.mem_sets, @PseudoMetricSpace.cobounded_sets α, mem_setOf_eq, compl_compl] theorem isBounded_iff_eventually {s : Set α} : IsBounded s ↔ ∀ᶠ C in atTop, ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → dist x y ≤ C := isBounded_iff.trans ⟨fun ⟨C, h⟩ => eventually_atTop.2 ⟨C, fun _C' hC' _x hx _y hy => (h hx hy).trans hC'⟩, Eventually.exists⟩ theorem isBounded_iff_exists_ge {s : Set α} (c : ℝ) : IsBounded s ↔ ∃ C, c ≤ C ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → dist x y ≤ C := ⟨fun h => ((eventually_ge_atTop c).and (isBounded_iff_eventually.1 h)).exists, fun h => isBounded_iff.2 <| h.imp fun _ => And.right⟩ theorem isBounded_iff_nndist {s : Set α} : IsBounded s ↔ ∃ C : ℝ≥0, ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → nndist x y ≤ C := by simp only [isBounded_iff_exists_ge 0, NNReal.exists, ← NNReal.coe_le_coe, ← dist_nndist, NNReal.coe_mk, exists_prop] theorem toUniformSpace_eq : ‹PseudoMetricSpace α›.toUniformSpace = .ofDist dist dist_self dist_comm dist_triangle := UniformSpace.ext PseudoMetricSpace.uniformity_dist theorem uniformity_basis_dist : (𝓤 α).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { p : α × α | dist p.1 p.2 < ε } := by rw [toUniformSpace_eq] exact UniformSpace.hasBasis_ofFun (exists_gt _) _ _ _ _ _ /-- Given `f : β → ℝ`, if `f` sends `{i | p i}` to a set of positive numbers accumulating to zero, then `f i`-neighborhoods of the diagonal form a basis of `𝓤 α`. For specific bases see `uniformity_basis_dist`, `uniformity_basis_dist_inv_nat_succ`, and `uniformity_basis_dist_inv_nat_pos`. -/ protected theorem mk_uniformity_basis {β : Type*} {p : β → Prop} {f : β → ℝ} (hf₀ : ∀ i, p i → 0 < f i) (hf : ∀ ⦃ε⦄, 0 < ε → ∃ i, p i ∧ f i ≤ ε) : (𝓤 α).HasBasis p fun i => { p : α × α | dist p.1 p.2 < f i } := by refine ⟨fun s => uniformity_basis_dist.mem_iff.trans ?_⟩ constructor · rintro ⟨ε, ε₀, hε⟩ rcases hf ε₀ with ⟨i, hi, H⟩ exact ⟨i, hi, fun x (hx : _ < _) => hε <| lt_of_lt_of_le hx H⟩ · exact fun ⟨i, hi, H⟩ => ⟨f i, hf₀ i hi, H⟩ theorem uniformity_basis_dist_rat : (𝓤 α).HasBasis (fun r : ℚ => 0 < r) fun r => { p : α × α | dist p.1 p.2 < r } := Metric.mk_uniformity_basis (fun _ => Rat.cast_pos.2) fun _ε hε => let ⟨r, hr0, hrε⟩ := exists_rat_btwn hε ⟨r, Rat.cast_pos.1 hr0, hrε.le⟩ theorem uniformity_basis_dist_inv_nat_succ : (𝓤 α).HasBasis (fun _ => True) fun n : ℕ => { p : α × α | dist p.1 p.2 < 1 / (↑n + 1) } := Metric.mk_uniformity_basis (fun n _ => div_pos zero_lt_one <| Nat.cast_add_one_pos n) fun _ε ε0 => (exists_nat_one_div_lt ε0).imp fun _n hn => ⟨trivial, le_of_lt hn⟩ theorem uniformity_basis_dist_inv_nat_pos : (𝓤 α).HasBasis (fun n : ℕ => 0 < n) fun n : ℕ => { p : α × α | dist p.1 p.2 < 1 / ↑n } := Metric.mk_uniformity_basis (fun _ hn => div_pos zero_lt_one <| Nat.cast_pos.2 hn) fun _ ε0 => let ⟨n, hn⟩ := exists_nat_one_div_lt ε0 ⟨n + 1, Nat.succ_pos n, mod_cast hn.le⟩ theorem uniformity_basis_dist_pow {r : ℝ} (h0 : 0 < r) (h1 : r < 1) : (𝓤 α).HasBasis (fun _ : ℕ => True) fun n : ℕ => { p : α × α | dist p.1 p.2 < r ^ n } := Metric.mk_uniformity_basis (fun _ _ => pow_pos h0 _) fun _ε ε0 => let ⟨n, hn⟩ := exists_pow_lt_of_lt_one ε0 h1 ⟨n, trivial, hn.le⟩ theorem uniformity_basis_dist_lt {R : ℝ} (hR : 0 < R) : (𝓤 α).HasBasis (fun r : ℝ => 0 < r ∧ r < R) fun r => { p : α × α | dist p.1 p.2 < r } := Metric.mk_uniformity_basis (fun _ => And.left) fun r hr => ⟨min r (R / 2), ⟨lt_min hr (half_pos hR), min_lt_iff.2 <| Or.inr (half_lt_self hR)⟩, min_le_left _ _⟩ /-- Given `f : β → ℝ`, if `f` sends `{i | p i}` to a set of positive numbers accumulating to zero, then closed neighborhoods of the diagonal of sizes `{f i | p i}` form a basis of `𝓤 α`. Currently we have only one specific basis `uniformity_basis_dist_le` based on this constructor. More can be easily added if needed in the future. -/ protected theorem mk_uniformity_basis_le {β : Type*} {p : β → Prop} {f : β → ℝ} (hf₀ : ∀ x, p x → 0 < f x) (hf : ∀ ε, 0 < ε → ∃ x, p x ∧ f x ≤ ε) : (𝓤 α).HasBasis p fun x => { p : α × α | dist p.1 p.2 ≤ f x } := by refine ⟨fun s => uniformity_basis_dist.mem_iff.trans ?_⟩ constructor · rintro ⟨ε, ε₀, hε⟩ rcases exists_between ε₀ with ⟨ε', hε'⟩ rcases hf ε' hε'.1 with ⟨i, hi, H⟩ exact ⟨i, hi, fun x (hx : _ ≤ _) => hε <| lt_of_le_of_lt (le_trans hx H) hε'.2⟩ · exact fun ⟨i, hi, H⟩ => ⟨f i, hf₀ i hi, fun x (hx : _ < _) => H (mem_setOf.2 hx.le)⟩ /-- Constant size closed neighborhoods of the diagonal form a basis of the uniformity filter. -/ theorem uniformity_basis_dist_le : (𝓤 α).HasBasis ((0 : ℝ) < ·) fun ε => { p : α × α | dist p.1 p.2 ≤ ε } := Metric.mk_uniformity_basis_le (fun _ => id) fun ε ε₀ => ⟨ε, ε₀, le_refl ε⟩ theorem uniformity_basis_dist_le_pow {r : ℝ} (h0 : 0 < r) (h1 : r < 1) : (𝓤 α).HasBasis (fun _ : ℕ => True) fun n : ℕ => { p : α × α | dist p.1 p.2 ≤ r ^ n } := Metric.mk_uniformity_basis_le (fun _ _ => pow_pos h0 _) fun _ε ε0 => let ⟨n, hn⟩ := exists_pow_lt_of_lt_one ε0 h1 ⟨n, trivial, hn.le⟩ theorem mem_uniformity_dist {s : Set (α × α)} : s ∈ 𝓤 α ↔ ∃ ε > 0, ∀ ⦃a b : α⦄, dist a b < ε → (a, b) ∈ s := uniformity_basis_dist.mem_uniformity_iff /-- A constant size neighborhood of the diagonal is an entourage. -/ theorem dist_mem_uniformity {ε : ℝ} (ε0 : 0 < ε) : { p : α × α | dist p.1 p.2 < ε } ∈ 𝓤 α := mem_uniformity_dist.2 ⟨ε, ε0, fun _ _ ↦ id⟩ theorem uniformContinuous_iff [PseudoMetricSpace β] {f : α → β} : UniformContinuous f ↔ ∀ ε > 0, ∃ δ > 0, ∀ ⦃a b : α⦄, dist a b < δ → dist (f a) (f b) < ε := uniformity_basis_dist.uniformContinuous_iff uniformity_basis_dist theorem uniformContinuousOn_iff [PseudoMetricSpace β] {f : α → β} {s : Set α} : UniformContinuousOn f s ↔ ∀ ε > 0, ∃ δ > 0, ∀ x ∈ s, ∀ y ∈ s, dist x y < δ → dist (f x) (f y) < ε := Metric.uniformity_basis_dist.uniformContinuousOn_iff Metric.uniformity_basis_dist theorem uniformContinuousOn_iff_le [PseudoMetricSpace β] {f : α → β} {s : Set α} : UniformContinuousOn f s ↔ ∀ ε > 0, ∃ δ > 0, ∀ x ∈ s, ∀ y ∈ s, dist x y ≤ δ → dist (f x) (f y) ≤ ε := Metric.uniformity_basis_dist_le.uniformContinuousOn_iff Metric.uniformity_basis_dist_le theorem nhds_basis_ball : (𝓝 x).HasBasis (0 < ·) (ball x) := nhds_basis_uniformity uniformity_basis_dist theorem mem_nhds_iff : s ∈ 𝓝 x ↔ ∃ ε > 0, ball x ε ⊆ s := nhds_basis_ball.mem_iff theorem eventually_nhds_iff {p : α → Prop} : (∀ᶠ y in 𝓝 x, p y) ↔ ∃ ε > 0, ∀ ⦃y⦄, dist y x < ε → p y := mem_nhds_iff theorem eventually_nhds_iff_ball {p : α → Prop} : (∀ᶠ y in 𝓝 x, p y) ↔ ∃ ε > 0, ∀ y ∈ ball x ε, p y := mem_nhds_iff /-- A version of `Filter.eventually_prod_iff` where the first filter consists of neighborhoods in a pseudo-metric space. -/ theorem eventually_nhds_prod_iff {f : Filter ι} {x₀ : α} {p : α × ι → Prop} : (∀ᶠ x in 𝓝 x₀ ×ˢ f, p x) ↔ ∃ ε > (0 : ℝ), ∃ pa : ι → Prop, (∀ᶠ i in f, pa i) ∧ ∀ ⦃x⦄, dist x x₀ < ε → ∀ ⦃i⦄, pa i → p (x, i) := by refine (nhds_basis_ball.prod f.basis_sets).eventually_iff.trans ?_ simp only [Prod.exists, forall_prod_set, id, mem_ball, and_assoc, exists_and_left, and_imp] rfl /-- A version of `Filter.eventually_prod_iff` where the second filter consists of neighborhoods in a pseudo-metric space. -/ theorem eventually_prod_nhds_iff {f : Filter ι} {x₀ : α} {p : ι × α → Prop} : (∀ᶠ x in f ×ˢ 𝓝 x₀, p x) ↔ ∃ pa : ι → Prop, (∀ᶠ i in f, pa i) ∧ ∃ ε > 0, ∀ ⦃i⦄, pa i → ∀ ⦃x⦄, dist x x₀ < ε → p (i, x) := by rw [eventually_swap_iff, Metric.eventually_nhds_prod_iff] constructor <;> · rintro ⟨a1, a2, a3, a4, a5⟩ exact ⟨a3, a4, a1, a2, fun _ b1 b2 b3 => a5 b3 b1⟩ theorem nhds_basis_closedBall : (𝓝 x).HasBasis (fun ε : ℝ => 0 < ε) (closedBall x) := nhds_basis_uniformity uniformity_basis_dist_le theorem nhds_basis_ball_inv_nat_succ : (𝓝 x).HasBasis (fun _ => True) fun n : ℕ => ball x (1 / (↑n + 1)) := nhds_basis_uniformity uniformity_basis_dist_inv_nat_succ theorem nhds_basis_ball_inv_nat_pos : (𝓝 x).HasBasis (fun n => 0 < n) fun n : ℕ => ball x (1 / ↑n) := nhds_basis_uniformity uniformity_basis_dist_inv_nat_pos theorem nhds_basis_ball_pow {r : ℝ} (h0 : 0 < r) (h1 : r < 1) : (𝓝 x).HasBasis (fun _ => True) fun n : ℕ => ball x (r ^ n) := nhds_basis_uniformity (uniformity_basis_dist_pow h0 h1) theorem nhds_basis_closedBall_pow {r : ℝ} (h0 : 0 < r) (h1 : r < 1) : (𝓝 x).HasBasis (fun _ => True) fun n : ℕ => closedBall x (r ^ n) := nhds_basis_uniformity (uniformity_basis_dist_le_pow h0 h1) theorem isOpen_iff : IsOpen s ↔ ∀ x ∈ s, ∃ ε > 0, ball x ε ⊆ s := by simp only [isOpen_iff_mem_nhds, mem_nhds_iff] @[simp] theorem isOpen_ball : IsOpen (ball x ε) := isOpen_iff.2 fun _ => exists_ball_subset_ball theorem ball_mem_nhds (x : α) {ε : ℝ} (ε0 : 0 < ε) : ball x ε ∈ 𝓝 x := isOpen_ball.mem_nhds (mem_ball_self ε0) theorem closedBall_mem_nhds (x : α) {ε : ℝ} (ε0 : 0 < ε) : closedBall x ε ∈ 𝓝 x := mem_of_superset (ball_mem_nhds x ε0) ball_subset_closedBall theorem closedBall_mem_nhds_of_mem {x c : α} {ε : ℝ} (h : x ∈ ball c ε) : closedBall c ε ∈ 𝓝 x := mem_of_superset (isOpen_ball.mem_nhds h) ball_subset_closedBall theorem nhdsWithin_basis_ball {s : Set α} : (𝓝[s] x).HasBasis (fun ε : ℝ => 0 < ε) fun ε => ball x ε ∩ s := nhdsWithin_hasBasis nhds_basis_ball s theorem mem_nhdsWithin_iff {t : Set α} : s ∈ 𝓝[t] x ↔ ∃ ε > 0, ball x ε ∩ t ⊆ s := nhdsWithin_basis_ball.mem_iff theorem tendsto_nhdsWithin_nhdsWithin [PseudoMetricSpace β] {t : Set β} {f : α → β} {a b} : Tendsto f (𝓝[s] a) (𝓝[t] b) ↔ ∀ ε > 0, ∃ δ > 0, ∀ ⦃x : α⦄, x ∈ s → dist x a < δ → f x ∈ t ∧ dist (f x) b < ε := (nhdsWithin_basis_ball.tendsto_iff nhdsWithin_basis_ball).trans <| by simp only [inter_comm _ s, inter_comm _ t, mem_inter_iff, and_imp, gt_iff_lt, mem_ball] theorem tendsto_nhdsWithin_nhds [PseudoMetricSpace β] {f : α → β} {a b} : Tendsto f (𝓝[s] a) (𝓝 b) ↔ ∀ ε > 0, ∃ δ > 0, ∀ ⦃x : α⦄, x ∈ s → dist x a < δ → dist (f x) b < ε := by rw [← nhdsWithin_univ b, tendsto_nhdsWithin_nhdsWithin] simp only [mem_univ, true_and] theorem tendsto_nhds_nhds [PseudoMetricSpace β] {f : α → β} {a b} : Tendsto f (𝓝 a) (𝓝 b) ↔ ∀ ε > 0, ∃ δ > 0, ∀ ⦃x : α⦄, dist x a < δ → dist (f x) b < ε := nhds_basis_ball.tendsto_iff nhds_basis_ball theorem continuousAt_iff [PseudoMetricSpace β] {f : α → β} {a : α} : ContinuousAt f a ↔ ∀ ε > 0, ∃ δ > 0, ∀ ⦃x : α⦄, dist x a < δ → dist (f x) (f a) < ε := by rw [ContinuousAt, tendsto_nhds_nhds] theorem continuousWithinAt_iff [PseudoMetricSpace β] {f : α → β} {a : α} {s : Set α} : ContinuousWithinAt f s a ↔ ∀ ε > 0, ∃ δ > 0, ∀ ⦃x : α⦄, x ∈ s → dist x a < δ → dist (f x) (f a) < ε := by rw [ContinuousWithinAt, tendsto_nhdsWithin_nhds] theorem continuousOn_iff [PseudoMetricSpace β] {f : α → β} {s : Set α} : ContinuousOn f s ↔ ∀ b ∈ s, ∀ ε > 0, ∃ δ > 0, ∀ a ∈ s, dist a b < δ → dist (f a) (f b) < ε := by simp [ContinuousOn, continuousWithinAt_iff] theorem continuous_iff [PseudoMetricSpace β] {f : α → β} : Continuous f ↔ ∀ b, ∀ ε > 0, ∃ δ > 0, ∀ a, dist a b < δ → dist (f a) (f b) < ε := continuous_iff_continuousAt.trans <| forall_congr' fun _ => tendsto_nhds_nhds theorem tendsto_nhds {f : Filter β} {u : β → α} {a : α} : Tendsto u f (𝓝 a) ↔ ∀ ε > 0, ∀ᶠ x in f, dist (u x) a < ε := nhds_basis_ball.tendsto_right_iff theorem continuousAt_iff' [TopologicalSpace β] {f : β → α} {b : β} : ContinuousAt f b ↔ ∀ ε > 0, ∀ᶠ x in 𝓝 b, dist (f x) (f b) < ε := by rw [ContinuousAt, tendsto_nhds] theorem continuousWithinAt_iff' [TopologicalSpace β] {f : β → α} {b : β} {s : Set β} : ContinuousWithinAt f s b ↔ ∀ ε > 0, ∀ᶠ x in 𝓝[s] b, dist (f x) (f b) < ε := by rw [ContinuousWithinAt, tendsto_nhds] theorem continuousOn_iff' [TopologicalSpace β] {f : β → α} {s : Set β} : ContinuousOn f s ↔ ∀ b ∈ s, ∀ ε > 0, ∀ᶠ x in 𝓝[s] b, dist (f x) (f b) < ε := by simp [ContinuousOn, continuousWithinAt_iff'] theorem continuous_iff' [TopologicalSpace β] {f : β → α} : Continuous f ↔ ∀ (a), ∀ ε > 0, ∀ᶠ x in 𝓝 a, dist (f x) (f a) < ε := continuous_iff_continuousAt.trans <| forall_congr' fun _ => tendsto_nhds theorem tendsto_atTop [Nonempty β] [SemilatticeSup β] {u : β → α} {a : α} : Tendsto u atTop (𝓝 a) ↔ ∀ ε > 0, ∃ N, ∀ n ≥ N, dist (u n) a < ε := (atTop_basis.tendsto_iff nhds_basis_ball).trans <| by simp only [true_and, mem_ball, mem_Ici] /-- A variant of `tendsto_atTop` that uses `∃ N, ∀ n > N, ...` rather than `∃ N, ∀ n ≥ N, ...` -/ theorem tendsto_atTop' [Nonempty β] [SemilatticeSup β] [NoMaxOrder β] {u : β → α} {a : α} : Tendsto u atTop (𝓝 a) ↔ ∀ ε > 0, ∃ N, ∀ n > N, dist (u n) a < ε := (atTop_basis_Ioi.tendsto_iff nhds_basis_ball).trans <| by simp only [true_and, gt_iff_lt, mem_Ioi, mem_ball] theorem isOpen_singleton_iff {α : Type*} [PseudoMetricSpace α] {x : α} : IsOpen ({x} : Set α) ↔ ∃ ε > 0, ∀ y, dist y x < ε → y = x := by simp [isOpen_iff, subset_singleton_iff, mem_ball] theorem _root_.Dense.exists_dist_lt {s : Set α} (hs : Dense s) (x : α) {ε : ℝ} (hε : 0 < ε) : ∃ y ∈ s, dist x y < ε := by have : (ball x ε).Nonempty := by simp [hε] simpa only [mem_ball'] using hs.exists_mem_open isOpen_ball this nonrec theorem _root_.DenseRange.exists_dist_lt {β : Type*} {f : β → α} (hf : DenseRange f) (x : α) {ε : ℝ} (hε : 0 < ε) : ∃ y, dist x (f y) < ε := exists_range_iff.1 (hf.exists_dist_lt x hε) /-- (Pseudo) metric space has discrete `UniformSpace` structure iff the distances between distinct points are uniformly bounded away from zero. -/ protected lemma uniformSpace_eq_bot : ‹PseudoMetricSpace α›.toUniformSpace = ⊥ ↔ ∃ r : ℝ, 0 < r ∧ Pairwise (r ≤ dist · · : α → α → Prop) := by simp only [uniformity_basis_dist.uniformSpace_eq_bot, mem_setOf_eq, not_lt] end Metric open Metric /-- If the distances between distinct points in a (pseudo) metric space are uniformly bounded away from zero, then the space has discrete topology. -/ lemma DiscreteTopology.of_forall_le_dist {α} [PseudoMetricSpace α] {r : ℝ} (hpos : 0 < r) (hr : Pairwise (r ≤ dist · · : α → α → Prop)) : DiscreteTopology α := ⟨by rw [Metric.uniformSpace_eq_bot.2 ⟨r, hpos, hr⟩, UniformSpace.toTopologicalSpace_bot]⟩ /- Instantiate a pseudometric space as a pseudoemetric space. Before we can state the instance, we need to show that the uniform structure coming from the edistance and the distance coincide. -/ theorem Metric.uniformity_edist_aux {α} (d : α → α → ℝ≥0) :
⨅ ε > (0 : ℝ), 𝓟 { p : α × α | ↑(d p.1 p.2) < ε } = ⨅ ε > (0 : ℝ≥0∞), 𝓟 { p : α × α | ↑(d p.1 p.2) < ε } := by simp only [le_antisymm_iff, le_iInf_iff, le_principal_iff] refine ⟨fun ε hε => ?_, fun ε hε => ?_⟩ · rcases ENNReal.lt_iff_exists_nnreal_btwn.1 hε with ⟨ε', ε'0, ε'ε⟩
Mathlib/Topology/MetricSpace/Pseudo/Defs.lean
889
893
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Yakov Pechersky -/ import Mathlib.Data.List.Nodup import Mathlib.Data.List.Infix import Mathlib.Data.Quot /-! # List rotation This file proves basic results about `List.rotate`, the list rotation. ## Main declarations * `List.IsRotated l₁ l₂`: States that `l₁` is a rotated version of `l₂`. * `List.cyclicPermutations l`: The list of all cyclic permutants of `l`, up to the length of `l`. ## Tags rotated, rotation, permutation, cycle -/ universe u variable {α : Type u} open Nat Function namespace List theorem rotate_mod (l : List α) (n : ℕ) : l.rotate (n % l.length) = l.rotate n := by simp [rotate] @[simp] theorem rotate_nil (n : ℕ) : ([] : List α).rotate n = [] := by simp [rotate] @[simp] theorem rotate_zero (l : List α) : l.rotate 0 = l := by simp [rotate] theorem rotate'_nil (n : ℕ) : ([] : List α).rotate' n = [] := by simp @[simp] theorem rotate'_zero (l : List α) : l.rotate' 0 = l := by cases l <;> rfl theorem rotate'_cons_succ (l : List α) (a : α) (n : ℕ) : (a :: l : List α).rotate' n.succ = (l ++ [a]).rotate' n := by simp [rotate'] @[simp] theorem length_rotate' : ∀ (l : List α) (n : ℕ), (l.rotate' n).length = l.length | [], _ => by simp | _ :: _, 0 => rfl | a :: l, n + 1 => by rw [List.rotate', length_rotate' (l ++ [a]) n]; simp theorem rotate'_eq_drop_append_take : ∀ {l : List α} {n : ℕ}, n ≤ l.length → l.rotate' n = l.drop n ++ l.take n | [], n, h => by simp [drop_append_of_le_length h] | l, 0, h => by simp [take_append_of_le_length h] | a :: l, n + 1, h => by have hnl : n ≤ l.length := le_of_succ_le_succ h have hnl' : n ≤ (l ++ [a]).length := by rw [length_append, length_cons, List.length]; exact le_of_succ_le h rw [rotate'_cons_succ, rotate'_eq_drop_append_take hnl', drop, take, drop_append_of_le_length hnl, take_append_of_le_length hnl]; simp theorem rotate'_rotate' : ∀ (l : List α) (n m : ℕ), (l.rotate' n).rotate' m = l.rotate' (n + m) | a :: l, 0, m => by simp | [], n, m => by simp | a :: l, n + 1, m => by rw [rotate'_cons_succ, rotate'_rotate' _ n, Nat.add_right_comm, ← rotate'_cons_succ, Nat.succ_eq_add_one] @[simp] theorem rotate'_length (l : List α) : rotate' l l.length = l := by rw [rotate'_eq_drop_append_take le_rfl]; simp @[simp] theorem rotate'_length_mul (l : List α) : ∀ n : ℕ, l.rotate' (l.length * n) = l | 0 => by simp | n + 1 => calc l.rotate' (l.length * (n + 1)) = (l.rotate' (l.length * n)).rotate' (l.rotate' (l.length * n)).length := by simp [-rotate'_length, Nat.mul_succ, rotate'_rotate'] _ = l := by rw [rotate'_length, rotate'_length_mul l n] theorem rotate'_mod (l : List α) (n : ℕ) : l.rotate' (n % l.length) = l.rotate' n := calc l.rotate' (n % l.length) = (l.rotate' (n % l.length)).rotate' ((l.rotate' (n % l.length)).length * (n / l.length)) := by rw [rotate'_length_mul] _ = l.rotate' n := by rw [rotate'_rotate', length_rotate', Nat.mod_add_div] theorem rotate_eq_rotate' (l : List α) (n : ℕ) : l.rotate n = l.rotate' n := if h : l.length = 0 then by simp_all [length_eq_zero_iff] else by rw [← rotate'_mod, rotate'_eq_drop_append_take (le_of_lt (Nat.mod_lt _ (Nat.pos_of_ne_zero h)))] simp [rotate] @[simp] theorem rotate_cons_succ (l : List α) (a : α) (n : ℕ) : (a :: l : List α).rotate (n + 1) = (l ++ [a]).rotate n := by rw [rotate_eq_rotate', rotate_eq_rotate', rotate'_cons_succ] @[simp] theorem mem_rotate : ∀ {l : List α} {a : α} {n : ℕ}, a ∈ l.rotate n ↔ a ∈ l | [], _, n => by simp | a :: l, _, 0 => by simp | a :: l, _, n + 1 => by simp [rotate_cons_succ, mem_rotate, or_comm] @[simp] theorem length_rotate (l : List α) (n : ℕ) : (l.rotate n).length = l.length := by rw [rotate_eq_rotate', length_rotate'] @[simp] theorem rotate_replicate (a : α) (n : ℕ) (k : ℕ) : (replicate n a).rotate k = replicate n a := eq_replicate_iff.2 ⟨by rw [length_rotate, length_replicate], fun b hb => eq_of_mem_replicate <| mem_rotate.1 hb⟩ theorem rotate_eq_drop_append_take {l : List α} {n : ℕ} : n ≤ l.length → l.rotate n = l.drop n ++ l.take n := by rw [rotate_eq_rotate']; exact rotate'_eq_drop_append_take theorem rotate_eq_drop_append_take_mod {l : List α} {n : ℕ} : l.rotate n = l.drop (n % l.length) ++ l.take (n % l.length) := by rcases l.length.zero_le.eq_or_lt with hl | hl · simp [eq_nil_of_length_eq_zero hl.symm] rw [← rotate_eq_drop_append_take (n.mod_lt hl).le, rotate_mod] @[simp] theorem rotate_append_length_eq (l l' : List α) : (l ++ l').rotate l.length = l' ++ l := by rw [rotate_eq_rotate'] induction l generalizing l' · simp · simp_all [rotate'] theorem rotate_rotate (l : List α) (n m : ℕ) : (l.rotate n).rotate m = l.rotate (n + m) := by rw [rotate_eq_rotate', rotate_eq_rotate', rotate_eq_rotate', rotate'_rotate'] @[simp] theorem rotate_length (l : List α) : rotate l l.length = l := by rw [rotate_eq_rotate', rotate'_length] @[simp] theorem rotate_length_mul (l : List α) (n : ℕ) : l.rotate (l.length * n) = l := by rw [rotate_eq_rotate', rotate'_length_mul] theorem rotate_perm (l : List α) (n : ℕ) : l.rotate n ~ l := by rw [rotate_eq_rotate'] induction' n with n hn generalizing l · simp · rcases l with - | ⟨hd, tl⟩ · simp · rw [rotate'_cons_succ] exact (hn _).trans (perm_append_singleton _ _) @[simp] theorem nodup_rotate {l : List α} {n : ℕ} : Nodup (l.rotate n) ↔ Nodup l := (rotate_perm l n).nodup_iff @[simp] theorem rotate_eq_nil_iff {l : List α} {n : ℕ} : l.rotate n = [] ↔ l = [] := by induction' n with n hn generalizing l · simp · rcases l with - | ⟨hd, tl⟩ · simp · simp [rotate_cons_succ, hn] theorem nil_eq_rotate_iff {l : List α} {n : ℕ} : [] = l.rotate n ↔ [] = l := by rw [eq_comm, rotate_eq_nil_iff, eq_comm] @[simp] theorem rotate_singleton (x : α) (n : ℕ) : [x].rotate n = [x] := rotate_replicate x 1 n theorem zipWith_rotate_distrib {β γ : Type*} (f : α → β → γ) (l : List α) (l' : List β) (n : ℕ) (h : l.length = l'.length) : (zipWith f l l').rotate n = zipWith f (l.rotate n) (l'.rotate n) := by rw [rotate_eq_drop_append_take_mod, rotate_eq_drop_append_take_mod, rotate_eq_drop_append_take_mod, h, zipWith_append, ← drop_zipWith, ← take_zipWith, List.length_zipWith, h, min_self] rw [length_drop, length_drop, h] theorem zipWith_rotate_one {β : Type*} (f : α → α → β) (x y : α) (l : List α) : zipWith f (x :: y :: l) ((x :: y :: l).rotate 1) = f x y :: zipWith f (y :: l) (l ++ [x]) := by simp theorem getElem?_rotate {l : List α} {n m : ℕ} (hml : m < l.length) : (l.rotate n)[m]? = l[(m + n) % l.length]? := by rw [rotate_eq_drop_append_take_mod] rcases lt_or_le m (l.drop (n % l.length)).length with hm | hm · rw [getElem?_append_left hm, getElem?_drop, ← add_mod_mod] rw [length_drop, Nat.lt_sub_iff_add_lt] at hm rw [mod_eq_of_lt hm, Nat.add_comm] · have hlt : n % length l < length l := mod_lt _ (m.zero_le.trans_lt hml) rw [getElem?_append_right hm, getElem?_take_of_lt, length_drop] · congr 1 rw [length_drop] at hm have hm' := Nat.sub_le_iff_le_add'.1 hm have : n % length l + m - length l < length l := by rw [Nat.sub_lt_iff_lt_add hm'] exact Nat.add_lt_add hlt hml conv_rhs => rw [Nat.add_comm m, ← mod_add_mod, mod_eq_sub_mod hm', mod_eq_of_lt this] omega · rwa [Nat.sub_lt_iff_lt_add' hm, length_drop, Nat.sub_add_cancel hlt.le] theorem getElem_rotate (l : List α) (n : ℕ) (k : Nat) (h : k < (l.rotate n).length) : (l.rotate n)[k] = l[(k + n) % l.length]'(mod_lt _ (length_rotate l n ▸ k.zero_le.trans_lt h)) := by rw [← Option.some_inj, ← getElem?_eq_getElem, ← getElem?_eq_getElem, getElem?_rotate] exact h.trans_eq (length_rotate _ _) set_option linter.deprecated false in @[deprecated getElem?_rotate (since := "2025-02-14")] theorem get?_rotate {l : List α} {n m : ℕ} (hml : m < l.length) : (l.rotate n).get? m = l.get? ((m + n) % l.length) := by simp only [get?_eq_getElem?, length_rotate, hml, getElem?_eq_getElem, getElem_rotate] rw [← getElem?_eq_getElem] theorem get_rotate (l : List α) (n : ℕ) (k : Fin (l.rotate n).length) : (l.rotate n).get k = l.get ⟨(k + n) % l.length, mod_lt _ (length_rotate l n ▸ k.pos)⟩ := by simp [getElem_rotate] theorem head?_rotate {l : List α} {n : ℕ} (h : n < l.length) : head? (l.rotate n) = l[n]? := by rw [head?_eq_getElem?, getElem?_rotate (n.zero_le.trans_lt h), Nat.zero_add, Nat.mod_eq_of_lt h] theorem get_rotate_one (l : List α) (k : Fin (l.rotate 1).length) : (l.rotate 1).get k = l.get ⟨(k + 1) % l.length, mod_lt _ (length_rotate l 1 ▸ k.pos)⟩ := get_rotate l 1 k /-- A version of `List.getElem_rotate` that represents `l[k]` in terms of `(List.rotate l n)[⋯]`, not vice versa. Can be used instead of rewriting `List.getElem_rotate` from right to left. -/ theorem getElem_eq_getElem_rotate (l : List α) (n : ℕ) (k : Nat) (hk : k < l.length) : l[k] = ((l.rotate n)[(l.length - n % l.length + k) % l.length]' ((Nat.mod_lt _ (k.zero_le.trans_lt hk)).trans_eq (length_rotate _ _).symm)) := by rw [getElem_rotate] refine congr_arg l.get (Fin.eq_of_val_eq ?_) simp only [mod_add_mod] rw [← add_mod_mod, Nat.add_right_comm, Nat.sub_add_cancel, add_mod_left, mod_eq_of_lt] exacts [hk, (mod_lt _ (k.zero_le.trans_lt hk)).le] /-- A version of `List.get_rotate` that represents `List.get l` in terms of `List.get (List.rotate l n)`, not vice versa. Can be used instead of rewriting `List.get_rotate` from right to left. -/ theorem get_eq_get_rotate (l : List α) (n : ℕ) (k : Fin l.length) : l.get k = (l.rotate n).get ⟨(l.length - n % l.length + k) % l.length, (Nat.mod_lt _ (k.1.zero_le.trans_lt k.2)).trans_eq (length_rotate _ _).symm⟩ := by rw [get_rotate] refine congr_arg l.get (Fin.eq_of_val_eq ?_) simp only [mod_add_mod] rw [← add_mod_mod, Nat.add_right_comm, Nat.sub_add_cancel, add_mod_left, mod_eq_of_lt] exacts [k.2, (mod_lt _ (k.1.zero_le.trans_lt k.2)).le] theorem rotate_eq_self_iff_eq_replicate [hα : Nonempty α] : ∀ {l : List α}, (∀ n, l.rotate n = l) ↔ ∃ a, l = replicate l.length a | [] => by simp | a :: l => ⟨fun h => ⟨a, ext_getElem length_replicate.symm fun n h₁ h₂ => by rw [getElem_replicate, ← Option.some_inj, ← getElem?_eq_getElem, ← head?_rotate h₁, h, head?_cons]⟩, fun ⟨b, hb⟩ n => by rw [hb, rotate_replicate]⟩ theorem rotate_one_eq_self_iff_eq_replicate [Nonempty α] {l : List α} : l.rotate 1 = l ↔ ∃ a : α, l = List.replicate l.length a := ⟨fun h => rotate_eq_self_iff_eq_replicate.mp fun n => Nat.rec l.rotate_zero (fun n hn => by rwa [Nat.succ_eq_add_one, ← l.rotate_rotate, hn]) n, fun h => rotate_eq_self_iff_eq_replicate.mpr h 1⟩ theorem rotate_injective (n : ℕ) : Function.Injective fun l : List α => l.rotate n := by rintro l l' (h : l.rotate n = l'.rotate n) have hle : l.length = l'.length := (l.length_rotate n).symm.trans (h.symm ▸ l'.length_rotate n) rw [rotate_eq_drop_append_take_mod, rotate_eq_drop_append_take_mod] at h obtain ⟨hd, ht⟩ := append_inj h (by simp_all) rw [← take_append_drop _ l, ht, hd, take_append_drop] @[simp] theorem rotate_eq_rotate {l l' : List α} {n : ℕ} : l.rotate n = l'.rotate n ↔ l = l' := (rotate_injective n).eq_iff theorem rotate_eq_iff {l l' : List α} {n : ℕ} : l.rotate n = l' ↔ l = l'.rotate (l'.length - n % l'.length) := by rw [← @rotate_eq_rotate _ l _ n, rotate_rotate, ← rotate_mod l', add_mod] rcases l'.length.zero_le.eq_or_lt with hl | hl · rw [eq_nil_of_length_eq_zero hl.symm, rotate_nil] · rcases (Nat.zero_le (n % l'.length)).eq_or_lt with hn | hn · simp [← hn] · rw [mod_eq_of_lt (Nat.sub_lt hl hn), Nat.sub_add_cancel, mod_self, rotate_zero] exact (Nat.mod_lt _ hl).le @[simp] theorem rotate_eq_singleton_iff {l : List α} {n : ℕ} {x : α} : l.rotate n = [x] ↔ l = [x] := by rw [rotate_eq_iff, rotate_singleton] @[simp] theorem singleton_eq_rotate_iff {l : List α} {n : ℕ} {x : α} : [x] = l.rotate n ↔ [x] = l := by rw [eq_comm, rotate_eq_singleton_iff, eq_comm] theorem reverse_rotate (l : List α) (n : ℕ) : (l.rotate n).reverse = l.reverse.rotate (l.length - n % l.length) := by rw [← length_reverse, ← rotate_eq_iff] induction' n with n hn generalizing l · simp · rcases l with - | ⟨hd, tl⟩ · simp · rw [rotate_cons_succ, ← rotate_rotate, hn] simp theorem rotate_reverse (l : List α) (n : ℕ) : l.reverse.rotate n = (l.rotate (l.length - n % l.length)).reverse := by rw [← reverse_reverse l] simp_rw [reverse_rotate, reverse_reverse, rotate_eq_iff, rotate_rotate, length_rotate, length_reverse] rw [← length_reverse] let k := n % l.reverse.length rcases hk' : k with - | k' · simp_all! [k, length_reverse, ← rotate_rotate] · rcases l with - | ⟨x, l⟩ · simp · rw [Nat.mod_eq_of_lt, Nat.sub_add_cancel, rotate_length] · exact Nat.sub_le _ _ · exact Nat.sub_lt (by simp) (by simp_all! [k]) theorem map_rotate {β : Type*} (f : α → β) (l : List α) (n : ℕ) : map f (l.rotate n) = (map f l).rotate n := by induction' n with n hn IH generalizing l · simp · rcases l with - | ⟨hd, tl⟩ · simp · simp [hn] theorem Nodup.rotate_congr {l : List α} (hl : l.Nodup) (hn : l ≠ []) (i j : ℕ) (h : l.rotate i = l.rotate j) : i % l.length = j % l.length := by rw [← rotate_mod l i, ← rotate_mod l j] at h simpa only [head?_rotate, mod_lt, length_pos_of_ne_nil hn, getElem?_eq_getElem, Option.some_inj, hl.getElem_inj_iff, Fin.ext_iff] using congr_arg head? h theorem Nodup.rotate_congr_iff {l : List α} (hl : l.Nodup) {i j : ℕ} : l.rotate i = l.rotate j ↔ i % l.length = j % l.length ∨ l = [] := by rcases eq_or_ne l [] with rfl | hn · simp · simp only [hn, or_false] refine ⟨hl.rotate_congr hn _ _, fun h ↦ ?_⟩ rw [← rotate_mod, h, rotate_mod] theorem Nodup.rotate_eq_self_iff {l : List α} (hl : l.Nodup) {n : ℕ} : l.rotate n = l ↔ n % l.length = 0 ∨ l = [] := by rw [← zero_mod, ← hl.rotate_congr_iff, rotate_zero] section IsRotated variable (l l' : List α) /-- `IsRotated l₁ l₂` or `l₁ ~r l₂` asserts that `l₁` and `l₂` are cyclic permutations of each other. This is defined by claiming that `∃ n, l.rotate n = l'`. -/ def IsRotated : Prop := ∃ n, l.rotate n = l' @[inherit_doc List.IsRotated] -- This matches the precedence of the infix `~` for `List.Perm`, and of other relation infixes infixr:50 " ~r " => IsRotated variable {l l'} @[refl] theorem IsRotated.refl (l : List α) : l ~r l := ⟨0, by simp⟩ @[symm] theorem IsRotated.symm (h : l ~r l') : l' ~r l := by obtain ⟨n, rfl⟩ := h rcases l with - | ⟨hd, tl⟩ · exists 0 · use (hd :: tl).length * n - n rw [rotate_rotate, Nat.add_sub_cancel', rotate_length_mul] exact Nat.le_mul_of_pos_left _ (by simp) theorem isRotated_comm : l ~r l' ↔ l' ~r l := ⟨IsRotated.symm, IsRotated.symm⟩ @[simp] protected theorem IsRotated.forall (l : List α) (n : ℕ) : l.rotate n ~r l := IsRotated.symm ⟨n, rfl⟩ @[trans] theorem IsRotated.trans : ∀ {l l' l'' : List α}, l ~r l' → l' ~r l'' → l ~r l'' | _, _, _, ⟨n, rfl⟩, ⟨m, rfl⟩ => ⟨n + m, by rw [rotate_rotate]⟩ theorem IsRotated.eqv : Equivalence (@IsRotated α) := Equivalence.mk IsRotated.refl IsRotated.symm IsRotated.trans /-- The relation `List.IsRotated l l'` forms a `Setoid` of cycles. -/ def IsRotated.setoid (α : Type*) : Setoid (List α) where r := IsRotated iseqv := IsRotated.eqv theorem IsRotated.perm (h : l ~r l') : l ~ l' := Exists.elim h fun _ hl => hl ▸ (rotate_perm _ _).symm theorem IsRotated.nodup_iff (h : l ~r l') : Nodup l ↔ Nodup l' := h.perm.nodup_iff theorem IsRotated.mem_iff (h : l ~r l') {a : α} : a ∈ l ↔ a ∈ l' := h.perm.mem_iff @[simp] theorem isRotated_nil_iff : l ~r [] ↔ l = [] := ⟨fun ⟨n, hn⟩ => by simpa using hn, fun h => h ▸ by rfl⟩ @[simp] theorem isRotated_nil_iff' : [] ~r l ↔ [] = l := by rw [isRotated_comm, isRotated_nil_iff, eq_comm] @[simp] theorem isRotated_singleton_iff {x : α} : l ~r [x] ↔ l = [x] := ⟨fun ⟨n, hn⟩ => by simpa using hn, fun h => h ▸ by rfl⟩ @[simp] theorem isRotated_singleton_iff' {x : α} : [x] ~r l ↔ [x] = l := by rw [isRotated_comm, isRotated_singleton_iff, eq_comm] theorem isRotated_concat (hd : α) (tl : List α) : (tl ++ [hd]) ~r (hd :: tl) := IsRotated.symm ⟨1, by simp⟩ theorem isRotated_append : (l ++ l') ~r (l' ++ l) := ⟨l.length, by simp⟩ theorem IsRotated.reverse (h : l ~r l') : l.reverse ~r l'.reverse := by obtain ⟨n, rfl⟩ := h exact ⟨_, (reverse_rotate _ _).symm⟩ theorem isRotated_reverse_comm_iff : l.reverse ~r l' ↔ l ~r l'.reverse := by constructor <;> · intro h simpa using h.reverse @[simp] theorem isRotated_reverse_iff : l.reverse ~r l'.reverse ↔ l ~r l' := by simp [isRotated_reverse_comm_iff] theorem isRotated_iff_mod : l ~r l' ↔ ∃ n ≤ l.length, l.rotate n = l' := by refine ⟨fun h => ?_, fun ⟨n, _, h⟩ => ⟨n, h⟩⟩ obtain ⟨n, rfl⟩ := h rcases l with - | ⟨hd, tl⟩ · simp · refine ⟨n % (hd :: tl).length, ?_, rotate_mod _ _⟩ refine (Nat.mod_lt _ ?_).le simp theorem isRotated_iff_mem_map_range : l ~r l' ↔ l' ∈ (List.range (l.length + 1)).map l.rotate := by simp_rw [mem_map, mem_range, isRotated_iff_mod] exact ⟨fun ⟨n, hn, h⟩ => ⟨n, Nat.lt_succ_of_le hn, h⟩, fun ⟨n, hn, h⟩ => ⟨n, Nat.le_of_lt_succ hn, h⟩⟩ theorem IsRotated.map {β : Type*} {l₁ l₂ : List α} (h : l₁ ~r l₂) (f : α → β) : map f l₁ ~r map f l₂ := by obtain ⟨n, rfl⟩ := h rw [map_rotate] use n theorem IsRotated.cons_getLast_dropLast (L : List α) (hL : L ≠ []) : L.getLast hL :: L.dropLast ~r L := by induction L using List.reverseRecOn with | nil => simp at hL | append_singleton a L _ => simp only [getLast_append, dropLast_concat] apply IsRotated.symm apply isRotated_concat theorem IsRotated.dropLast_tail {α} {L : List α} (hL : L ≠ []) (hL' : L.head hL = L.getLast hL) : L.dropLast ~r L.tail := match L with | [] => by simp | [_] => by simp | a :: b :: L => by simp only [head_cons, ne_eq, reduceCtorEq, not_false_eq_true, getLast_cons] at hL' simp [hL', IsRotated.cons_getLast_dropLast] /-- List of all cyclic permutations of `l`. The `cyclicPermutations` of a nonempty list `l` will always contain `List.length l` elements. This implies that under certain conditions, there are duplicates in `List.cyclicPermutations l`.
The `n`th entry is equal to `l.rotate n`, proven in `List.get_cyclicPermutations`. The proof that every cyclic permutant of `l` is in the list is `List.mem_cyclicPermutations_iff`.
Mathlib/Data/List/Rotate.lean
484
485
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Sophie Morel -/ import Mathlib.Algebra.Category.Grp.Preadditive import Mathlib.Algebra.Equiv.TransferInstance import Mathlib.CategoryTheory.ConcreteCategory.Elementwise import Mathlib.Data.DFinsupp.BigOperators import Mathlib.Data.DFinsupp.Small import Mathlib.GroupTheory.QuotientGroup.Defs /-! # The category of additive commutative groups has all colimits. This file constructs colimits in the category of additive commutative groups, as quotients of finitely supported functions. -/ universe u' w u v open CategoryTheory Limits namespace AddCommGrp variable {J : Type u} [Category.{v} J] (F : J ⥤ AddCommGrp.{w}) namespace Colimits /-! We build the colimit of a diagram in `AddCommGrp` by constructing the free group on the disjoint union of all the abelian groups in the diagram, then taking the quotient by the abelian group laws within each abelian group, and the identifications given by the morphisms in the diagram. -/ /-- The relations between elements of the direct sum of the `F.obj j` given by the morphisms in the diagram `J`. -/ abbrev Relations [DecidableEq J] : AddSubgroup (DFinsupp (fun j ↦ F.obj j)) := AddSubgroup.closure {x | ∃ (j j' : J) (u : j ⟶ j') (a : F.obj j), x = DFinsupp.single j' (F.map u a) - DFinsupp.single j a} /-- The candidate for the colimit of `F`, defined as the quotient of the direct sum of the commutative groups `F.obj j` by the relations given by the morphisms in the diagram. -/ def Quot [DecidableEq J] : Type (max u w) := DFinsupp (fun j ↦ F.obj j) ⧸ Relations F instance [DecidableEq J] : AddCommGroup (Quot F) := QuotientAddGroup.Quotient.addCommGroup (Relations F) /-- Inclusion of `F.obj j` into the candidate colimit. -/ def Quot.ι [DecidableEq J] (j : J) : F.obj j →+ Quot F := (QuotientAddGroup.mk' _).comp (DFinsupp.singleAddHom (fun j ↦ F.obj j) j) lemma Quot.addMonoidHom_ext [DecidableEq J] {α : Type*} [AddMonoid α] {f g : Quot F →+ α} (h : ∀ (j : J) (x : F.obj j), f (Quot.ι F j x) = g (Quot.ι F j x)) : f = g := QuotientAddGroup.addMonoidHom_ext _ (DFinsupp.addHom_ext h) variable (c : Cocone F) /-- (implementation detail) Part of the universal property of the colimit cocone, but without assuming that `Quot F` lives in the correct universe. -/ def Quot.desc [DecidableEq J] : Quot.{w} F →+ c.pt := by refine QuotientAddGroup.lift _ (DFinsupp.sumAddHom fun x => (c.ι.app x).hom) ?_ dsimp rw [AddSubgroup.closure_le] intro _ ⟨_, _, _, _, eq⟩ rw [eq] simp only [SetLike.mem_coe, AddMonoidHom.mem_ker, map_sub, DFinsupp.sumAddHom_single] change (F.map _ ≫ c.ι.app _) _ - _ = 0 rw [c.ι.naturality] simp only [Functor.const_obj_obj, Functor.const_obj_map, Category.comp_id, sub_self] @[simp] lemma Quot.ι_desc [DecidableEq J] (j : J) (x : F.obj j) : Quot.desc F c (Quot.ι F j x) = c.ι.app j x := by dsimp [desc, ι] erw [QuotientAddGroup.lift_mk'] simp @[simp] lemma Quot.map_ι [DecidableEq J] {j j' : J} {f : j ⟶ j'} (x : F.obj j) : Quot.ι F j' (F.map f x) = Quot.ι F j x := by dsimp [ι] refine eq_of_sub_eq_zero ?_ erw [← (QuotientAddGroup.mk' (Relations F)).map_sub, ← AddMonoidHom.mem_ker] rw [QuotientAddGroup.ker_mk'] simp only [DFinsupp.singleAddHom_apply] exact AddSubgroup.subset_closure ⟨j, j', f, x, rfl⟩ /-- The obvious additive map from `Quot F` to `Quot (F ⋙ uliftFunctor.{u'})`. -/ def quotToQuotUlift [DecidableEq J] : Quot F →+ Quot (F ⋙ uliftFunctor.{u'}) := by refine QuotientAddGroup.lift (Relations F) (DFinsupp.sumAddHom (fun j ↦ (Quot.ι _ j).comp AddEquiv.ulift.symm.toAddMonoidHom)) ?_ rw [AddSubgroup.closure_le] intro _ hx obtain ⟨j, j', u, a, rfl⟩ := hx rw [SetLike.mem_coe, AddMonoidHom.mem_ker, map_sub, DFinsupp.sumAddHom_single, DFinsupp.sumAddHom_single] change Quot.ι (F ⋙ uliftFunctor) j' ((F ⋙ uliftFunctor).map u (AddEquiv.ulift.symm a)) - _ = _ rw [Quot.map_ι] dsimp rw [sub_self] lemma quotToQuotUlift_ι [DecidableEq J] (j : J) (x : F.obj j) : quotToQuotUlift F (Quot.ι F j x) = Quot.ι _ j (ULift.up x) := by dsimp [quotToQuotUlift, Quot.ι] conv_lhs => erw [AddMonoidHom.comp_apply (QuotientAddGroup.mk' (Relations F)) (DFinsupp.singleAddHom _ j), QuotientAddGroup.lift_mk'] simp only [DFinsupp.singleAddHom_apply, DFinsupp.sumAddHom_single, AddMonoidHom.coe_comp, AddMonoidHom.coe_coe, Function.comp_apply] rfl /-- The obvious additive map from `Quot (F ⋙ uliftFunctor.{u'})` to `Quot F`. -/ def quotUliftToQuot [DecidableEq J] : Quot (F ⋙ uliftFunctor.{u'}) →+ Quot F := by refine QuotientAddGroup.lift (Relations (F ⋙ uliftFunctor)) (DFinsupp.sumAddHom (fun j ↦ (Quot.ι _ j).comp AddEquiv.ulift.toAddMonoidHom)) ?_ rw [AddSubgroup.closure_le] intro _ hx obtain ⟨j, j', u, a, rfl⟩ := hx rw [SetLike.mem_coe, AddMonoidHom.mem_ker, map_sub, DFinsupp.sumAddHom_single, DFinsupp.sumAddHom_single] change Quot.ι F j' (F.map u (AddEquiv.ulift a)) - _ = _ rw [Quot.map_ι] dsimp rw [sub_self] lemma quotUliftToQuot_ι [DecidableEq J] (j : J) (x : (F ⋙ uliftFunctor.{u'}).obj j) : quotUliftToQuot F (Quot.ι _ j x) = Quot.ι F j x.down := by dsimp [quotUliftToQuot, Quot.ι] conv_lhs => erw [AddMonoidHom.comp_apply (QuotientAddGroup.mk' (Relations (F ⋙ uliftFunctor))) (DFinsupp.singleAddHom _ j), QuotientAddGroup.lift_mk'] simp only [Functor.comp_obj, uliftFunctor_obj, DFinsupp.singleAddHom_apply, DFinsupp.sumAddHom_single, AddMonoidHom.coe_comp, AddMonoidHom.coe_coe, Function.comp_apply] rfl /-- The additive equivalence between `Quot F` and `Quot (F ⋙ uliftFunctor.{u'})`. -/ @[simp] def quotQuotUliftAddEquiv [DecidableEq J] : Quot F ≃+ Quot (F ⋙ uliftFunctor.{u'}) where toFun := quotToQuotUlift F invFun := quotUliftToQuot F left_inv x := by conv_rhs => rw [← AddMonoidHom.id_apply _ x] rw [← AddMonoidHom.comp_apply, Quot.addMonoidHom_ext F (f := (quotUliftToQuot F).comp (quotToQuotUlift F)) (fun j a ↦ ?_)] rw [AddMonoidHom.comp_apply, AddMonoidHom.id_apply, quotToQuotUlift_ι, quotUliftToQuot_ι] right_inv x := by conv_rhs => rw [← AddMonoidHom.id_apply _ x] rw [← AddMonoidHom.comp_apply, Quot.addMonoidHom_ext _ (f := (quotToQuotUlift F).comp (quotUliftToQuot F)) (fun j a ↦ ?_)] rw [AddMonoidHom.comp_apply, AddMonoidHom.id_apply, quotUliftToQuot_ι, quotToQuotUlift_ι] rfl map_add' _ _ := by simp lemma Quot.desc_quotQuotUliftAddEquiv [DecidableEq J] (c : Cocone F) : (Quot.desc (F ⋙ uliftFunctor.{u'}) (uliftFunctor.{u'}.mapCocone c)).comp (quotQuotUliftAddEquiv F).toAddMonoidHom = AddEquiv.ulift.symm.toAddMonoidHom.comp (Quot.desc F c) := by refine Quot.addMonoidHom_ext _ (fun j a ↦ ?_)
dsimp simp only [quotToQuotUlift_ι, Functor.comp_obj, uliftFunctor_obj, ι_desc, Functor.const_obj_obj, AddMonoidHom.coe_comp, AddMonoidHom.coe_coe, Function.comp_apply, ι_desc] erw [Quot.ι_desc] rfl
Mathlib/Algebra/Category/Grp/Colimits.lean
172
176
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Geometry.Euclidean.Angle.Oriented.RightAngle import Mathlib.Geometry.Euclidean.Circumcenter /-! # Angles in circles and sphere. This file proves results about angles in circles and spheres. -/ noncomputable section open Module Complex open scoped EuclideanGeometry Real RealInnerProductSpace ComplexConjugate namespace Orientation variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] variable [Fact (finrank ℝ V = 2)] (o : Orientation ℝ V (Fin 2)) /-- Angle at center of a circle equals twice angle at circumference, oriented vector angle form. -/ theorem oangle_eq_two_zsmul_oangle_sub_of_norm_eq {x y z : V} (hxyne : x ≠ y) (hxzne : x ≠ z) (hxy : ‖x‖ = ‖y‖) (hxz : ‖x‖ = ‖z‖) : o.oangle y z = (2 : ℤ) • o.oangle (y - x) (z - x) := by have hy : y ≠ 0 := by rintro rfl rw [norm_zero, norm_eq_zero] at hxy exact hxyne hxy have hx : x ≠ 0 := norm_ne_zero_iff.1 (hxy.symm ▸ norm_ne_zero_iff.2 hy) have hz : z ≠ 0 := norm_ne_zero_iff.1 (hxz ▸ norm_ne_zero_iff.2 hx) calc o.oangle y z = o.oangle x z - o.oangle x y := (o.oangle_sub_left hx hy hz).symm _ = π - (2 : ℤ) • o.oangle (x - z) x - (π - (2 : ℤ) • o.oangle (x - y) x) := by rw [o.oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq hxzne.symm hxz.symm, o.oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq hxyne.symm hxy.symm] _ = (2 : ℤ) • (o.oangle (x - y) x - o.oangle (x - z) x) := by abel _ = (2 : ℤ) • o.oangle (x - y) (x - z) := by rw [o.oangle_sub_right (sub_ne_zero_of_ne hxyne) (sub_ne_zero_of_ne hxzne) hx] _ = (2 : ℤ) • o.oangle (y - x) (z - x) := by rw [← oangle_neg_neg, neg_sub, neg_sub] /-- Angle at center of a circle equals twice angle at circumference, oriented vector angle form with radius specified. -/ theorem oangle_eq_two_zsmul_oangle_sub_of_norm_eq_real {x y z : V} (hxyne : x ≠ y) (hxzne : x ≠ z) {r : ℝ} (hx : ‖x‖ = r) (hy : ‖y‖ = r) (hz : ‖z‖ = r) : o.oangle y z = (2 : ℤ) • o.oangle (y - x) (z - x) := o.oangle_eq_two_zsmul_oangle_sub_of_norm_eq hxyne hxzne (hy.symm ▸ hx) (hz.symm ▸ hx) /-- Oriented vector angle version of "angles in same segment are equal" and "opposite angles of a cyclic quadrilateral add to π", for oriented angles mod π (for which those are the same result), represented here as equality of twice the angles. -/ theorem two_zsmul_oangle_sub_eq_two_zsmul_oangle_sub_of_norm_eq {x₁ x₂ y z : V} (hx₁yne : x₁ ≠ y) (hx₁zne : x₁ ≠ z) (hx₂yne : x₂ ≠ y) (hx₂zne : x₂ ≠ z) {r : ℝ} (hx₁ : ‖x₁‖ = r) (hx₂ : ‖x₂‖ = r) (hy : ‖y‖ = r) (hz : ‖z‖ = r) : (2 : ℤ) • o.oangle (y - x₁) (z - x₁) = (2 : ℤ) • o.oangle (y - x₂) (z - x₂) := o.oangle_eq_two_zsmul_oangle_sub_of_norm_eq_real hx₁yne hx₁zne hx₁ hy hz ▸ o.oangle_eq_two_zsmul_oangle_sub_of_norm_eq_real hx₂yne hx₂zne hx₂ hy hz end Orientation namespace EuclideanGeometry variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] [hd2 : Fact (finrank ℝ V = 2)] [Module.Oriented ℝ V (Fin 2)] local notation "o" => Module.Oriented.positiveOrientation namespace Sphere /-- Angle at center of a circle equals twice angle at circumference, oriented angle version. -/ theorem oangle_center_eq_two_zsmul_oangle {s : Sphere P} {p₁ p₂ p₃ : P} (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (hp₃ : p₃ ∈ s) (hp₂p₁ : p₂ ≠ p₁) (hp₂p₃ : p₂ ≠ p₃) : ∡ p₁ s.center p₃ = (2 : ℤ) • ∡ p₁ p₂ p₃ := by rw [mem_sphere, @dist_eq_norm_vsub V] at hp₁ hp₂ hp₃ rw [oangle, oangle, o.oangle_eq_two_zsmul_oangle_sub_of_norm_eq_real _ _ hp₂ hp₁ hp₃] <;> simp [hp₂p₁, hp₂p₃] /-- Oriented angle version of "angles in same segment are equal" and "opposite angles of a cyclic quadrilateral add to π", for oriented angles mod π (for which those are the same result), represented here as equality of twice the angles. -/ theorem two_zsmul_oangle_eq {s : Sphere P} {p₁ p₂ p₃ p₄ : P} (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (hp₃ : p₃ ∈ s) (hp₄ : p₄ ∈ s) (hp₂p₁ : p₂ ≠ p₁) (hp₂p₄ : p₂ ≠ p₄) (hp₃p₁ : p₃ ≠ p₁) (hp₃p₄ : p₃ ≠ p₄) : (2 : ℤ) • ∡ p₁ p₂ p₄ = (2 : ℤ) • ∡ p₁ p₃ p₄ := by rw [mem_sphere, @dist_eq_norm_vsub V] at hp₁ hp₂ hp₃ hp₄ rw [oangle, oangle, ← vsub_sub_vsub_cancel_right p₁ p₂ s.center, ← vsub_sub_vsub_cancel_right p₄ p₂ s.center,
o.two_zsmul_oangle_sub_eq_two_zsmul_oangle_sub_of_norm_eq _ _ _ _ hp₂ hp₃ hp₁ hp₄] <;> simp [hp₂p₁, hp₂p₄, hp₃p₁, hp₃p₄] end Sphere /-- Oriented angle version of "angles in same segment are equal" and "opposite angles of a cyclic quadrilateral add to π", for oriented angles mod π (for which those are the same result), represented here as equality of twice the angles. -/
Mathlib/Geometry/Euclidean/Angle/Sphere.lean
93
100